UNPKG

otplib

Version:

TypeScript-first library for TOTP and HOTP with multi-runtime and plugin support

4 lines • 37 kB
"use strict";var otplib=(function(e){Object.defineProperty(e,"__esModule",{value:!0});var t=class extends Error{constructor(e,t){super(e,t),this.name=`OTPError`}},n=class extends t{constructor(e){super(e),this.name=`SecretError`}},r=class extends n{constructor(e,t){super(`Secret must be at least ${e} bytes (${e*8} bits), got ${t} bytes`),this.name=`SecretTooShortError`}},i=class extends n{constructor(e,t){super(`Secret must not exceed ${e} bytes, got ${t} bytes`),this.name=`SecretTooLongError`}},a=class extends t{constructor(e){super(e),this.name=`CounterError`}},o=class extends a{constructor(){super(`Counter must be non-negative`),this.name=`CounterNegativeError`}},s=class extends a{constructor(){super(`Counter exceeds maximum safe integer value`),this.name=`CounterOverflowError`}},c=class extends a{constructor(){super(`Counter must be a finite integer`),this.name=`CounterNotIntegerError`}},l=class extends t{constructor(e){super(e),this.name=`TimeError`}},u=class extends l{constructor(){super(`Time must be non-negative`),this.name=`TimeNegativeError`}},d=class extends l{constructor(){super(`Time must be a finite number`),this.name=`TimeNotFiniteError`}},f=class extends t{constructor(e){super(e),this.name=`PeriodError`}},p=class extends f{constructor(e){super(`Period must be at least ${e} second(s)`),this.name=`PeriodTooSmallError`}},m=class extends f{constructor(e){super(`Period must not exceed ${e} seconds`),this.name=`PeriodTooLargeError`}},h=class extends t{constructor(e){super(e),this.name=`AlgorithmError`}},g=class extends h{constructor(e,t={}){let{supported:n,plugin:r}=t;super(`Unsupported hash algorithm.`+(n?` Expected one of: ${n.join(`, `)||`(none)`}`:``)+(r?` [plugin: ${r}]`:``)),this.name=`AlgorithmUnsupportedError`}},_=class extends t{constructor(e){super(e),this.name=`TokenError`}},v=class extends _{constructor(e,t){super(`Token must be ${e} digits, got ${t}`),this.name=`TokenLengthError`}},ee=class extends _{constructor(){super(`Token must contain only digits`),this.name=`TokenFormatError`}},y=class extends t{constructor(e,t){super(e,t),this.name=`CryptoError`}},b=class extends y{constructor(e,t){super(`HMAC computation failed: ${e}`,t),this.name=`HMACError`}},te=class extends y{constructor(e,t){super(`Random byte generation failed: ${e}`,t),this.name=`RandomBytesError`}},x=class extends t{constructor(e){super(e),this.name=`CounterToleranceError`}},ne=class extends x{constructor(e,t){super(`Counter tolerance validation failed: total checks (${t}) exceeds MAX_WINDOW (${e})`),this.name=`CounterToleranceTooLargeError`}},re=class extends x{constructor(){super(`Counter tolerance cannot contain negative values`),this.name=`CounterToleranceNegativeError`}},S=class extends t{constructor(e){super(e),this.name=`EpochToleranceError`}},ie=class extends S{constructor(){super(`Epoch tolerance cannot contain negative values`),this.name=`EpochToleranceNegativeError`}},ae=class extends S{constructor(e,t){super(`Epoch tolerance must not exceed ${e} seconds, got ${t}. Large tolerances can cause performance issues.`),this.name=`EpochToleranceTooLargeError`}},oe=class extends t{constructor(e){super(e),this.name=`PluginError`}},se=class extends oe{constructor(){super(`Crypto plugin is required.`),this.name=`CryptoPluginMissingError`}},ce=class extends oe{constructor(){super(`Base32 plugin is required.`),this.name=`Base32PluginMissingError`}},C=class extends t{constructor(e){super(e),this.name=`ConfigurationError`}},le=class extends C{constructor(){super(`Secret is required. Use generateSecret() to create one, or provide via { secret: 'YOUR_BASE32_SECRET' }`),this.name=`SecretMissingError`}},ue=class extends C{constructor(){super(`Label is required for URI generation. Example: { label: 'user@example.com' }`),this.name=`LabelMissingError`}},de=class extends C{constructor(){super(`Issuer is required for URI generation. Example: { issuer: 'MyApp' }`),this.name=`IssuerMissingError`}},fe=class extends C{constructor(){super(`Class API requires secret to be a Base32 string, not Uint8Array. Use generateSecret() or provide a Base32-encoded string.`),this.name=`SecretTypeError`}},pe=class extends t{constructor(e){super(e),this.name=`AfterTimeStepError`}},me=class extends pe{constructor(){super(`afterTimeStep must be >= 0`),this.name=`AfterTimeStepNegativeError`}},he=class extends pe{constructor(){super(`Invalid afterTimeStep: non-integer value`),this.name=`AfterTimeStepNotIntegerError`}},ge=class extends pe{constructor(){super(`Invalid afterTimeStep: cannot be greater than current time step plus window`),this.name=`AfterTimeStepRangeExceededError`}};let _e=new TextEncoder;new TextDecoder;let ve=2**53-1,ye=Symbol(`otplib.guardrails.override`);function w(e,t,n){if(typeof t!=`number`||!Number.isSafeInteger(t))throw new C(`Guardrail '${e}' must be a safe integer`);if(t<n)throw new C(`Guardrail '${e}' must be >= ${n}`)}let T=Object.freeze({MIN_SECRET_BYTES:16,MAX_SECRET_BYTES:64,MIN_PERIOD:1,MAX_PERIOD:3600,MAX_COUNTER:ve,MAX_WINDOW:99,[ye]:!1});function E(e){if(!e)return T;e.MIN_SECRET_BYTES!==void 0&&w(`MIN_SECRET_BYTES`,e.MIN_SECRET_BYTES,1),e.MAX_SECRET_BYTES!==void 0&&w(`MAX_SECRET_BYTES`,e.MAX_SECRET_BYTES,1),e.MIN_PERIOD!==void 0&&w(`MIN_PERIOD`,e.MIN_PERIOD,1),e.MAX_PERIOD!==void 0&&w(`MAX_PERIOD`,e.MAX_PERIOD,1),e.MAX_COUNTER!==void 0&&w(`MAX_COUNTER`,e.MAX_COUNTER,0),e.MAX_WINDOW!==void 0&&w(`MAX_WINDOW`,e.MAX_WINDOW,1);let t={...T,...e};if(t.MIN_SECRET_BYTES>t.MAX_SECRET_BYTES)throw new C(`Guardrail 'MIN_SECRET_BYTES' must be <= 'MAX_SECRET_BYTES'`);if(t.MIN_PERIOD>t.MAX_PERIOD)throw new C(`Guardrail 'MIN_PERIOD' must be <= 'MAX_PERIOD'`);return Object.freeze({...t,[ye]:!0})}let be={sha1:[`sha1`,`sha-1`,`sha_1`],sha256:[`sha256`,`sha-256`,`sha_256`],sha512:[`sha512`,`sha-512`,`sha_512`]},xe=Object.freeze(Object.keys(be)),Se=new Map(Object.entries(be).flatMap(([e,t])=>t.map(t=>[t,e])));function D(e,t={}){let{supported:n,plugin:r}=t,i=n===void 0?xe:xe.filter(e=>n.includes(e));if(typeof e==`string`){let t=Se.get(e.toLowerCase());if(t!==void 0&&i.includes(t))return t}throw new g(e,{supported:i,plugin:r})}function O(e,t=T){if(e.length<t.MIN_SECRET_BYTES)throw new r(t.MIN_SECRET_BYTES,e.length);if(e.length>t.MAX_SECRET_BYTES)throw new i(t.MAX_SECRET_BYTES,e.length)}function Ce(e,t=T){if(typeof e==`number`){if(!Number.isFinite(e)||!Number.isInteger(e))throw new c;if(!Number.isSafeInteger(e))throw new s}let n=typeof e==`bigint`?e:BigInt(e);if(n<0n)throw new o;if(n>BigInt(t.MAX_COUNTER))throw new s}function we(e){if(!Number.isFinite(e))throw new d;if(e<0)throw new u}function Te(e,t=T){if(!Number.isInteger(e)||e<t.MIN_PERIOD)throw new p(t.MIN_PERIOD);if(e>t.MAX_PERIOD)throw new m(t.MAX_PERIOD)}function Ee(e,t){if(e.length!==t)throw new v(t,e.length);if(!/^\d+$/.test(e))throw new ee}function De(e,t=T){let[n,r]=Fe(e);if(!Number.isSafeInteger(n)||!Number.isSafeInteger(r))throw new x(`Counter tolerance values must be safe integers`);if(n<0||r<0)throw new re;let i=n+r+1;if(i>t.MAX_WINDOW)throw new ne(t.MAX_WINDOW,i)}function Oe(e,t=30,n=T){let[r,i]=Array.isArray(e)?e:[e,e];if(!Number.isSafeInteger(r)||!Number.isSafeInteger(i))throw new S(`Epoch tolerance values must be safe integers`);if(r<0||i<0)throw new ie;let a=(n.MAX_WINDOW-1)*t,o=r+i;if(o>a)throw new ae(a,o)}function ke(e){let t=typeof e==`bigint`?e:BigInt(e),n=new ArrayBuffer(8);return new DataView(n).setBigUint64(0,t,!1),new Uint8Array(n)}function Ae(e){let t=e[e.length-1]&15;return(e[t]&127)<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function je(e,t){return(e%10**t).toString().padStart(t,`0`)}function Me(e,t){return e.length===t.length}function Ne(e,t){let n=Pe(e),r=Pe(t);if(!Me(n,r))return!1;let i=0;for(let e=0;e<n.length;e++)i|=n[e]^r[e];return i===0}function Pe(e){return typeof e==`string`?_e.encode(e):e}function k(e,t){return typeof e==`string`?(M(t),t.decode(e)):e}function A(e){let{crypto:t,base32:n,length:r=20}=e;j(t),M(n);let i=t.randomBytes(r);return n.encode(i,{padding:!1})}function Fe(e=0){return Array.isArray(e)?e:[0,e]}function Ie(e=0){return Array.isArray(e)?e:[e,e]}function j(e){if(!e)throw new se}function M(e){if(!e)throw new ce}function N(e){if(!e)throw new le}function Le(e){if(!e)throw new ue}function Re(e){if(!e)throw new de}function ze(e){if(typeof e!=`string`)throw new fe}function Be(e){return{ok:!0,value:e}}function Ve(e){return{ok:!1,error:e}}function He(e){return(...t)=>{try{return Be(e(...t))}catch(e){return Ve(e)}}}function Ue(e){return async(...t)=>{try{return Be(await e(...t))}catch(e){return Ve(e)}}}function We(e){return typeof e.then==`function`}var Ge=class{crypto;constructor(e){this.crypto=e}get plugin(){return this.crypto}normalize(e){return D(e,{supported:this.crypto.algorithms,plugin:this.crypto.name})}async hmac(e,t,n){let r=this.normalize(e);try{return await this.crypto.hmac(r,t,n)}catch(e){throw new b(e instanceof Error?e.message:String(e),{cause:e})}}hmacSync(e,t,n){let r=this.normalize(e);try{let e=this.crypto.hmac(r,t,n);if(!We(e))return e;Promise.resolve(e).catch(()=>void 0)}catch(e){throw new b(e instanceof Error?e.message:String(e),{cause:e})}throw new b(`Crypto plugin does not support synchronous HMAC operations`)}randomBytes(e){try{return this.crypto.randomBytes(e)}catch(e){throw new te(e instanceof Error?e.message:String(e),{cause:e})}}};function Ke(e){return new Ge(e)}var qe=class extends Error{constructor(e,t){super(e,t),this.name=`URIParseError`}},P=class extends qe{constructor(e,t,n){super(`Invalid value for parameter '${e}': ${t}`,n),this.name=`InvalidParameterError`}};function Je(e,t,n=2**53-1){if(typeof e!=`number`&&(typeof e!=`string`||e.trim()===``))return;let r=Number(e);return Number.isSafeInteger(r)&&r>=t&&r<=n?r:void 0}function Ye(e){let{type:t,label:n,params:r}=e;if(t!==`hotp`&&t!==`totp`)throw new P(`type`,String(t));let i=r.digits===void 0?void 0:Je(r.digits,1);if(r.digits!==void 0&&i===void 0)throw new P(`digits`,String(r.digits));let a=r.counter===void 0?void 0:Je(r.counter,0);if(r.counter!==void 0&&a===void 0)throw new P(`counter`,String(r.counter));let o=r.period===void 0?void 0:Je(r.period,1);if(r.period!==void 0&&o===void 0)throw new P(`period`,String(r.period));let s=`otpauth://${t}/${n.split(`:`).map(e=>encodeURIComponent(e)).join(`:`)}?`,c=[];if(r.secret&&c.push(`secret=${encodeURIComponent(r.secret)}`),r.issuer&&c.push(`issuer=${encodeURIComponent(r.issuer)}`),r.algorithm){let e=D(r.algorithm);e!==`sha1`&&c.push(`algorithm=${e.toUpperCase()}`)}return i!==void 0&&i!==6&&c.push(`digits=${i}`),t===`hotp`&&a!==void 0&&c.push(`counter=${a}`),t===`totp`&&o!==void 0&&o!==30&&c.push(`period=${o}`),s+=c.join(`&`),s}function Xe(e){let{issuer:t,label:n,secret:r,algorithm:i=`sha1`,digits:a=6,period:o=30}=e;return Ye({type:`totp`,label:t?`${t}:${n}`:n,params:{secret:r,issuer:t,algorithm:i,digits:a,period:o}})}function Ze(e){let{issuer:t,label:n,secret:r,counter:i=0,algorithm:a=`sha1`,digits:o=6}=e;return Ye({type:`hotp`,label:t?`${t}:${n}`:n,params:{secret:r,issuer:t,algorithm:a,digits:o,counter:i}})}var Qe=class{options;guardrails;constructor(e={}){this.options=e,this.guardrails=E(e.guardrails)}generateSecret(){let{crypto:e,base32:t}=this.options;return j(e),M(t),A({crypto:e,base32:t})}async generate(e,t){let n={...this.options,...t},{secret:r,crypto:i,base32:a,algorithm:o=`sha1`,digits:s=6}=n;return N(r),j(i),F({secret:r,counter:e,algorithm:o,digits:s,crypto:i,base32:a,guardrails:t?.guardrails??this.guardrails,hooks:n.hooks})}async verify(e,t){let n={...this.options,...t},{secret:r,crypto:i,base32:a,algorithm:o=`sha1`,digits:s=6,counterTolerance:c=0}=n;N(r),j(i);let l=t?.guardrails??this.guardrails;return tt({secret:r,token:e.token,counter:e.counter,algorithm:o,digits:s,counterTolerance:c,crypto:i,base32:a,guardrails:l,hooks:n.hooks})}toURI(e=0){let{issuer:t,label:n,secret:r,algorithm:i=`sha1`,digits:a=6}=this.options;return N(r),Le(n),Re(t),ze(r),Ze({issuer:t,label:n,secret:r,algorithm:i,digits:a,counter:e})}};function $e(e){let{secret:t,counter:n,algorithm:r=`sha1`,digits:i=6,crypto:a,base32:o,guardrails:s,hooks:c}=e;N(t),j(a);let l=k(t,o);O(l,s),Ce(n,s);let u=D(r,{supported:a.algorithms,plugin:a.name});return{ctx:Ke(a),algorithm:u,digits:i,secretBytes:l,counterBytes:ke(n),hooks:c}}async function F(e){let{ctx:t,algorithm:n,digits:r,secretBytes:i,counterBytes:a,hooks:o}=$e(e),s=await t.hmac(n,i,a),c=o?.truncateDigest?o.truncateDigest(s):Ae(s);return o?.encodeToken?o.encodeToken(c,r):je(c,r)}function I(e){let{ctx:t,algorithm:n,digits:r,secretBytes:i,counterBytes:a,hooks:o}=$e(e),s=t.hmacSync(n,i,a),c=o?.truncateDigest?o.truncateDigest(s):Ae(s);return o?.encodeToken?o.encodeToken(c,r):je(c,r)}function et(e){let{secret:t,counter:n,token:r,algorithm:i=`sha1`,digits:a=6,crypto:o,base32:s,counterTolerance:c=0,guardrails:l=E(),hooks:u}=e;N(t),j(o);let d=k(t,s);O(d,l),Ce(n,l);let f=D(i,{supported:o.algorithms,plugin:o.name});u?.validateToken?u.validateToken(r,a):Ee(r,a),De(c,l);let p=typeof n==`bigint`?Number(n):n,[m,h]=Fe(c);return{token:r,counterNum:p,past:m,future:h,totalChecks:m+h+1,crypto:o,getGenerateOptions:e=>({secret:d,counter:e,algorithm:f,digits:a,crypto:o,guardrails:l,hooks:u})}}async function tt(e){let{token:t,counterNum:n,past:r,totalChecks:i,crypto:a,getGenerateOptions:o}=et(e),s=Math.max(0,r-n);for(let e=s;e<i;e++){let i=e-r,s=await F(o(n+i));if(a.constantTimeEqual(s,t))return{valid:!0,delta:i|0}}return{valid:!1}}function nt(e){let{token:t,counterNum:n,past:r,totalChecks:i,crypto:a,getGenerateOptions:o}=et(e),s=Math.max(0,r-n);for(let e=s;e<i;e++){let i=e-r,s=I(o(n+i));if(a.constantTimeEqual(s,t))return{valid:!0,delta:i|0}}return{valid:!1}}var rt=class{options;guardrails;constructor(e={}){this.options=e,this.guardrails=E(e.guardrails)}generateSecret(){let{crypto:e,base32:t}=this.options;return j(e),M(t),A({crypto:e,base32:t})}async generate(e){let t={...this.options,...e},{secret:n,crypto:r,base32:i,algorithm:a=`sha1`,digits:o=6,period:s=30,epoch:c,t0:l=0}=t;N(n),j(r);let u=e?.guardrails??this.guardrails;return L({secret:n,algorithm:a,digits:o,period:s,epoch:c??Math.floor(Date.now()/1e3),t0:l,crypto:r,base32:i,guardrails:u,hooks:t.hooks})}async verify(e,t){let n={...this.options,...t},{secret:r,crypto:i,base32:a,algorithm:o=`sha1`,digits:s=6,period:c=30,epoch:l,t0:u=0,epochTolerance:d=0,afterTimeStep:f}=n;N(r),j(i);let p=t?.guardrails??this.guardrails;return lt({secret:r,token:e,algorithm:o,digits:s,period:c,epoch:l??Math.floor(Date.now()/1e3),t0:u,epochTolerance:d,afterTimeStep:f,crypto:i,base32:a,guardrails:p,hooks:n.hooks})}toURI(e){let{issuer:t,label:n,secret:r,algorithm:i=`sha1`,digits:a=6,period:o=30}=this.options,s=e?.label??n,c=e?.issuer??t,l=e?.secret??r;return N(l),Le(s),Re(c),ze(l),Xe({issuer:c,label:s,secret:l,algorithm:i,digits:a,period:o})}};function it(e){let{secret:t,epoch:n=Math.floor(Date.now()/1e3),t0:r=0,period:i=30,algorithm:a=`sha1`,digits:o=6,crypto:s,base32:c,guardrails:l=E(),hooks:u}=e;N(t),j(s);let d=k(t,c);O(d,l),we(n),Te(i,l);let f=D(a,{supported:s.algorithms,plugin:s.name});return{secret:d,counter:Math.floor((n-r)/i),algorithm:f,digits:o,crypto:s,guardrails:l,hooks:u}}async function L(e){return F(it(e))}function at(e){return I(it(e))}function ot(e,t){if(e!==void 0){if(e<0)throw new me;if(!Number.isSafeInteger(e))throw new he;if(e>t)throw new ge}}function st(e,t){return t!==void 0&&e<=t}function ct(e){let{secret:t,token:n,epoch:r=Math.floor(Date.now()/1e3),t0:i=0,period:a=30,algorithm:o=`sha1`,digits:s=6,crypto:c,base32:l,epochTolerance:u=0,afterTimeStep:d,guardrails:f=E(),hooks:p}=e;N(t),j(c);let m=k(t,l);O(m,f),we(r),Te(a,f);let h=D(o,{supported:c.algorithms,plugin:c.name});p?.validateToken?p.validateToken(n,s):Ee(n,s),Oe(u,a,f);let g=Math.floor((r-i)/a),[_,v]=Ie(u),ee=Math.max(0,Math.floor((r-_-i)/a)),y=Math.floor((r+v-i)/a);return ot(d,y),{token:n,crypto:c,minCounter:ee,maxCounter:y,currentCounter:g,t0:i,period:a,afterTimeStep:d,getGenerateOptions:e=>({secret:m,epoch:e*a+i,t0:i,period:a,algorithm:h,digits:s,crypto:c,guardrails:f,hooks:p})}}async function lt(e){let{token:t,crypto:n,minCounter:r,maxCounter:i,currentCounter:a,t0:o,period:s,afterTimeStep:c,getGenerateOptions:l}=ct(e);for(let e=r;e<=i;e++){if(st(e,c))continue;let r=await L(l(e));if(n.constantTimeEqual(r,t))return{valid:!0,delta:e-a,epoch:e*s+o,timeStep:e}}return{valid:!1}}function ut(e){let{token:t,crypto:n,minCounter:r,maxCounter:i,currentCounter:a,t0:o,period:s,afterTimeStep:c,getGenerateOptions:l}=ct(e);for(let e=r;e<=i;e++){if(st(e,c))continue;let r=at(l(e));if(n.constantTimeEqual(r,t))return{valid:!0,delta:e-a,epoch:e*s+o,timeStep:e}}return{valid:!1}} /*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */ let dt=e=>Object.freeze(e());function ft(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function pt(e){if(!ft(e))throw TypeError(`Uint8Array expected`)}function mt(e,t){if(typeof t!=`string`)throw TypeError(`${e}: string expected`);return!0}function ht(e,t=`number`){if(typeof e!=`number`)throw TypeError(`${t}: expected number, got ${typeof e}`);if(!Number.isSafeInteger(e))throw RangeError(`${t}: expected safe integer, got ${e}`)}function gt(...e){let t=e=>e,n=(e,t)=>n=>e(t(n));return{encode:e.map(e=>e.encode).reduceRight(n,t),decode:e.map(e=>e.decode).reduce(n,t)}}let _t=(()=>{let e=[];for(let t=0;t<40;t++)e.push(2**t);return e})(),vt=(()=>{try{let e=new TextDecoder;return e.decode(Uint8Array.of(65,48,43,127))===`A0+`?e:void 0}catch{return}})(),yt=8192;function bt(e){let t=e.length;if(vt!==void 0&&t>=12)return vt.decode(e);if(t<=yt)return String.fromCharCode.apply(null,e);let n=``;for(let r=0;r<t;r+=yt)n+=String.fromCharCode.apply(null,e.subarray(r,r+yt));return n}function xt(e){if(ht(e),e<=0||e>8)throw RangeError(`radix2: bits should be in (0..8]`);let t=_t[e]-1;return{encode:n=>{pt(n);let r=n.length,i=new Uint8Array(Math.ceil(r*8/e)),a=0,o=0,s=0;for(let c=0;c<r;)for(c+2<r?(a=a<<24|n[c]<<16|n[c+1]<<8|n[c+2],o+=24,c+=3):(a=(a<<8|n[c])&65535,o+=8,c++);o-=e,i[s++]=a>>o&t,!(o<e););return o>0&&(i[s]=a<<e-o&t),i},decode:t=>{let n=t.length,r=new Uint8Array(Math.floor(n*e/8)),i=0,a=0,o=0;for(let s=0;s<n;s++)for(i=(i<<e|t[s])&65535,a+=e;a>=8;a-=8)r[o++]=i>>a-8&255;if(i=i<<8-a&255,a>=e)throw Error(`Excess padding`);if(i>0)throw Error(`Non-zero padding: ${i}`);return r}}}function St(e,t){let n=e.length;if(n>128)throw Error(`alphabet: max 128 letters`);let r=new Uint8Array(n),i=new Int8Array(128).fill(-1);for(let t=0;t<n;t++){let n=e.charCodeAt(t);if(e.codePointAt(t)!==n||n>127)throw Error(`alphabet: single-char ASCII letters only`);r[t]=n,i[n]=t}if(t!==void 0)for(let e of Object.keys(t)){let n=e.charCodeAt(0),r=i[t[e].charCodeAt(0)];if(e.length!==1||n>127||r===void 0||r===-1)throw Error(`alphabet: invalid alias ${e}`);i[n]=r}return{encode:e=>{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){let i=e[n],a=r[i];if(a===void 0)throw Error(`alphabet.encode: invalid digit ${i}`);t[n]=a}return bt(t)},decode:t=>{mt(`decode`,t);let n=t.length,r=new Uint8Array(n);for(let a=0;a<n;a++){let n=t.charCodeAt(a),o=n<128?i[n]:-1;if(o===-1)throw Error(`Unknown letter "${t[a]}". Allowed: ${e}`);r[a]=o}return r}}}function Ct(e,t=`=`){return ht(e),mt(`padding`,t),{encode(n){for(;n.length*e%8;)n+=t;return n},decode(n){mt(`decode`,n);let r=n.length;if(r*e%8)throw Error(`padding: invalid length`);for(;r>0&&n[r-1]===t;r--)if((r-1)*e%8==0)throw Error(`padding: excess padding`);return n.slice(0,r)}}}let wt=dt(()=>gt(xt(5),St(`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`),Ct(5)));var Tt=class{name=`scure`;encode(e,t={}){let{padding:n=!1}=t,r=wt.encode(e);return n?r:r.replace(/=+$/,``)}decode(e){try{let t=e.toUpperCase(),n=t.padEnd(Math.ceil(t.length/8)*8,`=`);return wt.decode(n)}catch(e){throw Error(`Invalid Base32 string: ${e.message}`)}}};let Et=Object.freeze(new Tt);function Dt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}let Ot=e=>e?`"${e}" `:``;function R(e,t=``){if(typeof e!=`number`)throw TypeError(Ot(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(Ot(t)+`expected integer >= 0, got `+e);return e}function kt(e,t,n=``){if(Dt(e)&&(t===void 0||e.length===t))return e;t!==void 0&&R(t,`length`);let r=Dt(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=Ot(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}function At(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`expected hash wrapped by utils.createHasher`);if(R(e.outputLen),R(e.blockLen),e.outputLen<1||e.blockLen<1)throw Error(`hash blockLen / outputLen must be >= 1`)}let jt=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)},Mt=(e,t)=>{jt(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,`__proto__`))throw TypeError(`"${t}.__proto__" is not allowed`)};function z(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function Nt(e,t){kt(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function B(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Pt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function V(e,t){return e<<32-t|e>>>t}function Ft(e,t){return e<<t|e>>>32-t>>>0}function It(e,t,n=`opts`){return Mt(e,`defaults`),t!==void 0&&Mt(t,n),Object.assign(Object.create(null),e,t)}function Lt(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=It({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function Rt(e=32){R(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}let zt=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});var Bt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(At(e),kt(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`expected Hash instance`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),B(r)}update(e){return z(this),this.iHash.update(e),this}digestInto(e){z(this),Nt(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};let Vt=(()=>{let e=((e,t,n)=>new Bt(e,t).update(n).digest());return e.create=(e,t)=>new Bt(e,t),e})(),H=BigInt(2**32-1),Ht=BigInt(32);function Ut(e,t=!1){return t?{h:Number(e&H),l:Number(e>>Ht&H)}:{h:Number(e>>Ht&H)|0,l:Number(e&H)|0}}function Wt(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=Ut(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}let Gt=e=>e/2**32|0,Kt=e=>e>>>0;function qt(e,t,n,r){let i=Gt(n),a=Kt(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}let Jt=(e,t,n)=>e>>>n,Yt=(e,t,n)=>e<<32-n|t>>>n,U=(e,t,n)=>e>>>n|t<<32-n,W=(e,t,n)=>e<<32-n|t>>>n,G=(e,t,n)=>e<<64-n|t>>>n-32,K=(e,t,n)=>e>>>n-32|t<<64-n;function q(e,t,n,r){let i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}let Xt=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),Zt=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,Qt=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),$t=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,en=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),tn=(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0;function nn(e,t,n){return e&t^~e&n}function rn(e,t,n){return e&t^e&n^t&n}var an=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Pt(this.buffer)}update(e){z(this),kt(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=Pt(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){z(this),Nt(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),qt(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:Pt(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};let on=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),sn=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),J=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),Y=new Uint32Array(80);var cn=class extends an{A=J[0]|0;B=J[1]|0;C=J[2]|0;D=J[3]|0;E=J[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:e,B:t,C:n,D:r,E:i}=this;return[e,t,n,r,i]}set(e,t,n,r,i){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)Y[n]=e.getUint32(t,!1);for(let e=16;e<80;e++)Y[e]=Ft(Y[e-3]^Y[e-8]^Y[e-14]^Y[e-16],1);let{A:n,B:r,C:i,D:a,E:o}=this;for(let e=0;e<80;e++){let t,s;e<20?(t=nn(r,i,a),s=1518500249):e<40?(t=r^i^a,s=1859775393):e<60?(t=rn(r,i,a),s=2400959708):(t=r^i^a,s=3395469782);let c=Ft(n,5)+t+o+s+Y[e]|0;o=a,a=i,i=Ft(r,30),r=n,n=c}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,this.set(n,r,i,a,o)}roundClean(){B(Y)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0),B(this.buffer)}};let ln=Lt(()=>new cn),un=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),X=new Uint32Array(64);var dn=class extends an{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)X[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=X[e-15],n=X[e-2],r=V(t,7)^V(t,18)^t>>>3,i=V(n,17)^V(n,19)^n>>>10;X[e]=i+X[e-7]+r+X[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=V(o,6)^V(o,11)^V(o,25),u=l+t+nn(o,s,c)+un[e]+X[e]|0,d=(V(n,2)^V(n,13)^V(n,22))+rn(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){B(X)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),B(this.buffer)}},fn=class extends dn{constructor(){super(32,on)}};let pn=Wt(`0x428a2f98d728ae22.0x7137449123ef65cd.0xb5c0fbcfec4d3b2f.0xe9b5dba58189dbbc.0x3956c25bf348b538.0x59f111f1b605d019.0x923f82a4af194f9b.0xab1c5ed5da6d8118.0xd807aa98a3030242.0x12835b0145706fbe.0x243185be4ee4b28c.0x550c7dc3d5ffb4e2.0x72be5d74f27b896f.0x80deb1fe3b1696b1.0x9bdc06a725c71235.0xc19bf174cf692694.0xe49b69c19ef14ad2.0xefbe4786384f25e3.0x0fc19dc68b8cd5b5.0x240ca1cc77ac9c65.0x2de92c6f592b0275.0x4a7484aa6ea6e483.0x5cb0a9dcbd41fbd4.0x76f988da831153b5.0x983e5152ee66dfab.0xa831c66d2db43210.0xb00327c898fb213f.0xbf597fc7beef0ee4.0xc6e00bf33da88fc2.0xd5a79147930aa725.0x06ca6351e003826f.0x142929670a0e6e70.0x27b70a8546d22ffc.0x2e1b21385c26c926.0x4d2c6dfc5ac42aed.0x53380d139d95b3df.0x650a73548baf63de.0x766a0abb3c77b2a8.0x81c2c92e47edaee6.0x92722c851482353b.0xa2bfe8a14cf10364.0xa81a664bbc423001.0xc24b8b70d0f89791.0xc76c51a30654be30.0xd192e819d6ef5218.0xd69906245565a910.0xf40e35855771202a.0x106aa07032bbd1b8.0x19a4c116b8d2d0c8.0x1e376c085141ab53.0x2748774cdf8eeb99.0x34b0bcb5e19b48a8.0x391c0cb3c5c95a63.0x4ed8aa4ae3418acb.0x5b9cca4f7763e373.0x682e6ff3d6b2b8a3.0x748f82ee5defb2fc.0x78a5636f43172f60.0x84c87814a1f0ab72.0x8cc702081a6439ec.0x90befffa23631e28.0xa4506cebde82bde9.0xbef9a3f7b2c67915.0xc67178f2e372532b.0xca273eceea26619c.0xd186b8c721c0c207.0xeada7dd6cde0eb1e.0xf57d4f7fee6ed178.0x06f067aa72176fba.0x0a637dc5a2c898a6.0x113f9804bef90dae.0x1b710b35131c471b.0x28db77f523047d84.0x32caab7b40c72493.0x3c9ebe0a15c9bebc.0x431d67c49c100d4c.0x4cc5d4becb3e42b6.0x597f299cfc657e2a.0x5fcb6fab3ad6faec.0x6c44198c4a475817`.split(`.`).map(e=>BigInt(e))),mn=pn[0],hn=pn[1],Z=new Uint32Array(80),Q=new Uint32Array(80);var gn=class extends an{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,t){super(128,e,16,!1),this.Ah=t[0]|0,this.Al=t[1]|0,this.Bh=t[2]|0,this.Bl=t[3]|0,this.Ch=t[4]|0,this.Cl=t[5]|0,this.Dh=t[6]|0,this.Dl=t[7]|0,this.Eh=t[8]|0,this.El=t[9]|0,this.Fh=t[10]|0,this.Fl=t[11]|0,this.Gh=t[12]|0,this.Gl=t[13]|0,this.Hh=t[14]|0,this.Hl=t[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:a,Dh:o,Dl:s,Eh:c,El:l,Fh:u,Fl:d,Gh:f,Gl:p,Hh:m,Hl:h}=this;return[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=r|0,this.Ch=i|0,this.Cl=a|0,this.Dh=o|0,this.Dl=s|0,this.Eh=c|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=f|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)Z[n]=e.getUint32(t),Q[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=Z[e-15]|0,n=Q[e-15]|0,r=U(t,n,1)^U(t,n,8)^Jt(t,n,7),i=W(t,n,1)^W(t,n,8)^Yt(t,n,7),a=Z[e-2]|0,o=Q[e-2]|0,s=U(a,o,19)^G(a,o,61)^Jt(a,o,6),c=W(a,o,19)^K(a,o,61)^Yt(a,o,6),l=Qt(i,c,Q[e-7],Q[e-16]),u=$t(l,r,s,Z[e-7],Z[e-16]);Z[e]=u|0,Q[e]=l|0}let{Ah:n,Al:r,Bh:i,Bl:a,Ch:o,Cl:s,Dh:c,Dl:l,Eh:u,El:d,Fh:f,Fl:p,Gh:m,Gl:h,Hh:g,Hl:_}=this;for(let e=0;e<80;e++){let t=U(u,d,14)^U(u,d,18)^G(u,d,41),v=W(u,d,14)^W(u,d,18)^K(u,d,41),ee=u&f^~u&m,y=d&p^~d&h,b=en(_,v,y,hn[e],Q[e]),te=tn(b,g,t,ee,mn[e],Z[e]),x=b|0,ne=U(n,r,28)^G(n,r,34)^G(n,r,39),re=W(n,r,28)^K(n,r,34)^K(n,r,39),S=n&i^n&o^i&o,ie=r&a^r&s^a&s;g=m|0,_=h|0,m=f|0,h=p|0,f=u|0,p=d|0,{h:u,l:d}=q(c|0,l|0,te|0,x|0),c=o|0,l=s|0,o=i|0,s=a|0,i=n|0,a=r|0;let ae=Xt(x,re,ie);n=Zt(ae,te,ne,S),r=ae|0}({h:n,l:r}=q(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=q(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=q(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=q(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=q(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=q(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=q(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=q(this.Hh|0,this.Hl|0,g|0,_|0),this.set(n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_)}roundClean(){B(Z,Q)}destroy(){this.destroyed=!0,B(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},_n=class extends gn{constructor(){super(64,sn)}};let vn={sha1:ln,sha256:Lt(()=>new fn,zt(1)),sha512:Lt(()=>new _n,zt(3))},yn=Object.freeze(Object.keys(vn));var bn=class{name=`noble`;algorithms=yn;hmac(e,t,n){let r=D(e,{supported:this.algorithms,plugin:this.name});return Vt(vn[r],t,n)}randomBytes(e){return Rt(e)}constantTimeEqual(e,t){return Ne(e,t)}};let xn=Object.freeze(new bn);function Sn(e){return{secret:e.secret,strategy:e.strategy??`totp`,crypto:e.crypto??xn,base32:e.base32??Et,algorithm:e.algorithm??`sha1`,digits:e.digits??6,period:e.period??30,epoch:e.epoch??Math.floor(Date.now()/1e3),t0:e.t0??0,counter:e.counter,guardrails:e.guardrails??E(),hooks:e.hooks}}function Cn(e){return{...Sn(e),token:e.token,epochTolerance:e.epochTolerance??0,counterTolerance:e.counterTolerance??0,afterTimeStep:e.afterTimeStep}}function $(e,t,n){if(e===`totp`)return n.totp();if(e===`hotp`){if(t===void 0)throw new C(`Counter is required for HOTP strategy. Example: { strategy: 'hotp', counter: 0 }`);return n.hotp(t)}throw new C(`Unknown OTP strategy: ${e}. Valid strategies are 'totp' or 'hotp'.`)}function wn(e){let{crypto:t=xn,base32:n=Et,length:r=20}=e||{};return A({crypto:t,base32:n,length:r})}function Tn(e){let{strategy:t=`totp`,issuer:n,label:r,secret:i,algorithm:a=`sha1`,digits:o=6,period:s=30,counter:c}=e;return $(t,c,{totp:()=>Xe({issuer:n,label:r,secret:i,algorithm:a,digits:o,period:s}),hotp:e=>Ze({issuer:n,label:r,secret:i,algorithm:a,digits:o,counter:e})})}async function En(e){let t=Sn(e),{secret:n,crypto:r,base32:i,algorithm:a,digits:o,hooks:s}=t,c={secret:n,crypto:r,base32:i,algorithm:a,digits:o,hooks:s};return $(t.strategy,t.counter,{totp:()=>L({...c,period:t.period,epoch:t.epoch,t0:t.t0,guardrails:t.guardrails}),hotp:e=>F({...c,counter:e,guardrails:t.guardrails})})}function Dn(e){let t=Sn(e),{secret:n,crypto:r,base32:i,algorithm:a,digits:o,hooks:s}=t,c={secret:n,crypto:r,base32:i,algorithm:a,digits:o,hooks:s};return $(t.strategy,t.counter,{totp:()=>at({...c,period:t.period,epoch:t.epoch,t0:t.t0,guardrails:t.guardrails}),hotp:e=>I({...c,counter:e,guardrails:t.guardrails})})}async function On(e){let t=Cn(e),{secret:n,token:r,crypto:i,base32:a,algorithm:o,digits:s,hooks:c}=t,l={secret:n,token:r,crypto:i,base32:a,algorithm:o,digits:s,hooks:c};return $(t.strategy,t.counter,{totp:()=>lt({...l,period:t.period,epoch:t.epoch,t0:t.t0,epochTolerance:t.epochTolerance,afterTimeStep:t.afterTimeStep,guardrails:t.guardrails}),hotp:e=>tt({...l,counter:e,counterTolerance:t.counterTolerance,guardrails:t.guardrails})})}function kn(e){let t=Cn(e),{secret:n,token:r,crypto:i,base32:a,algorithm:o,digits:s,hooks:c}=t,l={secret:n,token:r,crypto:i,base32:a,algorithm:o,digits:s,hooks:c};return $(t.strategy,t.counter,{totp:()=>ut({...l,period:t.period,epoch:t.epoch,t0:t.t0,epochTolerance:t.epochTolerance,afterTimeStep:t.afterTimeStep,guardrails:t.guardrails}),hotp:e=>nt({...l,counter:e,counterTolerance:t.counterTolerance,guardrails:t.guardrails})})}var An=class{strategy;crypto;base32;guardrails;constructor(e={}){let{strategy:t=`totp`,crypto:n=xn,base32:r=Et,guardrails:i}=e;this.strategy=t,this.crypto=n,this.base32=r,this.guardrails=E(i)}getStrategy(){return this.strategy}generateSecret(e=20){return A({crypto:this.crypto,base32:this.base32,length:e})}async generate(e){return En({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}generateSync(e){return Dn({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}async verify(e){return On({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}verifySync(e){return kn({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}generateURI(e){return Tn({...e,strategy:this.strategy})}};return e.AlgorithmError=h,e.AlgorithmUnsupportedError=g,e.HMACError=b,e.HOTP=Qe,e.NobleCryptoPlugin=bn,e.OTP=An,e.ScureBase32Plugin=Tt,e.TOTP=rt,e.createGuardrails=E,e.generate=En,e.generateSecret=wn,e.generateSync=Dn,e.generateURI=Tn,e.stringToBytes=Pe,e.verify=On,e.verifySync=kn,e.wrapResult=He,e.wrapResultAsync=Ue,e})({}); //# sourceMappingURL=index.global.js.map