@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
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @module @category Build identity
3
+ *
4
+ * Locally authored (not vendored from marmot-ts; listed in VENDOR.md's
5
+ * "Locally authored (not vendored)" section). The constants identify the
6
+ * engine build that wrote a stored artifact: `@941design/marmot`'s storage
7
+ * envelope (ADR-007 §3, epic-marmot-client AC-STORE-2) stamps
8
+ * `ENGINE_VERSION` and `TS_MLS_PIN` on every write and refuses any envelope
9
+ * whose stamp differs.
10
+ *
11
+ * `ENGINE_VERSION` is the compared stamp: `state.<ENGINE_STATE_FORMAT>`, a
12
+ * hand-maintained state-format number (BACKLOG
13
+ * `engine-version-digest-overtriggers`, 2026-11-09). It must change whenever
14
+ * an engine change could make a stored artifact read differently: a
15
+ * serialized format, a selection/convergence rule whose decisions marmot
16
+ * persists (rewind tree, terminal ledger, held set, own-commit stamps), or a
17
+ * decoder of stored bytes. It need not change for an edit that touches none of
18
+ * these (a comment, a new read-only accessor), so such an edit no longer
19
+ * refuses every existing store.
20
+ *
21
+ * The decision is forced, not optional: the digests below still identify the
22
+ * engine code, and `state-format-ledger.json` (package root) records, per
23
+ * digest pair, the state format it was judged to be. Its last entry must
24
+ * match the digests on disk (`packages/marmot/test/engine-version.test.ts`),
25
+ * so every code change makes the author either bump `ENGINE_STATE_FORMAT` or
26
+ * append a same-format entry whose `note` says why nothing stored reads
27
+ * differently. When in doubt, bump. `ENGINE_BUILD` keeps the full code
28
+ * identity for diagnostics.
29
+ *
30
+ * The digests change whenever the engine code changes. The vendored source is
31
+ * upstream `marmot-ts` at the VENDOR.md pin plus `patches/*.diff`; the
32
+ * locally-authored (never-vendored) source is VENDOR.md's "Locally
33
+ * authored (not vendored)" list. `ENGINE_BUILD` folds in all three: the
34
+ * package version, `PATCHSET_DIGEST` (the vendored+patched side), and
35
+ * `LOCAL_SOURCE_DIGEST` (the locally-authored side). Changes that must
36
+ * update this file (and, for a digest, the ledger):
37
+ * - a package.json `version` bump → `ENGINE_PACKAGE_VERSION`;
38
+ * - any added, removed, renamed or edited `patches/*.diff` that touches a
39
+ * non-test engine source file, or a move of the marmot-ts pin in
40
+ * VENDOR.md → `PATCHSET_DIGEST`;
41
+ * - an edit to a non-test file in VENDOR.md's "Locally authored (not
42
+ * vendored)" list (other than this file itself — see below) →
43
+ * `LOCAL_SOURCE_DIGEST`;
44
+ * - a move of the `ts-mls` git+SHA pin → `TS_MLS_PIN` (compared separately).
45
+ *
46
+ * A patch is test-only — and excluded from `PATCHSET_DIGEST` — when every
47
+ * file it touches sits under a `__tests__/` directory: a `*.test.ts` spec, a
48
+ * test-only helper, or a test fixture. A file's target path is read from
49
+ * every `---`/`+++` header (so deletions count) AND every `rename from`/
50
+ * `rename to`/`copy from`/`copy to` header — a pure rename or copy carries
51
+ * no `---`/`+++` lines of its own, so a patch that combines a pure rename of
52
+ * a production file with a genuinely test-only hunk would otherwise be
53
+ * misclassified as test-only by the `---`/`+++` paths alone. Such a patch
54
+ * can never change the shape of state the engine serializes, so folding it
55
+ * into the stamp would force spurious envelope-mismatch churn on stored
56
+ * artifacts whenever a test or conformance/flake patch is touched. A patch
57
+ * that touches even one non-test file (source under `core/`, `engine/`,
58
+ * `audit/`, `utils/`, `index.ts`, `mls.ts`, …) is hashed in full, in the
59
+ * order below.
60
+ *
61
+ * `LOCAL_SOURCE_DIGEST` covers the other half of locally-authored source
62
+ * that `PATCHSET_DIGEST` cannot see: files in VENDOR.md's "Locally authored
63
+ * (not vendored)" list have no `patches/*.diff` entry (they were never
64
+ * vendored, so there is nothing to diff against upstream), so an edit to
65
+ * one is otherwise invisible to the stamp. It is a digest over every listed
66
+ * path that is (a) not itself under a `__tests__/` directory and (b) not
67
+ * this file (`src/version.ts` folding itself in would be circular — a
68
+ * change to this file already bumps `ENGINE_VERSION` directly, since the
69
+ * literals live here). Today the one such path is `src/core/leaf-succession.ts`
70
+ * (every other listed path is a test path), so the digest covers that file;
71
+ * it closes the gap for each non-test locally-authored file added to that
72
+ * list, without a second remediation round.
73
+ *
74
+ * Literals rather than a runtime read so the value is fixed at build time and
75
+ * needs no JSON or fs import. `packages/marmot/test/engine-version.test.ts`
76
+ * recomputes each from disk and fails — printing the expected value — when
77
+ * any drifts, so a patch or locally-authored-source change cannot ship with
78
+ * a stale stamp.
79
+ */
80
+ /** `@941design/marmot-engine` package version. */
81
+ export const ENGINE_PACKAGE_VERSION = "0.1.0";
82
+ /**
83
+ * First 16 hex chars of SHA-256 over `marmot-ts@<pin SHA>\n` followed by,
84
+ * for each non-test `patches/*.diff` (a patch excluded only when every one
85
+ * of its diff's `---`/`+++`/`rename from`/`rename to`/`copy from`/`copy to`
86
+ * paths sits under a `__tests__/` directory) in code-unit order,
87
+ * `<file name>\n<byte length>\n<bytes>`.
88
+ *
89
+ * Blind spot: it hashes the patch files, not the vendored tree, so a direct
90
+ * edit to a vendored file (bypassing `patches/`) or a new production file not
91
+ * listed as locally authored moves neither digest. `scripts/vendor/verify.sh`'s
92
+ * full re-derivation is the authoritative guard for that.
93
+ */
94
+ export const PATCHSET_DIGEST = "bd07cca1c2873857";
95
+ /**
96
+ * First 16 hex chars of SHA-256 over `local-source\n` followed by, for each
97
+ * non-test, non-`src/version.ts` path in VENDOR.md's "Locally authored (not
98
+ * vendored)" list, in code-unit order, `<path>\n<byte length>\n<bytes>`.
99
+ */
100
+ export const LOCAL_SOURCE_DIGEST = "dda4692d9eb4c034";
101
+ /**
102
+ * The engine's stored-state format. Bump it for any change that could make a
103
+ * stored artifact read differently (see the module doc); record each digest
104
+ * move in `state-format-ledger.json` either way.
105
+ */
106
+ export const ENGINE_STATE_FORMAT = 1;
107
+ /** The envelope's engine stamp (compared on every read): the state format. */
108
+ export const ENGINE_VERSION = `state.${ENGINE_STATE_FORMAT}`;
109
+ /** The engine build's full code identity (diagnostics): package version plus the vendored patch set and the locally-authored source. */
110
+ export const ENGINE_BUILD = `${ENGINE_PACKAGE_VERSION}+patches.${PATCHSET_DIGEST}.local.${LOCAL_SOURCE_DIGEST}`;
111
+ /** Commit SHA of the `941design/ts-mls` pin recorded in VENDOR.md (consumed via the `@941design/ts-mls` registry alias). */
112
+ export const TS_MLS_PIN = "26afb1d69fd4c5a613b8319610a69e4f4239e5b5";
package/package.json CHANGED
@@ -1,6 +1,71 @@
1
1
  {
2
2
  "name": "@941design/marmot-engine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "MLS convergence engine for Marmot groups, vendored from marmot-ts (dark-matter) and ported to the ts-mls API. Re-exports the pinned ts-mls surface at ./mls.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/941design/nostr-events.git"
10
+ },
11
+ "homepage": "https://github.com/941design/nostr-events#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/941design/nostr-events/issues"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "LICENSE",
19
+ "CHANGELOG.md"
20
+ ],
21
+ "exports": {
22
+ "./core": {
23
+ "types": "./dist/core/index.d.ts",
24
+ "import": "./dist/core/index.js"
25
+ },
26
+ "./engine": {
27
+ "types": "./dist/engine/index.d.ts",
28
+ "import": "./dist/engine/index.js"
29
+ },
30
+ "./audit": {
31
+ "types": "./dist/audit/index.d.ts",
32
+ "import": "./dist/audit/index.js"
33
+ },
34
+ "./mls": {
35
+ "types": "./dist/mls.d.ts",
36
+ "import": "./dist/mls.js"
37
+ },
38
+ "./version": {
39
+ "types": "./dist/version.d.ts",
40
+ "import": "./dist/version.js"
41
+ }
42
+ },
43
+ "dependencies": {
44
+ "@noble/ciphers": "^2.2.0",
45
+ "@noble/curves": "^2.2.0",
46
+ "@noble/hashes": "^2.2.0",
47
+ "@scure/base": "^2.2.0",
48
+ "debug": "^4.4.3",
49
+ "nostr-tools": "2.23.3",
50
+ "ts-mls": "npm:@941design/ts-mls@2.0.0-rc.16-941design.1"
51
+ },
52
+ "devDependencies": {
53
+ "@stryker-mutator/core": "^9.6.1",
54
+ "@stryker-mutator/vitest-runner": "^9.6.1",
55
+ "@types/debug": "^4.1.13",
56
+ "@types/node": "^25.6.0",
57
+ "fast-check": "3.23.2",
58
+ "typescript": "5.7.3",
59
+ "vitest": "2.1.8"
60
+ },
61
+ "publishConfig": {
62
+ "access": "public"
63
+ },
64
+ "scripts": {
65
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
66
+ "build": "pnpm run clean && tsc --project tsconfig.build.json",
67
+ "typecheck": "tsc --noEmit",
68
+ "test": "vitest run",
69
+ "mutation": "stryker run"
70
+ }
6
71
  }