Skip to main content

Authorization

When the client calls server’s restful interface, client need to set the following headers to pass the server’s authorization:

HeaderDescription
Content-Typeapplication/json;charset=UTF-8
X-Signature-appidAppid, unique code
X-Signature-timestampTimestamp, millisecond
X-Signature-nonceRandom uuid, replace “-” with “”,32 byte length
X-Signature-signatureSignature,lowercase,check below for sign details

Signature

tip

Please note that the signature is optional here. You can still access our API without signature. However, you will be limited to a lower rate. If you foresee your application having a higher rate to the AvengerDAO API, please contact us for a dedicated appid and appSecret.

signature = encodeHexString(
HmacSHA256(
appsecret,
appid;
timestamp;
nonce;
method;
uri;
query;
body
)
)

Where uri is the path, multiple key-value pair in query and header should be sorted alphabetically by key, comma separated, example:

Go Sample Code

appSecret := "" // the app secret

appid := "" // the app id
timestamp := strconv.FormatInt(time.Now().Unix(), 10) // the timestamp
nonce := strconv.Itoa(rand.Intn(9999999)) // the nonce
method := "POST" // the http method
url := "/api/v1/address-security" // the url
query := "" // the query string, it can be empty
body := string(postBody) // the request body

msgForSig := GenerateMsgForSig(appid, timestamp, nonce, method, url, query, body)
sig := ComputeSig(msgForSig, appSecret)

func GenerateMsgForSig(appid, timestamp, nonce, method, url, query, body string) string {
var msgForSig []byte

if query != "" {
msgForSig = []byte(fmt.Sprintf("%s;%s;%s;%s;%s;%s;%s", appid, timestamp, nonce, method, url, query, body))
} else {
msgForSig = []byte(fmt.Sprintf("%s;%s;%s;%s;%s;%s", appid, timestamp, nonce, method, url, body))
}

return string(msgForSig)
}

func ComputeSig(msgForSig, appSecret string) string {
message := []byte(msgForSig)

key := []byte(appSecret)
h := hmac.New(sha256.New, key)
h.Write(message)

return hex.EncodeToString(h.Sum(nil))
}
KeyValue
appid13cc90dc5ffa4032acb3
appsecretcd0ec4b1ca934b188996034541d7e810
url/api/v1/address-security
queryempty
methodPOST
body
{
"chain_id":"56",
"address":"0x312bc7eaaf93f1c60dc5afc115fccde161055fb0"
}
timestamp1657246234465
nonce791f398e93f14b3e98f916703f777f44

then:

signature = encodeHexString(HmacSHA256(
cd0ec4b1ca934b188996034541d7e810,
‘13cc90dc5ffa4032acb3;
1657246234465;
791f398e93f14b3e98f916703f777f44;
POST;
/api/v1/address-security;
{
"address":"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
"chainId":"56"
}
))

Note: The query can be empty. When the query is empty, you do not need to fill in the empty query and “;” in the concatenated string, but directly omit the query and “;”

Final header

HeaderDescription
Content-Typeapplication/json;charset=UTF-8
X-Signature-appid13cc90dc5ffa4032acb3
X-Signature-timestamp1657246234465
X-Signature-nonce791f398e93f14b3e98f916703f777f44
X-Signature-signaturebece3956c35911e598635345c0f428122e5423efc9fac68edf9dd377163a9897