diff --git a/dist/otpauth.cjs.js b/dist/otpauth.cjs.js index b927cf93..a76bbae3 100644 --- a/dist/otpauth.cjs.js +++ b/dist/otpauth.cjs.js @@ -1,5 +1,5 @@ -/*! otpauth v6.2.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ +/*! otpauth v6.2.2 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ /*! sjcl v1.0.8 | (c) bitwiseshiftleft | (BSD-2-Clause OR GPL-2.0-only) | https://github.com/bitwiseshiftleft/sjcl */ 'use strict'; @@ -2680,7 +2680,7 @@ var URI = /*#__PURE__*/function () { * Library version. * @type {string} */ -var version = '6.2.1'; +var version = '6.2.2'; exports.HOTP = HOTP; exports.Secret = Secret; diff --git a/dist/otpauth.cjs.min.js b/dist/otpauth.cjs.min.js index 423087e9..e0af4d64 100644 --- a/dist/otpauth.cjs.min.js +++ b/dist/otpauth.cjs.min.js @@ -1,4 +1,4 @@ -/*! otpauth v6.2.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ +/*! otpauth v6.2.2 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ /*! sjcl v1.0.8 | (c) bitwiseshiftleft | (BSD-2-Clause OR GPL-2.0-only) | https://github.com/bitwiseshiftleft/sjcl */ "use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,i=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,o=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw o}}}}Object.defineProperty(exports,"__esModule",{value:!0});var Utils={uint:{fromBuf:function(t){for(var e=new Uint8Array(t),r=0,i=0;i0?"".concat(t(this.issuer),":").concat(t(this.label),"?issuer=").concat(t(this.issuer),"&"):"".concat(t(this.label),"?"))+"secret=".concat(t(this.secret.b32),"&")+"algorithm=".concat(t(this.algorithm),"&")+"digits=".concat(t(this.digits),"&")+"period=".concat(t(this.period))}}],[{key:"generate",value:function(t){var e=t.secret,r=t.algorithm,i=t.digits,n=t.period,o=void 0===n?defaults.period:n,s=t.timestamp,a=void 0===s?Date.now():s;return HOTP.generate({secret:e,algorithm:r,digits:i,counter:Math.floor(a/1e3/o)})}},{key:"validate",value:function(t){ var e=t.token,r=t.secret,i=t.algorithm,n=t.digits,o=t.period,s=void 0===o?defaults.period:o,a=t.timestamp,l=void 0===a?Date.now():a,h=t.window;return HOTP.validate({token:e,secret:r,algorithm:i,digits:n,counter:Math.floor(l/1e3/s),window:h})}}]),t}(),OTPURI_PARAMS=["issuer","secret","algorithm","digits","counter","period"],OTPURI_REGEX=new RegExp("^otpauth:\\/\\/([ht]otp)\\/(.+)\\?((?:&?(?:".concat(OTPURI_PARAMS.join("|"),")=[^&]+)+)$"),"i"),SECRET_REGEX=/^[2-7A-Z]+=*$/i,ALGORITHM_REGEX=/^SHA(?:1|256|512)$/i,INTEGER_REGEX=/^[+-]?\d+$/,POSITIVE_INTEGER_REGEX=/^\+?[1-9]\d*$/,URI=function(){function t(){_classCallCheck(this,t)}return _createClass(t,null,[{key:"parse",value:function(t){var e;try{e=t.match(OTPURI_REGEX)}catch(t){}if(!Array.isArray(e))throw new URIError("Invalid URI format");var r,i=e[1].toLowerCase(),n=e[2].split(/:(.+)/,2).map(decodeURIComponent),o=e[3].split("&").reduce((function(t,e){var r=e.split(/=(.+)/,2).map(decodeURIComponent),i=r[0].toLowerCase(),n=r[1],o=t;return o[i]=n,o}),{}),s={} ;if("hotp"===i){if(r=HOTP,void 0===o.counter||!INTEGER_REGEX.test(o.counter))throw new TypeError("Missing or invalid 'counter' parameter");s.counter=parseInt(o.counter,10)}else{if("totp"!==i)throw new TypeError("Unknown OTP type");if(r=TOTP,void 0!==o.period){if(!POSITIVE_INTEGER_REGEX.test(o.period))throw new TypeError("Invalid 'period' parameter");s.period=parseInt(o.period,10)}}if(2===n.length)if(s.label=n[1],void 0===o.issuer)s.issuer=n[0];else{if(o.issuer!==n[0])throw new TypeError("Invalid 'issuer' parameter");s.issuer=o.issuer}else s.label=n[0],void 0!==o.issuer&&(s.issuer=o.issuer);if(void 0===o.secret||!SECRET_REGEX.test(o.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(s.secret=new Secret({buffer:Utils.b32.toBuf(o.secret)}),void 0!==o.algorithm){if(!ALGORITHM_REGEX.test(o.algorithm))throw new TypeError("Invalid 'algorithm' parameter");s.algorithm=o.algorithm}if(void 0!==o.digits){if(!POSITIVE_INTEGER_REGEX.test(o.digits))throw new TypeError("Invalid 'digits' parameter") -;s.digits=parseInt(o.digits,10)}return new r(s)}},{key:"stringify",value:function(t){if(t instanceof HOTP||t instanceof TOTP)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}]),t}(),version="6.2.1";exports.HOTP=HOTP,exports.Secret=Secret,exports.TOTP=TOTP,exports.URI=URI,exports.Utils=Utils,exports.version=version; +;s.digits=parseInt(o.digits,10)}return new r(s)}},{key:"stringify",value:function(t){if(t instanceof HOTP||t instanceof TOTP)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}]),t}(),version="6.2.2";exports.HOTP=HOTP,exports.Secret=Secret,exports.TOTP=TOTP,exports.URI=URI,exports.Utils=Utils,exports.version=version; //# sourceMappingURL=otpauth.cjs.min.js.map diff --git a/dist/otpauth.esm.js b/dist/otpauth.esm.js index f4d84915..15af954a 100644 --- a/dist/otpauth.esm.js +++ b/dist/otpauth.esm.js @@ -1,5 +1,5 @@ -/*! otpauth v6.2.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ +/*! otpauth v6.2.2 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ /*! sjcl v1.0.8 | (c) bitwiseshiftleft | (BSD-2-Clause OR GPL-2.0-only) | https://github.com/bitwiseshiftleft/sjcl */ function _typeof(obj) { "@babel/helpers - typeof"; @@ -2676,6 +2676,6 @@ var URI = /*#__PURE__*/function () { * Library version. * @type {string} */ -var version = '6.2.1'; +var version = '6.2.2'; export { HOTP, Secret, TOTP, URI, Utils, version }; diff --git a/dist/otpauth.esm.min.js b/dist/otpauth.esm.min.js index e9f13a87..f9ed85b8 100644 --- a/dist/otpauth.esm.min.js +++ b/dist/otpauth.esm.min.js @@ -1,4 +1,4 @@ -/*! otpauth v6.2.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ +/*! otpauth v6.2.2 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ /*! sjcl v1.0.8 | (c) bitwiseshiftleft | (BSD-2-Clause OR GPL-2.0-only) | https://github.com/bitwiseshiftleft/sjcl */ function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,i=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){s=!0,o=t},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}var Utils={uint:{fromBuf:function(t){for(var e=new Uint8Array(t),r=0,i=0;i=0&&0!==i;n--)r[n]=255&i,i-=r[n],i/=256 @@ -26,5 +26,5 @@ algorithm:this.algorithm,digits:this.digits,counter:i})}},{key:"validate",value: ;return t.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:i})}},{key:"validate",value:function(e){var r=e.token,i=e.timestamp,n=e.window;return t.validate({token:r,secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:i,window:n})}},{key:"toString",value:function(){var t=encodeURIComponent;return"otpauth://totp/"+"".concat(this.issuer.length>0?"".concat(t(this.issuer),":").concat(t(this.label),"?issuer=").concat(t(this.issuer),"&"):"".concat(t(this.label),"?"))+"secret=".concat(t(this.secret.b32),"&")+"algorithm=".concat(t(this.algorithm),"&")+"digits=".concat(t(this.digits),"&")+"period=".concat(t(this.period))}}],[{key:"generate",value:function(t){var e=t.secret,r=t.algorithm,i=t.digits,n=t.period,o=void 0===n?defaults.period:n,a=t.timestamp,s=void 0===a?Date.now():a;return HOTP.generate({secret:e,algorithm:r,digits:i,counter:Math.floor(s/1e3/o)})}},{key:"validate",value:function(t){ var e=t.token,r=t.secret,i=t.algorithm,n=t.digits,o=t.period,a=void 0===o?defaults.period:o,s=t.timestamp,l=void 0===s?Date.now():s,h=t.window;return HOTP.validate({token:e,secret:r,algorithm:i,digits:n,counter:Math.floor(l/1e3/a),window:h})}}]),t}(),OTPURI_PARAMS=["issuer","secret","algorithm","digits","counter","period"],OTPURI_REGEX=new RegExp("^otpauth:\\/\\/([ht]otp)\\/(.+)\\?((?:&?(?:".concat(OTPURI_PARAMS.join("|"),")=[^&]+)+)$"),"i"),SECRET_REGEX=/^[2-7A-Z]+=*$/i,ALGORITHM_REGEX=/^SHA(?:1|256|512)$/i,INTEGER_REGEX=/^[+-]?\d+$/,POSITIVE_INTEGER_REGEX=/^\+?[1-9]\d*$/,URI=function(){function t(){_classCallCheck(this,t)}return _createClass(t,null,[{key:"parse",value:function(t){var e;try{e=t.match(OTPURI_REGEX)}catch(t){}if(!Array.isArray(e))throw new URIError("Invalid URI format");var r,i=e[1].toLowerCase(),n=e[2].split(/:(.+)/,2).map(decodeURIComponent),o=e[3].split("&").reduce((function(t,e){var r=e.split(/=(.+)/,2).map(decodeURIComponent),i=r[0].toLowerCase(),n=r[1],o=t;return o[i]=n,o}),{}),a={} ;if("hotp"===i){if(r=HOTP,void 0===o.counter||!INTEGER_REGEX.test(o.counter))throw new TypeError("Missing or invalid 'counter' parameter");a.counter=parseInt(o.counter,10)}else{if("totp"!==i)throw new TypeError("Unknown OTP type");if(r=TOTP,void 0!==o.period){if(!POSITIVE_INTEGER_REGEX.test(o.period))throw new TypeError("Invalid 'period' parameter");a.period=parseInt(o.period,10)}}if(2===n.length)if(a.label=n[1],void 0===o.issuer)a.issuer=n[0];else{if(o.issuer!==n[0])throw new TypeError("Invalid 'issuer' parameter");a.issuer=o.issuer}else a.label=n[0],void 0!==o.issuer&&(a.issuer=o.issuer);if(void 0===o.secret||!SECRET_REGEX.test(o.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(a.secret=new Secret({buffer:Utils.b32.toBuf(o.secret)}),void 0!==o.algorithm){if(!ALGORITHM_REGEX.test(o.algorithm))throw new TypeError("Invalid 'algorithm' parameter");a.algorithm=o.algorithm}if(void 0!==o.digits){if(!POSITIVE_INTEGER_REGEX.test(o.digits))throw new TypeError("Invalid 'digits' parameter") -;a.digits=parseInt(o.digits,10)}return new r(a)}},{key:"stringify",value:function(t){if(t instanceof HOTP||t instanceof TOTP)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}]),t}(),version="6.2.1";export{HOTP,Secret,TOTP,URI,Utils,version}; +;a.digits=parseInt(o.digits,10)}return new r(a)}},{key:"stringify",value:function(t){if(t instanceof HOTP||t instanceof TOTP)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}]),t}(),version="6.2.2";export{HOTP,Secret,TOTP,URI,Utils,version}; //# sourceMappingURL=otpauth.esm.min.js.map diff --git a/dist/otpauth.umd.js b/dist/otpauth.umd.js index ab7939e4..ffc95002 100644 --- a/dist/otpauth.umd.js +++ b/dist/otpauth.umd.js @@ -1,5 +1,5 @@ -/*! otpauth v6.2.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ +/*! otpauth v6.2.2 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ /*! sjcl v1.0.8 | (c) bitwiseshiftleft | (BSD-2-Clause OR GPL-2.0-only) | https://github.com/bitwiseshiftleft/sjcl */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : @@ -2682,7 +2682,7 @@ * Library version. * @type {string} */ - var version = '6.2.1'; + var version = '6.2.2'; exports.HOTP = HOTP; exports.Secret = Secret; diff --git a/dist/otpauth.umd.min.js b/dist/otpauth.umd.min.js index 610d6aed..b6aa2e54 100644 --- a/dist/otpauth.umd.min.js +++ b/dist/otpauth.umd.min.js @@ -1,4 +1,4 @@ -/*! otpauth v6.2.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ +/*! otpauth v6.2.2 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth */ /*! sjcl v1.0.8 | (c) bitwiseshiftleft | (BSD-2-Clause OR GPL-2.0-only) | https://github.com/bitwiseshiftleft/sjcl */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).OTPAuth={})}(this,(function(exports){"use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,i=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,a=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,o=t},f:function(){try{ @@ -26,5 +26,5 @@ algorithm:this.algorithm,digits:this.digits,counter:i})}},{key:"validate",value: ;return t.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:i})}},{key:"validate",value:function(e){var r=e.token,i=e.timestamp,n=e.window;return t.validate({token:r,secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:i,window:n})}},{key:"toString",value:function(){var t=encodeURIComponent;return"otpauth://totp/"+"".concat(this.issuer.length>0?"".concat(t(this.issuer),":").concat(t(this.label),"?issuer=").concat(t(this.issuer),"&"):"".concat(t(this.label),"?"))+"secret=".concat(t(this.secret.b32),"&")+"algorithm=".concat(t(this.algorithm),"&")+"digits=".concat(t(this.digits),"&")+"period=".concat(t(this.period))}}],[{key:"generate",value:function(t){var e=t.secret,r=t.algorithm,i=t.digits,n=t.period,o=void 0===n?defaults.period:n,s=t.timestamp,a=void 0===s?Date.now():s;return HOTP.generate({secret:e,algorithm:r,digits:i,counter:Math.floor(a/1e3/o)})}},{key:"validate",value:function(t){ var e=t.token,r=t.secret,i=t.algorithm,n=t.digits,o=t.period,s=void 0===o?defaults.period:o,a=t.timestamp,l=void 0===a?Date.now():a,h=t.window;return HOTP.validate({token:e,secret:r,algorithm:i,digits:n,counter:Math.floor(l/1e3/s),window:h})}}]),t}(),OTPURI_PARAMS=["issuer","secret","algorithm","digits","counter","period"],OTPURI_REGEX=new RegExp("^otpauth:\\/\\/([ht]otp)\\/(.+)\\?((?:&?(?:".concat(OTPURI_PARAMS.join("|"),")=[^&]+)+)$"),"i"),SECRET_REGEX=/^[2-7A-Z]+=*$/i,ALGORITHM_REGEX=/^SHA(?:1|256|512)$/i,INTEGER_REGEX=/^[+-]?\d+$/,POSITIVE_INTEGER_REGEX=/^\+?[1-9]\d*$/,URI=function(){function t(){_classCallCheck(this,t)}return _createClass(t,null,[{key:"parse",value:function(t){var e;try{e=t.match(OTPURI_REGEX)}catch(t){}if(!Array.isArray(e))throw new URIError("Invalid URI format");var r,i=e[1].toLowerCase(),n=e[2].split(/:(.+)/,2).map(decodeURIComponent),o=e[3].split("&").reduce((function(t,e){var r=e.split(/=(.+)/,2).map(decodeURIComponent),i=r[0].toLowerCase(),n=r[1],o=t;return o[i]=n,o}),{}),s={} ;if("hotp"===i){if(r=HOTP,void 0===o.counter||!INTEGER_REGEX.test(o.counter))throw new TypeError("Missing or invalid 'counter' parameter");s.counter=parseInt(o.counter,10)}else{if("totp"!==i)throw new TypeError("Unknown OTP type");if(r=TOTP,void 0!==o.period){if(!POSITIVE_INTEGER_REGEX.test(o.period))throw new TypeError("Invalid 'period' parameter");s.period=parseInt(o.period,10)}}if(2===n.length)if(s.label=n[1],void 0===o.issuer)s.issuer=n[0];else{if(o.issuer!==n[0])throw new TypeError("Invalid 'issuer' parameter");s.issuer=o.issuer}else s.label=n[0],void 0!==o.issuer&&(s.issuer=o.issuer);if(void 0===o.secret||!SECRET_REGEX.test(o.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(s.secret=new Secret({buffer:Utils.b32.toBuf(o.secret)}),void 0!==o.algorithm){if(!ALGORITHM_REGEX.test(o.algorithm))throw new TypeError("Invalid 'algorithm' parameter");s.algorithm=o.algorithm}if(void 0!==o.digits){if(!POSITIVE_INTEGER_REGEX.test(o.digits))throw new TypeError("Invalid 'digits' parameter") -;s.digits=parseInt(o.digits,10)}return new r(s)}},{key:"stringify",value:function(t){if(t instanceof HOTP||t instanceof TOTP)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}]),t}(),version="6.2.1";exports.HOTP=HOTP,exports.Secret=Secret,exports.TOTP=TOTP,exports.URI=URI,exports.Utils=Utils,exports.version=version,Object.defineProperty(exports,"__esModule",{value:!0})})); +;s.digits=parseInt(o.digits,10)}return new r(s)}},{key:"stringify",value:function(t){if(t instanceof HOTP||t instanceof TOTP)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}]),t}(),version="6.2.2";exports.HOTP=HOTP,exports.Secret=Secret,exports.TOTP=TOTP,exports.URI=URI,exports.Utils=Utils,exports.version=version,Object.defineProperty(exports,"__esModule",{value:!0})})); //# sourceMappingURL=otpauth.umd.min.js.map diff --git a/docs/index.html b/docs/index.html index 6dd42df1..a96a4e2d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,7 +2,7 @@ - otpauth 6.2.1 | Documentation + otpauth 6.2.2 | Documentation @@ -15,7 +15,7 @@

otpauth

-
6.2.1
+
6.2.2