From a53054fc7b54b285f598c9dd632caabaa8c21b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Molinero=20Fern=C3=A1ndez?= Date: Mon, 3 Jun 2024 22:46:05 +0200 Subject: [PATCH] 9.3.1 --- dist/otpauth.esm.js | 4 ++-- dist/otpauth.esm.min.js | 4 ++-- dist/otpauth.node.cjs | 4 ++-- dist/otpauth.node.min.cjs | 4 ++-- dist/otpauth.node.min.mjs | 4 ++-- dist/otpauth.node.mjs | 4 ++-- dist/otpauth.slim.esm.js | 4 ++-- dist/otpauth.slim.esm.min.js | 4 ++-- dist/otpauth.umd.js | 4 ++-- dist/otpauth.umd.min.js | 4 ++-- docs/classes/HOTP.html | 30 +++++++++++++++--------------- docs/classes/Secret.html | 24 ++++++++++++------------ docs/classes/TOTP.html | 30 +++++++++++++++--------------- docs/classes/URI.html | 6 +++--- docs/variables/version.html | 2 +- jsr.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 18 files changed, 70 insertions(+), 70 deletions(-) diff --git a/dist/otpauth.esm.js b/dist/otpauth.esm.js index 7505b3a..fdc79cf 100644 --- a/dist/otpauth.esm.js +++ b/dist/otpauth.esm.js @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes /// // @ts-nocheck @@ -1861,6 +1861,6 @@ const sha3_512 = /* @__PURE__ */ gen(0x06, 72, 512 / 8); /** * Library version. * @type {string} - */ const version = "9.3.0"; + */ const version = "9.3.1"; export { HOTP, Secret, TOTP, URI, version }; diff --git a/dist/otpauth.esm.min.js b/dist/otpauth.esm.min.js index 5016575..66a2e1b 100644 --- a/dist/otpauth.esm.min.js +++ b/dist/otpauth.esm.min.js @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes /// // @ts-nocheck @@ -14,5 +14,5 @@ if(!this.enableXOF)throw new Error("XOF is not possible for this instance");retu },bt=t=>{let e=0,s=0,i="";for(let r=0;r=5;)i+=ft[s>>>e-5&31],e-=5;return e>0&&(i+=ft[s<<5-e&31]),i},gt=t=>{const e=new ArrayBuffer(t.length/2),s=new Uint8Array(e);for(let e=0;e{let e="";for(let s=0;s{const e=new ArrayBuffer(t.length),s=new Uint8Array(e);for(let e=0;e{let e="";for(let s=0;s{if(!xt)throw new Error("Encoding API not available");return xt.encode(t)},mt=t=>{if(!Lt)throw new Error("Encoding API not available");return Lt.decode(t)};class Ht{static fromLatin1(t){return new Ht({buffer:wt(t).buffer})}static fromUTF8(t){return new Ht({buffer:At(t).buffer})}static fromBase32(t){return new Ht({buffer:ut(t).buffer})}static fromHex(t){return new Ht({buffer:gt(t).buffer})}get buffer(){return this.bytes.buffer}get latin1(){return Object.defineProperty(this,"latin1",{enumerable:!0,writable:!1,configurable:!1,value:yt(this.bytes)}),this.latin1}get utf8(){return Object.defineProperty(this,"utf8",{enumerable:!0,writable:!1,configurable:!1,value:mt(this.bytes)}),this.utf8}get base32(){return Object.defineProperty(this,"base32",{enumerable:!0,writable:!1,configurable:!1,value:bt(this.bytes)}),this.base32}get hex(){return Object.defineProperty(this,"hex",{enumerable:!0,writable:!1,configurable:!1,value:pt(this.bytes)}),this.hex}constructor({buffer:t,size:e=20}={}){this.bytes=void 0===t?(t=>{if(!ct.crypto?.getRandomValues)throw new Error("Cryptography API not available");return ct.crypto.getRandomValues(new Uint8Array(t))})(e):new Uint8Array(t),Object.defineProperty(this,"bytes",{enumerable:!0,writable:!1,configurable:!1,value:this.bytes})}}class It{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0, algorithm:"SHA1",digits:6,counter:0,window:1}}static generate({secret:t,algorithm:e=It.defaults.algorithm,digits:s=It.defaults.digits,counter:i=It.defaults.counter}){const r=((t,e,s)=>{if(u){const i=dt[t.toUpperCase()];if(!i)throw new TypeError("Unknown hash function");return u(i,e,s)}throw new Error("Missing HMAC function")})(e,t.bytes,(t=>{const e=new ArrayBuffer(8),s=new Uint8Array(e);let i=t;for(let t=7;t>=0&&0!==i;t--)s[t]=255&i,i-=s[t],i/=256;return s})(i)),n=15&r[r.byteLength-1];return(((127&r[n])<<24|(255&r[n+1])<<16|(255&r[n+2])<<8|255&r[n+3])%10**s).toString().padStart(s,"0")}generate({counter:t=this.counter++}={}){return It.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:t})}static validate({token:t,secret:e,algorithm:s,digits:i,counter:r=It.defaults.counter,window:n=It.defaults.window}){if(t.length!==i)return null;let o=null;const h=n=>{const h=It.generate({secret:e,algorithm:s,digits:i,counter:n});((t,e)=>{{if(t.length!==e.length)throw new TypeError("Input strings must have the same length");let s=-1,i=0;for(;++s0?this.issuerInLabel?`${t(this.issuer)}:${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?`)+`secret=${t(this.secret.base32)}&`+`algorithm=${t(this.algorithm)}&`+`digits=${t(this.digits)}&`+`counter=${t(this.counter)}`}constructor({issuer:t=It.defaults.issuer,label:e=It.defaults.label,issuerInLabel:s=It.defaults.issuerInLabel,secret:i=new Ht,algorithm:r=It.defaults.algorithm,digits:n=It.defaults.digits,counter:o=It.defaults.counter}={}){this.issuer=t,this.label=e,this.issuerInLabel=s, this.secret="string"==typeof i?Ht.fromBase32(i):i,this.algorithm=r.toUpperCase(),this.digits=n,this.counter=o}}class Bt{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,period:30,window:1}}static generate({secret:t,algorithm:e,digits:s,period:i=Bt.defaults.period,timestamp:r=Date.now()}){return It.generate({secret:t,algorithm:e,digits:s,counter:Math.floor(r/1e3/i)})}generate({timestamp:t=Date.now()}={}){return Bt.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:t})}static validate({token:t,secret:e,algorithm:s,digits:i,period:r=Bt.defaults.period,timestamp:n=Date.now(),window:o}){return It.validate({token:t,secret:e,algorithm:s,digits:i,counter:Math.floor(n/1e3/r),window:o})}validate({token:t,timestamp:e,window:s}){return Bt.validate({token:t,secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:e,window:s})}toString(){const t=encodeURIComponent;return"otpauth://totp/"+(this.issuer.length>0?this.issuerInLabel?`${t(this.issuer)}:${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?`)+`secret=${t(this.secret.base32)}&`+`algorithm=${t(this.algorithm)}&`+`digits=${t(this.digits)}&`+`period=${t(this.period)}`}constructor({issuer:t=Bt.defaults.issuer,label:e=Bt.defaults.label,issuerInLabel:s=Bt.defaults.issuerInLabel,secret:i=new Ht,algorithm:r=Bt.defaults.algorithm,digits:n=Bt.defaults.digits,period:o=Bt.defaults.period}={}){this.issuer=t,this.label=e,this.issuerInLabel=s,this.secret="string"==typeof i?Ht.fromBase32(i):i,this.algorithm=r.toUpperCase(),this.digits=n,this.period=o}}const Et=/^otpauth:\/\/([ht]otp)\/(.+)\?([A-Z0-9.~_-]+=[^?&]*(?:&[A-Z0-9.~_-]+=[^?&]*)*)$/i,Ut=/^[2-7A-Z]+=*$/i,St=/^SHA(?:1|224|256|384|512|3-224|3-256|3-384|3-512)$/i,Ct=/^[+-]?\d+$/,vt=/^\+?[1-9]\d*$/;class kt{static parse(t){let e;try{e=t.match(Et)}catch(t){}if(!Array.isArray(e))throw new URIError("Invalid URI format") -;const s=e[1].toLowerCase(),i=e[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),r=e[3].split("&").reduce(((t,e)=>{const s=e.split(/=(.*)/,2).map(decodeURIComponent),i=s[0].toLowerCase(),r=s[1],n=t;return n[i]=r,n}),{});let n;const o={};if("hotp"===s){if(n=It,void 0===r.counter||!Ct.test(r.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(r.counter,10)}else{if("totp"!==s)throw new TypeError("Unknown OTP type");if(n=Bt,void 0!==r.period){if(!vt.test(r.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(r.period,10)}}if(void 0!==r.issuer&&(o.issuer=r.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===r.secret||!Ut.test(r.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(o.secret=r.secret,void 0!==r.algorithm){if(!St.test(r.algorithm))throw new TypeError("Invalid 'algorithm' parameter");o.algorithm=r.algorithm}if(void 0!==r.digits){if(!vt.test(r.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(r.digits,10)}return new n(o)}static stringify(t){if(t instanceof It||t instanceof Bt)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}const Ot="9.3.0";export{It as HOTP,Ht as Secret,Bt as TOTP,kt as URI,Ot as version}; +;const s=e[1].toLowerCase(),i=e[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),r=e[3].split("&").reduce(((t,e)=>{const s=e.split(/=(.*)/,2).map(decodeURIComponent),i=s[0].toLowerCase(),r=s[1],n=t;return n[i]=r,n}),{});let n;const o={};if("hotp"===s){if(n=It,void 0===r.counter||!Ct.test(r.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(r.counter,10)}else{if("totp"!==s)throw new TypeError("Unknown OTP type");if(n=Bt,void 0!==r.period){if(!vt.test(r.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(r.period,10)}}if(void 0!==r.issuer&&(o.issuer=r.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===r.secret||!Ut.test(r.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(o.secret=r.secret,void 0!==r.algorithm){if(!St.test(r.algorithm))throw new TypeError("Invalid 'algorithm' parameter");o.algorithm=r.algorithm}if(void 0!==r.digits){if(!vt.test(r.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(r.digits,10)}return new n(o)}static stringify(t){if(t instanceof It||t instanceof Bt)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}const Ot="9.3.1";export{It as HOTP,Ht as Secret,Bt as TOTP,kt as URI,Ot as version}; //# sourceMappingURL=otpauth.esm.min.js.map diff --git a/dist/otpauth.node.cjs b/dist/otpauth.node.cjs index 7d11d41..9ebcd80 100644 --- a/dist/otpauth.node.cjs +++ b/dist/otpauth.node.cjs @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth /// // @ts-nocheck 'use strict'; @@ -799,7 +799,7 @@ var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto); /** * Library version. * @type {string} - */ const version = "9.3.0"; + */ const version = "9.3.1"; exports.HOTP = HOTP; exports.Secret = Secret; diff --git a/dist/otpauth.node.min.cjs b/dist/otpauth.node.min.cjs index 401b0ca..927b9d6 100644 --- a/dist/otpauth.node.min.cjs +++ b/dist/otpauth.node.min.cjs @@ -1,9 +1,9 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth /// // @ts-nocheck "use strict";function e(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var i=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var t=e(require("node:crypto"));const r=(()=>{if("object"==typeof globalThis)return globalThis;Object.defineProperty(Object.prototype,"__GLOBALTHIS__",{get(){return this},configurable:!0});try{if("undefined"!=typeof __GLOBALTHIS__)return __GLOBALTHIS__}finally{delete Object.prototype.__GLOBALTHIS__}return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0})(),i="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",s=e=>{let t=e.length;for(;"="===e[t-1];)--t;const r=(t=8&&(o-=8,n[l++]=a>>>o)}return n},n=e=>{let t=0,r=0,s="";for(let n=0;n=5;)s+=i[r>>>t-5&31],t-=5;return t>0&&(s+=i[r<<5-t&31]),s},o=e=>{const t=new ArrayBuffer(e.length/2),r=new Uint8Array(t);for(let t=0;t{let t="";for(let r=0;r{const t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let t=0;t{let t="";for(let r=0;r{if(!h)throw new Error("Encoding API not available");return h.encode(e)},c=e=>{if(!d)throw new Error("Encoding API not available");return d.decode(e)};class g{static fromLatin1(e){return new g({buffer:l(e).buffer})}static fromUTF8(e){return new g({buffer:f(e).buffer})}static fromBase32(e){return new g({ buffer:s(e).buffer})}static fromHex(e){return new g({buffer:o(e).buffer})}get buffer(){return this.bytes.buffer}get latin1(){return Object.defineProperty(this,"latin1",{enumerable:!0,writable:!1,configurable:!1,value:u(this.bytes)}),this.latin1}get utf8(){return Object.defineProperty(this,"utf8",{enumerable:!0,writable:!1,configurable:!1,value:c(this.bytes)}),this.utf8}get base32(){return Object.defineProperty(this,"base32",{enumerable:!0,writable:!1,configurable:!1,value:n(this.bytes)}),this.base32}get hex(){return Object.defineProperty(this,"hex",{enumerable:!0,writable:!1,configurable:!1,value:a(this.bytes)}),this.hex}constructor({buffer:e,size:i=20}={}){this.bytes=void 0===e?(e=>{if(t?.randomBytes)return t.randomBytes(e);if(!r.crypto?.getRandomValues)throw new Error("Cryptography API not available");return r.crypto.getRandomValues(new Uint8Array(e))})(i):new Uint8Array(e),Object.defineProperty(this,"bytes",{enumerable:!0,writable:!1,configurable:!1,value:this.bytes})}}class p{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,counter:0,window:1}}static generate({secret:e,algorithm:i=p.defaults.algorithm,digits:s=p.defaults.digits,counter:n=p.defaults.counter}){const o=((e,i,s)=>{if(t?.createHmac){const n=t.createHmac(e,r.Buffer.from(i));return n.update(r.Buffer.from(s)),n.digest()}throw new Error("Missing HMAC function")})(i,e.bytes,(e=>{const t=new ArrayBuffer(8),r=new Uint8Array(t);let i=e;for(let e=7;e>=0&&0!==i;e--)r[e]=255&i,i-=r[e],i/=256;return r})(n)),a=15&o[o.byteLength-1];return(((127&o[a])<<24|(255&o[a+1])<<16|(255&o[a+2])<<8|255&o[a+3])%10**s).toString().padStart(s,"0")}generate({counter:e=this.counter++}={}){return p.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:e})}static validate({token:e,secret:i,algorithm:s,digits:n,counter:o=p.defaults.counter,window:a=p.defaults.window}){if(e.length!==n)return null;let l=null;const u=a=>{const u=p.generate({secret:i,algorithm:s,digits:n,counter:a});((e,i)=>{ if(t?.timingSafeEqual)return t.timingSafeEqual(r.Buffer.from(e),r.Buffer.from(i));{if(e.length!==i.length)throw new TypeError("Input strings must have the same length");let t=-1,r=0;for(;++t0?this.issuerInLabel?`${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?`)+`secret=${e(this.secret.base32)}&`+`algorithm=${e(this.algorithm)}&`+`digits=${e(this.digits)}&`+`counter=${e(this.counter)}`}constructor({issuer:e=p.defaults.issuer,label:t=p.defaults.label,issuerInLabel:r=p.defaults.issuerInLabel,secret:i=new g,algorithm:s=p.defaults.algorithm,digits:n=p.defaults.digits,counter:o=p.defaults.counter}={}){this.issuer=e,this.label=t,this.issuerInLabel=r,this.secret="string"==typeof i?g.fromBase32(i):i,this.algorithm=s.toUpperCase(),this.digits=n,this.counter=o}}class b{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,period:30,window:1}}static generate({secret:e,algorithm:t,digits:r,period:i=b.defaults.period,timestamp:s=Date.now()}){return p.generate({secret:e,algorithm:t,digits:r,counter:Math.floor(s/1e3/i)})}generate({timestamp:e=Date.now()}={}){return b.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:e})}static validate({token:e,secret:t,algorithm:r,digits:i,period:s=b.defaults.period,timestamp:n=Date.now(),window:o}){return p.validate({token:e,secret:t,algorithm:r,digits:i,counter:Math.floor(n/1e3/s),window:o})}validate({token:e,timestamp:t,window:r}){return b.validate({token:e,secret:this.secret,algorithm:this.algorithm,digits:this.digits, period:this.period,timestamp:t,window:r})}toString(){const e=encodeURIComponent;return"otpauth://totp/"+(this.issuer.length>0?this.issuerInLabel?`${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?`)+`secret=${e(this.secret.base32)}&`+`algorithm=${e(this.algorithm)}&`+`digits=${e(this.digits)}&`+`period=${e(this.period)}`}constructor({issuer:e=b.defaults.issuer,label:t=b.defaults.label,issuerInLabel:r=b.defaults.issuerInLabel,secret:i=new g,algorithm:s=b.defaults.algorithm,digits:n=b.defaults.digits,period:o=b.defaults.period}={}){this.issuer=e,this.label=t,this.issuerInLabel=r,this.secret="string"==typeof i?g.fromBase32(i):i,this.algorithm=s.toUpperCase(),this.digits=n,this.period=o}}const m=/^otpauth:\/\/([ht]otp)\/(.+)\?([A-Z0-9.~_-]+=[^?&]*(?:&[A-Z0-9.~_-]+=[^?&]*)*)$/i,w=/^[2-7A-Z]+=*$/i,y=/^SHA(?:1|224|256|384|512|3-224|3-256|3-384|3-512)$/i,v=/^[+-]?\d+$/,I=/^\+?[1-9]\d*$/;exports.HOTP=p,exports.Secret=g,exports.TOTP=b,exports.URI=class{static parse(e){let t;try{t=e.match(m)}catch(e){}if(!Array.isArray(t))throw new URIError("Invalid URI format");const r=t[1].toLowerCase(),i=t[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),s=t[3].split("&").reduce(((e,t)=>{const r=t.split(/=(.*)/,2).map(decodeURIComponent),i=r[0].toLowerCase(),s=r[1],n=e;return n[i]=s,n}),{});let n;const o={};if("hotp"===r){if(n=p,void 0===s.counter||!v.test(s.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(s.counter,10)}else{if("totp"!==r)throw new TypeError("Unknown OTP type");if(n=b,void 0!==s.period){if(!I.test(s.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(s.period,10)}}if(void 0!==s.issuer&&(o.issuer=s.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===s.secret||!w.test(s.secret))throw new TypeError("Missing or invalid 'secret' parameter") -;if(o.secret=s.secret,void 0!==s.algorithm){if(!y.test(s.algorithm))throw new TypeError("Invalid 'algorithm' parameter");o.algorithm=s.algorithm}if(void 0!==s.digits){if(!I.test(s.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(s.digits,10)}return new n(o)}static stringify(e){if(e instanceof p||e instanceof b)return e.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}},exports.version="9.3.0"; +;if(o.secret=s.secret,void 0!==s.algorithm){if(!y.test(s.algorithm))throw new TypeError("Invalid 'algorithm' parameter");o.algorithm=s.algorithm}if(void 0!==s.digits){if(!I.test(s.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(s.digits,10)}return new n(o)}static stringify(e){if(e instanceof p||e instanceof b)return e.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}},exports.version="9.3.1"; //# sourceMappingURL=otpauth.node.min.cjs.map diff --git a/dist/otpauth.node.min.mjs b/dist/otpauth.node.min.mjs index f09ef20..323bf26 100644 --- a/dist/otpauth.node.min.mjs +++ b/dist/otpauth.node.min.mjs @@ -1,9 +1,9 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth /// // @ts-nocheck import*as e from"node:crypto";const t=(()=>{if("object"==typeof globalThis)return globalThis;Object.defineProperty(Object.prototype,"__GLOBALTHIS__",{get(){return this},configurable:!0});try{if("undefined"!=typeof __GLOBALTHIS__)return __GLOBALTHIS__}finally{delete Object.prototype.__GLOBALTHIS__}return"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:void 0})(),r="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",i=e=>{let t=e.length;for(;"="===e[t-1];)--t;const i=(t=8&&(o-=8,n[l++]=a>>>o)}return n},s=e=>{let t=0,i=0,s="";for(let n=0;n=5;)s+=r[i>>>t-5&31],t-=5;return t>0&&(s+=r[i<<5-t&31]),s},n=e=>{const t=new ArrayBuffer(e.length/2),r=new Uint8Array(t);for(let t=0;t{let t="";for(let r=0;r{const t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let t=0;t{let t="";for(let r=0;r{if(!u)throw new Error("Encoding API not available");return u.encode(e)},f=e=>{if(!h)throw new Error("Encoding API not available");return h.decode(e)};class c{static fromLatin1(e){return new c({buffer:a(e).buffer})}static fromUTF8(e){return new c({buffer:d(e).buffer})}static fromBase32(e){return new c({buffer:i(e).buffer})}static fromHex(e){return new c({buffer:n(e).buffer})}get buffer(){return this.bytes.buffer}get latin1(){return Object.defineProperty(this,"latin1",{enumerable:!0,writable:!1,configurable:!1,value:l(this.bytes)}),this.latin1}get utf8(){ return Object.defineProperty(this,"utf8",{enumerable:!0,writable:!1,configurable:!1,value:f(this.bytes)}),this.utf8}get base32(){return Object.defineProperty(this,"base32",{enumerable:!0,writable:!1,configurable:!1,value:s(this.bytes)}),this.base32}get hex(){return Object.defineProperty(this,"hex",{enumerable:!0,writable:!1,configurable:!1,value:o(this.bytes)}),this.hex}constructor({buffer:r,size:i=20}={}){this.bytes=void 0===r?(r=>{if(e?.randomBytes)return e.randomBytes(r);if(!t.crypto?.getRandomValues)throw new Error("Cryptography API not available");return t.crypto.getRandomValues(new Uint8Array(r))})(i):new Uint8Array(r),Object.defineProperty(this,"bytes",{enumerable:!0,writable:!1,configurable:!1,value:this.bytes})}}class g{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,counter:0,window:1}}static generate({secret:r,algorithm:i=g.defaults.algorithm,digits:s=g.defaults.digits,counter:n=g.defaults.counter}){const o=((r,i,s)=>{if(e?.createHmac){const n=e.createHmac(r,t.Buffer.from(i));return n.update(t.Buffer.from(s)),n.digest()}throw new Error("Missing HMAC function")})(i,r.bytes,(e=>{const t=new ArrayBuffer(8),r=new Uint8Array(t);let i=e;for(let e=7;e>=0&&0!==i;e--)r[e]=255&i,i-=r[e],i/=256;return r})(n)),a=15&o[o.byteLength-1];return(((127&o[a])<<24|(255&o[a+1])<<16|(255&o[a+2])<<8|255&o[a+3])%10**s).toString().padStart(s,"0")}generate({counter:e=this.counter++}={}){return g.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:e})}static validate({token:r,secret:i,algorithm:s,digits:n,counter:o=g.defaults.counter,window:a=g.defaults.window}){if(r.length!==n)return null;let l=null;const u=a=>{const u=g.generate({secret:i,algorithm:s,digits:n,counter:a});((r,i)=>{if(e?.timingSafeEqual)return e.timingSafeEqual(t.Buffer.from(r),t.Buffer.from(i));{if(r.length!==i.length)throw new TypeError("Input strings must have the same length");let e=-1,t=0;for(;++e0?this.issuerInLabel?`${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?`)+`secret=${e(this.secret.base32)}&`+`algorithm=${e(this.algorithm)}&`+`digits=${e(this.digits)}&`+`counter=${e(this.counter)}`}constructor({issuer:e=g.defaults.issuer,label:t=g.defaults.label,issuerInLabel:r=g.defaults.issuerInLabel,secret:i=new c,algorithm:s=g.defaults.algorithm,digits:n=g.defaults.digits,counter:o=g.defaults.counter}={}){this.issuer=e,this.label=t,this.issuerInLabel=r,this.secret="string"==typeof i?c.fromBase32(i):i,this.algorithm=s.toUpperCase(),this.digits=n,this.counter=o}}class p{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,period:30,window:1}}static generate({secret:e,algorithm:t,digits:r,period:i=p.defaults.period,timestamp:s=Date.now()}){return g.generate({secret:e,algorithm:t,digits:r,counter:Math.floor(s/1e3/i)})}generate({timestamp:e=Date.now()}={}){return p.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:e})}static validate({token:e,secret:t,algorithm:r,digits:i,period:s=p.defaults.period,timestamp:n=Date.now(),window:o}){return g.validate({token:e,secret:t,algorithm:r,digits:i,counter:Math.floor(n/1e3/s),window:o})}validate({token:e,timestamp:t,window:r}){return p.validate({token:e,secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:t,window:r})}toString(){const e=encodeURIComponent ;return"otpauth://totp/"+(this.issuer.length>0?this.issuerInLabel?`${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?`)+`secret=${e(this.secret.base32)}&`+`algorithm=${e(this.algorithm)}&`+`digits=${e(this.digits)}&`+`period=${e(this.period)}`}constructor({issuer:e=p.defaults.issuer,label:t=p.defaults.label,issuerInLabel:r=p.defaults.issuerInLabel,secret:i=new c,algorithm:s=p.defaults.algorithm,digits:n=p.defaults.digits,period:o=p.defaults.period}={}){this.issuer=e,this.label=t,this.issuerInLabel=r,this.secret="string"==typeof i?c.fromBase32(i):i,this.algorithm=s.toUpperCase(),this.digits=n,this.period=o}}const b=/^otpauth:\/\/([ht]otp)\/(.+)\?([A-Z0-9.~_-]+=[^?&]*(?:&[A-Z0-9.~_-]+=[^?&]*)*)$/i,m=/^[2-7A-Z]+=*$/i,w=/^SHA(?:1|224|256|384|512|3-224|3-256|3-384|3-512)$/i,y=/^[+-]?\d+$/,I=/^\+?[1-9]\d*$/;class v{static parse(e){let t;try{t=e.match(b)}catch(e){}if(!Array.isArray(t))throw new URIError("Invalid URI format");const r=t[1].toLowerCase(),i=t[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),s=t[3].split("&").reduce(((e,t)=>{const r=t.split(/=(.*)/,2).map(decodeURIComponent),i=r[0].toLowerCase(),s=r[1],n=e;return n[i]=s,n}),{});let n;const o={};if("hotp"===r){if(n=g,void 0===s.counter||!y.test(s.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(s.counter,10)}else{if("totp"!==r)throw new TypeError("Unknown OTP type");if(n=p,void 0!==s.period){if(!I.test(s.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(s.period,10)}}if(void 0!==s.issuer&&(o.issuer=s.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===s.secret||!m.test(s.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(o.secret=s.secret,void 0!==s.algorithm){if(!w.test(s.algorithm))throw new TypeError("Invalid 'algorithm' parameter") -;o.algorithm=s.algorithm}if(void 0!==s.digits){if(!I.test(s.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(s.digits,10)}return new n(o)}static stringify(e){if(e instanceof g||e instanceof p)return e.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}const A="9.3.0";export{g as HOTP,c as Secret,p as TOTP,v as URI,A as version}; +;o.algorithm=s.algorithm}if(void 0!==s.digits){if(!I.test(s.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(s.digits,10)}return new n(o)}static stringify(e){if(e instanceof g||e instanceof p)return e.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}const A="9.3.1";export{g as HOTP,c as Secret,p as TOTP,v as URI,A as version}; //# sourceMappingURL=otpauth.node.min.mjs.map diff --git a/dist/otpauth.node.mjs b/dist/otpauth.node.mjs index 7f3073e..ca8bb3f 100644 --- a/dist/otpauth.node.mjs +++ b/dist/otpauth.node.mjs @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth /// // @ts-nocheck import * as crypto from 'node:crypto'; @@ -778,6 +778,6 @@ import * as crypto from 'node:crypto'; /** * Library version. * @type {string} - */ const version = "9.3.0"; + */ const version = "9.3.1"; export { HOTP, Secret, TOTP, URI, version }; diff --git a/dist/otpauth.slim.esm.js b/dist/otpauth.slim.esm.js index fbec23d..995d8f6 100644 --- a/dist/otpauth.slim.esm.js +++ b/dist/otpauth.slim.esm.js @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes /// // @ts-nocheck @@ -792,6 +792,6 @@ import { sha3_224, sha3_256, sha3_384, sha3_512 } from '@noble/hashes/sha3'; /** * Library version. * @type {string} - */ const version = "9.3.0"; + */ const version = "9.3.1"; export { HOTP, Secret, TOTP, URI, version }; diff --git a/dist/otpauth.slim.esm.min.js b/dist/otpauth.slim.esm.min.js index fbc4e3c..e9dfc1c 100644 --- a/dist/otpauth.slim.esm.min.js +++ b/dist/otpauth.slim.esm.min.js @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes /// // @ts-nocheck @@ -6,5 +6,5 @@ import{hmac as e}from"@noble/hashes/hmac";import{sha1 as t}from"@noble/hashes/sh buffer:I(e).buffer})}static fromBase32(e){return new T({buffer:f(e).buffer})}static fromHex(e){return new T({buffer:p(e).buffer})}get buffer(){return this.bytes.buffer}get latin1(){return Object.defineProperty(this,"latin1",{enumerable:!0,writable:!1,configurable:!1,value:m(this.bytes)}),this.latin1}get utf8(){return Object.defineProperty(this,"utf8",{enumerable:!0,writable:!1,configurable:!1,value:v(this.bytes)}),this.utf8}get base32(){return Object.defineProperty(this,"base32",{enumerable:!0,writable:!1,configurable:!1,value:g(this.bytes)}),this.base32}get hex(){return Object.defineProperty(this,"hex",{enumerable:!0,writable:!1,configurable:!1,value:b(this.bytes)}),this.hex}constructor({buffer:e,size:t=20}={}){this.bytes=void 0===e?(e=>{if(!h.crypto?.getRandomValues)throw new Error("Cryptography API not available");return h.crypto.getRandomValues(new Uint8Array(e))})(t):new Uint8Array(e),Object.defineProperty(this,"bytes",{enumerable:!0,writable:!1,configurable:!1,value:this.bytes})}}class ${static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,counter:0,window:1}}static generate({secret:t,algorithm:r=$.defaults.algorithm,digits:i=$.defaults.digits,counter:s=$.defaults.counter}){const n=((t,r,i)=>{if(e){const s=d[t.toUpperCase()];if(!s)throw new TypeError("Unknown hash function");return e(s,r,i)}throw new Error("Missing HMAC function")})(r,t.bytes,(e=>{const t=new ArrayBuffer(8),r=new Uint8Array(t);let i=e;for(let e=7;e>=0&&0!==i;e--)r[e]=255&i,i-=r[e],i/=256;return r})(s)),o=15&n[n.byteLength-1];return(((127&n[o])<<24|(255&n[o+1])<<16|(255&n[o+2])<<8|255&n[o+3])%10**i).toString().padStart(i,"0")}generate({counter:e=this.counter++}={}){return $.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:e})}static validate({token:e,secret:t,algorithm:r,digits:i,counter:s=$.defaults.counter,window:n=$.defaults.window}){if(e.length!==i)return null;let o=null;const a=n=>{const a=$.generate({secret:t,algorithm:r,digits:i,counter:n});((e,t)=>{{ if(e.length!==t.length)throw new TypeError("Input strings must have the same length");let r=-1,i=0;for(;++r0?this.issuerInLabel?`${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?`)+`secret=${e(this.secret.base32)}&`+`algorithm=${e(this.algorithm)}&`+`digits=${e(this.digits)}&`+`counter=${e(this.counter)}`}constructor({issuer:e=$.defaults.issuer,label:t=$.defaults.label,issuerInLabel:r=$.defaults.issuerInLabel,secret:i=new T,algorithm:s=$.defaults.algorithm,digits:n=$.defaults.digits,counter:o=$.defaults.counter}={}){this.issuer=e,this.label=t,this.issuerInLabel=r,this.secret="string"==typeof i?T.fromBase32(i):i,this.algorithm=s.toUpperCase(),this.digits=n,this.counter=o}}class L{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,period:30,window:1}}static generate({secret:e,algorithm:t,digits:r,period:i=L.defaults.period,timestamp:s=Date.now()}){return $.generate({secret:e,algorithm:t,digits:r,counter:Math.floor(s/1e3/i)})}generate({timestamp:e=Date.now()}={}){return L.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:e})}static validate({token:e,secret:t,algorithm:r,digits:i,period:s=L.defaults.period,timestamp:n=Date.now(),window:o}){return $.validate({token:e,secret:t,algorithm:r,digits:i,counter:Math.floor(n/1e3/s),window:o})}validate({token:e,timestamp:t,window:r}){return L.validate({token:e,secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:t,window:r})}toString(){const e=encodeURIComponent ;return"otpauth://totp/"+(this.issuer.length>0?this.issuerInLabel?`${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?issuer=${e(this.issuer)}&`:`${e(this.label)}?`)+`secret=${e(this.secret.base32)}&`+`algorithm=${e(this.algorithm)}&`+`digits=${e(this.digits)}&`+`period=${e(this.period)}`}constructor({issuer:e=L.defaults.issuer,label:t=L.defaults.label,issuerInLabel:r=L.defaults.issuerInLabel,secret:i=new T,algorithm:s=L.defaults.algorithm,digits:n=L.defaults.digits,period:o=L.defaults.period}={}){this.issuer=e,this.label=t,this.issuerInLabel=r,this.secret="string"==typeof i?T.fromBase32(i):i,this.algorithm=s.toUpperCase(),this.digits=n,this.period=o}}const S=/^otpauth:\/\/([ht]otp)\/(.+)\?([A-Z0-9.~_-]+=[^?&]*(?:&[A-Z0-9.~_-]+=[^?&]*)*)$/i,U=/^[2-7A-Z]+=*$/i,E=/^SHA(?:1|224|256|384|512|3-224|3-256|3-384|3-512)$/i,H=/^[+-]?\d+$/,C=/^\+?[1-9]\d*$/;class O{static parse(e){let t;try{t=e.match(S)}catch(e){}if(!Array.isArray(t))throw new URIError("Invalid URI format");const r=t[1].toLowerCase(),i=t[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),s=t[3].split("&").reduce(((e,t)=>{const r=t.split(/=(.*)/,2).map(decodeURIComponent),i=r[0].toLowerCase(),s=r[1],n=e;return n[i]=s,n}),{});let n;const o={};if("hotp"===r){if(n=$,void 0===s.counter||!H.test(s.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(s.counter,10)}else{if("totp"!==r)throw new TypeError("Unknown OTP type");if(n=L,void 0!==s.period){if(!C.test(s.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(s.period,10)}}if(void 0!==s.issuer&&(o.issuer=s.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===s.secret||!U.test(s.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(o.secret=s.secret,void 0!==s.algorithm){if(!E.test(s.algorithm))throw new TypeError("Invalid 'algorithm' parameter") -;o.algorithm=s.algorithm}if(void 0!==s.digits){if(!C.test(s.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(s.digits,10)}return new n(o)}static stringify(e){if(e instanceof $||e instanceof L)return e.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}const _="9.3.0";export{$ as HOTP,T as Secret,L as TOTP,O as URI,_ as version}; +;o.algorithm=s.algorithm}if(void 0!==s.digits){if(!C.test(s.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(s.digits,10)}return new n(o)}static stringify(e){if(e instanceof $||e instanceof L)return e.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}}const _="9.3.1";export{$ as HOTP,T as Secret,L as TOTP,O as URI,_ as version}; //# sourceMappingURL=otpauth.slim.esm.min.js.map diff --git a/dist/otpauth.umd.js b/dist/otpauth.umd.js index 9876c7a..dd0af8d 100644 --- a/dist/otpauth.umd.js +++ b/dist/otpauth.umd.js @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes /// // @ts-nocheck @@ -1867,7 +1867,7 @@ /** * Library version. * @type {string} - */ const version = "9.3.0"; + */ const version = "9.3.1"; exports.HOTP = HOTP; exports.Secret = Secret; diff --git a/dist/otpauth.umd.min.js b/dist/otpauth.umd.min.js index f4566b3..0955037 100644 --- a/dist/otpauth.umd.min.js +++ b/dist/otpauth.umd.min.js @@ -1,4 +1,4 @@ -//! otpauth 9.3.0 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth +//! otpauth 9.3.1 | (c) Héctor Molinero Fernández | MIT | https://github.com/hectorm/otpauth //! noble-hashes 1.4.0 | (c) Paul Miller | MIT | https://github.com/paulmillr/noble-hashes /// // @ts-nocheck @@ -14,5 +14,5 @@ if(!this.enableXOF)throw new Error("XOF is not possible for this instance");retu },gt=t=>{let e=0,s=0,i="";for(let r=0;r=5;)i+=ut[s>>>e-5&31],e-=5;return e>0&&(i+=ut[s<<5-e&31]),i},pt=t=>{const e=new ArrayBuffer(t.length/2),s=new Uint8Array(e);for(let e=0;e{let e="";for(let s=0;s{const e=new ArrayBuffer(t.length),s=new Uint8Array(e);for(let e=0;e{let e="";for(let s=0;s{if(!Lt)throw new Error("Encoding API not available");return Lt.encode(t)},Ht=t=>{if(!At)throw new Error("Encoding API not available");return At.decode(t)};class It{static fromLatin1(t){return new It({buffer:yt(t).buffer})}static fromUTF8(t){return new It({buffer:mt(t).buffer})}static fromBase32(t){return new It({buffer:bt(t).buffer})}static fromHex(t){return new It({buffer:pt(t).buffer})}get buffer(){return this.bytes.buffer}get latin1(){return Object.defineProperty(this,"latin1",{enumerable:!0,writable:!1,configurable:!1,value:xt(this.bytes)}),this.latin1}get utf8(){return Object.defineProperty(this,"utf8",{enumerable:!0,writable:!1,configurable:!1,value:Ht(this.bytes)}),this.utf8}get base32(){return Object.defineProperty(this,"base32",{enumerable:!0,writable:!1,configurable:!1,value:gt(this.bytes)}),this.base32}get hex(){return Object.defineProperty(this,"hex",{enumerable:!0,writable:!1,configurable:!1,value:wt(this.bytes)}),this.hex}constructor({buffer:t,size:e=20}={}){this.bytes=void 0===t?(t=>{if(!dt.crypto?.getRandomValues)throw new Error("Cryptography API not available");return dt.crypto.getRandomValues(new Uint8Array(t))})(e):new Uint8Array(t),Object.defineProperty(this,"bytes",{enumerable:!0,writable:!1,configurable:!1,value:this.bytes})}}class Bt{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0, algorithm:"SHA1",digits:6,counter:0,window:1}}static generate({secret:t,algorithm:e=Bt.defaults.algorithm,digits:s=Bt.defaults.digits,counter:i=Bt.defaults.counter}){const r=((t,e,s)=>{if(b){const i=ft[t.toUpperCase()];if(!i)throw new TypeError("Unknown hash function");return b(i,e,s)}throw new Error("Missing HMAC function")})(e,t.bytes,(t=>{const e=new ArrayBuffer(8),s=new Uint8Array(e);let i=t;for(let t=7;t>=0&&0!==i;t--)s[t]=255&i,i-=s[t],i/=256;return s})(i)),n=15&r[r.byteLength-1];return(((127&r[n])<<24|(255&r[n+1])<<16|(255&r[n+2])<<8|255&r[n+3])%10**s).toString().padStart(s,"0")}generate({counter:t=this.counter++}={}){return Bt.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:t})}static validate({token:t,secret:e,algorithm:s,digits:i,counter:r=Bt.defaults.counter,window:n=Bt.defaults.window}){if(t.length!==i)return null;let o=null;const h=n=>{const h=Bt.generate({secret:e,algorithm:s,digits:i,counter:n});((t,e)=>{{if(t.length!==e.length)throw new TypeError("Input strings must have the same length");let s=-1,i=0;for(;++s0?this.issuerInLabel?`${t(this.issuer)}:${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?`)+`secret=${t(this.secret.base32)}&`+`algorithm=${t(this.algorithm)}&`+`digits=${t(this.digits)}&`+`counter=${t(this.counter)}`}constructor({issuer:t=Bt.defaults.issuer,label:e=Bt.defaults.label,issuerInLabel:s=Bt.defaults.issuerInLabel,secret:i=new It,algorithm:r=Bt.defaults.algorithm,digits:n=Bt.defaults.digits,counter:o=Bt.defaults.counter}={}){this.issuer=t,this.label=e,this.issuerInLabel=s, this.secret="string"==typeof i?It.fromBase32(i):i,this.algorithm=r.toUpperCase(),this.digits=n,this.counter=o}}class Et{static get defaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,period:30,window:1}}static generate({secret:t,algorithm:e,digits:s,period:i=Et.defaults.period,timestamp:r=Date.now()}){return Bt.generate({secret:t,algorithm:e,digits:s,counter:Math.floor(r/1e3/i)})}generate({timestamp:t=Date.now()}={}){return Et.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:t})}static validate({token:t,secret:e,algorithm:s,digits:i,period:r=Et.defaults.period,timestamp:n=Date.now(),window:o}){return Bt.validate({token:t,secret:e,algorithm:s,digits:i,counter:Math.floor(n/1e3/r),window:o})}validate({token:t,timestamp:e,window:s}){return Et.validate({token:t,secret:this.secret,algorithm:this.algorithm,digits:this.digits,period:this.period,timestamp:e,window:s})}toString(){const t=encodeURIComponent;return"otpauth://totp/"+(this.issuer.length>0?this.issuerInLabel?`${t(this.issuer)}:${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?issuer=${t(this.issuer)}&`:`${t(this.label)}?`)+`secret=${t(this.secret.base32)}&`+`algorithm=${t(this.algorithm)}&`+`digits=${t(this.digits)}&`+`period=${t(this.period)}`}constructor({issuer:t=Et.defaults.issuer,label:e=Et.defaults.label,issuerInLabel:s=Et.defaults.issuerInLabel,secret:i=new It,algorithm:r=Et.defaults.algorithm,digits:n=Et.defaults.digits,period:o=Et.defaults.period}={}){this.issuer=t,this.label=e,this.issuerInLabel=s,this.secret="string"==typeof i?It.fromBase32(i):i,this.algorithm=r.toUpperCase(),this.digits=n,this.period=o}}const Ut=/^otpauth:\/\/([ht]otp)\/(.+)\?([A-Z0-9.~_-]+=[^?&]*(?:&[A-Z0-9.~_-]+=[^?&]*)*)$/i,St=/^[2-7A-Z]+=*$/i,Ct=/^SHA(?:1|224|256|384|512|3-224|3-256|3-384|3-512)$/i,Ot=/^[+-]?\d+$/,vt=/^\+?[1-9]\d*$/;t.HOTP=Bt,t.Secret=It,t.TOTP=Et,t.URI=class{static parse(t){let e;try{e=t.match(Ut)}catch(t){} -if(!Array.isArray(e))throw new URIError("Invalid URI format");const s=e[1].toLowerCase(),i=e[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),r=e[3].split("&").reduce(((t,e)=>{const s=e.split(/=(.*)/,2).map(decodeURIComponent),i=s[0].toLowerCase(),r=s[1],n=t;return n[i]=r,n}),{});let n;const o={};if("hotp"===s){if(n=Bt,void 0===r.counter||!Ot.test(r.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(r.counter,10)}else{if("totp"!==s)throw new TypeError("Unknown OTP type");if(n=Et,void 0!==r.period){if(!vt.test(r.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(r.period,10)}}if(void 0!==r.issuer&&(o.issuer=r.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===r.secret||!St.test(r.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(o.secret=r.secret,void 0!==r.algorithm){if(!Ct.test(r.algorithm))throw new TypeError("Invalid 'algorithm' parameter");o.algorithm=r.algorithm}if(void 0!==r.digits){if(!vt.test(r.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(r.digits,10)}return new n(o)}static stringify(t){if(t instanceof Bt||t instanceof Et)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}},t.version="9.3.0"})); +if(!Array.isArray(e))throw new URIError("Invalid URI format");const s=e[1].toLowerCase(),i=e[2].split(/(?::|%3A) *(.+)/i,2).map(decodeURIComponent),r=e[3].split("&").reduce(((t,e)=>{const s=e.split(/=(.*)/,2).map(decodeURIComponent),i=s[0].toLowerCase(),r=s[1],n=t;return n[i]=r,n}),{});let n;const o={};if("hotp"===s){if(n=Bt,void 0===r.counter||!Ot.test(r.counter))throw new TypeError("Missing or invalid 'counter' parameter");o.counter=parseInt(r.counter,10)}else{if("totp"!==s)throw new TypeError("Unknown OTP type");if(n=Et,void 0!==r.period){if(!vt.test(r.period))throw new TypeError("Invalid 'period' parameter");o.period=parseInt(r.period,10)}}if(void 0!==r.issuer&&(o.issuer=r.issuer),2===i.length?(o.label=i[1],void 0===o.issuer||""===o.issuer?o.issuer=i[0]:""===i[0]&&(o.issuerInLabel=!1)):(o.label=i[0],void 0!==o.issuer&&""!==o.issuer&&(o.issuerInLabel=!1)),void 0===r.secret||!St.test(r.secret))throw new TypeError("Missing or invalid 'secret' parameter");if(o.secret=r.secret,void 0!==r.algorithm){if(!Ct.test(r.algorithm))throw new TypeError("Invalid 'algorithm' parameter");o.algorithm=r.algorithm}if(void 0!==r.digits){if(!vt.test(r.digits))throw new TypeError("Invalid 'digits' parameter");o.digits=parseInt(r.digits,10)}return new n(o)}static stringify(t){if(t instanceof Bt||t instanceof Et)return t.toString();throw new TypeError("Invalid 'HOTP/TOTP' object")}},t.version="9.3.1"})); //# sourceMappingURL=otpauth.umd.min.js.map diff --git a/docs/classes/HOTP.html b/docs/classes/HOTP.html index 595aed0..88710fa 100644 --- a/docs/classes/HOTP.html +++ b/docs/classes/HOTP.html @@ -1,6 +1,6 @@ HOTP | otpauth

Class HOTP

HOTP: An HMAC-based One-time Password Algorithm.

Constructors

Constructors

Properties

algorithm counter digits @@ -23,34 +23,34 @@
  • issuerInLabel: undefined | boolean

    Include issuer prefix in label.

  • label: undefined | string

    Account label.

  • secret: undefined | string | Secret

    Secret key.

    -
  • Returns HOTP

    Properties

    algorithm: string

    HMAC hashing algorithm.

    -
    counter: number

    Initial counter value.

    -
    digits: number

    Token length.

    -
    issuer: string

    Account provider.

    -
    issuerInLabel: boolean

    Include issuer prefix in label.

    -
    label: string

    Account label.

    -
    secret: Secret

    Secret key.

    -

    Accessors

    • get defaults(): {
          algorithm: string;
          counter: number;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          window: number;
      }
    • Default configuration.

      -

      Returns {
          algorithm: string;
          counter: number;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          window: number;
      }

      • algorithm: string
      • counter: number
      • digits: number
      • issuer: string
      • issuerInLabel: boolean
      • label: string
      • window: number

    Methods

    • Generates an HOTP token.

      +

    Returns HOTP

    Properties

    algorithm: string

    HMAC hashing algorithm.

    +
    counter: number

    Initial counter value.

    +
    digits: number

    Token length.

    +
    issuer: string

    Account provider.

    +
    issuerInLabel: boolean

    Include issuer prefix in label.

    +
    label: string

    Account label.

    +
    secret: Secret

    Secret key.

    +

    Accessors

    • get defaults(): {
          algorithm: string;
          counter: number;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          window: number;
      }
    • Default configuration.

      +

      Returns {
          algorithm: string;
          counter: number;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          window: number;
      }

      • algorithm: string
      • counter: number
      • digits: number
      • issuer: string
      • issuerInLabel: boolean
      • label: string
      • window: number

    Methods

    • Generates an HOTP token.

      Parameters

      • Optional config: {
            counter: undefined | number;
        } = {}

        Configuration options.

        • counter: undefined | number

          Counter value.

      Returns string

      Token.

      -
    • Returns a Google Authenticator key URI.

      +
    • Returns a Google Authenticator key URI.

      Returns string

      URI.

      -
    • Validates an HOTP token.

      +
    • Validates an HOTP token.

      Parameters

      • config: {
            counter: undefined | number;
            token: string;
            window: undefined | number;
        }

        Configuration options.

        • counter: undefined | number

          Counter value.

        • token: string

          Token value.

        • window: undefined | number

          Window of counter values to test.

      Returns null | number

      Token delta or null if it is not found in the search window, in which case it should be considered invalid.

      -
    • Generates an HOTP token.

      +
    • Generates an HOTP token.

      Parameters

      • config: {
            algorithm: undefined | string;
            counter: undefined | number;
            digits: undefined | number;
            secret: Secret;
        }

        Configuration options.

        • algorithm: undefined | string

          HMAC hashing algorithm.

        • counter: undefined | number

          Counter value.

        • digits: undefined | number

          Token length.

        • secret: Secret

          Secret key.

      Returns string

      Token.

      -
    • Validates an HOTP token.

      +
    • Validates an HOTP token.

      Parameters

      • config: {
            algorithm: undefined | string;
            counter: undefined | number;
            digits: number;
            secret: Secret;
            token: string;
            window: undefined | number;
        }

        Configuration options.

        • algorithm: undefined | string

          HMAC hashing algorithm.

        • counter: undefined | number

          Counter value.

          @@ -59,4 +59,4 @@
        • token: string

          Token value.

        • window: undefined | number

          Window of counter values to test.

      Returns null | number

      Token delta or null if it is not found in the search window, in which case it should be considered invalid.

      -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/classes/Secret.html b/docs/classes/Secret.html index 01f2478..fc5553b 100644 --- a/docs/classes/Secret.html +++ b/docs/classes/Secret.html @@ -1,5 +1,5 @@ Secret | otpauth

    Class Secret

    OTP secret key.

    -

    Constructors

    Constructors

    Properties

    Accessors

    base32 buffer @@ -14,23 +14,23 @@

    Parameters

    • Optional config: {
          buffer: undefined | ArrayBufferLike;
          size: undefined | number;
      } = {}

      Configuration options.

      • buffer: undefined | ArrayBufferLike

        Secret key buffer.

      • size: undefined | number

        Number of random bytes to generate, ignored if 'buffer' is provided.

        -

    Returns Secret

    Properties

    bytes: Uint8Array

    Secret key.

    -

    Accessors

    • get base32(): string
    • Base32 string representation of secret key.

      -

      Returns string

    • get buffer(): ArrayBufferLike
    • Secret key buffer.

      +

    Returns Secret

    Properties

    bytes: Uint8Array

    Secret key.

    +

    Accessors

    • get base32(): string
    • Base32 string representation of secret key.

      +

      Returns string

    • get buffer(): ArrayBufferLike
    • Secret key buffer.

      Returns ArrayBufferLike

      Deprecated

      For backward compatibility, the "bytes" property should be used instead.

      -
    • get hex(): string
    • Hexadecimal string representation of secret key.

      -

      Returns string

    • get latin1(): string
    • Latin-1 string representation of secret key.

      -

      Returns string

    • get utf8(): string
    • UTF-8 string representation of secret key.

      -

      Returns string

    Methods

    • Converts a base32 string to a Secret object.

      +
    • get hex(): string
    • Hexadecimal string representation of secret key.

      +

      Returns string

    • get latin1(): string
    • Latin-1 string representation of secret key.

      +

      Returns string

    • get utf8(): string
    • UTF-8 string representation of secret key.

      +

      Returns string

    Methods

    • Converts a base32 string to a Secret object.

      Parameters

      • str: string

        Base32 string.

      Returns Secret

      Secret object.

      -
    • Converts a hexadecimal string to a Secret object.

      +
    • Converts a hexadecimal string to a Secret object.

      Parameters

      • str: string

        Hexadecimal string.

      Returns Secret

      Secret object.

      -
    • Converts a Latin-1 string to a Secret object.

      +
    • Converts a Latin-1 string to a Secret object.

      Parameters

      • str: string

        Latin-1 string.

      Returns Secret

      Secret object.

      -
    • Converts an UTF-8 string to a Secret object.

      +
    • Converts an UTF-8 string to a Secret object.

      Parameters

      • str: string

        UTF-8 string.

      Returns Secret

      Secret object.

      -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/classes/TOTP.html b/docs/classes/TOTP.html index e401dd7..e988c35 100644 --- a/docs/classes/TOTP.html +++ b/docs/classes/TOTP.html @@ -1,6 +1,6 @@ TOTP | otpauth

    Class TOTP

    TOTP: Time-Based One-Time Password Algorithm.

    Constructors

    Constructors

    Properties

    algorithm digits issuer @@ -23,27 +23,27 @@
  • label: undefined | string

    Account label.

  • period: undefined | number

    Token time-step duration.

  • secret: undefined | string | Secret

    Secret key.

    -
  • Returns TOTP

    Properties

    algorithm: string

    HMAC hashing algorithm.

    -
    digits: number

    Token length.

    -
    issuer: string

    Account provider.

    -
    issuerInLabel: boolean

    Include issuer prefix in label.

    -
    label: string

    Account label.

    -
    period: number

    Token time-step duration.

    -
    secret: Secret

    Secret key.

    -

    Accessors

    • get defaults(): {
          algorithm: string;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          period: number;
          window: number;
      }
    • Default configuration.

      -

      Returns {
          algorithm: string;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          period: number;
          window: number;
      }

      • algorithm: string
      • digits: number
      • issuer: string
      • issuerInLabel: boolean
      • label: string
      • period: number
      • window: number

    Methods

    • Generates a TOTP token.

      +

    Returns TOTP

    Properties

    algorithm: string

    HMAC hashing algorithm.

    +
    digits: number

    Token length.

    +
    issuer: string

    Account provider.

    +
    issuerInLabel: boolean

    Include issuer prefix in label.

    +
    label: string

    Account label.

    +
    period: number

    Token time-step duration.

    +
    secret: Secret

    Secret key.

    +

    Accessors

    • get defaults(): {
          algorithm: string;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          period: number;
          window: number;
      }
    • Default configuration.

      +

      Returns {
          algorithm: string;
          digits: number;
          issuer: string;
          issuerInLabel: boolean;
          label: string;
          period: number;
          window: number;
      }

      • algorithm: string
      • digits: number
      • issuer: string
      • issuerInLabel: boolean
      • label: string
      • period: number
      • window: number

    Methods

    • Generates a TOTP token.

      Parameters

      • Optional config: {
            timestamp: undefined | number;
        } = {}

        Configuration options.

        • timestamp: undefined | number

          Timestamp value in milliseconds.

      Returns string

      Token.

      -
    • Returns a Google Authenticator key URI.

      +
    • Returns a Google Authenticator key URI.

      Returns string

      URI.

      -
    • Validates a TOTP token.

      +
    • Validates a TOTP token.

      Parameters

      • config: {
            timestamp: undefined | number;
            token: string;
            window: undefined | number;
        }

        Configuration options.

        • timestamp: undefined | number

          Timestamp value in milliseconds.

        • token: string

          Token value.

        • window: undefined | number

          Window of counter values to test.

      Returns null | number

      Token delta or null if it is not found in the search window, in which case it should be considered invalid.

      -
    • Generates a TOTP token.

      +
    • Generates a TOTP token.

      Parameters

      • config: {
            algorithm: undefined | string;
            digits: undefined | number;
            period: undefined | number;
            secret: Secret;
            timestamp: undefined | number;
        }

        Configuration options.

        • algorithm: undefined | string

          HMAC hashing algorithm.

        • digits: undefined | number

          Token length.

          @@ -51,7 +51,7 @@
        • secret: Secret

          Secret key.

        • timestamp: undefined | number

          Timestamp value in milliseconds.

      Returns string

      Token.

      -
    • Validates a TOTP token.

      +
    • Validates a TOTP token.

      Parameters

      • config: {
            algorithm: undefined | string;
            digits: number;
            period: undefined | number;
            secret: Secret;
            timestamp: undefined | number;
            token: string;
            window: undefined | number;
        }

        Configuration options.

        • algorithm: undefined | string

          HMAC hashing algorithm.

        • digits: number

          Token length.

          @@ -61,4 +61,4 @@
        • token: string

          Token value.

        • window: undefined | number

          Window of counter values to test.

      Returns null | number

      Token delta or null if it is not found in the search window, in which case it should be considered invalid.

      -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/classes/URI.html b/docs/classes/URI.html index 879cdcf..b98bf08 100644 --- a/docs/classes/URI.html +++ b/docs/classes/URI.html @@ -1,12 +1,12 @@ URI | otpauth

    Class URI

    HOTP/TOTP object/string conversion.

    Constructors

    Constructors

    Methods

    Constructors

    Methods

    • Parses a Google Authenticator key URI and returns an HOTP/TOTP object.

      Parameters

      • uri: string

        Google Authenticator Key URI.

      Returns HOTP | TOTP

      HOTP/TOTP object.

      -
    • Converts an HOTP/TOTP object to a Google Authenticator key URI.

      +
    • Converts an HOTP/TOTP object to a Google Authenticator key URI.

      Parameters

      Returns string

      Google Authenticator Key URI.

      -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/docs/variables/version.html b/docs/variables/version.html index 361ed27..de52de2 100644 --- a/docs/variables/version.html +++ b/docs/variables/version.html @@ -1,2 +1,2 @@ version | otpauth

    Variable versionConst

    version: string = "__OTPAUTH_VERSION__"

    Library version.

    -
    \ No newline at end of file +
    \ No newline at end of file diff --git a/jsr.json b/jsr.json index 810fc30..3a24d21 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@hectorm/otpauth", - "version": "9.3.0", + "version": "9.3.1", "exports": { ".": "./dist/otpauth.esm.js" }, diff --git a/package-lock.json b/package-lock.json index 89e19a2..ff3812c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "otpauth", - "version": "9.3.0", + "version": "9.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "otpauth", - "version": "9.3.0", + "version": "9.3.1", "license": "MIT", "dependencies": { "@noble/hashes": "1.4.0" diff --git a/package.json b/package.json index 08eb295..7a91fa2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "otpauth", - "version": "9.3.0", + "version": "9.3.1", "description": "One Time Password (HOTP/TOTP) library for Node.js, Deno, Bun and browsers", "keywords": [ "otp",