Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function calculateAuthToken(peerId, timestamp) {
// calculate the auth token hash
const hash = CryptoJS.HmacSHA256(`${timestamp}:${credentialTTL}:${peerId}`, secretKey);
// convert the hash to a base64 string
return CryptoJS.enc.Base64.stringify(hash);
}
this.hash = function(base_string, key) {
return CryptoJS.HmacSHA256(base_string, key).toString(CryptoJS.enc.Base64);
};
break;
function get (url, callback) {
var nonce = getNonce();
var message = nonce + url;
var signature = cryptoJS.HmacSHA256(message, self.apiSecret);
var reqObject = {
url: url,
headers: {
'ACCESS_KEY': self.apiKey,
'ACCESS_SIGNATURE': signature,
'ACCESS_NONCE': nonce
}
}
request.get(reqObject, function (err, res, data) {
if (err) {
return callback(err);
} else {
try {
data = JSON.parse(data);
} catch (err) {
const sign = function (key, msg) {
'use strict';
const hash = CryptoJS.HmacSHA256(msg, key);
return hash.toString(CryptoJS.enc.Hex);
},
sha256 = function (msg) {
export function hmacSHA256(message, secret) {
secret = secret || message
return CryptoJS.HmacSHA256(message, secret).toString()
}
if (authenticationMethod === AuthenticationMethod.SIGNED) {
if (isNullOrUndefined(BinanceApiClient.API_SECRET)) {
throw new AuthenticationError(
httpMethod,
apiUrl,
authenticationMethod
);
}
apiUrl.searchParams.append(
"timestamp",
new Date().getTime().toString()
);
apiUrl.searchParams.append(
"signature",
CryptoJs.HmacSHA256(
apiUrl.searchParams.toString(),
BinanceApiClient.API_SECRET
).toString()
);
}
return headers;
}
}
signData(data) {
data.api_key = this.account.apiKey;
data.timestamp = Date.now() - 2000;
data.recv_window = 25000;
let dataString = this.objToString(this.sortObject(data));
data.sign = CryptoJS.HmacSHA256(dataString, this.account.apiSecret).
toString();
return this.sortObject(data);
},
sortObject(o) {
function getSignatureKey(key, dateStamp, regionName, serviceName) {
var kDate = crypto.HmacSHA256(dateStamp, 'AWS4' + key, {
asBytes: true
});
var kRegion = crypto.HmacSHA256(regionName, kDate, {
asBytes: true
});
var kService = crypto.HmacSHA256(serviceName, kRegion, {
asBytes: true
});
var kSigning = crypto.HmacSHA256('aws4_request', kService, {
asBytes: true
});
return kSigning;
}
const uri = '/onca/xml'
const params = {
AssociateTag: 'fbdevmygames-21',
AWSAccessKeyId: 'AKIAJ3IDBVUW6HZZFHWQ',
Keywords: barcode,
Operation: 'ItemSearch',
ResponseGroup: 'ItemAttributes',
SearchIndex: 'VideoGames',
Service: 'AWSECommerceService',
Timestamp: now.format('YYYY-MM-DD[T]HH:mm:ss[Z]')
}
const canonicalQueryString = qs.stringify(params)
const stringSoSign = `GET\n${endpoint}\n${uri}\n${canonicalQueryString}`
const hash = crypto.HmacSHA256(stringSoSign, AWS_SECRET_ACCESS_KEY)
const signature = hash.toString(crypto.enc.Base64)
const signedUrl = `http://${endpoint}${uri}?${canonicalQueryString}&Signature=${encodeURIComponent(signature)}`
const setting = {
method: 'GET',
url: signedUrl,
responseType: 'text',
}
return ajax(setting)
.map((response) => {
const xmlResponse = response.response
const jsonResponse = new X2JS().xml2js(xmlResponse)
let gameName = _.get(jsonResponse, 'ItemSearchResponse.Items.Item.ItemAttributes.Title', '')
gameName = gameName.replace(/\([^()]*\)/g, '')
function getSignatureKey(key, dateStamp, regionName, serviceName) {
var kDate = crypto.HmacSHA256(dateStamp, 'AWS4' + key, {
asBytes: true
});
var kRegion = crypto.HmacSHA256(regionName, kDate, {
asBytes: true
});
var kService = crypto.HmacSHA256(serviceName, kRegion, {
asBytes: true
});
var kSigning = crypto.HmacSHA256('aws4_request', kService, {
asBytes: true
});
return kSigning;
}