@kumiai/mls 0.3.1 → 0.4.1
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/README.md +3 -3
- package/lib/anchor.d.ts +39 -53
- package/lib/anchor.js +36 -44
- package/lib/codec.js +35 -2
- package/lib/credential.d.ts +7 -0
- package/lib/credential.js +13 -2
- package/lib/crypto.js +1 -0
- package/lib/envelope-fold.d.ts +4 -3
- package/lib/envelope-fold.js +5 -5
- package/lib/group-credential.js +1 -0
- package/lib/group-handle.d.ts +97 -10
- package/lib/group-handle.js +228 -23
- package/lib/group-welcome.d.ts +0 -3
- package/lib/group-welcome.js +1 -3
- package/lib/policy.d.ts +27 -34
- package/lib/policy.js +58 -56
- package/lib/recovery.d.ts +5 -5
- package/lib/recovery.js +44 -24
- package/lib/roster.d.ts +2 -2
- package/lib/roster.js +2 -2
- package/lib/types.d.ts +2 -2
- package/package.json +10 -10
package/lib/group-handle.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { normalizeDID } from '@kokuin/token';
|
|
2
|
-
import { contentTypes, createApplicationMessage, decode, encode, mlsMessageDecoder, mlsMessageEncoder, processMessage as mlsProcessMessage, nodeTypes, senderTypes, wireformats } from 'ts-mls';
|
|
2
|
+
import { contentTypes, createApplicationMessage, decode, encode, mlsExporter, mlsMessageDecoder, mlsMessageEncoder, processMessage as mlsProcessMessage, nodeTypes, senderTypes, wireformats } from 'ts-mls';
|
|
3
3
|
import { readGroupAnchor } from './anchor.js';
|
|
4
4
|
import { parseMLSCredentialIdentity } from './credential.js';
|
|
5
5
|
import { decodeControlEnvelope } from './envelope.js';
|
|
6
|
-
import { foldEnvelope } from './envelope-fold.js';
|
|
6
|
+
import { foldEnvelope, GROUP_TYPE_PREFIX } from './envelope-fold.js';
|
|
7
7
|
import { readMessageEpoch } from './group-info.js';
|
|
8
8
|
import { assertHeadMatches, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, headsMatch, readLedgerHead, readLedgerHeadExtension } from './head.js';
|
|
9
9
|
import { ledgerEntryDigest, verifyLedgerEntry } from './ledger.js';
|
|
@@ -77,14 +77,18 @@ export function mutexFor(handle) {
|
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Narrow a decoded frame to the PrivateMessage
|
|
81
|
-
* Returns undefined for anything that is not a PrivateMessage of
|
|
82
|
-
|
|
80
|
+
* Narrow a decoded frame to the PrivateMessage fields sender-data decrypt reads, for one
|
|
81
|
+
* content type. Returns undefined for anything that is not a PrivateMessage of that type.
|
|
82
|
+
*
|
|
83
|
+
* The sender-data derivation (RFC 9420 §6.3.2) is content-type-agnostic — the type is one
|
|
84
|
+
* byte of the AAD — so the same read serves a commit's committer and an application
|
|
85
|
+
* message's author.
|
|
86
|
+
*/ function readPrivateFrame(decoded, contentType) {
|
|
83
87
|
if (decoded == null || typeof decoded !== 'object') return undefined;
|
|
84
88
|
const frame = decoded;
|
|
85
89
|
if (frame.wireformat !== wireformats.mls_private_message) return undefined;
|
|
86
90
|
const pm = frame.privateMessage;
|
|
87
|
-
if (pm == null || pm.contentType !==
|
|
91
|
+
if (pm == null || pm.contentType !== contentType) return undefined;
|
|
88
92
|
if (!(pm.groupId instanceof Uint8Array) || typeof pm.epoch !== 'bigint' || !(pm.encryptedSenderData instanceof Uint8Array) || !(pm.ciphertext instanceof Uint8Array)) {
|
|
89
93
|
return undefined;
|
|
90
94
|
}
|
|
@@ -97,13 +101,18 @@ export function mutexFor(handle) {
|
|
|
97
101
|
};
|
|
98
102
|
}
|
|
99
103
|
/**
|
|
100
|
-
* Read the DID an external-join commit
|
|
104
|
+
* Read the DID an external-join commit CLAIMS control of. An external join is a
|
|
101
105
|
* PublicMessage from a joining non-member (senderType new_member_commit) carrying a
|
|
102
106
|
* commit; the committer holds no pre-commit leaf, so its DID rides the commit's own
|
|
103
107
|
* UpdatePath leaf credential. Returns undefined for anything else (keeps the
|
|
104
108
|
* pre-envelope path). Returns `{ did: undefined }` when the UpdatePath is absent or
|
|
105
109
|
* the leaf credential does not resolve to a basic-credential DID — cannot be a valid
|
|
106
110
|
* resync, so the caller rejects it. Narrows structurally.
|
|
111
|
+
*
|
|
112
|
+
* CLAIMS, not proves: this reads the credential and checks no signature, and the
|
|
113
|
+
* credential is a plain field any publisher can write. The DID it yields is the
|
|
114
|
+
* frame's word until {@link GroupHandle.readCommitHeader} has authenticated it, and
|
|
115
|
+
* a caller that reports it unauthenticated hands a forger the choice of committer.
|
|
107
116
|
*/ function readExternalCommit(decoded) {
|
|
108
117
|
if (decoded == null || typeof decoded !== 'object') return undefined;
|
|
109
118
|
const frame = decoded;
|
|
@@ -135,7 +144,7 @@ export function mutexFor(handle) {
|
|
|
135
144
|
}
|
|
136
145
|
}
|
|
137
146
|
/**
|
|
138
|
-
* Project a held ledger into the roster. foldRoster drops every non-`
|
|
147
|
+
* Project a held ledger into the roster. foldRoster drops every non-`kumiai.role`
|
|
139
148
|
* entry by type, so the mixed-type log is fed in whole. Replayed in order, repeats
|
|
140
149
|
* and all: a claim re-enacted at a later position must undo what came between.
|
|
141
150
|
*/ function foldLedgerRoster(ledger, anchor, groupID) {
|
|
@@ -350,6 +359,9 @@ export function mutexFor(handle) {
|
|
|
350
359
|
verified
|
|
351
360
|
});
|
|
352
361
|
}
|
|
362
|
+
// What this bootstrap ADDS, in log order, minus the reserved `kumiai.*` types the fold
|
|
363
|
+
// consumes itself — the same rule the commit path surfaces by.
|
|
364
|
+
const surfaced = log.filter(({ entryID, verified })=>!this.#entryBodies.has(entryID) && !verified.entry.type.startsWith(GROUP_TYPE_PREFIX)).map(({ verified })=>verified);
|
|
353
365
|
this.#ledger = log;
|
|
354
366
|
this.#entryBodies = new Map(log.map(({ entryID, token, verified })=>[
|
|
355
367
|
entryID,
|
|
@@ -359,6 +371,15 @@ export function mutexFor(handle) {
|
|
|
359
371
|
}
|
|
360
372
|
]));
|
|
361
373
|
this.#roster = foldLedgerRoster(log, this.#anchor, this.groupID);
|
|
374
|
+
// SURFACED HERE TOO, not only on the commit path. A heal is how a peer that missed commits
|
|
375
|
+
// catches up — it rejoins, gathers the whole ledger, and lands here — so a bootstrap that
|
|
376
|
+
// said nothing left a host consuming `onLedgerEntries` as an event stream permanently
|
|
377
|
+
// unaware of everything enacted while it was away. The state was right and the host was
|
|
378
|
+
// never told, which is the worst of both.
|
|
379
|
+
//
|
|
380
|
+
// Deduped against what this handle already held, so a peer bootstrapping over a partial
|
|
381
|
+
// ledger is not re-notified of entries it has already seen.
|
|
382
|
+
if (surfaced.length > 0) this.#onLedgerEntries?.(surfaced);
|
|
362
383
|
});
|
|
363
384
|
}
|
|
364
385
|
get memberCount() {
|
|
@@ -397,12 +418,51 @@ export function mutexFor(handle) {
|
|
|
397
418
|
* order. Leaves whose credential identity fails to parse are skipped (like
|
|
398
419
|
* findMemberLeafIndex). Reflects current #state — call before and after
|
|
399
420
|
* processMessage to diff a commit's membership change.
|
|
421
|
+
*
|
|
422
|
+
* The diff sees MEMBERSHIP, and only membership: an Add, a Remove, or both in
|
|
423
|
+
* one commit (compare as a set — a count misses that last case). It does NOT
|
|
424
|
+
* see an external-commit REJOIN by a member the group still holds. That member
|
|
425
|
+
* keeps its id, so the id set is unchanged; and its leaf index is unchanged
|
|
426
|
+
* too, because a resync blanks the member's old leaf and the new leaf then
|
|
427
|
+
* takes the leftmost blank — the one just blanked (RFC 9420 §12.4.3.2). No
|
|
428
|
+
* field of this result moves, and no before/after diff of it can be made to.
|
|
429
|
+
* A caller that must detect a rejoin reads the COMMIT instead — an external
|
|
430
|
+
* commit is structurally one: a public message from a non-member carrying a
|
|
431
|
+
* commit, recognizable from its own bytes before it is applied, and carrying
|
|
432
|
+
* its committer's id in its own UpdatePath leaf. That is the read
|
|
433
|
+
* {@link readCommitHeader} already makes internally to resolve such a
|
|
434
|
+
* committer, and it does not surface the fact today.
|
|
400
435
|
*/ listMembers() {
|
|
401
436
|
return [
|
|
402
437
|
...this.#iterateMembers()
|
|
403
438
|
];
|
|
404
439
|
}
|
|
405
440
|
/**
|
|
441
|
+
* The MLS exporter (RFC 9420 §8.5): a secret derived from THIS EPOCH's exporter secret,
|
|
442
|
+
* a label and a context. Every member at the epoch derives the same bytes; a member at
|
|
443
|
+
* any other epoch derives different ones, and cannot reach this epoch's from what it holds.
|
|
444
|
+
*
|
|
445
|
+
* That per-epoch property is the point, and it is the only thing that cuts a removed member
|
|
446
|
+
* off from anything keyed on it. A removed member keeps every exporter secret it ever held
|
|
447
|
+
* and every value it ever derived, and epoch numbers are a counter it can enumerate — so a
|
|
448
|
+
* consumer deriving a rotating name (an app-lane topic, say) must feed it from HERE and never
|
|
449
|
+
* from a lifelong group secret, which would rotate onto a name the removed member walks
|
|
450
|
+
* straight back onto.
|
|
451
|
+
*
|
|
452
|
+
* Non-mutating and consumes no ratchet key: the exporter secret is epoch-level. A handle a
|
|
453
|
+
* commit has superseded exports its own pre-commit epoch's secret, which is a feature — a
|
|
454
|
+
* reader opening a retained frame needs the secret of the epoch that frame was sealed at.
|
|
455
|
+
*
|
|
456
|
+
* DELIBERATELY NOT MUTEX-WRAPPED, unlike its neighbours, and two things depend on that. A
|
|
457
|
+
* consumer resolving a commit's ledger entries is called from INSIDE `processMessage`, which
|
|
458
|
+
* holds the mutex — so taking it here would deadlock every commit-apply. And `#state` is
|
|
459
|
+
* replaced only after resolution returns, so a read from in there sees the PRE-commit epoch's
|
|
460
|
+
* exporter secret, which is the epoch the blob being opened was sealed under. Both are silent
|
|
461
|
+
* consequences of this method's plainness; wrapping it "for consistency" breaks both.
|
|
462
|
+
*/ async exportSecret(label, context, length = 32) {
|
|
463
|
+
return await mlsExporter(this.#state.keySchedule.exporterSecret, label, context, length, this.#context.cipherSuite);
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
406
466
|
* Encrypt an application message for the group at this handle's current epoch,
|
|
407
467
|
* returning framed wire bytes. A handle a commit has already superseded (see
|
|
408
468
|
* {@link commitInvite}, {@link removeMember}, {@link commitLedgerEntries}) must not
|
|
@@ -421,6 +481,57 @@ export function mutexFor(handle) {
|
|
|
421
481
|
});
|
|
422
482
|
}
|
|
423
483
|
/**
|
|
484
|
+
* Open an application message sealed for the group and recover WHO SENT IT — the
|
|
485
|
+
* counterpart to {@link encrypt}, and the read half of the group's application lane.
|
|
486
|
+
*
|
|
487
|
+
* Throws for bytes this handle cannot open, which for an application message means
|
|
488
|
+
* ANY epoch but its own: MLS ratchets forward, so a frame sealed below this handle's
|
|
489
|
+
* epoch is gone and one sealed above it has not arrived yet. That is ordinary control
|
|
490
|
+
* flow for a caller walking a retained log full of frames from epochs it does not hold
|
|
491
|
+
* — it is how a frame says "not mine" — and such a caller must not read the throw as
|
|
492
|
+
* corruption. Use {@link readMessageEpoch} to tell those two cases apart before trying.
|
|
493
|
+
*
|
|
494
|
+
* WHY THE SENDER IS AUTHENTICATED and not merely claimed: the leaf index comes from the
|
|
495
|
+
* message's sender-data, encrypted under this epoch's sender-data secret, and the
|
|
496
|
+
* message body then opens only under the ratchet key derived at THAT leaf. A frame
|
|
497
|
+
* naming a leaf it was not sealed at does not open, so a sender that survives to be
|
|
498
|
+
* returned is one the AEAD has vouched for. The leaf is resolved to a DID against this
|
|
499
|
+
* handle's own ratchet tree, never from anything the frame carries.
|
|
500
|
+
*
|
|
501
|
+
* `senderDID` is absent only when the authenticated leaf holds no parsable credential —
|
|
502
|
+
* absent means "I cannot name the author", never "there is no author".
|
|
503
|
+
*
|
|
504
|
+
* ts-mls's own `processMessage` returns an application message's plaintext WITHOUT any
|
|
505
|
+
* sender, which is why this exists rather than delegating.
|
|
506
|
+
*/ async decrypt(message) {
|
|
507
|
+
const decoded = decode(mlsMessageDecoder, message);
|
|
508
|
+
if (decoded == null) throw new Error('decrypt: failed to decode MLSMessage');
|
|
509
|
+
return mutexFor(this).run(async ()=>{
|
|
510
|
+
const pm = readPrivateFrame(decoded, contentTypes.application);
|
|
511
|
+
if (pm == null) throw new Error('decrypt: not a PrivateMessage application frame');
|
|
512
|
+
// Read the sender BEFORE opening: the sender-data secret is epoch-level and this
|
|
513
|
+
// consumes no ratchet key, so a frame that then fails to open has cost nothing.
|
|
514
|
+
const leafIndex = await readSenderLeafIndex(this.#context, this.#state.keySchedule.senderDataSecret, pm);
|
|
515
|
+
const result = await mlsProcessMessage({
|
|
516
|
+
context: this.#context,
|
|
517
|
+
state: this.#state,
|
|
518
|
+
message: decoded
|
|
519
|
+
});
|
|
520
|
+
this.#state = result.newState;
|
|
521
|
+
zeroAll(result.consumed);
|
|
522
|
+
if (result.kind !== 'applicationMessage') {
|
|
523
|
+
throw new Error('decrypt: frame was not an application message');
|
|
524
|
+
}
|
|
525
|
+
const senderDID = leafIndex == null ? undefined : this.#didOfLeaf(leafIndex);
|
|
526
|
+
return {
|
|
527
|
+
payload: result.message,
|
|
528
|
+
...senderDID != null && {
|
|
529
|
+
senderDID
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
424
535
|
* The async pre-pass feeding the synchronous ts-mls commit callback, run before
|
|
425
536
|
* mlsProcessMessage. For anything that is not a PrivateMessage commit it just
|
|
426
537
|
* resolves the caller policy, wraps it for rejected-proposal capture, and applies
|
|
@@ -562,6 +673,51 @@ export function mutexFor(handle) {
|
|
|
562
673
|
applyOnAccept
|
|
563
674
|
};
|
|
564
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
* Does this external commit carry a signature that verifies as its own UpdatePath leaf's?
|
|
678
|
+
*
|
|
679
|
+
* An external commit is self-signed: the key that signed it is the `signaturePublicKey` of the
|
|
680
|
+
* same UpdatePath leaf whose credential names the committer. So a verified signature binds the
|
|
681
|
+
* two — whoever authored these bytes held the key of the leaf claiming that DID — and an
|
|
682
|
+
* unverified one means the credential is a field somebody wrote, nothing more.
|
|
683
|
+
*
|
|
684
|
+
* WHAT IT REQUIRES, and why the answer is only ever available at this handle's own epoch.
|
|
685
|
+
* MLS binds the full GroupContext into the signed FramedContentTBS for a new_member_commit
|
|
686
|
+
* sender, so verifying needs the group context the signer signed against: group id, epoch, tree
|
|
687
|
+
* hash, confirmed transcript hash, extensions. This handle holds exactly one — its current
|
|
688
|
+
* epoch's. It holds none for an epoch AHEAD of it, which no peer can, and that is not a gap
|
|
689
|
+
* this check can close: a peer that has fallen behind holds nothing to check the group's future
|
|
690
|
+
* with. So a commit framed anywhere but here answers false, and the caller reports no committer
|
|
691
|
+
* rather than an unauthenticated one.
|
|
692
|
+
*
|
|
693
|
+
* WHAT IT DOES NOT ESTABLISH. Possession of a key is not permission to use it: a verified
|
|
694
|
+
* signature says "the holder of that leaf key authored these bytes", never "this member may
|
|
695
|
+
* rejoin". And it is a property of the bytes, not of their delivery — a GENUINE external commit
|
|
696
|
+
* captured and re-published verifies exactly as it did the first time.
|
|
697
|
+
*
|
|
698
|
+
* Implemented by asking the MLS library to process the message with a callback that refuses it,
|
|
699
|
+
* which runs the real verification and stops before anything is applied. Deliberately not a
|
|
700
|
+
* reimplementation: a check that verified less than the apply path does would pass frames the
|
|
701
|
+
* apply path rejects, and the two must not drift. Non-mutating — the refusal returns this same
|
|
702
|
+
* state, and the result is discarded either way. Any throw is a "no": the library raises on a
|
|
703
|
+
* bad signature, on an epoch that is not this one, and on a malformed frame, and none of those
|
|
704
|
+
* is an authenticated committer.
|
|
705
|
+
*/ async #externalCommitAuthenticates(decoded) {
|
|
706
|
+
try {
|
|
707
|
+
const result = await mlsProcessMessage({
|
|
708
|
+
context: this.#context,
|
|
709
|
+
state: this.#state,
|
|
710
|
+
message: decoded,
|
|
711
|
+
callback: ()=>'reject'
|
|
712
|
+
});
|
|
713
|
+
// Zeroed rather than assumed empty: the refusal path hands back nothing to retire today,
|
|
714
|
+
// and this must not become a way to leak retired key material if that ever changes.
|
|
715
|
+
zeroAll(result.consumed);
|
|
716
|
+
return result.kind === 'newState' && result.actionTaken === 'reject';
|
|
717
|
+
} catch {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
565
721
|
/** The DID at a ratchet-tree leaf index, or undefined if that leaf is empty/unparsable. */ #didOfLeaf(leafIndex) {
|
|
566
722
|
for (const member of this.#iterateMembers()){
|
|
567
723
|
if (member.leafIndex === leafIndex) return member.id;
|
|
@@ -569,15 +725,35 @@ export function mutexFor(handle) {
|
|
|
569
725
|
return undefined;
|
|
570
726
|
}
|
|
571
727
|
/**
|
|
572
|
-
* Read a Commit
|
|
573
|
-
* state. `null` for bytes that are not a Commit.
|
|
728
|
+
* Read what a Commit says about itself against this handle, WITHOUT advancing state.
|
|
574
729
|
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
* handle
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
730
|
+
* **`null` means "these bytes are not a Commit" and nothing else.** It does not mean "a
|
|
731
|
+
* Commit I could not read": callers file `null` as poison and step over it, so answering it
|
|
732
|
+
* for a Commit this handle merely cannot authenticate would make a reader treat every commit
|
|
733
|
+
* framed away from its own epoch as garbage — including the ones that say it fell behind.
|
|
734
|
+
*
|
|
735
|
+
* The two facts the header carries are NOT equally available, and the return type says so:
|
|
736
|
+
* - `epoch` is in the message's CLEARTEXT ({@link readMessageEpoch}). Keyless, so it is
|
|
737
|
+
* readable for a Commit framed at any epoch — and unauthenticated, so it is the
|
|
738
|
+
* publisher's word and may only be used to decide what to try.
|
|
739
|
+
* - `committerDID` needs the epoch's sender-data secret. A member commit (PrivateMessage)
|
|
740
|
+
* has its committer encrypted under it: decrypt to the sender leaf index and resolve that
|
|
741
|
+
* against this handle's ratchet tree — the same leaf->DID the commit policy sees as
|
|
742
|
+
* `didOfLeaf(senderLeafIndex)`. Both the secret and the tree are THIS epoch's, so the
|
|
743
|
+
* committer resolves only for a Commit framed where this handle stands, and is ABSENT
|
|
744
|
+
* otherwise. Absent is "I cannot vouch for the author", never "there is no author": a
|
|
745
|
+
* caller must not substitute an unauthenticated one.
|
|
746
|
+
*
|
|
747
|
+
* An external commit needs no epoch secret and no tree lookup — it is a public message and its
|
|
748
|
+
* committer's DID rides its own UpdatePath leaf (see {@link readExternalCommit}), which is also
|
|
749
|
+
* what makes it recognizable as external. It is NOT exempt from authentication. The credential
|
|
750
|
+
* carrying that DID is a plain field, so it is returned only once the commit's own self-signed
|
|
751
|
+
* signature verifies, and it is ABSENT otherwise — the same rule the member path follows, for
|
|
752
|
+
* the same reason. Verifiable only at this handle's own epoch, since MLS binds the GroupContext
|
|
753
|
+
* into what an external commit signs; a commit framed elsewhere reports no committer.
|
|
754
|
+
*
|
|
755
|
+
* `external: true` is reported either way: it is read from the wireformat and sender type, both
|
|
756
|
+
* cleartext, so it is as available as the epoch and says nothing about who authored the frame.
|
|
581
757
|
*
|
|
582
758
|
* Runs on the handle mutex so the epoch secret, tree, and epoch are one snapshot against a
|
|
583
759
|
* concurrent processMessage. Non-mutating: sender-data decrypt is epoch-level and consumes
|
|
@@ -599,20 +775,49 @@ export function mutexFor(handle) {
|
|
|
599
775
|
if (epoch == null) return null;
|
|
600
776
|
// External-join commit: the committer holds no pre-commit leaf, so its DID rides the
|
|
601
777
|
// commit's own UpdatePath leaf. No tree lookup, no sender-data decrypt.
|
|
778
|
+
//
|
|
779
|
+
// `external: true` is reported, not just consumed to find the committer: a resync rejoin
|
|
780
|
+
// is invisible to every before/after diff a caller could run — it changes no member DID
|
|
781
|
+
// (the roster already held it) and no occupied leaf index (the new leaf lands on the
|
|
782
|
+
// leftmost blank, which is the one the resync just blanked). A caller that must know the
|
|
783
|
+
// group's membership shifted has no other way to see it, so the fact is surfaced here
|
|
784
|
+
// rather than discarded. Absent means a member commit.
|
|
602
785
|
const external = readExternalCommit(decoded);
|
|
603
786
|
if (external != null) {
|
|
604
|
-
|
|
787
|
+
// It IS a commit, so it gets a header even when the leaf credential will not parse to a
|
|
788
|
+
// DID and even when the signature will not verify — the epoch is readable and the
|
|
789
|
+
// caller's epoch rows are entitled to it. Only the committer goes missing.
|
|
790
|
+
//
|
|
791
|
+
// The signature is checkable only where this handle holds the GroupContext the commit's
|
|
792
|
+
// signature is bound to, which is the epoch this handle stands at. A commit framed
|
|
793
|
+
// anywhere else comes back with no committer — indistinguishable, from here, from a
|
|
794
|
+
// forgery, and treated as one.
|
|
795
|
+
const authentic = external.did != null && await this.#externalCommitAuthenticates(decoded);
|
|
796
|
+
return {
|
|
605
797
|
epoch,
|
|
606
|
-
|
|
798
|
+
external: true,
|
|
799
|
+
...authentic && {
|
|
800
|
+
committerDID: external.did
|
|
801
|
+
}
|
|
607
802
|
};
|
|
608
803
|
}
|
|
609
|
-
const pm =
|
|
610
|
-
|
|
611
|
-
|
|
804
|
+
const pm = readPrivateFrame(decoded, contentTypes.commit);
|
|
805
|
+
// The ONLY "not a Commit" verdict on this path, and the only thing `null` is for: the
|
|
806
|
+
// frame is not a PrivateMessage of contentType commit. Both of those fields are cleartext,
|
|
807
|
+
// so this verdict needs no key and is the same at every epoch.
|
|
808
|
+
if (pm == null) return null;
|
|
809
|
+
// From here the bytes ARE a commit, and every exit carries its epoch. The committer is
|
|
810
|
+
// what may be missing: sender-data is sealed under the epoch secret this handle holds
|
|
811
|
+
// right now, so a commit framed at any other epoch decrypts to nothing, and a leaf this
|
|
812
|
+
// tree does not hold resolves to nobody. Neither is a reason to call the frame garbage.
|
|
612
813
|
const leafIndex = await readSenderLeafIndex(this.#context, this.#state.keySchedule.senderDataSecret, pm);
|
|
613
|
-
if (leafIndex == null) return
|
|
814
|
+
if (leafIndex == null) return {
|
|
815
|
+
epoch
|
|
816
|
+
};
|
|
614
817
|
const committerDID = this.#didOfLeaf(leafIndex);
|
|
615
|
-
return committerDID == null ?
|
|
818
|
+
return committerDID == null ? {
|
|
819
|
+
epoch
|
|
820
|
+
} : {
|
|
616
821
|
epoch,
|
|
617
822
|
committerDID
|
|
618
823
|
};
|
package/lib/group-welcome.d.ts
CHANGED
|
@@ -17,9 +17,6 @@ export type ProcessWelcomeParams = {
|
|
|
17
17
|
ratchetTree?: unknown;
|
|
18
18
|
options?: GroupOptions;
|
|
19
19
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Process a Welcome message to join a group.
|
|
22
|
-
*/
|
|
23
20
|
export declare function processWelcome(params: ProcessWelcomeParams): Promise<ProcessWelcomeResult>;
|
|
24
21
|
export type ProcessWelcomeOnceParams = ProcessWelcomeParams & {
|
|
25
22
|
/** The group ids this member already holds a handle for. */
|
package/lib/group-welcome.js
CHANGED
|
@@ -7,9 +7,7 @@ import { GroupHandle } from './group-handle.js';
|
|
|
7
7
|
import { assertHeadMatches, computeHead, readLedgerHead } from './head.js';
|
|
8
8
|
import { ledgerEntryDigest, verifyLedgerEntry } from './ledger.js';
|
|
9
9
|
import { ROLE_ENTRY_TYPE } from './roster.js';
|
|
10
|
-
|
|
11
|
-
* Process a Welcome message to join a group.
|
|
12
|
-
*/ export async function processWelcome(params) {
|
|
10
|
+
export async function processWelcome(params) {
|
|
13
11
|
const { identity, invite, welcome, keyPackageBundle, ratchetTree, options } = params;
|
|
14
12
|
const cache = options?.cache ?? createInMemoryDIDCache();
|
|
15
13
|
const context = await resolveMlsContext(options);
|
package/lib/policy.d.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import type { GroupContextExtension, IncomingMessageAction, ProposalWithSender } from 'ts-mls';
|
|
2
2
|
import type { RosterState } from './roster.js';
|
|
3
3
|
/**
|
|
4
|
-
* Everything the receiving-side gate needs, resolved by the caller. Pure: no
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
9
|
-
* from an external commit's UpdatePath leaf (precomputed by the caller); undefined
|
|
10
|
-
* for a non-external commit.
|
|
4
|
+
* Everything the receiving-side gate needs, resolved by the caller. Pure: no group handle, no
|
|
5
|
+
* I/O. `didOfLeaf` maps a pre-commit leaf index to its member DID (undefined if unresolvable).
|
|
6
|
+
* `currentExtensions` is the pre-commit extension list the group-context-extensions rule pins
|
|
7
|
+
* against. `externalCommitDID` is the DID resolved from an external commit's UpdatePath leaf
|
|
8
|
+
* (precomputed by the caller); undefined for a non-external commit.
|
|
11
9
|
*/
|
|
12
10
|
export type CommitPolicyContext = {
|
|
13
|
-
/** Roster before
|
|
14
|
-
*
|
|
11
|
+
/** Roster before the commit. Judges every sender's authority — a promotion riding this same
|
|
12
|
+
* commit doesn't grant its subject commit authority. */
|
|
15
13
|
baseRoster: RosterState;
|
|
16
|
-
/** Roster after foldEnvelope applies this commit's
|
|
17
|
-
*
|
|
14
|
+
/** Roster after foldEnvelope applies this commit's kumiai.role entries. Judges the removed
|
|
15
|
+
* target: a Remove of a leaf still `admin` here carried no demotion and is rejected. */
|
|
18
16
|
candidateRoster: RosterState;
|
|
19
17
|
didOfLeaf: (leafIndex: number) => string | undefined;
|
|
20
|
-
/** The pre-commit GroupContext extension list. A group_context_extensions commit
|
|
21
|
-
*
|
|
18
|
+
/** The pre-commit GroupContext extension list. A group_context_extensions commit may change
|
|
19
|
+
* nothing in it but the ledger_head entry. */
|
|
22
20
|
currentExtensions: Array<GroupContextExtension>;
|
|
23
|
-
/** The head extension bytes this commit must install: the current head extended by
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* anything is rejected too. */
|
|
21
|
+
/** The head extension bytes this commit must install: the current head extended by the
|
|
22
|
+
* commit's envelope entry ids, in order. Equals the current head when the commit enacts
|
|
23
|
+
* nothing, so a commit that moves the head without enacting anything is rejected too. */
|
|
27
24
|
expectedHeadExtensionData: Uint8Array;
|
|
28
25
|
/** Whether the commit's envelope names any entries. */
|
|
29
26
|
commitEnactsEntries: boolean;
|
|
@@ -39,28 +36,24 @@ type IncomingMessage = {
|
|
|
39
36
|
proposal: ProposalWithSender;
|
|
40
37
|
};
|
|
41
38
|
/**
|
|
42
|
-
* Pure receiving-side commit policy
|
|
43
|
-
*
|
|
39
|
+
* Pure receiving-side commit policy: given the resolved context, decides whether an incoming
|
|
40
|
+
* commit or standalone proposal is admissible. Never throws.
|
|
44
41
|
*
|
|
45
|
-
* Per proposal the effective sender is
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* an `external_init`, the whole commit is judged by the external-init rule rather
|
|
52
|
-
* than the per-proposal loop.
|
|
42
|
+
* Per proposal, the effective sender is its own `senderLeafIndex` if present, else the
|
|
43
|
+
* committer's — a commit may carry by-reference proposals from other members, so checking only
|
|
44
|
+
* the committer would let an admin launder a member's Remove. Every proposal must pass its row
|
|
45
|
+
* or the whole commit rejects; no proposals is a key rotation any member may make. An
|
|
46
|
+
* `external_init` anywhere routes the whole commit to the external-init rule instead of the
|
|
47
|
+
* per-proposal loop.
|
|
53
48
|
*
|
|
54
|
-
* One rule
|
|
55
|
-
*
|
|
56
|
-
* head, and the head would stop covering the ledger.
|
|
49
|
+
* One rule isn't a proposal's own: a commit enacting ledger entries must carry a
|
|
50
|
+
* group-context-extensions proposal, or entries would be enacted without moving the head.
|
|
57
51
|
*/
|
|
58
52
|
export declare function defaultCommitPolicy(incoming: IncomingMessage, context: CommitPolicyContext): IncomingMessageAction;
|
|
59
53
|
/**
|
|
60
|
-
* Thrown by the caller's resolver
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* thrown by {@link defaultCommitPolicy}, which is pure and total.
|
|
54
|
+
* Thrown by the caller's resolver when an envelope names entry ids the ledger can't resolve.
|
|
55
|
+
* Belongs to the commit-policy resolution boundary, but {@link defaultCommitPolicy} itself is
|
|
56
|
+
* pure and total, and never throws it.
|
|
64
57
|
*/
|
|
65
58
|
export declare class MissingLedgerEntriesError extends Error {
|
|
66
59
|
#private;
|