libp2r2p 0.12.17 → 0.12.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2r2p",
3
- "version": "0.12.17",
3
+ "version": "0.12.18",
4
4
  "description": "Peer-to-relay-to-peer",
5
5
  "keywords": [
6
6
  "p2r2p",
@@ -21,6 +21,8 @@
21
21
  // }
22
22
  // const { question } = await messenger.ask({ receiverPubkey, payload: { ping: true }, idempotencyKey: 'request:42' })
23
23
  // await messenger.reply({ question, payload: { ok: true }, idempotencyKey: 'reply:42' })
24
+ // Optional expiresAt (Unix seconds) can only shorten the channel default:
25
+ // await messenger.reply({ question, payload: { ok: true }, expiresAt: askExpiration })
24
26
  // await messenger.tell({ receiverPubkey, payload: { note: 'hello' }, idempotencyKey: 'notification:42' })
25
27
  // await messenger.yell({ receiverPubkeys, payload: { notice: 'hello all' }, idempotencyKey: 'notice:42' })
26
28
  // await messenger.broadcastRumor({ receiverPubkeys, rumor: { kind, tags: [], content } })
@@ -241,6 +243,16 @@ function nowSeconds () {
241
243
  return Math.floor(Date.now() / 1000)
242
244
  }
243
245
 
246
+ function replyExpirationSeconds (defaultSeconds, expiresAt, nowMs) {
247
+ if (expiresAt === undefined) return defaultSeconds
248
+ if (!Number.isSafeInteger(expiresAt) || expiresAt <= 0) {
249
+ throw new ValidationError('INVALID_EXPIRES_AT')
250
+ }
251
+ const now = Math.floor(nowMs / 1000)
252
+ if (expiresAt <= now) throw new ValidationError('QUESTION_EXPIRED')
253
+ return Math.min(defaultSeconds, expiresAt - now)
254
+ }
255
+
244
256
  function normalizeOfflineRecoverySeconds (value) {
245
257
  if (!Number.isSafeInteger(value) || value < 0 || value > MAX_OFFLINE_RECOVERY_SECONDS) {
246
258
  throw new ValidationError('INVALID_OFFLINE_RECOVERY_SECONDS')
@@ -2870,11 +2882,16 @@ export class PrivateMessenger {
2870
2882
  } finally { releaseActivity() }
2871
2883
  }
2872
2884
 
2873
- async reply ({ channelPubkey = this.defaultChannelPubkey(), question, receiverPubkey, relays, relayToReceivers, message, code, payload, error, content, idempotencyKey, deletionPubkey, useBulkPacing = false }) {
2885
+ async reply ({ channelPubkey = this.defaultChannelPubkey(), question, receiverPubkey, relays, relayToReceivers, message, code, payload, error, content, idempotencyKey, deletionPubkey, expiresAt, useBulkPacing = false }) {
2874
2886
  idempotencyKey = normalizeIdempotencyKey(idempotencyKey) || undefined
2875
2887
  const channel = this.requireWritableChannel(channelPubkey)
2876
2888
  const releaseActivity = this.decryptionScheduler.activity(channelPubkey)
2877
2889
  try {
2890
+ const expirationSeconds = replyExpirationSeconds(
2891
+ this.eventExpirationSecondsFor(channel),
2892
+ expiresAt,
2893
+ this._now()
2894
+ )
2878
2895
  const resolvedReceiverPubkey = receiverPubkey || question?.pubkey || ''
2879
2896
  const routing = await this.resolveSendRouting({ channel, receiverPubkeys: [resolvedReceiverPubkey], relays, relayToReceivers })
2880
2897
  this.debugSend('reply', channelPubkey, { code, receiverPubkey: receiverPubkey || question?.pubkey || '' })
@@ -2886,7 +2903,7 @@ export class PrivateMessenger {
2886
2903
  question,
2887
2904
  receiverPubkey,
2888
2905
  ...routing,
2889
- expirationSeconds: this.eventExpirationSecondsFor(channel),
2906
+ expirationSeconds,
2890
2907
  temporaryStorageArea: this.temporaryStorageArea,
2891
2908
  deletionPubkey,
2892
2909
  autoDeletionCapability: this.autoDeletionCapabilityFor(channel),