Skip to content

feat(wallets): add BC-UR xpub import support - #522

Open
jbrauck-unchained wants to merge 2 commits into
caravan-bitcoin:mainfrom
jbrauck-unchained:codex/passport-seedsigner-bcur-xpub
Open

feat(wallets): add BC-UR xpub import support#522
jbrauck-unchained wants to merge 2 commits into
caravan-bitcoin:mainfrom
jbrauck-unchained:codex/passport-seedsigner-bcur-xpub

Conversation

@jbrauck-unchained

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Issue Number:

Fixes #

Snapshots/Videos:

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?

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

Have you read the contributing guide?

For information on creating and using changesets, please refer to our documentation on changesets.

@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
caravan-coordinator Ready Ready Preview Aug 2, 2026 11:42pm

Request Review

@changeset-bot

changeset-bot Bot commented Aug 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b059ec8

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

This PR includes changesets to release 1 package
Name Type
@caravan/wallets Minor

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

@Shadouts Shadouts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mostly requests for cleanup and deduplication of some logic available in the @caravan/bitcoin library

network: BitcoinNetwork
): Network.MAINNET | Network.TESTNET {
return network === Network.MAINNET ? Network.MAINNET : Network.TESTNET;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is the way to go. Does ExtendedPublicKey not already properly handle test networks like regtest? I don't think you have to transform the value before passing it to ExtendedPublicKey. If you find that you have to, then it smells like something else might be off. See my other comment about validateExtendedPublicKeyForNetwork()

const decodedResult = this.handleDecodedResult(
result.type,
Buffer.from(result.cbor.buffer),
Buffer.from(result.cbor),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's requiring this change?

expect(decoder.getError()).toBe(PASSPORT_MULTISIG_EXPORT_ERROR);
});

it("rejects a key that does not represent m/45'", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this actually be a constraint? If so, why?

import { bip32SerializationNetwork } from "./utils";

const PASSPORT_MULTISIG_PATH = "m/45'";
const PASSPORT_MULTISIG_INDEX = 0x8000002d;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe collect device-specific values together into a config object.

const PASSPORT_MULTISIG_INDEX = 0x8000002d;
const FINGERPRINT_PATTERN = /^[0-9a-f]{8}$/i;

export const PASSPORT_MULTISIG_EXPORT_ERROR =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't export just to get a test to work. This isn't really being used anywhere else.

import { BCUR2Decoder, ExtendedPublicKeyData } from "./decoder";
import { bip32SerializationNetwork } from "./utils";

const PASSPORT_MULTISIG_PATH = "m/45'";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use MULTISIG_ROOT from constants.ts

import { bip32SerializationNetwork } from "./utils";

const PASSPORT_MULTISIG_PATH = "m/45'";
const PASSPORT_MULTISIG_INDEX = 0x8000002d;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use hardenedBIP32Index() from @caravan/bitcoin


const PASSPORT_MULTISIG_PATH = "m/45'";
const PASSPORT_MULTISIG_INDEX = 0x8000002d;
const FINGERPRINT_PATTERN = /^[0-9a-f]{8}$/i;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use validateRootFingerprint from @caravan/bitcoin

Comment on lines +108 to +122
const serializationNetwork = bip32SerializationNetwork(network);
const expectedVersion =
serializationNetwork === Network.MAINNET
? EXTENDED_PUBLIC_KEY_VERSIONS.xpub
: EXTENDED_PUBLIC_KEY_VERSIONS.tpub;

let key: ExtendedPublicKey;
try {
key = ExtendedPublicKey.fromBase58(value.p2sh);
} catch (_error) {
throw new Error(PASSPORT_MULTISIG_EXPORT_ERROR);
}

if (
key.version !== expectedVersion ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some of this can be handled simply by using validateExtendedPublicKeyForNetwork() from @caravan/biitcoin

value.xfp.toLowerCase()
) {
throw new Error(PASSPORT_MULTISIG_EXPORT_ERROR);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is some more validation logic that can be replaced with stuff we have in @caravan/bitcoin

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.

2 participants