cojson 0.0.7 → 0.0.9
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/.eslintrc.cjs +11 -8
- package/dist/coValue.d.ts +97 -0
- package/dist/coValue.js +381 -0
- package/dist/coValue.js.map +1 -0
- package/dist/coValue.test.d.ts +1 -0
- package/dist/coValue.test.js +78 -0
- package/dist/coValue.test.js.map +1 -0
- package/dist/contentType.d.ts +15 -0
- package/dist/contentType.js +7 -0
- package/dist/contentType.js.map +1 -0
- package/dist/contentType.test.d.ts +1 -0
- package/dist/contentType.test.js +149 -0
- package/dist/contentType.test.js.map +1 -0
- package/dist/contentTypes/coList.d.ts +11 -0
- package/dist/contentTypes/coList.js +16 -0
- package/dist/contentTypes/coList.js.map +1 -0
- package/dist/contentTypes/coMap.d.ts +56 -0
- package/dist/contentTypes/coMap.js +126 -0
- package/dist/contentTypes/coMap.js.map +1 -0
- package/dist/contentTypes/coStream.d.ts +11 -0
- package/dist/contentTypes/coStream.js +16 -0
- package/dist/contentTypes/coStream.js.map +1 -0
- package/dist/contentTypes/static.d.ts +11 -0
- package/dist/contentTypes/static.js +14 -0
- package/dist/contentTypes/static.js.map +1 -0
- package/dist/crypto.d.ts +97 -0
- package/dist/crypto.js +156 -0
- package/dist/crypto.js.map +1 -0
- package/dist/crypto.test.d.ts +1 -0
- package/dist/crypto.test.js +115 -0
- package/dist/crypto.test.js.map +1 -0
- package/dist/ids.d.ts +7 -0
- package/dist/ids.js +2 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/jsonValue.d.ts +7 -0
- package/dist/jsonValue.js +2 -0
- package/dist/jsonValue.js.map +1 -0
- package/dist/node.d.ts +33 -0
- package/dist/node.js +113 -0
- package/dist/node.js.map +1 -0
- package/dist/permissions.d.ts +54 -0
- package/dist/permissions.js +218 -0
- package/dist/permissions.js.map +1 -0
- package/dist/permissions.test.d.ts +1 -0
- package/dist/permissions.test.js +794 -0
- package/dist/permissions.test.js.map +1 -0
- package/dist/sync.d.ts +80 -0
- package/dist/sync.js +271 -0
- package/dist/sync.js.map +1 -0
- package/dist/sync.test.d.ts +1 -0
- package/dist/sync.test.js +826 -0
- package/dist/sync.test.js.map +1 -0
- package/package.json +7 -6
- package/src/coValue.test.ts +3 -4
- package/src/coValue.ts +11 -11
- package/src/contentType.test.ts +3 -3
- package/src/contentType.ts +6 -6
- package/src/contentTypes/coList.ts +4 -4
- package/src/contentTypes/coMap.ts +6 -6
- package/src/contentTypes/coStream.ts +4 -4
- package/src/contentTypes/static.ts +5 -5
- package/src/crypto.test.ts +1 -1
- package/src/crypto.ts +2 -2
- package/src/index.ts +8 -8
- package/src/jsonValue.ts +1 -1
- package/src/node.ts +6 -7
- package/src/permissions.test.ts +5 -5
- package/src/permissions.ts +7 -7
- package/src/sync.test.ts +7 -7
- package/src/sync.ts +6 -6
- package/tsconfig.json +1 -7
- package/dist/coValue.mjs +0 -437
- package/dist/coValue.test.mjs +0 -122
- package/dist/contentType.mjs +0 -7
- package/dist/contentType.test.mjs +0 -179
- package/dist/contentTypes/coList.mjs +0 -18
- package/dist/contentTypes/coMap.mjs +0 -126
- package/dist/contentTypes/coStream.mjs +0 -18
- package/dist/contentTypes/static.mjs +0 -16
- package/dist/crypto.mjs +0 -207
- package/dist/crypto.test.mjs +0 -155
- package/dist/ids.mjs +0 -1
- package/dist/index.mjs +0 -21
- package/dist/jsonValue.mjs +0 -1
- package/dist/node.mjs +0 -144
- package/dist/permissions.mjs +0 -244
- package/dist/permissions.test.mjs +0 -985
- package/dist/sync.mjs +0 -318
- package/dist/sync.test.mjs +0 -861
|
@@ -1,985 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
getAgent,
|
|
4
|
-
getAgentID,
|
|
5
|
-
newRandomAgentCredential,
|
|
6
|
-
newRandomSessionID
|
|
7
|
-
} from "./coValue";
|
|
8
|
-
import { LocalNode } from "./node";
|
|
9
|
-
import { expectMap } from "./contentType";
|
|
10
|
-
import { expectTeamContent } from "./permissions";
|
|
11
|
-
import {
|
|
12
|
-
createdNowUnique,
|
|
13
|
-
getRecipientID,
|
|
14
|
-
newRandomKeySecret,
|
|
15
|
-
seal,
|
|
16
|
-
sealKeySecret
|
|
17
|
-
} from "./crypto";
|
|
18
|
-
function teamWithTwoAdmins() {
|
|
19
|
-
const { team, admin, adminID, node } = newTeam();
|
|
20
|
-
const otherAdmin = node.createAgent("otherAdmin");
|
|
21
|
-
const otherAdminID = getAgentID(getAgent(otherAdmin));
|
|
22
|
-
let content = expectTeamContent(team.getCurrentContent());
|
|
23
|
-
content.edit((editable) => {
|
|
24
|
-
editable.set(otherAdminID, "admin", "trusting");
|
|
25
|
-
expect(editable.get(otherAdminID)).toEqual("admin");
|
|
26
|
-
});
|
|
27
|
-
content = expectTeamContent(team.getCurrentContent());
|
|
28
|
-
if (content.type !== "comap") {
|
|
29
|
-
throw new Error("Expected map");
|
|
30
|
-
}
|
|
31
|
-
expect(content.get(otherAdminID)).toEqual("admin");
|
|
32
|
-
return { team, admin, adminID, otherAdmin, otherAdminID, node };
|
|
33
|
-
}
|
|
34
|
-
function newTeam() {
|
|
35
|
-
const admin = newRandomAgentCredential("admin");
|
|
36
|
-
const adminID = getAgentID(getAgent(admin));
|
|
37
|
-
const node = new LocalNode(admin, newRandomSessionID(adminID));
|
|
38
|
-
const team = node.createCoValue({
|
|
39
|
-
type: "comap",
|
|
40
|
-
ruleset: { type: "team", initialAdmin: adminID },
|
|
41
|
-
meta: null,
|
|
42
|
-
...createdNowUnique(),
|
|
43
|
-
publicNickname: "team"
|
|
44
|
-
});
|
|
45
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
46
|
-
teamContent.edit((editable) => {
|
|
47
|
-
editable.set(adminID, "admin", "trusting");
|
|
48
|
-
expect(editable.get(adminID)).toEqual("admin");
|
|
49
|
-
});
|
|
50
|
-
return { node, team, admin, adminID };
|
|
51
|
-
}
|
|
52
|
-
test("Initial admin can add another admin to a team", () => {
|
|
53
|
-
teamWithTwoAdmins();
|
|
54
|
-
});
|
|
55
|
-
function newTeamHighLevel() {
|
|
56
|
-
const admin = newRandomAgentCredential("admin");
|
|
57
|
-
const adminID = getAgentID(getAgent(admin));
|
|
58
|
-
const node = new LocalNode(admin, newRandomSessionID(adminID));
|
|
59
|
-
const team = node.createTeam();
|
|
60
|
-
return { admin, adminID, node, team };
|
|
61
|
-
}
|
|
62
|
-
function teamWithTwoAdminsHighLevel() {
|
|
63
|
-
const { admin, adminID, node, team } = newTeamHighLevel();
|
|
64
|
-
const otherAdmin = node.createAgent("otherAdmin");
|
|
65
|
-
const otherAdminID = getAgentID(getAgent(otherAdmin));
|
|
66
|
-
team.addMember(otherAdminID, "admin");
|
|
67
|
-
return { admin, adminID, node, team, otherAdmin, otherAdminID };
|
|
68
|
-
}
|
|
69
|
-
test("Initial admin can add another admin to a team (high level)", () => {
|
|
70
|
-
teamWithTwoAdminsHighLevel();
|
|
71
|
-
});
|
|
72
|
-
test("Added admin can add a third admin to a team", () => {
|
|
73
|
-
const { team, otherAdmin, otherAdminID, node } = teamWithTwoAdmins();
|
|
74
|
-
const teamAsOtherAdmin = team.testWithDifferentCredentials(
|
|
75
|
-
otherAdmin,
|
|
76
|
-
newRandomSessionID(otherAdminID)
|
|
77
|
-
);
|
|
78
|
-
let otherContent = expectTeamContent(teamAsOtherAdmin.getCurrentContent());
|
|
79
|
-
expect(otherContent.get(otherAdminID)).toEqual("admin");
|
|
80
|
-
const thirdAdmin = node.createAgent("thirdAdmin");
|
|
81
|
-
const thirdAdminID = getAgentID(getAgent(thirdAdmin));
|
|
82
|
-
otherContent.edit((editable) => {
|
|
83
|
-
editable.set(thirdAdminID, "admin", "trusting");
|
|
84
|
-
expect(editable.get(thirdAdminID)).toEqual("admin");
|
|
85
|
-
});
|
|
86
|
-
otherContent = expectTeamContent(teamAsOtherAdmin.getCurrentContent());
|
|
87
|
-
expect(otherContent.get(thirdAdminID)).toEqual("admin");
|
|
88
|
-
});
|
|
89
|
-
test("Added adming can add a third admin to a team (high level)", () => {
|
|
90
|
-
const { team, otherAdmin, otherAdminID, node } = teamWithTwoAdminsHighLevel();
|
|
91
|
-
const teamAsOtherAdmin = team.testWithDifferentCredentials(
|
|
92
|
-
otherAdmin,
|
|
93
|
-
newRandomSessionID(otherAdminID)
|
|
94
|
-
);
|
|
95
|
-
const thirdAdmin = node.createAgent("thirdAdmin");
|
|
96
|
-
const thirdAdminID = getAgentID(getAgent(thirdAdmin));
|
|
97
|
-
teamAsOtherAdmin.addMember(thirdAdminID, "admin");
|
|
98
|
-
expect(teamAsOtherAdmin.teamMap.get(thirdAdminID)).toEqual("admin");
|
|
99
|
-
});
|
|
100
|
-
test("Admins can't demote other admins in a team", () => {
|
|
101
|
-
const { team, adminID, otherAdmin, otherAdminID } = teamWithTwoAdmins();
|
|
102
|
-
let teamContent = expectTeamContent(team.getCurrentContent());
|
|
103
|
-
teamContent.edit((editable) => {
|
|
104
|
-
editable.set(otherAdminID, "writer", "trusting");
|
|
105
|
-
expect(editable.get(otherAdminID)).toEqual("admin");
|
|
106
|
-
});
|
|
107
|
-
teamContent = expectTeamContent(team.getCurrentContent());
|
|
108
|
-
expect(teamContent.get(otherAdminID)).toEqual("admin");
|
|
109
|
-
const teamAsOtherAdmin = team.testWithDifferentCredentials(
|
|
110
|
-
otherAdmin,
|
|
111
|
-
newRandomSessionID(otherAdminID)
|
|
112
|
-
);
|
|
113
|
-
let teamContentAsOtherAdmin = expectTeamContent(
|
|
114
|
-
teamAsOtherAdmin.getCurrentContent()
|
|
115
|
-
);
|
|
116
|
-
teamContentAsOtherAdmin.edit((editable) => {
|
|
117
|
-
editable.set(adminID, "writer", "trusting");
|
|
118
|
-
expect(editable.get(adminID)).toEqual("admin");
|
|
119
|
-
});
|
|
120
|
-
teamContentAsOtherAdmin = expectTeamContent(
|
|
121
|
-
teamAsOtherAdmin.getCurrentContent()
|
|
122
|
-
);
|
|
123
|
-
expect(teamContentAsOtherAdmin.get(adminID)).toEqual("admin");
|
|
124
|
-
});
|
|
125
|
-
test("Admins can't demote other admins in a team (high level)", () => {
|
|
126
|
-
const { team, adminID, otherAdmin, otherAdminID } = teamWithTwoAdminsHighLevel();
|
|
127
|
-
const teamAsOtherAdmin = team.testWithDifferentCredentials(
|
|
128
|
-
otherAdmin,
|
|
129
|
-
newRandomSessionID(otherAdminID)
|
|
130
|
-
);
|
|
131
|
-
expect(() => teamAsOtherAdmin.addMember(adminID, "writer")).toThrow(
|
|
132
|
-
"Failed to set role"
|
|
133
|
-
);
|
|
134
|
-
expect(teamAsOtherAdmin.teamMap.get(adminID)).toEqual("admin");
|
|
135
|
-
});
|
|
136
|
-
test("Admins an add writers to a team, who can't add admins, writers, or readers", () => {
|
|
137
|
-
const { team, node } = newTeam();
|
|
138
|
-
const writer = node.createAgent("writer");
|
|
139
|
-
const writerID = getAgentID(getAgent(writer));
|
|
140
|
-
let teamContent = expectTeamContent(team.getCurrentContent());
|
|
141
|
-
teamContent.edit((editable) => {
|
|
142
|
-
editable.set(writerID, "writer", "trusting");
|
|
143
|
-
expect(editable.get(writerID)).toEqual("writer");
|
|
144
|
-
});
|
|
145
|
-
teamContent = expectTeamContent(team.getCurrentContent());
|
|
146
|
-
expect(teamContent.get(writerID)).toEqual("writer");
|
|
147
|
-
const teamAsWriter = team.testWithDifferentCredentials(
|
|
148
|
-
writer,
|
|
149
|
-
newRandomSessionID(writerID)
|
|
150
|
-
);
|
|
151
|
-
let teamContentAsWriter = expectTeamContent(
|
|
152
|
-
teamAsWriter.getCurrentContent()
|
|
153
|
-
);
|
|
154
|
-
expect(teamContentAsWriter.get(writerID)).toEqual("writer");
|
|
155
|
-
const otherAgent = node.createAgent("otherAgent");
|
|
156
|
-
const otherAgentID = getAgentID(getAgent(otherAgent));
|
|
157
|
-
teamContentAsWriter.edit((editable) => {
|
|
158
|
-
editable.set(otherAgentID, "admin", "trusting");
|
|
159
|
-
expect(editable.get(otherAgentID)).toBeUndefined();
|
|
160
|
-
editable.set(otherAgentID, "writer", "trusting");
|
|
161
|
-
expect(editable.get(otherAgentID)).toBeUndefined();
|
|
162
|
-
editable.set(otherAgentID, "reader", "trusting");
|
|
163
|
-
expect(editable.get(otherAgentID)).toBeUndefined();
|
|
164
|
-
});
|
|
165
|
-
teamContentAsWriter = expectTeamContent(teamAsWriter.getCurrentContent());
|
|
166
|
-
expect(teamContentAsWriter.get(otherAgentID)).toBeUndefined();
|
|
167
|
-
});
|
|
168
|
-
test("Admins an add writers to a team, who can't add admins, writers, or readers (high level)", () => {
|
|
169
|
-
const { team, node } = newTeamHighLevel();
|
|
170
|
-
const writer = node.createAgent("writer");
|
|
171
|
-
const writerID = getAgentID(getAgent(writer));
|
|
172
|
-
team.addMember(writerID, "writer");
|
|
173
|
-
expect(team.teamMap.get(writerID)).toEqual("writer");
|
|
174
|
-
const teamAsWriter = team.testWithDifferentCredentials(
|
|
175
|
-
writer,
|
|
176
|
-
newRandomSessionID(writerID)
|
|
177
|
-
);
|
|
178
|
-
expect(teamAsWriter.teamMap.get(writerID)).toEqual("writer");
|
|
179
|
-
const otherAgent = node.createAgent("otherAgent");
|
|
180
|
-
const otherAgentID = getAgentID(getAgent(otherAgent));
|
|
181
|
-
expect(() => teamAsWriter.addMember(otherAgentID, "admin")).toThrow(
|
|
182
|
-
"Failed to set role"
|
|
183
|
-
);
|
|
184
|
-
expect(() => teamAsWriter.addMember(otherAgentID, "writer")).toThrow(
|
|
185
|
-
"Failed to set role"
|
|
186
|
-
);
|
|
187
|
-
expect(() => teamAsWriter.addMember(otherAgentID, "reader")).toThrow(
|
|
188
|
-
"Failed to set role"
|
|
189
|
-
);
|
|
190
|
-
expect(teamAsWriter.teamMap.get(otherAgentID)).toBeUndefined();
|
|
191
|
-
});
|
|
192
|
-
test("Admins can add readers to a team, who can't add admins, writers, or readers", () => {
|
|
193
|
-
const { team, node } = newTeam();
|
|
194
|
-
const reader = node.createAgent("reader");
|
|
195
|
-
const readerID = getAgentID(getAgent(reader));
|
|
196
|
-
let teamContent = expectTeamContent(team.getCurrentContent());
|
|
197
|
-
teamContent.edit((editable) => {
|
|
198
|
-
editable.set(readerID, "reader", "trusting");
|
|
199
|
-
expect(editable.get(readerID)).toEqual("reader");
|
|
200
|
-
});
|
|
201
|
-
teamContent = expectTeamContent(team.getCurrentContent());
|
|
202
|
-
expect(teamContent.get(readerID)).toEqual("reader");
|
|
203
|
-
const teamAsReader = team.testWithDifferentCredentials(
|
|
204
|
-
reader,
|
|
205
|
-
newRandomSessionID(readerID)
|
|
206
|
-
);
|
|
207
|
-
let teamContentAsReader = expectTeamContent(
|
|
208
|
-
teamAsReader.getCurrentContent()
|
|
209
|
-
);
|
|
210
|
-
expect(teamContentAsReader.get(readerID)).toEqual("reader");
|
|
211
|
-
const otherAgent = node.createAgent("otherAgent");
|
|
212
|
-
const otherAgentID = getAgentID(getAgent(otherAgent));
|
|
213
|
-
teamContentAsReader.edit((editable) => {
|
|
214
|
-
editable.set(otherAgentID, "admin", "trusting");
|
|
215
|
-
expect(editable.get(otherAgentID)).toBeUndefined();
|
|
216
|
-
editable.set(otherAgentID, "writer", "trusting");
|
|
217
|
-
expect(editable.get(otherAgentID)).toBeUndefined();
|
|
218
|
-
editable.set(otherAgentID, "reader", "trusting");
|
|
219
|
-
expect(editable.get(otherAgentID)).toBeUndefined();
|
|
220
|
-
});
|
|
221
|
-
teamContentAsReader = expectTeamContent(teamAsReader.getCurrentContent());
|
|
222
|
-
expect(teamContentAsReader.get(otherAgentID)).toBeUndefined();
|
|
223
|
-
});
|
|
224
|
-
test("Admins can add readers to a team, who can't add admins, writers, or readers (high level)", () => {
|
|
225
|
-
const { team, node } = newTeamHighLevel();
|
|
226
|
-
const reader = node.createAgent("reader");
|
|
227
|
-
const readerID = getAgentID(getAgent(reader));
|
|
228
|
-
team.addMember(readerID, "reader");
|
|
229
|
-
expect(team.teamMap.get(readerID)).toEqual("reader");
|
|
230
|
-
const teamAsReader = team.testWithDifferentCredentials(
|
|
231
|
-
reader,
|
|
232
|
-
newRandomSessionID(readerID)
|
|
233
|
-
);
|
|
234
|
-
expect(teamAsReader.teamMap.get(readerID)).toEqual("reader");
|
|
235
|
-
const otherAgent = node.createAgent("otherAgent");
|
|
236
|
-
const otherAgentID = getAgentID(getAgent(otherAgent));
|
|
237
|
-
expect(() => teamAsReader.addMember(otherAgentID, "admin")).toThrow(
|
|
238
|
-
"Failed to set role"
|
|
239
|
-
);
|
|
240
|
-
expect(() => teamAsReader.addMember(otherAgentID, "writer")).toThrow(
|
|
241
|
-
"Failed to set role"
|
|
242
|
-
);
|
|
243
|
-
expect(() => teamAsReader.addMember(otherAgentID, "reader")).toThrow(
|
|
244
|
-
"Failed to set role"
|
|
245
|
-
);
|
|
246
|
-
expect(teamAsReader.teamMap.get(otherAgentID)).toBeUndefined();
|
|
247
|
-
});
|
|
248
|
-
test("Admins can write to an object that is owned by their team", () => {
|
|
249
|
-
const { node, team } = newTeam();
|
|
250
|
-
const childObject = node.createCoValue({
|
|
251
|
-
type: "comap",
|
|
252
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
253
|
-
meta: null,
|
|
254
|
-
...createdNowUnique(),
|
|
255
|
-
publicNickname: "childObject"
|
|
256
|
-
});
|
|
257
|
-
let childContent = expectMap(childObject.getCurrentContent());
|
|
258
|
-
childContent.edit((editable) => {
|
|
259
|
-
editable.set("foo", "bar", "trusting");
|
|
260
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
261
|
-
});
|
|
262
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
263
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
264
|
-
});
|
|
265
|
-
test("Admins can write to an object that is owned by their team (high level)", () => {
|
|
266
|
-
const { node, team } = newTeamHighLevel();
|
|
267
|
-
let childObject = team.createMap();
|
|
268
|
-
childObject = childObject.edit((editable) => {
|
|
269
|
-
editable.set("foo", "bar", "trusting");
|
|
270
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
271
|
-
});
|
|
272
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
273
|
-
});
|
|
274
|
-
test("Writers can write to an object that is owned by their team", () => {
|
|
275
|
-
const { node, team } = newTeam();
|
|
276
|
-
const writer = node.createAgent("writer");
|
|
277
|
-
const writerID = getAgentID(getAgent(writer));
|
|
278
|
-
expectTeamContent(team.getCurrentContent()).edit((editable) => {
|
|
279
|
-
editable.set(writerID, "writer", "trusting");
|
|
280
|
-
expect(editable.get(writerID)).toEqual("writer");
|
|
281
|
-
});
|
|
282
|
-
const childObject = node.createCoValue({
|
|
283
|
-
type: "comap",
|
|
284
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
285
|
-
meta: null,
|
|
286
|
-
...createdNowUnique(),
|
|
287
|
-
publicNickname: "childObject"
|
|
288
|
-
});
|
|
289
|
-
const childObjectAsWriter = childObject.testWithDifferentCredentials(
|
|
290
|
-
writer,
|
|
291
|
-
newRandomSessionID(writerID)
|
|
292
|
-
);
|
|
293
|
-
let childContentAsWriter = expectMap(
|
|
294
|
-
childObjectAsWriter.getCurrentContent()
|
|
295
|
-
);
|
|
296
|
-
childContentAsWriter.edit((editable) => {
|
|
297
|
-
editable.set("foo", "bar", "trusting");
|
|
298
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
299
|
-
});
|
|
300
|
-
childContentAsWriter = expectMap(childObjectAsWriter.getCurrentContent());
|
|
301
|
-
expect(childContentAsWriter.get("foo")).toEqual("bar");
|
|
302
|
-
});
|
|
303
|
-
test("Writers can write to an object that is owned by their team (high level)", () => {
|
|
304
|
-
const { node, team } = newTeamHighLevel();
|
|
305
|
-
const writer = node.createAgent("writer");
|
|
306
|
-
const writerID = getAgentID(getAgent(writer));
|
|
307
|
-
team.addMember(writerID, "writer");
|
|
308
|
-
const childObject = team.createMap();
|
|
309
|
-
let childObjectAsWriter = expectMap(
|
|
310
|
-
childObject.coValue.testWithDifferentCredentials(writer, newRandomSessionID(writerID)).getCurrentContent()
|
|
311
|
-
);
|
|
312
|
-
childObjectAsWriter = childObjectAsWriter.edit((editable) => {
|
|
313
|
-
editable.set("foo", "bar", "trusting");
|
|
314
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
315
|
-
});
|
|
316
|
-
expect(childObjectAsWriter.get("foo")).toEqual("bar");
|
|
317
|
-
});
|
|
318
|
-
test("Readers can not write to an object that is owned by their team", () => {
|
|
319
|
-
const { node, team } = newTeam();
|
|
320
|
-
const reader = node.createAgent("reader");
|
|
321
|
-
const readerID = getAgentID(getAgent(reader));
|
|
322
|
-
expectTeamContent(team.getCurrentContent()).edit((editable) => {
|
|
323
|
-
editable.set(readerID, "reader", "trusting");
|
|
324
|
-
expect(editable.get(readerID)).toEqual("reader");
|
|
325
|
-
});
|
|
326
|
-
const childObject = node.createCoValue({
|
|
327
|
-
type: "comap",
|
|
328
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
329
|
-
meta: null,
|
|
330
|
-
...createdNowUnique(),
|
|
331
|
-
publicNickname: "childObject"
|
|
332
|
-
});
|
|
333
|
-
const childObjectAsReader = childObject.testWithDifferentCredentials(
|
|
334
|
-
reader,
|
|
335
|
-
newRandomSessionID(readerID)
|
|
336
|
-
);
|
|
337
|
-
let childContentAsReader = expectMap(
|
|
338
|
-
childObjectAsReader.getCurrentContent()
|
|
339
|
-
);
|
|
340
|
-
childContentAsReader.edit((editable) => {
|
|
341
|
-
editable.set("foo", "bar", "trusting");
|
|
342
|
-
expect(editable.get("foo")).toBeUndefined();
|
|
343
|
-
});
|
|
344
|
-
childContentAsReader = expectMap(childObjectAsReader.getCurrentContent());
|
|
345
|
-
expect(childContentAsReader.get("foo")).toBeUndefined();
|
|
346
|
-
});
|
|
347
|
-
test("Readers can not write to an object that is owned by their team (high level)", () => {
|
|
348
|
-
const { node, team } = newTeamHighLevel();
|
|
349
|
-
const reader = node.createAgent("reader");
|
|
350
|
-
const readerID = getAgentID(getAgent(reader));
|
|
351
|
-
team.addMember(readerID, "reader");
|
|
352
|
-
const childObject = team.createMap();
|
|
353
|
-
let childObjectAsReader = expectMap(
|
|
354
|
-
childObject.coValue.testWithDifferentCredentials(reader, newRandomSessionID(readerID)).getCurrentContent()
|
|
355
|
-
);
|
|
356
|
-
childObjectAsReader = childObjectAsReader.edit((editable) => {
|
|
357
|
-
editable.set("foo", "bar", "trusting");
|
|
358
|
-
expect(editable.get("foo")).toBeUndefined();
|
|
359
|
-
});
|
|
360
|
-
expect(childObjectAsReader.get("foo")).toBeUndefined();
|
|
361
|
-
});
|
|
362
|
-
test("Admins can set team read key and then use it to create and read private transactions in owned objects", () => {
|
|
363
|
-
const { node, team, admin, adminID } = newTeam();
|
|
364
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
365
|
-
teamContent.edit((editable) => {
|
|
366
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
367
|
-
const revelation = seal(
|
|
368
|
-
readKey,
|
|
369
|
-
admin.recipientSecret,
|
|
370
|
-
/* @__PURE__ */ new Set([getRecipientID(admin.recipientSecret)]),
|
|
371
|
-
{
|
|
372
|
-
in: team.id,
|
|
373
|
-
tx: team.nextTransactionID()
|
|
374
|
-
}
|
|
375
|
-
);
|
|
376
|
-
editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
|
|
377
|
-
expect(editable.get("readKey")).toEqual({
|
|
378
|
-
keyID: readKeyID,
|
|
379
|
-
revelation
|
|
380
|
-
});
|
|
381
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey);
|
|
382
|
-
});
|
|
383
|
-
const childObject = node.createCoValue({
|
|
384
|
-
type: "comap",
|
|
385
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
386
|
-
meta: null,
|
|
387
|
-
...createdNowUnique(),
|
|
388
|
-
publicNickname: "childObject"
|
|
389
|
-
});
|
|
390
|
-
let childContent = expectMap(childObject.getCurrentContent());
|
|
391
|
-
childContent.edit((editable) => {
|
|
392
|
-
editable.set("foo", "bar", "private");
|
|
393
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
394
|
-
});
|
|
395
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
396
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
397
|
-
});
|
|
398
|
-
test("Admins can set team read key and then use it to create and read private transactions in owned objects (high level)", () => {
|
|
399
|
-
const { node, team, admin } = newTeamHighLevel();
|
|
400
|
-
let childObject = team.createMap();
|
|
401
|
-
childObject = childObject.edit((editable) => {
|
|
402
|
-
editable.set("foo", "bar", "private");
|
|
403
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
404
|
-
});
|
|
405
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
406
|
-
});
|
|
407
|
-
test("Admins can set team read key and then writers can use it to create and read private transactions in owned objects", () => {
|
|
408
|
-
const { node, team, admin } = newTeam();
|
|
409
|
-
const writer = node.createAgent("writer");
|
|
410
|
-
const writerID = getAgentID(getAgent(writer));
|
|
411
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
412
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
413
|
-
teamContent.edit((editable) => {
|
|
414
|
-
editable.set(writerID, "writer", "trusting");
|
|
415
|
-
expect(editable.get(writerID)).toEqual("writer");
|
|
416
|
-
const revelation = seal(
|
|
417
|
-
readKey,
|
|
418
|
-
admin.recipientSecret,
|
|
419
|
-
/* @__PURE__ */ new Set([
|
|
420
|
-
getRecipientID(admin.recipientSecret),
|
|
421
|
-
getRecipientID(writer.recipientSecret)
|
|
422
|
-
]),
|
|
423
|
-
{
|
|
424
|
-
in: team.id,
|
|
425
|
-
tx: team.nextTransactionID()
|
|
426
|
-
}
|
|
427
|
-
);
|
|
428
|
-
editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
|
|
429
|
-
});
|
|
430
|
-
const childObject = node.createCoValue({
|
|
431
|
-
type: "comap",
|
|
432
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
433
|
-
meta: null,
|
|
434
|
-
...createdNowUnique(),
|
|
435
|
-
publicNickname: "childObject"
|
|
436
|
-
});
|
|
437
|
-
const childObjectAsWriter = childObject.testWithDifferentCredentials(
|
|
438
|
-
writer,
|
|
439
|
-
newRandomSessionID(writerID)
|
|
440
|
-
);
|
|
441
|
-
expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
|
|
442
|
-
let childContentAsWriter = expectMap(
|
|
443
|
-
childObjectAsWriter.getCurrentContent()
|
|
444
|
-
);
|
|
445
|
-
childContentAsWriter.edit((editable) => {
|
|
446
|
-
editable.set("foo", "bar", "private");
|
|
447
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
448
|
-
});
|
|
449
|
-
childContentAsWriter = expectMap(childObjectAsWriter.getCurrentContent());
|
|
450
|
-
expect(childContentAsWriter.get("foo")).toEqual("bar");
|
|
451
|
-
});
|
|
452
|
-
test("Admins can set team read key and then writers can use it to create and read private transactions in owned objects (high level)", () => {
|
|
453
|
-
const { node, team, admin } = newTeamHighLevel();
|
|
454
|
-
const writer = node.createAgent("writer");
|
|
455
|
-
const writerID = getAgentID(getAgent(writer));
|
|
456
|
-
team.addMember(writerID, "writer");
|
|
457
|
-
const childObject = team.createMap();
|
|
458
|
-
let childObjectAsWriter = expectMap(
|
|
459
|
-
childObject.coValue.testWithDifferentCredentials(writer, newRandomSessionID(writerID)).getCurrentContent()
|
|
460
|
-
);
|
|
461
|
-
childObjectAsWriter = childObjectAsWriter.edit((editable) => {
|
|
462
|
-
editable.set("foo", "bar", "private");
|
|
463
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
464
|
-
});
|
|
465
|
-
expect(childObjectAsWriter.get("foo")).toEqual("bar");
|
|
466
|
-
});
|
|
467
|
-
test("Admins can set team read key and then use it to create private transactions in owned objects, which readers can read", () => {
|
|
468
|
-
const { node, team, admin } = newTeam();
|
|
469
|
-
const reader = node.createAgent("reader");
|
|
470
|
-
const readerID = getAgentID(getAgent(reader));
|
|
471
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
472
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
473
|
-
teamContent.edit((editable) => {
|
|
474
|
-
editable.set(readerID, "reader", "trusting");
|
|
475
|
-
expect(editable.get(readerID)).toEqual("reader");
|
|
476
|
-
const revelation = seal(
|
|
477
|
-
readKey,
|
|
478
|
-
admin.recipientSecret,
|
|
479
|
-
/* @__PURE__ */ new Set([
|
|
480
|
-
getRecipientID(admin.recipientSecret),
|
|
481
|
-
getRecipientID(reader.recipientSecret)
|
|
482
|
-
]),
|
|
483
|
-
{
|
|
484
|
-
in: team.id,
|
|
485
|
-
tx: team.nextTransactionID()
|
|
486
|
-
}
|
|
487
|
-
);
|
|
488
|
-
editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
|
|
489
|
-
});
|
|
490
|
-
const childObject = node.createCoValue({
|
|
491
|
-
type: "comap",
|
|
492
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
493
|
-
meta: null,
|
|
494
|
-
...createdNowUnique(),
|
|
495
|
-
publicNickname: "childObject"
|
|
496
|
-
});
|
|
497
|
-
expectMap(childObject.getCurrentContent()).edit((editable) => {
|
|
498
|
-
editable.set("foo", "bar", "private");
|
|
499
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
500
|
-
});
|
|
501
|
-
const childObjectAsReader = childObject.testWithDifferentCredentials(
|
|
502
|
-
reader,
|
|
503
|
-
newRandomSessionID(readerID)
|
|
504
|
-
);
|
|
505
|
-
expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
|
|
506
|
-
const childContentAsReader = expectMap(
|
|
507
|
-
childObjectAsReader.getCurrentContent()
|
|
508
|
-
);
|
|
509
|
-
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
510
|
-
});
|
|
511
|
-
test("Admins can set team read key and then use it to create private transactions in owned objects, which readers can read (high level)", () => {
|
|
512
|
-
const { node, team, admin } = newTeamHighLevel();
|
|
513
|
-
const reader = node.createAgent("reader");
|
|
514
|
-
const readerID = getAgentID(getAgent(reader));
|
|
515
|
-
team.addMember(readerID, "reader");
|
|
516
|
-
let childObject = team.createMap();
|
|
517
|
-
childObject = childObject.edit((editable) => {
|
|
518
|
-
editable.set("foo", "bar", "private");
|
|
519
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
520
|
-
});
|
|
521
|
-
const childContentAsReader = expectMap(
|
|
522
|
-
childObject.coValue.testWithDifferentCredentials(reader, newRandomSessionID(readerID)).getCurrentContent()
|
|
523
|
-
);
|
|
524
|
-
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
525
|
-
});
|
|
526
|
-
test("Admins can set team 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", () => {
|
|
527
|
-
const { node, team, admin } = newTeam();
|
|
528
|
-
const reader1 = node.createAgent("reader1");
|
|
529
|
-
const reader1ID = getAgentID(getAgent(reader1));
|
|
530
|
-
const reader2 = node.createAgent("reader2");
|
|
531
|
-
const reader2ID = getAgentID(getAgent(reader2));
|
|
532
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
533
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
534
|
-
teamContent.edit((editable) => {
|
|
535
|
-
editable.set(reader1ID, "reader", "trusting");
|
|
536
|
-
expect(editable.get(reader1ID)).toEqual("reader");
|
|
537
|
-
const revelation1 = seal(
|
|
538
|
-
readKey,
|
|
539
|
-
admin.recipientSecret,
|
|
540
|
-
/* @__PURE__ */ new Set([
|
|
541
|
-
getRecipientID(admin.recipientSecret),
|
|
542
|
-
getRecipientID(reader1.recipientSecret)
|
|
543
|
-
]),
|
|
544
|
-
{
|
|
545
|
-
in: team.id,
|
|
546
|
-
tx: team.nextTransactionID()
|
|
547
|
-
}
|
|
548
|
-
);
|
|
549
|
-
editable.set(
|
|
550
|
-
"readKey",
|
|
551
|
-
{ keyID: readKeyID, revelation: revelation1 },
|
|
552
|
-
"trusting"
|
|
553
|
-
);
|
|
554
|
-
const revelation2 = seal(
|
|
555
|
-
readKey,
|
|
556
|
-
admin.recipientSecret,
|
|
557
|
-
/* @__PURE__ */ new Set([getRecipientID(reader2.recipientSecret)]),
|
|
558
|
-
{
|
|
559
|
-
in: team.id,
|
|
560
|
-
tx: team.nextTransactionID()
|
|
561
|
-
}
|
|
562
|
-
);
|
|
563
|
-
editable.set(
|
|
564
|
-
"readKey",
|
|
565
|
-
{ keyID: readKeyID, revelation: revelation2 },
|
|
566
|
-
"trusting"
|
|
567
|
-
);
|
|
568
|
-
});
|
|
569
|
-
const childObject = node.createCoValue({
|
|
570
|
-
type: "comap",
|
|
571
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
572
|
-
meta: null,
|
|
573
|
-
...createdNowUnique(),
|
|
574
|
-
publicNickname: "childObject"
|
|
575
|
-
});
|
|
576
|
-
expectMap(childObject.getCurrentContent()).edit((editable) => {
|
|
577
|
-
editable.set("foo", "bar", "private");
|
|
578
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
579
|
-
});
|
|
580
|
-
const childObjectAsReader1 = childObject.testWithDifferentCredentials(
|
|
581
|
-
reader1,
|
|
582
|
-
newRandomSessionID(reader1ID)
|
|
583
|
-
);
|
|
584
|
-
expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
|
|
585
|
-
const childContentAsReader1 = expectMap(
|
|
586
|
-
childObjectAsReader1.getCurrentContent()
|
|
587
|
-
);
|
|
588
|
-
expect(childContentAsReader1.get("foo")).toEqual("bar");
|
|
589
|
-
const childObjectAsReader2 = childObject.testWithDifferentCredentials(
|
|
590
|
-
reader2,
|
|
591
|
-
newRandomSessionID(reader2ID)
|
|
592
|
-
);
|
|
593
|
-
expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
|
|
594
|
-
const childContentAsReader2 = expectMap(
|
|
595
|
-
childObjectAsReader2.getCurrentContent()
|
|
596
|
-
);
|
|
597
|
-
expect(childContentAsReader2.get("foo")).toEqual("bar");
|
|
598
|
-
});
|
|
599
|
-
test("Admins can set team 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)", () => {
|
|
600
|
-
const { node, team, admin } = newTeamHighLevel();
|
|
601
|
-
const reader1 = node.createAgent("reader1");
|
|
602
|
-
const reader1ID = getAgentID(getAgent(reader1));
|
|
603
|
-
const reader2 = node.createAgent("reader2");
|
|
604
|
-
const reader2ID = getAgentID(getAgent(reader2));
|
|
605
|
-
team.addMember(reader1ID, "reader");
|
|
606
|
-
let childObject = team.createMap();
|
|
607
|
-
childObject = childObject.edit((editable) => {
|
|
608
|
-
editable.set("foo", "bar", "private");
|
|
609
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
610
|
-
});
|
|
611
|
-
const childContentAsReader1 = expectMap(
|
|
612
|
-
childObject.coValue.testWithDifferentCredentials(
|
|
613
|
-
reader1,
|
|
614
|
-
newRandomSessionID(reader1ID)
|
|
615
|
-
).getCurrentContent()
|
|
616
|
-
);
|
|
617
|
-
expect(childContentAsReader1.get("foo")).toEqual("bar");
|
|
618
|
-
team.addMember(reader2ID, "reader");
|
|
619
|
-
const childContentAsReader2 = expectMap(
|
|
620
|
-
childObject.coValue.testWithDifferentCredentials(
|
|
621
|
-
reader2,
|
|
622
|
-
newRandomSessionID(reader2ID)
|
|
623
|
-
).getCurrentContent()
|
|
624
|
-
);
|
|
625
|
-
expect(childContentAsReader2.get("foo")).toEqual("bar");
|
|
626
|
-
});
|
|
627
|
-
test("Admins can set team 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", () => {
|
|
628
|
-
const { node, team, admin, adminID } = newTeam();
|
|
629
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
630
|
-
teamContent.edit((editable) => {
|
|
631
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
632
|
-
const revelation = seal(
|
|
633
|
-
readKey,
|
|
634
|
-
admin.recipientSecret,
|
|
635
|
-
/* @__PURE__ */ new Set([getRecipientID(admin.recipientSecret)]),
|
|
636
|
-
{
|
|
637
|
-
in: team.id,
|
|
638
|
-
tx: team.nextTransactionID()
|
|
639
|
-
}
|
|
640
|
-
);
|
|
641
|
-
editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
|
|
642
|
-
expect(editable.get("readKey")).toEqual({
|
|
643
|
-
keyID: readKeyID,
|
|
644
|
-
revelation
|
|
645
|
-
});
|
|
646
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey);
|
|
647
|
-
});
|
|
648
|
-
const childObject = node.createCoValue({
|
|
649
|
-
type: "comap",
|
|
650
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
651
|
-
meta: null,
|
|
652
|
-
...createdNowUnique(),
|
|
653
|
-
publicNickname: "childObject"
|
|
654
|
-
});
|
|
655
|
-
let childContent = expectMap(childObject.getCurrentContent());
|
|
656
|
-
childContent.edit((editable) => {
|
|
657
|
-
editable.set("foo", "bar", "private");
|
|
658
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
659
|
-
});
|
|
660
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
661
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
662
|
-
teamContent.edit((editable) => {
|
|
663
|
-
const { secret: readKey2, id: readKeyID2 } = newRandomKeySecret();
|
|
664
|
-
const revelation = seal(
|
|
665
|
-
readKey2,
|
|
666
|
-
admin.recipientSecret,
|
|
667
|
-
/* @__PURE__ */ new Set([getRecipientID(admin.recipientSecret)]),
|
|
668
|
-
{
|
|
669
|
-
in: team.id,
|
|
670
|
-
tx: team.nextTransactionID()
|
|
671
|
-
}
|
|
672
|
-
);
|
|
673
|
-
editable.set("readKey", { keyID: readKeyID2, revelation }, "trusting");
|
|
674
|
-
expect(editable.get("readKey")).toEqual({
|
|
675
|
-
keyID: readKeyID2,
|
|
676
|
-
revelation
|
|
677
|
-
});
|
|
678
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey2);
|
|
679
|
-
});
|
|
680
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
681
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
682
|
-
childContent.edit((editable) => {
|
|
683
|
-
editable.set("foo2", "bar2", "private");
|
|
684
|
-
expect(editable.get("foo2")).toEqual("bar2");
|
|
685
|
-
});
|
|
686
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
687
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
688
|
-
expect(childContent.get("foo2")).toEqual("bar2");
|
|
689
|
-
});
|
|
690
|
-
test("Admins can set team 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)", () => {
|
|
691
|
-
const { node, team, admin, adminID } = newTeamHighLevel();
|
|
692
|
-
let childObject = team.createMap();
|
|
693
|
-
const firstReadKey = childObject.coValue.getCurrentReadKey();
|
|
694
|
-
childObject = childObject.edit((editable) => {
|
|
695
|
-
editable.set("foo", "bar", "private");
|
|
696
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
697
|
-
});
|
|
698
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
699
|
-
team.rotateReadKey();
|
|
700
|
-
expect(childObject.coValue.getCurrentReadKey()).not.toEqual(firstReadKey);
|
|
701
|
-
childObject = childObject.edit((editable) => {
|
|
702
|
-
editable.set("foo2", "bar2", "private");
|
|
703
|
-
expect(editable.get("foo2")).toEqual("bar2");
|
|
704
|
-
});
|
|
705
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
706
|
-
expect(childObject.get("foo2")).toEqual("bar2");
|
|
707
|
-
});
|
|
708
|
-
test("Admins can set team 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", () => {
|
|
709
|
-
const { node, team, admin, adminID } = newTeam();
|
|
710
|
-
const childObject = node.createCoValue({
|
|
711
|
-
type: "comap",
|
|
712
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
713
|
-
meta: null,
|
|
714
|
-
...createdNowUnique(),
|
|
715
|
-
publicNickname: "childObject"
|
|
716
|
-
});
|
|
717
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
718
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
719
|
-
teamContent.edit((editable) => {
|
|
720
|
-
const revelation = seal(
|
|
721
|
-
readKey,
|
|
722
|
-
admin.recipientSecret,
|
|
723
|
-
/* @__PURE__ */ new Set([getRecipientID(admin.recipientSecret)]),
|
|
724
|
-
{
|
|
725
|
-
in: team.id,
|
|
726
|
-
tx: team.nextTransactionID()
|
|
727
|
-
}
|
|
728
|
-
);
|
|
729
|
-
editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
|
|
730
|
-
expect(editable.get("readKey")).toEqual({
|
|
731
|
-
keyID: readKeyID,
|
|
732
|
-
revelation
|
|
733
|
-
});
|
|
734
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey);
|
|
735
|
-
});
|
|
736
|
-
let childContent = expectMap(childObject.getCurrentContent());
|
|
737
|
-
childContent.edit((editable) => {
|
|
738
|
-
editable.set("foo", "bar", "private");
|
|
739
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
740
|
-
});
|
|
741
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
742
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
743
|
-
const reader = node.createAgent("reader");
|
|
744
|
-
const readerID = getAgentID(getAgent(reader));
|
|
745
|
-
const { secret: readKey2, id: readKeyID2 } = newRandomKeySecret();
|
|
746
|
-
teamContent.edit((editable) => {
|
|
747
|
-
const revelation = seal(
|
|
748
|
-
readKey2,
|
|
749
|
-
admin.recipientSecret,
|
|
750
|
-
/* @__PURE__ */ new Set([
|
|
751
|
-
getRecipientID(admin.recipientSecret),
|
|
752
|
-
getRecipientID(reader.recipientSecret)
|
|
753
|
-
]),
|
|
754
|
-
{
|
|
755
|
-
in: team.id,
|
|
756
|
-
tx: team.nextTransactionID()
|
|
757
|
-
}
|
|
758
|
-
);
|
|
759
|
-
editable.set(
|
|
760
|
-
"readKey",
|
|
761
|
-
{
|
|
762
|
-
keyID: readKeyID2,
|
|
763
|
-
revelation,
|
|
764
|
-
previousKeys: {
|
|
765
|
-
[readKeyID]: sealKeySecret({
|
|
766
|
-
toSeal: { id: readKeyID, secret: readKey },
|
|
767
|
-
sealing: { id: readKeyID2, secret: readKey2 }
|
|
768
|
-
}).encrypted
|
|
769
|
-
}
|
|
770
|
-
},
|
|
771
|
-
"trusting"
|
|
772
|
-
);
|
|
773
|
-
expect(editable.get("readKey")).toMatchObject({
|
|
774
|
-
keyID: readKeyID2,
|
|
775
|
-
revelation
|
|
776
|
-
});
|
|
777
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey2);
|
|
778
|
-
editable.set(readerID, "reader", "trusting");
|
|
779
|
-
expect(editable.get(readerID)).toEqual("reader");
|
|
780
|
-
});
|
|
781
|
-
childContent.edit((editable) => {
|
|
782
|
-
editable.set("foo2", "bar2", "private");
|
|
783
|
-
expect(editable.get("foo2")).toEqual("bar2");
|
|
784
|
-
});
|
|
785
|
-
const childObjectAsReader = childObject.testWithDifferentCredentials(
|
|
786
|
-
reader,
|
|
787
|
-
newRandomSessionID(readerID)
|
|
788
|
-
);
|
|
789
|
-
expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
|
|
790
|
-
const childContentAsReader = expectMap(
|
|
791
|
-
childObjectAsReader.getCurrentContent()
|
|
792
|
-
);
|
|
793
|
-
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
794
|
-
expect(childContentAsReader.get("foo2")).toEqual("bar2");
|
|
795
|
-
});
|
|
796
|
-
test("Admins can set team 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)", () => {
|
|
797
|
-
const { node, team, admin, adminID } = newTeamHighLevel();
|
|
798
|
-
let childObject = team.createMap();
|
|
799
|
-
const firstReadKey = childObject.coValue.getCurrentReadKey();
|
|
800
|
-
childObject = childObject.edit((editable) => {
|
|
801
|
-
editable.set("foo", "bar", "private");
|
|
802
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
803
|
-
});
|
|
804
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
805
|
-
team.rotateReadKey();
|
|
806
|
-
expect(childObject.coValue.getCurrentReadKey()).not.toEqual(firstReadKey);
|
|
807
|
-
const reader = node.createAgent("reader");
|
|
808
|
-
const readerID = getAgentID(getAgent(reader));
|
|
809
|
-
team.addMember(readerID, "reader");
|
|
810
|
-
childObject = childObject.edit((editable) => {
|
|
811
|
-
editable.set("foo2", "bar2", "private");
|
|
812
|
-
expect(editable.get("foo2")).toEqual("bar2");
|
|
813
|
-
});
|
|
814
|
-
const childContentAsReader = expectMap(
|
|
815
|
-
childObject.coValue.testWithDifferentCredentials(reader, newRandomSessionID(readerID)).getCurrentContent()
|
|
816
|
-
);
|
|
817
|
-
expect(childContentAsReader.get("foo")).toEqual("bar");
|
|
818
|
-
expect(childContentAsReader.get("foo2")).toEqual("bar2");
|
|
819
|
-
});
|
|
820
|
-
test("Admins can set team 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", () => {
|
|
821
|
-
const { node, team, admin, adminID } = newTeam();
|
|
822
|
-
const childObject = node.createCoValue({
|
|
823
|
-
type: "comap",
|
|
824
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
825
|
-
meta: null,
|
|
826
|
-
...createdNowUnique(),
|
|
827
|
-
publicNickname: "childObject"
|
|
828
|
-
});
|
|
829
|
-
const teamContent = expectTeamContent(team.getCurrentContent());
|
|
830
|
-
const { secret: readKey, id: readKeyID } = newRandomKeySecret();
|
|
831
|
-
const reader = node.createAgent("reader");
|
|
832
|
-
const readerID = getAgentID(getAgent(reader));
|
|
833
|
-
const reader2 = node.createAgent("reader2");
|
|
834
|
-
const reader2ID = getAgentID(getAgent(reader));
|
|
835
|
-
teamContent.edit((editable) => {
|
|
836
|
-
const revelation = seal(
|
|
837
|
-
readKey,
|
|
838
|
-
admin.recipientSecret,
|
|
839
|
-
/* @__PURE__ */ new Set([
|
|
840
|
-
getRecipientID(admin.recipientSecret),
|
|
841
|
-
getRecipientID(reader.recipientSecret),
|
|
842
|
-
getRecipientID(reader2.recipientSecret)
|
|
843
|
-
]),
|
|
844
|
-
{
|
|
845
|
-
in: team.id,
|
|
846
|
-
tx: team.nextTransactionID()
|
|
847
|
-
}
|
|
848
|
-
);
|
|
849
|
-
editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
|
|
850
|
-
expect(editable.get("readKey")).toEqual({
|
|
851
|
-
keyID: readKeyID,
|
|
852
|
-
revelation
|
|
853
|
-
});
|
|
854
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey);
|
|
855
|
-
editable.set(readerID, "reader", "trusting");
|
|
856
|
-
expect(editable.get(readerID)).toEqual("reader");
|
|
857
|
-
editable.set(reader2ID, "reader", "trusting");
|
|
858
|
-
expect(editable.get(reader2ID)).toEqual("reader");
|
|
859
|
-
});
|
|
860
|
-
let childContent = expectMap(childObject.getCurrentContent());
|
|
861
|
-
childContent.edit((editable) => {
|
|
862
|
-
editable.set("foo", "bar", "private");
|
|
863
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
864
|
-
});
|
|
865
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
866
|
-
expect(childContent.get("foo")).toEqual("bar");
|
|
867
|
-
let childObjectAsReader = childObject.testWithDifferentCredentials(
|
|
868
|
-
reader,
|
|
869
|
-
newRandomSessionID(readerID)
|
|
870
|
-
);
|
|
871
|
-
expect(
|
|
872
|
-
expectMap(childObjectAsReader.getCurrentContent()).get("foo")
|
|
873
|
-
).toEqual("bar");
|
|
874
|
-
let childObjectAsReader2 = childObject.testWithDifferentCredentials(
|
|
875
|
-
reader,
|
|
876
|
-
newRandomSessionID(readerID)
|
|
877
|
-
);
|
|
878
|
-
expect(
|
|
879
|
-
expectMap(childObjectAsReader2.getCurrentContent()).get("foo")
|
|
880
|
-
).toEqual("bar");
|
|
881
|
-
const { secret: readKey2, id: readKeyID2 } = newRandomKeySecret();
|
|
882
|
-
teamContent.edit((editable) => {
|
|
883
|
-
const revelation = seal(
|
|
884
|
-
readKey2,
|
|
885
|
-
admin.recipientSecret,
|
|
886
|
-
/* @__PURE__ */ new Set([
|
|
887
|
-
getRecipientID(admin.recipientSecret),
|
|
888
|
-
getRecipientID(reader2.recipientSecret)
|
|
889
|
-
]),
|
|
890
|
-
{
|
|
891
|
-
in: team.id,
|
|
892
|
-
tx: team.nextTransactionID()
|
|
893
|
-
}
|
|
894
|
-
);
|
|
895
|
-
editable.set("readKey", { keyID: readKeyID2, revelation }, "trusting");
|
|
896
|
-
expect(editable.get("readKey")).toEqual({
|
|
897
|
-
keyID: readKeyID2,
|
|
898
|
-
revelation
|
|
899
|
-
});
|
|
900
|
-
expect(team.getCurrentReadKey().secret).toEqual(readKey2);
|
|
901
|
-
editable.set(readerID, "revoked", "trusting");
|
|
902
|
-
});
|
|
903
|
-
expect(childObject.getCurrentReadKey().secret).toEqual(readKey2);
|
|
904
|
-
childContent = expectMap(childObject.getCurrentContent());
|
|
905
|
-
childContent.edit((editable) => {
|
|
906
|
-
editable.set("foo2", "bar2", "private");
|
|
907
|
-
expect(editable.get("foo2")).toEqual("bar2");
|
|
908
|
-
});
|
|
909
|
-
childObjectAsReader = childObject.testWithDifferentCredentials(
|
|
910
|
-
reader,
|
|
911
|
-
newRandomSessionID(readerID)
|
|
912
|
-
);
|
|
913
|
-
childObjectAsReader2 = childObject.testWithDifferentCredentials(
|
|
914
|
-
reader2,
|
|
915
|
-
newRandomSessionID(reader2ID)
|
|
916
|
-
);
|
|
917
|
-
expect(
|
|
918
|
-
expectMap(childObjectAsReader.getCurrentContent()).get("foo2")
|
|
919
|
-
).toBeUndefined();
|
|
920
|
-
expect(
|
|
921
|
-
expectMap(childObjectAsReader2.getCurrentContent()).get("foo2")
|
|
922
|
-
).toEqual("bar2");
|
|
923
|
-
});
|
|
924
|
-
test("Admins can set team 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)", () => {
|
|
925
|
-
const { node, team, admin, adminID } = newTeamHighLevel();
|
|
926
|
-
let childObject = team.createMap();
|
|
927
|
-
childObject = childObject.edit((editable) => {
|
|
928
|
-
editable.set("foo", "bar", "private");
|
|
929
|
-
expect(editable.get("foo")).toEqual("bar");
|
|
930
|
-
});
|
|
931
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
932
|
-
team.rotateReadKey();
|
|
933
|
-
const secondReadKey = childObject.coValue.getCurrentReadKey();
|
|
934
|
-
const reader = node.createAgent("reader");
|
|
935
|
-
const readerID = getAgentID(getAgent(reader));
|
|
936
|
-
const reader2 = node.createAgent("reader2");
|
|
937
|
-
const reader2ID = getAgentID(getAgent(reader2));
|
|
938
|
-
team.addMember(readerID, "reader");
|
|
939
|
-
team.addMember(reader2ID, "reader");
|
|
940
|
-
childObject = childObject.edit((editable) => {
|
|
941
|
-
editable.set("foo2", "bar2", "private");
|
|
942
|
-
expect(editable.get("foo2")).toEqual("bar2");
|
|
943
|
-
});
|
|
944
|
-
expect(childObject.get("foo")).toEqual("bar");
|
|
945
|
-
expect(childObject.get("foo2")).toEqual("bar2");
|
|
946
|
-
team.removeMember(readerID);
|
|
947
|
-
expect(childObject.coValue.getCurrentReadKey()).not.toEqual(secondReadKey);
|
|
948
|
-
childObject = childObject.edit((editable) => {
|
|
949
|
-
editable.set("foo3", "bar3", "private");
|
|
950
|
-
expect(editable.get("foo3")).toEqual("bar3");
|
|
951
|
-
});
|
|
952
|
-
const childContentAsReader2 = expectMap(
|
|
953
|
-
childObject.coValue.testWithDifferentCredentials(
|
|
954
|
-
reader2,
|
|
955
|
-
newRandomSessionID(reader2ID)
|
|
956
|
-
).getCurrentContent()
|
|
957
|
-
);
|
|
958
|
-
expect(childContentAsReader2.get("foo")).toEqual("bar");
|
|
959
|
-
expect(childContentAsReader2.get("foo2")).toEqual("bar2");
|
|
960
|
-
expect(childContentAsReader2.get("foo3")).toEqual("bar3");
|
|
961
|
-
expect(
|
|
962
|
-
expectMap(
|
|
963
|
-
childObject.coValue.testWithDifferentCredentials(
|
|
964
|
-
reader,
|
|
965
|
-
newRandomSessionID(readerID)
|
|
966
|
-
).getCurrentContent()
|
|
967
|
-
).get("foo3")
|
|
968
|
-
).toBeUndefined();
|
|
969
|
-
});
|
|
970
|
-
test("Can create two owned objects in the same team and they will have different ids", () => {
|
|
971
|
-
const { node, team, admin, adminID } = newTeam();
|
|
972
|
-
const childObject1 = node.createCoValue({
|
|
973
|
-
type: "comap",
|
|
974
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
975
|
-
meta: null,
|
|
976
|
-
...createdNowUnique()
|
|
977
|
-
});
|
|
978
|
-
const childObject2 = node.createCoValue({
|
|
979
|
-
type: "comap",
|
|
980
|
-
ruleset: { type: "ownedByTeam", team: team.id },
|
|
981
|
-
meta: null,
|
|
982
|
-
...createdNowUnique()
|
|
983
|
-
});
|
|
984
|
-
expect(childObject1.id).not.toEqual(childObject2.id);
|
|
985
|
-
});
|