@algorandfoundation/algokit-utils 6.0.0-beta.3 → 6.0.0-beta.5
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.
- package/account/account.d.ts +33 -1
- package/account/account.d.ts.map +1 -1
- package/account/account.js +63 -0
- package/account/account.js.map +1 -1
- package/account/account.mjs +62 -1
- package/account/account.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +5 -0
- package/index.js.map +1 -1
- package/index.mjs +3 -2
- package/index.mjs.map +1 -1
- package/indexer-lookup.d.ts +11 -2
- package/indexer-lookup.d.ts.map +1 -1
- package/indexer-lookup.js +33 -1
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs +33 -2
- package/indexer-lookup.mjs.map +1 -1
- package/package.json +1 -1
- package/testing/fixtures/algorand-fixture.d.ts.map +1 -1
- package/testing/fixtures/algorand-fixture.js +15 -2
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs +15 -2
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/types/account-manager.d.ts +211 -0
- package/types/account-manager.d.ts.map +1 -0
- package/types/account-manager.js +265 -0
- package/types/account-manager.js.map +1 -0
- package/types/account-manager.mjs +263 -0
- package/types/account-manager.mjs.map +1 -0
- package/types/account.d.ts +19 -0
- package/types/account.d.ts.map +1 -1
- package/types/account.js.map +1 -1
- package/types/account.mjs.map +1 -1
- package/types/algorand-client.d.ts +183 -0
- package/types/algorand-client.d.ts.map +1 -0
- package/types/algorand-client.js +296 -0
- package/types/algorand-client.js.map +1 -0
- package/types/algorand-client.mjs +291 -0
- package/types/algorand-client.mjs.map +1 -0
- package/types/client-manager.d.ts +99 -0
- package/types/client-manager.d.ts.map +1 -0
- package/types/client-manager.js +99 -0
- package/types/client-manager.js.map +1 -0
- package/types/client-manager.mjs +97 -0
- package/types/client-manager.mjs.map +1 -0
- package/types/composer.d.ts +331 -0
- package/types/composer.d.ts.map +1 -0
- package/types/composer.js +446 -0
- package/types/composer.js.map +1 -0
- package/types/composer.mjs +444 -0
- package/types/composer.mjs.map +1 -0
- package/types/indexer.d.ts +39 -0
- package/types/indexer.d.ts.map +1 -1
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/network-client.d.ts +2 -2
- package/types/network-client.d.ts.map +1 -1
- package/types/testing.d.ts +8 -2
- package/types/testing.d.ts.map +1 -1
- package/types/transaction.d.ts +4 -0
- package/types/transaction.d.ts.map +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import algosdk from 'algosdk';
|
|
2
|
+
import { AccountInformation, SigningAccount, TransactionSignerAccount } from './account';
|
|
3
|
+
import { AlgoAmount } from './amount';
|
|
4
|
+
import { ClientManager } from './client-manager';
|
|
5
|
+
import { SendTransactionFrom } from './transaction';
|
|
6
|
+
/** Creates and keeps track of signing accounts that can sign transactions for a sending address. */
|
|
7
|
+
export declare class AccountManager {
|
|
8
|
+
private _clientManager;
|
|
9
|
+
private _accounts;
|
|
10
|
+
private _defaultSigner?;
|
|
11
|
+
/**
|
|
12
|
+
* Create a new account manager.
|
|
13
|
+
* @param clientManager The ClientManager client to use for algod and kmd clients
|
|
14
|
+
*/
|
|
15
|
+
constructor(clientManager: ClientManager);
|
|
16
|
+
/**
|
|
17
|
+
* Sets the default signer to use if no other signer is specified.
|
|
18
|
+
*
|
|
19
|
+
* If this isn't set an a transaction needs signing for a given sender
|
|
20
|
+
* then an error will be thrown from `getSigner` / `getAccount`.
|
|
21
|
+
* @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
|
|
22
|
+
* @returns The `AccountManager` so method calls can be chained
|
|
23
|
+
*/
|
|
24
|
+
setDefaultSigner(signer: algosdk.TransactionSigner | TransactionSignerAccount): AccountManager;
|
|
25
|
+
/**
|
|
26
|
+
* Records the given account against the address of the account for later
|
|
27
|
+
* retrieval and returns a `TransactionSignerAccount`.
|
|
28
|
+
*/
|
|
29
|
+
private signerAccount;
|
|
30
|
+
/**
|
|
31
|
+
* Tracks the given account for later signing.
|
|
32
|
+
* @param account The account to register, which can be a `TransactionSignerAccount`
|
|
33
|
+
* or any `SendTransactionFrom` compatible account object
|
|
34
|
+
* @returns The `AccountManager` instance for method chaining
|
|
35
|
+
*/
|
|
36
|
+
setSignerFromAccount(account: TransactionSignerAccount | SendTransactionFrom): this;
|
|
37
|
+
/**
|
|
38
|
+
* Tracks the given account for later signing.
|
|
39
|
+
* @param sender The sender address to use this signer for
|
|
40
|
+
* @param signer The signer to sign transactions with for the given sender
|
|
41
|
+
* @returns The `AccountManager` instance for method chaining
|
|
42
|
+
*/
|
|
43
|
+
setSigner(sender: string, signer: algosdk.TransactionSigner): this;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the `TransactionSigner` for the given sender address.
|
|
46
|
+
*
|
|
47
|
+
* If no signer has been registered for that address then the default signer is used if registered.
|
|
48
|
+
*
|
|
49
|
+
* @param sender The sender address
|
|
50
|
+
* @returns The `TransactionSigner` or throws an error if not found
|
|
51
|
+
*/
|
|
52
|
+
getSigner(sender: string): algosdk.TransactionSigner;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the `TransactionSignerAccount` for the given sender address.
|
|
55
|
+
* @param sender The sender address
|
|
56
|
+
* @returns The `TransactionSignerAccount` or throws an error if not found
|
|
57
|
+
*/
|
|
58
|
+
getAccount(sender: string): TransactionSignerAccount;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the given sender account's current status, balance and spendable amounts.
|
|
61
|
+
*
|
|
62
|
+
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddress)
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
|
|
66
|
+
* const accountInfo = await accountManager.getInformation(address);
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @param sender The account / address to look up
|
|
70
|
+
* @returns The account information
|
|
71
|
+
*/
|
|
72
|
+
getInformation(sender: string | TransactionSignerAccount): Promise<AccountInformation>;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the given sender account's asset holding for a given asset.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
|
|
79
|
+
* const assetId = 123345;
|
|
80
|
+
* const accountInfo = await accountManager.getAccountAssetInformation(address, assetId);
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)
|
|
84
|
+
* @param sender The address of the sender/account to look up
|
|
85
|
+
* @param assetId The ID of the asset to return a holding for
|
|
86
|
+
* @returns The account asset holding information
|
|
87
|
+
*/
|
|
88
|
+
getAssetInformation(sender: string | TransactionSignerAccount, assetId: number | bigint): Promise<import("./account").AccountAssetInformation>;
|
|
89
|
+
/**
|
|
90
|
+
* Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const account = await account.fromMnemonic("mnemonic secret ...")
|
|
95
|
+
* const rekeyedAccount = await account.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
|
|
96
|
+
* ```
|
|
97
|
+
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
98
|
+
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
99
|
+
* @param sender The optional sender address to use this signer for (aka a rekeyed account)
|
|
100
|
+
* @returns The account
|
|
101
|
+
*/
|
|
102
|
+
fromMnemonic(mnemonicSecret: string, sender?: string): TransactionSignerAccount & {
|
|
103
|
+
account: algosdk.Account | SigningAccount;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
|
|
107
|
+
*
|
|
108
|
+
* Note: This function expects to run in a Node.js environment.
|
|
109
|
+
*
|
|
110
|
+
* ## Convention:
|
|
111
|
+
* * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
112
|
+
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
113
|
+
* If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
114
|
+
* * **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
|
|
115
|
+
*
|
|
116
|
+
* 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).
|
|
117
|
+
*
|
|
118
|
+
* @example Default
|
|
119
|
+
*
|
|
120
|
+
* 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:
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const account = await account.fromEnvironment('MY_ACCOUNT', algod)
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* 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) ALGOs from the default LocalNet dispenser.
|
|
126
|
+
* 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.
|
|
127
|
+
*
|
|
128
|
+
* @param name The name identifier of the account
|
|
129
|
+
* @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account
|
|
130
|
+
* @returns The account
|
|
131
|
+
*/
|
|
132
|
+
fromEnvironment(name: string, fundWith?: AlgoAmount): Promise<void>;
|
|
133
|
+
/**
|
|
134
|
+
* Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
|
|
135
|
+
*
|
|
136
|
+
* @param name The name of the wallet to retrieve an account from
|
|
137
|
+
* @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)
|
|
138
|
+
* @param sender The optional sender address to use this signer for (aka a rekeyed account)
|
|
139
|
+
* @example Get default funded account in a LocalNet
|
|
140
|
+
*
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const defaultDispenserAccount = await account.fromKmd('unencrypted-default-wallet',
|
|
143
|
+
* a => a.status !== 'Offline' && a.amount > 1_000_000_000
|
|
144
|
+
* )
|
|
145
|
+
* ```
|
|
146
|
+
* @returns The account
|
|
147
|
+
*/
|
|
148
|
+
fromKmd(name: string, predicate?: (account: Record<string, any>) => boolean, sender?: string): Promise<TransactionSignerAccount & {
|
|
149
|
+
account: algosdk.Account | SigningAccount;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Tracks and returns an account that supports partial or full multisig signing.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const account = await account.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
|
|
157
|
+
* await account.fromEnvironment('ACCOUNT1'))
|
|
158
|
+
* ```
|
|
159
|
+
* @param multisigParams The parameters that define the multisig account
|
|
160
|
+
* @param signingAccounts The signers that are currently present
|
|
161
|
+
* @returns A multisig account wrapper
|
|
162
|
+
*/
|
|
163
|
+
multisig(multisigParams: algosdk.MultisigMetadata, signingAccounts: (algosdk.Account | SigningAccount)[]): TransactionSignerAccount & {
|
|
164
|
+
account: import("./account").MultisigAccount;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Tracks and returns an account that represents a logic signature.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const account = await account.logicsig(program, [new Uint8Array(3, ...)])
|
|
172
|
+
* ```
|
|
173
|
+
* @param program The bytes that make up the compiled logic signature
|
|
174
|
+
* @param args The (binary) arguments to pass into the logic signature
|
|
175
|
+
* @returns A logic signature account wrapper
|
|
176
|
+
*/
|
|
177
|
+
logicsig(program: Uint8Array, args?: Array<Uint8Array>): void;
|
|
178
|
+
/**
|
|
179
|
+
* Tracks and returns a new, random Algorand account with secret key loaded.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const account = await account.random()
|
|
184
|
+
* ```
|
|
185
|
+
* @returns The account
|
|
186
|
+
*/
|
|
187
|
+
random(): void;
|
|
188
|
+
/**
|
|
189
|
+
* Returns an account (with private key loaded) that can act as a dispenser.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* const account = await account.dispenser()
|
|
194
|
+
* ```
|
|
195
|
+
* If running on LocalNet then it will return the default dispenser account automatically,
|
|
196
|
+
* otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC.
|
|
197
|
+
* @returns The account
|
|
198
|
+
*/
|
|
199
|
+
dispenser(): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const account = await account.localNetDispenser()
|
|
206
|
+
* ```
|
|
207
|
+
* @returns The account
|
|
208
|
+
*/
|
|
209
|
+
localNetDispenser(): Promise<void>;
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=account-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-manager.d.ts","sourceRoot":"","sources":["../../src/types/account-manager.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAA;AAc7B,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAA;AACxF,OAAO,EAAE,UAAU,EAAE,MAA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,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,EACrD,MAAM,CAAC,EAAE,MAAM;;;IAOjB;;;;;;;;;;;OAWG;IACI,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC,gBAAgB,EAAE,eAAe,EAAE,CAAC,OAAO,CAAC,OAAO,GAAG,cAAc,CAAC,EAAE;;;IAI/G;;;;;;;;;;OAUG;IACI,QAAQ,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC;IAI7D;;;;;;;;OAQG;IACI,MAAM;IAIb;;;;;;;;;;OAUG;IACU,SAAS;IAItB;;;;;;;;OAQG;IACU,iBAAiB;CAG/B"}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var algosdk = require('algosdk');
|
|
4
|
+
var account = require('../account/account.js');
|
|
5
|
+
var getDispenserAccount = require('../account/get-dispenser-account.js');
|
|
6
|
+
var mnemonicAccount = require('../account/mnemonic-account.js');
|
|
7
|
+
var getKmdWalletAccount = require('../localnet/get-kmd-wallet-account.js');
|
|
8
|
+
var getLocalnetDispenserAccount = require('../localnet/get-localnet-dispenser-account.js');
|
|
9
|
+
var transaction = require('../transaction/transaction.js');
|
|
10
|
+
|
|
11
|
+
var LogicSigAccount = algosdk.LogicSigAccount;
|
|
12
|
+
/** Creates and keeps track of signing accounts that can sign transactions for a sending address. */
|
|
13
|
+
class AccountManager {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new account manager.
|
|
16
|
+
* @param clientManager The ClientManager client to use for algod and kmd clients
|
|
17
|
+
*/
|
|
18
|
+
constructor(clientManager) {
|
|
19
|
+
this._accounts = {};
|
|
20
|
+
this._clientManager = clientManager;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sets the default signer to use if no other signer is specified.
|
|
24
|
+
*
|
|
25
|
+
* If this isn't set an a transaction needs signing for a given sender
|
|
26
|
+
* then an error will be thrown from `getSigner` / `getAccount`.
|
|
27
|
+
* @param signer The signer to use, either a `TransactionSigner` or a `TransactionSignerAccount`
|
|
28
|
+
* @returns The `AccountManager` so method calls can be chained
|
|
29
|
+
*/
|
|
30
|
+
setDefaultSigner(signer) {
|
|
31
|
+
this._defaultSigner = 'signer' in signer ? signer.signer : signer;
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Records the given account against the address of the account for later
|
|
36
|
+
* retrieval and returns a `TransactionSignerAccount`.
|
|
37
|
+
*/
|
|
38
|
+
signerAccount(account) {
|
|
39
|
+
const acc = {
|
|
40
|
+
addr: transaction.getSenderAddress(account),
|
|
41
|
+
signer: transaction.getSenderTransactionSigner(account),
|
|
42
|
+
};
|
|
43
|
+
this._accounts[acc.addr] = acc;
|
|
44
|
+
return { ...acc, account };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Tracks the given account for later signing.
|
|
48
|
+
* @param account The account to register, which can be a `TransactionSignerAccount`
|
|
49
|
+
* or any `SendTransactionFrom` compatible account object
|
|
50
|
+
* @returns The `AccountManager` instance for method chaining
|
|
51
|
+
*/
|
|
52
|
+
setSignerFromAccount(account) {
|
|
53
|
+
this.signerAccount(account);
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Tracks the given account for later signing.
|
|
58
|
+
* @param sender The sender address to use this signer for
|
|
59
|
+
* @param signer The signer to sign transactions with for the given sender
|
|
60
|
+
* @returns The `AccountManager` instance for method chaining
|
|
61
|
+
*/
|
|
62
|
+
setSigner(sender, signer) {
|
|
63
|
+
this._accounts[sender] = { addr: sender, signer };
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns the `TransactionSigner` for the given sender address.
|
|
68
|
+
*
|
|
69
|
+
* If no signer has been registered for that address then the default signer is used if registered.
|
|
70
|
+
*
|
|
71
|
+
* @param sender The sender address
|
|
72
|
+
* @returns The `TransactionSigner` or throws an error if not found
|
|
73
|
+
*/
|
|
74
|
+
getSigner(sender) {
|
|
75
|
+
const signer = this._accounts[sender]?.signer ?? this._defaultSigner;
|
|
76
|
+
if (!signer)
|
|
77
|
+
throw new Error(`No signer found for address ${sender}`);
|
|
78
|
+
return signer;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the `TransactionSignerAccount` for the given sender address.
|
|
82
|
+
* @param sender The sender address
|
|
83
|
+
* @returns The `TransactionSignerAccount` or throws an error if not found
|
|
84
|
+
*/
|
|
85
|
+
getAccount(sender) {
|
|
86
|
+
const account = this._accounts[sender];
|
|
87
|
+
if (!account)
|
|
88
|
+
throw new Error(`No signer found for address ${sender}`);
|
|
89
|
+
return account;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns the given sender account's current status, balance and spendable amounts.
|
|
93
|
+
*
|
|
94
|
+
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddress)
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
|
|
98
|
+
* const accountInfo = await accountManager.getInformation(address);
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param sender The account / address to look up
|
|
102
|
+
* @returns The account information
|
|
103
|
+
*/
|
|
104
|
+
async getInformation(sender) {
|
|
105
|
+
return account.getAccountInformation(sender, this._clientManager.algod);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns the given sender account's asset holding for a given asset.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const address = "XBYLS2E6YI6XXL5BWCAMOA4GTWHXWENZMX5UHXMRNWWUQ7BXCY5WC5TEPA";
|
|
113
|
+
* const assetId = 123345;
|
|
114
|
+
* const accountInfo = await accountManager.getAccountAssetInformation(address, assetId);
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* [Response data schema details](https://developer.algorand.org/docs/rest-apis/algod/#get-v2accountsaddressassetsasset-id)
|
|
118
|
+
* @param sender The address of the sender/account to look up
|
|
119
|
+
* @param assetId The ID of the asset to return a holding for
|
|
120
|
+
* @returns The account asset holding information
|
|
121
|
+
*/
|
|
122
|
+
async getAssetInformation(sender, assetId) {
|
|
123
|
+
return account.getAccountAssetInformation(sender, assetId, this._clientManager.algod);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Tracks and returns an Algorand account with secret key loaded (i.e. that can sign transactions) by taking the mnemonic secret.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const account = await account.fromMnemonic("mnemonic secret ...")
|
|
131
|
+
* const rekeyedAccount = await account.fromMnemonic("mnemonic secret ...", "SENDERADDRESS...")
|
|
132
|
+
* ```
|
|
133
|
+
* @param mnemonicSecret The mnemonic secret representing the private key of an account; **Note: Be careful how the mnemonic is handled**,
|
|
134
|
+
* never commit it into source control and ideally load it from the environment (ideally via a secret storage service) rather than the file system.
|
|
135
|
+
* @param sender The optional sender address to use this signer for (aka a rekeyed account)
|
|
136
|
+
* @returns The account
|
|
137
|
+
*/
|
|
138
|
+
fromMnemonic(mnemonicSecret, sender) {
|
|
139
|
+
const account$1 = mnemonicAccount.mnemonicAccount(mnemonicSecret);
|
|
140
|
+
return this.signerAccount(sender ? account.rekeyedAccount(account$1, sender) : account$1);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Tracks and returns an Algorand account with private key loaded by convention from environment variables based on the given name identifier.
|
|
144
|
+
*
|
|
145
|
+
* Note: This function expects to run in a Node.js environment.
|
|
146
|
+
*
|
|
147
|
+
* ## Convention:
|
|
148
|
+
* * **Non-LocalNet:** will load process.env['\{NAME\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,
|
|
149
|
+
* never commit it into source control and ideally load it via a secret storage service rather than the file system.
|
|
150
|
+
* If process.env['\{NAME\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)
|
|
151
|
+
* * **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
|
|
152
|
+
*
|
|
153
|
+
* 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).
|
|
154
|
+
*
|
|
155
|
+
* @example Default
|
|
156
|
+
*
|
|
157
|
+
* 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:
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const account = await account.fromEnvironment('MY_ACCOUNT', algod)
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* 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) ALGOs from the default LocalNet dispenser.
|
|
163
|
+
* 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.
|
|
164
|
+
*
|
|
165
|
+
* @param name The name identifier of the account
|
|
166
|
+
* @param fundWith The optional amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 Algos will be funded from the dispenser account
|
|
167
|
+
* @returns The account
|
|
168
|
+
*/
|
|
169
|
+
async fromEnvironment(name, fundWith) {
|
|
170
|
+
this.signerAccount(await account.mnemonicAccountFromEnvironment({ name, fundWith }, this._clientManager.algod, this._clientManager.kmd));
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Tracks and returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
|
|
174
|
+
*
|
|
175
|
+
* @param name The name of the wallet to retrieve an account from
|
|
176
|
+
* @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)
|
|
177
|
+
* @param sender The optional sender address to use this signer for (aka a rekeyed account)
|
|
178
|
+
* @example Get default funded account in a LocalNet
|
|
179
|
+
*
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const defaultDispenserAccount = await account.fromKmd('unencrypted-default-wallet',
|
|
182
|
+
* a => a.status !== 'Offline' && a.amount > 1_000_000_000
|
|
183
|
+
* )
|
|
184
|
+
* ```
|
|
185
|
+
* @returns The account
|
|
186
|
+
*/
|
|
187
|
+
async fromKmd(name,
|
|
188
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
189
|
+
predicate, sender) {
|
|
190
|
+
const account$1 = await getKmdWalletAccount.getKmdWalletAccount({ name, predicate }, this._clientManager.algod, this._clientManager.kmd);
|
|
191
|
+
if (!account$1)
|
|
192
|
+
throw new Error(`Unable to find KMD account ${name}${predicate ? ' with predicate' : ''}`);
|
|
193
|
+
return this.signerAccount(sender ? account.rekeyedAccount(account$1, sender) : account$1);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Tracks and returns an account that supports partial or full multisig signing.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const account = await account.multisig({version: 1, threshold: 1, addrs: ["ADDRESS1...", "ADDRESS2..."]},
|
|
201
|
+
* await account.fromEnvironment('ACCOUNT1'))
|
|
202
|
+
* ```
|
|
203
|
+
* @param multisigParams The parameters that define the multisig account
|
|
204
|
+
* @param signingAccounts The signers that are currently present
|
|
205
|
+
* @returns A multisig account wrapper
|
|
206
|
+
*/
|
|
207
|
+
multisig(multisigParams, signingAccounts) {
|
|
208
|
+
return this.signerAccount(account.multisigAccount(multisigParams, signingAccounts));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Tracks and returns an account that represents a logic signature.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const account = await account.logicsig(program, [new Uint8Array(3, ...)])
|
|
216
|
+
* ```
|
|
217
|
+
* @param program The bytes that make up the compiled logic signature
|
|
218
|
+
* @param args The (binary) arguments to pass into the logic signature
|
|
219
|
+
* @returns A logic signature account wrapper
|
|
220
|
+
*/
|
|
221
|
+
logicsig(program, args) {
|
|
222
|
+
this.signerAccount(new LogicSigAccount(program, args));
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Tracks and returns a new, random Algorand account with secret key loaded.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* const account = await account.random()
|
|
230
|
+
* ```
|
|
231
|
+
* @returns The account
|
|
232
|
+
*/
|
|
233
|
+
random() {
|
|
234
|
+
this.signerAccount(account.randomAccount());
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Returns an account (with private key loaded) that can act as a dispenser.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const account = await account.dispenser()
|
|
242
|
+
* ```
|
|
243
|
+
* If running on LocalNet then it will return the default dispenser account automatically,
|
|
244
|
+
* otherwise it will load the account mnemonic stored in process.env.DISPENSER_MNEMONIC.
|
|
245
|
+
* @returns The account
|
|
246
|
+
*/
|
|
247
|
+
async dispenser() {
|
|
248
|
+
this.signerAccount(await getDispenserAccount.getDispenserAccount(this._clientManager.algod, this._clientManager.kmd));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const account = await account.localNetDispenser()
|
|
256
|
+
* ```
|
|
257
|
+
* @returns The account
|
|
258
|
+
*/
|
|
259
|
+
async localNetDispenser() {
|
|
260
|
+
this.signerAccount(await getLocalnetDispenserAccount.getLocalNetDispenserAccount(this._clientManager.algod, this._clientManager.kmd));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
exports.AccountManager = AccountManager;
|
|
265
|
+
//# sourceMappingURL=account-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-manager.js","sources":["../../src/types/account-manager.ts"],"sourcesContent":[null],"names":["getSenderAddress","getSenderTransactionSigner","getAccountInformation","getAccountAssetInformation","account","mnemonicAccount","rekeyedAccount","mnemonicAccountFromEnvironment","getKmdWalletAccount","multisigAccount","randomAccount","getDispenserAccount","getLocalNetDispenserAccount"],"mappings":";;;;;;;;;;AAkBA,IAAO,eAAe,GAAG,OAAO,CAAC,eAAe,CAAA;AAEhD;MACa,cAAc,CAAA;AAKzB;;;AAGG;AACH,IAAA,WAAA,CAAY,aAA4B,EAAA;QAPhC,IAAS,CAAA,SAAA,GAAoD,EAAE,CAAA;AAQrE,QAAA,IAAI,CAAC,cAAc,GAAG,aAAa,CAAA;KACpC;AAED;;;;;;;AAOG;AACI,IAAA,gBAAgB,CAAC,MAA4D,EAAA;AAClF,QAAA,IAAI,CAAC,cAAc,GAAG,QAAQ,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAA;AACjE,QAAA,OAAO,IAAI,CAAA;KACZ;AAED;;;AAGG;AACK,IAAA,aAAa,CAAgC,OAAU,EAAA;AAC7D,QAAA,MAAM,GAAG,GAAG;AACV,YAAA,IAAI,EAAEA,4BAAgB,CAAC,OAAO,CAAC;AAC/B,YAAA,MAAM,EAAEC,sCAA0B,CAAC,OAAO,CAAC;SAC5C,CAAA;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAA;AAC9B,QAAA,OAAO,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,CAAA;KAC3B;AAED;;;;;AAKG;AACI,IAAA,oBAAoB,CAAC,OAAuD,EAAA;AACjF,QAAA,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;AAC3B,QAAA,OAAO,IAAI,CAAA;KACZ;AAED;;;;;AAKG;IACI,SAAS,CAAC,MAAc,EAAE,MAAiC,EAAA;AAChE,QAAA,IA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