mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-19 22:31:54 +01:00
18 lines
360 B
Go
18 lines
360 B
Go
|
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
|
||
|
}
|