-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNCR_API.js
52 lines (52 loc) · 1.75 KB
/
NCR_API.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function createHMAC(sharedKey, secretKey, httpMethod, requestURL, contentType, nepOrganization, nepServiceVersion, contentMD5, nepApplicationKey, nepCorrelationID, nepEnterpriseUnit) {
const cryptojs = require('crypto-js');
const uri = requestURL.trim().replace(/^https?:\/\/[^\/]+\//, '/');
const d = new Date();
d.setMilliseconds(0);
const time = d.toISOString();
const oneTimeSecret = secretKey + time;
let toSign = httpMethod + "\n" + uri;
if (contentType) {
toSign += "\n" + contentType.trim();
}
if (contentMD5) {
toSign += "\n" + contentMD5.trim();
}
if (nepApplicationKey) {
toSign += "\n" + nepApplicationKey.trim();
}
if (nepCorrelationID) {
toSign += "\n" + nepCorrelationID.trim();
}
if (nepOrganization) {
toSign += "\n" + nepOrganization.trim();
}
if (nepServiceVersion) {
toSign += "\n" + nepServiceVersion.trim();
}
const key = cryptojs.HmacSHA512(toSign, oneTimeSecret);
const accessKey = sharedKey + ":" + cryptojs.enc.Base64.stringify(key);
return "AccessKey " + accessKey;
}
async function apiBackend(){
const fetch = require("node-fetch");
let tlogIDs=[]
let productNames=[]
try{
date= new Date()
res = null // REMOVED API KEY
jsonData = await res.json()
await Promise.all(jsonData.pageContent.map(x=> tlogIDs.push(x.tlogId)))
await Promise.all(tlogIDs.map(async function(x){
date= new Date()
res = null // REMOVED API KEY
jsonData= await res.json()
productNames.push(jsonData.tlog.items[0].productName)
}))
} catch(error) {
console.log(error)
}
NFTProduct=productNames[Math.floor(Math.random() * productNames.length)]
NFTProduct = NFTProduct.replace(/\s/g, '');
}
apiBackend()