Skip to content

Commit

Permalink
ResolvePubKeyを作成
Browse files Browse the repository at this point in the history
  • Loading branch information
studiokaiji committed Oct 19, 2023
1 parent 8c75154 commit e18108a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions hostr/cmd/tools/resolvePubKey.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e18108a

Please sign in to comment.