Skip to content

Fix PSBT serialization: remove stray 0x00 when there are no inputs or no outputs (bip174 patch)#2338

Open
jstortoise wants to merge 1 commit into
bitcoinjs:masterfrom
jstortoise:master
Open

Fix PSBT serialization: remove stray 0x00 when there are no inputs or no outputs (bip174 patch)#2338
jstortoise wants to merge 1 commit into
bitcoinjs:masterfrom
jstortoise:master

Conversation

@jstortoise
Copy link
Copy Markdown

Summary

PSBTs built with empty input lists and/or empty output lists were serialized with one extra 0x00 byte per empty side. That came from bip174’s keyValsOrEmptyToBuffer, which treated “no maps” as a single zero-length map delimiter. That does not match a strict BIP-174-style layout and can break interoperability with parsers in other stacks that expect the canonical byte length.

What we changed

  • Added a patch-package patch on bip174@3.0.0 so that when there are no input maps or no output maps, we append nothing instead of [Uint8Array.from([0])].
  • Wired postinstall to patch-package so a clean npm install reapplies the patch.
  • Updated test/fixtures/psbt.json for the addInput / “should be equal” case so the expected base64 matches the corrected serialization.

Testing

  • Full unit suite: npx mocha 'test/*.ts'.

Follow-up

  • When upstream bip174 releases a version with this fix, we should bump the dependency, delete patches/bip174+3.0.0.patch, and remove postinstall / patch-package if no other patches remain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant