@open-e2ee/signal-protocol-sdk 0.1.0-alpha.3 → 0.1.0-alpha.5
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/CHANGELOG.md +82 -2
- package/NOTICE +3 -1
- package/README.md +10 -5
- package/dist/blocking/types.d.ts +1 -1
- package/dist/blocking/types.js +1 -1
- package/dist/client/client.d.ts +3 -3
- package/dist/client/client.js +4 -4
- package/dist/client/client.js.map +1 -1
- package/dist/client/compose.d.ts +1 -1
- package/dist/client/compose.d.ts.map +1 -1
- package/dist/client/config.d.ts +2 -2
- package/dist/client/event-hooks.d.ts +1 -1
- package/dist/client/headless.d.ts +2 -2
- package/dist/client/headless.js +2 -2
- package/dist/client/key-rotation-core.d.ts +4 -4
- package/dist/client/key-rotation-core.js +11 -11
- package/dist/client/key-rotation-core.js.map +1 -1
- package/dist/client/media.d.ts +2 -2
- package/dist/client/media.js +5 -5
- package/dist/client/media.js.map +1 -1
- package/dist/client/messages.js +2 -2
- package/dist/client/messages.js.map +1 -1
- package/dist/client/relay-subscription.js +17 -0
- package/dist/client/relay-subscription.js.map +1 -1
- package/dist/client/retry.js +1 -1
- package/dist/client/retry.js.map +1 -1
- package/dist/client/sealed-sender-ops.js +1 -1
- package/dist/client/sealed-sender-ops.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 +5 -1
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +19 -14
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/device/provisioning.d.ts +3 -3
- package/dist/device/provisioning.js +2 -2
- package/dist/device/provisioning.js.map +1 -1
- package/dist/hooks/use-connection-presence.d.ts +2 -2
- package/dist/hooks/use-connection-presence.d.ts.map +1 -1
- package/dist/hooks/use-connection-presence.js +1 -1
- package/dist/hooks/use-group-membership.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/crypto/index.js +1 -1
- package/dist/internal/crypto/index.js.map +1 -1
- package/dist/internal/crypto/kdf/hkdf.d.ts +1 -1
- package/dist/internal/crypto/kdf/hkdf.d.ts.map +1 -1
- package/dist/internal/crypto/kdf/hkdf.js +2 -2
- package/dist/internal/crypto/kdf/hkdf.js.map +1 -1
- package/dist/internal/crypto/key-prefix.d.ts +1 -1
- package/dist/internal/crypto/key-prefix.js +1 -1
- package/dist/internal/crypto/pq/kyber.d.ts +1 -1
- package/dist/internal/crypto/pq/kyber.js +1 -1
- package/dist/internal/crypto/symmetric/aes-gcm-siv.d.ts +1 -1
- package/dist/internal/crypto/symmetric/aes-gcm-siv.js +1 -1
- package/dist/internal/crypto/utils.d.ts +2 -2
- package/dist/internal/crypto/utils.js +2 -2
- package/dist/internal/encoding/proto/index.js +1 -1
- package/dist/internal/encoding/proto/index.js.map +1 -1
- package/dist/internal/encoding/proto/pq-ratchet-serialize.d.ts +2 -2
- package/dist/internal/encoding/proto/pq-ratchet-serialize.d.ts.map +1 -1
- package/dist/internal/encoding/proto/pq-ratchet-serialize.js +2 -2
- package/dist/internal/encoding/proto/pq-ratchet-serialize.js.map +1 -1
- package/dist/internal/groups/group-id.d.ts +1 -1
- package/dist/internal/groups/group-id.js +1 -1
- package/dist/internal/groups/group-id.js.map +1 -1
- package/dist/internal/groups-v2/access-control.d.ts +8 -1
- package/dist/internal/groups-v2/access-control.d.ts.map +1 -1
- package/dist/internal/groups-v2/access-control.js +8 -1
- package/dist/internal/groups-v2/access-control.js.map +1 -1
- package/dist/internal/groups-v2/change-actions.d.ts +8 -3
- package/dist/internal/groups-v2/change-actions.d.ts.map +1 -1
- package/dist/internal/groups-v2/change-actions.js +8 -3
- package/dist/internal/groups-v2/change-actions.js.map +1 -1
- package/dist/internal/groups-v2/index.d.ts +7 -2
- package/dist/internal/groups-v2/index.d.ts.map +1 -1
- package/dist/internal/groups-v2/index.js.map +1 -1
- package/dist/internal/groups-v2/manager.d.ts +4 -2
- package/dist/internal/groups-v2/manager.d.ts.map +1 -1
- package/dist/internal/groups-v2/manager.js +5 -3
- package/dist/internal/groups-v2/manager.js.map +1 -1
- package/dist/internal/groups-v2/types.d.ts +10 -3
- package/dist/internal/groups-v2/types.d.ts.map +1 -1
- package/dist/internal/groups-v2/types.js.map +1 -1
- package/dist/internal/manager/manager.d.ts.map +1 -1
- package/dist/internal/manager/manager.js +25 -14
- package/dist/internal/manager/manager.js.map +1 -1
- package/dist/internal/protocol/double-ratchet/chains.d.ts +1 -1
- package/dist/internal/protocol/double-ratchet/chains.js +1 -1
- package/dist/internal/protocol/double-ratchet/ratchet.d.ts +1 -1
- package/dist/internal/protocol/double-ratchet/ratchet.js +1 -1
- package/dist/internal/protocol/sealed-sender/decryption.js +2 -2
- package/dist/internal/protocol/sealed-sender/decryption.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.d.ts +1 -1
- package/dist/internal/protocol/sealed-sender/types.js +1 -1
- package/dist/internal/protocol/sender-keys/index.d.ts +1 -1
- package/dist/internal/protocol/sender-keys/manager.d.ts +2 -2
- package/dist/internal/protocol/sender-keys/manager.js +3 -3
- package/dist/internal/protocol/sender-keys/manager.js.map +1 -1
- package/dist/internal/protocol/spqr/index.d.ts +1 -1
- package/dist/internal/protocol/spqr/index.js +1 -1
- package/dist/internal/protocol/spqr/message.d.ts +1 -1
- package/dist/internal/protocol/spqr/message.js +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/codec.d.ts +3 -3
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/codec.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/index.js +2 -2
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/index.js.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.d.ts +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.js +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/rs/lagrange.js.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/serialize.d.ts +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/serialize.js +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js +5 -5
- package/dist/internal/protocol/spqr/ml-kem-braid/state-machine.js.map +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/types.d.ts +1 -1
- package/dist/internal/protocol/spqr/ml-kem-braid/types.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/spqr.d.ts +9 -9
- package/dist/internal/protocol/spqr/spqr.d.ts.map +1 -1
- package/dist/internal/protocol/spqr/spqr.js +9 -9
- package/dist/internal/protocol/spqr/spqr.js.map +1 -1
- package/dist/internal/protocol/triple-ratchet/ratchet.d.ts +1 -1
- package/dist/internal/protocol/triple-ratchet/ratchet.js +1 -1
- package/dist/internal/protocol/username/generate.d.ts +1 -1
- package/dist/internal/protocol/username/generate.js +1 -1
- package/dist/internal/protocol/username/hash.d.ts +1 -1
- package/dist/internal/protocol/username/hash.js +1 -1
- package/dist/internal/protocol/username/link.d.ts +1 -1
- package/dist/internal/protocol/username/link.js +1 -1
- package/dist/internal/protocol/username/proof.d.ts +1 -1
- package/dist/internal/protocol/username/proof.js +1 -1
- package/dist/internal/protocol/x3dh/x3dh.js +3 -3
- package/dist/internal/protocol/x3dh/x3dh.js.map +1 -1
- package/dist/internal/protocol/zk/groups/auth-credential.d.ts +5 -4
- package/dist/internal/protocol/zk/groups/auth-credential.d.ts.map +1 -1
- package/dist/internal/protocol/zk/groups/auth-credential.js.map +1 -1
- package/dist/internal/protocol/zk/groups/client-zk-group-cipher.d.ts +2 -2
- package/dist/internal/protocol/zk/groups/client-zk-group-cipher.js +2 -2
- package/dist/internal/sesame/device-registry.d.ts +11 -6
- package/dist/internal/sesame/device-registry.d.ts.map +1 -1
- package/dist/internal/sesame/device-registry.js +11 -7
- package/dist/internal/sesame/device-registry.js.map +1 -1
- package/dist/internal/sesame/manager.js +1 -1
- package/dist/internal/sesame/manager.js.map +1 -1
- package/dist/internal/session/cipher.d.ts.map +1 -1
- package/dist/internal/session/cipher.js +8 -0
- package/dist/internal/session/cipher.js.map +1 -1
- package/dist/internal/session/keys.d.ts +1 -1
- package/dist/keys/generation.d.ts +4 -3
- package/dist/keys/generation.d.ts.map +1 -1
- package/dist/keys/generation.js +2 -2
- package/dist/keys/generation.js.map +1 -1
- package/dist/keys/types.d.ts +1 -1
- package/dist/keys/types.d.ts.map +1 -1
- package/dist/local/store/expo/adapter.d.ts +3 -3
- package/dist/local/store/expo/adapter.js +2 -2
- package/dist/local/store/expo/db.js +1 -1
- package/dist/local/store/expo/db.js.map +1 -1
- package/dist/local/store/expo/index.d.ts +1 -1
- package/dist/local/store/expo/models/local-identity.d.ts +1 -1
- package/dist/local/store/expo/models/local-identity.js +1 -1
- package/dist/local/store/expo/models/sender-key.d.ts +3 -3
- package/dist/local/store/expo/models/sender-key.d.ts.map +1 -1
- package/dist/local/store/expo/models/sender-key.js +3 -3
- package/dist/local/store/expo/models/sender-key.js.map +1 -1
- package/dist/local/store/expo/schema.d.ts +1 -1
- package/dist/local/store/expo/schema.js +1 -1
- package/dist/local/store/expo/secure-store-options.d.ts +1 -1
- package/dist/local/store/mock/adapter.d.ts +6 -0
- package/dist/local/store/mock/adapter.d.ts.map +1 -1
- package/dist/local/store/mock/adapter.js +117 -47
- package/dist/local/store/mock/adapter.js.map +1 -1
- package/dist/local/store/mock/failures.d.ts +34 -0
- package/dist/local/store/mock/failures.d.ts.map +1 -0
- package/dist/local/store/mock/failures.js +75 -0
- package/dist/local/store/mock/failures.js.map +1 -0
- package/dist/local/store/mock/index.d.ts +4 -3
- package/dist/local/store/mock/index.d.ts.map +1 -1
- package/dist/local/store/mock/index.js +3 -2
- package/dist/local/store/mock/index.js.map +1 -1
- package/dist/local/store/node/database-key.js +1 -1
- package/dist/local/store/react-native/adapter.js +2 -2
- package/dist/local/store/react-native/adapter.js.map +1 -1
- package/dist/local/store/react-native/storage.d.ts +1 -1
- package/dist/local/store/web/adapter.d.ts.map +1 -1
- package/dist/local/store/web/adapter.js +14 -2
- package/dist/local/store/web/adapter.js.map +1 -1
- package/dist/local/vault/index.d.ts +1 -1
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/media/index.d.ts +2 -2
- package/dist/media/index.js +2 -2
- package/dist/profile/cipher.d.ts +1 -1
- package/dist/profile/cipher.js +1 -1
- package/dist/profile/contact-state.d.ts +1 -1
- package/dist/profile/contact-state.js +1 -1
- package/dist/profile/crypto.d.ts +1 -1
- package/dist/profile/crypto.js +1 -1
- package/dist/profile/profile-key.js +1 -1
- package/dist/profile/update-service.d.ts +2 -2
- package/dist/profile/update-service.d.ts.map +1 -1
- package/dist/remote/object-store/convex-r2/server.d.ts +1 -1
- package/dist/remote/relay/convex/index.d.ts +1 -1
- package/dist/remote/relay/convex/index.js +1 -1
- package/dist/remote/relay/convex/relay.d.ts +2 -2
- package/dist/remote/relay/convex/relay.js +2 -2
- package/dist/remote/relay/convex/types.d.ts +7 -7
- package/dist/remote/relay/convex/types.js +1 -1
- package/dist/remote/relay/mock/adapter.d.ts +13 -2
- package/dist/remote/relay/mock/adapter.d.ts.map +1 -1
- package/dist/remote/relay/mock/adapter.js +165 -51
- package/dist/remote/relay/mock/adapter.js.map +1 -1
- package/dist/remote/relay/mock/failures.d.ts +57 -0
- package/dist/remote/relay/mock/failures.d.ts.map +1 -0
- package/dist/remote/relay/mock/failures.js +118 -0
- package/dist/remote/relay/mock/failures.js.map +1 -0
- package/dist/remote/relay/mock/index.d.ts +4 -3
- package/dist/remote/relay/mock/index.d.ts.map +1 -1
- package/dist/remote/relay/mock/index.js +4 -3
- package/dist/remote/relay/mock/index.js.map +1 -1
- package/dist/remote/relay/types.d.ts +1 -1
- package/dist/remote/relay/types.js +1 -1
- package/dist/safety/protobuf.d.ts +1 -1
- package/dist/safety/protobuf.d.ts.map +1 -1
- package/dist/types/api.d.ts +6 -6
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +2 -2
- package/dist/types/errors.js.map +1 -1
- package/dist/types/protocol-config.d.ts +3 -2
- package/dist/types/protocol-config.d.ts.map +1 -1
- package/dist/types/protocol-config.js.map +1 -1
- package/dist/types/protocol-constants.d.ts +1 -1
- package/dist/types/protocol-constants.js +1 -1
- package/dist/utils/binary-transfer.d.ts +1 -1
- package/dist/utils/errors.d.ts +2 -2
- package/dist/utils/errors.js +2 -2
- package/dist/utils/retry.d.ts +2 -1
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +3 -1
- package/dist/utils/retry.js.map +1 -1
- package/dist/zk/groups.d.ts +1 -1
- package/dist/zk/groups.js +1 -1
- package/docs/CLIENT_COMPOSITION.md +5 -3
- package/docs/DEVIATIONS.md +892 -0
- package/docs/GETTING_STARTED.md +10 -6
- package/docs/PACKAGE_SURFACE.md +2 -2
- package/docs/PROTOCOL_POLICY.md +11 -2
- package/docs/RECIPES.md +4 -0
- package/docs/api/classes/SignalProtocolClient.md +4 -4
- package/docs/api/functions/createDefaultSignalLogger.md +2 -2
- package/docs/api/functions/resolveSignalLogger.md +2 -2
- package/docs/api/interfaces/BlockedRecipientEntry.md +1 -1
- package/docs/api/interfaces/ILogger.md +1 -1
- package/docs/api/interfaces/ISignalLocalSecretVault.md +2 -2
- package/docs/api/interfaces/ISignalLocalStore.md +2 -2
- package/docs/api/interfaces/ISignalProtocolClient.md +2 -2
- package/docs/api/interfaces/MLKEMBraidAgentState.md +1 -1
- package/docs/api/interfaces/PreKeyMaintenanceStore.md +2 -1
- package/docs/api/interfaces/SealedSenderConfig.md +2 -2
- package/docs/api/interfaces/SignalProtocolClientCompositionOptions.md +2 -2
- package/docs/api/interfaces/SignalProtocolClientConfig.md +2 -2
- package/docs/api/interfaces/SignalProtocolClientHooks.md +1 -1
- package/docs/api/interfaces/SignalProtocolClientIdentityConfig.md +1 -1
- package/docs/api/interfaces/SignalProtocolClientMediaConfig.md +3 -3
- package/docs/api/interfaces/SignalProtocolConfig.md +1 -1
- package/docs/api/namespaces/encoding/functions/bytesToUrlSafeBase64.md +2 -2
- package/docs/api/namespaces/keys/functions/generateKemOneTimePreKeys.md +1 -1
- package/docs/api/namespaces/media/functions/prepareMediaAttachmentUpload.md +1 -1
- package/docs/api/namespaces/media/functions/resolveMediaAttachment.md +1 -1
- package/docs/api/namespaces/media/variables/downloadMediaAttachment.md +1 -1
- package/docs/api/type-aliases/GroupId.md +1 -1
- package/docs/api/variables/MAX_RECEIVER_CHAINS.md +1 -1
- package/docs/api/variables/ONE_TIME_PREKEY_BATCH_SIZE.md +1 -1
- package/docs/api/variables/defaultSignalLogger.md +2 -2
- package/local/store/mock/README.md +31 -0
- package/package.json +2 -1
- package/remote/relay/mock/README.md +37 -0
|
@@ -11,7 +11,19 @@ import { assertCurrentSessionRecord, CURRENT_SESSION_RECORD_VERSION, } from '../
|
|
|
11
11
|
import { acceptContactIdentityRotation as acceptRotation, createUnverifiedContactIdentityRecord, encodeCompositeIdentityV1, UNPINNED_DEVICE_IDENTITY_KEY, evaluateContactIdentityCandidate, verifyContactIdentityRecord, validateContactIdentityRecord, } from '../../../keys/identity.js';
|
|
12
12
|
import { IdentityKeyChange } from '../../../types/trust.js';
|
|
13
13
|
import { generateRandomBytes } from '../../../internal/crypto/random.js';
|
|
14
|
+
import { MockStoreFailureController, } from './failures.js';
|
|
15
|
+
/**
|
|
16
|
+
* Cross the same ownership boundary as a durable adapter.
|
|
17
|
+
*
|
|
18
|
+
* Real stores serialize values before persistence and deserialize fresh values
|
|
19
|
+
* on read. Keeping that behavior here prevents tests and examples from
|
|
20
|
+
* accidentally mutating persisted protocol state through an object reference.
|
|
21
|
+
*/
|
|
22
|
+
function cloneStored(value) {
|
|
23
|
+
return structuredClone(value);
|
|
24
|
+
}
|
|
14
25
|
export class MockSignalStore {
|
|
26
|
+
failures;
|
|
15
27
|
// Identity keys and registration IDs keyed by identityType
|
|
16
28
|
identityKeys = new Map();
|
|
17
29
|
registrationIds = new Map();
|
|
@@ -34,7 +46,7 @@ export class MockSignalStore {
|
|
|
34
46
|
// Sender Key Records: full state arrays (current + previous) keyed by "groupId:userId:deviceId"
|
|
35
47
|
senderKeyRecords = new Map();
|
|
36
48
|
// Skipped sender keys for out-of-order messages (composite key -> messageKey)
|
|
37
|
-
//
|
|
49
|
+
// The reference implementation uses capacity-only limits (no time-based expiration)
|
|
38
50
|
skippedSenderKeys = new Map();
|
|
39
51
|
// Message records for SESAME retry request support
|
|
40
52
|
// Key format: "sessionId:timestamp" for primary lookup
|
|
@@ -42,16 +54,21 @@ export class MockSignalStore {
|
|
|
42
54
|
messageRecords = new Map();
|
|
43
55
|
// Metadata storage
|
|
44
56
|
_metadata = new Map();
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
this.failures = new MockStoreFailureController(options.failures);
|
|
59
|
+
}
|
|
45
60
|
// ============================================================================
|
|
46
61
|
// Identity Key Management (Own Keys)
|
|
47
62
|
// ============================================================================
|
|
48
63
|
async storeIdentityKey(keyPair, identityType) {
|
|
64
|
+
this.failures.beforeWrite('storeIdentityKey');
|
|
49
65
|
const it = identityType ?? 'aci';
|
|
50
|
-
this.identityKeys.set(it, keyPair);
|
|
66
|
+
this.identityKeys.set(it, cloneStored(keyPair));
|
|
51
67
|
}
|
|
52
68
|
async getIdentityKey(identityType) {
|
|
53
69
|
const it = identityType ?? 'aci';
|
|
54
|
-
|
|
70
|
+
const keyPair = this.identityKeys.get(it);
|
|
71
|
+
return keyPair ? cloneStored(keyPair) : null;
|
|
55
72
|
}
|
|
56
73
|
async hasIdentityKey(identityType) {
|
|
57
74
|
const it = identityType ?? 'aci';
|
|
@@ -62,6 +79,7 @@ export class MockSignalStore {
|
|
|
62
79
|
return this.registrationIds.get(it) ?? 0;
|
|
63
80
|
}
|
|
64
81
|
async setLocalRegistrationId(id, identityType) {
|
|
82
|
+
this.failures.beforeWrite('setLocalRegistrationId');
|
|
65
83
|
const it = identityType ?? 'aci';
|
|
66
84
|
this.registrationIds.set(it, id);
|
|
67
85
|
}
|
|
@@ -69,11 +87,12 @@ export class MockSignalStore {
|
|
|
69
87
|
// Identity Verification (Contact Identity Keys)
|
|
70
88
|
// ============================================================================
|
|
71
89
|
async saveContactIdentity(address, identity, identityType, suppliedCommitment) {
|
|
90
|
+
this.failures.beforeWrite('saveContactIdentity');
|
|
72
91
|
const key = this.getContactIdentityKey(address, identityType);
|
|
73
92
|
const existing = this.contactIdentities.get(key) ?? null;
|
|
74
93
|
const status = evaluateContactIdentityCandidate(existing, identity, suppliedCommitment);
|
|
75
94
|
if (status === 'NEW') {
|
|
76
|
-
this.contactIdentities.set(key, createUnverifiedContactIdentityRecord(identity, Date.now()));
|
|
95
|
+
this.contactIdentities.set(key, cloneStored(createUnverifiedContactIdentityRecord(identity, Date.now())));
|
|
77
96
|
return IdentityKeyChange.NEW_IDENTITY;
|
|
78
97
|
}
|
|
79
98
|
if (status === 'MATCH')
|
|
@@ -93,6 +112,7 @@ export class MockSignalStore {
|
|
|
93
112
|
return await this.acceptContactIdentityRotationAndDeleteSessions(address, identity, identityType, suppliedCommitment);
|
|
94
113
|
}
|
|
95
114
|
async acceptContactIdentityRotationAndDeleteSessions(address, identity, identityType, suppliedCommitment) {
|
|
115
|
+
this.failures.beforeWrite('acceptContactIdentityRotationAndDeleteSessions');
|
|
96
116
|
const key = this.getContactIdentityKey(address, identityType);
|
|
97
117
|
const existing = this.contactIdentities.get(key);
|
|
98
118
|
if (!existing)
|
|
@@ -105,18 +125,19 @@ export class MockSignalStore {
|
|
|
105
125
|
return states.some((state) => state?.remoteAddress?.userId === address.userId);
|
|
106
126
|
})
|
|
107
127
|
.map(([sessionKey]) => sessionKey);
|
|
108
|
-
this.contactIdentities.set(key, replacement);
|
|
128
|
+
this.contactIdentities.set(key, cloneStored(replacement));
|
|
109
129
|
for (const sessionKey of sessionKeys)
|
|
110
130
|
this.sessionRecords.delete(sessionKey);
|
|
111
131
|
return structuredClone(replacement);
|
|
112
132
|
}
|
|
113
133
|
async verifyContactIdentity(address, identity, identityType, suppliedCommitment) {
|
|
134
|
+
this.failures.beforeWrite('verifyContactIdentity');
|
|
114
135
|
const key = this.getContactIdentityKey(address, identityType);
|
|
115
136
|
const existing = this.contactIdentities.get(key);
|
|
116
137
|
if (!existing)
|
|
117
138
|
throw new Error('Cannot verify an unseen identity');
|
|
118
139
|
const verified = verifyContactIdentityRecord(existing, identity, Date.now(), suppliedCommitment);
|
|
119
|
-
this.contactIdentities.set(key, verified);
|
|
140
|
+
this.contactIdentities.set(key, cloneStored(verified));
|
|
120
141
|
return structuredClone(verified);
|
|
121
142
|
}
|
|
122
143
|
async isTrustedIdentity(address, identity, _direction, identityType) {
|
|
@@ -128,16 +149,18 @@ export class MockSignalStore {
|
|
|
128
149
|
// PreKey Management
|
|
129
150
|
// ============================================================================
|
|
130
151
|
async storeEcSignedPreKey(signedPreKey, identityType) {
|
|
152
|
+
this.failures.beforeWrite('storeEcSignedPreKey');
|
|
131
153
|
const it = identityType ?? 'aci';
|
|
132
154
|
// Store by identityType:keyId (supports multiple prekeys for grace period handling)
|
|
133
|
-
this.ecSignedPreKeys.set(`${it}:${signedPreKey.keyId}`, signedPreKey);
|
|
155
|
+
this.ecSignedPreKeys.set(`${it}:${signedPreKey.keyId}`, cloneStored(signedPreKey));
|
|
134
156
|
}
|
|
135
157
|
async getEcSignedPreKey(keyId, identityType) {
|
|
136
158
|
const it = identityType ?? 'aci';
|
|
137
159
|
const prefix = `${it}:`;
|
|
138
160
|
if (keyId !== undefined) {
|
|
139
161
|
// Look up by specific keyId
|
|
140
|
-
|
|
162
|
+
const preKey = this.ecSignedPreKeys.get(`${prefix}${keyId}`);
|
|
163
|
+
return preKey ? cloneStored(preKey) : null;
|
|
141
164
|
}
|
|
142
165
|
// Return the most recent EC signed prekey (highest keyId) for this identityType
|
|
143
166
|
let maxKeyId = -1;
|
|
@@ -151,7 +174,7 @@ export class MockSignalStore {
|
|
|
151
174
|
}
|
|
152
175
|
}
|
|
153
176
|
}
|
|
154
|
-
return result;
|
|
177
|
+
return result ? cloneStored(result) : null;
|
|
155
178
|
}
|
|
156
179
|
async getAllEcSignedPreKeys(identityType) {
|
|
157
180
|
const it = identityType ?? 'aci';
|
|
@@ -159,19 +182,21 @@ export class MockSignalStore {
|
|
|
159
182
|
const result = [];
|
|
160
183
|
for (const [key, value] of this.ecSignedPreKeys.entries()) {
|
|
161
184
|
if (key.startsWith(prefix)) {
|
|
162
|
-
result.push(value);
|
|
185
|
+
result.push(cloneStored(value));
|
|
163
186
|
}
|
|
164
187
|
}
|
|
165
188
|
return result;
|
|
166
189
|
}
|
|
167
190
|
async removeEcSignedPreKey(keyId, identityType) {
|
|
191
|
+
this.failures.beforeWrite('removeEcSignedPreKey');
|
|
168
192
|
const it = identityType ?? 'aci';
|
|
169
193
|
this.ecSignedPreKeys.delete(`${it}:${keyId}`);
|
|
170
194
|
}
|
|
171
195
|
async storeEcOneTimePreKeys(prekeys, identityType) {
|
|
196
|
+
this.failures.beforeWrite('storeEcOneTimePreKeys');
|
|
172
197
|
const it = identityType ?? 'aci';
|
|
173
198
|
for (const pk of prekeys) {
|
|
174
|
-
this.ecOneTimePreKeys.set(`${it}:${pk.keyId}`, pk);
|
|
199
|
+
this.ecOneTimePreKeys.set(`${it}:${pk.keyId}`, cloneStored(pk));
|
|
175
200
|
}
|
|
176
201
|
}
|
|
177
202
|
async getEcOneTimePreKeys(identityType) {
|
|
@@ -180,34 +205,39 @@ export class MockSignalStore {
|
|
|
180
205
|
const result = [];
|
|
181
206
|
for (const [key, value] of this.ecOneTimePreKeys.entries()) {
|
|
182
207
|
if (key.startsWith(prefix)) {
|
|
183
|
-
result.push(value);
|
|
208
|
+
result.push(cloneStored(value));
|
|
184
209
|
}
|
|
185
210
|
}
|
|
186
211
|
return result;
|
|
187
212
|
}
|
|
188
213
|
async removeEcOneTimePreKey(preKeyId, identityType) {
|
|
214
|
+
this.failures.beforeWrite('removeEcOneTimePreKey');
|
|
189
215
|
const it = identityType ?? 'aci';
|
|
190
216
|
this.ecOneTimePreKeys.delete(`${it}:${preKeyId}`);
|
|
191
217
|
}
|
|
192
218
|
async storeKyberPreKey(kyberPreKey, identityType) {
|
|
219
|
+
this.failures.beforeWrite('storeKyberPreKey');
|
|
193
220
|
const it = identityType ?? 'aci';
|
|
194
|
-
this.kyberPreKeys.set(it, kyberPreKey);
|
|
221
|
+
this.kyberPreKeys.set(it, cloneStored(kyberPreKey));
|
|
195
222
|
}
|
|
196
223
|
async getKyberPreKey(identityType) {
|
|
197
224
|
const it = identityType ?? 'aci';
|
|
198
|
-
|
|
225
|
+
const preKey = this.kyberPreKeys.get(it);
|
|
226
|
+
return preKey ? cloneStored(preKey) : null;
|
|
199
227
|
}
|
|
200
228
|
async markKyberPreKeyUsed(kyberPreKeyId, signedPreKeyId, baseKeyBytes, identityType) {
|
|
229
|
+
this.failures.beforeWrite('markKyberPreKeyUsed');
|
|
201
230
|
const it = identityType ?? 'aci';
|
|
202
|
-
this.kyberUsage.set(`${it}:${kyberPreKeyId}`, { signedPreKeyId, baseKeyBytes });
|
|
231
|
+
this.kyberUsage.set(`${it}:${kyberPreKeyId}`, cloneStored({ signedPreKeyId, baseKeyBytes }));
|
|
203
232
|
}
|
|
204
233
|
// ============================================================================
|
|
205
234
|
// KEM One-Time PreKey Management (Per-Session Post-Quantum Forward Secrecy)
|
|
206
235
|
// ============================================================================
|
|
207
236
|
async storeKemOneTimePreKeys(prekeys, identityType) {
|
|
237
|
+
this.failures.beforeWrite('storeKemOneTimePreKeys');
|
|
208
238
|
const it = identityType ?? 'aci';
|
|
209
239
|
for (const pk of prekeys) {
|
|
210
|
-
this.kemOneTimePreKeys.set(`${it}:${pk.keyId}`, pk);
|
|
240
|
+
this.kemOneTimePreKeys.set(`${it}:${pk.keyId}`, cloneStored(pk));
|
|
211
241
|
}
|
|
212
242
|
}
|
|
213
243
|
async getKemOneTimePreKeys(identityType) {
|
|
@@ -216,16 +246,18 @@ export class MockSignalStore {
|
|
|
216
246
|
const result = [];
|
|
217
247
|
for (const [key, value] of this.kemOneTimePreKeys.entries()) {
|
|
218
248
|
if (key.startsWith(prefix)) {
|
|
219
|
-
result.push(value);
|
|
249
|
+
result.push(cloneStored(value));
|
|
220
250
|
}
|
|
221
251
|
}
|
|
222
252
|
return result;
|
|
223
253
|
}
|
|
224
254
|
async getKemOneTimePreKey(keyId, identityType) {
|
|
225
255
|
const it = identityType ?? 'aci';
|
|
226
|
-
|
|
256
|
+
const preKey = this.kemOneTimePreKeys.get(`${it}:${keyId}`);
|
|
257
|
+
return preKey ? cloneStored(preKey) : null;
|
|
227
258
|
}
|
|
228
259
|
async removeKemOneTimePreKey(keyId, identityType) {
|
|
260
|
+
this.failures.beforeWrite('removeKemOneTimePreKey');
|
|
229
261
|
const it = identityType ?? 'aci';
|
|
230
262
|
this.kemOneTimePreKeys.delete(`${it}:${keyId}`);
|
|
231
263
|
}
|
|
@@ -247,11 +279,13 @@ export class MockSignalStore {
|
|
|
247
279
|
* Store session record
|
|
248
280
|
*/
|
|
249
281
|
async storeSessionRecord(address, record) {
|
|
282
|
+
this.failures.beforeWrite('storeSessionRecord');
|
|
250
283
|
assertCurrentSessionRecord(record);
|
|
251
284
|
const key = this.getAddressKey(address);
|
|
252
|
-
this.sessionRecords.set(key, record);
|
|
285
|
+
this.sessionRecords.set(key, cloneStored(record));
|
|
253
286
|
}
|
|
254
287
|
async commitSessionTrust(commit) {
|
|
288
|
+
this.failures.beforeWrite('commitSessionTrust');
|
|
255
289
|
assertCurrentSessionRecord(commit.record);
|
|
256
290
|
const sessionKey = this.getAddressKey(commit.address);
|
|
257
291
|
const contactKey = this.getContactIdentityKey(commit.address, commit.contactIdentityType);
|
|
@@ -277,8 +311,8 @@ export class MockSignalStore {
|
|
|
277
311
|
}
|
|
278
312
|
// Map mutations cannot fail after validation; this is one synchronous commit point.
|
|
279
313
|
if (newContact)
|
|
280
|
-
this.contactIdentities.set(contactKey, newContact);
|
|
281
|
-
this.sessionRecords.set(sessionKey, commit.record);
|
|
314
|
+
this.contactIdentities.set(contactKey, cloneStored(newContact));
|
|
315
|
+
this.sessionRecords.set(sessionKey, cloneStored(commit.record));
|
|
282
316
|
if (ecKey)
|
|
283
317
|
this.ecOneTimePreKeys.delete(ecKey);
|
|
284
318
|
if (kemKey)
|
|
@@ -295,7 +329,7 @@ export class MockSignalStore {
|
|
|
295
329
|
return null;
|
|
296
330
|
try {
|
|
297
331
|
assertCurrentSessionRecord(record);
|
|
298
|
-
return record;
|
|
332
|
+
return cloneStored(record);
|
|
299
333
|
}
|
|
300
334
|
catch {
|
|
301
335
|
this.sessionRecords.delete(key);
|
|
@@ -303,10 +337,12 @@ export class MockSignalStore {
|
|
|
303
337
|
}
|
|
304
338
|
}
|
|
305
339
|
async deleteSessionRecord(address) {
|
|
340
|
+
this.failures.beforeWrite('deleteSessionRecord');
|
|
306
341
|
const key = this.getAddressKey(address);
|
|
307
342
|
this.sessionRecords.delete(key);
|
|
308
343
|
}
|
|
309
344
|
async archiveCurrentSession(address, newSession) {
|
|
345
|
+
this.failures.beforeWrite('archiveCurrentSession');
|
|
310
346
|
// Per SESAME §3.2: "previously active session is moved to the head of the inactive sessions list"
|
|
311
347
|
// This preserves the old session for potential delayed message decryption
|
|
312
348
|
const key = this.getAddressKey(address);
|
|
@@ -316,11 +352,11 @@ export class MockSignalStore {
|
|
|
316
352
|
if (!record.archivedSessions) {
|
|
317
353
|
record.archivedSessions = {};
|
|
318
354
|
}
|
|
319
|
-
record.archivedSessions[record.currentSession.baseKey] = record.currentSession;
|
|
355
|
+
record.archivedSessions[record.currentSession.baseKey] = cloneStored(record.currentSession);
|
|
320
356
|
}
|
|
321
357
|
if (record) {
|
|
322
358
|
// Set new current session (may be null/undefined to clear)
|
|
323
|
-
record.currentSession = newSession
|
|
359
|
+
record.currentSession = newSession ? cloneStored(newSession) : null;
|
|
324
360
|
if (record.metadata)
|
|
325
361
|
record.metadata.lastSentAt = Date.now();
|
|
326
362
|
this.sessionRecords.set(key, record);
|
|
@@ -328,7 +364,7 @@ export class MockSignalStore {
|
|
|
328
364
|
else if (newSession) {
|
|
329
365
|
// Create new record with just the new session
|
|
330
366
|
this.sessionRecords.set(key, {
|
|
331
|
-
currentSession: newSession,
|
|
367
|
+
currentSession: cloneStored(newSession),
|
|
332
368
|
archivedSessions: {},
|
|
333
369
|
version: CURRENT_SESSION_RECORD_VERSION,
|
|
334
370
|
});
|
|
@@ -341,7 +377,7 @@ export class MockSignalStore {
|
|
|
341
377
|
if (key.startsWith(`${userId}.`) || key === userId) {
|
|
342
378
|
try {
|
|
343
379
|
assertCurrentSessionRecord(record);
|
|
344
|
-
sessions.push(record);
|
|
380
|
+
sessions.push(cloneStored(record));
|
|
345
381
|
}
|
|
346
382
|
catch {
|
|
347
383
|
this.sessionRecords.delete(key);
|
|
@@ -362,18 +398,21 @@ export class MockSignalStore {
|
|
|
362
398
|
// ============================================================================
|
|
363
399
|
async getDatabaseKey() {
|
|
364
400
|
if (!this.databaseKey) {
|
|
401
|
+
this.failures.beforeWrite('getDatabaseKey');
|
|
365
402
|
this.databaseKey = await generateRandomBytes(32);
|
|
366
403
|
}
|
|
367
|
-
return this.databaseKey;
|
|
404
|
+
return cloneStored(this.databaseKey);
|
|
368
405
|
}
|
|
369
406
|
// ============================================================================
|
|
370
407
|
// SESAME Multi-Device Session Management
|
|
371
408
|
// ============================================================================
|
|
372
409
|
async getUserRecord(userId) {
|
|
373
|
-
|
|
410
|
+
const record = this.sesameUserRecords.get(userId);
|
|
411
|
+
return record ? cloneStored(record) : null;
|
|
374
412
|
}
|
|
375
413
|
async setUserRecord(userId, record) {
|
|
376
|
-
this.
|
|
414
|
+
this.failures.beforeWrite('setUserRecord');
|
|
415
|
+
this.sesameUserRecords.set(userId, cloneStored(record));
|
|
377
416
|
}
|
|
378
417
|
async getDeviceRecord(userId, deviceId) {
|
|
379
418
|
// Try live session record first for up-to-date state (SPQR epochs, DH ratchet keys)
|
|
@@ -383,7 +422,7 @@ export class MockSignalStore {
|
|
|
383
422
|
const stored = this.sesameUserRecords.get(userId)?.devices.get(deviceId);
|
|
384
423
|
if (sessionRecord) {
|
|
385
424
|
const now = Date.now();
|
|
386
|
-
return {
|
|
425
|
+
return cloneStored({
|
|
387
426
|
userId,
|
|
388
427
|
deviceId,
|
|
389
428
|
// Session state is re-read from the live session record, but the
|
|
@@ -405,21 +444,24 @@ export class MockSignalStore {
|
|
|
405
444
|
session: sessionRecord,
|
|
406
445
|
createdAt: sessionRecord.metadata?.createdAt ?? now,
|
|
407
446
|
updatedAt: now,
|
|
408
|
-
};
|
|
447
|
+
});
|
|
409
448
|
}
|
|
410
449
|
// Fall back to sesameUserRecords for device records without active sessions
|
|
411
450
|
const userRecord = this.sesameUserRecords.get(userId);
|
|
412
451
|
if (!userRecord)
|
|
413
452
|
return null;
|
|
414
|
-
|
|
453
|
+
const record = userRecord.devices.get(deviceId);
|
|
454
|
+
return record ? cloneStored(record) : null;
|
|
415
455
|
}
|
|
416
456
|
async setDeviceRecord(userId, deviceId, record) {
|
|
457
|
+
this.failures.beforeWrite('setDeviceRecord');
|
|
417
458
|
const address = { userId, deviceId };
|
|
459
|
+
const storedRecord = cloneStored(record);
|
|
418
460
|
// Store session directly to sessionRecords (preserving exact data including metadata state)
|
|
419
461
|
// We write directly instead of through storeSessionRecord() to avoid metadata auto-generation
|
|
420
|
-
if (
|
|
462
|
+
if (storedRecord.session) {
|
|
421
463
|
const key = this.getAddressKey(address);
|
|
422
|
-
this.sessionRecords.set(key,
|
|
464
|
+
this.sessionRecords.set(key, cloneStored(storedRecord.session));
|
|
423
465
|
}
|
|
424
466
|
// Also keep sesameUserRecords in sync for getUserRecord()
|
|
425
467
|
let userRecord = this.sesameUserRecords.get(userId);
|
|
@@ -432,13 +474,14 @@ export class MockSignalStore {
|
|
|
432
474
|
};
|
|
433
475
|
this.sesameUserRecords.set(userId, userRecord);
|
|
434
476
|
}
|
|
435
|
-
userRecord.devices.set(deviceId,
|
|
477
|
+
userRecord.devices.set(deviceId, storedRecord);
|
|
436
478
|
userRecord.updatedAt = Date.now();
|
|
437
479
|
}
|
|
438
480
|
async deleteDeviceRecord(userId, deviceId) {
|
|
481
|
+
this.failures.beforeWrite('deleteDeviceRecord');
|
|
439
482
|
// Delete session via canonical path (mirrors ExpoKeyStorageAdapter.deleteDeviceRecord)
|
|
440
483
|
const address = { userId, deviceId };
|
|
441
|
-
|
|
484
|
+
this.sessionRecords.delete(this.getAddressKey(address));
|
|
442
485
|
// Also clean up sesameUserRecords
|
|
443
486
|
const userRecord = this.sesameUserRecords.get(userId);
|
|
444
487
|
if (!userRecord)
|
|
@@ -464,6 +507,7 @@ export class MockSignalStore {
|
|
|
464
507
|
await this.setDeviceRecord(userId, deviceId, deviceRecord);
|
|
465
508
|
}
|
|
466
509
|
async deleteStaleRecords(maxLatency) {
|
|
510
|
+
this.failures.beforeWrite('deleteStaleRecords');
|
|
467
511
|
let deleted = 0;
|
|
468
512
|
const now = Date.now();
|
|
469
513
|
for (const [userId, userRecord] of this.sesameUserRecords.entries()) {
|
|
@@ -493,6 +537,7 @@ export class MockSignalStore {
|
|
|
493
537
|
return deleted;
|
|
494
538
|
}
|
|
495
539
|
async cleanupExpiredSessions(maxRecv) {
|
|
540
|
+
this.failures.beforeWrite('cleanupExpiredSessions');
|
|
496
541
|
let deleted = 0;
|
|
497
542
|
const now = Date.now();
|
|
498
543
|
for (const userRecord of this.sesameUserRecords.values()) {
|
|
@@ -550,6 +595,7 @@ export class MockSignalStore {
|
|
|
550
595
|
// Sender Keys Management (Group Messaging)
|
|
551
596
|
// ============================================================================
|
|
552
597
|
async storeSenderKey(groupId, userId, deviceId, state) {
|
|
598
|
+
this.failures.beforeWrite('storeSenderKey');
|
|
553
599
|
if (!this.senderKeys.has(groupId)) {
|
|
554
600
|
this.senderKeys.set(groupId, new Map());
|
|
555
601
|
}
|
|
@@ -558,7 +604,7 @@ export class MockSignalStore {
|
|
|
558
604
|
groupMap.set(userId, new Map());
|
|
559
605
|
}
|
|
560
606
|
const userMap = groupMap.get(userId);
|
|
561
|
-
userMap.set(deviceId, state);
|
|
607
|
+
userMap.set(deviceId, cloneStored(state));
|
|
562
608
|
}
|
|
563
609
|
async getSenderKey(groupId, userId, deviceId) {
|
|
564
610
|
const groupMap = this.senderKeys.get(groupId);
|
|
@@ -567,9 +613,11 @@ export class MockSignalStore {
|
|
|
567
613
|
const userMap = groupMap.get(userId);
|
|
568
614
|
if (!userMap)
|
|
569
615
|
return null;
|
|
570
|
-
|
|
616
|
+
const state = userMap.get(deviceId);
|
|
617
|
+
return state ? cloneStored(state) : null;
|
|
571
618
|
}
|
|
572
619
|
async deleteSenderKey(groupId, userId, deviceId) {
|
|
620
|
+
this.failures.beforeWrite('deleteSenderKey');
|
|
573
621
|
const groupMap = this.senderKeys.get(groupId);
|
|
574
622
|
if (!groupMap)
|
|
575
623
|
return;
|
|
@@ -594,12 +642,13 @@ export class MockSignalStore {
|
|
|
594
642
|
const allKeys = [];
|
|
595
643
|
for (const userMap of groupMap.values()) {
|
|
596
644
|
for (const state of userMap.values()) {
|
|
597
|
-
allKeys.push(state);
|
|
645
|
+
allKeys.push(cloneStored(state));
|
|
598
646
|
}
|
|
599
647
|
}
|
|
600
648
|
return allKeys;
|
|
601
649
|
}
|
|
602
650
|
async deleteAllSenderKeysForGroup(groupId) {
|
|
651
|
+
this.failures.beforeWrite('deleteAllSenderKeysForGroup');
|
|
603
652
|
const groupMap = this.senderKeys.get(groupId);
|
|
604
653
|
if (!groupMap)
|
|
605
654
|
return 0;
|
|
@@ -620,19 +669,27 @@ export class MockSignalStore {
|
|
|
620
669
|
return `${groupId}:${userId}:${deviceId}`;
|
|
621
670
|
}
|
|
622
671
|
async storeSenderKeyRecord(groupId, userId, deviceId, states) {
|
|
672
|
+
this.failures.beforeWrite('storeSenderKeyRecord');
|
|
623
673
|
if (states.length === 0)
|
|
624
674
|
return;
|
|
625
|
-
// Store current state
|
|
626
|
-
|
|
675
|
+
// Store current state without a second injected write boundary.
|
|
676
|
+
if (!this.senderKeys.has(groupId)) {
|
|
677
|
+
this.senderKeys.set(groupId, new Map());
|
|
678
|
+
}
|
|
679
|
+
const groupMap = this.senderKeys.get(groupId);
|
|
680
|
+
if (!groupMap.has(userId)) {
|
|
681
|
+
groupMap.set(userId, new Map());
|
|
682
|
+
}
|
|
683
|
+
groupMap.get(userId).set(deviceId, cloneStored(states[0]));
|
|
627
684
|
// Store the full record
|
|
628
685
|
const key = this.getSenderKeyRecordKey(groupId, userId, deviceId);
|
|
629
|
-
this.senderKeyRecords.set(key,
|
|
686
|
+
this.senderKeyRecords.set(key, cloneStored(states));
|
|
630
687
|
}
|
|
631
688
|
async getSenderKeyRecord(groupId, userId, deviceId) {
|
|
632
689
|
const key = this.getSenderKeyRecordKey(groupId, userId, deviceId);
|
|
633
690
|
const record = this.senderKeyRecords.get(key);
|
|
634
691
|
if (record)
|
|
635
|
-
return
|
|
692
|
+
return cloneStored(record);
|
|
636
693
|
// Fall back to current state only
|
|
637
694
|
const currentState = await this.getSenderKey(groupId, userId, deviceId);
|
|
638
695
|
if (!currentState)
|
|
@@ -646,18 +703,22 @@ export class MockSignalStore {
|
|
|
646
703
|
return `${groupId}:${senderId}:${senderDeviceId}:${chainIndex}`;
|
|
647
704
|
}
|
|
648
705
|
async storeSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex, messageKey) {
|
|
706
|
+
this.failures.beforeWrite('storeSkippedSenderKey');
|
|
649
707
|
const key = this.getSkippedKeyId(groupId, senderId, senderDeviceId, chainIndex);
|
|
650
|
-
this.skippedSenderKeys.set(key, messageKey);
|
|
708
|
+
this.skippedSenderKeys.set(key, cloneStored(messageKey));
|
|
651
709
|
}
|
|
652
710
|
async getSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex) {
|
|
653
711
|
const key = this.getSkippedKeyId(groupId, senderId, senderDeviceId, chainIndex);
|
|
654
|
-
|
|
712
|
+
const messageKey = this.skippedSenderKeys.get(key);
|
|
713
|
+
return messageKey ? cloneStored(messageKey) : null;
|
|
655
714
|
}
|
|
656
715
|
async deleteSkippedSenderKey(groupId, senderId, senderDeviceId, chainIndex) {
|
|
716
|
+
this.failures.beforeWrite('deleteSkippedSenderKey');
|
|
657
717
|
const key = this.getSkippedKeyId(groupId, senderId, senderDeviceId, chainIndex);
|
|
658
718
|
this.skippedSenderKeys.delete(key);
|
|
659
719
|
}
|
|
660
720
|
async countSkippedSenderKeys(groupId, senderId, senderDeviceId) {
|
|
721
|
+
this.failures.beforeWrite('deleteOldestSkippedSenderKeys');
|
|
661
722
|
const prefix = `${groupId}:${senderId}:${senderDeviceId}:`;
|
|
662
723
|
let count = 0;
|
|
663
724
|
for (const key of this.skippedSenderKeys.keys()) {
|
|
@@ -695,8 +756,9 @@ export class MockSignalStore {
|
|
|
695
756
|
return `${sessionId}:${timestamp}`;
|
|
696
757
|
}
|
|
697
758
|
async storeMessageRecord(record) {
|
|
759
|
+
this.failures.beforeWrite('storeMessageRecord');
|
|
698
760
|
const key = this.getMessageRecordKey(record.sessionId, record.timestamp);
|
|
699
|
-
this.messageRecords.set(key,
|
|
761
|
+
this.messageRecords.set(key, cloneStored(record));
|
|
700
762
|
}
|
|
701
763
|
/**
|
|
702
764
|
* Get a message record by session and timestamp (PRIMARY method).
|
|
@@ -705,16 +767,18 @@ export class MockSignalStore {
|
|
|
705
767
|
async getMessageRecord(sessionId, timestamp) {
|
|
706
768
|
const key = this.getMessageRecordKey(sessionId, timestamp);
|
|
707
769
|
const record = this.messageRecords.get(key);
|
|
708
|
-
return record ?
|
|
770
|
+
return record ? cloneStored(record) : null;
|
|
709
771
|
}
|
|
710
772
|
/**
|
|
711
773
|
* Delete a message record by session and timestamp (PRIMARY method).
|
|
712
774
|
*/
|
|
713
775
|
async deleteMessageRecord(sessionId, timestamp) {
|
|
776
|
+
this.failures.beforeWrite('deleteMessageRecord');
|
|
714
777
|
const key = this.getMessageRecordKey(sessionId, timestamp);
|
|
715
778
|
this.messageRecords.delete(key);
|
|
716
779
|
}
|
|
717
780
|
async deleteExpiredMessageRecords(maxAgeMs) {
|
|
781
|
+
this.failures.beforeWrite('deleteExpiredMessageRecords');
|
|
718
782
|
const cutoff = Date.now() - maxAgeMs;
|
|
719
783
|
let deleted = 0;
|
|
720
784
|
for (const [key, record] of this.messageRecords.entries()) {
|
|
@@ -726,11 +790,13 @@ export class MockSignalStore {
|
|
|
726
790
|
return deleted;
|
|
727
791
|
}
|
|
728
792
|
async clearAllMessageRecords() {
|
|
793
|
+
this.failures.beforeWrite('clearAllMessageRecords');
|
|
729
794
|
const count = this.messageRecords.size;
|
|
730
795
|
this.messageRecords.clear();
|
|
731
796
|
return count;
|
|
732
797
|
}
|
|
733
798
|
async deleteMessageRecordsForSession(sessionId) {
|
|
799
|
+
this.failures.beforeWrite('deleteMessageRecordsForSession');
|
|
734
800
|
let deleted = 0;
|
|
735
801
|
for (const [key, record] of this.messageRecords.entries()) {
|
|
736
802
|
if (record.sessionId === sessionId) {
|
|
@@ -744,6 +810,7 @@ export class MockSignalStore {
|
|
|
744
810
|
// Utility
|
|
745
811
|
// ============================================================================
|
|
746
812
|
async clearAllKeys() {
|
|
813
|
+
this.failures.beforeWrite('clearAllKeys');
|
|
747
814
|
this.identityKeys.clear();
|
|
748
815
|
this.registrationIds.clear();
|
|
749
816
|
this.contactIdentities.clear();
|
|
@@ -768,6 +835,7 @@ export class MockSignalStore {
|
|
|
768
835
|
return this._metadata.get(key) ?? null;
|
|
769
836
|
}
|
|
770
837
|
async setMetadata(key, value) {
|
|
838
|
+
this.failures.beforeWrite('setMetadata');
|
|
771
839
|
this._metadata.set(key, value);
|
|
772
840
|
}
|
|
773
841
|
// ============================================================================
|
|
@@ -813,6 +881,7 @@ export class MockSignalStore {
|
|
|
813
881
|
* @returns Counts of deleted prekeys by type
|
|
814
882
|
*/
|
|
815
883
|
async deleteAllPreKeys(identityType) {
|
|
884
|
+
this.failures.beforeWrite('deleteAllPreKeys');
|
|
816
885
|
const it = identityType ?? 'aci';
|
|
817
886
|
const prefix = `${it}:`;
|
|
818
887
|
let ecSignedPreKeysCount = 0;
|
|
@@ -856,6 +925,7 @@ export class MockSignalStore {
|
|
|
856
925
|
* Used during force key reset.
|
|
857
926
|
*/
|
|
858
927
|
async clearAllSessions() {
|
|
928
|
+
this.failures.beforeWrite('clearAllSessions');
|
|
859
929
|
this.sessionRecords.clear();
|
|
860
930
|
this.sesameUserRecords.clear();
|
|
861
931
|
}
|