{"version":3,"sources":["../../src/api/aptosConfig.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport aptosClient from \"@aptos-labs/aptos-client\";\nimport {\n  AptosSettings,\n  ClientConfig,\n  Client,\n  FullNodeConfig,\n  IndexerConfig,\n  FaucetConfig,\n  TransactionGenerationConfig,\n  PluginConfig,\n  TransactionSubmitter,\n} from \"../types\";\nimport {\n  NetworkToNodeAPI,\n  NetworkToFaucetAPI,\n  NetworkToIndexerAPI,\n  Network,\n  NetworkToPepperAPI,\n  NetworkToProverAPI,\n} from \"../utils/apiEndpoints\";\nimport { AptosApiType, DEFAULT_MAX_GAS_AMOUNT, DEFAULT_TXN_EXP_SEC_FROM_NOW } from \"../utils/const\";\nimport { isBun } from \"../utils/helpers\";\n\n/**\n * Represents the configuration settings for an Aptos SDK client instance.\n * This class allows customization of various endpoints and client settings.\n *\n * @example\n * ```typescript\n * import { Aptos, AptosConfig, Network } from \"@aptos-labs/ts-sdk\";\n *\n * async function runExample() {\n *     // Create a configuration for connecting to the Aptos testnet\n *     const config = new AptosConfig({ network: Network.TESTNET });\n *\n *     // Initialize the Aptos client with the configuration\n *     const aptos = new Aptos(config);\n *\n *     console.log(\"Aptos client initialized:\", aptos);\n * }\n * runExample().catch(console.error);\n * ```\n * @group Client\n */\nexport class AptosConfig {\n  /**\n   * The Network that this SDK is associated with. Defaults to DEVNET\n   * @group Client\n   */\n  readonly network: Network;\n\n  /**\n   * The client instance the SDK uses. Defaults to `@aptos-labs/aptos-client\n   * @group Client\n   */\n  readonly client: Client;\n\n  /**\n   * The optional hardcoded fullnode URL to send requests to instead of using the network\n   * @group Client\n   */\n  readonly fullnode?: string;\n\n  /**\n   * The optional hardcoded faucet URL to send requests to instead of using the network\n   * @group Client\n   */\n  readonly faucet?: string;\n\n  /**\n   * The optional hardcoded pepper service URL to send requests to instead of using the network\n   * @group Client\n   */\n  readonly pepper?: string;\n\n  /**\n   * The optional hardcoded prover service URL to send requests to instead of using the network\n   * @group Client\n   */\n  readonly prover?: string;\n\n  /**\n   * The optional hardcoded indexer URL to send requests to instead of using the network\n   * @group Client\n   */\n  readonly indexer?: string;\n\n  /**\n   * Optional client configurations\n   * @group Client\n   */\n  readonly clientConfig?: ClientConfig;\n\n  /**\n   * Optional specific Fullnode configurations\n   * @group Client\n   */\n  readonly fullnodeConfig?: FullNodeConfig;\n\n  /**\n   * Optional specific Indexer configurations\n   * @group Client\n   */\n  readonly indexerConfig?: IndexerConfig;\n\n  /**\n   * Optional specific Faucet configurations\n   * @group Client\n   */\n  readonly faucetConfig?: FaucetConfig;\n\n  /**\n   * Optional specific Transaction Generation configurations\n   * @group Client\n   */\n  readonly transactionGenerationConfig?: TransactionGenerationConfig;\n\n  /**\n   * Optional plugin config to override client behavior.\n   * @group Client\n   */\n  private pluginConfig?: PluginConfig;\n\n  /**\n   * Initializes an instance of the Aptos client with the specified settings.\n   * This allows users to configure various aspects of the client, such as network and endpoints.\n   *\n   * @param settings - Optional configuration settings for the Aptos client.\n   * @param settings.network - The network to connect to, defaults to `Network.DEVNET`.\n   * @param settings.fullnode - The fullnode endpoint to use for requests.\n   * @param settings.faucet - The faucet endpoint for obtaining test tokens.\n   * @param settings.pepper - The pepper used for transaction signing.\n   * @param settings.prover - The prover endpoint for transaction verification.\n   * @param settings.indexer - The indexer endpoint for querying blockchain data.\n   * @param settings.client - Custom client settings, defaults to a standard Aptos client.\n   * @param settings.clientConfig - Additional configuration for the client.\n   * @param settings.fullnodeConfig - Additional configuration for the fullnode.\n   * @param settings.indexerConfig - Additional configuration for the indexer.\n   * @param settings.faucetConfig - Additional configuration for the faucet.\n   *\n   * @example\n   * ```typescript\n   * import { Aptos, AptosConfig, Network } from \"@aptos-labs/ts-sdk\";\n   *\n   * async function runExample() {\n   *     // Create a new Aptos client with default settings\n   *     const config = new AptosConfig({ network: Network.TESTNET }); // Specify the network\n   *     const aptos = new Aptos(config);\n   *\n   *     console.log(\"Aptos client initialized:\", aptos);\n   * }\n   * runExample().catch(console.error);\n   * ```\n   * @group Client\n   */\n  constructor(settings?: AptosSettings) {\n    // If there are any endpoint overrides, they are custom networks, keep that in mind\n    if (settings?.fullnode || settings?.indexer || settings?.faucet || settings?.pepper || settings?.prover) {\n      if (settings?.network === Network.CUSTOM) {\n        console.info(\"Note: using CUSTOM network will require queries to lookup ChainId\");\n      } else if (!settings?.network) {\n        throw new Error(\"Custom endpoints require a network to be specified\");\n      }\n    }\n\n    // Warn Bun users about HTTP/2 compatibility issues.\n    // Bun's HTTP/2 support is not fully mature yet, so we recommend disabling it.\n    if (isBun() && settings?.clientConfig?.http2 !== false) {\n      console.warn(\n        \"[Aptos SDK] Bun does not fully support HTTP/2, which is enabled by default in this SDK. \" +\n          \"It is recommended to disable HTTP/2 by setting `clientConfig: { http2: false }` in your AptosConfig. \" +\n          \"For example: new AptosConfig({ network: Network.TESTNET, clientConfig: { http2: false } })\",\n      );\n    }\n\n    this.network = settings?.network ?? Network.DEVNET;\n    this.fullnode = settings?.fullnode;\n    this.faucet = settings?.faucet;\n    this.pepper = settings?.pepper;\n    this.prover = settings?.prover;\n    this.indexer = settings?.indexer;\n    this.client = settings?.client ?? { provider: aptosClient };\n    this.clientConfig = settings?.clientConfig ?? {};\n    this.fullnodeConfig = settings?.fullnodeConfig ?? {};\n    this.indexerConfig = settings?.indexerConfig ?? {};\n    this.faucetConfig = settings?.faucetConfig ?? {};\n    this.transactionGenerationConfig = settings?.transactionGenerationConfig ?? {};\n    this.pluginConfig = settings?.pluginSettings\n      ? {\n          ...settings.pluginSettings,\n          IGNORE_TRANSACTION_SUBMITTER: false,\n        }\n      : undefined;\n  }\n\n  /**\n   * Returns the URL endpoint to send the request to based on the specified API type.\n   * If a custom URL was provided in the configuration, that URL is returned. Otherwise, the URL endpoint is derived from the network.\n   *\n   * @param apiType - The type of Aptos API to get the URL for. This can be one of the following: FULLNODE, FAUCET, INDEXER, PEPPER, PROVER.\n   *\n   * @example\n   * ```typescript\n   * import { Aptos, AptosConfig, Network, AptosApiType } from \"@aptos-labs/ts-sdk\";\n   *\n   * const config = new AptosConfig({ network: Network.TESTNET });\n   * const aptos = new Aptos(config);\n   *\n   * async function runExample() {\n   *   // Getting the request URL for the FULLNODE API\n   *   const url = config.getRequestUrl(AptosApiType.FULLNODE);\n   *   console.log(\"Request URL for FULLNODE:\", url);\n   * }\n   * runExample().catch(console.error);\n   * ```\n   * @group Client\n   */\n  getRequestUrl(apiType: AptosApiType): string {\n    switch (apiType) {\n      case AptosApiType.FULLNODE:\n        if (this.fullnode !== undefined) return this.fullnode;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom full node url\");\n        return NetworkToNodeAPI[this.network];\n      case AptosApiType.FAUCET:\n        if (this.faucet !== undefined) return this.faucet;\n        if (this.network === Network.TESTNET) {\n          throw new Error(\n            \"There is no way to programmatically mint testnet APT, you must use the minting site at https://aptos.dev/network/faucet\",\n          );\n        }\n        if (this.network === Network.MAINNET) {\n          throw new Error(\"There is no mainnet faucet\");\n        }\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom faucet url\");\n        return NetworkToFaucetAPI[this.network];\n      case AptosApiType.INDEXER:\n        if (this.indexer !== undefined) return this.indexer;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom indexer url\");\n        return NetworkToIndexerAPI[this.network];\n      case AptosApiType.PEPPER:\n        if (this.pepper !== undefined) return this.pepper;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom pepper service url\");\n        return NetworkToPepperAPI[this.network];\n      case AptosApiType.PROVER:\n        if (this.prover !== undefined) return this.prover;\n        if (this.network === Network.CUSTOM) throw new Error(\"Please provide a custom prover service url\");\n        return NetworkToProverAPI[this.network];\n      default:\n        throw new Error(`apiType ${apiType} is not supported`);\n    }\n  }\n\n  /**\n   * Checks if the provided URL is a known pepper service endpoint.\n   *\n   * @param url - The URL to check against the known pepper service endpoints.\n   *\n   * @example\n   * ```typescript\n   * import { Aptos, AptosConfig, Network } from \"@aptos-labs/ts-sdk\";\n   *\n   * const config = new AptosConfig({ network: Network.TESTNET });\n   * const aptos = new Aptos(config);\n   *\n   * async function runExample() {\n   *     const url = \"https://example.pepper.service\"; // replace with a real pepper service URL\n   *\n   *     // Check if the URL is a known pepper service endpoint\n   *     const isPepperService = config.isPepperServiceRequest(url);\n   *\n   *     console.log(`Is the URL a known pepper service? ${isPepperService}`);\n   * }\n   * runExample().catch(console.error);\n   * ```\n   * @group Client\n   */\n  isPepperServiceRequest(url: string): boolean {\n    return NetworkToPepperAPI[this.network] === url;\n  }\n\n  /**\n   * Checks if the provided URL is a known prover service endpoint.\n   *\n   * @param url - The URL to check against known prover service endpoints.\n   * @returns A boolean indicating whether the URL is a known prover service endpoint.\n   *\n   * @example\n   * ```typescript\n   * import { Aptos, AptosConfig, Network } from \"@aptos-labs/ts-sdk\";\n   *\n   * const config = new AptosConfig({ network: Network.TESTNET });\n   * const aptos = new Aptos(config);\n   *\n   * // Check if the URL is a known prover service endpoint\n   * const url = \"https://prover.testnet.aptos.dev\"; // replace with a real URL if needed\n   * const isProver = config.isProverServiceRequest(url);\n   *\n   * console.log(`Is the URL a known prover service? ${isProver}`);\n   * ```\n   * @group Client\n   */\n  isProverServiceRequest(url: string): boolean {\n    return NetworkToProverAPI[this.network] === url;\n  }\n\n  getDefaultMaxGasAmount(): number {\n    return this.transactionGenerationConfig?.defaultMaxGasAmount ?? DEFAULT_MAX_GAS_AMOUNT;\n  }\n\n  getDefaultTxnExpirySecFromNow(): number {\n    return this.transactionGenerationConfig?.defaultTxnExpirySecFromNow ?? DEFAULT_TXN_EXP_SEC_FROM_NOW;\n  }\n\n  /**\n   * If you have set a custom transaction submitter, you can use this to determine\n   * whether to use it or not. For example, to stop using the transaction submitter:\n   *\n   * @example\n   * ```\n   * aptos.config.setIgnoreTransactionSubmitter(true);\n   * ```\n   *\n   * @group Client\n   */\n  setIgnoreTransactionSubmitter(ignore: boolean) {\n    if (this.pluginConfig) {\n      this.pluginConfig.IGNORE_TRANSACTION_SUBMITTER = ignore;\n    }\n  }\n\n  /**\n   * If a custom transaction submitter has been specified in the PluginConfig and\n   * IGNORE_TRANSACTION_SUBMITTER is false, this will return a transaction submitter\n   * that should be used instead of the default transaction submission behavior.\n   */\n  getTransactionSubmitter(): TransactionSubmitter | undefined {\n    if (this.pluginConfig === undefined) {\n      return undefined;\n    }\n\n    if (this.pluginConfig.IGNORE_TRANSACTION_SUBMITTER === true) {\n      return undefined;\n    }\n\n    return this.pluginConfig.TRANSACTION_SUBMITTER;\n  }\n}\n"],"mappings":"8JAGA,OAAOA,MAAiB,2BA4CjB,IAAMC,EAAN,KAAkB,CA+GvB,YAAYC,EAA0B,CAEpC,GAAIA,GAAU,UAAYA,GAAU,SAAWA,GAAU,QAAUA,GAAU,QAAUA,GAAU,QAC/F,GAAIA,GAAU,UAAY,SACxB,QAAQ,KAAK,mEAAmE,UACvE,CAACA,GAAU,QACpB,MAAM,IAAI,MAAM,oDAAoD,EAMpEC,EAAM,GAAKD,GAAU,cAAc,QAAU,IAC/C,QAAQ,KACN,yRAGF,EAGF,KAAK,QAAUA,GAAU,SAAW,SACpC,KAAK,SAAWA,GAAU,SAC1B,KAAK,OAASA,GAAU,OACxB,KAAK,OAASA,GAAU,OACxB,KAAK,OAASA,GAAU,OACxB,KAAK,QAAUA,GAAU,QACzB,KAAK,OAASA,GAAU,QAAU,CAAE,SAAUE,CAAY,EAC1D,KAAK,aAAeF,GAAU,cAAgB,CAAC,EAC/C,KAAK,eAAiBA,GAAU,gBAAkB,CAAC,EACnD,KAAK,cAAgBA,GAAU,eAAiB,CAAC,EACjD,KAAK,aAAeA,GAAU,cAAgB,CAAC,EAC/C,KAAK,4BAA8BA,GAAU,6BAA+B,CAAC,EAC7E,KAAK,aAAeA,GAAU,eAC1B,CACE,GAAGA,EAAS,eACZ,6BAA8B,EAChC,EACA,MACN,CAwBA,cAAcG,EAA+B,CAC3C,OAAQA,EAAS,CACf,eACE,GAAI,KAAK,WAAa,O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,OAAO,KAAK,aAAa,qBAC3B,CACF","names":["aptosClient","AptosConfig","settings","isBun","aptosClient","apiType","NetworkToNodeAPI","NetworkToFaucetAPI","NetworkToIndexerAPI","NetworkToPepperAPI","NetworkToProverAPI","url","ignore"]}