@algorandfoundation/algokit-utils 6.2.1 → 7.0.0-alpha.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 (465) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -26
  3. package/account/account.d.ts +21 -11
  4. package/account/get-account-config-from-environment.d.ts +0 -1
  5. package/account/get-account.d.ts +6 -7
  6. package/account/get-dispenser-account.d.ts +2 -3
  7. package/account/index.d.ts +0 -1
  8. package/account/mnemonic-account.d.ts +1 -2
  9. package/amount.d.ts +41 -9
  10. package/app-client.d.ts +19 -5
  11. package/app-deploy.d.ts +18 -2
  12. package/app.d.ts +39 -3
  13. package/asset.d.ts +10 -1
  14. package/config.d.ts +0 -1
  15. package/debugging/debugging.d.ts +3 -5
  16. package/debugging/index.d.ts +0 -2
  17. package/dispenser-client.d.ts +1 -2
  18. package/index.d.ts +8 -6
  19. package/index.js +61 -48
  20. package/index.js.map +1 -1
  21. package/index.mjs +27 -24
  22. package/index.mjs.map +1 -1
  23. package/indexer-lookup.d.ts +10 -9
  24. package/localnet/get-kmd-wallet-account.d.ts +1 -2
  25. package/localnet/get-localnet-dispenser-account.d.ts +1 -2
  26. package/localnet/get-or-create-kmd-wallet-account.d.ts +2 -3
  27. package/localnet/index.d.ts +0 -1
  28. package/localnet/is-localnet.d.ts +1 -2
  29. package/network-client.d.ts +3 -10
  30. package/package.json +5 -5
  31. package/{account → src/account}/account.js +38 -15
  32. package/src/account/account.js.map +1 -0
  33. package/{account → src/account}/account.mjs +39 -16
  34. package/src/account/account.mjs.map +1 -0
  35. package/src/account/get-account-config-from-environment.js.map +1 -0
  36. package/src/account/get-account-config-from-environment.mjs.map +1 -0
  37. package/{account → src/account}/get-account.js +5 -5
  38. package/src/account/get-account.js.map +1 -0
  39. package/{account → src/account}/get-account.mjs +5 -5
  40. package/src/account/get-account.mjs.map +1 -0
  41. package/{account → src/account}/get-dispenser-account.js +3 -3
  42. package/src/account/get-dispenser-account.js.map +1 -0
  43. package/{account → src/account}/get-dispenser-account.mjs +3 -3
  44. package/src/account/get-dispenser-account.mjs.map +1 -0
  45. package/{account → src/account}/mnemonic-account.js +1 -1
  46. package/src/account/mnemonic-account.js.map +1 -0
  47. package/{account → src/account}/mnemonic-account.mjs +1 -1
  48. package/src/account/mnemonic-account.mjs.map +1 -0
  49. package/src/amount.js +61 -0
  50. package/src/amount.js.map +1 -0
  51. package/src/amount.mjs +54 -0
  52. package/src/amount.mjs.map +1 -0
  53. package/{app-client.js → src/app-client.js} +20 -5
  54. package/src/app-client.js.map +1 -0
  55. package/{app-client.mjs → src/app-client.mjs} +20 -5
  56. package/src/app-client.mjs.map +1 -0
  57. package/src/app-deploy.js +285 -0
  58. package/src/app-deploy.js.map +1 -0
  59. package/src/app-deploy.mjs +276 -0
  60. package/src/app-deploy.mjs.map +1 -0
  61. package/src/app.js +349 -0
  62. package/src/app.js.map +1 -0
  63. package/src/app.mjs +329 -0
  64. package/src/app.mjs.map +1 -0
  65. package/src/asset.js +142 -0
  66. package/src/asset.js.map +1 -0
  67. package/src/asset.mjs +136 -0
  68. package/src/asset.mjs.map +1 -0
  69. package/{config.js → src/config.js} +1 -1
  70. package/src/config.js.map +1 -0
  71. package/{config.mjs → src/config.mjs} +1 -1
  72. package/src/config.mjs.map +1 -0
  73. package/src/debugging/debugging.js +15 -0
  74. package/src/debugging/debugging.js.map +1 -0
  75. package/src/debugging/debugging.mjs +13 -0
  76. package/src/debugging/debugging.mjs.map +1 -0
  77. package/{dispenser-client.js → src/dispenser-client.js} +3 -3
  78. package/src/dispenser-client.js.map +1 -0
  79. package/{dispenser-client.mjs → src/dispenser-client.mjs} +3 -3
  80. package/src/dispenser-client.mjs.map +1 -0
  81. package/{indexer-lookup.js → src/indexer-lookup.js} +14 -10
  82. package/src/indexer-lookup.js.map +1 -0
  83. package/{indexer-lookup.mjs → src/indexer-lookup.mjs} +14 -10
  84. package/src/indexer-lookup.mjs.map +1 -0
  85. package/{localnet → src/localnet}/get-kmd-wallet-account.js +3 -3
  86. package/src/localnet/get-kmd-wallet-account.js.map +1 -0
  87. package/{localnet → src/localnet}/get-kmd-wallet-account.mjs +3 -3
  88. package/src/localnet/get-kmd-wallet-account.mjs.map +1 -0
  89. package/{localnet → src/localnet}/get-localnet-dispenser-account.js +3 -3
  90. package/src/localnet/get-localnet-dispenser-account.js.map +1 -0
  91. package/{localnet → src/localnet}/get-localnet-dispenser-account.mjs +3 -3
  92. package/src/localnet/get-localnet-dispenser-account.mjs.map +1 -0
  93. package/{localnet → src/localnet}/get-or-create-kmd-wallet-account.js +4 -4
  94. package/src/localnet/get-or-create-kmd-wallet-account.js.map +1 -0
  95. package/{localnet → src/localnet}/get-or-create-kmd-wallet-account.mjs +4 -4
  96. package/src/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -0
  97. package/{localnet → src/localnet}/is-localnet.js +2 -2
  98. package/src/localnet/is-localnet.js.map +1 -0
  99. package/{localnet → src/localnet}/is-localnet.mjs +2 -2
  100. package/src/localnet/is-localnet.mjs.map +1 -0
  101. package/{network-client.js → src/network-client.js} +5 -12
  102. package/src/network-client.js.map +1 -0
  103. package/{network-client.mjs → src/network-client.mjs} +5 -12
  104. package/src/network-client.mjs.map +1 -0
  105. package/{testing → src/testing}/account.js +16 -4
  106. package/src/testing/account.js.map +1 -0
  107. package/{testing → src/testing}/account.mjs +17 -5
  108. package/src/testing/account.mjs.map +1 -0
  109. package/src/testing/fixtures/algokit-log-capture-fixture.js.map +1 -0
  110. package/src/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -0
  111. package/{testing → src/testing}/fixtures/algorand-fixture.js +18 -14
  112. package/src/testing/fixtures/algorand-fixture.js.map +1 -0
  113. package/{testing → src/testing}/fixtures/algorand-fixture.mjs +18 -14
  114. package/src/testing/fixtures/algorand-fixture.mjs.map +1 -0
  115. package/src/testing/indexer.js.map +1 -0
  116. package/src/testing/indexer.mjs.map +1 -0
  117. package/{testing → src/testing}/test-logger.js +7 -3
  118. package/src/testing/test-logger.js.map +1 -0
  119. package/{testing → src/testing}/test-logger.mjs +7 -3
  120. package/src/testing/test-logger.mjs.map +1 -0
  121. package/src/testing/transaction-logger.js.map +1 -0
  122. package/src/testing/transaction-logger.mjs.map +1 -0
  123. package/src/transaction/legacy-bridge.js +129 -0
  124. package/src/transaction/legacy-bridge.js.map +1 -0
  125. package/src/transaction/legacy-bridge.mjs +124 -0
  126. package/src/transaction/legacy-bridge.mjs.map +1 -0
  127. package/{transaction → src/transaction}/perform-atomic-transaction-composer-simulate.js +14 -9
  128. package/src/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -0
  129. package/{transaction → src/transaction}/perform-atomic-transaction-composer-simulate.mjs +15 -10
  130. package/src/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -0
  131. package/{transaction → src/transaction}/transaction.js +221 -141
  132. package/src/transaction/transaction.js.map +1 -0
  133. package/{transaction → src/transaction}/transaction.mjs +222 -142
  134. package/src/transaction/transaction.mjs.map +1 -0
  135. package/src/transfer/transfer-algos.js +31 -0
  136. package/src/transfer/transfer-algos.js.map +1 -0
  137. package/src/transfer/transfer-algos.mjs +29 -0
  138. package/src/transfer/transfer-algos.mjs.map +1 -0
  139. package/src/transfer/transfer.js +112 -0
  140. package/src/transfer/transfer.js.map +1 -0
  141. package/src/transfer/transfer.mjs +108 -0
  142. package/src/transfer/transfer.mjs.map +1 -0
  143. package/{util.js → src/util.js} +33 -7
  144. package/src/util.js.map +1 -0
  145. package/{util.mjs → src/util.mjs} +31 -7
  146. package/src/util.mjs.map +1 -0
  147. package/testing/_asset.d.ts +3 -5
  148. package/testing/account.d.ts +4 -4
  149. package/testing/fixtures/algokit-log-capture-fixture.d.ts +0 -1
  150. package/testing/fixtures/algorand-fixture.d.ts +1 -2
  151. package/testing/fixtures/index.d.ts +0 -1
  152. package/testing/index.d.ts +0 -1
  153. package/testing/index.js +6 -6
  154. package/testing/index.mjs +6 -6
  155. package/testing/indexer.d.ts +0 -1
  156. package/testing/test-logger.d.ts +0 -1
  157. package/testing/transaction-logger.d.ts +0 -1
  158. package/transaction/index.d.ts +0 -1
  159. package/transaction/legacy-bridge.d.ts +35 -0
  160. package/transaction/perform-atomic-transaction-composer-simulate.d.ts +4 -2
  161. package/transaction/transaction.d.ts +39 -20
  162. package/transfer/index.d.ts +0 -1
  163. package/transfer/transfer-algos.d.ts +4 -3
  164. package/transfer/transfer.d.ts +8 -2
  165. package/types/account-manager.d.ts +165 -40
  166. package/types/account-manager.js +255 -59
  167. package/types/account-manager.js.map +1 -1
  168. package/types/account-manager.mjs +255 -59
  169. package/types/account-manager.mjs.map +1 -1
  170. package/types/account.d.ts +137 -14
  171. package/types/account.js +2 -2
  172. package/types/account.js.map +1 -1
  173. package/types/account.mjs +3 -3
  174. package/types/account.mjs.map +1 -1
  175. package/types/algo-http-client-with-retry.d.ts +1 -3
  176. package/types/algo-http-client-with-retry.js +34 -4
  177. package/types/algo-http-client-with-retry.js.map +1 -1
  178. package/types/algo-http-client-with-retry.mjs +33 -3
  179. package/types/algo-http-client-with-retry.mjs.map +1 -1
  180. package/types/algorand-client-interface.d.ts +28 -0
  181. package/types/algorand-client-interface.js +3 -0
  182. package/types/algorand-client-interface.js.map +1 -0
  183. package/types/algorand-client-interface.mjs +2 -0
  184. package/types/algorand-client-interface.mjs.map +1 -0
  185. package/types/algorand-client-transaction-creator.d.ts +718 -0
  186. package/types/algorand-client-transaction-creator.js +683 -0
  187. package/types/algorand-client-transaction-creator.js.map +1 -0
  188. package/types/algorand-client-transaction-creator.mjs +681 -0
  189. package/types/algorand-client-transaction-creator.mjs.map +1 -0
  190. package/types/algorand-client-transaction-sender.d.ts +1158 -0
  191. package/types/algorand-client-transaction-sender.js +852 -0
  192. package/types/algorand-client-transaction-sender.js.map +1 -0
  193. package/types/algorand-client-transaction-sender.mjs +850 -0
  194. package/types/algorand-client-transaction-sender.mjs.map +1 -0
  195. package/types/algorand-client.d.ts +48 -91
  196. package/types/algorand-client.js +53 -132
  197. package/types/algorand-client.js.map +1 -1
  198. package/types/algorand-client.mjs +55 -131
  199. package/types/algorand-client.mjs.map +1 -1
  200. package/types/amount.d.ts +23 -12
  201. package/types/amount.js +33 -10
  202. package/types/amount.js.map +1 -1
  203. package/types/amount.mjs +33 -10
  204. package/types/amount.mjs.map +1 -1
  205. package/types/app-arc56.d.ts +359 -0
  206. package/types/app-arc56.js +184 -0
  207. package/types/app-arc56.js.map +1 -0
  208. package/types/app-arc56.mjs +175 -0
  209. package/types/app-arc56.mjs.map +1 -0
  210. package/types/app-client.d.ts +1511 -15
  211. package/types/app-client.js +1029 -43
  212. package/types/app-client.js.map +1 -1
  213. package/types/app-client.mjs +1030 -45
  214. package/types/app-client.mjs.map +1 -1
  215. package/types/app-deployer.d.ts +126 -0
  216. package/types/app-deployer.js +353 -0
  217. package/types/app-deployer.js.map +1 -0
  218. package/types/app-deployer.mjs +351 -0
  219. package/types/app-deployer.mjs.map +1 -0
  220. package/types/app-factory.d.ts +846 -0
  221. package/types/app-factory.js +410 -0
  222. package/types/app-factory.js.map +1 -0
  223. package/types/app-factory.mjs +408 -0
  224. package/types/app-factory.mjs.map +1 -0
  225. package/types/app-manager.d.ts +244 -0
  226. package/types/app-manager.js +423 -0
  227. package/types/app-manager.js.map +1 -0
  228. package/types/app-manager.mjs +421 -0
  229. package/types/app-manager.mjs.map +1 -0
  230. package/types/app-spec.d.ts +2 -1
  231. package/types/app-spec.js +127 -0
  232. package/types/app-spec.js.map +1 -1
  233. package/types/app-spec.mjs +126 -0
  234. package/types/app-spec.mjs.map +1 -1
  235. package/types/app.d.ts +57 -18
  236. package/types/app.js +1 -1
  237. package/types/app.js.map +1 -1
  238. package/types/app.mjs +1 -1
  239. package/types/app.mjs.map +1 -1
  240. package/types/asset-manager.d.ts +205 -0
  241. package/types/asset-manager.js +176 -0
  242. package/types/asset-manager.js.map +1 -0
  243. package/types/asset-manager.mjs +174 -0
  244. package/types/asset-manager.mjs.map +1 -0
  245. package/types/asset.d.ts +4 -5
  246. package/types/async-event-emitter.d.ts +14 -0
  247. package/types/async-event-emitter.js +50 -0
  248. package/types/async-event-emitter.js.map +1 -0
  249. package/types/async-event-emitter.mjs +48 -0
  250. package/types/async-event-emitter.mjs.map +1 -0
  251. package/types/client-manager.d.ts +171 -58
  252. package/types/client-manager.js +198 -43
  253. package/types/client-manager.js.map +1 -1
  254. package/types/client-manager.mjs +199 -44
  255. package/types/client-manager.mjs.map +1 -1
  256. package/types/composer.d.ts +474 -132
  257. package/types/composer.js +461 -167
  258. package/types/composer.js.map +1 -1
  259. package/types/composer.mjs +461 -168
  260. package/types/composer.mjs.map +1 -1
  261. package/types/config.d.ts +3 -6
  262. package/types/config.js +5 -44
  263. package/types/config.js.map +1 -1
  264. package/types/config.mjs +5 -27
  265. package/types/config.mjs.map +1 -1
  266. package/types/debugging.d.ts +29 -101
  267. package/types/debugging.js +16 -109
  268. package/types/debugging.js.map +1 -1
  269. package/types/debugging.mjs +12 -107
  270. package/types/debugging.mjs.map +1 -1
  271. package/types/dispenser-client.d.ts +14 -6
  272. package/types/dispenser-client.js +19 -14
  273. package/types/dispenser-client.js.map +1 -1
  274. package/types/dispenser-client.mjs +19 -14
  275. package/types/dispenser-client.mjs.map +1 -1
  276. package/types/expand.d.ts +7 -0
  277. package/types/expand.js +3 -0
  278. package/types/expand.js.map +1 -0
  279. package/types/expand.mjs +2 -0
  280. package/types/expand.mjs.map +1 -0
  281. package/types/indexer.d.ts +74 -756
  282. package/types/indexer.js.map +1 -1
  283. package/types/indexer.mjs.map +1 -1
  284. package/types/kmd-account-manager.d.ts +5 -6
  285. package/types/kmd-account-manager.js +9 -9
  286. package/types/kmd-account-manager.js.map +1 -1
  287. package/types/kmd-account-manager.mjs +10 -10
  288. package/types/kmd-account-manager.mjs.map +1 -1
  289. package/types/lifecycle-events.d.ts +10 -0
  290. package/types/lifecycle-events.js +8 -0
  291. package/types/lifecycle-events.js.map +1 -0
  292. package/types/lifecycle-events.mjs +8 -0
  293. package/types/lifecycle-events.mjs.map +1 -0
  294. package/types/logging.d.ts +0 -1
  295. package/types/logging.js.map +1 -1
  296. package/types/logging.mjs.map +1 -1
  297. package/types/logic-error.d.ts +2 -4
  298. package/types/logic-error.js +3 -3
  299. package/types/logic-error.js.map +1 -1
  300. package/types/logic-error.mjs +3 -3
  301. package/types/logic-error.mjs.map +1 -1
  302. package/types/network-client.d.ts +21 -3
  303. package/types/network-client.js +10 -0
  304. package/types/network-client.js.map +1 -1
  305. package/types/network-client.mjs +9 -0
  306. package/types/network-client.mjs.map +1 -1
  307. package/types/testing.d.ts +9 -11
  308. package/types/transaction.d.ts +17 -4
  309. package/types/transfer.d.ts +8 -8
  310. package/util.d.ts +15 -2
  311. package/account/account.d.ts.map +0 -1
  312. package/account/account.js.map +0 -1
  313. package/account/account.mjs.map +0 -1
  314. package/account/get-account-config-from-environment.d.ts.map +0 -1
  315. package/account/get-account-config-from-environment.js.map +0 -1
  316. package/account/get-account-config-from-environment.mjs.map +0 -1
  317. package/account/get-account.d.ts.map +0 -1
  318. package/account/get-account.js.map +0 -1
  319. package/account/get-account.mjs.map +0 -1
  320. package/account/get-dispenser-account.d.ts.map +0 -1
  321. package/account/get-dispenser-account.js.map +0 -1
  322. package/account/get-dispenser-account.mjs.map +0 -1
  323. package/account/index.d.ts.map +0 -1
  324. package/account/mnemonic-account.d.ts.map +0 -1
  325. package/account/mnemonic-account.js.map +0 -1
  326. package/account/mnemonic-account.mjs.map +0 -1
  327. package/amount.d.ts.map +0 -1
  328. package/amount.js +0 -34
  329. package/amount.js.map +0 -1
  330. package/amount.mjs +0 -30
  331. package/amount.mjs.map +0 -1
  332. package/app-client.d.ts.map +0 -1
  333. package/app-client.js.map +0 -1
  334. package/app-client.mjs.map +0 -1
  335. package/app-deploy.d.ts.map +0 -1
  336. package/app-deploy.js +0 -468
  337. package/app-deploy.js.map +0 -1
  338. package/app-deploy.mjs +0 -459
  339. package/app-deploy.mjs.map +0 -1
  340. package/app.d.ts.map +0 -1
  341. package/app.js +0 -599
  342. package/app.js.map +0 -1
  343. package/app.mjs +0 -579
  344. package/app.mjs.map +0 -1
  345. package/asset.d.ts.map +0 -1
  346. package/asset.js +0 -272
  347. package/asset.js.map +0 -1
  348. package/asset.mjs +0 -266
  349. package/asset.mjs.map +0 -1
  350. package/config.d.ts.map +0 -1
  351. package/config.js.map +0 -1
  352. package/config.mjs.map +0 -1
  353. package/debugging/debugging.d.ts.map +0 -1
  354. package/debugging/debugging.js +0 -139
  355. package/debugging/debugging.js.map +0 -1
  356. package/debugging/debugging.mjs +0 -118
  357. package/debugging/debugging.mjs.map +0 -1
  358. package/debugging/index.d.ts.map +0 -1
  359. package/debugging/simulate-and-persist-response.d.ts +0 -20
  360. package/debugging/simulate-and-persist-response.d.ts.map +0 -1
  361. package/debugging/simulate-and-persist-response.js +0 -108
  362. package/debugging/simulate-and-persist-response.js.map +0 -1
  363. package/debugging/simulate-and-persist-response.mjs +0 -89
  364. package/debugging/simulate-and-persist-response.mjs.map +0 -1
  365. package/dispenser-client.d.ts.map +0 -1
  366. package/dispenser-client.js.map +0 -1
  367. package/dispenser-client.mjs.map +0 -1
  368. package/index.d.ts.map +0 -1
  369. package/indexer-lookup.d.ts.map +0 -1
  370. package/indexer-lookup.js.map +0 -1
  371. package/indexer-lookup.mjs.map +0 -1
  372. package/localnet/get-kmd-wallet-account.d.ts.map +0 -1
  373. package/localnet/get-kmd-wallet-account.js.map +0 -1
  374. package/localnet/get-kmd-wallet-account.mjs.map +0 -1
  375. package/localnet/get-localnet-dispenser-account.d.ts.map +0 -1
  376. package/localnet/get-localnet-dispenser-account.js.map +0 -1
  377. package/localnet/get-localnet-dispenser-account.mjs.map +0 -1
  378. package/localnet/get-or-create-kmd-wallet-account.d.ts.map +0 -1
  379. package/localnet/get-or-create-kmd-wallet-account.js.map +0 -1
  380. package/localnet/get-or-create-kmd-wallet-account.mjs.map +0 -1
  381. package/localnet/index.d.ts.map +0 -1
  382. package/localnet/is-localnet.d.ts.map +0 -1
  383. package/localnet/is-localnet.js.map +0 -1
  384. package/localnet/is-localnet.mjs.map +0 -1
  385. package/network-client.d.ts.map +0 -1
  386. package/network-client.js.map +0 -1
  387. package/network-client.mjs.map +0 -1
  388. package/testing/_asset.d.ts.map +0 -1
  389. package/testing/account.d.ts.map +0 -1
  390. package/testing/account.js.map +0 -1
  391. package/testing/account.mjs.map +0 -1
  392. package/testing/fixtures/algokit-log-capture-fixture.d.ts.map +0 -1
  393. package/testing/fixtures/algokit-log-capture-fixture.js.map +0 -1
  394. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +0 -1
  395. package/testing/fixtures/algorand-fixture.d.ts.map +0 -1
  396. package/testing/fixtures/algorand-fixture.js.map +0 -1
  397. package/testing/fixtures/algorand-fixture.mjs.map +0 -1
  398. package/testing/fixtures/index.d.ts.map +0 -1
  399. package/testing/index.d.ts.map +0 -1
  400. package/testing/indexer.d.ts.map +0 -1
  401. package/testing/indexer.js.map +0 -1
  402. package/testing/indexer.mjs.map +0 -1
  403. package/testing/test-logger.d.ts.map +0 -1
  404. package/testing/test-logger.js.map +0 -1
  405. package/testing/test-logger.mjs.map +0 -1
  406. package/testing/transaction-logger.d.ts.map +0 -1
  407. package/testing/transaction-logger.js.map +0 -1
  408. package/testing/transaction-logger.mjs.map +0 -1
  409. package/transaction/index.d.ts.map +0 -1
  410. package/transaction/perform-atomic-transaction-composer-simulate.d.ts.map +0 -1
  411. package/transaction/perform-atomic-transaction-composer-simulate.js.map +0 -1
  412. package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +0 -1
  413. package/transaction/transaction.d.ts.map +0 -1
  414. package/transaction/transaction.js.map +0 -1
  415. package/transaction/transaction.mjs.map +0 -1
  416. package/transfer/index.d.ts.map +0 -1
  417. package/transfer/transfer-algos.d.ts.map +0 -1
  418. package/transfer/transfer-algos.js +0 -40
  419. package/transfer/transfer-algos.js.map +0 -1
  420. package/transfer/transfer-algos.mjs +0 -38
  421. package/transfer/transfer-algos.mjs.map +0 -1
  422. package/transfer/transfer.d.ts.map +0 -1
  423. package/transfer/transfer.js +0 -147
  424. package/transfer/transfer.js.map +0 -1
  425. package/transfer/transfer.mjs +0 -143
  426. package/transfer/transfer.mjs.map +0 -1
  427. package/types/account-manager.d.ts.map +0 -1
  428. package/types/account.d.ts.map +0 -1
  429. package/types/algo-http-client-with-retry.d.ts.map +0 -1
  430. package/types/algorand-client.d.ts.map +0 -1
  431. package/types/amount.d.ts.map +0 -1
  432. package/types/app-client.d.ts.map +0 -1
  433. package/types/app-spec.d.ts.map +0 -1
  434. package/types/app.d.ts.map +0 -1
  435. package/types/asset.d.ts.map +0 -1
  436. package/types/client-manager.d.ts.map +0 -1
  437. package/types/composer.d.ts.map +0 -1
  438. package/types/config.d.ts.map +0 -1
  439. package/types/debugging.d.ts.map +0 -1
  440. package/types/dispenser-client.d.ts.map +0 -1
  441. package/types/indexer.d.ts.map +0 -1
  442. package/types/kmd-account-manager.d.ts.map +0 -1
  443. package/types/logging.d.ts.map +0 -1
  444. package/types/logic-error.d.ts.map +0 -1
  445. package/types/network-client.d.ts.map +0 -1
  446. package/types/testing.d.ts.map +0 -1
  447. package/types/transaction.d.ts.map +0 -1
  448. package/types/transfer.d.ts.map +0 -1
  449. package/types/urlTokenBaseHTTPClient.d.ts +0 -41
  450. package/types/urlTokenBaseHTTPClient.d.ts.map +0 -1
  451. package/types/urlTokenBaseHTTPClient.js +0 -153
  452. package/types/urlTokenBaseHTTPClient.js.map +0 -1
  453. package/types/urlTokenBaseHTTPClient.mjs +0 -151
  454. package/types/urlTokenBaseHTTPClient.mjs.map +0 -1
  455. package/util.d.ts.map +0 -1
  456. package/util.js.map +0 -1
  457. package/util.mjs.map +0 -1
  458. /package/{account → src/account}/get-account-config-from-environment.js +0 -0
  459. /package/{account → src/account}/get-account-config-from-environment.mjs +0 -0
  460. /package/{testing → src/testing}/fixtures/algokit-log-capture-fixture.js +0 -0
  461. /package/{testing → src/testing}/fixtures/algokit-log-capture-fixture.mjs +0 -0
  462. /package/{testing → src/testing}/indexer.js +0 -0
  463. /package/{testing → src/testing}/indexer.mjs +0 -0
  464. /package/{testing → src/testing}/transaction-logger.js +0 -0
  465. /package/{testing → src/testing}/transaction-logger.mjs +0 -0
@@ -0,0 +1,244 @@
1
+ import algosdk, { Address } from 'algosdk';
2
+ import { TransactionSignerAccount } from './account';
3
+ import { BoxName, type ABIReturn, type AppState, type CompiledTeal, type TealTemplateParams } from './app';
4
+ import modelsv2 = algosdk.modelsv2;
5
+ /** Information about an app. */
6
+ export interface AppInformation {
7
+ /** The ID of the app. */
8
+ appId: bigint;
9
+ /** The escrow address that the app operates with. */
10
+ appAddress: Address;
11
+ /**
12
+ * Approval program.
13
+ */
14
+ approvalProgram: Uint8Array;
15
+ /**
16
+ * Clear state program.
17
+ */
18
+ clearStateProgram: Uint8Array;
19
+ /**
20
+ * The address that created this application. This is the address where the
21
+ * parameters and global state for this application can be found.
22
+ */
23
+ creator: Address;
24
+ /**
25
+ * Current global state values.
26
+ */
27
+ globalState: AppState;
28
+ /** The number of allocated ints in per-user local state. */
29
+ localInts: number;
30
+ /** The number of allocated byte slices in per-user local state. */
31
+ localByteSlices: number;
32
+ /** The number of allocated ints in global state. */
33
+ globalInts: number;
34
+ /** The number of allocated byte slices in global state. */
35
+ globalByteSlices: number;
36
+ /** Any extra pages that are needed for the smart contract. */
37
+ extraProgramPages?: number;
38
+ }
39
+ /**
40
+ * Something that identifies an app box name - either a:
41
+ * * `Uint8Array` (the actual binary of the box name)
42
+ * * `string` (that will be encoded to a `Uint8Array`)
43
+ * * `TransactionSignerAccount` (that will be encoded into the
44
+ * public key address of the corresponding account)
45
+ */
46
+ export type BoxIdentifier = string | Uint8Array | TransactionSignerAccount;
47
+ /**
48
+ * A grouping of the app ID and name identifier to reference an app box.
49
+ */
50
+ export interface BoxReference {
51
+ /**
52
+ * A unique application id
53
+ */
54
+ appId: bigint;
55
+ /**
56
+ * Identifier for a box name
57
+ */
58
+ name: BoxIdentifier;
59
+ }
60
+ /**
61
+ * Parameters to get and decode a box value as an ABI type.
62
+ */
63
+ export interface BoxValueRequestParams {
64
+ /** The ID of the app return box names for */
65
+ appId: bigint;
66
+ /** The name of the box to return either as a string, binary array or `BoxName` */
67
+ boxName: BoxIdentifier;
68
+ /** The ABI type to decode the value using */
69
+ type: algosdk.ABIType;
70
+ }
71
+ /**
72
+ * Parameters to get and decode a box value as an ABI type.
73
+ */
74
+ export interface BoxValuesRequestParams {
75
+ /** The ID of the app return box names for */
76
+ appId: bigint;
77
+ /** The names of the boxes to return either as a string, binary array or BoxName` */
78
+ boxNames: BoxIdentifier[];
79
+ /** The ABI type to decode the value using */
80
+ type: algosdk.ABIType;
81
+ }
82
+ /** Allows management of application information. */
83
+ export declare class AppManager {
84
+ private _algod;
85
+ private _compilationResults;
86
+ /**
87
+ * Creates an `AppManager`
88
+ * @param algod An algod instance
89
+ */
90
+ constructor(algod: algosdk.Algodv2);
91
+ /**
92
+ * Compiles the given TEAL using algod and returns the result, including source map.
93
+ *
94
+ * The result of this compilation is also cached keyed by the TEAL
95
+ * code so it can be retrieved via `getCompilationResult`.
96
+ *
97
+ * This function is re-entrant; it will only compile the same code once.
98
+ *
99
+ * @param tealCode The TEAL code
100
+ * @returns The information about the compiled file
101
+ */
102
+ compileTeal(tealCode: string): Promise<CompiledTeal>;
103
+ /**
104
+ * Performs template substitution of a teal template and compiles it, returning the compiled result.
105
+ *
106
+ * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters
107
+ * if deployment metadata is specified.
108
+ *
109
+ * * `TMPL_UPDATABLE` for updatability / immutability control
110
+ * * `TMPL_DELETABLE` for deletability / permanence control
111
+ *
112
+ * @param tealTemplateCode The TEAL logic to compile
113
+ * @param templateParams Any parameters to replace in the .teal file before compiling
114
+ * @param deploymentMetadata The deployment metadata the app will be deployed with
115
+ * @returns The information about the compiled code
116
+ */
117
+ compileTealTemplate(tealTemplateCode: string, templateParams?: TealTemplateParams, deploymentMetadata?: {
118
+ updatable?: boolean;
119
+ deletable?: boolean;
120
+ }): Promise<CompiledTeal>;
121
+ /**
122
+ * Returns a previous compilation result.
123
+ * @param tealCode The TEAL code
124
+ * @returns The information about the previously compiled file
125
+ * or `undefined` if that TEAL code wasn't previously compiled
126
+ */
127
+ getCompilationResult(tealCode: string): CompiledTeal | undefined;
128
+ /**
129
+ * Returns the current app information for the app with the given ID.
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * const appInfo = await appManager.getById(12353n);
134
+ * ```
135
+ *
136
+ * @param appId The ID of the app
137
+ * @returns The app information
138
+ */
139
+ getById(appId: bigint): Promise<AppInformation>;
140
+ /**
141
+ * Returns the current global state values for the given app ID and account address
142
+ *
143
+ * @param appId The ID of the app to return global state for
144
+ * @returns The current global state for the given app
145
+ */
146
+ getGlobalState(appId: bigint): Promise<AppState>;
147
+ /**
148
+ * Returns the current local state values for the given app ID and account address
149
+ *
150
+ * @param appId The ID of the app to return local state for
151
+ * @param address The string address of the account to get local state for the given app
152
+ * @returns The current local state for the given (app, account) combination
153
+ */
154
+ getLocalState(appId: bigint, address: Address | string): Promise<AppState>;
155
+ /**
156
+ * Returns the names of the current boxes for the given app.
157
+ * @param appId The ID of the app return box names for
158
+ * @returns The current box names
159
+ */
160
+ getBoxNames(appId: bigint): Promise<BoxName[]>;
161
+ /**
162
+ * Returns the value of the given box name for the given app.
163
+ * @param appId The ID of the app return box names for
164
+ * @param boxName The name of the box to return either as a string, binary array or `BoxName`
165
+ * @returns The current box value as a byte array
166
+ */
167
+ getBoxValue(appId: bigint, boxName: BoxIdentifier): Promise<Uint8Array>;
168
+ /**
169
+ * Returns the value of the given box names for the given app.
170
+ * @param appId The ID of the app return box names for
171
+ * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
172
+ * @returns The current box values as a byte array in the same order as the passed in box names
173
+ */
174
+ getBoxValues(appId: bigint, boxNames: BoxIdentifier[]): Promise<Uint8Array[]>;
175
+ /**
176
+ * Returns the value of the given box name for the given app decoded based on the given ABI type.
177
+ * @param request The parameters for the box value request
178
+ * @returns The current box value as an ABI value
179
+ */
180
+ getBoxValueFromABIType(request: BoxValueRequestParams): Promise<algosdk.ABIValue>;
181
+ /**
182
+ * Returns the value of the given box names for the given app decoded based on the given ABI type.
183
+ * @param request The parameters for the box value request
184
+ * @returns The current box values as an ABI value in the same order as the passed in box names
185
+ */
186
+ getBoxValuesFromABIType(request: BoxValuesRequestParams): Promise<algosdk.ABIValue[]>;
187
+ /**
188
+ * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
189
+ * @param boxId The box to return a reference for
190
+ * @returns The box reference ready to pass into a `algosdk.Transaction`
191
+ */
192
+ static getBoxReference(boxId: BoxIdentifier | BoxReference): algosdk.BoxReference;
193
+ /**
194
+ * Converts an array of global/local state values from the algod api to a more friendly
195
+ * generic object keyed by the UTF-8 value of the key.
196
+ * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
197
+ * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
198
+ */
199
+ static decodeAppState(state: {
200
+ key: Uint8Array;
201
+ value: modelsv2.TealValue | modelsv2.EvalDelta;
202
+ }[]): AppState;
203
+ /**
204
+ * Returns any ABI return values for the given app call arguments and transaction confirmation.
205
+ * @param confirmation The transaction confirmation from algod
206
+ * @param method The ABI method
207
+ * @returns The return value for the method call
208
+ */
209
+ static getABIReturn(confirmation: modelsv2.PendingTransactionResponse | undefined, method: algosdk.ABIMethod | undefined): ABIReturn | undefined;
210
+ /**
211
+ * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
212
+ *
213
+ * * `TMPL_UPDATABLE` for updatability / immutability control
214
+ * * `TMPL_DELETABLE` for deletability / permanence control
215
+ *
216
+ * Note: If these values are defined, but the corresponding `TMPL_*` value
217
+ * isn't in the teal code it will throw an exception.
218
+ *
219
+ * @param tealTemplateCode The TEAL template code to substitute
220
+ * @param params The deploy-time deployment control parameter value to replace
221
+ * @returns The replaced TEAL code
222
+ */
223
+ static replaceTealTemplateDeployTimeControlParams(tealTemplateCode: string, params: {
224
+ updatable?: boolean;
225
+ deletable?: boolean;
226
+ }): string;
227
+ /**
228
+ * Performs template substitution of a teal file.
229
+ *
230
+ * Looks for `TMPL_{parameter}` for template replacements.
231
+ *
232
+ * @param tealTemplateCode The TEAL template code to make parameter replacements in
233
+ * @param templateParams Any parameters to replace in the teal code
234
+ * @returns The TEAL code with replacements
235
+ */
236
+ static replaceTealTemplateParams(tealTemplateCode: string, templateParams?: TealTemplateParams): string;
237
+ /**
238
+ * Remove comments from TEAL code (useful to reduce code size before compilation).
239
+ *
240
+ * @param tealCode The TEAL logic to strip
241
+ * @returns The TEAL without comments
242
+ */
243
+ static stripTealComments(tealCode: string): string;
244
+ }
@@ -0,0 +1,423 @@
1
+ 'use strict';
2
+
3
+ var algosdk = require('algosdk');
4
+ var transaction = require('../src/transaction/transaction.js');
5
+ var types_app = require('./app.js');
6
+
7
+ /** Allows management of application information. */
8
+ class AppManager {
9
+ /**
10
+ * Creates an `AppManager`
11
+ * @param algod An algod instance
12
+ */
13
+ constructor(algod) {
14
+ this._compilationResults = {};
15
+ this._algod = algod;
16
+ }
17
+ /**
18
+ * Compiles the given TEAL using algod and returns the result, including source map.
19
+ *
20
+ * The result of this compilation is also cached keyed by the TEAL
21
+ * code so it can be retrieved via `getCompilationResult`.
22
+ *
23
+ * This function is re-entrant; it will only compile the same code once.
24
+ *
25
+ * @param tealCode The TEAL code
26
+ * @returns The information about the compiled file
27
+ */
28
+ async compileTeal(tealCode) {
29
+ if (this._compilationResults[tealCode]) {
30
+ return this._compilationResults[tealCode];
31
+ }
32
+ const compiled = await this._algod.compile(tealCode).sourcemap(true).do();
33
+ const result = {
34
+ teal: tealCode,
35
+ compiled: compiled.result,
36
+ compiledHash: compiled.hash,
37
+ compiledBase64ToBytes: new Uint8Array(Buffer.from(compiled.result, 'base64')),
38
+ sourceMap: new algosdk.ProgramSourceMap(JSON.parse(algosdk.encodeJSON(compiled.sourcemap))),
39
+ };
40
+ this._compilationResults[tealCode] = result;
41
+ return result;
42
+ }
43
+ /**
44
+ * Performs template substitution of a teal template and compiles it, returning the compiled result.
45
+ *
46
+ * Looks for `TMPL_{parameter}` for template replacements and replaces AlgoKit deploy-time control parameters
47
+ * if deployment metadata is specified.
48
+ *
49
+ * * `TMPL_UPDATABLE` for updatability / immutability control
50
+ * * `TMPL_DELETABLE` for deletability / permanence control
51
+ *
52
+ * @param tealTemplateCode The TEAL logic to compile
53
+ * @param templateParams Any parameters to replace in the .teal file before compiling
54
+ * @param deploymentMetadata The deployment metadata the app will be deployed with
55
+ * @returns The information about the compiled code
56
+ */
57
+ async compileTealTemplate(tealTemplateCode, templateParams, deploymentMetadata) {
58
+ let tealCode = AppManager.stripTealComments(tealTemplateCode);
59
+ tealCode = AppManager.replaceTealTemplateParams(tealCode, templateParams);
60
+ if (deploymentMetadata) {
61
+ tealCode = AppManager.replaceTealTemplateDeployTimeControlParams(tealCode, deploymentMetadata);
62
+ }
63
+ return await this.compileTeal(tealCode);
64
+ }
65
+ /**
66
+ * Returns a previous compilation result.
67
+ * @param tealCode The TEAL code
68
+ * @returns The information about the previously compiled file
69
+ * or `undefined` if that TEAL code wasn't previously compiled
70
+ */
71
+ getCompilationResult(tealCode) {
72
+ return this._compilationResults[tealCode];
73
+ }
74
+ /**
75
+ * Returns the current app information for the app with the given ID.
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const appInfo = await appManager.getById(12353n);
80
+ * ```
81
+ *
82
+ * @param appId The ID of the app
83
+ * @returns The app information
84
+ */
85
+ async getById(appId) {
86
+ const app = await this._algod.getApplicationByID(Number(appId)).do();
87
+ return {
88
+ appId: BigInt(app.id),
89
+ appAddress: algosdk.getApplicationAddress(app.id),
90
+ approvalProgram: app.params.approvalProgram,
91
+ clearStateProgram: app.params.clearStateProgram,
92
+ creator: app.params.creator,
93
+ localInts: Number(app.params.localStateSchema?.numUint ?? 0),
94
+ localByteSlices: Number(app.params.localStateSchema?.numByteSlice ?? 0),
95
+ globalInts: Number(app.params.globalStateSchema?.numUint ?? 0),
96
+ globalByteSlices: Number(app.params.globalStateSchema?.numByteSlice ?? 0),
97
+ extraProgramPages: Number(app.params.extraProgramPages ?? 0),
98
+ globalState: AppManager.decodeAppState(app.params.globalState ?? []),
99
+ };
100
+ }
101
+ /**
102
+ * Returns the current global state values for the given app ID and account address
103
+ *
104
+ * @param appId The ID of the app to return global state for
105
+ * @returns The current global state for the given app
106
+ */
107
+ async getGlobalState(appId) {
108
+ return (await this.getById(appId)).globalState;
109
+ }
110
+ /**
111
+ * Returns the current local state values for the given app ID and account address
112
+ *
113
+ * @param appId The ID of the app to return local state for
114
+ * @param address The string address of the account to get local state for the given app
115
+ * @returns The current local state for the given (app, account) combination
116
+ */
117
+ async getLocalState(appId, address) {
118
+ const appInfo = await this._algod.accountApplicationInformation(address, appId).do();
119
+ if (!appInfo.appLocalState?.keyValue) {
120
+ throw new Error("Couldn't find local state");
121
+ }
122
+ return AppManager.decodeAppState(appInfo.appLocalState.keyValue);
123
+ }
124
+ /**
125
+ * Returns the names of the current boxes for the given app.
126
+ * @param appId The ID of the app return box names for
127
+ * @returns The current box names
128
+ */
129
+ async getBoxNames(appId) {
130
+ const boxResult = await this._algod.getApplicationBoxes(appId).do();
131
+ return boxResult.boxes.map((b) => {
132
+ return {
133
+ nameRaw: b.name,
134
+ nameBase64: Buffer.from(b.name).toString('base64'),
135
+ name: Buffer.from(b.name).toString('utf-8'),
136
+ };
137
+ });
138
+ }
139
+ /**
140
+ * Returns the value of the given box name for the given app.
141
+ * @param appId The ID of the app return box names for
142
+ * @param boxName The name of the box to return either as a string, binary array or `BoxName`
143
+ * @returns The current box value as a byte array
144
+ */
145
+ async getBoxValue(appId, boxName) {
146
+ const name = AppManager.getBoxReference(boxName).name;
147
+ const boxResult = await this._algod.getApplicationBoxByName(Number(appId), name).do();
148
+ return boxResult.value;
149
+ }
150
+ /**
151
+ * Returns the value of the given box names for the given app.
152
+ * @param appId The ID of the app return box names for
153
+ * @param boxNames The names of the boxes to return either as a string, binary array or `BoxName`
154
+ * @returns The current box values as a byte array in the same order as the passed in box names
155
+ */
156
+ async getBoxValues(appId, boxNames) {
157
+ return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValue(appId, boxName)));
158
+ }
159
+ /**
160
+ * Returns the value of the given box name for the given app decoded based on the given ABI type.
161
+ * @param request The parameters for the box value request
162
+ * @returns The current box value as an ABI value
163
+ */
164
+ async getBoxValueFromABIType(request) {
165
+ const { appId, boxName, type } = request;
166
+ const value = await this.getBoxValue(appId, boxName);
167
+ return type.decode(value);
168
+ }
169
+ /**
170
+ * Returns the value of the given box names for the given app decoded based on the given ABI type.
171
+ * @param request The parameters for the box value request
172
+ * @returns The current box values as an ABI value in the same order as the passed in box names
173
+ */
174
+ async getBoxValuesFromABIType(request) {
175
+ const { appId, boxNames, type } = request;
176
+ return await Promise.all(boxNames.map(async (boxName) => await this.getBoxValueFromABIType({ appId, boxName, type })));
177
+ }
178
+ /**
179
+ * Returns a `algosdk.BoxReference` given a `BoxIdentifier` or `BoxReference`.
180
+ * @param boxId The box to return a reference for
181
+ * @returns The box reference ready to pass into a `algosdk.Transaction`
182
+ */
183
+ static getBoxReference(boxId) {
184
+ const ref = typeof boxId === 'object' && 'appId' in boxId ? boxId : { appId: 0n, name: boxId };
185
+ return {
186
+ appIndex: ref.appId,
187
+ name: typeof ref.name === 'string' ? new TextEncoder().encode(ref.name) : 'length' in ref.name ? ref.name : ref.name.addr.publicKey,
188
+ };
189
+ }
190
+ /**
191
+ * Converts an array of global/local state values from the algod api to a more friendly
192
+ * generic object keyed by the UTF-8 value of the key.
193
+ * @param state A `global-state`, `local-state`, `global-state-deltas` or `local-state-deltas`
194
+ * @returns An object keyeed by the UTF-8 representation of the key with various parsings of the values
195
+ */
196
+ static decodeAppState(state) {
197
+ const stateValues = {};
198
+ // Start with empty set
199
+ for (const stateVal of state) {
200
+ const keyBase64 = Buffer.from(stateVal.key).toString('base64');
201
+ const keyRaw = stateVal.key;
202
+ const key = Buffer.from(stateVal.key).toString('utf-8');
203
+ const tealValue = stateVal.value;
204
+ const dataTypeFlag = 'action' in tealValue ? tealValue.action : tealValue.type;
205
+ let valueBase64;
206
+ let valueRaw;
207
+ switch (dataTypeFlag) {
208
+ case 1:
209
+ valueBase64 =
210
+ typeof tealValue.bytes === 'string' ? tealValue.bytes : tealValue.bytes ? Buffer.from(tealValue.bytes).toString('base64') : '';
211
+ valueRaw = Buffer.from(valueBase64, 'base64');
212
+ stateValues[key] = {
213
+ keyRaw,
214
+ keyBase64,
215
+ valueRaw: new Uint8Array(valueRaw),
216
+ valueBase64: valueBase64,
217
+ value: valueRaw.toString('utf-8'),
218
+ };
219
+ break;
220
+ case 2: {
221
+ const value = tealValue.uint ?? 0;
222
+ stateValues[key] = {
223
+ keyRaw,
224
+ keyBase64,
225
+ value: BigInt(value),
226
+ };
227
+ break;
228
+ }
229
+ default:
230
+ throw new Error(`Received unknown state data type of ${dataTypeFlag}`);
231
+ }
232
+ }
233
+ return stateValues;
234
+ }
235
+ /**
236
+ * Returns any ABI return values for the given app call arguments and transaction confirmation.
237
+ * @param confirmation The transaction confirmation from algod
238
+ * @param method The ABI method
239
+ * @returns The return value for the method call
240
+ */
241
+ static getABIReturn(confirmation, method) {
242
+ if (!method || !confirmation || method.returns.type === 'void') {
243
+ return undefined;
244
+ }
245
+ // The parseMethodResponse method mutates the second parameter :(
246
+ const resultDummy = {
247
+ txID: '',
248
+ method,
249
+ rawReturnValue: new Uint8Array(),
250
+ };
251
+ return transaction.getABIReturnValue(algosdk.AtomicTransactionComposer.parseMethodResponse(method, resultDummy, confirmation));
252
+ }
253
+ /**
254
+ * Replaces AlgoKit deploy-time deployment control parameters within the given TEAL template code.
255
+ *
256
+ * * `TMPL_UPDATABLE` for updatability / immutability control
257
+ * * `TMPL_DELETABLE` for deletability / permanence control
258
+ *
259
+ * Note: If these values are defined, but the corresponding `TMPL_*` value
260
+ * isn't in the teal code it will throw an exception.
261
+ *
262
+ * @param tealTemplateCode The TEAL template code to substitute
263
+ * @param params The deploy-time deployment control parameter value to replace
264
+ * @returns The replaced TEAL code
265
+ */
266
+ static replaceTealTemplateDeployTimeControlParams(tealTemplateCode, params) {
267
+ if (params.updatable !== undefined) {
268
+ if (!tealTemplateCode.includes(types_app.UPDATABLE_TEMPLATE_NAME)) {
269
+ throw new Error(`Deploy-time updatability control requested for app deployment, but ${types_app.UPDATABLE_TEMPLATE_NAME} not present in TEAL code`);
270
+ }
271
+ tealTemplateCode = replaceTemplateVariable(tealTemplateCode, types_app.UPDATABLE_TEMPLATE_NAME, (params.updatable ? 1 : 0).toString());
272
+ }
273
+ if (params.deletable !== undefined) {
274
+ if (!tealTemplateCode.includes(types_app.DELETABLE_TEMPLATE_NAME)) {
275
+ throw new Error(`Deploy-time deletability control requested for app deployment, but ${types_app.DELETABLE_TEMPLATE_NAME} not present in TEAL code`);
276
+ }
277
+ tealTemplateCode = replaceTemplateVariable(tealTemplateCode, types_app.DELETABLE_TEMPLATE_NAME, (params.deletable ? 1 : 0).toString());
278
+ }
279
+ return tealTemplateCode;
280
+ }
281
+ /**
282
+ * Performs template substitution of a teal file.
283
+ *
284
+ * Looks for `TMPL_{parameter}` for template replacements.
285
+ *
286
+ * @param tealTemplateCode The TEAL template code to make parameter replacements in
287
+ * @param templateParams Any parameters to replace in the teal code
288
+ * @returns The TEAL code with replacements
289
+ */
290
+ static replaceTealTemplateParams(tealTemplateCode, templateParams) {
291
+ if (templateParams !== undefined) {
292
+ for (const key in templateParams) {
293
+ const value = templateParams[key];
294
+ const token = `TMPL_${key.replace(/^TMPL_/, '')}`;
295
+ // If this is a number, first replace any byte representations of the number
296
+ // These may appear in the TEAL in order to circumvent int compression and preserve PC values
297
+ if (typeof value === 'number' || typeof value === 'bigint') {
298
+ tealTemplateCode = tealTemplateCode.replace(new RegExp(`(?<=bytes )${token}`, 'g'), `0x${value.toString(16).padStart(16, '0')}`);
299
+ // We could probably return here since mixing pushint and pushbytes is likely not going to happen, but might as well do both
300
+ }
301
+ tealTemplateCode = replaceTemplateVariable(tealTemplateCode, token, typeof value === 'string'
302
+ ? `0x${Buffer.from(value, 'utf-8').toString('hex')}`
303
+ : ArrayBuffer.isView(value)
304
+ ? `0x${Buffer.from(value).toString('hex')}`
305
+ : value.toString());
306
+ }
307
+ }
308
+ return tealTemplateCode;
309
+ }
310
+ /**
311
+ * Remove comments from TEAL code (useful to reduce code size before compilation).
312
+ *
313
+ * @param tealCode The TEAL logic to strip
314
+ * @returns The TEAL without comments
315
+ */
316
+ static stripTealComments(tealCode) {
317
+ const stripCommentFromLine = (line) => {
318
+ const commentIndex = findUnquotedString(line, '//');
319
+ if (commentIndex === undefined) {
320
+ return line;
321
+ }
322
+ return line.slice(0, commentIndex).trimEnd();
323
+ };
324
+ return tealCode
325
+ .split('\n')
326
+ .map((line) => stripCommentFromLine(line))
327
+ .join('\n');
328
+ }
329
+ }
330
+ /**
331
+ * Find the first string within a line of TEAL. Only matches outside of quotes and base64 are returned.
332
+ * Returns undefined if not found
333
+ */
334
+ const findUnquotedString = (line, token, startIndex = 0, _endIndex) => {
335
+ const endIndex = _endIndex === undefined ? line.length : _endIndex;
336
+ let index = startIndex;
337
+ let inQuotes = false;
338
+ let inBase64 = false;
339
+ while (index < endIndex) {
340
+ const currentChar = line[index];
341
+ if ((currentChar === ' ' || currentChar === '(') && !inQuotes && lastTokenBase64(line, index)) {
342
+ // enter base64
343
+ inBase64 = true;
344
+ }
345
+ else if ((currentChar === ' ' || currentChar === ')') && !inQuotes && inBase64) {
346
+ // exit base64
347
+ inBase64 = false;
348
+ }
349
+ else if (currentChar === '\\' && inQuotes) {
350
+ // escaped char, skip next character
351
+ index += 1;
352
+ }
353
+ else if (currentChar === '"') {
354
+ // quote boundary
355
+ inQuotes = !inQuotes;
356
+ }
357
+ else if (!inQuotes && !inBase64 && line.startsWith(token, index)) {
358
+ // can test for match
359
+ return index;
360
+ }
361
+ index += 1;
362
+ }
363
+ return undefined;
364
+ };
365
+ const lastTokenBase64 = (line, index) => {
366
+ try {
367
+ const tokens = line.slice(0, index).split(/\s+/);
368
+ const last = tokens[tokens.length - 1];
369
+ return ['base64', 'b64'].includes(last);
370
+ }
371
+ catch {
372
+ return false;
373
+ }
374
+ };
375
+ function replaceTemplateVariable(program, token, replacement) {
376
+ const result = [];
377
+ const tokenIndexOffset = replacement.length - token.length;
378
+ const programLines = program.split('\n');
379
+ for (const line of programLines) {
380
+ const _commentIndex = findUnquotedString(line, '//');
381
+ const commentIndex = _commentIndex === undefined ? line.length : _commentIndex;
382
+ let code = line.substring(0, commentIndex);
383
+ const comment = line.substring(commentIndex);
384
+ let trailingIndex = 0;
385
+ // eslint-disable-next-line no-constant-condition
386
+ while (true) {
387
+ const tokenIndex = findTemplateToken(code, token, trailingIndex);
388
+ if (tokenIndex === undefined) {
389
+ break;
390
+ }
391
+ trailingIndex = tokenIndex + token.length;
392
+ const prefix = code.substring(0, tokenIndex);
393
+ const suffix = code.substring(trailingIndex);
394
+ code = `${prefix}${replacement}${suffix}`;
395
+ trailingIndex += tokenIndexOffset;
396
+ }
397
+ result.push(code + comment);
398
+ }
399
+ return result.join('\n');
400
+ }
401
+ const findTemplateToken = (line, token, startIndex = 0, _endIndex) => {
402
+ const endIndex = line.length ;
403
+ let index = startIndex;
404
+ while (index < endIndex) {
405
+ const tokenIndex = findUnquotedString(line, token, index, endIndex);
406
+ if (tokenIndex === undefined) {
407
+ break;
408
+ }
409
+ const trailingIndex = tokenIndex + token.length;
410
+ if ((tokenIndex === 0 || !isValidTokenCharacter(line[tokenIndex - 1])) &&
411
+ (trailingIndex >= line.length || !isValidTokenCharacter(line[trailingIndex]))) {
412
+ return tokenIndex;
413
+ }
414
+ index = trailingIndex;
415
+ }
416
+ return undefined;
417
+ };
418
+ function isValidTokenCharacter(char) {
419
+ return char.length === 1 && (/\w/.test(char) || char === '_');
420
+ }
421
+
422
+ exports.AppManager = AppManager;
423
+ //# sourceMappingURL=app-manager.js.map