added support for zapping replaceable events (#424)

* added support for zapping replaceable events

* Update nip57.ts

* Update nip57.ts

Co-authored-by: 雪猫 <SnowCait@users.noreply.github.com>

* apply @SnowCait's suggestions.

* fix lint error.

---------

Co-authored-by: AsaiToshiya <to.asai.60@gmail.com>
Co-authored-by: 雪猫 <SnowCait@users.noreply.github.com>
This commit is contained in:
bitcoinpirate 2025-02-23 16:46:51 +01:00 committed by GitHub
parent c1172caf1d
commit 44a679e642
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 2 deletions

View File

@ -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
}