bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.67k stars 2.1k forks source link

Examples on how to read private key from a wallet and create a wallet from a private key #1544

Closed calidion closed 4 years ago

calidion commented 4 years ago

Examples on how to read private key from a wallet and create a wallet from a private key

junderw commented 4 years ago

Using a combination of BIP39, BIP32 and a derivation path scheme such as BIP44 BIP49 or BIP84 should be fine.

Some examples are here:

https://github.com/bitcoinjs/bitcoinjs-lib/blob/a543f5aa6b58dc92b5b4dd89b953353d9f99894a/test/integration/bip32.spec.ts

calidion commented 4 years ago

@junderw

It seems the example use no private key and no wallet is generated?

junderw commented 4 years ago

Yes it does. Please read BIP32 to understand how HD key generation is used in wallets, then read BIP39 to understand how mnemonic phrases are used to store secret data for use in generating private keys then read BIP44 to understand the logic behind specific derivation paths and read BIP49 and BIP84 which are basically drop in replacements for BIP44 but with p2sh-p2wpkh and p2wpkh in mind respectively.