{"version":3,"sources":["../../src/api/ans.ts"],"sourcesContent":["// Copyright © Endless\n// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\nimport { Account } from \"../account\";\nimport { AccountAddress, AccountAddressInput } from \"../core\";\nimport {\n  RegisterNameParameters,\n  getExpiration,\n  getOwnerAddress,\n  registerName,\n  getPrimaryName,\n  setPrimaryName,\n  getTargetAddress,\n  setTargetAddress,\n  renewDomain,\n} from \"../internal/ans\";\nimport { InputGenerateTransactionOptions } from \"../transactions/types\";\nimport { EndlessConfig } from \"./endlessConfig\";\nimport { SimpleTransaction } from \"../transactions/instances/simpleTransaction\";\n\n/**\n * A class to handle all `ANS` operations\n */\nexport class ANS {\n  constructor(readonly config: EndlessConfig) { }\n\n  /**\n   * Retrieve the owner address of a domain name or subdomain name from the contract.\n   *\n   * @example\n   * // Will return the owner address of \"test.endless.apt\" or undefined\n   * const owner = await endless.getOwnerAddress({name: \"test.endless\"})\n   * // owner = 0x123...\n   *\n   * @param args.name - A string of the name to retrieve\n   *\n   * @returns AccountAddress if the name is owned, undefined otherwise\n   */\n  async getOwnerAddress(args: { name: string }): Promise<AccountAddress | undefined> {\n    return getOwnerAddress({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Retrieve the expiration time of a domain name or subdomain name from the contract.\n   *\n   * @example\n   * // Will return the expiration of \"test.endless.apt\" or undefined\n   * const exp = await endless.getExpiration({name: \"test.endless\"})\n   * // new Date(exp) would give you the date in question: 2021-01-01T00:00:00.000Z\n   *\n   * @param args.name - A string of the name to retrieve\n   *\n   * @returns number as a unix timestamp in milliseconds.\n   */\n  async getExpiration(args: { name: string }): Promise<number | undefined> {\n    return getExpiration({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Retrieve the target address of a domain or subdomain name. This is the\n   * address the name points to for use on chain. Note, the target address can\n   * point to addresses that are not the owner of the name\n   *\n   * @example\n   * const targetAddr = await endless.getTargetAddress({name: \"test.endless\"})\n   * // targetAddr = 0x123...\n   *\n   * @param args.name - A string of the name: primary, primary.apt, secondary.primary, secondary.primary.apt, etc.\n   *\n   * @returns AccountAddress if the name has a target, undefined otherwise\n   */\n  async getTargetAddress(args: { name: string }): Promise<AccountAddress | undefined> {\n    return getTargetAddress({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Sets the target address of a domain or subdomain name. This is the\n   * address the name points to for use on chain. Note, the target address can\n   * point to addresses that are not the owner of the name\n   *\n   * @example\n   * await endless.setTargetAddress({sender: alice, name: \"test.endless\", address: bob.accountAddress})\n   * const address = await endless.getTargetAddress({name: \"test.endless\"})\n   * // address = bob.accountAddress\n   *\n   * @param args.name - A string of the name: test.endless.apt, test.apt, test, test.endless, etc.\n   * @param args.address - A AccountAddressInput of the address to set the domain or subdomain to\n   *\n   * @returns SimpleTransaction\n   */\n  async setTargetAddress(args: {\n    sender: Account;\n    name: string;\n    address: AccountAddressInput;\n    options?: InputGenerateTransactionOptions;\n  }): Promise<SimpleTransaction> {\n    return setTargetAddress({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Retrieve the primary name for an account. An account can have\n   * multiple names that target it, but only a single name that is primary. An\n   * account also may not have a primary name.\n   *\n   * @example\n   * const name = await endless.getPrimaryName({address: alice.accountAddress})\n   * // name = test.endless\n   *\n   * @param args.address - A AccountAddressInput (address) of the account\n   *\n   * @returns a string if the account has a primary name, undefined otherwise\n   */\n  async getPrimaryName(args: { address: AccountAddressInput }): Promise<string | undefined> {\n    return getPrimaryName({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Sets the primary name for the sender. An account can have\n   * multiple names that target it, but only a single name that is primary. An\n   * account also may not have a primary name.\n   *\n   * @example\n   * await endless.setPrimaryName({sender: alice, name: \"test.endless\"})\n   * const primaryName = await endless.getPrimaryName({address: alice.accountAddress})\n   * // primaryName = test.endless\n   *\n   * @param args.sender - The sender account\n   * @param args.name - A string of the name: test, test.apt, test.endless, test.endless.apt, etc.\n   *\n   * @returns SimpleTransaction\n   */\n  async setPrimaryName(args: {\n    sender: Account;\n    name?: string;\n    options?: InputGenerateTransactionOptions;\n  }): Promise<SimpleTransaction> {\n    return setPrimaryName({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Registers a new name\n   *\n   * @example\n   * // An example of registering a subdomain name assuming def.apt is already registered\n   * // and belongs to the sender alice.\n   *  const txn = endless.registerName({\n   *    sender: alice,\n   *    name: \"test.endless.apt\",\n   *    expiration: {\n   *      policy: \"subdomain:independent\",\n   *      expirationDate: Date.now() + 30 * 24 * 60 * 60 * 1000,\n   *    },\n   *  });\n   *\n   * @param args.sender - The sender account\n   * @param args.name - A string of the name to register. This can be inclusive or exclusive of the .apt suffix.\n   * Examples include: \"test\", \"test.apt\", \"test.endless.apt\", etc.\n   * @param args.expiration  - An object with the expiration policy of the name.\n   * @param args.expiration.policy - 'domain' | 'subdomain:follow-domain' | 'subdomain:independent'\n   * - domain: Years is required and the name will expire after the given number of years.\n   * - subdomain:follow-domain: The name will expire at the same time as the domain name.\n   * - subdomain:independent: The name will expire at the given date.\n   * @param args.expiration.expirationDate - An epoch number in milliseconds of\n   * the date when the subdomain will expire. Only applicable when the policy is\n   * set to 'subdomain:independent'.\n   * @param args.transferable  - Determines if the subdomain being minted is soul-bound. Applicable only to subdomains.\n   * @param args.targetAddress optional - The address the domain name will resolve to. If not provided,\n   * the sender's address will be used.\n   * @param args.toAddress optional - The address to send the domain name to. If not provided,\n   * the transaction will be sent to the router.\n   *\n   * @returns SimpleTransaction\n   */\n  async registerName(args: Omit<RegisterNameParameters, \"endlessConfig\">): Promise<SimpleTransaction> {\n    return registerName({ endlessConfig: this.config, ...args });\n  }\n\n  /**\n   * Renews a domain name\n   *\n   * Note: If a domain name was minted with V1 of the contract, it will automatically be upgraded to V2 via this transaction.\n   *\n   * @example\n   * await endless.renewDomain({sender: alice, name: \"test\"})\n   * // test.apt will be renewed for one year\n   *\n   * @param args.sender - The sender account\n   * @param args.name - A string of the domain the subdomain will be under. The signer must be the domain owner.\n   * Subdomains cannot be renewed.\n   * @param args.years - The number of years to renew the name. Currently only one year is permitted.\n   *\n   * @returns SimpleTransaction\n   */\n  async renewDomain(args: {\n    sender: Account;\n    name: string;\n    years?: 1;\n    options?: InputGenerateTransactionOptions;\n  }): Promise<SimpleTransaction> {\n    return renewDomain({ endlessConfig: this.config, ...args });\n  }\n\n}\n"],"mappings":"0FAwBO,IAAMA,EAAN,KAAU,CACf,YAAqBC,EAAuB,CAAvB,YAAAA,CAAyB,CAc9C,MAAM,gBAAgBC,EAA6D,CACjF,OAAOC,EAAgB,CAAE,cAAe,KAAK,OAAQ,GAAGD,CAAK,CAAC,CAChE,CAcA,MAAM,cAAcA,EAAqD,CACvE,OAAOE,EAAc,CAAE,cAAe,KAAK,OAAQ,GAAGF,CAAK,CAAC,CAC9D,CAeA,MAAM,iBAAiBA,EAA6D,CAClF,OAAOG,EAAiB,CAAE,cAAe,KAAK,OAAQ,GAAGH,CAAK,CAAC,CACjE,CAiBA,MAAM,iBAAiBA,EAKQ,CAC7B,OAAOI,EAAiB,CAAE,cAAe,KAAK,OAAQ,GAAGJ,CAAK,CAAC,CACjE,CAeA,MAAM,eAAeA,EAAqE,CACxF,OAAOK,EAAe,CAAE,cAAe,KAAK,OAAQ,GAAGL,CAAK,CAAC,CAC/D,CAiBA,MAAM,eAAeA,EAIU,CAC7B,OAAOM,EAAe,CAAE,cAAe,KAAK,OAAQ,GAAGN,CAAK,CAAC,CAC/D,CAoCA,MAAM,aAAaA,EAAiF,CAClG,OAAOO,EAAa,CAAE,cAAe,KAAK,OAAQ,GAAGP,CAAK,CAAC,CAC7D,CAkBA,MAAM,YAAYA,EAKa,CAC7B,OAAOQ,EAAY,CAAE,cAAe,KAAK,OAAQ,GAAGR,CAAK,CAAC,CAC5D,CAEF","names":["ANS","config","args","getOwnerAddress","getExpiration","getTargetAddress","setTargetAddress","getPrimaryName","setPrimaryName","registerName","renewDomain"]}