mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
c78662fbfe
* replace all print statements with printV * restore backup error message * missing print statements, error fixes * Update cw_core/lib/utils/print_verbose.dart [skip ci] * Update cw_core/lib/utils/print_verbose.dart [skip ci] * CW-846: Correctly display balance (#1848) * Correctly display balance even with frozen coins * remove package= from AndroidMainfest.xml * update namespace * print -> printV --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
46 lines
1.5 KiB
Dart
46 lines
1.5 KiB
Dart
import 'dart:async';
|
|
|
|
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_bitcoin/ledger_bitcoin.dart';
|
|
import 'package:ledger_flutter_plus/ledger_flutter_plus.dart';
|
|
import 'package:cw_core/utils/print_verbose.dart';
|
|
|
|
class BitcoinHardwareWalletService {
|
|
BitcoinHardwareWalletService(this.ledgerConnection);
|
|
|
|
final LedgerConnection ledgerConnection;
|
|
|
|
Future<List<HardwareAccountData>> getAvailableAccounts(
|
|
{int index = 0, int limit = 5}) async {
|
|
final bitcoinLedgerApp = BitcoinLedgerApp(ledgerConnection);
|
|
|
|
final masterFp = await bitcoinLedgerApp.getMasterFingerprint();
|
|
|
|
final accounts = <HardwareAccountData>[];
|
|
final indexRange = List.generate(limit, (i) => i + index);
|
|
|
|
for (final i in indexRange) {
|
|
final derivationPath = "m/84'/0'/$i'";
|
|
final xpub =
|
|
await bitcoinLedgerApp.getXPubKey(derivationPath: derivationPath);
|
|
Bip32Slip10Secp256k1 hd =
|
|
Bip32Slip10Secp256k1.fromExtendedKey(xpub).childKey(Bip32KeyIndex(0));
|
|
|
|
final address = generateP2WPKHAddress(
|
|
hd: hd, index: 0, network: BitcoinNetwork.mainnet);
|
|
|
|
accounts.add(HardwareAccountData(
|
|
address: address,
|
|
accountIndex: i,
|
|
derivationPath: derivationPath,
|
|
masterFingerprint: masterFp,
|
|
xpub: xpub,
|
|
));
|
|
}
|
|
|
|
return accounts;
|
|
}
|
|
}
|