UNPKG

@rsksmart/rns-sdk

Version:
148 lines (147 loc) 6.25 kB
import { BigNumber, Contract, Signer } from 'ethers'; interface OperationResult<T> { estimateGas: () => Promise<BigNumber>; execute: () => Promise<T>; } type Network = 'mainnet' | 'testnet' | 'localhost'; interface NetworkAddresses { [key: string]: string | undefined; partnerAddress?: string; partnerRegistrarAddress?: string; partnerRenewerAddress?: string; rifTokenAddress?: string; rskOwnerAddress?: string; } export declare const mainnetAddresses: NetworkAddresses; export declare const testnetAddresses: NetworkAddresses; type CommitFunction = (label: string, owner: string, duration: BigNumber, addr?: string) => OperationResult<{ secret: string; hash: string; }>; type RegisterFunction = (label: string, owner: string, secret: string, duration: BigNumber, amount: BigNumber, addr?: string) => OperationResult<boolean>; type RenewFunction = (label: string, duration: BigNumber, amount: BigNumber) => OperationResult<boolean>; type CommitAndRegisterFunction = (label: string, owner: string, duration: BigNumber, amount: BigNumber, partnerConfigurationAddress: string, addr?: string) => OperationResult<boolean>; type TransferFunction = (label: string, to: string) => OperationResult<void>; type CommitArgs = Parameters<CommitFunction>; type RegisterArgs = Parameters<RegisterFunction>; type RenewArgs = Parameters<RenewFunction>; type CommitAndRegisterArgs = Parameters<CommitAndRegisterFunction>; type TransferArgs = Parameters<TransferFunction>; type AcceptedOperationNames = 'commit' | 'register' | 'renew' | 'commitAndRegister' | 'transfer'; type AcceptedArgs<T extends AcceptedOperationNames> = T extends 'commit' ? CommitArgs : T extends 'register' ? RegisterArgs : T extends 'renew' ? RenewArgs : T extends 'commitAndRegister' ? CommitAndRegisterArgs : T extends 'transfer' ? TransferArgs : never; export declare class PartnerRegistrar { rskOwner: Contract; partnerRegistrar: Contract; partnerRenewer: Contract; rifToken: Contract; signer: Signer; partnerAddress: string; networkAddresses: NetworkAddresses; constructor(signer: Signer, network: Network, networkAddresses?: NetworkAddresses); private validateNetworkAddressesLocalhost; private setNetworkAddresses; private getDefaultNetworkAddresses; /** * Transfers the ownership of an RNS name to another address * @param label the registered name * @param to the address to transfer the name to */ transfer(label: string, to: string): Promise<string>; private transferOp; /** * Reclaims ownership of an RNS name on the registry after a transfer * @param label */ reclaim(label: string): Promise<string>; /** * Checks availability of an RNS name * @param label the name to register */ available(label: string): Promise<boolean>; /** * Returns the owner of an RNS name * @param label the name to register */ ownerOf(label: string): Promise<string>; /** * Returns the price of an RNS name * @param label the name to register * @param duration the duration to register the name */ price(label: string, duration: BigNumber): Promise<BigNumber>; private commitOp; /** * @typedef CommitmentResult * @property secret - The secret used to create the commitment * @property hash - The resulting commitment hash */ /** * Make a commitment * @param label the name to register * @param owner the owner of the name * @param duration the duration to register the name * @param addr the address to set for the name resolution * @returns {CommitmentResult} the result of the commitment */ commit(label: string, owner: string, duration: BigNumber, addr?: string): Promise<{ secret: string; hash: string; }>; /** * Estimate gas cost for an operation * @param operationName the operation to estimate gas for * @param args the arguments for the operation * @returns the estimated gas cost for the operation */ estimateGas<T extends AcceptedOperationNames>(operationName: T, ...args: AcceptedArgs<T>): Promise<BigNumber>; private makeCommitment; /** * Reveals if the name is ready to be registered by calling register function. * @param hash the commitment hash */ canReveal(hash: string): Promise<boolean>; /** * Register a domain * @param label the name to register * @param owner the owner of the name * @param secret the commitment secret * @param duration the duration to register the name * @param amount the amount for the name registration * @param addr the address to set for the name resolution */ private registerOp; register(label: string, owner: string, secret: string, duration: BigNumber, amount: BigNumber, addr?: string): Promise<string>; /** * Renew an already purchased domain * @param label the name to be renewed * @param duration the duration to renew the name * @param amount the amount for the name renewal */ renew(label: string, duration: BigNumber, amount: BigNumber): Promise<string>; renewOp(label: string, duration: BigNumber, amount: BigNumber): OperationResult<string>; /** * Commit and register a domain * @param label the name to register * @param owner the owner of the name * @param duration the duration to register the name * @param amount the amount for the name registration * @param addr the address to set for the name resolution */ private commitAndRegisterOp; private getPartnerConfiguration; private getPartnerManagerContract; /** * Register a domain * @param label the name to register * @param owner the owner of the name * @param duration the duration to register the name * @param amount the amount for the name registration * @param addr the address to set for the name resolution */ commitAndRegister(label: string, owner: string, duration: BigNumber, amount: BigNumber, addr?: string): Promise<{ commitHash: string; commitSecret: string; registerTxHash: string; }>; } export {};