PHP WebShell

Текущая директория: /opt/BitGoJS/node_modules/@aptos-labs/ts-sdk/dist/esm

Просмотр файла: chunk-CX6KECGV.mjs.map

{"version":3,"sources":["../../src/internal/ans.ts"],"sourcesContent":["// Copyright © Aptos Foundation\n// SPDX-License-Identifier: Apache-2.0\n\n/**\n * This file contains the underlying implementations for exposed API surface in\n * the {@link api/name}. By moving the methods out into a separate file,\n * other namespaces and processes can access these methods without depending on the entire\n * name namespace and without having a dependency cycle error.\n */\n\nimport { AptosConfig } from \"../api/aptosConfig\";\nimport { Account } from \"../account\";\nimport { AccountAddress, AccountAddressInput } from \"../core\";\nimport { InputGenerateTransactionOptions } from \"../transactions/types\";\nimport { GetANSNameResponse, MoveAddressType, OrderByArg, PaginationArgs, WhereArg } from \"../types\";\nimport { GetNamesQuery } from \"../types/generated/operations\";\nimport { GetNames } from \"../types/generated/queries\";\nimport { CurrentAptosNamesBoolExp } from \"../types/generated/types\";\nimport { Network } from \"../utils/apiEndpoints\";\nimport { queryIndexer } from \"./general\";\nimport { view } from \"./view\";\nimport { generateTransaction } from \"./transactionSubmission\";\nimport { SimpleTransaction } from \"../transactions/instances/simpleTransaction\";\n\nexport const VALIDATION_RULES_DESCRIPTION = [\n  \"A name must be between 3 and 63 characters long,\",\n  \"and can only contain lowercase a-z, 0-9, and hyphens.\",\n  \"A name may not start or end with a hyphen.\",\n].join(\" \");\n\n/**\n * Validate if a given fragment is a valid ANS segment.\n * This function checks the length and character constraints of the fragment to ensure it meets the ANS standards.\n *\n * @param fragment - A fragment of a name, either the domain or subdomain.\n * @returns A boolean indicating if the fragment is a valid fragment.\n */\nexport function isValidANSSegment(fragment: string): boolean {\n  if (!fragment) return false;\n  if (fragment.length < 3) return false;\n  if (fragment.length > 63) return false;\n  // only lowercase a-z and 0-9 are allowed, along with -. a domain may not start or end with a hyphen\n  if (!/^[a-z\\d][a-z\\d-]{1,61}[a-z\\d]$/.test(fragment)) return false;\n  return true;\n}\n\n/**\n * Checks if an ANS name is valid or not.\n *\n * @param name - A string of the domain name, which can include or exclude the .apt suffix.\n */\nexport function isValidANSName(name: string): { domainName: string; subdomainName?: string } {\n  const [first, second, ...rest] = name.replace(/\\.apt$/, \"\").split(\".\");\n\n  if (rest.length > 0) {\n    throw new Error(`${name} is invalid. A name can only have two parts, a domain and a subdomain separated by a \".\"`);\n  }\n\n  if (!isValidANSSegment(first)) {\n    throw new Error(`${first} is not valid. ${VALIDATION_RULES_DESCRIPTION}`);\n  }\n\n  if (second && !isValidANSSegment(second)) {\n    throw new Error(`${second} is not valid. ${VALIDATION_RULES_DESCRIPTION}`);\n  }\n\n  return {\n    domainName: second || first,\n    subdomainName: second ? first : undefined,\n  };\n}\n\n/**\n * Policy for determining how subdomains expire in relation to their parent domain.\n */\nexport enum SubdomainExpirationPolicy {\n  Independent = 0,\n  FollowsDomain = 1,\n}\n\n/**\n * Determine if a given ANS name is considered active based on its expiration dates.\n * Domains are active if their expiration date is in the future, while subdomains may\n * follow their parent's expiration policy (1) or expire independently (0).\n * If the subdomain is expiring independently, it can expire before their parent, but not after.\n *\n * @param name - An ANS name returned from one of the functions of the SDK.\n * @returns A boolean indicating whether the contract considers the name active or not.\n */\nexport function isActiveANSName(name: GetANSNameResponse[0]): boolean {\n  if (!name) return false;\n\n  const isTLDExpired = new Date(name.domain_expiration_timestamp).getTime() < Date.now();\n  const isExpired = new Date(name.expiration_timestamp).getTime() < Date.now();\n\n  // If we are a subdomain, if our parent is expired we are always expired\n  if (name.subdomain && isTLDExpired) return false;\n\n  // If we are a subdomain and our expiration policy is to follow the domain, we\n  // are active (since we know our parent is not expired by this point)\n  if (name.subdomain && name.subdomain_expiration_policy === SubdomainExpirationPolicy.FollowsDomain) return true;\n\n  // At this point, we are either a TLD or a subdomain with an independent\n  // expiration policy, we are active as long as we the expiration timestamp\n  return !isExpired;\n}\n\nexport const LOCAL_ANS_ACCOUNT_PK =\n  process.env.ANS_TEST_ACCOUNT_PRIVATE_KEY ??\n  \"ed25519-priv-0x37368b46ce665362562c6d1d4ec01a08c8644c488690df5a17e13ba163e20221\";\nexport const LOCAL_ANS_ACCOUNT_ADDRESS =\n  process.env.ANS_TEST_ACCOUNT_ADDRESS ?? \"0x585fc9f0f0c54183b039ffc770ca282ebd87307916c215a3e692f2f8e4305e82\";\n\nconst NetworkToAnsContract: Record<Network, string | null> = {\n  [Network.TESTNET]: \"0x5f8fd2347449685cf41d4db97926ec3a096eaf381332be4f1318ad4d16a8497c\",\n  [Network.MAINNET]: \"0x867ed1f6bf916171b1de3ee92849b8978b7d1b9e0a8cc982a3d19d535dfd9c0c\",\n  [Network.LOCAL]: LOCAL_ANS_ACCOUNT_ADDRESS,\n  [Network.CUSTOM]: null,\n  [Network.DEVNET]: null,\n};\n\n/**\n * Retrieves the address of the ANS contract based on the specified Aptos network configuration.\n *\n * @param aptosConfig - The configuration object for the Aptos network.\n * @param aptosConfig.network - The network for which to retrieve the ANS contract address.\n *\n * @throws Throws an error if the ANS contract is not deployed to the specified network.\n */\nfunction getRouterAddress(aptosConfig: AptosConfig): string {\n  const address = NetworkToAnsContract[aptosConfig.network];\n  if (!address) throw new Error(`The ANS contract is not deployed to ${aptosConfig.network}`);\n  return address;\n}\n\nconst unwrapOption = <T>(option: any): T | undefined => {\n  if (!!option && typeof option === \"object\" && \"vec\" in option && Array.isArray(option.vec)) {\n    return option.vec[0];\n  }\n\n  return undefined;\n};\n\n/**\n * Retrieve the owner address of a specified domain or subdomain.\n *\n * @param args - The arguments for retrieving the owner address.\n * @param args.aptosConfig - The Aptos configuration object.\n * @param args.name - The name of the domain or subdomain to query.\n * @returns The account address of the owner, or undefined if not found.\n */\nexport async function getOwnerAddress(args: {\n  aptosConfig: AptosConfig;\n  name: string;\n}): Promise<AccountAddress | undefined> {\n  const { aptosConfig, name } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  const res = await view({\n    aptosConfig,\n    payload: {\n      function: `${routerAddress}::router::get_owner_addr`,\n      functionArguments: [domainName, subdomainName],\n    },\n  });\n\n  const owner = unwrapOption<MoveAddressType>(res[0]);\n\n  return owner ? AccountAddress.from(owner) : undefined;\n}\n\n/**\n * Parameters for registering a name in the Aptos network.\n *\n * @param aptosConfig - Configuration settings for the Aptos network.\n * @param sender - The account initiating the name registration.\n * @param name - The name to be registered.\n * @param expiration - The expiration policy for the name registration.\n */\nexport interface RegisterNameParameters {\n  aptosConfig: AptosConfig;\n  sender: Account;\n  name: string;\n  expiration:\n    | { policy: \"domain\"; years?: 1 }\n    | { policy: \"subdomain:follow-domain\" }\n    | { policy: \"subdomain:independent\"; expirationDate: number };\n  transferable?: boolean;\n  toAddress?: AccountAddressInput;\n  targetAddress?: AccountAddressInput;\n  options?: InputGenerateTransactionOptions;\n}\n\n/**\n * Registers a domain or subdomain with the specified parameters. This function ensures that the provided names and expiration\n * policies are valid before proceeding with the registration process.\n *\n * @param args - The parameters required for registering a name.\n * @param args.aptosConfig - The configuration settings for Aptos.\n * @param args.expiration - The expiration details for the registration.\n * @param args.name - The name to be registered, which can be a domain or subdomain.\n * @param args.sender - The account details of the sender initiating the registration.\n * @param args.targetAddress - The target address for the registration.\n * @param args.toAddress - The address to which the registration is associated.\n * @param args.options - Additional options for the registration process.\n * @param args.transferable - Indicates whether the registered name is transferable.\n *\n * @throws Error if the provided expiration policy is invalid for subdomains.\n * @throws Error if the domain does not exist.\n * @throws Error if the subdomain expiration time exceeds the domain expiration time.\n *\n * @returns A transaction object representing the registration process.\n */\nexport async function registerName(args: RegisterNameParameters): Promise<SimpleTransaction> {\n  const { aptosConfig, expiration, name, sender, targetAddress, toAddress, options, transferable } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  const hasSubdomainPolicy =\n    expiration.policy === \"subdomain:independent\" || expiration.policy === \"subdomain:follow-domain\";\n\n  if (subdomainName && !hasSubdomainPolicy) {\n    throw new Error(\n      \"Subdomains must have an expiration policy of either 'subdomain:independent' or 'subdomain:follow-domain'\",\n    );\n  }\n\n  if (hasSubdomainPolicy && !subdomainName) {\n    throw new Error(`Policy is set to ${expiration.policy} but no subdomain was provided`);\n  }\n\n  if (expiration.policy === \"domain\") {\n    const years = expiration.years ?? 1;\n    if (years !== 1) {\n      throw new Error(\"For now, names can only be registered for 1 year at a time\");\n    }\n\n    const secondsInYear = 31536000;\n    const registrationDuration = years * secondsInYear;\n\n    const transaction = await generateTransaction({\n      aptosConfig,\n      sender: sender.accountAddress.toString(),\n      data: {\n        function: `${routerAddress}::router::register_domain`,\n        functionArguments: [domainName, registrationDuration, targetAddress, toAddress],\n      },\n      options,\n    });\n\n    return transaction;\n  }\n\n  // We are a subdomain\n  if (!subdomainName) {\n    throw new Error(`${expiration.policy} requires a subdomain to be provided.`);\n  }\n\n  const tldExpiration = await getExpiration({ aptosConfig, name: domainName });\n  if (!tldExpiration) {\n    throw new Error(\"The domain does not exist\");\n  }\n\n  const expirationDateInMillisecondsSinceEpoch =\n    expiration.policy === \"subdomain:independent\" ? expiration.expirationDate : tldExpiration;\n\n  if (expirationDateInMillisecondsSinceEpoch > tldExpiration) {\n    throw new Error(\"The subdomain expiration time cannot be greater than the domain expiration time\");\n  }\n\n  const transaction = await generateTransaction({\n    aptosConfig,\n    sender: sender.accountAddress.toString(),\n    data: {\n      function: `${routerAddress}::router::register_subdomain`,\n      functionArguments: [\n        domainName,\n        subdomainName,\n        Math.round(expirationDateInMillisecondsSinceEpoch / 1000),\n        expiration.policy === \"subdomain:follow-domain\" ? 1 : 0,\n        !!transferable,\n        targetAddress,\n        toAddress,\n      ],\n    },\n    options,\n  });\n\n  return transaction;\n}\n\n/**\n * Retrieves the expiration time of a specified domain or subdomain in epoch milliseconds.\n *\n * @param args - The arguments for the function.\n * @param args.aptosConfig - The configuration object for Aptos.\n * @param args.name - The name of the domain or subdomain to check.\n * @returns The expiration time in epoch milliseconds, or undefined if an error occurs.\n */\nexport async function getExpiration(args: { aptosConfig: AptosConfig; name: string }): Promise<number | undefined> {\n  const { aptosConfig, name } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  try {\n    const res = await view({\n      aptosConfig,\n      payload: {\n        function: `${routerAddress}::router::get_expiration`,\n        functionArguments: [domainName, subdomainName],\n      },\n    });\n\n    // Normalize expiration time from epoch seconds to epoch milliseconds\n    return Number(res[0]) * 1000;\n  } catch (e) {\n    return undefined;\n  }\n}\n\n/**\n * Retrieves the primary name associated with a given account address.\n * This function helps in obtaining the complete domain name by combining the subdomain and domain names.\n *\n * @param args - The arguments for retrieving the primary name.\n * @param args.aptosConfig - The Aptos configuration object.\n * @param args.address - The account address for which to retrieve the primary name.\n * @returns The primary name as a string, or undefined if no domain name exists.\n */\nexport async function getPrimaryName(args: {\n  aptosConfig: AptosConfig;\n  address: AccountAddressInput;\n}): Promise<string | undefined> {\n  const { aptosConfig, address } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n\n  const res = await view({\n    aptosConfig,\n    payload: {\n      function: `${routerAddress}::router::get_primary_name`,\n      functionArguments: [AccountAddress.from(address).toString()],\n    },\n  });\n\n  const domainName = unwrapOption<MoveAddressType>(res[1]);\n  const subdomainName = unwrapOption<MoveAddressType>(res[0]);\n\n  if (!domainName) return undefined;\n\n  return [subdomainName, domainName].filter(Boolean).join(\".\");\n}\n\n/**\n * Sets the primary name for the specified account, allowing for the association of a domain or subdomain with the account.\n * If no name is provided, it clears the existing primary name.\n *\n * @param args - The arguments for setting the primary name.\n * @param args.aptosConfig - The Aptos configuration object.\n * @param args.sender - The account that is sending the transaction.\n * @param args.name - The name to set as the primary name. If omitted, the function will clear the primary name.\n * @param args.options - Optional transaction generation options.\n * @returns A transaction object representing the operation.\n */\nexport async function setPrimaryName(args: {\n  aptosConfig: AptosConfig;\n  sender: Account;\n  name?: string;\n  options?: InputGenerateTransactionOptions;\n}): Promise<SimpleTransaction> {\n  const { aptosConfig, sender, name, options } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n\n  if (!name) {\n    const transaction = await generateTransaction({\n      aptosConfig,\n      sender: sender.accountAddress.toString(),\n      data: {\n        function: `${routerAddress}::router::clear_primary_name`,\n        functionArguments: [],\n      },\n      options,\n    });\n\n    return transaction;\n  }\n\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  const transaction = await generateTransaction({\n    aptosConfig,\n    sender: sender.accountAddress.toString(),\n    data: {\n      function: `${routerAddress}::router::set_primary_name`,\n      functionArguments: [domainName, subdomainName],\n    },\n    options,\n  });\n\n  return transaction;\n}\n\n/**\n * Retrieves the target address associated with a given domain name and subdomain name.\n *\n * @param args - The arguments for retrieving the target address.\n * @param args.aptosConfig - The Aptos configuration object.\n * @param args.name - The name of the domain, which may include a subdomain.\n * @returns The target address as an AccountAddress, or undefined if not found.\n */\nexport async function getTargetAddress(args: {\n  aptosConfig: AptosConfig;\n  name: string;\n}): Promise<AccountAddress | undefined> {\n  const { aptosConfig, name } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  const res = await view({\n    aptosConfig,\n    payload: {\n      function: `${routerAddress}::router::get_target_addr`,\n      functionArguments: [domainName, subdomainName],\n    },\n  });\n\n  const target = unwrapOption<MoveAddressType>(res[0]);\n  return target ? AccountAddress.from(target) : undefined;\n}\n\n/**\n * Sets the target address for a specified domain and subdomain in the Aptos network.\n * This function helps to associate a given address with a domain name, allowing for easier access and management of resources.\n *\n * @param args - The arguments for setting the target address.\n * @param args.aptosConfig - The configuration settings for the Aptos network.\n * @param args.sender - The account that is sending the transaction.\n * @param args.name - The name of the domain or subdomain to be set.\n * @param args.address - The address to be associated with the domain or subdomain.\n * @param args.options - Optional parameters for generating the transaction.\n *\n * @returns A transaction object representing the set target address operation.\n */\nexport async function setTargetAddress(args: {\n  aptosConfig: AptosConfig;\n  sender: Account;\n  name: string;\n  address: AccountAddressInput;\n  options?: InputGenerateTransactionOptions;\n}): Promise<SimpleTransaction> {\n  const { aptosConfig, sender, name, address, options } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  const transaction = await generateTransaction({\n    aptosConfig,\n    sender: sender.accountAddress.toString(),\n    data: {\n      function: `${routerAddress}::router::set_target_addr`,\n      functionArguments: [domainName, subdomainName, address],\n    },\n    options,\n  });\n\n  return transaction;\n}\n\n/**\n * Retrieves the active Aptos name associated with the specified domain and subdomain.\n *\n * @param args - The parameters for the function.\n * @param args.aptosConfig - The configuration object for Aptos.\n * @param args.name - The name to look up, which includes the domain and optional subdomain.\n * @returns The active Aptos name if it exists; otherwise, returns undefined.\n */\nexport async function getName(args: {\n  aptosConfig: AptosConfig;\n  name: string;\n}): Promise<GetANSNameResponse[0] | undefined> {\n  const { aptosConfig, name } = args;\n  const { domainName, subdomainName = \"\" } = isValidANSName(name);\n\n  const where: CurrentAptosNamesBoolExp = {\n    domain: { _eq: domainName },\n    subdomain: { _eq: subdomainName },\n  };\n\n  const data = await queryIndexer<GetNamesQuery>({\n    aptosConfig,\n    query: {\n      query: GetNames,\n      variables: {\n        where_condition: where,\n        limit: 1,\n      },\n    },\n    originMethod: \"getName\",\n  });\n\n  // Convert the expiration_timestamp from an ISO string to milliseconds since epoch\n  let res = data.current_aptos_names[0];\n  if (res) {\n    res = sanitizeANSName(res);\n  }\n\n  return isActiveANSName(res) ? res : undefined;\n}\n\n/**\n * Options for querying names, including pagination, ordering, and filtering criteria.\n *\n * @param options - Pagination and filtering options for the query.\n */\ninterface QueryNamesOptions {\n  options?: PaginationArgs & OrderByArg<GetANSNameResponse[0]> & WhereArg<CurrentAptosNamesBoolExp>;\n}\n\n/**\n * Arguments for retrieving account names based on the specified account address.\n *\n * @param accountAddress - The address of the account for which names are to be retrieved.\n */\nexport interface GetAccountNamesArgs extends QueryNamesOptions {\n  accountAddress: AccountAddressInput;\n}\n\n/**\n * Retrieves the current Aptos names associated with a specific account address.\n *\n * @param args - The arguments for retrieving account names.\n * @param args.aptosConfig - The configuration object for Aptos.\n * @param args.options - Optional parameters for querying account names.\n * @param args.options.limit - The maximum number of names to retrieve.\n * @param args.options.offset - The number of names to skip before starting to collect the result set.\n * @param args.options.orderBy - The field by which to order the results.\n * @param args.options.where - Additional conditions to filter the results.\n * @param args.accountAddress - The address of the account for which to retrieve names.\n *\n * @returns An array of sanitized Aptos names associated with the specified account address.\n */\nexport async function getAccountNames(\n  args: { aptosConfig: AptosConfig } & GetAccountNamesArgs,\n): Promise<GetANSNameResponse> {\n  const { aptosConfig, options, accountAddress } = args;\n\n  const expirationDate = await getANSExpirationDate({ aptosConfig });\n\n  const data = await queryIndexer<GetNamesQuery>({\n    aptosConfig,\n    originMethod: \"getAccountNames\",\n    query: {\n      query: GetNames,\n      variables: {\n        limit: options?.limit,\n        offset: options?.offset,\n        order_by: options?.orderBy,\n        where_condition: {\n          ...(args.options?.where ?? {}),\n          owner_address: { _eq: accountAddress.toString() },\n          expiration_timestamp: { _gte: expirationDate },\n        },\n      },\n    },\n  });\n\n  return data.current_aptos_names.map(sanitizeANSName);\n}\n\n/**\n * Arguments for retrieving the domains associated with a specific account.\n *\n * @param accountAddress - The address of the account for which to fetch domains.\n */\nexport interface GetAccountDomainsArgs extends QueryNamesOptions {\n  accountAddress: AccountAddressInput;\n}\n\n/**\n * Retrieves the list of top-level domains owned by a specified account.\n *\n * @param args - The arguments for retrieving account domains.\n * @param args.aptosConfig - The Aptos configuration object.\n * @param args.options - Optional parameters for the query.\n * @param args.options.limit - The maximum number of results to return.\n * @param args.options.offset - The number of results to skip before starting to collect the result set.\n * @param args.options.orderBy - The field by which to order the results.\n * @param args.options.where - Additional conditions to filter the results.\n * @param args.options.where.owner_address - The address of the account whose domains are being queried.\n * @param args.options.where.expiration_timestamp - The minimum expiration timestamp for the domains.\n * @param args.options.where.subdomain - The specific subdomain to filter by.\n *\n * @returns An array of sanitized domain names owned by the specified account.\n */\nexport async function getAccountDomains(\n  args: { aptosConfig: AptosConfig } & GetAccountDomainsArgs,\n): Promise<GetANSNameResponse> {\n  const { aptosConfig, options, accountAddress } = args;\n\n  const expirationDate = await getANSExpirationDate({ aptosConfig });\n\n  const data = await queryIndexer<GetNamesQuery>({\n    aptosConfig,\n    originMethod: \"getAccountDomains\",\n    query: {\n      query: GetNames,\n      variables: {\n        limit: options?.limit,\n        offset: options?.offset,\n        order_by: options?.orderBy,\n        where_condition: {\n          ...(args.options?.where ?? {}),\n          owner_address: { _eq: accountAddress.toString() },\n          expiration_timestamp: { _gte: expirationDate },\n          subdomain: { _eq: \"\" },\n        },\n      },\n    },\n  });\n\n  return data.current_aptos_names.map(sanitizeANSName);\n}\n\n/**\n * Arguments for retrieving subdomains associated with a specific account.\n *\n * @param accountAddress - The address of the account for which to fetch subdomains.\n */\nexport interface GetAccountSubdomainsArgs extends QueryNamesOptions {\n  accountAddress: AccountAddressInput;\n}\n\n/**\n * Retrieves a list of subdomains owned by a specified account address.\n * This function helps you identify all subdomains associated with a given account.\n *\n * @param args - The arguments for retrieving account subdomains.\n * @param args.aptosConfig - The configuration object for Aptos.\n * @param args.options - Optional parameters for the query.\n * @param args.options.limit - The maximum number of results to return.\n * @param args.options.offset - The number of results to skip before starting to collect the result set.\n * @param args.options.orderBy - The field by which to order the results.\n * @param args.options.where - Additional conditions to filter the results.\n * @param args.options.where.owner_address - The address of the account to filter by.\n * @param args.options.where.expiration_timestamp - The expiration timestamp to filter by.\n * @param args.options.where.subdomain - The subdomain condition to filter by.\n * @param args.accountAddress - The address of the account whose subdomains are being queried.\n */\nexport async function getAccountSubdomains(\n  args: { aptosConfig: AptosConfig } & GetAccountSubdomainsArgs,\n): Promise<GetANSNameResponse> {\n  const { aptosConfig, options, accountAddress } = args;\n\n  const expirationDate = await getANSExpirationDate({ aptosConfig });\n\n  const data = await queryIndexer<GetNamesQuery>({\n    aptosConfig,\n    originMethod: \"getAccountSubdomains\",\n    query: {\n      query: GetNames,\n      variables: {\n        limit: options?.limit,\n        offset: options?.offset,\n        order_by: options?.orderBy,\n        where_condition: {\n          ...(args.options?.where ?? {}),\n          owner_address: { _eq: accountAddress.toString() },\n          expiration_timestamp: { _gte: expirationDate },\n          subdomain: { _neq: \"\" },\n        },\n      },\n    },\n  });\n\n  return data.current_aptos_names.map(sanitizeANSName);\n}\n\n/**\n * Arguments for retrieving subdomains associated with a specific domain.\n *\n * @param domain - The domain for which to fetch subdomains.\n */\nexport interface GetDomainSubdomainsArgs extends QueryNamesOptions {\n  domain: string;\n}\n\n/**\n * Retrieve the active subdomains associated with a specified domain.\n *\n * @param args - The arguments for retrieving subdomains.\n * @param args.aptosConfig - The configuration settings for Aptos.\n * @param args.options - Optional parameters for the query.\n * @param args.options.limit - The maximum number of results to return.\n * @param args.options.offset - The number of results to skip before starting to collect the results.\n * @param args.options.orderBy - The field by which to order the results.\n * @param args.options.where - Additional conditions to filter the results.\n * @param args.domain - The domain for which to retrieve subdomains.\n *\n * @returns An array of active subdomain names.\n */\nexport async function getDomainSubdomains(\n  args: { aptosConfig: AptosConfig } & GetDomainSubdomainsArgs,\n): Promise<GetANSNameResponse> {\n  const { aptosConfig, options, domain } = args;\n\n  const data = await queryIndexer<GetNamesQuery>({\n    aptosConfig,\n    originMethod: \"getDomainSubdomains\",\n    query: {\n      query: GetNames,\n      variables: {\n        limit: options?.limit,\n        offset: options?.offset,\n        order_by: options?.orderBy,\n        where_condition: {\n          ...(args.options?.where ?? {}),\n          domain: { _eq: domain },\n          subdomain: { _neq: \"\" },\n        },\n      },\n    },\n  });\n\n  return data.current_aptos_names.map(sanitizeANSName).filter(isActiveANSName);\n}\n\n/**\n * This function returns the expiration date in which a name is fully expired as\n * defined by the contract.  The grace period allows for names to be past\n * expiration for a certain amount of time before they are released to the\n * public. The names will not function as normal, but the owner can renew\n * without others taking ownership of the name. At the time of writing, the\n * contract specified 30 days.\n *\n * @param args - The arguments for the function.\n * @param args.aptosConfig - An AptosConfig object containing the configuration settings.\n * @returns The expiration date in ISO 8601 format.\n */\nasync function getANSExpirationDate(args: { aptosConfig: AptosConfig }): Promise<string> {\n  const { aptosConfig } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n\n  const [gracePeriodInSeconds] = await view<[number]>({\n    aptosConfig,\n    payload: {\n      function: `${routerAddress}::config::reregistration_grace_sec`,\n      functionArguments: [],\n    },\n  });\n\n  const gracePeriodInDays = gracePeriodInSeconds / 60 / 60 / 24;\n  const now = () => new Date();\n  return new Date(now().setDate(now().getDate() - gracePeriodInDays)).toISOString();\n}\n\n/**\n * Renews a domain for a specified duration. This function allows you to extend the registration of a domain for one year.\n *\n * @param args - The parameters required to renew the domain.\n * @param args.aptosConfig - The configuration settings for Aptos.\n * @param args.sender - The account that is sending the renewal transaction.\n * @param args.name - The name of the domain to renew.\n * @param args.years - The number of years to renew the domain for. Currently, only 1 year renewals are supported. (optional, default is 1)\n * @param args.options - Additional options for generating the transaction. (optional)\n * @throws Error if the name contains a subdomain or if the years parameter is not equal to 1.\n */\nexport async function renewDomain(args: {\n  aptosConfig: AptosConfig;\n  sender: Account;\n  name: string;\n  years?: 1;\n  options?: InputGenerateTransactionOptions;\n}): Promise<SimpleTransaction> {\n  const { aptosConfig, sender, name, years = 1, options } = args;\n  const routerAddress = getRouterAddress(aptosConfig);\n  const renewalDuration = years * 31536000;\n  const { domainName, subdomainName } = isValidANSName(name);\n\n  if (subdomainName) {\n    throw new Error(\"Subdomains cannot be renewed\");\n  }\n\n  if (years !== 1) {\n    throw new Error(\"Currently, only 1 year renewals are supported\");\n  }\n\n  const transaction = await generateTransaction({\n    aptosConfig,\n    sender: sender.accountAddress.toString(),\n    data: {\n      function: `${routerAddress}::router::renew_domain`,\n      functionArguments: [domainName, renewalDuration],\n    },\n    options,\n  });\n\n  return transaction;\n}\n\n/**\n * The indexer returns ISO strings for expiration, however the contract works in\n * epoch milliseconds. This function converts the ISO string to epoch\n * milliseconds. In the future, if other properties need sanitization, this can\n * be extended.\n *\n * @param name - The ANS name response to sanitize.\n * @param name.expiration_timestamp - The expiration timestamp in ISO string format.\n */\nfunction sanitizeANSName(name: GetANSNameResponse[0]): GetANSNameResponse[0] {\n  return {\n    ...name,\n    expiration_timestamp: new Date(name.expiration_timestamp).getTime(),\n  };\n}\n"],"mappings":"6MAwBO,IAAMA,EAA+B,CAC1C,mDACA,wDACA,4CACF,EAAE,KAAK,GAAG,EASH,SAASC,EAAkBC,EAA2B,CAK3D,MAJI,GAACA,GACDA,EAAS,OAAS,GAClBA,EAAS,OAAS,IAElB,CAAC,iCAAiC,KAAKA,CAAQ,EAErD,CAOO,SAASC,EAAeC,EAA8D,CAC3F,GAAM,CAACC,EAAOC,EAAQ,GAAGC,CAAI,EAAIH,EAAK,QAAQ,SAAU,EAAE,EAAE,MAAM,GAAG,EAErE,GAAIG,EAAK,OAAS,EAChB,MAAM,IAAI,MAAM,GAAGH,CAAI,0FAA0F,EAGnH,GAAI,CAACH,EAAkBI,CAAK,EAC1B,MAAM,IAAI,MAAM,GAAGA,CAAK,kBAAkBL,CAA4B,EAAE,EAG1E,GAAIM,GAAU,CAACL,EAAkBK,CAAM,EACrC,MAAM,IAAI,MAAM,GAAGA,CAAM,kBAAkBN,CAA4B,EAAE,EAG3E,MAAO,CACL,WAAYM,GAAUD,EACtB,cAAeC,EAASD,EAAQ,MAClC,CACF,CAKO,IAAKG,OACVA,IAAA,YAAc,GAAd,cACAA,IAAA,cAAgB,GAAhB,gBAFUA,OAAA,IAcL,SAASC,EAAgBL,EAAsC,CACpE,GAAI,CAACA,EAAM,MAAO,GAElB,IAAMM,EAAe,IAAI,KAAKN,EAAK,2BAA2B,EAAE,QAAQ,EAAI,KAAK,IAAI,EAC/EO,EAAY,IAAI,KAAKP,EAAK,oBAAoB,EAAE,QAAQ,EAAI,KAAK,IAAI,EAG3E,OAAIA,EAAK,WAAaM,EAAqB,GAIvCN,EAAK,WAAaA,EAAK,8BAAgC,EAAgD,GAIpG,CAACO,CACV,CAEO,IAAMC,EACX,qEAEWC,EACX,qEAEIC,EAAuD,CAC1D,QAAkB,qEAClB,QAAkB,qEAClB,MA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C5CgD,EAAkB3B,EAAQ,QAC1B,CAAE,WAAAd,EAAY,cAAAC,CAAc,EAAIrB,EAAeC,CAAI,EAEzD,GAAIoB,EACF,MAAM,IAAI,MAAM,8BAA8B,EAGhD,GAAIa,IAAU,EACZ,MAAM,IAAI,MAAM,+CAA+C,EAajE,OAVoB,MAAME,EAAoB,CAC5C,YAAAvB,EACA,OAAQe,EAAO,eAAe,SAAS,EACvC,KAAM,CACJ,SAAU,GAAGT,CAAa,yBAC1B,kBAAmB,CAACC,EAAYyC,CAAe,CACjD,EACA,QAAA9B,CACF,CAAC,CAGH,CAWA,SAASiB,EAAgB/C,EAAoD,CAC3E,MAAO,CACL,GAAGA,EACH,qBAAsB,IAAI,KAAKA,EAAK,oBAAoB,EAAE,QAAQ,CACpE,CACF","names":["VALIDATION_RULES_DESCRIPTION","isValidANSSegment","fragment","isValidANSName","name","first","second","rest","SubdomainExpirationPolicy","isActiveANSName","isTLDExpired","isExpired","LOCAL_ANS_ACCOUNT_PK","LOCAL_ANS_ACCOUNT_ADDRESS","NetworkToAnsContract","getRouterAddress","aptosConfig","address","unwrapOption","option","getOwnerAddress","args","routerAddress","domainName","subdomainName","res","view","owner","AccountAddress","registerName","expiration","sender","targetAddress","toAddress","options","transferable","hasSubdomainPolicy","years","registrationDuration","generateTransaction","tldExpiration","getExpiration","expirationDateInMillisecondsSinceEpoch","getPrimaryName","setPrimaryName","getTargetAddress","target","setTargetAddress","getName","queryIndexer","GetNames","sanitizeANSName","getAccountNames","accountAddress","expirationDate","getANSExpirationDate","getAccountDomains","getAccountSubdomains","getDomainSubdomains","domain","gracePeriodInSeconds","gracePeriodInDays","now","renewDomain","renewalDuration"]}

Выполнить команду


Для локальной разработки. Не используйте в интернете!