diff --git a/lib/features/common/contract/token_contract_use_case.dart b/lib/features/common/contract/token_contract_use_case.dart index 16b98567..283723ca 100644 --- a/lib/features/common/contract/token_contract_use_case.dart +++ b/lib/features/common/contract/token_contract_use_case.dart @@ -269,6 +269,12 @@ class TokenContractUseCase extends ReactiveUseCase { .getTokenTransferData(tokenHash, toAddress, amount); } + String signPersonalMessage({required String privateKey, required String message}) { + return _repository.tokenContract + .signPersonalMessage(privateKey: privateKey, message: message); + } + + String signMessage({required String privateKey, required String message}) { return _repository.tokenContract .signMessage(privateKey: privateKey, message: message); diff --git a/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_functions_helper.dart b/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_functions_helper.dart index 779ca0de..d010bf28 100644 --- a/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_functions_helper.dart +++ b/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_functions_helper.dart @@ -91,6 +91,21 @@ class BridgeFunctionsHelper { } } + String? signPersonalMessage( + String hexData, + ) { + loading(true); + try { + final res = tokenContractUseCase.signPersonalMessage( + privateKey: state.account!.privateKey, message: hexData); + return res; + } catch (e, s) { + addError(e, s); + } finally { + loading(false); + } + } + String? signTypedMessage( String hexData, ) { diff --git a/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_helper.dart b/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_helper.dart index 47655bb5..a9aa07e3 100644 --- a/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_helper.dart +++ b/lib/features/dapps/subfeatures/open_dapp/domain/helpers/bridge/bridge_helper.dart @@ -187,7 +187,7 @@ class BridgeHelper { } } - /// This function is used for both sign message and sign personal message + void signMessage({ required Map object, required VoidCallback cancel, @@ -220,6 +220,39 @@ class BridgeHelper { } } + + void signPersonalMessage({ + required Map object, + required VoidCallback cancel, + required Function(String hash) success, + }) async { + final hexData = object['data'] as String; + String message = MXCType.hexToString(hexData); + int chainId = state.network!.chainId; + String name = state.network!.symbol; + + try { + final result = await showSignMessageDialog( + context!, + title: translate('signature_request')!, + message: message, + networkName: '$name ($chainId)', + ); + + if (result != null && result) { + final hash = bridgeFunctionsHelper.signPersonalMessage( + hexData, + ); + if (hash != null) success.call(hash); + } else { + cancel.call(); + } + } catch (e, s) { + cancel.call(); + addError(e, s); + } + } + void signTypedMessage({ required Map object, required VoidCallback cancel, diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart index 56747240..a73f60fa 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_page.dart @@ -100,8 +100,7 @@ class OpenAppPage extends HookConsumerWidget { presenter.changeProgress(progress); presenter.setChain(null); }, - onUpdateVisitedHistory: - (controller, url, androidIsReload) { + onUpdateVisitedHistory: (controller, url, androidIsReload) { presenter.updateCurrentUrl(url); }, shouldOverrideUrlLoading: presenter.checkDeepLink, @@ -137,8 +136,8 @@ class OpenAppPage extends HookConsumerWidget { ); break; case EIP1193.signPersonalMessage: - Map object = params["object"]; - presenter.signMessage( + Map object = params["object"]; + presenter.signPersonalMessage( object: object, cancel: () { controller?.cancel(id); diff --git a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart index 16bc5187..fb12a4fe 100644 --- a/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart +++ b/lib/features/dapps/subfeatures/open_dapp/open_dapp_presenter.dart @@ -296,6 +296,17 @@ class OpenDAppPresenter extends CompletePresenter { success: success, ); + void signPersonalMessage({ + required Map object, + required VoidCallback cancel, + required Function(String hash) success, + }) async => + bridgeHelper.signPersonalMessage( + object: object, + cancel: cancel, + success: success, + ); + void signTypedMessage({ required Map object, required VoidCallback cancel, diff --git a/packages/shared b/packages/shared index f98f0c92..5cbb0d14 160000 --- a/packages/shared +++ b/packages/shared @@ -1 +1 @@ -Subproject commit f98f0c92c2dbebde870c0fe5816fbc2c90d05251 +Subproject commit 5cbb0d141c97876ec2afa7994952f0896c0b2284