|
1 | 1 | // dec2hex :: Integer -> String |
2 | 2 | // i.e. 0-255 -> '00'-'ff' |
3 | 3 | function dec2hex(dec) { |
4 | | - return ("0" + dec.toString(16)).substr(-2); |
| 4 | + return ('0' + dec.toString(16)).substr(-2); |
5 | 5 | } |
6 | 6 |
|
7 | 7 | // generateId :: Integer -> String |
8 | 8 | 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('')}"`; |
12 | 12 | } |
13 | 13 |
|
14 | 14 | // getAukaTimestamp :: Void -> String |
15 | 15 | 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}`; |
31 | 31 | } |
32 | 32 |
|
33 | 33 | // generatePubKey :: String -> Void |
34 | 34 | 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(); |
39 | 39 | } |
40 | 40 |
|
41 | 41 | // getHash :: String -> String |
42 | 42 | function getHash(body) { |
43 | | - return CryptoJS.SHA256(body).toString(CryptoJS.enc.Base64); |
| 43 | + return CryptoJS.SHA256(body).toString(CryptoJS.enc.Base64); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | // getSignedMessage :: String -> String |
47 | 47 | 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'); |
51 | 51 | } |
52 | 52 |
|
53 | 53 | // triggerAnimation :: Object -> Void |
54 | 54 | 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'); |
58 | 58 | } |
59 | 59 |
|
60 | 60 | // copyToClipboard :: Object -> Void |
61 | 61 | 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(); |
68 | 68 | } |
69 | 69 |
|
70 | 70 | let isIntegrator = false; |
71 | 71 |
|
72 | 72 | // setDefaultValues :: Void |
73 | 73 | 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; |
89 | 89 | } |
90 | 90 |
|
91 | | -document.getElementById("controllGroupIntegrator").style.display = "none"; |
| 91 | +document.getElementById('controllGroupIntegrator').style.display = 'none'; |
92 | 92 |
|
93 | 93 | 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(); |
99 | 99 | } |
100 | 100 |
|
101 | 101 | 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(); |
107 | 107 | } |
108 | 108 |
|
109 | 109 | // generateHeaders :: Void |
110 | 110 | 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 |
132 | 132 | Content-Type:application/json |
133 | 133 | X-Auka-Merchant:${merchantID} |
134 | 134 | X-Auka-User:${apiUser} |
135 | 135 | X-Auka-Timestamp:${timestamp} |
136 | 136 | X-Auka-Content-Digest:${contentDigest} |
137 | 137 | Authorization:${authorization}`; |
138 | 138 |
|
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 |
158 | 157 | Content-Type:application/json |
159 | 158 | X-Auka-Merchant:${merchantID} |
160 | 159 | X-Auka-Integrator:${integratorID} |
161 | 160 | X-Auka-Timestamp:${timestamp} |
162 | 161 | X-Auka-Content-Digest:${contentDigest} |
163 | 162 | Authorization:${authorization}`; |
164 | 163 |
|
165 | | - element.value = bulkHeaders; |
166 | | - |
167 | | - } |
| 164 | + element.value = bulkHeaders; |
| 165 | + } |
168 | 166 | } |
169 | 167 |
|
170 | 168 | // 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); |
177 | 175 |
|
178 | 176 | setDefaultValues(); |
179 | 177 | generateHeaders(); |
|
0 commit comments