Skip to content

Commit

Permalink
Merge pull request #6 from AlexandreBazeaud/master
Browse files Browse the repository at this point in the history
Adding signTypedDataV4
  • Loading branch information
michielpost authored Nov 26, 2021
2 parents b5be06b + 265aefb commit 72a0016
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions MetaMask.Blazor/MetaMaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ public async ValueTask<string> SignTypedData(string label, string value)
throw;
}
}

public async ValueTask<string> SignTypedDataV4(string typedData)
{
var module = await moduleTask.Value;
try
{
return await module.InvokeAsync<string>("signTypedDataV4", typedData);
}
catch (Exception ex)
{
HandleExceptions(ex);
throw;
}
}

public async ValueTask<string> SendTransaction(string to, BigInteger weiValue, string? data = null)
{
Expand Down
21 changes: 21 additions & 0 deletions MetaMask.Blazor/wwwroot/metaMaskJsInterop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 72a0016

Please sign in to comment.