import { BIP44Chain, BIP44ChainMap, getBIP44Chain } from "./constant"; import { IBIP44Path, IHDPlugin, IKeyPair, IMnemonic } from "../types"; export { BIP44Chain, BIP44ChainMap, getBIP44Chain }; export declare class HDWallet { private _secret; private _mnemonic; private _address; private _keypair; private _path; /** * generate hd wallet * * @param {any} opt options of generate, like: * { * mnemonic: "world list", // optional * // see also:bip39 https://github.com/bitcoinjs/bip39/tree/master/ts_src/wordlists * // language attribute appears with mnemonic attribute * language: english default/chinese_simplified/... * secret: "secret string", // optional, default this coding rules of SWTC chain * keypair: {privateKey: "xxxx", publicKey: "xxxx"} * } * way of create hd wallet * 1. {mnemonic: "xxx", language:"english"} * 2. {secret: "xxxx"} * 3. {keypair: {....}, path:{....}} * @returns {object} return hd wallet object */ constructor(opt: any); /** * generate mnemonic * * @static * @param {number} len strength of random bytes, default 128 * @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39 * @returns {string} return mnemonic string, spilt by blank */ static generateMnemonic: (len?: number, language?: string) => string; /** * get secret from mnemonic, obey encode rule base58 for jingtum * * @static * @param {string} mnemonic mnemonic words * @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39 * @returns {string} return secret string */ static getSecretFromMnemonic: (mnemonic: string, language?: string) => string; /** * get mnemonic from secret, obey encode rule base58 for jingtum * * @static * @param {string} secret secret string * @param {string} language localized word list, default is english. see also https://github.com/bitcoinjs/BIP39 * @returns {string} return mnemonic word list */ static getMnemonicFromSecret: (secret: string, language?: string) => string; /** * get keypair from secret * * @static * @param {string} secret secret string * @returns {object} return keypair object */ static getKeypairFromSecret: (secret: string) => any; /** * get hd wallet key pair * * @static * @param {string} rootSecret root secret * @param {number} chain chain index number * @param {number} account bip44 account index for purpose * @param {number} index bip44 last level index * @returns {IKeyPair} return keypair object */ static getHDKeypair: (rootSecret: string, chain: number, account: number, index: number, change?: number) => IKeyPair; /** * generate hd wallet * * @static * @param {any} opt options of generate, like: * { * len: 128/160/192/224/256, default is 128, determines number of mnemonic word * language: english default/chinese_simplified/chinese_traditional/czech/korean/french/japanese/... see also:bip39 https://github.com/bitcoinjs/bip39/tree/master/ts_src/wordlists * } * @returns {object} return hd wallet object */ static generate: (opt: any) => HDWallet; /** * create hd wallet from secret * * @static * @param {string} secret secret string * @returns {object} return hd wallet object */ static fromSecret: (secret: string) => HDWallet; /** * create hd wallet from mnemonic * * @static * @param {IMnemonic} mnemonic object like * {mnemonic: "abc abc ...", language: "english"} * @returns {object} return hd wallet object */ static fromMnemonic: (mnemonic: IMnemonic) => HDWallet; /** * create hd wallet from keypair * * @static * @param {IKeyPair} keypair object like * {publicKey: "public key...", privateKey: "private key..."} * @returns {object} return hd wallet object */ static fromKeypair: (keypair: IKeyPair) => HDWallet; /** * hd wallet is root or not * * @returns {boolean} return hd wallet root or not */ isRoot: () => boolean; /** * generate hd wallet by derive path, obey BIP44 protocol * * @param {any} opt options of derive, like: * { * chain: BIP44Chain.ETH, //chain code defined in bip44 * account: 0, // account for what purpose * change: 0, // optional attrube,default always 0, for change account after transfer * index: 0, // accout index * } * @returns {object} return hd wallet object */ deriveWallet: (opt: any) => HDWallet; /** * get wallet secret * * @returns {string} return wallet secret */ secret: () => string; /** * get wallet mnemonic * * @returns {IMnemonic} return IMnemonic object */ mnemonic: () => IMnemonic; /** * get chain of hd wallet * * @returns {string} return chain of hd wallet */ chain: () => string; /** * get address of hd wallet * * @returns {string} return address of hd wallet */ address: () => string; /** * check address valid or not * @param {string} address * @returns {boolean} true valid, false invalid */ isValidAddress: (address: string) => boolean; /** * check secret valid or not * * @param {string} secret * @returns {boolean} true valid, false invalid */ isValidSecret: (address: string) => boolean; /** * hash message * * @param {string} message * @returns {string} return hash of message */ hash: (message: string) => string; /** * sign message * @notice how to operate message(raw or hashed) is different in native sdk of different chain * to avoid confusion, we assume that native sdk will automatically hashed message * if not the case of native sdk, we hash this message in lower level(plugin), for example ethereum sdk * @param {string} message * @returns {string} return signature string */ sign: (message: string) => string; /** * verify signature valid or not * * @param {string} message origin message * @param {string} signature signature * @param {string} address account which sign * @param {IKeyPair} keypair keypair object, usually to provide public key, private key not required * * @returns {boolean} true valid, false invalid */ verify: (messgae: string, signature: string, address?: string, keypair?: IKeyPair) => boolean; /** * recover address/account from signature * * @param {string} message origin message * @param {string} signature signature * * @returns {string} return address */ recover: (messgae: string, signature: string) => string | void; /** * get specified chain wallet api * * @returns {IHDPlugin} return hd plugin object */ getWalletApi: () => IHDPlugin; /** * get keypair of hd wallet * * @returns {IKeyPair} return keypair of message */ keypair: () => IKeyPair; /** * get path of hd wallet * * @returns {IBIP44Path} return path of wallet */ path: () => IBIP44Path; /** * set keypair * @param {IKeyPair} keypair */ setKeypair: (keypair: IKeyPair) => void; }