-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
studiokaiji
committed
Oct 19, 2023
1 parent
8c75154
commit e18108a
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |