11// dec2hex :: Integer -> String
22// i.e. 0-255 -> '00'-'ff'
33function dec2hex ( dec ) {
4- return ( '0' + dec . toString ( 16 ) ) . substr ( - 2 )
4+ return ( "0" + dec . toString ( 16 ) ) . substr ( - 2 ) ;
55}
66
77// generateId :: Integer -> String
88function 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
1515function getAukaTimestamp ( ) {
1616 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 } `
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 } ` ;
2929
3030 return `${ fYear } -${ fMonth } -${ fDay } ${ fHours } :${ fMinutes } :${ fSeconds } ` ;
3131}
3232
3333// generatePubKey :: String -> Void
3434function generatePubKey ( privateKey ) {
35- console . log ( ' Generating new public key from private key' )
35+ console . log ( " Generating new public key from private key" ) ;
3636 const crypt = new JSEncrypt ( ) ;
3737 crypt . setKey ( privateKey ) ;
38- document . getElementById ( ' public_key' ) . value = crypt . getPublicKey ( )
38+ document . getElementById ( " public_key" ) . value = crypt . getPublicKey ( ) ;
3939}
4040
4141// getHash :: String -> String
4242function 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
@@ -59,69 +59,121 @@ function triggerAnimation(element) {
5959
6060// copyToClipboard :: Object -> Void
6161function 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
70+ let isIntegrator = false ;
71+
7072// setDefaultValues :: Void
7173function setDefaultValues ( ) {
72- const method = ''
73- const url = ''
74- const merchantID = ''
75- const apiUser = ''
76- const privateKey = ''
77- const body = ''
78-
79- document . getElementById ( 'private_key' ) . value = privateKey
80- document . getElementById ( 'method' ) . value = method
81- document . getElementById ( 'url' ) . value = url
82- document . getElementById ( 'body' ) . value = body
83- document . getElementById ( 'merchant_id' ) . value = merchantID
84- document . getElementById ( 'api_user' ) . value = apiUser
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+ }
90+
91+ document . getElementById ( "controllGroupIntegrator" ) . style . display = "none" ;
92+
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+ }
99+
100+ function integratorTrue ( ) {
101+ document . getElementById ( "controllGroupApiUser" ) . style . display = "none" ;
102+ document . getElementById ( "controllGroupIntegrator" ) . style . display = "block" ;
103+ isIntegrator = true ;
104+ // console.log(isIntegrator);
85105}
86106
87107// generateHeaders :: Void
88108function generateHeaders ( ) {
89- console . log ( 'Generating hedears' )
90- const element = document . getElementById ( 'bulk_headers' ) ;
91- void triggerAnimation ( element )
92-
93- const privateKey = document . getElementById ( 'private_key' ) . value
94- const method = document . getElementById ( 'method' ) . value
95- const url = document . getElementById ( 'url' ) . value
96- const merchantID = document . getElementById ( 'merchant_id' ) . value
97- const timestamp = getAukaTimestamp ( )
98- const apiUser = document . getElementById ( 'api_user' ) . value
99- const body = document . getElementById ( 'body' ) . value
100- const bodyHash = getHash ( body )
101- const contentDigest = `SHA256=${ bodyHash } `
102- const headers = `X-AUKA-CONTENT-DIGEST=${ contentDigest } &X-AUKA-MERCHANT=${ merchantID } &X-AUKA-TIMESTAMP=${ timestamp } &X-AUKA-USER=${ apiUser } `
103- const message = `${ method } |${ url } |${ headers } `
104- const signature = getSignedMessage ( privateKey , message )
105- const authorization = 'RSA-SHA256 ' + signature
106- const bulkHeaders =
107- `Accept:application/vnd.mcash.api.merchant.v1+json
109+ // console.log("Generating hedears");
110+ const element = document . getElementById ( "bulk_headers" ) ;
111+ void triggerAnimation ( element ) ;
112+
113+ if ( isIntegrator == false ) {
114+ console . log ( "Generating hedears with X-Auka-User" ) ;
115+
116+ const privateKey = document . getElementById ( "private_key" ) . value ;
117+ const method = document . getElementById ( "method" ) . value ;
118+ const url = document . getElementById ( "url" ) . value ;
119+ const merchantID = document . getElementById ( "merchant_id" ) . value ;
120+ const timestamp = getAukaTimestamp ( ) ;
121+ const apiUser = document . getElementById ( "api_user" ) . value ;
122+ const body = document . getElementById ( "body" ) . value ;
123+ const bodyHash = getHash ( body ) ;
124+ const contentDigest = `SHA256=${ bodyHash } ` ;
125+ const headers = `X-AUKA-CONTENT-DIGEST=${ contentDigest } &X-AUKA-MERCHANT=${ merchantID } &X-AUKA-TIMESTAMP=${ timestamp } &X-AUKA-USER=${ apiUser } ` ;
126+ const message = `${ method } |${ url } |${ headers } ` ;
127+ const signature = getSignedMessage ( privateKey , message ) ;
128+ const authorization = "RSA-SHA256 " + signature ;
129+ const bulkHeaders = `Accept:application/vnd.mcash.api.merchant.v1+json
108130Content-Type:application/json
109131X-Auka-Merchant:${ merchantID }
110132X-Auka-User:${ apiUser }
111133X-Auka-Timestamp:${ timestamp }
112134X-Auka-Content-Digest:${ contentDigest }
113- Authorization:${ authorization } `
135+ Authorization:${ authorization } ` ;
136+
137+ element . value = bulkHeaders ;
138+
139+ } else {
140+ console . log ( "Generating hedears with X-Auka-Integrator" ) ;
141+
142+ const privateKey = document . getElementById ( "private_key" ) . value ;
143+ const method = document . getElementById ( "method" ) . value ;
144+ const url = document . getElementById ( "url" ) . value ;
145+ const merchantID = document . getElementById ( "merchant_id" ) . value ;
146+ const timestamp = getAukaTimestamp ( ) ;
147+ const integratorID = document . getElementById ( "X_Auka_Integrator" ) . value ;
148+ const body = document . getElementById ( "body" ) . value ;
149+ const bodyHash = getHash ( body ) ;
150+ const contentDigest = `SHA256=${ bodyHash } ` ;
151+ const headers = `X-AUKA-CONTENT-DIGEST=${ contentDigest } &X-AUKA-MERCHANT=${ merchantID } &X-AUKA-TIMESTAMP=${ timestamp } &X-Auka-Integrator=${ integratorID } ` ;
152+ const message = `${ method } |${ url } |${ headers } ` ;
153+ const signature = getSignedMessage ( privateKey , message ) ;
154+ const authorization = "RSA-SHA256 " + signature ;
155+ const bulkHeaders = `Accept:application/vnd.mcash.api.merchant.v1+json
156+ Content-Type:application/json
157+ X-Auka-Merchant:${ merchantID }
158+ X-Auka-Integrator:${ integratorID }
159+ X-Auka-Timestamp:${ timestamp }
160+ X-Auka-Content-Digest:${ contentDigest }
161+ Authorization:${ authorization } ` ;
162+
163+ element . value = bulkHeaders ;
114164
115- element . value = bulkHeaders ;
165+ }
116166}
117167
118168// Main script
119- document . getElementById ( 'generate' ) . onclick = ( ) => generateHeaders ( )
120- document . getElementById ( 'method' ) . onchange = ( ) => generateHeaders ( )
121- document . getElementById ( 'url' ) . onchange = ( ) => generateHeaders ( )
122- document . getElementById ( 'body' ) . onchange = ( ) => generateHeaders ( )
123- document . getElementById ( 'bulk_headers' ) . onclick = event => 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 ) ;
124175
176+ setDefaultValues ( ) ;
177+ generateHeaders ( ) ;
125178
126- setDefaultValues ( )
127- generateHeaders ( )
179+ // console.log(isIntegrator);
0 commit comments