@opcat-labs/cat-sdk 1.0.1

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 (369) hide show
  1. package/README.md +19 -0
  2. package/artifacts/.templates/cat20/cat20.scrypt.map +1 -0
  3. package/artifacts/.templates/cat20/cat20.scrypt.tpl +60 -0
  4. package/artifacts/.templates/cat20/cat20.transformer.json +9 -0
  5. package/artifacts/.templates/cat20/cat20Guard.scrypt.map +1 -0
  6. package/artifacts/.templates/cat20/cat20Guard.scrypt.tpl +117 -0
  7. package/artifacts/.templates/cat20/cat20Guard.transformer.json +9 -0
  8. package/artifacts/.templates/cat20/cat20GuardStateLib.scrypt.map +1 -0
  9. package/artifacts/.templates/cat20/cat20GuardStateLib.scrypt.tpl +36 -0
  10. package/artifacts/.templates/cat20/cat20GuardStateLib.transformer.json +7 -0
  11. package/artifacts/.templates/cat20/cat20StateLib.scrypt.map +1 -0
  12. package/artifacts/.templates/cat20/cat20StateLib.scrypt.tpl +21 -0
  13. package/artifacts/.templates/cat20/cat20StateLib.transformer.json +7 -0
  14. package/artifacts/.templates/cat20/minters/cat20ClosedMinter.scrypt.map +1 -0
  15. package/artifacts/.templates/cat20/minters/cat20ClosedMinter.scrypt.tpl +61 -0
  16. package/artifacts/.templates/cat20/minters/cat20ClosedMinter.transformer.json +9 -0
  17. package/artifacts/.templates/cat20/minters/cat20ClosedMinterMetadata.scrypt.map +1 -0
  18. package/artifacts/.templates/cat20/minters/cat20ClosedMinterMetadata.scrypt.tpl +11 -0
  19. package/artifacts/.templates/cat20/minters/cat20ClosedMinterMetadata.transformer.json +7 -0
  20. package/artifacts/.templates/cat20/minters/cat20OpenMinter.scrypt.map +1 -0
  21. package/artifacts/.templates/cat20/minters/cat20OpenMinter.scrypt.tpl +94 -0
  22. package/artifacts/.templates/cat20/minters/cat20OpenMinter.transformer.json +9 -0
  23. package/artifacts/.templates/cat20/minters/cat20OpenMinterMetadata.scrypt.map +1 -0
  24. package/artifacts/.templates/cat20/minters/cat20OpenMinterMetadata.scrypt.tpl +11 -0
  25. package/artifacts/.templates/cat20/minters/cat20OpenMinterMetadata.transformer.json +7 -0
  26. package/artifacts/.templates/cat20/types.scrypt.map +1 -0
  27. package/artifacts/.templates/cat20/types.scrypt.tpl +45 -0
  28. package/artifacts/.templates/cat20/types.transformer.json +7 -0
  29. package/artifacts/.templates/cat20Incinerator.scrypt.map +1 -0
  30. package/artifacts/.templates/cat20Incinerator.scrypt.tpl +31 -0
  31. package/artifacts/.templates/cat20Incinerator.transformer.json +9 -0
  32. package/artifacts/.templates/constants.scrypt.map +1 -0
  33. package/artifacts/.templates/constants.scrypt.tpl +16 -0
  34. package/artifacts/.templates/constants.transformer.json +7 -0
  35. package/artifacts/.templates/counter.scrypt.map +1 -0
  36. package/artifacts/.templates/counter.scrypt.tpl +36 -0
  37. package/artifacts/.templates/counter.transformer.json +9 -0
  38. package/artifacts/.templates/p2pkh.scrypt.map +1 -0
  39. package/artifacts/.templates/p2pkh.scrypt.tpl +11 -0
  40. package/artifacts/.templates/p2pkh.transformer.json +7 -0
  41. package/artifacts/.templates/types.scrypt.map +1 -0
  42. package/artifacts/.templates/types.scrypt.tpl +6 -0
  43. package/artifacts/.templates/types.transformer.json +7 -0
  44. package/artifacts/.templates/utils/ownerUtils.scrypt.map +1 -0
  45. package/artifacts/.templates/utils/ownerUtils.scrypt.tpl +26 -0
  46. package/artifacts/.templates/utils/ownerUtils.transformer.json +7 -0
  47. package/artifacts/.templates/utils/safeMath.scrypt.map +1 -0
  48. package/artifacts/.templates/utils/safeMath.scrypt.tpl +11 -0
  49. package/artifacts/.templates/utils/safeMath.transformer.json +7 -0
  50. package/artifacts/cat20/cat20.json +477 -0
  51. package/artifacts/cat20/cat20.scrypt +62 -0
  52. package/artifacts/cat20/cat20Guard.json +447 -0
  53. package/artifacts/cat20/cat20Guard.scrypt +119 -0
  54. package/artifacts/cat20/cat20GuardStateLib.json +361 -0
  55. package/artifacts/cat20/cat20GuardStateLib.scrypt +38 -0
  56. package/artifacts/cat20/cat20StateLib.json +373 -0
  57. package/artifacts/cat20/cat20StateLib.scrypt +23 -0
  58. package/artifacts/cat20/minters/cat20ClosedMinter.json +477 -0
  59. package/artifacts/cat20/minters/cat20ClosedMinter.scrypt +63 -0
  60. package/artifacts/cat20/minters/cat20ClosedMinterMetadata.json +173 -0
  61. package/artifacts/cat20/minters/cat20ClosedMinterMetadata.scrypt +13 -0
  62. package/artifacts/cat20/minters/cat20OpenMinter.json +508 -0
  63. package/artifacts/cat20/minters/cat20OpenMinter.scrypt +96 -0
  64. package/artifacts/cat20/minters/cat20OpenMinterMetadata.json +173 -0
  65. package/artifacts/cat20/minters/cat20OpenMinterMetadata.scrypt +13 -0
  66. package/artifacts/cat20/types.json +159 -0
  67. package/artifacts/cat20/types.scrypt +47 -0
  68. package/artifacts/cat20Incinerator.json +396 -0
  69. package/artifacts/cat20Incinerator.scrypt +33 -0
  70. package/artifacts/constants.json +26 -0
  71. package/artifacts/constants.scrypt +18 -0
  72. package/artifacts/counter.json +253 -0
  73. package/artifacts/counter.scrypt +38 -0
  74. package/artifacts/p2pkh.json +229 -0
  75. package/artifacts/p2pkh.scrypt +13 -0
  76. package/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/backtrace.scrypt +38 -0
  77. package/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/contextUtils.scrypt +93 -0
  78. package/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/stateUtils.scrypt +9 -0
  79. package/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/stdUtils.scrypt +96 -0
  80. package/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/txHashPreimageUtils.scrypt +20 -0
  81. package/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/txUtils.scrypt +48 -0
  82. package/artifacts/scrypt-ts-opcat/assets/smart-contract/types/structs.scrypt +50 -0
  83. package/artifacts/types.json +33 -0
  84. package/artifacts/types.scrypt +8 -0
  85. package/artifacts/utils/ownerUtils.json +215 -0
  86. package/artifacts/utils/ownerUtils.scrypt +28 -0
  87. package/artifacts/utils/safeMath.json +215 -0
  88. package/artifacts/utils/safeMath.scrypt +13 -0
  89. package/dist/artifacts/.templates/cat20/cat20.scrypt.map +1 -0
  90. package/dist/artifacts/.templates/cat20/cat20.scrypt.tpl +60 -0
  91. package/dist/artifacts/.templates/cat20/cat20.transformer.json +9 -0
  92. package/dist/artifacts/.templates/cat20/cat20Guard.scrypt.map +1 -0
  93. package/dist/artifacts/.templates/cat20/cat20Guard.scrypt.tpl +117 -0
  94. package/dist/artifacts/.templates/cat20/cat20Guard.transformer.json +9 -0
  95. package/dist/artifacts/.templates/cat20/cat20GuardStateLib.scrypt.map +1 -0
  96. package/dist/artifacts/.templates/cat20/cat20GuardStateLib.scrypt.tpl +36 -0
  97. package/dist/artifacts/.templates/cat20/cat20GuardStateLib.transformer.json +7 -0
  98. package/dist/artifacts/.templates/cat20/cat20StateLib.scrypt.map +1 -0
  99. package/dist/artifacts/.templates/cat20/cat20StateLib.scrypt.tpl +21 -0
  100. package/dist/artifacts/.templates/cat20/cat20StateLib.transformer.json +7 -0
  101. package/dist/artifacts/.templates/cat20/minters/cat20ClosedMinter.scrypt.map +1 -0
  102. package/dist/artifacts/.templates/cat20/minters/cat20ClosedMinter.scrypt.tpl +61 -0
  103. package/dist/artifacts/.templates/cat20/minters/cat20ClosedMinter.transformer.json +9 -0
  104. package/dist/artifacts/.templates/cat20/minters/cat20ClosedMinterMetadata.scrypt.map +1 -0
  105. package/dist/artifacts/.templates/cat20/minters/cat20ClosedMinterMetadata.scrypt.tpl +11 -0
  106. package/dist/artifacts/.templates/cat20/minters/cat20ClosedMinterMetadata.transformer.json +7 -0
  107. package/dist/artifacts/.templates/cat20/minters/cat20OpenMinter.scrypt.map +1 -0
  108. package/dist/artifacts/.templates/cat20/minters/cat20OpenMinter.scrypt.tpl +94 -0
  109. package/dist/artifacts/.templates/cat20/minters/cat20OpenMinter.transformer.json +9 -0
  110. package/dist/artifacts/.templates/cat20/minters/cat20OpenMinterMetadata.scrypt.map +1 -0
  111. package/dist/artifacts/.templates/cat20/minters/cat20OpenMinterMetadata.scrypt.tpl +11 -0
  112. package/dist/artifacts/.templates/cat20/minters/cat20OpenMinterMetadata.transformer.json +7 -0
  113. package/dist/artifacts/.templates/cat20/types.scrypt.map +1 -0
  114. package/dist/artifacts/.templates/cat20/types.scrypt.tpl +45 -0
  115. package/dist/artifacts/.templates/cat20/types.transformer.json +7 -0
  116. package/dist/artifacts/.templates/cat20Incinerator.scrypt.map +1 -0
  117. package/dist/artifacts/.templates/cat20Incinerator.scrypt.tpl +31 -0
  118. package/dist/artifacts/.templates/cat20Incinerator.transformer.json +9 -0
  119. package/dist/artifacts/.templates/constants.scrypt.map +1 -0
  120. package/dist/artifacts/.templates/constants.scrypt.tpl +16 -0
  121. package/dist/artifacts/.templates/constants.transformer.json +7 -0
  122. package/dist/artifacts/.templates/counter.scrypt.map +1 -0
  123. package/dist/artifacts/.templates/counter.scrypt.tpl +36 -0
  124. package/dist/artifacts/.templates/counter.transformer.json +9 -0
  125. package/dist/artifacts/.templates/p2pkh.scrypt.map +1 -0
  126. package/dist/artifacts/.templates/p2pkh.scrypt.tpl +11 -0
  127. package/dist/artifacts/.templates/p2pkh.transformer.json +7 -0
  128. package/dist/artifacts/.templates/types.scrypt.map +1 -0
  129. package/dist/artifacts/.templates/types.scrypt.tpl +6 -0
  130. package/dist/artifacts/.templates/types.transformer.json +7 -0
  131. package/dist/artifacts/.templates/utils/ownerUtils.scrypt.map +1 -0
  132. package/dist/artifacts/.templates/utils/ownerUtils.scrypt.tpl +26 -0
  133. package/dist/artifacts/.templates/utils/ownerUtils.transformer.json +7 -0
  134. package/dist/artifacts/.templates/utils/safeMath.scrypt.map +1 -0
  135. package/dist/artifacts/.templates/utils/safeMath.scrypt.tpl +11 -0
  136. package/dist/artifacts/.templates/utils/safeMath.transformer.json +7 -0
  137. package/dist/artifacts/cat20/cat20.json +477 -0
  138. package/dist/artifacts/cat20/cat20.scrypt +62 -0
  139. package/dist/artifacts/cat20/cat20Guard.json +447 -0
  140. package/dist/artifacts/cat20/cat20Guard.scrypt +119 -0
  141. package/dist/artifacts/cat20/cat20GuardStateLib.json +361 -0
  142. package/dist/artifacts/cat20/cat20GuardStateLib.scrypt +38 -0
  143. package/dist/artifacts/cat20/cat20StateLib.json +373 -0
  144. package/dist/artifacts/cat20/cat20StateLib.scrypt +23 -0
  145. package/dist/artifacts/cat20/minters/cat20ClosedMinter.json +477 -0
  146. package/dist/artifacts/cat20/minters/cat20ClosedMinter.scrypt +63 -0
  147. package/dist/artifacts/cat20/minters/cat20ClosedMinterMetadata.json +173 -0
  148. package/dist/artifacts/cat20/minters/cat20ClosedMinterMetadata.scrypt +13 -0
  149. package/dist/artifacts/cat20/minters/cat20OpenMinter.json +508 -0
  150. package/dist/artifacts/cat20/minters/cat20OpenMinter.scrypt +96 -0
  151. package/dist/artifacts/cat20/minters/cat20OpenMinterMetadata.json +173 -0
  152. package/dist/artifacts/cat20/minters/cat20OpenMinterMetadata.scrypt +13 -0
  153. package/dist/artifacts/cat20/types.json +159 -0
  154. package/dist/artifacts/cat20/types.scrypt +47 -0
  155. package/dist/artifacts/cat20Incinerator.json +396 -0
  156. package/dist/artifacts/cat20Incinerator.scrypt +33 -0
  157. package/dist/artifacts/constants.json +26 -0
  158. package/dist/artifacts/constants.scrypt +18 -0
  159. package/dist/artifacts/counter.json +253 -0
  160. package/dist/artifacts/counter.scrypt +38 -0
  161. package/dist/artifacts/p2pkh.json +229 -0
  162. package/dist/artifacts/p2pkh.scrypt +13 -0
  163. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/backtrace.scrypt +38 -0
  164. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/contextUtils.scrypt +93 -0
  165. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/stateUtils.scrypt +9 -0
  166. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/stdUtils.scrypt +96 -0
  167. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/txHashPreimageUtils.scrypt +20 -0
  168. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/builtin-libs/txUtils.scrypt +48 -0
  169. package/dist/artifacts/scrypt-ts-opcat/assets/smart-contract/types/structs.scrypt +50 -0
  170. package/dist/artifacts/types.json +33 -0
  171. package/dist/artifacts/types.scrypt +8 -0
  172. package/dist/artifacts/utils/ownerUtils.json +215 -0
  173. package/dist/artifacts/utils/ownerUtils.scrypt +28 -0
  174. package/dist/artifacts/utils/safeMath.json +215 -0
  175. package/dist/artifacts/utils/safeMath.scrypt +13 -0
  176. package/dist/cjs/contracts/cat20/cat20.js +74 -0
  177. package/dist/cjs/contracts/cat20/cat20.js.map +1 -0
  178. package/dist/cjs/contracts/cat20/cat20Guard.js +169 -0
  179. package/dist/cjs/contracts/cat20/cat20Guard.js.map +1 -0
  180. package/dist/cjs/contracts/cat20/cat20GuardStateLib.js +72 -0
  181. package/dist/cjs/contracts/cat20/cat20GuardStateLib.js.map +1 -0
  182. package/dist/cjs/contracts/cat20/cat20StateLib.js +37 -0
  183. package/dist/cjs/contracts/cat20/cat20StateLib.js.map +1 -0
  184. package/dist/cjs/contracts/cat20/minters/cat20ClosedMinter.js +77 -0
  185. package/dist/cjs/contracts/cat20/minters/cat20ClosedMinter.js.map +1 -0
  186. package/dist/cjs/contracts/cat20/minters/cat20ClosedMinterMetadata.js +18 -0
  187. package/dist/cjs/contracts/cat20/minters/cat20ClosedMinterMetadata.js.map +1 -0
  188. package/dist/cjs/contracts/cat20/minters/cat20OpenMinter.js +138 -0
  189. package/dist/cjs/contracts/cat20/minters/cat20OpenMinter.js.map +1 -0
  190. package/dist/cjs/contracts/cat20/minters/cat20OpenMinterMetadata.js +22 -0
  191. package/dist/cjs/contracts/cat20/minters/cat20OpenMinterMetadata.js.map +1 -0
  192. package/dist/cjs/contracts/cat20/types.js +3 -0
  193. package/dist/cjs/contracts/cat20/types.js.map +1 -0
  194. package/dist/cjs/contracts/cat20Incinerator.js +45 -0
  195. package/dist/cjs/contracts/cat20Incinerator.js.map +1 -0
  196. package/dist/cjs/contracts/constants.js +110 -0
  197. package/dist/cjs/contracts/constants.js.map +1 -0
  198. package/dist/cjs/contracts/counter.js +29 -0
  199. package/dist/cjs/contracts/counter.js.map +1 -0
  200. package/dist/cjs/contracts/index.js +32 -0
  201. package/dist/cjs/contracts/index.js.map +1 -0
  202. package/dist/cjs/contracts/p2pkh.js +35 -0
  203. package/dist/cjs/contracts/p2pkh.js.map +1 -0
  204. package/dist/cjs/contracts/types.js +3 -0
  205. package/dist/cjs/contracts/types.js.map +1 -0
  206. package/dist/cjs/contracts/utils/ownerUtils.js +78 -0
  207. package/dist/cjs/contracts/utils/ownerUtils.js.map +1 -0
  208. package/dist/cjs/contracts/utils/safeMath.js +28 -0
  209. package/dist/cjs/contracts/utils/safeMath.js.map +1 -0
  210. package/dist/cjs/features/cat20/burn/burn.js +91 -0
  211. package/dist/cjs/features/cat20/burn/burn.js.map +1 -0
  212. package/dist/cjs/features/cat20/deploy/openMinter.js +135 -0
  213. package/dist/cjs/features/cat20/deploy/openMinter.js.map +1 -0
  214. package/dist/cjs/features/cat20/incinerate.js +108 -0
  215. package/dist/cjs/features/cat20/incinerate.js.map +1 -0
  216. package/dist/cjs/features/cat20/mint/openMinter.js +37 -0
  217. package/dist/cjs/features/cat20/mint/openMinter.js.map +1 -0
  218. package/dist/cjs/features/cat20/send/contractSend.js +130 -0
  219. package/dist/cjs/features/cat20/send/contractSend.js.map +1 -0
  220. package/dist/cjs/features/cat20/send/singleSend.js +172 -0
  221. package/dist/cjs/features/cat20/send/singleSend.js.map +1 -0
  222. package/dist/cjs/features/index.js +19 -0
  223. package/dist/cjs/features/index.js.map +1 -0
  224. package/dist/cjs/index.js +35 -0
  225. package/dist/cjs/index.js.map +1 -0
  226. package/dist/cjs/lib/index.js +19 -0
  227. package/dist/cjs/lib/index.js.map +1 -0
  228. package/dist/cjs/lib/metadata.js +32 -0
  229. package/dist/cjs/lib/metadata.js.map +1 -0
  230. package/dist/cjs/typeConstants.js +18 -0
  231. package/dist/cjs/typeConstants.js.map +1 -0
  232. package/dist/cjs/utils/check.js +24 -0
  233. package/dist/cjs/utils/check.js.map +1 -0
  234. package/dist/cjs/utils/contractPeripheral.js +189 -0
  235. package/dist/cjs/utils/contractPeripheral.js.map +1 -0
  236. package/dist/cjs/utils/index.js +223 -0
  237. package/dist/cjs/utils/index.js.map +1 -0
  238. package/dist/cjs/utils/loadAllArtifacts.js +39 -0
  239. package/dist/cjs/utils/loadAllArtifacts.js.map +1 -0
  240. package/dist/esm/contracts/cat20/cat20.js +72 -0
  241. package/dist/esm/contracts/cat20/cat20.js.map +1 -0
  242. package/dist/esm/contracts/cat20/cat20Guard.js +165 -0
  243. package/dist/esm/contracts/cat20/cat20Guard.js.map +1 -0
  244. package/dist/esm/contracts/cat20/cat20GuardStateLib.js +68 -0
  245. package/dist/esm/contracts/cat20/cat20GuardStateLib.js.map +1 -0
  246. package/dist/esm/contracts/cat20/cat20StateLib.js +33 -0
  247. package/dist/esm/contracts/cat20/cat20StateLib.js.map +1 -0
  248. package/dist/esm/contracts/cat20/minters/cat20ClosedMinter.js +75 -0
  249. package/dist/esm/contracts/cat20/minters/cat20ClosedMinter.js.map +1 -0
  250. package/dist/esm/contracts/cat20/minters/cat20ClosedMinterMetadata.js +14 -0
  251. package/dist/esm/contracts/cat20/minters/cat20ClosedMinterMetadata.js.map +1 -0
  252. package/dist/esm/contracts/cat20/minters/cat20OpenMinter.js +142 -0
  253. package/dist/esm/contracts/cat20/minters/cat20OpenMinter.js.map +1 -0
  254. package/dist/esm/contracts/cat20/minters/cat20OpenMinterMetadata.js +18 -0
  255. package/dist/esm/contracts/cat20/minters/cat20OpenMinterMetadata.js.map +1 -0
  256. package/dist/esm/contracts/cat20/types.js +2 -0
  257. package/dist/esm/contracts/cat20/types.js.map +1 -0
  258. package/dist/esm/contracts/cat20Incinerator.js +42 -0
  259. package/dist/esm/contracts/cat20Incinerator.js.map +1 -0
  260. package/dist/esm/contracts/constants.js +106 -0
  261. package/dist/esm/contracts/constants.js.map +1 -0
  262. package/dist/esm/contracts/counter.js +25 -0
  263. package/dist/esm/contracts/counter.js.map +1 -0
  264. package/dist/esm/contracts/index.js +16 -0
  265. package/dist/esm/contracts/index.js.map +1 -0
  266. package/dist/esm/contracts/p2pkh.js +32 -0
  267. package/dist/esm/contracts/p2pkh.js.map +1 -0
  268. package/dist/esm/contracts/types.js +2 -0
  269. package/dist/esm/contracts/types.js.map +1 -0
  270. package/dist/esm/contracts/utils/ownerUtils.js +74 -0
  271. package/dist/esm/contracts/utils/ownerUtils.js.map +1 -0
  272. package/dist/esm/contracts/utils/safeMath.js +24 -0
  273. package/dist/esm/contracts/utils/safeMath.js.map +1 -0
  274. package/dist/esm/features/cat20/burn/burn.js +87 -0
  275. package/dist/esm/features/cat20/burn/burn.js.map +1 -0
  276. package/dist/esm/features/cat20/deploy/openMinter.js +130 -0
  277. package/dist/esm/features/cat20/deploy/openMinter.js.map +1 -0
  278. package/dist/esm/features/cat20/incinerate.js +104 -0
  279. package/dist/esm/features/cat20/incinerate.js.map +1 -0
  280. package/dist/esm/features/cat20/mint/openMinter.js +33 -0
  281. package/dist/esm/features/cat20/mint/openMinter.js.map +1 -0
  282. package/dist/esm/features/cat20/send/contractSend.js +126 -0
  283. package/dist/esm/features/cat20/send/contractSend.js.map +1 -0
  284. package/dist/esm/features/cat20/send/singleSend.js +142 -0
  285. package/dist/esm/features/cat20/send/singleSend.js.map +1 -0
  286. package/dist/esm/features/index.js +7 -0
  287. package/dist/esm/features/index.js.map +1 -0
  288. package/dist/esm/index.js +9 -0
  289. package/dist/esm/index.js.map +1 -0
  290. package/dist/esm/lib/index.js +3 -0
  291. package/dist/esm/lib/index.js.map +1 -0
  292. package/dist/esm/lib/metadata.js +28 -0
  293. package/dist/esm/lib/metadata.js.map +1 -0
  294. package/dist/esm/typeConstants.js +15 -0
  295. package/dist/esm/typeConstants.js.map +1 -0
  296. package/dist/esm/utils/check.js +19 -0
  297. package/dist/esm/utils/check.js.map +1 -0
  298. package/dist/esm/utils/contractPeripheral.js +183 -0
  299. package/dist/esm/utils/contractPeripheral.js.map +1 -0
  300. package/dist/esm/utils/index.js +184 -0
  301. package/dist/esm/utils/index.js.map +1 -0
  302. package/dist/esm/utils/loadAllArtifacts.js +32 -0
  303. package/dist/esm/utils/loadAllArtifacts.js.map +1 -0
  304. package/dist/types/contracts/cat20/cat20.d.ts +12 -0
  305. package/dist/types/contracts/cat20/cat20.d.ts.map +1 -0
  306. package/dist/types/contracts/cat20/cat20Guard.d.ts +8 -0
  307. package/dist/types/contracts/cat20/cat20Guard.d.ts.map +1 -0
  308. package/dist/types/contracts/cat20/cat20GuardStateLib.d.ts +13 -0
  309. package/dist/types/contracts/cat20/cat20GuardStateLib.d.ts.map +1 -0
  310. package/dist/types/contracts/cat20/cat20StateLib.d.ts +7 -0
  311. package/dist/types/contracts/cat20/cat20StateLib.d.ts.map +1 -0
  312. package/dist/types/contracts/cat20/minters/cat20ClosedMinter.d.ts +10 -0
  313. package/dist/types/contracts/cat20/minters/cat20ClosedMinter.d.ts.map +1 -0
  314. package/dist/types/contracts/cat20/minters/cat20ClosedMinterMetadata.d.ts +6 -0
  315. package/dist/types/contracts/cat20/minters/cat20ClosedMinterMetadata.d.ts.map +1 -0
  316. package/dist/types/contracts/cat20/minters/cat20OpenMinter.d.ts +16 -0
  317. package/dist/types/contracts/cat20/minters/cat20OpenMinter.d.ts.map +1 -0
  318. package/dist/types/contracts/cat20/minters/cat20OpenMinterMetadata.d.ts +6 -0
  319. package/dist/types/contracts/cat20/minters/cat20OpenMinterMetadata.d.ts.map +1 -0
  320. package/dist/types/contracts/cat20/types.d.ts +58 -0
  321. package/dist/types/contracts/cat20/types.d.ts.map +1 -0
  322. package/dist/types/contracts/cat20Incinerator.d.ts +8 -0
  323. package/dist/types/contracts/cat20Incinerator.d.ts.map +1 -0
  324. package/dist/types/contracts/constants.d.ts +33 -0
  325. package/dist/types/contracts/constants.d.ts.map +1 -0
  326. package/dist/types/contracts/counter.d.ts +8 -0
  327. package/dist/types/contracts/counter.d.ts.map +1 -0
  328. package/dist/types/contracts/index.d.ts +16 -0
  329. package/dist/types/contracts/index.d.ts.map +1 -0
  330. package/dist/types/contracts/p2pkh.d.ts +7 -0
  331. package/dist/types/contracts/p2pkh.d.ts.map +1 -0
  332. package/dist/types/contracts/types.d.ts +9 -0
  333. package/dist/types/contracts/types.d.ts.map +1 -0
  334. package/dist/types/contracts/utils/ownerUtils.d.ts +19 -0
  335. package/dist/types/contracts/utils/ownerUtils.d.ts.map +1 -0
  336. package/dist/types/contracts/utils/safeMath.d.ts +5 -0
  337. package/dist/types/contracts/utils/safeMath.d.ts.map +1 -0
  338. package/dist/types/features/cat20/burn/burn.d.ts +6 -0
  339. package/dist/types/features/cat20/burn/burn.d.ts.map +1 -0
  340. package/dist/types/features/cat20/deploy/openMinter.d.ts +11 -0
  341. package/dist/types/features/cat20/deploy/openMinter.d.ts.map +1 -0
  342. package/dist/types/features/cat20/incinerate.d.ts +6 -0
  343. package/dist/types/features/cat20/incinerate.d.ts.map +1 -0
  344. package/dist/types/features/cat20/mint/openMinter.d.ts +7 -0
  345. package/dist/types/features/cat20/mint/openMinter.d.ts.map +1 -0
  346. package/dist/types/features/cat20/send/contractSend.d.ts +14 -0
  347. package/dist/types/features/cat20/send/contractSend.d.ts.map +1 -0
  348. package/dist/types/features/cat20/send/singleSend.d.ts +33 -0
  349. package/dist/types/features/cat20/send/singleSend.d.ts.map +1 -0
  350. package/dist/types/features/index.d.ts +7 -0
  351. package/dist/types/features/index.d.ts.map +1 -0
  352. package/dist/types/index.d.ts +7 -0
  353. package/dist/types/index.d.ts.map +1 -0
  354. package/dist/types/lib/index.d.ts +2 -0
  355. package/dist/types/lib/index.d.ts.map +1 -0
  356. package/dist/types/lib/metadata.d.ts +18 -0
  357. package/dist/types/lib/metadata.d.ts.map +1 -0
  358. package/dist/types/typeConstants.d.ts +31 -0
  359. package/dist/types/typeConstants.d.ts.map +1 -0
  360. package/dist/types/utils/check.d.ts +3 -0
  361. package/dist/types/utils/check.d.ts.map +1 -0
  362. package/dist/types/utils/contractPeripheral.d.ts +45 -0
  363. package/dist/types/utils/contractPeripheral.d.ts.map +1 -0
  364. package/dist/types/utils/index.d.ts +29 -0
  365. package/dist/types/utils/index.d.ts.map +1 -0
  366. package/dist/types/utils/loadAllArtifacts.d.ts +2 -0
  367. package/dist/types/utils/loadAllArtifacts.d.ts.map +1 -0
  368. package/package.json +76 -0
  369. package/scrypt.index.json +132 -0
@@ -0,0 +1,215 @@
1
+ {
2
+ "version": 10,
3
+ "compilerVersion": "1.21.0+commit.2ada378",
4
+ "contract": "_opcat_labs_cat_sdk_1_0_1__rs__SafeMath",
5
+ "md5": "d41d8cd98f00b204e9800998ecf8427e",
6
+ "structs": [
7
+ {
8
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__TxOut",
9
+ "params": [
10
+ {
11
+ "name": "scriptHash",
12
+ "type": "bytes"
13
+ },
14
+ {
15
+ "name": "dataHash",
16
+ "type": "bytes"
17
+ },
18
+ {
19
+ "name": "satoshis",
20
+ "type": "int"
21
+ }
22
+ ],
23
+ "genericTypes": []
24
+ },
25
+ {
26
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__TxIn",
27
+ "params": [
28
+ {
29
+ "name": "prevTxHash",
30
+ "type": "bytes"
31
+ },
32
+ {
33
+ "name": "prevOutputIndex",
34
+ "type": "int"
35
+ },
36
+ {
37
+ "name": "sequence",
38
+ "type": "int"
39
+ },
40
+ {
41
+ "name": "scriptHash",
42
+ "type": "bytes"
43
+ }
44
+ ],
45
+ "genericTypes": []
46
+ },
47
+ {
48
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__TxHashPreimage",
49
+ "params": [
50
+ {
51
+ "name": "version",
52
+ "type": "bytes"
53
+ },
54
+ {
55
+ "name": "inputList",
56
+ "type": "bytes"
57
+ },
58
+ {
59
+ "name": "outputList",
60
+ "type": "bytes"
61
+ },
62
+ {
63
+ "name": "nLockTime",
64
+ "type": "bytes"
65
+ }
66
+ ],
67
+ "genericTypes": []
68
+ },
69
+ {
70
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__BacktraceInfo",
71
+ "params": [
72
+ {
73
+ "name": "prevTxInput",
74
+ "type": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__TxIn"
75
+ },
76
+ {
77
+ "name": "prevTxInputIndex",
78
+ "type": "int"
79
+ },
80
+ {
81
+ "name": "prevPrevTxPreimage",
82
+ "type": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__TxHashPreimage"
83
+ }
84
+ ],
85
+ "genericTypes": []
86
+ },
87
+ {
88
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__SHPreimage",
89
+ "params": [
90
+ {
91
+ "name": "nVersion",
92
+ "type": "bytes"
93
+ },
94
+ {
95
+ "name": "hashPrevouts",
96
+ "type": "bytes"
97
+ },
98
+ {
99
+ "name": "spentScriptHash",
100
+ "type": "bytes"
101
+ },
102
+ {
103
+ "name": "spentDataHash",
104
+ "type": "bytes"
105
+ },
106
+ {
107
+ "name": "value",
108
+ "type": "int"
109
+ },
110
+ {
111
+ "name": "nSequence",
112
+ "type": "bytes"
113
+ },
114
+ {
115
+ "name": "hashSpentAmounts",
116
+ "type": "bytes"
117
+ },
118
+ {
119
+ "name": "hashSpentScriptHashes",
120
+ "type": "bytes"
121
+ },
122
+ {
123
+ "name": "hashSpentDataHashes",
124
+ "type": "bytes"
125
+ },
126
+ {
127
+ "name": "hashSequences",
128
+ "type": "bytes"
129
+ },
130
+ {
131
+ "name": "hashOutputs",
132
+ "type": "bytes"
133
+ },
134
+ {
135
+ "name": "inputIndex",
136
+ "type": "int"
137
+ },
138
+ {
139
+ "name": "nLockTime",
140
+ "type": "int"
141
+ },
142
+ {
143
+ "name": "sigHashType",
144
+ "type": "int"
145
+ }
146
+ ],
147
+ "genericTypes": []
148
+ },
149
+ {
150
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__Outpoint",
151
+ "params": [
152
+ {
153
+ "name": "txHash",
154
+ "type": "bytes"
155
+ },
156
+ {
157
+ "name": "outputIndex",
158
+ "type": "int"
159
+ }
160
+ ],
161
+ "genericTypes": []
162
+ },
163
+ {
164
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__ReadVarintResult",
165
+ "params": [
166
+ {
167
+ "name": "data",
168
+ "type": "bytes"
169
+ },
170
+ {
171
+ "name": "nextPos",
172
+ "type": "int"
173
+ }
174
+ ],
175
+ "genericTypes": []
176
+ }
177
+ ],
178
+ "library": [
179
+ {
180
+ "name": "_opcat_labs_cat_sdk_1_0_1__rs__SafeMath",
181
+ "params": [],
182
+ "properties": [],
183
+ "genericTypes": []
184
+ },
185
+ {
186
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__TxUtils",
187
+ "params": [],
188
+ "properties": [],
189
+ "genericTypes": []
190
+ },
191
+ {
192
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__ContextUtils",
193
+ "params": [],
194
+ "properties": [],
195
+ "genericTypes": []
196
+ },
197
+ {
198
+ "name": "_opcat_labs_scrypt_ts_opcat_1_0_3__rs__StdUtils",
199
+ "params": [],
200
+ "properties": [],
201
+ "genericTypes": []
202
+ }
203
+ ],
204
+ "alias": [],
205
+ "abi": [
206
+ {
207
+ "type": "constructor",
208
+ "params": []
209
+ }
210
+ ],
211
+ "stateProps": [],
212
+ "buildType": "release",
213
+ "file": "..\\safeMath.scrypt",
214
+ "hex": ""
215
+ }
@@ -0,0 +1,13 @@
1
+ import "../scrypt-ts-opcat/assets/smart-contract/builtin-libs/txUtils.scrypt";
2
+ import "../scrypt-ts-opcat/assets/smart-contract/builtin-libs/contextUtils.scrypt";
3
+
4
+
5
+
6
+
7
+ library _opcat_labs_cat_sdk_1_0_1__rs__SafeMath {
8
+ static function add(int a, int b) : int {
9
+ int c = a + b;
10
+ require(c >= a && c >= b);
11
+ return c;
12
+ }
13
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CAT20 = void 0;
13
+ const scrypt_ts_opcat_1 = require("@opcat-labs/scrypt-ts-opcat");
14
+ const ownerUtils_1 = require("../utils/ownerUtils");
15
+ const constants_1 = require("../constants");
16
+ const cat20GuardStateLib_1 = require("./cat20GuardStateLib");
17
+ class CAT20 extends scrypt_ts_opcat_1.SmartContract {
18
+ constructor(minterScriptHash, guardScriptHash) {
19
+ super(...arguments);
20
+ this.minterScriptHash = minterScriptHash;
21
+ this.guardScriptHash = guardScriptHash;
22
+ }
23
+ unlock(unlockArgs,
24
+ // guard
25
+ guardState, guardInputIndex,
26
+ // backtrace
27
+ backtraceInfo) {
28
+ this.backtraceToScript(backtraceInfo, this.minterScriptHash);
29
+ // make sure tx inputs contain a valid guard
30
+ this.checkGuard(guardState, this.ctx.spentScriptHash, this.ctx.inputIndex, guardInputIndex, this.ctx.spentScriptHashes, this.ctx.spentDataHashes);
31
+ if ((0, scrypt_ts_opcat_1.len)(this.state.ownerAddr) == constants_1.OWNER_ADDR_CONTRACT_HASH_BYTE_LEN) {
32
+ // unlock token owned by contract script
33
+ (0, scrypt_ts_opcat_1.assert)(this.state.ownerAddr ==
34
+ (0, scrypt_ts_opcat_1.slice)(this.ctx.spentScriptHashes, unlockArgs.contractInputIndex * scrypt_ts_opcat_1.TX_OUTPUT_SCRIPT_HASH_LEN, (unlockArgs.contractInputIndex + 1n) * scrypt_ts_opcat_1.TX_OUTPUT_SCRIPT_HASH_LEN));
35
+ }
36
+ else {
37
+ // unlock token owned by user key
38
+ ownerUtils_1.OwnerUtils.checkUserOwner(unlockArgs.userPubKey, this.state.ownerAddr);
39
+ (0, scrypt_ts_opcat_1.assert)(this.checkSig(unlockArgs.userSig, unlockArgs.userPubKey));
40
+ }
41
+ }
42
+ checkGuard(guardState, t_cat20ScriptHash, t_cat20InputIndexVal, guardInputIndexVal, t_spentScriptsCtx, t_spentDataHashesCtx) {
43
+ // 1. check there is a guard input by shPreimage.hashSpentScriptHashes
44
+ (0, scrypt_ts_opcat_1.assert)(scrypt_ts_opcat_1.ContextUtils.getSpentScriptHash(t_spentScriptsCtx, guardInputIndexVal) == this.guardScriptHash);
45
+ (0, scrypt_ts_opcat_1.assert)(scrypt_ts_opcat_1.ContextUtils.getSpentDataHash(t_spentDataHashesCtx, guardInputIndexVal) == cat20GuardStateLib_1.CAT20GuardStateLib.stateHash(guardState));
46
+ // 2. check the guard input is validating current input by checking guard state contains current token script
47
+ // and the corresponding value of array tokenScripts and tokenScriptIndexes is correct
48
+ const tokenScriptIndex = guardState.tokenScriptIndexes[Number(t_cat20InputIndexVal)];
49
+ (0, scrypt_ts_opcat_1.assert)(guardState.tokenScriptHashes[Number(tokenScriptIndex)] ==
50
+ t_cat20ScriptHash);
51
+ }
52
+ }
53
+ exports.CAT20 = CAT20;
54
+ __decorate([
55
+ (0, scrypt_ts_opcat_1.prop)(),
56
+ __metadata("design:type", String)
57
+ ], CAT20.prototype, "minterScriptHash", void 0);
58
+ __decorate([
59
+ (0, scrypt_ts_opcat_1.prop)(),
60
+ __metadata("design:type", String)
61
+ ], CAT20.prototype, "guardScriptHash", void 0);
62
+ __decorate([
63
+ (0, scrypt_ts_opcat_1.method)(),
64
+ __metadata("design:type", Function),
65
+ __metadata("design:paramtypes", [Object, Object, BigInt, Object]),
66
+ __metadata("design:returntype", void 0)
67
+ ], CAT20.prototype, "unlock", null);
68
+ __decorate([
69
+ (0, scrypt_ts_opcat_1.method)(),
70
+ __metadata("design:type", Function),
71
+ __metadata("design:paramtypes", [Object, String, BigInt, BigInt, String, String]),
72
+ __metadata("design:returntype", void 0)
73
+ ], CAT20.prototype, "checkGuard", null);
74
+ //# sourceMappingURL=cat20.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat20.js","sourceRoot":"","sources":["../../../../src/contracts/cat20/cat20.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAYoC;AACpC,oDAAgD;AAKhD,4CAAgE;AAEhE,6DAAyD;AAEzD,MAAa,KAAM,SAAQ,+BAAyB;IAOlD,YAAY,gBAA4B,EAAE,eAA2B;QACnE,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QACnB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;QACxC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;IACxC,CAAC;IAGM,MAAM,CACX,UAA8B;IAC9B,QAAQ;IACR,UAAgC,EAChC,eAAuB;IACvB,YAAY;IACZ,aAA4B;QAE5B,IAAI,CAAC,iBAAiB,CAAC,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAE7D,4CAA4C;QAC5C,IAAI,CAAC,UAAU,CACb,UAAU,EACV,IAAI,CAAC,GAAG,CAAC,eAAe,EACxB,IAAI,CAAC,GAAG,CAAC,UAAU,EACnB,eAAe,EACf,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAC1B,IAAI,CAAC,GAAG,CAAC,eAAe,CACzB,CAAA;QAED,I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vED,sBAuEC;AArEC;IADC,IAAA,sBAAI,GAAE;;+CACqB;AAG5B;IADC,IAAA,sBAAI,GAAE;;8CACoB;AASpB;IADN,IAAA,wBAAM,GAAE;;;;mCAgCR;AAGD;IADC,IAAA,wBAAM,GAAE;;;;uCAuBR"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CAT20Guard = void 0;
13
+ const scrypt_ts_opcat_1 = require("@opcat-labs/scrypt-ts-opcat");
14
+ const constants_1 = require("../constants");
15
+ const safeMath_1 = require("../utils/safeMath");
16
+ const cat20GuardStateLib_1 = require("./cat20GuardStateLib");
17
+ const cat20StateLib_1 = require("./cat20StateLib");
18
+ class CAT20Guard extends scrypt_ts_opcat_1.SmartContract {
19
+ unlock(nextStateHashes,
20
+ // for each curTx output except the state hash root output,
21
+ // if it is a token output, the value is token owner address of this output,
22
+ // otherwise, the value is the locking script hash of this output
23
+ ownerAddrOrScriptHashes,
24
+ // for each curTx output except the state hash root output,
25
+ // if it is a token output, the value is the token amount of this output,
26
+ // otherwise, the value is 0 by default
27
+ outputTokens,
28
+ // for each curTx output except the state hash root output,
29
+ // if it is a token output,
30
+ // the value marks the index of the token script used by this output in the tokenScripts,
31
+ // otherwise, the value is -1 by default
32
+ // this logic is the same as tokenScriptIndexes in GuardConstState which is used for token inputs
33
+ tokenScriptHashIndexes,
34
+ // output satoshi of each curTx output except the state hash root output
35
+ outputSatoshis,
36
+ // for each curTx input,
37
+ // if it is a token input, the value is the raw state of this input,
38
+ // otherwise, the value is an empty state by default
39
+ cat20States,
40
+ // the number of curTx outputs except for the state hash root output
41
+ outputCount) {
42
+ // check current input state hash empty
43
+ cat20GuardStateLib_1.CAT20GuardStateLib.formalCheckState(this.state);
44
+ // how many different types of tokens in curTx inputs
45
+ let inputTokenTypes = 0n;
46
+ const tokenScriptPlaceholders = [
47
+ constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FF,
48
+ constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FE,
49
+ constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FD,
50
+ constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FC,
51
+ ];
52
+ for (let i = 0; i < constants_1.GUARD_TOKEN_TYPE_MAX; i++) {
53
+ if (this.state.tokenScriptHashes[i] != tokenScriptPlaceholders[i]) {
54
+ inputTokenTypes++;
55
+ }
56
+ }
57
+ // ensure there are no placeholders between valid token scripts in curState.tokenScriptHashes
58
+ for (let i = 0; i < constants_1.GUARD_TOKEN_TYPE_MAX; i++) {
59
+ if (i < Number(inputTokenTypes)) {
60
+ (0, scrypt_ts_opcat_1.assert)(this.state.tokenScriptHashes[i] != tokenScriptPlaceholders[i]);
61
+ (0, scrypt_ts_opcat_1.assert)((0, scrypt_ts_opcat_1.len)(this.state.tokenScriptHashes[i]) == constants_1.OUTPUT_LOCKING_SCRIPT_HASH_LEN);
62
+ }
63
+ else {
64
+ (0, scrypt_ts_opcat_1.assert)(this.state.tokenScriptHashes[i] == tokenScriptPlaceholders[i]);
65
+ }
66
+ }
67
+ (0, scrypt_ts_opcat_1.assert)(inputTokenTypes > 0n);
68
+ // inputTokenTypes here is not trustable yet
69
+ // user could append token scripts in curState.tokenScripts that are not used in curTx inputs
70
+ // sum token input amount, data comes from cat20 raw states passed in by the user
71
+ const sumInputTokens = (0, scrypt_ts_opcat_1.fill)(0n, constants_1.GUARD_TOKEN_TYPE_MAX);
72
+ let tokenScriptIndexMax = -1n;
73
+ const inputCount = this.ctx.inputCount;
74
+ for (let i = 0; i < constants_1.TX_INPUT_COUNT_MAX; i++) {
75
+ const tokenScriptIndex = this.state.tokenScriptIndexes[Number(i)];
76
+ if (i < inputCount) {
77
+ (0, scrypt_ts_opcat_1.assert)(tokenScriptIndex < inputTokenTypes);
78
+ if (tokenScriptIndex != -1n) {
79
+ // this is a token input
80
+ const tokenScriptHash = this.state.tokenScriptHashes[Number(tokenScriptIndex)];
81
+ (0, scrypt_ts_opcat_1.assert)(tokenScriptHash == scrypt_ts_opcat_1.ContextUtils.getSpentScriptHash(this.ctx.spentScriptHashes, BigInt(i)));
82
+ cat20StateLib_1.CAT20StateLib.checkState(cat20States[i]);
83
+ (0, scrypt_ts_opcat_1.assert)(scrypt_ts_opcat_1.ContextUtils.getSpentDataHash(this.ctx.spentDataHashes, BigInt(i)) == cat20StateLib_1.CAT20StateLib.stateHash(cat20States[i]));
84
+ sumInputTokens[Number(tokenScriptIndex)] = safeMath_1.SafeMath.add(sumInputTokens[Number(tokenScriptIndex)], cat20States[i].amount);
85
+ tokenScriptIndexMax =
86
+ tokenScriptIndex > tokenScriptIndexMax
87
+ ? tokenScriptIndex
88
+ : tokenScriptIndexMax;
89
+ }
90
+ }
91
+ else {
92
+ (0, scrypt_ts_opcat_1.assert)(this.state.tokenScriptIndexes[i] == -1n);
93
+ }
94
+ }
95
+ // verify inputTokenTypes by tokenScriptIndexMax
96
+ // tokenScriptIndexMax is trustable because it is calculated after going through all the curTx inputs
97
+ // this also ensures that there is at least one token input in curTx
98
+ (0, scrypt_ts_opcat_1.assert)(tokenScriptIndexMax >= 0n && tokenScriptIndexMax == inputTokenTypes - 1n);
99
+ // sum token output amount, data comes from outputTokens passed in by the user
100
+ // and build curTx outputs and stateRoots as well
101
+ (0, scrypt_ts_opcat_1.assert)(outputCount >= 0n && outputCount <= constants_1.TX_OUTPUT_COUNT_MAX);
102
+ const sumOutputTokens = (0, scrypt_ts_opcat_1.fill)(0n, constants_1.GUARD_TOKEN_TYPE_MAX);
103
+ let outputs = (0, scrypt_ts_opcat_1.toByteString)('');
104
+ for (let i = 0; i < constants_1.TX_OUTPUT_COUNT_MAX; i++) {
105
+ if (i < outputCount) {
106
+ const ownerAddrOrScriptHash = ownerAddrOrScriptHashes[i];
107
+ (0, scrypt_ts_opcat_1.assert)((0, scrypt_ts_opcat_1.len)(ownerAddrOrScriptHash) > 0n);
108
+ const tokenScriptHashIndex = tokenScriptHashIndexes[i];
109
+ (0, scrypt_ts_opcat_1.assert)(tokenScriptHashIndex < inputTokenTypes);
110
+ if (tokenScriptHashIndex != -1n) {
111
+ // this is a token output
112
+ const tokenAmount = outputTokens[i];
113
+ (0, scrypt_ts_opcat_1.assert)(tokenAmount > 0n);
114
+ sumOutputTokens[Number(tokenScriptHashIndex)] = safeMath_1.SafeMath.add(sumOutputTokens[Number(tokenScriptHashIndex)], tokenAmount);
115
+ const tokenStateHash = cat20StateLib_1.CAT20StateLib.stateHash({
116
+ tag: constants_1.ConstantsLib.OPCAT_CAT20_TAG,
117
+ ownerAddr: ownerAddrOrScriptHash,
118
+ amount: tokenAmount,
119
+ });
120
+ (0, scrypt_ts_opcat_1.assert)(nextStateHashes[i] == tokenStateHash);
121
+ const tokenScriptHash = this.state.tokenScriptHashes[Number(tokenScriptHashIndex)];
122
+ outputs += scrypt_ts_opcat_1.TxUtils.buildDataOutput(tokenScriptHash, outputSatoshis[i], tokenStateHash);
123
+ }
124
+ else {
125
+ // this is a non-token output
126
+ (0, scrypt_ts_opcat_1.assert)(outputTokens[i] == 0n);
127
+ // locking script of this non-token output cannot be the same as any token script in curState
128
+ for (let j = 0; j < constants_1.GUARD_TOKEN_TYPE_MAX; j++) {
129
+ (0, scrypt_ts_opcat_1.assert)(ownerAddrOrScriptHash != this.state.tokenScriptHashes[j]);
130
+ }
131
+ outputs += scrypt_ts_opcat_1.TxUtils.buildDataOutput(ownerAddrOrScriptHash, outputSatoshis[i], nextStateHashes[i]);
132
+ }
133
+ }
134
+ else {
135
+ (0, scrypt_ts_opcat_1.assert)((0, scrypt_ts_opcat_1.len)(ownerAddrOrScriptHashes[i]) == 0n);
136
+ (0, scrypt_ts_opcat_1.assert)(tokenScriptHashIndexes[i] == -1n);
137
+ (0, scrypt_ts_opcat_1.assert)(outputTokens[i] == 0n);
138
+ (0, scrypt_ts_opcat_1.assert)(nextStateHashes[i] == (0, scrypt_ts_opcat_1.toByteString)(''));
139
+ (0, scrypt_ts_opcat_1.assert)(outputSatoshis[i] == 0n);
140
+ }
141
+ }
142
+ // check token amount consistency of inputs and outputs
143
+ for (let i = 0; i < constants_1.GUARD_TOKEN_TYPE_MAX; i++) {
144
+ (0, scrypt_ts_opcat_1.assert)(sumInputTokens[i] == this.state.tokenAmounts[i]);
145
+ (0, scrypt_ts_opcat_1.assert)(sumInputTokens[i] ==
146
+ safeMath_1.SafeMath.add(sumOutputTokens[i], this.state.tokenBurnAmounts[i]));
147
+ if (i < Number(inputTokenTypes)) {
148
+ (0, scrypt_ts_opcat_1.assert)(sumInputTokens[i] > 0n);
149
+ }
150
+ else {
151
+ (0, scrypt_ts_opcat_1.assert)(sumInputTokens[i] == 0n);
152
+ (0, scrypt_ts_opcat_1.assert)(sumOutputTokens[i] == 0n);
153
+ // no need to check below two lines here, but we keep them here for better readability
154
+ (0, scrypt_ts_opcat_1.assert)(this.state.tokenAmounts[i] == 0n);
155
+ (0, scrypt_ts_opcat_1.assert)(this.state.tokenBurnAmounts[i] == 0n);
156
+ }
157
+ }
158
+ // confine curTx outputs
159
+ (0, scrypt_ts_opcat_1.assert)(this.checkOutputs(outputs));
160
+ }
161
+ }
162
+ exports.CAT20Guard = CAT20Guard;
163
+ __decorate([
164
+ (0, scrypt_ts_opcat_1.method)(),
165
+ __metadata("design:type", Function),
166
+ __metadata("design:paramtypes", [Object, Object, Object, Object, Object, Object, BigInt]),
167
+ __metadata("design:returntype", void 0)
168
+ ], CAT20Guard.prototype, "unlock", null);
169
+ //# sourceMappingURL=cat20Guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat20Guard.js","sourceRoot":"","sources":["../../../../src/contracts/cat20/cat20Guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAYoC;AACpC,4CAOqB;AAErB,gDAA4C;AAC5C,6DAAyD;AAEzD,mDAA+C;AAE/C,MAAa,UAAW,SAAQ,+BAAmC;IAExD,MAAM,CACT,eAA4B;IAC5B,2DAA2D;IAC3D,4EAA4E;IAC5E,iEAAiE;IACjE,uBAA2E;IAC3E,2DAA2D;IAC3D,yEAAyE;IACzE,uCAAuC;IACvC,YAAkE;IAClE,2DAA2D;IAC3D,2BAA2B;IAC3B,yFAAyF;IACzF,wCAAwC;IACxC,iGAAiG;IACjG,sBAGC;IACD,wEAAwE;IACxE,cAA8D;IAC9D,wBAAwB;IACxB,oEAAoE;IACpE,oDAAoD;IACpD,WAA8D;IAC9D,oEAAoE;IACpE,WAAmB;QAEnB,uCAAuC;QAEvC,uCAAkB,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEhD,qDAAqD;QACrD,IAAI,eAAe,GAAG,EAAE,CAAA;QACxB,MAAM,uBAAuB,GAGzB;YACI,wBAAY,CAAC,gCAAgC;YAC7C,wBAAY,CAAC,gCAAgC;YAC7C,wBAAY,CAAC,gCAAgC;YAC7C,wBAAY,CAAC,gCAAgC;SAChD,CAAA;QACL,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gCAAoB,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5C,IAAI,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,uBAAuB,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChE,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,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;YACvD,IAAA,wBAAM,EACF,cAAc,CAAC,CAAC,CAAC;gBACjB,mBAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CACnE,CAAA;YACD,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,CAAC,EAAE,CAAC;gBAC9B,IAAA,wBAAM,EAAC,cAAc,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;YAClC,CAAC;iBAAM,CAAC;gBACJ,IAAA,wBAAM,EAAC,cAAc,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;gBAC/B,IAAA,wBAAM,EAAC,eAAe,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;gBAChC,sFAAsF;gBACtF,IAAA,wBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;gBACxC,IAAA,wBAAM,EAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;YAChD,CAAC;QACL,CAAC;QAED,wBAAwB;QACxB,IAAA,wBAAM,EAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IACtC,CAAC;CACJ;AAhLD,gCAgLC;AA9KU;IADN,IAAA,wBAAM,GAAE;;;;wCA8KR"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CAT20GuardStateLib = void 0;
13
+ const scrypt_ts_opcat_1 = require("@opcat-labs/scrypt-ts-opcat");
14
+ const constants_1 = require("../constants");
15
+ class CAT20GuardStateLib extends scrypt_ts_opcat_1.StateLib {
16
+ static formalCheckState(_state) {
17
+ CAT20GuardStateLib.checkTokenScriptsUniq(_state.tokenScriptHashes);
18
+ for (let i = 0; i < constants_1.GUARD_TOKEN_TYPE_MAX; i++) {
19
+ const scriptLen = (0, scrypt_ts_opcat_1.len)(_state.tokenScriptHashes[i]);
20
+ (0, scrypt_ts_opcat_1.assert)(scriptLen == scrypt_ts_opcat_1.SHA256_HASH_LEN);
21
+ (0, scrypt_ts_opcat_1.assert)(_state.tokenAmounts[i] >= 0);
22
+ (0, scrypt_ts_opcat_1.assert)(_state.tokenBurnAmounts[i] >= 0);
23
+ }
24
+ for (let i = 0; i < constants_1.TX_INPUT_COUNT_MAX; i++) {
25
+ const scriptIndex = _state.tokenScriptIndexes[i];
26
+ (0, scrypt_ts_opcat_1.assert)(scriptIndex >= -1 && scriptIndex < constants_1.GUARD_TOKEN_TYPE_MAX);
27
+ }
28
+ // return CAT20GuardProto.stateHash(_state)
29
+ return (0, scrypt_ts_opcat_1.toByteString)('');
30
+ }
31
+ /**
32
+ * Ensure tokenScripts does not have duplicate values
33
+ * @param tokenScripts token scripts
34
+ */
35
+ static checkTokenScriptsUniq(tokenScripts) {
36
+ // c42
37
+ (0, scrypt_ts_opcat_1.assert)(tokenScripts[0] != tokenScripts[1]);
38
+ (0, scrypt_ts_opcat_1.assert)(tokenScripts[0] != tokenScripts[2]);
39
+ (0, scrypt_ts_opcat_1.assert)(tokenScripts[0] != tokenScripts[3]);
40
+ (0, scrypt_ts_opcat_1.assert)(tokenScripts[1] != tokenScripts[2]);
41
+ (0, scrypt_ts_opcat_1.assert)(tokenScripts[1] != tokenScripts[3]);
42
+ (0, scrypt_ts_opcat_1.assert)(tokenScripts[2] != tokenScripts[3]);
43
+ }
44
+ static createEmptyState() {
45
+ const tokenScriptHashes = (0, scrypt_ts_opcat_1.fill)((0, scrypt_ts_opcat_1.toByteString)(''), constants_1.GUARD_TOKEN_TYPE_MAX);
46
+ // default value to ensure the uniqueness of token scripts
47
+ tokenScriptHashes[0] = constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FF;
48
+ tokenScriptHashes[1] = constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FE;
49
+ tokenScriptHashes[2] = constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FD;
50
+ tokenScriptHashes[3] = constants_1.ConstantsLib.TOKEN_SCRIPT_HASH_PLACEHOLDER_FC;
51
+ return {
52
+ tokenScriptHashes: tokenScriptHashes,
53
+ tokenAmounts: (0, scrypt_ts_opcat_1.fill)(0n, constants_1.GUARD_TOKEN_TYPE_MAX),
54
+ tokenBurnAmounts: (0, scrypt_ts_opcat_1.fill)(0n, constants_1.GUARD_TOKEN_TYPE_MAX),
55
+ tokenScriptIndexes: (0, scrypt_ts_opcat_1.fill)(-1n, constants_1.TX_INPUT_COUNT_MAX),
56
+ };
57
+ }
58
+ }
59
+ exports.CAT20GuardStateLib = CAT20GuardStateLib;
60
+ __decorate([
61
+ (0, scrypt_ts_opcat_1.method)(),
62
+ __metadata("design:type", Function),
63
+ __metadata("design:paramtypes", [Object]),
64
+ __metadata("design:returntype", String)
65
+ ], CAT20GuardStateLib, "formalCheckState", null);
66
+ __decorate([
67
+ (0, scrypt_ts_opcat_1.method)(),
68
+ __metadata("design:type", Function),
69
+ __metadata("design:paramtypes", [Object]),
70
+ __metadata("design:returntype", void 0)
71
+ ], CAT20GuardStateLib, "checkTokenScriptsUniq", null);
72
+ //# sourceMappingURL=cat20GuardStateLib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat20GuardStateLib.js","sourceRoot":"","sources":["../../../../src/contracts/cat20/cat20GuardStateLib.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAyI;AAEzI,4CAA2G;AAG3G,MAAa,kBAAmB,SAAQ,0BAA8B;IAG7D,AAAP,MAAM,CAAC,gBAAgB,CAAC,MAA4B;QAClD,kBAAkB,CAAC,qBAAqB,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;QAElE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gCAAoB,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,MAAM,SAAS,GAAG,IAAA,qBAAG,EAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;YAClD,IAAA,wBAAM,EAAC,SAAS,IAAI,iCAAe,CAAC,CAAA;YAEpC,IAAA,wBAAM,EAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;YACnC,IAAA,wBAAM,EAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QACzC,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,8BAAkB,EAAE,CAAC,EAAE,EAAE,CAAC;YAE5C,MAAM,WAAW,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAA;YAChD,IAAA,wBAAM,EAAC,WAAW,IAAI,CAAC,CAAC,IAAI,WAAW,GAAG,gCAAoB,CAAC,CAAA;QACjE,CAAC;QACD,2CAA2C;QAC3C,OAAO,IAAA,8BAAY,EAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAGD;;;OAGG;IAEI,AAAP,MAAM,CAAC,qBAAqB,CAC1B,YAAiE;QAEjE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,CAAA;IACH,CAAC;CAEF;AAzDD,gDAyDC;AAtDQ;IADN,IAAA,wBAAM,GAAE;;;;gDAmBR;AAQM;IADN,IAAA,wBAAM,GAAE;;;;qDAWR"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CAT20StateLib = void 0;
13
+ const scrypt_ts_opcat_1 = require("@opcat-labs/scrypt-ts-opcat");
14
+ const ownerUtils_1 = require("../utils/ownerUtils");
15
+ const constants_1 = require("../constants");
16
+ class CAT20StateLib extends scrypt_ts_opcat_1.StateLib {
17
+ static checkState(_state) {
18
+ ownerUtils_1.OwnerUtils.checkOwnerAddr(_state.ownerAddr);
19
+ (0, scrypt_ts_opcat_1.assert)(_state.amount > 0n, 'token amount should be non-negative');
20
+ (0, scrypt_ts_opcat_1.assert)(_state.tag == constants_1.ConstantsLib.OPCAT_CAT20_TAG, 'invalid tag');
21
+ }
22
+ static create(amount, address) {
23
+ return {
24
+ tag: constants_1.ConstantsLib.OPCAT_CAT20_TAG,
25
+ amount,
26
+ ownerAddr: address,
27
+ };
28
+ }
29
+ }
30
+ exports.CAT20StateLib = CAT20StateLib;
31
+ __decorate([
32
+ (0, scrypt_ts_opcat_1.method)(),
33
+ __metadata("design:type", Function),
34
+ __metadata("design:paramtypes", [Object]),
35
+ __metadata("design:returntype", void 0)
36
+ ], CAT20StateLib, "checkState", null);
37
+ //# sourceMappingURL=cat20StateLib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cat20StateLib.js","sourceRoot":"","sources":["../../../../src/contracts/cat20/cat20StateLib.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAmF;AAEnF,oDAAiD;AACjD,4CAA4C;AAE5C,MAAa,aAAc,SAAQ,0BAAoB;IAE5C,AAAP,MAAM,CAAC,UAAU,CAAC,MAAkB;QAChC,uBAAU,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAA,wBAAM,EAAC,MAAM,CAAC,MAAM,GAAG,EAAE,EAAE,qCAAqC,CAAC,CAAC;QAClE,IAAA,wBAAM,EAAC,MAAM,CAAC,GAAG,IAAI,wBAAY,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,MAAoB,EAAE,OAAmB;QACnD,OAAO;YACH,GAAG,EAAE,wBAAY,CAAC,eAAe;YACjC,MAAM;YACN,SAAS,EAAE,OAAO;SACrB,CAAA;IACL,CAAC;CACJ;AAfD,sCAeC;AAbU;IADN,IAAA,wBAAM,GAAE;;;;qCAKR"}