UNPKG

@ar.io/sdk

Version:

[![codecov](https://codecov.io/gh/ar-io/ar-io-sdk/graph/badge.svg?token=7dXKcT7dJy)](https://codecov.io/gh/ar-io/ar-io-sdk)

539 lines (538 loc) 23.6 kB
import { AntReadOptions, AoANTHandler, AoANTInfo, AoANTRead, AoANTRecord, AoANTSetBaseNameRecordParams, AoANTSetUndernameRecordParams, AoANTState, AoANTWrite, SortedANTRecords } from '../types/ant.js'; import { AoClient, AoMessageResult, AoSigner, ProcessConfiguration, UpgradeAntProgressEvent, WalletAddress, WithSigner, WriteOptions } from '../types/index.js'; import { forkANT, spawnANT } from '../utils/ao.js'; import { AOProcess, Logger } from './index.js'; type ANTConfigOptionalStrict = Required<ProcessConfiguration> & { strict?: boolean; hyperbeamUrl?: string; }; type ANTConfigNoSigner = ANTConfigOptionalStrict; type ANTConfigWithSigner = WithSigner<ANTConfigOptionalStrict>; export declare class ANT { /** * Versions of ANTs according to the ANT registry. * * Needs to be wrapped in a getter to avoid circular dependency issues. */ static get versions(): import("../types/ant.js").AoANTVersionsRead; /** * Spawn a new ANT. */ static spawn: typeof spawnANT; /** * Fork an ANT to a new process. * * @param config */ static fork: typeof forkANT; /** * Upgrade an ANT by forking it to the latest version and reassigning names. * * * @param config Configuration object for the upgrade process * @returns Promise resolving to the forked process ID and successfully reassigned names */ static upgrade({ signer, antProcessId, reassignAffiliatedNames, names, arioProcessId, antRegistryId, ao, logger, skipVersionCheck, onSigningProgress, hyperbeamUrl, }: { signer: AoSigner; antProcessId: string; arioProcessId?: string; skipVersionCheck?: boolean; ao?: AoClient; logger?: Logger; antRegistryId?: string; hyperbeamUrl?: string; onSigningProgress?: (name: keyof UpgradeAntProgressEvent, payload: UpgradeAntProgressEvent[keyof UpgradeAntProgressEvent]) => void; } & ({ names: string[]; reassignAffiliatedNames?: false; } | { names?: never; reassignAffiliatedNames: true; })): Promise<{ forkedProcessId: string; reassignedNames: Record<string, AoMessageResult>; failedReassignedNames: Record<string, { id?: string; error: Error; }>; }>; /** * Initialize overloads. * * @param config */ static init(config: ANTConfigNoSigner): AoANTRead; static init(config: ANTConfigWithSigner): AoANTWrite; } export declare class AoANTReadable implements AoANTRead { protected process: AOProcess; readonly processId: string; readonly hyperbeamUrl: URL | undefined; private strict; private checkHyperBeamPromise; private moduleId; private moduleIdPromise; private logger; constructor(config: ANTConfigOptionalStrict); /** * Check if the process is HyperBeam compatible. If so, we'll use the HyperBeam node to fetch the state. * * @returns {Promise<boolean>} True if the process is HyperBeam compatible, false otherwise. */ private checkHyperBeamCompatibility; getState({ strict }?: AntReadOptions): Promise<AoANTState>; getInfo({ strict }?: AntReadOptions): Promise<AoANTInfo>; /** * Returns the TX ID of the logo set for the ANT. */ getLogo(): Promise<string>; /** * Gets the module ID of the current ANT process by querying its spawn transaction tags. * Results are cached after the first successful fetch. * * @param graphqlUrl The GraphQL endpoint URL (defaults to Arweave's GraphQL endpoint) * @param retries Number of retry attempts (defaults to 3) * @returns Promise<string> The module ID used to spawn this ANT process * @example * ```ts * const moduleId = await ant.getModuleId(); * console.log(`ANT was spawned with module: ${moduleId}`); * ``` */ getModuleId({ graphqlUrl, retries, }?: { graphqlUrl?: string; retries?: number; }): Promise<string>; /** * Internal method to fetch the module ID from GraphQL. * * TODO: this could be more like get process headers/metadata and fetch additional details. * * It seems like module is the only relevant one, but scheduler and authority are also available. */ private fetchModuleId; /** * Gets the version string of the current ANT by matching its module ID * with versions from the ANT registry. * * @param antRegistryId The ANT registry process ID (defaults to mainnet registry) * @param graphqlUrl The GraphQL endpoint URL for getModuleId (defaults to Arweave's GraphQL endpoint) * @param retries Number of retry attempts for getModuleId (defaults to 3) * @returns Promise<string> The version string (e.g., "1.0.15") or "unknown" if not found * @example * ```ts * const version = await ant.getVersion(); * console.log(`ANT is running version: ${version}`); * ``` */ getVersion({ antRegistryId, graphqlUrl, retries, }?: { antRegistryId?: string; graphqlUrl?: string; retries?: number; }): Promise<string>; /** * Checks if the current ANT version is the latest according to the ANT registry. * * @param antRegistryId Optional ANT registry process ID. Defaults to mainnet ANT registry. * @param graphqlUrl Optional GraphQL endpoint. Defaults to https://arweave.net/graphql. * @param retries Optional number of retries for fetching module ID. Defaults to 3. * @returns {Promise<boolean>} True if current ANT version is the latest, false otherwise. */ isLatestVersion({ antRegistryId, graphqlUrl, retries, }?: { antRegistryId?: string; graphqlUrl?: string; retries?: number; }): Promise<boolean>; /** * @param undername @type {string} The domain name. * @returns {Promise<ANTRecord>} The record of the undername domain. * @example * Get the current record * ```ts * ant.getRecord({ undername: "john" }); * ``` */ getRecord({ undername }: { undername: string; }, { strict }?: AntReadOptions): Promise<AoANTRecord>; /** * @returns {Promise<SortedANTRecords>} All the undernames managed by the ANT. * @example * Get the current records * ```ts * ant.getRecords(); * ```` */ getRecords({ strict }?: AntReadOptions): Promise<SortedANTRecords>; /** * @returns {Promise<string>} The owner of the ANT. * @example * Get the current owner * ```ts * ant.getOwner(); * ``` */ getOwner({ strict }?: AntReadOptions): Promise<string>; /** * @returns {Promise<string[]>} The controllers of the ANT. * @example * Get the controllers of the ANT. * ```ts * ant.getControllers(); * ``` */ getControllers({ strict }?: AntReadOptions): Promise<WalletAddress[]>; /** * @returns {Promise<string>} The name of the ANT (not the same as ArNS name). * @example * Get the current name * ```ts * ant.getName(); * ``` */ getName({ strict }?: AntReadOptions): Promise<string>; /** * @returns {Promise<string>} The name of the ANT (not the same as ArNS name). * @example * The current ticker of the ANT. * ```ts * ant.getTicker(); * ``` */ getTicker({ strict }?: AntReadOptions): Promise<string>; /** * @returns {Promise<Record<WalletAddress, number>>} The balances of the ANT * @example * The current balances of the ANT. * ```ts * ant.getBalances(); * ``` */ getBalances({ strict }?: AntReadOptions): Promise<Record<string, number>>; /** * @param address @type {string} The address of the account you want the balance of. * @returns {Promise<number>} The balance of the provided address * @example * The current balance of the address. * ```ts * ant.getBalance({ address }); * ``` */ getBalance({ address }: { address: string; }, { strict }?: AntReadOptions): Promise<number>; /** * @returns {Promise<AoANTHandler[]>} The handlers of the ANT. * @example * Get the handlers of the ANT. * ```ts * const handlers = await ant.getHandlers(); * ``` */ getHandlers(): Promise<AoANTHandler[]>; } export declare class AoANTWriteable extends AoANTReadable implements AoANTWrite { private signer; constructor({ signer, ...config }: WithSigner<Required<ProcessConfiguration>> & { strict?: boolean; }); /** * @param target @type {string} The address of the account you want to transfer the ANT to. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.transfer({ target: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" }); * ``` */ transfer({ target }: { target: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * @param controller @type {string} The address of the account you want to set as a controller. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" }); * ``` */ addController({ controller, }: { controller: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * @param controller @type {string} The address of the account you want to remove from the controllers list * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.removeController({ controller: "fGht8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk" }); * ``` */ removeController({ controller, }: { controller: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the transactionId and ttlSeconds of a record (for updating the top level name, use undername "@".) * * @deprecated Use setUndernameRecord instead for undernames, and setBaseNameRecord instead for the top level name (e.g. "@") * @param undername @type {string} The record you want to set the transactionId and ttlSeconds of. * @param transactionId @type {string} The transactionId of the record. * @param ttlSeconds @type {number} The time to live of the record. * @param owner @type {string} Optional owner address for the record. * @param displayName @type {string} Optional display name for the record. * @param logo @type {string} Optional logo transaction ID for the record. * @param description @type {string} Optional description for the record. * @param keywords @type {string[]} Optional keywords array for the record. * @returns {Promise<AoMessageResult>} The result of the interaction. */ setRecord({ undername, transactionId, ttlSeconds, owner, displayName, logo, description, keywords, }: AoANTSetUndernameRecordParams, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the top level name of the ANT. This is the name that will be used to resolve the ANT (e.g. ardrive.ar.io) * * @param transactionId @type {string} The transactionId of the record. * @param ttlSeconds @type {number} The time to live of the record. * @param owner @type {string} Optional owner address for the record. * @param displayName @type {string} Optional display name for the record. * @param logo @type {string} Optional logo transaction ID for the record. * @param description @type {string} Optional description for the record. * @param keywords @type {string[]} Optional keywords array for the record. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setBaseNameRecord({ transactionId: "432l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM", ttlSeconds: 100 }); // ardrive.ar.io will resolve to the provided transaction id and be cached for 100 seconds by clients * ``` */ setBaseNameRecord({ transactionId, ttlSeconds, owner, displayName, logo, description, keywords, }: AoANTSetBaseNameRecordParams, options?: WriteOptions): Promise<AoMessageResult>; /** * Adds or updates an undername of the ANT. An undername is appended to the base name of the ANT (e.g. ardrive.ar.io) to form a fully qualified name (e.g. dapp_ardrive.ar.io) * * @param undername @type {string} The undername of the ANT. * @param transactionId @type {string} The transactionId of the record. * @param ttlSeconds @type {number} The time to live of the record. * @param owner @type {string} Optional owner address for the record. * @param displayName @type {string} Optional display name for the record. * @param logo @type {string} Optional logo transaction ID for the record. * @param description @type {string} Optional description for the record. * @param keywords @type {string[]} Optional keywords array for the record. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setUndernameRecord({ undername: "dapp", transactionId: "432l1cy0aksiL_x9M359faGzM_yjralacHIUo8_nQXM", ttlSeconds: 100 }); // dapp_ardrive.ar.io will resolve to the provided transaction id and be cached for 100 seconds by clients * ``` */ setUndernameRecord({ undername, transactionId, ttlSeconds, owner, displayName, logo, description, keywords, }: AoANTSetUndernameRecordParams, options?: WriteOptions): Promise<AoMessageResult>; /** * Removes an undername from the ANT. This will remove the undername from the ANT. * * @param undername @type {string} The undername you want to remove. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.removeUndernameRecord({ undername: "dapp" }); // removes dapp_ardrive.ar.io * ``` */ removeUndernameRecord({ undername, }: { undername: string; }): Promise<AoMessageResult>; /** * Removes a record from the ANT. This will remove the record from the ANT. If '@' is provided, the top level name will be removed. * * @deprecated Use removeUndernameRecord instead. * @param undername @type {string} The record you want to remove. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.removeRecord({ undername: "dapp" }); // removes dapp_ardrive.ar.io * ``` */ removeRecord({ undername, }: { undername: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the ticker of the ANT. This is the abbreviation displayed in ecosystem apps. * * @param ticker @type {string} Sets the ANT Ticker. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setTicker({ ticker: "KAPOW" }); * ``` */ setTicker({ ticker }: { ticker: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the name of the ANT. This is the display name of the ANT. This is NOT the base name record. * * @param name @type {string} Sets the Name of the ANT. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setName({ name: "test" }); // results in the resolution of `test_<apexName>.ar.io` * ``` */ setName({ name }: { name: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the description of the ANT. This is the description of the ANT displayed in ecosystem apps. * * @param description @type {string} Sets the ANT Description. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setDescription({ description: "This name is used for the ArDrive" }); * ``` */ setDescription({ description }: { description: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the keywords of the ANT. This is the keywords of the ANT displayed in ecosystem apps. * * @param keywords @type {string[]} Sets the ANT Keywords. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setKeywords({ keywords: ['keyword1', 'keyword2', 'keyword3']}); * ``` */ setKeywords({ keywords }: { keywords: string[]; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sets the logo of the ANT. This is the logo of the ANT displayed in ecosystem apps. Additionally, this logo is displayed for any primary names affiliated with the ANT. * * @param txId @type {string} - Arweave transaction id of the logo we want to set * @param options @type {WriteOptions} - additional options to add to the write interaction (optional) * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.setLogo({ logo: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f" }); * ``` */ setLogo({ txId }: { txId: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Releases an ArNS name associated with the ANT. This will release the name to the public and allow anyone to register it. All primary names must be removed before the name can be released. * * @param name @type {string} The name you want to release. The name will be put up for as a recently returned name on the ARIO contract. 50% of the winning bid will be distributed to the ANT owner at the time of purchase. If no purchase in the recently returned name period (14 epochs), the name will be released and can be reregistered by anyone. * @param arioProcessId @type {string} The processId of the ARIO contract. This is where the ANT will send the message to release the name. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.releaseName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID }); * ``` */ releaseName({ name, arioProcessId }: { name: string; arioProcessId: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Sends a message to the ARIO contract to reassign the the base ArNS name to a new ANT. This can only be done by the current owner of the ANT. * * @param name @type {string} The name you want to reassign. * @param arioProcessId @type {string} The processId of the ARIO contract. * @param antProcessId @type {string} The processId of the ANT contract. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.reassignName({ name: "ardrive", arioProcessId: ARIO_MAINNET_PROCESS_ID, antProcessId: NEW_ANT_PROCESS_ID }); * ``` */ reassignName({ name, arioProcessId, antProcessId, }: { name: string; arioProcessId: string; antProcessId: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Approves a primary name request for a given name or address. * * @param name @type {string} The name you want to approve. * @param address @type {WalletAddress} The address you want to approve. * @param arioProcessId @type {string} The processId of the ARIO contract. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.approvePrimaryNameRequest({ name: "ardrive", address: "U7RXcpaVShG4u9nIcPVmm2FJSM5Gru9gQCIiRaIPV7f", arioProcessId: ARIO_MAINNET_PROCESS_ID }); // approves the request for ardrive.ar.io to be registered by the address * ``` */ approvePrimaryNameRequest({ name, address, arioProcessId, }: { name: string; address: WalletAddress; arioProcessId: string; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Removes primary names from the ANT. This will remove the primary names associated with the base ArNS name controlled by this ANT. All primary names must be removed before the name can be released. * * @param names @type {string[]} The names you want to remove. * @param arioProcessId @type {string} The processId of the ARIO contract. * @param notifyOwners @type {boolean} Whether to notify the owners of the primary names. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.removePrimaryNames({ names: ["ardrive", "dapp_ardrive"], arioProcessId: ARIO_MAINNET_PROCESS_ID, notifyOwners: true }); // removes the primary names and associated wallet addresses assigned to "ardrive" and "dapp_ardrive" * ``` */ removePrimaryNames({ names, arioProcessId, notifyOwners, }: { names: string[]; arioProcessId: string; notifyOwners?: boolean; }, options?: WriteOptions): Promise<AoMessageResult>; /** * Upgrade this ANT by forking it to the latest version and reassigning names. * * This is a convenience method that calls the static ANT.upgrade() method * using this instance's process ID and signer. * * current version with latest ANT registry version and skip if already up to date. * * @param names @type {string[]} The ArNS names to reassign to the upgraded ANT. * @param arioProcessId @type {string} The processId of the ARIO contract. * @param antRegistryId @type {string} Optional ANT registry ID. * @param onSigningProgress Progress callback function. * @returns {Promise} The upgrade results. * @example * ```ts * const result = await ant.upgrade({ * names: ["example", "test"], * arioProcessId: ARIO_MAINNET_PROCESS_ID * }); * console.log(`Upgraded to process: ${result.forkedProcessId}`); * ``` */ upgrade(params?: { arioProcessId?: string; antRegistryId?: string; skipVersionCheck?: boolean; onSigningProgress?: (name: keyof UpgradeAntProgressEvent, payload: UpgradeAntProgressEvent[keyof UpgradeAntProgressEvent]) => void; } & ({ names: string[]; reassignAffiliatedNames?: false; } | { names?: never; reassignAffiliatedNames?: true; })): Promise<{ forkedProcessId: string; reassignedNames: Record<string, AoMessageResult>; failedReassignedNames: Record<string, { id?: string; error: Error; }>; }>; /** * Transfers ownership of a specific record (undername) to another address. This allows delegation of control for individual records within an ANT while maintaining the ANT owner's ultimate authority. * * @param undername @type {string} The subdomain/record whose ownership you want to transfer. * @param recipient @type {string} The address of the new owner for this record. * @returns {Promise<AoMessageResult>} The result of the interaction. * @example * ```ts * ant.transferRecord({ undername: "alice", recipient: "new-owner-address-123..." }); // transfers ownership of the "alice" record to the new owner * ``` */ transferRecord({ undername, recipient, }: { undername: string; recipient: string; }, options?: WriteOptions): Promise<AoMessageResult>; } export {};