mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-26 21:50:27 +00:00
36 lines
1 KiB
Dart
36 lines
1 KiB
Dart
|
import 'dart:async';
|
||
|
|
||
|
import 'package:cw_core/hardware/hardware_account_data.dart';
|
||
|
import 'package:ledger_ethereum/ledger_ethereum.dart';
|
||
|
import 'package:ledger_flutter/ledger_flutter.dart';
|
||
|
|
||
|
class EVMChainHardwareWalletService {
|
||
|
EVMChainHardwareWalletService(this.ledger, this.device);
|
||
|
|
||
|
final Ledger ledger;
|
||
|
final LedgerDevice device;
|
||
|
|
||
|
Future<List<HardwareAccountData>> getAvailableAccounts({int index = 0, int limit = 5}) async {
|
||
|
final ethereumLedgerApp = EthereumLedgerApp(ledger);
|
||
|
|
||
|
final version = await ethereumLedgerApp.getVersion(device);
|
||
|
|
||
|
final accounts = <HardwareAccountData>[];
|
||
|
final indexRange = List.generate(limit, (i) => i + index);
|
||
|
|
||
|
for (final i in indexRange) {
|
||
|
final derivationPath = "m/44'/60'/$i'/0/0";
|
||
|
final address =
|
||
|
await ethereumLedgerApp.getAccounts(device, accountsDerivationPath: derivationPath);
|
||
|
|
||
|
accounts.add(HardwareAccountData(
|
||
|
address: address.first,
|
||
|
accountIndex: i,
|
||
|
derivationPath: derivationPath,
|
||
|
));
|
||
|
}
|
||
|
|
||
|
return accounts;
|
||
|
}
|
||
|
}
|