From ab5ea8de369e7fe8d612ed6d3e5f38277d16e0b4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Thu, 16 Feb 2023 09:29:21 -0300 Subject: [PATCH] another nip57 helper and bump version. --- nip57.ts | 34 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/nip57.ts b/nip57.ts index e0d50e7..5fd8ca7 100644 --- a/nip57.ts +++ b/nip57.ts @@ -71,3 +71,37 @@ export function makeZapRequest({ return zr } + +export function makeZapReceipt({ + zapRequest, + preimage, + bolt11, + paidAt +}: { + zapRequest: string + preimage: string | null + bolt11: string + paidAt: Date +}): EventTemplate { + let zr: Event = JSON.parse(zapRequest) + let tagsFromZapRequest = zr.tags.filter( + ([t]) => t === 'e' || t === 'p' || t === 'a' + ) + + let zap = { + kind: 9735, + created_at: Math.round(paidAt.getTime() / 1000), + content: '', + tags: [ + ...tagsFromZapRequest, + ['bolt11', bolt11], + ['description', zapRequest] + ] + } + + if (preimage) { + zap.tags.push(['preimage', preimage]) + } + + return zap +} diff --git a/package.json b/package.json index 73be3b2..d88fb18 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nostr-tools", - "version": "1.4.1", + "version": "1.4.2", "description": "Tools for making a Nostr client.", "repository": { "type": "git",