<p>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 <a href="https://bitcoin.stackexchange.com/a/110736/26423">https://bitcoin.stackexchange.com/a/110736/26423</a> (and the other answer there).</p>

CC BY-SA 4.0
2024-10-24T11:51:43.690Z
2024-10-24T11:51:43.690Z
TheCharlatan
<p>I'm generating SegWit keys and addresses using <a href="https://github.com/bitcoinjs/bitcoinjs-lib" rel="nofollow noreferrer">bitcoinjs-lib</a>. I'm new to Blockchain so I'm using Ian Coleman's <a href="https://github.com/iancoleman/jsbip39" rel="nofollow noreferrer">bip39 repo</a> for guidance. However, I encountered different key and address outputs when generating them with <code>bitcoinjs-lib</code> compared to the results from Ian Coleman’s tool.</p>
<p>I found out that the reason is in the network config, I'm using the <code>bitcoin</code> network config directly from <code>bitcoinjs-lib</code>, while in that repo there's a custom config.</p>
<p>Here's the config I used:</p>
<pre><code>{
  messagePrefix: '\x18Bitcoin Signed Message:\n',
  bech32: 'bc',
  bip32: {
    public: 0x0488b21e,
    private: 0x0488ade4,
  },
  pubKeyHash: 0x00,
  scriptHash: 0x05
  wif: 0x80,
}
</code></pre>
<p>And here’s the config from Ian Coleman's tool:</p>
<pre><code>{
  messagePrefix:&quot;\u0018Bitcoin Signed Message:\n&quot;,
  bech32:&quot;bc&quot;,
  bip32:
    { 
      public: 78792518, // 0x4B24746
      private: 78791436 // 0x4B2430C
    },
  pubKeyHash: 0, // 0x00
  scriptHash: 5, // 0x05
  wif: 128 // 0x80
}

</code></pre>
<p>My result outputs keys that start from <code>xprv</code> and <code>xpub</code> while Ian Coleman's resulted in <code>zprv</code> and <code>zpub</code>.</p>
<p>Given that BIP84 mandates <code>zprv</code> and <code>zpub</code> prefixes for native SegWit keys, Ian Coleman’s config seems more appropriate. However, both configurations generate seemingly correct addresses.</p>
<p>So, my questions are:</p>
<ol>
<li>Which configuration is correct for generating native SegWit (BIP84) addresses?</li>
<li>Are there any risks or drawbacks in using the xpub/xprv prefixes for SegWit addresses, or will it just affect compatibility with certain wallets?&quot;</li>
</ol>

<bitcoin-core><segregated-witness><javascript><p2wpkh><bip-84>
Correct Configuration for Generating Bitcoin SegWit (BIP84) Addresses
Pavlo Zalutskiy
# Correct Configuration for Generating Bitcoin SegWit (BIP84) Addresses

(Asked by: username_0 on 2024-10-24)

I'm generating SegWit keys and addresses using [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib). I'm new to Blockchain so I'm using Ian Coleman's [bip39 repo](https://github.com/iancoleman/jsbip39) 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?"

**Tags:** bitcoin-core, segregated-witness, javascript, p2wpkh, bip-84


---

## 1 answers

### Answer by username_1 on 2024-10-24. Score: 1 | Accepted answer

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).


---

