@ottochain/sdk 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) 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 +20 -3
  62. package/dist/cjs/ottochain/genesis-manifest.js +6 -0
  63. package/dist/cjs/ottochain/metagraph-client.js +16 -8
  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 +117 -1
  69. package/dist/cjs/schema/fiber-app.js +132 -3
  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 +16 -8
  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 +110 -0
  148. package/dist/esm/schema/fiber-app.js +127 -3
  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/transaction.d.ts +9 -1
  212. package/dist/types/ottochain/types.d.ts +1 -1
  213. package/dist/types/privacy/index.d.ts +2 -2
  214. package/dist/types/privacy/sealed-bid.d.ts +9 -9
  215. package/dist/types/privacy/shield-app.d.ts +1 -1
  216. package/dist/types/schema/effects.d.ts +107 -0
  217. package/dist/types/schema/fiber-app.d.ts +281 -0
  218. package/dist/types/schema/guards.d.ts +12 -0
  219. package/dist/types/templates/asset-policy.d.ts +119 -0
  220. package/dist/types/templates/index.d.ts +26 -0
  221. package/dist/types/templates/machine.d.ts +139 -0
  222. package/dist/types/templates/migration.d.ts +34 -0
  223. package/dist/types/templates/state-shape.d.ts +30 -0
  224. package/dist/types/zk/index.d.ts +4 -4
  225. package/package.json +31 -13
@@ -1,122 +1,116 @@
1
- import { defineFiberApp } from "../../../schema/fiber-app.js";
1
+ import { defineFiberApp } from '../../../schema/fiber-app.js';
2
2
  /**
3
3
  * Minimal market state machine - extend for custom use cases.
4
4
  */
5
5
  export const marketUniversalDef = defineFiberApp({
6
6
  metadata: {
7
- name: "MarketUniversal",
8
- app: "markets",
9
- type: "universal",
10
- version: "1.0.0",
11
- description: "Minimal market state machine - extend for custom use cases",
7
+ name: 'MarketUniversal',
8
+ app: 'markets',
9
+ type: 'universal',
10
+ version: '1.0.0',
11
+ description: 'Minimal market state machine - extend for custom use cases',
12
12
  },
13
13
  createSchema: {
14
14
  properties: {},
15
15
  },
16
16
  stateSchema: {
17
17
  properties: {
18
- status: { type: "string" },
19
- totalCommitted: { type: "number", computed: true },
18
+ status: { type: 'string' },
19
+ totalCommitted: { type: 'number', computed: true },
20
20
  },
21
21
  },
22
22
  eventSchemas: {
23
- open: { description: "Open the market for participation" },
24
- cancel: { description: "Cancel the market" },
23
+ open: { description: 'Open the market for participation' },
24
+ cancel: { description: 'Cancel the market' },
25
25
  commit: {
26
- description: "Commit funds to the market",
26
+ description: 'Commit funds to the market',
27
27
  properties: {
28
- amount: { type: "number", minimum: 0 },
28
+ amount: { type: 'number', minimum: 0 },
29
29
  },
30
30
  },
31
- close: { description: "Close the market to new commits" },
32
- settle: { description: "Settle the market" },
31
+ close: { description: 'Close the market to new commits' },
32
+ settle: { description: 'Settle the market' },
33
33
  },
34
34
  states: {
35
35
  PROPOSED: {
36
- id: "PROPOSED",
36
+ id: 'PROPOSED',
37
37
  isFinal: false,
38
38
  metadata: {
39
- label: "Proposed",
40
- description: "Market created but not yet open",
41
- category: "initial",
39
+ label: 'Proposed',
40
+ description: 'Market created but not yet open',
41
+ category: 'initial',
42
42
  },
43
43
  },
44
44
  OPEN: {
45
- id: "OPEN",
45
+ id: 'OPEN',
46
46
  isFinal: false,
47
47
  metadata: {
48
- label: "Open",
49
- description: "Market is open for participation",
50
- category: "active",
48
+ label: 'Open',
49
+ description: 'Market is open for participation',
50
+ category: 'active',
51
51
  },
52
52
  },
53
53
  CLOSED: {
54
- id: "CLOSED",
54
+ id: 'CLOSED',
55
55
  isFinal: false,
56
56
  metadata: {
57
- label: "Closed",
58
- description: "Participation closed; awaiting settlement",
59
- category: "pending",
57
+ label: 'Closed',
58
+ description: 'Participation closed; awaiting settlement',
59
+ category: 'pending',
60
60
  },
61
61
  },
62
62
  SETTLED: {
63
- id: "SETTLED",
63
+ id: 'SETTLED',
64
64
  isFinal: true,
65
65
  metadata: {
66
- label: "Settled",
67
- description: "Market settled and payouts available (terminal)",
68
- category: "terminal",
66
+ label: 'Settled',
67
+ description: 'Market settled and payouts available (terminal)',
68
+ category: 'terminal',
69
69
  },
70
70
  },
71
71
  CANCELLED: {
72
- id: "CANCELLED",
72
+ id: 'CANCELLED',
73
73
  isFinal: true,
74
74
  metadata: {
75
- label: "Cancelled",
76
- description: "Market cancelled before settlement (terminal)",
77
- category: "terminal",
75
+ label: 'Cancelled',
76
+ description: 'Market cancelled before settlement (terminal)',
77
+ category: 'terminal',
78
78
  },
79
79
  },
80
80
  },
81
- initialState: "PROPOSED",
81
+ initialState: 'PROPOSED',
82
82
  transitions: [
83
83
  {
84
- from: "PROPOSED",
85
- to: "OPEN",
86
- eventName: "open",
87
- guard: { "==": [1, 1] },
84
+ from: 'PROPOSED',
85
+ to: 'OPEN',
86
+ eventName: 'open',
87
+ guard: { '==': [1, 1] },
88
88
  effect: {
89
- merge: [
90
- { var: "state" },
91
- { status: "OPEN", openedAt: { var: "$ordinal" } },
92
- ],
89
+ merge: [{ var: 'state' }, { status: 'OPEN', openedAt: { var: '$ordinal' } }],
93
90
  },
94
91
  dependencies: [],
95
92
  },
96
93
  {
97
- from: "PROPOSED",
98
- to: "CANCELLED",
99
- eventName: "cancel",
100
- guard: { "==": [1, 1] },
94
+ from: 'PROPOSED',
95
+ to: 'CANCELLED',
96
+ eventName: 'cancel',
97
+ guard: { '==': [1, 1] },
101
98
  effect: {
102
- merge: [
103
- { var: "state" },
104
- { status: "CANCELLED", cancelledAt: { var: "$ordinal" } },
105
- ],
99
+ merge: [{ var: 'state' }, { status: 'CANCELLED', cancelledAt: { var: '$ordinal' } }],
106
100
  },
107
101
  dependencies: [],
108
102
  },
109
103
  {
110
- from: "OPEN",
111
- to: "OPEN",
112
- eventName: "commit",
113
- guard: { ">": [{ var: "event.amount" }, 0] },
104
+ from: 'OPEN',
105
+ to: 'OPEN',
106
+ eventName: 'commit',
107
+ guard: { '>': [{ var: 'event.amount' }, 0] },
114
108
  effect: {
115
109
  merge: [
116
- { var: "state" },
110
+ { var: 'state' },
117
111
  {
118
112
  totalCommitted: {
119
- "+": [{ var: "state.totalCommitted" }, { var: "event.amount" }],
113
+ '+': [{ var: 'state.totalCommitted' }, { var: 'event.amount' }],
120
114
  },
121
115
  },
122
116
  ],
@@ -124,41 +118,32 @@ export const marketUniversalDef = defineFiberApp({
124
118
  dependencies: [],
125
119
  },
126
120
  {
127
- from: "OPEN",
128
- to: "CLOSED",
129
- eventName: "close",
130
- guard: { "==": [1, 1] },
121
+ from: 'OPEN',
122
+ to: 'CLOSED',
123
+ eventName: 'close',
124
+ guard: { '==': [1, 1] },
131
125
  effect: {
132
- merge: [
133
- { var: "state" },
134
- { status: "CLOSED", closedAt: { var: "$ordinal" } },
135
- ],
126
+ merge: [{ var: 'state' }, { status: 'CLOSED', closedAt: { var: '$ordinal' } }],
136
127
  },
137
128
  dependencies: [],
138
129
  },
139
130
  {
140
- from: "CLOSED",
141
- to: "SETTLED",
142
- eventName: "settle",
143
- guard: { "==": [1, 1] },
131
+ from: 'CLOSED',
132
+ to: 'SETTLED',
133
+ eventName: 'settle',
134
+ guard: { '==': [1, 1] },
144
135
  effect: {
145
- merge: [
146
- { var: "state" },
147
- { status: "SETTLED", settledAt: { var: "$ordinal" } },
148
- ],
136
+ merge: [{ var: 'state' }, { status: 'SETTLED', settledAt: { var: '$ordinal' } }],
149
137
  },
150
138
  dependencies: [],
151
139
  },
152
140
  {
153
- from: "CLOSED",
154
- to: "CANCELLED",
155
- eventName: "cancel",
156
- guard: { "==": [1, 1] },
141
+ from: 'CLOSED',
142
+ to: 'CANCELLED',
143
+ eventName: 'cancel',
144
+ guard: { '==': [1, 1] },
157
145
  effect: {
158
- merge: [
159
- { var: "state" },
160
- { status: "CANCELLED", cancelledAt: { var: "$ordinal" } },
161
- ],
146
+ merge: [{ var: 'state' }, { status: 'CANCELLED', cancelledAt: { var: '$ordinal' } }],
162
147
  },
163
148
  dependencies: [],
164
149
  },
@@ -7,11 +7,11 @@
7
7
  * @deprecated Use `@ottochain/sdk/apps/identity`
8
8
  * @packageDocumentation
9
9
  */
10
- export { IdentityState as OracleState, Reputation as OracleReputation, PenaltyEvent as SlashingEvent, Identity as Oracle, RegisterIdentityRequest as RegisterOracleRequest, ActivateIdentityRequest as ActivateOracleRequest, AddStakeRequest, WithdrawIdentityRequest as WithdrawOracleRequest, IdentityDefinition as OracleDefinition, identityStateFromJSON as oracleStateFromJSON, identityStateToJSON as oracleStateToJSON, } from "../identity/index.js";
11
- import { getIdentityDefinition } from "../identity/index.js";
10
+ export { IdentityState as OracleState, Reputation as OracleReputation, PenaltyEvent as SlashingEvent, Identity as Oracle, RegisterIdentityRequest as RegisterOracleRequest, ActivateIdentityRequest as ActivateOracleRequest, AddStakeRequest, WithdrawIdentityRequest as WithdrawOracleRequest, IdentityDefinition as OracleDefinition, identityStateFromJSON as oracleStateFromJSON, identityStateToJSON as oracleStateToJSON, } from '../identity/index.js';
11
+ import { getIdentityDefinition } from '../identity/index.js';
12
12
  /** @deprecated Use `getIdentityDefinition('oracle')` from `@ottochain/sdk/apps/identity` */
13
13
  export function getOracleDefinition(_type) {
14
- return getIdentityDefinition("oracle");
14
+ return getIdentityDefinition('oracle');
15
15
  }
16
16
  /** @deprecated Use `DEFAULT_REPUTATION_CONFIG` from `@ottochain/sdk/apps/identity` */
17
17
  export const DEFAULT_ORACLE_CONFIG = {
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Privacy Application — note-layer privacy primitives.
3
+ *
4
+ * Σ-protocol / ZK-backed fibers that carry real privacy on the OttoChain note
5
+ * layer. The flagship is `sigma-mixer`, a CDS OR-of-`dhtuple` ring mixer whose
6
+ * anonymity comes from a `sigma_verify` ring proof and whose double-spend safety
7
+ * comes from a witness-bound nullifier (`Nf = x_j·H`, `H` a NUMS base of unknown
8
+ * dlog w.r.t. `G`).
9
+ *
10
+ * The std-lib UTXO primitive is `shielded-note-pool` ({@link notePoolDef}): a
11
+ * fixed-denomination Tornado-style private asset pool over the `zk-shielded`
12
+ * Groth16 circuit. ⚠ UNAUDITED / TEST-ASSETS-ONLY (BN254 ~100-bit, single trusted
13
+ * relayer for root advancement) — see note-pool.ts.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { getPrivacyDefinition, PRIVACY_DEFINITIONS, sigmaDdhRingOf, notePoolDef } from '@ottochain/sdk/apps/privacy';
18
+ *
19
+ * const mixerDef = getPrivacyDefinition('sigma-mixer');
20
+ * // Build a custom n-member OR-of-dhtuple proposition for an audited H:
21
+ * const prop = sigmaDdhRingOf('state.points', 'event.nullifier', G_HEX, H_HEX, 8);
22
+ * // Instantiate a shielded note-pool (pin the circuit vkey + denomination + relayer):
23
+ * const pool = notePoolDef({ vkey, depth: 8, denom: 100, poolPolicyRef, feeAsset, relayer });
24
+ * ```
25
+ *
26
+ * @packageDocumentation
27
+ */
28
+ import { mixerDdhRingDef, sigmaDdhRingOf, notePoolDef, NOTE_POOL_STATE, PV_LAYOUT, ZERO_WORD, pvField, pmtMembership, } from './state-machines/index.js';
29
+ export { mixerDdhRingDef, sigmaDdhRingOf, notePoolDef, NOTE_POOL_STATE, PV_LAYOUT, ZERO_WORD, pvField, pmtMembership, };
30
+ /**
31
+ * A documented DEFAULT shielded-note-pool instance for the registry/lint surface, with PLACEHOLDER
32
+ * pin values (the real vkey comes from the SP1 `zk-shielded` toolchain; relayer/policy are
33
+ * deployment-specific). Downstream callers should build their own via {@link notePoolDef}; this
34
+ * instance exists so the privacy app group exposes a concrete `shielded-note-pool` definition.
35
+ * ⚠ UNAUDITED / TEST-ASSETS-ONLY.
36
+ */
37
+ export const shieldedNotePoolDef = notePoolDef({
38
+ vkey: ZERO_WORD,
39
+ depth: 8,
40
+ denom: 100,
41
+ poolPolicyRef: 'std.privacy.note-pool',
42
+ feeAsset: ZERO_WORD,
43
+ relayer: 'DAG0000000000000000000000000000000000000000',
44
+ });
45
+ /** All privacy (note-layer) state machine definitions. */
46
+ export const PRIVACY_DEFINITIONS = {
47
+ 'sigma-mixer': mixerDdhRingDef,
48
+ 'shielded-note-pool': shieldedNotePoolDef,
49
+ };
50
+ /**
51
+ * Get a privacy state machine definition by type.
52
+ * @param type - 'sigma-mixer' (default) | 'shielded-note-pool'.
53
+ */
54
+ export function getPrivacyDefinition(type = 'sigma-mixer') {
55
+ return PRIVACY_DEFINITIONS[type];
56
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Privacy (note-layer) state machine definitions.
3
+ * Re-exports from TypeScript definition files.
4
+ */
5
+ export { mixerDdhRingDef, sigmaDdhRingOf } from './mixer-ddhRing.js';
6
+ export { notePoolDef, NOTE_POOL_STATE, PV_LAYOUT, ZERO_WORD, pvField, pmtMembership, } from './note-pool.js';
@@ -0,0 +1,282 @@
1
+ import { defineFiberApp } from '../../../schema/fiber-app.js';
2
+ /**
3
+ * sigma-mixer — a CDS OR-of-`dhtuple` Σ-protocol ring mixer.
4
+ *
5
+ * Anonymity comes from a Cramer–Damgård–Schoenmakers OR-proof over the deposited
6
+ * ring, verified by the `sigma_verify` JLVM opcode; double-spend safety comes
7
+ * from a WITNESS-BOUND nullifier carried as the shared DDH point of an
8
+ * OR-of-`dhtuple` proposition.
9
+ *
10
+ * Each ring branch is a DDH tuple `dhtuple(G, H, P_i, Nf)`. A satisfied dhtuple
11
+ * proves knowledge of one `x` with `P_i = x·G` AND `Nf = x·H` (the verifier uses
12
+ * a SINGLE shared response `z` for both coordinate reconstructions
13
+ * `a1 = z·G − e·P_i`, `a2 = z·H − e·Nf`). The OR uses the SAME
14
+ * `v = event.nullifier` in every branch, so it hides which branch while forcing
15
+ * `event.nullifier = x_j·H` for the one real branch `j`. With `H` a NUMS base of
16
+ * unknown dlog w.r.t. `G`, the map `x ↦ x·H` is injective, so the nullifier is
17
+ * cryptographically bound to the proven secret — closing the
18
+ * witness-unbound-nullifier double-spend hole an OR-of-`dlog` ring leaves open.
19
+ *
20
+ * Verified against `@constellation-network/metagraph-sdk-jlvm@1.8.0-rc.5`: the
21
+ * `sigma_verify` dhtuple operands are exactly `["type","g","h","u","v"]` (each a
22
+ * 64-byte G1 hex), the OR child challenges XOR to the node challenge, and the
23
+ * strong-FS root challenge folds the bound message. Array append uses `merge`
24
+ * (`merge([arr,[item]])` flattens one level == append). All operators used
25
+ * (`sigma_verify`, `has`, `set`, `none`, `cat`, `substr`, `merge`) are in
26
+ * KNOWN_OPERATORS.
27
+ *
28
+ * SCOPE: this base definition is CRYPTO + LIFECYCLE. Production custody
29
+ * (`_transferAsset` in on deposit / out on withdraw), a signer-bound deposit-auth
30
+ * clause, and a `mixerId`-prefixed bound message are layered on by a downstream
31
+ * specialization (see the §8 production-hardening note in the design doc).
32
+ */
33
+ // =============================================================================
34
+ // sigmaDdhRingOf — the OR-of-dhtuple proposition builder
35
+ // =============================================================================
36
+ /**
37
+ * Emit the `or`-of-`dhtuple` proposition for an `n`-member ring, unrolling
38
+ * `{"var":"<pointsVar>.k"}` for `k in 0..n-1` as the `u` (commitment) of each
39
+ * branch, with `g = gHex`, `h = hHex` (literal 64-byte G1 hex) and a shared
40
+ * `v = {"var":"<nullifierVar>"}` across ALL branches.
41
+ *
42
+ * `n` is FIXED at definition time (the proposition shape is closed). `u` and `v`
43
+ * are `{"var":...}` map-node values that the evaluator resolves element-wise.
44
+ *
45
+ * @param pointsVar state var holding the ordered ring points, e.g. `"state.points"`.
46
+ * @param nullifierVar event var holding the revealed nullifier, e.g. `"event.nullifier"`.
47
+ * @param gHex the verifier generator `G=(1,2)` as 64-byte `0x` hex.
48
+ * @param hHex the NUMS second base `H` as 64-byte `0x` hex (unknown dlog wrt G).
49
+ * @param n ring size (number of unrolled branches).
50
+ */
51
+ export function sigmaDdhRingOf(pointsVar, nullifierVar, gHex, hHex, n) {
52
+ const children = [];
53
+ for (let k = 0; k < n; k++) {
54
+ children.push({
55
+ type: 'dhtuple',
56
+ g: gHex,
57
+ h: hHex,
58
+ u: { var: `${pointsVar}.${k}` },
59
+ v: { var: nullifierVar },
60
+ });
61
+ }
62
+ return { type: 'or', children };
63
+ }
64
+ /**
65
+ * The shared withdraw verify clauses (ring proof ∧ freshness ∧ recipient-bind).
66
+ * The lifecycle clause (`→drained` vs `→open`) is appended per transition.
67
+ */
68
+ function withdrawVerifyClauses(gHex, hHex, n) {
69
+ return [
70
+ {
71
+ sigma_verify: [
72
+ sigmaDdhRingOf('state.points', 'event.nullifier', gHex, hHex, n),
73
+ { var: 'event.proof' },
74
+ { var: 'event.message' },
75
+ ],
76
+ },
77
+ // Double-withdraw prevention: the witness-bound nullifier must be unseen.
78
+ { '!': { has: [{ var: 'state.spentNullifiers' }, { var: 'event.nullifier' }] } },
79
+ // Recipient binding (anti-front-run): message == Nf ‖ recipientHex.
80
+ {
81
+ '===': [
82
+ { var: 'event.message' },
83
+ {
84
+ cat: ['0x', { substr: [{ var: 'event.nullifier' }, 2] }, { substr: [{ var: 'event.recipientHex' }, 2] }],
85
+ },
86
+ ],
87
+ },
88
+ ];
89
+ }
90
+ // The withdraw effect: record the nullifier, advance the counter (+ optional status).
91
+ function withdrawEffect(extra) {
92
+ return {
93
+ merge: [
94
+ { var: 'state' },
95
+ {
96
+ spentNullifiers: {
97
+ set: [{ var: 'state.spentNullifiers' }, { var: 'event.nullifier' }, true],
98
+ },
99
+ withdrawCount: { '+': [{ var: 'state.withdrawCount' }, 1] },
100
+ ...extra,
101
+ },
102
+ ],
103
+ };
104
+ }
105
+ // G=(1,2) and the NUMS H are the e2e defaults (derived by scripts/gen-sigma-mixer-fixture.ts).
106
+ // Downstream apps pass their own audited H via the builder; these are the pinned-ring v1 demo values.
107
+ const G_HEX = '0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002';
108
+ const H_HEX = '0x039c846e3a79217fd140d094eec09fe4f398085d01dee70506edde1eb6a9d81608922722cc3a6c3a7ae4929e78e82dc5f25e91598a69f7f8b9b3adb95badb3d0';
109
+ const RING_N = 4;
110
+ /**
111
+ * sigma-mixer fiber definition (pinned-ring v1, n=4).
112
+ *
113
+ * Trust model: PUBLIC. Anyone may deposit a ring point or submit a withdrawal.
114
+ * Privacy = a CDS OR-proof hides which of the n branches is being spent;
115
+ * anonymity set = exactly n (the ring size is public). Double-spend safety =
116
+ * the witness-bound nullifier + spent-set. Replay/front-run safety = the
117
+ * message-bound recipient.
118
+ */
119
+ export const mixerDdhRingDef = defineFiberApp({
120
+ metadata: {
121
+ name: 'MixerDdhRing',
122
+ app: 'privacy',
123
+ type: 'sigma-mixer',
124
+ version: '1.0.0',
125
+ description: 'CDS OR-of-dhtuple Σ-protocol ring mixer. Anonymity via sigma_verify over an ' +
126
+ 'OR of DDH tuples (G,H,P_i,nullifier); the revealed nullifier Nf=x_j·H is ' +
127
+ 'witness-bound (H has unknown dlog wrt G), closing the ring-drain double-spend. ' +
128
+ 'Frozen-ring lifecycle (filling→open→drained) + message-bound recipient.',
129
+ },
130
+ createSchema: {
131
+ required: ['mixerId', 'denomination', 'anonymityTarget'],
132
+ properties: {
133
+ mixerId: { type: 'string', immutable: true, description: 'Mixer instance id.' },
134
+ denomination: {
135
+ type: 'integer',
136
+ immutable: true,
137
+ description: 'Equal denomination per deposit/withdraw (production custody).',
138
+ },
139
+ nullifierBaseH: {
140
+ type: 'string',
141
+ immutable: true,
142
+ description: 'The NUMS second base H (64B G1 hex); informational — H is inlined in the proposition.',
143
+ },
144
+ anonymityTarget: {
145
+ type: 'integer',
146
+ immutable: true,
147
+ description: 'Ring size n; the ring opens once depositCount == anonymityTarget.',
148
+ },
149
+ points: {
150
+ type: 'array',
151
+ items: { type: 'string' },
152
+ default: [],
153
+ description: 'Ordered ring commitments P_i = x_i·G (64B G1 hex).',
154
+ },
155
+ spentNullifiers: {
156
+ type: 'object',
157
+ default: {},
158
+ description: 'FLAT map nullifierHex -> true. MUST be {} (never null): has/set throw on null.',
159
+ },
160
+ depositCount: { type: 'integer', default: 0 },
161
+ withdrawCount: { type: 'integer', default: 0 },
162
+ status: { type: 'string', default: 'filling', description: 'filling → open → drained.' },
163
+ },
164
+ },
165
+ stateSchema: {
166
+ properties: {
167
+ mixerId: { type: 'string', immutable: true },
168
+ denomination: { type: 'integer', immutable: true },
169
+ nullifierBaseH: { type: 'string', immutable: true },
170
+ anonymityTarget: { type: 'integer', immutable: true },
171
+ points: { type: 'array', items: { type: 'string' }, computed: true },
172
+ spentNullifiers: { type: 'object', computed: true },
173
+ depositCount: { type: 'integer', computed: true },
174
+ withdrawCount: { type: 'integer', computed: true },
175
+ status: { type: 'string', computed: true },
176
+ },
177
+ },
178
+ eventSchemas: {
179
+ deposit: { description: 'Register a ring commitment point P_i = x_i·G.' },
180
+ withdraw: {
181
+ description: 'Spend one ring slot: a CDS OR-of-dhtuple proof + witness-bound nullifier + bound recipient.',
182
+ },
183
+ },
184
+ states: {
185
+ filling: {
186
+ id: 'filling',
187
+ isFinal: false,
188
+ metadata: { label: 'Filling', description: 'Ring accepting deposits.', category: 'active' },
189
+ },
190
+ open: {
191
+ id: 'open',
192
+ isFinal: false,
193
+ metadata: { label: 'Open', description: 'Ring frozen; withdrawals allowed.', category: 'active' },
194
+ },
195
+ drained: {
196
+ id: 'drained',
197
+ isFinal: true,
198
+ metadata: { label: 'Drained', description: 'All slots withdrawn; one-shot.', category: 'terminal' },
199
+ },
200
+ },
201
+ initialState: 'filling',
202
+ // ORDER IS LOAD-BEARING: the open-flip deposit is declared FIRST (exact
203
+ // boundary), the drained-flip withdraw is declared FIRST (exact boundary).
204
+ transitions: [
205
+ // Deposit A — the LAST deposit: filling → open. Declared FIRST.
206
+ {
207
+ from: 'filling',
208
+ to: 'open',
209
+ eventName: 'deposit',
210
+ guard: {
211
+ and: [
212
+ { '===': [{ '+': [{ var: 'state.depositCount' }, 1] }, { var: 'state.anonymityTarget' }] },
213
+ { '!!': [{ var: 'event.point' }] },
214
+ { none: [{ var: 'state.points' }, { '===': [{ var: '' }, { var: 'event.point' }] }] },
215
+ ],
216
+ },
217
+ effect: {
218
+ merge: [
219
+ { var: 'state' },
220
+ {
221
+ // Array append = merge([arr,[item]]) (verified: opMerge flattens one level).
222
+ points: { merge: [{ var: 'state.points' }, [{ var: 'event.point' }]] },
223
+ depositCount: { '+': [{ var: 'state.depositCount' }, 1] },
224
+ status: 'open',
225
+ },
226
+ ],
227
+ },
228
+ dependencies: [],
229
+ },
230
+ // Deposit B — not-yet-last: filling → filling. Declared SECOND.
231
+ {
232
+ from: 'filling',
233
+ to: 'filling',
234
+ eventName: 'deposit',
235
+ guard: {
236
+ and: [
237
+ { '<': [{ '+': [{ var: 'state.depositCount' }, 1] }, { var: 'state.anonymityTarget' }] },
238
+ { '!!': [{ var: 'event.point' }] },
239
+ { none: [{ var: 'state.points' }, { '===': [{ var: '' }, { var: 'event.point' }] }] },
240
+ ],
241
+ },
242
+ effect: {
243
+ merge: [
244
+ { var: 'state' },
245
+ {
246
+ points: { merge: [{ var: 'state.points' }, [{ var: 'event.point' }]] },
247
+ depositCount: { '+': [{ var: 'state.depositCount' }, 1] },
248
+ },
249
+ ],
250
+ },
251
+ dependencies: [],
252
+ },
253
+ // Withdraw → drained (the LAST withdrawal). Declared FIRST.
254
+ {
255
+ from: 'open',
256
+ to: 'drained',
257
+ eventName: 'withdraw',
258
+ guard: {
259
+ and: [
260
+ ...withdrawVerifyClauses(G_HEX, H_HEX, RING_N),
261
+ { '===': [{ '+': [{ var: 'state.withdrawCount' }, 1] }, { var: 'state.anonymityTarget' }] },
262
+ ],
263
+ },
264
+ effect: withdrawEffect({ status: 'drained' }),
265
+ dependencies: [],
266
+ },
267
+ // Withdraw → open (not-yet-last). Declared SECOND.
268
+ {
269
+ from: 'open',
270
+ to: 'open',
271
+ eventName: 'withdraw',
272
+ guard: {
273
+ and: [
274
+ ...withdrawVerifyClauses(G_HEX, H_HEX, RING_N),
275
+ { '<': [{ '+': [{ var: 'state.withdrawCount' }, 1] }, { var: 'state.anonymityTarget' }] },
276
+ ],
277
+ },
278
+ effect: withdrawEffect({}),
279
+ dependencies: [],
280
+ },
281
+ ],
282
+ });