cojson 0.0.11 → 0.0.12

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.
Files changed (75) hide show
  1. package/README.md +2 -2
  2. package/dist/account.d.ts +57 -0
  3. package/dist/account.js +76 -0
  4. package/dist/account.js.map +1 -0
  5. package/dist/account.test.d.ts +1 -0
  6. package/dist/account.test.js +40 -0
  7. package/dist/account.test.js.map +1 -0
  8. package/dist/coValue.d.ts +16 -35
  9. package/dist/coValue.js +49 -112
  10. package/dist/coValue.js.map +1 -1
  11. package/dist/coValue.test.js +16 -16
  12. package/dist/coValue.test.js.map +1 -1
  13. package/dist/contentType.d.ts +9 -9
  14. package/dist/contentType.js.map +1 -1
  15. package/dist/contentType.test.js +13 -17
  16. package/dist/contentType.test.js.map +1 -1
  17. package/dist/contentTypes/coList.d.ts +3 -3
  18. package/dist/contentTypes/coList.js.map +1 -1
  19. package/dist/contentTypes/coMap.d.ts +31 -21
  20. package/dist/contentTypes/coMap.js +28 -0
  21. package/dist/contentTypes/coMap.js.map +1 -1
  22. package/dist/contentTypes/coStream.d.ts +3 -3
  23. package/dist/contentTypes/coStream.js.map +1 -1
  24. package/dist/contentTypes/static.d.ts +4 -4
  25. package/dist/contentTypes/static.js.map +1 -1
  26. package/dist/crypto.d.ts +45 -39
  27. package/dist/crypto.js +68 -49
  28. package/dist/crypto.js.map +1 -1
  29. package/dist/crypto.test.js +45 -49
  30. package/dist/crypto.test.js.map +1 -1
  31. package/dist/ids.d.ts +5 -3
  32. package/dist/ids.js +3 -1
  33. package/dist/ids.js.map +1 -1
  34. package/dist/index.d.ts +12 -14
  35. package/dist/index.js +6 -8
  36. package/dist/index.js.map +1 -1
  37. package/dist/jsonValue.d.ts +2 -2
  38. package/dist/node.d.ts +25 -15
  39. package/dist/node.js +88 -33
  40. package/dist/node.js.map +1 -1
  41. package/dist/permissions.d.ts +27 -33
  42. package/dist/permissions.js +55 -47
  43. package/dist/permissions.js.map +1 -1
  44. package/dist/permissions.test.js +231 -314
  45. package/dist/permissions.test.js.map +1 -1
  46. package/dist/sync.d.ts +26 -28
  47. package/dist/sync.js +67 -63
  48. package/dist/sync.js.map +1 -1
  49. package/dist/sync.test.js +181 -298
  50. package/dist/sync.test.js.map +1 -1
  51. package/dist/testUtils.d.ts +37 -0
  52. package/dist/testUtils.js +157 -0
  53. package/dist/testUtils.js.map +1 -0
  54. package/package.json +1 -1
  55. package/src/account.test.ts +67 -0
  56. package/src/account.ts +152 -0
  57. package/src/coValue.test.ts +17 -31
  58. package/src/coValue.ts +93 -179
  59. package/src/contentType.test.ts +18 -45
  60. package/src/contentType.ts +15 -13
  61. package/src/contentTypes/coList.ts +4 -4
  62. package/src/contentTypes/coMap.ts +55 -29
  63. package/src/contentTypes/coStream.ts +4 -4
  64. package/src/contentTypes/static.ts +5 -5
  65. package/src/crypto.test.ts +53 -59
  66. package/src/crypto.ts +123 -95
  67. package/src/ids.ts +9 -3
  68. package/src/index.ts +14 -25
  69. package/src/jsonValue.ts +2 -2
  70. package/src/node.ts +189 -61
  71. package/src/permissions.test.ts +370 -404
  72. package/src/permissions.ts +126 -109
  73. package/src/sync.test.ts +258 -432
  74. package/src/sync.ts +95 -98
  75. package/src/testUtils.ts +229 -0
@@ -1,155 +1,84 @@
1
- import {
2
- getAgent,
3
- getAgentID,
4
- newRandomAgentCredential,
5
- newRandomSessionID,
6
- } from './coValue.js';
7
- import { LocalNode } from './node.js';
8
- import { expectMap } from './contentType.js';
9
- import { expectTeamContent } from './permissions.js';
1
+ import { newRandomSessionID } from "./coValue.js";
2
+ import { LocalNode } from "./node.js";
3
+ import { expectMap } from "./contentType.js";
4
+ import { expectTeamContent } from "./permissions.js";
10
5
  import {
11
6
  createdNowUnique,
12
- getRecipientID,
7
+ getSealerID,
13
8
  newRandomKeySecret,
14
9
  seal,
15
- sealKeySecret,
16
- } from './crypto.js';
17
-
18
- function teamWithTwoAdmins() {
19
- const { team, admin, adminID, node } = newTeam();
20
-
21
- const otherAdmin = node.createAgent("otherAdmin");
22
- const otherAdminID = getAgentID(getAgent(otherAdmin));
23
-
24
- let content = expectTeamContent(team.getCurrentContent());
25
-
26
- content.edit((editable) => {
27
- editable.set(otherAdminID, "admin", "trusting");
28
- expect(editable.get(otherAdminID)).toEqual("admin");
29
- });
30
-
31
- content = expectTeamContent(team.getCurrentContent());
32
-
33
- if (content.type !== "comap") {
34
- throw new Error("Expected map");
35
- }
36
-
37
- expect(content.get(otherAdminID)).toEqual("admin");
38
- return { team, admin, adminID, otherAdmin, otherAdminID, node };
39
- }
40
-
41
- function newTeam() {
42
- const admin = newRandomAgentCredential("admin");
43
- const adminID = getAgentID(getAgent(admin));
44
-
45
- const node = new LocalNode(admin, newRandomSessionID(adminID));
46
-
47
- const team = node.createCoValue({
48
- type: "comap",
49
- ruleset: { type: "team", initialAdmin: adminID },
50
- meta: null,
51
- ...createdNowUnique(),
52
- publicNickname: "team",
53
- });
54
-
55
- const teamContent = expectTeamContent(team.getCurrentContent());
56
-
57
- teamContent.edit((editable) => {
58
- editable.set(adminID, "admin", "trusting");
59
- expect(editable.get(adminID)).toEqual("admin");
60
- });
61
-
62
- return { node, team, admin, adminID };
63
- }
10
+ encryptKeySecret,
11
+ } from "./crypto.js";
12
+ import {
13
+ newTeam,
14
+ newTeamHighLevel,
15
+ teamWithTwoAdmins,
16
+ teamWithTwoAdminsHighLevel,
17
+ } from "./testUtils.js";
64
18
 
65
19
  test("Initial admin can add another admin to a team", () => {
66
20
  teamWithTwoAdmins();
67
21
  });
68
22
 
69
- function newTeamHighLevel() {
70
- const admin = newRandomAgentCredential("admin");
71
- const adminID = getAgentID(getAgent(admin));
72
-
73
- const node = new LocalNode(admin, newRandomSessionID(adminID));
74
-
75
- const team = node.createTeam();
76
-
77
- return { admin, adminID, node, team };
78
- }
79
-
80
- function teamWithTwoAdminsHighLevel() {
81
- const { admin, adminID, node, team } = newTeamHighLevel();
82
-
83
- const otherAdmin = node.createAgent("otherAdmin");
84
- const otherAdminID = getAgentID(getAgent(otherAdmin));
85
-
86
- team.addMember(otherAdminID, "admin");
87
-
88
- return { admin, adminID, node, team, otherAdmin, otherAdminID };
89
- }
90
-
91
23
  test("Initial admin can add another admin to a team (high level)", () => {
92
24
  teamWithTwoAdminsHighLevel();
93
25
  });
94
26
 
95
27
  test("Added admin can add a third admin to a team", () => {
96
- const { team, otherAdmin, otherAdminID, node } = teamWithTwoAdmins();
28
+ const { team, otherAdmin, node } = teamWithTwoAdmins();
97
29
 
98
- const teamAsOtherAdmin = team.testWithDifferentCredentials(
30
+ const teamAsOtherAdmin = team.testWithDifferentAccount(
99
31
  otherAdmin,
100
- newRandomSessionID(otherAdminID)
32
+ newRandomSessionID(otherAdmin.id)
101
33
  );
102
34
 
103
35
  let otherContent = expectTeamContent(teamAsOtherAdmin.getCurrentContent());
104
36
 
105
- expect(otherContent.get(otherAdminID)).toEqual("admin");
37
+ expect(otherContent.get(otherAdmin.id)).toEqual("admin");
106
38
 
107
- const thirdAdmin = node.createAgent("thirdAdmin");
108
- const thirdAdminID = getAgentID(getAgent(thirdAdmin));
39
+ const thirdAdmin = node.createAccount("thirdAdmin");
109
40
 
110
41
  otherContent.edit((editable) => {
111
- editable.set(thirdAdminID, "admin", "trusting");
112
- expect(editable.get(thirdAdminID)).toEqual("admin");
42
+ editable.set(thirdAdmin.id, "admin", "trusting");
43
+ expect(editable.get(thirdAdmin.id)).toEqual("admin");
113
44
  });
114
45
 
115
46
  otherContent = expectTeamContent(teamAsOtherAdmin.getCurrentContent());
116
47
 
117
- expect(otherContent.get(thirdAdminID)).toEqual("admin");
48
+ expect(otherContent.get(thirdAdmin.id)).toEqual("admin");
118
49
  });
119
50
 
120
51
  test("Added adming can add a third admin to a team (high level)", () => {
121
- const { team, otherAdmin, otherAdminID, node } =
122
- teamWithTwoAdminsHighLevel();
52
+ const { team, otherAdmin, node } = teamWithTwoAdminsHighLevel();
123
53
 
124
- const teamAsOtherAdmin = team.testWithDifferentCredentials(
54
+ const teamAsOtherAdmin = team.testWithDifferentAccount(
125
55
  otherAdmin,
126
- newRandomSessionID(otherAdminID)
56
+ newRandomSessionID(otherAdmin.id)
127
57
  );
128
58
 
129
- const thirdAdmin = node.createAgent("thirdAdmin");
130
- const thirdAdminID = getAgentID(getAgent(thirdAdmin));
59
+ const thirdAdmin = node.createAccount("thirdAdmin");
131
60
 
132
- teamAsOtherAdmin.addMember(thirdAdminID, "admin");
61
+ teamAsOtherAdmin.addMember(thirdAdmin.id, "admin");
133
62
 
134
- expect(teamAsOtherAdmin.teamMap.get(thirdAdminID)).toEqual("admin");
63
+ expect(teamAsOtherAdmin.teamMap.get(thirdAdmin.id)).toEqual("admin");
135
64
  });
136
65
 
137
66
  test("Admins can't demote other admins in a team", () => {
138
- const { team, adminID, otherAdmin, otherAdminID } = teamWithTwoAdmins();
67
+ const { team, admin, otherAdmin } = teamWithTwoAdmins();
139
68
 
140
69
  let teamContent = expectTeamContent(team.getCurrentContent());
141
70
 
142
71
  teamContent.edit((editable) => {
143
- editable.set(otherAdminID, "writer", "trusting");
144
- expect(editable.get(otherAdminID)).toEqual("admin");
72
+ editable.set(otherAdmin.id, "writer", "trusting");
73
+ expect(editable.get(otherAdmin.id)).toEqual("admin");
145
74
  });
146
75
 
147
76
  teamContent = expectTeamContent(team.getCurrentContent());
148
- expect(teamContent.get(otherAdminID)).toEqual("admin");
77
+ expect(teamContent.get(otherAdmin.id)).toEqual("admin");
149
78
 
150
- const teamAsOtherAdmin = team.testWithDifferentCredentials(
79
+ const teamAsOtherAdmin = team.testWithDifferentAccount(
151
80
  otherAdmin,
152
- newRandomSessionID(otherAdminID)
81
+ newRandomSessionID(otherAdmin.id)
153
82
  );
154
83
 
155
84
  let teamContentAsOtherAdmin = expectTeamContent(
@@ -157,185 +86,176 @@ test("Admins can't demote other admins in a team", () => {
157
86
  );
158
87
 
159
88
  teamContentAsOtherAdmin.edit((editable) => {
160
- editable.set(adminID, "writer", "trusting");
161
- expect(editable.get(adminID)).toEqual("admin");
89
+ editable.set(admin.id, "writer", "trusting");
90
+ expect(editable.get(admin.id)).toEqual("admin");
162
91
  });
163
92
 
164
93
  teamContentAsOtherAdmin = expectTeamContent(
165
94
  teamAsOtherAdmin.getCurrentContent()
166
95
  );
167
96
 
168
- expect(teamContentAsOtherAdmin.get(adminID)).toEqual("admin");
97
+ expect(teamContentAsOtherAdmin.get(admin.id)).toEqual("admin");
169
98
  });
170
99
 
171
100
  test("Admins can't demote other admins in a team (high level)", () => {
172
- const { team, adminID, otherAdmin, otherAdminID } =
173
- teamWithTwoAdminsHighLevel();
101
+ const { team, admin, otherAdmin } = teamWithTwoAdminsHighLevel();
174
102
 
175
- const teamAsOtherAdmin = team.testWithDifferentCredentials(
103
+ const teamAsOtherAdmin = team.testWithDifferentAccount(
176
104
  otherAdmin,
177
- newRandomSessionID(otherAdminID)
105
+ newRandomSessionID(otherAdmin.id)
178
106
  );
179
107
 
180
- expect(() => teamAsOtherAdmin.addMember(adminID, "writer")).toThrow(
108
+ expect(() => teamAsOtherAdmin.addMember(admin.id, "writer")).toThrow(
181
109
  "Failed to set role"
182
110
  );
183
111
 
184
- expect(teamAsOtherAdmin.teamMap.get(adminID)).toEqual("admin");
112
+ expect(teamAsOtherAdmin.teamMap.get(admin.id)).toEqual("admin");
185
113
  });
186
114
 
187
115
  test("Admins an add writers to a team, who can't add admins, writers, or readers", () => {
188
116
  const { team, node } = newTeam();
189
- const writer = node.createAgent("writer");
190
- const writerID = getAgentID(getAgent(writer));
117
+ const writer = node.createAccount("writer");
191
118
 
192
119
  let teamContent = expectTeamContent(team.getCurrentContent());
193
120
 
194
121
  teamContent.edit((editable) => {
195
- editable.set(writerID, "writer", "trusting");
196
- expect(editable.get(writerID)).toEqual("writer");
122
+ editable.set(writer.id, "writer", "trusting");
123
+ expect(editable.get(writer.id)).toEqual("writer");
197
124
  });
198
125
 
199
126
  teamContent = expectTeamContent(team.getCurrentContent());
200
- expect(teamContent.get(writerID)).toEqual("writer");
127
+ expect(teamContent.get(writer.id)).toEqual("writer");
201
128
 
202
- const teamAsWriter = team.testWithDifferentCredentials(
129
+ const teamAsWriter = team.testWithDifferentAccount(
203
130
  writer,
204
- newRandomSessionID(writerID)
131
+ newRandomSessionID(writer.id)
205
132
  );
206
133
 
207
134
  let teamContentAsWriter = expectTeamContent(
208
135
  teamAsWriter.getCurrentContent()
209
136
  );
210
137
 
211
- expect(teamContentAsWriter.get(writerID)).toEqual("writer");
138
+ expect(teamContentAsWriter.get(writer.id)).toEqual("writer");
212
139
 
213
- const otherAgent = node.createAgent("otherAgent");
214
- const otherAgentID = getAgentID(getAgent(otherAgent));
140
+ const otherAgent = node.createAccount("otherAgent");
215
141
 
216
142
  teamContentAsWriter.edit((editable) => {
217
- editable.set(otherAgentID, "admin", "trusting");
218
- expect(editable.get(otherAgentID)).toBeUndefined();
143
+ editable.set(otherAgent.id, "admin", "trusting");
144
+ expect(editable.get(otherAgent.id)).toBeUndefined();
219
145
 
220
- editable.set(otherAgentID, "writer", "trusting");
221
- expect(editable.get(otherAgentID)).toBeUndefined();
146
+ editable.set(otherAgent.id, "writer", "trusting");
147
+ expect(editable.get(otherAgent.id)).toBeUndefined();
222
148
 
223
- editable.set(otherAgentID, "reader", "trusting");
224
- expect(editable.get(otherAgentID)).toBeUndefined();
149
+ editable.set(otherAgent.id, "reader", "trusting");
150
+ expect(editable.get(otherAgent.id)).toBeUndefined();
225
151
  });
226
152
 
227
153
  teamContentAsWriter = expectTeamContent(teamAsWriter.getCurrentContent());
228
154
 
229
- expect(teamContentAsWriter.get(otherAgentID)).toBeUndefined();
155
+ expect(teamContentAsWriter.get(otherAgent.id)).toBeUndefined();
230
156
  });
231
157
 
232
158
  test("Admins an add writers to a team, who can't add admins, writers, or readers (high level)", () => {
233
159
  const { team, node } = newTeamHighLevel();
234
160
 
235
- const writer = node.createAgent("writer");
236
- const writerID = getAgentID(getAgent(writer));
161
+ const writer = node.createAccount("writer");
237
162
 
238
- team.addMember(writerID, "writer");
239
- expect(team.teamMap.get(writerID)).toEqual("writer");
163
+ team.addMember(writer.id, "writer");
164
+ expect(team.teamMap.get(writer.id)).toEqual("writer");
240
165
 
241
- const teamAsWriter = team.testWithDifferentCredentials(
166
+ const teamAsWriter = team.testWithDifferentAccount(
242
167
  writer,
243
- newRandomSessionID(writerID)
168
+ newRandomSessionID(writer.id)
244
169
  );
245
170
 
246
- expect(teamAsWriter.teamMap.get(writerID)).toEqual("writer");
171
+ expect(teamAsWriter.teamMap.get(writer.id)).toEqual("writer");
247
172
 
248
- const otherAgent = node.createAgent("otherAgent");
249
- const otherAgentID = getAgentID(getAgent(otherAgent));
173
+ const otherAgent = node.createAccount("otherAgent");
250
174
 
251
- expect(() => teamAsWriter.addMember(otherAgentID, "admin")).toThrow(
175
+ expect(() => teamAsWriter.addMember(otherAgent.id, "admin")).toThrow(
252
176
  "Failed to set role"
253
177
  );
254
- expect(() => teamAsWriter.addMember(otherAgentID, "writer")).toThrow(
178
+ expect(() => teamAsWriter.addMember(otherAgent.id, "writer")).toThrow(
255
179
  "Failed to set role"
256
180
  );
257
- expect(() => teamAsWriter.addMember(otherAgentID, "reader")).toThrow(
181
+ expect(() => teamAsWriter.addMember(otherAgent.id, "reader")).toThrow(
258
182
  "Failed to set role"
259
183
  );
260
184
 
261
- expect(teamAsWriter.teamMap.get(otherAgentID)).toBeUndefined();
185
+ expect(teamAsWriter.teamMap.get(otherAgent.id)).toBeUndefined();
262
186
  });
263
187
 
264
188
  test("Admins can add readers to a team, who can't add admins, writers, or readers", () => {
265
189
  const { team, node } = newTeam();
266
- const reader = node.createAgent("reader");
267
- const readerID = getAgentID(getAgent(reader));
190
+ const reader = node.createAccount("reader");
268
191
 
269
192
  let teamContent = expectTeamContent(team.getCurrentContent());
270
193
 
271
194
  teamContent.edit((editable) => {
272
- editable.set(readerID, "reader", "trusting");
273
- expect(editable.get(readerID)).toEqual("reader");
195
+ editable.set(reader.id, "reader", "trusting");
196
+ expect(editable.get(reader.id)).toEqual("reader");
274
197
  });
275
198
 
276
199
  teamContent = expectTeamContent(team.getCurrentContent());
277
- expect(teamContent.get(readerID)).toEqual("reader");
200
+ expect(teamContent.get(reader.id)).toEqual("reader");
278
201
 
279
- const teamAsReader = team.testWithDifferentCredentials(
202
+ const teamAsReader = team.testWithDifferentAccount(
280
203
  reader,
281
- newRandomSessionID(readerID)
204
+ newRandomSessionID(reader.id)
282
205
  );
283
206
 
284
207
  let teamContentAsReader = expectTeamContent(
285
208
  teamAsReader.getCurrentContent()
286
209
  );
287
210
 
288
- expect(teamContentAsReader.get(readerID)).toEqual("reader");
211
+ expect(teamContentAsReader.get(reader.id)).toEqual("reader");
289
212
 
290
- const otherAgent = node.createAgent("otherAgent");
291
- const otherAgentID = getAgentID(getAgent(otherAgent));
213
+ const otherAgent = node.createAccount("otherAgent");
292
214
 
293
215
  teamContentAsReader.edit((editable) => {
294
- editable.set(otherAgentID, "admin", "trusting");
295
- expect(editable.get(otherAgentID)).toBeUndefined();
216
+ editable.set(otherAgent.id, "admin", "trusting");
217
+ expect(editable.get(otherAgent.id)).toBeUndefined();
296
218
 
297
- editable.set(otherAgentID, "writer", "trusting");
298
- expect(editable.get(otherAgentID)).toBeUndefined();
219
+ editable.set(otherAgent.id, "writer", "trusting");
220
+ expect(editable.get(otherAgent.id)).toBeUndefined();
299
221
 
300
- editable.set(otherAgentID, "reader", "trusting");
301
- expect(editable.get(otherAgentID)).toBeUndefined();
222
+ editable.set(otherAgent.id, "reader", "trusting");
223
+ expect(editable.get(otherAgent.id)).toBeUndefined();
302
224
  });
303
225
 
304
226
  teamContentAsReader = expectTeamContent(teamAsReader.getCurrentContent());
305
227
 
306
- expect(teamContentAsReader.get(otherAgentID)).toBeUndefined();
228
+ expect(teamContentAsReader.get(otherAgent.id)).toBeUndefined();
307
229
  });
308
230
 
309
231
  test("Admins can add readers to a team, who can't add admins, writers, or readers (high level)", () => {
310
232
  const { team, node } = newTeamHighLevel();
311
233
 
312
- const reader = node.createAgent("reader");
313
- const readerID = getAgentID(getAgent(reader));
234
+ const reader = node.createAccount("reader");
314
235
 
315
- team.addMember(readerID, "reader");
316
- expect(team.teamMap.get(readerID)).toEqual("reader");
236
+ team.addMember(reader.id, "reader");
237
+ expect(team.teamMap.get(reader.id)).toEqual("reader");
317
238
 
318
- const teamAsReader = team.testWithDifferentCredentials(
239
+ const teamAsReader = team.testWithDifferentAccount(
319
240
  reader,
320
- newRandomSessionID(readerID)
241
+ newRandomSessionID(reader.id)
321
242
  );
322
243
 
323
- expect(teamAsReader.teamMap.get(readerID)).toEqual("reader");
244
+ expect(teamAsReader.teamMap.get(reader.id)).toEqual("reader");
324
245
 
325
- const otherAgent = node.createAgent("otherAgent");
326
- const otherAgentID = getAgentID(getAgent(otherAgent));
246
+ const otherAgent = node.createAccount("otherAgent");
327
247
 
328
- expect(() => teamAsReader.addMember(otherAgentID, "admin")).toThrow(
248
+ expect(() => teamAsReader.addMember(otherAgent.id, "admin")).toThrow(
329
249
  "Failed to set role"
330
250
  );
331
- expect(() => teamAsReader.addMember(otherAgentID, "writer")).toThrow(
251
+ expect(() => teamAsReader.addMember(otherAgent.id, "writer")).toThrow(
332
252
  "Failed to set role"
333
253
  );
334
- expect(() => teamAsReader.addMember(otherAgentID, "reader")).toThrow(
254
+ expect(() => teamAsReader.addMember(otherAgent.id, "reader")).toThrow(
335
255
  "Failed to set role"
336
256
  );
337
257
 
338
- expect(teamAsReader.teamMap.get(otherAgentID)).toBeUndefined();
258
+ expect(teamAsReader.teamMap.get(otherAgent.id)).toBeUndefined();
339
259
  });
340
260
 
341
261
  test("Admins can write to an object that is owned by their team", () => {
@@ -346,7 +266,6 @@ test("Admins can write to an object that is owned by their team", () => {
346
266
  ruleset: { type: "ownedByTeam", team: team.id },
347
267
  meta: null,
348
268
  ...createdNowUnique(),
349
- publicNickname: "childObject",
350
269
  });
351
270
 
352
271
  let childContent = expectMap(childObject.getCurrentContent());
@@ -377,12 +296,11 @@ test("Admins can write to an object that is owned by their team (high level)", (
377
296
  test("Writers can write to an object that is owned by their team", () => {
378
297
  const { node, team } = newTeam();
379
298
 
380
- const writer = node.createAgent("writer");
381
- const writerID = getAgentID(getAgent(writer));
299
+ const writer = node.createAccount("writer");
382
300
 
383
301
  expectTeamContent(team.getCurrentContent()).edit((editable) => {
384
- editable.set(writerID, "writer", "trusting");
385
- expect(editable.get(writerID)).toEqual("writer");
302
+ editable.set(writer.id, "writer", "trusting");
303
+ expect(editable.get(writer.id)).toEqual("writer");
386
304
  });
387
305
 
388
306
  const childObject = node.createCoValue({
@@ -390,12 +308,11 @@ test("Writers can write to an object that is owned by their team", () => {
390
308
  ruleset: { type: "ownedByTeam", team: team.id },
391
309
  meta: null,
392
310
  ...createdNowUnique(),
393
- publicNickname: "childObject",
394
311
  });
395
312
 
396
- const childObjectAsWriter = childObject.testWithDifferentCredentials(
313
+ const childObjectAsWriter = childObject.testWithDifferentAccount(
397
314
  writer,
398
- newRandomSessionID(writerID)
315
+ newRandomSessionID(writer.id)
399
316
  );
400
317
 
401
318
  let childContentAsWriter = expectMap(
@@ -415,16 +332,15 @@ test("Writers can write to an object that is owned by their team", () => {
415
332
  test("Writers can write to an object that is owned by their team (high level)", () => {
416
333
  const { node, team } = newTeamHighLevel();
417
334
 
418
- const writer = node.createAgent("writer");
419
- const writerID = getAgentID(getAgent(writer));
335
+ const writer = node.createAccount("writer");
420
336
 
421
- team.addMember(writerID, "writer");
337
+ team.addMember(writer.id, "writer");
422
338
 
423
339
  const childObject = team.createMap();
424
340
 
425
341
  let childObjectAsWriter = expectMap(
426
342
  childObject.coValue
427
- .testWithDifferentCredentials(writer, newRandomSessionID(writerID))
343
+ .testWithDifferentAccount(writer, newRandomSessionID(writer.id))
428
344
  .getCurrentContent()
429
345
  );
430
346
 
@@ -439,12 +355,11 @@ test("Writers can write to an object that is owned by their team (high level)",
439
355
  test("Readers can not write to an object that is owned by their team", () => {
440
356
  const { node, team } = newTeam();
441
357
 
442
- const reader = node.createAgent("reader");
443
- const readerID = getAgentID(getAgent(reader));
358
+ const reader = node.createAccount("reader");
444
359
 
445
360
  expectTeamContent(team.getCurrentContent()).edit((editable) => {
446
- editable.set(readerID, "reader", "trusting");
447
- expect(editable.get(readerID)).toEqual("reader");
361
+ editable.set(reader.id, "reader", "trusting");
362
+ expect(editable.get(reader.id)).toEqual("reader");
448
363
  });
449
364
 
450
365
  const childObject = node.createCoValue({
@@ -452,12 +367,11 @@ test("Readers can not write to an object that is owned by their team", () => {
452
367
  ruleset: { type: "ownedByTeam", team: team.id },
453
368
  meta: null,
454
369
  ...createdNowUnique(),
455
- publicNickname: "childObject",
456
370
  });
457
371
 
458
- const childObjectAsReader = childObject.testWithDifferentCredentials(
372
+ const childObjectAsReader = childObject.testWithDifferentAccount(
459
373
  reader,
460
- newRandomSessionID(readerID)
374
+ newRandomSessionID(reader.id)
461
375
  );
462
376
 
463
377
  let childContentAsReader = expectMap(
@@ -477,16 +391,15 @@ test("Readers can not write to an object that is owned by their team", () => {
477
391
  test("Readers can not write to an object that is owned by their team (high level)", () => {
478
392
  const { node, team } = newTeamHighLevel();
479
393
 
480
- const reader = node.createAgent("reader");
481
- const readerID = getAgentID(getAgent(reader));
394
+ const reader = node.createAccount("reader");
482
395
 
483
- team.addMember(readerID, "reader");
396
+ team.addMember(reader.id, "reader");
484
397
 
485
398
  const childObject = team.createMap();
486
399
 
487
400
  let childObjectAsReader = expectMap(
488
401
  childObject.coValue
489
- .testWithDifferentCredentials(reader, newRandomSessionID(readerID))
402
+ .testWithDifferentAccount(reader, newRandomSessionID(reader.id))
490
403
  .getCurrentContent()
491
404
  );
492
405
 
@@ -499,7 +412,7 @@ test("Readers can not write to an object that is owned by their team (high level
499
412
  });
500
413
 
501
414
  test("Admins can set team read key and then use it to create and read private transactions in owned objects", () => {
502
- const { node, team, admin, adminID } = newTeam();
415
+ const { node, team, admin } = newTeam();
503
416
 
504
417
  const teamContent = expectTeamContent(team.getCurrentContent());
505
418
 
@@ -507,18 +420,24 @@ test("Admins can set team read key and then use it to create and read private tr
507
420
  const { secret: readKey, id: readKeyID } = newRandomKeySecret();
508
421
  const revelation = seal(
509
422
  readKey,
510
- admin.recipientSecret,
511
- new Set([getRecipientID(admin.recipientSecret)]),
423
+ admin.currentSealerSecret(),
424
+ admin.currentSealerID(),
512
425
  {
513
426
  in: team.id,
514
427
  tx: team.nextTransactionID(),
515
428
  }
516
429
  );
517
- editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
518
- expect(editable.get("readKey")).toEqual({
519
- keyID: readKeyID,
520
- revelation,
521
- });
430
+
431
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
432
+
433
+ expect(editable.get(`${readKeyID}_for_${admin.id}`)).toEqual(
434
+ revelation
435
+ );
436
+
437
+ editable.set("readKey", readKeyID, "trusting");
438
+
439
+ expect(editable.get("readKey")).toEqual(readKeyID);
440
+
522
441
  expect(team.getCurrentReadKey().secret).toEqual(readKey);
523
442
  });
524
443
 
@@ -527,7 +446,6 @@ test("Admins can set team read key and then use it to create and read private tr
527
446
  ruleset: { type: "ownedByTeam", team: team.id },
528
447
  meta: null,
529
448
  ...createdNowUnique(),
530
- publicNickname: "childObject",
531
449
  });
532
450
 
533
451
  let childContent = expectMap(childObject.getCurrentContent());
@@ -557,29 +475,41 @@ test("Admins can set team read key and then use it to create and read private tr
557
475
  test("Admins can set team read key and then writers can use it to create and read private transactions in owned objects", () => {
558
476
  const { node, team, admin } = newTeam();
559
477
 
560
- const writer = node.createAgent("writer");
561
- const writerID = getAgentID(getAgent(writer));
478
+ const writer = node.createAccount("writer");
479
+
562
480
  const { secret: readKey, id: readKeyID } = newRandomKeySecret();
563
481
 
564
482
  const teamContent = expectTeamContent(team.getCurrentContent());
565
483
 
566
484
  teamContent.edit((editable) => {
567
- editable.set(writerID, "writer", "trusting");
568
- expect(editable.get(writerID)).toEqual("writer");
485
+ editable.set(writer.id, "writer", "trusting");
486
+ expect(editable.get(writer.id)).toEqual("writer");
569
487
 
570
- const revelation = seal(
488
+ const revelation1 = seal(
489
+ readKey,
490
+ admin.currentSealerSecret(),
491
+ admin.currentSealerID(),
492
+ {
493
+ in: team.id,
494
+ tx: team.nextTransactionID(),
495
+ }
496
+ );
497
+
498
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
499
+
500
+ const revelation2 = seal(
571
501
  readKey,
572
- admin.recipientSecret,
573
- new Set([
574
- getRecipientID(admin.recipientSecret),
575
- getRecipientID(writer.recipientSecret),
576
- ]),
502
+ admin.currentSealerSecret(),
503
+ writer.currentSealerID(),
577
504
  {
578
505
  in: team.id,
579
506
  tx: team.nextTransactionID(),
580
507
  }
581
508
  );
582
- editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
509
+
510
+ editable.set(`${readKeyID}_for_${writer.id}`, revelation2, "trusting");
511
+
512
+ editable.set("readKey", readKeyID, "trusting");
583
513
  });
584
514
 
585
515
  const childObject = node.createCoValue({
@@ -587,12 +517,11 @@ test("Admins can set team read key and then writers can use it to create and rea
587
517
  ruleset: { type: "ownedByTeam", team: team.id },
588
518
  meta: null,
589
519
  ...createdNowUnique(),
590
- publicNickname: "childObject",
591
520
  });
592
521
 
593
- const childObjectAsWriter = childObject.testWithDifferentCredentials(
522
+ const childObjectAsWriter = childObject.testWithDifferentAccount(
594
523
  writer,
595
- newRandomSessionID(writerID)
524
+ newRandomSessionID(writer.id)
596
525
  );
597
526
 
598
527
  expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
@@ -614,16 +543,15 @@ test("Admins can set team read key and then writers can use it to create and rea
614
543
  test("Admins can set team read key and then writers can use it to create and read private transactions in owned objects (high level)", () => {
615
544
  const { node, team, admin } = newTeamHighLevel();
616
545
 
617
- const writer = node.createAgent("writer");
618
- const writerID = getAgentID(getAgent(writer));
546
+ const writer = node.createAccount("writer");
619
547
 
620
- team.addMember(writerID, "writer");
548
+ team.addMember(writer.id, "writer");
621
549
 
622
550
  const childObject = team.createMap();
623
551
 
624
552
  let childObjectAsWriter = expectMap(
625
553
  childObject.coValue
626
- .testWithDifferentCredentials(writer, newRandomSessionID(writerID))
554
+ .testWithDifferentAccount(writer, newRandomSessionID(writer.id))
627
555
  .getCurrentContent()
628
556
  );
629
557
 
@@ -638,29 +566,41 @@ test("Admins can set team read key and then writers can use it to create and rea
638
566
  test("Admins can set team read key and then use it to create private transactions in owned objects, which readers can read", () => {
639
567
  const { node, team, admin } = newTeam();
640
568
 
641
- const reader = node.createAgent("reader");
642
- const readerID = getAgentID(getAgent(reader));
569
+ const reader = node.createAccount("reader");
570
+
643
571
  const { secret: readKey, id: readKeyID } = newRandomKeySecret();
644
572
 
645
573
  const teamContent = expectTeamContent(team.getCurrentContent());
646
574
 
647
575
  teamContent.edit((editable) => {
648
- editable.set(readerID, "reader", "trusting");
649
- expect(editable.get(readerID)).toEqual("reader");
576
+ editable.set(reader.id, "reader", "trusting");
577
+ expect(editable.get(reader.id)).toEqual("reader");
650
578
 
651
- const revelation = seal(
579
+ const revelation1 = seal(
652
580
  readKey,
653
- admin.recipientSecret,
654
- new Set([
655
- getRecipientID(admin.recipientSecret),
656
- getRecipientID(reader.recipientSecret),
657
- ]),
581
+ admin.currentSealerSecret(),
582
+ admin.currentSealerID(),
658
583
  {
659
584
  in: team.id,
660
585
  tx: team.nextTransactionID(),
661
586
  }
662
587
  );
663
- editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
588
+
589
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
590
+
591
+ const revelation2 = seal(
592
+ readKey,
593
+ admin.currentSealerSecret(),
594
+ reader.currentSealerID(),
595
+ {
596
+ in: team.id,
597
+ tx: team.nextTransactionID(),
598
+ }
599
+ );
600
+
601
+ editable.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
602
+
603
+ editable.set("readKey", readKeyID, "trusting");
664
604
  });
665
605
 
666
606
  const childObject = node.createCoValue({
@@ -668,7 +608,6 @@ test("Admins can set team read key and then use it to create private transaction
668
608
  ruleset: { type: "ownedByTeam", team: team.id },
669
609
  meta: null,
670
610
  ...createdNowUnique(),
671
- publicNickname: "childObject",
672
611
  });
673
612
 
674
613
  expectMap(childObject.getCurrentContent()).edit((editable) => {
@@ -676,9 +615,9 @@ test("Admins can set team read key and then use it to create private transaction
676
615
  expect(editable.get("foo")).toEqual("bar");
677
616
  });
678
617
 
679
- const childObjectAsReader = childObject.testWithDifferentCredentials(
618
+ const childObjectAsReader = childObject.testWithDifferentAccount(
680
619
  reader,
681
- newRandomSessionID(readerID)
620
+ newRandomSessionID(reader.id)
682
621
  );
683
622
 
684
623
  expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
@@ -693,10 +632,9 @@ test("Admins can set team read key and then use it to create private transaction
693
632
  test("Admins can set team read key and then use it to create private transactions in owned objects, which readers can read (high level)", () => {
694
633
  const { node, team, admin } = newTeamHighLevel();
695
634
 
696
- const reader = node.createAgent("reader");
697
- const readerID = getAgentID(getAgent(reader));
635
+ const reader = node.createAccount("reader");
698
636
 
699
- team.addMember(readerID, "reader");
637
+ team.addMember(reader.id, "reader");
700
638
 
701
639
  let childObject = team.createMap();
702
640
 
@@ -707,7 +645,7 @@ test("Admins can set team read key and then use it to create private transaction
707
645
 
708
646
  const childContentAsReader = expectMap(
709
647
  childObject.coValue
710
- .testWithDifferentCredentials(reader, newRandomSessionID(readerID))
648
+ .testWithDifferentAccount(reader, newRandomSessionID(reader.id))
711
649
  .getCurrentContent()
712
650
  );
713
651
 
@@ -717,50 +655,43 @@ test("Admins can set team read key and then use it to create private transaction
717
655
  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", () => {
718
656
  const { node, team, admin } = newTeam();
719
657
 
720
- const reader1 = node.createAgent("reader1");
721
- const reader1ID = getAgentID(getAgent(reader1));
722
- const reader2 = node.createAgent("reader2");
723
- const reader2ID = getAgentID(getAgent(reader2));
658
+ const reader1 = node.createAccount("reader1");
659
+
660
+ const reader2 = node.createAccount("reader2");
661
+
724
662
  const { secret: readKey, id: readKeyID } = newRandomKeySecret();
725
663
 
726
664
  const teamContent = expectTeamContent(team.getCurrentContent());
727
665
 
728
666
  teamContent.edit((editable) => {
729
- editable.set(reader1ID, "reader", "trusting");
730
- expect(editable.get(reader1ID)).toEqual("reader");
667
+ editable.set(reader1.id, "reader", "trusting");
668
+ expect(editable.get(reader1.id)).toEqual("reader");
731
669
 
732
670
  const revelation1 = seal(
733
671
  readKey,
734
- admin.recipientSecret,
735
- new Set([
736
- getRecipientID(admin.recipientSecret),
737
- getRecipientID(reader1.recipientSecret),
738
- ]),
672
+ admin.currentSealerSecret(),
673
+ admin.currentSealerID(),
739
674
  {
740
675
  in: team.id,
741
676
  tx: team.nextTransactionID(),
742
677
  }
743
678
  );
744
- editable.set(
745
- "readKey",
746
- { keyID: readKeyID, revelation: revelation1 },
747
- "trusting"
748
- );
679
+
680
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
749
681
 
750
682
  const revelation2 = seal(
751
683
  readKey,
752
- admin.recipientSecret,
753
- new Set([getRecipientID(reader2.recipientSecret)]),
684
+ admin.currentSealerSecret(),
685
+ reader1.currentSealerID(),
754
686
  {
755
687
  in: team.id,
756
688
  tx: team.nextTransactionID(),
757
689
  }
758
690
  );
759
- editable.set(
760
- "readKey",
761
- { keyID: readKeyID, revelation: revelation2 },
762
- "trusting"
763
- );
691
+
692
+ editable.set(`${readKeyID}_for_${reader1.id}`, revelation2, "trusting");
693
+
694
+ editable.set("readKey", readKeyID, "trusting");
764
695
  });
765
696
 
766
697
  const childObject = node.createCoValue({
@@ -768,7 +699,6 @@ test("Admins can set team read key and then use it to create private transaction
768
699
  ruleset: { type: "ownedByTeam", team: team.id },
769
700
  meta: null,
770
701
  ...createdNowUnique(),
771
- publicNickname: "childObject",
772
702
  });
773
703
 
774
704
  expectMap(childObject.getCurrentContent()).edit((editable) => {
@@ -776,9 +706,9 @@ test("Admins can set team read key and then use it to create private transaction
776
706
  expect(editable.get("foo")).toEqual("bar");
777
707
  });
778
708
 
779
- const childObjectAsReader1 = childObject.testWithDifferentCredentials(
709
+ const childObjectAsReader1 = childObject.testWithDifferentAccount(
780
710
  reader1,
781
- newRandomSessionID(reader1ID)
711
+ newRandomSessionID(reader1.id)
782
712
  );
783
713
 
784
714
  expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
@@ -789,9 +719,23 @@ test("Admins can set team read key and then use it to create private transaction
789
719
 
790
720
  expect(childContentAsReader1.get("foo")).toEqual("bar");
791
721
 
792
- const childObjectAsReader2 = childObject.testWithDifferentCredentials(
722
+ teamContent.edit((editable) => {
723
+ const revelation3 = seal(
724
+ readKey,
725
+ admin.currentSealerSecret(),
726
+ reader2.currentSealerID(),
727
+ {
728
+ in: team.id,
729
+ tx: team.nextTransactionID(),
730
+ }
731
+ );
732
+
733
+ editable.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
734
+ });
735
+
736
+ const childObjectAsReader2 = childObject.testWithDifferentAccount(
793
737
  reader2,
794
- newRandomSessionID(reader2ID)
738
+ newRandomSessionID(reader2.id)
795
739
  );
796
740
 
797
741
  expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
@@ -806,12 +750,11 @@ test("Admins can set team read key and then use it to create private transaction
806
750
  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)", () => {
807
751
  const { node, team, admin } = newTeamHighLevel();
808
752
 
809
- const reader1 = node.createAgent("reader1");
810
- const reader1ID = getAgentID(getAgent(reader1));
811
- const reader2 = node.createAgent("reader2");
812
- const reader2ID = getAgentID(getAgent(reader2));
753
+ const reader1 = node.createAccount("reader1");
813
754
 
814
- team.addMember(reader1ID, "reader");
755
+ const reader2 = node.createAccount("reader2");
756
+
757
+ team.addMember(reader1.id, "reader");
815
758
 
816
759
  let childObject = team.createMap();
817
760
 
@@ -822,23 +765,17 @@ test("Admins can set team read key and then use it to create private transaction
822
765
 
823
766
  const childContentAsReader1 = expectMap(
824
767
  childObject.coValue
825
- .testWithDifferentCredentials(
826
- reader1,
827
- newRandomSessionID(reader1ID)
828
- )
768
+ .testWithDifferentAccount(reader1, newRandomSessionID(reader1.id))
829
769
  .getCurrentContent()
830
770
  );
831
771
 
832
772
  expect(childContentAsReader1.get("foo")).toEqual("bar");
833
773
 
834
- team.addMember(reader2ID, "reader");
774
+ team.addMember(reader2.id, "reader");
835
775
 
836
776
  const childContentAsReader2 = expectMap(
837
777
  childObject.coValue
838
- .testWithDifferentCredentials(
839
- reader2,
840
- newRandomSessionID(reader2ID)
841
- )
778
+ .testWithDifferentAccount(reader2, newRandomSessionID(reader2.id))
842
779
  .getCurrentContent()
843
780
  );
844
781
 
@@ -846,7 +783,7 @@ test("Admins can set team read key and then use it to create private transaction
846
783
  });
847
784
 
848
785
  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", () => {
849
- const { node, team, admin, adminID } = newTeam();
786
+ const { node, team, admin } = newTeam();
850
787
 
851
788
  const teamContent = expectTeamContent(team.getCurrentContent());
852
789
 
@@ -854,18 +791,18 @@ test("Admins can set team read key, make a private transaction in an owned objec
854
791
  const { secret: readKey, id: readKeyID } = newRandomKeySecret();
855
792
  const revelation = seal(
856
793
  readKey,
857
- admin.recipientSecret,
858
- new Set([getRecipientID(admin.recipientSecret)]),
794
+ admin.currentSealerSecret(),
795
+ admin.currentSealerID(),
859
796
  {
860
797
  in: team.id,
861
798
  tx: team.nextTransactionID(),
862
799
  }
863
800
  );
864
- editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
865
- expect(editable.get("readKey")).toEqual({
866
- keyID: readKeyID,
867
- revelation,
868
- });
801
+
802
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
803
+
804
+ editable.set("readKey", readKeyID, "trusting");
805
+ expect(editable.get("readKey")).toEqual(readKeyID);
869
806
  expect(team.getCurrentReadKey().secret).toEqual(readKey);
870
807
  });
871
808
 
@@ -874,7 +811,6 @@ test("Admins can set team read key, make a private transaction in an owned objec
874
811
  ruleset: { type: "ownedByTeam", team: team.id },
875
812
  meta: null,
876
813
  ...createdNowUnique(),
877
- publicNickname: "childObject",
878
814
  });
879
815
 
880
816
  let childContent = expectMap(childObject.getCurrentContent());
@@ -892,19 +828,18 @@ test("Admins can set team read key, make a private transaction in an owned objec
892
828
 
893
829
  const revelation = seal(
894
830
  readKey2,
895
- admin.recipientSecret,
896
- new Set([getRecipientID(admin.recipientSecret)]),
831
+ admin.currentSealerSecret(),
832
+ admin.currentSealerID(),
897
833
  {
898
834
  in: team.id,
899
835
  tx: team.nextTransactionID(),
900
836
  }
901
837
  );
902
838
 
903
- editable.set("readKey", { keyID: readKeyID2, revelation }, "trusting");
904
- expect(editable.get("readKey")).toEqual({
905
- keyID: readKeyID2,
906
- revelation,
907
- });
839
+ editable.set(`${readKeyID2}_for_${admin.id}`, revelation, "trusting");
840
+
841
+ editable.set("readKey", readKeyID2, "trusting");
842
+ expect(editable.get("readKey")).toEqual(readKeyID2);
908
843
  expect(team.getCurrentReadKey().secret).toEqual(readKey2);
909
844
  });
910
845
 
@@ -921,7 +856,7 @@ test("Admins can set team read key, make a private transaction in an owned objec
921
856
  });
922
857
 
923
858
  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)", () => {
924
- const { node, team, admin, adminID } = newTeamHighLevel();
859
+ const { team } = newTeamHighLevel();
925
860
 
926
861
  let childObject = team.createMap();
927
862
 
@@ -948,14 +883,13 @@ test("Admins can set team read key, make a private transaction in an owned objec
948
883
  });
949
884
 
950
885
  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", () => {
951
- const { node, team, admin, adminID } = newTeam();
886
+ const { node, team, admin } = newTeam();
952
887
 
953
888
  const childObject = node.createCoValue({
954
889
  type: "comap",
955
890
  ruleset: { type: "ownedByTeam", team: team.id },
956
891
  meta: null,
957
892
  ...createdNowUnique(),
958
- publicNickname: "childObject",
959
893
  });
960
894
 
961
895
  const teamContent = expectTeamContent(team.getCurrentContent());
@@ -964,18 +898,18 @@ test("Admins can set team read key, make a private transaction in an owned objec
964
898
  teamContent.edit((editable) => {
965
899
  const revelation = seal(
966
900
  readKey,
967
- admin.recipientSecret,
968
- new Set([getRecipientID(admin.recipientSecret)]),
901
+ admin.currentSealerSecret(),
902
+ admin.currentSealerID(),
969
903
  {
970
904
  in: team.id,
971
905
  tx: team.nextTransactionID(),
972
906
  }
973
907
  );
974
- editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
975
- expect(editable.get("readKey")).toEqual({
976
- keyID: readKeyID,
977
- revelation,
978
- });
908
+
909
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
910
+
911
+ editable.set("readKey", readKeyID, "trusting");
912
+ expect(editable.get("readKey")).toEqual(readKeyID);
979
913
  expect(team.getCurrentReadKey().secret).toEqual(readKey);
980
914
  });
981
915
 
@@ -989,46 +923,51 @@ test("Admins can set team read key, make a private transaction in an owned objec
989
923
  childContent = expectMap(childObject.getCurrentContent());
990
924
  expect(childContent.get("foo")).toEqual("bar");
991
925
 
992
- const reader = node.createAgent("reader");
993
- const readerID = getAgentID(getAgent(reader));
926
+ const reader = node.createAccount("reader");
927
+
994
928
  const { secret: readKey2, id: readKeyID2 } = newRandomKeySecret();
995
929
 
996
930
  teamContent.edit((editable) => {
997
- const revelation = seal(
931
+ const revelation2 = seal(
998
932
  readKey2,
999
- admin.recipientSecret,
1000
- new Set([
1001
- getRecipientID(admin.recipientSecret),
1002
- getRecipientID(reader.recipientSecret),
1003
- ]),
933
+ admin.currentSealerSecret(),
934
+ admin.currentSealerID(),
1004
935
  {
1005
936
  in: team.id,
1006
937
  tx: team.nextTransactionID(),
1007
938
  }
1008
939
  );
1009
940
 
1010
- editable.set(
1011
- "readKey",
941
+ editable.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
942
+
943
+ const revelation3 = seal(
944
+ readKey2,
945
+ admin.currentSealerSecret(),
946
+ reader.currentSealerID(),
1012
947
  {
1013
- keyID: readKeyID2,
1014
- revelation,
1015
- previousKeys: {
1016
- [readKeyID]: sealKeySecret({
1017
- toSeal: { id: readKeyID, secret: readKey },
1018
- sealing: { id: readKeyID2, secret: readKey2 },
1019
- }).encrypted,
1020
- },
1021
- },
948
+ in: team.id,
949
+ tx: team.nextTransactionID(),
950
+ }
951
+ );
952
+
953
+ editable.set(`${readKeyID2}_for_${reader.id}`, revelation3, "trusting");
954
+
955
+ editable.set(
956
+ `${readKeyID}_for_${readKeyID2}`,
957
+ encryptKeySecret({
958
+ toEncrypt: { id: readKeyID, secret: readKey },
959
+ encrypting: { id: readKeyID2, secret: readKey2 },
960
+ }).encrypted,
1022
961
  "trusting"
1023
962
  );
1024
- expect(editable.get("readKey")).toMatchObject({
1025
- keyID: readKeyID2,
1026
- revelation,
1027
- });
963
+
964
+ editable.set("readKey", readKeyID2, "trusting");
965
+
966
+ expect(editable.get("readKey")).toEqual(readKeyID2);
1028
967
  expect(team.getCurrentReadKey().secret).toEqual(readKey2);
1029
968
 
1030
- editable.set(readerID, "reader", "trusting");
1031
- expect(editable.get(readerID)).toEqual("reader");
969
+ editable.set(reader.id, "reader", "trusting");
970
+ expect(editable.get(reader.id)).toEqual("reader");
1032
971
  });
1033
972
 
1034
973
  childContent.edit((editable) => {
@@ -1036,9 +975,9 @@ test("Admins can set team read key, make a private transaction in an owned objec
1036
975
  expect(editable.get("foo2")).toEqual("bar2");
1037
976
  });
1038
977
 
1039
- const childObjectAsReader = childObject.testWithDifferentCredentials(
978
+ const childObjectAsReader = childObject.testWithDifferentAccount(
1040
979
  reader,
1041
- newRandomSessionID(readerID)
980
+ newRandomSessionID(reader.id)
1042
981
  );
1043
982
 
1044
983
  expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
@@ -1052,7 +991,7 @@ test("Admins can set team read key, make a private transaction in an owned objec
1052
991
  });
1053
992
 
1054
993
  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)", () => {
1055
- const { node, team, admin, adminID } = newTeamHighLevel();
994
+ const { node, team } = newTeamHighLevel();
1056
995
 
1057
996
  let childObject = team.createMap();
1058
997
 
@@ -1069,10 +1008,9 @@ test("Admins can set team read key, make a private transaction in an owned objec
1069
1008
 
1070
1009
  expect(childObject.coValue.getCurrentReadKey()).not.toEqual(firstReadKey);
1071
1010
 
1072
- const reader = node.createAgent("reader");
1073
- const readerID = getAgentID(getAgent(reader));
1011
+ const reader = node.createAccount("reader");
1074
1012
 
1075
- team.addMember(readerID, "reader");
1013
+ team.addMember(reader.id, "reader");
1076
1014
 
1077
1015
  childObject = childObject.edit((editable) => {
1078
1016
  editable.set("foo2", "bar2", "private");
@@ -1081,7 +1019,7 @@ test("Admins can set team read key, make a private transaction in an owned objec
1081
1019
 
1082
1020
  const childContentAsReader = expectMap(
1083
1021
  childObject.coValue
1084
- .testWithDifferentCredentials(reader, newRandomSessionID(readerID))
1022
+ .testWithDifferentAccount(reader, newRandomSessionID(reader.id))
1085
1023
  .getCurrentContent()
1086
1024
  );
1087
1025
 
@@ -1090,48 +1028,66 @@ test("Admins can set team read key, make a private transaction in an owned objec
1090
1028
  });
1091
1029
 
1092
1030
  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", () => {
1093
- const { node, team, admin, adminID } = newTeam();
1031
+ const { node, team, admin } = newTeam();
1094
1032
 
1095
1033
  const childObject = node.createCoValue({
1096
1034
  type: "comap",
1097
1035
  ruleset: { type: "ownedByTeam", team: team.id },
1098
1036
  meta: null,
1099
1037
  ...createdNowUnique(),
1100
- publicNickname: "childObject",
1101
1038
  });
1102
1039
 
1103
1040
  const teamContent = expectTeamContent(team.getCurrentContent());
1104
1041
  const { secret: readKey, id: readKeyID } = newRandomKeySecret();
1105
- const reader = node.createAgent("reader");
1106
- const readerID = getAgentID(getAgent(reader));
1107
- const reader2 = node.createAgent("reader2");
1108
- const reader2ID = getAgentID(getAgent(reader));
1042
+ const reader = node.createAccount("reader");
1043
+
1044
+ const reader2 = node.createAccount("reader2");
1109
1045
 
1110
1046
  teamContent.edit((editable) => {
1111
- const revelation = seal(
1047
+ const revelation1 = seal(
1048
+ readKey,
1049
+ admin.currentSealerSecret(),
1050
+ admin.currentSealerID(),
1051
+ {
1052
+ in: team.id,
1053
+ tx: team.nextTransactionID(),
1054
+ }
1055
+ );
1056
+
1057
+ editable.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
1058
+
1059
+ const revelation2 = seal(
1060
+ readKey,
1061
+ admin.currentSealerSecret(),
1062
+ reader.currentSealerID(),
1063
+ {
1064
+ in: team.id,
1065
+ tx: team.nextTransactionID(),
1066
+ }
1067
+ );
1068
+
1069
+ editable.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
1070
+
1071
+ const revelation3 = seal(
1112
1072
  readKey,
1113
- admin.recipientSecret,
1114
- new Set([
1115
- getRecipientID(admin.recipientSecret),
1116
- getRecipientID(reader.recipientSecret),
1117
- getRecipientID(reader2.recipientSecret),
1118
- ]),
1073
+ admin.currentSealerSecret(),
1074
+ reader2.currentSealerID(),
1119
1075
  {
1120
1076
  in: team.id,
1121
1077
  tx: team.nextTransactionID(),
1122
1078
  }
1123
1079
  );
1124
- editable.set("readKey", { keyID: readKeyID, revelation }, "trusting");
1125
- expect(editable.get("readKey")).toEqual({
1126
- keyID: readKeyID,
1127
- revelation,
1128
- });
1080
+
1081
+ editable.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
1082
+
1083
+ editable.set("readKey", readKeyID, "trusting");
1084
+ expect(editable.get("readKey")).toEqual(readKeyID);
1129
1085
  expect(team.getCurrentReadKey().secret).toEqual(readKey);
1130
1086
 
1131
- editable.set(readerID, "reader", "trusting");
1132
- expect(editable.get(readerID)).toEqual("reader");
1133
- editable.set(reader2ID, "reader", "trusting");
1134
- expect(editable.get(reader2ID)).toEqual("reader");
1087
+ editable.set(reader.id, "reader", "trusting");
1088
+ expect(editable.get(reader.id)).toEqual("reader");
1089
+ editable.set(reader2.id, "reader", "trusting");
1090
+ expect(editable.get(reader2.id)).toEqual("reader");
1135
1091
  });
1136
1092
 
1137
1093
  let childContent = expectMap(childObject.getCurrentContent());
@@ -1144,18 +1100,18 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1144
1100
  childContent = expectMap(childObject.getCurrentContent());
1145
1101
  expect(childContent.get("foo")).toEqual("bar");
1146
1102
 
1147
- let childObjectAsReader = childObject.testWithDifferentCredentials(
1103
+ let childObjectAsReader = childObject.testWithDifferentAccount(
1148
1104
  reader,
1149
- newRandomSessionID(readerID)
1105
+ newRandomSessionID(reader.id)
1150
1106
  );
1151
1107
 
1152
1108
  expect(
1153
1109
  expectMap(childObjectAsReader.getCurrentContent()).get("foo")
1154
1110
  ).toEqual("bar");
1155
1111
 
1156
- let childObjectAsReader2 = childObject.testWithDifferentCredentials(
1112
+ let childObjectAsReader2 = childObject.testWithDifferentAccount(
1157
1113
  reader,
1158
- newRandomSessionID(readerID)
1114
+ newRandomSessionID(reader.id)
1159
1115
  );
1160
1116
 
1161
1117
  expect(
@@ -1165,27 +1121,44 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1165
1121
  const { secret: readKey2, id: readKeyID2 } = newRandomKeySecret();
1166
1122
 
1167
1123
  teamContent.edit((editable) => {
1168
- const revelation = seal(
1124
+ const newRevelation1 = seal(
1169
1125
  readKey2,
1170
- admin.recipientSecret,
1171
- new Set([
1172
- getRecipientID(admin.recipientSecret),
1173
- getRecipientID(reader2.recipientSecret),
1174
- ]),
1126
+ admin.currentSealerSecret(),
1127
+ admin.currentSealerID(),
1175
1128
  {
1176
1129
  in: team.id,
1177
1130
  tx: team.nextTransactionID(),
1178
1131
  }
1179
1132
  );
1180
- editable.set("readKey", { keyID: readKeyID2, revelation }, "trusting");
1181
- expect(editable.get("readKey")).toEqual({
1182
- keyID: readKeyID2,
1183
- revelation,
1184
- });
1133
+
1134
+ editable.set(
1135
+ `${readKeyID2}_for_${admin.id}`,
1136
+ newRevelation1,
1137
+ "trusting"
1138
+ );
1139
+
1140
+ const newRevelation2 = seal(
1141
+ readKey2,
1142
+ admin.currentSealerSecret(),
1143
+ reader2.currentSealerID(),
1144
+ {
1145
+ in: team.id,
1146
+ tx: team.nextTransactionID(),
1147
+ }
1148
+ );
1149
+
1150
+ editable.set(
1151
+ `${readKeyID2}_for_${reader2.id}`,
1152
+ newRevelation2,
1153
+ "trusting"
1154
+ );
1155
+
1156
+ editable.set("readKey", readKeyID2, "trusting");
1157
+ expect(editable.get("readKey")).toEqual(readKeyID2);
1185
1158
  expect(team.getCurrentReadKey().secret).toEqual(readKey2);
1186
1159
 
1187
- editable.set(readerID, "revoked", "trusting");
1188
- // expect(editable.get(readerID)).toEqual("revoked");
1160
+ editable.set(reader.id, "revoked", "trusting");
1161
+ // expect(editable.get(reader.id)).toEqual("revoked");
1189
1162
  });
1190
1163
 
1191
1164
  expect(childObject.getCurrentReadKey().secret).toEqual(readKey2);
@@ -1197,13 +1170,13 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1197
1170
  });
1198
1171
 
1199
1172
  // TODO: make sure these instances of coValues sync between each other so this isn't necessary?
1200
- childObjectAsReader = childObject.testWithDifferentCredentials(
1173
+ childObjectAsReader = childObject.testWithDifferentAccount(
1201
1174
  reader,
1202
- newRandomSessionID(readerID)
1175
+ newRandomSessionID(reader.id)
1203
1176
  );
1204
- childObjectAsReader2 = childObject.testWithDifferentCredentials(
1177
+ childObjectAsReader2 = childObject.testWithDifferentAccount(
1205
1178
  reader2,
1206
- newRandomSessionID(reader2ID)
1179
+ newRandomSessionID(reader2.id)
1207
1180
  );
1208
1181
 
1209
1182
  expect(
@@ -1215,7 +1188,7 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1215
1188
  });
1216
1189
 
1217
1190
  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)", () => {
1218
- const { node, team, admin, adminID } = newTeamHighLevel();
1191
+ const { node, team } = newTeamHighLevel();
1219
1192
 
1220
1193
  let childObject = team.createMap();
1221
1194
 
@@ -1230,13 +1203,12 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1230
1203
 
1231
1204
  const secondReadKey = childObject.coValue.getCurrentReadKey();
1232
1205
 
1233
- const reader = node.createAgent("reader");
1234
- const readerID = getAgentID(getAgent(reader));
1235
- const reader2 = node.createAgent("reader2");
1236
- const reader2ID = getAgentID(getAgent(reader2));
1206
+ const reader = node.createAccount("reader");
1207
+
1208
+ const reader2 = node.createAccount("reader2");
1237
1209
 
1238
- team.addMember(readerID, "reader");
1239
- team.addMember(reader2ID, "reader");
1210
+ team.addMember(reader.id, "reader");
1211
+ team.addMember(reader2.id, "reader");
1240
1212
 
1241
1213
  childObject = childObject.edit((editable) => {
1242
1214
  editable.set("foo2", "bar2", "private");
@@ -1246,7 +1218,7 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1246
1218
  expect(childObject.get("foo")).toEqual("bar");
1247
1219
  expect(childObject.get("foo2")).toEqual("bar2");
1248
1220
 
1249
- team.removeMember(readerID);
1221
+ team.removeMember(reader.id);
1250
1222
 
1251
1223
  expect(childObject.coValue.getCurrentReadKey()).not.toEqual(secondReadKey);
1252
1224
 
@@ -1257,10 +1229,7 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1257
1229
 
1258
1230
  const childContentAsReader2 = expectMap(
1259
1231
  childObject.coValue
1260
- .testWithDifferentCredentials(
1261
- reader2,
1262
- newRandomSessionID(reader2ID)
1263
- )
1232
+ .testWithDifferentAccount(reader2, newRandomSessionID(reader2.id))
1264
1233
  .getCurrentContent()
1265
1234
  );
1266
1235
 
@@ -1271,31 +1240,28 @@ test("Admins can set team read rey, make a private transaction in an owned objec
1271
1240
  expect(
1272
1241
  expectMap(
1273
1242
  childObject.coValue
1274
- .testWithDifferentCredentials(
1275
- reader,
1276
- newRandomSessionID(readerID)
1277
- )
1243
+ .testWithDifferentAccount(reader, newRandomSessionID(reader.id))
1278
1244
  .getCurrentContent()
1279
1245
  ).get("foo3")
1280
1246
  ).toBeUndefined();
1281
1247
  });
1282
1248
 
1283
1249
  test("Can create two owned objects in the same team and they will have different ids", () => {
1284
- const { node, team, admin, adminID } = newTeam();
1250
+ const { node, team } = newTeam();
1285
1251
 
1286
1252
  const childObject1 = node.createCoValue({
1287
1253
  type: "comap",
1288
1254
  ruleset: { type: "ownedByTeam", team: team.id },
1289
1255
  meta: null,
1290
- ...createdNowUnique()
1256
+ ...createdNowUnique(),
1291
1257
  });
1292
1258
 
1293
1259
  const childObject2 = node.createCoValue({
1294
1260
  type: "comap",
1295
1261
  ruleset: { type: "ownedByTeam", team: team.id },
1296
1262
  meta: null,
1297
- ...createdNowUnique()
1263
+ ...createdNowUnique(),
1298
1264
  });
1299
1265
 
1300
1266
  expect(childObject1.id).not.toEqual(childObject2.id);
1301
- });
1267
+ });