@ottochain/sdk 2.4.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/dist/cjs/apps/compute/index.js +33 -0
  2. package/dist/cjs/apps/compute/state-machines/compute-rule110.js +164 -0
  3. package/dist/cjs/apps/compute/state-machines/index.js +9 -0
  4. package/dist/cjs/apps/contracts/index.js +1 -1
  5. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +126 -148
  6. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +153 -174
  7. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
  8. package/dist/cjs/apps/corporate/state-machines/corp-board.js +415 -481
  9. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +368 -440
  10. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +532 -647
  11. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +499 -603
  12. package/dist/cjs/apps/governance/index.js +7 -7
  13. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +170 -209
  14. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +161 -214
  15. package/dist/cjs/apps/governance/state-machines/dao-single.js +92 -92
  16. package/dist/cjs/apps/governance/state-machines/dao-token.js +169 -223
  17. package/dist/cjs/apps/governance/state-machines/governance-simple.js +185 -217
  18. package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
  19. package/dist/cjs/apps/identity/constants.js +16 -24
  20. package/dist/cjs/apps/identity/index.js +1 -1
  21. package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
  22. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +151 -169
  23. package/dist/cjs/apps/identity/state-machines/identity-registry.js +89 -115
  24. package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
  25. package/dist/cjs/apps/index.js +4 -1
  26. package/dist/cjs/apps/lending/assets.js +41 -17
  27. package/dist/cjs/apps/lending/credit-scoring.js +4 -4
  28. package/dist/cjs/apps/lending/eligibility.js +9 -25
  29. package/dist/cjs/apps/lending/index.js +1 -1
  30. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +177 -156
  31. package/dist/cjs/apps/markets/index.js +1 -1
  32. package/dist/cjs/apps/markets/state-machines/market-auction.js +115 -134
  33. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +122 -137
  34. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +158 -177
  35. package/dist/cjs/apps/markets/state-machines/market-prediction.js +193 -227
  36. package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
  37. package/dist/cjs/apps/oracles/index.js +1 -1
  38. package/dist/cjs/apps/privacy/index.js +67 -0
  39. package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
  40. package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
  41. package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
  42. package/dist/cjs/apps/staked-pool/assets.js +103 -0
  43. package/dist/cjs/apps/staked-pool/base.js +498 -0
  44. package/dist/cjs/apps/staked-pool/consumer.js +55 -0
  45. package/dist/cjs/apps/staked-pool/index.js +83 -0
  46. package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
  47. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
  48. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
  49. package/dist/cjs/generated/google/protobuf/struct.js +1 -1
  50. package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
  51. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +1 -1
  52. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  53. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +1 -1
  54. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  55. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +1 -1
  56. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1 -1
  57. package/dist/cjs/generated/ottochain/v1/common.js +1 -1
  58. package/dist/cjs/generated/ottochain/v1/fiber.js +40 -2
  59. package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
  60. package/dist/cjs/generated/ottochain/v1/records.js +1 -1
  61. package/dist/cjs/index.js +21 -3
  62. package/dist/cjs/ottochain/genesis-manifest.js +6 -0
  63. package/dist/cjs/ottochain/metagraph-client.js +63 -11
  64. package/dist/cjs/ottochain/snapshot.js +2 -4
  65. package/dist/cjs/ottochain/transaction.js +10 -0
  66. package/dist/cjs/privacy/sealed-bid.js +85 -82
  67. package/dist/cjs/privacy/shield-app.js +32 -32
  68. package/dist/cjs/schema/effects.js +145 -1
  69. package/dist/cjs/schema/fiber-app.js +139 -5
  70. package/dist/cjs/schema/guard-lint.js +3 -12
  71. package/dist/cjs/schema/guards.js +38 -38
  72. package/dist/cjs/templates/asset-policy.js +190 -0
  73. package/dist/cjs/templates/index.js +86 -0
  74. package/dist/cjs/templates/machine.js +130 -0
  75. package/dist/cjs/templates/migration.js +39 -0
  76. package/dist/cjs/templates/state-shape.js +38 -0
  77. package/dist/cjs/validation.js +1 -3
  78. package/dist/esm/apps/compute/index.js +29 -0
  79. package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
  80. package/dist/esm/apps/compute/state-machines/index.js +5 -0
  81. package/dist/esm/apps/contracts/index.js +4 -4
  82. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +128 -150
  83. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +155 -176
  84. package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
  85. package/dist/esm/apps/corporate/index.js +2 -2
  86. package/dist/esm/apps/corporate/state-machines/corp-board.js +418 -484
  87. package/dist/esm/apps/corporate/state-machines/corp-entity.js +371 -443
  88. package/dist/esm/apps/corporate/state-machines/corp-securities.js +535 -650
  89. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +502 -606
  90. package/dist/esm/apps/governance/index.js +10 -10
  91. package/dist/esm/apps/governance/state-machines/dao-multisig.js +172 -211
  92. package/dist/esm/apps/governance/state-machines/dao-reputation.js +163 -216
  93. package/dist/esm/apps/governance/state-machines/dao-single.js +94 -94
  94. package/dist/esm/apps/governance/state-machines/dao-token.js +171 -225
  95. package/dist/esm/apps/governance/state-machines/governance-simple.js +187 -219
  96. package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
  97. package/dist/esm/apps/identity/constants.js +18 -26
  98. package/dist/esm/apps/identity/index.js +8 -8
  99. package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
  100. package/dist/esm/apps/identity/state-machines/identity-oracle.js +153 -171
  101. package/dist/esm/apps/identity/state-machines/identity-registry.js +91 -117
  102. package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
  103. package/dist/esm/apps/index.js +9 -6
  104. package/dist/esm/apps/lending/assets.js +41 -17
  105. package/dist/esm/apps/lending/credit-scoring.js +6 -6
  106. package/dist/esm/apps/lending/eligibility.js +10 -26
  107. package/dist/esm/apps/lending/index.js +5 -5
  108. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +178 -157
  109. package/dist/esm/apps/markets/index.js +5 -5
  110. package/dist/esm/apps/markets/state-machines/market-auction.js +117 -136
  111. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +124 -139
  112. package/dist/esm/apps/markets/state-machines/market-group-buy.js +160 -179
  113. package/dist/esm/apps/markets/state-machines/market-prediction.js +195 -229
  114. package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
  115. package/dist/esm/apps/oracles/index.js +3 -3
  116. package/dist/esm/apps/privacy/index.js +56 -0
  117. package/dist/esm/apps/privacy/state-machines/index.js +6 -0
  118. package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
  119. package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
  120. package/dist/esm/apps/staked-pool/assets.js +91 -0
  121. package/dist/esm/apps/staked-pool/base.js +493 -0
  122. package/dist/esm/apps/staked-pool/consumer.js +49 -0
  123. package/dist/esm/apps/staked-pool/index.js +60 -0
  124. package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
  125. package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
  126. package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
  127. package/dist/esm/generated/google/protobuf/struct.js +1 -1
  128. package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
  129. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +1 -1
  130. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  131. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
  132. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  133. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +1 -1
  134. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1 -1
  135. package/dist/esm/generated/ottochain/v1/common.js +1 -1
  136. package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
  137. package/dist/esm/generated/ottochain/v1/messages.js +1 -1
  138. package/dist/esm/generated/ottochain/v1/records.js +1 -1
  139. package/dist/esm/index.js +10 -4
  140. package/dist/esm/ottochain/genesis-manifest.js +6 -0
  141. package/dist/esm/ottochain/metagraph-client.js +63 -11
  142. package/dist/esm/ottochain/snapshot.js +2 -4
  143. package/dist/esm/ottochain/transaction.js +8 -0
  144. package/dist/esm/privacy/index.js +2 -2
  145. package/dist/esm/privacy/sealed-bid.js +87 -84
  146. package/dist/esm/privacy/shield-app.js +33 -33
  147. package/dist/esm/schema/effects.js +137 -0
  148. package/dist/esm/schema/fiber-app.js +134 -5
  149. package/dist/esm/schema/guard-lint.js +3 -12
  150. package/dist/esm/schema/guards.js +36 -37
  151. package/dist/esm/templates/asset-policy.js +182 -0
  152. package/dist/esm/templates/index.js +41 -0
  153. package/dist/esm/templates/machine.js +125 -0
  154. package/dist/esm/templates/migration.js +34 -0
  155. package/dist/esm/templates/state-shape.js +34 -0
  156. package/dist/esm/validation.js +1 -3
  157. package/dist/esm/zk/index.js +4 -4
  158. package/dist/types/apps/compute/index.d.ts +176 -0
  159. package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
  160. package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
  161. package/dist/types/apps/contracts/index.d.ts +14 -14
  162. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +3 -3
  163. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +3 -3
  164. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
  165. package/dist/types/apps/corporate/index.d.ts +162 -162
  166. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +88 -88
  167. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +14 -14
  168. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +18 -18
  169. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +43 -43
  170. package/dist/types/apps/governance/index.d.ts +81 -81
  171. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +16 -16
  172. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +22 -22
  173. package/dist/types/apps/governance/state-machines/dao-token.d.ts +21 -21
  174. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +11 -11
  175. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +4 -4
  176. package/dist/types/apps/identity/constants.d.ts +2 -2
  177. package/dist/types/apps/identity/index.d.ts +70 -70
  178. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
  179. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +11 -11
  180. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +27 -27
  181. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
  182. package/dist/types/apps/index.d.ts +9 -6
  183. package/dist/types/apps/lending/assets.d.ts +2 -2
  184. package/dist/types/apps/lending/credit-scoring.d.ts +5 -5
  185. package/dist/types/apps/lending/eligibility.d.ts +2 -2
  186. package/dist/types/apps/lending/index.d.ts +20 -12
  187. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +15 -7
  188. package/dist/types/apps/markets/index.d.ts +76 -76
  189. package/dist/types/apps/markets/state-machines/market-auction.d.ts +12 -12
  190. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +19 -19
  191. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +18 -18
  192. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +15 -15
  193. package/dist/types/apps/markets/state-machines/market-universal.d.ts +7 -7
  194. package/dist/types/apps/oracles/index.d.ts +1 -1
  195. package/dist/types/apps/privacy/index.d.ts +328 -0
  196. package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
  197. package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
  198. package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
  199. package/dist/types/apps/staked-pool/assets.d.ts +53 -0
  200. package/dist/types/apps/staked-pool/base.d.ts +80 -0
  201. package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
  202. package/dist/types/apps/staked-pool/index.d.ts +51 -0
  203. package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
  204. package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
  205. package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
  206. package/dist/types/generated/openapi.d.ts +13 -0
  207. package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
  208. package/dist/types/index.d.ts +3 -3
  209. package/dist/types/openapi.d.ts +4 -2
  210. package/dist/types/ottochain/genesis-manifest.d.ts +6 -0
  211. package/dist/types/ottochain/index.d.ts +1 -1
  212. package/dist/types/ottochain/metagraph-client.d.ts +69 -15
  213. package/dist/types/ottochain/transaction.d.ts +9 -1
  214. package/dist/types/ottochain/types.d.ts +1 -1
  215. package/dist/types/privacy/index.d.ts +2 -2
  216. package/dist/types/privacy/sealed-bid.d.ts +9 -9
  217. package/dist/types/privacy/shield-app.d.ts +1 -1
  218. package/dist/types/schema/effects.d.ts +132 -0
  219. package/dist/types/schema/fiber-app.d.ts +281 -0
  220. package/dist/types/schema/guards.d.ts +12 -0
  221. package/dist/types/templates/asset-policy.d.ts +119 -0
  222. package/dist/types/templates/index.d.ts +26 -0
  223. package/dist/types/templates/machine.d.ts +139 -0
  224. package/dist/types/templates/migration.d.ts +34 -0
  225. package/dist/types/templates/state-shape.d.ts +30 -0
  226. package/dist/types/zk/index.d.ts +4 -4
  227. package/package.json +31 -13
@@ -11,45 +11,45 @@
11
11
  * (the Vickrey price). This is the one shared-state step, kept simple for v1; a zk settlement
12
12
  * proof that seals losers' amounts forever is the deferred upgrade (RFC §10).
13
13
  */
14
- import { defineFiberApp } from "../schema/fiber-app.js";
15
- import { shieldApp } from "./shield-app.js";
14
+ import { defineFiberApp } from '../schema/fiber-app.js';
15
+ import { shieldApp } from './shield-app.js';
16
16
  // ── 1. The private bid (base app, shielded by shieldApp) ──────────────────────
17
17
  /** The per-bidder PRIVATE state: a bid note `{ amount, bidder, nonce }`. */
18
18
  export const sealedBidAccountDef = defineFiberApp({
19
19
  metadata: {
20
- name: "SealedBidAccount",
21
- app: "markets",
22
- type: "sealed-bid-account",
23
- version: "1.0.0",
20
+ name: 'SealedBidAccount',
21
+ app: 'markets',
22
+ type: 'sealed-bid-account',
23
+ version: '1.0.0',
24
24
  description: "A single bidder's sealed bid (private amount). Shielded via shieldApp.",
25
25
  },
26
26
  stateSchema: {
27
27
  properties: {
28
- amount: { type: "number", description: "the (private) bid amount" },
29
- bidder: { type: "address" },
30
- nonce: { type: "number", description: "per-note randomness; keeps the commitment hiding" },
28
+ amount: { type: 'number', description: 'the (private) bid amount' },
29
+ bidder: { type: 'address' },
30
+ nonce: { type: 'number', description: 'per-note randomness; keeps the commitment hiding' },
31
31
  },
32
32
  },
33
33
  eventSchemas: {
34
34
  place_bid: {
35
- description: "Set the sealed bid amount",
36
- required: ["amount"],
37
- properties: { amount: { type: "number", minimum: 1 } },
35
+ description: 'Set the sealed bid amount',
36
+ required: ['amount'],
37
+ properties: { amount: { type: 'number', minimum: 1 } },
38
38
  },
39
39
  },
40
40
  states: {
41
- OPEN: { id: "OPEN", isFinal: false, metadata: { label: "Open", description: "No bid yet", category: "initial" } },
42
- BID: { id: "BID", isFinal: false, metadata: { label: "Bid", description: "Bid committed", category: "active" } },
41
+ OPEN: { id: 'OPEN', isFinal: false, metadata: { label: 'Open', description: 'No bid yet', category: 'initial' } },
42
+ BID: { id: 'BID', isFinal: false, metadata: { label: 'Bid', description: 'Bid committed', category: 'active' } },
43
43
  },
44
- initialState: "OPEN",
44
+ initialState: 'OPEN',
45
45
  transitions: [
46
46
  {
47
47
  // This effect is what the zk-jlvm-shielded circuit runs in-zkVM; `exprHash` pins it.
48
- from: "OPEN",
49
- to: "BID",
50
- eventName: "place_bid",
51
- guard: { ">": [{ var: "event.amount" }, 0] },
52
- effect: { merge: [{ var: "state" }, { amount: { var: "event.amount" } }] },
48
+ from: 'OPEN',
49
+ to: 'BID',
50
+ eventName: 'place_bid',
51
+ guard: { '>': [{ var: 'event.amount' }, 0] },
52
+ effect: { merge: [{ var: 'state' }, { amount: { var: 'event.amount' } }] },
53
53
  dependencies: [],
54
54
  },
55
55
  ],
@@ -70,60 +70,69 @@ export function shieldedSealedBidDef(opts) {
70
70
  */
71
71
  export const vickreyAuctionDef = defineFiberApp({
72
72
  metadata: {
73
- name: "VickreyAuction",
74
- app: "markets",
75
- type: "vickrey-auction",
76
- version: "1.0.0",
77
- description: "Sealed-bid second-price auction: public reveal-then-tally over shielded bids.",
78
- crossReferences: { bidPool: "the ShieldedSealedBidAccount pool holding the sealed bids" },
73
+ name: 'VickreyAuction',
74
+ app: 'markets',
75
+ type: 'vickrey-auction',
76
+ version: '1.0.0',
77
+ description: 'Sealed-bid second-price auction: public reveal-then-tally over shielded bids.',
78
+ crossReferences: { bidPool: 'the ShieldedSealedBidAccount pool holding the sealed bids' },
79
79
  },
80
80
  createSchema: {
81
- required: ["seller", "deadline"],
81
+ required: ['seller', 'deadline'],
82
82
  properties: {
83
- seller: { type: "address", immutable: true },
84
- deadline: { type: "timestamp", immutable: true },
83
+ seller: { type: 'address', immutable: true },
84
+ deadline: { type: 'timestamp', immutable: true },
85
85
  },
86
86
  },
87
87
  stateSchema: {
88
88
  properties: {
89
- seller: { type: "address", immutable: true },
90
- deadline: { type: "timestamp", immutable: true },
91
- status: { type: "string", computed: true },
92
- revealed: { type: "array", computed: true, description: "opened bids [{bidder, amount}]" },
93
- winner: { type: "address", computed: true },
94
- clearingPrice: { type: "number", computed: true, description: "second-highest bid (Vickrey)" },
89
+ seller: { type: 'address', immutable: true },
90
+ deadline: { type: 'timestamp', immutable: true },
91
+ status: { type: 'string', computed: true },
92
+ revealed: { type: 'array', computed: true, description: 'opened bids [{bidder, amount}]' },
93
+ winner: { type: 'address', computed: true },
94
+ clearingPrice: { type: 'number', computed: true, description: 'second-highest bid (Vickrey)' },
95
95
  },
96
96
  },
97
97
  eventSchemas: {
98
98
  reveal: {
99
- description: "Open a sealed bid after the deadline",
100
- required: ["bidder", "amount"],
101
- properties: { bidder: { type: "address" }, amount: { type: "number", minimum: 1 } },
99
+ description: 'Open a sealed bid after the deadline',
100
+ required: ['bidder', 'amount'],
101
+ properties: { bidder: { type: 'address' }, amount: { type: 'number', minimum: 1 } },
102
102
  },
103
- settle: { description: "Tally the revealed bids (winner + second price)" },
103
+ settle: { description: 'Tally the revealed bids (winner + second price)' },
104
104
  },
105
105
  states: {
106
- OPEN: { id: "OPEN", isFinal: false, metadata: { label: "Open", description: "Bidding (sealed)", category: "initial" } },
107
- REVEAL: { id: "REVEAL", isFinal: false, metadata: { label: "Reveal", description: "Opening bids", category: "active" } },
108
- SETTLED: { id: "SETTLED", isFinal: true, metadata: { label: "Settled", description: "Winner + price set", category: "terminal" } },
106
+ OPEN: {
107
+ id: 'OPEN',
108
+ isFinal: false,
109
+ metadata: { label: 'Open', description: 'Bidding (sealed)', category: 'initial' },
110
+ },
111
+ REVEAL: {
112
+ id: 'REVEAL',
113
+ isFinal: false,
114
+ metadata: { label: 'Reveal', description: 'Opening bids', category: 'active' },
115
+ },
116
+ SETTLED: {
117
+ id: 'SETTLED',
118
+ isFinal: true,
119
+ metadata: { label: 'Settled', description: 'Winner + price set', category: 'terminal' },
120
+ },
109
121
  },
110
- initialState: "OPEN",
122
+ initialState: 'OPEN',
111
123
  transitions: [
112
124
  {
113
- from: "OPEN",
114
- to: "REVEAL",
115
- eventName: "reveal",
116
- guard: { ">=": [{ var: "$timestamp" }, { var: "state.deadline" }] },
125
+ from: 'OPEN',
126
+ to: 'REVEAL',
127
+ eventName: 'reveal',
128
+ guard: { '>=': [{ var: '$timestamp' }, { var: 'state.deadline' }] },
117
129
  effect: {
118
130
  merge: [
119
- { var: "state" },
131
+ { var: 'state' },
120
132
  {
121
- status: "REVEAL",
133
+ status: 'REVEAL',
122
134
  revealed: {
123
- cat: [
124
- { var: "state.revealed" },
125
- [{ bidder: { var: "event.bidder" }, amount: { var: "event.amount" } }],
126
- ],
135
+ cat: [{ var: 'state.revealed' }, [{ bidder: { var: 'event.bidder' }, amount: { var: 'event.amount' } }]],
127
136
  },
128
137
  },
129
138
  ],
@@ -131,19 +140,16 @@ export const vickreyAuctionDef = defineFiberApp({
131
140
  dependencies: [],
132
141
  },
133
142
  {
134
- from: "REVEAL",
135
- to: "REVEAL",
136
- eventName: "reveal",
137
- guard: { ">=": [{ var: "$timestamp" }, { var: "state.deadline" }] },
143
+ from: 'REVEAL',
144
+ to: 'REVEAL',
145
+ eventName: 'reveal',
146
+ guard: { '>=': [{ var: '$timestamp' }, { var: 'state.deadline' }] },
138
147
  effect: {
139
148
  merge: [
140
- { var: "state" },
149
+ { var: 'state' },
141
150
  {
142
151
  revealed: {
143
- cat: [
144
- { var: "state.revealed" },
145
- [{ bidder: { var: "event.bidder" }, amount: { var: "event.amount" } }],
146
- ],
152
+ cat: [{ var: 'state.revealed' }, [{ bidder: { var: 'event.bidder' }, amount: { var: 'event.amount' } }]],
147
153
  },
148
154
  },
149
155
  ],
@@ -152,44 +158,41 @@ export const vickreyAuctionDef = defineFiberApp({
152
158
  },
153
159
  {
154
160
  // Vickrey tally: fold the revealed bids tracking (max, second, winner).
155
- from: "REVEAL",
156
- to: "SETTLED",
157
- eventName: "settle",
158
- guard: { ">": [{ reduce: [{ var: "state.revealed" }, { "+": [{ var: "accumulator" }, 1] }, 0] }, 0] },
161
+ from: 'REVEAL',
162
+ to: 'SETTLED',
163
+ eventName: 'settle',
164
+ guard: { '>': [{ reduce: [{ var: 'state.revealed' }, { '+': [{ var: 'accumulator' }, 1] }, 0] }, 0] },
159
165
  effect: {
160
166
  merge: [
161
- { var: "state" },
167
+ { var: 'state' },
162
168
  {
163
- status: "SETTLED",
164
- settledAt: { var: "$timestamp" },
169
+ status: 'SETTLED',
170
+ settledAt: { var: '$timestamp' },
165
171
  winner: {
166
- var: [
167
- "tally.winner",
168
- null,
169
- ],
172
+ var: ['tally.winner', null],
170
173
  },
171
- clearingPrice: { var: ["tally.second", 0] },
174
+ clearingPrice: { var: ['tally.second', 0] },
172
175
  // compute the tally once and expose it for the two fields above
173
176
  tally: {
174
177
  reduce: [
175
- { var: "state.revealed" },
178
+ { var: 'state.revealed' },
176
179
  {
177
180
  if: [
178
- { ">": [{ var: "current.amount" }, { var: "accumulator.max" }] },
181
+ { '>': [{ var: 'current.amount' }, { var: 'accumulator.max' }] },
179
182
  {
180
- max: { var: "current.amount" },
181
- second: { var: "accumulator.max" },
182
- winner: { var: "current.bidder" },
183
+ max: { var: 'current.amount' },
184
+ second: { var: 'accumulator.max' },
185
+ winner: { var: 'current.bidder' },
183
186
  },
184
187
  {
185
188
  if: [
186
- { ">": [{ var: "current.amount" }, { var: "accumulator.second" }] },
189
+ { '>': [{ var: 'current.amount' }, { var: 'accumulator.second' }] },
187
190
  {
188
- max: { var: "accumulator.max" },
189
- second: { var: "current.amount" },
190
- winner: { var: "accumulator.winner" },
191
+ max: { var: 'accumulator.max' },
192
+ second: { var: 'current.amount' },
193
+ winner: { var: 'accumulator.winner' },
191
194
  },
192
- { var: "accumulator" },
195
+ { var: 'accumulator' },
193
196
  ],
194
197
  },
195
198
  ],
@@ -24,7 +24,7 @@
24
24
  * O(state size) (RFC §8). Keep shielded note state small (a few KB); for large keyed state use
25
25
  * the auth-DB variant (RFC §3.1.1).
26
26
  */
27
- import { defineFiberApp, } from "../schema/fiber-app.js";
27
+ import { defineFiberApp } from '../schema/fiber-app.js';
28
28
  /**
29
29
  * Field extractors over the abi-encoded `JlvmTransitionPublicValues` — four static `bytes32`
30
30
  * `[anchor | nullifier | newCommitment | exprHash]`, a fixed 128-byte (256 hex char) layout with
@@ -36,15 +36,15 @@ const pvField = (publicValues, hexOffset) => ({
36
36
  });
37
37
  /** Standard public state every shielded pool carries (the rest of the app state is private/off-chain). */
38
38
  export const SHIELDED_POOL_STATE = {
39
- vkey: { type: "hash", immutable: true },
40
- exprHash: { type: "hash", immutable: true },
41
- rootWindow: { type: "integer", immutable: true },
42
- currentRoot: { type: "hash", computed: true },
43
- knownRoots: { type: "array", computed: true, description: "rolling window of valid anchors (hex)" },
44
- nullifiers: { type: "array", computed: true, description: "spent set (hex); monotonic — see RFC §5.3" },
45
- commitments: { type: "array", computed: true, description: "append-only log of output commitments (hex)" },
46
- leafCount: { type: "integer", computed: true, default: 0 },
47
- transitions: { type: "integer", computed: true, default: 0 },
39
+ vkey: { type: 'hash', immutable: true },
40
+ exprHash: { type: 'hash', immutable: true },
41
+ rootWindow: { type: 'integer', immutable: true },
42
+ currentRoot: { type: 'hash', computed: true },
43
+ knownRoots: { type: 'array', computed: true, description: 'rolling window of valid anchors (hex)' },
44
+ nullifiers: { type: 'array', computed: true, description: 'spent set (hex); monotonic — see RFC §5.3' },
45
+ commitments: { type: 'array', computed: true, description: 'append-only log of output commitments (hex)' },
46
+ leafCount: { type: 'integer', computed: true, default: 0 },
47
+ transitions: { type: 'integer', computed: true, default: 0 },
48
48
  };
49
49
  /**
50
50
  * Build the shielded-pool variant of `base`.
@@ -53,7 +53,7 @@ export const SHIELDED_POOL_STATE = {
53
53
  * @param opts the circuit vkey + the pinned `exprHash` + the anchor window.
54
54
  */
55
55
  export function shieldApp(base, opts) {
56
- const publicValues = { var: "event.publicValues" };
56
+ const publicValues = { var: 'event.publicValues' };
57
57
  const anchor = pvField(publicValues, 2);
58
58
  const nullifier = pvField(publicValues, 66);
59
59
  const newCommitment = pvField(publicValues, 130);
@@ -62,13 +62,13 @@ export function shieldApp(base, opts) {
62
62
  const guard = {
63
63
  and: [
64
64
  // 1. the proof verifies against the pool's pinned vkey over EXACTLY these public bytes
65
- { groth16_verify: [{ var: "state.vkey" }, publicValues, { var: "event.proof" }] },
65
+ { groth16_verify: [{ var: 'state.vkey' }, publicValues, { var: 'event.proof' }] },
66
66
  // 2. it ran the app logic this pool pins (binds which effect produced the transition)
67
- { "===": [exprHash, { var: "state.exprHash" }] },
67
+ { '===': [exprHash, { var: 'state.exprHash' }] },
68
68
  // 3. the spent note was proven under an anchor we still honor
69
- { in: [anchor, { var: "state.knownRoots" }] },
69
+ { in: [anchor, { var: 'state.knownRoots' }] },
70
70
  // 4. inter-transfer double-spend guard: the nullifier is not already spent
71
- { none: [{ var: "state.nullifiers" }, { "===": [{ var: "" }, nullifier] }] },
71
+ { none: [{ var: 'state.nullifiers' }, { '===': [{ var: '' }, nullifier] }] },
72
72
  ],
73
73
  };
74
74
  // EFFECT (combine): spend the nullifier, record the new commitment, advance counters.
@@ -76,52 +76,52 @@ export function shieldApp(base, opts) {
76
76
  // per RFC §6.2 / §10; the chain records the commitment + nullifier here.
77
77
  const effect = {
78
78
  merge: [
79
- { var: "state" },
79
+ { var: 'state' },
80
80
  {
81
- nullifiers: { cat: [{ var: "state.nullifiers" }, [nullifier]] },
82
- commitments: { cat: [{ var: "state.commitments" }, [newCommitment]] },
83
- leafCount: { "+": [{ var: "state.leafCount" }, 1] },
84
- transitions: { "+": [{ var: "state.transitions" }, 1] },
85
- lastTransitionAt: { var: "$ordinal" },
81
+ nullifiers: { cat: [{ var: 'state.nullifiers' }, [nullifier]] },
82
+ commitments: { cat: [{ var: 'state.commitments' }, [newCommitment]] },
83
+ leafCount: { '+': [{ var: 'state.leafCount' }, 1] },
84
+ transitions: { '+': [{ var: 'state.transitions' }, 1] },
85
+ lastTransitionAt: { var: '$ordinal' },
86
86
  },
87
87
  ],
88
88
  };
89
89
  return defineFiberApp({
90
90
  metadata: {
91
91
  name: `Shielded${base.metadata.name}`,
92
- app: "privacy",
92
+ app: 'privacy',
93
93
  type: `shielded-${base.metadata.type}`,
94
94
  version: base.metadata.version,
95
95
  description: `Shielded (zk-jlvm-shielded) variant of ${base.metadata.name}: private state transitions ` +
96
96
  `verified by a Groth16 proof; the nullifier set + anchors are public pool state.`,
97
97
  },
98
98
  createSchema: {
99
- required: ["vkey", "exprHash"],
99
+ required: ['vkey', 'exprHash'],
100
100
  properties: {
101
- vkey: { type: "hash", immutable: true, default: opts.vkey },
102
- exprHash: { type: "hash", immutable: true, default: opts.exprHash },
103
- rootWindow: { type: "integer", immutable: true, default: opts.rootWindow ?? 64 },
101
+ vkey: { type: 'hash', immutable: true, default: opts.vkey },
102
+ exprHash: { type: 'hash', immutable: true, default: opts.exprHash },
103
+ rootWindow: { type: 'integer', immutable: true, default: opts.rootWindow ?? 64 },
104
104
  },
105
105
  },
106
106
  stateSchema: { properties: { ...SHIELDED_POOL_STATE } },
107
107
  eventSchemas: {
108
108
  transition: {
109
109
  description: `A private state transition of ${base.metadata.name}, attested by a zk-jlvm-shielded Groth16 proof.`,
110
- required: ["proof", "publicValues"],
110
+ required: ['proof', 'publicValues'],
111
111
  properties: {
112
- proof: { type: "string", description: "Groth16 proof bytes (0x hex)" },
113
- publicValues: { type: "string", description: "abi-encoded JlvmTransitionPublicValues (4×bytes32, 0x hex)" },
112
+ proof: { type: 'string', description: 'Groth16 proof bytes (0x hex)' },
113
+ publicValues: { type: 'string', description: 'abi-encoded JlvmTransitionPublicValues (4×bytes32, 0x hex)' },
114
114
  },
115
115
  },
116
116
  },
117
117
  states: {
118
118
  ACTIVE: {
119
- id: "ACTIVE",
119
+ id: 'ACTIVE',
120
120
  isFinal: false,
121
- metadata: { label: "Active", description: "Pool accepts shielded transitions", category: "active" },
121
+ metadata: { label: 'Active', description: 'Pool accepts shielded transitions', category: 'active' },
122
122
  },
123
123
  },
124
- initialState: "ACTIVE",
125
- transitions: [{ from: "ACTIVE", to: "ACTIVE", eventName: "transition", guard, effect, dependencies: [] }],
124
+ initialState: 'ACTIVE',
125
+ transitions: [{ from: 'ACTIVE', to: 'ACTIVE', eventName: 'transition', guard, effect, dependencies: [] }],
126
126
  });
127
127
  }
@@ -33,3 +33,140 @@ export const addDependency = (fiberId) => ({
33
33
  export const setDependencyActive = (fiberId, active) => ({
34
34
  _setDependencyActive: [{ fiberId, active }],
35
35
  });
36
+ /**
37
+ * `_transferAsset`: move one or more WHOLE asset instances the emitting fiber holds, each to a single
38
+ * recipient. The directive rides INSIDE a `merge` effect map (the engine extracts `_`-prefixed keys
39
+ * before merging into state); a transition-level `emits` block is silently stripped by
40
+ * `toProtoDefinition`, which would strand the asset.
41
+ *
42
+ * Each directive is `{ assetId, recipient }` ONLY — there is NO `amount` field. The combiner reassigns
43
+ * `holder := recipient` on the WHOLE asset record (`AssetCombiner.applyFiberTransfer`); value is moved
44
+ * one whole instance at a time, never split. `recipient` must resolve to the canonical `AssetHolder`
45
+ * OBJECT form — `{"Fiber":{"fiberId":..}}` / `{"Wallet":{"address":..}}` — built with {@link toFiber} /
46
+ * {@link toWallet}; the chain raises a graceful `CombineRejected` on a bare string or malformed object
47
+ * (`EffectExtractor.parseAssetTransfer`). `assetId` is a UUID; the holder id may be a literal or an
48
+ * expression (e.g. `{ var: "event.agent" }`).
49
+ *
50
+ * Combiner-side holder defense (R1) independently re-validates every directive: the asset must resolve,
51
+ * be held by `Fiber(self)`, be `behavior.transferable`, and (Fiber recipient) the recipient fiber must be
52
+ * live — else the whole transition is `CombineRejected`. There is a hard cap of 32 asset mutations per
53
+ * transition (all-or-nothing); keep emitting fibers at ≤1 transfer per transition for claim/withdraw/slash.
54
+ *
55
+ * @example
56
+ * effect: { merge: [ { var: "state" }, {
57
+ * status: "SETTLED",
58
+ * ...transferAsset([{ assetId: { var: "event.rewardAssetId" }, recipient: toWallet({ var: "event.agent" }) }]),
59
+ * } ] }
60
+ */
61
+ export const transferAsset = (transfers) => ({ _transferAsset: transfers });
62
+ /**
63
+ * Build a `_transferAsset` `recipient` as the canonical `AssetHolder` OBJECT form. The chain requires the
64
+ * object form ONLY — `{"Fiber":{"fiberId":..}}` / `{"Wallet":{"address":..}}` — and raises a graceful
65
+ * `CombineRejected` on a bare string or a malformed object (`EffectExtractor.parseAssetTransfer`); the
66
+ * legacy bare-string UUID/DAG-address disambiguation has been removed. These mirror the typed
67
+ * {@link fiberHolder} / {@link walletHolder} `AssetHolder` builders (used for `MintAsset.holder` /
68
+ * `ApplyMorphism.recipient`) but accept a `JsonLogicValue`, so the id can be a runtime expression:
69
+ *
70
+ * ```ts
71
+ * transferAsset([{ assetId, recipient: toFiber({ var: "event.retailerId" }) }]); // → {"Fiber":{"fiberId":..}}
72
+ * transferAsset([{ assetId, recipient: toWallet({ var: "event.agent" }) }]); // → {"Wallet":{"address":..}}
73
+ * ```
74
+ */
75
+ export const toFiber = (fiberId) => ({
76
+ Fiber: { fiberId },
77
+ });
78
+ /** See {@link toFiber}: a `transferAsset` recipient held by a wallet — `{"Wallet":{"address":..}}`. */
79
+ export const toWallet = (address) => ({
80
+ Wallet: { address },
81
+ });
82
+ /**
83
+ * `_triggers` (F4): fire one or more CROSS-FIBER events. Each entry is projected to
84
+ * `{ targetMachineId, eventName, payload }` — the exact shape the chain's `EffectExtractor` reads
85
+ * (`ReservedKeys.scala`, `EffectExtractor.scala`). `target` is the recipient fiber id (a literal UUID
86
+ * or an expression, e.g. `{ var: "event.retailerId" }`); `event` is the event NAME to enqueue on it;
87
+ * `payload` is the event body — omit it and the builder emits `{}` (never `null`).
88
+ *
89
+ * Authoring this as a builder makes a typo'd `_trigger` / `triggres` a TypeScript error rather than a
90
+ * silently-merged state field (the F4 foot-gun). Place the fragment INSIDE the effect's state-update
91
+ * map so it rides in the evaluated result the extractor reads.
92
+ *
93
+ * @example
94
+ * effect: { merge: [ { var: "state" }, {
95
+ * status: "debt_current",
96
+ * ...triggers([{ target: { var: "event.retailerId" }, event: "process_sale",
97
+ * payload: { buyerId: { var: "machineId" }, quantity: { var: "event.quantity" } } }]),
98
+ * } ] }
99
+ */
100
+ export const triggers = (ts) => ({
101
+ _triggers: ts.map((t) => ({
102
+ targetMachineId: t.target,
103
+ eventName: t.event,
104
+ payload: t.payload ?? {},
105
+ })),
106
+ });
107
+ /**
108
+ * `_spawn`: create one or more CHILD fibers, each from a literal machine `definition`. Each entry is
109
+ * `{ childId, definition, initialData, owners }` (`ReservedKeys.scala`, `EffectExtractor.scala`).
110
+ *
111
+ * The chain extracts `_spawn` from the effect EXPRESSION, not the evaluated result, so `definition`
112
+ * MUST be a literal {@link ProtoStateMachineDefinition} (e.g. a nested `machine().wireDefinition()` /
113
+ * `toProtoDefinition(child)` output) — NOT an expression the engine would evaluate at runtime.
114
+ *
115
+ * F8 gotcha — `owners` is load-bearing. A spawned child's transitions are gated by
116
+ * `owners ∪ authorizedSigners` (`riverdale-economy/README.md`), so EVERY party that will later drive
117
+ * the child (e.g. every bidder on a spawned auction) MUST be listed in `owners`, or their events are
118
+ * rejected. `owners` may be a literal id array or an expression (e.g. `{ var: "event.auctionOwners" }`);
119
+ * `childId` / `initialData` likewise accept literals or expressions.
120
+ */
121
+ export const spawn = (ds) => ({ _spawn: ds });
122
+ /**
123
+ * `_emit`: emit one or more domain events to the fiber's outbox. Each entry is
124
+ * `{ name, data, destination? }` (`ReservedKeys.scala`, `EffectExtractor.scala`). `name` is the event
125
+ * name, `data` the body (a literal or an expression), and `destination` an OPTIONAL routing target —
126
+ * omit it when absent (callers never pass `null`, so it is simply absent on the wire).
127
+ */
128
+ export const emit = (es) => ({
129
+ _emit: es,
130
+ });
131
+ /**
132
+ * `_scriptCall`: invoke a SCRIPT fiber's `method` from an effect. Unlike the array-valued directives,
133
+ * `_scriptCall` is a SINGLE object `{ fiberId, method, args }` (chain `ReservedKeys.scala` `SCRIPT_CALL` /
134
+ * `EffectExtractor.extractScriptCall`). `fiberId` is the target script's UUID (a literal or an expression,
135
+ * e.g. `{ var: "state.resolverId" }`); `method` is the script method NAME; `args` is the argument body —
136
+ * a JSON-Logic value the chain EVALUATES against the transition context before dispatch.
137
+ *
138
+ * The chain's extractor requires ALL THREE fields — if `args` is absent the whole call is silently DROPPED
139
+ * (fail-silent, like the other extractors). So the builder ALWAYS emits `args`, defaulting an omitted one
140
+ * to `{}` (no-args), mirroring how {@link triggers} defaults an absent `payload`. Authoring this as a
141
+ * builder makes a typo'd `_scriptcall` / wrong field a TypeScript error rather than a silently-merged
142
+ * state field. Place the fragment INSIDE the effect's state-update map so it rides in the evaluated result.
143
+ *
144
+ * @example
145
+ * effect: { merge: [ { var: "state" }, {
146
+ * status: "resolving",
147
+ * ...scriptCall({ fiberId: { var: "state.resolverId" }, method: "resolve",
148
+ * args: { marketId: { var: "machineId" } } }),
149
+ * } ] }
150
+ */
151
+ export const scriptCall = (call) => ({
152
+ _scriptCall: {
153
+ fiberId: call.fiberId,
154
+ method: call.method,
155
+ args: call.args ?? {},
156
+ },
157
+ });
158
+ /**
159
+ * The complete set of `_`-prefixed RESERVED effect keys the chain's `EffectExtractor` consumes and
160
+ * `StateMerger` strips from state (`ReservedKeys.scala:12-49`). Exported so a validator (Proposal 01)
161
+ * can reject an unknown `_`-prefixed key (a typo'd directive) instead of letting it silently leak into
162
+ * persisted state.
163
+ */
164
+ export const RESERVED_EFFECT_KEYS = [
165
+ '_triggers',
166
+ '_spawn',
167
+ '_emit',
168
+ '_transferAsset',
169
+ '_scriptCall',
170
+ '_addDependency',
171
+ '_setDependencyActive',
172
+ ];