cojson 0.0.6 → 0.0.8

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