diff options
| author | Adrien Hopkins <[email protected]> | 2025-09-13 15:11:04 -0500 |
|---|---|---|
| committer | Adrien Hopkins <[email protected]> | 2025-09-13 15:11:04 -0500 |
| commit | 3083a8675ee2378513d63954ca1bd5468f738660 (patch) | |
| tree | 447b76cbe3f5c97d539f5cd5ba86cf1f4d8e9a60 /src/lib | |
| parent | b7df8fc8c7824049206b0d2afc840acda6c1c5ee (diff) | |
| download | coinos-ui-3083a8675ee2378513d63954ca1bd5468f738660.tar.gz coinos-ui-3083a8675ee2378513d63954ca1bd5468f738660.zip | |
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.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/nip17.ts | 11 |
1 files changed, 11 insertions, 0 deletions
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; +} |
