Skip to content

Commit

Permalink
Merge pull request #307 from WalletConnect/chores/smart_contracts_int…
Browse files Browse the repository at this point in the history
…eraction_fixes

Chores/smart contracts interaction fixes
  • Loading branch information
quetool authored Aug 12, 2024
2 parents 0090cb4 + 7039c0f commit 4cfb17a
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 133 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.3.1-beta02
## 2.3.1

- Added Connectivity check to core and throw exceptions when internet connection is gone
- Fix for https://github.com/WalletConnect/WalletConnectFlutterV2/issues/303 (EIP-55 validation for SIWE)
Expand Down
7 changes: 7 additions & 0 deletions example/dapp/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
PODS:
- appcheck (1.0.3):
- Flutter
- connectivity_plus (0.0.1):
- Flutter
- FlutterMacOS
- Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1):
- Flutter
Expand All @@ -14,6 +17,7 @@ PODS:

DEPENDENCIES:
- appcheck (from `.symlinks/plugins/appcheck/ios`)
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/darwin`)
- Flutter (from `Flutter`)
- flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand All @@ -23,6 +27,8 @@ DEPENDENCIES:
EXTERNAL SOURCES:
appcheck:
:path: ".symlinks/plugins/appcheck/ios"
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/darwin"
Flutter:
:path: Flutter
flutter_keyboard_visibility:
Expand All @@ -36,6 +42,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
appcheck: e1ab9d4e03736f03e0401554a134d1ed502d7629
connectivity_plus: ddd7f30999e1faaef5967c23d5b6d503d10434db
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
Expand Down
1 change: 0 additions & 1 deletion example/dapp/lib/utils/crypto/eip155.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class EIP155 {
return web3App.requestWriteContract(
topic: topic,
chainId: sepolia.chainId,
rpcUrl: sepolia.rpc.first,
deployedContract: deployedContract,
functionName: 'transfer',
transaction: Transaction(
Expand Down
2 changes: 2 additions & 0 deletions example/dapp/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import FlutterMacOS
import Foundation

import connectivity_plus
import package_info_plus
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
Expand Down
6 changes: 4 additions & 2 deletions example/dapp/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ dependencies:
# intl: ^0.19.0
package_info_plus: ^7.0.0
walletconnect_modal_flutter: ^2.1.20
# walletconnect_flutter_v2:
# path: ../..

dependency_overrides:
walletconnect_flutter_v2:
path: ../..

dev_dependencies:
flutter_test:
Expand Down
3 changes: 3 additions & 0 deletions example/dapp/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions example/dapp/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
url_launcher_windows
)

Expand Down
7 changes: 5 additions & 2 deletions example/wallet/lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,11 @@ class __DataContainerState extends State<_DataContainer> {
],
),
ImageFiltered(
imageFilter:
ImageFilter.blur(sigmaX: blurValue, sigmaY: blurValue),
imageFilter: ImageFilter.blur(
sigmaX: blurValue,
sigmaY: blurValue,
tileMode: TileMode.decal,
),
child: Text(
widget.data,
style: const TextStyle(
Expand Down
1 change: 0 additions & 1 deletion lib/apis/sign_api/i_sign_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ abstract class ISignClient {
Future<dynamic> requestWriteContract({
required String topic,
required String chainId,
required String rpcUrl,
required DeployedContract deployedContract,
required String functionName,
required Transaction transaction,
Expand Down
1 change: 0 additions & 1 deletion lib/apis/sign_api/i_sign_engine_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ abstract class ISignEngineApp extends ISignEngineCommon {
Future<dynamic> requestWriteContract({
required String topic,
required String chainId,
required String rpcUrl,
required DeployedContract deployedContract,
required String functionName,
required Transaction transaction,
Expand Down
6 changes: 2 additions & 4 deletions lib/apis/sign_api/sign_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class SignClient implements ISignClient {
required String functionName,
required String rpcUrl,
EthereumAddress? sender,
List parameters = const [],
List<dynamic> parameters = const [],
}) async {
try {
return await engine.requestReadContract(
Expand All @@ -312,18 +312,16 @@ class SignClient implements ISignClient {
Future<dynamic> requestWriteContract({
required String topic,
required String chainId,
required String rpcUrl,
required DeployedContract deployedContract,
required String functionName,
required Transaction transaction,
String? method,
List parameters = const [],
String? method,
}) async {
try {
return await engine.requestWriteContract(
topic: topic,
chainId: chainId,
rpcUrl: rpcUrl,
deployedContract: deployedContract,
functionName: functionName,
transaction: transaction,
Expand Down
38 changes: 14 additions & 24 deletions lib/apis/sign_api/sign_engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:http/http.dart' as http;
import 'package:walletconnect_flutter_v2/apis/core/pairing/utils/json_rpc_utils.dart';
import 'package:walletconnect_flutter_v2/apis/core/store/i_generic_store.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/i_sessions.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/custom_credentials.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/sign_api_validator_utils.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/recaps_utils.dart';
Expand Down Expand Up @@ -543,27 +542,20 @@ class SignEngine implements ISignEngine {
Future<dynamic> requestWriteContract({
required String topic,
required String chainId,
required String rpcUrl,
required DeployedContract deployedContract,
required String functionName,
required Transaction transaction,
String? method,
List<dynamic> parameters = const [],
String? method,
}) async {
if (transaction.from == null) {
throw Exception('Transaction must include `from` value');
}
final credentials = CustomCredentials(
signEngine: this,
topic: topic,
chainId: chainId,
address: transaction.from!,
method: method,
);

final trx = Transaction.callContract(
contract: deployedContract,
function: deployedContract.function(functionName),
from: credentials.address,
from: transaction.from!,
value: transaction.value,
maxGas: transaction.maxGas,
gasPrice: transaction.gasPrice,
Expand All @@ -573,13 +565,13 @@ class SignEngine implements ISignEngine {
parameters: parameters,
);

if (chainId.contains(':')) {
chainId = chainId.split(':').last;
}
return await Web3Client(rpcUrl, http.Client()).sendTransaction(
credentials,
trx,
chainId: int.parse(chainId),
return await request(
topic: topic,
chainId: chainId,
request: SessionRequestParams(
method: method ?? MethodsConstants.ethSendTransaction,
params: [trx.toJson()],
),
);
}

Expand Down Expand Up @@ -1869,11 +1861,10 @@ class SignEngine implements ISignEngine {
);

final walletAddress = AddressUtils.getDidAddress(payload.iss);
final ethAddress = EthereumAddress.fromHex(walletAddress);
final chainId = AddressUtils.getDidChainId(payload.iss);

final isValid = await AuthSignature.verifySignature(
ethAddress.hexEip55,
walletAddress.toEIP55(),
reconstructed,
signature,
chainId,
Expand All @@ -1892,7 +1883,6 @@ class SignEngine implements ISignEngine {
final header =
'${cacaoPayload.domain} wants you to sign in with your Ethereum account:';
final walletAddress = AddressUtils.getDidAddress(iss);
final ethAddress = EthereumAddress.fromHex(walletAddress);

if (cacaoPayload.aud.isEmpty) {
throw WalletConnectError(code: -1, message: 'aud is required');
Expand Down Expand Up @@ -1929,7 +1919,7 @@ class SignEngine implements ISignEngine {

final message = [
header,
ethAddress.hexEip55,
walletAddress.toEIP55(),
'',
statement,
'',
Expand Down Expand Up @@ -2390,7 +2380,7 @@ class SignEngine implements ISignEngine {

final parsedAddress = AddressUtils.getDidAddress(payload.iss);
for (var chain in approvedChains.toSet()) {
approvedAccounts.add('$chain:$parsedAddress');
approvedAccounts.add('$chain:${parsedAddress.toEIP55()}');
}
}
} on WalletConnectError catch (e) {
Expand Down Expand Up @@ -2589,7 +2579,7 @@ class SignEngine implements ISignEngine {

final parsedAddress = AddressUtils.getDidAddress(payload.iss);
for (var chain in approvedChains.toSet()) {
approvedAccounts.add('$chain:$parsedAddress');
approvedAccounts.add('$chain:${parsedAddress.toEIP55()}');
}
}

Expand Down
8 changes: 8 additions & 0 deletions lib/apis/sign_api/utils/auth/address_utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';

class AddressUtils {
static String getDidAddress(String iss) {
return iss.split(':').last;
Expand All @@ -11,3 +13,9 @@ class AddressUtils {
return iss.substring(iss.indexOf(RegExp(r':')) + 1);
}
}

extension AddressUtilsExtension on String {
String toEIP55() {
return EthereumAddress.fromHex(this).hexEip55;
}
}
3 changes: 3 additions & 0 deletions lib/apis/sign_api/utils/auth/auth_signature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:walletconnect_flutter_v2/apis/core/pairing/utils/json_rpc_utils.
import 'package:walletconnect_flutter_v2/apis/models/basic_models.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/models/auth/common_auth_models.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/models/auth/session_auth_models.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/address_utils.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/auth_constants.dart';
import 'package:walletconnect_flutter_v2/apis/sign_api/utils/auth/recaps_utils.dart';
import 'package:web3dart/crypto.dart' as crypto;
Expand Down Expand Up @@ -199,6 +200,8 @@ class AuthSignature {
if (!iss.contains('did:pkh:')) {
iss = 'did:pkh:$iss';
}
final address = AddressUtils.getDidAddress(iss);
iss = iss.replaceAll(address, address.toEIP55());
return Cacao(
h: const CacaoHeader(t: CacaoHeader.CAIP122),
p: CacaoPayload.fromRequestPayload(
Expand Down
80 changes: 0 additions & 80 deletions lib/apis/sign_api/utils/custom_credentials.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/apis/utils/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'package:web3dart/crypto.dart' as crypto;
extension TransactionExtension on Transaction {
Map<String, dynamic> toJson() {
return {
if (from != null) 'from': from!.hex,
if (to != null) 'to': to!.hex,
if (from != null) 'from': from!.hexEip55,
if (to != null) 'to': to!.hexEip55,
if (maxGas != null) 'gas': '0x${maxGas!.toRadixString(16)}',
if (gasPrice != null)
'gasPrice': '0x${gasPrice!.getInWei.toRadixString(16)}',
Expand Down
Loading

0 comments on commit 4cfb17a

Please sign in to comment.