{"version":3,"sources":["../../src/api/account.ts"],"sourcesContent":["// Copyright © Endless\n// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Account as AccountModule } from \"../account\";\nimport { AccountAddress, AccountAddressInput, PrivateKey } from \"../core\";\nimport {\n  AccountBalancesResponse,\n  AccountData,\n  GetAccountsCoinBalanceResponse,\n  GetAccountCoinsDataResponse,\n  GetCreatedCoinDataResponse,\n  LedgerVersionArg,\n  MoveModuleBytecode,\n  MoveResource,\n  MoveStructId,\n  PaginationArgs,\n  PaginationArgsOfIndexer,\n  PageableCollectionResponse,\n  PageableNftOwnedCollectionResponse,\n  PageableNftTokenResponse,\n  TransactionResponse,\n} from \"../types\";\nimport {\n  deriveAccountFromPrivateKey,\n  getAccountCoinAmount,\n  getAccountsCoinBalance,\n  getAccountsCoinsBalances,\n  getAccountCoinsData,\n  getInfo,\n  getModule,\n  getModules,\n  getResource,\n  getResources,\n  getTransactions,\n  lookupOriginalAccountAddress,\n  getCoinsDataCreatedBy,\n  getAccountCollections,\n  getAccountNfts,\n  getAccountNftCollections,\n} from \"../internal/account\";\nimport {\n  // ENDLESS_COIN,\n  ENDLESS_COIN_ID,\n} from \"../utils/const\";\nimport { EndlessConfig } from \"./endlessConfig\";\n\n/**\n * A class to query all `Account` related queries on Endless.\n */\nexport class Account {\n  constructor(readonly config: EndlessConfig) {}\n\n  /**\n   * Queries the current state for an Endless account given its account address\n   *\n   * @param args.accountAddress Endless account address\n   *\n   * @returns The account data\n   *\n   * @example An example of the returned account\n   * ```\n   * {\n   *    sequence_number: \"1\",\n   *    authentication_key: \"0x5307b5f4bc67829097a8ba9b43dba3b88261eeccd1f709d9bde240fc100fbb69\"\n   * }\n   * ```\n   */\n  async getAccountInfo(args: { accountAddress: AccountAddressInput }): Promise<AccountData> {\n    return getInfo({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries for all modules in an account given an account address\n   *\n   * Note: In order to get all account modules, this function may call the API\n   * multiple times as it auto paginates.\n   *\n   * @param args.accountAddress Endless account address\n   * @param args.options.offset The number module to start returning results from\n   * @param args.options.limit The number of results to return\n   * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n   *\n   * @returns Account modules\n   */\n  async getAccountModules(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgs & LedgerVersionArg;\n  }): Promise<MoveModuleBytecode[]> {\n    return getModules({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries for a specific account module given account address and module name\n   *\n   * @param args.accountAddress Endless account address\n   * @param args.moduleName The name of the module\n   * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n   *\n   * @returns Account module\n   *\n   * @example\n   * const module = await endless.getAccountModule({accountAddress:\"0x456\"})\n   * // An example of an account module response\n   * ```\n   * {\n   *    bytecode: \"0xa11ceb0b0600000006010002030206050807070f0d081c200\",\n   *    abi: { address: \"0x1\" }\n   * }\n   * ```\n   */\n  async getAccountModule(args: {\n    accountAddress: AccountAddressInput;\n    moduleName: string;\n    options?: LedgerVersionArg;\n  }): Promise<MoveModuleBytecode> {\n    return getModule({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries account transactions given an account address\n   *\n   * Note: In order to get all account transactions, this function may call the API\n   * multiple times as it auto paginates.\n   *\n   * @example\n   * const transactions = await endless.getAccountTransactions({accountAddress:\"0x456\"})\n   *\n   * @param args.accountAddress Endless account address\n   * @param args.options.offset The number transaction to start returning results from\n   * @param args.options.limit The number of results to return\n   *\n   * @returns The account transactions\n   */\n  async getAccountTransactions(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgs;\n  }): Promise<TransactionResponse[]> {\n    return getTransactions({\n      endlessConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Queries all account resources given an account address\n   *\n   * Note: In order to get all account resources, this function may call the API\n   * multiple times as it auto paginates.\n   *\n   * @example\n   * const resources = await endless.getAccountResources({accountAddress:\"0x456\"})\n   *\n   * @param args.accountAddress Endless account address\n   * @param args.options.offset The number resource to start returning results from\n   * @param args.options.limit The number of results to return\n   * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n   * @returns Account resources\n   */\n  async getAccountResources(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgs & LedgerVersionArg;\n  }): Promise<MoveResource[]> {\n    return getResources({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries a specific account resource given account address and resource type. Note that the default is `any` in order\n   * to allow for ease of accessing properties of the object.\n   *\n   * @type The typed output of the resource\n   * @param args.accountAddress Endless account address\n   * @param args.resourceType String representation of an on-chain Move struct type, i.e \"0x1::endless_coin::EndlessCoin\"\n   * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n   *\n   * @returns Account resource\n   *\n   * @example\n   * const resource = await endless.getAccountResource({accountAddress:\"0x456\"})\n   *\n   */\n  async getAccountResource<T extends {} = any>(args: {\n    accountAddress: AccountAddressInput;\n    resourceType: MoveStructId;\n    options?: LedgerVersionArg;\n  }): Promise<T> {\n    return getResource<T>({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Looks up the account address for a given authentication key\n   *\n   * This handles both if the account's authentication key has been rotated or not.\n   *\n   * @example\n   * const accountAddress = await endless.lookupOriginalAccountAddress({authenticationKey:account.accountAddress})\n   *\n   * @param args.authenticationKey The authentication key\n   * @param args.options.ledgerVersion The ledger version to query, if not provided it will get the latest version\n   * @returns Promise<AccountAddress> The accountAddress associated with the authentication key\n   */\n  async lookupOriginalAccountAddress(args: {\n    authenticationKey: AccountAddressInput;\n    options?: LedgerVersionArg;\n  }): Promise<AccountAddress> {\n    return lookupOriginalAccountAddress({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries an account's coins data\n   *\n   * @example\n   * const accountCoinsData = await endless.getAccountCoinsData({accountAddress:\"0x123\"})\n   *\n   * @param args.accountAddress The account address we want to get the coins data for\n   * @param args.options.page optional. The page number\n   * @param args.options.pageSize optional. The number of results to return\n   * @param args.options.coin optional. Filter by coin id\n   * @returns Array with the coins data\n   */\n  async getAccountCoinsData(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgsOfIndexer & { coin?: string };\n  }): Promise<GetAccountCoinsDataResponse> {\n    return getAccountCoinsData({\n      endlessConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Queries coins data created by account\n   *\n   * @example\n   * const accountCoinsData = await endless.getCoinsDataCreatedBy({accountAddress:\"0x123\"})\n   *\n   * @param args.accountAddress The account address of who create the coins\n   * @param args.options.page optional. The page number\n   * @param args.options.pageSize optional. The number of results to return\n   * @param args.options.coin optional. Filter by coin id\n   * @returns Array with the coins data\n   */\n  async getCoinsDataCreatedBy(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgsOfIndexer & { coin?: string };\n  }): Promise<GetCreatedCoinDataResponse> {\n    return getCoinsDataCreatedBy({\n      endlessConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Queries the account's EDS amount\n   *\n   * @example\n   * const accountAPTAmount = await endless.getAccountAPTAmount({accountAddress:\"0x123\"})\n   *\n   * @param args.accountAddress The account address we want to get the total count for\n   * @returns Current amount of account's APT\n   */\n  // async getAccountAPTAmount(args: {\n  //   accountAddress: AccountAddressInput;\n  // }): Promise<number> {\n  //   return this.getAccountCoinAmount({ coinType: ENDLESS_COIN, ...args });\n  // }\n  async getAccountEDSAmount(args: {\n    accountAddress: AccountAddressInput;\n  }): Promise<number> {\n    return this.getAccountCoinAmount({ coinId: ENDLESS_COIN_ID, ...args });\n  }\n\n  /**\n   * Queries the account's coin amount by the coin type\n   *\n   * @example\n   * const accountCoinAmount = await endless.getAccountCoinAmount({accountAddress:\"0x123\", coinType:\"0x1::endless_coin::EndlessCoin\"})\n   *\n   * @param args.accountAddress The account address we want to get the total count for\n   * @param args.coinType The coin type to query\n   * @returns Current amount of account's coin\n   */\n  async getAccountCoinAmount(args: {\n    accountAddress: AccountAddressInput;\n    coinId: string;\n  }): Promise<number> {\n    return getAccountCoinAmount({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Derives an account by providing a private key.\n   * This functions resolves the provided private key type and derives the public key from it.\n   *\n   * If the privateKey is a Secp256k1 type, it derives the account using the derived public key and\n   * auth key using the SingleKey scheme locally.\n   *\n   * If the privateKey is a ED25519 type, it looks up the authentication key on chain, and uses it to resolve\n   * whether it is a Legacy ED25519 key or a Unified ED25519 key. It then derives the account based\n   * on that.\n   *\n   * @example\n   * const account = await endless.deriveAccountFromPrivateKey({privateKey:new Ed25519PrivateKey(\"0x123\")})\n   *\n   * @param args.privateKey An account private key\n   * @returns Account type\n   */\n  async deriveAccountFromPrivateKey(args: { privateKey: PrivateKey }): Promise<AccountModule> {\n    return deriveAccountFromPrivateKey({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries an account's coins data\n   *\n   * @example\n   * const accountCoinsData = await endless.getAccountCoinsData({accountAddress:[\"0x123\"]})\n   *\n   * @param args.accountAddress The account address we want to get the coins data for\n   * @param args.coinAddress The coinAddress address we want to get the coins data for\n   * @returns Array with the coins data\n   */\n  async getAccountsCoinBalance(args: {\n    accountAddress: AccountAddressInput[];\n    coinAddress: AccountAddressInput;\n  }): Promise<GetAccountsCoinBalanceResponse> {\n    return getAccountsCoinBalance({\n      endlessConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Queries the balances of specified coins for multiple accounts.\n   *\n   * @example\n   * const balances = await endless.getAccountsCoinsBalances({\n   *   accounts: [\"0x123\", \"0x456\"],\n   *   coins: [\"0x1::aptos_coin::AptosCoin\"]\n   * });\n   *\n   * @param args.accounts The account addresses to query balances for.\n   * @param args.coins The coin types (e.g., \"0x1::aptos_coin::AptosCoin\") to query balances for.\n   * @returns An array of account balances corresponding to the requested accounts.\n   */\n  async getAccountsCoinsBalances(args: {\n    accounts: AccountAddressInput[];\n    coins: string[];\n  }): Promise<AccountBalancesResponse[]> {\n    return getAccountsCoinsBalances({\n      endlessConfig: this.config,\n      ...args,\n    });\n  }\n\n  /**\n   * Queries for collections created by an account\n   *\n   * @param args.accountAddress The account address\n   * @param args.options.page optional. The page number\n   * @param args.options.pageSize optional. The number of results per page\n   * @param args.options.collection optional. Filter by collection name or ID\n   * @returns PageableCollectionResponse\n   */\n  async getAccountCollections(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgsOfIndexer & { collection?: string };\n  }): Promise<PageableCollectionResponse> {\n    return getAccountCollections({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries for NFTs owned by an account\n   *\n   * @param args.accountAddress The account address\n   * @param args.options.page optional. The page number\n   * @param args.options.pageSize optional. The number of results per page\n   * @param args.options.token optional. Filter by token name or ID\n   * @param args.options.collection optional. Filter by collection name or ID\n   * @returns PageableNftTokenResponse\n   */\n  async getAccountNfts(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgsOfIndexer & { token?: string; collection?: string };\n  }): Promise<PageableNftTokenResponse> {\n    return getAccountNfts({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Queries for NFT collections where the account owns tokens\n   *\n   * @param args.accountAddress The account address\n   * @param args.options.page optional. The page number\n   * @param args.options.pageSize optional. The number of results per page\n   * @param args.options.collection optional. Filter by collection name or ID\n   * @returns PageableNftOwnedCollectionResponse\n   */\n  async getAccountNftCollections(args: {\n    accountAddress: AccountAddressInput;\n    options?: PaginationArgsOfIndexer & { collection?: string };\n  }): Promise<PageableNftOwnedCollectionResponse> {\n    return getAccountNftCollections({ endlessConfig: this.config, ...args });\n  }\n}"],"mappings":"2LAkDO,IAAMA,EAAN,KAAc,CACnB,YAAqBC,EAAuB,CAAvB,YAAAA,CAAwB,CAiB7C,MAAM,eAAeC,EAAqE,CACxF,OAAOC,EAAQ,CAAE,cAAe,KAAK,OAAQ,GAAGD,CAAK,CAAC,CACxD,CAeA,MAAM,kBAAkBA,EAGU,CAChC,OAAOE,EAAW,CAAE,cAAe,KAAK,OAAQ,GAAGF,CAAK,CAAC,CAC3D,CAqBA,MAAM,iBAAiBA,EAIS,CAC9B,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AGf,CAAK,CAAC,CACtE,CAYA,MAAM,eAAeA,EAGiB,CACpC,OAAOgB,EAAe,CAAE,cAAe,KAAK,OAAQ,GAAGhB,CAAK,CAAC,CAC/D,CAWA,MAAM,yBAAyBA,EAGiB,CAC9C,OAAOiB,EAAyB,CAAE,cAAe,KAAK,OAAQ,GAAGjB,CAAK,CAAC,CACzE,CACF","names":["Account","config","args","getInfo","getModules","getModule","getTransactions","getResources","getResource","lookupOriginalAccountAddress","getAccountCoinsData","getCoinsDataCreatedBy","ENDLESS_COIN_ID","getAccountCoinAmount","deriveAccountFromPrivateKey","getAccountsCoinBalance","getAccountsCoinsBalances","getAccountCollections","getAccountNfts","getAccountNftCollections"]}