Skip to content

Commit

Permalink
Remove padding input form ledger PSBT signing (#311)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Man <tim@secretkeylabs.com>
  • Loading branch information
victorkirov and teebszet committed Dec 12, 2023
1 parent a63afd5 commit 8d13683
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ledger/psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export async function signLedgerPSBT({
const masterFingerPrint = await app.getMasterFingerprint();

const { inputTotal, outputTotal } = getIoTotals(txn);
let addedPaddingInput = false;

if (inputTotal < outputTotal) {
// There is a bug in Ledger that if the inputs are greater than the outputs, then it will fail to sign
Expand All @@ -153,6 +154,7 @@ export async function signLedgerPSBT({
amount: outputTotal - inputTotal,
},
});
addedPaddingInput = true;
}

if (
Expand Down Expand Up @@ -204,6 +206,12 @@ export async function signLedgerPSBT({
}
}

if (addedPaddingInput) {
// We inserted a dummy input to get around a Ledger bug, so we need to remove it
// @ts-expect-error: Expected error as inputs are private, but this is the only way to remove the input
txn.inputs.pop();
}

if (finalize) {
txn.finalize();
}
Expand Down

0 comments on commit 8d13683

Please sign in to comment.