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