@ottochain/sdk 2.2.5 → 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 (222) hide show
  1. package/dist/cjs/apps/contracts/index.js +15 -8
  2. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +89 -46
  3. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +152 -45
  4. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +40 -8
  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 +85 -43
  12. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +73 -43
  13. package/dist/cjs/apps/governance/state-machines/dao-single.js +55 -14
  14. package/dist/cjs/apps/governance/state-machines/dao-token.js +103 -45
  15. package/dist/cjs/apps/governance/state-machines/governance-simple.js +129 -65
  16. package/dist/cjs/apps/governance/state-machines/governance-universal.js +29 -5
  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 +57 -9
  20. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +70 -27
  21. package/dist/cjs/apps/identity/state-machines/identity-registry.js +288 -0
  22. package/dist/cjs/apps/identity/state-machines/identity-universal.js +30 -6
  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 +44 -19
  33. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +54 -29
  34. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +53 -31
  35. package/dist/cjs/apps/markets/state-machines/market-prediction.js +120 -61
  36. package/dist/cjs/apps/markets/state-machines/market-universal.js +50 -10
  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 +1722 -1
  49. package/dist/cjs/generated/ottochain/v1/fiber.js +355 -5
  50. package/dist/cjs/generated/ottochain/v1/messages.js +775 -3
  51. package/dist/cjs/generated/ottochain/v1/records.js +350 -3
  52. package/dist/cjs/index.js +45 -7
  53. package/dist/cjs/openapi.js +2 -0
  54. package/dist/cjs/ottochain/drop-nulls.js +1 -2
  55. package/dist/cjs/ottochain/genesis-manifest.js +193 -0
  56. package/dist/cjs/ottochain/index.js +27 -13
  57. package/dist/cjs/ottochain/metagraph-client.js +65 -8
  58. package/dist/cjs/ottochain/snapshot.js +11 -12
  59. package/dist/cjs/ottochain/transaction.js +57 -14
  60. package/dist/cjs/ottochain/types.js +19 -1
  61. package/dist/cjs/privacy/index.js +14 -0
  62. package/dist/cjs/privacy/sealed-bid.js +210 -0
  63. package/dist/cjs/privacy/shield-app.js +131 -0
  64. package/dist/cjs/schema/effects.js +40 -0
  65. package/dist/cjs/schema/fiber-app.js +19 -13
  66. package/dist/cjs/schema/guard-lint.js +352 -0
  67. package/dist/cjs/schema/guards.js +246 -0
  68. package/dist/cjs/signing.js +80 -0
  69. package/dist/cjs/types.js +2 -3
  70. package/dist/cjs/validation.js +8 -8
  71. package/dist/cjs/verify.js +9 -4
  72. package/dist/cjs/zk/commit.js +53 -0
  73. package/dist/cjs/zk/guard.js +107 -0
  74. package/dist/cjs/zk/index.js +48 -0
  75. package/dist/cjs/zk/preimage.js +37 -0
  76. package/dist/cjs/zk/prover.js +87 -0
  77. package/dist/cjs/zk/registry.js +62 -0
  78. package/dist/cjs/zk/types.js +28 -0
  79. package/dist/cjs/zk/witness.js +19 -0
  80. package/dist/esm/apps/contracts/index.js +7 -3
  81. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +89 -46
  82. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +152 -45
  83. package/dist/esm/apps/contracts/state-machines/contract-universal.js +40 -8
  84. package/dist/esm/apps/corporate/state-machines/corp-board.js +169 -59
  85. package/dist/esm/apps/corporate/state-machines/corp-entity.js +245 -47
  86. package/dist/esm/apps/corporate/state-machines/corp-securities.js +407 -99
  87. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +151 -37
  88. package/dist/esm/apps/governance/state-machines/dao-multisig.js +85 -43
  89. package/dist/esm/apps/governance/state-machines/dao-reputation.js +73 -43
  90. package/dist/esm/apps/governance/state-machines/dao-single.js +55 -14
  91. package/dist/esm/apps/governance/state-machines/dao-token.js +103 -45
  92. package/dist/esm/apps/governance/state-machines/governance-simple.js +129 -65
  93. package/dist/esm/apps/governance/state-machines/governance-universal.js +29 -5
  94. package/dist/esm/apps/identity/constants.js +51 -12
  95. package/dist/esm/apps/identity/index.js +12 -7
  96. package/dist/esm/apps/identity/state-machines/identity-agent.js +57 -9
  97. package/dist/esm/apps/identity/state-machines/identity-oracle.js +70 -27
  98. package/dist/esm/apps/identity/state-machines/identity-registry.js +285 -0
  99. package/dist/esm/apps/identity/state-machines/identity-universal.js +30 -6
  100. package/dist/esm/apps/identity/state-machines/index.js +1 -0
  101. package/dist/esm/apps/index.js +1 -0
  102. package/dist/esm/apps/lending/assets.js +207 -0
  103. package/dist/esm/apps/lending/credit-scoring.js +81 -0
  104. package/dist/esm/apps/lending/eligibility.js +115 -0
  105. package/dist/esm/apps/lending/index.js +69 -0
  106. package/dist/esm/apps/lending/state-machines/index.js +5 -0
  107. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +409 -0
  108. package/dist/esm/apps/markets/index.js +8 -4
  109. package/dist/esm/apps/markets/state-machines/market-auction.js +44 -19
  110. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +54 -29
  111. package/dist/esm/apps/markets/state-machines/market-group-buy.js +53 -31
  112. package/dist/esm/apps/markets/state-machines/market-prediction.js +120 -61
  113. package/dist/esm/apps/markets/state-machines/market-universal.js +50 -10
  114. package/dist/esm/generated/index.js +9 -5
  115. package/dist/esm/generated/openapi.js +5 -0
  116. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +46 -46
  117. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +114 -120
  118. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +100 -100
  119. package/dist/esm/generated/ottochain/v1/common.js +1718 -0
  120. package/dist/esm/generated/ottochain/v1/fiber.js +351 -1
  121. package/dist/esm/generated/ottochain/v1/messages.js +774 -2
  122. package/dist/esm/generated/ottochain/v1/records.js +349 -2
  123. package/dist/esm/index.js +23 -2
  124. package/dist/esm/openapi.js +1 -0
  125. package/dist/esm/ottochain/genesis-manifest.js +189 -0
  126. package/dist/esm/ottochain/index.js +4 -3
  127. package/dist/esm/ottochain/metagraph-client.js +65 -8
  128. package/dist/esm/ottochain/snapshot.js +4 -4
  129. package/dist/esm/ottochain/transaction.js +43 -3
  130. package/dist/esm/ottochain/types.js +18 -0
  131. package/dist/esm/privacy/index.js +6 -0
  132. package/dist/esm/privacy/sealed-bid.js +206 -0
  133. package/dist/esm/privacy/shield-app.js +127 -0
  134. package/dist/esm/schema/effects.js +35 -0
  135. package/dist/esm/schema/fiber-app.js +13 -6
  136. package/dist/esm/schema/guard-lint.js +346 -0
  137. package/dist/esm/schema/guards.js +229 -0
  138. package/dist/esm/signing.js +74 -0
  139. package/dist/esm/verify.js +8 -2
  140. package/dist/esm/zk/commit.js +44 -0
  141. package/dist/esm/zk/guard.js +99 -0
  142. package/dist/esm/zk/index.js +19 -0
  143. package/dist/esm/zk/preimage.js +30 -0
  144. package/dist/esm/zk/prover.js +82 -0
  145. package/dist/esm/zk/registry.js +55 -0
  146. package/dist/esm/zk/types.js +25 -0
  147. package/dist/esm/zk/witness.js +15 -0
  148. package/dist/types/apps/contracts/index.d.ts +159 -227
  149. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +50 -101
  150. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +86 -120
  151. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +20 -4
  152. package/dist/types/apps/corporate/index.d.ts +1040 -304
  153. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +188 -52
  154. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +267 -62
  155. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +355 -131
  156. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +225 -53
  157. package/dist/types/apps/governance/index.d.ts +396 -417
  158. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +92 -95
  159. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +57 -69
  160. package/dist/types/apps/governance/state-machines/dao-single.d.ts +40 -50
  161. package/dist/types/apps/governance/state-machines/dao-token.d.ts +80 -53
  162. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +107 -121
  163. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +17 -5
  164. package/dist/types/apps/identity/constants.d.ts +32 -4
  165. package/dist/types/apps/identity/index.d.ts +449 -100
  166. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +30 -0
  167. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +41 -87
  168. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
  169. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +15 -0
  170. package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
  171. package/dist/types/apps/index.d.ts +1 -0
  172. package/dist/types/apps/lending/assets.d.ts +258 -0
  173. package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
  174. package/dist/types/apps/lending/eligibility.d.ts +83 -0
  175. package/dist/types/apps/lending/index.d.ts +548 -0
  176. package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
  177. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +528 -0
  178. package/dist/types/apps/markets/index.d.ts +184 -204
  179. package/dist/types/apps/markets/state-machines/market-auction.d.ts +25 -37
  180. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +26 -34
  181. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +31 -43
  182. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +67 -72
  183. package/dist/types/apps/markets/state-machines/market-universal.d.ts +30 -10
  184. package/dist/types/generated/index.d.ts +5 -5
  185. package/dist/types/generated/openapi.d.ts +1257 -0
  186. package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
  187. package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
  188. package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
  189. package/dist/types/generated/ottochain/v1/common.d.ts +228 -0
  190. package/dist/types/generated/ottochain/v1/fiber.d.ts +32 -1
  191. package/dist/types/generated/ottochain/v1/messages.d.ts +84 -0
  192. package/dist/types/generated/ottochain/v1/records.d.ts +34 -0
  193. package/dist/types/index.d.ts +8 -2
  194. package/dist/types/openapi.d.ts +22 -0
  195. package/dist/types/ottochain/genesis-manifest.d.ts +130 -0
  196. package/dist/types/ottochain/index.d.ts +6 -5
  197. package/dist/types/ottochain/metagraph-client.d.ts +49 -7
  198. package/dist/types/ottochain/snapshot.d.ts +6 -6
  199. package/dist/types/ottochain/transaction.d.ts +33 -1
  200. package/dist/types/ottochain/types.d.ts +602 -11
  201. package/dist/types/privacy/index.d.ts +6 -0
  202. package/dist/types/privacy/sealed-bid.d.ts +348 -0
  203. package/dist/types/privacy/shield-app.d.ts +48 -0
  204. package/dist/types/schema/effects.d.ts +34 -0
  205. package/dist/types/schema/fiber-app.d.ts +41 -3
  206. package/dist/types/schema/guard-lint.d.ts +111 -0
  207. package/dist/types/schema/guards.d.ts +134 -0
  208. package/dist/types/signing.d.ts +45 -0
  209. package/dist/types/validation.d.ts +22 -217
  210. package/dist/types/verify.d.ts +4 -0
  211. package/dist/types/zk/commit.d.ts +28 -0
  212. package/dist/types/zk/guard.d.ts +46 -0
  213. package/dist/types/zk/index.d.ts +19 -0
  214. package/dist/types/zk/preimage.d.ts +10 -0
  215. package/dist/types/zk/prover.d.ts +34 -0
  216. package/dist/types/zk/registry.d.ts +34 -0
  217. package/dist/types/zk/types.d.ts +33 -0
  218. package/dist/types/zk/witness.d.ts +40 -0
  219. package/package.json +52 -35
  220. package/dist/cjs/ottochain/normalize.js +0 -186
  221. package/dist/esm/ottochain/normalize.js +0 -179
  222. package/dist/types/ottochain/normalize.d.ts +0 -79
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Genesis Manifest Exporter
3
+ *
4
+ * The ottochain metagraph can boot from a NON-EMPTY genesis: a set of standard
5
+ * packages pre-registered in the registry before any user transaction. This SDK
6
+ * is the source of truth for those std apps (their proto schemas + JSON-Logic
7
+ * state-machine definitions), so it is also the source of truth for the
8
+ * *genesis manifest* — the per-app CONTENT the chain needs to pre-register each
9
+ * package at genesis.
10
+ *
11
+ * DESIGN — content, not consensus hashes:
12
+ * The manifest ships CONTENT only: the `machineShape` (the typed, proto-faithful
13
+ * projection of the app's state message) and the `definition` (the JSON-Logic
14
+ * `StateMachineDefinition`, verbatim — the same object the chain decodes for any
15
+ * fiber). The CHAIN computes the consensus values itself from this content:
16
+ * - `logicHash` = `StateMachineDefinition.computeDigest(definition)`
17
+ * - `schemaHash` = commitment over the FileDescriptorSet (off-chain/Bridge)
18
+ * We deliberately do NOT replicate the chain's canonical hashing here, so there
19
+ * is ZERO hash-parity risk. No advisory hashes are emitted (see HONESTY notes in
20
+ * the PR description); add them later only if an off-chain consumer needs them,
21
+ * clearly marked advisory.
22
+ *
23
+ * NAMING — the reserved `std` label:
24
+ * Each package is named `std.<app>.package`. `RegistryName` reserves the `std`
25
+ * label in-protocol (`RegistryName.isReserved`), so ordinary user registrations
26
+ * of `std.*` are rejected — only the privileged genesis path may claim them.
27
+ * That is exactly the point: users cannot squat the standard names.
28
+ *
29
+ * SCHEMA SHAPES — chain-verified ground truth:
30
+ * The three `stateMessage` shapes are reproduced verbatim from the chain's own
31
+ * conformance suite (`StandardAppsConformanceSuite`, the `identity` / `proposal`
32
+ * / `market` `MessageShape` vals), which proves the on-chain shape validator and
33
+ * the conformance gate accept them. `commands` is left EMPTY for this first cut —
34
+ * the conformance suite itself models all three apps with `SortedMap.empty`
35
+ * commands, and the proto `*Request` messages are transaction-layer DTOs that do
36
+ * not map cleanly onto the universal state machines' free-form JSON-Logic event
37
+ * payloads. Deriving per-event command shapes is a flagged follow-up.
38
+ *
39
+ * The JSON shape emitted here is built to deserialize against the chain's circe
40
+ * codecs (`MachineShape` / `FieldShape` / `MessageShape` and
41
+ * `StateMachineDefinition`), whose magnolia config is camelCase with defaults.
42
+ *
43
+ * @packageDocumentation
44
+ */
45
+ import { identityUniversalDef } from '../apps/identity/state-machines/identity-universal.js';
46
+ import { govUniversalDef } from '../apps/governance/state-machines/governance-universal.js';
47
+ import { marketUniversalDef } from '../apps/markets/state-machines/market-universal.js';
48
+ import { toProtoDefinition } from '../schema/fiber-app.js';
49
+ /** Manifest schema version. Bump on any breaking change to the shape. */
50
+ export const GENESIS_MANIFEST_VERSION = 1;
51
+ // ─── Chain-verified state-message shapes ──────────────────────────────────────
52
+ // Reproduced VERBATIM from ottochain
53
+ // modules/shared-data/.../StandardAppsConformanceSuite.scala — the `identity`,
54
+ // `proposal`, and `market` MessageShape vals. Keep these byte-for-byte in step
55
+ // with that suite; it is what guarantees the chain accepts them.
56
+ /** Helper: a FieldShape with the two boolean defaults made explicit. */
57
+ function field(name, number, typeName, repeated = false, optional = false) {
58
+ return { name, number, typeName, repeated, optional };
59
+ }
60
+ /** ottochain.apps.identity.v1.Identity */
61
+ const identityStateMessage = {
62
+ typeName: 'ottochain.apps.identity.v1.Identity',
63
+ fields: [
64
+ field('id', 1, 'string'),
65
+ field('address', 2, 'string'),
66
+ field('public_key', 3, 'string'),
67
+ field('display_name', 4, 'string'),
68
+ field('identity_type', 5, 'ottochain.apps.identity.v1.Type'),
69
+ field('state', 6, 'ottochain.apps.identity.v1.State'),
70
+ field('reputation', 7, 'ottochain.apps.identity.v1.Reputation'),
71
+ field('stake', 8, 'int64'),
72
+ field('domains', 9, 'string', true),
73
+ field('platform_links', 10, 'ottochain.apps.identity.v1.PlatformLink', true),
74
+ field('penalty_history', 11, 'ottochain.apps.identity.v1.PenaltyEvent', true),
75
+ field('created_at', 12, 'google.protobuf.Timestamp'),
76
+ field('updated_at', 13, 'google.protobuf.Timestamp'),
77
+ ],
78
+ };
79
+ /** ottochain.apps.governance.v1.Proposal */
80
+ const governanceStateMessage = {
81
+ typeName: 'ottochain.apps.governance.v1.Proposal',
82
+ fields: [
83
+ field('id', 1, 'string'),
84
+ field('title', 2, 'string'),
85
+ field('description', 3, 'string'),
86
+ field('action_type', 4, 'string'),
87
+ field('payload', 5, 'google.protobuf.Struct'),
88
+ field('proposer', 6, 'string'),
89
+ field('proposed_at', 7, 'google.protobuf.Timestamp'),
90
+ field('deadline', 8, 'google.protobuf.Timestamp'),
91
+ field('queued_at', 9, 'google.protobuf.Timestamp'),
92
+ field('executable_at', 10, 'google.protobuf.Timestamp'),
93
+ ],
94
+ };
95
+ /** ottochain.apps.markets.v1.Market */
96
+ const marketStateMessage = {
97
+ typeName: 'ottochain.apps.markets.v1.Market',
98
+ fields: [
99
+ field('id', 1, 'string'),
100
+ field('market_type', 2, 'ottochain.apps.markets.v1.Type'),
101
+ field('creator', 3, 'string'),
102
+ field('title', 4, 'string'),
103
+ field('terms', 5, 'google.protobuf.Struct'),
104
+ field('deadline', 6, 'google.protobuf.Timestamp'),
105
+ field('threshold', 7, 'int64'),
106
+ field('commitments', 8, 'ottochain.apps.markets.v1.Commitment', true),
107
+ field('oracles', 9, 'string', true),
108
+ field('quorum', 10, 'int32'),
109
+ field('resolutions', 11, 'ottochain.apps.markets.v1.Resolution', true),
110
+ field('status', 12, 'ottochain.apps.markets.v1.State'),
111
+ field('created_at', 13, 'google.protobuf.Timestamp'),
112
+ field('updated_at', 14, 'google.protobuf.Timestamp'),
113
+ ],
114
+ };
115
+ // ─── Definition projection (single source of truth = the exported defs) ───────
116
+ /**
117
+ * Project a `FiberAppDefinition` into the chain's wire `StateMachineDefinition`,
118
+ * matching the `json-archive/*.json` convention exactly:
119
+ * - states carry explicit `metadata: null`,
120
+ * - transitions carry explicit `dependencies: []`,
121
+ * - the TypeScript-only `FiberAppMetadata` is stripped (`metadata: null`).
122
+ *
123
+ * Built on the shared `toProtoDefinition` projector so the manifest never drifts
124
+ * from the SDK's own exported app definitions. The chain decodes `dependencies:
125
+ * []` / `metadata: null` identically to their absent forms (its codecs use
126
+ * defaults), so this is consensus-equivalent to the archives while staying
127
+ * byte-identical to the checked-in `json-archive/*.json` files.
128
+ */
129
+ function toWireDefinition(def) {
130
+ const proto = toProtoDefinition(def);
131
+ const states = {};
132
+ for (const [key, st] of Object.entries(proto.states)) {
133
+ states[key] = { id: st.id, isFinal: st.isFinal, metadata: null };
134
+ }
135
+ return {
136
+ states,
137
+ initialState: proto.initialState,
138
+ transitions: proto.transitions.map((t) => ({
139
+ from: t.from,
140
+ to: t.to,
141
+ eventName: t.eventName,
142
+ guard: t.guard,
143
+ effect: t.effect,
144
+ dependencies: t.dependencies ?? [],
145
+ })),
146
+ // Strip FiberAppMetadata — the chain's `metadata` is `Option[JsonLogicValue]`.
147
+ metadata: null,
148
+ };
149
+ }
150
+ // ─── Builder ──────────────────────────────────────────────────────────────────
151
+ /**
152
+ * Assemble the genesis manifest for the standard apps.
153
+ *
154
+ * Covers THREE apps in this first cut — identity, governance, markets (all the
155
+ * `universal` variant). The other std apps (contracts, oracles, corporate) and
156
+ * non-universal variants are a flagged follow-up.
157
+ *
158
+ * @returns a `GenesisManifest` whose JSON deserializes against the chain's circe
159
+ * codecs. Hashes are intentionally absent — the chain derives them.
160
+ */
161
+ export function buildGenesisManifest() {
162
+ const packages = [
163
+ {
164
+ name: 'std.identity.package',
165
+ semver: '1.0.0',
166
+ strict: false,
167
+ metadata: {},
168
+ machineShape: { stateMessage: identityStateMessage, commands: {} },
169
+ definition: toWireDefinition(identityUniversalDef),
170
+ },
171
+ {
172
+ name: 'std.governance.package',
173
+ semver: '1.0.0',
174
+ strict: false,
175
+ metadata: {},
176
+ machineShape: { stateMessage: governanceStateMessage, commands: {} },
177
+ definition: toWireDefinition(govUniversalDef),
178
+ },
179
+ {
180
+ name: 'std.markets.package',
181
+ semver: '1.0.0',
182
+ strict: false,
183
+ metadata: {},
184
+ machineShape: { stateMessage: marketStateMessage, commands: {} },
185
+ definition: toWireDefinition(marketUniversalDef),
186
+ },
187
+ ];
188
+ return { version: GENESIS_MANIFEST_VERSION, packages };
189
+ }
@@ -8,13 +8,14 @@
8
8
  // Re-export generated protobuf types (for binary encoding)
9
9
  export * as proto from '../generated/index.js';
10
10
  // Runtime message type validation
11
- export { OTTOCHAIN_MESSAGE_TYPES } from './types.js';
11
+ export { OTTOCHAIN_MESSAGE_TYPES, TOKEN_BEHAVIOR_BITS } from './types.js';
12
12
  export { decodeOnChainState, getSnapshotOnChainState, getLatestOnChainState, getLogsForFiber, getEventReceipts, getScriptInvocations, extractOnChainState, } from './snapshot.js';
13
13
  export { MetagraphClient } from './metagraph-client.js';
14
14
  // Transaction helpers (state machine payloads, signing)
15
- export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, createStateMachinePayload, createScriptPayload, createDataTransactionRequest, } from './transaction.js';
15
+ export { createTransitionPayload, createArchivePayload, createInvokeScriptPayload, signTransaction, addTransactionSignature, getPublicKeyForRegistration, createStateMachinePayload, createScriptPayload, createDataTransactionRequest, createAssetPolicyPayload, createMintAssetPayload, createApplyMorphismPayload, createAuthorizeComposePayload, } from './transaction.js';
16
16
  // Data utilities
17
- export { normalizeCreateStateMachine, normalizeTransitionStateMachine, normalizeArchiveStateMachine, normalizeMessage, } from './normalize.js';
18
17
  export { dropNulls } from './drop-nulls.js';
18
+ // Genesis manifest exporter (std-app pre-registration content)
19
+ export { buildGenesisManifest, GENESIS_MANIFEST_VERSION } from './genesis-manifest.js';
19
20
  // Note: Governance and Corporate types are now in src/apps/
20
21
  // Import from '@ottochain/sdk/apps' instead
@@ -4,7 +4,7 @@
4
4
  * Client for interacting with ottochain ML0 custom routes (/v1 prefix)
5
5
  * and framework snapshot endpoints.
6
6
  *
7
- * @see modules/l0/src/main/scala/xyz/kd5ujc/metagraph_l0/ML0CustomRoutes.scala
7
+ * @see modules/l0/src/main/scala/xyz/kd5ujc/metagraph_l0/ML0Routes.scala
8
8
  * @see modules/data_l1/src/main/scala/xyz/kd5ujc/data_l1/DataL1CustomRoutes.scala
9
9
  * @packageDocumentation
10
10
  */
@@ -28,7 +28,7 @@ import { extractOnChainState } from './snapshot.js';
28
28
  * const onChain = await client.getOnChain();
29
29
  *
30
30
  * // Get all active state machines
31
- * const machines = await client.getStateMachines('Active');
31
+ * const machines = await client.getStateMachines('ACTIVE');
32
32
  *
33
33
  * // Get event receipts for a fiber
34
34
  * const events = await client.getStateMachineEvents(fiberId);
@@ -87,18 +87,18 @@ export class MetagraphClient {
87
87
  return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/events`);
88
88
  }
89
89
  /**
90
- * Get all script oracles, optionally filtered by status.
90
+ * Get all scripts, optionally filtered by status.
91
91
  */
92
92
  async getScripts(status) {
93
93
  const query = status ? `?status=${status}` : '';
94
- return this.ml0.get(`/data-application/v1/oracles${query}`);
94
+ return this.ml0.get(`/data-application/v1/scripts${query}`);
95
95
  }
96
96
  /**
97
- * Get a single script oracle by fiber ID.
97
+ * Get a single script by fiber ID.
98
98
  */
99
99
  async getScript(scriptId) {
100
100
  try {
101
- return await this.ml0.get(`/data-application/v1/oracles/${scriptId}`);
101
+ return await this.ml0.get(`/data-application/v1/scripts/${scriptId}`);
102
102
  }
103
103
  catch (error) {
104
104
  if (error instanceof NetworkError && error.statusCode === 404) {
@@ -108,10 +108,67 @@ export class MetagraphClient {
108
108
  }
109
109
  }
110
110
  /**
111
- * Get oracle invocations from the current ordinal's logs.
111
+ * Get script invocations from the current ordinal's logs.
112
112
  */
113
113
  async getScriptInvocations(scriptId) {
114
- return this.ml0.get(`/data-application/v1/oracles/${scriptId}/invocations`);
114
+ return this.ml0.get(`/data-application/v1/scripts/${scriptId}/invocations`);
115
+ }
116
+ // -------------------------------------------------------------------------
117
+ // Registry, audit, state-proofs, fee estimates (ML0 /data-application/v1/*)
118
+ // -------------------------------------------------------------------------
119
+ /** Get the metagraph version string. */
120
+ async getVersion() {
121
+ return this.ml0.get('/data-application/v1/version');
122
+ }
123
+ /** Get the full registry namespace, keyed by full registry name `labels.tld`. */
124
+ async getRegistry() {
125
+ return this.ml0.get('/data-application/v1/registry');
126
+ }
127
+ /** Resolve a single registry entry by full name (`labels.tld`), or null if unregistered. */
128
+ async getRegistryEntry(name) {
129
+ try {
130
+ return await this.ml0.get(`/data-application/v1/registry/${encodeURIComponent(name)}`);
131
+ }
132
+ catch (error) {
133
+ if (error instanceof NetworkError && error.statusCode === 404)
134
+ return null;
135
+ throw error;
136
+ }
137
+ }
138
+ /** Reverse-resolve a fiber UUID to its canonical registered name (#29), or null. */
139
+ async getReverseName(fiberId) {
140
+ try {
141
+ return await this.ml0.get(`/data-application/v1/registry/reverse/${fiberId}`);
142
+ }
143
+ catch (error) {
144
+ if (error instanceof NetworkError && error.statusCode === 404)
145
+ return null;
146
+ throw error;
147
+ }
148
+ }
149
+ /** Get the rendered audit-trail lines for a state-machine fiber. */
150
+ async getStateMachineAudit(fiberId) {
151
+ return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/audit`);
152
+ }
153
+ /** Light-client state proof for a field of a state-machine fiber, against the committed root. */
154
+ async getStateMachineStateProof(fiberId, field) {
155
+ return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/state-proof?field=${encodeURIComponent(field)}`);
156
+ }
157
+ /** Light-client state proof for a field of a script fiber. */
158
+ async getScriptStateProof(fiberId, field) {
159
+ return this.ml0.get(`/data-application/v1/scripts/${fiberId}/state-proof?field=${encodeURIComponent(field)}`);
160
+ }
161
+ /** Light-client state proof for a field of an asset instance. */
162
+ async getAssetStateProof(assetId, field) {
163
+ return this.ml0.get(`/data-application/v1/assets/${assetId}/state-proof?field=${encodeURIComponent(field)}`);
164
+ }
165
+ /** Estimate the fee/gas for a transition event on a state-machine fiber. */
166
+ async estimateTransitionFee(fiberId, eventName) {
167
+ return this.ml0.get(`/data-application/v1/state-machines/${fiberId}/estimate-fee?event=${encodeURIComponent(eventName)}`);
168
+ }
169
+ /** Estimate the fee/gas for invoking a script fiber. */
170
+ async estimateScriptFee(fiberId) {
171
+ return this.ml0.get(`/data-application/v1/scripts/${fiberId}/estimate-fee`);
115
172
  }
116
173
  // -------------------------------------------------------------------------
117
174
  // Framework snapshot endpoints (ML0 /snapshots/*)
@@ -73,7 +73,7 @@ export function getLogsForFiber(onChain, fiberId) {
73
73
  /**
74
74
  * Get EventReceipt log entries for a specific fiber.
75
75
  *
76
- * EventReceipts are distinguished from OracleInvocations by the presence
76
+ * EventReceipts are distinguished from ScriptInvocations by the presence
77
77
  * of the `eventName` field.
78
78
  *
79
79
  * @param onChain - Decoded on-chain state
@@ -85,14 +85,14 @@ export function getEventReceipts(onChain, fiberId) {
85
85
  .filter((entry) => 'eventName' in entry && 'success' in entry);
86
86
  }
87
87
  /**
88
- * Get OracleInvocation log entries for a specific fiber.
88
+ * Get ScriptInvocation log entries for a specific fiber.
89
89
  *
90
- * OracleInvocations are distinguished from EventReceipts by the presence
90
+ * ScriptInvocations are distinguished from EventReceipts by the presence
91
91
  * of the `method` field.
92
92
  *
93
93
  * @param onChain - Decoded on-chain state
94
94
  * @param fiberId - Fiber UUID to filter by
95
- * @returns Array of OracleInvocation entries
95
+ * @returns Array of ScriptInvocation entries
96
96
  */
97
97
  export function getScriptInvocations(onChain, fiberId) {
98
98
  return getLogsForFiber(onChain, fiberId)
@@ -4,10 +4,18 @@
4
4
  * These helpers create properly formatted payloads for the bridge's
5
5
  * self-signed mode, where clients sign their own transactions.
6
6
  */
7
- import { signDataUpdate, getPublicKeyId } from '@constellation-network/metagraph-sdk';
7
+ import { getPublicKeyId } from '@constellation-network/metagraph-sdk';
8
+ import { signDataUpdate } from '../signing.js';
8
9
  /**
9
10
  * Create a new state machine fiber payload.
10
11
  *
12
+ * @remarks
13
+ * `params.definition` is signed VERBATIM. Pass the output of `toProtoDefinition(def)` (the
14
+ * allowlisted wire shape) — NOT a raw `FiberAppDefinition`: extra authoring fields
15
+ * (`createSchema` / `stateSchema` / `eventSchemas` / per-transition `emits`) would be signed
16
+ * but re-encoded away by the chain, diverging the canonical → opaque `InvalidSignature`.
17
+ * See `tests/ottochain/signing-parity.test.ts`.
18
+ *
11
19
  * @param params - State machine creation parameters
12
20
  * @returns A CreateStateMachine message ready for signing
13
21
  *
@@ -94,7 +102,7 @@ export function createArchivePayload(params) {
94
102
  * },
95
103
  * },
96
104
  * initialState: { value: 0 },
97
- * accessControl: { type: 'open' },
105
+ * accessControl: { Public: {} },
98
106
  * });
99
107
  * const signed = await signTransaction(script, privateKey);
100
108
  * ```
@@ -105,7 +113,7 @@ export function createScriptPayload(params) {
105
113
  fiberId: params.fiberId,
106
114
  scriptProgram: params.scriptProgram,
107
115
  initialState: params.initialState ?? null,
108
- accessControl: params.accessControl ?? { type: 'open' },
116
+ accessControl: params.accessControl ?? { Public: {} },
109
117
  },
110
118
  };
111
119
  }
@@ -125,12 +133,41 @@ export function createInvokeScriptPayload(params) {
125
133
  },
126
134
  };
127
135
  }
136
+ // ============================================================================
137
+ // Asset Operations (asset-model.md §7)
138
+ // ============================================================================
139
+ //
140
+ // Thin typed wrappers: the chain message types ({@link CreateAssetPolicy}, etc.) already model
141
+ // every field (required vs `Option`), so these builders just apply the `{ MessageName: ... }`
142
+ // envelope, for API parity with the state-machine/script `create*Payload` helpers. Sign the result
143
+ // with {@link signTransaction} (the canonical `JCS(dropNulls)` path drops any omitted optionals).
144
+ /** Wrap a {@link CreateAssetPolicy} (publish an asset-policy package version). */
145
+ export function createAssetPolicyPayload(params) {
146
+ return { CreateAssetPolicy: params };
147
+ }
148
+ /** Wrap a {@link MintAsset} (mint a new asset instance against a resolved policy version). */
149
+ export function createMintAssetPayload(params) {
150
+ return { MintAsset: params };
151
+ }
152
+ /** Wrap an {@link ApplyMorphism} (apply a typed morphism to an asset instance). */
153
+ export function createApplyMorphismPayload(params) {
154
+ return { ApplyMorphism: params };
155
+ }
156
+ /** Wrap an {@link AuthorizeCompose} (commit half of the symmetric-compose handshake). */
157
+ export function createAuthorizeComposePayload(params) {
158
+ return { AuthorizeCompose: params };
159
+ }
128
160
  /**
129
161
  * Sign a transaction payload for self-signed mode.
130
162
  *
131
163
  * This creates a Signed<T> object with the exact format expected by the bridge's
132
164
  * `/agent/transition` endpoint when using self-signed mode.
133
165
  *
166
+ * The signature is computed over the null-dropped canonical bytes (null
167
+ * object fields removed recursively, array nulls preserved, then RFC 8785),
168
+ * matching metakit's content-hash rule. Explicit-null and absent optional
169
+ * fields therefore produce identical signatures.
170
+ *
134
171
  * @param message - The message to sign (e.g., from createTransitionPayload)
135
172
  * @param privateKey - The private key in hex format (64 characters)
136
173
  * @returns A signed object ready for submission to the bridge
@@ -199,6 +236,9 @@ export function createDataTransactionRequest(signed) {
199
236
  * Use this for multi-signature scenarios where multiple parties
200
237
  * need to sign the same transaction.
201
238
  *
239
+ * The new signature is computed over the null-dropped canonical bytes,
240
+ * matching metakit's content-hash rule (see {@link signTransaction}).
241
+ *
202
242
  * @param signed - The already-signed transaction
203
243
  * @param privateKey - Additional signer's private key
204
244
  * @returns Transaction with additional signature
@@ -7,6 +7,14 @@
7
7
  * @see modules/models/src/main/scala/xyz/kd5ujc/schema/
8
8
  * @packageDocumentation
9
9
  */
10
+ /** Bit weights for {@link TokenBehavior} (T=16, S=8, C=4, E=2, G=1). */
11
+ export const TOKEN_BEHAVIOR_BITS = {
12
+ transferable: 16,
13
+ splittable: 8,
14
+ combinable: 4,
15
+ expirable: 2,
16
+ governable: 1,
17
+ };
10
18
  /**
11
19
  * Names of all valid OttochainMessage types.
12
20
  * Use this for runtime validation (e.g., in API routes).
@@ -15,6 +23,16 @@ export const OTTOCHAIN_MESSAGE_TYPES = [
15
23
  'CreateStateMachine',
16
24
  'TransitionStateMachine',
17
25
  'ArchiveStateMachine',
26
+ 'UpgradeFiber',
18
27
  'CreateScript',
19
28
  'InvokeScript',
29
+ 'UpgradeScript',
30
+ 'PublishMachineVersion',
31
+ 'PublishScriptVersion',
32
+ 'SetVersionStatus',
33
+ 'RegisterAlias',
34
+ 'CreateAssetPolicy',
35
+ 'MintAsset',
36
+ 'ApplyMorphism',
37
+ 'AuthorizeCompose',
20
38
  ];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Privacy: shield any fiber app into a zk-jlvm-shielded private-state pool.
3
+ * See docs/design/zk-private-contract-state-rfc.md.
4
+ */
5
+ export { shieldApp, SHIELDED_POOL_STATE } from "./shield-app.js";
6
+ export { sealedBidAccountDef, shieldedSealedBidDef, vickreyAuctionDef } from "./sealed-bid.js";