ethereumjs / ethereumjs-wallet

Utilities for handling Ethereum keys
MIT License
986 stars 295 forks source link

Unable to Generate Same Account from MetaMask Mnemonic #68

Closed theomarshanti closed 6 years ago

theomarshanti commented 6 years ago

Hello - I've been unable to generate the account I see in MetaMask from the same Mnemonic. Due to the lack of documentation, I may be misunderstanding how to do so. I have tried running the following in a Truffle Node console in my Terminal:

1) var seed = bip39.mnemonicToSeed(mnemonic) var wallet_test = hdkey.fromMasterSeed(seed) wallet_test.derivePath("m/44'/60'/0'/0/0") wallet_test.derivePath("m/44'/60'/0'/0")

2) var seed = bip39.mnemonicToSeedHex(mnemonic) var wallet_test = hdkey.fromMasterSeed(seed) wallet_test.derivePath("m/44'/60'/0'/0/0") wallet_test.derivePath("m/44'/60'/0'/0")

But none of them have outputted the same account I have in MetaMask. Can anyone point out why this doesn't work please?

If it helps, this does work with truffle-hd-wallet-provider

Alexintosh commented 6 years ago

Using path m/44'/60'/0'/0/0, it works fine for me. I've been also double checking with MEW.

This is my code:

const defaulHDpath = "m/44'/60'/0'/0/0"; // Compatible with Jaxx, Metamask, Exodus, imToken, TREZOR (ETH) & Digital Bitbox
test('ethereumjs-wallet/hdkey produces same address given a mnemonic', () => {    
    const addressShouldBe = "0x3ff386fe1a669bd11d116ffca3d53d356cea6f06";
    const seed = bip39.mnemonicToSeed(mnemonic.join(' '));
    const wallet = HDKEY.fromMasterSeed(seed).derivePath(defaulHDpath).getWallet();
    expect(wallet.getAddressString()).toBe(addressShouldBe);
});
theomarshanti commented 6 years ago

Thank you so much @Alexintosh - it worked

TCRetriever commented 2 years ago

https://cyberbump.net/metamask-ronin-and-binance-wallet-password-recovery-using-btcrecover-lost-or-forgotten-password/