@ottochain/sdk 2.4.0 → 2.6.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 (227) hide show
  1. package/dist/cjs/apps/compute/index.js +33 -0
  2. package/dist/cjs/apps/compute/state-machines/compute-rule110.js +164 -0
  3. package/dist/cjs/apps/compute/state-machines/index.js +9 -0
  4. package/dist/cjs/apps/contracts/index.js +1 -1
  5. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +126 -148
  6. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +153 -174
  7. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
  8. package/dist/cjs/apps/corporate/state-machines/corp-board.js +415 -481
  9. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +368 -440
  10. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +532 -647
  11. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +499 -603
  12. package/dist/cjs/apps/governance/index.js +7 -7
  13. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +170 -209
  14. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +161 -214
  15. package/dist/cjs/apps/governance/state-machines/dao-single.js +92 -92
  16. package/dist/cjs/apps/governance/state-machines/dao-token.js +169 -223
  17. package/dist/cjs/apps/governance/state-machines/governance-simple.js +185 -217
  18. package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
  19. package/dist/cjs/apps/identity/constants.js +16 -24
  20. package/dist/cjs/apps/identity/index.js +1 -1
  21. package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
  22. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +151 -169
  23. package/dist/cjs/apps/identity/state-machines/identity-registry.js +89 -115
  24. package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
  25. package/dist/cjs/apps/index.js +4 -1
  26. package/dist/cjs/apps/lending/assets.js +41 -17
  27. package/dist/cjs/apps/lending/credit-scoring.js +4 -4
  28. package/dist/cjs/apps/lending/eligibility.js +9 -25
  29. package/dist/cjs/apps/lending/index.js +1 -1
  30. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +177 -156
  31. package/dist/cjs/apps/markets/index.js +1 -1
  32. package/dist/cjs/apps/markets/state-machines/market-auction.js +115 -134
  33. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +122 -137
  34. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +158 -177
  35. package/dist/cjs/apps/markets/state-machines/market-prediction.js +193 -227
  36. package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
  37. package/dist/cjs/apps/oracles/index.js +1 -1
  38. package/dist/cjs/apps/privacy/index.js +67 -0
  39. package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
  40. package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
  41. package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
  42. package/dist/cjs/apps/staked-pool/assets.js +103 -0
  43. package/dist/cjs/apps/staked-pool/base.js +498 -0
  44. package/dist/cjs/apps/staked-pool/consumer.js +55 -0
  45. package/dist/cjs/apps/staked-pool/index.js +83 -0
  46. package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
  47. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
  48. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
  49. package/dist/cjs/generated/google/protobuf/struct.js +1 -1
  50. package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
  51. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +1 -1
  52. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  53. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +1 -1
  54. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  55. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +1 -1
  56. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1 -1
  57. package/dist/cjs/generated/ottochain/v1/common.js +1 -1
  58. package/dist/cjs/generated/ottochain/v1/fiber.js +40 -2
  59. package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
  60. package/dist/cjs/generated/ottochain/v1/records.js +1 -1
  61. package/dist/cjs/index.js +21 -3
  62. package/dist/cjs/ottochain/genesis-manifest.js +6 -0
  63. package/dist/cjs/ottochain/metagraph-client.js +63 -11
  64. package/dist/cjs/ottochain/snapshot.js +2 -4
  65. package/dist/cjs/ottochain/transaction.js +10 -0
  66. package/dist/cjs/privacy/sealed-bid.js +85 -82
  67. package/dist/cjs/privacy/shield-app.js +32 -32
  68. package/dist/cjs/schema/effects.js +145 -1
  69. package/dist/cjs/schema/fiber-app.js +139 -5
  70. package/dist/cjs/schema/guard-lint.js +3 -12
  71. package/dist/cjs/schema/guards.js +38 -38
  72. package/dist/cjs/templates/asset-policy.js +190 -0
  73. package/dist/cjs/templates/index.js +86 -0
  74. package/dist/cjs/templates/machine.js +130 -0
  75. package/dist/cjs/templates/migration.js +39 -0
  76. package/dist/cjs/templates/state-shape.js +38 -0
  77. package/dist/cjs/validation.js +1 -3
  78. package/dist/esm/apps/compute/index.js +29 -0
  79. package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
  80. package/dist/esm/apps/compute/state-machines/index.js +5 -0
  81. package/dist/esm/apps/contracts/index.js +4 -4
  82. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +128 -150
  83. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +155 -176
  84. package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
  85. package/dist/esm/apps/corporate/index.js +2 -2
  86. package/dist/esm/apps/corporate/state-machines/corp-board.js +418 -484
  87. package/dist/esm/apps/corporate/state-machines/corp-entity.js +371 -443
  88. package/dist/esm/apps/corporate/state-machines/corp-securities.js +535 -650
  89. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +502 -606
  90. package/dist/esm/apps/governance/index.js +10 -10
  91. package/dist/esm/apps/governance/state-machines/dao-multisig.js +172 -211
  92. package/dist/esm/apps/governance/state-machines/dao-reputation.js +163 -216
  93. package/dist/esm/apps/governance/state-machines/dao-single.js +94 -94
  94. package/dist/esm/apps/governance/state-machines/dao-token.js +171 -225
  95. package/dist/esm/apps/governance/state-machines/governance-simple.js +187 -219
  96. package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
  97. package/dist/esm/apps/identity/constants.js +18 -26
  98. package/dist/esm/apps/identity/index.js +8 -8
  99. package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
  100. package/dist/esm/apps/identity/state-machines/identity-oracle.js +153 -171
  101. package/dist/esm/apps/identity/state-machines/identity-registry.js +91 -117
  102. package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
  103. package/dist/esm/apps/index.js +9 -6
  104. package/dist/esm/apps/lending/assets.js +41 -17
  105. package/dist/esm/apps/lending/credit-scoring.js +6 -6
  106. package/dist/esm/apps/lending/eligibility.js +10 -26
  107. package/dist/esm/apps/lending/index.js +5 -5
  108. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +178 -157
  109. package/dist/esm/apps/markets/index.js +5 -5
  110. package/dist/esm/apps/markets/state-machines/market-auction.js +117 -136
  111. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +124 -139
  112. package/dist/esm/apps/markets/state-machines/market-group-buy.js +160 -179
  113. package/dist/esm/apps/markets/state-machines/market-prediction.js +195 -229
  114. package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
  115. package/dist/esm/apps/oracles/index.js +3 -3
  116. package/dist/esm/apps/privacy/index.js +56 -0
  117. package/dist/esm/apps/privacy/state-machines/index.js +6 -0
  118. package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
  119. package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
  120. package/dist/esm/apps/staked-pool/assets.js +91 -0
  121. package/dist/esm/apps/staked-pool/base.js +493 -0
  122. package/dist/esm/apps/staked-pool/consumer.js +49 -0
  123. package/dist/esm/apps/staked-pool/index.js +60 -0
  124. package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
  125. package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
  126. package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
  127. package/dist/esm/generated/google/protobuf/struct.js +1 -1
  128. package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
  129. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +1 -1
  130. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  131. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
  132. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  133. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +1 -1
  134. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1 -1
  135. package/dist/esm/generated/ottochain/v1/common.js +1 -1
  136. package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
  137. package/dist/esm/generated/ottochain/v1/messages.js +1 -1
  138. package/dist/esm/generated/ottochain/v1/records.js +1 -1
  139. package/dist/esm/index.js +10 -4
  140. package/dist/esm/ottochain/genesis-manifest.js +6 -0
  141. package/dist/esm/ottochain/metagraph-client.js +63 -11
  142. package/dist/esm/ottochain/snapshot.js +2 -4
  143. package/dist/esm/ottochain/transaction.js +8 -0
  144. package/dist/esm/privacy/index.js +2 -2
  145. package/dist/esm/privacy/sealed-bid.js +87 -84
  146. package/dist/esm/privacy/shield-app.js +33 -33
  147. package/dist/esm/schema/effects.js +137 -0
  148. package/dist/esm/schema/fiber-app.js +134 -5
  149. package/dist/esm/schema/guard-lint.js +3 -12
  150. package/dist/esm/schema/guards.js +36 -37
  151. package/dist/esm/templates/asset-policy.js +182 -0
  152. package/dist/esm/templates/index.js +41 -0
  153. package/dist/esm/templates/machine.js +125 -0
  154. package/dist/esm/templates/migration.js +34 -0
  155. package/dist/esm/templates/state-shape.js +34 -0
  156. package/dist/esm/validation.js +1 -3
  157. package/dist/esm/zk/index.js +4 -4
  158. package/dist/types/apps/compute/index.d.ts +176 -0
  159. package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
  160. package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
  161. package/dist/types/apps/contracts/index.d.ts +14 -14
  162. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +3 -3
  163. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +3 -3
  164. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
  165. package/dist/types/apps/corporate/index.d.ts +162 -162
  166. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +88 -88
  167. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +14 -14
  168. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +18 -18
  169. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +43 -43
  170. package/dist/types/apps/governance/index.d.ts +81 -81
  171. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +16 -16
  172. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +22 -22
  173. package/dist/types/apps/governance/state-machines/dao-token.d.ts +21 -21
  174. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +11 -11
  175. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +4 -4
  176. package/dist/types/apps/identity/constants.d.ts +2 -2
  177. package/dist/types/apps/identity/index.d.ts +70 -70
  178. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
  179. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +11 -11
  180. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +27 -27
  181. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
  182. package/dist/types/apps/index.d.ts +9 -6
  183. package/dist/types/apps/lending/assets.d.ts +2 -2
  184. package/dist/types/apps/lending/credit-scoring.d.ts +5 -5
  185. package/dist/types/apps/lending/eligibility.d.ts +2 -2
  186. package/dist/types/apps/lending/index.d.ts +20 -12
  187. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +15 -7
  188. package/dist/types/apps/markets/index.d.ts +76 -76
  189. package/dist/types/apps/markets/state-machines/market-auction.d.ts +12 -12
  190. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +19 -19
  191. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +18 -18
  192. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +15 -15
  193. package/dist/types/apps/markets/state-machines/market-universal.d.ts +7 -7
  194. package/dist/types/apps/oracles/index.d.ts +1 -1
  195. package/dist/types/apps/privacy/index.d.ts +328 -0
  196. package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
  197. package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
  198. package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
  199. package/dist/types/apps/staked-pool/assets.d.ts +53 -0
  200. package/dist/types/apps/staked-pool/base.d.ts +80 -0
  201. package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
  202. package/dist/types/apps/staked-pool/index.d.ts +51 -0
  203. package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
  204. package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
  205. package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
  206. package/dist/types/generated/openapi.d.ts +13 -0
  207. package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
  208. package/dist/types/index.d.ts +3 -3
  209. package/dist/types/openapi.d.ts +4 -2
  210. package/dist/types/ottochain/genesis-manifest.d.ts +6 -0
  211. package/dist/types/ottochain/index.d.ts +1 -1
  212. package/dist/types/ottochain/metagraph-client.d.ts +69 -15
  213. package/dist/types/ottochain/transaction.d.ts +9 -1
  214. package/dist/types/ottochain/types.d.ts +1 -1
  215. package/dist/types/privacy/index.d.ts +2 -2
  216. package/dist/types/privacy/sealed-bid.d.ts +9 -9
  217. package/dist/types/privacy/shield-app.d.ts +1 -1
  218. package/dist/types/schema/effects.d.ts +132 -0
  219. package/dist/types/schema/fiber-app.d.ts +281 -0
  220. package/dist/types/schema/guards.d.ts +12 -0
  221. package/dist/types/templates/asset-policy.d.ts +119 -0
  222. package/dist/types/templates/index.d.ts +26 -0
  223. package/dist/types/templates/machine.d.ts +139 -0
  224. package/dist/types/templates/migration.d.ts +34 -0
  225. package/dist/types/templates/state-shape.d.ts +30 -0
  226. package/dist/types/zk/index.d.ts +4 -4
  227. package/package.json +31 -13
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Versioned-machine skeleton + `transition()` / `effect()` composition (handoff §1.2).
3
+ *
4
+ * Two moves:
5
+ * 1. `transition()` / `effect()` build the wire `Transition` + its flat effect map from typed
6
+ * fragments instead of a hand-rolled JSON blob.
7
+ * 2. `machine()` is a versioned-package SKELETON that OWNS exactly ONE canonical wire definition
8
+ * (`toProtoDefinition(app)`, computed once) and hands the SAME object to BOTH `publishVersion()`
9
+ * and `create()`. That is the verified-binding invariant (F9): because publish and create cannot
10
+ * drift, the chain's `definition.computeDigest` equals the registered `logicHash` and the bind
11
+ * admits the fiber. The skeleton REUSES `toProtoDefinition` (the one canonicalization path) — it
12
+ * never re-derives the wire shape.
13
+ *
14
+ * Guardrail (CLAUDE.md #1): every builder here is a pure function emitting the exact wire shape the
15
+ * chain re-derives. Absent optionals (`metadata`/`participants`/`parentFiberId`/`migration`) are
16
+ * OMITTED, never `null`; required-no-default fields (`strict` on publish, `dependencies: []` per
17
+ * transition) are ALWAYS present.
18
+ */
19
+ import { toProtoDefinition, } from '../schema/fiber-app.js';
20
+ /**
21
+ * Build a wire {@link Transition} from a typed spec.
22
+ *
23
+ * - `on` → `eventName` (the wire key);
24
+ * - `guard` defaults to `{ "==": [1, 1] }`;
25
+ * - `dependencies` defaults to `[]` and is ALWAYS present;
26
+ * - `effect` is passed through (build it with {@link effect}).
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * transition({
31
+ * from: 'debt_current', to: 'debt_current', on: 'buy',
32
+ * effect: effect(
33
+ * { status: 'debt_current', purchaseCount: { '+': [{ var: 'state.purchaseCount' }, 1] } },
34
+ * triggers([...]), transferAsset([...]),
35
+ * ),
36
+ * });
37
+ * ```
38
+ */
39
+ export function transition(t) {
40
+ return {
41
+ from: t.from,
42
+ to: t.to,
43
+ eventName: t.on,
44
+ guard: t.guard ?? { '==': [1, 1] },
45
+ effect: t.effect,
46
+ dependencies: t.dependencies ?? [],
47
+ };
48
+ }
49
+ // =============================================================================
50
+ // effect()
51
+ // =============================================================================
52
+ /**
53
+ * Compose an effect into ONE FLAT map: the state-update fields PLUS any `_`-directive fragments,
54
+ * all in a single object (`Object.assign({}, stateUpdate, ...directives)`).
55
+ *
56
+ * Riverdale effects are flat maps that mix `_`-reserved directives (`_triggers`, `_transferAsset`,
57
+ * `_spawn`, …) with plain state-update fields — they are NOT `merge`-wrapped. Each directive fragment
58
+ * is a `Record` (e.g. the output of `transferAsset(...)` / `triggers(...)`), spread in here. Later
59
+ * fragments override earlier keys (`Object.assign` semantics).
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * effect(
64
+ * { status: 'debt_current', purchaseCount: { '+': [{ var: 'state.purchaseCount' }, 1] } },
65
+ * { _triggers: [...] },
66
+ * transferAsset([{ assetId: { var: 'event.payAssetId' }, recipient: toFiber({ var: 'event.retailerId' }) }]),
67
+ * );
68
+ * // => { status, purchaseCount, _triggers, _transferAsset }
69
+ * ```
70
+ */
71
+ export function effect(stateUpdate, ...directives) {
72
+ return Object.assign({}, stateUpdate, ...directives);
73
+ }
74
+ /** A pinned-Exact `SchemaRef` for `name@version`. Wire: `{ name, version: { Exact: { version } } }`. */
75
+ function exactRef(name, version) {
76
+ return { name, version: { Exact: { version } } };
77
+ }
78
+ /**
79
+ * Build a versioned-machine skeleton that binds publish + create to ONE canonical definition.
80
+ *
81
+ * The definition is projected ONCE here (`toProtoDefinition(spec.app)`) and the SAME reference is handed
82
+ * to `wireDefinition()`, `publishVersion().definition`, `create().definition`, and
83
+ * `upgradeFrom().newDefinition` — so they cannot drift and the chain's verified binding admits the fiber
84
+ * (F9). REUSES `toProtoDefinition` (the single canonicalization path); never re-derives the wire shape.
85
+ */
86
+ export function machine(spec) {
87
+ // Project the canonical wire definition ONCE; every consumer reuses this exact reference.
88
+ const wireDef = toProtoDefinition(spec.app);
89
+ return {
90
+ wireDefinition() {
91
+ return wireDef;
92
+ },
93
+ publishVersion(o) {
94
+ return {
95
+ name: spec.name,
96
+ version: spec.version,
97
+ // REQUIRED-no-default on the wire; '' is valid empty base64 when no descriptor set is bound.
98
+ schemaB64: o?.schemaB64 ?? '',
99
+ machineShape: spec.schemaShape,
100
+ definition: wireDef, // SAME reference as wireDefinition()/create()
101
+ strict: o?.strict ?? false, // REQUIRED — never omitted
102
+ ...(o?.metadata ? { metadata: o.metadata } : {}), // OMIT when absent
103
+ };
104
+ },
105
+ create(o) {
106
+ return {
107
+ fiberId: o.fiberId,
108
+ definition: wireDef, // SAME reference as wireDefinition()/publishVersion()
109
+ initialData: o.initialData,
110
+ schemaRef: exactRef(spec.name, spec.version), // verified binding: name@version
111
+ ...(o.participants ? { participants: o.participants } : {}), // OMIT when absent
112
+ ...(o.parentFiberId ? { parentFiberId: o.parentFiberId } : {}), // OMIT when absent
113
+ };
114
+ },
115
+ upgradeFrom(o) {
116
+ return {
117
+ fiberId: o.fiberId,
118
+ targetRef: exactRef(spec.name, spec.version),
119
+ newDefinition: wireDef, // SAME reference — re-pin hashes to the same logicHash
120
+ targetSequenceNumber: o.targetSequenceNumber,
121
+ ...(o.migration !== undefined ? { migration: o.migration } : {}), // OMIT (Option) when absent
122
+ };
123
+ },
124
+ };
125
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Migration builders — the `UpgradeFiber.migration` JSON-Logic transform applied on a version upgrade.
3
+ *
4
+ * THE FOOT-GUN (F9): a migration's evaluation root is the BARE prior state, not `state.x`.
5
+ * The chain evaluates the migration expression against `sm.stateData` directly
6
+ * (`MeteredEvaluator.eval(expr, sm.stateData, Migration)`, FiberEngine.scala:300), so:
7
+ * - `{ var: '' }` => the WHOLE prior state object
8
+ * - `{ var: 'loyaltyPoints' }` => the top-level `loyaltyPoints` field
9
+ * This is UNLIKE an effect, where the root is the transition context and you read `{ var: 'state.x' }`.
10
+ * Writing `state.loyaltyPoints` in a migration silently reads `undefined`. These helpers hide that
11
+ * asymmetry by pinning the bare-state root for you.
12
+ *
13
+ * `migration` is `Option` on `UpgradeFiber` — when there is no transform, OMIT the key (never send `null`).
14
+ */
15
+ /**
16
+ * Seed / overwrite top-level state fields on a version upgrade.
17
+ * Emits `{ merge: [{ var: '' }, fields] }` — merges `fields` onto the bare prior state, so existing
18
+ * fields are preserved and the named fields are added or overwritten.
19
+ *
20
+ * The `{ var: '' }` root is the BARE prior state (NOT `state.x` like an effect) — that asymmetry is
21
+ * exactly the F9 foot-gun this helper hides.
22
+ *
23
+ * @example seedFields({ loyaltyPoints: 0 }) // => { merge: [{ var: '' }, { loyaltyPoints: 0 }] }
24
+ */
25
+ export const seedFields = (fields) => ({
26
+ merge: [{ var: '' }, fields],
27
+ });
28
+ /**
29
+ * General migration transform with the bare-state root made explicit. `build` receives `{ var: '' }`
30
+ * (the whole prior state) and returns the migration JSON-Logic.
31
+ *
32
+ * @example migration((s) => ({ merge: [s, { x: 1 }] })) // => { merge: [{ var: '' }, { x: 1 }] }
33
+ */
34
+ export const migration = (build) => build({ var: '' });
@@ -0,0 +1,34 @@
1
+ /**
2
+ * State-shape-with-defaults — the SDK half of Proposal 01's "declared state shape" (removes F5).
3
+ *
4
+ * A declared shape carries a `default` (and optional `type`) per field. It seeds `initialData` so every
5
+ * accumulator starts at a concrete value — a counter read via `{ '+': [{ var: 'state.x' }, ...] }` never
6
+ * resolves `null` because `x` was never written. It also yields the set of declared field names for
7
+ * Proposal 01's var-path checks.
8
+ */
9
+ /**
10
+ * Build `initialData` by overlaying `overrides` onto each field's declared `default`.
11
+ * Every declared field gets a concrete value, so no field reads `null` at runtime. An override for a
12
+ * field replaces that field's default; overrides for undeclared fields are ignored (only declared fields
13
+ * are emitted). Determinism: pure function of its inputs, stable key order (declared order).
14
+ *
15
+ * @example seedState({ fields: { purchaseCount: { default: 0 }, status: { default: 'ACTIVE' } } })
16
+ * // => { purchaseCount: 0, status: 'ACTIVE' }
17
+ */
18
+ export function seedState(shape, overrides) {
19
+ const seeded = {};
20
+ for (const [name, field] of Object.entries(shape.fields)) {
21
+ seeded[name] =
22
+ overrides !== undefined && Object.prototype.hasOwnProperty.call(overrides, name)
23
+ ? overrides[name]
24
+ : field.default;
25
+ }
26
+ return seeded;
27
+ }
28
+ /**
29
+ * The set of declared state-field names — the fields the effects may read.
30
+ * Feeds Proposal 01's var-path checks (a `{ var: 'state.foo' }` whose `foo` is not declared is suspect).
31
+ */
32
+ export function declaredFields(shape) {
33
+ return new Set(Object.keys(shape.fields));
34
+ }
@@ -23,9 +23,7 @@ const hexString = (length) => {
23
23
  /**
24
24
  * Schema for a DAG address
25
25
  */
26
- export const DagAddressSchema = z
27
- .string()
28
- .regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
26
+ export const DagAddressSchema = z.string().regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
29
27
  // ============================================================================
30
28
  // Core Type Schemas
31
29
  // ============================================================================
@@ -10,10 +10,10 @@
10
10
  * `canonicalForSigning(data)`, so a proof's `exprHash` word equals {@link exprHash}`(rule)` equals a
11
11
  * policy's `logicHash` — see {@link proverPreimage} and docs/design/client-side-private-data.md §3.0.
12
12
  */
13
- export { canonicalForSigning, proverPreimage, exprHash, dataHash, KECCAK_TRUE, } from './preimage';
13
+ export { canonicalForSigning, proverPreimage, exprHash, dataHash, KECCAK_TRUE } from './preimage';
14
14
  export { R, toFr, frToHex, randomSalt, poseidonCommit, poseidonCommitN, openCommitment, } from './commit';
15
- export { decodeJlvmPublicValues, } from './types';
16
- export { groth16Witness, pmtWitness, } from './witness';
17
- export { ExprRegistry, boundRule, atLeast, atMost, } from './registry';
15
+ export { decodeJlvmPublicValues } from './types';
16
+ export { groth16Witness, pmtWitness } from './witness';
17
+ export { ExprRegistry, boundRule, atLeast, atMost } from './registry';
18
18
  export { wordOffset, semiPrivateGuard, verifyGroth16Bundle, checkSemiPrivateBinding, verifySemiPrivate, } from './guard';
19
19
  export { SubprocessProver, parseGroth16Stdout, } from './prover';
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Compute Application — bare computation substrates.
3
+ *
4
+ * Turing-complete JLVM substrates with no parties, assets, or governance: pure
5
+ * in-place state evolution. The flagship is `rule110`, an in-place Rule-110
6
+ * cellular automaton that proves the account layer is Turing-complete.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { getComputeDefinition, COMPUTE_DEFINITIONS } from '@ottochain/sdk/apps/compute';
11
+ *
12
+ * const rule110Def = getComputeDefinition('rule110');
13
+ * ```
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ import { computeRule110Def } from './state-machines/index.js';
18
+ import type { FiberAppDefinition } from '../../schema/fiber-app.js';
19
+ export { computeRule110Def };
20
+ /** All compute (bare-computation) state machine definitions. */
21
+ export declare const COMPUTE_DEFINITIONS: {
22
+ readonly rule110: {
23
+ readonly metadata: {
24
+ readonly name: "ComputeRule110";
25
+ readonly app: "compute";
26
+ readonly type: "rule110";
27
+ readonly version: "1.0.0";
28
+ readonly description: string;
29
+ };
30
+ readonly createSchema: {
31
+ readonly required: readonly ["tape", "idx"];
32
+ readonly properties: {
33
+ readonly tape: {
34
+ readonly type: "array";
35
+ readonly items: {
36
+ readonly type: "integer";
37
+ };
38
+ readonly description: "0/1 CA row (length N).";
39
+ };
40
+ readonly idx: {
41
+ readonly type: "array";
42
+ readonly items: {
43
+ readonly type: "integer";
44
+ };
45
+ readonly immutable: true;
46
+ readonly description: string;
47
+ };
48
+ readonly gen: {
49
+ readonly type: "integer";
50
+ readonly default: 0;
51
+ readonly description: "Generation counter (TM step count).";
52
+ };
53
+ readonly maxGen: {
54
+ readonly type: "integer";
55
+ readonly description: "Optional halt bound; absent ⇒ unbounded.";
56
+ };
57
+ };
58
+ };
59
+ readonly stateSchema: {
60
+ readonly properties: {
61
+ readonly tape: {
62
+ readonly type: "array";
63
+ readonly items: {
64
+ readonly type: "integer";
65
+ };
66
+ readonly computed: true;
67
+ };
68
+ readonly idx: {
69
+ readonly type: "array";
70
+ readonly items: {
71
+ readonly type: "integer";
72
+ };
73
+ readonly immutable: true;
74
+ };
75
+ readonly gen: {
76
+ readonly type: "integer";
77
+ readonly computed: true;
78
+ };
79
+ readonly maxGen: {
80
+ readonly type: "integer";
81
+ };
82
+ readonly status: {
83
+ readonly type: "string";
84
+ readonly computed: true;
85
+ };
86
+ };
87
+ };
88
+ readonly eventSchemas: {
89
+ readonly step: {
90
+ readonly description: "Advance one CA generation in place.";
91
+ };
92
+ readonly halt: {
93
+ readonly description: "Terminate once maxGen is reached (gated by gen >= maxGen).";
94
+ };
95
+ };
96
+ readonly states: {
97
+ readonly RUNNING: {
98
+ readonly id: "RUNNING";
99
+ readonly isFinal: false;
100
+ readonly metadata: {
101
+ readonly label: "Running";
102
+ readonly description: "CA evolving; each step = one generation.";
103
+ readonly category: "active";
104
+ };
105
+ };
106
+ readonly HALTED: {
107
+ readonly id: "HALTED";
108
+ readonly isFinal: true;
109
+ readonly metadata: {
110
+ readonly label: "Halted";
111
+ readonly description: "maxGen reached; terminal.";
112
+ readonly category: "terminal";
113
+ };
114
+ };
115
+ };
116
+ readonly initialState: "RUNNING";
117
+ readonly transitions: readonly [{
118
+ readonly from: "RUNNING";
119
+ readonly to: "RUNNING";
120
+ readonly eventName: "step";
121
+ readonly guard: {
122
+ readonly or: readonly [{
123
+ readonly missing: readonly ["state.maxGen"];
124
+ }, {
125
+ readonly '<': readonly [{
126
+ readonly var: "state.gen";
127
+ }, {
128
+ readonly var: "state.maxGen";
129
+ }];
130
+ }];
131
+ };
132
+ readonly effect: {
133
+ readonly merge: readonly [{
134
+ readonly var: "state";
135
+ }, {
136
+ readonly tape: {
137
+ readonly map: readonly [{
138
+ readonly var: "state.idx";
139
+ }, import("../../schema/fiber-app.js").JsonLogicRule];
140
+ };
141
+ readonly gen: {
142
+ readonly '+': readonly [{
143
+ readonly var: "state.gen";
144
+ }, 1];
145
+ };
146
+ }];
147
+ };
148
+ readonly dependencies: readonly [];
149
+ }, {
150
+ readonly from: "RUNNING";
151
+ readonly to: "HALTED";
152
+ readonly eventName: "halt";
153
+ readonly guard: {
154
+ readonly '>=': readonly [{
155
+ readonly var: "state.gen";
156
+ }, {
157
+ readonly var: "state.maxGen";
158
+ }];
159
+ };
160
+ readonly effect: {
161
+ readonly merge: readonly [{
162
+ readonly var: "state";
163
+ }, {
164
+ readonly status: "halted";
165
+ }];
166
+ };
167
+ readonly dependencies: readonly [];
168
+ }];
169
+ };
170
+ };
171
+ export type ComputeDefType = keyof typeof COMPUTE_DEFINITIONS;
172
+ /**
173
+ * Get a compute state machine definition by type.
174
+ * @param type - 'rule110' (default).
175
+ */
176
+ export declare function getComputeDefinition(type?: ComputeDefType): FiberAppDefinition;
@@ -0,0 +1,157 @@
1
+ import type { JsonLogicRule } from '../../../schema/fiber-app.js';
2
+ /**
3
+ * Rule-110 cellular-automaton fiber definition.
4
+ *
5
+ * Trust model: PUBLIC / PERMISSIONLESS / pure compute. No assets, no parties,
6
+ * no owner — anyone may submit `step`. The DoS surface is bounded by per-event
7
+ * gas/fee (~987 gas/cell) and the optional `maxGen` halt bound (absent ⇒
8
+ * unbounded; runs until fees stop).
9
+ */
10
+ export declare const computeRule110Def: {
11
+ readonly metadata: {
12
+ readonly name: "ComputeRule110";
13
+ readonly app: "compute";
14
+ readonly type: "rule110";
15
+ readonly version: "1.0.0";
16
+ readonly description: string;
17
+ };
18
+ readonly createSchema: {
19
+ readonly required: readonly ["tape", "idx"];
20
+ readonly properties: {
21
+ readonly tape: {
22
+ readonly type: "array";
23
+ readonly items: {
24
+ readonly type: "integer";
25
+ };
26
+ readonly description: "0/1 CA row (length N).";
27
+ };
28
+ readonly idx: {
29
+ readonly type: "array";
30
+ readonly items: {
31
+ readonly type: "integer";
32
+ };
33
+ readonly immutable: true;
34
+ readonly description: string;
35
+ };
36
+ readonly gen: {
37
+ readonly type: "integer";
38
+ readonly default: 0;
39
+ readonly description: "Generation counter (TM step count).";
40
+ };
41
+ readonly maxGen: {
42
+ readonly type: "integer";
43
+ readonly description: "Optional halt bound; absent ⇒ unbounded.";
44
+ };
45
+ };
46
+ };
47
+ readonly stateSchema: {
48
+ readonly properties: {
49
+ readonly tape: {
50
+ readonly type: "array";
51
+ readonly items: {
52
+ readonly type: "integer";
53
+ };
54
+ readonly computed: true;
55
+ };
56
+ readonly idx: {
57
+ readonly type: "array";
58
+ readonly items: {
59
+ readonly type: "integer";
60
+ };
61
+ readonly immutable: true;
62
+ };
63
+ readonly gen: {
64
+ readonly type: "integer";
65
+ readonly computed: true;
66
+ };
67
+ readonly maxGen: {
68
+ readonly type: "integer";
69
+ };
70
+ readonly status: {
71
+ readonly type: "string";
72
+ readonly computed: true;
73
+ };
74
+ };
75
+ };
76
+ readonly eventSchemas: {
77
+ readonly step: {
78
+ readonly description: "Advance one CA generation in place.";
79
+ };
80
+ readonly halt: {
81
+ readonly description: "Terminate once maxGen is reached (gated by gen >= maxGen).";
82
+ };
83
+ };
84
+ readonly states: {
85
+ readonly RUNNING: {
86
+ readonly id: "RUNNING";
87
+ readonly isFinal: false;
88
+ readonly metadata: {
89
+ readonly label: "Running";
90
+ readonly description: "CA evolving; each step = one generation.";
91
+ readonly category: "active";
92
+ };
93
+ };
94
+ readonly HALTED: {
95
+ readonly id: "HALTED";
96
+ readonly isFinal: true;
97
+ readonly metadata: {
98
+ readonly label: "Halted";
99
+ readonly description: "maxGen reached; terminal.";
100
+ readonly category: "terminal";
101
+ };
102
+ };
103
+ };
104
+ readonly initialState: "RUNNING";
105
+ readonly transitions: readonly [{
106
+ readonly from: "RUNNING";
107
+ readonly to: "RUNNING";
108
+ readonly eventName: "step";
109
+ readonly guard: {
110
+ readonly or: readonly [{
111
+ readonly missing: readonly ["state.maxGen"];
112
+ }, {
113
+ readonly '<': readonly [{
114
+ readonly var: "state.gen";
115
+ }, {
116
+ readonly var: "state.maxGen";
117
+ }];
118
+ }];
119
+ };
120
+ readonly effect: {
121
+ readonly merge: readonly [{
122
+ readonly var: "state";
123
+ }, {
124
+ readonly tape: {
125
+ readonly map: readonly [{
126
+ readonly var: "state.idx";
127
+ }, JsonLogicRule];
128
+ };
129
+ readonly gen: {
130
+ readonly '+': readonly [{
131
+ readonly var: "state.gen";
132
+ }, 1];
133
+ };
134
+ }];
135
+ };
136
+ readonly dependencies: readonly [];
137
+ }, {
138
+ readonly from: "RUNNING";
139
+ readonly to: "HALTED";
140
+ readonly eventName: "halt";
141
+ readonly guard: {
142
+ readonly '>=': readonly [{
143
+ readonly var: "state.gen";
144
+ }, {
145
+ readonly var: "state.maxGen";
146
+ }];
147
+ };
148
+ readonly effect: {
149
+ readonly merge: readonly [{
150
+ readonly var: "state";
151
+ }, {
152
+ readonly status: "halted";
153
+ }];
154
+ };
155
+ readonly dependencies: readonly [];
156
+ }];
157
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Compute (bare-computation) state machine definitions.
3
+ * Re-exports from TypeScript definition files.
4
+ */
5
+ export { computeRule110Def } from './compute-rule110.js';
@@ -18,10 +18,10 @@
18
18
  *
19
19
  * @packageDocumentation
20
20
  */
21
- export { State, Contract, ProposeContractRequest, AcceptContractRequest, CompleteContractRequest, RejectContractRequest, DisputeContractRequest, ContractDefinition, stateFromJSON, stateToJSON, } from "../../generated/ottochain/apps/contracts/v1/contract.js";
22
- export { State as ContractState, stateFromJSON as contractStateFromJSON, stateToJSON as contractStateToJSON, } from "../../generated/ottochain/apps/contracts/v1/contract.js";
23
- import { contractUniversalDef, contractAgreementDef, contractEscrowDef } from "./state-machines/index.js";
24
- import type { FiberAppDefinition } from "../../schema/fiber-app.js";
21
+ export { State, Contract, ProposeContractRequest, AcceptContractRequest, CompleteContractRequest, RejectContractRequest, DisputeContractRequest, ContractDefinition, stateFromJSON, stateToJSON, } from '../../generated/ottochain/apps/contracts/v1/contract.js';
22
+ export { State as ContractState, stateFromJSON as contractStateFromJSON, stateToJSON as contractStateToJSON, } from '../../generated/ottochain/apps/contracts/v1/contract.js';
23
+ import { contractUniversalDef, contractAgreementDef, contractEscrowDef } from './state-machines/index.js';
24
+ import type { FiberAppDefinition } from '../../schema/fiber-app.js';
25
25
  export { contractUniversalDef, contractAgreementDef, contractEscrowDef };
26
26
  /** All contract state machine definitions */
27
27
  export declare const CONTRACTS_DEFINITIONS: {
@@ -104,7 +104,7 @@ export declare const CONTRACTS_DEFINITIONS: {
104
104
  to: "ACTIVE";
105
105
  eventName: "accept";
106
106
  guard: {
107
- "==": number[];
107
+ '==': number[];
108
108
  };
109
109
  effect: {
110
110
  merge: ({
@@ -125,7 +125,7 @@ export declare const CONTRACTS_DEFINITIONS: {
125
125
  to: "CANCELLED";
126
126
  eventName: "cancel";
127
127
  guard: {
128
- "==": number[];
128
+ '==': number[];
129
129
  };
130
130
  effect: {
131
131
  merge: ({
@@ -146,7 +146,7 @@ export declare const CONTRACTS_DEFINITIONS: {
146
146
  to: "COMPLETED";
147
147
  eventName: "complete";
148
148
  guard: {
149
- "==": number[];
149
+ '==': number[];
150
150
  };
151
151
  effect: {
152
152
  merge: ({
@@ -167,7 +167,7 @@ export declare const CONTRACTS_DEFINITIONS: {
167
167
  to: "CANCELLED";
168
168
  eventName: "cancel";
169
169
  guard: {
170
- "==": number[];
170
+ '==': number[];
171
171
  };
172
172
  effect: {
173
173
  merge: ({
@@ -460,7 +460,7 @@ export declare const CONTRACTS_DEFINITIONS: {
460
460
  eventName: "submit_completion";
461
461
  guard: {
462
462
  and: import("../../index.js").GuardRule[];
463
- ">="?: undefined;
463
+ '>='?: undefined;
464
464
  or?: undefined;
465
465
  };
466
466
  effect: {
@@ -492,7 +492,7 @@ export declare const CONTRACTS_DEFINITIONS: {
492
492
  to: "COMPLETED";
493
493
  eventName: "finalize";
494
494
  guard: {
495
- ">=": (number | {
495
+ '>=': (number | {
496
496
  length: {
497
497
  var: string;
498
498
  }[];
@@ -548,7 +548,7 @@ export declare const CONTRACTS_DEFINITIONS: {
548
548
  guard: {
549
549
  or: import("../../index.js").GuardRule[];
550
550
  and?: undefined;
551
- ">="?: undefined;
551
+ '>='?: undefined;
552
552
  };
553
553
  effect: {
554
554
  merge: ({
@@ -918,7 +918,7 @@ export declare const CONTRACTS_DEFINITIONS: {
918
918
  };
919
919
  };
920
920
  releaseDeadline: {
921
- "+": {
921
+ '+': {
922
922
  var: string;
923
923
  }[];
924
924
  };
@@ -1027,9 +1027,9 @@ export declare const CONTRACTS_DEFINITIONS: {
1027
1027
  guard: {
1028
1028
  or: ({
1029
1029
  and: import("../../index.js").GuardRule[];
1030
- ">="?: undefined;
1030
+ '>='?: undefined;
1031
1031
  } | {
1032
- ">=": {
1032
+ '>=': {
1033
1033
  var: string;
1034
1034
  }[];
1035
1035
  and?: undefined;