The format you utilize is determined by how it’s essential to use the personal key. Your code produces a uncooked hex personal key, with out formatting.
$ node index.js
mnemonic: thunder buy pave tower lecture improve supreme half child health tray shove
addrnodePublicKey: 02ceb48796223dc3777fe210a2034059b5e39b3743e59d62f75ef07a32f8440caf
addernodePrivateKey: 310fe2e677a3ad28acb91d2645bb33882f015ab11e59dce9d2a72905979e3cb6
Uncooked Personal Key
A personal key (in bitcoin, i.e. ECDSA SECP256K1
) is a 32 byte quantity between 0x1
and 0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140
.
For instance:
0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
Pockets Enter Format (WIF)
Nonetheless, pockets software program usually makes use of the Pockets Enter Format (WIF) to make it simpler to repeat over. It makes use of base58check
encoding so it avoids ambiguous characters (like 0 and O), it’s shorter, and features a checksum in case of typos. For instance:
5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
WIF Conversion
The method of changing a uncooked personal key to WIF is define right here: https://en.bitcoin.it/wiki/Wallet_import_format:
-
Take a personal key
0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
-
Add a 0x80 byte in entrance of it for mainnet addresses or 0xef for testnet addresses. Additionally add a 0x01 byte on the finish if the personal key will correspond to a compressed public key
800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
-
Carry out SHA-256 hash on the prolonged key
8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592
-
Carry out SHA-256 hash on results of SHA-256 hash
507A5B8DFED0FC6FE8801743720CEDEC06AA5C6FCA72B07C49964492FB98A714
-
Take the primary 4 bytes of the second SHA-256 hash, that is the checksum
507A5B8D
-
Add the 4 checksum bytes from level 5 on the finish of the prolonged key from level 2
800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D507A5B8D
-
Convert the outcome from a byte string right into a base58 string utilizing Base58Check encoding. That is the Pockets Import Format
5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ
Potential node.js sources: