cojson 0.8.12 → 0.8.16
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 +89 -83
- package/dist/native/PeerKnownStates.js +1 -1
- package/dist/native/PeerKnownStates.js.map +1 -1
- package/dist/native/PeerState.js +1 -1
- 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/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 +2 -4
- 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 +1 -1
- package/dist/web/PeerKnownStates.js.map +1 -1
- package/dist/web/PeerState.js +1 -1
- 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/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 +2 -4
- 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 +91 -89
- package/src/PeerState.ts +72 -73
- package/src/PriorityBasedMessageQueue.ts +42 -49
- 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 +593 -615
- 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/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 +1300 -1291
- package/src/tests/testUtils.ts +52 -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
|
@@ -1,1775 +1,1710 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
2
|
import { expectMap } from "../coValue.js";
|
|
3
|
+
import { ControlledAgent } from "../coValues/account.js";
|
|
4
|
+
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
5
|
+
import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
3
6
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
groupWithTwoAdmins,
|
|
8
|
+
groupWithTwoAdminsHighLevel,
|
|
9
|
+
newGroup,
|
|
10
|
+
newGroupHighLevel,
|
|
8
11
|
} from "./testUtils.js";
|
|
9
|
-
import { expectGroup } from "../typeUtils/expectGroup.js";
|
|
10
|
-
import { WasmCrypto } from "../crypto/WasmCrypto.js";
|
|
11
|
-
import { ControlledAgent } from "../coValues/account.js";
|
|
12
12
|
|
|
13
13
|
const Crypto = await WasmCrypto.create();
|
|
14
14
|
|
|
15
15
|
test("Initial admin can add another admin to a group", () => {
|
|
16
|
-
|
|
16
|
+
groupWithTwoAdmins();
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
test("Initial admin can add another admin to a group (high level)", () => {
|
|
20
|
-
|
|
20
|
+
groupWithTwoAdminsHighLevel();
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test("Added admin can add a third admin to a group", () => {
|
|
24
|
-
|
|
24
|
+
const { groupCore, otherAdmin, node } = groupWithTwoAdmins();
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
const groupAsOtherAdmin = expectGroup(
|
|
27
|
+
groupCore
|
|
28
|
+
.testWithDifferentAccount(
|
|
29
|
+
otherAdmin,
|
|
30
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
31
|
+
)
|
|
32
|
+
.getCurrentContent(),
|
|
33
|
+
);
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
expect(groupAsOtherAdmin.get(otherAdmin.id)).toEqual("admin");
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const thirdAdmin = node.createAccount();
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
groupAsOtherAdmin.set(thirdAdmin.id, "admin", "trusting");
|
|
40
|
+
expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
test("Added adming can add a third admin to a group (high level)", () => {
|
|
44
|
-
|
|
44
|
+
const { group, otherAdmin } = groupWithTwoAdminsHighLevel();
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
const groupAsOtherAdmin = expectGroup(
|
|
47
|
+
group.core
|
|
48
|
+
.testWithDifferentAccount(
|
|
49
|
+
otherAdmin,
|
|
50
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
51
|
+
)
|
|
52
|
+
.getCurrentContent(),
|
|
53
|
+
);
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const thirdAdmin = groupAsOtherAdmin.core.node.createAccount();
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
groupAsOtherAdmin.addMember(thirdAdmin, "admin");
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
test("Admins can't demote other admins in a group", () => {
|
|
63
|
-
|
|
63
|
+
const { groupCore, admin, otherAdmin } = groupWithTwoAdmins();
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
groupContent.set(otherAdmin.id, "writer", "trusting");
|
|
68
|
+
expect(groupContent.get(otherAdmin.id)).toEqual("admin");
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
expect(groupContent.get(otherAdmin.id)).toEqual("admin");
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
const groupAsOtherAdmin = expectGroup(
|
|
73
|
+
groupCore
|
|
74
|
+
.testWithDifferentAccount(
|
|
75
|
+
otherAdmin,
|
|
76
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
77
|
+
)
|
|
78
|
+
.getCurrentContent(),
|
|
79
|
+
);
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
groupAsOtherAdmin.set(admin.id, "writer", "trusting");
|
|
82
|
+
expect(groupAsOtherAdmin.get(admin.id)).toEqual("admin");
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
test("Admins can't demote other admins in a group (high level)", () => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
86
|
+
const { group, admin, otherAdmin } = groupWithTwoAdminsHighLevel();
|
|
87
|
+
|
|
88
|
+
const groupAsOtherAdmin = expectGroup(
|
|
89
|
+
group.core
|
|
90
|
+
.testWithDifferentAccount(
|
|
91
|
+
otherAdmin,
|
|
92
|
+
Crypto.newRandomSessionID(otherAdmin.id),
|
|
93
|
+
)
|
|
94
|
+
.getCurrentContent(),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
expect(() => groupAsOtherAdmin.addMemberInternal(admin.id, "writer")).toThrow(
|
|
98
|
+
"Failed to set role",
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
expect(groupAsOtherAdmin.get(admin.id)).toEqual("admin");
|
|
102
102
|
});
|
|
103
103
|
|
|
104
104
|
test("Admins an add writers to a group, who can't add admins, writers, or readers", () => {
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
const { groupCore, node } = newGroup();
|
|
106
|
+
const writer = node.createAccount();
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
groupContent.set(writer.id, "writer", "trusting");
|
|
111
|
+
expect(groupContent.get(writer.id)).toEqual("writer");
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
expect(groupContent.get(writer.id)).toEqual("writer");
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
.getCurrentContent(),
|
|
122
|
-
);
|
|
115
|
+
const groupAsWriter = expectGroup(
|
|
116
|
+
groupCore
|
|
117
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
118
|
+
.getCurrentContent(),
|
|
119
|
+
);
|
|
123
120
|
|
|
124
|
-
|
|
121
|
+
expect(groupAsWriter.get(writer.id)).toEqual("writer");
|
|
125
122
|
|
|
126
|
-
|
|
123
|
+
const otherAgent = node.createAccount();
|
|
127
124
|
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
groupAsWriter.set(otherAgent.id, "admin", "trusting");
|
|
126
|
+
expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
|
|
130
127
|
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
groupAsWriter.set(otherAgent.id, "writer", "trusting");
|
|
129
|
+
expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
|
|
133
130
|
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
groupAsWriter.set(otherAgent.id, "reader", "trusting");
|
|
132
|
+
expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
|
|
136
133
|
});
|
|
137
134
|
|
|
138
135
|
test("Admins an add writers to a group, who can't add admins, writers, or readers (high level)", () => {
|
|
139
|
-
|
|
136
|
+
const { group, node } = newGroupHighLevel();
|
|
140
137
|
|
|
141
|
-
|
|
138
|
+
const writer = node.createAccount();
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
group.addMember(writer, "writer");
|
|
141
|
+
expect(group.get(writer.id)).toEqual("writer");
|
|
145
142
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
)
|
|
152
|
-
.getCurrentContent(),
|
|
153
|
-
);
|
|
143
|
+
const groupAsWriter = expectGroup(
|
|
144
|
+
group.core
|
|
145
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
146
|
+
.getCurrentContent(),
|
|
147
|
+
);
|
|
154
148
|
|
|
155
|
-
|
|
149
|
+
expect(groupAsWriter.get(writer.id)).toEqual("writer");
|
|
156
150
|
|
|
157
|
-
|
|
151
|
+
const otherAgent = groupAsWriter.core.node.createAccount();
|
|
158
152
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
153
|
+
expect(() => groupAsWriter.addMember(otherAgent, "admin")).toThrow(
|
|
154
|
+
"Failed to set role",
|
|
155
|
+
);
|
|
156
|
+
expect(() => groupAsWriter.addMember(otherAgent, "writer")).toThrow(
|
|
157
|
+
"Failed to set role",
|
|
158
|
+
);
|
|
159
|
+
expect(() => groupAsWriter.addMember(otherAgent, "reader")).toThrow(
|
|
160
|
+
"Failed to set role",
|
|
161
|
+
);
|
|
168
162
|
|
|
169
|
-
|
|
163
|
+
expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
|
|
170
164
|
});
|
|
171
165
|
|
|
172
166
|
test("Admins can add readers to a group, who can't add admins, writers, or readers", () => {
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
const { groupCore, node } = newGroup();
|
|
168
|
+
const reader = node.createAccount();
|
|
175
169
|
|
|
176
|
-
|
|
170
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
177
171
|
|
|
178
|
-
|
|
179
|
-
|
|
172
|
+
groupContent.set(reader.id, "reader", "trusting");
|
|
173
|
+
expect(groupContent.get(reader.id)).toEqual("reader");
|
|
180
174
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
)
|
|
187
|
-
.getCurrentContent(),
|
|
188
|
-
);
|
|
175
|
+
const groupAsReader = expectGroup(
|
|
176
|
+
groupCore
|
|
177
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
178
|
+
.getCurrentContent(),
|
|
179
|
+
);
|
|
189
180
|
|
|
190
|
-
|
|
181
|
+
expect(groupAsReader.get(reader.id)).toEqual("reader");
|
|
191
182
|
|
|
192
|
-
|
|
183
|
+
const otherAgent = node.createAccount();
|
|
193
184
|
|
|
194
|
-
|
|
195
|
-
|
|
185
|
+
groupAsReader.set(otherAgent.id, "admin", "trusting");
|
|
186
|
+
expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
|
|
196
187
|
|
|
197
|
-
|
|
198
|
-
|
|
188
|
+
groupAsReader.set(otherAgent.id, "writer", "trusting");
|
|
189
|
+
expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
|
|
199
190
|
|
|
200
|
-
|
|
191
|
+
groupAsReader.set(otherAgent.id, "reader", "trusting");
|
|
201
192
|
|
|
202
|
-
|
|
193
|
+
expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
|
|
203
194
|
});
|
|
204
195
|
|
|
205
196
|
test("Admins can add readers to a group, who can't add admins, writers, or readers (high level)", () => {
|
|
206
|
-
|
|
197
|
+
const { group, node } = newGroupHighLevel();
|
|
207
198
|
|
|
208
|
-
|
|
199
|
+
const reader = node.createAccount();
|
|
209
200
|
|
|
210
|
-
|
|
211
|
-
|
|
201
|
+
group.addMember(reader, "reader");
|
|
202
|
+
expect(group.get(reader.id)).toEqual("reader");
|
|
212
203
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
)
|
|
219
|
-
.getCurrentContent(),
|
|
220
|
-
);
|
|
204
|
+
const groupAsReader = expectGroup(
|
|
205
|
+
group.core
|
|
206
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
207
|
+
.getCurrentContent(),
|
|
208
|
+
);
|
|
221
209
|
|
|
222
|
-
|
|
210
|
+
expect(groupAsReader.get(reader.id)).toEqual("reader");
|
|
223
211
|
|
|
224
|
-
|
|
212
|
+
const otherAgent = groupAsReader.core.node.createAccount();
|
|
225
213
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
214
|
+
expect(() => groupAsReader.addMember(otherAgent, "admin")).toThrow(
|
|
215
|
+
"Failed to set role",
|
|
216
|
+
);
|
|
217
|
+
expect(() => groupAsReader.addMember(otherAgent, "writer")).toThrow(
|
|
218
|
+
"Failed to set role",
|
|
219
|
+
);
|
|
220
|
+
expect(() => groupAsReader.addMember(otherAgent, "reader")).toThrow(
|
|
221
|
+
"Failed to set role",
|
|
222
|
+
);
|
|
235
223
|
|
|
236
|
-
|
|
224
|
+
expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
|
|
237
225
|
});
|
|
238
226
|
|
|
239
227
|
test("Admins can write to an object that is owned by their group", () => {
|
|
240
|
-
|
|
228
|
+
const { node, groupCore } = newGroup();
|
|
241
229
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
230
|
+
const childObject = node.createCoValue({
|
|
231
|
+
type: "comap",
|
|
232
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
233
|
+
meta: null,
|
|
234
|
+
...Crypto.createdNowUnique(),
|
|
235
|
+
});
|
|
248
236
|
|
|
249
|
-
|
|
237
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
250
238
|
|
|
251
|
-
|
|
252
|
-
|
|
239
|
+
childContent.set("foo", "bar", "trusting");
|
|
240
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
253
241
|
});
|
|
254
242
|
|
|
255
243
|
test("Admins can write to an object that is owned by their group (high level)", () => {
|
|
256
|
-
|
|
244
|
+
const { group } = newGroupHighLevel();
|
|
257
245
|
|
|
258
|
-
|
|
246
|
+
const childObject = group.createMap();
|
|
259
247
|
|
|
260
|
-
|
|
261
|
-
|
|
248
|
+
childObject.set("foo", "bar", "trusting");
|
|
249
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
262
250
|
});
|
|
263
251
|
|
|
264
252
|
test("Writers can write to an object that is owned by their group", () => {
|
|
265
|
-
|
|
253
|
+
const { node, groupCore } = newGroup();
|
|
266
254
|
|
|
267
|
-
|
|
255
|
+
const writer = node.createAccount();
|
|
268
256
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
257
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
258
|
+
group.set(writer.id, "writer", "trusting");
|
|
259
|
+
expect(group.get(writer.id)).toEqual("writer");
|
|
272
260
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
261
|
+
const childObject = node.createCoValue({
|
|
262
|
+
type: "comap",
|
|
263
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
264
|
+
meta: null,
|
|
265
|
+
...Crypto.createdNowUnique(),
|
|
266
|
+
});
|
|
279
267
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
268
|
+
const childObjectAsWriter = childObject.testWithDifferentAccount(
|
|
269
|
+
writer,
|
|
270
|
+
Crypto.newRandomSessionID(writer.id),
|
|
271
|
+
);
|
|
284
272
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
273
|
+
const childContentAsWriter = expectMap(
|
|
274
|
+
childObjectAsWriter.getCurrentContent(),
|
|
275
|
+
);
|
|
288
276
|
|
|
289
|
-
|
|
290
|
-
|
|
277
|
+
childContentAsWriter.set("foo", "bar", "trusting");
|
|
278
|
+
expect(childContentAsWriter.get("foo")).toEqual("bar");
|
|
291
279
|
});
|
|
292
280
|
|
|
293
281
|
test("Writers can write to an object that is owned by their group (high level)", () => {
|
|
294
|
-
|
|
282
|
+
const { node, group } = newGroupHighLevel();
|
|
295
283
|
|
|
296
|
-
|
|
284
|
+
const writer = node.createAccount();
|
|
297
285
|
|
|
298
|
-
|
|
286
|
+
group.addMember(writer, "writer");
|
|
299
287
|
|
|
300
|
-
|
|
288
|
+
const childObject = group.createMap();
|
|
301
289
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
)
|
|
308
|
-
.getCurrentContent(),
|
|
309
|
-
);
|
|
290
|
+
const childObjectAsWriter = expectMap(
|
|
291
|
+
childObject.core
|
|
292
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
293
|
+
.getCurrentContent(),
|
|
294
|
+
);
|
|
310
295
|
|
|
311
|
-
|
|
312
|
-
|
|
296
|
+
childObjectAsWriter.set("foo", "bar", "trusting");
|
|
297
|
+
expect(childObjectAsWriter.get("foo")).toEqual("bar");
|
|
313
298
|
});
|
|
314
299
|
|
|
315
300
|
test("Readers can not write to an object that is owned by their group", () => {
|
|
316
|
-
|
|
301
|
+
const { node, groupCore } = newGroup();
|
|
317
302
|
|
|
318
|
-
|
|
303
|
+
const reader = node.createAccount();
|
|
319
304
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
305
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
306
|
+
group.set(reader.id, "reader", "trusting");
|
|
307
|
+
expect(group.get(reader.id)).toEqual("reader");
|
|
323
308
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
309
|
+
const childObject = node.createCoValue({
|
|
310
|
+
type: "comap",
|
|
311
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
312
|
+
meta: null,
|
|
313
|
+
...Crypto.createdNowUnique(),
|
|
314
|
+
});
|
|
330
315
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
316
|
+
const childObjectAsReader = childObject.testWithDifferentAccount(
|
|
317
|
+
reader,
|
|
318
|
+
Crypto.newRandomSessionID(reader.id),
|
|
319
|
+
);
|
|
335
320
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
321
|
+
const childContentAsReader = expectMap(
|
|
322
|
+
childObjectAsReader.getCurrentContent(),
|
|
323
|
+
);
|
|
339
324
|
|
|
340
|
-
|
|
341
|
-
|
|
325
|
+
childContentAsReader.set("foo", "bar", "trusting");
|
|
326
|
+
expect(childContentAsReader.get("foo")).toBeUndefined();
|
|
342
327
|
});
|
|
343
328
|
|
|
344
329
|
test("Readers can not write to an object that is owned by their group (high level)", () => {
|
|
345
|
-
|
|
330
|
+
const { node, group } = newGroupHighLevel();
|
|
346
331
|
|
|
347
|
-
|
|
332
|
+
const reader = node.createAccount();
|
|
348
333
|
|
|
349
|
-
|
|
334
|
+
group.addMember(reader, "reader");
|
|
350
335
|
|
|
351
|
-
|
|
336
|
+
const childObject = group.createMap();
|
|
352
337
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
)
|
|
359
|
-
.getCurrentContent(),
|
|
360
|
-
);
|
|
338
|
+
const childObjectAsReader = expectMap(
|
|
339
|
+
childObject.core
|
|
340
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
341
|
+
.getCurrentContent(),
|
|
342
|
+
);
|
|
361
343
|
|
|
362
|
-
|
|
363
|
-
|
|
344
|
+
childObjectAsReader.set("foo", "bar", "trusting");
|
|
345
|
+
expect(childObjectAsReader.get("foo")).toBeUndefined();
|
|
364
346
|
});
|
|
365
347
|
|
|
366
348
|
test("Admins can set group read key and then use it to create and read private transactions in owned objects", () => {
|
|
367
|
-
|
|
349
|
+
const { node, groupCore, admin } = newGroup();
|
|
368
350
|
|
|
369
|
-
|
|
351
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
370
352
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
353
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
354
|
+
const revelation = Crypto.seal({
|
|
355
|
+
message: readKey,
|
|
356
|
+
from: admin.currentSealerSecret(),
|
|
357
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
358
|
+
nOnceMaterial: {
|
|
359
|
+
in: groupCore.id,
|
|
360
|
+
tx: groupCore.nextTransactionID(),
|
|
361
|
+
},
|
|
362
|
+
});
|
|
381
363
|
|
|
382
|
-
|
|
364
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
383
365
|
|
|
384
|
-
|
|
385
|
-
revelation,
|
|
386
|
-
);
|
|
366
|
+
expect(groupContent.get(`${readKeyID}_for_${admin.id}`)).toEqual(revelation);
|
|
387
367
|
|
|
388
|
-
|
|
368
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
389
369
|
|
|
390
|
-
|
|
370
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID);
|
|
391
371
|
|
|
392
|
-
|
|
372
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
|
|
393
373
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
374
|
+
const childObject = node.createCoValue({
|
|
375
|
+
type: "comap",
|
|
376
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
377
|
+
meta: null,
|
|
378
|
+
...Crypto.createdNowUnique(),
|
|
379
|
+
});
|
|
400
380
|
|
|
401
|
-
|
|
381
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
402
382
|
|
|
403
|
-
|
|
404
|
-
|
|
383
|
+
childContent.set("foo", "bar", "private");
|
|
384
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
405
385
|
});
|
|
406
386
|
|
|
407
387
|
test("Admins can set group read key and then use it to create and read private transactions in owned objects (high level)", () => {
|
|
408
|
-
|
|
388
|
+
const { group } = newGroupHighLevel();
|
|
409
389
|
|
|
410
|
-
|
|
390
|
+
const childObject = group.createMap();
|
|
411
391
|
|
|
412
|
-
|
|
413
|
-
|
|
392
|
+
childObject.set("foo", "bar", "private");
|
|
393
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
414
394
|
});
|
|
415
395
|
|
|
416
396
|
test("Admins can set group read key and then writers can use it to create and read private transactions in owned objects", () => {
|
|
417
|
-
|
|
397
|
+
const { node, groupCore, admin } = newGroup();
|
|
418
398
|
|
|
419
|
-
|
|
399
|
+
const writer = node.createAccount();
|
|
420
400
|
|
|
421
|
-
|
|
401
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
422
402
|
|
|
423
|
-
|
|
403
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
424
404
|
|
|
425
|
-
|
|
426
|
-
|
|
405
|
+
groupContent.set(writer.id, "writer", "trusting");
|
|
406
|
+
expect(groupContent.get(writer.id)).toEqual("writer");
|
|
427
407
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
408
|
+
const revelation1 = Crypto.seal({
|
|
409
|
+
message: readKey,
|
|
410
|
+
from: admin.currentSealerSecret(),
|
|
411
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
412
|
+
nOnceMaterial: {
|
|
413
|
+
in: groupCore.id,
|
|
414
|
+
tx: groupCore.nextTransactionID(),
|
|
415
|
+
},
|
|
416
|
+
});
|
|
437
417
|
|
|
438
|
-
|
|
418
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
|
|
439
419
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
420
|
+
const revelation2 = Crypto.seal({
|
|
421
|
+
message: readKey,
|
|
422
|
+
from: admin.currentSealerSecret(),
|
|
423
|
+
to: writer.currentSealerID()._unsafeUnwrap(),
|
|
424
|
+
nOnceMaterial: {
|
|
425
|
+
in: groupCore.id,
|
|
426
|
+
tx: groupCore.nextTransactionID(),
|
|
427
|
+
},
|
|
428
|
+
});
|
|
449
429
|
|
|
450
|
-
|
|
430
|
+
groupContent.set(`${readKeyID}_for_${writer.id}`, revelation2, "trusting");
|
|
451
431
|
|
|
452
|
-
|
|
432
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
453
433
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
434
|
+
const childObject = node.createCoValue({
|
|
435
|
+
type: "comap",
|
|
436
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
437
|
+
meta: null,
|
|
438
|
+
...Crypto.createdNowUnique(),
|
|
439
|
+
});
|
|
460
440
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
441
|
+
const childObjectAsWriter = childObject.testWithDifferentAccount(
|
|
442
|
+
writer,
|
|
443
|
+
Crypto.newRandomSessionID(writer.id),
|
|
444
|
+
);
|
|
465
445
|
|
|
466
|
-
|
|
446
|
+
expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
|
|
467
447
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
448
|
+
const childContentAsWriter = expectMap(
|
|
449
|
+
childObjectAsWriter.getCurrentContent(),
|
|
450
|
+
);
|
|
471
451
|
|
|
472
|
-
|
|
473
|
-
|
|
452
|
+
childContentAsWriter.set("foo", "bar", "private");
|
|
453
|
+
expect(childContentAsWriter.get("foo")).toEqual("bar");
|
|
474
454
|
});
|
|
475
455
|
|
|
476
456
|
test("Admins can set group read key and then writers can use it to create and read private transactions in owned objects (high level)", () => {
|
|
477
|
-
|
|
457
|
+
const { node, group } = newGroupHighLevel();
|
|
478
458
|
|
|
479
|
-
|
|
459
|
+
const writer = node.createAccount();
|
|
480
460
|
|
|
481
|
-
|
|
461
|
+
group.addMember(writer, "writer");
|
|
482
462
|
|
|
483
|
-
|
|
463
|
+
const childObject = group.createMap();
|
|
484
464
|
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
)
|
|
491
|
-
.getCurrentContent(),
|
|
492
|
-
);
|
|
465
|
+
const childObjectAsWriter = expectMap(
|
|
466
|
+
childObject.core
|
|
467
|
+
.testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
|
|
468
|
+
.getCurrentContent(),
|
|
469
|
+
);
|
|
493
470
|
|
|
494
|
-
|
|
495
|
-
|
|
471
|
+
childObjectAsWriter.set("foo", "bar", "private");
|
|
472
|
+
expect(childObjectAsWriter.get("foo")).toEqual("bar");
|
|
496
473
|
});
|
|
497
474
|
|
|
498
475
|
test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read", () => {
|
|
499
|
-
|
|
476
|
+
const { node, groupCore, admin } = newGroup();
|
|
500
477
|
|
|
501
|
-
|
|
478
|
+
const reader = node.createAccount();
|
|
502
479
|
|
|
503
|
-
|
|
480
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
504
481
|
|
|
505
|
-
|
|
482
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
506
483
|
|
|
507
|
-
|
|
508
|
-
|
|
484
|
+
groupContent.set(reader.id, "reader", "trusting");
|
|
485
|
+
expect(groupContent.get(reader.id)).toEqual("reader");
|
|
509
486
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
487
|
+
const revelation1 = Crypto.seal({
|
|
488
|
+
message: readKey,
|
|
489
|
+
from: admin.currentSealerSecret(),
|
|
490
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
491
|
+
nOnceMaterial: {
|
|
492
|
+
in: groupCore.id,
|
|
493
|
+
tx: groupCore.nextTransactionID(),
|
|
494
|
+
},
|
|
495
|
+
});
|
|
519
496
|
|
|
520
|
-
|
|
497
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
|
|
521
498
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
499
|
+
const revelation2 = Crypto.seal({
|
|
500
|
+
message: readKey,
|
|
501
|
+
from: admin.currentSealerSecret(),
|
|
502
|
+
to: reader.currentSealerID()._unsafeUnwrap(),
|
|
503
|
+
nOnceMaterial: {
|
|
504
|
+
in: groupCore.id,
|
|
505
|
+
tx: groupCore.nextTransactionID(),
|
|
506
|
+
},
|
|
507
|
+
});
|
|
531
508
|
|
|
532
|
-
|
|
509
|
+
groupContent.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
|
|
533
510
|
|
|
534
|
-
|
|
511
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
535
512
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
513
|
+
const childObject = node.createCoValue({
|
|
514
|
+
type: "comap",
|
|
515
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
516
|
+
meta: null,
|
|
517
|
+
...Crypto.createdNowUnique(),
|
|
518
|
+
});
|
|
542
519
|
|
|
543
|
-
|
|
520
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
544
521
|
|
|
545
|
-
|
|
546
|
-
|
|
522
|
+
childContent.set("foo", "bar", "private");
|
|
523
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
547
524
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
525
|
+
const childObjectAsReader = childObject.testWithDifferentAccount(
|
|
526
|
+
reader,
|
|
527
|
+
Crypto.newRandomSessionID(reader.id),
|
|
528
|
+
);
|
|
552
529
|
|
|
553
|
-
|
|
530
|
+
expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
|
|
554
531
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
532
|
+
const childContentAsReader = expectMap(
|
|
533
|
+
childObjectAsReader.getCurrentContent(),
|
|
534
|
+
);
|
|
558
535
|
|
|
559
|
-
|
|
536
|
+
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
560
537
|
});
|
|
561
538
|
|
|
562
539
|
test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read (high level)", () => {
|
|
563
|
-
|
|
540
|
+
const { node, group } = newGroupHighLevel();
|
|
564
541
|
|
|
565
|
-
|
|
542
|
+
const reader = node.createAccount();
|
|
566
543
|
|
|
567
|
-
|
|
544
|
+
group.addMember(reader, "reader");
|
|
568
545
|
|
|
569
|
-
|
|
546
|
+
const childObject = group.createMap();
|
|
570
547
|
|
|
571
|
-
|
|
572
|
-
|
|
548
|
+
childObject.set("foo", "bar", "private");
|
|
549
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
573
550
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
)
|
|
580
|
-
.getCurrentContent(),
|
|
581
|
-
);
|
|
551
|
+
const childContentAsReader = expectMap(
|
|
552
|
+
childObject.core
|
|
553
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
554
|
+
.getCurrentContent(),
|
|
555
|
+
);
|
|
582
556
|
|
|
583
|
-
|
|
557
|
+
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
584
558
|
});
|
|
585
559
|
|
|
586
560
|
test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read, even with a separate later revelation for the same read key", () => {
|
|
587
|
-
|
|
561
|
+
const { node, groupCore, admin } = newGroup();
|
|
588
562
|
|
|
589
|
-
|
|
563
|
+
const reader1 = node.createAccount();
|
|
590
564
|
|
|
591
|
-
|
|
565
|
+
const reader2 = node.createAccount();
|
|
592
566
|
|
|
593
|
-
|
|
567
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
594
568
|
|
|
595
|
-
|
|
569
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
596
570
|
|
|
597
|
-
|
|
598
|
-
|
|
571
|
+
groupContent.set(reader1.id, "reader", "trusting");
|
|
572
|
+
expect(groupContent.get(reader1.id)).toEqual("reader");
|
|
599
573
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
574
|
+
const revelation1 = Crypto.seal({
|
|
575
|
+
message: readKey,
|
|
576
|
+
from: admin.currentSealerSecret(),
|
|
577
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
578
|
+
nOnceMaterial: {
|
|
579
|
+
in: groupCore.id,
|
|
580
|
+
tx: groupCore.nextTransactionID(),
|
|
581
|
+
},
|
|
582
|
+
});
|
|
609
583
|
|
|
610
|
-
|
|
584
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
|
|
611
585
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
586
|
+
const revelation2 = Crypto.seal({
|
|
587
|
+
message: readKey,
|
|
588
|
+
from: admin.currentSealerSecret(),
|
|
589
|
+
to: reader1.currentSealerID()._unsafeUnwrap(),
|
|
590
|
+
nOnceMaterial: {
|
|
591
|
+
in: groupCore.id,
|
|
592
|
+
tx: groupCore.nextTransactionID(),
|
|
593
|
+
},
|
|
594
|
+
});
|
|
621
595
|
|
|
622
|
-
|
|
596
|
+
groupContent.set(`${readKeyID}_for_${reader1.id}`, revelation2, "trusting");
|
|
623
597
|
|
|
624
|
-
|
|
598
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
625
599
|
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
600
|
+
const childObject = node.createCoValue({
|
|
601
|
+
type: "comap",
|
|
602
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
603
|
+
meta: null,
|
|
604
|
+
...Crypto.createdNowUnique(),
|
|
605
|
+
});
|
|
632
606
|
|
|
633
|
-
|
|
607
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
634
608
|
|
|
635
|
-
|
|
636
|
-
|
|
609
|
+
childContent.set("foo", "bar", "private");
|
|
610
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
637
611
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
612
|
+
const childObjectAsReader1 = childObject.testWithDifferentAccount(
|
|
613
|
+
reader1,
|
|
614
|
+
Crypto.newRandomSessionID(reader1.id),
|
|
615
|
+
);
|
|
642
616
|
|
|
643
|
-
|
|
617
|
+
expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
|
|
644
618
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
619
|
+
const childContentAsReader1 = expectMap(
|
|
620
|
+
childObjectAsReader1.getCurrentContent(),
|
|
621
|
+
);
|
|
648
622
|
|
|
649
|
-
|
|
623
|
+
expect(childContentAsReader1.get("foo")).toEqual("bar");
|
|
650
624
|
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
625
|
+
const revelation3 = Crypto.seal({
|
|
626
|
+
message: readKey,
|
|
627
|
+
from: admin.currentSealerSecret(),
|
|
628
|
+
to: reader2.currentSealerID()._unsafeUnwrap(),
|
|
629
|
+
nOnceMaterial: {
|
|
630
|
+
in: groupCore.id,
|
|
631
|
+
tx: groupCore.nextTransactionID(),
|
|
632
|
+
},
|
|
633
|
+
});
|
|
660
634
|
|
|
661
|
-
|
|
635
|
+
groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
|
|
662
636
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
637
|
+
const childObjectAsReader2 = childObject.testWithDifferentAccount(
|
|
638
|
+
reader2,
|
|
639
|
+
Crypto.newRandomSessionID(reader2.id),
|
|
640
|
+
);
|
|
667
641
|
|
|
668
|
-
|
|
642
|
+
expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
|
|
669
643
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
644
|
+
const childContentAsReader2 = expectMap(
|
|
645
|
+
childObjectAsReader2.getCurrentContent(),
|
|
646
|
+
);
|
|
673
647
|
|
|
674
|
-
|
|
648
|
+
expect(childContentAsReader2.get("foo")).toEqual("bar");
|
|
675
649
|
});
|
|
676
650
|
|
|
677
651
|
test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read, even with a separate later revelation for the same read key (high level)", () => {
|
|
678
|
-
|
|
652
|
+
const { node, group } = newGroupHighLevel();
|
|
679
653
|
|
|
680
|
-
|
|
654
|
+
const reader1 = node.createAccount();
|
|
681
655
|
|
|
682
|
-
|
|
656
|
+
const reader2 = node.createAccount();
|
|
683
657
|
|
|
684
|
-
|
|
658
|
+
group.addMember(reader1, "reader");
|
|
685
659
|
|
|
686
|
-
|
|
660
|
+
const childObject = group.createMap();
|
|
687
661
|
|
|
688
|
-
|
|
689
|
-
|
|
662
|
+
childObject.set("foo", "bar", "private");
|
|
663
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
690
664
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
)
|
|
697
|
-
.getCurrentContent(),
|
|
698
|
-
);
|
|
665
|
+
const childContentAsReader1 = expectMap(
|
|
666
|
+
childObject.core
|
|
667
|
+
.testWithDifferentAccount(reader1, Crypto.newRandomSessionID(reader1.id))
|
|
668
|
+
.getCurrentContent(),
|
|
669
|
+
);
|
|
699
670
|
|
|
700
|
-
|
|
671
|
+
expect(childContentAsReader1.get("foo")).toEqual("bar");
|
|
701
672
|
|
|
702
|
-
|
|
673
|
+
group.addMember(reader2, "reader");
|
|
703
674
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
)
|
|
710
|
-
.getCurrentContent(),
|
|
711
|
-
);
|
|
675
|
+
const childContentAsReader2 = expectMap(
|
|
676
|
+
childObject.core
|
|
677
|
+
.testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
|
|
678
|
+
.getCurrentContent(),
|
|
679
|
+
);
|
|
712
680
|
|
|
713
|
-
|
|
681
|
+
expect(childContentAsReader2.get("foo")).toEqual("bar");
|
|
714
682
|
});
|
|
715
683
|
|
|
716
684
|
test("Admins can set group read key, make a private transaction in an owned object, rotate the read key, make another private transaction, and both can be read by the admin", () => {
|
|
717
|
-
|
|
685
|
+
const { node, groupCore, admin } = newGroup();
|
|
718
686
|
|
|
719
|
-
|
|
687
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
720
688
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
689
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
690
|
+
const revelation1 = Crypto.seal({
|
|
691
|
+
message: readKey,
|
|
692
|
+
from: admin.currentSealerSecret(),
|
|
693
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
694
|
+
nOnceMaterial: {
|
|
695
|
+
in: groupCore.id,
|
|
696
|
+
tx: groupCore.nextTransactionID(),
|
|
697
|
+
},
|
|
698
|
+
});
|
|
731
699
|
|
|
732
|
-
|
|
700
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
|
|
733
701
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
702
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
703
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID);
|
|
704
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
|
|
737
705
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
706
|
+
const childObject = node.createCoValue({
|
|
707
|
+
type: "comap",
|
|
708
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
709
|
+
meta: null,
|
|
710
|
+
...Crypto.createdNowUnique(),
|
|
711
|
+
});
|
|
744
712
|
|
|
745
|
-
|
|
713
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
746
714
|
|
|
747
|
-
|
|
748
|
-
|
|
715
|
+
childContent.set("foo", "bar", "private");
|
|
716
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
749
717
|
|
|
750
|
-
|
|
718
|
+
const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
|
|
751
719
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
720
|
+
const revelation2 = Crypto.seal({
|
|
721
|
+
message: readKey2,
|
|
722
|
+
from: admin.currentSealerSecret(),
|
|
723
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
724
|
+
nOnceMaterial: {
|
|
725
|
+
in: groupCore.id,
|
|
726
|
+
tx: groupCore.nextTransactionID(),
|
|
727
|
+
},
|
|
728
|
+
});
|
|
761
729
|
|
|
762
|
-
|
|
730
|
+
groupContent.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
|
|
763
731
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
732
|
+
groupContent.set("readKey", readKeyID2, "trusting");
|
|
733
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID2);
|
|
734
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
|
|
767
735
|
|
|
768
|
-
|
|
736
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
769
737
|
|
|
770
|
-
|
|
771
|
-
|
|
738
|
+
childContent.set("foo2", "bar2", "private");
|
|
739
|
+
expect(childContent.get("foo2")).toEqual("bar2");
|
|
772
740
|
});
|
|
773
741
|
|
|
774
742
|
test("Admins can set group read key, make a private transaction in an owned object, rotate the read key, make another private transaction, and both can be read by the admin (high level)", () => {
|
|
775
|
-
|
|
743
|
+
const { group } = newGroupHighLevel();
|
|
776
744
|
|
|
777
|
-
|
|
745
|
+
const childObject = group.createMap();
|
|
778
746
|
|
|
779
|
-
|
|
747
|
+
const firstReadKey = childObject.core.getCurrentReadKey();
|
|
780
748
|
|
|
781
|
-
|
|
782
|
-
|
|
749
|
+
childObject.set("foo", "bar", "private");
|
|
750
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
783
751
|
|
|
784
|
-
|
|
752
|
+
group.rotateReadKey();
|
|
785
753
|
|
|
786
|
-
|
|
754
|
+
expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
|
|
787
755
|
|
|
788
|
-
|
|
789
|
-
|
|
756
|
+
childObject.set("foo2", "bar2", "private");
|
|
757
|
+
expect(childObject.get("foo2")).toEqual("bar2");
|
|
790
758
|
});
|
|
791
759
|
|
|
792
760
|
test("Admins can set group read key, make a private transaction in an owned object, rotate the read key, add a reader, make another private transaction in the owned object, and both can be read by the reader", () => {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
761
|
+
const { node, groupCore, admin } = newGroup();
|
|
762
|
+
|
|
763
|
+
const childObject = node.createCoValue({
|
|
764
|
+
type: "comap",
|
|
765
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
766
|
+
meta: null,
|
|
767
|
+
...Crypto.createdNowUnique(),
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
771
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
772
|
+
|
|
773
|
+
const revelation = Crypto.seal({
|
|
774
|
+
message: readKey,
|
|
775
|
+
from: admin.currentSealerSecret(),
|
|
776
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
777
|
+
nOnceMaterial: {
|
|
778
|
+
in: groupCore.id,
|
|
779
|
+
tx: groupCore.nextTransactionID(),
|
|
780
|
+
},
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
784
|
+
|
|
785
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
786
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID);
|
|
787
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
|
|
788
|
+
|
|
789
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
790
|
+
|
|
791
|
+
childContent.set("foo", "bar", "private");
|
|
792
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
793
|
+
|
|
794
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
795
|
+
|
|
796
|
+
const reader = node.createAccount();
|
|
797
|
+
|
|
798
|
+
const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
|
|
799
|
+
|
|
800
|
+
const revelation2 = Crypto.seal({
|
|
801
|
+
message: readKey2,
|
|
802
|
+
from: admin.currentSealerSecret(),
|
|
803
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
804
|
+
nOnceMaterial: {
|
|
805
|
+
in: groupCore.id,
|
|
806
|
+
tx: groupCore.nextTransactionID(),
|
|
807
|
+
},
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
groupContent.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
|
|
811
|
+
|
|
812
|
+
const revelation3 = Crypto.seal({
|
|
813
|
+
message: readKey2,
|
|
814
|
+
from: admin.currentSealerSecret(),
|
|
815
|
+
to: reader.currentSealerID()._unsafeUnwrap(),
|
|
816
|
+
nOnceMaterial: {
|
|
817
|
+
in: groupCore.id,
|
|
818
|
+
tx: groupCore.nextTransactionID(),
|
|
819
|
+
},
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
groupContent.set(`${readKeyID2}_for_${reader.id}`, revelation3, "trusting");
|
|
823
|
+
|
|
824
|
+
groupContent.set(
|
|
825
|
+
`${readKeyID}_for_${readKeyID2}`,
|
|
826
|
+
Crypto.encryptKeySecret({
|
|
827
|
+
toEncrypt: { id: readKeyID, secret: readKey },
|
|
828
|
+
encrypting: { id: readKeyID2, secret: readKey2 },
|
|
829
|
+
}).encrypted,
|
|
830
|
+
"trusting",
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
groupContent.set("readKey", readKeyID2, "trusting");
|
|
834
|
+
|
|
835
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID2);
|
|
836
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
|
|
837
|
+
|
|
838
|
+
groupContent.set(reader.id, "reader", "trusting");
|
|
839
|
+
expect(groupContent.get(reader.id)).toEqual("reader");
|
|
840
|
+
|
|
841
|
+
childContent.set("foo2", "bar2", "private");
|
|
842
|
+
expect(childContent.get("foo2")).toEqual("bar2");
|
|
843
|
+
|
|
844
|
+
const childObjectAsReader = childObject.testWithDifferentAccount(
|
|
845
|
+
reader,
|
|
846
|
+
Crypto.newRandomSessionID(reader.id),
|
|
847
|
+
);
|
|
848
|
+
|
|
849
|
+
expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
|
|
850
|
+
|
|
851
|
+
const childContentAsReader = expectMap(
|
|
852
|
+
childObjectAsReader.getCurrentContent(),
|
|
853
|
+
);
|
|
854
|
+
|
|
855
|
+
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
856
|
+
expect(childContentAsReader.get("foo2")).toEqual("bar2");
|
|
889
857
|
});
|
|
890
858
|
|
|
891
859
|
test("Admins can set group read key, make a private transaction in an owned object, rotate the read key, add a reader, make another private transaction in the owned object, and both can be read by the reader (high level)", () => {
|
|
892
|
-
|
|
860
|
+
const { node, group } = newGroupHighLevel();
|
|
893
861
|
|
|
894
|
-
|
|
862
|
+
const childObject = group.createMap();
|
|
895
863
|
|
|
896
|
-
|
|
864
|
+
const firstReadKey = childObject.core.getCurrentReadKey();
|
|
897
865
|
|
|
898
|
-
|
|
899
|
-
|
|
866
|
+
childObject.set("foo", "bar", "private");
|
|
867
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
900
868
|
|
|
901
|
-
|
|
869
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
902
870
|
|
|
903
|
-
|
|
871
|
+
group.rotateReadKey();
|
|
904
872
|
|
|
905
|
-
|
|
873
|
+
expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
|
|
906
874
|
|
|
907
|
-
|
|
875
|
+
const reader = node.createAccount();
|
|
908
876
|
|
|
909
|
-
|
|
877
|
+
group.addMember(reader, "reader");
|
|
910
878
|
|
|
911
|
-
|
|
912
|
-
|
|
879
|
+
childObject.set("foo2", "bar2", "private");
|
|
880
|
+
expect(childObject.get("foo2")).toEqual("bar2");
|
|
913
881
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
)
|
|
920
|
-
.getCurrentContent(),
|
|
921
|
-
);
|
|
882
|
+
const childContentAsReader = expectMap(
|
|
883
|
+
childObject.core
|
|
884
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
885
|
+
.getCurrentContent(),
|
|
886
|
+
);
|
|
922
887
|
|
|
923
|
-
|
|
924
|
-
|
|
888
|
+
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
889
|
+
expect(childContentAsReader.get("foo2")).toEqual("bar2");
|
|
925
890
|
});
|
|
926
891
|
|
|
927
892
|
test("Admins can set group read rey, make a private transaction in an owned object, rotate the read key, add two readers, rotate the read key again to kick out one reader, make another private transaction in the owned object, and only the remaining reader can read both transactions", () => {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
)
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
).toBeUndefined();
|
|
1070
|
-
expect(
|
|
1071
|
-
expectMap(childObjectAsReader2.getCurrentContent()).get("foo2"),
|
|
1072
|
-
).toEqual("bar2");
|
|
893
|
+
const { node, groupCore, admin } = newGroup();
|
|
894
|
+
|
|
895
|
+
const childObject = node.createCoValue({
|
|
896
|
+
type: "comap",
|
|
897
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
898
|
+
meta: null,
|
|
899
|
+
...Crypto.createdNowUnique(),
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
const groupContent = expectGroup(groupCore.getCurrentContent());
|
|
903
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
904
|
+
const reader = node.createAccount();
|
|
905
|
+
|
|
906
|
+
const reader2 = node.createAccount();
|
|
907
|
+
|
|
908
|
+
const revelation1 = Crypto.seal({
|
|
909
|
+
message: readKey,
|
|
910
|
+
from: admin.currentSealerSecret(),
|
|
911
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
912
|
+
nOnceMaterial: {
|
|
913
|
+
in: groupCore.id,
|
|
914
|
+
tx: groupCore.nextTransactionID(),
|
|
915
|
+
},
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
|
|
919
|
+
|
|
920
|
+
const revelation2 = Crypto.seal({
|
|
921
|
+
message: readKey,
|
|
922
|
+
from: admin.currentSealerSecret(),
|
|
923
|
+
to: reader.currentSealerID()._unsafeUnwrap(),
|
|
924
|
+
nOnceMaterial: {
|
|
925
|
+
in: groupCore.id,
|
|
926
|
+
tx: groupCore.nextTransactionID(),
|
|
927
|
+
},
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
groupContent.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
|
|
931
|
+
|
|
932
|
+
const revelation3 = Crypto.seal({
|
|
933
|
+
message: readKey,
|
|
934
|
+
from: admin.currentSealerSecret(),
|
|
935
|
+
to: reader2.currentSealerID()._unsafeUnwrap(),
|
|
936
|
+
nOnceMaterial: {
|
|
937
|
+
in: groupCore.id,
|
|
938
|
+
tx: groupCore.nextTransactionID(),
|
|
939
|
+
},
|
|
940
|
+
});
|
|
941
|
+
|
|
942
|
+
groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
|
|
943
|
+
|
|
944
|
+
groupContent.set("readKey", readKeyID, "trusting");
|
|
945
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID);
|
|
946
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
|
|
947
|
+
|
|
948
|
+
groupContent.set(reader.id, "reader", "trusting");
|
|
949
|
+
expect(groupContent.get(reader.id)).toEqual("reader");
|
|
950
|
+
groupContent.set(reader2.id, "reader", "trusting");
|
|
951
|
+
expect(groupContent.get(reader2.id)).toEqual("reader");
|
|
952
|
+
|
|
953
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
954
|
+
|
|
955
|
+
childContent.set("foo", "bar", "private");
|
|
956
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
957
|
+
|
|
958
|
+
let childObjectAsReader = childObject.testWithDifferentAccount(
|
|
959
|
+
reader,
|
|
960
|
+
Crypto.newRandomSessionID(reader.id),
|
|
961
|
+
);
|
|
962
|
+
|
|
963
|
+
expect(expectMap(childObjectAsReader.getCurrentContent()).get("foo")).toEqual(
|
|
964
|
+
"bar",
|
|
965
|
+
);
|
|
966
|
+
|
|
967
|
+
let childObjectAsReader2 = childObject.testWithDifferentAccount(
|
|
968
|
+
reader,
|
|
969
|
+
Crypto.newRandomSessionID(reader.id),
|
|
970
|
+
);
|
|
971
|
+
|
|
972
|
+
expect(
|
|
973
|
+
expectMap(childObjectAsReader2.getCurrentContent()).get("foo"),
|
|
974
|
+
).toEqual("bar");
|
|
975
|
+
|
|
976
|
+
const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
|
|
977
|
+
|
|
978
|
+
const newRevelation1 = Crypto.seal({
|
|
979
|
+
message: readKey2,
|
|
980
|
+
from: admin.currentSealerSecret(),
|
|
981
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
982
|
+
nOnceMaterial: {
|
|
983
|
+
in: groupCore.id,
|
|
984
|
+
tx: groupCore.nextTransactionID(),
|
|
985
|
+
},
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
groupContent.set(`${readKeyID2}_for_${admin.id}`, newRevelation1, "trusting");
|
|
989
|
+
|
|
990
|
+
const newRevelation2 = Crypto.seal({
|
|
991
|
+
message: readKey2,
|
|
992
|
+
from: admin.currentSealerSecret(),
|
|
993
|
+
to: reader2.currentSealerID()._unsafeUnwrap(),
|
|
994
|
+
nOnceMaterial: {
|
|
995
|
+
in: groupCore.id,
|
|
996
|
+
tx: groupCore.nextTransactionID(),
|
|
997
|
+
},
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
groupContent.set(
|
|
1001
|
+
`${readKeyID2}_for_${reader2.id}`,
|
|
1002
|
+
newRevelation2,
|
|
1003
|
+
"trusting",
|
|
1004
|
+
);
|
|
1005
|
+
|
|
1006
|
+
groupContent.set("readKey", readKeyID2, "trusting");
|
|
1007
|
+
expect(groupContent.get("readKey")).toEqual(readKeyID2);
|
|
1008
|
+
expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
|
|
1009
|
+
|
|
1010
|
+
groupContent.set(reader.id, "revoked", "trusting");
|
|
1011
|
+
// expect(editable.get(reader.id)).toEqual("revoked");
|
|
1012
|
+
|
|
1013
|
+
expect(childObject.getCurrentReadKey().secret).toEqual(readKey2);
|
|
1014
|
+
|
|
1015
|
+
childContent.set("foo2", "bar2", "private");
|
|
1016
|
+
expect(childContent.get("foo2")).toEqual("bar2");
|
|
1017
|
+
|
|
1018
|
+
// TODO: make sure these instances of coValues sync between each other so this isn't necessary?
|
|
1019
|
+
childObjectAsReader = childObject.testWithDifferentAccount(
|
|
1020
|
+
reader,
|
|
1021
|
+
Crypto.newRandomSessionID(reader.id),
|
|
1022
|
+
);
|
|
1023
|
+
childObjectAsReader2 = childObject.testWithDifferentAccount(
|
|
1024
|
+
reader2,
|
|
1025
|
+
Crypto.newRandomSessionID(reader2.id),
|
|
1026
|
+
);
|
|
1027
|
+
|
|
1028
|
+
expect(
|
|
1029
|
+
expectMap(childObjectAsReader.getCurrentContent()).get("foo2"),
|
|
1030
|
+
).toBeUndefined();
|
|
1031
|
+
expect(
|
|
1032
|
+
expectMap(childObjectAsReader2.getCurrentContent()).get("foo2"),
|
|
1033
|
+
).toEqual("bar2");
|
|
1073
1034
|
});
|
|
1074
1035
|
|
|
1075
1036
|
test("Admins can set group read rey, make a private transaction in an owned object, rotate the read key, add two readers, rotate the read key again to kick out one reader, make another private transaction in the owned object, and only the remaining reader can read both transactions (high level)", () => {
|
|
1076
|
-
|
|
1037
|
+
const { node, group } = newGroupHighLevel();
|
|
1077
1038
|
|
|
1078
|
-
|
|
1039
|
+
const childObject = group.createMap();
|
|
1079
1040
|
|
|
1080
|
-
|
|
1081
|
-
|
|
1041
|
+
childObject.set("foo", "bar", "private");
|
|
1042
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
1082
1043
|
|
|
1083
|
-
|
|
1044
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
1084
1045
|
|
|
1085
|
-
|
|
1046
|
+
group.rotateReadKey();
|
|
1086
1047
|
|
|
1087
|
-
|
|
1048
|
+
const secondReadKey = childObject.core.getCurrentReadKey();
|
|
1088
1049
|
|
|
1089
|
-
|
|
1050
|
+
const reader = node.createAccount();
|
|
1090
1051
|
|
|
1091
|
-
|
|
1052
|
+
const reader2 = node.createAccount();
|
|
1092
1053
|
|
|
1093
|
-
|
|
1094
|
-
|
|
1054
|
+
group.addMember(reader, "reader");
|
|
1055
|
+
group.addMember(reader2, "reader");
|
|
1095
1056
|
|
|
1096
|
-
|
|
1097
|
-
|
|
1057
|
+
childObject.set("foo2", "bar2", "private");
|
|
1058
|
+
expect(childObject.get("foo2")).toEqual("bar2");
|
|
1098
1059
|
|
|
1099
|
-
|
|
1060
|
+
group.removeMember(reader);
|
|
1100
1061
|
|
|
1101
|
-
|
|
1062
|
+
expect(childObject.core.getCurrentReadKey()).not.toEqual(secondReadKey);
|
|
1102
1063
|
|
|
1103
|
-
|
|
1104
|
-
|
|
1064
|
+
childObject.set("foo3", "bar3", "private");
|
|
1065
|
+
expect(childObject.get("foo3")).toEqual("bar3");
|
|
1105
1066
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
)
|
|
1112
|
-
.getCurrentContent(),
|
|
1113
|
-
);
|
|
1067
|
+
const childContentAsReader2 = expectMap(
|
|
1068
|
+
childObject.core
|
|
1069
|
+
.testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
|
|
1070
|
+
.getCurrentContent(),
|
|
1071
|
+
);
|
|
1114
1072
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1073
|
+
expect(childContentAsReader2.get("foo")).toEqual("bar");
|
|
1074
|
+
expect(childContentAsReader2.get("foo2")).toEqual("bar2");
|
|
1075
|
+
expect(childContentAsReader2.get("foo3")).toEqual("bar3");
|
|
1118
1076
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
.getCurrentContent(),
|
|
1127
|
-
).get("foo3"),
|
|
1128
|
-
).toBeUndefined();
|
|
1077
|
+
expect(
|
|
1078
|
+
expectMap(
|
|
1079
|
+
childObject.core
|
|
1080
|
+
.testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
|
|
1081
|
+
.getCurrentContent(),
|
|
1082
|
+
).get("foo3"),
|
|
1083
|
+
).toBeUndefined();
|
|
1129
1084
|
});
|
|
1130
1085
|
|
|
1131
1086
|
test("Can create two owned objects in the same group and they will have different ids", () => {
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1087
|
+
const { node, groupCore } = newGroup();
|
|
1088
|
+
|
|
1089
|
+
const childObject1 = node.createCoValue({
|
|
1090
|
+
type: "comap",
|
|
1091
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
1092
|
+
meta: null,
|
|
1093
|
+
...Crypto.createdNowUnique(),
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
const childObject2 = node.createCoValue({
|
|
1097
|
+
type: "comap",
|
|
1098
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
1099
|
+
meta: null,
|
|
1100
|
+
...Crypto.createdNowUnique(),
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
expect(childObject1.id).not.toEqual(childObject2.id);
|
|
1149
1104
|
});
|
|
1150
1105
|
|
|
1151
1106
|
test("Admins can create an adminInvite, which can add an admin", () => {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1107
|
+
const { groupCore, admin } = newGroup();
|
|
1108
|
+
|
|
1109
|
+
const inviteSecret = Crypto.newRandomAgentSecret();
|
|
1110
|
+
const inviteID = Crypto.getAgentID(inviteSecret);
|
|
1111
|
+
|
|
1112
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1113
|
+
|
|
1114
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1115
|
+
const revelation = Crypto.seal({
|
|
1116
|
+
message: readKey,
|
|
1117
|
+
from: admin.currentSealerSecret(),
|
|
1118
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
1119
|
+
nOnceMaterial: {
|
|
1120
|
+
in: groupCore.id,
|
|
1121
|
+
tx: groupCore.nextTransactionID(),
|
|
1122
|
+
},
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
1126
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1127
|
+
|
|
1128
|
+
group.set(inviteID, "adminInvite", "trusting");
|
|
1129
|
+
|
|
1130
|
+
expect(group.get(inviteID)).toEqual("adminInvite");
|
|
1131
|
+
|
|
1132
|
+
const revelationForInvite = Crypto.seal({
|
|
1133
|
+
message: readKey,
|
|
1134
|
+
from: admin.currentSealerSecret(),
|
|
1135
|
+
to: Crypto.getAgentSealerID(inviteID),
|
|
1136
|
+
nOnceMaterial: {
|
|
1137
|
+
in: groupCore.id,
|
|
1138
|
+
tx: groupCore.nextTransactionID(),
|
|
1139
|
+
},
|
|
1140
|
+
});
|
|
1141
|
+
|
|
1142
|
+
group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
|
|
1143
|
+
|
|
1144
|
+
const groupAsInvite = expectGroup(
|
|
1145
|
+
groupCore
|
|
1146
|
+
.testWithDifferentAccount(
|
|
1147
|
+
new ControlledAgent(inviteSecret, Crypto),
|
|
1148
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1149
|
+
)
|
|
1150
|
+
.getCurrentContent(),
|
|
1151
|
+
);
|
|
1152
|
+
|
|
1153
|
+
const invitedAdminSecret = Crypto.newRandomAgentSecret();
|
|
1154
|
+
const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
|
|
1155
|
+
|
|
1156
|
+
groupAsInvite.set(invitedAdminID, "admin", "trusting");
|
|
1157
|
+
|
|
1158
|
+
expect(groupAsInvite.get(invitedAdminID)).toEqual("admin");
|
|
1159
|
+
|
|
1160
|
+
const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
|
|
1161
|
+
|
|
1162
|
+
expect(readKeyAsInvite.secret).toBeDefined();
|
|
1163
|
+
|
|
1164
|
+
const revelation2 = Crypto.seal({
|
|
1165
|
+
message: readKeyAsInvite.secret!,
|
|
1166
|
+
from: Crypto.getAgentSealerSecret(invitedAdminSecret),
|
|
1167
|
+
to: Crypto.getAgentSealerID(invitedAdminID),
|
|
1168
|
+
nOnceMaterial: {
|
|
1169
|
+
in: groupCore.id,
|
|
1170
|
+
tx: groupCore.nextTransactionID(),
|
|
1171
|
+
},
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
groupAsInvite.set(
|
|
1175
|
+
`${readKeyAsInvite.id}_for_${invitedAdminID}`,
|
|
1176
|
+
revelation2,
|
|
1177
|
+
"trusting",
|
|
1178
|
+
);
|
|
1179
|
+
|
|
1180
|
+
expect(
|
|
1181
|
+
groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedAdminID}`),
|
|
1182
|
+
).toEqual(revelation2);
|
|
1228
1183
|
});
|
|
1229
1184
|
|
|
1230
1185
|
test("Admins can create an adminInvite, which can add an admin (high-level)", async () => {
|
|
1231
|
-
|
|
1186
|
+
const { node, group } = newGroupHighLevel();
|
|
1232
1187
|
|
|
1233
|
-
|
|
1188
|
+
const inviteSecret = group.createInvite("admin");
|
|
1234
1189
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1190
|
+
const invitedAdminSecret = Crypto.newRandomAgentSecret();
|
|
1191
|
+
const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
|
|
1237
1192
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1193
|
+
const nodeAsInvitedAdmin = node.testWithDifferentAccount(
|
|
1194
|
+
new ControlledAgent(invitedAdminSecret, Crypto),
|
|
1195
|
+
Crypto.newRandomSessionID(invitedAdminID),
|
|
1196
|
+
);
|
|
1242
1197
|
|
|
1243
|
-
|
|
1198
|
+
await nodeAsInvitedAdmin.acceptInvite(group.id, inviteSecret);
|
|
1244
1199
|
|
|
1245
|
-
|
|
1246
|
-
|
|
1200
|
+
const thirdAdmin = Crypto.newRandomAgentSecret();
|
|
1201
|
+
const thirdAdminID = Crypto.getAgentID(thirdAdmin);
|
|
1247
1202
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1203
|
+
const groupAsInvitedAdmin = await nodeAsInvitedAdmin.load(group.id);
|
|
1204
|
+
if (groupAsInvitedAdmin === "unavailable") {
|
|
1205
|
+
throw new Error("groupAsInvitedAdmin is unavailable");
|
|
1206
|
+
}
|
|
1252
1207
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1208
|
+
expect(groupAsInvitedAdmin.get(invitedAdminID)).toEqual("admin");
|
|
1209
|
+
expect(groupAsInvitedAdmin.core.getCurrentReadKey().secret).toBeDefined();
|
|
1255
1210
|
|
|
1256
|
-
|
|
1211
|
+
groupAsInvitedAdmin.addMemberInternal(thirdAdminID, "admin");
|
|
1257
1212
|
|
|
1258
|
-
|
|
1213
|
+
expect(groupAsInvitedAdmin.get(thirdAdminID)).toEqual("admin");
|
|
1259
1214
|
});
|
|
1260
1215
|
|
|
1261
1216
|
test("Admins can create a writerInvite, which can add a writer", () => {
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1217
|
+
const { groupCore, admin } = newGroup();
|
|
1218
|
+
|
|
1219
|
+
const inviteSecret = Crypto.newRandomAgentSecret();
|
|
1220
|
+
const inviteID = Crypto.getAgentID(inviteSecret);
|
|
1221
|
+
|
|
1222
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1223
|
+
|
|
1224
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1225
|
+
const revelation = Crypto.seal({
|
|
1226
|
+
message: readKey,
|
|
1227
|
+
from: admin.currentSealerSecret(),
|
|
1228
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
1229
|
+
nOnceMaterial: {
|
|
1230
|
+
in: groupCore.id,
|
|
1231
|
+
tx: groupCore.nextTransactionID(),
|
|
1232
|
+
},
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
1236
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1237
|
+
|
|
1238
|
+
group.set(inviteID, "writerInvite", "trusting");
|
|
1239
|
+
|
|
1240
|
+
expect(group.get(inviteID)).toEqual("writerInvite");
|
|
1241
|
+
|
|
1242
|
+
const revelationForInvite = Crypto.seal({
|
|
1243
|
+
message: readKey,
|
|
1244
|
+
from: admin.currentSealerSecret(),
|
|
1245
|
+
to: Crypto.getAgentSealerID(inviteID),
|
|
1246
|
+
nOnceMaterial: {
|
|
1247
|
+
in: groupCore.id,
|
|
1248
|
+
tx: groupCore.nextTransactionID(),
|
|
1249
|
+
},
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
|
|
1253
|
+
|
|
1254
|
+
const groupAsInvite = expectGroup(
|
|
1255
|
+
groupCore
|
|
1256
|
+
.testWithDifferentAccount(
|
|
1257
|
+
new ControlledAgent(inviteSecret, Crypto),
|
|
1258
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1259
|
+
)
|
|
1260
|
+
.getCurrentContent(),
|
|
1261
|
+
);
|
|
1262
|
+
|
|
1263
|
+
const invitedWriterSecret = Crypto.newRandomAgentSecret();
|
|
1264
|
+
const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
|
|
1265
|
+
|
|
1266
|
+
groupAsInvite.set(invitedWriterID, "writer", "trusting");
|
|
1267
|
+
|
|
1268
|
+
expect(groupAsInvite.get(invitedWriterID)).toEqual("writer");
|
|
1269
|
+
|
|
1270
|
+
const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
|
|
1271
|
+
|
|
1272
|
+
expect(readKeyAsInvite.secret).toBeDefined();
|
|
1273
|
+
|
|
1274
|
+
const revelation2 = Crypto.seal({
|
|
1275
|
+
message: readKeyAsInvite.secret!,
|
|
1276
|
+
from: Crypto.getAgentSealerSecret(invitedWriterSecret),
|
|
1277
|
+
to: Crypto.getAgentSealerID(invitedWriterID),
|
|
1278
|
+
nOnceMaterial: {
|
|
1279
|
+
in: groupCore.id,
|
|
1280
|
+
tx: groupCore.nextTransactionID(),
|
|
1281
|
+
},
|
|
1282
|
+
});
|
|
1283
|
+
|
|
1284
|
+
groupAsInvite.set(
|
|
1285
|
+
`${readKeyAsInvite.id}_for_${invitedWriterID}`,
|
|
1286
|
+
revelation2,
|
|
1287
|
+
"trusting",
|
|
1288
|
+
);
|
|
1289
|
+
|
|
1290
|
+
expect(
|
|
1291
|
+
groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedWriterID}`),
|
|
1292
|
+
).toEqual(revelation2);
|
|
1338
1293
|
});
|
|
1339
1294
|
|
|
1340
1295
|
test("Admins can create a writerInvite, which can add a writer (high-level)", async () => {
|
|
1341
|
-
|
|
1296
|
+
const { node, group } = newGroupHighLevel();
|
|
1342
1297
|
|
|
1343
|
-
|
|
1298
|
+
const inviteSecret = group.createInvite("writer");
|
|
1344
1299
|
|
|
1345
|
-
|
|
1346
|
-
|
|
1300
|
+
const invitedWriterSecret = Crypto.newRandomAgentSecret();
|
|
1301
|
+
const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
|
|
1347
1302
|
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1303
|
+
const nodeAsInvitedWriter = node.testWithDifferentAccount(
|
|
1304
|
+
new ControlledAgent(invitedWriterSecret, Crypto),
|
|
1305
|
+
Crypto.newRandomSessionID(invitedWriterID),
|
|
1306
|
+
);
|
|
1352
1307
|
|
|
1353
|
-
|
|
1308
|
+
await nodeAsInvitedWriter.acceptInvite(group.id, inviteSecret);
|
|
1354
1309
|
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1310
|
+
const groupAsInvitedWriter = await nodeAsInvitedWriter.load(group.id);
|
|
1311
|
+
if (groupAsInvitedWriter === "unavailable") {
|
|
1312
|
+
throw new Error("groupAsInvitedAdmin is unavailable");
|
|
1313
|
+
}
|
|
1359
1314
|
|
|
1360
|
-
|
|
1361
|
-
|
|
1315
|
+
expect(groupAsInvitedWriter.get(invitedWriterID)).toEqual("writer");
|
|
1316
|
+
expect(groupAsInvitedWriter.core.getCurrentReadKey().secret).toBeDefined();
|
|
1362
1317
|
});
|
|
1363
1318
|
|
|
1364
1319
|
test("Admins can create a readerInvite, which can add a reader", () => {
|
|
1365
|
-
|
|
1320
|
+
const { groupCore, admin } = newGroup();
|
|
1366
1321
|
|
|
1367
|
-
|
|
1368
|
-
|
|
1322
|
+
const inviteSecret = Crypto.newRandomAgentSecret();
|
|
1323
|
+
const inviteID = Crypto.getAgentID(inviteSecret);
|
|
1369
1324
|
|
|
1370
|
-
|
|
1325
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1371
1326
|
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1327
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1328
|
+
const revelation = Crypto.seal({
|
|
1329
|
+
message: readKey,
|
|
1330
|
+
from: admin.currentSealerSecret(),
|
|
1331
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
1332
|
+
nOnceMaterial: {
|
|
1333
|
+
in: groupCore.id,
|
|
1334
|
+
tx: groupCore.nextTransactionID(),
|
|
1335
|
+
},
|
|
1336
|
+
});
|
|
1382
1337
|
|
|
1383
|
-
|
|
1384
|
-
|
|
1338
|
+
group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
1339
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1385
1340
|
|
|
1386
|
-
|
|
1341
|
+
group.set(inviteID, "readerInvite", "trusting");
|
|
1387
1342
|
|
|
1388
|
-
|
|
1343
|
+
expect(group.get(inviteID)).toEqual("readerInvite");
|
|
1389
1344
|
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1345
|
+
const revelationForInvite = Crypto.seal({
|
|
1346
|
+
message: readKey,
|
|
1347
|
+
from: admin.currentSealerSecret(),
|
|
1348
|
+
to: Crypto.getAgentSealerID(inviteID),
|
|
1349
|
+
nOnceMaterial: {
|
|
1350
|
+
in: groupCore.id,
|
|
1351
|
+
tx: groupCore.nextTransactionID(),
|
|
1352
|
+
},
|
|
1353
|
+
});
|
|
1399
1354
|
|
|
1400
|
-
|
|
1355
|
+
group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
|
|
1401
1356
|
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1357
|
+
const groupAsInvite = expectGroup(
|
|
1358
|
+
groupCore
|
|
1359
|
+
.testWithDifferentAccount(
|
|
1360
|
+
new ControlledAgent(inviteSecret, Crypto),
|
|
1361
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1362
|
+
)
|
|
1363
|
+
.getCurrentContent(),
|
|
1364
|
+
);
|
|
1410
1365
|
|
|
1411
|
-
|
|
1412
|
-
|
|
1366
|
+
const invitedReaderSecret = Crypto.newRandomAgentSecret();
|
|
1367
|
+
const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
|
|
1413
1368
|
|
|
1414
|
-
|
|
1369
|
+
groupAsInvite.set(invitedReaderID, "reader", "trusting");
|
|
1415
1370
|
|
|
1416
|
-
|
|
1371
|
+
expect(groupAsInvite.get(invitedReaderID)).toEqual("reader");
|
|
1417
1372
|
|
|
1418
|
-
|
|
1373
|
+
const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
|
|
1419
1374
|
|
|
1420
|
-
|
|
1375
|
+
expect(readKeyAsInvite.secret).toBeDefined();
|
|
1421
1376
|
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1377
|
+
groupAsInvite.set(
|
|
1378
|
+
`${readKeyAsInvite.id}_for_${invitedReaderID}`,
|
|
1379
|
+
revelation,
|
|
1380
|
+
"trusting",
|
|
1381
|
+
);
|
|
1427
1382
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1383
|
+
expect(
|
|
1384
|
+
groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedReaderID}`),
|
|
1385
|
+
).toEqual(revelation);
|
|
1431
1386
|
});
|
|
1432
1387
|
|
|
1433
1388
|
test("Admins can create a readerInvite, which can add a reader (high-level)", async () => {
|
|
1434
|
-
|
|
1389
|
+
const { node, group } = newGroupHighLevel();
|
|
1435
1390
|
|
|
1436
|
-
|
|
1391
|
+
const inviteSecret = group.createInvite("reader");
|
|
1437
1392
|
|
|
1438
|
-
|
|
1439
|
-
|
|
1393
|
+
const invitedReaderSecret = Crypto.newRandomAgentSecret();
|
|
1394
|
+
const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
|
|
1440
1395
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1396
|
+
const nodeAsInvitedReader = node.testWithDifferentAccount(
|
|
1397
|
+
new ControlledAgent(invitedReaderSecret, Crypto),
|
|
1398
|
+
Crypto.newRandomSessionID(invitedReaderID),
|
|
1399
|
+
);
|
|
1445
1400
|
|
|
1446
|
-
|
|
1401
|
+
await nodeAsInvitedReader.acceptInvite(group.id, inviteSecret);
|
|
1447
1402
|
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1403
|
+
const groupAsInvitedReader = await nodeAsInvitedReader.load(group.id);
|
|
1404
|
+
if (groupAsInvitedReader === "unavailable") {
|
|
1405
|
+
throw new Error("groupAsInvitedAdmin is unavailable");
|
|
1406
|
+
}
|
|
1452
1407
|
|
|
1453
|
-
|
|
1454
|
-
|
|
1408
|
+
expect(groupAsInvitedReader.get(invitedReaderID)).toEqual("reader");
|
|
1409
|
+
expect(groupAsInvitedReader.core.getCurrentReadKey().secret).toBeDefined();
|
|
1455
1410
|
});
|
|
1456
1411
|
|
|
1457
1412
|
test("WriterInvites can not invite admins", () => {
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1413
|
+
const { groupCore, admin } = newGroup();
|
|
1414
|
+
|
|
1415
|
+
const inviteSecret = Crypto.newRandomAgentSecret();
|
|
1416
|
+
const inviteID = Crypto.getAgentID(inviteSecret);
|
|
1417
|
+
|
|
1418
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1419
|
+
|
|
1420
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1421
|
+
const revelation = Crypto.seal({
|
|
1422
|
+
message: readKey,
|
|
1423
|
+
from: admin.currentSealerSecret(),
|
|
1424
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
1425
|
+
nOnceMaterial: {
|
|
1426
|
+
in: groupCore.id,
|
|
1427
|
+
tx: groupCore.nextTransactionID(),
|
|
1428
|
+
},
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
1432
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1433
|
+
|
|
1434
|
+
group.set(inviteID, "writerInvite", "trusting");
|
|
1435
|
+
|
|
1436
|
+
expect(group.get(inviteID)).toEqual("writerInvite");
|
|
1437
|
+
|
|
1438
|
+
const revelationForInvite = Crypto.seal({
|
|
1439
|
+
message: readKey,
|
|
1440
|
+
from: admin.currentSealerSecret(),
|
|
1441
|
+
to: Crypto.getAgentSealerID(inviteID),
|
|
1442
|
+
nOnceMaterial: {
|
|
1443
|
+
in: groupCore.id,
|
|
1444
|
+
tx: groupCore.nextTransactionID(),
|
|
1445
|
+
},
|
|
1446
|
+
});
|
|
1447
|
+
|
|
1448
|
+
group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
|
|
1449
|
+
|
|
1450
|
+
const groupAsInvite = expectGroup(
|
|
1451
|
+
groupCore
|
|
1452
|
+
.testWithDifferentAccount(
|
|
1453
|
+
new ControlledAgent(inviteSecret, Crypto),
|
|
1454
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1455
|
+
)
|
|
1456
|
+
.getCurrentContent(),
|
|
1457
|
+
);
|
|
1458
|
+
|
|
1459
|
+
const invitedAdminSecret = Crypto.newRandomAgentSecret();
|
|
1460
|
+
const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
|
|
1461
|
+
|
|
1462
|
+
groupAsInvite.set(invitedAdminID, "admin", "trusting");
|
|
1463
|
+
expect(groupAsInvite.get(invitedAdminID)).toBeUndefined();
|
|
1509
1464
|
});
|
|
1510
1465
|
|
|
1511
1466
|
test("ReaderInvites can not invite admins", () => {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1467
|
+
const { groupCore, admin } = newGroup();
|
|
1468
|
+
|
|
1469
|
+
const inviteSecret = Crypto.newRandomAgentSecret();
|
|
1470
|
+
const inviteID = Crypto.getAgentID(inviteSecret);
|
|
1471
|
+
|
|
1472
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1473
|
+
|
|
1474
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1475
|
+
const revelation = Crypto.seal({
|
|
1476
|
+
message: readKey,
|
|
1477
|
+
from: admin.currentSealerSecret(),
|
|
1478
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
1479
|
+
nOnceMaterial: {
|
|
1480
|
+
in: groupCore.id,
|
|
1481
|
+
tx: groupCore.nextTransactionID(),
|
|
1482
|
+
},
|
|
1483
|
+
});
|
|
1484
|
+
|
|
1485
|
+
group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
1486
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1487
|
+
|
|
1488
|
+
group.set(inviteID, "readerInvite", "trusting");
|
|
1489
|
+
|
|
1490
|
+
expect(group.get(inviteID)).toEqual("readerInvite");
|
|
1491
|
+
|
|
1492
|
+
const revelationForInvite = Crypto.seal({
|
|
1493
|
+
message: readKey,
|
|
1494
|
+
from: admin.currentSealerSecret(),
|
|
1495
|
+
to: Crypto.getAgentSealerID(inviteID),
|
|
1496
|
+
nOnceMaterial: {
|
|
1497
|
+
in: groupCore.id,
|
|
1498
|
+
tx: groupCore.nextTransactionID(),
|
|
1499
|
+
},
|
|
1500
|
+
});
|
|
1501
|
+
|
|
1502
|
+
group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
|
|
1503
|
+
|
|
1504
|
+
const groupAsInvite = expectGroup(
|
|
1505
|
+
groupCore
|
|
1506
|
+
.testWithDifferentAccount(
|
|
1507
|
+
new ControlledAgent(inviteSecret, Crypto),
|
|
1508
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1509
|
+
)
|
|
1510
|
+
.getCurrentContent(),
|
|
1511
|
+
);
|
|
1512
|
+
|
|
1513
|
+
const invitedAdminSecret = Crypto.newRandomAgentSecret();
|
|
1514
|
+
const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
|
|
1515
|
+
|
|
1516
|
+
groupAsInvite.set(invitedAdminID, "admin", "trusting");
|
|
1517
|
+
expect(groupAsInvite.get(invitedAdminID)).toBeUndefined();
|
|
1563
1518
|
});
|
|
1564
1519
|
|
|
1565
1520
|
test("ReaderInvites can not invite writers", () => {
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1521
|
+
const { groupCore, admin } = newGroup();
|
|
1522
|
+
|
|
1523
|
+
const inviteSecret = Crypto.newRandomAgentSecret();
|
|
1524
|
+
const inviteID = Crypto.getAgentID(inviteSecret);
|
|
1525
|
+
|
|
1526
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1527
|
+
|
|
1528
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1529
|
+
const revelation = Crypto.seal({
|
|
1530
|
+
message: readKey,
|
|
1531
|
+
from: admin.currentSealerSecret(),
|
|
1532
|
+
to: admin.currentSealerID()._unsafeUnwrap(),
|
|
1533
|
+
nOnceMaterial: {
|
|
1534
|
+
in: groupCore.id,
|
|
1535
|
+
tx: groupCore.nextTransactionID(),
|
|
1536
|
+
},
|
|
1537
|
+
});
|
|
1538
|
+
|
|
1539
|
+
group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
|
|
1540
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1541
|
+
|
|
1542
|
+
group.set(inviteID, "readerInvite", "trusting");
|
|
1543
|
+
|
|
1544
|
+
expect(group.get(inviteID)).toEqual("readerInvite");
|
|
1545
|
+
|
|
1546
|
+
const revelationForInvite = Crypto.seal({
|
|
1547
|
+
message: readKey,
|
|
1548
|
+
from: admin.currentSealerSecret(),
|
|
1549
|
+
to: Crypto.getAgentSealerID(inviteID),
|
|
1550
|
+
nOnceMaterial: {
|
|
1551
|
+
in: groupCore.id,
|
|
1552
|
+
tx: groupCore.nextTransactionID(),
|
|
1553
|
+
},
|
|
1554
|
+
});
|
|
1555
|
+
|
|
1556
|
+
group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
|
|
1557
|
+
|
|
1558
|
+
const groupAsInvite = expectGroup(
|
|
1559
|
+
groupCore
|
|
1560
|
+
.testWithDifferentAccount(
|
|
1561
|
+
new ControlledAgent(inviteSecret, Crypto),
|
|
1562
|
+
Crypto.newRandomSessionID(inviteID),
|
|
1563
|
+
)
|
|
1564
|
+
.getCurrentContent(),
|
|
1565
|
+
);
|
|
1566
|
+
|
|
1567
|
+
const invitedWriterSecret = Crypto.newRandomAgentSecret();
|
|
1568
|
+
const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
|
|
1569
|
+
|
|
1570
|
+
groupAsInvite.set(invitedWriterID, "writer", "trusting");
|
|
1571
|
+
expect(groupAsInvite.get(invitedWriterID)).toBeUndefined();
|
|
1617
1572
|
});
|
|
1618
1573
|
|
|
1619
1574
|
test("Can give read permission to 'everyone'", () => {
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
)
|
|
1656
|
-
.getCurrentContent(),
|
|
1657
|
-
);
|
|
1658
|
-
|
|
1659
|
-
expect(childContent2.get("foo")).toEqual("bar");
|
|
1575
|
+
const { node, groupCore } = newGroup();
|
|
1576
|
+
|
|
1577
|
+
const childObject = node.createCoValue({
|
|
1578
|
+
type: "comap",
|
|
1579
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
1580
|
+
meta: null,
|
|
1581
|
+
...Crypto.createdNowUnique(),
|
|
1582
|
+
});
|
|
1583
|
+
|
|
1584
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1585
|
+
|
|
1586
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1587
|
+
group.set("everyone", "reader", "trusting");
|
|
1588
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1589
|
+
group.set(`${readKeyID}_for_everyone`, readKey, "trusting");
|
|
1590
|
+
|
|
1591
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
1592
|
+
|
|
1593
|
+
expect(childContent.get("foo")).toBeUndefined();
|
|
1594
|
+
|
|
1595
|
+
childContent.set("foo", "bar", "private");
|
|
1596
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
1597
|
+
|
|
1598
|
+
const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
|
|
1599
|
+
|
|
1600
|
+
const childContent2 = expectMap(
|
|
1601
|
+
childObject
|
|
1602
|
+
.testWithDifferentAccount(
|
|
1603
|
+
newAccount,
|
|
1604
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1605
|
+
)
|
|
1606
|
+
.getCurrentContent(),
|
|
1607
|
+
);
|
|
1608
|
+
|
|
1609
|
+
expect(childContent2.get("foo")).toEqual("bar");
|
|
1660
1610
|
});
|
|
1661
1611
|
|
|
1662
1612
|
test("Can give read permissions to 'everyone' (high-level)", async () => {
|
|
1663
|
-
|
|
1613
|
+
const { group } = newGroupHighLevel();
|
|
1664
1614
|
|
|
1665
|
-
|
|
1615
|
+
const childObject = group.createMap();
|
|
1666
1616
|
|
|
1667
|
-
|
|
1617
|
+
expect(childObject.get("foo")).toBeUndefined();
|
|
1668
1618
|
|
|
1669
|
-
|
|
1619
|
+
group.addMember("everyone", "reader");
|
|
1670
1620
|
|
|
1671
|
-
|
|
1672
|
-
|
|
1621
|
+
childObject.set("foo", "bar", "private");
|
|
1622
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
1673
1623
|
|
|
1674
|
-
|
|
1675
|
-
Crypto.newRandomAgentSecret(),
|
|
1676
|
-
Crypto,
|
|
1677
|
-
);
|
|
1624
|
+
const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
|
|
1678
1625
|
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
.getCurrentContent(),
|
|
1688
|
-
);
|
|
1626
|
+
const childContent2 = expectMap(
|
|
1627
|
+
childObject.core
|
|
1628
|
+
.testWithDifferentAccount(
|
|
1629
|
+
new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto),
|
|
1630
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1631
|
+
)
|
|
1632
|
+
.getCurrentContent(),
|
|
1633
|
+
);
|
|
1689
1634
|
|
|
1690
|
-
|
|
1635
|
+
expect(childContent2.get("foo")).toEqual("bar");
|
|
1691
1636
|
});
|
|
1692
1637
|
|
|
1693
1638
|
test("Can give write permission to 'everyone'", async () => {
|
|
1694
|
-
|
|
1639
|
+
const { node, groupCore } = newGroup();
|
|
1695
1640
|
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1641
|
+
const childObject = node.createCoValue({
|
|
1642
|
+
type: "comap",
|
|
1643
|
+
ruleset: { type: "ownedByGroup", group: groupCore.id },
|
|
1644
|
+
meta: null,
|
|
1645
|
+
...Crypto.createdNowUnique(),
|
|
1646
|
+
});
|
|
1702
1647
|
|
|
1703
|
-
|
|
1648
|
+
const group = expectGroup(groupCore.getCurrentContent());
|
|
1704
1649
|
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1650
|
+
const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
|
|
1651
|
+
group.set("everyone", "writer", "trusting");
|
|
1652
|
+
group.set("readKey", readKeyID, "trusting");
|
|
1653
|
+
group.set(`${readKeyID}_for_everyone`, readKey, "trusting");
|
|
1709
1654
|
|
|
1710
|
-
|
|
1655
|
+
const childContent = expectMap(childObject.getCurrentContent());
|
|
1711
1656
|
|
|
1712
|
-
|
|
1657
|
+
expect(childContent.get("foo")).toBeUndefined();
|
|
1713
1658
|
|
|
1714
|
-
|
|
1715
|
-
|
|
1659
|
+
childContent.set("foo", "bar", "private");
|
|
1660
|
+
expect(childContent.get("foo")).toEqual("bar");
|
|
1716
1661
|
|
|
1717
|
-
|
|
1718
|
-
Crypto.newRandomAgentSecret(),
|
|
1719
|
-
Crypto,
|
|
1720
|
-
);
|
|
1662
|
+
const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
|
|
1721
1663
|
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
.getCurrentContent(),
|
|
1731
|
-
);
|
|
1664
|
+
const childContent2 = expectMap(
|
|
1665
|
+
childObject
|
|
1666
|
+
.testWithDifferentAccount(
|
|
1667
|
+
newAccount,
|
|
1668
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1669
|
+
)
|
|
1670
|
+
.getCurrentContent(),
|
|
1671
|
+
);
|
|
1732
1672
|
|
|
1733
|
-
|
|
1734
|
-
|
|
1673
|
+
// TODO: resolve race condition
|
|
1674
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
1735
1675
|
|
|
1736
|
-
|
|
1676
|
+
expect(childContent2.get("foo")).toEqual("bar");
|
|
1737
1677
|
|
|
1738
|
-
|
|
1739
|
-
|
|
1678
|
+
childContent2.set("foo", "bar2", "private");
|
|
1679
|
+
expect(childContent2.get("foo")).toEqual("bar2");
|
|
1740
1680
|
});
|
|
1741
1681
|
|
|
1742
1682
|
test("Can give write permissions to 'everyone' (high-level)", async () => {
|
|
1743
|
-
|
|
1683
|
+
const { group } = newGroupHighLevel();
|
|
1744
1684
|
|
|
1745
|
-
|
|
1685
|
+
const childObject = group.createMap();
|
|
1746
1686
|
|
|
1747
|
-
|
|
1687
|
+
expect(childObject.get("foo")).toBeUndefined();
|
|
1748
1688
|
|
|
1749
|
-
|
|
1689
|
+
group.addMember("everyone", "writer");
|
|
1750
1690
|
|
|
1751
|
-
|
|
1752
|
-
|
|
1691
|
+
childObject.set("foo", "bar", "private");
|
|
1692
|
+
expect(childObject.get("foo")).toEqual("bar");
|
|
1753
1693
|
|
|
1754
|
-
|
|
1755
|
-
Crypto.newRandomAgentSecret(),
|
|
1756
|
-
Crypto,
|
|
1757
|
-
);
|
|
1694
|
+
const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
|
|
1758
1695
|
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
.getCurrentContent(),
|
|
1768
|
-
);
|
|
1696
|
+
const childContent2 = expectMap(
|
|
1697
|
+
childObject.core
|
|
1698
|
+
.testWithDifferentAccount(
|
|
1699
|
+
newAccount,
|
|
1700
|
+
Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
|
|
1701
|
+
)
|
|
1702
|
+
.getCurrentContent(),
|
|
1703
|
+
);
|
|
1769
1704
|
|
|
1770
|
-
|
|
1705
|
+
expect(childContent2.get("foo")).toEqual("bar");
|
|
1771
1706
|
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1707
|
+
console.log("Before anon set");
|
|
1708
|
+
childContent2.set("foo", "bar2", "private");
|
|
1709
|
+
expect(childContent2.get("foo")).toEqual("bar2");
|
|
1775
1710
|
});
|