http-hmac-javascript
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Date.now||(Date.now=function(){return(new Date).getTime()});var AcquiaHttpHmac=function(){function e(t){var n=t.realm,r=t.public_key,o=t.secret_key,a=t.version,i=void 0===a?"2.0":a,s=t.default_content_type,c=void 0===s?"application/json":s;if(_classCallCheck(this,e),!n)throw new Error('The "realm" must not be empty.');if(!r)throw new Error('The "public_key" must not be empty.');if(!o)throw new Error('The "secret_key" must not be empty.');var u=["2.0"];if(u.indexOf(i)<0)throw new Error('The version must be "'+u.join('" or "')+'". Version "'+i+'" is not supported.');var p=CryptoJS.enc.Base64.parse(o);this.config={realm:n,public_key:r,parsed_secret_key:p,version:i,default_content_type:c},this.SUPPORTED_METHODS=["GET","POST","PUT","DELETE","HEAD","OPTIONS","CUSTOM"]}return _createClass(e,[{key:"sign",value:function(e){var t=e.request,n=e.method,r=e.path,o=e.signed_headers,a=void 0===o?{}:o,i=e.content_type,s=void 0===i?this.config.default_content_type:i,c=e.body,u=void 0===c?"":c;if(!(t instanceof XMLHttpRequest||"undefined"!=typeof MockHttpRequest&&t instanceof MockHttpRequest))throw new Error("The request must be a XMLHttpRequest.");if(this.SUPPORTED_METHODS.indexOf(n)<0)throw new Error('The method must be "'+this.SUPPORTED_METHODS.join('" or "')+'". "'+n+'" is not supported.');if(!r)throw new Error("The end point path must not be empty.");var p=function(e){var t=arguments.length<=1||void 0===arguments[1]?"=":arguments[1],n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r=arguments.length<=3||void 0===arguments[3]?"&":arguments[3],o=[];for(var a in e)e.hasOwnProperty(a)&&o.push(""+a+t+e[a]+n);return o.join(r)},h=function(){var e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:7&n|8).toString(16)})},m=function(e,t){var n=["GET","HEAD"];return 0!==e.length&&n.indexOf(t)<0},f=h(),l=document.createElement("a"),d={id:this.config.public_key,nonce:f,realm:this.config.realm,version:this.config.version},y=Math.floor(Date.now()/1e3).toString(),x=m(u,n)?CryptoJS.SHA256(u).toString(CryptoJS.enc.Base64):"",g=m(u,n)?"\n"+s+"\n"+x:"";l.href=r;var v=l.port?":"+l.port:"",H=""+l.hostname+v,S=l.search.substring(1),_=n+"\n"+H+"\n"+l.pathname+"\n"+S+"\n"+p(d)+"\n"+y+g,T=p(d,'="','"',","),w=0===Object.keys(a).length?"":',headers="'+Object.keys(a).join()+'"',E=CryptoJS.HmacSHA256(_,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),b="acquia-http-hmac "+T+',signature="'+E+'"'+w;t.acquiaHttpHmac={},t.acquiaHttpHmac.timestamp=y,t.acquiaHttpHmac.nonce=f,t.setRequestHeader("X-Authorization-Timestamp",y),t.setRequestHeader("Authorization",b),x&&t.setRequestHeader("X-Authorization-Content-SHA256",x)}},{key:"hasValidResponse",value:function(e){var t=e.acquiaHttpHmac.nonce+"\n"+e.acquiaHttpHmac.timestamp+"\n"+e.responseText,n=CryptoJS.HmacSHA256(t,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),r=e.getResponseHeader("X-Server-Authorization-HMAC-SHA256");return n===r}}]),e}(); | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Date.now||(Date.now=function(){return(new Date).getTime()});var AcquiaHttpHmac=function(){function e(t){var n=t.realm,r=t.public_key,o=t.secret_key,a=t.version,i=void 0===a?"2.0":a,s=t.default_content_type,u=void 0===s?"application/json":s;if(_classCallCheck(this,e),!n)throw new Error('The "realm" must not be empty.');if(!r)throw new Error('The "public_key" must not be empty.');if(!o)throw new Error('The "secret_key" must not be empty.');var c=["2.0"];if(c.indexOf(i)<0)throw new Error('The version must be "'+c.join('" or "')+'". Version "'+i+'" is not supported.');var p=CryptoJS.enc.Base64.parse(o);this.config={realm:n,public_key:r,parsed_secret_key:p,version:i,default_content_type:u},this.SUPPORTED_METHODS=["GET","POST","PUT","DELETE","HEAD","OPTIONS","CUSTOM"]}return _createClass(e,[{key:"sign",value:function(e){var t=e.request,n=e.method,r=e.path,o=e.signed_headers,a=void 0===o?{}:o,i=e.content_type,s=void 0===i?this.config.default_content_type:i,u=e.body,c=void 0===u?"":u;if(!(t instanceof XMLHttpRequest||"undefined"!=typeof MockHttpRequest&&t instanceof MockHttpRequest))throw new Error("The request must be a XMLHttpRequest.");if(this.SUPPORTED_METHODS.indexOf(n)<0)throw new Error('The method must be "'+this.SUPPORTED_METHODS.join('" or "')+'". "'+n+'" is not supported.');if(!r)throw new Error("The end point path must not be empty.");var p=function(e){var t=arguments.length<=1||void 0===arguments[1]?"=":arguments[1],n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r=arguments.length<=3||void 0===arguments[3]?"&":arguments[3],o=[];for(var a in e)e.hasOwnProperty(a)&&o.push(""+a+t+e[a]+n);return o.join(r)},f=function(){var e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:7&n|8).toString(16)})},m=function(e,t){var n=["GET","HEAD"];return 0!==e.length&&n.indexOf(t)<0},h=f(),y=document.createElement("a"),l={id:this.config.public_key,nonce:h,realm:this.config.realm,version:this.config.version},d=Math.floor(Date.now()/1e3).toString(),x=m(c,n)?CryptoJS.SHA256(c).toString(CryptoJS.enc.Base64):"",H=m(c,n)?"\n"+s+"\n"+x:"";y.href=r;var g=y.port?":"+y.port:"",v=""+y.hostname+g,S=y.search.substring(1),_=n+"\n"+v+"\n"+y.pathname+"\n"+S+"\n"+p(l)+"\n"+d+H,b=p(l,'="','"',","),w=0===Object.keys(a).length?"":',headers="'+Object.keys(a).join()+'"',T=CryptoJS.HmacSHA256(_,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),E="acquia-http-hmac "+b+',signature="'+T+'"'+w;t.acquiaHttpHmac={},t.acquiaHttpHmac.timestamp=d,t.acquiaHttpHmac.nonce=h,t.setRequestHeader("X-Authorization-Timestamp",d),t.setRequestHeader("Authorization",E),x&&t.setRequestHeader("X-Authorization-Content-SHA256",x)}},{key:"hasValidResponse",value:function(e){var t=e.acquiaHttpHmac.nonce+"\n"+e.acquiaHttpHmac.timestamp+"\n"+e.responseText,n=CryptoJS.HmacSHA256(t,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),r=e.getResponseHeader("X-Server-Authorization-HMAC-SHA256");return n===r}}]),e}();if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))){var CryptoJS=require("crypto-js");module.exports=exports=AcquiaHttpHmac}else{if("function"==typeof define&&define.amd)throw new Error("Update here to support AMD.");window.AcquiaHttpHmac=AcquiaHttpHmac} | ||
!function(t,n){"object"==typeof exports?module.exports=exports=n():"function"==typeof define&&define.amd?define([],n):t.CryptoJS=n()}(this,function(){var t=t||function(t,n){var i={},e=i.lib={},r=e.Base=function(){function t(){}return{extend:function(n){t.prototype=this;var i=new t;return n&&i.mixIn(n),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),s=e.WordArray=r.extend({init:function(t,i){t=this.words=t||[],i!=n?this.sigBytes=i:this.sigBytes=4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var n=this.words,i=t.words,e=this.sigBytes,r=t.sigBytes;if(this.clamp(),e%4)for(var s=0;r>s;s++){var o=i[s>>>2]>>>24-s%4*8&255;n[e+s>>>2]|=o<<24-(e+s)%4*8}else for(var s=0;r>s;s+=4)n[e+s>>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var n=this.words,i=this.sigBytes;n[i>>>2]&=4294967295<<32-i%4*8,n.length=t.ceil(i/4)},clone:function(){var t=r.clone.call(this);return t.words=this.words.slice(0),t},random:function(n){for(var i,e=[],r=function(n){var n=n,i=987654321,e=4294967295;return function(){i=36969*(65535&i)+(i>>16)&e,n=18e3*(65535&n)+(n>>16)&e;var r=(i<<16)+n&e;return r/=4294967296,r+=.5,r*(t.random()>.5?1:-1)}},o=0;n>o;o+=4){var a=r(4294967296*(i||t.random()));i=987654071*a(),e.push(4294967296*a()|0)}return new s.init(e,n)}}),o=i.enc={},a=o.Hex={stringify:function(t){for(var n=t.words,i=t.sigBytes,e=[],r=0;i>r;r++){var s=n[r>>>2]>>>24-r%4*8&255;e.push((s>>>4).toString(16)),e.push((15&s).toString(16))}return e.join("")},parse:function(t){for(var n=t.length,i=[],e=0;n>e;e+=2)i[e>>>3]|=parseInt(t.substr(e,2),16)<<24-e%8*4;return new s.init(i,n/2)}},c=o.Latin1={stringify:function(t){for(var n=t.words,i=t.sigBytes,e=[],r=0;i>r;r++){var s=n[r>>>2]>>>24-r%4*8&255;e.push(String.fromCharCode(s))}return e.join("")},parse:function(t){for(var n=t.length,i=[],e=0;n>e;e++)i[e>>>2]|=(255&t.charCodeAt(e))<<24-e%4*8;return new s.init(i,n)}},u=o.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(n){throw new Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=e.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(n){var i=this._data,e=i.words,r=i.sigBytes,o=this.blockSize,a=4*o,c=r/a;c=n?t.ceil(c):t.max((0|c)-this._minBufferSize,0);var u=c*o,f=t.min(4*u,r);if(u){for(var h=0;u>h;h+=o)this._doProcessBlock(e,h);var p=e.splice(0,u);i.sigBytes-=f}return new s.init(p,f)},clone:function(){var t=r.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0}),h=(e.Hasher=f.extend({cfg:r.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){t&&this._append(t);var n=this._doFinalize();return n},blockSize:16,_createHelper:function(t){return function(n,i){return new t.init(i).finalize(n)}},_createHmacHelper:function(t){return function(n,i){return new h.HMAC.init(t,i).finalize(n)}}}),i.algo={});return i}(Math);return t}); | ||
@@ -7,2 +7,2 @@ !function(e,t){"object"==typeof exports?module.exports=exports=t(require("./core")):"function"==typeof define&&define.amd?define(["./core"],t):t(e.CryptoJS)}(this,function(e){!function(){var t=e,i=t.lib,n=i.Base,s=t.enc,r=s.Utf8,o=t.algo;o.HMAC=n.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=r.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),o=this._iKey=t.clone(),a=s.words,f=o.words,c=0;i>c;c++)a[c]^=1549556828,f[c]^=909522486;s.sigBytes=o.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);t.reset();var n=t.finalize(this._oKey.clone().concat(i));return n}})}()}); | ||
!function(r,e){"object"==typeof exports?module.exports=exports=e(require("./core")):"function"==typeof define&&define.amd?define(["./core"],e):e(r.CryptoJS)}(this,function(r){return function(){var e=r,t=e.lib,n=t.WordArray,a=e.enc;a.Base64={stringify:function(r){var e=r.words,t=r.sigBytes,n=this._map;r.clamp();for(var a=[],i=0;t>i;i+=3)for(var o=e[i>>>2]>>>24-i%4*8&255,f=e[i+1>>>2]>>>24-(i+1)%4*8&255,c=e[i+2>>>2]>>>24-(i+2)%4*8&255,s=o<<16|f<<8|c,p=0;4>p&&t>i+.75*p;p++)a.push(n.charAt(s>>>6*(3-p)&63));var u=n.charAt(64);if(u)for(;a.length%4;)a.push(u);return a.join("")},parse:function(r){var e=r.length,t=this._map,a=t.charAt(64);if(a){var i=r.indexOf(a);-1!=i&&(e=i)}for(var o=[],f=0,c=0;e>c;c++)if(c%4){var s=t.indexOf(r.charAt(c-1))<<c%4*2,p=t.indexOf(r.charAt(c))>>>6-c%4*2,u=s|p;o[f>>>2]|=u<<24-f%4*8,f++}return n.create(o,f)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),r.enc.Base64}); | ||
"use strict";var method="GET",port=location.port?":"+location.port:"",pathname=location.pathname.replace(/html$/,"php"),path=location.protocol+"//"+location.hostname+port+pathname+"?first_word=Hello&second_word=World#myAnchor",signed_headers={"special-header-1":"special_header_1_value","special-header-2":"special_header_2_value"},content_type="text/plain",hmac_config={realm:"dice",public_key:"ABCD-1234",secret_key:"d175024aa4c4d8b312a7114687790c772dd94fb725cb68016aaeae5a76d68102"},HMAC=new AcquiaHttpHmac(hmac_config),request=new XMLHttpRequest;request.onreadystatechange=function(){if(4==request.readyState){if(200!==request.status)throw new Error("Problem retrieving data.",request);if(!HMAC.hasValidResponse(request))throw new Error("The request does not have a valid response.",request);document.getElementById("text-display").innerHTML=request.response}},request.open(method,path,!0),request.setRequestHeader("Content-Type",content_type),request.setRequestHeader("Special-Header-1","special_header_1_value"),request.setRequestHeader("Special-Header-2","special_header_2_value"),request.setRequestHeader("Special-Header-3","special_header_3_value");var sign_parameters={request:request,method:method,path:path,signed_headers:signed_headers,content_type:content_type};HMAC.sign(sign_parameters),request.send(); | ||
"use strict";var method="GET",port=location.port?":"+location.port:"",pathname=location.pathname.replace(/html$/,"php"),path=location.protocol+"//"+location.hostname+port+pathname+"?first_word=Hello&second_word=World#myAnchor",signed_headers={"special-header-1":"special_header_1_value","special-header-2":"special_header_2_value"},content_type="text/plain",hmac_config={realm:"dice",public_key:"ABCD-1234",secret_key:"d175024aa4c4d8b312a7114687790c772dd94fb725cb68016aaeae5a76d68102"},HMAC=new AcquiaHttpHmac(hmac_config),request=new XMLHttpRequest;request.onreadystatechange=function(){if(4===request.readyState){if(200!==request.status)throw new Error("Problem retrieving data.",request);if(!HMAC.hasValidResponse(request))throw new Error("The request does not have a valid response.",request);document.getElementById("text-display").innerHTML=request.response}},request.open(method,path,!0),request.setRequestHeader("Content-Type",content_type),request.setRequestHeader("Special-Header-1","special_header_1_value"),request.setRequestHeader("Special-Header-2","special_header_2_value"),request.setRequestHeader("Special-Header-3","special_header_3_value");var sign_parameters={request:request,method:method,path:path,signed_headers:signed_headers,content_type:content_type};HMAC.sign(sign_parameters),request.send(); |
@@ -1,2 +0,2 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Date.now||(Date.now=function(){return(new Date).getTime()});var AcquiaHttpHmac=function(){function e(t){var n=t.realm,r=t.public_key,o=t.secret_key,a=t.version,i=void 0===a?"2.0":a,s=t.default_content_type,c=void 0===s?"application/json":s;if(_classCallCheck(this,e),!n)throw new Error('The "realm" must not be empty.');if(!r)throw new Error('The "public_key" must not be empty.');if(!o)throw new Error('The "secret_key" must not be empty.');var u=["2.0"];if(u.indexOf(i)<0)throw new Error('The version must be "'+u.join('" or "')+'". Version "'+i+'" is not supported.');var p=CryptoJS.enc.Base64.parse(o);this.config={realm:n,public_key:r,parsed_secret_key:p,version:i,default_content_type:c},this.SUPPORTED_METHODS=["GET","POST","PUT","DELETE","HEAD","OPTIONS","CUSTOM"]}return _createClass(e,[{key:"sign",value:function(e){var t=e.request,n=e.method,r=e.path,o=e.signed_headers,a=void 0===o?{}:o,i=e.content_type,s=void 0===i?this.config.default_content_type:i,c=e.body,u=void 0===c?"":c;if(!(t instanceof XMLHttpRequest||"undefined"!=typeof MockHttpRequest&&t instanceof MockHttpRequest))throw new Error("The request must be a XMLHttpRequest.");if(this.SUPPORTED_METHODS.indexOf(n)<0)throw new Error('The method must be "'+this.SUPPORTED_METHODS.join('" or "')+'". "'+n+'" is not supported.');if(!r)throw new Error("The end point path must not be empty.");var p=function(e){var t=arguments.length<=1||void 0===arguments[1]?"=":arguments[1],n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r=arguments.length<=3||void 0===arguments[3]?"&":arguments[3],o=[];for(var a in e)e.hasOwnProperty(a)&&o.push(""+a+t+e[a]+n);return o.join(r)},h=function(){var e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:7&n|8).toString(16)})},m=function(e,t){var n=["GET","HEAD"];return 0!==e.length&&n.indexOf(t)<0},f=h(),l=document.createElement("a"),d={id:this.config.public_key,nonce:f,realm:this.config.realm,version:this.config.version},y=Math.floor(Date.now()/1e3).toString(),x=m(u,n)?CryptoJS.SHA256(u).toString(CryptoJS.enc.Base64):"",g=m(u,n)?"\n"+s+"\n"+x:"";l.href=r;var v=l.port?":"+l.port:"",H=""+l.hostname+v,S=l.search.substring(1),_=n+"\n"+H+"\n"+l.pathname+"\n"+S+"\n"+p(d)+"\n"+y+g,T=p(d,'="','"',","),w=0===Object.keys(a).length?"":',headers="'+Object.keys(a).join()+'"',E=CryptoJS.HmacSHA256(_,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),b="acquia-http-hmac "+T+',signature="'+E+'"'+w;t.acquiaHttpHmac={},t.acquiaHttpHmac.timestamp=y,t.acquiaHttpHmac.nonce=f,t.setRequestHeader("X-Authorization-Timestamp",y),t.setRequestHeader("Authorization",b),x&&t.setRequestHeader("X-Authorization-Content-SHA256",x)}},{key:"hasValidResponse",value:function(e){var t=e.acquiaHttpHmac.nonce+"\n"+e.acquiaHttpHmac.timestamp+"\n"+e.responseText,n=CryptoJS.HmacSHA256(t,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),r=e.getResponseHeader("X-Server-Authorization-HMAC-SHA256");return n===r}}]),e}(); | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Date.now||(Date.now=function(){return(new Date).getTime()});var AcquiaHttpHmac=function(){function e(t){var n=t.realm,r=t.public_key,o=t.secret_key,a=t.version,i=void 0===a?"2.0":a,s=t.default_content_type,u=void 0===s?"application/json":s;if(_classCallCheck(this,e),!n)throw new Error('The "realm" must not be empty.');if(!r)throw new Error('The "public_key" must not be empty.');if(!o)throw new Error('The "secret_key" must not be empty.');var c=["2.0"];if(c.indexOf(i)<0)throw new Error('The version must be "'+c.join('" or "')+'". Version "'+i+'" is not supported.');var p=CryptoJS.enc.Base64.parse(o);this.config={realm:n,public_key:r,parsed_secret_key:p,version:i,default_content_type:u},this.SUPPORTED_METHODS=["GET","POST","PUT","DELETE","HEAD","OPTIONS","CUSTOM"]}return _createClass(e,[{key:"sign",value:function(e){var t=e.request,n=e.method,r=e.path,o=e.signed_headers,a=void 0===o?{}:o,i=e.content_type,s=void 0===i?this.config.default_content_type:i,u=e.body,c=void 0===u?"":u;if(!(t instanceof XMLHttpRequest||"undefined"!=typeof MockHttpRequest&&t instanceof MockHttpRequest))throw new Error("The request must be a XMLHttpRequest.");if(this.SUPPORTED_METHODS.indexOf(n)<0)throw new Error('The method must be "'+this.SUPPORTED_METHODS.join('" or "')+'". "'+n+'" is not supported.');if(!r)throw new Error("The end point path must not be empty.");var p=function(e){var t=arguments.length<=1||void 0===arguments[1]?"=":arguments[1],n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r=arguments.length<=3||void 0===arguments[3]?"&":arguments[3],o=[];for(var a in e)e.hasOwnProperty(a)&&o.push(""+a+t+e[a]+n);return o.join(r)},f=function(){var e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:7&n|8).toString(16)})},m=function(e,t){var n=["GET","HEAD"];return 0!==e.length&&n.indexOf(t)<0},h=f(),y=document.createElement("a"),l={id:this.config.public_key,nonce:h,realm:this.config.realm,version:this.config.version},d=Math.floor(Date.now()/1e3).toString(),x=m(c,n)?CryptoJS.SHA256(c).toString(CryptoJS.enc.Base64):"",H=m(c,n)?"\n"+s+"\n"+x:"";y.href=r;var g=y.port?":"+y.port:"",v=""+y.hostname+g,S=y.search.substring(1),_=n+"\n"+v+"\n"+y.pathname+"\n"+S+"\n"+p(l)+"\n"+d+H,b=p(l,'="','"',","),w=0===Object.keys(a).length?"":',headers="'+Object.keys(a).join()+'"',T=CryptoJS.HmacSHA256(_,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),E="acquia-http-hmac "+b+',signature="'+T+'"'+w;t.acquiaHttpHmac={},t.acquiaHttpHmac.timestamp=d,t.acquiaHttpHmac.nonce=h,t.setRequestHeader("X-Authorization-Timestamp",d),t.setRequestHeader("Authorization",E),x&&t.setRequestHeader("X-Authorization-Content-SHA256",x)}},{key:"hasValidResponse",value:function(e){var t=e.acquiaHttpHmac.nonce+"\n"+e.acquiaHttpHmac.timestamp+"\n"+e.responseText,n=CryptoJS.HmacSHA256(t,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),r=e.getResponseHeader("X-Server-Authorization-HMAC-SHA256");return n===r}}]),e}();if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))){var CryptoJS=require("crypto-js");module.exports=exports=AcquiaHttpHmac}else{if("function"==typeof define&&define.amd)throw new Error("Update here to support AMD.");window.AcquiaHttpHmac=AcquiaHttpHmac} | ||
!function(t,n){"object"==typeof exports?module.exports=exports=n():"function"==typeof define&&define.amd?define([],n):t.CryptoJS=n()}(this,function(){var t=t||function(t,n){var i={},e=i.lib={},r=e.Base=function(){function t(){}return{extend:function(n){t.prototype=this;var i=new t;return n&&i.mixIn(n),i.hasOwnProperty("init")||(i.init=function(){i.$super.init.apply(this,arguments)}),i.init.prototype=i,i.$super=this,i},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var n in t)t.hasOwnProperty(n)&&(this[n]=t[n]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),s=e.WordArray=r.extend({init:function(t,i){t=this.words=t||[],i!=n?this.sigBytes=i:this.sigBytes=4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var n=this.words,i=t.words,e=this.sigBytes,r=t.sigBytes;if(this.clamp(),e%4)for(var s=0;r>s;s++){var o=i[s>>>2]>>>24-s%4*8&255;n[e+s>>>2]|=o<<24-(e+s)%4*8}else for(var s=0;r>s;s+=4)n[e+s>>>2]=i[s>>>2];return this.sigBytes+=r,this},clamp:function(){var n=this.words,i=this.sigBytes;n[i>>>2]&=4294967295<<32-i%4*8,n.length=t.ceil(i/4)},clone:function(){var t=r.clone.call(this);return t.words=this.words.slice(0),t},random:function(n){for(var i,e=[],r=function(n){var n=n,i=987654321,e=4294967295;return function(){i=36969*(65535&i)+(i>>16)&e,n=18e3*(65535&n)+(n>>16)&e;var r=(i<<16)+n&e;return r/=4294967296,r+=.5,r*(t.random()>.5?1:-1)}},o=0;n>o;o+=4){var a=r(4294967296*(i||t.random()));i=987654071*a(),e.push(4294967296*a()|0)}return new s.init(e,n)}}),o=i.enc={},a=o.Hex={stringify:function(t){for(var n=t.words,i=t.sigBytes,e=[],r=0;i>r;r++){var s=n[r>>>2]>>>24-r%4*8&255;e.push((s>>>4).toString(16)),e.push((15&s).toString(16))}return e.join("")},parse:function(t){for(var n=t.length,i=[],e=0;n>e;e+=2)i[e>>>3]|=parseInt(t.substr(e,2),16)<<24-e%8*4;return new s.init(i,n/2)}},c=o.Latin1={stringify:function(t){for(var n=t.words,i=t.sigBytes,e=[],r=0;i>r;r++){var s=n[r>>>2]>>>24-r%4*8&255;e.push(String.fromCharCode(s))}return e.join("")},parse:function(t){for(var n=t.length,i=[],e=0;n>e;e++)i[e>>>2]|=(255&t.charCodeAt(e))<<24-e%4*8;return new s.init(i,n)}},u=o.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(n){throw new Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},f=e.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(n){var i=this._data,e=i.words,r=i.sigBytes,o=this.blockSize,a=4*o,c=r/a;c=n?t.ceil(c):t.max((0|c)-this._minBufferSize,0);var u=c*o,f=t.min(4*u,r);if(u){for(var h=0;u>h;h+=o)this._doProcessBlock(e,h);var p=e.splice(0,u);i.sigBytes-=f}return new s.init(p,f)},clone:function(){var t=r.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0}),h=(e.Hasher=f.extend({cfg:r.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){f.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){t&&this._append(t);var n=this._doFinalize();return n},blockSize:16,_createHelper:function(t){return function(n,i){return new t.init(i).finalize(n)}},_createHmacHelper:function(t){return function(n,i){return new h.HMAC.init(t,i).finalize(n)}}}),i.algo={});return i}(Math);return t}); | ||
@@ -7,2 +7,2 @@ !function(e,t){"object"==typeof exports?module.exports=exports=t(require("./core")):"function"==typeof define&&define.amd?define(["./core"],t):t(e.CryptoJS)}(this,function(e){!function(){var t=e,i=t.lib,n=i.Base,s=t.enc,r=s.Utf8,o=t.algo;o.HMAC=n.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=r.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var s=this._oKey=t.clone(),o=this._iKey=t.clone(),a=s.words,f=o.words,c=0;i>c;c++)a[c]^=1549556828,f[c]^=909522486;s.sigBytes=o.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);t.reset();var n=t.finalize(this._oKey.clone().concat(i));return n}})}()}); | ||
!function(r,e){"object"==typeof exports?module.exports=exports=e(require("./core")):"function"==typeof define&&define.amd?define(["./core"],e):e(r.CryptoJS)}(this,function(r){return function(){var e=r,t=e.lib,n=t.WordArray,a=e.enc;a.Base64={stringify:function(r){var e=r.words,t=r.sigBytes,n=this._map;r.clamp();for(var a=[],i=0;t>i;i+=3)for(var o=e[i>>>2]>>>24-i%4*8&255,f=e[i+1>>>2]>>>24-(i+1)%4*8&255,c=e[i+2>>>2]>>>24-(i+2)%4*8&255,s=o<<16|f<<8|c,p=0;4>p&&t>i+.75*p;p++)a.push(n.charAt(s>>>6*(3-p)&63));var u=n.charAt(64);if(u)for(;a.length%4;)a.push(u);return a.join("")},parse:function(r){var e=r.length,t=this._map,a=t.charAt(64);if(a){var i=r.indexOf(a);-1!=i&&(e=i)}for(var o=[],f=0,c=0;e>c;c++)if(c%4){var s=t.indexOf(r.charAt(c-1))<<c%4*2,p=t.indexOf(r.charAt(c))>>>6-c%4*2,u=s|p;o[f>>>2]|=u<<24-f%4*8,f++}return n.create(o,f)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),r.enc.Base64}); | ||
"use strict";var method="POST",port=location.port?":"+location.port:"",pathname=location.pathname.replace(/html$/,"php"),path=location.protocol+"//"+location.hostname+port+pathname+"?myQueryParameter=90210#myAnchor",signed_headers={"special-header-1":"special_header_1_value","special-header-2":"special_header_2_value"},content_type="application/x-www-form-urlencoded",body="first_word=Hello&second_word=World",hmac_config={realm:"dice",public_key:"ABCD-1234",secret_key:"d175024aa4c4d8b312a7114687790c772dd94fb725cb68016aaeae5a76d68102"},HMAC=new AcquiaHttpHmac(hmac_config),request=new XMLHttpRequest;request.onreadystatechange=function(){if(4==request.readyState){if(200!==request.status)throw new Error("Problem retrieving data.",request);if(!HMAC.hasValidResponse(request))throw new Error("The request does not have a valid response.",request);document.getElementById("text-display").innerHTML=request.response}},request.open(method,path,!0),request.setRequestHeader("Content-Type",content_type),request.setRequestHeader("Special-Header-1","special_header_1_value"),request.setRequestHeader("Special-Header-2","special_header_2_value"),request.setRequestHeader("Special-Header-3","special_header_3_value");var sign_parameters={request:request,method:method,path:path,signed_headers:signed_headers,content_type:content_type,body:body};HMAC.sign(sign_parameters),request.send(body); | ||
"use strict";var method="POST",port=location.port?":"+location.port:"",pathname=location.pathname.replace(/html$/,"php"),path=location.protocol+"//"+location.hostname+port+pathname+"?myQueryParameter=90210#myAnchor",signed_headers={"special-header-1":"special_header_1_value","special-header-2":"special_header_2_value"},content_type="application/x-www-form-urlencoded",body="first_word=Hello&second_word=World",hmac_config={realm:"dice",public_key:"ABCD-1234",secret_key:"d175024aa4c4d8b312a7114687790c772dd94fb725cb68016aaeae5a76d68102"},HMAC=new AcquiaHttpHmac(hmac_config),request=new XMLHttpRequest;request.onreadystatechange=function(){if(4===request.readyState){if(200!==request.status)throw new Error("Problem retrieving data.",request);if(!HMAC.hasValidResponse(request))throw new Error("The request does not have a valid response.",request);document.getElementById("text-display").innerHTML=request.response}},request.open(method,path,!0),request.setRequestHeader("Content-Type",content_type),request.setRequestHeader("Special-Header-1","special_header_1_value"),request.setRequestHeader("Special-Header-2","special_header_2_value"),request.setRequestHeader("Special-Header-3","special_header_3_value");var sign_parameters={request:request,method:method,path:path,signed_headers:signed_headers,content_type:content_type,body:body};HMAC.sign(sign_parameters),request.send(body); |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -19,4 +21,2 @@ | ||
* For more information, see: https://github.com/acquia/http-hmac-spec/tree/2.0 | ||
* | ||
* @todo Needs to explicitly include the Crypto-js library as a dependency. | ||
*/ | ||
@@ -242,2 +242,14 @@ | ||
return AcquiaHttpHmac; | ||
}(); | ||
}(); | ||
if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === "object") { | ||
// CommonJS | ||
var CryptoJS = require('crypto-js'); | ||
module.exports = exports = AcquiaHttpHmac; | ||
} else if (typeof define === "function" && define.amd) { | ||
// AMD | ||
throw new Error('Update here to support AMD.'); | ||
} else { | ||
// Global (browser) | ||
window.AcquiaHttpHmac = AcquiaHttpHmac; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Date.now||(Date.now=function(){return(new Date).getTime()});var AcquiaHttpHmac=function(){function e(t){var n=t.realm,r=t.public_key,o=t.secret_key,a=t.version,i=void 0===a?"2.0":a,s=t.default_content_type,c=void 0===s?"application/json":s;if(_classCallCheck(this,e),!n)throw new Error('The "realm" must not be empty.');if(!r)throw new Error('The "public_key" must not be empty.');if(!o)throw new Error('The "secret_key" must not be empty.');var u=["2.0"];if(u.indexOf(i)<0)throw new Error('The version must be "'+u.join('" or "')+'". Version "'+i+'" is not supported.');var p=CryptoJS.enc.Base64.parse(o);this.config={realm:n,public_key:r,parsed_secret_key:p,version:i,default_content_type:c},this.SUPPORTED_METHODS=["GET","POST","PUT","DELETE","HEAD","OPTIONS","CUSTOM"]}return _createClass(e,[{key:"sign",value:function(e){var t=e.request,n=e.method,r=e.path,o=e.signed_headers,a=void 0===o?{}:o,i=e.content_type,s=void 0===i?this.config.default_content_type:i,c=e.body,u=void 0===c?"":c;if(!(t instanceof XMLHttpRequest||"undefined"!=typeof MockHttpRequest&&t instanceof MockHttpRequest))throw new Error("The request must be a XMLHttpRequest.");if(this.SUPPORTED_METHODS.indexOf(n)<0)throw new Error('The method must be "'+this.SUPPORTED_METHODS.join('" or "')+'". "'+n+'" is not supported.');if(!r)throw new Error("The end point path must not be empty.");var p=function(e){var t=arguments.length<=1||void 0===arguments[1]?"=":arguments[1],n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r=arguments.length<=3||void 0===arguments[3]?"&":arguments[3],o=[];for(var a in e)e.hasOwnProperty(a)&&o.push(""+a+t+e[a]+n);return o.join(r)},h=function(){var e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:7&n|8).toString(16)})},m=function(e,t){var n=["GET","HEAD"];return 0!==e.length&&n.indexOf(t)<0},f=h(),l=document.createElement("a"),d={id:this.config.public_key,nonce:f,realm:this.config.realm,version:this.config.version},y=Math.floor(Date.now()/1e3).toString(),x=m(u,n)?CryptoJS.SHA256(u).toString(CryptoJS.enc.Base64):"",g=m(u,n)?"\n"+s+"\n"+x:"";l.href=r;var v=l.port?":"+l.port:"",H=""+l.hostname+v,S=l.search.substring(1),_=n+"\n"+H+"\n"+l.pathname+"\n"+S+"\n"+p(d)+"\n"+y+g,T=p(d,'="','"',","),w=0===Object.keys(a).length?"":',headers="'+Object.keys(a).join()+'"',E=CryptoJS.HmacSHA256(_,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),b="acquia-http-hmac "+T+',signature="'+E+'"'+w;t.acquiaHttpHmac={},t.acquiaHttpHmac.timestamp=y,t.acquiaHttpHmac.nonce=f,t.setRequestHeader("X-Authorization-Timestamp",y),t.setRequestHeader("Authorization",b),x&&t.setRequestHeader("X-Authorization-Content-SHA256",x)}},{key:"hasValidResponse",value:function(e){var t=e.acquiaHttpHmac.nonce+"\n"+e.acquiaHttpHmac.timestamp+"\n"+e.responseText,n=CryptoJS.HmacSHA256(t,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),r=e.getResponseHeader("X-Server-Authorization-HMAC-SHA256");return n===r}}]),e}(); | ||
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Date.now||(Date.now=function(){return(new Date).getTime()});var AcquiaHttpHmac=function(){function e(t){var n=t.realm,r=t.public_key,o=t.secret_key,a=t.version,i=void 0===a?"2.0":a,s=t.default_content_type,u=void 0===s?"application/json":s;if(_classCallCheck(this,e),!n)throw new Error('The "realm" must not be empty.');if(!r)throw new Error('The "public_key" must not be empty.');if(!o)throw new Error('The "secret_key" must not be empty.');var c=["2.0"];if(c.indexOf(i)<0)throw new Error('The version must be "'+c.join('" or "')+'". Version "'+i+'" is not supported.');var p=CryptoJS.enc.Base64.parse(o);this.config={realm:n,public_key:r,parsed_secret_key:p,version:i,default_content_type:u},this.SUPPORTED_METHODS=["GET","POST","PUT","DELETE","HEAD","OPTIONS","CUSTOM"]}return _createClass(e,[{key:"sign",value:function(e){var t=e.request,n=e.method,r=e.path,o=e.signed_headers,a=void 0===o?{}:o,i=e.content_type,s=void 0===i?this.config.default_content_type:i,u=e.body,c=void 0===u?"":u;if(!(t instanceof XMLHttpRequest||"undefined"!=typeof MockHttpRequest&&t instanceof MockHttpRequest))throw new Error("The request must be a XMLHttpRequest.");if(this.SUPPORTED_METHODS.indexOf(n)<0)throw new Error('The method must be "'+this.SUPPORTED_METHODS.join('" or "')+'". "'+n+'" is not supported.');if(!r)throw new Error("The end point path must not be empty.");var p=function(e){var t=arguments.length<=1||void 0===arguments[1]?"=":arguments[1],n=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r=arguments.length<=3||void 0===arguments[3]?"&":arguments[3],o=[];for(var a in e)e.hasOwnProperty(a)&&o.push(""+a+t+e[a]+n);return o.join(r)},f=function(){var e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:7&n|8).toString(16)})},m=function(e,t){var n=["GET","HEAD"];return 0!==e.length&&n.indexOf(t)<0},h=f(),y=document.createElement("a"),l={id:this.config.public_key,nonce:h,realm:this.config.realm,version:this.config.version},d=Math.floor(Date.now()/1e3).toString(),x=m(c,n)?CryptoJS.SHA256(c).toString(CryptoJS.enc.Base64):"",H=m(c,n)?"\n"+s+"\n"+x:"";y.href=r;var g=y.port?":"+y.port:"",v=""+y.hostname+g,S=y.search.substring(1),_=n+"\n"+v+"\n"+y.pathname+"\n"+S+"\n"+p(l)+"\n"+d+H,b=p(l,'="','"',","),w=0===Object.keys(a).length?"":',headers="'+Object.keys(a).join()+'"',T=CryptoJS.HmacSHA256(_,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),E="acquia-http-hmac "+b+',signature="'+T+'"'+w;t.acquiaHttpHmac={},t.acquiaHttpHmac.timestamp=d,t.acquiaHttpHmac.nonce=h,t.setRequestHeader("X-Authorization-Timestamp",d),t.setRequestHeader("Authorization",E),x&&t.setRequestHeader("X-Authorization-Content-SHA256",x)}},{key:"hasValidResponse",value:function(e){var t=e.acquiaHttpHmac.nonce+"\n"+e.acquiaHttpHmac.timestamp+"\n"+e.responseText,n=CryptoJS.HmacSHA256(t,this.config.parsed_secret_key).toString(CryptoJS.enc.Base64),r=e.getResponseHeader("X-Server-Authorization-HMAC-SHA256");return n===r}}]),e}();if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))){var CryptoJS=require("crypto-js");module.exports=exports=AcquiaHttpHmac}else{if("function"==typeof define&&define.amd)throw new Error("Update here to support AMD.");window.AcquiaHttpHmac=AcquiaHttpHmac} |
@@ -11,4 +11,2 @@ 'use strict'; | ||
* For more information, see: https://github.com/acquia/http-hmac-spec/tree/2.0 | ||
* | ||
* @todo Needs to explicitly include the Crypto-js library as a dependency. | ||
*/ | ||
@@ -201,1 +199,15 @@ class AcquiaHttpHmac { | ||
} | ||
if (typeof exports === "object") { | ||
// CommonJS | ||
var CryptoJS = require('crypto-js'); | ||
module.exports = exports = AcquiaHttpHmac; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
// AMD | ||
throw new Error('Update here to support AMD.') | ||
} | ||
else { | ||
// Global (browser) | ||
window.AcquiaHttpHmac = AcquiaHttpHmac; | ||
} |
{ | ||
"name": "http-hmac-javascript", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "HTTP HMAC JavaScript Library", | ||
"main": "gulpfile.js", | ||
"main": "./lib/es5/hmac.js", | ||
"dependencies": { | ||
@@ -7,0 +7,0 @@ "crypto-js": "^3.1.6" |
@@ -29,7 +29,6 @@ /** | ||
request.onreadystatechange = () => { | ||
if (request.readyState == 4) { | ||
if (request.readyState === 4) { | ||
// Check if the response status is 200 ok. | ||
if (request.status !== 200) { | ||
throw new Error('Problem retrieving data.', request); | ||
return; | ||
} | ||
@@ -40,3 +39,2 @@ | ||
throw new Error('The request does not have a valid response.', request); | ||
return; | ||
} | ||
@@ -43,0 +41,0 @@ |
@@ -30,7 +30,6 @@ /** | ||
request.onreadystatechange = () => { | ||
if (request.readyState == 4) { | ||
if (request.readyState === 4) { | ||
// Check if the response status is 200 ok. | ||
if (request.status !== 200) { | ||
throw new Error('Problem retrieving data.', request); | ||
return; | ||
} | ||
@@ -41,3 +40,2 @@ | ||
throw new Error('The request does not have a valid response.', request); | ||
return; | ||
} | ||
@@ -44,0 +42,0 @@ |
@@ -11,4 +11,2 @@ 'use strict'; | ||
* For more information, see: https://github.com/acquia/http-hmac-spec/tree/2.0 | ||
* | ||
* @todo Needs to explicitly include the Crypto-js library as a dependency. | ||
*/ | ||
@@ -201,1 +199,15 @@ class AcquiaHttpHmac { | ||
} | ||
if (typeof exports === "object") { | ||
// CommonJS | ||
var CryptoJS = require('crypto-js'); | ||
module.exports = exports = AcquiaHttpHmac; | ||
} | ||
else if (typeof define === "function" && define.amd) { | ||
// AMD | ||
throw new Error('Update here to support AMD.') | ||
} | ||
else { | ||
// Global (browser) | ||
window.AcquiaHttpHmac = AcquiaHttpHmac; | ||
} |
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
74605
3.29%1015
3.26%0
-100%4
33.33%