cojson 0.7.0-alpha.36 → 0.7.0-alpha.38
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/.eslintrc.cjs +3 -2
- package/.prettierrc.js +9 -0
- package/.turbo/turbo-build.log +3 -36
- package/.turbo/turbo-lint.log +4 -0
- package/.turbo/turbo-test.log +1106 -0
- package/CHANGELOG.md +12 -0
- package/README.md +3 -1
- package/dist/base64url.test.js +25 -0
- package/dist/base64url.test.js.map +1 -0
- package/dist/coValueCore.js +16 -15
- package/dist/coValueCore.js.map +1 -1
- package/dist/coValues/account.js +16 -15
- package/dist/coValues/account.js.map +1 -1
- package/dist/coValues/group.js +13 -14
- package/dist/coValues/group.js.map +1 -1
- package/dist/coreToCoValue.js.map +1 -1
- package/dist/crypto/PureJSCrypto.js +89 -0
- package/dist/crypto/PureJSCrypto.js.map +1 -0
- package/dist/crypto/WasmCrypto.js +127 -0
- package/dist/crypto/WasmCrypto.js.map +1 -0
- package/dist/crypto/crypto.js +151 -0
- package/dist/crypto/crypto.js.map +1 -0
- package/dist/ids.js +4 -2
- package/dist/ids.js.map +1 -1
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/jsonStringify.js.map +1 -1
- package/dist/localNode.js +24 -24
- package/dist/localNode.js.map +1 -1
- package/dist/permissions.js.map +1 -1
- package/dist/storage/FileSystem.js +2 -2
- package/dist/storage/FileSystem.js.map +1 -1
- package/dist/storage/chunksAndKnownStates.js +2 -2
- package/dist/storage/chunksAndKnownStates.js.map +1 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/sync.js +6 -2
- package/dist/sync.js.map +1 -1
- package/dist/tests/account.test.js +58 -0
- package/dist/tests/account.test.js.map +1 -0
- package/dist/tests/coList.test.js +76 -0
- package/dist/tests/coList.test.js.map +1 -0
- package/dist/tests/coMap.test.js +136 -0
- package/dist/tests/coMap.test.js.map +1 -0
- package/dist/tests/coStream.test.js +172 -0
- package/dist/tests/coStream.test.js.map +1 -0
- package/dist/tests/coValueCore.test.js +114 -0
- package/dist/tests/coValueCore.test.js.map +1 -0
- package/dist/tests/crypto.test.js +118 -0
- package/dist/tests/crypto.test.js.map +1 -0
- package/dist/tests/cryptoImpl.test.js +113 -0
- package/dist/tests/cryptoImpl.test.js.map +1 -0
- package/dist/tests/group.test.js +34 -0
- package/dist/tests/group.test.js.map +1 -0
- package/dist/tests/permissions.test.js +1060 -0
- package/dist/tests/permissions.test.js.map +1 -0
- package/dist/tests/sync.test.js +816 -0
- package/dist/tests/sync.test.js.map +1 -0
- package/dist/tests/testUtils.js +10 -9
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/typeUtils/accountOrAgentIDfromSessionID.js.map +1 -1
- package/dist/typeUtils/isAccountID.js.map +1 -1
- package/dist/typeUtils/isCoValue.js.map +1 -1
- package/package.json +14 -28
- package/src/base64url.test.ts +6 -6
- package/src/coValue.ts +1 -1
- package/src/coValueCore.ts +87 -85
- package/src/coValues/account.ts +26 -28
- package/src/coValues/coList.ts +10 -10
- package/src/coValues/coMap.ts +10 -10
- package/src/coValues/coStream.ts +17 -17
- package/src/coValues/group.ts +93 -109
- package/src/coreToCoValue.ts +5 -2
- package/src/crypto/PureJSCrypto.ts +200 -0
- package/src/crypto/WasmCrypto.ts +259 -0
- package/src/crypto/crypto.ts +336 -0
- package/src/ids.ts +8 -7
- package/src/index.ts +14 -26
- package/src/jsonStringify.ts +6 -4
- package/src/jsonValue.ts +2 -2
- package/src/localNode.ts +86 -80
- package/src/media.ts +3 -3
- package/src/permissions.ts +14 -16
- package/src/storage/FileSystem.ts +31 -30
- package/src/storage/chunksAndKnownStates.ts +24 -17
- package/src/storage/index.ts +42 -38
- package/src/streamUtils.ts +12 -12
- package/src/sync.ts +56 -40
- package/src/tests/account.test.ts +8 -12
- package/src/tests/coList.test.ts +19 -25
- package/src/tests/coMap.test.ts +25 -30
- package/src/tests/coStream.test.ts +28 -38
- package/src/tests/coValueCore.test.ts +35 -36
- package/src/tests/crypto.test.ts +66 -72
- package/src/tests/cryptoImpl.test.ts +183 -0
- package/src/tests/group.test.ts +16 -17
- package/src/tests/permissions.test.ts +237 -254
- package/src/tests/sync.test.ts +119 -120
- package/src/tests/testUtils.ts +22 -19
- package/src/typeUtils/accountOrAgentIDfromSessionID.ts +1 -2
- package/src/typeUtils/expectGroup.ts +1 -1
- package/src/typeUtils/isAccountID.ts +0 -1
- package/src/typeUtils/isCoValue.ts +1 -2
- package/tsconfig.json +0 -1
- package/dist/crypto.js +0 -255
- package/dist/crypto.js.map +0 -1
- package/src/crypto.ts +0 -485
package/src/coValues/coList.ts
CHANGED
|
@@ -196,7 +196,7 @@ export class RawCoListView<
|
|
|
196
196
|
} else {
|
|
197
197
|
throw new Error(
|
|
198
198
|
"Unknown list operation " +
|
|
199
|
-
(change as { op: unknown }).op
|
|
199
|
+
(change as { op: unknown }).op,
|
|
200
200
|
);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -285,7 +285,7 @@ export class RawCoListView<
|
|
|
285
285
|
value: Item;
|
|
286
286
|
madeAt: number;
|
|
287
287
|
opID: OpID;
|
|
288
|
-
}[]
|
|
288
|
+
}[],
|
|
289
289
|
) {
|
|
290
290
|
const entry =
|
|
291
291
|
this.insertions[opID.sessionID]?.[opID.txIndex]?.[opID.changeIdx];
|
|
@@ -372,7 +372,7 @@ export class RawCoListView<
|
|
|
372
372
|
for (const deletion of changeEntry || []) {
|
|
373
373
|
const madeAt = new Date(deletion.madeAt);
|
|
374
374
|
const by = accountOrAgentIDfromSessionID(
|
|
375
|
-
deletion.deletionID.sessionID
|
|
375
|
+
deletion.deletionID.sessionID,
|
|
376
376
|
);
|
|
377
377
|
edits.push({
|
|
378
378
|
by,
|
|
@@ -413,7 +413,7 @@ export class RawCoList<
|
|
|
413
413
|
append(
|
|
414
414
|
item: Item,
|
|
415
415
|
after?: number,
|
|
416
|
-
privacy: "private" | "trusting" = "private"
|
|
416
|
+
privacy: "private" | "trusting" = "private",
|
|
417
417
|
) {
|
|
418
418
|
const entries = this.entries();
|
|
419
419
|
after =
|
|
@@ -443,7 +443,7 @@ export class RawCoList<
|
|
|
443
443
|
after: opIDBefore,
|
|
444
444
|
},
|
|
445
445
|
],
|
|
446
|
-
privacy
|
|
446
|
+
privacy,
|
|
447
447
|
);
|
|
448
448
|
|
|
449
449
|
const listAfter = new RawCoList(this.core) as this;
|
|
@@ -467,7 +467,7 @@ export class RawCoList<
|
|
|
467
467
|
prepend(
|
|
468
468
|
item: Item,
|
|
469
469
|
before?: number,
|
|
470
|
-
privacy: "private" | "trusting" = "private"
|
|
470
|
+
privacy: "private" | "trusting" = "private",
|
|
471
471
|
) {
|
|
472
472
|
const entries = this.entries();
|
|
473
473
|
before = before === undefined ? 0 : before;
|
|
@@ -496,7 +496,7 @@ export class RawCoList<
|
|
|
496
496
|
before: opIDAfter,
|
|
497
497
|
},
|
|
498
498
|
],
|
|
499
|
-
privacy
|
|
499
|
+
privacy,
|
|
500
500
|
);
|
|
501
501
|
|
|
502
502
|
const listAfter = new RawCoList(this.core) as this;
|
|
@@ -529,7 +529,7 @@ export class RawCoList<
|
|
|
529
529
|
insertion: entry.opID,
|
|
530
530
|
},
|
|
531
531
|
],
|
|
532
|
-
privacy
|
|
532
|
+
privacy,
|
|
533
533
|
);
|
|
534
534
|
|
|
535
535
|
const listAfter = new RawCoList(this.core) as this;
|
|
@@ -544,7 +544,7 @@ export class RawCoList<
|
|
|
544
544
|
replace(
|
|
545
545
|
at: number,
|
|
546
546
|
newItem: Item,
|
|
547
|
-
privacy: "private" | "trusting" = "private"
|
|
547
|
+
privacy: "private" | "trusting" = "private",
|
|
548
548
|
) {
|
|
549
549
|
const entries = this.entries();
|
|
550
550
|
const entry = entries[at];
|
|
@@ -564,7 +564,7 @@ export class RawCoList<
|
|
|
564
564
|
insertion: entry.opID,
|
|
565
565
|
},
|
|
566
566
|
],
|
|
567
|
-
privacy
|
|
567
|
+
privacy,
|
|
568
568
|
);
|
|
569
569
|
const listAfter = new RawCoList(this.core) as this;
|
|
570
570
|
|
package/src/coValues/coMap.ts
CHANGED
|
@@ -50,14 +50,14 @@ export class RawCoMapView<
|
|
|
50
50
|
/** @internal */
|
|
51
51
|
constructor(
|
|
52
52
|
core: CoValueCore,
|
|
53
|
-
options?: { ignorePrivateTransactions: true }
|
|
53
|
+
options?: { ignorePrivateTransactions: true },
|
|
54
54
|
) {
|
|
55
55
|
this.id = core.id as CoID<this>;
|
|
56
56
|
this.core = core;
|
|
57
57
|
this.ops = {};
|
|
58
58
|
|
|
59
59
|
for (const { txID, changes, madeAt } of core.getValidSortedTransactions(
|
|
60
|
-
options
|
|
60
|
+
options,
|
|
61
61
|
)) {
|
|
62
62
|
for (const [changeIdx, changeUntyped] of changes.entries()) {
|
|
63
63
|
const change = changeUntyped as MapOpPayload<
|
|
@@ -105,11 +105,11 @@ export class RawCoMapView<
|
|
|
105
105
|
|
|
106
106
|
/** @internal */
|
|
107
107
|
timeFilteredOps<K extends keyof Shape & string>(
|
|
108
|
-
key: K
|
|
108
|
+
key: K,
|
|
109
109
|
): MapOp<K, Shape[K]>[] | undefined {
|
|
110
110
|
if (this.atTimeFilter) {
|
|
111
111
|
return this.ops[key]?.filter(
|
|
112
|
-
(op) => op.madeAt <= this.atTimeFilter
|
|
112
|
+
(op) => op.madeAt <= this.atTimeFilter!,
|
|
113
113
|
);
|
|
114
114
|
} else {
|
|
115
115
|
return this.ops[key];
|
|
@@ -193,7 +193,7 @@ export class RawCoMapView<
|
|
|
193
193
|
/** @category 5. Edit history */
|
|
194
194
|
nthEditAt<K extends keyof Shape & string>(
|
|
195
195
|
key: K,
|
|
196
|
-
n: number
|
|
196
|
+
n: number,
|
|
197
197
|
):
|
|
198
198
|
| {
|
|
199
199
|
by: AccountID | AgentID;
|
|
@@ -223,7 +223,7 @@ export class RawCoMapView<
|
|
|
223
223
|
|
|
224
224
|
/** @category 5. Edit history */
|
|
225
225
|
lastEditAt<K extends keyof Shape & string>(
|
|
226
|
-
key: K
|
|
226
|
+
key: K,
|
|
227
227
|
):
|
|
228
228
|
| {
|
|
229
229
|
by: AccountID | AgentID;
|
|
@@ -280,7 +280,7 @@ export class RawCoMap<
|
|
|
280
280
|
set<K extends keyof Shape & string>(
|
|
281
281
|
key: K,
|
|
282
282
|
value: Shape[K],
|
|
283
|
-
privacy: "private" | "trusting" = "private"
|
|
283
|
+
privacy: "private" | "trusting" = "private",
|
|
284
284
|
): void {
|
|
285
285
|
this.core.makeTransaction(
|
|
286
286
|
[
|
|
@@ -290,7 +290,7 @@ export class RawCoMap<
|
|
|
290
290
|
value: isCoValue(value) ? value.id : value,
|
|
291
291
|
},
|
|
292
292
|
],
|
|
293
|
-
privacy
|
|
293
|
+
privacy,
|
|
294
294
|
);
|
|
295
295
|
|
|
296
296
|
const after = new RawCoMap(this.core) as this;
|
|
@@ -308,7 +308,7 @@ export class RawCoMap<
|
|
|
308
308
|
**/
|
|
309
309
|
delete(
|
|
310
310
|
key: keyof Shape & string,
|
|
311
|
-
privacy: "private" | "trusting" = "private"
|
|
311
|
+
privacy: "private" | "trusting" = "private",
|
|
312
312
|
) {
|
|
313
313
|
this.core.makeTransaction(
|
|
314
314
|
[
|
|
@@ -317,7 +317,7 @@ export class RawCoMap<
|
|
|
317
317
|
key,
|
|
318
318
|
},
|
|
319
319
|
],
|
|
320
|
-
privacy
|
|
320
|
+
privacy,
|
|
321
321
|
);
|
|
322
322
|
|
|
323
323
|
const after = new RawCoMap(this.core) as this;
|
package/src/coValues/coStream.ts
CHANGED
|
@@ -43,7 +43,7 @@ export type CoStreamItem<Item extends JsonValue> = {
|
|
|
43
43
|
|
|
44
44
|
export class RawCoStreamView<
|
|
45
45
|
Item extends JsonValue = JsonValue,
|
|
46
|
-
Meta extends JsonObject | null = JsonObject | null
|
|
46
|
+
Meta extends JsonObject | null = JsonObject | null,
|
|
47
47
|
> implements RawCoValue
|
|
48
48
|
{
|
|
49
49
|
id: CoID<this>;
|
|
@@ -100,7 +100,7 @@ export class RawCoStreamView<
|
|
|
100
100
|
return undefined;
|
|
101
101
|
} else if (Object.keys(this.items).length !== 1) {
|
|
102
102
|
throw new Error(
|
|
103
|
-
"CoStream.getSingleStream() can only be called when there is exactly one stream"
|
|
103
|
+
"CoStream.getSingleStream() can only be called when there is exactly one stream",
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -115,13 +115,13 @@ export class RawCoStreamView<
|
|
|
115
115
|
return new Set(
|
|
116
116
|
this.sessions()
|
|
117
117
|
.map(accountOrAgentIDfromSessionID)
|
|
118
|
-
.filter(isAccountID)
|
|
118
|
+
.filter(isAccountID),
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
nthItemIn(
|
|
123
123
|
sessionID: SessionID,
|
|
124
|
-
n: number
|
|
124
|
+
n: number,
|
|
125
125
|
):
|
|
126
126
|
| {
|
|
127
127
|
by: AccountID | AgentID;
|
|
@@ -214,7 +214,7 @@ export class RawCoStreamView<
|
|
|
214
214
|
in: sessionID as SessionID,
|
|
215
215
|
...item,
|
|
216
216
|
}))
|
|
217
|
-
: []
|
|
217
|
+
: [],
|
|
218
218
|
),
|
|
219
219
|
];
|
|
220
220
|
|
|
@@ -232,7 +232,7 @@ export class RawCoStreamView<
|
|
|
232
232
|
Object.entries(this.items).map(([sessionID, items]) => [
|
|
233
233
|
sessionID,
|
|
234
234
|
items.map((item) => item.value),
|
|
235
|
-
])
|
|
235
|
+
]),
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
238
|
|
|
@@ -245,7 +245,7 @@ export class RawCoStreamView<
|
|
|
245
245
|
|
|
246
246
|
export class RawCoStream<
|
|
247
247
|
Item extends JsonValue = JsonValue,
|
|
248
|
-
Meta extends JsonObject | null = JsonObject | null
|
|
248
|
+
Meta extends JsonObject | null = JsonObject | null,
|
|
249
249
|
>
|
|
250
250
|
extends RawCoStreamView<Item, Meta>
|
|
251
251
|
implements RawCoValue
|
|
@@ -259,13 +259,13 @@ export class RawCoStream<
|
|
|
259
259
|
const binary_U_prefixLength = 8; // "binary_U".length;
|
|
260
260
|
|
|
261
261
|
export class RawBinaryCoStreamView<
|
|
262
|
-
Meta extends BinaryCoStreamMeta = { type: "binary" }
|
|
262
|
+
Meta extends BinaryCoStreamMeta = { type: "binary" },
|
|
263
263
|
>
|
|
264
264
|
extends RawCoStreamView<BinaryStreamItem, Meta>
|
|
265
265
|
implements RawCoValue
|
|
266
266
|
{
|
|
267
267
|
getBinaryChunks(
|
|
268
|
-
allowUnfinished?: boolean
|
|
268
|
+
allowUnfinished?: boolean,
|
|
269
269
|
):
|
|
270
270
|
| (BinaryStreamInfo & { chunks: Uint8Array[]; finished: boolean })
|
|
271
271
|
| undefined {
|
|
@@ -304,7 +304,7 @@ export class RawBinaryCoStreamView<
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
const chunk = base64URLtoBytes(
|
|
307
|
-
item.chunk.slice(binary_U_prefixLength)
|
|
307
|
+
item.chunk.slice(binary_U_prefixLength),
|
|
308
308
|
);
|
|
309
309
|
// totalLength += chunk.length;
|
|
310
310
|
chunks.push(chunk);
|
|
@@ -331,7 +331,7 @@ export class RawBinaryCoStreamView<
|
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
export class RawBinaryCoStream<
|
|
334
|
-
Meta extends BinaryCoStreamMeta = { type: "binary" }
|
|
334
|
+
Meta extends BinaryCoStreamMeta = { type: "binary" },
|
|
335
335
|
>
|
|
336
336
|
extends RawBinaryCoStreamView<Meta>
|
|
337
337
|
implements RawCoValue
|
|
@@ -340,7 +340,7 @@ export class RawBinaryCoStream<
|
|
|
340
340
|
push(
|
|
341
341
|
item: BinaryStreamItem,
|
|
342
342
|
privacy: "private" | "trusting" = "private",
|
|
343
|
-
updateView: boolean = true
|
|
343
|
+
updateView: boolean = true,
|
|
344
344
|
): void {
|
|
345
345
|
this.core.makeTransaction([item], privacy);
|
|
346
346
|
if (updateView) {
|
|
@@ -350,7 +350,7 @@ export class RawBinaryCoStream<
|
|
|
350
350
|
|
|
351
351
|
startBinaryStream(
|
|
352
352
|
settings: BinaryStreamInfo,
|
|
353
|
-
privacy: "private" | "trusting" = "private"
|
|
353
|
+
privacy: "private" | "trusting" = "private",
|
|
354
354
|
): void {
|
|
355
355
|
this.push(
|
|
356
356
|
{
|
|
@@ -358,13 +358,13 @@ export class RawBinaryCoStream<
|
|
|
358
358
|
...settings,
|
|
359
359
|
} satisfies BinaryStreamStart,
|
|
360
360
|
privacy,
|
|
361
|
-
false
|
|
361
|
+
false,
|
|
362
362
|
);
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
pushBinaryStreamChunk(
|
|
366
366
|
chunk: Uint8Array,
|
|
367
|
-
privacy: "private" | "trusting" = "private"
|
|
367
|
+
privacy: "private" | "trusting" = "private",
|
|
368
368
|
): void {
|
|
369
369
|
// const before = performance.now();
|
|
370
370
|
this.push(
|
|
@@ -373,7 +373,7 @@ export class RawBinaryCoStream<
|
|
|
373
373
|
chunk: `binary_U${bytesToBase64url(chunk)}`,
|
|
374
374
|
} satisfies BinaryStreamChunk,
|
|
375
375
|
privacy,
|
|
376
|
-
false
|
|
376
|
+
false,
|
|
377
377
|
);
|
|
378
378
|
// const after = performance.now();
|
|
379
379
|
// console.log(
|
|
@@ -388,7 +388,7 @@ export class RawBinaryCoStream<
|
|
|
388
388
|
type: "end",
|
|
389
389
|
} satisfies BinaryStreamEnd,
|
|
390
390
|
privacy,
|
|
391
|
-
true
|
|
391
|
+
true,
|
|
392
392
|
);
|
|
393
393
|
}
|
|
394
394
|
}
|
package/src/coValues/group.ts
CHANGED
|
@@ -3,26 +3,9 @@ import { RawCoMap } from "./coMap.js";
|
|
|
3
3
|
import { RawCoList } from "./coList.js";
|
|
4
4
|
import { JsonObject } from "../jsonValue.js";
|
|
5
5
|
import { RawBinaryCoStream, RawCoStream } from "./coStream.js";
|
|
6
|
-
import {
|
|
7
|
-
Encrypted,
|
|
8
|
-
KeyID,
|
|
9
|
-
KeySecret,
|
|
10
|
-
createdNowUnique,
|
|
11
|
-
newRandomKeySecret,
|
|
12
|
-
seal,
|
|
13
|
-
encryptKeySecret,
|
|
14
|
-
getAgentSealerID,
|
|
15
|
-
Sealed,
|
|
16
|
-
newRandomSecretSeed,
|
|
17
|
-
agentSecretFromSecretSeed,
|
|
18
|
-
getAgentID,
|
|
19
|
-
} from "../crypto.js";
|
|
6
|
+
import { Encrypted, KeyID, KeySecret, Sealed } from "../crypto/crypto.js";
|
|
20
7
|
import { AgentID, isAgentID } from "../ids.js";
|
|
21
|
-
import {
|
|
22
|
-
RawAccount,
|
|
23
|
-
AccountID,
|
|
24
|
-
ControlledAccountOrAgent,
|
|
25
|
-
} from "./account.js";
|
|
8
|
+
import { RawAccount, AccountID, ControlledAccountOrAgent } from "./account.js";
|
|
26
9
|
import { Role } from "../permissions.js";
|
|
27
10
|
import { base58 } from "@scure/base";
|
|
28
11
|
|
|
@@ -65,7 +48,7 @@ export type GroupShape = {
|
|
|
65
48
|
* ```
|
|
66
49
|
* */
|
|
67
50
|
export class RawGroup<
|
|
68
|
-
Meta extends JsonObject | null = JsonObject | null
|
|
51
|
+
Meta extends JsonObject | null = JsonObject | null,
|
|
69
52
|
> extends RawCoMap<GroupShape, Meta> {
|
|
70
53
|
/**
|
|
71
54
|
* Returns the current role of a given account.
|
|
@@ -98,7 +81,7 @@ export class RawGroup<
|
|
|
98
81
|
*/
|
|
99
82
|
addMember(
|
|
100
83
|
account: RawAccount | ControlledAccountOrAgent | Everyone,
|
|
101
|
-
role: Role
|
|
84
|
+
role: Role,
|
|
102
85
|
) {
|
|
103
86
|
this.addMemberInternal(account, role);
|
|
104
87
|
}
|
|
@@ -106,58 +89,58 @@ export class RawGroup<
|
|
|
106
89
|
/** @internal */
|
|
107
90
|
addMemberInternal(
|
|
108
91
|
account: RawAccount | ControlledAccountOrAgent | AgentID | Everyone,
|
|
109
|
-
role: Role
|
|
92
|
+
role: Role,
|
|
110
93
|
) {
|
|
111
|
-
|
|
94
|
+
const currentReadKey = this.core.getCurrentReadKey();
|
|
112
95
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
96
|
+
if (!currentReadKey.secret) {
|
|
97
|
+
throw new Error("Can't add member without read key secret");
|
|
98
|
+
}
|
|
116
99
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
this.set(account, role, "trusting");
|
|
124
|
-
|
|
125
|
-
if (this.get(account) !== role) {
|
|
126
|
-
throw new Error("Failed to set role");
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this.set(
|
|
130
|
-
`${currentReadKey.id}_for_${EVERYONE}`,
|
|
131
|
-
currentReadKey.secret,
|
|
132
|
-
"trusting"
|
|
133
|
-
);
|
|
134
|
-
} else {
|
|
135
|
-
const memberKey =
|
|
136
|
-
typeof account === "string" ? account : account.id;
|
|
137
|
-
const agent =
|
|
138
|
-
typeof account === "string"
|
|
139
|
-
? account
|
|
140
|
-
: account.currentAgentID();
|
|
141
|
-
this.set(memberKey, role, "trusting");
|
|
142
|
-
|
|
143
|
-
if (this.get(memberKey) !== role) {
|
|
144
|
-
throw new Error("Failed to set role");
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
this.set(
|
|
148
|
-
`${currentReadKey.id}_for_${memberKey}`,
|
|
149
|
-
seal({
|
|
150
|
-
message: currentReadKey.secret,
|
|
151
|
-
from: this.core.node.account.currentSealerSecret(),
|
|
152
|
-
to: getAgentSealerID(agent),
|
|
153
|
-
nOnceMaterial: {
|
|
154
|
-
in: this.id,
|
|
155
|
-
tx: this.core.nextTransactionID(),
|
|
156
|
-
},
|
|
157
|
-
}),
|
|
158
|
-
"trusting"
|
|
100
|
+
if (account === EVERYONE) {
|
|
101
|
+
if (!(role === "reader" || role === "writer")) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
"Can't make everyone something other than reader or writer",
|
|
159
104
|
);
|
|
160
105
|
}
|
|
106
|
+
this.set(account, role, "trusting");
|
|
107
|
+
|
|
108
|
+
if (this.get(account) !== role) {
|
|
109
|
+
throw new Error("Failed to set role");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.set(
|
|
113
|
+
`${currentReadKey.id}_for_${EVERYONE}`,
|
|
114
|
+
currentReadKey.secret,
|
|
115
|
+
"trusting",
|
|
116
|
+
);
|
|
117
|
+
} else {
|
|
118
|
+
const memberKey =
|
|
119
|
+
typeof account === "string" ? account : account.id;
|
|
120
|
+
const agent =
|
|
121
|
+
typeof account === "string"
|
|
122
|
+
? account
|
|
123
|
+
: account.currentAgentID();
|
|
124
|
+
this.set(memberKey, role, "trusting");
|
|
125
|
+
|
|
126
|
+
if (this.get(memberKey) !== role) {
|
|
127
|
+
throw new Error("Failed to set role");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.set(
|
|
131
|
+
`${currentReadKey.id}_for_${memberKey}`,
|
|
132
|
+
this.core.crypto.seal({
|
|
133
|
+
message: currentReadKey.secret,
|
|
134
|
+
from: this.core.node.account.currentSealerSecret(),
|
|
135
|
+
to: this.core.crypto.getAgentSealerID(agent),
|
|
136
|
+
nOnceMaterial: {
|
|
137
|
+
in: this.id,
|
|
138
|
+
tx: this.core.nextTransactionID(),
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
"trusting",
|
|
142
|
+
);
|
|
143
|
+
}
|
|
161
144
|
}
|
|
162
145
|
|
|
163
146
|
/** @internal */
|
|
@@ -177,7 +160,7 @@ export class RawGroup<
|
|
|
177
160
|
|
|
178
161
|
if (!maybeCurrentReadKey.secret) {
|
|
179
162
|
throw new Error(
|
|
180
|
-
"Can't rotate read key secret we don't have access to"
|
|
163
|
+
"Can't rotate read key secret we don't have access to",
|
|
181
164
|
);
|
|
182
165
|
}
|
|
183
166
|
|
|
@@ -186,39 +169,39 @@ export class RawGroup<
|
|
|
186
169
|
secret: maybeCurrentReadKey.secret,
|
|
187
170
|
};
|
|
188
171
|
|
|
189
|
-
const newReadKey = newRandomKeySecret();
|
|
172
|
+
const newReadKey = this.core.crypto.newRandomKeySecret();
|
|
190
173
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.set(
|
|
198
|
-
`${newReadKey.id}_for_${readerID}`,
|
|
199
|
-
seal({
|
|
200
|
-
message: newReadKey.secret,
|
|
201
|
-
from: this.core.node.account.currentSealerSecret(),
|
|
202
|
-
to: getAgentSealerID(reader),
|
|
203
|
-
nOnceMaterial: {
|
|
204
|
-
in: this.id,
|
|
205
|
-
tx: this.core.nextTransactionID(),
|
|
206
|
-
},
|
|
207
|
-
}),
|
|
208
|
-
"trusting"
|
|
209
|
-
);
|
|
210
|
-
}
|
|
174
|
+
for (const readerID of currentlyPermittedReaders) {
|
|
175
|
+
const reader = this.core.node.resolveAccountAgent(
|
|
176
|
+
readerID,
|
|
177
|
+
"Expected to know currently permitted reader",
|
|
178
|
+
);
|
|
211
179
|
|
|
212
180
|
this.set(
|
|
213
|
-
`${
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
181
|
+
`${newReadKey.id}_for_${readerID}`,
|
|
182
|
+
this.core.crypto.seal({
|
|
183
|
+
message: newReadKey.secret,
|
|
184
|
+
from: this.core.node.account.currentSealerSecret(),
|
|
185
|
+
to: this.core.crypto.getAgentSealerID(reader),
|
|
186
|
+
nOnceMaterial: {
|
|
187
|
+
in: this.id,
|
|
188
|
+
tx: this.core.nextTransactionID(),
|
|
189
|
+
},
|
|
190
|
+
}),
|
|
191
|
+
"trusting",
|
|
219
192
|
);
|
|
193
|
+
}
|
|
220
194
|
|
|
221
|
-
|
|
195
|
+
this.set(
|
|
196
|
+
`${currentReadKey.id}_for_${newReadKey.id}`,
|
|
197
|
+
this.core.crypto.encryptKeySecret({
|
|
198
|
+
encrypting: newReadKey,
|
|
199
|
+
toEncrypt: currentReadKey,
|
|
200
|
+
}).encrypted,
|
|
201
|
+
"trusting",
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
this.set("readKey", newReadKey.id, "trusting");
|
|
222
205
|
}
|
|
223
206
|
|
|
224
207
|
/**
|
|
@@ -234,10 +217,10 @@ export class RawGroup<
|
|
|
234
217
|
|
|
235
218
|
/** @internal */
|
|
236
219
|
removeMemberInternal(
|
|
237
|
-
account: RawAccount | ControlledAccountOrAgent | AgentID | Everyone
|
|
220
|
+
account: RawAccount | ControlledAccountOrAgent | AgentID | Everyone,
|
|
238
221
|
) {
|
|
239
222
|
const memberKey = typeof account === "string" ? account : account.id;
|
|
240
|
-
|
|
223
|
+
this.set(memberKey, "revoked", "trusting");
|
|
241
224
|
this.rotateReadKey();
|
|
242
225
|
}
|
|
243
226
|
|
|
@@ -249,10 +232,11 @@ export class RawGroup<
|
|
|
249
232
|
* @category 2. Role changing
|
|
250
233
|
*/
|
|
251
234
|
createInvite(role: "reader" | "writer" | "admin"): InviteSecret {
|
|
252
|
-
const secretSeed = newRandomSecretSeed();
|
|
235
|
+
const secretSeed = this.core.crypto.newRandomSecretSeed();
|
|
253
236
|
|
|
254
|
-
const inviteSecret =
|
|
255
|
-
|
|
237
|
+
const inviteSecret =
|
|
238
|
+
this.core.crypto.agentSecretFromSecretSeed(secretSeed);
|
|
239
|
+
const inviteID = this.core.crypto.getAgentID(inviteSecret);
|
|
256
240
|
|
|
257
241
|
this.addMemberInternal(inviteID, `${role}Invite` as Role);
|
|
258
242
|
|
|
@@ -268,7 +252,7 @@ export class RawGroup<
|
|
|
268
252
|
createMap<M extends RawCoMap>(
|
|
269
253
|
init?: M["_shape"],
|
|
270
254
|
meta?: M["headerMeta"],
|
|
271
|
-
initPrivacy: "trusting" | "private" = "private"
|
|
255
|
+
initPrivacy: "trusting" | "private" = "private",
|
|
272
256
|
): M {
|
|
273
257
|
const map = this.core.node
|
|
274
258
|
.createCoValue({
|
|
@@ -278,7 +262,7 @@ export class RawGroup<
|
|
|
278
262
|
group: this.id,
|
|
279
263
|
},
|
|
280
264
|
meta: meta || null,
|
|
281
|
-
...createdNowUnique(),
|
|
265
|
+
...this.core.crypto.createdNowUnique(),
|
|
282
266
|
})
|
|
283
267
|
.getCurrentContent() as M;
|
|
284
268
|
|
|
@@ -300,7 +284,7 @@ export class RawGroup<
|
|
|
300
284
|
createList<L extends RawCoList>(
|
|
301
285
|
init?: L["_item"][],
|
|
302
286
|
meta?: L["headerMeta"],
|
|
303
|
-
initPrivacy: "trusting" | "private" = "private"
|
|
287
|
+
initPrivacy: "trusting" | "private" = "private",
|
|
304
288
|
): L {
|
|
305
289
|
const list = this.core.node
|
|
306
290
|
.createCoValue({
|
|
@@ -310,7 +294,7 @@ export class RawGroup<
|
|
|
310
294
|
group: this.id,
|
|
311
295
|
},
|
|
312
296
|
meta: meta || null,
|
|
313
|
-
...createdNowUnique(),
|
|
297
|
+
...this.core.crypto.createdNowUnique(),
|
|
314
298
|
})
|
|
315
299
|
.getCurrentContent() as L;
|
|
316
300
|
|
|
@@ -333,14 +317,14 @@ export class RawGroup<
|
|
|
333
317
|
group: this.id,
|
|
334
318
|
},
|
|
335
319
|
meta: meta || null,
|
|
336
|
-
...createdNowUnique(),
|
|
320
|
+
...this.core.crypto.createdNowUnique(),
|
|
337
321
|
})
|
|
338
322
|
.getCurrentContent() as C;
|
|
339
323
|
}
|
|
340
324
|
|
|
341
325
|
/** @category 3. Value creation */
|
|
342
326
|
createBinaryStream<C extends RawBinaryCoStream>(
|
|
343
|
-
meta: C["headerMeta"] = { type: "binary" }
|
|
327
|
+
meta: C["headerMeta"] = { type: "binary" },
|
|
344
328
|
): C {
|
|
345
329
|
return this.core.node
|
|
346
330
|
.createCoValue({
|
|
@@ -350,7 +334,7 @@ export class RawGroup<
|
|
|
350
334
|
group: this.id,
|
|
351
335
|
},
|
|
352
336
|
meta: meta,
|
|
353
|
-
...createdNowUnique(),
|
|
337
|
+
...this.core.crypto.createdNowUnique(),
|
|
354
338
|
})
|
|
355
339
|
.getCurrentContent() as C;
|
|
356
340
|
}
|
package/src/coreToCoValue.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { RawBinaryCoStream } from "./coValues/coStream.js";
|
|
|
8
8
|
|
|
9
9
|
export function coreToCoValue(
|
|
10
10
|
core: CoValueCore,
|
|
11
|
-
options?: { ignorePrivateTransactions: true }
|
|
11
|
+
options?: { ignorePrivateTransactions: true },
|
|
12
12
|
) {
|
|
13
13
|
if (core.header.type === "comap") {
|
|
14
14
|
if (core.header.ruleset.type === "group") {
|
|
@@ -17,7 +17,10 @@ export function coreToCoValue(
|
|
|
17
17
|
!options?.ignorePrivateTransactions
|
|
18
18
|
) {
|
|
19
19
|
if (core.id === core.node.account.id) {
|
|
20
|
-
return new RawControlledAccount(
|
|
20
|
+
return new RawControlledAccount(
|
|
21
|
+
core,
|
|
22
|
+
core.node.account.agentSecret,
|
|
23
|
+
);
|
|
21
24
|
} else {
|
|
22
25
|
return new RawAccount(core);
|
|
23
26
|
}
|