libp2r2p 0.10.3 → 0.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -278,6 +278,12 @@ NIP-44 v2 uses the interoperable `nip44-v2` salt by default. A custom UTF-8
278
278
  salt of at most 32 bytes may be passed to `getConversationKey()`, but messages
279
279
  derived with it are not interoperable with standard NIP-44 implementations.
280
280
 
281
+ NIP-46 clients and bunker signers use a 30-second operation timeout by
282
+ default. Set `timeout` in the `Nip46Client`/`BunkerSigner` constructor to
283
+ choose another default, override it for an individual `connect()` or RPC, or
284
+ pass `timeout: null` explicitly when an operation is intentionally allowed to
285
+ wait indefinitely.
286
+
281
287
  Nostr Web Tokens are available from `libp2r2p/nwt`. Creation returns a signed
282
288
  kind `27519` event, while transport encoding is kept separate:
283
289
 
@@ -129,7 +129,9 @@ export class Nip46Client {
129
129
  get pointer () { return { ...this.#pointer, relays: [...this.#pointer.relays] } }
130
130
 
131
131
  // Connects and immediately asks the remote signer for its preferred relays.
132
- async connect ({ requestedPermissions = [], clientMetadata, timeout = null, signal } = {}) {
132
+ // An omitted timeout inherits the configurable constructor timeout; null
133
+ // explicitly disables the response deadline.
134
+ async connect ({ requestedPermissions = [], clientMetadata, timeout, signal } = {}) {
133
135
  const permissions = Array.isArray(requestedPermissions)
134
136
  ? requestedPermissions.filter(permission => typeof permission === 'string' && permission).join(',')
135
137
  : ''
@@ -59,7 +59,7 @@ export class Nip46Transport {
59
59
  #secretKey
60
60
  #pubkey
61
61
  #relayPool
62
- #networkTimeout
62
+ #operationTimeout
63
63
  #timeoutAfterFirstEose
64
64
  #onError
65
65
  #contexts = new Set()
@@ -80,7 +80,7 @@ export class Nip46Transport {
80
80
  this.#secretKey = secretKey
81
81
  this.#pubkey = getPublicKey(secretKey)
82
82
  this.#relayPool = relayPool
83
- this.#networkTimeout = networkTimeout
83
+ this.#operationTimeout = networkTimeout
84
84
  this.#timeoutAfterFirstEose = timeoutAfterFirstEose
85
85
  this.#onError = onError
86
86
  }
@@ -111,7 +111,7 @@ export class Nip46Transport {
111
111
  return context
112
112
  }
113
113
 
114
- async awaitContextReady (context, { timeout = this.#networkTimeout, signal } = {}) {
114
+ async awaitContextReady (context, { timeout = this.#operationTimeout, signal } = {}) {
115
115
  const report = await waitForNip46(context.stream.ready, {
116
116
  timeout,
117
117
  signal,
@@ -159,11 +159,14 @@ export class Nip46Transport {
159
159
  return true
160
160
  }
161
161
 
162
- async sendRequest (peerPubkey, method, params = [], {
163
- timeout = null,
164
- signal,
165
- extension
166
- } = {}) {
162
+ async sendRequest (peerPubkey, method, params = [], options = {}) {
163
+ const {
164
+ // Undefined inherits the constructor-wide operation timeout. Passing
165
+ // null explicitly is the opt-out for RPCs that may wait indefinitely.
166
+ timeout = this.#operationTimeout,
167
+ signal,
168
+ extension
169
+ } = options
167
170
  if (this.#closed) throw new Error('NIP46_CLOSED')
168
171
  if (typeof method !== 'string' || !method) throw new ValidationError('NIP46_METHOD_REQUIRED')
169
172
  if (!Array.isArray(params) || !params.every(param => typeof param === 'string')) {
@@ -229,7 +232,7 @@ export class Nip46Transport {
229
232
  if (!relays.length) throw new Error('NIP46_NO_READY_RELAYS')
230
233
  const event = createNip46Event({ secretKey: this.#secretKey, recipientPubkey: peerPubkey, payload })
231
234
  const published = await this.#relayPool.sendEvent(event, relays, {
232
- timeout: this.#networkTimeout,
235
+ timeout: this.#operationTimeout,
233
236
  timeoutUntilFirstFulfillment: null
234
237
  })
235
238
  if (!published.success) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2r2p",
3
- "version": "0.10.3",
3
+ "version": "0.10.4",
4
4
  "description": "Peer-to-relay-to-peer",
5
5
  "keywords": [
6
6
  "p2r2p",