@open-e2ee/signal-protocol-sdk 11.0.0 → 12.0.1
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 +1348 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/TROUBLESHOOTING.md +8 -8
- package/client/README.md +70 -37
- package/device/README.md +39 -85
- package/dist/client/client.d.ts +334 -63
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +1175 -186
- package/dist/client/client.js.map +1 -1
- package/dist/client/config.d.ts +57 -42
- 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 +280 -14
- package/dist/client/event-hooks.d.ts.map +1 -1
- package/dist/client/event-hooks.js +8 -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-mailbox-subscription.d.ts +34 -2
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +87 -17
- 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 +115 -55
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted.d.ts +10 -4
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +10 -4
- package/dist/client/hosted.js.map +1 -1
- package/dist/client/index.d.ts +5 -3
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -0
- 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 +111 -20
- package/dist/client/messages.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 +20 -7
- package/dist/client/relay-acceptance.d.ts.map +1 -1
- package/dist/client/relay-acceptance.js +30 -12
- 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 +193 -123
- 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 +57 -10
- package/dist/client/retry-family.d.ts.map +1 -1
- package/dist/client/retry-family.js +54 -12
- package/dist/client/retry-family.js.map +1 -1
- package/dist/client/retry-request-envelope.d.ts +107 -8
- package/dist/client/retry-request-envelope.d.ts.map +1 -1
- package/dist/client/retry-request-envelope.js +172 -23
- package/dist/client/retry-request-envelope.js.map +1 -1
- package/dist/client/retry-request-lifecycle.d.ts +70 -14
- package/dist/client/retry-request-lifecycle.d.ts.map +1 -1
- package/dist/client/retry-request-lifecycle.js +162 -32
- package/dist/client/retry-request-lifecycle.js.map +1 -1
- 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 +100 -12
- package/dist/client/retry.d.ts.map +1 -1
- package/dist/client/retry.js +619 -116
- 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 +2260 -342
- 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 +26 -20
- package/dist/internal/manager/manager.d.ts.map +1 -1
- package/dist/internal/manager/manager.js +64 -41
- 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 +15 -13
- package/dist/internal/session/cipher.d.ts.map +1 -1
- package/dist/internal/session/cipher.js +41 -23
- 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 +5 -13
- 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 +317 -18
- package/dist/local/store/reliability.d.ts.map +1 -1
- package/dist/local/store/reliability.js +371 -46
- 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/driver.d.ts +9 -0
- package/dist/local/store/sqlite/driver.d.ts.map +1 -1
- 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/sqlite/web/sqlite3mc/sqlite3.mjs +2 -1
- package/dist/local/store/sqlite/web/worker.d.ts +8 -0
- package/dist/local/store/sqlite/web/worker.d.ts.map +1 -1
- package/dist/local/store/sqlite/web/worker.js +64 -2
- package/dist/local/store/sqlite/web/worker.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 +92 -107
- 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/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 +165 -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
|
@@ -28,11 +28,16 @@ import { acceptContactIdentityRotation as acceptRotation, createUnverifiedContac
|
|
|
28
28
|
import { ProtocolAddress } from '../../../types/address.js';
|
|
29
29
|
import { IdentityKeyChange, StorageQuotaExceededError } from '../../../types/index.js';
|
|
30
30
|
import { assertCurrentSessionRecord } from '../../../types/session.js';
|
|
31
|
+
import { isExpiredRemovedDevice } from '../../../internal/sesame/types.js';
|
|
31
32
|
import { withDeviceRecordLocks } from '../../../internal/session/record-locks.js';
|
|
32
33
|
import { withSession } from '../device-record.js';
|
|
33
34
|
import { decodeUserRecord, encodeUserRecord } from './device-record.js';
|
|
35
|
+
import { IndexedDbSendLog, SEND_LOG_STORE_NAMES, upgradeSendLogStores, } from './send-log.js';
|
|
36
|
+
import { IndexedDbReceiveWork, upgradeReceiveWorkStore, } from './receive-work.js';
|
|
37
|
+
import { IndexedDbSenderKeyHandoffs, upgradeSenderKeyHandoffStore, } from './sender-key-handoff.js';
|
|
34
38
|
import { deserializeSessionRecord, serializeSessionRecord } from '../session-codec.js';
|
|
35
|
-
import { receivedContentKey
|
|
39
|
+
import { receivedContentKey } from '../received-content.js';
|
|
40
|
+
import { convertLegacyReceivedContent } from '../receive-work.js';
|
|
36
41
|
import { createKyberPreKeyState, createKyberPreKeyInstanceId, getCurrentKyberPreKey, getRetainedKyberPreKey, recordKyberPreKeyUse, recordKyberPreKeyUseById, retainKyberPreKey, } from '../kyber-prekey-lifecycle.js';
|
|
37
42
|
function equalBytes(left, right) {
|
|
38
43
|
if (!left || !right)
|
|
@@ -41,6 +46,69 @@ function equalBytes(left, right) {
|
|
|
41
46
|
return false;
|
|
42
47
|
return left.every((value, index) => value === right[index]);
|
|
43
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The first byte of an encrypted metadata value. The record cipher's output
|
|
51
|
+
* follows it. A metadata value stored as a string is a clear value that an
|
|
52
|
+
* older SDK wrote.
|
|
53
|
+
*/
|
|
54
|
+
const METADATA_CIPHER_VERSION = 1;
|
|
55
|
+
/**
|
|
56
|
+
* Set after every clear metadata value is encrypted. A crash before it is set
|
|
57
|
+
* runs the migration again at the next open.
|
|
58
|
+
*/
|
|
59
|
+
const METADATA_CIPHER_MARKER_KEY = 'metadataCipherVersion';
|
|
60
|
+
function metadataStorageKey(key) {
|
|
61
|
+
return `meta:${key}`;
|
|
62
|
+
}
|
|
63
|
+
/** Compares two raw stored metadata values, clear or encrypted. */
|
|
64
|
+
function sameStoredMetadata(left, right) {
|
|
65
|
+
if (left instanceof Uint8Array && right instanceof Uint8Array)
|
|
66
|
+
return equalBytes(left, right);
|
|
67
|
+
return left === right;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The database as the send log types it. The schema extends
|
|
71
|
+
* `SendLogDBSchema`, so the send log stores have the same types in both. The
|
|
72
|
+
* idb types do not let a database with more stores stand in for one with
|
|
73
|
+
* fewer.
|
|
74
|
+
*/
|
|
75
|
+
function sendLogView(db) {
|
|
76
|
+
return db;
|
|
77
|
+
}
|
|
78
|
+
/** The database as the receive records type it, for the same reason as `sendLogView`. */
|
|
79
|
+
function receiveWorkView(db) {
|
|
80
|
+
return db;
|
|
81
|
+
}
|
|
82
|
+
/** The database as the sender-key handoff rows type it, for the same reason as `sendLogView`. */
|
|
83
|
+
function senderKeyHandoffView(db) {
|
|
84
|
+
return db;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run the reads and the mutations of one read-write transaction. `enter`
|
|
88
|
+
* reads what it needs, then pushes every mutation in one synchronous batch:
|
|
89
|
+
* a page that dies commits a transaction idle at an await, so an await
|
|
90
|
+
* between two mutations could land only some of them. A failure aborts the
|
|
91
|
+
* transaction, so no mutation of the batch commits.
|
|
92
|
+
*/
|
|
93
|
+
async function commitTransaction(tx, enter) {
|
|
94
|
+
const writes = [];
|
|
95
|
+
const completed = tx.done;
|
|
96
|
+
void completed.catch(() => undefined);
|
|
97
|
+
try {
|
|
98
|
+
await enter(writes);
|
|
99
|
+
await Promise.all([...writes, completed]);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
try {
|
|
103
|
+
tx.abort();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
/* The failed transaction can already be inactive. */
|
|
107
|
+
}
|
|
108
|
+
await Promise.allSettled([...writes, completed]);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
44
112
|
/**
|
|
45
113
|
* Compares stored ciphertext, not secret material - corrupt-row cleanup only
|
|
46
114
|
* deletes a row whose bytes are still the ones that failed to deserialize.
|
|
@@ -142,10 +210,35 @@ function mapQuotaFailuresAtBoundary(store) {
|
|
|
142
210
|
* - TOFU (Trust On First Use) for contact verification
|
|
143
211
|
*/
|
|
144
212
|
export class IndexedDbSignalProtocolStore {
|
|
213
|
+
/** Each value is encrypted with a key that this database holds in the same origin. */
|
|
214
|
+
protection = Object.freeze({
|
|
215
|
+
atRest: 'record-cipher',
|
|
216
|
+
keyCustody: 'same-origin',
|
|
217
|
+
});
|
|
145
218
|
db = null;
|
|
146
219
|
databaseKey = null;
|
|
220
|
+
senderKeyHandoffs = new IndexedDbSenderKeyHandoffs(() => senderKeyHandoffView(this.db), {
|
|
221
|
+
encrypt: (plaintext) => this.encrypt(plaintext),
|
|
222
|
+
decrypt: (encrypted) => this.decrypt(encrypted),
|
|
223
|
+
databaseKey: () => this.getDatabaseKey(),
|
|
224
|
+
});
|
|
147
225
|
dbName = 'signal-protocol-storage';
|
|
148
|
-
|
|
226
|
+
/** The database name. The tabs and workers of the origin share its locks. */
|
|
227
|
+
storeIdentity = this.dbName;
|
|
228
|
+
// v10 adds the sender-key handoff store. v11 adds `removedAt` to the
|
|
229
|
+
// device record. The encrypted record holds the field, so v11 changes no
|
|
230
|
+
// object store. It keeps an older SDK, which does not skip a removed
|
|
231
|
+
// device, from opening the database.
|
|
232
|
+
dbVersion = 11;
|
|
233
|
+
sendLog = new IndexedDbSendLog(() => sendLogView(this.db), {
|
|
234
|
+
encrypt: (plaintext) => this.encrypt(plaintext),
|
|
235
|
+
decrypt: (encrypted) => this.decrypt(encrypted),
|
|
236
|
+
});
|
|
237
|
+
receiveWork = new IndexedDbReceiveWork(() => receiveWorkView(this.db), {
|
|
238
|
+
encrypt: (plaintext) => this.encrypt(plaintext),
|
|
239
|
+
decrypt: (encrypted) => this.decrypt(encrypted),
|
|
240
|
+
databaseKey: () => this.getDatabaseKey(),
|
|
241
|
+
});
|
|
149
242
|
constructor() {
|
|
150
243
|
mapQuotaFailuresAtBoundary(this);
|
|
151
244
|
}
|
|
@@ -238,6 +331,9 @@ export class IndexedDbSignalProtocolStore {
|
|
|
238
331
|
messageStore.createIndex('by-session', 'sessionId');
|
|
239
332
|
messageStore.createIndex('by-created', 'createdAt');
|
|
240
333
|
}
|
|
334
|
+
upgradeSendLogStores(sendLogView(db));
|
|
335
|
+
upgradeReceiveWorkStore(receiveWorkView(db));
|
|
336
|
+
upgradeSenderKeyHandoffStore(senderKeyHandoffView(db));
|
|
241
337
|
},
|
|
242
338
|
});
|
|
243
339
|
// Get or generate database encryption key
|
|
@@ -264,6 +360,8 @@ export class IndexedDbSignalProtocolStore {
|
|
|
264
360
|
console.warn('[IndexedDbSignalProtocolStore] Database encryption key stored in IndexedDB. ' +
|
|
265
361
|
'Ensure Content Security Policy (CSP) is configured to mitigate XSS risks.');
|
|
266
362
|
}
|
|
363
|
+
await this.encryptClearMetadata();
|
|
364
|
+
await this.convertLegacyReceivedRows();
|
|
267
365
|
}
|
|
268
366
|
/**
|
|
269
367
|
* Close the underlying IndexedDB connection and drop the in-memory copy of
|
|
@@ -394,31 +492,35 @@ export class IndexedDbSignalProtocolStore {
|
|
|
394
492
|
const replacement = acceptRotation(existing, identity, Date.now(), suppliedCommitment);
|
|
395
493
|
validateContactIdentityRecord(replacement);
|
|
396
494
|
const encrypted = await this.encrypt(JSON.stringify(replacement));
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
await
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
contacts.put({
|
|
495
|
+
const accountHash = (await this.senderKeyHandoffs.index()).account(address.userId);
|
|
496
|
+
const tx = this.db.transaction(['contacts', 'sessions', 'senderKeyHandoff'], 'readwrite');
|
|
497
|
+
await commitTransaction(tx, async (writes) => {
|
|
498
|
+
const contacts = tx.objectStore('contacts');
|
|
499
|
+
const current = await contacts.get(key);
|
|
500
|
+
if (!current || current.revision !== existing.revision) {
|
|
501
|
+
throw new Error('Contact identity changed concurrently during rotation');
|
|
502
|
+
}
|
|
503
|
+
// Read the doomed session and handoff keys before mutating, then enter
|
|
504
|
+
// every mutation in one synchronous batch. A cursor walk that deletes
|
|
505
|
+
// as it goes leaves windows where the new pin commits with sessions
|
|
506
|
+
// still trusted under the old identity.
|
|
507
|
+
const sessions = tx.objectStore('sessions');
|
|
508
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
509
|
+
const doomedKeys = await sessions.index('by-user').getAllKeys(address.userId);
|
|
510
|
+
const doomedHandoffs = await handoffs.index('by-account').getAllKeys(accountHash);
|
|
511
|
+
writes.push(contacts.put({
|
|
414
512
|
key,
|
|
415
513
|
userId: address.userId,
|
|
416
514
|
data: encrypted,
|
|
417
515
|
revision: replacement.revision,
|
|
418
|
-
})
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
516
|
+
}));
|
|
517
|
+
// Push each request as it is created. A later synchronous throw must
|
|
518
|
+
// not leave an earlier request outside the settled set.
|
|
519
|
+
for (const sessionKey of doomedKeys)
|
|
520
|
+
writes.push(sessions.delete(sessionKey));
|
|
521
|
+
for (const handoffKey of doomedHandoffs)
|
|
522
|
+
writes.push(handoffs.delete(handoffKey));
|
|
523
|
+
});
|
|
422
524
|
return replacement;
|
|
423
525
|
}
|
|
424
526
|
async verifyContactIdentity(address, identity, identityType, suppliedCommitment) {
|
|
@@ -712,9 +814,7 @@ export class IndexedDbSignalProtocolStore {
|
|
|
712
814
|
? await this.encrypt(JSON.stringify(newContact))
|
|
713
815
|
: undefined;
|
|
714
816
|
const encrypted = await this.encrypt(serializeSessionRecord(commit.record));
|
|
715
|
-
const
|
|
716
|
-
? await this.encrypt(JSON.stringify(commit.receivedContent))
|
|
717
|
-
: undefined;
|
|
817
|
+
const work = commit.receiveWork ? await this.receiveWork.seal(commit.receiveWork) : undefined;
|
|
718
818
|
const kyberStorageKey = `kyber:${commit.localIdentityType}`;
|
|
719
819
|
const storedKyberState = commit.kyberPreKeyUse
|
|
720
820
|
? await this.db.get('prekeys', kyberStorageKey)
|
|
@@ -727,7 +827,11 @@ export class IndexedDbSignalProtocolStore {
|
|
|
727
827
|
recordKyberPreKeyUse(state, commit.localIdentityType, commit.kyberPreKeyUse);
|
|
728
828
|
updatedKyberState = await this.encrypt(JSON.stringify(state));
|
|
729
829
|
}
|
|
730
|
-
const
|
|
830
|
+
const invalidation = commit.senderKeyHandoffInvalidation;
|
|
831
|
+
const invalidatedHash = invalidation
|
|
832
|
+
? (await this.senderKeyHandoffs.index()).recipient(invalidation)
|
|
833
|
+
: undefined;
|
|
834
|
+
const tx = this.db.transaction(['contacts', 'prekeys', 'sessions', 'receiveWork', 'senderKeyHandoff'], 'readwrite');
|
|
731
835
|
const contacts = tx.objectStore('contacts');
|
|
732
836
|
const prekeys = tx.objectStore('prekeys');
|
|
733
837
|
const currentContactRow = await contacts.get(contactKey);
|
|
@@ -756,14 +860,18 @@ export class IndexedDbSignalProtocolStore {
|
|
|
756
860
|
await tx.done;
|
|
757
861
|
throw new Error('Kyber prekey state changed during atomic session/trust commit');
|
|
758
862
|
}
|
|
863
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
864
|
+
const doomedHandoffs = invalidatedHash === undefined
|
|
865
|
+
? []
|
|
866
|
+
: await handoffs.index('by-recipient').getAllKeys(invalidatedHash);
|
|
759
867
|
// Every mutation must enter the transaction in one synchronous batch.
|
|
760
868
|
// A dying page closes its connection gracefully, and a transaction that
|
|
761
869
|
// is idle at an await boundary then commits the writes it already holds.
|
|
762
870
|
// An await between mutations is a window for a partial commit.
|
|
763
871
|
const writes = [];
|
|
764
872
|
try {
|
|
765
|
-
if (
|
|
766
|
-
writes.push(tx.objectStore('
|
|
873
|
+
if (work)
|
|
874
|
+
writes.push(tx.objectStore('receiveWork').put(work));
|
|
767
875
|
if (newContact && encryptedContact) {
|
|
768
876
|
writes.push(contacts.put({
|
|
769
877
|
key: contactKey,
|
|
@@ -787,6 +895,8 @@ export class IndexedDbSignalProtocolStore {
|
|
|
787
895
|
writes.push(prekeys.delete(kemPreKeyStorageKey));
|
|
788
896
|
if (updatedKyberState)
|
|
789
897
|
writes.push(prekeys.put(updatedKyberState, kyberStorageKey));
|
|
898
|
+
for (const handoffKey of doomedHandoffs)
|
|
899
|
+
writes.push(handoffs.delete(handoffKey));
|
|
790
900
|
await Promise.all([...writes, tx.done]);
|
|
791
901
|
}
|
|
792
902
|
catch (error) {
|
|
@@ -802,28 +912,56 @@ export class IndexedDbSignalProtocolStore {
|
|
|
802
912
|
}
|
|
803
913
|
async deleteSessionRecord(address) {
|
|
804
914
|
this.ensureInitialized();
|
|
805
|
-
|
|
806
|
-
await this.db.delete('sessions', addressKey);
|
|
915
|
+
await this.replaceSessionAndDeleteHandoffs(address, null);
|
|
807
916
|
}
|
|
808
917
|
async archiveCurrentSession(address, newSession) {
|
|
809
918
|
this.ensureInitialized();
|
|
810
919
|
// With SessionRecord, archiving is handled via SessionRecord.archiveCurrent()
|
|
811
920
|
// This method updates or replaces the session state
|
|
812
|
-
if (newSession) {
|
|
813
|
-
const record = await this.getSessionRecord(address);
|
|
814
|
-
if (record) {
|
|
815
|
-
// Update existing session with new state
|
|
816
|
-
record.currentSession = newSession;
|
|
817
|
-
if (record.metadata) {
|
|
818
|
-
record.metadata.lastSentAt = Date.now();
|
|
819
|
-
}
|
|
820
|
-
await this.storeSessionRecord(address, record);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
else {
|
|
921
|
+
if (!newSession) {
|
|
824
922
|
// If no new session, just delete the old one
|
|
825
|
-
await this.
|
|
923
|
+
await this.replaceSessionAndDeleteHandoffs(address, null);
|
|
924
|
+
return;
|
|
826
925
|
}
|
|
926
|
+
const record = await this.getSessionRecord(address);
|
|
927
|
+
if (record) {
|
|
928
|
+
// Update existing session with new state
|
|
929
|
+
record.currentSession = newSession;
|
|
930
|
+
if (record.metadata) {
|
|
931
|
+
record.metadata.lastSentAt = Date.now();
|
|
932
|
+
}
|
|
933
|
+
assertCurrentSessionRecord(record);
|
|
934
|
+
}
|
|
935
|
+
await this.replaceSessionAndDeleteHandoffs(address, record ? await this.encrypt(serializeSessionRecord(record)) : undefined);
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Write or delete the session of one device and delete the handoff rows of
|
|
939
|
+
* that device in every group, in one transaction. `null` deletes the
|
|
940
|
+
* session, and `undefined` leaves it.
|
|
941
|
+
*/
|
|
942
|
+
async replaceSessionAndDeleteHandoffs(address, encrypted) {
|
|
943
|
+
const addressKey = this.serializeAddress(address);
|
|
944
|
+
const recipientHash = (await this.senderKeyHandoffs.index()).recipient(address);
|
|
945
|
+
const tx = this.db.transaction(['sessions', 'senderKeyHandoff'], 'readwrite');
|
|
946
|
+
await commitTransaction(tx, async (writes) => {
|
|
947
|
+
const sessions = tx.objectStore('sessions');
|
|
948
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
949
|
+
const doomedHandoffs = await handoffs.index('by-recipient').getAllKeys(recipientHash);
|
|
950
|
+
if (encrypted) {
|
|
951
|
+
writes.push(sessions.put({
|
|
952
|
+
key: addressKey,
|
|
953
|
+
userId: address.userId,
|
|
954
|
+
deviceId: address.deviceId,
|
|
955
|
+
data: encrypted,
|
|
956
|
+
updatedAt: Date.now(),
|
|
957
|
+
}));
|
|
958
|
+
}
|
|
959
|
+
else if (encrypted === null) {
|
|
960
|
+
writes.push(sessions.delete(addressKey));
|
|
961
|
+
}
|
|
962
|
+
for (const handoffKey of doomedHandoffs)
|
|
963
|
+
writes.push(handoffs.delete(handoffKey));
|
|
964
|
+
});
|
|
827
965
|
}
|
|
828
966
|
async getSessionsForUser(userId) {
|
|
829
967
|
this.ensureInitialized();
|
|
@@ -889,6 +1027,10 @@ export class IndexedDbSignalProtocolStore {
|
|
|
889
1027
|
await this.db.clear('senderKeyRecords');
|
|
890
1028
|
await this.db.clear('skippedSenderKeys');
|
|
891
1029
|
await this.db.clear('messageRecords');
|
|
1030
|
+
for (const name of SEND_LOG_STORE_NAMES)
|
|
1031
|
+
await this.db.clear(name);
|
|
1032
|
+
await this.db.clear('receiveWork');
|
|
1033
|
+
await this.db.clear('senderKeyHandoff');
|
|
892
1034
|
// Generate new database encryption key after clearing
|
|
893
1035
|
this.databaseKey = await generateRandomBytes(32);
|
|
894
1036
|
await this.db.put('metadata', this.databaseKey, 'databaseKey');
|
|
@@ -898,30 +1040,38 @@ export class IndexedDbSignalProtocolStore {
|
|
|
898
1040
|
// ============================================================================
|
|
899
1041
|
async getMetadata(key) {
|
|
900
1042
|
this.ensureInitialized();
|
|
901
|
-
|
|
902
|
-
return typeof stored === 'string' ? stored : null;
|
|
1043
|
+
return await this.openMetadataValue(await this.db.get('metadata', metadataStorageKey(key)));
|
|
903
1044
|
}
|
|
904
1045
|
async setMetadata(key, value) {
|
|
905
1046
|
this.ensureInitialized();
|
|
906
|
-
await this.
|
|
1047
|
+
const sealed = await this.sealMetadataValue(value);
|
|
1048
|
+
await this.db.put('metadata', sealed, metadataStorageKey(key));
|
|
907
1049
|
}
|
|
908
1050
|
async deleteMetadata(key) {
|
|
909
1051
|
this.ensureInitialized();
|
|
910
|
-
await this.db.delete('metadata',
|
|
1052
|
+
await this.db.delete('metadata', metadataStorageKey(key));
|
|
911
1053
|
}
|
|
912
1054
|
async compareAndSetMetadata(key, expected, value) {
|
|
913
1055
|
this.ensureInitialized();
|
|
1056
|
+
const storageKey = metadataStorageKey(key);
|
|
1057
|
+
// The cipher is not an IndexedDB request, and an await on it would let
|
|
1058
|
+
// the transaction commit. So the decrypt and the encrypt run first. The
|
|
1059
|
+
// transaction then compares the raw value that was read, so a writer that
|
|
1060
|
+
// changed the value since that read fails the check.
|
|
1061
|
+
const observed = await this.db.get('metadata', storageKey);
|
|
1062
|
+
if ((await this.openMetadataValue(observed)) !== expected)
|
|
1063
|
+
return false;
|
|
1064
|
+
const sealed = value === null ? null : await this.sealMetadataValue(value);
|
|
914
1065
|
const tx = this.db.transaction('metadata', 'readwrite');
|
|
915
1066
|
try {
|
|
916
|
-
|
|
917
|
-
if ((typeof stored === 'string' ? stored : null) !== expected) {
|
|
1067
|
+
if (!sameStoredMetadata(await tx.store.get(storageKey), observed)) {
|
|
918
1068
|
await tx.done;
|
|
919
1069
|
return false;
|
|
920
1070
|
}
|
|
921
|
-
if (
|
|
922
|
-
await tx.store.delete(
|
|
1071
|
+
if (sealed === null)
|
|
1072
|
+
await tx.store.delete(storageKey);
|
|
923
1073
|
else
|
|
924
|
-
await tx.store.put(
|
|
1074
|
+
await tx.store.put(sealed, storageKey);
|
|
925
1075
|
await tx.done;
|
|
926
1076
|
return true;
|
|
927
1077
|
}
|
|
@@ -930,6 +1080,65 @@ export class IndexedDbSignalProtocolStore {
|
|
|
930
1080
|
throw error;
|
|
931
1081
|
}
|
|
932
1082
|
}
|
|
1083
|
+
/** Encrypt one metadata value with the record cipher, behind its version byte. */
|
|
1084
|
+
async sealMetadataValue(value) {
|
|
1085
|
+
const encrypted = await this.encrypt(value);
|
|
1086
|
+
const sealed = new Uint8Array(1 + encrypted.length);
|
|
1087
|
+
sealed[0] = METADATA_CIPHER_VERSION;
|
|
1088
|
+
sealed.set(encrypted, 1);
|
|
1089
|
+
return sealed;
|
|
1090
|
+
}
|
|
1091
|
+
/** Read one stored metadata value, encrypted or clear. */
|
|
1092
|
+
async openMetadataValue(stored) {
|
|
1093
|
+
if (typeof stored === 'string')
|
|
1094
|
+
return stored;
|
|
1095
|
+
if (!(stored instanceof Uint8Array))
|
|
1096
|
+
return null;
|
|
1097
|
+
if (stored[0] !== METADATA_CIPHER_VERSION) {
|
|
1098
|
+
throw new Error(`Unsupported metadata cipher version ${stored[0]}`);
|
|
1099
|
+
}
|
|
1100
|
+
return await this.decrypt(stored.subarray(1));
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* Encrypt every clear metadata value, then set the marker. The marker is
|
|
1104
|
+
* set last, so a crash partway leaves it unset and the next open runs the
|
|
1105
|
+
* migration again. Each value is replaced only while it still holds the
|
|
1106
|
+
* clear value that was read, so a concurrent writer is never overwritten.
|
|
1107
|
+
*
|
|
1108
|
+
* A full origin stops the migration without the marker. The store still
|
|
1109
|
+
* opens, because a reader accepts clear values, and the next open
|
|
1110
|
+
* continues the migration.
|
|
1111
|
+
*/
|
|
1112
|
+
async encryptClearMetadata() {
|
|
1113
|
+
const db = this.db;
|
|
1114
|
+
if ((await db.get('metadata', METADATA_CIPHER_MARKER_KEY)) === METADATA_CIPHER_VERSION)
|
|
1115
|
+
return;
|
|
1116
|
+
const prefix = metadataStorageKey('');
|
|
1117
|
+
const keys = (await db.getAllKeys('metadata')).filter((key) => key.startsWith(prefix));
|
|
1118
|
+
try {
|
|
1119
|
+
for (const key of keys) {
|
|
1120
|
+
const stored = await db.get('metadata', key);
|
|
1121
|
+
if (typeof stored !== 'string')
|
|
1122
|
+
continue;
|
|
1123
|
+
const sealed = await this.sealMetadataValue(stored);
|
|
1124
|
+
const tx = db.transaction('metadata', 'readwrite');
|
|
1125
|
+
try {
|
|
1126
|
+
if ((await tx.store.get(key)) === stored)
|
|
1127
|
+
await tx.store.put(sealed, key);
|
|
1128
|
+
await tx.done;
|
|
1129
|
+
}
|
|
1130
|
+
catch (error) {
|
|
1131
|
+
await tx.done.catch(() => undefined);
|
|
1132
|
+
throw error;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
await db.put('metadata', METADATA_CIPHER_VERSION, METADATA_CIPHER_MARKER_KEY);
|
|
1136
|
+
}
|
|
1137
|
+
catch (error) {
|
|
1138
|
+
if (!isQuotaExceededError(error))
|
|
1139
|
+
throw error;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
933
1142
|
// ============================================================================
|
|
934
1143
|
// Private Helper Methods
|
|
935
1144
|
// ============================================================================
|
|
@@ -1026,7 +1235,7 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1026
1235
|
const session = await this.getSessionRecord(ProtocolAddress.create(userId, deviceId));
|
|
1027
1236
|
return withSession(userId, deviceId, stored, session);
|
|
1028
1237
|
}
|
|
1029
|
-
async setDeviceRecord(userId, deviceId, record) {
|
|
1238
|
+
async setDeviceRecord(userId, deviceId, record, options) {
|
|
1030
1239
|
if (record.session)
|
|
1031
1240
|
assertCurrentSessionRecord(record.session);
|
|
1032
1241
|
const now = Date.now();
|
|
@@ -1044,20 +1253,29 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1044
1253
|
const session = record.session
|
|
1045
1254
|
? await this.encrypt(serializeSessionRecord(record.session))
|
|
1046
1255
|
: null;
|
|
1047
|
-
const
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1256
|
+
const invalidation = options?.senderKeyHandoffInvalidation;
|
|
1257
|
+
const invalidatedHash = invalidation
|
|
1258
|
+
? (await this.senderKeyHandoffs.index()).recipient(invalidation)
|
|
1259
|
+
: undefined;
|
|
1260
|
+
const tx = this.db.transaction(['sesameUsers', 'sessions', 'senderKeyHandoff'], 'readwrite');
|
|
1261
|
+
await commitTransaction(tx, async (writes) => {
|
|
1262
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
1263
|
+
const doomedHandoffs = invalidatedHash === undefined
|
|
1264
|
+
? []
|
|
1265
|
+
: await handoffs.index('by-recipient').getAllKeys(invalidatedHash);
|
|
1266
|
+
writes.push(tx.objectStore('sesameUsers').put({ key: userId, data: user, updatedAt: now }));
|
|
1267
|
+
if (session) {
|
|
1268
|
+
writes.push(tx.objectStore('sessions').put({
|
|
1269
|
+
key: this.serializeAddress(ProtocolAddress.create(userId, deviceId)),
|
|
1270
|
+
userId,
|
|
1271
|
+
deviceId,
|
|
1272
|
+
data: session,
|
|
1273
|
+
updatedAt: now,
|
|
1274
|
+
}));
|
|
1275
|
+
}
|
|
1276
|
+
for (const handoffKey of doomedHandoffs)
|
|
1277
|
+
writes.push(handoffs.delete(handoffKey));
|
|
1278
|
+
});
|
|
1061
1279
|
}
|
|
1062
1280
|
async deleteDeviceRecord(userId, deviceId) {
|
|
1063
1281
|
const now = Date.now();
|
|
@@ -1069,14 +1287,20 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1069
1287
|
// A device can exist through its session alone, so the session goes even
|
|
1070
1288
|
// when no stored user record names the device.
|
|
1071
1289
|
const sessionKey = this.serializeAddress(ProtocolAddress.create(userId, deviceId));
|
|
1072
|
-
const
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
writes.push(
|
|
1079
|
-
|
|
1290
|
+
const recipientHash = (await this.senderKeyHandoffs.index()).recipient({ userId, deviceId });
|
|
1291
|
+
const tx = this.db.transaction(['sesameUsers', 'sessions', 'senderKeyHandoff'], 'readwrite');
|
|
1292
|
+
await commitTransaction(tx, async (writes) => {
|
|
1293
|
+
const users = tx.objectStore('sesameUsers');
|
|
1294
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
1295
|
+
const doomedHandoffs = await handoffs.index('by-recipient').getAllKeys(recipientHash);
|
|
1296
|
+
writes.push(tx.objectStore('sessions').delete(sessionKey));
|
|
1297
|
+
if (user)
|
|
1298
|
+
writes.push(users.put({ key: userId, data: user, updatedAt: now }));
|
|
1299
|
+
else if (userRecord)
|
|
1300
|
+
writes.push(users.delete(userId));
|
|
1301
|
+
for (const handoffKey of doomedHandoffs)
|
|
1302
|
+
writes.push(handoffs.delete(handoffKey));
|
|
1303
|
+
});
|
|
1080
1304
|
}
|
|
1081
1305
|
async getStoredUserRecord(userId) {
|
|
1082
1306
|
this.ensureInitialized();
|
|
@@ -1176,9 +1400,21 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1176
1400
|
const record = await this.getSenderKeyRecord(groupId, userId, deviceId);
|
|
1177
1401
|
return record?.[0] ?? null;
|
|
1178
1402
|
}
|
|
1179
|
-
async deleteSenderKey(groupId, userId, deviceId) {
|
|
1403
|
+
async deleteSenderKey(groupId, userId, deviceId, options) {
|
|
1180
1404
|
this.ensureInitialized();
|
|
1181
|
-
|
|
1405
|
+
if (!options?.deleteSenderKeyHandoffs) {
|
|
1406
|
+
await this.db.delete('senderKeyRecords', [groupId, userId, deviceId]);
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
const groupHash = (await this.senderKeyHandoffs.index()).group(groupId);
|
|
1410
|
+
const tx = this.db.transaction(['senderKeyRecords', 'senderKeyHandoff'], 'readwrite');
|
|
1411
|
+
await commitTransaction(tx, async (writes) => {
|
|
1412
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
1413
|
+
const doomedHandoffs = await handoffs.index('by-group').getAllKeys(groupHash);
|
|
1414
|
+
writes.push(tx.objectStore('senderKeyRecords').delete([groupId, userId, deviceId]));
|
|
1415
|
+
for (const handoffKey of doomedHandoffs)
|
|
1416
|
+
writes.push(handoffs.delete(handoffKey));
|
|
1417
|
+
});
|
|
1182
1418
|
}
|
|
1183
1419
|
async resolveGroupForSenderKeyId(senderKeyId, userId, deviceId) {
|
|
1184
1420
|
this.ensureInitialized();
|
|
@@ -1222,30 +1458,39 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1222
1458
|
async deleteAllSenderKeysForGroup(groupId) {
|
|
1223
1459
|
this.ensureInitialized();
|
|
1224
1460
|
// Read the doomed keys before mutating, then enter every delete in one
|
|
1225
|
-
// synchronous batch, so the sender keys
|
|
1226
|
-
|
|
1227
|
-
const
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1461
|
+
// synchronous batch, so the sender keys, the skipped keys, and the
|
|
1462
|
+
// handoff rows go together.
|
|
1463
|
+
const groupHash = (await this.senderKeyHandoffs.index()).group(groupId);
|
|
1464
|
+
const tx = this.db.transaction(['senderKeyRecords', 'skippedSenderKeys', 'senderKeyHandoff'], 'readwrite');
|
|
1465
|
+
let deleted = 0;
|
|
1466
|
+
await commitTransaction(tx, async (writes) => {
|
|
1467
|
+
const senderKeyRecords = tx.objectStore('senderKeyRecords');
|
|
1468
|
+
const skippedSenderKeys = tx.objectStore('skippedSenderKeys');
|
|
1469
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
1470
|
+
const [recordKeys, skippedKeys, handoffKeys] = await Promise.all([
|
|
1471
|
+
senderKeyRecords.index('by-group').getAllKeys(groupId),
|
|
1472
|
+
skippedSenderKeys.index('by-group').getAllKeys(groupId),
|
|
1473
|
+
handoffs.index('by-group').getAllKeys(groupHash),
|
|
1474
|
+
]);
|
|
1475
|
+
deleted = recordKeys.length;
|
|
1476
|
+
// Push each request as it is created. A later synchronous throw must
|
|
1477
|
+
// not leave an earlier request outside the settled set.
|
|
1478
|
+
for (const key of recordKeys)
|
|
1479
|
+
writes.push(senderKeyRecords.delete(key));
|
|
1480
|
+
for (const key of skippedKeys)
|
|
1481
|
+
writes.push(skippedSenderKeys.delete(key));
|
|
1482
|
+
for (const key of handoffKeys)
|
|
1483
|
+
writes.push(handoffs.delete(key));
|
|
1484
|
+
});
|
|
1485
|
+
return deleted;
|
|
1486
|
+
}
|
|
1487
|
+
async storeSenderKeyRecord(groupId, userId, deviceId, states, receive, options) {
|
|
1241
1488
|
this.ensureInitialized();
|
|
1242
1489
|
if (states.length === 0) {
|
|
1243
1490
|
return;
|
|
1244
1491
|
}
|
|
1245
1492
|
const encrypted = await this.encrypt(JSON.stringify(states));
|
|
1246
|
-
const
|
|
1247
|
-
? await this.encrypt(JSON.stringify(receive.content))
|
|
1248
|
-
: undefined;
|
|
1493
|
+
const work = receive?.work ? await this.receiveWork.seal(receive.work) : undefined;
|
|
1249
1494
|
// Finish encryption before opening the IDB transaction, which must not await crypto.
|
|
1250
1495
|
const skippedKeys = await Promise.all((receive?.skippedKeys?.keys ?? []).map(async (skipped) => ({
|
|
1251
1496
|
key: this.getSkippedSenderKeyStorageKey(groupId, userId, deviceId, skipped.senderKeyId, skipped.chainIndex),
|
|
@@ -1255,7 +1500,10 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1255
1500
|
data: await this.encrypt(JSON.stringify(skipped.messageKey)),
|
|
1256
1501
|
createdAt: Date.now(),
|
|
1257
1502
|
})));
|
|
1258
|
-
const
|
|
1503
|
+
const deletedGroupHash = options?.deleteSenderKeyHandoffs
|
|
1504
|
+
? (await this.senderKeyHandoffs.index()).group(groupId)
|
|
1505
|
+
: undefined;
|
|
1506
|
+
const tx = this.db.transaction(['senderKeyRecords', 'skippedSenderKeys', 'receiveWork', 'senderKeyHandoff'], 'readwrite');
|
|
1259
1507
|
// Observe aborts immediately, including while the skipped-key read is pending.
|
|
1260
1508
|
const completed = tx.done;
|
|
1261
1509
|
void completed.catch(() => undefined);
|
|
@@ -1271,6 +1519,10 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1271
1519
|
.index('by-sender')
|
|
1272
1520
|
.getAll(this.getSkippedSenderKeyPrefix(groupId, userId, deviceId))).map(({ key, chainIndex }) => ({ key, chainIndex }))
|
|
1273
1521
|
: [];
|
|
1522
|
+
const handoffs = tx.objectStore('senderKeyHandoff');
|
|
1523
|
+
const doomedHandoffs = deletedGroupHash === undefined
|
|
1524
|
+
? []
|
|
1525
|
+
: await handoffs.index('by-group').getAllKeys(deletedGroupHash);
|
|
1274
1526
|
const sameKey = (a, b) => a.every((part, index) => part === b[index]);
|
|
1275
1527
|
const skippedWrites = [];
|
|
1276
1528
|
for (const skipped of skippedKeys) {
|
|
@@ -1303,9 +1555,10 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1303
1555
|
for (const write of skippedWrites) {
|
|
1304
1556
|
writes.push('put' in write ? skippedStore.put(write.put) : skippedStore.delete(write.delete));
|
|
1305
1557
|
}
|
|
1306
|
-
if (
|
|
1307
|
-
writes.push(tx.objectStore('
|
|
1308
|
-
|
|
1558
|
+
if (work)
|
|
1559
|
+
writes.push(tx.objectStore('receiveWork').put(work));
|
|
1560
|
+
for (const handoffKey of doomedHandoffs)
|
|
1561
|
+
writes.push(handoffs.delete(handoffKey));
|
|
1309
1562
|
await Promise.all([...writes, completed]);
|
|
1310
1563
|
}
|
|
1311
1564
|
catch (error) {
|
|
@@ -1319,34 +1572,124 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1319
1572
|
throw error;
|
|
1320
1573
|
}
|
|
1321
1574
|
}
|
|
1322
|
-
|
|
1575
|
+
// ============================================================================
|
|
1576
|
+
// Sender-Key Handoff Ledger
|
|
1577
|
+
// ============================================================================
|
|
1578
|
+
async recordSenderKeyHandoff(record) {
|
|
1323
1579
|
this.ensureInitialized();
|
|
1324
|
-
|
|
1325
|
-
if (value === undefined)
|
|
1326
|
-
return null;
|
|
1327
|
-
if (!(value instanceof Uint8Array))
|
|
1328
|
-
throw new Error('Invalid encrypted received content');
|
|
1329
|
-
return parseReceivedContent(await this.decrypt(value), id);
|
|
1580
|
+
await this.senderKeyHandoffs.record(record);
|
|
1330
1581
|
}
|
|
1331
|
-
async
|
|
1582
|
+
async listSenderKeyHandoffs(groupId, generation) {
|
|
1332
1583
|
this.ensureInitialized();
|
|
1333
|
-
|
|
1584
|
+
return this.senderKeyHandoffs.list(groupId, generation);
|
|
1334
1585
|
}
|
|
1335
|
-
async
|
|
1586
|
+
async invalidateSenderKeyHandoff(groupId, device) {
|
|
1336
1587
|
this.ensureInitialized();
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1588
|
+
return this.senderKeyHandoffs.deleteDeviceInGroup(groupId, device);
|
|
1589
|
+
}
|
|
1590
|
+
async invalidateAccountSenderKeyHandoffs(userId) {
|
|
1591
|
+
this.ensureInitialized();
|
|
1592
|
+
return this.senderKeyHandoffs.deleteAccount(userId);
|
|
1593
|
+
}
|
|
1594
|
+
async listSenderKeyHandoffGroupIds() {
|
|
1595
|
+
this.ensureInitialized();
|
|
1596
|
+
return this.senderKeyHandoffs.groupIds();
|
|
1597
|
+
}
|
|
1598
|
+
async retainSenderKeyHandoffs(groupId, senderKeyId) {
|
|
1599
|
+
this.ensureInitialized();
|
|
1600
|
+
return this.senderKeyHandoffs.retain(groupId, senderKeyId);
|
|
1601
|
+
}
|
|
1602
|
+
// ============================================================================
|
|
1603
|
+
// Receive records
|
|
1604
|
+
// ============================================================================
|
|
1605
|
+
async getReceiveWork(workId) {
|
|
1606
|
+
this.ensureInitialized();
|
|
1607
|
+
return await this.receiveWork.get(workId);
|
|
1608
|
+
}
|
|
1609
|
+
async putReceiveWork(record, expectedRevision) {
|
|
1610
|
+
this.ensureInitialized();
|
|
1611
|
+
return await this.receiveWork.put(record, expectedRevision);
|
|
1612
|
+
}
|
|
1613
|
+
async listReceiveWork(query) {
|
|
1614
|
+
this.ensureInitialized();
|
|
1615
|
+
return await this.receiveWork.list(query);
|
|
1616
|
+
}
|
|
1617
|
+
async receiveWorkUsage(query) {
|
|
1618
|
+
this.ensureInitialized();
|
|
1619
|
+
return await this.receiveWork.usage(query);
|
|
1620
|
+
}
|
|
1621
|
+
async completeReceiveWork(workId, expectedRevision, metadata = []) {
|
|
1622
|
+
this.ensureInitialized();
|
|
1623
|
+
// Seal every metadata value first: the transaction must not await the cipher.
|
|
1624
|
+
const metadataWrites = await Promise.all(metadata.map(async ({ key, value }) => ({
|
|
1625
|
+
storageKey: metadataStorageKey(key),
|
|
1626
|
+
sealed: value === null ? null : await this.sealMetadataValue(value),
|
|
1627
|
+
})));
|
|
1628
|
+
const tx = this.db.transaction(['receiveWork', 'metadata'], 'readwrite');
|
|
1629
|
+
const completed = tx.done;
|
|
1630
|
+
void completed.catch(() => undefined);
|
|
1631
|
+
const writes = [];
|
|
1632
|
+
try {
|
|
1633
|
+
const records = tx.objectStore('receiveWork');
|
|
1634
|
+
const current = await records.get(workId);
|
|
1635
|
+
if (current?.revision !== expectedRevision) {
|
|
1636
|
+
await completed;
|
|
1637
|
+
return false;
|
|
1638
|
+
}
|
|
1639
|
+
// Enter the delete and every metadata write in one synchronous batch.
|
|
1640
|
+
const metadataStore = tx.objectStore('metadata');
|
|
1641
|
+
writes.push(records.delete(workId));
|
|
1642
|
+
for (const { storageKey, sealed } of metadataWrites) {
|
|
1643
|
+
writes.push(sealed === null ? metadataStore.delete(storageKey) : metadataStore.put(sealed, storageKey));
|
|
1644
|
+
}
|
|
1645
|
+
await Promise.all([...writes, completed]);
|
|
1646
|
+
return true;
|
|
1344
1647
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1648
|
+
catch (error) {
|
|
1649
|
+
try {
|
|
1650
|
+
tx.abort();
|
|
1651
|
+
}
|
|
1652
|
+
catch {
|
|
1653
|
+
/* The failed transaction can already be inactive. */
|
|
1654
|
+
}
|
|
1655
|
+
await Promise.allSettled([...writes, completed]);
|
|
1656
|
+
throw error;
|
|
1348
1657
|
}
|
|
1349
|
-
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
* Convert the legacy received content rows to receive records. A full
|
|
1661
|
+
* origin stops the conversion without its marker. The store still opens,
|
|
1662
|
+
* and the next open continues the conversion.
|
|
1663
|
+
*/
|
|
1664
|
+
async convertLegacyReceivedRows() {
|
|
1665
|
+
try {
|
|
1666
|
+
await convertLegacyReceivedContent(this, this.legacyReceivedContent());
|
|
1667
|
+
}
|
|
1668
|
+
catch (error) {
|
|
1669
|
+
if (!isQuotaExceededError(error) && !(error instanceof StorageQuotaExceededError)) {
|
|
1670
|
+
throw error;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
/** The legacy rows: raw metadata keys `received-content:<id>`, each value from the record cipher. */
|
|
1675
|
+
legacyReceivedContent() {
|
|
1676
|
+
const prefix = receivedContentKey('');
|
|
1677
|
+
return {
|
|
1678
|
+
listIds: async () => (await this.db.getAllKeys('metadata'))
|
|
1679
|
+
.filter((key) => key.startsWith(prefix))
|
|
1680
|
+
.map((key) => key.slice(prefix.length)),
|
|
1681
|
+
read: async (id) => {
|
|
1682
|
+
const value = await this.db.get('metadata', receivedContentKey(id));
|
|
1683
|
+
if (value === undefined)
|
|
1684
|
+
return null;
|
|
1685
|
+
if (!(value instanceof Uint8Array))
|
|
1686
|
+
throw new Error('Invalid encrypted received content');
|
|
1687
|
+
return await this.decrypt(value);
|
|
1688
|
+
},
|
|
1689
|
+
delete: async (id) => {
|
|
1690
|
+
await this.db.delete('metadata', receivedContentKey(id));
|
|
1691
|
+
},
|
|
1692
|
+
};
|
|
1350
1693
|
}
|
|
1351
1694
|
async getSenderKeyRecord(groupId, userId, deviceId) {
|
|
1352
1695
|
this.ensureInitialized();
|
|
@@ -1415,12 +1758,14 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1415
1758
|
// ============================================================================
|
|
1416
1759
|
async storeMessageRecord(record) {
|
|
1417
1760
|
this.ensureInitialized();
|
|
1418
|
-
const
|
|
1761
|
+
const key = this.getMessageRecordStorageKey(record.sessionId, record.timestamp);
|
|
1762
|
+
const createdAt = (await this.db.get('messageRecords', key))?.createdAt ?? Date.now();
|
|
1763
|
+
const encrypted = await this.encrypt(JSON.stringify({ ...record, createdAt }));
|
|
1419
1764
|
await this.db.put('messageRecords', {
|
|
1420
|
-
key
|
|
1765
|
+
key,
|
|
1421
1766
|
sessionId: record.sessionId,
|
|
1422
1767
|
timestamp: record.timestamp,
|
|
1423
|
-
createdAt
|
|
1768
|
+
createdAt,
|
|
1424
1769
|
data: encrypted,
|
|
1425
1770
|
});
|
|
1426
1771
|
}
|
|
@@ -1468,6 +1813,111 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1468
1813
|
await Promise.all(matches.map((key) => this.db.delete('messageRecords', key)));
|
|
1469
1814
|
return matches.length;
|
|
1470
1815
|
}
|
|
1816
|
+
/**
|
|
1817
|
+
* The records decrypt and encrypt outside a transaction, because IndexedDB
|
|
1818
|
+
* commits an idle transaction. The write transaction then changes a record
|
|
1819
|
+
* only when its stored bytes still equal the bytes that `rewrite` read.
|
|
1820
|
+
*/
|
|
1821
|
+
async rewriteMessageRecords(rewrite) {
|
|
1822
|
+
this.ensureInitialized();
|
|
1823
|
+
const selected = [];
|
|
1824
|
+
for (const stored of await this.db.getAll('messageRecords')) {
|
|
1825
|
+
const record = JSON.parse(await this.decrypt(stored.data));
|
|
1826
|
+
const plaintext = rewrite(record);
|
|
1827
|
+
if (plaintext === record.plaintext)
|
|
1828
|
+
continue;
|
|
1829
|
+
const replacement = plaintext === null ? null : await this.encrypt(JSON.stringify({ ...record, plaintext }));
|
|
1830
|
+
selected.push({ key: stored.key, data: stored.data, replacement });
|
|
1831
|
+
}
|
|
1832
|
+
if (selected.length === 0)
|
|
1833
|
+
return 0;
|
|
1834
|
+
const tx = this.db.transaction('messageRecords', 'readwrite');
|
|
1835
|
+
const store = tx.objectStore('messageRecords');
|
|
1836
|
+
let changed = 0;
|
|
1837
|
+
for (const { key, data, replacement } of selected) {
|
|
1838
|
+
const current = await store.get(key);
|
|
1839
|
+
if (!current || !encryptedBytesEqual(current.data, data))
|
|
1840
|
+
continue;
|
|
1841
|
+
if (replacement === null) {
|
|
1842
|
+
await store.delete(key);
|
|
1843
|
+
}
|
|
1844
|
+
else {
|
|
1845
|
+
await store.put({ ...current, data: replacement });
|
|
1846
|
+
}
|
|
1847
|
+
changed++;
|
|
1848
|
+
}
|
|
1849
|
+
await tx.done;
|
|
1850
|
+
return changed;
|
|
1851
|
+
}
|
|
1852
|
+
// ============================================================================
|
|
1853
|
+
// Send Log (resendable group content)
|
|
1854
|
+
// The send log concept lives in ./send-log.ts. This store implements the
|
|
1855
|
+
// whole local store interface, so it keeps these delegates.
|
|
1856
|
+
// ============================================================================
|
|
1857
|
+
async storeSendLogEntry(payload, recipients) {
|
|
1858
|
+
this.ensureInitialized();
|
|
1859
|
+
return this.sendLog.storeSendLogEntry(payload, recipients);
|
|
1860
|
+
}
|
|
1861
|
+
async appendSendLogRecipients(clientMessageId, recipients) {
|
|
1862
|
+
this.ensureInitialized();
|
|
1863
|
+
return this.sendLog.appendSendLogRecipients(clientMessageId, recipients);
|
|
1864
|
+
}
|
|
1865
|
+
async markSendLogComplete(clientMessageId) {
|
|
1866
|
+
this.ensureInitialized();
|
|
1867
|
+
return this.sendLog.markSendLogComplete(clientMessageId);
|
|
1868
|
+
}
|
|
1869
|
+
async getSendLogEntry(clientMessageId, recipient) {
|
|
1870
|
+
this.ensureInitialized();
|
|
1871
|
+
return this.sendLog.getSendLogEntry(clientMessageId, recipient);
|
|
1872
|
+
}
|
|
1873
|
+
async findSendLogEntries(recipient, clientTimestamp) {
|
|
1874
|
+
this.ensureInitialized();
|
|
1875
|
+
return this.sendLog.findSendLogEntries(recipient, clientTimestamp);
|
|
1876
|
+
}
|
|
1877
|
+
async getSendLogRecipients(clientMessageId) {
|
|
1878
|
+
this.ensureInitialized();
|
|
1879
|
+
return this.sendLog.getSendLogRecipients(clientMessageId);
|
|
1880
|
+
}
|
|
1881
|
+
async deleteSendLogRecipient(clientMessageId, recipient) {
|
|
1882
|
+
this.ensureInitialized();
|
|
1883
|
+
return this.sendLog.deleteSendLogRecipient(clientMessageId, recipient);
|
|
1884
|
+
}
|
|
1885
|
+
async deleteSendLogRecipientsByTimestamp(recipient, clientTimestamps) {
|
|
1886
|
+
this.ensureInitialized();
|
|
1887
|
+
return this.sendLog.deleteSendLogRecipientsByTimestamp(recipient, clientTimestamps);
|
|
1888
|
+
}
|
|
1889
|
+
async incrementSendLogResendCount(clientMessageId, recipient) {
|
|
1890
|
+
this.ensureInitialized();
|
|
1891
|
+
return this.sendLog.incrementSendLogResendCount(clientMessageId, recipient);
|
|
1892
|
+
}
|
|
1893
|
+
async deleteSendLogEntry(clientMessageId) {
|
|
1894
|
+
this.ensureInitialized();
|
|
1895
|
+
return this.sendLog.deleteSendLogEntry(clientMessageId);
|
|
1896
|
+
}
|
|
1897
|
+
async deleteExpiredSendLog(maxAgeMs) {
|
|
1898
|
+
this.ensureInitialized();
|
|
1899
|
+
return this.sendLog.deleteExpiredSendLog(maxAgeMs);
|
|
1900
|
+
}
|
|
1901
|
+
async clearSendLog() {
|
|
1902
|
+
this.ensureInitialized();
|
|
1903
|
+
return this.sendLog.clearSendLog();
|
|
1904
|
+
}
|
|
1905
|
+
async storeResendJob(job) {
|
|
1906
|
+
this.ensureInitialized();
|
|
1907
|
+
return this.sendLog.storeResendJob(job);
|
|
1908
|
+
}
|
|
1909
|
+
async getResendJob(jobId) {
|
|
1910
|
+
this.ensureInitialized();
|
|
1911
|
+
return this.sendLog.getResendJob(jobId);
|
|
1912
|
+
}
|
|
1913
|
+
async getPendingResendJobs() {
|
|
1914
|
+
this.ensureInitialized();
|
|
1915
|
+
return this.sendLog.getPendingResendJobs();
|
|
1916
|
+
}
|
|
1917
|
+
async completeResendJob(jobId, state) {
|
|
1918
|
+
this.ensureInitialized();
|
|
1919
|
+
return this.sendLog.completeResendJob(jobId, state);
|
|
1920
|
+
}
|
|
1471
1921
|
// ============================================================================
|
|
1472
1922
|
// Key Recovery Methods (Bug #7 - Identifier Collision Recovery)
|
|
1473
1923
|
// ============================================================================
|
|
@@ -1571,12 +2021,14 @@ export class IndexedDbSignalProtocolStore {
|
|
|
1571
2021
|
}
|
|
1572
2022
|
/**
|
|
1573
2023
|
* A device record is stale when it has no current session and no archived
|
|
1574
|
-
* session, and it has not been updated within `maxLatency
|
|
2024
|
+
* session, and it has not been updated within `maxLatency`, or when its
|
|
2025
|
+
* removal is older than `maxLatency`.
|
|
1575
2026
|
*/
|
|
1576
2027
|
function isStaleDeviceRecord(record, now, maxLatency) {
|
|
1577
2028
|
const hasNoSessions = !record.session ||
|
|
1578
2029
|
(!record.session.currentSession && Object.keys(record.session.archivedSessions).length === 0);
|
|
1579
|
-
return hasNoSessions && now - record.updatedAt > maxLatency
|
|
2030
|
+
return ((hasNoSessions && now - record.updatedAt > maxLatency) ||
|
|
2031
|
+
isExpiredRemovedDevice(record, now, maxLatency));
|
|
1580
2032
|
}
|
|
1581
2033
|
/**
|
|
1582
2034
|
* Delete the sessions of `record` that are older than `maxRecv`, and return
|