Bitcoin Forum
May 05, 2024, 08:25:01 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: BIP 32 - Find xprv from seed and passphrase (bitcore-mnemonic)  (Read 1752 times)
redPanda (OP)
Member
**
Offline Offline

Activity: 65
Merit: 16


View Profile
April 11, 2016, 07:19:05 PM
Merited by ABCbits (2)
 #1

from BIP 47:  https://github.com/trezor/python-mnemonic/blob/master/vectors.json
Code:
passphrase = "TREZOR";
entropy = "00000000000000000000000000000000";
code    = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
seed    = "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04";
xprv    = "xprv9s21ZrQH143K3h3fDYiay8mocZ3afhfULfb5GX8kCBdno77K4HiA15Tg23wpbeF1pLfs1c5SPmYHrEpTuuRhxMwvKDwqdKiGJS9XFKzUsAF";
from entropy and passphrase, I can find code, seed and xprv with bitcore-mnemonic (node.js):
Code:
var Mnemonic = require('bitcore-mnemonic');
mnemonic   = Mnemonic._entropy2mnemonic(new Buffer(entropy, 'hex'), Mnemonic.Words.ENGLISH);
customCode = new Mnemonic(mnemonic);
theSeed    = customCode.toSeed(passphrase);
xprv       = customCode.toHDPrivateKey(passphrase);

Now I would like to use "seed" in BIP 32 with passphrase and find xprv (and mnemonic?) with bitcore-mnemonic.
Is there a way to do that ?
1714897501
Hero Member
*
Offline Offline

Posts: 1714897501

View Profile Personal Message (Offline)

Ignore
1714897501
Reply with quote  #2

1714897501
Report to moderator
1714897501
Hero Member
*
Offline Offline

Posts: 1714897501

View Profile Personal Message (Offline)

Ignore
1714897501
Reply with quote  #2

1714897501
Report to moderator
The Bitcoin network protocol was designed to be extremely flexible. It can be used to create timed transactions, escrow transactions, multi-signature transactions, etc. The current features of the client only hint at what will be possible in the future.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714897501
Hero Member
*
Offline Offline

Posts: 1714897501

View Profile Personal Message (Offline)

Ignore
1714897501
Reply with quote  #2

1714897501
Report to moderator
1714897501
Hero Member
*
Offline Offline

Posts: 1714897501

View Profile Personal Message (Offline)

Ignore
1714897501
Reply with quote  #2

1714897501
Report to moderator
johoe
Full Member
***
Offline Offline

Activity: 217
Merit: 238


View Profile
April 11, 2016, 07:58:33 PM
Last edit: April 11, 2016, 08:13:38 PM by johoe
Merited by ABCbits (1)
 #2

Look for bip 39.  This is from mnemonic words and passphrase to seed.

EDIT: I think I understand, you want to go the other direction?  It's not feasible to find mnemonic words and/or passphrase from an xprv key or seed. PBKDF2 is not invertible.

From seed to xprv is easy, just the last line of your code.  Well, not really but look at the function:

Code:
Mnemonic.prototype.toHDPrivateKey = function(passphrase, network) {
  var seed = this.toSeed(passphrase);
  return bitcore.HDPrivateKey.fromSeed(seed, network);
};

So the last line of that function gives you the xprv from seed.

Donations to 1CF62UFWXiKqFUmgQMUby9DpEW5LXjypU3
redPanda (OP)
Member
**
Offline Offline

Activity: 65
Merit: 16


View Profile
April 12, 2016, 01:29:16 PM
 #3

You're right: I want to do exactly this: given seed and passphrase: get xpriv

from BIP32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki
Code:
Master key generation:
Generate a seed byte sequence S of a chosen length (between 128 and 512 bits; 256 bits is advised) from a (P)RNG.
Calculate I = HMAC-SHA512(Key = "Bitcoin seed", Data = S)
Split I into two 32-byte sequences, I_L and I_R.
Use parse256(I_L) as master secret key, and I_R as master chain code.
xpriv is essentially a serialization of the master secret key (I_L) and the master chain code (I_R).

So the function you gave me seems the right one BUT I have 2 problems:

1) if I do in node.js

var Mnemonic = require('bitcore-mnemonic');
var bitcore = require('bitcore');

I have the following error:
Code:
Error: More than one instance of bitcore found with versions: v0.13.4 and v0.13.14.
Please make sure to require bitcore and check that submodules do not also include their own bitcore dependency.
2) I don't understand the keyword "prototype" so I can't try your function.
Can you please indicate me how can I can use this function in my code
johoe
Full Member
***
Offline Offline

Activity: 217
Merit: 238


View Profile
April 12, 2016, 02:50:20 PM
 #4

Something like this should work:

Code:
var bitcore = require('bitcore-lib');
var xprv = bitcore.HDPrivateKey.fromSeed(seed);

I'm not familiar enough with javascript to know how to fix the bitcore version errors.

Donations to 1CF62UFWXiKqFUmgQMUby9DpEW5LXjypU3
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!