@open-e2ee/signal-protocol-sdk 13.2.0 → 13.3.0

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +1 -1
  3. package/SECURITY.md +2 -2
  4. package/dist/client/client.d.ts.map +1 -1
  5. package/dist/client/client.js +37 -4
  6. package/dist/client/client.js.map +1 -1
  7. package/dist/client/group-outbox.d.ts +2 -1
  8. package/dist/client/group-outbox.d.ts.map +1 -1
  9. package/dist/client/group-outbox.js +4 -1
  10. package/dist/client/group-outbox.js.map +1 -1
  11. package/dist/client/hosted-mailbox-subscription.d.ts +4 -2
  12. package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
  13. package/dist/client/hosted-mailbox-subscription.js +4 -2
  14. package/dist/client/hosted-mailbox-subscription.js.map +1 -1
  15. package/dist/client/receive-work-seed.d.ts +6 -2
  16. package/dist/client/receive-work-seed.d.ts.map +1 -1
  17. package/dist/client/receive-work-seed.js +4 -0
  18. package/dist/client/receive-work-seed.js.map +1 -1
  19. package/dist/client/relay-subscription.js +1 -1
  20. package/dist/client/relay-subscription.js.map +1 -1
  21. package/dist/client/retry-family.d.ts +69 -13
  22. package/dist/client/retry-family.d.ts.map +1 -1
  23. package/dist/client/retry-family.js +104 -11
  24. package/dist/client/retry-family.js.map +1 -1
  25. package/dist/client/send-timestamp.d.ts +67 -0
  26. package/dist/client/send-timestamp.d.ts.map +1 -0
  27. package/dist/client/send-timestamp.js +82 -0
  28. package/dist/client/send-timestamp.js.map +1 -0
  29. package/dist/client/signal-service-cipher.d.ts +5 -0
  30. package/dist/client/signal-service-cipher.d.ts.map +1 -1
  31. package/dist/client/signal-service-cipher.js +31 -5
  32. package/dist/client/signal-service-cipher.js.map +1 -1
  33. package/dist/client/types.d.ts +9 -0
  34. package/dist/client/types.d.ts.map +1 -1
  35. package/dist/client/types.js.map +1 -1
  36. package/dist/local/store/reliability.d.ts +6 -3
  37. package/dist/local/store/reliability.d.ts.map +1 -1
  38. package/dist/local/store/reliability.js +6 -3
  39. package/dist/local/store/reliability.js.map +1 -1
  40. package/dist/local/store/sqlite/convert-plaintext.d.ts +1 -7
  41. package/dist/local/store/sqlite/convert-plaintext.d.ts.map +1 -1
  42. package/dist/local/store/sqlite/convert-plaintext.js +1 -9
  43. package/dist/local/store/sqlite/convert-plaintext.js.map +1 -1
  44. package/dist/local/store/sqlite/file-name.d.ts +5 -0
  45. package/dist/local/store/sqlite/file-name.d.ts.map +1 -0
  46. package/dist/local/store/sqlite/file-name.js +7 -0
  47. package/dist/local/store/sqlite/file-name.js.map +1 -0
  48. package/dist/local/store/sqlite/open-store.d.ts.map +1 -1
  49. package/dist/local/store/sqlite/open-store.js +2 -1
  50. package/dist/local/store/sqlite/open-store.js.map +1 -1
  51. package/dist/local/store/sqlite/web/file-name.d.ts +22 -0
  52. package/dist/local/store/sqlite/web/file-name.d.ts.map +1 -0
  53. package/dist/local/store/sqlite/web/file-name.js +72 -0
  54. package/dist/local/store/sqlite/web/file-name.js.map +1 -0
  55. package/dist/local/store/sqlite/web/worker.js +5 -12
  56. package/dist/local/store/sqlite/web/worker.js.map +1 -1
  57. package/dist/local/store/web-sqlite/adapter.d.ts +5 -4
  58. package/dist/local/store/web-sqlite/adapter.d.ts.map +1 -1
  59. package/dist/local/store/web-sqlite/adapter.js +7 -4
  60. package/dist/local/store/web-sqlite/adapter.js.map +1 -1
  61. package/dist/local/vault/indexed-db.d.ts +7 -3
  62. package/dist/local/vault/indexed-db.d.ts.map +1 -1
  63. package/dist/local/vault/indexed-db.js +25 -21
  64. package/dist/local/vault/indexed-db.js.map +1 -1
  65. package/dist/types/api.d.ts +25 -0
  66. package/dist/types/api.d.ts.map +1 -1
  67. package/dist/types/errors.d.ts +69 -1
  68. package/dist/types/errors.d.ts.map +1 -1
  69. package/dist/types/errors.js +77 -1
  70. package/dist/types/errors.js.map +1 -1
  71. package/docs/ASSURANCE.md +1 -1
  72. package/docs/DEVIATIONS.md +3 -3
  73. package/docs/ERROR_HANDLING.md +1 -0
  74. package/docs/GETTING_STARTED.md +10 -0
  75. package/local/store/README.md +16 -9
  76. package/local/store/web-sqlite/README.md +22 -6
  77. package/package.json +1 -1
@@ -27,6 +27,7 @@ import { GroupReceiveRefusedError, GroupReceiveUnavailableError, refuseSyncFromO
27
27
  import { sizedReceiveWork } from '../local/store/receive-work.js';
28
28
  import { envelopeCiphertextBytes } from './delivery-error.js';
29
29
  import { GroupSenderKeyOperations } from './group-sender-key-operations.js';
30
+ import { checkNewSendTimestamp, withCheckedSendTimestamp, } from './send-timestamp.js';
30
31
  import { ContentHint } from '../types/messages.js';
31
32
  import { createDefaultSignalProtocolContentAdapter, } from './content-adapter.js';
32
33
  import * as CryptoUtils from '../internal/crypto/index.js';
@@ -490,6 +491,11 @@ export class SignalProtocolServiceCipher {
490
491
  }
491
492
  return this.fanOut.request(post, control.stopSignal);
492
493
  }
494
+ /**
495
+ * Post a sync payload to this account's other devices. The timestamp is the
496
+ * epoch of the sync. A caller that passes an application-supplied time
497
+ * checks it first, as a new send checks its timestamp.
498
+ */
493
499
  async sendSyncPayloadToLocalOtherDevices(payloadBytes, timestamp) {
494
500
  if (!this.relay) {
495
501
  return;
@@ -520,6 +526,7 @@ export class SignalProtocolServiceCipher {
520
526
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, timestamp);
521
527
  }
522
528
  async sendMediaAttachmentDeleteSyncToLocalOtherDevices(entry) {
529
+ checkNewSendTimestamp({ timestamp: entry.deletedAt });
523
530
  const payloadBytes = this.getResolvedContentAdapter().serializeMediaAttachmentDeleteSync(entry);
524
531
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, entry.deletedAt);
525
532
  }
@@ -534,18 +541,22 @@ export class SignalProtocolServiceCipher {
534
541
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, timestamp);
535
542
  }
536
543
  async sendRecipientUsernameSyncToLocalOtherDevices(recipientUsername) {
544
+ checkNewSendTimestamp({ timestamp: recipientUsername.learnedAt });
537
545
  const payloadBytes = this.getResolvedContentAdapter().serializeRecipientUsernameSync(recipientUsername);
538
546
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, recipientUsername.learnedAt);
539
547
  }
540
548
  async sendVerificationStateSyncToLocalOtherDevices(verificationState) {
549
+ checkNewSendTimestamp({ timestamp: verificationState.changedAt });
541
550
  const payloadBytes = this.getResolvedContentAdapter().serializeVerificationStateSync(verificationState);
542
551
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, verificationState.changedAt);
543
552
  }
544
553
  async sendTaskNotificationAckSyncToLocalOtherDevices(ack) {
554
+ checkNewSendTimestamp({ timestamp: ack.acknowledgedAt });
545
555
  const payloadBytes = this.getResolvedContentAdapter().serializeTaskNotificationAckSync(ack);
546
556
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, ack.acknowledgedAt);
547
557
  }
548
558
  async sendBlockedRecipientsSyncToLocalOtherDevices(blocked) {
559
+ checkNewSendTimestamp({ timestamp: blocked.syncedAt });
549
560
  const payloadBytes = this.getResolvedContentAdapter().serializeBlockedRecipientsSync(blocked);
550
561
  await this.sendSyncPayloadToLocalOtherDevices(payloadBytes, blocked.syncedAt);
551
562
  }
@@ -1169,7 +1180,12 @@ export class SignalProtocolServiceCipher {
1169
1180
  */
1170
1181
  async encrypt(recipientId, content, options, sessions = this.sessionCallbacks, stopSignal) {
1171
1182
  const clientMessageId = options?.clientMessageId ?? (await CryptoUtils.generateUuidV4());
1172
- const durableOptions = { ...options, clientMessageId };
1183
+ // The client entry can mark the origin of the timestamp. The public type
1184
+ // of the options leaves the mark out, and the spread keeps its symbol key.
1185
+ const durableOptions = {
1186
+ ...options,
1187
+ clientMessageId,
1188
+ };
1173
1189
  const encrypt = async () => {
1174
1190
  if (durableOptions.isBinary) {
1175
1191
  return this.encryptBinaryAttachment(recipientId, content, durableOptions, sessions, stopSignal);
@@ -1811,6 +1827,9 @@ export class SignalProtocolServiceCipher {
1811
1827
  const reconciled = await this.reconcilePendingDirectIntent(existing, plaintextBytes, sessions);
1812
1828
  return this.sendStoredDirectIntent(await this.reconcileDirectSyncDevices(reconciled, plaintextBytes, sessions, stopSignal), plaintextBytes, sessions, stopSignal);
1813
1829
  }
1830
+ // A new send checks the timestamp before the session setup, which can
1831
+ // post to the Relay. The replays above keep the stored timestamp.
1832
+ checkNewSendTimestamp(options);
1814
1833
  const sendFirst = await this.ensureSessionsForUser(recipientUserId, sessions, true);
1815
1834
  const sealedSender = this.relay ? await this.resolveSealedSenderContext(recipientUserId) : null;
1816
1835
  const directSealedSender = sealedSender && this.relay?.sendMultiRecipientUnidentified ? sealedSender : null;
@@ -3774,18 +3793,25 @@ export class SignalProtocolServiceCipher {
3774
3793
  if (!this.relay) {
3775
3794
  throw new EncryptionError('Relay server not configured. Cannot send attachments without server connection.', EncryptionErrorCode.INITIALIZATION_FAILED);
3776
3795
  }
3777
- const uploaded = await this.prepareAttachmentUpload(data, options);
3796
+ // The upload posts the file, so a new send checks its timestamp first,
3797
+ // once, against one clock reading. The mark stops the checks of the send
3798
+ // after the upload, which would read a later clock. A send that repeats a
3799
+ // stored intent keeps the stored timestamp.
3800
+ const sendOptions = (await getOutgoingMessageIntent(this.storage, options.clientMessageId))
3801
+ ? options
3802
+ : withCheckedSendTimestamp(options);
3803
+ const uploaded = await this.prepareAttachmentUpload(data, sendOptions);
3778
3804
  const attachmentPayload = serializeMediaAttachmentMessage({
3779
3805
  attachment: uploaded,
3780
- timestamp: options.timestamp ?? Date.now(),
3806
+ timestamp: sendOptions.timestamp ?? Date.now(),
3781
3807
  });
3782
3808
  const attachmentBytes = new TextEncoder().encode(attachmentPayload);
3783
3809
  let result;
3784
3810
  if (isGroupId(recipientId)) {
3785
- result = await this.encryptToGroup(recipientId, attachmentBytes, options, sessions, stopSignal);
3811
+ result = await this.encryptToGroup(recipientId, attachmentBytes, sendOptions, sessions, stopSignal);
3786
3812
  }
3787
3813
  else {
3788
- result = await this.encryptToUser(recipientId, attachmentBytes, options, sessions);
3814
+ result = await this.encryptToUser(recipientId, attachmentBytes, sendOptions, sessions);
3789
3815
  }
3790
3816
  return {
3791
3817
  ...result,