mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-06-21 14:22:43 +02:00
a function to check if a public key hex is a public key hex.
This commit is contained in:
parent
02759120ea
commit
7803cc74b3
9
keys.go
9
keys.go
@ -5,6 +5,7 @@ import (
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"math/big"
|
||||
"strings"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
||||
@ -37,3 +38,11 @@ func GetPublicKey(sk string) (string, error) {
|
||||
_, pk := btcec.PrivKeyFromBytes(b)
|
||||
return hex.EncodeToString(schnorr.SerializePubKey(pk)), nil
|
||||
}
|
||||
|
||||
func IsValidPublicKeyHex(pk string) bool {
|
||||
if strings.ToLower(pk) != pk {
|
||||
return false
|
||||
}
|
||||
dec, _ := hex.DecodeString(pk)
|
||||
return len(dec) == 32
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user