cojson 0.7.35 → 0.8.3

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 (222) hide show
  1. package/.turbo/turbo-build.log +2 -7
  2. package/.turbo/turbo-lint.log +4 -0
  3. package/CHANGELOG.md +13 -0
  4. package/dist/{PeerState.js → native/PeerState.js} +13 -5
  5. package/dist/native/PeerState.js.map +1 -0
  6. package/dist/native/PriorityBasedMessageQueue.js.map +1 -0
  7. package/dist/native/base64url.js.map +1 -0
  8. package/dist/native/base64url.test.js.map +1 -0
  9. package/dist/native/coValue.js.map +1 -0
  10. package/dist/{coValueCore.js → native/coValueCore.js} +0 -6
  11. package/dist/native/coValueCore.js.map +1 -0
  12. package/dist/{coValues → native/coValues}/account.js +2 -3
  13. package/dist/native/coValues/account.js.map +1 -0
  14. package/dist/native/coValues/coList.js.map +1 -0
  15. package/dist/native/coValues/coMap.js.map +1 -0
  16. package/dist/native/coValues/coStream.js.map +1 -0
  17. package/dist/{coValues → native/coValues}/group.js +8 -8
  18. package/dist/native/coValues/group.js.map +1 -0
  19. package/dist/native/coreToCoValue.js.map +1 -0
  20. package/dist/{crypto → native/crypto}/PureJSCrypto.js +4 -0
  21. package/dist/native/crypto/PureJSCrypto.js.map +1 -0
  22. package/dist/{crypto → native/crypto}/crypto.js +4 -1
  23. package/dist/native/crypto/crypto.js.map +1 -0
  24. package/dist/native/ids.js.map +1 -0
  25. package/dist/{index.js → native/index.native.js} +4 -6
  26. package/dist/native/index.native.js.map +1 -0
  27. package/dist/native/jsonStringify.js.map +1 -0
  28. package/dist/{jsonValue.js.map → native/jsonValue.js.map} +1 -1
  29. package/dist/{localNode.js → native/localNode.js} +44 -38
  30. package/dist/native/localNode.js.map +1 -0
  31. package/dist/native/media.js.map +1 -0
  32. package/dist/native/permissions.js.map +1 -0
  33. package/dist/native/priority.js.map +1 -0
  34. package/dist/native/storage/FileSystem.js.map +1 -0
  35. package/dist/{storage → native/storage}/chunksAndKnownStates.js +1 -1
  36. package/dist/native/storage/chunksAndKnownStates.js.map +1 -0
  37. package/dist/native/storage/index.js.map +1 -0
  38. package/dist/native/streamUtils.js.map +1 -0
  39. package/dist/native/sync.js.map +1 -0
  40. package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -0
  41. package/dist/native/typeUtils/expectGroup.js.map +1 -0
  42. package/dist/native/typeUtils/isAccountID.js.map +1 -0
  43. package/dist/native/typeUtils/isCoValue.js.map +1 -0
  44. package/dist/web/PeerState.js +66 -0
  45. package/dist/web/PeerState.js.map +1 -0
  46. package/dist/web/PriorityBasedMessageQueue.js +51 -0
  47. package/dist/web/PriorityBasedMessageQueue.js.map +1 -0
  48. package/dist/web/base64url.js +59 -0
  49. package/dist/web/base64url.js.map +1 -0
  50. package/dist/web/base64url.test.js +25 -0
  51. package/dist/web/base64url.test.js.map +1 -0
  52. package/dist/web/coValue.js +19 -0
  53. package/dist/web/coValue.js.map +1 -0
  54. package/dist/web/coValueCore.js +693 -0
  55. package/dist/web/coValueCore.js.map +1 -0
  56. package/dist/web/coValues/account.js +96 -0
  57. package/dist/web/coValues/account.js.map +1 -0
  58. package/dist/web/coValues/coList.js +393 -0
  59. package/dist/web/coValues/coList.js.map +1 -0
  60. package/dist/web/coValues/coMap.js +197 -0
  61. package/dist/web/coValues/coMap.js.map +1 -0
  62. package/dist/web/coValues/coStream.js +220 -0
  63. package/dist/web/coValues/coStream.js.map +1 -0
  64. package/dist/web/coValues/group.js +250 -0
  65. package/dist/web/coValues/group.js.map +1 -0
  66. package/dist/web/coreToCoValue.js +42 -0
  67. package/dist/web/coreToCoValue.js.map +1 -0
  68. package/dist/web/crypto/PureJSCrypto.js +93 -0
  69. package/dist/web/crypto/PureJSCrypto.js.map +1 -0
  70. package/dist/{crypto → web/crypto}/WasmCrypto.js +3 -0
  71. package/dist/web/crypto/WasmCrypto.js.map +1 -0
  72. package/dist/web/crypto/crypto.js +154 -0
  73. package/dist/web/crypto/crypto.js.map +1 -0
  74. package/dist/web/ids.js +17 -0
  75. package/dist/web/ids.js.map +1 -0
  76. package/dist/web/index.web.js +40 -0
  77. package/dist/web/index.web.js.map +1 -0
  78. package/dist/web/jsonStringify.js +57 -0
  79. package/dist/web/jsonStringify.js.map +1 -0
  80. package/dist/web/jsonValue.js +2 -0
  81. package/dist/web/jsonValue.js.map +1 -0
  82. package/dist/web/localNode.js +442 -0
  83. package/dist/web/localNode.js.map +1 -0
  84. package/dist/web/media.js +2 -0
  85. package/dist/web/media.js.map +1 -0
  86. package/dist/web/permissions.js +206 -0
  87. package/dist/web/permissions.js.map +1 -0
  88. package/dist/web/priority.js +31 -0
  89. package/dist/web/priority.js.map +1 -0
  90. package/dist/web/storage/FileSystem.js +58 -0
  91. package/dist/web/storage/FileSystem.js.map +1 -0
  92. package/dist/web/storage/chunksAndKnownStates.js +100 -0
  93. package/dist/web/storage/chunksAndKnownStates.js.map +1 -0
  94. package/dist/web/storage/index.js +348 -0
  95. package/dist/web/storage/index.js.map +1 -0
  96. package/dist/web/streamUtils.js +41 -0
  97. package/dist/web/streamUtils.js.map +1 -0
  98. package/dist/web/sync.js +504 -0
  99. package/dist/web/sync.js.map +1 -0
  100. package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js +5 -0
  101. package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -0
  102. package/dist/web/typeUtils/expectGroup.js +13 -0
  103. package/dist/web/typeUtils/expectGroup.js.map +1 -0
  104. package/dist/web/typeUtils/isAccountID.js +4 -0
  105. package/dist/web/typeUtils/isAccountID.js.map +1 -0
  106. package/dist/web/typeUtils/isCoValue.js +11 -0
  107. package/dist/web/typeUtils/isCoValue.js.map +1 -0
  108. package/package.json +25 -8
  109. package/src/PeerState.ts +18 -7
  110. package/src/coValue.ts +1 -1
  111. package/src/coValueCore.ts +9 -14
  112. package/src/coValues/account.ts +12 -7
  113. package/src/coValues/coList.ts +4 -4
  114. package/src/coValues/coMap.ts +3 -3
  115. package/src/coValues/coStream.ts +8 -8
  116. package/src/coValues/group.ts +15 -11
  117. package/src/crypto/PureJSCrypto.ts +5 -0
  118. package/src/crypto/WasmCrypto.ts +4 -0
  119. package/src/crypto/crypto.ts +11 -1
  120. package/src/ids.ts +2 -2
  121. package/src/{index.ts → index.native.ts} +7 -8
  122. package/src/index.web.ts +152 -0
  123. package/src/localNode.ts +75 -67
  124. package/src/permissions.ts +5 -5
  125. package/src/storage/chunksAndKnownStates.ts +1 -1
  126. package/src/storage/index.ts +1 -1
  127. package/src/tests/account.test.ts +1 -2
  128. package/src/tests/coList.test.ts +1 -1
  129. package/src/tests/coMap.test.ts +1 -1
  130. package/src/tests/coStream.test.ts +2 -1
  131. package/src/tests/cryptoImpl.test.ts +24 -2
  132. package/src/tests/group.test.ts +6 -8
  133. package/src/tests/permissions.test.ts +90 -43
  134. package/src/tests/priority.test.ts +44 -15
  135. package/src/tests/sync.test.ts +8 -8
  136. package/src/tests/testUtils.ts +1 -2
  137. package/src/typeUtils/accountOrAgentIDfromSessionID.ts +3 -3
  138. package/src/typeUtils/isAccountID.ts +2 -2
  139. package/tsconfig.json +5 -4
  140. package/tsconfig.native.json +12 -0
  141. package/tsconfig.web.json +11 -0
  142. package/dist/PeerState.js.map +0 -1
  143. package/dist/PriorityBasedMessageQueue.js.map +0 -1
  144. package/dist/base64url.js.map +0 -1
  145. package/dist/base64url.test.js.map +0 -1
  146. package/dist/coValue.js.map +0 -1
  147. package/dist/coValueCore.js.map +0 -1
  148. package/dist/coValues/account.js.map +0 -1
  149. package/dist/coValues/coList.js.map +0 -1
  150. package/dist/coValues/coMap.js.map +0 -1
  151. package/dist/coValues/coStream.js.map +0 -1
  152. package/dist/coValues/group.js.map +0 -1
  153. package/dist/coreToCoValue.js.map +0 -1
  154. package/dist/crypto/PureJSCrypto.js.map +0 -1
  155. package/dist/crypto/WasmCrypto.js.map +0 -1
  156. package/dist/crypto/crypto.js.map +0 -1
  157. package/dist/ids.js.map +0 -1
  158. package/dist/index.js.map +0 -1
  159. package/dist/jsonStringify.js.map +0 -1
  160. package/dist/localNode.js.map +0 -1
  161. package/dist/media.js.map +0 -1
  162. package/dist/permissions.js.map +0 -1
  163. package/dist/priority.js.map +0 -1
  164. package/dist/storage/FileSystem.js.map +0 -1
  165. package/dist/storage/chunksAndKnownStates.js.map +0 -1
  166. package/dist/storage/index.js.map +0 -1
  167. package/dist/streamUtils.js.map +0 -1
  168. package/dist/sync.js.map +0 -1
  169. package/dist/tests/PeerState.test.js +0 -80
  170. package/dist/tests/PeerState.test.js.map +0 -1
  171. package/dist/tests/PriorityBasedMessageQueue.test.js +0 -97
  172. package/dist/tests/PriorityBasedMessageQueue.test.js.map +0 -1
  173. package/dist/tests/account.test.js +0 -59
  174. package/dist/tests/account.test.js.map +0 -1
  175. package/dist/tests/coList.test.js +0 -76
  176. package/dist/tests/coList.test.js.map +0 -1
  177. package/dist/tests/coMap.test.js +0 -136
  178. package/dist/tests/coMap.test.js.map +0 -1
  179. package/dist/tests/coStream.test.js +0 -205
  180. package/dist/tests/coStream.test.js.map +0 -1
  181. package/dist/tests/coValueCore.test.js +0 -124
  182. package/dist/tests/coValueCore.test.js.map +0 -1
  183. package/dist/tests/crypto.test.js +0 -118
  184. package/dist/tests/crypto.test.js.map +0 -1
  185. package/dist/tests/cryptoImpl.test.js +0 -113
  186. package/dist/tests/cryptoImpl.test.js.map +0 -1
  187. package/dist/tests/group.test.js +0 -34
  188. package/dist/tests/group.test.js.map +0 -1
  189. package/dist/tests/permissions.test.js +0 -1060
  190. package/dist/tests/permissions.test.js.map +0 -1
  191. package/dist/tests/priority.test.js +0 -61
  192. package/dist/tests/priority.test.js.map +0 -1
  193. package/dist/tests/sync.test.js +0 -1187
  194. package/dist/tests/sync.test.js.map +0 -1
  195. package/dist/tests/testUtils.js +0 -60
  196. package/dist/tests/testUtils.js.map +0 -1
  197. package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +0 -1
  198. package/dist/typeUtils/expectGroup.js.map +0 -1
  199. package/dist/typeUtils/isAccountID.js.map +0 -1
  200. package/dist/typeUtils/isCoValue.js.map +0 -1
  201. /package/dist/{PriorityBasedMessageQueue.js → native/PriorityBasedMessageQueue.js} +0 -0
  202. /package/dist/{base64url.js → native/base64url.js} +0 -0
  203. /package/dist/{base64url.test.js → native/base64url.test.js} +0 -0
  204. /package/dist/{coValue.js → native/coValue.js} +0 -0
  205. /package/dist/{coValues → native/coValues}/coList.js +0 -0
  206. /package/dist/{coValues → native/coValues}/coMap.js +0 -0
  207. /package/dist/{coValues → native/coValues}/coStream.js +0 -0
  208. /package/dist/{coreToCoValue.js → native/coreToCoValue.js} +0 -0
  209. /package/dist/{ids.js → native/ids.js} +0 -0
  210. /package/dist/{jsonStringify.js → native/jsonStringify.js} +0 -0
  211. /package/dist/{jsonValue.js → native/jsonValue.js} +0 -0
  212. /package/dist/{media.js → native/media.js} +0 -0
  213. /package/dist/{permissions.js → native/permissions.js} +0 -0
  214. /package/dist/{priority.js → native/priority.js} +0 -0
  215. /package/dist/{storage → native/storage}/FileSystem.js +0 -0
  216. /package/dist/{storage → native/storage}/index.js +0 -0
  217. /package/dist/{streamUtils.js → native/streamUtils.js} +0 -0
  218. /package/dist/{sync.js → native/sync.js} +0 -0
  219. /package/dist/{typeUtils → native/typeUtils}/accountOrAgentIDfromSessionID.js +0 -0
  220. /package/dist/{typeUtils → native/typeUtils}/expectGroup.js +0 -0
  221. /package/dist/{typeUtils → native/typeUtils}/isAccountID.js +0 -0
  222. /package/dist/{typeUtils → native/typeUtils}/isCoValue.js +0 -0
@@ -0,0 +1,152 @@
1
+ import { WasmCrypto } from "./crypto/WasmCrypto.js";
2
+
3
+ import {
4
+ CoValueCore,
5
+ type CoValueUniqueness,
6
+ MAX_RECOMMENDED_TX_SIZE,
7
+ idforHeader,
8
+ } from "./coValueCore.js";
9
+ import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromSessionID.js";
10
+ import { LocalNode } from "./localNode.js";
11
+ import { type RawCoValue } from "./coValue.js";
12
+ import { RawCoMap } from "./coValues/coMap.js";
13
+ import { RawCoList } from "./coValues/coList.js";
14
+ import { RawCoStream, RawBinaryCoStream } from "./coValues/coStream.js";
15
+ import {
16
+ secretSeedLength,
17
+ shortHashLength,
18
+ StreamingHash,
19
+ CryptoProvider,
20
+ } from "./crypto/crypto.js";
21
+ import { connectedPeers, Channel } from "./streamUtils.js";
22
+ import { ControlledAgent, RawControlledAccount } from "./coValues/account.js";
23
+ import type { Role } from "./permissions.js";
24
+ import { rawCoIDtoBytes, rawCoIDfromBytes, isRawCoID } from "./ids.js";
25
+ import { RawGroup, EVERYONE } from "./coValues/group.js";
26
+ import type { Everyone } from "./coValues/group.js";
27
+ import { base64URLtoBytes, bytesToBase64url } from "./base64url.js";
28
+ import { parseJSON } from "./jsonStringify.js";
29
+ import {
30
+ RawAccount,
31
+ RawProfile,
32
+ accountHeaderForInitialAgentSecret,
33
+ } from "./coValues/account.js";
34
+ import { expectGroup } from "./typeUtils/expectGroup.js";
35
+ import { isAccountID } from "./typeUtils/isAccountID.js";
36
+
37
+ import type { SessionID, AgentID } from "./ids.js";
38
+ import type { CoID, AnyRawCoValue } from "./coValue.js";
39
+ import type {
40
+ BinaryStreamInfo,
41
+ BinaryCoStreamMeta,
42
+ } from "./coValues/coStream.js";
43
+ import type { JsonValue } from "./jsonValue.js";
44
+ import type {
45
+ SyncMessage,
46
+ Peer,
47
+ IncomingSyncStream,
48
+ OutgoingSyncQueue,
49
+ } from "./sync.js";
50
+ import { DisconnectedError, PingTimeoutError } from "./sync.js";
51
+ import type { AgentSecret } from "./crypto/crypto.js";
52
+ import type {
53
+ RawAccountID,
54
+ AccountMeta,
55
+ RawAccountMigration,
56
+ } from "./coValues/account.js";
57
+ import type { InviteSecret } from "./coValues/group.js";
58
+ import type * as Media from "./media.js";
59
+
60
+ type Value = JsonValue | AnyRawCoValue;
61
+
62
+ import { LSMStorage, BlockFilename, WalFilename } from "./storage/index.js";
63
+ import { FileSystem } from "./storage/FileSystem.js";
64
+ import { getPriorityFromHeader } from "./priority.js";
65
+
66
+ /** @hidden */
67
+ export const cojsonInternals = {
68
+ connectedPeers,
69
+ rawCoIDtoBytes,
70
+ rawCoIDfromBytes,
71
+ secretSeedLength,
72
+ shortHashLength,
73
+ expectGroup,
74
+ base64URLtoBytes,
75
+ bytesToBase64url,
76
+ parseJSON,
77
+ accountOrAgentIDfromSessionID,
78
+ isAccountID,
79
+ accountHeaderForInitialAgentSecret,
80
+ idforHeader,
81
+ StreamingHash,
82
+ Channel,
83
+ getPriorityFromHeader,
84
+ };
85
+
86
+ export {
87
+ LocalNode,
88
+ RawGroup,
89
+ Role,
90
+ EVERYONE,
91
+ Everyone,
92
+ RawCoMap,
93
+ RawCoList,
94
+ RawCoStream,
95
+ RawBinaryCoStream,
96
+ RawCoValue,
97
+ CoID,
98
+ AnyRawCoValue,
99
+ RawAccount,
100
+ RawAccountID,
101
+ AccountMeta,
102
+ RawAccountMigration,
103
+ RawProfile as Profile,
104
+ SessionID,
105
+ Media,
106
+ CoValueCore,
107
+ ControlledAgent,
108
+ RawControlledAccount,
109
+ MAX_RECOMMENDED_TX_SIZE,
110
+ JsonValue,
111
+ Peer,
112
+ BinaryStreamInfo,
113
+ BinaryCoStreamMeta,
114
+ AgentID,
115
+ AgentSecret,
116
+ InviteSecret,
117
+ CryptoProvider,
118
+ SyncMessage,
119
+ isRawCoID,
120
+ LSMStorage,
121
+ WasmCrypto,
122
+ };
123
+
124
+ export type {
125
+ Value,
126
+ FileSystem,
127
+ BlockFilename,
128
+ WalFilename,
129
+ IncomingSyncStream,
130
+ OutgoingSyncQueue,
131
+ DisconnectedError,
132
+ PingTimeoutError,
133
+ CoValueUniqueness,
134
+ };
135
+
136
+ // eslint-disable-next-line @typescript-eslint/no-namespace
137
+ export namespace CojsonInternalTypes {
138
+ export type CoValueKnownState = import("./sync.js").CoValueKnownState;
139
+ export type DoneMessage = import("./sync.js").DoneMessage;
140
+ export type KnownStateMessage = import("./sync.js").KnownStateMessage;
141
+ export type LoadMessage = import("./sync.js").LoadMessage;
142
+ export type NewContentMessage = import("./sync.js").NewContentMessage;
143
+ export type CoValueHeader = import("./coValueCore.js").CoValueHeader;
144
+ export type Transaction = import("./coValueCore.js").Transaction;
145
+ export type TransactionID = import("./ids.js").TransactionID;
146
+ export type Signature = import("./crypto/crypto.js").Signature;
147
+ export type RawCoID = import("./ids.js").RawCoID;
148
+ export type ProfileShape = import("./coValues/account.js").ProfileShape;
149
+ export type SealerSecret = import("./crypto/crypto.js").SealerSecret;
150
+ export type SignerSecret = import("./crypto/crypto.js").SignerSecret;
151
+ export type JsonObject = import("./jsonValue.js").JsonObject;
152
+ }
package/src/localNode.ts CHANGED
@@ -2,7 +2,7 @@ import { AgentSecret, CryptoProvider } from "./crypto/crypto.js";
2
2
  import {
3
3
  CoValueCore,
4
4
  CoValueHeader,
5
- newRandomSessionID,
5
+ CoValueUniqueness,
6
6
  } from "./coValueCore.js";
7
7
  import {
8
8
  InviteSecret,
@@ -19,12 +19,13 @@ import {
19
19
  ControlledAccountOrAgent,
20
20
  RawControlledAccount,
21
21
  ControlledAgent,
22
- AccountID,
22
+ RawAccountID,
23
23
  RawProfile,
24
+ RawProfile as Profile,
24
25
  RawAccountMigration,
25
26
  InvalidAccountAgentIDError,
26
27
  } from "./coValues/account.js";
27
- import { Profile, RawCoValue } from "./index.js";
28
+ import { RawCoValue } from "./coValue.js";
28
29
  import { expectGroup } from "./typeUtils/expectGroup.js";
29
30
  import { err, ok, okAsync, Result, ResultAsync } from "neverthrow";
30
31
 
@@ -81,14 +82,14 @@ export class LocalNode {
81
82
  initialAgentSecret?: AgentSecret;
82
83
  }): Promise<{
83
84
  node: LocalNode;
84
- accountID: AccountID;
85
+ accountID: RawAccountID;
85
86
  accountSecret: AgentSecret;
86
87
  sessionID: SessionID;
87
88
  }> {
88
89
  const throwawayAgent = crypto.newRandomAgentSecret();
89
90
  const setupNode = new LocalNode(
90
91
  new ControlledAgent(throwawayAgent, crypto),
91
- newRandomSessionID(crypto.getAgentID(throwawayAgent)),
92
+ crypto.newRandomSessionID(crypto.getAgentID(throwawayAgent)),
92
93
  crypto,
93
94
  );
94
95
 
@@ -96,7 +97,7 @@ export class LocalNode {
96
97
 
97
98
  const nodeWithAccount = account.core.node.testWithDifferentAccount(
98
99
  account,
99
- newRandomSessionID(account.id),
100
+ crypto.newRandomSessionID(account.id),
100
101
  );
101
102
 
102
103
  const accountOnNodeWithAccount =
@@ -173,73 +174,78 @@ export class LocalNode {
173
174
  crypto,
174
175
  migration,
175
176
  }: {
176
- accountID: AccountID;
177
+ accountID: RawAccountID;
177
178
  accountSecret: AgentSecret;
178
179
  sessionID: SessionID | undefined;
179
180
  peersToLoadFrom: Peer[];
180
181
  crypto: CryptoProvider;
181
182
  migration?: RawAccountMigration<Meta>;
182
183
  }): Promise<LocalNode> {
183
- const loadingNode = new LocalNode(
184
- new ControlledAgent(accountSecret, crypto),
185
- newRandomSessionID(accountID),
186
- crypto,
187
- );
188
-
189
- for (const peer of peersToLoadFrom) {
190
- loadingNode.syncManager.addPeer(peer);
191
- }
184
+ try {
185
+ const loadingNode = new LocalNode(
186
+ new ControlledAgent(accountSecret, crypto),
187
+ crypto.newRandomSessionID(accountID),
188
+ crypto,
189
+ );
192
190
 
193
- const accountPromise = loadingNode.load(accountID);
191
+ for (const peer of peersToLoadFrom) {
192
+ loadingNode.syncManager.addPeer(peer);
193
+ }
194
194
 
195
- const account = await accountPromise;
195
+ const accountPromise = loadingNode.load(accountID);
196
196
 
197
- if (account === "unavailable") {
198
- throw new Error("Account unavailable from all peers");
199
- }
197
+ const account = await accountPromise;
200
198
 
201
- const controlledAccount = new RawControlledAccount(
202
- account.core,
203
- accountSecret,
204
- );
199
+ if (account === "unavailable") {
200
+ throw new Error("Account unavailable from all peers");
201
+ }
205
202
 
206
- // since this is all synchronous, we can just swap out nodes for the SyncManager
207
- const node = loadingNode.testWithDifferentAccount(
208
- controlledAccount,
209
- sessionID || newRandomSessionID(accountID),
210
- );
211
- node.syncManager = loadingNode.syncManager;
212
- node.syncManager.local = node;
203
+ const controlledAccount = new RawControlledAccount(
204
+ account.core,
205
+ accountSecret,
206
+ );
213
207
 
214
- controlledAccount.core.node = node;
215
- node.coValues[accountID] = {
216
- state: "loaded",
217
- coValue: controlledAccount.core,
218
- };
219
- controlledAccount.core._cachedContent = undefined;
208
+ // since this is all synchronous, we can just swap out nodes for the SyncManager
209
+ const node = loadingNode.testWithDifferentAccount(
210
+ controlledAccount,
211
+ sessionID || crypto.newRandomSessionID(accountID),
212
+ );
213
+ node.syncManager = loadingNode.syncManager;
214
+ node.syncManager.local = node;
215
+
216
+ controlledAccount.core.node = node;
217
+ node.coValues[accountID] = {
218
+ state: "loaded",
219
+ coValue: controlledAccount.core,
220
+ };
221
+ controlledAccount.core._cachedContent = undefined;
222
+
223
+ const profileID = account.get("profile");
224
+ if (!profileID) {
225
+ throw new Error("Account has no profile");
226
+ }
227
+ const profile = await node.load(profileID);
220
228
 
221
- const profileID = account.get("profile");
222
- if (!profileID) {
223
- throw new Error("Account has no profile");
224
- }
225
- const profile = await node.load(profileID);
229
+ if (profile === "unavailable") {
230
+ throw new Error("Profile unavailable from all peers");
231
+ }
226
232
 
227
- if (profile === "unavailable") {
228
- throw new Error("Profile unavailable from all peers");
229
- }
233
+ if (migration) {
234
+ await migration(
235
+ controlledAccount as RawControlledAccount<Meta>,
236
+ node,
237
+ );
238
+ node.account = new RawControlledAccount(
239
+ controlledAccount.core,
240
+ controlledAccount.agentSecret,
241
+ );
242
+ }
230
243
 
231
- if (migration) {
232
- await migration(
233
- controlledAccount as RawControlledAccount<Meta>,
234
- node,
235
- );
236
- node.account = new RawControlledAccount(
237
- controlledAccount.core,
238
- controlledAccount.agentSecret,
239
- );
244
+ return node;
245
+ } catch (e) {
246
+ console.error("Error withLoadedAccount", e);
247
+ throw e;
240
248
  }
241
-
242
- return node;
243
249
  }
244
250
 
245
251
  /** @internal */
@@ -429,7 +435,7 @@ export class LocalNode {
429
435
  group.core
430
436
  .testWithDifferentAccount(
431
437
  new ControlledAgent(inviteAgentSecret, this.crypto),
432
- newRandomSessionID(inviteAgentID),
438
+ this.crypto.newRandomSessionID(inviteAgentID),
433
439
  )
434
440
  .getCurrentContent(),
435
441
  );
@@ -470,7 +476,7 @@ export class LocalNode {
470
476
  }
471
477
 
472
478
  /** @internal */
473
- expectProfileLoaded(id: AccountID, expectation?: string): RawProfile {
479
+ expectProfileLoaded(id: RawAccountID, expectation?: string): RawProfile {
474
480
  const account = this.expectCoValueLoaded(id, expectation);
475
481
  const profileID = expectGroup(account.getCurrentContent()).get(
476
482
  "profile",
@@ -499,7 +505,7 @@ export class LocalNode {
499
505
  )
500
506
  .testWithDifferentAccount(
501
507
  new ControlledAgent(agentSecret, this.crypto),
502
- newRandomSessionID(accountAgentID),
508
+ this.crypto.newRandomSessionID(accountAgentID),
503
509
  )
504
510
  .getCurrentContent(),
505
511
  );
@@ -533,7 +539,7 @@ export class LocalNode {
533
539
 
534
540
  /** @internal */
535
541
  resolveAccountAgent(
536
- id: AccountID | AgentID,
542
+ id: RawAccountID | AgentID,
537
543
  expectation?: string,
538
544
  ): Result<AgentID, ResolveAccountAgentError> {
539
545
  if (isAgentID(id)) {
@@ -560,7 +566,7 @@ export class LocalNode {
560
566
  }
561
567
 
562
568
  resolveAccountAgentAsync(
563
- id: AccountID | AgentID,
569
+ id: RawAccountID | AgentID,
564
570
  expectation?: string,
565
571
  ): ResultAsync<AgentID, ResolveAccountAgentError> {
566
572
  if (isAgentID(id)) {
@@ -606,12 +612,14 @@ export class LocalNode {
606
612
  /**
607
613
  * @deprecated use Account.createGroup() instead
608
614
  */
609
- createGroup(): RawGroup {
615
+ createGroup(
616
+ uniqueness: CoValueUniqueness = this.crypto.createdNowUnique(),
617
+ ): RawGroup {
610
618
  const groupCoValue = this.createCoValue({
611
619
  type: "comap",
612
620
  ruleset: { type: "group", initialAdmin: this.account.id },
613
621
  meta: null,
614
- ...this.crypto.createdNowUnique(),
622
+ ...uniqueness,
615
623
  });
616
624
 
617
625
  const group = expectGroup(groupCoValue.getCurrentContent());
@@ -731,19 +739,19 @@ export type LoadCoValueCoreError = {
731
739
  type: "ErrorLoadingCoValueCore";
732
740
  error: unknown;
733
741
  expectation?: string;
734
- id: AccountID;
742
+ id: RawAccountID;
735
743
  };
736
744
 
737
745
  export type AccountUnavailableFromAllPeersError = {
738
746
  type: "AccountUnavailableFromAllPeers";
739
747
  expectation?: string;
740
- id: AccountID;
748
+ id: RawAccountID;
741
749
  };
742
750
 
743
751
  export type UnexpectedlyNotAccountError = {
744
752
  type: "UnexpectedlyNotAccount";
745
753
  expectation?: string;
746
- id: AccountID;
754
+ id: RawAccountID;
747
755
  };
748
756
 
749
757
  export type ResolveAccountAgentError =
@@ -5,13 +5,13 @@ import { KeyID } from "./crypto/crypto.js";
5
5
  import { CoValueCore, Transaction } from "./coValueCore.js";
6
6
  import { accountOrAgentIDfromSessionID } from "./typeUtils/accountOrAgentIDfromSessionID.js";
7
7
  import { AgentID, RawCoID, SessionID, TransactionID } from "./ids.js";
8
- import { RawAccount, AccountID, RawProfile } from "./coValues/account.js";
8
+ import { RawAccount, RawAccountID, RawProfile } from "./coValues/account.js";
9
9
  import { parseJSON } from "./jsonStringify.js";
10
10
  import { EVERYONE, Everyone } from "./coValues/group.js";
11
11
  import { expectGroup } from "./typeUtils/expectGroup.js";
12
12
 
13
13
  export type PermissionsDef =
14
- | { type: "group"; initialAdmin: AccountID | AgentID }
14
+ | { type: "group"; initialAdmin: RawAccountID | AgentID }
15
15
  | { type: "ownedByGroup"; group: RawCoID }
16
16
  | { type: "unsafeAllowAll" };
17
17
 
@@ -53,7 +53,7 @@ export function determineValidTransactions(
53
53
  }
54
54
 
55
55
  const memberState: {
56
- [agent: AccountID | AgentID]: Role;
56
+ [agent: RawAccountID | AgentID]: Role;
57
57
  [EVERYONE]?: Role;
58
58
  } = {};
59
59
 
@@ -99,7 +99,7 @@ export function determineValidTransactions(
99
99
  }
100
100
 
101
101
  const change = changes[0] as
102
- | MapOpPayload<AccountID | AgentID | Everyone, Role>
102
+ | MapOpPayload<RawAccountID | AgentID | Everyone, Role>
103
103
  | MapOpPayload<"readKey", JsonValue>
104
104
  | MapOpPayload<"profile", CoID<RawProfile>>;
105
105
  if (changes.length !== 1) {
@@ -303,7 +303,7 @@ export function isKeyForKeyField(co: string): co is `${KeyID}_for_${KeyID}` {
303
303
 
304
304
  export function isKeyForAccountField(
305
305
  co: string,
306
- ): co is `${KeyID}_for_${AccountID | AgentID}` {
306
+ ): co is `${KeyID}_for_${RawAccountID | AgentID}` {
307
307
  return (
308
308
  (co.startsWith("key_") &&
309
309
  (co.includes("_for_sealer") || co.includes("_for_co"))) ||
@@ -1,5 +1,5 @@
1
1
  import { RawCoID, SessionID } from "../ids.js";
2
- import { MAX_RECOMMENDED_TX_SIZE } from "../index.js";
2
+ import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
3
3
  import { getPriorityFromHeader } from "../priority.js";
4
4
  import { CoValueKnownState, NewContentMessage } from "../sync.js";
5
5
  import { CoValueChunk } from "./index.js";
@@ -8,7 +8,7 @@ import {
8
8
  OutgoingSyncQueue,
9
9
  Peer,
10
10
  } from "../sync.js";
11
- import { CoID, RawCoValue } from "../index.js";
11
+ import { CoID, RawCoValue } from "../coValue.js";
12
12
  import { connectedPeers } from "../streamUtils.js";
13
13
  import {
14
14
  chunkToKnownState,
@@ -1,5 +1,4 @@
1
1
  import { expect, test } from "vitest";
2
- import { newRandomSessionID } from "../coValueCore.js";
3
2
  import { LocalNode } from "../localNode.js";
4
3
  import { connectedPeers } from "../streamUtils.js";
5
4
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
@@ -65,7 +64,7 @@ test("Can create account with one node, and then load it on another", async () =
65
64
  const node2 = await LocalNode.withLoadedAccount({
66
65
  accountID,
67
66
  accountSecret,
68
- sessionID: newRandomSessionID(accountID),
67
+ sessionID: Crypto.newRandomSessionID(accountID),
69
68
  peersToLoadFrom: [node1asPeer],
70
69
  crypto: Crypto,
71
70
  });
@@ -1,8 +1,8 @@
1
1
  import { expect, test } from "vitest";
2
2
  import { expectList } from "../coValue.js";
3
- import { WasmCrypto } from "../index.js";
4
3
  import { LocalNode } from "../localNode.js";
5
4
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
5
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
6
6
 
7
7
  const Crypto = await WasmCrypto.create();
8
8
 
@@ -1,9 +1,9 @@
1
1
  import { expect, test } from "vitest";
2
2
  import { expectMap } from "../coValue.js";
3
- import { WasmCrypto } from "../index.js";
4
3
  import { LocalNode } from "../localNode.js";
5
4
  import { accountOrAgentIDfromSessionID } from "../typeUtils/accountOrAgentIDfromSessionID.js";
6
5
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
6
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
7
7
 
8
8
  const Crypto = await WasmCrypto.create();
9
9
 
@@ -1,9 +1,10 @@
1
1
  import { expect, test, describe } from "vitest";
2
2
  import { expectStream } from "../coValue.js";
3
3
  import { RawBinaryCoStream } from "../coValues/coStream.js";
4
- import { MAX_RECOMMENDED_TX_SIZE, WasmCrypto } from "../index.js";
4
+ import { MAX_RECOMMENDED_TX_SIZE } from "../coValueCore.js";
5
5
  import { LocalNode } from "../localNode.js";
6
6
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
7
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
7
8
 
8
9
  const Crypto = await WasmCrypto.create();
9
10
 
@@ -1,8 +1,8 @@
1
- import { KeySecret } from "../crypto/crypto.js";
1
+ import { KeySecret, StreamingHash } from "../crypto/crypto.js";
2
2
  import { WasmCrypto } from "../crypto/WasmCrypto.js";
3
3
  import { PureJSCrypto } from "../crypto/PureJSCrypto.js";
4
4
  import { describe, test, expect } from "vitest";
5
- import { SessionID } from "../index.js";
5
+ import { SessionID } from "../ids.js";
6
6
 
7
7
  describe.each([
8
8
  { impl: await WasmCrypto.create(), name: "Wasm" },
@@ -180,4 +180,26 @@ describe.each([
180
180
  ),
181
181
  ).toThrow();
182
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
+ });
183
205
  });
@@ -1,13 +1,11 @@
1
1
  import { expect, test } from "vitest";
2
- import {
3
- LocalNode,
4
- RawCoMap,
5
- RawCoList,
6
- RawCoStream,
7
- RawBinaryCoStream,
8
- WasmCrypto,
9
- } from "../index.js";
10
2
  import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
3
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
4
+ import { LocalNode } from "../localNode.js";
5
+ import { RawCoList } from "../coValues/coList.js";
6
+ import { RawCoMap } from "../coValues/coMap.js";
7
+ import { RawCoStream } from "../coValues/coStream.js";
8
+ import { RawBinaryCoStream } from "../coValues/coStream.js";
11
9
 
12
10
  const Crypto = await WasmCrypto.create();
13
11