@algorandfoundation/algokit-utils 10.0.0-alpha.31 → 10.0.0-alpha.32

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 (318) hide show
  1. package/account-manager.d.ts +448 -0
  2. package/account-manager.js +623 -0
  3. package/account-manager.js.map +1 -0
  4. package/account-manager.mjs +620 -0
  5. package/account-manager.mjs.map +1 -0
  6. package/account.d.ts +156 -0
  7. package/account.js +10 -0
  8. package/account.js.map +1 -0
  9. package/account.mjs +9 -0
  10. package/account.mjs.map +1 -0
  11. package/algorand-client-transaction-creator.d.ts +1103 -0
  12. package/algorand-client-transaction-creator.js +735 -0
  13. package/algorand-client-transaction-creator.js.map +1 -0
  14. package/algorand-client-transaction-creator.mjs +734 -0
  15. package/algorand-client-transaction-creator.mjs.map +1 -0
  16. package/algorand-client-transaction-sender.d.ts +1317 -0
  17. package/algorand-client-transaction-sender.js +933 -0
  18. package/algorand-client-transaction-sender.js.map +1 -0
  19. package/algorand-client-transaction-sender.mjs +932 -0
  20. package/algorand-client-transaction-sender.mjs.map +1 -0
  21. package/algorand-client.d.ts +246 -0
  22. package/algorand-client.js +325 -0
  23. package/algorand-client.js.map +1 -0
  24. package/algorand-client.mjs +325 -0
  25. package/algorand-client.mjs.map +1 -0
  26. package/amount.d.ts +46 -3
  27. package/amount.js +92 -13
  28. package/amount.js.map +1 -1
  29. package/amount.mjs +80 -3
  30. package/amount.mjs.map +1 -1
  31. package/app-client.d.ts +2130 -0
  32. package/app-client.js +909 -0
  33. package/app-client.js.map +1 -0
  34. package/app-client.mjs +908 -0
  35. package/app-client.mjs.map +1 -0
  36. package/app-deployer.d.ts +166 -0
  37. package/app-deployer.js +353 -0
  38. package/app-deployer.js.map +1 -0
  39. package/app-deployer.mjs +353 -0
  40. package/app-deployer.mjs.map +1 -0
  41. package/app-factory.d.ts +965 -0
  42. package/app-factory.js +448 -0
  43. package/app-factory.js.map +1 -0
  44. package/app-factory.mjs +448 -0
  45. package/app-factory.mjs.map +1 -0
  46. package/app-manager.d.ts +323 -0
  47. package/app-manager.js +468 -0
  48. package/app-manager.js.map +1 -0
  49. package/app-manager.mjs +468 -0
  50. package/app-manager.mjs.map +1 -0
  51. package/app-spec.d.ts +203 -0
  52. package/app-spec.js +137 -0
  53. package/app-spec.js.map +1 -0
  54. package/app-spec.mjs +137 -0
  55. package/app-spec.mjs.map +1 -0
  56. package/app.d.ts +257 -0
  57. package/app.js +49 -0
  58. package/app.js.map +1 -0
  59. package/app.mjs +42 -0
  60. package/app.mjs.map +1 -0
  61. package/asset-manager.d.ts +212 -0
  62. package/asset-manager.js +166 -0
  63. package/asset-manager.js.map +1 -0
  64. package/asset-manager.mjs +166 -0
  65. package/asset-manager.mjs.map +1 -0
  66. package/async-event-emitter.d.ts +16 -0
  67. package/async-event-emitter.js +38 -0
  68. package/async-event-emitter.js.map +1 -0
  69. package/async-event-emitter.mjs +37 -0
  70. package/async-event-emitter.mjs.map +1 -0
  71. package/client-manager.d.ts +475 -0
  72. package/client-manager.js +616 -0
  73. package/client-manager.js.map +1 -0
  74. package/client-manager.mjs +616 -0
  75. package/client-manager.mjs.map +1 -0
  76. package/composer.d.ts +947 -0
  77. package/composer.js +1584 -0
  78. package/composer.js.map +1 -0
  79. package/composer.mjs +1583 -0
  80. package/composer.mjs.map +1 -0
  81. package/config.d.ts +1 -1
  82. package/config.js +2 -2
  83. package/config.js.map +1 -1
  84. package/config.mjs +1 -1
  85. package/config.mjs.map +1 -1
  86. package/debugging.d.ts +47 -0
  87. package/debugging.js +20 -0
  88. package/debugging.js.map +1 -0
  89. package/debugging.mjs +15 -0
  90. package/debugging.mjs.map +1 -0
  91. package/dispenser-client.d.ts +90 -0
  92. package/dispenser-client.js +127 -0
  93. package/dispenser-client.js.map +1 -0
  94. package/dispenser-client.mjs +127 -0
  95. package/dispenser-client.mjs.map +1 -0
  96. package/expand.d.ts +2 -0
  97. package/expand.js +0 -0
  98. package/expand.mjs +0 -0
  99. package/index.d.ts +6 -5
  100. package/index.js +4 -3
  101. package/index.mjs +5 -5
  102. package/indexer-client/indexer-lookup.d.ts +1 -1
  103. package/indexer-client/indexer-lookup.js.map +1 -1
  104. package/indexer-client/indexer-lookup.mjs.map +1 -1
  105. package/indexer.d.ts +40 -0
  106. package/indexer.js +38 -0
  107. package/indexer.js.map +1 -0
  108. package/indexer.mjs +35 -0
  109. package/indexer.mjs.map +1 -0
  110. package/instance-of.d.ts +8 -0
  111. package/kmd-account-manager.d.ts +74 -0
  112. package/kmd-account-manager.js +167 -0
  113. package/kmd-account-manager.js.map +1 -0
  114. package/kmd-account-manager.mjs +165 -0
  115. package/kmd-account-manager.mjs.map +1 -0
  116. package/lifecycle-events.d.ts +14 -0
  117. package/lifecycle-events.js +11 -0
  118. package/lifecycle-events.js.map +1 -0
  119. package/lifecycle-events.mjs +10 -0
  120. package/lifecycle-events.mjs.map +1 -0
  121. package/logging.d.ts +13 -0
  122. package/logging.js +47 -0
  123. package/logging.js.map +1 -0
  124. package/logging.mjs +42 -0
  125. package/logging.mjs.map +1 -0
  126. package/logic-error.d.ts +39 -0
  127. package/logic-error.js +54 -0
  128. package/logic-error.js.map +1 -0
  129. package/logic-error.mjs +53 -0
  130. package/logic-error.mjs.map +1 -0
  131. package/network-client.d.ts +43 -0
  132. package/network-client.js +14 -0
  133. package/network-client.js.map +1 -0
  134. package/network-client.mjs +13 -0
  135. package/network-client.mjs.map +1 -0
  136. package/package.json +11 -1
  137. package/testing/account.d.ts +2 -2
  138. package/testing/account.js +1 -1
  139. package/testing/account.js.map +1 -1
  140. package/testing/account.mjs +1 -1
  141. package/testing/account.mjs.map +1 -1
  142. package/testing/fixtures/algokit-log-capture-fixture.d.ts +1 -1
  143. package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
  144. package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
  145. package/testing/fixtures/algorand-fixture.d.ts +2 -2
  146. package/testing/fixtures/algorand-fixture.js +2 -2
  147. package/testing/fixtures/algorand-fixture.js.map +1 -1
  148. package/testing/fixtures/algorand-fixture.mjs +2 -2
  149. package/testing/fixtures/algorand-fixture.mjs.map +1 -1
  150. package/testing/index.d.ts +2 -1
  151. package/testing/test-logger.d.ts +1 -1
  152. package/testing/test-logger.js.map +1 -1
  153. package/testing/test-logger.mjs.map +1 -1
  154. package/testing/types.d.ts +156 -0
  155. package/transaction/index.d.ts +4 -0
  156. package/transaction/index.js +9 -0
  157. package/transaction/index.mjs +4 -0
  158. package/transaction/perform-transaction-composer-simulate.d.ts +1 -1
  159. package/transaction/perform-transaction-composer-simulate.js.map +1 -1
  160. package/transaction/perform-transaction-composer-simulate.mjs.map +1 -1
  161. package/transaction/transaction.d.ts +2 -2
  162. package/transaction/transaction.js.map +1 -1
  163. package/transaction/transaction.mjs.map +1 -1
  164. package/transaction/types.d.ts +133 -0
  165. package/transactions/app-call.d.ts +1 -1
  166. package/transactions/app-call.js +1 -1
  167. package/transactions/app-call.js.map +1 -1
  168. package/transactions/app-call.mjs +1 -1
  169. package/transactions/app-call.mjs.map +1 -1
  170. package/transactions/common.d.ts +1 -1
  171. package/transactions/common.js.map +1 -1
  172. package/transactions/common.mjs.map +1 -1
  173. package/transactions/method-call.d.ts +1 -1
  174. package/transactions/method-call.js +1 -1
  175. package/transactions/method-call.js.map +1 -1
  176. package/transactions/method-call.mjs +1 -1
  177. package/transactions/method-call.mjs.map +1 -1
  178. package/transactions/payment.d.ts +1 -1
  179. package/transactions/payment.js.map +1 -1
  180. package/transactions/payment.mjs.map +1 -1
  181. package/types/account-manager.d.ts +11 -442
  182. package/types/account-manager.js +5 -616
  183. package/types/account-manager.js.map +1 -1
  184. package/types/account-manager.mjs +5 -614
  185. package/types/account-manager.mjs.map +1 -1
  186. package/types/account.d.ts +8 -150
  187. package/types/account.js +3 -4
  188. package/types/account.js.map +1 -1
  189. package/types/account.mjs +4 -4
  190. package/types/account.mjs.map +1 -1
  191. package/types/algorand-client-transaction-creator.d.ts +5 -1098
  192. package/types/algorand-client-transaction-creator.js +3 -729
  193. package/types/algorand-client-transaction-creator.js.map +1 -1
  194. package/types/algorand-client-transaction-creator.mjs +4 -729
  195. package/types/algorand-client-transaction-creator.mjs.map +1 -1
  196. package/types/algorand-client-transaction-sender.d.ts +5 -1312
  197. package/types/algorand-client-transaction-sender.js +3 -927
  198. package/types/algorand-client-transaction-sender.js.map +1 -1
  199. package/types/algorand-client-transaction-sender.mjs +3 -926
  200. package/types/algorand-client-transaction-sender.mjs.map +1 -1
  201. package/types/algorand-client.d.ts +5 -241
  202. package/types/algorand-client.js +3 -319
  203. package/types/algorand-client.js.map +1 -1
  204. package/types/algorand-client.mjs +3 -319
  205. package/types/algorand-client.mjs.map +1 -1
  206. package/types/amount.d.ts +6 -45
  207. package/types/amount.js +3 -79
  208. package/types/amount.js.map +1 -1
  209. package/types/amount.mjs +4 -79
  210. package/types/amount.mjs.map +1 -1
  211. package/types/app-client.d.ts +75 -2125
  212. package/types/app-client.js +3 -903
  213. package/types/app-client.js.map +1 -1
  214. package/types/app-client.mjs +3 -902
  215. package/types/app-client.mjs.map +1 -1
  216. package/types/app-deployer.d.ts +21 -161
  217. package/types/app-deployer.js +3 -347
  218. package/types/app-deployer.js.map +1 -1
  219. package/types/app-deployer.mjs +3 -347
  220. package/types/app-deployer.mjs.map +1 -1
  221. package/types/app-factory.d.ts +21 -960
  222. package/types/app-factory.js +3 -442
  223. package/types/app-factory.js.map +1 -1
  224. package/types/app-factory.mjs +3 -442
  225. package/types/app-factory.mjs.map +1 -1
  226. package/types/app-manager.d.ts +15 -318
  227. package/types/app-manager.js +3 -462
  228. package/types/app-manager.js.map +1 -1
  229. package/types/app-manager.mjs +3 -462
  230. package/types/app-manager.mjs.map +1 -1
  231. package/types/app-spec.d.ts +39 -198
  232. package/types/app-spec.js +3 -131
  233. package/types/app-spec.js.map +1 -1
  234. package/types/app-spec.mjs +3 -131
  235. package/types/app-spec.mjs.map +1 -1
  236. package/types/app.d.ts +62 -247
  237. package/types/app.js +15 -37
  238. package/types/app.js.map +1 -1
  239. package/types/app.mjs +16 -37
  240. package/types/app.mjs.map +1 -1
  241. package/types/asset-manager.d.ts +9 -207
  242. package/types/asset-manager.js +3 -160
  243. package/types/asset-manager.js.map +1 -1
  244. package/types/asset-manager.mjs +3 -160
  245. package/types/asset-manager.mjs.map +1 -1
  246. package/types/async-event-emitter.d.ts +7 -11
  247. package/types/async-event-emitter.js +3 -32
  248. package/types/async-event-emitter.js.map +1 -1
  249. package/types/async-event-emitter.mjs +4 -32
  250. package/types/async-event-emitter.mjs.map +1 -1
  251. package/types/client-manager.d.ts +27 -470
  252. package/types/client-manager.js +3 -610
  253. package/types/client-manager.js.map +1 -1
  254. package/types/client-manager.mjs +3 -610
  255. package/types/client-manager.mjs.map +1 -1
  256. package/types/composer.d.ts +79 -943
  257. package/types/composer.js +3 -1578
  258. package/types/composer.js.map +1 -1
  259. package/types/composer.mjs +3 -1577
  260. package/types/composer.mjs.map +1 -1
  261. package/types/config.d.ts +7 -52
  262. package/types/config.js +3 -74
  263. package/types/config.js.map +1 -1
  264. package/types/config.mjs +3 -74
  265. package/types/config.mjs.map +1 -1
  266. package/types/debugging.d.ts +12 -37
  267. package/types/debugging.js +11 -10
  268. package/types/debugging.js.map +1 -1
  269. package/types/debugging.mjs +12 -10
  270. package/types/debugging.mjs.map +1 -1
  271. package/types/dispenser-client.d.ts +11 -85
  272. package/types/dispenser-client.js +3 -121
  273. package/types/dispenser-client.js.map +1 -1
  274. package/types/dispenser-client.mjs +3 -121
  275. package/types/dispenser-client.mjs.map +1 -1
  276. package/types/expand.d.ts +8 -2
  277. package/types/indexer.d.ts +16 -36
  278. package/types/indexer.js +7 -30
  279. package/types/indexer.js.map +1 -1
  280. package/types/indexer.mjs +8 -30
  281. package/types/indexer.mjs.map +1 -1
  282. package/types/instance-of.d.ts +4 -4
  283. package/types/kmd-account-manager.d.ts +5 -69
  284. package/types/kmd-account-manager.js +3 -161
  285. package/types/kmd-account-manager.js.map +1 -1
  286. package/types/kmd-account-manager.mjs +3 -159
  287. package/types/kmd-account-manager.mjs.map +1 -1
  288. package/types/lifecycle-events.d.ts +7 -9
  289. package/types/lifecycle-events.js +3 -5
  290. package/types/lifecycle-events.js.map +1 -1
  291. package/types/lifecycle-events.mjs +4 -5
  292. package/types/lifecycle-events.mjs.map +1 -1
  293. package/types/logging.d.ts +14 -9
  294. package/types/logging.js +11 -37
  295. package/types/logging.js.map +1 -1
  296. package/types/logging.mjs +12 -37
  297. package/types/logging.mjs.map +1 -1
  298. package/types/logic-error.d.ts +8 -35
  299. package/types/logic-error.js +3 -48
  300. package/types/logic-error.js.map +1 -1
  301. package/types/logic-error.mjs +4 -48
  302. package/types/logic-error.mjs.map +1 -1
  303. package/types/network-client.d.ts +10 -39
  304. package/types/network-client.js +3 -8
  305. package/types/network-client.js.map +1 -1
  306. package/types/network-client.mjs +4 -8
  307. package/types/network-client.mjs.map +1 -1
  308. package/types/testing.d.ts +13 -151
  309. package/types/transaction.d.ts +33 -128
  310. package/updatable-config.d.ts +57 -0
  311. package/updatable-config.js +80 -0
  312. package/updatable-config.js.map +1 -0
  313. package/updatable-config.mjs +80 -0
  314. package/updatable-config.mjs.map +1 -0
  315. package/util.js +1 -1
  316. package/util.js.map +1 -1
  317. package/util.mjs +1 -1
  318. package/util.mjs.map +1 -1
@@ -1,621 +1,10 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
- const require_address = require('../packages/common/src/address.js');
3
- const require_amount = require('./amount.js');
4
- const require_config = require('../config.js');
5
- const require_util = require('../util.js');
6
- const require_index = require('../packages/algo25/src/index.js');
7
- const require_signer = require('../packages/transact/src/signer.js');
8
- const require_multisig = require('../packages/transact/src/multisig.js');
9
- const require_logicsig = require('../packages/transact/src/logicsig.js');
10
- const require_account = require('./account.js');
11
- const require_composer = require('./composer.js');
12
- const require_kmd_account_manager = require('./kmd-account-manager.js');
13
- let tweetnacl = require("tweetnacl");
14
- tweetnacl = require_rolldown_runtime.__toESM(tweetnacl);
1
+ const require_account_manager = require('../account-manager.js');
15
2
 
16
3
  //#region src/types/account-manager.ts
17
- /**
18
- * Returns a `TransactionSigner` for the given account that can sign a transaction.
19
- * This function has memoization, so will return the same transaction signer for a given account.
20
- * @param account An account that can sign a transaction
21
- * @returns A transaction signer
22
- * @example
23
- * ```typescript
24
- * const signer = getAccountTransactionSigner(account)
25
- * ```
26
- */
27
- const getAccountTransactionSigner = require_util.memoize(function(account) {
28
- return account.signer;
29
- });
30
- /** Creates and keeps track of signing accounts that can sign transactions for a sending address. */
31
- var AccountManager = class {
32
- _clientManager;
33
- _kmdAccountManager;
34
- _accounts = {};
35
- _defaultSigner;
36
- /**
37
- * Create a new account manager.
38
- * @param clientManager The ClientManager client to use for algod and kmd clients
39
- * @example Create a new account manager
40
- * ```typescript
41
- * const accountManager = new AccountManager(clientManager)
42
- * ```
43
- */
44
- constructor(clientManager) {
45
- this._clientManager = clientManager;
46
- this._kmdAccountManager = new require_kmd_account_manager.KmdAccountManager(clientManager);
47
- }
48
- _getComposer(getSuggestedParams) {
49
- return new require_composer.TransactionComposer({
50
- algod: this._clientManager.algod,
51
- getSigner: this.getSigner.bind(this),
52
- getSuggestedParams: getSuggestedParams ?? (() => this._clientManager.algod.suggestedParams())
53
- });
54
- }
55
- /**
56
- * KMD account manager that allows you to easily get and create accounts using KMD.
57
- * @returns The `KmdAccountManager` instance.
58
- * @example
59
- * ```typescript
60
- * const kmdManager = accountManager.kmd;
61
- * ```
62
- */
63
- get kmd() {
64
- return this._kmdAccountManager;
65
- }
66
- /**
67
- * Sets the default signer to use if no other signer is specified.
68
- *
69
- * If this isn't set an a transaction needs signing for a given sender
70
- * then an error will be thrown from `getSigner` / `getAccount`.
71
- * @param signer The signer to use, either a `TransactionSigner` or a `AddressWithSigner`
72
- * @example
73
- * ```typescript
74
- * const signer = accountManager.random() // Can be anything that returns a `TransactionSigner` or `AddressWithSigner`
75
- * accountManager.setDefaultSigner(signer)
76
- *
77
- * // When signing a transaction, if there is no signer registered for the sender then the default signer will be used
78
- * const signer = accountManager.getSigner("SENDERADDRESS")
79
- * ```
80
- * @returns The `AccountManager` so method calls can be chained
81
- */
82
- setDefaultSigner(signer) {
83
- this._defaultSigner = "signer" in signer ? signer.signer : signer;
84
- return this;
85
- }
86
- /**
87
- * Records the given account (that can sign) against the address of the provided account for later
88
- * retrieval and returns a `AddressWithTransactionSigner` along with the original account in an `account` property.
89
- */
90
- signerAccount(account) {
91
- const signer = getAccountTransactionSigner(account);
92
- const acc = {
93
- addr: account.addr,
94
- signer
95
- };
96
- this._accounts[acc.addr.toString()] = acc;
97
- const addressWithAccount = require_address.Address.fromString(acc.addr.toString());
98
- addressWithAccount.account = account;
99
- addressWithAccount.addr = acc.addr;
100
- addressWithAccount.signer = signer;
101
- return addressWithAccount;
102
- }
103
- /**
104
- * Tracks the given account for later signing.
105
- *
106
- * Note: If you are generating accounts via the various methods on `AccountManager`
107
- * (like `random`, `fromMnemonic`, `logicsig`, etc.) then they automatically get tracked.
108
- * @param account The account to register, which can be a `AddressWithSigner` or
109
- * a `algosdk.Account`, `algosdk.LogicSigAccount`, `SigningAccount` or `MultisigAccount`
110
- * @example
111
- * ```typescript
112
- * const accountManager = new AccountManager(clientManager)
113
- * .setSignerFromAccount(algosdk.generateAccount())
114
- * .setSignerFromAccount(new algosdk.LogicSigAccount(program, args))
115
- * .setSignerFromAccount(new SigningAccount(mnemonic, sender))
116
- * .setSignerFromAccount(new MultisigAccount({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]}, [account1, account2]))
117
- * .setSignerFromAccount({addr: "SENDERADDRESS", signer: transactionSigner})
118
- * ```
119
- * @returns The `AccountManager` instance for method chaining
120
- */
121
- setSignerFromAccount(account) {
122
- this.signerAccount(account);
123
- return this;
124
- }
125
- /**
126
- * Tracks the given `TransactionSigner` against the given sender address for later signing.
127
- * @param sender The sender address to use this signer for
128
- * @param signer The `TransactionSigner` to sign transactions with for the given sender
129
- * @example
130
- * ```typescript
131
- * const accountManager = new AccountManager(clientManager)
132
- * .setSigner("SENDERADDRESS", transactionSigner)
133
- * ```
134
- * @returns The `AccountManager` instance for method chaining
135
- */
136
- setSigner(sender, signer) {
137
- this._accounts[require_address.getAddress(sender).toString()] = {
138
- addr: require_address.getAddress(sender),
139
- signer
140
- };
141
- return this;
142
- }
143
- /**
144
- * Takes all registered signers from the given `AccountManager` and adds them to this `AccountManager`.
145
- *
146
- * This is useful for situations where you have multiple contexts you are building accounts in such as unit tests.
147
- * @param anotherAccountManager Another account manager with signers registered
148
- * @param overwriteExisting Whether or not to overwrite any signers that have the same sender address with the ones in the other account manager or not (default: true)
149
- * @returns The `AccountManager` instance for method chaining
150
- * @example
151
- * ```typescript
152
- * accountManager2.setSigners(accountManager1);
153
- * ```
154
- */
155
- setSigners(anotherAccountManager, overwriteExisting = true) {
156
- this._accounts = overwriteExisting ? {
157
- ...this._accounts,
158
- ...anotherAccountManager._accounts
159
- } : {
160
- ...anotherAccountManager._accounts,
161
- ...this._accounts
162
- };
163
- return this;
164
- }
165
- /**
166
- * Returns the `TransactionSigner` for the given sender address, ready to sign a transaction for that sender.
167
- *
168
- * If no signer has been registered for that address then the default signer is used if registered and
169
- * if not then an error is thrown.
170
- *
171
- * @param sender The sender address
172
- * @example
173
- * ```typescript
174
- * const signer = accountManager.getSigner("SENDERADDRESS")
175
- * ```
176
- * @returns The `TransactionSigner` or throws an error if not found and no default signer is set
177
- */
178
- getSigner(sender) {
179
- const signer = this._accounts[require_address.getAddress(sender).toString()]?.signer ?? this._defaultSigner;
180
- if (!signer) throw new Error(`No signer found for address ${sender}`);
181
- return signer;
182
- }
183
- /**
184
- * Returns the `AddressWithSigner` for the given sender address.
185
- *
186
- * If no signer has been registered for that address then an error is thrown.
187
- * @param sender The sender address
188
- * @example
189
- * ```typescript
190
- * const sender = accountManager.random()
191
- * // ...
192
- * // Returns the `AddressWithSigner` for `sender` that has previously been registered
193
- * const account = accountManager.getAccount(sender)
194
- * ```
195
- * @returns The `AddressWithSigner` or throws an error if not found
196
- */
197
- getAccount(sender) {
198
- const account = this._accounts[require_address.getAddress(sender).toString()];
199
- if (!account) throw new Error(`No signer found for address ${sender}`);
200
- return account;
201
- }
202
- /**
203
- * Returns the given sender account's current status, balance and spendable amounts.
204
- *
205
- * [Response data schema details](https://dev.algorand.co/reference/rest-apis/algod/#accountinformation)
206
- * @example
207
- * ```typescript
208
- * const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
209
- * const accountInfo = await accountManager.getInformation(address);
210
- * ```
211
- *
212
- * @param sender The account / address to look up
213
- * @returns The account information
214
- */
215
- async getInformation(sender) {
216
- const senderAddress = require_address.getAddress(sender).toString();
217
- const { round, lastHeartbeat = void 0, lastProposed = void 0, address, ...account } = await this._clientManager.algod.accountInformation(senderAddress);
218
- return {
219
- ...account,
220
- authAddr: account.authAddr,
221
- address,
222
- balance: require_amount.AlgoAmount.MicroAlgo(Number(account.amount)),
223
- amountWithoutPendingRewards: require_amount.AlgoAmount.MicroAlgo(Number(account.amountWithoutPendingRewards)),
224
- minBalance: require_amount.AlgoAmount.MicroAlgo(Number(account.minBalance)),
225
- pendingRewards: require_amount.AlgoAmount.MicroAlgo(Number(account.pendingRewards)),
226
- rewards: require_amount.AlgoAmount.MicroAlgo(Number(account.rewards)),
227
- validAsOfRound: BigInt(round),
228
- totalAppsOptedIn: Number(account.totalAppsOptedIn),
229
- totalAssetsOptedIn: Number(account.totalAssetsOptedIn),
230
- totalCreatedApps: Number(account.totalCreatedApps),
231
- totalCreatedAssets: Number(account.totalCreatedAssets),
232
- appsTotalExtraPages: account.appsTotalExtraPages !== void 0 ? Number(account.appsTotalExtraPages) : void 0,
233
- rewardBase: account.rewardBase !== void 0 ? Number(account.rewardBase) : void 0,
234
- totalBoxBytes: account.totalBoxBytes !== void 0 ? Number(account.totalBoxBytes) : void 0,
235
- totalBoxes: account.totalBoxes !== void 0 ? Number(account.totalBoxes) : void 0,
236
- lastHeartbeatRound: lastHeartbeat !== void 0 ? BigInt(lastHeartbeat) : void 0,
237
- lastProposedRound: lastProposed !== void 0 ? BigInt(lastProposed) : void 0
238
- };
239
- }
240
- /**
241
- * Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
242
- *
243
- * @example
244
- * ```typescript
245
- * const account = accountManager.fromMnemonic("mnemonic secret ...")
246
- * const rekeyedAccount = accountManager.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
247
- * ```
248
- * @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
249
- * never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
250
- * @param sender The optional sender address to use this signer for (aka a rekeyed account)
251
- * @returns The account
252
- */
253
- fromMnemonic(mnemonicSecret, sender) {
254
- const seed = require_index.seedFromMnemonic(mnemonicSecret);
255
- const keypair = tweetnacl.default.sign.keyPair.fromSeed(seed);
256
- const addrWithSigners = require_signer.generateAddressWithSigners({
257
- ed25519Pubkey: keypair.publicKey,
258
- sendingAddress: require_address.getOptionalAddress(sender),
259
- rawEd25519Signer: async (bytesToSign) => {
260
- return tweetnacl.default.sign.detached(bytesToSign, keypair.secretKey);
261
- }
262
- });
263
- return this.signerAccount(addrWithSigners);
264
- }
265
- /**
266
- * Tracks and returns an Algorand account that is a rekeyed version of the given account to a new sender.
267
- *
268
- * @example
269
- * ```typescript
270
- * const account = accountManager.fromMnemonic("mnemonic secret ...")
271
- * const rekeyedAccount = accountManager.rekeyed(account, "SENDERADDRESS...")
272
- * ```
273
- * @param account The account to use as the signer for this new rekeyed account
274
- * @param sender The sender address to use as the new sender
275
- * @returns The account
276
- */
277
- rekeyed(sender, account) {
278
- return this.signerAccount({
279
- addr: require_address.getAddress(sender),
280
- signer: account.signer
281
- });
282
- }
283
- /**
284
- * Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
285
- *
286
- * Note: This function expects to run in a Node.js environment.
287
- *
288
- * ## Convention:
289
- * * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
290
- * never commit it into source control and ideally load it via a secret storage service rather than the file system.
291
- * If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
292
- * * **LocalNet:** will load the account from a KMD wallet called \{NAME\} and if that wallet doesn't exist it will create it and fund the account for you
293
- *
294
- * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).
295
- *
296
- * @example Default
297
- *
298
- * If you have a mnemonic secret loaded into `process.env.MY_ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:
299
- * ```typescript
300
- * const account = await accountManager.fromEnvironment('MY_ACCOUNT')
301
- * ```
302
- *
303
- * If that code runs against LocalNet then a wallet called `MY_ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.
304
- * If not running against LocalNet then it will use proces.env.MY_ACCOUNT_MNEMONIC as the private key and (if present) process.env.MY_ACCOUNT_SENDER as the sender address.
305
- *
306
- * @param name The name identifier of the account
307
- * @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account
308
- * @returns The account
309
- */
310
- async fromEnvironment(name, fundWith) {
311
- if (!process || !process.env) throw new Error("Attempt to get account with private key from a non Node.js context; this is not supported!");
312
- const accountMnemonic = process.env[`${name.toUpperCase()}_MNEMONIC`];
313
- const sender = process.env[`${name.toUpperCase()}_SENDER`];
314
- if (accountMnemonic) return this.fromMnemonic(accountMnemonic, sender);
315
- if (await this._clientManager.isLocalNet()) {
316
- const account = await this._kmdAccountManager.getOrCreateWalletAccount(name, fundWith);
317
- return this.signerAccount(account);
318
- }
319
- throw new Error(`Missing environment variable ${name.toUpperCase()}_MNEMONIC when looking for account ${name}`);
320
- }
321
- /**
322
- * Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
323
- *
324
- * @param name The name of the wallet to retrieve an account from
325
- * @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)
326
- * @param sender The optional sender address to use this signer for (aka a rekeyed account)
327
- * @example Get default funded account in a LocalNet
328
- *
329
- * ```typescript
330
- * const defaultDispenserAccount = await accountManager.fromKmd('unencrypted-default-wallet',
331
- * a => a.status !== 'Offline' && a.amount > 1_000_000_000
332
- * )
333
- * ```
334
- * @returns The account
335
- */
336
- async fromKmd(name, predicate, sender) {
337
- const account = await this._kmdAccountManager.getWalletAccount(name, predicate, sender);
338
- if (!account) throw new Error(`Unable to find KMD account ${name}${predicate ? " with predicate" : ""}`);
339
- return this.signerAccount(account);
340
- }
341
- /**
342
- * Tracks and returns an account that supports partial or full multisig signing.
343
- *
344
- * @example
345
- * ```typescript
346
- * const account = accountManager.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
347
- * [(await accountManager.fromEnvironment('ACCOUNT1')).account])
348
- * ```
349
- * @param multisigParams The parameters that define the multisig account
350
- * @param subSigners The signers that are currently present
351
- * @returns A multisig account wrapper
352
- */
353
- multisig(multisigParams, subSigners) {
354
- return this.signerAccount(new require_multisig.MultisigAccount(multisigParams, subSigners));
355
- }
356
- /**
357
- * Tracks and returns an account that represents a logic signature.
358
- *
359
- * @example
360
- * ```typescript
361
- * const account = accountManager.logicsig(program, [new Uint8Array(3, ...)])
362
- * ```
363
- * @param program The bytes that make up the compiled logic signature
364
- * @param args The (binary) arguments to pass into the logic signature
365
- * @returns A logic signature account wrapper
366
- */
367
- logicsig(program, args) {
368
- return this.signerAccount(new require_logicsig.LogicSigAccount(program, args));
369
- }
370
- /**
371
- * Tracks and returns a new, random Algorand account with secret key loaded.
372
- *
373
- * @example
374
- * ```typescript
375
- * const account = accountManager.random()
376
- * ```
377
- * @returns The account
378
- */
379
- random() {
380
- const keypair = tweetnacl.default.sign.keyPair();
381
- const rawSigner = async (bytesToSign) => {
382
- return tweetnacl.default.sign.detached(bytesToSign, keypair.secretKey);
383
- };
384
- const addrWithSigners = require_signer.generateAddressWithSigners({
385
- ed25519Pubkey: keypair.publicKey,
386
- rawEd25519Signer: rawSigner
387
- });
388
- this._accounts[addrWithSigners.addr.toString()] = addrWithSigners;
389
- const acct = addrWithSigners.addr;
390
- for (const prop in addrWithSigners) {
391
- if (prop === "addr") {
392
- acct.addr = new require_address.Address(addrWithSigners.addr.publicKey);
393
- continue;
394
- }
395
- acct[prop] = addrWithSigners[prop];
396
- }
397
- return acct;
398
- }
399
- /**
400
- * Returns an account (with private key loaded) that can act as a dispenser from
401
- * environment variables, or against default LocalNet if no environment variables present.
402
- *
403
- * Note: requires a Node.js environment to execute.
404
- *
405
- * If present, it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC and optionally
406
- * process.env.DISPENSER_SENDER if it's a rekeyed account.
407
- *
408
- * @example
409
- * ```typescript
410
- * const account = await accountManager.dispenserFromEnvironment()
411
- * ```
412
- *
413
- * @returns The account
414
- */
415
- async dispenserFromEnvironment() {
416
- if (!process || !process.env) throw new Error("Attempt to get dispenser from environment from a non Node.js context; this is not supported!");
417
- return process.env[`${require_account.DISPENSER_ACCOUNT.toUpperCase()}_MNEMONIC`] ? await this.fromEnvironment(require_account.DISPENSER_ACCOUNT) : await this.localNetDispenser();
418
- }
419
- /**
420
- * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
421
- *
422
- * @example
423
- * ```typescript
424
- * const account = await accountManager.localNetDispenser()
425
- * ```
426
- * @returns The account
427
- */
428
- async localNetDispenser() {
429
- const dispenser = await this._kmdAccountManager.getLocalNetDispenserAccount();
430
- return this.signerAccount(dispenser);
431
- }
432
- /**
433
- * Rekey an account to a new address.
434
- *
435
- * **Note:** Please be careful with this function and be sure to read the [official rekey guidance](https://dev.algorand.co/concepts/accounts/rekeying).
436
- *
437
- * @param account The account to rekey
438
- * @param rekeyTo The account address or signing account of the account that will be used to authorise transactions for the rekeyed account going forward.
439
- * If a signing account is provided that will now be tracked as the signer for `account` in this `AccountManager`
440
- * @param options Any parameters to control the transaction or execution of the transaction
441
- *
442
- * @example Basic example (with string addresses)
443
- * ```typescript
444
- * await accountManager.rekeyAccount({account: "ACCOUNTADDRESS", rekeyTo: "NEWADDRESS"})
445
- * ```
446
- * @example Basic example (with signer accounts)
447
- * ```typescript
448
- * await accountManager.rekeyAccount({account: account1, rekeyTo: newSignerAccount})
449
- * ```
450
- * @example Advanced example
451
- * ```typescript
452
- * await accountManager.rekeyAccount({
453
- * account: "ACCOUNTADDRESS",
454
- * rekeyTo: "NEWADDRESS",
455
- * lease: 'lease',
456
- * note: 'note',
457
- * firstValidRound: 1000n,
458
- * validityWindow: 10,
459
- * extraFee: (1000).microAlgo(),
460
- * staticFee: (1000).microAlgo(),
461
- * // Max fee doesn't make sense with extraFee AND staticFee
462
- * // already specified, but here for completeness
463
- * maxFee: (3000).microAlgo(),
464
- * maxRoundsToWaitForConfirmation: 5,
465
- * suppressLog: true,
466
- * })
467
- * ```
468
- * @returns The result of the transaction and the transaction that was sent
469
- */
470
- async rekeyAccount(account, rekeyTo, options) {
471
- const result = await this._getComposer().addPayment({
472
- ...options,
473
- sender: require_address.getAddress(account),
474
- receiver: require_address.getAddress(account),
475
- amount: require_amount.AlgoAmount.MicroAlgo(0),
476
- rekeyTo: require_address.getAddress(rekeyTo)
477
- }).send(options);
478
- if (typeof rekeyTo === "object" && "addr" in rekeyTo) this.rekeyed(account, rekeyTo);
479
- require_config.Config.getLogger(options?.suppressLog).info(`Rekeyed ${account} to ${rekeyTo} via transaction ${result.txIds.at(-1)}`);
480
- return {
481
- ...result,
482
- transaction: result.transactions.at(-1),
483
- confirmation: result.confirmations.at(-1)
484
- };
485
- }
486
- async _getEnsureFundedAmount(sender, minSpendingBalance, minFundingIncrement) {
487
- const accountInfo = await this.getInformation(sender);
488
- const currentSpendingBalance = accountInfo.balance.microAlgo - accountInfo.minBalance.microAlgo;
489
- const amountFunded = require_util.calculateFundAmount(minSpendingBalance.microAlgo, currentSpendingBalance, minFundingIncrement?.microAlgo ?? 0n);
490
- return amountFunded === null ? void 0 : require_amount.AlgoAmount.MicroAlgo(amountFunded);
491
- }
492
- /**
493
- * Funds a given account using a dispenser account as a funding source such that
494
- * the given account has a certain amount of Algo free to spend (accounting for
495
- * Algo locked in minimum balance requirement).
496
- *
497
- * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
498
- *
499
- * @param accountToFund The account to fund
500
- * @param dispenserAccount The account to use as a dispenser funding source
501
- * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
502
- * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
503
- * @example Example using AlgorandClient
504
- * ```typescript
505
- * // Basic example
506
- * await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1))
507
- * // With configuration
508
- * await accountManager.ensureFunded("ACCOUNTADDRESS", "DISPENSERADDRESS", algokit.algo(1),
509
- * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
510
- * )
511
- * ```
512
- * @returns
513
- * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
514
- * - `undefined` if no funds were needed.
515
- */
516
- async ensureFunded(accountToFund, dispenserAccount, minSpendingBalance, options) {
517
- const addressToFund = require_address.getAddress(accountToFund);
518
- const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
519
- if (!amountFunded) return void 0;
520
- const result = await this._getComposer().addPayment({
521
- ...options,
522
- sender: require_address.getAddress(dispenserAccount),
523
- receiver: addressToFund,
524
- amount: amountFunded
525
- }).send(options);
526
- return {
527
- ...result,
528
- transaction: result.transactions[0],
529
- confirmation: result.confirmations[0],
530
- transactionId: result.txIds[0],
531
- amountFunded
532
- };
533
- }
534
- /**
535
- * Funds a given account using a dispenser account retrieved from the environment,
536
- * per the `dispenserFromEnvironment` method, as a funding source such that
537
- * the given account has a certain amount of Algo free to spend (accounting for
538
- * Algo locked in minimum balance requirement).
539
- *
540
- * **Note:** requires a Node.js environment to execute.
541
- *
542
- * The dispenser account is retrieved from the account mnemonic stored in
543
- * process.env.DISPENSER_MNEMONIC and optionally process.env.DISPENSER_SENDER
544
- * if it's a rekeyed account, or against default LocalNet if no environment variables present.
545
- *
546
- * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
547
- *
548
- * @param accountToFund The account to fund
549
- * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
550
- * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
551
- * @example Example using AlgorandClient
552
- * ```typescript
553
- * // Basic example
554
- * await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1))
555
- * // With configuration
556
- * await accountManager.ensureFundedFromEnvironment("ACCOUNTADDRESS", algokit.algo(1),
557
- * { minFundingIncrement: algokit.algo(2), fee: (1000).microAlgo(), suppressLog: true }
558
- * )
559
- * ```
560
- * @returns
561
- * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
562
- * - `undefined` if no funds were needed.
563
- */
564
- async ensureFundedFromEnvironment(accountToFund, minSpendingBalance, options) {
565
- const addressToFund = require_address.getAddress(accountToFund);
566
- const dispenserAccount = await this.dispenserFromEnvironment();
567
- const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
568
- if (!amountFunded) return void 0;
569
- const result = await this._getComposer().addPayment({
570
- ...options,
571
- sender: dispenserAccount,
572
- receiver: addressToFund,
573
- amount: amountFunded
574
- }).send(options);
575
- return {
576
- ...result,
577
- transaction: result.transactions[0],
578
- confirmation: result.confirmations[0],
579
- transactionId: result.txIds[0],
580
- amountFunded
581
- };
582
- }
583
- /**
584
- * Funds a given account using the TestNet Dispenser API as a funding source such that
585
- * the account has a certain amount of Algo free to spend (accounting for Algo locked
586
- * in minimum balance requirement).
587
- *
588
- * https://dev.algorand.co/concepts/smart-contracts/costs-constraints#mbr
589
- *
590
- * @param accountToFund The account to fund
591
- * @param dispenserClient The TestNet dispenser funding client
592
- * @param minSpendingBalance The minimum balance of Algo that the account should have available to spend (i.e. on top of minimum balance requirement)
593
- * @param options Optional parameters to control the funding increment, transaction or execution of the transaction
594
- * @example Example using AlgorandClient
595
- * ```typescript
596
- * // Basic example
597
- * await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1))
598
- * // With configuration
599
- * await accountManager.ensureFundedFromTestNetDispenserApi("ACCOUNTADDRESS", algorand.client.getTestNetDispenserFromEnvironment(), algokit.algo(1),
600
- * { minFundingIncrement: algokit.algo(2) }
601
- * )
602
- * ```
603
- * @returns
604
- * - The result of executing the dispensing transaction and the `amountFunded` if funds were needed.
605
- * - `undefined` if no funds were needed.
606
- */
607
- async ensureFundedFromTestNetDispenserApi(accountToFund, dispenserClient, minSpendingBalance, options) {
608
- if (!await this._clientManager.isTestNet()) throw new Error("Attempt to fund using TestNet dispenser API on non TestNet network.");
609
- const addressToFund = require_address.getAddress(accountToFund);
610
- const amountFunded = await this._getEnsureFundedAmount(addressToFund, minSpendingBalance, options?.minFundingIncrement);
611
- if (!amountFunded) return void 0;
612
- const result = await dispenserClient.fund(addressToFund, amountFunded.microAlgo);
613
- return {
614
- amountFunded: require_amount.AlgoAmount.MicroAlgo(result.amount),
615
- transactionId: result.txId
616
- };
617
- }
618
- };
4
+ /** @deprecated Import from `@algorandfoundation/algokit-utils/account-manager` instead */
5
+ const AccountManager = require_account_manager.AccountManager;
6
+ /** @deprecated Import from `@algorandfoundation/algokit-utils/account-manager` instead */
7
+ const getAccountTransactionSigner = require_account_manager.getAccountTransactionSigner;
619
8
 
620
9
  //#endregion
621
10
  exports.AccountManager = AccountManager;