/challenge/verify/evm request body

What request body is needed for /challenge/verify/evm?

I followed Sign In with MetaMask document. I can see my Next.js app presents user’s address profileId and signature like this

User session:
{
  "address": "0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b",
  "profileId": "0xe7285226dd8d301c9f1b25c60cb155fd76a683605d815763aa4bdfdb7e8292b5",
  "signature": "0x5e7cbf76184b8cbddf334xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx70ce88ddee76830bb31b"
}

Then I try to verify the signature by /challenge/verify/evm. But it returns Invalid message error.

What kind of message is needed here?

Input params

message

deblog.club wants you to sign in with your Ethereum account:\n0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b\n\nPlease sign this message to confirm your identity.\n\nURI: http://localhost:3000\nVersion: 1\nChain ID: 1\nNonce: waXwRE8zYj9WBEfVx\nIssued At: 2022-09-27T14:02:19.212Z

signature (copied from Next.js users page)

0x5e7cbf76184b8cbddf334xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx70ce88ddee76830bb31b

Result

{
  "statusCode": 400,
  "name": "Error",
  "message": "Invalid message: {\"success\":false,\"state\":103,\"length\":276,\"matched\":0,\"maxMatched\":60,\"maxTreeDepth\":15,\"nodeHits\":258,\"inputLength\":276,\"subBegin\":0,\"subEnd\":276,\"subLength\":276}"
}

Only message and signature. You can test it directly in swagger interface too. You will find the link in documentation on the first page.

Yeah I checked swagger as well.
Unfortunately, I’m getting the same error response.

https://authapi.moralis.io/api-docs/#/challenge/verifyChallengeEvm

I think I’m putting a wrong message. No?

deblog.club wants you to sign in with your Ethereum account:\n0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b\n\nPlease sign this message to confirm your identity.\n\nURI: http://localhost:3000\nVersion: 1\nChain ID: 1\nNonce: waXwRE8zYj9WBEfVx\nIssued At: 2022-09-27T14:02:19.212Z

Do you know the proper way to generate the message?

Since you followed the mentioned tutorial in the docs, you already called the /challenge/verify/evm with Moralis.Auth.verify.

You can read more about the syntax here

Yes, Next.js app already called the verify

What I’m trying to do is to check the signature is valid or not on server side.

  1. Next.js app verified and get signature
  2. Next.js app send the signature to Rails servier.
  3. Rails server confirm the signature is valid or not.

In Step 3, I need to call /challenge/verify/evm with the signature again.

Please let me know if my understanding is not correct.

What doesn’t work?
You can see the format directly in the swagger. Sometimes a different enter format or some message parameter with invalid value or missing could cause errors.

You should be able to test is successfully in the swagger when everything is set as expected.

I cannot get 201 response from /challenge/verify/evm
It just return 400.

  1. To put console log message on Next.js app before verifiy
  2. Next.js app passes the verify and present signature.
  3. Copy the signature and message into the /challenge/verify/evm
  4. Response is 400 Invalid message

Do you know the proper way to generate the message?

The message is generated first, you can generate it directly in swagger, sign it and then verify it.

The generated message seemed to be multiline which is returned from the request message.

I’m putting this message

deblog.club wants you to sign in with your Ethereum account:\n0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b\n\nPlease sign this message to confirm your identity.\n\nURI: http://localhost:3000\nVersion: 1\nChain ID: 1\nNonce: waXwRE8zYj9WBEfVx\nIssued At: 2022-09-27T14:02:19.212Z

Instead of this one. Cause it should be one line.

deblog.club wants you to sign in with your Ethereum account:
0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b

Please sign this message to confirm your identity.

URI: http://localhost:3000
Version: 1
Chain ID: 1
Nonce: waXwRE8zYj9WBEfVx
Issued At: 2022-09-27T14:02:19.212Z

Right?

Yes, it should be one line

1 Like

Ok. So the curl request it like this

curl --request POST \
     --url https://authapi.moralis.io/challenge/verify/evm \
     --header 'X-API-KEY: GDlFIJ8uIErqaQCfxxxxxxxxxxxxxxxxxxxxxxxxW36wjmwWb' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
     "signature": "0xbc53bf24906e51d0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf285171b",
     "message": "deblog.club wants you to sign in with your Ethereum account:\\n0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b\\n\\nPlease sign this message to confirm your identity.\\n\\nURI: http://localhost:3000\\nVersion: 1\\nChain ID: 1\\nNonce: tL8ejuiK6RUFhPXrE\\nIssued At: 2022-09-27T16:55:03.381Z"
}

and it returns 400. Why?

response

{
  "statusCode": 400,
  "name": "Error",
  "message": "Invalid message: {\"success\":false,\"state\":103,\"length\":276,\"matched\":0,\"maxMatched\":60,\"maxTreeDepth\":15,\"nodeHits\":258,\"inputLength\":276,\"subBegin\":0,\"subEnd\":276,\"subLength\":276}"
}

I regenerate the signature more than 10 times and try it. But the response is 400 every time. I think I input something wrong. Because the error message clearly says “Invalid message”

this format seems strange, maybe it is expected to be with two \

hmm. I changed like this. but it’s not working.

deblog.club wants you to sign in with your Ethereum account:\\0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b\\\\Please sign this message to confirm your identity.\\\\URI: http://localhost:3000\\Version: 1\\Chain ID: 1\\Nonce: tL8ejuiK6RUFhPXrE\\Issued At: 2022-09-27T16:55:03.381Z

This one is not working as well.

curl --request POST \
     --url https://authapi.moralis.io/challenge/verify/evm \
     --header 'X-API-KEY: GDlFIJ8uIErqaQCfTQxxxxxxxxxxxxxxxwjmwWb' \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
     "signature": "0x33ab7687c3bf3xxxxxxxxxxxxxxxxxxxx336188a0496c03f161b",
     "message": "deblog.club wants you to sign in with your Ethereum account: 0x41Dd2e751dF10b27356cd1790567Ba6C4B5d933b  Please sign this message to confirm your identity.  URI: http://localhost:3000 Version: 1 Chain ID: 1 Nonce: uuY77ky0uqo4dGhCD Issued At: 2022-09-27T18:56:01.089Z"
}
'

you could try with \n instead of \\n

maybe this tutorial will help you more

1 Like

oh yeah. This is nice. I’ll go though this document. Thx!

1 Like

you could try with \n instead of \\n

The error message is slightly different if I send a message with \n

{
  "statusCode": 400,
   "name": "NotFoundException",
   "message": "Challenge not found, Timeout may have exceeded"
}

Why? it’s changed??

there is a timeout for a challenge, that default time of 15 seconds that you could change to more