-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/add bitbox support #18
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2a9769b
fix: loading wallet after creation/restoring and abstracting the wall…
konstantinullrich 391311e
feat: add bitbox
konstantinullrich bad82e7
Merge branch 'trunk' into feature/add-bitbox-support
konstantinullrich 0f232fb
refactor: rename Wallet to SoftwareWallet
konstantinullrich 5f583e4
Update lib/styles/styles.dart
konstantinullrich 7532952
Update lib/styles/styles.dart
konstantinullrich c6a893e
fix: correct typo in BottomSheet text style constants
konstantinullrich ded63c8
Merge branch 'trunk' into feature/add-bitbox-support
konstantinullrich e30e7f4
refactor: use `defaultTargetPlatform` for platform checks and conditi…
konstantinullrich 9d23138
Merge branch 'trunk' into feature/add-bitbox-support
konstantinullrich f0f90ab
refactor: remove unused `RestoreWalletState` and update `SoftwareWall…
konstantinullrich d7191c2
chore: update dependencies and improve README setup instructions
konstantinullrich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import 'package:bitbox_flutter/bitbox_flutter.dart' as sdk; | ||
| import 'package:realunit_wallet/packages/hardware_wallet/bitbox_credentials.dart'; | ||
|
|
||
| class BitboxService { | ||
| BitboxService() { | ||
| bitboxManager = sdk.BitboxManager(); | ||
| } | ||
|
|
||
| late sdk.BitboxManager bitboxManager; | ||
|
|
||
| Future<List<sdk.BitboxDevice>> getAllUsbDevices() => bitboxManager.devices; | ||
|
|
||
| BitboxCredentials getCredentials(String address) => | ||
| BitboxCredentials(address)..setBitbox(bitboxManager); | ||
|
|
||
| Future<void> connectDevice(sdk.BitboxDevice device) async { | ||
| await bitboxManager.connect(device); | ||
| final didInit = await bitboxManager.initBitBox(); | ||
|
|
||
| if (!didInit) throw Exception("Failed to init"); | ||
|
|
||
| final didVerify = await bitboxManager.channelHashVerify(); | ||
|
|
||
| if (!didVerify) throw Exception("Failed to verify"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import 'dart:async'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:bitbox_flutter/bitbox_manager.dart'; | ||
| import 'package:web3dart/crypto.dart'; | ||
| import 'package:web3dart/web3dart.dart'; | ||
|
|
||
| class BitboxCredentials extends CredentialsWithKnownAddress { | ||
| final String _address; | ||
|
|
||
| BitboxManager? bitboxManager; | ||
| String? derivationPath; | ||
|
|
||
| BitboxCredentials(this._address); | ||
|
|
||
| @override | ||
| EthereumAddress get address => EthereumAddress.fromHex(_address); | ||
|
|
||
| void setBitbox(BitboxManager connection, [String? derivationPath_]) { | ||
| bitboxManager = connection; | ||
| derivationPath = derivationPath_ ?? "m/44'/60'/0'/0/0"; | ||
| } | ||
|
|
||
| @override | ||
| MsgSignature signToEcSignature(Uint8List payload, {int? chainId, bool isEIP1559 = false}) => | ||
| throw UnimplementedError("EvmLedgerCredentials.signToEcSignature"); | ||
|
|
||
| @override | ||
| Future<MsgSignature> signToSignature(Uint8List payload, | ||
| {int? chainId, bool isEIP1559 = false}) async { | ||
| if (bitboxManager == null) { | ||
| throw Exception("Bitbox not connected"); | ||
| } | ||
|
|
||
| if (isEIP1559) payload = payload.sublist(1); | ||
| final sig = await bitboxManager! | ||
| .signETHRLPTransaction(chainId ?? 1, derivationPath!, bytesToHex(payload), isEIP1559); | ||
|
|
||
| final r = bytesToHex(sig.sublist(0, 32)); | ||
| final s = bytesToHex(sig.sublist(32, 32 + 32)); | ||
| final v = sig.last.toInt(); | ||
|
|
||
| if (isEIP1559) { | ||
| return MsgSignature(BigInt.parse(r, radix: 16), BigInt.parse(s, radix: 16), v); | ||
| } | ||
|
|
||
| var truncChainId = chainId ?? 1; | ||
| while (truncChainId.bitLength > 32) { | ||
| truncChainId >>= 8; | ||
| } | ||
|
|
||
| final truncTarget = truncChainId * 2 + 35; | ||
|
|
||
| int parity = v; | ||
| if (truncTarget & 0xff == v) { | ||
| parity = 0; | ||
| } else if ((truncTarget + 1) & 0xff == v) { | ||
| parity = 1; | ||
| } | ||
|
|
||
| // https://github.com/ethereumjs/ethereumjs-util/blob/8ffe697fafb33cefc7b7ec01c11e3a7da787fe0e/src/signature.ts#L26 | ||
| final chainIdV = chainId != null ? (parity + (chainId * 2 + 35)) : parity; | ||
|
|
||
| return MsgSignature(BigInt.parse(r, radix: 16), BigInt.parse(s, radix: 16), chainIdV); | ||
| } | ||
|
|
||
| @override | ||
| Future<Uint8List> signPersonalMessage(Uint8List payload, {int? chainId}) async { | ||
| if (isNotConnected) throw Exception("Bitbox not connected"); | ||
| return await bitboxManager!.signETHMessage(chainId ?? 1, derivationPath!, payload); | ||
| } | ||
|
|
||
| @override | ||
| Uint8List signPersonalMessageToUint8List(Uint8List payload, {int? chainId}) => | ||
| throw UnimplementedError("EvmLedgerCredentials.signPersonalMessageToUint8List"); | ||
|
|
||
| bool get isNotConnected => bitboxManager == null; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,19 @@ | ||
| import 'package:realunit_wallet/packages/storage/database.dart'; | ||
| import 'package:realunit_wallet/packages/storage/wallet_storage.dart'; | ||
| import 'package:realunit_wallet/packages/wallet/wallet.dart'; | ||
|
|
||
| class WalletRepository { | ||
| final AppDatabase _appDatabase; | ||
|
|
||
| const WalletRepository(this._appDatabase); | ||
|
|
||
| Future<int> createWallet(String name, String seed) => | ||
| _appDatabase.insertWallet(name, seed); | ||
| Future<int> createWallet(String name, WalletType type, String seed) => | ||
| _appDatabase.insertWallet(name, seed, "", type.index); | ||
|
|
||
| Future<WalletInfo?> getWalletById(int id) => | ||
| _appDatabase.getWalletById(id); | ||
| Future<int> createViewWallet(String name, WalletType type, String address) => | ||
| _appDatabase.insertWallet(name, "", address, type.index); | ||
|
|
||
| Future<WalletInfo?> getWalletById(int id) => _appDatabase.getWalletById(id); | ||
|
|
||
| Future<void> deleteWallet(int id) => _appDatabase.deleteWallet(id); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| import 'dart:io'; | ||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| class DeviceInfo { | ||
| DeviceInfo._(); | ||
|
|
||
| static DeviceInfo get instance => DeviceInfo._(); | ||
|
|
||
| bool get isMobile => Platform.isAndroid || Platform.isIOS; | ||
| bool get isMobile => [TargetPlatform.android, TargetPlatform.iOS].contains(defaultTargetPlatform); | ||
|
|
||
| bool get isDesktop => | ||
| Platform.isMacOS || Platform.isWindows || Platform.isLinux; | ||
| bool get isDesktop => [TargetPlatform.macOS, TargetPlatform.windows, TargetPlatform.linux] | ||
| .contains(defaultTargetPlatform); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.