Skip to content

Commit 64036c4

Browse files
author
Christian Wick
committed
Code formating
1 parent 9e6ba2d commit 64036c4

1 file changed

Lines changed: 109 additions & 111 deletions

File tree

index.js

Lines changed: 109 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,179 +1,177 @@
11
// dec2hex :: Integer -> String
22
// i.e. 0-255 -> '00'-'ff'
33
function dec2hex(dec) {
4-
return ("0" + dec.toString(16)).substr(-2);
4+
return ('0' + dec.toString(16)).substr(-2);
55
}
66

77
// generateId :: Integer -> String
88
function generateId(len) {
9-
var arr = new Uint8Array((len || 10) / 2);
10-
window.crypto.getRandomValues(arr);
11-
return `"${Array.from(arr, dec2hex).join("")}"`;
9+
var arr = new Uint8Array((len || 10) / 2);
10+
window.crypto.getRandomValues(arr);
11+
return `"${Array.from(arr, dec2hex).join('')}"`;
1212
}
1313

1414
// getAukaTimestamp :: Void -> String
1515
function getAukaTimestamp() {
16-
const d = new Date();
17-
const fYear = d.getUTCFullYear().toString();
18-
const month = (d.getUTCMonth() + 1).toString();
19-
const day = d.getUTCDate().toString();
20-
const hours = d.getUTCHours().toString();
21-
const minutes = parseInt(d.getUTCMinutes()).toString();
22-
const seconds = parseInt(d.getUTCSeconds()).toString();
23-
24-
const fMonth = month.length == 2 ? month : `0${month}`;
25-
const fDay = day.length == 2 ? day : `0${day}`;
26-
const fHours = hours.length == 2 ? hours : `0${hours}`;
27-
const fMinutes = minutes.length == 2 ? minutes : `0${minutes}`;
28-
const fSeconds = seconds.length == 2 ? seconds : `0${seconds}`;
29-
30-
return `${fYear}-${fMonth}-${fDay} ${fHours}:${fMinutes}:${fSeconds}`;
16+
const d = new Date();
17+
const fYear = d.getUTCFullYear().toString();
18+
const month = (d.getUTCMonth() + 1).toString();
19+
const day = d.getUTCDate().toString();
20+
const hours = d.getUTCHours().toString();
21+
const minutes = parseInt(d.getUTCMinutes()).toString();
22+
const seconds = parseInt(d.getUTCSeconds()).toString();
23+
24+
const fMonth = month.length == 2 ? month : `0${month}`;
25+
const fDay = day.length == 2 ? day : `0${day}`;
26+
const fHours = hours.length == 2 ? hours : `0${hours}`;
27+
const fMinutes = minutes.length == 2 ? minutes : `0${minutes}`;
28+
const fSeconds = seconds.length == 2 ? seconds : `0${seconds}`;
29+
30+
return `${fYear}-${fMonth}-${fDay} ${fHours}:${fMinutes}:${fSeconds}`;
3131
}
3232

3333
// generatePubKey :: String -> Void
3434
function generatePubKey(privateKey) {
35-
console.log("Generating new public key from private key");
36-
const crypt = new JSEncrypt();
37-
crypt.setKey(privateKey);
38-
document.getElementById("public_key").value = crypt.getPublicKey();
35+
console.log('Generating new public key from private key');
36+
const crypt = new JSEncrypt();
37+
crypt.setKey(privateKey);
38+
document.getElementById('public_key').value = crypt.getPublicKey();
3939
}
4040

4141
// getHash :: String -> String
4242
function getHash(body) {
43-
return CryptoJS.SHA256(body).toString(CryptoJS.enc.Base64);
43+
return CryptoJS.SHA256(body).toString(CryptoJS.enc.Base64);
4444
}
4545

4646
// getSignedMessage :: String -> String
4747
function getSignedMessage(privateKey, message) {
48-
const crypt = new JSEncrypt();
49-
crypt.setKey(privateKey);
50-
return crypt.sign(message, CryptoJS.SHA256, "sha256");
48+
const crypt = new JSEncrypt();
49+
crypt.setKey(privateKey);
50+
return crypt.sign(message, CryptoJS.SHA256, 'sha256');
5151
}
5252

5353
// triggerAnimation :: Object -> Void
5454
function triggerAnimation(element) {
55-
element.classList.remove("change-animation");
56-
void element.offsetWidth;
57-
element.classList.add("change-animation");
55+
element.classList.remove('change-animation');
56+
void element.offsetWidth;
57+
element.classList.add('change-animation');
5858
}
5959

6060
// copyToClipboard :: Object -> Void
6161
function copyToClipboard(event) {
62-
const element = event.target;
63-
void triggerAnimation(element);
64-
console.log(`Copying contents of ${element.name} to clipboard`);
65-
element.select();
66-
document.execCommand("copy");
67-
window.getSelection().removeAllRanges();
62+
const element = event.target;
63+
void triggerAnimation(element);
64+
console.log(`Copying contents of ${element.name} to clipboard`);
65+
element.select();
66+
document.execCommand('copy');
67+
window.getSelection().removeAllRanges();
6868
}
6969

7070
let isIntegrator = false;
7171

7272
// setDefaultValues :: Void
7373
function setDefaultValues() {
74-
const method = "";
75-
const url = "";
76-
const merchantID = "";
77-
const apiUser = "";
78-
const integratorID = "";
79-
const privateKey = "";
80-
const body = "";
81-
82-
document.getElementById("private_key").value = privateKey;
83-
document.getElementById("method").value = method;
84-
document.getElementById("url").value = url;
85-
document.getElementById("body").value = body;
86-
document.getElementById("merchant_id").value = merchantID;
87-
document.getElementById("api_user").value = apiUser;
88-
document.getElementById("X_Auka_Integrator").value = integratorID;
74+
const method = '';
75+
const url = '';
76+
const merchantID = '';
77+
const apiUser = '';
78+
const integratorID = '';
79+
const privateKey = '';
80+
const body = '';
81+
82+
document.getElementById('private_key').value = privateKey;
83+
document.getElementById('method').value = method;
84+
document.getElementById('url').value = url;
85+
document.getElementById('body').value = body;
86+
document.getElementById('merchant_id').value = merchantID;
87+
document.getElementById('api_user').value = apiUser;
88+
document.getElementById('X_Auka_Integrator').value = integratorID;
8989
}
9090

91-
document.getElementById("controllGroupIntegrator").style.display = "none";
91+
document.getElementById('controllGroupIntegrator').style.display = 'none';
9292

9393
function integratorFalse() {
94-
document.getElementById("controllGroupApiUser").style.display = "block";
95-
document.getElementById("controllGroupIntegrator").style.display = "none";
96-
isIntegrator = false;
97-
// console.log(isIntegrator);
98-
generateHeaders();
94+
document.getElementById('controllGroupApiUser').style.display = 'block';
95+
document.getElementById('controllGroupIntegrator').style.display = 'none';
96+
isIntegrator = false;
97+
// console.log(isIntegrator);
98+
generateHeaders();
9999
}
100100

101101
function integratorTrue() {
102-
document.getElementById("controllGroupApiUser").style.display = "none";
103-
document.getElementById("controllGroupIntegrator").style.display = "block";
104-
isIntegrator = true;
105-
// console.log(isIntegrator);
106-
generateHeaders();
102+
document.getElementById('controllGroupApiUser').style.display = 'none';
103+
document.getElementById('controllGroupIntegrator').style.display = 'block';
104+
isIntegrator = true;
105+
// console.log(isIntegrator);
106+
generateHeaders();
107107
}
108108

109109
// generateHeaders :: Void
110110
function generateHeaders() {
111-
// console.log("Generating hedears");
112-
const element = document.getElementById("bulk_headers");
113-
void triggerAnimation(element);
114-
115-
if (isIntegrator == false) {
116-
console.log("Generating hedears with X-Auka-User");
117-
118-
const privateKey = document.getElementById("private_key").value;
119-
const method = document.getElementById("method").value;
120-
const url = document.getElementById("url").value;
121-
const merchantID = document.getElementById("merchant_id").value;
122-
const timestamp = getAukaTimestamp();
123-
const apiUser = document.getElementById("api_user").value;
124-
const body = document.getElementById("body").value;
125-
const bodyHash = getHash(body);
126-
const contentDigest = `SHA256=${bodyHash}`;
127-
const headers = `X-AUKA-CONTENT-DIGEST=${contentDigest}&X-AUKA-MERCHANT=${merchantID}&X-AUKA-TIMESTAMP=${timestamp}&X-AUKA-USER=${apiUser}`;
128-
const message = `${method}|${url}|${headers}`;
129-
const signature = getSignedMessage(privateKey, message);
130-
const authorization = "RSA-SHA256 " + signature;
131-
const bulkHeaders = `Accept:application/vnd.mcash.api.merchant.v1+json
111+
// console.log("Generating hedears");
112+
const element = document.getElementById('bulk_headers');
113+
void triggerAnimation(element);
114+
115+
if (isIntegrator == false) {
116+
console.log('Generating hedears with X-Auka-User');
117+
118+
const privateKey = document.getElementById('private_key').value;
119+
const method = document.getElementById('method').value;
120+
const url = document.getElementById('url').value;
121+
const merchantID = document.getElementById('merchant_id').value;
122+
const timestamp = getAukaTimestamp();
123+
const apiUser = document.getElementById('api_user').value;
124+
const body = document.getElementById('body').value;
125+
const bodyHash = getHash(body);
126+
const contentDigest = `SHA256=${bodyHash}`;
127+
const headers = `X-AUKA-CONTENT-DIGEST=${contentDigest}&X-AUKA-MERCHANT=${merchantID}&X-AUKA-TIMESTAMP=${timestamp}&X-AUKA-USER=${apiUser}`;
128+
const message = `${method}|${url}|${headers}`;
129+
const signature = getSignedMessage(privateKey, message);
130+
const authorization = 'RSA-SHA256 ' + signature;
131+
const bulkHeaders = `Accept:application/vnd.mcash.api.merchant.v1+json
132132
Content-Type:application/json
133133
X-Auka-Merchant:${merchantID}
134134
X-Auka-User:${apiUser}
135135
X-Auka-Timestamp:${timestamp}
136136
X-Auka-Content-Digest:${contentDigest}
137137
Authorization:${authorization}`;
138138

139-
element.value = bulkHeaders;
140-
141-
} else {
142-
console.log("Generating hedears with X-Auka-Integrator");
143-
144-
const privateKey = document.getElementById("private_key").value;
145-
const method = document.getElementById("method").value;
146-
const url = document.getElementById("url").value;
147-
const merchantID = document.getElementById("merchant_id").value;
148-
const timestamp = getAukaTimestamp();
149-
const integratorID = document.getElementById("X_Auka_Integrator").value;
150-
const body = document.getElementById("body").value;
151-
const bodyHash = getHash(body);
152-
const contentDigest = `SHA256=${bodyHash}`;
153-
const headers = `X-AUKA-CONTENT-DIGEST=${contentDigest}&X-AUKA-MERCHANT=${merchantID}&X-AUKA-TIMESTAMP=${timestamp}&X-Auka-Integrator=${integratorID}`;
154-
const message = `${method}|${url}|${headers}`;
155-
const signature = getSignedMessage(privateKey, message);
156-
const authorization = "RSA-SHA256 " + signature;
157-
const bulkHeaders = `Accept:application/vnd.mcash.api.merchant.v1+json
139+
element.value = bulkHeaders;
140+
} else {
141+
console.log('Generating hedears with X-Auka-Integrator');
142+
143+
const privateKey = document.getElementById('private_key').value;
144+
const method = document.getElementById('method').value;
145+
const url = document.getElementById('url').value;
146+
const merchantID = document.getElementById('merchant_id').value;
147+
const timestamp = getAukaTimestamp();
148+
const integratorID = document.getElementById('X_Auka_Integrator').value;
149+
const body = document.getElementById('body').value;
150+
const bodyHash = getHash(body);
151+
const contentDigest = `SHA256=${bodyHash}`;
152+
const headers = `X-AUKA-CONTENT-DIGEST=${contentDigest}&X-AUKA-MERCHANT=${merchantID}&X-AUKA-TIMESTAMP=${timestamp}&X-Auka-Integrator=${integratorID}`;
153+
const message = `${method}|${url}|${headers}`;
154+
const signature = getSignedMessage(privateKey, message);
155+
const authorization = 'RSA-SHA256 ' + signature;
156+
const bulkHeaders = `Accept:application/vnd.mcash.api.merchant.v1+json
158157
Content-Type:application/json
159158
X-Auka-Merchant:${merchantID}
160159
X-Auka-Integrator:${integratorID}
161160
X-Auka-Timestamp:${timestamp}
162161
X-Auka-Content-Digest:${contentDigest}
163162
Authorization:${authorization}`;
164163

165-
element.value = bulkHeaders;
166-
167-
}
164+
element.value = bulkHeaders;
165+
}
168166
}
169167

170168
// Main script
171-
document.getElementById("generate").onclick = () => generateHeaders();
172-
document.getElementById("method").onchange = () => generateHeaders();
173-
document.getElementById("url").onchange = () => generateHeaders();
174-
document.getElementById("body").onchange = () => generateHeaders();
175-
document.getElementById("bulk_headers").onclick = (event) =>
176-
copyToClipboard(event);
169+
document.getElementById('generate').onclick = () => generateHeaders();
170+
document.getElementById('method').onchange = () => generateHeaders();
171+
document.getElementById('url').onchange = () => generateHeaders();
172+
document.getElementById('body').onchange = () => generateHeaders();
173+
document.getElementById('bulk_headers').onclick = (event) =>
174+
copyToClipboard(event);
177175

178176
setDefaultValues();
179177
generateHeaders();

0 commit comments

Comments
 (0)