Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions nip57.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -49,7 +50,7 @@ export function makeZapRequest({
comment = '',
}: {
profile: string
event: string | null
event: string | Event | null
amount: number
comment: string
relays: string[]
Expand All @@ -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
}
Expand Down