@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createKeyedLocks, withKeyedLock } from '../../utils/keyed-lock.js';
|
|
2
2
|
const OUTBOX_PREFIX = 'reliability:exact-ciphertext-outbox:v2';
|
|
3
3
|
const INCOMING_PREFIX = 'reliability:processed-envelopes:v2';
|
|
4
|
-
const RETRY_REQUESTED_PREFIX = 'reliability:retry-requested:
|
|
4
|
+
const RETRY_REQUESTED_PREFIX = 'reliability:retry-requested:v2';
|
|
5
5
|
const RETRY_RESEND_PREFIX = 'reliability:retry-resend:v1';
|
|
6
6
|
const RETRY_FAMILY_PREFIX = 'reliability:retry-family:v1';
|
|
7
7
|
const SENT_TIMESTAMP_PREFIX = 'reliability:sent-timestamps:v1';
|
|
@@ -18,6 +18,13 @@ export const RELIABILITY_RECORD_TTL_MS = 30 * DAY_MS;
|
|
|
18
18
|
* time after the failure.
|
|
19
19
|
*/
|
|
20
20
|
export const RETRY_REQUESTER_RECORD_TTL_MS = 2 * RELIABILITY_RECORD_TTL_MS;
|
|
21
|
+
/**
|
|
22
|
+
* The time from the first failure of a retry request to its end: 14 days,
|
|
23
|
+
* the default retention of resendable content of a sender,
|
|
24
|
+
* `RESENDABLE_CONTENT_RETENTION_MS`. A request whose content did not come
|
|
25
|
+
* at this time ends as `expired-content`.
|
|
26
|
+
*/
|
|
27
|
+
export const RETRY_REQUEST_DEADLINE_MS = 14 * DAY_MS;
|
|
21
28
|
const mutationTails = new WeakMap();
|
|
22
29
|
const outgoingIntentLocks = createKeyedLocks();
|
|
23
30
|
const incomingEnvelopeLocks = createKeyedLocks();
|
|
@@ -139,33 +146,193 @@ function sameIntent(a, b) {
|
|
|
139
146
|
a.groupSenderKeyDistributionId === b.groupSenderKeyDistributionId &&
|
|
140
147
|
JSON.stringify(a.groupSharedMessage) === JSON.stringify(b.groupSharedMessage));
|
|
141
148
|
}
|
|
142
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Apply a change of the device set to a group intent in one write. Each
|
|
151
|
+
* removed device first loses all of its messages. Then each new message is
|
|
152
|
+
* appended to its list. A new message for a device that still has a message
|
|
153
|
+
* in the same list must be equal to it, and is not appended again. The same
|
|
154
|
+
* write replaces or removes the shared body when the change names one.
|
|
155
|
+
*/
|
|
156
|
+
export async function reconcileOutgoingGroupDeviceSet(store, clientMessageId, change) {
|
|
143
157
|
return serializeMutation(store, async () => {
|
|
144
158
|
const key = recordKey('outbox', clientMessageId);
|
|
145
159
|
const existing = parseJson(await store.getMetadata(key), null);
|
|
146
160
|
if (!existing || existing.kind !== 'group' || existing.result) {
|
|
147
|
-
throw new Error('Cannot
|
|
161
|
+
throw new Error('Cannot change the devices of a missing or completed group outbox intent');
|
|
148
162
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
163
|
+
const removed = new Set(change.removed.map(outgoingDeviceKey));
|
|
164
|
+
const kept = (messages) => messages.filter((message) => !removed.has(outgoingMessageDeviceKey(message)));
|
|
165
|
+
const preMessages = appendOutgoingDeviceMessages(kept(existing.preMessages ?? []), change.preMessages);
|
|
166
|
+
existing.deviceMessages = appendOutgoingDeviceMessages(kept(existing.deviceMessages), change.deviceMessages);
|
|
167
|
+
existing.syncMessages = appendOutgoingDeviceMessages(kept(existing.syncMessages), change.syncMessages);
|
|
168
|
+
if (preMessages.length > 0)
|
|
169
|
+
existing.preMessages = preMessages;
|
|
170
|
+
else
|
|
171
|
+
delete existing.preMessages;
|
|
172
|
+
applyGroupSharedMessage(existing, change.groupSharedMessage);
|
|
173
|
+
await store.setMetadata(key, JSON.stringify(existing));
|
|
174
|
+
return cloneReliabilityValue(existing);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Replace the shared body of a group intent, or remove it with null. An
|
|
179
|
+
* absent body leaves the stored body.
|
|
180
|
+
*/
|
|
181
|
+
function applyGroupSharedMessage(intent, groupSharedMessage) {
|
|
182
|
+
if (groupSharedMessage === null)
|
|
183
|
+
delete intent.groupSharedMessage;
|
|
184
|
+
else if (groupSharedMessage) {
|
|
185
|
+
intent.groupSharedMessage = cloneReliabilityValue(groupSharedMessage);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Commit the repair of a declared send phase and its restart count in one
|
|
190
|
+
* write. Each removed device first loses all of its messages. Then each new
|
|
191
|
+
* message is appended to its list. A completed intent takes a repair only of
|
|
192
|
+
* its pending sync phase, and a terminal intent takes none.
|
|
193
|
+
*/
|
|
194
|
+
export async function repairOutgoingDeviceSet(store, clientMessageId, repair) {
|
|
195
|
+
return serializeMutation(store, async () => {
|
|
196
|
+
const key = recordKey('outbox', clientMessageId);
|
|
197
|
+
const existing = parseJson(await store.getMetadata(key), null);
|
|
198
|
+
if (!existing || (existing.result && !(repair.phase === 'sync' && existing.syncPending))) {
|
|
199
|
+
throw new Error('Cannot repair the device set of a missing or completed outbox intent');
|
|
200
|
+
}
|
|
201
|
+
if (existing.deviceSetUnresolved) {
|
|
202
|
+
throw new Error('Cannot repair the device set of a terminal outbox intent');
|
|
203
|
+
}
|
|
204
|
+
const restarts = existing.deviceSetRestarts?.[repair.phase] ?? 0;
|
|
205
|
+
if (repair.restarts !== restarts + 1) {
|
|
206
|
+
throw new Error('Cannot repair the device set of an outbox intent from a different restart');
|
|
207
|
+
}
|
|
208
|
+
const removed = new Set(repair.removed.map(outgoingDeviceKey));
|
|
209
|
+
const kept = (messages) => messages.filter((message) => !removed.has(outgoingMessageDeviceKey(message)));
|
|
210
|
+
const preMessages = appendOutgoingDeviceMessages(kept(existing.preMessages ?? []), repair.preMessages ?? []);
|
|
211
|
+
existing.deviceMessages = appendOutgoingDeviceMessages(kept(existing.deviceMessages), repair.deviceMessages ?? []);
|
|
212
|
+
existing.syncMessages = appendOutgoingDeviceMessages(kept(existing.syncMessages), repair.syncMessages ?? [], 'Cannot replace a persisted sync transmission');
|
|
213
|
+
if (preMessages.length > 0)
|
|
214
|
+
existing.preMessages = preMessages;
|
|
215
|
+
else
|
|
216
|
+
delete existing.preMessages;
|
|
217
|
+
applyGroupSharedMessage(existing, repair.groupSharedMessage);
|
|
218
|
+
existing.deviceSetRestarts = { ...existing.deviceSetRestarts, [repair.phase]: repair.restarts };
|
|
219
|
+
const bundleMissing = (repair.bundleMissing ?? []).map((device) => ({
|
|
220
|
+
userId: device.userId,
|
|
221
|
+
deviceId: device.deviceId,
|
|
222
|
+
}));
|
|
223
|
+
const otherPhase = repair.phase === 'recipient' ? 'sync' : 'recipient';
|
|
224
|
+
const otherMissing = existing.deviceSetBundleMissing?.[otherPhase];
|
|
225
|
+
if (bundleMissing.length === 0 && !otherMissing)
|
|
226
|
+
delete existing.deviceSetBundleMissing;
|
|
227
|
+
else {
|
|
228
|
+
existing.deviceSetBundleMissing = {
|
|
229
|
+
...(otherMissing && { [otherPhase]: otherMissing }),
|
|
230
|
+
...(bundleMissing.length > 0 && { [repair.phase]: bundleMissing }),
|
|
231
|
+
};
|
|
159
232
|
}
|
|
160
233
|
await store.setMetadata(key, JSON.stringify(existing));
|
|
161
234
|
return cloneReliabilityValue(existing);
|
|
162
235
|
});
|
|
163
236
|
}
|
|
164
237
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
238
|
+
* Record that a phase of a declared send ended without reconciliation. The
|
|
239
|
+
* restart counts stay. The SDK does not post the phase again until the
|
|
240
|
+
* application calls `send()` with the same `clientMessageId`.
|
|
167
241
|
*/
|
|
168
|
-
export async function
|
|
242
|
+
export async function markOutgoingDeviceSetUnresolved(store, clientMessageId, unresolved) {
|
|
243
|
+
return serializeMutation(store, async () => {
|
|
244
|
+
const key = recordKey('outbox', clientMessageId);
|
|
245
|
+
const existing = parseJson(await store.getMetadata(key), null);
|
|
246
|
+
if (!existing || (existing.result && !(unresolved.phase === 'sync' && existing.syncPending))) {
|
|
247
|
+
throw new Error('Cannot end the device set of a missing or completed outbox intent');
|
|
248
|
+
}
|
|
249
|
+
existing.deviceSetUnresolved = cloneReliabilityValue(unresolved);
|
|
250
|
+
await store.setMetadata(key, JSON.stringify(existing));
|
|
251
|
+
return cloneReliabilityValue(existing);
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Start a new run of a terminal declared send at 0 restarts: remove the
|
|
256
|
+
* terminal record and the restart counts in one write. An intent that is not
|
|
257
|
+
* terminal keeps its counts.
|
|
258
|
+
*/
|
|
259
|
+
export async function restartOutgoingDeviceSet(store, clientMessageId) {
|
|
260
|
+
return serializeMutation(store, async () => {
|
|
261
|
+
const key = recordKey('outbox', clientMessageId);
|
|
262
|
+
const existing = parseJson(await store.getMetadata(key), null);
|
|
263
|
+
if (!existing)
|
|
264
|
+
throw new Error('Cannot restart a missing outbox intent');
|
|
265
|
+
if (existing.deviceSetUnresolved) {
|
|
266
|
+
delete existing.deviceSetUnresolved;
|
|
267
|
+
delete existing.deviceSetRestarts;
|
|
268
|
+
await store.setMetadata(key, JSON.stringify(existing));
|
|
269
|
+
}
|
|
270
|
+
return cloneReliabilityValue(existing);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Complete the pending sync phase of a completed intent: remove its sync
|
|
275
|
+
* messages, its restart counts, and its terminal record.
|
|
276
|
+
*/
|
|
277
|
+
export async function completeOutgoingSyncPhase(store, clientMessageId) {
|
|
278
|
+
await serializeMutation(store, async () => {
|
|
279
|
+
const key = recordKey('outbox', clientMessageId);
|
|
280
|
+
const existing = parseJson(await store.getMetadata(key), null);
|
|
281
|
+
if (!existing?.result)
|
|
282
|
+
throw new Error('Cannot complete the sync phase of an open intent');
|
|
283
|
+
delete existing.syncPending;
|
|
284
|
+
delete existing.deviceSetRestarts;
|
|
285
|
+
delete existing.deviceSetUnresolved;
|
|
286
|
+
delete existing.deviceSetBundleMissing;
|
|
287
|
+
existing.syncMessages = [];
|
|
288
|
+
await store.setMetadata(key, JSON.stringify(existing));
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The result of a completed intent as a send returns it. A pending sync
|
|
293
|
+
* phase gives `syncPending`.
|
|
294
|
+
*/
|
|
295
|
+
export function outgoingMessageIntentResult(intent) {
|
|
296
|
+
if (!intent.result)
|
|
297
|
+
return undefined;
|
|
298
|
+
return {
|
|
299
|
+
...cloneReliabilityValue(intent.result),
|
|
300
|
+
...(intent.syncPending && { syncPending: true }),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function outgoingDeviceKey({ userId, deviceId }) {
|
|
304
|
+
return `${userId}\u0000${String(deviceId)}`;
|
|
305
|
+
}
|
|
306
|
+
function outgoingMessageDeviceKey(message) {
|
|
307
|
+
return outgoingDeviceKey({
|
|
308
|
+
userId: message.recipientUserId,
|
|
309
|
+
deviceId: message.recipientDeviceId,
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* The messages with each new message appended once. A stored message of the
|
|
314
|
+
* same device must be equal to the new message.
|
|
315
|
+
*/
|
|
316
|
+
function appendOutgoingDeviceMessages(messages, additions, refusal = 'Cannot replace a persisted group transmission') {
|
|
317
|
+
for (const message of additions) {
|
|
318
|
+
const prior = messages.find((candidate) => outgoingMessageDeviceKey(candidate) === outgoingMessageDeviceKey(message));
|
|
319
|
+
if (prior) {
|
|
320
|
+
if (JSON.stringify(prior) !== JSON.stringify(message)) {
|
|
321
|
+
throw new Error(refusal);
|
|
322
|
+
}
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
messages.push(cloneReliabilityValue(message));
|
|
326
|
+
}
|
|
327
|
+
return messages;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Remove the pre-messages that the relay accepted or that the send dropped
|
|
331
|
+
* from a group intent, so a replay posts only the pre-messages that the relay
|
|
332
|
+
* did not accept. Each device in `removedDevices` loses all of its messages
|
|
333
|
+
* in the same write.
|
|
334
|
+
*/
|
|
335
|
+
export async function confirmOutgoingPreMessages(store, clientMessageId, acceptedClientMessageIds, removedDevices = []) {
|
|
169
336
|
return serializeMutation(store, async () => {
|
|
170
337
|
const key = recordKey('outbox', clientMessageId);
|
|
171
338
|
const existing = parseJson(await store.getMetadata(key), null);
|
|
@@ -173,7 +340,11 @@ export async function confirmOutgoingPreMessages(store, clientMessageId, accepte
|
|
|
173
340
|
throw new Error('Cannot confirm pre-messages of a missing or completed group outbox intent');
|
|
174
341
|
}
|
|
175
342
|
const accepted = new Set(acceptedClientMessageIds);
|
|
176
|
-
const
|
|
343
|
+
const removed = new Set(removedDevices.map(outgoingDeviceKey));
|
|
344
|
+
const kept = (messages) => messages.filter((message) => !removed.has(outgoingMessageDeviceKey(message)));
|
|
345
|
+
const remaining = kept(existing.preMessages ?? []).filter((message) => message.clientMessageId === undefined || !accepted.has(message.clientMessageId));
|
|
346
|
+
existing.deviceMessages = kept(existing.deviceMessages);
|
|
347
|
+
existing.syncMessages = kept(existing.syncMessages);
|
|
177
348
|
if (remaining.length > 0)
|
|
178
349
|
existing.preMessages = remaining;
|
|
179
350
|
else
|
|
@@ -182,6 +353,36 @@ export async function confirmOutgoingPreMessages(store, clientMessageId, accepte
|
|
|
182
353
|
return cloneReliabilityValue(existing);
|
|
183
354
|
});
|
|
184
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Replace stored pre-messages of a group intent in one write. Each
|
|
358
|
+
* replacement keeps the target and the timestamp of the pre-message that it
|
|
359
|
+
* replaces, and the stored pre-message must still equal the expected one.
|
|
360
|
+
*/
|
|
361
|
+
export async function replaceOutgoingGroupPreMessages(store, clientMessageId, replacements) {
|
|
362
|
+
return serializeMutation(store, async () => {
|
|
363
|
+
const key = recordKey('outbox', clientMessageId);
|
|
364
|
+
const existing = parseJson(await store.getMetadata(key), null);
|
|
365
|
+
if (!existing || existing.kind !== 'group' || existing.result) {
|
|
366
|
+
throw new Error('Cannot replace pre-messages of a missing or completed group outbox intent');
|
|
367
|
+
}
|
|
368
|
+
const preMessages = existing.preMessages ?? [];
|
|
369
|
+
for (const { expected, replacement } of replacements) {
|
|
370
|
+
const index = preMessages.findIndex((candidate) => candidate.recipientUserId === expected.recipientUserId &&
|
|
371
|
+
candidate.recipientDeviceId === expected.recipientDeviceId);
|
|
372
|
+
if (index < 0 || JSON.stringify(preMessages[index]) !== JSON.stringify(expected)) {
|
|
373
|
+
throw new Error('Cannot replace an unexpected group pre-message');
|
|
374
|
+
}
|
|
375
|
+
if (replacement.recipientUserId !== expected.recipientUserId ||
|
|
376
|
+
replacement.recipientDeviceId !== expected.recipientDeviceId ||
|
|
377
|
+
replacement.timestamp !== expected.timestamp) {
|
|
378
|
+
throw new Error('A group pre-message replacement cannot change its target or timestamp');
|
|
379
|
+
}
|
|
380
|
+
preMessages[index] = cloneReliabilityValue(replacement);
|
|
381
|
+
}
|
|
382
|
+
await store.setMetadata(key, JSON.stringify(existing));
|
|
383
|
+
return cloneReliabilityValue(existing);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
185
386
|
/**
|
|
186
387
|
* Apply the recipient's device list to a direct intent in one write: remove
|
|
187
388
|
* the messages of the devices that the list no longer shows, append a message
|
|
@@ -213,6 +414,25 @@ export async function reconcileOutgoingDirectDeviceMessages(store, clientMessage
|
|
|
213
414
|
return cloneReliabilityValue(existing);
|
|
214
415
|
});
|
|
215
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* Change the sync copies of a direct or group intent in one write. The sync
|
|
419
|
+
* copies of each removed own device leave the intent first. Then each new
|
|
420
|
+
* sync copy is appended. A new copy for a device that still has a copy must
|
|
421
|
+
* be equal to it, and is not appended again. A completed intent accepts the
|
|
422
|
+
* change only while its sync phase is pending.
|
|
423
|
+
*/
|
|
424
|
+
export async function reconcileOutgoingSyncMessages(store, clientMessageId, removedDeviceIds, additions) {
|
|
425
|
+
return serializeMutation(store, async () => {
|
|
426
|
+
const key = recordKey('outbox', clientMessageId);
|
|
427
|
+
const existing = parseJson(await store.getMetadata(key), null);
|
|
428
|
+
if (!existing || (existing.result && !existing.syncPending)) {
|
|
429
|
+
throw new Error('Cannot change the sync copies of a missing or completed outbox intent');
|
|
430
|
+
}
|
|
431
|
+
existing.syncMessages = appendOutgoingDeviceMessages(existing.syncMessages.filter((message) => !removedDeviceIds.includes(message.recipientDeviceId)), additions, 'Cannot replace a persisted sync transmission');
|
|
432
|
+
await store.setMetadata(key, JSON.stringify(existing));
|
|
433
|
+
return cloneReliabilityValue(existing);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
216
436
|
export async function replaceOutgoingDirectDeviceMessage(store, clientMessageId, expected, replacement) {
|
|
217
437
|
return serializeMutation(store, async () => {
|
|
218
438
|
const key = recordKey('outbox', clientMessageId);
|
|
@@ -309,7 +529,14 @@ export async function updateDeliveryStatus(store, clientMessageId, update, now =
|
|
|
309
529
|
return value;
|
|
310
530
|
});
|
|
311
531
|
}
|
|
312
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Complete an outgoing intent with its Relay result. With `syncPending`,
|
|
534
|
+
* the recipient phase completed and the sync phase did not: the intent keeps
|
|
535
|
+
* its sync messages and the restart count of its sync phase, so a replay
|
|
536
|
+
* posts only the sync messages. With `syncPending` and no sync messages, the
|
|
537
|
+
* read of the own device list failed, and a replay reads it.
|
|
538
|
+
*/
|
|
539
|
+
export async function completeOutgoingMessageIntent(store, clientMessageId, result, options = {}) {
|
|
313
540
|
await serializeMutation(store, async () => {
|
|
314
541
|
const key = recordKey('outbox', clientMessageId);
|
|
315
542
|
const existing = parseJson(await store.getMetadata(key), null);
|
|
@@ -322,7 +549,28 @@ export async function completeOutgoingMessageIntent(store, clientMessageId, resu
|
|
|
322
549
|
delete existing.reconcilePending;
|
|
323
550
|
delete existing.preMessages;
|
|
324
551
|
existing.deviceMessages = [];
|
|
325
|
-
|
|
552
|
+
if (options.syncPending) {
|
|
553
|
+
existing.syncPending = true;
|
|
554
|
+
const sync = existing.deviceSetRestarts?.sync;
|
|
555
|
+
if (sync === undefined)
|
|
556
|
+
delete existing.deviceSetRestarts;
|
|
557
|
+
else
|
|
558
|
+
existing.deviceSetRestarts = { sync };
|
|
559
|
+
if (existing.deviceSetUnresolved?.phase !== 'sync')
|
|
560
|
+
delete existing.deviceSetUnresolved;
|
|
561
|
+
const syncMissing = existing.deviceSetBundleMissing?.sync;
|
|
562
|
+
if (syncMissing)
|
|
563
|
+
existing.deviceSetBundleMissing = { sync: syncMissing };
|
|
564
|
+
else
|
|
565
|
+
delete existing.deviceSetBundleMissing;
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
existing.syncMessages = [];
|
|
569
|
+
delete existing.syncPending;
|
|
570
|
+
delete existing.deviceSetRestarts;
|
|
571
|
+
delete existing.deviceSetUnresolved;
|
|
572
|
+
delete existing.deviceSetBundleMissing;
|
|
573
|
+
}
|
|
326
574
|
delete existing.sealedSenderAuth;
|
|
327
575
|
delete existing.groupCiphertext;
|
|
328
576
|
delete existing.groupSenderKeyDistributionId;
|
|
@@ -332,7 +580,9 @@ export async function completeOutgoingMessageIntent(store, clientMessageId, resu
|
|
|
332
580
|
}
|
|
333
581
|
/** The lifetime of one processed-envelope record. */
|
|
334
582
|
function processedEnvelopeTtl(record) {
|
|
335
|
-
return record.fulfilled
|
|
583
|
+
return record.fulfilled || record.completed
|
|
584
|
+
? RETRY_REQUESTER_RECORD_TTL_MS
|
|
585
|
+
: RELIABILITY_RECORD_TTL_MS;
|
|
336
586
|
}
|
|
337
587
|
/**
|
|
338
588
|
* The time that the incoming ledger indexes one record at. The ledger
|
|
@@ -346,16 +596,20 @@ async function readProcessedEnvelope(store, envelopeId) {
|
|
|
346
596
|
const value = await store.getMetadata(recordKey('incoming', envelopeId));
|
|
347
597
|
if (value === null)
|
|
348
598
|
return null;
|
|
349
|
-
const { processedAt, fingerprint, fulfilled } = JSON.parse(value);
|
|
599
|
+
const { processedAt, fingerprint, fulfilled, completed, outcome } = JSON.parse(value);
|
|
350
600
|
if (!Number.isFinite(processedAt) ||
|
|
351
601
|
(fingerprint !== undefined && typeof fingerprint !== 'string') ||
|
|
352
|
-
(fulfilled !== undefined && fulfilled !== true)
|
|
602
|
+
(fulfilled !== undefined && fulfilled !== true) ||
|
|
603
|
+
(completed !== undefined && completed !== true) ||
|
|
604
|
+
(outcome !== undefined && outcome !== 'denied' && outcome !== 'expired')) {
|
|
353
605
|
throw new Error('Corrupt processed-envelope record');
|
|
354
606
|
}
|
|
355
607
|
return {
|
|
356
608
|
processedAt,
|
|
357
609
|
...(fingerprint !== undefined && { fingerprint }),
|
|
358
610
|
...(fulfilled === true && { fulfilled }),
|
|
611
|
+
...(completed === true && { completed }),
|
|
612
|
+
...(outcome !== undefined && { outcome }),
|
|
359
613
|
};
|
|
360
614
|
}
|
|
361
615
|
/**
|
|
@@ -380,7 +634,7 @@ export async function hasProcessedEnvelope(store, envelopeId, now = Date.now())
|
|
|
380
634
|
}
|
|
381
635
|
/**
|
|
382
636
|
* Record that the local device processed one envelope ID. The write keeps
|
|
383
|
-
* the fingerprint and the
|
|
637
|
+
* the fingerprint, the flags, and the outcome of a record that counts, so a
|
|
384
638
|
* later store for the same ID never clears them.
|
|
385
639
|
*
|
|
386
640
|
* @param fulfilled - True when the application got the content of this
|
|
@@ -388,28 +642,75 @@ export async function hasProcessedEnvelope(store, envelopeId, now = Date.now())
|
|
|
388
642
|
* one write.
|
|
389
643
|
*/
|
|
390
644
|
export async function storeProcessedEnvelope(store, envelopeId, processedAt = Date.now(), fingerprint, fulfilled) {
|
|
645
|
+
await serializeMutation(store, () => writeProcessedEnvelope(store, processedAt, {
|
|
646
|
+
envelopeId,
|
|
647
|
+
...(fingerprint !== undefined && { fingerprint }),
|
|
648
|
+
...(fulfilled && { fulfilled }),
|
|
649
|
+
}));
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Write several processed-envelope records in one turn of the mutation
|
|
653
|
+
* queue. A denial with no receive record uses it: the denied outcome and
|
|
654
|
+
* the processed fact of the envelope land together.
|
|
655
|
+
*/
|
|
656
|
+
export async function writeProcessedEnvelopes(store, writes, processedAt = Date.now()) {
|
|
391
657
|
await serializeMutation(store, async () => {
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
658
|
+
for (const write of writes)
|
|
659
|
+
await writeProcessedEnvelope(store, processedAt, write);
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
/** Write one processed-envelope record. The caller holds the mutation queue. */
|
|
663
|
+
async function writeProcessedEnvelope(store, processedAt, write) {
|
|
664
|
+
const { envelopeId } = write;
|
|
665
|
+
const existing = await readProcessedEnvelope(store, envelopeId);
|
|
666
|
+
const current = existing && existing.processedAt >= processedAt - processedEnvelopeTtl(existing)
|
|
667
|
+
? existing
|
|
668
|
+
: null;
|
|
669
|
+
const keptFingerprint = write.fingerprint ?? current?.fingerprint;
|
|
670
|
+
const keptOutcome = write.outcome ?? current?.outcome;
|
|
671
|
+
const record = {
|
|
672
|
+
processedAt,
|
|
673
|
+
...(keptFingerprint !== undefined && { fingerprint: keptFingerprint }),
|
|
674
|
+
...((write.fulfilled || current?.fulfilled) && { fulfilled: true }),
|
|
675
|
+
...((write.completed || current?.completed) && { completed: true }),
|
|
676
|
+
...(keptOutcome !== undefined && { outcome: keptOutcome }),
|
|
677
|
+
};
|
|
678
|
+
const indexTime = processedEnvelopeIndexTime(record);
|
|
679
|
+
const retainedDays = await pruneExpiredBuckets(store, 'incoming', processedAt);
|
|
680
|
+
await store.setMetadata(recordKey('incoming', envelopeId), JSON.stringify(record));
|
|
681
|
+
await indexRecord(store, 'incoming', envelopeId, indexTime, retainedDays);
|
|
682
|
+
// The bucket of the earlier record would prune the new record early.
|
|
683
|
+
if (existing) {
|
|
684
|
+
const existingIndexTime = processedEnvelopeIndexTime(existing);
|
|
685
|
+
if (dayFor(existingIndexTime) !== dayFor(indexTime)) {
|
|
686
|
+
await unindexRecord(store, 'incoming', envelopeId, existingIndexTime);
|
|
412
687
|
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Complete one receive record: delete it and write its processed-envelope
|
|
692
|
+
* records in one atomic store write. The writes run against a buffer over
|
|
693
|
+
* the store, so the ledger index and the records commit with the delete or
|
|
694
|
+
* not at all.
|
|
695
|
+
*
|
|
696
|
+
* @returns False, with nothing written, when the stored revision of the
|
|
697
|
+
* receive record is not `expectedRevision`.
|
|
698
|
+
*/
|
|
699
|
+
export async function completeReceiveRecord(store, workId, expectedRevision, writes, processedAt = Date.now()) {
|
|
700
|
+
return serializeMutation(store, async () => {
|
|
701
|
+
const buffer = new Map();
|
|
702
|
+
const buffered = {
|
|
703
|
+
getMetadata: async (key) => (buffer.has(key) ? buffer.get(key) : store.getMetadata(key)),
|
|
704
|
+
setMetadata: async (key, value) => {
|
|
705
|
+
buffer.set(key, value);
|
|
706
|
+
},
|
|
707
|
+
deleteMetadata: async (key) => {
|
|
708
|
+
buffer.set(key, null);
|
|
709
|
+
},
|
|
710
|
+
};
|
|
711
|
+
for (const write of writes)
|
|
712
|
+
await writeProcessedEnvelope(buffered, processedAt, write);
|
|
713
|
+
return store.completeReceiveWork(workId, expectedRevision, [...buffer].map(([key, value]) => ({ key, value })));
|
|
413
714
|
});
|
|
414
715
|
}
|
|
415
716
|
/**
|
|
@@ -534,6 +835,43 @@ export async function resolveRetryFamilyMember(store, envelopeId, now = Date.now
|
|
|
534
835
|
return undefined;
|
|
535
836
|
return { retryId: member.retryId, failedEnvelopeId, kind: member.kind, attempt: member.attempt };
|
|
536
837
|
}
|
|
838
|
+
/** The shortest time between two session reset null messages to one device. */
|
|
839
|
+
export const RETRY_TERMINAL_NULL_MESSAGE_INTERVAL_MS = 60 * 60 * 1_000;
|
|
840
|
+
const RETRY_TERMINAL_CLASSES = new Set([
|
|
841
|
+
'missing-sender',
|
|
842
|
+
'missing-prekey',
|
|
843
|
+
'revoked-authority',
|
|
844
|
+
'expired-content',
|
|
845
|
+
'attempts-exhausted',
|
|
846
|
+
'deletion',
|
|
847
|
+
'abuse-allowance-exhausted',
|
|
848
|
+
'membership-refused',
|
|
849
|
+
]);
|
|
850
|
+
function isRetryTerminal(value) {
|
|
851
|
+
if (value === null || typeof value !== 'object')
|
|
852
|
+
return false;
|
|
853
|
+
const terminal = value;
|
|
854
|
+
return (typeof terminal.class === 'string' &&
|
|
855
|
+
RETRY_TERMINAL_CLASSES.has(terminal.class) &&
|
|
856
|
+
Number.isFinite(terminal.at) &&
|
|
857
|
+
typeof terminal.emitted === 'boolean');
|
|
858
|
+
}
|
|
859
|
+
function isRetryTerminalRecovery(value) {
|
|
860
|
+
if (value === null || typeof value !== 'object')
|
|
861
|
+
return false;
|
|
862
|
+
const recovery = value;
|
|
863
|
+
const nullMessage = recovery.nullMessage;
|
|
864
|
+
return (typeof recovery.userId === 'string' &&
|
|
865
|
+
Number.isSafeInteger(recovery.deviceId) &&
|
|
866
|
+
(recovery.senderKey === 'applied' || recovery.senderKey === 'skipped') &&
|
|
867
|
+
(nullMessage === undefined ||
|
|
868
|
+
(typeof nullMessage === 'object' &&
|
|
869
|
+
nullMessage !== null &&
|
|
870
|
+
(nullMessage.outcome === 'sent' ||
|
|
871
|
+
nullMessage.outcome === 'limited' ||
|
|
872
|
+
nullMessage.outcome === 'failed') &&
|
|
873
|
+
Number.isFinite(nullMessage.at))));
|
|
874
|
+
}
|
|
537
875
|
/**
|
|
538
876
|
* Get the stored retry request for one failed envelope. A record older than
|
|
539
877
|
* `RETRY_REQUESTER_RECORD_TTL_MS` does not count.
|
|
@@ -550,7 +888,23 @@ export async function getRetryRequest(store, failedEnvelopeId, now = Date.now(),
|
|
|
550
888
|
!isRetryId(record.retryId) ||
|
|
551
889
|
!Number.isSafeInteger(record.attempt) ||
|
|
552
890
|
record.attempt < 1 ||
|
|
553
|
-
typeof record.answered !== 'boolean'
|
|
891
|
+
typeof record.answered !== 'boolean' ||
|
|
892
|
+
!Number.isFinite(record.deadlineAt) ||
|
|
893
|
+
(record.nextAttemptAt !== undefined && !Number.isFinite(record.nextAttemptAt)) ||
|
|
894
|
+
(record.lastFailureClass !== undefined &&
|
|
895
|
+
record.lastFailureClass !== 'transport-outage' &&
|
|
896
|
+
record.lastFailureClass !== 'rate-refusal') ||
|
|
897
|
+
(record.terminal !== undefined && !isRetryTerminal(record.terminal)) ||
|
|
898
|
+
(record.envelope === undefined && record.terminal === undefined) ||
|
|
899
|
+
(record.receivedAt !== undefined && !Number.isFinite(record.receivedAt)) ||
|
|
900
|
+
(record.errorShown !== undefined && typeof record.errorShown !== 'boolean') ||
|
|
901
|
+
(record.recoveredEmitted !== undefined && typeof record.recoveredEmitted !== 'boolean') ||
|
|
902
|
+
(record.groupId !== undefined && (typeof record.groupId !== 'string' || !record.groupId)) ||
|
|
903
|
+
(record.failedSender !== undefined &&
|
|
904
|
+
(typeof record.failedSender?.userId !== 'string' ||
|
|
905
|
+
!Number.isSafeInteger(record.failedSender.deviceId))) ||
|
|
906
|
+
(record.recovery !== undefined &&
|
|
907
|
+
(record.terminal?.class !== 'expired-content' || !isRetryTerminalRecovery(record.recovery)))) {
|
|
554
908
|
throw new Error('Corrupt retry-request record');
|
|
555
909
|
}
|
|
556
910
|
if (record.requestedAt < now - RETRY_REQUESTER_RECORD_TTL_MS)
|
|
@@ -581,8 +935,104 @@ export async function markRetryRequestAnswered(store, failedEnvelopeId, retryId,
|
|
|
581
935
|
record.attempt !== attempt) {
|
|
582
936
|
return;
|
|
583
937
|
}
|
|
584
|
-
// The attempt keeps its time, so its bucket index stays.
|
|
585
|
-
|
|
938
|
+
// The attempt keeps its time, so its bucket index stays. An answer ends
|
|
939
|
+
// the wait for a later post of the attempt.
|
|
940
|
+
await store.setMetadata(recordKey('retry-requested', failedEnvelopeId), JSON.stringify({
|
|
941
|
+
...record,
|
|
942
|
+
answered: true,
|
|
943
|
+
nextAttemptAt: undefined,
|
|
944
|
+
lastFailureClass: undefined,
|
|
945
|
+
}));
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Change the lifecycle fields of the stored attempt of a retry request. It
|
|
950
|
+
* writes only when the record holds the given retry ID and attempt, so a
|
|
951
|
+
* change for an attempt that a later attempt replaced writes nothing. A
|
|
952
|
+
* field with the value undefined is removed. The attempt keeps its time,
|
|
953
|
+
* so its bucket index stays.
|
|
954
|
+
*
|
|
955
|
+
* @returns The changed record, or null when no record matched.
|
|
956
|
+
*/
|
|
957
|
+
export async function updateRetryRequest(store, failedEnvelopeId, retryId, attempt, changes, now = Date.now()) {
|
|
958
|
+
return serializeMutation(store, async () => {
|
|
959
|
+
const record = await getRetryRequest(store, failedEnvelopeId, now);
|
|
960
|
+
if (!record || record.retryId !== retryId || record.attempt !== attempt)
|
|
961
|
+
return null;
|
|
962
|
+
const changed = cloneReliabilityValue({ ...record, ...changes });
|
|
963
|
+
await store.setMetadata(recordKey('retry-requested', failedEnvelopeId), JSON.stringify(changed));
|
|
964
|
+
return changed;
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
/**
|
|
968
|
+
* The failed envelope IDs of the stored retry requests that are not older
|
|
969
|
+
* than `RETRY_REQUESTER_RECORD_TTL_MS`. The caller reads each record with
|
|
970
|
+
* `getRetryRequest`.
|
|
971
|
+
*/
|
|
972
|
+
export async function listRetryRequestIds(store, now = Date.now()) {
|
|
973
|
+
const firstRetainedDay = dayFor(now - RETRY_REQUESTER_RECORD_TTL_MS);
|
|
974
|
+
const days = parseJson(await store.getMetadata(manifestKey('retry-requested')), []);
|
|
975
|
+
const ids = [];
|
|
976
|
+
for (const day of days) {
|
|
977
|
+
if (day < firstRetainedDay)
|
|
978
|
+
continue;
|
|
979
|
+
for (const id of parseJson(await store.getMetadata(bucketKey('retry-requested', day)), [])) {
|
|
980
|
+
if (!ids.includes(id))
|
|
981
|
+
ids.push(id);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
return ids;
|
|
985
|
+
}
|
|
986
|
+
/** The key prefix of the retry request records before the lifecycle fields. */
|
|
987
|
+
const RETRY_REQUESTED_V1_PREFIX = 'reliability:retry-requested:v1';
|
|
988
|
+
/** A v1 retry request record, or null for a value that does not parse. */
|
|
989
|
+
function parseV1RetryRequest(value) {
|
|
990
|
+
try {
|
|
991
|
+
const record = parseJson(value, null);
|
|
992
|
+
return record !== null && typeof record === 'object' ? record : null;
|
|
993
|
+
}
|
|
994
|
+
catch {
|
|
995
|
+
return null;
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Move each retry request record of the v1 prefix to the current prefix,
|
|
1000
|
+
* and delete the v1 keys. A v1 record has no deadline, so the moved record
|
|
1001
|
+
* gets the time of its stored attempt plus `RETRY_REQUEST_DEADLINE_MS`. A
|
|
1002
|
+
* v1 record does not tell whether the post of its attempt reached the
|
|
1003
|
+
* Relay, so an unanswered record is due at the time of its stored attempt,
|
|
1004
|
+
* and the scheduler posts its stored bytes again. A
|
|
1005
|
+
* record older than `RETRY_REQUESTER_RECORD_TTL_MS`, and a record that does
|
|
1006
|
+
* not parse, is deleted. With no v1 keys, it writes nothing.
|
|
1007
|
+
*/
|
|
1008
|
+
export async function migrateRetryRequestRecords(store, now = Date.now()) {
|
|
1009
|
+
const v1ManifestKey = `${RETRY_REQUESTED_V1_PREFIX}:manifest`;
|
|
1010
|
+
const days = parseJson(await store.getMetadata(v1ManifestKey), []);
|
|
1011
|
+
if (days.length === 0)
|
|
1012
|
+
return;
|
|
1013
|
+
await serializeMutation(store, async () => {
|
|
1014
|
+
for (const day of days) {
|
|
1015
|
+
const v1BucketKey = `${RETRY_REQUESTED_V1_PREFIX}:bucket:${day}`;
|
|
1016
|
+
for (const id of parseJson(await store.getMetadata(v1BucketKey), [])) {
|
|
1017
|
+
const v1RecordKey = `${RETRY_REQUESTED_V1_PREFIX}:record:${encodeURIComponent(id)}`;
|
|
1018
|
+
const record = parseV1RetryRequest(await store.getMetadata(v1RecordKey));
|
|
1019
|
+
if (record &&
|
|
1020
|
+
Number.isFinite(record.requestedAt) &&
|
|
1021
|
+
record.requestedAt >= now - RETRY_REQUESTER_RECORD_TTL_MS) {
|
|
1022
|
+
const retainedDays = await pruneExpiredBuckets(store, 'retry-requested', now);
|
|
1023
|
+
await store.setMetadata(recordKey('retry-requested', id), JSON.stringify({
|
|
1024
|
+
...record,
|
|
1025
|
+
deadlineAt: record.requestedAt + RETRY_REQUEST_DEADLINE_MS,
|
|
1026
|
+
...(!record.answered &&
|
|
1027
|
+
record.envelope !== undefined && { nextAttemptAt: record.requestedAt }),
|
|
1028
|
+
}));
|
|
1029
|
+
await indexRecord(store, 'retry-requested', id, record.requestedAt, retainedDays);
|
|
1030
|
+
}
|
|
1031
|
+
await store.deleteMetadata(v1RecordKey);
|
|
1032
|
+
}
|
|
1033
|
+
await store.deleteMetadata(v1BucketKey);
|
|
1034
|
+
}
|
|
1035
|
+
await store.deleteMetadata(v1ManifestKey);
|
|
586
1036
|
});
|
|
587
1037
|
}
|
|
588
1038
|
/**
|
|
@@ -601,7 +1051,9 @@ export async function markRetryRequestAnswered(store, failedEnvelopeId, retryId,
|
|
|
601
1051
|
*/
|
|
602
1052
|
export async function storeRetryRequest(store, request) {
|
|
603
1053
|
await serializeMutation(store, async () => {
|
|
604
|
-
|
|
1054
|
+
// A request with no envelope posted nothing, so no member can name it.
|
|
1055
|
+
if (request.envelope)
|
|
1056
|
+
await indexRetryFamily(store, request);
|
|
605
1057
|
const key = recordKey('retry-requested', request.failedEnvelopeId);
|
|
606
1058
|
const replaced = parseJson(await store.getMetadata(key), null);
|
|
607
1059
|
const retainedDays = await pruneExpiredBuckets(store, 'retry-requested', request.requestedAt);
|
|
@@ -642,6 +1094,21 @@ export async function getRetryResend(store, recipientUserId, recipientDeviceId,
|
|
|
642
1094
|
const record = parseJson(await store.getMetadata(recordKey('retry-resend', retryResendRecordId(recipientUserId, recipientDeviceId, failedEnvelopeId))), null);
|
|
643
1095
|
if (!record)
|
|
644
1096
|
return null;
|
|
1097
|
+
if (record.terminal !== undefined) {
|
|
1098
|
+
if (!isRetryTerminal(record.terminal) ||
|
|
1099
|
+
record.failedEnvelopeId !== failedEnvelopeId ||
|
|
1100
|
+
!isRetryId(record.retryId) ||
|
|
1101
|
+
typeof record.requestEnvelopeId !== 'string' ||
|
|
1102
|
+
(record.kind !== 'resend' && record.kind !== 'null') ||
|
|
1103
|
+
record.recipientUserId !== recipientUserId ||
|
|
1104
|
+
record.recipientDeviceId !== recipientDeviceId ||
|
|
1105
|
+
!answersItsRequestAttempt(record)) {
|
|
1106
|
+
throw new Error('Corrupt retry-resend record');
|
|
1107
|
+
}
|
|
1108
|
+
if (record.terminal.at < now - RELIABILITY_RECORD_TTL_MS)
|
|
1109
|
+
return null;
|
|
1110
|
+
return cloneReliabilityValue(record);
|
|
1111
|
+
}
|
|
645
1112
|
if (!Number.isFinite(record.operationEpochMilliseconds) ||
|
|
646
1113
|
record.failedEnvelopeId !== failedEnvelopeId ||
|
|
647
1114
|
!isRetryId(record.retryId) ||
|
|
@@ -663,27 +1130,34 @@ function answersItsRequestAttempt(record) {
|
|
|
663
1130
|
member.retryId === record.retryId &&
|
|
664
1131
|
member.attempt === record.attempt);
|
|
665
1132
|
}
|
|
1133
|
+
/** The time from which a retry-resend record expires. */
|
|
1134
|
+
function retryResendTime(record) {
|
|
1135
|
+
return record.terminal === undefined ? record.operationEpochMilliseconds : record.terminal.at;
|
|
1136
|
+
}
|
|
666
1137
|
/**
|
|
667
|
-
* Record the encrypted bytes of a retry resend before their post
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
* is not the attempt number of the
|
|
1138
|
+
* Record the encrypted bytes of a retry resend before their post, or the
|
|
1139
|
+
* terminal state of the answer. A later write replaces the earlier one in
|
|
1140
|
+
* one write, so the record holds one state at each point. Throws, and
|
|
1141
|
+
* writes nothing, when the attempt is not the attempt number of the
|
|
1142
|
+
* request envelope.
|
|
671
1143
|
*/
|
|
672
1144
|
export async function storeRetryResend(store, resend) {
|
|
673
1145
|
if (resend.attempt !== retryRequestAttempt(resend)) {
|
|
674
1146
|
throw new Error('A retry resend carries the attempt number of its request');
|
|
675
1147
|
}
|
|
676
1148
|
await serializeMutation(store, async () => {
|
|
677
|
-
const id =
|
|
1149
|
+
const id = resend.terminal === undefined
|
|
1150
|
+
? retryResendRecordId(resend.message.recipientUserId, resend.message.recipientDeviceId, resend.failedEnvelopeId)
|
|
1151
|
+
: retryResendRecordId(resend.recipientUserId, resend.recipientDeviceId, resend.failedEnvelopeId);
|
|
678
1152
|
const key = recordKey('retry-resend', id);
|
|
679
1153
|
const replaced = parseJson(await store.getMetadata(key), null);
|
|
680
|
-
const
|
|
1154
|
+
const time = retryResendTime(resend);
|
|
1155
|
+
const retainedDays = await pruneExpiredBuckets(store, 'retry-resend', time);
|
|
681
1156
|
await store.setMetadata(key, JSON.stringify(resend));
|
|
682
|
-
await indexRecord(store, 'retry-resend', id,
|
|
683
|
-
// The bucket of the replaced
|
|
684
|
-
if (replaced &&
|
|
685
|
-
|
|
686
|
-
await unindexRecord(store, 'retry-resend', id, replaced.operationEpochMilliseconds);
|
|
1157
|
+
await indexRecord(store, 'retry-resend', id, time, retainedDays);
|
|
1158
|
+
// The bucket of the replaced time would prune the new record early.
|
|
1159
|
+
if (replaced && dayFor(retryResendTime(replaced)) !== dayFor(time)) {
|
|
1160
|
+
await unindexRecord(store, 'retry-resend', id, retryResendTime(replaced));
|
|
687
1161
|
}
|
|
688
1162
|
});
|
|
689
1163
|
}
|