@ottochain/sdk 2.3.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (287) hide show
  1. package/dist/cjs/apps/compute/index.js +33 -0
  2. package/dist/cjs/apps/compute/state-machines/compute-rule110.js +164 -0
  3. package/dist/cjs/apps/compute/state-machines/index.js +9 -0
  4. package/dist/cjs/apps/contracts/index.js +16 -9
  5. package/dist/cjs/apps/contracts/state-machines/contract-agreement.js +134 -161
  6. package/dist/cjs/apps/contracts/state-machines/contract-escrow.js +192 -170
  7. package/dist/cjs/apps/contracts/state-machines/contract-universal.js +46 -58
  8. package/dist/cjs/apps/corporate/index.js +2 -2
  9. package/dist/cjs/apps/corporate/state-machines/corp-board.js +500 -456
  10. package/dist/cjs/apps/corporate/state-machines/corp-entity.js +487 -361
  11. package/dist/cjs/apps/corporate/state-machines/corp-securities.js +769 -576
  12. package/dist/cjs/apps/corporate/state-machines/corp-shareholders.js +567 -557
  13. package/dist/cjs/apps/governance/index.js +21 -21
  14. package/dist/cjs/apps/governance/state-machines/dao-multisig.js +188 -209
  15. package/dist/cjs/apps/governance/state-machines/dao-reputation.js +181 -228
  16. package/dist/cjs/apps/governance/state-machines/dao-single.js +105 -88
  17. package/dist/cjs/apps/governance/state-machines/dao-token.js +199 -227
  18. package/dist/cjs/apps/governance/state-machines/governance-simple.js +231 -231
  19. package/dist/cjs/apps/governance/state-machines/governance-universal.js +64 -64
  20. package/dist/cjs/apps/identity/constants.js +55 -22
  21. package/dist/cjs/apps/identity/index.js +28 -12
  22. package/dist/cjs/apps/identity/state-machines/identity-agent.js +124 -158
  23. package/dist/cjs/apps/identity/state-machines/identity-oracle.js +158 -173
  24. package/dist/cjs/apps/identity/state-machines/identity-registry.js +262 -0
  25. package/dist/cjs/apps/identity/state-machines/identity-universal.js +51 -57
  26. package/dist/cjs/apps/identity/state-machines/index.js +3 -1
  27. package/dist/cjs/apps/index.js +22 -8
  28. package/dist/cjs/apps/lending/assets.js +247 -0
  29. package/dist/cjs/apps/lending/credit-scoring.js +87 -0
  30. package/dist/cjs/apps/lending/eligibility.js +105 -0
  31. package/dist/cjs/apps/lending/index.js +91 -0
  32. package/dist/cjs/apps/lending/state-machines/index.js +9 -0
  33. package/dist/cjs/apps/lending/state-machines/lending-zk-loan.js +433 -0
  34. package/dist/cjs/apps/markets/index.js +22 -12
  35. package/dist/cjs/apps/markets/state-machines/market-auction.js +116 -134
  36. package/dist/cjs/apps/markets/state-machines/market-crowdfund.js +131 -141
  37. package/dist/cjs/apps/markets/state-machines/market-group-buy.js +163 -184
  38. package/dist/cjs/apps/markets/state-machines/market-prediction.js +226 -233
  39. package/dist/cjs/apps/markets/state-machines/market-universal.js +65 -80
  40. package/dist/cjs/apps/oracles/index.js +3 -3
  41. package/dist/cjs/apps/privacy/index.js +67 -0
  42. package/dist/cjs/apps/privacy/state-machines/index.js +17 -0
  43. package/dist/cjs/apps/privacy/state-machines/mixer-ddhRing.js +286 -0
  44. package/dist/cjs/apps/privacy/state-machines/note-pool.js +476 -0
  45. package/dist/cjs/apps/staked-pool/assets.js +103 -0
  46. package/dist/cjs/apps/staked-pool/base.js +498 -0
  47. package/dist/cjs/apps/staked-pool/consumer.js +55 -0
  48. package/dist/cjs/apps/staked-pool/index.js +83 -0
  49. package/dist/cjs/apps/staked-pool/state-machines/index.js +12 -0
  50. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-base.js +49 -0
  51. package/dist/cjs/apps/staked-pool/state-machines/staked-pool-oracle.js +131 -0
  52. package/dist/cjs/errors.js +3 -3
  53. package/dist/cjs/generated/google/protobuf/struct.js +5 -5
  54. package/dist/cjs/generated/google/protobuf/timestamp.js +1 -1
  55. package/dist/cjs/generated/index.js +11 -7
  56. package/dist/cjs/generated/openapi.js +6 -0
  57. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +51 -51
  58. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +20 -21
  59. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +14 -14
  60. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +5 -5
  61. package/dist/cjs/generated/ottochain/apps/identity/v1/identity.js +125 -131
  62. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +108 -108
  63. package/dist/cjs/generated/ottochain/v1/common.js +5 -5
  64. package/dist/cjs/generated/ottochain/v1/fiber.js +44 -6
  65. package/dist/cjs/generated/ottochain/v1/messages.js +1 -1
  66. package/dist/cjs/generated/ottochain/v1/records.js +1 -1
  67. package/dist/cjs/index.js +58 -7
  68. package/dist/cjs/openapi.js +2 -0
  69. package/dist/cjs/ottochain/drop-nulls.js +1 -2
  70. package/dist/cjs/ottochain/genesis-manifest.js +17 -11
  71. package/dist/cjs/ottochain/index.js +23 -13
  72. package/dist/cjs/ottochain/metagraph-client.js +81 -16
  73. package/dist/cjs/ottochain/snapshot.js +13 -16
  74. package/dist/cjs/ottochain/transaction.js +67 -14
  75. package/dist/cjs/ottochain/types.js +16 -2
  76. package/dist/cjs/privacy/index.js +14 -0
  77. package/dist/cjs/privacy/sealed-bid.js +213 -0
  78. package/dist/cjs/privacy/shield-app.js +131 -0
  79. package/dist/cjs/schema/effects.js +156 -0
  80. package/dist/cjs/schema/fiber-app.js +150 -15
  81. package/dist/cjs/schema/guard-lint.js +343 -0
  82. package/dist/cjs/schema/guards.js +246 -0
  83. package/dist/cjs/signing.js +80 -0
  84. package/dist/cjs/templates/asset-policy.js +190 -0
  85. package/dist/cjs/templates/index.js +86 -0
  86. package/dist/cjs/templates/machine.js +130 -0
  87. package/dist/cjs/templates/migration.js +39 -0
  88. package/dist/cjs/templates/state-shape.js +38 -0
  89. package/dist/cjs/types.js +2 -3
  90. package/dist/cjs/validation.js +9 -11
  91. package/dist/cjs/verify.js +9 -4
  92. package/dist/cjs/zk/commit.js +53 -0
  93. package/dist/cjs/zk/guard.js +107 -0
  94. package/dist/cjs/zk/index.js +48 -0
  95. package/dist/cjs/zk/preimage.js +37 -0
  96. package/dist/cjs/zk/prover.js +87 -0
  97. package/dist/cjs/zk/registry.js +62 -0
  98. package/dist/cjs/zk/types.js +28 -0
  99. package/dist/cjs/zk/witness.js +19 -0
  100. package/dist/esm/apps/compute/index.js +29 -0
  101. package/dist/esm/apps/compute/state-machines/compute-rule110.js +161 -0
  102. package/dist/esm/apps/compute/state-machines/index.js +5 -0
  103. package/dist/esm/apps/contracts/index.js +9 -5
  104. package/dist/esm/apps/contracts/state-machines/contract-agreement.js +135 -162
  105. package/dist/esm/apps/contracts/state-machines/contract-escrow.js +193 -171
  106. package/dist/esm/apps/contracts/state-machines/contract-universal.js +47 -59
  107. package/dist/esm/apps/corporate/index.js +2 -2
  108. package/dist/esm/apps/corporate/state-machines/corp-board.js +501 -457
  109. package/dist/esm/apps/corporate/state-machines/corp-entity.js +488 -362
  110. package/dist/esm/apps/corporate/state-machines/corp-securities.js +770 -577
  111. package/dist/esm/apps/corporate/state-machines/corp-shareholders.js +568 -558
  112. package/dist/esm/apps/governance/index.js +10 -10
  113. package/dist/esm/apps/governance/state-machines/dao-multisig.js +189 -210
  114. package/dist/esm/apps/governance/state-machines/dao-reputation.js +182 -229
  115. package/dist/esm/apps/governance/state-machines/dao-single.js +106 -89
  116. package/dist/esm/apps/governance/state-machines/dao-token.js +200 -228
  117. package/dist/esm/apps/governance/state-machines/governance-simple.js +232 -232
  118. package/dist/esm/apps/governance/state-machines/governance-universal.js +65 -65
  119. package/dist/esm/apps/identity/constants.js +52 -21
  120. package/dist/esm/apps/identity/index.js +14 -9
  121. package/dist/esm/apps/identity/state-machines/identity-agent.js +125 -159
  122. package/dist/esm/apps/identity/state-machines/identity-oracle.js +159 -174
  123. package/dist/esm/apps/identity/state-machines/identity-registry.js +259 -0
  124. package/dist/esm/apps/identity/state-machines/identity-universal.js +52 -58
  125. package/dist/esm/apps/identity/state-machines/index.js +1 -0
  126. package/dist/esm/apps/index.js +9 -5
  127. package/dist/esm/apps/lending/assets.js +231 -0
  128. package/dist/esm/apps/lending/credit-scoring.js +81 -0
  129. package/dist/esm/apps/lending/eligibility.js +99 -0
  130. package/dist/esm/apps/lending/index.js +69 -0
  131. package/dist/esm/apps/lending/state-machines/index.js +5 -0
  132. package/dist/esm/apps/lending/state-machines/lending-zk-loan.js +430 -0
  133. package/dist/esm/apps/markets/index.js +11 -7
  134. package/dist/esm/apps/markets/state-machines/market-auction.js +117 -135
  135. package/dist/esm/apps/markets/state-machines/market-crowdfund.js +132 -142
  136. package/dist/esm/apps/markets/state-machines/market-group-buy.js +164 -185
  137. package/dist/esm/apps/markets/state-machines/market-prediction.js +227 -234
  138. package/dist/esm/apps/markets/state-machines/market-universal.js +66 -81
  139. package/dist/esm/apps/oracles/index.js +3 -3
  140. package/dist/esm/apps/privacy/index.js +56 -0
  141. package/dist/esm/apps/privacy/state-machines/index.js +6 -0
  142. package/dist/esm/apps/privacy/state-machines/mixer-ddhRing.js +282 -0
  143. package/dist/esm/apps/privacy/state-machines/note-pool.js +470 -0
  144. package/dist/esm/apps/staked-pool/assets.js +91 -0
  145. package/dist/esm/apps/staked-pool/base.js +493 -0
  146. package/dist/esm/apps/staked-pool/consumer.js +49 -0
  147. package/dist/esm/apps/staked-pool/index.js +60 -0
  148. package/dist/esm/apps/staked-pool/state-machines/index.js +6 -0
  149. package/dist/esm/apps/staked-pool/state-machines/staked-pool-base.js +46 -0
  150. package/dist/esm/apps/staked-pool/state-machines/staked-pool-oracle.js +127 -0
  151. package/dist/esm/generated/google/protobuf/struct.js +1 -1
  152. package/dist/esm/generated/google/protobuf/timestamp.js +1 -1
  153. package/dist/esm/generated/index.js +9 -5
  154. package/dist/esm/generated/openapi.js +5 -0
  155. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +47 -47
  156. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +1 -1
  157. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +1 -1
  158. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +1 -1
  159. package/dist/esm/generated/ottochain/apps/identity/v1/identity.js +115 -121
  160. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +101 -101
  161. package/dist/esm/generated/ottochain/v1/common.js +1 -1
  162. package/dist/esm/generated/ottochain/v1/fiber.js +40 -2
  163. package/dist/esm/generated/ottochain/v1/messages.js +1 -1
  164. package/dist/esm/generated/ottochain/v1/records.js +1 -1
  165. package/dist/esm/index.js +28 -3
  166. package/dist/esm/openapi.js +1 -0
  167. package/dist/esm/ottochain/genesis-manifest.js +15 -9
  168. package/dist/esm/ottochain/index.js +2 -3
  169. package/dist/esm/ottochain/metagraph-client.js +81 -16
  170. package/dist/esm/ottochain/snapshot.js +6 -8
  171. package/dist/esm/ottochain/transaction.js +51 -3
  172. package/dist/esm/ottochain/types.js +15 -1
  173. package/dist/esm/privacy/index.js +6 -0
  174. package/dist/esm/privacy/sealed-bid.js +209 -0
  175. package/dist/esm/privacy/shield-app.js +127 -0
  176. package/dist/esm/schema/effects.js +145 -0
  177. package/dist/esm/schema/fiber-app.js +139 -8
  178. package/dist/esm/schema/guard-lint.js +337 -0
  179. package/dist/esm/schema/guards.js +228 -0
  180. package/dist/esm/signing.js +74 -0
  181. package/dist/esm/templates/asset-policy.js +182 -0
  182. package/dist/esm/templates/index.js +41 -0
  183. package/dist/esm/templates/machine.js +125 -0
  184. package/dist/esm/templates/migration.js +34 -0
  185. package/dist/esm/templates/state-shape.js +34 -0
  186. package/dist/esm/validation.js +1 -3
  187. package/dist/esm/verify.js +8 -2
  188. package/dist/esm/zk/commit.js +44 -0
  189. package/dist/esm/zk/guard.js +99 -0
  190. package/dist/esm/zk/index.js +19 -0
  191. package/dist/esm/zk/preimage.js +30 -0
  192. package/dist/esm/zk/prover.js +82 -0
  193. package/dist/esm/zk/registry.js +55 -0
  194. package/dist/esm/zk/types.js +25 -0
  195. package/dist/esm/zk/witness.js +15 -0
  196. package/dist/types/apps/compute/index.d.ts +176 -0
  197. package/dist/types/apps/compute/state-machines/compute-rule110.d.ts +157 -0
  198. package/dist/types/apps/compute/state-machines/index.d.ts +5 -0
  199. package/dist/types/apps/contracts/index.d.ts +81 -221
  200. package/dist/types/apps/contracts/state-machines/contract-agreement.d.ts +23 -98
  201. package/dist/types/apps/contracts/state-machines/contract-escrow.d.ts +49 -115
  202. package/dist/types/apps/contracts/state-machines/contract-universal.d.ts +4 -4
  203. package/dist/types/apps/corporate/index.d.ts +1176 -440
  204. package/dist/types/apps/corporate/state-machines/corp-board.d.ts +271 -135
  205. package/dist/types/apps/corporate/state-machines/corp-entity.d.ts +279 -74
  206. package/dist/types/apps/corporate/state-machines/corp-securities.d.ts +373 -149
  207. package/dist/types/apps/corporate/state-machines/corp-shareholders.d.ts +252 -80
  208. package/dist/types/apps/governance/index.d.ts +368 -470
  209. package/dist/types/apps/governance/state-machines/dao-multisig.d.ts +92 -107
  210. package/dist/types/apps/governance/state-machines/dao-reputation.d.ts +61 -85
  211. package/dist/types/apps/governance/state-machines/dao-single.d.ts +25 -47
  212. package/dist/types/apps/governance/state-machines/dao-token.d.ts +79 -68
  213. package/dist/types/apps/governance/state-machines/governance-simple.d.ts +95 -125
  214. package/dist/types/apps/governance/state-machines/governance-universal.d.ts +6 -6
  215. package/dist/types/apps/identity/constants.d.ts +33 -5
  216. package/dist/types/apps/identity/index.d.ts +415 -131
  217. package/dist/types/apps/identity/state-machines/identity-agent.d.ts +23 -23
  218. package/dist/types/apps/identity/state-machines/identity-oracle.d.ts +27 -98
  219. package/dist/types/apps/identity/state-machines/identity-registry.d.ts +379 -0
  220. package/dist/types/apps/identity/state-machines/identity-universal.d.ts +4 -4
  221. package/dist/types/apps/identity/state-machines/index.d.ts +1 -0
  222. package/dist/types/apps/index.d.ts +9 -5
  223. package/dist/types/apps/lending/assets.d.ts +258 -0
  224. package/dist/types/apps/lending/credit-scoring.d.ts +80 -0
  225. package/dist/types/apps/lending/eligibility.d.ts +83 -0
  226. package/dist/types/apps/lending/index.d.ts +556 -0
  227. package/dist/types/apps/lending/state-machines/index.d.ts +5 -0
  228. package/dist/types/apps/lending/state-machines/lending-zk-loan.d.ts +536 -0
  229. package/dist/types/apps/markets/index.d.ts +181 -276
  230. package/dist/types/apps/markets/state-machines/market-auction.d.ts +25 -49
  231. package/dist/types/apps/markets/state-machines/market-crowdfund.d.ts +35 -53
  232. package/dist/types/apps/markets/state-machines/market-group-buy.d.ts +35 -61
  233. package/dist/types/apps/markets/state-machines/market-prediction.d.ts +65 -86
  234. package/dist/types/apps/markets/state-machines/market-universal.d.ts +12 -12
  235. package/dist/types/apps/oracles/index.d.ts +1 -1
  236. package/dist/types/apps/privacy/index.d.ts +328 -0
  237. package/dist/types/apps/privacy/state-machines/index.d.ts +6 -0
  238. package/dist/types/apps/privacy/state-machines/mixer-ddhRing.d.ts +337 -0
  239. package/dist/types/apps/privacy/state-machines/note-pool.d.ts +196 -0
  240. package/dist/types/apps/staked-pool/assets.d.ts +53 -0
  241. package/dist/types/apps/staked-pool/base.d.ts +80 -0
  242. package/dist/types/apps/staked-pool/consumer.d.ts +29 -0
  243. package/dist/types/apps/staked-pool/index.d.ts +51 -0
  244. package/dist/types/apps/staked-pool/state-machines/index.d.ts +6 -0
  245. package/dist/types/apps/staked-pool/state-machines/staked-pool-base.d.ts +8 -0
  246. package/dist/types/apps/staked-pool/state-machines/staked-pool-oracle.d.ts +34 -0
  247. package/dist/types/generated/index.d.ts +5 -5
  248. package/dist/types/generated/openapi.d.ts +1270 -0
  249. package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +5 -5
  250. package/dist/types/generated/ottochain/apps/identity/v1/identity.d.ts +12 -12
  251. package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +11 -11
  252. package/dist/types/generated/ottochain/v1/fiber.d.ts +7 -0
  253. package/dist/types/index.d.ts +7 -3
  254. package/dist/types/openapi.d.ts +24 -0
  255. package/dist/types/ottochain/genesis-manifest.d.ts +11 -5
  256. package/dist/types/ottochain/index.d.ts +5 -6
  257. package/dist/types/ottochain/metagraph-client.d.ts +49 -7
  258. package/dist/types/ottochain/snapshot.d.ts +6 -6
  259. package/dist/types/ottochain/transaction.d.ts +41 -1
  260. package/dist/types/ottochain/types.d.ts +336 -31
  261. package/dist/types/privacy/index.d.ts +6 -0
  262. package/dist/types/privacy/sealed-bid.d.ts +348 -0
  263. package/dist/types/privacy/shield-app.d.ts +48 -0
  264. package/dist/types/schema/effects.d.ts +141 -0
  265. package/dist/types/schema/fiber-app.d.ts +282 -2
  266. package/dist/types/schema/guard-lint.d.ts +111 -0
  267. package/dist/types/schema/guards.d.ts +146 -0
  268. package/dist/types/signing.d.ts +45 -0
  269. package/dist/types/templates/asset-policy.d.ts +119 -0
  270. package/dist/types/templates/index.d.ts +26 -0
  271. package/dist/types/templates/machine.d.ts +139 -0
  272. package/dist/types/templates/migration.d.ts +34 -0
  273. package/dist/types/templates/state-shape.d.ts +30 -0
  274. package/dist/types/validation.d.ts +22 -217
  275. package/dist/types/verify.d.ts +4 -0
  276. package/dist/types/zk/commit.d.ts +28 -0
  277. package/dist/types/zk/guard.d.ts +46 -0
  278. package/dist/types/zk/index.d.ts +19 -0
  279. package/dist/types/zk/preimage.d.ts +10 -0
  280. package/dist/types/zk/prover.d.ts +34 -0
  281. package/dist/types/zk/registry.d.ts +34 -0
  282. package/dist/types/zk/types.d.ts +33 -0
  283. package/dist/types/zk/witness.d.ts +40 -0
  284. package/package.json +47 -15
  285. package/dist/cjs/ottochain/normalize.js +0 -186
  286. package/dist/esm/ottochain/normalize.js +0 -179
  287. package/dist/types/ottochain/normalize.d.ts +0 -79
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sumBehavior = sumBehavior;
4
+ exports.defaultStateTypeName = defaultStateTypeName;
5
+ exports.fungiblePolicy = fungiblePolicy;
6
+ exports.nftPolicy = nftPolicy;
7
+ exports.soulboundPolicy = soulboundPolicy;
8
+ exports.customPolicy = customPolicy;
9
+ /**
10
+ * Asset-policy preset builders (§1.1 of the SDK std-lib/templates handoff).
11
+ *
12
+ * Each builder is a PURE function that emits the exact {@link CreateAssetPolicy} wire body the chain
13
+ * re-derives — no `Date.now()`/`Math.random()`/`crypto.randomUUID()`; fixed inputs → fixed output. The
14
+ * on-chain policy `schemaHash` and `logicHash` are both `RegistryShape.AssetPolicy.computeDigest` over
15
+ * `behavior`/`supply`/`morphisms`/`stateShape` (no JSON-Logic body), so these presets are pure data.
16
+ *
17
+ * Hard invariants (CLAUDE.md rule #1 — the signed canonical is frozen):
18
+ * - `behavior` is ALWAYS summed from {@link TOKEN_BEHAVIOR_BITS} (T=16, S=8, C=4, E=2, G=1), never a
19
+ * magic literal int.
20
+ * - `morphisms` is REQUIRED on the wire (presence required, emptiness meaningful) — emit `{}` when empty,
21
+ * NEVER omit it.
22
+ * - `supply` is REQUIRED — emit `{}` when there is no supply authority, never omit it.
23
+ * - Absent optionals are OMITTED, never emitted as `null`/`undefined` (the chain signs over
24
+ * `JCS(dropNulls(payload))`).
25
+ *
26
+ * @see src/ottochain/types.ts — CreateAssetPolicy, SupplyPolicy, MorphismSpec, MorphismKind, TOKEN_BEHAVIOR_BITS
27
+ */
28
+ const types_js_1 = require("../ottochain/types.js");
29
+ /** The default mint/burn guard the riverdale presets use: an always-true predicate `{"==":[1,1]}`. */
30
+ const alwaysTrue = () => ({ '==': [1, 1] });
31
+ /** A `PUBLIC`-visibility morphism spec (the riverdale preset visibility). Fresh object per call. */
32
+ const publicMorphism = () => ({ visibility: 'PUBLIC' });
33
+ /** Sum behavior bits from their NAMES — never a magic literal int (CLAUDE.md #1). */
34
+ function sumBehavior(bits) {
35
+ return bits.reduce((acc, name) => acc + types_js_1.TOKEN_BEHAVIOR_BITS[name], 0);
36
+ }
37
+ /**
38
+ * Derive the default `stateShape.typeName`: strip a trailing `.asset` label, PascalCase the remainder
39
+ * (splitting on `.`/`-`/`_`/space), then append `State`.
40
+ * `rvd.asset` → `RvdState`, `goods.asset` → `GoodsState`, `capped.asset` → `CappedState`.
41
+ */
42
+ function defaultStateTypeName(name) {
43
+ const ASSET_SUFFIX = '.asset';
44
+ const base = name.endsWith(ASSET_SUFFIX) ? name.slice(0, -ASSET_SUFFIX.length) : name;
45
+ const pascal = base
46
+ .split(/[.\-_\s]+/)
47
+ .filter(Boolean)
48
+ .map((seg) => seg.charAt(0).toUpperCase() + seg.slice(1))
49
+ .join('');
50
+ return `${pascal}State`;
51
+ }
52
+ /** Build a {@link SupplyPolicy}, OMITTING every absent field (no `undefined`/`null` keys). */
53
+ function buildSupply(opts) {
54
+ const supply = {};
55
+ if (opts.maxSupply !== undefined)
56
+ supply.maxSupply = opts.maxSupply;
57
+ if (opts.mintPolicy !== undefined)
58
+ supply.mintPolicy = opts.mintPolicy;
59
+ if (opts.burnPolicy !== undefined)
60
+ supply.burnPolicy = opts.burnPolicy;
61
+ if (opts.decimals !== undefined)
62
+ supply.decimals = opts.decimals;
63
+ return supply;
64
+ }
65
+ /** Assemble the final {@link CreateAssetPolicy}, attaching `metadata` only when present. */
66
+ function assemble(args) {
67
+ const stateShape = {
68
+ typeName: args.stateTypeName ?? defaultStateTypeName(args.name),
69
+ fields: [],
70
+ };
71
+ const policy = {
72
+ name: args.name,
73
+ version: args.version,
74
+ behavior: args.behavior,
75
+ supply: args.supply,
76
+ morphisms: args.morphisms,
77
+ stateShape,
78
+ };
79
+ if (args.metadata !== undefined)
80
+ policy.metadata = args.metadata;
81
+ return policy;
82
+ }
83
+ /**
84
+ * Fungible currency. Behavior `T|S|C = 28` (transferable + splittable + combinable). Standard morphism
85
+ * set TRANSFER + FRACTIONALIZE + STAKE (`stakeable`, default true) + BURN (when `burnable`), all PUBLIC.
86
+ *
87
+ * Reproduces `riverdale-economy/rvd-policy.json` exactly via
88
+ * `fungiblePolicy({ name: 'rvd.asset', version: '1.0.0', mintable: true, burnable: true })`.
89
+ */
90
+ function fungiblePolicy(p) {
91
+ const behavior = sumBehavior(['transferable', 'splittable', 'combinable']); // 28
92
+ const morphisms = {
93
+ TRANSFER: publicMorphism(),
94
+ FRACTIONALIZE: publicMorphism(),
95
+ };
96
+ if (p.stakeable !== false)
97
+ morphisms.STAKE = publicMorphism();
98
+ if (p.burnable)
99
+ morphisms.BURN = publicMorphism();
100
+ let mintPolicy;
101
+ if (p.mintGuard !== undefined)
102
+ mintPolicy = p.mintGuard;
103
+ else if (p.mintable)
104
+ mintPolicy = alwaysTrue();
105
+ const supply = buildSupply({
106
+ maxSupply: p.maxSupply,
107
+ mintPolicy,
108
+ burnPolicy: p.burnable ? alwaysTrue() : undefined,
109
+ decimals: p.decimals,
110
+ });
111
+ return assemble({
112
+ name: p.name,
113
+ version: p.version,
114
+ behavior,
115
+ supply,
116
+ morphisms,
117
+ stateTypeName: p.stateTypeName,
118
+ metadata: p.metadata,
119
+ });
120
+ }
121
+ /**
122
+ * Non-fungible token. Behavior `T = 16`, or `T|C = 20` with `combinable: true` (the riverdale
123
+ * `goods.asset`); `transferable: false` drops the T bit (a bound collectible). `morphisms` is `{}` by
124
+ * default (emitted explicitly, never omitted). Mintable by default ⇒ `supply.mintPolicy = {"==":[1,1]}`.
125
+ *
126
+ * Reproduces `riverdale-economy/goods-policy.json` exactly via
127
+ * `nftPolicy({ name: 'goods.asset', version: '1.0.0', combinable: true })`.
128
+ */
129
+ function nftPolicy(p) {
130
+ const bits = [];
131
+ if (p.transferable !== false)
132
+ bits.push('transferable');
133
+ if (p.combinable)
134
+ bits.push('combinable');
135
+ const behavior = sumBehavior(bits);
136
+ let mintPolicy;
137
+ if (p.mintGuard !== undefined)
138
+ mintPolicy = p.mintGuard;
139
+ else if (p.mintable !== false)
140
+ mintPolicy = alwaysTrue();
141
+ const supply = buildSupply({ maxSupply: p.maxSupply, mintPolicy });
142
+ return assemble({
143
+ name: p.name,
144
+ version: p.version,
145
+ behavior,
146
+ supply,
147
+ morphisms: {},
148
+ stateTypeName: p.stateTypeName,
149
+ metadata: p.metadata,
150
+ });
151
+ }
152
+ /**
153
+ * Soulbound token: non-transferable, governable only (`G = 1`; `+E = 3` when `expirable`). No TRANSFER
154
+ * morphism (`morphisms: {}`); minting is closed after issue (empty `supply`).
155
+ */
156
+ function soulboundPolicy(p) {
157
+ const bits = ['governable'];
158
+ if (p.expirable)
159
+ bits.push('expirable');
160
+ const behavior = sumBehavior(bits);
161
+ return assemble({
162
+ name: p.name,
163
+ version: p.version,
164
+ behavior,
165
+ supply: buildSupply({}), // mint closed after issue
166
+ morphisms: {}, // non-transferable: no TRANSFER morphism
167
+ stateTypeName: p.stateTypeName,
168
+ metadata: p.metadata,
169
+ });
170
+ }
171
+ /**
172
+ * Escape hatch: declare `behavior` by NAME (summed from {@link TOKEN_BEHAVIOR_BITS}, never a magic int)
173
+ * and pass `supply` + `morphisms` through raw. Use when no preset fits.
174
+ *
175
+ * Reproduces `riverdale-economy/capped-policy.json` exactly via
176
+ * `customPolicy({ name: 'capped.asset', version: '1.0.0',
177
+ * behavior: ['transferable', 'splittable', 'combinable'],
178
+ * supply: { maxSupply: 100, mintPolicy: { '==': [1, 1] } }, morphisms: {} })`.
179
+ */
180
+ function customPolicy(p) {
181
+ return assemble({
182
+ name: p.name,
183
+ version: p.version,
184
+ behavior: sumBehavior(p.behavior),
185
+ supply: p.supply,
186
+ morphisms: p.morphisms,
187
+ stateTypeName: p.stateTypeName,
188
+ metadata: p.metadata,
189
+ });
190
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /**
3
+ * `@ottochain/sdk/templates` — the fiber & asset authoring template catalog.
4
+ *
5
+ * Typed builders that emit the EXACT canonical wire shapes app authors otherwise hand-roll as raw
6
+ * JSON-Logic (asset policies, versioned machines, effect directives, migrations, seeded state). Every
7
+ * builder is additive and pure — it returns the same wire shape the chain re-derives, so a template
8
+ * output signs to byte-identical `JCS(dropNulls(payload))` (CLAUDE.md rule #1). Hand-rolled JSON keeps
9
+ * working; these just make the recurring shapes typed, named, and mistake-resistant.
10
+ *
11
+ * Origin: the fiber-ergonomics program (ottochain `docs/proposals/fiber-ergonomics/`), Phase A — the
12
+ * `riverdale-economy` e2e is the migration proof (each preset reproduces its checked-in golden JSON).
13
+ *
14
+ * @example
15
+ * import {
16
+ * fungiblePolicy, machine, transition, effect, guard,
17
+ * transferAsset, triggers, spawn, seedState, seedFields,
18
+ * } from '@ottochain/sdk/templates';
19
+ */
20
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ var desc = Object.getOwnPropertyDescriptor(m, k);
23
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
+ desc = { enumerable: true, get: function() { return m[k]; } };
25
+ }
26
+ Object.defineProperty(o, k2, desc);
27
+ }) : (function(o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ }));
31
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
33
+ }) : function(o, v) {
34
+ o["default"] = v;
35
+ });
36
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
37
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
38
+ };
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.projectFiberPolicy = exports.immutable = exports.unconstrained = exports.constrained = exports.toProtoDefinition = exports.defineFiberApp = exports.guard = void 0;
58
+ // ─── 1.1 Asset-policy presets ────────────────────────────────────────────────
59
+ // fungiblePolicy / nftPolicy / soulboundPolicy / customPolicy (+ sumBehavior, defaultStateTypeName,
60
+ // BehaviorBitName) — emit a `CreateAssetPolicy`; behavior is summed from TOKEN_BEHAVIOR_BITS, never a literal.
61
+ __exportStar(require("./asset-policy.js"), exports);
62
+ // ─── 1.2 Versioned-machine skeleton + transition()/effect() ──────────────────
63
+ // machine / transition / effect (+ TransitionSpec, MachineSpec, Machine, …). The skeleton owns ONE
64
+ // canonical wire definition, so publish + create cannot drift (verified binding, F9).
65
+ __exportStar(require("./machine.js"), exports);
66
+ // ─── 1.4 Migration helpers ───────────────────────────────────────────────────
67
+ // seedFields / migration — hides the bare-state-root ({"var":""}) foot-gun.
68
+ __exportStar(require("./migration.js"), exports);
69
+ // ─── 1.5 State-shape-with-defaults ───────────────────────────────────────────
70
+ // seedState / declaredFields / StateShape — auto-seed accumulators so no field reads null (F5).
71
+ __exportStar(require("./state-shape.js"), exports);
72
+ // ─── 1.3 Effect-directive builders ───────────────────────────────────────────
73
+ // transferAsset / triggers / spawn / emit / toFiber / toWallet / addDependency / setDependencyActive /
74
+ // RESERVED_EFFECT_KEYS — a typo'd directive is a TS error, not a silent state field (F4).
75
+ __exportStar(require("../schema/effects.js"), exports);
76
+ // ─── Authorization-guard builders (namespace) ────────────────────────────────
77
+ // `guard.signerIsParty('state.borrower')` reads as intent at the call site.
78
+ exports.guard = __importStar(require("../schema/guards.js"));
79
+ // ─── Existing machine/policy primitives re-surfaced for one-import authoring ──
80
+ var fiber_app_js_1 = require("../schema/fiber-app.js");
81
+ Object.defineProperty(exports, "defineFiberApp", { enumerable: true, get: function () { return fiber_app_js_1.defineFiberApp; } });
82
+ Object.defineProperty(exports, "toProtoDefinition", { enumerable: true, get: function () { return fiber_app_js_1.toProtoDefinition; } });
83
+ Object.defineProperty(exports, "constrained", { enumerable: true, get: function () { return fiber_app_js_1.constrained; } });
84
+ Object.defineProperty(exports, "unconstrained", { enumerable: true, get: function () { return fiber_app_js_1.unconstrained; } });
85
+ Object.defineProperty(exports, "immutable", { enumerable: true, get: function () { return fiber_app_js_1.immutable; } });
86
+ Object.defineProperty(exports, "projectFiberPolicy", { enumerable: true, get: function () { return fiber_app_js_1.projectFiberPolicy; } });
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ /**
3
+ * Versioned-machine skeleton + `transition()` / `effect()` composition (handoff §1.2).
4
+ *
5
+ * Two moves:
6
+ * 1. `transition()` / `effect()` build the wire `Transition` + its flat effect map from typed
7
+ * fragments instead of a hand-rolled JSON blob.
8
+ * 2. `machine()` is a versioned-package SKELETON that OWNS exactly ONE canonical wire definition
9
+ * (`toProtoDefinition(app)`, computed once) and hands the SAME object to BOTH `publishVersion()`
10
+ * and `create()`. That is the verified-binding invariant (F9): because publish and create cannot
11
+ * drift, the chain's `definition.computeDigest` equals the registered `logicHash` and the bind
12
+ * admits the fiber. The skeleton REUSES `toProtoDefinition` (the one canonicalization path) — it
13
+ * never re-derives the wire shape.
14
+ *
15
+ * Guardrail (CLAUDE.md #1): every builder here is a pure function emitting the exact wire shape the
16
+ * chain re-derives. Absent optionals (`metadata`/`participants`/`parentFiberId`/`migration`) are
17
+ * OMITTED, never `null`; required-no-default fields (`strict` on publish, `dependencies: []` per
18
+ * transition) are ALWAYS present.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.transition = transition;
22
+ exports.effect = effect;
23
+ exports.machine = machine;
24
+ const fiber_app_js_1 = require("../schema/fiber-app.js");
25
+ /**
26
+ * Build a wire {@link Transition} from a typed spec.
27
+ *
28
+ * - `on` → `eventName` (the wire key);
29
+ * - `guard` defaults to `{ "==": [1, 1] }`;
30
+ * - `dependencies` defaults to `[]` and is ALWAYS present;
31
+ * - `effect` is passed through (build it with {@link effect}).
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * transition({
36
+ * from: 'debt_current', to: 'debt_current', on: 'buy',
37
+ * effect: effect(
38
+ * { status: 'debt_current', purchaseCount: { '+': [{ var: 'state.purchaseCount' }, 1] } },
39
+ * triggers([...]), transferAsset([...]),
40
+ * ),
41
+ * });
42
+ * ```
43
+ */
44
+ function transition(t) {
45
+ return {
46
+ from: t.from,
47
+ to: t.to,
48
+ eventName: t.on,
49
+ guard: t.guard ?? { '==': [1, 1] },
50
+ effect: t.effect,
51
+ dependencies: t.dependencies ?? [],
52
+ };
53
+ }
54
+ // =============================================================================
55
+ // effect()
56
+ // =============================================================================
57
+ /**
58
+ * Compose an effect into ONE FLAT map: the state-update fields PLUS any `_`-directive fragments,
59
+ * all in a single object (`Object.assign({}, stateUpdate, ...directives)`).
60
+ *
61
+ * Riverdale effects are flat maps that mix `_`-reserved directives (`_triggers`, `_transferAsset`,
62
+ * `_spawn`, …) with plain state-update fields — they are NOT `merge`-wrapped. Each directive fragment
63
+ * is a `Record` (e.g. the output of `transferAsset(...)` / `triggers(...)`), spread in here. Later
64
+ * fragments override earlier keys (`Object.assign` semantics).
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * effect(
69
+ * { status: 'debt_current', purchaseCount: { '+': [{ var: 'state.purchaseCount' }, 1] } },
70
+ * { _triggers: [...] },
71
+ * transferAsset([{ assetId: { var: 'event.payAssetId' }, recipient: toFiber({ var: 'event.retailerId' }) }]),
72
+ * );
73
+ * // => { status, purchaseCount, _triggers, _transferAsset }
74
+ * ```
75
+ */
76
+ function effect(stateUpdate, ...directives) {
77
+ return Object.assign({}, stateUpdate, ...directives);
78
+ }
79
+ /** A pinned-Exact `SchemaRef` for `name@version`. Wire: `{ name, version: { Exact: { version } } }`. */
80
+ function exactRef(name, version) {
81
+ return { name, version: { Exact: { version } } };
82
+ }
83
+ /**
84
+ * Build a versioned-machine skeleton that binds publish + create to ONE canonical definition.
85
+ *
86
+ * The definition is projected ONCE here (`toProtoDefinition(spec.app)`) and the SAME reference is handed
87
+ * to `wireDefinition()`, `publishVersion().definition`, `create().definition`, and
88
+ * `upgradeFrom().newDefinition` — so they cannot drift and the chain's verified binding admits the fiber
89
+ * (F9). REUSES `toProtoDefinition` (the single canonicalization path); never re-derives the wire shape.
90
+ */
91
+ function machine(spec) {
92
+ // Project the canonical wire definition ONCE; every consumer reuses this exact reference.
93
+ const wireDef = (0, fiber_app_js_1.toProtoDefinition)(spec.app);
94
+ return {
95
+ wireDefinition() {
96
+ return wireDef;
97
+ },
98
+ publishVersion(o) {
99
+ return {
100
+ name: spec.name,
101
+ version: spec.version,
102
+ // REQUIRED-no-default on the wire; '' is valid empty base64 when no descriptor set is bound.
103
+ schemaB64: o?.schemaB64 ?? '',
104
+ machineShape: spec.schemaShape,
105
+ definition: wireDef, // SAME reference as wireDefinition()/create()
106
+ strict: o?.strict ?? false, // REQUIRED — never omitted
107
+ ...(o?.metadata ? { metadata: o.metadata } : {}), // OMIT when absent
108
+ };
109
+ },
110
+ create(o) {
111
+ return {
112
+ fiberId: o.fiberId,
113
+ definition: wireDef, // SAME reference as wireDefinition()/publishVersion()
114
+ initialData: o.initialData,
115
+ schemaRef: exactRef(spec.name, spec.version), // verified binding: name@version
116
+ ...(o.participants ? { participants: o.participants } : {}), // OMIT when absent
117
+ ...(o.parentFiberId ? { parentFiberId: o.parentFiberId } : {}), // OMIT when absent
118
+ };
119
+ },
120
+ upgradeFrom(o) {
121
+ return {
122
+ fiberId: o.fiberId,
123
+ targetRef: exactRef(spec.name, spec.version),
124
+ newDefinition: wireDef, // SAME reference — re-pin hashes to the same logicHash
125
+ targetSequenceNumber: o.targetSequenceNumber,
126
+ ...(o.migration !== undefined ? { migration: o.migration } : {}), // OMIT (Option) when absent
127
+ };
128
+ },
129
+ };
130
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /**
3
+ * Migration builders — the `UpgradeFiber.migration` JSON-Logic transform applied on a version upgrade.
4
+ *
5
+ * THE FOOT-GUN (F9): a migration's evaluation root is the BARE prior state, not `state.x`.
6
+ * The chain evaluates the migration expression against `sm.stateData` directly
7
+ * (`MeteredEvaluator.eval(expr, sm.stateData, Migration)`, FiberEngine.scala:300), so:
8
+ * - `{ var: '' }` => the WHOLE prior state object
9
+ * - `{ var: 'loyaltyPoints' }` => the top-level `loyaltyPoints` field
10
+ * This is UNLIKE an effect, where the root is the transition context and you read `{ var: 'state.x' }`.
11
+ * Writing `state.loyaltyPoints` in a migration silently reads `undefined`. These helpers hide that
12
+ * asymmetry by pinning the bare-state root for you.
13
+ *
14
+ * `migration` is `Option` on `UpgradeFiber` — when there is no transform, OMIT the key (never send `null`).
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.migration = exports.seedFields = void 0;
18
+ /**
19
+ * Seed / overwrite top-level state fields on a version upgrade.
20
+ * Emits `{ merge: [{ var: '' }, fields] }` — merges `fields` onto the bare prior state, so existing
21
+ * fields are preserved and the named fields are added or overwritten.
22
+ *
23
+ * The `{ var: '' }` root is the BARE prior state (NOT `state.x` like an effect) — that asymmetry is
24
+ * exactly the F9 foot-gun this helper hides.
25
+ *
26
+ * @example seedFields({ loyaltyPoints: 0 }) // => { merge: [{ var: '' }, { loyaltyPoints: 0 }] }
27
+ */
28
+ const seedFields = (fields) => ({
29
+ merge: [{ var: '' }, fields],
30
+ });
31
+ exports.seedFields = seedFields;
32
+ /**
33
+ * General migration transform with the bare-state root made explicit. `build` receives `{ var: '' }`
34
+ * (the whole prior state) and returns the migration JSON-Logic.
35
+ *
36
+ * @example migration((s) => ({ merge: [s, { x: 1 }] })) // => { merge: [{ var: '' }, { x: 1 }] }
37
+ */
38
+ const migration = (build) => build({ var: '' });
39
+ exports.migration = migration;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * State-shape-with-defaults — the SDK half of Proposal 01's "declared state shape" (removes F5).
4
+ *
5
+ * A declared shape carries a `default` (and optional `type`) per field. It seeds `initialData` so every
6
+ * accumulator starts at a concrete value — a counter read via `{ '+': [{ var: 'state.x' }, ...] }` never
7
+ * resolves `null` because `x` was never written. It also yields the set of declared field names for
8
+ * Proposal 01's var-path checks.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.seedState = seedState;
12
+ exports.declaredFields = declaredFields;
13
+ /**
14
+ * Build `initialData` by overlaying `overrides` onto each field's declared `default`.
15
+ * Every declared field gets a concrete value, so no field reads `null` at runtime. An override for a
16
+ * field replaces that field's default; overrides for undeclared fields are ignored (only declared fields
17
+ * are emitted). Determinism: pure function of its inputs, stable key order (declared order).
18
+ *
19
+ * @example seedState({ fields: { purchaseCount: { default: 0 }, status: { default: 'ACTIVE' } } })
20
+ * // => { purchaseCount: 0, status: 'ACTIVE' }
21
+ */
22
+ function seedState(shape, overrides) {
23
+ const seeded = {};
24
+ for (const [name, field] of Object.entries(shape.fields)) {
25
+ seeded[name] =
26
+ overrides !== undefined && Object.prototype.hasOwnProperty.call(overrides, name)
27
+ ? overrides[name]
28
+ : field.default;
29
+ }
30
+ return seeded;
31
+ }
32
+ /**
33
+ * The set of declared state-field names — the fields the effects may read.
34
+ * Feeds Proposal 01's var-path checks (a `{ var: 'state.foo' }` whose `foo` is not declared is suspect).
35
+ */
36
+ function declaredFields(shape) {
37
+ return new Set(Object.keys(shape.fields));
38
+ }
package/dist/cjs/types.js CHANGED
@@ -8,18 +8,17 @@
8
8
  * @packageDocumentation
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isValidFiberId = exports.isValidAddress = void 0;
11
+ exports.isValidAddress = isValidAddress;
12
+ exports.isValidFiberId = isValidFiberId;
12
13
  /**
13
14
  * Validate a DAG address format.
14
15
  */
15
16
  function isValidAddress(value) {
16
17
  return /^DAG[0-9a-zA-Z]+$/.test(value);
17
18
  }
18
- exports.isValidAddress = isValidAddress;
19
19
  /**
20
20
  * Validate a UUID format.
21
21
  */
22
22
  function isValidFiberId(value) {
23
23
  return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
24
24
  }
25
- exports.isValidFiberId = isValidFiberId;
@@ -7,7 +7,14 @@
7
7
  * @packageDocumentation
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.assert = exports.safeParse = exports.validateKeyPair = exports.validateAddress = exports.validatePublicKey = exports.validatePrivateKey = exports.validate = exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = void 0;
10
+ exports.CompleteContractRequestSchema = exports.AcceptContractRequestSchema = exports.ProposeContractRequestSchema = exports.ContractTermsSchema = exports.PlatformLinkSchema = exports.AgentIdentityRegistrationSchema = exports.TransferParamsSchema = exports.CurrencyTransactionSchema = exports.CurrencyTransactionValueSchema = exports.TransactionReferenceSchema = exports.SignedSchema = exports.SignatureProofSchema = exports.KeyPairSchema = exports.PublicKeySchema = exports.PrivateKeySchema = exports.DagAddressSchema = void 0;
11
+ exports.validate = validate;
12
+ exports.validatePrivateKey = validatePrivateKey;
13
+ exports.validatePublicKey = validatePublicKey;
14
+ exports.validateAddress = validateAddress;
15
+ exports.validateKeyPair = validateKeyPair;
16
+ exports.safeParse = safeParse;
17
+ exports.assert = assert;
11
18
  const zod_1 = require("zod");
12
19
  const errors_js_1 = require("./errors.js");
13
20
  // ============================================================================
@@ -26,9 +33,7 @@ const hexString = (length) => {
26
33
  /**
27
34
  * Schema for a DAG address
28
35
  */
29
- exports.DagAddressSchema = zod_1.z
30
- .string()
31
- .regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
36
+ exports.DagAddressSchema = zod_1.z.string().regex(/^DAG[0-9][a-zA-Z0-9]{36}$/, 'Must be a valid DAG address');
32
37
  // ============================================================================
33
38
  // Core Type Schemas
34
39
  // ============================================================================
@@ -209,7 +214,6 @@ function validate(schema, data, fieldName) {
209
214
  }
210
215
  return result.data;
211
216
  }
212
- exports.validate = validate;
213
217
  /**
214
218
  * Validate a private key
215
219
  *
@@ -220,7 +224,6 @@ exports.validate = validate;
220
224
  function validatePrivateKey(privateKey) {
221
225
  return validate(exports.PrivateKeySchema, privateKey, 'privateKey');
222
226
  }
223
- exports.validatePrivateKey = validatePrivateKey;
224
227
  /**
225
228
  * Validate a public key
226
229
  *
@@ -231,7 +234,6 @@ exports.validatePrivateKey = validatePrivateKey;
231
234
  function validatePublicKey(publicKey) {
232
235
  return validate(exports.PublicKeySchema, publicKey, 'publicKey');
233
236
  }
234
- exports.validatePublicKey = validatePublicKey;
235
237
  /**
236
238
  * Validate a DAG address
237
239
  *
@@ -242,7 +244,6 @@ exports.validatePublicKey = validatePublicKey;
242
244
  function validateAddress(address) {
243
245
  return validate(exports.DagAddressSchema, address, 'address');
244
246
  }
245
- exports.validateAddress = validateAddress;
246
247
  /**
247
248
  * Validate a KeyPair
248
249
  *
@@ -253,7 +254,6 @@ exports.validateAddress = validateAddress;
253
254
  function validateKeyPair(keyPair) {
254
255
  return validate(exports.KeyPairSchema, keyPair, 'keyPair');
255
256
  }
256
- exports.validateKeyPair = validateKeyPair;
257
257
  /**
258
258
  * Safe validation that returns a result object instead of throwing
259
259
  *
@@ -295,7 +295,6 @@ function safeParse(schema, data) {
295
295
  }),
296
296
  };
297
297
  }
298
- exports.safeParse = safeParse;
299
298
  /**
300
299
  * Assert that a condition is true, throwing ValidationError if not
301
300
  *
@@ -309,4 +308,3 @@ function assert(condition, message, field) {
309
308
  throw new errors_js_1.ValidationError(message, { field });
310
309
  }
311
310
  }
312
- exports.assert = assert;
@@ -5,13 +5,18 @@
5
5
  * The package embeds `mode: "standard"|"dataUpdate"` in signed objects and
6
6
  * its verify() ignores the `isDataUpdate` parameter when `mode` is present.
7
7
  * This wrapper strips `mode` so callers' explicit `isDataUpdate` always wins.
8
+ *
9
+ * In dataUpdate mode, verification happens over the null-dropped canonical
10
+ * bytes (drop null object fields, preserve array nulls, then RFC 8785) —
11
+ * mirroring the SDK's dataUpdate signers and metakit's content-hash rule.
8
12
  */
9
13
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.verify = void 0;
14
+ exports.verify = verify;
11
15
  const metagraph_sdk_1 = require("@constellation-network/metagraph-sdk");
16
+ const drop_nulls_js_1 = require("./ottochain/drop-nulls.js");
12
17
  function verify(signed, isDataUpdate) {
13
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
18
  const { mode, ...rest } = signed;
15
- return (0, metagraph_sdk_1.verify)(rest, isDataUpdate);
19
+ const isDU = isDataUpdate ?? mode === 'dataUpdate';
20
+ const target = isDU ? { ...rest, value: (0, drop_nulls_js_1.dropNulls)(signed.value) } : rest;
21
+ return (0, metagraph_sdk_1.verify)(target, isDU);
16
22
  }
17
- exports.verify = verify;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.frToHex = exports.toFr = exports.R = void 0;
4
+ exports.randomSalt = randomSalt;
5
+ exports.poseidonCommitN = poseidonCommitN;
6
+ exports.poseidonCommit = poseidonCommit;
7
+ exports.openCommitment = openCommitment;
8
+ /**
9
+ * Poseidon commitments over BN254 Fr, computed through the JLVM `poseidon` opcode — the SAME
10
+ * byte-for-byte implementation the chain and the Rust/Scala circuits use. We deliberately route
11
+ * through `jsonLogic.apply` rather than reimplementing Poseidon: the opcode locks the field order,
12
+ * the circomlib round constants, and the `0x` 32-byte big-endian Fr encoding every crypto opcode
13
+ * expects (hard acceptance vector: `poseidon([1,2]) == 0x115cc0f5…189a`).
14
+ *
15
+ * (The standalone `poseidonHash`/`encodeFr` functions exist inside `-jlvm` but are NOT part of its
16
+ * public export surface — only the VM opcodes are — so the opcode path is also the only stable one.)
17
+ */
18
+ const metagraph_sdk_jlvm_1 = require("@constellation-network/metagraph-sdk-jlvm");
19
+ const node_crypto_1 = require("node:crypto");
20
+ /**
21
+ * BN254 (alt_bn128) scalar field modulus R. A public field constant (not a secret / not Poseidon
22
+ * itself); the `poseidon` opcode re-validates canonicity, so this only drives reduction + sampling.
23
+ */
24
+ exports.R = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
25
+ /** Reduce an arbitrary bigint into a canonical BN254 Fr element `[0, R)`. */
26
+ const toFr = (x) => ((x % exports.R) + exports.R) % exports.R;
27
+ exports.toFr = toFr;
28
+ /** Encode a field element as the lowercase `0x` 32-byte big-endian hex the crypto opcodes expect. */
29
+ const frToHex = (x) => `0x${(0, exports.toFr)(x).toString(16).padStart(64, '0')}`;
30
+ exports.frToHex = frToHex;
31
+ const bytesToBig = (b) => b.reduce((a, x) => (a << 8n) | BigInt(x), 0n);
32
+ /** A fresh random salt as a canonical Fr (rejection-sampled to avoid modulo bias near R). */
33
+ function randomSalt() {
34
+ for (;;) {
35
+ const v = bytesToBig((0, node_crypto_1.randomBytes)(32));
36
+ if (v < exports.R)
37
+ return v;
38
+ }
39
+ }
40
+ /** `cm = Poseidon([...fields, salt])` via the VM's own opcode. Returns the `0x` 32-byte commitment. */
41
+ function poseidonCommitN(fields, saltFr) {
42
+ const inputs = [...fields.map(exports.frToHex), (0, exports.frToHex)(saltFr)];
43
+ // The bundled poseidon supports width t ≤ 5 (≤ 4 inputs incl. the salt); the opcode throws past it.
44
+ return metagraph_sdk_jlvm_1.jsonLogic.apply({ poseidon: inputs }, {});
45
+ }
46
+ /** `cm = Poseidon([fieldFr, saltFr])` — the commitment for one value field (a bid, a score). */
47
+ function poseidonCommit(fieldFr, saltFr) {
48
+ return poseidonCommitN([fieldFr], saltFr);
49
+ }
50
+ /** Commit `fields` under a fresh (or supplied) salt; returns the commitment + opening. */
51
+ function openCommitment(fields, salt = randomSalt()) {
52
+ return { cm: poseidonCommitN(fields, salt), fields, salt };
53
+ }