@open-e2ee/signal-protocol-sdk 2.0.1 → 3.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 +10 -17
- package/ARCHITECTURE.md +1 -2
- package/CHANGELOG.md +80 -0
- package/LICENSE +11 -655
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +5 -7
- package/README.md +11 -11
- package/SECURITY.md +2 -2
- package/TROUBLESHOOTING.md +2 -6
- package/client/README.md +34 -16
- package/device/README.md +1 -1
- package/dist/client/client.d.ts +13 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +136 -73
- package/dist/client/client.js.map +1 -1
- package/dist/client/config.d.ts +14 -18
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js.map +1 -1
- package/dist/client/content-adapter.d.ts +2 -0
- package/dist/client/content-adapter.d.ts.map +1 -1
- package/dist/client/content-adapter.js +4 -0
- package/dist/client/content-adapter.js.map +1 -1
- package/dist/client/endorsement-manager.d.ts +4 -1
- package/dist/client/endorsement-manager.d.ts.map +1 -1
- package/dist/client/endorsement-manager.js +14 -6
- package/dist/client/endorsement-manager.js.map +1 -1
- package/dist/client/group-authority.d.ts +8 -0
- package/dist/client/group-authority.d.ts.map +1 -0
- package/dist/client/group-authority.js +2 -0
- package/dist/client/group-authority.js.map +1 -0
- package/dist/client/headless.d.ts +3 -8
- package/dist/client/headless.d.ts.map +1 -1
- package/dist/client/headless.js +3 -8
- package/dist/client/headless.js.map +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts +32 -0
- package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -0
- package/dist/client/hosted-anonymous-delivery.js +239 -0
- package/dist/client/hosted-anonymous-delivery.js.map +1 -0
- package/dist/client/hosted-connection.d.ts +1 -1
- package/dist/client/hosted-connection.d.ts.map +1 -1
- package/dist/client/hosted-connection.js +18 -51
- package/dist/client/hosted-connection.js.map +1 -1
- package/dist/client/hosted-group-authority.d.ts +11 -0
- package/dist/client/hosted-group-authority.d.ts.map +1 -0
- package/dist/client/hosted-group-authority.js +96 -0
- package/dist/client/hosted-group-authority.js.map +1 -0
- package/dist/client/hosted-groups.d.ts +31 -0
- package/dist/client/hosted-groups.d.ts.map +1 -0
- package/dist/client/hosted-groups.js +217 -0
- package/dist/client/hosted-groups.js.map +1 -0
- package/dist/client/hosted-mailbox-subscription.d.ts +34 -0
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -0
- package/dist/client/hosted-mailbox-subscription.js +257 -0
- package/dist/client/hosted-mailbox-subscription.js.map +1 -0
- package/dist/client/hosted-prekey-publication.d.ts +51 -0
- package/dist/client/hosted-prekey-publication.d.ts.map +1 -0
- package/dist/client/hosted-prekey-publication.js +249 -0
- package/dist/client/hosted-prekey-publication.js.map +1 -0
- package/dist/client/hosted-push.d.ts +4 -5
- package/dist/client/hosted-push.d.ts.map +1 -1
- package/dist/client/hosted-push.js +22 -22
- package/dist/client/hosted-push.js.map +1 -1
- package/dist/client/hosted-transport.d.ts +57 -35
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +666 -341
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted-trust.d.ts +29 -0
- package/dist/client/hosted-trust.d.ts.map +1 -0
- package/dist/client/hosted-trust.js +28 -0
- package/dist/client/hosted-trust.js.map +1 -0
- package/dist/client/hosted.d.ts +18 -13
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +78 -34
- package/dist/client/hosted.js.map +1 -1
- package/dist/client/index.d.ts +14 -14
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +7 -7
- package/dist/client/index.js.map +1 -1
- package/dist/client/key-rotation-core.d.ts +8 -0
- package/dist/client/key-rotation-core.d.ts.map +1 -1
- package/dist/client/key-rotation-core.js +12 -1
- package/dist/client/key-rotation-core.js.map +1 -1
- package/dist/client/key-rotation.d.ts +2 -1
- package/dist/client/key-rotation.d.ts.map +1 -1
- package/dist/client/key-rotation.js +4 -4
- package/dist/client/key-rotation.js.map +1 -1
- package/dist/client/media-queue-persistence.d.ts +14 -0
- package/dist/client/media-queue-persistence.d.ts.map +1 -0
- package/dist/client/media-queue-persistence.js +123 -0
- package/dist/client/media-queue-persistence.js.map +1 -0
- package/dist/client/media-upload-budget.d.ts +3 -0
- package/dist/client/media-upload-budget.d.ts.map +1 -0
- package/dist/client/media-upload-budget.js +27 -0
- package/dist/client/media-upload-budget.js.map +1 -0
- package/dist/client/media.d.ts +51 -15
- package/dist/client/media.d.ts.map +1 -1
- package/dist/client/media.js +541 -73
- package/dist/client/media.js.map +1 -1
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/messages.js +13 -14
- package/dist/client/messages.js.map +1 -1
- package/dist/client/prekeys.d.ts.map +1 -1
- package/dist/client/prekeys.js +131 -43
- package/dist/client/prekeys.js.map +1 -1
- package/dist/client/relay-subscription.d.ts +4 -0
- package/dist/client/relay-subscription.d.ts.map +1 -1
- package/dist/client/relay-subscription.js +58 -25
- package/dist/client/relay-subscription.js.map +1 -1
- package/dist/client/sender-key-distribution.d.ts +8 -0
- package/dist/client/sender-key-distribution.d.ts.map +1 -0
- package/dist/client/sender-key-distribution.js +59 -0
- package/dist/client/sender-key-distribution.js.map +1 -0
- package/dist/client/signal-service-cipher.d.ts +7 -3
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +41 -16
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/device/{expo-metadata.d.ts → expo/index.d.ts} +3 -3
- package/dist/device/expo/index.d.ts.map +1 -0
- package/dist/device/{expo-metadata.js → expo/index.js} +2 -2
- package/dist/device/expo/index.js.map +1 -0
- package/dist/device/index.js +1 -1
- package/dist/device/index.js.map +1 -1
- package/dist/device/provisioning.d.ts +1 -1
- package/dist/device/provisioning.js +1 -1
- package/dist/device/types.d.ts +1 -1
- package/dist/groups/server.d.ts +10 -0
- package/dist/groups/server.d.ts.map +1 -0
- package/dist/groups/server.js +6 -0
- package/dist/groups/server.js.map +1 -0
- package/dist/hooks/use-connection-presence.d.ts +2 -4
- package/dist/hooks/use-connection-presence.d.ts.map +1 -1
- package/dist/hooks/use-connection-presence.js +2 -4
- package/dist/hooks/use-connection-presence.js.map +1 -1
- package/dist/index.d.ts +51 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -24
- package/dist/index.js.map +1 -1
- package/dist/internal/groups/authority-certificate.d.ts +22 -0
- package/dist/internal/groups/authority-certificate.d.ts.map +1 -0
- package/dist/internal/groups/authority-certificate.js +99 -0
- package/dist/internal/groups/authority-certificate.js.map +1 -0
- package/dist/internal/groups/error-details.d.ts +9 -0
- package/dist/internal/groups/error-details.d.ts.map +1 -0
- package/dist/internal/groups/error-details.js +30 -0
- package/dist/internal/groups/error-details.js.map +1 -0
- package/dist/internal/groups/manager.d.ts +5 -0
- package/dist/internal/groups/manager.d.ts.map +1 -1
- package/dist/internal/groups/manager.js +3 -0
- package/dist/internal/groups/manager.js.map +1 -1
- package/dist/internal/groups/server-engine.d.ts +7 -0
- package/dist/internal/groups/server-engine.d.ts.map +1 -1
- package/dist/internal/groups/server-engine.js +51 -19
- package/dist/internal/groups/server-engine.js.map +1 -1
- package/dist/internal/groups/wire.d.ts.map +1 -1
- package/dist/internal/groups/wire.js +10 -9
- package/dist/internal/groups/wire.js.map +1 -1
- package/dist/internal/manager/manager.d.ts +1 -1
- package/dist/internal/manager/manager.d.ts.map +1 -1
- package/dist/internal/manager/manager.js +22 -25
- package/dist/internal/manager/manager.js.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts +1 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.js +27 -14
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
- package/dist/internal/sesame/manager.d.ts +2 -2
- package/dist/internal/sesame/manager.d.ts.map +1 -1
- package/dist/internal/sesame/manager.js +6 -6
- package/dist/internal/sesame/manager.js.map +1 -1
- package/dist/internal/sesame/types.d.ts +1 -1
- package/dist/internal/sesame/types.d.ts.map +1 -1
- package/dist/internal/session/cipher.d.ts +1 -1
- package/dist/internal/session/cipher.d.ts.map +1 -1
- package/dist/internal/session/cipher.js +31 -28
- package/dist/internal/session/cipher.js.map +1 -1
- package/dist/layers.d.ts +1 -1
- package/dist/layers.d.ts.map +1 -1
- package/dist/layers.js +1 -1
- package/dist/layers.js.map +1 -1
- package/dist/local/store/expo/adapter.d.ts +8 -2
- package/dist/local/store/expo/adapter.d.ts.map +1 -1
- package/dist/local/store/expo/adapter.js +28 -9
- package/dist/local/store/expo/adapter.js.map +1 -1
- package/dist/local/store/expo/key-storage.d.ts +7 -1
- package/dist/local/store/expo/key-storage.d.ts.map +1 -1
- package/dist/local/store/expo/key-storage.js +82 -17
- package/dist/local/store/expo/key-storage.js.map +1 -1
- package/dist/local/store/expo/models/kyber-prekey-used.d.ts +1 -4
- package/dist/local/store/expo/models/kyber-prekey-used.d.ts.map +1 -1
- package/dist/local/store/expo/models/kyber-prekey-used.js +23 -9
- package/dist/local/store/expo/models/kyber-prekey-used.js.map +1 -1
- package/dist/local/store/expo/models/kyber-prekey.d.ts +4 -4
- package/dist/local/store/expo/models/kyber-prekey.d.ts.map +1 -1
- package/dist/local/store/expo/models/kyber-prekey.js +67 -26
- package/dist/local/store/expo/models/kyber-prekey.js.map +1 -1
- package/dist/local/store/expo/schema.d.ts +21 -2
- package/dist/local/store/expo/schema.d.ts.map +1 -1
- package/dist/local/store/expo/schema.js +10 -2
- package/dist/local/store/expo/schema.js.map +1 -1
- package/dist/local/store/kyber-prekey-lifecycle.d.ts +46 -0
- package/dist/local/store/kyber-prekey-lifecycle.d.ts.map +1 -0
- package/dist/local/store/kyber-prekey-lifecycle.js +88 -0
- package/dist/local/store/kyber-prekey-lifecycle.js.map +1 -0
- package/dist/local/store/memory/adapter.d.ts +11 -3
- package/dist/local/store/memory/adapter.d.ts.map +1 -1
- package/dist/local/store/memory/adapter.js +113 -28
- package/dist/local/store/memory/adapter.js.map +1 -1
- package/dist/local/store/node/adapter.d.ts +8 -2
- package/dist/local/store/node/adapter.d.ts.map +1 -1
- package/dist/local/store/node/adapter.js +31 -13
- package/dist/local/store/node/adapter.js.map +1 -1
- package/dist/local/store/node/database-file-commit.d.ts +8 -0
- package/dist/local/store/node/database-file-commit.d.ts.map +1 -0
- package/dist/local/store/node/database-file-commit.js +62 -0
- package/dist/local/store/node/database-file-commit.js.map +1 -0
- package/dist/local/store/node/database-key.d.ts +6 -1
- package/dist/local/store/node/database-key.d.ts.map +1 -1
- package/dist/local/store/node/database-key.js +79 -44
- package/dist/local/store/node/database-key.js.map +1 -1
- package/dist/local/store/node/database-lock.d.ts +8 -0
- package/dist/local/store/node/database-lock.d.ts.map +1 -0
- package/dist/local/store/node/database-lock.js +44 -0
- package/dist/local/store/node/database-lock.js.map +1 -0
- package/dist/local/store/node/database.d.ts +15 -14
- package/dist/local/store/node/database.d.ts.map +1 -1
- package/dist/local/store/node/database.js +197 -202
- package/dist/local/store/node/database.js.map +1 -1
- package/dist/local/store/react-native/adapter.d.ts +8 -2
- package/dist/local/store/react-native/adapter.d.ts.map +1 -1
- package/dist/local/store/react-native/adapter.js +151 -66
- package/dist/local/store/react-native/adapter.js.map +1 -1
- package/dist/local/store/received-content.d.ts +9 -0
- package/dist/local/store/received-content.d.ts.map +1 -0
- package/dist/local/store/received-content.js +46 -0
- package/dist/local/store/received-content.js.map +1 -0
- package/dist/local/store/reliability.d.ts +2 -2
- package/dist/local/store/reliability.d.ts.map +1 -1
- package/dist/local/store/reliability.js +7 -4
- package/dist/local/store/reliability.js.map +1 -1
- package/dist/local/store/web/adapter.d.ts +8 -2
- package/dist/local/store/web/adapter.d.ts.map +1 -1
- package/dist/local/store/web/adapter.js +206 -73
- package/dist/local/store/web/adapter.js.map +1 -1
- package/dist/media/index.d.ts +71 -61
- package/dist/media/index.d.ts.map +1 -1
- package/dist/media/index.js +550 -386
- package/dist/media/index.js.map +1 -1
- package/dist/media/prepared-upload.d.ts +37 -0
- package/dist/media/prepared-upload.d.ts.map +1 -0
- package/dist/media/prepared-upload.js +46 -0
- package/dist/media/prepared-upload.js.map +1 -0
- package/dist/remote/object-store/convex-r2/server.d.ts +2 -1
- package/dist/remote/object-store/convex-r2/server.d.ts.map +1 -1
- package/dist/remote/object-store/convex-r2/server.js +4 -0
- package/dist/remote/object-store/convex-r2/server.js.map +1 -1
- package/dist/remote/object-store/convex-r2/storage.d.ts.map +1 -1
- package/dist/remote/object-store/convex-r2/storage.js +1 -0
- package/dist/remote/object-store/convex-r2/storage.js.map +1 -1
- package/dist/remote/object-store/index.d.ts +3 -1
- package/dist/remote/object-store/index.d.ts.map +1 -1
- package/dist/remote/object-store/index.js +1 -1
- package/dist/remote/object-store/index.js.map +1 -1
- package/dist/remote/object-store/s3/storage.d.ts +3 -1
- package/dist/remote/object-store/s3/storage.d.ts.map +1 -1
- package/dist/remote/object-store/s3/storage.js +9 -2
- package/dist/remote/object-store/s3/storage.js.map +1 -1
- package/dist/remote/object-store/types.d.ts +33 -4
- package/dist/remote/object-store/types.d.ts.map +1 -1
- package/dist/remote/object-store/upload-error.d.ts +23 -0
- package/dist/remote/object-store/upload-error.d.ts.map +1 -0
- package/dist/remote/object-store/upload-error.js +33 -0
- package/dist/remote/object-store/upload-error.js.map +1 -0
- package/dist/remote/object-store/validation.d.ts +7 -1
- package/dist/remote/object-store/validation.d.ts.map +1 -1
- package/dist/remote/object-store/validation.js +39 -25
- package/dist/remote/object-store/validation.js.map +1 -1
- package/dist/remote/relay/index.d.ts +5 -12
- package/dist/remote/relay/index.d.ts.map +1 -1
- package/dist/remote/relay/index.js +4 -11
- package/dist/remote/relay/index.js.map +1 -1
- package/dist/remote/relay/memory/adapter.d.ts +2 -1
- package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
- package/dist/remote/relay/memory/adapter.js +10 -0
- package/dist/remote/relay/memory/adapter.js.map +1 -1
- package/dist/remote/relay/types.d.ts +28 -17
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/types/api.d.ts +36 -1
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/session.d.ts +6 -0
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js.map +1 -1
- package/docs/ASSURANCE.md +7 -7
- package/docs/CLIENT_COMPOSITION.md +12 -19
- package/docs/DEVIATIONS.md +1 -1
- package/docs/DOCUMENTATION_STANDARDS.md +4 -0
- package/docs/GETTING_STARTED.md +23 -38
- package/docs/INTERFACES.md +22 -13
- package/docs/PACKAGE_SURFACE.md +5 -12
- package/docs/RECIPES.md +10 -23
- package/examples/browser/index.html +2 -2
- package/local/store/README.md +16 -1
- package/local/store/expo/README.md +23 -19
- package/local/store/node/README.md +29 -0
- package/media/README.md +94 -0
- package/package.json +17 -27
- package/remote/README.md +16 -16
- package/remote/object-store/README.md +8 -0
- package/remote/object-store/s3/README.md +10 -1
- package/remote/relay/README.md +3 -2
- package/COMMERCIAL.md +0 -56
- package/dist/device/expo-metadata.d.ts.map +0 -1
- package/dist/device/expo-metadata.js.map +0 -1
- package/dist/remote/relay/convex/backend.d.ts +0 -394
- package/dist/remote/relay/convex/backend.d.ts.map +0 -1
- package/dist/remote/relay/convex/backend.js +0 -678
- package/dist/remote/relay/convex/backend.js.map +0 -1
- package/dist/remote/relay/convex/component/_generated/api.d.ts +0 -58
- package/dist/remote/relay/convex/component/_generated/api.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/_generated/api.js +0 -31
- package/dist/remote/relay/convex/component/_generated/api.js.map +0 -1
- package/dist/remote/relay/convex/component/_generated/component.d.ts +0 -475
- package/dist/remote/relay/convex/component/_generated/component.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/_generated/component.js +0 -11
- package/dist/remote/relay/convex/component/_generated/component.js.map +0 -1
- package/dist/remote/relay/convex/component/_generated/dataModel.d.ts +0 -46
- package/dist/remote/relay/convex/component/_generated/dataModel.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/_generated/dataModel.js +0 -11
- package/dist/remote/relay/convex/component/_generated/dataModel.js.map +0 -1
- package/dist/remote/relay/convex/component/_generated/server.d.ts +0 -129
- package/dist/remote/relay/convex/component/_generated/server.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/_generated/server.js +0 -79
- package/dist/remote/relay/convex/component/_generated/server.js.map +0 -1
- package/dist/remote/relay/convex/component/accounts.d.ts +0 -45
- package/dist/remote/relay/convex/component/accounts.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/accounts.js +0 -184
- package/dist/remote/relay/convex/component/accounts.js.map +0 -1
- package/dist/remote/relay/convex/component/certificates.d.ts +0 -10
- package/dist/remote/relay/convex/component/certificates.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/certificates.js +0 -126
- package/dist/remote/relay/convex/component/certificates.js.map +0 -1
- package/dist/remote/relay/convex/component/cleanup.d.ts +0 -32
- package/dist/remote/relay/convex/component/cleanup.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/cleanup.js +0 -146
- package/dist/remote/relay/convex/component/cleanup.js.map +0 -1
- package/dist/remote/relay/convex/component/convex.config.d.ts +0 -5
- package/dist/remote/relay/convex/component/convex.config.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/convex.config.js +0 -35
- package/dist/remote/relay/convex/component/convex.config.js.map +0 -1
- package/dist/remote/relay/convex/component/crons.d.ts +0 -3
- package/dist/remote/relay/convex/component/crons.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/crons.js +0 -10
- package/dist/remote/relay/convex/component/crons.js.map +0 -1
- package/dist/remote/relay/convex/component/devices.d.ts +0 -102
- package/dist/remote/relay/convex/component/devices.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/devices.js +0 -300
- package/dist/remote/relay/convex/component/devices.js.map +0 -1
- package/dist/remote/relay/convex/component/errors.d.ts +0 -22
- package/dist/remote/relay/convex/component/errors.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/errors.js +0 -17
- package/dist/remote/relay/convex/component/errors.js.map +0 -1
- package/dist/remote/relay/convex/component/groups.d.ts +0 -63
- package/dist/remote/relay/convex/component/groups.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/groups.js +0 -341
- package/dist/remote/relay/convex/component/groups.js.map +0 -1
- package/dist/remote/relay/convex/component/keys.d.ts +0 -130
- package/dist/remote/relay/convex/component/keys.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/keys.js +0 -578
- package/dist/remote/relay/convex/component/keys.js.map +0 -1
- package/dist/remote/relay/convex/component/messages.d.ts +0 -105
- package/dist/remote/relay/convex/component/messages.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/messages.js +0 -702
- package/dist/remote/relay/convex/component/messages.js.map +0 -1
- package/dist/remote/relay/convex/component/provisioning.d.ts +0 -92
- package/dist/remote/relay/convex/component/provisioning.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/provisioning.js +0 -360
- package/dist/remote/relay/convex/component/provisioning.js.map +0 -1
- package/dist/remote/relay/convex/component/runtime.d.ts +0 -18
- package/dist/remote/relay/convex/component/runtime.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/runtime.js +0 -144
- package/dist/remote/relay/convex/component/runtime.js.map +0 -1
- package/dist/remote/relay/convex/component/schema.d.ts +0 -358
- package/dist/remote/relay/convex/component/schema.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/schema.js +0 -288
- package/dist/remote/relay/convex/component/schema.js.map +0 -1
- package/dist/remote/relay/convex/component/zkAuth.d.ts +0 -18
- package/dist/remote/relay/convex/component/zkAuth.d.ts.map +0 -1
- package/dist/remote/relay/convex/component/zkAuth.js +0 -86
- package/dist/remote/relay/convex/component/zkAuth.js.map +0 -1
- package/dist/remote/relay/convex/constants.d.ts +0 -3
- package/dist/remote/relay/convex/constants.d.ts.map +0 -1
- package/dist/remote/relay/convex/constants.js +0 -3
- package/dist/remote/relay/convex/constants.js.map +0 -1
- package/dist/remote/relay/convex/group-server.d.ts +0 -123
- package/dist/remote/relay/convex/group-server.d.ts.map +0 -1
- package/dist/remote/relay/convex/group-server.js +0 -184
- package/dist/remote/relay/convex/group-server.js.map +0 -1
- package/dist/remote/relay/convex/index.d.ts +0 -42
- package/dist/remote/relay/convex/index.d.ts.map +0 -1
- package/dist/remote/relay/convex/index.js +0 -38
- package/dist/remote/relay/convex/index.js.map +0 -1
- package/dist/remote/relay/convex/relay.d.ts +0 -323
- package/dist/remote/relay/convex/relay.d.ts.map +0 -1
- package/dist/remote/relay/convex/relay.js +0 -1144
- package/dist/remote/relay/convex/relay.js.map +0 -1
- package/dist/remote/relay/convex/types.d.ts +0 -24
- package/dist/remote/relay/convex/types.d.ts.map +0 -1
- package/dist/remote/relay/convex/types.js +0 -14
- package/dist/remote/relay/convex/types.js.map +0 -1
- package/remote/relay/convex/README.md +0 -61
- package/remote/relay/convex/component/README.md +0 -462
|
@@ -1,702 +0,0 @@
|
|
|
1
|
-
import { MINUTE, RateLimiter, isRateLimitError } from '@convex-dev/rate-limiter';
|
|
2
|
-
import { ConvexError, v } from 'convex/values';
|
|
3
|
-
import { base64ToBytes, bytesToBase64 } from '../../../../internal/crypto/utils.js';
|
|
4
|
-
import { MAX_DEVICES } from '../../../../device/constants.js';
|
|
5
|
-
import { serializeReceivedMessage } from '../../../../internal/protocol/sealed-sender/multi-recipient-message.js';
|
|
6
|
-
import { asBase64 } from '../../../../types/utils.js';
|
|
7
|
-
import { components } from './_generated/api.js';
|
|
8
|
-
import { mutation, query } from './_generated/server.js';
|
|
9
|
-
import { authorizeAccessKey, authorizeGroupSendToken, callerIdentityArgs, rememberAccount, } from './accounts.js';
|
|
10
|
-
import { relayError, unauthorized } from './errors.js';
|
|
11
|
-
const MESSAGE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
12
|
-
const MAX_PENDING_MESSAGES = 1000;
|
|
13
|
-
const MAX_PENDING_RETRY_REQUESTS = 1000;
|
|
14
|
-
const MAX_MULTI_RECIPIENT_DEVICES = 1000;
|
|
15
|
-
/**
|
|
16
|
-
* Ceiling on a single message's content, before base64 framing.
|
|
17
|
-
*
|
|
18
|
-
* 96 KiB, and the same 96 KiB for the shared multi-recipient ciphertext.
|
|
19
|
-
* The reference validates what each recipient will *receive* against a
|
|
20
|
-
* single 96 KiB message-size constant. That view is the one-byte version,
|
|
21
|
-
* that recipient's key material, and the shared data, on the individual and
|
|
22
|
-
* multi-recipient paths alike. Its separate 256 KiB constant is an HTTP
|
|
23
|
-
* entity-read cap on the whole request, which is the shared payload plus
|
|
24
|
-
* every recipient block. That cap is not a content ceiling, and an earlier
|
|
25
|
-
* version of this file mistook it for one. The shared ciphertext is the dominant term of
|
|
26
|
-
* the per-recipient view, so it is what the ceiling binds here.
|
|
27
|
-
*
|
|
28
|
-
* The columns are base64 strings, so the byte ceilings are enforced as
|
|
29
|
-
* string-length ceilings. Base64 emits 4 characters per started group of 3
|
|
30
|
-
* bytes, which is 4 * ceil(n / 3). The ceiling belongs inside the division.
|
|
31
|
-
* Otherwise a payload whose size is not a multiple of 3 encodes 2 characters
|
|
32
|
-
* past the advertised limit, and full-size messages are refused.
|
|
33
|
-
*/
|
|
34
|
-
const base64LengthOf = (byteLength) => 4 * Math.ceil(byteLength / 3);
|
|
35
|
-
const MAX_MESSAGE_BYTES = 96 * 1024;
|
|
36
|
-
const MAX_MULTI_RECIPIENT_MESSAGE_BYTES = 96 * 1024;
|
|
37
|
-
const MAX_CIPHERTEXT_LENGTH = base64LengthOf(MAX_MESSAGE_BYTES);
|
|
38
|
-
const MAX_MULTI_RECIPIENT_CIPHERTEXT_LENGTH = base64LengthOf(MAX_MULTI_RECIPIENT_MESSAGE_BYTES);
|
|
39
|
-
/**
|
|
40
|
-
* Inbound budget per recipient, spent in ciphertext bytes.
|
|
41
|
-
*
|
|
42
|
-
* Keyed by the *target*, because that is the only stable identity on these
|
|
43
|
-
* paths. A sealed sender is anonymous by design, so any per-sender limit is
|
|
44
|
-
* either meaningless or a hole. The reference implementation bounds inbound
|
|
45
|
-
* message bytes per destination the same way, on its identified and sealed
|
|
46
|
-
* single-recipient paths alike.
|
|
47
|
-
*
|
|
48
|
-
* What this closes is unbounded queue flooding. Without it, one anonymous
|
|
49
|
-
* caller holding a valid access key can grow a victim's `messages` table
|
|
50
|
-
* without limit for the whole retention window. Any account-authenticated
|
|
51
|
-
* caller on the identified path can do the same. The budget is generous for
|
|
52
|
-
* real traffic and fatal for floods. Sealed envelopes run 1-2 KiB, so the
|
|
53
|
-
* sustained rate is hundreds of messages a minute per recipient.
|
|
54
|
-
*
|
|
55
|
-
* The multi-recipient path is deliberately not metered, matching the
|
|
56
|
-
* reference. A group-send token already prices that path, and a per-recipient
|
|
57
|
-
* budget there would let one noisy group partially starve delivery to its
|
|
58
|
-
* quietest member. Verified against the reference's MessageController: its
|
|
59
|
-
* inbound-bytes limiter is validated only in `sendIndividualMessage`, never
|
|
60
|
-
* on the multi-recipient route. Metering here would also have to fail the
|
|
61
|
-
* whole fan-out rather than one recipient, because the charge and the
|
|
62
|
-
* inserts share a transaction. A single recipient at their ceiling would
|
|
63
|
-
* then block delivery to everyone else in the call.
|
|
64
|
-
*
|
|
65
|
-
* What the exemption assumes is that one call fans out to distinct devices.
|
|
66
|
-
* The reference gets that from its wire format, which parses recipients into
|
|
67
|
-
* a map keyed by service ID. The flat array here does not, so the handler
|
|
68
|
-
* rejects a repeated device explicitly.
|
|
69
|
-
*/
|
|
70
|
-
const rateLimiter = new RateLimiter(components.rateLimiter, {
|
|
71
|
-
inboundMessageBytes: {
|
|
72
|
-
kind: 'token bucket',
|
|
73
|
-
rate: 1024 * 1024,
|
|
74
|
-
period: MINUTE,
|
|
75
|
-
capacity: 4 * 1024 * 1024,
|
|
76
|
-
},
|
|
77
|
-
// Sub-limit for the identified path, keyed by (sender, target). The
|
|
78
|
-
// shared per-target bucket is forced on the sealed path. There is no
|
|
79
|
-
// sender identity to key on there, but the identified path has one.
|
|
80
|
-
// Without this sub-limit a single authenticated account could drain a
|
|
81
|
-
// victim's whole shared budget and 429 every other sender indefinitely. A quarter
|
|
82
|
-
// of the shared bucket keeps one sender from monopolizing it while
|
|
83
|
-
// leaving any real conversation far below the ceiling.
|
|
84
|
-
inboundMessageBytesPerSender: {
|
|
85
|
-
kind: 'token bucket',
|
|
86
|
-
rate: 256 * 1024,
|
|
87
|
-
period: MINUTE,
|
|
88
|
-
capacity: 1024 * 1024,
|
|
89
|
-
},
|
|
90
|
-
// Counted, not metered by size: a retry request is a fixed-shape row. A
|
|
91
|
-
// client coming back from a broken session legitimately asks for one per
|
|
92
|
-
// message it could not decrypt, so the burst allowance is generous.
|
|
93
|
-
//
|
|
94
|
-
// What this bounds is the *rate*, not the total. A refilling bucket never
|
|
95
|
-
// refuses a patient caller. A hostile account can still accrete rows
|
|
96
|
-
// against a target at the refill rate. It can do that for as long as it
|
|
97
|
-
// cares to, up to whatever the seven-day TTL retains. That is a
|
|
98
|
-
// storage-and-noise cost, not a denial, because the target reads the
|
|
99
|
-
// oldest page first and can drain. The row TTL, not this bucket, is what
|
|
100
|
-
// ultimately bounds it.
|
|
101
|
-
retryRequests: {
|
|
102
|
-
kind: 'token bucket',
|
|
103
|
-
rate: 120,
|
|
104
|
-
period: MINUTE,
|
|
105
|
-
capacity: 240,
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
/** Approximate decoded size of a base64 column, for budget accounting. */
|
|
109
|
-
function ciphertextBytes(encoded) {
|
|
110
|
-
return Math.floor((encoded.length * 3) / 4);
|
|
111
|
-
}
|
|
112
|
-
function requireCiphertextWithin(encoded, maxLength) {
|
|
113
|
-
if (encoded.length > maxLength) {
|
|
114
|
-
throw relayError('INVALID_REQUEST', 413, 'Message content exceeds the maximum size');
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Re-throw a limiter rejection as a 429, or pass anything else through.
|
|
119
|
-
*
|
|
120
|
-
* The component's limiter writes inside the caller's transaction, so this
|
|
121
|
-
* only ever shapes the error. The charges themselves are undone by the
|
|
122
|
-
* throw, whichever limit produced it.
|
|
123
|
-
*/
|
|
124
|
-
function rethrowRateLimited(error, message) {
|
|
125
|
-
if (isRateLimitError(error)) {
|
|
126
|
-
throw relayError('RATE_LIMITED', 429, message, {
|
|
127
|
-
retryAfter: error.data.retryAfter,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
if (error instanceof ConvexError) {
|
|
131
|
-
const data = error.data;
|
|
132
|
-
if (data.kind === 'RateLimited') {
|
|
133
|
-
throw relayError('RATE_LIMITED', 429, message, {
|
|
134
|
-
retryAfter: typeof data.retryAfter === 'number' ? data.retryAfter : undefined,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw error;
|
|
139
|
-
}
|
|
140
|
-
async function chargeInboundBudget(ctx, targetUserId, bytes, senderUserId) {
|
|
141
|
-
try {
|
|
142
|
-
// Order between the two buckets carries no meaning. Both charges are
|
|
143
|
-
// written in this mutation's transaction, so whichever limit throws
|
|
144
|
-
// discards the other's spend along with everything else. The sub-limit
|
|
145
|
-
// runs first only because it is the more specific diagnosis of the two.
|
|
146
|
-
if (senderUserId !== undefined) {
|
|
147
|
-
await rateLimiter.limit(ctx, 'inboundMessageBytesPerSender', {
|
|
148
|
-
key: JSON.stringify([senderUserId, targetUserId]),
|
|
149
|
-
count: bytes,
|
|
150
|
-
throws: true,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
await rateLimiter.limit(ctx, 'inboundMessageBytes', {
|
|
154
|
-
key: targetUserId,
|
|
155
|
-
count: bytes,
|
|
156
|
-
throws: true,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
rethrowRateLimited(error, 'Inbound message rate limit exceeded for this recipient');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Bound how fast one account can create retry-request rows.
|
|
165
|
-
*
|
|
166
|
-
* These rows carry no caller-supplied content, so there is nothing to bound
|
|
167
|
-
* by size. The cost is the row itself, held for the full retention window.
|
|
168
|
-
* Nothing else on this path constrains them. The request names an original
|
|
169
|
-
* sender it never has to have talked to, so there is no relationship to
|
|
170
|
-
* check either.
|
|
171
|
-
*/
|
|
172
|
-
async function chargeRetryRequest(ctx, requesterUserId) {
|
|
173
|
-
try {
|
|
174
|
-
await rateLimiter.limit(ctx, 'retryRequests', {
|
|
175
|
-
key: requesterUserId,
|
|
176
|
-
throws: true,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
rethrowRateLimited(error, 'Retry-request rate limit exceeded');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Reject a sealed single-recipient send whose target device does not exist.
|
|
185
|
-
*
|
|
186
|
-
* The multi-recipient path already reports unknown devices through
|
|
187
|
-
* `uuids404`, and the reference implementation refuses sealed sends to
|
|
188
|
-
* unknown destinations outright. Without this check the path is a write
|
|
189
|
-
* primitive for rows nothing will ever read. An anonymous caller can address
|
|
190
|
-
* arbitrary device IDs, and every insert sits in the table for the full
|
|
191
|
-
* retention window.
|
|
192
|
-
*/
|
|
193
|
-
async function requireActiveDevice(ctx, userId, deviceId) {
|
|
194
|
-
const device = await ctx.db
|
|
195
|
-
.query('devices')
|
|
196
|
-
.withIndex('by_user_id_and_device_id', (q) => q.eq('userId', userId).eq('deviceId', deviceId))
|
|
197
|
-
.unique();
|
|
198
|
-
if (!device?.registered || !device.enabled) {
|
|
199
|
-
throw relayError('NOT_FOUND', 404, 'Unknown destination device');
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const messageTypeValidator = v.union(v.literal('ciphertext'), v.literal('prekey_bundle'), v.literal('sender_key'), v.literal('server_delivery_receipt'), v.literal('unidentified_sender'));
|
|
203
|
-
const deliveryClassValidator = v.union(v.literal('user-visible'), v.literal('background-sync'), v.literal('ephemeral'));
|
|
204
|
-
const receiptValidator = v.object({
|
|
205
|
-
messageId: v.string(),
|
|
206
|
-
serverTimestamp: v.number(),
|
|
207
|
-
});
|
|
208
|
-
const pendingMessageValidator = v.object({
|
|
209
|
-
id: v.string(),
|
|
210
|
-
targetUserId: v.string(),
|
|
211
|
-
targetDeviceId: v.number(),
|
|
212
|
-
senderUserId: v.string(),
|
|
213
|
-
senderDeviceId: v.number(),
|
|
214
|
-
ciphertext: v.string(),
|
|
215
|
-
messageType: messageTypeValidator,
|
|
216
|
-
deliveryClass: deliveryClassValidator,
|
|
217
|
-
timestamp: v.number(),
|
|
218
|
-
serverTimestamp: v.number(),
|
|
219
|
-
clientMessageId: v.optional(v.string()),
|
|
220
|
-
expiresAt: v.number(),
|
|
221
|
-
});
|
|
222
|
-
const retryReasonValidator = v.union(v.literal('NO_SESSION'), v.literal('DECRYPTION_FAILED'), v.literal('SESSION_EXPIRED'), v.literal('STALE_DEVICE_LIST'), v.literal('IDENTITY_KEY_MISMATCH'));
|
|
223
|
-
async function insertMessage(ctx, input) {
|
|
224
|
-
if (input.clientMessageId !== undefined) {
|
|
225
|
-
const existing = await ctx.db
|
|
226
|
-
.query('messages')
|
|
227
|
-
.withIndex('by_target_and_client_message_id', (q) => q
|
|
228
|
-
.eq('targetUserId', input.targetUserId)
|
|
229
|
-
.eq('targetDeviceId', input.targetDeviceId)
|
|
230
|
-
.eq('senderUserId', input.senderUserId)
|
|
231
|
-
.eq('clientMessageId', input.clientMessageId))
|
|
232
|
-
.unique();
|
|
233
|
-
if (existing) {
|
|
234
|
-
return {
|
|
235
|
-
messageId: existing.messageId,
|
|
236
|
-
serverTimestamp: existing.serverTimestamp,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
const serverTimestamp = Date.now();
|
|
241
|
-
const messageId = crypto.randomUUID();
|
|
242
|
-
await ctx.db.insert('messages', {
|
|
243
|
-
...input,
|
|
244
|
-
messageId,
|
|
245
|
-
serverTimestamp,
|
|
246
|
-
expiresAt: serverTimestamp + MESSAGE_TTL_MS,
|
|
247
|
-
});
|
|
248
|
-
return { messageId, serverTimestamp };
|
|
249
|
-
}
|
|
250
|
-
export const send = mutation({
|
|
251
|
-
args: {
|
|
252
|
-
...callerIdentityArgs,
|
|
253
|
-
targetUserId: v.string(),
|
|
254
|
-
targetDeviceId: v.number(),
|
|
255
|
-
senderDeviceId: v.number(),
|
|
256
|
-
ciphertext: v.string(),
|
|
257
|
-
messageType: messageTypeValidator,
|
|
258
|
-
deliveryClass: deliveryClassValidator,
|
|
259
|
-
timestamp: v.number(),
|
|
260
|
-
clientMessageId: v.optional(v.string()),
|
|
261
|
-
recipientRegistrationId: v.optional(v.number()),
|
|
262
|
-
},
|
|
263
|
-
returns: receiptValidator,
|
|
264
|
-
handler: async (ctx, input) => {
|
|
265
|
-
await rememberAccount(ctx, input);
|
|
266
|
-
requireCiphertextWithin(input.ciphertext, MAX_CIPHERTEXT_LENGTH);
|
|
267
|
-
if (input.recipientRegistrationId !== undefined) {
|
|
268
|
-
const registration = await ctx.db
|
|
269
|
-
.query('identityRegistrations')
|
|
270
|
-
.withIndex('by_user_id_and_device_id_and_identity_type', (q) => q
|
|
271
|
-
.eq('userId', input.targetUserId)
|
|
272
|
-
.eq('deviceId', input.targetDeviceId)
|
|
273
|
-
.eq('identityType', 'aci'))
|
|
274
|
-
.unique();
|
|
275
|
-
if (registration && registration.registrationId !== input.recipientRegistrationId) {
|
|
276
|
-
// Names only the stale device, matching the reference's 410 body.
|
|
277
|
-
// The current registration ID stays out. The sender re-fetches the
|
|
278
|
-
// prekey bundle to recover, and that path is rate limited. This one
|
|
279
|
-
// would otherwise hand any account-authenticated caller a free
|
|
280
|
-
// oracle for registration-ID changes on arbitrary devices.
|
|
281
|
-
throw relayError('STALE_DEVICE', 410, 'Recipient device registration changed', {
|
|
282
|
-
staleDevices: [input.targetDeviceId],
|
|
283
|
-
reason: 'device_reinstalled',
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
// Placed after the registration check for readability, not for safety. A
|
|
288
|
-
// send that 410s could charge first and still cost nothing, because the
|
|
289
|
-
// throw rolls the charge back with the rest of the mutation. Nothing on
|
|
290
|
-
// this path depends on the order.
|
|
291
|
-
await chargeInboundBudget(ctx, input.targetUserId, ciphertextBytes(input.ciphertext), input.callerUserId);
|
|
292
|
-
// Convex subscriptions are database-backed. This adapter cannot prove
|
|
293
|
-
// transient device acceptance without first retaining the frame, so it
|
|
294
|
-
// rejects ephemeral work instead of reporting false delivery or turning
|
|
295
|
-
// typing into offline mailbox state.
|
|
296
|
-
if (input.deliveryClass === 'ephemeral') {
|
|
297
|
-
throw relayError('NOT_IMPLEMENTED', 501, 'This Relay adapter has no live-only delivery transport');
|
|
298
|
-
}
|
|
299
|
-
return await insertMessage(ctx, {
|
|
300
|
-
targetUserId: input.targetUserId,
|
|
301
|
-
targetDeviceId: input.targetDeviceId,
|
|
302
|
-
senderUserId: input.callerUserId,
|
|
303
|
-
senderDeviceId: input.senderDeviceId,
|
|
304
|
-
ciphertext: input.ciphertext,
|
|
305
|
-
messageType: input.messageType,
|
|
306
|
-
deliveryClass: input.deliveryClass,
|
|
307
|
-
timestamp: input.timestamp,
|
|
308
|
-
clientMessageId: input.clientMessageId,
|
|
309
|
-
});
|
|
310
|
-
},
|
|
311
|
-
});
|
|
312
|
-
export const getPendingMessages = query({
|
|
313
|
-
args: {
|
|
314
|
-
...callerIdentityArgs,
|
|
315
|
-
deviceId: v.number(),
|
|
316
|
-
},
|
|
317
|
-
returns: v.array(pendingMessageValidator),
|
|
318
|
-
handler: async (ctx, input) => {
|
|
319
|
-
// Read-time expiry filter: the hourly cron eventually deletes expired
|
|
320
|
-
// rows, but until it runs they must neither be delivered nor consume
|
|
321
|
-
// the pending-message budget.
|
|
322
|
-
//
|
|
323
|
-
// Date.now() is fixed per transaction and cached with the query result.
|
|
324
|
-
// A subscribed client therefore does not see a row drop out the instant
|
|
325
|
-
// it expires. It sees the drop when a write to this index range
|
|
326
|
-
// invalidates the subscription. Any new message for this device does
|
|
327
|
-
// that, and so does the cron's delete. Staleness is therefore bounded by
|
|
328
|
-
// the cron interval. The effect is a message delivered late rather than
|
|
329
|
-
// one delivered wrongly, because expiresAt is a retention bound, not an
|
|
330
|
-
// authorization gate.
|
|
331
|
-
const now = Date.now();
|
|
332
|
-
const rows = (await ctx.db
|
|
333
|
-
.query('messages')
|
|
334
|
-
.withIndex('by_target_user_id_and_target_device_id', (q) => q.eq('targetUserId', input.callerUserId).eq('targetDeviceId', input.deviceId))
|
|
335
|
-
.take(MAX_PENDING_MESSAGES)).filter((row) => row.expiresAt > now);
|
|
336
|
-
// Multi-recipient rows store only their per-recipient prefix. The wire
|
|
337
|
-
// form is reassembled here from the once-stored shared payload. The
|
|
338
|
-
// payload shares the row's exact expiresAt, and the filter above has
|
|
339
|
-
// already dropped expired rows, so a missing payload is not a benign
|
|
340
|
-
// expiry race. It is an integrity fault, and it is served as one.
|
|
341
|
-
const sharedByPayloadId = new Map();
|
|
342
|
-
const wireCiphertext = async (row) => {
|
|
343
|
-
if (row.sharedPayloadId === undefined)
|
|
344
|
-
return row.ciphertext;
|
|
345
|
-
let shared = sharedByPayloadId.get(row.sharedPayloadId);
|
|
346
|
-
if (!shared) {
|
|
347
|
-
const payloadId = row.sharedPayloadId;
|
|
348
|
-
const payload = await ctx.db
|
|
349
|
-
.query('multiRecipientPayloads')
|
|
350
|
-
.withIndex('by_payload_id', (q) => q.eq('payloadId', payloadId))
|
|
351
|
-
.unique();
|
|
352
|
-
if (!payload) {
|
|
353
|
-
// ConvexError so the structured {code, status} survives
|
|
354
|
-
// serialization, matching the groups module's integrity-fault
|
|
355
|
-
// rejections. Not a RelayErrorCode: those name request faults,
|
|
356
|
-
// and this one is the server's.
|
|
357
|
-
throw new ConvexError({
|
|
358
|
-
code: 'INTERNAL_ERROR',
|
|
359
|
-
status: 500,
|
|
360
|
-
message: 'Shared multi-recipient payload is missing for a live message',
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
shared = base64ToBytes(asBase64(payload.sharedBase64));
|
|
364
|
-
sharedByPayloadId.set(row.sharedPayloadId, shared);
|
|
365
|
-
}
|
|
366
|
-
const prefix = base64ToBytes(asBase64(row.ciphertext));
|
|
367
|
-
const wire = new Uint8Array(prefix.length + shared.length);
|
|
368
|
-
wire.set(prefix, 0);
|
|
369
|
-
wire.set(shared, prefix.length);
|
|
370
|
-
return bytesToBase64(wire);
|
|
371
|
-
};
|
|
372
|
-
return Promise.all(rows.map(async ({ messageId, targetUserId, targetDeviceId, senderUserId, senderDeviceId, messageType, deliveryClass, timestamp, serverTimestamp, clientMessageId, expiresAt, ...row }) => ({
|
|
373
|
-
id: messageId,
|
|
374
|
-
targetUserId,
|
|
375
|
-
targetDeviceId,
|
|
376
|
-
senderUserId,
|
|
377
|
-
senderDeviceId,
|
|
378
|
-
ciphertext: await wireCiphertext(row),
|
|
379
|
-
messageType,
|
|
380
|
-
deliveryClass,
|
|
381
|
-
timestamp,
|
|
382
|
-
serverTimestamp,
|
|
383
|
-
clientMessageId,
|
|
384
|
-
expiresAt,
|
|
385
|
-
})));
|
|
386
|
-
},
|
|
387
|
-
});
|
|
388
|
-
export const markDelivered = mutation({
|
|
389
|
-
args: {
|
|
390
|
-
...callerIdentityArgs,
|
|
391
|
-
messageId: v.string(),
|
|
392
|
-
},
|
|
393
|
-
returns: v.null(),
|
|
394
|
-
handler: async (ctx, input) => {
|
|
395
|
-
await rememberAccount(ctx, input);
|
|
396
|
-
const message = await ctx.db
|
|
397
|
-
.query('messages')
|
|
398
|
-
.withIndex('by_message_id', (q) => q.eq('messageId', input.messageId))
|
|
399
|
-
.unique();
|
|
400
|
-
if (!message)
|
|
401
|
-
return null;
|
|
402
|
-
if (message.targetUserId !== input.callerUserId) {
|
|
403
|
-
throw unauthorized('only the target account can mark a message delivered');
|
|
404
|
-
}
|
|
405
|
-
await ctx.db.delete(message._id);
|
|
406
|
-
return null;
|
|
407
|
-
},
|
|
408
|
-
});
|
|
409
|
-
// There is deliberately no `getGroupMembers` endpoint, and the component
|
|
410
|
-
// derives no membership map from group state. Group authorization is proved
|
|
411
|
-
// entirely by zero-knowledge presentations, so `groups` rows never name an
|
|
412
|
-
// account. Membership is local-first. Senders resolve fan-out recipients
|
|
413
|
-
// from their own decrypted group state and supply them to the send path.
|
|
414
|
-
//
|
|
415
|
-
// Nothing a `messages` row stores *names* a group either. The row carries a
|
|
416
|
-
// `sender_key` message type, which says the payload is group traffic without
|
|
417
|
-
// saying which group. The distribution identifier inside the frame is
|
|
418
|
-
// opaque.
|
|
419
|
-
//
|
|
420
|
-
// That closes the group's name, not the group partition, and the difference is
|
|
421
|
-
// easy to overstate. The distribution identifier is unencrypted, sits inside
|
|
422
|
-
// the `ciphertext` column, and is stable for the life of a sender key. Keys
|
|
423
|
-
// rotate on membership change, never on a timer, so grouping rows by it
|
|
424
|
-
// recovers a sender's group traffic.
|
|
425
|
-
//
|
|
426
|
-
// One send also produces byte-identical ciphertext on every recipient row, and
|
|
427
|
-
// the multi-recipient sealed path is handed the roster outright. An operator
|
|
428
|
-
// therefore sees who talked to whom and can partition those pairs into
|
|
429
|
-
// unlabeled groups. What it cannot do is put a meaningful, cross-send label on
|
|
430
|
-
// one. See the group metadata privacy note in README.md, which states the
|
|
431
|
-
// remaining channels in full.
|
|
432
|
-
export const getActiveDevices = query({
|
|
433
|
-
args: {
|
|
434
|
-
...callerIdentityArgs,
|
|
435
|
-
userId: v.string(),
|
|
436
|
-
},
|
|
437
|
-
returns: v.array(v.object({
|
|
438
|
-
userId: v.string(),
|
|
439
|
-
deviceId: v.number(),
|
|
440
|
-
})),
|
|
441
|
-
handler: async (ctx, input) => {
|
|
442
|
-
const rows = await ctx.db
|
|
443
|
-
.query('devices')
|
|
444
|
-
.withIndex('by_user_id', (q) => q.eq('userId', input.userId))
|
|
445
|
-
.take(MAX_DEVICES);
|
|
446
|
-
return rows
|
|
447
|
-
.filter((row) => row.registered && row.enabled)
|
|
448
|
-
.map((row) => ({
|
|
449
|
-
userId: input.userId,
|
|
450
|
-
deviceId: row.deviceId,
|
|
451
|
-
}));
|
|
452
|
-
},
|
|
453
|
-
});
|
|
454
|
-
async function authorizeUnidentified(ctx, recipients, auth) {
|
|
455
|
-
const hasAccessKey = auth.unidentifiedAccessKey !== undefined;
|
|
456
|
-
const hasGroupToken = auth.groupSendToken !== undefined;
|
|
457
|
-
if (hasAccessKey === hasGroupToken) {
|
|
458
|
-
throw unauthorized('exactly one sealed-sender authorization is required');
|
|
459
|
-
}
|
|
460
|
-
if (auth.groupSendToken !== undefined) {
|
|
461
|
-
// The caller names the ACI it claims for each recipient. The token
|
|
462
|
-
// endorses ACIs, not user IDs, so it can be verified before any account
|
|
463
|
-
// is read. See authorizeGroupSendToken for why that ordering matters.
|
|
464
|
-
const named = [];
|
|
465
|
-
for (const recipient of recipients) {
|
|
466
|
-
if (recipient.aciBytes === undefined) {
|
|
467
|
-
throw unauthorized('a group-send token requires an ACI for every recipient');
|
|
468
|
-
}
|
|
469
|
-
named.push({ userId: recipient.userId, aciBytes: recipient.aciBytes });
|
|
470
|
-
}
|
|
471
|
-
await authorizeGroupSendToken(ctx, named, auth.groupSendToken);
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
const distinctRecipients = [...new Set(recipients.map((recipient) => recipient.userId))];
|
|
475
|
-
for (const userId of distinctRecipients) {
|
|
476
|
-
await authorizeAccessKey(ctx, userId, auth.unidentifiedAccessKey);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
const multiRecipientValidator = v.object({
|
|
480
|
-
userId: v.string(),
|
|
481
|
-
deviceId: v.number(),
|
|
482
|
-
registrationId: v.number(),
|
|
483
|
-
/** The recipient ACI the caller claims. Required with a group-send token,
|
|
484
|
-
* which endorses ACIs rather than user IDs. */
|
|
485
|
-
aciBytes: v.optional(v.bytes()),
|
|
486
|
-
encryptedMessageKeyBase64: v.string(),
|
|
487
|
-
authenticationTagBase64: v.string(),
|
|
488
|
-
});
|
|
489
|
-
export const sendMultiRecipientUnidentified = mutation({
|
|
490
|
-
args: {
|
|
491
|
-
recipients: v.array(multiRecipientValidator),
|
|
492
|
-
ephemeralPublicBase64: v.string(),
|
|
493
|
-
messageCiphertextBase64: v.string(),
|
|
494
|
-
deliveryClass: deliveryClassValidator,
|
|
495
|
-
timestamp: v.number(),
|
|
496
|
-
clientMessageId: v.optional(v.string()),
|
|
497
|
-
unidentifiedAccessKey: v.optional(v.string()),
|
|
498
|
-
groupSendToken: v.optional(v.bytes()),
|
|
499
|
-
},
|
|
500
|
-
returns: v.object({
|
|
501
|
-
messageId: v.string(),
|
|
502
|
-
serverTimestamp: v.number(),
|
|
503
|
-
uuids404: v.array(v.string()),
|
|
504
|
-
}),
|
|
505
|
-
handler: async (ctx, input) => {
|
|
506
|
-
if (input.recipients.length > MAX_MULTI_RECIPIENT_DEVICES) {
|
|
507
|
-
throw relayError('INVALID_REQUEST', 400, `Multi-recipient delivery supports at most ${MAX_MULTI_RECIPIENT_DEVICES} devices`);
|
|
508
|
-
}
|
|
509
|
-
requireCiphertextWithin(input.messageCiphertextBase64, MAX_MULTI_RECIPIENT_CIPHERTEXT_LENGTH);
|
|
510
|
-
// Per-recipient key material is a fixed-size key and tag. The reference
|
|
511
|
-
// budgets ~100 bytes per recipient block. 512 base64 characters is far
|
|
512
|
-
// above any real encoding and far below a useful flood.
|
|
513
|
-
//
|
|
514
|
-
// One entry per (userId, deviceId). Each accepted entry stores only its
|
|
515
|
-
// own key material next to a reference to the once-stored shared
|
|
516
|
-
// payload. A repeat is still rejected rather than collapsed. A
|
|
517
|
-
// group-send token endorses the recipient *set*, saying nothing about
|
|
518
|
-
// how many times a member may appear in it. A repeat is therefore a
|
|
519
|
-
// client bug, and quietly picking one of two conflicting key blocks
|
|
520
|
-
// would bury it.
|
|
521
|
-
const seenDevices = new Set();
|
|
522
|
-
for (const recipient of input.recipients) {
|
|
523
|
-
requireCiphertextWithin(recipient.encryptedMessageKeyBase64, 512);
|
|
524
|
-
requireCiphertextWithin(recipient.authenticationTagBase64, 512);
|
|
525
|
-
const deviceKey = JSON.stringify([recipient.userId, recipient.deviceId]);
|
|
526
|
-
if (seenDevices.has(deviceKey)) {
|
|
527
|
-
throw relayError('INVALID_REQUEST', 400, 'Multi-recipient delivery names the same device more than once');
|
|
528
|
-
}
|
|
529
|
-
seenDevices.add(deviceKey);
|
|
530
|
-
}
|
|
531
|
-
await authorizeUnidentified(ctx, input.recipients.map((recipient) => ({
|
|
532
|
-
userId: recipient.userId,
|
|
533
|
-
aciBytes: recipient.aciBytes,
|
|
534
|
-
})), input);
|
|
535
|
-
const ephemeralPublic = base64ToBytes(asBase64(input.ephemeralPublicBase64));
|
|
536
|
-
const messageCiphertext = base64ToBytes(asBase64(input.messageCiphertextBase64));
|
|
537
|
-
// The shared remainder is the ephemeral public key and the message
|
|
538
|
-
// ciphertext. It is stored once and referenced from every accepted
|
|
539
|
-
// recipient row. That matches the reference's message store, which
|
|
540
|
-
// inserts one shared multi-recipient payload and hands each recipient a
|
|
541
|
-
// pointer. Storing
|
|
542
|
-
// a copy per row turns a ~100 KiB send into recipient-count times that
|
|
543
|
-
// in one transaction. Created lazily on the first accepted recipient.
|
|
544
|
-
// A request whose recipients all 404 (or all deduplicate) stores
|
|
545
|
-
// nothing new beyond, at worst, one TTL-reaped orphan payload.
|
|
546
|
-
const sharedLength = ephemeralPublic.length + messageCiphertext.length;
|
|
547
|
-
let sharedPayloadId;
|
|
548
|
-
const ensureSharedPayload = async (shared) => {
|
|
549
|
-
if (sharedPayloadId === undefined) {
|
|
550
|
-
sharedPayloadId = crypto.randomUUID();
|
|
551
|
-
await ctx.db.insert('multiRecipientPayloads', {
|
|
552
|
-
payloadId: sharedPayloadId,
|
|
553
|
-
sharedBase64: bytesToBase64(shared),
|
|
554
|
-
expiresAt: Date.now() + MESSAGE_TTL_MS,
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
return sharedPayloadId;
|
|
558
|
-
};
|
|
559
|
-
let first;
|
|
560
|
-
const uuids404 = new Set();
|
|
561
|
-
const chargedUsers = new Set();
|
|
562
|
-
for (const recipient of input.recipients) {
|
|
563
|
-
const device = await ctx.db
|
|
564
|
-
.query('devices')
|
|
565
|
-
.withIndex('by_user_id_and_device_id', (q) => q.eq('userId', recipient.userId).eq('deviceId', recipient.deviceId))
|
|
566
|
-
.unique();
|
|
567
|
-
if (!device?.registered || !device.enabled) {
|
|
568
|
-
uuids404.add(recipient.userId);
|
|
569
|
-
continue;
|
|
570
|
-
}
|
|
571
|
-
const registration = await ctx.db
|
|
572
|
-
.query('identityRegistrations')
|
|
573
|
-
.withIndex('by_user_id_and_device_id_and_identity_type', (q) => q
|
|
574
|
-
.eq('userId', recipient.userId)
|
|
575
|
-
.eq('deviceId', recipient.deviceId)
|
|
576
|
-
.eq('identityType', 'aci'))
|
|
577
|
-
.unique();
|
|
578
|
-
if (registration && registration.registrationId !== recipient.registrationId) {
|
|
579
|
-
uuids404.add(recipient.userId);
|
|
580
|
-
continue;
|
|
581
|
-
}
|
|
582
|
-
if (!chargedUsers.has(recipient.userId)) {
|
|
583
|
-
await chargeInboundBudget(ctx, recipient.userId, ciphertextBytes(input.messageCiphertextBase64));
|
|
584
|
-
chargedUsers.add(recipient.userId);
|
|
585
|
-
}
|
|
586
|
-
// The canonical serializer builds (and validates) the full wire
|
|
587
|
-
// form. The row keeps only the per-recipient prefix (version byte
|
|
588
|
-
// and key material), and delivery reattaches the shared suffix.
|
|
589
|
-
const receivedMessage = serializeReceivedMessage(base64ToBytes(asBase64(recipient.encryptedMessageKeyBase64)), base64ToBytes(asBase64(recipient.authenticationTagBase64)), ephemeralPublic, messageCiphertext);
|
|
590
|
-
const prefix = receivedMessage.subarray(0, receivedMessage.length - sharedLength);
|
|
591
|
-
const result = await insertMessage(ctx, {
|
|
592
|
-
targetUserId: recipient.userId,
|
|
593
|
-
targetDeviceId: recipient.deviceId,
|
|
594
|
-
senderUserId: '',
|
|
595
|
-
senderDeviceId: 0,
|
|
596
|
-
ciphertext: bytesToBase64(prefix),
|
|
597
|
-
messageType: 'unidentified_sender',
|
|
598
|
-
deliveryClass: input.deliveryClass,
|
|
599
|
-
timestamp: input.timestamp,
|
|
600
|
-
clientMessageId: input.clientMessageId,
|
|
601
|
-
sharedPayloadId: await ensureSharedPayload(receivedMessage.subarray(receivedMessage.length - sharedLength)),
|
|
602
|
-
});
|
|
603
|
-
first ??= result;
|
|
604
|
-
}
|
|
605
|
-
const fallbackTimestamp = Date.now();
|
|
606
|
-
return {
|
|
607
|
-
messageId: first?.messageId ?? `multi-${crypto.randomUUID()}`,
|
|
608
|
-
serverTimestamp: first?.serverTimestamp ?? fallbackTimestamp,
|
|
609
|
-
uuids404: [...uuids404],
|
|
610
|
-
};
|
|
611
|
-
},
|
|
612
|
-
});
|
|
613
|
-
export const sendRetryRequest = mutation({
|
|
614
|
-
args: {
|
|
615
|
-
...callerIdentityArgs,
|
|
616
|
-
requesterDeviceId: v.number(),
|
|
617
|
-
originalSenderUserId: v.string(),
|
|
618
|
-
originalSenderDeviceId: v.number(),
|
|
619
|
-
failedTimestamp: v.number(),
|
|
620
|
-
timestamp: v.number(),
|
|
621
|
-
reason: retryReasonValidator,
|
|
622
|
-
},
|
|
623
|
-
returns: v.null(),
|
|
624
|
-
handler: async (ctx, input) => {
|
|
625
|
-
await rememberAccount(ctx, input);
|
|
626
|
-
await chargeRetryRequest(ctx, input.callerUserId);
|
|
627
|
-
await ctx.db.insert('retryRequests', {
|
|
628
|
-
requestId: crypto.randomUUID(),
|
|
629
|
-
requesterUserId: input.callerUserId,
|
|
630
|
-
requesterDeviceId: input.requesterDeviceId,
|
|
631
|
-
originalSenderUserId: input.originalSenderUserId,
|
|
632
|
-
originalSenderDeviceId: input.originalSenderDeviceId,
|
|
633
|
-
failedTimestamp: input.failedTimestamp,
|
|
634
|
-
timestamp: input.timestamp,
|
|
635
|
-
reason: input.reason,
|
|
636
|
-
expiresAt: Date.now() + MESSAGE_TTL_MS,
|
|
637
|
-
});
|
|
638
|
-
return null;
|
|
639
|
-
},
|
|
640
|
-
});
|
|
641
|
-
const retryRequestValidator = v.object({
|
|
642
|
-
id: v.string(),
|
|
643
|
-
requesterUserId: v.string(),
|
|
644
|
-
requesterDeviceId: v.number(),
|
|
645
|
-
originalSenderUserId: v.string(),
|
|
646
|
-
originalSenderDeviceId: v.number(),
|
|
647
|
-
failedTimestamp: v.number(),
|
|
648
|
-
timestamp: v.number(),
|
|
649
|
-
reason: retryReasonValidator,
|
|
650
|
-
});
|
|
651
|
-
export const getPendingRetryRequests = query({
|
|
652
|
-
args: {
|
|
653
|
-
...callerIdentityArgs,
|
|
654
|
-
deviceId: v.number(),
|
|
655
|
-
},
|
|
656
|
-
returns: v.array(retryRequestValidator),
|
|
657
|
-
handler: async (ctx, input) => {
|
|
658
|
-
// Same read-time expiry filter and the same transaction-fixed clock as
|
|
659
|
-
// getPendingMessages. An expired retry request may survive in a cached
|
|
660
|
-
// subscription until the hourly cron deletes it. Acting on a stale retry
|
|
661
|
-
// request costs one redundant re-send, so the window is harmless.
|
|
662
|
-
const now = Date.now();
|
|
663
|
-
const rows = (await ctx.db
|
|
664
|
-
.query('retryRequests')
|
|
665
|
-
.withIndex('by_original_sender_user_id_and_original_sender_device_id', (q) => q
|
|
666
|
-
.eq('originalSenderUserId', input.callerUserId)
|
|
667
|
-
.eq('originalSenderDeviceId', input.deviceId))
|
|
668
|
-
.take(MAX_PENDING_RETRY_REQUESTS)).filter((row) => row.expiresAt > now);
|
|
669
|
-
return rows.map(({ requestId, ...request }) => ({
|
|
670
|
-
id: requestId,
|
|
671
|
-
requesterUserId: request.requesterUserId,
|
|
672
|
-
requesterDeviceId: request.requesterDeviceId,
|
|
673
|
-
originalSenderUserId: request.originalSenderUserId,
|
|
674
|
-
originalSenderDeviceId: request.originalSenderDeviceId,
|
|
675
|
-
failedTimestamp: request.failedTimestamp,
|
|
676
|
-
timestamp: request.timestamp,
|
|
677
|
-
reason: request.reason,
|
|
678
|
-
}));
|
|
679
|
-
},
|
|
680
|
-
});
|
|
681
|
-
export const markRetryRequestHandled = mutation({
|
|
682
|
-
args: {
|
|
683
|
-
...callerIdentityArgs,
|
|
684
|
-
requestId: v.string(),
|
|
685
|
-
},
|
|
686
|
-
returns: v.null(),
|
|
687
|
-
handler: async (ctx, input) => {
|
|
688
|
-
await rememberAccount(ctx, input);
|
|
689
|
-
const request = await ctx.db
|
|
690
|
-
.query('retryRequests')
|
|
691
|
-
.withIndex('by_request_id', (q) => q.eq('requestId', input.requestId))
|
|
692
|
-
.unique();
|
|
693
|
-
if (!request)
|
|
694
|
-
return null;
|
|
695
|
-
if (request.originalSenderUserId !== input.callerUserId) {
|
|
696
|
-
throw unauthorized('only the original sender can handle a retry request');
|
|
697
|
-
}
|
|
698
|
-
await ctx.db.delete(request._id);
|
|
699
|
-
return null;
|
|
700
|
-
},
|
|
701
|
-
});
|
|
702
|
-
//# sourceMappingURL=messages.js.map
|