1

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:

  1. Which configuration is correct for generating native SegWit (BIP84) addresses?
  2. Are there any risks or drawbacks in using the xpub/xprv prefixes for SegWit addresses, or will it just affect compatibility with certain wallets?"

1 Answer 1

1

The prefixes don't have an influence on address generation, or at least not within bitcoinjs-lib. They were mostly used for a wallet to figure out which addresses to generate in case you import an entire xprv or xpub into a different wallet (or at least the wallet I used to work on tried to do this). This is however discouraged at this point, because it is a layer violation. Taproot (BIP86) addresses do not have their own key version anymore for this reason and just use xprv/xpub as a prefix. Also see https://bitcoin.stackexchange.com/a/110736/26423 (and the other answer there).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.