@open-e2ee/signal-protocol-sdk 10.1.0 → 12.0.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.
- package/ADAPTERS.md +4 -4
- package/ARCHITECTURE.md +6 -8
- package/CHANGELOG.md +1413 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/TROUBLESHOOTING.md +1 -1
- package/client/README.md +84 -37
- package/device/README.md +39 -85
- package/dist/client/client.d.ts +342 -62
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +1195 -179
- package/dist/client/client.js.map +1 -1
- package/dist/client/config.d.ts +40 -32
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js +1 -1
- package/dist/client/config.js.map +1 -1
- package/dist/client/constants.d.ts +42 -8
- package/dist/client/constants.d.ts.map +1 -1
- package/dist/client/constants.js +48 -3
- package/dist/client/constants.js.map +1 -1
- package/dist/client/content-adapter.d.ts +80 -0
- package/dist/client/content-adapter.d.ts.map +1 -1
- package/dist/client/content-adapter.js +225 -12
- package/dist/client/content-adapter.js.map +1 -1
- package/dist/client/delivery-error.d.ts +150 -0
- package/dist/client/delivery-error.d.ts.map +1 -0
- package/dist/client/delivery-error.js +226 -0
- package/dist/client/delivery-error.js.map +1 -0
- package/dist/client/delivery-status.d.ts +32 -6
- package/dist/client/delivery-status.d.ts.map +1 -1
- package/dist/client/delivery-status.js +61 -13
- package/dist/client/delivery-status.js.map +1 -1
- package/dist/client/device-set-reconciliation.d.ts +196 -0
- package/dist/client/device-set-reconciliation.d.ts.map +1 -0
- package/dist/client/device-set-reconciliation.js +282 -0
- package/dist/client/device-set-reconciliation.js.map +1 -0
- package/dist/client/distribution-records.d.ts +29 -0
- package/dist/client/distribution-records.d.ts.map +1 -0
- package/dist/client/distribution-records.js +33 -0
- package/dist/client/distribution-records.js.map +1 -0
- package/dist/client/event-hooks.d.ts +308 -6
- package/dist/client/event-hooks.d.ts.map +1 -1
- package/dist/client/event-hooks.js +9 -0
- package/dist/client/event-hooks.js.map +1 -1
- package/dist/client/group-device-set.d.ts +47 -0
- package/dist/client/group-device-set.d.ts.map +1 -0
- package/dist/client/group-device-set.js +65 -0
- package/dist/client/group-device-set.js.map +1 -0
- package/dist/client/group-fetcher.d.ts +116 -0
- package/dist/client/group-fetcher.d.ts.map +1 -0
- package/dist/client/group-fetcher.js +598 -0
- package/dist/client/group-fetcher.js.map +1 -0
- package/dist/client/group-outbox.d.ts +172 -10
- package/dist/client/group-outbox.d.ts.map +1 -1
- package/dist/client/group-outbox.js +915 -74
- package/dist/client/group-outbox.js.map +1 -1
- package/dist/client/group-receive-authorization.d.ts +127 -4
- package/dist/client/group-receive-authorization.d.ts.map +1 -1
- package/dist/client/group-receive-authorization.js +270 -20
- package/dist/client/group-receive-authorization.js.map +1 -1
- package/dist/client/group-sealed-sender.d.ts +3 -0
- package/dist/client/group-sealed-sender.d.ts.map +1 -1
- package/dist/client/group-sealed-sender.js +1 -0
- package/dist/client/group-sealed-sender.js.map +1 -1
- package/dist/client/group-sender-key-operations.d.ts +14 -3
- package/dist/client/group-sender-key-operations.d.ts.map +1 -1
- package/dist/client/group-sender-key-operations.js +26 -5
- package/dist/client/group-sender-key-operations.js.map +1 -1
- package/dist/client/groups.d.ts +5 -5
- package/dist/client/groups.d.ts.map +1 -1
- package/dist/client/groups.js +5 -4
- package/dist/client/groups.js.map +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts +61 -9
- package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
- package/dist/client/hosted-anonymous-delivery.js +242 -48
- package/dist/client/hosted-anonymous-delivery.js.map +1 -1
- package/dist/client/hosted-assertion-id.d.ts +7 -0
- package/dist/client/hosted-assertion-id.d.ts.map +1 -0
- package/dist/client/hosted-assertion-id.js +51 -0
- package/dist/client/hosted-assertion-id.js.map +1 -0
- package/dist/client/hosted-device-standing.d.ts +52 -0
- package/dist/client/hosted-device-standing.d.ts.map +1 -0
- package/dist/client/hosted-device-standing.js +74 -0
- package/dist/client/hosted-device-standing.js.map +1 -0
- package/dist/client/hosted-mailbox-subscription.d.ts +48 -3
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +288 -74
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-push.d.ts +22 -4
- package/dist/client/hosted-push.d.ts.map +1 -1
- package/dist/client/hosted-push.js +75 -22
- package/dist/client/hosted-push.js.map +1 -1
- package/dist/client/hosted-transport.d.ts +22 -28
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +167 -69
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted.d.ts +22 -5
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +122 -45
- package/dist/client/hosted.js.map +1 -1
- package/dist/client/index.d.ts +6 -4
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +3 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/messages.d.ts +25 -3
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/messages.js +118 -17
- package/dist/client/messages.js.map +1 -1
- package/dist/client/one-time-prekey-refill.d.ts +7 -0
- package/dist/client/one-time-prekey-refill.d.ts.map +1 -1
- package/dist/client/one-time-prekey-refill.js +5 -1
- package/dist/client/one-time-prekey-refill.js.map +1 -1
- package/dist/client/receive-admission.d.ts +58 -0
- package/dist/client/receive-admission.d.ts.map +1 -0
- package/dist/client/receive-admission.js +78 -0
- package/dist/client/receive-admission.js.map +1 -0
- package/dist/client/receive-expiry.d.ts +31 -0
- package/dist/client/receive-expiry.d.ts.map +1 -0
- package/dist/client/receive-expiry.js +35 -0
- package/dist/client/receive-expiry.js.map +1 -0
- package/dist/client/receive-hook-bound.d.ts +50 -0
- package/dist/client/receive-hook-bound.d.ts.map +1 -0
- package/dist/client/receive-hook-bound.js +115 -0
- package/dist/client/receive-hook-bound.js.map +1 -0
- package/dist/client/receive-queue.d.ts +299 -0
- package/dist/client/receive-queue.d.ts.map +1 -0
- package/dist/client/receive-queue.js +1420 -0
- package/dist/client/receive-queue.js.map +1 -0
- package/dist/client/receive-work-seed.d.ts +54 -0
- package/dist/client/receive-work-seed.d.ts.map +1 -0
- package/dist/client/receive-work-seed.js +116 -0
- package/dist/client/receive-work-seed.js.map +1 -0
- package/dist/client/recovery-driver.d.ts +25 -0
- package/dist/client/recovery-driver.d.ts.map +1 -0
- package/dist/client/recovery-driver.js +121 -0
- package/dist/client/recovery-driver.js.map +1 -0
- package/dist/client/relay-acceptance.d.ts +30 -0
- package/dist/client/relay-acceptance.d.ts.map +1 -1
- package/dist/client/relay-acceptance.js +55 -0
- package/dist/client/relay-acceptance.js.map +1 -1
- package/dist/client/relay-device-refusal.d.ts +18 -0
- package/dist/client/relay-device-refusal.d.ts.map +1 -1
- package/dist/client/relay-device-refusal.js +31 -0
- package/dist/client/relay-device-refusal.js.map +1 -1
- package/dist/client/relay-sealed-route.d.ts +36 -0
- package/dist/client/relay-sealed-route.d.ts.map +1 -0
- package/dist/client/relay-sealed-route.js +45 -0
- package/dist/client/relay-sealed-route.js.map +1 -0
- package/dist/client/relay-subscription.d.ts +56 -13
- package/dist/client/relay-subscription.d.ts.map +1 -1
- package/dist/client/relay-subscription.js +220 -150
- package/dist/client/relay-subscription.js.map +1 -1
- package/dist/client/resendable-content.d.ts +98 -0
- package/dist/client/resendable-content.d.ts.map +1 -0
- package/dist/client/resendable-content.js +136 -0
- package/dist/client/resendable-content.js.map +1 -0
- package/dist/client/retry-family.d.ts +68 -19
- package/dist/client/retry-family.d.ts.map +1 -1
- package/dist/client/retry-family.js +59 -17
- package/dist/client/retry-family.js.map +1 -1
- package/dist/client/retry-request-envelope.d.ts +145 -18
- package/dist/client/retry-request-envelope.d.ts.map +1 -1
- package/dist/client/retry-request-envelope.js +301 -64
- package/dist/client/retry-request-envelope.js.map +1 -1
- package/dist/client/retry-request-lifecycle.d.ts +157 -0
- package/dist/client/retry-request-lifecycle.d.ts.map +1 -0
- package/dist/client/retry-request-lifecycle.js +437 -0
- package/dist/client/retry-request-lifecycle.js.map +1 -0
- package/dist/client/retry-terminal-recovery.d.ts +100 -0
- package/dist/client/retry-terminal-recovery.d.ts.map +1 -0
- package/dist/client/retry-terminal-recovery.js +164 -0
- package/dist/client/retry-terminal-recovery.js.map +1 -0
- package/dist/client/retry-utils.d.ts +27 -0
- package/dist/client/retry-utils.d.ts.map +1 -1
- package/dist/client/retry-utils.js +46 -0
- package/dist/client/retry-utils.js.map +1 -1
- package/dist/client/retry.d.ts +106 -18
- package/dist/client/retry.d.ts.map +1 -1
- package/dist/client/retry.js +687 -139
- package/dist/client/retry.js.map +1 -1
- package/dist/client/sealed-sender.d.ts +23 -6
- package/dist/client/sealed-sender.d.ts.map +1 -1
- package/dist/client/sealed-sender.js +30 -6
- package/dist/client/sealed-sender.js.map +1 -1
- package/dist/client/sessions.d.ts +2 -2
- package/dist/client/sessions.js +2 -2
- package/dist/client/signal-service-cipher.d.ts +726 -19
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +2265 -343
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/state.d.ts +5 -0
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/state.js +11 -1
- package/dist/client/state.js.map +1 -1
- package/dist/client/storage-protection.d.ts +64 -0
- package/dist/client/storage-protection.d.ts.map +1 -0
- package/dist/client/storage-protection.js +150 -0
- package/dist/client/storage-protection.js.map +1 -0
- package/dist/client/types.d.ts +149 -15
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/device/constants.d.ts +0 -5
- package/dist/device/constants.d.ts.map +1 -1
- package/dist/device/constants.js +0 -5
- package/dist/device/constants.js.map +1 -1
- package/dist/device/expo/index.d.ts +4 -17
- package/dist/device/expo/index.d.ts.map +1 -1
- package/dist/device/expo/index.js +4 -23
- package/dist/device/expo/index.js.map +1 -1
- package/dist/device/index.d.ts +0 -2
- package/dist/device/index.d.ts.map +1 -1
- package/dist/device/index.js +0 -7
- package/dist/device/index.js.map +1 -1
- package/dist/device/lifecycle/manager.d.ts +5 -4
- package/dist/device/lifecycle/manager.d.ts.map +1 -1
- package/dist/device/lifecycle/manager.js +16 -16
- package/dist/device/lifecycle/manager.js.map +1 -1
- package/dist/device/lifecycle/types.d.ts +2 -2
- package/dist/device/lifecycle/types.d.ts.map +1 -1
- package/dist/device/react-native/index.d.ts +4 -15
- package/dist/device/react-native/index.d.ts.map +1 -1
- package/dist/device/react-native/index.js +4 -21
- package/dist/device/react-native/index.js.map +1 -1
- package/dist/device/types.d.ts +1 -1
- package/dist/groups/index.d.ts +1 -1
- package/dist/groups/index.d.ts.map +1 -1
- package/dist/index.d.ts +8 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/crypto/ec/x25519-validation.d.ts +0 -1
- package/dist/internal/crypto/ec/x25519-validation.d.ts.map +1 -1
- package/dist/internal/crypto/ec/x25519-validation.js +0 -1
- package/dist/internal/crypto/ec/x25519-validation.js.map +1 -1
- package/dist/internal/crypto/validation.d.ts +2 -2
- package/dist/internal/groups/index.d.ts +1 -0
- package/dist/internal/groups/index.d.ts.map +1 -1
- package/dist/internal/groups/index.js +1 -0
- package/dist/internal/groups/index.js.map +1 -1
- package/dist/internal/groups/manager.d.ts +37 -16
- package/dist/internal/groups/manager.d.ts.map +1 -1
- package/dist/internal/groups/manager.js +46 -1
- package/dist/internal/groups/manager.js.map +1 -1
- package/dist/internal/groups/receive-record.d.ts +78 -0
- package/dist/internal/groups/receive-record.d.ts.map +1 -0
- package/dist/internal/groups/receive-record.js +43 -0
- package/dist/internal/groups/receive-record.js.map +1 -0
- package/dist/internal/groups/sdk-store.d.ts +27 -3
- package/dist/internal/groups/sdk-store.d.ts.map +1 -1
- package/dist/internal/groups/sdk-store.js +151 -19
- package/dist/internal/groups/sdk-store.js.map +1 -1
- package/dist/internal/groups/wire.d.ts +12 -1
- package/dist/internal/groups/wire.d.ts.map +1 -1
- package/dist/internal/groups/wire.js +36 -0
- package/dist/internal/groups/wire.js.map +1 -1
- package/dist/internal/manager/index.d.ts +1 -1
- package/dist/internal/manager/manager.d.ts +20 -19
- package/dist/internal/manager/manager.d.ts.map +1 -1
- package/dist/internal/manager/manager.js +56 -39
- package/dist/internal/manager/manager.js.map +1 -1
- package/dist/internal/protocol/double-ratchet/chains.d.ts +4 -18
- package/dist/internal/protocol/double-ratchet/chains.d.ts.map +1 -1
- package/dist/internal/protocol/double-ratchet/chains.js +23 -74
- package/dist/internal/protocol/double-ratchet/chains.js.map +1 -1
- package/dist/internal/protocol/double-ratchet/index.d.ts +1 -1
- package/dist/internal/protocol/double-ratchet/index.d.ts.map +1 -1
- package/dist/internal/protocol/double-ratchet/index.js +1 -1
- package/dist/internal/protocol/double-ratchet/index.js.map +1 -1
- package/dist/internal/protocol/double-ratchet/ratchet.d.ts +5 -7
- package/dist/internal/protocol/double-ratchet/ratchet.d.ts.map +1 -1
- package/dist/internal/protocol/double-ratchet/ratchet.js +4 -6
- package/dist/internal/protocol/double-ratchet/ratchet.js.map +1 -1
- package/dist/internal/protocol/pqxdh/pqxdh.d.ts.map +1 -1
- package/dist/internal/protocol/pqxdh/pqxdh.js +2 -1
- package/dist/internal/protocol/pqxdh/pqxdh.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.d.ts +6 -8
- package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.js +8 -9
- package/dist/internal/protocol/sealed-sender/types.js.map +1 -1
- package/dist/internal/protocol/sender-keys/handoff-ledger.d.ts +110 -0
- package/dist/internal/protocol/sender-keys/handoff-ledger.d.ts.map +1 -0
- package/dist/internal/protocol/sender-keys/handoff-ledger.js +124 -0
- package/dist/internal/protocol/sender-keys/handoff-ledger.js.map +1 -0
- package/dist/internal/protocol/sender-keys/manager.d.ts +71 -62
- package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.js +228 -175
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
- package/dist/internal/protocol/spqr/index.d.ts +2 -2
- package/dist/internal/protocol/spqr/index.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/index.js +2 -2
- package/dist/internal/protocol/spqr/index.js.map +1 -1
- package/dist/internal/protocol/spqr/serialize.d.ts +9 -1
- package/dist/internal/protocol/spqr/serialize.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/serialize.js +56 -16
- package/dist/internal/protocol/spqr/serialize.js.map +1 -1
- package/dist/internal/protocol/spqr/spqr.d.ts +1 -14
- package/dist/internal/protocol/spqr/spqr.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/spqr.js +54 -42
- package/dist/internal/protocol/spqr/spqr.js.map +1 -1
- package/dist/internal/protocol/spqr/validate.d.ts +26 -6
- package/dist/internal/protocol/spqr/validate.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/validate.js +49 -21
- package/dist/internal/protocol/spqr/validate.js.map +1 -1
- package/dist/internal/sesame/index.d.ts +1 -1
- package/dist/internal/sesame/index.d.ts.map +1 -1
- package/dist/internal/sesame/index.js.map +1 -1
- package/dist/internal/sesame/manager.d.ts +66 -13
- package/dist/internal/sesame/manager.d.ts.map +1 -1
- package/dist/internal/sesame/manager.js +221 -87
- package/dist/internal/sesame/manager.js.map +1 -1
- package/dist/internal/sesame/types.d.ts +95 -17
- package/dist/internal/sesame/types.d.ts.map +1 -1
- package/dist/internal/sesame/types.js +17 -0
- package/dist/internal/sesame/types.js.map +1 -1
- package/dist/internal/session/builder.d.ts +5 -5
- package/dist/internal/session/builder.d.ts.map +1 -1
- package/dist/internal/session/builder.js +12 -17
- package/dist/internal/session/builder.js.map +1 -1
- package/dist/internal/session/cipher.d.ts +13 -11
- package/dist/internal/session/cipher.d.ts.map +1 -1
- package/dist/internal/session/cipher.js +40 -22
- package/dist/internal/session/cipher.js.map +1 -1
- package/dist/internal/session/factory.d.ts +5 -5
- package/dist/internal/session/factory.d.ts.map +1 -1
- package/dist/internal/session/factory.js +4 -4
- package/dist/internal/session/factory.js.map +1 -1
- package/dist/internal/session/handshake.d.ts +14 -16
- package/dist/internal/session/handshake.d.ts.map +1 -1
- package/dist/internal/session/handshake.js +18 -75
- package/dist/internal/session/handshake.js.map +1 -1
- package/dist/internal/session/index.d.ts +1 -1
- package/dist/internal/session/index.js +1 -1
- package/dist/internal/session/record-locks.d.ts +17 -6
- package/dist/internal/session/record-locks.d.ts.map +1 -1
- package/dist/internal/session/record-locks.js +43 -7
- package/dist/internal/session/record-locks.js.map +1 -1
- package/dist/internal/session/session-resolver.d.ts +1 -1
- package/dist/internal/session/session-resolver.js +1 -1
- package/dist/internal/session/state.d.ts +2 -2
- package/dist/internal/session/state.js +1 -1
- package/dist/internal/session/types.d.ts +4 -12
- package/dist/internal/session/types.d.ts.map +1 -1
- package/dist/internal/session/types.js +1 -1
- package/dist/keys/generation.d.ts +2 -2
- package/dist/keys/generation.js +2 -2
- package/dist/keys/types.d.ts +5 -5
- package/dist/keys/types.d.ts.map +1 -1
- package/dist/keys/types.js +1 -1
- package/dist/layers.d.ts +1 -1
- package/dist/layers.js +2 -2
- package/dist/layers.js.map +1 -1
- package/dist/local/store/expo/adapter.d.ts.map +1 -1
- package/dist/local/store/expo/adapter.js +12 -8
- package/dist/local/store/expo/adapter.js.map +1 -1
- package/dist/local/store/key-value/adapter.d.ts +76 -10
- package/dist/local/store/key-value/adapter.d.ts.map +1 -1
- package/dist/local/store/key-value/adapter.js +367 -61
- package/dist/local/store/key-value/adapter.js.map +1 -1
- package/dist/local/store/key-value/backend-conformance.d.ts.map +1 -1
- package/dist/local/store/key-value/backend-conformance.js +74 -0
- package/dist/local/store/key-value/backend-conformance.js.map +1 -1
- package/dist/local/store/key-value/batch.d.ts +2 -0
- package/dist/local/store/key-value/batch.d.ts.map +1 -1
- package/dist/local/store/key-value/batch.js +26 -0
- package/dist/local/store/key-value/batch.js.map +1 -1
- package/dist/local/store/key-value/receive-work.d.ts +55 -0
- package/dist/local/store/key-value/receive-work.d.ts.map +1 -0
- package/dist/local/store/key-value/receive-work.js +162 -0
- package/dist/local/store/key-value/receive-work.js.map +1 -0
- package/dist/local/store/key-value/send-log.d.ts +61 -0
- package/dist/local/store/key-value/send-log.d.ts.map +1 -0
- package/dist/local/store/key-value/send-log.js +430 -0
- package/dist/local/store/key-value/send-log.js.map +1 -0
- package/dist/local/store/key-value/sender-key-handoff.d.ts +68 -0
- package/dist/local/store/key-value/sender-key-handoff.d.ts.map +1 -0
- package/dist/local/store/key-value/sender-key-handoff.js +189 -0
- package/dist/local/store/key-value/sender-key-handoff.js.map +1 -0
- package/dist/local/store/key-value/storage.d.ts +15 -0
- package/dist/local/store/key-value/storage.d.ts.map +1 -1
- package/dist/local/store/keyed-index.d.ts +23 -0
- package/dist/local/store/keyed-index.d.ts.map +1 -0
- package/dist/local/store/keyed-index.js +41 -0
- package/dist/local/store/keyed-index.js.map +1 -0
- package/dist/local/store/memory/adapter.d.ts +44 -12
- package/dist/local/store/memory/adapter.d.ts.map +1 -1
- package/dist/local/store/memory/adapter.js +197 -46
- package/dist/local/store/memory/adapter.js.map +1 -1
- package/dist/local/store/memory/send-log.d.ts +42 -0
- package/dist/local/store/memory/send-log.d.ts.map +1 -0
- package/dist/local/store/memory/send-log.js +190 -0
- package/dist/local/store/memory/send-log.js.map +1 -0
- package/dist/local/store/node/adapter.d.ts.map +1 -1
- package/dist/local/store/node/adapter.js +8 -6
- package/dist/local/store/node/adapter.js.map +1 -1
- package/dist/local/store/react-native/adapter.d.ts.map +1 -1
- package/dist/local/store/react-native/adapter.js +12 -8
- package/dist/local/store/react-native/adapter.js.map +1 -1
- package/dist/local/store/receive-work.d.ts +87 -0
- package/dist/local/store/receive-work.d.ts.map +1 -0
- package/dist/local/store/receive-work.js +204 -0
- package/dist/local/store/receive-work.js.map +1 -0
- package/dist/local/store/received-content.d.ts +3 -3
- package/dist/local/store/received-content.d.ts.map +1 -1
- package/dist/local/store/received-content.js +2 -11
- package/dist/local/store/received-content.js.map +1 -1
- package/dist/local/store/reliability.d.ts +411 -14
- package/dist/local/store/reliability.d.ts.map +1 -1
- package/dist/local/store/reliability.js +532 -58
- package/dist/local/store/reliability.js.map +1 -1
- package/dist/local/store/send-log-order.d.ts +15 -0
- package/dist/local/store/send-log-order.d.ts.map +1 -0
- package/dist/local/store/send-log-order.js +24 -0
- package/dist/local/store/send-log-order.js.map +1 -0
- package/dist/local/store/sender-key-handoff-index.d.ts +38 -0
- package/dist/local/store/sender-key-handoff-index.d.ts.map +1 -0
- package/dist/local/store/sender-key-handoff-index.js +101 -0
- package/dist/local/store/sender-key-handoff-index.js.map +1 -0
- package/dist/local/store/sender-key-handoff-table.d.ts +29 -0
- package/dist/local/store/sender-key-handoff-table.d.ts.map +1 -0
- package/dist/local/store/sender-key-handoff-table.js +97 -0
- package/dist/local/store/sender-key-handoff-table.js.map +1 -0
- package/dist/local/store/sqlite/encryption.d.ts +8 -1
- package/dist/local/store/sqlite/encryption.d.ts.map +1 -1
- package/dist/local/store/sqlite/encryption.js +9 -0
- package/dist/local/store/sqlite/encryption.js.map +1 -1
- package/dist/local/store/sqlite/key-storage/index.d.ts +25 -4
- package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -1
- package/dist/local/store/sqlite/key-storage/index.js +68 -7
- package/dist/local/store/sqlite/key-storage/index.js.map +1 -1
- package/dist/local/store/sqlite/key-storage/message-records.d.ts +16 -4
- package/dist/local/store/sqlite/key-storage/message-records.d.ts.map +1 -1
- package/dist/local/store/sqlite/key-storage/message-records.js +49 -6
- package/dist/local/store/sqlite/key-storage/message-records.js.map +1 -1
- package/dist/local/store/sqlite/key-storage/metadata.d.ts +8 -7
- package/dist/local/store/sqlite/key-storage/metadata.d.ts.map +1 -1
- package/dist/local/store/sqlite/key-storage/metadata.js +17 -15
- package/dist/local/store/sqlite/key-storage/metadata.js.map +1 -1
- package/dist/local/store/sqlite/key-storage/receive-work.d.ts +27 -0
- package/dist/local/store/sqlite/key-storage/receive-work.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/receive-work.js +98 -0
- package/dist/local/store/sqlite/key-storage/receive-work.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/send-log.d.ts +27 -0
- package/dist/local/store/sqlite/key-storage/send-log.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/send-log.js +178 -0
- package/dist/local/store/sqlite/key-storage/send-log.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/sender-key-handoff.d.ts +27 -0
- package/dist/local/store/sqlite/key-storage/sender-key-handoff.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/sender-key-handoff.js +75 -0
- package/dist/local/store/sqlite/key-storage/sender-key-handoff.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/session-trust.d.ts +2 -2
- package/dist/local/store/sqlite/key-storage/session-trust.js +5 -5
- package/dist/local/store/sqlite/key-storage/session-trust.js.map +1 -1
- package/dist/local/store/sqlite/migrations.d.ts.map +1 -1
- package/dist/local/store/sqlite/migrations.js +101 -0
- package/dist/local/store/sqlite/migrations.js.map +1 -1
- package/dist/local/store/sqlite/models/index.d.ts +2 -1
- package/dist/local/store/sqlite/models/index.d.ts.map +1 -1
- package/dist/local/store/sqlite/models/index.js +5 -1
- package/dist/local/store/sqlite/models/index.js.map +1 -1
- package/dist/local/store/sqlite/models/message-record.d.ts +15 -0
- package/dist/local/store/sqlite/models/message-record.d.ts.map +1 -1
- package/dist/local/store/sqlite/models/message-record.js +24 -0
- package/dist/local/store/sqlite/models/message-record.js.map +1 -1
- package/dist/local/store/sqlite/models/send-log.d.ts +51 -0
- package/dist/local/store/sqlite/models/send-log.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/send-log.js +206 -0
- package/dist/local/store/sqlite/models/send-log.js.map +1 -0
- package/dist/local/store/sqlite/open-store.d.ts +9 -1
- package/dist/local/store/sqlite/open-store.d.ts.map +1 -1
- package/dist/local/store/sqlite/open-store.js +20 -1
- package/dist/local/store/sqlite/open-store.js.map +1 -1
- package/dist/local/store/sqlite/schema.d.ts +34 -1
- package/dist/local/store/sqlite/schema.d.ts.map +1 -1
- package/dist/local/store/sqlite/schema.js +14 -0
- package/dist/local/store/sqlite/schema.js.map +1 -1
- package/dist/local/store/sqlite/store.d.ts +61 -11
- package/dist/local/store/sqlite/store.d.ts.map +1 -1
- package/dist/local/store/sqlite/store.js +191 -27
- package/dist/local/store/sqlite/store.js.map +1 -1
- package/dist/local/store/web/adapter.d.ts +76 -8
- package/dist/local/store/web/adapter.d.ts.map +1 -1
- package/dist/local/store/web/adapter.js +579 -127
- package/dist/local/store/web/adapter.js.map +1 -1
- package/dist/local/store/web/receive-work.d.ts +57 -0
- package/dist/local/store/web/receive-work.d.ts.map +1 -0
- package/dist/local/store/web/receive-work.js +99 -0
- package/dist/local/store/web/receive-work.js.map +1 -0
- package/dist/local/store/web/send-log.d.ts +92 -0
- package/dist/local/store/web/send-log.d.ts.map +1 -0
- package/dist/local/store/web/send-log.js +267 -0
- package/dist/local/store/web/send-log.js.map +1 -0
- package/dist/local/store/web/sender-key-handoff.d.ts +81 -0
- package/dist/local/store/web/sender-key-handoff.d.ts.map +1 -0
- package/dist/local/store/web/sender-key-handoff.js +156 -0
- package/dist/local/store/web/sender-key-handoff.js.map +1 -0
- package/dist/local/store/web-sqlite/adapter.d.ts +2 -0
- package/dist/local/store/web-sqlite/adapter.d.ts.map +1 -1
- package/dist/local/store/web-sqlite/adapter.js +12 -6
- package/dist/local/store/web-sqlite/adapter.js.map +1 -1
- package/dist/local/vault/custody.d.ts +8 -0
- package/dist/local/vault/custody.d.ts.map +1 -0
- package/dist/local/vault/custody.js +9 -0
- package/dist/local/vault/custody.js.map +1 -0
- package/dist/local/vault/electron-safe-storage.d.ts +3 -1
- package/dist/local/vault/electron-safe-storage.d.ts.map +1 -1
- package/dist/local/vault/electron-safe-storage.js +2 -0
- package/dist/local/vault/electron-safe-storage.js.map +1 -1
- package/dist/local/vault/expo-secure-store.d.ts +3 -1
- package/dist/local/vault/expo-secure-store.d.ts.map +1 -1
- package/dist/local/vault/expo-secure-store.js +2 -0
- package/dist/local/vault/expo-secure-store.js.map +1 -1
- package/dist/local/vault/indexed-db.d.ts +3 -1
- package/dist/local/vault/indexed-db.d.ts.map +1 -1
- package/dist/local/vault/indexed-db.js +2 -0
- package/dist/local/vault/indexed-db.js.map +1 -1
- package/dist/local/vault/react-native-keychain.d.ts +3 -1
- package/dist/local/vault/react-native-keychain.d.ts.map +1 -1
- package/dist/local/vault/react-native-keychain.js +2 -0
- package/dist/local/vault/react-native-keychain.js.map +1 -1
- package/dist/remote/relay/device-set.d.ts +94 -0
- package/dist/remote/relay/device-set.d.ts.map +1 -0
- package/dist/remote/relay/device-set.js +156 -0
- package/dist/remote/relay/device-set.js.map +1 -0
- package/dist/remote/relay/types.d.ts +104 -110
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/safety/core.d.ts +15 -6
- package/dist/safety/core.d.ts.map +1 -1
- package/dist/safety/core.js +41 -27
- package/dist/safety/core.js.map +1 -1
- package/dist/safety/index.d.ts +2 -1
- package/dist/safety/index.d.ts.map +1 -1
- package/dist/safety/index.js +12 -18
- package/dist/safety/index.js.map +1 -1
- package/dist/types/api.d.ts +707 -62
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/errors.d.ts +14 -33
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +14 -24
- package/dist/types/errors.js.map +1 -1
- package/dist/types/messages.d.ts +2 -2
- package/dist/types/messages.js +1 -1
- package/dist/types/protocol-config.d.ts +175 -42
- package/dist/types/protocol-config.d.ts.map +1 -1
- package/dist/types/protocol-config.js +19 -38
- package/dist/types/protocol-config.js.map +1 -1
- package/dist/types/protocol-constants.d.ts +6 -6
- package/dist/types/protocol-constants.js +6 -6
- package/dist/types/session.d.ts +7 -7
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js +39 -21
- package/dist/types/session.js.map +1 -1
- package/dist/username/link.d.ts +2 -2
- package/dist/username/link.js +2 -2
- package/dist/utils/origin-lock.d.ts +45 -0
- package/dist/utils/origin-lock.d.ts.map +1 -0
- package/dist/utils/origin-lock.js +80 -0
- package/dist/utils/origin-lock.js.map +1 -0
- package/dist/utils/retry.d.ts +2 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +7 -0
- package/dist/utils/retry.js.map +1 -1
- package/docs/ASSURANCE.md +6 -6
- package/docs/CLIENT_COMPOSITION.md +2 -2
- package/docs/DEVIATIONS.md +677 -182
- package/docs/E2EE.md +1 -1
- package/docs/ERROR_HANDLING.md +235 -2
- package/docs/GETTING_STARTED.md +7 -4
- package/docs/INTERFACES.md +1 -1
- package/docs/PACKAGE_SURFACE.md +6 -5
- package/docs/PROTOCOL_POLICY.md +102 -22
- package/docs/RECIPES.md +3 -15
- package/docs/SECURITY.md +90 -5
- package/keys/README.md +3 -3
- package/local/store/README.md +78 -14
- package/local/store/key-value/README.md +14 -3
- package/local/store/node/README.md +8 -3
- package/local/store/web/README.md +9 -0
- package/local/store/web-sqlite/README.md +14 -2
- package/local/vault/README.md +21 -0
- package/package.json +1 -6
- package/remote/README.md +0 -1
- package/remote/relay/README.md +2 -2
- package/dist/device/provisioning.d.ts +0 -242
- package/dist/device/provisioning.d.ts.map +0 -1
- package/dist/device/provisioning.js +0 -421
- package/dist/device/provisioning.js.map +0 -1
- package/dist/internal/protocol/x3dh/index.d.ts +0 -15
- package/dist/internal/protocol/x3dh/index.d.ts.map +0 -1
- package/dist/internal/protocol/x3dh/index.js +0 -13
- package/dist/internal/protocol/x3dh/index.js.map +0 -1
- package/dist/internal/protocol/x3dh/x3dh.d.ts +0 -131
- package/dist/internal/protocol/x3dh/x3dh.d.ts.map +0 -1
- package/dist/internal/protocol/x3dh/x3dh.js +0 -261
- package/dist/internal/protocol/x3dh/x3dh.js.map +0 -1
|
@@ -34,19 +34,26 @@ import { assertCurrentSessionRecord } from '../../../types/session.js';
|
|
|
34
34
|
import { acceptContactIdentityRotation as acceptRotation, createUnverifiedContactIdentityRecord, evaluateContactIdentityCandidate, validateContactIdentityRecord, verifyContactIdentityRecord, } from '../../../keys/identity.js';
|
|
35
35
|
import { ProtocolAddress } from '../../../types/address.js';
|
|
36
36
|
import { IdentityKeyChange, StorageQuotaExceededError } from '../../../types/index.js';
|
|
37
|
+
import { secretVaultCustody } from '../../vault/custody.js';
|
|
37
38
|
import { requireSecretVault } from '../../vault/require.js';
|
|
38
39
|
import { asBase64 } from '../../../types/utils.js';
|
|
39
40
|
import { withDeviceRecordLocks } from '../../../internal/session/record-locks.js';
|
|
41
|
+
import { isExpiredRemovedDevice } from '../../../internal/sesame/types.js';
|
|
40
42
|
import { withSession } from '../device-record.js';
|
|
41
43
|
import { decodeUserRecord, encodeUserRecord } from './device-record.js';
|
|
42
44
|
import { deleteDataThenReplaceValueKey, openValueKey } from './value-key.js';
|
|
45
|
+
import { KeyValueSendLog } from './send-log.js';
|
|
46
|
+
import { KeyValueSenderKeyHandoffs } from './sender-key-handoff.js';
|
|
43
47
|
import { deserializeSessionRecord, serializeSessionRecord } from '../session-codec.js';
|
|
44
|
-
import {
|
|
48
|
+
import { convertLegacyReceivedContent } from '../receive-work.js';
|
|
49
|
+
import { KeyValueReceiveWork, LEGACY_RECEIVED_CONTENT_PREFIX } from './receive-work.js';
|
|
45
50
|
import { createKyberPreKeyState, createKyberPreKeyInstanceId, getCurrentKyberPreKey, getRetainedKyberPreKey, recordKyberPreKeyUse, recordKyberPreKeyUseById, retainKyberPreKey, } from '../kyber-prekey-lifecycle.js';
|
|
46
51
|
const STORAGE_KEYS = {
|
|
47
52
|
IDENTITY_KEY_PREFIX: '@signal:identity:keyPair:',
|
|
48
53
|
REGISTRATION_ID_PREFIX: '@signal:metadata:registrationId:',
|
|
49
54
|
METADATA_PREFIX: '@signal:metadata:value:',
|
|
55
|
+
// Set after every clear metadata value is encrypted.
|
|
56
|
+
METADATA_CIPHER_MARKER: '@signal:metadata-cipher-version',
|
|
50
57
|
CONTACT_PREFIX: '@signal:contacts:',
|
|
51
58
|
CONTACT_V1_PREFIX: '@signal:contacts:v1:',
|
|
52
59
|
PREKEY_PREFIX: '@signal:prekeys:',
|
|
@@ -71,6 +78,14 @@ const STORAGE_KEYS = {
|
|
|
71
78
|
MESSAGE_RECORD_PREFIX: '@signal:message-record:',
|
|
72
79
|
SECURITY_EVENTS: '@signal:security-events',
|
|
73
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* The version tag of an encrypted metadata value. The record cipher's base64
|
|
83
|
+
* output follows it. A value without the tag is a clear value that an older
|
|
84
|
+
* SDK wrote.
|
|
85
|
+
*/
|
|
86
|
+
const METADATA_CIPHER_TAG = 'sealed:v1:';
|
|
87
|
+
/** The marker value. The marker is the last write of the migration. */
|
|
88
|
+
const METADATA_CIPHER_VERSION = '1';
|
|
74
89
|
/**
|
|
75
90
|
* Escape a value so it cannot contain the `:` that joins composite keys.
|
|
76
91
|
*
|
|
@@ -184,13 +199,36 @@ function mapQuotaFailuresAtBoundary(store) {
|
|
|
184
199
|
* ```
|
|
185
200
|
*/
|
|
186
201
|
export class KeyValueSignalProtocolStore {
|
|
202
|
+
/** Each value is encrypted with the value key, which the vault holds. */
|
|
203
|
+
protection;
|
|
187
204
|
databaseKey = null;
|
|
188
205
|
initialized = false;
|
|
189
206
|
storageBackend;
|
|
190
207
|
vault;
|
|
208
|
+
sendLog;
|
|
209
|
+
senderKeyHandoffs;
|
|
210
|
+
receiveWork;
|
|
191
211
|
constructor(options, operation) {
|
|
192
212
|
this.storageBackend = options.storage;
|
|
193
213
|
this.vault = requireSecretVault(options.vault, operation);
|
|
214
|
+
this.sendLog = new KeyValueSendLog(this.storageBackend, {
|
|
215
|
+
encrypt: (plaintext) => this.encrypt(plaintext),
|
|
216
|
+
decrypt: (encrypted) => this.decrypt(encrypted),
|
|
217
|
+
});
|
|
218
|
+
this.receiveWork = new KeyValueReceiveWork(this.storageBackend, {
|
|
219
|
+
encrypt: (plaintext) => this.encrypt(plaintext),
|
|
220
|
+
decrypt: (encrypted) => this.decrypt(encrypted),
|
|
221
|
+
databaseKey: () => this.getDatabaseKey(),
|
|
222
|
+
});
|
|
223
|
+
this.senderKeyHandoffs = new KeyValueSenderKeyHandoffs(this.storageBackend, {
|
|
224
|
+
encrypt: (plaintext) => this.encrypt(plaintext),
|
|
225
|
+
decrypt: (encrypted) => this.decrypt(encrypted),
|
|
226
|
+
databaseKey: () => this.getDatabaseKey(),
|
|
227
|
+
});
|
|
228
|
+
this.protection = Object.freeze({
|
|
229
|
+
atRest: 'record-cipher',
|
|
230
|
+
keyCustody: secretVaultCustody(this.vault),
|
|
231
|
+
});
|
|
194
232
|
mapQuotaFailuresAtBoundary(this);
|
|
195
233
|
}
|
|
196
234
|
/**
|
|
@@ -232,7 +270,9 @@ export class KeyValueSignalProtocolStore {
|
|
|
232
270
|
return;
|
|
233
271
|
}
|
|
234
272
|
this.databaseKey = await openValueKey(this.storageBackend, this.vault);
|
|
273
|
+
await this.encryptClearMetadata();
|
|
235
274
|
this.initialized = true;
|
|
275
|
+
await this.convertLegacyReceivedRows();
|
|
236
276
|
}
|
|
237
277
|
/** Delete the store data, then replace the value key. See `deleteDataThenReplaceValueKey`. */
|
|
238
278
|
async resetData() {
|
|
@@ -324,6 +364,7 @@ export class KeyValueSignalProtocolStore {
|
|
|
324
364
|
keyPrefix: STORAGE_KEYS.SESSION_PREFIX,
|
|
325
365
|
userId: address.userId,
|
|
326
366
|
},
|
|
367
|
+
await this.senderKeyHandoffs.removeAccount(address.userId),
|
|
327
368
|
]);
|
|
328
369
|
return replacement;
|
|
329
370
|
}
|
|
@@ -499,6 +540,11 @@ export class KeyValueSignalProtocolStore {
|
|
|
499
540
|
// ============================================================================
|
|
500
541
|
async storeSessionRecord(address, record) {
|
|
501
542
|
this.ensureInitialized();
|
|
543
|
+
const write = await this.sessionRecordWrite(address, record);
|
|
544
|
+
await this.storageBackend.setItem(write.key, write.value);
|
|
545
|
+
}
|
|
546
|
+
/** The write of one session record, for a batch that commits it with other changes. */
|
|
547
|
+
async sessionRecordWrite(address, record) {
|
|
502
548
|
assertCurrentSessionRecord(record);
|
|
503
549
|
const addressKey = this.serializeAddress(address);
|
|
504
550
|
const storageKey = `${STORAGE_KEYS.SESSION_PREFIX}${addressKey}`;
|
|
@@ -509,7 +555,7 @@ export class KeyValueSignalProtocolStore {
|
|
|
509
555
|
data: encrypted,
|
|
510
556
|
updatedAt: Date.now(),
|
|
511
557
|
};
|
|
512
|
-
|
|
558
|
+
return { type: 'set', key: storageKey, value: JSON.stringify(storedRecord) };
|
|
513
559
|
}
|
|
514
560
|
async getSessionRecord(address) {
|
|
515
561
|
this.ensureInitialized();
|
|
@@ -614,47 +660,28 @@ export class KeyValueSignalProtocolStore {
|
|
|
614
660
|
operations.push({ type: 'check', key: kyberStorageKey, expectedValue: kyberStateValue });
|
|
615
661
|
operations.push({ type: 'set', key: kyberStorageKey, value: updatedKyberStateValue });
|
|
616
662
|
}
|
|
617
|
-
if (commit.
|
|
618
|
-
operations.push(
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
value: await this.encrypt(JSON.stringify(commit.receivedContent)),
|
|
622
|
-
});
|
|
623
|
-
await this.storageBackend.atomicWrite(operations);
|
|
624
|
-
}
|
|
625
|
-
async getReceivedContent(id) {
|
|
626
|
-
this.ensureInitialized();
|
|
627
|
-
const value = await this.storageBackend.getItem(`@signal:received-content:${id}`);
|
|
628
|
-
return value ? parseReceivedContent(await this.decrypt(value), id) : null;
|
|
629
|
-
}
|
|
630
|
-
async deleteReceivedContent(id) {
|
|
631
|
-
this.ensureInitialized();
|
|
632
|
-
await this.storageBackend.removeItem(`@signal:received-content:${id}`);
|
|
633
|
-
}
|
|
634
|
-
async deleteExpiredReceivedContent(before) {
|
|
635
|
-
this.ensureInitialized();
|
|
636
|
-
const prefix = '@signal:received-content:';
|
|
637
|
-
const keys = (await this.storageBackend.getAllKeys()).filter((key) => key.startsWith(prefix));
|
|
638
|
-
const expired = [];
|
|
639
|
-
for (const key of keys) {
|
|
640
|
-
const value = await this.getReceivedContent(key.slice(prefix.length));
|
|
641
|
-
if (value && value.receivedAt < before)
|
|
642
|
-
expired.push(key);
|
|
663
|
+
if (commit.receiveWork)
|
|
664
|
+
operations.push(await this.receiveWork.seal(commit.receiveWork));
|
|
665
|
+
if (commit.senderKeyHandoffInvalidation) {
|
|
666
|
+
operations.push(await this.senderKeyHandoffs.removeDevice(commit.senderKeyHandoffInvalidation));
|
|
643
667
|
}
|
|
644
|
-
|
|
645
|
-
await this.storageBackend.atomicWrite(expired.map((key) => ({ type: 'remove', key })));
|
|
646
|
-
return expired.length;
|
|
668
|
+
await this.storageBackend.atomicWrite(operations);
|
|
647
669
|
}
|
|
648
670
|
async deleteSessionRecord(address) {
|
|
649
671
|
this.ensureInitialized();
|
|
650
672
|
const addressKey = this.serializeAddress(address);
|
|
651
673
|
const storageKey = `${STORAGE_KEYS.SESSION_PREFIX}${addressKey}`;
|
|
652
|
-
await this.storageBackend.
|
|
674
|
+
await this.storageBackend.atomicWrite([
|
|
675
|
+
{ type: 'remove', key: storageKey },
|
|
676
|
+
await this.senderKeyHandoffs.removeDevice(address),
|
|
677
|
+
]);
|
|
653
678
|
}
|
|
654
679
|
async archiveCurrentSession(address, newSession) {
|
|
655
680
|
this.ensureInitialized();
|
|
656
681
|
// With SessionRecord, archiving is handled at the DeviceRecord level
|
|
657
|
-
// This method updates or replaces the session state
|
|
682
|
+
// This method updates or replaces the session state. The handoff rows of
|
|
683
|
+
// the device go in the same batch.
|
|
684
|
+
const operations = [];
|
|
658
685
|
if (newSession) {
|
|
659
686
|
const record = await this.getSessionRecord(address);
|
|
660
687
|
if (record) {
|
|
@@ -663,13 +690,18 @@ export class KeyValueSignalProtocolStore {
|
|
|
663
690
|
if (record.metadata) {
|
|
664
691
|
record.metadata.lastSentAt = Date.now();
|
|
665
692
|
}
|
|
666
|
-
await this.
|
|
693
|
+
operations.push(await this.sessionRecordWrite(address, record));
|
|
667
694
|
}
|
|
668
695
|
}
|
|
669
696
|
else {
|
|
670
697
|
// If no new session, just delete the old one
|
|
671
|
-
|
|
698
|
+
operations.push({
|
|
699
|
+
type: 'remove',
|
|
700
|
+
key: `${STORAGE_KEYS.SESSION_PREFIX}${this.serializeAddress(address)}`,
|
|
701
|
+
});
|
|
672
702
|
}
|
|
703
|
+
operations.push(await this.senderKeyHandoffs.removeDevice(address));
|
|
704
|
+
await this.storageBackend.atomicWrite(operations);
|
|
673
705
|
}
|
|
674
706
|
async getSessionsForUser(userId) {
|
|
675
707
|
this.ensureInitialized();
|
|
@@ -718,22 +750,32 @@ export class KeyValueSignalProtocolStore {
|
|
|
718
750
|
// Metadata storage
|
|
719
751
|
// ============================================================================
|
|
720
752
|
async getMetadata(key) {
|
|
721
|
-
|
|
753
|
+
this.ensureInitialized();
|
|
754
|
+
return this.openMetadataValue(await this.storageBackend.getItem(this.getMetadataStorageKey(key)));
|
|
722
755
|
}
|
|
723
756
|
async setMetadata(key, value) {
|
|
724
|
-
|
|
757
|
+
this.ensureInitialized();
|
|
758
|
+
await this.storageBackend.setItem(this.getMetadataStorageKey(key), await this.sealMetadataValue(value));
|
|
725
759
|
}
|
|
726
760
|
async deleteMetadata(key) {
|
|
761
|
+
this.ensureInitialized();
|
|
727
762
|
await this.storageBackend.removeItem(this.getMetadataStorageKey(key));
|
|
728
763
|
}
|
|
729
764
|
async compareAndSetMetadata(key, expected, value) {
|
|
765
|
+
this.ensureInitialized();
|
|
730
766
|
const storageKey = this.getMetadataStorageKey(key);
|
|
767
|
+
// Compare the decrypted value, then check the raw value that was read.
|
|
768
|
+
// The cipher draws a new IV for each write, so a writer that changed the
|
|
769
|
+
// value since the read fails the check, even when it wrote equal text.
|
|
770
|
+
const observed = await this.storageBackend.getItem(storageKey);
|
|
771
|
+
if ((await this.openMetadataValue(observed)) !== expected)
|
|
772
|
+
return false;
|
|
731
773
|
try {
|
|
732
774
|
await this.storageBackend.atomicWrite([
|
|
733
|
-
{ type: 'check', key: storageKey, expectedValue:
|
|
775
|
+
{ type: 'check', key: storageKey, expectedValue: observed },
|
|
734
776
|
value === null
|
|
735
777
|
? { type: 'remove', key: storageKey }
|
|
736
|
-
: { type: 'set', key: storageKey, value },
|
|
778
|
+
: { type: 'set', key: storageKey, value: await this.sealMetadataValue(value) },
|
|
737
779
|
]);
|
|
738
780
|
return true;
|
|
739
781
|
}
|
|
@@ -744,12 +786,116 @@ export class KeyValueSignalProtocolStore {
|
|
|
744
786
|
'name' in error &&
|
|
745
787
|
error.name === 'QuotaExceededError')
|
|
746
788
|
throw error;
|
|
747
|
-
if ((await this.storageBackend.getItem(storageKey)) !==
|
|
789
|
+
if ((await this.storageBackend.getItem(storageKey)) !== observed)
|
|
748
790
|
return false;
|
|
749
791
|
throw error;
|
|
750
792
|
}
|
|
751
793
|
}
|
|
752
794
|
// ============================================================================
|
|
795
|
+
// Receive records
|
|
796
|
+
// ============================================================================
|
|
797
|
+
async getReceiveWork(workId) {
|
|
798
|
+
this.ensureInitialized();
|
|
799
|
+
return this.receiveWork.get(workId);
|
|
800
|
+
}
|
|
801
|
+
async putReceiveWork(record, expectedRevision) {
|
|
802
|
+
this.ensureInitialized();
|
|
803
|
+
return this.receiveWork.put(record, expectedRevision);
|
|
804
|
+
}
|
|
805
|
+
async listReceiveWork(query) {
|
|
806
|
+
this.ensureInitialized();
|
|
807
|
+
return this.receiveWork.list(query);
|
|
808
|
+
}
|
|
809
|
+
async receiveWorkUsage(query) {
|
|
810
|
+
this.ensureInitialized();
|
|
811
|
+
return this.receiveWork.usage(query);
|
|
812
|
+
}
|
|
813
|
+
async completeReceiveWork(workId, expectedRevision, metadata = []) {
|
|
814
|
+
this.ensureInitialized();
|
|
815
|
+
const writes = [];
|
|
816
|
+
for (const { key, value } of metadata) {
|
|
817
|
+
const storageKey = this.getMetadataStorageKey(key);
|
|
818
|
+
writes.push(value === null
|
|
819
|
+
? { type: 'remove', key: storageKey }
|
|
820
|
+
: { type: 'set', key: storageKey, value: await this.sealMetadataValue(value) });
|
|
821
|
+
}
|
|
822
|
+
return this.receiveWork.complete(workId, expectedRevision, writes);
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Convert the legacy received-content rows to receive records. A backend
|
|
826
|
+
* without legacy rows gets no marker, so opening an empty store writes
|
|
827
|
+
* nothing. A full backend stops the conversion without the marker, and
|
|
828
|
+
* the next open continues it.
|
|
829
|
+
*/
|
|
830
|
+
async convertLegacyReceivedRows() {
|
|
831
|
+
const keys = await this.storageBackend.getAllKeys();
|
|
832
|
+
if (!keys.some((key) => key.startsWith(LEGACY_RECEIVED_CONTENT_PREFIX)))
|
|
833
|
+
return;
|
|
834
|
+
try {
|
|
835
|
+
await convertLegacyReceivedContent(this, this.receiveWork.legacySource());
|
|
836
|
+
}
|
|
837
|
+
catch (error) {
|
|
838
|
+
if (!isQuotaExceededError(error) && !(error instanceof StorageQuotaExceededError)) {
|
|
839
|
+
throw error;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
/** Encrypt one metadata value with the record cipher, behind its version tag. */
|
|
844
|
+
async sealMetadataValue(value) {
|
|
845
|
+
return `${METADATA_CIPHER_TAG}${await this.encrypt(value)}`;
|
|
846
|
+
}
|
|
847
|
+
/** Read one stored metadata value, encrypted or clear. */
|
|
848
|
+
async openMetadataValue(stored) {
|
|
849
|
+
if (stored === null || !stored.startsWith(METADATA_CIPHER_TAG))
|
|
850
|
+
return stored;
|
|
851
|
+
return this.decrypt(stored.slice(METADATA_CIPHER_TAG.length));
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Encrypt every clear metadata value, then set the marker. The marker is
|
|
855
|
+
* set last, so a crash partway leaves it unset and the next open runs the
|
|
856
|
+
* migration again. A value that carries the tag is never sealed again, so
|
|
857
|
+
* a corrupt encrypted value stays corrupt and its read fails in the cipher.
|
|
858
|
+
* Each value is replaced only while it still holds the clear value that was
|
|
859
|
+
* read, so a concurrent writer is never overwritten.
|
|
860
|
+
*
|
|
861
|
+
* A backend without metadata gets no marker, so opening an empty store
|
|
862
|
+
* writes nothing. A full backend stops the migration without the marker.
|
|
863
|
+
* The store still opens, because a reader accepts clear values, and the
|
|
864
|
+
* next open continues the migration.
|
|
865
|
+
*/
|
|
866
|
+
async encryptClearMetadata() {
|
|
867
|
+
const backend = this.storageBackend;
|
|
868
|
+
const marker = await backend.getItem(STORAGE_KEYS.METADATA_CIPHER_MARKER);
|
|
869
|
+
if (marker === METADATA_CIPHER_VERSION)
|
|
870
|
+
return;
|
|
871
|
+
const keys = (await backend.getAllKeys()).filter((key) => key.startsWith(STORAGE_KEYS.METADATA_PREFIX));
|
|
872
|
+
if (keys.length === 0)
|
|
873
|
+
return;
|
|
874
|
+
try {
|
|
875
|
+
for (const key of keys) {
|
|
876
|
+
const stored = await backend.getItem(key);
|
|
877
|
+
if (stored === null || stored.startsWith(METADATA_CIPHER_TAG))
|
|
878
|
+
continue;
|
|
879
|
+
const sealed = await this.sealMetadataValue(stored);
|
|
880
|
+
try {
|
|
881
|
+
await backend.atomicWrite([
|
|
882
|
+
{ type: 'check', key, expectedValue: stored },
|
|
883
|
+
{ type: 'set', key, value: sealed },
|
|
884
|
+
]);
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
if (isQuotaExceededError(error) || (await backend.getItem(key)) === stored)
|
|
888
|
+
throw error;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
await backend.setItem(STORAGE_KEYS.METADATA_CIPHER_MARKER, METADATA_CIPHER_VERSION);
|
|
892
|
+
}
|
|
893
|
+
catch (error) {
|
|
894
|
+
if (!isQuotaExceededError(error))
|
|
895
|
+
throw error;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
// ============================================================================
|
|
753
899
|
// Private Helper Methods
|
|
754
900
|
// ============================================================================
|
|
755
901
|
/**
|
|
@@ -976,7 +1122,7 @@ export class KeyValueSignalProtocolStore {
|
|
|
976
1122
|
const session = await this.getSessionRecord(ProtocolAddress.create(userId, deviceId));
|
|
977
1123
|
return withSession(userId, deviceId, stored, session);
|
|
978
1124
|
}
|
|
979
|
-
async setDeviceRecord(userId, deviceId, record) {
|
|
1125
|
+
async setDeviceRecord(userId, deviceId, record, options) {
|
|
980
1126
|
const now = Date.now();
|
|
981
1127
|
const userRecord = (await this.getStoredUserRecord(userId)) ?? {
|
|
982
1128
|
userId,
|
|
@@ -1005,11 +1151,16 @@ export class KeyValueSignalProtocolStore {
|
|
|
1005
1151
|
}),
|
|
1006
1152
|
});
|
|
1007
1153
|
}
|
|
1154
|
+
if (options?.senderKeyHandoffInvalidation) {
|
|
1155
|
+
operations.push(await this.senderKeyHandoffs.removeDevice(options.senderKeyHandoffInvalidation));
|
|
1156
|
+
}
|
|
1008
1157
|
await this.storageBackend.atomicWrite(operations);
|
|
1009
1158
|
}
|
|
1010
1159
|
async deleteDeviceRecord(userId, deviceId) {
|
|
1011
1160
|
const userRecord = await this.getStoredUserRecord(userId);
|
|
1161
|
+
const removeHandoffs = await this.senderKeyHandoffs.removeDevice({ userId, deviceId });
|
|
1012
1162
|
if (!userRecord) {
|
|
1163
|
+
await this.storageBackend.atomicWrite([removeHandoffs]);
|
|
1013
1164
|
return;
|
|
1014
1165
|
}
|
|
1015
1166
|
userRecord.devices.delete(deviceId);
|
|
@@ -1025,6 +1176,7 @@ export class KeyValueSignalProtocolStore {
|
|
|
1025
1176
|
key: userKey,
|
|
1026
1177
|
value: await this.encrypt(JSON.stringify(encodeUserRecord(userRecord))),
|
|
1027
1178
|
},
|
|
1179
|
+
removeHandoffs,
|
|
1028
1180
|
]);
|
|
1029
1181
|
}
|
|
1030
1182
|
async getStoredUserRecord(userId) {
|
|
@@ -1118,10 +1270,16 @@ export class KeyValueSignalProtocolStore {
|
|
|
1118
1270
|
const record = await this.getSenderKeyRecord(groupId, userId, deviceId);
|
|
1119
1271
|
return record?.[0] ?? null;
|
|
1120
1272
|
}
|
|
1121
|
-
async deleteSenderKey(groupId, userId, deviceId) {
|
|
1273
|
+
async deleteSenderKey(groupId, userId, deviceId, options) {
|
|
1122
1274
|
this.ensureInitialized();
|
|
1123
|
-
|
|
1124
|
-
|
|
1275
|
+
const operations = [
|
|
1276
|
+
...(await this.senderKeyIdPointerRemovals(groupId, userId, deviceId)),
|
|
1277
|
+
{ type: 'remove', key: this.getSenderKeyRecordStorageKey(groupId, userId, deviceId) },
|
|
1278
|
+
];
|
|
1279
|
+
if (options?.deleteSenderKeyHandoffs) {
|
|
1280
|
+
operations.push(await this.senderKeyHandoffs.removeGroup(groupId));
|
|
1281
|
+
}
|
|
1282
|
+
await this.storageBackend.atomicWrite(operations);
|
|
1125
1283
|
}
|
|
1126
1284
|
/**
|
|
1127
1285
|
* Build the storage key for a `senderKeyId` pointer.
|
|
@@ -1144,14 +1302,18 @@ export class KeyValueSignalProtocolStore {
|
|
|
1144
1302
|
* self-healing, because `resolveGroupForSenderKeyId` confirms and deletes
|
|
1145
1303
|
* it. A record that outlives its pointers is simply unreachable by id.
|
|
1146
1304
|
*/
|
|
1147
|
-
|
|
1305
|
+
/** The removals of the `senderKeyId` pointers of one stored record. */
|
|
1306
|
+
async senderKeyIdPointerRemovals(groupId, userId, deviceId) {
|
|
1148
1307
|
const record = await this.getSenderKeyRecord(groupId, userId, deviceId);
|
|
1149
1308
|
if (!record)
|
|
1150
|
-
return;
|
|
1151
|
-
|
|
1309
|
+
return [];
|
|
1310
|
+
return record
|
|
1152
1311
|
.map((state) => state.senderKeyId)
|
|
1153
1312
|
.filter(Boolean)
|
|
1154
|
-
.map((senderKeyId) =>
|
|
1313
|
+
.map((senderKeyId) => ({
|
|
1314
|
+
type: 'remove',
|
|
1315
|
+
key: this.getSenderKeyIdPointerKey(senderKeyId, userId, deviceId),
|
|
1316
|
+
}));
|
|
1155
1317
|
}
|
|
1156
1318
|
async resolveGroupForSenderKeyId(senderKeyId, userId, deviceId) {
|
|
1157
1319
|
this.ensureInitialized();
|
|
@@ -1225,17 +1387,21 @@ export class KeyValueSignalProtocolStore {
|
|
|
1225
1387
|
this.ensureInitialized();
|
|
1226
1388
|
const allKeys = await this.storageBackend.getAllKeys();
|
|
1227
1389
|
const senderKeys = allKeys.filter((key) => key.startsWith(this.getSenderKeyRecordGroupPrefix(groupId)));
|
|
1390
|
+
const operations = [];
|
|
1228
1391
|
for (const recordKey of senderKeys) {
|
|
1229
1392
|
const parsed = this.parseSenderKeyRecordStorageKey(recordKey);
|
|
1230
1393
|
if (parsed) {
|
|
1231
|
-
await this.
|
|
1394
|
+
operations.push(...(await this.senderKeyIdPointerRemovals(parsed.groupId, parsed.userId, parsed.deviceId)));
|
|
1232
1395
|
}
|
|
1233
1396
|
}
|
|
1234
1397
|
const skippedKeys = allKeys.filter((key) => key.startsWith(this.getSkippedSenderKeyGroupPrefix(groupId)));
|
|
1235
|
-
|
|
1398
|
+
for (const key of [...senderKeys, ...skippedKeys])
|
|
1399
|
+
operations.push({ type: 'remove', key });
|
|
1400
|
+
operations.push(await this.senderKeyHandoffs.removeGroup(groupId));
|
|
1401
|
+
await this.storageBackend.atomicWrite(operations);
|
|
1236
1402
|
return senderKeys.length;
|
|
1237
1403
|
}
|
|
1238
|
-
async storeSenderKeyRecord(groupId, userId, deviceId, states, receive) {
|
|
1404
|
+
async storeSenderKeyRecord(groupId, userId, deviceId, states, receive, options) {
|
|
1239
1405
|
this.ensureInitialized();
|
|
1240
1406
|
if (states.length === 0) {
|
|
1241
1407
|
return;
|
|
@@ -1284,21 +1450,46 @@ export class KeyValueSignalProtocolStore {
|
|
|
1284
1450
|
});
|
|
1285
1451
|
}
|
|
1286
1452
|
}
|
|
1287
|
-
if (receive.
|
|
1288
|
-
operations.push(
|
|
1289
|
-
type: 'set',
|
|
1290
|
-
key: `@signal:received-content:${receive.content.id}`,
|
|
1291
|
-
value: await this.encrypt(JSON.stringify(receive.content)),
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1453
|
+
if (receive.work)
|
|
1454
|
+
operations.push(await this.receiveWork.seal(receive.work));
|
|
1294
1455
|
if (receive.consumedSkippedKey !== undefined)
|
|
1295
1456
|
operations.push({
|
|
1296
1457
|
type: 'remove',
|
|
1297
1458
|
key: this.getSkippedSenderKeyStorageKey(groupId, userId, deviceId, receive.consumedSkippedKey.senderKeyId, receive.consumedSkippedKey.chainIndex),
|
|
1298
1459
|
});
|
|
1299
1460
|
}
|
|
1461
|
+
if (options?.deleteSenderKeyHandoffs) {
|
|
1462
|
+
operations.push(await this.senderKeyHandoffs.removeGroup(groupId));
|
|
1463
|
+
}
|
|
1300
1464
|
await this.storageBackend.atomicWrite(operations);
|
|
1301
1465
|
}
|
|
1466
|
+
// ============================================================================
|
|
1467
|
+
// Sender-Key Handoff Ledger
|
|
1468
|
+
// ============================================================================
|
|
1469
|
+
async recordSenderKeyHandoff(record) {
|
|
1470
|
+
this.ensureInitialized();
|
|
1471
|
+
await this.senderKeyHandoffs.record(record);
|
|
1472
|
+
}
|
|
1473
|
+
async listSenderKeyHandoffs(groupId, generation) {
|
|
1474
|
+
this.ensureInitialized();
|
|
1475
|
+
return this.senderKeyHandoffs.list(groupId, generation);
|
|
1476
|
+
}
|
|
1477
|
+
async invalidateSenderKeyHandoff(groupId, device) {
|
|
1478
|
+
this.ensureInitialized();
|
|
1479
|
+
return this.senderKeyHandoffs.deleteDeviceInGroup(groupId, device);
|
|
1480
|
+
}
|
|
1481
|
+
async invalidateAccountSenderKeyHandoffs(userId) {
|
|
1482
|
+
this.ensureInitialized();
|
|
1483
|
+
return this.senderKeyHandoffs.deleteAccount(userId);
|
|
1484
|
+
}
|
|
1485
|
+
async listSenderKeyHandoffGroupIds() {
|
|
1486
|
+
this.ensureInitialized();
|
|
1487
|
+
return this.senderKeyHandoffs.groupIds();
|
|
1488
|
+
}
|
|
1489
|
+
async retainSenderKeyHandoffs(groupId, senderKeyId) {
|
|
1490
|
+
this.ensureInitialized();
|
|
1491
|
+
return this.senderKeyHandoffs.retain(groupId, senderKeyId);
|
|
1492
|
+
}
|
|
1302
1493
|
async getSenderKeyRecord(groupId, userId, deviceId) {
|
|
1303
1494
|
this.ensureInitialized();
|
|
1304
1495
|
const encrypted = await this.storageBackend.getItem(this.getSenderKeyRecordStorageKey(groupId, userId, deviceId));
|
|
@@ -1346,12 +1537,86 @@ export class KeyValueSignalProtocolStore {
|
|
|
1346
1537
|
return matches.length;
|
|
1347
1538
|
}
|
|
1348
1539
|
// ============================================================================
|
|
1540
|
+
// Send Log (resendable group content)
|
|
1541
|
+
// The send log concept lives in ./send-log.ts. This store implements the
|
|
1542
|
+
// whole local store interface, so it keeps these delegates.
|
|
1543
|
+
// ============================================================================
|
|
1544
|
+
async storeSendLogEntry(payload, recipients) {
|
|
1545
|
+
this.ensureInitialized();
|
|
1546
|
+
return this.sendLog.storeSendLogEntry(payload, recipients);
|
|
1547
|
+
}
|
|
1548
|
+
async appendSendLogRecipients(clientMessageId, recipients) {
|
|
1549
|
+
this.ensureInitialized();
|
|
1550
|
+
return this.sendLog.appendSendLogRecipients(clientMessageId, recipients);
|
|
1551
|
+
}
|
|
1552
|
+
async markSendLogComplete(clientMessageId) {
|
|
1553
|
+
this.ensureInitialized();
|
|
1554
|
+
return this.sendLog.markSendLogComplete(clientMessageId);
|
|
1555
|
+
}
|
|
1556
|
+
async getSendLogEntry(clientMessageId, recipient) {
|
|
1557
|
+
this.ensureInitialized();
|
|
1558
|
+
return this.sendLog.getSendLogEntry(clientMessageId, recipient);
|
|
1559
|
+
}
|
|
1560
|
+
async findSendLogEntries(recipient, clientTimestamp) {
|
|
1561
|
+
this.ensureInitialized();
|
|
1562
|
+
return this.sendLog.findSendLogEntries(recipient, clientTimestamp);
|
|
1563
|
+
}
|
|
1564
|
+
async getSendLogRecipients(clientMessageId) {
|
|
1565
|
+
this.ensureInitialized();
|
|
1566
|
+
return this.sendLog.getSendLogRecipients(clientMessageId);
|
|
1567
|
+
}
|
|
1568
|
+
async deleteSendLogRecipient(clientMessageId, recipient) {
|
|
1569
|
+
this.ensureInitialized();
|
|
1570
|
+
return this.sendLog.deleteSendLogRecipient(clientMessageId, recipient);
|
|
1571
|
+
}
|
|
1572
|
+
async deleteSendLogRecipientsByTimestamp(recipient, clientTimestamps) {
|
|
1573
|
+
this.ensureInitialized();
|
|
1574
|
+
return this.sendLog.deleteSendLogRecipientsByTimestamp(recipient, clientTimestamps);
|
|
1575
|
+
}
|
|
1576
|
+
async incrementSendLogResendCount(clientMessageId, recipient) {
|
|
1577
|
+
this.ensureInitialized();
|
|
1578
|
+
return this.sendLog.incrementSendLogResendCount(clientMessageId, recipient);
|
|
1579
|
+
}
|
|
1580
|
+
async deleteSendLogEntry(clientMessageId) {
|
|
1581
|
+
this.ensureInitialized();
|
|
1582
|
+
return this.sendLog.deleteSendLogEntry(clientMessageId);
|
|
1583
|
+
}
|
|
1584
|
+
async deleteExpiredSendLog(maxAgeMs) {
|
|
1585
|
+
this.ensureInitialized();
|
|
1586
|
+
return this.sendLog.deleteExpiredSendLog(maxAgeMs);
|
|
1587
|
+
}
|
|
1588
|
+
async clearSendLog() {
|
|
1589
|
+
this.ensureInitialized();
|
|
1590
|
+
return this.sendLog.clearSendLog();
|
|
1591
|
+
}
|
|
1592
|
+
async storeResendJob(job) {
|
|
1593
|
+
this.ensureInitialized();
|
|
1594
|
+
return this.sendLog.storeResendJob(job);
|
|
1595
|
+
}
|
|
1596
|
+
async getResendJob(jobId) {
|
|
1597
|
+
this.ensureInitialized();
|
|
1598
|
+
return this.sendLog.getResendJob(jobId);
|
|
1599
|
+
}
|
|
1600
|
+
async getPendingResendJobs() {
|
|
1601
|
+
this.ensureInitialized();
|
|
1602
|
+
return this.sendLog.getPendingResendJobs();
|
|
1603
|
+
}
|
|
1604
|
+
async completeResendJob(jobId, state) {
|
|
1605
|
+
this.ensureInitialized();
|
|
1606
|
+
return this.sendLog.completeResendJob(jobId, state);
|
|
1607
|
+
}
|
|
1608
|
+
// ============================================================================
|
|
1349
1609
|
// Message Record Storage (Not Yet Implemented)
|
|
1350
1610
|
// Retry records are indexed by the client timestamp assigned before encryption.
|
|
1351
1611
|
// ============================================================================
|
|
1352
1612
|
async storeMessageRecord(record) {
|
|
1353
1613
|
this.ensureInitialized();
|
|
1354
|
-
|
|
1614
|
+
const key = this.getMessageRecordStorageKey(record.sessionId, record.timestamp);
|
|
1615
|
+
const stored = await this.storageBackend.getItem(key);
|
|
1616
|
+
const createdAt = stored
|
|
1617
|
+
? JSON.parse(await this.decrypt(stored)).createdAt
|
|
1618
|
+
: Date.now();
|
|
1619
|
+
await this.storageBackend.setItem(key, await this.encrypt(JSON.stringify({ ...record, createdAt })));
|
|
1355
1620
|
}
|
|
1356
1621
|
async getMessageRecord(sessionId, timestamp) {
|
|
1357
1622
|
this.ensureInitialized();
|
|
@@ -1405,6 +1670,45 @@ export class KeyValueSignalProtocolStore {
|
|
|
1405
1670
|
}
|
|
1406
1671
|
return messageKeys.length;
|
|
1407
1672
|
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Each write checks that the record still holds the value that `rewrite`
|
|
1675
|
+
* read. A record that another write replaced in between stays as that
|
|
1676
|
+
* write left it.
|
|
1677
|
+
*/
|
|
1678
|
+
async rewriteMessageRecords(rewrite) {
|
|
1679
|
+
this.ensureInitialized();
|
|
1680
|
+
const allKeys = await this.storageBackend.getAllKeys();
|
|
1681
|
+
const messageKeys = allKeys.filter((key) => key.startsWith(STORAGE_KEYS.MESSAGE_RECORD_PREFIX));
|
|
1682
|
+
let changed = 0;
|
|
1683
|
+
for (const key of messageKeys) {
|
|
1684
|
+
const encrypted = await this.storageBackend.getItem(key);
|
|
1685
|
+
if (!encrypted)
|
|
1686
|
+
continue;
|
|
1687
|
+
const record = JSON.parse(await this.decrypt(encrypted));
|
|
1688
|
+
const plaintext = rewrite(record);
|
|
1689
|
+
if (plaintext === record.plaintext)
|
|
1690
|
+
continue;
|
|
1691
|
+
const write = plaintext === null
|
|
1692
|
+
? { type: 'remove', key }
|
|
1693
|
+
: {
|
|
1694
|
+
type: 'set',
|
|
1695
|
+
key,
|
|
1696
|
+
value: await this.encrypt(JSON.stringify({ ...record, plaintext })),
|
|
1697
|
+
};
|
|
1698
|
+
try {
|
|
1699
|
+
await this.storageBackend.atomicWrite([
|
|
1700
|
+
{ type: 'check', key, expectedValue: encrypted },
|
|
1701
|
+
write,
|
|
1702
|
+
]);
|
|
1703
|
+
changed++;
|
|
1704
|
+
}
|
|
1705
|
+
catch (error) {
|
|
1706
|
+
if ((await this.storageBackend.getItem(key)) === encrypted)
|
|
1707
|
+
throw error;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return changed;
|
|
1711
|
+
}
|
|
1408
1712
|
// ============================================================================
|
|
1409
1713
|
// Key Recovery Methods (Bug #7 - Identifier Collision Recovery)
|
|
1410
1714
|
// ============================================================================
|
|
@@ -1474,12 +1778,14 @@ export class KeyValueSignalProtocolStore {
|
|
|
1474
1778
|
}
|
|
1475
1779
|
/**
|
|
1476
1780
|
* A device record is stale when it has no current session and no archived
|
|
1477
|
-
* session, and it has not been updated within `maxLatency
|
|
1781
|
+
* session, and it has not been updated within `maxLatency`, or when its
|
|
1782
|
+
* removal is older than `maxLatency`.
|
|
1478
1783
|
*/
|
|
1479
1784
|
function isStaleDeviceRecord(record, now, maxLatency) {
|
|
1480
1785
|
const hasNoSessions = !record.session ||
|
|
1481
1786
|
(!record.session.currentSession && Object.keys(record.session.archivedSessions).length === 0);
|
|
1482
|
-
return hasNoSessions && now - record.updatedAt > maxLatency
|
|
1787
|
+
return ((hasNoSessions && now - record.updatedAt > maxLatency) ||
|
|
1788
|
+
isExpiredRemovedDevice(record, now, maxLatency));
|
|
1483
1789
|
}
|
|
1484
1790
|
/**
|
|
1485
1791
|
* Delete the sessions of `record` that are older than `maxRecv`, and return
|