Skip to content

consolidate PSBT exports to @caravan/psbt#466

Open
kunal-595 wants to merge 1 commit intocaravan-bitcoin:mainfrom
kunal-595:refactor/psbt-ownership
Open

consolidate PSBT exports to @caravan/psbt#466
kunal-595 wants to merge 1 commit intocaravan-bitcoin:mainfrom
kunal-595:refactor/psbt-ownership

Conversation

@kunal-595
Copy link

Hi,@bucko13

What kind of change does this PR introduce?
Refactoring / internal maintenance


Issue Number:
Fixes #461


Snapshots/Videos:
N/A – internal refactoring, no UI changes


If relevant, did you update the documentation?
N/A – internal refactoring only


Summary

This PR implements Step 1 of #461 by consolidating PSBT ownership on @caravan/psbt.

Specifically, it:

  • Moves PSBT signature related helpers into @caravan/psbt
  • Deprecates and removes internal PSBT exports from @caravan/bitcoin
  • Updates the coordinator to consume PSBT functionlity exclusively from @caravan/psbt

The change is intentionally scoped to avoid any modifications to cryptographic behavior, ECC initialization, or wallet signing logic. Existing PSBT construction and signing behavior is preserved, with regresion coverage added to ensure parity.


Does this PR introduce a breaking change?
No. This is an internal refactor with no user-visible or behavioral changes.


Checklist

  • I have tested my changes thoroughly.
  • I have added or updated tests to cover my changes (if applicable).
  • I have verified that test coverage meets or exceeds 95% (if applicable).
  • I have run the test suite locally, and all tests pass.
  • I have written tests for all new changes/features.
  • I have followed the project's coding style and conventions.
  • I have created a changeset to document my changes (npm run changeset).

Other information

All tests pass locally (322 tests).
New test coverage added for:

  • addSignaturesToPSBT
  • parseSignaturesFromPSBT
  • parseSignatureArrayFromPSBT

Follow-up work (ECC abstraction, bitcoinjs lib v6 migration, wallet updates) is intentionally deferred to separate PRs after this change lands.


Have you read the contributing guide?
Yes

Copilot AI review requested due to automatic review settings February 3, 2026 23:21
@vercel
Copy link

vercel bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
caravan-coordinator Ready Ready Preview, Comment Feb 3, 2026 11:23pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

🦋 Changeset detected

Latest commit: 3fbc890

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@caravan/psbt Minor
@caravan/bitcoin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the first step of consolidating PSBT functionality by moving signature-related helpers from @caravan/bitcoin to @caravan/psbt. The refactoring is part of a larger effort to standardize on bitcoinjs-lib v6 and eliminate duplicate PSBT implementations.

Changes:

  • Adds addSignaturesToPSBT, parseSignaturesFromPSBT, and parseSignatureArrayFromPSBT functions to @caravan/psbt with bitcoinjs-lib v6 support
  • Deprecates corresponding functions and constants in @caravan/bitcoin without removing them
  • Updates the coordinator application to import PSBT signature functions from @caravan/psbt instead of @caravan/bitcoin

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/caravan-psbt/src/psbtv0/psbt.ts Adds three PSBT signature helper functions and two private helper functions with v6 API compatibility
packages/caravan-psbt/src/psbtv0/psbt.test.ts Adds minimal test coverage for the new functions (error cases only)
packages/caravan-bitcoin/src/psbt.ts Adds @deprecated JSDoc tags to functions and constants being migrated
apps/coordinator/src/components/Wallet/WalletSign.jsx Updates import to use @caravan/psbt
apps/coordinator/src/components/ScriptExplorer/Transaction.jsx Updates import to use @caravan/psbt
apps/coordinator/src/components/ScriptExplorer/SignatureImporter.jsx Updates import to use @caravan/psbt
apps/coordinator/src/components/Hermit/HermitSignatureImporterPsbt.jsx Updates import to use @caravan/psbt
apps/coordinator/src/components/Hermit/HermitSignatureImporter.tsx Updates import to use @caravan/psbt
.changeset/good-moons-cheat.md Documents the changes with appropriate semver bumps (minor for psbt, patch for bitcoin)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +257 to +288
describe("parseSignaturesFromPSBT", () => {
it("should return null for invalid PSBT", () => {
expect(parseSignaturesFromPSBT("invalid")).toBeNull();
});

it("should return null for PSBT with no signatures", () => {
// Unsigned PSBT from test fixtures
const unsignedPsbt = TEST_FIXTURES.transactions[0].psbt;
if (unsignedPsbt) {
expect(parseSignaturesFromPSBT(unsignedPsbt)).toBeNull();
}
});
});

describe("parseSignatureArrayFromPSBT", () => {
it("should return null for invalid PSBT", () => {
expect(parseSignatureArrayFromPSBT("invalid")).toBeNull();
});

it("should return null for PSBT with no signatures", () => {
const unsignedPsbt = TEST_FIXTURES.transactions[0].psbt;
if (unsignedPsbt) {
expect(parseSignatureArrayFromPSBT(unsignedPsbt)).toBeNull();
}
});
});

describe("addSignaturesToPSBT", () => {
it("should return null for invalid PSBT", () => {
expect(addSignaturesToPSBT("testnet", "invalid", [], [])).toBeNull();
});
});
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test coverage for the newly added functions is insufficient. While the existing tests in @caravan/bitcoin (packages/caravan-bitcoin/src/psbt.test.ts) include comprehensive tests for partially signed PSBTs, fully signed PSBTs with single and multiple inputs, the tests here only cover error cases (invalid PSBTs and PSBTs with no signatures). Consider adding tests that verify the happy path scenarios, such as:

  1. Successfully adding signatures to an unsigned PSBT
  2. Parsing signatures from partially signed PSBTs
  3. Parsing signatures from fully signed PSBTs with single and multiple inputs
  4. Verifying signature validation works correctly

These tests would ensure functional parity with the original implementation and provide confidence in the migration.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunal-595 did you copy all the tests from packages/caravan-bitcoin/src/psbt.test.ts to packages/caravan-psbt/src/psbtv0/psbt.test.ts ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet , i have only added error case coverage (invalid PSBTs, no signatures) .

the happy path tests from packages/caravan-bitcoin/src/psbt.test.ts including unsigned, partially signed, and fully signed PSBT fixtures (single and multi-input), along with signature parsing and addition have not been ported yet
i will move those next to reach parity with the original implemntation

Copy link
Contributor

@Legend101Zz Legend101Zz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good overall thanks for taking this up with, I think the approach you took would also not cause any breaks and maybe the comment I had earlier on the issue would have been wrong , I'll test it out once to also confirm eveyrthing works nicely :)

},
];
psbt.data.updateInput(inputIndex, { partialSig });
const validator = (pk: any, msghash: any, sig: any): boolean =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe as we are moving things from @caravan/bitcoin to @caravan/psbt we can take this chance to also add some type defs if possible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea , i will add explicit types while migrating this code.
That includes removing any from the validator and defining clear parameter and return types for the signature helpers, i will include this in the same PR.

* adds partial signature object(s) to each input and returns the PSBT with
* partial signature(s) included.
*/
export function addSignaturesToPSBT(network, psbt, pubkeys, signatures) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same maybe some type defs

Comment on lines +257 to +288
describe("parseSignaturesFromPSBT", () => {
it("should return null for invalid PSBT", () => {
expect(parseSignaturesFromPSBT("invalid")).toBeNull();
});

it("should return null for PSBT with no signatures", () => {
// Unsigned PSBT from test fixtures
const unsignedPsbt = TEST_FIXTURES.transactions[0].psbt;
if (unsignedPsbt) {
expect(parseSignaturesFromPSBT(unsignedPsbt)).toBeNull();
}
});
});

describe("parseSignatureArrayFromPSBT", () => {
it("should return null for invalid PSBT", () => {
expect(parseSignatureArrayFromPSBT("invalid")).toBeNull();
});

it("should return null for PSBT with no signatures", () => {
const unsignedPsbt = TEST_FIXTURES.transactions[0].psbt;
if (unsignedPsbt) {
expect(parseSignatureArrayFromPSBT(unsignedPsbt)).toBeNull();
}
});
});

describe("addSignaturesToPSBT", () => {
it("should return null for invalid PSBT", () => {
expect(addSignaturesToPSBT("testnet", "invalid", [], [])).toBeNull();
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunal-595 did you copy all the tests from packages/caravan-bitcoin/src/psbt.test.ts to packages/caravan-psbt/src/psbtv0/psbt.test.ts ?

@Legend101Zz
Copy link
Contributor

@bucko13 can you please approve the workflow , so we can test if this did not break any functionality ?

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.

refactor: remove bitcoinjs-lib v5 and consolidate PSBT on v6

3 participants