From 44a679e6429b9c10abe45a5d85406dbd1c89c53c Mon Sep 17 00:00:00 2001 From: bitcoinpirate Date: Sun, 23 Feb 2025 16:46:51 +0100 Subject: [PATCH] added support for zapping replaceable events (#424) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added support for zapping replaceable events * Update nip57.ts * Update nip57.ts Co-authored-by: 雪猫 * apply @SnowCait's suggestions. * fix lint error. --------- Co-authored-by: AsaiToshiya Co-authored-by: 雪猫 --- nip57.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/nip57.ts b/nip57.ts index a95a52d..0736e2f 100644 --- a/nip57.ts +++ b/nip57.ts @@ -2,6 +2,7 @@ import { bech32 } from '@scure/base' import { validateEvent, verifyEvent, type Event, type EventTemplate } from './pure.ts' import { utf8Decoder } from './utils.ts' +import { isReplaceableKind, isAddressableKind } from './kinds.ts' var _fetch: any @@ -49,7 +50,7 @@ export function makeZapRequest({ comment = '', }: { profile: string - event: string | null + event: string | Event | null amount: number comment: string relays: string[] @@ -68,9 +69,22 @@ export function makeZapRequest({ ], } - if (event) { + if (event && typeof event === 'string') { zr.tags.push(['e', event]) } + if (event && typeof event === 'object') { + // replacable event + if (isReplaceableKind(event.kind)) { + const a = ['a', `${event.kind}:${event.pubkey}:`] + zr.tags.push(a) + // addressable event + } else if (isAddressableKind(event.kind)) { + let d = event.tags.find(([t, v]) => t === 'd' && v) + if (!d) throw new Error('d tag not found or is empty') + const a = ['a', `${event.kind}:${event.pubkey}:${d[1]}`] + zr.tags.push(a) + } + } return zr }