Created
October 29, 2019 16:33
-
-
Save dohaki/313d4bf3bb5644d4c2c179531cd173f3 to your computer and use it in GitHub Desktop.
Revisions
-
dohaki created this gist
Oct 29, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ import { ethers } from "ethers"; import { EthersWalletData, IdentityWalletData } from "../typings"; import { TL_WALLET_VERSION } from "./TLWallet"; export class WalletFromEthers extends ethers.Wallet { public static fromWalletData( walletData: EthersWalletData | IdentityWalletData ) { const { signingKey } = walletData.meta const { privateKey, mnemonic } = signingKey return new this(privateKey, mnemonic) } public static fromEthers( walletFromEthers: ethers.Wallet ) { const { privateKey, mnemonic } = walletFromEthers return new this(privateKey, mnemonic) } constructor(privateKey: string, mnemonic: string) { const signingKeyFromEthers = new ethers.utils.SigningKey( privateKey ) // @ts-ignore signingKeyFromEthers.mnemonic = mnemonic // @ts-ignore signingKeyFromEthers.path = DEFAULT_DERIVATION_PATH super(signingKeyFromEthers) } public toWalletData(walletType, address) { return { address, version: TL_WALLET_VERSION, type: walletType, meta: { signingKey: { mnemonic: this.mnemonic, privateKey: this.privateKey } } } } }