@open-e2ee/signal-protocol-sdk 0.1.0-alpha.6 → 0.1.0-alpha.8
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 +1 -1
- package/ARCHITECTURE.md +1 -1
- package/CHANGELOG.md +876 -3
- package/COMMERCIAL.md +56 -0
- package/README.md +13 -8
- package/SECURITY.md +15 -1
- package/client/README.md +1 -1
- package/dist/client/client.d.ts +32 -28
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +136 -80
- package/dist/client/client.js.map +1 -1
- package/dist/client/compose.d.ts +6 -1
- package/dist/client/compose.d.ts.map +1 -1
- package/dist/client/compose.js +2 -0
- package/dist/client/compose.js.map +1 -1
- package/dist/client/config.d.ts +53 -19
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js.map +1 -1
- package/dist/client/endorsement-manager.d.ts +23 -2
- package/dist/client/endorsement-manager.d.ts.map +1 -1
- package/dist/client/endorsement-manager.js +35 -10
- package/dist/client/endorsement-manager.js.map +1 -1
- package/dist/client/groups.d.ts +29 -29
- package/dist/client/groups.d.ts.map +1 -1
- package/dist/client/groups.js +54 -37
- package/dist/client/groups.js.map +1 -1
- package/dist/client/headless.d.ts +1 -1
- package/dist/client/headless.js +1 -1
- package/dist/client/sealed-sender-ops.d.ts +27 -1
- package/dist/client/sealed-sender-ops.d.ts.map +1 -1
- package/dist/client/sealed-sender-ops.js +36 -6
- package/dist/client/sealed-sender-ops.js.map +1 -1
- package/dist/client/signal-service-cipher.d.ts +21 -2
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +119 -53
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/types.d.ts +20 -7
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/groups/index.d.ts +4 -4
- package/dist/groups/index.d.ts.map +1 -1
- package/dist/groups/index.js +3 -3
- package/dist/groups/index.js.map +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/crypto/index.d.ts +1 -1
- package/dist/internal/crypto/index.d.ts.map +1 -1
- package/dist/internal/crypto/index.js +1 -1
- package/dist/internal/crypto/index.js.map +1 -1
- package/dist/internal/crypto/random.d.ts +9 -0
- package/dist/internal/crypto/random.d.ts.map +1 -1
- package/dist/internal/crypto/random.js +16 -0
- package/dist/internal/crypto/random.js.map +1 -1
- package/dist/internal/groups/access-control.d.ts +170 -0
- package/dist/internal/groups/access-control.d.ts.map +1 -0
- package/dist/internal/groups/access-control.js +284 -0
- package/dist/internal/groups/access-control.js.map +1 -0
- package/dist/internal/groups/change-actions.d.ts +57 -0
- package/dist/internal/groups/change-actions.d.ts.map +1 -0
- package/dist/internal/groups/change-actions.js +827 -0
- package/dist/internal/groups/change-actions.js.map +1 -0
- package/dist/internal/groups/change-authorization.d.ts +16 -0
- package/dist/internal/groups/change-authorization.d.ts.map +1 -0
- package/dist/internal/groups/change-authorization.js +120 -0
- package/dist/internal/groups/change-authorization.js.map +1 -0
- package/dist/internal/{groups-v2 → groups}/encrypted-state.d.ts +12 -2
- package/dist/internal/groups/encrypted-state.d.ts.map +1 -0
- package/dist/internal/{groups-v2 → groups}/encrypted-state.js +122 -22
- package/dist/internal/groups/encrypted-state.js.map +1 -0
- package/dist/internal/groups/group-id.d.ts +9 -9
- package/dist/internal/groups/group-id.d.ts.map +1 -1
- package/dist/internal/groups/group-id.js +11 -12
- package/dist/internal/groups/group-id.js.map +1 -1
- package/dist/internal/groups/index.d.ts +16 -6
- package/dist/internal/groups/index.d.ts.map +1 -1
- package/dist/internal/groups/index.js +9 -1
- package/dist/internal/groups/index.js.map +1 -1
- package/dist/internal/groups/invite-link.d.ts.map +1 -0
- package/dist/internal/groups/invite-link.js.map +1 -0
- package/dist/internal/{groups-v2 → groups}/manager.d.ts +188 -40
- package/dist/internal/groups/manager.d.ts.map +1 -0
- package/dist/internal/groups/manager.js +1923 -0
- package/dist/internal/groups/manager.js.map +1 -0
- package/dist/internal/groups/sdk-store.d.ts +32 -0
- package/dist/internal/groups/sdk-store.d.ts.map +1 -0
- package/dist/internal/groups/sdk-store.js +111 -0
- package/dist/internal/groups/sdk-store.js.map +1 -0
- package/dist/internal/groups/server-engine.d.ts +83 -0
- package/dist/internal/groups/server-engine.d.ts.map +1 -0
- package/dist/internal/groups/server-engine.js +1186 -0
- package/dist/internal/groups/server-engine.js.map +1 -0
- package/dist/internal/groups/trust-root.d.ts +32 -0
- package/dist/internal/groups/trust-root.d.ts.map +1 -0
- package/dist/internal/groups/trust-root.js +91 -0
- package/dist/internal/groups/trust-root.js.map +1 -0
- package/dist/internal/{groups-v2 → groups}/types.d.ts +188 -46
- package/dist/internal/groups/types.d.ts.map +1 -0
- package/dist/internal/{groups-v2 → groups}/types.js +3 -2
- package/dist/internal/groups/types.js.map +1 -0
- package/dist/internal/groups/wire.d.ts +68 -0
- package/dist/internal/groups/wire.d.ts.map +1 -0
- package/dist/internal/groups/wire.js +708 -0
- package/dist/internal/groups/wire.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/decryption-v2.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/decryption-v2.js +32 -18
- package/dist/internal/protocol/sealed-sender/decryption-v2.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/decryption.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/decryption.js +33 -19
- package/dist/internal/protocol/sealed-sender/decryption.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/encryption-v2.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/encryption-v2.js +8 -14
- package/dist/internal/protocol/sealed-sender/encryption-v2.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/encryption.d.ts +9 -4
- package/dist/internal/protocol/sealed-sender/encryption.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/encryption.js +7 -15
- package/dist/internal/protocol/sealed-sender/encryption.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts +6 -7
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.js +5 -7
- package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/trust-root.d.ts +45 -0
- package/dist/internal/protocol/sealed-sender/trust-root.d.ts.map +1 -0
- package/dist/internal/protocol/sealed-sender/trust-root.js +77 -0
- package/dist/internal/protocol/sealed-sender/trust-root.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/types.d.ts +64 -9
- package/dist/internal/protocol/sealed-sender/types.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.js +43 -0
- package/dist/internal/protocol/sealed-sender/types.js.map +1 -1
- package/dist/internal/protocol/sender-keys/index.d.ts +1 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts +38 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.js +109 -8
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
- package/dist/internal/protocol/zk/groups/auth-credential.d.ts +9 -7
- package/dist/internal/protocol/zk/groups/auth-credential.d.ts.map +1 -1
- package/dist/internal/protocol/zk/groups/auth-credential.js +68 -29
- package/dist/internal/protocol/zk/groups/auth-credential.js.map +1 -1
- package/dist/internal/protocol/zk/groups/server-params.d.ts +1 -1
- package/dist/internal/protocol/zk/groups/server-params.d.ts.map +1 -1
- package/dist/internal/protocol/zk/groups/server-params.js.map +1 -1
- package/dist/internal/protocol/zk/groups/uid-struct.d.ts +2 -0
- package/dist/internal/protocol/zk/groups/uid-struct.d.ts.map +1 -1
- package/dist/internal/protocol/zk/groups/uid-struct.js +4 -0
- package/dist/internal/protocol/zk/groups/uid-struct.js.map +1 -1
- package/dist/layers.d.ts +1 -1
- package/dist/layers.js +3 -3
- package/dist/layers.js.map +1 -1
- package/dist/local/store/expo/adapter.d.ts +14 -15
- package/dist/local/store/expo/adapter.d.ts.map +1 -1
- package/dist/local/store/expo/adapter.js +109 -102
- package/dist/local/store/expo/adapter.js.map +1 -1
- package/dist/local/store/expo/db.d.ts +4 -1
- package/dist/local/store/expo/db.d.ts.map +1 -1
- package/dist/local/store/expo/db.js +5 -0
- package/dist/local/store/expo/db.js.map +1 -1
- package/dist/local/store/expo/index.d.ts +0 -2
- package/dist/local/store/expo/index.d.ts.map +1 -1
- package/dist/local/store/expo/index.js +1 -1
- package/dist/local/store/expo/index.js.map +1 -1
- package/dist/local/store/expo/models/index.d.ts +1 -1
- package/dist/local/store/expo/models/index.d.ts.map +1 -1
- package/dist/local/store/expo/models/index.js +2 -2
- package/dist/local/store/expo/models/index.js.map +1 -1
- package/dist/local/store/expo/models/sender-key.d.ts +101 -77
- package/dist/local/store/expo/models/sender-key.d.ts.map +1 -1
- package/dist/local/store/expo/models/sender-key.js +154 -124
- package/dist/local/store/expo/models/sender-key.js.map +1 -1
- package/dist/local/store/expo/schema.d.ts +134 -32
- package/dist/local/store/expo/schema.d.ts.map +1 -1
- package/dist/local/store/expo/schema.js +36 -7
- package/dist/local/store/expo/schema.js.map +1 -1
- package/dist/local/store/mock/adapter.d.ts +1 -0
- package/dist/local/store/mock/adapter.d.ts.map +1 -1
- package/dist/local/store/mock/adapter.js +18 -0
- package/dist/local/store/mock/adapter.js.map +1 -1
- package/dist/local/store/react-native/adapter.d.ts +39 -0
- package/dist/local/store/react-native/adapter.d.ts.map +1 -1
- package/dist/local/store/react-native/adapter.js +163 -8
- package/dist/local/store/react-native/adapter.js.map +1 -1
- package/dist/local/store/web/adapter.d.ts +1 -0
- package/dist/local/store/web/adapter.d.ts.map +1 -1
- package/dist/local/store/web/adapter.js +33 -1
- package/dist/local/store/web/adapter.js.map +1 -1
- package/dist/remote/relay/convex/backend.d.ts +402 -0
- package/dist/remote/relay/convex/backend.d.ts.map +1 -0
- package/dist/remote/relay/convex/backend.js +684 -0
- package/dist/remote/relay/convex/backend.js.map +1 -0
- package/dist/remote/relay/convex/component/_generated/api.d.ts +58 -0
- package/dist/remote/relay/convex/component/_generated/api.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/_generated/api.js +31 -0
- package/dist/remote/relay/convex/component/_generated/api.js.map +1 -0
- package/dist/remote/relay/convex/component/_generated/component.d.ts +480 -0
- package/dist/remote/relay/convex/component/_generated/component.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/_generated/component.js +11 -0
- package/dist/remote/relay/convex/component/_generated/component.js.map +1 -0
- package/dist/remote/relay/convex/component/_generated/dataModel.d.ts +46 -0
- package/dist/remote/relay/convex/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/_generated/dataModel.js +11 -0
- package/dist/remote/relay/convex/component/_generated/dataModel.js.map +1 -0
- package/dist/remote/relay/convex/component/_generated/server.d.ts +129 -0
- package/dist/remote/relay/convex/component/_generated/server.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/_generated/server.js +79 -0
- package/dist/remote/relay/convex/component/_generated/server.js.map +1 -0
- package/dist/remote/relay/convex/component/accounts.d.ts +43 -0
- package/dist/remote/relay/convex/component/accounts.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/accounts.js +181 -0
- package/dist/remote/relay/convex/component/accounts.js.map +1 -0
- package/dist/remote/relay/convex/component/certificates.d.ts +10 -0
- package/dist/remote/relay/convex/component/certificates.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/certificates.js +122 -0
- package/dist/remote/relay/convex/component/certificates.js.map +1 -0
- package/dist/remote/relay/convex/component/cleanup.d.ts +26 -0
- package/dist/remote/relay/convex/component/cleanup.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/cleanup.js +127 -0
- package/dist/remote/relay/convex/component/cleanup.js.map +1 -0
- package/dist/remote/relay/convex/component/convex.config.d.ts +5 -0
- package/dist/remote/relay/convex/component/convex.config.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/convex.config.js +33 -0
- package/dist/remote/relay/convex/component/convex.config.js.map +1 -0
- package/dist/remote/relay/convex/component/crons.d.ts +3 -0
- package/dist/remote/relay/convex/component/crons.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/crons.js +9 -0
- package/dist/remote/relay/convex/component/crons.js.map +1 -0
- package/dist/remote/relay/convex/component/devices.d.ts +101 -0
- package/dist/remote/relay/convex/component/devices.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/devices.js +299 -0
- package/dist/remote/relay/convex/component/devices.js.map +1 -0
- package/dist/remote/relay/convex/component/errors.d.ts +22 -0
- package/dist/remote/relay/convex/component/errors.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/errors.js +17 -0
- package/dist/remote/relay/convex/component/errors.js.map +1 -0
- package/dist/remote/relay/convex/component/groups.d.ts +60 -0
- package/dist/remote/relay/convex/component/groups.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/groups.js +331 -0
- package/dist/remote/relay/convex/component/groups.js.map +1 -0
- package/dist/remote/relay/convex/component/keys.d.ts +130 -0
- package/dist/remote/relay/convex/component/keys.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/keys.js +578 -0
- package/dist/remote/relay/convex/component/keys.js.map +1 -0
- package/dist/remote/relay/convex/component/messages.d.ts +119 -0
- package/dist/remote/relay/convex/component/messages.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/messages.js +649 -0
- package/dist/remote/relay/convex/component/messages.js.map +1 -0
- package/dist/remote/relay/convex/component/provisioning.d.ts +92 -0
- package/dist/remote/relay/convex/component/provisioning.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/provisioning.js +359 -0
- package/dist/remote/relay/convex/component/provisioning.js.map +1 -0
- package/dist/remote/relay/convex/component/runtime.d.ts +18 -0
- package/dist/remote/relay/convex/component/runtime.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/runtime.js +142 -0
- package/dist/remote/relay/convex/component/runtime.js.map +1 -0
- package/dist/remote/relay/convex/component/schema.d.ts +344 -0
- package/dist/remote/relay/convex/component/schema.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/schema.js +266 -0
- package/dist/remote/relay/convex/component/schema.js.map +1 -0
- package/dist/remote/relay/convex/component/zkAuth.d.ts +12 -0
- package/dist/remote/relay/convex/component/zkAuth.d.ts.map +1 -0
- package/dist/remote/relay/convex/component/zkAuth.js +71 -0
- package/dist/remote/relay/convex/component/zkAuth.js.map +1 -0
- package/dist/remote/relay/convex/constants.d.ts +3 -0
- package/dist/remote/relay/convex/constants.d.ts.map +1 -0
- package/dist/remote/relay/convex/constants.js +3 -0
- package/dist/remote/relay/convex/constants.js.map +1 -0
- package/dist/remote/relay/convex/group-server.d.ts +25 -21
- package/dist/remote/relay/convex/group-server.d.ts.map +1 -1
- package/dist/remote/relay/convex/group-server.js +51 -21
- package/dist/remote/relay/convex/group-server.js.map +1 -1
- package/dist/remote/relay/convex/index.d.ts +4 -1
- package/dist/remote/relay/convex/index.d.ts.map +1 -1
- package/dist/remote/relay/convex/index.js +3 -1
- package/dist/remote/relay/convex/index.js.map +1 -1
- package/dist/remote/relay/convex/relay.d.ts +54 -67
- package/dist/remote/relay/convex/relay.d.ts.map +1 -1
- package/dist/remote/relay/convex/relay.js +123 -42
- package/dist/remote/relay/convex/relay.js.map +1 -1
- package/dist/remote/relay/convex/types.d.ts +16 -103
- package/dist/remote/relay/convex/types.d.ts.map +1 -1
- package/dist/remote/relay/convex/types.js +8 -13
- package/dist/remote/relay/convex/types.js.map +1 -1
- package/dist/remote/relay/index.d.ts +1 -1
- package/dist/remote/relay/index.d.ts.map +1 -1
- package/dist/remote/relay/mock/adapter.d.ts +33 -20
- package/dist/remote/relay/mock/adapter.d.ts.map +1 -1
- package/dist/remote/relay/mock/adapter.js +98 -81
- package/dist/remote/relay/mock/adapter.js.map +1 -1
- package/dist/remote/relay/mock/group-server.d.ts +9 -0
- package/dist/remote/relay/mock/group-server.d.ts.map +1 -0
- package/dist/remote/relay/mock/group-server.js +9 -0
- package/dist/remote/relay/mock/group-server.js.map +1 -0
- package/dist/remote/relay/types.d.ts +73 -79
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/remote/relay/types.js +0 -1
- package/dist/remote/relay/types.js.map +1 -1
- package/dist/types/api.d.ts +23 -2
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/protocol-config.d.ts +51 -0
- package/dist/types/protocol-config.d.ts.map +1 -1
- package/dist/types/protocol-config.js +46 -0
- package/dist/types/protocol-config.js.map +1 -1
- package/docs/ASSURANCE.md +10 -6
- package/docs/CLIENT_COMPOSITION.md +23 -69
- package/docs/DEVIATIONS.md +77 -41
- package/docs/E2EE.md +71 -6
- package/docs/GETTING_STARTED.md +1 -1
- package/docs/PACKAGE_SURFACE.md +6 -0
- package/docs/RECIPES.md +1 -1
- package/docs/SECURITY.md +8 -0
- package/groups/README.md +16 -5
- package/local/store/expo/README.md +10 -1
- package/local/store/node/README.md +10 -1
- package/package.json +20 -4
- package/remote/relay/convex/README.md +6 -0
- package/remote/relay/convex/component/README.md +428 -0
- package/scripts/oe-groups.mjs +162 -0
- package/dist/internal/groups-v2/access-control.d.ts +0 -108
- package/dist/internal/groups-v2/access-control.d.ts.map +0 -1
- package/dist/internal/groups-v2/access-control.js +0 -191
- package/dist/internal/groups-v2/access-control.js.map +0 -1
- package/dist/internal/groups-v2/change-actions.d.ts +0 -40
- package/dist/internal/groups-v2/change-actions.d.ts.map +0 -1
- package/dist/internal/groups-v2/change-actions.js +0 -363
- package/dist/internal/groups-v2/change-actions.js.map +0 -1
- package/dist/internal/groups-v2/encrypted-state.d.ts.map +0 -1
- package/dist/internal/groups-v2/encrypted-state.js.map +0 -1
- package/dist/internal/groups-v2/index.d.ts +0 -19
- package/dist/internal/groups-v2/index.d.ts.map +0 -1
- package/dist/internal/groups-v2/index.js +0 -11
- package/dist/internal/groups-v2/index.js.map +0 -1
- package/dist/internal/groups-v2/invite-link.d.ts.map +0 -1
- package/dist/internal/groups-v2/invite-link.js.map +0 -1
- package/dist/internal/groups-v2/manager.d.ts.map +0 -1
- package/dist/internal/groups-v2/manager.js +0 -1095
- package/dist/internal/groups-v2/manager.js.map +0 -1
- package/dist/internal/groups-v2/types.d.ts.map +0 -1
- package/dist/internal/groups-v2/types.js.map +0 -1
- package/docs/api/README.md +0 -471
- package/docs/api/classes/EncryptionError.md +0 -112
- package/docs/api/classes/EndorsementManager.md +0 -307
- package/docs/api/classes/SealedSenderAuthError.md +0 -127
- package/docs/api/classes/ServerDerivedKeyPair.md +0 -68
- package/docs/api/classes/ServerDerivedPublicKey.md +0 -33
- package/docs/api/classes/ServerRootKeyPair.md +0 -94
- package/docs/api/classes/ServerRootPublicKey.md +0 -72
- package/docs/api/classes/SignalProtocolBlockingManager.md +0 -106
- package/docs/api/classes/SignalProtocolClient.md +0 -2654
- package/docs/api/classes/VerificationFailure.md +0 -25
- package/docs/api/enumerations/ContentHint.md +0 -63
- package/docs/api/enumerations/EncryptionErrorCode.md +0 -488
- package/docs/api/enumerations/IdentityKeyChange.md +0 -65
- package/docs/api/enumerations/MessageType.md +0 -29
- package/docs/api/enumerations/TrustDirection.md +0 -33
- package/docs/api/enumerations/TypingAction.md +0 -31
- package/docs/api/functions/createDefaultSignalProtocolContentAdapter.md +0 -13
- package/docs/api/functions/createDefaultSignalProtocolLogger.md +0 -36
- package/docs/api/functions/createGroupId.md +0 -32
- package/docs/api/functions/createSignalProtocolClient.md +0 -36
- package/docs/api/functions/createSignalProtocolClientConfig.md +0 -24
- package/docs/api/functions/extractGroupId.md +0 -32
- package/docs/api/functions/formatVersion.md +0 -25
- package/docs/api/functions/isCompatible.md +0 -31
- package/docs/api/functions/isGroupId.md +0 -37
- package/docs/api/functions/isSealedSenderAuthError.md +0 -25
- package/docs/api/functions/parseVersion.md +0 -29
- package/docs/api/functions/resolveSPQRLimits.md +0 -21
- package/docs/api/functions/resolveSignalProtocolLogger.md +0 -42
- package/docs/api/interfaces/AccountIdentityProvisioning.md +0 -43
- package/docs/api/interfaces/AccountIdentityRotation.md +0 -69
- package/docs/api/interfaces/AttachmentTransferOptions.md +0 -49
- package/docs/api/interfaces/BlockedRecipientEntry.md +0 -25
- package/docs/api/interfaces/BlockedRecipientsSyncInput.md +0 -27
- package/docs/api/interfaces/ConfigurationSyncInput.md +0 -19
- package/docs/api/interfaces/CredentialPublicKey.md +0 -25
- package/docs/api/interfaces/DataMessageInput.md +0 -21
- package/docs/api/interfaces/DecryptedEnvelope.md +0 -95
- package/docs/api/interfaces/DecryptedGroup.md +0 -86
- package/docs/api/interfaces/DeviceInfo.md +0 -79
- package/docs/api/interfaces/DeviceRecord.md +0 -87
- package/docs/api/interfaces/DeviceRegistration.md +0 -27
- package/docs/api/interfaces/DoubleRatchetConfig.md +0 -36
- package/docs/api/interfaces/EcOneTimePreKey.md +0 -27
- package/docs/api/interfaces/EcSignedPreKey.md +0 -39
- package/docs/api/interfaces/EcSignedPreKeyUpload.md +0 -50
- package/docs/api/interfaces/EncryptionErrorContext.md +0 -51
- package/docs/api/interfaces/Envelope.md +0 -154
- package/docs/api/interfaces/ForceKeyResetResult.md +0 -37
- package/docs/api/interfaces/GroupAuthorization.md +0 -23
- package/docs/api/interfaces/GroupChangeEntry.md +0 -42
- package/docs/api/interfaces/GroupMemberDevice.md +0 -26
- package/docs/api/interfaces/IEcOneTimePreKeyStore.md +0 -86
- package/docs/api/interfaces/IEcSignedPreKeyStore.md +0 -133
- package/docs/api/interfaces/IGroupServer.md +0 -120
- package/docs/api/interfaces/IGroupStateStore.md +0 -128
- package/docs/api/interfaces/IIdentityKeyStore.md +0 -312
- package/docs/api/interfaces/IKemPreKeyStore.md +0 -144
- package/docs/api/interfaces/IKyberLastResortPreKeyStore.md +0 -112
- package/docs/api/interfaces/ILogger.md +0 -117
- package/docs/api/interfaces/IProtocolStore.md +0 -1033
- package/docs/api/interfaces/ISenderKeyStore.md +0 -417
- package/docs/api/interfaces/ISesameStore.md +0 -249
- package/docs/api/interfaces/ISessionStore.md +0 -178
- package/docs/api/interfaces/ISignalProtocolClient.md +0 -1185
- package/docs/api/interfaces/ISignalProtocolLocalSecretVault.md +0 -71
- package/docs/api/interfaces/ISignalProtocolLocalStore.md +0 -2053
- package/docs/api/interfaces/ISignalProtocolManager.md +0 -272
- package/docs/api/interfaces/ISignalProtocolRelayServer.md +0 -1329
- package/docs/api/interfaces/IdentityKeyPair.md +0 -49
- package/docs/api/interfaces/IncomingEnvelope.md +0 -91
- package/docs/api/interfaces/InspectedSignalProtocolContent.md +0 -43
- package/docs/api/interfaces/KDFChain.md +0 -31
- package/docs/api/interfaces/KemLastResortPreKeyUpload.md +0 -50
- package/docs/api/interfaces/KeyPair.md +0 -23
- package/docs/api/interfaces/KyberPreKey.md +0 -42
- package/docs/api/interfaces/MLKEMBraidAgentState.md +0 -191
- package/docs/api/interfaces/MLKEMBraidMessage.md +0 -49
- package/docs/api/interfaces/MediaAttachmentDeleteSyncInput.md +0 -31
- package/docs/api/interfaces/MessageHeader.md +0 -49
- package/docs/api/interfaces/MessageRecord.md +0 -86
- package/docs/api/interfaces/ParsedReceiptContent.md +0 -19
- package/docs/api/interfaces/ParsedTypingContent.md +0 -19
- package/docs/api/interfaces/PreKeyMaintenanceStore.md +0 -88
- package/docs/api/interfaces/PreKeyMessage.md +0 -159
- package/docs/api/interfaces/PreKeyStatusResult.md +0 -21
- package/docs/api/interfaces/PreKeyUpload.md +0 -42
- package/docs/api/interfaces/ProcessEnvelopeOptions.md +0 -72
- package/docs/api/interfaces/ProtocolAddress.md +0 -38
- package/docs/api/interfaces/ProtocolStrategyConfig.md +0 -91
- package/docs/api/interfaces/RatchetMessage.md +0 -96
- package/docs/api/interfaces/ReadSyncEntryInput.md +0 -19
- package/docs/api/interfaces/ReceiverChain.md +0 -43
- package/docs/api/interfaces/RecipientUsernameSyncInput.md +0 -31
- package/docs/api/interfaces/RelayPreKeyBundle.md +0 -254
- package/docs/api/interfaces/RemoteObjectDownload.md +0 -33
- package/docs/api/interfaces/RemoteObjectUpload.md +0 -49
- package/docs/api/interfaces/ResolvedSPQRInfoStrings.md +0 -27
- package/docs/api/interfaces/ResolvedSPQRLimits.md +0 -37
- package/docs/api/interfaces/RetryRequest.md +0 -80
- package/docs/api/interfaces/SCKAState.md +0 -65
- package/docs/api/interfaces/SPQRLimits.md +0 -40
- package/docs/api/interfaces/SPQRState.md +0 -191
- package/docs/api/interfaces/SafetyNumber.md +0 -60
- package/docs/api/interfaces/SafetyNumberConfirmation.md +0 -46
- package/docs/api/interfaces/SealedSenderConfig.md +0 -70
- package/docs/api/interfaces/SendOptions.md +0 -191
- package/docs/api/interfaces/SendResult.md +0 -93
- package/docs/api/interfaces/SenderKeyDistributionMessage.md +0 -43
- package/docs/api/interfaces/SenderKeyState.md +0 -76
- package/docs/api/interfaces/SenderKeysConfig.md +0 -65
- package/docs/api/interfaces/SentSyncTranscriptInput.md +0 -31
- package/docs/api/interfaces/ServiceId.md +0 -19
- package/docs/api/interfaces/SesameMessage.md +0 -84
- package/docs/api/interfaces/SesameStats.md +0 -57
- package/docs/api/interfaces/SessionHealthResult.md +0 -120
- package/docs/api/interfaces/SessionRecord.md +0 -80
- package/docs/api/interfaces/SessionRecordMetadata.md +0 -109
- package/docs/api/interfaces/SessionState.md +0 -368
- package/docs/api/interfaces/SessionTrustCommit.md +0 -58
- package/docs/api/interfaces/SignalProtocolBlockingHooks.md +0 -44
- package/docs/api/interfaces/SignalProtocolBlockingManagerOptions.md +0 -31
- package/docs/api/interfaces/SignalProtocolBlockingMirror.md +0 -30
- package/docs/api/interfaces/SignalProtocolBlockingStore.md +0 -83
- package/docs/api/interfaces/SignalProtocolClientAdapterConfig.md +0 -44
- package/docs/api/interfaces/SignalProtocolClientCompositionOptions.md +0 -693
- package/docs/api/interfaces/SignalProtocolClientConfig.md +0 -839
- package/docs/api/interfaces/SignalProtocolClientDeleteLocalAttachmentInput.md +0 -25
- package/docs/api/interfaces/SignalProtocolClientHooks.md +0 -506
- package/docs/api/interfaces/SignalProtocolClientIdentityConfig.md +0 -35
- package/docs/api/interfaces/SignalProtocolClientLoadLocalAttachmentInput.md +0 -187
- package/docs/api/interfaces/SignalProtocolClientLoadedLocalAttachment.md +0 -19
- package/docs/api/interfaces/SignalProtocolClientMedia.md +0 -83
- package/docs/api/interfaces/SignalProtocolClientMediaCompletedResult.md +0 -25
- package/docs/api/interfaces/SignalProtocolClientMediaConfig.md +0 -157
- package/docs/api/interfaces/SignalProtocolClientMediaDownloadCompletedResult.md +0 -37
- package/docs/api/interfaces/SignalProtocolClientMediaDownloadNotNeededResult.md +0 -25
- package/docs/api/interfaces/SignalProtocolClientMediaFailedResult.md +0 -19
- package/docs/api/interfaces/SignalProtocolClientMediaOperationOptions.md +0 -53
- package/docs/api/interfaces/SignalProtocolClientMediaPendingResult.md +0 -19
- package/docs/api/interfaces/SignalProtocolClientMediaProcessResult.md +0 -43
- package/docs/api/interfaces/SignalProtocolClientMediaSkippedResult.md +0 -25
- package/docs/api/interfaces/SignalProtocolClientMediaUploadCompletedResult.md +0 -31
- package/docs/api/interfaces/SignalProtocolClientProcessPendingMediaOptions.md +0 -87
- package/docs/api/interfaces/SignalProtocolClientSaveDownloadedAttachmentInput.md +0 -25
- package/docs/api/interfaces/SignalProtocolClientSaveUploadedAttachmentInput.md +0 -25
- package/docs/api/interfaces/SignalProtocolClientSyncDeleteInput.md +0 -19
- package/docs/api/interfaces/SignalProtocolConfig.md +0 -50
- package/docs/api/interfaces/SignalProtocolContentAdapter.md +0 -325
- package/docs/api/interfaces/SignalProtocolRemoteObjectStore.md +0 -88
- package/docs/api/interfaces/SkippedSenderMessageKey.md +0 -26
- package/docs/api/interfaces/TaskNotificationAckSyncInput.md +0 -31
- package/docs/api/interfaces/TripleRatchetState.md +0 -64
- package/docs/api/interfaces/UserRecord.md +0 -71
- package/docs/api/interfaces/UsernameStateSyncInput.md +0 -19
- package/docs/api/interfaces/VerificationStateSyncInput.md +0 -31
- package/docs/api/interfaces/VersionNegotiationState.md +0 -84
- package/docs/api/interfaces/ViewOnceOpenSyncInput.md +0 -19
- package/docs/api/namespaces/ProtocolAddress/README.md +0 -33
- package/docs/api/namespaces/ProtocolAddress/functions/create.md +0 -41
- package/docs/api/namespaces/ProtocolAddress/functions/equals.md +0 -39
- package/docs/api/namespaces/ProtocolAddress/functions/fromStorageKey.md +0 -36
- package/docs/api/namespaces/ProtocolAddress/functions/isUser.md +0 -39
- package/docs/api/namespaces/ProtocolAddress/functions/isValid.md +0 -34
- package/docs/api/namespaces/ProtocolAddress/functions/parse.md +0 -41
- package/docs/api/namespaces/ProtocolAddress/functions/toStorageKey.md +0 -38
- package/docs/api/namespaces/ProtocolAddress/functions/toString.md +0 -34
- package/docs/api/namespaces/SessionRecord/README.md +0 -30
- package/docs/api/namespaces/SessionRecord/functions/archiveCurrent.md +0 -40
- package/docs/api/namespaces/SessionRecord/functions/archiveCurrentState.md +0 -34
- package/docs/api/namespaces/SessionRecord/functions/create.md +0 -25
- package/docs/api/namespaces/SessionRecord/functions/deserialize.md +0 -29
- package/docs/api/namespaces/SessionRecord/functions/findSession.md +0 -34
- package/docs/api/namespaces/SessionRecord/functions/getAllSessions.md +0 -25
- package/docs/api/namespaces/SessionRecord/functions/getArchivedCount.md +0 -25
- package/docs/api/namespaces/SessionRecord/functions/hasCurrentSession.md +0 -25
- package/docs/api/namespaces/SessionRecord/functions/hasUsableSenderChain.md +0 -36
- package/docs/api/namespaces/SessionRecord/functions/promoteSession.md +0 -34
- package/docs/api/namespaces/SessionRecord/functions/serialize.md +0 -28
- package/docs/api/namespaces/SessionRecord/variables/MAX_ARCHIVED_SESSIONS.md +0 -14
- package/docs/api/namespaces/SessionState/README.md +0 -15
- package/docs/api/namespaces/SessionState/functions/getSessionId.md +0 -32
- package/docs/api/namespaces/blocking/README.md +0 -43
- package/docs/api/namespaces/encoding/README.md +0 -33
- package/docs/api/namespaces/encoding/functions/base64ToUrlSafe.md +0 -28
- package/docs/api/namespaces/encoding/functions/bytesToBase64.md +0 -21
- package/docs/api/namespaces/encoding/functions/bytesToString.md +0 -21
- package/docs/api/namespaces/encoding/functions/bytesToUrlSafeBase64.md +0 -33
- package/docs/api/namespaces/encoding/functions/concatBytes.md +0 -21
- package/docs/api/namespaces/encoding/functions/stringToBytes.md +0 -21
- package/docs/api/namespaces/encoding/functions/urlSafeToBase64.md +0 -27
- package/docs/api/namespaces/keys/README.md +0 -130
- package/docs/api/namespaces/keys/functions/acceptContactIdentityRotation.md +0 -33
- package/docs/api/namespaces/keys/functions/assertIdentityCommitment.md +0 -25
- package/docs/api/namespaces/keys/functions/canonicalizeDeviceIdentityKey.md +0 -30
- package/docs/api/namespaces/keys/functions/compareDeviceIdentityKeys.md +0 -28
- package/docs/api/namespaces/keys/functions/compositeIdentitiesEqual.md +0 -23
- package/docs/api/namespaces/keys/functions/createCompositeIdentityV1.md +0 -19
- package/docs/api/namespaces/keys/functions/createPreKeySignatureContext.md +0 -31
- package/docs/api/namespaces/keys/functions/createUnverifiedContactIdentityRecord.md +0 -23
- package/docs/api/namespaces/keys/functions/decodeCompositeIdentityV1.md +0 -19
- package/docs/api/namespaces/keys/functions/deriveIdentityCommitment.md +0 -19
- package/docs/api/namespaces/keys/functions/encodeCompositeIdentityV1.md +0 -19
- package/docs/api/namespaces/keys/functions/evaluateContactIdentityCandidate.md +0 -27
- package/docs/api/namespaces/keys/functions/generateEcOneTimePreKeys.md +0 -37
- package/docs/api/namespaces/keys/functions/generateEcSignedPreKey.md +0 -39
- package/docs/api/namespaces/keys/functions/generateEcSignedPreKeyId.md +0 -21
- package/docs/api/namespaces/keys/functions/generateIdentityKeyPair.md +0 -24
- package/docs/api/namespaces/keys/functions/generateKemOneTimePreKeys.md +0 -47
- package/docs/api/namespaces/keys/functions/generateKyberLastResortPreKey.md +0 -37
- package/docs/api/namespaces/keys/functions/generateRegistrationId.md +0 -13
- package/docs/api/namespaces/keys/functions/isValidDeviceIdentityKey.md +0 -22
- package/docs/api/namespaces/keys/functions/signMlKem1024PreKey.md +0 -29
- package/docs/api/namespaces/keys/functions/signPreKey.md +0 -31
- package/docs/api/namespaces/keys/functions/validateContactIdentityRecord.md +0 -19
- package/docs/api/namespaces/keys/functions/verifyContactIdentityRecord.md +0 -31
- package/docs/api/namespaces/keys/functions/verifyMlKem1024PreKey.md +0 -33
- package/docs/api/namespaces/keys/functions/verifyPreKeySignature.md +0 -35
- package/docs/api/namespaces/keys/interfaces/CompositeIdentityV1.md +0 -33
- package/docs/api/namespaces/keys/interfaces/ContactIdentityRecord.md +0 -53
- package/docs/api/namespaces/keys/interfaces/KemOneTimePreKey.md +0 -43
- package/docs/api/namespaces/keys/type-aliases/IdentityCandidateStatus.md +0 -9
- package/docs/api/namespaces/keys/type-aliases/IdentityTrustState.md +0 -9
- package/docs/api/namespaces/keys/type-aliases/IdentityType.md +0 -9
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_ED25519_TAG.md +0 -9
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_LENGTH.md +0 -9
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_VERSION.md +0 -9
- package/docs/api/namespaces/keys/variables/COMPOSITE_IDENTITY_V1_X25519_TAG.md +0 -9
- package/docs/api/namespaces/keys/variables/IDENTITY_COMMITMENT_V1_DOMAIN.md +0 -9
- package/docs/api/namespaces/keys/variables/PREKEY_ALGORITHM_ML_KEM_1024.md +0 -9
- package/docs/api/namespaces/keys/variables/PREKEY_ALGORITHM_X25519.md +0 -9
- package/docs/api/namespaces/keys/variables/PREKEY_SIGNATURE_V1_DOMAIN.md +0 -9
- package/docs/api/namespaces/keys/variables/UNPINNED_DEVICE_IDENTITY_KEY.md +0 -18
- package/docs/api/namespaces/media/README.md +0 -105
- package/docs/api/namespaces/media/classes/MediaAttachmentError.md +0 -57
- package/docs/api/namespaces/media/functions/createByteRangeMediaAttachmentTransfer.md +0 -19
- package/docs/api/namespaces/media/functions/createMediaAttachmentDeliveryId.md +0 -29
- package/docs/api/namespaces/media/functions/createMediaAttachmentId.md +0 -19
- package/docs/api/namespaces/media/functions/createMediaAttachmentMessage.md +0 -25
- package/docs/api/namespaces/media/functions/createMediaAttachmentPointer.md +0 -19
- package/docs/api/namespaces/media/functions/createTusMediaAttachmentTransfer.md +0 -19
- package/docs/api/namespaces/media/functions/deleteMediaAttachment.md +0 -23
- package/docs/api/namespaces/media/functions/executeMediaAttachmentJob.md +0 -23
- package/docs/api/namespaces/media/functions/isMediaAttachmentFlagSet.md +0 -19
- package/docs/api/namespaces/media/functions/parseMediaAttachmentMessage.md +0 -19
- package/docs/api/namespaces/media/functions/planMediaAttachmentCleanup.md +0 -23
- package/docs/api/namespaces/media/functions/planMediaAttachmentCleanupJobs.md +0 -19
- package/docs/api/namespaces/media/functions/planMediaAttachmentDeleteSync.md +0 -19
- package/docs/api/namespaces/media/functions/planMediaAttachmentDownloadJob.md +0 -19
- package/docs/api/namespaces/media/functions/planMediaAttachmentOpen.md +0 -19
- package/docs/api/namespaces/media/functions/planMediaAttachmentProcessing.md +0 -19
- package/docs/api/namespaces/media/functions/planMediaAttachmentUploadJob.md +0 -19
- package/docs/api/namespaces/media/functions/prepareMediaAttachmentUpload.md +0 -30
- package/docs/api/namespaces/media/functions/resolveMediaAttachment.md +0 -30
- package/docs/api/namespaces/media/functions/serializeMediaAttachmentMessage.md +0 -25
- package/docs/api/namespaces/media/functions/validateMediaAttachmentPolicy.md +0 -23
- package/docs/api/namespaces/media/interfaces/ByteRangeMediaAttachmentPartialStore.md +0 -68
- package/docs/api/namespaces/media/interfaces/ByteRangeMediaAttachmentTransferOptions.md +0 -91
- package/docs/api/namespaces/media/interfaces/DeleteMediaAttachmentOptions.md +0 -25
- package/docs/api/namespaces/media/interfaces/DeleteMediaAttachmentResult.md +0 -19
- package/docs/api/namespaces/media/interfaces/ExecuteMediaAttachmentJobOptions.md +0 -157
- package/docs/api/namespaces/media/interfaces/MediaAttachmentBackgroundJob.md +0 -85
- package/docs/api/namespaces/media/interfaces/MediaAttachmentCleanupPlan.md +0 -37
- package/docs/api/namespaces/media/interfaces/MediaAttachmentJobExecutionResult.md +0 -55
- package/docs/api/namespaces/media/interfaces/MediaAttachmentMessage.md +0 -31
- package/docs/api/namespaces/media/interfaces/MediaAttachmentOpenDecision.md +0 -31
- package/docs/api/namespaces/media/interfaces/MediaAttachmentPointer.md +0 -133
- package/docs/api/namespaces/media/interfaces/MediaAttachmentPolicy.md +0 -67
- package/docs/api/namespaces/media/interfaces/MediaAttachmentProcessingPlan.md +0 -73
- package/docs/api/namespaces/media/interfaces/MediaAttachmentProgress.md +0 -69
- package/docs/api/namespaces/media/interfaces/MediaAttachmentResumeState.md +0 -37
- package/docs/api/namespaces/media/interfaces/MediaAttachmentRetryOptions.md +0 -31
- package/docs/api/namespaces/media/interfaces/MediaAttachmentTransfer.md +0 -51
- package/docs/api/namespaces/media/interfaces/MediaAttachmentTransferCheckpoint.md +0 -69
- package/docs/api/namespaces/media/interfaces/MediaAttachmentTransferOptions.md +0 -67
- package/docs/api/namespaces/media/interfaces/MediaAttachmentUploadJobData.md +0 -19
- package/docs/api/namespaces/media/interfaces/MediaAttachmentUploadResponse.md +0 -25
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentCleanupJobsInput.md +0 -61
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentDeleteSyncInput.md +0 -25
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentDownloadJobInput.md +0 -161
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentOpenInput.md +0 -25
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentProcessingInput.md +0 -83
- package/docs/api/namespaces/media/interfaces/PlanMediaAttachmentUploadJobInput.md +0 -147
- package/docs/api/namespaces/media/interfaces/PrepareMediaAttachmentUploadOptions.md +0 -144
- package/docs/api/namespaces/media/interfaces/ResolveMediaAttachmentOptions.md +0 -55
- package/docs/api/namespaces/media/interfaces/ResolvedMediaAttachment.md +0 -109
- package/docs/api/namespaces/media/interfaces/TusMediaAttachmentTransferOptions.md +0 -85
- package/docs/api/namespaces/media/type-aliases/CreateMediaAttachmentPointerInput.md +0 -15
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentCheckpointCallback.md +0 -19
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentCleanupReason.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentErrorCode.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentFlag.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobExecutionStatus.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobOperation.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobPriority.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobSkipReason.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentJobSource.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentKnownIds.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentMessageType.md +0 -9
- package/docs/api/namespaces/media/type-aliases/MediaAttachmentProgressCallback.md +0 -19
- package/docs/api/namespaces/media/variables/MEDIA_ATTACHMENT_POLICY_DEFAULTS.md +0 -47
- package/docs/api/namespaces/media/variables/MEDIA_ATTACHMENT_POLICY_PRESETS.md +0 -95
- package/docs/api/namespaces/media/variables/MediaAttachmentCleanupReason.md +0 -27
- package/docs/api/namespaces/media/variables/MediaAttachmentErrorCode.md +0 -75
- package/docs/api/namespaces/media/variables/MediaAttachmentFlag.md +0 -23
- package/docs/api/namespaces/media/variables/MediaAttachmentJobExecutionStatus.md +0 -19
- package/docs/api/namespaces/media/variables/MediaAttachmentJobOperation.md +0 -31
- package/docs/api/namespaces/media/variables/MediaAttachmentJobPriority.md +0 -23
- package/docs/api/namespaces/media/variables/MediaAttachmentJobSource.md +0 -51
- package/docs/api/namespaces/media/variables/MediaAttachmentMessageType.md +0 -15
- package/docs/api/namespaces/media/variables/downloadMediaAttachment.md +0 -30
- package/docs/api/namespaces/safety/README.md +0 -61
- package/docs/api/namespaces/safety/classes/DisplayableFingerprint.md +0 -108
- package/docs/api/namespaces/safety/classes/Fingerprint.md +0 -104
- package/docs/api/namespaces/safety/classes/ScannableFingerprint.md +0 -209
- package/docs/api/namespaces/safety/functions/base64ToBytes.md +0 -21
- package/docs/api/namespaces/safety/functions/clearFingerprintCache.md +0 -15
- package/docs/api/namespaces/safety/functions/compareSafetyNumbers.md +0 -25
- package/docs/api/namespaces/safety/functions/createFingerprintData.md +0 -60
- package/docs/api/namespaces/safety/functions/extractQrData.md +0 -34
- package/docs/api/namespaces/safety/functions/generateCompositeSafetyNumber.md +0 -39
- package/docs/api/namespaces/safety/functions/generateEmojiFingerprint.md +0 -24
- package/docs/api/namespaces/safety/functions/generateSingleKeyReferenceSafetyNumber.md +0 -51
- package/docs/api/namespaces/safety/functions/generateVerifySchemeUrl.md +0 -32
- package/docs/api/namespaces/safety/functions/generateVerifyUrl.md +0 -49
- package/docs/api/namespaces/safety/functions/isValidSafetyNumber.md +0 -21
- package/docs/api/namespaces/safety/functions/isVerifyUrl.md +0 -45
- package/docs/api/namespaces/safety/functions/parseVerifyUrl.md +0 -31
- package/docs/api/namespaces/safety/interfaces/FingerprintData.md +0 -52
- package/docs/api/namespaces/safety/interfaces/SafetyNumber.md +0 -49
- package/docs/api/namespaces/safety/interfaces/VerifyLinkConfig.md +0 -28
- package/docs/api/namespaces/safety/interfaces/VerifyUrlParams.md +0 -49
- package/docs/api/namespaces/safety/type-aliases/CompareResult.md +0 -21
- package/docs/api/namespaces/safety/variables/DEFAULT_VERIFY_LINK_CONFIG.md +0 -12
- package/docs/api/namespaces/safety/variables/FINGERPRINT_ITERATIONS.md +0 -12
- package/docs/api/namespaces/safety/variables/FINGERPRINT_VERSION.md +0 -12
- package/docs/api/namespaces/safety/variables/VERIFY_BASE_URL.md +0 -11
- package/docs/api/namespaces/safety/variables/VERIFY_SCHEME_URL.md +0 -11
- package/docs/api/type-aliases/Base64.md +0 -20
- package/docs/api/type-aliases/BraidPolicy.md +0 -11
- package/docs/api/type-aliases/Bytes.md +0 -20
- package/docs/api/type-aliases/Ciphertext.md +0 -21
- package/docs/api/type-aliases/DeviceType.md +0 -11
- package/docs/api/type-aliases/DownloadedAttachment.md +0 -11
- package/docs/api/type-aliases/GroupId.md +0 -27
- package/docs/api/type-aliases/Hex.md +0 -20
- package/docs/api/type-aliases/HookName.md +0 -11
- package/docs/api/type-aliases/PostQuantumPolicy.md +0 -11
- package/docs/api/type-aliases/PreparedAttachmentUpload.md +0 -14
- package/docs/api/type-aliases/PrivateKey.md +0 -22
- package/docs/api/type-aliases/ProgressCallback.md +0 -45
- package/docs/api/type-aliases/PublicKey.md +0 -22
- package/docs/api/type-aliases/RemoteObjectCompleteUploadRequest.md +0 -19
- package/docs/api/type-aliases/RemoteObjectDeleteRequest.md +0 -19
- package/docs/api/type-aliases/RemoteObjectDownloadRequest.md +0 -19
- package/docs/api/type-aliases/RemoteObjectUploadRequest.md +0 -42
- package/docs/api/type-aliases/SCKAMode.md +0 -11
- package/docs/api/type-aliases/SealedSenderAuth.md +0 -15
- package/docs/api/type-aliases/SignalProtocolClientMediaCleanupInput.md +0 -9
- package/docs/api/type-aliases/SignalProtocolClientMediaCleanupResult.md +0 -9
- package/docs/api/type-aliases/SignalProtocolClientMediaDownloadInput.md +0 -9
- package/docs/api/type-aliases/SignalProtocolClientMediaDownloadResult.md +0 -9
- package/docs/api/type-aliases/SignalProtocolClientMediaOperationResult.md +0 -9
- package/docs/api/type-aliases/SignalProtocolClientMediaUploadInput.md +0 -9
- package/docs/api/type-aliases/SignalProtocolClientMediaUploadResult.md +0 -9
- package/docs/api/type-aliases/Signature.md +0 -21
- package/docs/api/type-aliases/Unsubscribe.md +0 -15
- package/docs/api/variables/BraidPolicy.md +0 -21
- package/docs/api/variables/DEFAULT_DEVICE_ID.md +0 -12
- package/docs/api/variables/DOUBLE_RATCHET_SPEC.md +0 -11
- package/docs/api/variables/GROUP_V2_PREFIX.md +0 -11
- package/docs/api/variables/KEY_REFRESH_INTERVAL_MS_DEFAULT.md +0 -11
- package/docs/api/variables/MAX_MESSAGE_KEYS.md +0 -14
- package/docs/api/variables/MAX_PREKEY_AGE_MS_DEFAULT.md +0 -11
- package/docs/api/variables/MAX_RECEIVER_CHAINS.md +0 -14
- package/docs/api/variables/MAX_REGISTRATION_ID.md +0 -16
- package/docs/api/variables/MAX_SKIP.md +0 -11
- package/docs/api/variables/MESSAGE_FORMAT.md +0 -11
- package/docs/api/variables/MIN_REGISTRATION_ID.md +0 -16
- package/docs/api/variables/ML_KEM_BRAID_SPEC.md +0 -11
- package/docs/api/variables/ONE_TIME_PREKEY_BATCH_SIZE.md +0 -21
- package/docs/api/variables/PQXDH_SPEC.md +0 -11
- package/docs/api/variables/PostQuantumPolicy.md +0 -21
- package/docs/api/variables/SENDER_KEY_FORMAT.md +0 -11
- package/docs/api/variables/SENDER_KEY_SPEC.md +0 -11
- package/docs/api/variables/SESAME_SPEC.md +0 -11
- package/docs/api/variables/SESSION_FORMAT.md +0 -11
- package/docs/api/variables/SPQR_LIMITS_DEFAULTS.md +0 -11
- package/docs/api/variables/X3DH_SPEC.md +0 -9
- package/docs/api/variables/defaultSignalProtocolLogger.md +0 -32
- /package/dist/internal/{groups-v2 → groups}/invite-link.d.ts +0 -0
- /package/dist/internal/{groups-v2 → groups}/invite-link.js +0 -0
|
@@ -0,0 +1,1923 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Group manager
|
|
3
|
+
*
|
|
4
|
+
* Orchestrates group lifecycle operations:
|
|
5
|
+
* - Group creation/deletion
|
|
6
|
+
* - Membership changes (add, remove, promote, ban)
|
|
7
|
+
* - Attribute updates (title, description, avatar, timer)
|
|
8
|
+
* - State sync from server (change log replay)
|
|
9
|
+
* - Invite link management
|
|
10
|
+
* - Sender key rotation on membership removal
|
|
11
|
+
*
|
|
12
|
+
* The manager coordinates between:
|
|
13
|
+
* - zero-knowledge group cryptography for encryption/decryption
|
|
14
|
+
* - Encrypted state layer for serialization
|
|
15
|
+
* - Change actions for state transitions
|
|
16
|
+
* - Access control for authorization
|
|
17
|
+
* - SenderKeyManager for group messaging key rotation
|
|
18
|
+
* - Server relay for state storage
|
|
19
|
+
*
|
|
20
|
+
* @module groups/manager
|
|
21
|
+
*/
|
|
22
|
+
import { SERVICE_ID_ACI, SERVICE_ID_PNI, serviceIdBinary, groupMasterKey, deriveGroupSecretParams, getGroupPublicParams, GROUP_MASTER_KEY_LEN, encryptUuid, decryptUuid, decryptProfileKeyCiphertext, serverVerifySignature, } from '../protocol/zk/groups/index.js';
|
|
23
|
+
import { isNilUuid } from '../protocol/zk/groups/uid-struct.js';
|
|
24
|
+
import { MemberRole, AccessRequired, EnabledState, defaultAccessControl, emptyGroupChange, } from './types.js';
|
|
25
|
+
import { encryptGroupState, decryptGroupState, decryptGroupJoinInfo, encryptMember, encryptLabelAsBlob, decryptLabelFromBlob, encryptGroupTitle, decryptGroupTitle, encryptGroupDescription, decryptGroupDescription, encryptDisappearingMessagesTimer, decryptDisappearingMessagesTimer, } from './encrypted-state.js';
|
|
26
|
+
import { applyGroupChange, validateChangeAccessControl, validateChangeIdentifiers, validateChangeMemberRoles, validateChangeStructure, } from './change-actions.js';
|
|
27
|
+
import { canPerformAction, GroupAction, isMember, isPending, isBanned, isStoredMemberRole, satisfiesLiveGroupAdministratorInvariant, } from './access-control.js';
|
|
28
|
+
import { validateChangeAuthorization } from './change-authorization.js';
|
|
29
|
+
import { createGroupInviteLink, parseGroupInviteLink, generateInviteLinkPassword, } from './invite-link.js';
|
|
30
|
+
import { createGroupId, extractGroupId } from '../groups/group-id.js';
|
|
31
|
+
import { constantTimeEqual as bytesEqual } from '../crypto/utils.js';
|
|
32
|
+
import { bytesToHex } from '../../encoding/hex.js';
|
|
33
|
+
import { receiveAuthCredential, presentAuthCredential, deserializeAuthCredentialResponse, serializeAuthCredentialPresentation, serializeGroupPublicParams, } from '../protocol/zk/groups/auth-credential.js';
|
|
34
|
+
import { receiveProfileKeyCredential, deserializeProfileKeyCredentialResponse, } from '../protocol/zk/groups/profile-key-credential.js';
|
|
35
|
+
import { SECONDS_PER_DAY } from '../protocol/zk/groups/group-params.js';
|
|
36
|
+
import AsyncLock from 'async-lock';
|
|
37
|
+
import { assertEncryptedGroupChangeForm, assertValidEncryptedGroupChangeWire, assertValidEncryptedGroupWire, deserializeEncryptedGroup, deserializeEncryptedGroupChange, deserializeEncryptedGroupJoinInfo, serializeEncryptedGroupCreationSubmission, serializeEncryptedGroupChange, serializeGroupBaseline, serializeGroupChangeCommitment, countGroupChangeActions, requiredGroupChangeEpoch, toEncryptedGroupCreationSubmission, } from './wire.js';
|
|
38
|
+
function classifyGroupMemberInput(member) {
|
|
39
|
+
const invalid = (detail) => {
|
|
40
|
+
throw new Error(`INVALID_GROUP_MEMBER_INPUT: ${detail}`);
|
|
41
|
+
};
|
|
42
|
+
if (typeof member !== 'object' ||
|
|
43
|
+
member === null ||
|
|
44
|
+
Array.isArray(member)) {
|
|
45
|
+
return invalid('Member must be exactly one supported input variant');
|
|
46
|
+
}
|
|
47
|
+
const hasOwn = (field) => Object.prototype.hasOwnProperty.call(member, field);
|
|
48
|
+
const hasPresentation = hasOwn('profileKeyCredential');
|
|
49
|
+
const hasServiceId = hasOwn('serviceIdBytes');
|
|
50
|
+
if (hasPresentation === hasServiceId) {
|
|
51
|
+
return invalid('Member must be exactly one of a presented member or an invitation');
|
|
52
|
+
}
|
|
53
|
+
const allowedFields = new Set(hasPresentation
|
|
54
|
+
? ['aciBytes', 'profileKey', 'profileKeyCredential', 'role']
|
|
55
|
+
: ['serviceIdBytes', 'role']);
|
|
56
|
+
const unexpected = Object.keys(member).find((field) => !allowedFields.has(field));
|
|
57
|
+
if (unexpected !== undefined) {
|
|
58
|
+
return invalid(`Member contains unsupported field ${unexpected}`);
|
|
59
|
+
}
|
|
60
|
+
if (member.role !== undefined &&
|
|
61
|
+
!isStoredMemberRole(member.role)) {
|
|
62
|
+
return invalid('Member role is outside its stored-role domain');
|
|
63
|
+
}
|
|
64
|
+
if (hasPresentation) {
|
|
65
|
+
const presented = member;
|
|
66
|
+
if (!(presented.aciBytes instanceof Uint8Array) ||
|
|
67
|
+
presented.aciBytes.length !== 16) {
|
|
68
|
+
return invalid('Presented member ACI must be 16-byte data');
|
|
69
|
+
}
|
|
70
|
+
if (!(presented.profileKey instanceof Uint8Array) ||
|
|
71
|
+
presented.profileKey.length !== 32) {
|
|
72
|
+
return invalid('Presented member profile key must be 32-byte data');
|
|
73
|
+
}
|
|
74
|
+
const credential = presented.profileKeyCredential;
|
|
75
|
+
const credentialRecord = typeof credential === 'object' && credential !== null
|
|
76
|
+
? credential
|
|
77
|
+
: undefined;
|
|
78
|
+
const hasObjectField = (field) => {
|
|
79
|
+
const value = credentialRecord?.[field];
|
|
80
|
+
return typeof value === 'object' && value !== null;
|
|
81
|
+
};
|
|
82
|
+
if (credentialRecord === undefined ||
|
|
83
|
+
!hasObjectField('credential') ||
|
|
84
|
+
!hasObjectField('aci') ||
|
|
85
|
+
!hasObjectField('profileKey') ||
|
|
86
|
+
!Number.isSafeInteger(credentialRecord.redemptionTime)) {
|
|
87
|
+
return invalid('Presented member must carry a complete verified profile-key credential');
|
|
88
|
+
}
|
|
89
|
+
return 'presented';
|
|
90
|
+
}
|
|
91
|
+
const invited = member;
|
|
92
|
+
if (!(invited.serviceIdBytes instanceof Uint8Array)) {
|
|
93
|
+
return invalid('Invitation ServiceId must be byte data');
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
assertServiceIdBytes(invited.serviceIdBytes);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
return invalid(error instanceof Error ? error.message : 'Invitation ServiceId is invalid');
|
|
100
|
+
}
|
|
101
|
+
return 'invited';
|
|
102
|
+
}
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// GroupManager
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
/**
|
|
107
|
+
* Manages group lifecycle and state.
|
|
108
|
+
*
|
|
109
|
+
* This is the primary entry point for group operations. It coordinates
|
|
110
|
+
* between crypto primitives, storage, and server communication.
|
|
111
|
+
*/
|
|
112
|
+
/** Default maximum group size enforced by the manager. */
|
|
113
|
+
export const MAX_GROUP_SIZE = 1000;
|
|
114
|
+
export const MAX_SUPPORTED_CHANGE_EPOCH = 6;
|
|
115
|
+
export class GroupManager {
|
|
116
|
+
store;
|
|
117
|
+
server;
|
|
118
|
+
onSenderKeyRotation;
|
|
119
|
+
onEndorsementsInvalidated;
|
|
120
|
+
issueCredential;
|
|
121
|
+
credentialPublicKey;
|
|
122
|
+
serverSigningPublicKey;
|
|
123
|
+
aci;
|
|
124
|
+
pni;
|
|
125
|
+
issueProfileKeyCredentialFn;
|
|
126
|
+
profileKeyCredentialPublicKey;
|
|
127
|
+
profileKey;
|
|
128
|
+
cachedCredential = null;
|
|
129
|
+
cachedProfileKeyCredential = null;
|
|
130
|
+
/** Serializes credential fetches to prevent duplicate network requests. */
|
|
131
|
+
credentialLock = new AsyncLock();
|
|
132
|
+
constructor(options) {
|
|
133
|
+
this.store = options.store;
|
|
134
|
+
this.server = options.server;
|
|
135
|
+
this.onSenderKeyRotation = options.onSenderKeyRotation;
|
|
136
|
+
this.onEndorsementsInvalidated = options.onEndorsementsInvalidated;
|
|
137
|
+
this.issueCredential = options.issueCredential;
|
|
138
|
+
this.credentialPublicKey = options.credentialPublicKey;
|
|
139
|
+
this.serverSigningPublicKey = options.serverSigningPublicKey
|
|
140
|
+
? new Uint8Array(options.serverSigningPublicKey)
|
|
141
|
+
: undefined;
|
|
142
|
+
if (this.serverSigningPublicKey && this.serverSigningPublicKey.length !== 32) {
|
|
143
|
+
throw new Error(`Server signing public key must be 32 bytes, got ${this.serverSigningPublicKey.length}`);
|
|
144
|
+
}
|
|
145
|
+
if (!this.serverSigningPublicKey) {
|
|
146
|
+
if (options.allowUnauthenticatedGroupHistory !== true) {
|
|
147
|
+
throw new Error('Group server signing key is required unless allowUnauthenticatedGroupHistory is explicitly enabled');
|
|
148
|
+
}
|
|
149
|
+
const warning = {
|
|
150
|
+
code: 'GROUP_SERVER_SIGNATURE_VERIFICATION_DISABLED',
|
|
151
|
+
message: 'Group server signing key is not configured; authenticated group history is disabled.',
|
|
152
|
+
};
|
|
153
|
+
if (options.onConfigurationWarning) {
|
|
154
|
+
options.onConfigurationWarning(warning);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
console.warn(warning.message);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
this.aci = options.aci;
|
|
161
|
+
this.pni = options.pni;
|
|
162
|
+
this.issueProfileKeyCredentialFn = options.issueProfileKeyCredential;
|
|
163
|
+
this.profileKeyCredentialPublicKey = options.profileKeyCredentialPublicKey;
|
|
164
|
+
this.profileKey = new Uint8Array(options.profileKey);
|
|
165
|
+
if (this.profileKey.length !== 32) {
|
|
166
|
+
throw new Error(`Profile key must be 32 bytes, got ${this.profileKey.length}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// =========================================================================
|
|
170
|
+
// Authorization
|
|
171
|
+
// =========================================================================
|
|
172
|
+
/**
|
|
173
|
+
* Build authorization for a group operation.
|
|
174
|
+
*
|
|
175
|
+
* Flow: issue credential -> receive (verify issuance) -> present (create ZK proof)
|
|
176
|
+
*
|
|
177
|
+
* Public so the endorsement refresher (SignalProtocolClient) can build auth for
|
|
178
|
+
* relay.refreshGroupSendEndorsements(). Safe because:
|
|
179
|
+
* - Credential is day-cached (one server round-trip per UTC day max)
|
|
180
|
+
* - Each presentation uses fresh randomness → unlinkable
|
|
181
|
+
* - No secret material is exposed; only the ZK proof + group public params
|
|
182
|
+
*/
|
|
183
|
+
async getAuthorization(rawGroupId) {
|
|
184
|
+
const secretParams = await this.getSecretParams(rawGroupId);
|
|
185
|
+
const groupPublicParams = getGroupPublicParams(secretParams);
|
|
186
|
+
// Get or refresh credential (day-aligned).
|
|
187
|
+
// The lock prevents concurrent fetches for the same day-scoped credential.
|
|
188
|
+
const credential = await this.credentialLock.acquire('credential', async () => {
|
|
189
|
+
const today = Math.floor(Date.now() / 1000 / SECONDS_PER_DAY) * SECONDS_PER_DAY;
|
|
190
|
+
if (this.cachedCredential?.redemptionTime === today) {
|
|
191
|
+
return this.cachedCredential.credential;
|
|
192
|
+
}
|
|
193
|
+
const responseBytes = await this.issueCredential();
|
|
194
|
+
const response = deserializeAuthCredentialResponse(new Uint8Array(responseBytes));
|
|
195
|
+
const cred = receiveAuthCredential(this.credentialPublicKey, response, this.aci, this.pni, today);
|
|
196
|
+
this.cachedCredential = { redemptionTime: today, credential: cred };
|
|
197
|
+
return cred;
|
|
198
|
+
});
|
|
199
|
+
// Create fresh presentation (new randomness each time for unlinkability)
|
|
200
|
+
const presentation = presentAuthCredential(this.credentialPublicKey, credential, secretParams, crypto.getRandomValues(new Uint8Array(32)));
|
|
201
|
+
return {
|
|
202
|
+
presentation: serializeAuthCredentialPresentation(presentation),
|
|
203
|
+
groupPublicParams: serializeGroupPublicParams(groupPublicParams),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get or refresh the profile key credential for the current user.
|
|
208
|
+
* Group profile-key introductions are never permitted without this proof.
|
|
209
|
+
*/
|
|
210
|
+
async getPresentationContext() {
|
|
211
|
+
const today = Math.floor(Date.now() / 1000 / SECONDS_PER_DAY) * SECONDS_PER_DAY;
|
|
212
|
+
if (!this.cachedProfileKeyCredential ||
|
|
213
|
+
this.cachedProfileKeyCredential.redemptionTime !== today) {
|
|
214
|
+
const responseBytes = await this.issueProfileKeyCredentialFn();
|
|
215
|
+
const response = deserializeProfileKeyCredentialResponse(new Uint8Array(responseBytes));
|
|
216
|
+
const credential = receiveProfileKeyCredential(this.profileKeyCredentialPublicKey, response, this.aci, this.profileKey, response.redemptionTime, Math.floor(Date.now() / 1000));
|
|
217
|
+
this.cachedProfileKeyCredential = { redemptionTime: today, credential };
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
credential: this.cachedProfileKeyCredential.credential,
|
|
221
|
+
credentialPublicKey: this.profileKeyCredentialPublicKey,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Execute a group server operation with one credential-refresh retry.
|
|
226
|
+
* On `UNAUTHORIZED`, clears the credential cache and retries once.
|
|
227
|
+
*
|
|
228
|
+
* This is an SDK transport convenience, not specified behaviour: day-aligned
|
|
229
|
+
* auth credentials can expire mid-flight, and one refresh is cheaper than
|
|
230
|
+
* surfacing a spurious authorization failure.
|
|
231
|
+
*/
|
|
232
|
+
async withAuthRetry(rawGroupId, operation) {
|
|
233
|
+
const authorization = await this.getAuthorization(rawGroupId);
|
|
234
|
+
try {
|
|
235
|
+
return await operation(authorization);
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
const isUnauthorized = err instanceof Error && err.message.includes('UNAUTHORIZED');
|
|
239
|
+
if (!isUnauthorized)
|
|
240
|
+
throw err;
|
|
241
|
+
// Clear stale credential and retry once
|
|
242
|
+
this.cachedCredential = null;
|
|
243
|
+
const freshAuth = await this.getAuthorization(rawGroupId);
|
|
244
|
+
return await operation(freshAuth);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Invalidate endorsement cache for a group (non-fatal).
|
|
249
|
+
*
|
|
250
|
+
* Called after membership changes. Failures are logged but do not
|
|
251
|
+
* propagate — endorsements are lazily refreshed on next send.
|
|
252
|
+
*/
|
|
253
|
+
async invalidateEndorsements(rawGroupId) {
|
|
254
|
+
if (!this.onEndorsementsInvalidated)
|
|
255
|
+
return;
|
|
256
|
+
try {
|
|
257
|
+
await this.onEndorsementsInvalidated(rawGroupId);
|
|
258
|
+
}
|
|
259
|
+
catch {
|
|
260
|
+
// Non-fatal — endorsements will be refreshed on next send
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// =========================================================================
|
|
264
|
+
// Group Creation
|
|
265
|
+
// =========================================================================
|
|
266
|
+
/**
|
|
267
|
+
* Create a new group.
|
|
268
|
+
*
|
|
269
|
+
* Generates a GroupMasterKey, derives all secrets, creates the initial
|
|
270
|
+
* encrypted state, and uploads to the server.
|
|
271
|
+
*
|
|
272
|
+
* @param creatorAci - 16-byte ACI of the group creator
|
|
273
|
+
* @param creatorProfileKey - 32-byte profile key of the creator
|
|
274
|
+
* @param members - Targets with presentation material to add, or ServiceIds
|
|
275
|
+
* to invite without profile material
|
|
276
|
+
* @param title - Group title
|
|
277
|
+
* @param options - Optional settings (description, access control, avatar, timer)
|
|
278
|
+
* @returns GroupId and master key
|
|
279
|
+
*/
|
|
280
|
+
async createGroup(creatorAci, creatorProfileKey, members, title, options) {
|
|
281
|
+
// Generate random master key
|
|
282
|
+
const masterKeyBytes = new Uint8Array(GROUP_MASTER_KEY_LEN);
|
|
283
|
+
crypto.getRandomValues(masterKeyBytes);
|
|
284
|
+
const mk = groupMasterKey(masterKeyBytes);
|
|
285
|
+
// Derive all group secrets
|
|
286
|
+
const secretParams = deriveGroupSecretParams(mk);
|
|
287
|
+
// Build initial decrypted state
|
|
288
|
+
const ac = {
|
|
289
|
+
...defaultAccessControl(),
|
|
290
|
+
...options?.accessControl,
|
|
291
|
+
};
|
|
292
|
+
const creatorMember = {
|
|
293
|
+
aciBytes: creatorAci,
|
|
294
|
+
role: MemberRole.ADMINISTRATOR,
|
|
295
|
+
profileKey: creatorProfileKey,
|
|
296
|
+
joinedAtRevision: 0,
|
|
297
|
+
pniBytes: new Uint8Array(0),
|
|
298
|
+
labelEmoji: '',
|
|
299
|
+
labelString: '',
|
|
300
|
+
};
|
|
301
|
+
const presentedMembers = [];
|
|
302
|
+
const invitedMembers = [];
|
|
303
|
+
for (const member of members) {
|
|
304
|
+
if (classifyGroupMemberInput(member) === 'presented') {
|
|
305
|
+
presentedMembers.push(member);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
invitedMembers.push(member);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const additionalMembers = presentedMembers.map((member) => ({
|
|
312
|
+
aciBytes: member.aciBytes,
|
|
313
|
+
role: member.role ?? MemberRole.DEFAULT,
|
|
314
|
+
profileKey: member.profileKey,
|
|
315
|
+
joinedAtRevision: 0,
|
|
316
|
+
pniBytes: new Uint8Array(0),
|
|
317
|
+
labelEmoji: '',
|
|
318
|
+
labelString: '',
|
|
319
|
+
}));
|
|
320
|
+
const pendingMembers = invitedMembers.map((member) => {
|
|
321
|
+
assertServiceIdBytes(member.serviceIdBytes);
|
|
322
|
+
return {
|
|
323
|
+
serviceIdBytes: member.serviceIdBytes,
|
|
324
|
+
role: member.role ?? MemberRole.DEFAULT,
|
|
325
|
+
addedByAci: creatorAci,
|
|
326
|
+
timestamp: Date.now(),
|
|
327
|
+
serviceIdCipherText: new Uint8Array(0),
|
|
328
|
+
};
|
|
329
|
+
});
|
|
330
|
+
const initialState = {
|
|
331
|
+
title,
|
|
332
|
+
avatar: options?.avatarUrl ?? '',
|
|
333
|
+
disappearingMessagesTimer: {
|
|
334
|
+
duration: options?.disappearingMessagesDuration ?? 0,
|
|
335
|
+
},
|
|
336
|
+
accessControl: ac,
|
|
337
|
+
revision: 0,
|
|
338
|
+
members: [creatorMember, ...additionalMembers],
|
|
339
|
+
pendingMembers,
|
|
340
|
+
requestingMembers: [],
|
|
341
|
+
inviteLinkPassword: new Uint8Array(0),
|
|
342
|
+
description: options?.description ?? '',
|
|
343
|
+
isAnnouncementGroup: EnabledState.DISABLED,
|
|
344
|
+
bannedMembers: [],
|
|
345
|
+
terminated: false,
|
|
346
|
+
};
|
|
347
|
+
// Get presentation context for the creator's member entry
|
|
348
|
+
const presentationCtx = await this.getPresentationContext();
|
|
349
|
+
const memberContexts = new Map();
|
|
350
|
+
const creatorAciHex = Array.from(creatorAci)
|
|
351
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
352
|
+
.join('');
|
|
353
|
+
memberContexts.set(creatorAciHex, presentationCtx);
|
|
354
|
+
for (const member of presentedMembers) {
|
|
355
|
+
const { profileKeyCredential: proof } = member;
|
|
356
|
+
memberContexts.set(bytesToHex(member.aciBytes), {
|
|
357
|
+
credential: proof,
|
|
358
|
+
credentialPublicKey: this.profileKeyCredentialPublicKey,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
// Encrypt the initial state
|
|
362
|
+
const encryptedState = encryptGroupState(secretParams, initialState, memberContexts);
|
|
363
|
+
// Creation submits no provenance. The server derives it before signing
|
|
364
|
+
// canonical version zero.
|
|
365
|
+
const serialized = serializeEncryptedGroupCreationSubmission(toEncryptedGroupCreationSubmission(encryptedState));
|
|
366
|
+
// Derive group identifier
|
|
367
|
+
const groupIdHex = bytesToHex(secretParams.groupId);
|
|
368
|
+
const groupId = createGroupId(groupIdHex);
|
|
369
|
+
// Store master key first so getAuthorization can derive secret params
|
|
370
|
+
await this.store.storeMasterKey(groupIdHex, masterKeyBytes);
|
|
371
|
+
try {
|
|
372
|
+
// Upload to server with auth credential (+ retry on UNAUTHORIZED)
|
|
373
|
+
await this.withAuthRetry(groupIdHex, (auth) => this.server.createGroup(secretParams.groupId, serialized, auth));
|
|
374
|
+
}
|
|
375
|
+
catch (err) {
|
|
376
|
+
// Clean up orphan master key — server doesn't have this group
|
|
377
|
+
await this.store.deleteMasterKey(groupIdHex);
|
|
378
|
+
throw err;
|
|
379
|
+
}
|
|
380
|
+
// Creation is C9's first-baseline path. Cache only the exact canonical
|
|
381
|
+
// version-zero state the server signed, never the optimistic submission.
|
|
382
|
+
const snapshot = await this.withAuthRetry(groupIdHex, (auth) => this.server.getGroup(secretParams.groupId, auth, 0));
|
|
383
|
+
if (!snapshot) {
|
|
384
|
+
throw new Error('GROUP_SNAPSHOT_NOT_FOUND: Server did not return canonical version zero');
|
|
385
|
+
}
|
|
386
|
+
const canonicalState = this.decryptVerifiedSnapshot(secretParams, snapshot);
|
|
387
|
+
await this.store.storeGroupState(groupIdHex, canonicalState);
|
|
388
|
+
return { groupId, masterKey: masterKeyBytes };
|
|
389
|
+
}
|
|
390
|
+
// =========================================================================
|
|
391
|
+
// State Retrieval
|
|
392
|
+
// =========================================================================
|
|
393
|
+
/**
|
|
394
|
+
* Get the decrypted group state.
|
|
395
|
+
*
|
|
396
|
+
* Returns cached state if available, otherwise fetches from server.
|
|
397
|
+
*
|
|
398
|
+
* @param groupId - Group identifier
|
|
399
|
+
* @returns Decrypted group state
|
|
400
|
+
*/
|
|
401
|
+
async getGroupState(groupId) {
|
|
402
|
+
const rawId = extractGroupId(groupId);
|
|
403
|
+
// Try cache first
|
|
404
|
+
const cached = await this.store.getGroupState(rawId);
|
|
405
|
+
if (cached)
|
|
406
|
+
return cached;
|
|
407
|
+
// Fetch from server
|
|
408
|
+
return this.syncGroup(groupId);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Sync group state from server.
|
|
412
|
+
*
|
|
413
|
+
* Fetches the latest state or change log and applies updates.
|
|
414
|
+
*
|
|
415
|
+
* @param groupId - Group identifier
|
|
416
|
+
* @returns Updated decrypted group state
|
|
417
|
+
*/
|
|
418
|
+
async syncGroup(groupId) {
|
|
419
|
+
const rawId = extractGroupId(groupId);
|
|
420
|
+
await this.retryPendingSenderKeyRotation(groupId);
|
|
421
|
+
const secretParams = await this.getSecretParams(rawId);
|
|
422
|
+
// Check current cached revision
|
|
423
|
+
const cached = await this.store.getGroupState(rawId);
|
|
424
|
+
const currentRevision = cached?.revision ?? -1;
|
|
425
|
+
if (currentRevision >= 0) {
|
|
426
|
+
if (!this.isReadableBySelf(cached)) {
|
|
427
|
+
const baseline = await this.withAuthRetry(rawId, (auth) => this.server.getGroup(secretParams.groupId, auth));
|
|
428
|
+
if (!baseline) {
|
|
429
|
+
throw new Error(`GROUP_NOT_FOUND: Group ${rawId} not found on server`);
|
|
430
|
+
}
|
|
431
|
+
const restored = this.decryptVerifiedSnapshot(secretParams, baseline);
|
|
432
|
+
if (restored.revision <= currentRevision ||
|
|
433
|
+
!this.isReadableBySelf(restored)) {
|
|
434
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Re-entitlement baseline does not follow the revoked span');
|
|
435
|
+
}
|
|
436
|
+
await this.store.storeGroupState(rawId, restored);
|
|
437
|
+
return restored;
|
|
438
|
+
}
|
|
439
|
+
// A pending principal holds an entitlement to the current state, not a
|
|
440
|
+
// tenure: the server refuses them the change log outright, and C1/C3's
|
|
441
|
+
// verified-transition requirement starts at the baseline their
|
|
442
|
+
// acceptance will establish, not at the invitation (S10a). So they
|
|
443
|
+
// catch up the way the reference ecosystem's clients do when the
|
|
444
|
+
// server does not recognize them as a member — a fresh signed
|
|
445
|
+
// snapshot, verified and installed whole.
|
|
446
|
+
if (!isMember(cached, this.aci.uuid)) {
|
|
447
|
+
let result;
|
|
448
|
+
try {
|
|
449
|
+
result = await this.withAuthRetry(rawId, (auth) => this.server.getGroup(secretParams.groupId, auth));
|
|
450
|
+
}
|
|
451
|
+
catch (error) {
|
|
452
|
+
if (!GroupManager.isNotReadableRejection(error))
|
|
453
|
+
throw error;
|
|
454
|
+
// The invitation this principal held was revoked. Nothing is
|
|
455
|
+
// installed: the cached pending view stays the last verified
|
|
456
|
+
// state, and a later re-invitation serves a fresh snapshot.
|
|
457
|
+
throw new Error('GROUP_ACCESS_REVOKED: Invitation was revoked before it could be accepted');
|
|
458
|
+
}
|
|
459
|
+
if (!result) {
|
|
460
|
+
throw new Error(`GROUP_NOT_FOUND: Group ${rawId} not found on server`);
|
|
461
|
+
}
|
|
462
|
+
const state = this.decryptVerifiedSnapshot(secretParams, result);
|
|
463
|
+
if (state.revision < currentRevision) {
|
|
464
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Server snapshot regressed behind the verified baseline');
|
|
465
|
+
}
|
|
466
|
+
await this.store.storeGroupState(rawId, state);
|
|
467
|
+
return state;
|
|
468
|
+
}
|
|
469
|
+
// Once a member has a baseline it may advance only through
|
|
470
|
+
// individually verified transitions. A full snapshot must never bypass
|
|
471
|
+
// a bad or missing log entry (C1/C3).
|
|
472
|
+
const changes = await this.withAuthRetry(rawId, (auth) => this.server.getGroupChanges(secretParams.groupId, currentRevision, auth));
|
|
473
|
+
let state = cached;
|
|
474
|
+
for (const entry of changes) {
|
|
475
|
+
state = await this.applyVerifiedChange(rawId, state, entry);
|
|
476
|
+
}
|
|
477
|
+
if (!this.isReadableBySelf(state)) {
|
|
478
|
+
let baseline = null;
|
|
479
|
+
try {
|
|
480
|
+
baseline = await this.withAuthRetry(rawId, (auth) => this.server.getGroup(secretParams.groupId, auth));
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
if (!GroupManager.isNotReadableRejection(error))
|
|
484
|
+
throw error;
|
|
485
|
+
}
|
|
486
|
+
if (baseline) {
|
|
487
|
+
const restored = this.decryptVerifiedSnapshot(secretParams, baseline);
|
|
488
|
+
if (restored.revision <= state.revision ||
|
|
489
|
+
!this.isReadableBySelf(restored)) {
|
|
490
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Re-entitlement baseline does not follow the revoked span');
|
|
491
|
+
}
|
|
492
|
+
await this.store.storeGroupState(rawId, restored);
|
|
493
|
+
return restored;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return state;
|
|
497
|
+
}
|
|
498
|
+
// Full state fetch
|
|
499
|
+
const result = await this.withAuthRetry(rawId, (auth) => this.server.getGroup(secretParams.groupId, auth));
|
|
500
|
+
if (!result) {
|
|
501
|
+
throw new Error(`GROUP_NOT_FOUND: Group ${rawId} not found on server`);
|
|
502
|
+
}
|
|
503
|
+
const state = this.decryptVerifiedSnapshot(secretParams, result);
|
|
504
|
+
await this.store.storeGroupState(rawId, state);
|
|
505
|
+
return state;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Verify, authorize, structurally validate, and apply one server change.
|
|
509
|
+
*
|
|
510
|
+
* This is the only path by which a signed Actions value advances cached
|
|
511
|
+
* state. Each successful prefix is persisted before the next entry is read.
|
|
512
|
+
*/
|
|
513
|
+
async applyVerifiedChange(rawGroupId, state, entry, options = {}) {
|
|
514
|
+
if (this.serverSigningPublicKey &&
|
|
515
|
+
!serverVerifySignature({ signingPublicKey: this.serverSigningPublicKey }, serializeGroupChangeCommitment(entry.changeEpoch, entry.actions), entry.serverSignature)) {
|
|
516
|
+
throw new Error('INVALID_SERVER_SIGNATURE: Group change signature verification failed');
|
|
517
|
+
}
|
|
518
|
+
if (!Number.isInteger(entry.changeEpoch) ||
|
|
519
|
+
entry.changeEpoch < 0 ||
|
|
520
|
+
entry.changeEpoch > MAX_SUPPORTED_CHANGE_EPOCH) {
|
|
521
|
+
throw new Error(`UNSUPPORTED_CHANGE_EPOCH: Maximum ${MAX_SUPPORTED_CHANGE_EPOCH}, got ${entry.changeEpoch}`);
|
|
522
|
+
}
|
|
523
|
+
const encrypted = deserializeEncryptedGroupChange(entry.actions);
|
|
524
|
+
try {
|
|
525
|
+
assertValidEncryptedGroupChangeWire(encrypted, 'canonical');
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
throw new Error(`INVALID_CHANGE: ${error instanceof Error ? error.message : 'Signed Actions are malformed'}`);
|
|
529
|
+
}
|
|
530
|
+
const requiredEpoch = requiredGroupChangeEpoch(encrypted);
|
|
531
|
+
if (entry.changeEpoch !== requiredEpoch) {
|
|
532
|
+
throw new Error(`INVALID_CHANGE_EPOCH: Signed epoch ${entry.changeEpoch} does not match required epoch ${requiredEpoch}`);
|
|
533
|
+
}
|
|
534
|
+
const secretParams = await this.getSecretParams(rawGroupId);
|
|
535
|
+
if (!encrypted.groupId || !bytesEqual(encrypted.groupId, secretParams.groupId)) {
|
|
536
|
+
throw new Error('GROUP_BINDING_MISMATCH: Signed change names a different group');
|
|
537
|
+
}
|
|
538
|
+
if (encrypted.revision !== state.revision + 1 || entry.version !== encrypted.revision) {
|
|
539
|
+
throw new Error(`INVALID_CHANGE_SEQUENCE: Expected ${state.revision + 1}, got Actions ${encrypted.revision} / entry ${entry.version}`);
|
|
540
|
+
}
|
|
541
|
+
const change = decryptChangeFields(encrypted, secretParams);
|
|
542
|
+
const authorizationErrors = validateChangeAuthorization(state, change);
|
|
543
|
+
if (authorizationErrors.length > 0) {
|
|
544
|
+
throw new Error(`UNAUTHORIZED_CHANGE: ${authorizationErrors.join(', ')}`);
|
|
545
|
+
}
|
|
546
|
+
const structuralErrors = validateChangeStructure(state, change);
|
|
547
|
+
if (structuralErrors.length > 0) {
|
|
548
|
+
throw new Error(`INVALID_CHANGE: ${structuralErrors.join(', ')}`);
|
|
549
|
+
}
|
|
550
|
+
const nextState = applyGroupChange(state, change);
|
|
551
|
+
if (options.stateVisibility === 'group_join_info') {
|
|
552
|
+
if (!this.isRestrictedGroupJoinInfoChange(change, countGroupChangeActions(encrypted))) {
|
|
553
|
+
throw new Error('INVALID_CHANGE: GroupJoinInfo validation is restricted to one link-join action');
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
else if (!satisfiesLiveGroupAdministratorInvariant(nextState)) {
|
|
557
|
+
throw new Error('INVALID_CHANGE: Every non-terminated group must have at least one administrator');
|
|
558
|
+
}
|
|
559
|
+
if (options.persist !== false) {
|
|
560
|
+
if (this.requiresSenderKeyRotation(change)) {
|
|
561
|
+
await this.store.storeGroupStateWithSenderKeyRotationBarrier(rawGroupId, nextState);
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
await this.store.storeGroupState(rawGroupId, nextState);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (options.react !== false) {
|
|
568
|
+
if (this.requiresSenderKeyRotation(change)) {
|
|
569
|
+
if (options.persist === false) {
|
|
570
|
+
throw new Error('INVALID_GROUP_REACTION: Cannot rotate without a persisted C7 barrier');
|
|
571
|
+
}
|
|
572
|
+
await this.completePendingSenderKeyRotation(rawGroupId, nextState.revision);
|
|
573
|
+
}
|
|
574
|
+
if (this.changesMembership(change)) {
|
|
575
|
+
await this.invalidateEndorsements(rawGroupId);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return nextState;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Revision 20's two §11 projection-only action surfaces.
|
|
582
|
+
*
|
|
583
|
+
* The normal C6 path evaluates result-state invariants against complete
|
|
584
|
+
* verified state. A prospective link joiner cannot see the member list, so
|
|
585
|
+
* only these additive self-actions may skip predicates that need it.
|
|
586
|
+
*/
|
|
587
|
+
isRestrictedGroupJoinInfoChange(change, actionCount) {
|
|
588
|
+
if (actionCount !== 1)
|
|
589
|
+
return false;
|
|
590
|
+
if (!bytesEqual(change.editorServiceIdBytes, serviceIdBinary(this.aci))) {
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
if (change.newMembers.length === 1) {
|
|
594
|
+
const member = change.newMembers[0];
|
|
595
|
+
return (member.role === MemberRole.DEFAULT &&
|
|
596
|
+
bytesEqual(member.aciBytes, this.aci.uuid));
|
|
597
|
+
}
|
|
598
|
+
if (change.newRequestingMembers.length === 1) {
|
|
599
|
+
return bytesEqual(change.newRequestingMembers[0].aciBytes, this.aci.uuid);
|
|
600
|
+
}
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
changesMembership(change) {
|
|
604
|
+
return (change.newMembers.length > 0 ||
|
|
605
|
+
change.deleteMembers.length > 0 ||
|
|
606
|
+
change.newPendingMembers.length > 0 ||
|
|
607
|
+
change.deletePendingMembers.length > 0 ||
|
|
608
|
+
change.promotePendingMembers.length > 0 ||
|
|
609
|
+
change.promotePendingPniAciMembers.length > 0 ||
|
|
610
|
+
change.newRequestingMembers.length > 0 ||
|
|
611
|
+
change.deleteRequestingMembers.length > 0 ||
|
|
612
|
+
change.promoteRequestingMembers.length > 0 ||
|
|
613
|
+
change.newBannedMembers.length > 0 ||
|
|
614
|
+
change.deleteBannedMembers.length > 0);
|
|
615
|
+
}
|
|
616
|
+
requiresSenderKeyRotation(change) {
|
|
617
|
+
return (change.deleteMembers.length > 0 ||
|
|
618
|
+
change.newBannedMembers.length > 0 ||
|
|
619
|
+
change.terminate === true);
|
|
620
|
+
}
|
|
621
|
+
securityReactionPendingError(rawGroupId, revision, cause) {
|
|
622
|
+
const error = new Error(`GROUP_CHANGE_ACCEPTED_SECURITY_REACTION_PENDING: Group ${rawGroupId} accepted revision ${revision}, but sender-key rotation remains pending`);
|
|
623
|
+
error.name = 'GroupSecurityReactionPendingError';
|
|
624
|
+
if (cause !== undefined) {
|
|
625
|
+
error.cause = cause;
|
|
626
|
+
}
|
|
627
|
+
return error;
|
|
628
|
+
}
|
|
629
|
+
async completePendingSenderKeyRotation(rawGroupId, revision) {
|
|
630
|
+
const acceptedState = await this.store.getGroupState(rawGroupId);
|
|
631
|
+
if (!acceptedState || acceptedState.revision < revision) {
|
|
632
|
+
throw this.securityReactionPendingError(rawGroupId, revision);
|
|
633
|
+
}
|
|
634
|
+
if (!this.onSenderKeyRotation) {
|
|
635
|
+
throw this.securityReactionPendingError(rawGroupId, revision);
|
|
636
|
+
}
|
|
637
|
+
try {
|
|
638
|
+
await this.onSenderKeyRotation(createGroupId(rawGroupId));
|
|
639
|
+
await this.store.clearSenderKeyRotationBarrier(rawGroupId, revision);
|
|
640
|
+
}
|
|
641
|
+
catch (cause) {
|
|
642
|
+
throw this.securityReactionPendingError(rawGroupId, revision, cause);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Retry and clear a durable C7 barrier, including after reconstruction.
|
|
647
|
+
*/
|
|
648
|
+
async retryPendingSenderKeyRotation(groupId) {
|
|
649
|
+
const rawGroupId = extractGroupId(groupId);
|
|
650
|
+
const revision = await this.store.getSenderKeyRotationBarrier(rawGroupId);
|
|
651
|
+
if (revision === null)
|
|
652
|
+
return;
|
|
653
|
+
await this.completePendingSenderKeyRotation(rawGroupId, revision);
|
|
654
|
+
await this.invalidateEndorsements(rawGroupId);
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Enforce C7 rotation readiness and C10 send eligibility.
|
|
658
|
+
*/
|
|
659
|
+
async assertGroupSendAllowed(groupId) {
|
|
660
|
+
const rawGroupId = extractGroupId(groupId);
|
|
661
|
+
const revision = await this.store.getSenderKeyRotationBarrier(rawGroupId);
|
|
662
|
+
if (revision !== null) {
|
|
663
|
+
throw new Error(`GROUP_SEND_BLOCKED_BY_SECURITY_REACTION: Sender-key rotation is pending for group ${rawGroupId} at accepted revision ${revision}`);
|
|
664
|
+
}
|
|
665
|
+
// The durable master key is the local boundary between Group System
|
|
666
|
+
// groups and the pre-existing ad-hoc Sender Keys API. No master key means
|
|
667
|
+
// this manager has no group authorization state to enforce.
|
|
668
|
+
const masterKey = await this.store.getMasterKey(rawGroupId);
|
|
669
|
+
if (masterKey === null)
|
|
670
|
+
return;
|
|
671
|
+
const state = await this.store.getGroupState(rawGroupId);
|
|
672
|
+
if (state === null) {
|
|
673
|
+
throw new Error(`GROUP_SEND_BLOCKED_BY_ELIGIBILITY: Managed group ${rawGroupId} has no verified accepted state`);
|
|
674
|
+
}
|
|
675
|
+
if (state.terminated) {
|
|
676
|
+
throw new Error(`GROUP_SEND_BLOCKED_BY_ELIGIBILITY: Group ${rawGroupId} is terminated`);
|
|
677
|
+
}
|
|
678
|
+
if (!isMember(state, this.aci.uuid)) {
|
|
679
|
+
throw new Error(`GROUP_SEND_BLOCKED_BY_ELIGIBILITY: Sender is not a member of group ${rawGroupId}`);
|
|
680
|
+
}
|
|
681
|
+
const aciServiceId = serviceIdBinary(this.aci);
|
|
682
|
+
const pniServiceId = this.pni === undefined ? undefined : serviceIdBinary(this.pni);
|
|
683
|
+
if (isBanned(state, aciServiceId) ||
|
|
684
|
+
(pniServiceId !== undefined && isBanned(state, pniServiceId))) {
|
|
685
|
+
throw new Error(`GROUP_SEND_BLOCKED_BY_ELIGIBILITY: Sender is banned from group ${rawGroupId}`);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
// =========================================================================
|
|
689
|
+
// Membership Operations
|
|
690
|
+
// =========================================================================
|
|
691
|
+
/**
|
|
692
|
+
* Add a member to the group.
|
|
693
|
+
*
|
|
694
|
+
* @param groupId - Group identifier
|
|
695
|
+
* @param editorAci - ACI of the user performing the action
|
|
696
|
+
* A target with presentation material is added immediately. Otherwise the
|
|
697
|
+
* target is invited without a profile key and presents when accepting.
|
|
698
|
+
*/
|
|
699
|
+
async addMember(groupId, editorAci, member) {
|
|
700
|
+
const inputKind = classifyGroupMemberInput(member);
|
|
701
|
+
const rawId = extractGroupId(groupId);
|
|
702
|
+
const state = await this.getGroupState(groupId);
|
|
703
|
+
// Authorization check
|
|
704
|
+
const editorServiceIdBytes = aciToServiceIdBytes(editorAci);
|
|
705
|
+
const change = emptyGroupChange(editorServiceIdBytes, state.revision + 1);
|
|
706
|
+
if (inputKind === 'presented') {
|
|
707
|
+
const presentedMember = member;
|
|
708
|
+
const assignedRole = member.role ?? MemberRole.DEFAULT;
|
|
709
|
+
if (!canPerformAction(state, editorServiceIdBytes, GroupAction.ADD_MEMBER, {
|
|
710
|
+
targetAciBytes: presentedMember.aciBytes,
|
|
711
|
+
assignedRole,
|
|
712
|
+
})) {
|
|
713
|
+
throw new Error('UNAUTHORIZED: Insufficient permissions to add member');
|
|
714
|
+
}
|
|
715
|
+
if (isMember(state, presentedMember.aciBytes)) {
|
|
716
|
+
throw new Error('ALREADY_MEMBER: User is already a group member');
|
|
717
|
+
}
|
|
718
|
+
const targetServiceId = aciToServiceIdBytes(presentedMember.aciBytes);
|
|
719
|
+
if (isBanned(state, targetServiceId)) {
|
|
720
|
+
throw new Error('BANNED_MEMBER: User is banned from this group');
|
|
721
|
+
}
|
|
722
|
+
change.newMembers = [
|
|
723
|
+
{
|
|
724
|
+
aciBytes: presentedMember.aciBytes,
|
|
725
|
+
role: assignedRole,
|
|
726
|
+
profileKey: presentedMember.profileKey,
|
|
727
|
+
},
|
|
728
|
+
];
|
|
729
|
+
const { profileKeyCredential: proof } = presentedMember;
|
|
730
|
+
const contexts = new Map([
|
|
731
|
+
[
|
|
732
|
+
bytesToHex(presentedMember.aciBytes),
|
|
733
|
+
{
|
|
734
|
+
credential: proof,
|
|
735
|
+
credentialPublicKey: this.profileKeyCredentialPublicKey,
|
|
736
|
+
},
|
|
737
|
+
],
|
|
738
|
+
]);
|
|
739
|
+
await this.submitChange(rawId, state, change, contexts);
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const invitedMember = member;
|
|
743
|
+
assertServiceIdBytes(invitedMember.serviceIdBytes);
|
|
744
|
+
if (!canPerformAction(state, editorServiceIdBytes, GroupAction.ADD_MEMBER_PENDING_PROFILE_KEY, {
|
|
745
|
+
targetServiceIdBytes: invitedMember.serviceIdBytes,
|
|
746
|
+
assignedRole: invitedMember.role ?? MemberRole.DEFAULT,
|
|
747
|
+
})) {
|
|
748
|
+
throw new Error('UNAUTHORIZED: Insufficient permissions to invite member');
|
|
749
|
+
}
|
|
750
|
+
if (isPending(state, invitedMember.serviceIdBytes)) {
|
|
751
|
+
throw new Error('ALREADY_PENDING: User already has an invitation');
|
|
752
|
+
}
|
|
753
|
+
if (isBanned(state, invitedMember.serviceIdBytes)) {
|
|
754
|
+
throw new Error('BANNED_MEMBER: User is banned from this group');
|
|
755
|
+
}
|
|
756
|
+
change.newPendingMembers = [
|
|
757
|
+
{
|
|
758
|
+
serviceIdBytes: invitedMember.serviceIdBytes,
|
|
759
|
+
role: invitedMember.role ?? MemberRole.DEFAULT,
|
|
760
|
+
},
|
|
761
|
+
];
|
|
762
|
+
await this.submitChange(rawId, state, change);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Accept this client's pending profile-key invitation.
|
|
766
|
+
*
|
|
767
|
+
* The pending entry carries no profile key. Acceptance introduces the
|
|
768
|
+
* client's own profile-key ciphertext together with the mandatory S12
|
|
769
|
+
* presentation, using the PNI-to-ACI promotion when the invitation is
|
|
770
|
+
* keyed by this account's PNI.
|
|
771
|
+
*/
|
|
772
|
+
async acceptMemberInvitation(groupId) {
|
|
773
|
+
const rawId = extractGroupId(groupId);
|
|
774
|
+
const state = await this.getGroupState(groupId);
|
|
775
|
+
const aciServiceIdBytes = serviceIdBinary(this.aci);
|
|
776
|
+
const pniServiceIdBytes = this.pni === undefined ? undefined : serviceIdBinary(this.pni);
|
|
777
|
+
const pendingByPni = pniServiceIdBytes === undefined
|
|
778
|
+
? undefined
|
|
779
|
+
: state.pendingMembers.find((member) => bytesEqual(member.serviceIdBytes, pniServiceIdBytes));
|
|
780
|
+
const pendingByAci = state.pendingMembers.find((member) => bytesEqual(member.serviceIdBytes, aciServiceIdBytes));
|
|
781
|
+
const pending = pendingByPni ?? pendingByAci;
|
|
782
|
+
if (!pending) {
|
|
783
|
+
throw new Error('INVITATION_NOT_FOUND: No pending invitation for this account');
|
|
784
|
+
}
|
|
785
|
+
if (pendingByPni &&
|
|
786
|
+
pendingByAci &&
|
|
787
|
+
pendingByPni.role !== pendingByAci.role) {
|
|
788
|
+
throw new Error('INVITATION_ROLE_CONFLICT: ACI and PNI invitations assign different roles; decline one invitation before accepting');
|
|
789
|
+
}
|
|
790
|
+
const change = emptyGroupChange(pendingByPni ? pniServiceIdBytes : aciServiceIdBytes, state.revision + 1);
|
|
791
|
+
const promoted = {
|
|
792
|
+
aciBytes: this.aci.uuid,
|
|
793
|
+
profileKey: this.profileKey,
|
|
794
|
+
};
|
|
795
|
+
if (pendingByPni) {
|
|
796
|
+
change.promotePendingPniAciMembers = [
|
|
797
|
+
{ ...promoted, pniBytes: this.pni.uuid },
|
|
798
|
+
];
|
|
799
|
+
}
|
|
800
|
+
else {
|
|
801
|
+
change.promotePendingMembers = [promoted];
|
|
802
|
+
}
|
|
803
|
+
const presentationContext = await this.getPresentationContext();
|
|
804
|
+
await this.submitChange(rawId, state, change, new Map([[bytesToHex(this.aci.uuid), presentationContext]]));
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Decline one of this account's pending profile-key invitations.
|
|
808
|
+
*
|
|
809
|
+
* Selecting the ACI invitation is the self-service resolution for a
|
|
810
|
+
* conflicting dual ACI+PNI invitation before accepting the PNI invitation.
|
|
811
|
+
*/
|
|
812
|
+
async declineMemberInvitation(groupId, identity = 'aci') {
|
|
813
|
+
const rawId = extractGroupId(groupId);
|
|
814
|
+
const state = await this.getGroupState(groupId);
|
|
815
|
+
const serviceId = identity === 'aci'
|
|
816
|
+
? this.aci
|
|
817
|
+
: this.pni;
|
|
818
|
+
if (!serviceId) {
|
|
819
|
+
throw new Error('INVITATION_NOT_FOUND: This account has no PNI invitation identity');
|
|
820
|
+
}
|
|
821
|
+
const serviceIdBytes = serviceIdBinary(serviceId);
|
|
822
|
+
const pending = state.pendingMembers.find((member) => bytesEqual(member.serviceIdBytes, serviceIdBytes));
|
|
823
|
+
if (!pending) {
|
|
824
|
+
throw new Error(`INVITATION_NOT_FOUND: No pending ${identity.toUpperCase()} invitation for this account`);
|
|
825
|
+
}
|
|
826
|
+
const change = emptyGroupChange(serviceIdBytes, state.revision + 1);
|
|
827
|
+
change.deletePendingMembers = [
|
|
828
|
+
{
|
|
829
|
+
serviceIdBytes,
|
|
830
|
+
serviceIdCipherText: pending.serviceIdCipherText,
|
|
831
|
+
},
|
|
832
|
+
];
|
|
833
|
+
await this.submitChange(rawId, state, change);
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Remove a member from the group.
|
|
837
|
+
*
|
|
838
|
+
* Triggers sender key rotation for forward secrecy.
|
|
839
|
+
*
|
|
840
|
+
* @param groupId - Group identifier
|
|
841
|
+
* @param editorAci - ACI of the user performing the action
|
|
842
|
+
* @param targetAci - ACI of the member to remove
|
|
843
|
+
*/
|
|
844
|
+
async removeMember(groupId, editorAci, targetAci) {
|
|
845
|
+
const rawId = extractGroupId(groupId);
|
|
846
|
+
const state = await this.getGroupState(groupId);
|
|
847
|
+
if (!canPerformAction(state, aciToServiceIdBytes(editorAci), GroupAction.REMOVE_MEMBER, {
|
|
848
|
+
targetAciBytes: targetAci,
|
|
849
|
+
})) {
|
|
850
|
+
throw new Error('UNAUTHORIZED: Insufficient permissions to remove member');
|
|
851
|
+
}
|
|
852
|
+
if (!isMember(state, targetAci)) {
|
|
853
|
+
throw new Error('NOT_MEMBER: User is not a group member');
|
|
854
|
+
}
|
|
855
|
+
const change = emptyGroupChange(aciToServiceIdBytes(editorAci), state.revision + 1);
|
|
856
|
+
change.deleteMembers = [targetAci];
|
|
857
|
+
await this.submitChange(rawId, state, change);
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Leave the group (self-remove).
|
|
861
|
+
*
|
|
862
|
+
* @param groupId - Group identifier
|
|
863
|
+
* @param userAci - ACI of the user leaving
|
|
864
|
+
*/
|
|
865
|
+
async leaveGroup(groupId, userAci) {
|
|
866
|
+
await this.removeMember(groupId, userAci, userAci);
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Modify a member's role.
|
|
870
|
+
*
|
|
871
|
+
* @param groupId - Group identifier
|
|
872
|
+
* @param editorAci - ACI of the admin performing the action
|
|
873
|
+
* @param targetAci - ACI of the member to modify
|
|
874
|
+
* @param newRole - New role
|
|
875
|
+
*/
|
|
876
|
+
async modifyMemberRole(groupId, editorAci, targetAci, newRole) {
|
|
877
|
+
const rawId = extractGroupId(groupId);
|
|
878
|
+
const state = await this.getGroupState(groupId);
|
|
879
|
+
const editorServiceIdBytes = aciToServiceIdBytes(editorAci);
|
|
880
|
+
if (!canPerformAction(state, editorServiceIdBytes, GroupAction.MODIFY_MEMBER_ROLE)) {
|
|
881
|
+
throw new Error('UNAUTHORIZED: Only admins can modify member roles');
|
|
882
|
+
}
|
|
883
|
+
if (!isMember(state, targetAci)) {
|
|
884
|
+
throw new Error('NOT_MEMBER: User is not a group member');
|
|
885
|
+
}
|
|
886
|
+
const change = emptyGroupChange(editorServiceIdBytes, state.revision + 1);
|
|
887
|
+
change.modifyMemberRoles = [{ aciBytes: targetAci, role: newRole }];
|
|
888
|
+
await this.submitChange(rawId, state, change);
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Ban a member from the group.
|
|
892
|
+
*
|
|
893
|
+
* Removes the member if present and adds to ban list.
|
|
894
|
+
* Triggers sender key rotation.
|
|
895
|
+
*
|
|
896
|
+
* @param groupId - Group identifier
|
|
897
|
+
* @param editorAci - ACI of the admin
|
|
898
|
+
* @param targetServiceId - ServiceId bytes of the user to ban
|
|
899
|
+
*/
|
|
900
|
+
async banMember(groupId, editorAci, targetServiceId) {
|
|
901
|
+
const rawId = extractGroupId(groupId);
|
|
902
|
+
const state = await this.getGroupState(groupId);
|
|
903
|
+
assertServiceIdBytes(targetServiceId);
|
|
904
|
+
const editorServiceIdBytes = aciToServiceIdBytes(editorAci);
|
|
905
|
+
if (!canPerformAction(state, editorServiceIdBytes, GroupAction.BAN_MEMBER)) {
|
|
906
|
+
throw new Error('UNAUTHORIZED: Only admins can ban members');
|
|
907
|
+
}
|
|
908
|
+
const change = emptyGroupChange(editorServiceIdBytes, state.revision + 1);
|
|
909
|
+
// Only an ACI principal can occupy the full-member list.
|
|
910
|
+
if (targetServiceId[0] === SERVICE_ID_ACI) {
|
|
911
|
+
const targetAci = targetServiceId.slice(1);
|
|
912
|
+
if (isMember(state, targetAci)) {
|
|
913
|
+
change.deleteMembers = [targetAci];
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
change.newBannedMembers = [{ serviceIdBytes: targetServiceId }];
|
|
917
|
+
await this.submitChange(rawId, state, change);
|
|
918
|
+
}
|
|
919
|
+
// =========================================================================
|
|
920
|
+
// Attribute Updates
|
|
921
|
+
// =========================================================================
|
|
922
|
+
/**
|
|
923
|
+
* Apply a single attribute change to a group.
|
|
924
|
+
*
|
|
925
|
+
* Handles the common pattern: load state, check permissions, create change,
|
|
926
|
+
* apply mutation, submit to server.
|
|
927
|
+
*/
|
|
928
|
+
async applyAttributeChange(groupId, editorAci, action, mutate) {
|
|
929
|
+
const rawId = extractGroupId(groupId);
|
|
930
|
+
const state = await this.getGroupState(groupId);
|
|
931
|
+
const editorServiceIdBytes = aciToServiceIdBytes(editorAci);
|
|
932
|
+
if (!canPerformAction(state, editorServiceIdBytes, action)) {
|
|
933
|
+
throw new Error(`UNAUTHORIZED: Cannot perform ${action} — insufficient permissions`);
|
|
934
|
+
}
|
|
935
|
+
const change = emptyGroupChange(editorServiceIdBytes, state.revision + 1);
|
|
936
|
+
mutate(change);
|
|
937
|
+
await this.submitChange(rawId, state, change);
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Update the group title.
|
|
941
|
+
*/
|
|
942
|
+
async updateTitle(groupId, editorAci, title) {
|
|
943
|
+
await this.applyAttributeChange(groupId, editorAci, GroupAction.MODIFY_TITLE, (change) => {
|
|
944
|
+
change.newTitle = { value: title };
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Update the group description.
|
|
949
|
+
*/
|
|
950
|
+
async updateDescription(groupId, editorAci, description) {
|
|
951
|
+
await this.applyAttributeChange(groupId, editorAci, GroupAction.MODIFY_DESCRIPTION, (change) => {
|
|
952
|
+
change.newDescription = { value: description };
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Update the disappearing messages timer.
|
|
957
|
+
*/
|
|
958
|
+
async updateDisappearingMessagesTimer(groupId, editorAci, duration) {
|
|
959
|
+
await this.applyAttributeChange(groupId, editorAci, GroupAction.MODIFY_DISAPPEARING_MESSAGES, (change) => {
|
|
960
|
+
change.newTimer = { duration };
|
|
961
|
+
});
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Update access control settings.
|
|
965
|
+
*/
|
|
966
|
+
async updateAccessControl(groupId, editorAci, updates) {
|
|
967
|
+
const rawId = extractGroupId(groupId);
|
|
968
|
+
const state = await this.getGroupState(groupId);
|
|
969
|
+
// All access control changes require admin
|
|
970
|
+
const actions = [
|
|
971
|
+
updates.attributes !== undefined && GroupAction.MODIFY_ATTRIBUTES_ACCESS,
|
|
972
|
+
updates.members !== undefined && GroupAction.MODIFY_MEMBERS_ACCESS,
|
|
973
|
+
updates.addFromInviteLink !== undefined && GroupAction.MODIFY_INVITE_LINK_ACCESS,
|
|
974
|
+
updates.memberLabel !== undefined && GroupAction.MODIFY_MEMBER_LABEL_ACCESS,
|
|
975
|
+
].filter(Boolean);
|
|
976
|
+
for (const action of actions) {
|
|
977
|
+
if (!canPerformAction(state, aciToServiceIdBytes(editorAci), action)) {
|
|
978
|
+
throw new Error('UNAUTHORIZED: Only admins can modify access control');
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
const change = emptyGroupChange(aciToServiceIdBytes(editorAci), state.revision + 1);
|
|
982
|
+
if (updates.attributes !== undefined) {
|
|
983
|
+
change.newAttributeAccess = updates.attributes;
|
|
984
|
+
}
|
|
985
|
+
if (updates.members !== undefined) {
|
|
986
|
+
change.newMemberAccess = updates.members;
|
|
987
|
+
}
|
|
988
|
+
if (updates.addFromInviteLink !== undefined) {
|
|
989
|
+
change.newInviteLinkAccess = updates.addFromInviteLink;
|
|
990
|
+
}
|
|
991
|
+
if (updates.memberLabel !== undefined) {
|
|
992
|
+
change.newMemberLabelAccess = updates.memberLabel;
|
|
993
|
+
}
|
|
994
|
+
await this.submitChange(rawId, state, change);
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Toggle announcement-only mode.
|
|
998
|
+
*/
|
|
999
|
+
async setAnnouncementMode(groupId, editorAci, enabled) {
|
|
1000
|
+
await this.applyAttributeChange(groupId, editorAci, GroupAction.MODIFY_ANNOUNCEMENTS, (change) => {
|
|
1001
|
+
change.newIsAnnouncementGroup = enabled ? EnabledState.ENABLED : EnabledState.DISABLED;
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Permanently terminate a group.
|
|
1006
|
+
*
|
|
1007
|
+
* Termination is an administrator-only, irreversible state transition and
|
|
1008
|
+
* triggers sender-key rotation through the verified-change reaction path.
|
|
1009
|
+
*/
|
|
1010
|
+
async terminateGroup(groupId, editorAci) {
|
|
1011
|
+
await this.applyAttributeChange(groupId, editorAci, GroupAction.TERMINATE_GROUP, (change) => {
|
|
1012
|
+
change.terminate = true;
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
// =========================================================================
|
|
1016
|
+
// Invite Links
|
|
1017
|
+
// =========================================================================
|
|
1018
|
+
/**
|
|
1019
|
+
* Create an invite link for the group.
|
|
1020
|
+
*
|
|
1021
|
+
* @param groupId - Group identifier
|
|
1022
|
+
* @param editorAci - ACI of the admin
|
|
1023
|
+
* @returns The invite link URL
|
|
1024
|
+
*/
|
|
1025
|
+
async createInviteLink(groupId, editorAci) {
|
|
1026
|
+
const rawId = extractGroupId(groupId);
|
|
1027
|
+
const state = await this.getGroupState(groupId);
|
|
1028
|
+
if (!canPerformAction(state, aciToServiceIdBytes(editorAci), GroupAction.MODIFY_INVITE_LINK_PASSWORD)) {
|
|
1029
|
+
throw new Error('UNAUTHORIZED: Only admins can create invite links');
|
|
1030
|
+
}
|
|
1031
|
+
const masterKeyBytes = await this.store.getMasterKey(rawId);
|
|
1032
|
+
if (!masterKeyBytes) {
|
|
1033
|
+
throw new Error('MASTER_KEY_NOT_FOUND: No master key for group');
|
|
1034
|
+
}
|
|
1035
|
+
const password = generateInviteLinkPassword();
|
|
1036
|
+
// Update group state with new invite link password
|
|
1037
|
+
// editorServiceIdBytes must be 17 bytes (1 byte kind + 16 byte UUID)
|
|
1038
|
+
const editorServiceIdBytes = aciToServiceIdBytes(editorAci);
|
|
1039
|
+
const change = emptyGroupChange(editorServiceIdBytes, state.revision + 1);
|
|
1040
|
+
change.newInviteLinkPassword = password;
|
|
1041
|
+
// Enable invite link access if not already
|
|
1042
|
+
if (state.accessControl.addFromInviteLink === AccessRequired.UNSATISFIABLE) {
|
|
1043
|
+
change.newInviteLinkAccess = AccessRequired.ANY;
|
|
1044
|
+
}
|
|
1045
|
+
await this.submitChange(rawId, state, change);
|
|
1046
|
+
return createGroupInviteLink(masterKeyBytes, password);
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Join a group via invite link.
|
|
1050
|
+
*
|
|
1051
|
+
* When `addFromInviteLink` is `AccessRequired.ADMINISTRATOR`, the user is
|
|
1052
|
+
* added to `requestingMembers` instead of `members`, requiring admin approval.
|
|
1053
|
+
*
|
|
1054
|
+
* @param url - Invite link URL
|
|
1055
|
+
* @param userAci - ACI of the joining user
|
|
1056
|
+
* @param userProfileKey - Profile key of the joining user
|
|
1057
|
+
* @returns GroupId and join status ('joined' or 'pending_approval')
|
|
1058
|
+
*/
|
|
1059
|
+
async joinViaInviteLink(url, userAci, userProfileKey) {
|
|
1060
|
+
if (!bytesEqual(userAci, this.aci.uuid)) {
|
|
1061
|
+
throw new Error('INVALID_JOIN_PRINCIPAL: Join target must match the authenticated ACI');
|
|
1062
|
+
}
|
|
1063
|
+
const parsed = parseGroupInviteLink(url);
|
|
1064
|
+
if (!parsed) {
|
|
1065
|
+
throw new Error('INVALID_INVITE_LINK: Could not parse invite link');
|
|
1066
|
+
}
|
|
1067
|
+
const mk = groupMasterKey(parsed.masterKey);
|
|
1068
|
+
const secretParams = deriveGroupSecretParams(mk);
|
|
1069
|
+
const groupIdHex = bytesToHex(secretParams.groupId);
|
|
1070
|
+
const groupIdPrefixed = createGroupId(groupIdHex);
|
|
1071
|
+
// Store master key locally (needed for getAuthorization)
|
|
1072
|
+
await this.store.storeMasterKey(groupIdHex, parsed.masterKey);
|
|
1073
|
+
const cachedBaseline = await this.store.getGroupState(groupIdHex);
|
|
1074
|
+
// A non-member receives only the reduced projection. The password is
|
|
1075
|
+
// independently checked here and again with the eventual submission
|
|
1076
|
+
// (S10/S11).
|
|
1077
|
+
const result = await this.withAuthRetry(groupIdHex, (auth) => this.server.getGroupJoinInfo(secretParams.groupId, parsed.inviteLinkPassword, auth));
|
|
1078
|
+
if (!result) {
|
|
1079
|
+
throw new Error('GROUP_NOT_FOUND: Group no longer exists');
|
|
1080
|
+
}
|
|
1081
|
+
const encryptedJoinInfo = deserializeEncryptedGroupJoinInfo(result.encryptedJoinInfo);
|
|
1082
|
+
const joinInfo = decryptGroupJoinInfo(secretParams, encryptedJoinInfo);
|
|
1083
|
+
const expectedPublicParams = serializeGroupPublicParams(getGroupPublicParams(secretParams));
|
|
1084
|
+
if (!bytesEqual(joinInfo.publicKey, expectedPublicParams)) {
|
|
1085
|
+
throw new Error('GROUP_BINDING_MISMATCH: Join-info public parameters do not match invite');
|
|
1086
|
+
}
|
|
1087
|
+
if (joinInfo.revision !== result.version) {
|
|
1088
|
+
throw new Error(`INVALID_CHANGE_SEQUENCE: Join info is ${joinInfo.revision}, response is ${result.version}`);
|
|
1089
|
+
}
|
|
1090
|
+
// An existing request is enough to read its own pending status even after
|
|
1091
|
+
// link rotation or disablement. It does not grant access to full state.
|
|
1092
|
+
if (joinInfo.pendingAdminApproval) {
|
|
1093
|
+
return { groupId: groupIdPrefixed, status: 'pending_approval' };
|
|
1094
|
+
}
|
|
1095
|
+
// Validate invite link access is enabled for a new request.
|
|
1096
|
+
if (joinInfo.addFromInviteLink === AccessRequired.UNSATISFIABLE ||
|
|
1097
|
+
joinInfo.addFromInviteLink === AccessRequired.UNKNOWN) {
|
|
1098
|
+
throw new Error('INVITE_LINK_DISABLED: Invite links are disabled');
|
|
1099
|
+
}
|
|
1100
|
+
const decryptBoundSnapshot = (snapshot, expectedVersion) => {
|
|
1101
|
+
if (expectedVersion !== undefined && snapshot.version !== expectedVersion) {
|
|
1102
|
+
throw new Error(`INVALID_CHANGE_SEQUENCE: Expected snapshot ${expectedVersion}, got ${snapshot.version}`);
|
|
1103
|
+
}
|
|
1104
|
+
return this.decryptVerifiedSnapshot(secretParams, snapshot);
|
|
1105
|
+
};
|
|
1106
|
+
// Preserve idempotency without exposing member lists to non-members. The
|
|
1107
|
+
// server either returns a full state because the authenticated requester is
|
|
1108
|
+
// already readable under S10, or rejects with FORBIDDEN and the link flow
|
|
1109
|
+
// continues using only GroupJoinInfo.
|
|
1110
|
+
let readableResult = null;
|
|
1111
|
+
try {
|
|
1112
|
+
readableResult = await this.withAuthRetry(groupIdHex, (auth) => this.server.getGroup(secretParams.groupId, auth));
|
|
1113
|
+
}
|
|
1114
|
+
catch (error) {
|
|
1115
|
+
if (!GroupManager.isNotReadableRejection(error))
|
|
1116
|
+
throw error;
|
|
1117
|
+
}
|
|
1118
|
+
if (readableResult) {
|
|
1119
|
+
const readableState = decryptBoundSnapshot(readableResult);
|
|
1120
|
+
if (isMember(readableState, userAci)) {
|
|
1121
|
+
if (!cachedBaseline) {
|
|
1122
|
+
await this.store.storeGroupState(groupIdHex, readableState);
|
|
1123
|
+
return { groupId: groupIdPrefixed, status: 'joined' };
|
|
1124
|
+
}
|
|
1125
|
+
if (!this.isReadableBySelf(cachedBaseline)) {
|
|
1126
|
+
if (readableState.revision <= cachedBaseline.revision) {
|
|
1127
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Re-entitlement baseline does not follow the revoked span');
|
|
1128
|
+
}
|
|
1129
|
+
await this.store.storeGroupState(groupIdHex, readableState);
|
|
1130
|
+
return { groupId: groupIdPrefixed, status: 'joined' };
|
|
1131
|
+
}
|
|
1132
|
+
const synced = await this.syncGroup(groupIdPrefixed);
|
|
1133
|
+
if (synced.revision < readableState.revision) {
|
|
1134
|
+
if (this.isReadableBySelf(synced)) {
|
|
1135
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Snapshot cannot bridge living group history');
|
|
1136
|
+
}
|
|
1137
|
+
await this.store.storeGroupState(groupIdHex, readableState);
|
|
1138
|
+
return { groupId: groupIdPrefixed, status: 'joined' };
|
|
1139
|
+
}
|
|
1140
|
+
if (!isMember(synced, userAci)) {
|
|
1141
|
+
throw new Error('INVALID_GROUP_STATE: Idempotent join no longer has member status');
|
|
1142
|
+
}
|
|
1143
|
+
return { groupId: groupIdPrefixed, status: 'joined' };
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
// Check group capacity
|
|
1147
|
+
if (joinInfo.memberCount >= MAX_GROUP_SIZE) {
|
|
1148
|
+
throw new Error(`GROUP_FULL: Group has reached maximum capacity of ${MAX_GROUP_SIZE} members`);
|
|
1149
|
+
}
|
|
1150
|
+
// This intentionally contains no member list. It is sufficient for the
|
|
1151
|
+
// state-decidable half of link-join authorization and for validating the
|
|
1152
|
+
// self-add transition without exposing existing membership (S10).
|
|
1153
|
+
const state = {
|
|
1154
|
+
title: joinInfo.title,
|
|
1155
|
+
avatar: joinInfo.avatar,
|
|
1156
|
+
disappearingMessagesTimer: { duration: 0 },
|
|
1157
|
+
accessControl: {
|
|
1158
|
+
...defaultAccessControl(),
|
|
1159
|
+
addFromInviteLink: joinInfo.addFromInviteLink,
|
|
1160
|
+
},
|
|
1161
|
+
revision: joinInfo.revision,
|
|
1162
|
+
members: [],
|
|
1163
|
+
pendingMembers: [],
|
|
1164
|
+
requestingMembers: [],
|
|
1165
|
+
inviteLinkPassword: new Uint8Array(0),
|
|
1166
|
+
description: joinInfo.description,
|
|
1167
|
+
isAnnouncementGroup: EnabledState.DISABLED,
|
|
1168
|
+
bannedMembers: [],
|
|
1169
|
+
terminated: false,
|
|
1170
|
+
};
|
|
1171
|
+
// editorServiceIdBytes must be 17 bytes (1 byte kind + 16 byte UUID)
|
|
1172
|
+
const editorServiceIdBytes = aciToServiceIdBytes(userAci);
|
|
1173
|
+
const change = emptyGroupChange(editorServiceIdBytes, state.revision + 1);
|
|
1174
|
+
const presentationCtx = await this.getPresentationContext();
|
|
1175
|
+
const memberContexts = new Map([
|
|
1176
|
+
[bytesToHex(userAci), presentationCtx],
|
|
1177
|
+
]);
|
|
1178
|
+
// Admin approval path: add to requestingMembers instead of members
|
|
1179
|
+
if (joinInfo.addFromInviteLink === AccessRequired.ADMINISTRATOR) {
|
|
1180
|
+
change.newRequestingMembers = [
|
|
1181
|
+
{
|
|
1182
|
+
aciBytes: userAci,
|
|
1183
|
+
profileKey: userProfileKey,
|
|
1184
|
+
},
|
|
1185
|
+
];
|
|
1186
|
+
const actions = encryptAndSerializeChange(change, secretParams, memberContexts);
|
|
1187
|
+
const entry = await this.withAuthRetry(groupIdHex, (auth) => this.server.submitGroupChange(secretParams.groupId, state.revision, actions, parsed.inviteLinkPassword, auth));
|
|
1188
|
+
await this.applyVerifiedChange(groupIdHex, state, entry, {
|
|
1189
|
+
persist: false,
|
|
1190
|
+
react: false,
|
|
1191
|
+
stateVisibility: 'group_join_info',
|
|
1192
|
+
});
|
|
1193
|
+
await this.invalidateEndorsements(groupIdHex);
|
|
1194
|
+
return { groupId: groupIdPrefixed, status: 'pending_approval' };
|
|
1195
|
+
}
|
|
1196
|
+
if (joinInfo.addFromInviteLink !== AccessRequired.ANY) {
|
|
1197
|
+
throw new Error(`INVITE_LINK_DISABLED: Unsupported invite-link mode`);
|
|
1198
|
+
}
|
|
1199
|
+
// Direct join path: add self as member
|
|
1200
|
+
change.newMembers = [
|
|
1201
|
+
{
|
|
1202
|
+
aciBytes: userAci,
|
|
1203
|
+
role: MemberRole.DEFAULT,
|
|
1204
|
+
profileKey: userProfileKey,
|
|
1205
|
+
},
|
|
1206
|
+
];
|
|
1207
|
+
const actions = encryptAndSerializeChange(change, secretParams, memberContexts);
|
|
1208
|
+
const entry = await this.withAuthRetry(groupIdHex, (auth) => this.server.submitGroupChange(secretParams.groupId, state.revision, actions, parsed.inviteLinkPassword, auth));
|
|
1209
|
+
await this.applyVerifiedChange(groupIdHex, state, entry, {
|
|
1210
|
+
persist: false,
|
|
1211
|
+
react: false,
|
|
1212
|
+
stateVisibility: 'group_join_info',
|
|
1213
|
+
});
|
|
1214
|
+
if (cachedBaseline && this.isReadableBySelf(cachedBaseline)) {
|
|
1215
|
+
const synced = await this.syncGroup(groupIdPrefixed);
|
|
1216
|
+
if (isMember(synced, userAci)) {
|
|
1217
|
+
await this.invalidateEndorsements(groupIdHex);
|
|
1218
|
+
return { groupId: groupIdPrefixed, status: 'joined' };
|
|
1219
|
+
}
|
|
1220
|
+
if (this.isReadableBySelf(synced)) {
|
|
1221
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Snapshot cannot bridge living group history');
|
|
1222
|
+
}
|
|
1223
|
+
if (entry.version <= synced.revision) {
|
|
1224
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Re-entitlement baseline does not follow the revoked span');
|
|
1225
|
+
}
|
|
1226
|
+
// S10 intentionally stops a stale reader at its own revoking
|
|
1227
|
+
// transition. The accepted, signed rejoin establishes a new entitlement
|
|
1228
|
+
// boundary, so continue below and install that exact accepted snapshot
|
|
1229
|
+
// as the new baseline.
|
|
1230
|
+
}
|
|
1231
|
+
else if (cachedBaseline && entry.version <= cachedBaseline.revision) {
|
|
1232
|
+
throw new Error('INVALID_CHANGE_SEQUENCE: Re-entitlement baseline does not follow the revoked span');
|
|
1233
|
+
}
|
|
1234
|
+
// The accepted, signed self-add makes the requester a member. Only now may
|
|
1235
|
+
// the client request the full state. Fetch the exact historical version
|
|
1236
|
+
// established by that verified transition so a concurrent later mutation
|
|
1237
|
+
// cannot force an unverified snapshot jump.
|
|
1238
|
+
let fullResult;
|
|
1239
|
+
try {
|
|
1240
|
+
fullResult = await this.withAuthRetry(groupIdHex, (auth) => this.server.getGroup(secretParams.groupId, auth, entry.version));
|
|
1241
|
+
}
|
|
1242
|
+
catch (error) {
|
|
1243
|
+
// Only the not-readable rejection is revocation. This is a *versioned*
|
|
1244
|
+
// read, so the same 403 code can also carry the join-version floor —
|
|
1245
|
+
// a rejection about one historical version, raised while the
|
|
1246
|
+
// membership itself is fine — and translating that into
|
|
1247
|
+
// GROUP_ACCESS_REVOKED would report a live member as removed.
|
|
1248
|
+
if (!GroupManager.isNotReadableRejection(error))
|
|
1249
|
+
throw error;
|
|
1250
|
+
// The join was accepted and signed, then revoked before this read: the
|
|
1251
|
+
// server authorizes reads at the current state, and the current state
|
|
1252
|
+
// no longer lists us. Surface the revocation instead of claiming a
|
|
1253
|
+
// membership we can neither read nor verify — no state is installed,
|
|
1254
|
+
// and from here this principal is the ordinary re-entitlement case: a
|
|
1255
|
+
// later re-add or approval serves a fresh signed baseline.
|
|
1256
|
+
throw new Error('GROUP_ACCESS_REVOKED: Join was accepted, then revoked before its baseline could be read');
|
|
1257
|
+
}
|
|
1258
|
+
if (!fullResult) {
|
|
1259
|
+
throw new Error(`GROUP_SNAPSHOT_NOT_FOUND: Accepted join snapshot ${entry.version} is unavailable`);
|
|
1260
|
+
}
|
|
1261
|
+
const joinedState = decryptBoundSnapshot(fullResult, entry.version);
|
|
1262
|
+
if (!isMember(joinedState, userAci)) {
|
|
1263
|
+
throw new Error('INVALID_GROUP_SNAPSHOT: Accepted join is absent from returned state');
|
|
1264
|
+
}
|
|
1265
|
+
await this.store.storeGroupState(groupIdHex, joinedState);
|
|
1266
|
+
await this.invalidateEndorsements(groupIdHex);
|
|
1267
|
+
return { groupId: groupIdPrefixed, status: 'joined' };
|
|
1268
|
+
}
|
|
1269
|
+
// =========================================================================
|
|
1270
|
+
// Internal helpers
|
|
1271
|
+
// =========================================================================
|
|
1272
|
+
/**
|
|
1273
|
+
* Whether a server rejection means "you may not read this group at all".
|
|
1274
|
+
*
|
|
1275
|
+
* Only the `not_readable` FORBIDDEN carries that meaning — it is what the
|
|
1276
|
+
* server raises when the requester is banned or absent from the
|
|
1277
|
+
* authorizing roster, and it is the sole rejection a client may interpret
|
|
1278
|
+
* as revocation. The same code with reason `before_join` is the
|
|
1279
|
+
* join-version floor: it refuses one historical version while saying
|
|
1280
|
+
* nothing about current access, so treating it as revocation would
|
|
1281
|
+
* mistranslate a live membership into "revoked". Anything else (bad
|
|
1282
|
+
* presentation, malformed request) is not an access answer at all.
|
|
1283
|
+
*/
|
|
1284
|
+
static isNotReadableRejection(error) {
|
|
1285
|
+
const data = error != null && typeof error === 'object' && 'data' in error
|
|
1286
|
+
? error.data
|
|
1287
|
+
: undefined;
|
|
1288
|
+
return data?.code === 'FORBIDDEN' && data?.reason === 'not_readable';
|
|
1289
|
+
}
|
|
1290
|
+
/** Whether this client's verified local span still carries full-state read access. */
|
|
1291
|
+
isReadableBySelf(state) {
|
|
1292
|
+
const aciServiceId = serviceIdBinary(this.aci);
|
|
1293
|
+
const pniServiceId = this.pni === undefined ? undefined : serviceIdBinary(this.pni);
|
|
1294
|
+
if (isBanned(state, aciServiceId) ||
|
|
1295
|
+
(pniServiceId !== undefined && isBanned(state, pniServiceId))) {
|
|
1296
|
+
return false;
|
|
1297
|
+
}
|
|
1298
|
+
return (isMember(state, this.aci.uuid) ||
|
|
1299
|
+
isPending(state, aciServiceId) ||
|
|
1300
|
+
(pniServiceId !== undefined && isPending(state, pniServiceId)));
|
|
1301
|
+
}
|
|
1302
|
+
/** Verify the S14 commitment before parsing or installing a snapshot. */
|
|
1303
|
+
verifyBaselineSignature(groupId, snapshot) {
|
|
1304
|
+
if (this.serverSigningPublicKey &&
|
|
1305
|
+
!serverVerifySignature({ signingPublicKey: this.serverSigningPublicKey }, serializeGroupBaseline(groupId, snapshot.version, snapshot.encryptedState), snapshot.baselineSignature)) {
|
|
1306
|
+
throw new Error('INVALID_SERVER_SIGNATURE: Group baseline signature verification failed');
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
/** Verify, bind, and decrypt one canonical full-state response. */
|
|
1310
|
+
decryptVerifiedSnapshot(secretParams, snapshot) {
|
|
1311
|
+
this.verifyBaselineSignature(secretParams.groupId, snapshot);
|
|
1312
|
+
const encryptedState = deserializeEncryptedGroup(snapshot.encryptedState);
|
|
1313
|
+
try {
|
|
1314
|
+
assertValidEncryptedGroupWire(encryptedState);
|
|
1315
|
+
}
|
|
1316
|
+
catch (error) {
|
|
1317
|
+
throw new Error(`INVALID_GROUP_SNAPSHOT: ${error instanceof Error ? error.message : 'Encrypted state is malformed'}`);
|
|
1318
|
+
}
|
|
1319
|
+
const expectedPublicParams = serializeGroupPublicParams(getGroupPublicParams(secretParams));
|
|
1320
|
+
if (!bytesEqual(encryptedState.publicKey, expectedPublicParams)) {
|
|
1321
|
+
throw new Error('GROUP_BINDING_MISMATCH: Snapshot public parameters do not match group');
|
|
1322
|
+
}
|
|
1323
|
+
if (encryptedState.version !== snapshot.version) {
|
|
1324
|
+
throw new Error(`INVALID_CHANGE_SEQUENCE: Snapshot is ${encryptedState.version}, response is ${snapshot.version}`);
|
|
1325
|
+
}
|
|
1326
|
+
const state = decryptGroupState(secretParams, encryptedState);
|
|
1327
|
+
if (state.revision !== snapshot.version) {
|
|
1328
|
+
throw new Error(`INVALID_GROUP_SNAPSHOT: State revision ${state.revision} does not match ${snapshot.version}`);
|
|
1329
|
+
}
|
|
1330
|
+
return state;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Get GroupSecretParams for a group from stored master key.
|
|
1334
|
+
*/
|
|
1335
|
+
async getSecretParams(rawGroupId) {
|
|
1336
|
+
const masterKeyBytes = await this.store.getMasterKey(rawGroupId);
|
|
1337
|
+
if (!masterKeyBytes) {
|
|
1338
|
+
throw new Error(`MASTER_KEY_NOT_FOUND: No master key for group ${rawGroupId}`);
|
|
1339
|
+
}
|
|
1340
|
+
const mk = groupMasterKey(masterKeyBytes);
|
|
1341
|
+
return deriveGroupSecretParams(mk);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Submit a change to the server and update local state.
|
|
1345
|
+
*
|
|
1346
|
+
* @param memberPresentationContexts - Optional presentation contexts for members
|
|
1347
|
+
* being added. Keyed by ACI hex. The reference implementation always includes a presentation when
|
|
1348
|
+
* adding a full member (AddMemberAction, PromotePending, etc.).
|
|
1349
|
+
*/
|
|
1350
|
+
async submitChange(rawGroupId, currentState, change, memberPresentationContexts) {
|
|
1351
|
+
const MAX_VERSION_CONFLICT_RETRIES = 3;
|
|
1352
|
+
let state = currentState;
|
|
1353
|
+
for (let attempt = 0; attempt <= MAX_VERSION_CONFLICT_RETRIES; attempt++) {
|
|
1354
|
+
const editorServiceIdBytes = this.actionNamedSourceServiceId(change) ??
|
|
1355
|
+
this.sourceServiceIdForState(state);
|
|
1356
|
+
// Re-base the change onto the current state revision
|
|
1357
|
+
const rebasedChange = {
|
|
1358
|
+
...change,
|
|
1359
|
+
editorServiceIdBytes,
|
|
1360
|
+
revision: state.revision + 1,
|
|
1361
|
+
};
|
|
1362
|
+
// Authorization and structural validity are deliberately independent.
|
|
1363
|
+
const authorizationErrors = validateChangeAuthorization(state, rebasedChange);
|
|
1364
|
+
if (authorizationErrors.length > 0) {
|
|
1365
|
+
throw new Error(`UNAUTHORIZED_CHANGE: ${authorizationErrors.join(', ')}`);
|
|
1366
|
+
}
|
|
1367
|
+
const structuralErrors = validateChangeStructure(state, rebasedChange, 'submission');
|
|
1368
|
+
if (structuralErrors.length > 0) {
|
|
1369
|
+
throw new Error(`INVALID_CHANGE: ${structuralErrors.join(', ')}`);
|
|
1370
|
+
}
|
|
1371
|
+
// The server applies ciphertext actions to its own pre-change state.
|
|
1372
|
+
// Sending a client-computed replacement snapshot would make S4/S5
|
|
1373
|
+
// enforcement meaningless.
|
|
1374
|
+
const secretParams = await this.getSecretParams(rawGroupId);
|
|
1375
|
+
const actions = encryptAndSerializeChange(rebasedChange, secretParams, memberPresentationContexts);
|
|
1376
|
+
try {
|
|
1377
|
+
const entry = await this.withAuthRetry(rawGroupId, (auth) => this.server.submitGroupChange(secretParams.groupId, state.revision, actions, new Uint8Array(0), auth));
|
|
1378
|
+
await this.applyVerifiedChange(rawGroupId, state, entry);
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
catch (err) {
|
|
1382
|
+
const conflictData = err != null && typeof err === 'object' && 'data' in err
|
|
1383
|
+
? err.data
|
|
1384
|
+
: undefined;
|
|
1385
|
+
// Detect VERSION_CONFLICT from ConvexError structured data
|
|
1386
|
+
const isVersionConflict = conflictData?.code === 'VERSION_CONFLICT';
|
|
1387
|
+
if (!isVersionConflict || attempt === MAX_VERSION_CONFLICT_RETRIES) {
|
|
1388
|
+
throw err;
|
|
1389
|
+
}
|
|
1390
|
+
// Re-sync group state from server and retry
|
|
1391
|
+
const groupId = createGroupId(rawGroupId);
|
|
1392
|
+
state = await this.syncGroup(groupId);
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
/**
|
|
1397
|
+
* Mirror S3's action-named attribution before falling back to state lookup.
|
|
1398
|
+
*
|
|
1399
|
+
* A self-targeted pending delete exercises the named alias, as does a
|
|
1400
|
+
* PNI-to-ACI promotion. One accepted change may exercise only one alias.
|
|
1401
|
+
*/
|
|
1402
|
+
actionNamedSourceServiceId(change) {
|
|
1403
|
+
const aciServiceId = serviceIdBinary(this.aci);
|
|
1404
|
+
const pniServiceId = this.pni === undefined ? undefined : serviceIdBinary(this.pni);
|
|
1405
|
+
const candidates = [];
|
|
1406
|
+
const addCandidate = (candidate) => {
|
|
1407
|
+
if (!candidates.some((current) => bytesEqual(current, candidate))) {
|
|
1408
|
+
candidates.push(candidate);
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
for (const promotion of change.promotePendingPniAciMembers) {
|
|
1412
|
+
if (pniServiceId !== undefined &&
|
|
1413
|
+
bytesEqual(promotion.pniBytes, this.pni.uuid)) {
|
|
1414
|
+
addCandidate(pniServiceId);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
for (const removal of change.deletePendingMembers) {
|
|
1418
|
+
if (bytesEqual(removal.serviceIdBytes, aciServiceId)) {
|
|
1419
|
+
addCandidate(aciServiceId);
|
|
1420
|
+
}
|
|
1421
|
+
else if (pniServiceId !== undefined &&
|
|
1422
|
+
bytesEqual(removal.serviceIdBytes, pniServiceId)) {
|
|
1423
|
+
addCandidate(pniServiceId);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (change.deleteRequestingMembers.some((target) => bytesEqual(target, this.aci.uuid))) {
|
|
1427
|
+
addCandidate(aciServiceId);
|
|
1428
|
+
}
|
|
1429
|
+
if (candidates.length > 1) {
|
|
1430
|
+
throw new Error('AMBIGUOUS_CHANGE_ATTRIBUTION: A change cannot exercise self-rights under multiple aliases');
|
|
1431
|
+
}
|
|
1432
|
+
return candidates[0];
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Mirror S3's deterministic pre-state attribution for ordinary actions.
|
|
1436
|
+
*
|
|
1437
|
+
* ACI wins when both aliases occur in state; a PNI-only pending invitee is
|
|
1438
|
+
* attributed to that PNI so self-decline remains possible.
|
|
1439
|
+
*/
|
|
1440
|
+
sourceServiceIdForState(state) {
|
|
1441
|
+
const aciServiceId = serviceIdBinary(this.aci);
|
|
1442
|
+
const aciMatches = isMember(state, this.aci.uuid) ||
|
|
1443
|
+
isPending(state, aciServiceId) ||
|
|
1444
|
+
state.requestingMembers.some((member) => bytesEqual(member.aciBytes, this.aci.uuid));
|
|
1445
|
+
if (aciMatches || this.pni === undefined)
|
|
1446
|
+
return aciServiceId;
|
|
1447
|
+
const pniServiceId = serviceIdBinary(this.pni);
|
|
1448
|
+
return isPending(state, pniServiceId)
|
|
1449
|
+
? pniServiceId
|
|
1450
|
+
: aciServiceId;
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
/**
|
|
1454
|
+
* Encrypt and serialize a DecryptedGroupChange for server submission.
|
|
1455
|
+
*
|
|
1456
|
+
* The client deliberately leaves sourceUserId and groupId unset. A conforming
|
|
1457
|
+
* server derives and sets both before signing the accepted Actions.
|
|
1458
|
+
*/
|
|
1459
|
+
export function encryptAndSerializeChange(change, secretParams, memberPresentationContexts) {
|
|
1460
|
+
const errors = [
|
|
1461
|
+
...validateChangeIdentifiers(change),
|
|
1462
|
+
...validateChangeAccessControl(change),
|
|
1463
|
+
...validateChangeMemberRoles(change),
|
|
1464
|
+
];
|
|
1465
|
+
if (errors.length > 0) {
|
|
1466
|
+
throw new Error(`INVALID_CHANGE: ${errors.join('; ')}`);
|
|
1467
|
+
}
|
|
1468
|
+
if (!Number.isSafeInteger(change.revision) || change.revision < 1) {
|
|
1469
|
+
throw new Error('INVALID_CHANGE: change revision must be a positive safe integer');
|
|
1470
|
+
}
|
|
1471
|
+
if (change.newIsAnnouncementGroup !== undefined &&
|
|
1472
|
+
change.newIsAnnouncementGroup !== EnabledState.ENABLED &&
|
|
1473
|
+
change.newIsAnnouncementGroup !== EnabledState.DISABLED) {
|
|
1474
|
+
throw new Error('INVALID_CHANGE: newIsAnnouncementGroup is outside its §7.8 domain');
|
|
1475
|
+
}
|
|
1476
|
+
const { newInviteLinkPassword: actionPw } = change;
|
|
1477
|
+
if (actionPw !== undefined &&
|
|
1478
|
+
actionPw.length !== 16) {
|
|
1479
|
+
throw new Error('INVALID_CHANGE: newInviteLinkPassword must be exactly 16 bytes');
|
|
1480
|
+
}
|
|
1481
|
+
const encrypted = encryptChangeFields(change, secretParams, memberPresentationContexts);
|
|
1482
|
+
assertEncryptedGroupChangeForm(encrypted, 'submission');
|
|
1483
|
+
return serializeEncryptedGroupChange(encrypted);
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Deserialize and decrypt a change from server.
|
|
1487
|
+
*
|
|
1488
|
+
* Restores JSON from bytes, then decrypts identity fields back to plaintext.
|
|
1489
|
+
*/
|
|
1490
|
+
export function deserializeAndDecryptChange(bytes, secretParams) {
|
|
1491
|
+
return decryptChangeFields(deserializeEncryptedGroupChange(bytes), secretParams);
|
|
1492
|
+
}
|
|
1493
|
+
// ---------------------------------------------------------------------------
|
|
1494
|
+
// Change field encryption helpers
|
|
1495
|
+
// ---------------------------------------------------------------------------
|
|
1496
|
+
/** Encrypt a 16-byte ACI as a UuidCiphertext. */
|
|
1497
|
+
function encryptAci(secretParams, aciBytes) {
|
|
1498
|
+
const serviceId = { kind: SERVICE_ID_ACI, uuid: aciBytes };
|
|
1499
|
+
return encryptUuid(secretParams, serviceId);
|
|
1500
|
+
}
|
|
1501
|
+
/** Encrypt a 17-byte ServiceId (kind + uuid) as a UuidCiphertext. */
|
|
1502
|
+
function encryptServiceIdBytes(secretParams, serviceIdBytes) {
|
|
1503
|
+
if (serviceIdBytes.length !== 17) {
|
|
1504
|
+
throw new Error(`ServiceIdBytes must be 17 bytes, got ${serviceIdBytes.length}`);
|
|
1505
|
+
}
|
|
1506
|
+
const kind = serviceIdBytes[0];
|
|
1507
|
+
if (kind !== SERVICE_ID_ACI && kind !== SERVICE_ID_PNI) {
|
|
1508
|
+
throw new Error(`Invalid ServiceId kind byte: 0x${kind.toString(16).padStart(2, '0')}`);
|
|
1509
|
+
}
|
|
1510
|
+
const serviceId = { kind, uuid: serviceIdBytes.slice(1) };
|
|
1511
|
+
return encryptUuid(secretParams, serviceId);
|
|
1512
|
+
}
|
|
1513
|
+
/** Decrypt a UuidCiphertext back to 16-byte ACI UUID. */
|
|
1514
|
+
function decryptAci(secretParams, ciphertext) {
|
|
1515
|
+
const serviceId = decryptUuid(secretParams, ciphertext);
|
|
1516
|
+
if (serviceId.kind !== SERVICE_ID_ACI) {
|
|
1517
|
+
throw new Error(`Expected ACI service ID, got kind ${serviceId.kind}`);
|
|
1518
|
+
}
|
|
1519
|
+
return serviceId.uuid;
|
|
1520
|
+
}
|
|
1521
|
+
/** Decrypt a UuidCiphertext back to 17-byte ServiceId binary. */
|
|
1522
|
+
function decryptServiceIdBytes(secretParams, ciphertext) {
|
|
1523
|
+
const serviceId = decryptUuid(secretParams, ciphertext);
|
|
1524
|
+
return serviceIdBinary(serviceId);
|
|
1525
|
+
}
|
|
1526
|
+
function decryptQuarantinableServiceId(secretParams, ciphertext, requiredKind) {
|
|
1527
|
+
let serviceId;
|
|
1528
|
+
try {
|
|
1529
|
+
serviceId = decryptUuid(secretParams, ciphertext);
|
|
1530
|
+
}
|
|
1531
|
+
catch {
|
|
1532
|
+
return undefined;
|
|
1533
|
+
}
|
|
1534
|
+
if (requiredKind !== undefined && serviceId.kind !== requiredKind) {
|
|
1535
|
+
throw new Error(`Expected service ID kind ${requiredKind}, got ${serviceId.kind}`);
|
|
1536
|
+
}
|
|
1537
|
+
return isNilUuid(serviceId.uuid)
|
|
1538
|
+
? undefined
|
|
1539
|
+
: serviceIdBinary(serviceId);
|
|
1540
|
+
}
|
|
1541
|
+
// ---------------------------------------------------------------------------
|
|
1542
|
+
// Member-level encryption/decryption for change actions
|
|
1543
|
+
// ---------------------------------------------------------------------------
|
|
1544
|
+
function encryptProfileKeyActionFields(secretParams, member, presentationContext) {
|
|
1545
|
+
const encryptedMember = encryptMember(secretParams, {
|
|
1546
|
+
...member,
|
|
1547
|
+
role: MemberRole.DEFAULT,
|
|
1548
|
+
joinedAtRevision: 0,
|
|
1549
|
+
pniBytes: new Uint8Array(0),
|
|
1550
|
+
labelEmoji: '',
|
|
1551
|
+
labelString: '',
|
|
1552
|
+
}, presentationContext);
|
|
1553
|
+
return {
|
|
1554
|
+
aciCiphertext: encryptedMember.userId,
|
|
1555
|
+
profileKeyCiphertext: encryptedMember.profileKey,
|
|
1556
|
+
presentation: encryptedMember.presentation,
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
function decryptProfileKeyActionFields(secretParams, member) {
|
|
1560
|
+
const aciBytes = decryptAci(secretParams, member.aciCiphertext);
|
|
1561
|
+
return {
|
|
1562
|
+
aciBytes,
|
|
1563
|
+
profileKey: decryptProfileKeyCiphertext(secretParams, member.profileKeyCiphertext, aciBytes),
|
|
1564
|
+
};
|
|
1565
|
+
}
|
|
1566
|
+
function encryptChangeAddMember(secretParams, member, presentationContext) {
|
|
1567
|
+
return {
|
|
1568
|
+
...encryptProfileKeyActionFields(secretParams, member, presentationContext),
|
|
1569
|
+
role: member.role,
|
|
1570
|
+
...(member.joinedAtRevision === undefined
|
|
1571
|
+
? {}
|
|
1572
|
+
: { joinedAtRevision: member.joinedAtRevision }),
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
function decryptChangeAddMember(secretParams, member) {
|
|
1576
|
+
return {
|
|
1577
|
+
...decryptProfileKeyActionFields(secretParams, member),
|
|
1578
|
+
role: member.role,
|
|
1579
|
+
...(member.joinedAtRevision === undefined
|
|
1580
|
+
? {}
|
|
1581
|
+
: { joinedAtRevision: member.joinedAtRevision }),
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
function encryptChangePendingPromotion(secretParams, member, presentationContext) {
|
|
1585
|
+
return {
|
|
1586
|
+
...encryptProfileKeyActionFields(secretParams, member, presentationContext),
|
|
1587
|
+
...(member.role === undefined ? {} : { role: member.role }),
|
|
1588
|
+
...(member.joinedAtRevision === undefined
|
|
1589
|
+
? {}
|
|
1590
|
+
: { joinedAtRevision: member.joinedAtRevision }),
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
function decryptChangePendingPromotion(secretParams, member) {
|
|
1594
|
+
return {
|
|
1595
|
+
...decryptProfileKeyActionFields(secretParams, member),
|
|
1596
|
+
...(member.role === undefined ? {} : { role: member.role }),
|
|
1597
|
+
...(member.joinedAtRevision === undefined
|
|
1598
|
+
? {}
|
|
1599
|
+
: { joinedAtRevision: member.joinedAtRevision }),
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1602
|
+
function encryptChangePniAciPromotion(secretParams, member, presentationContext) {
|
|
1603
|
+
return {
|
|
1604
|
+
...encryptChangePendingPromotion(secretParams, member, presentationContext),
|
|
1605
|
+
pniCiphertext: encryptUuid(secretParams, {
|
|
1606
|
+
kind: SERVICE_ID_PNI,
|
|
1607
|
+
uuid: member.pniBytes,
|
|
1608
|
+
}),
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
function decryptChangePniAciPromotion(secretParams, member) {
|
|
1612
|
+
const pni = decryptUuid(secretParams, member.pniCiphertext);
|
|
1613
|
+
if (pni.kind !== SERVICE_ID_PNI) {
|
|
1614
|
+
throw new Error(`Expected PNI service ID, got kind ${pni.kind}`);
|
|
1615
|
+
}
|
|
1616
|
+
return {
|
|
1617
|
+
...decryptChangePendingPromotion(secretParams, member),
|
|
1618
|
+
pniBytes: pni.uuid,
|
|
1619
|
+
};
|
|
1620
|
+
}
|
|
1621
|
+
function encryptChangePendingMember(secretParams, pending) {
|
|
1622
|
+
if (pending.quarantined === true) {
|
|
1623
|
+
throw new Error('INVALID_CHANGE: Quarantined pending entries cannot be submitted');
|
|
1624
|
+
}
|
|
1625
|
+
return {
|
|
1626
|
+
serviceIdCiphertext: encryptServiceIdBytes(secretParams, pending.serviceIdBytes),
|
|
1627
|
+
role: pending.role,
|
|
1628
|
+
...(pending.addedByAci === undefined
|
|
1629
|
+
? {}
|
|
1630
|
+
: { addedByAciCiphertext: encryptAci(secretParams, pending.addedByAci) }),
|
|
1631
|
+
...(pending.timestamp === undefined ? {} : { timestamp: pending.timestamp }),
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
function decryptChangePendingMember(secretParams, pending) {
|
|
1635
|
+
const serviceIdBytes = decryptQuarantinableServiceId(secretParams, pending.serviceIdCiphertext);
|
|
1636
|
+
return {
|
|
1637
|
+
serviceIdBytes: serviceIdBytes ?? new Uint8Array(0),
|
|
1638
|
+
role: pending.role,
|
|
1639
|
+
...(pending.addedByAciCiphertext === undefined
|
|
1640
|
+
? {}
|
|
1641
|
+
: {
|
|
1642
|
+
addedByAci: decryptAci(secretParams, pending.addedByAciCiphertext),
|
|
1643
|
+
}),
|
|
1644
|
+
...(pending.timestamp === undefined ? {} : { timestamp: pending.timestamp }),
|
|
1645
|
+
// Preserve ciphertext for re-encryption on removal
|
|
1646
|
+
serviceIdCipherText: new Uint8Array(pending.serviceIdCiphertext),
|
|
1647
|
+
...(serviceIdBytes === undefined ? { quarantined: true } : {}),
|
|
1648
|
+
};
|
|
1649
|
+
}
|
|
1650
|
+
function encryptChangePendingMemberRemoval(secretParams, removal) {
|
|
1651
|
+
// Use the preserved ciphertext if available; otherwise encrypt from plaintext
|
|
1652
|
+
if (removal.serviceIdCipherText.length > 0) {
|
|
1653
|
+
return { serviceIdCiphertext: removal.serviceIdCipherText };
|
|
1654
|
+
}
|
|
1655
|
+
return {
|
|
1656
|
+
serviceIdCiphertext: encryptServiceIdBytes(secretParams, removal.serviceIdBytes),
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
function decryptChangePendingMemberRemoval(secretParams, removal) {
|
|
1660
|
+
const serviceIdBytes = decryptQuarantinableServiceId(secretParams, removal.serviceIdCiphertext);
|
|
1661
|
+
return {
|
|
1662
|
+
serviceIdBytes: serviceIdBytes ?? new Uint8Array(0),
|
|
1663
|
+
serviceIdCipherText: new Uint8Array(removal.serviceIdCiphertext),
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
function encryptChangeRequestingMember(secretParams, member, presentationContext) {
|
|
1667
|
+
if (member.quarantined === true) {
|
|
1668
|
+
throw new Error('INVALID_CHANGE: Quarantined requesting entries cannot be submitted');
|
|
1669
|
+
}
|
|
1670
|
+
const encryptedMember = encryptProfileKeyActionFields(secretParams, member, presentationContext);
|
|
1671
|
+
return {
|
|
1672
|
+
aciCiphertext: encryptedMember.aciCiphertext,
|
|
1673
|
+
profileKeyCiphertext: encryptedMember.profileKeyCiphertext,
|
|
1674
|
+
presentation: encryptedMember.presentation,
|
|
1675
|
+
...(member.timestamp === undefined ? {} : { timestamp: member.timestamp }),
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
function decryptChangeRequestingMember(secretParams, member) {
|
|
1679
|
+
const serviceIdBytes = decryptQuarantinableServiceId(secretParams, member.aciCiphertext, SERVICE_ID_ACI);
|
|
1680
|
+
if (serviceIdBytes === undefined) {
|
|
1681
|
+
return {
|
|
1682
|
+
aciBytes: new Uint8Array(0),
|
|
1683
|
+
profileKey: new Uint8Array(0),
|
|
1684
|
+
aciCipherText: new Uint8Array(member.aciCiphertext),
|
|
1685
|
+
profileKeyCipherText: new Uint8Array(member.profileKeyCiphertext),
|
|
1686
|
+
quarantined: true,
|
|
1687
|
+
...(member.timestamp === undefined ? {} : { timestamp: member.timestamp }),
|
|
1688
|
+
};
|
|
1689
|
+
}
|
|
1690
|
+
return {
|
|
1691
|
+
...decryptProfileKeyActionFields(secretParams, member),
|
|
1692
|
+
...(member.timestamp === undefined ? {} : { timestamp: member.timestamp }),
|
|
1693
|
+
};
|
|
1694
|
+
}
|
|
1695
|
+
function encryptChangeApproveMember(secretParams, member) {
|
|
1696
|
+
return {
|
|
1697
|
+
aciCiphertext: encryptAci(secretParams, member.aciBytes),
|
|
1698
|
+
role: member.role,
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
function decryptChangeApproveMember(secretParams, member) {
|
|
1702
|
+
return {
|
|
1703
|
+
aciBytes: decryptAci(secretParams, member.aciCiphertext),
|
|
1704
|
+
role: member.role,
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
function encryptChangeModifyMemberRole(secretParams, modify) {
|
|
1708
|
+
return {
|
|
1709
|
+
aciCiphertext: encryptAci(secretParams, modify.aciBytes),
|
|
1710
|
+
role: modify.role,
|
|
1711
|
+
};
|
|
1712
|
+
}
|
|
1713
|
+
function decryptChangeModifyMemberRole(secretParams, modify) {
|
|
1714
|
+
return {
|
|
1715
|
+
aciBytes: decryptAci(secretParams, modify.aciCiphertext),
|
|
1716
|
+
role: modify.role,
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
function encryptChangeBannedMember(secretParams, member) {
|
|
1720
|
+
if (member.quarantined === true) {
|
|
1721
|
+
throw new Error('INVALID_CHANGE: Quarantined banned entries cannot be submitted');
|
|
1722
|
+
}
|
|
1723
|
+
return {
|
|
1724
|
+
serviceIdCiphertext: encryptServiceIdBytes(secretParams, member.serviceIdBytes),
|
|
1725
|
+
...(member.timestamp === undefined ? {} : { timestamp: member.timestamp }),
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
function decryptChangeBannedMember(secretParams, member) {
|
|
1729
|
+
const serviceIdBytes = decryptQuarantinableServiceId(secretParams, member.serviceIdCiphertext);
|
|
1730
|
+
return {
|
|
1731
|
+
serviceIdBytes: serviceIdBytes ?? new Uint8Array(0),
|
|
1732
|
+
...(serviceIdBytes === undefined
|
|
1733
|
+
? {
|
|
1734
|
+
serviceIdCipherText: new Uint8Array(member.serviceIdCiphertext),
|
|
1735
|
+
quarantined: true,
|
|
1736
|
+
}
|
|
1737
|
+
: {}),
|
|
1738
|
+
...(member.timestamp === undefined ? {} : { timestamp: member.timestamp }),
|
|
1739
|
+
};
|
|
1740
|
+
}
|
|
1741
|
+
function encryptChangeBannedMemberRemoval(secretParams, member) {
|
|
1742
|
+
return {
|
|
1743
|
+
serviceIdCiphertext: member.serviceIdCipherText !== undefined
|
|
1744
|
+
? new Uint8Array(member.serviceIdCipherText)
|
|
1745
|
+
: encryptServiceIdBytes(secretParams, member.serviceIdBytes),
|
|
1746
|
+
};
|
|
1747
|
+
}
|
|
1748
|
+
function decryptChangeBannedMemberRemoval(secretParams, member) {
|
|
1749
|
+
const serviceIdBytes = decryptQuarantinableServiceId(secretParams, member.serviceIdCiphertext);
|
|
1750
|
+
return {
|
|
1751
|
+
serviceIdBytes: serviceIdBytes ?? new Uint8Array(0),
|
|
1752
|
+
...(serviceIdBytes === undefined
|
|
1753
|
+
? { serviceIdCipherText: new Uint8Array(member.serviceIdCiphertext) }
|
|
1754
|
+
: {}),
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
function encryptChangeModifyMemberLabel(secretParams, modify) {
|
|
1758
|
+
return {
|
|
1759
|
+
aciCiphertext: encryptAci(secretParams, modify.aciBytes),
|
|
1760
|
+
labelEmojiCiphertext: encryptLabelAsBlob(secretParams, modify.labelEmoji),
|
|
1761
|
+
labelStringCiphertext: encryptLabelAsBlob(secretParams, modify.labelString),
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1764
|
+
function decryptChangeModifyMemberLabel(secretParams, modify) {
|
|
1765
|
+
return {
|
|
1766
|
+
aciBytes: decryptAci(secretParams, modify.aciCiphertext),
|
|
1767
|
+
labelEmoji: decryptLabelFromBlob(secretParams, modify.labelEmojiCiphertext),
|
|
1768
|
+
labelString: decryptLabelFromBlob(secretParams, modify.labelStringCiphertext),
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
// ---------------------------------------------------------------------------
|
|
1772
|
+
// Top-level change encryption/decryption
|
|
1773
|
+
// ---------------------------------------------------------------------------
|
|
1774
|
+
/**
|
|
1775
|
+
* Encrypt all identity fields in a DecryptedGroupChange.
|
|
1776
|
+
*
|
|
1777
|
+
* Walks each action type and encrypts ACI, PNI, and profileKey fields
|
|
1778
|
+
* using zkgroup primitives. Public policy and sequencing fields pass through.
|
|
1779
|
+
*/
|
|
1780
|
+
function encryptChangeFields(change, secretParams, memberPresentationContexts) {
|
|
1781
|
+
const presentationFor = (aciBytes) => memberPresentationContexts?.get(bytesToHex(aciBytes));
|
|
1782
|
+
const randomness = () => crypto.getRandomValues(new Uint8Array(32));
|
|
1783
|
+
return {
|
|
1784
|
+
revision: change.revision,
|
|
1785
|
+
// Membership
|
|
1786
|
+
newMembers: change.newMembers.map((m) => encryptChangeAddMember(secretParams, m, presentationFor(m.aciBytes))),
|
|
1787
|
+
deleteMembers: change.deleteMembers.map((aci) => encryptAci(secretParams, aci)),
|
|
1788
|
+
modifyMemberRoles: change.modifyMemberRoles.map((m) => encryptChangeModifyMemberRole(secretParams, m)),
|
|
1789
|
+
modifiedProfileKeys: change.modifiedProfileKeys.map((m) => encryptProfileKeyActionFields(secretParams, m, presentationFor(m.aciBytes))),
|
|
1790
|
+
// Pending members
|
|
1791
|
+
newPendingMembers: change.newPendingMembers.map((m) => encryptChangePendingMember(secretParams, m)),
|
|
1792
|
+
deletePendingMembers: change.deletePendingMembers.map((m) => encryptChangePendingMemberRemoval(secretParams, m)),
|
|
1793
|
+
promotePendingMembers: change.promotePendingMembers.map((m) => encryptChangePendingPromotion(secretParams, m, presentationFor(m.aciBytes))),
|
|
1794
|
+
// Attributes
|
|
1795
|
+
newTitle: change.newTitle === undefined
|
|
1796
|
+
? undefined
|
|
1797
|
+
: encryptGroupTitle(secretParams, randomness(), change.newTitle.value),
|
|
1798
|
+
newAvatar: change.newAvatar,
|
|
1799
|
+
newTimer: change.newTimer === undefined
|
|
1800
|
+
? undefined
|
|
1801
|
+
: encryptDisappearingMessagesTimer(secretParams, randomness(), change.newTimer.duration),
|
|
1802
|
+
// Access control (pass through)
|
|
1803
|
+
newAttributeAccess: change.newAttributeAccess,
|
|
1804
|
+
newMemberAccess: change.newMemberAccess,
|
|
1805
|
+
newInviteLinkAccess: change.newInviteLinkAccess,
|
|
1806
|
+
newMemberLabelAccess: change.newMemberLabelAccess,
|
|
1807
|
+
// Requesting members
|
|
1808
|
+
newRequestingMembers: change.newRequestingMembers.map((m) => encryptChangeRequestingMember(secretParams, m, presentationFor(m.aciBytes))),
|
|
1809
|
+
deleteRequestingMembers: change.deleteRequestingMembers.map((aciOrCiphertext) => aciOrCiphertext.length === 65
|
|
1810
|
+
? new Uint8Array(aciOrCiphertext)
|
|
1811
|
+
: encryptAci(secretParams, aciOrCiphertext)),
|
|
1812
|
+
promoteRequestingMembers: change.promoteRequestingMembers.map((m) => encryptChangeApproveMember(secretParams, m)),
|
|
1813
|
+
// Invite link (pass through)
|
|
1814
|
+
newInviteLinkPassword: change.newInviteLinkPassword,
|
|
1815
|
+
// Description
|
|
1816
|
+
newDescription: change.newDescription === undefined
|
|
1817
|
+
? undefined
|
|
1818
|
+
: encryptGroupDescription(secretParams, randomness(), change.newDescription.value),
|
|
1819
|
+
// Announcements (pass through)
|
|
1820
|
+
newIsAnnouncementGroup: change.newIsAnnouncementGroup,
|
|
1821
|
+
// Ban list
|
|
1822
|
+
newBannedMembers: change.newBannedMembers.map((m) => encryptChangeBannedMember(secretParams, m)),
|
|
1823
|
+
deleteBannedMembers: change.deleteBannedMembers.map((m) => encryptChangeBannedMemberRemoval(secretParams, m)),
|
|
1824
|
+
// PNI-ACI promotion
|
|
1825
|
+
promotePendingPniAciMembers: change.promotePendingPniAciMembers.map((m) => encryptChangePniAciPromotion(secretParams, m, presentationFor(m.aciBytes))),
|
|
1826
|
+
// Labels
|
|
1827
|
+
modifyMemberLabels: change.modifyMemberLabels.map((m) => encryptChangeModifyMemberLabel(secretParams, m)),
|
|
1828
|
+
terminate: change.terminate,
|
|
1829
|
+
};
|
|
1830
|
+
}
|
|
1831
|
+
/**
|
|
1832
|
+
* Decrypt all identity fields in an EncryptedGroupChange.
|
|
1833
|
+
*
|
|
1834
|
+
* Reverses the encryption performed by encryptChangeFields().
|
|
1835
|
+
*/
|
|
1836
|
+
function decryptChangeFields(encrypted, secretParams) {
|
|
1837
|
+
if (!encrypted.sourceUserId) {
|
|
1838
|
+
throw new Error('INVALID_CHANGE: Signed Actions are missing server-set sourceUserId');
|
|
1839
|
+
}
|
|
1840
|
+
const change = {
|
|
1841
|
+
editorServiceIdBytes: decryptServiceIdBytes(secretParams, encrypted.sourceUserId),
|
|
1842
|
+
revision: encrypted.revision,
|
|
1843
|
+
// Membership
|
|
1844
|
+
newMembers: encrypted.newMembers.map((m) => decryptChangeAddMember(secretParams, m)),
|
|
1845
|
+
deleteMembers: encrypted.deleteMembers.map((ct) => decryptAci(secretParams, ct)),
|
|
1846
|
+
modifyMemberRoles: encrypted.modifyMemberRoles.map((m) => decryptChangeModifyMemberRole(secretParams, m)),
|
|
1847
|
+
modifiedProfileKeys: encrypted.modifiedProfileKeys.map((m) => decryptProfileKeyActionFields(secretParams, m)),
|
|
1848
|
+
// Pending members
|
|
1849
|
+
newPendingMembers: encrypted.newPendingMembers.map((m) => decryptChangePendingMember(secretParams, m)),
|
|
1850
|
+
deletePendingMembers: encrypted.deletePendingMembers.map((m) => decryptChangePendingMemberRemoval(secretParams, m)),
|
|
1851
|
+
promotePendingMembers: encrypted.promotePendingMembers.map((m) => decryptChangePendingPromotion(secretParams, m)),
|
|
1852
|
+
// Attributes
|
|
1853
|
+
newTitle: encrypted.newTitle === undefined
|
|
1854
|
+
? undefined
|
|
1855
|
+
: { value: decryptGroupTitle(secretParams, encrypted.newTitle) },
|
|
1856
|
+
newAvatar: encrypted.newAvatar,
|
|
1857
|
+
newTimer: encrypted.newTimer === undefined
|
|
1858
|
+
? undefined
|
|
1859
|
+
: decryptDisappearingMessagesTimer(secretParams, encrypted.newTimer),
|
|
1860
|
+
// Access control (pass through)
|
|
1861
|
+
newAttributeAccess: encrypted.newAttributeAccess,
|
|
1862
|
+
newMemberAccess: encrypted.newMemberAccess,
|
|
1863
|
+
newInviteLinkAccess: encrypted.newInviteLinkAccess,
|
|
1864
|
+
newMemberLabelAccess: encrypted.newMemberLabelAccess,
|
|
1865
|
+
// Requesting members
|
|
1866
|
+
newRequestingMembers: encrypted.newRequestingMembers.map((m) => decryptChangeRequestingMember(secretParams, m)),
|
|
1867
|
+
deleteRequestingMembers: encrypted.deleteRequestingMembers.map((ct) => {
|
|
1868
|
+
const serviceIdBytes = decryptQuarantinableServiceId(secretParams, ct, SERVICE_ID_ACI);
|
|
1869
|
+
return serviceIdBytes === undefined
|
|
1870
|
+
? new Uint8Array(ct)
|
|
1871
|
+
: serviceIdBytes.subarray(1);
|
|
1872
|
+
}),
|
|
1873
|
+
promoteRequestingMembers: encrypted.promoteRequestingMembers.map((m) => decryptChangeApproveMember(secretParams, m)),
|
|
1874
|
+
// Invite link (pass through)
|
|
1875
|
+
newInviteLinkPassword: encrypted.newInviteLinkPassword,
|
|
1876
|
+
// Description
|
|
1877
|
+
newDescription: encrypted.newDescription === undefined
|
|
1878
|
+
? undefined
|
|
1879
|
+
: { value: decryptGroupDescription(secretParams, encrypted.newDescription) },
|
|
1880
|
+
// Announcements (pass through)
|
|
1881
|
+
newIsAnnouncementGroup: encrypted.newIsAnnouncementGroup,
|
|
1882
|
+
// Ban list
|
|
1883
|
+
newBannedMembers: encrypted.newBannedMembers.map((m) => decryptChangeBannedMember(secretParams, m)),
|
|
1884
|
+
deleteBannedMembers: encrypted.deleteBannedMembers.map((m) => decryptChangeBannedMemberRemoval(secretParams, m)),
|
|
1885
|
+
// PNI-ACI promotion
|
|
1886
|
+
promotePendingPniAciMembers: encrypted.promotePendingPniAciMembers.map((m) => decryptChangePniAciPromotion(secretParams, m)),
|
|
1887
|
+
// Labels
|
|
1888
|
+
modifyMemberLabels: encrypted.modifyMemberLabels.map((m) => decryptChangeModifyMemberLabel(secretParams, m)),
|
|
1889
|
+
terminate: encrypted.terminate,
|
|
1890
|
+
};
|
|
1891
|
+
const identifierErrors = validateChangeIdentifiers(change);
|
|
1892
|
+
if (identifierErrors.length > 0) {
|
|
1893
|
+
throw new Error(`INVALID_CHANGE: ${identifierErrors.join('; ')}`);
|
|
1894
|
+
}
|
|
1895
|
+
return change;
|
|
1896
|
+
}
|
|
1897
|
+
// ---------------------------------------------------------------------------
|
|
1898
|
+
// Utility helpers
|
|
1899
|
+
// ---------------------------------------------------------------------------
|
|
1900
|
+
/**
|
|
1901
|
+
* Convert a 16-byte ACI UUID to a 17-byte ServiceId binary (ACI kind prefix + UUID).
|
|
1902
|
+
*
|
|
1903
|
+
* Used for `editorServiceIdBytes` in DecryptedGroupChange, which requires
|
|
1904
|
+
* the full ServiceId format for encryption.
|
|
1905
|
+
*/
|
|
1906
|
+
function aciToServiceIdBytes(aciBytes) {
|
|
1907
|
+
if (aciBytes.length !== 16) {
|
|
1908
|
+
throw new Error(`ACI must be 16 bytes, got ${aciBytes.length}`);
|
|
1909
|
+
}
|
|
1910
|
+
const sid = new Uint8Array(17);
|
|
1911
|
+
sid[0] = SERVICE_ID_ACI;
|
|
1912
|
+
sid.set(aciBytes, 1);
|
|
1913
|
+
return sid;
|
|
1914
|
+
}
|
|
1915
|
+
function assertServiceIdBytes(serviceIdBytes) {
|
|
1916
|
+
if (serviceIdBytes.length !== 17) {
|
|
1917
|
+
throw new Error(`ServiceId must be 17 bytes, got ${serviceIdBytes.length}`);
|
|
1918
|
+
}
|
|
1919
|
+
if (serviceIdBytes[0] !== SERVICE_ID_ACI && serviceIdBytes[0] !== SERVICE_ID_PNI) {
|
|
1920
|
+
throw new Error(`Invalid ServiceId kind: ${serviceIdBytes[0]}`);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
//# sourceMappingURL=manager.js.map
|