@open-e2ee/signal-protocol-sdk 7.1.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ADAPTERS.md +55 -6
- package/ARCHITECTURE.md +1 -0
- package/CHANGELOG.md +565 -0
- package/README.md +19 -5
- package/SECURITY.md +2 -2
- package/THIRD_PARTY_NOTICES.md +429 -0
- package/TROUBLESHOOTING.md +10 -0
- package/client/README.md +1 -2
- package/device/README.md +50 -19
- package/dist/client/client.d.ts +31 -5
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +149 -90
- package/dist/client/client.js.map +1 -1
- package/dist/client/event-hooks.d.ts.map +1 -1
- package/dist/client/event-hooks.js +2 -0
- package/dist/client/event-hooks.js.map +1 -1
- package/dist/client/files.d.ts.map +1 -1
- package/dist/client/files.js +19 -2
- package/dist/client/files.js.map +1 -1
- package/dist/client/headless.d.ts +1 -1
- package/dist/client/headless.js +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
- package/dist/client/hosted-anonymous-delivery.js +2 -1
- package/dist/client/hosted-anonymous-delivery.js.map +1 -1
- package/dist/client/hosted-connection.d.ts +1 -1
- package/dist/client/hosted-connection.d.ts.map +1 -1
- package/dist/client/hosted-connection.js +8 -12
- package/dist/client/hosted-connection.js.map +1 -1
- package/dist/client/hosted-group-authority.d.ts.map +1 -1
- package/dist/client/hosted-group-authority.js +2 -1
- package/dist/client/hosted-group-authority.js.map +1 -1
- package/dist/client/hosted-groups.d.ts.map +1 -1
- package/dist/client/hosted-groups.js +2 -1
- package/dist/client/hosted-groups.js.map +1 -1
- package/dist/client/hosted-push.d.ts.map +1 -1
- package/dist/client/hosted-push.js +2 -1
- package/dist/client/hosted-push.js.map +1 -1
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +10 -11
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted-trust.d.ts +11 -11
- package/dist/client/hosted-trust.d.ts.map +1 -1
- package/dist/client/hosted-trust.js +12 -12
- package/dist/client/hosted-trust.js.map +1 -1
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/messages.js +6 -1
- package/dist/client/messages.js.map +1 -1
- package/dist/client/multi-device.d.ts.map +1 -1
- package/dist/client/multi-device.js +2 -1
- package/dist/client/multi-device.js.map +1 -1
- package/dist/client/relay-lifecycle.d.ts +6 -2
- package/dist/client/relay-lifecycle.d.ts.map +1 -1
- package/dist/client/relay-lifecycle.js.map +1 -1
- package/dist/client/relay-work.d.ts +30 -0
- package/dist/client/relay-work.d.ts.map +1 -0
- package/dist/client/relay-work.js +189 -0
- package/dist/client/relay-work.js.map +1 -0
- package/dist/client/retry.d.ts.map +1 -1
- package/dist/client/retry.js +2 -0
- package/dist/client/retry.js.map +1 -1
- package/dist/client/sessions.d.ts.map +1 -1
- package/dist/client/sessions.js +3 -0
- package/dist/client/sessions.js.map +1 -1
- package/dist/client/signal-service-cipher.d.ts +39 -16
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +100 -60
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/state.d.ts +8 -0
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/state.js +11 -0
- package/dist/client/state.js.map +1 -1
- package/dist/client/types.d.ts +5 -1
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/device/connection.d.ts +1 -1
- package/dist/device/connection.d.ts.map +1 -1
- package/dist/device/connection.js +4 -11
- package/dist/device/connection.js.map +1 -1
- package/dist/device/device-id.d.ts +10 -4
- package/dist/device/device-id.d.ts.map +1 -1
- package/dist/device/device-id.js +15 -9
- package/dist/device/device-id.js.map +1 -1
- package/dist/device/device-name-crypto.d.ts.map +1 -1
- package/dist/device/device-name-crypto.js +2 -2
- package/dist/device/device-name-crypto.js.map +1 -1
- package/dist/device/expo/index.d.ts +25 -8
- package/dist/device/expo/index.d.ts.map +1 -1
- package/dist/device/expo/index.js +58 -8
- package/dist/device/expo/index.js.map +1 -1
- package/dist/device/index.d.ts +2 -2
- package/dist/device/index.d.ts.map +1 -1
- package/dist/device/index.js +3 -2
- package/dist/device/index.js.map +1 -1
- package/dist/device/lifecycle/index.d.ts +4 -2
- package/dist/device/lifecycle/index.d.ts.map +1 -1
- package/dist/device/lifecycle/index.js.map +1 -1
- package/dist/device/lifecycle/manager.d.ts +12 -14
- package/dist/device/lifecycle/manager.d.ts.map +1 -1
- package/dist/device/lifecycle/manager.js +52 -97
- package/dist/device/lifecycle/manager.js.map +1 -1
- package/dist/device/lifecycle/types.d.ts +26 -16
- package/dist/device/lifecycle/types.d.ts.map +1 -1
- package/dist/device/lifecycle/utils.d.ts +8 -4
- package/dist/device/lifecycle/utils.d.ts.map +1 -1
- package/dist/device/lifecycle/utils.js +12 -16
- package/dist/device/lifecycle/utils.js.map +1 -1
- package/dist/device/provisioning.d.ts.map +1 -1
- package/dist/device/provisioning.js +6 -8
- package/dist/device/provisioning.js.map +1 -1
- package/dist/device/react-native/index.d.ts +40 -0
- package/dist/device/react-native/index.d.ts.map +1 -0
- package/dist/device/react-native/index.js +74 -0
- package/dist/device/react-native/index.js.map +1 -0
- package/dist/device/transfer.d.ts +15 -7
- package/dist/device/transfer.d.ts.map +1 -1
- package/dist/device/transfer.js +30 -22
- package/dist/device/transfer.js.map +1 -1
- package/dist/device/types.d.ts +15 -7
- package/dist/device/types.d.ts.map +1 -1
- package/dist/device/types.js.map +1 -1
- package/dist/device/vault-text.d.ts +13 -0
- package/dist/device/vault-text.d.ts.map +1 -0
- package/dist/device/vault-text.js +17 -0
- package/dist/device/vault-text.js.map +1 -0
- package/dist/hooks/use-key-rotation.d.ts.map +1 -1
- package/dist/hooks/use-key-rotation.js +2 -1
- package/dist/hooks/use-key-rotation.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/crypto/index.d.ts +3 -3
- package/dist/internal/crypto/index.d.ts.map +1 -1
- package/dist/internal/crypto/index.js +3 -3
- package/dist/internal/crypto/index.js.map +1 -1
- package/dist/internal/crypto/random-host.d.ts +1 -1
- package/dist/internal/crypto/random-host.d.ts.map +1 -1
- package/dist/internal/crypto/random-host.js +3 -2
- package/dist/internal/crypto/random-host.js.map +1 -1
- package/dist/internal/crypto/random-host.native.d.ts +6 -1
- package/dist/internal/crypto/random-host.native.d.ts.map +1 -1
- package/dist/internal/crypto/random-host.native.js +14 -10
- package/dist/internal/crypto/random-host.native.js.map +1 -1
- package/dist/internal/crypto/random-host.node.d.ts +1 -1
- package/dist/internal/crypto/random-host.node.d.ts.map +1 -1
- package/dist/internal/crypto/random-host.node.js +1 -1
- package/dist/internal/crypto/random-host.node.js.map +1 -1
- package/dist/internal/crypto/random.d.ts +12 -3
- package/dist/internal/crypto/random.d.ts.map +1 -1
- package/dist/internal/crypto/random.js +14 -3
- package/dist/internal/crypto/random.js.map +1 -1
- package/dist/internal/crypto/utils.d.ts.map +1 -1
- package/dist/internal/crypto/utils.js +10 -6
- package/dist/internal/crypto/utils.js.map +1 -1
- package/dist/internal/encoding/proto/primitives.d.ts +2 -0
- package/dist/internal/encoding/proto/primitives.d.ts.map +1 -1
- package/dist/internal/encoding/proto/primitives.js +2 -1
- package/dist/internal/encoding/proto/primitives.js.map +1 -1
- package/dist/internal/encoding/proto/signal-message.d.ts +1 -0
- package/dist/internal/encoding/proto/signal-message.d.ts.map +1 -1
- package/dist/internal/encoding/proto/signal-message.js +2 -1
- package/dist/internal/encoding/proto/signal-message.js.map +1 -1
- package/dist/internal/groups/authority-certificate.d.ts.map +1 -1
- package/dist/internal/groups/authority-certificate.js +2 -1
- package/dist/internal/groups/authority-certificate.js.map +1 -1
- package/dist/internal/groups/encrypted-state.d.ts.map +1 -1
- package/dist/internal/groups/encrypted-state.js +9 -7
- package/dist/internal/groups/encrypted-state.js.map +1 -1
- package/dist/internal/groups/invite-link.d.ts.map +1 -1
- package/dist/internal/groups/invite-link.js +2 -1
- package/dist/internal/groups/invite-link.js.map +1 -1
- package/dist/internal/groups/manager.d.ts.map +1 -1
- package/dist/internal/groups/manager.js +5 -5
- package/dist/internal/groups/manager.js.map +1 -1
- package/dist/internal/groups/sdk-store.d.ts.map +1 -1
- package/dist/internal/groups/sdk-store.js +4 -3
- package/dist/internal/groups/sdk-store.js.map +1 -1
- package/dist/internal/groups/server-engine.d.ts +6 -1
- package/dist/internal/groups/server-engine.d.ts.map +1 -1
- package/dist/internal/groups/server-engine.js +11 -15
- package/dist/internal/groups/server-engine.js.map +1 -1
- package/dist/internal/groups/wire.d.ts.map +1 -1
- package/dist/internal/groups/wire.js +2 -1
- package/dist/internal/groups/wire.js.map +1 -1
- package/dist/internal/platform/blob.d.ts +10 -0
- package/dist/internal/platform/blob.d.ts.map +1 -0
- package/dist/internal/platform/blob.js +30 -0
- package/dist/internal/platform/blob.js.map +1 -0
- package/dist/internal/platform/env.d.ts +13 -0
- package/dist/internal/platform/env.d.ts.map +1 -0
- package/dist/internal/platform/env.js +17 -0
- package/dist/internal/platform/env.js.map +1 -0
- package/dist/internal/platform/index.d.ts +5 -0
- package/dist/internal/platform/index.d.ts.map +1 -0
- package/dist/internal/platform/index.js +5 -0
- package/dist/internal/platform/index.js.map +1 -0
- package/dist/internal/platform/url.d.ts +72 -0
- package/dist/internal/platform/url.d.ts.map +1 -0
- package/dist/internal/platform/url.js +275 -0
- package/dist/internal/platform/url.js.map +1 -0
- package/dist/internal/platform/utf8.d.ts +28 -0
- package/dist/internal/platform/utf8.d.ts.map +1 -0
- package/dist/internal/platform/utf8.js +167 -0
- package/dist/internal/platform/utf8.js.map +1 -0
- package/dist/internal/protocol/sealed-sender/delivery-token.d.ts +1 -1
- package/dist/internal/protocol/sealed-sender/delivery-token.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/delivery-token.js +5 -10
- package/dist/internal/protocol/sealed-sender/delivery-token.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.d.ts.map +1 -1
- package/dist/internal/protocol/sealed-sender/proto/index.js +2 -4
- package/dist/internal/protocol/sealed-sender/proto/index.js.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts.map +1 -1
- package/dist/internal/protocol/sender-keys/manager.js +4 -3
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.d.ts +4 -4
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.js +8 -10
- package/dist/internal/protocol/spqr/ml-kem-braid/noble-pq/index.js.map +1 -1
- package/dist/internal/protocol/username/hash.d.ts.map +1 -1
- package/dist/internal/protocol/username/hash.js +18 -3
- package/dist/internal/protocol/username/hash.js.map +1 -1
- package/dist/internal/protocol/username/link.d.ts.map +1 -1
- package/dist/internal/protocol/username/link.js +2 -1
- package/dist/internal/protocol/username/link.js.map +1 -1
- package/dist/internal/protocol/username/proof.d.ts.map +1 -1
- package/dist/internal/protocol/username/proof.js +2 -1
- package/dist/internal/protocol/username/proof.js.map +1 -1
- package/dist/internal/sesame/device-registry.d.ts +22 -6
- package/dist/internal/sesame/device-registry.d.ts.map +1 -1
- package/dist/internal/sesame/device-registry.js +18 -12
- package/dist/internal/sesame/device-registry.js.map +1 -1
- package/dist/internal/sesame/index.d.ts +1 -1
- package/dist/internal/sesame/index.d.ts.map +1 -1
- package/dist/internal/sesame/manager.d.ts.map +1 -1
- package/dist/internal/sesame/manager.js +3 -2
- package/dist/internal/sesame/manager.js.map +1 -1
- package/dist/internal/session/index.d.ts +1 -2
- package/dist/internal/session/index.d.ts.map +1 -1
- package/dist/internal/session/index.js +1 -1
- package/dist/internal/session/index.js.map +1 -1
- package/dist/internal/session/validation.d.ts +0 -80
- package/dist/internal/session/validation.d.ts.map +1 -1
- package/dist/internal/session/validation.js +0 -134
- package/dist/internal/session/validation.js.map +1 -1
- package/dist/local/store/device-record.d.ts +18 -0
- package/dist/local/store/device-record.d.ts.map +1 -0
- package/dist/local/store/device-record.js +34 -0
- package/dist/local/store/device-record.js.map +1 -0
- package/dist/local/store/expo/adapter.d.ts +59 -238
- package/dist/local/store/expo/adapter.d.ts.map +1 -1
- package/dist/local/store/expo/adapter.js +83 -640
- package/dist/local/store/expo/adapter.js.map +1 -1
- package/dist/local/store/expo/driver.d.ts +16 -0
- package/dist/local/store/expo/driver.d.ts.map +1 -0
- package/dist/local/store/expo/driver.js +141 -0
- package/dist/local/store/expo/driver.js.map +1 -0
- package/dist/local/store/expo/index.d.ts +3 -12
- package/dist/local/store/expo/index.d.ts.map +1 -1
- package/dist/local/store/expo/index.js +1 -8
- package/dist/local/store/expo/index.js.map +1 -1
- package/dist/local/store/expo/maintenance.d.ts +3 -2
- package/dist/local/store/expo/maintenance.d.ts.map +1 -1
- package/dist/local/store/expo/maintenance.js +5 -34
- package/dist/local/store/expo/maintenance.js.map +1 -1
- package/dist/local/store/index.d.ts +10 -5
- package/dist/local/store/index.d.ts.map +1 -1
- package/dist/local/store/index.js +10 -5
- package/dist/local/store/index.js.map +1 -1
- package/dist/local/store/key-value/adapter.d.ts +326 -0
- package/dist/local/store/key-value/adapter.d.ts.map +1 -0
- package/dist/local/store/key-value/adapter.js +1472 -0
- package/dist/local/store/key-value/adapter.js.map +1 -0
- package/dist/local/store/{react-native → key-value}/backend-conformance.d.ts +7 -8
- package/dist/local/store/key-value/backend-conformance.d.ts.map +1 -0
- package/dist/local/store/{react-native → key-value}/backend-conformance.js +4 -5
- package/dist/local/store/key-value/backend-conformance.js.map +1 -0
- package/dist/local/store/key-value/batch.d.ts +41 -0
- package/dist/local/store/key-value/batch.d.ts.map +1 -0
- package/dist/local/store/key-value/batch.js +77 -0
- package/dist/local/store/key-value/batch.js.map +1 -0
- package/dist/local/store/key-value/device-record.d.ts +23 -0
- package/dist/local/store/key-value/device-record.d.ts.map +1 -0
- package/dist/local/store/key-value/device-record.js +33 -0
- package/dist/local/store/key-value/device-record.js.map +1 -0
- package/dist/local/store/key-value/index.d.ts +24 -0
- package/dist/local/store/key-value/index.d.ts.map +1 -0
- package/dist/local/store/key-value/index.js +8 -0
- package/dist/local/store/key-value/index.js.map +1 -0
- package/dist/local/store/key-value/realm/index.d.ts +83 -0
- package/dist/local/store/key-value/realm/index.d.ts.map +1 -0
- package/dist/local/store/key-value/realm/index.js +102 -0
- package/dist/local/store/key-value/realm/index.js.map +1 -0
- package/dist/local/store/{react-native → key-value}/storage.d.ts +6 -6
- package/dist/local/store/key-value/storage.d.ts.map +1 -0
- package/dist/local/store/key-value/storage.js.map +1 -0
- package/dist/local/store/key-value/transactional-backend.d.ts +50 -0
- package/dist/local/store/key-value/transactional-backend.d.ts.map +1 -0
- package/dist/local/store/key-value/transactional-backend.js +90 -0
- package/dist/local/store/key-value/transactional-backend.js.map +1 -0
- package/dist/local/store/key-value/value-key.d.ts +34 -0
- package/dist/local/store/key-value/value-key.d.ts.map +1 -0
- package/dist/local/store/key-value/value-key.js +83 -0
- package/dist/local/store/key-value/value-key.js.map +1 -0
- package/dist/local/store/memory/adapter.d.ts +8 -0
- package/dist/local/store/memory/adapter.d.ts.map +1 -1
- package/dist/local/store/memory/adapter.js +60 -75
- package/dist/local/store/memory/adapter.js.map +1 -1
- package/dist/local/store/node/adapter.d.ts +74 -130
- package/dist/local/store/node/adapter.d.ts.map +1 -1
- package/dist/local/store/node/adapter.js +83 -727
- package/dist/local/store/node/adapter.js.map +1 -1
- package/dist/local/store/node/index.d.ts +8 -6
- package/dist/local/store/node/index.d.ts.map +1 -1
- package/dist/local/store/node/index.js +3 -7
- package/dist/local/store/node/index.js.map +1 -1
- package/dist/local/store/node/maintenance.d.ts +5 -0
- package/dist/local/store/node/maintenance.d.ts.map +1 -0
- package/dist/local/store/node/maintenance.js +7 -0
- package/dist/local/store/node/maintenance.js.map +1 -0
- package/dist/local/store/node/owner-lock.d.ts +26 -0
- package/dist/local/store/node/owner-lock.d.ts.map +1 -0
- package/dist/local/store/node/owner-lock.js +88 -0
- package/dist/local/store/node/owner-lock.js.map +1 -0
- package/dist/local/store/react-native/adapter.d.ts +63 -273
- package/dist/local/store/react-native/adapter.d.ts.map +1 -1
- package/dist/local/store/react-native/adapter.js +80 -1405
- package/dist/local/store/react-native/adapter.js.map +1 -1
- package/dist/local/store/react-native/index.d.ts +7 -19
- package/dist/local/store/react-native/index.d.ts.map +1 -1
- package/dist/local/store/react-native/index.js +2 -7
- package/dist/local/store/react-native/index.js.map +1 -1
- package/dist/local/store/react-native/maintenance.d.ts +5 -0
- package/dist/local/store/react-native/maintenance.d.ts.map +1 -0
- package/dist/local/store/react-native/maintenance.js +7 -0
- package/dist/local/store/react-native/maintenance.js.map +1 -0
- package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.d.ts +38 -0
- package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.d.ts.map +1 -0
- package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.js +196 -0
- package/dist/local/store/sqlite/better-sqlite3-multiple-ciphers-driver.js.map +1 -0
- package/dist/local/store/sqlite/database.d.ts +20 -0
- package/dist/local/store/sqlite/database.d.ts.map +1 -0
- package/dist/local/store/sqlite/database.js +41 -0
- package/dist/local/store/sqlite/database.js.map +1 -0
- package/dist/local/store/sqlite/driver.d.ts +138 -0
- package/dist/local/store/sqlite/driver.d.ts.map +1 -0
- package/dist/local/store/sqlite/driver.js +10 -0
- package/dist/local/store/sqlite/driver.js.map +1 -0
- package/dist/local/store/sqlite/encryption.d.ts +61 -0
- package/dist/local/store/sqlite/encryption.d.ts.map +1 -0
- package/dist/local/store/sqlite/encryption.js +98 -0
- package/dist/local/store/sqlite/encryption.js.map +1 -0
- package/dist/local/store/sqlite/errors.d.ts +70 -0
- package/dist/local/store/sqlite/errors.d.ts.map +1 -0
- package/dist/local/store/sqlite/errors.js +101 -0
- package/dist/local/store/sqlite/errors.js.map +1 -0
- package/dist/local/store/sqlite/executor.d.ts +22 -0
- package/dist/local/store/sqlite/executor.d.ts.map +1 -0
- package/dist/local/store/sqlite/executor.js +129 -0
- package/dist/local/store/sqlite/executor.js.map +1 -0
- package/dist/local/store/sqlite/index.d.ts +20 -0
- package/dist/local/store/sqlite/index.d.ts.map +1 -0
- package/dist/local/store/sqlite/index.js +18 -0
- package/dist/local/store/sqlite/index.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/account.d.ts +45 -0
- package/dist/local/store/sqlite/key-storage/account.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/account.js +125 -0
- package/dist/local/store/sqlite/key-storage/account.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/contact-identities.d.ts +19 -0
- package/dist/local/store/sqlite/key-storage/contact-identities.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/contact-identities.js +85 -0
- package/dist/local/store/sqlite/key-storage/contact-identities.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/context.d.ts +19 -0
- package/dist/local/store/sqlite/key-storage/context.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/context.js +18 -0
- package/dist/local/store/sqlite/key-storage/context.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/identity-keys.d.ts +18 -0
- package/dist/local/store/sqlite/key-storage/identity-keys.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/identity-keys.js +88 -0
- package/dist/local/store/sqlite/key-storage/identity-keys.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/index.d.ts +108 -0
- package/dist/local/store/sqlite/key-storage/index.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/index.js +241 -0
- package/dist/local/store/sqlite/key-storage/index.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/message-records.d.ts +41 -0
- package/dist/local/store/sqlite/key-storage/message-records.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/message-records.js +133 -0
- package/dist/local/store/sqlite/key-storage/message-records.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/metadata.d.ts +16 -0
- package/dist/local/store/sqlite/key-storage/metadata.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/metadata.js +53 -0
- package/dist/local/store/sqlite/key-storage/metadata.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/one-time-prekeys.d.ts +36 -0
- package/dist/local/store/sqlite/key-storage/one-time-prekeys.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/one-time-prekeys.js +129 -0
- package/dist/local/store/sqlite/key-storage/one-time-prekeys.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/session-trust.d.ts +10 -0
- package/dist/local/store/sqlite/key-storage/session-trust.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/session-trust.js +88 -0
- package/dist/local/store/sqlite/key-storage/session-trust.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/sessions.d.ts +50 -0
- package/dist/local/store/sqlite/key-storage/sessions.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/sessions.js +209 -0
- package/dist/local/store/sqlite/key-storage/sessions.js.map +1 -0
- package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts +69 -0
- package/dist/local/store/sqlite/key-storage/signed-prekeys.d.ts.map +1 -0
- package/dist/local/store/sqlite/key-storage/signed-prekeys.js +219 -0
- package/dist/local/store/sqlite/key-storage/signed-prekeys.js.map +1 -0
- package/dist/local/store/sqlite/maintenance.d.ts +7 -0
- package/dist/local/store/sqlite/maintenance.d.ts.map +1 -0
- package/dist/local/store/sqlite/maintenance.js +32 -0
- package/dist/local/store/sqlite/maintenance.js.map +1 -0
- package/dist/local/store/sqlite/migrations.d.ts +31 -0
- package/dist/local/store/sqlite/migrations.d.ts.map +1 -0
- package/dist/local/store/sqlite/migrations.js +232 -0
- package/dist/local/store/sqlite/migrations.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/ec-one-time-prekey.d.ts +17 -22
- package/dist/local/store/sqlite/models/ec-one-time-prekey.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/ec-one-time-prekey.js +61 -99
- package/dist/local/store/sqlite/models/ec-one-time-prekey.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/ec-signed-prekey.d.ts +22 -25
- package/dist/local/store/sqlite/models/ec-signed-prekey.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/ec-signed-prekey.js +82 -128
- package/dist/local/store/sqlite/models/ec-signed-prekey.js.map +1 -0
- package/dist/local/store/sqlite/models/identity-key-id.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/identity-key-id.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/index.d.ts +5 -5
- package/dist/local/store/sqlite/models/index.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/index.js +12 -5
- package/dist/local/store/sqlite/models/index.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/kyber-one-time-prekey.d.ts +17 -20
- package/dist/local/store/sqlite/models/kyber-one-time-prekey.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/kyber-one-time-prekey.js +65 -105
- package/dist/local/store/sqlite/models/kyber-one-time-prekey.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/kyber-prekey-used.d.ts +3 -3
- package/dist/local/store/sqlite/models/kyber-prekey-used.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/kyber-prekey-used.js +13 -25
- package/dist/local/store/sqlite/models/kyber-prekey-used.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/kyber-prekey.d.ts +16 -19
- package/dist/local/store/sqlite/models/kyber-prekey.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/kyber-prekey.js +67 -111
- package/dist/local/store/sqlite/models/kyber-prekey.js.map +1 -0
- package/dist/local/store/sqlite/models/local-identity.d.ts +51 -0
- package/dist/local/store/sqlite/models/local-identity.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/local-identity.js +150 -0
- package/dist/local/store/sqlite/models/local-identity.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/message-record.d.ts +15 -44
- package/dist/local/store/sqlite/models/message-record.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/message-record.js +43 -109
- package/dist/local/store/sqlite/models/message-record.js.map +1 -0
- package/dist/local/store/sqlite/models/recipient-identity.d.ts +21 -0
- package/dist/local/store/sqlite/models/recipient-identity.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/recipient-identity.js +59 -0
- package/dist/local/store/sqlite/models/recipient-identity.js.map +1 -0
- package/dist/local/store/sqlite/models/replaced-prekeys.d.ts +23 -0
- package/dist/local/store/sqlite/models/replaced-prekeys.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/replaced-prekeys.js +42 -0
- package/dist/local/store/sqlite/models/replaced-prekeys.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/sender-key.d.ts +22 -23
- package/dist/local/store/sqlite/models/sender-key.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/sender-key.js +66 -94
- package/dist/local/store/sqlite/models/sender-key.js.map +1 -0
- package/dist/local/store/sqlite/models/sesame-user-record.d.ts +32 -0
- package/dist/local/store/sqlite/models/sesame-user-record.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/sesame-user-record.js +78 -0
- package/dist/local/store/sqlite/models/sesame-user-record.js.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/session.d.ts +24 -20
- package/dist/local/store/sqlite/models/session.d.ts.map +1 -0
- package/dist/local/store/{expo → sqlite}/models/session.js +54 -72
- package/dist/local/store/sqlite/models/session.js.map +1 -0
- package/dist/local/store/sqlite/models/skipped-sender-key.d.ts +24 -0
- package/dist/local/store/sqlite/models/skipped-sender-key.d.ts.map +1 -0
- package/dist/local/store/sqlite/models/skipped-sender-key.js +62 -0
- package/dist/local/store/sqlite/models/skipped-sender-key.js.map +1 -0
- package/dist/local/store/sqlite/op-sqlite-driver.d.ts +14 -0
- package/dist/local/store/sqlite/op-sqlite-driver.d.ts.map +1 -0
- package/dist/local/store/sqlite/op-sqlite-driver.js +180 -0
- package/dist/local/store/sqlite/op-sqlite-driver.js.map +1 -0
- package/dist/local/store/sqlite/open-store.d.ts +83 -0
- package/dist/local/store/sqlite/open-store.d.ts.map +1 -0
- package/dist/local/store/sqlite/open-store.js +177 -0
- package/dist/local/store/sqlite/open-store.js.map +1 -0
- package/dist/local/store/sqlite/schema.d.ts +102 -0
- package/dist/local/store/sqlite/schema.d.ts.map +1 -0
- package/dist/local/store/sqlite/schema.js +61 -0
- package/dist/local/store/sqlite/schema.js.map +1 -0
- package/dist/local/store/sqlite/store.d.ts +199 -0
- package/dist/local/store/sqlite/store.d.ts.map +1 -0
- package/dist/local/store/sqlite/store.js +494 -0
- package/dist/local/store/sqlite/store.js.map +1 -0
- package/dist/local/store/sqlite/web/driver.d.ts +50 -0
- package/dist/local/store/sqlite/web/driver.d.ts.map +1 -0
- package/dist/local/store/sqlite/web/driver.js +169 -0
- package/dist/local/store/sqlite/web/driver.js.map +1 -0
- package/dist/local/store/sqlite/web/protocol.d.ts +80 -0
- package/dist/local/store/sqlite/web/protocol.d.ts.map +1 -0
- package/dist/local/store/sqlite/web/protocol.js +13 -0
- package/dist/local/store/sqlite/web/protocol.js.map +1 -0
- package/dist/local/store/sqlite/web/sqlite3mc/sqlite3.mjs +14526 -0
- package/dist/local/store/sqlite/web/sqlite3mc/sqlite3.wasm +0 -0
- package/dist/local/store/sqlite/web/worker.d.ts +36 -0
- package/dist/local/store/sqlite/web/worker.d.ts.map +1 -0
- package/dist/local/store/sqlite/web/worker.js +616 -0
- package/dist/local/store/sqlite/web/worker.js.map +1 -0
- package/dist/local/store/web/adapter.d.ts +5 -14
- package/dist/local/store/web/adapter.d.ts.map +1 -1
- package/dist/local/store/web/adapter.js +119 -106
- package/dist/local/store/web/adapter.js.map +1 -1
- package/dist/local/store/web/device-record.d.ts +23 -0
- package/dist/local/store/web/device-record.d.ts.map +1 -0
- package/dist/local/store/web/device-record.js +31 -0
- package/dist/local/store/web/device-record.js.map +1 -0
- package/dist/local/store/web-sqlite/adapter.d.ts +98 -0
- package/dist/local/store/web-sqlite/adapter.d.ts.map +1 -0
- package/dist/local/store/web-sqlite/adapter.js +151 -0
- package/dist/local/store/web-sqlite/adapter.js.map +1 -0
- package/dist/local/store/web-sqlite/index.d.ts +14 -0
- package/dist/local/store/web-sqlite/index.d.ts.map +1 -0
- package/dist/local/store/web-sqlite/index.js +3 -0
- package/dist/local/store/web-sqlite/index.js.map +1 -0
- package/dist/local/store/web-sqlite/maintenance.d.ts +5 -0
- package/dist/local/store/web-sqlite/maintenance.d.ts.map +1 -0
- package/dist/local/store/web-sqlite/maintenance.js +7 -0
- package/dist/local/store/web-sqlite/maintenance.js.map +1 -0
- package/dist/local/store/web-sqlite/store-locks.d.ts +33 -0
- package/dist/local/store/web-sqlite/store-locks.d.ts.map +1 -0
- package/dist/local/store/web-sqlite/store-locks.js +60 -0
- package/dist/local/store/web-sqlite/store-locks.js.map +1 -0
- package/dist/local/vault/electron-safe-storage.d.ts +45 -0
- package/dist/local/vault/electron-safe-storage.d.ts.map +1 -0
- package/dist/local/vault/electron-safe-storage.js +212 -0
- package/dist/local/vault/electron-safe-storage.js.map +1 -0
- package/dist/local/vault/index.d.ts +4 -2
- package/dist/local/vault/index.d.ts.map +1 -1
- package/dist/local/vault/indexed-db.d.ts +37 -0
- package/dist/local/vault/indexed-db.d.ts.map +1 -0
- package/dist/local/vault/indexed-db.js +102 -0
- package/dist/local/vault/indexed-db.js.map +1 -0
- package/dist/local/vault/react-native-keychain.d.ts +12 -0
- package/dist/local/vault/react-native-keychain.d.ts.map +1 -0
- package/dist/local/vault/react-native-keychain.js +71 -0
- package/dist/local/vault/react-native-keychain.js.map +1 -0
- package/dist/local/vault/require.d.ts +10 -0
- package/dist/local/vault/require.d.ts.map +1 -0
- package/dist/local/vault/require.js +16 -0
- package/dist/local/vault/require.js.map +1 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +2 -1
- package/dist/logger.js.map +1 -1
- package/dist/media/index.d.ts.map +1 -1
- package/dist/media/index.js +2 -1
- package/dist/media/index.js.map +1 -1
- package/dist/profile/contact-state.d.ts.map +1 -1
- package/dist/profile/contact-state.js +2 -4
- package/dist/profile/contact-state.js.map +1 -1
- package/dist/profile/index.d.ts +0 -1
- package/dist/profile/index.d.ts.map +1 -1
- package/dist/profile/index.js +0 -2
- package/dist/profile/index.js.map +1 -1
- package/dist/profile/profile-key.d.ts +16 -11
- package/dist/profile/profile-key.d.ts.map +1 -1
- package/dist/profile/profile-key.js +29 -29
- package/dist/profile/profile-key.js.map +1 -1
- package/dist/profile/update-service.d.ts +6 -0
- package/dist/profile/update-service.d.ts.map +1 -1
- package/dist/profile/update-service.js +3 -1
- package/dist/profile/update-service.js.map +1 -1
- package/dist/remote/object-store/validation.d.ts.map +1 -1
- package/dist/remote/object-store/validation.js +2 -1
- package/dist/remote/object-store/validation.js.map +1 -1
- package/dist/remote/relay/memory/adapter.d.ts +2 -3
- package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
- package/dist/remote/relay/memory/adapter.js +22 -30
- package/dist/remote/relay/memory/adapter.js.map +1 -1
- package/dist/remote/relay/memory/failures.d.ts.map +1 -1
- package/dist/remote/relay/memory/failures.js +2 -1
- package/dist/remote/relay/memory/failures.js.map +1 -1
- package/dist/remote/relay/memory/group-server.d.ts +5 -1
- package/dist/remote/relay/memory/group-server.d.ts.map +1 -1
- package/dist/remote/relay/memory/group-server.js +11 -1
- package/dist/remote/relay/memory/group-server.js.map +1 -1
- package/dist/safety/url.d.ts.map +1 -1
- package/dist/safety/url.js +21 -26
- package/dist/safety/url.js.map +1 -1
- package/dist/types/api.d.ts +15 -2
- package/dist/types/api.d.ts.map +1 -1
- package/dist/types/errors.d.ts +97 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +105 -1
- package/dist/types/errors.js.map +1 -1
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/session.js +2 -1
- package/dist/types/session.js.map +1 -1
- package/dist/utils/retry.d.ts +2 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +4 -2
- package/dist/utils/retry.js.map +1 -1
- package/docs/ASSURANCE.md +81 -8
- package/docs/CLIENT_COMPOSITION.md +1 -2
- package/docs/DEVIATIONS.md +27 -3
- package/docs/ERROR_HANDLING.md +6 -0
- package/docs/GETTING_STARTED.md +1 -2
- package/docs/PACKAGE_SURFACE.md +29 -11
- package/docs/RECIPES.md +1 -2
- package/examples/browser/index.html +1 -1
- package/local/store/README.md +117 -34
- package/local/store/expo/README.md +67 -47
- package/local/store/key-value/README.md +278 -0
- package/local/store/node/README.md +206 -45
- package/local/store/react-native/README.md +121 -52
- package/local/store/web/README.md +9 -0
- package/local/store/web-sqlite/README.md +202 -0
- package/local/vault/README.md +115 -2
- package/package.json +61 -42
- package/profile/README.md +9 -11
- package/remote/README.md +1 -2
- package/dist/local/store/expo/database-key.d.ts +0 -142
- package/dist/local/store/expo/database-key.d.ts.map +0 -1
- package/dist/local/store/expo/database-key.js +0 -312
- package/dist/local/store/expo/database-key.js.map +0 -1
- package/dist/local/store/expo/db.d.ts +0 -95
- package/dist/local/store/expo/db.d.ts.map +0 -1
- package/dist/local/store/expo/db.js +0 -147
- package/dist/local/store/expo/db.js.map +0 -1
- package/dist/local/store/expo/key-storage.d.ts +0 -429
- package/dist/local/store/expo/key-storage.d.ts.map +0 -1
- package/dist/local/store/expo/key-storage.js +0 -1361
- package/dist/local/store/expo/key-storage.js.map +0 -1
- package/dist/local/store/expo/models/ec-one-time-prekey.d.ts.map +0 -1
- package/dist/local/store/expo/models/ec-one-time-prekey.js.map +0 -1
- package/dist/local/store/expo/models/ec-signed-prekey.d.ts.map +0 -1
- package/dist/local/store/expo/models/ec-signed-prekey.js.map +0 -1
- package/dist/local/store/expo/models/identity-key-id.d.ts.map +0 -1
- package/dist/local/store/expo/models/identity-key-id.js.map +0 -1
- package/dist/local/store/expo/models/index.d.ts.map +0 -1
- package/dist/local/store/expo/models/index.js.map +0 -1
- package/dist/local/store/expo/models/kyber-one-time-prekey.d.ts.map +0 -1
- package/dist/local/store/expo/models/kyber-one-time-prekey.js.map +0 -1
- package/dist/local/store/expo/models/kyber-prekey-used.d.ts.map +0 -1
- package/dist/local/store/expo/models/kyber-prekey-used.js.map +0 -1
- package/dist/local/store/expo/models/kyber-prekey.d.ts.map +0 -1
- package/dist/local/store/expo/models/kyber-prekey.js.map +0 -1
- package/dist/local/store/expo/models/local-identity.d.ts +0 -52
- package/dist/local/store/expo/models/local-identity.d.ts.map +0 -1
- package/dist/local/store/expo/models/local-identity.js +0 -166
- package/dist/local/store/expo/models/local-identity.js.map +0 -1
- package/dist/local/store/expo/models/message-record.d.ts.map +0 -1
- package/dist/local/store/expo/models/message-record.js.map +0 -1
- package/dist/local/store/expo/models/recipient-identity.d.ts +0 -21
- package/dist/local/store/expo/models/recipient-identity.d.ts.map +0 -1
- package/dist/local/store/expo/models/recipient-identity.js +0 -66
- package/dist/local/store/expo/models/recipient-identity.js.map +0 -1
- package/dist/local/store/expo/models/replaced-prekey-utils.d.ts +0 -33
- package/dist/local/store/expo/models/replaced-prekey-utils.d.ts.map +0 -1
- package/dist/local/store/expo/models/replaced-prekey-utils.js +0 -54
- package/dist/local/store/expo/models/replaced-prekey-utils.js.map +0 -1
- package/dist/local/store/expo/models/sender-key.d.ts.map +0 -1
- package/dist/local/store/expo/models/sender-key.js.map +0 -1
- package/dist/local/store/expo/models/session.d.ts.map +0 -1
- package/dist/local/store/expo/models/session.js.map +0 -1
- package/dist/local/store/expo/schema.d.ts +0 -1917
- package/dist/local/store/expo/schema.d.ts.map +0 -1
- package/dist/local/store/expo/schema.js +0 -197
- package/dist/local/store/expo/schema.js.map +0 -1
- package/dist/local/store/node/database-encryption.d.ts +0 -109
- package/dist/local/store/node/database-encryption.d.ts.map +0 -1
- package/dist/local/store/node/database-encryption.js +0 -202
- package/dist/local/store/node/database-encryption.js.map +0 -1
- package/dist/local/store/node/database-file-commit.d.ts +0 -8
- package/dist/local/store/node/database-file-commit.d.ts.map +0 -1
- package/dist/local/store/node/database-file-commit.js +0 -62
- package/dist/local/store/node/database-file-commit.js.map +0 -1
- package/dist/local/store/node/database-key.d.ts +0 -129
- package/dist/local/store/node/database-key.d.ts.map +0 -1
- package/dist/local/store/node/database-key.js +0 -293
- package/dist/local/store/node/database-key.js.map +0 -1
- package/dist/local/store/node/database-lock.d.ts +0 -8
- package/dist/local/store/node/database-lock.d.ts.map +0 -1
- package/dist/local/store/node/database-lock.js +0 -44
- package/dist/local/store/node/database-lock.js.map +0 -1
- package/dist/local/store/node/database.d.ts +0 -226
- package/dist/local/store/node/database.d.ts.map +0 -1
- package/dist/local/store/node/database.js +0 -813
- package/dist/local/store/node/database.js.map +0 -1
- package/dist/local/store/react-native/backend-conformance.d.ts.map +0 -1
- package/dist/local/store/react-native/backend-conformance.js.map +0 -1
- package/dist/local/store/react-native/reference-backend.d.ts +0 -43
- package/dist/local/store/react-native/reference-backend.d.ts.map +0 -1
- package/dist/local/store/react-native/reference-backend.js +0 -178
- package/dist/local/store/react-native/reference-backend.js.map +0 -1
- package/dist/local/store/react-native/storage.d.ts.map +0 -1
- package/dist/local/store/react-native/storage.js.map +0 -1
- package/dist/profile/storage.d.ts +0 -61
- package/dist/profile/storage.d.ts.map +0 -1
- package/dist/profile/storage.js +0 -145
- package/dist/profile/storage.js.map +0 -1
- /package/dist/local/store/{react-native → key-value}/storage.js +0 -0
- /package/dist/local/store/{expo → sqlite}/models/identity-key-id.d.ts +0 -0
- /package/dist/local/store/{expo → sqlite}/models/identity-key-id.js +0 -0
|
@@ -1,743 +1,99 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Node
|
|
2
|
+
* Node and Electron Signal Protocol Store
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - node:crypto for encryption
|
|
8
|
-
* - Secure file permissions (0600)
|
|
9
|
-
*
|
|
10
|
-
* @example Usage
|
|
11
|
-
* ```typescript
|
|
12
|
-
* const storage = new NodeSignalProtocolStore({
|
|
13
|
-
* dataDir: '~/.signal-protocol/signal'
|
|
14
|
-
* });
|
|
15
|
-
* await storage.initialize();
|
|
16
|
-
*
|
|
17
|
-
* // Store identity key
|
|
18
|
-
* await storage.storeIdentityKey(keyPair);
|
|
19
|
-
* ```
|
|
4
|
+
* The SDK owns the database file. One call opens it in a directory that the
|
|
5
|
+
* app chooses, gets or creates its key through the app's secret vault, applies
|
|
6
|
+
* the SDK migrations, and returns the store.
|
|
20
7
|
*/
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function deserializeDeviceRecord(data) {
|
|
38
|
-
return {
|
|
39
|
-
...data,
|
|
40
|
-
identityKey: Uint8Array.from(data.identityKey),
|
|
41
|
-
session: data.session ? deserializeSessionRecord(data.session) : null,
|
|
42
|
-
};
|
|
8
|
+
import { createBetterSqlite3MultipleCiphersDriver } from '../sqlite/better-sqlite3-multiple-ciphers-driver.js';
|
|
9
|
+
import { openSqliteStore, resetSqliteStore, } from '../sqlite/open-store.js';
|
|
10
|
+
import { SqliteSignalProtocolStore } from '../sqlite/store.js';
|
|
11
|
+
import { withOwnerLock } from './owner-lock.js';
|
|
12
|
+
/** The database file name when the options name none. */
|
|
13
|
+
const DEFAULT_DATABASE_NAME = 'open-e2ee-signal-protocol.db';
|
|
14
|
+
/** The database of each open store, for the helpers of this entry. */
|
|
15
|
+
const databases = new WeakMap();
|
|
16
|
+
/** The executor of an open store. Not exported from the entry. */
|
|
17
|
+
export function nodeStoreDatabase(store) {
|
|
18
|
+
const database = databases.get(store);
|
|
19
|
+
if (!database)
|
|
20
|
+
throw new TypeError('Open the store with nodeStore().');
|
|
21
|
+
return database;
|
|
43
22
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
serializeDeviceRecord(device),
|
|
50
|
-
]),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
function deserializeUserRecord(data) {
|
|
54
|
-
return {
|
|
55
|
-
...data,
|
|
56
|
-
devices: new Map(data.devices.map(([deviceId, device]) => [deviceId, deserializeDeviceRecord(device)])),
|
|
57
|
-
};
|
|
23
|
+
/** Run `run` on the core options of the store, with the owner lock. */
|
|
24
|
+
async function withStoreOptions(options, operation, run) {
|
|
25
|
+
const driver = createBetterSqlite3MultipleCiphersDriver({ directory: options.directory });
|
|
26
|
+
const storeOptions = { ...options, driver, name: options.name ?? DEFAULT_DATABASE_NAME };
|
|
27
|
+
return withOwnerLock(driver, storeOptions.name, operation, () => run(storeOptions));
|
|
58
28
|
}
|
|
59
29
|
/**
|
|
60
|
-
*
|
|
30
|
+
* Local Signal Protocol state for Node and the Electron main process, in an
|
|
31
|
+
* SDK-owned SQLCipher database.
|
|
32
|
+
*
|
|
33
|
+
* Open it with {@link nodeStore}. The store holds the database file until
|
|
34
|
+
* {@link NodeSignalProtocolStore.close}. A second open of the same file in
|
|
35
|
+
* the process fails with `INVALID_STATE`, and an open in another process
|
|
36
|
+
* fails with `SqliteStoreInUseError`.
|
|
37
|
+
*
|
|
38
|
+
* Every table holds material that must not leave the device, including the
|
|
39
|
+
* group sender keys. SQLCipher encrypts the whole file, so the database key
|
|
40
|
+
* in the vault is the only thing that protects it.
|
|
61
41
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* abort the whole pass, leaving a store that can never expire anything again.
|
|
42
|
+
* @category Key Storage
|
|
43
|
+
* @see {@link SignalProtocolLocalStore} for interface documentation
|
|
65
44
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
export class NodeSignalProtocolStore extends SqliteSignalProtocolStore {
|
|
46
|
+
constructor(database, logger) {
|
|
47
|
+
super(database, { logger });
|
|
48
|
+
databases.set(this, database);
|
|
49
|
+
}
|
|
50
|
+
/** @internal Use {@link nodeStore}. */
|
|
51
|
+
static async open(options) {
|
|
52
|
+
const database = await withStoreOptions(options, 'open', openSqliteStore);
|
|
53
|
+
return new NodeSignalProtocolStore(database, options.logger);
|
|
54
|
+
}
|
|
55
|
+
/** @internal Use {@link resetNodeStore}. */
|
|
56
|
+
static async reset(options) {
|
|
57
|
+
const database = await withStoreOptions(options, 'reset', resetSqliteStore);
|
|
58
|
+
return new NodeSignalProtocolStore(database, options.logger);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wait for the queued work, then close the database and release the file.
|
|
62
|
+
* Every later call rejects with `SqliteStoreClosedError`.
|
|
63
|
+
*/
|
|
64
|
+
close() {
|
|
65
|
+
return nodeStoreDatabase(this).close();
|
|
71
66
|
}
|
|
72
|
-
catch {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/** Read a nested dictionary level, creating it on demand for writes. */
|
|
77
|
-
function branch(parent, key, create) {
|
|
78
|
-
const existing = parent[key];
|
|
79
|
-
if (existing !== undefined)
|
|
80
|
-
return existing;
|
|
81
|
-
const created = create();
|
|
82
|
-
parent[key] = created;
|
|
83
|
-
return created;
|
|
84
|
-
}
|
|
85
|
-
/** Same, for a level whose value is itself a dictionary. */
|
|
86
|
-
function subtree(parent, key) {
|
|
87
|
-
return branch(parent, key, () => Object.create(null));
|
|
88
67
|
}
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Open the store. On first use it creates the database key in the vault, then
|
|
70
|
+
* the database file. With `encryptionAtRest: false` it does not use the vault.
|
|
71
|
+
*
|
|
72
|
+
* @throws SqliteStoreInUseError when a store in another process holds the
|
|
73
|
+
* file. The open reads no vault entry and does not touch the file.
|
|
74
|
+
* @throws EncryptionError with `LOCAL_STORE_KEY_LOST` when the database file
|
|
75
|
+
* exists and the vault holds no key for it, also after the directory moved.
|
|
76
|
+
* Move the vault entry, restore it, or call {@link resetNodeStore}.
|
|
77
|
+
* @throws EncryptionError with `KEY_STORAGE_ERROR` when the vault fails or
|
|
78
|
+
* holds a key of the wrong size, when the key does not open the file, or
|
|
79
|
+
* when the file was created with the other `encryptionAtRest` setting.
|
|
80
|
+
* @throws EncryptionError with `INVALID_STATE` when the name is not valid,
|
|
81
|
+
* when a store of this process holds the file, or when a newer SDK wrote
|
|
82
|
+
* the file.
|
|
83
|
+
*/
|
|
84
|
+
export function nodeStore(options) {
|
|
85
|
+
return NodeSignalProtocolStore.open(options);
|
|
100
86
|
}
|
|
101
87
|
/**
|
|
102
|
-
*
|
|
88
|
+
* Delete the database file, then create a new key, and return the open, empty
|
|
89
|
+
* store. This is the only way to open a store whose key is lost.
|
|
103
90
|
*
|
|
104
|
-
*
|
|
91
|
+
* @throws SqliteStoreInUseError when a store in another process holds the
|
|
92
|
+
* file. The reset changes nothing.
|
|
93
|
+
* @throws EncryptionError with `INVALID_STATE` when the name is not valid, or
|
|
94
|
+
* when a store of this process holds the file. Close that store first.
|
|
105
95
|
*/
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
constructor(config) {
|
|
109
|
-
this.db = getNodeEncryptedDatabase(config?.dataDir);
|
|
110
|
-
}
|
|
111
|
-
// ============================================================================
|
|
112
|
-
// Initialization
|
|
113
|
-
// ============================================================================
|
|
114
|
-
async initialize() {
|
|
115
|
-
await this.db.initialize();
|
|
116
|
-
}
|
|
117
|
-
// ============================================================================
|
|
118
|
-
// Identity Key Management (Own Keys)
|
|
119
|
-
// ============================================================================
|
|
120
|
-
async storeIdentityKey(keyPair, identityType) {
|
|
121
|
-
const it = identityType ?? 'aci';
|
|
122
|
-
await this.db.storeIdentityKey(keyPair, it);
|
|
123
|
-
}
|
|
124
|
-
async getIdentityKey(identityType) {
|
|
125
|
-
const it = identityType ?? 'aci';
|
|
126
|
-
return await this.db.getIdentityKey(it);
|
|
127
|
-
}
|
|
128
|
-
async hasIdentityKey(identityType) {
|
|
129
|
-
const key = await this.getIdentityKey(identityType);
|
|
130
|
-
return key !== null;
|
|
131
|
-
}
|
|
132
|
-
async getLocalRegistrationId(identityType) {
|
|
133
|
-
return await this.db.getRegistrationId(identityType ?? 'aci');
|
|
134
|
-
}
|
|
135
|
-
async setLocalRegistrationId(id, identityType) {
|
|
136
|
-
// A registration ID identifies this install for the lifetime of the
|
|
137
|
-
// install. Holding it in memory would hand every restart a fresh one and
|
|
138
|
-
// make every peer read the process as a reinstall.
|
|
139
|
-
await this.db.setRegistrationId(identityType ?? 'aci', id);
|
|
140
|
-
}
|
|
141
|
-
// ============================================================================
|
|
142
|
-
// Identity Verification (Contact Identity Keys)
|
|
143
|
-
// ============================================================================
|
|
144
|
-
async saveContactIdentity(address, identity, identityType, suppliedCommitment) {
|
|
145
|
-
const key = this.getContactIdentityKey(address, identityType);
|
|
146
|
-
const existing = await this.db.getContactIdentity(key);
|
|
147
|
-
const status = evaluateContactIdentityCandidate(existing, identity, suppliedCommitment);
|
|
148
|
-
if (status === 'NEW') {
|
|
149
|
-
await this.db.storeContactIdentity(key, createUnverifiedContactIdentityRecord(identity, Date.now()));
|
|
150
|
-
return IdentityKeyChange.NEW_IDENTITY;
|
|
151
|
-
}
|
|
152
|
-
if (status === 'MATCH')
|
|
153
|
-
return IdentityKeyChange.UNCHANGED;
|
|
154
|
-
if (status === 'ROLLBACK')
|
|
155
|
-
return IdentityKeyChange.ROLLBACK;
|
|
156
|
-
return IdentityKeyChange.CHANGED;
|
|
157
|
-
}
|
|
158
|
-
async getContactIdentity(address, identityType) {
|
|
159
|
-
const record = await this.db.getContactIdentity(this.getContactIdentityKey(address, identityType));
|
|
160
|
-
if (record)
|
|
161
|
-
validateContactIdentityRecord(record);
|
|
162
|
-
return record;
|
|
163
|
-
}
|
|
164
|
-
async acceptContactIdentityRotation(address, identity, identityType, suppliedCommitment) {
|
|
165
|
-
return await this.acceptContactIdentityRotationAndDeleteSessions(address, identity, identityType, suppliedCommitment);
|
|
166
|
-
}
|
|
167
|
-
async acceptContactIdentityRotationAndDeleteSessions(address, identity, identityType, suppliedCommitment) {
|
|
168
|
-
const key = this.getContactIdentityKey(address, identityType);
|
|
169
|
-
return await this.db.mutateContactIdentityAndDeleteSessions(key, address.userId, (existing) => {
|
|
170
|
-
if (!existing)
|
|
171
|
-
throw new Error('Cannot rotate an unseen identity');
|
|
172
|
-
return acceptRotation(existing, identity, Date.now(), suppliedCommitment);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
async verifyContactIdentity(address, identity, identityType, suppliedCommitment) {
|
|
176
|
-
const key = this.getContactIdentityKey(address, identityType);
|
|
177
|
-
return await this.db.mutateContactIdentity(key, (existing) => {
|
|
178
|
-
if (!existing)
|
|
179
|
-
throw new Error('Cannot verify an unseen identity');
|
|
180
|
-
return verifyContactIdentityRecord(existing, identity, Date.now(), suppliedCommitment);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
async isTrustedIdentity(address, identity, _direction, identityType) {
|
|
184
|
-
const saved = await this.getContactIdentity(address, identityType);
|
|
185
|
-
const status = evaluateContactIdentityCandidate(saved, identity);
|
|
186
|
-
return status === 'NEW' || status === 'MATCH';
|
|
187
|
-
}
|
|
188
|
-
// ============================================================================
|
|
189
|
-
// PreKey Management
|
|
190
|
-
// ============================================================================
|
|
191
|
-
async storeEcSignedPreKey(signedPreKey, identityType) {
|
|
192
|
-
const it = identityType ?? 'aci';
|
|
193
|
-
await this.db.storeEcSignedPreKey(signedPreKey, it);
|
|
194
|
-
}
|
|
195
|
-
async getEcSignedPreKey(keyId, identityType) {
|
|
196
|
-
const it = identityType ?? 'aci';
|
|
197
|
-
return await this.db.getEcSignedPreKey(keyId, it);
|
|
198
|
-
}
|
|
199
|
-
async getAllEcSignedPreKeys(identityType) {
|
|
200
|
-
const it = identityType ?? 'aci';
|
|
201
|
-
return await this.db.getAllEcSignedPreKeys(it);
|
|
202
|
-
}
|
|
203
|
-
async removeEcSignedPreKey(keyId, identityType) {
|
|
204
|
-
const it = identityType ?? 'aci';
|
|
205
|
-
return await this.db.removeEcSignedPreKey(keyId, it);
|
|
206
|
-
}
|
|
207
|
-
async storeEcOneTimePreKeys(prekeys, identityType) {
|
|
208
|
-
const it = identityType ?? 'aci';
|
|
209
|
-
await this.db.storeEcOneTimePreKeys(prekeys, it);
|
|
210
|
-
}
|
|
211
|
-
async getEcOneTimePreKeys(identityType) {
|
|
212
|
-
const it = identityType ?? 'aci';
|
|
213
|
-
return await this.db.getEcOneTimePreKeys(it);
|
|
214
|
-
}
|
|
215
|
-
async removeEcOneTimePreKey(preKeyId, identityType) {
|
|
216
|
-
const it = identityType ?? 'aci';
|
|
217
|
-
await this.db.removeEcOneTimePreKey((key) => key.keyId === preKeyId, it);
|
|
218
|
-
}
|
|
219
|
-
async storeKemOneTimePreKeys(prekeys, identityType) {
|
|
220
|
-
await this.db.storeKemOneTimePreKeys(prekeys, identityType ?? 'aci');
|
|
221
|
-
}
|
|
222
|
-
async getKemOneTimePreKeys(identityType) {
|
|
223
|
-
return await this.db.getKemOneTimePreKeys(identityType ?? 'aci');
|
|
224
|
-
}
|
|
225
|
-
async getKemOneTimePreKey(keyId, identityType) {
|
|
226
|
-
return ((await this.getKemOneTimePreKeys(identityType)).find((key) => key.keyId === keyId) ?? null);
|
|
227
|
-
}
|
|
228
|
-
async removeKemOneTimePreKey(keyId, identityType) {
|
|
229
|
-
await this.db.removeKemOneTimePreKey(keyId, identityType ?? 'aci');
|
|
230
|
-
}
|
|
231
|
-
async getKemOneTimePreKeyCount(identityType) {
|
|
232
|
-
return (await this.getKemOneTimePreKeys(identityType)).length;
|
|
233
|
-
}
|
|
234
|
-
async storeKyberPreKey(kyberPreKey, identityType) {
|
|
235
|
-
const it = identityType ?? 'aci';
|
|
236
|
-
await this.db.storeKyberPreKey(kyberPreKey, it);
|
|
237
|
-
}
|
|
238
|
-
async getKyberPreKey(identityType) {
|
|
239
|
-
const it = identityType ?? 'aci';
|
|
240
|
-
return await this.db.getCurrentKyberPreKey(it);
|
|
241
|
-
}
|
|
242
|
-
async getKyberPreKeyById(keyId, identityType) {
|
|
243
|
-
return await this.db.getKyberPreKeyById(keyId, identityType ?? 'aci');
|
|
244
|
-
}
|
|
245
|
-
async markKyberPreKeyUsed(kyberPreKeyId, signedPreKeyId, baseKeyBytes, identityType) {
|
|
246
|
-
const it = identityType ?? 'aci';
|
|
247
|
-
await this.db.markKyberPreKeyUsed(it, { kyberPreKeyId, signedPreKeyId, baseKeyBytes });
|
|
248
|
-
}
|
|
249
|
-
// ============================================================================
|
|
250
|
-
// Session Management
|
|
251
|
-
// ============================================================================
|
|
252
|
-
async storeSessionRecord(address, record) {
|
|
253
|
-
assertCurrentSessionRecord(record);
|
|
254
|
-
const key = this.getAddressKey(address);
|
|
255
|
-
await this.db.storeSession(key, address.userId, address.deviceId, serializeSessionRecord(record));
|
|
256
|
-
}
|
|
257
|
-
async getSessionRecord(address) {
|
|
258
|
-
const key = this.getAddressKey(address);
|
|
259
|
-
const serialized = await this.db.getSession(key);
|
|
260
|
-
if (serialized) {
|
|
261
|
-
try {
|
|
262
|
-
const record = deserializeSessionRecord(serialized);
|
|
263
|
-
assertCurrentSessionRecord(record);
|
|
264
|
-
return record;
|
|
265
|
-
}
|
|
266
|
-
catch {
|
|
267
|
-
await this.db.deleteSession(key);
|
|
268
|
-
return null;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
async deleteSessionRecord(address) {
|
|
274
|
-
const key = this.getAddressKey(address);
|
|
275
|
-
await this.db.deleteSession(key);
|
|
276
|
-
}
|
|
277
|
-
async archiveCurrentSession(address, newSession) {
|
|
278
|
-
const key = this.getAddressKey(address);
|
|
279
|
-
const serialized = await this.db.getSession(key);
|
|
280
|
-
const record = serialized ? deserializeSessionRecord(serialized) : null;
|
|
281
|
-
if (!record) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
// Archive current session by its baseKey
|
|
285
|
-
if (record.currentSession) {
|
|
286
|
-
if (!record.archivedSessions) {
|
|
287
|
-
record.archivedSessions = {};
|
|
288
|
-
}
|
|
289
|
-
record.archivedSessions[record.currentSession.baseKey] = record.currentSession;
|
|
290
|
-
}
|
|
291
|
-
// Set new session as current
|
|
292
|
-
record.currentSession = newSession || null;
|
|
293
|
-
await this.db.storeSession(key, address.userId, address.deviceId, serializeSessionRecord(record));
|
|
294
|
-
}
|
|
295
|
-
async getSessionsForUser(userId) {
|
|
296
|
-
const serialized = await this.db.getSessionsForUser(userId);
|
|
297
|
-
return serialized.map(deserializeSessionRecord);
|
|
298
|
-
}
|
|
299
|
-
async commitSessionTrust(commit) {
|
|
300
|
-
assertCurrentSessionRecord(commit.record);
|
|
301
|
-
const contactKey = this.getContactIdentityKey(commit.address, commit.contactIdentityType);
|
|
302
|
-
await this.db.commitSessionTrust(this.getAddressKey(commit.address), commit.address.userId, commit.address.deviceId, serializeSessionRecord(commit.record), commit.localIdentityType, contactKey, (existing) => {
|
|
303
|
-
const status = evaluateContactIdentityCandidate(existing, commit.contactIdentity);
|
|
304
|
-
if (status === 'NEW') {
|
|
305
|
-
return createUnverifiedContactIdentityRecord(commit.contactIdentity, Date.now());
|
|
306
|
-
}
|
|
307
|
-
if (status === 'MATCH' && existing)
|
|
308
|
-
return existing;
|
|
309
|
-
throw new Error(`Atomic session/trust commit rejected contact identity status ${status}`);
|
|
310
|
-
}, commit.oneTimePreKeyId, commit.kemOneTimePreKeyId, commit.receivedContent, commit.kyberPreKeyUse);
|
|
311
|
-
}
|
|
312
|
-
async hasSession(address) {
|
|
313
|
-
const record = await this.getSessionRecord(address);
|
|
314
|
-
return record !== null;
|
|
315
|
-
}
|
|
316
|
-
async getSessionCount() {
|
|
317
|
-
const stats = await this.db.getStats();
|
|
318
|
-
return stats.sessions;
|
|
319
|
-
}
|
|
320
|
-
// ============================================================================
|
|
321
|
-
// Database Encryption
|
|
322
|
-
// ============================================================================
|
|
323
|
-
async getDatabaseKey() {
|
|
324
|
-
const key = await this.db['dbKey'];
|
|
325
|
-
if (!key) {
|
|
326
|
-
throw new EncryptionError('Database key not initialized', EncryptionErrorCode.INITIALIZATION_FAILED);
|
|
327
|
-
}
|
|
328
|
-
return key;
|
|
329
|
-
}
|
|
330
|
-
// ============================================================================
|
|
331
|
-
// SESAME Multi-Device Session Management
|
|
332
|
-
//
|
|
333
|
-
// A device's session is the same session the protocol store holds for that
|
|
334
|
-
// address. Writes go to both so `getSessionRecord` and `getDeviceSession`
|
|
335
|
-
// never disagree about which ratchet is current.
|
|
336
|
-
// ============================================================================
|
|
337
|
-
async getUserRecord(userId) {
|
|
338
|
-
const { users } = await this.db.readSesameState();
|
|
339
|
-
const stored = users[userId];
|
|
340
|
-
return stored ? deserializeUserRecord(stored) : null;
|
|
341
|
-
}
|
|
342
|
-
async setUserRecord(userId, record) {
|
|
343
|
-
const serialized = serializeUserRecord(record);
|
|
344
|
-
await this.db.mutateSesameState(({ users, sessions }) => {
|
|
345
|
-
users[userId] = serialized;
|
|
346
|
-
for (const [deviceId, device] of serialized.devices) {
|
|
347
|
-
if (!device.session)
|
|
348
|
-
continue;
|
|
349
|
-
sessions[this.getAddressKey({ userId, deviceId })] = {
|
|
350
|
-
userId,
|
|
351
|
-
deviceId,
|
|
352
|
-
serializedRecord: device.session,
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
async getDeviceRecord(userId, deviceId) {
|
|
358
|
-
// The live session is read through `getSessionRecord` rather than out of
|
|
359
|
-
// the device record. A session this store would refuse to hand the protocol
|
|
360
|
-
// layer is therefore not handed to the SESAME layer either.
|
|
361
|
-
const session = await this.getSessionRecord(ProtocolAddress.create(userId, deviceId));
|
|
362
|
-
const { users } = await this.db.readSesameState();
|
|
363
|
-
const stored = users[userId]?.devices.find(([id]) => id === deviceId)?.[1] ?? null;
|
|
364
|
-
if (!session)
|
|
365
|
-
return stored ? deserializeDeviceRecord(stored) : null;
|
|
366
|
-
const now = Date.now();
|
|
367
|
-
return {
|
|
368
|
-
...(stored ? deserializeDeviceRecord(stored) : {}),
|
|
369
|
-
userId,
|
|
370
|
-
deviceId,
|
|
371
|
-
// The identity pin is a trust decision, so it comes from what was
|
|
372
|
-
// persisted rather than from whichever session happens to be current.
|
|
373
|
-
// Re-deriving it would unpin a device the moment its session is archived.
|
|
374
|
-
identityKey: stored?.identityKey.length
|
|
375
|
-
? Uint8Array.from(stored.identityKey)
|
|
376
|
-
: session.currentSession?.remoteIdentity
|
|
377
|
-
? encodeCompositeIdentityV1(session.currentSession.remoteIdentity)
|
|
378
|
-
: UNPINNED_DEVICE_IDENTITY_KEY,
|
|
379
|
-
session,
|
|
380
|
-
createdAt: session.metadata?.createdAt ?? stored?.createdAt ?? now,
|
|
381
|
-
updatedAt: now,
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
async setDeviceRecord(userId, deviceId, record) {
|
|
385
|
-
const serialized = serializeDeviceRecord(record);
|
|
386
|
-
await this.db.mutateSesameState(({ users, sessions }) => {
|
|
387
|
-
const now = Date.now();
|
|
388
|
-
const user = branch(users, userId, () => ({
|
|
389
|
-
userId,
|
|
390
|
-
devices: [],
|
|
391
|
-
createdAt: now,
|
|
392
|
-
updatedAt: now,
|
|
393
|
-
}));
|
|
394
|
-
const index = user.devices.findIndex(([id]) => id === deviceId);
|
|
395
|
-
if (index >= 0)
|
|
396
|
-
user.devices[index] = [deviceId, serialized];
|
|
397
|
-
else
|
|
398
|
-
user.devices.push([deviceId, serialized]);
|
|
399
|
-
user.updatedAt = now;
|
|
400
|
-
if (serialized.session) {
|
|
401
|
-
sessions[this.getAddressKey({ userId, deviceId })] = {
|
|
402
|
-
userId,
|
|
403
|
-
deviceId,
|
|
404
|
-
serializedRecord: serialized.session,
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
async deleteDeviceRecord(userId, deviceId) {
|
|
410
|
-
await this.db.mutateSesameState(({ users, sessions }) => {
|
|
411
|
-
delete sessions[this.getAddressKey({ userId, deviceId })];
|
|
412
|
-
const user = users[userId];
|
|
413
|
-
if (!user)
|
|
414
|
-
return;
|
|
415
|
-
user.devices = user.devices.filter(([id]) => id !== deviceId);
|
|
416
|
-
user.updatedAt = Date.now();
|
|
417
|
-
if (user.devices.length === 0)
|
|
418
|
-
delete users[userId];
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
async getDeviceSession(userId, deviceId) {
|
|
422
|
-
return (await this.getDeviceRecord(userId, deviceId))?.session ?? null;
|
|
423
|
-
}
|
|
424
|
-
async setDeviceSession(userId, deviceId, session) {
|
|
425
|
-
const record = await this.getDeviceRecord(userId, deviceId);
|
|
426
|
-
if (!record)
|
|
427
|
-
throw new Error(`Device record not found: ${userId}:${deviceId}`);
|
|
428
|
-
record.session = session;
|
|
429
|
-
record.updatedAt = Date.now();
|
|
430
|
-
await this.setDeviceRecord(userId, deviceId, record);
|
|
431
|
-
}
|
|
432
|
-
async deleteStaleRecords(maxLatency) {
|
|
433
|
-
return await this.db.mutateSesameState(({ users }) => {
|
|
434
|
-
const now = Date.now();
|
|
435
|
-
let deleted = 0;
|
|
436
|
-
for (const userId of Object.keys(users)) {
|
|
437
|
-
const user = users[userId];
|
|
438
|
-
const kept = user.devices.filter(([, device]) => {
|
|
439
|
-
const record = readStoredSession(device.session);
|
|
440
|
-
const hasNoSessions = !record ||
|
|
441
|
-
(!record.currentSession && Object.keys(record.archivedSessions).length === 0);
|
|
442
|
-
return !(hasNoSessions && now - device.createdAt > maxLatency);
|
|
443
|
-
});
|
|
444
|
-
deleted += user.devices.length - kept.length;
|
|
445
|
-
user.devices = kept;
|
|
446
|
-
user.updatedAt = now;
|
|
447
|
-
if (user.devices.length === 0)
|
|
448
|
-
delete users[userId];
|
|
449
|
-
}
|
|
450
|
-
return deleted;
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
|
-
async cleanupExpiredSessions(maxRecv) {
|
|
454
|
-
return await this.db.mutateSesameState(({ users, sessions }) => {
|
|
455
|
-
const now = Date.now();
|
|
456
|
-
let deleted = 0;
|
|
457
|
-
for (const user of Object.values(users)) {
|
|
458
|
-
for (const [deviceId, device] of user.devices) {
|
|
459
|
-
if (!device.session)
|
|
460
|
-
continue;
|
|
461
|
-
const record = readStoredSession(device.session);
|
|
462
|
-
if (!record) {
|
|
463
|
-
device.session = null;
|
|
464
|
-
delete sessions[this.getAddressKey({ userId: user.userId, deviceId })];
|
|
465
|
-
continue;
|
|
466
|
-
}
|
|
467
|
-
const createdAt = record.metadata?.createdAt ?? 0;
|
|
468
|
-
if (now - createdAt > maxRecv) {
|
|
469
|
-
if (record.currentSession)
|
|
470
|
-
deleted++;
|
|
471
|
-
deleted += Object.keys(record.archivedSessions).length;
|
|
472
|
-
device.session = null;
|
|
473
|
-
delete sessions[this.getAddressKey({ userId: user.userId, deviceId })];
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
for (const [baseKey, state] of Object.entries(record.archivedSessions)) {
|
|
477
|
-
if (now - (state?.lastUsedAt ?? createdAt) <= maxRecv)
|
|
478
|
-
continue;
|
|
479
|
-
delete record.archivedSessions[baseKey];
|
|
480
|
-
deleted++;
|
|
481
|
-
}
|
|
482
|
-
device.session = serializeSessionRecord(record);
|
|
483
|
-
sessions[this.getAddressKey({ userId: user.userId, deviceId })] = {
|
|
484
|
-
userId: user.userId,
|
|
485
|
-
deviceId,
|
|
486
|
-
serializedRecord: device.session,
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
device.updatedAt = now;
|
|
490
|
-
}
|
|
491
|
-
user.updatedAt = now;
|
|
492
|
-
}
|
|
493
|
-
return deleted;
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
async getAllUserIds() {
|
|
497
|
-
const { users } = await this.db.readSesameState();
|
|
498
|
-
return Object.keys(users);
|
|
499
|
-
}
|
|
500
|
-
async getSesameDeviceIds(userId) {
|
|
501
|
-
const { users } = await this.db.readSesameState();
|
|
502
|
-
return users[userId]?.devices.map(([deviceId]) => deviceId) ?? [];
|
|
503
|
-
}
|
|
504
|
-
// ============================================================================
|
|
505
|
-
// Sender Keys (Group Messaging)
|
|
506
|
-
// ============================================================================
|
|
507
|
-
async storeSenderKey(groupId, userId, deviceId, state) {
|
|
508
|
-
await this.db.mutateSenderKeyState(({ current }) => {
|
|
509
|
-
const users = subtree(current, groupId);
|
|
510
|
-
subtree(users, userId)[String(deviceId)] = state;
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
async getSenderKey(groupId, userId, deviceId) {
|
|
514
|
-
const { current } = await this.db.readSenderKeyState();
|
|
515
|
-
return current[groupId]?.[userId]?.[String(deviceId)] ?? null;
|
|
516
|
-
}
|
|
517
|
-
async deleteSenderKey(groupId, userId, deviceId) {
|
|
518
|
-
await this.db.mutateSenderKeyState(({ current, records }) => {
|
|
519
|
-
pruneSenderKeyDevice(current, groupId, userId, deviceId);
|
|
520
|
-
pruneSenderKeyDevice(records, groupId, userId, deviceId);
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
async resolveGroupForSenderKeyId(senderKeyId, userId, deviceId) {
|
|
524
|
-
if (!senderKeyId)
|
|
525
|
-
return null;
|
|
526
|
-
const { current, records } = await this.db.readSenderKeyState();
|
|
527
|
-
const device = String(deviceId);
|
|
528
|
-
for (const groupId of new Set([...Object.keys(current), ...Object.keys(records)])) {
|
|
529
|
-
if (current[groupId]?.[userId]?.[device]?.senderKeyId === senderKeyId)
|
|
530
|
-
return groupId;
|
|
531
|
-
// A message encrypted just before a rotation still names the superseded
|
|
532
|
-
// key, so the retained previous states have to be searched too.
|
|
533
|
-
const retained = records[groupId]?.[userId]?.[device];
|
|
534
|
-
if (retained?.some((state) => state.senderKeyId === senderKeyId))
|
|
535
|
-
return groupId;
|
|
536
|
-
}
|
|
537
|
-
return null;
|
|
538
|
-
}
|
|
539
|
-
async getAllSenderKeysForGroup(groupId) {
|
|
540
|
-
const { current } = await this.db.readSenderKeyState();
|
|
541
|
-
const users = current[groupId];
|
|
542
|
-
if (!users)
|
|
543
|
-
return [];
|
|
544
|
-
return Object.values(users).flatMap((devices) => Object.values(devices));
|
|
545
|
-
}
|
|
546
|
-
async deleteAllSenderKeysForGroup(groupId) {
|
|
547
|
-
return await this.db.mutateSenderKeyState(({ current, records, skipped }) => {
|
|
548
|
-
const users = current[groupId];
|
|
549
|
-
const count = users
|
|
550
|
-
? Object.values(users).reduce((total, devices) => total + Object.keys(devices).length, 0)
|
|
551
|
-
: 0;
|
|
552
|
-
// Each identifier is its own key, so deleting one group cannot reach a
|
|
553
|
-
// group whose name merely shares a prefix with it.
|
|
554
|
-
delete current[groupId];
|
|
555
|
-
delete records[groupId];
|
|
556
|
-
delete skipped[groupId];
|
|
557
|
-
return count;
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
async storeSenderKeyRecord(groupId, userId, deviceId, states, receive) {
|
|
561
|
-
if (states.length === 0)
|
|
562
|
-
return;
|
|
563
|
-
await this.db.mutateSenderKeyState(({ current, records, skipped }) => {
|
|
564
|
-
const device = String(deviceId);
|
|
565
|
-
subtree(subtree(current, groupId), userId)[device] = states[0];
|
|
566
|
-
subtree(subtree(records, groupId), userId)[device] = states;
|
|
567
|
-
if (receive?.consumedChainIndex !== undefined) {
|
|
568
|
-
const keys = skipped[groupId]?.[userId]?.[device];
|
|
569
|
-
if (keys)
|
|
570
|
-
delete keys[String(receive.consumedChainIndex)];
|
|
571
|
-
}
|
|
572
|
-
}, receive?.content);
|
|
573
|
-
}
|
|
574
|
-
async getSenderKeyRecord(groupId, userId, deviceId) {
|
|
575
|
-
const { current, records } = await this.db.readSenderKeyState();
|
|
576
|
-
const device = String(deviceId);
|
|
577
|
-
const record = records[groupId]?.[userId]?.[device];
|
|
578
|
-
if (record)
|
|
579
|
-
return record;
|
|
580
|
-
const state = current[groupId]?.[userId]?.[device];
|
|
581
|
-
return state ? [state] : null;
|
|
582
|
-
}
|
|
583
|
-
// ============================================================================
|
|
584
|
-
// Skipped Sender Keys (Out-of-Order Group Messages)
|
|
585
|
-
// ============================================================================
|
|
586
|
-
async storeSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex, messageKey) {
|
|
587
|
-
await this.db.mutateSenderKeyState(({ skipped }) => {
|
|
588
|
-
const senders = subtree(skipped, groupId);
|
|
589
|
-
const devices = subtree(senders, senderId);
|
|
590
|
-
subtree(devices, String(senderDeviceId))[String(chainIndex)] = messageKey;
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
async getSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex) {
|
|
594
|
-
const { skipped } = await this.db.readSenderKeyState();
|
|
595
|
-
const stored = skipped[groupId]?.[senderId]?.[String(senderDeviceId)]?.[String(chainIndex)];
|
|
596
|
-
return stored ?? null;
|
|
597
|
-
}
|
|
598
|
-
async deleteSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex) {
|
|
599
|
-
await this.db.mutateSenderKeyState(({ skipped }) => {
|
|
600
|
-
const keys = skipped[groupId]?.[senderId]?.[String(senderDeviceId)];
|
|
601
|
-
if (keys)
|
|
602
|
-
delete keys[String(chainIndex)];
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
async countSkippedSenderKeys(groupId, senderId, senderDeviceId) {
|
|
606
|
-
const { skipped } = await this.db.readSenderKeyState();
|
|
607
|
-
const keys = skipped[groupId]?.[senderId]?.[String(senderDeviceId)];
|
|
608
|
-
return keys ? Object.keys(keys).length : 0;
|
|
609
|
-
}
|
|
610
|
-
async deleteOldestSkippedSenderKeys(groupId, senderId, senderDeviceId, count) {
|
|
611
|
-
return await this.db.mutateSenderKeyState(({ skipped }) => {
|
|
612
|
-
const keys = skipped[groupId]?.[senderId]?.[String(senderDeviceId)];
|
|
613
|
-
if (!keys)
|
|
614
|
-
return 0;
|
|
615
|
-
// Chain index is the message order, so the lowest indices are the oldest.
|
|
616
|
-
const oldest = Object.keys(keys)
|
|
617
|
-
.sort((a, b) => Number(a) - Number(b))
|
|
618
|
-
.slice(0, count);
|
|
619
|
-
for (const chainIndex of oldest)
|
|
620
|
-
delete keys[chainIndex];
|
|
621
|
-
return oldest.length;
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
// ============================================================================
|
|
625
|
-
// Message Records (SESAME Retry Support)
|
|
626
|
-
// ============================================================================
|
|
627
|
-
async storeMessageRecord(record) {
|
|
628
|
-
await this.db.mutateMessageRecords((records) => {
|
|
629
|
-
subtree(records, record.sessionId)[String(record.timestamp)] = record;
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
async getMessageRecord(sessionId, timestamp) {
|
|
633
|
-
const records = await this.db.readMessageRecords();
|
|
634
|
-
return records[sessionId]?.[String(timestamp)] ?? null;
|
|
635
|
-
}
|
|
636
|
-
async deleteMessageRecord(sessionId, timestamp) {
|
|
637
|
-
await this.db.mutateMessageRecords((records) => {
|
|
638
|
-
const session = records[sessionId];
|
|
639
|
-
if (!session)
|
|
640
|
-
return;
|
|
641
|
-
delete session[String(timestamp)];
|
|
642
|
-
if (Object.keys(session).length === 0)
|
|
643
|
-
delete records[sessionId];
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
async deleteExpiredMessageRecords(maxAgeMs) {
|
|
647
|
-
const cutoff = Date.now() - maxAgeMs;
|
|
648
|
-
return await this.db.mutateMessageRecords((records) => {
|
|
649
|
-
let deleted = 0;
|
|
650
|
-
for (const sessionId of Object.keys(records)) {
|
|
651
|
-
const session = records[sessionId];
|
|
652
|
-
for (const key of Object.keys(session)) {
|
|
653
|
-
if (session[key].createdAt >= cutoff)
|
|
654
|
-
continue;
|
|
655
|
-
delete session[key];
|
|
656
|
-
deleted++;
|
|
657
|
-
}
|
|
658
|
-
if (Object.keys(session).length === 0)
|
|
659
|
-
delete records[sessionId];
|
|
660
|
-
}
|
|
661
|
-
return deleted;
|
|
662
|
-
});
|
|
663
|
-
}
|
|
664
|
-
async clearAllMessageRecords() {
|
|
665
|
-
return await this.db.mutateMessageRecords((records) => {
|
|
666
|
-
let deleted = 0;
|
|
667
|
-
for (const sessionId of Object.keys(records)) {
|
|
668
|
-
deleted += Object.keys(records[sessionId]).length;
|
|
669
|
-
delete records[sessionId];
|
|
670
|
-
}
|
|
671
|
-
return deleted;
|
|
672
|
-
});
|
|
673
|
-
}
|
|
674
|
-
async deleteMessageRecordsForSession(sessionId) {
|
|
675
|
-
return await this.db.mutateMessageRecords((records) => {
|
|
676
|
-
const deleted = Object.keys(records[sessionId] ?? {}).length;
|
|
677
|
-
delete records[sessionId];
|
|
678
|
-
return deleted;
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
// ============================================================================
|
|
682
|
-
// Metadata
|
|
683
|
-
// ============================================================================
|
|
684
|
-
async getMetadata(key) {
|
|
685
|
-
return await this.db.getMetadataValue(key);
|
|
686
|
-
}
|
|
687
|
-
async getReceivedContent(id) {
|
|
688
|
-
const value = await this.db.getMetadataValue(`received-content:${id}`);
|
|
689
|
-
return value ? parseReceivedContent(value, id) : null;
|
|
690
|
-
}
|
|
691
|
-
async deleteReceivedContent(id) {
|
|
692
|
-
await this.db.deleteMetadataValue(`received-content:${id}`);
|
|
693
|
-
}
|
|
694
|
-
async deleteExpiredReceivedContent(before) {
|
|
695
|
-
return this.db.deleteExpiredReceivedContent(before);
|
|
696
|
-
}
|
|
697
|
-
async setMetadata(key, value) {
|
|
698
|
-
await this.db.setMetadataValue(key, value);
|
|
699
|
-
}
|
|
700
|
-
async deleteMetadata(key) {
|
|
701
|
-
await this.db.deleteMetadataValue(key);
|
|
702
|
-
}
|
|
703
|
-
async compareAndSetMetadata(key, expected, value) {
|
|
704
|
-
return this.db.compareAndSetMetadataValue(key, expected, value);
|
|
705
|
-
}
|
|
706
|
-
// ============================================================================
|
|
707
|
-
// Key Recovery (PQXDH §4.13 identifier-collision recovery)
|
|
708
|
-
// ============================================================================
|
|
709
|
-
async getEcSignedPreKeyMaxId(identityType) {
|
|
710
|
-
return await this.db.getEcSignedPreKeyMaxId(identityType ?? 'aci');
|
|
711
|
-
}
|
|
712
|
-
async getKyberPreKeyMaxId(identityType) {
|
|
713
|
-
return await this.db.getKyberPreKeyMaxId(identityType ?? 'aci');
|
|
714
|
-
}
|
|
715
|
-
async deleteAllPreKeys(identityType) {
|
|
716
|
-
return await this.db.deleteAllPreKeys(identityType ?? 'aci');
|
|
717
|
-
}
|
|
718
|
-
async clearAllSessions() {
|
|
719
|
-
// A device record whose session is gone is not a device this store can
|
|
720
|
-
// reach. The SESAME records therefore go with the sessions in the same
|
|
721
|
-
// commit.
|
|
722
|
-
await this.db.clearSesameState();
|
|
723
|
-
}
|
|
724
|
-
async getDetailedStats() {
|
|
725
|
-
return await this.db.getDetailedStats();
|
|
726
|
-
}
|
|
727
|
-
// ============================================================================
|
|
728
|
-
// Utility
|
|
729
|
-
// ============================================================================
|
|
730
|
-
async clearAllKeys() {
|
|
731
|
-
await this.db.deleteDatabase();
|
|
732
|
-
}
|
|
733
|
-
// ============================================================================
|
|
734
|
-
// Helper Methods
|
|
735
|
-
// ============================================================================
|
|
736
|
-
getAddressKey(address) {
|
|
737
|
-
return ProtocolAddress.toString(address);
|
|
738
|
-
}
|
|
739
|
-
getContactIdentityKey(address, identityType) {
|
|
740
|
-
return `${address.userId}:${identityType ?? 'aci'}`;
|
|
741
|
-
}
|
|
96
|
+
export function resetNodeStore(options) {
|
|
97
|
+
return NodeSignalProtocolStore.reset(options);
|
|
742
98
|
}
|
|
743
99
|
//# sourceMappingURL=adapter.js.map
|