@kumiai/mls 0.2.0 → 0.3.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/lib/head.d.ts CHANGED
@@ -8,73 +8,70 @@ export type LedgerHead = {
8
8
  head: Uint8Array;
9
9
  };
10
10
  /**
11
- * Thrown when a joiner's recomputed head does not match the authenticated one:
12
- * an inviter omitted, reordered, or truncated a ledger entry. Carries both heads
13
- * so a caller can log the mismatch. Thrown by the joiner's verification path in
14
- * a later step; here it backs {@link assertHeadMatches}.
11
+ * Thrown when a recomputed head does not match the authenticated one — an inviter
12
+ * omitted, reordered, or truncated a ledger entry. Carries both heads for logging.
13
+ * Backs {@link assertHeadMatches}.
15
14
  */
16
15
  export declare class LedgerIncompleteError extends Error {
17
16
  #private;
18
17
  constructor(expected: Uint8Array, actual: Uint8Array);
19
- /** The authenticated head read from the group's GroupContext. Named apart from
20
- * `expected`/`actual` on purpose: a test runner's diff formatter assigns those
21
- * two properties on any thrown Error, and a getter-only pair turns an
22
- * unexpected throw into a `Cannot set property` TypeError instead of the real
23
- * failure. */
18
+ /** The authenticated head from the group's GroupContext. Named apart from
19
+ * `expected`/`actual` on purpose: a test runner's diff formatter assigns those on
20
+ * any thrown Error, and a getter-only pair would turn an unexpected throw into a
21
+ * `Cannot set property` TypeError masking the real failure. */
24
22
  get expectedHead(): Uint8Array;
25
23
  /** The head recomputed from the entries the inviter supplied. */
26
24
  get actualHead(): Uint8Array;
27
25
  }
28
- /**
29
- * Genesis head for a group: `SHA256(DOMAIN ‖ groupID)`. Pure. The epoch-0 link
30
- * of the chain, written into the GroupContext by group creation.
31
- */
26
+ /** Genesis head for a group: `SHA256(DOMAIN ‖ groupID)`. Pure. The epoch-0 link of
27
+ * the chain, written into the GroupContext at group creation. */
32
28
  export declare function genesisHead(groupID: string): Uint8Array;
33
29
  /**
34
- * Extend a head by a batch of entry ids, in envelope order. Each id is a chain
35
- * link: `head ← SHA256(head ‖ frame(id))`, folded left to right. Pure,
36
- * order-sensitive, and length-sensitive (see {@link frameID}). An empty batch is
37
- * a no-op — a commit carrying no entries does not move the head.
30
+ * Extend a head by a batch of entry ids, in envelope order: `head ← SHA256(head ‖
31
+ * frame(id))`, folded left to right. Pure, order- and length-sensitive (see
32
+ * {@link frameID}). An empty batch is a no-op — a commit with no entries does not
33
+ * move the head.
38
34
  */
39
35
  export declare function extendHead(head: Uint8Array, entryIDs: Array<string>): Uint8Array;
40
36
  /**
41
37
  * Recompute a head from genesis across an ordered id list. Pure. Composes with
42
38
  * {@link extendHead}: `computeHead(g, [...a, ...b])` equals
43
- * `extendHead(extendHead(genesisHead(g), a), b)`, so an existing member verifies
44
- * a head update by extending its own chain — never by refolding from genesis.
39
+ * `extendHead(extendHead(genesisHead(g), a), b)`, so a member can verify a head
40
+ * update by extending its own chain rather than refolding from genesis.
45
41
  */
46
42
  export declare function computeHead(groupID: string, entryIDs: Array<string>): Uint8Array;
47
43
  /**
48
- * Encode a head as the LedgerHead GroupContext extension data: one version byte
49
- * (`LEDGER_HEAD_VERSION`) followed by the 32 digest bytes. A single canonical
50
- * byte form — no JSON — so the value can be byte-compared in the commit policy.
44
+ * Encode a head as LedgerHead extension data: one version byte
45
+ * (`LEDGER_HEAD_VERSION`) then the 32 digest bytes. A single canonical byte form —
46
+ * no JSON — so the commit policy can byte-compare it.
51
47
  */
52
48
  export declare function encodeLedgerHead(head: Uint8Array): Uint8Array;
53
- /**
54
- * Tolerant decode: returns null on any wrong length or unknown version byte,
55
- * never throws. Only a version-`LEDGER_HEAD_VERSION`, `1 + 32`-byte buffer
56
- * decodes.
57
- */
49
+ /** Tolerant decode: null on any wrong length or unknown version byte, never throws.
50
+ * Only a version-`LEDGER_HEAD_VERSION`, `1 + 32`-byte buffer decodes. */
58
51
  export declare function decodeLedgerHead(bytes: Uint8Array): LedgerHead | null;
59
52
  /** Build the ledger-head GroupContext extension for a head digest. */
60
53
  export declare function buildLedgerHeadExtension(head: Uint8Array): GroupContextExtension;
61
54
  /**
62
- * The head's raw GroupContext extension, exactly as it sits in the group, or
63
- * null when genuinely absent. Never throws. Mirrors
64
- * {@link readGroupAnchorExtension}: it does not decode — it is the source of the
65
- * verbatim bytes a group-context-extensions proposal must copy and the commit
66
- * policy byte-compares.
55
+ * The head's raw GroupContext extension, verbatim, or null when genuinely absent.
56
+ * Never throws, never decodes — the source of the bytes a group-context-extensions
57
+ * proposal must copy and the commit policy byte-compares. Mirrors
58
+ * {@link readGroupAnchorExtension}.
67
59
  */
68
60
  export declare function readLedgerHeadExtension(handle: GroupHandle): GroupContextExtension | null;
69
61
  /**
70
- * Read and decode the ledger head from a group handle. Returns null only when
71
- * the head extension is genuinely absent. A present-but-undecodable extension is
72
- * corruption, not absence, and throws — so a control gate fails closed rather
73
- * than silently treating a tampered head as no head. For bytes to byte-compare
74
- * or copy into a proposal, use {@link readLedgerHeadExtension}, never a
75
- * re-encode of this result.
62
+ * Read and decode the ledger head. Null only when the extension is genuinely absent;
63
+ * a present-but-undecodable extension is corruption, not absence, and THROWS — a
64
+ * control gate fails closed rather than treating a tampered head as no head. For
65
+ * bytes to byte-compare or copy into a proposal use {@link readLedgerHeadExtension},
66
+ * never a re-encode of this result.
76
67
  */
77
68
  export declare function readLedgerHead(handle: GroupHandle): LedgerHead | null;
69
+ /**
70
+ * Whether a recomputed head equals the authenticated one — the predicate form of
71
+ * {@link assertHeadMatches}. Two entry points on one comparison: a fail-closed gate
72
+ * throws, a local invariant check reads the boolean.
73
+ */
74
+ export declare function headsMatch(expected: Uint8Array, actual: Uint8Array): boolean;
78
75
  /**
79
76
  * Assert a recomputed head matches the authenticated one, or throw
80
77
  * {@link LedgerIncompleteError} carrying both. Returns for equal heads.
package/lib/head.js CHANGED
@@ -3,19 +3,15 @@ import { concatBytes } from '@noble/hashes/utils.js';
3
3
  import { makeCustomExtension } from 'ts-mls';
4
4
  import { LEDGER_HEAD_EXTENSION_TYPE } from './anchor.js';
5
5
  /** Binary version tag for the encoded ledger-head extension. */ export const LEDGER_HEAD_VERSION = 1;
6
- /**
7
- * Domain separator mixed into every genesis head so a head can never collide
8
- * with a raw SHA-256 of unrelated data (e.g. a bare group id, or another
9
- * protocol's digest of the same bytes). Fixed, non-empty, and namespaced to
10
- * this module and version.
11
- */ const DOMAIN = new TextEncoder().encode('kumiai/mls/ledger-head/v1');
6
+ /** Domain separator mixed into every genesis head so a head never collides with a
7
+ * raw SHA-256 of unrelated data (a bare group id, another protocol's digest of the
8
+ * same bytes). Fixed, non-empty, namespaced to this module and version. */ const DOMAIN = new TextEncoder().encode('kumiai/mls/ledger-head/v1');
12
9
  const utf8 = new TextEncoder();
13
10
  const SHA256_LENGTH = 32;
14
11
  /**
15
- * Thrown when a joiner's recomputed head does not match the authenticated one:
16
- * an inviter omitted, reordered, or truncated a ledger entry. Carries both heads
17
- * so a caller can log the mismatch. Thrown by the joiner's verification path in
18
- * a later step; here it backs {@link assertHeadMatches}.
12
+ * Thrown when a recomputed head does not match the authenticated one — an inviter
13
+ * omitted, reordered, or truncated a ledger entry. Carries both heads for logging.
14
+ * Backs {@link assertHeadMatches}.
19
15
  */ export class LedgerIncompleteError extends Error {
20
16
  #expected;
21
17
  #actual;
@@ -25,11 +21,10 @@ const SHA256_LENGTH = 32;
25
21
  this.#expected = expected;
26
22
  this.#actual = actual;
27
23
  }
28
- /** The authenticated head read from the group's GroupContext. Named apart from
29
- * `expected`/`actual` on purpose: a test runner's diff formatter assigns those
30
- * two properties on any thrown Error, and a getter-only pair turns an
31
- * unexpected throw into a `Cannot set property` TypeError instead of the real
32
- * failure. */ get expectedHead() {
24
+ /** The authenticated head from the group's GroupContext. Named apart from
25
+ * `expected`/`actual` on purpose: a test runner's diff formatter assigns those on
26
+ * any thrown Error, and a getter-only pair would turn an unexpected throw into a
27
+ * `Cannot set property` TypeError masking the real failure. */ get expectedHead() {
33
28
  return this.#expected;
34
29
  }
35
30
  /** The head recomputed from the entries the inviter supplied. */ get actualHead() {
@@ -37,9 +32,9 @@ const SHA256_LENGTH = 32;
37
32
  }
38
33
  }
39
34
  /**
40
- * Length-frame one entry id: a 4-byte big-endian length prefix before the id's
41
- * UTF-8 bytes. The prefix makes the chain unambiguous about id boundaries, so
42
- * `['ab','c']` and `['a','bc']` cannot fold to the same head.
35
+ * Length-frame one entry id: 4-byte big-endian length prefix before the id's UTF-8
36
+ * bytes. Makes id boundaries unambiguous, so `['ab','c']` and `['a','bc']` cannot
37
+ * fold to the same head.
43
38
  */ function frameID(id) {
44
39
  const bytes = utf8.encode(id);
45
40
  const framed = new Uint8Array(4 + bytes.length);
@@ -48,17 +43,15 @@ const SHA256_LENGTH = 32;
48
43
  framed.set(bytes, 4);
49
44
  return framed;
50
45
  }
51
- /**
52
- * Genesis head for a group: `SHA256(DOMAIN ‖ groupID)`. Pure. The epoch-0 link
53
- * of the chain, written into the GroupContext by group creation.
54
- */ export function genesisHead(groupID) {
46
+ /** Genesis head for a group: `SHA256(DOMAIN ‖ groupID)`. Pure. The epoch-0 link of
47
+ * the chain, written into the GroupContext at group creation. */ export function genesisHead(groupID) {
55
48
  return sha256(concatBytes(DOMAIN, utf8.encode(groupID)));
56
49
  }
57
50
  /**
58
- * Extend a head by a batch of entry ids, in envelope order. Each id is a chain
59
- * link: `head ← SHA256(head ‖ frame(id))`, folded left to right. Pure,
60
- * order-sensitive, and length-sensitive (see {@link frameID}). An empty batch is
61
- * a no-op — a commit carrying no entries does not move the head.
51
+ * Extend a head by a batch of entry ids, in envelope order: `head ← SHA256(head ‖
52
+ * frame(id))`, folded left to right. Pure, order- and length-sensitive (see
53
+ * {@link frameID}). An empty batch is a no-op — a commit with no entries does not
54
+ * move the head.
62
55
  */ export function extendHead(head, entryIDs) {
63
56
  let acc = head;
64
57
  for (const id of entryIDs){
@@ -69,26 +62,23 @@ const SHA256_LENGTH = 32;
69
62
  /**
70
63
  * Recompute a head from genesis across an ordered id list. Pure. Composes with
71
64
  * {@link extendHead}: `computeHead(g, [...a, ...b])` equals
72
- * `extendHead(extendHead(genesisHead(g), a), b)`, so an existing member verifies
73
- * a head update by extending its own chain — never by refolding from genesis.
65
+ * `extendHead(extendHead(genesisHead(g), a), b)`, so a member can verify a head
66
+ * update by extending its own chain rather than refolding from genesis.
74
67
  */ export function computeHead(groupID, entryIDs) {
75
68
  return extendHead(genesisHead(groupID), entryIDs);
76
69
  }
77
70
  /**
78
- * Encode a head as the LedgerHead GroupContext extension data: one version byte
79
- * (`LEDGER_HEAD_VERSION`) followed by the 32 digest bytes. A single canonical
80
- * byte form — no JSON — so the value can be byte-compared in the commit policy.
71
+ * Encode a head as LedgerHead extension data: one version byte
72
+ * (`LEDGER_HEAD_VERSION`) then the 32 digest bytes. A single canonical byte form —
73
+ * no JSON — so the commit policy can byte-compare it.
81
74
  */ export function encodeLedgerHead(head) {
82
75
  const bytes = new Uint8Array(1 + head.length);
83
76
  bytes[0] = LEDGER_HEAD_VERSION;
84
77
  bytes.set(head, 1);
85
78
  return bytes;
86
79
  }
87
- /**
88
- * Tolerant decode: returns null on any wrong length or unknown version byte,
89
- * never throws. Only a version-`LEDGER_HEAD_VERSION`, `1 + 32`-byte buffer
90
- * decodes.
91
- */ export function decodeLedgerHead(bytes) {
80
+ /** Tolerant decode: null on any wrong length or unknown version byte, never throws.
81
+ * Only a version-`LEDGER_HEAD_VERSION`, `1 + 32`-byte buffer decodes. */ export function decodeLedgerHead(bytes) {
92
82
  if (bytes.length !== 1 + SHA256_LENGTH || bytes[0] !== LEDGER_HEAD_VERSION) {
93
83
  return null;
94
84
  }
@@ -107,21 +97,19 @@ function findHeadExtension(handle) {
107
97
  return handle.state.groupContext.extensions.find((ext)=>ext.extensionType === LEDGER_HEAD_EXTENSION_TYPE);
108
98
  }
109
99
  /**
110
- * The head's raw GroupContext extension, exactly as it sits in the group, or
111
- * null when genuinely absent. Never throws. Mirrors
112
- * {@link readGroupAnchorExtension}: it does not decode — it is the source of the
113
- * verbatim bytes a group-context-extensions proposal must copy and the commit
114
- * policy byte-compares.
100
+ * The head's raw GroupContext extension, verbatim, or null when genuinely absent.
101
+ * Never throws, never decodes — the source of the bytes a group-context-extensions
102
+ * proposal must copy and the commit policy byte-compares. Mirrors
103
+ * {@link readGroupAnchorExtension}.
115
104
  */ export function readLedgerHeadExtension(handle) {
116
105
  return findHeadExtension(handle) ?? null;
117
106
  }
118
107
  /**
119
- * Read and decode the ledger head from a group handle. Returns null only when
120
- * the head extension is genuinely absent. A present-but-undecodable extension is
121
- * corruption, not absence, and throws — so a control gate fails closed rather
122
- * than silently treating a tampered head as no head. For bytes to byte-compare
123
- * or copy into a proposal, use {@link readLedgerHeadExtension}, never a
124
- * re-encode of this result.
108
+ * Read and decode the ledger head. Null only when the extension is genuinely absent;
109
+ * a present-but-undecodable extension is corruption, not absence, and THROWS — a
110
+ * control gate fails closed rather than treating a tampered head as no head. For
111
+ * bytes to byte-compare or copy into a proposal use {@link readLedgerHeadExtension},
112
+ * never a re-encode of this result.
125
113
  */ export function readLedgerHead(handle) {
126
114
  const extension = findHeadExtension(handle);
127
115
  if (extension == null) {
@@ -145,11 +133,18 @@ function bytesEqual(a, b) {
145
133
  }
146
134
  return true;
147
135
  }
136
+ /**
137
+ * Whether a recomputed head equals the authenticated one — the predicate form of
138
+ * {@link assertHeadMatches}. Two entry points on one comparison: a fail-closed gate
139
+ * throws, a local invariant check reads the boolean.
140
+ */ export function headsMatch(expected, actual) {
141
+ return bytesEqual(expected, actual);
142
+ }
148
143
  /**
149
144
  * Assert a recomputed head matches the authenticated one, or throw
150
145
  * {@link LedgerIncompleteError} carrying both. Returns for equal heads.
151
146
  */ export function assertHeadMatches(expected, actual) {
152
- if (!bytesEqual(expected, actual)) {
147
+ if (!headsMatch(expected, actual)) {
153
148
  throw new LedgerIncompleteError(expected, actual);
154
149
  }
155
150
  }
package/lib/index.d.ts CHANGED
@@ -8,9 +8,10 @@ export { createNobleCryptoProvider, type NobleCryptoProviderOptions, nobleCrypto
8
8
  export { CONTROL_ENVELOPE_VERSION, type ControlEnvelope, type DecodeResult, decodeControlEnvelope, encodeControlEnvelope, } from './envelope.js';
9
9
  export { type EnvelopeFoldResult, foldEnvelope } from './envelope-fold.js';
10
10
  export { type FoldDrop, type FoldInput, foldLedger, type LedgerReducer, } from './fold.js';
11
- export { type CommitInviteResult, type CommitLedgerEntriesResult, CommitRejectedError, type CreateGroupResult, type CreateInviteParams, type CreateInviteResult, commitInvite, commitLedgerEntries, createGroup, createInvite, createKeyPackageBundle, type ExportGroupInfoParams, type ExportGroupInfoResult, exportGroupInfo, GroupHandle, type GroupHandleParams, type HeldLedgerEntry, type InspectGroupInfoResult, inspectGroupInfo, type JoinGroupExternalParams, type JoinGroupExternalResult, joinGroupExternal, type LedgerLogEntry, makeMLSCredential, type ProcessWelcomeParams, type ProcessWelcomeResult, processWelcome, type RemoveMemberResult, type RestoreGroupParams, readMessageEpoch, removeMember, restoreGroup, } from './group.js';
12
- export { assertHeadMatches, buildLedgerHeadExtension, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, LEDGER_HEAD_VERSION, type LedgerHead, LedgerIncompleteError, readLedgerHead, readLedgerHeadExtension, } from './head.js';
11
+ export { type CommitInviteResult, type CommitLedgerEntriesResult, CommitRejectedError, type CreateGroupResult, type CreateInviteParams, type CreateInviteResult, commitInvite, commitLedgerEntries, createGroup, createInvite, createKeyPackageBundle, type ExportGroupInfoParams, type ExportGroupInfoResult, exportGroupInfo, GroupHandle, type GroupHandleParams, type HeldLedgerEntry, type InspectGroupInfoResult, inspectGroupInfo, type JoinGroupExternalParams, type JoinGroupExternalResult, joinGroupExternal, type LedgerLogEntry, makeMLSCredential, type ProcessWelcomeOnceParams, type ProcessWelcomeParams, type ProcessWelcomeResult, processWelcome, processWelcomeOnce, type RemoveMemberResult, type RestoreGroupParams, readMessageEpoch, removeMember, restoreGroup, } from './group.js';
12
+ export { assertHeadMatches, buildLedgerHeadExtension, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, headsMatch, LEDGER_HEAD_VERSION, type LedgerHead, LedgerIncompleteError, readLedgerHead, readLedgerHeadExtension, } from './head.js';
13
13
  export { type LedgerEntry, ledgerEntryDigest, signLedgerEntry, type VerifiedLedgerEntry, verifyLedgerEntry, } from './ledger.js';
14
14
  export { type CommitPolicyContext, defaultCommitPolicy, MissingLedgerEntriesError, } from './policy.js';
15
+ export { type CreateRecoveryRequestParams, type CreateRecoveryRequestResult, createRecoveryRequest, type OpenSealedGroupInfoParams, type OpenSealedLedgerParams, openSealedGroupInfo, openSealedLedger, RECOVERY_REQUEST_TYPE, type RecoveryRequest, RecoveryRequestError, type RecoveryRequestRejection, SEALED_GROUP_INFO_VERSION, SEALED_LEDGER_VERSION, SealedGroupInfoError, type SealedGroupInfoRejection, SealedLedgerError, type SealedLedgerRejection, type SealedReplyRejection, type SealGroupInfoParams, type SealLedgerParams, sealGroupInfo, sealLedger, type VerifiedRecoveryRequest, } from './recovery.js';
15
16
  export { adminCount, foldRoster, type GroupPermission, ROLE_ENTRY_TYPE, type RoleValue, type RosterState, roleReducer, } from './roster.js';
16
17
  export type { GroupOptions, GroupSyncScope, Invite, KeyPackageBundle } from './types.js';
package/lib/index.js CHANGED
@@ -7,8 +7,9 @@ export { createNobleCryptoProvider, nobleCryptoProvider } from './crypto.js';
7
7
  export { CONTROL_ENVELOPE_VERSION, decodeControlEnvelope, encodeControlEnvelope } from './envelope.js';
8
8
  export { foldEnvelope } from './envelope-fold.js';
9
9
  export { foldLedger } from './fold.js';
10
- export { CommitRejectedError, commitInvite, commitLedgerEntries, createGroup, createInvite, createKeyPackageBundle, exportGroupInfo, GroupHandle, inspectGroupInfo, joinGroupExternal, makeMLSCredential, processWelcome, readMessageEpoch, removeMember, restoreGroup } from './group.js';
11
- export { assertHeadMatches, buildLedgerHeadExtension, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, LEDGER_HEAD_VERSION, LedgerIncompleteError, readLedgerHead, readLedgerHeadExtension } from './head.js';
10
+ export { CommitRejectedError, commitInvite, commitLedgerEntries, createGroup, createInvite, createKeyPackageBundle, exportGroupInfo, GroupHandle, inspectGroupInfo, joinGroupExternal, makeMLSCredential, processWelcome, processWelcomeOnce, readMessageEpoch, removeMember, restoreGroup } from './group.js';
11
+ export { assertHeadMatches, buildLedgerHeadExtension, computeHead, decodeLedgerHead, encodeLedgerHead, extendHead, genesisHead, headsMatch, LEDGER_HEAD_VERSION, LedgerIncompleteError, readLedgerHead, readLedgerHeadExtension } from './head.js';
12
12
  export { ledgerEntryDigest, signLedgerEntry, verifyLedgerEntry } from './ledger.js';
13
13
  export { defaultCommitPolicy, MissingLedgerEntriesError } from './policy.js';
14
+ export { createRecoveryRequest, openSealedGroupInfo, openSealedLedger, RECOVERY_REQUEST_TYPE, RecoveryRequestError, SEALED_GROUP_INFO_VERSION, SEALED_LEDGER_VERSION, SealedGroupInfoError, SealedLedgerError, sealGroupInfo, sealLedger } from './recovery.js';
14
15
  export { adminCount, foldRoster, ROLE_ENTRY_TYPE, roleReducer } from './roster.js';
@@ -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>>;