Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cw 503 ledger support #1310

Merged
merged 72 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
3993dae
CW-503 Prepare Ledger integration
konstantinullrich Nov 24, 2023
e5f543f
CW-503 Revert Tor ignore
konstantinullrich Nov 27, 2023
1f27af7
CW-503 Add Connect Device Page
konstantinullrich Nov 27, 2023
3eff448
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Dec 11, 2023
ebbd30f
CW-503 Add createWalletFromDevice for monero
konstantinullrich Dec 13, 2023
f082e31
CW-503 Add Connect Device Page
konstantinullrich Dec 13, 2023
8450f59
CW-503 Add Connect Device Page
konstantinullrich Dec 13, 2023
8a12009
CW-503 Add Debug Options
konstantinullrich Jan 10, 2024
5b51828
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Jan 11, 2024
7a3f9e0
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Jan 12, 2024
942f5b9
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Jan 31, 2024
32d050c
CW-503 Add proper hardware wallet selection screen
konstantinullrich Feb 8, 2024
33f818b
CW-503 Minor design changes on connect_device_page
konstantinullrich Feb 9, 2024
0b7e5ea
CW-503 Add Create Wallet from Ledger
konstantinullrich Feb 22, 2024
c09c5b9
CW-503 Spent Ledger ETH Funds
konstantinullrich Feb 23, 2024
fd3c9fb
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Feb 23, 2024
89578fc
CW-503 Minor fixes
konstantinullrich Feb 23, 2024
b6d11f5
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Feb 23, 2024
9892496
CW-503 Fix Merge conflicts
konstantinullrich Feb 23, 2024
48e677e
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Feb 23, 2024
59faeeb
CW-503 Fix Merge conflicts
konstantinullrich Feb 23, 2024
8985e3f
CW-503 Fix Merge conflicts
konstantinullrich Feb 23, 2024
45aea41
CW-503 Fix minor conflicts
konstantinullrich Feb 23, 2024
59b21d9
CW-503 Improve Ledger BLE Communication
konstantinullrich Mar 1, 2024
d710799
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Mar 1, 2024
18df4ed
CW-503 Improve Ledger BLE Communication
konstantinullrich Mar 1, 2024
021f192
CW-503 Rollback Monero Test code
konstantinullrich Mar 1, 2024
9ffafb8
CW-503 Fix Execution failed for task :app:checkReleaseDuplicateClasses
konstantinullrich Mar 4, 2024
b9b393c
CW-503 Better Error-Exceptions
konstantinullrich Mar 4, 2024
065dbe1
CW-503 Add SetPinScreen before restore from hardware-wallet
konstantinullrich Mar 4, 2024
044feb3
CW-503 override web3dart to use cake's git hosted version
konstantinullrich Mar 4, 2024
4dd2d59
CW-503 Implement ledger sign messages
konstantinullrich Mar 4, 2024
02b111b
CW-503 Implement ledger sign messages and send erc20 tokens
konstantinullrich Mar 5, 2024
de6f451
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Mar 5, 2024
f09663a
CW-503 Fix merge conflicts
konstantinullrich Mar 5, 2024
8deb684
CW-503 Fix merge conflicts
konstantinullrich Mar 5, 2024
477ef8e
CW-503 Use dep override for ledger_flutter
konstantinullrich Mar 5, 2024
c5ceaac
CW-503 Ledger ERC20 finalisation
konstantinullrich Mar 6, 2024
d1a0340
CW-503 More graceful error handling
konstantinullrich Mar 7, 2024
7a38210
CW-503 Even more graceful error handling & remove debug code
konstantinullrich Mar 8, 2024
bd733f4
CW-503 Minor Changes for Vik
konstantinullrich Mar 9, 2024
b2a53b1
CW-503 Fix USB connection
konstantinullrich Mar 13, 2024
5f34c05
CW-503 Maybe this overrides web3dart finally
konstantinullrich Mar 13, 2024
ac4dfc1
Merge branch 'main' into CW-503-Ledger-support
OmarHatem28 Mar 14, 2024
e49205f
Indicate Loading on the first 5 Wallet Accounts
konstantinullrich Mar 25, 2024
5d5c42c
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Mar 25, 2024
718bb33
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Mar 26, 2024
d75bbcd
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Mar 27, 2024
6560352
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Apr 1, 2024
ed1b91f
Merge branch 'main' into CW-503-Ledger-support
konstantinullrich Apr 1, 2024
f1cb3ca
Merge branch 'main' of https://github.com/cake-tech/cake_wallet into …
OmarHatem28 Apr 6, 2024
f3ef285
Fix conflicts with main
OmarHatem28 Apr 6, 2024
0371853
Add Bluetooth permission to iOS [skip ci]
OmarHatem28 Apr 6, 2024
8d73495
add privacyinfo for ios [skip ci]
OmarHatem28 Apr 6, 2024
d66b978
update PrivacyInfo.xcprivacy [scip ci]
OmarHatem28 Apr 6, 2024
6a43f08
ios shit [skip ci]
OmarHatem28 Apr 6, 2024
10c7dd3
Merge remote-tracking branch 'origin/CW-503-Ledger-support' into CW-5…
konstantinullrich Apr 8, 2024
f2da926
Resolve open Todos regarding iOS Support
konstantinullrich Apr 8, 2024
6b0cd14
Remove erc20 dependency to have more granular control over the tx UX
konstantinullrich Apr 9, 2024
0c8b15f
Merge branch 'refs/heads/main' into CW-503-Ledger-support
konstantinullrich Apr 9, 2024
2ed5ce5
Better error handling
konstantinullrich Apr 12, 2024
7c185b1
Improve Ledger account handling
konstantinullrich Apr 16, 2024
24341ba
Merge branch 'refs/heads/main' into CW-503-Ledger-support
konstantinullrich Apr 23, 2024
feebdbb
Implement requested Changes
konstantinullrich Apr 23, 2024
0670baa
Implement requested Changes
konstantinullrich Apr 23, 2024
fa28985
Merge branch 'refs/heads/main' into CW-503-Ledger-support
konstantinullrich Apr 25, 2024
6c9f334
Implement requested Changes
konstantinullrich Apr 25, 2024
fd5dba1
Implement requested Changes
konstantinullrich Apr 25, 2024
43ce2f3
Merge branch 'refs/heads/main' into CW-503-Ledger-support
konstantinullrich Apr 29, 2024
6674b77
Merge branch 'refs/heads/main' into CW-503-Ledger-support
konstantinullrich Apr 30, 2024
271cc07
Fix merge conflicts
konstantinullrich Apr 30, 2024
5a98bb5
Update wallet_info.dart
OmarHatem28 Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions android/app/src/main/AndroidManifestBase.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<!--bibo01 : hardware option-->
<uses-feature android:name="android.hardware.bluetooth" android:required="false"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>

<!-- required for API 18 - 30 -->
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission
android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />

<!-- API 31+ -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

<application
android:name=".Application"
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.21'
repositories {
google()
jcenter()
Expand Down
Binary file added assets/images/bluetooth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/ledger_nano.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/usb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions cw_bitcoin/lib/bitcoin_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import 'package:cw_core/wallet_type.dart';
import 'package:hive/hive.dart';
import 'package:collection/collection.dart';

class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials, BitcoinRestoreWalletFromWIFCredentials> {
class BitcoinWalletService extends WalletService<
BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials,
BitcoinRestoreWalletFromWIFCredentials, BitcoinNewWalletCredentials> {
BitcoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);

final Box<WalletInfo> walletInfoSource;
Expand Down Expand Up @@ -97,6 +99,11 @@ class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
}

@override
Future<BitcoinWallet> restoreFromHardwareWallet(BitcoinNewWalletCredentials credentials) {
throw UnimplementedError("Restoring a Bitcoin wallet from a hardware wallet is not yet supported!");
}

@override
Future<BitcoinWallet> restoreFromKeys(BitcoinRestoreWalletFromWIFCredentials credentials,
{bool? isTestnet}) async =>
Expand Down
2 changes: 1 addition & 1 deletion cw_bitcoin/lib/electrum_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ abstract class ElectrumWalletBase
void setExceptionHandler(void Function(FlutterErrorDetails) onError) => _onError = onError;

@override
String signMessage(String message, {String? address = null}) {
Future<String> signMessage(String message, {String? address = null}) async {
final index = address != null
? walletAddresses.allAddresses.firstWhere((element) => element.address == address).index
: null;
Expand Down
7 changes: 6 additions & 1 deletion cw_bitcoin/lib/litecoin_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'package:collection/collection.dart';
class LitecoinWalletService extends WalletService<
BitcoinNewWalletCredentials,
BitcoinRestoreWalletFromSeedCredentials,
BitcoinRestoreWalletFromWIFCredentials> {
BitcoinRestoreWalletFromWIFCredentials,BitcoinNewWalletCredentials> {
LitecoinWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);

final Box<WalletInfo> walletInfoSource;
Expand Down Expand Up @@ -92,6 +92,11 @@ class LitecoinWalletService extends WalletService<
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
}

@override
Future<LitecoinWallet> restoreFromHardwareWallet(BitcoinNewWalletCredentials credentials) {
throw UnimplementedError("Restoring a Litecoin wallet from a hardware wallet is not yet supported!");
}

@override
Future<LitecoinWallet> restoreFromKeys(
BitcoinRestoreWalletFromWIFCredentials credentials, {bool? isTestnet}) async =>
Expand Down
2 changes: 1 addition & 1 deletion cw_bitcoin_cash/lib/src/bitcoin_cash_wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ abstract class BitcoinCashWalletBase extends ElectrumWallet with Store {
}

@override
String signMessage(String message, {String? address = null}) {
Future<String> signMessage(String message, {String? address = null}) async {
final index = address != null
? walletAddresses.allAddresses
.firstWhere((element) => element.address == AddressUtils.toLegacyAddress(address))
Expand Down
7 changes: 6 additions & 1 deletion cw_bitcoin_cash/lib/src/bitcoin_cash_wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:collection/collection.dart';
import 'package:hive/hive.dart';

class BitcoinCashWalletService extends WalletService<BitcoinCashNewWalletCredentials,
BitcoinCashRestoreWalletFromSeedCredentials, BitcoinCashRestoreWalletFromWIFCredentials> {
BitcoinCashRestoreWalletFromSeedCredentials, BitcoinCashRestoreWalletFromWIFCredentials, BitcoinCashNewWalletCredentials> {
BitcoinCashWalletService(this.walletInfoSource, this.unspentCoinsInfoSource);

final Box<WalletInfo> walletInfoSource;
Expand Down Expand Up @@ -93,6 +93,11 @@ class BitcoinCashWalletService extends WalletService<BitcoinCashNewWalletCredent
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
}

@override
Future<BitcoinCashWallet> restoreFromHardwareWallet(BitcoinCashNewWalletCredentials credentials) {
throw UnimplementedError("Restoring a Bitcoin Cash wallet from a hardware wallet is not yet supported!");
}

@override
Future<BitcoinCashWallet> restoreFromKeys(credentials, {bool? isTestnet}) {
// TODO: implement restoreFromKeys
Expand Down
27 changes: 27 additions & 0 deletions cw_core/lib/hardware/device_connection_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:cw_core/wallet_type.dart';

enum DeviceConnectionType {
usb,
ble;

static List<DeviceConnectionType> supportedConnectionTypes(WalletType walletType,
[bool isIOS = false]) {
switch (walletType) {
case WalletType.ethereum:
case WalletType.polygon:
if (isIOS) return [DeviceConnectionType.ble];
return [DeviceConnectionType.ble, DeviceConnectionType.usb];
default:
return [];
}
}

String get iconString {
switch (this) {
case ble:
return 'assets/images/bluetooth.png';
case usb:
return 'assets/images/usb.png';
}
}
}
7 changes: 7 additions & 0 deletions cw_core/lib/hardware/device_not_connected_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class DeviceNotConnectedException implements Exception {
final String message;

DeviceNotConnectedException({
this.message = '',
});
}
3 changes: 2 additions & 1 deletion cw_core/lib/hive_type_ids.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ const ERC20_TOKEN_TYPE_ID = 12;
const NANO_ACCOUNT_TYPE_ID = 13;
const POW_NODE_TYPE_ID = 14;
const DERIVATION_TYPE_TYPE_ID = 15;
const SPL_TOKEN_TYPE_ID = 16;
const SPL_TOKEN_TYPE_ID = 16;
const HARDWARE_WALLET_TYPE_TYPE_ID = 17;
4 changes: 3 additions & 1 deletion cw_core/lib/wallet_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans

bool get isEnabledAutoGenerateSubaddress => false;

bool get isHardwareWallet => walletInfo.isHardwareWallet;

Future<void> connectToNode({required Node node});

// there is a default definition here because only coins with a pow node (nano based) need to override this
Expand Down Expand Up @@ -88,7 +90,7 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans

Future<void> renameWalletFiles(String newWalletName);

String signMessage(String message, {String? address = null}) => throw UnimplementedError();
Future<String> signMessage(String message, {String? address = null}) => throw UnimplementedError();

bool? isTestnet;
}
2 changes: 2 additions & 0 deletions cw_core/lib/wallet_credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class WalletCredentials {
this.password,
this.derivationType,
this.derivationPath,
this.hardwareWalletType,
});

final String name;
Expand All @@ -18,4 +19,5 @@ abstract class WalletCredentials {
DerivationType? derivationType;
String? derivationPath;
WalletInfo? walletInfo;
HardwareWalletType? hardwareWalletType;
}
74 changes: 45 additions & 29 deletions cw_core/lib/wallet_info.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

import 'package:cw_core/address_info.dart';
import 'package:cw_core/hive_type_ids.dart';
import 'package:cw_core/wallet_type.dart';
Expand All @@ -22,6 +23,12 @@ enum DerivationType {
electrum2,
}

@HiveType(typeId: HARDWARE_WALLET_TYPE_TYPE_ID)
enum HardwareWalletType {
@HiveField(0)
ledger,
}

class DerivationInfo {
DerivationInfo({
required this.derivationType,
Expand All @@ -45,21 +52,22 @@ class DerivationInfo {
@HiveType(typeId: WalletInfo.typeId)
class WalletInfo extends HiveObject {
WalletInfo(
this.id,
this.name,
this.type,
this.isRecovery,
this.restoreHeight,
this.timestamp,
this.dirPath,
this.path,
this.address,
this.yatEid,
this.yatLastUsedAddressRaw,
this.showIntroCakePayCard,
this.derivationType,
this.derivationPath)
: _yatLastUsedAddressController = StreamController<String>.broadcast();
this.id,
this.name,
this.type,
this.isRecovery,
this.restoreHeight,
this.timestamp,
this.dirPath,
this.path,
this.address,
this.yatEid,
this.yatLastUsedAddressRaw,
this.showIntroCakePayCard,
this.derivationType,
this.derivationPath,
this.hardwareWalletType,
) : _yatLastUsedAddressController = StreamController<String>.broadcast();

factory WalletInfo.external({
required String id,
Expand All @@ -76,22 +84,25 @@ class WalletInfo extends HiveObject {
String yatLastUsedAddressRaw = '',
DerivationType? derivationType,
String? derivationPath,
HardwareWalletType? hardwareWalletType,
}) {
return WalletInfo(
id,
name,
type,
isRecovery,
restoreHeight,
date.millisecondsSinceEpoch,
dirPath,
path,
address,
yatEid,
yatLastUsedAddressRaw,
showIntroCakePayCard,
derivationType,
derivationPath);
id,
name,
type,
isRecovery,
restoreHeight,
date.millisecondsSinceEpoch,
dirPath,
path,
address,
yatEid,
yatLastUsedAddressRaw,
showIntroCakePayCard,
derivationType,
derivationPath,
hardwareWalletType,
);
}

static const typeId = WALLET_INFO_TYPE_ID;
Expand Down Expand Up @@ -154,6 +165,9 @@ class WalletInfo extends HiveObject {
@HiveField(19)
String? network;

@HiveField(20)
HardwareWalletType? hardwareWalletType;

String get yatLastUsedAddress => yatLastUsedAddressRaw ?? '';

set yatLastUsedAddress(String address) {
Expand All @@ -170,6 +184,8 @@ class WalletInfo extends HiveObject {
return showIntroCakePayCard!;
}

bool get isHardwareWallet => hardwareWalletType != null;

DateTime get date => DateTime.fromMillisecondsSinceEpoch(timestamp);

Stream<String> get yatLastUsedAddressStream => _yatLastUsedAddressController.stream;
Expand Down
4 changes: 3 additions & 1 deletion cw_core/lib/wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import 'package:cw_core/wallet_credentials.dart';
import 'package:cw_core/wallet_type.dart';

abstract class WalletService<N extends WalletCredentials, RFS extends WalletCredentials,
RFK extends WalletCredentials> {
RFK extends WalletCredentials, RFH extends WalletCredentials> {
WalletType getType();

Future<WalletBase> create(N credentials, {bool? isTestnet});

Future<WalletBase> restoreFromHardwareWallet(RFH credentials);

Future<WalletBase> restoreFromSeed(RFS credentials, {bool? isTestnet});

Future<WalletBase> restoreFromKeys(RFK credentials, {bool? isTestnet});
Expand Down
18 changes: 17 additions & 1 deletion cw_ethereum/lib/ethereum_wallet_service.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:bip39/bip39.dart' as bip39;
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_ethereum/ethereum_client.dart';
import 'package:cw_ethereum/ethereum_mnemonics_exception.dart';
import 'package:cw_ethereum/ethereum_wallet.dart';
import 'package:cw_evm/evm_chain_wallet_creation_credentials.dart';
import 'package:cw_evm/evm_chain_wallet_service.dart';
import 'package:bip39/bip39.dart' as bip39;

class EthereumWalletService extends EVMChainWalletService<EthereumWallet> {
EthereumWalletService(super.walletInfoSource, {required this.client});
Expand Down Expand Up @@ -82,6 +82,22 @@ class EthereumWalletService extends EVMChainWalletService<EthereumWallet> {
await walletInfoSource.put(currentWalletInfo.key, newWalletInfo);
}

@override
Future<EthereumWallet> restoreFromHardwareWallet(
EVMChainRestoreWalletFromHardware credentials) async {
final wallet = EthereumWallet(
walletInfo: credentials.walletInfo!,
password: credentials.password!,
client: client,
);

await wallet.init();
wallet.addInitialTokens();
await wallet.save();

return wallet;
}

@override
Future<EthereumWallet> restoreFromKeys(EVMChainRestoreWalletFromPrivateKey credentials,
{bool? isTestnet}) async {
Expand Down
6 changes: 6 additions & 0 deletions cw_ethereum/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ dependencies:
path: ../cw_evm
hive: ^2.2.3

dependency_overrides:
web3dart:
git:
url: https://github.com/cake-tech/web3dart.git
ref: cake

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down