@kumiai/mls 0.2.0 → 0.3.0
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-commit.d.ts +100 -0
- package/lib/group-commit.js +252 -0
- package/lib/group-context.d.ts +11 -0
- package/lib/group-context.js +33 -0
- package/lib/group-create.d.ts +19 -0
- package/lib/group-create.js +85 -0
- package/lib/group-credential.d.ts +6 -0
- package/lib/group-credential.js +39 -0
- package/lib/group-handle.d.ts +177 -0
- package/lib/group-handle.js +613 -0
- package/lib/group-info.d.ts +57 -0
- package/lib/group-info.js +85 -0
- package/lib/group-membership.d.ts +25 -0
- package/lib/group-membership.js +36 -0
- package/lib/group-welcome.d.ts +67 -0
- package/lib/group-welcome.js +178 -0
- package/lib/group.d.ts +7 -339
- package/lib/group.js +7 -1194
- package/lib/head.d.ts +35 -38
- package/lib/head.js +43 -48
- package/lib/index.d.ts +3 -2
- package/lib/index.js +3 -2
- package/lib/recovery.d.ts +227 -0
- package/lib/recovery.js +456 -0
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { type DIDCache, type DIDResolver } from '@kokuin/token';
|
|
2
|
+
import { type ClientState, type IncomingMessageCallback, type MlsContext, type ProposalWithSender } from 'ts-mls';
|
|
3
|
+
import { type GroupAnchor } from './anchor.js';
|
|
4
|
+
import { type GroupMember, type MemberCredential } from './credential.js';
|
|
5
|
+
import { type VerifiedLedgerEntry } from './ledger.js';
|
|
6
|
+
import { type Mutex } from './mutex.js';
|
|
7
|
+
import { type CommitPolicyContext } from './policy.js';
|
|
8
|
+
import { type RosterState } from './roster.js';
|
|
9
|
+
export declare function mutexFor(handle: GroupHandle): Mutex;
|
|
10
|
+
/** Thrown by GroupHandle.processMessage when the commit policy rejects an incoming
|
|
11
|
+
* commit. The handle is left at its pre-commit epoch. */
|
|
12
|
+
export declare class CommitRejectedError extends Error {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(proposals: Array<ProposalWithSender>, senderLeafIndex?: number);
|
|
15
|
+
get proposals(): Array<ProposalWithSender>;
|
|
16
|
+
get senderLeafIndex(): number | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A control-ledger entry as a handle holds it: the signed token (canonical
|
|
20
|
+
* persistent/wire form, the only thing forwardable to another party) paired with
|
|
21
|
+
* its verified form. The verified form is a one-way derivation, so keeping only it
|
|
22
|
+
* would leave a handle unable to forward its ledger.
|
|
23
|
+
*/
|
|
24
|
+
export type HeldLedgerEntry = {
|
|
25
|
+
token: string;
|
|
26
|
+
verified: VerifiedLedgerEntry;
|
|
27
|
+
};
|
|
28
|
+
/** A held entry paired with its content id — one position in the ledger log. */
|
|
29
|
+
export type LedgerLogEntry = HeldLedgerEntry & {
|
|
30
|
+
entryID: string;
|
|
31
|
+
};
|
|
32
|
+
export type GroupHandleParams = {
|
|
33
|
+
state: ClientState;
|
|
34
|
+
credential: MemberCredential;
|
|
35
|
+
context: MlsContext;
|
|
36
|
+
/** The control-ledger log this handle starts from, in enactment order. A handle
|
|
37
|
+
* derived from another (commitInvite/removeMember) inherits the parent's, so the
|
|
38
|
+
* roster it folds does not revert to the anchor alone. */
|
|
39
|
+
ledger?: ReadonlyArray<LedgerLogEntry>;
|
|
40
|
+
cache: DIDCache;
|
|
41
|
+
resolver?: DIDResolver;
|
|
42
|
+
/** Default commit policy applied by processMessage. */
|
|
43
|
+
commitPolicy?: IncomingMessageCallback;
|
|
44
|
+
/** Fetch control-ledger entry bodies the local ledger lacks (commit pre-pass). */
|
|
45
|
+
resolveLedgerEntries?: (ids: Array<string>) => Promise<Array<string>>;
|
|
46
|
+
/** Surface an accepted commit's notarized non-`group.role` entries to the consumer. */
|
|
47
|
+
onLedgerEntries?: (entries: Array<VerifiedLedgerEntry>) => void;
|
|
48
|
+
};
|
|
49
|
+
/** Mutable wrapper around MLS group state + Enkaku credential. */
|
|
50
|
+
export declare class GroupHandle {
|
|
51
|
+
#private;
|
|
52
|
+
constructor(params: GroupHandleParams);
|
|
53
|
+
get groupID(): string;
|
|
54
|
+
get epoch(): bigint;
|
|
55
|
+
get treeHash(): Uint8Array;
|
|
56
|
+
get credential(): MemberCredential;
|
|
57
|
+
get state(): ClientState;
|
|
58
|
+
get context(): MlsContext;
|
|
59
|
+
get cache(): DIDCache;
|
|
60
|
+
get resolver(): DIDResolver | undefined;
|
|
61
|
+
/** The commit policy enforced by processMessage, if any. Carried onto
|
|
62
|
+
* handles derived from this one (commitInvite/removeMember). */
|
|
63
|
+
get commitPolicy(): IncomingMessageCallback | undefined;
|
|
64
|
+
/** The ledger-entry resolver, carried onto handles derived from this one. */
|
|
65
|
+
get resolveLedgerEntries(): ((ids: Array<string>) => Promise<Array<string>>) | undefined;
|
|
66
|
+
/** The accepted-commit entry sink, carried onto handles derived from this one. */
|
|
67
|
+
get onLedgerEntries(): ((entries: Array<VerifiedLedgerEntry>) => void) | undefined;
|
|
68
|
+
/** The genesis anchor seeded into this handle at construction. */
|
|
69
|
+
get anchor(): GroupAnchor;
|
|
70
|
+
/** The control-ledger log this handle holds, in enactment order, repeats and
|
|
71
|
+
* all. Carried onto handles derived from this one (commitInvite/removeMember). */
|
|
72
|
+
get ledger(): ReadonlyArray<LedgerLogEntry>;
|
|
73
|
+
/** The ordered signed tokens this handle holds, repeats included — the ledger's
|
|
74
|
+
* canonical persistent/wire form, and the list the authenticated head folds over.
|
|
75
|
+
* Feeds createInvite, restoreGroup, and host persistence. The verified entries are
|
|
76
|
+
* a derived cache with no export form: the only way in is applyLedgerEntries,
|
|
77
|
+
* which re-verifies. */
|
|
78
|
+
get ledgerTokens(): Array<string>;
|
|
79
|
+
/** The control roster folded from the anchor and every applied ledger entry. */
|
|
80
|
+
get roster(): RosterState;
|
|
81
|
+
/**
|
|
82
|
+
* Verify signed ledger tokens, append the valid ones in the order given, and
|
|
83
|
+
* refold the roster. Tokens that fail verification or whose groupID mismatches are
|
|
84
|
+
* dropped (defensive — the strict admin-issuer enforcement is the commit pre-pass).
|
|
85
|
+
* Every token is re-verified on the way in: no entry enters a ledger unverified,
|
|
86
|
+
* whatever the import path.
|
|
87
|
+
*
|
|
88
|
+
* A token the log already holds is appended again, not skipped: the log records
|
|
89
|
+
* what each commit enacted, not a set of claims, and a repeat is the only way to
|
|
90
|
+
* express a demotion back to a previously-held role. Nothing replays a commit into
|
|
91
|
+
* it (MLS applies each once, restoreGroup replays a token list once, processWelcome
|
|
92
|
+
* folds an invite once). Serialized on the handle's mutex.
|
|
93
|
+
*/
|
|
94
|
+
applyLedgerEntries(tokens: Array<string>): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the ledger this handle holds is the whole ledger its GroupContext
|
|
97
|
+
* attests to: the head folded from the ids it holds, in order, against the
|
|
98
|
+
* authenticated `ledger_head`.
|
|
99
|
+
*
|
|
100
|
+
* Purely local — reads this handle's ledger and GroupContext, consults no peer.
|
|
101
|
+
* False means incomplete (e.g. an external-commit rejoin arrives with an *empty*
|
|
102
|
+
* ledger against a live, non-genesis head), and {@link bootstrapLedger} must run
|
|
103
|
+
* before the handle can be trusted to fold a roster or judge a commit.
|
|
104
|
+
*
|
|
105
|
+
* A group with no entries reads true, non-vacuously: the empty fold is the genesis
|
|
106
|
+
* head (a real 32-byte digest bound to this group), which matches only a head that
|
|
107
|
+
* has never moved — exactly a genuinely empty ledger.
|
|
108
|
+
*/
|
|
109
|
+
isLedgerComplete(): Promise<boolean>;
|
|
110
|
+
/**
|
|
111
|
+
* The whole ordered ledger this handle holds, as signed tokens — what a responder
|
|
112
|
+
* serves to a bootstrapping peer. Order is load-bearing: the head is a chain
|
|
113
|
+
* digest, so a permuted list folds to a different head and is rejected.
|
|
114
|
+
*/
|
|
115
|
+
getLedger(): Promise<Array<string>>;
|
|
116
|
+
/**
|
|
117
|
+
* Install a gathered ledger, verified against the authenticated head before a
|
|
118
|
+
* single entry is folded.
|
|
119
|
+
*
|
|
120
|
+
* The gathered list is the group's WHOLE ledger from genesis, not a delta: a list
|
|
121
|
+
* that reproduces the head this GroupContext carries *is* the entire ledger, in
|
|
122
|
+
* order, and replaces whatever this handle held.
|
|
123
|
+
*
|
|
124
|
+
* Check before fold, structurally: the head is recomputed over the incoming
|
|
125
|
+
* `tokens` while the handle's ledger, entry bodies, and roster are untouched, and
|
|
126
|
+
* the fold's results are installed in one assignment at the end. A rejected ledger
|
|
127
|
+
* writes nothing — no half-applied window, no rollback.
|
|
128
|
+
*
|
|
129
|
+
* Signatures alone do not cover this: a lying responder can hand back genuinely
|
|
130
|
+
* signed, correctly scoped tokens with one demotion omitted or two transposed —
|
|
131
|
+
* every signature verifies, yet the folded roster contains an admin the group
|
|
132
|
+
* demoted. Omission and reordering are exactly what the head chain protects and
|
|
133
|
+
* signatures do not. The bound: **a lying responder can withhold, never rewrite.**
|
|
134
|
+
*
|
|
135
|
+
* Throws {@link LedgerIncompleteError} on a head mismatch; the caller drops that
|
|
136
|
+
* responder and tries the next.
|
|
137
|
+
*/
|
|
138
|
+
bootstrapLedger(tokens: Array<string>): Promise<void>;
|
|
139
|
+
get memberCount(): number;
|
|
140
|
+
findMemberLeafIndex(id: string): number | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* The group's current members from the ratchet tree, in ascending leaf-index
|
|
143
|
+
* order. Leaves whose credential identity fails to parse are skipped (like
|
|
144
|
+
* findMemberLeafIndex). Reflects current #state — call before and after
|
|
145
|
+
* processMessage to diff a commit's membership change.
|
|
146
|
+
*/
|
|
147
|
+
listMembers(): Array<GroupMember>;
|
|
148
|
+
/**
|
|
149
|
+
* Encrypt an application message for the group at this handle's current epoch,
|
|
150
|
+
* returning framed wire bytes. A handle a commit has already superseded (see
|
|
151
|
+
* {@link commitInvite}, {@link removeMember}, {@link commitLedgerEntries}) must not
|
|
152
|
+
* be reused to send — it silently emits at the now-stale epoch. Adopt the commit's
|
|
153
|
+
* `newGroup` and encrypt on that.
|
|
154
|
+
*/
|
|
155
|
+
encrypt(plaintext: Uint8Array): Promise<Uint8Array>;
|
|
156
|
+
/**
|
|
157
|
+
* Process a received MLS message (Commit, Proposal, or application). Accepts
|
|
158
|
+
* wire-form bytes (preferred, e.g. from commitInvite/removeMember) or a pre-decoded
|
|
159
|
+
* ts-mls object (legacy). Param widens to `unknown` because `Uint8Array | unknown`
|
|
160
|
+
* collapses to `unknown`; the runtime `instanceof` selects the decode path.
|
|
161
|
+
*/
|
|
162
|
+
processMessage(message: Uint8Array | unknown, opts?: {
|
|
163
|
+
commitPolicy?: IncomingMessageCallback;
|
|
164
|
+
}): Promise<Uint8Array | null>;
|
|
165
|
+
}
|
|
166
|
+
/** Build the CommitPolicyContext both the receive gate and the send-side pending
|
|
167
|
+
* filter judge against, so the two always agree. `entryIDs` are the ledger entry
|
|
168
|
+
* ids this commit enacts (drives the expected head); `candidateRoster` is the
|
|
169
|
+
* post-fold roster receivers install. */
|
|
170
|
+
export declare function buildCommitPolicyContext(handle: GroupHandle, args: {
|
|
171
|
+
baseRoster: RosterState;
|
|
172
|
+
candidateRoster: RosterState;
|
|
173
|
+
entryIDs: Array<string>;
|
|
174
|
+
externalCommitDID?: string;
|
|
175
|
+
}): CommitPolicyContext;
|
|
176
|
+
/** Build the handle a commit hands back: the post-commit state, everything else inherited. */
|
|
177
|
+
export declare function deriveGroup(group: GroupHandle, state: ClientState): GroupHandle;
|