here’s the request evm challenge code:
func GeneratePersonalSign(domain string, chainId int, address string, expirationTime string, notBefore string) (GetPersonalSignContent, error) {
var resp GetPersonalSignContent
url1 := "https://authapi.moralis.io/challenge/request/evm"
address = strings.ToLower(address)
str := fmt.Sprintf("{\"domain\":\"%s\",\"chainId\":%d,\"address\":\"%s\",\"statement\":\"Please confirm\",\"uri\":\"https://console.bytehunter.xyz/\",\"expirationTime\":\"%s\",\"notBefore\":\"%s\",\"resources\":[\"https://console.bytehunter.xyz\"],\"timeout\":120}",
domain, chainId, address, expirationTime, notBefore)
payload := strings.NewReader(str)
req, errRequest := http.NewRequest("POST", url1, payload)
if errRequest != nil {
log.Println("error creating request", errRequest)
return GetPersonalSignContent{}, errRequest
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-API-Key", lb.GetKey())
res, errDoClient := http.DefaultClient.Do(req)
if errDoClient != nil {
log.Println("error", errDoClient)
return GetPersonalSignContent{}, errDoClient
}
defer res.Body.Close()
body, errReadBody := ioutil.ReadAll(res.Body)
if errReadBody != nil {
log.Println("error reading body: ", errReadBody)
return GetPersonalSignContent{}, errReadBody
}
errUnmarshal := jsoniter.Unmarshal(body, &resp)
if errUnmarshal != nil {
log.Println("err unmarshal", errUnmarshal)
return GetPersonalSignContent{}, errUnmarshal
}
return resp, nil
}
here’s the verify code:
func VerifySignature(message, signature string) (bool, error) {
url1 := "https://authapi.moralis.io/challenge/verify/evm"
str := fmt.Sprintf("{\"message\":\"%s\",\"signature\":\"%s\"}", message, signature)
log.Println("str2", message)
payload := strings.NewReader(str)
req, _ := http.NewRequest("POST", url1, payload)
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("X-API-Key", lb.GetKey())
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
//fmt.Println(res)
fmt.Println(string(body))
return false, nil
}
And i meet the error:{"statusCode":400,"name":"BadRequestException","message":"Unexpected token \n in JSON at position 70"}
And when i replace the \n, and i meet the other error:
{
"statusCode": 400,
"name": "Error",
"message": "Invalid message: {\"success\":false,\"state\":103,\"length\":362,\"matched\":0,\"maxMatched\":58,\"maxTreeDepth\":15,\"nodeHits\":222,\"inputLength\":362,\"subBegin\":0,\"subEnd\":362,\"subLength\":362}"
}
And I use the personal_sign to generate the signature, what should I do to solve the problem?
The photo is a comparison between the generated message and the verified message.