mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
nip46: NostrConnectAdmin kind and handle "auth_url".
This commit is contained in:
1
kinds.ts
1
kinds.ts
@@ -78,6 +78,7 @@ export const ClientAuth = 22242
|
||||
export const NWCWalletRequest = 23194
|
||||
export const NWCWalletResponse = 23195
|
||||
export const NostrConnect = 24133
|
||||
export const NostrConnectAdmin = 24134
|
||||
export const HTTPAuth = 27235
|
||||
export const Followsets = 30000
|
||||
export const Genericlists = 30001
|
||||
|
||||
22
nip46.ts
22
nip46.ts
@@ -4,7 +4,7 @@ import { AbstractSimplePool, SubCloser } from './abstract-pool.ts'
|
||||
import { decrypt, encrypt } from './nip04.ts'
|
||||
import { NIP05_REGEX } from './nip05.ts'
|
||||
import { SimplePool } from './pool.ts'
|
||||
import { Handlerinformation, NostrConnect } from './kinds.ts'
|
||||
import { Handlerinformation, NostrConnect, NostrConnectAdmin } from './kinds.ts'
|
||||
|
||||
var _fetch: any
|
||||
|
||||
@@ -87,7 +87,7 @@ export class BunkerSigner {
|
||||
* @param remotePubkey - An optional remote public key. This is the key you want to sign as.
|
||||
* @param secretKey - An optional key pair.
|
||||
*/
|
||||
public constructor(clientSecretKey: Uint8Array, bp: BunkerPointer) {
|
||||
public constructor(clientSecretKey: Uint8Array, bp: BunkerPointer, params: { onauth?: (url: string) => void } = {}) {
|
||||
this.pool = new SimplePool()
|
||||
this.secretKey = clientSecretKey
|
||||
this.relays = bp.relays
|
||||
@@ -102,13 +102,18 @@ export class BunkerSigner {
|
||||
|
||||
this.subCloser = this.pool.subscribeMany(
|
||||
this.relays,
|
||||
[{ kinds: [NostrConnect, 24134], '#p': [getPublicKey(this.secretKey)] }],
|
||||
[{ kinds: [NostrConnect, NostrConnectAdmin], '#p': [getPublicKey(this.secretKey)] }],
|
||||
{
|
||||
async onevent(event: NostrEvent) {
|
||||
const decryptedContent = await decrypt(clientSecretKey, event.pubkey, event.content)
|
||||
const parsedContent = JSON.parse(decryptedContent)
|
||||
const { id, result, error } = parsedContent
|
||||
|
||||
if (result === 'auth_url') {
|
||||
params.onauth?.(error)
|
||||
return
|
||||
}
|
||||
|
||||
let handler = listeners[id]
|
||||
if (handler) {
|
||||
if (error) handler.reject(error)
|
||||
@@ -143,7 +148,7 @@ export class BunkerSigner {
|
||||
// the request event
|
||||
const verifiedEvent: VerifiedEvent = finalizeEvent(
|
||||
{
|
||||
kind: method === 'create_account' ? 24134 : NostrConnect,
|
||||
kind: method === 'create_account' ? NostrConnectAdmin : NostrConnect,
|
||||
tags: [['p', this.remotePubkey]],
|
||||
content: encryptedContent,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
@@ -154,15 +159,6 @@ export class BunkerSigner {
|
||||
// setup callback listener
|
||||
this.listeners[id] = { resolve, reject }
|
||||
|
||||
// Build auth_url handler
|
||||
// const authHandler = (response: Response) => {
|
||||
// if (response.result) {
|
||||
// this.emit('authChallengeSuccess', response)
|
||||
// } else {
|
||||
// this.emit('authChallengeError', response.error)
|
||||
// }
|
||||
// }
|
||||
|
||||
// publish the event
|
||||
await Promise.any(this.pool.publish(this.relays, verifiedEvent))
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user