@941design/marmot-engine 0.0.0-stage → 0.2.0-alpha.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/CHANGELOG.md +434 -0
- package/LICENSE +49 -0
- package/README.md +33 -2
- package/dist/audit/emitter.d.ts +17 -0
- package/dist/audit/emitter.js +30 -0
- package/dist/audit/helpers.d.ts +16 -0
- package/dist/audit/helpers.js +103 -0
- package/dist/audit/index.d.ts +6 -0
- package/dist/audit/index.js +6 -0
- package/dist/audit/recorder.d.ts +13 -0
- package/dist/audit/recorder.js +24 -0
- package/dist/audit/sink.d.ts +16 -0
- package/dist/audit/sink.js +27 -0
- package/dist/audit/types-internal.d.ts +7 -0
- package/dist/audit/types-internal.js +1 -0
- package/dist/audit/types.d.ts +289 -0
- package/dist/audit/types.js +2 -0
- package/dist/core/account-identity-proof.d.ts +165 -0
- package/dist/core/account-identity-proof.js +277 -0
- package/dist/core/application-rumor.d.ts +45 -0
- package/dist/core/application-rumor.js +120 -0
- package/dist/core/auth-service.d.ts +2 -0
- package/dist/core/auth-service.js +52 -0
- package/dist/core/binary.d.ts +142 -0
- package/dist/core/binary.js +363 -0
- package/dist/core/capabilities.d.ts +51 -0
- package/dist/core/capabilities.js +102 -0
- package/dist/core/client-state.d.ts +119 -0
- package/dist/core/client-state.js +226 -0
- package/dist/core/commit-authorization.d.ts +26 -0
- package/dist/core/commit-authorization.js +26 -0
- package/dist/core/components/admin-policy.d.ts +4 -0
- package/dist/core/components/admin-policy.js +69 -0
- package/dist/core/components/agent-text-stream.d.ts +51 -0
- package/dist/core/components/agent-text-stream.js +112 -0
- package/dist/core/components/app-components-list.d.ts +17 -0
- package/dist/core/components/app-components-list.js +35 -0
- package/dist/core/components/avatar-url.d.ts +12 -0
- package/dist/core/components/avatar-url.js +85 -0
- package/dist/core/components/bytes.d.ts +5 -0
- package/dist/core/components/bytes.js +18 -0
- package/dist/core/components/dictionary.d.ts +80 -0
- package/dist/core/components/dictionary.js +175 -0
- package/dist/core/components/disband-validation.d.ts +21 -0
- package/dist/core/components/disband-validation.js +173 -0
- package/dist/core/components/encrypted-media.d.ts +44 -0
- package/dist/core/components/encrypted-media.js +210 -0
- package/dist/core/components/group-lifecycle.d.ts +10 -0
- package/dist/core/components/group-lifecycle.js +32 -0
- package/dist/core/components/group-profile.d.ts +24 -0
- package/dist/core/components/group-profile.js +35 -0
- package/dist/core/components/host-safety.d.ts +9 -0
- package/dist/core/components/host-safety.js +148 -0
- package/dist/core/components/ids.d.ts +74 -0
- package/dist/core/components/ids.js +73 -0
- package/dist/core/components/index.d.ts +14 -0
- package/dist/core/components/index.js +14 -0
- package/dist/core/components/integrity.d.ts +141 -0
- package/dist/core/components/integrity.js +293 -0
- package/dist/core/components/message-retention.d.ts +17 -0
- package/dist/core/components/message-retention.js +26 -0
- package/dist/core/components/nostr-routing.d.ts +8 -0
- package/dist/core/components/nostr-routing.js +92 -0
- package/dist/core/components/url.d.ts +26 -0
- package/dist/core/components/url.js +44 -0
- package/dist/core/convergence-status.d.ts +84 -0
- package/dist/core/convergence-status.js +82 -0
- package/dist/core/convergence.d.ts +567 -0
- package/dist/core/convergence.js +1150 -0
- package/dist/core/credential.d.ts +16 -0
- package/dist/core/credential.js +64 -0
- package/dist/core/default-capabilities.d.ts +9 -0
- package/dist/core/default-capabilities.js +34 -0
- package/dist/core/extensions.d.ts +9 -0
- package/dist/core/extensions.js +5 -0
- package/dist/core/grease.d.ts +2 -0
- package/dist/core/grease.js +6 -0
- package/dist/core/group-event.d.ts +18 -0
- package/dist/core/group-event.js +30 -0
- package/dist/core/group-lifecycle.d.ts +42 -0
- package/dist/core/group-lifecycle.js +66 -0
- package/dist/core/group-members.d.ts +37 -0
- package/dist/core/group-members.js +99 -0
- package/dist/core/group-message-classify.d.ts +42 -0
- package/dist/core/group-message-classify.js +57 -0
- package/dist/core/group-message-crypto.d.ts +53 -0
- package/dist/core/group-message-crypto.js +140 -0
- package/dist/core/group-message.d.ts +5 -0
- package/dist/core/group-message.js +11 -0
- package/dist/core/group.d.ts +45 -0
- package/dist/core/group.js +78 -0
- package/dist/core/inbound.d.ts +102 -0
- package/dist/core/inbound.js +79 -0
- package/dist/core/index.d.ts +28 -0
- package/dist/core/index.js +26 -0
- package/dist/core/key-package-eligibility.d.ts +31 -0
- package/dist/core/key-package-eligibility.js +116 -0
- package/dist/core/key-package-event-decode.d.ts +43 -0
- package/dist/core/key-package-event-decode.js +118 -0
- package/dist/core/key-package-event-delete.d.ts +16 -0
- package/dist/core/key-package-event-delete.js +46 -0
- package/dist/core/key-package-event-encode.d.ts +28 -0
- package/dist/core/key-package-event-encode.js +102 -0
- package/dist/core/key-package-event.d.ts +4 -0
- package/dist/core/key-package-event.js +8 -0
- package/dist/core/key-package.d.ts +55 -0
- package/dist/core/key-package.js +115 -0
- package/dist/core/leaf-succession.d.ts +83 -0
- package/dist/core/leaf-succession.js +97 -0
- package/dist/core/media/canonical.d.ts +34 -0
- package/dist/core/media/canonical.js +57 -0
- package/dist/core/media/crypto.d.ts +79 -0
- package/dist/core/media/crypto.js +215 -0
- package/dist/core/media/imeta.d.ts +33 -0
- package/dist/core/media/imeta.js +188 -0
- package/dist/core/media/locator.d.ts +44 -0
- package/dist/core/media/locator.js +69 -0
- package/dist/core/media/types.d.ts +83 -0
- package/dist/core/media/types.js +12 -0
- package/dist/core/media.d.ts +6 -0
- package/dist/core/media.js +12 -0
- package/dist/core/protocol.d.ts +51 -0
- package/dist/core/protocol.js +41 -0
- package/dist/core/relay-lists.d.ts +52 -0
- package/dist/core/relay-lists.js +86 -0
- package/dist/core/retained-history.d.ts +78 -0
- package/dist/core/retained-history.js +59 -0
- package/dist/core/transport.d.ts +43 -0
- package/dist/core/transport.js +21 -0
- package/dist/core/welcome-event.d.ts +61 -0
- package/dist/core/welcome-event.js +116 -0
- package/dist/core/welcome-join.d.ts +155 -0
- package/dist/core/welcome-join.js +243 -0
- package/dist/core/welcome.d.ts +3 -0
- package/dist/core/welcome.js +6 -0
- package/dist/engine/admin-policy.d.ts +58 -0
- package/dist/engine/admin-policy.js +137 -0
- package/dist/engine/auto-committer.d.ts +39 -0
- package/dist/engine/auto-committer.js +42 -0
- package/dist/engine/delivered-payloads.d.ts +61 -0
- package/dist/engine/delivered-payloads.js +84 -0
- package/dist/engine/disband-request.d.ts +41 -0
- package/dist/engine/disband-request.js +86 -0
- package/dist/engine/disband-tombstone.d.ts +14 -0
- package/dist/engine/disband-tombstone.js +66 -0
- package/dist/engine/fork-recovery.d.ts +672 -0
- package/dist/engine/fork-recovery.js +1615 -0
- package/dist/engine/group-engine.d.ts +571 -0
- package/dist/engine/group-engine.js +5112 -0
- package/dist/engine/history-tree.d.ts +232 -0
- package/dist/engine/history-tree.js +651 -0
- package/dist/engine/index.d.ts +16 -0
- package/dist/engine/index.js +15 -0
- package/dist/engine/ingest-disposition.d.ts +5 -0
- package/dist/engine/ingest-disposition.js +63 -0
- package/dist/engine/ingest.d.ts +390 -0
- package/dist/engine/ingest.js +1258 -0
- package/dist/engine/ingestion-pool.d.ts +74 -0
- package/dist/engine/ingestion-pool.js +95 -0
- package/dist/engine/message-dedup.d.ts +16 -0
- package/dist/engine/message-dedup.js +20 -0
- package/dist/engine/own-commit-stamp.d.ts +30 -0
- package/dist/engine/own-commit-stamp.js +71 -0
- package/dist/engine/retained-store.d.ts +79 -0
- package/dist/engine/retained-store.js +133 -0
- package/dist/engine/sender-ratchet.d.ts +50 -0
- package/dist/engine/sender-ratchet.js +196 -0
- package/dist/engine/state-notifications.d.ts +122 -0
- package/dist/engine/state-notifications.js +173 -0
- package/dist/engine/tree-convergence.d.ts +41 -0
- package/dist/engine/tree-convergence.js +90 -0
- package/dist/engine/types.d.ts +366 -0
- package/dist/engine/types.js +14 -0
- package/dist/engine/wire-format.d.ts +77 -0
- package/dist/engine/wire-format.js +120 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -0
- package/dist/mls.d.ts +11 -0
- package/dist/mls.js +11 -0
- package/dist/utils/debug.d.ts +3 -0
- package/dist/utils/debug.js +3 -0
- package/dist/utils/encoding.d.ts +38 -0
- package/dist/utils/encoding.js +91 -0
- package/dist/utils/key-value.d.ts +18 -0
- package/dist/utils/key-value.js +2 -0
- package/dist/utils/nostr.d.ts +35 -0
- package/dist/utils/nostr.js +26 -0
- package/dist/utils/relay-url.d.ts +10 -0
- package/dist/utils/relay-url.js +23 -0
- package/dist/utils/tag-cardinality.d.ts +50 -0
- package/dist/utils/tag-cardinality.js +91 -0
- package/dist/utils/timestamp.d.ts +50 -0
- package/dist/utils/timestamp.js +95 -0
- package/dist/version.d.ts +112 -0
- package/dist/version.js +112 -0
- package/package.json +68 -3
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import { type CiphersuiteImpl, type ClientConfig, type ClientState, InternalError, type IncomingMessageCallback, type MlsFramedMessage, MlsMessage, type ProcessMessageResult, type ProposalWithSender, ValidationError } from "ts-mls";
|
|
2
|
+
import { type AppWitness, type BranchCandidate, type CandidatePathEdge, type ConvergencePolicy, type EquivocationCreditInput, type EquivocationNodeContext, type HiddenCreditPolicy, type LeafEquivocation, type RemovedLeaf, type BranchScore } from "../core/convergence.js";
|
|
3
|
+
import { type LeafKeySuccession } from "../core/leaf-succession.js";
|
|
4
|
+
import type { EdgeSnapshot } from "./history-tree.js";
|
|
5
|
+
import type { RetainedAppliedLink } from "./retained-store.js";
|
|
6
|
+
import type { CommitRejection, DisbandCandidateEvidence, GroupPeeler } from "./types.js";
|
|
7
|
+
/** One applied step on a candidate branch: parent → message → child. */
|
|
8
|
+
export interface ChainLink {
|
|
9
|
+
parent: ClientState;
|
|
10
|
+
message: MlsMessage;
|
|
11
|
+
child: ClientState;
|
|
12
|
+
/**
|
|
13
|
+
* The commit's authenticated member sender at `parent` — the
|
|
14
|
+
* {@link authenticatedSenderOf} the step was resolved with, independent of
|
|
15
|
+
* the commit's wire framing; `undefined` only for a non-member sender.
|
|
16
|
+
*/
|
|
17
|
+
senderLeafIndex: number | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A resulting state already known for one of our own applied commits, together
|
|
21
|
+
* with the confirmation tag of the exact parent it was applied to (CONV-04).
|
|
22
|
+
*
|
|
23
|
+
* The parent tag is load-bearing, not bookkeeping: `candidatesAt` admits any
|
|
24
|
+
* pooled message whose framed epoch matches the DFS node's epoch and never
|
|
25
|
+
* checks parentage, so without it the short-circuit would fire while exploring
|
|
26
|
+
* a COMPETING fork node at the same epoch and splice our canonical chain onto
|
|
27
|
+
* that branch — inflating its depth (the primary key `selectCanonicalBranch`
|
|
28
|
+
* scores on) and, if it then won, corrupting `RetainedHistoryStore` with a
|
|
29
|
+
* parent→child edge that never happened.
|
|
30
|
+
*/
|
|
31
|
+
export interface KnownNextState {
|
|
32
|
+
parentTag: string;
|
|
33
|
+
state: ClientState;
|
|
34
|
+
/**
|
|
35
|
+
* The commit's authenticated member sender at that parent, when the caller
|
|
36
|
+
* recorded it (a retained disband candidate). The short-circuit cannot
|
|
37
|
+
* re-derive it — it skips `processMessage` — so without it
|
|
38
|
+
* {@link authenticatedSenderOf} falls back to the framing, which identifies
|
|
39
|
+
* our own public-framed stamped commits (the CONV-04 case).
|
|
40
|
+
*/
|
|
41
|
+
senderLeafIndex?: number;
|
|
42
|
+
}
|
|
43
|
+
/** Shared parent-relative candidate resolution used by live and tree recovery. */
|
|
44
|
+
export type ParentResolution = {
|
|
45
|
+
kind: "resolved";
|
|
46
|
+
result: ProcessMessageResult & {
|
|
47
|
+
kind: "newState";
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
kind: "authentication_mismatch";
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The commit authenticated against this parent, but its `UpdatePath` holds
|
|
54
|
+
* no path secret for any private key the parent carries
|
|
55
|
+
* ({@link isNoOverlapError}; for a sole member's own commit, whose
|
|
56
|
+
* `UpdatePath` is empty, {@link isNoCommonAncestorError} from the parent's own
|
|
57
|
+
* leaf): this device lost path secrets it should hold —
|
|
58
|
+
* its state predates a commit of its own leaf that it did not author here
|
|
59
|
+
* (a restored snapshot). Never a dropped candidate: the caller surfaces the
|
|
60
|
+
* cause so the client can fence the group (epic-marmot-client AC-HIST-4).
|
|
61
|
+
*
|
|
62
|
+
* Seam (`branchAwareFence`): `senderLeafIndex` is the commit's authenticated
|
|
63
|
+
* committer at this parent (the admin callback's capture, taken after the
|
|
64
|
+
* framing verified); `undefined` when the callback never ran.
|
|
65
|
+
*
|
|
66
|
+
* Seam (`removalFinality`, ADR-017 R-2): `proposals` are the resolved
|
|
67
|
+
* proposals the same capture buffered — what the opaque head's removal facts
|
|
68
|
+
* are read from (`opaqueRemovalFactsOf`); present exactly when the
|
|
69
|
+
* callback ran (the committer is known).
|
|
70
|
+
*/
|
|
71
|
+
| {
|
|
72
|
+
kind: "fenced";
|
|
73
|
+
cause: unknown;
|
|
74
|
+
senderLeafIndex?: number;
|
|
75
|
+
/** @internal Seam (`removalFinality`): the capture's proposals (above). */
|
|
76
|
+
proposals?: readonly ProposalWithSender[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The commit references (by `ProposalRef`) a proposal this parent has not
|
|
80
|
+
* staged: not evaluable here YET — the proposal may still arrive.
|
|
81
|
+
*/
|
|
82
|
+
| {
|
|
83
|
+
kind: "missing_proposal";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Seam (convergence rejection reason): `rejection` names the gate that
|
|
87
|
+
* refused the commit (`admin-policy`, or the violation of
|
|
88
|
+
* `validateCommitLegality`); absent when the processing result was no
|
|
89
|
+
* accepted commit at all.
|
|
90
|
+
*/
|
|
91
|
+
| {
|
|
92
|
+
kind: "rejected";
|
|
93
|
+
reason: "authorization_or_components";
|
|
94
|
+
rejection?: CommitRejection;
|
|
95
|
+
} | {
|
|
96
|
+
kind: "deferred";
|
|
97
|
+
reason: "temporary_refusal";
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Authenticates a Commit against one exact parent, then applies the shared
|
|
101
|
+
* parent-relative authorization/component gate. A stamped own Commit is
|
|
102
|
+
* already authenticated and authorized and therefore uses its recorded child.
|
|
103
|
+
*/
|
|
104
|
+
export declare function resolveCandidateParent(params: {
|
|
105
|
+
ciphersuite: CiphersuiteImpl;
|
|
106
|
+
clientConfig?: ClientConfig;
|
|
107
|
+
parent: ClientState;
|
|
108
|
+
message: MlsFramedMessage;
|
|
109
|
+
callback: IncomingMessageCallback;
|
|
110
|
+
known?: KnownNextState;
|
|
111
|
+
}): Promise<ParentResolution>;
|
|
112
|
+
/**
|
|
113
|
+
* A commit that references (by `ProposalRef`) a proposal the state it is
|
|
114
|
+
* applied to has not staged. ts-mls signals this with a `ValidationError`
|
|
115
|
+
* "Could not find proposal with supplied reference".
|
|
116
|
+
*/
|
|
117
|
+
export declare function isMissingProposalReference(error: unknown): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* ts-mls's "this device lost its own path secrets" failure: a commit that
|
|
120
|
+
* authenticated against the state it is applied to, but whose `UpdatePath`
|
|
121
|
+
* encrypts no path secret to any private key that state holds. ts-mls throws
|
|
122
|
+
* `InternalError("No overlap between provided private keys and update path")`
|
|
123
|
+
* from `applyUpdatePathSecret` — after the framing (membership tag, signature)
|
|
124
|
+
* was verified, so the commit is genuine at that parent. Replaying a commit of
|
|
125
|
+
* the replaying leaf itself (an `UpdatePath` never encrypts to its committer)
|
|
126
|
+
* or any later commit encrypted to keys such a commit installed raises it.
|
|
127
|
+
*/
|
|
128
|
+
export declare function isNoOverlapError(error: unknown): error is InternalError;
|
|
129
|
+
/**
|
|
130
|
+
* ts-mls's `ValidationError("Could not find common ancestor")`, thrown by
|
|
131
|
+
* `applyUpdatePathSecret` (via `firstMatchAncestor`) at the same point as
|
|
132
|
+
* {@link isNoOverlapError} — after the framing was verified — when the
|
|
133
|
+
* committer's filtered direct path holds no ancestor of the applying leaf. For
|
|
134
|
+
* a commit of another leaf their lowest common ancestor is always on it (the
|
|
135
|
+
* applying leaf keeps its copath resolution non-empty; a commit removing it
|
|
136
|
+
* returns before the path is applied), so it arises only for a commit of the
|
|
137
|
+
* applying leaf itself whose filtered direct path is empty: a sole member's own
|
|
138
|
+
* commit. Its own-leaf meaning is the caller's to check.
|
|
139
|
+
*/
|
|
140
|
+
export declare function isNoCommonAncestorError(error: unknown): error is ValidationError;
|
|
141
|
+
/**
|
|
142
|
+
* Whether `error`, thrown applying a commit whose authenticated committer is
|
|
143
|
+
* `committerLeafIndex` to a state whose own leaf is `ownLeafIndex`, is the
|
|
144
|
+
* sole-member shape of lost own path secrets: an
|
|
145
|
+
* {@link isNoCommonAncestorError} of the applying leaf's own commit. Records
|
|
146
|
+
* the verdict on the error so {@link isLostPathSecretsError} recognises it
|
|
147
|
+
* wherever it is surfaced. The same error from a foreign committer is not
|
|
148
|
+
* (`false`, unrecorded): it carries no evidence of lost path secrets.
|
|
149
|
+
* `committerLeafIndex` is the admin callback's capture, so `undefined` (the
|
|
150
|
+
* callback never ran: the framing did not verify) never matches.
|
|
151
|
+
*/
|
|
152
|
+
export declare function classifyOwnCommitPathLoss(error: unknown, committerLeafIndex: number | undefined, ownLeafIndex: number): error is ValidationError;
|
|
153
|
+
/**
|
|
154
|
+
* This device lost its own path secrets (AC-HIST-4): {@link isNoOverlapError},
|
|
155
|
+
* or an {@link isNoCommonAncestorError} that {@link classifyOwnCommitPathLoss}
|
|
156
|
+
* attributed to the applying leaf's own commit (a sole member's). The
|
|
157
|
+
* predicate the client fences on.
|
|
158
|
+
*/
|
|
159
|
+
export declare function isLostPathSecretsError(error: unknown): error is Error;
|
|
160
|
+
/**
|
|
161
|
+
* Seam (`branchAwareFence`), LD-1: the fence error of a held opaque candidate
|
|
162
|
+
* rebuilt from the message its record kept (a decision taken on a later pass
|
|
163
|
+
* or after a reload no longer has the thrown error object). The result is an
|
|
164
|
+
* error {@link isLostPathSecretsError} accepts: ts-mls's own
|
|
165
|
+
* `InternalError` class for the no-overlap message, and for the sole-member
|
|
166
|
+
* shape (`Could not find common ancestor`) a `ValidationError` registered as
|
|
167
|
+
* an own-commit path loss, the same way {@link classifyOwnCommitPathLoss}
|
|
168
|
+
* registers the thrown one. A plain `Error` with the same message is no
|
|
169
|
+
* lost-path-secrets error (the client's `recordedFencingError` is one), which
|
|
170
|
+
* is why the client predicate stays the engine's.
|
|
171
|
+
*/
|
|
172
|
+
export declare function reconstructLostPathSecretsError(message: string): Error;
|
|
173
|
+
/**
|
|
174
|
+
* The member sender a framed Commit's PLAINTEXT framing names: the leaf index
|
|
175
|
+
* of a member-sent `PublicMessage`, `undefined` for every other shape — a
|
|
176
|
+
* `PrivateMessage` encrypts its sender, so its framing names none. Framing is
|
|
177
|
+
* attacker-controlled: a member can wire any commit either way. So this is no
|
|
178
|
+
* sender attribution on its own; its only caller is
|
|
179
|
+
* {@link authenticatedSenderOf}, as the fallback for a resolution that never
|
|
180
|
+
* ran `processMessage`.
|
|
181
|
+
*/
|
|
182
|
+
export declare function senderLeafIndexOf(message: MlsMessage): number | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* The authenticated member sender of a Commit resolved against its parent:
|
|
185
|
+
* `processMessage`'s `senderLeafIndex` — read from the verified plaintext
|
|
186
|
+
* framing of a `PublicMessage` and from the decrypted sender data of a
|
|
187
|
+
* `PrivateMessage` alike, so an edge's sender never depends on how its commit
|
|
188
|
+
* was framed on the wire (ADR-016 "Framing independence"). The framing is the
|
|
189
|
+
* fallback only when the resolution produced no sender: the CONV-04
|
|
190
|
+
* short-circuit for our own already-applied commits (a synthesized result
|
|
191
|
+
* that never ran `processMessage`; Marmot frames its own commits as
|
|
192
|
+
* `PublicMessage`), and a record persisted before senders were (`result`
|
|
193
|
+
* absent). `undefined` for a non-member (external) sender — which cannot
|
|
194
|
+
* equivocate, so its edge earns no credit and raises no report.
|
|
195
|
+
*
|
|
196
|
+
* Every site that attributes an edge, a chain link, a recorded history-tree
|
|
197
|
+
* edge or a branch's tip committer derives its sender here (a source scan
|
|
198
|
+
* pins {@link senderLeafIndexOf} to this one call site).
|
|
199
|
+
*/
|
|
200
|
+
export declare function authenticatedSenderOf(result: {
|
|
201
|
+
readonly senderLeafIndex: number | undefined;
|
|
202
|
+
} | undefined, message: MlsMessage): number | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* A commit that removes the LOCAL leaf, applied to a retained parent (seam,
|
|
205
|
+
* epic-marmot-client S20). ts-mls's `removedFromGroup` tombstone keeps its
|
|
206
|
+
* parent's epoch and confirmation tag, so such a commit can neither be a
|
|
207
|
+
* history-tree node nor a tag-keyed branch tip; with the engine's
|
|
208
|
+
* `removalConvergence` seam it is scored as a branch candidate of its own.
|
|
209
|
+
*/
|
|
210
|
+
export interface RemovalEdge {
|
|
211
|
+
/** Hex confirmation tag of the state the commit was applied to. */
|
|
212
|
+
parentTag: string;
|
|
213
|
+
/** That state, serialized before any sibling was explored from it. */
|
|
214
|
+
parentSnapshot: Uint8Array;
|
|
215
|
+
/** The removing commit. */
|
|
216
|
+
message: MlsMessage;
|
|
217
|
+
/** Its authenticated member sender at the parent ({@link authenticatedSenderOf}). */
|
|
218
|
+
senderLeafIndex: number | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* Seam (`removalFinality`): the removal leaf's facts, R-1 on the parent and
|
|
221
|
+
* the commit's `removedFromGroup` tombstone ({@link edgeFactsOf}); set by
|
|
222
|
+
* pool replay only while the seam is effective.
|
|
223
|
+
* @internal
|
|
224
|
+
*/
|
|
225
|
+
facts?: EdgeFacts;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The tip committer of a branch whose tip commit was authored by
|
|
229
|
+
* `senderLeafIndex` (its {@link authenticatedSenderOf}) at `parent`: that
|
|
230
|
+
* leaf's credential pubkey in `parent`, or empty bytes when it cannot be
|
|
231
|
+
* resolved — the derivation every candidate's `tipCommitter` uses, in pool
|
|
232
|
+
* replay and tree-fed re-convergence alike (seam, epic-marmot-client S20:
|
|
233
|
+
* shared with removal candidates, whose tombstone tree no longer holds the
|
|
234
|
+
* sender).
|
|
235
|
+
*/
|
|
236
|
+
export declare function tipCommitterOf(parent: ClientState, senderLeafIndex: number | undefined): Uint8Array;
|
|
237
|
+
/**
|
|
238
|
+
* Seam (`equivocationCredit`): the membership facts of one equivocation node —
|
|
239
|
+
* every occupied leaf index of `state`'s ratchet tree with its hex leaf
|
|
240
|
+
* signature key and, when the credential parses, its hex account pubkey. Shared
|
|
241
|
+
* by pool replay and the tree-fed sites so both resolve the same
|
|
242
|
+
* {@link EquivocationCreditInput} for the same node.
|
|
243
|
+
*/
|
|
244
|
+
export declare function equivocationNodeContextOf(state: ClientState): EquivocationNodeContext;
|
|
245
|
+
/**
|
|
246
|
+
* Seam (`equivocationCredit`): the hex leaf signature key of a commit's member
|
|
247
|
+
* sender in the commit's `parent` state, or `undefined` when the sender is not
|
|
248
|
+
* a member or its leaf is blank there (such an edge earns no credit).
|
|
249
|
+
*/
|
|
250
|
+
export declare function senderLeafKeyOf(parent: ClientState, senderLeafIndex: number | undefined): string | undefined;
|
|
251
|
+
/**
|
|
252
|
+
* Seam (key rotation, lineage clause of ADR-016 D2 rule 4): the signature-key
|
|
253
|
+
* successions the commit `parent` → `child` made at its own committer's leaf
|
|
254
|
+
* (`senderLeafIndex`), the only fact the credit lineage reads. Empty when the
|
|
255
|
+
* sender is unknown, nothing rotated, or the key change was made by another
|
|
256
|
+
* leaf (an Update proposal, a Remove plus re-Add): none of those extends the
|
|
257
|
+
* keys a leaf's later edges are credited under.
|
|
258
|
+
*
|
|
259
|
+
* @internal
|
|
260
|
+
*/
|
|
261
|
+
export declare function committerSuccessionsOf(parent: ClientState, child: ClientState, senderLeafIndex: number | undefined): readonly LeafKeySuccession[];
|
|
262
|
+
/**
|
|
263
|
+
* Seam (`removalFinality`, ADR-017 R-1, architecture.md SC-R8): the leaves the
|
|
264
|
+
* commit `parent` → `child` removes, each as occupied in `parent` — every index
|
|
265
|
+
* `s` where `parent` holds a leaf with signature key `K` and `child` holds no
|
|
266
|
+
* leaf with key `K` at `s`, except the indices {@link leafKeySuccessions}
|
|
267
|
+
* reports (the same leaf continuing under a new key: a rotation is not a
|
|
268
|
+
* removal). A same-key self-update removes nothing; a Remove plus an Add at one
|
|
269
|
+
* index removes the old occupant. `child` may be the `removedFromGroup`
|
|
270
|
+
* tombstone of a commit that removed the processing device (its ratchet tree
|
|
271
|
+
* is the proposal-applied one). Strictly ascending by `leafIndex`, keys
|
|
272
|
+
* lowercase hex. Total: `undefined` (unknown, never evidence) when either
|
|
273
|
+
* state is unavailable or malformed. With {@link opaqueRemovalFactsOf} the only
|
|
274
|
+
* producer of `CandidatePathEdge.removed`.
|
|
275
|
+
*
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
export declare function edgeRemovalFactsOf(parent: ClientState, child: ClientState): readonly RemovedLeaf[] | undefined;
|
|
279
|
+
/**
|
|
280
|
+
* Seam (`removalFinality`, ADR-017 R-2, architecture.md SC-R8): the removal
|
|
281
|
+
* facts of an opaque head — a commit this device cannot apply, so it has no
|
|
282
|
+
* child state — read from the resolved `proposals` the admin callback captured
|
|
283
|
+
* at its held `parent`: `(s, K_P[s])` for every Remove of `s` (and every
|
|
284
|
+
* `self_remove`, whose target is its sender: it blanks the sender's leaf as a
|
|
285
|
+
* Remove does, so R-1 on the unseen child would report it too). `undefined`
|
|
286
|
+
* (the fence then fails closed) for (i) no captured proposals, (ii) an Add in
|
|
287
|
+
* the same commit whose key equals `K_P[s]` of one of its targets (the leaf
|
|
288
|
+
* would reappear under the same key at some index), (iii) an unavailable
|
|
289
|
+
* parent, and for a target the parent holds no leaf at. Whenever it yields a
|
|
290
|
+
* set it equals {@link edgeRemovalFactsOf} on the unseen child. Strictly
|
|
291
|
+
* ascending by `leafIndex`. Total.
|
|
292
|
+
*
|
|
293
|
+
* @internal
|
|
294
|
+
*/
|
|
295
|
+
export declare function opaqueRemovalFactsOf(parent: ClientState, proposals: readonly ProposalWithSender[]): readonly RemovedLeaf[] | undefined;
|
|
296
|
+
/**
|
|
297
|
+
* Seam (`removalFinality`, architecture.md SC-R3): the facts one edge
|
|
298
|
+
* contributes to a credit input — its removal facts ({@link edgeRemovalFactsOf}),
|
|
299
|
+
* its sender's leaf signature key in the parent ({@link senderLeafKeyOf}) and the
|
|
300
|
+
* successions it made at its committer's own leaf ({@link committerSuccessionsOf})
|
|
301
|
+
* — the value of the engine's per-digest memo, computed by one function at
|
|
302
|
+
* every site so pool replay and the tree sites resolve the same facts (G2).
|
|
303
|
+
*
|
|
304
|
+
* @internal
|
|
305
|
+
*/
|
|
306
|
+
export interface EdgeFacts {
|
|
307
|
+
readonly removed: readonly RemovedLeaf[] | undefined;
|
|
308
|
+
readonly senderKey: string | undefined;
|
|
309
|
+
readonly successions: readonly LeafKeySuccession[];
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Seam (`removalFinality`): the {@link EdgeFacts} of the commit `parent` →
|
|
313
|
+
* `child` by `senderLeafIndex`. Total (each part is).
|
|
314
|
+
*
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
317
|
+
export declare function edgeFactsOf(parent: ClientState, child: ClientState, senderLeafIndex: number | undefined): EdgeFacts;
|
|
318
|
+
/**
|
|
319
|
+
* Seam (key rotation): the per-edge succession facts of a credit input at the
|
|
320
|
+
* tree-fed sites, hex commit digest → {@link committerSuccessionsOf}, for every
|
|
321
|
+
* edge of `paths` that a later edge of the same path follows (the credit of an
|
|
322
|
+
* edge depends on the successions of the edges BEFORE it, so the last edge's
|
|
323
|
+
* own is never read). `stateOf` resolves a confirmation tag to the state the
|
|
324
|
+
* site holds for it; an edge whose parent or child state it cannot resolve (or
|
|
325
|
+
* whose child is a virtual `removal:` / `terminal:` / `opaque:` leaf) gets no
|
|
326
|
+
* fact, which fails closed to the pre-key-rotation credit for its successors.
|
|
327
|
+
*
|
|
328
|
+
* @internal
|
|
329
|
+
*/
|
|
330
|
+
export declare function successionFactsOf(paths: Iterable<readonly CandidatePathEdge[]>, stateOf: (tag: string) => Promise<ClientState | undefined>): Promise<Map<string, readonly LeafKeySuccession[]>>;
|
|
331
|
+
/**
|
|
332
|
+
* Seam (`branchAwareFence`): one fenced pool-replay candidate as the pure core
|
|
333
|
+
* sees it, minus `U` (known once the whole pool was replayed): the head edge
|
|
334
|
+
* `N → opaque:<digestHex>` with the authenticated committer, the edges from
|
|
335
|
+
* the replay root to `N` and the epoch of `N`.
|
|
336
|
+
*/
|
|
337
|
+
export interface OpaqueDraft {
|
|
338
|
+
headEdge: CandidatePathEdge;
|
|
339
|
+
pathToParent: readonly CandidatePathEdge[];
|
|
340
|
+
parentEpoch: number;
|
|
341
|
+
headCommitter: Uint8Array;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Seam (`branchAwareFence`): a fenced or skipped commit that replay discovered
|
|
345
|
+
* by decrypting an `encrypted` envelope under an explored state (it was not in
|
|
346
|
+
* the pool): the envelopes' indices in the `encrypted` list handed to
|
|
347
|
+
* `resolveFork` and the commit. Keyed by hex commit digest in
|
|
348
|
+
* `opaqueEncrypted`, present only when non-empty and only for digests that are
|
|
349
|
+
* in `fenced` or `opaqueSkipped`, so the caller can apply the decision to that
|
|
350
|
+
* envelope too.
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
export interface OpaqueFromEncrypted {
|
|
354
|
+
/** Every `encrypted` index whose envelope opened to this commit (distinct wrappers of one commit). */
|
|
355
|
+
indices: number[];
|
|
356
|
+
message: MlsMessage;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Seam (`branchAwareFence`): what the caller needs to hold a pool-replay
|
|
360
|
+
* commit judged `skipped` (it stays revisable: Design Decision 6) — the node
|
|
361
|
+
* `N` it failed at, that node's epoch, its authenticated sender and the
|
|
362
|
+
* lost-path-secrets cause. Keyed by hex commit digest in `opaqueHeld`, with
|
|
363
|
+
* exactly the digests of `opaqueSkipped`.
|
|
364
|
+
* @internal
|
|
365
|
+
*/
|
|
366
|
+
export interface OpaqueHeldInfo {
|
|
367
|
+
parentTag: string;
|
|
368
|
+
parentEpoch: number;
|
|
369
|
+
senderLeafIndex: number | undefined;
|
|
370
|
+
cause: unknown;
|
|
371
|
+
/**
|
|
372
|
+
* Seam (`removalFinality`): the head's R-2 facts ({@link opaqueRemovalFactsOf}),
|
|
373
|
+
* read at the held parent while replay had it; set only while the seam is
|
|
374
|
+
* effective at the fence, and absent when they are unresolvable (fail-closed).
|
|
375
|
+
*/
|
|
376
|
+
removed?: readonly RemovedLeaf[];
|
|
377
|
+
}
|
|
378
|
+
/** The outcome of resolving a fork; the caller applies state/lifecycle changes. */
|
|
379
|
+
export type ForkResolution = {
|
|
380
|
+
outcome: "recovered";
|
|
381
|
+
winnerTip: ClientState;
|
|
382
|
+
winnerChain: ChainLink[];
|
|
383
|
+
result: ProcessMessageResult;
|
|
384
|
+
/** Every branch edge built while resolving (for history retention). */
|
|
385
|
+
edges: EdgeSnapshot[];
|
|
386
|
+
/**
|
|
387
|
+
* Seam (`removalFinality`): hex commit digest → the facts of each of
|
|
388
|
+
* `edges`, computed at edge creation (engine memory; the history tree
|
|
389
|
+
* never sees them). Present only while the seam is effective.
|
|
390
|
+
* @internal
|
|
391
|
+
*/
|
|
392
|
+
edgeFacts?: ReadonlyMap<string, EdgeFacts>;
|
|
393
|
+
/** Pool commits not evaluable yet: they reference a proposal the fork root has not staged. */
|
|
394
|
+
awaitingProposal: ReadonlySet<string>;
|
|
395
|
+
/**
|
|
396
|
+
* Seam (convergence rejection reason): pool commits dropped as
|
|
397
|
+
* candidates for failing the authorization / commit-legality gate, with
|
|
398
|
+
* the gate; present only when non-empty.
|
|
399
|
+
*/
|
|
400
|
+
rejected?: ReadonlyMap<string, CommitRejection>;
|
|
401
|
+
/** Seam (S20): commits found to remove the local leaf (each a branch candidate). */
|
|
402
|
+
removals?: RemovalEdge[];
|
|
403
|
+
decision?: {
|
|
404
|
+
selectedBranchId: string;
|
|
405
|
+
selectedTipDigest: string;
|
|
406
|
+
selectedTipCommitter: string;
|
|
407
|
+
decisiveRule: string;
|
|
408
|
+
score: BranchScore;
|
|
409
|
+
};
|
|
410
|
+
selectedTerminal?: DisbandCandidateEvidence;
|
|
411
|
+
/** Seam (`equivocationCredit`): every leaf equivocation the candidate tree holds, whoever won. */
|
|
412
|
+
equivocations?: LeafEquivocation[];
|
|
413
|
+
/**
|
|
414
|
+
* Seam (`branchAwareFence`): hex digests of fenced pool commits judged
|
|
415
|
+
* unable to win (`opaqueCouldWin` false); present only when non-empty.
|
|
416
|
+
* @internal
|
|
417
|
+
*/
|
|
418
|
+
opaqueSkipped?: ReadonlySet<string>;
|
|
419
|
+
/**
|
|
420
|
+
* Seam (`branchAwareFence`): the hold info of every `opaqueSkipped` digest.
|
|
421
|
+
* @internal
|
|
422
|
+
*/
|
|
423
|
+
opaqueHeld?: ReadonlyMap<string, OpaqueHeldInfo>;
|
|
424
|
+
/** @internal */
|
|
425
|
+
opaqueEncrypted?: ReadonlyMap<string, OpaqueFromEncrypted>;
|
|
426
|
+
/**
|
|
427
|
+
* Seam (`branchAwareFence`): the winner's tip commit when replay opened
|
|
428
|
+
* it from an `encrypted` envelope (it is no pool entry), so a result
|
|
429
|
+
* about the rewind can be attributed to its envelope.
|
|
430
|
+
* @internal
|
|
431
|
+
*/
|
|
432
|
+
opaqueTipEnvelope?: OpaqueFromEncrypted;
|
|
433
|
+
} | {
|
|
434
|
+
outcome: "superseded";
|
|
435
|
+
edges: EdgeSnapshot[];
|
|
436
|
+
/** @internal */
|
|
437
|
+
edgeFacts?: ReadonlyMap<string, EdgeFacts>;
|
|
438
|
+
/** Pool commits not evaluable yet: they reference a proposal the fork root has not staged. */
|
|
439
|
+
awaitingProposal: ReadonlySet<string>;
|
|
440
|
+
/** Seam (convergence rejection reason): see the `recovered` outcome. */
|
|
441
|
+
rejected?: ReadonlyMap<string, CommitRejection>;
|
|
442
|
+
/** Seam (S20): commits found to remove the local leaf (each a branch candidate). */
|
|
443
|
+
removals?: RemovalEdge[];
|
|
444
|
+
winnerTip?: ClientState;
|
|
445
|
+
decision?: {
|
|
446
|
+
selectedBranchId: string;
|
|
447
|
+
selectedTipDigest: string;
|
|
448
|
+
selectedTipCommitter: string;
|
|
449
|
+
decisiveRule: string;
|
|
450
|
+
score: BranchScore;
|
|
451
|
+
};
|
|
452
|
+
selectedTerminal?: DisbandCandidateEvidence;
|
|
453
|
+
/** Seam (`equivocationCredit`): every leaf equivocation the candidate tree holds, whoever won. */
|
|
454
|
+
equivocations?: LeafEquivocation[];
|
|
455
|
+
/**
|
|
456
|
+
* Seam (`branchAwareFence`): see the `recovered` outcome.
|
|
457
|
+
* @internal
|
|
458
|
+
*/
|
|
459
|
+
opaqueSkipped?: ReadonlySet<string>;
|
|
460
|
+
/** @internal */
|
|
461
|
+
opaqueHeld?: ReadonlyMap<string, OpaqueHeldInfo>;
|
|
462
|
+
/** @internal */
|
|
463
|
+
opaqueEncrypted?: ReadonlyMap<string, OpaqueFromEncrypted>;
|
|
464
|
+
} | {
|
|
465
|
+
outcome: "skip";
|
|
466
|
+
/** Pool commits not evaluable yet: they reference a proposal the fork root has not staged. */
|
|
467
|
+
awaitingProposal?: ReadonlySet<string>;
|
|
468
|
+
/** Seam (convergence rejection reason): see the `recovered` outcome. */
|
|
469
|
+
rejected?: ReadonlyMap<string, CommitRejection>;
|
|
470
|
+
/**
|
|
471
|
+
* Hex commit digest → cause, for pool commits whose replay showed this
|
|
472
|
+
* device lost its own path secrets (`fenced`). When non-empty no branch
|
|
473
|
+
* is selected or applied: the caller surfaces each as a terminal
|
|
474
|
+
* `unreadable` carrying its cause, and the client fences the group.
|
|
475
|
+
* Seam (`branchAwareFence`): only the fenced commits that could win
|
|
476
|
+
* (or all of them when no processable branch is eligible).
|
|
477
|
+
*/
|
|
478
|
+
fenced?: ReadonlyMap<string, unknown>;
|
|
479
|
+
/**
|
|
480
|
+
* Seam (`branchAwareFence`): the leaf equivocations the candidate tree
|
|
481
|
+
* (opaque head edges included) holds; reported on `skip` too. Present
|
|
482
|
+
* only when non-empty.
|
|
483
|
+
*/
|
|
484
|
+
equivocations?: LeafEquivocation[];
|
|
485
|
+
/**
|
|
486
|
+
* Seam (`branchAwareFence`): see the `recovered` outcome.
|
|
487
|
+
* @internal
|
|
488
|
+
*/
|
|
489
|
+
opaqueSkipped?: ReadonlySet<string>;
|
|
490
|
+
/** @internal */
|
|
491
|
+
opaqueHeld?: ReadonlyMap<string, OpaqueHeldInfo>;
|
|
492
|
+
/** @internal */
|
|
493
|
+
opaqueEncrypted?: ReadonlyMap<string, OpaqueFromEncrypted>;
|
|
494
|
+
};
|
|
495
|
+
/** Inputs needed to access retained history during fork resolution. */
|
|
496
|
+
export interface RetainedView {
|
|
497
|
+
stateAt(epoch: number): ClientState | undefined;
|
|
498
|
+
appliedCommitsBetween(forkEpoch: number, tipEpoch: number): MlsMessage[];
|
|
499
|
+
appliedLinksBetween?(forkEpoch: number, tipEpoch: number): RetainedAppliedLink[];
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Convergence fork recovery (Marmot v2 `protocol-core/convergence.md`):
|
|
503
|
+
* rebuilds candidate branches by replaying retained applied commits plus
|
|
504
|
+
* competing commits, scores them with the pure {@link selectCanonicalBranch}
|
|
505
|
+
* core, and reports the canonical branch so the caller can rewind.
|
|
506
|
+
*
|
|
507
|
+
* This is the stateful "candidate branch construction" layer that
|
|
508
|
+
* `convergence.ts` deliberately leaves out. It holds no engine state of its own;
|
|
509
|
+
* branch tip/chain bookkeeping is per-call. Mirrors darkmatter
|
|
510
|
+
* `cgka-engine/src/fork_recovery.rs`.
|
|
511
|
+
*/
|
|
512
|
+
export declare class ForkRecovery<TEnvelope> {
|
|
513
|
+
#private;
|
|
514
|
+
constructor(ciphersuite: CiphersuiteImpl, peeler: GroupPeeler<TEnvelope>, policy?: ConvergencePolicy, clientConfig?: ClientConfig, options?: {
|
|
515
|
+
removalCandidates?: boolean;
|
|
516
|
+
equivocationCredit?: boolean;
|
|
517
|
+
branchAwareFence?: boolean;
|
|
518
|
+
hiddenCreditPolicy?: HiddenCreditPolicy;
|
|
519
|
+
removalFinality?: boolean;
|
|
520
|
+
});
|
|
521
|
+
/**
|
|
522
|
+
* Resolves a fork at `forkEpoch` (`convergence.md`): rebuilds candidate
|
|
523
|
+
* branches by replaying retained applied commits plus the competing `pool`,
|
|
524
|
+
* selects the canonical branch, and reports it when it differs from the
|
|
525
|
+
* caller's current tip. The caller applies the rewind (state + lifecycle).
|
|
526
|
+
*/
|
|
527
|
+
resolveFork(params: {
|
|
528
|
+
forkEpoch: number;
|
|
529
|
+
pool: MlsMessage[];
|
|
530
|
+
encrypted?: TEnvelope[];
|
|
531
|
+
witnessEnvelopes?: TEnvelope[];
|
|
532
|
+
/**
|
|
533
|
+
* Application messages delivered before a restart and reloaded with the
|
|
534
|
+
* history tree. They have no transport envelope, so each is weighed as the
|
|
535
|
+
* MLS message itself ({@link collectMessageWitnessesAt}), beside
|
|
536
|
+
* `witnessEnvelopes`.
|
|
537
|
+
*/
|
|
538
|
+
witnessMessages?: MlsMessage[];
|
|
539
|
+
currentState: ClientState;
|
|
540
|
+
retained: RetainedView;
|
|
541
|
+
adminCallback: IncomingMessageCallback;
|
|
542
|
+
/**
|
|
543
|
+
* Builds the admin-verification callback for one candidate parent. When
|
|
544
|
+
* given it replaces `adminCallback` for candidate replay, so each commit
|
|
545
|
+
* is authorized against its own parent (as tree-fed re-convergence does).
|
|
546
|
+
*/
|
|
547
|
+
adminCallbackFor?: (parent: ClientState) => IncomingMessageCallback;
|
|
548
|
+
terminalCandidates?: ReadonlyMap<string, DisbandCandidateEvidence>;
|
|
549
|
+
knownCandidates?: ReadonlyMap<string, KnownNextState>;
|
|
550
|
+
/**
|
|
551
|
+
* Seam (`branchAwareFence`): `U`'s source (spec Design Decision 3a) — the
|
|
552
|
+
* event ids of the group's envelopes the caller was handed that no state it
|
|
553
|
+
* holds decrypts (the engine's persisted set). Counted with the ids of
|
|
554
|
+
* `encrypted`, less every id some state of this replay decrypted. Read
|
|
555
|
+
* only with the seam on.
|
|
556
|
+
* @internal
|
|
557
|
+
*/
|
|
558
|
+
undecryptable?: ReadonlySet<string>;
|
|
559
|
+
/**
|
|
560
|
+
* Seam (`branchAwareFence`): `U` has saturated — the caller stopped tracking
|
|
561
|
+
* ids at its cap, so the count is unknown and read as unbounded. Every
|
|
562
|
+
* opaque candidate then fences (today's behaviour). Read only with the seam
|
|
563
|
+
* on.
|
|
564
|
+
* @internal
|
|
565
|
+
*/
|
|
566
|
+
undecryptableSaturated?: boolean;
|
|
567
|
+
/**
|
|
568
|
+
* Seam (`branchAwareFence`), batch settle (spec Design Decision 6): the
|
|
569
|
+
* caller hands one batch in several calls and this is not the last. A
|
|
570
|
+
* could-win candidate is then NOT fenced here: it is reported skipped
|
|
571
|
+
* (`opaqueSkipped`, with `opaqueHeld` info) and held, and the settle at
|
|
572
|
+
* the end of the batch decides it against everything the batch brought.
|
|
573
|
+
* A candidate that cannot be held (no authenticated committer) still
|
|
574
|
+
* fences. Read only with the seam on.
|
|
575
|
+
* @internal
|
|
576
|
+
*/
|
|
577
|
+
holdCouldWin?: boolean;
|
|
578
|
+
}): Promise<ForkResolution>;
|
|
579
|
+
}
|
|
580
|
+
/** Seam (`branchAwareFence`), OQ-1: the shipped default of the hidden-credit policy. */
|
|
581
|
+
export declare const DEFAULT_HIDDEN_CREDIT_POLICY: HiddenCreditPolicy;
|
|
582
|
+
/**
|
|
583
|
+
* Seam (`branchAwareFence`), OQ-1: the hidden-credit policy an owner asked for.
|
|
584
|
+
* `undefined` is the {@link DEFAULT_HIDDEN_CREDIT_POLICY}; exactly the two
|
|
585
|
+
* {@link HiddenCreditPolicy} values are accepted; anything else is a
|
|
586
|
+
* `TypeError` (a misspelt policy must not silently become the default).
|
|
587
|
+
*/
|
|
588
|
+
export declare function normalizeHiddenCreditPolicy(value: unknown): HiddenCreditPolicy;
|
|
589
|
+
/**
|
|
590
|
+
* Seam (`branchAwareFence`): the per-digest fence decision of ADR-016 D6, one
|
|
591
|
+
* function for every site that holds an opaque candidate — pool replay
|
|
592
|
+
* ({@link ForkRecovery}) and the tree-fed sites of `MarmotGroupEngine` (the
|
|
593
|
+
* removal parent and the tree sweep) — so the sites cannot drift apart. A
|
|
594
|
+
* `drafts` entry fences when no processable `branch` is eligible, when its
|
|
595
|
+
* committer is unknown (`headEdge.senderLeafIndex`), or when `opaqueCouldWin`
|
|
596
|
+
* says its best case `o*` (appended last, so ties go to it) would be selected;
|
|
597
|
+
* otherwise it is skipped. Every `fenced` digest is decided; `undecryptable`
|
|
598
|
+
* is `U`, the depth bound and the hidden-credit bound `H` (`H = U` under the
|
|
599
|
+
* default `conservative` policy; `hiddenCreditPolicy` and `ownLeafIndex` select
|
|
600
|
+
* the OQ-1 alternative, see {@link HiddenCreditPolicy}). Candidates sharing (parent node, sender) are one
|
|
601
|
+
* group, scored once at its best case (the minimal digest among all `drafts` of
|
|
602
|
+
* the group, held members included) and decided together. `equivocations` is
|
|
603
|
+
* the report of the candidate tree with every opaque head edge in it. Pure
|
|
604
|
+
* given its inputs.
|
|
605
|
+
*
|
|
606
|
+
* Seam (`removalFinality`, architecture.md SC-R7, AC-HOLD-2): with
|
|
607
|
+
* `credit.removalFinality` a group of two or more heads is a direct
|
|
608
|
+
* equivocation the device sees, so every head of it is scored with
|
|
609
|
+
* `headEquivocated` (anchored at its parent node) and the group fences iff ANY
|
|
610
|
+
* head could win: the heads differ by digest and by their removal facts, and a
|
|
611
|
+
* sibling's facts count at the parent's ancestors, so one representative is
|
|
612
|
+
* sound only at the root (AR-R15). A group of one, and every group without the
|
|
613
|
+
* flag, keeps the minimal-digest representative.
|
|
614
|
+
* @internal
|
|
615
|
+
*/
|
|
616
|
+
export declare function decideOpaqueDrafts(params: {
|
|
617
|
+
policy: ConvergencePolicy;
|
|
618
|
+
currentTipEpoch: number;
|
|
619
|
+
branches: readonly BranchCandidate[];
|
|
620
|
+
fenced: ReadonlyMap<string, unknown>;
|
|
621
|
+
drafts: ReadonlyMap<string, OpaqueDraft>;
|
|
622
|
+
undecryptable: number;
|
|
623
|
+
/**
|
|
624
|
+
* `U` has saturated (the persisted set reached its cap): `undecryptable` is
|
|
625
|
+
* then only the last count known and the true one is unbounded, so every
|
|
626
|
+
* `fenced` digest fences — the fail-closed direction, never an un-fence.
|
|
627
|
+
*/
|
|
628
|
+
undecryptableSaturated?: boolean;
|
|
629
|
+
credit: EquivocationCreditInput;
|
|
630
|
+
/** OQ-1; `conservative` when absent. A value other than the two fails closed (every candidate fences). */
|
|
631
|
+
hiddenCreditPolicy?: HiddenCreditPolicy;
|
|
632
|
+
/** The device's own leaf `ℓ`; read only by `anchored-zero`. */
|
|
633
|
+
ownLeafIndex?: number;
|
|
634
|
+
}): {
|
|
635
|
+
fenced: Map<string, unknown>;
|
|
636
|
+
skipped: Set<string>;
|
|
637
|
+
equivocations: LeafEquivocation[];
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* Collects the {@link AppWitness}es that decrypt against a single candidate
|
|
641
|
+
* `state` (`convergence.md` "App-payload witnesses"): each witness envelope is
|
|
642
|
+
* peeled and processed, and an authenticated application message contributes a
|
|
643
|
+
* witness keyed by the sender's account pubkey. Seam: the witness is credited
|
|
644
|
+
* at the epoch the message was SENT in (its framing), not at the epoch of the
|
|
645
|
+
* state that happened to decrypt it, so a payload sent at or before a fork root
|
|
646
|
+
* that a post-root snapshot still decrypts (`historicalReceiverData`) is not a
|
|
647
|
+
* witness for the branch (`isWitnessEligible`: strictly after the fork) and one
|
|
648
|
+
* message is not credited once per node it decrypts on. Used by both
|
|
649
|
+
* the pool-replay branch builder ({@link ForkRecovery}) and the tree-fed
|
|
650
|
+
* re-convergence pass, which gathers witnesses per retained fork-branch node.
|
|
651
|
+
*/
|
|
652
|
+
export declare function collectWitnessesAt<TEnvelope>(params: {
|
|
653
|
+
peeler: GroupPeeler<TEnvelope>;
|
|
654
|
+
ciphersuite: CiphersuiteImpl;
|
|
655
|
+
clientConfig?: ClientConfig;
|
|
656
|
+
state: ClientState;
|
|
657
|
+
witnessEnvelopes: TEnvelope[];
|
|
658
|
+
callback: IncomingMessageCallback;
|
|
659
|
+
}): Promise<AppWitness[]>;
|
|
660
|
+
/**
|
|
661
|
+
* {@link collectWitnessesAt} for application messages the history tree kept
|
|
662
|
+
* across a restart (`GroupHistoryTree#witnesses`): the tree holds the MLS
|
|
663
|
+
* message, not the transport envelope it arrived in, so there is nothing to
|
|
664
|
+
* peel — each message is processed against `state` directly.
|
|
665
|
+
*/
|
|
666
|
+
export declare function collectMessageWitnessesAt(params: {
|
|
667
|
+
ciphersuite: CiphersuiteImpl;
|
|
668
|
+
clientConfig?: ClientConfig;
|
|
669
|
+
state: ClientState;
|
|
670
|
+
witnessMessages: readonly MlsMessage[];
|
|
671
|
+
callback: IncomingMessageCallback;
|
|
672
|
+
}): Promise<AppWitness[]>;
|