Ethereumjs

具有單個助記詞的不同地址

  • October 22, 2018

我正在嘗試在我的程式碼中實現 ethereumjs-wallet 庫。但是當我決定將生成的帳戶與此處使用相同助記符生成的帳戶進行比較時,我得到的帳戶完全不同,即使種子與我的相同。我錯過了什麼?

我這樣做:

Web3 = require('web3');
bip39 = require('bip39')
etherHDkey = require('ethereumjs-wallet/hdkey')
ethUtil = require('ethereumjs-util')

mnemonic = bip39.generateMnemonic()
seedHex = bip39.mnemonicToSeedHex(mnemonic)
HDwallet = etherHDkey.fromMasterSeed(seedHex)
zeroWallet = HDwallet.derivePath("m/44'/60'/0'/0/0").getWallet();
console.log(mnemonic)
console.log(seedHex)
console.log(`Address: ${zeroWallet.getAddressString()}`);
console.log(`Private Key: ${zeroWallet.getPrivateKeyString()}`);

這是輸出:

slogan east ugly dish enable remove economy faint senior pause mention where
db90f73b1f23d449b021739c6c3aa85e47e8e26aa95b1ff6e883773536e6b126e15c34876070bd37befead1fc74057dfce2c6b045e8d4de6146584c96940486f
Address: 0xf298302699395cb4472b74e41427733c0ce6bcff
Private Key: 0x5b1b539ca7edd8e78f2c33fc6d9f1ef0d35db3490de9ed04f92c20bde54fbf48

然後,當我將此助記符插入到此處slogan east ugly dish enable remove economy faint senior pause mention where的相應欄位時,我得到相同的種子,但地址完全不同。

例如,我0x7C373bAD5cF89b5c2730486eF2c1b8E803eD11d5使用相同的路徑m/44'/60'/0'/0/0'而不是預期的0xf298302699395cb4472b74e41427733c0ce6bcff``m/44'/60'/0'/0/0'

這裡有什麼問題?謝謝你。

您的問題出在第 7 行和第 8 行,您將種子十六進制輸入到fromMasterSeed函式中。你應該做的是餵原始種子。當你這樣做時,你最終會得到與 freewallet.org 相同的輸出:

Web3 = require('web3');
bip39 = require('bip39')
etherHDkey = require('ethereumjs-wallet/hdkey')
ethUtil = require('ethereumjs-util')

mnemonic = bip39.generateMnemonic()
seed = bip39.mnemonicToSeed(mnemonic)
HDwallet = etherHDkey.fromMasterSeed(seed)
zeroWallet = HDwallet.derivePath("m/44'/60'/0'/0/0").getWallet();
console.log(mnemonic)
console.log(seed)
console.log(`Address: ${zeroWallet.getAddressString()}`);
console.log(`Private Key: ${zeroWallet.getPrivateKeyString()}`);

輸出:

soldier mechanic sleep gym extend bone bundle price exhaust solar attack whale
<Buffer f0 80 57 49 3c 24 2c 4d 93 d6 c7 77 26 a7 40 37 8b 79 ed 83 8d 61 fb 57 36 43 44 41 69 bb 57 a8 46 21 71 b5 93 de ea 9c 4b 0c ea dd 70 81 cb 8c 8a 33 ... >
Address: 0x666e89cef3d251774f17e82c5a98e3622dd82dd8
Private Key: 0xf0e65787415522d260fce50ddfff4c4506714d58ee39f9a548b0102fa1d3be69

這與 freewallet.org 的輸出相同。

引用自:https://ethereum.stackexchange.com/questions/60988