Upgrading to Ledger Flutter Plus

This commit is contained in:
Konstantin Ullrich 2024-09-17 14:34:03 +02:00
parent 474ead28b8
commit 1e91aa8f65
No known key found for this signature in database
GPG key ID: 6B3199AD9B3D23B8
4 changed files with 25 additions and 25 deletions

View file

@ -4,19 +4,19 @@ import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:cw_bitcoin/utils.dart';
import 'package:cw_core/hardware/hardware_account_data.dart';
import 'package:ledger_flutter/ledger_flutter.dart';
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
import 'package:ledger_litecoin/ledger_litecoin.dart';
class BitcoinCashHardwareWalletService {
BitcoinCashHardwareWalletService(this.ledger, this.device);
BitcoinCashHardwareWalletService(this.ledgerConnection);
final Ledger ledger;
final LedgerDevice device;
final LedgerConnection ledgerConnection;
Future<List<HardwareAccountData>> getAvailableAccounts({int index = 0, int limit = 5}) async {
final bitcoinCashLedgerApp = LitecoinLedgerApp(ledger);
Future<List<HardwareAccountData>> getAvailableAccounts(
{int index = 0, int limit = 5}) async {
final bitcoinCashLedgerApp = LitecoinLedgerApp(ledgerConnection);
final version = await bitcoinCashLedgerApp.getVersion(device);
final version = await bitcoinCashLedgerApp.getVersion();
print(version);
final accounts = <HardwareAccountData>[];
@ -26,24 +26,24 @@ class BitcoinCashHardwareWalletService {
for (final i in indexRange) {
final derivationPath = "m/44'/145'/$i'";
final xpub = await bitcoinCashLedgerApp.getXPubKey(
device,
accountsDerivationPath: derivationPath,
xPubVersion: int.parse(hex.encode(xpubVersion.public), radix: 16),
addressFormat: AddressFormat.cashaddr,
);
final hd = Bip32Slip10Secp256k1.fromExtendedKey(xpub, xpubVersion).childKey(Bip32KeyIndex(0));
final hd = Bip32Slip10Secp256k1.fromExtendedKey(xpub, xpubVersion)
.childKey(Bip32KeyIndex(0));
final address = generateP2PKHAddress(hd: hd, index: 0, network: BitcoinCashNetwork.mainnet);
final address = generateP2PKHAddress(
hd: hd, index: 0, network: BitcoinCashNetwork.mainnet);
accounts.add(HardwareAccountData(
accounts.add(HardwareAccountData(
address: address,
accountIndex: i,
derivationPath: derivationPath,
xpub: xpub,
));
}
}
return
accounts;
return accounts;
}
}

View file

@ -15,7 +15,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_flutter/ledger_flutter.dart';
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
import 'package:ledger_litecoin/ledger_litecoin.dart';
import 'package:mobx/mobx.dart';
@ -227,16 +227,14 @@ abstract class BitcoinCashWalletBase extends ElectrumWallet with Store {
return priv.signMessage(StringUtils.encode(message));
}
Ledger? _ledger;
LedgerDevice? _ledgerDevice;
LedgerConnection? _ledgerConnection;
LitecoinLedgerApp? _bitcoinCashLedgerApp;
@override
void setLedger(Ledger setLedger, LedgerDevice setLedgerDevice) {
_ledger = setLedger;
_ledgerDevice = setLedgerDevice;
void setLedgerConnection(LedgerConnection connection) {
_ledgerConnection = connection;
_bitcoinCashLedgerApp =
LitecoinLedgerApp(_ledger!, derivationPath: walletInfo.derivationInfo!.derivationPath!);
LitecoinLedgerApp(_ledgerConnection!, derivationPath: walletInfo.derivationInfo!.derivationPath!);
}
@override
@ -274,7 +272,6 @@ abstract class BitcoinCashWalletBase extends ElectrumWallet with Store {
final rawHex = await _bitcoinCashLedgerApp!.createTransaction(
_ledgerDevice!,
inputs: readyInputs,
outputs: outputs
.map((e) => TransactionOutput.fromBigInt(

View file

@ -29,10 +29,14 @@ dependencies:
git:
url: https://github.com/cake-tech/blockchain_utils
ref: cake-update-v2
ledger_flutter: ^1.0.1
ledger_flutter_plus:
git:
url: https://github.com/cake-tech/ledger-flutter-plus
ref: cake-v1
ledger_litecoin:
git:
url: https://github.com/cake-tech/ledger-litecoin
url: https://github.com/cake-tech/ledger-flutter-plus-plugins
path: ./packages/ledger-litecoin
dev_dependencies:
flutter_test:

View file

@ -1011,7 +1011,6 @@ import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_service.dart';
import 'package:hive/hive.dart';
import 'package:ledger_flutter/ledger_flutter.dart';
""";
const bitcoinCashCWHeaders = """
import 'package:cw_bitcoin_cash/cw_bitcoin_cash.dart';