Repository navigation
fix(sdk-api): require previous transactions for v1 non-segwit psbt inputs - #10190
Open
prikshitchawla300 wants to merge 2 commits into
Open
prikshitchawla300 wants to merge 2 commits into
prikshitchawla300 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
Contributor
Contributor
|
|
prikshitchawla300
force-pushed
the
prikshitchawla/cshld-2230-v1-psbt-require-prev-tx
branch
from
November 24, 2026 10:54
fa6f89c to
4e6d9d9
Compare
Contributor
|
The txid is not validated before it goes into the URL. |
…puts The legacy sighash used by non-segwit (p2sh) inputs does not commit to the input value, so the full previous transaction is needed to know what an input spends. - signPsbtRequest refuses a PSBT if any p2sh input lacks nonWitnessUtxo or its nonWitnessUtxo does not hash to the txid the input spends, and signs in safe mode instead of withUnsafeNonSegwit. - The v1 PSBT builder attaches the previous transaction of every p2sh input instead of using skipNonWitnessUtxo. It is taken from the unspent's prevTx or fetched from the BitGo v1 tx endpoint (GET /api/v1/tx/:txid), and must match the input's txid, script and value. - createTransaction no longer falls back to the legacy format when a previous transaction contradicts the unspent data (PrevTxMismatchError). Other PSBT build errors still fall back. BREAKING CHANGE: v1 signTransaction no longer signs PSBTs whose p2sh inputs only carry witnessUtxo. PSBTs built by this SDK now include the previous transactions; PSBTs built elsewhere must include nonWitnessUtxo for p2sh inputs. Ticket: CSHLD-2230
prikshitchawla300
force-pushed
the
prikshitchawla/cshld-2230-v1-psbt-require-prev-tx
branch
from
November 24, 2026 13:54
4e6d9d9 to
de63b52
Compare
veetragjain
approved these changes
Nov 24, 2026
Ticket: CSHLD-2230
prikshitchawla300
force-pushed
the
prikshitchawla/cshld-2230-v1-psbt-require-prev-tx
branch
from
November 25, 2026 09:37
e2ad6f2 to
82a4baf
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The legacy sighash used by non-segwit (p2sh) inputs does not commit to the input value, so the full previous transaction (
nonWitnessUtxo) is needed to know what an input spends. The v1 PSBT path built and signed p2sh inputs fromwitnessUtxoonly (skipNonWitnessUtxo+withUnsafeNonSegwit). This change makes it require and verify the previous transaction.Behaviour change
signPsbtRequest): refuses the whole PSBT if any p2sh input has nononWitnessUtxo, or itsnonWitnessUtxodoes not hash to the txid the input spends. Signing now runs in safe mode (withUnsafeNonSegwit(..., false)). Segwit and taproot inputs are unchanged.createTransactionwithusePsbt): attaches the previous transaction of every p2sh input instead of usingskipNonWitnessUtxo. It is taken from the unspent'sprevTxif present, otherwise fetched from BitGo's v1 tx endpoint (GET /api/v1/tx/:txid). The v1 indexer returns the transaction without witness data, which is enough fornonWitnessUtxosince it is only checked against the txid. It must match the input's txid, and the spent output must have the unspent's script and value.PrevTxMismatchError),createTransactionrejects instead of falling back to the legacy format. Other PSBT build errors, including a failed fetch or a response without a hex, still fall back as before.BREAKING CHANGE: v1
signTransactionno longer signs PSBTs whose p2sh inputs only carrywitnessUtxo. PSBTs built by this SDK now include the previous transactions. PSBTs built elsewhere must includenonWitnessUtxofor p2sh inputs.Changes
modules/sdk-api/src/v1/signPsbt.ts:nonWitnessUtxocheck, safe-mode signingmodules/sdk-api/src/v1/transactionBuilder.ts: fetch and verify previous transactions,PrevTxMismatchErrormodules/sdk-api/src/v1/wallet.ts: no legacy fallback onPrevTxMismatchErrortest/unit/v1/signPsbt.tsandtest/unit/v1/wallet.tsTesting
sdk-apiunit tests: 297 passingnonWitnessUtxorefused, one bad input refuses the whole PSBT,nonWitnessUtxoof another transaction refused, segwit inputs still sign fromwitnessUtxo, fetch from/api/v1/tx/:txid, value / txid / script mismatch rejected without fallback, and a failed fetch or missing hex still falling back./api/v1/tx/:txidreturned a hex that hashes to the txid and has the expected output value and script.Ticket: CSHLD-2230