mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
partial nip57 support.
This commit is contained in:
14
event.ts
14
event.ts
@@ -25,20 +25,22 @@ export enum Kind {
|
|||||||
Article = 30023
|
Article = 30023
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Event = {
|
export type EventTemplate = {
|
||||||
id?: string
|
|
||||||
sig?: string
|
|
||||||
kind: Kind
|
kind: Kind
|
||||||
tags: string[][]
|
tags: string[][]
|
||||||
pubkey: string
|
|
||||||
content: string
|
content: string
|
||||||
created_at: number
|
created_at: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBlankEvent(): Event {
|
export type Event = EventTemplate & {
|
||||||
|
pubkey: string
|
||||||
|
id: string
|
||||||
|
sig: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getBlankEvent(): EventTemplate {
|
||||||
return {
|
return {
|
||||||
kind: 255,
|
kind: 255,
|
||||||
pubkey: '',
|
|
||||||
content: '',
|
content: '',
|
||||||
tags: [],
|
tags: [],
|
||||||
created_at: 0
|
created_at: 0
|
||||||
|
|||||||
1
index.ts
1
index.ts
@@ -9,6 +9,7 @@ export * as nip05 from './nip05'
|
|||||||
export * as nip06 from './nip06'
|
export * as nip06 from './nip06'
|
||||||
export * as nip19 from './nip19'
|
export * as nip19 from './nip19'
|
||||||
export * as nip26 from './nip26'
|
export * as nip26 from './nip26'
|
||||||
|
export * as nip57 from './nip57'
|
||||||
|
|
||||||
export * as fj from './fakejson'
|
export * as fj from './fakejson'
|
||||||
export * as utils from './utils'
|
export * as utils from './utils'
|
||||||
|
|||||||
73
nip57.ts
Normal file
73
nip57.ts
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import {bech32} from '@scure/base'
|
||||||
|
|
||||||
|
import {Event, EventTemplate} from './event'
|
||||||
|
import {utf8Decoder} from './utils'
|
||||||
|
|
||||||
|
var _fetch: any
|
||||||
|
|
||||||
|
try {
|
||||||
|
_fetch = fetch
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
export function useFetchImplementation(fetchImplementation: any) {
|
||||||
|
_fetch = fetchImplementation
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getZapEndpoint(metadata: Event): Promise<null | string> {
|
||||||
|
try {
|
||||||
|
let lnurl: string = ''
|
||||||
|
let {lud06, lud16} = JSON.parse(metadata.content)
|
||||||
|
if (lud06) {
|
||||||
|
let {words} = bech32.decode(lud06, 1000)
|
||||||
|
let data = bech32.fromWords(words)
|
||||||
|
lnurl = utf8Decoder.decode(data)
|
||||||
|
} else if (lud16) {
|
||||||
|
let [name, domain] = lud16.split('@')
|
||||||
|
lnurl = `https://${domain}/.well-known/lnurlp/${name}`
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = await _fetch(lnurl)
|
||||||
|
let body = await res.json()
|
||||||
|
|
||||||
|
if (body.allowsNostr && body.nostrPubkey) {
|
||||||
|
return body.callback
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
/*-*/
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function makeZapRequest({
|
||||||
|
profile,
|
||||||
|
event,
|
||||||
|
amount,
|
||||||
|
relays,
|
||||||
|
comment = ''
|
||||||
|
}: {
|
||||||
|
profile: string
|
||||||
|
event: string | null
|
||||||
|
amount: string
|
||||||
|
comment: string
|
||||||
|
relays: string[]
|
||||||
|
}): EventTemplate {
|
||||||
|
let zr = {
|
||||||
|
kind: 9734,
|
||||||
|
created_at: Math.round(Date.now() / 1000),
|
||||||
|
content: comment,
|
||||||
|
tags: [
|
||||||
|
['p', profile],
|
||||||
|
['amount', amount],
|
||||||
|
['relays', ...relays]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event) {
|
||||||
|
zr.tags.push(['e', event])
|
||||||
|
}
|
||||||
|
|
||||||
|
return zr
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user