mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-10 21:04:10 +02:00
a function to check if a public key hex is a public key hex.
This commit is contained in:
9
keys.go
9
keys.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
"github.com/btcsuite/btcd/btcec/v2/schnorr"
|
||||||
@@ -37,3 +38,11 @@ func GetPublicKey(sk string) (string, error) {
|
|||||||
_, pk := btcec.PrivKeyFromBytes(b)
|
_, pk := btcec.PrivKeyFromBytes(b)
|
||||||
return hex.EncodeToString(schnorr.SerializePubKey(pk)), nil
|
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
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user