cojson 0.8.12 → 0.8.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +95 -83
  2. package/dist/native/PeerKnownStates.js +6 -1
  3. package/dist/native/PeerKnownStates.js.map +1 -1
  4. package/dist/native/PeerState.js +4 -3
  5. package/dist/native/PeerState.js.map +1 -1
  6. package/dist/native/PriorityBasedMessageQueue.js +1 -10
  7. package/dist/native/PriorityBasedMessageQueue.js.map +1 -1
  8. package/dist/native/SyncStateSubscriptionManager.js +70 -0
  9. package/dist/native/SyncStateSubscriptionManager.js.map +1 -0
  10. package/dist/native/base64url.js.map +1 -1
  11. package/dist/native/base64url.test.js +1 -1
  12. package/dist/native/base64url.test.js.map +1 -1
  13. package/dist/native/coValue.js.map +1 -1
  14. package/dist/native/coValueCore.js +141 -149
  15. package/dist/native/coValueCore.js.map +1 -1
  16. package/dist/native/coValueState.js.map +1 -1
  17. package/dist/native/coValues/account.js +6 -6
  18. package/dist/native/coValues/account.js.map +1 -1
  19. package/dist/native/coValues/coList.js +2 -3
  20. package/dist/native/coValues/coList.js.map +1 -1
  21. package/dist/native/coValues/coMap.js +1 -1
  22. package/dist/native/coValues/coMap.js.map +1 -1
  23. package/dist/native/coValues/coStream.js +3 -5
  24. package/dist/native/coValues/coStream.js.map +1 -1
  25. package/dist/native/coValues/group.js +11 -11
  26. package/dist/native/coValues/group.js.map +1 -1
  27. package/dist/native/coreToCoValue.js +2 -2
  28. package/dist/native/coreToCoValue.js.map +1 -1
  29. package/dist/native/crypto/PureJSCrypto.js +4 -4
  30. package/dist/native/crypto/PureJSCrypto.js.map +1 -1
  31. package/dist/native/crypto/crypto.js.map +1 -1
  32. package/dist/native/exports.js +12 -12
  33. package/dist/native/exports.js.map +1 -1
  34. package/dist/native/ids.js.map +1 -1
  35. package/dist/native/jsonStringify.js.map +1 -1
  36. package/dist/native/localNode.js +5 -7
  37. package/dist/native/localNode.js.map +1 -1
  38. package/dist/native/permissions.js +4 -7
  39. package/dist/native/permissions.js.map +1 -1
  40. package/dist/native/priority.js.map +1 -1
  41. package/dist/native/storage/FileSystem.js.map +1 -1
  42. package/dist/native/storage/chunksAndKnownStates.js +2 -4
  43. package/dist/native/storage/chunksAndKnownStates.js.map +1 -1
  44. package/dist/native/storage/index.js +6 -15
  45. package/dist/native/storage/index.js.map +1 -1
  46. package/dist/native/streamUtils.js.map +1 -1
  47. package/dist/native/sync.js +57 -7
  48. package/dist/native/sync.js.map +1 -1
  49. package/dist/native/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
  50. package/dist/native/typeUtils/expectGroup.js.map +1 -1
  51. package/dist/native/typeUtils/isAccountID.js.map +1 -1
  52. package/dist/native/typeUtils/isCoValue.js +1 -1
  53. package/dist/native/typeUtils/isCoValue.js.map +1 -1
  54. package/dist/web/PeerKnownStates.js +6 -1
  55. package/dist/web/PeerKnownStates.js.map +1 -1
  56. package/dist/web/PeerState.js +4 -3
  57. package/dist/web/PeerState.js.map +1 -1
  58. package/dist/web/PriorityBasedMessageQueue.js +1 -10
  59. package/dist/web/PriorityBasedMessageQueue.js.map +1 -1
  60. package/dist/web/SyncStateSubscriptionManager.js +70 -0
  61. package/dist/web/SyncStateSubscriptionManager.js.map +1 -0
  62. package/dist/web/base64url.js.map +1 -1
  63. package/dist/web/base64url.test.js +1 -1
  64. package/dist/web/base64url.test.js.map +1 -1
  65. package/dist/web/coValue.js.map +1 -1
  66. package/dist/web/coValueCore.js +141 -149
  67. package/dist/web/coValueCore.js.map +1 -1
  68. package/dist/web/coValueState.js.map +1 -1
  69. package/dist/web/coValues/account.js +6 -6
  70. package/dist/web/coValues/account.js.map +1 -1
  71. package/dist/web/coValues/coList.js +2 -3
  72. package/dist/web/coValues/coList.js.map +1 -1
  73. package/dist/web/coValues/coMap.js +1 -1
  74. package/dist/web/coValues/coMap.js.map +1 -1
  75. package/dist/web/coValues/coStream.js +3 -5
  76. package/dist/web/coValues/coStream.js.map +1 -1
  77. package/dist/web/coValues/group.js +11 -11
  78. package/dist/web/coValues/group.js.map +1 -1
  79. package/dist/web/coreToCoValue.js +2 -2
  80. package/dist/web/coreToCoValue.js.map +1 -1
  81. package/dist/web/crypto/PureJSCrypto.js +4 -4
  82. package/dist/web/crypto/PureJSCrypto.js.map +1 -1
  83. package/dist/web/crypto/WasmCrypto.js +5 -5
  84. package/dist/web/crypto/WasmCrypto.js.map +1 -1
  85. package/dist/web/crypto/crypto.js.map +1 -1
  86. package/dist/web/exports.js +12 -12
  87. package/dist/web/exports.js.map +1 -1
  88. package/dist/web/ids.js.map +1 -1
  89. package/dist/web/jsonStringify.js.map +1 -1
  90. package/dist/web/localNode.js +5 -7
  91. package/dist/web/localNode.js.map +1 -1
  92. package/dist/web/permissions.js +4 -7
  93. package/dist/web/permissions.js.map +1 -1
  94. package/dist/web/priority.js.map +1 -1
  95. package/dist/web/storage/FileSystem.js.map +1 -1
  96. package/dist/web/storage/chunksAndKnownStates.js +2 -4
  97. package/dist/web/storage/chunksAndKnownStates.js.map +1 -1
  98. package/dist/web/storage/index.js +6 -15
  99. package/dist/web/storage/index.js.map +1 -1
  100. package/dist/web/streamUtils.js.map +1 -1
  101. package/dist/web/sync.js +57 -7
  102. package/dist/web/sync.js.map +1 -1
  103. package/dist/web/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
  104. package/dist/web/typeUtils/expectGroup.js.map +1 -1
  105. package/dist/web/typeUtils/isAccountID.js.map +1 -1
  106. package/dist/web/typeUtils/isCoValue.js +1 -1
  107. package/dist/web/typeUtils/isCoValue.js.map +1 -1
  108. package/package.json +4 -14
  109. package/src/PeerKnownStates.ts +98 -90
  110. package/src/PeerState.ts +92 -73
  111. package/src/PriorityBasedMessageQueue.ts +42 -49
  112. package/src/SyncStateSubscriptionManager.ts +124 -0
  113. package/src/base64url.test.ts +24 -24
  114. package/src/base64url.ts +44 -45
  115. package/src/coValue.ts +45 -45
  116. package/src/coValueCore.ts +746 -785
  117. package/src/coValueState.ts +82 -72
  118. package/src/coValues/account.ts +143 -150
  119. package/src/coValues/coList.ts +520 -522
  120. package/src/coValues/coMap.ts +283 -285
  121. package/src/coValues/coStream.ts +320 -324
  122. package/src/coValues/group.ts +306 -305
  123. package/src/coreToCoValue.ts +28 -31
  124. package/src/crypto/PureJSCrypto.ts +188 -194
  125. package/src/crypto/WasmCrypto.ts +236 -254
  126. package/src/crypto/crypto.ts +302 -309
  127. package/src/exports.ts +116 -116
  128. package/src/ids.ts +9 -9
  129. package/src/jsonStringify.ts +46 -46
  130. package/src/jsonValue.ts +24 -10
  131. package/src/localNode.ts +635 -660
  132. package/src/media.ts +3 -3
  133. package/src/permissions.ts +272 -278
  134. package/src/priority.ts +21 -19
  135. package/src/storage/FileSystem.ts +91 -99
  136. package/src/storage/chunksAndKnownStates.ts +110 -115
  137. package/src/storage/index.ts +466 -497
  138. package/src/streamUtils.ts +60 -60
  139. package/src/sync.ts +656 -608
  140. package/src/tests/PeerKnownStates.test.ts +38 -34
  141. package/src/tests/PeerState.test.ts +101 -64
  142. package/src/tests/PriorityBasedMessageQueue.test.ts +91 -91
  143. package/src/tests/SyncStateSubscriptionManager.test.ts +232 -0
  144. package/src/tests/account.test.ts +59 -59
  145. package/src/tests/coList.test.ts +65 -65
  146. package/src/tests/coMap.test.ts +137 -137
  147. package/src/tests/coStream.test.ts +254 -257
  148. package/src/tests/coValueCore.test.ts +153 -156
  149. package/src/tests/crypto.test.ts +136 -144
  150. package/src/tests/cryptoImpl.test.ts +205 -197
  151. package/src/tests/group.test.ts +24 -24
  152. package/src/tests/permissions.test.ts +1306 -1371
  153. package/src/tests/priority.test.ts +65 -82
  154. package/src/tests/sync.test.ts +1573 -1263
  155. package/src/tests/testUtils.ts +85 -53
  156. package/src/typeUtils/accountOrAgentIDfromSessionID.ts +4 -4
  157. package/src/typeUtils/expectGroup.ts +9 -9
  158. package/src/typeUtils/isAccountID.ts +1 -1
  159. package/src/typeUtils/isCoValue.ts +9 -9
  160. package/tsconfig.json +4 -6
  161. package/tsconfig.native.json +9 -11
  162. package/tsconfig.web.json +4 -10
  163. package/.eslintrc.cjs +0 -25
  164. package/.prettierrc.js +0 -9
@@ -1,1775 +1,1710 @@
1
1
  import { expect, test } from "vitest";
2
2
  import { expectMap } from "../coValue.js";
3
+ import { ControlledAgent } from "../coValues/account.js";
4
+ import { WasmCrypto } from "../crypto/WasmCrypto.js";
5
+ import { expectGroup } from "../typeUtils/expectGroup.js";
3
6
  import {
4
- newGroup,
5
- newGroupHighLevel,
6
- groupWithTwoAdmins,
7
- groupWithTwoAdminsHighLevel,
7
+ groupWithTwoAdmins,
8
+ groupWithTwoAdminsHighLevel,
9
+ newGroup,
10
+ newGroupHighLevel,
8
11
  } from "./testUtils.js";
9
- import { expectGroup } from "../typeUtils/expectGroup.js";
10
- import { WasmCrypto } from "../crypto/WasmCrypto.js";
11
- import { ControlledAgent } from "../coValues/account.js";
12
12
 
13
13
  const Crypto = await WasmCrypto.create();
14
14
 
15
15
  test("Initial admin can add another admin to a group", () => {
16
- groupWithTwoAdmins();
16
+ groupWithTwoAdmins();
17
17
  });
18
18
 
19
19
  test("Initial admin can add another admin to a group (high level)", () => {
20
- groupWithTwoAdminsHighLevel();
20
+ groupWithTwoAdminsHighLevel();
21
21
  });
22
22
 
23
23
  test("Added admin can add a third admin to a group", () => {
24
- const { groupCore, otherAdmin, node } = groupWithTwoAdmins();
24
+ const { groupCore, otherAdmin, node } = groupWithTwoAdmins();
25
25
 
26
- const groupAsOtherAdmin = expectGroup(
27
- groupCore
28
- .testWithDifferentAccount(
29
- otherAdmin,
30
- Crypto.newRandomSessionID(otherAdmin.id),
31
- )
32
- .getCurrentContent(),
33
- );
26
+ const groupAsOtherAdmin = expectGroup(
27
+ groupCore
28
+ .testWithDifferentAccount(
29
+ otherAdmin,
30
+ Crypto.newRandomSessionID(otherAdmin.id),
31
+ )
32
+ .getCurrentContent(),
33
+ );
34
34
 
35
- expect(groupAsOtherAdmin.get(otherAdmin.id)).toEqual("admin");
35
+ expect(groupAsOtherAdmin.get(otherAdmin.id)).toEqual("admin");
36
36
 
37
- const thirdAdmin = node.createAccount();
37
+ const thirdAdmin = node.createAccount();
38
38
 
39
- groupAsOtherAdmin.set(thirdAdmin.id, "admin", "trusting");
40
- expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
39
+ groupAsOtherAdmin.set(thirdAdmin.id, "admin", "trusting");
40
+ expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
41
41
  });
42
42
 
43
43
  test("Added adming can add a third admin to a group (high level)", () => {
44
- const { group, otherAdmin } = groupWithTwoAdminsHighLevel();
44
+ const { group, otherAdmin } = groupWithTwoAdminsHighLevel();
45
45
 
46
- const groupAsOtherAdmin = expectGroup(
47
- group.core
48
- .testWithDifferentAccount(
49
- otherAdmin,
50
- Crypto.newRandomSessionID(otherAdmin.id),
51
- )
52
- .getCurrentContent(),
53
- );
46
+ const groupAsOtherAdmin = expectGroup(
47
+ group.core
48
+ .testWithDifferentAccount(
49
+ otherAdmin,
50
+ Crypto.newRandomSessionID(otherAdmin.id),
51
+ )
52
+ .getCurrentContent(),
53
+ );
54
54
 
55
- const thirdAdmin = groupAsOtherAdmin.core.node.createAccount();
55
+ const thirdAdmin = groupAsOtherAdmin.core.node.createAccount();
56
56
 
57
- groupAsOtherAdmin.addMember(thirdAdmin, "admin");
57
+ groupAsOtherAdmin.addMember(thirdAdmin, "admin");
58
58
 
59
- expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
59
+ expect(groupAsOtherAdmin.get(thirdAdmin.id)).toEqual("admin");
60
60
  });
61
61
 
62
62
  test("Admins can't demote other admins in a group", () => {
63
- const { groupCore, admin, otherAdmin } = groupWithTwoAdmins();
63
+ const { groupCore, admin, otherAdmin } = groupWithTwoAdmins();
64
64
 
65
- const groupContent = expectGroup(groupCore.getCurrentContent());
65
+ const groupContent = expectGroup(groupCore.getCurrentContent());
66
66
 
67
- groupContent.set(otherAdmin.id, "writer", "trusting");
68
- expect(groupContent.get(otherAdmin.id)).toEqual("admin");
67
+ groupContent.set(otherAdmin.id, "writer", "trusting");
68
+ expect(groupContent.get(otherAdmin.id)).toEqual("admin");
69
69
 
70
- expect(groupContent.get(otherAdmin.id)).toEqual("admin");
70
+ expect(groupContent.get(otherAdmin.id)).toEqual("admin");
71
71
 
72
- const groupAsOtherAdmin = expectGroup(
73
- groupCore
74
- .testWithDifferentAccount(
75
- otherAdmin,
76
- Crypto.newRandomSessionID(otherAdmin.id),
77
- )
78
- .getCurrentContent(),
79
- );
72
+ const groupAsOtherAdmin = expectGroup(
73
+ groupCore
74
+ .testWithDifferentAccount(
75
+ otherAdmin,
76
+ Crypto.newRandomSessionID(otherAdmin.id),
77
+ )
78
+ .getCurrentContent(),
79
+ );
80
80
 
81
- groupAsOtherAdmin.set(admin.id, "writer", "trusting");
82
- expect(groupAsOtherAdmin.get(admin.id)).toEqual("admin");
81
+ groupAsOtherAdmin.set(admin.id, "writer", "trusting");
82
+ expect(groupAsOtherAdmin.get(admin.id)).toEqual("admin");
83
83
  });
84
84
 
85
85
  test("Admins can't demote other admins in a group (high level)", () => {
86
- const { group, admin, otherAdmin } = groupWithTwoAdminsHighLevel();
87
-
88
- const groupAsOtherAdmin = expectGroup(
89
- group.core
90
- .testWithDifferentAccount(
91
- otherAdmin,
92
- Crypto.newRandomSessionID(otherAdmin.id),
93
- )
94
- .getCurrentContent(),
95
- );
96
-
97
- expect(() =>
98
- groupAsOtherAdmin.addMemberInternal(admin.id, "writer"),
99
- ).toThrow("Failed to set role");
100
-
101
- expect(groupAsOtherAdmin.get(admin.id)).toEqual("admin");
86
+ const { group, admin, otherAdmin } = groupWithTwoAdminsHighLevel();
87
+
88
+ const groupAsOtherAdmin = expectGroup(
89
+ group.core
90
+ .testWithDifferentAccount(
91
+ otherAdmin,
92
+ Crypto.newRandomSessionID(otherAdmin.id),
93
+ )
94
+ .getCurrentContent(),
95
+ );
96
+
97
+ expect(() => groupAsOtherAdmin.addMemberInternal(admin.id, "writer")).toThrow(
98
+ "Failed to set role",
99
+ );
100
+
101
+ expect(groupAsOtherAdmin.get(admin.id)).toEqual("admin");
102
102
  });
103
103
 
104
104
  test("Admins an add writers to a group, who can't add admins, writers, or readers", () => {
105
- const { groupCore, node } = newGroup();
106
- const writer = node.createAccount();
105
+ const { groupCore, node } = newGroup();
106
+ const writer = node.createAccount();
107
107
 
108
- const groupContent = expectGroup(groupCore.getCurrentContent());
108
+ const groupContent = expectGroup(groupCore.getCurrentContent());
109
109
 
110
- groupContent.set(writer.id, "writer", "trusting");
111
- expect(groupContent.get(writer.id)).toEqual("writer");
110
+ groupContent.set(writer.id, "writer", "trusting");
111
+ expect(groupContent.get(writer.id)).toEqual("writer");
112
112
 
113
- expect(groupContent.get(writer.id)).toEqual("writer");
113
+ expect(groupContent.get(writer.id)).toEqual("writer");
114
114
 
115
- const groupAsWriter = expectGroup(
116
- groupCore
117
- .testWithDifferentAccount(
118
- writer,
119
- Crypto.newRandomSessionID(writer.id),
120
- )
121
- .getCurrentContent(),
122
- );
115
+ const groupAsWriter = expectGroup(
116
+ groupCore
117
+ .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
118
+ .getCurrentContent(),
119
+ );
123
120
 
124
- expect(groupAsWriter.get(writer.id)).toEqual("writer");
121
+ expect(groupAsWriter.get(writer.id)).toEqual("writer");
125
122
 
126
- const otherAgent = node.createAccount();
123
+ const otherAgent = node.createAccount();
127
124
 
128
- groupAsWriter.set(otherAgent.id, "admin", "trusting");
129
- expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
125
+ groupAsWriter.set(otherAgent.id, "admin", "trusting");
126
+ expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
130
127
 
131
- groupAsWriter.set(otherAgent.id, "writer", "trusting");
132
- expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
128
+ groupAsWriter.set(otherAgent.id, "writer", "trusting");
129
+ expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
133
130
 
134
- groupAsWriter.set(otherAgent.id, "reader", "trusting");
135
- expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
131
+ groupAsWriter.set(otherAgent.id, "reader", "trusting");
132
+ expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
136
133
  });
137
134
 
138
135
  test("Admins an add writers to a group, who can't add admins, writers, or readers (high level)", () => {
139
- const { group, node } = newGroupHighLevel();
136
+ const { group, node } = newGroupHighLevel();
140
137
 
141
- const writer = node.createAccount();
138
+ const writer = node.createAccount();
142
139
 
143
- group.addMember(writer, "writer");
144
- expect(group.get(writer.id)).toEqual("writer");
140
+ group.addMember(writer, "writer");
141
+ expect(group.get(writer.id)).toEqual("writer");
145
142
 
146
- const groupAsWriter = expectGroup(
147
- group.core
148
- .testWithDifferentAccount(
149
- writer,
150
- Crypto.newRandomSessionID(writer.id),
151
- )
152
- .getCurrentContent(),
153
- );
143
+ const groupAsWriter = expectGroup(
144
+ group.core
145
+ .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
146
+ .getCurrentContent(),
147
+ );
154
148
 
155
- expect(groupAsWriter.get(writer.id)).toEqual("writer");
149
+ expect(groupAsWriter.get(writer.id)).toEqual("writer");
156
150
 
157
- const otherAgent = groupAsWriter.core.node.createAccount();
151
+ const otherAgent = groupAsWriter.core.node.createAccount();
158
152
 
159
- expect(() => groupAsWriter.addMember(otherAgent, "admin")).toThrow(
160
- "Failed to set role",
161
- );
162
- expect(() => groupAsWriter.addMember(otherAgent, "writer")).toThrow(
163
- "Failed to set role",
164
- );
165
- expect(() => groupAsWriter.addMember(otherAgent, "reader")).toThrow(
166
- "Failed to set role",
167
- );
153
+ expect(() => groupAsWriter.addMember(otherAgent, "admin")).toThrow(
154
+ "Failed to set role",
155
+ );
156
+ expect(() => groupAsWriter.addMember(otherAgent, "writer")).toThrow(
157
+ "Failed to set role",
158
+ );
159
+ expect(() => groupAsWriter.addMember(otherAgent, "reader")).toThrow(
160
+ "Failed to set role",
161
+ );
168
162
 
169
- expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
163
+ expect(groupAsWriter.get(otherAgent.id)).toBeUndefined();
170
164
  });
171
165
 
172
166
  test("Admins can add readers to a group, who can't add admins, writers, or readers", () => {
173
- const { groupCore, node } = newGroup();
174
- const reader = node.createAccount();
167
+ const { groupCore, node } = newGroup();
168
+ const reader = node.createAccount();
175
169
 
176
- const groupContent = expectGroup(groupCore.getCurrentContent());
170
+ const groupContent = expectGroup(groupCore.getCurrentContent());
177
171
 
178
- groupContent.set(reader.id, "reader", "trusting");
179
- expect(groupContent.get(reader.id)).toEqual("reader");
172
+ groupContent.set(reader.id, "reader", "trusting");
173
+ expect(groupContent.get(reader.id)).toEqual("reader");
180
174
 
181
- const groupAsReader = expectGroup(
182
- groupCore
183
- .testWithDifferentAccount(
184
- reader,
185
- Crypto.newRandomSessionID(reader.id),
186
- )
187
- .getCurrentContent(),
188
- );
175
+ const groupAsReader = expectGroup(
176
+ groupCore
177
+ .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
178
+ .getCurrentContent(),
179
+ );
189
180
 
190
- expect(groupAsReader.get(reader.id)).toEqual("reader");
181
+ expect(groupAsReader.get(reader.id)).toEqual("reader");
191
182
 
192
- const otherAgent = node.createAccount();
183
+ const otherAgent = node.createAccount();
193
184
 
194
- groupAsReader.set(otherAgent.id, "admin", "trusting");
195
- expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
185
+ groupAsReader.set(otherAgent.id, "admin", "trusting");
186
+ expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
196
187
 
197
- groupAsReader.set(otherAgent.id, "writer", "trusting");
198
- expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
188
+ groupAsReader.set(otherAgent.id, "writer", "trusting");
189
+ expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
199
190
 
200
- groupAsReader.set(otherAgent.id, "reader", "trusting");
191
+ groupAsReader.set(otherAgent.id, "reader", "trusting");
201
192
 
202
- expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
193
+ expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
203
194
  });
204
195
 
205
196
  test("Admins can add readers to a group, who can't add admins, writers, or readers (high level)", () => {
206
- const { group, node } = newGroupHighLevel();
197
+ const { group, node } = newGroupHighLevel();
207
198
 
208
- const reader = node.createAccount();
199
+ const reader = node.createAccount();
209
200
 
210
- group.addMember(reader, "reader");
211
- expect(group.get(reader.id)).toEqual("reader");
201
+ group.addMember(reader, "reader");
202
+ expect(group.get(reader.id)).toEqual("reader");
212
203
 
213
- const groupAsReader = expectGroup(
214
- group.core
215
- .testWithDifferentAccount(
216
- reader,
217
- Crypto.newRandomSessionID(reader.id),
218
- )
219
- .getCurrentContent(),
220
- );
204
+ const groupAsReader = expectGroup(
205
+ group.core
206
+ .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
207
+ .getCurrentContent(),
208
+ );
221
209
 
222
- expect(groupAsReader.get(reader.id)).toEqual("reader");
210
+ expect(groupAsReader.get(reader.id)).toEqual("reader");
223
211
 
224
- const otherAgent = groupAsReader.core.node.createAccount();
212
+ const otherAgent = groupAsReader.core.node.createAccount();
225
213
 
226
- expect(() => groupAsReader.addMember(otherAgent, "admin")).toThrow(
227
- "Failed to set role",
228
- );
229
- expect(() => groupAsReader.addMember(otherAgent, "writer")).toThrow(
230
- "Failed to set role",
231
- );
232
- expect(() => groupAsReader.addMember(otherAgent, "reader")).toThrow(
233
- "Failed to set role",
234
- );
214
+ expect(() => groupAsReader.addMember(otherAgent, "admin")).toThrow(
215
+ "Failed to set role",
216
+ );
217
+ expect(() => groupAsReader.addMember(otherAgent, "writer")).toThrow(
218
+ "Failed to set role",
219
+ );
220
+ expect(() => groupAsReader.addMember(otherAgent, "reader")).toThrow(
221
+ "Failed to set role",
222
+ );
235
223
 
236
- expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
224
+ expect(groupAsReader.get(otherAgent.id)).toBeUndefined();
237
225
  });
238
226
 
239
227
  test("Admins can write to an object that is owned by their group", () => {
240
- const { node, groupCore } = newGroup();
228
+ const { node, groupCore } = newGroup();
241
229
 
242
- const childObject = node.createCoValue({
243
- type: "comap",
244
- ruleset: { type: "ownedByGroup", group: groupCore.id },
245
- meta: null,
246
- ...Crypto.createdNowUnique(),
247
- });
230
+ const childObject = node.createCoValue({
231
+ type: "comap",
232
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
233
+ meta: null,
234
+ ...Crypto.createdNowUnique(),
235
+ });
248
236
 
249
- const childContent = expectMap(childObject.getCurrentContent());
237
+ const childContent = expectMap(childObject.getCurrentContent());
250
238
 
251
- childContent.set("foo", "bar", "trusting");
252
- expect(childContent.get("foo")).toEqual("bar");
239
+ childContent.set("foo", "bar", "trusting");
240
+ expect(childContent.get("foo")).toEqual("bar");
253
241
  });
254
242
 
255
243
  test("Admins can write to an object that is owned by their group (high level)", () => {
256
- const { group } = newGroupHighLevel();
244
+ const { group } = newGroupHighLevel();
257
245
 
258
- const childObject = group.createMap();
246
+ const childObject = group.createMap();
259
247
 
260
- childObject.set("foo", "bar", "trusting");
261
- expect(childObject.get("foo")).toEqual("bar");
248
+ childObject.set("foo", "bar", "trusting");
249
+ expect(childObject.get("foo")).toEqual("bar");
262
250
  });
263
251
 
264
252
  test("Writers can write to an object that is owned by their group", () => {
265
- const { node, groupCore } = newGroup();
253
+ const { node, groupCore } = newGroup();
266
254
 
267
- const writer = node.createAccount();
255
+ const writer = node.createAccount();
268
256
 
269
- const group = expectGroup(groupCore.getCurrentContent());
270
- group.set(writer.id, "writer", "trusting");
271
- expect(group.get(writer.id)).toEqual("writer");
257
+ const group = expectGroup(groupCore.getCurrentContent());
258
+ group.set(writer.id, "writer", "trusting");
259
+ expect(group.get(writer.id)).toEqual("writer");
272
260
 
273
- const childObject = node.createCoValue({
274
- type: "comap",
275
- ruleset: { type: "ownedByGroup", group: groupCore.id },
276
- meta: null,
277
- ...Crypto.createdNowUnique(),
278
- });
261
+ const childObject = node.createCoValue({
262
+ type: "comap",
263
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
264
+ meta: null,
265
+ ...Crypto.createdNowUnique(),
266
+ });
279
267
 
280
- const childObjectAsWriter = childObject.testWithDifferentAccount(
281
- writer,
282
- Crypto.newRandomSessionID(writer.id),
283
- );
268
+ const childObjectAsWriter = childObject.testWithDifferentAccount(
269
+ writer,
270
+ Crypto.newRandomSessionID(writer.id),
271
+ );
284
272
 
285
- const childContentAsWriter = expectMap(
286
- childObjectAsWriter.getCurrentContent(),
287
- );
273
+ const childContentAsWriter = expectMap(
274
+ childObjectAsWriter.getCurrentContent(),
275
+ );
288
276
 
289
- childContentAsWriter.set("foo", "bar", "trusting");
290
- expect(childContentAsWriter.get("foo")).toEqual("bar");
277
+ childContentAsWriter.set("foo", "bar", "trusting");
278
+ expect(childContentAsWriter.get("foo")).toEqual("bar");
291
279
  });
292
280
 
293
281
  test("Writers can write to an object that is owned by their group (high level)", () => {
294
- const { node, group } = newGroupHighLevel();
282
+ const { node, group } = newGroupHighLevel();
295
283
 
296
- const writer = node.createAccount();
284
+ const writer = node.createAccount();
297
285
 
298
- group.addMember(writer, "writer");
286
+ group.addMember(writer, "writer");
299
287
 
300
- const childObject = group.createMap();
288
+ const childObject = group.createMap();
301
289
 
302
- const childObjectAsWriter = expectMap(
303
- childObject.core
304
- .testWithDifferentAccount(
305
- writer,
306
- Crypto.newRandomSessionID(writer.id),
307
- )
308
- .getCurrentContent(),
309
- );
290
+ const childObjectAsWriter = expectMap(
291
+ childObject.core
292
+ .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
293
+ .getCurrentContent(),
294
+ );
310
295
 
311
- childObjectAsWriter.set("foo", "bar", "trusting");
312
- expect(childObjectAsWriter.get("foo")).toEqual("bar");
296
+ childObjectAsWriter.set("foo", "bar", "trusting");
297
+ expect(childObjectAsWriter.get("foo")).toEqual("bar");
313
298
  });
314
299
 
315
300
  test("Readers can not write to an object that is owned by their group", () => {
316
- const { node, groupCore } = newGroup();
301
+ const { node, groupCore } = newGroup();
317
302
 
318
- const reader = node.createAccount();
303
+ const reader = node.createAccount();
319
304
 
320
- const group = expectGroup(groupCore.getCurrentContent());
321
- group.set(reader.id, "reader", "trusting");
322
- expect(group.get(reader.id)).toEqual("reader");
305
+ const group = expectGroup(groupCore.getCurrentContent());
306
+ group.set(reader.id, "reader", "trusting");
307
+ expect(group.get(reader.id)).toEqual("reader");
323
308
 
324
- const childObject = node.createCoValue({
325
- type: "comap",
326
- ruleset: { type: "ownedByGroup", group: groupCore.id },
327
- meta: null,
328
- ...Crypto.createdNowUnique(),
329
- });
309
+ const childObject = node.createCoValue({
310
+ type: "comap",
311
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
312
+ meta: null,
313
+ ...Crypto.createdNowUnique(),
314
+ });
330
315
 
331
- const childObjectAsReader = childObject.testWithDifferentAccount(
332
- reader,
333
- Crypto.newRandomSessionID(reader.id),
334
- );
316
+ const childObjectAsReader = childObject.testWithDifferentAccount(
317
+ reader,
318
+ Crypto.newRandomSessionID(reader.id),
319
+ );
335
320
 
336
- const childContentAsReader = expectMap(
337
- childObjectAsReader.getCurrentContent(),
338
- );
321
+ const childContentAsReader = expectMap(
322
+ childObjectAsReader.getCurrentContent(),
323
+ );
339
324
 
340
- childContentAsReader.set("foo", "bar", "trusting");
341
- expect(childContentAsReader.get("foo")).toBeUndefined();
325
+ childContentAsReader.set("foo", "bar", "trusting");
326
+ expect(childContentAsReader.get("foo")).toBeUndefined();
342
327
  });
343
328
 
344
329
  test("Readers can not write to an object that is owned by their group (high level)", () => {
345
- const { node, group } = newGroupHighLevel();
330
+ const { node, group } = newGroupHighLevel();
346
331
 
347
- const reader = node.createAccount();
332
+ const reader = node.createAccount();
348
333
 
349
- group.addMember(reader, "reader");
334
+ group.addMember(reader, "reader");
350
335
 
351
- const childObject = group.createMap();
336
+ const childObject = group.createMap();
352
337
 
353
- const childObjectAsReader = expectMap(
354
- childObject.core
355
- .testWithDifferentAccount(
356
- reader,
357
- Crypto.newRandomSessionID(reader.id),
358
- )
359
- .getCurrentContent(),
360
- );
338
+ const childObjectAsReader = expectMap(
339
+ childObject.core
340
+ .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
341
+ .getCurrentContent(),
342
+ );
361
343
 
362
- childObjectAsReader.set("foo", "bar", "trusting");
363
- expect(childObjectAsReader.get("foo")).toBeUndefined();
344
+ childObjectAsReader.set("foo", "bar", "trusting");
345
+ expect(childObjectAsReader.get("foo")).toBeUndefined();
364
346
  });
365
347
 
366
348
  test("Admins can set group read key and then use it to create and read private transactions in owned objects", () => {
367
- const { node, groupCore, admin } = newGroup();
349
+ const { node, groupCore, admin } = newGroup();
368
350
 
369
- const groupContent = expectGroup(groupCore.getCurrentContent());
351
+ const groupContent = expectGroup(groupCore.getCurrentContent());
370
352
 
371
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
372
- const revelation = Crypto.seal({
373
- message: readKey,
374
- from: admin.currentSealerSecret(),
375
- to: admin.currentSealerID()._unsafeUnwrap(),
376
- nOnceMaterial: {
377
- in: groupCore.id,
378
- tx: groupCore.nextTransactionID(),
379
- },
380
- });
353
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
354
+ const revelation = Crypto.seal({
355
+ message: readKey,
356
+ from: admin.currentSealerSecret(),
357
+ to: admin.currentSealerID()._unsafeUnwrap(),
358
+ nOnceMaterial: {
359
+ in: groupCore.id,
360
+ tx: groupCore.nextTransactionID(),
361
+ },
362
+ });
381
363
 
382
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
364
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
383
365
 
384
- expect(groupContent.get(`${readKeyID}_for_${admin.id}`)).toEqual(
385
- revelation,
386
- );
366
+ expect(groupContent.get(`${readKeyID}_for_${admin.id}`)).toEqual(revelation);
387
367
 
388
- groupContent.set("readKey", readKeyID, "trusting");
368
+ groupContent.set("readKey", readKeyID, "trusting");
389
369
 
390
- expect(groupContent.get("readKey")).toEqual(readKeyID);
370
+ expect(groupContent.get("readKey")).toEqual(readKeyID);
391
371
 
392
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
372
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
393
373
 
394
- const childObject = node.createCoValue({
395
- type: "comap",
396
- ruleset: { type: "ownedByGroup", group: groupCore.id },
397
- meta: null,
398
- ...Crypto.createdNowUnique(),
399
- });
374
+ const childObject = node.createCoValue({
375
+ type: "comap",
376
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
377
+ meta: null,
378
+ ...Crypto.createdNowUnique(),
379
+ });
400
380
 
401
- const childContent = expectMap(childObject.getCurrentContent());
381
+ const childContent = expectMap(childObject.getCurrentContent());
402
382
 
403
- childContent.set("foo", "bar", "private");
404
- expect(childContent.get("foo")).toEqual("bar");
383
+ childContent.set("foo", "bar", "private");
384
+ expect(childContent.get("foo")).toEqual("bar");
405
385
  });
406
386
 
407
387
  test("Admins can set group read key and then use it to create and read private transactions in owned objects (high level)", () => {
408
- const { group } = newGroupHighLevel();
388
+ const { group } = newGroupHighLevel();
409
389
 
410
- const childObject = group.createMap();
390
+ const childObject = group.createMap();
411
391
 
412
- childObject.set("foo", "bar", "private");
413
- expect(childObject.get("foo")).toEqual("bar");
392
+ childObject.set("foo", "bar", "private");
393
+ expect(childObject.get("foo")).toEqual("bar");
414
394
  });
415
395
 
416
396
  test("Admins can set group read key and then writers can use it to create and read private transactions in owned objects", () => {
417
- const { node, groupCore, admin } = newGroup();
397
+ const { node, groupCore, admin } = newGroup();
418
398
 
419
- const writer = node.createAccount();
399
+ const writer = node.createAccount();
420
400
 
421
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
401
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
422
402
 
423
- const groupContent = expectGroup(groupCore.getCurrentContent());
403
+ const groupContent = expectGroup(groupCore.getCurrentContent());
424
404
 
425
- groupContent.set(writer.id, "writer", "trusting");
426
- expect(groupContent.get(writer.id)).toEqual("writer");
405
+ groupContent.set(writer.id, "writer", "trusting");
406
+ expect(groupContent.get(writer.id)).toEqual("writer");
427
407
 
428
- const revelation1 = Crypto.seal({
429
- message: readKey,
430
- from: admin.currentSealerSecret(),
431
- to: admin.currentSealerID()._unsafeUnwrap(),
432
- nOnceMaterial: {
433
- in: groupCore.id,
434
- tx: groupCore.nextTransactionID(),
435
- },
436
- });
408
+ const revelation1 = Crypto.seal({
409
+ message: readKey,
410
+ from: admin.currentSealerSecret(),
411
+ to: admin.currentSealerID()._unsafeUnwrap(),
412
+ nOnceMaterial: {
413
+ in: groupCore.id,
414
+ tx: groupCore.nextTransactionID(),
415
+ },
416
+ });
437
417
 
438
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
418
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
439
419
 
440
- const revelation2 = Crypto.seal({
441
- message: readKey,
442
- from: admin.currentSealerSecret(),
443
- to: writer.currentSealerID()._unsafeUnwrap(),
444
- nOnceMaterial: {
445
- in: groupCore.id,
446
- tx: groupCore.nextTransactionID(),
447
- },
448
- });
420
+ const revelation2 = Crypto.seal({
421
+ message: readKey,
422
+ from: admin.currentSealerSecret(),
423
+ to: writer.currentSealerID()._unsafeUnwrap(),
424
+ nOnceMaterial: {
425
+ in: groupCore.id,
426
+ tx: groupCore.nextTransactionID(),
427
+ },
428
+ });
449
429
 
450
- groupContent.set(`${readKeyID}_for_${writer.id}`, revelation2, "trusting");
430
+ groupContent.set(`${readKeyID}_for_${writer.id}`, revelation2, "trusting");
451
431
 
452
- groupContent.set("readKey", readKeyID, "trusting");
432
+ groupContent.set("readKey", readKeyID, "trusting");
453
433
 
454
- const childObject = node.createCoValue({
455
- type: "comap",
456
- ruleset: { type: "ownedByGroup", group: groupCore.id },
457
- meta: null,
458
- ...Crypto.createdNowUnique(),
459
- });
434
+ const childObject = node.createCoValue({
435
+ type: "comap",
436
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
437
+ meta: null,
438
+ ...Crypto.createdNowUnique(),
439
+ });
460
440
 
461
- const childObjectAsWriter = childObject.testWithDifferentAccount(
462
- writer,
463
- Crypto.newRandomSessionID(writer.id),
464
- );
441
+ const childObjectAsWriter = childObject.testWithDifferentAccount(
442
+ writer,
443
+ Crypto.newRandomSessionID(writer.id),
444
+ );
465
445
 
466
- expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
446
+ expect(childObject.getCurrentReadKey().secret).toEqual(readKey);
467
447
 
468
- const childContentAsWriter = expectMap(
469
- childObjectAsWriter.getCurrentContent(),
470
- );
448
+ const childContentAsWriter = expectMap(
449
+ childObjectAsWriter.getCurrentContent(),
450
+ );
471
451
 
472
- childContentAsWriter.set("foo", "bar", "private");
473
- expect(childContentAsWriter.get("foo")).toEqual("bar");
452
+ childContentAsWriter.set("foo", "bar", "private");
453
+ expect(childContentAsWriter.get("foo")).toEqual("bar");
474
454
  });
475
455
 
476
456
  test("Admins can set group read key and then writers can use it to create and read private transactions in owned objects (high level)", () => {
477
- const { node, group } = newGroupHighLevel();
457
+ const { node, group } = newGroupHighLevel();
478
458
 
479
- const writer = node.createAccount();
459
+ const writer = node.createAccount();
480
460
 
481
- group.addMember(writer, "writer");
461
+ group.addMember(writer, "writer");
482
462
 
483
- const childObject = group.createMap();
463
+ const childObject = group.createMap();
484
464
 
485
- const childObjectAsWriter = expectMap(
486
- childObject.core
487
- .testWithDifferentAccount(
488
- writer,
489
- Crypto.newRandomSessionID(writer.id),
490
- )
491
- .getCurrentContent(),
492
- );
465
+ const childObjectAsWriter = expectMap(
466
+ childObject.core
467
+ .testWithDifferentAccount(writer, Crypto.newRandomSessionID(writer.id))
468
+ .getCurrentContent(),
469
+ );
493
470
 
494
- childObjectAsWriter.set("foo", "bar", "private");
495
- expect(childObjectAsWriter.get("foo")).toEqual("bar");
471
+ childObjectAsWriter.set("foo", "bar", "private");
472
+ expect(childObjectAsWriter.get("foo")).toEqual("bar");
496
473
  });
497
474
 
498
475
  test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read", () => {
499
- const { node, groupCore, admin } = newGroup();
476
+ const { node, groupCore, admin } = newGroup();
500
477
 
501
- const reader = node.createAccount();
478
+ const reader = node.createAccount();
502
479
 
503
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
480
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
504
481
 
505
- const groupContent = expectGroup(groupCore.getCurrentContent());
482
+ const groupContent = expectGroup(groupCore.getCurrentContent());
506
483
 
507
- groupContent.set(reader.id, "reader", "trusting");
508
- expect(groupContent.get(reader.id)).toEqual("reader");
484
+ groupContent.set(reader.id, "reader", "trusting");
485
+ expect(groupContent.get(reader.id)).toEqual("reader");
509
486
 
510
- const revelation1 = Crypto.seal({
511
- message: readKey,
512
- from: admin.currentSealerSecret(),
513
- to: admin.currentSealerID()._unsafeUnwrap(),
514
- nOnceMaterial: {
515
- in: groupCore.id,
516
- tx: groupCore.nextTransactionID(),
517
- },
518
- });
487
+ const revelation1 = Crypto.seal({
488
+ message: readKey,
489
+ from: admin.currentSealerSecret(),
490
+ to: admin.currentSealerID()._unsafeUnwrap(),
491
+ nOnceMaterial: {
492
+ in: groupCore.id,
493
+ tx: groupCore.nextTransactionID(),
494
+ },
495
+ });
519
496
 
520
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
497
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
521
498
 
522
- const revelation2 = Crypto.seal({
523
- message: readKey,
524
- from: admin.currentSealerSecret(),
525
- to: reader.currentSealerID()._unsafeUnwrap(),
526
- nOnceMaterial: {
527
- in: groupCore.id,
528
- tx: groupCore.nextTransactionID(),
529
- },
530
- });
499
+ const revelation2 = Crypto.seal({
500
+ message: readKey,
501
+ from: admin.currentSealerSecret(),
502
+ to: reader.currentSealerID()._unsafeUnwrap(),
503
+ nOnceMaterial: {
504
+ in: groupCore.id,
505
+ tx: groupCore.nextTransactionID(),
506
+ },
507
+ });
531
508
 
532
- groupContent.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
509
+ groupContent.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
533
510
 
534
- groupContent.set("readKey", readKeyID, "trusting");
511
+ groupContent.set("readKey", readKeyID, "trusting");
535
512
 
536
- const childObject = node.createCoValue({
537
- type: "comap",
538
- ruleset: { type: "ownedByGroup", group: groupCore.id },
539
- meta: null,
540
- ...Crypto.createdNowUnique(),
541
- });
513
+ const childObject = node.createCoValue({
514
+ type: "comap",
515
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
516
+ meta: null,
517
+ ...Crypto.createdNowUnique(),
518
+ });
542
519
 
543
- const childContent = expectMap(childObject.getCurrentContent());
520
+ const childContent = expectMap(childObject.getCurrentContent());
544
521
 
545
- childContent.set("foo", "bar", "private");
546
- expect(childContent.get("foo")).toEqual("bar");
522
+ childContent.set("foo", "bar", "private");
523
+ expect(childContent.get("foo")).toEqual("bar");
547
524
 
548
- const childObjectAsReader = childObject.testWithDifferentAccount(
549
- reader,
550
- Crypto.newRandomSessionID(reader.id),
551
- );
525
+ const childObjectAsReader = childObject.testWithDifferentAccount(
526
+ reader,
527
+ Crypto.newRandomSessionID(reader.id),
528
+ );
552
529
 
553
- expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
530
+ expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey);
554
531
 
555
- const childContentAsReader = expectMap(
556
- childObjectAsReader.getCurrentContent(),
557
- );
532
+ const childContentAsReader = expectMap(
533
+ childObjectAsReader.getCurrentContent(),
534
+ );
558
535
 
559
- expect(childContentAsReader.get("foo")).toEqual("bar");
536
+ expect(childContentAsReader.get("foo")).toEqual("bar");
560
537
  });
561
538
 
562
539
  test("Admins can set group read key and then use it to create private transactions in owned objects, which readers can read (high level)", () => {
563
- const { node, group } = newGroupHighLevel();
540
+ const { node, group } = newGroupHighLevel();
564
541
 
565
- const reader = node.createAccount();
542
+ const reader = node.createAccount();
566
543
 
567
- group.addMember(reader, "reader");
544
+ group.addMember(reader, "reader");
568
545
 
569
- const childObject = group.createMap();
546
+ const childObject = group.createMap();
570
547
 
571
- childObject.set("foo", "bar", "private");
572
- expect(childObject.get("foo")).toEqual("bar");
548
+ childObject.set("foo", "bar", "private");
549
+ expect(childObject.get("foo")).toEqual("bar");
573
550
 
574
- const childContentAsReader = expectMap(
575
- childObject.core
576
- .testWithDifferentAccount(
577
- reader,
578
- Crypto.newRandomSessionID(reader.id),
579
- )
580
- .getCurrentContent(),
581
- );
551
+ const childContentAsReader = expectMap(
552
+ childObject.core
553
+ .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
554
+ .getCurrentContent(),
555
+ );
582
556
 
583
- expect(childContentAsReader.get("foo")).toEqual("bar");
557
+ expect(childContentAsReader.get("foo")).toEqual("bar");
584
558
  });
585
559
 
586
560
  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", () => {
587
- const { node, groupCore, admin } = newGroup();
561
+ const { node, groupCore, admin } = newGroup();
588
562
 
589
- const reader1 = node.createAccount();
563
+ const reader1 = node.createAccount();
590
564
 
591
- const reader2 = node.createAccount();
565
+ const reader2 = node.createAccount();
592
566
 
593
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
567
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
594
568
 
595
- const groupContent = expectGroup(groupCore.getCurrentContent());
569
+ const groupContent = expectGroup(groupCore.getCurrentContent());
596
570
 
597
- groupContent.set(reader1.id, "reader", "trusting");
598
- expect(groupContent.get(reader1.id)).toEqual("reader");
571
+ groupContent.set(reader1.id, "reader", "trusting");
572
+ expect(groupContent.get(reader1.id)).toEqual("reader");
599
573
 
600
- const revelation1 = Crypto.seal({
601
- message: readKey,
602
- from: admin.currentSealerSecret(),
603
- to: admin.currentSealerID()._unsafeUnwrap(),
604
- nOnceMaterial: {
605
- in: groupCore.id,
606
- tx: groupCore.nextTransactionID(),
607
- },
608
- });
574
+ const revelation1 = Crypto.seal({
575
+ message: readKey,
576
+ from: admin.currentSealerSecret(),
577
+ to: admin.currentSealerID()._unsafeUnwrap(),
578
+ nOnceMaterial: {
579
+ in: groupCore.id,
580
+ tx: groupCore.nextTransactionID(),
581
+ },
582
+ });
609
583
 
610
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
584
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
611
585
 
612
- const revelation2 = Crypto.seal({
613
- message: readKey,
614
- from: admin.currentSealerSecret(),
615
- to: reader1.currentSealerID()._unsafeUnwrap(),
616
- nOnceMaterial: {
617
- in: groupCore.id,
618
- tx: groupCore.nextTransactionID(),
619
- },
620
- });
586
+ const revelation2 = Crypto.seal({
587
+ message: readKey,
588
+ from: admin.currentSealerSecret(),
589
+ to: reader1.currentSealerID()._unsafeUnwrap(),
590
+ nOnceMaterial: {
591
+ in: groupCore.id,
592
+ tx: groupCore.nextTransactionID(),
593
+ },
594
+ });
621
595
 
622
- groupContent.set(`${readKeyID}_for_${reader1.id}`, revelation2, "trusting");
596
+ groupContent.set(`${readKeyID}_for_${reader1.id}`, revelation2, "trusting");
623
597
 
624
- groupContent.set("readKey", readKeyID, "trusting");
598
+ groupContent.set("readKey", readKeyID, "trusting");
625
599
 
626
- const childObject = node.createCoValue({
627
- type: "comap",
628
- ruleset: { type: "ownedByGroup", group: groupCore.id },
629
- meta: null,
630
- ...Crypto.createdNowUnique(),
631
- });
600
+ const childObject = node.createCoValue({
601
+ type: "comap",
602
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
603
+ meta: null,
604
+ ...Crypto.createdNowUnique(),
605
+ });
632
606
 
633
- const childContent = expectMap(childObject.getCurrentContent());
607
+ const childContent = expectMap(childObject.getCurrentContent());
634
608
 
635
- childContent.set("foo", "bar", "private");
636
- expect(childContent.get("foo")).toEqual("bar");
609
+ childContent.set("foo", "bar", "private");
610
+ expect(childContent.get("foo")).toEqual("bar");
637
611
 
638
- const childObjectAsReader1 = childObject.testWithDifferentAccount(
639
- reader1,
640
- Crypto.newRandomSessionID(reader1.id),
641
- );
612
+ const childObjectAsReader1 = childObject.testWithDifferentAccount(
613
+ reader1,
614
+ Crypto.newRandomSessionID(reader1.id),
615
+ );
642
616
 
643
- expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
617
+ expect(childObjectAsReader1.getCurrentReadKey().secret).toEqual(readKey);
644
618
 
645
- const childContentAsReader1 = expectMap(
646
- childObjectAsReader1.getCurrentContent(),
647
- );
619
+ const childContentAsReader1 = expectMap(
620
+ childObjectAsReader1.getCurrentContent(),
621
+ );
648
622
 
649
- expect(childContentAsReader1.get("foo")).toEqual("bar");
623
+ expect(childContentAsReader1.get("foo")).toEqual("bar");
650
624
 
651
- const revelation3 = Crypto.seal({
652
- message: readKey,
653
- from: admin.currentSealerSecret(),
654
- to: reader2.currentSealerID()._unsafeUnwrap(),
655
- nOnceMaterial: {
656
- in: groupCore.id,
657
- tx: groupCore.nextTransactionID(),
658
- },
659
- });
625
+ const revelation3 = Crypto.seal({
626
+ message: readKey,
627
+ from: admin.currentSealerSecret(),
628
+ to: reader2.currentSealerID()._unsafeUnwrap(),
629
+ nOnceMaterial: {
630
+ in: groupCore.id,
631
+ tx: groupCore.nextTransactionID(),
632
+ },
633
+ });
660
634
 
661
- groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
635
+ groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
662
636
 
663
- const childObjectAsReader2 = childObject.testWithDifferentAccount(
664
- reader2,
665
- Crypto.newRandomSessionID(reader2.id),
666
- );
637
+ const childObjectAsReader2 = childObject.testWithDifferentAccount(
638
+ reader2,
639
+ Crypto.newRandomSessionID(reader2.id),
640
+ );
667
641
 
668
- expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
642
+ expect(childObjectAsReader2.getCurrentReadKey().secret).toEqual(readKey);
669
643
 
670
- const childContentAsReader2 = expectMap(
671
- childObjectAsReader2.getCurrentContent(),
672
- );
644
+ const childContentAsReader2 = expectMap(
645
+ childObjectAsReader2.getCurrentContent(),
646
+ );
673
647
 
674
- expect(childContentAsReader2.get("foo")).toEqual("bar");
648
+ expect(childContentAsReader2.get("foo")).toEqual("bar");
675
649
  });
676
650
 
677
651
  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)", () => {
678
- const { node, group } = newGroupHighLevel();
652
+ const { node, group } = newGroupHighLevel();
679
653
 
680
- const reader1 = node.createAccount();
654
+ const reader1 = node.createAccount();
681
655
 
682
- const reader2 = node.createAccount();
656
+ const reader2 = node.createAccount();
683
657
 
684
- group.addMember(reader1, "reader");
658
+ group.addMember(reader1, "reader");
685
659
 
686
- const childObject = group.createMap();
660
+ const childObject = group.createMap();
687
661
 
688
- childObject.set("foo", "bar", "private");
689
- expect(childObject.get("foo")).toEqual("bar");
662
+ childObject.set("foo", "bar", "private");
663
+ expect(childObject.get("foo")).toEqual("bar");
690
664
 
691
- const childContentAsReader1 = expectMap(
692
- childObject.core
693
- .testWithDifferentAccount(
694
- reader1,
695
- Crypto.newRandomSessionID(reader1.id),
696
- )
697
- .getCurrentContent(),
698
- );
665
+ const childContentAsReader1 = expectMap(
666
+ childObject.core
667
+ .testWithDifferentAccount(reader1, Crypto.newRandomSessionID(reader1.id))
668
+ .getCurrentContent(),
669
+ );
699
670
 
700
- expect(childContentAsReader1.get("foo")).toEqual("bar");
671
+ expect(childContentAsReader1.get("foo")).toEqual("bar");
701
672
 
702
- group.addMember(reader2, "reader");
673
+ group.addMember(reader2, "reader");
703
674
 
704
- const childContentAsReader2 = expectMap(
705
- childObject.core
706
- .testWithDifferentAccount(
707
- reader2,
708
- Crypto.newRandomSessionID(reader2.id),
709
- )
710
- .getCurrentContent(),
711
- );
675
+ const childContentAsReader2 = expectMap(
676
+ childObject.core
677
+ .testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
678
+ .getCurrentContent(),
679
+ );
712
680
 
713
- expect(childContentAsReader2.get("foo")).toEqual("bar");
681
+ expect(childContentAsReader2.get("foo")).toEqual("bar");
714
682
  });
715
683
 
716
684
  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", () => {
717
- const { node, groupCore, admin } = newGroup();
685
+ const { node, groupCore, admin } = newGroup();
718
686
 
719
- const groupContent = expectGroup(groupCore.getCurrentContent());
687
+ const groupContent = expectGroup(groupCore.getCurrentContent());
720
688
 
721
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
722
- const revelation1 = Crypto.seal({
723
- message: readKey,
724
- from: admin.currentSealerSecret(),
725
- to: admin.currentSealerID()._unsafeUnwrap(),
726
- nOnceMaterial: {
727
- in: groupCore.id,
728
- tx: groupCore.nextTransactionID(),
729
- },
730
- });
689
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
690
+ const revelation1 = Crypto.seal({
691
+ message: readKey,
692
+ from: admin.currentSealerSecret(),
693
+ to: admin.currentSealerID()._unsafeUnwrap(),
694
+ nOnceMaterial: {
695
+ in: groupCore.id,
696
+ tx: groupCore.nextTransactionID(),
697
+ },
698
+ });
731
699
 
732
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
700
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
733
701
 
734
- groupContent.set("readKey", readKeyID, "trusting");
735
- expect(groupContent.get("readKey")).toEqual(readKeyID);
736
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
702
+ groupContent.set("readKey", readKeyID, "trusting");
703
+ expect(groupContent.get("readKey")).toEqual(readKeyID);
704
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
737
705
 
738
- const childObject = node.createCoValue({
739
- type: "comap",
740
- ruleset: { type: "ownedByGroup", group: groupCore.id },
741
- meta: null,
742
- ...Crypto.createdNowUnique(),
743
- });
706
+ const childObject = node.createCoValue({
707
+ type: "comap",
708
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
709
+ meta: null,
710
+ ...Crypto.createdNowUnique(),
711
+ });
744
712
 
745
- const childContent = expectMap(childObject.getCurrentContent());
713
+ const childContent = expectMap(childObject.getCurrentContent());
746
714
 
747
- childContent.set("foo", "bar", "private");
748
- expect(childContent.get("foo")).toEqual("bar");
715
+ childContent.set("foo", "bar", "private");
716
+ expect(childContent.get("foo")).toEqual("bar");
749
717
 
750
- const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
718
+ const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
751
719
 
752
- const revelation2 = Crypto.seal({
753
- message: readKey2,
754
- from: admin.currentSealerSecret(),
755
- to: admin.currentSealerID()._unsafeUnwrap(),
756
- nOnceMaterial: {
757
- in: groupCore.id,
758
- tx: groupCore.nextTransactionID(),
759
- },
760
- });
720
+ const revelation2 = Crypto.seal({
721
+ message: readKey2,
722
+ from: admin.currentSealerSecret(),
723
+ to: admin.currentSealerID()._unsafeUnwrap(),
724
+ nOnceMaterial: {
725
+ in: groupCore.id,
726
+ tx: groupCore.nextTransactionID(),
727
+ },
728
+ });
761
729
 
762
- groupContent.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
730
+ groupContent.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
763
731
 
764
- groupContent.set("readKey", readKeyID2, "trusting");
765
- expect(groupContent.get("readKey")).toEqual(readKeyID2);
766
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
732
+ groupContent.set("readKey", readKeyID2, "trusting");
733
+ expect(groupContent.get("readKey")).toEqual(readKeyID2);
734
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
767
735
 
768
- expect(childContent.get("foo")).toEqual("bar");
736
+ expect(childContent.get("foo")).toEqual("bar");
769
737
 
770
- childContent.set("foo2", "bar2", "private");
771
- expect(childContent.get("foo2")).toEqual("bar2");
738
+ childContent.set("foo2", "bar2", "private");
739
+ expect(childContent.get("foo2")).toEqual("bar2");
772
740
  });
773
741
 
774
742
  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)", () => {
775
- const { group } = newGroupHighLevel();
743
+ const { group } = newGroupHighLevel();
776
744
 
777
- const childObject = group.createMap();
745
+ const childObject = group.createMap();
778
746
 
779
- const firstReadKey = childObject.core.getCurrentReadKey();
747
+ const firstReadKey = childObject.core.getCurrentReadKey();
780
748
 
781
- childObject.set("foo", "bar", "private");
782
- expect(childObject.get("foo")).toEqual("bar");
749
+ childObject.set("foo", "bar", "private");
750
+ expect(childObject.get("foo")).toEqual("bar");
783
751
 
784
- group.rotateReadKey();
752
+ group.rotateReadKey();
785
753
 
786
- expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
754
+ expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
787
755
 
788
- childObject.set("foo2", "bar2", "private");
789
- expect(childObject.get("foo2")).toEqual("bar2");
756
+ childObject.set("foo2", "bar2", "private");
757
+ expect(childObject.get("foo2")).toEqual("bar2");
790
758
  });
791
759
 
792
760
  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", () => {
793
- const { node, groupCore, admin } = newGroup();
794
-
795
- const childObject = node.createCoValue({
796
- type: "comap",
797
- ruleset: { type: "ownedByGroup", group: groupCore.id },
798
- meta: null,
799
- ...Crypto.createdNowUnique(),
800
- });
801
-
802
- const groupContent = expectGroup(groupCore.getCurrentContent());
803
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
804
-
805
- const revelation = Crypto.seal({
806
- message: readKey,
807
- from: admin.currentSealerSecret(),
808
- to: admin.currentSealerID()._unsafeUnwrap(),
809
- nOnceMaterial: {
810
- in: groupCore.id,
811
- tx: groupCore.nextTransactionID(),
812
- },
813
- });
814
-
815
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
816
-
817
- groupContent.set("readKey", readKeyID, "trusting");
818
- expect(groupContent.get("readKey")).toEqual(readKeyID);
819
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
820
-
821
- const childContent = expectMap(childObject.getCurrentContent());
822
-
823
- childContent.set("foo", "bar", "private");
824
- expect(childContent.get("foo")).toEqual("bar");
825
-
826
- expect(childContent.get("foo")).toEqual("bar");
827
-
828
- const reader = node.createAccount();
829
-
830
- const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
831
-
832
- const revelation2 = Crypto.seal({
833
- message: readKey2,
834
- from: admin.currentSealerSecret(),
835
- to: admin.currentSealerID()._unsafeUnwrap(),
836
- nOnceMaterial: {
837
- in: groupCore.id,
838
- tx: groupCore.nextTransactionID(),
839
- },
840
- });
841
-
842
- groupContent.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
843
-
844
- const revelation3 = Crypto.seal({
845
- message: readKey2,
846
- from: admin.currentSealerSecret(),
847
- to: reader.currentSealerID()._unsafeUnwrap(),
848
- nOnceMaterial: {
849
- in: groupCore.id,
850
- tx: groupCore.nextTransactionID(),
851
- },
852
- });
853
-
854
- groupContent.set(`${readKeyID2}_for_${reader.id}`, revelation3, "trusting");
855
-
856
- groupContent.set(
857
- `${readKeyID}_for_${readKeyID2}`,
858
- Crypto.encryptKeySecret({
859
- toEncrypt: { id: readKeyID, secret: readKey },
860
- encrypting: { id: readKeyID2, secret: readKey2 },
861
- }).encrypted,
862
- "trusting",
863
- );
864
-
865
- groupContent.set("readKey", readKeyID2, "trusting");
866
-
867
- expect(groupContent.get("readKey")).toEqual(readKeyID2);
868
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
869
-
870
- groupContent.set(reader.id, "reader", "trusting");
871
- expect(groupContent.get(reader.id)).toEqual("reader");
872
-
873
- childContent.set("foo2", "bar2", "private");
874
- expect(childContent.get("foo2")).toEqual("bar2");
875
-
876
- const childObjectAsReader = childObject.testWithDifferentAccount(
877
- reader,
878
- Crypto.newRandomSessionID(reader.id),
879
- );
880
-
881
- expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
882
-
883
- const childContentAsReader = expectMap(
884
- childObjectAsReader.getCurrentContent(),
885
- );
886
-
887
- expect(childContentAsReader.get("foo")).toEqual("bar");
888
- expect(childContentAsReader.get("foo2")).toEqual("bar2");
761
+ const { node, groupCore, admin } = newGroup();
762
+
763
+ const childObject = node.createCoValue({
764
+ type: "comap",
765
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
766
+ meta: null,
767
+ ...Crypto.createdNowUnique(),
768
+ });
769
+
770
+ const groupContent = expectGroup(groupCore.getCurrentContent());
771
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
772
+
773
+ const revelation = Crypto.seal({
774
+ message: readKey,
775
+ from: admin.currentSealerSecret(),
776
+ to: admin.currentSealerID()._unsafeUnwrap(),
777
+ nOnceMaterial: {
778
+ in: groupCore.id,
779
+ tx: groupCore.nextTransactionID(),
780
+ },
781
+ });
782
+
783
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
784
+
785
+ groupContent.set("readKey", readKeyID, "trusting");
786
+ expect(groupContent.get("readKey")).toEqual(readKeyID);
787
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
788
+
789
+ const childContent = expectMap(childObject.getCurrentContent());
790
+
791
+ childContent.set("foo", "bar", "private");
792
+ expect(childContent.get("foo")).toEqual("bar");
793
+
794
+ expect(childContent.get("foo")).toEqual("bar");
795
+
796
+ const reader = node.createAccount();
797
+
798
+ const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
799
+
800
+ const revelation2 = Crypto.seal({
801
+ message: readKey2,
802
+ from: admin.currentSealerSecret(),
803
+ to: admin.currentSealerID()._unsafeUnwrap(),
804
+ nOnceMaterial: {
805
+ in: groupCore.id,
806
+ tx: groupCore.nextTransactionID(),
807
+ },
808
+ });
809
+
810
+ groupContent.set(`${readKeyID2}_for_${admin.id}`, revelation2, "trusting");
811
+
812
+ const revelation3 = Crypto.seal({
813
+ message: readKey2,
814
+ from: admin.currentSealerSecret(),
815
+ to: reader.currentSealerID()._unsafeUnwrap(),
816
+ nOnceMaterial: {
817
+ in: groupCore.id,
818
+ tx: groupCore.nextTransactionID(),
819
+ },
820
+ });
821
+
822
+ groupContent.set(`${readKeyID2}_for_${reader.id}`, revelation3, "trusting");
823
+
824
+ groupContent.set(
825
+ `${readKeyID}_for_${readKeyID2}`,
826
+ Crypto.encryptKeySecret({
827
+ toEncrypt: { id: readKeyID, secret: readKey },
828
+ encrypting: { id: readKeyID2, secret: readKey2 },
829
+ }).encrypted,
830
+ "trusting",
831
+ );
832
+
833
+ groupContent.set("readKey", readKeyID2, "trusting");
834
+
835
+ expect(groupContent.get("readKey")).toEqual(readKeyID2);
836
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
837
+
838
+ groupContent.set(reader.id, "reader", "trusting");
839
+ expect(groupContent.get(reader.id)).toEqual("reader");
840
+
841
+ childContent.set("foo2", "bar2", "private");
842
+ expect(childContent.get("foo2")).toEqual("bar2");
843
+
844
+ const childObjectAsReader = childObject.testWithDifferentAccount(
845
+ reader,
846
+ Crypto.newRandomSessionID(reader.id),
847
+ );
848
+
849
+ expect(childObjectAsReader.getCurrentReadKey().secret).toEqual(readKey2);
850
+
851
+ const childContentAsReader = expectMap(
852
+ childObjectAsReader.getCurrentContent(),
853
+ );
854
+
855
+ expect(childContentAsReader.get("foo")).toEqual("bar");
856
+ expect(childContentAsReader.get("foo2")).toEqual("bar2");
889
857
  });
890
858
 
891
859
  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)", () => {
892
- const { node, group } = newGroupHighLevel();
860
+ const { node, group } = newGroupHighLevel();
893
861
 
894
- const childObject = group.createMap();
862
+ const childObject = group.createMap();
895
863
 
896
- const firstReadKey = childObject.core.getCurrentReadKey();
864
+ const firstReadKey = childObject.core.getCurrentReadKey();
897
865
 
898
- childObject.set("foo", "bar", "private");
899
- expect(childObject.get("foo")).toEqual("bar");
866
+ childObject.set("foo", "bar", "private");
867
+ expect(childObject.get("foo")).toEqual("bar");
900
868
 
901
- expect(childObject.get("foo")).toEqual("bar");
869
+ expect(childObject.get("foo")).toEqual("bar");
902
870
 
903
- group.rotateReadKey();
871
+ group.rotateReadKey();
904
872
 
905
- expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
873
+ expect(childObject.core.getCurrentReadKey()).not.toEqual(firstReadKey);
906
874
 
907
- const reader = node.createAccount();
875
+ const reader = node.createAccount();
908
876
 
909
- group.addMember(reader, "reader");
877
+ group.addMember(reader, "reader");
910
878
 
911
- childObject.set("foo2", "bar2", "private");
912
- expect(childObject.get("foo2")).toEqual("bar2");
879
+ childObject.set("foo2", "bar2", "private");
880
+ expect(childObject.get("foo2")).toEqual("bar2");
913
881
 
914
- const childContentAsReader = expectMap(
915
- childObject.core
916
- .testWithDifferentAccount(
917
- reader,
918
- Crypto.newRandomSessionID(reader.id),
919
- )
920
- .getCurrentContent(),
921
- );
882
+ const childContentAsReader = expectMap(
883
+ childObject.core
884
+ .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
885
+ .getCurrentContent(),
886
+ );
922
887
 
923
- expect(childContentAsReader.get("foo")).toEqual("bar");
924
- expect(childContentAsReader.get("foo2")).toEqual("bar2");
888
+ expect(childContentAsReader.get("foo")).toEqual("bar");
889
+ expect(childContentAsReader.get("foo2")).toEqual("bar2");
925
890
  });
926
891
 
927
892
  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", () => {
928
- const { node, groupCore, admin } = newGroup();
929
-
930
- const childObject = node.createCoValue({
931
- type: "comap",
932
- ruleset: { type: "ownedByGroup", group: groupCore.id },
933
- meta: null,
934
- ...Crypto.createdNowUnique(),
935
- });
936
-
937
- const groupContent = expectGroup(groupCore.getCurrentContent());
938
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
939
- const reader = node.createAccount();
940
-
941
- const reader2 = node.createAccount();
942
-
943
- const revelation1 = Crypto.seal({
944
- message: readKey,
945
- from: admin.currentSealerSecret(),
946
- to: admin.currentSealerID()._unsafeUnwrap(),
947
- nOnceMaterial: {
948
- in: groupCore.id,
949
- tx: groupCore.nextTransactionID(),
950
- },
951
- });
952
-
953
- groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
954
-
955
- const revelation2 = Crypto.seal({
956
- message: readKey,
957
- from: admin.currentSealerSecret(),
958
- to: reader.currentSealerID()._unsafeUnwrap(),
959
- nOnceMaterial: {
960
- in: groupCore.id,
961
- tx: groupCore.nextTransactionID(),
962
- },
963
- });
964
-
965
- groupContent.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
966
-
967
- const revelation3 = Crypto.seal({
968
- message: readKey,
969
- from: admin.currentSealerSecret(),
970
- to: reader2.currentSealerID()._unsafeUnwrap(),
971
- nOnceMaterial: {
972
- in: groupCore.id,
973
- tx: groupCore.nextTransactionID(),
974
- },
975
- });
976
-
977
- groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
978
-
979
- groupContent.set("readKey", readKeyID, "trusting");
980
- expect(groupContent.get("readKey")).toEqual(readKeyID);
981
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
982
-
983
- groupContent.set(reader.id, "reader", "trusting");
984
- expect(groupContent.get(reader.id)).toEqual("reader");
985
- groupContent.set(reader2.id, "reader", "trusting");
986
- expect(groupContent.get(reader2.id)).toEqual("reader");
987
-
988
- const childContent = expectMap(childObject.getCurrentContent());
989
-
990
- childContent.set("foo", "bar", "private");
991
- expect(childContent.get("foo")).toEqual("bar");
992
-
993
- let childObjectAsReader = childObject.testWithDifferentAccount(
994
- reader,
995
- Crypto.newRandomSessionID(reader.id),
996
- );
997
-
998
- expect(
999
- expectMap(childObjectAsReader.getCurrentContent()).get("foo"),
1000
- ).toEqual("bar");
1001
-
1002
- let childObjectAsReader2 = childObject.testWithDifferentAccount(
1003
- reader,
1004
- Crypto.newRandomSessionID(reader.id),
1005
- );
1006
-
1007
- expect(
1008
- expectMap(childObjectAsReader2.getCurrentContent()).get("foo"),
1009
- ).toEqual("bar");
1010
-
1011
- const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
1012
-
1013
- const newRevelation1 = Crypto.seal({
1014
- message: readKey2,
1015
- from: admin.currentSealerSecret(),
1016
- to: admin.currentSealerID()._unsafeUnwrap(),
1017
- nOnceMaterial: {
1018
- in: groupCore.id,
1019
- tx: groupCore.nextTransactionID(),
1020
- },
1021
- });
1022
-
1023
- groupContent.set(
1024
- `${readKeyID2}_for_${admin.id}`,
1025
- newRevelation1,
1026
- "trusting",
1027
- );
1028
-
1029
- const newRevelation2 = Crypto.seal({
1030
- message: readKey2,
1031
- from: admin.currentSealerSecret(),
1032
- to: reader2.currentSealerID()._unsafeUnwrap(),
1033
- nOnceMaterial: {
1034
- in: groupCore.id,
1035
- tx: groupCore.nextTransactionID(),
1036
- },
1037
- });
1038
-
1039
- groupContent.set(
1040
- `${readKeyID2}_for_${reader2.id}`,
1041
- newRevelation2,
1042
- "trusting",
1043
- );
1044
-
1045
- groupContent.set("readKey", readKeyID2, "trusting");
1046
- expect(groupContent.get("readKey")).toEqual(readKeyID2);
1047
- expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
1048
-
1049
- groupContent.set(reader.id, "revoked", "trusting");
1050
- // expect(editable.get(reader.id)).toEqual("revoked");
1051
-
1052
- expect(childObject.getCurrentReadKey().secret).toEqual(readKey2);
1053
-
1054
- childContent.set("foo2", "bar2", "private");
1055
- expect(childContent.get("foo2")).toEqual("bar2");
1056
-
1057
- // TODO: make sure these instances of coValues sync between each other so this isn't necessary?
1058
- childObjectAsReader = childObject.testWithDifferentAccount(
1059
- reader,
1060
- Crypto.newRandomSessionID(reader.id),
1061
- );
1062
- childObjectAsReader2 = childObject.testWithDifferentAccount(
1063
- reader2,
1064
- Crypto.newRandomSessionID(reader2.id),
1065
- );
1066
-
1067
- expect(
1068
- expectMap(childObjectAsReader.getCurrentContent()).get("foo2"),
1069
- ).toBeUndefined();
1070
- expect(
1071
- expectMap(childObjectAsReader2.getCurrentContent()).get("foo2"),
1072
- ).toEqual("bar2");
893
+ const { node, groupCore, admin } = newGroup();
894
+
895
+ const childObject = node.createCoValue({
896
+ type: "comap",
897
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
898
+ meta: null,
899
+ ...Crypto.createdNowUnique(),
900
+ });
901
+
902
+ const groupContent = expectGroup(groupCore.getCurrentContent());
903
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
904
+ const reader = node.createAccount();
905
+
906
+ const reader2 = node.createAccount();
907
+
908
+ const revelation1 = Crypto.seal({
909
+ message: readKey,
910
+ from: admin.currentSealerSecret(),
911
+ to: admin.currentSealerID()._unsafeUnwrap(),
912
+ nOnceMaterial: {
913
+ in: groupCore.id,
914
+ tx: groupCore.nextTransactionID(),
915
+ },
916
+ });
917
+
918
+ groupContent.set(`${readKeyID}_for_${admin.id}`, revelation1, "trusting");
919
+
920
+ const revelation2 = Crypto.seal({
921
+ message: readKey,
922
+ from: admin.currentSealerSecret(),
923
+ to: reader.currentSealerID()._unsafeUnwrap(),
924
+ nOnceMaterial: {
925
+ in: groupCore.id,
926
+ tx: groupCore.nextTransactionID(),
927
+ },
928
+ });
929
+
930
+ groupContent.set(`${readKeyID}_for_${reader.id}`, revelation2, "trusting");
931
+
932
+ const revelation3 = Crypto.seal({
933
+ message: readKey,
934
+ from: admin.currentSealerSecret(),
935
+ to: reader2.currentSealerID()._unsafeUnwrap(),
936
+ nOnceMaterial: {
937
+ in: groupCore.id,
938
+ tx: groupCore.nextTransactionID(),
939
+ },
940
+ });
941
+
942
+ groupContent.set(`${readKeyID}_for_${reader2.id}`, revelation3, "trusting");
943
+
944
+ groupContent.set("readKey", readKeyID, "trusting");
945
+ expect(groupContent.get("readKey")).toEqual(readKeyID);
946
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey);
947
+
948
+ groupContent.set(reader.id, "reader", "trusting");
949
+ expect(groupContent.get(reader.id)).toEqual("reader");
950
+ groupContent.set(reader2.id, "reader", "trusting");
951
+ expect(groupContent.get(reader2.id)).toEqual("reader");
952
+
953
+ const childContent = expectMap(childObject.getCurrentContent());
954
+
955
+ childContent.set("foo", "bar", "private");
956
+ expect(childContent.get("foo")).toEqual("bar");
957
+
958
+ let childObjectAsReader = childObject.testWithDifferentAccount(
959
+ reader,
960
+ Crypto.newRandomSessionID(reader.id),
961
+ );
962
+
963
+ expect(expectMap(childObjectAsReader.getCurrentContent()).get("foo")).toEqual(
964
+ "bar",
965
+ );
966
+
967
+ let childObjectAsReader2 = childObject.testWithDifferentAccount(
968
+ reader,
969
+ Crypto.newRandomSessionID(reader.id),
970
+ );
971
+
972
+ expect(
973
+ expectMap(childObjectAsReader2.getCurrentContent()).get("foo"),
974
+ ).toEqual("bar");
975
+
976
+ const { secret: readKey2, id: readKeyID2 } = Crypto.newRandomKeySecret();
977
+
978
+ const newRevelation1 = Crypto.seal({
979
+ message: readKey2,
980
+ from: admin.currentSealerSecret(),
981
+ to: admin.currentSealerID()._unsafeUnwrap(),
982
+ nOnceMaterial: {
983
+ in: groupCore.id,
984
+ tx: groupCore.nextTransactionID(),
985
+ },
986
+ });
987
+
988
+ groupContent.set(`${readKeyID2}_for_${admin.id}`, newRevelation1, "trusting");
989
+
990
+ const newRevelation2 = Crypto.seal({
991
+ message: readKey2,
992
+ from: admin.currentSealerSecret(),
993
+ to: reader2.currentSealerID()._unsafeUnwrap(),
994
+ nOnceMaterial: {
995
+ in: groupCore.id,
996
+ tx: groupCore.nextTransactionID(),
997
+ },
998
+ });
999
+
1000
+ groupContent.set(
1001
+ `${readKeyID2}_for_${reader2.id}`,
1002
+ newRevelation2,
1003
+ "trusting",
1004
+ );
1005
+
1006
+ groupContent.set("readKey", readKeyID2, "trusting");
1007
+ expect(groupContent.get("readKey")).toEqual(readKeyID2);
1008
+ expect(groupCore.getCurrentReadKey().secret).toEqual(readKey2);
1009
+
1010
+ groupContent.set(reader.id, "revoked", "trusting");
1011
+ // expect(editable.get(reader.id)).toEqual("revoked");
1012
+
1013
+ expect(childObject.getCurrentReadKey().secret).toEqual(readKey2);
1014
+
1015
+ childContent.set("foo2", "bar2", "private");
1016
+ expect(childContent.get("foo2")).toEqual("bar2");
1017
+
1018
+ // TODO: make sure these instances of coValues sync between each other so this isn't necessary?
1019
+ childObjectAsReader = childObject.testWithDifferentAccount(
1020
+ reader,
1021
+ Crypto.newRandomSessionID(reader.id),
1022
+ );
1023
+ childObjectAsReader2 = childObject.testWithDifferentAccount(
1024
+ reader2,
1025
+ Crypto.newRandomSessionID(reader2.id),
1026
+ );
1027
+
1028
+ expect(
1029
+ expectMap(childObjectAsReader.getCurrentContent()).get("foo2"),
1030
+ ).toBeUndefined();
1031
+ expect(
1032
+ expectMap(childObjectAsReader2.getCurrentContent()).get("foo2"),
1033
+ ).toEqual("bar2");
1073
1034
  });
1074
1035
 
1075
1036
  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)", () => {
1076
- const { node, group } = newGroupHighLevel();
1037
+ const { node, group } = newGroupHighLevel();
1077
1038
 
1078
- const childObject = group.createMap();
1039
+ const childObject = group.createMap();
1079
1040
 
1080
- childObject.set("foo", "bar", "private");
1081
- expect(childObject.get("foo")).toEqual("bar");
1041
+ childObject.set("foo", "bar", "private");
1042
+ expect(childObject.get("foo")).toEqual("bar");
1082
1043
 
1083
- expect(childObject.get("foo")).toEqual("bar");
1044
+ expect(childObject.get("foo")).toEqual("bar");
1084
1045
 
1085
- group.rotateReadKey();
1046
+ group.rotateReadKey();
1086
1047
 
1087
- const secondReadKey = childObject.core.getCurrentReadKey();
1048
+ const secondReadKey = childObject.core.getCurrentReadKey();
1088
1049
 
1089
- const reader = node.createAccount();
1050
+ const reader = node.createAccount();
1090
1051
 
1091
- const reader2 = node.createAccount();
1052
+ const reader2 = node.createAccount();
1092
1053
 
1093
- group.addMember(reader, "reader");
1094
- group.addMember(reader2, "reader");
1054
+ group.addMember(reader, "reader");
1055
+ group.addMember(reader2, "reader");
1095
1056
 
1096
- childObject.set("foo2", "bar2", "private");
1097
- expect(childObject.get("foo2")).toEqual("bar2");
1057
+ childObject.set("foo2", "bar2", "private");
1058
+ expect(childObject.get("foo2")).toEqual("bar2");
1098
1059
 
1099
- group.removeMember(reader);
1060
+ group.removeMember(reader);
1100
1061
 
1101
- expect(childObject.core.getCurrentReadKey()).not.toEqual(secondReadKey);
1062
+ expect(childObject.core.getCurrentReadKey()).not.toEqual(secondReadKey);
1102
1063
 
1103
- childObject.set("foo3", "bar3", "private");
1104
- expect(childObject.get("foo3")).toEqual("bar3");
1064
+ childObject.set("foo3", "bar3", "private");
1065
+ expect(childObject.get("foo3")).toEqual("bar3");
1105
1066
 
1106
- const childContentAsReader2 = expectMap(
1107
- childObject.core
1108
- .testWithDifferentAccount(
1109
- reader2,
1110
- Crypto.newRandomSessionID(reader2.id),
1111
- )
1112
- .getCurrentContent(),
1113
- );
1067
+ const childContentAsReader2 = expectMap(
1068
+ childObject.core
1069
+ .testWithDifferentAccount(reader2, Crypto.newRandomSessionID(reader2.id))
1070
+ .getCurrentContent(),
1071
+ );
1114
1072
 
1115
- expect(childContentAsReader2.get("foo")).toEqual("bar");
1116
- expect(childContentAsReader2.get("foo2")).toEqual("bar2");
1117
- expect(childContentAsReader2.get("foo3")).toEqual("bar3");
1073
+ expect(childContentAsReader2.get("foo")).toEqual("bar");
1074
+ expect(childContentAsReader2.get("foo2")).toEqual("bar2");
1075
+ expect(childContentAsReader2.get("foo3")).toEqual("bar3");
1118
1076
 
1119
- expect(
1120
- expectMap(
1121
- childObject.core
1122
- .testWithDifferentAccount(
1123
- reader,
1124
- Crypto.newRandomSessionID(reader.id),
1125
- )
1126
- .getCurrentContent(),
1127
- ).get("foo3"),
1128
- ).toBeUndefined();
1077
+ expect(
1078
+ expectMap(
1079
+ childObject.core
1080
+ .testWithDifferentAccount(reader, Crypto.newRandomSessionID(reader.id))
1081
+ .getCurrentContent(),
1082
+ ).get("foo3"),
1083
+ ).toBeUndefined();
1129
1084
  });
1130
1085
 
1131
1086
  test("Can create two owned objects in the same group and they will have different ids", () => {
1132
- const { node, groupCore } = newGroup();
1133
-
1134
- const childObject1 = node.createCoValue({
1135
- type: "comap",
1136
- ruleset: { type: "ownedByGroup", group: groupCore.id },
1137
- meta: null,
1138
- ...Crypto.createdNowUnique(),
1139
- });
1140
-
1141
- const childObject2 = node.createCoValue({
1142
- type: "comap",
1143
- ruleset: { type: "ownedByGroup", group: groupCore.id },
1144
- meta: null,
1145
- ...Crypto.createdNowUnique(),
1146
- });
1147
-
1148
- expect(childObject1.id).not.toEqual(childObject2.id);
1087
+ const { node, groupCore } = newGroup();
1088
+
1089
+ const childObject1 = node.createCoValue({
1090
+ type: "comap",
1091
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
1092
+ meta: null,
1093
+ ...Crypto.createdNowUnique(),
1094
+ });
1095
+
1096
+ const childObject2 = node.createCoValue({
1097
+ type: "comap",
1098
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
1099
+ meta: null,
1100
+ ...Crypto.createdNowUnique(),
1101
+ });
1102
+
1103
+ expect(childObject1.id).not.toEqual(childObject2.id);
1149
1104
  });
1150
1105
 
1151
1106
  test("Admins can create an adminInvite, which can add an admin", () => {
1152
- const { groupCore, admin } = newGroup();
1153
-
1154
- const inviteSecret = Crypto.newRandomAgentSecret();
1155
- const inviteID = Crypto.getAgentID(inviteSecret);
1156
-
1157
- const group = expectGroup(groupCore.getCurrentContent());
1158
-
1159
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1160
- const revelation = Crypto.seal({
1161
- message: readKey,
1162
- from: admin.currentSealerSecret(),
1163
- to: admin.currentSealerID()._unsafeUnwrap(),
1164
- nOnceMaterial: {
1165
- in: groupCore.id,
1166
- tx: groupCore.nextTransactionID(),
1167
- },
1168
- });
1169
-
1170
- group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1171
- group.set("readKey", readKeyID, "trusting");
1172
-
1173
- group.set(inviteID, "adminInvite", "trusting");
1174
-
1175
- expect(group.get(inviteID)).toEqual("adminInvite");
1176
-
1177
- const revelationForInvite = Crypto.seal({
1178
- message: readKey,
1179
- from: admin.currentSealerSecret(),
1180
- to: Crypto.getAgentSealerID(inviteID),
1181
- nOnceMaterial: {
1182
- in: groupCore.id,
1183
- tx: groupCore.nextTransactionID(),
1184
- },
1185
- });
1186
-
1187
- group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1188
-
1189
- const groupAsInvite = expectGroup(
1190
- groupCore
1191
- .testWithDifferentAccount(
1192
- new ControlledAgent(inviteSecret, Crypto),
1193
- Crypto.newRandomSessionID(inviteID),
1194
- )
1195
- .getCurrentContent(),
1196
- );
1197
-
1198
- const invitedAdminSecret = Crypto.newRandomAgentSecret();
1199
- const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1200
-
1201
- groupAsInvite.set(invitedAdminID, "admin", "trusting");
1202
-
1203
- expect(groupAsInvite.get(invitedAdminID)).toEqual("admin");
1204
-
1205
- const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
1206
-
1207
- expect(readKeyAsInvite.secret).toBeDefined();
1208
-
1209
- const revelation2 = Crypto.seal({
1210
- message: readKeyAsInvite.secret!,
1211
- from: Crypto.getAgentSealerSecret(invitedAdminSecret),
1212
- to: Crypto.getAgentSealerID(invitedAdminID),
1213
- nOnceMaterial: {
1214
- in: groupCore.id,
1215
- tx: groupCore.nextTransactionID(),
1216
- },
1217
- });
1218
-
1219
- groupAsInvite.set(
1220
- `${readKeyAsInvite.id}_for_${invitedAdminID}`,
1221
- revelation2,
1222
- "trusting",
1223
- );
1224
-
1225
- expect(
1226
- groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedAdminID}`),
1227
- ).toEqual(revelation2);
1107
+ const { groupCore, admin } = newGroup();
1108
+
1109
+ const inviteSecret = Crypto.newRandomAgentSecret();
1110
+ const inviteID = Crypto.getAgentID(inviteSecret);
1111
+
1112
+ const group = expectGroup(groupCore.getCurrentContent());
1113
+
1114
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1115
+ const revelation = Crypto.seal({
1116
+ message: readKey,
1117
+ from: admin.currentSealerSecret(),
1118
+ to: admin.currentSealerID()._unsafeUnwrap(),
1119
+ nOnceMaterial: {
1120
+ in: groupCore.id,
1121
+ tx: groupCore.nextTransactionID(),
1122
+ },
1123
+ });
1124
+
1125
+ group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1126
+ group.set("readKey", readKeyID, "trusting");
1127
+
1128
+ group.set(inviteID, "adminInvite", "trusting");
1129
+
1130
+ expect(group.get(inviteID)).toEqual("adminInvite");
1131
+
1132
+ const revelationForInvite = Crypto.seal({
1133
+ message: readKey,
1134
+ from: admin.currentSealerSecret(),
1135
+ to: Crypto.getAgentSealerID(inviteID),
1136
+ nOnceMaterial: {
1137
+ in: groupCore.id,
1138
+ tx: groupCore.nextTransactionID(),
1139
+ },
1140
+ });
1141
+
1142
+ group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1143
+
1144
+ const groupAsInvite = expectGroup(
1145
+ groupCore
1146
+ .testWithDifferentAccount(
1147
+ new ControlledAgent(inviteSecret, Crypto),
1148
+ Crypto.newRandomSessionID(inviteID),
1149
+ )
1150
+ .getCurrentContent(),
1151
+ );
1152
+
1153
+ const invitedAdminSecret = Crypto.newRandomAgentSecret();
1154
+ const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1155
+
1156
+ groupAsInvite.set(invitedAdminID, "admin", "trusting");
1157
+
1158
+ expect(groupAsInvite.get(invitedAdminID)).toEqual("admin");
1159
+
1160
+ const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
1161
+
1162
+ expect(readKeyAsInvite.secret).toBeDefined();
1163
+
1164
+ const revelation2 = Crypto.seal({
1165
+ message: readKeyAsInvite.secret!,
1166
+ from: Crypto.getAgentSealerSecret(invitedAdminSecret),
1167
+ to: Crypto.getAgentSealerID(invitedAdminID),
1168
+ nOnceMaterial: {
1169
+ in: groupCore.id,
1170
+ tx: groupCore.nextTransactionID(),
1171
+ },
1172
+ });
1173
+
1174
+ groupAsInvite.set(
1175
+ `${readKeyAsInvite.id}_for_${invitedAdminID}`,
1176
+ revelation2,
1177
+ "trusting",
1178
+ );
1179
+
1180
+ expect(
1181
+ groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedAdminID}`),
1182
+ ).toEqual(revelation2);
1228
1183
  });
1229
1184
 
1230
1185
  test("Admins can create an adminInvite, which can add an admin (high-level)", async () => {
1231
- const { node, group } = newGroupHighLevel();
1186
+ const { node, group } = newGroupHighLevel();
1232
1187
 
1233
- const inviteSecret = group.createInvite("admin");
1188
+ const inviteSecret = group.createInvite("admin");
1234
1189
 
1235
- const invitedAdminSecret = Crypto.newRandomAgentSecret();
1236
- const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1190
+ const invitedAdminSecret = Crypto.newRandomAgentSecret();
1191
+ const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1237
1192
 
1238
- const nodeAsInvitedAdmin = node.testWithDifferentAccount(
1239
- new ControlledAgent(invitedAdminSecret, Crypto),
1240
- Crypto.newRandomSessionID(invitedAdminID),
1241
- );
1193
+ const nodeAsInvitedAdmin = node.testWithDifferentAccount(
1194
+ new ControlledAgent(invitedAdminSecret, Crypto),
1195
+ Crypto.newRandomSessionID(invitedAdminID),
1196
+ );
1242
1197
 
1243
- await nodeAsInvitedAdmin.acceptInvite(group.id, inviteSecret);
1198
+ await nodeAsInvitedAdmin.acceptInvite(group.id, inviteSecret);
1244
1199
 
1245
- const thirdAdmin = Crypto.newRandomAgentSecret();
1246
- const thirdAdminID = Crypto.getAgentID(thirdAdmin);
1200
+ const thirdAdmin = Crypto.newRandomAgentSecret();
1201
+ const thirdAdminID = Crypto.getAgentID(thirdAdmin);
1247
1202
 
1248
- const groupAsInvitedAdmin = await nodeAsInvitedAdmin.load(group.id);
1249
- if (groupAsInvitedAdmin === "unavailable") {
1250
- throw new Error("groupAsInvitedAdmin is unavailable");
1251
- }
1203
+ const groupAsInvitedAdmin = await nodeAsInvitedAdmin.load(group.id);
1204
+ if (groupAsInvitedAdmin === "unavailable") {
1205
+ throw new Error("groupAsInvitedAdmin is unavailable");
1206
+ }
1252
1207
 
1253
- expect(groupAsInvitedAdmin.get(invitedAdminID)).toEqual("admin");
1254
- expect(groupAsInvitedAdmin.core.getCurrentReadKey().secret).toBeDefined();
1208
+ expect(groupAsInvitedAdmin.get(invitedAdminID)).toEqual("admin");
1209
+ expect(groupAsInvitedAdmin.core.getCurrentReadKey().secret).toBeDefined();
1255
1210
 
1256
- groupAsInvitedAdmin.addMemberInternal(thirdAdminID, "admin");
1211
+ groupAsInvitedAdmin.addMemberInternal(thirdAdminID, "admin");
1257
1212
 
1258
- expect(groupAsInvitedAdmin.get(thirdAdminID)).toEqual("admin");
1213
+ expect(groupAsInvitedAdmin.get(thirdAdminID)).toEqual("admin");
1259
1214
  });
1260
1215
 
1261
1216
  test("Admins can create a writerInvite, which can add a writer", () => {
1262
- const { groupCore, admin } = newGroup();
1263
-
1264
- const inviteSecret = Crypto.newRandomAgentSecret();
1265
- const inviteID = Crypto.getAgentID(inviteSecret);
1266
-
1267
- const group = expectGroup(groupCore.getCurrentContent());
1268
-
1269
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1270
- const revelation = Crypto.seal({
1271
- message: readKey,
1272
- from: admin.currentSealerSecret(),
1273
- to: admin.currentSealerID()._unsafeUnwrap(),
1274
- nOnceMaterial: {
1275
- in: groupCore.id,
1276
- tx: groupCore.nextTransactionID(),
1277
- },
1278
- });
1279
-
1280
- group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1281
- group.set("readKey", readKeyID, "trusting");
1282
-
1283
- group.set(inviteID, "writerInvite", "trusting");
1284
-
1285
- expect(group.get(inviteID)).toEqual("writerInvite");
1286
-
1287
- const revelationForInvite = Crypto.seal({
1288
- message: readKey,
1289
- from: admin.currentSealerSecret(),
1290
- to: Crypto.getAgentSealerID(inviteID),
1291
- nOnceMaterial: {
1292
- in: groupCore.id,
1293
- tx: groupCore.nextTransactionID(),
1294
- },
1295
- });
1296
-
1297
- group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1298
-
1299
- const groupAsInvite = expectGroup(
1300
- groupCore
1301
- .testWithDifferentAccount(
1302
- new ControlledAgent(inviteSecret, Crypto),
1303
- Crypto.newRandomSessionID(inviteID),
1304
- )
1305
- .getCurrentContent(),
1306
- );
1307
-
1308
- const invitedWriterSecret = Crypto.newRandomAgentSecret();
1309
- const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1310
-
1311
- groupAsInvite.set(invitedWriterID, "writer", "trusting");
1312
-
1313
- expect(groupAsInvite.get(invitedWriterID)).toEqual("writer");
1314
-
1315
- const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
1316
-
1317
- expect(readKeyAsInvite.secret).toBeDefined();
1318
-
1319
- const revelation2 = Crypto.seal({
1320
- message: readKeyAsInvite.secret!,
1321
- from: Crypto.getAgentSealerSecret(invitedWriterSecret),
1322
- to: Crypto.getAgentSealerID(invitedWriterID),
1323
- nOnceMaterial: {
1324
- in: groupCore.id,
1325
- tx: groupCore.nextTransactionID(),
1326
- },
1327
- });
1328
-
1329
- groupAsInvite.set(
1330
- `${readKeyAsInvite.id}_for_${invitedWriterID}`,
1331
- revelation2,
1332
- "trusting",
1333
- );
1334
-
1335
- expect(
1336
- groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedWriterID}`),
1337
- ).toEqual(revelation2);
1217
+ const { groupCore, admin } = newGroup();
1218
+
1219
+ const inviteSecret = Crypto.newRandomAgentSecret();
1220
+ const inviteID = Crypto.getAgentID(inviteSecret);
1221
+
1222
+ const group = expectGroup(groupCore.getCurrentContent());
1223
+
1224
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1225
+ const revelation = Crypto.seal({
1226
+ message: readKey,
1227
+ from: admin.currentSealerSecret(),
1228
+ to: admin.currentSealerID()._unsafeUnwrap(),
1229
+ nOnceMaterial: {
1230
+ in: groupCore.id,
1231
+ tx: groupCore.nextTransactionID(),
1232
+ },
1233
+ });
1234
+
1235
+ group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1236
+ group.set("readKey", readKeyID, "trusting");
1237
+
1238
+ group.set(inviteID, "writerInvite", "trusting");
1239
+
1240
+ expect(group.get(inviteID)).toEqual("writerInvite");
1241
+
1242
+ const revelationForInvite = Crypto.seal({
1243
+ message: readKey,
1244
+ from: admin.currentSealerSecret(),
1245
+ to: Crypto.getAgentSealerID(inviteID),
1246
+ nOnceMaterial: {
1247
+ in: groupCore.id,
1248
+ tx: groupCore.nextTransactionID(),
1249
+ },
1250
+ });
1251
+
1252
+ group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1253
+
1254
+ const groupAsInvite = expectGroup(
1255
+ groupCore
1256
+ .testWithDifferentAccount(
1257
+ new ControlledAgent(inviteSecret, Crypto),
1258
+ Crypto.newRandomSessionID(inviteID),
1259
+ )
1260
+ .getCurrentContent(),
1261
+ );
1262
+
1263
+ const invitedWriterSecret = Crypto.newRandomAgentSecret();
1264
+ const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1265
+
1266
+ groupAsInvite.set(invitedWriterID, "writer", "trusting");
1267
+
1268
+ expect(groupAsInvite.get(invitedWriterID)).toEqual("writer");
1269
+
1270
+ const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
1271
+
1272
+ expect(readKeyAsInvite.secret).toBeDefined();
1273
+
1274
+ const revelation2 = Crypto.seal({
1275
+ message: readKeyAsInvite.secret!,
1276
+ from: Crypto.getAgentSealerSecret(invitedWriterSecret),
1277
+ to: Crypto.getAgentSealerID(invitedWriterID),
1278
+ nOnceMaterial: {
1279
+ in: groupCore.id,
1280
+ tx: groupCore.nextTransactionID(),
1281
+ },
1282
+ });
1283
+
1284
+ groupAsInvite.set(
1285
+ `${readKeyAsInvite.id}_for_${invitedWriterID}`,
1286
+ revelation2,
1287
+ "trusting",
1288
+ );
1289
+
1290
+ expect(
1291
+ groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedWriterID}`),
1292
+ ).toEqual(revelation2);
1338
1293
  });
1339
1294
 
1340
1295
  test("Admins can create a writerInvite, which can add a writer (high-level)", async () => {
1341
- const { node, group } = newGroupHighLevel();
1296
+ const { node, group } = newGroupHighLevel();
1342
1297
 
1343
- const inviteSecret = group.createInvite("writer");
1298
+ const inviteSecret = group.createInvite("writer");
1344
1299
 
1345
- const invitedWriterSecret = Crypto.newRandomAgentSecret();
1346
- const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1300
+ const invitedWriterSecret = Crypto.newRandomAgentSecret();
1301
+ const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1347
1302
 
1348
- const nodeAsInvitedWriter = node.testWithDifferentAccount(
1349
- new ControlledAgent(invitedWriterSecret, Crypto),
1350
- Crypto.newRandomSessionID(invitedWriterID),
1351
- );
1303
+ const nodeAsInvitedWriter = node.testWithDifferentAccount(
1304
+ new ControlledAgent(invitedWriterSecret, Crypto),
1305
+ Crypto.newRandomSessionID(invitedWriterID),
1306
+ );
1352
1307
 
1353
- await nodeAsInvitedWriter.acceptInvite(group.id, inviteSecret);
1308
+ await nodeAsInvitedWriter.acceptInvite(group.id, inviteSecret);
1354
1309
 
1355
- const groupAsInvitedWriter = await nodeAsInvitedWriter.load(group.id);
1356
- if (groupAsInvitedWriter === "unavailable") {
1357
- throw new Error("groupAsInvitedAdmin is unavailable");
1358
- }
1310
+ const groupAsInvitedWriter = await nodeAsInvitedWriter.load(group.id);
1311
+ if (groupAsInvitedWriter === "unavailable") {
1312
+ throw new Error("groupAsInvitedAdmin is unavailable");
1313
+ }
1359
1314
 
1360
- expect(groupAsInvitedWriter.get(invitedWriterID)).toEqual("writer");
1361
- expect(groupAsInvitedWriter.core.getCurrentReadKey().secret).toBeDefined();
1315
+ expect(groupAsInvitedWriter.get(invitedWriterID)).toEqual("writer");
1316
+ expect(groupAsInvitedWriter.core.getCurrentReadKey().secret).toBeDefined();
1362
1317
  });
1363
1318
 
1364
1319
  test("Admins can create a readerInvite, which can add a reader", () => {
1365
- const { groupCore, admin } = newGroup();
1320
+ const { groupCore, admin } = newGroup();
1366
1321
 
1367
- const inviteSecret = Crypto.newRandomAgentSecret();
1368
- const inviteID = Crypto.getAgentID(inviteSecret);
1322
+ const inviteSecret = Crypto.newRandomAgentSecret();
1323
+ const inviteID = Crypto.getAgentID(inviteSecret);
1369
1324
 
1370
- const group = expectGroup(groupCore.getCurrentContent());
1325
+ const group = expectGroup(groupCore.getCurrentContent());
1371
1326
 
1372
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1373
- const revelation = Crypto.seal({
1374
- message: readKey,
1375
- from: admin.currentSealerSecret(),
1376
- to: admin.currentSealerID()._unsafeUnwrap(),
1377
- nOnceMaterial: {
1378
- in: groupCore.id,
1379
- tx: groupCore.nextTransactionID(),
1380
- },
1381
- });
1327
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1328
+ const revelation = Crypto.seal({
1329
+ message: readKey,
1330
+ from: admin.currentSealerSecret(),
1331
+ to: admin.currentSealerID()._unsafeUnwrap(),
1332
+ nOnceMaterial: {
1333
+ in: groupCore.id,
1334
+ tx: groupCore.nextTransactionID(),
1335
+ },
1336
+ });
1382
1337
 
1383
- group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1384
- group.set("readKey", readKeyID, "trusting");
1338
+ group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1339
+ group.set("readKey", readKeyID, "trusting");
1385
1340
 
1386
- group.set(inviteID, "readerInvite", "trusting");
1341
+ group.set(inviteID, "readerInvite", "trusting");
1387
1342
 
1388
- expect(group.get(inviteID)).toEqual("readerInvite");
1343
+ expect(group.get(inviteID)).toEqual("readerInvite");
1389
1344
 
1390
- const revelationForInvite = Crypto.seal({
1391
- message: readKey,
1392
- from: admin.currentSealerSecret(),
1393
- to: Crypto.getAgentSealerID(inviteID),
1394
- nOnceMaterial: {
1395
- in: groupCore.id,
1396
- tx: groupCore.nextTransactionID(),
1397
- },
1398
- });
1345
+ const revelationForInvite = Crypto.seal({
1346
+ message: readKey,
1347
+ from: admin.currentSealerSecret(),
1348
+ to: Crypto.getAgentSealerID(inviteID),
1349
+ nOnceMaterial: {
1350
+ in: groupCore.id,
1351
+ tx: groupCore.nextTransactionID(),
1352
+ },
1353
+ });
1399
1354
 
1400
- group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1355
+ group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1401
1356
 
1402
- const groupAsInvite = expectGroup(
1403
- groupCore
1404
- .testWithDifferentAccount(
1405
- new ControlledAgent(inviteSecret, Crypto),
1406
- Crypto.newRandomSessionID(inviteID),
1407
- )
1408
- .getCurrentContent(),
1409
- );
1357
+ const groupAsInvite = expectGroup(
1358
+ groupCore
1359
+ .testWithDifferentAccount(
1360
+ new ControlledAgent(inviteSecret, Crypto),
1361
+ Crypto.newRandomSessionID(inviteID),
1362
+ )
1363
+ .getCurrentContent(),
1364
+ );
1410
1365
 
1411
- const invitedReaderSecret = Crypto.newRandomAgentSecret();
1412
- const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
1366
+ const invitedReaderSecret = Crypto.newRandomAgentSecret();
1367
+ const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
1413
1368
 
1414
- groupAsInvite.set(invitedReaderID, "reader", "trusting");
1369
+ groupAsInvite.set(invitedReaderID, "reader", "trusting");
1415
1370
 
1416
- expect(groupAsInvite.get(invitedReaderID)).toEqual("reader");
1371
+ expect(groupAsInvite.get(invitedReaderID)).toEqual("reader");
1417
1372
 
1418
- const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
1373
+ const readKeyAsInvite = groupAsInvite.core.getCurrentReadKey();
1419
1374
 
1420
- expect(readKeyAsInvite.secret).toBeDefined();
1375
+ expect(readKeyAsInvite.secret).toBeDefined();
1421
1376
 
1422
- groupAsInvite.set(
1423
- `${readKeyAsInvite.id}_for_${invitedReaderID}`,
1424
- revelation,
1425
- "trusting",
1426
- );
1377
+ groupAsInvite.set(
1378
+ `${readKeyAsInvite.id}_for_${invitedReaderID}`,
1379
+ revelation,
1380
+ "trusting",
1381
+ );
1427
1382
 
1428
- expect(
1429
- groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedReaderID}`),
1430
- ).toEqual(revelation);
1383
+ expect(
1384
+ groupAsInvite.get(`${readKeyAsInvite.id}_for_${invitedReaderID}`),
1385
+ ).toEqual(revelation);
1431
1386
  });
1432
1387
 
1433
1388
  test("Admins can create a readerInvite, which can add a reader (high-level)", async () => {
1434
- const { node, group } = newGroupHighLevel();
1389
+ const { node, group } = newGroupHighLevel();
1435
1390
 
1436
- const inviteSecret = group.createInvite("reader");
1391
+ const inviteSecret = group.createInvite("reader");
1437
1392
 
1438
- const invitedReaderSecret = Crypto.newRandomAgentSecret();
1439
- const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
1393
+ const invitedReaderSecret = Crypto.newRandomAgentSecret();
1394
+ const invitedReaderID = Crypto.getAgentID(invitedReaderSecret);
1440
1395
 
1441
- const nodeAsInvitedReader = node.testWithDifferentAccount(
1442
- new ControlledAgent(invitedReaderSecret, Crypto),
1443
- Crypto.newRandomSessionID(invitedReaderID),
1444
- );
1396
+ const nodeAsInvitedReader = node.testWithDifferentAccount(
1397
+ new ControlledAgent(invitedReaderSecret, Crypto),
1398
+ Crypto.newRandomSessionID(invitedReaderID),
1399
+ );
1445
1400
 
1446
- await nodeAsInvitedReader.acceptInvite(group.id, inviteSecret);
1401
+ await nodeAsInvitedReader.acceptInvite(group.id, inviteSecret);
1447
1402
 
1448
- const groupAsInvitedReader = await nodeAsInvitedReader.load(group.id);
1449
- if (groupAsInvitedReader === "unavailable") {
1450
- throw new Error("groupAsInvitedAdmin is unavailable");
1451
- }
1403
+ const groupAsInvitedReader = await nodeAsInvitedReader.load(group.id);
1404
+ if (groupAsInvitedReader === "unavailable") {
1405
+ throw new Error("groupAsInvitedAdmin is unavailable");
1406
+ }
1452
1407
 
1453
- expect(groupAsInvitedReader.get(invitedReaderID)).toEqual("reader");
1454
- expect(groupAsInvitedReader.core.getCurrentReadKey().secret).toBeDefined();
1408
+ expect(groupAsInvitedReader.get(invitedReaderID)).toEqual("reader");
1409
+ expect(groupAsInvitedReader.core.getCurrentReadKey().secret).toBeDefined();
1455
1410
  });
1456
1411
 
1457
1412
  test("WriterInvites can not invite admins", () => {
1458
- const { groupCore, admin } = newGroup();
1459
-
1460
- const inviteSecret = Crypto.newRandomAgentSecret();
1461
- const inviteID = Crypto.getAgentID(inviteSecret);
1462
-
1463
- const group = expectGroup(groupCore.getCurrentContent());
1464
-
1465
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1466
- const revelation = Crypto.seal({
1467
- message: readKey,
1468
- from: admin.currentSealerSecret(),
1469
- to: admin.currentSealerID()._unsafeUnwrap(),
1470
- nOnceMaterial: {
1471
- in: groupCore.id,
1472
- tx: groupCore.nextTransactionID(),
1473
- },
1474
- });
1475
-
1476
- group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1477
- group.set("readKey", readKeyID, "trusting");
1478
-
1479
- group.set(inviteID, "writerInvite", "trusting");
1480
-
1481
- expect(group.get(inviteID)).toEqual("writerInvite");
1482
-
1483
- const revelationForInvite = Crypto.seal({
1484
- message: readKey,
1485
- from: admin.currentSealerSecret(),
1486
- to: Crypto.getAgentSealerID(inviteID),
1487
- nOnceMaterial: {
1488
- in: groupCore.id,
1489
- tx: groupCore.nextTransactionID(),
1490
- },
1491
- });
1492
-
1493
- group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1494
-
1495
- const groupAsInvite = expectGroup(
1496
- groupCore
1497
- .testWithDifferentAccount(
1498
- new ControlledAgent(inviteSecret, Crypto),
1499
- Crypto.newRandomSessionID(inviteID),
1500
- )
1501
- .getCurrentContent(),
1502
- );
1503
-
1504
- const invitedAdminSecret = Crypto.newRandomAgentSecret();
1505
- const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1506
-
1507
- groupAsInvite.set(invitedAdminID, "admin", "trusting");
1508
- expect(groupAsInvite.get(invitedAdminID)).toBeUndefined();
1413
+ const { groupCore, admin } = newGroup();
1414
+
1415
+ const inviteSecret = Crypto.newRandomAgentSecret();
1416
+ const inviteID = Crypto.getAgentID(inviteSecret);
1417
+
1418
+ const group = expectGroup(groupCore.getCurrentContent());
1419
+
1420
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1421
+ const revelation = Crypto.seal({
1422
+ message: readKey,
1423
+ from: admin.currentSealerSecret(),
1424
+ to: admin.currentSealerID()._unsafeUnwrap(),
1425
+ nOnceMaterial: {
1426
+ in: groupCore.id,
1427
+ tx: groupCore.nextTransactionID(),
1428
+ },
1429
+ });
1430
+
1431
+ group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1432
+ group.set("readKey", readKeyID, "trusting");
1433
+
1434
+ group.set(inviteID, "writerInvite", "trusting");
1435
+
1436
+ expect(group.get(inviteID)).toEqual("writerInvite");
1437
+
1438
+ const revelationForInvite = Crypto.seal({
1439
+ message: readKey,
1440
+ from: admin.currentSealerSecret(),
1441
+ to: Crypto.getAgentSealerID(inviteID),
1442
+ nOnceMaterial: {
1443
+ in: groupCore.id,
1444
+ tx: groupCore.nextTransactionID(),
1445
+ },
1446
+ });
1447
+
1448
+ group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1449
+
1450
+ const groupAsInvite = expectGroup(
1451
+ groupCore
1452
+ .testWithDifferentAccount(
1453
+ new ControlledAgent(inviteSecret, Crypto),
1454
+ Crypto.newRandomSessionID(inviteID),
1455
+ )
1456
+ .getCurrentContent(),
1457
+ );
1458
+
1459
+ const invitedAdminSecret = Crypto.newRandomAgentSecret();
1460
+ const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1461
+
1462
+ groupAsInvite.set(invitedAdminID, "admin", "trusting");
1463
+ expect(groupAsInvite.get(invitedAdminID)).toBeUndefined();
1509
1464
  });
1510
1465
 
1511
1466
  test("ReaderInvites can not invite admins", () => {
1512
- const { groupCore, admin } = newGroup();
1513
-
1514
- const inviteSecret = Crypto.newRandomAgentSecret();
1515
- const inviteID = Crypto.getAgentID(inviteSecret);
1516
-
1517
- const group = expectGroup(groupCore.getCurrentContent());
1518
-
1519
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1520
- const revelation = Crypto.seal({
1521
- message: readKey,
1522
- from: admin.currentSealerSecret(),
1523
- to: admin.currentSealerID()._unsafeUnwrap(),
1524
- nOnceMaterial: {
1525
- in: groupCore.id,
1526
- tx: groupCore.nextTransactionID(),
1527
- },
1528
- });
1529
-
1530
- group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1531
- group.set("readKey", readKeyID, "trusting");
1532
-
1533
- group.set(inviteID, "readerInvite", "trusting");
1534
-
1535
- expect(group.get(inviteID)).toEqual("readerInvite");
1536
-
1537
- const revelationForInvite = Crypto.seal({
1538
- message: readKey,
1539
- from: admin.currentSealerSecret(),
1540
- to: Crypto.getAgentSealerID(inviteID),
1541
- nOnceMaterial: {
1542
- in: groupCore.id,
1543
- tx: groupCore.nextTransactionID(),
1544
- },
1545
- });
1546
-
1547
- group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1548
-
1549
- const groupAsInvite = expectGroup(
1550
- groupCore
1551
- .testWithDifferentAccount(
1552
- new ControlledAgent(inviteSecret, Crypto),
1553
- Crypto.newRandomSessionID(inviteID),
1554
- )
1555
- .getCurrentContent(),
1556
- );
1557
-
1558
- const invitedAdminSecret = Crypto.newRandomAgentSecret();
1559
- const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1560
-
1561
- groupAsInvite.set(invitedAdminID, "admin", "trusting");
1562
- expect(groupAsInvite.get(invitedAdminID)).toBeUndefined();
1467
+ const { groupCore, admin } = newGroup();
1468
+
1469
+ const inviteSecret = Crypto.newRandomAgentSecret();
1470
+ const inviteID = Crypto.getAgentID(inviteSecret);
1471
+
1472
+ const group = expectGroup(groupCore.getCurrentContent());
1473
+
1474
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1475
+ const revelation = Crypto.seal({
1476
+ message: readKey,
1477
+ from: admin.currentSealerSecret(),
1478
+ to: admin.currentSealerID()._unsafeUnwrap(),
1479
+ nOnceMaterial: {
1480
+ in: groupCore.id,
1481
+ tx: groupCore.nextTransactionID(),
1482
+ },
1483
+ });
1484
+
1485
+ group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1486
+ group.set("readKey", readKeyID, "trusting");
1487
+
1488
+ group.set(inviteID, "readerInvite", "trusting");
1489
+
1490
+ expect(group.get(inviteID)).toEqual("readerInvite");
1491
+
1492
+ const revelationForInvite = Crypto.seal({
1493
+ message: readKey,
1494
+ from: admin.currentSealerSecret(),
1495
+ to: Crypto.getAgentSealerID(inviteID),
1496
+ nOnceMaterial: {
1497
+ in: groupCore.id,
1498
+ tx: groupCore.nextTransactionID(),
1499
+ },
1500
+ });
1501
+
1502
+ group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1503
+
1504
+ const groupAsInvite = expectGroup(
1505
+ groupCore
1506
+ .testWithDifferentAccount(
1507
+ new ControlledAgent(inviteSecret, Crypto),
1508
+ Crypto.newRandomSessionID(inviteID),
1509
+ )
1510
+ .getCurrentContent(),
1511
+ );
1512
+
1513
+ const invitedAdminSecret = Crypto.newRandomAgentSecret();
1514
+ const invitedAdminID = Crypto.getAgentID(invitedAdminSecret);
1515
+
1516
+ groupAsInvite.set(invitedAdminID, "admin", "trusting");
1517
+ expect(groupAsInvite.get(invitedAdminID)).toBeUndefined();
1563
1518
  });
1564
1519
 
1565
1520
  test("ReaderInvites can not invite writers", () => {
1566
- const { groupCore, admin } = newGroup();
1567
-
1568
- const inviteSecret = Crypto.newRandomAgentSecret();
1569
- const inviteID = Crypto.getAgentID(inviteSecret);
1570
-
1571
- const group = expectGroup(groupCore.getCurrentContent());
1572
-
1573
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1574
- const revelation = Crypto.seal({
1575
- message: readKey,
1576
- from: admin.currentSealerSecret(),
1577
- to: admin.currentSealerID()._unsafeUnwrap(),
1578
- nOnceMaterial: {
1579
- in: groupCore.id,
1580
- tx: groupCore.nextTransactionID(),
1581
- },
1582
- });
1583
-
1584
- group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1585
- group.set("readKey", readKeyID, "trusting");
1586
-
1587
- group.set(inviteID, "readerInvite", "trusting");
1588
-
1589
- expect(group.get(inviteID)).toEqual("readerInvite");
1590
-
1591
- const revelationForInvite = Crypto.seal({
1592
- message: readKey,
1593
- from: admin.currentSealerSecret(),
1594
- to: Crypto.getAgentSealerID(inviteID),
1595
- nOnceMaterial: {
1596
- in: groupCore.id,
1597
- tx: groupCore.nextTransactionID(),
1598
- },
1599
- });
1600
-
1601
- group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1602
-
1603
- const groupAsInvite = expectGroup(
1604
- groupCore
1605
- .testWithDifferentAccount(
1606
- new ControlledAgent(inviteSecret, Crypto),
1607
- Crypto.newRandomSessionID(inviteID),
1608
- )
1609
- .getCurrentContent(),
1610
- );
1611
-
1612
- const invitedWriterSecret = Crypto.newRandomAgentSecret();
1613
- const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1614
-
1615
- groupAsInvite.set(invitedWriterID, "writer", "trusting");
1616
- expect(groupAsInvite.get(invitedWriterID)).toBeUndefined();
1521
+ const { groupCore, admin } = newGroup();
1522
+
1523
+ const inviteSecret = Crypto.newRandomAgentSecret();
1524
+ const inviteID = Crypto.getAgentID(inviteSecret);
1525
+
1526
+ const group = expectGroup(groupCore.getCurrentContent());
1527
+
1528
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1529
+ const revelation = Crypto.seal({
1530
+ message: readKey,
1531
+ from: admin.currentSealerSecret(),
1532
+ to: admin.currentSealerID()._unsafeUnwrap(),
1533
+ nOnceMaterial: {
1534
+ in: groupCore.id,
1535
+ tx: groupCore.nextTransactionID(),
1536
+ },
1537
+ });
1538
+
1539
+ group.set(`${readKeyID}_for_${admin.id}`, revelation, "trusting");
1540
+ group.set("readKey", readKeyID, "trusting");
1541
+
1542
+ group.set(inviteID, "readerInvite", "trusting");
1543
+
1544
+ expect(group.get(inviteID)).toEqual("readerInvite");
1545
+
1546
+ const revelationForInvite = Crypto.seal({
1547
+ message: readKey,
1548
+ from: admin.currentSealerSecret(),
1549
+ to: Crypto.getAgentSealerID(inviteID),
1550
+ nOnceMaterial: {
1551
+ in: groupCore.id,
1552
+ tx: groupCore.nextTransactionID(),
1553
+ },
1554
+ });
1555
+
1556
+ group.set(`${readKeyID}_for_${inviteID}`, revelationForInvite, "trusting");
1557
+
1558
+ const groupAsInvite = expectGroup(
1559
+ groupCore
1560
+ .testWithDifferentAccount(
1561
+ new ControlledAgent(inviteSecret, Crypto),
1562
+ Crypto.newRandomSessionID(inviteID),
1563
+ )
1564
+ .getCurrentContent(),
1565
+ );
1566
+
1567
+ const invitedWriterSecret = Crypto.newRandomAgentSecret();
1568
+ const invitedWriterID = Crypto.getAgentID(invitedWriterSecret);
1569
+
1570
+ groupAsInvite.set(invitedWriterID, "writer", "trusting");
1571
+ expect(groupAsInvite.get(invitedWriterID)).toBeUndefined();
1617
1572
  });
1618
1573
 
1619
1574
  test("Can give read permission to 'everyone'", () => {
1620
- const { node, groupCore } = newGroup();
1621
-
1622
- const childObject = node.createCoValue({
1623
- type: "comap",
1624
- ruleset: { type: "ownedByGroup", group: groupCore.id },
1625
- meta: null,
1626
- ...Crypto.createdNowUnique(),
1627
- });
1628
-
1629
- const group = expectGroup(groupCore.getCurrentContent());
1630
-
1631
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1632
- group.set("everyone", "reader", "trusting");
1633
- group.set("readKey", readKeyID, "trusting");
1634
- group.set(`${readKeyID}_for_everyone`, readKey, "trusting");
1635
-
1636
- const childContent = expectMap(childObject.getCurrentContent());
1637
-
1638
- expect(childContent.get("foo")).toBeUndefined();
1639
-
1640
- childContent.set("foo", "bar", "private");
1641
- expect(childContent.get("foo")).toEqual("bar");
1642
-
1643
- const newAccount = new ControlledAgent(
1644
- Crypto.newRandomAgentSecret(),
1645
- Crypto,
1646
- );
1647
-
1648
- const childContent2 = expectMap(
1649
- childObject
1650
- .testWithDifferentAccount(
1651
- newAccount,
1652
- Crypto.newRandomSessionID(
1653
- newAccount.currentAgentID()._unsafeUnwrap(),
1654
- ),
1655
- )
1656
- .getCurrentContent(),
1657
- );
1658
-
1659
- expect(childContent2.get("foo")).toEqual("bar");
1575
+ const { node, groupCore } = newGroup();
1576
+
1577
+ const childObject = node.createCoValue({
1578
+ type: "comap",
1579
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
1580
+ meta: null,
1581
+ ...Crypto.createdNowUnique(),
1582
+ });
1583
+
1584
+ const group = expectGroup(groupCore.getCurrentContent());
1585
+
1586
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1587
+ group.set("everyone", "reader", "trusting");
1588
+ group.set("readKey", readKeyID, "trusting");
1589
+ group.set(`${readKeyID}_for_everyone`, readKey, "trusting");
1590
+
1591
+ const childContent = expectMap(childObject.getCurrentContent());
1592
+
1593
+ expect(childContent.get("foo")).toBeUndefined();
1594
+
1595
+ childContent.set("foo", "bar", "private");
1596
+ expect(childContent.get("foo")).toEqual("bar");
1597
+
1598
+ const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
1599
+
1600
+ const childContent2 = expectMap(
1601
+ childObject
1602
+ .testWithDifferentAccount(
1603
+ newAccount,
1604
+ Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
1605
+ )
1606
+ .getCurrentContent(),
1607
+ );
1608
+
1609
+ expect(childContent2.get("foo")).toEqual("bar");
1660
1610
  });
1661
1611
 
1662
1612
  test("Can give read permissions to 'everyone' (high-level)", async () => {
1663
- const { group } = newGroupHighLevel();
1613
+ const { group } = newGroupHighLevel();
1664
1614
 
1665
- const childObject = group.createMap();
1615
+ const childObject = group.createMap();
1666
1616
 
1667
- expect(childObject.get("foo")).toBeUndefined();
1617
+ expect(childObject.get("foo")).toBeUndefined();
1668
1618
 
1669
- group.addMember("everyone", "reader");
1619
+ group.addMember("everyone", "reader");
1670
1620
 
1671
- childObject.set("foo", "bar", "private");
1672
- expect(childObject.get("foo")).toEqual("bar");
1621
+ childObject.set("foo", "bar", "private");
1622
+ expect(childObject.get("foo")).toEqual("bar");
1673
1623
 
1674
- const newAccount = new ControlledAgent(
1675
- Crypto.newRandomAgentSecret(),
1676
- Crypto,
1677
- );
1624
+ const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
1678
1625
 
1679
- const childContent2 = expectMap(
1680
- childObject.core
1681
- .testWithDifferentAccount(
1682
- new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto),
1683
- Crypto.newRandomSessionID(
1684
- newAccount.currentAgentID()._unsafeUnwrap(),
1685
- ),
1686
- )
1687
- .getCurrentContent(),
1688
- );
1626
+ const childContent2 = expectMap(
1627
+ childObject.core
1628
+ .testWithDifferentAccount(
1629
+ new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto),
1630
+ Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
1631
+ )
1632
+ .getCurrentContent(),
1633
+ );
1689
1634
 
1690
- expect(childContent2.get("foo")).toEqual("bar");
1635
+ expect(childContent2.get("foo")).toEqual("bar");
1691
1636
  });
1692
1637
 
1693
1638
  test("Can give write permission to 'everyone'", async () => {
1694
- const { node, groupCore } = newGroup();
1639
+ const { node, groupCore } = newGroup();
1695
1640
 
1696
- const childObject = node.createCoValue({
1697
- type: "comap",
1698
- ruleset: { type: "ownedByGroup", group: groupCore.id },
1699
- meta: null,
1700
- ...Crypto.createdNowUnique(),
1701
- });
1641
+ const childObject = node.createCoValue({
1642
+ type: "comap",
1643
+ ruleset: { type: "ownedByGroup", group: groupCore.id },
1644
+ meta: null,
1645
+ ...Crypto.createdNowUnique(),
1646
+ });
1702
1647
 
1703
- const group = expectGroup(groupCore.getCurrentContent());
1648
+ const group = expectGroup(groupCore.getCurrentContent());
1704
1649
 
1705
- const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1706
- group.set("everyone", "writer", "trusting");
1707
- group.set("readKey", readKeyID, "trusting");
1708
- group.set(`${readKeyID}_for_everyone`, readKey, "trusting");
1650
+ const { secret: readKey, id: readKeyID } = Crypto.newRandomKeySecret();
1651
+ group.set("everyone", "writer", "trusting");
1652
+ group.set("readKey", readKeyID, "trusting");
1653
+ group.set(`${readKeyID}_for_everyone`, readKey, "trusting");
1709
1654
 
1710
- const childContent = expectMap(childObject.getCurrentContent());
1655
+ const childContent = expectMap(childObject.getCurrentContent());
1711
1656
 
1712
- expect(childContent.get("foo")).toBeUndefined();
1657
+ expect(childContent.get("foo")).toBeUndefined();
1713
1658
 
1714
- childContent.set("foo", "bar", "private");
1715
- expect(childContent.get("foo")).toEqual("bar");
1659
+ childContent.set("foo", "bar", "private");
1660
+ expect(childContent.get("foo")).toEqual("bar");
1716
1661
 
1717
- const newAccount = new ControlledAgent(
1718
- Crypto.newRandomAgentSecret(),
1719
- Crypto,
1720
- );
1662
+ const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
1721
1663
 
1722
- const childContent2 = expectMap(
1723
- childObject
1724
- .testWithDifferentAccount(
1725
- newAccount,
1726
- Crypto.newRandomSessionID(
1727
- newAccount.currentAgentID()._unsafeUnwrap(),
1728
- ),
1729
- )
1730
- .getCurrentContent(),
1731
- );
1664
+ const childContent2 = expectMap(
1665
+ childObject
1666
+ .testWithDifferentAccount(
1667
+ newAccount,
1668
+ Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
1669
+ )
1670
+ .getCurrentContent(),
1671
+ );
1732
1672
 
1733
- // TODO: resolve race condition
1734
- await new Promise((resolve) => setTimeout(resolve, 50));
1673
+ // TODO: resolve race condition
1674
+ await new Promise((resolve) => setTimeout(resolve, 50));
1735
1675
 
1736
- expect(childContent2.get("foo")).toEqual("bar");
1676
+ expect(childContent2.get("foo")).toEqual("bar");
1737
1677
 
1738
- childContent2.set("foo", "bar2", "private");
1739
- expect(childContent2.get("foo")).toEqual("bar2");
1678
+ childContent2.set("foo", "bar2", "private");
1679
+ expect(childContent2.get("foo")).toEqual("bar2");
1740
1680
  });
1741
1681
 
1742
1682
  test("Can give write permissions to 'everyone' (high-level)", async () => {
1743
- const { group } = newGroupHighLevel();
1683
+ const { group } = newGroupHighLevel();
1744
1684
 
1745
- const childObject = group.createMap();
1685
+ const childObject = group.createMap();
1746
1686
 
1747
- expect(childObject.get("foo")).toBeUndefined();
1687
+ expect(childObject.get("foo")).toBeUndefined();
1748
1688
 
1749
- group.addMember("everyone", "writer");
1689
+ group.addMember("everyone", "writer");
1750
1690
 
1751
- childObject.set("foo", "bar", "private");
1752
- expect(childObject.get("foo")).toEqual("bar");
1691
+ childObject.set("foo", "bar", "private");
1692
+ expect(childObject.get("foo")).toEqual("bar");
1753
1693
 
1754
- const newAccount = new ControlledAgent(
1755
- Crypto.newRandomAgentSecret(),
1756
- Crypto,
1757
- );
1694
+ const newAccount = new ControlledAgent(Crypto.newRandomAgentSecret(), Crypto);
1758
1695
 
1759
- const childContent2 = expectMap(
1760
- childObject.core
1761
- .testWithDifferentAccount(
1762
- newAccount,
1763
- Crypto.newRandomSessionID(
1764
- newAccount.currentAgentID()._unsafeUnwrap(),
1765
- ),
1766
- )
1767
- .getCurrentContent(),
1768
- );
1696
+ const childContent2 = expectMap(
1697
+ childObject.core
1698
+ .testWithDifferentAccount(
1699
+ newAccount,
1700
+ Crypto.newRandomSessionID(newAccount.currentAgentID()._unsafeUnwrap()),
1701
+ )
1702
+ .getCurrentContent(),
1703
+ );
1769
1704
 
1770
- expect(childContent2.get("foo")).toEqual("bar");
1705
+ expect(childContent2.get("foo")).toEqual("bar");
1771
1706
 
1772
- console.log("Before anon set");
1773
- childContent2.set("foo", "bar2", "private");
1774
- expect(childContent2.get("foo")).toEqual("bar2");
1707
+ console.log("Before anon set");
1708
+ childContent2.set("foo", "bar2", "private");
1709
+ expect(childContent2.get("foo")).toEqual("bar2");
1775
1710
  });