From 9e91d1638f6f41497805672fbe9e086f9444ab87 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Mon, 15 Jul 2024 17:43:51 +0200 Subject: [PATCH] feat: remove unnecesary bitcoin network index fetching function --- src/dlc-handlers/ledger-dlc-handler.ts | 9 ++++++--- src/functions/bitcoin/bitcoin-functions.ts | 23 +++++----------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/dlc-handlers/ledger-dlc-handler.ts b/src/dlc-handlers/ledger-dlc-handler.ts index beac555..53aadd9 100644 --- a/src/dlc-handlers/ledger-dlc-handler.ts +++ b/src/dlc-handlers/ledger-dlc-handler.ts @@ -328,7 +328,8 @@ export class LedgerDLCHandler { this.walletAccountIndex, this.walletAddressIndex, multisigPayment, - this.bitcoinNetwork + this.bitcoinNetwork, + this.bitcoinNetworkIndex ); const formattedFundingPSBT = Psbt.fromBuffer(Buffer.from(fundingTransaction.toPSBT()), { @@ -403,7 +404,8 @@ export class LedgerDLCHandler { this.walletAccountIndex, this.walletAddressIndex, multisigPayment, - this.bitcoinNetwork + this.bitcoinNetwork, + this.bitcoinNetworkIndex ); const formattedWithdrawPSBT = Psbt.fromBuffer(Buffer.from(withdrawTransaction.toPSBT()), { @@ -463,7 +465,8 @@ export class LedgerDLCHandler { this.walletAccountIndex, this.walletAddressIndex, multisigPayment, - this.bitcoinNetwork + this.bitcoinNetwork, + this.bitcoinNetworkIndex ); const formattedDepositPSBT = Psbt.fromBuffer(Buffer.from(depositTransaction.toPSBT()), { diff --git a/src/functions/bitcoin/bitcoin-functions.ts b/src/functions/bitcoin/bitcoin-functions.ts index 04515c4..3ce87b4 100644 --- a/src/functions/bitcoin/bitcoin-functions.ts +++ b/src/functions/bitcoin/bitcoin-functions.ts @@ -371,13 +371,12 @@ export function createBitcoinInputSigningConfiguration( walletAccountIndex: number, walletAddressIndex: number, multisigPayment: P2TROut, - bitcoinNetwork: Network + bitcoinNetwork: Network, + bitcoinNetworkIndex: number ): BitcoinInputSigningConfig[] { - const networkIndex = getBitcoinNetworkIndex(bitcoinNetwork); - - const nativeSegwitDerivationPath = `m/84'/${networkIndex}'/${walletAccountIndex}'/0/${walletAddressIndex}`; - const taprootDerivationPath = `m/86'/${networkIndex}'/${walletAccountIndex}'/0/${walletAddressIndex}`; - const multisigDerivationPath = `m/86'/${networkIndex}'/${walletAccountIndex}'/0/0`; + const nativeSegwitDerivationPath = `m/84'/${bitcoinNetworkIndex}'/${walletAccountIndex}'/0/${walletAddressIndex}`; + const taprootDerivationPath = `m/86'/${bitcoinNetworkIndex}'/${walletAccountIndex}'/0/${walletAddressIndex}`; + const multisigDerivationPath = `m/86'/${bitcoinNetworkIndex}'/${walletAccountIndex}'/0/0`; const multisigPaymentScript = multisigPayment.script; @@ -473,18 +472,6 @@ export function finalizeUserInputs(transaction: Transaction, userPayment: P2TROu }); } -export function getBitcoinNetworkIndex(bitcoinNetwork: Network): number { - switch (bitcoinNetwork) { - case bitcoin: - return 0; - case testnet: - case regtest: - return 1; - default: - throw new Error('Unsupported Bitcoin Network'); - } -} - /** * Converts an ECDSA Public Key to a Schnorr Public Key. * @param publicKey - The ECDSA Public Key.