From 265aefb5ac393931f967983a0bd85922c950eb79 Mon Sep 17 00:00:00 2001 From: MetalMallard Date: Fri, 26 Nov 2021 13:58:21 +0100 Subject: [PATCH] Adding signTypedDataV4 method to interop.js and equivalent method to MetaMaskService.cs --- MetaMask.Blazor/MetaMaskService.cs | 14 +++++++++++++ MetaMask.Blazor/wwwroot/metaMaskJsInterop.js | 21 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/MetaMask.Blazor/MetaMaskService.cs b/MetaMask.Blazor/MetaMaskService.cs index ecec1c5..c04f16a 100644 --- a/MetaMask.Blazor/MetaMaskService.cs +++ b/MetaMask.Blazor/MetaMaskService.cs @@ -162,6 +162,20 @@ public async ValueTask SignTypedData(string label, string value) throw; } } + + public async ValueTask SignTypedDataV4(string typedData) + { + var module = await moduleTask.Value; + try + { + return await module.InvokeAsync("signTypedDataV4", typedData); + } + catch (Exception ex) + { + HandleExceptions(ex); + throw; + } + } public async ValueTask SendTransaction(string to, BigInteger weiValue, string? data = null) { diff --git a/MetaMask.Blazor/wwwroot/metaMaskJsInterop.js b/MetaMask.Blazor/wwwroot/metaMaskJsInterop.js index 5f8f504..90bbd65 100644 --- a/MetaMask.Blazor/wwwroot/metaMaskJsInterop.js +++ b/MetaMask.Blazor/wwwroot/metaMaskJsInterop.js @@ -117,6 +117,27 @@ export async function signTypedData(label, value) { } } +export async function signTypedDataV4(typedData) { + await checkMetaMask(); + + try { + var result = await ethereum.request({ + method: 'eth_signTypedData_v4', + params: + [ + ethereum.selectedAddress, + typedData + ], + from: ethereum.selectedAddress + }); + + return result; + } catch (error) { + // User denied account access... + throw "UserDenied" + } +} + export async function sendTransaction(to, value, data) { await checkMetaMask();