diff --git a/example/wallet/lib/dependencies/chains/evm_service.dart b/example/wallet/lib/dependencies/chains/evm_service.dart index a8ff39b5..95e0e4a3 100644 --- a/example/wallet/lib/dependencies/chains/evm_service.dart +++ b/example/wallet/lib/dependencies/chains/evm_service.dart @@ -51,7 +51,7 @@ class EVMService { 'eth_signTransaction': ethSignTransaction, 'eth_sendTransaction': ethSendTransaction, 'eth_signTypedData': ethSignTypedData, - 'eth_signTypedData_v4': ethSignTypedData, + 'eth_signTypedData_v4': ethSignTypedDataV4, 'wallet_switchEthereumChain': switchChain, 'wallet_addEthereumChain': addChain, // add whatever method/handler you want to support @@ -162,7 +162,7 @@ class EVMService { debugPrint('[$runtimeType] ethSignTypedData request: $parameters'); final pRequest = _web3Wallet.pendingRequests.getAll().first; - final data = parameters[1] as String; + final data = EthUtils.getDataFromParamsList(parameters); var response = JsonRpcResponse( id: pRequest.id, jsonrpc: '2.0', @@ -176,7 +176,7 @@ class EVMService { final signature = EthSigUtil.signTypedData( privateKey: keys[0].privateKey, jsonData: data, - version: TypedDataVersion.V4, + version: TypedDataVersion.V1, ); response = response.copyWith(result: signature); } catch (e) { @@ -199,6 +199,47 @@ class EVMService { ); } + Future ethSignTypedDataV4(String topic, dynamic parameters) async { + debugPrint('[$runtimeType] ethSignTypedDataV4 request: $parameters'); + + final pRequest = _web3Wallet.pendingRequests.getAll().first; + final data = EthUtils.getDataFromParamsList(parameters); + var response = JsonRpcResponse( + id: pRequest.id, + jsonrpc: '2.0', + ); + if (await requestApproval(data)) { + try { + final keys = GetIt.I().getKeysForChain( + chainSupported.chainId, + ); + + final signature = EthSigUtil.signTypedData( + privateKey: keys[0].privateKey, + jsonData: data, + version: TypedDataVersion.V4, + ); + response = response.copyWith(result: signature); + } catch (e) { + debugPrint('[$runtimeType] ethSignTypedDataV4 error $e'); + response = response.copyWith( + error: JsonRpcError(code: 0, message: e.toString()), + ); + } + } else { + response = response.copyWith( + error: const JsonRpcError(code: 5001, message: 'User rejected method'), + ); + } + + _goBackToDapp(topic, response.result ?? response.error); + + return _web3Wallet.respondSessionRequest( + topic: topic, + response: response, + ); + } + Future ethSignTransaction(String topic, dynamic parameters) async { debugPrint('[$runtimeType] ethSignTransaction request: $parameters'); final pRequest = _web3Wallet.pendingRequests.getAll().first; @@ -207,8 +248,8 @@ class EVMService { jsonrpc: '2.0', ); - final tJson = parameters[0] as Map; - final result = await approveTransaction(tJson); + final data = EthUtils.getTransactionFromParams(parameters); + final result = await approveTransaction(data); if (result is Transaction) { try { // Load the private key @@ -259,8 +300,8 @@ class EVMService { jsonrpc: '2.0', ); - final tJson = parameters[0] as Map; - final result = await approveTransaction(tJson); + final data = EthUtils.getTransactionFromParams(parameters); + final result = await approveTransaction(data); if (result is Transaction) { try { // Load the private key