Skip to content

Commit

Permalink
app: Remove dependency between orchid_ticket and vpn code.
Browse files Browse the repository at this point in the history
  • Loading branch information
patniemeyer committed Feb 23, 2024
1 parent cedd75a commit 9b32f6e
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 35 deletions.
23 changes: 11 additions & 12 deletions gui-orchid/lib/api/orchid_crypto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)}');
Expand Down Expand Up @@ -93,7 +90,6 @@ class Crypto {
static String formatSecretFixed(BigInt private) {
return private.toRadixString(16).padLeft(64, '0');
}

}

class EthereumKeyPair {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/api/orchid_eth/orchid_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/api/orchid_eth/orchid_account_mock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 9 additions & 8 deletions gui-orchid/lib/api/orchid_eth/orchid_ticket.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
}
Expand All @@ -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(
Expand Down Expand Up @@ -150,3 +150,4 @@ class OrchidTicket {
print('r: ${this.sig_r}\ns: ${this.sig_s}');
}
}

1 change: 1 addition & 0 deletions gui-orchid/lib/api/orchid_eth/v0/orchid_eth_v0.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/api/orchid_eth/v1/orchid_eth_v1_rpc.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion gui-orchid/lib/orchid/account/account_finder.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
8 changes: 2 additions & 6 deletions gui-orchid/lib/orchid/account/account_store.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<Account> get accounts {
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/orchid/account/account_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/orchid/account/orchid_account_entry.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/orchid/menu/orchid_key_selector_menu.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion gui-orchid/lib/pages/circuit/orchid_hop_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion gui-orchid/lib/pages/connect/connect_page.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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';
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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/pages/connect/welcome_panel.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion gui-orchid/lib/pages/purchase/purchase_page.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/vpn/model/orchid_hop.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 3 additions & 2 deletions gui-orchid/lib/vpn/purchase/orchid_pac_seller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}

/*
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/vpn/purchase/orchid_pac_server.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
1 change: 1 addition & 0 deletions gui-orchid/lib/vpn/purchase/orchid_pac_transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 9b32f6e

Please sign in to comment.