import Decimal from 'decimal.js'; import { AccountData, Auth, IKey } from './auth'; import { SignDocResponse } from './wallet'; export type BroadcastMode = 'broadcast_tx_async' | 'broadcast_tx_sync' | 'broadcast_tx_commit'; /** * HttpEndpoint is a type that represents an HTTP endpoint. */ export interface HttpEndpoint { url: string; headers: Record; } export declare function isHttpEndpoint(endpoint: unknown): endpoint is HttpEndpoint; export interface Price { amount: Decimal; denom: string; } /** * SignerConfig is a configuration object for a signer. */ export interface SignerConfig { /** * possible changes for publicKey generation */ publicKey: { /** * compressed or uncompressed */ isCompressed: boolean; /** * method to hash public key */ hash(publicKey: IKey): IKey; }; message: { /** * method to hash arbitrary message in methods with `Arbitrary` in name. i.e. * - signArbitrary * - broadcastArbitrary */ hash(data: Uint8Array): Uint8Array; }; } /** * BroadcastOptions is an object that contains options for broadcasting a transaction. */ export interface BroadcastOptions { /** * whether to check the tx result after broadcasting. * if checkTx && deliverTx are true, it's equivalent to broadcast_tx_commit. * else if checkTx is true, it's equivalent to broadcast_tx_sync. * else if checkTx is false, it's equivalent to broadcast_tx_async. */ checkTx?: boolean; /** * whether to check the tx is delivered after broadcasting. * if checkTx && deliverTx are true, it's equivalent to broadcast_tx_commit. */ deliverTx?: boolean; /** * timeout in milliseconds for checking broadcast_tx_commit result. */ timeoutMs?: number; /** * polling interval in milliseconds for checking broadcast_tx_commit result. */ pollIntervalMs?: number; /** * whether to use legacy broadcast_tx_commit result. */ useLegacyBroadcastTxCommit?: boolean; } /** * the response after creating sign doc. */ export interface CreateDocResponse { /** * transaction object with or without signature. */ tx: Tx; /** * document to be signed. */ doc: Doc; } /** * the response after signing a document. */ export interface SignResponse extends CreateDocResponse { /** * broadcast the transaction. */ broadcast: (options?: BroadcastOpts) => Promise; } /** * IDocSigner is an interface for signing document. * @template TDoc - document type * @template TArgs - arguments type */ export interface IDocSigner> { /** * sign document. * @param doc - document to be signed * @param args - arguments for signing */ signDoc(doc: TDoc, args?: TArgs): Promise; } /** * UniSigner is a generic interface for signing and broadcasting transactions. * It is used to abstract the signing and broadcasting process for different chains. * @template SignArgs - arguments for sign method * @template Tx - transaction type * @template Doc - sign doc type * @template AddressResponse - address type * @template BroadcastResponse - response type after broadcasting a transaction * @template BroadcastOpts - options for broadcasting a transaction * @template SignDocResp - response type after signing a document */ export interface UniSigner> { publicKey?: IKey; /** * to get printable address(es) */ getAddress(): Promise; /** * sign arbitrary data in bytes */ signArbitrary(data: Uint8Array): IKey | Promise; /** * sign document */ signDoc(doc: Doc): SignDocResp | Promise; /** * broadcast arbitrary data in bytes */ broadcastArbitrary(data: Uint8Array, options?: BroadcastOpts): Promise; /** * build signed transaction document based on sign arguments. * @argument args - arguments for signing. e.g. messages, fee, memo, etc. */ sign(args: SignArgs): Promise>; /** * sign and broadcast transaction based on sign arguments. */ signAndBroadcast(args: SignArgs, options?: BroadcastOpts): Promise; /** * broadcast a signed transaction. */ broadcast(tx: Tx, options?: BroadcastOpts): Promise; } /** * BaseSigner is a base class for signers */ export declare class BaseSigner { protected _auth: Auth; protected _config: SignerConfig; constructor(auth: Auth, config: SignerConfig); get auth(): Auth; get config(): SignerConfig; get publicKey(): IKey; setAuth(auth: Auth): void; /** * default common implementation for sign arbitrary data in bytes. */ signArbitrary(data: Uint8Array): IKey; } /** * SIGN_MODE for IGenericOfflineSigner */ export declare const SIGN_MODE: { /** * SIGN_MODE for (cosmos_)direct */ DIRECT: string; /** * SIGN_MODE for (cosmos_)amino */ AMINO: string; /** * SIGN_MODE for ethereum_tx */ ETHEREUM_TX: string; }; /** * IGenericOfflineSigner is an interface for offline signers. */ export interface IGenericOfflineSigner, TAcctData = AccountData> { /** * sign mode */ signMode: string; /** * get accounts * @returns a list of accounts */ getAccounts: () => Promise; /** * sign document * @param signerAddress * @param signDoc * @returns */ sign: (args: TSignArgs) => Promise; } export interface IGenericOfflineSignArgs { signerAddress: TAddr; signDoc: TDoc; }