michielpost / MetaMask.Blazor

Use MetaMask with Blazor WebAssembly
MIT License
44 stars 21 forks source link

Add personal sign function #20

Closed kochol closed 1 year ago

kochol commented 1 year ago

Personal sign function is used to create SiWE applications and website and backend can verify the sign easily by NEthereum library.

michielpost commented 1 year ago

Thanks, I'll add it to the sample and release it to NuGet.

michielpost commented 1 year ago

Available on NuGet with version 1.9.0

kochol commented 1 year ago

Wow, fast merge.

Here is an example of how to use NEthereum library to verify the signed message.

            // using Nethereum.Signer;

            EthereumMessageSigner signer = new EthereumMessageSigner();
            var address = signer.EncodeUTF8AndEcRecover(Message, SignedMessage);

            address = address.ToLower();
michielpost commented 1 year ago

Great, thanks for the sample to verify the signed message. I included that in the sample app.

kochol commented 1 year ago

One thing to mention here is, I think my code only works for English messages and the texts in other languages will not work.

If we want to support them too, we have to find a way to convert utf8 strings to hex strings.

https://stackoverflow.com/questions/21647928/javascript-unicode-string-to-hex https://stackoverflow.com/questions/36637146/encode-string-to-hex

kochol commented 1 year ago

We can also convert string to hex on C# part.