thirdweb-dev / unity-sdk

Best in class Web3 Unity SDK, powered by thirdweb.
https://portal.thirdweb.com/unity
Apache License 2.0
126 stars 70 forks source link

Called Wallet.Sign() with this message on WebGL build, failed and got this error: invalid hexlify error #212

Closed crmantow closed 1 month ago

crmantow commented 1 month ago

The string i want to sign:

string domain = "myDomain";
string chainId = "1";
string message = "Sign in";
string uri = "myUri";

string data = "{\"domain\":\"" + domain + "\",\"chainId\":" + chainId + ",\"message\":\"" + message + "\",\"wallet\":\"" + walletAddress + "\",\"nonce\":\"" + nonce + "\",\"uri\":\"" + uri + "\"}";
return await sdk.Wallet.Sign(data);
0xFirekeeper commented 1 month ago

You can try copying this code for SIWE https://github.com/thirdweb-dev/unity-sdk/blob/dafafeaaf343d3de6c934212c0fe4bac662bc537/Assets/Thirdweb/Core/Scripts/Wallet.cs#L136-L149

Or use v5 Utils.GenerateSIWE

crmantow commented 1 month ago

I recently discovered that the invalid hexify error appears when I include the chainId in the JSON data string, but the error disappears when I exclude it. Is there a specific reason for this behavior?

I need to sign the message with the chainId included in the format, so any insight on how to fix this would be appreciated.