@algorandfoundation/algokit-utils 10.0.0-alpha.1 → 10.0.0-alpha.10

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 (316) hide show
  1. package/README.md +27 -5
  2. package/_virtual/rolldown_runtime.js +20 -11
  3. package/_virtual/rolldown_runtime.mjs +10 -5
  4. package/algo25/index.d.ts +2 -0
  5. package/algo25/index.js +9 -0
  6. package/algo25/index.mjs +3 -0
  7. package/algod-client/index.d.ts +2 -5
  8. package/package.json +1 -1
  9. package/packages/abi/src/abi-method.d.ts +1 -1
  10. package/packages/abi/src/abi-method.js.map +1 -1
  11. package/packages/abi/src/abi-method.mjs.map +1 -1
  12. package/packages/abi/src/abi-type.d.ts +1 -1
  13. package/packages/abi/src/abi-type.js +2 -1
  14. package/packages/abi/src/abi-type.js.map +1 -1
  15. package/packages/abi/src/abi-type.mjs +2 -1
  16. package/packages/abi/src/abi-type.mjs.map +1 -1
  17. package/packages/abi/src/arc56-contract.js +1 -0
  18. package/packages/abi/src/arc56-contract.js.map +1 -1
  19. package/packages/abi/src/arc56-contract.mjs +1 -0
  20. package/packages/abi/src/arc56-contract.mjs.map +1 -1
  21. package/packages/algo25/src/english.js.map +1 -1
  22. package/packages/algo25/src/english.mjs.map +1 -1
  23. package/packages/algo25/src/index.d.ts +40 -0
  24. package/packages/algo25/src/index.js +44 -0
  25. package/packages/algo25/src/index.js.map +1 -1
  26. package/packages/algo25/src/index.mjs +39 -1
  27. package/packages/algo25/src/index.mjs.map +1 -1
  28. package/packages/algod_client/src/apis/api-service.d.ts +44 -44
  29. package/packages/algod_client/src/apis/api-service.js +153 -153
  30. package/packages/algod_client/src/apis/api-service.js.map +1 -1
  31. package/packages/algod_client/src/apis/api-service.mjs +153 -153
  32. package/packages/algod_client/src/apis/api-service.mjs.map +1 -1
  33. package/packages/algod_client/src/core/api-error.js +3 -1
  34. package/packages/algod_client/src/core/api-error.js.map +1 -1
  35. package/packages/algod_client/src/core/api-error.mjs +3 -1
  36. package/packages/algod_client/src/core/api-error.mjs.map +1 -1
  37. package/packages/algod_client/src/core/model-runtime.js +4 -4
  38. package/packages/algod_client/src/core/model-runtime.js.map +1 -1
  39. package/packages/algod_client/src/core/model-runtime.mjs +6 -6
  40. package/packages/algod_client/src/core/model-runtime.mjs.map +1 -1
  41. package/packages/algod_client/src/models/account-participation.js +4 -4
  42. package/packages/algod_client/src/models/account-participation.js.map +1 -1
  43. package/packages/algod_client/src/models/account-participation.mjs +4 -4
  44. package/packages/algod_client/src/models/account-participation.mjs.map +1 -1
  45. package/packages/algod_client/src/models/application-state-schema.d.ts +2 -2
  46. package/packages/algod_client/src/models/application-state-schema.js +2 -2
  47. package/packages/algod_client/src/models/application-state-schema.js.map +1 -1
  48. package/packages/algod_client/src/models/application-state-schema.mjs +2 -2
  49. package/packages/algod_client/src/models/application-state-schema.mjs.map +1 -1
  50. package/packages/algod_client/src/models/asset-params.js +2 -1
  51. package/packages/algod_client/src/models/asset-params.js.map +1 -1
  52. package/packages/algod_client/src/models/asset-params.mjs +2 -1
  53. package/packages/algod_client/src/models/asset-params.mjs.map +1 -1
  54. package/packages/algod_client/src/models/block-response.js +1 -2
  55. package/packages/algod_client/src/models/block-response.js.map +1 -1
  56. package/packages/algod_client/src/models/block-response.mjs +2 -3
  57. package/packages/algod_client/src/models/block-response.mjs.map +1 -1
  58. package/packages/algod_client/src/models/block.d.ts +49 -29
  59. package/packages/algod_client/src/models/block.js +174 -98
  60. package/packages/algod_client/src/models/block.js.map +1 -1
  61. package/packages/algod_client/src/models/block.mjs +174 -98
  62. package/packages/algod_client/src/models/block.mjs.map +1 -1
  63. package/packages/algod_client/src/models/ledger-state-delta.js +1 -1
  64. package/packages/algod_client/src/models/ledger-state-delta.js.map +1 -1
  65. package/packages/algod_client/src/models/ledger-state-delta.mjs +2 -2
  66. package/packages/algod_client/src/models/ledger-state-delta.mjs.map +1 -1
  67. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.d.ts +3 -5
  68. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.js +4 -6
  69. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.js.map +1 -1
  70. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.mjs +3 -5
  71. package/packages/algod_client/src/models/simulate-unnamed-resources-accessed.mjs.map +1 -1
  72. package/packages/algod_client/src/models/transaction-parameters-response.js +2 -2
  73. package/packages/algod_client/src/models/transaction-parameters-response.js.map +1 -1
  74. package/packages/algod_client/src/models/transaction-parameters-response.mjs +2 -2
  75. package/packages/algod_client/src/models/transaction-parameters-response.mjs.map +1 -1
  76. package/packages/common/src/address.js +0 -14
  77. package/packages/common/src/address.js.map +1 -1
  78. package/packages/common/src/address.mjs +1 -14
  79. package/packages/common/src/address.mjs.map +1 -1
  80. package/packages/common/src/codecs/composite/map.js +7 -4
  81. package/packages/common/src/codecs/composite/map.js.map +1 -1
  82. package/packages/common/src/codecs/composite/map.mjs +7 -4
  83. package/packages/common/src/codecs/composite/map.mjs.map +1 -1
  84. package/packages/common/src/codecs/composite/record.js +0 -1
  85. package/packages/common/src/codecs/composite/record.js.map +1 -1
  86. package/packages/common/src/codecs/primitives/address.js +0 -1
  87. package/packages/common/src/codecs/primitives/address.js.map +1 -1
  88. package/packages/common/src/codecs/primitives/bytes.js +0 -1
  89. package/packages/common/src/codecs/primitives/bytes.js.map +1 -1
  90. package/packages/common/src/codecs/primitives/fixed-bytes.js +0 -1
  91. package/packages/common/src/codecs/primitives/fixed-bytes.js.map +1 -1
  92. package/packages/common/src/codecs/wire.js +0 -1
  93. package/packages/common/src/codecs/wire.js.map +1 -1
  94. package/packages/common/src/json.mjs +2 -2
  95. package/packages/common/src/json.mjs.map +1 -1
  96. package/packages/common/src/msgpack.js +0 -1
  97. package/packages/common/src/msgpack.js.map +1 -1
  98. package/packages/indexer_client/src/apis/api-service.d.ts +1 -1
  99. package/packages/indexer_client/src/apis/api-service.js +12 -12
  100. package/packages/indexer_client/src/apis/api-service.js.map +1 -1
  101. package/packages/indexer_client/src/apis/api-service.mjs +12 -12
  102. package/packages/indexer_client/src/apis/api-service.mjs.map +1 -1
  103. package/packages/indexer_client/src/core/api-error.js +3 -1
  104. package/packages/indexer_client/src/core/api-error.js.map +1 -1
  105. package/packages/indexer_client/src/core/api-error.mjs +3 -1
  106. package/packages/indexer_client/src/core/api-error.mjs.map +1 -1
  107. package/packages/indexer_client/src/core/model-runtime.js +4 -4
  108. package/packages/indexer_client/src/core/model-runtime.js.map +1 -1
  109. package/packages/indexer_client/src/core/model-runtime.mjs +6 -6
  110. package/packages/indexer_client/src/core/model-runtime.mjs.map +1 -1
  111. package/packages/indexer_client/src/models/account-participation.js +4 -4
  112. package/packages/indexer_client/src/models/account-participation.js.map +1 -1
  113. package/packages/indexer_client/src/models/account-participation.mjs +4 -4
  114. package/packages/indexer_client/src/models/account-participation.mjs.map +1 -1
  115. package/packages/indexer_client/src/models/application-state-schema.d.ts +2 -2
  116. package/packages/indexer_client/src/models/application-state-schema.js +2 -2
  117. package/packages/indexer_client/src/models/application-state-schema.js.map +1 -1
  118. package/packages/indexer_client/src/models/application-state-schema.mjs +2 -2
  119. package/packages/indexer_client/src/models/application-state-schema.mjs.map +1 -1
  120. package/packages/indexer_client/src/models/asset-params.js +2 -1
  121. package/packages/indexer_client/src/models/asset-params.js.map +1 -1
  122. package/packages/indexer_client/src/models/asset-params.mjs +2 -1
  123. package/packages/indexer_client/src/models/asset-params.mjs.map +1 -1
  124. package/packages/indexer_client/src/models/block.js +8 -8
  125. package/packages/indexer_client/src/models/block.js.map +1 -1
  126. package/packages/indexer_client/src/models/block.mjs +8 -8
  127. package/packages/indexer_client/src/models/block.mjs.map +1 -1
  128. package/packages/indexer_client/src/models/eval-delta-key-value.d.ts +1 -1
  129. package/packages/indexer_client/src/models/eval-delta-key-value.js +2 -2
  130. package/packages/indexer_client/src/models/eval-delta-key-value.js.map +1 -1
  131. package/packages/indexer_client/src/models/eval-delta-key-value.mjs +2 -2
  132. package/packages/indexer_client/src/models/eval-delta-key-value.mjs.map +1 -1
  133. package/packages/indexer_client/src/models/eval-delta.d.ts +1 -1
  134. package/packages/indexer_client/src/models/eval-delta.js +2 -2
  135. package/packages/indexer_client/src/models/eval-delta.js.map +1 -1
  136. package/packages/indexer_client/src/models/eval-delta.mjs +2 -2
  137. package/packages/indexer_client/src/models/eval-delta.mjs.map +1 -1
  138. package/packages/indexer_client/src/models/hb-proof-fields.js +6 -6
  139. package/packages/indexer_client/src/models/hb-proof-fields.js.map +1 -1
  140. package/packages/indexer_client/src/models/hb-proof-fields.mjs +6 -6
  141. package/packages/indexer_client/src/models/hb-proof-fields.mjs.map +1 -1
  142. package/packages/indexer_client/src/models/state-proof-verifier.js +2 -2
  143. package/packages/indexer_client/src/models/state-proof-verifier.js.map +1 -1
  144. package/packages/indexer_client/src/models/state-proof-verifier.mjs +2 -2
  145. package/packages/indexer_client/src/models/state-proof-verifier.mjs.map +1 -1
  146. package/packages/indexer_client/src/models/state-schema.d.ts +2 -2
  147. package/packages/indexer_client/src/models/state-schema.js +2 -2
  148. package/packages/indexer_client/src/models/state-schema.js.map +1 -1
  149. package/packages/indexer_client/src/models/state-schema.mjs +2 -2
  150. package/packages/indexer_client/src/models/state-schema.mjs.map +1 -1
  151. package/packages/indexer_client/src/models/teal-key-value.d.ts +1 -1
  152. package/packages/indexer_client/src/models/teal-key-value.js +2 -2
  153. package/packages/indexer_client/src/models/teal-key-value.js.map +1 -1
  154. package/packages/indexer_client/src/models/teal-key-value.mjs +2 -2
  155. package/packages/indexer_client/src/models/teal-key-value.mjs.map +1 -1
  156. package/packages/indexer_client/src/models/transaction-heartbeat.js +2 -1
  157. package/packages/indexer_client/src/models/transaction-heartbeat.js.map +1 -1
  158. package/packages/indexer_client/src/models/transaction-heartbeat.mjs +2 -1
  159. package/packages/indexer_client/src/models/transaction-heartbeat.mjs.map +1 -1
  160. package/packages/indexer_client/src/models/transaction-keyreg.js +4 -4
  161. package/packages/indexer_client/src/models/transaction-keyreg.js.map +1 -1
  162. package/packages/indexer_client/src/models/transaction-keyreg.mjs +4 -4
  163. package/packages/indexer_client/src/models/transaction-keyreg.mjs.map +1 -1
  164. package/packages/indexer_client/src/models/transaction-signature-logicsig.js +2 -1
  165. package/packages/indexer_client/src/models/transaction-signature-logicsig.js.map +1 -1
  166. package/packages/indexer_client/src/models/transaction-signature-logicsig.mjs +2 -1
  167. package/packages/indexer_client/src/models/transaction-signature-logicsig.mjs.map +1 -1
  168. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.js +3 -3
  169. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.js.map +1 -1
  170. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.mjs +3 -3
  171. package/packages/indexer_client/src/models/transaction-signature-multisig-subsignature.mjs.map +1 -1
  172. package/packages/indexer_client/src/models/transaction.d.ts +2 -2
  173. package/packages/indexer_client/src/models/transaction.js +6 -5
  174. package/packages/indexer_client/src/models/transaction.js.map +1 -1
  175. package/packages/indexer_client/src/models/transaction.mjs +6 -5
  176. package/packages/indexer_client/src/models/transaction.mjs.map +1 -1
  177. package/packages/kmd_client/src/apis/api-service.d.ts +5 -5
  178. package/packages/kmd_client/src/apis/api-service.js +32 -32
  179. package/packages/kmd_client/src/apis/api-service.js.map +1 -1
  180. package/packages/kmd_client/src/apis/api-service.mjs +32 -32
  181. package/packages/kmd_client/src/apis/api-service.mjs.map +1 -1
  182. package/packages/kmd_client/src/core/api-error.js +3 -1
  183. package/packages/kmd_client/src/core/api-error.js.map +1 -1
  184. package/packages/kmd_client/src/core/api-error.mjs +3 -1
  185. package/packages/kmd_client/src/core/api-error.mjs.map +1 -1
  186. package/packages/kmd_client/src/core/model-runtime.js +4 -4
  187. package/packages/kmd_client/src/core/model-runtime.js.map +1 -1
  188. package/packages/kmd_client/src/core/model-runtime.mjs +6 -6
  189. package/packages/kmd_client/src/core/model-runtime.mjs.map +1 -1
  190. package/packages/sdk/src/encoding/encoding.js +12 -2
  191. package/packages/sdk/src/encoding/encoding.js.map +1 -1
  192. package/packages/sdk/src/encoding/encoding.mjs +12 -1
  193. package/packages/sdk/src/encoding/encoding.mjs.map +1 -1
  194. package/packages/sdk/src/encoding/schema/map.js +0 -2
  195. package/packages/sdk/src/encoding/schema/map.js.map +1 -1
  196. package/packages/sdk/src/utils/utils.mjs +2 -2
  197. package/packages/sdk/src/utils/utils.mjs.map +1 -1
  198. package/packages/transact/src/logicsig.d.ts +3 -15
  199. package/packages/transact/src/logicsig.js +16 -36
  200. package/packages/transact/src/logicsig.js.map +1 -1
  201. package/packages/transact/src/logicsig.mjs +18 -36
  202. package/packages/transact/src/logicsig.mjs.map +1 -1
  203. package/packages/transact/src/multisig.d.ts +7 -115
  204. package/packages/transact/src/multisig.js +86 -136
  205. package/packages/transact/src/multisig.js.map +1 -1
  206. package/packages/transact/src/multisig.mjs +87 -117
  207. package/packages/transact/src/multisig.mjs.map +1 -1
  208. package/packages/transact/src/transactions/app-call.d.ts +10 -10
  209. package/packages/transact/src/transactions/app-call.js.map +1 -1
  210. package/packages/transact/src/transactions/app-call.mjs.map +1 -1
  211. package/packages/transact/src/transactions/reference-types-meta.d.ts +26 -0
  212. package/packages/transact/src/transactions/reference-types-meta.js +71 -0
  213. package/packages/transact/src/transactions/reference-types-meta.js.map +1 -0
  214. package/packages/transact/src/transactions/reference-types-meta.mjs +69 -0
  215. package/packages/transact/src/transactions/reference-types-meta.mjs.map +1 -0
  216. package/packages/transact/src/transactions/signed-transaction-meta.js +2 -3
  217. package/packages/transact/src/transactions/signed-transaction-meta.js.map +1 -1
  218. package/packages/transact/src/transactions/signed-transaction-meta.mjs +3 -3
  219. package/packages/transact/src/transactions/signed-transaction-meta.mjs.map +1 -1
  220. package/packages/transact/src/transactions/signed-transaction.d.ts +2 -2
  221. package/packages/transact/src/transactions/signed-transaction.js.map +1 -1
  222. package/packages/transact/src/transactions/signed-transaction.mjs.map +1 -1
  223. package/packages/transact/src/transactions/transaction-meta.js +29 -23
  224. package/packages/transact/src/transactions/transaction-meta.js.map +1 -1
  225. package/packages/transact/src/transactions/transaction-meta.mjs +29 -23
  226. package/packages/transact/src/transactions/transaction-meta.mjs.map +1 -1
  227. package/packages/transact/src/transactions/transaction.js +1 -0
  228. package/packages/transact/src/transactions/transaction.js.map +1 -1
  229. package/packages/transact/src/transactions/transaction.mjs +1 -0
  230. package/packages/transact/src/transactions/transaction.mjs.map +1 -1
  231. package/sdk/index.js +1 -1
  232. package/testing/fixtures/algorand-fixture.d.ts +3 -3
  233. package/testing/fixtures/algorand-fixture.js.map +1 -1
  234. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  235. package/transact/index.d.ts +5 -4
  236. package/transact/index.js +4 -22
  237. package/transact/index.mjs +4 -3
  238. package/transaction/transaction.js +2 -2
  239. package/transaction/transaction.js.map +1 -1
  240. package/transaction/transaction.mjs +2 -2
  241. package/transaction/transaction.mjs.map +1 -1
  242. package/transactions/app-call.d.ts +4 -3
  243. package/transactions/app-call.js +15 -15
  244. package/transactions/app-call.js.map +1 -1
  245. package/transactions/app-call.mjs +15 -15
  246. package/transactions/app-call.mjs.map +1 -1
  247. package/transactions/asset-config.d.ts +1 -1
  248. package/transactions/asset-config.js +1 -1
  249. package/transactions/asset-config.js.map +1 -1
  250. package/transactions/asset-config.mjs +1 -1
  251. package/transactions/asset-config.mjs.map +1 -1
  252. package/transactions/method-call.js +12 -12
  253. package/transactions/method-call.js.map +1 -1
  254. package/transactions/method-call.mjs +12 -12
  255. package/transactions/method-call.mjs.map +1 -1
  256. package/types/account-manager.js +2 -2
  257. package/types/account-manager.js.map +1 -1
  258. package/types/account-manager.mjs +2 -2
  259. package/types/account-manager.mjs.map +1 -1
  260. package/types/algorand-client-transaction-creator.d.ts +97 -83
  261. package/types/algorand-client-transaction-creator.js +8 -0
  262. package/types/algorand-client-transaction-creator.js.map +1 -1
  263. package/types/algorand-client-transaction-creator.mjs +8 -0
  264. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  265. package/types/algorand-client-transaction-sender.d.ts +100 -86
  266. package/types/algorand-client-transaction-sender.js +8 -1
  267. package/types/algorand-client-transaction-sender.js.map +1 -1
  268. package/types/algorand-client-transaction-sender.mjs +8 -0
  269. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  270. package/types/app-client.d.ts +265 -260
  271. package/types/app-client.js +0 -1
  272. package/types/app-client.js.map +1 -1
  273. package/types/app-deployer.js +1 -1
  274. package/types/app-deployer.js.map +1 -1
  275. package/types/app-deployer.mjs +1 -1
  276. package/types/app-deployer.mjs.map +1 -1
  277. package/types/app-factory.d.ts +91 -88
  278. package/types/app-manager.d.ts +3 -1
  279. package/types/app-manager.js +16 -10
  280. package/types/app-manager.js.map +1 -1
  281. package/types/app-manager.mjs +16 -10
  282. package/types/app-manager.mjs.map +1 -1
  283. package/types/app-spec.js +12 -5
  284. package/types/app-spec.js.map +1 -1
  285. package/types/app-spec.mjs +12 -5
  286. package/types/app-spec.mjs.map +1 -1
  287. package/types/asset-manager.js +1 -1
  288. package/types/asset-manager.js.map +1 -1
  289. package/types/asset-manager.mjs +1 -1
  290. package/types/asset-manager.mjs.map +1 -1
  291. package/types/composer.d.ts +9 -0
  292. package/types/composer.js +28 -13
  293. package/types/composer.js.map +1 -1
  294. package/types/composer.mjs +28 -12
  295. package/types/composer.mjs.map +1 -1
  296. package/types/kmd-account-manager.d.ts +1 -0
  297. package/types/kmd-account-manager.js +21 -10
  298. package/types/kmd-account-manager.js.map +1 -1
  299. package/types/kmd-account-manager.mjs +22 -11
  300. package/types/kmd-account-manager.mjs.map +1 -1
  301. package/types/testing.d.ts +2 -2
  302. package/packages/algod_client/src/models/application-local-reference.d.ts +0 -20
  303. package/packages/algod_client/src/models/application-local-reference.js +0 -23
  304. package/packages/algod_client/src/models/application-local-reference.js.map +0 -1
  305. package/packages/algod_client/src/models/application-local-reference.mjs +0 -23
  306. package/packages/algod_client/src/models/application-local-reference.mjs.map +0 -1
  307. package/packages/algod_client/src/models/asset-holding-reference.d.ts +0 -20
  308. package/packages/algod_client/src/models/asset-holding-reference.js +0 -23
  309. package/packages/algod_client/src/models/asset-holding-reference.js.map +0 -1
  310. package/packages/algod_client/src/models/asset-holding-reference.mjs +0 -23
  311. package/packages/algod_client/src/models/asset-holding-reference.mjs.map +0 -1
  312. package/packages/algod_client/src/models/box-reference.d.ts +0 -17
  313. package/packages/algod_client/src/models/box-reference.js +0 -23
  314. package/packages/algod_client/src/models/box-reference.js.map +0 -1
  315. package/packages/algod_client/src/models/box-reference.mjs +0 -23
  316. package/packages/algod_client/src/models/box-reference.mjs.map +0 -1
package/README.md CHANGED
@@ -52,17 +52,33 @@ This is an open source project managed by the Algorand Foundation. See the [Algo
52
52
 
53
53
  To successfully run the tests in this repository you need to be running LocalNet via [AlgoKit](https://github.com/algorandfoundation/algokit-cli) and also have package dependencies and `.env.template` copied to `.env` (both of which `algokit bootstrap all` can do for you):
54
54
 
55
- ```
55
+ ```bash
56
56
  algokit bootstrap all
57
57
  algokit localnet start
58
58
  ```
59
59
 
60
60
  To run tests you can use VS Code, or:
61
61
 
62
- ```
62
+ ```bash
63
63
  npm run test
64
64
  ```
65
65
 
66
+ ### Prerequisites
67
+
68
+ - [Rust](https://rust-lang.org/tools/install/) - Required for building native dependencies
69
+ - [Bun](https://bun.sh/docs/installation) - JavaScript runtime and package manager
70
+ - [Polytest](https://github.com/algorandfoundation/algokit-polytest) - Install via Cargo:
71
+
72
+ ```bash
73
+ cargo install polytest
74
+ ```
75
+
76
+ To update to a specific version if required:
77
+
78
+ ```bash
79
+ cargo install polytest --version {X}
80
+ ```
81
+
66
82
  ### Mock Server for Client Tests
67
83
 
68
84
  The `algod_client`, `indexer_client`, and `kmd_client` packages use a mock server for deterministic API testing against pre-recorded HAR files. The mock server is managed externally (not by the test framework).
@@ -71,7 +87,13 @@ The `algod_client`, `indexer_client`, and `kmd_client` packages use a mock serve
71
87
 
72
88
  **Local development:**
73
89
 
74
- 1. Clone algokit-polytest and start the mock servers:
90
+ 1. Init algokit-polytest on first run
91
+
92
+ ```bash
93
+ npm run polytest:init
94
+ ```
95
+
96
+ 2. Start the mock servers:
75
97
 
76
98
  ```bash
77
99
  npm run polytest:start-mock-servers
@@ -79,7 +101,7 @@ npm run polytest:start-mock-servers
79
101
 
80
102
  This starts algod (port 8000), indexer (port 8002), and kmd (port 8001) in the background.
81
103
 
82
- 2. Set environment variables and run tests.
104
+ 3. Set environment variables and run tests.
83
105
 
84
106
  | Environment Variable | Description | Default Port |
85
107
  | -------------------- | ----------------------- | ------------ |
@@ -94,7 +116,7 @@ Environment variables can also be set via `.env` file in project root (copy from
94
116
  npm run test
95
117
  ```
96
118
 
97
- 3. Stop servers when done:
119
+ 4. Stop servers when done:
98
120
 
99
121
  ```bash
100
122
  npm run polytest:stop-mock-servers
@@ -5,21 +5,30 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (all) => {
8
+ var __export = (all, symbols) => {
9
9
  let target = {};
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ }
16
+ if (symbols) {
17
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
18
+ }
14
19
  return target;
15
20
  };
16
21
  var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
18
- key = keys[i];
19
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
- get: ((k) => from[k]).bind(null, key),
21
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
- });
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
+ key = keys[i];
25
+ if (!__hasOwnProp.call(to, key) && key !== except) {
26
+ __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ }
23
32
  }
24
33
  return to;
25
34
  };
@@ -1,11 +1,16 @@
1
1
  //#region rolldown:runtime
2
2
  var __defProp = Object.defineProperty;
3
- var __export = (all) => {
3
+ var __export = (all, symbols) => {
4
4
  let target = {};
5
- for (var name in all) __defProp(target, name, {
6
- get: all[name],
7
- enumerable: true
8
- });
5
+ for (var name in all) {
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ }
11
+ if (symbols) {
12
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
13
+ }
9
14
  return target;
10
15
  };
11
16
 
@@ -0,0 +1,2 @@
1
+ import { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic } from "../packages/algo25/src/index.js";
2
+ export { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic };
@@ -0,0 +1,9 @@
1
+ const require_index = require('../packages/algo25/src/index.js');
2
+
3
+ exports.FAIL_TO_DECODE_MNEMONIC_ERROR_MSG = require_index.FAIL_TO_DECODE_MNEMONIC_ERROR_MSG;
4
+ exports.NOT_IN_WORDS_LIST_ERROR_MSG = require_index.NOT_IN_WORDS_LIST_ERROR_MSG;
5
+ exports.masterDerivationKeyToMnemonic = require_index.masterDerivationKeyToMnemonic;
6
+ exports.mnemonicFromSeed = require_index.mnemonicFromSeed;
7
+ exports.mnemonicToMasterDerivationKey = require_index.mnemonicToMasterDerivationKey;
8
+ exports.secretKeyToMnemonic = require_index.secretKeyToMnemonic;
9
+ exports.seedFromMnemonic = require_index.seedFromMnemonic;
@@ -0,0 +1,3 @@
1
+ import { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic } from "../packages/algo25/src/index.mjs";
2
+
3
+ export { FAIL_TO_DECODE_MNEMONIC_ERROR_MSG, NOT_IN_WORDS_LIST_ERROR_MSG, masterDerivationKeyToMnemonic, mnemonicFromSeed, mnemonicToMasterDerivationKey, secretKeyToMnemonic, seedFromMnemonic };
@@ -5,7 +5,7 @@ import { ApiError } from "../packages/algod_client/src/core/api-error.js";
5
5
  import { decodeJson, decodeMsgpack, encodeJson, encodeMsgpack } from "../packages/algod_client/src/core/model-runtime.js";
6
6
  import { GenesisAllocation } from "../packages/algod_client/src/models/genesis-allocation.js";
7
7
  import { Genesis } from "../packages/algod_client/src/models/genesis.js";
8
- import { ApplyData, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHeader, BlockStateProofTrackingData, ParticipationUpdates, SignedTxnInBlock, SignedTxnWithAD } from "../packages/algod_client/src/models/block.js";
8
+ import { ApplyData, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHeader, BlockStateProofTrackingData, ParticipationUpdates, RewardState, SignedTxnInBlock, SignedTxnWithAD, TxnCommitments, UpgradeState, UpgradeVote } from "../packages/algod_client/src/models/block.js";
9
9
  import { LedgerStateDelta } from "../packages/algod_client/src/models/ledger-state-delta.js";
10
10
  import { LedgerStateDeltaForTransactionGroup } from "../packages/algod_client/src/models/ledger-state-delta-for-transaction-group.js";
11
11
  import { AccountParticipation } from "../packages/algod_client/src/models/account-participation.js";
@@ -20,8 +20,6 @@ import { AssetParams } from "../packages/algod_client/src/models/asset-params.js
20
20
  import { Asset } from "../packages/algod_client/src/models/asset.js";
21
21
  import { AssetHolding } from "../packages/algod_client/src/models/asset-holding.js";
22
22
  import { Account } from "../packages/algod_client/src/models/account.js";
23
- import { AssetHoldingReference } from "../packages/algod_client/src/models/asset-holding-reference.js";
24
- import { ApplicationLocalReference } from "../packages/algod_client/src/models/application-local-reference.js";
25
23
  import { AvmValue } from "../packages/algod_client/src/models/avm-value.js";
26
24
  import { AvmKeyValue } from "../packages/algod_client/src/models/avm-key-value.js";
27
25
  import { EvalDelta } from "../packages/algod_client/src/models/eval-delta.js";
@@ -33,7 +31,6 @@ import { SimulateTraceConfig } from "../packages/algod_client/src/models/simulat
33
31
  import { SimulateRequest } from "../packages/algod_client/src/models/simulate-request.js";
34
32
  import { Box } from "../packages/algod_client/src/models/box.js";
35
33
  import { BoxDescriptor } from "../packages/algod_client/src/models/box-descriptor.js";
36
- import { BoxReference } from "../packages/algod_client/src/models/box-reference.js";
37
34
  import { BuildVersion } from "../packages/algod_client/src/models/build-version.js";
38
35
  import { Version } from "../packages/algod_client/src/models/version.js";
39
36
  import { PendingTransactionResponse } from "../packages/algod_client/src/models/pending-transaction-response.js";
@@ -73,4 +70,4 @@ import { DisassembleResponse } from "../packages/algod_client/src/models/disasse
73
70
  import { SuggestedParams, SuggestedParamsMeta } from "../packages/algod_client/src/models/suggested-params.js";
74
71
  import { AlgodApi } from "../packages/algod_client/src/apis/api-service.js";
75
72
  import { AlgodClient } from "../packages/algod_client/src/client.js";
76
- export { Account, AccountApplicationResponse, AccountAssetResponse, AccountParticipation, AccountStateDelta, AlgodApi, AlgodClient, ApiError, ApiRequestOptions, Application, ApplicationInitialStates, ApplicationKvStorage, ApplicationLocalReference, ApplicationLocalState, ApplicationParams, ApplicationStateOperation, ApplicationStateSchema, ApplyData, Asset, AssetHolding, AssetHoldingReference, AssetParams, AvmKeyValue, AvmValue, BaseHttpRequest, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHashResponse, BlockHeader, BlockResponse, BlockStateProofTrackingData, BlockTxidsResponse, Box, BoxDescriptor, BoxReference, BoxesResponse, BuildVersion, ClientConfig, CompileResponse, DisassembleResponse, EvalDelta, EvalDeltaKeyValue, FetchHttpRequest, Genesis, GenesisAllocation, GetBlockTimeStampOffsetResponse, GetSyncRoundResponse, LedgerStateDelta, LedgerStateDeltaForTransactionGroup, LightBlockHeaderProof, NodeStatusResponse, ParticipationUpdates, PendingTransactionResponse, PendingTransactionsResponse, PostTransactionsResponse, ScratchChange, SignedTxnInBlock, SignedTxnWithAD, SimulateInitialStates, SimulateRequest, SimulateRequestTransactionGroup, SimulateResponse, SimulateTraceConfig, SimulateTransactionGroupResult, SimulateTransactionResult, SimulateUnnamedResourcesAccessed, SimulationEvalOverrides, SimulationOpcodeTraceUnit, SimulationTransactionExecTrace, SourceMap, StateDelta, StateProof, StateProofMessage, SuggestedParams, SuggestedParamsMeta, SupplyResponse, TealKeyValue, TealKeyValueStore, TealValue, TransactionGroupLedgerStateDeltasForRoundResponse, TransactionParametersResponse, TransactionProof, Version, decodeJson, decodeMsgpack, encodeJson, encodeMsgpack, inputValueAsString };
73
+ export { Account, AccountApplicationResponse, AccountAssetResponse, AccountParticipation, AccountStateDelta, AlgodApi, AlgodClient, ApiError, ApiRequestOptions, Application, ApplicationInitialStates, ApplicationKvStorage, ApplicationLocalState, ApplicationParams, ApplicationStateOperation, ApplicationStateSchema, ApplyData, Asset, AssetHolding, AssetParams, AvmKeyValue, AvmValue, BaseHttpRequest, Block, BlockAppEvalDelta, BlockEvalDelta, BlockHashResponse, BlockHeader, BlockResponse, BlockStateProofTrackingData, BlockTxidsResponse, Box, BoxDescriptor, BoxesResponse, BuildVersion, ClientConfig, CompileResponse, DisassembleResponse, EvalDelta, EvalDeltaKeyValue, FetchHttpRequest, Genesis, GenesisAllocation, GetBlockTimeStampOffsetResponse, GetSyncRoundResponse, LedgerStateDelta, LedgerStateDeltaForTransactionGroup, LightBlockHeaderProof, NodeStatusResponse, ParticipationUpdates, PendingTransactionResponse, PendingTransactionsResponse, PostTransactionsResponse, RewardState, ScratchChange, SignedTxnInBlock, SignedTxnWithAD, SimulateInitialStates, SimulateRequest, SimulateRequestTransactionGroup, SimulateResponse, SimulateTraceConfig, SimulateTransactionGroupResult, SimulateTransactionResult, SimulateUnnamedResourcesAccessed, SimulationEvalOverrides, SimulationOpcodeTraceUnit, SimulationTransactionExecTrace, SourceMap, StateDelta, StateProof, StateProofMessage, SuggestedParams, SuggestedParamsMeta, SupplyResponse, TealKeyValue, TealKeyValueStore, TealValue, TransactionGroupLedgerStateDeltasForRoundResponse, TransactionParametersResponse, TransactionProof, TxnCommitments, UpgradeState, UpgradeVote, Version, decodeJson, decodeMsgpack, encodeJson, encodeMsgpack, inputValueAsString };
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "**"
7
7
  ],
8
8
  "name": "@algorandfoundation/algokit-utils",
9
- "version": "10.0.0-alpha.1",
9
+ "version": "10.0.0-alpha.10",
10
10
  "private": false,
11
11
  "description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
12
12
  "author": "Algorand Foundation",
@@ -61,7 +61,7 @@ type ABIReturn = {
61
61
  rawReturnValue?: undefined;
62
62
  returnValue?: undefined;
63
63
  method: ABIMethod;
64
- decodeError: Error;
64
+ decodeError?: Error;
65
65
  };
66
66
  declare class ABIMethod {
67
67
  readonly name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"abi-method.js","names":["sha512","parseTupleContent","ABIType","convertedDefaultValue: ABIDefaultValue | undefined","ABIStructType","ABIUintType","ABIAddressType"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB,MAAM,OAAO,KAAK,KACf,KAAK,QAAQ;AACZ,OAAI,qBAAqB,IAAI,KAAK,IAAI,mBAAmB,IAAI,KAAK,CAAE,QAAO,IAAI;AAC/E,UAAO,IAAI,KAAK;IAChB,CACD,KAAK,IAAI;AAEZ,SAAO,GAAG,KAAK,KAAK,GAAG,KAAK,GADZ,KAAK,QAAQ,SAAS,SAAS,SAAS,KAAK,QAAQ,KAAK;;;;;;CAQ5E,cAA0B;EACxB,MAAM,OAAOA,kBAAO,WAAW,MAAM,KAAK,cAAc,CAAC;AACzD,SAAO,IAAI,WAAW,KAAK,MAAM,GAAG,EAAE,CAAC;;;;;;;;CASzC,OAAO,cAAc,WAA8B;EACjD,MAAM,YAAY,UAAU,QAAQ,IA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6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAIG,6BAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAIC,iCAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
1
+ {"version":3,"file":"abi-method.js","names":["sha512","parseTupleContent","ABIType","convertedDefaultValue: ABIDefaultValue | undefined","ABIStructType","ABIUintType","ABIAddressType"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError?: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAA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"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB,MAAM,OAAO,KAAK,KACf,KAAK,QAAQ;AACZ,OAAI,qBAAqB,IAAI,KAAK,IAAI,mBAAmB,IAAI,KAAK,CAAE,QAAO,IAAI;AAC/E,UAAO,IAAI,KAAK;IAChB,CACD,KAAK,IAAI;AAEZ,SAAO,GAAG,KAAK,KAAK,GAAG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,YAClD,OAAM,IAAI,MAAM,8CAA8C,QAAQ;AACxE,UAAO;EACT,KAAK,YACH,QAAO,QAAQ,KAAK,SAAS,CAAC,OAAO,MAAM;;;AAIjD,SAAgB,UAAU,MAAgC;AACxD,QAAO,OAAO,SAAS,aAAa,SAAS,eAAe,SAAS,cAAc,SAAS;;AAG9F,SAAgB,mBAAmB,MAA4C,OAA6B;AAC1G,KAAI,SAAS,iBAAiB,SAAS,SAAS,iBAAiB,YAC/D,QAAO,IAAI,YAAY,GAAG,CAAC,OAAO,MAAM;UAC/B,SAAS,iBAAiB,QACnC,QAAO,IAAI,gBAAgB,CAAC,OAAO,MAAM;UAChC,UAAU,KAAK,CACxB,QAAO,eAAe,MAAM,MAAM;AAEpC,QAAO,KAAK,OAAO,MAAM;;AAG3B,SAAgB,mBAAmB,MAAyB,OAA6B;AACvF,QAAO,UAAU,KAAK,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
1
+ {"version":3,"file":"abi-method.mjs","names":["convertedDefaultValue: ABIDefaultValue | undefined"],"sources":["../../../../packages/abi/src/abi-method.ts"],"sourcesContent":["import sha512 from 'js-sha512'\nimport { ABIAddressType, ABIStructType, ABIType, ABIUintType, parseTupleContent } from './abi-type'\nimport { ABIValue } from './abi-value'\nimport { ARC28Event } from './arc28-event'\nimport { AVMType, Arc56Contract, Arc56Method } from './arc56-contract'\n\nexport enum ABITransactionType {\n Txn = 'txn',\n Payment = 'pay',\n KeyRegistration = 'keyreg',\n AssetConfig = 'acfg',\n AssetTransfer = 'axfer',\n AssetFreeze = 'afrz',\n AppCall = 'appl',\n}\nexport enum ABIReferenceType {\n Account = 'account',\n Application = 'application',\n Asset = 'asset',\n}\nexport type ABIMethodArgType = ABIType | ABITransactionType | ABIReferenceType\nexport type ABIMethodReturnType = ABIType | 'void'\n\nexport type ABIMethodArg = {\n type: ABIMethodArgType\n name?: string\n description?: string\n defaultValue?: ABIDefaultValue\n}\n\nexport type ABIMethodReturn = {\n type: ABIMethodReturnType\n description?: string\n}\n\nexport type ABIDefaultValue = {\n /** Base64 encoded bytes, base64 ARC4 encoded uint64, or UTF-8 method selector */\n data: string\n /** Where the default value is coming from */\n source: DefaultValueSource\n /** How the data is encoded. This is the encoding for the data provided here, not the arg type */\n type?: ABIType | AVMType\n}\n\nexport enum DefaultValueSource {\n Box = 'box',\n Global = 'global',\n Local = 'local',\n Literal = 'literal',\n Method = 'method',\n}\n\n/** Represents an ABI method return value with parsed data. */\nexport type ABIReturn =\n | {\n /** The method that was called. */\n method: ABIMethod\n /** The raw return value as bytes.\n *\n * This is the value from the last app call log with the first 4 bytes (the ABI return prefix) omitted.\n */\n rawReturnValue: Uint8Array\n /** The parsed ABI return value. */\n returnValue: ABIValue\n decodeError: undefined\n }\n | { rawReturnValue?: undefined; returnValue?: undefined; method: ABIMethod; decodeError?: Error }\n\n/** Decoded ARC-56 struct as a struct rather than a tuple. */\nexport type ABIStruct = {\n [key: string]: ABIStruct | ABIValue\n}\n\nexport class ABIMethod {\n readonly name: string\n readonly description?: string\n readonly args: ABIMethodArg[]\n readonly returns: ABIMethodReturn\n readonly events?: ARC28Event[]\n readonly readonly?: boolean\n\n constructor(params: {\n name: string\n description?: string\n args: ABIMethodArg[]\n returns: ABIMethodReturn\n events?: ARC28Event[]\n readonly?: boolean\n }) {\n this.name = params.name\n this.description = params.description\n this.args = params.args\n this.returns = params.returns\n this.events = params.events\n this.readonly = params.readonly\n }\n\n /**\n * Returns the signature of this ABI method.\n * @returns The signature, e.g. `my_method(unit64,string)bytes`\n */\n getSignature(): string {\n const args = this.args\n .map((arg) => {\n if (argTypeIsTransaction(arg.type) || argTypeIsReference(arg.type)) return arg.type\n return arg.type.name\n })\n .join(',')\n const returns = this.returns.type === 'void' ? 'void' : this.returns.type.name\n return `${this.name}(${args})${returns}`\n }\n\n /**\n * Returns the method selector of this ABI method.\n * @returns The 4-byte method selector\n */\n getSelector(): Uint8Array {\n const hash = sha512.sha512_256.array(this.getSignature())\n return new Uint8Array(hash.slice(0, 4))\n }\n\n /**\n * Returns the ABI method object for a given method signature.\n * @param signature The method signature\n * e.g. `my_method(unit64,string)bytes`\n * @returns The `ABIMethod`\n */\n static fromSignature(signature: string): ABIMethod {\n const argsStart = signature.indexOf('(')\n if (argsStart === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n let argsEnd = -1\n let depth = 0\n for (let i = argsStart; i < signature.length; i++) {\n const char = signature[i]\n\n if (char === '(') {\n depth += 1\n } else if (char === ')') {\n if (depth === 0) {\n // unpaired parenthesis\n break\n }\n\n depth -= 1\n if (depth === 0) {\n argsEnd = i\n break\n }\n }\n }\n\n if (argsEnd === -1) {\n throw new Error(`Invalid method signature: ${signature}`)\n }\n\n const name = signature.slice(0, argsStart)\n const args = parseTupleContent(signature.slice(argsStart + 1, argsEnd)).map((n: string) => {\n if (argTypeIsTransaction(n as ABIMethodArgType) || argTypeIsReference(n as ABIMethodArgType)) {\n return { type: n as ABIMethodArgType } satisfies ABIMethodArg\n }\n return { type: ABIType.from(n) } satisfies ABIMethodArg\n })\n const returnType = signature.slice(argsEnd + 1)\n const returns = { type: returnType === 'void' ? ('void' as const) : ABIType.from(returnType) } satisfies ABIMethodReturn\n\n return new ABIMethod({\n name,\n args,\n returns,\n })\n }\n}\n\n/**\n * Returns the ABI method object for a given method name or signature and ARC-56 app spec.\n * @param methodNameOrSignature The method name or method signature to call if an ABI call is being emitted.\n * e.g. `my_method` or `my_method(unit64,string)bytes`\n * @param appSpec The app spec for the app\n * @returns The `ABIMethod`\n */\nexport function getABIMethod(methodNameOrSignature: string, appSpec: Arc56Contract): ABIMethod {\n if (!methodNameOrSignature.includes('(')) {\n const methods = appSpec.methods.filter((m) => m.name === methodNameOrSignature)\n if (methods.length === 0) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n if (methods.length > 1) {\n throw new Error(\n `Received a call to method ${methodNameOrSignature} in contract ${\n appSpec.name\n }, but this resolved to multiple methods; please pass in an ABI signature instead: ${appSpec.methods\n .map((m) => getArc56MethodSignature(m))\n .join(', ')}`,\n )\n }\n return arc56MethodToABIMethod(methods[0], appSpec)\n } else {\n const method = appSpec.methods.find((m) => getArc56MethodSignature(m) === methodNameOrSignature)\n if (!method) throw new Error(`Unable to find method ${methodNameOrSignature} in ${appSpec.name} app.`)\n return arc56MethodToABIMethod(method, appSpec)\n }\n}\n\nexport function arc56MethodToABIMethod(method: Arc56Method, appSpec: Arc56Contract): ABIMethod {\n if (typeof method.name !== 'string' || typeof method.returns !== 'object' || !Array.isArray(method.args)) {\n throw new Error('Invalid ABIMethod parameters')\n }\n\n const args = method.args.map(({ type, name, desc, struct, defaultValue }) => {\n const convertedDefaultValue: ABIDefaultValue | undefined = defaultValue\n ? {\n data: defaultValue.data,\n source: defaultValue.source as DefaultValueSource,\n type: defaultValue.type ? (isAVMType(defaultValue.type) ? defaultValue.type : ABIType.from(defaultValue.type)) : undefined,\n }\n : undefined\n\n if (argTypeIsTransaction(type as ABIMethodArgType) || argTypeIsReference(type as ABIMethodArgType)) {\n return {\n type: type as ABIMethodArgType,\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n if (struct) {\n return {\n type: ABIStructType.fromStruct(struct, appSpec.structs),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n }\n\n return {\n type: ABIType.from(type),\n name,\n description: desc,\n defaultValue: convertedDefaultValue,\n } satisfies ABIMethodArg\n })\n\n const returns = {\n type:\n method.returns.type === ('void' as const)\n ? ('void' as const)\n : method.returns.struct\n ? ABIStructType.fromStruct(method.returns.struct, appSpec.structs)\n : ABIType.from(method.returns.type),\n desc: method.returns.desc,\n }\n\n return new ABIMethod({\n name: method.name,\n description: method.desc,\n args,\n returns,\n events: method.events,\n readonly: method.readonly,\n })\n}\n\nexport function argTypeIsTransaction(type: ABIMethodArgType): type is ABITransactionType {\n return (\n typeof type === 'string' &&\n (type === ABITransactionType.Txn ||\n type === ABITransactionType.Payment ||\n type === ABITransactionType.KeyRegistration ||\n type === ABITransactionType.AssetConfig ||\n type === ABITransactionType.AssetTransfer ||\n type === ABITransactionType.AssetFreeze ||\n type === ABITransactionType.AppCall)\n )\n}\n\nexport function argTypeIsReference(type: ABIMethodArgType): type is ABIReferenceType {\n return (\n typeof type === 'string' &&\n (type === ABIReferenceType.Account || type === ABIReferenceType.Application || type === ABIReferenceType.Asset)\n )\n}\n\nexport function argTypeIsAbiType(type: ABIMethodArgType): type is ABIType {\n return !argTypeIsTransaction(type) && !argTypeIsReference(type)\n}\n\nfunction getArc56MethodSignature(method: Arc56Method): string {\n const args = method.args.map((arg) => arg.type).join(',')\n const returns = method.returns.type\n return `${method.name}(${args})${returns}`\n}\n\nexport function decodeAVMValue(avmType: AVMType, bytes: Uint8Array): ABIValue {\n switch (avmType) {\n case 'AVMString':\n return Buffer.from(bytes).toString('utf-8')\n case 'AVMBytes':\n return bytes\n case 'AVMUint64':\n return ABIType.from('uint64').decode(bytes)\n }\n}\n\nexport function encodeAVMValue(avmType: AVMType, value: ABIValue): Uint8Array {\n switch (avmType) {\n case 'AVMString':\n return ABIType.from('string').encode(value)\n case 'AVMBytes':\n if (typeof value === 'string') return Buffer.from(value, 'utf-8')\n if (typeof value !== 'object' || !(value instanceof Uint8Array))\n throw new Error(`Expected bytes value for AVMBytes, but got ${value}`)\n return value\n case 'AVMUint64':\n return ABIType.from('uint64').encode(value)\n }\n}\n\nexport function isAVMType(type: unknown): type is AVMType {\n return typeof type === 'string' && (type === 'AVMString' || type === 'AVMBytes' || type === 'AVMUint64')\n}\n\nexport function getABIDecodedValue(type: AVMType | ABIType | ABIReferenceType, bytes: Uint8Array): ABIValue {\n if (type === ABIReferenceType.Asset || type === ABIReferenceType.Application) {\n return new ABIUintType(64).decode(bytes)\n } else if (type === ABIReferenceType.Account) {\n return new ABIAddressType().decode(bytes)\n } else if (isAVMType(type)) {\n return decodeAVMValue(type, bytes)\n }\n return type.decode(bytes)\n}\n\nexport function getABIEncodedValue(type: AVMType | ABIType, value: ABIValue): Uint8Array {\n return isAVMType(type) ? encodeAVMValue(type, value) : type.encode(value)\n}\n"],"mappings":";;;;AAMA,IAAY,oEAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEF,IAAY,gEAAL;AACL;AACA;AACA;;;AAuDF,IAAa,YAAb,MAAa,UAAU;CACrB,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAOT;AACD,OAAK,OAAO,OAAO;AACnB,OAAK,cAAc,OAAO;AAC1B,OAAK,OAAO,OAAO;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,SAAS,OAAO;AACrB,OAAK,WAAW,OAAO;;;;;;CAOzB,eAAuB;EACrB,MAAM,OAAO,KAAK,KACf,KAAK,QAAQ;AACZ,OAAI,qBAAqB,IAAI,KAAK,IAAI,mBAAmB,IAAI,KAAK,CAAE,QAAO,IAAI;AAC/E,UAAO,IAAI,KAAK;IAChB,CACD,KAAK,IAAI;AAEZ,SAAO,GAAG,KAAK,KAAK,GAAG,KAAK,GADZ,KAAK,QAAQ,SAAS,SAAS,SAAS,KAAK,QAAQ,KAAK;;;;;;CAQ5E,cAA0B;EACxB,MAAM,OAAO,OAAO,WAAW,MAAM,KAAK,cAAc,CAAC;AACzD,SAAO,IAAI,WAAW,KAAK,MAAM,GAAG,EAAE,CAAC;;;;;;;;CASzC,OAAO,cAAc,WAA8B;EACjD,MAAM,YAAY,UAAU,QAAQ,IAAI;AACxC,MAAI,cAAc,GAChB,OAAM,IAAI,MAAM,6BAA6B,YAAY;EAG3D,IAAI,UAAU;EACd,IAAI,QAAQ;AACZ,OAAK,IAAI,IAAI,WAAW,IAAI,UAAU,QAAQ,KAAK;GACjD,MAAM,OAAO,UAAU;AAEvB,OAAI,SAAS,IACX,UAAS;YACA,SAAS,KAAK;AACvB,QAAI,UAAU,EAEZ;AAGF,aAAS;AACT,QAAI,UAAU,GAAG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K,GAAG,eAAe,MAAM,MAAM,GAAG,KAAK,OAAO,MAAM"}
@@ -114,7 +114,7 @@ declare class ABIAddressType extends ABIType {
114
114
  isDynamic(): boolean;
115
115
  byteLen(): number;
116
116
  encode(value: ABIValue): Uint8Array;
117
- decode(bytes: Uint8Array): ABIValue;
117
+ decode(bytes: Uint8Array): string;
118
118
  }
119
119
  /**
120
120
  * A boolean ABI type.
@@ -167,10 +167,11 @@ var ABIAddressType = class ABIAddressType extends ABIType {
167
167
  encode(value) {
168
168
  if (typeof value === "string") return require_address.Address.fromString(value).publicKey;
169
169
  if (value instanceof require_address.Address) return value.publicKey;
170
+ if (value instanceof Uint8Array && value.length === 32) return value;
170
171
  throw new Error(`Cannot encode value as address: ${value}`);
171
172
  }
172
173
  decode(bytes) {
173
- return new require_address.Address(bytes);
174
+ return new require_address.Address(bytes).toString();
174
175
  }
175
176
  };
176
177
  /**