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.
- package/.turbo/turbo-build.log +2 -7
- package/.turbo/turbo-lint.log +4 -0
- package/CHANGELOG.md +13 -0
- package/dist/{PeerState.js → native/PeerState.js} +13 -5
- 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/{coValueCore.js → native/coValueCore.js} +0 -6
- package/dist/native/coValueCore.js.map +1 -0
- package/dist/{coValues → native/coValues}/account.js +2 -3
- 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/{coValues → native/coValues}/group.js +8 -8
- 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 +4 -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} +4 -6
- 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} +44 -38
- 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/PeerState.ts +18 -7
- package/src/coValue.ts +1 -1
- package/src/coValueCore.ts +9 -14
- package/src/coValues/account.ts +12 -7
- package/src/coValues/coList.ts +4 -4
- package/src/coValues/coMap.ts +3 -3
- package/src/coValues/coStream.ts +8 -8
- package/src/coValues/group.ts +15 -11
- package/src/crypto/PureJSCrypto.ts +5 -0
- package/src/crypto/WasmCrypto.ts +4 -0
- package/src/crypto/crypto.ts +11 -1
- package/src/ids.ts +2 -2
- package/src/{index.ts → index.native.ts} +7 -8
- package/src/index.web.ts +152 -0
- package/src/localNode.ts +75 -67
- package/src/permissions.ts +5 -5
- package/src/storage/chunksAndKnownStates.ts +1 -1
- package/src/storage/index.ts +1 -1
- package/src/tests/account.test.ts +1 -2
- 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 +90 -43
- package/src/tests/priority.test.ts +44 -15
- package/src/tests/sync.test.ts +8 -8
- package/src/tests/testUtils.ts +1 -2
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +3 -3
- package/src/typeUtils/isAccountID.ts +2 -2
- 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 -59
- 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 -1060
- 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 -1187
- package/dist/tests/sync.test.js.map +0 -1
- package/dist/tests/testUtils.js +0 -60
- 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/{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/{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/{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/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
|
@@ -2,7 +2,7 @@ import { AgentSecret, CryptoProvider } from "./crypto/crypto.js";
|
|
|
2
2
|
import {
|
|
3
3
|
CoValueCore,
|
|
4
4
|
CoValueHeader,
|
|
5
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -81,14 +82,14 @@ export class LocalNode {
|
|
|
81
82
|
initialAgentSecret?: AgentSecret;
|
|
82
83
|
}): Promise<{
|
|
83
84
|
node: LocalNode;
|
|
84
|
-
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:
|
|
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
|
-
|
|
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 */
|
|
@@ -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:
|
|
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:
|
|
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:
|
|
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(
|
|
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
|
-
...
|
|
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:
|
|
742
|
+
id: RawAccountID;
|
|
735
743
|
};
|
|
736
744
|
|
|
737
745
|
export type AccountUnavailableFromAllPeersError = {
|
|
738
746
|
type: "AccountUnavailableFromAllPeers";
|
|
739
747
|
expectation?: string;
|
|
740
|
-
id:
|
|
748
|
+
id: RawAccountID;
|
|
741
749
|
};
|
|
742
750
|
|
|
743
751
|
export type UnexpectedlyNotAccountError = {
|
|
744
752
|
type: "UnexpectedlyNotAccount";
|
|
745
753
|
expectation?: string;
|
|
746
|
-
id:
|
|
754
|
+
id: RawAccountID;
|
|
747
755
|
};
|
|
748
756
|
|
|
749
757
|
export type ResolveAccountAgentError =
|
package/src/permissions.ts
CHANGED
|
@@ -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,
|
|
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:
|
|
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:
|
|
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<
|
|
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_${
|
|
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 "../
|
|
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
|
@@ -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
|
});
|
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
|
|