cojson 0.8.12 → 0.8.17
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 +95 -83
- package/dist/native/PeerKnownStates.js +6 -1
- package/dist/native/PeerKnownStates.js.map +1 -1
- package/dist/native/PeerState.js +4 -3
- package/dist/native/PeerState.js.map +1 -1
- package/dist/native/PriorityBasedMessageQueue.js +1 -10
- package/dist/native/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/native/SyncStateSubscriptionManager.js +70 -0
- package/dist/native/SyncStateSubscriptionManager.js.map +1 -0
- package/dist/native/base64url.js.map +1 -1
- package/dist/native/base64url.test.js +1 -1
- package/dist/native/base64url.test.js.map +1 -1
- package/dist/native/coValue.js.map +1 -1
- package/dist/native/coValueCore.js +141 -149
- package/dist/native/coValueCore.js.map +1 -1
- package/dist/native/coValueState.js.map +1 -1
- package/dist/native/coValues/account.js +6 -6
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +2 -3
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +1 -1
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coStream.js +3 -5
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/group.js +11 -11
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coreToCoValue.js +2 -2
- package/dist/native/coreToCoValue.js.map +1 -1
- package/dist/native/crypto/PureJSCrypto.js +4 -4
- package/dist/native/crypto/PureJSCrypto.js.map +1 -1
- package/dist/native/crypto/crypto.js.map +1 -1
- package/dist/native/exports.js +12 -12
- package/dist/native/exports.js.map +1 -1
- package/dist/native/ids.js.map +1 -1
- package/dist/native/jsonStringify.js.map +1 -1
- package/dist/native/localNode.js +5 -7
- package/dist/native/localNode.js.map +1 -1
- package/dist/native/permissions.js +4 -7
- package/dist/native/permissions.js.map +1 -1
- package/dist/native/priority.js.map +1 -1
- package/dist/native/storage/FileSystem.js.map +1 -1
- package/dist/native/storage/chunksAndKnownStates.js +2 -4
- package/dist/native/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/native/storage/index.js +6 -15
- package/dist/native/storage/index.js.map +1 -1
- package/dist/native/streamUtils.js.map +1 -1
- package/dist/native/sync.js +57 -7
- package/dist/native/sync.js.map +1 -1
- package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/native/typeUtils/expectGroup.js.map +1 -1
- package/dist/native/typeUtils/isAccountID.js.map +1 -1
- package/dist/native/typeUtils/isCoValue.js +1 -1
- package/dist/native/typeUtils/isCoValue.js.map +1 -1
- package/dist/web/PeerKnownStates.js +6 -1
- package/dist/web/PeerKnownStates.js.map +1 -1
- package/dist/web/PeerState.js +4 -3
- package/dist/web/PeerState.js.map +1 -1
- package/dist/web/PriorityBasedMessageQueue.js +1 -10
- package/dist/web/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/web/SyncStateSubscriptionManager.js +70 -0
- package/dist/web/SyncStateSubscriptionManager.js.map +1 -0
- package/dist/web/base64url.js.map +1 -1
- package/dist/web/base64url.test.js +1 -1
- package/dist/web/base64url.test.js.map +1 -1
- package/dist/web/coValue.js.map +1 -1
- package/dist/web/coValueCore.js +141 -149
- package/dist/web/coValueCore.js.map +1 -1
- package/dist/web/coValueState.js.map +1 -1
- package/dist/web/coValues/account.js +6 -6
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +2 -3
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +1 -1
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coStream.js +3 -5
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/group.js +11 -11
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coreToCoValue.js +2 -2
- package/dist/web/coreToCoValue.js.map +1 -1
- package/dist/web/crypto/PureJSCrypto.js +4 -4
- package/dist/web/crypto/PureJSCrypto.js.map +1 -1
- package/dist/web/crypto/WasmCrypto.js +5 -5
- package/dist/web/crypto/WasmCrypto.js.map +1 -1
- package/dist/web/crypto/crypto.js.map +1 -1
- package/dist/web/exports.js +12 -12
- package/dist/web/exports.js.map +1 -1
- package/dist/web/ids.js.map +1 -1
- package/dist/web/jsonStringify.js.map +1 -1
- package/dist/web/localNode.js +5 -7
- package/dist/web/localNode.js.map +1 -1
- package/dist/web/permissions.js +4 -7
- package/dist/web/permissions.js.map +1 -1
- package/dist/web/priority.js.map +1 -1
- package/dist/web/storage/FileSystem.js.map +1 -1
- package/dist/web/storage/chunksAndKnownStates.js +2 -4
- package/dist/web/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/web/storage/index.js +6 -15
- package/dist/web/storage/index.js.map +1 -1
- package/dist/web/streamUtils.js.map +1 -1
- package/dist/web/sync.js +57 -7
- package/dist/web/sync.js.map +1 -1
- package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/web/typeUtils/expectGroup.js.map +1 -1
- package/dist/web/typeUtils/isAccountID.js.map +1 -1
- package/dist/web/typeUtils/isCoValue.js +1 -1
- package/dist/web/typeUtils/isCoValue.js.map +1 -1
- package/package.json +4 -14
- package/src/PeerKnownStates.ts +98 -90
- package/src/PeerState.ts +92 -73
- package/src/PriorityBasedMessageQueue.ts +42 -49
- package/src/SyncStateSubscriptionManager.ts +124 -0
- package/src/base64url.test.ts +24 -24
- package/src/base64url.ts +44 -45
- package/src/coValue.ts +45 -45
- package/src/coValueCore.ts +746 -785
- package/src/coValueState.ts +82 -72
- package/src/coValues/account.ts +143 -150
- package/src/coValues/coList.ts +520 -522
- package/src/coValues/coMap.ts +283 -285
- package/src/coValues/coStream.ts +320 -324
- package/src/coValues/group.ts +306 -305
- package/src/coreToCoValue.ts +28 -31
- package/src/crypto/PureJSCrypto.ts +188 -194
- package/src/crypto/WasmCrypto.ts +236 -254
- package/src/crypto/crypto.ts +302 -309
- package/src/exports.ts +116 -116
- package/src/ids.ts +9 -9
- package/src/jsonStringify.ts +46 -46
- package/src/jsonValue.ts +24 -10
- package/src/localNode.ts +635 -660
- package/src/media.ts +3 -3
- package/src/permissions.ts +272 -278
- package/src/priority.ts +21 -19
- package/src/storage/FileSystem.ts +91 -99
- package/src/storage/chunksAndKnownStates.ts +110 -115
- package/src/storage/index.ts +466 -497
- package/src/streamUtils.ts +60 -60
- package/src/sync.ts +656 -608
- package/src/tests/PeerKnownStates.test.ts +38 -34
- package/src/tests/PeerState.test.ts +101 -64
- package/src/tests/PriorityBasedMessageQueue.test.ts +91 -91
- package/src/tests/SyncStateSubscriptionManager.test.ts +232 -0
- package/src/tests/account.test.ts +59 -59
- package/src/tests/coList.test.ts +65 -65
- package/src/tests/coMap.test.ts +137 -137
- package/src/tests/coStream.test.ts +254 -257
- package/src/tests/coValueCore.test.ts +153 -156
- package/src/tests/crypto.test.ts +136 -144
- package/src/tests/cryptoImpl.test.ts +205 -197
- package/src/tests/group.test.ts +24 -24
- package/src/tests/permissions.test.ts +1306 -1371
- package/src/tests/priority.test.ts +65 -82
- package/src/tests/sync.test.ts +1573 -1263
- package/src/tests/testUtils.ts +85 -53
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +4 -4
- package/src/typeUtils/expectGroup.ts +9 -9
- package/src/typeUtils/isAccountID.ts +1 -1
- package/src/typeUtils/isCoValue.ts +9 -9
- package/tsconfig.json +4 -6
- package/tsconfig.native.json +9 -11
- package/tsconfig.web.json +4 -10
- package/.eslintrc.cjs +0 -25
- package/.prettierrc.js +0 -9
|
@@ -1,205 +1,213 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
3
2
|
import { PureJSCrypto } from "../crypto/PureJSCrypto.js";
|
|
4
|
-
import {
|
|
3
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
4
|
+
import { KeySecret, StreamingHash } from "../crypto/crypto.js";
|
|
5
5
|
import { SessionID } from "../ids.js";
|
|
6
6
|
|
|
7
7
|
describe.each([
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
{ impl: await WasmCrypto.create(), name: "Wasm" },
|
|
9
|
+
{ impl: await PureJSCrypto.create(), name: "PureJS" },
|
|
10
10
|
])("Crypto $name", ({ impl }) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
11
|
+
test("randomBytes", () => {
|
|
12
|
+
expect(impl.randomBytes(32).length).toEqual(32);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("blake3HashOnce", () => {
|
|
16
|
+
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
17
|
+
const hash = impl.blake3HashOnce(data);
|
|
18
|
+
// prettier-ignore
|
|
19
|
+
expect(hash).toEqual(
|
|
20
|
+
new Uint8Array([
|
|
21
|
+
2, 79, 103, 192, 66, 90, 61, 192, 47, 186, 245, 140, 185, 61, 229, 19,
|
|
22
|
+
46, 61, 117, 197, 25, 250, 160, 186, 218, 33, 73, 29, 136, 201, 112, 87,
|
|
23
|
+
]),
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("blake3HashOnceWithContext", () => {
|
|
28
|
+
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
29
|
+
const context = new Uint8Array([6, 7, 8, 9, 10]);
|
|
30
|
+
const hash = impl.blake3HashOnceWithContext(data, { context });
|
|
31
|
+
// prettier-ignore
|
|
32
|
+
expect(hash).toEqual(
|
|
33
|
+
new Uint8Array([
|
|
34
|
+
26, 197, 20, 5, 159, 115, 36, 109, 188, 32, 237, 183, 252, 248, 89, 48,
|
|
35
|
+
212, 51, 102, 180, 94, 56, 201, 33, 196, 52, 222, 121, 103, 112, 153,
|
|
36
|
+
98,
|
|
37
|
+
]),
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("incrementalBlake3", () => {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const state = impl.emptyBlake3State() as any;
|
|
44
|
+
const data = new Uint8Array([1, 2, 3, 4, 5]);
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
const state2 = impl.blake3IncrementalUpdate(state, data) as any;
|
|
47
|
+
expect(impl.blake3DigestForState(state2)).toEqual(
|
|
48
|
+
// prettier-ignore
|
|
49
|
+
new Uint8Array([
|
|
50
|
+
2, 79, 103, 192, 66, 90, 61, 192, 47, 186, 245, 140, 185, 61, 229, 19,
|
|
51
|
+
46, 61, 117, 197, 25, 250, 160, 186, 218, 33, 73, 29, 136, 201, 112, 87,
|
|
52
|
+
]),
|
|
53
|
+
);
|
|
54
|
+
const data2 = new Uint8Array([6, 7, 8, 9, 10]);
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
const state3 = impl.blake3IncrementalUpdate(state2, data2) as any;
|
|
57
|
+
expect(impl.blake3DigestForState(state3)).toEqual(
|
|
58
|
+
// prettier-ignore
|
|
59
|
+
new Uint8Array([
|
|
60
|
+
165, 131, 141, 69, 2, 69, 39, 236, 196, 244, 180, 213, 147, 124, 222,
|
|
61
|
+
39, 68, 223, 54, 176, 242, 97, 200, 101, 204, 79, 21, 233, 56, 51, 1,
|
|
62
|
+
199,
|
|
63
|
+
]),
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("newEd25519SigningKey", () => {
|
|
68
|
+
expect(impl.newEd25519SigningKey().length).toEqual(32);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("getSignerID", () => {
|
|
72
|
+
const secret = impl.signerSecretFromBytes(
|
|
73
|
+
new Uint8Array(Array.from({ length: 32 }, (_, i) => i * 2)),
|
|
74
|
+
);
|
|
75
|
+
const id = impl.getSignerID(secret);
|
|
76
|
+
expect(id).toEqual("signer_z8wDhwtSA2twZvmz8J3Df63TdCBxC7ta9hFASV9cZC9xw");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("sign and verify", () => {
|
|
80
|
+
const secret = impl.signerSecretFromBytes(
|
|
81
|
+
new Uint8Array(Array.from({ length: 32 }, (_, i) => i * 2)),
|
|
82
|
+
);
|
|
83
|
+
const wrongSecret = impl.signerSecretFromBytes(
|
|
84
|
+
new Uint8Array(
|
|
85
|
+
Array.from({ length: 32 }, (_, i) => (i === 0 ? 1 : i * 2)),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
const message = { foo: "bar" };
|
|
89
|
+
const wrongMessage = { foo: "baz" };
|
|
90
|
+
const signature = impl.sign(secret, message);
|
|
91
|
+
const wrongSignature = impl.sign(wrongSecret, message);
|
|
92
|
+
expect(signature).toEqual(
|
|
93
|
+
"signature_zHH7trJJ4iJFgYv9B8QtF96qcG7PbPJcfojy9ACtJc6z9FqzbJNM6xeqVLxCEK1oSj1oSYAgy2V3CW5SzjYDh8ax",
|
|
94
|
+
);
|
|
95
|
+
expect(
|
|
96
|
+
impl.verify(signature, message, impl.getSignerID(secret)),
|
|
97
|
+
).toBeTruthy();
|
|
98
|
+
expect(
|
|
99
|
+
impl.verify(wrongSignature, message, impl.getSignerID(secret)),
|
|
100
|
+
).toBeFalsy();
|
|
101
|
+
expect(
|
|
102
|
+
impl.verify(signature, wrongMessage, impl.getSignerID(secret)),
|
|
103
|
+
).toBeFalsy();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("newX25519StaticSecret", () => {
|
|
107
|
+
expect(impl.newX25519StaticSecret().length).toEqual(32);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("getSealerID", () => {
|
|
111
|
+
const secret = impl.sealerSecretFromBytes(
|
|
112
|
+
new Uint8Array(Array.from({ length: 32 }, (_, i) => i * 2)),
|
|
113
|
+
);
|
|
114
|
+
const id = impl.getSealerID(secret);
|
|
115
|
+
expect(id).toEqual("sealer_zBvzQipsgJZwgy4rN5dfnWQWQNrV4PnJpWfDjZkJ5iYqy");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("encrypt and decrypt", () => {
|
|
119
|
+
const secret: KeySecret =
|
|
120
|
+
"keySecret_zyRhQCZGM3LwEjB2nXTktyBQ56JiDBHbRtYjjddiugjT";
|
|
121
|
+
const data = { foo: "bar" };
|
|
122
|
+
const nOnceMaterial = { bar: "foo" };
|
|
123
|
+
const encrypted = impl.encrypt(data, secret, nOnceMaterial);
|
|
124
|
+
expect(encrypted).toEqual("encrypted_UDrVbWTATlj-ECtLqJQ==");
|
|
125
|
+
const decrypted = impl.decrypt(encrypted, secret, nOnceMaterial);
|
|
126
|
+
expect(decrypted).toEqual(data);
|
|
127
|
+
const wrongSecret =
|
|
128
|
+
"keySecret_zyRhQCZGM3LwEjB2nXTktyBQ56JiDBHbRtYjjddingjT";
|
|
129
|
+
expect(impl.decrypt(encrypted, wrongSecret, nOnceMaterial)).toBeUndefined();
|
|
130
|
+
const wrongNOnceMaterial = { bar: "baz" };
|
|
131
|
+
expect(impl.decrypt(encrypted, secret, wrongNOnceMaterial)).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("seal and unseal", () => {
|
|
135
|
+
const senderSecret =
|
|
136
|
+
"sealerSecret_zFffKAY7Ln5ouAbmC6K21N6uPs1RQXyhpcuQzK3kPWhhg";
|
|
137
|
+
const recipientSecret =
|
|
138
|
+
"sealerSecret_z3K6m9AHmEJeTrCQW4zY5vicneorj9sVQasA7E8FYvDQa";
|
|
139
|
+
const message = { foo: "bar" };
|
|
140
|
+
const nOnceMaterial = {
|
|
141
|
+
in: "co_zSomeCoValue" as const,
|
|
142
|
+
tx: {
|
|
143
|
+
sessionID: "co_zSomeAccount_session_zSomeSession" as SessionID,
|
|
144
|
+
txIndex: 42,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const sealed = impl.seal({
|
|
149
|
+
message,
|
|
150
|
+
from: senderSecret,
|
|
151
|
+
to: impl.getSealerID(recipientSecret),
|
|
152
|
+
nOnceMaterial,
|
|
122
153
|
});
|
|
123
154
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
test("StreamingHash clone", () => {
|
|
185
|
-
const originalHash = new StreamingHash(impl);
|
|
186
|
-
originalHash.update({ foo: "bar" });
|
|
187
|
-
|
|
188
|
-
const clonedHash = originalHash.clone();
|
|
189
|
-
|
|
190
|
-
// Update the original hash
|
|
191
|
-
originalHash.update({ baz: "qux" });
|
|
192
|
-
|
|
193
|
-
// Update the cloned hash differently
|
|
194
|
-
clonedHash.update({ quux: "corge" });
|
|
195
|
-
|
|
196
|
-
// The digests should be different
|
|
197
|
-
expect(originalHash.digest()).not.toEqual(clonedHash.digest());
|
|
198
|
-
|
|
199
|
-
// The cloned hash should match a new hash with the same updates
|
|
200
|
-
const newHash = new StreamingHash(impl);
|
|
201
|
-
newHash.update({ foo: "bar" });
|
|
202
|
-
newHash.update({ quux: "corge" });
|
|
203
|
-
expect(clonedHash.digest()).toEqual(newHash.digest());
|
|
204
|
-
});
|
|
155
|
+
expect(sealed).toEqual("sealed_UtuddAQjop6zMR47aI7HOqj-f0kR2tdFvRxzDe4I=");
|
|
156
|
+
|
|
157
|
+
const unsealed = impl.unseal(
|
|
158
|
+
sealed,
|
|
159
|
+
recipientSecret,
|
|
160
|
+
impl.getSealerID(senderSecret),
|
|
161
|
+
nOnceMaterial,
|
|
162
|
+
);
|
|
163
|
+
expect(unsealed).toEqual(message);
|
|
164
|
+
|
|
165
|
+
const wrongRecipientSecret =
|
|
166
|
+
"sealerSecret_zHV1Y1VPbc31B8bi7yw4oL5CPPnPFspKwUjkFErgJFuoB";
|
|
167
|
+
expect(() =>
|
|
168
|
+
impl.unseal(
|
|
169
|
+
sealed,
|
|
170
|
+
wrongRecipientSecret,
|
|
171
|
+
impl.getSealerID(senderSecret),
|
|
172
|
+
nOnceMaterial,
|
|
173
|
+
),
|
|
174
|
+
).toThrow();
|
|
175
|
+
const wrongNOnceMaterial = {
|
|
176
|
+
in: "co_zSomeCoValue" as const,
|
|
177
|
+
tx: {
|
|
178
|
+
sessionID: "co_zSomeAccount_session_zSomeSession" as SessionID,
|
|
179
|
+
txIndex: 43,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
expect(() =>
|
|
183
|
+
impl.unseal(
|
|
184
|
+
sealed,
|
|
185
|
+
recipientSecret,
|
|
186
|
+
impl.getSealerID(senderSecret),
|
|
187
|
+
wrongNOnceMaterial,
|
|
188
|
+
),
|
|
189
|
+
).toThrow();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("StreamingHash clone", () => {
|
|
193
|
+
const originalHash = new StreamingHash(impl);
|
|
194
|
+
originalHash.update({ foo: "bar" });
|
|
195
|
+
|
|
196
|
+
const clonedHash = originalHash.clone();
|
|
197
|
+
|
|
198
|
+
// Update the original hash
|
|
199
|
+
originalHash.update({ baz: "qux" });
|
|
200
|
+
|
|
201
|
+
// Update the cloned hash differently
|
|
202
|
+
clonedHash.update({ quux: "corge" });
|
|
203
|
+
|
|
204
|
+
// The digests should be different
|
|
205
|
+
expect(originalHash.digest()).not.toEqual(clonedHash.digest());
|
|
206
|
+
|
|
207
|
+
// The cloned hash should match a new hash with the same updates
|
|
208
|
+
const newHash = new StreamingHash(impl);
|
|
209
|
+
newHash.update({ foo: "bar" });
|
|
210
|
+
newHash.update({ quux: "corge" });
|
|
211
|
+
expect(clonedHash.digest()).toEqual(newHash.digest());
|
|
212
|
+
});
|
|
205
213
|
});
|
package/src/tests/group.test.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
-
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
3
|
-
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
4
|
-
import { LocalNode } from "../localNode.js";
|
|
5
2
|
import { RawCoList } from "../coValues/coList.js";
|
|
6
3
|
import { RawCoMap } from "../coValues/coMap.js";
|
|
7
4
|
import { RawCoStream } from "../coValues/coStream.js";
|
|
8
5
|
import { RawBinaryCoStream } from "../coValues/coStream.js";
|
|
6
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
7
|
+
import { LocalNode } from "../localNode.js";
|
|
8
|
+
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
9
9
|
|
|
10
10
|
const Crypto = await WasmCrypto.create();
|
|
11
11
|
|
|
12
12
|
test("Can create a RawCoMap in a group", () => {
|
|
13
|
-
|
|
13
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const group = node.createGroup();
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const map = group.createMap();
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
expect(map.core.getCurrentContent().type).toEqual("comap");
|
|
20
|
+
expect(map instanceof RawCoMap).toEqual(true);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test("Can create a CoList in a group", () => {
|
|
24
|
-
|
|
24
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
const group = node.createGroup();
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const list = group.createList();
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
expect(list.core.getCurrentContent().type).toEqual("colist");
|
|
31
|
+
expect(list instanceof RawCoList).toEqual(true);
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
test("Can create a CoStream in a group", () => {
|
|
35
|
-
|
|
35
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const group = node.createGroup();
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const stream = group.createStream();
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
expect(stream.core.getCurrentContent().type).toEqual("costream");
|
|
42
|
+
expect(stream instanceof RawCoStream).toEqual(true);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
test("Can create a BinaryCoStream in a group", () => {
|
|
46
|
-
|
|
46
|
+
const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const group = node.createGroup();
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
const stream = group.createBinaryStream();
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
expect(stream.core.getCurrentContent().type).toEqual("costream");
|
|
53
|
+
expect(stream.headerMeta.type).toEqual("binary");
|
|
54
|
+
expect(stream instanceof RawBinaryCoStream).toEqual(true);
|
|
55
55
|
});
|