Mnemonic-Seed
如何使用 BIP39 測試向量?
在BIP39 規範頁面上有來自 Trezor連結的測試向量數組。它看起來像這樣:
["ffffffffffffffffffffffffffffffff", "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069", "xprv9s21ZrQH143K2V4oox4M8Zmhi2Fjx5XK4Lf7GKRvPSgydU3mjZuKGCTg7UPiBUD7ydVPvSLtg9hjp7MQTYsW67rZHAXeccqYqrsx8LcXnyd" ],
當我嘗試使用任何這些助記詞時,我無法使用Bip39 JS lib
xpriv...
從任何這些範例中獲得匹配。例如:
const MNEMONIC = "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong"; const seed = Bip39.mnemonicToSeed(MNEMONIC); console.log("Seed =", seed.toString("hex")); const rootNode = Bip32.fromSeed(seed, Bitcoin.networks.bitcoin); console.log("Bip32 Root key =", rootNode.toBase58());
返回完全不同的結果
Seed = b6a6d8921942dd9806607ebc2750416b289adea669198769f2e15ed926c3aa92bf88ece232317b4ea463e84b0fcd3b53577812ee449ccc448eb45e6f544e25b6 Bip32 Root key = xprv9s21ZrQH143K2PfMvkNViFc1fgumGqBew45JD8SxA59Jc5M66n3diqb92JjvaR61zT9P89Grys12kdtV4EFVo6tMwER7U2hcUmZ9VfMYPLC
我怎樣才能得到這些
c5525...
,xpriv...
它到底是什麼?更新:
正如user3074620建議的那樣,我嘗試使用“TREZOR”密碼,因為它有效!
這是玩有人感興趣的程式碼。
您必須添加
'TREZOR'
到您的第二行:
const seed = Bip39.mnemonicToSeed(MNEMONIC, 'TREZOR');
然後它應該工作。
您可以在 BitcoinJS repo 的 BIP39 測試案例中看到這一點:
<https://github.com/bitcoinjs/bip39/blob/4fce199e73f7ab68bdf9f7382dc10f7e1adaa499/test/index.js#L13-L33>
function testVector (description, wordlist, password, v, i) { var ventropy = v[0] var vmnemonic = v[1] var vseedHex = v[2] test('for ' + description + '(' + i + '), ' + ventropy, function (t) { t.plan(5) t.equal(bip39.mnemonicToEntropy(vmnemonic, wordlist), ventropy, 'mnemonicToEntropy returns ' + ventropy.slice(0, 40) + '...') t.equal(bip39.mnemonicToSeedHex(vmnemonic, password), vseedHex, 'mnemonicToSeedHex returns ' + vseedHex.slice(0, 40) + '...') t.equal(bip39.entropyToMnemonic(ventropy, wordlist), vmnemonic, 'entropyToMnemonic returns ' + vmnemonic.slice(0, 40) + '...') function rng () { return Buffer.from(ventropy, 'hex') } t.equal(bip39.generateMnemonic(undefined, rng, wordlist), vmnemonic, 'generateMnemonic returns RNG entropy unmodified') t.equal(bip39.validateMnemonic(vmnemonic, wordlist), true, 'validateMnemonic returns true') }) } vectors.english.forEach(function (v, i) { testVector('English', undefined, 'TREZOR', v, i) }) vectors.japanese.forEach(function (v, i) { testVector('Japanese', WORDLISTS.japanese, '㍍ガバヴァぱばぐゞちぢ十人十色', v, i) }) vectors.custom.forEach(function (v, i) { testVector('Custom', WORDLISTS.custom, undefined, v, i) })