Akash-pay API's are protected behind a sign based verification using the HMAC sha256 Algorithm.These are essential for any finance platform as they provide a way to check the integrity of information transmitted over or stored in an unreliable medium.
Script For Generation Sign
Following is JS code for Generating a sign
import crypto from'crypto';exportclassHmacUtil {statichmac256(key:string, msg:string) {constmac=crypto.createHmac('sha256', key);constdata=mac.update(msg).digest('hex').toLowerCase();return data; }staticgetStringToSign(body:Record<string,any> ,nonce:string,timestamp:string, reqMethod:string, requestURI:string) {consttreeMap=newMap(Object.entries(body).sort());let s2s ='';for (const [k,v] of treeMap) {if (!k ||typeof v ==='object') {continue; }if (v !==null&& v !==undefined&&String(v)) { s2s += ${k}=${v}&; } }constbodyString=s2s.slice(0,-1);constCotentMd5=crypto.createHash('md5').update(bodyString).digest('hex');conststringToSign= reqMethod +'\n'+ CotentMd5 +'\n'+ requestURI +'\n'+ timestamp +'\n'+ nonce ;return stringToSign }}constnonce='123456';consttimestamp=Date.now();console.log(timestamp)constreqMethod='POST';constrequestURI='http://localhost:8080/api/external/transfer-to-cosmos'; //request endpointconststr=HmacUtil.getStringToSign({"email":"utkarsh38200@gmail.com"//user email }, nonce,timestamp.toString(), reqMethod, requestURI) //call this method for generating the sign to send in the Headerconstsign=HmacUtil.hmac256("<secret-key>",str)constappId="<app-id>"