From 98aa1fd6c95d228c692d3fe99d9c3bde0fd183f4 Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Fri, 9 Jan 2026 20:47:07 +0100 Subject: [PATCH] fix: custom Bitcoin Ledger derivation paths and update ledger-bitcoin dependency (#2798) * fix: custom Bitcoin Ledger derivation paths and update ledger-bitcoin dependency * fix: remove unused `derivationPath` in `signTransaction` method --- cw_bitcoin/lib/bitcoin_wallet.dart | 8 ++++++-- cw_bitcoin/lib/hardware/bitcoin_ledger_service.dart | 4 ++++ cw_bitcoin/pubspec.yaml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cw_bitcoin/lib/bitcoin_wallet.dart b/cw_bitcoin/lib/bitcoin_wallet.dart index b1feeb7a9..495357425 100644 --- a/cw_bitcoin/lib/bitcoin_wallet.dart +++ b/cw_bitcoin/lib/bitcoin_wallet.dart @@ -13,6 +13,7 @@ import 'package:cw_bitcoin/electrum_derivations.dart'; import 'package:cw_bitcoin/electrum_wallet.dart'; import 'package:cw_bitcoin/electrum_wallet_snapshot.dart'; import 'package:cw_bitcoin/hardware/bitcoin_hardware_wallet_service.dart'; +import 'package:cw_bitcoin/hardware/bitcoin_ledger_service.dart'; import 'package:cw_bitcoin/payjoin/manager.dart'; import 'package:cw_bitcoin/payjoin/storage.dart'; import 'package:cw_bitcoin/pending_bitcoin_transaction.dart'; @@ -31,9 +32,7 @@ import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_keys_file.dart'; import 'package:flutter/foundation.dart'; import 'package:hive/hive.dart'; -import 'package:ledger_bitcoin/ledger_bitcoin.dart'; import 'package:ledger_bitcoin/psbt.dart'; -import 'package:ledger_flutter_plus/ledger_flutter_plus.dart'; import 'package:mobx/mobx.dart'; import 'package:ur/cbor_lite.dart'; import 'package:ur/ur.dart'; @@ -356,6 +355,11 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store { ); final psbtStr = base64Encode(psbt.serialize()); + if (hardwareWalletService is BitcoinLedgerService && derivationInfo.derivationPath != null) { + (hardwareWalletService as BitcoinLedgerService) + .setAccountDerivationPath(derivationInfo.derivationPath!); + } + final rawHex = await hardwareWalletService!.signTransaction(transaction: psbtStr); return BtcTransaction.fromRaw(BytesUtils.toHexString(rawHex)); } diff --git a/cw_bitcoin/lib/hardware/bitcoin_ledger_service.dart b/cw_bitcoin/lib/hardware/bitcoin_ledger_service.dart index 65ab76400..19c5bdc93 100644 --- a/cw_bitcoin/lib/hardware/bitcoin_ledger_service.dart +++ b/cw_bitcoin/lib/hardware/bitcoin_ledger_service.dart @@ -18,6 +18,10 @@ class BitcoinLedgerService extends HardwareWalletService with BitcoinHardwareWal final LedgerConnection ledgerConnection; final BitcoinLedgerApp bitcoinLedgerApp; + void setAccountDerivationPath(String derivationPath) { + bitcoinLedgerApp.derivationPath = derivationPath; + } + @override Future> getAvailableAccounts({int index = 0, int limit = 5}) async { final masterFp = await bitcoinLedgerApp.getMasterFingerprint(); diff --git a/cw_bitcoin/pubspec.yaml b/cw_bitcoin/pubspec.yaml index 942a5069a..3747e8dbb 100644 --- a/cw_bitcoin/pubspec.yaml +++ b/cw_bitcoin/pubspec.yaml @@ -49,7 +49,7 @@ dependencies: git: url: https://github.com/cake-tech/ledger-flutter-plus-plugins path: packages/ledger-bitcoin - ref: dc42621f55702d0732681afc2f90bc0047f26633 + ref: 75bba8632c529debf30ee2b1858530009fa6440b ledger_litecoin: git: url: https://github.com/cake-tech/ledger-flutter-plus-plugins