a function to check if a public key hex is a public key hex.

This commit is contained in:
fiatjaf 2023-03-14 21:42:37 -03:00
parent 02759120ea
commit 7803cc74b3
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -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
}