mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-04-10 20:59:24 +02:00
IsValidPublicKey() and IsValid32ByteHex() replacing IsValidPublicKeyHex()
This commit is contained in:
parent
1a7b8991a3
commit
70f719ea31
7
keys.go
7
keys.go
@ -39,6 +39,7 @@ func GetPublicKey(sk string) (string, error) {
|
||||
return hex.EncodeToString(schnorr.SerializePubKey(pk)), nil
|
||||
}
|
||||
|
||||
// Deprecated: use IsValid32ByteHex instead -- functionality unchanged.
|
||||
func IsValidPublicKeyHex(pk string) bool {
|
||||
if strings.ToLower(pk) != pk {
|
||||
return false
|
||||
@ -46,3 +47,9 @@ func IsValidPublicKeyHex(pk string) bool {
|
||||
dec, _ := hex.DecodeString(pk)
|
||||
return len(dec) == 32
|
||||
}
|
||||
|
||||
func IsValidPublicKey(pk string) bool {
|
||||
v, _ := hex.DecodeString(pk)
|
||||
_, err := btcec.ParsePubKey(v)
|
||||
return len(v) == 32 && err == nil
|
||||
}
|
||||
|
12
utils.go
12
utils.go
@ -1,6 +1,7 @@
|
||||
package nostr
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
@ -18,3 +19,14 @@ func IsValidRelayURL(u string) bool {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func IsValid32ByteHex(thing string) bool {
|
||||
if strings.ToLower(thing) != thing {
|
||||
return false
|
||||
}
|
||||
if len(thing) != 64 {
|
||||
return false
|
||||
}
|
||||
_, err := hex.DecodeString(thing)
|
||||
return err == nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user