cojson 0.19.22 → 0.20.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +66 -0
- package/dist/PeerState.d.ts +6 -1
- package/dist/PeerState.d.ts.map +1 -1
- package/dist/PeerState.js +18 -3
- package/dist/PeerState.js.map +1 -1
- package/dist/coValueContentMessage.d.ts +0 -2
- package/dist/coValueContentMessage.d.ts.map +1 -1
- package/dist/coValueContentMessage.js +0 -8
- package/dist/coValueContentMessage.js.map +1 -1
- package/dist/coValueCore/SessionMap.d.ts +4 -2
- package/dist/coValueCore/SessionMap.d.ts.map +1 -1
- package/dist/coValueCore/SessionMap.js +30 -0
- package/dist/coValueCore/SessionMap.js.map +1 -1
- package/dist/coValueCore/coValueCore.d.ts +70 -5
- package/dist/coValueCore/coValueCore.d.ts.map +1 -1
- package/dist/coValueCore/coValueCore.js +302 -31
- package/dist/coValueCore/coValueCore.js.map +1 -1
- package/dist/coValueCore/verifiedState.d.ts +6 -1
- package/dist/coValueCore/verifiedState.d.ts.map +1 -1
- package/dist/coValueCore/verifiedState.js +9 -0
- package/dist/coValueCore/verifiedState.js.map +1 -1
- package/dist/coValues/coList.d.ts +4 -2
- package/dist/coValues/coList.d.ts.map +1 -1
- package/dist/coValues/coList.js +3 -0
- package/dist/coValues/coList.js.map +1 -1
- package/dist/coValues/group.d.ts.map +1 -1
- package/dist/coValues/group.js +3 -6
- package/dist/coValues/group.js.map +1 -1
- package/dist/config.d.ts +2 -8
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -12
- package/dist/config.js.map +1 -1
- package/dist/crypto/NapiCrypto.d.ts +1 -2
- package/dist/crypto/NapiCrypto.d.ts.map +1 -1
- package/dist/crypto/NapiCrypto.js +19 -4
- package/dist/crypto/NapiCrypto.js.map +1 -1
- package/dist/crypto/RNCrypto.d.ts.map +1 -1
- package/dist/crypto/RNCrypto.js +19 -4
- package/dist/crypto/RNCrypto.js.map +1 -1
- package/dist/crypto/WasmCrypto.d.ts +11 -4
- package/dist/crypto/WasmCrypto.d.ts.map +1 -1
- package/dist/crypto/WasmCrypto.js +52 -10
- package/dist/crypto/WasmCrypto.js.map +1 -1
- package/dist/crypto/WasmCryptoEdge.d.ts +1 -0
- package/dist/crypto/WasmCryptoEdge.d.ts.map +1 -1
- package/dist/crypto/WasmCryptoEdge.js +4 -1
- package/dist/crypto/WasmCryptoEdge.js.map +1 -1
- package/dist/crypto/crypto.d.ts +3 -3
- package/dist/crypto/crypto.d.ts.map +1 -1
- package/dist/crypto/crypto.js +6 -1
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/exports.d.ts +5 -5
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js +4 -3
- package/dist/exports.js.map +1 -1
- package/dist/ids.d.ts +4 -1
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +4 -0
- package/dist/ids.js.map +1 -1
- package/dist/knownState.d.ts +2 -0
- package/dist/knownState.d.ts.map +1 -1
- package/dist/localNode.d.ts +12 -0
- package/dist/localNode.d.ts.map +1 -1
- package/dist/localNode.js +14 -0
- package/dist/localNode.js.map +1 -1
- package/dist/platformUtils.d.ts +3 -0
- package/dist/platformUtils.d.ts.map +1 -0
- package/dist/platformUtils.js +24 -0
- package/dist/platformUtils.js.map +1 -0
- package/dist/queue/LinkedList.d.ts +9 -3
- package/dist/queue/LinkedList.d.ts.map +1 -1
- package/dist/queue/LinkedList.js +30 -1
- package/dist/queue/LinkedList.js.map +1 -1
- package/dist/queue/OutgoingLoadQueue.d.ts +95 -0
- package/dist/queue/OutgoingLoadQueue.d.ts.map +1 -0
- package/dist/queue/OutgoingLoadQueue.js +240 -0
- package/dist/queue/OutgoingLoadQueue.js.map +1 -0
- package/dist/storage/DeletedCoValuesEraserScheduler.d.ts +30 -0
- package/dist/storage/DeletedCoValuesEraserScheduler.d.ts.map +1 -0
- package/dist/storage/DeletedCoValuesEraserScheduler.js +84 -0
- package/dist/storage/DeletedCoValuesEraserScheduler.js.map +1 -0
- package/dist/storage/sqlite/client.d.ts +3 -0
- package/dist/storage/sqlite/client.d.ts.map +1 -1
- package/dist/storage/sqlite/client.js +44 -0
- package/dist/storage/sqlite/client.js.map +1 -1
- package/dist/storage/sqlite/sqliteMigrations.d.ts.map +1 -1
- package/dist/storage/sqlite/sqliteMigrations.js +7 -0
- package/dist/storage/sqlite/sqliteMigrations.js.map +1 -1
- package/dist/storage/sqliteAsync/client.d.ts +3 -0
- package/dist/storage/sqliteAsync/client.d.ts.map +1 -1
- package/dist/storage/sqliteAsync/client.js +42 -0
- package/dist/storage/sqliteAsync/client.js.map +1 -1
- package/dist/storage/storageAsync.d.ts +7 -0
- package/dist/storage/storageAsync.d.ts.map +1 -1
- package/dist/storage/storageAsync.js +48 -0
- package/dist/storage/storageAsync.js.map +1 -1
- package/dist/storage/storageSync.d.ts +6 -0
- package/dist/storage/storageSync.d.ts.map +1 -1
- package/dist/storage/storageSync.js +42 -0
- package/dist/storage/storageSync.js.map +1 -1
- package/dist/storage/types.d.ts +59 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/types.js +12 -1
- package/dist/storage/types.js.map +1 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +66 -43
- package/dist/sync.js.map +1 -1
- package/dist/tests/DeletedCoValuesEraserScheduler.test.d.ts +2 -0
- package/dist/tests/DeletedCoValuesEraserScheduler.test.d.ts.map +1 -0
- package/dist/tests/DeletedCoValuesEraserScheduler.test.js +149 -0
- package/dist/tests/DeletedCoValuesEraserScheduler.test.js.map +1 -0
- package/dist/tests/GarbageCollector.test.js +5 -6
- package/dist/tests/GarbageCollector.test.js.map +1 -1
- package/dist/tests/LinkedList.test.js +90 -0
- package/dist/tests/LinkedList.test.js.map +1 -1
- package/dist/tests/OutgoingLoadQueue.test.d.ts +2 -0
- package/dist/tests/OutgoingLoadQueue.test.d.ts.map +1 -0
- package/dist/tests/OutgoingLoadQueue.test.js +814 -0
- package/dist/tests/OutgoingLoadQueue.test.js.map +1 -0
- package/dist/tests/StorageApiAsync.test.js +484 -152
- package/dist/tests/StorageApiAsync.test.js.map +1 -1
- package/dist/tests/StorageApiSync.test.js +505 -136
- package/dist/tests/StorageApiSync.test.js.map +1 -1
- package/dist/tests/WasmCrypto.test.js +6 -3
- package/dist/tests/WasmCrypto.test.js.map +1 -1
- package/dist/tests/coValueCore.loadFromStorage.test.js +3 -0
- package/dist/tests/coValueCore.loadFromStorage.test.js.map +1 -1
- package/dist/tests/coValueCore.test.js +34 -13
- package/dist/tests/coValueCore.test.js.map +1 -1
- package/dist/tests/coreWasm.test.js +127 -4
- package/dist/tests/coreWasm.test.js.map +1 -1
- package/dist/tests/crypto.test.js +89 -93
- package/dist/tests/crypto.test.js.map +1 -1
- package/dist/tests/deleteCoValue.test.d.ts +2 -0
- package/dist/tests/deleteCoValue.test.d.ts.map +1 -0
- package/dist/tests/deleteCoValue.test.js +313 -0
- package/dist/tests/deleteCoValue.test.js.map +1 -0
- package/dist/tests/group.removeMember.test.js +18 -30
- package/dist/tests/group.removeMember.test.js.map +1 -1
- package/dist/tests/knownState.lazyLoading.test.js +3 -0
- package/dist/tests/knownState.lazyLoading.test.js.map +1 -1
- package/dist/tests/sync.concurrentLoad.test.d.ts +2 -0
- package/dist/tests/sync.concurrentLoad.test.d.ts.map +1 -0
- package/dist/tests/sync.concurrentLoad.test.js +481 -0
- package/dist/tests/sync.concurrentLoad.test.js.map +1 -0
- package/dist/tests/sync.deleted.test.d.ts +2 -0
- package/dist/tests/sync.deleted.test.d.ts.map +1 -0
- package/dist/tests/sync.deleted.test.js +214 -0
- package/dist/tests/sync.deleted.test.js.map +1 -0
- package/dist/tests/sync.mesh.test.js +3 -2
- package/dist/tests/sync.mesh.test.js.map +1 -1
- package/dist/tests/sync.storage.test.js +4 -3
- package/dist/tests/sync.storage.test.js.map +1 -1
- package/dist/tests/sync.test.js +3 -2
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/tests/testStorage.d.ts +3 -0
- package/dist/tests/testStorage.d.ts.map +1 -1
- package/dist/tests/testStorage.js +17 -1
- package/dist/tests/testStorage.js.map +1 -1
- package/dist/tests/testUtils.d.ts +7 -3
- package/dist/tests/testUtils.d.ts.map +1 -1
- package/dist/tests/testUtils.js +19 -4
- package/dist/tests/testUtils.js.map +1 -1
- package/package.json +6 -16
- package/src/PeerState.ts +26 -3
- package/src/coValueContentMessage.ts +0 -14
- package/src/coValueCore/SessionMap.ts +43 -1
- package/src/coValueCore/coValueCore.ts +415 -27
- package/src/coValueCore/verifiedState.ts +26 -3
- package/src/coValues/coList.ts +9 -3
- package/src/coValues/group.ts +5 -6
- package/src/config.ts +4 -13
- package/src/crypto/NapiCrypto.ts +29 -13
- package/src/crypto/RNCrypto.ts +29 -11
- package/src/crypto/WasmCrypto.ts +67 -20
- package/src/crypto/WasmCryptoEdge.ts +5 -1
- package/src/crypto/crypto.ts +16 -4
- package/src/exports.ts +4 -2
- package/src/ids.ts +11 -1
- package/src/localNode.ts +15 -0
- package/src/platformUtils.ts +26 -0
- package/src/queue/LinkedList.ts +34 -4
- package/src/queue/OutgoingLoadQueue.ts +307 -0
- package/src/storage/DeletedCoValuesEraserScheduler.ts +124 -0
- package/src/storage/sqlite/client.ts +77 -0
- package/src/storage/sqlite/sqliteMigrations.ts +7 -0
- package/src/storage/sqliteAsync/client.ts +75 -0
- package/src/storage/storageAsync.ts +62 -0
- package/src/storage/storageSync.ts +58 -0
- package/src/storage/types.ts +69 -0
- package/src/sync.ts +78 -46
- package/src/tests/DeletedCoValuesEraserScheduler.test.ts +185 -0
- package/src/tests/GarbageCollector.test.ts +6 -10
- package/src/tests/LinkedList.test.ts +111 -0
- package/src/tests/OutgoingLoadQueue.test.ts +1129 -0
- package/src/tests/StorageApiAsync.test.ts +572 -162
- package/src/tests/StorageApiSync.test.ts +580 -143
- package/src/tests/WasmCrypto.test.ts +8 -3
- package/src/tests/coValueCore.loadFromStorage.test.ts +6 -0
- package/src/tests/coValueCore.test.ts +49 -14
- package/src/tests/coreWasm.test.ts +319 -10
- package/src/tests/crypto.test.ts +141 -150
- package/src/tests/deleteCoValue.test.ts +528 -0
- package/src/tests/group.removeMember.test.ts +35 -35
- package/src/tests/knownState.lazyLoading.test.ts +6 -0
- package/src/tests/sync.concurrentLoad.test.ts +650 -0
- package/src/tests/sync.deleted.test.ts +294 -0
- package/src/tests/sync.mesh.test.ts +5 -2
- package/src/tests/sync.storage.test.ts +6 -3
- package/src/tests/sync.test.ts +5 -2
- package/src/tests/testStorage.ts +31 -2
- package/src/tests/testUtils.ts +31 -10
- package/dist/crypto/PureJSCrypto.d.ts +0 -77
- package/dist/crypto/PureJSCrypto.d.ts.map +0 -1
- package/dist/crypto/PureJSCrypto.js +0 -236
- package/dist/crypto/PureJSCrypto.js.map +0 -1
- package/dist/tests/PureJSCrypto.test.d.ts +0 -2
- package/dist/tests/PureJSCrypto.test.d.ts.map +0 -1
- package/dist/tests/PureJSCrypto.test.js +0 -145
- package/dist/tests/PureJSCrypto.test.js.map +0 -1
- package/src/crypto/PureJSCrypto.ts +0 -429
- package/src/tests/PureJSCrypto.test.ts +0 -217
package/src/tests/crypto.test.ts
CHANGED
|
@@ -3,176 +3,167 @@ import { x25519 } from "@noble/curves/ed25519";
|
|
|
3
3
|
import { blake3 } from "@noble/hashes/blake3";
|
|
4
4
|
import { base58, base64url } from "@scure/base";
|
|
5
5
|
import { expect, test, vi } from "vitest";
|
|
6
|
-
import { PureJSCrypto } from "../crypto/PureJSCrypto.js";
|
|
7
6
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
8
7
|
import { SessionID } from "../ids.js";
|
|
9
8
|
import { stableStringify } from "../jsonStringify.js";
|
|
10
9
|
|
|
11
|
-
const
|
|
12
|
-
const pureJSCrypto = await PureJSCrypto.create();
|
|
13
|
-
|
|
14
|
-
[wasmCrypto, pureJSCrypto].forEach((crypto) => {
|
|
15
|
-
const name = crypto.constructor.name;
|
|
16
|
-
|
|
17
|
-
test(`Signatures round-trip and use stable stringify [${name}]`, () => {
|
|
18
|
-
const data = { b: "world", a: "hello" };
|
|
19
|
-
const signer = crypto.newRandomSigner();
|
|
20
|
-
const signature = crypto.sign(signer, data);
|
|
21
|
-
|
|
22
|
-
expect(signature).toMatch(/^signature_z/);
|
|
23
|
-
expect(
|
|
24
|
-
crypto.verify(
|
|
25
|
-
signature,
|
|
26
|
-
{ a: "hello", b: "world" },
|
|
27
|
-
crypto.getSignerID(signer),
|
|
28
|
-
),
|
|
29
|
-
).toBe(true);
|
|
30
|
-
});
|
|
10
|
+
const crypto = await WasmCrypto.create();
|
|
31
11
|
|
|
32
|
-
|
|
33
|
-
const data = { b: "world", a: "hello" };
|
|
34
|
-
const signer = crypto.newRandomSigner();
|
|
35
|
-
const signer2 = crypto.newRandomSigner();
|
|
36
|
-
const wrongSignature = crypto.sign(signer2, data);
|
|
12
|
+
const name = crypto.constructor.name;
|
|
37
13
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
test(`Signatures round-trip and use stable stringify [${name}]`, () => {
|
|
15
|
+
const data = { b: "world", a: "hello" };
|
|
16
|
+
const signer = crypto.newRandomSigner();
|
|
17
|
+
const signature = crypto.sign(signer, data);
|
|
42
18
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
} as const;
|
|
53
|
-
|
|
54
|
-
const sealed = crypto.seal({
|
|
55
|
-
message: data,
|
|
56
|
-
from: sender,
|
|
57
|
-
to: crypto.getSealerID(sealer),
|
|
58
|
-
nOnceMaterial,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(
|
|
62
|
-
crypto.unseal(sealed, sealer, crypto.getSealerID(sender), nOnceMaterial),
|
|
63
|
-
).toEqual(data);
|
|
64
|
-
expect(() =>
|
|
65
|
-
crypto.unseal(
|
|
66
|
-
sealed,
|
|
67
|
-
wrongSealer,
|
|
68
|
-
crypto.getSealerID(sender),
|
|
69
|
-
nOnceMaterial,
|
|
70
|
-
),
|
|
71
|
-
).toThrow(name === "PureJSCrypto" ? "invalid tag" : "Wrong tag");
|
|
72
|
-
|
|
73
|
-
// trying with wrong sealer secret, by hand
|
|
74
|
-
const nOnce = blake3(
|
|
75
|
-
new TextEncoder().encode(stableStringify(nOnceMaterial)),
|
|
76
|
-
).slice(0, 24);
|
|
77
|
-
const sealer3priv = base58.decode(
|
|
78
|
-
wrongSealer.substring("sealerSecret_z".length),
|
|
79
|
-
);
|
|
80
|
-
const senderPub = base58.decode(
|
|
81
|
-
crypto.getSealerID(sender).substring("sealer_z".length),
|
|
82
|
-
);
|
|
83
|
-
const sealedBytes = base64url.decode(sealed.substring("sealed_U".length));
|
|
84
|
-
const sharedSecret = x25519.getSharedSecret(sealer3priv, senderPub);
|
|
85
|
-
|
|
86
|
-
expect(() => {
|
|
87
|
-
const _ = xsalsa20poly1305(sharedSecret, nOnce).decrypt(sealedBytes);
|
|
88
|
-
}).toThrow("invalid tag");
|
|
89
|
-
});
|
|
19
|
+
expect(signature).toMatch(/^signature_z/);
|
|
20
|
+
expect(
|
|
21
|
+
crypto.verify(
|
|
22
|
+
signature,
|
|
23
|
+
{ a: "hello", b: "world" },
|
|
24
|
+
crypto.getSignerID(signer),
|
|
25
|
+
),
|
|
26
|
+
).toBe(true);
|
|
27
|
+
});
|
|
90
28
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
29
|
+
test(`Invalid signatures don't verify [${name}]`, () => {
|
|
30
|
+
const data = { b: "world", a: "hello" };
|
|
31
|
+
const signer = crypto.newRandomSigner();
|
|
32
|
+
const signer2 = crypto.newRandomSigner();
|
|
33
|
+
const wrongSignature = crypto.sign(signer2, data);
|
|
95
34
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
35
|
+
expect(crypto.verify(wrongSignature, data, crypto.getSignerID(signer))).toBe(
|
|
36
|
+
false,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test(`encrypting round-trips, but invalid receiver can't unseal [${name}]`, () => {
|
|
41
|
+
const data = { b: "world", a: "hello" };
|
|
42
|
+
const sender = crypto.newRandomSealer();
|
|
43
|
+
const sealer = crypto.newRandomSealer();
|
|
44
|
+
const wrongSealer = crypto.newRandomSealer();
|
|
45
|
+
|
|
46
|
+
const nOnceMaterial = {
|
|
47
|
+
in: "co_zTEST",
|
|
48
|
+
tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
const sealed = crypto.seal({
|
|
52
|
+
message: data,
|
|
53
|
+
from: sender,
|
|
54
|
+
to: crypto.getSealerID(sealer),
|
|
55
|
+
nOnceMaterial,
|
|
99
56
|
});
|
|
100
57
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
58
|
+
expect(
|
|
59
|
+
crypto.unseal(sealed, sealer, crypto.getSealerID(sender), nOnceMaterial),
|
|
60
|
+
).toEqual(data);
|
|
61
|
+
expect(() =>
|
|
62
|
+
crypto.unseal(
|
|
63
|
+
sealed,
|
|
64
|
+
wrongSealer,
|
|
65
|
+
crypto.getSealerID(sender),
|
|
66
|
+
nOnceMaterial,
|
|
67
|
+
),
|
|
68
|
+
).toThrow("Wrong tag");
|
|
69
|
+
|
|
70
|
+
// trying with wrong sealer secret, by hand
|
|
71
|
+
const nOnce = blake3(
|
|
72
|
+
new TextEncoder().encode(stableStringify(nOnceMaterial)),
|
|
73
|
+
).slice(0, 24);
|
|
74
|
+
const sealer3priv = base58.decode(
|
|
75
|
+
wrongSealer.substring("sealerSecret_z".length),
|
|
76
|
+
);
|
|
77
|
+
const senderPub = base58.decode(
|
|
78
|
+
crypto.getSealerID(sender).substring("sealer_z".length),
|
|
79
|
+
);
|
|
80
|
+
const sealedBytes = base64url.decode(sealed.substring("sealed_U".length));
|
|
81
|
+
const sharedSecret = x25519.getSharedSecret(sealer3priv, senderPub);
|
|
82
|
+
|
|
83
|
+
expect(() => {
|
|
84
|
+
const _ = xsalsa20poly1305(sharedSecret, nOnce).decrypt(sealedBytes);
|
|
85
|
+
}).toThrow("invalid tag");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test(`Hashing is deterministic [${name}]`, () => {
|
|
89
|
+
expect(crypto.secureHash({ b: "world", a: "hello" })).toEqual(
|
|
90
|
+
crypto.secureHash({ a: "hello", b: "world" }),
|
|
91
|
+
);
|
|
104
92
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
93
|
+
expect(crypto.shortHash({ b: "world", a: "hello" })).toEqual(
|
|
94
|
+
crypto.shortHash({ a: "hello", b: "world" }),
|
|
95
|
+
);
|
|
96
|
+
});
|
|
109
97
|
|
|
110
|
-
|
|
98
|
+
test(`Encryption of keySecrets round-trips [${name}]`, () => {
|
|
99
|
+
const toEncrypt = crypto.newRandomKeySecret();
|
|
100
|
+
const encrypting = crypto.newRandomKeySecret();
|
|
111
101
|
|
|
112
|
-
|
|
102
|
+
const keys = {
|
|
103
|
+
toEncrypt,
|
|
104
|
+
encrypting,
|
|
105
|
+
};
|
|
113
106
|
|
|
114
|
-
|
|
115
|
-
});
|
|
107
|
+
const encrypted = crypto.encryptKeySecret(keys);
|
|
116
108
|
|
|
117
|
-
|
|
118
|
-
const toEncrypt = crypto.newRandomKeySecret();
|
|
119
|
-
const encrypting = crypto.newRandomKeySecret();
|
|
120
|
-
const encryptingWrong = crypto.newRandomKeySecret();
|
|
109
|
+
const decrypted = crypto.decryptKeySecret(encrypted, encrypting.secret);
|
|
121
110
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
encrypting,
|
|
125
|
-
};
|
|
111
|
+
expect(decrypted).toEqual(toEncrypt.secret);
|
|
112
|
+
});
|
|
126
113
|
|
|
127
|
-
|
|
114
|
+
test(`Encryption of keySecrets doesn't decrypt with a wrong key [${name}]`, () => {
|
|
115
|
+
const toEncrypt = crypto.newRandomKeySecret();
|
|
116
|
+
const encrypting = crypto.newRandomKeySecret();
|
|
117
|
+
const encryptingWrong = crypto.newRandomKeySecret();
|
|
128
118
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
119
|
+
const keys = {
|
|
120
|
+
toEncrypt,
|
|
121
|
+
encrypting,
|
|
122
|
+
};
|
|
133
123
|
|
|
134
|
-
|
|
135
|
-
});
|
|
124
|
+
const encrypted = crypto.encryptKeySecret(keys);
|
|
136
125
|
|
|
137
|
-
|
|
138
|
-
const data = "not valid json";
|
|
139
|
-
const sender = crypto.newRandomSealer();
|
|
140
|
-
const sealer = crypto.newRandomSealer();
|
|
141
|
-
|
|
142
|
-
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
143
|
-
|
|
144
|
-
const nOnceMaterial = {
|
|
145
|
-
in: "co_zTEST",
|
|
146
|
-
tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
|
|
147
|
-
} as const;
|
|
148
|
-
|
|
149
|
-
// Create a sealed message with invalid JSON
|
|
150
|
-
const nOnce = blake3(
|
|
151
|
-
new TextEncoder().encode(stableStringify(nOnceMaterial)),
|
|
152
|
-
).slice(0, 24);
|
|
153
|
-
|
|
154
|
-
const senderPriv = base58.decode(sender.substring("sealerSecret_z".length));
|
|
155
|
-
const sealerPub = base58.decode(
|
|
156
|
-
crypto.getSealerID(sealer).substring("sealer_z".length),
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const plaintext = new TextEncoder().encode(data);
|
|
160
|
-
const sharedSecret = x25519.getSharedSecret(senderPriv, sealerPub);
|
|
161
|
-
const sealedBytes = xsalsa20poly1305(sharedSecret, nOnce).encrypt(
|
|
162
|
-
plaintext,
|
|
163
|
-
);
|
|
164
|
-
const sealed = `sealed_U${base64url.encode(sealedBytes)}`;
|
|
165
|
-
|
|
166
|
-
const result = crypto.unseal(
|
|
167
|
-
sealed as any,
|
|
168
|
-
sealer,
|
|
169
|
-
crypto.getSealerID(sender),
|
|
170
|
-
nOnceMaterial,
|
|
171
|
-
);
|
|
126
|
+
const decrypted = crypto.decryptKeySecret(encrypted, encryptingWrong.secret);
|
|
172
127
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
128
|
+
expect(decrypted).toBeUndefined();
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test(`Unsealing malformed JSON logs error [${name}]`, () => {
|
|
132
|
+
const data = "not valid json";
|
|
133
|
+
const sender = crypto.newRandomSealer();
|
|
134
|
+
const sealer = crypto.newRandomSealer();
|
|
135
|
+
|
|
136
|
+
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
137
|
+
|
|
138
|
+
const nOnceMaterial = {
|
|
139
|
+
in: "co_zTEST",
|
|
140
|
+
tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
|
|
141
|
+
} as const;
|
|
142
|
+
|
|
143
|
+
// Create a sealed message with invalid JSON
|
|
144
|
+
const nOnce = blake3(
|
|
145
|
+
new TextEncoder().encode(stableStringify(nOnceMaterial)),
|
|
146
|
+
).slice(0, 24);
|
|
147
|
+
|
|
148
|
+
const senderPriv = base58.decode(sender.substring("sealerSecret_z".length));
|
|
149
|
+
const sealerPub = base58.decode(
|
|
150
|
+
crypto.getSealerID(sealer).substring("sealer_z".length),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const plaintext = new TextEncoder().encode(data);
|
|
154
|
+
const sharedSecret = x25519.getSharedSecret(senderPriv, sealerPub);
|
|
155
|
+
const sealedBytes = xsalsa20poly1305(sharedSecret, nOnce).encrypt(plaintext);
|
|
156
|
+
const sealed = `sealed_U${base64url.encode(sealedBytes)}`;
|
|
157
|
+
|
|
158
|
+
const result = crypto.unseal(
|
|
159
|
+
sealed as any,
|
|
160
|
+
sealer,
|
|
161
|
+
crypto.getSealerID(sender),
|
|
162
|
+
nOnceMaterial,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(result).toBeUndefined();
|
|
166
|
+
expect(consoleSpy.mock.lastCall?.[0]).toContain(
|
|
167
|
+
"Failed to decrypt/parse sealed message",
|
|
168
|
+
);
|
|
178
169
|
});
|