@kumiai/mls 0.1.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/README.md +21 -9
- package/lib/anchor.d.ts +87 -0
- package/lib/anchor.js +124 -0
- package/lib/credential.d.ts +3 -12
- package/lib/credential.js +0 -13
- package/lib/envelope-fold.d.ts +35 -0
- package/lib/envelope-fold.js +86 -0
- package/lib/envelope.d.ts +53 -0
- package/lib/envelope.js +87 -0
- package/lib/fold.d.ts +68 -0
- package/lib/fold.js +53 -0
- 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 -233
- package/lib/group.js +7 -653
- package/lib/head.d.ts +79 -0
- package/lib/head.js +150 -0
- package/lib/index.d.ts +11 -3
- package/lib/index.js +11 -3
- package/lib/ledger.d.ts +49 -0
- package/lib/ledger.js +67 -0
- package/lib/mutex.d.ts +14 -0
- package/lib/mutex.js +20 -0
- package/lib/policy.d.ts +71 -0
- package/lib/policy.js +191 -0
- package/lib/recovery.d.ts +227 -0
- package/lib/recovery.js +456 -0
- package/lib/roster.d.ts +45 -0
- package/lib/roster.js +72 -0
- package/lib/types.d.ts +31 -11
- package/package.json +2 -3
- package/lib/capability.d.ts +0 -47
- package/lib/capability.js +0 -79
package/lib/policy.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { normalizeDID } from '@kokuin/token';
|
|
2
|
+
import { defaultProposalTypes, isDefaultProposal } from 'ts-mls';
|
|
3
|
+
import { LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
|
|
4
|
+
function bytesEqual(a, b) {
|
|
5
|
+
if (a.length !== b.length) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
for(let i = 0; i < a.length; i++){
|
|
9
|
+
if (a[i] !== b[i]) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Fail-closed admin check: a leaf that resolves to no DID, or a DID absent from
|
|
17
|
+
* the roster, or one holding any role but `admin`, is not an admin. An undefined
|
|
18
|
+
* leaf (external commit with no committer leaf) is never an admin.
|
|
19
|
+
*/ function isAdmin(context, leafIndex) {
|
|
20
|
+
if (leafIndex === undefined) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const did = context.didOfLeaf(leafIndex);
|
|
24
|
+
if (did === undefined) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return context.baseRoster.roles.get(normalizeDID(did)) === 'admin';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The group-context-extensions rule: an admin may replace the extension list
|
|
31
|
+
* only to move the ledger-head extension to the head this commit's envelope
|
|
32
|
+
* accounts for. A GCE proposal replaces the *entire* list, so the proposed list
|
|
33
|
+
* must positionally equal the current list — same length, same extension types in
|
|
34
|
+
* the same positions, byte-identical data — with the single exception of the
|
|
35
|
+
* ledger_head entry, whose data must equal the expected head. This pins the anchor
|
|
36
|
+
* and every other extension: an admin cannot inject or strip an extension (e.g.
|
|
37
|
+
* external_senders, which grants a non-member the ability to inject proposals)
|
|
38
|
+
* inside an otherwise-valid head move.
|
|
39
|
+
*
|
|
40
|
+
* The head must equal the current head extended by the envelope's entry ids, in
|
|
41
|
+
* envelope order. A head moved to anything else — including moved at all by a
|
|
42
|
+
* commit that enacts nothing — would stop proving which entries the group has
|
|
43
|
+
* enacted, which is the omission hole the head exists to close.
|
|
44
|
+
*/ function evaluateGroupContextExtensions(extensions, context) {
|
|
45
|
+
const expected = context.currentExtensions.map((ext)=>ext.extensionType === LEDGER_HEAD_EXTENSION_TYPE ? {
|
|
46
|
+
extensionType: LEDGER_HEAD_EXTENSION_TYPE,
|
|
47
|
+
extensionData: context.expectedHeadExtensionData
|
|
48
|
+
} : ext);
|
|
49
|
+
if (extensions.length !== expected.length) return 'reject';
|
|
50
|
+
for(let i = 0; i < expected.length; i++){
|
|
51
|
+
const got = extensions[i];
|
|
52
|
+
const want = expected[i];
|
|
53
|
+
if (got.extensionType !== want.extensionType) return 'reject';
|
|
54
|
+
// Both sides must be raw bytes to byte-compare. ts-mls's own extensionsEqual
|
|
55
|
+
// is not re-exported, so this hand-rolled compare only handles Uint8Array
|
|
56
|
+
// extensionData; a default-typed (decoded-object) extension — e.g.
|
|
57
|
+
// external_senders or required_capabilities — fails the instanceof guard and
|
|
58
|
+
// is rejected even when it is an honest, unmodified carry-over. That is
|
|
59
|
+
// fail-closed liveness, not a security gap: no group in this repo anchors
|
|
60
|
+
// such an extension today. Revisit this compare if one is introduced.
|
|
61
|
+
if (!(got.extensionData instanceof Uint8Array) || !(want.extensionData instanceof Uint8Array) || !bytesEqual(got.extensionData, want.extensionData)) {
|
|
62
|
+
return 'reject';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return 'accept';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Apply one proposal's row using the given effective sender. Unknown or custom
|
|
69
|
+
* proposal types fail closed. `external_init` is evaluated at the commit level,
|
|
70
|
+
* never here, so it rejects if it reaches a per-proposal row (a standalone
|
|
71
|
+
* external_init).
|
|
72
|
+
*/ function evaluateProposal(proposal, effectiveSender, context) {
|
|
73
|
+
if (!isDefaultProposal(proposal)) {
|
|
74
|
+
return 'reject';
|
|
75
|
+
}
|
|
76
|
+
switch(proposal.proposalType){
|
|
77
|
+
case defaultProposalTypes.add:
|
|
78
|
+
case defaultProposalTypes.psk:
|
|
79
|
+
case defaultProposalTypes.reinit:
|
|
80
|
+
return isAdmin(context, effectiveSender) ? 'accept' : 'reject';
|
|
81
|
+
case defaultProposalTypes.remove:
|
|
82
|
+
{
|
|
83
|
+
// A removed admin must have been demoted in this same envelope: the candidate
|
|
84
|
+
// roster then shows them `member`. Still `admin` here means no demotion rode the
|
|
85
|
+
// commit. Checked before the self-removal shortcut, so an admin cannot self-remove
|
|
86
|
+
// without demoting itself.
|
|
87
|
+
const removedDID = context.didOfLeaf(proposal.remove.removed);
|
|
88
|
+
if (removedDID !== undefined && context.candidateRoster.roles.get(normalizeDID(removedDID)) === 'admin') {
|
|
89
|
+
return 'reject';
|
|
90
|
+
}
|
|
91
|
+
if (isAdmin(context, effectiveSender)) {
|
|
92
|
+
return 'accept';
|
|
93
|
+
}
|
|
94
|
+
return effectiveSender !== undefined && proposal.remove.removed === effectiveSender ? 'accept' : 'reject';
|
|
95
|
+
}
|
|
96
|
+
case defaultProposalTypes.update:
|
|
97
|
+
return 'accept';
|
|
98
|
+
case defaultProposalTypes.group_context_extensions:
|
|
99
|
+
return isAdmin(context, effectiveSender) ? evaluateGroupContextExtensions(proposal.groupContextExtensions.extensions, context) : 'reject';
|
|
100
|
+
default:
|
|
101
|
+
return 'reject';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The whole-commit external-init rule. An external commit joins by proving
|
|
106
|
+
* control of a roster DID's key and removing that DID's stale leaf, so it is
|
|
107
|
+
* accepted only when `externalCommitDID` is a roster member and the commit's
|
|
108
|
+
* proposals are exactly one `external_init` plus one `remove` of the leaf whose
|
|
109
|
+
* DID equals `externalCommitDID` — nothing else.
|
|
110
|
+
*/ function evaluateExternalCommit(proposals, context) {
|
|
111
|
+
const did = context.externalCommitDID;
|
|
112
|
+
if (did === undefined || !context.baseRoster.roles.has(normalizeDID(did))) {
|
|
113
|
+
return 'reject';
|
|
114
|
+
}
|
|
115
|
+
if (proposals.length !== 2) {
|
|
116
|
+
return 'reject';
|
|
117
|
+
}
|
|
118
|
+
let sawExternalInit = false;
|
|
119
|
+
let removeTarget;
|
|
120
|
+
for (const { proposal } of proposals){
|
|
121
|
+
if (!isDefaultProposal(proposal)) {
|
|
122
|
+
return 'reject';
|
|
123
|
+
}
|
|
124
|
+
if (proposal.proposalType === defaultProposalTypes.external_init) {
|
|
125
|
+
sawExternalInit = true;
|
|
126
|
+
} else if (proposal.proposalType === defaultProposalTypes.remove) {
|
|
127
|
+
removeTarget = proposal.remove.removed;
|
|
128
|
+
} else {
|
|
129
|
+
return 'reject';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!sawExternalInit || removeTarget === undefined) {
|
|
133
|
+
return 'reject';
|
|
134
|
+
}
|
|
135
|
+
return context.didOfLeaf(removeTarget) === did ? 'accept' : 'reject';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Pure receiving-side commit policy. Given the resolved context, decides whether
|
|
139
|
+
* an incoming commit or standalone proposal is admissible. Never throws.
|
|
140
|
+
*
|
|
141
|
+
* Per proposal the effective sender is the proposal's own `senderLeafIndex` when
|
|
142
|
+
* present, else the committer's — a commit may carry by-reference proposals
|
|
143
|
+
* authored by other members, so checking only the committer would let an admin
|
|
144
|
+
* launder a member's Remove. A commit is accepted only when every proposal
|
|
145
|
+
* passes its row; the first failing proposal rejects the whole commit. A commit
|
|
146
|
+
* with no proposals is a key rotation any member may make. When any proposal is
|
|
147
|
+
* an `external_init`, the whole commit is judged by the external-init rule rather
|
|
148
|
+
* than the per-proposal loop.
|
|
149
|
+
*
|
|
150
|
+
* One rule is not a proposal's own: a commit that enacts ledger entries must carry
|
|
151
|
+
* a group-context-extensions proposal, or it would enact entries without moving the
|
|
152
|
+
* head, and the head would stop covering the ledger.
|
|
153
|
+
*/ export function defaultCommitPolicy(incoming, context) {
|
|
154
|
+
if (incoming.kind === 'proposal') {
|
|
155
|
+
const { proposal, senderLeafIndex } = incoming.proposal;
|
|
156
|
+
return evaluateProposal(proposal, senderLeafIndex, context);
|
|
157
|
+
}
|
|
158
|
+
const { proposals, senderLeafIndex } = incoming;
|
|
159
|
+
if (context.commitEnactsEntries && !proposals.some(({ proposal })=>proposal.proposalType === defaultProposalTypes.group_context_extensions)) {
|
|
160
|
+
return 'reject';
|
|
161
|
+
}
|
|
162
|
+
if (proposals.length === 0) {
|
|
163
|
+
return 'accept';
|
|
164
|
+
}
|
|
165
|
+
if (proposals.some(({ proposal })=>proposal.proposalType === defaultProposalTypes.external_init)) {
|
|
166
|
+
return evaluateExternalCommit(proposals, context);
|
|
167
|
+
}
|
|
168
|
+
for (const { proposal, senderLeafIndex: proposalSender } of proposals){
|
|
169
|
+
const effectiveSender = proposalSender ?? senderLeafIndex;
|
|
170
|
+
if (evaluateProposal(proposal, effectiveSender, context) === 'reject') {
|
|
171
|
+
return 'reject';
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return 'accept';
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Thrown by the caller's resolver path when the entry bodies an envelope names
|
|
178
|
+
* cannot be resolved from the ledger. Carries the unresolved ids. Defined here
|
|
179
|
+
* because it belongs to the commit-policy resolution boundary, but it is never
|
|
180
|
+
* thrown by {@link defaultCommitPolicy}, which is pure and total.
|
|
181
|
+
*/ export class MissingLedgerEntriesError extends Error {
|
|
182
|
+
#ids;
|
|
183
|
+
constructor(ids){
|
|
184
|
+
super(`ledger entries could not be resolved: ${ids.join(', ')}`);
|
|
185
|
+
this.name = 'MissingLedgerEntriesError';
|
|
186
|
+
this.#ids = ids;
|
|
187
|
+
}
|
|
188
|
+
/** The entry ids named by the envelope that could not be resolved. */ get ids() {
|
|
189
|
+
return this.#ids;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { type SigningIdentity } from '@kokuin/token';
|
|
2
|
+
import { type GroupHandle } from './group.js';
|
|
3
|
+
/** `type` tag on every recovery-request token. Domain-separates it, so a token
|
|
4
|
+
* minted for another purpose can never pose as a request for group state. */
|
|
5
|
+
export declare const RECOVERY_REQUEST_TYPE = "group.recovery-request";
|
|
6
|
+
/** `type` tag on a responder's GroupInfo attestation. Domain-separates the
|
|
7
|
+
* membership proof, so no token minted elsewhere can stand in for it. */
|
|
8
|
+
export declare const RECOVERY_GROUPINFO_TYPE = "group.recovery-groupinfo";
|
|
9
|
+
/** The only sealed-reply format this build produces or opens. */
|
|
10
|
+
export declare const SEALED_GROUP_INFO_VERSION = 1;
|
|
11
|
+
/** The sealed ledger reply shares the frame — `[version][enc][ct]` — and nothing
|
|
12
|
+
* else: see {@link LEDGER_REPLY}. */
|
|
13
|
+
export declare const SEALED_LEDGER_VERSION = 1;
|
|
14
|
+
/**
|
|
15
|
+
* The signed payload a recovering peer publishes. The requester DID is the signed
|
|
16
|
+
* `iss`, never a self-asserted payload field — nothing to disagree with the
|
|
17
|
+
* signing key. `ephemeralKey` is the only key a reply is ever sealed to (a
|
|
18
|
+
* responder never seals to a key handed in alongside the request), so the
|
|
19
|
+
* signature covers the key that matters.
|
|
20
|
+
*/
|
|
21
|
+
export type RecoveryRequest = {
|
|
22
|
+
type: typeof RECOVERY_REQUEST_TYPE;
|
|
23
|
+
groupID: string;
|
|
24
|
+
requestID: string;
|
|
25
|
+
/** Multibase-encoded X25519 public key, minted per request. */
|
|
26
|
+
ephemeralKey: string;
|
|
27
|
+
};
|
|
28
|
+
/** A recovery request whose signature verified and whose fields parsed. */
|
|
29
|
+
export type VerifiedRecoveryRequest = {
|
|
30
|
+
/** The authenticated issuer of the request token, normalized. */
|
|
31
|
+
requesterDID: string;
|
|
32
|
+
groupID: string;
|
|
33
|
+
requestID: string;
|
|
34
|
+
ephemeralPublicKey: Uint8Array;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Why a responder refused a request.
|
|
38
|
+
*
|
|
39
|
+
* - `unverified` — token unparseable, unsigned, or signature fails against the DID
|
|
40
|
+
* it names.
|
|
41
|
+
* - `malformed` — signature verified but payload is not a recovery request (wrong
|
|
42
|
+
* `type`, missing field, or `ephemeralKey` not a 32-byte X25519 key).
|
|
43
|
+
* - `group-mismatch` — validly signed request for another group. Without this
|
|
44
|
+
* check a responder in both groups would seal *this* group's state to a request
|
|
45
|
+
* authorized against another.
|
|
46
|
+
* - `not-a-member` — requester's DID has no leaf in the responder's current
|
|
47
|
+
* ratchet tree. The authorization check; a removed member fails it.
|
|
48
|
+
*/
|
|
49
|
+
export type RecoveryRequestRejection = 'unverified' | 'malformed' | 'group-mismatch' | 'not-a-member';
|
|
50
|
+
/** Thrown by {@link sealGroupInfo}. The primitive refuses loudly rather than
|
|
51
|
+
* returning an empty reply; a responder that wants to stay silent catches this. */
|
|
52
|
+
export declare class RecoveryRequestError extends Error {
|
|
53
|
+
#private;
|
|
54
|
+
constructor(reason: RecoveryRequestRejection, message: string);
|
|
55
|
+
get reason(): RecoveryRequestRejection;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Why a requester could not open a reply.
|
|
59
|
+
*
|
|
60
|
+
* - `not-for-me` — the AEAD refused: sealed to another ephemeral key, or AAD binds
|
|
61
|
+
* another member or request. Indistinguishable and all mean "not this peer's".
|
|
62
|
+
* Never a post-decryption field comparison — the binding is the AAD, so a reply
|
|
63
|
+
* for someone else never decrypts.
|
|
64
|
+
* - `malformed` — frame truncated or unknown version, or the sealed plaintext is
|
|
65
|
+
* not a framed `MLSMessage(GroupInfo)`.
|
|
66
|
+
*/
|
|
67
|
+
export type SealedReplyRejection = 'not-for-me' | 'malformed';
|
|
68
|
+
/**
|
|
69
|
+
* Why a requester could not open a sealed GroupInfo — the two shared reasons plus
|
|
70
|
+
* two the AEAD cannot enforce (HPKE base mode authenticates no responder):
|
|
71
|
+
*
|
|
72
|
+
* - `unauthenticated` — no valid proof that a member of the requester's own
|
|
73
|
+
* last-known group sealed it: missing/unsigned/unverifiable attestation, one that
|
|
74
|
+
* does not bind this group / request / GroupInfo, or one signed by a DID with no
|
|
75
|
+
* leaf in the requester's tree.
|
|
76
|
+
* - `group-mismatch` — the offered GroupInfo names a different group id or carries a
|
|
77
|
+
* different genesis anchor than the group being healed. The anchor is immutable
|
|
78
|
+
* and the requester holds it, so this is a byte comparison, not a trust decision.
|
|
79
|
+
*/
|
|
80
|
+
export type SealedGroupInfoRejection = SealedReplyRejection | 'unauthenticated' | 'group-mismatch';
|
|
81
|
+
/** Why a requester could not open a sealed ledger — the same two answers. A
|
|
82
|
+
* GroupInfo presented as a ledger is `not-for-me`, not `malformed`: the domains
|
|
83
|
+
* differ, so the AEAD refuses before anything is parsed. */
|
|
84
|
+
export type SealedLedgerRejection = SealedReplyRejection;
|
|
85
|
+
/** Thrown by {@link openSealedGroupInfo}. Distinguishes "not addressed to me" from
|
|
86
|
+
* "corrupt", so a peer sifting a shared lane drops the former quietly. */
|
|
87
|
+
export declare class SealedGroupInfoError extends Error {
|
|
88
|
+
#private;
|
|
89
|
+
constructor(reason: SealedGroupInfoRejection, message: string);
|
|
90
|
+
get reason(): SealedGroupInfoRejection;
|
|
91
|
+
}
|
|
92
|
+
/** Thrown by {@link openSealedLedger}, read like its GroupInfo sibling: a requester
|
|
93
|
+
* sifting a shared lane drops `not-for-me` quietly (every other member's reply to
|
|
94
|
+
* every other request looks like this) and shouts about `malformed`. */
|
|
95
|
+
export declare class SealedLedgerError extends Error {
|
|
96
|
+
#private;
|
|
97
|
+
constructor(reason: SealedReplyRejection, message: string);
|
|
98
|
+
get reason(): SealedReplyRejection;
|
|
99
|
+
}
|
|
100
|
+
export type CreateRecoveryRequestParams = {
|
|
101
|
+
/** The requester's own (possibly stale) handle: it names the group, and its
|
|
102
|
+
* ciphersuite is the HPKE the ephemeral keypair must be minted under. */
|
|
103
|
+
group: GroupHandle;
|
|
104
|
+
identity: SigningIdentity;
|
|
105
|
+
/** Correlation id, minted per recover() call. Not authorization — the signature
|
|
106
|
+
* and the responder's roster check carry that. */
|
|
107
|
+
requestID: string;
|
|
108
|
+
};
|
|
109
|
+
export type CreateRecoveryRequestResult = {
|
|
110
|
+
/** The signed request token, verbatim wire form. */
|
|
111
|
+
request: string;
|
|
112
|
+
ephemeralPublicKey: Uint8Array;
|
|
113
|
+
/** Retained by the host, keyed by `requestID`, until the reply is opened. The
|
|
114
|
+
* caller owns its lifetime: nothing here zeroes it. */
|
|
115
|
+
ephemeralPrivateKey: Uint8Array;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Mint an ephemeral HPKE keypair and sign the request that publishes its public
|
|
119
|
+
* half. One keypair per request: the private half is what makes the reply openable
|
|
120
|
+
* by this peer and nobody else — an attacker who stole the peer's DID identity key
|
|
121
|
+
* can forge the *request* but cannot read the answer. The keypair is drawn from the
|
|
122
|
+
* group's own ciphersuite HPKE, so no second HPKE enters the system.
|
|
123
|
+
*/
|
|
124
|
+
export declare function createRecoveryRequest(params: CreateRecoveryRequestParams): Promise<CreateRecoveryRequestResult>;
|
|
125
|
+
export type SealGroupInfoParams = {
|
|
126
|
+
/** The responder's current handle. Its ratchet tree — not a roster snapshot or
|
|
127
|
+
* policy list — is what authorizes the requester. */
|
|
128
|
+
group: GroupHandle;
|
|
129
|
+
/** The responder's signing identity: signs the membership attestation and must be
|
|
130
|
+
* the identity behind `group`'s own leaf. */
|
|
131
|
+
identity: SigningIdentity;
|
|
132
|
+
/** The signed request token, verbatim. */
|
|
133
|
+
request: string;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Answer a recovery request with this group's framed `MLSMessage(GroupInfo)`,
|
|
137
|
+
* sealed to the ephemeral key inside the signed request, plus a membership
|
|
138
|
+
* attestation signed with the responder's DID identity key.
|
|
139
|
+
*
|
|
140
|
+
* The attestation is load-bearing: HPKE base mode seals to the requester's public
|
|
141
|
+
* ephemeral key (which rides the public request in the clear), so the AEAD cannot
|
|
142
|
+
* distinguish a member's reply from a forgery. The attestation — bound to this
|
|
143
|
+
* group, request, and a digest of these exact GroupInfo bytes — lets the requester
|
|
144
|
+
* refuse a reply from anyone holding no leaf in its own last-known tree.
|
|
145
|
+
*
|
|
146
|
+
* Throws {@link RecoveryRequestError} for every refusal. The reply is
|
|
147
|
+
* `[version][enc][ct]`, unreadable without the ephemeral private key and opening
|
|
148
|
+
* for no other member, request, or kind.
|
|
149
|
+
*/
|
|
150
|
+
export declare function sealGroupInfo(params: SealGroupInfoParams): Promise<Uint8Array>;
|
|
151
|
+
export type OpenSealedGroupInfoParams = {
|
|
152
|
+
/** The requester's own handle. Supplies the DID and group the AAD is rebuilt from
|
|
153
|
+
* — a caller has no DID to pass, so cannot open a reply for someone else. */
|
|
154
|
+
group: GroupHandle;
|
|
155
|
+
sealed: Uint8Array;
|
|
156
|
+
/** The id of the request this reply is expected to answer. */
|
|
157
|
+
requestID: string;
|
|
158
|
+
/** The private half retained since {@link createRecoveryRequest}. */
|
|
159
|
+
ephemeralPrivateKey: Uint8Array;
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Open a sealed reply and return the framed `MLSMessage(GroupInfo)` — the exact
|
|
163
|
+
* bytes `joinGroupExternal` takes. Throws {@link SealedGroupInfoError}.
|
|
164
|
+
*
|
|
165
|
+
* Opening is not the end of the check: HPKE base mode proves only that this peer
|
|
166
|
+
* held the ephemeral key, not that a member sealed it. Two further gates make the
|
|
167
|
+
* reply roster-intrinsic before the bytes are handed on — the signed attestation
|
|
168
|
+
* must place the sealer in this requester's own last-known tree, and the offered
|
|
169
|
+
* GroupInfo's group id and genesis anchor must match the group being healed.
|
|
170
|
+
*/
|
|
171
|
+
export declare function openSealedGroupInfo(params: OpenSealedGroupInfoParams): Promise<Uint8Array>;
|
|
172
|
+
export type SealLedgerParams = {
|
|
173
|
+
/** The responder's current handle. Its ratchet tree authorizes the requester on
|
|
174
|
+
* the same terms as {@link sealGroupInfo}, and its own ledger is the only one it
|
|
175
|
+
* can seal: the payload is read from {@link GroupHandle.getLedger}, never handed
|
|
176
|
+
* in, so no caller can seal another group's authority state through this. */
|
|
177
|
+
group: GroupHandle;
|
|
178
|
+
/** The signed request token, verbatim — the same {@link createRecoveryRequest}
|
|
179
|
+
* token a GroupInfo request carries. */
|
|
180
|
+
request: string;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Answer a ledger gather: the group's whole ordered authority state, sealed to the
|
|
184
|
+
* ephemeral key inside the signed request.
|
|
185
|
+
*
|
|
186
|
+
* These are the SAME bodies a commit frame seals under the epoch secret, but the
|
|
187
|
+
* rendezvous topic is public and secretless. A reply the hub could open would hand
|
|
188
|
+
* every role change, in order, to anyone who knows the topic; an unauthorized reply
|
|
189
|
+
* would hand them to anyone who can mint a request. {@link sealToRequest}'s roster
|
|
190
|
+
* check closes the second hole and is NOT optional — a seal without it merely
|
|
191
|
+
* encrypts the authority state neatly to the attacker's own key.
|
|
192
|
+
*
|
|
193
|
+
* Epoch-INDEPENDENT, hence HPKE to an ephemeral key and not the epoch secret: the
|
|
194
|
+
* peer most needing a bootstrap may be at an older epoch than every responder, and
|
|
195
|
+
* a reply sealed under the responder's current epoch would be unopenable by it.
|
|
196
|
+
*
|
|
197
|
+
* The ledger sealed is always this handle's own — read from
|
|
198
|
+
* {@link GroupHandle.getLedger} under the mutex — so a responder can only ever seal
|
|
199
|
+
* the authority state of the group whose tree just authorized the requester.
|
|
200
|
+
*
|
|
201
|
+
* Throws {@link RecoveryRequestError} for every refusal; the responder stays silent.
|
|
202
|
+
*/
|
|
203
|
+
export declare function sealLedger(params: SealLedgerParams): Promise<Uint8Array>;
|
|
204
|
+
export type OpenSealedLedgerParams = {
|
|
205
|
+
/** The requester's own handle: the DID and group the AAD is rebuilt from. */
|
|
206
|
+
group: GroupHandle;
|
|
207
|
+
sealed: Uint8Array;
|
|
208
|
+
/** The id of the request this reply is expected to answer. */
|
|
209
|
+
requestID: string;
|
|
210
|
+
/** The private half retained since {@link createRecoveryRequest}. */
|
|
211
|
+
ephemeralPrivateKey: Uint8Array;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Open a sealed ledger reply and return the responder's whole ordered ledger, as
|
|
215
|
+
* signed tokens.
|
|
216
|
+
*
|
|
217
|
+
* Opening proves NOTHING about who sealed these tokens: HPKE base mode over an AAD
|
|
218
|
+
* whose fields all ride the public request in the clear, so any observer (the hub, a
|
|
219
|
+
* stranger who learned the topic) can forge a reply that opens as a member's would.
|
|
220
|
+
* The bound is not the seal but the head check the caller runs next —
|
|
221
|
+
* {@link GroupHandle.bootstrapLedger} re-derives every id from the token bytes and
|
|
222
|
+
* gates on the MLS-authenticated `ledger_head`, which a forger cannot reproduce. So a
|
|
223
|
+
* forged or lying reply can withhold, reorder, or truncate — never rewrite — and a
|
|
224
|
+
* forged one simply fails that check. Residual is DoS only (a forged reply can burn a
|
|
225
|
+
* gather attempt), not compromise. Throws {@link SealedLedgerError}.
|
|
226
|
+
*/
|
|
227
|
+
export declare function openSealedLedger(params: OpenSealedLedgerParams): Promise<Array<string>>;
|