mirror of
https://github.com/studiokaiji/nostr-webhost.git
synced 2025-12-17 23:04:23 +01:00
ResolvePubKeyを作成
This commit is contained in:
24
hostr/cmd/tools/resolvePubKey.go
Normal file
24
hostr/cmd/tools/resolvePubKey.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr/nip19"
|
||||
)
|
||||
|
||||
func ResolvePubKey(npubOrHex string) (string, error) {
|
||||
// npubから始まる場合はデコードする
|
||||
if npubOrHex[0:4] == "npub" {
|
||||
_, v, err := nip19.Decode(npubOrHex)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Invalid npub")
|
||||
}
|
||||
return v.(string), nil
|
||||
} else {
|
||||
_, err := nip19.EncodePublicKey(npubOrHex)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Invalid pubkey")
|
||||
}
|
||||
}
|
||||
return npubOrHex, nil
|
||||
}
|
||||
Reference in New Issue
Block a user