@aeternity/aepp-sdk
Version:
SDK for the æternity blockchain
139 lines (138 loc) • 4.45 kB
TypeScript
import Node from './Node.js';
import AccountBase from './account/Base.js';
import { Encoded } from './utils/encoder.js';
import CompilerBase from './contract/compiler/Base.js';
import AeSdkMethods, { OnAccount, AeSdkMethodsOptions, WrappedOptions } from './AeSdkMethods.js';
type NodeInfo = Awaited<ReturnType<Node['getNodeInfo']>> & {
name: string;
};
/**
* Basic AeSdk class implements:
* - node selector,
* - integrated compiler support,
* - wrappers of account methods mapped to the current account.
*/
export default class AeSdkBase extends AeSdkMethods {
#private;
pool: Map<string, Node>;
selectedNodeName?: string;
/**
* @param options - Options
* @param options.nodes - Array of nodes
*/
constructor({ nodes, ...options }?: AeSdkMethodsOptions & {
nodes?: Array<{
name: string;
instance: Node;
}>;
});
get compilerApi(): CompilerBase;
get api(): Node;
/**
* Add Node
* @param name - Node name
* @param node - Node instance
* @param select - Select this node as current
* @example
* ```js
* // add and select new node with name 'testNode'
* aeSdkBase.addNode('testNode', new Node({ url }), true)
* ```
*/
addNode(name: string, node: Node, select?: boolean): void;
/**
* Select Node
* @param name - Node name
* @example
* nodePool.selectNode('testNode')
*/
selectNode(name: string): void;
/**
* Check if you have selected node
* @example
* nodePool.isNodeConnected()
*/
isNodeConnected(): this is AeSdkBase & {
selectedNodeName: string;
};
protected ensureNodeConnected(): asserts this is AeSdkBase & {
selectedNodeName: string;
};
/**
* Get information about node
* @example
* ```js
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
* ```
*/
getNodeInfo(): Promise<NodeInfo>;
/**
* Get array of available nodes
* @example
* nodePool.getNodesInPool()
*/
getNodesInPool(): Promise<NodeInfo[]>;
addresses(): Encoded.AccountAddress[];
/**
* Resolves an account
* @param account - ak-address, instance of AccountBase, or keypair
*/
_resolveAccount(account?: OnAccount): AccountBase;
get address(): Encoded.AccountAddress;
/**
* Sign data blob
* @param data - Data to sign
* @param options - Options
* @deprecated Use `unsafeSign` method instead
*/
sign(data: string | Uint8Array, options?: {
onAccount?: OnAccount;
}): Promise<Uint8Array>;
/**
* Sign data blob
* @param data - Data to sign
* @param options - Options
*/
unsafeSign(data: string | Uint8Array, { onAccount, ...options }?: {
onAccount?: OnAccount;
}): Promise<Uint8Array>;
/**
* Sign encoded transaction
* @param tx - Transaction to sign
* @param options - Options
*/
signTransaction(tx: Encoded.Transaction, { onAccount, ...options }?: {
onAccount?: OnAccount;
} & Parameters<AccountBase['signTransaction']>[1]): Promise<Encoded.Transaction>;
/**
* Sign message
* @param message - Message to sign
* @param options - Options
*/
signMessage(message: string, { onAccount, ...options }?: {
onAccount?: OnAccount;
} & Parameters<AccountBase['signMessage']>[1]): Promise<Uint8Array>;
/**
* Sign typed data
* @param data - Encoded data to sign
* @param aci - Type of data to sign
* @param options - Options
*/
signTypedData(data: Encoded.ContractBytearray, aci: Parameters<AccountBase['signTypedData']>[1], { onAccount, ...options }?: {
onAccount?: OnAccount;
} & Parameters<AccountBase['signTypedData']>[2]): Promise<Encoded.Signature>;
/**
* Sign delegation, works only in Ceres
* @param delegation - Delegation to sign
* @param options - Options
*/
signDelegation(delegation: Encoded.Bytearray, { onAccount, ...options }?: {
onAccount?: OnAccount;
} & Parameters<AccountBase['signDelegation']>[1]): Promise<Encoded.Signature>;
/**
* The same as AeSdkMethods:getContext, but it would resolve ak_-prefixed address in
* `mergeWith.onAccount` to AccountBase.
*/
getContext(mergeWith?: AeSdkMethodsOptions): AeSdkMethodsOptions & WrappedOptions;
}
export {};