{"version":3,"file":"account.mjs","sources":["../../src/types/account.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { AlgoAmount } from './amount'\nimport ApplicationLocalState = algosdk.modelsv2.ApplicationLocalState\nimport ApplicationStateSchema = algosdk.modelsv2.ApplicationStateSchema\nimport AssetHolding = algosdk.modelsv2.AssetHolding\nimport Application = algosdk.modelsv2.Application\nimport Asset = algosdk.modelsv2.Asset\nimport AccountParticipation = algosdk.modelsv2.AccountParticipation\nimport Account = algosdk.Account\nimport MultisigMetadata = algosdk.MultisigMetadata\nimport Transaction = algosdk.Transaction\nimport TransactionSigner = algosdk.TransactionSigner\n\n/**\n * The account name identifier used for fund dispensing in test environments\n */\nexport const DISPENSER_ACCOUNT = 'DISPENSER'\n\n/** Account wrapper that supports partial or full multisig signing. */\nexport class MultisigAccount {\n  _params: algosdk.MultisigMetadata\n  _signingAccounts: (algosdk.Account | SigningAccount)[]\n  _addr: Address\n  _signer: TransactionSigner\n\n  /** The parameters for the multisig account */\n  get params(): Readonly<algosdk.MultisigMetadata> {\n    return this._params\n  }\n\n  /** The list of accounts that are present to sign */\n  get signingAccounts(): Readonly<(algosdk.Account | SigningAccount)[]> {\n    return this._signingAccounts\n  }\n\n  /** The address of the multisig account */\n  get addr(): Readonly<Address> {\n    return this._addr\n  }\n\n  /** The transaction signer for the multisig account */\n  get signer(): TransactionSigner {\n    return this._signer\n  }\n\n  constructor(multisigParams: MultisigMetadata, signingAccounts: (Account | SigningAccount)[]) {\n    this._params = multisigParams\n    this._signingAccounts = signingAccounts\n    this._addr = algosdk.multisigAddress(multisigParams)\n    this._signer = algosdk.makeMultiSigAccountTransactionSigner(\n      multisigParams,\n      signingAccounts.map((a) => a.sk),\n    )\n  }\n\n  /**\n   * Sign the given transaction\n   * @param transaction Either a transaction object or a raw, partially signed transaction\n   * @returns The transaction signed by the present signers\n   * @example\n   * ```typescript\n   * const signedTxn = multisigAccount.sign(myTransaction)\n   * ```\n   */\n  public sign(transaction: Transaction | Uint8Array): Uint8Array {\n    let signedTxn = 'sender' in transaction ? undefined : transaction\n    for (const signer of this._signingAccounts) {\n      if (signedTxn) {\n        signedTxn = algosdk.appendSignMultisigTransaction(signedTxn, this._params, signer.sk).blob\n      } else {\n        signedTxn = algosdk.signMultisigTransaction(transaction as Transaction, this._params, signer.sk).blob\n      }\n    }\n    return signedTxn!\n  }\n}\n\n/** Account wrapper that supports a rekeyed account */\nexport class SigningAccount implements Account {\n  private _account: Account\n  private _signer: TransactionSigner\n  private _sender: Address\n\n  /**\n   * Algorand address of the sender\n   */\n  get addr(): Readonly<Address> {\n    return this._sender\n  }\n\n  /**\n   * Secret key belonging to the signer\n   */\n  get sk(): Readonly<Uint8Array> {\n    return this._account.sk\n  }\n\n  /**\n   * Transaction signer for the underlying signing account\n   */\n  get signer(): TransactionSigner {\n    return this._signer\n  }\n\n  /**\n   * Algorand account of the sender address and signer private key\n   */\n  get sender(): Account {\n    return {\n      addr: this._sender,\n      sk: this._account.sk,\n    }\n  }\n\n  constructor(account: Account, sender: string | Address | undefined) {\n    this._account = account\n    this._sender = typeof sender === 'string' ? Address.fromString(sender) : (sender ?? account.addr)\n    this._signer = algosdk.makeBasicAccountTransactionSigner(account)\n  }\n}\n\n/** A wrapper around `TransactionSigner` that also has the sender address. */\nexport interface TransactionSignerAccount {\n  addr: Readonly<Address>\n  signer: TransactionSigner\n}\n\n/** Account information at a given round. */\nexport type AccountInformation = {\n  /**\n   * The account public key\n   */\n  address: Address\n\n  /** The balance of Algo currently held by the account. */\n  balance: AlgoAmount\n\n  /**\n   * The amount of Algo in the account, without the pending rewards.\n   */\n  amountWithoutPendingRewards: AlgoAmount\n\n  /**\n   * Algo balance required to be held by the account.\n   *\n   * The requirement grows based on asset and application usage.\n   */\n  minBalance: AlgoAmount\n  /**\n   * Amount of Algo of pending rewards in this account.\n   */\n  pendingRewards: AlgoAmount\n\n  /**\n   * Total rewards of Algo the account has received, including pending\n   * rewards.\n   */\n  rewards: AlgoAmount\n\n  /**\n   * The round number for which this information is relevant.\n   */\n  validAsOfRound: bigint\n\n  /**\n   * Delegation status of the account's Algo:\n   * * Offline - indicates that the associated account is delegated.\n   * * Online - indicates that the associated account used as part of the delegation pool.\n   * * NotParticipating - indicates that the associated account is neither a delegator nor a delegate.\n   */\n  status: string\n\n  /**\n   * The count of all applications that have been opted in, equivalent to the count\n   * of application local data (AppLocalState objects) stored in this account.\n   */\n  totalAppsOptedIn: number\n\n  /**\n   * The count of all assets that have been opted in, equivalent to the count of\n   * AssetHolding objects held by this account.\n   */\n  totalAssetsOptedIn: number\n\n  /**\n   * The count of all apps (AppParams objects) created by this account.\n   */\n  totalCreatedApps: number\n\n  /**\n   * The count of all assets (AssetParams objects) created by this account.\n   */\n  totalCreatedAssets: number\n\n  /**\n   * Applications local data stored in this account.\n   */\n  appsLocalState?: ApplicationLocalState[]\n\n  /**\n   * The sum of all extra application program pages for this account.\n   */\n  appsTotalExtraPages?: number\n  /**\n   * (tsch) stores the sum of all of the local schemas and global schemas in this\n   * account.\n   * Note: the raw account uses `StateSchema` for this type.\n   */\n  appsTotalSchema?: ApplicationStateSchema\n\n  /**\n   * Assets held by this account.\n   */\n  assets?: AssetHolding[]\n\n  /**\n   * The address against which signing should be checked. If empty, the\n   * address of the current account is used. This field can be updated in any\n   * transaction by setting the `RekeyTo` field.\n   */\n  authAddr?: Address\n\n  /**\n   * Parameters of applications created by this account including app global data.\n   */\n  createdApps?: Application[]\n\n  /**\n   * (apar) parameters of assets created by this account.\n   * Note: the raw account uses `map[int] -> Asset` for this type.\n   */\n  createdAssets?: Asset[]\n\n  /**\n   * AccountParticipation describes the parameters used by this account in consensus\n   * protocol.\n   */\n  participation?: AccountParticipation\n\n  /**\n   * Used as part of the rewards computation. Only applicable to accounts\n   * which are participating.\n   */\n  rewardBase?: number\n\n  /**\n   * Indicates what type of signature is used by this account, must be one of:\n   * * sig\n   * * msig\n   * * lsig\n   */\n  sigType?: string\n\n  /**\n   * The total number of bytes used by this account's app's box keys and\n   * values.\n   */\n  totalBoxBytes?: number\n\n  /**\n   * The number of existing boxes created by this account's app.\n   */\n  totalBoxes?: number\n\n  /**\n   * The round in which this account last went online, or explicitly renewed their\n   * online status.\n   */\n  lastHeartbeatRound?: bigint\n\n  /**\n   * The round in which this account last proposed the block.\n   */\n  lastProposedRound?: bigint\n}\n\n/** Account asset holding information at a given round. */\nexport type AccountAssetInformation = {\n  /** The ID of the asset held. */\n  assetId: bigint\n  /** The current balance of that asset holding. */\n  balance: bigint\n  /** Whether or not the asset is frozen for the account. */\n  frozen: boolean\n  /** The round as at which the holding was correct. */\n  round: bigint\n}\n\n/**\n * @deprecated The methods that use this can be achieved using `AccountManager` instead.\n * Config for an account config */\nexport interface AccountConfig {\n  /** Mnemonic for an account */\n  accountMnemonic: string\n  /** Address of a rekeyed account */\n  senderAddress?: string\n  /** Account name used to retrieve config */\n  accountName: string\n\n  /** @deprecated Renamed to senderAddress in 2.3.1 */\n  senderMnemonic?: string\n}\n"],"names":[],"mappings":";;AAaA;;AAEG;AACI,MAAM,iBAAiB,GAAG;AAEjC;MACa,eAAe,CAAA;;AAO1B,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;;;AAIrB,IAAA,IAAI,eAAe,GAAA;QACjB,OAAO,IAAI,CAAC,gBAAgB;;;AAI9B,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,IAAI,CAAC,KAAK;;;AAInB,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;;IAGrB,WAAY,CAAA,cAAgC,EAAE,eAA6C,EAAA;AACzF,QAAA,IAAI,CAAC,OAAO,GAAG,cAAc;AAC7B,QAAA,IAAI,CAAC,gBAAgB,GAAG,eAAe;QACvC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,eAAe,CAAC,cAAc,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,oCAAoC,CACzD,cAAc,EACd,eAAe,CAAC,GAAG,CAAC,CAA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