import { Signer } from "./signer"; import { Conflux, Wallet as ConfluxSdkWallet, PrivateKeyAccount } from "js-conflux-sdk"; import Account from "js-conflux-sdk/dist/types/wallet/Account"; export class Wallet extends Signer { networkId: number; cfxWallet: any; account: Account; address: string; cfxClient?: Conflux; constructor(privateKey: string, provider?, networkId: number = 1) { super(provider); this.networkId = networkId; this.account = new PrivateKeyAccount(privateKey, networkId); this.address = this.account.address if (provider !== undefined) { provider.cfxClient.wallet.set(this.account.address, this.account); } } public static createRandom(entropy?: any, networkId: number = 1): Wallet { const cfxWallet = new ConfluxSdkWallet(networkId); const account = cfxWallet.addRandom(); const accountPrivateKey = account["privateKey"]; // return accountPrivateKey; return new Wallet(accountPrivateKey); } public async getAccount(addressOrIndex: string | number = 0): Promise { if (typeof (addressOrIndex) === "string") { return this.getAccountByAddress(addressOrIndex) } else if (typeof (addressOrIndex) === "number") { return this.getAccountByIndex(addressOrIndex) } } }