!function(t,e){"object"==typeofexports&&"undefined"!=typeofmodule?e(exports):"function"==typeofdefine&&define.amd?define(["exports"],e):e((t="undefined"!=typeofglobalThis?globalThis:t||self).OTPAuth={})}(this,function(t){"use strict";functione(t){if(!Number.isSafeInteger(t)||t<0)thrownewError("positive integer expected, got "+t)}functions(t,...e){if(!((s=t)instanceofUint8Array||ArrayBuffer.isView(s)&&"Uint8Array"===s.constructor.name))thrownewError("Uint8Array expected");vars;if(e.length>0&&!e.includes(t.length))thrownewError("Uint8Array expected of length "+e+", got length="+t.length)}functioni(t,e=!0){if(t.destroyed)thrownewError("Hash instance has been destroyed");if(e&&t.finished)thrownewError("Hash#digest() has already been called")}functionr(t,e){s(t);consti=e.outputLen;if(t.length<i)thrownewError("digestInto() expects output buffer of length at least "+i)}functionn(...t){for(lete=0;e<t.length;e++)t[e].fill(0)}functiono(t){returnnewDataView(t.buffer,t.byteOffset,t.byteLength)}functionh(t,e){returnt<<32-e|t>>>e}functiona(t,e){returnt<<e|t>>>32-e>>>0}functionc(t){returnt<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}constl=(()=>68===newUint8Array(newUint32Array([287454020]).buffer)[0])()?t=>t:function(t){for(lete=0;e<t.length;e++)t[e]=c(t[e]);returnt};functionu(t){return"string"==typeoft&&(t=function(t){if("string"!=typeoft)thrownewError("string expected");returnnewUint8Array((newTextEncoder).encode(t))}(t)),s(t),t}classf{}functiond(t){conste=e=>t().update(u(e)).digest(),s=t();returne.outputLen=s.outputLen,e.blockLen=s.blockLen,e.create=()=>t(),e}classbextendsf{update(t){returni(this),this.iHash.update(t),this}digestInto(t){i(this),s(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){constt=newUint8Array(this.oHash.outputLen);returnthis.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}))
;const{oHash:e,iHash:s,finished:i,destroyed:r,blockLen:n,outputLen:o}=this;returnt.finished=i,t.destroyed=r,t.blockLen=n,t.outputLen=o,t.oHash=e._cloneInto(t.oHash),t.iHash=s._cloneInto(t.iHash),t}clone(){returnthis._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}constructor(t,s){super(),this.finished=!1,this.destroyed=!1,function(t){if("function"!=typeoft||"function"!=typeoft.create)thrownewError("Hash should be wrapped by utils.createHasher");e(t.outputLen),e(t.blockLen)}(t);consti=u(s);if(this.iHash=t.create(),"function"!=typeofthis.iHash.update)thrownewError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;constr=this.blockLen,o=newUint8Array(r);o.set(i.length>r?t.create().update(i).digest():i);for(lett=0;t<o.length;t++)o[t]^=54;this.iHash.update(o),this.oHash=t.create();for(lett=0;t<o.length;t++)o[t]^=106;this.oHash.update(o),n(o)}}constg=(t,e,s)=>newb(t,e).update(s).digest();functionp(t,e,s){returnt&e^~t&s}functionw(t,e,s){returnt&e^t&s^e&s}g.create=(t,e)=>newb(t,e);classyextendsf{update(t){i(this),s(t=u(t));const{view:e,buffer:r,blockLen:n}=this,h=t.length;for(lets=0;s<h;){consti=Math.min(n-this.pos,h-s);if(i===n){conste=o(t);for(;n<=h-s;s+=n)this.process(e,s);continue}r.set(t.subarray(s,s+i),this.pos),this.pos+=i,s+=i,this.pos===n&&(this.process(e,0),this.pos=0)}returnthis.length+=t.length,this.roundClean(),this}digestInto(t){i(this),r(t,this),this.finished=!0;const{buffer:e,view:s,blockLen:h,isLE:a}=this;let{pos:c}=this;e[c++]=128,n(this.buffer.subarray(c)),this.padOffset>h-c&&(this.process(s,0),c=0);for(lett=c;t<h;t++)e[t]=0;!function(t,e,s,i){if("function"==typeoft.setBigUint64)returnt.setBigUint64(e,s,i);constr=BigInt(32),n=BigInt(4294967295),o=Number(s>>r&n),h=Number(s&n),a=i?4:0,c=i?0:4;t.setUint32(e+a,o,i),t.setUint32(e+c,h,i)}(s,h-8,BigInt(8*this.length),a),this.process(s,0);constl=o(t),u=this.outputLen
;if(u%4)thrownewError("_sha2: outputLen should be aligned to 32bit");constf=u/4,d=this.get();if(f>d.length)thrownewError("_sha2: outputLen bigger than state");for(lett=0;t<f;t++)l.setUint32(4*t,d[t],a)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);consts=t.slice(0,e);returnthis.destroy(),s}_cloneInto(t){t||(t=newthis.constructor),t.set(...this.get());const{blockLen:e,buffer:s,length:i,finished:r,destroyed:n,pos:o}=this;returnt.destroyed=n,t.finished=r,t.length=i,t.pos=o,i%e&&t.buffer.set(s),t}clone(){returnthis._cloneInto()}constructor(t,e,s,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=s,this.isLE=i,this.buffer=newUint8Array(t),this.view=o(this.buffer)}}constx=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),m=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),A=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),H=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),I=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),L=newUint32Array(80);classEextendsy{get(){const{A:t,B:e,C:s,D:i,E:r}=this;return[t,e,s,i,r]}set(t,e,s,i,r){this.A=0|t,this.B=0|e,this.C=0|s,this.D=0|i,this.E=0|r}process(t,e){for(lets=0;s<16;s++,e+=4)L[s]=t.getUint32(e,!1);for(lett=16;t<80;t++)L[t]=a(L[t-3]^L[t-8]^L[t-14]^L[t-16],1);let{A:s,B:i,C:r,D:n,E:o}=this;for(lett=0;t<80;t++){lete,h;t<20?(e=p(i,r,n),h=1518500249):t<40?(e=i^r^n,h=1859775393):t<60?(e=w(i,r,n),h=2400959708):(e=i^r^n,h=3395469782);constc=a(s,5)+e+o+h+L[t]|0;o=n,n=r,r=a(i,30),i=s,s=c}s=s+this.A|0,i=i+this.B|0,r=r+this.C|0,n=n+this.D|0,o=o+this.E|0,
constet=d(()=>newZ),st=d(()=>newz),it=d(()=>newq),rt=d(()=>newtt),nt=BigInt(0),ot=BigInt(1),ht=BigInt(2),at=BigInt(7),ct=BigInt(256),lt=BigInt(113),ut=[],ft=[],dt=[];for(lett=0,e=ot,s=1,i=0;t<24;t++){[s,i]=[i,(2*s+3*i)%5],ut.push(2*(5*i+s)),ft.push((t+1)*(t+2)/2%64);letr=nt;for(lett=0;t<7;t++)e=(e<<ot^(e>>at)*lt)%ct,e&ht&&(r^=ot<<(ot<<BigInt(t))-ot);dt.push(r)}constbt=C(dt,!0),gt=bt[0],pt=bt[1],wt=(t,e,s)=>s>32?((t,e,s)=>e<<s-32|t>>>64-s)(t,e,s):((t,e,s)=>t<<s|e>>>32-s)(t,e,s),yt=(t,e,s)=>s>32?((t,e,s)=>t<<s-32|e>>>64-s)(t,e,s):((t,e,s)=>e<<s|t>>>32-s)(t,e,s);classxtextendsf{clone(){returnthis._cloneInto()}keccak(){l(this.state32),function(t,e=24){consts=newUint32Array(10);for(leti=24-e;i<24;i++){for(lete=0;e<10;e++)s[e]=t[e]^t[e+10]^t[e+20]^t[e+30]^t[e+40];for(lete=0;e<10;e+=2){consti=(e+8)%10,r=(e+2)%10,n=s[r],o=s[r+1],h=wt(n,o,1)^s[i],a=yt(n,o,1)^s[i+1];for(lets=0;s<50;s+=10)t[e+s]^=h,t[e+s+1]^=a}lete=t[2],r=t[3];for(lets=0;s<24;s++){consti=ft[s],n=wt(e,r,i),o=yt(e,r,i),h=ut[s];e=t[h],r=t[h+1],t[h]=n,t[h+1]=o}for(lete=0;e<50;e+=10){for(leti=0;i<10;i++)s[i]=t[e+i];for(leti=0;i<10;i++)t[e+i]^=~s[(i+2)%10]&s[(i+4)%10]}t[0]^=gt[i],t[1]^=pt[i]}n(s)}(this.state32,this.rounds),l(this.state32),this.posOut=0,this.pos=0}update(t){i(this),s(t=u(t));const{blockLen:e,state:r}=this,n=t.length;for(lets=0;s<n;){consti=Math.min(e-this.pos,n-s);for(lete=0;e<i;e++)r[this.pos++]^=t[s++];this.pos===e&&this.keccak()}returnthis}finish(){if(this.finished)return;this.finished=!0;const{state:t,suffix:e,pos:s,blockLen:i}=this;t[s]^=e,128&e&&s===i-1&&this.keccak(),t[i-1]^=128,this.keccak()}writeInto(t){i(this,!1),s(t),this.finish();conste=this.state,{blockLen:r}=this;for(lets=0,i=t.length;s<i;){this.posOut>=r&&this.keccak();constn=Math.min(r-this.posOut,i-s);t.set(e.subarray(this.posOut,this.posOut+n),s),this.posOut+=n,s+=n}returnt}xofInto(t){if(!this.enableXOF)thrownewError("XOF is not possible for this instance");returnthis.writeInto(t)}xof(t){returne(t),this.xofInto(newUint8Array(t))}
digestInto(t){if(r(t,this),this.finished)thrownewError("digest() was already called");returnthis.writeInto(t),this.destroy(),t}digest(){returnthis.digestInto(newUint8Array(this.outputLen))}destroy(){this.destroyed=!0,n(this.state)}_cloneInto(t){const{blockLen:e,suffix:s,outputLen:i,rounds:r,enableXOF:n}=this;returnt||(t=newxt(e,s,i,n,r)),t.state32.set(this.state32),t.pos=this.pos,t.posOut=this.posOut,t.finished=this.finished,t.rounds=r,t.suffix=s,t.outputLen=i,t.enableXOF=n,t.destroyed=this.destroyed,t}constructor(t,s,i,r=!1,n=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=t,this.suffix=s,this.outputLen=i,this.enableXOF=r,this.rounds=n,e(i),!(0<t&&t<200))thrownewError("only keccak-f1600 function is supported");varo;this.state=newUint8Array(200),this.state32=(o=this.state,newUint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}}constmt=(t,e,s)=>d(()=>newxt(e,t,s)),At=(()=>mt(6,144,28))(),Ht=(()=>mt(6,136,32))(),It=(()=>mt(6,104,48))(),Lt=(()=>mt(6,72,64))(),Et=(()=>{if("object"==typeofglobalThis)returnglobalThis;Object.defineProperty(Object.prototype,"__GLOBALTHIS__",{get(){returnthis},configurable:!0});try{if("undefined"!=typeof__GLOBALTHIS__)return__GLOBALTHIS__}finally{deleteObject.prototype.__GLOBALTHIS__}return"undefined"!=typeofself?self:"undefined"!=typeofwindow?window:"undefined"!=typeofglobal?global:void0})(),Ut={SHA1:U,SHA224:st,SHA256:et,SHA384:rt,SHA512:it,"SHA3-224":At,"SHA3-256":Ht,"SHA3-384":It,"SHA3-512":Lt},Bt=t=>{switch(!0){case/^(?:SHA-?1|SSL3-SHA1)$/i.test(t):return"SHA1";case/^SHA(?:2?-)?224$/i.test(t):return"SHA224";case/^SHA(?:2?-)?256$/i.test(t):return"SHA256";case/^SHA(?:2?-)?384$/i.test(t):return"SHA384";case/^SHA(?:2?-)?512$/i.test(t):return"SHA512";case/^SHA3-224$/i.test(t):return"SHA3-224";case/^SHA3-256$/i.test(t):return"SHA3-256";case/^SHA3-384$/i.test(t):return"SHA3-384";case/^SHA3-512$/i.test(t):return"SHA3-512";default:thrownewTypeError(`Unknown hash algorithm: ${t}`)}
},St="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",Ot=t=>{lete=(t=t.replace(/ /g,"")).length;for(;"="===t[e-1];)--e;t=(e<t.length?t.substring(0,e):t).toUpperCase();consts=newArrayBuffer(5*t.length/8|0),i=newUint8Array(s);letr=0,n=0,o=0;for(lete=0;e<t.length;e++){consts=St.indexOf(t[e]);if(-1===s)thrownewTypeError(`Invalid character found: ${t[e]}`);n=n<<5|s,r+=5,r>=8&&(r-=8,i[o++]=n>>>r)}returni},Ct=t=>{lete=0,s=0,i="";for(letr=0;r<t.length;r++)for(s=s<<8|t[r],e+=8;e>=5;)i+=St[s>>>e-5&31],e-=5;returne>0&&(i+=St[s<<5-e&31]),i},vt=t=>{t=t.replace(/ /g,"");conste=newArrayBuffer(t.length/2),s=newUint8Array(e);for(lete=0;e<t.length;e+=2)s[e/2]=parseInt(t.substring(e,e+2),16);returns},kt=t=>{lete="";for(lets=0;s<t.length;s++){consti=t[s].toString(16);1===i.length&&(e+="0"),e+=i}returne.toUpperCase()},$t=t=>{conste=newArrayBuffer(t.length),s=newUint8Array(e);for(lete=0;e<t.length;e++)s[e]=255&t.charCodeAt(e);returns},Tt=t=>{lete="";for(lets=0;s<t.length;s++)e+=String.fromCharCode(t[s]);returne},Dt=Et.TextEncoder?newEt.TextEncoder:null,_t=Et.TextDecoder?newEt.TextDecoder:null,Ft=t=>{if(!Dt)thrownewError("Encoding API not available");returnDt.encode(t)},Gt=t=>{if(!_t)thrownewError("Encoding API not available");return_t.decode(t)};classPt{staticfromLatin1(t){returnnewPt({buffer:$t(t).buffer})}staticfromUTF8(t){returnnewPt({buffer:Ft(t).buffer})}staticfromBase32(t){returnnewPt({buffer:Ot(t).buffer})}staticfromHex(t){returnnewPt({buffer:vt(t).buffer})}getbuffer(){returnthis.bytes.buffer}getlatin1(){returnObject.defineProperty(this,"latin1",{enumerable:!0,writable:!1,configurable:!1,value:Tt(this.bytes)}),this.latin1}getutf8(){returnObject.defineProperty(this,"utf8",{enumerable:!0,writable:!1,configurable:!1,value:Gt(this.bytes)}),this.utf8}getbase32(){returnObject.defineProperty(this,"base32",{enumerable:!0,writable:!1,configurable:!1,value:Ct(this.bytes)}),this.base32}gethex(){returnObject.defineProperty(this,"hex",{enumerable:!0,writable:!1,configurable:!1,
value:kt(this.bytes)}),this.hex}constructor({buffer:t,size:e=20}={}){this.bytes=void0===t?(t=>{if(Et.crypto?.getRandomValues)returnEt.crypto.getRandomValues(newUint8Array(t));thrownewError("Cryptography API not available")})(e):newUint8Array(t),Object.defineProperty(this,"bytes",{enumerable:!0,writable:!1,configurable:!1,value:this.bytes})}}classjt{staticgetdefaults(){return{issuer:"",label:"OTPAuth",issuerInLabel:!0,algorithm:"SHA1",digits:6,counter:0,window:1}}staticgenerate({secret:t,algorithm:e=jt.defaults.algorithm,digits:s=jt.defaults.digits,counter:i=jt.defaults.counter}){constr=((t,e,s)=>{if(g){consti=Ut[t]??Ut[Bt(t)];returng(i,e,s)}thrownewError("Missing HMAC function")})(e,t.bytes,(t=>{conste=newArrayBuffer(8),s=newUint8Array(e);leti=t;for(lett=7;t>=0&&0!==i;t--)s[t]=255&i,i-=s[t],i/=256;returns})(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++}={}){returnjt.generate({secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:t})}staticvalidate({token:t,secret:e,algorithm:s,digits:i=jt.defaults.digits,counter:r=jt.defaults.counter,window:n=jt.defaults.window}){if(t.length!==i)returnnull;leto=null;consth=n=>{consth=jt.generate({secret:e,algorithm:s,digits:i,counter:n});((t,e)=>{{if(t.length!==e.length)thrownewTypeError("Input strings must have the same length");lets=-1,i=0;for(;++s<t.length;)i|=t.charCodeAt(s)^e.charCodeAt(s);return0===i}})(t,h)&&(o=n-r)};h(r);for(lett=1;t<=n&&null===o&&(h(r-t),null===o)&&(h(r+t),null===o);++t);returno}validate({token:t,counter:e=this.counter,window:s}){returnjt.validate({token:t,secret:this.secret,algorithm:this.algorithm,digits:this.digits,counter:e,window:s})}toString(){constt=encodeURIComponent