@open-e2ee/signal-protocol-sdk 14.0.0 → 14.2.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 +5 -5
- package/ARCHITECTURE.md +1 -1
- package/CHANGELOG.md +461 -0
- package/README.md +21 -15
- package/SECURITY.md +2 -2
- package/TROUBLESHOOTING.md +1 -1
- package/client/README.md +35 -22
- package/device/README.md +5 -5
- package/dist/client/client.d.ts +44 -34
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +221 -146
- package/dist/client/client.js.map +1 -1
- package/dist/client/compose.d.ts +7 -5
- package/dist/client/compose.d.ts.map +1 -1
- package/dist/client/compose.js +7 -2
- package/dist/client/compose.js.map +1 -1
- package/dist/client/config.d.ts +23 -14
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js.map +1 -1
- package/dist/client/content-adapter.d.ts +9 -0
- package/dist/client/content-adapter.d.ts.map +1 -1
- package/dist/client/content-adapter.js +6 -0
- package/dist/client/content-adapter.js.map +1 -1
- package/dist/client/delivery-status.d.ts +2 -2
- package/dist/client/delivery-status.d.ts.map +1 -1
- package/dist/client/delivery-status.js +10 -4
- package/dist/client/delivery-status.js.map +1 -1
- package/dist/client/device-set-reconciliation.d.ts +24 -16
- package/dist/client/device-set-reconciliation.d.ts.map +1 -1
- package/dist/client/device-set-reconciliation.js +17 -14
- package/dist/client/device-set-reconciliation.js.map +1 -1
- package/dist/client/event-hooks.d.ts +22 -7
- package/dist/client/event-hooks.d.ts.map +1 -1
- package/dist/client/event-hooks.js +35 -5
- package/dist/client/event-hooks.js.map +1 -1
- package/dist/client/group-device-set.d.ts +1 -1
- package/dist/client/group-device-set.d.ts.map +1 -1
- package/dist/client/group-key-sync.js +1 -1
- package/dist/client/group-key-sync.js.map +1 -1
- package/dist/client/group-outbox.d.ts +7 -7
- package/dist/client/group-outbox.d.ts.map +1 -1
- package/dist/client/group-outbox.js +24 -24
- package/dist/client/group-outbox.js.map +1 -1
- package/dist/client/group-sealed-sender.d.ts +1 -1
- package/dist/client/group-sealed-sender.d.ts.map +1 -1
- package/dist/client/group-sender-key-operations.js +1 -1
- package/dist/client/group-sender-key-operations.js.map +1 -1
- package/dist/client/headless.d.ts +6 -6
- package/dist/client/headless.d.ts.map +1 -1
- package/dist/client/headless.js +7 -7
- package/dist/client/headless.js.map +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts +18 -6
- package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
- package/dist/client/hosted-anonymous-delivery.js +63 -20
- package/dist/client/hosted-anonymous-delivery.js.map +1 -1
- package/dist/client/hosted-assertion-id.d.ts +1 -1
- package/dist/client/hosted-assertion-id.d.ts.map +1 -1
- package/dist/client/hosted-assertion-id.js +1 -1
- package/dist/client/hosted-assertion-id.js.map +1 -1
- package/dist/client/hosted-connection.d.ts +5 -5
- package/dist/client/hosted-connection.d.ts.map +1 -1
- package/dist/client/hosted-connection.js +32 -32
- package/dist/client/hosted-connection.js.map +1 -1
- package/dist/client/hosted-device-link-transport.d.ts +2 -2
- package/dist/client/hosted-device-link-transport.d.ts.map +1 -1
- package/dist/client/hosted-device-link-transport.js +1 -1
- package/dist/client/hosted-device-link-transport.js.map +1 -1
- package/dist/client/hosted-device-link.d.ts +5 -1
- package/dist/client/hosted-device-link.d.ts.map +1 -1
- package/dist/client/hosted-device-link.js +7 -4
- package/dist/client/hosted-device-link.js.map +1 -1
- package/dist/client/hosted-device-standing.d.ts +13 -5
- package/dist/client/hosted-device-standing.d.ts.map +1 -1
- package/dist/client/hosted-device-standing.js +11 -6
- package/dist/client/hosted-device-standing.js.map +1 -1
- package/dist/client/hosted-group-authority.d.ts +2 -2
- package/dist/client/hosted-group-authority.d.ts.map +1 -1
- package/dist/client/hosted-group-authority.js +8 -8
- package/dist/client/hosted-group-authority.js.map +1 -1
- package/dist/client/hosted-groups.d.ts +4 -4
- package/dist/client/hosted-groups.d.ts.map +1 -1
- package/dist/client/hosted-groups.js +8 -8
- package/dist/client/hosted-groups.js.map +1 -1
- package/dist/client/hosted-http-error.d.ts +8 -4
- package/dist/client/hosted-http-error.d.ts.map +1 -1
- package/dist/client/hosted-http-error.js +7 -4
- package/dist/client/hosted-http-error.js.map +1 -1
- package/dist/client/hosted-mailbox-subscription.d.ts +16 -15
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +21 -25
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-prekey-publication.d.ts +9 -9
- package/dist/client/hosted-prekey-publication.d.ts.map +1 -1
- package/dist/client/hosted-prekey-publication.js.map +1 -1
- package/dist/client/hosted-presence-frames.d.ts +62 -38
- package/dist/client/hosted-presence-frames.d.ts.map +1 -1
- package/dist/client/hosted-presence-frames.js +4 -2
- package/dist/client/hosted-presence-frames.js.map +1 -1
- package/dist/client/hosted-presence.d.ts +22 -14
- package/dist/client/hosted-presence.d.ts.map +1 -1
- package/dist/client/hosted-presence.js +26 -17
- package/dist/client/hosted-presence.js.map +1 -1
- package/dist/client/hosted-profile-keys.d.ts +3 -1
- package/dist/client/hosted-profile-keys.d.ts.map +1 -1
- package/dist/client/hosted-profile-keys.js +19 -15
- package/dist/client/hosted-profile-keys.js.map +1 -1
- package/dist/client/hosted-push.d.ts +38 -16
- package/dist/client/hosted-push.d.ts.map +1 -1
- package/dist/client/hosted-push.js +11 -5
- package/dist/client/hosted-push.js.map +1 -1
- package/dist/client/hosted-resume-error.d.ts +21 -9
- package/dist/client/hosted-resume-error.d.ts.map +1 -1
- package/dist/client/hosted-resume-error.js +4 -1
- package/dist/client/hosted-resume-error.js.map +1 -1
- package/dist/client/hosted-resume.d.ts +3 -3
- package/dist/client/hosted-resume.d.ts.map +1 -1
- package/dist/client/hosted-resume.js +12 -12
- package/dist/client/hosted-resume.js.map +1 -1
- package/dist/client/hosted-sandbox-identity.d.ts +82 -5
- package/dist/client/hosted-sandbox-identity.d.ts.map +1 -1
- package/dist/client/hosted-sandbox-identity.js +160 -50
- package/dist/client/hosted-sandbox-identity.js.map +1 -1
- package/dist/client/hosted-store-records.d.ts +46 -0
- package/dist/client/hosted-store-records.d.ts.map +1 -0
- package/dist/client/hosted-store-records.js +32 -0
- package/dist/client/hosted-store-records.js.map +1 -0
- package/dist/client/hosted-transport.d.ts +53 -33
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +225 -138
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted-trust.d.ts +1 -1
- package/dist/client/hosted-trust.d.ts.map +1 -1
- package/dist/client/hosted-trust.js +1 -1
- package/dist/client/hosted-trust.js.map +1 -1
- package/dist/client/hosted.d.ts +144 -75
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +106 -61
- package/dist/client/hosted.js.map +1 -1
- package/dist/client/index.d.ts +4 -4
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +4 -4
- package/dist/client/index.js.map +1 -1
- package/dist/client/key-rotation-core.d.ts +4 -4
- package/dist/client/key-rotation-core.d.ts.map +1 -1
- package/dist/client/key-rotation-core.js +8 -8
- package/dist/client/key-rotation-core.js.map +1 -1
- package/dist/client/key-rotation.js +2 -2
- package/dist/client/key-rotation.js.map +1 -1
- package/dist/client/messages.d.ts +3 -3
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/messages.js +18 -18
- package/dist/client/messages.js.map +1 -1
- package/dist/client/one-time-prekey-refill.d.ts +1 -1
- package/dist/client/one-time-prekey-refill.d.ts.map +1 -1
- package/dist/client/prekeys.js +17 -17
- package/dist/client/prekeys.js.map +1 -1
- package/dist/client/receive-queue.d.ts +4 -4
- package/dist/client/receive-queue.d.ts.map +1 -1
- package/dist/client/receive-queue.js +29 -29
- package/dist/client/receive-queue.js.map +1 -1
- package/dist/client/receive-work-seed.d.ts +6 -2
- package/dist/client/receive-work-seed.d.ts.map +1 -1
- package/dist/client/receive-work-seed.js.map +1 -1
- package/dist/client/recovery-driver.js +7 -7
- package/dist/client/recovery-driver.js.map +1 -1
- package/dist/client/retry-request-envelope.d.ts +3 -3
- package/dist/client/retry-request-envelope.d.ts.map +1 -1
- package/dist/client/retry-request-envelope.js +10 -10
- package/dist/client/retry-request-envelope.js.map +1 -1
- package/dist/client/retry-request-lifecycle.d.ts +1 -1
- package/dist/client/retry-request-lifecycle.d.ts.map +1 -1
- package/dist/client/retry-request-lifecycle.js +8 -8
- package/dist/client/retry-request-lifecycle.js.map +1 -1
- package/dist/client/retry-terminal-recovery.js +2 -2
- package/dist/client/retry-terminal-recovery.js.map +1 -1
- package/dist/client/retry.js +13 -13
- package/dist/client/retry.js.map +1 -1
- package/dist/client/sealed-sender.d.ts +13 -4
- package/dist/client/sealed-sender.d.ts.map +1 -1
- package/dist/client/sealed-sender.js +27 -15
- package/dist/client/sealed-sender.js.map +1 -1
- package/dist/client/send-deadline.d.ts +8 -7
- package/dist/client/send-deadline.d.ts.map +1 -1
- package/dist/client/send-deadline.js +41 -23
- package/dist/client/send-deadline.js.map +1 -1
- package/dist/client/send-intent-driver.js +9 -9
- package/dist/client/send-intent-driver.js.map +1 -1
- package/dist/client/sessions.js +11 -11
- package/dist/client/sessions.js.map +1 -1
- package/dist/client/{relay-acceptance.d.ts → signal-relay-acceptance.d.ts} +9 -9
- package/dist/client/signal-relay-acceptance.d.ts.map +1 -0
- package/dist/client/{relay-acceptance.js → signal-relay-acceptance.js} +7 -7
- package/dist/client/signal-relay-acceptance.js.map +1 -0
- package/dist/client/{relay-device-refusal.d.ts → signal-relay-device-refusal.d.ts} +7 -7
- package/dist/client/signal-relay-device-refusal.d.ts.map +1 -0
- package/dist/client/{relay-device-refusal.js → signal-relay-device-refusal.js} +9 -9
- package/dist/client/signal-relay-device-refusal.js.map +1 -0
- package/dist/client/{relay-lifecycle.d.ts → signal-relay-lifecycle.d.ts} +21 -11
- package/dist/client/signal-relay-lifecycle.d.ts.map +1 -0
- package/dist/client/{relay-lifecycle.js → signal-relay-lifecycle.js} +19 -9
- package/dist/client/signal-relay-lifecycle.js.map +1 -0
- package/dist/client/signal-relay-period-close.d.ts +35 -0
- package/dist/client/signal-relay-period-close.d.ts.map +1 -0
- package/dist/client/signal-relay-period-close.js +63 -0
- package/dist/client/signal-relay-period-close.js.map +1 -0
- package/dist/client/{relay-protocol.d.ts → signal-relay-protocol.d.ts} +12 -8
- package/dist/client/signal-relay-protocol.d.ts.map +1 -0
- package/dist/client/{relay-protocol.js → signal-relay-protocol.js} +13 -10
- package/dist/client/signal-relay-protocol.js.map +1 -0
- package/dist/client/{relay-receipt-intake.d.ts → signal-relay-receipt-intake.d.ts} +12 -12
- package/dist/client/signal-relay-receipt-intake.d.ts.map +1 -0
- package/dist/client/{relay-receipt-intake.js → signal-relay-receipt-intake.js} +9 -9
- package/dist/client/signal-relay-receipt-intake.js.map +1 -0
- package/dist/client/{relay-receipt-join.d.ts → signal-relay-receipt-join.d.ts} +8 -8
- package/dist/client/signal-relay-receipt-join.d.ts.map +1 -0
- package/dist/client/{relay-receipt-join.js → signal-relay-receipt-join.js} +11 -11
- package/dist/client/signal-relay-receipt-join.js.map +1 -0
- package/dist/client/{relay-request-deadline.d.ts → signal-relay-request-deadline.d.ts} +3 -3
- package/dist/client/signal-relay-request-deadline.d.ts.map +1 -0
- package/dist/client/{relay-request-deadline.js → signal-relay-request-deadline.js} +4 -4
- package/dist/client/signal-relay-request-deadline.js.map +1 -0
- package/dist/client/{relay-sealed-route.d.ts → signal-relay-sealed-route.d.ts} +1 -1
- package/dist/client/signal-relay-sealed-route.d.ts.map +1 -0
- package/dist/client/{relay-sealed-route.js → signal-relay-sealed-route.js} +1 -1
- package/dist/client/signal-relay-sealed-route.js.map +1 -0
- package/dist/client/{relay-subscription.d.ts → signal-relay-subscription.d.ts} +12 -12
- package/dist/client/signal-relay-subscription.d.ts.map +1 -0
- package/dist/client/{relay-subscription.js → signal-relay-subscription.js} +23 -23
- package/dist/client/signal-relay-subscription.js.map +1 -0
- package/dist/client/{relay-work.d.ts → signal-relay-work.d.ts} +7 -7
- package/dist/client/signal-relay-work.d.ts.map +1 -0
- package/dist/client/{relay-work.js → signal-relay-work.js} +13 -13
- package/dist/client/signal-relay-work.js.map +1 -0
- package/dist/client/signal-service-cipher.d.ts +11 -9
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +103 -98
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/state.d.ts +4 -4
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/state.js +3 -3
- package/dist/client/state.js.map +1 -1
- package/dist/client/types.d.ts +13 -4
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/device/connection.d.ts +10 -4
- package/dist/device/connection.d.ts.map +1 -1
- package/dist/device/connection.js +8 -3
- package/dist/device/connection.js.map +1 -1
- package/dist/device/index.d.ts +2 -2
- package/dist/device/index.d.ts.map +1 -1
- package/dist/device/index.js +1 -1
- package/dist/device/index.js.map +1 -1
- package/dist/device/types.d.ts +3 -1
- package/dist/device/types.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -2
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/use-signal-relay-connection-state.d.ts +40 -0
- package/dist/hooks/use-signal-relay-connection-state.d.ts.map +1 -0
- package/dist/hooks/use-signal-relay-connection-state.js +45 -0
- package/dist/hooks/use-signal-relay-connection-state.js.map +1 -0
- package/dist/hooks/use-signal-relay-lifecycle.d.ts +43 -0
- package/dist/hooks/use-signal-relay-lifecycle.d.ts.map +1 -0
- package/dist/hooks/use-signal-relay-lifecycle.js +38 -0
- package/dist/hooks/use-signal-relay-lifecycle.js.map +1 -0
- package/dist/index.d.ts +18 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/groups/authority-certificate.d.ts +7 -1
- package/dist/internal/groups/authority-certificate.d.ts.map +1 -1
- package/dist/internal/groups/authority-certificate.js +29 -6
- package/dist/internal/groups/authority-certificate.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/certificate.js +2 -2
- package/dist/internal/protocol/sealed-sender/certificate.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.js +5 -5
- package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
- package/dist/internal/sesame/device-registry.d.ts +13 -13
- package/dist/internal/sesame/device-registry.d.ts.map +1 -1
- package/dist/internal/sesame/device-registry.js +20 -20
- package/dist/internal/sesame/device-registry.js.map +1 -1
- package/dist/local/store/receive-work.d.ts +29 -0
- package/dist/local/store/receive-work.d.ts.map +1 -1
- package/dist/local/store/receive-work.js +58 -1
- package/dist/local/store/receive-work.js.map +1 -1
- package/dist/local/store/received-content.d.ts +1 -1
- package/dist/local/store/received-content.d.ts.map +1 -1
- package/dist/local/store/reliability.d.ts +11 -3
- package/dist/local/store/reliability.d.ts.map +1 -1
- package/dist/local/store/reliability.js +4 -0
- package/dist/local/store/reliability.js.map +1 -1
- package/dist/local/store/sqlite/key-storage/index.d.ts +3 -9
- package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -1
- package/dist/local/store/sqlite/key-storage/index.js.map +1 -1
- package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts +1 -7
- package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts.map +1 -1
- package/dist/local/store/sqlite/key-storage/signed-prekeys.js.map +1 -1
- package/dist/local/store/sqlite/models/kyber-prekey.d.ts +4 -9
- package/dist/local/store/sqlite/models/kyber-prekey.d.ts.map +1 -1
- package/dist/local/store/sqlite/models/kyber-prekey.js +4 -1
- package/dist/local/store/sqlite/models/kyber-prekey.js.map +1 -1
- package/dist/local/store/sqlite/store.d.ts.map +1 -1
- package/dist/local/store/sqlite/store.js +1 -2
- package/dist/local/store/sqlite/store.js.map +1 -1
- package/dist/remote/signal-relay/connection-state.d.ts +16 -0
- package/dist/remote/signal-relay/connection-state.d.ts.map +1 -0
- package/dist/remote/{relay → signal-relay}/connection-state.js +1 -1
- package/dist/remote/signal-relay/connection-state.js.map +1 -0
- package/dist/remote/{relay → signal-relay}/device-set.d.ts +3 -3
- package/dist/remote/signal-relay/device-set.d.ts.map +1 -0
- package/dist/remote/{relay → signal-relay}/device-set.js +7 -7
- package/dist/remote/signal-relay/device-set.js.map +1 -0
- package/dist/remote/{relay → signal-relay}/index.d.ts +3 -3
- package/dist/remote/signal-relay/index.d.ts.map +1 -0
- package/dist/remote/{relay → signal-relay}/index.js +2 -2
- package/dist/remote/signal-relay/index.js.map +1 -0
- package/dist/remote/{relay → signal-relay}/request-admission.d.ts +7 -5
- package/dist/remote/signal-relay/request-admission.d.ts.map +1 -0
- package/dist/remote/{relay → signal-relay}/request-admission.js +7 -6
- package/dist/remote/signal-relay/request-admission.js.map +1 -0
- package/dist/remote/{relay → signal-relay}/types.d.ts +30 -12
- package/dist/remote/signal-relay/types.d.ts.map +1 -0
- package/dist/remote/{relay → signal-relay}/types.js +1 -1
- package/dist/remote/signal-relay/types.js.map +1 -0
- package/dist/safety/core.d.ts +1 -1
- package/dist/safety/core.js +1 -1
- package/dist/types/api.d.ts +43 -20
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/errors.d.ts +55 -7
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +61 -8
- package/dist/types/errors.js.map +1 -1
- package/dist/types/renamed-member.d.ts +41 -0
- package/dist/types/renamed-member.d.ts.map +1 -0
- package/dist/types/renamed-member.js +73 -0
- package/dist/types/renamed-member.js.map +1 -0
- package/dist/utils/bounded-fan-out.d.ts +2 -2
- package/dist/utils/bounded-fan-out.d.ts.map +1 -1
- package/dist/utils/bounded-fan-out.js +2 -2
- package/dist/utils/bounded-fan-out.js.map +1 -1
- package/dist/utils/retry.d.ts +3 -3
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +4 -3
- package/dist/utils/retry.js.map +1 -1
- package/docs/ASSURANCE.md +8 -8
- package/docs/CLIENT_COMPOSITION.md +11 -7
- package/docs/DEVIATIONS.md +58 -8
- package/docs/ERROR_HANDLING.md +24 -24
- package/docs/GETTING_STARTED.md +25 -16
- package/docs/INTERFACES.md +5 -5
- package/docs/PACKAGE_SURFACE.md +14 -4
- package/docs/PROTOCOL_POLICY.md +4 -4
- package/docs/RECIPES.md +274 -15
- package/hooks/README.md +11 -11
- package/local/store/expo/README.md +1 -1
- package/local/store/key-value/README.md +2 -2
- package/local/store/node/README.md +1 -1
- package/local/store/react-native/README.md +1 -1
- package/local/store/web/README.md +1 -1
- package/local/store/web-sqlite/README.md +2 -2
- package/package.json +22 -7
- package/remote/README.md +4 -4
- package/remote/object-store/convex-r2/README.md +1 -1
- package/remote/{relay → signal-relay}/README.md +16 -6
- package/dist/client/relay-acceptance.d.ts.map +0 -1
- package/dist/client/relay-acceptance.js.map +0 -1
- package/dist/client/relay-device-refusal.d.ts.map +0 -1
- package/dist/client/relay-device-refusal.js.map +0 -1
- package/dist/client/relay-lifecycle.d.ts.map +0 -1
- package/dist/client/relay-lifecycle.js.map +0 -1
- package/dist/client/relay-protocol.d.ts.map +0 -1
- package/dist/client/relay-protocol.js.map +0 -1
- package/dist/client/relay-receipt-intake.d.ts.map +0 -1
- package/dist/client/relay-receipt-intake.js.map +0 -1
- package/dist/client/relay-receipt-join.d.ts.map +0 -1
- package/dist/client/relay-receipt-join.js.map +0 -1
- package/dist/client/relay-request-deadline.d.ts.map +0 -1
- package/dist/client/relay-request-deadline.js.map +0 -1
- package/dist/client/relay-sealed-route.d.ts.map +0 -1
- package/dist/client/relay-sealed-route.js.map +0 -1
- package/dist/client/relay-subscription.d.ts.map +0 -1
- package/dist/client/relay-subscription.js.map +0 -1
- package/dist/client/relay-work.d.ts.map +0 -1
- package/dist/client/relay-work.js.map +0 -1
- package/dist/hooks/use-relay-connection-state.d.ts +0 -32
- package/dist/hooks/use-relay-connection-state.d.ts.map +0 -1
- package/dist/hooks/use-relay-connection-state.js +0 -31
- package/dist/hooks/use-relay-connection-state.js.map +0 -1
- package/dist/hooks/use-relay-lifecycle.d.ts +0 -36
- package/dist/hooks/use-relay-lifecycle.d.ts.map +0 -1
- package/dist/hooks/use-relay-lifecycle.js +0 -35
- package/dist/hooks/use-relay-lifecycle.js.map +0 -1
- package/dist/remote/relay/connection-state.d.ts +0 -16
- package/dist/remote/relay/connection-state.d.ts.map +0 -1
- package/dist/remote/relay/connection-state.js.map +0 -1
- package/dist/remote/relay/device-set.d.ts.map +0 -1
- package/dist/remote/relay/device-set.js.map +0 -1
- package/dist/remote/relay/index.d.ts.map +0 -1
- package/dist/remote/relay/index.js.map +0 -1
- package/dist/remote/relay/request-admission.d.ts.map +0 -1
- package/dist/remote/relay/request-admission.js.map +0 -1
- package/dist/remote/relay/types.d.ts.map +0 -1
- package/dist/remote/relay/types.js.map +0 -1
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HostedSignalProtocolRelayResumeError } from './hosted-resume-error.js';
|
|
2
2
|
import { hostedAssertionIdentifier } from "./hosted-assertion-id.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { HostedSignalProtocolRelayHttpError } from "./hosted-http-error.js";
|
|
4
|
+
import { submitHostedSignalProtocolRelayDeviceLink } from "./hosted-device-link-transport.js";
|
|
5
5
|
import { utf8Decode, websocketUrl } from "../internal/platform/index.js";
|
|
6
6
|
import AsyncLock from "async-lock";
|
|
7
7
|
import { createCompositeIdentityV1, decodeCompositeIdentityV1, encodeCompositeIdentityV1, } from "../keys/identity.js";
|
|
8
8
|
import { base64ToBytes, bytesToBase64, bytesToUrlSafeBase64, concatBytes, generateRandomBytes, generateUuidV4, sha256, stringToBytes, urlSafeToBase64, } from "../internal/crypto/index.js";
|
|
9
9
|
import { RemoteObjectUploadError } from "../remote/object-store/index.js";
|
|
10
|
-
import {
|
|
10
|
+
import { SignalProtocolRelayConnectionStateOwner } from "../remote/signal-relay/connection-state.js";
|
|
11
11
|
import { presenceHttpBody, } from "./hosted-presence-frames.js";
|
|
12
12
|
import { subscribeHostedMailbox, } from "./hosted-mailbox-subscription.js";
|
|
13
13
|
import { HostedGroupServer } from "./hosted-groups.js";
|
|
14
|
-
import { RELAY_PROTOCOL_VERSION,
|
|
15
|
-
import {
|
|
14
|
+
import { RELAY_PROTOCOL_VERSION, markSignalProtocolRelayAnswerVersion, signalRelayProtocolHeadersFor, throwIfUpgradeRequired, } from "./signal-relay-protocol.js";
|
|
15
|
+
import { HostedSignalProtocolRelayDeviceUnknownError, throwIfDeviceRevoked, } from "./hosted-device-standing.js";
|
|
16
16
|
import { HostedAnonymousDelivery, HostedAnonymousDeliveryError, decodeHostedAnonymousEnvelope, } from "./hosted-anonymous-delivery.js";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { createAdapterSignalProtocolRelayFanOut, rethrowSignalProtocolRelayWorkStopped } from "./signal-relay-work.js";
|
|
18
|
+
import { withSignalProtocolRelayRequestDeadline } from "./signal-relay-request-deadline.js";
|
|
19
19
|
import { applyPreKeyUploads, parseHostedPreKeyStatus, parseStoredPendingPublication, parseStoredPublication, publicationMatchesStatus, registrationPreKey, statusPreKeys, storedPreKey, storedPublication, } from "./hosted-prekey-publication.js";
|
|
20
|
-
import { declareRefusesRemovedDevices,
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
|
|
20
|
+
import { declareRefusesRemovedDevices, markSignalProtocolRelayDeviceRefusal, } from "./signal-relay-device-refusal.js";
|
|
21
|
+
import { onePeriodClosedRetry } from "./signal-relay-period-close.js";
|
|
22
|
+
import { declareComparesDeviceSets, deviceSetRefusal, markDeviceSetRefusal, parseDeviceSetRefusal, } from "../remote/signal-relay/device-set.js";
|
|
23
|
+
import { admitRepeatRequest, markAfterRepeatedRequest, } from "../remote/signal-relay/request-admission.js";
|
|
24
|
+
import { SignalProtocolRelayReceiptInbox, declareSignalProtocolRelayReceiptIntake, decodeSignalProtocolRelayDeliveryReceipts, } from "./signal-relay-receipt-intake.js";
|
|
25
|
+
import { SignalProtocolRelayReceiptJoin, declareSignalProtocolRelayReceiptJoin, } from "./signal-relay-receipt-join.js";
|
|
26
|
+
import { hostedStoreRecordKey, readHostedStoreRecord, writeHostedStoreRecord, } from "./hosted-store-records.js";
|
|
27
|
+
const SESSION_METADATA_PREFIX = {
|
|
28
|
+
current: "signalRelay.session.v2:",
|
|
29
|
+
earlier: "hostedRelay.session.v1:",
|
|
30
|
+
};
|
|
26
31
|
const DEVICE_TOKEN_REFRESH_SECONDS = 60;
|
|
27
32
|
const MAXIMUM_RESPONSE_BYTES = 1024 * 1024;
|
|
28
33
|
const PREKEY_EXPIRY_MILLISECONDS = 30 * 24 * 60 * 60 * 1000;
|
|
@@ -69,7 +74,7 @@ const CONCLUSIVE_REFUSAL_CODES = new Set([
|
|
|
69
74
|
* outage, is not conclusive.
|
|
70
75
|
*/
|
|
71
76
|
function isConclusiveRefusal(error) {
|
|
72
|
-
return (error instanceof
|
|
77
|
+
return (error instanceof HostedSignalProtocolRelayHttpError &&
|
|
73
78
|
!error.retryable &&
|
|
74
79
|
CONCLUSIVE_REFUSAL_CODES.has(error.code));
|
|
75
80
|
}
|
|
@@ -87,7 +92,7 @@ async function withOneUncertainRetry(deliveryClass, post, beforeRepeat) {
|
|
|
87
92
|
}
|
|
88
93
|
catch (error) {
|
|
89
94
|
if (deliveryClass === "ephemeral" ||
|
|
90
|
-
!(error instanceof
|
|
95
|
+
!(error instanceof HostedSignalProtocolRelayHttpError) ||
|
|
91
96
|
error.code !== "DELIVERY_UNCERTAIN") {
|
|
92
97
|
throw error;
|
|
93
98
|
}
|
|
@@ -151,7 +156,7 @@ function decodeBase64Url(value, label) {
|
|
|
151
156
|
throw new Error(`${label} is invalid`);
|
|
152
157
|
}
|
|
153
158
|
}
|
|
154
|
-
function
|
|
159
|
+
function signalProtocolRelayScopeId(connection) {
|
|
155
160
|
return bytesToUrlSafeBase64(connection.relayScopeId);
|
|
156
161
|
}
|
|
157
162
|
function identifiedEndpoint(connection) {
|
|
@@ -159,10 +164,10 @@ function identifiedEndpoint(connection) {
|
|
|
159
164
|
}
|
|
160
165
|
/**
|
|
161
166
|
* Read the body of a Relay answer. An error answer throws, and the error
|
|
162
|
-
* records `
|
|
167
|
+
* records `signalRelayProtocolVersion`, the protocol version of the request that
|
|
163
168
|
* it answers.
|
|
164
169
|
*/
|
|
165
|
-
async function parseResponse(response,
|
|
170
|
+
async function parseResponse(response, signalRelayProtocolVersion) {
|
|
166
171
|
const body = await response.text();
|
|
167
172
|
if (body.length > MAXIMUM_RESPONSE_BYTES) {
|
|
168
173
|
throw new Error("Signal Protocol Relay response is too large");
|
|
@@ -183,11 +188,11 @@ async function parseResponse(response, relayProtocolVersion) {
|
|
|
183
188
|
if (!response.ok) {
|
|
184
189
|
// `UPGRADE_REQUIRED` and `DEVICE_REVOKED` are terminal at any error
|
|
185
190
|
// status, so `authenticatedPost` and every other retry, which matches only
|
|
186
|
-
// a `
|
|
187
|
-
// stays a `
|
|
191
|
+
// a `HostedSignalProtocolRelayHttpError`, never repeat them. `PROTOCOL_UNSUPPORTED`
|
|
192
|
+
// stays a `HostedSignalProtocolRelayHttpError` whose `retryable` is true: the Relay
|
|
188
193
|
// sends it for a version above the newest one that it serves, which
|
|
189
194
|
// happens only after a Relay rollback.
|
|
190
|
-
throwIfUpgradeRequired(response.status, parsed,
|
|
195
|
+
throwIfUpgradeRequired(response.status, parsed, signalRelayProtocolVersion);
|
|
191
196
|
throwIfDeviceRevoked(response.status, parsed);
|
|
192
197
|
const error = record(parsed) && record(parsed.error) ? parsed.error : {};
|
|
193
198
|
const code = typeof error.code === "string" ? error.code : "UNKNOWN";
|
|
@@ -196,10 +201,10 @@ async function parseResponse(response, relayProtocolVersion) {
|
|
|
196
201
|
: "Signal Protocol Relay request failed";
|
|
197
202
|
// A refused declared post names the devices of each account in
|
|
198
203
|
// `details`. The error keeps them for the device-set reconciliation.
|
|
199
|
-
throw
|
|
204
|
+
throw markSignalProtocolRelayAnswerVersion(new HostedSignalProtocolRelayHttpError(response.status, code, message, {
|
|
200
205
|
...(record(error.details) ? { data: { details: error.details } } : {}),
|
|
201
206
|
retryable: error.retryable === true,
|
|
202
|
-
}),
|
|
207
|
+
}), signalRelayProtocolVersion);
|
|
203
208
|
}
|
|
204
209
|
return parsed;
|
|
205
210
|
}
|
|
@@ -208,17 +213,17 @@ async function parseResponse(response, relayProtocolVersion) {
|
|
|
208
213
|
* generation names it. The Relay refuses such a device as NOT_FOUND.
|
|
209
214
|
*/
|
|
210
215
|
function missingDestination(userId, deviceId) {
|
|
211
|
-
return
|
|
216
|
+
return markSignalProtocolRelayDeviceRefusal(new Error("Signal Protocol Relay destination device does not exist"), { code: "NOT_FOUND", userId, deviceId });
|
|
212
217
|
}
|
|
213
|
-
async function postJson(connection,
|
|
218
|
+
async function postJson(connection, signalRelayProtocolVersion, path, body, token) {
|
|
214
219
|
const headers = new Headers({
|
|
215
220
|
accept: "application/json",
|
|
216
221
|
"content-type": "application/json",
|
|
217
|
-
...
|
|
222
|
+
...signalRelayProtocolHeadersFor(signalRelayProtocolVersion),
|
|
218
223
|
});
|
|
219
224
|
if (token !== undefined)
|
|
220
225
|
headers.set("authorization", `Bearer ${token}`);
|
|
221
|
-
return
|
|
226
|
+
return withSignalProtocolRelayRequestDeadline(async (signal) => {
|
|
222
227
|
let response;
|
|
223
228
|
try {
|
|
224
229
|
response = await fetch(`${identifiedEndpoint(connection)}${path}`, {
|
|
@@ -233,7 +238,7 @@ async function postJson(connection, relayProtocolVersion, path, body, token) {
|
|
|
233
238
|
catch (cause) {
|
|
234
239
|
throw new Error("Signal Protocol Relay request could not be completed", { cause });
|
|
235
240
|
}
|
|
236
|
-
return parseResponse(response,
|
|
241
|
+
return parseResponse(response, signalRelayProtocolVersion);
|
|
237
242
|
});
|
|
238
243
|
}
|
|
239
244
|
function serializedPreKey(prekey) {
|
|
@@ -276,10 +281,10 @@ async function registrationMaterialFingerprint(identity, registrationId, prekeys
|
|
|
276
281
|
async function registrationChallenge(request) {
|
|
277
282
|
return sha256(concatBytes(request.assertionPurpose === "recover"
|
|
278
283
|
? RECOVERY_CHALLENGE_LABEL
|
|
279
|
-
: REGISTRATION_CHALLENGE_LABEL, text(
|
|
284
|
+
: REGISTRATION_CHALLENGE_LABEL, text(signalProtocolRelayScopeId(request.connection)), text(await hostedAssertionIdentifier(request.assertion, request.assertionPurpose, request.operationId)), text(request.operationId), text(await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys))));
|
|
280
285
|
}
|
|
281
286
|
async function sessionMetadataKey(connection) {
|
|
282
|
-
return
|
|
287
|
+
return hostedStoreRecordKey(SESSION_METADATA_PREFIX, bytesToUrlSafeBase64(await sha256(concatBytes(stringToBytes(connection.publishableKey), new Uint8Array([0]), connection.relayScopeId))));
|
|
283
288
|
}
|
|
284
289
|
function parseSession(value, connection) {
|
|
285
290
|
let parsed;
|
|
@@ -302,7 +307,7 @@ function parseSession(value, connection) {
|
|
|
302
307
|
parsed.generation < 0 ||
|
|
303
308
|
!Number.isSafeInteger(parsed.mailboxGeneration) ||
|
|
304
309
|
parsed.mailboxGeneration < 0 ||
|
|
305
|
-
parsed.relayScopeId !==
|
|
310
|
+
parsed.relayScopeId !== signalProtocolRelayScopeId(connection)) {
|
|
306
311
|
throw new Error("Stored Signal Protocol Relay session is invalid");
|
|
307
312
|
}
|
|
308
313
|
return {
|
|
@@ -316,6 +321,19 @@ function parseSession(value, connection) {
|
|
|
316
321
|
relayScopeId: parsed.relayScopeId,
|
|
317
322
|
};
|
|
318
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* The scope claim of a device token. Protocol version 3 names the claim
|
|
326
|
+
* `signal_relay_scope_id`, and protocol versions 1 and 2 name it
|
|
327
|
+
* `relay_scope_id`. A token that carries both claims with different values
|
|
328
|
+
* has no scope.
|
|
329
|
+
*/
|
|
330
|
+
function deviceTokenScopeId(claims) {
|
|
331
|
+
const scope = claims.signal_relay_scope_id;
|
|
332
|
+
const earlierScope = claims.relay_scope_id;
|
|
333
|
+
if (scope === undefined)
|
|
334
|
+
return earlierScope;
|
|
335
|
+
return earlierScope === undefined || earlierScope === scope ? scope : undefined;
|
|
336
|
+
}
|
|
319
337
|
function tokenExpiration(token, session) {
|
|
320
338
|
const parts = token.split(".");
|
|
321
339
|
if (parts.length !== 3)
|
|
@@ -327,7 +345,7 @@ function tokenExpiration(token, session) {
|
|
|
327
345
|
claims.device_id !== session.deviceId ||
|
|
328
346
|
claims.generation !== session.generation ||
|
|
329
347
|
claims.mailbox_generation !== session.mailboxGeneration ||
|
|
330
|
-
claims
|
|
348
|
+
deviceTokenScopeId(claims) !== session.relayScopeId ||
|
|
331
349
|
!Number.isSafeInteger(claims.exp)) {
|
|
332
350
|
return 0;
|
|
333
351
|
}
|
|
@@ -337,6 +355,18 @@ function tokenExpiration(token, session) {
|
|
|
337
355
|
return 0;
|
|
338
356
|
}
|
|
339
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* The issuer and audience pairs of a device token. Protocol versions 1 and 2
|
|
360
|
+
* issue the first pair, and protocol version 3 issues the second. The SDK
|
|
361
|
+
* accepts each pair until the Relay retires versions 1 and 2.
|
|
362
|
+
*/
|
|
363
|
+
const SIGNAL_RELAY_DEVICE_TOKEN_ISSUERS = [
|
|
364
|
+
{ issuer: 'open-e2ee-relay', audience: 'open-e2ee-relay-device' },
|
|
365
|
+
{ issuer: 'signal-relay', audience: 'signal-relay-device' },
|
|
366
|
+
];
|
|
367
|
+
function isSignalRelayDeviceTokenIssuer(issuer, audience) {
|
|
368
|
+
return SIGNAL_RELAY_DEVICE_TOKEN_ISSUERS.some((pair) => pair.issuer === issuer && pair.audience === audience);
|
|
369
|
+
}
|
|
340
370
|
function assertLinkToken(session) {
|
|
341
371
|
const parts = session.deviceToken.split('.');
|
|
342
372
|
if (parts.length !== 3)
|
|
@@ -347,7 +377,7 @@ function assertLinkToken(session) {
|
|
|
347
377
|
header.alg !== 'EdDSA' || header.typ !== 'JWT' || typeof header.kid !== 'string' || !header.kid ||
|
|
348
378
|
decodeBase64Url(parts[2], 'Device token signature').length !== 64 ||
|
|
349
379
|
!record(claims) || typeof claims.jti !== 'string' || !claims.jti ||
|
|
350
|
-
claims.iss
|
|
380
|
+
!isSignalRelayDeviceTokenIssuer(claims.iss, claims.aud) || claims.token_use !== 'device' ||
|
|
351
381
|
typeof claims.account_state_id !== 'string' || !claims.account_state_id ||
|
|
352
382
|
!Number.isSafeInteger(claims.iat) || claims.iat < 0 ||
|
|
353
383
|
tokenExpiration(session.deviceToken, session) <= claims.iat)
|
|
@@ -417,13 +447,13 @@ function decodeDeliveryWire(value) {
|
|
|
417
447
|
version: DELIVERY_WIRE_VERSION,
|
|
418
448
|
};
|
|
419
449
|
}
|
|
420
|
-
export class
|
|
450
|
+
export class HostedSignalProtocolRelayHttpTransport {
|
|
421
451
|
connection;
|
|
422
452
|
storage;
|
|
423
453
|
deviceAuthentication;
|
|
424
454
|
session;
|
|
425
455
|
persistRefreshedToken;
|
|
426
|
-
|
|
456
|
+
signalRelayProtocolVersion;
|
|
427
457
|
groups;
|
|
428
458
|
groupServer;
|
|
429
459
|
anonymousDelivery;
|
|
@@ -435,22 +465,22 @@ export class HostedRelayHttpTransport {
|
|
|
435
465
|
ephemeralAcknowledgments = new Set();
|
|
436
466
|
subscription;
|
|
437
467
|
subscriptionGeneration = 0;
|
|
438
|
-
connectionState = new
|
|
468
|
+
connectionState = new SignalProtocolRelayConnectionStateOwner();
|
|
439
469
|
presenceListeners = new Set();
|
|
440
|
-
receiptInbox = new
|
|
441
|
-
receiptJoin = new
|
|
470
|
+
receiptInbox = new SignalProtocolRelayReceiptInbox();
|
|
471
|
+
receiptJoin = new SignalProtocolRelayReceiptJoin();
|
|
442
472
|
constructor(connection, storage, deviceAuthentication, session, persistRefreshedToken = true,
|
|
443
473
|
/**
|
|
444
474
|
* @internal The Relay protocol version of the client that owns this
|
|
445
475
|
* transport. Every carrier of the client sends it.
|
|
446
476
|
*/
|
|
447
|
-
|
|
477
|
+
signalRelayProtocolVersion = RELAY_PROTOCOL_VERSION) {
|
|
448
478
|
this.connection = connection;
|
|
449
479
|
this.storage = storage;
|
|
450
480
|
this.deviceAuthentication = deviceAuthentication;
|
|
451
481
|
this.session = session;
|
|
452
482
|
this.persistRefreshedToken = persistRefreshedToken;
|
|
453
|
-
this.
|
|
483
|
+
this.signalRelayProtocolVersion = signalRelayProtocolVersion;
|
|
454
484
|
// The Relay refuses a removed device's mailbox on every send path before
|
|
455
485
|
// its device list shows the removal, so a direct send may post first.
|
|
456
486
|
declareRefusesRemovedDevices(this);
|
|
@@ -460,16 +490,16 @@ export class HostedRelayHttpTransport {
|
|
|
460
490
|
declareComparesDeviceSets(this);
|
|
461
491
|
// The Relay sends Relay delivery receipts to the sender, and replies to
|
|
462
492
|
// each acknowledgment with the messages whose receipt it owns.
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.groups = new HostedGroupServer(connection,
|
|
493
|
+
declareSignalProtocolRelayReceiptIntake(this, this.receiptInbox);
|
|
494
|
+
declareSignalProtocolRelayReceiptJoin(this, this.receiptJoin);
|
|
495
|
+
this.groups = new HostedGroupServer(connection, signalRelayProtocolVersion);
|
|
466
496
|
this.groupServer = {
|
|
467
497
|
server: this.groups,
|
|
468
498
|
issueAuthCredential: (userId, authorityKeyId) => this.issueAuthCredential(userId, authorityKeyId),
|
|
469
499
|
issueProfileKeyCredential: (userId, request, authorityKeyId) => this.issueProfileKeyCredential(userId, request, authorityKeyId),
|
|
470
500
|
setUnidentifiedAccessKey: (userId, accessKey) => this.setUnidentifiedAccessKey(userId, accessKey),
|
|
471
501
|
};
|
|
472
|
-
this.fanOut =
|
|
502
|
+
this.fanOut = createAdapterSignalProtocolRelayFanOut(this);
|
|
473
503
|
this.anonymousDelivery = new HostedAnonymousDelivery(connection, this.fanOut, async (accountAddress, deviceId, declaredDeviceIds) => {
|
|
474
504
|
const key = `${accountAddress}\0${deviceId}`;
|
|
475
505
|
if (!this.destinationGenerations.has(key))
|
|
@@ -482,7 +512,7 @@ export class HostedRelayHttpTransport {
|
|
|
482
512
|
if (generation === undefined)
|
|
483
513
|
throw missingDestination(accountAddress, deviceId);
|
|
484
514
|
return { accountAddress, deviceId, generation };
|
|
485
|
-
}, (clientMessageId, request) => admitRepeatRequest(this, clientMessageId, request),
|
|
515
|
+
}, (clientMessageId, request) => admitRepeatRequest(this, clientMessageId, request), signalRelayProtocolVersion, ({ accountAddress, deviceId, generation }) => this.destinationRecovered(accountAddress, deviceId, generation, true));
|
|
486
516
|
}
|
|
487
517
|
get accountId() {
|
|
488
518
|
return this.session.canonicalAccountId;
|
|
@@ -524,7 +554,7 @@ export class HostedRelayHttpTransport {
|
|
|
524
554
|
return await this.commitObjectUpload(objectId);
|
|
525
555
|
}
|
|
526
556
|
catch (error) {
|
|
527
|
-
if (error instanceof
|
|
557
|
+
if (error instanceof HostedSignalProtocolRelayHttpError &&
|
|
528
558
|
error.code === "UPLOAD_INCOMPLETE")
|
|
529
559
|
return null;
|
|
530
560
|
throw this.uploadError(error, "settlement");
|
|
@@ -538,7 +568,7 @@ export class HostedRelayHttpTransport {
|
|
|
538
568
|
},
|
|
539
569
|
};
|
|
540
570
|
uploadError(error, phase) {
|
|
541
|
-
if (!(error instanceof
|
|
571
|
+
if (!(error instanceof HostedSignalProtocolRelayHttpError))
|
|
542
572
|
return error;
|
|
543
573
|
switch (error.code) {
|
|
544
574
|
case "UPLOAD_EXPIRED":
|
|
@@ -563,7 +593,7 @@ export class HostedRelayHttpTransport {
|
|
|
563
593
|
}
|
|
564
594
|
}
|
|
565
595
|
async persistSession() {
|
|
566
|
-
await this.storage
|
|
596
|
+
await writeHostedStoreRecord(this.storage, await sessionMetadataKey(this.connection), JSON.stringify(this.session));
|
|
567
597
|
}
|
|
568
598
|
async commitObjectUpload(objectId) {
|
|
569
599
|
const value = await this.authenticatedPost("/objects/commit-upload", {
|
|
@@ -591,7 +621,7 @@ export class HostedRelayHttpTransport {
|
|
|
591
621
|
const proof = await this.deviceAuthentication.signChallenge(challenge);
|
|
592
622
|
let value;
|
|
593
623
|
try {
|
|
594
|
-
value = await postJson(this.connection, this.
|
|
624
|
+
value = await postJson(this.connection, this.signalRelayProtocolVersion, "/identity/token", {
|
|
595
625
|
accountAddress: this.session.canonicalAccountId,
|
|
596
626
|
// The Relay checks this key against the keys that a recovery revoked.
|
|
597
627
|
deviceAuthenticationPublicKey: bytesToBase64(this.deviceAuthentication.publicKey),
|
|
@@ -604,10 +634,10 @@ export class HostedRelayHttpTransport {
|
|
|
604
634
|
}
|
|
605
635
|
catch (error) {
|
|
606
636
|
// A token refusal names this device, so it is not a
|
|
607
|
-
// `
|
|
637
|
+
// `HostedSignalProtocolRelayHttpError`. A catch that reads `NOT_FOUND` as a missing
|
|
608
638
|
// destination cannot take it.
|
|
609
|
-
if (error instanceof
|
|
610
|
-
throw new
|
|
639
|
+
if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND")
|
|
640
|
+
throw new HostedSignalProtocolRelayDeviceUnknownError(error.status, error.message);
|
|
611
641
|
throw error;
|
|
612
642
|
}
|
|
613
643
|
if (!record(value) || typeof value.deviceToken !== "string") {
|
|
@@ -647,20 +677,20 @@ export class HostedRelayHttpTransport {
|
|
|
647
677
|
throw new Error('Signal Protocol Relay returned an invalid device token');
|
|
648
678
|
return body(claims.jti);
|
|
649
679
|
};
|
|
650
|
-
const value = await
|
|
680
|
+
const value = await submitHostedSignalProtocolRelayDeviceLink(request, {
|
|
651
681
|
relayScopeId: this.session.relayScopeId,
|
|
652
682
|
materialFingerprint,
|
|
653
683
|
signalRegistration: signalRegistration(request.signalIdentity, request.registrationId, request.registrationPreKeys),
|
|
654
684
|
post: async (body) => {
|
|
655
685
|
let token = await this.token();
|
|
656
686
|
try {
|
|
657
|
-
return await postJson(this.connection, this.
|
|
687
|
+
return await postJson(this.connection, this.signalRelayProtocolVersion, '/identity/devices/link', await bodyFor(body, token), token);
|
|
658
688
|
}
|
|
659
689
|
catch (error) {
|
|
660
|
-
if (!(error instanceof
|
|
690
|
+
if (!(error instanceof HostedSignalProtocolRelayHttpError) || error.code !== 'TOKEN_INVALID')
|
|
661
691
|
throw error;
|
|
662
692
|
token = await this.token(true);
|
|
663
|
-
return postJson(this.connection, this.
|
|
693
|
+
return postJson(this.connection, this.signalRelayProtocolVersion, '/identity/devices/link', await bodyFor(body, token), token);
|
|
664
694
|
}
|
|
665
695
|
},
|
|
666
696
|
});
|
|
@@ -684,7 +714,7 @@ export class HostedRelayHttpTransport {
|
|
|
684
714
|
throw new Error('Signal Protocol Relay returned an invalid managed device link');
|
|
685
715
|
assertLinkToken(session);
|
|
686
716
|
const key = await sessionMetadataKey(this.connection);
|
|
687
|
-
const stored = await storage
|
|
717
|
+
const stored = await readHostedStoreRecord(storage, key);
|
|
688
718
|
if (stored !== null) {
|
|
689
719
|
const existing = parseSession(stored, this.connection);
|
|
690
720
|
assertLinkToken(existing);
|
|
@@ -698,22 +728,24 @@ export class HostedRelayHttpTransport {
|
|
|
698
728
|
throw new Error('Stored Signal Protocol Relay link session conflicts with the retained attempt');
|
|
699
729
|
session = existing;
|
|
700
730
|
}
|
|
701
|
-
const transport = new
|
|
731
|
+
const transport = new HostedSignalProtocolRelayHttpTransport(this.connection, storage, request.newDeviceAuthentication, session, true, this.signalRelayProtocolVersion);
|
|
702
732
|
// Persist the complete shape before synchronization or token renewal can fail.
|
|
703
733
|
try {
|
|
704
|
-
await storage
|
|
734
|
+
await writeHostedStoreRecord(storage, key, JSON.stringify(session));
|
|
705
735
|
await transport.ensureAuthenticated();
|
|
706
736
|
}
|
|
707
737
|
catch (error) {
|
|
708
738
|
// A renewal refusal cannot prove that the accepted link had no effect.
|
|
709
|
-
if (error instanceof
|
|
739
|
+
if (error instanceof HostedSignalProtocolRelayHttpError && !error.retryable &&
|
|
710
740
|
(error.code === 'KEY_PROOF_INVALID' || error.code === 'CONFLICT'))
|
|
711
741
|
throw new Error('Signal Protocol Relay accepted the link but session adoption failed', { cause: error });
|
|
712
742
|
throw error;
|
|
713
743
|
}
|
|
744
|
+
const scopeId = this.connection.relayScopeId.slice();
|
|
714
745
|
return {
|
|
715
746
|
canonicalAccountId: session.canonicalAccountId, deviceId: session.deviceId,
|
|
716
|
-
|
|
747
|
+
signalProtocolRelayScopeId: scopeId, relayScopeId: scopeId,
|
|
748
|
+
signalProtocolRelay: transport, relay: transport,
|
|
717
749
|
remoteObjectStore: transport.objectStore, transport,
|
|
718
750
|
accountPreserved: true, protocolStateCopied: false,
|
|
719
751
|
};
|
|
@@ -726,10 +758,10 @@ export class HostedRelayHttpTransport {
|
|
|
726
758
|
async authenticatedPost(path, body, beforeRepeat) {
|
|
727
759
|
let token = await this.token();
|
|
728
760
|
try {
|
|
729
|
-
return await postJson(this.connection, this.
|
|
761
|
+
return await postJson(this.connection, this.signalRelayProtocolVersion, path, body, token);
|
|
730
762
|
}
|
|
731
763
|
catch (error) {
|
|
732
|
-
if (!(error instanceof
|
|
764
|
+
if (!(error instanceof HostedSignalProtocolRelayHttpError) ||
|
|
733
765
|
error.code !== "TOKEN_INVALID") {
|
|
734
766
|
throw error;
|
|
735
767
|
}
|
|
@@ -740,7 +772,7 @@ export class HostedRelayHttpTransport {
|
|
|
740
772
|
catch {
|
|
741
773
|
throw error;
|
|
742
774
|
}
|
|
743
|
-
return postJson(this.connection, this.
|
|
775
|
+
return postJson(this.connection, this.signalRelayProtocolVersion, path, body, token);
|
|
744
776
|
}
|
|
745
777
|
}
|
|
746
778
|
assertCurrentIdentity(userId, deviceId, identityType = "aci") {
|
|
@@ -764,6 +796,30 @@ export class HostedRelayHttpTransport {
|
|
|
764
796
|
}
|
|
765
797
|
return lookup;
|
|
766
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* The Relay refused a post to this mailbox generation as NOT_FOUND. True
|
|
801
|
+
* when a new read of the device directory lists the device at another
|
|
802
|
+
* mailbox generation: a recovery replaced the device, so the refusal is
|
|
803
|
+
* the stale-device refusal of the posted generation. False when the read
|
|
804
|
+
* fails, or the directory does not list the device, or lists it at the
|
|
805
|
+
* posted generation. The read refills the destination cache, so a repost
|
|
806
|
+
* goes to the listed generation. An identified post runs in a slot of the
|
|
807
|
+
* relay request bound, so it reads without a slot. A sealed post holds no
|
|
808
|
+
* slot, so it reads under the bound.
|
|
809
|
+
*/
|
|
810
|
+
async destinationRecovered(userId, deviceId, postedGeneration, underBound) {
|
|
811
|
+
try {
|
|
812
|
+
await (underBound
|
|
813
|
+
? this.fanOut.request(() => this.directory(userId))
|
|
814
|
+
: this.directory(userId));
|
|
815
|
+
}
|
|
816
|
+
catch (error) {
|
|
817
|
+
rethrowSignalProtocolRelayWorkStopped(error);
|
|
818
|
+
return false;
|
|
819
|
+
}
|
|
820
|
+
const listed = this.destinationGenerations.get(`${userId}\0${String(deviceId)}`);
|
|
821
|
+
return listed !== undefined && listed !== postedGeneration;
|
|
822
|
+
}
|
|
767
823
|
async directory(userId) {
|
|
768
824
|
const value = await this.authenticatedPost("/identity/devices", {
|
|
769
825
|
accountAddress: userId,
|
|
@@ -822,7 +878,7 @@ export class HostedRelayHttpTransport {
|
|
|
822
878
|
? this.session.mailboxGeneration
|
|
823
879
|
: this.destinationGenerations.get(key);
|
|
824
880
|
if (generation === undefined) {
|
|
825
|
-
throw new
|
|
881
|
+
throw new HostedSignalProtocolRelayHttpError(404, "NOT_FOUND", "Signal Protocol Relay destination device does not exist");
|
|
826
882
|
}
|
|
827
883
|
return this.authenticatedPost(path, {
|
|
828
884
|
accountAddress: userId,
|
|
@@ -837,7 +893,7 @@ export class HostedRelayHttpTransport {
|
|
|
837
893
|
}
|
|
838
894
|
catch (error) {
|
|
839
895
|
if (!cached ||
|
|
840
|
-
!(error instanceof
|
|
896
|
+
!(error instanceof HostedSignalProtocolRelayHttpError) ||
|
|
841
897
|
error.code !== "NOT_FOUND") {
|
|
842
898
|
throw error;
|
|
843
899
|
}
|
|
@@ -871,7 +927,7 @@ export class HostedRelayHttpTransport {
|
|
|
871
927
|
* publication returns after that one read.
|
|
872
928
|
*/
|
|
873
929
|
async publishCurrentPrekeys(plan) {
|
|
874
|
-
await hostedPreKeyPublicationLock.acquire(await sessionMetadataKey(this.connection), async () => {
|
|
930
|
+
await hostedPreKeyPublicationLock.acquire((await sessionMetadataKey(this.connection)).current, async () => {
|
|
875
931
|
const current = await this.currentIdentity();
|
|
876
932
|
let status = await this.prekeyStatus(this.session.canonicalAccountId, this.session.deviceId);
|
|
877
933
|
if (status.authorityGeneration !== this.session.generation ||
|
|
@@ -988,7 +1044,7 @@ export class HostedRelayHttpTransport {
|
|
|
988
1044
|
messages: value.messages.map((candidate) => this.incomingEnvelope(candidate)),
|
|
989
1045
|
receipts: value.receipts === undefined
|
|
990
1046
|
? []
|
|
991
|
-
:
|
|
1047
|
+
: decodeSignalProtocolRelayDeliveryReceipts(value.receipts),
|
|
992
1048
|
...(value.nextCursor === undefined
|
|
993
1049
|
? {}
|
|
994
1050
|
: { nextCursor: value.nextCursor }),
|
|
@@ -1056,7 +1112,7 @@ export class HostedRelayHttpTransport {
|
|
|
1056
1112
|
if (proof.byteLength !== 64)
|
|
1057
1113
|
throw new Error("Signal Protocol Relay certificate proof is invalid");
|
|
1058
1114
|
try {
|
|
1059
|
-
const result = await postJson(this.connection, this.
|
|
1115
|
+
const result = await postJson(this.connection, this.signalRelayProtocolVersion, "/certificates/issue", {
|
|
1060
1116
|
publishableKey: this.connection.publishableKey,
|
|
1061
1117
|
nonce,
|
|
1062
1118
|
deviceProof: bytesToBase64(proof),
|
|
@@ -1070,7 +1126,7 @@ export class HostedRelayHttpTransport {
|
|
|
1070
1126
|
}
|
|
1071
1127
|
catch (error) {
|
|
1072
1128
|
if (attempt > 0 ||
|
|
1073
|
-
!(error instanceof
|
|
1129
|
+
!(error instanceof HostedSignalProtocolRelayHttpError) ||
|
|
1074
1130
|
error.code !== "TOKEN_INVALID")
|
|
1075
1131
|
throw error;
|
|
1076
1132
|
}
|
|
@@ -1233,7 +1289,7 @@ export class HostedRelayHttpTransport {
|
|
|
1233
1289
|
for (let start = MAXIMUM_ACKNOWLEDGMENT_IDS; start < receiptIds.length; start += MAXIMUM_ACKNOWLEDGMENT_IDS)
|
|
1234
1290
|
await this.acknowledge([], receiptIds.slice(start, start + MAXIMUM_ACKNOWLEDGMENT_IDS));
|
|
1235
1291
|
}
|
|
1236
|
-
|
|
1292
|
+
receiveSignalProtocolRelayReceipt(receipt) {
|
|
1237
1293
|
return this.receiptInbox.handOff(receipt);
|
|
1238
1294
|
}
|
|
1239
1295
|
async createObjectUpload(input) {
|
|
@@ -1273,7 +1329,7 @@ export class HostedRelayHttpTransport {
|
|
|
1273
1329
|
expiresAt: tokenExpiration(token, this.session) * 1_000,
|
|
1274
1330
|
headers: {
|
|
1275
1331
|
authorization: `Bearer ${token}`,
|
|
1276
|
-
...
|
|
1332
|
+
...signalRelayProtocolHeadersFor(this.signalRelayProtocolVersion),
|
|
1277
1333
|
"x-open-e2ee-publishable-key": this.connection.publishableKey,
|
|
1278
1334
|
"x-open-e2ee-object-id": input.objectId,
|
|
1279
1335
|
"x-open-e2ee-attachment-capability": input.readCapability,
|
|
@@ -1294,7 +1350,7 @@ export class HostedRelayHttpTransport {
|
|
|
1294
1350
|
generation = this.destinationGenerations.get(key);
|
|
1295
1351
|
}
|
|
1296
1352
|
if (generation === undefined && envelope.declaredDeviceIds !== undefined) {
|
|
1297
|
-
throw markDeviceSetRefusal(new
|
|
1353
|
+
throw markDeviceSetRefusal(new HostedSignalProtocolRelayHttpError(409, "DEVICE_SET_MISMATCH", "The declared device set differs from the device directory"), this.directoryDeviceSetRefusal(envelope.targetUserId, envelope.declaredDeviceIds));
|
|
1298
1354
|
}
|
|
1299
1355
|
if (generation === undefined)
|
|
1300
1356
|
throw missingDestination(envelope.targetUserId, envelope.targetDeviceId);
|
|
@@ -1307,7 +1363,7 @@ export class HostedRelayHttpTransport {
|
|
|
1307
1363
|
},
|
|
1308
1364
|
];
|
|
1309
1365
|
let value;
|
|
1310
|
-
let
|
|
1366
|
+
let uncertainRepeat = false;
|
|
1311
1367
|
// Each repeat request meets the checks that the owner of the post
|
|
1312
1368
|
// registered under its message ID, and names its device and the answer
|
|
1313
1369
|
// that it follows.
|
|
@@ -1316,59 +1372,83 @@ export class HostedRelayHttpTransport {
|
|
|
1316
1372
|
deviceId: envelope.targetDeviceId,
|
|
1317
1373
|
after,
|
|
1318
1374
|
});
|
|
1375
|
+
const repeatAfterUncertain = async () => {
|
|
1376
|
+
await beforeRepeat("uncertain")();
|
|
1377
|
+
uncertainRepeat = true;
|
|
1378
|
+
};
|
|
1379
|
+
// A PERIOD_CLOSED answer proves that the Relay stored nothing, so the
|
|
1380
|
+
// same request goes once more, in the next period.
|
|
1381
|
+
const periodClosedRetry = onePeriodClosedRetry();
|
|
1319
1382
|
try {
|
|
1320
|
-
value = await withOneUncertainRetry(envelope.deliveryClass, () => {
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
...(deviceSets === undefined ? {} : { deviceSets }),
|
|
1338
|
-
}, beforeRepeat("token"));
|
|
1339
|
-
}, beforeRepeat("uncertain"));
|
|
1383
|
+
value = await withOneUncertainRetry(envelope.deliveryClass, () => periodClosedRetry(() => this.authenticatedPost("/delivery/send", {
|
|
1384
|
+
contentKind: envelope.contentKind ?? "message",
|
|
1385
|
+
deliveryClass: envelope.deliveryClass,
|
|
1386
|
+
destination: {
|
|
1387
|
+
accountAddress: envelope.targetUserId,
|
|
1388
|
+
deviceId: envelope.targetDeviceId,
|
|
1389
|
+
generation,
|
|
1390
|
+
},
|
|
1391
|
+
envelope: bytesToBase64(encodeDeliveryWire(envelope)),
|
|
1392
|
+
messageId,
|
|
1393
|
+
operationEpochMilliseconds: envelope.operationEpochMilliseconds ?? envelope.timestamp,
|
|
1394
|
+
publishableKey: this.connection.publishableKey,
|
|
1395
|
+
...(envelope.recipientRegistrationId === undefined
|
|
1396
|
+
? {}
|
|
1397
|
+
: { recipientRegistrationId: envelope.recipientRegistrationId }),
|
|
1398
|
+
...(deviceSets === undefined ? {} : { deviceSets }),
|
|
1399
|
+
}, beforeRepeat("token")), beforeRepeat("period-closed")), repeatAfterUncertain);
|
|
1340
1400
|
}
|
|
1341
1401
|
catch (error) {
|
|
1342
1402
|
// After an uncertain answer, the first request can have stored the
|
|
1343
1403
|
// copy, so the answer to the repeat tells nothing about the post.
|
|
1344
|
-
const answer = (failure) =>
|
|
1404
|
+
const answer = (failure) => uncertainRepeat ? markAfterRepeatedRequest(failure) : failure;
|
|
1345
1405
|
const device = {
|
|
1346
1406
|
userId: envelope.targetUserId,
|
|
1347
1407
|
deviceId: envelope.targetDeviceId,
|
|
1348
1408
|
};
|
|
1349
|
-
if (deviceSets !== undefined && error instanceof
|
|
1409
|
+
if (deviceSets !== undefined && error instanceof HostedSignalProtocolRelayHttpError) {
|
|
1350
1410
|
const refusal = parseDeviceSetRefusal(error.code, error.data?.details);
|
|
1351
1411
|
if (refusal !== undefined) {
|
|
1352
1412
|
this.forgetDestinationGenerations(refusal.accounts);
|
|
1353
1413
|
throw answer(markDeviceSetRefusal(error, refusal));
|
|
1354
1414
|
}
|
|
1355
1415
|
}
|
|
1356
|
-
|
|
1416
|
+
const staleDevice = (stale) => answer(markSignalProtocolRelayDeviceRefusal(new HostedSignalProtocolRelayHttpError(stale.status, "STALE_DEVICE", stale.message, {
|
|
1417
|
+
data: {
|
|
1418
|
+
code: "STALE_DEVICE",
|
|
1419
|
+
message: stale.message,
|
|
1420
|
+
reason: "device_reinstalled",
|
|
1421
|
+
staleDevices: [envelope.targetDeviceId],
|
|
1422
|
+
},
|
|
1423
|
+
retryable: stale.retryable,
|
|
1424
|
+
}), { code: "STALE_DEVICE", ...device }));
|
|
1425
|
+
if (error instanceof HostedSignalProtocolRelayHttpError &&
|
|
1357
1426
|
error.code === "STALE_DEVICE") {
|
|
1358
|
-
throw
|
|
1359
|
-
data: {
|
|
1360
|
-
code: "STALE_DEVICE",
|
|
1361
|
-
message: error.message,
|
|
1362
|
-
reason: "device_reinstalled",
|
|
1363
|
-
staleDevices: [envelope.targetDeviceId],
|
|
1364
|
-
},
|
|
1365
|
-
retryable: error.retryable,
|
|
1366
|
-
}), { code: "STALE_DEVICE", ...device }));
|
|
1427
|
+
throw staleDevice(error);
|
|
1367
1428
|
}
|
|
1368
1429
|
// Only the Relay's own error body names NOT_FOUND. A 404 without it
|
|
1369
1430
|
// fails to parse or carries no code, so it is not a device refusal.
|
|
1370
|
-
if (error instanceof
|
|
1371
|
-
|
|
1431
|
+
if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND") {
|
|
1432
|
+
// A recovery retired the posted generation. As for a stale device,
|
|
1433
|
+
// the send archives the session and posts to the recovered device.
|
|
1434
|
+
// A declared post gets the declared STALE_DEVICE that the Relay
|
|
1435
|
+
// gives for a changed registration.
|
|
1436
|
+
if (await this.destinationRecovered(envelope.targetUserId, envelope.targetDeviceId, generation, false)) {
|
|
1437
|
+
const stale = staleDevice(error);
|
|
1438
|
+
throw deviceSets === undefined
|
|
1439
|
+
? stale
|
|
1440
|
+
: markDeviceSetRefusal(stale, {
|
|
1441
|
+
kind: "stale",
|
|
1442
|
+
accounts: [
|
|
1443
|
+
{
|
|
1444
|
+
userId: envelope.targetUserId,
|
|
1445
|
+
staleDeviceIds: [envelope.targetDeviceId],
|
|
1446
|
+
},
|
|
1447
|
+
],
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
throw answer(markSignalProtocolRelayDeviceRefusal(error, { code: "NOT_FOUND", ...device }));
|
|
1451
|
+
}
|
|
1372
1452
|
throw answer(error);
|
|
1373
1453
|
}
|
|
1374
1454
|
if (!record(value) ||
|
|
@@ -1390,7 +1470,7 @@ export class HostedRelayHttpTransport {
|
|
|
1390
1470
|
serverTimestamp: typeof value.enqueuedAt === "number"
|
|
1391
1471
|
? value.enqueuedAt
|
|
1392
1472
|
: envelope.timestamp,
|
|
1393
|
-
...(typeof value.duplicate === "boolean" &&
|
|
1473
|
+
...(typeof value.duplicate === "boolean" && !uncertainRepeat
|
|
1394
1474
|
? { duplicate: value.duplicate }
|
|
1395
1475
|
: {}),
|
|
1396
1476
|
...(typeof value.expiresAt === "number"
|
|
@@ -1408,7 +1488,7 @@ export class HostedRelayHttpTransport {
|
|
|
1408
1488
|
const generation = ++this.subscriptionGeneration;
|
|
1409
1489
|
const subscription = subscribeHostedMailbox({
|
|
1410
1490
|
...options,
|
|
1411
|
-
|
|
1491
|
+
signalRelayProtocolVersion: this.signalRelayProtocolVersion,
|
|
1412
1492
|
onConnectionState: (state, reason) => {
|
|
1413
1493
|
if (generation === this.subscriptionGeneration)
|
|
1414
1494
|
this.connectionState.move(state, reason);
|
|
@@ -1432,14 +1512,7 @@ export class HostedRelayHttpTransport {
|
|
|
1432
1512
|
const previous = this.session.deviceToken;
|
|
1433
1513
|
const token = await this.token();
|
|
1434
1514
|
const url = websocketUrl(`${identifiedEndpoint(this.connection)}/mailbox/connect`, [["publishableKey", this.connection.publishableKey]]);
|
|
1435
|
-
return {
|
|
1436
|
-
url,
|
|
1437
|
-
token,
|
|
1438
|
-
renewAt: (tokenExpiration(token, this.session) -
|
|
1439
|
-
DEVICE_TOKEN_REFRESH_SECONDS) *
|
|
1440
|
-
1_000,
|
|
1441
|
-
refreshed: token !== previous,
|
|
1442
|
-
};
|
|
1515
|
+
return { url, token, refreshed: token !== previous };
|
|
1443
1516
|
},
|
|
1444
1517
|
isConclusiveRefusal,
|
|
1445
1518
|
decodeDurable: (message) => this.incomingEnvelope(message),
|
|
@@ -1489,12 +1562,20 @@ export class HostedRelayHttpTransport {
|
|
|
1489
1562
|
subscription.unsubscribe();
|
|
1490
1563
|
};
|
|
1491
1564
|
}
|
|
1492
|
-
get
|
|
1565
|
+
get signalProtocolRelayConnectionState() {
|
|
1493
1566
|
return this.connectionState.current;
|
|
1494
1567
|
}
|
|
1495
|
-
|
|
1568
|
+
subscribeSignalProtocolRelayConnectionState(listener) {
|
|
1496
1569
|
return this.connectionState.subscribe(listener);
|
|
1497
1570
|
}
|
|
1571
|
+
/** @deprecated Use `signalProtocolRelayConnectionState`. SDK 15.0.0 removes this name. */
|
|
1572
|
+
get relayConnectionState() {
|
|
1573
|
+
return this.signalProtocolRelayConnectionState;
|
|
1574
|
+
}
|
|
1575
|
+
/** @deprecated Use `subscribeSignalProtocolRelayConnectionState`. SDK 15.0.0 removes this name. */
|
|
1576
|
+
subscribeRelayConnectionState(listener) {
|
|
1577
|
+
return this.subscribeSignalProtocolRelayConnectionState(listener);
|
|
1578
|
+
}
|
|
1498
1579
|
/**
|
|
1499
1580
|
* Acknowledges over the live mailbox socket when one exists, in one frame per
|
|
1500
1581
|
* drained burst, and over HTTP otherwise.
|
|
@@ -1539,7 +1620,7 @@ export class HostedRelayHttpTransport {
|
|
|
1539
1620
|
.identityPublicMaterial);
|
|
1540
1621
|
}
|
|
1541
1622
|
catch (error) {
|
|
1542
|
-
if (error instanceof
|
|
1623
|
+
if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND")
|
|
1543
1624
|
return null;
|
|
1544
1625
|
throw error;
|
|
1545
1626
|
}
|
|
@@ -1556,7 +1637,7 @@ export class HostedRelayHttpTransport {
|
|
|
1556
1637
|
value = await this.prekeyPost("/prekeys/consume", userId, deviceId, identityType);
|
|
1557
1638
|
}
|
|
1558
1639
|
catch (error) {
|
|
1559
|
-
if (error instanceof
|
|
1640
|
+
if (error instanceof HostedSignalProtocolRelayHttpError && error.code === "NOT_FOUND")
|
|
1560
1641
|
return null;
|
|
1561
1642
|
throw error;
|
|
1562
1643
|
}
|
|
@@ -1708,7 +1789,7 @@ export class HostedRelayHttpTransport {
|
|
|
1708
1789
|
}
|
|
1709
1790
|
}
|
|
1710
1791
|
}
|
|
1711
|
-
export async function
|
|
1792
|
+
export async function bootstrapHostedSignalProtocolRelayTransport(request) {
|
|
1712
1793
|
const proof = await request.deviceAuthentication.signChallenge(await registrationChallenge(request));
|
|
1713
1794
|
// A new client starts at the default version, which the transport built
|
|
1714
1795
|
// below also takes.
|
|
@@ -1739,7 +1820,7 @@ export async function bootstrapHostedRelayTransport(request) {
|
|
|
1739
1820
|
preKeyPublication: storedPublication(generation, materialFingerprint, request.operationId, 0, request.registrationPreKeys),
|
|
1740
1821
|
relayScopeId: requiredString(value, "relayScopeId"),
|
|
1741
1822
|
};
|
|
1742
|
-
if (session.relayScopeId !==
|
|
1823
|
+
if (session.relayScopeId !== signalProtocolRelayScopeId(request.connection) ||
|
|
1743
1824
|
session.deviceId < 1 ||
|
|
1744
1825
|
session.generation < 0 ||
|
|
1745
1826
|
session.mailboxGeneration < 0 ||
|
|
@@ -1747,31 +1828,34 @@ export async function bootstrapHostedRelayTransport(request) {
|
|
|
1747
1828
|
Math.floor(Date.now() / 1_000)) {
|
|
1748
1829
|
throw new Error("Signal Protocol Relay returned an invalid registration");
|
|
1749
1830
|
}
|
|
1750
|
-
await request.storage
|
|
1751
|
-
const transport = new
|
|
1831
|
+
await writeHostedStoreRecord(request.storage, await sessionMetadataKey(request.connection), JSON.stringify(session));
|
|
1832
|
+
const transport = new HostedSignalProtocolRelayHttpTransport(request.connection, request.storage, request.deviceAuthentication, session);
|
|
1833
|
+
const scopeId = request.connection.relayScopeId.slice();
|
|
1752
1834
|
return {
|
|
1753
1835
|
canonicalAccountId: session.canonicalAccountId,
|
|
1754
1836
|
deviceId: session.deviceId,
|
|
1837
|
+
signalProtocolRelay: transport,
|
|
1755
1838
|
relay: transport,
|
|
1756
|
-
|
|
1839
|
+
signalProtocolRelayScopeId: scopeId,
|
|
1840
|
+
relayScopeId: scopeId,
|
|
1757
1841
|
remoteObjectStore: transport.objectStore,
|
|
1758
1842
|
transport,
|
|
1759
1843
|
};
|
|
1760
1844
|
}
|
|
1761
|
-
export async function
|
|
1845
|
+
export async function resumeHostedSignalProtocolRelayTransport(options) {
|
|
1762
1846
|
let stored;
|
|
1763
1847
|
try {
|
|
1764
|
-
stored = await options.storage
|
|
1848
|
+
stored = await readHostedStoreRecord(options.storage, await sessionMetadataKey(options.connection));
|
|
1765
1849
|
}
|
|
1766
1850
|
catch (cause) {
|
|
1767
1851
|
if (options.requireExisting) {
|
|
1768
|
-
throw new
|
|
1852
|
+
throw new HostedSignalProtocolRelayResumeError('RETAINED_STATE_UNREADABLE', 'reading-local-state', { cause });
|
|
1769
1853
|
}
|
|
1770
1854
|
throw cause;
|
|
1771
1855
|
}
|
|
1772
1856
|
if (!stored) {
|
|
1773
1857
|
if (options.requireExisting) {
|
|
1774
|
-
throw new
|
|
1858
|
+
throw new HostedSignalProtocolRelayResumeError('RETAINED_SESSION_UNAVAILABLE', 'reading-local-state');
|
|
1775
1859
|
}
|
|
1776
1860
|
return undefined;
|
|
1777
1861
|
}
|
|
@@ -1781,28 +1865,31 @@ export async function resumeHostedRelayTransport(options) {
|
|
|
1781
1865
|
}
|
|
1782
1866
|
catch (cause) {
|
|
1783
1867
|
if (options.requireExisting) {
|
|
1784
|
-
throw new
|
|
1868
|
+
throw new HostedSignalProtocolRelayResumeError('RETAINED_SESSION_UNAVAILABLE', 'reading-local-state', { cause });
|
|
1785
1869
|
}
|
|
1786
1870
|
throw cause;
|
|
1787
1871
|
}
|
|
1788
|
-
const transport = new
|
|
1872
|
+
const transport = new HostedSignalProtocolRelayHttpTransport(options.connection, options.storage, options.deviceAuthentication, session);
|
|
1789
1873
|
options.onAuthenticating?.();
|
|
1790
1874
|
await transport.ensureAuthenticated(true);
|
|
1875
|
+
const scopeId = options.connection.relayScopeId.slice();
|
|
1791
1876
|
return {
|
|
1792
1877
|
canonicalAccountId: session.canonicalAccountId,
|
|
1793
1878
|
deviceId: session.deviceId,
|
|
1879
|
+
signalProtocolRelay: transport,
|
|
1794
1880
|
relay: transport,
|
|
1795
|
-
|
|
1881
|
+
signalProtocolRelayScopeId: scopeId,
|
|
1882
|
+
relayScopeId: scopeId,
|
|
1796
1883
|
remoteObjectStore: transport.objectStore,
|
|
1797
1884
|
transport,
|
|
1798
1885
|
};
|
|
1799
1886
|
}
|
|
1800
1887
|
/** Compose a link using a detached active session without publication writes. */
|
|
1801
|
-
export async function
|
|
1802
|
-
const stored = await options.activeStorage
|
|
1888
|
+
export async function linkHostedSignalProtocolRelayTransport(options) {
|
|
1889
|
+
const stored = await readHostedStoreRecord(options.activeStorage, await sessionMetadataKey(options.connection));
|
|
1803
1890
|
if (!stored)
|
|
1804
1891
|
throw new Error('Signal Protocol Relay device link requires an active hosted session');
|
|
1805
|
-
const active = new
|
|
1892
|
+
const active = new HostedSignalProtocolRelayHttpTransport(options.connection, options.activeStorage, options.request.activeDeviceAuthentication, parseSession(stored, options.connection), false);
|
|
1806
1893
|
return active.linkDevice(options.request, options.storage);
|
|
1807
1894
|
}
|
|
1808
1895
|
//# sourceMappingURL=hosted-transport.js.map
|