Closed kaloudis closed 4 years ago
Can you clarify what the variable passphrase
is?
I think you may be getting confused between a BIP39 passphrase (to combine with a BIP39 mnemonic) and a BIP38 passphrase (to decrypt a BIP38 encrypted private key).
If it's a passphrase for your mnemonic (BIP39), which I'm assuming is what it is, then you don't need BIP38, just do:
const bip39 = require('bip39');
const bip32 = require('bip32');
const mnemonic = "much bottom such hurt hunt welcome cushion erosion pulse admit name deer"
const passphrase = "password1";
const seed = bip39.mnemonicToSeedSync(mnemonic, passphrase);
const node = bip32.fromSeed(seed);
node.derivePath("m/44'/0'/0'/0/0").toWIF();
// "KxZFVjWvGqCvtKowcps9TusBrSa1zkUpBTFkoNiLYhxcTnrAC9n7"
You can enter that mnemonic/passphrase on https://iancoleman.io/bip39/ and you'll see the private key for the m/44'/0'/0'/0/0
address is the same.
If I've assumed incorrectly and you really do want to use BIP38 then you need to generate a keypair normally first, then encrypt the private key with BIP38, then use your passphrase to decrypt it in the future.
Works like a charm. Thank @lukechilds!
Hey all,
First time really get my hands dirty with bitcoinjs-lib and related libraries. I'm working with a BIP39 mnemonic and a BIP38 passphrase for it. I'm not quite sure how to get the private key in the right format for the
bip38.decrypt()
functionApologies if this question is better suited for one of the other repos.