Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/wallet-hardware/src/ledger/clients/utxo-psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const BaseLedgerPsbtUTXO = ({ chain }: { chain: SupportedCoin }) => {
const leafSegments = pathSegments.slice(3);
const change = Number(leafSegments[0] ?? 0);
const addressIndex = Number(leafSegments[1] ?? 0);
const format = getWalletFormatFor(derivationPath);
// getWalletFormatFor expects an m/-prefixed path (it reads the purpose
// from the second segment); derivationPath is normalized without it.
const format = getWalletFormatFor(`m/${derivationPath}`);
const template = templateForFormat(format);

let cachedAccountXpub: string | undefined;
Expand Down
23 changes: 17 additions & 6 deletions packages/wallet-hardware/src/ledger/clients/utxo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ const signUTXOTransaction = (
const splitNewTx = btcApp.splitTransaction(newTxHex, true);
const outputScriptHex = btcApp.serializeTransactionOutputs(splitNewTx).toString("hex");

// hw-app-btc derives the signing policy from these flags:
// additionals ["bech32"] + segwit → wpkh (native segwit, m/84')
// no additionals + segwit → sh(wpkh) (P2SH-P2WPKH, m/49')
// no additionals + !segwit → pkh (legacy, m/44')
// They must match the derivation path or the BTC app rejects with 0x6a80.
const format = getWalletFormatFor(derivationPath);
const segwit = format !== "legacy";
const params: CreateTransactionArg = {
additionals: ["bech32"],
additionals: format === "bech32" ? ["bech32"] : [],
associatedKeysets: inputs.map(() => derivationPath),
inputs,
outputScriptHex,
segwit: true,
useTrustedInputForSegwit: true,
segwit,
useTrustedInputForSegwit: segwit,
};

return btcApp.createPaymentTransaction({ ...params, ...options });
Expand Down Expand Up @@ -83,13 +90,17 @@ const signUTXOTransactionWithMultiplePaths = (
const splitNewTx = btcApp.splitTransaction(newTxHex, true);
const outputScriptHex = btcApp.serializeTransactionOutputs(splitNewTx).toString("hex");

// Same policy/path matching rules as signUTXOTransaction; all paths share
// one account so the first path determines the format.
const format = getWalletFormatFor(derivationPaths[0] ?? "");
const segwit = format !== "legacy";
const params: CreateTransactionArg = {
additionals: ["bech32"],
additionals: format === "bech32" ? ["bech32"] : [],
associatedKeysets: derivationPaths,
inputs,
outputScriptHex,
segwit: true,
useTrustedInputForSegwit: true,
segwit,
useTrustedInputForSegwit: segwit,
};

return btcApp.createPaymentTransaction({ ...params, ...options });
Expand Down