I'm generating SegWit keys and addresses using bitcoinjs-lib. I'm new to Blockchain so I'm using Ian Coleman's bip39 repo for guidance. However, I encountered different key and address outputs when generating them with bitcoinjs-lib
compared to the results from Ian Coleman’s tool.
I found out that the reason is in the network config, I'm using the bitcoin
network config directly from bitcoinjs-lib
, while in that repo there's a custom config.
Here's the config I used:
{
messagePrefix: '\x18Bitcoin Signed Message:\n',
bech32: 'bc',
bip32: {
public: 0x0488b21e,
private: 0x0488ade4,
},
pubKeyHash: 0x00,
scriptHash: 0x05
wif: 0x80,
}
And here’s the config from Ian Coleman's tool:
{
messagePrefix:"\u0018Bitcoin Signed Message:\n",
bech32:"bc",
bip32:
{
public: 78792518, // 0x4B24746
private: 78791436 // 0x4B2430C
},
pubKeyHash: 0, // 0x00
scriptHash: 5, // 0x05
wif: 128 // 0x80
}
My result outputs keys that start from xprv
and xpub
while Ian Coleman's resulted in zprv
and zpub
.
Given that BIP84 mandates zprv
and zpub
prefixes for native SegWit keys, Ian Coleman’s config seems more appropriate. However, both configurations generate seemingly correct addresses.
So, my questions are:
- Which configuration is correct for generating native SegWit (BIP84) addresses?
- Are there any risks or drawbacks in using the xpub/xprv prefixes for SegWit addresses, or will it just affect compatibility with certain wallets?"