@ottochain/sdk 2.3.0 → 2.4.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 (209) hide show
  1. package/dist/cjs/apps/contracts/index.js +15 -8
  2. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +35 -40
  3. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +80 -37
  4. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +4 -4
  5. package/dist/cjs/apps/corporate/index.js +2 -2
  6. package/dist/cjs/apps/corporate/state-machines/corp-board.js +169 -59
  7. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +245 -47
  8. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +407 -99
  9. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +151 -37
  10. package/dist/cjs/apps/governance/index.js +14 -14
  11. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +58 -40
  12. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +46 -40
  13. package/dist/cjs/apps/governance/state-machines/dao-single.js +28 -11
  14. package/dist/cjs/apps/governance/state-machines/dao-token.js +67 -41
  15. package/dist/cjs/apps/governance/state-machines/governance-simple.js +93 -61
  16. package/dist/cjs/apps/governance/state-machines/governance-universal.js +2 -2
  17. package/dist/cjs/apps/identity/constants.js +55 -14
  18. package/dist/cjs/apps/identity/index.js +27 -11
  19. package/dist/cjs/apps/identity/state-machines/identity-agent.js +3 -3
  20. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +25 -22
  21. package/dist/cjs/apps/identity/state-machines/identity-registry.js +288 -0
  22. package/dist/cjs/apps/identity/state-machines/identity-universal.js +3 -3
  23. package/dist/cjs/apps/identity/state-machines/index.js +3 -1
  24. package/dist/cjs/apps/index.js +19 -8
  25. package/dist/cjs/apps/lending/assets.js +223 -0
  26. package/dist/cjs/apps/lending/credit-scoring.js +87 -0
  27. package/dist/cjs/apps/lending/eligibility.js +121 -0
  28. package/dist/cjs/apps/lending/index.js +91 -0
  29. package/dist/cjs/apps/lending/state-machines/index.js +9 -0
  30. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +412 -0
  31. package/dist/cjs/apps/markets/index.js +21 -11
  32. package/dist/cjs/apps/markets/state-machines/market-auction.js +14 -13
  33. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +29 -24
  34. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +24 -26
  35. package/dist/cjs/apps/markets/state-machines/market-prediction.js +80 -53
  36. package/dist/cjs/apps/markets/state-machines/market-universal.js +5 -5
  37. package/dist/cjs/apps/oracles/index.js +2 -2
  38. package/dist/cjs/errors.js +3 -3
  39. package/dist/cjs/generated/google/protobuf/struct.js +4 -4
  40. package/dist/cjs/generated/index.js +11 -7
  41. package/dist/cjs/generated/openapi.js +6 -0
  42. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +50 -50
  43. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +19 -20
  44. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +13 -13
  45. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +4 -4
  46. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +124 -130
  47. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +107 -107
  48. package/dist/cjs/generated/ottochain/v1/common.js +4 -4
  49. package/dist/cjs/generated/ottochain/v1/fiber.js +4 -4
  50. package/dist/cjs/index.js +41 -7
  51. package/dist/cjs/openapi.js +2 -0
  52. package/dist/cjs/ottochain/drop-nulls.js +1 -2
  53. package/dist/cjs/ottochain/genesis-manifest.js +11 -11
  54. package/dist/cjs/ottochain/index.js +23 -13
  55. package/dist/cjs/ottochain/metagraph-client.js +65 -8
  56. package/dist/cjs/ottochain/snapshot.js +11 -12
  57. package/dist/cjs/ottochain/transaction.js +57 -14
  58. package/dist/cjs/ottochain/types.js +16 -2
  59. package/dist/cjs/privacy/index.js +14 -0
  60. package/dist/cjs/privacy/sealed-bid.js +210 -0
  61. package/dist/cjs/privacy/shield-app.js +131 -0
  62. package/dist/cjs/schema/effects.js +40 -0
  63. package/dist/cjs/schema/fiber-app.js +19 -13
  64. package/dist/cjs/schema/guard-lint.js +352 -0
  65. package/dist/cjs/schema/guards.js +246 -0
  66. package/dist/cjs/signing.js +80 -0
  67. package/dist/cjs/types.js +2 -3
  68. package/dist/cjs/validation.js +8 -8
  69. package/dist/cjs/verify.js +9 -4
  70. package/dist/cjs/zk/commit.js +53 -0
  71. package/dist/cjs/zk/guard.js +107 -0
  72. package/dist/cjs/zk/index.js +48 -0
  73. package/dist/cjs/zk/preimage.js +37 -0
  74. package/dist/cjs/zk/prover.js +87 -0
  75. package/dist/cjs/zk/registry.js +62 -0
  76. package/dist/cjs/zk/types.js +28 -0
  77. package/dist/cjs/zk/witness.js +19 -0
  78. package/dist/esm/apps/contracts/index.js +7 -3
  79. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +35 -40
  80. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +80 -37
  81. package/dist/esm/apps/contracts/state-machines/contract-universal.js +4 -4
  82. package/dist/esm/apps/corporate/state-machines/corp-board.js +169 -59
  83. package/dist/esm/apps/corporate/state-machines/corp-entity.js +245 -47
  84. package/dist/esm/apps/corporate/state-machines/corp-securities.js +407 -99
  85. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +151 -37
  86. package/dist/esm/apps/governance/state-machines/dao-multisig.js +58 -40
  87. package/dist/esm/apps/governance/state-machines/dao-reputation.js +46 -40
  88. package/dist/esm/apps/governance/state-machines/dao-single.js +28 -11
  89. package/dist/esm/apps/governance/state-machines/dao-token.js +67 -41
  90. package/dist/esm/apps/governance/state-machines/governance-simple.js +93 -61
  91. package/dist/esm/apps/governance/state-machines/governance-universal.js +2 -2
  92. package/dist/esm/apps/identity/constants.js +51 -12
  93. package/dist/esm/apps/identity/index.js +12 -7
  94. package/dist/esm/apps/identity/state-machines/identity-agent.js +3 -3
  95. package/dist/esm/apps/identity/state-machines/identity-oracle.js +25 -22
  96. package/dist/esm/apps/identity/state-machines/identity-registry.js +285 -0
  97. package/dist/esm/apps/identity/state-machines/identity-universal.js +3 -3
  98. package/dist/esm/apps/identity/state-machines/index.js +1 -0
  99. package/dist/esm/apps/index.js +1 -0
  100. package/dist/esm/apps/lending/assets.js +207 -0
  101. package/dist/esm/apps/lending/credit-scoring.js +81 -0
  102. package/dist/esm/apps/lending/eligibility.js +115 -0
  103. package/dist/esm/apps/lending/index.js +69 -0
  104. package/dist/esm/apps/lending/state-machines/index.js +5 -0
  105. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +409 -0
  106. package/dist/esm/apps/markets/index.js +8 -4
  107. package/dist/esm/apps/markets/state-machines/market-auction.js +14 -13
  108. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +29 -24
  109. package/dist/esm/apps/markets/state-machines/market-group-buy.js +24 -26
  110. package/dist/esm/apps/markets/state-machines/market-prediction.js +80 -53
  111. package/dist/esm/apps/markets/state-machines/market-universal.js +5 -5
  112. package/dist/esm/generated/index.js +9 -5
  113. package/dist/esm/generated/openapi.js +5 -0
  114. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +46 -46
  115. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +114 -120
  116. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +100 -100
  117. package/dist/esm/index.js +21 -2
  118. package/dist/esm/openapi.js +1 -0
  119. package/dist/esm/ottochain/genesis-manifest.js +9 -9
  120. package/dist/esm/ottochain/index.js +2 -3
  121. package/dist/esm/ottochain/metagraph-client.js +65 -8
  122. package/dist/esm/ottochain/snapshot.js +4 -4
  123. package/dist/esm/ottochain/transaction.js +43 -3
  124. package/dist/esm/ottochain/types.js +15 -1
  125. package/dist/esm/privacy/index.js +6 -0
  126. package/dist/esm/privacy/sealed-bid.js +206 -0
  127. package/dist/esm/privacy/shield-app.js +127 -0
  128. package/dist/esm/schema/effects.js +35 -0
  129. package/dist/esm/schema/fiber-app.js +13 -6
  130. package/dist/esm/schema/guard-lint.js +346 -0
  131. package/dist/esm/schema/guards.js +229 -0
  132. package/dist/esm/signing.js +74 -0
  133. package/dist/esm/verify.js +8 -2
  134. package/dist/esm/zk/commit.js +44 -0
  135. package/dist/esm/zk/guard.js +99 -0
  136. package/dist/esm/zk/index.js +19 -0
  137. package/dist/esm/zk/preimage.js +30 -0
  138. package/dist/esm/zk/prover.js +82 -0
  139. package/dist/esm/zk/registry.js +55 -0
  140. package/dist/esm/zk/types.js +25 -0
  141. package/dist/esm/zk/witness.js +15 -0
  142. package/dist/types/apps/contracts/index.d.ts +69 -209
  143. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +20 -95
  144. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +46 -112
  145. package/dist/types/apps/corporate/index.d.ts +1040 -304
  146. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +188 -52
  147. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +267 -62
  148. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +355 -131
  149. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +225 -53
  150. package/dist/types/apps/governance/index.d.ts +296 -398
  151. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +77 -92
  152. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +42 -66
  153. package/dist/types/apps/governance/state-machines/dao-single.d.ts +25 -47
  154. package/dist/types/apps/governance/state-machines/dao-token.d.ts +60 -49
  155. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +87 -117
  156. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +2 -2
  157. package/dist/types/apps/identity/constants.d.ts +32 -4
  158. package/dist/types/apps/identity/index.d.ts +378 -94
  159. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +16 -87
  160. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
  161. package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
  162. package/dist/types/apps/index.d.ts +1 -0
  163. package/dist/types/apps/lending/assets.d.ts +258 -0
  164. package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
  165. package/dist/types/apps/lending/eligibility.d.ts +83 -0
  166. package/dist/types/apps/lending/index.d.ts +548 -0
  167. package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
  168. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +528 -0
  169. package/dist/types/apps/markets/index.d.ts +108 -203
  170. package/dist/types/apps/markets/state-machines/market-auction.d.ts +13 -37
  171. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +16 -34
  172. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +17 -43
  173. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +51 -72
  174. package/dist/types/apps/markets/state-machines/market-universal.d.ts +5 -5
  175. package/dist/types/generated/index.d.ts +5 -5
  176. package/dist/types/generated/openapi.d.ts +1257 -0
  177. package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
  178. package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
  179. package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
  180. package/dist/types/index.d.ts +6 -2
  181. package/dist/types/openapi.d.ts +22 -0
  182. package/dist/types/ottochain/genesis-manifest.d.ts +5 -5
  183. package/dist/types/ottochain/index.d.ts +5 -6
  184. package/dist/types/ottochain/metagraph-client.d.ts +49 -7
  185. package/dist/types/ottochain/snapshot.d.ts +6 -6
  186. package/dist/types/ottochain/transaction.d.ts +33 -1
  187. package/dist/types/ottochain/types.d.ts +335 -30
  188. package/dist/types/privacy/index.d.ts +6 -0
  189. package/dist/types/privacy/sealed-bid.d.ts +348 -0
  190. package/dist/types/privacy/shield-app.d.ts +48 -0
  191. package/dist/types/schema/effects.d.ts +34 -0
  192. package/dist/types/schema/fiber-app.d.ts +1 -2
  193. package/dist/types/schema/guard-lint.d.ts +111 -0
  194. package/dist/types/schema/guards.d.ts +134 -0
  195. package/dist/types/signing.d.ts +45 -0
  196. package/dist/types/validation.d.ts +22 -217
  197. package/dist/types/verify.d.ts +4 -0
  198. package/dist/types/zk/commit.d.ts +28 -0
  199. package/dist/types/zk/guard.d.ts +46 -0
  200. package/dist/types/zk/index.d.ts +19 -0
  201. package/dist/types/zk/preimage.d.ts +10 -0
  202. package/dist/types/zk/prover.d.ts +34 -0
  203. package/dist/types/zk/registry.d.ts +34 -0
  204. package/dist/types/zk/types.d.ts +33 -0
  205. package/dist/types/zk/witness.d.ts +40 -0
  206. package/package.json +27 -13
  207. package/dist/cjs/ottochain/normalize.js +0 -186
  208. package/dist/esm/ottochain/normalize.js +0 -179
  209. package/dist/types/ottochain/normalize.d.ts +0 -79
@@ -0,0 +1,34 @@
1
+ import type { Groth16Bundle } from './types';
2
+ /** A request to prove that evaluating `expr` over `data` yields a result (raw JSON — canonicalized here). */
3
+ export interface Groth16ProveRequest {
4
+ /** The JLVM rule (plain JSON). Canonicalized before it reaches the prover. */
5
+ expr: unknown;
6
+ /** The (private) data context (plain JSON). Canonicalized before it reaches the prover. */
7
+ data: unknown;
8
+ }
9
+ /** Produces SP1-Groth16 bundles for the semi-private tier. Swap implementations in tests. */
10
+ export interface ZkProver {
11
+ proveGroth16(req: Groth16ProveRequest): Promise<Groth16Bundle>;
12
+ }
13
+ /** Configuration for {@link SubprocessProver}. Provide a binary OR a cargo manifest (binary wins). */
14
+ export interface SubprocessProverOptions {
15
+ /** Path to a prebuilt zk-jlvm host binary. Defaults to `ZK_JLVM_BIN`. */
16
+ binaryPath?: string;
17
+ /** Path to the zk-jlvm `script` crate's `Cargo.toml` (run via `cargo run --release`). Defaults to `ZK_JLVM_MANIFEST`. */
18
+ cargoManifestPath?: string;
19
+ /** Extra environment for the child (e.g. `{ SP1_PROVER: 'cuda' }`). Merged over `process.env`. */
20
+ env?: Record<string, string>;
21
+ /** Working directory for the child process. */
22
+ cwd?: string;
23
+ /** Hard timeout in ms. Default 1_800_000 (30 min) — SP1 Groth16 wrapping is slow. */
24
+ timeoutMs?: number;
25
+ }
26
+ /** Parse the host's `vkey:` / `public values:` / `proof bytes:` stdout lines into a bundle. */
27
+ export declare function parseGroth16Stdout(stdout: string): Groth16Bundle;
28
+ /** Drives the zk-jlvm host out-of-process. */
29
+ export declare class SubprocessProver implements ZkProver {
30
+ private readonly opts;
31
+ constructor(opts?: SubprocessProverOptions);
32
+ proveGroth16(req: Groth16ProveRequest): Promise<Groth16Bundle>;
33
+ private run;
34
+ }
@@ -0,0 +1,34 @@
1
+ /** A registered rule and the public `logicHash` that pins it on-chain and in proofs. */
2
+ export interface RegisteredRule {
3
+ /** The JLVM rule, as plain JSON (canonicalized when hashed and when fed to the prover). */
4
+ rule: unknown;
5
+ /** `keccak256(canonicalize(rule))` — the on-chain `logicHash` and a proof's `exprHash` word. */
6
+ logicHash: `0x${string}`;
7
+ }
8
+ /** A client-side registry mapping rule names to their canonical `logicHash`. */
9
+ export declare class ExprRegistry {
10
+ private readonly byName;
11
+ /** Register (or replace) a named rule; returns the entry with its computed `logicHash`. */
12
+ register(name: string, rule: unknown): RegisteredRule;
13
+ /** Whether a rule is registered under `name`. */
14
+ has(name: string): boolean;
15
+ /** The registered rule, or throw if unknown. */
16
+ ruleOf(name: string): unknown;
17
+ /** The registered rule's `logicHash`, or throw if unknown. */
18
+ logicHashOf(name: string): `0x${string}`;
19
+ /** All registered names, in insertion order. */
20
+ names(): string[];
21
+ private require;
22
+ }
23
+ /** The comparators a bound rule can pin a private value against. */
24
+ export type Comparator = '>=' | '>' | '<=' | '<' | '==' | '!=';
25
+ /**
26
+ * A single-bound predicate `{[op]:[{var:varName}, bound]}` — the "pinned bound" a proof binds to.
27
+ * `bound` stays a JSON primitive (number/string) so the canonical bytes the prover hashes match the
28
+ * canonical bytes the rule registers under (bigint is not JSON-serializable — pre-encode if needed).
29
+ */
30
+ export declare function boundRule(varName: string, op: Comparator, bound: number | string): Record<string, unknown>;
31
+ /** `{">=":[{"var":varName}, bound]}` — "the hidden `varName` is at least `bound`". */
32
+ export declare const atLeast: (varName: string, bound: number | string) => Record<string, unknown>;
33
+ /** `{"<=":[{"var":varName}, bound]}` — "the hidden `varName` is at most `bound`". */
34
+ export declare const atMost: (varName: string, bound: number | string) => Record<string, unknown>;
@@ -0,0 +1,33 @@
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
+ /** The decoded zk-jlvm public values: the keccak triple + the ok bit. */
10
+ export interface DecodedPublicValues {
11
+ /** keccak256(canonicalize(expr)) — pins WHICH JLVM rule ran (equals the registry logicHash). */
12
+ exprHash: `0x${string}`;
13
+ /** keccak256(canonicalize(data)) — the (private) data context's hash. */
14
+ dataHash: `0x${string}`;
15
+ /** keccak256(canonicalize(output)) — for a guarded "rule == true" proof, equals KECCAK_TRUE. */
16
+ outputHash: `0x${string}`;
17
+ /** Whether the JLVM evaluation succeeded (false ⇒ the guest aborted / errored). */
18
+ ok: boolean;
19
+ }
20
+ /** A produced SP1-Groth16 bundle from the zk-jlvm prover (`--mode groth16`). */
21
+ export interface Groth16Bundle {
22
+ /** `abi_encode(JlvmPublicValues)` as a `0x` hex string. */
23
+ publicValues: `0x${string}`;
24
+ /** SP1 Groth16 proof bytes as a `0x` hex string. */
25
+ proof: `0x${string}`;
26
+ /** The program verification key (`bytes32`) as a `0x` hex string. */
27
+ vkey: `0x${string}`;
28
+ }
29
+ /**
30
+ * Decode `abi_encode(JlvmPublicValues)`: four 32-byte words `[exprHash | dataHash | outputHash | ok]`.
31
+ * The bool is right-aligned in its word (final byte `0x00`/`0x01`).
32
+ */
33
+ export declare function decodeJlvmPublicValues(pv: `0x${string}`): DecodedPublicValues;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Witness shapers: turn a produced proof bundle (or a Merkle inclusion path) into the exact
3
+ * `JsonLogicValue` map a holder carries on a signed op's `witness` field. The combiner injects that
4
+ * map under the `witness` context key, and the policy guard reads `witness.publicValues` /
5
+ * `witness.proof` (groth16) or `witness.leaf` / `witness.index` / `witness.siblings` (pmt) — the
6
+ * shapes are fixed by metakit's guard opcodes (see ottochain ZkGatedMorphismSuite).
7
+ */
8
+ import type { FrHex } from './commit';
9
+ import { type DecodedPublicValues, type Groth16Bundle } from './types';
10
+ /** The on-op map a `groth16_verify` guard reads. The vkey is NOT here — it is a literal in the guard. */
11
+ export interface Groth16WitnessMap {
12
+ /** `abi_encode(JlvmPublicValues)` as `0x` hex — the guard's `witness.publicValues`. */
13
+ publicValues: `0x${string}`;
14
+ /** SP1-Groth16 proof bytes as `0x` hex — the guard's `witness.proof`. */
15
+ proof: `0x${string}`;
16
+ }
17
+ /** A groth16 witness ready to attach to an op, plus its decoded public values for client binding. */
18
+ export interface Groth16Witness {
19
+ /** Attach this to the op's `witness` field (it is a plain `JsonLogicValue` map). */
20
+ witness: Groth16WitnessMap;
21
+ /** The decoded `{exprHash, dataHash, outputHash, ok}` — inspect/bind BEFORE submitting. */
22
+ decoded: DecodedPublicValues;
23
+ }
24
+ /**
25
+ * Shape a produced {@link Groth16Bundle} into the on-op witness map (`{publicValues, proof}`) and
26
+ * surface its decoded public values. The vkey rides in the guard, not the witness, so it is dropped.
27
+ */
28
+ export declare function groth16Witness(bundle: Groth16Bundle): Groth16Witness;
29
+ /**
30
+ * The on-op map a `pmt_verify` guard reads. `siblings` is the authentication path in the order the
31
+ * `pmt_verify` opcode folds it (ROOT-FIRST / top-down, as produced by metakit's PoseidonMerkleTree);
32
+ * `index` is the leaf position. Pass values straight through from the tree builder — do not reorder.
33
+ */
34
+ export interface PmtWitnessMap {
35
+ leaf: FrHex;
36
+ index: number;
37
+ siblings: FrHex[];
38
+ }
39
+ /** Shape a Poseidon-Merkle inclusion path into the on-op `pmt_verify` witness map. */
40
+ export declare function pmtWitness(leaf: FrHex, index: number, siblings: FrHex[]): PmtWitnessMap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ottochain/sdk",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "TypeScript SDK for ottochain metagraph operations - signing, encoding, and network interactions",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -21,6 +21,11 @@
21
21
  "require": "./dist/cjs/ottochain/index.js",
22
22
  "types": "./dist/types/ottochain/index.d.ts"
23
23
  },
24
+ "./zk": {
25
+ "import": "./dist/esm/zk/index.js",
26
+ "require": "./dist/cjs/zk/index.js",
27
+ "types": "./dist/types/zk/index.d.ts"
28
+ },
24
29
  "./apps/identity": {
25
30
  "import": "./dist/esm/apps/identity/index.js",
26
31
  "require": "./dist/cjs/apps/identity/index.js",
@@ -36,6 +41,11 @@
36
41
  "require": "./dist/cjs/apps/markets/index.js",
37
42
  "types": "./dist/types/apps/markets/index.d.ts"
38
43
  },
44
+ "./apps/lending": {
45
+ "import": "./dist/esm/apps/lending/index.js",
46
+ "require": "./dist/cjs/apps/lending/index.js",
47
+ "types": "./dist/types/apps/lending/index.d.ts"
48
+ },
39
49
  "./apps/oracles": {
40
50
  "import": "./dist/esm/apps/oracles/index.js",
41
51
  "require": "./dist/cjs/apps/oracles/index.js",
@@ -77,6 +87,7 @@
77
87
  "lint": "eslint src tests",
78
88
  "format": "prettier --write src tests",
79
89
  "generate": "buf generate",
90
+ "gen:openapi": "openapi-typescript openapi/ottochain-openapi.json -o src/generated/openapi.ts",
80
91
  "lint:proto": "buf lint",
81
92
  "docs": "typedoc",
82
93
  "docs:watch": "typedoc --watch",
@@ -107,31 +118,34 @@
107
118
  },
108
119
  "dependencies": {
109
120
  "@bufbuild/protobuf": "^2.12.0",
110
- "@constellation-network/metagraph-sdk": "^0.2.0",
121
+ "@constellation-network/metagraph-sdk": "1.8.0-rc.5",
122
+ "@constellation-network/metagraph-sdk-jlvm": "1.8.0-rc.5",
123
+ "@noble/hashes": "^1.8.0",
111
124
  "@stardust-collective/dag4": "^2.6.0",
112
125
  "@stardust-collective/dag4-keystore": "^2.6.0",
113
126
  "canonicalize": "^3.0.0",
114
127
  "js-sha256": "^0.11.1",
115
128
  "js-sha512": "^0.9.0",
116
- "zod": "^3.22.0"
129
+ "zod": "^4.4.3"
117
130
  },
118
131
  "devDependencies": {
119
- "@babel/preset-env": "^7.29.0",
120
- "@commitlint/cli": "^20.5.2",
121
- "@commitlint/config-conventional": "^20.5.0",
122
- "@eslint/js": "^9.39.4",
132
+ "@babel/preset-env": "^7.29.7",
133
+ "@commitlint/cli": "^21.0.2",
134
+ "@commitlint/config-conventional": "^21.0.2",
135
+ "@eslint/js": "^10.0.1",
123
136
  "@jest/globals": "^30.3.0",
124
137
  "@types/jest": "^30.0.0",
125
- "@types/node": "^25.6.0",
126
- "@typescript-eslint/eslint-plugin": "^8.56.1",
127
- "@typescript-eslint/parser": "^8.59.0",
128
- "eslint": "^9.39.3",
138
+ "@types/node": "^25.9.3",
139
+ "@typescript-eslint/eslint-plugin": "^8.61.0",
140
+ "@typescript-eslint/parser": "^8.61.0",
141
+ "eslint": "^10.5.0",
129
142
  "jest": "^30.3.0",
130
- "prettier": "^3.8.3",
143
+ "openapi-typescript": "^7.13.0",
144
+ "prettier": "^3.8.4",
131
145
  "ts-jest": "29.4.9",
132
146
  "ts-proto": "^2.11.6",
133
147
  "typedoc": "^0.28.19",
134
- "typescript": "^5.0.0"
148
+ "typescript": "^6.0.3"
135
149
  },
136
150
  "peerDependencies": {
137
151
  "@stardust-collective/dag4": "^2.6.0"
@@ -1,186 +0,0 @@
1
- "use strict";
2
- /**
3
- * Normalize OttoChain Messages for Signing
4
- *
5
- * Converts OttoChain message objects to the wire format expected by the
6
- * Scala metagraph. Specifically, ensures all `Option[A]=None` fields are
7
- * present as explicit `null` values, matching what circe's magnolia encoder
8
- * produces on the Scala side.
9
- *
10
- * This is necessary because metakit's `JsonBinaryCodec.deriveDataUpdate`
11
- * (rc.8) canonicalizes the circe-encoded JSON **including null fields**.
12
- * If the TypeScript client omits optional fields (undefined), the canonical
13
- * JSON won't match and signature verification will fail.
14
- *
15
- * Schema mapping (Scala → TypeScript):
16
- * - `Option[A] = None` → `null` (must be explicit, not undefined/absent)
17
- * - `Option[A] = Some(v)` → `v`
18
- * - `List.empty` → `[]`
19
- * - `Map.empty` → `{}`
20
- */
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.normalizeMessage = exports.normalizeArchiveStateMachine = exports.normalizeTransitionStateMachine = exports.normalizeCreateStateMachine = void 0;
23
- /**
24
- * Normalize a State object for wire format
25
- */
26
- function normalizeState(state) {
27
- return {
28
- id: state.id,
29
- isFinal: state.isFinal ?? false,
30
- metadata: state.metadata ?? null,
31
- };
32
- }
33
- /**
34
- * Normalize a Transition object for wire format
35
- *
36
- * Scala Transition schema:
37
- * from: StateId (required)
38
- * to: StateId (required)
39
- * eventName: String (required)
40
- * guard: JsonLogicExpression (required)
41
- * effect: JsonLogicExpression (required)
42
- * dependencies: Set[UUID] = Set.empty
43
- *
44
- * `dependencies` serializes as `[]` when empty (default). Both `guard`
45
- * and `effect` are required non-optional fields.
46
- */
47
- function normalizeTransition(t) {
48
- return {
49
- from: t.from,
50
- to: t.to,
51
- eventName: t.eventName,
52
- guard: t.guard,
53
- effect: t.effect,
54
- dependencies: t.dependencies ?? [],
55
- };
56
- }
57
- /**
58
- * Check if a value looks like FiberAppMetadata (has 'name' and 'app' fields).
59
- * These TypeScript-only fields should be stripped before sending to metagraph.
60
- */
61
- function isFiberAppMetadata(value) {
62
- return (typeof value === 'object' &&
63
- value !== null &&
64
- 'name' in value &&
65
- 'app' in value);
66
- }
67
- /**
68
- * Normalize a StateMachineDefinition for wire format
69
- *
70
- * Strips FiberAppMetadata from the definition — the Scala schema expects
71
- * `metadata: Option[Json] = None`, not the TypeScript app metadata object.
72
- */
73
- function normalizeDefinition(def) {
74
- const states = def.states;
75
- const normalizedStates = {};
76
- if (states) {
77
- for (const [key, state] of Object.entries(states)) {
78
- normalizedStates[key] = normalizeState(state);
79
- }
80
- }
81
- const transitions = def.transitions ?? [];
82
- // Strip FiberAppMetadata if present — it's TypeScript-only, not part of wire format.
83
- // The Scala schema has `metadata: Option[Json] = None`, so use null for wire format.
84
- const wireMetadata = isFiberAppMetadata(def.metadata) ? null : (def.metadata ?? null);
85
- return {
86
- states: normalizedStates,
87
- initialState: def.initialState,
88
- transitions: transitions.map(normalizeTransition),
89
- metadata: wireMetadata,
90
- };
91
- }
92
- /**
93
- * Normalize a CreateStateMachine message for wire format
94
- *
95
- * Ensures all Option/default fields are explicit in wire format:
96
- * - definition.metadata → null when absent
97
- * - definition.states[*].metadata → null when absent
98
- * - definition.transitions[*].dependencies → [] when absent
99
- * - parentFiberId → null when absent
100
- *
101
- * @example
102
- * ```typescript
103
- * const message = normalizeCreateStateMachine({
104
- * fiberId: '...',
105
- * definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
106
- * initialData: {}
107
- * });
108
- * // message now has parentFiberId: null, definition.metadata: null, etc.
109
- * ```
110
- */
111
- function normalizeCreateStateMachine(msg) {
112
- return {
113
- fiberId: msg.fiberId,
114
- definition: normalizeDefinition(msg.definition),
115
- initialData: msg.initialData ?? {},
116
- parentFiberId: msg.parentFiberId ?? null,
117
- };
118
- }
119
- exports.normalizeCreateStateMachine = normalizeCreateStateMachine;
120
- /**
121
- * Normalize a TransitionStateMachine message for wire format
122
- *
123
- * Scala TransitionStateMachine schema:
124
- * fiberId: UUID (required)
125
- * eventName: String (required)
126
- * payload: JsonLogicValue (required)
127
- * targetSequenceNumber: FiberOrdinal (required)
128
- *
129
- * All fields are required — no Option types, so no null normalization needed.
130
- */
131
- function normalizeTransitionStateMachine(msg) {
132
- return {
133
- fiberId: msg.fiberId,
134
- eventName: msg.eventName,
135
- payload: msg.payload,
136
- targetSequenceNumber: msg.targetSequenceNumber,
137
- };
138
- }
139
- exports.normalizeTransitionStateMachine = normalizeTransitionStateMachine;
140
- /**
141
- * Normalize an ArchiveStateMachine message for wire format
142
- *
143
- * Scala ArchiveStateMachine schema:
144
- * fiberId: UUID (required)
145
- * targetSequenceNumber: FiberOrdinal (required)
146
- *
147
- * All fields are required — no Option types, so no null normalization needed.
148
- */
149
- function normalizeArchiveStateMachine(msg) {
150
- return {
151
- fiberId: msg.fiberId,
152
- targetSequenceNumber: msg.targetSequenceNumber,
153
- };
154
- }
155
- exports.normalizeArchiveStateMachine = normalizeArchiveStateMachine;
156
- /**
157
- * Normalize any OttochainMessage wrapper for wire format.
158
- *
159
- * Detects the message type from the wrapper key and applies the
160
- * appropriate normalization.
161
- *
162
- * @param message - OttochainMessage in wrapper format: `{ CreateStateMachine: {...} }`
163
- * @returns Normalized message with all Option fields as explicit null
164
- *
165
- * @example
166
- * ```typescript
167
- * const normalized = normalizeMessage({
168
- * CreateStateMachine: { fiberId: '...', definition: {...}, initialData: {} }
169
- * });
170
- * const signed = await signDataUpdate(normalized, privateKey);
171
- * ```
172
- */
173
- function normalizeMessage(message) {
174
- if ('CreateStateMachine' in message) {
175
- return { CreateStateMachine: normalizeCreateStateMachine(message.CreateStateMachine) };
176
- }
177
- if ('TransitionStateMachine' in message) {
178
- return { TransitionStateMachine: normalizeTransitionStateMachine(message.TransitionStateMachine) };
179
- }
180
- if ('ArchiveStateMachine' in message) {
181
- return { ArchiveStateMachine: normalizeArchiveStateMachine(message.ArchiveStateMachine) };
182
- }
183
- // CreateScript and InvokeScript — pass through (no optional fields)
184
- return message;
185
- }
186
- exports.normalizeMessage = normalizeMessage;
@@ -1,179 +0,0 @@
1
- /**
2
- * Normalize OttoChain Messages for Signing
3
- *
4
- * Converts OttoChain message objects to the wire format expected by the
5
- * Scala metagraph. Specifically, ensures all `Option[A]=None` fields are
6
- * present as explicit `null` values, matching what circe's magnolia encoder
7
- * produces on the Scala side.
8
- *
9
- * This is necessary because metakit's `JsonBinaryCodec.deriveDataUpdate`
10
- * (rc.8) canonicalizes the circe-encoded JSON **including null fields**.
11
- * If the TypeScript client omits optional fields (undefined), the canonical
12
- * JSON won't match and signature verification will fail.
13
- *
14
- * Schema mapping (Scala → TypeScript):
15
- * - `Option[A] = None` → `null` (must be explicit, not undefined/absent)
16
- * - `Option[A] = Some(v)` → `v`
17
- * - `List.empty` → `[]`
18
- * - `Map.empty` → `{}`
19
- */
20
- /**
21
- * Normalize a State object for wire format
22
- */
23
- function normalizeState(state) {
24
- return {
25
- id: state.id,
26
- isFinal: state.isFinal ?? false,
27
- metadata: state.metadata ?? null,
28
- };
29
- }
30
- /**
31
- * Normalize a Transition object for wire format
32
- *
33
- * Scala Transition schema:
34
- * from: StateId (required)
35
- * to: StateId (required)
36
- * eventName: String (required)
37
- * guard: JsonLogicExpression (required)
38
- * effect: JsonLogicExpression (required)
39
- * dependencies: Set[UUID] = Set.empty
40
- *
41
- * `dependencies` serializes as `[]` when empty (default). Both `guard`
42
- * and `effect` are required non-optional fields.
43
- */
44
- function normalizeTransition(t) {
45
- return {
46
- from: t.from,
47
- to: t.to,
48
- eventName: t.eventName,
49
- guard: t.guard,
50
- effect: t.effect,
51
- dependencies: t.dependencies ?? [],
52
- };
53
- }
54
- /**
55
- * Check if a value looks like FiberAppMetadata (has 'name' and 'app' fields).
56
- * These TypeScript-only fields should be stripped before sending to metagraph.
57
- */
58
- function isFiberAppMetadata(value) {
59
- return (typeof value === 'object' &&
60
- value !== null &&
61
- 'name' in value &&
62
- 'app' in value);
63
- }
64
- /**
65
- * Normalize a StateMachineDefinition for wire format
66
- *
67
- * Strips FiberAppMetadata from the definition — the Scala schema expects
68
- * `metadata: Option[Json] = None`, not the TypeScript app metadata object.
69
- */
70
- function normalizeDefinition(def) {
71
- const states = def.states;
72
- const normalizedStates = {};
73
- if (states) {
74
- for (const [key, state] of Object.entries(states)) {
75
- normalizedStates[key] = normalizeState(state);
76
- }
77
- }
78
- const transitions = def.transitions ?? [];
79
- // Strip FiberAppMetadata if present — it's TypeScript-only, not part of wire format.
80
- // The Scala schema has `metadata: Option[Json] = None`, so use null for wire format.
81
- const wireMetadata = isFiberAppMetadata(def.metadata) ? null : (def.metadata ?? null);
82
- return {
83
- states: normalizedStates,
84
- initialState: def.initialState,
85
- transitions: transitions.map(normalizeTransition),
86
- metadata: wireMetadata,
87
- };
88
- }
89
- /**
90
- * Normalize a CreateStateMachine message for wire format
91
- *
92
- * Ensures all Option/default fields are explicit in wire format:
93
- * - definition.metadata → null when absent
94
- * - definition.states[*].metadata → null when absent
95
- * - definition.transitions[*].dependencies → [] when absent
96
- * - parentFiberId → null when absent
97
- *
98
- * @example
99
- * ```typescript
100
- * const message = normalizeCreateStateMachine({
101
- * fiberId: '...',
102
- * definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
103
- * initialData: {}
104
- * });
105
- * // message now has parentFiberId: null, definition.metadata: null, etc.
106
- * ```
107
- */
108
- export function normalizeCreateStateMachine(msg) {
109
- return {
110
- fiberId: msg.fiberId,
111
- definition: normalizeDefinition(msg.definition),
112
- initialData: msg.initialData ?? {},
113
- parentFiberId: msg.parentFiberId ?? null,
114
- };
115
- }
116
- /**
117
- * Normalize a TransitionStateMachine message for wire format
118
- *
119
- * Scala TransitionStateMachine schema:
120
- * fiberId: UUID (required)
121
- * eventName: String (required)
122
- * payload: JsonLogicValue (required)
123
- * targetSequenceNumber: FiberOrdinal (required)
124
- *
125
- * All fields are required — no Option types, so no null normalization needed.
126
- */
127
- export function normalizeTransitionStateMachine(msg) {
128
- return {
129
- fiberId: msg.fiberId,
130
- eventName: msg.eventName,
131
- payload: msg.payload,
132
- targetSequenceNumber: msg.targetSequenceNumber,
133
- };
134
- }
135
- /**
136
- * Normalize an ArchiveStateMachine message for wire format
137
- *
138
- * Scala ArchiveStateMachine schema:
139
- * fiberId: UUID (required)
140
- * targetSequenceNumber: FiberOrdinal (required)
141
- *
142
- * All fields are required — no Option types, so no null normalization needed.
143
- */
144
- export function normalizeArchiveStateMachine(msg) {
145
- return {
146
- fiberId: msg.fiberId,
147
- targetSequenceNumber: msg.targetSequenceNumber,
148
- };
149
- }
150
- /**
151
- * Normalize any OttochainMessage wrapper for wire format.
152
- *
153
- * Detects the message type from the wrapper key and applies the
154
- * appropriate normalization.
155
- *
156
- * @param message - OttochainMessage in wrapper format: `{ CreateStateMachine: {...} }`
157
- * @returns Normalized message with all Option fields as explicit null
158
- *
159
- * @example
160
- * ```typescript
161
- * const normalized = normalizeMessage({
162
- * CreateStateMachine: { fiberId: '...', definition: {...}, initialData: {} }
163
- * });
164
- * const signed = await signDataUpdate(normalized, privateKey);
165
- * ```
166
- */
167
- export function normalizeMessage(message) {
168
- if ('CreateStateMachine' in message) {
169
- return { CreateStateMachine: normalizeCreateStateMachine(message.CreateStateMachine) };
170
- }
171
- if ('TransitionStateMachine' in message) {
172
- return { TransitionStateMachine: normalizeTransitionStateMachine(message.TransitionStateMachine) };
173
- }
174
- if ('ArchiveStateMachine' in message) {
175
- return { ArchiveStateMachine: normalizeArchiveStateMachine(message.ArchiveStateMachine) };
176
- }
177
- // CreateScript and InvokeScript — pass through (no optional fields)
178
- return message;
179
- }
@@ -1,79 +0,0 @@
1
- /**
2
- * Normalize OttoChain Messages for Signing
3
- *
4
- * Converts OttoChain message objects to the wire format expected by the
5
- * Scala metagraph. Specifically, ensures all `Option[A]=None` fields are
6
- * present as explicit `null` values, matching what circe's magnolia encoder
7
- * produces on the Scala side.
8
- *
9
- * This is necessary because metakit's `JsonBinaryCodec.deriveDataUpdate`
10
- * (rc.8) canonicalizes the circe-encoded JSON **including null fields**.
11
- * If the TypeScript client omits optional fields (undefined), the canonical
12
- * JSON won't match and signature verification will fail.
13
- *
14
- * Schema mapping (Scala → TypeScript):
15
- * - `Option[A] = None` → `null` (must be explicit, not undefined/absent)
16
- * - `Option[A] = Some(v)` → `v`
17
- * - `List.empty` → `[]`
18
- * - `Map.empty` → `{}`
19
- */
20
- /**
21
- * Normalize a CreateStateMachine message for wire format
22
- *
23
- * Ensures all Option/default fields are explicit in wire format:
24
- * - definition.metadata → null when absent
25
- * - definition.states[*].metadata → null when absent
26
- * - definition.transitions[*].dependencies → [] when absent
27
- * - parentFiberId → null when absent
28
- *
29
- * @example
30
- * ```typescript
31
- * const message = normalizeCreateStateMachine({
32
- * fiberId: '...',
33
- * definition: { states: { INIT: { id: { value: 'INIT' }, isFinal: false } }, ... },
34
- * initialData: {}
35
- * });
36
- * // message now has parentFiberId: null, definition.metadata: null, etc.
37
- * ```
38
- */
39
- export declare function normalizeCreateStateMachine(msg: Record<string, unknown>): Record<string, unknown>;
40
- /**
41
- * Normalize a TransitionStateMachine message for wire format
42
- *
43
- * Scala TransitionStateMachine schema:
44
- * fiberId: UUID (required)
45
- * eventName: String (required)
46
- * payload: JsonLogicValue (required)
47
- * targetSequenceNumber: FiberOrdinal (required)
48
- *
49
- * All fields are required — no Option types, so no null normalization needed.
50
- */
51
- export declare function normalizeTransitionStateMachine(msg: Record<string, unknown>): Record<string, unknown>;
52
- /**
53
- * Normalize an ArchiveStateMachine message for wire format
54
- *
55
- * Scala ArchiveStateMachine schema:
56
- * fiberId: UUID (required)
57
- * targetSequenceNumber: FiberOrdinal (required)
58
- *
59
- * All fields are required — no Option types, so no null normalization needed.
60
- */
61
- export declare function normalizeArchiveStateMachine(msg: Record<string, unknown>): Record<string, unknown>;
62
- /**
63
- * Normalize any OttochainMessage wrapper for wire format.
64
- *
65
- * Detects the message type from the wrapper key and applies the
66
- * appropriate normalization.
67
- *
68
- * @param message - OttochainMessage in wrapper format: `{ CreateStateMachine: {...} }`
69
- * @returns Normalized message with all Option fields as explicit null
70
- *
71
- * @example
72
- * ```typescript
73
- * const normalized = normalizeMessage({
74
- * CreateStateMachine: { fiberId: '...', definition: {...}, initialData: {} }
75
- * });
76
- * const signed = await signDataUpdate(normalized, privateKey);
77
- * ```
78
- */
79
- export declare function normalizeMessage(message: Record<string, unknown>): Record<string, unknown>;