UNPKG

@harmony-js/core

Version:

harmony core package

135 lines 3.75 kB
/** * @packageDocumentation * @module harmony-core */ import { HttpProvider, WSProvider, Messenger, ShardingItem } from '@harmony-js/network'; import { Transaction, TransactionFactory } from '@harmony-js/transaction'; import { Blockchain } from './blockchain'; import { ContractFactory } from '@harmony-js/contract'; import { HarmonyConfig } from './util'; /** @hidden */ export declare enum ExtensionType { MathWallet = "MathWallet", OneWallet = "OneWallet" } /** @hidden */ export interface ExtensionAccount { address: 'string'; name: 'string'; } /** @hidden */ export interface ExtensionNetwork { chain_url: string; net_version: number; } /** @hidden */ export interface ExtensionInterface { signTransaction: (transaction: Transaction, updateNonce: boolean, encodeMode: string, blockNumber: string) => Promise<Transaction>; getAccount: () => Promise<ExtensionAccount>; forgetIdentity: () => Promise<void>; messenger?: Messenger; version: string; isMathWallet?: boolean; isOneWallet?: boolean; network: ExtensionNetwork; } export declare class HarmonyExtension { /**@ignore*/ extensionType: ExtensionType | null; /**@ignore*/ wallet: ExtensionInterface; /**@ignore*/ provider: HttpProvider | WSProvider; /**@ignore*/ messenger: Messenger; /**@ignore*/ blockchain: Blockchain; /**@ignore*/ transactions: TransactionFactory; /**@ignore*/ contracts: ContractFactory; /**@ignore*/ crypto: any; /**@ignore*/ utils: any; /**@ignore*/ defaultShardID?: number; /** * Create an blockchain instance support wallet injection * * @param wallet could be MathWallet or OneWallet instance * @param config (optional), using default `Chain_Id` and `Chain_Type` * * @example * ```javascript * // Using Mathwallet instance * export const initEx = async() => { * hmyEx = new HarmonyExtension(window.harmony); * } * // Using OneWallet instance * export const initEx = async() => { * hmyEx = new HarmonyExtension(window.onewallet); * } * ``` */ constructor(wallet: ExtensionInterface, config?: HarmonyConfig); /** * Will change the provider for its module. * * @param provider a valid provider, you can replace it with your own working node * * @example * ```javascript * const tmp = hmyEx.setProvider('http://localhost:9500'); * ``` */ setProvider(provider: string | HttpProvider | WSProvider): void; /** * Change the Shard ID * * @example * ``` * hmyEx.setShardID(2); * ``` */ setShardID(shardID: number): void; isExtension(wallet: ExtensionInterface): void; /** * Get the wallet account * * @example * ```javascript * const account = hmyEx.login(); * console.log(account); * ``` */ login(): Promise<ExtensionAccount>; /** * Log out the wallet account * * @example * ```javascript * hmyEx.logout(); * ``` */ logout(): Promise<void>; /** * Set the sharding Structure * * @param shardingStructures The array of information of sharding structures * * @example * ```javascript * hmyEx.shardingStructures([ * {"current":true,"http":"http://127.0.0.1:9500", * "shardID":0,"ws":"ws://127.0.0.1:9800"}, * {"current":false,"http":"http://127.0.0.1:9501", * "shardID":1,"ws":"ws://127.0.0.1:9801"} * ]); * ``` */ shardingStructures(shardingStructures: ShardingItem[]): void; /**@ignore*/ private setMessenger; } //# sourceMappingURL=harmonyExtension.d.ts.map