@algorandfoundation/algokit-utils 1.0.0-beta.6 → 1.0.0-beta.8

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 (72) hide show
  1. package/{dist/index.js → index.js} +1 -0
  2. package/package.json +3 -94
  3. package/LICENSE +0 -21
  4. package/README.md +0 -31
  5. package/dist/account.d.ts +0 -87
  6. package/dist/account.d.ts.map +0 -1
  7. package/dist/account.js +0 -144
  8. package/dist/account.js.map +0 -1
  9. package/dist/algo-amount.d.ts +0 -18
  10. package/dist/algo-amount.d.ts.map +0 -1
  11. package/dist/algo-amount.js +0 -31
  12. package/dist/algo-amount.js.map +0 -1
  13. package/dist/algo-http-client-with-retry.d.ts +0 -14
  14. package/dist/algo-http-client-with-retry.d.ts.map +0 -1
  15. package/dist/algo-http-client-with-retry.js +0 -62
  16. package/dist/algo-http-client-with-retry.js.map +0 -1
  17. package/dist/app.d.ts +0 -189
  18. package/dist/app.d.ts.map +0 -1
  19. package/dist/app.js +0 -265
  20. package/dist/app.js.map +0 -1
  21. package/dist/application-client.d.ts +0 -108
  22. package/dist/application-client.d.ts.map +0 -1
  23. package/dist/application-client.js +0 -252
  24. package/dist/application-client.js.map +0 -1
  25. package/dist/config.d.ts +0 -27
  26. package/dist/config.d.ts.map +0 -1
  27. package/dist/config.js +0 -46
  28. package/dist/config.js.map +0 -1
  29. package/dist/deploy-app.d.ts +0 -159
  30. package/dist/deploy-app.d.ts.map +0 -1
  31. package/dist/deploy-app.js +0 -416
  32. package/dist/deploy-app.js.map +0 -1
  33. package/dist/index.d.ts +0 -11
  34. package/dist/index.d.ts.map +0 -1
  35. package/dist/index.js.map +0 -1
  36. package/dist/indexer-lookup.d.ts +0 -31
  37. package/dist/indexer-lookup.d.ts.map +0 -1
  38. package/dist/indexer-lookup.js +0 -96
  39. package/dist/indexer-lookup.js.map +0 -1
  40. package/dist/localnet.d.ts +0 -54
  41. package/dist/localnet.d.ts.map +0 -1
  42. package/dist/localnet.js +0 -121
  43. package/dist/localnet.js.map +0 -1
  44. package/dist/network-client.d.ts +0 -102
  45. package/dist/network-client.d.ts.map +0 -1
  46. package/dist/network-client.js +0 -182
  47. package/dist/network-client.js.map +0 -1
  48. package/dist/package.json +0 -20
  49. package/dist/transaction.d.ts +0 -157
  50. package/dist/transaction.d.ts.map +0 -1
  51. package/dist/transaction.js +0 -306
  52. package/dist/transaction.js.map +0 -1
  53. package/dist/transfer.d.ts +0 -24
  54. package/dist/transfer.d.ts.map +0 -1
  55. package/dist/transfer.js +0 -33
  56. package/dist/transfer.js.map +0 -1
  57. package/dist/types/algod.d.ts +0 -124
  58. package/dist/types/algod.d.ts.map +0 -1
  59. package/dist/types/algod.js +0 -3
  60. package/dist/types/algod.js.map +0 -1
  61. package/dist/types/appspec.d.ts +0 -79
  62. package/dist/types/appspec.d.ts.map +0 -1
  63. package/dist/types/appspec.js +0 -15
  64. package/dist/types/appspec.js.map +0 -1
  65. package/dist/types/indexer.d.ts +0 -314
  66. package/dist/types/indexer.d.ts.map +0 -1
  67. package/dist/types/indexer.js +0 -25
  68. package/dist/types/indexer.js.map +0 -1
  69. package/dist/urlTokenBaseHTTPClient.d.ts +0 -41
  70. package/dist/urlTokenBaseHTTPClient.d.ts.map +0 -1
  71. package/dist/urlTokenBaseHTTPClient.js +0 -151
  72. package/dist/urlTokenBaseHTTPClient.js.map +0 -1
@@ -1,54 +0,0 @@
1
- import { Account, Algodv2, Kmd } from 'algosdk';
2
- import { AlgoAmount } from './algo-amount';
3
- /** Returns true if the algod client is pointing to a LocalNet Algorand network */
4
- export declare function isLocalNet(algod: Algodv2): Promise<boolean>;
5
- /**
6
- * Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
7
- *
8
- * This is useful to get idempotent accounts from a local sandbox without having to specify the private key (which will change when resetting the sandbox).
9
- *
10
- * This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh sandbox.
11
- *
12
- * If this is used via @see {getAccount}, then you can even use the same code that runs on production without changes for local development!
13
- *
14
- * @param walletAccount The wallet details with:
15
- * * `name`: The name of the wallet to retrieve / create
16
- * * `fundWith`: The number of Algos to fund the account with it it gets created, if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
17
- * @param algod An algod client
18
- * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
19
- *
20
- * @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
21
- */
22
- export declare function getOrCreateKmdWalletAccount(walletAccount: {
23
- name: string;
24
- fundWith?: AlgoAmount;
25
- }, algod: Algodv2, kmdClient?: Kmd): Promise<Account>;
26
- /**
27
- * Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
28
- *
29
- * @param walletAccount The details of the wallet, with:
30
- * * `name`: The name of the wallet to retrieve an account from
31
- * * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
32
- * @param algod An algod client
33
- * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
34
- * @example Get default funded account in a LocalNet
35
- *
36
- * ```
37
- * const defaultDispenserAccount = await getKmdWalletAccount(algod,
38
- * 'unencrypted-default-wallet',
39
- * a => a.status !== 'Offline' && a.amount > 1_000_000_000
40
- * )
41
- * ```
42
- */
43
- export declare function getKmdWalletAccount(walletAccount: {
44
- name: string;
45
- predicate?: (account: Record<string, any>) => boolean;
46
- }, algod: Algodv2, kmdClient?: Kmd): Promise<Account | undefined>;
47
- /**
48
- * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
49
- *
50
- * @param algod An algod client
51
- * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
52
- */
53
- export declare function getLocalNetDispenserAccount(algod: Algodv2, kmdClient?: Kmd): Promise<Account>;
54
- //# sourceMappingURL=localnet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"localnet.d.ts","sourceRoot":"","sources":["../src/localnet.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAK1C,kFAAkF;AAClF,wBAAsB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAIjE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,2BAA2B,CAC/C,aAAa,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAE,EACtD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,CAAC,CAmClB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CACvC,aAAa,EAAE;IACb,IAAI,EAAE,MAAM,CAAA;IAEZ,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAA;CACtD,EACD,KAAK,EAAE,OAAO,EACd,SAAS,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAmC9B;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAWnG"}
package/dist/localnet.js DELETED
@@ -1,121 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLocalNetDispenserAccount = exports.getKmdWalletAccount = exports.getOrCreateKmdWalletAccount = exports.isLocalNet = void 0;
7
- const algosdk_1 = __importDefault(require("algosdk"));
8
- const account_1 = require("./account");
9
- const algo_amount_1 = require("./algo-amount");
10
- const config_1 = require("./config");
11
- const network_client_1 = require("./network-client");
12
- const transfer_1 = require("./transfer");
13
- /** Returns true if the algod client is pointing to a LocalNet Algorand network */
14
- async function isLocalNet(algod) {
15
- const params = await algod.getTransactionParams().do();
16
- return params.genesisID === 'devnet-v1' || params.genesisID === 'sandnet-v1';
17
- }
18
- exports.isLocalNet = isLocalNet;
19
- /**
20
- * Gets an account with private key loaded from a KMD wallet of the given name, or alternatively creates one with funds in it via a KMD wallet of the given name.
21
- *
22
- * This is useful to get idempotent accounts from a local sandbox without having to specify the private key (which will change when resetting the sandbox).
23
- *
24
- * This significantly speeds up local dev time and improves experience since you can write code that *just works* first go without manual config in a fresh sandbox.
25
- *
26
- * If this is used via @see {getAccount}, then you can even use the same code that runs on production without changes for local development!
27
- *
28
- * @param walletAccount The wallet details with:
29
- * * `name`: The name of the wallet to retrieve / create
30
- * * `fundWith`: The number of Algos to fund the account with it it gets created, if not specified then 1000 Algos will be funded from the dispenser account @see {getDispenserAccount}
31
- * @param algod An algod client
32
- * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
33
- *
34
- * @returns An Algorand account with private key loaded - either one that already existed in the given KMD wallet, or a new one that is funded for you
35
- */
36
- async function getOrCreateKmdWalletAccount(walletAccount, algod, kmdClient) {
37
- const kmd = kmdClient ?? (0, network_client_1.getAlgoKmdClient)();
38
- // Get an existing account from the KMD wallet
39
- const existing = await getKmdWalletAccount(walletAccount, algod, kmd);
40
- if (existing) {
41
- return existing;
42
- }
43
- // None existed: create the KMD wallet instead
44
- const walletId = (await kmd.createWallet(walletAccount.name, '')).wallet.id;
45
- const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
46
- await kmd.generateKey(walletHandle);
47
- // Get the account from the new KMD wallet
48
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
- const account = (await getKmdWalletAccount(walletAccount, algod, kmd));
50
- config_1.AlgoKitConfig.logger.info(`Couldn't find existing account in Sandbox under name '${walletAccount.name}'; created account ${account.addr} with keys stored in KMD and funding with ${walletAccount.fundWith?.algos ?? 1000} ALGOs`);
51
- // Fund the account from the dispenser
52
- await (0, transfer_1.transferAlgos)({
53
- amount: walletAccount.fundWith ?? algo_amount_1.AlgoAmount.Algos(1000),
54
- from: await (0, account_1.getDispenserAccount)(algod),
55
- to: account.addr,
56
- }, algod);
57
- return account;
58
- }
59
- exports.getOrCreateKmdWalletAccount = getOrCreateKmdWalletAccount;
60
- /**
61
- * Returns an Algorand account with private key loaded from the given KMD wallet (identified by name).
62
- *
63
- * @param walletAccount The details of the wallet, with:
64
- * * `name`: The name of the wallet to retrieve an account from
65
- * * `predicate`: An optional filter to use to find the account (otherwise it will return a random account from the wallet)
66
- * @param algod An algod client
67
- * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
68
- * @example Get default funded account in a LocalNet
69
- *
70
- * ```
71
- * const defaultDispenserAccount = await getKmdWalletAccount(algod,
72
- * 'unencrypted-default-wallet',
73
- * a => a.status !== 'Offline' && a.amount > 1_000_000_000
74
- * )
75
- * ```
76
- */
77
- async function getKmdWalletAccount(walletAccount, algod, kmdClient) {
78
- const { name, predicate } = walletAccount;
79
- const kmd = kmdClient ?? (0, network_client_1.getAlgoKmdClient)();
80
- const wallets = await kmd.listWallets();
81
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
- const wallet = wallets.wallets.filter((w) => w.name === name);
83
- if (wallet.length === 0) {
84
- return undefined;
85
- }
86
- const walletId = wallet[0].id;
87
- const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token;
88
- const keyIds = (await kmd.listKeys(walletHandle)).addresses;
89
- let i = 0;
90
- if (predicate) {
91
- for (i = 0; i < keyIds.length; i++) {
92
- const key = keyIds[i];
93
- const account = await algod.accountInformation(key).do();
94
- if (predicate(account)) {
95
- break;
96
- }
97
- }
98
- }
99
- if (i >= keyIds.length) {
100
- return undefined;
101
- }
102
- const accountKey = (await kmd.exportKey(walletHandle, '', keyIds[i])).private_key;
103
- const accountMnemonic = algosdk_1.default.secretKeyToMnemonic(accountKey);
104
- return (0, account_1.getAccountFromMnemonic)(accountMnemonic);
105
- }
106
- exports.getKmdWalletAccount = getKmdWalletAccount;
107
- /**
108
- * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts)
109
- *
110
- * @param algod An algod client
111
- * @param kmdClient A KMD client, if not specified then a default KMD client will be loaded from environment variables @see {getAlgoKmdClient}
112
- */
113
- async function getLocalNetDispenserAccount(algod, kmdClient) {
114
- if (!(await isLocalNet(algod))) {
115
- throw "Can't get default account from non LocalNet network";
116
- }
117
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
- return (await getKmdWalletAccount({ name: 'unencrypted-default-wallet', predicate: (a) => a.status !== 'Offline' && a.amount > 1000000000 }, algod, kmdClient));
119
- }
120
- exports.getLocalNetDispenserAccount = getLocalNetDispenserAccount;
121
- //# sourceMappingURL=localnet.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"localnet.js","sourceRoot":"","sources":["../src/localnet.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAwD;AACxD,uCAAuE;AACvE,+CAA0C;AAC1C,qCAAwC;AACxC,qDAAmD;AACnD,yCAA0C;AAE1C,kFAAkF;AAC3E,KAAK,UAAU,UAAU,CAAC,KAAc;IAC7C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE,CAAA;IAEtD,OAAO,MAAM,CAAC,SAAS,KAAK,WAAW,IAAI,MAAM,CAAC,SAAS,KAAK,YAAY,CAAA;AAC9E,CAAC;AAJD,gCAIC;AAED;;;;;;;;;;;;;;;;GAgBG;AACI,KAAK,UAAU,2BAA2B,CAC/C,aAAsD,EACtD,KAAc,EACd,SAAe;IAEf,MAAM,GAAG,GAAG,SAAS,IAAI,IAAA,iCAAgB,GAAE,CAAA;IAE3C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BAAmB,CAAC,UAAU,CAAC,CAAA;IAC/D,OAAO,IAAA,gCAAsB,EAAC,eAAe,CAAC,CAAA;AAChD,CAAC;AA3CD,kDA2CC;AAED;;;;;GAKG;AACI,KAAK,UAAU,2BAA2B,CAAC,KAAc,EAAE,SAAe;IAC/E,IAAI,CAAC,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE;QAC9B,MAAM,qDAAqD,CAAA;KAC5D;IAED,oEAAoE;IACpE,OAAO,CAAC,MAAM,mBAAmB,CAC/B,EAAE,IAAI,EAAE,4BAA4B,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,GAAG,UAAa,EAAE,EAC5G,KAAK,EACL,SAAS,CACV,CAAE,CAAA;AACL,CAAC;AAXD,kEAWC"}
@@ -1,102 +0,0 @@
1
- import { Algodv2, Indexer, Kmd } from 'algosdk';
2
- import { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient';
3
- /** Config for an Algorand SDK client */
4
- export interface AlgoClientConfig {
5
- /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */
6
- server: string;
7
- /** The port to use e.g. 4001, 443, etc. */
8
- port?: string | number;
9
- /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */
10
- token?: string | TokenHeader;
11
- }
12
- /** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
13
- export declare function getAlgodConfigFromEnvironment(): AlgoClientConfig;
14
- /** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
15
- export declare function getIndexerConfigFromEnvironment(): AlgoClientConfig;
16
- /** Returns the Algorand configuration to point to the AlgoNode service
17
- *
18
- * @param network Which network to connect to - TestNet or MainNet
19
- * @param config Which algod config to return - Algod or Indexer
20
- */
21
- export declare function getAlgoNodeConfig(network: 'testnet' | 'mainnet', config: 'algod' | 'indexer'): AlgoClientConfig;
22
- /** Returns the Algorand configuration to point to the default LocalNet
23
- *
24
- * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
25
- */
26
- export declare function getDefaultLocalNetConfig(configOrPort: 'algod' | 'indexer' | 'kmd' | number): AlgoClientConfig;
27
- /** Returns an algod SDK client that automatically retries on idempotent calls
28
- *
29
- * @param config The config if you want to override the default (getting config from process.env)
30
- * @example Default (load from environment variables)
31
- *
32
- * ```
33
- * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
34
- * // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
35
- * const algod = getAlgoClient()
36
- * await algod.healthCheck().do()
37
- * ```
38
- * @example AlgoNode (testnet)
39
- * ```
40
- * const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
41
- * await algod.healthCheck().do()
42
- * ```
43
- * @example AlgoNode (mainnet)
44
- * ```
45
- * const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
46
- * await algod.healthCheck().do()
47
- * ```
48
- * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
49
- * ```
50
- * const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
51
- * await algod.healthCheck().do()
52
- * ```
53
- */
54
- export declare function getAlgoClient(config?: AlgoClientConfig): Algodv2;
55
- /** Returns an indexer SDK client that automatically retries on idempotent calls
56
- *
57
- * @param config The config if you want to override the default (getting config from process.env)
58
- * @example Default (load from environment variables)
59
- *
60
- * ```
61
- * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
62
- * // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
63
- * const indexer = getAlgoIndexerClient()
64
- * await indexer.makeHealthCheck().do()
65
- * ```
66
- * @example AlgoNode (testnet)
67
- * ```
68
- * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
69
- * await indexer.makeHealthCheck().do()
70
- * ```
71
- * @example AlgoNode (mainnet)
72
- * ```
73
- * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
74
- * await indexer.makeHealthCheck().do()
75
- * ```
76
- * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
77
- * ```
78
- * const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
79
- * await indexer.makeHealthCheck().do()
80
- * ```
81
- */
82
- export declare function getAlgoIndexerClient(config?: AlgoClientConfig): Indexer;
83
- /**
84
- * Returns a KMD SDK client that automatically retries on idempotent calls
85
- *
86
- * KMD client allows you to export private keys, which is useful to get the default account in a sandbox network.
87
- *
88
- * @param config The config if you want to override the default (getting config from process.env)
89
- * @example Default (load from environment variables)
90
- *
91
- * ```
92
- * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
93
- * const kmd = getAlgoKmdClient()
94
- * ```
95
- * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
96
- * ```
97
- * const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
98
- * ```
99
- */
100
- export declare function getAlgoKmdClient(config?: AlgoClientConfig): Kmd;
101
- export { isLocalNet } from './localnet';
102
- //# sourceMappingURL=network-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"network-client.d.ts","sourceRoot":"","sources":["../src/network-client.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAG9E,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACtB,yIAAyI;IACzI,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;CAC7B;AAED,mIAAmI;AACnI,wBAAgB,6BAA6B,IAAI,gBAAgB,CAchE;AAED,qIAAqI;AACrI,wBAAgB,+BAA+B,IAAI,gBAAgB,CAclE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,GAAG,SAAS,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,gBAAgB,CAK/G;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,gBAAgB,CAM7G;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAIhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAIvE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,GAAG,CAK/D;AAED,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA"}
@@ -1,182 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isLocalNet = exports.getAlgoKmdClient = exports.getAlgoIndexerClient = exports.getAlgoClient = exports.getDefaultLocalNetConfig = exports.getAlgoNodeConfig = exports.getIndexerConfigFromEnvironment = exports.getAlgodConfigFromEnvironment = void 0;
27
- const algosdk_1 = __importStar(require("algosdk"));
28
- const algo_http_client_with_retry_1 = require("./algo-http-client-with-retry");
29
- /** Retrieve the algod configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
30
- function getAlgodConfigFromEnvironment() {
31
- if (!process || !process.env) {
32
- throw new Error('Attempt to get default algod configuration from a non Node.js context; supply the config instead');
33
- }
34
- if (!process.env.ALGOD_SERVER) {
35
- throw new Error('Attempt to get default algod configuration without specifying ALGOD_SERVER in the environment variables');
36
- }
37
- return {
38
- server: process.env.ALGOD_SERVER,
39
- port: process.env.ALGOD_PORT,
40
- token: process.env.ALGOD_TOKEN,
41
- };
42
- }
43
- exports.getAlgodConfigFromEnvironment = getAlgodConfigFromEnvironment;
44
- /** Retrieve the indexer configuration from environment variables (expects to be called from a Node.js environment not algod-side) */
45
- function getIndexerConfigFromEnvironment() {
46
- if (!process || !process.env) {
47
- throw new Error('Attempt to get default indexer configuration from a non Node.js context; supply the config instead');
48
- }
49
- if (!process.env.INDEXER_SERVER) {
50
- throw new Error('Attempt to get default indexer configuration without specifying INDEXER_SERVER in the environment variables');
51
- }
52
- return {
53
- server: process.env.INDEXER_SERVER,
54
- port: process.env.INDEXER_PORT,
55
- token: process.env.INDEXER_TOKEN,
56
- };
57
- }
58
- exports.getIndexerConfigFromEnvironment = getIndexerConfigFromEnvironment;
59
- /** Returns the Algorand configuration to point to the AlgoNode service
60
- *
61
- * @param network Which network to connect to - TestNet or MainNet
62
- * @param config Which algod config to return - Algod or Indexer
63
- */
64
- function getAlgoNodeConfig(network, config) {
65
- return {
66
- server: `https://${network}-${config === 'algod' ? 'api' : 'idx'}.algonode.cloud/`,
67
- port: 443,
68
- };
69
- }
70
- exports.getAlgoNodeConfig = getAlgoNodeConfig;
71
- /** Returns the Algorand configuration to point to the default LocalNet
72
- *
73
- * @param configOrPort Which algod config to return - algod, kmd, or indexer OR a port number
74
- */
75
- function getDefaultLocalNetConfig(configOrPort) {
76
- return {
77
- server: `http://localhost`,
78
- port: configOrPort === 'algod' ? 4001 : configOrPort === 'indexer' ? 8980 : configOrPort === 'kmd' ? 4002 : configOrPort,
79
- token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
80
- };
81
- }
82
- exports.getDefaultLocalNetConfig = getDefaultLocalNetConfig;
83
- function getAlgoTokenHeader(server, token, defaultHeader) {
84
- // Purestake uses a slightly different API key header than the default
85
- if (server.includes('purestake.io') && typeof token === 'string')
86
- return { 'X-API-Key': token };
87
- // Because we override the default HTTP Client construction (to get retries) we need to put a string token into the standard header ourselves
88
- return typeof token === 'string' ? { [defaultHeader ?? 'X-Algo-API-Token']: token } : token ?? {};
89
- }
90
- /** Returns an algod SDK client that automatically retries on idempotent calls
91
- *
92
- * @param config The config if you want to override the default (getting config from process.env)
93
- * @example Default (load from environment variables)
94
- *
95
- * ```
96
- * // Uses process.env.ALGOD_SERVER, process.env.ALGOD_PORT and process.env.ALGOD_TOKEN
97
- * // Automatically detects if you are using PureStake to switch in the right header name for ALGOD_TOKEN
98
- * const algod = getAlgoClient()
99
- * await algod.healthCheck().do()
100
- * ```
101
- * @example AlgoNode (testnet)
102
- * ```
103
- * const algod = getAlgoClient(getAlgoNodeConfig('testnet', 'algod'))
104
- * await algod.healthCheck().do()
105
- * ```
106
- * @example AlgoNode (mainnet)
107
- * ```
108
- * const algod = getAlgoClient(getAlgoNodeConfig('mainnet', 'algod'))
109
- * await algod.healthCheck().do()
110
- * ```
111
- * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
112
- * ```
113
- * const algod = getAlgoClient({server: 'http://localhost', port: '4001', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
114
- * await algod.healthCheck().do()
115
- * ```
116
- */
117
- function getAlgoClient(config) {
118
- const { token, server, port } = config ?? getAlgodConfigFromEnvironment();
119
- const httpClientWithRetry = new algo_http_client_with_retry_1.AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token), server, port);
120
- return new algosdk_1.default.Algodv2(httpClientWithRetry, server);
121
- }
122
- exports.getAlgoClient = getAlgoClient;
123
- /** Returns an indexer SDK client that automatically retries on idempotent calls
124
- *
125
- * @param config The config if you want to override the default (getting config from process.env)
126
- * @example Default (load from environment variables)
127
- *
128
- * ```
129
- * // Uses process.env.INDEXER_SERVER, process.env.INDEXER_PORT and process.env.INDEXER_TOKEN
130
- * // Automatically detects if you are using PureStake to switch in the right header name for INDEXER_TOKEN
131
- * const indexer = getAlgoIndexerClient()
132
- * await indexer.makeHealthCheck().do()
133
- * ```
134
- * @example AlgoNode (testnet)
135
- * ```
136
- * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('testnet', 'indexer'))
137
- * await indexer.makeHealthCheck().do()
138
- * ```
139
- * @example AlgoNode (mainnet)
140
- * ```
141
- * const indexer = getAlgoIndexerClient(getAlgoNodeConfig('mainnet', 'indexer'))
142
- * await indexer.makeHealthCheck().do()
143
- * ```
144
- * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
145
- * ```
146
- * const indexer = getAlgoIndexerClient({server: 'http://localhost', port: '8980', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
147
- * await indexer.makeHealthCheck().do()
148
- * ```
149
- */
150
- function getAlgoIndexerClient(config) {
151
- const { token, server, port } = config ?? getIndexerConfigFromEnvironment();
152
- const httpClientWithRetry = new algo_http_client_with_retry_1.AlgoHttpClientWithRetry(getAlgoTokenHeader(server, token, 'X-Indexer-API-Token'), server, port);
153
- return new algosdk_1.Indexer(httpClientWithRetry);
154
- }
155
- exports.getAlgoIndexerClient = getAlgoIndexerClient;
156
- /**
157
- * Returns a KMD SDK client that automatically retries on idempotent calls
158
- *
159
- * KMD client allows you to export private keys, which is useful to get the default account in a sandbox network.
160
- *
161
- * @param config The config if you want to override the default (getting config from process.env)
162
- * @example Default (load from environment variables)
163
- *
164
- * ```
165
- * // Uses process.env.ALGOD_SERVER, process.env.KMD_PORT (or if not specified: port 4002) and process.env.ALGOD_TOKEN
166
- * const kmd = getAlgoKmdClient()
167
- * ```
168
- * @example Custom (e.g. default local sandbox, although we recommend loading this into a .env and using the Default option instead)
169
- * ```
170
- * const kmd = getAlgoKmdClient({server: 'http://localhost', port: '4002', token: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'})
171
- * ```
172
- */
173
- function getAlgoKmdClient(config) {
174
- const { token, server } = config ?? getAlgodConfigFromEnvironment();
175
- // We can only use Kmd on the Sandbox otherwise it's not exposed so this makes some assumptions
176
- // (e.g. same token and server as algod and port 4002 by default)
177
- return new algosdk_1.Kmd(token, server, process?.env?.KMD_PORT ?? '4002');
178
- }
179
- exports.getAlgoKmdClient = getAlgoKmdClient;
180
- var localnet_1 = require("./localnet");
181
- Object.defineProperty(exports, "isLocalNet", { enumerable: true, get: function () { return localnet_1.isLocalNet; } });
182
- //# sourceMappingURL=network-client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"network-client.js","sourceRoot":"","sources":["../src/network-client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAwD;AAExD,+EAAuE;AAYvE,mIAAmI;AACnI,SAAgB,6BAA6B;IAC3C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,kGAAkG,CAAC,CAAA;KACpH;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE;QAC7B,MAAM,IAAI,KAAK,CAAC,yGAAyG,CAAC,CAAA;KAC3H;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QAChC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;QAC5B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;KAC/B,CAAA;AACH,CAAC;AAdD,sEAcC;AAED,qIAAqI;AACrI,SAAgB,+BAA+B;IAC7C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5B,MAAM,IAAI,KAAK,CAAC,oGAAoG,CAAC,CAAA;KACtH;IAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,6GAA6G,CAAC,CAAA;KAC/H;IAED,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QAClC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QAC9B,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;KACjC,CAAA;AACH,CAAC;AAdD,0EAcC;AAED;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,OAA8B,EAAE,MAA2B;IAC3F,OAAO;QACL,MAAM,EAAE,WAAW,OAAO,IAAI,MAAM,KAAK,OAAO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D,sCAIC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,oBAAoB,CAAC,MAAyB;IAC5D,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,+BAA+B,EAAE,CAAA;IAC3E,MAAM,mBAAmB,GAAG,IAAI,qDAAuB,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,qBAAqB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IAC/H,OAAO,IAAI,iBAAO,CAAC,mBAAmB,CAAC,CAAA;AACzC,CAAC;AAJD,oDAIC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,gBAAgB,CAAC,MAAyB;IACxD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,6BAA6B,EAAE,CAAA;IACnE,+FAA+F;IAC/F,iEAAiE;IACjE,OAAO,IAAI,aAAG,CAAC,KAAe,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,IAAI,MAAM,CAAC,CAAA;AAC3E,CAAC;AALD,4CAKC;AAED,uCAAuC;AAA9B,sGAAA,UAAU,OAAA"}
package/dist/package.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "main": "index.js",
3
- "types": "index.d.ts",
4
- "name": "@algorandfoundation/algokit-utils",
5
- "version": "0.1.0",
6
- "private": false,
7
- "description": "A set of core Algorand utilities written in TypeScript and released via npm that make it easier to build solutions on Algorand.",
8
- "author": "Algorand Foundation",
9
- "license": "MIT",
10
- "engines": {
11
- "node": ">=16.0"
12
- },
13
- "files": [
14
- "dist/**/*"
15
- ],
16
- "dependencies": {
17
- "algosdk": "^2.1.0",
18
- "buffer": "^6.0.3"
19
- }
20
- }