diff --git a/src/nostr.ts b/src/nostr.ts index 4b4cd80..af68454 100644 --- a/src/nostr.ts +++ b/src/nostr.ts @@ -1,6 +1,7 @@ import NDK, {NDKEvent, NDKPrivateKeySigner, NDKUser} from "@nostr-dev-kit/ndk"; import {generateSecretKey} from "nostr-tools"; import {randomTimeUpTo2DaysInThePast} from "./general.ts"; +import {decode as nip19Decode, npubEncode} from "nostr-tools/nip19"; export async function encryptEventForRecipient( ndk: NDK, @@ -25,3 +26,14 @@ export async function encryptEventForRecipient( giftWrap.ndk = ndk; return giftWrap; } + +export function npubToPubKeyString(npub: string) { + const decoded = nip19Decode(npub); + if (decoded.type !== 'npub') + throw new Error('Invalid npub'); + return decoded.data; +} + +export function pubKeyStringToNpub(pubKey: string) { + return npubEncode(pubKey); +}