nicehash/rest-clients-demo

Insomnia

Ralle001 opened this issue · 2 comments

Looking to get the API work with Insomnia but I dont know which value goes where. Like are the API key go as a header or what?

Thank you

Screenshot 2022-12-24 at 20 55 52

Im trying to do it with JSON but aI dont think I can generate a random Nonce for every request and Im not sure this is the right format

bl4z commented

this is pre-request script workin with postman

function generateNonce() {
    var d = Date.now();
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    var r = (d + Math.random() * 16) % 16 | 0;
    d = Math.floor(d / 16);
    return (c == 'x' ? r : r & 0x7 | 0x8).toString(16);
    });
}

function getPath(url) {
    var pathRegex = /.+?\:\/\/.+?(\/.+?)(?:#|\?|$)/;
    var result = url.match(pathRegex);
    return result && result.length > 1 ? result[1] : ''; 
}
 
function getQueryString(url) {
    var arrSplit = url.split('?');
    return arrSplit.length > 1 ? url.substring(url.indexOf('?')+1) : ''; 
}

var secret = "xxxx";
var key = "xxxx";
var org = "xxxx";

var time = new Date().getTime();
var nonce = generateNonce();

var reqMeth = request['method'];
var path = getPath(request['url']);
var query = getQueryString(request['url']);
var data = request['data'];

query = query.replace('{{current-date}}', time);

var content = key + "\x00" + time + "\x00" + nonce + "\x00\x00" + org + "\x00\x00" + reqMeth + "\x00" + path  + "\x00" + query;
if (!(Object.entries(data).length === 0 && data.constructor === Object)) {
    content += "\x00" + data;
}

var HMACsig = CryptoJS.HmacSHA256(content, secret);
xServiceAuth = key + ":" + HMACsig;

console.log("method: " + reqMeth);
console.log("path" + path);
console.log("query: " + query);
console.log("content: " + content);
console.log("digest: " + HMACsig);

postman.setEnvironmentVariable("nonce", nonce);
postman.setEnvironmentVariable("auth", xServiceAuth);
postman.setEnvironmentVariable("current-date", time);
postman.setEnvironmentVariable("org", org);

then use this values as header params

X-Time: {{current-date}}
X-Nonce: {{nonce}}
X-Auth: {{auth}}
X-Organization-Id: {{org}}