How to use BIP39 test vectors?

0

On the page of BIP39 specs there's test vector array from Trezor link. It looks like this:

["ffffffffffffffffffffffffffffffff",

 "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong",

 "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069",

 "xprv9s21ZrQH143K2V4oox4M8Zmhi2Fjx5XK4Lf7GKRvPSgydU3mjZuKGCTg7UPiBUD7ydVPvSLtg9hjp7MQTYsW67rZHAXeccqYqrsx8LcXnyd"
],

When I try to use any of these mnemonic phrases I can't get matching xpriv... form any of these samples using Bip39 JS lib.

For example:

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());

returns totally different results

Seed = b6a6d8921942dd9806607ebc2750416b289adea669198769f2e15ed926c3aa92bf88ece232317b4ea463e84b0fcd3b53577812ee449ccc448eb45e6f544e25b6
Bip32 Root key = xprv9s21ZrQH143K2PfMvkNViFc1fgumGqBew45JD8SxA59Jc5M66n3diqb92JjvaR61zT9P89Grys12kdtV4EFVo6tMwER7U2hcUmZ9VfMYPLC

How can I get these c5525... and xpriv... and what is it exactly?

UPDATE:

as user3074620 suggested, I tried to use 'TREZOR' password, as it's works!

here's code to play someone is interested.

lebed2045

Posted 2019-03-14T01:33:37.517

Reputation: 25

Answers

0

You must add 'TREZOR' to your second line:

const seed = Bip39.mnemonicToSeed(MNEMONIC, 'TREZOR');

Then it should work.

You can see this in the BIP39 test cases in the BitcoinJS repo:

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) })

user3074620

Posted 2019-03-14T01:33:37.517

Reputation: 176

0

Could not resist providing the even more succinct results below that uses simple UNIX and bitcoin-explorer commands:

% echo "ffffffffffffffffffffffffffffffff" | bx mnemonic-new

zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong

% echo "ffffffffffffffffffffffffffffffff" | bx mnemonic-new | bx mnemonic-to-seed -p "TREZOR"

ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069

% echo "ffffffffffffffffffffffffffffffff" | bx mnemonic-new | bx mnemonic-to-seed -p "TREZOR" | bx hd-new

xprv9s21ZrQH143K2V4oox4M8Zmhi2Fjx5XK4Lf7GKRvPSgydU3mjZuKGCTg7UPiBUD7ydVPvSLtg9hjp7MQTYsW67rZHAXeccqYqrsx8LcXnyd

skaht

Posted 2019-03-14T01:33:37.517

Reputation: 2 588