import { SecretUtils } from "./enigmautils"; import { Log } from "./logs"; import { Coin, CosmosSdkTx, JsonObject, StdTx } from "./types"; export interface CosmosSdkAccount { /** Bech32 account address */ readonly address: string; readonly coins: ReadonlyArray; /** Bech32 encoded pubkey */ readonly public_key: string; readonly account_number: number; readonly sequence: number; } export interface NodeInfo { readonly protocol_version: { readonly p2p: string; readonly block: string; readonly app: string; }; readonly id: string; readonly listen_addr: string; readonly network: string; readonly version: string; readonly channels: string; readonly moniker: string; readonly other: { readonly tx_index: string; readonly rpc_address: string; }; } export interface ApplicationVersion { readonly name: string; readonly server_name: string; readonly client_name: string; readonly version: string; readonly commit: string; readonly build_tags: string; readonly go: string; } export interface NodeInfoResponse { readonly node_info: NodeInfo; readonly application_version: ApplicationVersion; } export interface BlockId { readonly hash: string; } export interface BlockHeader { readonly version: { readonly block: string; readonly app: string; }; readonly height: string; readonly chain_id: string; /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ readonly time: string; readonly last_commit_hash: string; readonly last_block_id: BlockId; /** Can be empty */ readonly data_hash: string; readonly validators_hash: string; readonly next_validators_hash: string; readonly consensus_hash: string; readonly app_hash: string; /** Can be empty */ readonly last_results_hash: string; /** Can be empty */ readonly evidence_hash: string; readonly proposer_address: string; } export interface Block { readonly header: BlockHeader; readonly data: { /** Array of base64 encoded transactions */ readonly txs: ReadonlyArray | null; }; } export interface BlockResponse { readonly block_id: BlockId; readonly block: Block; } interface AuthAccountsResponse { readonly height: string; readonly result: { readonly type: "cosmos-sdk/Account"; readonly value: CosmosSdkAccount; }; } interface ContractHashResponse { readonly height: string; readonly result: string; } declare type WasmResponse = WasmSuccess | WasmError; interface WasmSuccess { readonly height: string; readonly result: T; } interface WasmError { readonly error: string; } export interface TxsResponse { readonly height: string; readonly txhash: string; /** 🤷‍♂️ */ readonly codespace?: string; /** Falsy when transaction execution succeeded. Contains error code on error. */ readonly code?: number; raw_log: string; data: string; logs?: Log[]; readonly tx: CosmosSdkTx; /** The gas limit as set by the user */ readonly gas_wanted?: string; /** The gas used by the execution */ readonly gas_used?: string; readonly timestamp: string; } interface SearchTxsResponse { readonly total_count: string; readonly count: string; readonly page_number: string; readonly page_total: string; readonly limit: string; readonly txs: TxsResponse[]; } export interface PostTxsResponse { readonly height: string; readonly txhash: string; readonly code?: number; readonly raw_log?: string; data: any; /** The same as `raw_log` but deserialized? */ readonly logs?: object; /** The gas limit as set by the user */ readonly gas_wanted?: string; /** The gas used by the execution */ readonly gas_used?: string; } interface EncodeTxResponse { readonly tx: string; } export interface CodeInfo { readonly code_id: number; /** Bech32 account address */ readonly creator: string; /** Hex-encoded sha256 hash of the code stored here */ readonly code_hash: string; readonly source?: string; readonly builder?: string; } export interface CodeDetails extends CodeInfo { /** Base64 encoded raw wasm data */ readonly wasm: any; } export interface ContractInfo { readonly contract_address: string; readonly code_id: number; /** Bech32 account address */ readonly creator: string; readonly label: string; } export interface ContractDetails extends ContractInfo { /** Argument passed on initialization of the contract */ readonly init_msg: object; } declare type RestClientResponse = | NodeInfoResponse | BlockResponse | AuthAccountsResponse | TxsResponse | SearchTxsResponse | PostTxsResponse | EncodeTxResponse | WasmResponse | WasmResponse | WasmResponse | WasmResponse | WasmResponse | WasmResponse; /** * The mode used to send transaction * * @see https://cosmos.network/rpc/#/Transactions/post_txs */ export declare enum BroadcastMode { /** Return after tx commit */ Block = "block", /** Return afer CheckTx */ Sync = "sync", /** Return right away */ Async = "async", } export declare class RestClient { private readonly client; readonly broadcastMode: BroadcastMode; enigmautils: SecretUtils; codeHashCache: Map; /** * Creates a new client to interact with a Cosmos SDK light client daemon. * This class tries to be a direct mapping onto the API. Some basic decoding and normalizatin is done * but things like caching are done at a higher level. * * When building apps, you should not need to use this class directly. If you do, this indicates a missing feature * in higher level components. Feel free to raise an issue in this case. * * @param apiUrl The URL of a Cosmos SDK light client daemon API (sometimes called REST server or REST API) * @param broadcastMode Defines at which point of the transaction processing the postTx method (i.e. transaction broadcasting) returns * @param seed - The seed used to generate sender TX encryption key. If empty will generate random new one */ constructor(apiUrl: string, broadcastMode?: BroadcastMode, seed?: Uint8Array); get(path: string): Promise; post(path: string, params: any): Promise; authAccounts(address: string): Promise; blocksLatest(): Promise; blocks(height: number): Promise; nodeInfo(): Promise; txById(id: string, tryToDecrypt?: boolean): Promise; txsQuery(query: string, tryToDecrypt?: boolean): Promise; /** returns the amino-encoding of the transaction performed by the server */ encodeTx(tx: CosmosSdkTx): Promise; /** * Broadcasts a signed transaction to into the transaction pool. * Depending on the RestClient's broadcast mode, this might or might * wait for checkTx or deliverTx to be executed before returning. * * @param tx a signed transaction as StdTx (i.e. not wrapped in type/value container) */ postTx(tx: StdTx): Promise; listCodeInfo(): Promise; getCode(id: number): Promise; listContractsByCodeId(id: number): Promise; getCodeHashByCodeId(id: number): Promise; getCodeHashByContractAddr(addr: string): Promise; /** * Returns null when contract was not found at this address. */ getContractInfo(address: string): Promise; /** * Makes a smart query on the contract and parses the reponse as JSON. * Throws error if no such contract exists, the query format is invalid or the response is invalid. */ queryContractSmart( contractAddress: string, query: object, addedParams?: object, contractCodeHash?: string, ): Promise; /** * Get the consensus keypair for IO encryption */ getMasterCerts(address: string, query: object): Promise; decryptDataField(dataField: string | undefined, nonces: Array): Promise; decryptLogs(logs: readonly Log[], nonces: Array): Promise; decryptTxsResponse(txsResponse: TxsResponse): Promise; } export {};