fix nip19 bech32 encoding and decoding.

This commit is contained in:
fiatjaf
2022-11-15 16:29:37 -03:00
parent dd0571229b
commit 2ec7957409
3 changed files with 38 additions and 16 deletions

17
nip19/utils.go Normal file
View File

@@ -0,0 +1,17 @@
package nip19
import (
"encoding/hex"
"strings"
)
// TranslatePublicKey turns a hex or bech32 public key into always hex
func TranslatePublicKey(bech32orHexKey string) string {
if strings.HasPrefix(bech32orHexKey, "npub1") {
data, _, _ := Decode(bech32orHexKey)
return hex.EncodeToString(data)
}
// just return what we got
return bech32orHexKey
}