cojson 0.8.12 → 0.8.17
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/CHANGELOG.md +95 -83
- package/dist/native/PeerKnownStates.js +6 -1
- package/dist/native/PeerKnownStates.js.map +1 -1
- package/dist/native/PeerState.js +4 -3
- package/dist/native/PeerState.js.map +1 -1
- package/dist/native/PriorityBasedMessageQueue.js +1 -10
- package/dist/native/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/native/SyncStateSubscriptionManager.js +70 -0
- package/dist/native/SyncStateSubscriptionManager.js.map +1 -0
- package/dist/native/base64url.js.map +1 -1
- package/dist/native/base64url.test.js +1 -1
- package/dist/native/base64url.test.js.map +1 -1
- package/dist/native/coValue.js.map +1 -1
- package/dist/native/coValueCore.js +141 -149
- package/dist/native/coValueCore.js.map +1 -1
- package/dist/native/coValueState.js.map +1 -1
- package/dist/native/coValues/account.js +6 -6
- package/dist/native/coValues/account.js.map +1 -1
- package/dist/native/coValues/coList.js +2 -3
- package/dist/native/coValues/coList.js.map +1 -1
- package/dist/native/coValues/coMap.js +1 -1
- package/dist/native/coValues/coMap.js.map +1 -1
- package/dist/native/coValues/coStream.js +3 -5
- package/dist/native/coValues/coStream.js.map +1 -1
- package/dist/native/coValues/group.js +11 -11
- package/dist/native/coValues/group.js.map +1 -1
- package/dist/native/coreToCoValue.js +2 -2
- package/dist/native/coreToCoValue.js.map +1 -1
- package/dist/native/crypto/PureJSCrypto.js +4 -4
- package/dist/native/crypto/PureJSCrypto.js.map +1 -1
- package/dist/native/crypto/crypto.js.map +1 -1
- package/dist/native/exports.js +12 -12
- package/dist/native/exports.js.map +1 -1
- package/dist/native/ids.js.map +1 -1
- package/dist/native/jsonStringify.js.map +1 -1
- package/dist/native/localNode.js +5 -7
- package/dist/native/localNode.js.map +1 -1
- package/dist/native/permissions.js +4 -7
- package/dist/native/permissions.js.map +1 -1
- package/dist/native/priority.js.map +1 -1
- package/dist/native/storage/FileSystem.js.map +1 -1
- package/dist/native/storage/chunksAndKnownStates.js +2 -4
- package/dist/native/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/native/storage/index.js +6 -15
- package/dist/native/storage/index.js.map +1 -1
- package/dist/native/streamUtils.js.map +1 -1
- package/dist/native/sync.js +57 -7
- package/dist/native/sync.js.map +1 -1
- package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/native/typeUtils/expectGroup.js.map +1 -1
- package/dist/native/typeUtils/isAccountID.js.map +1 -1
- package/dist/native/typeUtils/isCoValue.js +1 -1
- package/dist/native/typeUtils/isCoValue.js.map +1 -1
- package/dist/web/PeerKnownStates.js +6 -1
- package/dist/web/PeerKnownStates.js.map +1 -1
- package/dist/web/PeerState.js +4 -3
- package/dist/web/PeerState.js.map +1 -1
- package/dist/web/PriorityBasedMessageQueue.js +1 -10
- package/dist/web/PriorityBasedMessageQueue.js.map +1 -1
- package/dist/web/SyncStateSubscriptionManager.js +70 -0
- package/dist/web/SyncStateSubscriptionManager.js.map +1 -0
- package/dist/web/base64url.js.map +1 -1
- package/dist/web/base64url.test.js +1 -1
- package/dist/web/base64url.test.js.map +1 -1
- package/dist/web/coValue.js.map +1 -1
- package/dist/web/coValueCore.js +141 -149
- package/dist/web/coValueCore.js.map +1 -1
- package/dist/web/coValueState.js.map +1 -1
- package/dist/web/coValues/account.js +6 -6
- package/dist/web/coValues/account.js.map +1 -1
- package/dist/web/coValues/coList.js +2 -3
- package/dist/web/coValues/coList.js.map +1 -1
- package/dist/web/coValues/coMap.js +1 -1
- package/dist/web/coValues/coMap.js.map +1 -1
- package/dist/web/coValues/coStream.js +3 -5
- package/dist/web/coValues/coStream.js.map +1 -1
- package/dist/web/coValues/group.js +11 -11
- package/dist/web/coValues/group.js.map +1 -1
- package/dist/web/coreToCoValue.js +2 -2
- package/dist/web/coreToCoValue.js.map +1 -1
- package/dist/web/crypto/PureJSCrypto.js +4 -4
- package/dist/web/crypto/PureJSCrypto.js.map +1 -1
- package/dist/web/crypto/WasmCrypto.js +5 -5
- package/dist/web/crypto/WasmCrypto.js.map +1 -1
- package/dist/web/crypto/crypto.js.map +1 -1
- package/dist/web/exports.js +12 -12
- package/dist/web/exports.js.map +1 -1
- package/dist/web/ids.js.map +1 -1
- package/dist/web/jsonStringify.js.map +1 -1
- package/dist/web/localNode.js +5 -7
- package/dist/web/localNode.js.map +1 -1
- package/dist/web/permissions.js +4 -7
- package/dist/web/permissions.js.map +1 -1
- package/dist/web/priority.js.map +1 -1
- package/dist/web/storage/FileSystem.js.map +1 -1
- package/dist/web/storage/chunksAndKnownStates.js +2 -4
- package/dist/web/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/web/storage/index.js +6 -15
- package/dist/web/storage/index.js.map +1 -1
- package/dist/web/streamUtils.js.map +1 -1
- package/dist/web/sync.js +57 -7
- package/dist/web/sync.js.map +1 -1
- package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/web/typeUtils/expectGroup.js.map +1 -1
- package/dist/web/typeUtils/isAccountID.js.map +1 -1
- package/dist/web/typeUtils/isCoValue.js +1 -1
- package/dist/web/typeUtils/isCoValue.js.map +1 -1
- package/package.json +4 -14
- package/src/PeerKnownStates.ts +98 -90
- package/src/PeerState.ts +92 -73
- package/src/PriorityBasedMessageQueue.ts +42 -49
- package/src/SyncStateSubscriptionManager.ts +124 -0
- package/src/base64url.test.ts +24 -24
- package/src/base64url.ts +44 -45
- package/src/coValue.ts +45 -45
- package/src/coValueCore.ts +746 -785
- package/src/coValueState.ts +82 -72
- package/src/coValues/account.ts +143 -150
- package/src/coValues/coList.ts +520 -522
- package/src/coValues/coMap.ts +283 -285
- package/src/coValues/coStream.ts +320 -324
- package/src/coValues/group.ts +306 -305
- package/src/coreToCoValue.ts +28 -31
- package/src/crypto/PureJSCrypto.ts +188 -194
- package/src/crypto/WasmCrypto.ts +236 -254
- package/src/crypto/crypto.ts +302 -309
- package/src/exports.ts +116 -116
- package/src/ids.ts +9 -9
- package/src/jsonStringify.ts +46 -46
- package/src/jsonValue.ts +24 -10
- package/src/localNode.ts +635 -660
- package/src/media.ts +3 -3
- package/src/permissions.ts +272 -278
- package/src/priority.ts +21 -19
- package/src/storage/FileSystem.ts +91 -99
- package/src/storage/chunksAndKnownStates.ts +110 -115
- package/src/storage/index.ts +466 -497
- package/src/streamUtils.ts +60 -60
- package/src/sync.ts +656 -608
- package/src/tests/PeerKnownStates.test.ts +38 -34
- package/src/tests/PeerState.test.ts +101 -64
- package/src/tests/PriorityBasedMessageQueue.test.ts +91 -91
- package/src/tests/SyncStateSubscriptionManager.test.ts +232 -0
- package/src/tests/account.test.ts +59 -59
- package/src/tests/coList.test.ts +65 -65
- package/src/tests/coMap.test.ts +137 -137
- package/src/tests/coStream.test.ts +254 -257
- package/src/tests/coValueCore.test.ts +153 -156
- package/src/tests/crypto.test.ts +136 -144
- package/src/tests/cryptoImpl.test.ts +205 -197
- package/src/tests/group.test.ts +24 -24
- package/src/tests/permissions.test.ts +1306 -1371
- package/src/tests/priority.test.ts +65 -82
- package/src/tests/sync.test.ts +1573 -1263
- package/src/tests/testUtils.ts +85 -53
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +4 -4
- package/src/typeUtils/expectGroup.ts +9 -9
- package/src/typeUtils/isAccountID.ts +1 -1
- package/src/typeUtils/isCoValue.ts +9 -9
- package/tsconfig.json +4 -6
- package/tsconfig.native.json +9 -11
- package/tsconfig.web.json +4 -10
- package/.eslintrc.cjs +0 -25
- package/.prettierrc.js +0 -9
package/src/coValueState.ts
CHANGED
|
@@ -2,106 +2,116 @@ import { CoValueCore } from "./coValueCore.js";
|
|
|
2
2
|
import { PeerID } from "./sync.js";
|
|
3
3
|
|
|
4
4
|
function createResolvablePromise<T>() {
|
|
5
|
-
|
|
5
|
+
let resolve!: (value: T) => void;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const promise = new Promise<T>((res) => {
|
|
8
|
+
resolve = res;
|
|
9
|
+
});
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
return { promise, resolve };
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class CoValueUnknownState {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
type = "unknown" as const;
|
|
16
|
+
private peers: Map<
|
|
17
|
+
PeerID,
|
|
18
|
+
ReturnType<typeof createResolvablePromise<"available" | "unavailable">>
|
|
19
|
+
>;
|
|
20
|
+
private resolve: (value: "available" | "unavailable") => void;
|
|
21
|
+
|
|
22
|
+
ready: Promise<"available" | "unavailable">;
|
|
23
|
+
|
|
24
|
+
constructor(peersIds: Iterable<PeerID>) {
|
|
25
|
+
this.peers = new Map();
|
|
26
|
+
|
|
27
|
+
for (const peerId of peersIds) {
|
|
28
|
+
this.peers.set(
|
|
29
|
+
peerId,
|
|
30
|
+
createResolvablePromise<"available" | "unavailable">(),
|
|
31
|
+
);
|
|
32
|
+
}
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
const { resolve, promise } = createResolvablePromise<
|
|
35
|
+
"available" | "unavailable"
|
|
36
|
+
>();
|
|
23
37
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
38
|
+
this.ready = promise;
|
|
39
|
+
this.resolve = resolve;
|
|
40
|
+
}
|
|
27
41
|
|
|
28
|
-
|
|
42
|
+
update(peerId: PeerID, value: "available" | "unavailable") {
|
|
43
|
+
const entry = this.peers.get(peerId);
|
|
29
44
|
|
|
30
|
-
|
|
31
|
-
|
|
45
|
+
if (entry) {
|
|
46
|
+
entry.resolve(value);
|
|
32
47
|
}
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
entry.resolve(value);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (value === "available") {
|
|
42
|
-
this.resolve("available");
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
49
|
+
if (value === "available") {
|
|
50
|
+
this.resolve("available");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
this.peers.delete(peerId);
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
56
|
+
// If none of the peers have the coValue, we resolve to unavailable
|
|
57
|
+
if (this.peers.size === 0) {
|
|
58
|
+
this.resolve("unavailable");
|
|
52
59
|
}
|
|
60
|
+
}
|
|
53
61
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
// Wait for a specific peer to have a known state
|
|
63
|
+
waitForPeer(peerId: PeerID) {
|
|
64
|
+
const entry = this.peers.get(peerId);
|
|
57
65
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return entry.promise;
|
|
66
|
+
if (!entry) {
|
|
67
|
+
return Promise.resolve();
|
|
63
68
|
}
|
|
69
|
+
|
|
70
|
+
return entry.promise;
|
|
71
|
+
}
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
class CoValueAvailableState {
|
|
67
|
-
|
|
75
|
+
type = "available" as const;
|
|
68
76
|
|
|
69
|
-
|
|
77
|
+
constructor(public coValue: CoValueCore) {}
|
|
70
78
|
}
|
|
71
79
|
|
|
72
|
-
type CoValueStateAction =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
type CoValueStateAction =
|
|
81
|
+
| {
|
|
82
|
+
type: "not-found";
|
|
83
|
+
peerId: PeerID;
|
|
84
|
+
}
|
|
85
|
+
| {
|
|
86
|
+
type: "found";
|
|
87
|
+
peerId: PeerID;
|
|
88
|
+
coValue: CoValueCore;
|
|
89
|
+
};
|
|
80
90
|
|
|
81
91
|
export class CoValueState {
|
|
82
|
-
|
|
92
|
+
constructor(public state: CoValueUnknownState | CoValueAvailableState) {}
|
|
83
93
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
static Unknown(peersToWaitFor: Set<PeerID>) {
|
|
95
|
+
return new CoValueState(new CoValueUnknownState(peersToWaitFor));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static Available(coValue: CoValueCore) {
|
|
99
|
+
return new CoValueState(new CoValueAvailableState(coValue));
|
|
100
|
+
}
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
dispatch(action: CoValueStateAction) {
|
|
103
|
+
if (this.state.type === "available") {
|
|
104
|
+
return;
|
|
90
105
|
}
|
|
91
106
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
break;
|
|
101
|
-
case "found":
|
|
102
|
-
this.state.update(action.peerId, "available");
|
|
103
|
-
this.state = new CoValueAvailableState(action.coValue);
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
107
|
+
switch (action.type) {
|
|
108
|
+
case "not-found":
|
|
109
|
+
this.state.update(action.peerId, "unavailable");
|
|
110
|
+
break;
|
|
111
|
+
case "found":
|
|
112
|
+
this.state.update(action.peerId, "available");
|
|
113
|
+
this.state = new CoValueAvailableState(action.coValue);
|
|
114
|
+
break;
|
|
106
115
|
}
|
|
116
|
+
}
|
|
107
117
|
}
|
package/src/coValues/account.ts
CHANGED
|
@@ -1,193 +1,186 @@
|
|
|
1
|
+
import { Result, ok } from "neverthrow";
|
|
2
|
+
import { CoID, RawCoValue } from "../coValue.js";
|
|
1
3
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
CoValueCore,
|
|
5
|
+
CoValueHeader,
|
|
6
|
+
CoValueUniqueness,
|
|
5
7
|
} from "../coValueCore.js";
|
|
6
|
-
import { CoID, RawCoValue } from "../coValue.js";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
AgentSecret,
|
|
10
|
+
CryptoProvider,
|
|
11
|
+
SealerID,
|
|
12
|
+
SealerSecret,
|
|
13
|
+
SignerID,
|
|
14
|
+
SignerSecret,
|
|
14
15
|
} from "../crypto/crypto.js";
|
|
15
16
|
import { AgentID } from "../ids.js";
|
|
16
|
-
import { RawCoMap } from "./coMap.js";
|
|
17
|
-
import { RawGroup, InviteSecret } from "./group.js";
|
|
18
17
|
import { JsonObject } from "../jsonValue.js";
|
|
19
|
-
import { err, ok, Result } from "neverthrow";
|
|
20
18
|
import { LocalNode } from "../localNode.js";
|
|
19
|
+
import { RawCoMap } from "./coMap.js";
|
|
20
|
+
import { InviteSecret, RawGroup } from "./group.js";
|
|
21
21
|
|
|
22
22
|
export function accountHeaderForInitialAgentSecret(
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
agentSecret: AgentSecret,
|
|
24
|
+
crypto: CryptoProvider,
|
|
25
25
|
): CoValueHeader {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
const agent = crypto.getAgentID(agentSecret);
|
|
27
|
+
return {
|
|
28
|
+
type: "comap",
|
|
29
|
+
ruleset: { type: "group", initialAdmin: agent },
|
|
30
|
+
meta: {
|
|
31
|
+
type: "account",
|
|
32
|
+
},
|
|
33
|
+
createdAt: null,
|
|
34
|
+
uniqueness: null,
|
|
35
|
+
};
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export type InvalidAccountAgentIDError = {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
type: "InvalidAccountAgentID";
|
|
40
|
+
reason: string;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
export class RawAccount<
|
|
44
|
-
|
|
44
|
+
Meta extends AccountMeta = AccountMeta,
|
|
45
45
|
> extends RawGroup<Meta> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
const agents = this.keys().filter((k): k is AgentID =>
|
|
53
|
-
k.startsWith("sealer_"),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
if (agents.length !== 1) {
|
|
57
|
-
return err({
|
|
58
|
-
type: "InvalidAccountAgentID",
|
|
59
|
-
reason: "Account has " + agents.length + " agents",
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this._cachedCurrentAgentID = agents[0];
|
|
64
|
-
|
|
65
|
-
return ok(agents[0]!);
|
|
46
|
+
_cachedCurrentAgentID: AgentID | undefined;
|
|
47
|
+
|
|
48
|
+
currentAgentID(): Result<AgentID, InvalidAccountAgentIDError> {
|
|
49
|
+
if (this._cachedCurrentAgentID) {
|
|
50
|
+
return ok(this._cachedCurrentAgentID);
|
|
66
51
|
}
|
|
52
|
+
const agents = this.keys()
|
|
53
|
+
.filter((k): k is AgentID => k.startsWith("sealer_"))
|
|
54
|
+
.sort(
|
|
55
|
+
(a, b) =>
|
|
56
|
+
(this.lastEditAt(a)?.at.getTime() || 0) -
|
|
57
|
+
(this.lastEditAt(b)?.at.getTime() || 0),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (agents.length !== 1) {
|
|
61
|
+
console.warn("Account has " + agents.length + " agents", this.id);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this._cachedCurrentAgentID = agents[0];
|
|
65
|
+
|
|
66
|
+
return ok(agents[0]!);
|
|
67
|
+
}
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export interface ControlledAccountOrAgent {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
id: RawAccountID | AgentID;
|
|
72
|
+
agentSecret: AgentSecret;
|
|
73
|
+
|
|
74
|
+
currentAgentID: () => Result<AgentID, InvalidAccountAgentIDError>;
|
|
75
|
+
currentSignerID: () => Result<SignerID, InvalidAccountAgentIDError>;
|
|
76
|
+
currentSignerSecret: () => SignerSecret;
|
|
77
|
+
currentSealerID: () => Result<SealerID, InvalidAccountAgentIDError>;
|
|
78
|
+
currentSealerSecret: () => SealerSecret;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/** @hidden */
|
|
81
82
|
export class RawControlledAccount<Meta extends AccountMeta = AccountMeta>
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
extends RawAccount<Meta>
|
|
84
|
+
implements ControlledAccountOrAgent
|
|
84
85
|
{
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
const agentID = this.crypto.getAgentID(this.agentSecret);
|
|
117
|
-
this._cachedCurrentAgentID = agentID;
|
|
118
|
-
return ok(agentID);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
currentSignerID() {
|
|
122
|
-
return this.currentAgentID().map((id) =>
|
|
123
|
-
this.crypto.getAgentSignerID(id),
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
currentSignerSecret(): SignerSecret {
|
|
128
|
-
return this.crypto.getAgentSignerSecret(this.agentSecret);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
currentSealerID() {
|
|
132
|
-
return this.currentAgentID().map((id) =>
|
|
133
|
-
this.crypto.getAgentSealerID(id),
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
currentSealerSecret(): SealerSecret {
|
|
138
|
-
return this.crypto.getAgentSealerSecret(this.agentSecret);
|
|
86
|
+
agentSecret: AgentSecret;
|
|
87
|
+
crypto: CryptoProvider;
|
|
88
|
+
|
|
89
|
+
constructor(core: CoValueCore, agentSecret: AgentSecret) {
|
|
90
|
+
super(core);
|
|
91
|
+
|
|
92
|
+
this.agentSecret = agentSecret;
|
|
93
|
+
this.crypto = core.node.crypto;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new group (with the current account as the group's first admin).
|
|
98
|
+
* @category 1. High-level
|
|
99
|
+
*/
|
|
100
|
+
createGroup(
|
|
101
|
+
uniqueness: CoValueUniqueness = this.core.crypto.createdNowUnique(),
|
|
102
|
+
) {
|
|
103
|
+
return this.core.node.createGroup(uniqueness);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async acceptInvite<T extends RawCoValue>(
|
|
107
|
+
groupOrOwnedValueID: CoID<T>,
|
|
108
|
+
inviteSecret: InviteSecret,
|
|
109
|
+
): Promise<void> {
|
|
110
|
+
return this.core.node.acceptInvite(groupOrOwnedValueID, inviteSecret);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
currentAgentID(): Result<AgentID, InvalidAccountAgentIDError> {
|
|
114
|
+
if (this._cachedCurrentAgentID) {
|
|
115
|
+
return ok(this._cachedCurrentAgentID);
|
|
139
116
|
}
|
|
117
|
+
const agentID = this.crypto.getAgentID(this.agentSecret);
|
|
118
|
+
this._cachedCurrentAgentID = agentID;
|
|
119
|
+
return ok(agentID);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
currentSignerID() {
|
|
123
|
+
return this.currentAgentID().map((id) => this.crypto.getAgentSignerID(id));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
currentSignerSecret(): SignerSecret {
|
|
127
|
+
return this.crypto.getAgentSignerSecret(this.agentSecret);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
currentSealerID() {
|
|
131
|
+
return this.currentAgentID().map((id) => this.crypto.getAgentSealerID(id));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
currentSealerSecret(): SealerSecret {
|
|
135
|
+
return this.crypto.getAgentSealerSecret(this.agentSecret);
|
|
136
|
+
}
|
|
140
137
|
}
|
|
141
138
|
|
|
142
139
|
export class ControlledAgent implements ControlledAccountOrAgent {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
currentSealerSecret(): SealerSecret {
|
|
173
|
-
return this.crypto.getAgentSealerSecret(this.agentSecret);
|
|
174
|
-
}
|
|
140
|
+
constructor(
|
|
141
|
+
public agentSecret: AgentSecret,
|
|
142
|
+
public crypto: CryptoProvider,
|
|
143
|
+
) {}
|
|
144
|
+
|
|
145
|
+
get id(): AgentID {
|
|
146
|
+
return this.crypto.getAgentID(this.agentSecret);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
currentAgentID() {
|
|
150
|
+
return ok(this.crypto.getAgentID(this.agentSecret));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
currentSignerID() {
|
|
154
|
+
return this.currentAgentID().map((id) => this.crypto.getAgentSignerID(id));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
currentSignerSecret(): SignerSecret {
|
|
158
|
+
return this.crypto.getAgentSignerSecret(this.agentSecret);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
currentSealerID() {
|
|
162
|
+
return this.currentAgentID().map((id) => this.crypto.getAgentSealerID(id));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
currentSealerSecret(): SealerSecret {
|
|
166
|
+
return this.crypto.getAgentSealerSecret(this.agentSecret);
|
|
167
|
+
}
|
|
175
168
|
}
|
|
176
169
|
|
|
177
170
|
export type AccountMeta = { type: "account" };
|
|
178
171
|
export type RawAccountID = CoID<RawAccount>;
|
|
179
172
|
|
|
180
173
|
export type ProfileShape = {
|
|
181
|
-
|
|
174
|
+
name: string;
|
|
182
175
|
};
|
|
183
176
|
|
|
184
177
|
export class RawProfile<
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
Shape extends ProfileShape = ProfileShape,
|
|
179
|
+
Meta extends JsonObject | null = JsonObject | null,
|
|
187
180
|
> extends RawCoMap<Shape, Meta> {}
|
|
188
181
|
|
|
189
182
|
export type RawAccountMigration<Meta extends AccountMeta = AccountMeta> = (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
183
|
+
account: RawControlledAccount<Meta>,
|
|
184
|
+
localNode: LocalNode,
|
|
185
|
+
creationProps?: { name: string },
|
|
193
186
|
) => void | Promise<void>;
|