4

I have a message need to sign like below

message = { "types": { 'EIP712Domain': [{ 'name': "name", 'type': "string" }, { 'name': "version", 'type': "string" }, { 'name': "chainId", 'type': "uint256" }], 'SignIn': [{ 'name': "message", 'type': "string" }, { 'name': "Wallet address", 'type': "address" }] }, 'primaryType': "SignIn", "domain": { "name": "DefusionAi", "version": "1.0.0", "chainId": 91715 }, "message": { "message": my_message, "Wallet address":address } } 

My problem is that I can't sign message for this website because 'name': "Wallet address" and "Wallet address":address have white space , but I can't remove whitespace because if I do so, sign_message function works but it's wrong signature. The website link is here

and this is screenshot of metamask

enter image description here

4
  • 2
    You're right a name with whitespace doesn't make sense (github.com/ethereum/EIPs/blob/master/EIPS/…) You should try to contact the project to fix it; if they don't, they may not be worth trusting or using as pretending to be EIP-712 compliant, without being so, can be nefarious. Commented Aug 9, 2023 at 1:25
  • But it's true , the link website is above , you can check it. There is a name "Wallet address" when we sign metamask Commented Aug 9, 2023 at 6:06
  • I would not recommend anyone to click the link in the question. Only suggestions are to contact the project and if you can look at the website's code on Github and see what it does. If you figure it out, please post here and we can all learn. Also, other people reading this question may find it helpful if you include the Metamask screenshot. Commented Aug 9, 2023 at 6:47
  • sure , I've just edited to add metamask screenshot above . I believe that "Wallet address" is the name in my message which has white space Commented Aug 9, 2023 at 8:39

1 Answer 1

3

Metamask's typed-data signing implementation is more permissive than eth-account's encode_structured_data. A new python implementation is in process that will be more compatible with EIP712 signing as it's being used out in the wild.

In the meantime, if you don't mind a little javascript, this should generate the signature properly:

const { SignTypedDataVersion } = require("@metamask/eth-sig-util/sign-typed-data") const ethSigUtil = require("@metamask/eth-sig-util") const test_message_json = require("./your-message.json") const test_key = "private-key" let v4 = SignTypedDataVersion.V4 sig = ethSigUtil.signTypedData({privateKey: test_key, data: test_message_json, version: v4}) console.log(sig) 
2
  • Can I use this method with python code ? or it is only available with js ? Commented Aug 12, 2023 at 5:05
  • encode_structured_data from the eth-account library link is the equivalent function for python. It encodes similarly for most messages, but differently (or not at all) for non-standard cases, such as spaces in a dict key. Commented Aug 14, 2023 at 11:15

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.