mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-10 17:18:51 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db6baf2e6b | ||
|
|
bb1e6f4356 | ||
|
|
5626d3048b |
1
kinds.ts
1
kinds.ts
@@ -78,7 +78,6 @@ export const ClientAuth = 22242
|
|||||||
export const NWCWalletRequest = 23194
|
export const NWCWalletRequest = 23194
|
||||||
export const NWCWalletResponse = 23195
|
export const NWCWalletResponse = 23195
|
||||||
export const NostrConnect = 24133
|
export const NostrConnect = 24133
|
||||||
export const NostrConnectAdmin = 24134
|
|
||||||
export const HTTPAuth = 27235
|
export const HTTPAuth = 27235
|
||||||
export const Followsets = 30000
|
export const Followsets = 30000
|
||||||
export const Genericlists = 30001
|
export const Genericlists = 30001
|
||||||
|
|||||||
14
nip46.ts
14
nip46.ts
@@ -4,7 +4,7 @@ import { AbstractSimplePool, SubCloser } from './abstract-pool.ts'
|
|||||||
import { decrypt, encrypt } from './nip04.ts'
|
import { decrypt, encrypt } from './nip04.ts'
|
||||||
import { NIP05_REGEX } from './nip05.ts'
|
import { NIP05_REGEX } from './nip05.ts'
|
||||||
import { SimplePool } from './pool.ts'
|
import { SimplePool } from './pool.ts'
|
||||||
import { Handlerinformation, NostrConnect, NostrConnectAdmin } from './kinds.ts'
|
import { Handlerinformation, NostrConnect } from './kinds.ts'
|
||||||
import { hexToBytes } from '@noble/hashes/utils'
|
import { hexToBytes } from '@noble/hashes/utils'
|
||||||
|
|
||||||
var _fetch: any
|
var _fetch: any
|
||||||
@@ -83,6 +83,7 @@ export class BunkerSigner {
|
|||||||
reject: (_: string) => void
|
reject: (_: string) => void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private waitingForAuth: { [id: string]: boolean }
|
||||||
private secretKey: Uint8Array
|
private secretKey: Uint8Array
|
||||||
public bp: BunkerPointer
|
public bp: BunkerPointer
|
||||||
|
|
||||||
@@ -104,17 +105,21 @@ export class BunkerSigner {
|
|||||||
this.idPrefix = Math.random().toString(36).substring(7)
|
this.idPrefix = Math.random().toString(36).substring(7)
|
||||||
this.serial = 0
|
this.serial = 0
|
||||||
this.listeners = {}
|
this.listeners = {}
|
||||||
|
this.waitingForAuth = {}
|
||||||
|
|
||||||
const listeners = this.listeners
|
const listeners = this.listeners
|
||||||
|
const waitingForAuth = this.waitingForAuth
|
||||||
|
|
||||||
this.subCloser = this.pool.subscribeMany(
|
this.subCloser = this.pool.subscribeMany(
|
||||||
this.bp.relays,
|
this.bp.relays,
|
||||||
[{ kinds: [NostrConnect, NostrConnectAdmin], '#p': [getPublicKey(this.secretKey)] }],
|
[{ kinds: [NostrConnect], '#p': [getPublicKey(this.secretKey)] }],
|
||||||
{
|
{
|
||||||
async onevent(event: NostrEvent) {
|
async onevent(event: NostrEvent) {
|
||||||
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
const { id, result, error } = JSON.parse(await decrypt(clientSecretKey, event.pubkey, event.content))
|
||||||
|
|
||||||
if (result === 'auth_url') {
|
if (result === 'auth_url' && waitingForAuth[id]) {
|
||||||
|
delete listeners[id]
|
||||||
|
|
||||||
if (params.onauth) {
|
if (params.onauth) {
|
||||||
params.onauth(error)
|
params.onauth(error)
|
||||||
} else {
|
} else {
|
||||||
@@ -155,7 +160,7 @@ export class BunkerSigner {
|
|||||||
// the request event
|
// the request event
|
||||||
const verifiedEvent: VerifiedEvent = finalizeEvent(
|
const verifiedEvent: VerifiedEvent = finalizeEvent(
|
||||||
{
|
{
|
||||||
kind: method === 'create_account' ? NostrConnectAdmin : NostrConnect,
|
kind: NostrConnect,
|
||||||
tags: [['p', this.bp.pubkey]],
|
tags: [['p', this.bp.pubkey]],
|
||||||
content: encryptedContent,
|
content: encryptedContent,
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
@@ -165,6 +170,7 @@ export class BunkerSigner {
|
|||||||
|
|
||||||
// setup callback listener
|
// setup callback listener
|
||||||
this.listeners[id] = { resolve, reject }
|
this.listeners[id] = { resolve, reject }
|
||||||
|
this.waitingForAuth[id] = true
|
||||||
|
|
||||||
// publish the event
|
// publish the event
|
||||||
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent))
|
await Promise.any(this.pool.publish(this.bp.relays, verifiedEvent))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.2.0",
|
"version": "2.2.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