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