Skip to content

Commit

Permalink
feat: remove unnecesary bitcoin network index fetching function
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Jul 15, 2024
1 parent f2ee37e commit 9e91d16
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
9 changes: 6 additions & 3 deletions src/dlc-handlers/ledger-dlc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()), {
Expand Down Expand Up @@ -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()), {
Expand Down Expand Up @@ -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()), {
Expand Down
23 changes: 5 additions & 18 deletions src/functions/bitcoin/bitcoin-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 9e91d16

Please sign in to comment.