mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
nip57: include "k" tag.
This commit is contained in:
2
jsr.json
2
jsr.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.16.0",
|
"version": "2.16.1",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|||||||
53
nip57.ts
53
nip57.ts
@@ -1,6 +1,6 @@
|
|||||||
import { bech32 } from '@scure/base'
|
import { bech32 } from '@scure/base'
|
||||||
|
|
||||||
import { validateEvent, verifyEvent, type Event, type EventTemplate } from './pure.ts'
|
import { NostrEvent, validateEvent, verifyEvent, type Event, type EventTemplate } from './pure.ts'
|
||||||
import { utf8Decoder } from './utils.ts'
|
import { utf8Decoder } from './utils.ts'
|
||||||
import { isReplaceableKind, isAddressableKind } from './kinds.ts'
|
import { isReplaceableKind, isAddressableKind } from './kinds.ts'
|
||||||
|
|
||||||
@@ -42,48 +42,43 @@ export async function getZapEndpoint(metadata: Event): Promise<null | string> {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeZapRequest({
|
type ProfileZap = {
|
||||||
profile,
|
pubkey: string
|
||||||
event,
|
|
||||||
amount,
|
|
||||||
relays,
|
|
||||||
comment = '',
|
|
||||||
}: {
|
|
||||||
profile: string
|
|
||||||
event: string | Event | null
|
|
||||||
amount: number
|
amount: number
|
||||||
comment: string
|
comment?: string
|
||||||
relays: string[]
|
relays: string[]
|
||||||
}): EventTemplate {
|
}
|
||||||
if (!amount) throw new Error('amount not given')
|
|
||||||
if (!profile) throw new Error('profile not given')
|
|
||||||
|
|
||||||
|
type EventZap = {
|
||||||
|
event: NostrEvent
|
||||||
|
amount: number
|
||||||
|
comment?: string
|
||||||
|
relays: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeZapRequest(params: ProfileZap | EventZap): EventTemplate {
|
||||||
let zr: EventTemplate = {
|
let zr: EventTemplate = {
|
||||||
kind: 9734,
|
kind: 9734,
|
||||||
created_at: Math.round(Date.now() / 1000),
|
created_at: Math.round(Date.now() / 1000),
|
||||||
content: comment,
|
content: params.comment || '',
|
||||||
tags: [
|
tags: [
|
||||||
['p', profile],
|
['p', 'pubkey' in params ? params.pubkey : params.event.pubkey],
|
||||||
['amount', amount.toString()],
|
['amount', params.amount.toString()],
|
||||||
['relays', ...relays],
|
['relays', ...params.relays],
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event && typeof event === 'string') {
|
if ('event' in params) {
|
||||||
zr.tags.push(['e', event])
|
if (isReplaceableKind(params.event.kind)) {
|
||||||
}
|
const a = ['a', `${params.event.kind}:${params.event.pubkey}:`]
|
||||||
if (event && typeof event === 'object') {
|
|
||||||
// replacable event
|
|
||||||
if (isReplaceableKind(event.kind)) {
|
|
||||||
const a = ['a', `${event.kind}:${event.pubkey}:`]
|
|
||||||
zr.tags.push(a)
|
zr.tags.push(a)
|
||||||
// addressable event
|
} else if (isAddressableKind(params.event.kind)) {
|
||||||
} else if (isAddressableKind(event.kind)) {
|
let d = params.event.tags.find(([t, v]) => t === 'd' && v)
|
||||||
let d = event.tags.find(([t, v]) => t === 'd' && v)
|
|
||||||
if (!d) throw new Error('d tag not found or is empty')
|
if (!d) throw new Error('d tag not found or is empty')
|
||||||
const a = ['a', `${event.kind}:${event.pubkey}:${d[1]}`]
|
const a = ['a', `${params.event.kind}:${params.event.pubkey}:${d[1]}`]
|
||||||
zr.tags.push(a)
|
zr.tags.push(a)
|
||||||
}
|
}
|
||||||
|
zr.tags.push(['k', params.event.kind.toString()])
|
||||||
}
|
}
|
||||||
|
|
||||||
return zr
|
return zr
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.16.0",
|
"version": "2.16.1",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user