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",