@941design/marmot-engine 0.0.0-stage → 0.2.0-alpha.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/CHANGELOG.md +477 -0
- package/LICENSE +53 -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 +93 -0
- package/dist/core/components/ids.js +92 -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 +56 -0
- package/dist/core/group.js +95 -0
- package/dist/core/inbound.d.ts +102 -0
- package/dist/core/inbound.js +79 -0
- package/dist/core/index.d.ts +29 -0
- package/dist/core/index.js +27 -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 +117 -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 +66 -0
- package/dist/core/key-package.js +147 -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-profile.d.ts +262 -0
- package/dist/core/protocol-profile.js +535 -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 +75 -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 +5134 -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,651 @@
|
|
|
1
|
+
/** @module @category Engine */
|
|
2
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
|
|
3
|
+
import { decode, encode, mlsMessageDecoder, mlsMessageEncoder, } from "ts-mls";
|
|
4
|
+
import { BinaryReader, BinaryWriter } from "../core/binary.js";
|
|
5
|
+
import { deserializeClientState, serializeClientState, } from "../core/client-state.js";
|
|
6
|
+
import { commitDigest } from "../core/convergence.js";
|
|
7
|
+
import { decodeOwnCommitRecord, encodeOwnCommitRecord, } from "./own-commit-stamp.js";
|
|
8
|
+
/** Wire-format version byte for a persisted node-edge / meta record. */
|
|
9
|
+
const HISTORY_TREE_VERSION = 1;
|
|
10
|
+
/** Default number of heavy snapshots kept rehydrated in memory at once. */
|
|
11
|
+
const DEFAULT_SNAPSHOT_CACHE = 128;
|
|
12
|
+
const metaKey = (gid) => `${gid}/meta`;
|
|
13
|
+
const edgeKey = (gid, tag) => `${gid}/edge/${tag}`;
|
|
14
|
+
const stateKey = (gid, tag) => `${gid}/state/${tag}`;
|
|
15
|
+
const commitKey = (gid, tag) => `${gid}/commit/${tag}`;
|
|
16
|
+
const witnessKey = (gid, digest) => `${gid}/witness/${digest}`;
|
|
17
|
+
/**
|
|
18
|
+
* The retained group history tree (Marmot v2 full-fork history). Holds every
|
|
19
|
+
* group state ever observed — the canonical branch and every fork — as a tree
|
|
20
|
+
* of {@link ClientState} snapshots linked by commit edges. No pruning is
|
|
21
|
+
* performed: the tree retains everything.
|
|
22
|
+
*
|
|
23
|
+
* The **light index** (per-node epoch/parent/edge metadata) is always resident.
|
|
24
|
+
* **Heavy material** (serialized snapshots + commit bytes) is kept in a bounded
|
|
25
|
+
* in-memory LRU and otherwise fetched from a backing key-value store on demand,
|
|
26
|
+
* so memory stays bounded even as the tree grows without limit. Newly recorded
|
|
27
|
+
* nodes are pinned in memory until {@link flush} persists them.
|
|
28
|
+
*
|
|
29
|
+
* Snapshots are stored as bytes, never as live `ClientState` objects: ts-mls
|
|
30
|
+
* zeroes a parent state's consumed secrets in place when a commit is processed
|
|
31
|
+
* from it, so a retained live object could be corrupted out from under a
|
|
32
|
+
* sibling-branch replay. Re-deriving a state ({@link stateAt}) decodes a fresh,
|
|
33
|
+
* independent object every call.
|
|
34
|
+
*/
|
|
35
|
+
export class GroupHistoryTree {
|
|
36
|
+
/** The resident light index — node metadata, always in memory. */
|
|
37
|
+
#nodes = new Map();
|
|
38
|
+
/** Bounded LRU of heavy material; dirty (unflushed) entries are never evicted. */
|
|
39
|
+
#heavy = new Map();
|
|
40
|
+
/** Tags whose light + heavy material has not yet been flushed to the store. */
|
|
41
|
+
#dirty = new Set();
|
|
42
|
+
/** Max heavy entries kept resident (excluding pinned dirty entries). */
|
|
43
|
+
#cacheMax;
|
|
44
|
+
/** The root node tag, or `undefined` while the tree is empty. */
|
|
45
|
+
#rootTag;
|
|
46
|
+
/** Hex group id, derived from the root state; the persistence key prefix. */
|
|
47
|
+
#gid;
|
|
48
|
+
/** Whether the root pointer (meta) needs flushing. */
|
|
49
|
+
#rootDirty = false;
|
|
50
|
+
/** Backing store for heavy material, once bound. */
|
|
51
|
+
#store;
|
|
52
|
+
/** Delivered application messages kept as witness inputs, by digest. */
|
|
53
|
+
#witnesses = new Map();
|
|
54
|
+
/** Witness digests whose record has not yet been flushed. */
|
|
55
|
+
#witnessDirty = new Set();
|
|
56
|
+
/** Witness digests forgotten since the last flush (their record is removed from the store). */
|
|
57
|
+
#witnessGone = new Set();
|
|
58
|
+
/** Seeds an empty tree, optionally with a root {@link ClientState}. */
|
|
59
|
+
constructor(root, options) {
|
|
60
|
+
this.#cacheMax = options?.snapshotCacheSize ?? DEFAULT_SNAPSHOT_CACHE;
|
|
61
|
+
if (root)
|
|
62
|
+
this.setRoot(root);
|
|
63
|
+
}
|
|
64
|
+
/** The root node tag (the welcome/creation state), or `undefined` if empty. */
|
|
65
|
+
get rootTag() {
|
|
66
|
+
return this.#rootTag;
|
|
67
|
+
}
|
|
68
|
+
/** Number of nodes (states) retained in the tree. */
|
|
69
|
+
get size() {
|
|
70
|
+
return this.#nodes.size;
|
|
71
|
+
}
|
|
72
|
+
/** Oldest epoch still named by the tree, or `undefined` when it is empty. */
|
|
73
|
+
oldestEpoch() {
|
|
74
|
+
let oldest;
|
|
75
|
+
for (const node of this.#nodes.values())
|
|
76
|
+
if (oldest === undefined || node.epoch < oldest)
|
|
77
|
+
oldest = node.epoch;
|
|
78
|
+
return oldest;
|
|
79
|
+
}
|
|
80
|
+
/** Whether unflushed changes are pending. */
|
|
81
|
+
get isDirty() {
|
|
82
|
+
return (this.#dirty.size > 0 ||
|
|
83
|
+
this.#rootDirty ||
|
|
84
|
+
this.#witnessDirty.size > 0 ||
|
|
85
|
+
this.#witnessGone.size > 0);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Sets the root from a {@link ClientState}. The root carries no commit edge.
|
|
89
|
+
* Throws if a different root is already set (a tree has exactly one root).
|
|
90
|
+
*/
|
|
91
|
+
setRoot(state) {
|
|
92
|
+
const tag = bytesToHex(state.confirmationTag);
|
|
93
|
+
if (this.#rootTag !== undefined && this.#rootTag !== tag) {
|
|
94
|
+
throw new Error("GroupHistoryTree: root already set to a different node");
|
|
95
|
+
}
|
|
96
|
+
if (!this.#nodes.has(tag)) {
|
|
97
|
+
this.#nodes.set(tag, {
|
|
98
|
+
tag,
|
|
99
|
+
epoch: Number(state.groupContext.epoch),
|
|
100
|
+
childTags: [],
|
|
101
|
+
});
|
|
102
|
+
this.#putHeavy(tag, { snapshot: serializeClientState(state) });
|
|
103
|
+
this.#dirty.add(tag);
|
|
104
|
+
}
|
|
105
|
+
this.#rootTag = tag;
|
|
106
|
+
this.#gid = bytesToHex(state.groupContext.groupId);
|
|
107
|
+
this.#rootDirty = true;
|
|
108
|
+
return tag;
|
|
109
|
+
}
|
|
110
|
+
/** Whether a node with `tag` exists. */
|
|
111
|
+
hasNode(tag) {
|
|
112
|
+
return this.#nodes.has(tag);
|
|
113
|
+
}
|
|
114
|
+
/** Returns a read-only view of a node, or `undefined` if absent. */
|
|
115
|
+
node(tag) {
|
|
116
|
+
const n = this.#nodes.get(tag);
|
|
117
|
+
if (!n)
|
|
118
|
+
return undefined;
|
|
119
|
+
return {
|
|
120
|
+
tag: n.tag,
|
|
121
|
+
epoch: n.epoch,
|
|
122
|
+
parentTag: n.parentTag,
|
|
123
|
+
childTags: [...n.childTags],
|
|
124
|
+
edge: n.edge,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/** All node tags, in insertion order. */
|
|
128
|
+
tags() {
|
|
129
|
+
return [...this.#nodes.keys()];
|
|
130
|
+
}
|
|
131
|
+
/** The epoch of a node, or `undefined` if absent. */
|
|
132
|
+
epochOf(tag) {
|
|
133
|
+
return this.#nodes.get(tag)?.epoch;
|
|
134
|
+
}
|
|
135
|
+
/** The parent tag of a node, or `undefined` for the root / absent node. */
|
|
136
|
+
parentOf(tag) {
|
|
137
|
+
return this.#nodes.get(tag)?.parentTag;
|
|
138
|
+
}
|
|
139
|
+
/** Child tags of a node (empty for a tip or an absent node). */
|
|
140
|
+
childrenOf(tag) {
|
|
141
|
+
const n = this.#nodes.get(tag);
|
|
142
|
+
return n ? [...n.childTags] : [];
|
|
143
|
+
}
|
|
144
|
+
/** Whether a node is a tip (exists and has no children). */
|
|
145
|
+
isTip(tag) {
|
|
146
|
+
const n = this.#nodes.get(tag);
|
|
147
|
+
return n !== undefined && n.childTags.length === 0;
|
|
148
|
+
}
|
|
149
|
+
/** All tip tags (leaf states) — the candidate branches for convergence. */
|
|
150
|
+
tips() {
|
|
151
|
+
const out = [];
|
|
152
|
+
for (const n of this.#nodes.values())
|
|
153
|
+
if (n.childTags.length === 0)
|
|
154
|
+
out.push(n.tag);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
/** All node tags sitting at `epoch`. */
|
|
158
|
+
nodesAtEpoch(epoch) {
|
|
159
|
+
const out = [];
|
|
160
|
+
for (const n of this.#nodes.values())
|
|
161
|
+
if (n.epoch === epoch)
|
|
162
|
+
out.push(n.tag);
|
|
163
|
+
return out;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The path from the root to `tag` (inclusive of both), or `undefined` if the
|
|
167
|
+
* node is absent or its chain to the root is broken.
|
|
168
|
+
*/
|
|
169
|
+
path(tag) {
|
|
170
|
+
const out = [];
|
|
171
|
+
let cursor = tag;
|
|
172
|
+
const seen = new Set();
|
|
173
|
+
while (cursor !== undefined) {
|
|
174
|
+
if (seen.has(cursor))
|
|
175
|
+
return undefined; // cycle guard (should never happen)
|
|
176
|
+
seen.add(cursor);
|
|
177
|
+
const n = this.#nodes.get(cursor);
|
|
178
|
+
if (!n)
|
|
179
|
+
return undefined;
|
|
180
|
+
out.push(cursor);
|
|
181
|
+
cursor = n.parentTag;
|
|
182
|
+
}
|
|
183
|
+
out.reverse();
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
/** Ancestor tags of a node, nearest-first (excludes the node itself). */
|
|
187
|
+
ancestors(tag) {
|
|
188
|
+
const full = this.path(tag);
|
|
189
|
+
if (!full)
|
|
190
|
+
return [];
|
|
191
|
+
// path is root..tag; drop the node itself and reverse to nearest-first.
|
|
192
|
+
return full.slice(0, -1).reverse();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The lowest common ancestor of two nodes (the fork point), or `undefined` if
|
|
196
|
+
* they share no ancestor (e.g. live in different trees).
|
|
197
|
+
*/
|
|
198
|
+
lowestCommonAncestor(a, b) {
|
|
199
|
+
const pathA = this.path(a);
|
|
200
|
+
if (!pathA)
|
|
201
|
+
return undefined;
|
|
202
|
+
const ancestorsA = new Set(pathA);
|
|
203
|
+
let cursor = b;
|
|
204
|
+
while (cursor !== undefined) {
|
|
205
|
+
if (ancestorsA.has(cursor))
|
|
206
|
+
return cursor;
|
|
207
|
+
cursor = this.#nodes.get(cursor)?.parentTag;
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The serialized `ClientState` snapshot bytes for a node, or `undefined` if
|
|
213
|
+
* absent. Served from the in-memory cache, else fetched from the store.
|
|
214
|
+
*/
|
|
215
|
+
async snapshotOf(tag) {
|
|
216
|
+
if (!this.#nodes.has(tag))
|
|
217
|
+
return undefined;
|
|
218
|
+
const cached = this.#heavy.get(tag);
|
|
219
|
+
if (cached) {
|
|
220
|
+
this.#touch(tag);
|
|
221
|
+
return cached.snapshot;
|
|
222
|
+
}
|
|
223
|
+
if (!this.#store || !this.#gid)
|
|
224
|
+
return undefined;
|
|
225
|
+
const bytes = await this.#store.getItem(stateKey(this.#gid, tag));
|
|
226
|
+
if (!bytes)
|
|
227
|
+
return undefined;
|
|
228
|
+
this.#putHeavy(tag, { snapshot: bytes });
|
|
229
|
+
return bytes;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Rehydrates a node's state into a fresh, independent {@link ClientState}, or
|
|
233
|
+
* `undefined` if no snapshot is retained. Each call decodes a new object, so
|
|
234
|
+
* callers may mutate/advance it without affecting the tree.
|
|
235
|
+
*/
|
|
236
|
+
async stateAt(tag) {
|
|
237
|
+
const bytes = await this.snapshotOf(tag);
|
|
238
|
+
return bytes ? deserializeClientState(bytes) : undefined;
|
|
239
|
+
}
|
|
240
|
+
/** The serialized commit bytes that produced a node, or `undefined`. */
|
|
241
|
+
async commitBytesOf(childTag) {
|
|
242
|
+
const node = this.#nodes.get(childTag);
|
|
243
|
+
if (!node || !node.parentTag)
|
|
244
|
+
return undefined;
|
|
245
|
+
const cached = this.#heavy.get(childTag);
|
|
246
|
+
if (cached?.commit) {
|
|
247
|
+
this.#touch(childTag);
|
|
248
|
+
return decodeOwnCommitRecord(cached.commit).wireBytes;
|
|
249
|
+
}
|
|
250
|
+
if (!this.#store || !this.#gid)
|
|
251
|
+
return undefined;
|
|
252
|
+
// Fetched on demand (rare — for replay/debug); not cached, to avoid
|
|
253
|
+
// displacing a hot snapshot or polluting the LRU with commit-only entries.
|
|
254
|
+
const record = await this.#store.getItem(commitKey(this.#gid, childTag));
|
|
255
|
+
return record ? decodeOwnCommitRecord(record).wireBytes : undefined;
|
|
256
|
+
}
|
|
257
|
+
/** Confirmation-time evidence for a locally-authored commit, if stamped. */
|
|
258
|
+
async ownCommitStampOf(childTag) {
|
|
259
|
+
const node = this.#nodes.get(childTag);
|
|
260
|
+
if (!node || !node.parentTag)
|
|
261
|
+
return undefined;
|
|
262
|
+
const cached = this.#heavy.get(childTag)?.commit;
|
|
263
|
+
const record = cached ??
|
|
264
|
+
(this.#store && this.#gid
|
|
265
|
+
? await this.#store.getItem(commitKey(this.#gid, childTag))
|
|
266
|
+
: null);
|
|
267
|
+
if (!record)
|
|
268
|
+
return undefined;
|
|
269
|
+
const decoded = decodeOwnCommitRecord(record);
|
|
270
|
+
return decoded.kind === "stamped" ? decoded.stamp : undefined;
|
|
271
|
+
}
|
|
272
|
+
/** Decodes the commit `MlsMessage` that produced a node, or `undefined`. */
|
|
273
|
+
async commitMessageOf(childTag) {
|
|
274
|
+
const bytes = await this.commitBytesOf(childTag);
|
|
275
|
+
if (!bytes)
|
|
276
|
+
return undefined;
|
|
277
|
+
const message = decode(mlsMessageDecoder, bytes);
|
|
278
|
+
if (!message)
|
|
279
|
+
throw new Error("GroupHistoryTree: failed to decode commit message");
|
|
280
|
+
return message;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Records a commit applied from a retained parent node to its resulting child
|
|
284
|
+
* state, adding (or linking) the child node. Idempotent on the child tag: a
|
|
285
|
+
* duplicate commit re-links without overwriting. Throws if the parent is not
|
|
286
|
+
* already in the tree.
|
|
287
|
+
*
|
|
288
|
+
* @returns the child node tag.
|
|
289
|
+
*/
|
|
290
|
+
recordCommit(parentTag, commitMessage, childState, senderLeafIndex, ownCommitStamp) {
|
|
291
|
+
const parent = this.#nodes.get(parentTag);
|
|
292
|
+
if (!parent)
|
|
293
|
+
throw new Error(`GroupHistoryTree: parent ${parentTag.slice(0, 8)} not in tree`);
|
|
294
|
+
const childTag = bytesToHex(childState.confirmationTag);
|
|
295
|
+
const bytes = encode(mlsMessageEncoder, commitMessage);
|
|
296
|
+
const existing = this.#nodes.get(childTag);
|
|
297
|
+
if (!existing) {
|
|
298
|
+
this.#nodes.set(childTag, {
|
|
299
|
+
tag: childTag,
|
|
300
|
+
epoch: Number(childState.groupContext.epoch),
|
|
301
|
+
parentTag,
|
|
302
|
+
childTags: [],
|
|
303
|
+
edge: { commitDigest: commitDigest(bytes), senderLeafIndex },
|
|
304
|
+
});
|
|
305
|
+
this.#putHeavy(childTag, {
|
|
306
|
+
snapshot: serializeClientState(childState),
|
|
307
|
+
commit: ownCommitStamp
|
|
308
|
+
? encodeOwnCommitRecord({ wireBytes: bytes, stamp: ownCommitStamp })
|
|
309
|
+
: bytes,
|
|
310
|
+
});
|
|
311
|
+
this.#dirty.add(childTag);
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
if (existing.parentTag !== parentTag ||
|
|
315
|
+
!existing.edge ||
|
|
316
|
+
bytesToHex(existing.edge.commitDigest) !== bytesToHex(commitDigest(bytes)))
|
|
317
|
+
throw new Error("GroupHistoryTree: existing child has conflicting parent or commit");
|
|
318
|
+
// Confirmation can follow an earlier observation of the same edge. In
|
|
319
|
+
// that case preserve idempotence while upgrading the bare wire record to
|
|
320
|
+
// durable confirmation-time evidence. Never replace an existing stamp.
|
|
321
|
+
const cached = this.#heavy.get(childTag);
|
|
322
|
+
const decoded = cached?.commit
|
|
323
|
+
? decodeOwnCommitRecord(cached.commit)
|
|
324
|
+
: undefined;
|
|
325
|
+
if (ownCommitStamp && decoded?.kind === "legacy") {
|
|
326
|
+
this.#putHeavy(childTag, {
|
|
327
|
+
snapshot: cached.snapshot,
|
|
328
|
+
commit: encodeOwnCommitRecord({ wireBytes: bytes, stamp: ownCommitStamp }),
|
|
329
|
+
});
|
|
330
|
+
this.#dirty.add(childTag);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (!parent.childTags.includes(childTag))
|
|
334
|
+
parent.childTags.push(childTag);
|
|
335
|
+
return childTag;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Records an edge from a snapshot captured at branch-build time. Unlike
|
|
339
|
+
* {@link recordCommit}, the child snapshot is supplied pre-serialized — fork
|
|
340
|
+
* recovery serializes each branch state the instant it is produced, before
|
|
341
|
+
* ts-mls can zero that state's secrets when exploring its children. Idempotent
|
|
342
|
+
* on the child tag. Returns `false` (without recording) when the parent is not
|
|
343
|
+
* yet in the tree, so a batch can skip a dangling edge instead of throwing.
|
|
344
|
+
*/
|
|
345
|
+
recordEdge(edge) {
|
|
346
|
+
const parent = this.#nodes.get(edge.parentTag);
|
|
347
|
+
if (!parent)
|
|
348
|
+
return false;
|
|
349
|
+
if (!this.#nodes.has(edge.childTag)) {
|
|
350
|
+
this.#nodes.set(edge.childTag, {
|
|
351
|
+
tag: edge.childTag,
|
|
352
|
+
epoch: edge.childEpoch,
|
|
353
|
+
parentTag: edge.parentTag,
|
|
354
|
+
childTags: [],
|
|
355
|
+
edge: {
|
|
356
|
+
commitDigest: edge.commitDigest,
|
|
357
|
+
senderLeafIndex: edge.senderLeafIndex,
|
|
358
|
+
},
|
|
359
|
+
});
|
|
360
|
+
this.#putHeavy(edge.childTag, {
|
|
361
|
+
snapshot: edge.childSnapshot,
|
|
362
|
+
commit: edge.commitBytes,
|
|
363
|
+
});
|
|
364
|
+
this.#dirty.add(edge.childTag);
|
|
365
|
+
}
|
|
366
|
+
if (!parent.childTags.includes(edge.childTag))
|
|
367
|
+
parent.childTags.push(edge.childTag);
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Replaces a node's retained snapshot — used after staging a proposal onto a
|
|
372
|
+
* node, which updates its `unappliedProposals` without advancing the epoch.
|
|
373
|
+
* The new state's confirmation tag MUST equal the node tag (staging a proposal
|
|
374
|
+
* does not change it). Throws if the node is absent or the tag would change.
|
|
375
|
+
*/
|
|
376
|
+
updateSnapshot(tag, state) {
|
|
377
|
+
const node = this.#nodes.get(tag);
|
|
378
|
+
if (!node)
|
|
379
|
+
throw new Error(`GroupHistoryTree: cannot update absent node ${tag.slice(0, 8)}`);
|
|
380
|
+
const stateTag = bytesToHex(state.confirmationTag);
|
|
381
|
+
if (stateTag !== tag)
|
|
382
|
+
throw new Error("GroupHistoryTree: updateSnapshot would change the node identity");
|
|
383
|
+
const existing = this.#heavy.get(tag);
|
|
384
|
+
this.#putHeavy(tag, {
|
|
385
|
+
snapshot: serializeClientState(state),
|
|
386
|
+
commit: existing?.commit,
|
|
387
|
+
});
|
|
388
|
+
this.#dirty.add(tag);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Keeps a delivered application message as a witness input, persisted on the
|
|
392
|
+
* next {@link flush} and reloaded by {@link load}. Idempotent on the message.
|
|
393
|
+
*
|
|
394
|
+
* @returns the record digest.
|
|
395
|
+
*/
|
|
396
|
+
recordWitness(epoch, stateTag, message) {
|
|
397
|
+
const digest = bytesToHex(commitDigest(encode(mlsMessageEncoder, message)));
|
|
398
|
+
if (!this.#witnesses.has(digest)) {
|
|
399
|
+
this.#witnesses.set(digest, { digest, epoch, stateTag, message });
|
|
400
|
+
this.#witnessDirty.add(digest);
|
|
401
|
+
this.#witnessGone.delete(digest);
|
|
402
|
+
}
|
|
403
|
+
return digest;
|
|
404
|
+
}
|
|
405
|
+
/** The retained witness inputs, in the order they were recorded (loaded ones in key order). */
|
|
406
|
+
witnesses() {
|
|
407
|
+
return [...this.#witnesses.values()];
|
|
408
|
+
}
|
|
409
|
+
/** Forgets every witness input delivered below `epoch` (see the engine's `#pruneDelivered` for the bound). */
|
|
410
|
+
pruneWitnessesBelow(epoch) {
|
|
411
|
+
for (const witness of [...this.#witnesses.values()])
|
|
412
|
+
if (witness.epoch < epoch)
|
|
413
|
+
this.#forgetWitnessDigest(witness.digest);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Forgets the witness inputs a rewind abandons: those delivered strictly
|
|
417
|
+
* after `forkEpoch` on a state outside `canonicalTags` (the same rule as the
|
|
418
|
+
* delivered-payload ledger's `invalidatedByRewind`).
|
|
419
|
+
*/
|
|
420
|
+
invalidateWitnessesByRewind(forkEpoch, canonicalTags) {
|
|
421
|
+
for (const witness of [...this.#witnesses.values()])
|
|
422
|
+
if (witness.epoch > forkEpoch && !canonicalTags.has(witness.stateTag))
|
|
423
|
+
this.#forgetWitnessDigest(witness.digest);
|
|
424
|
+
}
|
|
425
|
+
#forgetWitnessDigest(digest) {
|
|
426
|
+
if (!this.#witnesses.delete(digest))
|
|
427
|
+
return;
|
|
428
|
+
this.#witnessDirty.delete(digest);
|
|
429
|
+
this.#witnessGone.add(digest);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Binds a backing store to a fresh, in-memory tree so its nodes can be flushed
|
|
433
|
+
* and its heavy material later evicted/reloaded. Marks every current node
|
|
434
|
+
* dirty so the first {@link flush} persists the whole tree. A no-op if the
|
|
435
|
+
* same store is already bound (e.g. on a tree loaded via {@link load}).
|
|
436
|
+
*/
|
|
437
|
+
bindStore(store) {
|
|
438
|
+
if (this.#store === store)
|
|
439
|
+
return;
|
|
440
|
+
this.#store = store;
|
|
441
|
+
this.#rootDirty = true;
|
|
442
|
+
for (const tag of this.#nodes.keys())
|
|
443
|
+
this.#dirty.add(tag);
|
|
444
|
+
for (const digest of this.#witnesses.keys())
|
|
445
|
+
this.#witnessDirty.add(digest);
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Persists all unflushed nodes incrementally: each dirty node's light edge
|
|
449
|
+
* record, snapshot, and commit bytes are written under its own keys, plus the
|
|
450
|
+
* meta (root) record. Append-only — already-persisted nodes are untouched, so
|
|
451
|
+
* a save costs O(new nodes), not O(tree). Requires a bound store.
|
|
452
|
+
*/
|
|
453
|
+
async flush() {
|
|
454
|
+
if (!this.#store || !this.#gid)
|
|
455
|
+
throw new Error("GroupHistoryTree: flush requires a bound store");
|
|
456
|
+
const gid = this.#gid;
|
|
457
|
+
for (const tag of this.#dirty) {
|
|
458
|
+
const node = this.#nodes.get(tag);
|
|
459
|
+
const heavy = this.#heavy.get(tag);
|
|
460
|
+
if (!node || !heavy)
|
|
461
|
+
continue;
|
|
462
|
+
await this.#store.setItem(edgeKey(gid, tag), encodeEdgeRecord(node));
|
|
463
|
+
await this.#store.setItem(stateKey(gid, tag), heavy.snapshot);
|
|
464
|
+
if (node.parentTag && heavy.commit)
|
|
465
|
+
await this.#store.setItem(commitKey(gid, tag), heavy.commit);
|
|
466
|
+
}
|
|
467
|
+
for (const digest of this.#witnessDirty) {
|
|
468
|
+
const witness = this.#witnesses.get(digest);
|
|
469
|
+
if (witness)
|
|
470
|
+
await this.#store.setItem(witnessKey(gid, digest), encodeWitnessRecord(witness));
|
|
471
|
+
}
|
|
472
|
+
for (const digest of this.#witnessGone)
|
|
473
|
+
await this.#store.removeItem(witnessKey(gid, digest));
|
|
474
|
+
this.#witnessDirty.clear();
|
|
475
|
+
this.#witnessGone.clear();
|
|
476
|
+
if (this.#rootDirty && this.#rootTag) {
|
|
477
|
+
await this.#store.setItem(metaKey(gid), encodeMeta(this.#rootTag));
|
|
478
|
+
this.#rootDirty = false;
|
|
479
|
+
}
|
|
480
|
+
this.#dirty.clear();
|
|
481
|
+
// Flushed entries are now clean and may be evicted under cache pressure.
|
|
482
|
+
this.#evict();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Loads a tree's light index from a store (heavy material stays lazy). Returns
|
|
486
|
+
* `undefined` if no tree is persisted under `gid`. The store stays bound, so
|
|
487
|
+
* snapshots/commit bytes are fetched on demand.
|
|
488
|
+
*/
|
|
489
|
+
static async load(store, gid, options) {
|
|
490
|
+
const metaBytes = await store.getItem(metaKey(gid));
|
|
491
|
+
if (!metaBytes)
|
|
492
|
+
return undefined;
|
|
493
|
+
const rootTag = decodeMeta(metaBytes);
|
|
494
|
+
const tree = new GroupHistoryTree(undefined, options);
|
|
495
|
+
tree.#store = store;
|
|
496
|
+
tree.#gid = gid;
|
|
497
|
+
const prefix = `${gid}/edge/`;
|
|
498
|
+
const keys = await store.keys();
|
|
499
|
+
for (const key of keys) {
|
|
500
|
+
if (!key.startsWith(prefix))
|
|
501
|
+
continue;
|
|
502
|
+
const tag = key.slice(prefix.length);
|
|
503
|
+
const bytes = await store.getItem(key);
|
|
504
|
+
if (!bytes)
|
|
505
|
+
continue;
|
|
506
|
+
const rec = decodeEdgeRecord(bytes);
|
|
507
|
+
tree.#nodes.set(tag, {
|
|
508
|
+
tag,
|
|
509
|
+
epoch: rec.epoch,
|
|
510
|
+
parentTag: rec.parentTag,
|
|
511
|
+
childTags: [],
|
|
512
|
+
edge: rec.edge,
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
for (const node of tree.#nodes.values()) {
|
|
516
|
+
if (node.parentTag)
|
|
517
|
+
tree.#nodes.get(node.parentTag)?.childTags.push(node.tag);
|
|
518
|
+
}
|
|
519
|
+
const witnessPrefix = `${gid}/witness/`;
|
|
520
|
+
for (const key of keys) {
|
|
521
|
+
if (!key.startsWith(witnessPrefix))
|
|
522
|
+
continue;
|
|
523
|
+
const bytes = await store.getItem(key);
|
|
524
|
+
if (!bytes)
|
|
525
|
+
continue;
|
|
526
|
+
const digest = key.slice(witnessPrefix.length);
|
|
527
|
+
// Witnesses are best-effort evidence: a record that does not decode is
|
|
528
|
+
// dropped (and removed from the store by the next flush), never fatal
|
|
529
|
+
// to the tree.
|
|
530
|
+
try {
|
|
531
|
+
tree.#witnesses.set(digest, decodeWitnessRecord(digest, bytes));
|
|
532
|
+
}
|
|
533
|
+
catch {
|
|
534
|
+
tree.#witnessGone.add(digest);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
tree.#rootTag = rootTag;
|
|
538
|
+
// Loaded nodes are already persisted — nothing dirty.
|
|
539
|
+
return tree;
|
|
540
|
+
}
|
|
541
|
+
/** Removes every persisted key for a group's tree from the store. */
|
|
542
|
+
static async purge(store, gid) {
|
|
543
|
+
const prefix = `${gid}/`;
|
|
544
|
+
const keys = await store.keys();
|
|
545
|
+
for (const key of keys) {
|
|
546
|
+
if (key === metaKey(gid) || key.startsWith(prefix))
|
|
547
|
+
await store.removeItem(key);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
/** Inserts/refreshes a heavy entry at the LRU tail, then evicts if needed. */
|
|
551
|
+
#putHeavy(tag, entry) {
|
|
552
|
+
this.#heavy.delete(tag);
|
|
553
|
+
this.#heavy.set(tag, entry);
|
|
554
|
+
this.#evict();
|
|
555
|
+
}
|
|
556
|
+
/** Moves a heavy entry to the LRU tail (most-recently-used). */
|
|
557
|
+
#touch(tag) {
|
|
558
|
+
const entry = this.#heavy.get(tag);
|
|
559
|
+
if (!entry)
|
|
560
|
+
return;
|
|
561
|
+
this.#heavy.delete(tag);
|
|
562
|
+
this.#heavy.set(tag, entry);
|
|
563
|
+
}
|
|
564
|
+
/** Evicts clean (flushed) heavy entries oldest-first until within the cap. */
|
|
565
|
+
#evict() {
|
|
566
|
+
if (this.#heavy.size <= this.#cacheMax)
|
|
567
|
+
return;
|
|
568
|
+
for (const tag of this.#heavy.keys()) {
|
|
569
|
+
if (this.#heavy.size <= this.#cacheMax)
|
|
570
|
+
break;
|
|
571
|
+
if (this.#dirty.has(tag))
|
|
572
|
+
continue; // never evict unflushed material
|
|
573
|
+
this.#heavy.delete(tag);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/** Encodes a node's light edge record (everything but the heavy material). */
|
|
578
|
+
function encodeEdgeRecord(node) {
|
|
579
|
+
const w = new BinaryWriter().uint8(HISTORY_TREE_VERSION).varint(node.epoch);
|
|
580
|
+
w.opaque(node.parentTag ? hexToBytes(node.parentTag) : new Uint8Array());
|
|
581
|
+
if (node.parentTag) {
|
|
582
|
+
w.opaque(node.edge?.commitDigest ?? new Uint8Array());
|
|
583
|
+
if (node.edge?.senderLeafIndex !== undefined) {
|
|
584
|
+
w.uint8(1).varint(node.edge.senderLeafIndex);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
w.uint8(0);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
return w.build();
|
|
591
|
+
}
|
|
592
|
+
/** Decodes a light edge record into its node fields. */
|
|
593
|
+
function decodeEdgeRecord(bytes) {
|
|
594
|
+
const r = new BinaryReader(bytes);
|
|
595
|
+
const version = r.uint8();
|
|
596
|
+
if (version !== HISTORY_TREE_VERSION)
|
|
597
|
+
throw new Error(`GroupHistoryTree: unknown edge record version ${version}`);
|
|
598
|
+
const epoch = r.varint();
|
|
599
|
+
const parentBytes = r.opaque();
|
|
600
|
+
const parentTag = parentBytes.length ? bytesToHex(parentBytes) : undefined;
|
|
601
|
+
let edge;
|
|
602
|
+
if (parentTag) {
|
|
603
|
+
const commitDigestBytes = r.opaque();
|
|
604
|
+
const senderPresent = r.uint8();
|
|
605
|
+
const senderLeafIndex = senderPresent ? r.varint() : undefined;
|
|
606
|
+
edge = { commitDigest: commitDigestBytes, senderLeafIndex };
|
|
607
|
+
}
|
|
608
|
+
r.end();
|
|
609
|
+
return { epoch, parentTag, edge };
|
|
610
|
+
}
|
|
611
|
+
/** Encodes a witness input record: the delivery state's identity and the message. */
|
|
612
|
+
function encodeWitnessRecord(witness) {
|
|
613
|
+
return new BinaryWriter()
|
|
614
|
+
.uint8(HISTORY_TREE_VERSION)
|
|
615
|
+
.varint(witness.epoch)
|
|
616
|
+
.opaque(hexToBytes(witness.stateTag))
|
|
617
|
+
.opaque(encode(mlsMessageEncoder, witness.message))
|
|
618
|
+
.build();
|
|
619
|
+
}
|
|
620
|
+
/** Decodes a witness input record stored under `digest`. */
|
|
621
|
+
function decodeWitnessRecord(digest, bytes) {
|
|
622
|
+
const r = new BinaryReader(bytes);
|
|
623
|
+
const version = r.uint8();
|
|
624
|
+
if (version !== HISTORY_TREE_VERSION)
|
|
625
|
+
throw new Error(`GroupHistoryTree: unknown witness record version ${version}`);
|
|
626
|
+
const epoch = r.varint();
|
|
627
|
+
const stateTag = bytesToHex(r.opaque());
|
|
628
|
+
const messageBytes = r.opaque();
|
|
629
|
+
r.end();
|
|
630
|
+
const message = decode(mlsMessageDecoder, messageBytes);
|
|
631
|
+
if (!message)
|
|
632
|
+
throw new Error("GroupHistoryTree: failed to decode witness message");
|
|
633
|
+
return { digest, epoch, stateTag, message };
|
|
634
|
+
}
|
|
635
|
+
/** Encodes the meta record (the root tag pointer). */
|
|
636
|
+
function encodeMeta(rootTag) {
|
|
637
|
+
return new BinaryWriter()
|
|
638
|
+
.uint8(HISTORY_TREE_VERSION)
|
|
639
|
+
.opaque(hexToBytes(rootTag))
|
|
640
|
+
.build();
|
|
641
|
+
}
|
|
642
|
+
/** Decodes the meta record into the root tag. */
|
|
643
|
+
function decodeMeta(bytes) {
|
|
644
|
+
const r = new BinaryReader(bytes);
|
|
645
|
+
const version = r.uint8();
|
|
646
|
+
if (version !== HISTORY_TREE_VERSION)
|
|
647
|
+
throw new Error(`GroupHistoryTree: unknown meta version ${version}`);
|
|
648
|
+
const rootBytes = r.opaque();
|
|
649
|
+
r.end();
|
|
650
|
+
return rootBytes.length ? bytesToHex(rootBytes) : undefined;
|
|
651
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** @module @category Engine */
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
export * from "./state-notifications.js";
|
|
4
|
+
export * from "./history-tree.js";
|
|
5
|
+
export * from "./admin-policy.js";
|
|
6
|
+
export * from "./ingest-disposition.js";
|
|
7
|
+
export * from "./retained-store.js";
|
|
8
|
+
export * from "./own-commit-stamp.js";
|
|
9
|
+
export * from "./ingestion-pool.js";
|
|
10
|
+
export * from "./fork-recovery.js";
|
|
11
|
+
export * from "./ingest.js";
|
|
12
|
+
export * from "./group-engine.js";
|
|
13
|
+
export * from "./auto-committer.js";
|
|
14
|
+
export * from "./disband-request.js";
|
|
15
|
+
export * from "./sender-ratchet.js";
|
|
16
|
+
export type { GenericKeyValueStore } from "../utils/key-value.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @module @category Engine */
|
|
2
|
+
export * from "./types.js";
|
|
3
|
+
export * from "./state-notifications.js";
|
|
4
|
+
export * from "./history-tree.js";
|
|
5
|
+
export * from "./admin-policy.js";
|
|
6
|
+
export * from "./ingest-disposition.js";
|
|
7
|
+
export * from "./retained-store.js";
|
|
8
|
+
export * from "./own-commit-stamp.js";
|
|
9
|
+
export * from "./ingestion-pool.js";
|
|
10
|
+
export * from "./fork-recovery.js";
|
|
11
|
+
export * from "./ingest.js";
|
|
12
|
+
export * from "./group-engine.js";
|
|
13
|
+
export * from "./auto-committer.js";
|
|
14
|
+
export * from "./disband-request.js";
|
|
15
|
+
export * from "./sender-ratchet.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** @module @category Engine */
|
|
2
|
+
import { type Disposition } from "../core/inbound.js";
|
|
3
|
+
import type { IngestResult } from "./types.js";
|
|
4
|
+
/** Maps an {@link IngestResult} to its protocol-visible {@link Disposition}. */
|
|
5
|
+
export declare function ingestResultDisposition<TEnvelope>(result: IngestResult<TEnvelope>): Disposition;
|