cojson 0.8.0 → 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.
- package/.turbo/turbo-build.log +2 -2
- package/CHANGELOG.md +6 -0
- package/dist/native/PeerState.js.map +1 -0
- package/dist/native/PriorityBasedMessageQueue.js.map +1 -0
- package/dist/native/base64url.js.map +1 -0
- package/dist/native/base64url.test.js.map +1 -0
- package/dist/native/coValue.js.map +1 -0
- package/dist/native/coValueCore.js.map +1 -0
- package/dist/native/coValues/account.js.map +1 -0
- package/dist/native/coValues/coList.js.map +1 -0
- package/dist/native/coValues/coMap.js.map +1 -0
- package/dist/native/coValues/coStream.js.map +1 -0
- package/dist/native/coValues/group.js.map +1 -0
- package/dist/native/coreToCoValue.js.map +1 -0
- package/dist/{crypto → native/crypto}/PureJSCrypto.js +4 -0
- package/dist/native/crypto/PureJSCrypto.js.map +1 -0
- package/dist/{crypto → native/crypto}/crypto.js +1 -1
- package/dist/native/crypto/crypto.js.map +1 -0
- package/dist/native/ids.js.map +1 -0
- package/dist/{index.js → native/index.native.js} +3 -4
- package/dist/native/index.native.js.map +1 -0
- package/dist/native/jsonStringify.js.map +1 -0
- package/dist/{jsonValue.js.map → native/jsonValue.js.map} +1 -1
- package/dist/{localNode.js → native/localNode.js} +38 -32
- package/dist/native/localNode.js.map +1 -0
- package/dist/native/media.js.map +1 -0
- package/dist/native/permissions.js.map +1 -0
- package/dist/native/priority.js.map +1 -0
- package/dist/native/storage/FileSystem.js.map +1 -0
- package/dist/{storage → native/storage}/chunksAndKnownStates.js +1 -1
- package/dist/native/storage/chunksAndKnownStates.js.map +1 -0
- package/dist/native/storage/index.js.map +1 -0
- package/dist/native/streamUtils.js.map +1 -0
- package/dist/native/sync.js.map +1 -0
- package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -0
- package/dist/native/typeUtils/expectGroup.js.map +1 -0
- package/dist/native/typeUtils/isAccountID.js.map +1 -0
- package/dist/native/typeUtils/isCoValue.js.map +1 -0
- package/dist/web/PeerState.js +66 -0
- package/dist/web/PeerState.js.map +1 -0
- package/dist/web/PriorityBasedMessageQueue.js +51 -0
- package/dist/web/PriorityBasedMessageQueue.js.map +1 -0
- package/dist/web/base64url.js +59 -0
- package/dist/web/base64url.js.map +1 -0
- package/dist/web/base64url.test.js +25 -0
- package/dist/web/base64url.test.js.map +1 -0
- package/dist/web/coValue.js +19 -0
- package/dist/web/coValue.js.map +1 -0
- package/dist/web/coValueCore.js +693 -0
- package/dist/web/coValueCore.js.map +1 -0
- package/dist/web/coValues/account.js +96 -0
- package/dist/web/coValues/account.js.map +1 -0
- package/dist/web/coValues/coList.js +393 -0
- package/dist/web/coValues/coList.js.map +1 -0
- package/dist/web/coValues/coMap.js +197 -0
- package/dist/web/coValues/coMap.js.map +1 -0
- package/dist/web/coValues/coStream.js +220 -0
- package/dist/web/coValues/coStream.js.map +1 -0
- package/dist/web/coValues/group.js +250 -0
- package/dist/web/coValues/group.js.map +1 -0
- package/dist/web/coreToCoValue.js +42 -0
- package/dist/web/coreToCoValue.js.map +1 -0
- package/dist/web/crypto/PureJSCrypto.js +93 -0
- package/dist/web/crypto/PureJSCrypto.js.map +1 -0
- package/dist/{crypto → web/crypto}/WasmCrypto.js +3 -0
- package/dist/web/crypto/WasmCrypto.js.map +1 -0
- package/dist/web/crypto/crypto.js +154 -0
- package/dist/web/crypto/crypto.js.map +1 -0
- package/dist/web/ids.js +17 -0
- package/dist/web/ids.js.map +1 -0
- package/dist/web/index.web.js +40 -0
- package/dist/web/index.web.js.map +1 -0
- package/dist/web/jsonStringify.js +57 -0
- package/dist/web/jsonStringify.js.map +1 -0
- package/dist/web/jsonValue.js +2 -0
- package/dist/web/jsonValue.js.map +1 -0
- package/dist/web/localNode.js +442 -0
- package/dist/web/localNode.js.map +1 -0
- package/dist/web/media.js +2 -0
- package/dist/web/media.js.map +1 -0
- package/dist/web/permissions.js +206 -0
- package/dist/web/permissions.js.map +1 -0
- package/dist/web/priority.js +31 -0
- package/dist/web/priority.js.map +1 -0
- package/dist/web/storage/FileSystem.js +58 -0
- package/dist/web/storage/FileSystem.js.map +1 -0
- package/dist/web/storage/chunksAndKnownStates.js +100 -0
- package/dist/web/storage/chunksAndKnownStates.js.map +1 -0
- package/dist/web/storage/index.js +348 -0
- package/dist/web/storage/index.js.map +1 -0
- package/dist/web/streamUtils.js +41 -0
- package/dist/web/streamUtils.js.map +1 -0
- package/dist/web/sync.js +504 -0
- package/dist/web/sync.js.map +1 -0
- package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js +5 -0
- package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -0
- package/dist/web/typeUtils/expectGroup.js +13 -0
- package/dist/web/typeUtils/expectGroup.js.map +1 -0
- package/dist/web/typeUtils/isAccountID.js +4 -0
- package/dist/web/typeUtils/isAccountID.js.map +1 -0
- package/dist/web/typeUtils/isCoValue.js +11 -0
- package/dist/web/typeUtils/isCoValue.js.map +1 -0
- package/package.json +25 -8
- package/src/coValue.ts +1 -1
- package/src/coValueCore.ts +4 -1
- package/src/coValues/account.ts +9 -3
- package/src/crypto/PureJSCrypto.ts +5 -0
- package/src/crypto/WasmCrypto.ts +4 -0
- package/src/crypto/crypto.ts +7 -2
- package/src/{index.ts → index.native.ts} +4 -5
- package/src/index.web.ts +152 -0
- package/src/localNode.ts +61 -53
- package/src/storage/chunksAndKnownStates.ts +1 -1
- package/src/storage/index.ts +1 -1
- package/src/tests/coList.test.ts +1 -1
- package/src/tests/coMap.test.ts +1 -1
- package/src/tests/coStream.test.ts +2 -1
- package/src/tests/cryptoImpl.test.ts +24 -2
- package/src/tests/group.test.ts +6 -8
- package/src/tests/permissions.test.ts +66 -18
- package/src/tests/priority.test.ts +44 -15
- package/tsconfig.json +5 -4
- package/tsconfig.native.json +12 -0
- package/tsconfig.web.json +11 -0
- package/dist/PeerState.js.map +0 -1
- package/dist/PriorityBasedMessageQueue.js.map +0 -1
- package/dist/base64url.js.map +0 -1
- package/dist/base64url.test.js.map +0 -1
- package/dist/coValue.js.map +0 -1
- package/dist/coValueCore.js.map +0 -1
- package/dist/coValues/account.js.map +0 -1
- package/dist/coValues/coList.js.map +0 -1
- package/dist/coValues/coMap.js.map +0 -1
- package/dist/coValues/coStream.js.map +0 -1
- package/dist/coValues/group.js.map +0 -1
- package/dist/coreToCoValue.js.map +0 -1
- package/dist/crypto/PureJSCrypto.js.map +0 -1
- package/dist/crypto/WasmCrypto.js.map +0 -1
- package/dist/crypto/crypto.js.map +0 -1
- package/dist/ids.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/jsonStringify.js.map +0 -1
- package/dist/localNode.js.map +0 -1
- package/dist/media.js.map +0 -1
- package/dist/permissions.js.map +0 -1
- package/dist/priority.js.map +0 -1
- package/dist/storage/FileSystem.js.map +0 -1
- package/dist/storage/chunksAndKnownStates.js.map +0 -1
- package/dist/storage/index.js.map +0 -1
- package/dist/streamUtils.js.map +0 -1
- package/dist/sync.js.map +0 -1
- package/dist/tests/PeerState.test.js +0 -80
- package/dist/tests/PeerState.test.js.map +0 -1
- package/dist/tests/PriorityBasedMessageQueue.test.js +0 -97
- package/dist/tests/PriorityBasedMessageQueue.test.js.map +0 -1
- package/dist/tests/account.test.js +0 -58
- package/dist/tests/account.test.js.map +0 -1
- package/dist/tests/coList.test.js +0 -76
- package/dist/tests/coList.test.js.map +0 -1
- package/dist/tests/coMap.test.js +0 -136
- package/dist/tests/coMap.test.js.map +0 -1
- package/dist/tests/coStream.test.js +0 -205
- package/dist/tests/coStream.test.js.map +0 -1
- package/dist/tests/coValueCore.test.js +0 -124
- package/dist/tests/coValueCore.test.js.map +0 -1
- package/dist/tests/crypto.test.js +0 -118
- package/dist/tests/crypto.test.js.map +0 -1
- package/dist/tests/cryptoImpl.test.js +0 -113
- package/dist/tests/cryptoImpl.test.js.map +0 -1
- package/dist/tests/group.test.js +0 -34
- package/dist/tests/group.test.js.map +0 -1
- package/dist/tests/permissions.test.js +0 -1059
- package/dist/tests/permissions.test.js.map +0 -1
- package/dist/tests/priority.test.js +0 -61
- package/dist/tests/priority.test.js.map +0 -1
- package/dist/tests/sync.test.js +0 -1186
- package/dist/tests/sync.test.js.map +0 -1
- package/dist/tests/testUtils.js +0 -59
- package/dist/tests/testUtils.js.map +0 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +0 -1
- package/dist/typeUtils/expectGroup.js.map +0 -1
- package/dist/typeUtils/isAccountID.js.map +0 -1
- package/dist/typeUtils/isCoValue.js.map +0 -1
- /package/dist/{PeerState.js → native/PeerState.js} +0 -0
- /package/dist/{PriorityBasedMessageQueue.js → native/PriorityBasedMessageQueue.js} +0 -0
- /package/dist/{base64url.js → native/base64url.js} +0 -0
- /package/dist/{base64url.test.js → native/base64url.test.js} +0 -0
- /package/dist/{coValue.js → native/coValue.js} +0 -0
- /package/dist/{coValueCore.js → native/coValueCore.js} +0 -0
- /package/dist/{coValues → native/coValues}/account.js +0 -0
- /package/dist/{coValues → native/coValues}/coList.js +0 -0
- /package/dist/{coValues → native/coValues}/coMap.js +0 -0
- /package/dist/{coValues → native/coValues}/coStream.js +0 -0
- /package/dist/{coValues → native/coValues}/group.js +0 -0
- /package/dist/{coreToCoValue.js → native/coreToCoValue.js} +0 -0
- /package/dist/{ids.js → native/ids.js} +0 -0
- /package/dist/{jsonStringify.js → native/jsonStringify.js} +0 -0
- /package/dist/{jsonValue.js → native/jsonValue.js} +0 -0
- /package/dist/{media.js → native/media.js} +0 -0
- /package/dist/{permissions.js → native/permissions.js} +0 -0
- /package/dist/{priority.js → native/priority.js} +0 -0
- /package/dist/{storage → native/storage}/FileSystem.js +0 -0
- /package/dist/{storage → native/storage}/index.js +0 -0
- /package/dist/{streamUtils.js → native/streamUtils.js} +0 -0
- /package/dist/{sync.js → native/sync.js} +0 -0
- /package/dist/{typeUtils → native/typeUtils}/accountOrAgentIDfromSessionID.js +0 -0
- /package/dist/{typeUtils → native/typeUtils}/expectGroup.js +0 -0
- /package/dist/{typeUtils → native/typeUtils}/isAccountID.js +0 -0
- /package/dist/{typeUtils → native/typeUtils}/isCoValue.js +0 -0
package/src/coValueCore.ts
CHANGED
|
@@ -43,7 +43,10 @@ export type CoValueHeader = {
|
|
|
43
43
|
meta: JsonObject | null;
|
|
44
44
|
} & CoValueUniqueness;
|
|
45
45
|
|
|
46
|
-
export type CoValueUniqueness = {
|
|
46
|
+
export type CoValueUniqueness = {
|
|
47
|
+
uniqueness: JsonValue;
|
|
48
|
+
createdAt?: `2${string}` | null;
|
|
49
|
+
};
|
|
47
50
|
|
|
48
51
|
export function idforHeader(
|
|
49
52
|
header: CoValueHeader,
|
package/src/coValues/account.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CoValueCore,
|
|
3
|
+
CoValueHeader,
|
|
4
|
+
CoValueUniqueness,
|
|
5
|
+
} from "../coValueCore.js";
|
|
2
6
|
import { CoID, RawCoValue } from "../coValue.js";
|
|
3
7
|
import {
|
|
4
8
|
AgentSecret,
|
|
@@ -11,9 +15,9 @@ import {
|
|
|
11
15
|
import { AgentID } from "../ids.js";
|
|
12
16
|
import { RawCoMap } from "./coMap.js";
|
|
13
17
|
import { RawGroup, InviteSecret } from "./group.js";
|
|
14
|
-
import { LocalNode } from "../index.js";
|
|
15
18
|
import { JsonObject } from "../jsonValue.js";
|
|
16
19
|
import { err, ok, Result } from "neverthrow";
|
|
20
|
+
import { LocalNode } from "../localNode.js";
|
|
17
21
|
|
|
18
22
|
export function accountHeaderForInitialAgentSecret(
|
|
19
23
|
agentSecret: AgentSecret,
|
|
@@ -92,7 +96,9 @@ export class RawControlledAccount<Meta extends AccountMeta = AccountMeta>
|
|
|
92
96
|
* Creates a new group (with the current account as the group's first admin).
|
|
93
97
|
* @category 1. High-level
|
|
94
98
|
*/
|
|
95
|
-
createGroup(
|
|
99
|
+
createGroup(
|
|
100
|
+
uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique(),
|
|
101
|
+
) {
|
|
96
102
|
return this.core.node.createGroup(uniqueness);
|
|
97
103
|
}
|
|
98
104
|
|
|
@@ -36,6 +36,11 @@ export class PureJSCrypto extends CryptoProvider<Blake3State> {
|
|
|
36
36
|
return blake3.create({});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
cloneBlake3State(state: any): Blake3State {
|
|
41
|
+
return state.clone();
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
blake3HashOnce(data: Uint8Array) {
|
|
40
45
|
return blake3(data);
|
|
41
46
|
}
|
package/src/crypto/WasmCrypto.ts
CHANGED
|
@@ -64,6 +64,10 @@ export class WasmCrypto extends CryptoProvider<Uint8Array> {
|
|
|
64
64
|
return this.blake3Instance.init().save();
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
cloneBlake3State(state: Uint8Array): Uint8Array {
|
|
68
|
+
return this.blake3Instance.load(state).save();
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
blake3HashOnce(data: Uint8Array) {
|
|
68
72
|
return this.blake3Instance.init().update(data).digest("binary");
|
|
69
73
|
}
|
package/src/crypto/crypto.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { JsonValue } from "../jsonValue.js";
|
|
|
2
2
|
import { base58 } from "@scure/base";
|
|
3
3
|
import { AgentID, RawCoID, TransactionID } from "../ids.js";
|
|
4
4
|
import { Stringified, parseJSON, stableStringify } from "../jsonStringify.js";
|
|
5
|
-
import { RawAccountID
|
|
5
|
+
import { RawAccountID } from "../coValues/account.js";
|
|
6
|
+
import { SessionID } from "../ids.js";
|
|
6
7
|
|
|
7
8
|
export type SignerSecret = `signerSecret_z${string}`;
|
|
8
9
|
export type SignerID = `signer_z${string}`;
|
|
@@ -103,6 +104,7 @@ export abstract class CryptoProvider<Blake3State = any> {
|
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
abstract emptyBlake3State(): Blake3State;
|
|
107
|
+
abstract cloneBlake3State(state: Blake3State): Blake3State;
|
|
106
108
|
abstract blake3HashOnce(data: Uint8Array): Uint8Array;
|
|
107
109
|
abstract blake3HashOnceWithContext(
|
|
108
110
|
data: Uint8Array,
|
|
@@ -323,7 +325,10 @@ export class StreamingHash {
|
|
|
323
325
|
}
|
|
324
326
|
|
|
325
327
|
clone(): StreamingHash {
|
|
326
|
-
return new StreamingHash(
|
|
328
|
+
return new StreamingHash(
|
|
329
|
+
this.crypto,
|
|
330
|
+
this.crypto.cloneBlake3State(this.state),
|
|
331
|
+
);
|
|
327
332
|
}
|
|
328
333
|
}
|
|
329
334
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PureJSCrypto } from "./crypto/PureJSCrypto.js";
|
|
2
|
+
|
|
1
3
|
import {
|
|
2
4
|
CoValueCore,
|
|
3
5
|
type CoValueUniqueness,
|
|
@@ -16,8 +18,6 @@ import {
|
|
|
16
18
|
StreamingHash,
|
|
17
19
|
CryptoProvider,
|
|
18
20
|
} from "./crypto/crypto.js";
|
|
19
|
-
import { WasmCrypto } from "./crypto/WasmCrypto.js";
|
|
20
|
-
import { PureJSCrypto } from "./crypto/PureJSCrypto.js";
|
|
21
21
|
import { connectedPeers, Channel } from "./streamUtils.js";
|
|
22
22
|
import { ControlledAgent, RawControlledAccount } from "./coValues/account.js";
|
|
23
23
|
import type { Role } from "./permissions.js";
|
|
@@ -115,11 +115,10 @@ export {
|
|
|
115
115
|
AgentSecret,
|
|
116
116
|
InviteSecret,
|
|
117
117
|
CryptoProvider,
|
|
118
|
-
WasmCrypto,
|
|
119
|
-
PureJSCrypto,
|
|
120
118
|
SyncMessage,
|
|
121
119
|
isRawCoID,
|
|
122
120
|
LSMStorage,
|
|
121
|
+
PureJSCrypto,
|
|
123
122
|
};
|
|
124
123
|
|
|
125
124
|
export type {
|
|
@@ -131,7 +130,7 @@ export type {
|
|
|
131
130
|
OutgoingSyncQueue,
|
|
132
131
|
DisconnectedError,
|
|
133
132
|
PingTimeoutError,
|
|
134
|
-
CoValueUniqueness
|
|
133
|
+
CoValueUniqueness,
|
|
135
134
|
};
|
|
136
135
|
|
|
137
136
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
package/src/index.web.ts
ADDED
|
@@ -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
|
@@ -21,10 +21,11 @@ import {
|
|
|
21
21
|
ControlledAgent,
|
|
22
22
|
RawAccountID,
|
|
23
23
|
RawProfile,
|
|
24
|
+
RawProfile as Profile,
|
|
24
25
|
RawAccountMigration,
|
|
25
26
|
InvalidAccountAgentIDError,
|
|
26
27
|
} from "./coValues/account.js";
|
|
27
|
-
import {
|
|
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
|
|
|
@@ -180,66 +181,71 @@ export class LocalNode {
|
|
|
180
181
|
crypto: CryptoProvider;
|
|
181
182
|
migration?: RawAccountMigration<Meta>;
|
|
182
183
|
}): Promise<LocalNode> {
|
|
183
|
-
|
|
184
|
-
new
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
191
|
+
for (const peer of peersToLoadFrom) {
|
|
192
|
+
loadingNode.syncManager.addPeer(peer);
|
|
193
|
+
}
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
const accountPromise = loadingNode.load(accountID);
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
throw new Error("Account unavailable from all peers");
|
|
199
|
-
}
|
|
197
|
+
const account = await accountPromise;
|
|
200
198
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
);
|
|
199
|
+
if (account === "unavailable") {
|
|
200
|
+
throw new Error("Account unavailable from all peers");
|
|
201
|
+
}
|
|
205
202
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
228
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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 */
|
|
@@ -606,12 +612,14 @@ export class LocalNode {
|
|
|
606
612
|
/**
|
|
607
613
|
* @deprecated use Account.createGroup() instead
|
|
608
614
|
*/
|
|
609
|
-
createGroup(
|
|
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
|
-
...uniqueness
|
|
622
|
+
...uniqueness,
|
|
615
623
|
});
|
|
616
624
|
|
|
617
625
|
const group = expectGroup(groupCoValue.getCurrentContent());
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RawCoID, SessionID } from "../ids.js";
|
|
2
|
-
import { MAX_RECOMMENDED_TX_SIZE } from "../
|
|
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";
|
package/src/storage/index.ts
CHANGED
package/src/tests/coList.test.ts
CHANGED
|
@@ -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
|
|
package/src/tests/coMap.test.ts
CHANGED
|
@@ -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
|
|
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 "../
|
|
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
|
});
|
package/src/tests/group.test.ts
CHANGED
|
@@ -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
|
|