diff options
| author | Adam Soltys <[email protected]> | 2025-02-27 09:38:41 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-02-27 09:38:41 -0800 |
| commit | d1c65a4e27cf3d67152caefbc1856dd47c38fe93 (patch) | |
| tree | 379b1324a234c494418d4650c7c656bd4afc781b /lib | |
| parent | 88175fc2e5cfc313372366018b2f5256382d6e52 (diff) | |
| download | coinos-server-d1c65a4e27cf3d67152caefbc1856dd47c38fe93.tar.gz coinos-server-d1c65a4e27cf3d67152caefbc1856dd47c38fe93.zip | |
encrypt nwc notifications
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/notifications.ts | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/notifications.ts b/lib/notifications.ts index e988a728..5d602291 100644 --- a/lib/notifications.ts +++ b/lib/notifications.ts @@ -7,7 +7,8 @@ import mqtt from "$lib/mqtt"; import { publish, serverSecret } from "$lib/nostr"; import { emit } from "$lib/sockets"; import { f, fiat, fmt, getUser, link, nada, t } from "$lib/utils"; -import { finalizeEvent } from "nostr-tools"; +import { hexToBytes } from "@noble/hashes/utils"; +import { finalizeEvent, nip04 } from "nostr-tools"; import webpush from "web-push"; if (config.vapid) { @@ -98,11 +99,13 @@ export const nwcNotify = async (p) => { settled_at: p.created, }; - const content = JSON.stringify({ + const payload = JSON.stringify({ notification_type: p.amount > 0 ? "payment_received" : "payment_sent", notification, }); + const content = await nip04.encrypt(serverSecret, pubkey, payload); + const unsigned = { content, tags: [["p", pubkey]], @@ -110,7 +113,7 @@ export const nwcNotify = async (p) => { created_at: Math.floor(Date.now() / 1000), }; - const event = finalizeEvent(unsigned, serverSecret); + const event = finalizeEvent(unsigned, hexToBytes(serverSecret)); publish(event).catch(nada); } |
