cojson 0.13.17 → 0.13.18

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 (166) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +9 -0
  3. package/dist/PeerState.d.ts +3 -0
  4. package/dist/PeerState.d.ts.map +1 -1
  5. package/dist/PeerState.js +9 -0
  6. package/dist/PeerState.js.map +1 -1
  7. package/dist/SyncStateManager.d.ts.map +1 -1
  8. package/dist/SyncStateManager.js +2 -3
  9. package/dist/SyncStateManager.js.map +1 -1
  10. package/dist/coValue.d.ts +4 -4
  11. package/dist/coValue.d.ts.map +1 -1
  12. package/dist/coValue.js +4 -4
  13. package/dist/coValue.js.map +1 -1
  14. package/dist/coValueCore/coValueCore.d.ts +143 -0
  15. package/dist/coValueCore/coValueCore.d.ts.map +1 -0
  16. package/dist/{coValueCore.js → coValueCore/coValueCore.js} +314 -246
  17. package/dist/coValueCore/coValueCore.js.map +1 -0
  18. package/dist/coValueCore/verifiedState.d.ts +65 -0
  19. package/dist/coValueCore/verifiedState.d.ts.map +1 -0
  20. package/dist/coValueCore/verifiedState.js +210 -0
  21. package/dist/coValueCore/verifiedState.js.map +1 -0
  22. package/dist/coValues/account.d.ts +8 -10
  23. package/dist/coValues/account.d.ts.map +1 -1
  24. package/dist/coValues/account.js +12 -13
  25. package/dist/coValues/account.js.map +1 -1
  26. package/dist/coValues/coList.d.ts +3 -3
  27. package/dist/coValues/coList.d.ts.map +1 -1
  28. package/dist/coValues/coList.js +6 -3
  29. package/dist/coValues/coList.js.map +1 -1
  30. package/dist/coValues/coMap.d.ts +3 -3
  31. package/dist/coValues/coMap.d.ts.map +1 -1
  32. package/dist/coValues/coMap.js +3 -3
  33. package/dist/coValues/coMap.js.map +1 -1
  34. package/dist/coValues/coPlainText.d.ts +2 -2
  35. package/dist/coValues/coPlainText.d.ts.map +1 -1
  36. package/dist/coValues/coPlainText.js +4 -4
  37. package/dist/coValues/coPlainText.js.map +1 -1
  38. package/dist/coValues/coStream.d.ts +3 -3
  39. package/dist/coValues/coStream.d.ts.map +1 -1
  40. package/dist/coValues/coStream.js +3 -3
  41. package/dist/coValues/coStream.js.map +1 -1
  42. package/dist/coValues/group.d.ts +7 -2
  43. package/dist/coValues/group.d.ts.map +1 -1
  44. package/dist/coValues/group.js +29 -26
  45. package/dist/coValues/group.js.map +1 -1
  46. package/dist/coreToCoValue.d.ts +2 -2
  47. package/dist/coreToCoValue.d.ts.map +1 -1
  48. package/dist/coreToCoValue.js +10 -14
  49. package/dist/coreToCoValue.js.map +1 -1
  50. package/dist/exports.d.ts +6 -5
  51. package/dist/exports.d.ts.map +1 -1
  52. package/dist/exports.js +3 -4
  53. package/dist/exports.js.map +1 -1
  54. package/dist/localNode.d.ts +30 -24
  55. package/dist/localNode.d.ts.map +1 -1
  56. package/dist/localNode.js +139 -170
  57. package/dist/localNode.js.map +1 -1
  58. package/dist/permissions.d.ts +2 -1
  59. package/dist/permissions.d.ts.map +1 -1
  60. package/dist/permissions.js +15 -11
  61. package/dist/permissions.js.map +1 -1
  62. package/dist/priority.d.ts +1 -1
  63. package/dist/priority.d.ts.map +1 -1
  64. package/dist/sync.d.ts +2 -2
  65. package/dist/sync.d.ts.map +1 -1
  66. package/dist/sync.js +86 -55
  67. package/dist/sync.js.map +1 -1
  68. package/dist/tests/coList.test.js +19 -16
  69. package/dist/tests/coList.test.js.map +1 -1
  70. package/dist/tests/coMap.test.js +12 -13
  71. package/dist/tests/coMap.test.js.map +1 -1
  72. package/dist/tests/coPlainText.test.js +9 -10
  73. package/dist/tests/coPlainText.test.js.map +1 -1
  74. package/dist/tests/coStream.test.js +22 -17
  75. package/dist/tests/coStream.test.js.map +1 -1
  76. package/dist/tests/coValueCore.test.js +22 -28
  77. package/dist/tests/coValueCore.test.js.map +1 -1
  78. package/dist/tests/coValueCoreLoadingState.test.d.ts +2 -0
  79. package/dist/tests/coValueCoreLoadingState.test.d.ts.map +1 -0
  80. package/dist/tests/{coValueState.test.js → coValueCoreLoadingState.test.js} +62 -46
  81. package/dist/tests/coValueCoreLoadingState.test.js.map +1 -0
  82. package/dist/tests/group.test.js +42 -43
  83. package/dist/tests/group.test.js.map +1 -1
  84. package/dist/tests/messagesTestUtils.d.ts +2 -2
  85. package/dist/tests/messagesTestUtils.d.ts.map +1 -1
  86. package/dist/tests/messagesTestUtils.js +1 -1
  87. package/dist/tests/messagesTestUtils.js.map +1 -1
  88. package/dist/tests/permissions.test.js +224 -292
  89. package/dist/tests/permissions.test.js.map +1 -1
  90. package/dist/tests/priority.test.js +13 -14
  91. package/dist/tests/priority.test.js.map +1 -1
  92. package/dist/tests/sync.auth.test.d.ts +2 -0
  93. package/dist/tests/sync.auth.test.d.ts.map +1 -0
  94. package/dist/tests/sync.auth.test.js +141 -0
  95. package/dist/tests/sync.auth.test.js.map +1 -0
  96. package/dist/tests/sync.load.test.js +4 -4
  97. package/dist/tests/sync.load.test.js.map +1 -1
  98. package/dist/tests/sync.mesh.test.js +25 -12
  99. package/dist/tests/sync.mesh.test.js.map +1 -1
  100. package/dist/tests/sync.peerReconciliation.test.js +19 -19
  101. package/dist/tests/sync.peerReconciliation.test.js.map +1 -1
  102. package/dist/tests/sync.storage.test.js +20 -13
  103. package/dist/tests/sync.storage.test.js.map +1 -1
  104. package/dist/tests/sync.test.js +32 -39
  105. package/dist/tests/sync.test.js.map +1 -1
  106. package/dist/tests/sync.upload.test.js +126 -37
  107. package/dist/tests/sync.upload.test.js.map +1 -1
  108. package/dist/tests/testUtils.d.ts +24 -15
  109. package/dist/tests/testUtils.d.ts.map +1 -1
  110. package/dist/tests/testUtils.js +88 -61
  111. package/dist/tests/testUtils.js.map +1 -1
  112. package/dist/typeUtils/expectGroup.js +1 -1
  113. package/dist/typeUtils/expectGroup.js.map +1 -1
  114. package/package.json +1 -1
  115. package/src/PeerState.ts +11 -0
  116. package/src/SyncStateManager.ts +2 -3
  117. package/src/coValue.ts +11 -8
  118. package/src/{coValueCore.ts → coValueCore/coValueCore.ts} +469 -413
  119. package/src/coValueCore/verifiedState.ts +376 -0
  120. package/src/coValues/account.ts +20 -25
  121. package/src/coValues/coList.ts +12 -6
  122. package/src/coValues/coMap.ts +9 -6
  123. package/src/coValues/coPlainText.ts +9 -6
  124. package/src/coValues/coStream.ts +9 -6
  125. package/src/coValues/group.ts +50 -28
  126. package/src/coreToCoValue.ts +14 -15
  127. package/src/exports.ts +9 -7
  128. package/src/localNode.ts +227 -273
  129. package/src/permissions.ts +18 -12
  130. package/src/priority.ts +1 -1
  131. package/src/sync.ts +96 -63
  132. package/src/tests/coList.test.ts +21 -15
  133. package/src/tests/coMap.test.ts +12 -13
  134. package/src/tests/coPlainText.test.ts +12 -9
  135. package/src/tests/coStream.test.ts +25 -16
  136. package/src/tests/coValueCore.test.ts +30 -27
  137. package/src/tests/{coValueState.test.ts → coValueCoreLoadingState.test.ts} +67 -57
  138. package/src/tests/group.test.ts +44 -68
  139. package/src/tests/messagesTestUtils.ts +3 -8
  140. package/src/tests/permissions.test.ts +283 -449
  141. package/src/tests/priority.test.ts +17 -13
  142. package/src/tests/sync.auth.test.ts +188 -0
  143. package/src/tests/sync.load.test.ts +4 -4
  144. package/src/tests/sync.mesh.test.ts +25 -12
  145. package/src/tests/sync.peerReconciliation.test.ts +25 -25
  146. package/src/tests/sync.storage.test.ts +20 -13
  147. package/src/tests/sync.test.ts +43 -43
  148. package/src/tests/sync.upload.test.ts +157 -37
  149. package/src/tests/testUtils.ts +120 -74
  150. package/src/typeUtils/expectGroup.ts +1 -1
  151. package/dist/CoValuesStore.d.ts +0 -14
  152. package/dist/CoValuesStore.d.ts.map +0 -1
  153. package/dist/CoValuesStore.js +0 -32
  154. package/dist/CoValuesStore.js.map +0 -1
  155. package/dist/coValueCore.d.ts +0 -142
  156. package/dist/coValueCore.d.ts.map +0 -1
  157. package/dist/coValueCore.js.map +0 -1
  158. package/dist/coValueState.d.ts +0 -34
  159. package/dist/coValueState.d.ts.map +0 -1
  160. package/dist/coValueState.js +0 -190
  161. package/dist/coValueState.js.map +0 -1
  162. package/dist/tests/coValueState.test.d.ts +0 -2
  163. package/dist/tests/coValueState.test.d.ts.map +0 -1
  164. package/dist/tests/coValueState.test.js.map +0 -1
  165. package/src/CoValuesStore.ts +0 -41
  166. package/src/coValueState.ts +0 -245
@@ -2,12 +2,11 @@ import { beforeEach, expect, test } from "vitest";
2
2
  import { expectMap } from "../coValue.js";
3
3
  import { operationToEditEntry } from "../coValues/coMap.js";
4
4
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
5
- import { LocalNode } from "../localNode.js";
6
5
  import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
7
6
  import {
8
7
  hotSleep,
9
8
  loadCoValueOrFail,
10
- randomAnonymousAccountAndSessionID,
9
+ nodeWithRandomAgentAndSessionID,
11
10
  setupTestNode,
12
11
  waitFor,
13
12
  } from "./testUtils.js";
@@ -19,7 +18,7 @@ beforeEach(async () => {
19
18
  });
20
19
 
21
20
  test("Empty CoMap works", () => {
22
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
21
+ const node = nodeWithRandomAgentAndSessionID();
23
22
 
24
23
  const coValue = node.createCoValue({
25
24
  type: "comap",
@@ -36,7 +35,7 @@ test("Empty CoMap works", () => {
36
35
  });
37
36
 
38
37
  test("Can insert and delete CoMap entries in edit()", () => {
39
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
38
+ const node = nodeWithRandomAgentAndSessionID();
40
39
 
41
40
  const coValue = node.createCoValue({
42
41
  type: "comap",
@@ -60,7 +59,7 @@ test("Can insert and delete CoMap entries in edit()", () => {
60
59
  });
61
60
 
62
61
  test("Can get CoMap entry values at different points in time", () => {
63
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
62
+ const node = nodeWithRandomAgentAndSessionID();
64
63
 
65
64
  const coValue = node.createCoValue({
66
65
  type: "comap",
@@ -110,7 +109,7 @@ test("Can get CoMap entry values at different points in time", () => {
110
109
  });
111
110
 
112
111
  test("Can get all historic values of key in CoMap", () => {
113
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
112
+ const node = nodeWithRandomAgentAndSessionID();
114
113
 
115
114
  const coValue = node.createCoValue({
116
115
  type: "comap",
@@ -134,25 +133,25 @@ test("Can get all historic values of key in CoMap", () => {
134
133
  expect([...content.editsAt("hello")]).toEqual([
135
134
  {
136
135
  tx: editA!.tx,
137
- by: node.account.id,
136
+ by: node.getCurrentAgent().id,
138
137
  value: "A",
139
138
  at: editA?.at,
140
139
  },
141
140
  {
142
141
  tx: editB!.tx,
143
- by: node.account.id,
142
+ by: node.getCurrentAgent().id,
144
143
  value: "B",
145
144
  at: editB?.at,
146
145
  },
147
146
  {
148
147
  tx: editDel!.tx,
149
- by: node.account.id,
148
+ by: node.getCurrentAgent().id,
150
149
  value: undefined,
151
150
  at: editDel?.at,
152
151
  },
153
152
  {
154
153
  tx: editC!.tx,
155
- by: node.account.id,
154
+ by: node.getCurrentAgent().id,
156
155
  value: "C",
157
156
  at: editC?.at,
158
157
  },
@@ -160,7 +159,7 @@ test("Can get all historic values of key in CoMap", () => {
160
159
  });
161
160
 
162
161
  test("Can get last tx ID for a key in CoMap", () => {
163
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
162
+ const node = nodeWithRandomAgentAndSessionID();
164
163
 
165
164
  const coValue = node.createCoValue({
166
165
  type: "comap",
@@ -177,7 +176,7 @@ test("Can get last tx ID for a key in CoMap", () => {
177
176
  content.set("hello", "A", "trusting");
178
177
  const sessionID = content.lastEditAt("hello")?.tx.sessionID;
179
178
  expect(sessionID && accountOrAgentIDfromSessionID(sessionID)).toEqual(
180
- node.account.id,
179
+ node.getCurrentAgent().id,
181
180
  );
182
181
  expect(content.lastEditAt("hello")?.tx.txIndex).toEqual(0);
183
182
  content.set("hello", "B", "trusting");
@@ -187,7 +186,7 @@ test("Can get last tx ID for a key in CoMap", () => {
187
186
  });
188
187
 
189
188
  test("Can set items in bulk with assign", () => {
190
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
189
+ const node = nodeWithRandomAgentAndSessionID();
191
190
 
192
191
  const coValue = node.createCoValue({
193
192
  type: "comap",
@@ -2,7 +2,10 @@ import { afterEach, expect, test, vi } from "vitest";
2
2
  import { expectPlainText } from "../coValue.js";
3
3
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
4
4
  import { LocalNode } from "../localNode.js";
5
- import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
5
+ import {
6
+ nodeWithRandomAgentAndSessionID,
7
+ randomAgentAndSessionID,
8
+ } from "./testUtils.js";
6
9
 
7
10
  const Crypto = await WasmCrypto.create();
8
11
 
@@ -13,7 +16,7 @@ test("should throw on creation if Intl.Segmenter is not available", () => {
13
16
  Segmenter: undefined,
14
17
  });
15
18
 
16
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
19
+ const node = nodeWithRandomAgentAndSessionID();
17
20
  const group = node.createGroup();
18
21
  expect(() => group.createPlainText()).toThrow(
19
22
  "Intl.Segmenter is not supported. Use a polyfill to get coPlainText support in Jazz. (eg. https://formatjs.github.io/docs/polyfills/intl-segmenter/)",
@@ -21,7 +24,7 @@ test("should throw on creation if Intl.Segmenter is not available", () => {
21
24
  });
22
25
 
23
26
  test("Empty CoPlainText works", () => {
24
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
27
+ const node = nodeWithRandomAgentAndSessionID();
25
28
 
26
29
  const coValue = node.createCoValue({
27
30
  type: "coplaintext",
@@ -37,7 +40,7 @@ test("Empty CoPlainText works", () => {
37
40
  });
38
41
 
39
42
  test("Can insert into empty CoPlainText", () => {
40
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
43
+ const node = nodeWithRandomAgentAndSessionID();
41
44
 
42
45
  const coValue = node.createCoValue({
43
46
  type: "coplaintext",
@@ -55,7 +58,7 @@ test("Can insert into empty CoPlainText", () => {
55
58
  });
56
59
 
57
60
  test("Can insert and delete in CoPlainText", () => {
58
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
61
+ const node = nodeWithRandomAgentAndSessionID();
59
62
 
60
63
  const coValue = node.createCoValue({
61
64
  type: "coplaintext",
@@ -88,7 +91,7 @@ test("Can insert and delete in CoPlainText", () => {
88
91
  });
89
92
 
90
93
  test("Multiple items inserted appear in correct order", () => {
91
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
94
+ const node = nodeWithRandomAgentAndSessionID();
92
95
 
93
96
  const coValue = node.createCoValue({
94
97
  type: "coplaintext",
@@ -109,7 +112,7 @@ test("Multiple items inserted appear in correct order", () => {
109
112
  });
110
113
 
111
114
  test("Items inserted at start appear with latest first", () => {
112
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
115
+ const node = nodeWithRandomAgentAndSessionID();
113
116
 
114
117
  const coValue = node.createCoValue({
115
118
  type: "coplaintext",
@@ -131,7 +134,7 @@ test("Items inserted at start appear with latest first", () => {
131
134
  });
132
135
 
133
136
  test("Handles different locales correctly", () => {
134
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
137
+ const node = nodeWithRandomAgentAndSessionID();
135
138
 
136
139
  // Test with explicit locale in meta
137
140
  const coValueJa = node.createCoValue({
@@ -175,7 +178,7 @@ test("Handles different locales correctly", () => {
175
178
  });
176
179
 
177
180
  test("insertBefore and insertAfter work as expected", () => {
178
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
181
+ const node = nodeWithRandomAgentAndSessionID();
179
182
  const coValue = node.createCoValue({
180
183
  type: "coplaintext",
181
184
  ruleset: { type: "unsafeAllowAll" },
@@ -1,6 +1,6 @@
1
1
  import { beforeEach, describe, expect, test } from "vitest";
2
2
  import { expectStream } from "../coValue.js";
3
- import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
3
+ import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore/coValueCore.js";
4
4
  import {
5
5
  BinaryStreamItem,
6
6
  CoStreamItem,
@@ -12,7 +12,8 @@ import { SessionID } from "../ids.js";
12
12
  import { LocalNode } from "../localNode.js";
13
13
  import {
14
14
  loadCoValueOrFail,
15
- randomAnonymousAccountAndSessionID,
15
+ nodeWithRandomAgentAndSessionID,
16
+ randomAgentAndSessionID,
16
17
  setupTestNode,
17
18
  waitFor,
18
19
  } from "./testUtils.js";
@@ -24,7 +25,7 @@ beforeEach(async () => {
24
25
  });
25
26
 
26
27
  test("Empty CoStream works", () => {
27
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
28
+ const node = nodeWithRandomAgentAndSessionID();
28
29
 
29
30
  const coValue = node.createCoValue({
30
31
  type: "costream",
@@ -41,7 +42,7 @@ test("Empty CoStream works", () => {
41
42
  });
42
43
 
43
44
  test("Can push into CoStream", () => {
44
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
45
+ const node = nodeWithRandomAgentAndSessionID();
45
46
 
46
47
  const coValue = node.createCoValue({
47
48
  type: "costream",
@@ -67,7 +68,7 @@ test("Can push into CoStream", () => {
67
68
  });
68
69
 
69
70
  test("Empty RawBinaryCoStream works", () => {
70
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
71
+ const node = nodeWithRandomAgentAndSessionID();
71
72
 
72
73
  const coValue = node.createCoValue({
73
74
  type: "costream",
@@ -93,7 +94,7 @@ test("Empty RawBinaryCoStream works", () => {
93
94
  });
94
95
 
95
96
  test("Can push into RawBinaryCoStream", () => {
96
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
97
+ const node = nodeWithRandomAgentAndSessionID();
97
98
 
98
99
  const coValue = node.createCoValue({
99
100
  type: "costream",
@@ -129,7 +130,7 @@ test("Can push into RawBinaryCoStream", () => {
129
130
  });
130
131
 
131
132
  test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE), we store an inbetween signature every time we reach MAX_RECOMMENDED_TX_SIZE and split up newContentSince accordingly", () => {
132
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
133
+ const node = nodeWithRandomAgentAndSessionID();
133
134
 
134
135
  const coValue = node.createCoValue({
135
136
  type: "costream",
@@ -161,7 +162,11 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
161
162
 
162
163
  content.endBinaryStream("trusting");
163
164
 
164
- const sessionEntry = coValue.sessionLogs.get(node.currentSessionID)!;
165
+ if (!coValue.isAvailable()) {
166
+ throw new Error("CoValue is not available");
167
+ }
168
+
169
+ const sessionEntry = coValue.verified.sessions.get(node.currentSessionID)!;
165
170
  expect(sessionEntry.transactions.length).toEqual(12);
166
171
  expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
167
172
  expect(sessionEntry.signatureAfter[1]).not.toBeDefined();
@@ -176,7 +181,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
176
181
  expect(sessionEntry.signatureAfter[10]).not.toBeDefined();
177
182
  expect(sessionEntry.signatureAfter[11]).not.toBeDefined();
178
183
 
179
- const newContent = coValue.newContentSince({
184
+ const newContent = coValue.verified.newContentSince({
180
185
  id: coValue.id,
181
186
  header: false,
182
187
  sessions: {},
@@ -199,7 +204,7 @@ test("When adding large transactions (small fraction of MAX_RECOMMENDED_TX_SIZE)
199
204
  });
200
205
 
201
206
  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", () => {
202
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
207
+ const node = nodeWithRandomAgentAndSessionID();
203
208
 
204
209
  const coValue = node.createCoValue({
205
210
  type: "costream",
@@ -231,7 +236,11 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
231
236
 
232
237
  content.endBinaryStream("trusting");
233
238
 
234
- const sessionEntry = coValue.sessionLogs.get(node.currentSessionID)!;
239
+ if (!coValue.isAvailable()) {
240
+ throw new Error("CoValue is not available");
241
+ }
242
+
243
+ const sessionEntry = coValue.verified.sessions.get(node.currentSessionID)!;
235
244
  expect(sessionEntry.transactions.length).toEqual(5);
236
245
  expect(sessionEntry.signatureAfter[0]).not.toBeDefined();
237
246
  expect(sessionEntry.signatureAfter[1]).toBeDefined();
@@ -239,7 +248,7 @@ test("When adding large transactions (bigger than MAX_RECOMMENDED_TX_SIZE), we s
239
248
  expect(sessionEntry.signatureAfter[3]).toBeDefined();
240
249
  expect(sessionEntry.signatureAfter[4]).not.toBeDefined();
241
250
 
242
- const newContent = coValue.newContentSince({
251
+ const newContent = coValue.verified.newContentSince({
243
252
  id: coValue.id,
244
253
  header: false,
245
254
  sessions: {},
@@ -308,7 +317,7 @@ test("totalValidTransactions should return the number of valid transactions proc
308
317
 
309
318
  describe("isBinaryStreamEnded", () => {
310
319
  function setup() {
311
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
320
+ const node = nodeWithRandomAgentAndSessionID();
312
321
 
313
322
  const coValue = node.createCoValue({
314
323
  type: "costream",
@@ -371,7 +380,7 @@ describe("Binary stream order", () => {
371
380
  }
372
381
 
373
382
  test("sorts by madeAt timestamp first", () => {
374
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
383
+ const node = nodeWithRandomAgentAndSessionID();
375
384
  const coValue = node.createCoValue({
376
385
  type: "costream",
377
386
  ruleset: { type: "unsafeAllowAll" },
@@ -403,7 +412,7 @@ describe("Binary stream order", () => {
403
412
  });
404
413
 
405
414
  test("sorts by sessionID when timestamps are equal", () => {
406
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
415
+ const node = nodeWithRandomAgentAndSessionID();
407
416
  const coValue = node.createCoValue({
408
417
  type: "costream",
409
418
  ruleset: { type: "unsafeAllowAll" },
@@ -436,7 +445,7 @@ describe("Binary stream order", () => {
436
445
  });
437
446
 
438
447
  test("sorts by txIndex when timestamps and sessionIDs are equal", () => {
439
- const node = new LocalNode(...randomAnonymousAccountAndSessionID(), Crypto);
448
+ const node = nodeWithRandomAgentAndSessionID();
440
449
  const coValue = node.createCoValue({
441
450
  type: "costream",
442
451
  ruleset: { type: "unsafeAllowAll" },
@@ -1,5 +1,6 @@
1
1
  import { assert, afterEach, beforeEach, expect, test, vi } from "vitest";
2
- import { CoValueCore, Transaction } from "../coValueCore.js";
2
+ import { CoValueCore } from "../coValueCore/coValueCore.js";
3
+ import { Transaction } from "../coValueCore/verifiedState.js";
3
4
  import { MapOpPayload } from "../coValues/coMap.js";
4
5
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
5
6
  import { stableStringify } from "../jsonStringify.js";
@@ -10,7 +11,8 @@ import {
10
11
  createTestNode,
11
12
  createTwoConnectedNodes,
12
13
  loadCoValueOrFail,
13
- randomAnonymousAccountAndSessionID,
14
+ nodeWithRandomAgentAndSessionID,
15
+ randomAgentAndSessionID,
14
16
  tearDownTestMetricReader,
15
17
  } from "./testUtils.js";
16
18
 
@@ -27,8 +29,8 @@ afterEach(() => {
27
29
  });
28
30
 
29
31
  test("Can create coValue with new agent credentials and add transaction to it", () => {
30
- const [account, sessionID] = randomAnonymousAccountAndSessionID();
31
- const node = new LocalNode(account, sessionID, Crypto);
32
+ const [agent, sessionID] = randomAgentAndSessionID();
33
+ const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
32
34
 
33
35
  const coValue = node.createCoValue({
34
36
  type: "costream",
@@ -47,7 +49,7 @@ test("Can create coValue with new agent credentials and add transaction to it",
47
49
  ]),
48
50
  };
49
51
 
50
- const { expectedNewHash } = coValue.expectedNewHashAfter(
52
+ const { expectedNewHash } = coValue.verified.expectedNewHashAfter(
51
53
  node.currentSessionID,
52
54
  [transaction],
53
55
  );
@@ -58,7 +60,8 @@ test("Can create coValue with new agent credentials and add transaction to it",
58
60
  node.currentSessionID,
59
61
  [transaction],
60
62
  expectedNewHash,
61
- Crypto.sign(account.currentSignerSecret(), expectedNewHash),
63
+ Crypto.sign(agent.currentSignerSecret(), expectedNewHash),
64
+ "immediate",
62
65
  )
63
66
  ._unsafeUnwrap(),
64
67
  ).toBe(true);
@@ -66,8 +69,7 @@ test("Can create coValue with new agent credentials and add transaction to it",
66
69
 
67
70
  test("transactions with wrong signature are rejected", () => {
68
71
  const wrongAgent = Crypto.newRandomAgentSecret();
69
- const [agentSecret, sessionID] = randomAnonymousAccountAndSessionID();
70
- const node = new LocalNode(agentSecret, sessionID, Crypto);
72
+ const node = nodeWithRandomAgentAndSessionID();
71
73
 
72
74
  const coValue = node.createCoValue({
73
75
  type: "costream",
@@ -86,7 +88,7 @@ test("transactions with wrong signature are rejected", () => {
86
88
  ]),
87
89
  };
88
90
 
89
- const { expectedNewHash } = coValue.expectedNewHashAfter(
91
+ const { expectedNewHash } = coValue.verified.expectedNewHashAfter(
90
92
  node.currentSessionID,
91
93
  [transaction],
92
94
  );
@@ -98,13 +100,14 @@ test("transactions with wrong signature are rejected", () => {
98
100
  [transaction],
99
101
  expectedNewHash,
100
102
  Crypto.sign(Crypto.getAgentSignerSecret(wrongAgent), expectedNewHash),
103
+ "immediate",
101
104
  )
102
105
  ._unsafeUnwrapErr({ withStackTrace: true });
103
106
  });
104
107
 
105
108
  test("transactions with correctly signed, but wrong hash are rejected", () => {
106
- const [account, sessionID] = randomAnonymousAccountAndSessionID();
107
- const node = new LocalNode(account, sessionID, Crypto);
109
+ const [agent, sessionID] = randomAgentAndSessionID();
110
+ const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
108
111
 
109
112
  const coValue = node.createCoValue({
110
113
  type: "costream",
@@ -123,7 +126,7 @@ test("transactions with correctly signed, but wrong hash are rejected", () => {
123
126
  ]),
124
127
  };
125
128
 
126
- const { expectedNewHash } = coValue.expectedNewHashAfter(
129
+ const { expectedNewHash } = coValue.verified.expectedNewHashAfter(
127
130
  node.currentSessionID,
128
131
  [
129
132
  {
@@ -144,14 +147,15 @@ test("transactions with correctly signed, but wrong hash are rejected", () => {
144
147
  node.currentSessionID,
145
148
  [transaction],
146
149
  expectedNewHash,
147
- Crypto.sign(account.currentSignerSecret(), expectedNewHash),
150
+ Crypto.sign(agent.currentSignerSecret(), expectedNewHash),
151
+ "immediate",
148
152
  )
149
153
  ._unsafeUnwrapErr({ withStackTrace: true });
150
154
  });
151
155
 
152
156
  test("New transactions in a group correctly update owned values, including subscriptions", async () => {
153
- const [account, sessionID] = randomAnonymousAccountAndSessionID();
154
- const node = new LocalNode(account, sessionID, Crypto);
157
+ const [agent, sessionID] = randomAgentAndSessionID();
158
+ const node = new LocalNode(agent.agentSecret, sessionID, Crypto);
155
159
 
156
160
  const group = node.createGroup();
157
161
 
@@ -175,18 +179,19 @@ test("New transactions in a group correctly update owned values, including subsc
175
179
  changes: stableStringify([
176
180
  {
177
181
  op: "set",
178
- key: account.id,
182
+ key: agent.id,
179
183
  value: "revoked",
180
- } satisfies MapOpPayload<typeof account.id, Role>,
184
+ } satisfies MapOpPayload<typeof agent.id, Role>,
181
185
  ]),
182
186
  } satisfies Transaction;
183
187
 
184
- const { expectedNewHash } = group.core.expectedNewHashAfter(sessionID, [
185
- resignationThatWeJustLearnedAbout,
186
- ]);
188
+ const { expectedNewHash } = group.core.verified.expectedNewHashAfter(
189
+ sessionID,
190
+ [resignationThatWeJustLearnedAbout],
191
+ );
187
192
 
188
193
  const signature = Crypto.sign(
189
- node.account.currentSignerSecret(),
194
+ node.getCurrentAgent().currentSignerSecret(),
190
195
  expectedNewHash,
191
196
  );
192
197
 
@@ -198,6 +203,7 @@ test("New transactions in a group correctly update owned values, including subsc
198
203
  [resignationThatWeJustLearnedAbout],
199
204
  expectedNewHash,
200
205
  signature,
206
+ "immediate",
201
207
  )
202
208
  ._unsafeUnwrap({ withStackTrace: true });
203
209
 
@@ -210,8 +216,7 @@ test("New transactions in a group correctly update owned values, including subsc
210
216
  });
211
217
 
212
218
  test("correctly records transactions", async () => {
213
- const [account, sessionID] = randomAnonymousAccountAndSessionID();
214
- const node = new LocalNode(account, sessionID, Crypto);
219
+ const node = nodeWithRandomAgentAndSessionID();
215
220
 
216
221
  const changes1 = stableStringify([{ hello: "world" }]);
217
222
  node.syncManager.recordTransactionsSize(
@@ -253,8 +258,7 @@ test("correctly records transactions", async () => {
253
258
  });
254
259
 
255
260
  test("(smoke test) records transactions from local node", async () => {
256
- const [account, sessionID] = randomAnonymousAccountAndSessionID();
257
- const node = new LocalNode(account, sessionID, Crypto);
261
+ const node = nodeWithRandomAgentAndSessionID();
258
262
 
259
263
  node.createGroup();
260
264
 
@@ -294,8 +298,7 @@ test("creating a coValue with a group should't trigger automatically a content c
294
298
  });
295
299
 
296
300
  test("loading a coValue core without having the owner group available doesn't crash", () => {
297
- const [account, sessionID] = randomAnonymousAccountAndSessionID();
298
- const node = new LocalNode(account, sessionID, Crypto);
301
+ const node = nodeWithRandomAgentAndSessionID();
299
302
 
300
303
  const otherNode = createTestNode();
301
304