@ottochain/sdk 2.3.0 → 2.5.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 (287) 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 +16 -9
  5. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +134 -161
  6. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +192 -170
  7. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
  8. package/dist/cjs/apps/corporate/index.js +2 -2
  9. package/dist/cjs/apps/corporate/state-machines/corp-board.js +500 -456
  10. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +487 -361
  11. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +769 -576
  12. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +567 -557
  13. package/dist/cjs/apps/governance/index.js +21 -21
  14. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +188 -209
  15. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +181 -228
  16. package/dist/cjs/apps/governance/state-machines/dao-single.js +105 -88
  17. package/dist/cjs/apps/governance/state-machines/dao-token.js +199 -227
  18. package/dist/cjs/apps/governance/state-machines/governance-simple.js +231 -231
  19. package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
  20. package/dist/cjs/apps/identity/constants.js +55 -22
  21. package/dist/cjs/apps/identity/index.js +28 -12
  22. package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
  23. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +158 -173
  24. package/dist/cjs/apps/identity/state-machines/identity-registry.js +262 -0
  25. package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
  26. package/dist/cjs/apps/identity/state-machines/index.js +3 -1
  27. package/dist/cjs/apps/index.js +22 -8
  28. package/dist/cjs/apps/lending/assets.js +247 -0
  29. package/dist/cjs/apps/lending/credit-scoring.js +87 -0
  30. package/dist/cjs/apps/lending/eligibility.js +105 -0
  31. package/dist/cjs/apps/lending/index.js +91 -0
  32. package/dist/cjs/apps/lending/state-machines/index.js +9 -0
  33. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +433 -0
  34. package/dist/cjs/apps/markets/index.js +22 -12
  35. package/dist/cjs/apps/markets/state-machines/market-auction.js +116 -134
  36. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +131 -141
  37. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +163 -184
  38. package/dist/cjs/apps/markets/state-machines/market-prediction.js +226 -233
  39. package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
  40. package/dist/cjs/apps/oracles/index.js +3 -3
  41. package/dist/cjs/apps/privacy/index.js +67 -0
  42. package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
  43. package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
  44. package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
  45. package/dist/cjs/apps/staked-pool/assets.js +103 -0
  46. package/dist/cjs/apps/staked-pool/base.js +498 -0
  47. package/dist/cjs/apps/staked-pool/consumer.js +55 -0
  48. package/dist/cjs/apps/staked-pool/index.js +83 -0
  49. package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
  50. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
  51. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
  52. package/dist/cjs/errors.js +3 -3
  53. package/dist/cjs/generated/google/protobuf/struct.js +5 -5
  54. package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
  55. package/dist/cjs/generated/index.js +11 -7
  56. package/dist/cjs/generated/openapi.js +6 -0
  57. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +51 -51
  58. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +20 -21
  59. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +14 -14
  60. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +5 -5
  61. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +125 -131
  62. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +108 -108
  63. package/dist/cjs/generated/ottochain/v1/common.js +5 -5
  64. package/dist/cjs/generated/ottochain/v1/fiber.js +44 -6
  65. package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
  66. package/dist/cjs/generated/ottochain/v1/records.js +1 -1
  67. package/dist/cjs/index.js +58 -7
  68. package/dist/cjs/openapi.js +2 -0
  69. package/dist/cjs/ottochain/drop-nulls.js +1 -2
  70. package/dist/cjs/ottochain/genesis-manifest.js +17 -11
  71. package/dist/cjs/ottochain/index.js +23 -13
  72. package/dist/cjs/ottochain/metagraph-client.js +81 -16
  73. package/dist/cjs/ottochain/snapshot.js +13 -16
  74. package/dist/cjs/ottochain/transaction.js +67 -14
  75. package/dist/cjs/ottochain/types.js +16 -2
  76. package/dist/cjs/privacy/index.js +14 -0
  77. package/dist/cjs/privacy/sealed-bid.js +213 -0
  78. package/dist/cjs/privacy/shield-app.js +131 -0
  79. package/dist/cjs/schema/effects.js +156 -0
  80. package/dist/cjs/schema/fiber-app.js +150 -15
  81. package/dist/cjs/schema/guard-lint.js +343 -0
  82. package/dist/cjs/schema/guards.js +246 -0
  83. package/dist/cjs/signing.js +80 -0
  84. package/dist/cjs/templates/asset-policy.js +190 -0
  85. package/dist/cjs/templates/index.js +86 -0
  86. package/dist/cjs/templates/machine.js +130 -0
  87. package/dist/cjs/templates/migration.js +39 -0
  88. package/dist/cjs/templates/state-shape.js +38 -0
  89. package/dist/cjs/types.js +2 -3
  90. package/dist/cjs/validation.js +9 -11
  91. package/dist/cjs/verify.js +9 -4
  92. package/dist/cjs/zk/commit.js +53 -0
  93. package/dist/cjs/zk/guard.js +107 -0
  94. package/dist/cjs/zk/index.js +48 -0
  95. package/dist/cjs/zk/preimage.js +37 -0
  96. package/dist/cjs/zk/prover.js +87 -0
  97. package/dist/cjs/zk/registry.js +62 -0
  98. package/dist/cjs/zk/types.js +28 -0
  99. package/dist/cjs/zk/witness.js +19 -0
  100. package/dist/esm/apps/compute/index.js +29 -0
  101. package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
  102. package/dist/esm/apps/compute/state-machines/index.js +5 -0
  103. package/dist/esm/apps/contracts/index.js +9 -5
  104. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +135 -162
  105. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +193 -171
  106. package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
  107. package/dist/esm/apps/corporate/index.js +2 -2
  108. package/dist/esm/apps/corporate/state-machines/corp-board.js +501 -457
  109. package/dist/esm/apps/corporate/state-machines/corp-entity.js +488 -362
  110. package/dist/esm/apps/corporate/state-machines/corp-securities.js +770 -577
  111. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +568 -558
  112. package/dist/esm/apps/governance/index.js +10 -10
  113. package/dist/esm/apps/governance/state-machines/dao-multisig.js +189 -210
  114. package/dist/esm/apps/governance/state-machines/dao-reputation.js +182 -229
  115. package/dist/esm/apps/governance/state-machines/dao-single.js +106 -89
  116. package/dist/esm/apps/governance/state-machines/dao-token.js +200 -228
  117. package/dist/esm/apps/governance/state-machines/governance-simple.js +232 -232
  118. package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
  119. package/dist/esm/apps/identity/constants.js +52 -21
  120. package/dist/esm/apps/identity/index.js +14 -9
  121. package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
  122. package/dist/esm/apps/identity/state-machines/identity-oracle.js +159 -174
  123. package/dist/esm/apps/identity/state-machines/identity-registry.js +259 -0
  124. package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
  125. package/dist/esm/apps/identity/state-machines/index.js +1 -0
  126. package/dist/esm/apps/index.js +9 -5
  127. package/dist/esm/apps/lending/assets.js +231 -0
  128. package/dist/esm/apps/lending/credit-scoring.js +81 -0
  129. package/dist/esm/apps/lending/eligibility.js +99 -0
  130. package/dist/esm/apps/lending/index.js +69 -0
  131. package/dist/esm/apps/lending/state-machines/index.js +5 -0
  132. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +430 -0
  133. package/dist/esm/apps/markets/index.js +11 -7
  134. package/dist/esm/apps/markets/state-machines/market-auction.js +117 -135
  135. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +132 -142
  136. package/dist/esm/apps/markets/state-machines/market-group-buy.js +164 -185
  137. package/dist/esm/apps/markets/state-machines/market-prediction.js +227 -234
  138. package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
  139. package/dist/esm/apps/oracles/index.js +3 -3
  140. package/dist/esm/apps/privacy/index.js +56 -0
  141. package/dist/esm/apps/privacy/state-machines/index.js +6 -0
  142. package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
  143. package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
  144. package/dist/esm/apps/staked-pool/assets.js +91 -0
  145. package/dist/esm/apps/staked-pool/base.js +493 -0
  146. package/dist/esm/apps/staked-pool/consumer.js +49 -0
  147. package/dist/esm/apps/staked-pool/index.js +60 -0
  148. package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
  149. package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
  150. package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
  151. package/dist/esm/generated/google/protobuf/struct.js +1 -1
  152. package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
  153. package/dist/esm/generated/index.js +9 -5
  154. package/dist/esm/generated/openapi.js +5 -0
  155. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +47 -47
  156. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  157. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
  158. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  159. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +115 -121
  160. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +101 -101
  161. package/dist/esm/generated/ottochain/v1/common.js +1 -1
  162. package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
  163. package/dist/esm/generated/ottochain/v1/messages.js +1 -1
  164. package/dist/esm/generated/ottochain/v1/records.js +1 -1
  165. package/dist/esm/index.js +28 -3
  166. package/dist/esm/openapi.js +1 -0
  167. package/dist/esm/ottochain/genesis-manifest.js +15 -9
  168. package/dist/esm/ottochain/index.js +2 -3
  169. package/dist/esm/ottochain/metagraph-client.js +81 -16
  170. package/dist/esm/ottochain/snapshot.js +6 -8
  171. package/dist/esm/ottochain/transaction.js +51 -3
  172. package/dist/esm/ottochain/types.js +15 -1
  173. package/dist/esm/privacy/index.js +6 -0
  174. package/dist/esm/privacy/sealed-bid.js +209 -0
  175. package/dist/esm/privacy/shield-app.js +127 -0
  176. package/dist/esm/schema/effects.js +145 -0
  177. package/dist/esm/schema/fiber-app.js +139 -8
  178. package/dist/esm/schema/guard-lint.js +337 -0
  179. package/dist/esm/schema/guards.js +228 -0
  180. package/dist/esm/signing.js +74 -0
  181. package/dist/esm/templates/asset-policy.js +182 -0
  182. package/dist/esm/templates/index.js +41 -0
  183. package/dist/esm/templates/machine.js +125 -0
  184. package/dist/esm/templates/migration.js +34 -0
  185. package/dist/esm/templates/state-shape.js +34 -0
  186. package/dist/esm/validation.js +1 -3
  187. package/dist/esm/verify.js +8 -2
  188. package/dist/esm/zk/commit.js +44 -0
  189. package/dist/esm/zk/guard.js +99 -0
  190. package/dist/esm/zk/index.js +19 -0
  191. package/dist/esm/zk/preimage.js +30 -0
  192. package/dist/esm/zk/prover.js +82 -0
  193. package/dist/esm/zk/registry.js +55 -0
  194. package/dist/esm/zk/types.js +25 -0
  195. package/dist/esm/zk/witness.js +15 -0
  196. package/dist/types/apps/compute/index.d.ts +176 -0
  197. package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
  198. package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
  199. package/dist/types/apps/contracts/index.d.ts +81 -221
  200. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +23 -98
  201. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +49 -115
  202. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
  203. package/dist/types/apps/corporate/index.d.ts +1176 -440
  204. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +271 -135
  205. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +279 -74
  206. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +373 -149
  207. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +252 -80
  208. package/dist/types/apps/governance/index.d.ts +368 -470
  209. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +92 -107
  210. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +61 -85
  211. package/dist/types/apps/governance/state-machines/dao-single.d.ts +25 -47
  212. package/dist/types/apps/governance/state-machines/dao-token.d.ts +79 -68
  213. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +95 -125
  214. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +6 -6
  215. package/dist/types/apps/identity/constants.d.ts +33 -5
  216. package/dist/types/apps/identity/index.d.ts +415 -131
  217. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
  218. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +27 -98
  219. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
  220. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
  221. package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
  222. package/dist/types/apps/index.d.ts +9 -5
  223. package/dist/types/apps/lending/assets.d.ts +258 -0
  224. package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
  225. package/dist/types/apps/lending/eligibility.d.ts +83 -0
  226. package/dist/types/apps/lending/index.d.ts +556 -0
  227. package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
  228. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +536 -0
  229. package/dist/types/apps/markets/index.d.ts +181 -276
  230. package/dist/types/apps/markets/state-machines/market-auction.d.ts +25 -49
  231. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +35 -53
  232. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +35 -61
  233. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +65 -86
  234. package/dist/types/apps/markets/state-machines/market-universal.d.ts +12 -12
  235. package/dist/types/apps/oracles/index.d.ts +1 -1
  236. package/dist/types/apps/privacy/index.d.ts +328 -0
  237. package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
  238. package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
  239. package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
  240. package/dist/types/apps/staked-pool/assets.d.ts +53 -0
  241. package/dist/types/apps/staked-pool/base.d.ts +80 -0
  242. package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
  243. package/dist/types/apps/staked-pool/index.d.ts +51 -0
  244. package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
  245. package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
  246. package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
  247. package/dist/types/generated/index.d.ts +5 -5
  248. package/dist/types/generated/openapi.d.ts +1270 -0
  249. package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
  250. package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
  251. package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
  252. package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
  253. package/dist/types/index.d.ts +7 -3
  254. package/dist/types/openapi.d.ts +24 -0
  255. package/dist/types/ottochain/genesis-manifest.d.ts +11 -5
  256. package/dist/types/ottochain/index.d.ts +5 -6
  257. package/dist/types/ottochain/metagraph-client.d.ts +49 -7
  258. package/dist/types/ottochain/snapshot.d.ts +6 -6
  259. package/dist/types/ottochain/transaction.d.ts +41 -1
  260. package/dist/types/ottochain/types.d.ts +336 -31
  261. package/dist/types/privacy/index.d.ts +6 -0
  262. package/dist/types/privacy/sealed-bid.d.ts +348 -0
  263. package/dist/types/privacy/shield-app.d.ts +48 -0
  264. package/dist/types/schema/effects.d.ts +141 -0
  265. package/dist/types/schema/fiber-app.d.ts +282 -2
  266. package/dist/types/schema/guard-lint.d.ts +111 -0
  267. package/dist/types/schema/guards.d.ts +146 -0
  268. package/dist/types/signing.d.ts +45 -0
  269. package/dist/types/templates/asset-policy.d.ts +119 -0
  270. package/dist/types/templates/index.d.ts +26 -0
  271. package/dist/types/templates/machine.d.ts +139 -0
  272. package/dist/types/templates/migration.d.ts +34 -0
  273. package/dist/types/templates/state-shape.d.ts +30 -0
  274. package/dist/types/validation.d.ts +22 -217
  275. package/dist/types/verify.d.ts +4 -0
  276. package/dist/types/zk/commit.d.ts +28 -0
  277. package/dist/types/zk/guard.d.ts +46 -0
  278. package/dist/types/zk/index.d.ts +19 -0
  279. package/dist/types/zk/preimage.d.ts +10 -0
  280. package/dist/types/zk/prover.d.ts +34 -0
  281. package/dist/types/zk/registry.d.ts +34 -0
  282. package/dist/types/zk/types.d.ts +33 -0
  283. package/dist/types/zk/witness.d.ts +40 -0
  284. package/package.json +47 -15
  285. package/dist/cjs/ottochain/normalize.js +0 -186
  286. package/dist/esm/ottochain/normalize.js +0 -179
  287. package/dist/types/ottochain/normalize.d.ts +0 -79
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Driving the SP1 zk-jlvm host (`rust/zk-jlvm/script`, `--mode groth16`) to produce a
3
+ * {@link Groth16Bundle} from a JLVM `expr` + `data`.
4
+ *
5
+ * THE load-bearing step: the host's guest hashes the RAW `--expr` / `--data` strings
6
+ * (`exprHash = keccak256(expr_bytes)`), so this driver feeds it `canonicalForSigning(expr)` /
7
+ * `canonicalForSigning(data)`. That makes a proof's `exprHash` word equal {@link exprHash}`(rule)`
8
+ * equal a policy's `logicHash` — without it the binding silently never matches.
9
+ *
10
+ * Proving is heavy (SP1; minutes, optionally `SP1_PROVER=cuda`) and needs the Rust toolchain, so this
11
+ * is an out-of-process driver, not an in-SDK prover. Point it at a prebuilt `binaryPath`, or at the
12
+ * crate via `cargoManifestPath`; configure either explicitly or through `ZK_JLVM_BIN` /
13
+ * `ZK_JLVM_MANIFEST` env vars.
14
+ */
15
+ import { canonicalForSigning } from './preimage';
16
+ const reLine = (label) => new RegExp(`^${label}:\\s*(0x[0-9a-fA-F]+)\\s*$`, 'm');
17
+ /** Parse the host's `vkey:` / `public values:` / `proof bytes:` stdout lines into a bundle. */
18
+ export function parseGroth16Stdout(stdout) {
19
+ const grab = (label, key) => {
20
+ const m = stdout.match(reLine(label));
21
+ if (!m)
22
+ throw new Error(`zk-jlvm host produced no "${label}:" line (could not read ${key})`);
23
+ return m[1].toLowerCase();
24
+ };
25
+ return {
26
+ vkey: grab('vkey', 'vkey'),
27
+ publicValues: grab('public values', 'publicValues'),
28
+ proof: grab('proof bytes', 'proof'),
29
+ };
30
+ }
31
+ /** Drives the zk-jlvm host out-of-process. */
32
+ export class SubprocessProver {
33
+ constructor(opts = {}) {
34
+ this.opts = opts;
35
+ }
36
+ async proveGroth16(req) {
37
+ // Canonicalize BEFORE proving so exprHash/dataHash bind the same bytes the chain signs over.
38
+ const expr = canonicalForSigning(req.expr);
39
+ const data = canonicalForSigning(req.data);
40
+ const modeArgs = ['--mode', 'groth16', '--expr', expr, '--data', data];
41
+ const binaryPath = this.opts.binaryPath ?? process.env.ZK_JLVM_BIN;
42
+ const manifest = this.opts.cargoManifestPath ?? process.env.ZK_JLVM_MANIFEST;
43
+ let command;
44
+ let args;
45
+ if (binaryPath) {
46
+ command = binaryPath;
47
+ args = modeArgs;
48
+ }
49
+ else if (manifest) {
50
+ command = 'cargo';
51
+ args = ['run', '--release', '--manifest-path', manifest, '--', ...modeArgs];
52
+ }
53
+ else {
54
+ throw new Error('SubprocessProver: set `binaryPath` (or ZK_JLVM_BIN), or `cargoManifestPath` (or ZK_JLVM_MANIFEST)');
55
+ }
56
+ const stdout = await this.run(command, args);
57
+ return parseGroth16Stdout(stdout);
58
+ }
59
+ run(command, args) {
60
+ const { env, cwd, timeoutMs = 1800000 } = this.opts;
61
+ // Lazy-load child_process so importing the zk slice stays light for non-proving consumers.
62
+ return import('node:child_process').then(({ spawn }) => new Promise((resolve, reject) => {
63
+ // argv (no shell) — `expr`/`data` are JSON with quotes/braces; never interpolate into a shell.
64
+ const child = spawn(command, args, {
65
+ cwd,
66
+ env: { ...process.env, ...env },
67
+ timeout: timeoutMs,
68
+ });
69
+ let out = '';
70
+ let err = '';
71
+ child.stdout.on('data', (d) => (out += d.toString()));
72
+ child.stderr.on('data', (d) => (err += d.toString()));
73
+ child.on('error', reject);
74
+ child.on('close', (code) => {
75
+ if (code === 0)
76
+ resolve(out);
77
+ else
78
+ reject(new Error(`zk-jlvm host exited ${code}: ${err.trim() || out.trim()}`));
79
+ });
80
+ }));
81
+ }
82
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The expression registry binds a human name → a published JLVM rule → its `logicHash`
3
+ * (`keccak256(canonicalize(rule))`). The `logicHash` is the load-bearing public value: it equals the
4
+ * `exprHash` word a zk-jlvm proof commits AND the literal a semi-private guard pins. Registering a
5
+ * rule with a LITERAL bound ("pin the bound into the rule", e.g. `{">=":[{"var":"score"},700]}`)
6
+ * makes "the proof's exprHash == this logicHash" mean "the hidden value satisfies THIS public,
7
+ * legible rule" — privacy of the value, transparency of the predicate.
8
+ */
9
+ import { exprHash } from './preimage';
10
+ /** A client-side registry mapping rule names to their canonical `logicHash`. */
11
+ export class ExprRegistry {
12
+ constructor() {
13
+ this.byName = new Map();
14
+ }
15
+ /** Register (or replace) a named rule; returns the entry with its computed `logicHash`. */
16
+ register(name, rule) {
17
+ const entry = { rule, logicHash: exprHash(rule) };
18
+ this.byName.set(name, entry);
19
+ return entry;
20
+ }
21
+ /** Whether a rule is registered under `name`. */
22
+ has(name) {
23
+ return this.byName.has(name);
24
+ }
25
+ /** The registered rule, or throw if unknown. */
26
+ ruleOf(name) {
27
+ return this.require(name).rule;
28
+ }
29
+ /** The registered rule's `logicHash`, or throw if unknown. */
30
+ logicHashOf(name) {
31
+ return this.require(name).logicHash;
32
+ }
33
+ /** All registered names, in insertion order. */
34
+ names() {
35
+ return [...this.byName.keys()];
36
+ }
37
+ require(name) {
38
+ const entry = this.byName.get(name);
39
+ if (!entry)
40
+ throw new Error(`ExprRegistry: no rule registered under "${name}"`);
41
+ return entry;
42
+ }
43
+ }
44
+ /**
45
+ * A single-bound predicate `{[op]:[{var:varName}, bound]}` — the "pinned bound" a proof binds to.
46
+ * `bound` stays a JSON primitive (number/string) so the canonical bytes the prover hashes match the
47
+ * canonical bytes the rule registers under (bigint is not JSON-serializable — pre-encode if needed).
48
+ */
49
+ export function boundRule(varName, op, bound) {
50
+ return { [op]: [{ var: varName }, bound] };
51
+ }
52
+ /** `{">=":[{"var":varName}, bound]}` — "the hidden `varName` is at least `bound`". */
53
+ export const atLeast = (varName, bound) => boundRule(varName, '>=', bound);
54
+ /** `{"<=":[{"var":varName}, bound]}` — "the hidden `varName` is at most `bound`". */
55
+ export const atMost = (varName, bound) => boundRule(varName, '<=', bound);
@@ -0,0 +1,25 @@
1
+ /**
2
+ * SP1 zk-jlvm public-values types + decode.
3
+ *
4
+ * The guest commits `abi_encode(JlvmPublicValues{ bytes32 exprHash, bytes32 dataHash,
5
+ * bytes32 outputHash, bool ok })` — four 32-byte words, the bool right-aligned in its word.
6
+ * There is no on-chain `jlvm_pv_decode` opcode: the chain guard parses the same blob with the
7
+ * native JLVM `cat`/`substr` ops. This decode mirrors that for client-side binding/inspection.
8
+ */
9
+ /**
10
+ * Decode `abi_encode(JlvmPublicValues)`: four 32-byte words `[exprHash | dataHash | outputHash | ok]`.
11
+ * The bool is right-aligned in its word (final byte `0x00`/`0x01`).
12
+ */
13
+ export function decodeJlvmPublicValues(pv) {
14
+ const b = pv.startsWith('0x') ? pv.slice(2) : pv;
15
+ if (b.length < 4 * 64) {
16
+ throw new Error(`publicValues too short: ${b.length} hex chars (need >= 256)`);
17
+ }
18
+ const word = (i) => `0x${b.slice(i * 64, i * 64 + 64)}`;
19
+ return {
20
+ exprHash: word(0),
21
+ dataHash: word(1),
22
+ outputHash: word(2),
23
+ ok: b.slice(3 * 64 + 62, 3 * 64 + 64) !== '00',
24
+ };
25
+ }
@@ -0,0 +1,15 @@
1
+ import { decodeJlvmPublicValues } from './types';
2
+ /**
3
+ * Shape a produced {@link Groth16Bundle} into the on-op witness map (`{publicValues, proof}`) and
4
+ * surface its decoded public values. The vkey rides in the guard, not the witness, so it is dropped.
5
+ */
6
+ export function groth16Witness(bundle) {
7
+ return {
8
+ witness: { publicValues: bundle.publicValues, proof: bundle.proof },
9
+ decoded: decodeJlvmPublicValues(bundle.publicValues),
10
+ };
11
+ }
12
+ /** Shape a Poseidon-Merkle inclusion path into the on-op `pmt_verify` witness map. */
13
+ export function pmtWitness(leaf, index, siblings) {
14
+ return { leaf, index, siblings };
15
+ }
@@ -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';