@algorandfoundation/algokit-utils 7.0.0-beta.9 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/account/account.js +6 -4
- package/account/account.js.map +1 -1
- package/account/account.mjs +6 -4
- package/account/account.mjs.map +1 -1
- package/account/get-account-config-from-environment.js.map +1 -1
- package/account/get-account-config-from-environment.mjs.map +1 -1
- package/account/get-account.js.map +1 -1
- package/account/get-account.mjs.map +1 -1
- package/account/get-dispenser-account.js.map +1 -1
- package/account/get-dispenser-account.mjs.map +1 -1
- package/account/mnemonic-account.js.map +1 -1
- package/account/mnemonic-account.mjs.map +1 -1
- package/amount.js.map +1 -1
- package/amount.mjs.map +1 -1
- package/app-client.js.map +1 -1
- package/app-client.mjs.map +1 -1
- package/app-deploy.js +2 -10
- package/app-deploy.js.map +1 -1
- package/app-deploy.mjs +3 -11
- package/app-deploy.mjs.map +1 -1
- package/app.d.ts +2 -2
- package/app.js +2 -2
- package/app.js.map +1 -1
- package/app.mjs +2 -2
- package/app.mjs.map +1 -1
- package/asset.js.map +1 -1
- package/asset.mjs.map +1 -1
- package/debugging/debugging.js.map +1 -1
- package/debugging/debugging.mjs.map +1 -1
- package/dispenser-client.js.map +1 -1
- package/dispenser-client.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +6 -0
- package/index.js.map +1 -1
- package/index.mjs +2 -1
- package/index.mjs.map +1 -1
- package/indexer-lookup.js.map +1 -1
- package/indexer-lookup.mjs.map +1 -1
- package/localnet/get-kmd-wallet-account.js.map +1 -1
- package/localnet/get-kmd-wallet-account.mjs.map +1 -1
- package/localnet/get-localnet-dispenser-account.js.map +1 -1
- package/localnet/get-localnet-dispenser-account.mjs.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.js.map +1 -1
- package/localnet/get-or-create-kmd-wallet-account.mjs.map +1 -1
- package/localnet/is-localnet.js.map +1 -1
- package/localnet/is-localnet.mjs.map +1 -1
- package/network-client.js.map +1 -1
- package/network-client.mjs.map +1 -1
- package/package.json +5 -5
- package/testing/account.js.map +1 -1
- package/testing/account.mjs.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.js.map +1 -1
- package/testing/fixtures/algokit-log-capture-fixture.mjs.map +1 -1
- package/testing/fixtures/algorand-fixture.js.map +1 -1
- package/testing/fixtures/algorand-fixture.mjs.map +1 -1
- package/testing/indexer.js.map +1 -1
- package/testing/indexer.mjs.map +1 -1
- package/testing/test-logger.js.map +1 -1
- package/testing/test-logger.mjs.map +1 -1
- package/testing/transaction-logger.js.map +1 -1
- package/testing/transaction-logger.mjs.map +1 -1
- package/transaction/legacy-bridge.js +2 -2
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +3 -3
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.js +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.js.map +1 -1
- package/transaction/perform-atomic-transaction-composer-simulate.mjs +1 -0
- package/transaction/perform-atomic-transaction-composer-simulate.mjs.map +1 -1
- package/transaction/transaction.d.ts +14 -7
- package/transaction/transaction.js +57 -31
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs +55 -30
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer-algos.js.map +1 -1
- package/transfer/transfer-algos.mjs.map +1 -1
- package/transfer/transfer.js.map +1 -1
- package/transfer/transfer.mjs.map +1 -1
- package/types/account-manager.d.ts +1 -1
- package/types/account-manager.js +10 -8
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs +11 -9
- package/types/account-manager.mjs.map +1 -1
- package/types/account.d.ts +9 -0
- package/types/account.js.map +1 -1
- package/types/account.mjs.map +1 -1
- package/types/algo-http-client-with-retry.js.map +1 -1
- package/types/algo-http-client-with-retry.mjs.map +1 -1
- package/types/algorand-client-interface.d.ts +2 -2
- package/types/algorand-client-transaction-creator.d.ts +5 -3
- package/types/algorand-client-transaction-creator.js +3 -1
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs +3 -1
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.d.ts +12 -8
- package/types/algorand-client-transaction-sender.js +6 -2
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs +6 -2
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +3 -4
- package/types/algorand-client.js +2 -5
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +4 -4
- package/types/algorand-client.mjs.map +1 -1
- package/types/amount.js.map +1 -1
- package/types/amount.mjs.map +1 -1
- package/types/app-arc56.d.ts +31 -20
- package/types/app-arc56.js.map +1 -1
- package/types/app-arc56.mjs.map +1 -1
- package/types/app-client.d.ts +21 -10
- package/types/app-client.js +143 -36
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +141 -34
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.js +1 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs +2 -2
- package/types/app-deployer.mjs.map +1 -1
- package/types/app-factory.d.ts +32 -21
- package/types/app-factory.js +8 -2
- package/types/app-factory.js.map +1 -1
- package/types/app-factory.mjs +8 -2
- package/types/app-factory.mjs.map +1 -1
- package/types/app-manager.js +105 -23
- package/types/app-manager.js.map +1 -1
- package/types/app-manager.mjs +105 -23
- package/types/app-manager.mjs.map +1 -1
- package/types/app-spec.js +8 -2
- package/types/app-spec.js.map +1 -1
- package/types/app-spec.mjs +8 -2
- package/types/app-spec.mjs.map +1 -1
- package/types/app.d.ts +8 -7
- package/types/app.js.map +1 -1
- package/types/app.mjs.map +1 -1
- package/types/asset-manager.d.ts +4 -4
- package/types/asset-manager.js +2 -2
- package/types/asset-manager.js.map +1 -1
- package/types/asset-manager.mjs +2 -2
- package/types/asset-manager.mjs.map +1 -1
- package/types/async-event-emitter.d.ts +1 -10
- package/types/async-event-emitter.js +0 -5
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs +1 -6
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/client-manager.js +2 -2
- package/types/client-manager.js.map +1 -1
- package/types/client-manager.mjs +2 -2
- package/types/client-manager.mjs.map +1 -1
- package/types/composer.d.ts +56 -30
- package/types/composer.js +103 -47
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +104 -46
- package/types/composer.mjs.map +1 -1
- package/types/config.d.ts +0 -4
- package/types/config.js.map +1 -1
- package/types/config.mjs.map +1 -1
- package/types/debugging.d.ts +1 -1
- package/types/debugging.js +1 -1
- package/types/debugging.js.map +1 -1
- package/types/debugging.mjs +1 -1
- package/types/debugging.mjs.map +1 -1
- package/types/dispenser-client.js.map +1 -1
- package/types/dispenser-client.mjs.map +1 -1
- package/types/indexer.js.map +1 -1
- package/types/indexer.mjs.map +1 -1
- package/types/kmd-account-manager.js +1 -1
- package/types/kmd-account-manager.js.map +1 -1
- package/types/kmd-account-manager.mjs +2 -2
- package/types/kmd-account-manager.mjs.map +1 -1
- package/types/lifecycle-events.d.ts +10 -0
- package/types/lifecycle-events.js +8 -0
- package/types/lifecycle-events.js.map +1 -0
- package/types/lifecycle-events.mjs +8 -0
- package/types/lifecycle-events.mjs.map +1 -0
- package/types/logging.js.map +1 -1
- package/types/logging.mjs.map +1 -1
- package/types/logic-error.d.ts +2 -3
- package/types/logic-error.js +3 -3
- package/types/logic-error.js.map +1 -1
- package/types/logic-error.mjs +3 -3
- package/types/logic-error.mjs.map +1 -1
- package/types/network-client.js.map +1 -1
- package/types/network-client.mjs.map +1 -1
- package/types/testing.d.ts +1 -1
- package/types/transaction.d.ts +1 -1
- package/types/urlTokenBaseHTTPClient.js.map +1 -1
- package/types/urlTokenBaseHTTPClient.mjs.map +1 -1
- package/util.js.map +1 -1
- package/util.mjs.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kmd-account-manager.mjs","sources":["../../src/types/kmd-account-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { SigningAccount, TransactionSignerAccount } from './account'\nimport { AlgoAmount } from './amount'\nimport { ClientManager } from './client-manager'\nimport AlgoKitComposer from './composer'\n\n/** Provides abstractions over a [KMD](https://github.com/algorand/go-algorand/blob/master/daemon/kmd/README.md) instance\n * that makes it easier to get and manage accounts using KMD. */\nexport class KmdAccountManager {\n private _clientManager: Omit<ClientManager, 'kmd'>\n private _kmd?: algosdk.Kmd | null\n\n /**\n * Create a new KMD manager.\n * @param clientManager A ClientManager client to use for algod and kmd clients\n */\n constructor(clientManager: ClientManager) {\n this._clientManager = clientManager\n try {\n this._kmd = clientManager.kmd\n } catch {\n this._kmd = undefined\n }\n }\n\n async kmd(): Promise<algosdk.Kmd> {\n if (this._kmd === undefined) {\n if (await this._clientManager.isLocalNet()) {\n const { kmdConfig } = ClientManager.getConfigFromEnvironmentOrLocalNet()\n if (kmdConfig) {\n this._kmd = ClientManager.getKmdClient(kmdConfig)\n return this._kmd\n }\n }\n this._kmd = null\n }\n\n if (!this._kmd) {\n throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n }\n\n return this._kmd\n }\n\n /**\n * Returns an Algorand signing account with private key loaded from the given KMD wallet (identified by name).\n *\n * @param walletName The name of the wallet to retrieve an account from\n * @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)\n * @param sender The optional sender address to use this signer for (aka a rekeyed account)\n * @example Get default funded account in a LocalNet\n *\n * ```typescript\n * const defaultDispenserAccount = await kmdAccountManager.getWalletAccount(\n * 'unencrypted-default-wallet',\n * a => a.status !== 'Offline' && a.amount > 1_000_000_000\n * )\n * ```\n * @returns The signing account (with private key loaded) or undefined if no matching wallet or account was found\n */\n public async getWalletAccount(\n walletName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n predicate?: (account: Record<string, any>) => boolean,\n sender?: string,\n ): Promise<(TransactionSignerAccount & { account: SigningAccount }) | undefined> {\n const kmd = await this.kmd()\n\n const walletsResponse = await kmd.listWallets()\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const wallet = walletsResponse.wallets.filter((w: any) => w.name === walletName)\n if (wallet.length === 0) {\n return undefined\n }\n\n const walletId = wallet[0].id\n\n const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token\n const addresses = (await kmd.listKeys(walletHandle)).addresses\n\n let i = 0\n if (predicate) {\n for (i = 0; i < addresses.length; i++) {\n const address = addresses[i]\n const account = await this._clientManager.algod.accountInformation(address).do()\n if (predicate(account)) {\n break\n }\n }\n }\n\n if (i >= addresses.length) {\n return undefined\n }\n\n const accountKey = (await kmd.exportKey(walletHandle, '', addresses[i])).private_key\n\n const accountMnemonic = algosdk.secretKeyToMnemonic(accountKey)\n\n const account = algosdk.mnemonicToSecretKey(accountMnemonic)\n const signingAccount = new SigningAccount(account, sender)\n\n return {\n account: signingAccount,\n addr: signingAccount.addr,\n signer: signingAccount.signer,\n }\n }\n\n /**\n * 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.\n *\n * This is useful to get idempotent accounts from LocalNet without having to specify the private key (which will change when resetting the LocalNet).\n *\n * 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 LocalNet.\n *\n * If this is used via `mnemonicAccountFromEnvironment`, then you can even use the same code that runs on production without changes for local development!\n *\n * @param name The name of the wallet to retrieve / create\n * @param fundWith The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account\n *\n * @example\n * ```typescript\n * // Idempotently get (if exists) or crate (if it doesn't exist yet) an account by name using KMD\n * // if creating it then fund it with 2 ALGO from the default dispenser account\n * const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algo())\n * // This will return the same account as above since the name matches\n * const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1')\n * ```\n *\n * @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\n */\n public async getOrCreateWalletAccount(\n name: string,\n fundWith?: AlgoAmount,\n ): Promise<TransactionSignerAccount & { account: SigningAccount }> {\n // Get an existing account from the KMD wallet\n const existing = await this.getWalletAccount(name)\n if (existing) {\n return existing\n }\n\n const kmd = await this.kmd()\n\n // None existed: create the KMD wallet instead\n const walletId = (await kmd.createWallet(name, '')).wallet.id\n const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token\n await kmd.generateKey(walletHandle)\n\n // Get the account from the new KMD wallet\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const account = (await this.getWalletAccount(name))!\n\n Config.logger.info(\n `LocalNet account '${name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${\n fundWith?.algo ?? 1000\n } ALGO`,\n )\n\n // Fund the account from the dispenser\n const dispenser = await this.getLocalNetDispenserAccount()\n await new AlgoKitComposer({\n algod: this._clientManager.algod,\n getSigner: () => dispenser.signer,\n getSuggestedParams: () => this._clientManager.algod.getTransactionParams().do(),\n })\n .addPayment({\n amount: fundWith ?? AlgoAmount.Algo(1000),\n receiver: account.addr,\n sender: dispenser.addr,\n })\n .send()\n\n return account\n }\n\n /**\n * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).\n * @example\n * ```typescript\n * const dispenser = await kmdAccountManager.getLocalNetDispenserAccount()\n * ```\n * @returns The default LocalNet dispenser account\n */\n public async getLocalNetDispenserAccount() {\n if (!(await this._clientManager.isLocalNet())) {\n throw new Error(\"Can't get LocalNet dispenser account from non LocalNet network\")\n }\n\n const dispenser = await this.getWalletAccount('unencrypted-default-wallet', (a) => a.status !== 'Offline' && a.amount > 1_000_000_000)\n if (!dispenser) {\n throw new Error(\"Error retrieving LocalNet dispenser account; couldn't find the default account in KMD\")\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return dispenser\n }\n}\n"],"names":[],"mappings":";;;;;;;AAOA;AACgE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C,KAAK,CAAC,oBAAoB,EAAE,CAAC,EAAE,EAAE;SAChF,CAAC;AACC,aAAA,UAAU,CAAC;YACV,MAAM,EAAE,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;YACzC,QAAQ,EAAE,OAAO,CAAC,IAAI;YACtB,MAAM,EAAE,SAAS,CAAC,IAAI;SACvB,CAAC;AACD,aAAA,IAAI,EAAE,CAAA;AAET,QAAA,OAAO,OAAO,CAAA;KACf;AAED;;;;;;;AAOG;AACI,IAAA,MAAM,2BAA2B,GAAA;QACtC,IAAI,EAAE,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,EAAE;AAC7C,YAAA,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAA;SAClF;QAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,4BAA4B,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,GAAG,UAAa,CAAC,CAAA;QACtI,IAAI,CAAC,SAAS,EAAE;AACd,YAAA,MAAM,IAAI,KAAK,CAAC,uFAAuF,CAAC,CAAA;SACzG;;AAGD,QAAA,OAAO,SAAS,CAAA;KACjB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"kmd-account-manager.mjs","sources":["../../src/types/kmd-account-manager.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { Config } from '../config'\nimport { SigningAccount, TransactionSignerAccount } from './account'\nimport { AlgoAmount } from './amount'\nimport { ClientManager } from './client-manager'\nimport { TransactionComposer } from './composer'\n\n/** Provides abstractions over a [KMD](https://github.com/algorand/go-algorand/blob/master/daemon/kmd/README.md) instance\n * that makes it easier to get and manage accounts using KMD. */\nexport class KmdAccountManager {\n private _clientManager: Omit<ClientManager, 'kmd'>\n private _kmd?: algosdk.Kmd | null\n\n /**\n * Create a new KMD manager.\n * @param clientManager A ClientManager client to use for algod and kmd clients\n */\n constructor(clientManager: ClientManager) {\n this._clientManager = clientManager\n try {\n this._kmd = clientManager.kmd\n } catch {\n this._kmd = undefined\n }\n }\n\n async kmd(): Promise<algosdk.Kmd> {\n if (this._kmd === undefined) {\n if (await this._clientManager.isLocalNet()) {\n const { kmdConfig } = ClientManager.getConfigFromEnvironmentOrLocalNet()\n if (kmdConfig) {\n this._kmd = ClientManager.getKmdClient(kmdConfig)\n return this._kmd\n }\n }\n this._kmd = null\n }\n\n if (!this._kmd) {\n throw new Error('Attempt to use Kmd client in AlgoKit instance with no Kmd configured')\n }\n\n return this._kmd\n }\n\n /**\n * Returns an Algorand signing account with private key loaded from the given KMD wallet (identified by name).\n *\n * @param walletName The name of the wallet to retrieve an account from\n * @param predicate An optional filter to use to find the account (otherwise it will return a random account from the wallet)\n * @param sender The optional sender address to use this signer for (aka a rekeyed account)\n * @example Get default funded account in a LocalNet\n *\n * ```typescript\n * const defaultDispenserAccount = await kmdAccountManager.getWalletAccount(\n * 'unencrypted-default-wallet',\n * a => a.status !== 'Offline' && a.amount > 1_000_000_000\n * )\n * ```\n * @returns The signing account (with private key loaded) or undefined if no matching wallet or account was found\n */\n public async getWalletAccount(\n walletName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n predicate?: (account: Record<string, any>) => boolean,\n sender?: string,\n ): Promise<(TransactionSignerAccount & { account: SigningAccount }) | undefined> {\n const kmd = await this.kmd()\n\n const walletsResponse = await kmd.listWallets()\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const wallet = walletsResponse.wallets.filter((w: any) => w.name === walletName)\n if (wallet.length === 0) {\n return undefined\n }\n\n const walletId = wallet[0].id\n\n const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token\n const addresses = (await kmd.listKeys(walletHandle)).addresses\n\n let i = 0\n if (predicate) {\n for (i = 0; i < addresses.length; i++) {\n const address = addresses[i]\n const account = await this._clientManager.algod.accountInformation(address).do()\n if (predicate(account)) {\n break\n }\n }\n }\n\n if (i >= addresses.length) {\n return undefined\n }\n\n const accountKey = (await kmd.exportKey(walletHandle, '', addresses[i])).private_key\n\n const accountMnemonic = algosdk.secretKeyToMnemonic(accountKey)\n\n const account = algosdk.mnemonicToSecretKey(accountMnemonic)\n const signingAccount = new SigningAccount(account, sender)\n\n return {\n account: signingAccount,\n addr: signingAccount.addr,\n signer: signingAccount.signer,\n }\n }\n\n /**\n * 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.\n *\n * This is useful to get idempotent accounts from LocalNet without having to specify the private key (which will change when resetting the LocalNet).\n *\n * 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 LocalNet.\n *\n * If this is used via `mnemonicAccountFromEnvironment`, then you can even use the same code that runs on production without changes for local development!\n *\n * @param name The name of the wallet to retrieve / create\n * @param fundWith The number of Algo to fund the account with when it gets created, if not specified then 1000 ALGO will be funded from the dispenser account\n *\n * @example\n * ```typescript\n * // Idempotently get (if exists) or crate (if it doesn't exist yet) an account by name using KMD\n * // if creating it then fund it with 2 ALGO from the default dispenser account\n * const newAccount = await kmdAccountManager.getOrCreateWalletAccount('account1', (2).algo())\n * // This will return the same account as above since the name matches\n * const existingAccount = await kmdAccountManager.getOrCreateWalletAccount('account1')\n * ```\n *\n * @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\n */\n public async getOrCreateWalletAccount(\n name: string,\n fundWith?: AlgoAmount,\n ): Promise<TransactionSignerAccount & { account: SigningAccount }> {\n // Get an existing account from the KMD wallet\n const existing = await this.getWalletAccount(name)\n if (existing) {\n return existing\n }\n\n const kmd = await this.kmd()\n\n // None existed: create the KMD wallet instead\n const walletId = (await kmd.createWallet(name, '')).wallet.id\n const walletHandle = (await kmd.initWalletHandle(walletId, '')).wallet_handle_token\n await kmd.generateKey(walletHandle)\n\n // Get the account from the new KMD wallet\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const account = (await this.getWalletAccount(name))!\n\n Config.logger.info(\n `LocalNet account '${name}' doesn't yet exist; created account ${account.addr} with keys stored in KMD and funding with ${\n fundWith?.algo ?? 1000\n } ALGO`,\n )\n\n // Fund the account from the dispenser\n const dispenser = await this.getLocalNetDispenserAccount()\n await new TransactionComposer({\n algod: this._clientManager.algod,\n getSigner: () => dispenser.signer,\n getSuggestedParams: () => this._clientManager.algod.getTransactionParams().do(),\n })\n .addPayment({\n amount: fundWith ?? AlgoAmount.Algo(1000),\n receiver: account.addr,\n sender: dispenser.addr,\n })\n .send()\n\n return account\n }\n\n /**\n * Returns an Algorand account with private key loaded for the default LocalNet dispenser account (that can be used to fund other accounts).\n * @example\n * ```typescript\n * const dispenser = await kmdAccountManager.getLocalNetDispenserAccount()\n * ```\n * @returns The default LocalNet dispenser account\n */\n public async getLocalNetDispenserAccount() {\n if (!(await this._clientManager.isLocalNet())) {\n throw new Error(\"Can't get LocalNet dispenser account from non LocalNet network\")\n }\n\n const dispenser = await this.getWalletAccount('unencrypted-default-wallet', (a) => a.status !== 'Offline' && a.amount > 1_000_000_000)\n if (!dispenser) {\n throw new Error(\"Error retrieving LocalNet dispenser account; couldn't find the default account in KMD\")\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return dispenser\n }\n}\n"],"names":[],"mappings":";;;;;;;AAOA;AACgE;MACnD,iBAAiB,CAAA;AAI5B;;;AAGG;AACH,IAAA,WAAA,CAAY,aAA4B,EAAA;AACtC,QAAA,IAAI,CAAC,cAAc,GAAG,aAAa;AACnC,QAAA,IAAI;AACF,YAAA,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC,GAAG;;AAC7B,QAAA,MAAM;AACN,YAAA,IAAI,CAAC,IAAI,GAAG,SAAS;;;AAIzB,IAAA,MAAM,GAAG,GAAA;AACP,QAAA,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE;YAC3B,IAAI,MAAM,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,EAAE;gBAC1C,MAAM,EAAE,SAAS,EAAE,GAA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C;;;AAI1G,QAAA,OAAO,SAAS;;AAEnB;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AVMTracesEventData, TealSourcesDebugEventData } from './debugging';
|
|
2
|
+
export declare enum EventType {
|
|
3
|
+
TxnGroupSimulated = "TxnGroupSimulated",
|
|
4
|
+
AppCompiled = "AppCompiled"
|
|
5
|
+
}
|
|
6
|
+
export type EventDataMap = {
|
|
7
|
+
[EventType.TxnGroupSimulated]: AVMTracesEventData;
|
|
8
|
+
[EventType.AppCompiled]: TealSourcesDebugEventData;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.EventType = void 0;
|
|
4
|
+
(function (EventType) {
|
|
5
|
+
EventType["TxnGroupSimulated"] = "TxnGroupSimulated";
|
|
6
|
+
EventType["AppCompiled"] = "AppCompiled";
|
|
7
|
+
})(exports.EventType || (exports.EventType = {}));
|
|
8
|
+
//# sourceMappingURL=lifecycle-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-events.js","sources":["../../src/types/lifecycle-events.ts"],"sourcesContent":["import { AVMTracesEventData, TealSourcesDebugEventData } from './debugging'\n\nexport enum EventType {\n TxnGroupSimulated = 'TxnGroupSimulated',\n AppCompiled = 'AppCompiled',\n}\n\nexport type EventDataMap = {\n [EventType.TxnGroupSimulated]: AVMTracesEventData\n [EventType.AppCompiled]: TealSourcesDebugEventData\n [key: string]: unknown\n}\n"],"names":["EventType"],"mappings":";;AAEYA;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC;AACvC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC7B,CAAC,EAHWA,iBAAS,KAATA,iBAAS,GAGpB,EAAA,CAAA,CAAA;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-events.mjs","sources":["../../src/types/lifecycle-events.ts"],"sourcesContent":["import { AVMTracesEventData, TealSourcesDebugEventData } from './debugging'\n\nexport enum EventType {\n TxnGroupSimulated = 'TxnGroupSimulated',\n AppCompiled = 'AppCompiled',\n}\n\nexport type EventDataMap = {\n [EventType.TxnGroupSimulated]: AVMTracesEventData\n [EventType.AppCompiled]: TealSourcesDebugEventData\n [key: string]: unknown\n}\n"],"names":[],"mappings":"IAEY;AAAZ,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,mBAAA,CAAA,GAAA,mBAAuC;AACvC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;AAC7B,CAAC,EAHW,SAAS,KAAT,SAAS,GAGpB,EAAA,CAAA,CAAA;;;;"}
|
package/types/logging.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":";;AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK
|
|
1
|
+
{"version":3,"file":"logging.js","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":";;AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK;;AAGT,MAAA,iBAAiB,GAAW;IACvC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;AACjB,IAAA,KAAK,EAAE,MAAK,GAAG;;AAGJ,MAAA,oBAAoB,GAAW;IAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,KAAK,EAAE,OAAO,CAAC,KAAK;;AAGT,MAAA,oBAAoB,GAAW;IAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,IAAI,EAAE,MAAK,GAAG;AACd,IAAA,OAAO,EAAE,MAAK,GAAG;AACjB,IAAA,KAAK,EAAE,MAAK,GAAG;;AAGjB;AACa,MAAA,UAAU,GAAW;;AAEhC,IAAA,KAAK,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAExE,IAAA,IAAI,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAEvE,IAAA,IAAI,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAEvE,IAAA,OAAO,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAE1E,IAAA,KAAK,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;;;;;;;;"}
|
package/types/logging.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.mjs","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":"AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK
|
|
1
|
+
{"version":3,"file":"logging.mjs","sources":["../../src/types/logging.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\n/** General purpose logger type, compatible with Winston and others. */\nexport type Logger = {\n error(message: string, ...optionalParams: unknown[]): void\n warn(message: string, ...optionalParams: unknown[]): void\n info(message: string, ...optionalParams: unknown[]): void\n verbose(message: string, ...optionalParams: unknown[]): void\n debug(message: string, ...optionalParams: unknown[]): void\n}\n\n/** A logger implementation that writes to console */\nexport const consoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: console.debug,\n}\n\nexport const infoConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: () => {},\n debug: () => {},\n}\n\nexport const verboseConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: console.info,\n verbose: console.trace,\n debug: console.debug,\n}\n\nexport const warningConsoleLogger: Logger = {\n error: console.error,\n warn: console.warn,\n info: () => {},\n verbose: () => {},\n debug: () => {},\n}\n\n/** A logger implementation that does nothing */\nexport const nullLogger: Logger = {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n error: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n warn: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n info: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n verbose: function (message: string, ...optionalParams: unknown[]): void {},\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n debug: function (message: string, ...optionalParams: unknown[]): void {},\n}\n"],"names":[],"mappings":"AAAA;AACA;AAWA;AACa,MAAA,aAAa,GAAW;IACnC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;IACjB,KAAK,EAAE,OAAO,CAAC,KAAK;;AAGT,MAAA,iBAAiB,GAAW;IACvC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,OAAO,EAAE,MAAK,GAAG;AACjB,IAAA,KAAK,EAAE,MAAK,GAAG;;AAGJ,MAAA,oBAAoB,GAAW;IAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,IAAI,EAAE,OAAO,CAAC,IAAI;IAClB,OAAO,EAAE,OAAO,CAAC,KAAK;IACtB,KAAK,EAAE,OAAO,CAAC,KAAK;;AAGT,MAAA,oBAAoB,GAAW;IAC1C,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC,IAAI;AAClB,IAAA,IAAI,EAAE,MAAK,GAAG;AACd,IAAA,OAAO,EAAE,MAAK,GAAG;AACjB,IAAA,KAAK,EAAE,MAAK,GAAG;;AAGjB;AACa,MAAA,UAAU,GAAW;;AAEhC,IAAA,KAAK,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAExE,IAAA,IAAI,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAEvE,IAAA,IAAI,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAEvE,IAAA,OAAO,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;AAE1E,IAAA,KAAK,EAAE,UAAU,OAAe,EAAE,GAAG,cAAyB,KAAU;;;;;"}
|
package/types/logic-error.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type algosdk from 'algosdk';
|
|
2
1
|
/**
|
|
3
2
|
* Details about a smart contract logic error
|
|
4
3
|
*/
|
|
@@ -30,7 +29,7 @@ export declare class LogicError extends Error {
|
|
|
30
29
|
* Create a new logic error object.
|
|
31
30
|
* @param errorDetails The details of the logic error
|
|
32
31
|
* @param program The TEAL source code, split by line
|
|
33
|
-
* @param
|
|
32
|
+
* @param getLineForPc The source map of the TEAL source code
|
|
34
33
|
*/
|
|
35
|
-
constructor(errorDetails: LogicErrorDetails, program: string[],
|
|
34
|
+
constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined);
|
|
36
35
|
}
|
package/types/logic-error.js
CHANGED
|
@@ -25,15 +25,15 @@ class LogicError extends Error {
|
|
|
25
25
|
* Create a new logic error object.
|
|
26
26
|
* @param errorDetails The details of the logic error
|
|
27
27
|
* @param program The TEAL source code, split by line
|
|
28
|
-
* @param
|
|
28
|
+
* @param getLineForPc The source map of the TEAL source code
|
|
29
29
|
*/
|
|
30
|
-
constructor(errorDetails, program,
|
|
30
|
+
constructor(errorDetails, program, getLineForPc) {
|
|
31
31
|
super();
|
|
32
32
|
this.lines = 5;
|
|
33
33
|
this.teal_line = 0;
|
|
34
34
|
this.led = errorDetails;
|
|
35
35
|
this.program = program;
|
|
36
|
-
const line =
|
|
36
|
+
const line = getLineForPc(errorDetails.pc);
|
|
37
37
|
this.teal_line = line === undefined ? 0 : line;
|
|
38
38
|
this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`;
|
|
39
39
|
if (this.teal_line > 0) {
|
package/types/logic-error.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic-error.js","sources":["../../src/types/logic-error.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"logic-error.js","sources":["../../src/types/logic-error.ts"],"sourcesContent":["const LOGIC_ERROR = /transaction ([A-Z0-9]+): logic eval error: (.*). Details: .*pc=([0-9]+).*/\n\n/**\n * Details about a smart contract logic error\n */\nexport interface LogicErrorDetails {\n /** The ID of the transaction with the logic error */\n txId: string\n /** The program counter where the error was */\n pc: number\n /** The error message */\n msg: string\n /** The full error description */\n desc: string\n /** Any trace information included in the error */\n traces: Record<string, unknown>[]\n}\n\n/** Wraps key functionality around processing logic errors */\nexport class LogicError extends Error {\n /** Takes an error message and parses out the details of any logic errors in there.\n * @param error The error message to parse\n * @returns The logic error details if any, or undefined\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static parseLogicError(error: any): LogicErrorDetails | undefined {\n const errorMessage = error.message\n const res = LOGIC_ERROR.exec(errorMessage)\n if (res === null || res.length <= 3) return undefined\n\n return {\n txId: res[1],\n msg: res[2],\n desc: errorMessage,\n pc: parseInt(res[3] ? res[3] : '0'),\n traces: error.traces,\n } as LogicErrorDetails\n }\n\n public led: LogicErrorDetails\n public program: string[]\n public lines = 5\n public teal_line = 0\n override stack?: string\n\n /**\n * Create a new logic error object.\n * @param errorDetails The details of the logic error\n * @param program The TEAL source code, split by line\n * @param getLineForPc The source map of the TEAL source code\n */\n constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined) {\n super()\n this.led = errorDetails\n this.program = program\n\n const line = getLineForPc(errorDetails.pc)\n this.teal_line = line === undefined ? 0 : line\n\n this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`\n\n if (this.teal_line > 0) {\n const start = this.teal_line > this.lines ? this.teal_line - this.lines : 0\n const stop = program.length > this.teal_line + this.lines ? this.teal_line + this.lines : program.length\n\n const stack_lines = program.slice(start, stop)\n\n stack_lines[stack_lines.length / 2] += ' <--- Error'\n\n this.stack = stack_lines.join('\\n')\n }\n }\n}\n"],"names":[],"mappings":";;AAAA,MAAM,WAAW,GAAG,2EAA2E;AAkB/F;AACM,MAAO,UAAW,SAAQ,KAAK,CAAA;AACnC;;;AAGG;;IAEH,OAAO,eAAe,CAAC,KAAU,EAAA;AAC/B,QAAA,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO;QAClC,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1C,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;AAAE,YAAA,OAAO,SAAS;QAErD,OAAO;AACL,YAAA,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AACZ,YAAA,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACX,YAAA,IAAI,EAAE,YAAY;AAClB,YAAA,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;YACnC,MAAM,EAAE,KAAK,CAAC,MAAM;SACA;;AASxB;;;;;AAKG;AACH,IAAA,WAAA,CAAY,YAA+B,EAAE,OAAiB,EAAE,YAAgD,EAAA;AAC9G,QAAA,KAAK,EAAE;QAXF,IAAK,CAAA,KAAA,GAAG,CAAC;QACT,IAAS,CAAA,SAAA,GAAG,CAAC;AAWlB,QAAA,IAAI,CAAC,GAAG,GAAG,YAAY;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;QAEtB,MAAM,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC,EAAE,CAAC;AAC1C,QAAA,IAAI,CAAC,SAAS,GAAG,IAAI,KAAK,SAAS,GAAG,CAAC,GAAG,IAAI;AAE9C,QAAA,IAAI,CAAC,OAAO,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAQ,KAAA,EAAA,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;AAE9D,QAAA,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC;AAC3E,YAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM;YAExG,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;YAE9C,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,aAAa;YAEpD,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;;AAGxC;;;;"}
|
package/types/logic-error.mjs
CHANGED
|
@@ -23,15 +23,15 @@ class LogicError extends Error {
|
|
|
23
23
|
* Create a new logic error object.
|
|
24
24
|
* @param errorDetails The details of the logic error
|
|
25
25
|
* @param program The TEAL source code, split by line
|
|
26
|
-
* @param
|
|
26
|
+
* @param getLineForPc The source map of the TEAL source code
|
|
27
27
|
*/
|
|
28
|
-
constructor(errorDetails, program,
|
|
28
|
+
constructor(errorDetails, program, getLineForPc) {
|
|
29
29
|
super();
|
|
30
30
|
this.lines = 5;
|
|
31
31
|
this.teal_line = 0;
|
|
32
32
|
this.led = errorDetails;
|
|
33
33
|
this.program = program;
|
|
34
|
-
const line =
|
|
34
|
+
const line = getLineForPc(errorDetails.pc);
|
|
35
35
|
this.teal_line = line === undefined ? 0 : line;
|
|
36
36
|
this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`;
|
|
37
37
|
if (this.teal_line > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logic-error.mjs","sources":["../../src/types/logic-error.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"logic-error.mjs","sources":["../../src/types/logic-error.ts"],"sourcesContent":["const LOGIC_ERROR = /transaction ([A-Z0-9]+): logic eval error: (.*). Details: .*pc=([0-9]+).*/\n\n/**\n * Details about a smart contract logic error\n */\nexport interface LogicErrorDetails {\n /** The ID of the transaction with the logic error */\n txId: string\n /** The program counter where the error was */\n pc: number\n /** The error message */\n msg: string\n /** The full error description */\n desc: string\n /** Any trace information included in the error */\n traces: Record<string, unknown>[]\n}\n\n/** Wraps key functionality around processing logic errors */\nexport class LogicError extends Error {\n /** Takes an error message and parses out the details of any logic errors in there.\n * @param error The error message to parse\n * @returns The logic error details if any, or undefined\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static parseLogicError(error: any): LogicErrorDetails | undefined {\n const errorMessage = error.message\n const res = LOGIC_ERROR.exec(errorMessage)\n if (res === null || res.length <= 3) return undefined\n\n return {\n txId: res[1],\n msg: res[2],\n desc: errorMessage,\n pc: parseInt(res[3] ? res[3] : '0'),\n traces: error.traces,\n } as LogicErrorDetails\n }\n\n public led: LogicErrorDetails\n public program: string[]\n public lines = 5\n public teal_line = 0\n override stack?: string\n\n /**\n * Create a new logic error object.\n * @param errorDetails The details of the logic error\n * @param program The TEAL source code, split by line\n * @param getLineForPc The source map of the TEAL source code\n */\n constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined) {\n super()\n this.led = errorDetails\n this.program = program\n\n const line = getLineForPc(errorDetails.pc)\n this.teal_line = line === undefined ? 0 : line\n\n this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`\n\n if (this.teal_line > 0) {\n const start = this.teal_line > this.lines ? this.teal_line - this.lines : 0\n const stop = program.length > this.teal_line + this.lines ? this.teal_line + this.lines : program.length\n\n const stack_lines = program.slice(start, stop)\n\n stack_lines[stack_lines.length / 2]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QAAA,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC;AAC3E,YAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM;YAExG,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC;YAE9C,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,aAAa;YAEpD,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;;;AAGxC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-client.js","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":";;AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc
|
|
1
|
+
{"version":3,"file":"network-client.js","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":";;AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc;AAChG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network-client.mjs","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":"AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc
|
|
1
|
+
{"version":3,"file":"network-client.mjs","sources":["../../src/types/network-client.ts"],"sourcesContent":["import type { TokenHeader } from 'algosdk/dist/types/client/urlTokenBaseHTTPClient'\n\n/** Config for an Algorand SDK client. */\nexport interface AlgoClientConfig {\n /** Base URL of the server e.g. http://localhost, https://testnet-api.algonode.cloud/, etc. */\n server: string\n /** The port to use e.g. 4001, 443, etc. */\n port?: string | number\n /** The token to use for API authentication (or undefined if none needed) - can be a string, or an object with the header key => value */\n token?: string | TokenHeader\n}\n\n/** Configuration for algod, indexer and kmd clients. */\nexport interface AlgoConfig {\n /** Algod client configuration */\n algodConfig: AlgoClientConfig\n /** Indexer client configuration */\n indexerConfig?: AlgoClientConfig\n /** Kmd configuration */\n kmdConfig?: AlgoClientConfig\n}\n\n/** Details of the current network. */\nexport interface NetworkDetails {\n /** Whether or not the network is TestNet. */\n isTestNet: boolean\n /** Whether or not the network is MainNet. */\n isMainNet: boolean\n /** Whether or not the network is LocalNet. */\n isLocalNet: boolean\n /** The genesis ID of the current network. */\n genesisId: string\n /** The base64 genesis hash of the current network. */\n genesisHash: string\n}\n\n/**\n * Returns true if the given network genesisId is associated with a LocalNet network.\n * @param genesisId The network genesis ID\n * @returns Whether the given genesis ID is associated with a LocalNet network\n */\nexport function genesisIdIsLocalNet(genesisId: string) {\n return genesisId === 'devnet-v1' || genesisId === 'sandnet-v1' || genesisId === 'dockernet-v1'\n}\n"],"names":[],"mappings":"AAoCA;;;;AAIG;AACG,SAAU,mBAAmB,CAAC,SAAiB,EAAA;IACnD,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,YAAY,IAAI,SAAS,KAAK,cAAc;AAChG;;;;"}
|
package/types/testing.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { TransactionLogger } from '../testing';
|
|
|
3
3
|
import { TestLogger } from '../testing/test-logger';
|
|
4
4
|
import { AlgoAmount } from '../types/amount';
|
|
5
5
|
import { MultisigAccount, SigningAccount, TransactionSignerAccount } from './account';
|
|
6
|
-
import AlgorandClient from './algorand-client';
|
|
6
|
+
import { AlgorandClient } from './algorand-client';
|
|
7
7
|
import { TransactionLookupResult } from './indexer';
|
|
8
8
|
import { AlgoConfig } from './network-client';
|
|
9
9
|
import Account = algosdk.Account;
|
package/types/transaction.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface SendTransactionParams {
|
|
|
37
37
|
maxFee?: AlgoAmount;
|
|
38
38
|
/** The maximum number of rounds to wait for confirmation, only applies if `skipWaiting` is `undefined` or `false`, default: wait up to 5 rounds */
|
|
39
39
|
maxRoundsToWaitForConfirmation?: number;
|
|
40
|
-
/**
|
|
40
|
+
/** Whether to use simulate to automatically populate app call resources in the txn objects. Defaults to true when there are app calls in the group. */
|
|
41
41
|
populateAppCallResources?: boolean;
|
|
42
42
|
}
|
|
43
43
|
/** Result from sending a single transaction. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlTokenBaseHTTPClient.js","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":["Buffer"],"mappings":";;;;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAwB;AAGvC,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;KACzB;AACF,CAAA;AAID;;;;AAIG;MACU,sBAAsB,CAAA;;AAKjC,IAAA,WAAA,CACE,WAAwB,EACxB,UAAkB,EAClB,IAAsB;;AAEd,IAAA,cAAA,GAAsC,EAAE,EAAA;QAAxC,IAAc,CAAA,cAAA,GAAd,cAAc,CAA0B;;;;AAKhD,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,CAAG,EAAA,UAAU,GAAG,CAAA;AAChF,QAAA,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;AAC9C,QAAA,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;AAC/B,YAAA,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;SACrC;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACvC,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;SACtE;AAED,QAAA,IAAI,CAAC,OAAO,GAAG,aAAa,CAAA;AAC5B,QAAA,IAAI,CAAC,WAAW,GAAG,WAAW,C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,IAAI;YACV,OAAO;AACR,SAAA,CAAC,CAAA;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;KACvD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"urlTokenBaseHTTPClient.js","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":["Buffer"],"mappings":";;;;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ;AAGf,QAAA,IAAI,CAAC,IAAI,GAA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;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;IAGxD,MAAM,MAAM,CACV,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;AAEzD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlTokenBaseHTTPClient.mjs","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":[],"mappings":";;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,IAAQ,CAAA,QAAA,GAAR,QAAQ,CAAwB;AAGvC,QAAA,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;AACnC,QAAA,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;KACzB;AACF,CAAA;AAID;;;;AAIG;MACU,sBAAsB,CAAA;;AAKjC,IAAA,WAAA,CACE,WAAwB,EACxB,UAAkB,EAClB,IAAsB;;AAEd,IAAA,cAAA,GAAsC,EAAE,EAAA;QAAxC,IAAc,CAAA,cAAA,GAAd,cAAc,CAA0B;;;;AAKhD,QAAA,MAAM,eAAe,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,UAAU,GAAG,CAAG,EAAA,UAAU,GAAG,CAAA;AAChF,QAAA,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;AAC9C,QAAA,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;AAC/B,YAAA,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAA;SACrC;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACvC,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAA;SACtE;AAED,QAAA,IAAI,CAAC,OAAO,GAAG,aAA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AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC,CAAA;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;KACvD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"urlTokenBaseHTTPClient.mjs","sources":["../../src/types/urlTokenBaseHTTPClient.ts"],"sourcesContent":["// Copied from https://github.com/algorand/js-algorand-sdk/blob/e9635e9ffc9019994f0790ee4b8d9733c6590250/src/client/urlTokenBaseHTTPClient.ts\n// There was an error trying to reference the file from algosdk\n// This is referenced from algo-http-client-with-retry.ts and extended to add retry logic to improve resilience\n// todo: Find out why this can't be referenced from algosdk directly so we don't have to duplicate here\nimport type { BaseHTTPClient, BaseHTTPClientError, BaseHTTPClientResponse, Query } from 'algosdk/dist/types/client/baseHTTPClient'\nimport { Buffer } from 'buffer'\n\nexport interface AlgodTokenHeader {\n 'X-Algo-API-Token': string\n}\n\nexport interface IndexerTokenHeader {\n 'X-Indexer-API-Token': string\n}\n\nexport interface KMDTokenHeader {\n 'X-KMD-API-Token': string\n}\n\nexport interface CustomTokenHeader {\n [headerName: string]: string\n}\n\nclass URLTokenBaseHTTPError extends Error implements BaseHTTPClientError {\n constructor(\n message: string,\n public response: BaseHTTPClientResponse,\n ) {\n super(message)\n this.name = 'URLTokenBaseHTTPError'\n this.response = response\n }\n}\n\nexport type TokenHeader = AlgodTokenHeader | IndexerTokenHeader | KMDTokenHeader | CustomTokenHeader\n\n/**\n * Implementation of BaseHTTPClient that uses a URL and a token\n * and make the REST queries using fetch.\n * This is the default implementation of BaseHTTPClient.\n */\nexport class URLTokenBaseHTTPClient implements BaseHTTPClient {\n private readonly baseURL: URL\n private readonly tokenHeader: TokenHeader\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(\n tokenHeader: TokenHeader,\n baseServer: string,\n port?: string | number,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private defaultHeaders: Record<string, any> = {},\n ) {\n // Append a trailing slash so we can use relative paths. Without the trailing\n // slash, the last path segment will be replaced by the relative path. See\n // usage in `addressWithPath`.\n const fixedBaseServer = baseServer.endsWith('/') ? baseServer : `${baseServer}/`\n const baseServerURL = new URL(fixedBaseServer)\n if (typeof port !== 'undefined') {\n baseServerURL.port = port.toString()\n }\n\n if (baseServerURL.protocol.length === 0) {\n throw new Error('Invalid base server URL, protocol must be defined.')\n }\n\n this.baseURL = baseServerURL\n this.tokenHeader = tokenHeader\n }\n\n /**\n * Compute the URL for a path relative to the instance's address\n * @param relativePath - A path string\n * @param query - An optional key-value object of query parameters to add to the URL. If the\n * relativePath already has query parameters on it, the additional parameters defined here will\n * be added to the URL without modifying those (unless a key collision occurs).\n * @returns A URL string\n */\n private getURL(relativePath: string, query?: Query<string>): string {\n let fixedRelativePath: string\n if (relativePath.startsWith('./')) {\n fixedRelativePath = relativePath\n } else if (relativePath.startsWith('/')) {\n fixedRelativePath = `.${relativePath}`\n } else {\n fixedRelativePath = `./${relativePath}`\n }\n const address = new URL(fixedRelativePath, this.baseURL)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n address.searchParams.set(key, value)\n }\n }\n return address.toString()\n }\n\n private static formatFetchResponseHeaders(headers: Headers): Record<string, string> {\n const headersObj: Record<string, string> = {}\n headers.forEach((key, value) => {\n headersObj[key] = value\n })\n return headersObj\n }\n\n private static async checkHttpError(res: Response) {\n if (res.ok) {\n return\n }\n\n let body: Uint8Array | null = null\n let bodyErrorMessage: string | null = null\n\n try {\n body = new Uint8Array(await res.arrayBuffer())\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const decoded: Record<string, any> = JSON.parse(Buffer.from(body).toString())\n if (decoded.message) {\n bodyErrorMessage = decoded.message\n }\n } catch {\n // ignore any error that happened while we are parsing the error response\n }\n\n let message = `Network request error. Received status ${res.status} (${res.statusText})`\n if (bodyErrorMessage) {\n message += `: ${bodyErrorMessage}`\n }\n\n throw new URLTokenBaseHTTPError(message, {\n body: body !== null ? body : new Uint8Array(),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n })\n }\n\n private static async formatFetchResponse(res: Response): Promise<BaseHTTPClientResponse> {\n await this.checkHttpError(res)\n return {\n body: new Uint8Array(await res.arrayBuffer()),\n status: res.status,\n headers: URLTokenBaseHTTPClient.formatFetchResponseHeaders(res.headers),\n }\n }\n\n async get(relativePath: string, query?: Query<string>, requestHeaders: Record<string, string> = {}): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n mode: 'cors',\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async post(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'POST',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n\n async delete(\n relativePath: string,\n data: Uint8Array,\n query?: Query<string>,\n requestHeaders: Record<string, string> = {},\n ): Promise<BaseHTTPClientResponse> {\n // Expand headers for use in fetch\n const headers = {\n ...this.tokenHeader,\n ...this.defaultHeaders,\n ...requestHeaders,\n }\n\n const res = await fetch(this.getURL(relativePath, query), {\n method: 'DELETE',\n mode: 'cors',\n body: data,\n headers,\n })\n\n return URLTokenBaseHTTPClient.formatFetchResponse(res)\n }\n}\n"],"names":[],"mappings":";;AAuBA,MAAM,qBAAsB,SAAQ,KAAK,CAAA;IACvC,WACE,CAAA,OAAe,EACR,QAAgC,EAAA;QAEvC,KAAK,CAAC,OAAO,CAAC;QAFP,IAAQ,CAAA,QAAA,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IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;IAGxD,MAAM,MAAM,CACV,YAAoB,EACpB,IAAgB,EAChB,KAAqB,EACrB,cAAA,GAAyC,EAAE,EAAA;;AAG3C,QAAA,MAAM,OAAO,GAAG;YACd,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,IAAI,CAAC,cAAc;AACtB,YAAA,GAAG,cAAc;SAClB;AAED,QAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE;AACxD,YAAA,MAAM,EAAE,QAAQ;AAChB,YAAA,IAAI,EAAE,MAAM;AACZ,YAAA,IAAI,EAAE,IAAI;YACV,OAAO;AACR,SAAA,CAAC;AAEF,QAAA,OAAO,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC;;AAEzD;;;;"}
|
package/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK
|
|
1
|
+
{"version":3,"file":"util.js","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":";;AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAC3C,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,oFAAA,CAAsF,CAC9G;;SACI,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAClD,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,qFAAA,CAAuF,CAC/G;;AAEH,IAAA,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB;AAEM,MAAO,qBAAsB,SAAQ,KAAK,CAAA;AAAG;AAEnD;;;;;;AAMG;AACU,MAAA,mBAAmB,GAAG,CACjC,kBAA0B,EAC1B,sBAA8B,EAC9B,mBAA2B,KACV;AACjB,IAAA,IAAI,kBAAkB,GAAG,sBAAsB,EAAE;AAC/C,QAAA,MAAM,aAAa,GAAG,kBAAkB,GAAG,sBAAsB;AACjE,QAAA,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;;SACtE;AACL,QAAA,OAAO,IAAI;;AAEf;AAWA;;;;;AAKG;UACc,UAAU,CAAI,KAAU,EAAE,SAAiB,EAAA;AAC1D,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,SAAS;QAAE,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;AACvF;AAEA;;;;AAIG;AACU,MAAA,OAAO,GAAG,CAA2B,EAAiB,KAAI;AACrE,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAE;IACvB,MAAM,MAAM,GAAG,UAAyB,GAAM,EAAA;AAC5C,QAAA,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;AAC/F,KAAC;AACD,IAAA,MAAM,CAAC,KAAK,GAAG,KAAK;AACpB,IAAA,OAAO,MAAuB;AAChC;MAEa,gBAAgB,GAAG,CAAC,IAAgB,EAAE,UAAsB,KAAa;AACpF,IAAA,IAAI,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;AAAE,QAAA,OAAO,KAAK;AACjD,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC;AAAE,YAAA,OAAO,KAAK;;AAE7C,IAAA,OAAO,IAAI;AACb;;;;;;;;;"}
|
package/util.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.mjs","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK
|
|
1
|
+
{"version":3,"file":"util.mjs","sources":["../src/util.ts"],"sourcesContent":["/**\n * Converts a value which might be a number or a bigint into a number to be used with apis that don't support bigint.\n *\n * Throws an UnsafeConversionError if the conversion would result in an unsafe integer for the Number type\n * @param value\n */\nexport const toNumber = (value: number | bigint) => {\n if (typeof value === 'number') return value\n\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is larger than the maximum safe integer the Number type can hold.`,\n )\n } else if (value < BigInt(Number.MIN_SAFE_INTEGER)) {\n throw new UnsafeConversionError(\n `Cannot convert ${value} to a Number as it is smaller than the minimum safe integer the Number type can hold.`,\n )\n }\n return Number(value)\n}\n\nexport class UnsafeConversionError extends Error {}\n\n/**\n * Calculates the amount of funds to add to a wallet to bring it up to the minimum spending balance.\n * @param minSpendingBalance The minimum spending balance for the wallet\n * @param currentSpendingBalance The current spending balance for the wallet\n * @param minFundingIncrement The minimum amount of funds that can be added to the wallet\n * @returns The amount of funds to add to the wallet or null if the wallet is already above the minimum spending balance\n */\nexport const calculateFundAmount = (\n minSpendingBalance: bigint,\n currentSpendingBalance: bigint,\n minFundingIncrement: bigint,\n): bigint | null => {\n if (minSpendingBalance > currentSpendingBalance) {\n const minFundAmount = minSpendingBalance - currentSpendingBalance\n return BigInt(Math.max(Number(minFundAmount), Number(minFundingIncrement)))\n } else {\n return null\n }\n}\n\n/**\n * Checks if the current environment is Node.js\n *\n * @returns A boolean indicating whether the current environment is Node.js\n */\nexport const isNode = () => {\n return typeof process !== 'undefined' && process.versions != null && process.versions.node != null\n}\n\n/**\n * Returns the given array split into chunks of `batchSize` batches.\n * @param array The array to chunk\n * @param batchSize The size of batches to split the array into\n * @returns A generator that yields the array split into chunks of `batchSize` batches\n */\nexport function* chunkArray<T>(array: T[], batchSize: number): Generator<T[], void> {\n for (let i = 0; i < array.length; i += batchSize) yield array.slice(i, i + batchSize)\n}\n\n/**\n * Memoize calls to the given function in an in-memory map.\n * @param fn The function to memoize\n * @returns The memoized function\n */\nexport const memoize = <T = unknown, R = unknown>(fn: (val: T) => R) => {\n const cache = new Map()\n const cached = function (this: unknown, val: T) {\n return cache.has(val) ? cache.get(val) : cache.set(val, fn.call(this, val)) && cache.get(val)\n }\n cached.cache = cache\n return cached as (val: T) => R\n}\n\nexport const binaryStartsWith = (base: Uint8Array, startsWith: Uint8Array): boolean => {\n if (startsWith.length > base.length) return false\n for (let i = 0; i < startsWith.length; i++) {\n if (base[i] !== startsWith[i]) return false\n }\n return true\n}\n"],"names":[],"mappings":"AAAA;;;;;AAKG;AACU,MAAA,QAAQ,GAAG,CAAC,KAAsB,KAAI;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;AAAE,QAAA,OAAO,KAAK;IAE3C,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAC3C,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,oFAAA,CAAsF,CAC9G;;SACI,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,EAAE;AAClD,QAAA,MAAM,IAAI,qBAAqB,CAC7B,kBAAkB,KAAK,CAAA,qFAAA,CAAuF,CAC/G;;AAEH,IAAA,OAAO,MAAM,CAAC,KAAK,CAAC;AACtB;AAEM,MAAO,qBAAsB,SAAQ,KAAK,CAAA;AAAG;AAEnD;;;;;;AAMG;AACU,MAAA,mBAAmB,GAAG,CACjC,kBAA0B,EAC1B,sBAA8B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