@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.
Files changed (196) hide show
  1. package/CHANGELOG.md +434 -0
  2. package/LICENSE +49 -0
  3. package/README.md +33 -2
  4. package/dist/audit/emitter.d.ts +17 -0
  5. package/dist/audit/emitter.js +30 -0
  6. package/dist/audit/helpers.d.ts +16 -0
  7. package/dist/audit/helpers.js +103 -0
  8. package/dist/audit/index.d.ts +6 -0
  9. package/dist/audit/index.js +6 -0
  10. package/dist/audit/recorder.d.ts +13 -0
  11. package/dist/audit/recorder.js +24 -0
  12. package/dist/audit/sink.d.ts +16 -0
  13. package/dist/audit/sink.js +27 -0
  14. package/dist/audit/types-internal.d.ts +7 -0
  15. package/dist/audit/types-internal.js +1 -0
  16. package/dist/audit/types.d.ts +289 -0
  17. package/dist/audit/types.js +2 -0
  18. package/dist/core/account-identity-proof.d.ts +165 -0
  19. package/dist/core/account-identity-proof.js +277 -0
  20. package/dist/core/application-rumor.d.ts +45 -0
  21. package/dist/core/application-rumor.js +120 -0
  22. package/dist/core/auth-service.d.ts +2 -0
  23. package/dist/core/auth-service.js +52 -0
  24. package/dist/core/binary.d.ts +142 -0
  25. package/dist/core/binary.js +363 -0
  26. package/dist/core/capabilities.d.ts +51 -0
  27. package/dist/core/capabilities.js +102 -0
  28. package/dist/core/client-state.d.ts +119 -0
  29. package/dist/core/client-state.js +226 -0
  30. package/dist/core/commit-authorization.d.ts +26 -0
  31. package/dist/core/commit-authorization.js +26 -0
  32. package/dist/core/components/admin-policy.d.ts +4 -0
  33. package/dist/core/components/admin-policy.js +69 -0
  34. package/dist/core/components/agent-text-stream.d.ts +51 -0
  35. package/dist/core/components/agent-text-stream.js +112 -0
  36. package/dist/core/components/app-components-list.d.ts +17 -0
  37. package/dist/core/components/app-components-list.js +35 -0
  38. package/dist/core/components/avatar-url.d.ts +12 -0
  39. package/dist/core/components/avatar-url.js +85 -0
  40. package/dist/core/components/bytes.d.ts +5 -0
  41. package/dist/core/components/bytes.js +18 -0
  42. package/dist/core/components/dictionary.d.ts +80 -0
  43. package/dist/core/components/dictionary.js +175 -0
  44. package/dist/core/components/disband-validation.d.ts +21 -0
  45. package/dist/core/components/disband-validation.js +173 -0
  46. package/dist/core/components/encrypted-media.d.ts +44 -0
  47. package/dist/core/components/encrypted-media.js +210 -0
  48. package/dist/core/components/group-lifecycle.d.ts +10 -0
  49. package/dist/core/components/group-lifecycle.js +32 -0
  50. package/dist/core/components/group-profile.d.ts +24 -0
  51. package/dist/core/components/group-profile.js +35 -0
  52. package/dist/core/components/host-safety.d.ts +9 -0
  53. package/dist/core/components/host-safety.js +148 -0
  54. package/dist/core/components/ids.d.ts +74 -0
  55. package/dist/core/components/ids.js +73 -0
  56. package/dist/core/components/index.d.ts +14 -0
  57. package/dist/core/components/index.js +14 -0
  58. package/dist/core/components/integrity.d.ts +141 -0
  59. package/dist/core/components/integrity.js +293 -0
  60. package/dist/core/components/message-retention.d.ts +17 -0
  61. package/dist/core/components/message-retention.js +26 -0
  62. package/dist/core/components/nostr-routing.d.ts +8 -0
  63. package/dist/core/components/nostr-routing.js +92 -0
  64. package/dist/core/components/url.d.ts +26 -0
  65. package/dist/core/components/url.js +44 -0
  66. package/dist/core/convergence-status.d.ts +84 -0
  67. package/dist/core/convergence-status.js +82 -0
  68. package/dist/core/convergence.d.ts +567 -0
  69. package/dist/core/convergence.js +1150 -0
  70. package/dist/core/credential.d.ts +16 -0
  71. package/dist/core/credential.js +64 -0
  72. package/dist/core/default-capabilities.d.ts +9 -0
  73. package/dist/core/default-capabilities.js +34 -0
  74. package/dist/core/extensions.d.ts +9 -0
  75. package/dist/core/extensions.js +5 -0
  76. package/dist/core/grease.d.ts +2 -0
  77. package/dist/core/grease.js +6 -0
  78. package/dist/core/group-event.d.ts +18 -0
  79. package/dist/core/group-event.js +30 -0
  80. package/dist/core/group-lifecycle.d.ts +42 -0
  81. package/dist/core/group-lifecycle.js +66 -0
  82. package/dist/core/group-members.d.ts +37 -0
  83. package/dist/core/group-members.js +99 -0
  84. package/dist/core/group-message-classify.d.ts +42 -0
  85. package/dist/core/group-message-classify.js +57 -0
  86. package/dist/core/group-message-crypto.d.ts +53 -0
  87. package/dist/core/group-message-crypto.js +140 -0
  88. package/dist/core/group-message.d.ts +5 -0
  89. package/dist/core/group-message.js +11 -0
  90. package/dist/core/group.d.ts +45 -0
  91. package/dist/core/group.js +78 -0
  92. package/dist/core/inbound.d.ts +102 -0
  93. package/dist/core/inbound.js +79 -0
  94. package/dist/core/index.d.ts +28 -0
  95. package/dist/core/index.js +26 -0
  96. package/dist/core/key-package-eligibility.d.ts +31 -0
  97. package/dist/core/key-package-eligibility.js +116 -0
  98. package/dist/core/key-package-event-decode.d.ts +43 -0
  99. package/dist/core/key-package-event-decode.js +118 -0
  100. package/dist/core/key-package-event-delete.d.ts +16 -0
  101. package/dist/core/key-package-event-delete.js +46 -0
  102. package/dist/core/key-package-event-encode.d.ts +28 -0
  103. package/dist/core/key-package-event-encode.js +102 -0
  104. package/dist/core/key-package-event.d.ts +4 -0
  105. package/dist/core/key-package-event.js +8 -0
  106. package/dist/core/key-package.d.ts +55 -0
  107. package/dist/core/key-package.js +115 -0
  108. package/dist/core/leaf-succession.d.ts +83 -0
  109. package/dist/core/leaf-succession.js +97 -0
  110. package/dist/core/media/canonical.d.ts +34 -0
  111. package/dist/core/media/canonical.js +57 -0
  112. package/dist/core/media/crypto.d.ts +79 -0
  113. package/dist/core/media/crypto.js +215 -0
  114. package/dist/core/media/imeta.d.ts +33 -0
  115. package/dist/core/media/imeta.js +188 -0
  116. package/dist/core/media/locator.d.ts +44 -0
  117. package/dist/core/media/locator.js +69 -0
  118. package/dist/core/media/types.d.ts +83 -0
  119. package/dist/core/media/types.js +12 -0
  120. package/dist/core/media.d.ts +6 -0
  121. package/dist/core/media.js +12 -0
  122. package/dist/core/protocol.d.ts +51 -0
  123. package/dist/core/protocol.js +41 -0
  124. package/dist/core/relay-lists.d.ts +52 -0
  125. package/dist/core/relay-lists.js +86 -0
  126. package/dist/core/retained-history.d.ts +78 -0
  127. package/dist/core/retained-history.js +59 -0
  128. package/dist/core/transport.d.ts +43 -0
  129. package/dist/core/transport.js +21 -0
  130. package/dist/core/welcome-event.d.ts +61 -0
  131. package/dist/core/welcome-event.js +116 -0
  132. package/dist/core/welcome-join.d.ts +155 -0
  133. package/dist/core/welcome-join.js +243 -0
  134. package/dist/core/welcome.d.ts +3 -0
  135. package/dist/core/welcome.js +6 -0
  136. package/dist/engine/admin-policy.d.ts +58 -0
  137. package/dist/engine/admin-policy.js +137 -0
  138. package/dist/engine/auto-committer.d.ts +39 -0
  139. package/dist/engine/auto-committer.js +42 -0
  140. package/dist/engine/delivered-payloads.d.ts +61 -0
  141. package/dist/engine/delivered-payloads.js +84 -0
  142. package/dist/engine/disband-request.d.ts +41 -0
  143. package/dist/engine/disband-request.js +86 -0
  144. package/dist/engine/disband-tombstone.d.ts +14 -0
  145. package/dist/engine/disband-tombstone.js +66 -0
  146. package/dist/engine/fork-recovery.d.ts +672 -0
  147. package/dist/engine/fork-recovery.js +1615 -0
  148. package/dist/engine/group-engine.d.ts +571 -0
  149. package/dist/engine/group-engine.js +5112 -0
  150. package/dist/engine/history-tree.d.ts +232 -0
  151. package/dist/engine/history-tree.js +651 -0
  152. package/dist/engine/index.d.ts +16 -0
  153. package/dist/engine/index.js +15 -0
  154. package/dist/engine/ingest-disposition.d.ts +5 -0
  155. package/dist/engine/ingest-disposition.js +63 -0
  156. package/dist/engine/ingest.d.ts +390 -0
  157. package/dist/engine/ingest.js +1258 -0
  158. package/dist/engine/ingestion-pool.d.ts +74 -0
  159. package/dist/engine/ingestion-pool.js +95 -0
  160. package/dist/engine/message-dedup.d.ts +16 -0
  161. package/dist/engine/message-dedup.js +20 -0
  162. package/dist/engine/own-commit-stamp.d.ts +30 -0
  163. package/dist/engine/own-commit-stamp.js +71 -0
  164. package/dist/engine/retained-store.d.ts +79 -0
  165. package/dist/engine/retained-store.js +133 -0
  166. package/dist/engine/sender-ratchet.d.ts +50 -0
  167. package/dist/engine/sender-ratchet.js +196 -0
  168. package/dist/engine/state-notifications.d.ts +122 -0
  169. package/dist/engine/state-notifications.js +173 -0
  170. package/dist/engine/tree-convergence.d.ts +41 -0
  171. package/dist/engine/tree-convergence.js +90 -0
  172. package/dist/engine/types.d.ts +366 -0
  173. package/dist/engine/types.js +14 -0
  174. package/dist/engine/wire-format.d.ts +77 -0
  175. package/dist/engine/wire-format.js +120 -0
  176. package/dist/index.d.ts +12 -0
  177. package/dist/index.js +1 -0
  178. package/dist/mls.d.ts +11 -0
  179. package/dist/mls.js +11 -0
  180. package/dist/utils/debug.d.ts +3 -0
  181. package/dist/utils/debug.js +3 -0
  182. package/dist/utils/encoding.d.ts +38 -0
  183. package/dist/utils/encoding.js +91 -0
  184. package/dist/utils/key-value.d.ts +18 -0
  185. package/dist/utils/key-value.js +2 -0
  186. package/dist/utils/nostr.d.ts +35 -0
  187. package/dist/utils/nostr.js +26 -0
  188. package/dist/utils/relay-url.d.ts +10 -0
  189. package/dist/utils/relay-url.js +23 -0
  190. package/dist/utils/tag-cardinality.d.ts +50 -0
  191. package/dist/utils/tag-cardinality.js +91 -0
  192. package/dist/utils/timestamp.d.ts +50 -0
  193. package/dist/utils/timestamp.js +95 -0
  194. package/dist/version.d.ts +112 -0
  195. package/dist/version.js +112 -0
  196. package/package.json +68 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,434 @@
1
+ # @941design/marmot-engine
2
+
3
+ ## 0.2.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c425a58: The engine stamp stored envelopes are compared against is now a stored-state format, `ENGINE_VERSION = "state.<N>"`
8
+ (`ENGINE_STATE_FORMAT`), instead of a digest of the engine code; the code identity moves to the new `ENGINE_BUILD`.
9
+ Engine changes that leave stored state reading the same (a comment, a read-only accessor) no longer refuse every store;
10
+ `state-format-ledger.json` and a test force a recorded decision on each code change.
11
+ This change itself moves the stamp once: stores written by earlier builds are refused with `storeIncompatible`.
12
+ - 5ee090c: Branch-aware own-leaf fence: a commit of the device's own leaf
13
+ that it cannot open is fenced only whenever the opaque branch could win.
14
+
15
+ Until now a restored device that met a commit of its own leaf it could not process (ts-mls's "No overlap between
16
+ provided private keys and update path", `isLostPathSecretsError`) was fenced at once, wherever it met it. Behind the
17
+ new seam option `MarmotGroupEngineOptions.branchAwareFence` (and `ForkRecovery`'s), off by default and effective only
18
+ together with `equivocationCredit` (with either off every result is byte for byte the previous one), the unreadable
19
+ commit is an *opaque candidate* decided against the processable branches. Its best case `o*` — the candidate's own
20
+ head edge, up to `U` hidden edges below it (`U` is the group's undecryptable count, see below), the hidden credit the
21
+ policy allows and the minimal tiebreak bytes — is scored by the unchanged credited cascade, appended last so an exact
22
+ tie goes to the opaque side; the group is fenced (`unreadable`, carrying a lost-path-secrets error) iff `o*` could
23
+ win, or no processable branch is eligible (a sole member stays fenced). Otherwise the digest is `skipped`
24
+ (`past-epoch`) and held. The decision is taken per digest, at the pool-replay, direct-apply, removal-parent and
25
+ tree-sweep sites alike, and again on every later convergence pass (a later arrival, a larger `U`, a pending own
26
+ commit that confirms), within the rollback horizon (`maxRewindCommits`; leaving it drops the candidate without a
27
+ fence, a pruned parent fences it).
28
+
29
+ - **Conservative hidden-credit policy, pending a decision.** `MarmotGroupEngineOptions.hiddenCreditPolicy` is exactly
30
+ `"conservative"` (the default: the hidden subtree may carry up to `U` credit) or `"anchored-zero"` (an opaque head by
31
+ the device's own leaf, anchored at its parent node, earns no hidden credit there); any other value is a `TypeError`
32
+ at construction while the seam is on, and it is ignored otherwise. The product question which one `@941design/marmot`
33
+ ships is unanswered: under the shipped conservative policy a deliberate attacker's burst from a cloned leaf
34
+ still fences the real device.
35
+ - **The record.** New getter `opaque` and constructor option `opaque` (a `HeldOpaqueRecord`: the held candidates —
36
+ digest, parent tag, epoch, sender, error message, original envelope; at most `MAX_HELD_OPAQUE_CANDIDATES = 16`, the
37
+ overflow fences, candidates sharing a parent node and sender are scored once at their best case — and the
38
+ `undecryptableIds`, `U`), a new object on every change; a malformed record is rejected with `OpaqueRecordInvalid`
39
+ (a `TypeError`). `U` counts the distinct ids of group envelopes that no state the device holds opens and leaves only
40
+ when one decrypts; it is a function of the received set, never of arrival order or `created_at`.
41
+ - **Pure core.** New exports `OpaqueCandidate`, `HiddenCreditPolicy`, `opaqueBestCase`, `opaqueCouldWin` and
42
+ `selectCanonicalBranchWithOpaque`; `ForkResolution` / `AppliedForkResolution` gain `opaqueSkipped` and `opaqueHeld`
43
+ (omitted when empty, never an empty set) and a `skip` outcome now carries the `leafEquivocation` report it used to
44
+ drop.
45
+ - **Batch settle.** `MarmotGroupEngine.ingest(envelopes, { settle?: boolean })`: `settle: false` says more
46
+ envelopes of the caller's batch follow. A deferred call fences nothing that could still be outdone: a could-win
47
+ candidate is held (`skipped`, provisional) at every site, and a call with `settle` unset — an empty `ingest([])`
48
+ suffices — decides it against everything the batch brought. An unavailable parent, an unverified record and a full
49
+ held set still fence at once. The option is ignored with the seam off. `ForkRecovery.resolveFork` takes the
50
+ matching `holdCouldWin` (a deferred replay reports a could-win digest in `opaqueSkipped` with its `opaqueHeld`
51
+ info instead of `fenced`). A decision is therefore taken on the whole batch, whatever the order of the commits in
52
+ it; across separately settled batches it is the whole-batch decision over everything received up to that settle,
53
+ and a fence is terminal.
54
+ - **`send` settles first.** With the seam on, every send path (application message, proposal, commit, self-update,
55
+ invite) first runs the full decision for an open unsettled batch and for any held candidate — the one
56
+ `ingest([])` runs, without the pool passes. A candidate that could win rejects the send with its lost-path-secrets
57
+ error (which a client turns into its fence) and nothing is created. While an own commit is pending nothing is
58
+ decided: a commit or self-update refuses as before, an application message or proposal refuses while a candidate
59
+ is held, and the next send decides. A deferred `ingest` step with a candidate held also postpones the elected auto-commit of pending
60
+ self-removes to the settling call (any later non-deferred ingest covers a batch that never settles). An unsettled batch (a `settle: false` call
61
+ with no settling call after it) is an engine state: only a settling call closes it, and the entry points that act
62
+ (`send`, `driveConvergence`, `reconvergeFromHistory`) decide in full, so an interleaved entry point can fence more,
63
+ never less; the deferral is an explicit argument of the deferred call's own body, never instance state, so an entry point that interleaves — even while the deferred call awaits inside the peeler — decides in full.
64
+ - **Further exports** (the barrels re-export every module, so these are public though meant for the seam's callers
65
+ and tests): `decideOpaqueDrafts` and `OpaqueDraft` (the one per-digest decision both pool replay and the tree-fed
66
+ sites call), `normalizeHiddenCreditPolicy` and `DEFAULT_HIDDEN_CREDIT_POLICY`, `reconstructLostPathSecretsError`
67
+ (a real ts-mls error rebuilt from a record's message, so `isLostPathSecretsError` holds), `OpaqueFromEncrypted`,
68
+ `OpaqueHeldInfo`, the `ForkResolution` / `AppliedForkResolution` keys `opaqueEncrypted` and `opaqueTipEnvelope`,
69
+ the `resolveFork` parameters `undecryptable` (the persisted `U` id set) and `holdCouldWin`, and the optional
70
+ `IngestContext` hooks `decideOpaque`, `holdOpaque`, `opaqueDecided` (and `fencedOpaque` / `releaseOpaque`).
71
+ - **Known limits.** Groups whose history fetch carries envelopes the device can never open — the pre-join history of
72
+ a late joiner, junk — carry a high `U`, which raises every candidate's best case, so such devices fall back to
73
+ today's fence. Live delivery hands the engine one event per call, so a lone own-leaf commit that arrives alone
74
+ (no sibling received yet) is fenced on arrival — sound for what the device has received — and a fence is
75
+ terminal; a history walk that spans several windows decides each window as its own batch. `U` is unbounded in the
76
+ record.
77
+
78
+ Sixteen local patches change engine source, so `PATCHSET_DIGEST` moves `b4c18eea1028b444` → `22af43683e8de310` and
79
+ `ENGINE_VERSION` changes: every store an earlier build wrote is refused (`envelope-mismatch`, surfaced by
80
+ `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
81
+ - **A plain call is a batch of its own.** With the seam on, `ingest(envelopes)` (no `settle` option, envelopes
82
+ present) is `ingest(envelopes, { settle: false })` followed by `ingest([])` by construction: its body runs as a
83
+ deferred step and the same call then settles, so a candidate that the call's own later envelopes outdo is skipped,
84
+ not fenced (it used to be fenced when it sorted after the competing commit). A fenced candidate is therefore first
85
+ reported as the provisional `skipped` and then as `unreadable` within the call. While a batch is open the engine
86
+ also remembers, per held candidate, every envelope it yielded a provisional `skipped` for (duplicate wrappers of the
87
+ commit), and the fence yields `unreadable` for each of them; candidates sharing a parent node and sender fence
88
+ together. This bookkeeping is in memory and batch-scoped (a batch that never settles, or a reload, keeps the
89
+ provisional semantics). With the seam off nothing changes.
90
+ - c9a0364: A pool-replay commit that fork recovery drops for failing the authorization or commit-legality gate now says why. The
91
+ `skipped` (`past-epoch`) result of such a commit carries the new optional `droppedReason`
92
+ (`"admin-policy" | "component-integrity" | "admin-leaf-coupling" | "disband-legality"`, the reason set of a `rejected`
93
+ result): the direct apply path already reported a violation as `rejected`, but the convergence seam yielded the same
94
+ `skipped` as for a commit that merely lost, so a regression on the rewind path showed only as a member silently staying
95
+ active. Additive: `reason` and the disposition are unchanged, an ordinary skip carries no key, and a resolution that
96
+ rejected nothing is unchanged. The violation's diagnostic is logged by the engine (debug), not put on a result. A rewind
97
+ is no longer reported (`processed`) against such a dropped commit: it is yielded `skipped` with its reason, and the rewind
98
+ is attributed to another pool entry.
99
+
100
+ Six local patches change engine source, so `PATCHSET_DIGEST` moves
101
+ (`eee3df5a61b028e2` → `573f46469fecbbcf` → … → `18c5881cacb81c85` with the later patches of this release) and `ENGINE_VERSION` changes: every store an
102
+ earlier build wrote is refused (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be
103
+ recovered by a wipe.
104
+ - 5141e1a: Device key rotation support: a default-off `selfUpdate` leaf-patch seam, the pure
105
+ `leafKeySuccessions` predicate, and the key-succession lineage of the equivocation credit.
106
+
107
+ **`selfUpdate` leaf patch.** `send({ kind: 'selfUpdate' })` accepts an optional `leafNodePatch` (the `ts-mls`
108
+ `LeafNodePatch` type, re-exported at `@941design/marmot-engine/mls`), forwarded to `createCommit`. A patch carrying a
109
+ `signatureKeyPair` replaces the committer's leaf signature key in the commit's UpdatePath: the commit is signed under the key
110
+ the leaf holds now (receivers verify it against the parent tree), the new leaf is self-signed under the patched key,
111
+ `pending.newState.signaturePrivateKey` is the patched private key (it survives `serializeClientState`), and `engine.state`
112
+ keeps the old key until `confirmPublished`. After the commit is canonical a commit signed under the retired key is refused by
113
+ every member. `extensions` replaces the leaf's whole extension list, so a key rotation swaps the account-identity-proof
114
+ extension in the same commit. A patched signature key that the tree the commit produces would hold twice (the sender's own
115
+ key, another leaf's, a bundled Add's) is refused by `send` before anything is staged; a bundled Remove of the leaf that holds
116
+ it frees it. Authorization, the lifecycle gate and the commit-legality checks are those of the unpatched `selfUpdate`. A
117
+ patched `selfUpdate` may also carry `extraProposals` of Remove kind only (by value, in the same commit as the path rotation),
118
+ so the duplicate-leaf repair is one atomic commit; they are authorized by the engine's `authorizeCommit` seam exactly like a
119
+ `commit` intent's (the default refuses a non-admin's Remove; marmot's same-account seam allows a same-account one) and the
120
+ uniqueness check counts them. Without a patch the call is upstream's.
121
+
122
+ **`leafKeySuccessions(parent, child)`** (`@941design/marmot-engine/core`, with the `LeafKeySuccession` type): the pure, total
123
+ predicate that tells a leaf's signature key replaced in place (a commit whose UpdatePath leaf carries a new key, or a committed
124
+ Update proposal) from the leaf disappearing. A Remove plus an Add of the same account into one index, a different account at
125
+ the index and a blank index are never successions. It is sound only when `child` is exactly one commit after `parent`: over a
126
+ gap, a Remove plus re-Add followed by a self-update reads as a rotation, so call it per edge, never on a tip pair. It is the
127
+ exception removal evidence by key difference needs.
128
+
129
+ **Equivocation credit lineage**, behind the existing `equivocationCredit` flag. A leaf that rotates its own
130
+ signature key kept the credit of the rotation commit but lost that of every later edge, because the key it signs under no longer
131
+ equals the key at the equivocation node; an honest rotated branch could lose to a rival it beats today. Now the keys a leaf is
132
+ credited under, along one candidate path, are extended by the `commit`-source succession of the committing leaf itself and by
133
+ nothing else: a key change by an Update proposal, a Remove plus re-Add, or a missing fact (an unavailable parent or child state)
134
+ earns exactly what it earned. Detection is untouched (a stale clone of the retired key is still a direct equivocation reported
135
+ with the retired key; a lone rotation reports nothing) and so is the branch-aware fence, which reads the same credit.
136
+ `EquivocationCreditInput` gains the optional `successions` map; with the flag off nothing is read and no path is built. The
137
+ three construction sites (pool replay, the tree-fed pass, the removal composition) and the two opaque-fence sites supply the
138
+ facts.
139
+
140
+ **Vendoring.** Six local patches change engine source and `src/core/leaf-succession.ts` is a new
141
+ locally authored file, so `PATCHSET_DIGEST` moves (`18b10c8ce421f728` → `18c5881cacb81c85`), `LOCAL_SOURCE_DIGEST` moves
142
+ (`c69e218dcb54be03` → `75382d7b2da18890`) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused
143
+ (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
144
+ - c8cda86: The engine records a `convergence_decision` for an inbound commit it applies in order.
145
+
146
+ Upstream MDK applies every commit through a scheduled convergence pass and records the decision of that pass; this
147
+ engine applied a commit that extends the canonical tip directly and recorded a decision only when a fork was resolved,
148
+ so a consumer reading the audit stream saw the epoch-2 fork decision as a client's latest where MDK's latest is the
149
+ pass of the epoch-3 commit that followed (the MDK vector `cross-route-own-commit-recovery/v1`, known failing until now).
150
+
151
+ - **The event.** An in-order apply of an inbound commit emits `{ type: "convergence_decision", decisive_rule:
152
+ "only_candidate", selected_tip_digest: <the commit's digest>, selected_tip_committer: <the committer's account>,
153
+ selected_fork_epoch: <the parent epoch>, selected_tip_epoch, witness_quorum_met: false, app_witness_score: 0 }`; its
154
+ one candidate carries `commit_ids: [<digest>]` and `commit_count: 1`, which a fork pass's candidates do not. Not
155
+ emitted for a commit that removes the local leaf, for a disband candidate, or for a fork-resolved apply (which
156
+ keeps its own decision), nor for the engine's own commit.
157
+ - **API.** `IngestContext` gains the optional `commitAppliedInOrder(parentState, message, newState, senderLeafIndex)`,
158
+ which `ingestEnvelopes` calls right after `recordCommit`; the engine implements it. A consumer of the audit stream
159
+ sees one more `convergence_decision` per applied commit; `@941design/marmot` reads no audit stream.
160
+ - **Stamp.** Two local patches change engine source, so `PATCHSET_DIGEST` moves (the batch ends at `834029be75954cae`, `22af43683e8de310` before it) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused
161
+ (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
162
+ - 0aa122f: Seven types that appear in the signatures of the public API are now importable; the API reference build now fails on any public type that is not exported.
163
+
164
+ - `@941design/marmot-engine/core` exports `OpaqueBounds`, `MediaCryptoFields`, `Rumor` and `ConvergenceStatus`
165
+ together with `convergenceStatuses`, the constant `ConvergenceStatus` is derived from (the whole
166
+ `convergence-status` module is not re-exported).
167
+ - `@941design/marmot-engine/engine` exports `HistoryTreeStore`, `DeferredEntry` and `GenericKeyValueStore`.
168
+ - **Stamp.** Six local patches change engine source, so `PATCHSET_DIGEST` moves (the batch ends at `834029be75954cae`, 22af43683e8de310 before it) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused (`envelope-mismatch`, surfaced by
169
+ `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
170
+ - 2c11e4b: Removal finality: a removal, once it competes with commits by the leaf it
171
+ removes, is no longer undone by depth alone. Behind the new engine option `MarmotGroupEngineOptions.removalFinality`
172
+ (threaded to `ForkRecovery`), off by default and effective only together with `equivocationCredit` (at the opaque fence
173
+ also with `branchAwareFence`); with it off every result is byte for byte the previous one.
174
+
175
+ - **The rule (pure core).** At a *rule node* — a branching node of the candidate tree below which a non-inert removal
176
+ counts, every candidate's tip within `maxRewindCommits` of it (the node-local guard) — a branch's credited edges
177
+ authored by a leaf that a removal on a sibling branch removes earn no *finality* (keyed by leaf index along the
178
+ credited key lineage, so an in-place rotation does not escape it); the entries with the maximal finality are kept,
179
+ and among them a removal head by a non-removed author is preferred before today's ordering. A removal by an author
180
+ anchored at the node in the subtree it heads is inert there (subtree-local inertness). Dead chains up to
181
+ `maxRewindCommits - 1` commits past the removal's parent are decided by the rule; a longer one falls back to today's
182
+ ordering. No new no-winner path; with no non-inert removal the result is unchanged.
183
+ - **New core exports.** `RemovedLeaf`, `CandidatePathEdge.removed` (absent: unknown; `[]`: removes nothing),
184
+ `EquivocationCreditInput.removalFinality`, `CanonicalSelection.decidedByRemoval` (present iff the flag),
185
+ `OpaqueScoringOptions.headEquivocated`, `branchingNodesOf` and `phaseOneNodesOf` (phase 1 is structural — every
186
+ branching node — when the rule is effective).
187
+ - **The four selection sites.** Pool replay, `#reconvergeFromTree`, `#reconvergeWithRemovals` (the removed device's own
188
+ decision, through the virtual `removal:<digest>` edge carrying every leaf the removal removes) and the opaque /
189
+ fence comparator all read per-edge removal facts. `ForkResolution` reports `decisiveRule: "removal_finality"` exactly
190
+ when the rule changed the winner. Facts are derived by `@internal` oracles (`edgeRemovalFactsOf`,
191
+ `opaqueRemovalFactsOf`) and memoised in engine memory only (`#edgeFactMemo`, bounded, never persisted); only an absent
192
+ fact on a removal head sends its node to the previous ordering; a deeper absent fact contributes nothing.
193
+ - **Interop.** A third silent deviation from the Marmot convergence rules / MDK selection (after structural branch
194
+ selection and equivocation credit), valid only in groups whose every member runs this engine with the option on.
195
+
196
+ Four local patches change engine source, so
197
+ `PATCHSET_DIGEST` moves in two steps `18c5881cacb81c85` → `21939d6d69a39e65` (`LOCAL_SOURCE_DIGEST` unchanged) and `ENGINE_VERSION`
198
+ changes: every store an earlier build wrote is refused (`envelope-mismatch`, surfaced by `@941design/marmot` as
199
+ `storeIncompatible`) and can be recovered by a wipe.
200
+ - 73baee0: Close the rewind takeover via a stale leaf snapshot: other-leaf credited depth at equivocation nodes.
201
+
202
+ `@941design/marmot-engine` — a new seam option, off by default (upstream selection, except the sender-attribution change below):
203
+ `MarmotGroupEngineOptions.equivocationCredit` (and `ForkRecovery`'s `equivocationCredit` option). With it on, every
204
+ branch candidate carries its `path` from the fork root (`BranchCandidate.path`, `CandidatePathEdge`), and at an
205
+ equivocation node — a node where one leaf (same index, same leaf signature key) heads one child subtree and also
206
+ authored a commit in another, the cryptographic trace of a restored stale snapshot — that leaf's commits earn nothing
207
+ inside the subtree it heads, and only depth built by leaves that were members at that node counts; a credit tie keeps
208
+ today's ordering. A node whose ratchet-tree facts a site
209
+ cannot resolve falls back to today's ordering on its own, without switching credit off elsewhere. Applied at all three
210
+ selection sites (pool replay, tree-fed re-convergence, re-convergence with removals). New pure core functions
211
+ `equivocationNodesOf` and `selectCanonicalBranchCredited` (types `EquivocationCreditInput`,
212
+ `EquivocationNodeContext`, `LeafEquivocation`, `CanonicalSelection`); `selectCanonicalBranch` takes an optional
213
+ fourth `credit` argument. A direct equivocation — two child commits of one node by one leaf — is reported, whoever
214
+ wins, as the new envelope-less `IngestResult` `{ kind: "leafEquivocation", evidence }` (disposition `accepted`) and
215
+ on `ForkResolution` / `AppliedForkResolution` as `equivocations`; evidence that spans child subtrees only (also the
216
+ shape of an honest lost race re-driven onto the winner) feeds credit but is not reported. `decision.decisiveRule`
217
+ gains `"equivocation_credit"` when credit changed the outcome. New helpers
218
+ `equivocationNodeContextOf` and `senderLeafKeyOf`. Edge senders are framing-independent: the new
219
+ `authenticatedSenderOf(result, message)` takes a commit's sender from its processing result (a `PrivateMessage`'s
220
+ decrypted sender data as a `PublicMessage`'s framing), so a burst framed as `PrivateMessage` is detected and credited
221
+ like any other; `ChainLink` and `RemovalEdge` gain `senderLeafIndex`, `KnownNextState` an optional one, and
222
+ `tipCommitterOf` now takes `(parent, senderLeafIndex)` instead of `(parent, message)` (a breaking signature change
223
+ for direct callers). With the seam off, the seam's only behaviour change is that a `PrivateMessage`-framed tip resolves its
224
+ tip committer. The persisted disband-convergence record carries an optional `senderLeafIndex`. The patch set changed,
225
+ so `ENGINE_VERSION` changes.
226
+
227
+ `@941design/marmot-engine` — ingest now defers a commit framed exactly one epoch ahead of the current epoch as
228
+ `deferred` (`missing_parent`), like one further ahead, instead of handing it to MLS processing where it failed
229
+ membership verification and terminated as `unreadable` (`protocol-core/inbound-processing.md`: a commit missing its
230
+ parent is retryable, never terminal). With `equivocationCredit` on, a credit rewind onto a shallower tip could
231
+ otherwise drop a later commit extending the abandoned branch and leave a member permanently split. The patch set
232
+ changed, so `ENGINE_VERSION` changes.
233
+
234
+ ### Patch Changes
235
+
236
+ - 1b6789d: First npm pre-release (alpha) of all four packages.
237
+ - 5794a86: `leafKeySuccessions` is total per leaf instead of per state: a leaf without a byte `signaturePublicKey` contributes no
238
+ succession and no longer erases the genuine rotations at other indices (which removal finality would otherwise read as
239
+ removals). Only reachable with malformed (non-ts-mls) input.
240
+
241
+ `ENGINE_VERSION` moves: `PATCHSET_DIGEST` `21939d6d69a39e65` → `2f0cf69d072f56b5` (a TSDoc-only edit of patch `9l`) and
242
+ `LOCAL_SOURCE_DIGEST` `75382d7b2da18890` → `dda4692d9eb4c034`, so stores written by the previous build are refused as
243
+ `storeIncompatible` (as for every engine change).
244
+ - 85dfd19: Three disband and rewind fixes in the engine:
245
+
246
+ - **Any single admin of a multi-admin group can disband it.** `requestDisband` already carries its own admin-policy
247
+ update (`[actor]`). The commit seam's admin-leaf coupling no longer splices a second update for the other admins
248
+ it removes. Before, that second update made the commit illegal ("exactly one lifecycle and admin-policy
249
+ replacement"), so disband worked only in single-admin groups. Receivers no longer reject such a disband with
250
+ `admin-leaf-coupling` either. `validateCommitLegality` skips the coupling check for a valid disband, because a
251
+ removed receiver's tombstone still carries the parent's admin set.
252
+ - **After a rewind onto a shallower tip, the retained window holds nothing above the new tip.** Equivocation
253
+ credit can cause such a rewind. The new `RetainedHistoryStore.discardAbove(epoch)` drops the abandoned branch's
254
+ states and links, so `retainedStates()` (the cross-epoch media-decrypt candidates) no longer offers that
255
+ branch's keys.
256
+ - **Scheduled disband settlement reports equivocations.** When it settles under `equivocationCredit`,
257
+ `driveConvergence()` now returns the selection's `leafEquivocation` results, also when the disband is
258
+ selected. Before, they were dropped.
259
+
260
+ `ENGINE_VERSION` moves (new `PATCHSET_DIGEST`), so envelopes written by earlier builds are refused
261
+ (`storeIncompatible`); wipe the store by marker to recover.
262
+ - c538b1a: Fence on lost path secrets at the fork-recovery, tree-sweep and re-convergence sites, not only on direct apply.
263
+ Replaying a commit whose `UpdatePath` holds no secret for any key the replaying state carries — ts-mls's
264
+ `InternalError("No overlap between provided private keys and update path")`, raised for a commit of the device's
265
+ own leaf that a restored, older state did not author — is now a first-class outcome:
266
+
267
+ - `isNoOverlapError(error)` is exported from `@941design/marmot-engine/engine`;
268
+ - `ParentResolution` gains `{ kind: "fenced"; cause }`, returned by `resolveCandidateParent` instead of
269
+ `authentication_mismatch`;
270
+ - fork recovery no longer drops such a candidate: it selects no branch (`skip` with `fenced`) and ingest yields a
271
+ terminal `unreadable` carrying the error for that commit, the same result the direct apply path yields;
272
+ - the pool's tree sweep yields that terminal `unreadable` too (and drops the envelope from the pool) instead of
273
+ leaving it pooled;
274
+ - tree-fed re-convergence abandons a winner chain whose link replay raises it (fail closed — every tree edge's child
275
+ state is held, so no transport envelope exists to surface).
276
+
277
+ Previously a restored device whose own commit won a same-epoch race, but was delivered after the competing commit,
278
+ silently forked off instead of being fenced.
279
+
280
+ `ENGINE_VERSION` moves (new `PATCHSET_DIGEST`), so envelopes written by earlier builds are refused
281
+ (`storeIncompatible`); wipe the store by marker to recover.
282
+ - 13a56b8: The branch-aware fence's internal plumbing is marked `@internal` instead of being documented public API: the barrels
283
+ re-export whole modules, so `decideOpaqueDrafts`, `OpaqueFromEncrypted`, `OpaqueHeldInfo`, the test seam
284
+ `selectCanonicalBranchWithOpaque` (with `OpaqueSelection`), the `opaque*` members of `ForkResolution` /
285
+ `AppliedForkResolution`, the `undecryptable` / `undecryptableSaturated` / `holdCouldWin` inputs of
286
+ `ForkRecovery.resolveFork` and the `IngestContext` members the engine fills for the seam (`opaqueDecided`, `decideOpaque`,
287
+ `holdOpaque`, `releaseOpaque`, `fencedOpaque`, `undecryptable`) were listed as public surface. They are excluded from the
288
+ generated documentation (the repo's `excludeInternal`) and may change in any release; they stay importable and typed, so no
289
+ consumer breaks. A test pins the tag on each declaration and the exclusion from a typedoc conversion.
290
+
291
+ Three comment-only local patches still move
292
+ `PATCHSET_DIGEST` (`40a448f66adcaeee` → … → `18c5881cacb81c85` with the other patches of this release) and so `ENGINE_VERSION`, as every patch change must: a store an
293
+ earlier build wrote is refused (`envelope-mismatch`, `storeIncompatible`) and can be recovered by a wipe.
294
+ - fb40ae1: Engine internals: the shared opaque decision (`#holdOrDecide`) no longer carries a branch that could not be reached.
295
+ Since the batch settle a plain ingest is a deferred step plus a settle, so a could-win verdict is provisional only inside a
296
+ deferred step; the non-deferred "other envelopes are still pooled or undecided" computation, the `hold`/`defer` defaults and
297
+ the optional `pending` argument of `IngestContext.decideOpaque` are removed. A verdict taken outside a deferred step is
298
+ final; the only difference from before is on the fail-closed side (a fence instead of a hold), never a skip where a fence
299
+ stood.
300
+
301
+ A local patch pair changes engine source, so `PATCHSET_DIGEST` moves
302
+ (`40a448f66adcaeee` → … → `18c5881cacb81c85` with the other patches of this release) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused
303
+ (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
304
+ - 76eeb86: `MarmotGroupEngine.ingest` documents its caller contract: the engine accepts
305
+ any envelope and does not route by group; routing by the transport's group tag (the Nostr `h` tag) is the caller's job
306
+ (`@941design/marmot` does it), so a group's engine should be handed only that group's traffic. An envelope for another
307
+ group cannot be read and is pooled as undecryptable until the pool evicts it, where upstream's engine classes it stale
308
+ at once. The engine deliberately does not filter on the tag: the routing id can rotate through a routing-component
309
+ update, and a filter run ahead of the commits that decide the current id would terminally skip own-group input (an
310
+ early-skip attempt was reverted for that race). Residual: a caller that mixes groups inflates `pendingCount` until
311
+ eviction.
312
+
313
+ - **Stamp.** One doc-only local patch touches engine source,
314
+ so `PATCHSET_DIGEST` moves and the batch of this release ends at `834029be75954cae` (`22af43683e8de310` before it):
315
+ every store an earlier build wrote is refused (`envelope-mismatch`, surfaced by `@941design/marmot` as
316
+ `storeIncompatible`) and can be recovered by a wipe.
317
+ - 72e42b4: `MarmotGroupEngine.removalActor()`: the hex account identity of the committer of the held removal's selected commit
318
+ (`RemovalRecord.commits[0]`), also on a rebuilt engine; `undefined` when none is held or it cannot be resolved. A new
319
+ local patch moves the engine stamp, so stores written by the previous
320
+ build are refused with `storeIncompatible`.
321
+ - 8858e61: A removed admin now accepts its own removal. When another admin removes an admin in one commit (the engine's
322
+ admin-policy splice drops the removed admin from the admin list in the same commit), the removed admin's engine used to
323
+ fail the coupling check on every receive path (rejected `admin-leaf-coupling` inbound; the removal candidate silently
324
+ dropped on the rewind path, when the removal won a fork against the removed admin's own same-epoch commit) and never
325
+ reached the removed-from-group state.
326
+
327
+ - **Cause and fix.** ts-mls hands a receiver the commit removes a tombstone that carries the PARENT group context (its
328
+ admin set) beside the post-commit roster, so the removed admin read itself as an orphan. `validateCommitLegality` now
329
+ takes the resulting admin set for such a receiver from the commit's own last admin-policy (`0x8003`) update. A trailing
330
+ remove operation or undecodable bytes is still the "did not decode" violation, a tombstone commit without an admin-policy
331
+ update keeps the carried-forward check, and every receiver that is not removed is unchanged. A removal whose last
332
+ admin-policy update still lists the removed admin is still rejected on the removed admin and on the other members.
333
+ - **Stamp.** One local patch changes engine source
334
+ , so `PATCHSET_DIGEST` moves (`834029be75954cae` →
335
+ `882f1f81f2f51ee9`) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused (`envelope-mismatch`,
336
+ surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
337
+ - 05e238d: A restarted engine keeps the application-witness evidence it had before the restart. Branch convergence weighs a fork
338
+ branch by the application messages delivered on it (`witness_quorum_met`, `app_witness_score`); that evidence was
339
+ resident-only, so a restart between a witness message and the fork resolution turned a witness-selected decision into a
340
+ tip-committer one (upstream MDK re-admits its stored processed application messages for witness scoring).
341
+
342
+ - **What is persisted.** `GroupHistoryTree` now keeps each delivered application message (the MLS message, its epoch and
343
+ delivery state) beside its nodes: `recordWitness` / `witnesses()`, written by `flush()` under
344
+ `<gid>/witness/<digest>` and read back by `GroupHistoryTree.load`. The engine mirrors its delivered-payload ledger into
345
+ the tree (record, prune, drop on a rewind that abandons the branch), so the persisted set follows the
346
+ ledger.
347
+ - **What a reloaded engine does with it.** The messages the ledger does not hold (those delivered before the restart) are
348
+ weighed on every convergence path that weighs witnesses: the tree-fed re-convergence, the removal-convergence pass and the
349
+ pool-replay fork resolution (`ForkRecovery#resolveFork({ witnessMessages })`, `collectMessageWitnessesAt`). An engine that
350
+ was never restarted behaves as before.
351
+ - **Bounded.** Witnesses are pruned from the tip: one counts only above its branch's fork epoch and a fork is resolvable
352
+ only within `maxRewindCommits` (R) of the tip, so those below `tip - 2R` (a rewind can lower the tip by up to R) are
353
+ dropped from memory and the store on every delivery, rewind and engine construction. A record that does not decode on
354
+ load is skipped, never fatal to the tree.
355
+ - **Not yet in `@941design/marmot`.** The client rebuilds its history tree from its retained-window record rather than
356
+ through `GroupHistoryTree.load`, so a client restart does not carry the witnesses yet, and a proof-gate rollback
357
+ (`rebuildEngine`, a fresh tree) drops them too; the engine-level restart keeps them.
358
+ - **Stamp.** Three local patches change engine source, so
359
+ `PATCHSET_DIGEST` moves (`882f1f81f2f51ee9` → `40a448f66adcaeee`, together with the undecryptable-set cap patches of the same release) and `ENGINE_VERSION` changes: every store an earlier
360
+ build wrote is refused (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered
361
+ by a wipe.
362
+ - cf2115a: Application messages are decoded as strictly as MDK decodes them: a message whose bytes start with U+FEFF, that
363
+ holds malformed UTF-8, or whose strings hold an unpaired surrogate escape, is refused (before, it was accepted here while MDK peers refused it, so members on different
364
+ implementations saw different histories). Avatar `dim`/`thumbhash` hints keep a leading U+FEFF. New conformance
365
+ patches move the engine stamp, so stores written by the previous build are refused with `storeIncompatible`.
366
+ - 780e176: A reload no longer changes what the branch-aware fence decides at the rewind horizon. The engine's history tree keeps every
367
+ node it observed while the rewind window the client persists keeps only the canonical path within `maxRewindCommits` of the
368
+ tip (and the forks off it), so an envelope whose parent lay beyond the horizon was read, and ledgered `skipped`, by an engine
369
+ that never reloaded but counted in the undecryptable set `U` after a reload. With the seam on the tree sweep now reads only
370
+ inside that window for commits (`#rewindWindow`, the same predicate as the persisted window), so both agree. It can only grow `U` (a
371
+ skipped envelope may stay undecryptable, as it already did after a reload), never turn a fence into a skip. Seam off, or an
372
+ unbounded horizon, is unchanged. The reload / rollback invariance tests now include scenarios whose tip stands one epoch
373
+ past the horizon. Application messages and proposals are still read tree-wide.
374
+
375
+ Two local patches change engine source, so `PATCHSET_DIGEST` moves
376
+ (`40a448f66adcaeee` → … → `18c5881cacb81c85` with the other patches of this release) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused
377
+ (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
378
+ - 3294d70: **Tree-fed re-convergence no longer reverts a witness-selected branch.** At the end of `ingest`, the history-tree
379
+ pass now weighs the app witnesses delivered on earlier ingests (the delivered-payload ledger), as pool-replay fork
380
+ recovery already did. Before, it saw only the current batch and the ingestion pool. When the witnesses had arrived
381
+ earlier, a branch that pool replay had just kept on witnesses could be switched off by the structural tie-break in
382
+ the same `ingest` call, and the payloads delivered on it were invalidated. A consequence: an equal-depth fork
383
+ sibling or foreign removal no longer outranks a tip that carries a delivered payload. Found by the MDK vector
384
+ `convergence-witness-selected/v1`. Witnesses are cached per history-tree node and envelope, so while a fork stays
385
+ in the tree an `ingest` decrypts only envelopes new to each node rather than the whole ledger again (200 delivered
386
+ payloads: about 10 ms per ingest, against about 750 ms uncached).
387
+
388
+ `ENGINE_VERSION` moves (new `PATCHSET_DIGEST`), so envelopes written by earlier builds are refused
389
+ (`storeIncompatible`); wipe the store by marker to recover.
390
+ - 16ed6ac: `ts-mls` now comes from the npm registry (`npm:@941design/ts-mls@2.0.0-rc.16-941design.1`) instead of
391
+ a git URL, so a default-configured pnpm 10+ install of `@941design/marmot-engine` no longer fails with
392
+ `ERR_PNPM_EXOTIC_SUBDEP`. The MLS code is unchanged: the published build is byte-identical to the
393
+ previous git pin.
394
+ - f7a682f: The branch-aware fence's undecryptable set `U` is bounded, fail-closed. `U` (the ids of group envelopes no held state
395
+ decrypts) is permanent and persisted id by id in `marmot.opaque`, so history a device can never read (before it joined,
396
+ before a restored snapshot's window, junk) filled it for good and the record was rewritten, in full, on every change.
397
+
398
+ - **Cap and saturation.** The engine keeps at most `MAX_UNDECRYPTABLE_IDS` (1,024, about 69 KB of record; per engine
399
+ `maxUndecryptableIds`) ids per group. The id that would exceed the cap saturates `U` instead: the ids are dropped, the
400
+ record carries one flag (`HeldOpaqueRecord.undecryptableSaturated`), and the count is read as unbounded, so every opaque
401
+ candidate fences — today's behaviour for an own-leaf commit, never a skip. It can only turn a skip into a fence: dropping
402
+ ids and keeping a count would undercount hidden edges. Saturation is sticky (a decrypt cannot shrink what is no longer
403
+ tracked; a reload, a prune and the capacity paths keep it) and is persisted and restored with the held candidates.
404
+ - **`@941design/marmot`.** `marmot.opaque` stores and restores the flag (a stored flag that is not `true` is corrupt and
405
+ fences the group), and the proof-gate rollback no longer reads an id missing from a saturated record as a decrypt.
406
+ - **Not done.** Scoping the history fetch so that pre-join and pre-window history never reaches the engine is not part of
407
+ this change: the spec rules a `created_at`-based exclusion out (a publisher chooses its `created_at`, so an excluded
408
+ hidden edge is an undercount), and no sound floor exists today. A restored device that fetched such history still gets
409
+ today's fence for an own-leaf commit once `U` saturates.
410
+ - **Stamp.** Two local patches change engine source, so `PATCHSET_DIGEST` moves (`882f1f81f2f51ee9` →
411
+ `40a448f66adcaeee`) and `ENGINE_VERSION` changes: every store an earlier build wrote is refused (`envelope-mismatch`,
412
+ surfaced by `@941design/marmot` as `storeIncompatible`) and can be recovered by a wipe.
413
+ - 2ab78c6: Marmot text fields keep a leading U+FEFF: `decodeUtf8` no longer strips it as a byte-order mark, so a group name or
414
+ description starting with it reads back exactly (a name of just U+FEFF no longer decodes as empty), as other
415
+ implementations read it. A new local patch moves the engine stamp, so
416
+ stores written by the previous build are refused with `storeIncompatible`.
417
+ - 372aaba: An app-payload witness is credited at the epoch its message was sent in, not at the epoch of the state that decrypted it.
418
+
419
+ `collectWitnessesAt`, shared by pool replay and the tree-fed re-convergence pass, credited every witness at the
420
+ decrypting state's epoch, and `isWitnessEligible` only requires that epoch to be past the fork. A payload sent at or
421
+ before the fork root that a post-root snapshot still decrypts (`historicalReceiverData`) therefore counted as a
422
+ post-fork witness on every post-root node of every candidate path: two such payloads from two senders met the witness
423
+ quorum on pre-fork traffic, and a deeper branch collected more credit from the same message. Reproduced on the tree-fed
424
+ path: two root-epoch payloads delivered after the fork switched the canonical branch from a really-witnessed shallow
425
+ one to a deeper unwitnessed one and retracted what had been delivered on the first. The witness epoch is now the
426
+ message's framed epoch, so a message at or before the fork is not a witness and one message is one credit per epoch.
427
+ Selection can change in the cases above and nowhere else: a witness sent after the fork is credited at its own epoch,
428
+ as before on the node it was sent on.
429
+
430
+ - **Stamp.** One local patch changes engine source, so
431
+ `PATCHSET_DIGEST` moves (the batch ends at `834029be75954cae`, `22af43683e8de310` before it) and `ENGINE_VERSION` changes: every store an earlier
432
+ build wrote is refused (`envelope-mismatch`, surfaced by `@941design/marmot` as `storeIncompatible`) and can be
433
+ recovered by a wipe.
434
+ - Upstream still has the defect; the report is `docs/upstream/marmot-ts-witness-credit-epoch.md`.
package/LICENSE ADDED
@@ -0,0 +1,49 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Markus Rother
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ Portions of this package (src/core, src/engine, src/audit, src/utils) are
26
+ derived from marmot-ts (https://github.com/marmot-protocol/marmot-ts),
27
+ distributed under the following license:
28
+
29
+ MIT License
30
+
31
+ Copyright (c) 2026 Internet Privacy Foundation
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in all
41
+ copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # `@941design/marmot-engine`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The MLS convergence engine behind `@941design/marmot`: the `core`, `engine`
4
+ and `audit` modules of [`marmot-ts`](https://github.com/marmot-protocol/marmot-ts)
5
+ (`dark-matter` branch), vendored at a pinned commit, ported onto the
6
+ [`ts-mls`](https://github.com/LukaJCB/ts-mls) API and patched locally.
7
+
8
+ Most applications should depend on `@941design/marmot` instead; this package
9
+ is its engine and the single owner of the `ts-mls` dependency.
10
+
11
+ > **Pre-1.0.** Every `0.x` release may break the API. Pin an exact version.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ pnpm add @941design/marmot-engine
17
+ ```
18
+
19
+ ## Subpaths
20
+
21
+ There is no root export. Import from one of:
22
+
23
+ | Subpath | Surface |
24
+ | ----------------------------------- | -------------------------------------------------------------------------- |
25
+ | `@941design/marmot-engine/core` | Credentials, key packages, group/welcome events, application-message codec |
26
+ | `@941design/marmot-engine/engine` | `MarmotGroupEngine`, ingest pipeline, retained history, convergence |
27
+ | `@941design/marmot-engine/audit` | Audit sink types and an in-memory implementation |
28
+ | `@941design/marmot-engine/mls` | Re-export of the pinned `ts-mls` surface the engine is built against |
29
+ | `@941design/marmot-engine/version` | The engine's version and stored-state format stamps |
30
+
31
+ ## License
32
+
33
+ MIT — see [`LICENSE`](./LICENSE), which also carries the `marmot-ts` notice
34
+ for the vendored code.
@@ -0,0 +1,17 @@
1
+ import type { AuditContextOptions, AuditEmitContext, AuditEventContext, AuditEventKind, AuditSink, MarmotAuditEvent } from "./types.js";
2
+ export declare class AuditEmitter implements AuditSink {
3
+ #private;
4
+ readonly context: AuditEmitContext;
5
+ readonly sink: AuditSink;
6
+ constructor(options: AuditContextOptions & {
7
+ sink?: AuditSink;
8
+ });
9
+ record(event: MarmotAuditEvent): void;
10
+ emit(kind: AuditEventKind, options?: {
11
+ groupRef?: string;
12
+ context?: AuditEventContext;
13
+ }): MarmotAuditEvent;
14
+ }
15
+ export declare function createAuditEmitter(options: (AuditContextOptions & {
16
+ sink?: AuditSink;
17
+ }) | undefined): AuditEmitter | undefined;
@@ -0,0 +1,30 @@
1
+ /** @module @category Audit */
2
+ import { auditNowMs, createAuditEvent } from "./helpers.js";
3
+ import { safeAuditSink } from "./sink.js";
4
+ export class AuditEmitter {
5
+ context;
6
+ sink;
7
+ #seq = 0;
8
+ constructor(options) {
9
+ this.sink = safeAuditSink(options.sink);
10
+ this.context = {
11
+ engineId: options.engineId,
12
+ accountRef: options.accountRef,
13
+ recorderSessionId: options.recorderSessionId,
14
+ dataMode: options.dataMode ?? "obfuscated_sensitive_data",
15
+ source: options.source,
16
+ now: options.now ?? auditNowMs,
17
+ };
18
+ }
19
+ record(event) {
20
+ this.sink.record(event);
21
+ }
22
+ emit(kind, options) {
23
+ const event = createAuditEvent(this.context, this.#seq++, kind, options);
24
+ this.record(event);
25
+ return event;
26
+ }
27
+ }
28
+ export function createAuditEmitter(options) {
29
+ return options ? new AuditEmitter(options) : undefined;
30
+ }
@@ -0,0 +1,16 @@
1
+ import type { AuditEmitContext, AuditEpochState, AuditEventContext, AuditMessageArtifactKind, MarmotAuditEvent } from "./types.js";
2
+ export declare function auditNowMs(): number;
3
+ export declare function digestBytes(bytes: Uint8Array): string;
4
+ export declare function digestString(value: string): string;
5
+ export declare function toAuditBytes(value: Uint8Array | string): Uint8Array;
6
+ export declare function deriveAccountRef(accountId: Uint8Array | string): string;
7
+ export declare function deriveMemberRef(memberIdentity: Uint8Array | string): string;
8
+ export declare function deriveEngineId(accountId: Uint8Array | string, deviceId: Uint8Array | string): string;
9
+ export declare function auditEpochStateName(value: string): AuditEpochState;
10
+ export declare function messageArtifactKindFromNostrKind(kind: number | undefined): AuditMessageArtifactKind;
11
+ export declare function createAuditEvent(context: AuditEmitContext, seq: number, kind: MarmotAuditEvent["kind"], options?: {
12
+ groupRef?: string;
13
+ context?: AuditEventContext;
14
+ }): MarmotAuditEvent;
15
+ export declare function mergeAuditContexts(a: AuditEventContext | undefined, b: AuditEventContext | undefined): AuditEventContext | undefined;
16
+ export declare function errorDetail(error: unknown): string;