Signature verification

The signature verification is to prevent external malicious requests and verify fee collection addresses.

Here is a code sample for signature generation.

In Chainge SDK, the signature algorithm is calculated automatically when a request requires a signature.

let CryptoJS = require('crypto-js')
# appSecret from Chainge
let appSecret =  "";
# appKey from Chainge 
let appKey = "32Mh2R1xUdtJWHGXA1cGJNHzDUzbkZoB2dTWt3RdzoiLq7LjxxBUDLi1RBCgKxFh";

let paramJson = {
    #Users EVM address
    "evmAddress":"0xE8abdABcC14029ee931A5af11361957DaB2F58D6", 
    #EVM address to cross chain assets from original chain
    "fromAddress" : "0xE8abdABcC14029ee931A5af11361957DaB2F58D6",
    #to address to cross chain assets to target chain
    "toAddress" : "0xE8abdABcC14029ee931A5af11361957DaB2F58D6",
    # from chain symbol from supported chains API result
    "fromChain":"FSN",
    # to chain symbol from supported chains API result
    "toChain" : "FSN",
    # from Token symbol from supported tokens API result (make sure it is supported on the from Chain)
    "fromToken" : "CHNG",
    # from Token symbol from supported tokens API result (make sure it is supported on the target Chain)
    "toToken" : "CHNG",
    # cross chain amount
    "fromAmount" : 0.0001,
    # fee level structure int, please refer to fee structure page
    "feeLevel" : 0,
    # a certHash to prove users assets are transferred, generated in previous step
    "certHash": "0x999488c5cc95ad41000dfc2fd14b621e5be984d6f0094feb131d713241303eb0"
}
# time stamp is only valid within 20 seconds
let timestamp = new Date().getTime();
let expireTime = 15000;

let strBody = "";
let keysBody = Object.keys(paramJson);

keysBody = keysBody.sort();
for (const key of keysBody) {
    const val = paramJson[key];
    strBody += `${key}=${val}`;
}

let param = Object.assign({}, {
    appKey: appKey,
    expireTime: expireTime,
    timestamp: timestamp
});

let strHeader = "";
let headerKeys = Object.keys(param);
headerKeys = headerKeys.sort();
for (const key of headerKeys) {
if (key !== "signature") {
    const val = param[key];
    strHeader += `${key}=${val}`;
}
}
str = strBody + strHeader;
const sign = CryptoJS.HmacSHA256(str, appSecret).toString();

Last updated