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