From 3083a8675ee2378513d63954ca1bd5468f738660 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Sat, 13 Sep 2025 15:11:04 -0500 Subject: Add message decryption Currently, this just takes a message from the text box and returns its decrypted version, but next I will make it decrypt messages it gets from relays. This code works with both NIP-07 (window.nostr) and getPrivateKey(). If both are available, it chooses NIP-07 like the encryption code. --- src/lib/nip17.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/lib') diff --git a/src/lib/nip17.ts b/src/lib/nip17.ts index 6a9888b6..84790275 100644 --- a/src/lib/nip17.ts +++ b/src/lib/nip17.ts @@ -78,3 +78,14 @@ const giftWrap = (event: object, receiverPK: string) => { return finalizeEvent(giftWrapEvent, secretKey); } + +export const decryptNIP17MessageNIP07 = async (text: string): string => { + const wrapped = JSON.parse(text); + const sealedText = await window.nostr.nip44.decrypt( + wrapped.pubkey, wrapped.content); + const sealed = JSON.parse(sealedText); + const rumourText = await window.nostr.nip44.decrypt( + sealed.pubkey, sealed.content); + const rumour = JSON.parse(rumourText); + return rumour.content; +} -- cgit v1.2.3