cojson 0.20.7 → 0.20.8

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 (209) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +18 -0
  3. package/dist/SyncStateManager.d.ts.map +1 -1
  4. package/dist/SyncStateManager.js +0 -2
  5. package/dist/SyncStateManager.js.map +1 -1
  6. package/dist/base64url.d.ts +15 -0
  7. package/dist/base64url.d.ts.map +1 -1
  8. package/dist/base64url.js +101 -5
  9. package/dist/base64url.js.map +1 -1
  10. package/dist/base64url.test.js +76 -1
  11. package/dist/base64url.test.js.map +1 -1
  12. package/dist/coValue.d.ts +2 -1
  13. package/dist/coValue.d.ts.map +1 -1
  14. package/dist/coValue.js.map +1 -1
  15. package/dist/coValueCore/coValueCore.d.ts +9 -11
  16. package/dist/coValueCore/coValueCore.d.ts.map +1 -1
  17. package/dist/coValueCore/coValueCore.js +92 -65
  18. package/dist/coValueCore/coValueCore.js.map +1 -1
  19. package/dist/coValueCore/verifiedState.d.ts +38 -7
  20. package/dist/coValueCore/verifiedState.d.ts.map +1 -1
  21. package/dist/coValueCore/verifiedState.js +226 -30
  22. package/dist/coValueCore/verifiedState.js.map +1 -1
  23. package/dist/coValues/binaryCoStream.d.ts +63 -0
  24. package/dist/coValues/binaryCoStream.d.ts.map +1 -0
  25. package/dist/coValues/binaryCoStream.js +125 -0
  26. package/dist/coValues/binaryCoStream.js.map +1 -0
  27. package/dist/coValues/coList.d.ts +3 -1
  28. package/dist/coValues/coList.d.ts.map +1 -1
  29. package/dist/coValues/coList.js +15 -6
  30. package/dist/coValues/coList.js.map +1 -1
  31. package/dist/coValues/coMap.d.ts +1 -1
  32. package/dist/coValues/coMap.d.ts.map +1 -1
  33. package/dist/coValues/coMap.js +2 -2
  34. package/dist/coValues/coMap.js.map +1 -1
  35. package/dist/coValues/coStream.d.ts +0 -38
  36. package/dist/coValues/coStream.d.ts.map +1 -1
  37. package/dist/coValues/coStream.js +0 -86
  38. package/dist/coValues/coStream.js.map +1 -1
  39. package/dist/coValues/group.d.ts +44 -6
  40. package/dist/coValues/group.d.ts.map +1 -1
  41. package/dist/coValues/group.js +198 -17
  42. package/dist/coValues/group.js.map +1 -1
  43. package/dist/coreToCoValue.d.ts +2 -1
  44. package/dist/coreToCoValue.d.ts.map +1 -1
  45. package/dist/coreToCoValue.js +2 -1
  46. package/dist/coreToCoValue.js.map +1 -1
  47. package/dist/crypto/NapiCrypto.d.ts +18 -24
  48. package/dist/crypto/NapiCrypto.d.ts.map +1 -1
  49. package/dist/crypto/NapiCrypto.js +98 -60
  50. package/dist/crypto/NapiCrypto.js.map +1 -1
  51. package/dist/crypto/RNCrypto.d.ts +16 -3
  52. package/dist/crypto/RNCrypto.d.ts.map +1 -1
  53. package/dist/crypto/RNCrypto.js +117 -54
  54. package/dist/crypto/RNCrypto.js.map +1 -1
  55. package/dist/crypto/WasmCrypto.d.ts +18 -24
  56. package/dist/crypto/WasmCrypto.d.ts.map +1 -1
  57. package/dist/crypto/WasmCrypto.js +100 -61
  58. package/dist/crypto/WasmCrypto.js.map +1 -1
  59. package/dist/crypto/crypto.d.ts +55 -19
  60. package/dist/crypto/crypto.d.ts.map +1 -1
  61. package/dist/crypto/crypto.js +14 -3
  62. package/dist/crypto/crypto.js.map +1 -1
  63. package/dist/exports.d.ts +7 -3
  64. package/dist/exports.d.ts.map +1 -1
  65. package/dist/exports.js +4 -2
  66. package/dist/exports.js.map +1 -1
  67. package/dist/localNode.d.ts +3 -1
  68. package/dist/localNode.d.ts.map +1 -1
  69. package/dist/localNode.js +10 -3
  70. package/dist/localNode.js.map +1 -1
  71. package/dist/media.d.ts +1 -1
  72. package/dist/media.d.ts.map +1 -1
  73. package/dist/permissions.d.ts +2 -1
  74. package/dist/permissions.d.ts.map +1 -1
  75. package/dist/permissions.js +19 -3
  76. package/dist/permissions.js.map +1 -1
  77. package/dist/storage/sqliteAsync/client.d.ts +24 -12
  78. package/dist/storage/sqliteAsync/client.d.ts.map +1 -1
  79. package/dist/storage/sqliteAsync/client.js +70 -58
  80. package/dist/storage/sqliteAsync/client.js.map +1 -1
  81. package/dist/storage/sqliteAsync/types.d.ts +1 -1
  82. package/dist/storage/sqliteAsync/types.d.ts.map +1 -1
  83. package/dist/storage/types.d.ts +1 -0
  84. package/dist/storage/types.d.ts.map +1 -1
  85. package/dist/sync.d.ts.map +1 -1
  86. package/dist/sync.js +7 -1
  87. package/dist/sync.js.map +1 -1
  88. package/dist/tests/CojsonMessageChannel.test.js +2 -2
  89. package/dist/tests/SQLiteClientAsync.test.d.ts +2 -0
  90. package/dist/tests/SQLiteClientAsync.test.d.ts.map +1 -0
  91. package/dist/tests/SQLiteClientAsync.test.js +64 -0
  92. package/dist/tests/SQLiteClientAsync.test.js.map +1 -0
  93. package/dist/tests/StorageApiAsync.test.js +2 -8
  94. package/dist/tests/StorageApiAsync.test.js.map +1 -1
  95. package/dist/tests/SyncStateManager.test.js +2 -2
  96. package/dist/tests/WasmCrypto.test.js +1 -15
  97. package/dist/tests/WasmCrypto.test.js.map +1 -1
  98. package/dist/tests/coList.test.js +24 -5
  99. package/dist/tests/coList.test.js.map +1 -1
  100. package/dist/tests/coStream.test.js +4 -3
  101. package/dist/tests/coStream.test.js.map +1 -1
  102. package/dist/tests/coValueCore.initTransaction.test.d.ts +2 -0
  103. package/dist/tests/coValueCore.initTransaction.test.d.ts.map +1 -0
  104. package/dist/tests/coValueCore.initTransaction.test.js +438 -0
  105. package/dist/tests/coValueCore.initTransaction.test.js.map +1 -0
  106. package/dist/tests/coValueCore.test.js +11 -19
  107. package/dist/tests/coValueCore.test.js.map +1 -1
  108. package/dist/tests/crypto.test.js +83 -0
  109. package/dist/tests/crypto.test.js.map +1 -1
  110. package/dist/tests/deleteCoValue.test.js +5 -5
  111. package/dist/tests/deleteCoValue.test.js.map +1 -1
  112. package/dist/tests/group.inheritance.test.js +11 -0
  113. package/dist/tests/group.inheritance.test.js.map +1 -1
  114. package/dist/tests/group.test.js +24 -1
  115. package/dist/tests/group.test.js.map +1 -1
  116. package/dist/tests/groupSealer.test.d.ts +2 -0
  117. package/dist/tests/groupSealer.test.d.ts.map +1 -0
  118. package/dist/tests/groupSealer.test.js +913 -0
  119. package/dist/tests/groupSealer.test.js.map +1 -0
  120. package/dist/tests/setup.js +5 -0
  121. package/dist/tests/setup.js.map +1 -1
  122. package/dist/tests/sync.auth.test.js +10 -10
  123. package/dist/tests/sync.concurrentLoad.test.js +12 -12
  124. package/dist/tests/sync.deleted.test.js +8 -8
  125. package/dist/tests/sync.garbageCollection.test.js +10 -10
  126. package/dist/tests/sync.invite.test.js +12 -12
  127. package/dist/tests/sync.known.test.js +2 -2
  128. package/dist/tests/sync.load.test.js +107 -107
  129. package/dist/tests/sync.mesh.test.js +164 -46
  130. package/dist/tests/sync.mesh.test.js.map +1 -1
  131. package/dist/tests/sync.multipleServers.test.js +43 -43
  132. package/dist/tests/sync.peerReconciliation.test.js +29 -29
  133. package/dist/tests/sync.sharding.test.js +3 -3
  134. package/dist/tests/sync.storage.test.js +104 -104
  135. package/dist/tests/sync.storage.test.js.map +1 -1
  136. package/dist/tests/sync.storageAsync.test.js +56 -56
  137. package/dist/tests/sync.upload.test.js +22 -22
  138. package/dist/tests/testStorage.d.ts +2 -0
  139. package/dist/tests/testStorage.d.ts.map +1 -1
  140. package/dist/tests/testStorage.js +30 -6
  141. package/dist/tests/testStorage.js.map +1 -1
  142. package/dist/typeUtils/isCoValue.js +1 -1
  143. package/dist/typeUtils/isCoValue.js.map +1 -1
  144. package/package.json +4 -4
  145. package/src/SyncStateManager.ts +0 -2
  146. package/src/base64url.test.ts +89 -1
  147. package/src/base64url.ts +134 -6
  148. package/src/coValue.ts +2 -1
  149. package/src/coValueCore/coValueCore.ts +126 -84
  150. package/src/coValueCore/verifiedState.ts +335 -53
  151. package/src/coValues/binaryCoStream.ts +217 -0
  152. package/src/coValues/coList.ts +21 -8
  153. package/src/coValues/coMap.ts +3 -0
  154. package/src/coValues/coStream.ts +0 -170
  155. package/src/coValues/group.ts +270 -21
  156. package/src/coreToCoValue.ts +2 -1
  157. package/src/crypto/NapiCrypto.ts +198 -95
  158. package/src/crypto/RNCrypto.ts +229 -102
  159. package/src/crypto/WasmCrypto.ts +201 -95
  160. package/src/crypto/crypto.ts +118 -45
  161. package/src/exports.ts +11 -5
  162. package/src/localNode.ts +17 -1
  163. package/src/media.ts +1 -1
  164. package/src/permissions.ts +30 -7
  165. package/src/storage/sqliteAsync/client.ts +136 -115
  166. package/src/storage/sqliteAsync/types.ts +3 -1
  167. package/src/storage/types.ts +4 -0
  168. package/src/sync.ts +10 -1
  169. package/src/tests/CojsonMessageChannel.test.ts +2 -2
  170. package/src/tests/SQLiteClientAsync.test.ts +75 -0
  171. package/src/tests/StorageApiAsync.test.ts +4 -9
  172. package/src/tests/SyncStateManager.test.ts +2 -2
  173. package/src/tests/WasmCrypto.test.ts +1 -25
  174. package/src/tests/coList.test.ts +39 -5
  175. package/src/tests/coStream.test.ts +4 -5
  176. package/src/tests/coValueCore.initTransaction.test.ts +836 -0
  177. package/src/tests/coValueCore.test.ts +11 -22
  178. package/src/tests/crypto.test.ts +107 -0
  179. package/src/tests/deleteCoValue.test.ts +5 -5
  180. package/src/tests/group.inheritance.test.ts +16 -0
  181. package/src/tests/group.test.ts +29 -1
  182. package/src/tests/groupSealer.test.ts +1473 -0
  183. package/src/tests/setup.ts +6 -0
  184. package/src/tests/sync.auth.test.ts +10 -10
  185. package/src/tests/sync.concurrentLoad.test.ts +12 -12
  186. package/src/tests/sync.deleted.test.ts +8 -8
  187. package/src/tests/sync.garbageCollection.test.ts +10 -10
  188. package/src/tests/sync.invite.test.ts +12 -12
  189. package/src/tests/sync.known.test.ts +2 -2
  190. package/src/tests/sync.load.test.ts +107 -107
  191. package/src/tests/sync.mesh.test.ts +189 -46
  192. package/src/tests/sync.multipleServers.test.ts +43 -43
  193. package/src/tests/sync.peerReconciliation.test.ts +29 -29
  194. package/src/tests/sync.sharding.test.ts +3 -3
  195. package/src/tests/sync.storage.test.ts +104 -104
  196. package/src/tests/sync.storageAsync.test.ts +56 -56
  197. package/src/tests/sync.upload.test.ts +22 -22
  198. package/src/tests/testStorage.ts +39 -9
  199. package/src/typeUtils/isCoValue.ts +1 -1
  200. package/dist/coValueCore/SessionMap.d.ts +0 -55
  201. package/dist/coValueCore/SessionMap.d.ts.map +0 -1
  202. package/dist/coValueCore/SessionMap.js +0 -206
  203. package/dist/coValueCore/SessionMap.js.map +0 -1
  204. package/dist/tests/coreWasm.test.d.ts +0 -2
  205. package/dist/tests/coreWasm.test.d.ts.map +0 -1
  206. package/dist/tests/coreWasm.test.js +0 -203
  207. package/dist/tests/coreWasm.test.js.map +0 -1
  208. package/src/coValueCore/SessionMap.ts +0 -394
  209. package/src/tests/coreWasm.test.ts +0 -452
@@ -1,452 +0,0 @@
1
- import { assert, describe, expect, it } from "vitest";
2
- import { WasmCrypto } from "../crypto/WasmCrypto";
3
- import { LocalNode } from "../exports";
4
- import { agentAndSessionIDFromSecret } from "./testUtils";
5
- import { Transaction } from "../coValueCore/verifiedState";
6
-
7
- const wasmCrypto = await WasmCrypto.create();
8
-
9
- const agentSecret =
10
- "sealerSecret_zE3Nr7YFr1KkVbJSx4JDCzYn4ApYdm8kJ5ghNBxREHQya/signerSecret_z9fEu4eNG1eXHMak3YSzY7uLdoG8HESSJ8YW4xWdNNDSP";
11
-
12
- function createTestNode() {
13
- const [agent, session] = agentAndSessionIDFromSecret(agentSecret);
14
- return {
15
- agent,
16
- session,
17
- node: new LocalNode(agent.agentSecret, session, wasmCrypto),
18
- };
19
- }
20
-
21
- describe("SessionLog WASM", () => {
22
- it("it works", () => {
23
- const [agent, sessionId] = agentAndSessionIDFromSecret(agentSecret);
24
-
25
- const session = wasmCrypto.createSessionLog(
26
- "co_test1" as any,
27
- sessionId,
28
- agent.currentSignerID(),
29
- );
30
-
31
- expect(session).toBeDefined();
32
- });
33
-
34
- it("test_add_from_example_json", () => {
35
- const { agent, session, node } = createTestNode();
36
-
37
- const group = node.createGroup();
38
- const sessionContent =
39
- group.core.newContentSince(undefined)?.[0]?.new[session];
40
- assert(sessionContent);
41
-
42
- let log = wasmCrypto.createSessionLog(
43
- group.id,
44
- session,
45
- agent.currentSignerID(),
46
- );
47
-
48
- log.tryAdd(
49
- sessionContent.newTransactions,
50
- sessionContent.lastSignature,
51
- false,
52
- );
53
- });
54
-
55
- it("test_add_new_transaction", () => {
56
- const { agent, session, node } = createTestNode();
57
-
58
- const group = node.createGroup();
59
- const sessionContent =
60
- group.core.newContentSince(undefined)?.[0]?.new[session];
61
- assert(sessionContent);
62
-
63
- let log = wasmCrypto.createSessionLog(
64
- group.id,
65
- session,
66
- agent.currentSignerID(),
67
- );
68
-
69
- const changesJson = [
70
- { after: "start", op: "app", value: "co_zMphsnYN6GU8nn2HDY5suvyGufY" },
71
- ];
72
- const key = group.getCurrentReadKey();
73
- assert(key);
74
- assert(key.secret);
75
-
76
- const { signature, transaction } = log.addNewPrivateTransaction(
77
- agent,
78
- changesJson,
79
- key.id,
80
- key.secret,
81
- 0,
82
- undefined,
83
- );
84
-
85
- expect(signature).toMatch(/^signature_z[a-zA-Z0-9]+$/);
86
- expect(transaction).toEqual({
87
- encryptedChanges: expect.stringMatching(/^encrypted_U/),
88
- keyUsed: expect.stringMatching(/^key_z/),
89
- madeAt: 0,
90
- privacy: "private",
91
- });
92
-
93
- const decrypted = log.decryptNextTransactionChangesJson(0, key.secret);
94
-
95
- expect(decrypted).toEqual(
96
- '[{"after":"start","op":"app","value":"co_zMphsnYN6GU8nn2HDY5suvyGufY"}]',
97
- );
98
- });
99
-
100
- it("test_decrypt + clone", () => {
101
- const [agent] = agentAndSessionIDFromSecret(agentSecret);
102
- const fixtures = {
103
- id: "co_zWwrEiushQLvbkWd6Z3L8WxTU1r",
104
- signature:
105
- "signature_z3ktW7wxMnW7VYExCGZv4Ug2UJSW3ag6zLDiP8GpZThzif6veJt7JipYpUgshhuGbgHtLcWywWSWysV7hChxFypDt",
106
- decrypted:
107
- '[{"after":"start","op":"app","value":"co_zMphsnYN6GU8nn2HDY5suvyGufY"}]',
108
- key: {
109
- secret: "keySecret_z3dU66SsyQkkGKpNCJW6NX74MnfVGHUyY7r85b4M8X88L",
110
- id: "key_z5XUAHyoqUV9zXWvMK",
111
- },
112
- transaction: {
113
- privacy: "private",
114
- madeAt: 0,
115
- encryptedChanges:
116
- "encrypted_UNAxqdUSGRZ2rzuLU99AFPKCe2C0HwsTzMWQreXZqLr6RpWrSMa-5lwgwIev7xPHTgZFq5UyUgMFrO9zlHJHJGgjJcDzFihY=" as any,
117
- keyUsed: "key_z5XUAHyoqUV9zXWvMK",
118
- },
119
- session:
120
- "sealer_z5yhsCCe2XwLTZC4254mUoMASshm3Diq49JrefPpjTktp/signer_z7gVGDpNz9qUtsRxAkHMuu4DYdtVVCG4XELTKPYdoYLPr_session_z9mDP8FoonSA",
121
- } as const;
122
-
123
- let log = wasmCrypto.createSessionLog(
124
- fixtures.id,
125
- fixtures.session,
126
- agent.currentSignerID(),
127
- );
128
-
129
- log.tryAdd([fixtures.transaction], fixtures.signature, true);
130
-
131
- const decrypted = log
132
- .clone()
133
- .decryptNextTransactionChangesJson(0, fixtures.key.secret);
134
-
135
- expect(decrypted).toEqual(fixtures.decrypted);
136
- });
137
-
138
- function shuffleObjectKeys<T extends object>(obj: T): T {
139
- const keys = Object.keys(obj);
140
- // Fisher-Yates shuffle
141
- for (let i = keys.length - 1; i > 0; i--) {
142
- const j = Math.floor(Math.random() * (i + 1));
143
- [keys[i], keys[j]] = [keys[j]!, keys[i]!];
144
- }
145
- const result = {} as T;
146
- for (const key of keys) {
147
- (result as any)[key] = (obj as any)[key];
148
- }
149
- return result;
150
- }
151
-
152
- function shuffleTransactions(transactions: Transaction[]): Transaction[] {
153
- return transactions.map((t) => shuffleObjectKeys(t) as Transaction);
154
- }
155
-
156
- describe("Signature validation after shuffling transaction keys", () => {
157
- it("trusting transactions with 100 k/v entries", () => {
158
- const { agent, session, node } = createTestNode();
159
-
160
- const group = node.createGroup();
161
- const map = group.createMap();
162
-
163
- // Create 100 trusting transactions with explicit test data
164
- for (let i = 0; i < 100; i++) {
165
- map.core.makeTransaction(
166
- [{ op: "set", key: `key${i}`, value: `value${i}` }],
167
- "trusting",
168
- undefined,
169
- i * 1000,
170
- );
171
- }
172
-
173
- const sessionContent =
174
- map.core.newContentSince(undefined)?.[0]?.new[session];
175
- assert(sessionContent);
176
- expect(sessionContent.newTransactions.length).toBe(100);
177
-
178
- const log = wasmCrypto.createSessionLog(
179
- map.id,
180
- session,
181
- agent.currentSignerID(),
182
- );
183
- const logShuffled = wasmCrypto.createSessionLog(
184
- map.id,
185
- session,
186
- agent.currentSignerID(),
187
- );
188
-
189
- const shuffledTransactions = shuffleTransactions(
190
- sessionContent.newTransactions,
191
- );
192
-
193
- expect(() =>
194
- log.tryAdd(
195
- sessionContent.newTransactions,
196
- sessionContent.lastSignature,
197
- false,
198
- ),
199
- ).not.toThrow();
200
-
201
- expect(() =>
202
- logShuffled.tryAdd(
203
- shuffledTransactions,
204
- sessionContent.lastSignature,
205
- false,
206
- ),
207
- ).not.toThrow();
208
- });
209
-
210
- it("private transactions with 100 k/v entries", () => {
211
- const { agent, session, node } = createTestNode();
212
-
213
- const group = node.createGroup();
214
- const map = group.createMap();
215
-
216
- // Create 100 private transactions with explicit test data
217
- for (let i = 0; i < 100; i++) {
218
- map.core.makeTransaction(
219
- [{ op: "set", key: `secretKey${i}`, value: `secretValue${i}` }],
220
- "private",
221
- undefined,
222
- i * 1000,
223
- );
224
- }
225
-
226
- const sessionContent =
227
- map.core.newContentSince(undefined)?.[0]?.new[session];
228
- assert(sessionContent);
229
- expect(sessionContent.newTransactions.length).toBe(100);
230
-
231
- // Verify transactions are actually private (encrypted)
232
- const firstTx = sessionContent.newTransactions[0];
233
- assert(firstTx);
234
- expect(firstTx.privacy).toBe("private");
235
- expect("encryptedChanges" in firstTx).toBe(true);
236
-
237
- const log = wasmCrypto.createSessionLog(
238
- map.id,
239
- session,
240
- agent.currentSignerID(),
241
- );
242
- const logShuffled = wasmCrypto.createSessionLog(
243
- map.id,
244
- session,
245
- agent.currentSignerID(),
246
- );
247
-
248
- const shuffledTransactions = shuffleTransactions(
249
- sessionContent.newTransactions,
250
- );
251
-
252
- expect(() =>
253
- log.tryAdd(
254
- sessionContent.newTransactions,
255
- sessionContent.lastSignature,
256
- false,
257
- ),
258
- ).not.toThrow();
259
-
260
- expect(() =>
261
- logShuffled.tryAdd(
262
- shuffledTransactions,
263
- sessionContent.lastSignature,
264
- false,
265
- ),
266
- ).not.toThrow();
267
- });
268
-
269
- it("trusting transactions with metas", () => {
270
- const { agent, session, node } = createTestNode();
271
-
272
- const group = node.createGroup();
273
- const map = group.createMap();
274
-
275
- // Create transactions with metas
276
- for (let i = 0; i < 50; i++) {
277
- map.core.makeTransaction(
278
- [{ op: "set", key: `key${i}`, value: `value${i}` }],
279
- "trusting",
280
- { index: i, timestamp: i * 1000, nested: { data: `meta${i}` } },
281
- i * 1000,
282
- );
283
- }
284
-
285
- const sessionContent =
286
- map.core.newContentSince(undefined)?.[0]?.new[session];
287
- assert(sessionContent);
288
- expect(sessionContent.newTransactions.length).toBe(50);
289
-
290
- // Verify metas are present
291
- const firstTx = sessionContent.newTransactions[0];
292
- assert(firstTx);
293
- expect(firstTx.meta).toBeDefined();
294
-
295
- const log = wasmCrypto.createSessionLog(
296
- map.id,
297
- session,
298
- agent.currentSignerID(),
299
- );
300
- const logShuffled = wasmCrypto.createSessionLog(
301
- map.id,
302
- session,
303
- agent.currentSignerID(),
304
- );
305
-
306
- const shuffledTransactions = shuffleTransactions(
307
- sessionContent.newTransactions,
308
- );
309
-
310
- expect(() =>
311
- log.tryAdd(
312
- sessionContent.newTransactions,
313
- sessionContent.lastSignature,
314
- false,
315
- ),
316
- ).not.toThrow();
317
-
318
- expect(() =>
319
- logShuffled.tryAdd(
320
- shuffledTransactions,
321
- sessionContent.lastSignature,
322
- false,
323
- ),
324
- ).not.toThrow();
325
- });
326
-
327
- it("private transactions with metas", () => {
328
- const { agent, session, node } = createTestNode();
329
-
330
- const group = node.createGroup();
331
- const map = group.createMap();
332
-
333
- // Create private transactions with encrypted metas
334
- for (let i = 0; i < 50; i++) {
335
- map.core.makeTransaction(
336
- [{ op: "set", key: `secretKey${i}`, value: `secretValue${i}` }],
337
- "private",
338
- { index: i, secret: `confidential${i}` },
339
- i * 1000,
340
- );
341
- }
342
-
343
- const sessionContent =
344
- map.core.newContentSince(undefined)?.[0]?.new[session];
345
- assert(sessionContent);
346
- expect(sessionContent.newTransactions.length).toBe(50);
347
-
348
- // Verify transactions are private with encrypted metas
349
- const firstTx = sessionContent.newTransactions[0];
350
- assert(firstTx);
351
- expect(firstTx.privacy).toBe("private");
352
- expect("encryptedChanges" in firstTx).toBe(true);
353
- expect(firstTx.meta).toBeDefined();
354
-
355
- const log = wasmCrypto.createSessionLog(
356
- map.id,
357
- session,
358
- agent.currentSignerID(),
359
- );
360
- const logShuffled = wasmCrypto.createSessionLog(
361
- map.id,
362
- session,
363
- agent.currentSignerID(),
364
- );
365
-
366
- const shuffledTransactions = shuffleTransactions(
367
- sessionContent.newTransactions,
368
- );
369
-
370
- expect(() =>
371
- log.tryAdd(
372
- sessionContent.newTransactions,
373
- sessionContent.lastSignature,
374
- false,
375
- ),
376
- ).not.toThrow();
377
-
378
- expect(() =>
379
- logShuffled.tryAdd(
380
- shuffledTransactions,
381
- sessionContent.lastSignature,
382
- false,
383
- ),
384
- ).not.toThrow();
385
- });
386
-
387
- it("mixed trusting and private transactions across multiple sessions", () => {
388
- const { agent, session, node } = createTestNode();
389
-
390
- const group = node.createGroup();
391
- const map = group.createMap();
392
-
393
- // Create alternating trusting and private transactions
394
- for (let i = 0; i < 50; i++) {
395
- const privacy = i % 2 === 0 ? "trusting" : "private";
396
- const hasMeta = i % 3 === 0;
397
- map.core.makeTransaction(
398
- [{ op: "set", key: `mixedKey${i}`, value: `mixedValue${i}` }],
399
- privacy,
400
- hasMeta ? { iteration: i, type: privacy } : undefined,
401
- i * 1000,
402
- );
403
- }
404
-
405
- const sessionContent =
406
- map.core.newContentSince(undefined)?.[0]?.new[session];
407
- assert(sessionContent);
408
- expect(sessionContent.newTransactions.length).toBe(50);
409
-
410
- // Verify we have a mix of trusting and private transactions
411
- const trustingCount = sessionContent.newTransactions.filter(
412
- (t) => t.privacy === "trusting",
413
- ).length;
414
- const privateCount = sessionContent.newTransactions.filter(
415
- (t) => t.privacy === "private",
416
- ).length;
417
- expect(trustingCount).toBe(25);
418
- expect(privateCount).toBe(25);
419
-
420
- const log = wasmCrypto.createSessionLog(
421
- map.id,
422
- session,
423
- agent.currentSignerID(),
424
- );
425
- const logShuffled = wasmCrypto.createSessionLog(
426
- map.id,
427
- session,
428
- agent.currentSignerID(),
429
- );
430
-
431
- const shuffledTransactions = shuffleTransactions(
432
- sessionContent.newTransactions,
433
- );
434
-
435
- expect(() =>
436
- log.tryAdd(
437
- sessionContent.newTransactions,
438
- sessionContent.lastSignature,
439
- false,
440
- ),
441
- ).not.toThrow();
442
-
443
- expect(() =>
444
- logShuffled.tryAdd(
445
- shuffledTransactions,
446
- sessionContent.lastSignature,
447
- false,
448
- ),
449
- ).not.toThrow();
450
- });
451
- });
452
- });