import { IEncrypt, IJingchangWalletModel, IKeypairsModel, IKeystoreModel, IKeyPair } from "./types"; /** * api of jingchang wallet * * @export * @class JingchangWallet */ export default class JingchangWallet { static readonly version = "1.0"; private static readonly _name; private static readonly _walletID; private _jingchangWallet; /** * if the value is true, support save multiple wallet keystore for each type, otherwise only support one. * * @private * @type {boolean} * @memberof JingchangWallet */ private _multiple; /** * if the value is true, use the default swt keystore's password which be generated in the beginning as password for other type. * * @private * @type {boolean} * @memberof JingchangWallet */ private _samePassword; /** * Creates an instance of JingchangWallet. * @param {IJingchangWalletModel} wallet * @param {boolean} [multiple=false] if the value is true, support save multiple wallet keystore for each type, otherwise only support one. * @param {boolean} [samePassword=true] if the value is true, use the default swt keystore's password which be generated * in the beginning as password for other type. * @memberof JingchangWallet */ constructor(wallet: IJingchangWalletModel, multiple?: boolean, samePassword?: boolean); /** * check jingchang wallet is valid or not * * @static * @param {*} wallet * @returns {boolean} return true if valid. * @memberof JingchangWallet */ static isValid(wallet: any): boolean; /** * create a jingchang wallet * * @static * @param {string} password password for keystore * @param {string} [secret] swtc chain's secret * @param {string} [alias] wallet name * @returns {Promise} resolve jingchang wallet if success. * @memberof JingchangWallet */ static generate(password: string, secret?: string, alias?: string): Promise; /** * get jingchang wallet from local storage * * @static * @returns {(IJingchangWalletModel | null)} return jingchang wallet or null * @memberof JingchangWallet */ static get(): IJingchangWalletModel | null; /** * clear jingchang wallet from local storage * * @static * @memberof JingchangWallet */ static clear(): void; /** * save jingchang wallet to local storage. * * @static * @param {IJingchangWalletModel} wallet * @memberof JingchangWallet */ static save(wallet: IJingchangWalletModel): void; /** * derive key pair with secret * * @static * @param {string} secret * @param {string} [chain="swt"] * @returns {IKeyPair} for privateKey, it's length should be 64 when call `decryptWithPrivateKey`, but the origin derived * privateKey's length is 66 that contains prefix `00` for `secp256k1` or `ED` for `ed25519`, so removed it. * @memberof JingchangWallet */ static deriveKeyPair(secret: string, chain?: string): IKeyPair; /** * encrypt data with public key * * @static * @param {string} message * @param {string} publicKey * @returns {Promise} * @memberof JingchangWallet */ static encryptWithPublicKey(message: string, publicKey: string): Promise; /** * decrypt data with private key * * @static * @param {IEncrypt} message * @param {string} privateKey the privateKey's length should be 64 * @returns {Promise} * @memberof JingchangWallet */ static decryptWithPrivateKey(message: IEncrypt, privateKey: string): Promise; /** * get wallets from jingchang wallet * * @static * @param {IJingchangWalletModel} jcWallet * @returns {Array} return wallets if valid, otherwise return empty array. * @memberof JingchangWallet */ static getWallets(keystore: IJingchangWalletModel): Array; /** * set property of _jingchangWallet * * @param {IJingchangWalletModel} wallet * @memberof JingchangWallet */ setJingchangWallet(wallet: IJingchangWalletModel): void; /** * get default wallet's keystore address for each type * * @param {string} [type="swt"] * @returns {Promise} resolve address if success * @memberof JingchangWallet */ getAddress(type?: string): Promise; /** * get default wallet keystore with type * * @param {string} [type="swt"] * @returns {Promise} resolve default wallet keystore if success. * @memberof JingchangWallet */ getWalletWithType(type?: string): Promise; /** * get wallet keystore with address * * @param {string} address * @returns {Promise} resolve wallet keystore if success. * @memberof JingchangWallet */ getWalletWithAddress(address: string): Promise; /** * check if has default wallet for each type * * @param {string} [type="swt"] * @returns {boolean} return true if has default * @memberof JingchangWallet */ hasDefault(type?: string): boolean; /** * get the default wallet keystore's secret with type. * * @param {string} password * @param {string} [type="swt"] * @returns {Promise} * @memberof JingchangWallet */ getSecretWithType(password: string, type?: string): Promise; /** * get the wallet keystore's secret with address. * * @param {string} password * @param {string} address * @returns {Promise} * @memberof JingchangWallet resolve secret if success. */ getSecretWithAddress(password: string, address: string): Promise; /** * change the whole jingchang wallet password, if you set property of _samePassword is false, will throw an error * * @param {string} oldPassword * @param {string} newPassword * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ changeWholePassword(oldPassword: string, newPassword: string): Promise; /** * change the keystore password with address, if you set the property of _samePassword is true, will throw an error * * @param {string} address * @param {string} oldPassword * @param {string} newPassword * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ changePasswordWithAddress(address: string, oldPassword: string, newPassword: string): Promise; /** * replace keystore, if forget password * * @param {string} secret * @param {string} password * @param {(secret: string) => string} retriveSecret * @returns {Promise} * @memberof JingchangWallet */ replaceKeystore(secret: string, password: string, retriveSecret: (secret: string) => string): Promise; /** * remove default wallet keystore of the given type * * @param {string} [type="swt"] * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ removeWalletWithType(type?: string): Promise; /** * remove wallet keystore of the given address * * @param {string} address * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ removeWalletWithAddress(address: string): Promise; /** * set defalut wallet keystore for each type * * @param {string} address * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ setDefaultWallet(address: string): Promise; /** * import secret * * @param {string} secret * @param {string} password * @param {string} type * @param {(secret: string) => string} retriveSecret * @param {string} [alias] wallet name * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ importSecret(secret: string, password: string, type: string, retriveSecret: (secret: string) => string, alias?: string): Promise; /** * find wallet keystore according to filter function * * @protected * @param {(wallet: IKeystoreModel) => boolean} filter * @returns {IKeystoreModel} return wallet keystore if existent, otherwise throw `keystore is invalid` if the jingchang wallet is invalid * or throw `wallet is empty` if the wallet isn't existent * @memberof JingchangWallet */ protected findWallet(filter: (wallet: IKeystoreModel) => boolean): IKeystoreModel; /** * encrypt data * * @protected * @param {string} password * @param {IKeypairsModel} keypairs * @returns {IKeystoreModel} * @memberof JingchangWallet */ protected getEncryptData(password: string, keypairs: IKeypairsModel): Promise; /** * save wallet keystore to jingchang wallet * * @private * @param {string} password * @param {IKeypairsModel} keypairs * @returns {Promise} resolve new jingchang wallet if success * @memberof JingchangWallet */ private saveWallet; }