diff --git a/gui-orchid/lib/api/orchid_crypto.dart b/gui-orchid/lib/api/orchid_crypto.dart index d8ce23dbd..154db4de9 100644 --- a/gui-orchid/lib/api/orchid_crypto.dart +++ b/gui-orchid/lib/api/orchid_crypto.dart @@ -13,9 +13,6 @@ import 'package:uuid/uuid_util.dart'; import 'package:web3dart/credentials.dart' as web3; import 'package:web3dart/crypto.dart'; -import 'orchid_keys.dart'; -export 'orchid_keys.dart'; - class Crypto { static final ECDomainParameters curve = ECCurve_secp256k1(); @@ -52,14 +49,14 @@ class Crypto { final ethereumAddress = Uint8List.view( hashed.buffer, 32 /*bytes*/ - 20 /*eth address length bytes*/); - return new EthereumKeyPair( + return EthereumKeyPair( private: privateKey, public: toHex(publicKey), addressString: toHex(ethereumAddress)); } static String toHex(Uint8List bytes) { - var result = new StringBuffer('0x'); + var result = StringBuffer('0x'); bytes.forEach((val) { var pad = val < 16 ? '0' : ''; result.write('$pad${val.toRadixString(16)}'); @@ -93,7 +90,6 @@ class Crypto { static String formatSecretFixed(BigInt private) { return private.toRadixString(16).padLeft(64, '0'); } - } class EthereumKeyPair { @@ -179,7 +175,9 @@ class EthereumAddress { EthereumAddress.from(String text) : this.value = parse(text); static fromNullable(String? text) { - if (text == 'null') { return null; } + if (text == 'null') { + return null; + } return text == null ? null : EthereumAddress.from(text); } @@ -190,10 +188,11 @@ class EthereumAddress { final raw = value.toRadixString(16).padLeft(40, '0'); final eip55 = Web3DartUtils.eip55ChecksumEthereumAddress(raw); final hex = prefix ? eip55 : Hex.remove0x(eip55); - if (elide) + if (elide) { return elideAddressString(hex); - else + } else { return hex; + } } static String elideAddressString(String hex) { @@ -265,9 +264,9 @@ class Web3DartUtils { return true; } - static MsgSignature web3Sign(Uint8List payload, StoredEthereumKey key) { - final credentials = web3.EthPrivateKey.fromHex(key.formatSecretFixed()); - //print("payload = ${hex.encode(payload)}"); + static MsgSignature web3Sign(Uint8List payload, BigInt key) { + final web3.EthPrivateKey credentials = + web3.EthPrivateKey.fromHex(Crypto.formatSecretFixed(key)); // Use web3 sign(), not web3 credentials.sign() which does a keccak256 on payload. return sign(payload, credentials.privateKey); } diff --git a/gui-orchid/lib/api/orchid_eth/orchid_account.dart b/gui-orchid/lib/api/orchid_eth/orchid_account.dart index 9dc2fecac..37bbf070e 100644 --- a/gui-orchid/lib/api/orchid_eth/orchid_account.dart +++ b/gui-orchid/lib/api/orchid_eth/orchid_account.dart @@ -4,6 +4,7 @@ import 'package:orchid/api/orchid_eth/v0/orchid_eth_v0.dart'; import 'package:orchid/api/orchid_eth/v0/orchid_market_v0.dart'; import 'package:orchid/api/orchid_eth/v1/orchid_eth_v1.dart'; import 'package:orchid/api/orchid_eth/v1/orchid_market_v1.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/api/orchid_eth/orchid_account_mock.dart'; import 'package:orchid/util/cacheable.dart'; diff --git a/gui-orchid/lib/api/orchid_eth/orchid_account_mock.dart b/gui-orchid/lib/api/orchid_eth/orchid_account_mock.dart index 89a778717..75713ca48 100644 --- a/gui-orchid/lib/api/orchid_eth/orchid_account_mock.dart +++ b/gui-orchid/lib/api/orchid_eth/orchid_account_mock.dart @@ -7,6 +7,7 @@ import 'package:orchid/api/orchid_eth/orchid_market.dart'; import 'package:orchid/api/orchid_eth/token_type.dart'; import 'package:orchid/api/orchid_eth/tokens.dart'; import 'package:orchid/api/orchid_eth/v0/orchid_contract_v0.dart'; +import 'package:orchid/api/orchid_keys.dart'; /// Mock account data for testing and screenshot generation class AccountMock { diff --git a/gui-orchid/lib/api/orchid_eth/orchid_ticket.dart b/gui-orchid/lib/api/orchid_eth/orchid_ticket.dart index 27050ce63..afb17deb4 100644 --- a/gui-orchid/lib/api/orchid_eth/orchid_ticket.dart +++ b/gui-orchid/lib/api/orchid_eth/orchid_ticket.dart @@ -1,11 +1,11 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:convert/convert.dart'; +import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/util/hex.dart'; -import 'dart:typed_data'; import 'package:web3dart/crypto.dart'; -import '../orchid_crypto.dart'; -import 'abi_encode.dart'; import 'package:web3dart/credentials.dart' as web3; +import 'abi_encode.dart'; // Orchid Lottery ticket serialization and evaluation. // This is direct port of the JS version of this class. @@ -30,7 +30,7 @@ class OrchidTicket { required BigInt privateKey, // uint256 int? millisecondsSinceEpoch, }) { - this.initTicketData(data, lotaddr, token, amount, ratio, funder, recipient, + initTicketData(data, lotaddr, token, amount, ratio, funder, recipient, commitment, privateKey, millisecondsSinceEpoch: millisecondsSinceEpoch); } @@ -47,10 +47,10 @@ class OrchidTicket { for (var i = 0; i < str.length; i += 64) { ticket.add(str.substring(i, i + 64)); } - this.packed0 = BigInt.parse(ticket[0], radix: 16); - this.packed1 = BigInt.parse(ticket[1], radix: 16); - this.sig_r = ticket[2].startsWith("0x") ? ticket[2] : '0x' + ticket[2]; - this.sig_s = ticket[3].startsWith("0x") ? ticket[3] : '0x' + ticket[3]; + packed0 = BigInt.parse(ticket[0], radix: 16); + packed1 = BigInt.parse(ticket[1], radix: 16); + sig_r = ticket[2].startsWith("0x") ? ticket[2] : '0x' + ticket[2]; + sig_s = ticket[3].startsWith("0x") ? ticket[3] : '0x' + ticket[3]; } void initTicketData( @@ -150,3 +150,4 @@ class OrchidTicket { print('r: ${this.sig_r}\ns: ${this.sig_s}'); } } + diff --git a/gui-orchid/lib/api/orchid_eth/v0/orchid_eth_v0.dart b/gui-orchid/lib/api/orchid_eth/v0/orchid_eth_v0.dart index 2d5661803..3a11e9d8c 100644 --- a/gui-orchid/lib/api/orchid_eth/v0/orchid_eth_v0.dart +++ b/gui-orchid/lib/api/orchid_eth/v0/orchid_eth_v0.dart @@ -1,3 +1,4 @@ +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_user_param.dart'; import 'package:orchid/api/orchid_eth/eth_rpc.dart'; import 'package:orchid/api/orchid_eth/tokens_legacy.dart'; diff --git a/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1.dart b/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1.dart index dd282e67a..303a5bd5b 100644 --- a/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1.dart +++ b/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1.dart @@ -1,4 +1,5 @@ import 'package:orchid/api/orchid_eth/token_type.dart'; +import 'package:orchid/api/orchid_keys.dart'; import '../chains.dart'; import '../orchid_account.dart'; import '../orchid_lottery.dart'; diff --git a/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1_rpc.dart b/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1_rpc.dart index 12f8ea5ab..8d3aad24e 100644 --- a/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1_rpc.dart +++ b/gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1_rpc.dart @@ -1,4 +1,5 @@ import 'dart:math'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_user_config.dart'; import 'package:orchid/api/orchid_eth/eth_rpc.dart'; import 'package:orchid/api/orchid_eth/token_type.dart'; diff --git a/gui-orchid/lib/api/orchid_user_config/orchid_account_import.dart b/gui-orchid/lib/api/orchid_user_config/orchid_account_import.dart index ff6d2312d..0d97089cd 100644 --- a/gui-orchid/lib/api/orchid_user_config/orchid_account_import.dart +++ b/gui-orchid/lib/api/orchid_user_config/orchid_account_import.dart @@ -1,5 +1,6 @@ import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/api/preferences/user_preferences_keys.dart'; import 'package:orchid/vpn/preferences/user_preferences_vpn.dart'; diff --git a/gui-orchid/lib/orchid/account/account_finder.dart b/gui-orchid/lib/orchid/account/account_finder.dart index e9f52e9aa..95e3d0e1b 100644 --- a/gui-orchid/lib/orchid/account/account_finder.dart +++ b/gui-orchid/lib/orchid/account/account_finder.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:core'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/api/preferences/user_preferences_keys.dart'; import 'account_store.dart'; diff --git a/gui-orchid/lib/orchid/account/account_store.dart b/gui-orchid/lib/orchid/account/account_store.dart index 6b4a6ad10..9e676177e 100644 --- a/gui-orchid/lib/orchid/account/account_store.dart +++ b/gui-orchid/lib/orchid/account/account_store.dart @@ -1,8 +1,8 @@ import 'package:flutter/foundation.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/v0/orchid_eth_v0.dart'; import 'package:orchid/api/orchid_eth/v1/orchid_eth_v1.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/vpn/preferences/user_preferences_vpn.dart'; import 'package:orchid/api/orchid_eth/chains.dart'; @@ -32,11 +32,7 @@ class AccountStore extends ChangeNotifier { AccountStore({ required this.identity, this.discoverAccounts = true, - }) { - if (identity == null) { - throw Exception("identity may not be null"); - } - } + }); /// All accounts known for the identity, unordered. Set get accounts { diff --git a/gui-orchid/lib/orchid/account/account_view_model.dart b/gui-orchid/lib/orchid/account/account_view_model.dart index 8b8be51e1..81d441a80 100644 --- a/gui-orchid/lib/orchid/account/account_view_model.dart +++ b/gui-orchid/lib/orchid/account/account_view_model.dart @@ -3,6 +3,7 @@ import 'package:orchid/api/orchid_eth/chains.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; import 'package:orchid/api/orchid_eth/token_type.dart'; import 'package:orchid/api/orchid_eth/orchid_account_detail.dart'; +import 'package:orchid/api/orchid_keys.dart'; /// The view model for the account // Note: There is duplication in the account detail. Consider cleanup. diff --git a/gui-orchid/lib/orchid/account/orchid_account_entry.dart b/gui-orchid/lib/orchid/account/orchid_account_entry.dart index 2870710eb..b5b715e8b 100644 --- a/gui-orchid/lib/orchid/account/orchid_account_entry.dart +++ b/gui-orchid/lib/orchid/account/orchid_account_entry.dart @@ -1,3 +1,4 @@ +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_account_import.dart'; import 'package:orchid/common/app_buttons.dart'; import 'package:orchid/orchid/orchid.dart'; diff --git a/gui-orchid/lib/orchid/menu/orchid_funder_selector_menu.dart b/gui-orchid/lib/orchid/menu/orchid_funder_selector_menu.dart index d305643b0..ede4ab448 100644 --- a/gui-orchid/lib/orchid/menu/orchid_funder_selector_menu.dart +++ b/gui-orchid/lib/orchid/menu/orchid_funder_selector_menu.dart @@ -1,6 +1,6 @@ +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/orchid/orchid.dart'; import 'dart:async'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; import 'package:orchid/vpn/preferences/user_preferences_vpn.dart'; import 'package:orchid/orchid/orchid_circular_identicon.dart'; diff --git a/gui-orchid/lib/orchid/menu/orchid_key_selector_menu.dart b/gui-orchid/lib/orchid/menu/orchid_key_selector_menu.dart index 22241fb98..2d1579e9f 100644 --- a/gui-orchid/lib/orchid/menu/orchid_key_selector_menu.dart +++ b/gui-orchid/lib/orchid/menu/orchid_key_selector_menu.dart @@ -1,3 +1,4 @@ +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/preferences/user_preferences_keys.dart'; import 'package:orchid/orchid/orchid.dart'; import 'dart:async'; diff --git a/gui-orchid/lib/pages/account_manager/account_manager_page.dart b/gui-orchid/lib/pages/account_manager/account_manager_page.dart index 38a7e45c9..9f94e7c2a 100644 --- a/gui-orchid/lib/pages/account_manager/account_manager_page.dart +++ b/gui-orchid/lib/pages/account_manager/account_manager_page.dart @@ -1,8 +1,8 @@ import 'dart:async'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_account_import.dart'; import 'package:orchid/api/preferences/user_preferences_keys.dart'; import 'package:orchid/orchid/orchid.dart'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/chains.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; import 'package:orchid/api/orchid_platform.dart'; diff --git a/gui-orchid/lib/pages/circuit/orchid_hop_page.dart b/gui-orchid/lib/pages/circuit/orchid_hop_page.dart index 1b84b36bc..22e0e8bee 100644 --- a/gui-orchid/lib/pages/circuit/orchid_hop_page.dart +++ b/gui-orchid/lib/pages/circuit/orchid_hop_page.dart @@ -1,9 +1,9 @@ +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/orchid/orchid.dart'; import 'dart:async'; import 'package:badges/badges.dart' as badge; import 'package:flutter/services.dart'; import 'package:orchid/api/orchid_eth/orchid_lottery.dart'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; import 'package:orchid/api/orchid_eth/orchid_market.dart'; import 'package:orchid/api/orchid_eth/v0/orchid_eth_v0.dart'; diff --git a/gui-orchid/lib/pages/connect/connect_page.dart b/gui-orchid/lib/pages/connect/connect_page.dart index d40c67388..f2094b525 100644 --- a/gui-orchid/lib/pages/connect/connect_page.dart +++ b/gui-orchid/lib/pages/connect/connect_page.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/vpn/preferences/release_version.dart'; import 'package:orchid/orchid/orchid.dart'; import 'package:orchid/api/orchid_eth/v1/orchid_eth_bandwidth_pricing.dart'; @@ -6,7 +7,6 @@ import 'package:orchid/api/preferences/user_preferences_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_user_config.dart'; import 'package:orchid/vpn/monitoring/restart_manager.dart'; import 'package:orchid/api/orchid_eth/orchid_lottery.dart'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; import 'package:orchid/vpn/preferences/user_preferences_vpn.dart'; import 'package:orchid/api/pricing/orchid_pricing.dart'; diff --git a/gui-orchid/lib/pages/connect/welcome_panel.dart b/gui-orchid/lib/pages/connect/welcome_panel.dart index aff307095..8e727ffcc 100644 --- a/gui-orchid/lib/pages/connect/welcome_panel.dart +++ b/gui-orchid/lib/pages/connect/welcome_panel.dart @@ -1,4 +1,5 @@ import 'package:flutter/services.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_account_import.dart'; import 'package:orchid/api/orchid_eth/chains.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; diff --git a/gui-orchid/lib/pages/purchase/purchase_page.dart b/gui-orchid/lib/pages/purchase/purchase_page.dart index ad03f2447..933671da0 100644 --- a/gui-orchid/lib/pages/purchase/purchase_page.dart +++ b/gui-orchid/lib/pages/purchase/purchase_page.dart @@ -1,8 +1,8 @@ import 'package:orchid/api/orchid_eth/v1/orchid_eth_bandwidth_pricing.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/orchid/orchid.dart'; import 'dart:async'; import 'package:orchid/vpn/orchid_api_mock.dart'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/chains.dart'; import 'package:orchid/api/orchid_platform.dart'; import 'package:orchid/api/orchid_urls.dart'; diff --git a/gui-orchid/lib/vpn/model/orchid_hop.dart b/gui-orchid/lib/vpn/model/orchid_hop.dart index 8647b8450..c56c230af 100644 --- a/gui-orchid/lib/vpn/model/orchid_hop.dart +++ b/gui-orchid/lib/vpn/model/orchid_hop.dart @@ -1,6 +1,7 @@ import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/orchid_account.dart'; import 'package:orchid/api/orchid_eth/chains.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/vpn/preferences/user_preferences_vpn.dart'; import 'package:orchid/vpn/model/circuit_hop.dart'; diff --git a/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_generate.dart b/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_generate.dart index 743c81033..f56580b49 100644 --- a/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_generate.dart +++ b/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_generate.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/api/preferences/user_preferences_keys.dart'; import 'package:orchid/api/orchid_crypto.dart'; diff --git a/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_import.dart b/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_import.dart index a3a47d938..789565534 100644 --- a/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_import.dart +++ b/gui-orchid/lib/vpn/orchid_vpn_config/orchid_vpn_config_import.dart @@ -1,7 +1,7 @@ import 'dart:async'; import 'dart:convert'; -import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/chains.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/api/orchid_user_config/orchid_account_import.dart'; import 'package:orchid/api/preferences/user_preferences_keys.dart'; diff --git a/gui-orchid/lib/vpn/purchase/orchid_pac_seller.dart b/gui-orchid/lib/vpn/purchase/orchid_pac_seller.dart index 48cd655b8..136ca5354 100644 --- a/gui-orchid/lib/vpn/purchase/orchid_pac_seller.dart +++ b/gui-orchid/lib/vpn/purchase/orchid_pac_seller.dart @@ -8,6 +8,7 @@ import 'package:orchid/api/orchid_eth/eth_transaction.dart'; import 'package:orchid/api/orchid_eth/token_type.dart'; import 'package:orchid/api/orchid_eth/v1/orchid_contract_v1.dart'; import 'package:orchid/api/orchid_eth/v1/orchid_eth_v1.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_log.dart'; import 'package:orchid/api/pricing/orchid_pricing.dart'; import 'package:orchid/api/pricing/usd.dart'; @@ -115,7 +116,7 @@ class OrchidPacSeller { refill: refill, )); var sig = Web3DartUtils.web3Sign( - keccak256(Uint8List.fromList(packedEditParams)), signerKey); + keccak256(Uint8List.fromList(packedEditParams)), signerKey.private); // The abi encoded seller edit call tx data var encodedSellerEditCall = abiEncodeSellerEdit( @@ -150,7 +151,7 @@ class OrchidPacSeller { var encoded = utf8.encode(msg); Uint8List uint8list = Uint8List.fromList(encoded); - return Web3DartUtils.web3Sign(keccak256(uint8list), signerKey); + return Web3DartUtils.web3Sign(keccak256(uint8list), signerKey.private); } /* diff --git a/gui-orchid/lib/vpn/purchase/orchid_pac_server.dart b/gui-orchid/lib/vpn/purchase/orchid_pac_server.dart index 2a1663aec..4359b1019 100644 --- a/gui-orchid/lib/vpn/purchase/orchid_pac_server.dart +++ b/gui-orchid/lib/vpn/purchase/orchid_pac_server.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:http/http.dart' as http; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_user_config/orchid_user_config.dart'; import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/abi_encode.dart'; diff --git a/gui-orchid/lib/vpn/purchase/orchid_pac_transaction.dart b/gui-orchid/lib/vpn/purchase/orchid_pac_transaction.dart index f15baf233..8a29ca954 100644 --- a/gui-orchid/lib/vpn/purchase/orchid_pac_transaction.dart +++ b/gui-orchid/lib/vpn/purchase/orchid_pac_transaction.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:orchid/api/orchid_crypto.dart'; import 'package:orchid/api/orchid_eth/eth_transaction.dart'; +import 'package:orchid/api/orchid_keys.dart'; import 'package:orchid/api/orchid_language.dart'; import 'package:orchid/api/orchid_platform.dart'; import 'package:orchid/api/preferences/observable_preference.dart';