mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
nip57: use Kind enum instead of using the number directly
This commit is contained in:
14
nip57.ts
14
nip57.ts
@@ -1,6 +1,6 @@
|
|||||||
import {bech32} from '@scure/base'
|
import {bech32} from '@scure/base'
|
||||||
|
|
||||||
import {Event, EventTemplate, validateEvent, verifySignature} from './event'
|
import {Event, EventTemplate, validateEvent, verifySignature, Kind} from './event'
|
||||||
import {utf8Decoder} from './utils'
|
import {utf8Decoder} from './utils'
|
||||||
|
|
||||||
var _fetch: any
|
var _fetch: any
|
||||||
@@ -13,7 +13,7 @@ export function useFetchImplementation(fetchImplementation: any) {
|
|||||||
_fetch = fetchImplementation
|
_fetch = fetchImplementation
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getZapEndpoint(metadata: Event<0>): Promise<null | string> {
|
export async function getZapEndpoint(metadata: Event<Kind.Metadata>): Promise<null | string> {
|
||||||
try {
|
try {
|
||||||
let lnurl: string = ''
|
let lnurl: string = ''
|
||||||
let {lud06, lud16} = JSON.parse(metadata.content)
|
let {lud06, lud16} = JSON.parse(metadata.content)
|
||||||
@@ -53,11 +53,11 @@ export function makeZapRequest({
|
|||||||
amount: number
|
amount: number
|
||||||
comment: string
|
comment: string
|
||||||
relays: string[]
|
relays: string[]
|
||||||
}): EventTemplate<9734> {
|
}): EventTemplate<Kind.ZapRequest> {
|
||||||
if (!amount) throw new Error('amount not given')
|
if (!amount) throw new Error('amount not given')
|
||||||
if (!profile) throw new Error('profile not given')
|
if (!profile) throw new Error('profile not given')
|
||||||
|
|
||||||
let zr: EventTemplate<9734> = {
|
let zr: EventTemplate<Kind.ZapRequest> = {
|
||||||
kind: 9734,
|
kind: 9734,
|
||||||
created_at: Math.round(Date.now() / 1000),
|
created_at: Math.round(Date.now() / 1000),
|
||||||
content: comment,
|
content: comment,
|
||||||
@@ -113,13 +113,13 @@ export function makeZapReceipt({
|
|||||||
preimage: string | null
|
preimage: string | null
|
||||||
bolt11: string
|
bolt11: string
|
||||||
paidAt: Date
|
paidAt: Date
|
||||||
}): EventTemplate<9735> {
|
}): EventTemplate<Kind.Zap> {
|
||||||
let zr: Event<9734> = JSON.parse(zapRequest)
|
let zr: Event<Kind.ZapRequest> = JSON.parse(zapRequest)
|
||||||
let tagsFromZapRequest = zr.tags.filter(
|
let tagsFromZapRequest = zr.tags.filter(
|
||||||
([t]) => t === 'e' || t === 'p' || t === 'a'
|
([t]) => t === 'e' || t === 'p' || t === 'a'
|
||||||
)
|
)
|
||||||
|
|
||||||
let zap: EventTemplate<9735> = {
|
let zap: EventTemplate<Kind.Zap> = {
|
||||||
kind: 9735,
|
kind: 9735,
|
||||||
created_at: Math.round(paidAt.getTime() / 1000),
|
created_at: Math.round(paidAt.getTime() / 1000),
|
||||||
content: '',
|
content: '',
|
||||||
|
|||||||
Reference in New Issue
Block a user