@aeternity/aepp-sdk
Version:
SDK for the æternity blockchain
181 lines (180 loc) • 6.82 kB
TypeScript
/**
* Aens methods - routines to interact with the æternity naming system
*
* The high-level description of the naming system is
* https://github.com/aeternity/protocol/blob/master/AENS.md in the protocol
* repository.
*/
import BigNumber from 'bignumber.js';
import { Tag, AensName } from './tx/builder/constants.js';
import { Encoded, Encoding } from './utils/encoder.js';
import { sendTransaction, SendTransactionOptions } from './send-transaction.js';
import { Optional } from './utils/other.js';
import { BuildTxOptions } from './tx/builder/index.js';
import Node from './Node.js';
import AccountBase from './account/Base.js';
import { AddressEncodings } from './tx/builder/field-types/address.js';
interface NameRevokeOptions extends BuildTxOptions<Tag.NameRevokeTx, 'nameId' | 'accountId'>, Optional<SendTransactionOptions, 'onAccount' | 'onNode'> {
}
interface KeyPointers {
[key: string]: Encoded.Generic<AddressEncodings | Encoding.Bytearray>;
}
interface NameUpdateOptions extends BuildTxOptions<Tag.NameUpdateTx, 'nameId' | 'accountId' | 'pointers'>, Optional<SendTransactionOptions, 'onAccount' | 'onNode'> {
/**
* Get the pointers from the node and merge with provided ones. Pointers with the same key will be
* overwritten.
*/
extendPointers?: boolean;
}
interface NameTransferOptions extends BuildTxOptions<Tag.NameTransferTx, 'nameId' | 'accountId' | 'recipientId'>, Optional<SendTransactionOptions, 'onAccount' | 'onNode'> {
}
interface NamePreclaimOptions extends BuildTxOptions<Tag.NamePreclaimTx, 'accountId' | 'commitmentId'>, Optional<SendTransactionOptions, 'onAccount' | 'onNode'> {
}
interface NameClaimOptions extends BuildTxOptions<Tag.NameClaimTx, 'accountId' | 'name'>, Optional<SendTransactionOptions, 'onAccount' | 'onNode'> {
}
/**
* @category AENS
* @example
* ```js
* const name = new Name('test.chain', aeSdk.getContext())
* ```
*/
export default class Name {
#private;
readonly value: AensName;
options: {
onNode: Node;
onAccount: AccountBase;
} & Omit<NameRevokeOptions & NameUpdateOptions & NameTransferOptions & NamePreclaimOptions & NameClaimOptions, 'version'>;
/**
* @param value - AENS name
* @param options - Options
* @param options.onNode - Node to use
* @param options.onAccount - Account to use
*/
constructor(value: AensName, options: {
onNode: Node;
onAccount: AccountBase;
} & Omit<NameRevokeOptions & NameUpdateOptions & NameTransferOptions & NamePreclaimOptions & NameClaimOptions, 'version'>);
/**
* Name ID encoded as nm_-prefixed string
*/
get id(): Encoded.Name;
/**
* Revoke a name
* @param options - Options
* @returns mined transaction details
* @example
* ```js
* await name.revoke({ fee, ttl, nonce })
* ```
*/
revoke(options?: NameRevokeOptions): ReturnType<typeof sendTransaction>;
/**
* Update a name
* @param pointers - Map of pointer keys to corresponding addresses
* @param options - Options
* @example
* ```js
* const name = 'test.chain'
* const channel = 'ch_2519mBs...'
* const pointers = {
* account_pubkey: 'ak_asd23dasdas...,',
* contract_pubkey: 'ct_asdf34fasdasd...',
* [getDefaultPointerKey(channel)]: channel,
* }
* await name.update(pointers, { nameTtl, ttl, fee, nonce, clientTtl })
* ```
*/
update(pointers: KeyPointers, options?: NameUpdateOptions): ReturnType<typeof sendTransaction>;
/**
* Transfer a name to another account
* @param address - Recipient account public key
* @param options - Options
* @returns mined transaction details
* @example
* ```js
* await name.transfer('ak_asd23dasdas...', { ttl, fee, nonce })
* ```
*/
transfer(address: Encoded.AccountAddress, options?: NameTransferOptions): ReturnType<typeof sendTransaction>;
/**
* Query the AENS name info from the node and return the object with info
* @param options - Options
* @example
* ```js
* const nameEntry = await name.getState()
* console.log(nameEntry.owner)
* ```
*/
getState(options?: {
onNode?: Node;
}): Promise<Awaited<ReturnType<Node['getNameEntryByName']>> & {
id: Encoded.Name;
owner: Encoded.AccountAddress;
}>;
/**
* Query the AENS auction info from the node and return the object with info
* @param options - Options
* @example
* ```js
* const auctionEntry = await name.getAuctionState()
* console.log(auctionEntry.highestBidder)
* ```
*/
getAuctionState(options?: {
onNode?: Node;
}): Promise<Awaited<ReturnType<Node['getAuctionEntryByName']>> & {
id: Encoded.Name;
highestBidder: Encoded.AccountAddress;
}>;
/**
*
* @param nameTtl - represents in number of blocks (max and default is 180000)
* @param options - Options
* @returns mined transaction details
*/
extendTtl(nameTtl?: number, options?: Omit<Parameters<Name['update']>[1], 'extendPointers' | 'nameTtl'>): ReturnType<Name['update']>;
/**
* Claim a name.
*
* Since the Ceres protocol upgrade, it is possible to claim a name without preclaiming it.
* If you preclaim, wait for at least 1 key block to be mined before exposing a name in the
* NameClaimTx to ensure that nobody can front-run the claim.
*
* @param options - options
* @returns mined transaction details
* @example
* ```js
* await name.claim({ ttl, fee, nonce, nameFee })
* ```
*/
claim(options?: NameClaimOptions): ReturnType<typeof sendTransaction>;
/**
* Preclaim a name. This sends a commitment hash (derived from the name and a random salt) to
* the node. Preclaiming was required to claim a name before the Ceres protocol upgrade.
* After the upgrade, preclaiming is optional but still available for added security if you
* want to claim a non-auction name.
* @param options - Options
* @example
* ```js
* await name.preclaim({ ttl, fee, nonce })
* ```
*/
preclaim(options?: NamePreclaimOptions): Promise<Awaited<ReturnType<typeof sendTransaction>> & {
nameSalt: number;
}>;
/**
* Bid to name auction
* @param nameFee - Name fee (bid fee)
* @param options - Options
* @returns mined transaction details
* @example
* ```js
* const bidFee = computeBidFee(name.value, { startFee, increment: 0.42 })
* await name.bid(213109412839123, { ttl, fee, nonce })
* ```
*/
bid(nameFee: number | string | BigNumber, options?: Omit<NameClaimOptions, 'nameFee'>): ReturnType<typeof sendTransaction>;
}
export {};