UNPKG

@pokt-network/pocket-js

Version:

Pocket-js core package with the main functionalities to interact with the Pocket Network.

114 lines (113 loc) 6.07 kB
/// <reference types="node" /> import { Configuration } from "./config"; import { RelayHeaders, RelayResponse } from "./rpc/models"; import { SessionManager } from "./session/session-manager"; import { Node, RPC, IRPCProvider, RpcError } from "./rpc"; import { Keybase } from "./keybase/keybase"; import { PocketAAT } from "@pokt-network/aat-js"; import { TransactionSigner, ITransactionSender, IKVStore } from "./"; import { ConsensusRelayResponse } from "./rpc/models/output/consensus-relay-response"; import { ConsensusNode } from "./rpc/models/consensus-node"; import { ChallengeResponse } from "./rpc/models/output/challenge-response"; import { BaseProfiler } from "./utils/base-profiler"; import { ProtoTxDecoder } from "./transactions/factory/proto-tx-decoder"; /** * * HTTPMethod enum with the possible Staking status values */ export declare enum HTTPMethod { POST = "POST", GET = "GET", DELETE = "DELETE", NA = "" } /** * * * @class Pocket */ export declare class Pocket { readonly configuration: Configuration; readonly keybase: Keybase; readonly sessionManager: SessionManager; private innerRpc?; private profiler; /** * Creates an instance of Pocket. * @param {URL} dispatchers - Array holding the initial dispatcher url(s). * @param {IRPCProvider} rpcProvider - Provider which will be used to reach out to the Pocket Core RPC interface. * @param {Configuration} configuration - Configuration object. * @param {IKVStore} store - Save data using a Key/Value relationship. This object save information in memory. * @param {BaseProfiler} profiler - BaseProfiler implementation for metrics, defaults to an empty NoOpProfiler. * @memberof Pocket */ constructor(dispatchers: URL[], rpcProvider?: IRPCProvider, configuration?: Configuration, store?: IKVStore, profiler?: BaseProfiler); /** * Returns the Session Manager's routing table dispatcher's count * @returns {Number} - Dispatcher's count. * @memberof Pocket */ getDispatchersCount(): number; /** * Creates a new instance of RPC if you set an IRPCProvider or return the previous existing instance * @param {IRPCProvider} rpcProvider - Provider which will be used to reach out to the Pocket Core RPC interface. * @returns {RPC} - A RPC object. * @memberof Pocket */ rpc(rpcProvider?: IRPCProvider): RPC | undefined; /** * * Sends a Relay Request to multiple nodes for manual consensus * @param {string} data - string holding the json rpc call. * @param {string} blockchain - Blockchain hash. * @param {PocketAAT} pocketAAT - Pocket Authentication Token. * @param {Configuration} configuration - Pocket configuration object. * @param {RelayHeaders} headers - (Optional) An object holding the HTTP Headers. * @param {HTTPMethod} method - (Optional) HTTP method for REST API calls. * @param {string} path - (Optional) REST API path. * @param {Node} node - (Optional) Session node which will receive the Relay. * @returns {ConsensusRelayResponse | ChallengeResponse | Error} - A Consensus Relay Response object, Challenge response or error. * @memberof Pocket */ sendConsensusRelay(data: string, blockchain: string, pocketAAT: PocketAAT, configuration?: Configuration, headers?: RelayHeaders, method?: HTTPMethod, path?: string, node?: Node): Promise<ConsensusRelayResponse | ChallengeResponse | RpcError>; /** * * Sends a Relay Request * @param {string} data - string holding the json rpc call. * @param {string} blockchain - Blockchain hash. * @param {PocketAAT} pocketAAT - Pocket Authentication Token. * @param {Configuration} configuration - Pocket configuration object. * @param {RelayHeaders} headers - (Optional) An object holding the HTTP Headers. * @param {HTTPMethod} method - (Optional) HTTP method for REST API calls. * @param {string} path - (Optional) REST API path. * @param {Node} node - (Optional) Session node which will receive the Relay. * @param {boolean} consensusEnabled - (Optional) True or false if the relay will be sent to multiple nodes for consensus, default is false. * @returns {RelayResponse} - A Relay Response object. * @memberof Pocket */ sendRelay(data: string, blockchain: string, pocketAAT: PocketAAT, configuration?: Configuration, headers?: RelayHeaders, method?: HTTPMethod, path?: string, node?: Node, consensusEnabled?: boolean, requestID?: string): Promise<RelayResponse | ConsensusNode | RpcError>; /** * Creates an ITransactionSender given a private key * @param {Buffer | string} privateKey * @returns {ITransactionSender} - Interface with all the possible MsgTypes in a Pocket Network transaction and a function to submit the transaction to the network. * @memberof Pocket */ withPrivateKey(privateKey: Buffer | string): ITransactionSender | Error; /** * Creates an ITransactionSender given an already imported account into this instanc keybase * @param {Buffer | string} address - address of the account * @param {string} passphrase - passphrase for the account * @returns {ITransactionSender} - Interface with all the possible MsgTypes in a Pocket Network transaction and a function to submit the transaction to the network. * @memberof Pocket */ withImportedAccount(address: Buffer | string, passphrase: string): Promise<ITransactionSender | Error>; /** * Creates an ITransactionSender given a {TransactionSigner} function * @param {TransactionSigner} txSigner - Function which will sign the transaction bytes * @returns {ITransactionSender} - Interface with all the possible MsgTypes in a Pocket Network transaction and a function to submit the transaction to the network. * @memberof Pocket */ withTxSigner(txSigner: TransactionSigner): ITransactionSender | Error; withProtoTxDecoder(): ProtoTxDecoder | Error; } export * from "@pokt-network/aat-js";