{"version":3,"file":"get-account.mjs","names":[],"sources":["../../src/account/get-account.ts"],"sourcesContent":["import algosdk from 'algosdk'\nimport { AccountConfig, SigningAccount } from '../types/account'\nimport { AccountManager } from '../types/account-manager'\nimport { AlgoAmount } from '../types/amount'\nimport { ClientManager } from '../types/client-manager'\nimport Account = algosdk.Account\nimport Algodv2 = algosdk.Algodv2\nimport Kmd = algosdk.Kmd\n\n/**  @deprecated use `algorand.account.fromEnvironment()` instead\n *\n * Returns an Algorand account with private key loaded by convention based on the given name identifier.\n *\n * Note: This function expects to run in a Node.js environment.\n *\n * ## Convention:\n * * **Non-LocalNet:** will load process.env['\\{NAME\\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,\n *  never commit it into source control and ideally load it via a secret storage service rather than the file system.\n *   If process.env['\\{NAME\\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)\n * * **LocalNet:** will load the account from a KMD wallet called \\{NAME\\} and if that wallet doesn't exist it will create it and fund the account for you\n *\n * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).\n *\n * @example Default\n *\n * If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:\n * ```typescript\n * const account = await getAccount('ACCOUNT', algod)\n * ```\n *\n * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.\n *\n * @param account The details of the account to get, either the name identifier (string) or an object with:\n *   * `name`: The name identifier of the account\n *   * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account\n * @param algod An algod client\n * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables\n * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)\n */\nexport async function getAccount(\n  account: { name: string; fundWith?: AlgoAmount } | string,\n  algod: Algodv2,\n  kmdClient?: Kmd,\n): Promise<Account | SigningAccount>\n\n/**  @deprecated use `algorand.account.fromEnvironment()` instead\n * Returns an Algorand account with private key loaded by convention based on the given name identifier.\n *\n * Note: This function expects to run in a Node.js environment.\n *\n * @example Default\n *\n * If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:\n * ```typescript\n * const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod)\n * ```\n *\n * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.\n *\n * @param account The details of the account to get, an object with:\n *   * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName)\n *   * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account\n * @param algod An algod client\n * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables\n * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)\n */\nexport async function getAccount(\n  account: { config: AccountConfig; fundWith?: AlgoAmount },\n  algod: Algodv2,\n  kmdClient?: Kmd,\n): Promise<Account | SigningAccount>\n\n/**  @deprecated use `algorand.account.fromEnvironment()` instead\n * Returns an Algorand account with private key loaded by convention based on the given name identifier.\n *\n * Note: This function expects to run in a Node.js environment.\n *\n * ## Convention:\n * * **Non-LocalNet:** will load process.env['\\{NAME\\}_MNEMONIC'] as a mnemonic secret; **Note: Be careful how the mnemonic is handled**,\n *  never commit it into source control and ideally load it via a secret storage service rather than the file system.\n *   If process.env['\\{NAME\\}_SENDER'] is defined then it will use that for the sender address (i.e. to support rekeyed accounts)\n * * **LocalNet:** will load the account from a KMD wallet called \\{NAME\\} and if that wallet doesn't exist it will create it and fund the account for you\n *\n * This allows you to write code that will work seamlessly in production and local development (LocalNet) without manual config locally (including when you reset the LocalNet).\n *\n * @example Default\n *\n * If you have a mnemonic secret loaded into `process.env.ACCOUNT_MNEMONIC` then you can call the following to get that private key loaded into an account object:\n * ```typescript\n * const account = await getAccount({config: getAccountConfigFromEnvironment('ACCOUNT')}, algod)\n * ```\n *\n * If that code runs against LocalNet then a wallet called `ACCOUNT` will automatically be created with an account that is automatically funded with 1000 (default) ALGO from the default LocalNet dispenser.\n *\n * @param account The details of the account to get, either the name identifier (string) or an object with:\n *   * `config`: Account configuration. To get from environment use getAccountConfigFromEnvironment(accountName) OR\n *   * `name`: string: The name identifier of the account (deprecated)\n *   And optionally\n *   * `fundWith`: The amount to fund the account with when it gets created (when targeting LocalNet), if not specified then 1000 ALGO will be funded from the dispenser account\n * @param algod An algod client\n * @param kmdClient An optional KMD client to use to create an account (when targeting LocalNet), if not specified then a default KMD client will be loaded from environment variables\n * @returns The requested account with private key loaded from the environment variables or when targeting LocalNet from KMD (idempotently creating and funding the account)\n */\nexport async function getAccount(\n  account: { name: string; fundWith?: AlgoAmount } | { config: AccountConfig; fundWith?: AlgoAmount } | string,\n  algod: Algodv2,\n  kmdClient?: Kmd,\n): Promise<Account | SigningAccount> {\n  let name: string\n  let fundWith: AlgoAmount | undefined = undefined\n\n  if (typeof account === 'string') {\n    name = account\n  } else if ('name' in account) {\n    name = account.name\n    fundWith = account.fundWith\n  } else if ('config' in account) {\n    name = account.config.accountName\n    fundWith = account.fundWith\n  } else {\n    throw new Error('Missing name or account config')\n  }\n\n  return (await new AccountManager(new ClientManager({ algod, kmd: kmdClient })).fromEnvironment(name, fundWith)).account\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,eAAsB,WACpB,SACA,OACA,WACmC;CACnC,IAAI;CACJ,IAAI,WAAmC,KAAA;CAEvC,IAAI,OAAO,YAAY,UACrB,OAAO;MACF,IAAI,UAAU,SAAS;EAC5B,OAAO,QAAQ;EACf,WAAW,QAAQ;CACrB,OAAO,IAAI,YAAY,SAAS;EAC9B,OAAO,QAAQ,OAAO;EACtB,WAAW,QAAQ;CACrB,OACE,MAAM,IAAI,MAAM,gCAAgC;CAGlD,QAAQ,MAAM,IAAI,eAAe,IAAI,cAAc;EAAE;EAAO,KAAK;CAAU,CAAC,CAAC,CAAC,CAAC,gBAAgB,MAAM,QAAQ,EAAA,CAAG;AAClH"}