chore: Bump version and document NIP-46 usage
This commit is contained in:
parent
8866042edf
commit
0e6e7af934
|
@ -191,7 +191,7 @@ const localSecretKey = generateSecretKey()
|
||||||
|
|
||||||
### Method 1: Using a Bunker URI (`bunker://`)
|
### Method 1: Using a Bunker URI (`bunker://`)
|
||||||
|
|
||||||
This is the bunker-initiated flow. Your client receives a `bunker://` string or a NIP-05 identifier from the user. You use `BunkerSigner.fromBunker()` to create an instance, which returns immediately. You must then explicitly call `await bunker.connect()` to establish the connection with the bunker.
|
This is the bunker-initiated flow. Your client receives a `bunker://` string or a NIP-05 identifier from the user. You use `BunkerSigner.fromBunker()` to create an instance, which returns immediately. For the **initial connection** with a new bunker, you must explicitly call `await bunker.connect()` to establish the connection and receive authorization.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { BunkerSigner, parseBunkerInput } from '@nostr/tools/nip46'
|
import { BunkerSigner, parseBunkerInput } from '@nostr/tools/nip46'
|
||||||
|
@ -221,6 +221,7 @@ const event = await bunker.signEvent({
|
||||||
await signer.close()
|
await signer.close()
|
||||||
pool.close([])
|
pool.close([])
|
||||||
```
|
```
|
||||||
|
> **Note on Reconnecting:** Once a connection has been successfully established and the `BunkerPointer` is stored, you do **not** need to call `await bunker.connect()` on subsequent sessions.
|
||||||
|
|
||||||
### Method 2: Using a Client-generated URI (`nostrconnect://`)
|
### Method 2: Using a Client-generated URI (`nostrconnect://`)
|
||||||
|
|
||||||
|
@ -260,6 +261,7 @@ const event = await signer.signEvent({
|
||||||
await signer.close()
|
await signer.close()
|
||||||
pool.close([])
|
pool.close([])
|
||||||
```
|
```
|
||||||
|
> **Note on Persistence:** This method is ideal for the initial sign-in. To allow users to stay logged in across sessions, you should store the connection details and use `Method 1` for subsequent reconnections.
|
||||||
|
|
||||||
### Parsing thread from any note based on NIP-10
|
### Parsing thread from any note based on NIP-10
|
||||||
|
|
||||||
|
|
2
jsr.json
2
jsr.json
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.16.2",
|
"version": "2.17.0",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.ts",
|
||||||
|
|
8
nip46.ts
8
nip46.ts
|
@ -97,7 +97,7 @@ export type ParsedNostrConnectURI = {
|
||||||
name?: string
|
name?: string
|
||||||
url?: string
|
url?: string
|
||||||
image?: string
|
image?: string
|
||||||
};
|
}
|
||||||
originalString: string
|
originalString: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,6 @@ export function parseNostrConnectURI(uri: string): ParsedNostrConnectURI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type BunkerSignerParams = {
|
export type BunkerSignerParams = {
|
||||||
pool?: AbstractSimplePool
|
pool?: AbstractSimplePool
|
||||||
onauth?: (url: string) => void
|
onauth?: (url: string) => void
|
||||||
|
@ -236,7 +235,7 @@ export class BunkerSigner implements Signer {
|
||||||
public static fromBunker(
|
public static fromBunker(
|
||||||
clientSecretKey: Uint8Array,
|
clientSecretKey: Uint8Array,
|
||||||
bp: BunkerPointer,
|
bp: BunkerPointer,
|
||||||
params: BunkerSignerParams = {}
|
params: BunkerSignerParams = {},
|
||||||
): BunkerSigner {
|
): BunkerSigner {
|
||||||
if (bp.relays.length === 0) {
|
if (bp.relays.length === 0) {
|
||||||
throw new Error('No relays specified for this bunker')
|
throw new Error('No relays specified for this bunker')
|
||||||
|
@ -304,12 +303,11 @@ export class BunkerSigner implements Signer {
|
||||||
reject(new Error('Subscription closed before connection was established.'))
|
reject(new Error('Subscription closed before connection was established.'))
|
||||||
},
|
},
|
||||||
maxWait,
|
maxWait,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private setupSubscription(params: BunkerSignerParams) {
|
private setupSubscription(params: BunkerSignerParams) {
|
||||||
const listeners = this.listeners
|
const listeners = this.listeners
|
||||||
const waitingForAuth = this.waitingForAuth
|
const waitingForAuth = this.waitingForAuth
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.16.2",
|
"version": "2.17.0",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
Loading…
Reference in New Issue