cojson 0.2.3 → 0.3.0

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 (78) hide show
  1. package/dist/account.d.ts +1 -1
  2. package/dist/coValue.d.ts +5 -13
  3. package/dist/coValue.js +14 -7
  4. package/dist/coValue.js.map +1 -1
  5. package/dist/coValueCore.d.ts +6 -6
  6. package/dist/coValueCore.js +11 -14
  7. package/dist/coValueCore.js.map +1 -1
  8. package/dist/coValues/coList.d.ts +99 -34
  9. package/dist/coValues/coList.js +162 -72
  10. package/dist/coValues/coList.js.map +1 -1
  11. package/dist/coValues/coMap.d.ts +96 -31
  12. package/dist/coValues/coMap.js +157 -114
  13. package/dist/coValues/coMap.js.map +1 -1
  14. package/dist/coValues/coStream.d.ts +67 -23
  15. package/dist/coValues/coStream.js +131 -59
  16. package/dist/coValues/coStream.js.map +1 -1
  17. package/dist/crypto.d.ts +8 -3
  18. package/dist/crypto.js +6 -6
  19. package/dist/crypto.js.map +1 -1
  20. package/dist/group.d.ts +57 -23
  21. package/dist/group.js +75 -33
  22. package/dist/group.js.map +1 -1
  23. package/dist/index.d.ts +8 -6
  24. package/dist/index.js +8 -8
  25. package/dist/index.js.map +1 -1
  26. package/dist/{node.d.ts → localNode.d.ts} +16 -8
  27. package/dist/{node.js → localNode.js} +48 -40
  28. package/dist/localNode.js.map +1 -0
  29. package/dist/permissions.js +6 -3
  30. package/dist/permissions.js.map +1 -1
  31. package/dist/queriedCoValues/queriedCoList.d.ts +66 -0
  32. package/dist/queriedCoValues/queriedCoList.js +120 -0
  33. package/dist/queriedCoValues/queriedCoList.js.map +1 -0
  34. package/dist/queriedCoValues/queriedCoMap.d.ts +47 -0
  35. package/dist/queriedCoValues/queriedCoMap.js +83 -0
  36. package/dist/queriedCoValues/queriedCoMap.js.map +1 -0
  37. package/dist/queriedCoValues/queriedCoStream.d.ts +40 -0
  38. package/dist/queriedCoValues/queriedCoStream.js +72 -0
  39. package/dist/queriedCoValues/queriedCoStream.js.map +1 -0
  40. package/dist/queries.d.ts +29 -112
  41. package/dist/queries.js +44 -227
  42. package/dist/queries.js.map +1 -1
  43. package/dist/sync.d.ts +1 -1
  44. package/dist/sync.js +1 -1
  45. package/dist/sync.js.map +1 -1
  46. package/dist/tests/testUtils.d.ts +1 -1
  47. package/dist/tests/testUtils.js +3 -3
  48. package/dist/tests/testUtils.js.map +1 -1
  49. package/package.json +2 -2
  50. package/src/account.ts +1 -1
  51. package/src/coValue.ts +25 -20
  52. package/src/coValueCore.ts +17 -21
  53. package/src/coValues/coList.ts +242 -128
  54. package/src/coValues/coMap.ts +293 -162
  55. package/src/coValues/coStream.ts +227 -94
  56. package/src/crypto.ts +37 -24
  57. package/src/group.ts +90 -63
  58. package/src/index.ts +35 -25
  59. package/src/{node.ts → localNode.ts} +64 -64
  60. package/src/permissions.ts +15 -18
  61. package/src/queriedCoValues/queriedCoList.ts +248 -0
  62. package/src/queriedCoValues/queriedCoMap.ts +180 -0
  63. package/src/queriedCoValues/queriedCoStream.ts +125 -0
  64. package/src/queries.ts +83 -460
  65. package/src/sync.ts +2 -2
  66. package/src/tests/account.test.ts +3 -6
  67. package/src/tests/coValue.test.ts +116 -110
  68. package/src/tests/coValueCore.test.ts +1 -1
  69. package/src/tests/crypto.test.ts +19 -21
  70. package/src/tests/permissions.test.ts +255 -242
  71. package/src/tests/queries.test.ts +57 -40
  72. package/src/tests/sync.test.ts +30 -30
  73. package/src/tests/testUtils.ts +3 -3
  74. package/dist/coValues/static.d.ts +0 -14
  75. package/dist/coValues/static.js +0 -20
  76. package/dist/coValues/static.js.map +0 -1
  77. package/dist/node.js.map +0 -1
  78. package/src/coValues/static.ts +0 -31
@@ -1,8 +1,9 @@
1
+ import { expectList, expectMap, expectStream } from "../coValue.js";
1
2
  import { accountOrAgentIDfromSessionID } from "../coValueCore.js";
2
3
  import { BinaryCoStream } from "../coValues/coStream.js";
3
4
  import { createdNowUnique } from "../crypto.js";
4
5
  import { MAX_RECOMMENDED_TX_SIZE, cojsonReady } from "../index.js";
5
- import { LocalNode } from "../node.js";
6
+ import { LocalNode } from "../localNode.js";
6
7
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
7
8
 
8
9
  beforeEach(async () => {
@@ -19,11 +20,7 @@ test("Empty CoMap works", () => {
19
20
  ...createdNowUnique(),
20
21
  });
21
22
 
22
- const content = coValue.getCurrentContent();
23
-
24
- if (content.type !== "comap") {
25
- throw new Error("Expected map");
26
- }
23
+ const content = expectMap(coValue.getCurrentContent());
27
24
 
28
25
  expect(content.type).toEqual("comap");
29
26
  expect([...content.keys()]).toEqual([]);
@@ -40,11 +37,7 @@ test("Can insert and delete CoMap entries in edit()", () => {
40
37
  ...createdNowUnique(),
41
38
  });
42
39
 
43
- const content = coValue.getCurrentContent();
44
-
45
- if (content.type !== "comap") {
46
- throw new Error("Expected map");
47
- }
40
+ const content = expectMap(coValue.getCurrentContent());
48
41
 
49
42
  expect(content.type).toEqual("comap");
50
43
 
@@ -69,11 +62,7 @@ test("Can get CoMap entry values at different points in time", () => {
69
62
  ...createdNowUnique(),
70
63
  });
71
64
 
72
- const content = coValue.getCurrentContent();
73
-
74
- if (content.type !== "comap") {
75
- throw new Error("Expected map");
76
- }
65
+ const content = expectMap(coValue.getCurrentContent());
77
66
 
78
67
  expect(content.type).toEqual("comap");
79
68
 
@@ -88,10 +77,10 @@ test("Can get CoMap entry values at different points in time", () => {
88
77
  while (Date.now() < beforeC + 10) {}
89
78
  editable.set("hello", "C", "trusting");
90
79
  expect(editable.get("hello")).toEqual("C");
91
- expect(editable.getAtTime("hello", Date.now())).toEqual("C");
92
- expect(editable.getAtTime("hello", beforeA)).toEqual(undefined);
93
- expect(editable.getAtTime("hello", beforeB)).toEqual("A");
94
- expect(editable.getAtTime("hello", beforeC)).toEqual("B");
80
+ expect(editable.atTime(Date.now()).get("hello")).toEqual("C");
81
+ expect(editable.atTime(beforeA).get("hello")).toEqual(undefined);
82
+ expect(editable.atTime(beforeB).get("hello")).toEqual("A");
83
+ expect(editable.atTime(beforeC).get("hello")).toEqual("B");
95
84
  });
96
85
  });
97
86
 
@@ -105,43 +94,43 @@ test("Can get all historic values of key in CoMap", () => {
105
94
  ...createdNowUnique(),
106
95
  });
107
96
 
108
- const content = coValue.getCurrentContent();
109
-
110
- if (content.type !== "comap") {
111
- throw new Error("Expected map");
112
- }
97
+ const content = expectMap(coValue.getCurrentContent());
113
98
 
114
99
  expect(content.type).toEqual("comap");
115
100
 
116
101
  content.edit((editable) => {
117
102
  editable.set("hello", "A", "trusting");
118
- const txA = editable.getLastTxID("hello");
103
+ const editA = editable.lastEditAt("hello");
119
104
  editable.set("hello", "B", "trusting");
120
- const txB = editable.getLastTxID("hello");
105
+ const editB = editable.lastEditAt("hello");
121
106
  editable.delete("hello", "trusting");
122
- const txDel = editable.getLastTxID("hello");
107
+ const editDel = editable.lastEditAt("hello");
123
108
  editable.set("hello", "C", "trusting");
124
- const txC = editable.getLastTxID("hello");
125
- expect(editable.getHistory("hello")).toEqual([
109
+ const editC = editable.lastEditAt("hello");
110
+ expect([...editable.editsAt("hello")]).toEqual([
126
111
  {
127
- txID: txA,
112
+ tx: editA!.tx,
113
+ by: node.account.id,
128
114
  value: "A",
129
- at: txA && coValue.getTx(txA)?.madeAt,
115
+ at: editA?.at,
130
116
  },
131
117
  {
132
- txID: txB,
118
+ tx: editB!.tx,
119
+ by: node.account.id,
133
120
  value: "B",
134
- at: txB && coValue.getTx(txB)?.madeAt,
121
+ at: editB?.at,
135
122
  },
136
123
  {
137
- txID: txDel,
124
+ tx: editDel!.tx,
125
+ by: node.account.id,
138
126
  value: undefined,
139
- at: txDel && coValue.getTx(txDel)?.madeAt,
127
+ at: editDel?.at,
140
128
  },
141
129
  {
142
- txID: txC,
130
+ tx: editC!.tx,
131
+ by: node.account.id,
143
132
  value: "C",
144
- at: txC && coValue.getTx(txC)?.madeAt,
133
+ at: editC?.at,
145
134
  },
146
135
  ]);
147
136
  });
@@ -157,26 +146,22 @@ test("Can get last tx ID for a key in CoMap", () => {
157
146
  ...createdNowUnique(),
158
147
  });
159
148
 
160
- const content = coValue.getCurrentContent();
161
-
162
- if (content.type !== "comap") {
163
- throw new Error("Expected map");
164
- }
149
+ const content = expectMap(coValue.getCurrentContent());
165
150
 
166
151
  expect(content.type).toEqual("comap");
167
152
 
168
153
  content.edit((editable) => {
169
- expect(editable.getLastTxID("hello")).toEqual(undefined);
154
+ expect(editable.lastEditAt("hello")).toEqual(undefined);
170
155
  editable.set("hello", "A", "trusting");
171
- const sessionID = editable.getLastTxID("hello")?.sessionID;
156
+ const sessionID = editable.lastEditAt("hello")?.tx.sessionID;
172
157
  expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
173
158
  node.account.id
174
159
  );
175
- expect(editable.getLastTxID("hello")?.txIndex).toEqual(0);
160
+ expect(editable.lastEditAt("hello")?.tx.txIndex).toEqual(0);
176
161
  editable.set("hello", "B", "trusting");
177
- expect(editable.getLastTxID("hello")?.txIndex).toEqual(1);
162
+ expect(editable.lastEditAt("hello")?.tx.txIndex).toEqual(1);
178
163
  editable.set("hello", "C", "trusting");
179
- expect(editable.getLastTxID("hello")?.txIndex).toEqual(2);
164
+ expect(editable.lastEditAt("hello")?.tx.txIndex).toEqual(2);
180
165
  });
181
166
  });
182
167
 
@@ -190,11 +175,7 @@ test("Empty CoList works", () => {
190
175
  ...createdNowUnique(),
191
176
  });
192
177
 
193
- const content = coValue.getCurrentContent();
194
-
195
- if (content.type !== "colist") {
196
- throw new Error("Expected list");
197
- }
178
+ const content = expectList(coValue.getCurrentContent());
198
179
 
199
180
  expect(content.type).toEqual("colist");
200
181
  expect(content.toJSON()).toEqual([]);
@@ -210,22 +191,16 @@ test("Can append, prepend and delete items to CoList", () => {
210
191
  ...createdNowUnique(),
211
192
  });
212
193
 
213
- const content = coValue.getCurrentContent();
214
-
215
- if (content.type !== "colist") {
216
- throw new Error("Expected list");
217
- }
218
-
219
- expect(content.type).toEqual("colist");
194
+ const content = expectList(coValue.getCurrentContent());
220
195
 
221
196
  content.edit((editable) => {
222
- editable.append(0, "hello", "trusting");
197
+ editable.append("hello", 0, "trusting");
223
198
  expect(editable.toJSON()).toEqual(["hello"]);
224
- editable.append(0, "world", "trusting");
199
+ editable.append("world", 0, "trusting");
225
200
  expect(editable.toJSON()).toEqual(["hello", "world"]);
226
- editable.prepend(1, "beautiful", "trusting");
201
+ editable.prepend("beautiful", 1, "trusting");
227
202
  expect(editable.toJSON()).toEqual(["hello", "beautiful", "world"]);
228
- editable.prepend(3, "hooray", "trusting");
203
+ editable.prepend("hooray", 3, "trusting");
229
204
  expect(editable.toJSON()).toEqual([
230
205
  "hello",
231
206
  "beautiful",
@@ -247,20 +222,16 @@ test("Push is equivalent to append after last item", () => {
247
222
  ...createdNowUnique(),
248
223
  });
249
224
 
250
- const content = coValue.getCurrentContent();
251
-
252
- if (content.type !== "colist") {
253
- throw new Error("Expected list");
254
- }
225
+ const content = expectList(coValue.getCurrentContent());
255
226
 
256
227
  expect(content.type).toEqual("colist");
257
228
 
258
229
  content.edit((editable) => {
259
- editable.append(0, "hello", "trusting");
230
+ editable.append("hello", 0, "trusting");
260
231
  expect(editable.toJSON()).toEqual(["hello"]);
261
- editable.push("world", "trusting");
232
+ editable.append("world", undefined, "trusting");
262
233
  expect(editable.toJSON()).toEqual(["hello", "world"]);
263
- editable.push("hooray", "trusting");
234
+ editable.append("hooray", undefined, "trusting");
264
235
  expect(editable.toJSON()).toEqual(["hello", "world", "hooray"]);
265
236
  });
266
237
  });
@@ -275,16 +246,12 @@ test("Can push into empty list", () => {
275
246
  ...createdNowUnique(),
276
247
  });
277
248
 
278
- const content = coValue.getCurrentContent();
279
-
280
- if (content.type !== "colist") {
281
- throw new Error("Expected list");
282
- }
249
+ const content = expectList(coValue.getCurrentContent());
283
250
 
284
251
  expect(content.type).toEqual("colist");
285
252
 
286
253
  content.edit((editable) => {
287
- editable.push("hello", "trusting");
254
+ editable.append("hello", undefined, "trusting");
288
255
  expect(editable.toJSON()).toEqual(["hello"]);
289
256
  });
290
257
  });
@@ -299,11 +266,7 @@ test("Empty CoStream works", () => {
299
266
  ...createdNowUnique(),
300
267
  });
301
268
 
302
- const content = coValue.getCurrentContent();
303
-
304
- if (content.type !== "costream") {
305
- throw new Error("Expected stream");
306
- }
269
+ const content = expectStream(coValue.getCurrentContent());
307
270
 
308
271
  expect(content.type).toEqual("costream");
309
272
  expect(content.toJSON()).toEqual({});
@@ -320,11 +283,7 @@ test("Can push into CoStream", () => {
320
283
  ...createdNowUnique(),
321
284
  });
322
285
 
323
- const content = coValue.getCurrentContent();
324
-
325
- if (content.type !== "costream") {
326
- throw new Error("Expected stream");
327
- }
286
+ const content = expectStream(coValue.getCurrentContent());
328
287
 
329
288
  content.edit((editable) => {
330
289
  editable.push({ hello: "world" }, "trusting");
@@ -354,7 +313,11 @@ test("Empty BinaryCoStream works", () => {
354
313
 
355
314
  const content = coValue.getCurrentContent();
356
315
 
357
- if (content.type !== "costream" || content.meta?.type !== "binary" || !(content instanceof BinaryCoStream)) {
316
+ if (
317
+ content.type !== "costream" ||
318
+ content.meta?.type !== "binary" ||
319
+ !(content instanceof BinaryCoStream)
320
+ ) {
358
321
  throw new Error("Expected binary stream");
359
322
  }
360
323
 
@@ -376,12 +339,19 @@ test("Can push into BinaryCoStream", () => {
376
339
 
377
340
  const content = coValue.getCurrentContent();
378
341
 
379
- if (content.type !== "costream" || content.meta?.type !== "binary" || !(content instanceof BinaryCoStream)) {
342
+ if (
343
+ content.type !== "costream" ||
344
+ content.meta?.type !== "binary" ||
345
+ !(content instanceof BinaryCoStream)
346
+ ) {
380
347
  throw new Error("Expected binary stream");
381
348
  }
382
349
 
383
350
  content.edit((editable) => {
384
- editable.startBinaryStream({mimeType: "text/plain", fileName: "test.txt"}, "trusting");
351
+ editable.startBinaryStream(
352
+ { mimeType: "text/plain", fileName: "test.txt" },
353
+ "trusting"
354
+ );
385
355
  expect(editable.getBinaryChunks(true)).toEqual({
386
356
  mimeType: "text/plain",
387
357
  fileName: "test.txt",
@@ -426,16 +396,23 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
426
396
 
427
397
  const content = coValue.getCurrentContent();
428
398
 
429
- if (content.type !== "costream" || content.meta?.type !== "binary" || !(content instanceof BinaryCoStream)) {
399
+ if (
400
+ content.type !== "costream" ||
401
+ content.meta?.type !== "binary" ||
402
+ !(content instanceof BinaryCoStream)
403
+ ) {
430
404
  throw new Error("Expected binary stream");
431
405
  }
432
406
 
433
407
  content.edit((editable) => {
434
- editable.startBinaryStream({mimeType: "text/plain", fileName: "test.txt"}, "trusting");
408
+ editable.startBinaryStream(
409
+ { mimeType: "text/plain", fileName: "test.txt" },
410
+ "trusting"
411
+ );
435
412
  });
436
413
 
437
414
  for (let i = 0; i < 10; i++) {
438
- const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE/3 + 100);
415
+ const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE / 3 + 100);
439
416
 
440
417
  content.edit((editable) => {
441
418
  editable.pushBinaryStreamChunk(chunk, "trusting");
@@ -461,14 +438,26 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
461
438
  expect(sessionEntry.signatureAfter[10]).not.toBeDefined();
462
439
  expect(sessionEntry.signatureAfter[11]).not.toBeDefined();
463
440
 
464
- const newContent = coValue.newContentSince({id: coValue.id, header: false, sessions: {}})!;
441
+ const newContent = coValue.newContentSince({
442
+ id: coValue.id,
443
+ header: false,
444
+ sessions: {},
445
+ })!;
465
446
 
466
- expect(newContent.length).toEqual(5)
447
+ expect(newContent.length).toEqual(5);
467
448
  expect(newContent[0]!.header).toBeDefined();
468
- expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.signatureAfter[3]);
469
- expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.signatureAfter[6]);
470
- expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.signatureAfter[9]);
471
- expect(newContent[4]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.lastSignature);
449
+ expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(
450
+ sessionEntry.signatureAfter[3]
451
+ );
452
+ expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(
453
+ sessionEntry.signatureAfter[6]
454
+ );
455
+ expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(
456
+ sessionEntry.signatureAfter[9]
457
+ );
458
+ expect(newContent[4]!.new[node.currentSessionID]!.lastSignature).toEqual(
459
+ sessionEntry.lastSignature
460
+ );
472
461
  });
473
462
 
474
463
  test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we store an inbetween signature after every large transaction and split up newContentSince accordingly", () => {
@@ -483,12 +472,19 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
483
472
 
484
473
  const content = coValue.getCurrentContent();
485
474
 
486
- if (content.type !== "costream" || content.meta?.type !== "binary" || !(content instanceof BinaryCoStream)) {
475
+ if (
476
+ content.type !== "costream" ||
477
+ content.meta?.type !== "binary" ||
478
+ !(content instanceof BinaryCoStream)
479
+ ) {
487
480
  throw new Error("Expected binary stream");
488
481
  }
489
482
 
490
483
  content.edit((editable) => {
491
- editable.startBinaryStream({mimeType: "text/plain", fileName: "test.txt"}, "trusting");
484
+ editable.startBinaryStream(
485
+ { mimeType: "text/plain", fileName: "test.txt" },
486
+ "trusting"
487
+ );
492
488
  });
493
489
 
494
490
  const chunk = new Uint8Array(MAX_RECOMMENDED_TX_SIZE + 100);
@@ -511,14 +507,24 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
511
507
  expect(sessionEntry.signatureAfter[3]).toBeDefined();
512
508
  expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
513
509
 
514
- const newContent = coValue.newContentSince({id: coValue.id, header: false, sessions: {}})!;
510
+ const newContent = coValue.newContentSince({
511
+ id: coValue.id,
512
+ header: false,
513
+ sessions: {},
514
+ })!;
515
515
 
516
- expect(newContent.length).toEqual(5)
516
+ expect(newContent.length).toEqual(5);
517
517
  expect(newContent[0]!.header).toBeDefined();
518
- expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.signatureAfter[1]);
519
- expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.signatureAfter[2]);
520
- expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.signatureAfter[3]);
521
- expect(newContent[4]!.new[node.currentSessionID]!.lastSignature).toEqual(sessionEntry.lastSignature);
518
+ expect(newContent[1]!.new[node.currentSessionID]!.lastSignature).toEqual(
519
+ sessionEntry.signatureAfter[1]
520
+ );
521
+ expect(newContent[2]!.new[node.currentSessionID]!.lastSignature).toEqual(
522
+ sessionEntry.signatureAfter[2]
523
+ );
524
+ expect(newContent[3]!.new[node.currentSessionID]!.lastSignature).toEqual(
525
+ sessionEntry.signatureAfter[3]
526
+ );
527
+ expect(newContent[4]!.new[node.currentSessionID]!.lastSignature).toEqual(
528
+ sessionEntry.lastSignature
529
+ );
522
530
  });
523
-
524
-
@@ -1,5 +1,5 @@
1
1
  import { Transaction } from "../coValueCore.js";
2
- import { LocalNode } from "../node.js";
2
+ import { LocalNode } from "../localNode.js";
3
3
  import { createdNowUnique, getAgentSignerSecret, newRandomAgentSecret, sign } from "../crypto.js";
4
4
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
5
5
  import { MapOpPayload } from "../coValues/coMap.js";
@@ -14,14 +14,14 @@ import {
14
14
  decryptForTransaction,
15
15
  encryptKeySecret,
16
16
  decryptKeySecret,
17
- } from '../crypto.js';
17
+ } from "../crypto.js";
18
18
  import { base58, base64url } from "@scure/base";
19
19
  import { x25519 } from "@noble/curves/ed25519";
20
20
  import { xsalsa20_poly1305 } from "@noble/ciphers/salsa";
21
21
  import { blake3 } from "@noble/hashes/blake3";
22
22
  import stableStringify from "fast-json-stable-stringify";
23
- import { SessionID } from '../ids.js';
24
- import { cojsonReady } from '../index.js';
23
+ import { SessionID } from "../ids.js";
24
+ import { cojsonReady } from "../index.js";
25
25
 
26
26
  beforeEach(async () => {
27
27
  await cojsonReady;
@@ -58,18 +58,18 @@ test("encrypting round-trips, but invalid receiver can't unseal", () => {
58
58
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
59
59
  } as const;
60
60
 
61
- const sealed = seal(
62
- data,
63
- sender,
64
- getSealerID(sealer),
65
- nOnceMaterial
66
- );
61
+ const sealed = seal({
62
+ message: data,
63
+ from: sender,
64
+ to: getSealerID(sealer),
65
+ nOnceMaterial,
66
+ });
67
67
 
68
- expect(
69
- unseal(sealed, sealer, getSealerID(sender), nOnceMaterial)
70
- ).toEqual(data);
71
- expect(
72
- () => unseal(sealed, wrongSealer, getSealerID(sender), nOnceMaterial)
68
+ expect(unseal(sealed, sealer, getSealerID(sender), nOnceMaterial)).toEqual(
69
+ data
70
+ );
71
+ expect(() =>
72
+ unseal(sealed, wrongSealer, getSealerID(sender), nOnceMaterial)
73
73
  ).toThrow(/Wrong tag/);
74
74
 
75
75
  // trying with wrong sealer secret, by hand
@@ -82,9 +82,7 @@ test("encrypting round-trips, but invalid receiver can't unseal", () => {
82
82
  const senderPub = base58.decode(
83
83
  getSealerID(sender).substring("sealer_z".length)
84
84
  );
85
- const sealedBytes = base64url.decode(
86
- sealed.substring("sealed_U".length)
87
- );
85
+ const sealedBytes = base64url.decode(sealed.substring("sealed_U".length));
88
86
  const sharedSecret = x25519.getSharedSecret(sealer3priv, senderPub);
89
87
 
90
88
  expect(() => {
@@ -105,7 +103,7 @@ test("Hashing is deterministic", () => {
105
103
  test("Encryption for transactions round-trips", () => {
106
104
  const { secret } = newRandomKeySecret();
107
105
 
108
- const encrypted1 = encryptForTransaction({ a: "hello" }, secret, {
106
+ const encrypted1 = encryptForTransaction({ a: "hello" }, secret, {
109
107
  in: "co_zTEST",
110
108
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
111
109
  });
@@ -120,7 +118,7 @@ test("Encryption for transactions round-trips", () => {
120
118
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
121
119
  });
122
120
 
123
- const decrypted2 = decryptForTransaction(encrypted2, secret, {
121
+ const decrypted2 = decryptForTransaction(encrypted2, secret, {
124
122
  in: "co_zTEST",
125
123
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 1 },
126
124
  });
@@ -132,7 +130,7 @@ test("Encryption for transactions doesn't decrypt with a wrong key", () => {
132
130
  const { secret } = newRandomKeySecret();
133
131
  const { secret: secret2 } = newRandomKeySecret();
134
132
 
135
- const encrypted1 = encryptForTransaction({ a: "hello" }, secret, {
133
+ const encrypted1 = encryptForTransaction({ a: "hello" }, secret, {
136
134
  in: "co_zTEST",
137
135
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
138
136
  });
@@ -147,7 +145,7 @@ test("Encryption for transactions doesn't decrypt with a wrong key", () => {
147
145
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 0 },
148
146
  });
149
147
 
150
- const decrypted2 = decryptForTransaction(encrypted2, secret2, {
148
+ const decrypted2 = decryptForTransaction(encrypted2, secret2, {
151
149
  in: "co_zTEST",
152
150
  tx: { sessionID: "co_zTEST_session_zTEST" as SessionID, txIndex: 1 },
153
151
  });