Skip to content

Instantly share code, notes, and snippets.

@dohaki
Created October 29, 2019 16:33
Show Gist options
  • Select an option

  • Save dohaki/313d4bf3bb5644d4c2c179531cd173f3 to your computer and use it in GitHub Desktop.

Select an option

Save dohaki/313d4bf3bb5644d4c2c179531cd173f3 to your computer and use it in GitHub Desktop.
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
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment