cojson 0.7.34 → 0.7.35-guest-auth.5
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 +7 -2
- package/.turbo/turbo-test.log +269 -268
- package/CHANGELOG.md +12 -0
- package/dist/coValueCore.js +0 -6
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/account.js +2 -3
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/coStream.js.map +1 -1
- package/dist/coValues/group.js +8 -8
- package/dist/coValues/group.js.map +1 -1
- package/dist/crypto/crypto.js +3 -0
- package/dist/crypto/crypto.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/localNode.js +9 -9
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.js.map +1 -1
- package/dist/tests/account.test.js +1 -2
- package/dist/tests/account.test.js.map +1 -1
- package/dist/tests/permissions.test.js +41 -42
- package/dist/tests/permissions.test.js.map +1 -1
- package/dist/tests/sync.test.js +4 -5
- package/dist/tests/sync.test.js.map +1 -1
- package/dist/tests/testUtils.js +1 -2
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/typeUtils/isAccountID.js.map +1 -1
- package/package.json +1 -1
- package/src/coValueCore.ts +7 -15
- package/src/coValues/account.ts +5 -6
- 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/crypto.ts +5 -0
- package/src/ids.ts +2 -2
- package/src/index.ts +4 -4
- package/src/localNode.ts +18 -18
- package/src/permissions.ts +5 -5
- package/src/tests/account.test.ts +1 -2
- package/src/tests/permissions.test.ts +41 -42
- package/src/tests/sync.test.ts +7 -8
- package/src/tests/testUtils.ts +1 -2
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +3 -3
- package/src/typeUtils/isAccountID.ts +2 -2
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,7 +19,7 @@ import {
|
|
|
19
19
|
ControlledAccountOrAgent,
|
|
20
20
|
RawControlledAccount,
|
|
21
21
|
ControlledAgent,
|
|
22
|
-
|
|
22
|
+
RawAccountID,
|
|
23
23
|
RawProfile,
|
|
24
24
|
RawAccountMigration,
|
|
25
25
|
InvalidAccountAgentIDError,
|
|
@@ -81,14 +81,14 @@ export class LocalNode {
|
|
|
81
81
|
initialAgentSecret?: AgentSecret;
|
|
82
82
|
}): Promise<{
|
|
83
83
|
node: LocalNode;
|
|
84
|
-
accountID:
|
|
84
|
+
accountID: RawAccountID;
|
|
85
85
|
accountSecret: AgentSecret;
|
|
86
86
|
sessionID: SessionID;
|
|
87
87
|
}> {
|
|
88
88
|
const throwawayAgent = crypto.newRandomAgentSecret();
|
|
89
89
|
const setupNode = new LocalNode(
|
|
90
90
|
new ControlledAgent(throwawayAgent, crypto),
|
|
91
|
-
newRandomSessionID(crypto.getAgentID(throwawayAgent)),
|
|
91
|
+
crypto.newRandomSessionID(crypto.getAgentID(throwawayAgent)),
|
|
92
92
|
crypto,
|
|
93
93
|
);
|
|
94
94
|
|
|
@@ -96,7 +96,7 @@ export class LocalNode {
|
|
|
96
96
|
|
|
97
97
|
const nodeWithAccount = account.core.node.testWithDifferentAccount(
|
|
98
98
|
account,
|
|
99
|
-
newRandomSessionID(account.id),
|
|
99
|
+
crypto.newRandomSessionID(account.id),
|
|
100
100
|
);
|
|
101
101
|
|
|
102
102
|
const accountOnNodeWithAccount =
|
|
@@ -173,7 +173,7 @@ export class LocalNode {
|
|
|
173
173
|
crypto,
|
|
174
174
|
migration,
|
|
175
175
|
}: {
|
|
176
|
-
accountID:
|
|
176
|
+
accountID: RawAccountID;
|
|
177
177
|
accountSecret: AgentSecret;
|
|
178
178
|
sessionID: SessionID | undefined;
|
|
179
179
|
peersToLoadFrom: Peer[];
|
|
@@ -182,7 +182,7 @@ export class LocalNode {
|
|
|
182
182
|
}): Promise<LocalNode> {
|
|
183
183
|
const loadingNode = new LocalNode(
|
|
184
184
|
new ControlledAgent(accountSecret, crypto),
|
|
185
|
-
newRandomSessionID(accountID),
|
|
185
|
+
crypto.newRandomSessionID(accountID),
|
|
186
186
|
crypto,
|
|
187
187
|
);
|
|
188
188
|
|
|
@@ -206,7 +206,7 @@ export class LocalNode {
|
|
|
206
206
|
// since this is all synchronous, we can just swap out nodes for the SyncManager
|
|
207
207
|
const node = loadingNode.testWithDifferentAccount(
|
|
208
208
|
controlledAccount,
|
|
209
|
-
sessionID || newRandomSessionID(accountID),
|
|
209
|
+
sessionID || crypto.newRandomSessionID(accountID),
|
|
210
210
|
);
|
|
211
211
|
node.syncManager = loadingNode.syncManager;
|
|
212
212
|
node.syncManager.local = node;
|
|
@@ -429,7 +429,7 @@ export class LocalNode {
|
|
|
429
429
|
group.core
|
|
430
430
|
.testWithDifferentAccount(
|
|
431
431
|
new ControlledAgent(inviteAgentSecret, this.crypto),
|
|
432
|
-
newRandomSessionID(inviteAgentID),
|
|
432
|
+
this.crypto.newRandomSessionID(inviteAgentID),
|
|
433
433
|
)
|
|
434
434
|
.getCurrentContent(),
|
|
435
435
|
);
|
|
@@ -470,7 +470,7 @@ export class LocalNode {
|
|
|
470
470
|
}
|
|
471
471
|
|
|
472
472
|
/** @internal */
|
|
473
|
-
expectProfileLoaded(id:
|
|
473
|
+
expectProfileLoaded(id: RawAccountID, expectation?: string): RawProfile {
|
|
474
474
|
const account = this.expectCoValueLoaded(id, expectation);
|
|
475
475
|
const profileID = expectGroup(account.getCurrentContent()).get(
|
|
476
476
|
"profile",
|
|
@@ -499,7 +499,7 @@ export class LocalNode {
|
|
|
499
499
|
)
|
|
500
500
|
.testWithDifferentAccount(
|
|
501
501
|
new ControlledAgent(agentSecret, this.crypto),
|
|
502
|
-
newRandomSessionID(accountAgentID),
|
|
502
|
+
this.crypto.newRandomSessionID(accountAgentID),
|
|
503
503
|
)
|
|
504
504
|
.getCurrentContent(),
|
|
505
505
|
);
|
|
@@ -533,7 +533,7 @@ export class LocalNode {
|
|
|
533
533
|
|
|
534
534
|
/** @internal */
|
|
535
535
|
resolveAccountAgent(
|
|
536
|
-
id:
|
|
536
|
+
id: RawAccountID | AgentID,
|
|
537
537
|
expectation?: string,
|
|
538
538
|
): Result<AgentID, ResolveAccountAgentError> {
|
|
539
539
|
if (isAgentID(id)) {
|
|
@@ -560,7 +560,7 @@ export class LocalNode {
|
|
|
560
560
|
}
|
|
561
561
|
|
|
562
562
|
resolveAccountAgentAsync(
|
|
563
|
-
id:
|
|
563
|
+
id: RawAccountID | AgentID,
|
|
564
564
|
expectation?: string,
|
|
565
565
|
): ResultAsync<AgentID, ResolveAccountAgentError> {
|
|
566
566
|
if (isAgentID(id)) {
|
|
@@ -606,12 +606,12 @@ export class LocalNode {
|
|
|
606
606
|
/**
|
|
607
607
|
* @deprecated use Account.createGroup() instead
|
|
608
608
|
*/
|
|
609
|
-
createGroup(): RawGroup {
|
|
609
|
+
createGroup(uniqueness: CoValueUniqueness = this.crypto.createdNowUnique()): RawGroup {
|
|
610
610
|
const groupCoValue = this.createCoValue({
|
|
611
611
|
type: "comap",
|
|
612
612
|
ruleset: { type: "group", initialAdmin: this.account.id },
|
|
613
613
|
meta: null,
|
|
614
|
-
...
|
|
614
|
+
...uniqueness
|
|
615
615
|
});
|
|
616
616
|
|
|
617
617
|
const group = expectGroup(groupCoValue.getCurrentContent());
|
|
@@ -731,19 +731,19 @@ export type LoadCoValueCoreError = {
|
|
|
731
731
|
type: "ErrorLoadingCoValueCore";
|
|
732
732
|
error: unknown;
|
|
733
733
|
expectation?: string;
|
|
734
|
-
id:
|
|
734
|
+
id: RawAccountID;
|
|
735
735
|
};
|
|
736
736
|
|
|
737
737
|
export type AccountUnavailableFromAllPeersError = {
|
|
738
738
|
type: "AccountUnavailableFromAllPeers";
|
|
739
739
|
expectation?: string;
|
|
740
|
-
id:
|
|
740
|
+
id: RawAccountID;
|
|
741
741
|
};
|
|
742
742
|
|
|
743
743
|
export type UnexpectedlyNotAccountError = {
|
|
744
744
|
type: "UnexpectedlyNotAccount";
|
|
745
745
|
expectation?: string;
|
|
746
|
-
id:
|
|
746
|
+
id: RawAccountID;
|
|
747
747
|
};
|
|
748
748
|
|
|
749
749
|
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,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,5 +1,4 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
-
import { newRandomSessionID } from "../coValueCore.js";
|
|
3
2
|
import { expectMap } from "../coValue.js";
|
|
4
3
|
import {
|
|
5
4
|
newGroup,
|
|
@@ -27,7 +26,7 @@ test("Added admin can add a third admin to a group", () => {
|
|
|
27
26
|
groupCore
|
|
28
27
|
.testWithDifferentAccount(
|
|
29
28
|
otherAdmin,
|
|
30
|
-
newRandomSessionID(otherAdmin.id),
|
|
29
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
31
30
|
)
|
|
32
31
|
.getCurrentContent(),
|
|
33
32
|
);
|
|
@@ -47,7 +46,7 @@ test("Added adming can add a third admin to a group (high level)", () => {
|
|
|
47
46
|
group.core
|
|
48
47
|
.testWithDifferentAccount(
|
|
49
48
|
otherAdmin,
|
|
50
|
-
newRandomSessionID(otherAdmin.id),
|
|
49
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
51
50
|
)
|
|
52
51
|
.getCurrentContent(),
|
|
53
52
|
);
|
|
@@ -73,7 +72,7 @@ test("Admins can't demote other admins in a group", () => {
|
|
|
73
72
|
groupCore
|
|
74
73
|
.testWithDifferentAccount(
|
|
75
74
|
otherAdmin,
|
|
76
|
-
newRandomSessionID(otherAdmin.id),
|
|
75
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
77
76
|
)
|
|
78
77
|
.getCurrentContent(),
|
|
79
78
|
);
|
|
@@ -89,7 +88,7 @@ test("Admins can't demote other admins in a group (high level)", () => {
|
|
|
89
88
|
group.core
|
|
90
89
|
.testWithDifferentAccount(
|
|
91
90
|
otherAdmin,
|
|
92
|
-
newRandomSessionID(otherAdmin.id),
|
|
91
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
93
92
|
)
|
|
94
93
|
.getCurrentContent(),
|
|
95
94
|
);
|
|
@@ -114,7 +113,7 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
|
|
|
114
113
|
|
|
115
114
|
const groupAsWriter = expectGroup(
|
|
116
115
|
groupCore
|
|
117
|
-
.testWithDifferentAccount(writer, newRandomSessionID(writer.id))
|
|
116
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
118
117
|
.getCurrentContent(),
|
|
119
118
|
);
|
|
120
119
|
|
|
@@ -142,7 +141,7 @@ test("Admins an add writers to a group, who can't add admins, writers, or reader
|
|
|
142
141
|
|
|
143
142
|
const groupAsWriter = expectGroup(
|
|
144
143
|
group.core
|
|
145
|
-
.testWithDifferentAccount(writer, newRandomSessionID(writer.id))
|
|
144
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
146
145
|
.getCurrentContent(),
|
|
147
146
|
);
|
|
148
147
|
|
|
@@ -174,7 +173,7 @@ test("Admins can add readers to a group, who can't add admins, writers, or reade
|
|
|
174
173
|
|
|
175
174
|
const groupAsReader = expectGroup(
|
|
176
175
|
groupCore
|
|
177
|
-
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
176
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
178
177
|
.getCurrentContent(),
|
|
179
178
|
);
|
|
180
179
|
|
|
@@ -203,7 +202,7 @@ test("Admins can add readers to a group, who can't add admins, writers, or reade
|
|
|
203
202
|
|
|
204
203
|
const groupAsReader = expectGroup(
|
|
205
204
|
group.core
|
|
206
|
-
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
205
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
207
206
|
.getCurrentContent(),
|
|
208
207
|
);
|
|
209
208
|
|
|
@@ -267,7 +266,7 @@ test("Writers can write to an object that is owned by their group", () => {
|
|
|
267
266
|
|
|
268
267
|
const childObjectAsWriter = childObject.testWithDifferentAccount(
|
|
269
268
|
writer,
|
|
270
|
-
newRandomSessionID(writer.id),
|
|
269
|
+
Crypto.newRandomSessionID(writer.id),
|
|
271
270
|
);
|
|
272
271
|
|
|
273
272
|
const childContentAsWriter = expectMap(
|
|
@@ -289,7 +288,7 @@ test("Writers can write to an object that is owned by their group (high level)",
|
|
|
289
288
|
|
|
290
289
|
const childObjectAsWriter = expectMap(
|
|
291
290
|
childObject.core
|
|
292
|
-
.testWithDifferentAccount(writer, newRandomSessionID(writer.id))
|
|
291
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
293
292
|
.getCurrentContent(),
|
|
294
293
|
);
|
|
295
294
|
|
|
@@ -315,7 +314,7 @@ test("Readers can not write to an object that is owned by their group", () => {
|
|
|
315
314
|
|
|
316
315
|
const childObjectAsReader = childObject.testWithDifferentAccount(
|
|
317
316
|
reader,
|
|
318
|
-
newRandomSessionID(reader.id),
|
|
317
|
+
Crypto.newRandomSessionID(reader.id),
|
|
319
318
|
);
|
|
320
319
|
|
|
321
320
|
const childContentAsReader = expectMap(
|
|
@@ -337,7 +336,7 @@ test("Readers can not write to an object that is owned by their group (high leve
|
|
|
337
336
|
|
|
338
337
|
const childObjectAsReader = expectMap(
|
|
339
338
|
childObject.core
|
|
340
|
-
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
339
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
341
340
|
.getCurrentContent(),
|
|
342
341
|
);
|
|
343
342
|
|
|
@@ -442,7 +441,7 @@ test("Admins can set group read key and then writers can use it to create and re
|
|
|
442
441
|
|
|
443
442
|
const childObjectAsWriter = childObject.testWithDifferentAccount(
|
|
444
443
|
writer,
|
|
445
|
-
newRandomSessionID(writer.id),
|
|
444
|
+
Crypto.newRandomSessionID(writer.id),
|
|
446
445
|
);
|
|
447
446
|
|
|
448
447
|
expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
|
|
@@ -466,7 +465,7 @@ test("Admins can set group read key and then writers can use it to create and re
|
|
|
466
465
|
|
|
467
466
|
const childObjectAsWriter = expectMap(
|
|
468
467
|
childObject.core
|
|
469
|
-
.testWithDifferentAccount(writer, newRandomSessionID(writer.id))
|
|
468
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
470
469
|
.getCurrentContent(),
|
|
471
470
|
);
|
|
472
471
|
|
|
@@ -526,7 +525,7 @@ test("Admins can set group read key and then use it to create private transactio
|
|
|
526
525
|
|
|
527
526
|
const childObjectAsReader = childObject.testWithDifferentAccount(
|
|
528
527
|
reader,
|
|
529
|
-
newRandomSessionID(reader.id),
|
|
528
|
+
Crypto.newRandomSessionID(reader.id),
|
|
530
529
|
);
|
|
531
530
|
|
|
532
531
|
expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
|
|
@@ -552,7 +551,7 @@ test("Admins can set group read key and then use it to create private transactio
|
|
|
552
551
|
|
|
553
552
|
const childContentAsReader = expectMap(
|
|
554
553
|
childObject.core
|
|
555
|
-
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
554
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
556
555
|
.getCurrentContent(),
|
|
557
556
|
);
|
|
558
557
|
|
|
@@ -613,7 +612,7 @@ test("Admins can set group read key and then use it to create private transactio
|
|
|
613
612
|
|
|
614
613
|
const childObjectAsReader1 = childObject.testWithDifferentAccount(
|
|
615
614
|
reader1,
|
|
616
|
-
newRandomSessionID(reader1.id),
|
|
615
|
+
Crypto.newRandomSessionID(reader1.id),
|
|
617
616
|
);
|
|
618
617
|
|
|
619
618
|
expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
|
|
@@ -638,7 +637,7 @@ test("Admins can set group read key and then use it to create private transactio
|
|
|
638
637
|
|
|
639
638
|
const childObjectAsReader2 = childObject.testWithDifferentAccount(
|
|
640
639
|
reader2,
|
|
641
|
-
newRandomSessionID(reader2.id),
|
|
640
|
+
Crypto.newRandomSessionID(reader2.id),
|
|
642
641
|
);
|
|
643
642
|
|
|
644
643
|
expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
|
|
@@ -666,7 +665,7 @@ test("Admins can set group read key and then use it to create private transactio
|
|
|
666
665
|
|
|
667
666
|
const childContentAsReader1 = expectMap(
|
|
668
667
|
childObject.core
|
|
669
|
-
.testWithDifferentAccount(reader1, newRandomSessionID(reader1.id))
|
|
668
|
+
.testWithDifferentAccount(reader1, Crypto.newRandomSessionID(reader1.id))
|
|
670
669
|
.getCurrentContent(),
|
|
671
670
|
);
|
|
672
671
|
|
|
@@ -676,7 +675,7 @@ test("Admins can set group read key and then use it to create private transactio
|
|
|
676
675
|
|
|
677
676
|
const childContentAsReader2 = expectMap(
|
|
678
677
|
childObject.core
|
|
679
|
-
.testWithDifferentAccount(reader2, newRandomSessionID(reader2.id))
|
|
678
|
+
.testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
|
|
680
679
|
.getCurrentContent(),
|
|
681
680
|
);
|
|
682
681
|
|
|
@@ -845,7 +844,7 @@ test("Admins can set group read key, make a private transaction in an owned obje
|
|
|
845
844
|
|
|
846
845
|
const childObjectAsReader = childObject.testWithDifferentAccount(
|
|
847
846
|
reader,
|
|
848
|
-
newRandomSessionID(reader.id),
|
|
847
|
+
Crypto.newRandomSessionID(reader.id),
|
|
849
848
|
);
|
|
850
849
|
|
|
851
850
|
expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
|
|
@@ -883,7 +882,7 @@ test("Admins can set group read key, make a private transaction in an owned obje
|
|
|
883
882
|
|
|
884
883
|
const childContentAsReader = expectMap(
|
|
885
884
|
childObject.core
|
|
886
|
-
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
885
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
887
886
|
.getCurrentContent(),
|
|
888
887
|
);
|
|
889
888
|
|
|
@@ -959,7 +958,7 @@ test("Admins can set group read rey, make a private transaction in an owned obje
|
|
|
959
958
|
|
|
960
959
|
let childObjectAsReader = childObject.testWithDifferentAccount(
|
|
961
960
|
reader,
|
|
962
|
-
newRandomSessionID(reader.id),
|
|
961
|
+
Crypto.newRandomSessionID(reader.id),
|
|
963
962
|
);
|
|
964
963
|
|
|
965
964
|
expect(
|
|
@@ -968,7 +967,7 @@ test("Admins can set group read rey, make a private transaction in an owned obje
|
|
|
968
967
|
|
|
969
968
|
let childObjectAsReader2 = childObject.testWithDifferentAccount(
|
|
970
969
|
reader,
|
|
971
|
-
newRandomSessionID(reader.id),
|
|
970
|
+
Crypto.newRandomSessionID(reader.id),
|
|
972
971
|
);
|
|
973
972
|
|
|
974
973
|
expect(
|
|
@@ -1024,11 +1023,11 @@ test("Admins can set group read rey, make a private transaction in an owned obje
|
|
|
1024
1023
|
// TODO: make sure these instances of coValues sync between each other so this isn't necessary?
|
|
1025
1024
|
childObjectAsReader = childObject.testWithDifferentAccount(
|
|
1026
1025
|
reader,
|
|
1027
|
-
newRandomSessionID(reader.id),
|
|
1026
|
+
Crypto.newRandomSessionID(reader.id),
|
|
1028
1027
|
);
|
|
1029
1028
|
childObjectAsReader2 = childObject.testWithDifferentAccount(
|
|
1030
1029
|
reader2,
|
|
1031
|
-
newRandomSessionID(reader2.id),
|
|
1030
|
+
Crypto.newRandomSessionID(reader2.id),
|
|
1032
1031
|
);
|
|
1033
1032
|
|
|
1034
1033
|
expect(
|
|
@@ -1072,7 +1071,7 @@ test("Admins can set group read rey, make a private transaction in an owned obje
|
|
|
1072
1071
|
|
|
1073
1072
|
const childContentAsReader2 = expectMap(
|
|
1074
1073
|
childObject.core
|
|
1075
|
-
.testWithDifferentAccount(reader2, newRandomSessionID(reader2.id))
|
|
1074
|
+
.testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
|
|
1076
1075
|
.getCurrentContent(),
|
|
1077
1076
|
);
|
|
1078
1077
|
|
|
@@ -1083,7 +1082,7 @@ test("Admins can set group read rey, make a private transaction in an owned obje
|
|
|
1083
1082
|
expect(
|
|
1084
1083
|
expectMap(
|
|
1085
1084
|
childObject.core
|
|
1086
|
-
.testWithDifferentAccount(reader, newRandomSessionID(reader.id))
|
|
1085
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
1087
1086
|
.getCurrentContent(),
|
|
1088
1087
|
).get("foo3"),
|
|
1089
1088
|
).toBeUndefined();
|
|
@@ -1151,7 +1150,7 @@ test("Admins can create an adminInvite, which can add an admin", () => {
|
|
|
1151
1150
|
groupCore
|
|
1152
1151
|
.testWithDifferentAccount(
|
|
1153
1152
|
new ControlledAgent(inviteSecret, Crypto),
|
|
1154
|
-
newRandomSessionID(inviteID),
|
|
1153
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1155
1154
|
)
|
|
1156
1155
|
.getCurrentContent(),
|
|
1157
1156
|
);
|
|
@@ -1198,7 +1197,7 @@ test("Admins can create an adminInvite, which can add an admin (high-level)", as
|
|
|
1198
1197
|
|
|
1199
1198
|
const nodeAsInvitedAdmin = node.testWithDifferentAccount(
|
|
1200
1199
|
new ControlledAgent(invitedAdminSecret, Crypto),
|
|
1201
|
-
newRandomSessionID(invitedAdminID),
|
|
1200
|
+
Crypto.newRandomSessionID(invitedAdminID),
|
|
1202
1201
|
);
|
|
1203
1202
|
|
|
1204
1203
|
await nodeAsInvitedAdmin.acceptInvite(group.id, inviteSecret);
|
|
@@ -1261,7 +1260,7 @@ test("Admins can create a writerInvite, which can add a writer", () => {
|
|
|
1261
1260
|
groupCore
|
|
1262
1261
|
.testWithDifferentAccount(
|
|
1263
1262
|
new ControlledAgent(inviteSecret, Crypto),
|
|
1264
|
-
newRandomSessionID(inviteID),
|
|
1263
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1265
1264
|
)
|
|
1266
1265
|
.getCurrentContent(),
|
|
1267
1266
|
);
|
|
@@ -1308,7 +1307,7 @@ test("Admins can create a writerInvite, which can add a writer (high-level)", as
|
|
|
1308
1307
|
|
|
1309
1308
|
const nodeAsInvitedWriter = node.testWithDifferentAccount(
|
|
1310
1309
|
new ControlledAgent(invitedWriterSecret, Crypto),
|
|
1311
|
-
newRandomSessionID(invitedWriterID),
|
|
1310
|
+
Crypto.newRandomSessionID(invitedWriterID),
|
|
1312
1311
|
);
|
|
1313
1312
|
|
|
1314
1313
|
await nodeAsInvitedWriter.acceptInvite(group.id, inviteSecret);
|
|
@@ -1364,7 +1363,7 @@ test("Admins can create a readerInvite, which can add a reader", () => {
|
|
|
1364
1363
|
groupCore
|
|
1365
1364
|
.testWithDifferentAccount(
|
|
1366
1365
|
new ControlledAgent(inviteSecret, Crypto),
|
|
1367
|
-
newRandomSessionID(inviteID),
|
|
1366
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1368
1367
|
)
|
|
1369
1368
|
.getCurrentContent(),
|
|
1370
1369
|
);
|
|
@@ -1401,7 +1400,7 @@ test("Admins can create a readerInvite, which can add a reader (high-level)", as
|
|
|
1401
1400
|
|
|
1402
1401
|
const nodeAsInvitedReader = node.testWithDifferentAccount(
|
|
1403
1402
|
new ControlledAgent(invitedReaderSecret, Crypto),
|
|
1404
|
-
newRandomSessionID(invitedReaderID),
|
|
1403
|
+
Crypto.newRandomSessionID(invitedReaderID),
|
|
1405
1404
|
);
|
|
1406
1405
|
|
|
1407
1406
|
await nodeAsInvitedReader.acceptInvite(group.id, inviteSecret);
|
|
@@ -1457,7 +1456,7 @@ test("WriterInvites can not invite admins", () => {
|
|
|
1457
1456
|
groupCore
|
|
1458
1457
|
.testWithDifferentAccount(
|
|
1459
1458
|
new ControlledAgent(inviteSecret, Crypto),
|
|
1460
|
-
newRandomSessionID(inviteID),
|
|
1459
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1461
1460
|
)
|
|
1462
1461
|
.getCurrentContent(),
|
|
1463
1462
|
);
|
|
@@ -1511,7 +1510,7 @@ test("ReaderInvites can not invite admins", () => {
|
|
|
1511
1510
|
groupCore
|
|
1512
1511
|
.testWithDifferentAccount(
|
|
1513
1512
|
new ControlledAgent(inviteSecret, Crypto),
|
|
1514
|
-
newRandomSessionID(inviteID),
|
|
1513
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1515
1514
|
)
|
|
1516
1515
|
.getCurrentContent(),
|
|
1517
1516
|
);
|
|
@@ -1565,7 +1564,7 @@ test("ReaderInvites can not invite writers", () => {
|
|
|
1565
1564
|
groupCore
|
|
1566
1565
|
.testWithDifferentAccount(
|
|
1567
1566
|
new ControlledAgent(inviteSecret, Crypto),
|
|
1568
|
-
newRandomSessionID(inviteID),
|
|
1567
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1569
1568
|
)
|
|
1570
1569
|
.getCurrentContent(),
|
|
1571
1570
|
);
|
|
@@ -1610,7 +1609,7 @@ test("Can give read permission to 'everyone'", () => {
|
|
|
1610
1609
|
childObject
|
|
1611
1610
|
.testWithDifferentAccount(
|
|
1612
1611
|
newAccount,
|
|
1613
|
-
newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1612
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1614
1613
|
)
|
|
1615
1614
|
.getCurrentContent(),
|
|
1616
1615
|
);
|
|
@@ -1639,7 +1638,7 @@ test("Can give read permissions to 'everyone' (high-level)", async () => {
|
|
|
1639
1638
|
childObject.core
|
|
1640
1639
|
.testWithDifferentAccount(
|
|
1641
1640
|
new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto),
|
|
1642
|
-
newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1641
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1643
1642
|
)
|
|
1644
1643
|
.getCurrentContent(),
|
|
1645
1644
|
);
|
|
@@ -1680,7 +1679,7 @@ test("Can give write permission to 'everyone'", async () => {
|
|
|
1680
1679
|
childObject
|
|
1681
1680
|
.testWithDifferentAccount(
|
|
1682
1681
|
newAccount,
|
|
1683
|
-
newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1682
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1684
1683
|
)
|
|
1685
1684
|
.getCurrentContent(),
|
|
1686
1685
|
);
|
|
@@ -1715,7 +1714,7 @@ test("Can give write permissions to 'everyone' (high-level)", async () => {
|
|
|
1715
1714
|
childObject.core
|
|
1716
1715
|
.testWithDifferentAccount(
|
|
1717
1716
|
newAccount,
|
|
1718
|
-
newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1717
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1719
1718
|
)
|
|
1720
1719
|
.getCurrentContent(),
|
|
1721
1720
|
);
|
package/src/tests/sync.test.ts
CHANGED
|
@@ -5,11 +5,10 @@ import { MapOpPayload } from "../coValues/coMap.js";
|
|
|
5
5
|
import { RawGroup } from "../coValues/group.js";
|
|
6
6
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
7
7
|
import { connectedPeers, newQueuePair } from "../streamUtils.js";
|
|
8
|
-
import {
|
|
8
|
+
import { RawAccountID } from "../coValues/account.js";
|
|
9
9
|
import { stableStringify } from "../jsonStringify.js";
|
|
10
10
|
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
11
11
|
import { expectMap } from "../coValue.js";
|
|
12
|
-
import { newRandomSessionID } from "../coValueCore.js";
|
|
13
12
|
|
|
14
13
|
const Crypto = await WasmCrypto.create();
|
|
15
14
|
|
|
@@ -713,7 +712,7 @@ test.skip("When replaying creation and transactions of a coValue as new content,
|
|
|
713
712
|
crashOnClose: true,
|
|
714
713
|
});
|
|
715
714
|
|
|
716
|
-
const node2 = new LocalNode(admin, newRandomSessionID(admin.id), Crypto);
|
|
715
|
+
const node2 = new LocalNode(admin, Crypto.newRandomSessionID(admin.id), Crypto);
|
|
717
716
|
|
|
718
717
|
const [inRx2, inTx2] = newQueuePair();
|
|
719
718
|
const [outRx2, outTx2] = newQueuePair();
|
|
@@ -864,7 +863,7 @@ test("Can sync a coValue through a server to another client", async () => {
|
|
|
864
863
|
client1.syncManager.addPeer(serverAsPeerForClient1);
|
|
865
864
|
server.syncManager.addPeer(client1AsPeer);
|
|
866
865
|
|
|
867
|
-
const client2 = new LocalNode(admin, newRandomSessionID(admin.id), Crypto);
|
|
866
|
+
const client2 = new LocalNode(admin, Crypto.newRandomSessionID(admin.id), Crypto);
|
|
868
867
|
|
|
869
868
|
const [serverAsPeerForClient2, client2AsPeer] = connectedPeers(
|
|
870
869
|
"serverFor2",
|
|
@@ -916,7 +915,7 @@ test("Can sync a coValue with private transactions through a server to another c
|
|
|
916
915
|
client1.syncManager.addPeer(serverAsPeer);
|
|
917
916
|
server.syncManager.addPeer(client1AsPeer);
|
|
918
917
|
|
|
919
|
-
const client2 = new LocalNode(admin, newRandomSessionID(admin.id), Crypto);
|
|
918
|
+
const client2 = new LocalNode(admin, client1.crypto.newRandomSessionID(admin.id), Crypto);
|
|
920
919
|
|
|
921
920
|
const [serverAsOtherPeer, client2AsPeer] = await connectedPeers(
|
|
922
921
|
"server",
|
|
@@ -1064,7 +1063,7 @@ test("If we start loading a coValue before connecting to a peer that has it, it
|
|
|
1064
1063
|
const map = group.createMap();
|
|
1065
1064
|
map.set("hello", "world", "trusting");
|
|
1066
1065
|
|
|
1067
|
-
const node2 = new LocalNode(admin, newRandomSessionID(admin.id), Crypto);
|
|
1066
|
+
const node2 = new LocalNode(admin, Crypto.newRandomSessionID(admin.id), Crypto);
|
|
1068
1067
|
|
|
1069
1068
|
const [node1asPeer, node2asPeer] = await connectedPeers("peer1", "peer2", {
|
|
1070
1069
|
peer1role: "server",
|
|
@@ -1097,7 +1096,7 @@ function groupContentEx(group: RawGroup) {
|
|
|
1097
1096
|
};
|
|
1098
1097
|
}
|
|
1099
1098
|
|
|
1100
|
-
function _admContEx(adminID:
|
|
1099
|
+
function _admContEx(adminID: RawAccountID) {
|
|
1101
1100
|
return {
|
|
1102
1101
|
action: "content",
|
|
1103
1102
|
id: adminID,
|
|
@@ -1111,7 +1110,7 @@ function groupStateEx(group: RawGroup) {
|
|
|
1111
1110
|
};
|
|
1112
1111
|
}
|
|
1113
1112
|
|
|
1114
|
-
function _admStateEx(adminID:
|
|
1113
|
+
function _admStateEx(adminID: RawAccountID) {
|
|
1115
1114
|
return {
|
|
1116
1115
|
action: "known",
|
|
1117
1116
|
id: adminID,
|
package/src/tests/testUtils.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { expect } from "vitest";
|
|
2
|
-
import { newRandomSessionID } from "../coValueCore.js";
|
|
3
2
|
import { LocalNode } from "../localNode.js";
|
|
4
3
|
import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
5
4
|
import { ControlledAgent } from "../coValues/account.js";
|
|
@@ -14,7 +13,7 @@ export function randomAnonymousAccountAndSessionID(): [
|
|
|
14
13
|
] {
|
|
15
14
|
const agentSecret = Crypto.newRandomAgentSecret();
|
|
16
15
|
|
|
17
|
-
const sessionID = newRandomSessionID(Crypto.getAgentID(agentSecret));
|
|
16
|
+
const sessionID = Crypto.newRandomSessionID(Crypto.getAgentID(agentSecret));
|
|
18
17
|
|
|
19
18
|
return [new ControlledAgent(agentSecret, Crypto), sessionID];
|
|
20
19
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentID, SessionID } from "../ids.js";
|
|
2
|
-
import {
|
|
2
|
+
import { RawAccountID } from "../coValues/account.js";
|
|
3
3
|
|
|
4
4
|
export function accountOrAgentIDfromSessionID(
|
|
5
5
|
sessionID: SessionID,
|
|
6
|
-
):
|
|
6
|
+
): RawAccountID | AgentID {
|
|
7
7
|
const until = sessionID.indexOf("_session");
|
|
8
|
-
return sessionID.slice(0, until) as
|
|
8
|
+
return sessionID.slice(0, until) as RawAccountID | AgentID;
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawAccountID } from "../coValues/account.js";
|
|
2
2
|
import type { AgentID } from "../ids.js";
|
|
3
3
|
|
|
4
|
-
export function isAccountID(id:
|
|
4
|
+
export function isAccountID(id: RawAccountID | AgentID): id is RawAccountID {
|
|
5
5
|
return id.startsWith("co_");
|
|
6
6
|
}
|