mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-09 00:28:51 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce059d4608 | ||
|
|
b72b0dc1f0 | ||
|
|
29e5b71473 |
51
nip46.ts
51
nip46.ts
@@ -5,6 +5,7 @@ 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, NostrConnectAdmin } from './kinds.ts'
|
||||||
|
import { hexToBytes } from '@noble/hashes/utils'
|
||||||
|
|
||||||
var _fetch: any
|
var _fetch: any
|
||||||
|
|
||||||
@@ -182,9 +183,8 @@ export class BunkerSigner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a ping request to the remote server.
|
* Calls the "connect" method on the bunker.
|
||||||
* Requires permission/access rights to bunker.
|
* The promise will be rejected if the response is not "pong".
|
||||||
* @returns "Pong" if successful. The promise will reject if the response is not "pong".
|
|
||||||
*/
|
*/
|
||||||
async ping(): Promise<void> {
|
async ping(): Promise<void> {
|
||||||
let resp = await this.sendRequest('ping', [])
|
let resp = await this.sendRequest('ping', [])
|
||||||
@@ -192,17 +192,27 @@ export class BunkerSigner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects to a remote server using the provided keys and remote public key.
|
* Calls the "connect" method on the bunker.
|
||||||
* Optionally, a secret can be provided for additional authentication.
|
|
||||||
*
|
|
||||||
* @param remotePubkey - Optional the remote public key to connect to.
|
|
||||||
* @param secret - Optional secret for additional authentication.
|
|
||||||
* @returns "ack" if successful. The promise will reject if the response is not "ack".
|
|
||||||
*/
|
*/
|
||||||
async connect(): Promise<void> {
|
async connect(): Promise<void> {
|
||||||
await this.sendRequest('connect', [getPublicKey(this.secretKey), this.connectionSecret])
|
await this.sendRequest('connect', [getPublicKey(this.secretKey), this.connectionSecret])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This was supposed to call the "get_public_key" method on the bunker,
|
||||||
|
* but instead we just returns the public key we already know.
|
||||||
|
*/
|
||||||
|
async getPublicKey(): Promise<string> {
|
||||||
|
return this.remotePubkey
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calls the "get_relays" method on the bunker.
|
||||||
|
*/
|
||||||
|
async getRelays(): Promise<{ [relay: string]: { read: boolean; write: boolean } }> {
|
||||||
|
return JSON.parse(await this.sendRequest('get_relays', []))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs an event using the remote private key.
|
* Signs an event using the remote private key.
|
||||||
* @param event - The event to sign.
|
* @param event - The event to sign.
|
||||||
@@ -217,6 +227,27 @@ export class BunkerSigner {
|
|||||||
throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(signed)}`)
|
throw new Error(`event returned from bunker is improperly signed: ${JSON.stringify(signed)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async nip04Encrypt(thirdPartyPubkey: string, plaintext: string): Promise<string> {
|
||||||
|
return await this.sendRequest('nip04_encrypt', [thirdPartyPubkey, plaintext])
|
||||||
|
}
|
||||||
|
|
||||||
|
async nip04Decrypt(thirdPartyPubkey: string, ciphertext: string): Promise<string> {
|
||||||
|
return await this.sendRequest('nip04_decrypt', [thirdPartyPubkey, ciphertext])
|
||||||
|
}
|
||||||
|
|
||||||
|
async nip44GetKey(thirdPartyPubkey: string): Promise<Uint8Array> {
|
||||||
|
let resp = await this.sendRequest('nip44_get_key', [thirdPartyPubkey])
|
||||||
|
return hexToBytes(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
async nip44Encrypt(thirdPartyPubkey: string, plaintext: string): Promise<string> {
|
||||||
|
return await this.sendRequest('nip44_encrypt', [thirdPartyPubkey, plaintext])
|
||||||
|
}
|
||||||
|
|
||||||
|
async nip44Decrypt(thirdPartyPubkey: string, ciphertext: string): Promise<string> {
|
||||||
|
return await this.sendRequest('nip44_encrypt', [thirdPartyPubkey, ciphertext])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,7 +285,7 @@ export async function createAccount(
|
|||||||
* Fetches info on available providers that announce themselves using NIP-89 events.
|
* Fetches info on available providers that announce themselves using NIP-89 events.
|
||||||
* @returns A promise that resolves to an array of available bunker objects.
|
* @returns A promise that resolves to an array of available bunker objects.
|
||||||
*/
|
*/
|
||||||
export async function fetchCustodialbunkers(pool: AbstractSimplePool, relays: string[]): Promise<BunkerProfile[]> {
|
export async function fetchCustodialBunkers(pool: AbstractSimplePool, relays: string[]): Promise<BunkerProfile[]> {
|
||||||
const events = await pool.querySync(relays, {
|
const events = await pool.querySync(relays, {
|
||||||
kinds: [Handlerinformation],
|
kinds: [Handlerinformation],
|
||||||
'#k': [NostrConnect.toString()],
|
'#k': [NostrConnect.toString()],
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.1.7",
|
"version": "2.1.8",
|
||||||
"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