Skip to content
Prev Previous commit
Next Next commit
added path tests for Taproot
  • Loading branch information
bertonjulian committed Mar 5, 2025
commit 86b5ff70bef49c5a4e8b23df90cd2a34b48e7fee
1 change: 1 addition & 0 deletions packages/xpub-lib/src/derivation.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function deriveAddress({ purpose, pubkey, network }) {
return bc1qAddress
}
case Purpose.P2TR: {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

// Context: https://bitcoinops.org/en/topics/x-only-public-keys/
const xOnlyPubkey = toXOnly(pubkey)
const { address: bc1pAddress } = bitcoin.payments.p2tr({
internalPubkey: xOnlyPubkey,
Expand Down
10 changes: 10 additions & 0 deletions packages/xpub-lib/src/paths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ describe("accountDerivationPath", () => {
expect(
accountDerivationPath({ purpose: Purpose.P2WPKH, accountNumber: 0 })
).toBe("m/84'/1'/0'")
expect(
accountDerivationPath({ purpose: Purpose.P2TR, accountNumber: 0 })
).toBe("m/86'/1'/0'")
expect(
accountDerivationPath({ purpose: Purpose.P2PKH, accountNumber: 1337 })
).toBe("m/44'/1'/1337'")
Expand All @@ -86,6 +89,13 @@ describe("accountDerivationPath", () => {
network: Network.MAINNET,
})
).toBe("m/84'/0'/0'")
expect(
accountDerivationPath({
purpose: Purpose.P2TR,
accountNumber: 0,
network: Network.MAINNET,
})
).toBe("m/86'/0'/0'")
expect(
accountDerivationPath({
purpose: Purpose.P2WPKH,
Expand Down
Loading