cojson 0.0.21 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/account.d.ts +1 -1
- package/dist/account.js +1 -1
- package/dist/account.js.map +1 -1
- package/dist/coValue.d.ts +10 -4
- package/dist/coValue.js +32 -15
- package/dist/coValue.js.map +1 -1
- package/dist/contentTypes/coMap.d.ts +2 -2
- package/dist/contentTypes/coMap.js +6 -6
- package/dist/contentTypes/coMap.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +2 -1
- package/dist/node.js +68 -11
- package/dist/node.js.map +1 -1
- package/dist/permissions.d.ts +4 -32
- package/dist/permissions.js +42 -106
- package/dist/permissions.js.map +1 -1
- package/dist/team.d.ts +37 -0
- package/dist/team.js +116 -0
- package/dist/team.js.map +1 -0
- package/dist/testUtils.d.ts +2 -2
- package/dist/testUtils.js +1 -1
- package/dist/testUtils.js.map +1 -1
- package/package.json +2 -2
- package/src/account.ts +1 -1
- package/src/coValue.test.ts +58 -0
- package/src/coValue.ts +41 -24
- package/src/contentTypes/coMap.ts +8 -8
- package/src/crypto.test.ts +10 -9
- package/src/index.ts +5 -0
- package/src/node.ts +151 -26
- package/src/permissions.test.ts +503 -3
- package/src/permissions.ts +70 -206
- package/src/sync.test.ts +8 -8
- package/src/team.ts +233 -0
- package/src/testUtils.ts +1 -1
- package/tsconfig.json +1 -0
- package/dist/account.test.d.ts +0 -1
- package/dist/account.test.js +0 -40
- package/dist/account.test.js.map +0 -1
- package/dist/coValue.test.d.ts +0 -1
- package/dist/coValue.test.js +0 -78
- package/dist/coValue.test.js.map +0 -1
- package/dist/contentType.test.d.ts +0 -1
- package/dist/contentType.test.js +0 -145
- package/dist/contentType.test.js.map +0 -1
- package/dist/crypto.test.d.ts +0 -1
- package/dist/crypto.test.js +0 -111
- package/dist/crypto.test.js.map +0 -1
- package/dist/permissions.test.d.ts +0 -1
- package/dist/permissions.test.js +0 -711
- package/dist/permissions.test.js.map +0 -1
- package/dist/sync.test.d.ts +0 -1
- package/dist/sync.test.js +0 -827
- package/dist/sync.test.js.map +0 -1
package/dist/permissions.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { createdNowUnique, newRandomKeySecret, seal, encryptKeySecret, getAgentSealerID, } from "./crypto.js";
|
|
2
1
|
import { accountOrAgentIDfromSessionID, } from "./coValue.js";
|
|
3
|
-
import { isAgentID } from "./ids.js";
|
|
4
2
|
export function determineValidTransactions(coValue) {
|
|
5
3
|
if (coValue.header.ruleset.type === "team") {
|
|
6
4
|
const allTrustingTransactionsSorted = Object.entries(coValue.sessions).flatMap(([sessionID, sessionLog]) => {
|
|
@@ -33,7 +31,7 @@ export function determineValidTransactions(coValue) {
|
|
|
33
31
|
console.warn("Team transaction must have exactly one change");
|
|
34
32
|
continue;
|
|
35
33
|
}
|
|
36
|
-
if (change.op !== "
|
|
34
|
+
if (change.op !== "set") {
|
|
37
35
|
console.warn("Team transaction must set a role or readKey");
|
|
38
36
|
continue;
|
|
39
37
|
}
|
|
@@ -45,7 +43,7 @@ export function determineValidTransactions(coValue) {
|
|
|
45
43
|
validTransactions.push({ txID: { sessionID, txIndex }, tx });
|
|
46
44
|
continue;
|
|
47
45
|
}
|
|
48
|
-
else if (change.key ===
|
|
46
|
+
else if (change.key === "profile") {
|
|
49
47
|
if (memberState[transactor] !== "admin") {
|
|
50
48
|
console.warn("Only admins can set profile");
|
|
51
49
|
continue;
|
|
@@ -53,8 +51,12 @@ export function determineValidTransactions(coValue) {
|
|
|
53
51
|
validTransactions.push({ txID: { sessionID, txIndex }, tx });
|
|
54
52
|
continue;
|
|
55
53
|
}
|
|
56
|
-
else if (isKeyForKeyField(change.key) ||
|
|
57
|
-
|
|
54
|
+
else if (isKeyForKeyField(change.key) ||
|
|
55
|
+
isKeyForAccountField(change.key)) {
|
|
56
|
+
if (memberState[transactor] !== "admin" &&
|
|
57
|
+
memberState[transactor] !== "adminInvite" &&
|
|
58
|
+
memberState[transactor] !== "writerInvite" &&
|
|
59
|
+
memberState[transactor] !== "readerInvite") {
|
|
58
60
|
console.warn("Only admins can reveal keys");
|
|
59
61
|
continue;
|
|
60
62
|
}
|
|
@@ -67,24 +69,47 @@ export function determineValidTransactions(coValue) {
|
|
|
67
69
|
if (change.value !== "admin" &&
|
|
68
70
|
change.value !== "writer" &&
|
|
69
71
|
change.value !== "reader" &&
|
|
70
|
-
change.value !== "revoked"
|
|
72
|
+
change.value !== "revoked" &&
|
|
73
|
+
change.value !== "adminInvite" &&
|
|
74
|
+
change.value !== "writerInvite" &&
|
|
75
|
+
change.value !== "readerInvite") {
|
|
71
76
|
console.warn("Team transaction must set a valid role");
|
|
72
77
|
continue;
|
|
73
78
|
}
|
|
74
79
|
const isFirstSelfAppointment = !memberState[transactor] &&
|
|
75
80
|
transactor === initialAdmin &&
|
|
76
|
-
change.op === "
|
|
81
|
+
change.op === "set" &&
|
|
77
82
|
change.key === transactor &&
|
|
78
83
|
change.value === "admin";
|
|
79
84
|
if (!isFirstSelfAppointment) {
|
|
80
|
-
if (memberState[transactor]
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
if (memberState[transactor] === "admin") {
|
|
86
|
+
if (memberState[affectedMember] === "admin" &&
|
|
87
|
+
affectedMember !== transactor &&
|
|
88
|
+
assignedRole !== "admin") {
|
|
89
|
+
console.warn("Admins can only demote themselves.");
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (memberState[transactor] === "adminInvite") {
|
|
94
|
+
if (change.value !== "admin") {
|
|
95
|
+
console.warn("AdminInvites can only create admins.");
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
83
98
|
}
|
|
84
|
-
if (memberState[
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
99
|
+
else if (memberState[transactor] === "writerInvite") {
|
|
100
|
+
if (change.value !== "writer") {
|
|
101
|
+
console.warn("WriterInvites can only create writers.");
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (memberState[transactor] === "readerInvite") {
|
|
106
|
+
if (change.value !== "reader") {
|
|
107
|
+
console.warn("ReaderInvites can only create reader.");
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
console.warn("Team transaction must be made by current admin or invite");
|
|
88
113
|
continue;
|
|
89
114
|
}
|
|
90
115
|
}
|
|
@@ -127,100 +152,11 @@ export function determineValidTransactions(coValue) {
|
|
|
127
152
|
throw new Error("Unknown ruleset type " + coValue.header.ruleset.type);
|
|
128
153
|
}
|
|
129
154
|
}
|
|
130
|
-
export function expectTeamContent(content) {
|
|
131
|
-
if (content.type !== "comap") {
|
|
132
|
-
throw new Error("Expected map");
|
|
133
|
-
}
|
|
134
|
-
return content;
|
|
135
|
-
}
|
|
136
|
-
export class Team {
|
|
137
|
-
constructor(teamMap, node) {
|
|
138
|
-
this.teamMap = teamMap;
|
|
139
|
-
this.node = node;
|
|
140
|
-
}
|
|
141
|
-
get id() {
|
|
142
|
-
return this.teamMap.id;
|
|
143
|
-
}
|
|
144
|
-
addMember(accountID, role) {
|
|
145
|
-
this.teamMap = this.teamMap.edit((map) => {
|
|
146
|
-
const currentReadKey = this.teamMap.coValue.getCurrentReadKey();
|
|
147
|
-
if (!currentReadKey.secret) {
|
|
148
|
-
throw new Error("Can't add member without read key secret");
|
|
149
|
-
}
|
|
150
|
-
const agent = this.node.resolveAccountAgent(accountID, "Expected to know agent to add them to team");
|
|
151
|
-
map.set(accountID, role, "trusting");
|
|
152
|
-
if (map.get(accountID) !== role) {
|
|
153
|
-
throw new Error("Failed to set role");
|
|
154
|
-
}
|
|
155
|
-
map.set(`${currentReadKey.id}_for_${accountID}`, seal(currentReadKey.secret, this.teamMap.coValue.node.account.currentSealerSecret(), getAgentSealerID(agent), {
|
|
156
|
-
in: this.teamMap.coValue.id,
|
|
157
|
-
tx: this.teamMap.coValue.nextTransactionID(),
|
|
158
|
-
}), "trusting");
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
rotateReadKey() {
|
|
162
|
-
const currentlyPermittedReaders = this.teamMap.keys().filter((key) => {
|
|
163
|
-
if (key.startsWith("co_") || isAgentID(key)) {
|
|
164
|
-
const role = this.teamMap.get(key);
|
|
165
|
-
return (role === "admin" || role === "writer" || role === "reader");
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
const maybeCurrentReadKey = this.teamMap.coValue.getCurrentReadKey();
|
|
172
|
-
if (!maybeCurrentReadKey.secret) {
|
|
173
|
-
throw new Error("Can't rotate read key secret we don't have access to");
|
|
174
|
-
}
|
|
175
|
-
const currentReadKey = {
|
|
176
|
-
id: maybeCurrentReadKey.id,
|
|
177
|
-
secret: maybeCurrentReadKey.secret,
|
|
178
|
-
};
|
|
179
|
-
const newReadKey = newRandomKeySecret();
|
|
180
|
-
this.teamMap = this.teamMap.edit((map) => {
|
|
181
|
-
for (const readerID of currentlyPermittedReaders) {
|
|
182
|
-
const reader = this.node.resolveAccountAgent(readerID, "Expected to know currently permitted reader");
|
|
183
|
-
map.set(`${newReadKey.id}_for_${readerID}`, seal(newReadKey.secret, this.teamMap.coValue.node.account.currentSealerSecret(), getAgentSealerID(reader), {
|
|
184
|
-
in: this.teamMap.coValue.id,
|
|
185
|
-
tx: this.teamMap.coValue.nextTransactionID(),
|
|
186
|
-
}), "trusting");
|
|
187
|
-
}
|
|
188
|
-
map.set(`${currentReadKey.id}_for_${newReadKey.id}`, encryptKeySecret({
|
|
189
|
-
encrypting: newReadKey,
|
|
190
|
-
toEncrypt: currentReadKey,
|
|
191
|
-
}).encrypted, "trusting");
|
|
192
|
-
map.set("readKey", newReadKey.id, "trusting");
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
removeMember(accountID) {
|
|
196
|
-
this.teamMap = this.teamMap.edit((map) => {
|
|
197
|
-
map.set(accountID, "revoked", "trusting");
|
|
198
|
-
});
|
|
199
|
-
this.rotateReadKey();
|
|
200
|
-
}
|
|
201
|
-
createMap(meta) {
|
|
202
|
-
return this.node
|
|
203
|
-
.createCoValue({
|
|
204
|
-
type: "comap",
|
|
205
|
-
ruleset: {
|
|
206
|
-
type: "ownedByTeam",
|
|
207
|
-
team: this.teamMap.id,
|
|
208
|
-
},
|
|
209
|
-
meta: meta || null,
|
|
210
|
-
...createdNowUnique(),
|
|
211
|
-
})
|
|
212
|
-
.getCurrentContent();
|
|
213
|
-
}
|
|
214
|
-
testWithDifferentAccount(account, sessionId) {
|
|
215
|
-
return new Team(expectTeamContent(this.teamMap.coValue
|
|
216
|
-
.testWithDifferentAccount(account, sessionId)
|
|
217
|
-
.getCurrentContent()), this.node);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
155
|
export function isKeyForKeyField(field) {
|
|
221
156
|
return field.startsWith("key_") && field.includes("_for_key");
|
|
222
157
|
}
|
|
223
158
|
export function isKeyForAccountField(field) {
|
|
224
|
-
return field.startsWith("key_") &&
|
|
159
|
+
return (field.startsWith("key_") &&
|
|
160
|
+
(field.includes("_for_sealer") || field.includes("_for_co")));
|
|
225
161
|
}
|
|
226
162
|
//# sourceMappingURL=permissions.js.map
|
package/dist/permissions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAMA,OAAO,EAIH,6BAA6B,GAChC,MAAM,cAAc,CAAC;AAqBtB,MAAM,UAAU,0BAA0B,CACtC,OAAgB;IAEhB,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;QACxC,MAAM,6BAA6B,GAAG,MAAM,CAAC,OAAO,CAChD,OAAO,CA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AC;AACN,CAAC"}
|
package/dist/team.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CoID, ContentType } from "./contentType.js";
|
|
2
|
+
import { CoMap } from "./contentTypes/coMap.js";
|
|
3
|
+
import { JsonObject, JsonValue } from "./jsonValue.js";
|
|
4
|
+
import { Encrypted, KeyID, KeySecret, Sealed } from "./crypto.js";
|
|
5
|
+
import { LocalNode } from "./node.js";
|
|
6
|
+
import { SessionID } from "./ids.js";
|
|
7
|
+
import { AccountIDOrAgentID, GeneralizedControlledAccount, Profile } from "./account.js";
|
|
8
|
+
import { Role } from "./permissions.js";
|
|
9
|
+
export type TeamContent = {
|
|
10
|
+
profile: CoID<Profile> | null;
|
|
11
|
+
[key: AccountIDOrAgentID]: Role;
|
|
12
|
+
readKey: KeyID;
|
|
13
|
+
[revelationFor: `${KeyID}_for_${AccountIDOrAgentID}`]: Sealed<KeySecret>;
|
|
14
|
+
[oldKeyForNewKey: `${KeyID}_for_${KeyID}`]: Encrypted<KeySecret, {
|
|
15
|
+
encryptedID: KeyID;
|
|
16
|
+
encryptingID: KeyID;
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
export declare function expectTeamContent(content: ContentType): CoMap<TeamContent, JsonObject | null>;
|
|
20
|
+
export declare class Team {
|
|
21
|
+
teamMap: CoMap<TeamContent, JsonObject | null>;
|
|
22
|
+
node: LocalNode;
|
|
23
|
+
constructor(teamMap: CoMap<TeamContent, JsonObject | null>, node: LocalNode);
|
|
24
|
+
get id(): CoID<CoMap<TeamContent, JsonObject | null>>;
|
|
25
|
+
roleOf(accountID: AccountIDOrAgentID): Role | undefined;
|
|
26
|
+
myRole(): Role | undefined;
|
|
27
|
+
addMember(accountID: AccountIDOrAgentID, role: Role): void;
|
|
28
|
+
createInvite(role: "reader" | "writer" | "admin"): InviteSecret;
|
|
29
|
+
rotateReadKey(): void;
|
|
30
|
+
removeMember(accountID: AccountIDOrAgentID): void;
|
|
31
|
+
createMap<M extends {
|
|
32
|
+
[key: string]: JsonValue;
|
|
33
|
+
}, Meta extends JsonObject | null = null>(meta?: Meta): CoMap<M, Meta>;
|
|
34
|
+
testWithDifferentAccount(account: GeneralizedControlledAccount, sessionId: SessionID): Team;
|
|
35
|
+
}
|
|
36
|
+
export type InviteSecret = `inviteSecret_z${string}`;
|
|
37
|
+
export declare function secretSeedFromInviteSecret(inviteSecret: InviteSecret): Uint8Array;
|
package/dist/team.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createdNowUnique, newRandomKeySecret, seal, encryptKeySecret, getAgentSealerID, newRandomSecretSeed, agentSecretFromSecretSeed, getAgentID, } from "./crypto.js";
|
|
2
|
+
import { isAgentID } from "./ids.js";
|
|
3
|
+
import { base58 } from "@scure/base";
|
|
4
|
+
export function expectTeamContent(content) {
|
|
5
|
+
if (content.type !== "comap") {
|
|
6
|
+
throw new Error("Expected map");
|
|
7
|
+
}
|
|
8
|
+
return content;
|
|
9
|
+
}
|
|
10
|
+
export class Team {
|
|
11
|
+
constructor(teamMap, node) {
|
|
12
|
+
this.teamMap = teamMap;
|
|
13
|
+
this.node = node;
|
|
14
|
+
}
|
|
15
|
+
get id() {
|
|
16
|
+
return this.teamMap.id;
|
|
17
|
+
}
|
|
18
|
+
roleOf(accountID) {
|
|
19
|
+
return this.teamMap.get(accountID);
|
|
20
|
+
}
|
|
21
|
+
myRole() {
|
|
22
|
+
return this.roleOf(this.node.account.id);
|
|
23
|
+
}
|
|
24
|
+
addMember(accountID, role) {
|
|
25
|
+
this.teamMap = this.teamMap.edit((map) => {
|
|
26
|
+
const currentReadKey = this.teamMap.coValue.getCurrentReadKey();
|
|
27
|
+
if (!currentReadKey.secret) {
|
|
28
|
+
throw new Error("Can't add member without read key secret");
|
|
29
|
+
}
|
|
30
|
+
const agent = this.node.resolveAccountAgent(accountID, "Expected to know agent to add them to team");
|
|
31
|
+
map.set(accountID, role, "trusting");
|
|
32
|
+
if (map.get(accountID) !== role) {
|
|
33
|
+
throw new Error("Failed to set role");
|
|
34
|
+
}
|
|
35
|
+
map.set(`${currentReadKey.id}_for_${accountID}`, seal(currentReadKey.secret, this.teamMap.coValue.node.account.currentSealerSecret(), getAgentSealerID(agent), {
|
|
36
|
+
in: this.teamMap.coValue.id,
|
|
37
|
+
tx: this.teamMap.coValue.nextTransactionID(),
|
|
38
|
+
}), "trusting");
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
createInvite(role) {
|
|
42
|
+
const secretSeed = newRandomSecretSeed();
|
|
43
|
+
const inviteSecret = agentSecretFromSecretSeed(secretSeed);
|
|
44
|
+
const inviteID = getAgentID(inviteSecret);
|
|
45
|
+
this.addMember(inviteID, `${role}Invite`);
|
|
46
|
+
return inviteSecretFromSecretSeed(secretSeed);
|
|
47
|
+
}
|
|
48
|
+
rotateReadKey() {
|
|
49
|
+
const currentlyPermittedReaders = this.teamMap.keys().filter((key) => {
|
|
50
|
+
if (key.startsWith("co_") || isAgentID(key)) {
|
|
51
|
+
const role = this.teamMap.get(key);
|
|
52
|
+
return (role === "admin" || role === "writer" || role === "reader");
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const maybeCurrentReadKey = this.teamMap.coValue.getCurrentReadKey();
|
|
59
|
+
if (!maybeCurrentReadKey.secret) {
|
|
60
|
+
throw new Error("Can't rotate read key secret we don't have access to");
|
|
61
|
+
}
|
|
62
|
+
const currentReadKey = {
|
|
63
|
+
id: maybeCurrentReadKey.id,
|
|
64
|
+
secret: maybeCurrentReadKey.secret,
|
|
65
|
+
};
|
|
66
|
+
const newReadKey = newRandomKeySecret();
|
|
67
|
+
this.teamMap = this.teamMap.edit((map) => {
|
|
68
|
+
for (const readerID of currentlyPermittedReaders) {
|
|
69
|
+
const reader = this.node.resolveAccountAgent(readerID, "Expected to know currently permitted reader");
|
|
70
|
+
map.set(`${newReadKey.id}_for_${readerID}`, seal(newReadKey.secret, this.teamMap.coValue.node.account.currentSealerSecret(), getAgentSealerID(reader), {
|
|
71
|
+
in: this.teamMap.coValue.id,
|
|
72
|
+
tx: this.teamMap.coValue.nextTransactionID(),
|
|
73
|
+
}), "trusting");
|
|
74
|
+
}
|
|
75
|
+
map.set(`${currentReadKey.id}_for_${newReadKey.id}`, encryptKeySecret({
|
|
76
|
+
encrypting: newReadKey,
|
|
77
|
+
toEncrypt: currentReadKey,
|
|
78
|
+
}).encrypted, "trusting");
|
|
79
|
+
map.set("readKey", newReadKey.id, "trusting");
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
removeMember(accountID) {
|
|
83
|
+
this.teamMap = this.teamMap.edit((map) => {
|
|
84
|
+
map.set(accountID, "revoked", "trusting");
|
|
85
|
+
});
|
|
86
|
+
this.rotateReadKey();
|
|
87
|
+
}
|
|
88
|
+
createMap(meta) {
|
|
89
|
+
return this.node
|
|
90
|
+
.createCoValue({
|
|
91
|
+
type: "comap",
|
|
92
|
+
ruleset: {
|
|
93
|
+
type: "ownedByTeam",
|
|
94
|
+
team: this.teamMap.id,
|
|
95
|
+
},
|
|
96
|
+
meta: meta || null,
|
|
97
|
+
...createdNowUnique(),
|
|
98
|
+
})
|
|
99
|
+
.getCurrentContent();
|
|
100
|
+
}
|
|
101
|
+
testWithDifferentAccount(account, sessionId) {
|
|
102
|
+
return new Team(expectTeamContent(this.teamMap.coValue
|
|
103
|
+
.testWithDifferentAccount(account, sessionId)
|
|
104
|
+
.getCurrentContent()), this.node);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function inviteSecretFromSecretSeed(secretSeed) {
|
|
108
|
+
return `inviteSecret_z${base58.encode(secretSeed)}`;
|
|
109
|
+
}
|
|
110
|
+
export function secretSeedFromInviteSecret(inviteSecret) {
|
|
111
|
+
if (!inviteSecret.startsWith("inviteSecret_z")) {
|
|
112
|
+
throw new Error("Invalid invite secret");
|
|
113
|
+
}
|
|
114
|
+
return base58.decode(inviteSecret.slice("inviteSecret_z".length));
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=team.js.map
|
package/dist/team.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team.js","sourceRoot":"","sources":["../src/team.ts"],"names":[],"mappings":"AAGA,OAAO,EAIH,gBAAgB,EAChB,kBAAkB,EAClB,IAAI,EACJ,gBAAgB,EAChB,gBAAgB,EAEhB,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAa,SAAS,EAAE,MAAM,UAAU,CAAC;AAOhD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAarC,MAAM,UAAU,iBAAiB,CAC7B,OAAoB;IAEpB,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;KACnC;IAED,OAAO,OAAgD,CAAC;AAC5D,CAAC;AAED,MAAM,OAAO,IAAI;IAIb,YACI,OAA8C,EAC9C,IAAe;QAEf,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,IAAI,EAAE;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,SAA6B;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACvC,CAAC;IAED,MAAM;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,SAAS,CAAC,SAA6B,EAAE,IAAU;QAC/C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACrC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,EA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AA0B,CAAC,UAAsB;IACtD,OAAO,iBAAiB,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,YAA0B;IACjE,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE;QAC5C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;KAC5C;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/testUtils.d.ts
CHANGED
|
@@ -16,12 +16,12 @@ export declare function teamWithTwoAdmins(): {
|
|
|
16
16
|
export declare function newTeamHighLevel(): {
|
|
17
17
|
admin: AnonymousControlledAccount;
|
|
18
18
|
node: LocalNode;
|
|
19
|
-
team: import("./
|
|
19
|
+
team: import("./team.js").Team;
|
|
20
20
|
};
|
|
21
21
|
export declare function teamWithTwoAdminsHighLevel(): {
|
|
22
22
|
admin: AnonymousControlledAccount;
|
|
23
23
|
node: LocalNode;
|
|
24
|
-
team: import("./
|
|
24
|
+
team: import("./team.js").Team;
|
|
25
25
|
otherAdmin: import("./account.js").ControlledAccount;
|
|
26
26
|
};
|
|
27
27
|
export declare function shouldNotResolve<T>(promise: Promise<T>, ops: {
|
package/dist/testUtils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createdNowUnique, getAgentID, newRandomAgentSecret } from "./crypto.js";
|
|
2
2
|
import { newRandomSessionID } from "./coValue.js";
|
|
3
3
|
import { LocalNode } from "./node.js";
|
|
4
|
-
import { expectTeamContent } from "./
|
|
4
|
+
import { expectTeamContent } from "./team.js";
|
|
5
5
|
import { AnonymousControlledAccount } from "./account.js";
|
|
6
6
|
export function randomAnonymousAccountAndSessionID() {
|
|
7
7
|
const agentSecret = newRandomAgentSecret();
|
package/dist/testUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,gBAAgB,EAAE,UAAU,EAAE,oBAAoB,EAAG,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../src/testUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,gBAAgB,EAAE,UAAU,EAAE,oBAAoB,EAAG,MAAM,aAAa,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG1D,MAAM,UAAU,kCAAkC;IAC9C,MAAM,WAAW,GAAG,oBAAoB,EAAE,CAAC;IAE3C,MAAM,SAAS,GAAG,kBAAkB,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;IAE9D,OAAO,CAAC,IAAI,0BAA0B,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,OAAO;IACnB,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,kCAAkC,EAAE,CAAC;IAEhE,MAAM,IAAI,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAE7C,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC;QAC5B,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,EAAE;QACjD,IAAI,EAAE,IAAI;Q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ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "0.0.
|
|
8
|
+
"version": "0.0.23",
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@types/jest": "^29.5.3",
|
|
11
11
|
"@typescript-eslint/eslint-plugin": "^6.2.1",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"/dist/"
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "6557532743f3d5984afd2c3754c3272fde009a2a"
|
|
56
56
|
}
|
package/src/account.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from "./crypto.js";
|
|
15
15
|
import { AgentID } from "./ids.js";
|
|
16
16
|
import { CoMap, LocalNode } from "./index.js";
|
|
17
|
-
import { Team, TeamContent } from "./
|
|
17
|
+
import { Team, TeamContent } from "./team.js";
|
|
18
18
|
|
|
19
19
|
export function accountHeaderForInitialAgentSecret(
|
|
20
20
|
agentSecret: AgentSecret
|
package/src/coValue.test.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { Transaction } from "./coValue.js";
|
|
|
2
2
|
import { LocalNode } from "./node.js";
|
|
3
3
|
import { createdNowUnique, getAgentSignerSecret, newRandomAgentSecret, sign } from "./crypto.js";
|
|
4
4
|
import { randomAnonymousAccountAndSessionID } from "./testUtils.js";
|
|
5
|
+
import { CoMap, MapOpPayload } from "./contentTypes/coMap.js";
|
|
6
|
+
import { AccountID } from "./index.js";
|
|
7
|
+
import { Role } from "./permissions.js";
|
|
5
8
|
|
|
6
9
|
test("Can create coValue with new agent credentials and add transaction to it", () => {
|
|
7
10
|
const [account, sessionID] = randomAnonymousAccountAndSessionID();
|
|
@@ -121,3 +124,58 @@ test("transactions with correctly signed, but wrong hash are rejected", () => {
|
|
|
121
124
|
)
|
|
122
125
|
).toBe(false);
|
|
123
126
|
});
|
|
127
|
+
|
|
128
|
+
test("New transactions in a team correctly update owned values, including subscriptions", async () => {
|
|
129
|
+
const [account, sessionID] = randomAnonymousAccountAndSessionID();
|
|
130
|
+
const node = new LocalNode(account, sessionID);
|
|
131
|
+
|
|
132
|
+
const team = node.createTeam();
|
|
133
|
+
|
|
134
|
+
const timeBeforeEdit = Date.now();
|
|
135
|
+
|
|
136
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
137
|
+
|
|
138
|
+
let map = team.createMap();
|
|
139
|
+
|
|
140
|
+
let mapAfterEdit = map.edit((map) => {
|
|
141
|
+
map.set("hello", "world");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const listener = jest.fn().mockImplementation();
|
|
145
|
+
|
|
146
|
+
map.subscribe(listener);
|
|
147
|
+
|
|
148
|
+
expect(listener.mock.calls[0][0].get("hello")).toBe("world");
|
|
149
|
+
|
|
150
|
+
const resignationThatWeJustLearnedAbout = {
|
|
151
|
+
privacy: "trusting",
|
|
152
|
+
madeAt: timeBeforeEdit,
|
|
153
|
+
changes: [
|
|
154
|
+
{
|
|
155
|
+
op: "set",
|
|
156
|
+
key: account.id,
|
|
157
|
+
value: "revoked"
|
|
158
|
+
} satisfies MapOpPayload<typeof account.id, Role>
|
|
159
|
+
]
|
|
160
|
+
} satisfies Transaction;
|
|
161
|
+
|
|
162
|
+
const { expectedNewHash } = team.teamMap.coValue.expectedNewHashAfter(sessionID, [
|
|
163
|
+
resignationThatWeJustLearnedAbout,
|
|
164
|
+
]);
|
|
165
|
+
|
|
166
|
+
const signature = sign(
|
|
167
|
+
node.account.currentSignerSecret(),
|
|
168
|
+
expectedNewHash
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
expect(map.coValue.getValidSortedTransactions().length).toBe(1);
|
|
172
|
+
|
|
173
|
+
const manuallyAdddedTxSuccess = team.teamMap.coValue.tryAddTransactions(node.ownSessionID, [resignationThatWeJustLearnedAbout], expectedNewHash, signature);
|
|
174
|
+
|
|
175
|
+
expect(manuallyAdddedTxSuccess).toBe(true);
|
|
176
|
+
|
|
177
|
+
expect(listener.mock.calls.length).toBe(2);
|
|
178
|
+
expect(listener.mock.calls[1][0].get("hello")).toBe(undefined);
|
|
179
|
+
|
|
180
|
+
expect(map.coValue.getValidSortedTransactions().length).toBe(0);
|
|
181
|
+
});
|