@ottochain/sdk 0.2.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 (330) hide show
  1. package/README.md +305 -0
  2. package/dist/apps/contracts/index.d.ts +21 -0
  3. package/dist/apps/contracts/index.js +39 -0
  4. package/dist/apps/contracts/types.d.ts +24 -0
  5. package/dist/apps/contracts/types.js +48 -0
  6. package/dist/apps/identity/index.d.ts +22 -0
  7. package/dist/apps/identity/index.js +40 -0
  8. package/dist/apps/identity/types.d.ts +30 -0
  9. package/dist/apps/identity/types.js +53 -0
  10. package/dist/apps/index.d.ts +29 -0
  11. package/dist/apps/index.js +60 -0
  12. package/dist/apps/markets/index.d.ts +26 -0
  13. package/dist/apps/markets/index.js +46 -0
  14. package/dist/apps/markets/types.d.ts +185 -0
  15. package/dist/apps/markets/types.js +252 -0
  16. package/dist/apps/oracles/index.d.ts +26 -0
  17. package/dist/apps/oracles/index.js +46 -0
  18. package/dist/apps/oracles/types.d.ts +211 -0
  19. package/dist/apps/oracles/types.js +306 -0
  20. package/dist/cjs/apps/contracts/index.js +60 -0
  21. package/dist/cjs/apps/contracts/state-machines/contract.json +420 -0
  22. package/dist/cjs/apps/contracts/state-machines/escrow.json +426 -0
  23. package/dist/cjs/apps/contracts/types.js +48 -0
  24. package/dist/cjs/apps/corporate/index.js +112 -0
  25. package/dist/cjs/apps/corporate/state-machines/corporate-board.json +1064 -0
  26. package/dist/cjs/apps/corporate/state-machines/corporate-bylaws.json +751 -0
  27. package/dist/cjs/apps/corporate/state-machines/corporate-committee.json +957 -0
  28. package/dist/cjs/apps/corporate/state-machines/corporate-compliance.json +1293 -0
  29. package/dist/cjs/apps/corporate/state-machines/corporate-entity.json +861 -0
  30. package/dist/cjs/apps/corporate/state-machines/corporate-officers.json +843 -0
  31. package/dist/cjs/apps/corporate/state-machines/corporate-proxy.json +783 -0
  32. package/dist/cjs/apps/corporate/state-machines/corporate-resolution.json +1174 -0
  33. package/dist/cjs/apps/corporate/state-machines/corporate-securities.json +1215 -0
  34. package/dist/cjs/apps/corporate/state-machines/corporate-shareholders.json +1298 -0
  35. package/dist/cjs/apps/corporate/types.js +44 -0
  36. package/dist/cjs/apps/governance/index.js +203 -0
  37. package/dist/cjs/apps/governance/state-machines/dao-multisig.json +711 -0
  38. package/dist/cjs/apps/governance/state-machines/dao-single.json +258 -0
  39. package/dist/cjs/apps/governance/state-machines/dao-threshold.json +660 -0
  40. package/dist/cjs/apps/governance/state-machines/dao-token.json +680 -0
  41. package/dist/cjs/apps/governance/state-machines/governance-constitution.json +401 -0
  42. package/dist/cjs/apps/governance/state-machines/governance-executive.json +441 -0
  43. package/dist/cjs/apps/governance/state-machines/governance-judiciary.json +626 -0
  44. package/dist/cjs/apps/governance/state-machines/governance-legislature.json +726 -0
  45. package/dist/cjs/apps/governance/state-machines/governance-simple.json +679 -0
  46. package/dist/cjs/apps/governance/types.js +42 -0
  47. package/dist/cjs/apps/identity/constants.js +58 -0
  48. package/dist/cjs/apps/identity/index.js +78 -0
  49. package/dist/cjs/apps/identity/state-machines/agent-identity.json +320 -0
  50. package/dist/cjs/apps/identity/types.js +53 -0
  51. package/dist/cjs/apps/index.js +58 -0
  52. package/dist/cjs/apps/markets/index.js +55 -0
  53. package/dist/cjs/apps/markets/state-machines/market-universal.json +354 -0
  54. package/dist/cjs/apps/markets/types.js +219 -0
  55. package/dist/cjs/apps/oracles/index.js +62 -0
  56. package/dist/cjs/apps/oracles/state-machines/oracle.json +452 -0
  57. package/dist/cjs/apps/oracles/types.js +282 -0
  58. package/dist/cjs/errors.js +293 -0
  59. package/dist/cjs/generated/google/protobuf/struct.js +514 -0
  60. package/dist/cjs/generated/google/protobuf/timestamp.js +92 -0
  61. package/dist/cjs/generated/index.js +150 -0
  62. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract.js +873 -0
  63. package/dist/cjs/generated/ottochain/apps/contracts/v1/contract_pb.js +100 -0
  64. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate.js +4515 -0
  65. package/dist/cjs/generated/ottochain/apps/corporate/v1/corporate_pb.js +392 -0
  66. package/dist/cjs/generated/ottochain/apps/governance/v1/governance.js +3255 -0
  67. package/dist/cjs/generated/ottochain/apps/governance/v1/governance_pb.js +235 -0
  68. package/dist/cjs/generated/ottochain/apps/identity/v1/agent.js +619 -0
  69. package/dist/cjs/generated/ottochain/apps/identity/v1/agent_pb.js +116 -0
  70. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation.js +780 -0
  71. package/dist/cjs/generated/ottochain/apps/identity/v1/attestation_pb.js +79 -0
  72. package/dist/cjs/generated/ottochain/apps/markets/v1/market.js +1261 -0
  73. package/dist/cjs/generated/ottochain/apps/markets/v1/market_pb.js +151 -0
  74. package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle.js +1223 -0
  75. package/dist/cjs/generated/ottochain/apps/oracles/v1/oracle_pb.js +109 -0
  76. package/dist/cjs/generated/ottochain/v1/common.js +10 -0
  77. package/dist/cjs/generated/ottochain/v1/common_pb.js +37 -0
  78. package/dist/cjs/generated/ottochain/v1/fiber.js +1057 -0
  79. package/dist/cjs/generated/ottochain/v1/fiber_pb.js +86 -0
  80. package/dist/cjs/generated/ottochain/v1/messages.js +740 -0
  81. package/dist/cjs/generated/ottochain/v1/messages_pb.js +44 -0
  82. package/dist/cjs/generated/ottochain/v1/records.js +1253 -0
  83. package/dist/cjs/generated/ottochain/v1/records_pb.js +44 -0
  84. package/dist/cjs/index.js +79 -0
  85. package/dist/cjs/metakit/binary.js +58 -0
  86. package/dist/cjs/metakit/canonicalize.js +40 -0
  87. package/dist/cjs/metakit/codec.js +45 -0
  88. package/dist/cjs/metakit/currency-transaction.js +319 -0
  89. package/dist/cjs/metakit/currency-types.js +13 -0
  90. package/dist/cjs/metakit/hash.js +84 -0
  91. package/dist/cjs/metakit/index.js +74 -0
  92. package/dist/cjs/metakit/network/client.js +78 -0
  93. package/dist/cjs/metakit/network/currency-l1-client.js +101 -0
  94. package/dist/cjs/metakit/network/data-l1-client.js +76 -0
  95. package/dist/cjs/metakit/network/index.js +16 -0
  96. package/dist/cjs/metakit/network/types.js +20 -0
  97. package/dist/cjs/metakit/sign.js +120 -0
  98. package/dist/cjs/metakit/signed-object.js +100 -0
  99. package/dist/cjs/metakit/types.js +14 -0
  100. package/dist/cjs/metakit/verify.js +217 -0
  101. package/dist/cjs/metakit/wallet.js +127 -0
  102. package/dist/cjs/ottochain/index.js +47 -0
  103. package/dist/cjs/ottochain/metagraph-client.js +157 -0
  104. package/dist/cjs/ottochain/snapshot.js +110 -0
  105. package/dist/cjs/ottochain/types.js +11 -0
  106. package/dist/cjs/package.json +1 -0
  107. package/dist/cjs/types.js +25 -0
  108. package/dist/cjs/validation.js +312 -0
  109. package/dist/errors.d.ts +221 -0
  110. package/dist/errors.js +293 -0
  111. package/dist/esm/apps/contracts/index.js +42 -0
  112. package/dist/esm/apps/contracts/state-machines/contract.json +420 -0
  113. package/dist/esm/apps/contracts/state-machines/escrow.json +426 -0
  114. package/dist/esm/apps/contracts/types.js +44 -0
  115. package/dist/esm/apps/corporate/index.js +57 -0
  116. package/dist/esm/apps/corporate/state-machines/corporate-board.json +1064 -0
  117. package/dist/esm/apps/corporate/state-machines/corporate-bylaws.json +751 -0
  118. package/dist/esm/apps/corporate/state-machines/corporate-committee.json +957 -0
  119. package/dist/esm/apps/corporate/state-machines/corporate-compliance.json +1293 -0
  120. package/dist/esm/apps/corporate/state-machines/corporate-entity.json +861 -0
  121. package/dist/esm/apps/corporate/state-machines/corporate-officers.json +843 -0
  122. package/dist/esm/apps/corporate/state-machines/corporate-proxy.json +783 -0
  123. package/dist/esm/apps/corporate/state-machines/corporate-resolution.json +1174 -0
  124. package/dist/esm/apps/corporate/state-machines/corporate-securities.json +1215 -0
  125. package/dist/esm/apps/corporate/state-machines/corporate-shareholders.json +1298 -0
  126. package/dist/esm/apps/corporate/types.js +38 -0
  127. package/dist/esm/apps/governance/index.js +154 -0
  128. package/dist/esm/apps/governance/state-machines/dao-multisig.json +711 -0
  129. package/dist/esm/apps/governance/state-machines/dao-single.json +258 -0
  130. package/dist/esm/apps/governance/state-machines/dao-threshold.json +660 -0
  131. package/dist/esm/apps/governance/state-machines/dao-token.json +680 -0
  132. package/dist/esm/apps/governance/state-machines/governance-constitution.json +401 -0
  133. package/dist/esm/apps/governance/state-machines/governance-executive.json +441 -0
  134. package/dist/esm/apps/governance/state-machines/governance-judiciary.json +626 -0
  135. package/dist/esm/apps/governance/state-machines/governance-legislature.json +726 -0
  136. package/dist/esm/apps/governance/state-machines/governance-simple.json +679 -0
  137. package/dist/esm/apps/governance/types.js +35 -0
  138. package/dist/esm/apps/identity/constants.js +53 -0
  139. package/dist/esm/apps/identity/index.js +50 -0
  140. package/dist/esm/apps/identity/state-machines/agent-identity.json +320 -0
  141. package/dist/esm/apps/identity/types.js +50 -0
  142. package/dist/esm/apps/index.js +32 -0
  143. package/dist/esm/apps/markets/index.js +34 -0
  144. package/dist/esm/apps/markets/state-machines/market-universal.json +354 -0
  145. package/dist/esm/apps/markets/types.js +206 -0
  146. package/dist/esm/apps/oracles/index.js +42 -0
  147. package/dist/esm/apps/oracles/state-machines/oracle.json +452 -0
  148. package/dist/esm/apps/oracles/types.js +267 -0
  149. package/dist/esm/errors.js +283 -0
  150. package/dist/esm/generated/google/protobuf/struct.js +508 -0
  151. package/dist/esm/generated/google/protobuf/timestamp.js +89 -0
  152. package/dist/esm/generated/index.js +26 -0
  153. package/dist/esm/generated/ottochain/apps/contracts/v1/contract.js +867 -0
  154. package/dist/esm/generated/ottochain/apps/contracts/v1/contract_pb.js +97 -0
  155. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate.js +4493 -0
  156. package/dist/esm/generated/ottochain/apps/corporate/v1/corporate_pb.js +389 -0
  157. package/dist/esm/generated/ottochain/apps/governance/v1/governance.js +3240 -0
  158. package/dist/esm/generated/ottochain/apps/governance/v1/governance_pb.js +232 -0
  159. package/dist/esm/generated/ottochain/apps/identity/v1/agent.js +610 -0
  160. package/dist/esm/generated/ottochain/apps/identity/v1/agent_pb.js +113 -0
  161. package/dist/esm/generated/ottochain/apps/identity/v1/attestation.js +774 -0
  162. package/dist/esm/generated/ottochain/apps/identity/v1/attestation_pb.js +76 -0
  163. package/dist/esm/generated/ottochain/apps/markets/v1/market.js +1252 -0
  164. package/dist/esm/generated/ottochain/apps/markets/v1/market_pb.js +148 -0
  165. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle.js +1217 -0
  166. package/dist/esm/generated/ottochain/apps/oracles/v1/oracle_pb.js +106 -0
  167. package/dist/esm/generated/ottochain/v1/common.js +7 -0
  168. package/dist/esm/generated/ottochain/v1/common_pb.js +34 -0
  169. package/dist/esm/generated/ottochain/v1/fiber.js +1051 -0
  170. package/dist/esm/generated/ottochain/v1/fiber_pb.js +83 -0
  171. package/dist/esm/generated/ottochain/v1/messages.js +737 -0
  172. package/dist/esm/generated/ottochain/v1/messages_pb.js +41 -0
  173. package/dist/esm/generated/ottochain/v1/records.js +1250 -0
  174. package/dist/esm/generated/ottochain/v1/records_pb.js +41 -0
  175. package/dist/esm/index.js +33 -0
  176. package/dist/esm/metakit/binary.js +53 -0
  177. package/dist/esm/metakit/canonicalize.js +33 -0
  178. package/dist/esm/metakit/codec.js +38 -0
  179. package/dist/esm/metakit/currency-transaction.js +306 -0
  180. package/dist/esm/metakit/currency-types.js +10 -0
  181. package/dist/esm/metakit/hash.js +77 -0
  182. package/dist/esm/metakit/index.js +30 -0
  183. package/dist/esm/metakit/network/client.js +74 -0
  184. package/dist/esm/metakit/network/currency-l1-client.js +97 -0
  185. package/dist/esm/metakit/network/data-l1-client.js +72 -0
  186. package/dist/esm/metakit/network/index.js +9 -0
  187. package/dist/esm/metakit/network/types.js +16 -0
  188. package/dist/esm/metakit/sign.js +114 -0
  189. package/dist/esm/metakit/signed-object.js +94 -0
  190. package/dist/esm/metakit/types.js +11 -0
  191. package/dist/esm/metakit/verify.js +210 -0
  192. package/dist/esm/metakit/wallet.js +117 -0
  193. package/dist/esm/ottochain/index.js +13 -0
  194. package/dist/esm/ottochain/metagraph-client.js +153 -0
  195. package/dist/esm/ottochain/snapshot.js +100 -0
  196. package/dist/esm/ottochain/types.js +10 -0
  197. package/dist/esm/package.json +1 -0
  198. package/dist/esm/types.js +20 -0
  199. package/dist/esm/validation.js +301 -0
  200. package/dist/generated/index.d.ts +15 -0
  201. package/dist/generated/index.js +34 -0
  202. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +274 -0
  203. package/dist/generated/ottochain/apps/contracts/v1/contract_pb.js +100 -0
  204. package/dist/generated/ottochain/apps/identity/v1/agent_pb.d.ts +211 -0
  205. package/dist/generated/ottochain/apps/identity/v1/agent_pb.js +116 -0
  206. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +238 -0
  207. package/dist/generated/ottochain/apps/identity/v1/attestation_pb.js +79 -0
  208. package/dist/generated/ottochain/apps/markets/v1/market_pb.d.ts +436 -0
  209. package/dist/generated/ottochain/apps/markets/v1/market_pb.js +151 -0
  210. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +393 -0
  211. package/dist/generated/ottochain/apps/oracles/v1/oracle_pb.js +109 -0
  212. package/dist/generated/ottochain/v1/common_pb.d.ts +86 -0
  213. package/dist/generated/ottochain/v1/common_pb.js +37 -0
  214. package/dist/generated/ottochain/v1/fiber_pb.d.ts +292 -0
  215. package/dist/generated/ottochain/v1/fiber_pb.js +86 -0
  216. package/dist/generated/ottochain/v1/messages_pb.d.ts +190 -0
  217. package/dist/generated/ottochain/v1/messages_pb.js +44 -0
  218. package/dist/generated/ottochain/v1/records_pb.d.ts +221 -0
  219. package/dist/generated/ottochain/v1/records_pb.js +44 -0
  220. package/dist/index.d.ts +21 -0
  221. package/dist/index.js +77 -0
  222. package/dist/metakit/binary.d.ts +38 -0
  223. package/dist/metakit/binary.js +58 -0
  224. package/dist/metakit/canonicalize.d.ts +26 -0
  225. package/dist/metakit/canonicalize.js +40 -0
  226. package/dist/metakit/codec.d.ts +16 -0
  227. package/dist/metakit/codec.js +45 -0
  228. package/dist/metakit/currency-transaction.d.ts +157 -0
  229. package/dist/metakit/currency-transaction.js +319 -0
  230. package/dist/metakit/currency-types.d.ts +55 -0
  231. package/dist/metakit/currency-types.js +13 -0
  232. package/dist/metakit/hash.d.ts +50 -0
  233. package/dist/metakit/hash.js +84 -0
  234. package/dist/metakit/index.d.ts +23 -0
  235. package/dist/metakit/index.js +74 -0
  236. package/dist/metakit/network/client.d.ts +23 -0
  237. package/dist/metakit/network/client.js +78 -0
  238. package/dist/metakit/network/currency-l1-client.d.ts +71 -0
  239. package/dist/metakit/network/currency-l1-client.js +101 -0
  240. package/dist/metakit/network/data-l1-client.d.ts +57 -0
  241. package/dist/metakit/network/data-l1-client.js +76 -0
  242. package/dist/metakit/network/index.d.ts +10 -0
  243. package/dist/metakit/network/index.js +16 -0
  244. package/dist/metakit/network/types.d.ts +74 -0
  245. package/dist/metakit/network/types.js +20 -0
  246. package/dist/metakit/sign.d.ts +65 -0
  247. package/dist/metakit/sign.js +120 -0
  248. package/dist/metakit/signed-object.d.ts +66 -0
  249. package/dist/metakit/signed-object.js +100 -0
  250. package/dist/metakit/types.d.ts +67 -0
  251. package/dist/metakit/types.js +14 -0
  252. package/dist/metakit/verify.d.ts +55 -0
  253. package/dist/metakit/verify.js +217 -0
  254. package/dist/metakit/wallet.d.ts +70 -0
  255. package/dist/metakit/wallet.js +127 -0
  256. package/dist/ottochain/index.d.ts +13 -0
  257. package/dist/ottochain/index.js +45 -0
  258. package/dist/ottochain/metagraph-client.d.ts +111 -0
  259. package/dist/ottochain/metagraph-client.js +157 -0
  260. package/dist/ottochain/snapshot.d.ts +86 -0
  261. package/dist/ottochain/snapshot.js +110 -0
  262. package/dist/ottochain/types.d.ts +278 -0
  263. package/dist/ottochain/types.js +11 -0
  264. package/dist/types/apps/contracts/index.d.ts +30 -0
  265. package/dist/types/apps/contracts/types.d.ts +24 -0
  266. package/dist/types/apps/corporate/index.d.ts +27 -0
  267. package/dist/types/apps/corporate/types.d.ts +9861 -0
  268. package/dist/types/apps/governance/index.d.ts +77 -0
  269. package/dist/types/apps/governance/types.d.ts +344 -0
  270. package/dist/types/apps/identity/constants.d.ts +27 -0
  271. package/dist/types/apps/identity/index.d.ts +39 -0
  272. package/dist/types/apps/identity/types.d.ts +30 -0
  273. package/dist/types/apps/index.d.ts +31 -0
  274. package/dist/types/apps/markets/index.d.ts +26 -0
  275. package/dist/types/apps/markets/types.d.ts +155 -0
  276. package/dist/types/apps/oracles/index.d.ts +34 -0
  277. package/dist/types/apps/oracles/types.d.ts +193 -0
  278. package/dist/types/errors.d.ts +221 -0
  279. package/dist/types/generated/google/protobuf/struct.d.ts +134 -0
  280. package/dist/types/generated/google/protobuf/timestamp.d.ts +134 -0
  281. package/dist/types/generated/index.d.ts +18 -0
  282. package/dist/types/generated/ottochain/apps/contracts/v1/contract.d.ts +112 -0
  283. package/dist/types/generated/ottochain/apps/contracts/v1/contract_pb.d.ts +274 -0
  284. package/dist/types/generated/ottochain/apps/corporate/v1/corporate.d.ts +376 -0
  285. package/dist/types/generated/ottochain/apps/corporate/v1/corporate_pb.d.ts +1172 -0
  286. package/dist/types/generated/ottochain/apps/governance/v1/governance.d.ts +296 -0
  287. package/dist/types/generated/ottochain/apps/governance/v1/governance_pb.d.ts +772 -0
  288. package/dist/types/generated/ottochain/apps/identity/v1/agent.d.ts +94 -0
  289. package/dist/types/generated/ottochain/apps/identity/v1/agent_pb.d.ts +211 -0
  290. package/dist/types/generated/ottochain/apps/identity/v1/attestation.d.ts +102 -0
  291. package/dist/types/generated/ottochain/apps/identity/v1/attestation_pb.d.ts +238 -0
  292. package/dist/types/generated/ottochain/apps/markets/v1/market.d.ts +174 -0
  293. package/dist/types/generated/ottochain/apps/markets/v1/market_pb.d.ts +436 -0
  294. package/dist/types/generated/ottochain/apps/oracles/v1/oracle.d.ts +150 -0
  295. package/dist/types/generated/ottochain/apps/oracles/v1/oracle_pb.d.ts +393 -0
  296. package/dist/types/generated/ottochain/v1/common.d.ts +1 -0
  297. package/dist/types/generated/ottochain/v1/common_pb.d.ts +86 -0
  298. package/dist/types/generated/ottochain/v1/fiber.d.ts +130 -0
  299. package/dist/types/generated/ottochain/v1/fiber_pb.d.ts +292 -0
  300. package/dist/types/generated/ottochain/v1/messages.d.ts +89 -0
  301. package/dist/types/generated/ottochain/v1/messages_pb.d.ts +190 -0
  302. package/dist/types/generated/ottochain/v1/records.d.ts +128 -0
  303. package/dist/types/generated/ottochain/v1/records_pb.d.ts +221 -0
  304. package/dist/types/index.d.ts +22 -0
  305. package/dist/types/metakit/binary.d.ts +38 -0
  306. package/dist/types/metakit/canonicalize.d.ts +26 -0
  307. package/dist/types/metakit/codec.d.ts +16 -0
  308. package/dist/types/metakit/currency-transaction.d.ts +157 -0
  309. package/dist/types/metakit/currency-types.d.ts +55 -0
  310. package/dist/types/metakit/hash.d.ts +50 -0
  311. package/dist/types/metakit/index.d.ts +23 -0
  312. package/dist/types/metakit/network/client.d.ts +23 -0
  313. package/dist/types/metakit/network/currency-l1-client.d.ts +71 -0
  314. package/dist/types/metakit/network/data-l1-client.d.ts +57 -0
  315. package/dist/types/metakit/network/index.d.ts +10 -0
  316. package/dist/types/metakit/network/types.d.ts +74 -0
  317. package/dist/types/metakit/sign.d.ts +65 -0
  318. package/dist/types/metakit/signed-object.d.ts +66 -0
  319. package/dist/types/metakit/types.d.ts +67 -0
  320. package/dist/types/metakit/verify.d.ts +55 -0
  321. package/dist/types/metakit/wallet.d.ts +70 -0
  322. package/dist/types/ottochain/index.d.ts +13 -0
  323. package/dist/types/ottochain/metagraph-client.d.ts +111 -0
  324. package/dist/types/ottochain/snapshot.d.ts +86 -0
  325. package/dist/types/ottochain/types.d.ts +210 -0
  326. package/dist/types/types.d.ts +51 -0
  327. package/dist/types/validation.d.ts +449 -0
  328. package/dist/validation.d.ts +449 -0
  329. package/dist/validation.js +312 -0
  330. package/package.json +136 -0
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ // @generated by protoc-gen-es v2.2.0 with parameter "target=ts,import_extension=.js"
3
+ // @generated from file ottochain/v1/records.proto (package ottochain.v1, syntax proto3)
4
+ /* eslint-disable */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CalculatedStateSchema = exports.FiberLogEntryListSchema = exports.OnChainStateSchema = exports.FiberCommitSchema = exports.ScriptFiberRecordSchema = exports.StateMachineFiberRecordSchema = exports.file_ottochain_v1_records = void 0;
7
+ const codegenv1_1 = require("@bufbuild/protobuf/codegenv1");
8
+ const common_pb_js_1 = require("./common_pb.js");
9
+ const fiber_pb_js_1 = require("./fiber_pb.js");
10
+ const wkt_1 = require("@bufbuild/protobuf/wkt");
11
+ /**
12
+ * Describes the file ottochain/v1/records.proto.
13
+ */
14
+ exports.file_ottochain_v1_records = (0, codegenv1_1.fileDesc)("ChpvdHRvY2hhaW4vdjEvcmVjb3Jkcy5wcm90bxIMb3R0b2NoYWluLnYxIsIFChdTdGF0ZU1hY2hpbmVGaWJlclJlY29yZBIQCghmaWJlcl9pZBgBIAEoCRI3ChBjcmVhdGlvbl9vcmRpbmFsGAIgASgLMh0ub3R0b2NoYWluLnYxLlNuYXBzaG90T3JkaW5hbBI+ChdwcmV2aW91c191cGRhdGVfb3JkaW5hbBgDIAEoCzIdLm90dG9jaGFpbi52MS5TbmFwc2hvdE9yZGluYWwSPAoVbGF0ZXN0X3VwZGF0ZV9vcmRpbmFsGAQgASgLMh0ub3R0b2NoYWluLnYxLlNuYXBzaG90T3JkaW5hbBI4CgpkZWZpbml0aW9uGAUgASgLMiQub3R0b2NoYWluLnYxLlN0YXRlTWFjaGluZURlZmluaXRpb24SLAoNY3VycmVudF9zdGF0ZRgGIAEoCzIVLm90dG9jaGFpbi52MS5TdGF0ZUlkEioKCnN0YXRlX2RhdGEYByABKAsyFi5nb29nbGUucHJvdG9idWYuVmFsdWUSMAoPc3RhdGVfZGF0YV9oYXNoGAggASgLMhcub3R0b2NoYWluLnYxLkhhc2hWYWx1ZRIzCg9zZXF1ZW5jZV9udW1iZXIYCSABKAsyGi5vdHRvY2hhaW4udjEuRmliZXJPcmRpbmFsEiUKBm93bmVycxgKIAMoCzIVLm90dG9jaGFpbi52MS5BZGRyZXNzEikKBnN0YXR1cxgLIAEoDjIZLm90dG9jaGFpbi52MS5GaWJlclN0YXR1cxI1CgxsYXN0X3JlY2VpcHQYDCABKAsyGi5vdHRvY2hhaW4udjEuRXZlbnRSZWNlaXB0SACIAQESHAoPcGFyZW50X2ZpYmVyX2lkGA0gASgJSAGIAQESFwoPY2hpbGRfZmliZXJfaWRzGA4gAygJQg8KDV9sYXN0X3JlY2VpcHRCEgoQX3BhcmVudF9maWJlcl9pZCLrBAoRU2NyaXB0RmliZXJSZWNvcmQSEAoIZmliZXJfaWQYASABKAkSNwoQY3JlYXRpb25fb3JkaW5hbBgCIAEoCzIdLm90dG9jaGFpbi52MS5TbmFwc2hvdE9yZGluYWwSPAoVbGF0ZXN0X3VwZGF0ZV9vcmRpbmFsGAMgASgLMh0ub3R0b2NoYWluLnYxLlNuYXBzaG90T3JkaW5hbBIuCg5zY3JpcHRfcHJvZ3JhbRgEIAEoCzIWLmdvb2dsZS5wcm90b2J1Zi5WYWx1ZRIvCgpzdGF0ZV9kYXRhGAUgASgLMhYuZ29vZ2xlLnByb3RvYnVmLlZhbHVlSACIAQESNQoPc3RhdGVfZGF0YV9oYXNoGAYgASgLMhcub3R0b2NoYWluLnYxLkhhc2hWYWx1ZUgBiAEBEjkKDmFjY2Vzc19jb250cm9sGAcgASgLMiEub3R0b2NoYWluLnYxLkFjY2Vzc0NvbnRyb2xQb2xpY3kSMwoPc2VxdWVuY2VfbnVtYmVyGAggASgLMhoub3R0b2NoYWluLnYxLkZpYmVyT3JkaW5hbBIlCgZvd25lcnMYCSADKAsyFS5vdHRvY2hhaW4udjEuQWRkcmVzcxIpCgZzdGF0dXMYCiABKA4yGS5vdHRvY2hhaW4udjEuRmliZXJTdGF0dXMSPAoPbGFzdF9pbnZvY2F0aW9uGAsgASgLMh4ub3R0b2NoYWluLnYxLlNjcmlwdEludm9jYXRpb25IAogBAUINCgtfc3RhdGVfZGF0YUISChBfc3RhdGVfZGF0YV9oYXNoQhIKEF9sYXN0X2ludm9jYXRpb24iuwEKC0ZpYmVyQ29tbWl0EiwKC3JlY29yZF9oYXNoGAEgASgLMhcub3R0b2NoYWluLnYxLkhhc2hWYWx1ZRI1Cg9zdGF0ZV9kYXRhX2hhc2gYAiABKAsyFy5vdHRvY2hhaW4udjEuSGFzaFZhbHVlSACIAQESMwoPc2VxdWVuY2VfbnVtYmVyGAMgASgLMhoub3R0b2NoYWluLnYxLkZpYmVyT3JkaW5hbEISChBfc3RhdGVfZGF0YV9oYXNoIrgCCgxPbkNoYWluU3RhdGUSQwoNZmliZXJfY29tbWl0cxgBIAMoCzIsLm90dG9jaGFpbi52MS5PbkNoYWluU3RhdGUuRmliZXJDb21taXRzRW50cnkSPwoLbGF0ZXN0X2xvZ3MYAiADKAsyKi5vdHRvY2hhaW4udjEuT25DaGFpblN0YXRlLkxhdGVzdExvZ3NFbnRyeRpOChFGaWJlckNvbW1pdHNFbnRyeRILCgNrZXkYASABKAkSKAoFdmFsdWUYAiABKAsyGS5vdHRvY2hhaW4udjEuRmliZXJDb21taXQ6AjgBGlIKD0xhdGVzdExvZ3NFbnRyeRILCgNrZXkYASABKAkSLgoFdmFsdWUYAiABKAsyHy5vdHRvY2hhaW4udjEuRmliZXJMb2dFbnRyeUxpc3Q6AjgBIkEKEUZpYmVyTG9nRW50cnlMaXN0EiwKB2VudHJpZXMYASADKAsyGy5vdHRvY2hhaW4udjEuRmliZXJMb2dFbnRyeSLGAgoPQ2FsY3VsYXRlZFN0YXRlEkgKDnN0YXRlX21hY2hpbmVzGAEgAygLMjAub3R0b2NoYWluLnYxLkNhbGN1bGF0ZWRTdGF0ZS5TdGF0ZU1hY2hpbmVzRW50cnkSOwoHc2NyaXB0cxgCIAMoCzIqLm90dG9jaGFpbi52MS5DYWxjdWxhdGVkU3RhdGUuU2NyaXB0c0VudHJ5GlsKElN0YXRlTWFjaGluZXNFbnRyeRILCgNrZXkYASABKAkSNAoFdmFsdWUYAiABKAsyJS5vdHRvY2hhaW4udjEuU3RhdGVNYWNoaW5lRmliZXJSZWNvcmQ6AjgBGk8KDFNjcmlwdHNFbnRyeRILCgNrZXkYASABKAkSLgoFdmFsdWUYAiABKAsyHy5vdHRvY2hhaW4udjEuU2NyaXB0RmliZXJSZWNvcmQ6AjgBQnEKEGNvbS5vdHRvY2hhaW4udjFCDFJlY29yZHNQcm90b1ABogIDT1hYqgIMT3R0b2NoYWluLlYxygIMT3R0b2NoYWluXFYx4gIYT3R0b2NoYWluXFYxXEdQQk1ldGFkYXRh6gINT3R0b2NoYWluOjpWMWIGcHJvdG8z", [common_pb_js_1.file_ottochain_v1_common, fiber_pb_js_1.file_ottochain_v1_fiber, wkt_1.file_google_protobuf_struct]);
15
+ /**
16
+ * Describes the message ottochain.v1.StateMachineFiberRecord.
17
+ * Use `create(StateMachineFiberRecordSchema)` to create a new message.
18
+ */
19
+ exports.StateMachineFiberRecordSchema = (0, codegenv1_1.messageDesc)(exports.file_ottochain_v1_records, 0);
20
+ /**
21
+ * Describes the message ottochain.v1.ScriptFiberRecord.
22
+ * Use `create(ScriptFiberRecordSchema)` to create a new message.
23
+ */
24
+ exports.ScriptFiberRecordSchema = (0, codegenv1_1.messageDesc)(exports.file_ottochain_v1_records, 1);
25
+ /**
26
+ * Describes the message ottochain.v1.FiberCommit.
27
+ * Use `create(FiberCommitSchema)` to create a new message.
28
+ */
29
+ exports.FiberCommitSchema = (0, codegenv1_1.messageDesc)(exports.file_ottochain_v1_records, 2);
30
+ /**
31
+ * Describes the message ottochain.v1.OnChainState.
32
+ * Use `create(OnChainStateSchema)` to create a new message.
33
+ */
34
+ exports.OnChainStateSchema = (0, codegenv1_1.messageDesc)(exports.file_ottochain_v1_records, 3);
35
+ /**
36
+ * Describes the message ottochain.v1.FiberLogEntryList.
37
+ * Use `create(FiberLogEntryListSchema)` to create a new message.
38
+ */
39
+ exports.FiberLogEntryListSchema = (0, codegenv1_1.messageDesc)(exports.file_ottochain_v1_records, 4);
40
+ /**
41
+ * Describes the message ottochain.v1.CalculatedState.
42
+ * Use `create(CalculatedStateSchema)` to create a new message.
43
+ */
44
+ exports.CalculatedStateSchema = (0, codegenv1_1.messageDesc)(exports.file_ottochain_v1_records, 5);
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * Ottochain SDK
4
+ *
5
+ * Unified SDK combining metakit framework operations with ottochain domain types.
6
+ *
7
+ * Structure:
8
+ * - `metakit` — Signing, encoding, hashing, and network clients for Constellation metagraphs
9
+ * - `generated` — Protobuf-generated types (source of truth)
10
+ * - `apps/identity` — Agent Identity application types
11
+ * - `apps/contracts` — Contract application types
12
+ * - `errors` — Custom error classes for structured error handling
13
+ * - `validation` — Input validation with Zod schemas
14
+ *
15
+ * @packageDocumentation
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ 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 = exports.wrapError = exports.isErrorCode = exports.ErrorCode = exports.TransactionError = exports.SigningError = exports.ValidationError = exports.NetworkError = exports.OttoChainError = void 0;
33
+ // Type aliases for semantic clarity (matches wire format)
34
+ __exportStar(require("./types.js"), exports);
35
+ // Metakit utilities (signing, hashing, HTTP client)
36
+ __exportStar(require("./metakit/index.js"), exports);
37
+ // Generated protobuf types (canonical definitions)
38
+ __exportStar(require("./generated/index.js"), exports);
39
+ // Custom error classes
40
+ var errors_js_1 = require("./errors.js");
41
+ Object.defineProperty(exports, "OttoChainError", { enumerable: true, get: function () { return errors_js_1.OttoChainError; } });
42
+ Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return errors_js_1.NetworkError; } });
43
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_js_1.ValidationError; } });
44
+ Object.defineProperty(exports, "SigningError", { enumerable: true, get: function () { return errors_js_1.SigningError; } });
45
+ Object.defineProperty(exports, "TransactionError", { enumerable: true, get: function () { return errors_js_1.TransactionError; } });
46
+ Object.defineProperty(exports, "ErrorCode", { enumerable: true, get: function () { return errors_js_1.ErrorCode; } });
47
+ Object.defineProperty(exports, "isErrorCode", { enumerable: true, get: function () { return errors_js_1.isErrorCode; } });
48
+ Object.defineProperty(exports, "wrapError", { enumerable: true, get: function () { return errors_js_1.wrapError; } });
49
+ // Validation schemas and helpers
50
+ var validation_js_1 = require("./validation.js");
51
+ // Schemas
52
+ Object.defineProperty(exports, "DagAddressSchema", { enumerable: true, get: function () { return validation_js_1.DagAddressSchema; } });
53
+ Object.defineProperty(exports, "PrivateKeySchema", { enumerable: true, get: function () { return validation_js_1.PrivateKeySchema; } });
54
+ Object.defineProperty(exports, "PublicKeySchema", { enumerable: true, get: function () { return validation_js_1.PublicKeySchema; } });
55
+ Object.defineProperty(exports, "KeyPairSchema", { enumerable: true, get: function () { return validation_js_1.KeyPairSchema; } });
56
+ Object.defineProperty(exports, "SignatureProofSchema", { enumerable: true, get: function () { return validation_js_1.SignatureProofSchema; } });
57
+ Object.defineProperty(exports, "SignedSchema", { enumerable: true, get: function () { return validation_js_1.SignedSchema; } });
58
+ Object.defineProperty(exports, "TransactionReferenceSchema", { enumerable: true, get: function () { return validation_js_1.TransactionReferenceSchema; } });
59
+ Object.defineProperty(exports, "CurrencyTransactionValueSchema", { enumerable: true, get: function () { return validation_js_1.CurrencyTransactionValueSchema; } });
60
+ Object.defineProperty(exports, "CurrencyTransactionSchema", { enumerable: true, get: function () { return validation_js_1.CurrencyTransactionSchema; } });
61
+ Object.defineProperty(exports, "TransferParamsSchema", { enumerable: true, get: function () { return validation_js_1.TransferParamsSchema; } });
62
+ Object.defineProperty(exports, "AgentIdentityRegistrationSchema", { enumerable: true, get: function () { return validation_js_1.AgentIdentityRegistrationSchema; } });
63
+ Object.defineProperty(exports, "PlatformLinkSchema", { enumerable: true, get: function () { return validation_js_1.PlatformLinkSchema; } });
64
+ Object.defineProperty(exports, "ContractTermsSchema", { enumerable: true, get: function () { return validation_js_1.ContractTermsSchema; } });
65
+ Object.defineProperty(exports, "ProposeContractRequestSchema", { enumerable: true, get: function () { return validation_js_1.ProposeContractRequestSchema; } });
66
+ Object.defineProperty(exports, "AcceptContractRequestSchema", { enumerable: true, get: function () { return validation_js_1.AcceptContractRequestSchema; } });
67
+ Object.defineProperty(exports, "CompleteContractRequestSchema", { enumerable: true, get: function () { return validation_js_1.CompleteContractRequestSchema; } });
68
+ // Helpers
69
+ Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validation_js_1.validate; } });
70
+ Object.defineProperty(exports, "validatePrivateKey", { enumerable: true, get: function () { return validation_js_1.validatePrivateKey; } });
71
+ Object.defineProperty(exports, "validatePublicKey", { enumerable: true, get: function () { return validation_js_1.validatePublicKey; } });
72
+ Object.defineProperty(exports, "validateAddress", { enumerable: true, get: function () { return validation_js_1.validateAddress; } });
73
+ Object.defineProperty(exports, "validateKeyPair", { enumerable: true, get: function () { return validation_js_1.validateKeyPair; } });
74
+ Object.defineProperty(exports, "safeParse", { enumerable: true, get: function () { return validation_js_1.safeParse; } });
75
+ Object.defineProperty(exports, "assert", { enumerable: true, get: function () { return validation_js_1.assert; } });
76
+ // Error classes
77
+ __exportStar(require("./errors.js"), exports);
78
+ // Validation schemas and helpers
79
+ __exportStar(require("./validation.js"), exports);
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ /**
3
+ * Binary Encoding
4
+ *
5
+ * Converts JSON data to binary format for cryptographic operations.
6
+ * Supports both regular encoding and DataUpdate encoding with Constellation prefix.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.encodeDataUpdate = exports.toBytes = void 0;
10
+ const canonicalize_js_1 = require("./canonicalize.js");
11
+ const types_js_1 = require("./types.js");
12
+ /**
13
+ * Convert data to binary bytes for signing
14
+ *
15
+ * For regular data:
16
+ * JSON -> RFC 8785 canonicalization -> UTF-8 bytes
17
+ *
18
+ * For DataUpdate (isDataUpdate=true):
19
+ * JSON -> RFC 8785 -> UTF-8 -> Base64 -> prepend Constellation prefix -> UTF-8 bytes
20
+ *
21
+ * @param data - Any JSON-serializable object
22
+ * @param isDataUpdate - If true, applies DataUpdate encoding with Constellation prefix
23
+ * @returns Binary bytes as Uint8Array
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * // Regular encoding
28
+ * const bytes = toBytes({ action: 'test' });
29
+ *
30
+ * // DataUpdate encoding
31
+ * const updateBytes = toBytes({ action: 'test' }, true);
32
+ * ```
33
+ */
34
+ function toBytes(data, isDataUpdate = false) {
35
+ const canonicalJson = (0, canonicalize_js_1.canonicalize)(data);
36
+ const utf8Bytes = new TextEncoder().encode(canonicalJson);
37
+ if (isDataUpdate) {
38
+ // Base64 encode the UTF-8 bytes
39
+ const base64String = Buffer.from(utf8Bytes).toString('base64');
40
+ // Create the wrapped string with Constellation prefix
41
+ const wrappedString = `${types_js_1.CONSTELLATION_PREFIX}${base64String.length}\n${base64String}`;
42
+ return new TextEncoder().encode(wrappedString);
43
+ }
44
+ return utf8Bytes;
45
+ }
46
+ exports.toBytes = toBytes;
47
+ /**
48
+ * Encode data as a DataUpdate with Constellation prefix
49
+ *
50
+ * This is equivalent to `toBytes(data, true)`.
51
+ *
52
+ * @param data - Any JSON-serializable object
53
+ * @returns Binary bytes with Constellation prefix
54
+ */
55
+ function encodeDataUpdate(data) {
56
+ return toBytes(data, true);
57
+ }
58
+ exports.encodeDataUpdate = encodeDataUpdate;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * RFC 8785 JSON Canonicalization
4
+ *
5
+ * Provides deterministic JSON serialization according to RFC 8785.
6
+ * This ensures identical JSON objects always produce identical strings.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.canonicalize = void 0;
13
+ const canonicalize_1 = __importDefault(require("canonicalize"));
14
+ /**
15
+ * Canonicalize JSON data according to RFC 8785
16
+ *
17
+ * Key features:
18
+ * - Object keys sorted by UTF-16BE binary comparison
19
+ * - Numbers serialized in shortest decimal representation
20
+ * - No whitespace
21
+ * - Proper Unicode escaping
22
+ *
23
+ * @param data - Any JSON-serializable object
24
+ * @returns Canonical JSON string
25
+ * @throws Error if data cannot be serialized to JSON
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const canonical = canonicalize({ b: 2, a: 1 });
30
+ * // Returns: '{"a":1,"b":2}'
31
+ * ```
32
+ */
33
+ function canonicalize(data) {
34
+ const result = (0, canonicalize_1.default)(data);
35
+ if (result === undefined) {
36
+ throw new Error('Failed to canonicalize data: data cannot be serialized to JSON');
37
+ }
38
+ return result;
39
+ }
40
+ exports.canonicalize = canonicalize;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * Codec Utilities
4
+ *
5
+ * Encoding/decoding utilities for the Constellation signature protocol.
6
+ * Re-exports from binary.ts for backwards compatibility and provides additional utilities.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.decodeDataUpdate = exports.CONSTELLATION_PREFIX = exports.encodeDataUpdate = exports.toBytes = void 0;
10
+ var binary_js_1 = require("./binary.js");
11
+ Object.defineProperty(exports, "toBytes", { enumerable: true, get: function () { return binary_js_1.toBytes; } });
12
+ Object.defineProperty(exports, "encodeDataUpdate", { enumerable: true, get: function () { return binary_js_1.encodeDataUpdate; } });
13
+ var types_js_1 = require("./types.js");
14
+ Object.defineProperty(exports, "CONSTELLATION_PREFIX", { enumerable: true, get: function () { return types_js_1.CONSTELLATION_PREFIX; } });
15
+ /**
16
+ * Decode a DataUpdate encoded message back to its original JSON
17
+ *
18
+ * @param bytes - DataUpdate encoded bytes
19
+ * @returns Decoded JSON object
20
+ * @throws Error if bytes are not valid DataUpdate encoding
21
+ */
22
+ function decodeDataUpdate(bytes) {
23
+ const text = new TextDecoder().decode(bytes);
24
+ // Validate prefix
25
+ if (!text.startsWith('\x19Constellation Signed Data:\n')) {
26
+ throw new Error('Invalid DataUpdate encoding: missing Constellation prefix');
27
+ }
28
+ // Parse the format: \x19Constellation Signed Data:\n{length}\n{base64}
29
+ const withoutPrefix = text.slice('\x19Constellation Signed Data:\n'.length);
30
+ const newlineIndex = withoutPrefix.indexOf('\n');
31
+ if (newlineIndex === -1) {
32
+ throw new Error('Invalid DataUpdate encoding: missing length delimiter');
33
+ }
34
+ const lengthStr = withoutPrefix.slice(0, newlineIndex);
35
+ const base64Data = withoutPrefix.slice(newlineIndex + 1);
36
+ const expectedLength = parseInt(lengthStr, 10);
37
+ if (isNaN(expectedLength) || base64Data.length !== expectedLength) {
38
+ throw new Error('Invalid DataUpdate encoding: length mismatch');
39
+ }
40
+ // Decode base64 to UTF-8 JSON
41
+ const jsonBytes = Buffer.from(base64Data, 'base64');
42
+ const jsonString = new TextDecoder().decode(jsonBytes);
43
+ return JSON.parse(jsonString);
44
+ }
45
+ exports.decodeDataUpdate = decodeDataUpdate;
@@ -0,0 +1,319 @@
1
+ "use strict";
2
+ /**
3
+ * Currency transaction operations for metagraph token transfers
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.getTransactionReference = exports.hashCurrencyTransaction = exports.encodeCurrencyTransaction = exports.verifyCurrencyTransaction = exports.signCurrencyTransaction = exports.createCurrencyTransactionBatch = exports.createCurrencyTransaction = exports.isValidDagAddress = exports.unitsToToken = exports.tokenToUnits = void 0;
9
+ const dag4_keystore_1 = require("@stardust-collective/dag4-keystore");
10
+ const currency_types_js_1 = require("./currency-types.js");
11
+ const wallet_js_1 = require("./wallet.js");
12
+ const verify_js_1 = require("./verify.js");
13
+ /**
14
+ * Convert token amount to smallest units
15
+ *
16
+ * @param amount - Amount in token units (e.g., 100.5)
17
+ * @returns Amount in smallest units (1e-8)
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const units = tokenToUnits(100.5); // 10050000000
22
+ * ```
23
+ */
24
+ function tokenToUnits(amount) {
25
+ return Math.floor(amount * 1e8);
26
+ }
27
+ exports.tokenToUnits = tokenToUnits;
28
+ /**
29
+ * Convert smallest units to token amount
30
+ *
31
+ * @param units - Amount in smallest units
32
+ * @returns Amount in token units
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const tokens = unitsToToken(10050000000); // 100.5
37
+ * ```
38
+ */
39
+ function unitsToToken(units) {
40
+ return units * currency_types_js_1.TOKEN_DECIMALS;
41
+ }
42
+ exports.unitsToToken = unitsToToken;
43
+ /**
44
+ * Validate DAG address format
45
+ *
46
+ * @param address - DAG address to validate
47
+ * @returns True if address is valid
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * const valid = isValidDagAddress('DAG...');
52
+ * ```
53
+ */
54
+ function isValidDagAddress(address) {
55
+ return dag4_keystore_1.keyStore.validateDagAddress(address);
56
+ }
57
+ exports.isValidDagAddress = isValidDagAddress;
58
+ /**
59
+ * Create a metagraph token transaction
60
+ *
61
+ * @param params - Transfer parameters
62
+ * @param privateKey - Private key to sign with (hex string)
63
+ * @param lastRef - Reference to last accepted transaction
64
+ * @returns Signed currency transaction
65
+ *
66
+ * @throws If addresses are invalid or amount is too small
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const tx = await createCurrencyTransaction(
71
+ * { destination: 'DAG...', amount: 100.5, fee: 0 },
72
+ * privateKey,
73
+ * { hash: 'abc123...', ordinal: 5 }
74
+ * );
75
+ * ```
76
+ */
77
+ async function createCurrencyTransaction(params, privateKey, lastRef) {
78
+ // Get source address from private key
79
+ const publicKey = dag4_keystore_1.keyStore.getPublicKeyFromPrivate(privateKey);
80
+ const source = (0, wallet_js_1.getAddress)(publicKey);
81
+ // Validate addresses
82
+ if (!isValidDagAddress(source)) {
83
+ throw new Error('Invalid source address');
84
+ }
85
+ if (!isValidDagAddress(params.destination)) {
86
+ throw new Error('Invalid destination address');
87
+ }
88
+ if (source === params.destination) {
89
+ throw new Error('Source and destination addresses cannot be the same');
90
+ }
91
+ // Convert amounts to smallest units
92
+ const amount = tokenToUnits(params.amount);
93
+ const fee = tokenToUnits(params.fee ?? 0);
94
+ // Validate amounts
95
+ if (amount < 1) {
96
+ throw new Error('Transfer amount must be greater than 1e-8');
97
+ }
98
+ if (fee < 0) {
99
+ throw new Error('Fee must be greater than or equal to zero');
100
+ }
101
+ // Use dag4.js TransactionV2 to create and encode the transaction
102
+ const txProps = {
103
+ fromAddress: source,
104
+ toAddress: params.destination,
105
+ amount,
106
+ fee,
107
+ lastTxRef: lastRef,
108
+ };
109
+ const tx = new dag4_keystore_1.TransactionV2(txProps);
110
+ // Get encoded transaction for hashing
111
+ const encodedTx = tx.getEncoded();
112
+ // Kryo serialize - v2 uses setReferences = false (matching dag4.js behavior)
113
+ const serializedTx = dag4_keystore_1.txEncode.kryoSerialize(encodedTx, false);
114
+ // Hash the serialized transaction
115
+ const hash = dag4_keystore_1.keyStore.sha256(Buffer.from(serializedTx, 'hex'));
116
+ // Sign the hash
117
+ const signature = await dag4_keystore_1.keyStore.sign(privateKey, hash);
118
+ // Get uncompressed public key
119
+ const uncompressedPublicKey = publicKey.length === 128 ? '04' + publicKey : publicKey;
120
+ // Verify signature
121
+ const success = dag4_keystore_1.keyStore.verify(uncompressedPublicKey, hash, signature);
122
+ if (!success) {
123
+ throw new Error('Sign-Verify failed');
124
+ }
125
+ // Add signature proof (remove '04' prefix from public key)
126
+ const proof = {
127
+ id: uncompressedPublicKey.substring(2),
128
+ signature,
129
+ };
130
+ tx.addSignature(proof);
131
+ return tx.getPostTransaction();
132
+ }
133
+ exports.createCurrencyTransaction = createCurrencyTransaction;
134
+ /**
135
+ * Create multiple metagraph token transactions (batch)
136
+ *
137
+ * @param transfers - Array of transfer parameters
138
+ * @param privateKey - Private key to sign with
139
+ * @param lastRef - Reference to last accepted transaction
140
+ * @returns Array of signed currency transactions
141
+ *
142
+ * @throws If any address is invalid or amount is too small
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const txns = await createCurrencyTransactionBatch(
147
+ * [
148
+ * { destination: 'DAG...1', amount: 10 },
149
+ * { destination: 'DAG...2', amount: 20 },
150
+ * ],
151
+ * privateKey,
152
+ * { hash: 'abc123...', ordinal: 5 }
153
+ * );
154
+ * ```
155
+ */
156
+ async function createCurrencyTransactionBatch(transfers, privateKey, lastRef) {
157
+ const transactions = [];
158
+ let currentRef = { ...lastRef };
159
+ for (const transfer of transfers) {
160
+ const tx = await createCurrencyTransaction(transfer, privateKey, currentRef);
161
+ // Calculate hash for next transaction's parent reference
162
+ const hash = await hashCurrencyTransaction(tx);
163
+ // Update reference for next transaction
164
+ currentRef = {
165
+ hash: hash.value,
166
+ ordinal: currentRef.ordinal + 1,
167
+ };
168
+ transactions.push(tx);
169
+ }
170
+ return transactions;
171
+ }
172
+ exports.createCurrencyTransactionBatch = createCurrencyTransactionBatch;
173
+ /**
174
+ * Add a signature to an existing currency transaction (for multi-sig)
175
+ *
176
+ * @param transaction - Transaction to sign
177
+ * @param privateKey - Private key to sign with
178
+ * @returns Transaction with additional signature
179
+ *
180
+ * @throws If sign-verify fails
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const signedTx = await signCurrencyTransaction(tx, privateKey2);
185
+ * ```
186
+ */
187
+ async function signCurrencyTransaction(transaction, privateKey) {
188
+ // Reconstruct TransactionV2 from PostTransaction
189
+ const tx = dag4_keystore_1.TransactionV2.fromPostTransaction(transaction);
190
+ // Restore existing proofs (fromPostTransaction doesn't copy them)
191
+ for (const existingProof of transaction.proofs) {
192
+ tx.addSignature(existingProof);
193
+ }
194
+ // Get encoded transaction
195
+ const encodedTx = tx.getEncoded();
196
+ // Kryo serialize - v2 uses setReferences = false (matching dag4.js behavior)
197
+ const serializedTx = dag4_keystore_1.txEncode.kryoSerialize(encodedTx, false);
198
+ const hash = dag4_keystore_1.keyStore.sha256(Buffer.from(serializedTx, 'hex'));
199
+ // Sign the hash
200
+ const publicKey = dag4_keystore_1.keyStore.getPublicKeyFromPrivate(privateKey);
201
+ const signature = await dag4_keystore_1.keyStore.sign(privateKey, hash);
202
+ // Verify signature
203
+ const uncompressedPublicKey = publicKey.length === 128 ? '04' + publicKey : publicKey;
204
+ const success = dag4_keystore_1.keyStore.verify(uncompressedPublicKey, hash, signature);
205
+ if (!success) {
206
+ throw new Error('Sign-Verify failed');
207
+ }
208
+ // Add new proof
209
+ const proof = {
210
+ id: uncompressedPublicKey.substring(2),
211
+ signature,
212
+ };
213
+ tx.addSignature(proof);
214
+ return tx.getPostTransaction();
215
+ }
216
+ exports.signCurrencyTransaction = signCurrencyTransaction;
217
+ /**
218
+ * Verify all signatures on a currency transaction
219
+ *
220
+ * @param transaction - Transaction to verify
221
+ * @returns Verification result with valid/invalid proofs
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const result = await verifyCurrencyTransaction(tx);
226
+ * console.log('Valid:', result.isValid);
227
+ * ```
228
+ */
229
+ async function verifyCurrencyTransaction(transaction) {
230
+ // Reconstruct TransactionV2 to get encoded form
231
+ const tx = dag4_keystore_1.TransactionV2.fromPostTransaction(transaction);
232
+ // Get hash
233
+ const encodedTx = tx.getEncoded();
234
+ // Kryo serialize - v2 uses setReferences = false (matching dag4.js behavior)
235
+ const serializedTx = dag4_keystore_1.txEncode.kryoSerialize(encodedTx, false);
236
+ const hash = dag4_keystore_1.keyStore.sha256(Buffer.from(serializedTx, 'hex'));
237
+ const validProofs = [];
238
+ const invalidProofs = [];
239
+ // Verify each proof
240
+ for (const proof of transaction.proofs) {
241
+ const publicKey = '04' + proof.id; // Add back the '04' prefix
242
+ // Normalize signature to low-S form for BIP 62/146 compatibility
243
+ const normalizedSignature = (0, verify_js_1.normalizeSignatureToLowS)(proof.signature);
244
+ const isValid = dag4_keystore_1.keyStore.verify(publicKey, hash, normalizedSignature);
245
+ if (isValid) {
246
+ validProofs.push(proof);
247
+ }
248
+ else {
249
+ invalidProofs.push(proof);
250
+ }
251
+ }
252
+ return {
253
+ isValid: invalidProofs.length === 0 && validProofs.length > 0,
254
+ validProofs,
255
+ invalidProofs,
256
+ };
257
+ }
258
+ exports.verifyCurrencyTransaction = verifyCurrencyTransaction;
259
+ /**
260
+ * Encode a currency transaction for hashing
261
+ *
262
+ * @param transaction - Transaction to encode
263
+ * @returns Hex-encoded string
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * const encoded = encodeCurrencyTransaction(tx);
268
+ * ```
269
+ */
270
+ function encodeCurrencyTransaction(transaction) {
271
+ const tx = dag4_keystore_1.TransactionV2.fromPostTransaction(transaction);
272
+ return tx.getEncoded();
273
+ }
274
+ exports.encodeCurrencyTransaction = encodeCurrencyTransaction;
275
+ /**
276
+ * Hash a currency transaction
277
+ *
278
+ * @param transaction - Transaction to hash
279
+ * @returns Hash object with value and bytes
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const hash = await hashCurrencyTransaction(tx);
284
+ * console.log('Hash:', hash.value);
285
+ * ```
286
+ */
287
+ async function hashCurrencyTransaction(transaction) {
288
+ const encoded = encodeCurrencyTransaction(transaction);
289
+ // Kryo serialize - v2 uses setReferences = false (matching dag4.js behavior)
290
+ const serialized = dag4_keystore_1.txEncode.kryoSerialize(encoded, false);
291
+ const hash = dag4_keystore_1.keyStore.sha256(Buffer.from(serialized, 'hex'));
292
+ return {
293
+ value: hash,
294
+ bytes: Buffer.from(hash, 'hex'),
295
+ };
296
+ }
297
+ exports.hashCurrencyTransaction = hashCurrencyTransaction;
298
+ /**
299
+ * Get transaction reference from a currency transaction
300
+ * Useful for chaining transactions
301
+ *
302
+ * @param transaction - Transaction to extract reference from
303
+ * @param ordinal - Ordinal number for this transaction
304
+ * @returns Transaction reference
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const ref = await getTransactionReference(tx, 6);
309
+ * // Use ref as lastRef for next transaction
310
+ * ```
311
+ */
312
+ async function getTransactionReference(transaction, ordinal) {
313
+ const hash = await hashCurrencyTransaction(transaction);
314
+ return {
315
+ hash: hash.value,
316
+ ordinal,
317
+ };
318
+ }
319
+ exports.getTransactionReference = getTransactionReference;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Currency transaction types for metagraph token transfers
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.TOKEN_DECIMALS = void 0;
9
+ /**
10
+ * Token decimals constant (1e-8)
11
+ * Same as DAG_DECIMALS from dag4.js
12
+ */
13
+ exports.TOKEN_DECIMALS = 1e-8;