Skip to content

WCN-3934 Path-agnostic wallet PSBT parsing and wallet prefix helpers - #458

Draft
davidkaplanbitgo wants to merge 1 commit into
masterfrom
davidkaplan/wcn-3934-bitgowasm-wasm-utxo-per-wallet-derivation-prefix-path
Draft

davidkaplanbitgo wants to merge 1 commit into
masterfrom
davidkaplan/wcn-3934-bitgowasm-wasm-utxo-per-wallet-derivation-prefix-path

Conversation

@davidkaplanbitgo

Copy link
Copy Markdown
Contributor

Ticket: WCN-3934

Part of the BIP-0044 style wallet derivation project (spike WCN-3907): wallets that share root xpubs get a second, per-wallet derivation scheme 44/<coin_type>/<h1>/<h2>/<chain>/<index>. h1/h2 are recomputed from the three wallet root keys, never stored.

Changes

  • New fixedScriptWallet.deriveWalletAccount(keys) and deriveWalletPrefix(keys, coinType) (Rust wallet_prefix.rs, wasm exports, TS wrappers) with the shared test vectors as a Rust test.
  • Parse, explain and getWalletKeysFromPsbt classify wallet inputs/outputs by the full derivation path recorded in the PSBT, matching key origins by fingerprint. A key with no origin entry (taproot/MuSig2 inputs only carry signer+cosigner) is derived from its xpub along a present entry's path; script equality is still the binding check. A non-matching output returns None instead of aborting the whole parse; a non-matching input is an error. ParsedInput/ParsedOutput.derivationPath hold the full recorded path.
  • RootWalletKeys::new_with_derivation_prefixes returns a typed error on a hardened component instead of panicking.
  • expectedScript option on add-wallet-input; mismatch fails with the typed WalletInputScriptMismatch and leaves the PSBT unchanged. Omitting it changes nothing.

New public API

Rust: wallet_prefix::{derive_wallet_account, derive_wallet_prefix, WalletPrefixError}, WalletKeysError, AddWalletInputError, WalletInputOptions.expected_script, BitGoPsbt::try_add_wallet_input_at_index. RootWalletKeys::new_with_derivation_prefixes now returns Result; OutputScriptType::check takes the three derived pubkeys. wasm: derive_wallet_account, derive_wallet_prefix, trailing expected_script argument on add_wallet_input/add_wallet_input_at_index. TS: deriveWalletAccount, deriveWalletPrefix, AddWalletInputOptions.expectedScript.

Test

  • cargo check --all-targets passes. cargo test and the mocha suite have NOT been run, and no mocha tests were added for the new behaviour yet; existing fixtures should be unaffected by inspection only.
  • Known gap: the mixed legacy+bip44 build via two RootWalletKeys relies on per-keys prefixes in create_bip32_derivation and is untested; hydrate_psbt still takes one key set (no per-unspent prefix).

Downstream (IMS, BitGoJS, wallet-platform) need the release of this change.

@linear-code

linear-code Bot commented Oct 31, 2026

Copy link
Copy Markdown

WCN-3934

Add deriveWalletAccount and deriveWalletPrefix (44/<coin_type>/<h1>/<h2>)
with the shared test vectors. Parse, explain and getWalletKeysFromPsbt now
classify inputs and outputs by the full derivation path recorded in the
PSBT, matching key origins by fingerprint and deriving a missing key
(taproot and MuSig2 inputs) along a present entry's path; the script
comparison still binds the result. A non-matching output returns None
instead of aborting the parse. Hardened derivation prefixes return a typed
error instead of panicking, and add-input accepts an optional
expectedScript that fails with WalletInputScriptMismatch.

Ticket: WCN-3934
@davidkaplanbitgo
davidkaplanbitgo force-pushed the davidkaplan/wcn-3934-bitgowasm-wasm-utxo-per-wallet-derivation-prefix-path branch from 20c789d to 770c516 Compare October 31, 2026 12:03
@davidkaplanbitgo

Copy link
Copy Markdown
Contributor Author

@claude

This branch has not been deployed

No deployments
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