@kumiai/mls 0.12.2 → 0.12.3
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/lib/group-handle.d.ts +6 -0
- package/lib/group-handle.js +85 -21
- package/package.json +2 -2
package/lib/group-handle.d.ts
CHANGED
|
@@ -94,6 +94,12 @@ export type GroupHandleParams = {
|
|
|
94
94
|
export declare class GroupHandle {
|
|
95
95
|
#private;
|
|
96
96
|
constructor(params: GroupHandleParams);
|
|
97
|
+
/** Copy the current checkpoint without replaying ledger tokens or sharing mutable state.
|
|
98
|
+
* Pending adoption notifications belong to the source; the copy starts non-speculative. */
|
|
99
|
+
clone(options?: {
|
|
100
|
+
resolveLedgerEntries?: (ids: Array<string>) => Promise<Array<string>>;
|
|
101
|
+
onLedgerEntries?: (entries: Array<VerifiedLedgerEntry>) => void;
|
|
102
|
+
}): GroupHandle;
|
|
97
103
|
sendAdmission(): SendAdmission;
|
|
98
104
|
confirmAdopted(): void;
|
|
99
105
|
get groupID(): string;
|
package/lib/group-handle.js
CHANGED
|
@@ -25,6 +25,8 @@ import { readSenderLeafIndex } from './sender-data.js';
|
|
|
25
25
|
/** One serializer per live handle, so its state-mutating operations run one at a
|
|
26
26
|
* time in issue order. Keyed weakly: the entry is collected with the handle, and
|
|
27
27
|
* the handle carries no reference back to it. */ const MUTEXES = new WeakMap();
|
|
28
|
+
// Module-private construction path: only clone can supply an already-folded snapshot.
|
|
29
|
+
const CLONE_SOURCE = Symbol('cloneSource');
|
|
28
30
|
const HISTORICAL_REGISTRIES = new WeakMap();
|
|
29
31
|
export function registryAt(group, head) {
|
|
30
32
|
let cache = HISTORICAL_REGISTRIES.get(group);
|
|
@@ -346,27 +348,55 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
346
348
|
this.#commitPolicy = params.commitPolicy;
|
|
347
349
|
this.#resolveLedgerEntries = params.resolveLedgerEntries;
|
|
348
350
|
this.#onLedgerEntries = params.onLedgerEntries;
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
351
|
+
const source = params[CLONE_SOURCE];
|
|
352
|
+
let admission;
|
|
353
|
+
if (source != null) {
|
|
354
|
+
const snapshot = structuredClone({
|
|
355
|
+
anchor: source.#anchor,
|
|
356
|
+
ledger: source.#ledger,
|
|
357
|
+
entryBodies: source.#entryBodies,
|
|
358
|
+
roster: source.#roster,
|
|
359
|
+
registry: source.#registry,
|
|
360
|
+
admission: source.#admission
|
|
361
|
+
});
|
|
362
|
+
this.#anchor = snapshot.anchor;
|
|
363
|
+
this.#ledger = snapshot.ledger;
|
|
364
|
+
this.#entryBodies = snapshot.entryBodies;
|
|
365
|
+
this.#roster = snapshot.roster;
|
|
366
|
+
this.#registry = snapshot.registry;
|
|
367
|
+
admission = Object.freeze(snapshot.admission);
|
|
368
|
+
// Preserve the trusted snapshot, never promote caller-mutated exposed claims.
|
|
369
|
+
for (const [index, held] of source.#ledger.entries()){
|
|
370
|
+
const copied = this.#ledger[index];
|
|
371
|
+
const verified = VERIFIED_LEDGER_ENTRIES.get(held.verified);
|
|
372
|
+
if (copied != null && verified != null) {
|
|
373
|
+
VERIFIED_LEDGER_ENTRIES.set(copied.verified, structuredClone(verified));
|
|
365
374
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
// Seed control state from the genesis anchor in the group's GroupContext. Reading
|
|
378
|
+
// it here makes the constructor the single choke no anchorless handle slips
|
|
379
|
+
// through: an absent anchor fails closed rather than installing a permissive roster.
|
|
380
|
+
const anchor = readGroupAnchor(this);
|
|
381
|
+
if (anchor == null) {
|
|
382
|
+
throw new Error('group has no anchor extension; cannot seed a control roster');
|
|
383
|
+
}
|
|
384
|
+
this.#anchor = anchor;
|
|
385
|
+
this.#ledger = [
|
|
386
|
+
...params.ledger ?? []
|
|
387
|
+
];
|
|
388
|
+
this.#entryBodies = new Map(this.#ledger.map(({ entryID, token, verified })=>[
|
|
389
|
+
entryID,
|
|
390
|
+
{
|
|
391
|
+
token,
|
|
392
|
+
verified
|
|
393
|
+
}
|
|
394
|
+
]));
|
|
395
|
+
const folded = foldLedgerControl(this.#ledger, anchor, this.groupID);
|
|
396
|
+
this.#roster = folded.roster;
|
|
397
|
+
this.#registry = registryWithTreeBindings(folded.registry, this.#state.ratchetTree, this.#anchor);
|
|
398
|
+
}
|
|
399
|
+
const anchor = this.#anchor;
|
|
370
400
|
// Authentication reads only this handle's registry and lifetime limits.
|
|
371
401
|
const denyHolder = deviceDenyHolderFor(this.#context);
|
|
372
402
|
if (denyHolder != null) {
|
|
@@ -381,7 +411,41 @@ function ledgerLogEntry(entryID, token, verified) {
|
|
|
381
411
|
}
|
|
382
412
|
EMITTERS.set(this, params.events ?? new EventEmitter());
|
|
383
413
|
this.#pendingControlEvents = params.speculative ? [] : undefined;
|
|
384
|
-
this.#admission = this.#computeAdmission();
|
|
414
|
+
this.#admission = admission ?? this.#computeAdmission();
|
|
415
|
+
}
|
|
416
|
+
/** Copy the current checkpoint without replaying ledger tokens or sharing mutable state.
|
|
417
|
+
* Pending adoption notifications belong to the source; the copy starts non-speculative. */ clone(options) {
|
|
418
|
+
const context = deviceDenyHolderFor(this.#context) == null ? {
|
|
419
|
+
...this.#context,
|
|
420
|
+
// External authentication is caller-owned behaviour, like the cipher suite and callbacks.
|
|
421
|
+
authService: {
|
|
422
|
+
validateCredential: this.#context.authService.validateCredential.bind(this.#context.authService)
|
|
423
|
+
}
|
|
424
|
+
} : createMlsContext(this.#context.cipherSuite, this.#anchor);
|
|
425
|
+
const config = this.#context.clientConfig;
|
|
426
|
+
if (config != null) {
|
|
427
|
+
const equality = config.keyPackageEqualityConfig;
|
|
428
|
+
context.clientConfig = {
|
|
429
|
+
keyRetentionConfig: structuredClone(config.keyRetentionConfig),
|
|
430
|
+
lifetimeConfig: structuredClone(config.lifetimeConfig),
|
|
431
|
+
paddingConfig: structuredClone(config.paddingConfig),
|
|
432
|
+
keyPackageEqualityConfig: {
|
|
433
|
+
compareKeyPackages: equality.compareKeyPackages.bind(equality),
|
|
434
|
+
compareKeyPackageToLeafNode: equality.compareKeyPackageToLeafNode.bind(equality)
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
context.externalPsks = structuredClone(this.#context.externalPsks);
|
|
439
|
+
const params = {
|
|
440
|
+
[CLONE_SOURCE]: this,
|
|
441
|
+
state: structuredClone(this.#state),
|
|
442
|
+
credential: structuredClone(this.#credential),
|
|
443
|
+
context,
|
|
444
|
+
commitPolicy: this.#commitPolicy,
|
|
445
|
+
resolveLedgerEntries: options?.resolveLedgerEntries ?? this.#resolveLedgerEntries,
|
|
446
|
+
onLedgerEntries: options?.onLedgerEntries ?? this.#onLedgerEntries
|
|
447
|
+
};
|
|
448
|
+
return new GroupHandle(params);
|
|
385
449
|
}
|
|
386
450
|
#computeAdmission() {
|
|
387
451
|
const leaf = leafAt(this.#state.ratchetTree, this.#state.privatePath.leafIndex);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumiai/mls",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "E2EE group identity and membership for Enkaku using MLS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mls",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@kokuin/capability": "^0.5.2",
|
|
29
29
|
"@kokuin/controller": "^0.2.5",
|
|
30
|
-
"@kokuin/token": "^0.6.
|
|
30
|
+
"@kokuin/token": "^0.6.4",
|
|
31
31
|
"@noble/ciphers": "^2.4.0",
|
|
32
32
|
"@noble/curves": "^2.4.0",
|
|
33
33
|
"@noble/hashes": "^2.4.0",
|