fix(bitcoin-wallet-snap): reveal own output scripts when signing a PSBT - #225
Open
jeremytsng wants to merge 3 commits into
Open
fix(bitcoin-wallet-snap): reveal own output scripts when signing a PSBT#225jeremytsng wants to merge 3 commits into
jeremytsng wants to merge 3 commits into
Conversation
This was referenced Aug 27, 2026
Partner PSBT templates may pay wallet scripts beyond the revealed set; BDK's lookahead lets them pass isMine while routine sync, which queries revealed scripts only, never watches them. Signing now reveals every own output script and persists the wallet before broadcast, so signed-away change is always covered by sync. The reveal runs only on the signing path: signing sits behind the user confirmation dialog, while fillPsbt and computeFee stay reveal-free so an unconfirmed request cannot advance the revealed index.
jeremytsng
force-pushed
the
fix/btc-snap-reveal-at-sign
branch
from
August 28, 2026 05:09
276f370 to
cdd693d
Compare
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.
Explanation
Second of three PRs splitting #201 per review feedback. Stacked on #224.
When the snap fills and signs a partner-supplied PSBT (bridge/swap), the template's change output pays one of our own scripts — but that script may sit beyond the revealed set. BDK's lookahead lets it pass
isMine, so we sign it, while routine sync (start_sync_with_revealed_spks) never queries it. Change we signed away can then be missing from the balance, which is the shape of both support cases behind this stack (0.09 BTC and 6.9 BTC).The rule this PR adds: if we sign it, we watch it.
BitcoinAccount.revealToScript(script): resolves the script's keychain and derivation index (derivation_of_spk) and reveals up to it (reveal_addresses_to) when it lies beyond the last revealed index. Verified against the pinned@metamask/bitcoindevkitbuild:derivation_indexreturns the last revealed index, and lookahead scripts resolve.signPsbtreveals every own output script of the PSBT after a successful signature and persists the wallet before broadcast — explicitly, sobroadcast: falseflows are covered too.fillPsbtandcomputeFee(callable without confirmation) reveal nothing, so an unconfirmed request cannot advance the revealed index; per signature the reveal distance is bounded by BDK's lookahead.References
Checklist