otplib
Version:
TypeScript-first library for TOTP and HOTP with multi-runtime and plugin support
7 lines (6 loc) • 36.5 kB
JavaScript
;var otplib=(()=>{var Ut=Object.defineProperty;var Wr=Object.getOwnPropertyDescriptor;var Xr=Object.getOwnPropertyNames;var Yr=Object.prototype.hasOwnProperty;var Kr=(t,e)=>{for(var r in e)Ut(t,r,{get:e[r],enumerable:!0})},Jr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xr(e))!Yr.call(t,o)&&o!==r&&Ut(t,o,{get:()=>e[o],enumerable:!(n=Wr(e,o))||n.enumerable});return t};var Qr=t=>Jr(Ut({},"__esModule",{value:!0}),t);var yn={};Kr(yn,{AlgorithmError:()=>ee,AlgorithmUnsupportedError:()=>V,HMACError:()=>U,HOTP:()=>je,NobleCryptoPlugin:()=>Ze,OTP:()=>Ht,ScureBase32Plugin:()=>We,TOTP:()=>Fe,createGuardrails:()=>y,generate:()=>At,generateSecret:()=>Fr,generateSync:()=>Pt,generateURI:()=>wt,stringToBytes:()=>ke,verify:()=>St,verifySync:()=>Ct,wrapResult:()=>Nt,wrapResultAsync:()=>Vt});var T=class extends Error{constructor(e,r){super(e,r),this.name="OTPError"}},ie=class extends T{constructor(e){super(e),this.name="SecretError"}},ae=class extends ie{constructor(e,r){super(`Secret must be at least ${e} bytes (${e*8} bits), got ${r} bytes`),this.name="SecretTooShortError"}},ce=class extends ie{constructor(e,r){super(`Secret must not exceed ${e} bytes, got ${r} bytes`),this.name="SecretTooLongError"}},Q=class extends T{constructor(e){super(e),this.name="CounterError"}},ue=class extends Q{constructor(){super("Counter must be non-negative"),this.name="CounterNegativeError"}},Z=class extends Q{constructor(){super("Counter exceeds maximum safe integer value"),this.name="CounterOverflowError"}},le=class extends Q{constructor(){super("Counter must be a finite integer"),this.name="CounterNotIntegerError"}},pe=class extends T{constructor(e){super(e),this.name="TimeError"}},fe=class extends pe{constructor(){super("Time must be non-negative"),this.name="TimeNegativeError"}},he=class extends pe{constructor(){super("Time must be a finite number"),this.name="TimeNotFiniteError"}},de=class extends T{constructor(e){super(e),this.name="PeriodError"}},ge=class extends de{constructor(e){super(`Period must be at least ${e} second(s)`),this.name="PeriodTooSmallError"}},xe=class extends de{constructor(e){super(`Period must not exceed ${e} seconds`),this.name="PeriodTooLargeError"}};var ee=class extends T{constructor(e){super(e),this.name="AlgorithmError"}},V=class extends ee{constructor(e,r={}){let{supported:n,plugin:o}=r;super("Unsupported hash algorithm."+(n?` Expected one of: ${n.join(", ")||"(none)"}`:"")+(o?` [plugin: ${o}]`:"")),this.name="AlgorithmUnsupportedError"}},me=class extends T{constructor(e){super(e),this.name="TokenError"}},ye=class extends me{constructor(e,r){super(`Token must be ${e} digits, got ${r}`),this.name="TokenLengthError"}},be=class extends me{constructor(){super("Token must contain only digits"),this.name="TokenFormatError"}},Te=class extends T{constructor(e,r){super(e,r),this.name="CryptoError"}},U=class extends Te{constructor(e,r){super(`HMAC computation failed: ${e}`,r),this.name="HMACError"}},Oe=class extends Te{constructor(e,r){super(`Random byte generation failed: ${e}`,r),this.name="RandomBytesError"}};var $=class extends T{constructor(e){super(e),this.name="CounterToleranceError"}},Ee=class extends ${constructor(e,r){super(`Counter tolerance validation failed: total checks (${r}) exceeds MAX_WINDOW (${e})`),this.name="CounterToleranceTooLargeError"}},we=class extends ${constructor(){super("Counter tolerance cannot contain negative values"),this.name="CounterToleranceNegativeError"}},j=class extends T{constructor(e){super(e),this.name="EpochToleranceError"}},Ae=class extends j{constructor(){super("Epoch tolerance cannot contain negative values"),this.name="EpochToleranceNegativeError"}},Pe=class extends j{constructor(e,r){super(`Epoch tolerance must not exceed ${e} seconds, got ${r}. Large tolerances can cause performance issues.`),this.name="EpochToleranceTooLargeError"}},Se=class extends T{constructor(e){super(e),this.name="PluginError"}},Ce=class extends Se{constructor(){super("Crypto plugin is required."),this.name="CryptoPluginMissingError"}},He=class extends Se{constructor(){super("Base32 plugin is required."),this.name="Base32PluginMissingError"}},O=class extends T{constructor(e){super(e),this.name="ConfigurationError"}},Re=class extends O{constructor(){super("Secret is required. Use generateSecret() to create one, or provide via { secret: 'YOUR_BASE32_SECRET' }"),this.name="SecretMissingError"}},Ie=class extends O{constructor(){super("Label is required for URI generation. Example: { label: 'user@example.com' }"),this.name="LabelMissingError"}},Be=class extends O{constructor(){super("Issuer is required for URI generation. Example: { issuer: 'MyApp' }"),this.name="IssuerMissingError"}},_e=class extends O{constructor(){super("Class API requires secret to be a Base32 string, not Uint8Array. Use generateSecret() or provide a Base32-encoded string."),this.name="SecretTypeError"}},te=class extends T{constructor(e){super(e),this.name="AfterTimeStepError"}},Ue=class extends te{constructor(){super("afterTimeStep must be >= 0"),this.name="AfterTimeStepNegativeError"}},ve=class extends te{constructor(){super("Invalid afterTimeStep: non-integer value"),this.name="AfterTimeStepNotIntegerError"}},Le=class extends te{constructor(){super("Invalid afterTimeStep: cannot be greater than current time step plus window"),this.name="AfterTimeStepRangeExceededError"}};var Zr=new TextEncoder,wn=new TextDecoder,ir=16,ar=64,cr=20,ur=1,lr=3600,pr=30,fr=Number.MAX_SAFE_INTEGER,hr=99,dr=Symbol("otplib.guardrails.override");function re(t,e,r){if(typeof e!="number"||!Number.isSafeInteger(e))throw new O(`Guardrail '${t}' must be a safe integer`);if(e<r)throw new O(`Guardrail '${t}' must be >= ${r}`)}var z=Object.freeze({MIN_SECRET_BYTES:ir,MAX_SECRET_BYTES:ar,MIN_PERIOD:ur,MAX_PERIOD:lr,MAX_COUNTER:fr,MAX_WINDOW:hr,[dr]:!1});function y(t){if(!t)return z;t.MIN_SECRET_BYTES!==void 0&&re("MIN_SECRET_BYTES",t.MIN_SECRET_BYTES,1),t.MAX_SECRET_BYTES!==void 0&&re("MAX_SECRET_BYTES",t.MAX_SECRET_BYTES,1),t.MIN_PERIOD!==void 0&&re("MIN_PERIOD",t.MIN_PERIOD,1),t.MAX_PERIOD!==void 0&&re("MAX_PERIOD",t.MAX_PERIOD,1),t.MAX_COUNTER!==void 0&&re("MAX_COUNTER",t.MAX_COUNTER,0),t.MAX_WINDOW!==void 0&&re("MAX_WINDOW",t.MAX_WINDOW,1);let e={...z,...t};if(e.MIN_SECRET_BYTES>e.MAX_SECRET_BYTES)throw new O("Guardrail 'MIN_SECRET_BYTES' must be <= 'MAX_SECRET_BYTES'");if(e.MIN_PERIOD>e.MAX_PERIOD)throw new O("Guardrail 'MIN_PERIOD' must be <= 'MAX_PERIOD'");return Object.freeze({...e,[dr]:!0})}var gr={sha1:["sha1","sha-1","sha_1"],sha256:["sha256","sha-256","sha_256"],sha512:["sha512","sha-512","sha_512"]},vt=Object.freeze(Object.keys(gr)),en=new Map(Object.entries(gr).flatMap(([t,e])=>e.map(r=>[r,t])));function A(t,e={}){let{supported:r,plugin:n}=e,o=r===void 0?vt:vt.filter(s=>r.includes(s));if(typeof t=="string"){let s=en.get(t.toLowerCase());if(s!==void 0&&o.includes(s))return s}throw new V(t,{supported:o,plugin:n})}function F(t,e=z){if(t.length<e.MIN_SECRET_BYTES)throw new ae(e.MIN_SECRET_BYTES,t.length);if(t.length>e.MAX_SECRET_BYTES)throw new ce(e.MAX_SECRET_BYTES,t.length)}function nt(t,e=z){if(typeof t=="number"){if(!Number.isFinite(t)||!Number.isInteger(t))throw new le;if(!Number.isSafeInteger(t))throw new Z}let r=typeof t=="bigint"?t:BigInt(t);if(r<0n)throw new ue;if(r>BigInt(e.MAX_COUNTER))throw new Z}function ot(t){if(!Number.isFinite(t))throw new he;if(t<0)throw new fe}function st(t,e=z){if(!Number.isInteger(t)||t<e.MIN_PERIOD)throw new ge(e.MIN_PERIOD);if(t>e.MAX_PERIOD)throw new xe(e.MAX_PERIOD)}function Me(t,e){if(t.length!==e)throw new ye(e,t.length);if(!/^\d+$/.test(t))throw new be}function Lt(t,e=z){let[r,n]=ct(t);if(!Number.isSafeInteger(r)||!Number.isSafeInteger(n))throw new $("Counter tolerance values must be safe integers");if(r<0||n<0)throw new we;let o=r+n+1;if(o>e.MAX_WINDOW)throw new Ee(e.MAX_WINDOW,o)}function kt(t,e=pr,r=z){let[n,o]=Array.isArray(t)?t:[t,t];if(!Number.isSafeInteger(n)||!Number.isSafeInteger(o))throw new j("Epoch tolerance values must be safe integers");if(n<0||o<0)throw new Ae;let s=(r.MAX_WINDOW-1)*e,i=n+o;if(i>s)throw new Pe(s,i)}function Mt(t){let e=typeof t=="bigint"?t:BigInt(t),r=new ArrayBuffer(8);return new DataView(r).setBigUint64(0,e,!1),new Uint8Array(r)}function it(t){let e=t[t.length-1]&15;return(t[e]&127)<<24|t[e+1]<<16|t[e+2]<<8|t[e+3]}function at(t,e){let r=10**e;return(t%r).toString().padStart(e,"0")}function xr(t,e){return t.length===e.length}function Dt(t,e){let r=ke(t),n=ke(e);if(!xr(r,n))return!1;let o=0;for(let s=0;s<r.length;s++)o|=r[s]^n[s];return o===0}function ke(t){return typeof t=="string"?Zr.encode(t):t}function q(t,e){return typeof t=="string"?(W(e),e.decode(t)):t}function v(t){let{crypto:e,base32:r,length:n=cr}=t;b(e),W(r);let o=e.randomBytes(n);return r.encode(o,{padding:!1})}function ct(t=0){return Array.isArray(t)?t:[0,t]}function Gt(t=0){return Array.isArray(t)?t:[t,t]}function b(t){if(!t)throw new Ce}function W(t){if(!t)throw new He}function E(t){if(!t)throw new Re}function De(t){if(!t)throw new Ie}function Ge(t){if(!t)throw new Be}function Ne(t){if(typeof t!="string")throw new _e}function mr(t){return{ok:!0,value:t}}function yr(t){return{ok:!1,error:t}}function Nt(t){return(...e)=>{try{return mr(t(...e))}catch(r){return yr(r)}}}function Vt(t){return async(...e)=>{try{return mr(await t(...e))}catch(r){return yr(r)}}}function tn(t){return typeof t.then=="function"}var ut=class{constructor(e){this.crypto=e}get plugin(){return this.crypto}normalize(e){return A(e,{supported:this.crypto.algorithms,plugin:this.crypto.name})}async hmac(e,r,n){let o=this.normalize(e);try{return await this.crypto.hmac(o,r,n)}catch(s){let i=s instanceof Error?s.message:String(s);throw new U(i,{cause:s})}}hmacSync(e,r,n){let o=this.normalize(e);try{let s=this.crypto.hmac(o,r,n);if(!tn(s))return s;Promise.resolve(s).catch(()=>{})}catch(s){let i=s instanceof Error?s.message:String(s);throw new U(i,{cause:s})}throw new U("Crypto plugin does not support synchronous HMAC operations")}randomBytes(e){try{return this.crypto.randomBytes(e)}catch(r){let n=r instanceof Error?r.message:String(r);throw new Oe(n,{cause:r})}}};function $t(t){return new ut(t)}function jt(t){let{type:e,label:r,params:n}=t,o=r.split(":").map(a=>encodeURIComponent(a)).join(":"),s=`otpauth://${e}/${o}?`,i=[];if(n.secret&&i.push(`secret=${encodeURIComponent(n.secret)}`),n.issuer&&i.push(`issuer=${encodeURIComponent(n.issuer)}`),n.algorithm){let a=A(n.algorithm);a!=="sha1"&&i.push(`algorithm=${a.toUpperCase()}`)}return n.digits&&n.digits!==6&&i.push(`digits=${n.digits}`),e==="hotp"&&n.counter!==void 0&&i.push(`counter=${n.counter}`),e==="totp"&&n.period!==void 0&&n.period!==30&&i.push(`period=${n.period}`),s+=i.join("&"),s}function Ve(t){let{issuer:e,label:r,secret:n,algorithm:o="sha1",digits:s=6,period:i=30}=t,a=e?`${e}:${r}`:r;return jt({type:"totp",label:a,params:{secret:n,issuer:e,algorithm:o,digits:s,period:i}})}function $e(t){let{issuer:e,label:r,secret:n,counter:o=0,algorithm:s="sha1",digits:i=6}=t,a=e?`${e}:${r}`:r;return jt({type:"hotp",label:a,params:{secret:n,issuer:e,algorithm:s,digits:i,counter:o}})}var je=class{options;guardrails;constructor(e={}){this.options=e,this.guardrails=y(e.guardrails)}generateSecret(){let{crypto:e,base32:r}=this.options;return b(e),W(r),v({crypto:e,base32:r})}async generate(e,r){let n={...this.options,...r},{secret:o,crypto:s,base32:i,algorithm:a="sha1",digits:c=6}=n;E(o),b(s);let u=r?.guardrails??this.guardrails;return X({secret:o,counter:e,algorithm:a,digits:c,crypto:s,base32:i,guardrails:u,hooks:n.hooks})}async verify(e,r){let n={...this.options,...r},{secret:o,crypto:s,base32:i,algorithm:a="sha1",digits:c=6,counterTolerance:u=0}=n;E(o),b(s);let l=r?.guardrails??this.guardrails;return lt({secret:o,token:e.token,counter:e.counter,algorithm:a,digits:c,counterTolerance:u,crypto:s,base32:i,guardrails:l,hooks:n.hooks})}toURI(e=0){let{issuer:r,label:n,secret:o,algorithm:s="sha1",digits:i=6}=this.options;return E(o),De(n),Ge(r),Ne(o),$e({issuer:r,label:n,secret:o,algorithm:s,digits:i,counter:e})}};function br(t){let{secret:e,counter:r,algorithm:n="sha1",digits:o=6,crypto:s,base32:i,guardrails:a,hooks:c}=t;E(e),b(s);let u=q(e,i);F(u,a),nt(r,a);let l=A(n,{supported:s.algorithms,plugin:s.name}),p=$t(s),f=Mt(r);return{ctx:p,algorithm:l,digits:o,secretBytes:u,counterBytes:f,hooks:c}}async function X(t){let{ctx:e,algorithm:r,digits:n,secretBytes:o,counterBytes:s,hooks:i}=br(t),a=await e.hmac(r,o,s),c=i?.truncateDigest?i.truncateDigest(a):it(a);return i?.encodeToken?i.encodeToken(c,n):at(c,n)}function ze(t){let{ctx:e,algorithm:r,digits:n,secretBytes:o,counterBytes:s,hooks:i}=br(t),a=e.hmacSync(r,o,s),c=i?.truncateDigest?i.truncateDigest(a):it(a);return i?.encodeToken?i.encodeToken(c,n):at(c,n)}function Tr(t){let{secret:e,counter:r,token:n,algorithm:o="sha1",digits:s=6,crypto:i,base32:a,counterTolerance:c=0,guardrails:u=y(),hooks:l}=t;E(e),b(i);let p=q(e,a);F(p,u),nt(r,u);let f=A(o,{supported:i.algorithms,plugin:i.name});l?.validateToken?l.validateToken(n,s):Me(n,s),Lt(c,u);let h=typeof r=="bigint"?Number(r):r,[g,x]=ct(c),w=g+x+1;return{token:n,counterNum:h,past:g,future:x,totalChecks:w,crypto:i,getGenerateOptions:I=>({secret:p,counter:I,algorithm:f,digits:s,crypto:i,guardrails:u,hooks:l})}}async function lt(t){let{token:e,counterNum:r,past:n,totalChecks:o,crypto:s,getGenerateOptions:i}=Tr(t),a=Math.max(0,n-r);for(let c=a;c<o;c++){let u=c-n,l=r+u,p=await X(i(l));if(s.constantTimeEqual(p,e))return{valid:!0,delta:u|0}}return{valid:!1}}function Or(t){let{token:e,counterNum:r,past:n,totalChecks:o,crypto:s,getGenerateOptions:i}=Tr(t),a=Math.max(0,n-r);for(let c=a;c<o;c++){let u=c-n,l=r+u,p=ze(i(l));if(s.constantTimeEqual(p,e))return{valid:!0,delta:u|0}}return{valid:!1}}var Fe=class{options;guardrails;constructor(e={}){this.options=e,this.guardrails=y(e.guardrails)}generateSecret(){let{crypto:e,base32:r}=this.options;return b(e),W(r),v({crypto:e,base32:r})}async generate(e){let r={...this.options,...e},{secret:n,crypto:o,base32:s,algorithm:i="sha1",digits:a=6,period:c=30,epoch:u,t0:l=0}=r;E(n),b(o);let p=e?.guardrails??this.guardrails;return qe({secret:n,algorithm:i,digits:a,period:c,epoch:u??Math.floor(Date.now()/1e3),t0:l,crypto:o,base32:s,guardrails:p,hooks:r.hooks})}async verify(e,r){let n={...this.options,...r},{secret:o,crypto:s,base32:i,algorithm:a="sha1",digits:c=6,period:u=30,epoch:l,t0:p=0,epochTolerance:f=0,afterTimeStep:h}=n;E(o),b(s);let g=r?.guardrails??this.guardrails;return pt({secret:o,token:e,algorithm:a,digits:c,period:u,epoch:l??Math.floor(Date.now()/1e3),t0:p,epochTolerance:f,afterTimeStep:h,crypto:s,base32:i,guardrails:g,hooks:n.hooks})}toURI(e){let{issuer:r,label:n,secret:o,algorithm:s="sha1",digits:i=6,period:a=30}=this.options,c=e?.label??n,u=e?.issuer??r,l=e?.secret??o;return E(l),De(c),Ge(u),Ne(l),Ve({issuer:u,label:c,secret:l,algorithm:s,digits:i,period:a})}};function Er(t){let{secret:e,epoch:r=Math.floor(Date.now()/1e3),t0:n=0,period:o=30,algorithm:s="sha1",digits:i=6,crypto:a,base32:c,guardrails:u=y(),hooks:l}=t;E(e),b(a);let p=q(e,c);F(p,u),ot(r),st(o,u);let f=A(s,{supported:a.algorithms,plugin:a.name}),h=Math.floor((r-n)/o);return{secret:p,counter:h,algorithm:f,digits:i,crypto:a,guardrails:u,hooks:l}}async function qe(t){let e=Er(t);return X(e)}function zt(t){let e=Er(t);return ze(e)}function rn(t,e){if(t!==void 0){if(t<0)throw new Ue;if(!Number.isSafeInteger(t))throw new ve;if(t>e)throw new Le}}function wr(t,e){return e!==void 0&&t<=e}function Ar(t){let{secret:e,token:r,epoch:n=Math.floor(Date.now()/1e3),t0:o=0,period:s=30,algorithm:i="sha1",digits:a=6,crypto:c,base32:u,epochTolerance:l=0,afterTimeStep:p,guardrails:f=y(),hooks:h}=t;E(e),b(c);let g=q(e,u);F(g,f),ot(n),st(s,f);let x=A(i,{supported:c.algorithms,plugin:c.name});h?.validateToken?h.validateToken(r,a):Me(r,a),kt(l,s,f);let w=Math.floor((n-o)/s),[I,N]=Gt(l),d=Math.max(0,Math.floor((n-I-o)/s)),S=Math.floor((n+N-o)/s);return rn(p,S),{token:r,crypto:c,minCounter:d,maxCounter:S,currentCounter:w,t0:o,period:s,afterTimeStep:p,getGenerateOptions:H=>({secret:g,epoch:H*s+o,t0:o,period:s,algorithm:x,digits:a,crypto:c,guardrails:f,hooks:h})}}async function pt(t){let{token:e,crypto:r,minCounter:n,maxCounter:o,currentCounter:s,t0:i,period:a,afterTimeStep:c,getGenerateOptions:u}=Ar(t);for(let l=n;l<=o;l++){if(wr(l,c))continue;let p=await qe(u(l));if(r.constantTimeEqual(p,e))return{valid:!0,delta:l-s,epoch:l*a+i,timeStep:l}}return{valid:!1}}function Pr(t){let{token:e,crypto:r,minCounter:n,maxCounter:o,currentCounter:s,t0:i,period:a,afterTimeStep:c,getGenerateOptions:u}=Ar(t);for(let l=n;l<=o;l++){if(wr(l,c))continue;let p=zt(u(l));if(r.constantTimeEqual(p,e))return{valid:!0,delta:l-s,epoch:l*a+i,timeStep:l}}return{valid:!1}}function nn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Cr(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(r=>typeof r=="string"):e.every(r=>Number.isSafeInteger(r)):!1}function ft(t,e){if(typeof e!="string")throw new TypeError(`${t}: string expected`);return!0}function Wt(t){if(typeof t!="number")throw new TypeError(`number expected, got ${typeof t}`);if(!Number.isSafeInteger(t))throw new RangeError(`invalid integer: ${t}`)}function qt(t){if(!Array.isArray(t))throw new TypeError("array expected")}function ht(t,e){if(!Cr(!0,e))throw new TypeError(`${t}: array of strings expected`)}function on(t,e){if(!Cr(!1,e))throw new TypeError(`${t}: array of numbers expected`)}function sn(...t){let e=s=>s,r=(s,i)=>a=>s(i(a)),n=t.map(s=>s.encode).reduceRight(r,e),o=t.map(s=>s.decode).reduce(r,e);return{encode:n,decode:o}}function an(t){let e=typeof t=="string"?t.split(""):t,r=e.length;ht("alphabet",e);let n=new Map(e.map((o,s)=>[o,s]));return{encode:o=>(qt(o),o.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=r)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:o=>(qt(o),o.map(s=>{ft("alphabet.decode",s);let i=n.get(s);if(i===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return i}))}}function cn(t=""){return ft("join",t),{encode:e=>(ht("join.decode",e),e.join(t)),decode:e=>(ft("join.decode",e),e.split(t))}}function un(t,e="="){return Wt(t),ft("padding",e),{encode(r){for(ht("padding.encode",r);r.length*t%8;)r.push(e);return r},decode(r){ht("padding.decode",r);let n=r.length;if(n*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;n>0&&r[n-1]===e;n--)if((n-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return r.slice(0,n)}}}var Hr=(t,e)=>e===0?t:Hr(e,t%e),dt=(t,e)=>t+(e-Hr(t,e)),Ft=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Sr(t,e,r,n){if(qt(t),e<=0||e>32)throw new RangeError(`convertRadix2: wrong from=${e}`);if(r<=0||r>32)throw new RangeError(`convertRadix2: wrong to=${r}`);if(dt(e,r)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${r} carryBits=${dt(e,r)}`);let o=0,s=0,i=Ft[e],a=Ft[r]-1,c=[];for(let u of t){if(Wt(u),u>=i)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(o=o<<e|u,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=r;s-=r)c.push((o>>s-r&a)>>>0);let l=Ft[s];if(l===void 0)throw new Error("invalid carry");o&=l-1}if(o=o<<r-s&a,!n&&s>=e)throw new Error("Excess padding");if(!n&&o>0)throw new Error(`Non-zero padding: ${o}`);return n&&s>0&&c.push(o>>>0),c}function ln(t,e=!1){if(Wt(t),t<=0||t>32)throw new RangeError("radix2: bits should be in (0..32]");if(dt(8,t)>32||dt(t,8)>32)throw new RangeError("radix2: carry overflow");return{encode:r=>{if(!nn(r))throw new TypeError("radix2.encode input should be Uint8Array");return Sr(Array.from(r),8,t,!e)},decode:r=>(on("radix2.decode",r),Uint8Array.from(Sr(r,t,8,e)))}}var Xt=Object.freeze(sn(ln(5),an("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),un(5),cn("")));var We=class{name="scure";encode(e,r={}){let{padding:n=!1}=r,o=Xt.encode(e);return n?o:o.replace(/=+$/,"")}decode(e){try{let r=e.toUpperCase(),n=r.padEnd(Math.ceil(r.length/8)*8,"=");return Xt.decode(n)}catch(r){throw new Error(`Invalid Base32 string: ${r.message}`)}}},ne=Object.freeze(new We);function pn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Yt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Xe(t,e,r=""){let n=pn(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function Rr(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Yt(t.outputLen),Yt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function oe(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function gt(t,e){Xe(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function P(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function xt(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function C(t,e){return t<<32-e|t>>>e}function mt(t,e){return t<<e|t>>>32-e>>>0}function Ye(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ir(t=32){Yt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var Kt=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});var yt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Rr(e),Xe(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),P(o)}update(e){return oe(this),this.iHash.update(e),this}digestInto(e){oe(this),gt(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),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:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Br=(()=>{let t=((e,r,n)=>new yt(e,r).update(n).digest());return t.create=(e,r)=>new yt(e,r),t})();function bt(t,e,r){return t&e^~t&r}function Tt(t,e,r){return t&e^t&r^e&r}var Y=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=xt(this.buffer)}update(e){oe(this),Xe(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=xt(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){oe(this),gt(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,P(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let p=i;p<o;p++)r[p]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=xt(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<u;p++)a.setUint32(4*p,l[p],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},L=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var m=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ke=Uint32Array.from([1732584193,4023233417,2562383102,271733878,3285377520]),k=new Uint32Array(80),Jt=class extends Y{A=Ke[0]|0;B=Ke[1]|0;C=Ke[2]|0;D=Ke[3]|0;E=Ke[4]|0;constructor(){super(64,20,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s}=this;return[e,r,n,o,s]}set(e,r,n,o,s){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0}process(e,r){for(let c=0;c<16;c++,r+=4)k[c]=e.getUint32(r,!1);for(let c=16;c<80;c++)k[c]=mt(k[c-3]^k[c-8]^k[c-14]^k[c-16],1);let{A:n,B:o,C:s,D:i,E:a}=this;for(let c=0;c<80;c++){let u,l;c<20?(u=bt(o,s,i),l=1518500249):c<40?(u=o^s^i,l=1859775393):c<60?(u=Tt(o,s,i),l=2400959708):(u=o^s^i,l=3395469782);let p=mt(n,5)+u+a+l+k[c]|0;a=i,i=s,s=mt(o,30),o=n,n=p}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,this.set(n,o,s,i,a)}roundClean(){P(k)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0),P(this.buffer)}},_r=Ye(()=>new Jt);var Ot=BigInt(4294967295),Ur=BigInt(32);function fn(t,e=!1){return e?{h:Number(t&Ot),l:Number(t>>Ur&Ot)}:{h:Number(t>>Ur&Ot)|0,l:Number(t&Ot)|0}}function vr(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=fn(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Qt=(t,e,r)=>t>>>r,Zt=(t,e,r)=>t<<32-r|e>>>r,K=(t,e,r)=>t>>>r|e<<32-r,J=(t,e,r)=>t<<32-r|e>>>r,Je=(t,e,r)=>t<<64-r|e>>>r-32,Qe=(t,e,r)=>t>>>r-32|e<<64-r;function R(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Lr=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),kr=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Mr=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Dr=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Gr=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Nr=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var dn=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]),M=new Uint32Array(64),er=class extends Y{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let p=0;p<16;p++,r+=4)M[p]=e.getUint32(r,!1);for(let p=16;p<64;p++){let f=M[p-15],h=M[p-2],g=C(f,7)^C(f,18)^f>>>3,x=C(h,17)^C(h,19)^h>>>10;M[p]=x+M[p-7]+g+M[p-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let p=0;p<64;p++){let f=C(a,6)^C(a,11)^C(a,25),h=l+f+bt(a,c,u)+dn[p]+M[p]|0,x=(C(n,2)^C(n,13)^C(n,22))+Tt(n,o,s)|0;l=u,u=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){P(M)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),P(this.buffer)}},tr=class extends er{A=L[0]|0;B=L[1]|0;C=L[2]|0;D=L[3]|0;E=L[4]|0;F=L[5]|0;G=L[6]|0;H=L[7]|0;constructor(){super(32)}};var Vr=vr(["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"].map(t=>BigInt(t))),gn=Vr[0],xn=Vr[1],D=new Uint32Array(80),G=new Uint32Array(80),rr=class extends Y{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:l,Fh:p,Fl:f,Gh:h,Gl:g,Hh:x,Hl:w}=this;return[e,r,n,o,s,i,a,c,u,l,p,f,h,g,x,w]}set(e,r,n,o,s,i,a,c,u,l,p,f,h,g,x,w){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=p|0,this.Fl=f|0,this.Gh=h|0,this.Gl=g|0,this.Hh=x|0,this.Hl=w|0}process(e,r){for(let d=0;d<16;d++,r+=4)D[d]=e.getUint32(r),G[d]=e.getUint32(r+=4);for(let d=16;d<80;d++){let S=D[d-15]|0,H=G[d-15]|0,Rt=K(S,H,1)^K(S,H,8)^Qt(S,H,7),It=J(S,H,1)^J(S,H,8)^Zt(S,H,7),B=D[d-2]|0,_=G[d-2]|0,tt=K(B,_,19)^Je(B,_,61)^Qt(B,_,6),Bt=J(B,_,19)^Qe(B,_,61)^Zt(B,_,6),rt=Mr(It,Bt,G[d-7],G[d-16]),_t=Dr(rt,Rt,tt,D[d-7],D[d-16]);D[d]=_t|0,G[d]=rt|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:l,Eh:p,El:f,Fh:h,Fl:g,Gh:x,Gl:w,Hh:I,Hl:N}=this;for(let d=0;d<80;d++){let S=K(p,f,14)^K(p,f,18)^Je(p,f,41),H=J(p,f,14)^J(p,f,18)^Qe(p,f,41),Rt=p&h^~p&x,It=f&g^~f&w,B=Gr(N,H,It,xn[d],G[d]),_=Nr(B,I,S,Rt,gn[d],D[d]),tt=B|0,Bt=K(n,o,28)^Je(n,o,34)^Je(n,o,39),rt=J(n,o,28)^Qe(n,o,34)^Qe(n,o,39),_t=n&s^n&a^s&a,qr=o&i^o&c^i&c;I=x|0,N=w|0,x=h|0,w=g|0,h=p|0,g=f|0,{h:p,l:f}=R(u|0,l|0,_|0,tt|0),u=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let sr=Lr(tt,rt,qr);n=kr(sr,_,Bt,_t),o=sr|0}({h:n,l:o}=R(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=R(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=R(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=R(this.Dh|0,this.Dl|0,u|0,l|0),{h:p,l:f}=R(this.Eh|0,this.El|0,p|0,f|0),{h,l:g}=R(this.Fh|0,this.Fl|0,h|0,g|0),{h:x,l:w}=R(this.Gh|0,this.Gl|0,x|0,w|0),{h:I,l:N}=R(this.Hh|0,this.Hl|0,I|0,N|0),this.set(n,o,s,i,a,c,u,l,p,f,h,g,x,w,I,N)}roundClean(){P(D,G)}destroy(){this.destroyed=!0,P(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},nr=class extends rr{Ah=m[0]|0;Al=m[1]|0;Bh=m[2]|0;Bl=m[3]|0;Ch=m[4]|0;Cl=m[5]|0;Dh=m[6]|0;Dl=m[7]|0;Eh=m[8]|0;El=m[9]|0;Fh=m[10]|0;Fl=m[11]|0;Gh=m[12]|0;Gl=m[13]|0;Hh=m[14]|0;Hl=m[15]|0;constructor(){super(64)}};var $r=Ye(()=>new tr,Kt(1));var jr=Ye(()=>new nr,Kt(3));var zr={sha1:_r,sha256:$r,sha512:jr},mn=Object.freeze(Object.keys(zr)),Ze=class{name="noble";algorithms=mn;hmac(e,r,n){let o=A(e,{supported:this.algorithms,plugin:this.name});return Br(zr[o],r,n)}randomBytes(e){return Ir(e)}constantTimeEqual(e,r){return Dt(e,r)}},se=Object.freeze(new Ze);function Et(t){return{secret:t.secret,strategy:t.strategy??"totp",crypto:t.crypto??se,base32:t.base32??ne,algorithm:t.algorithm??"sha1",digits:t.digits??6,period:t.period??30,epoch:t.epoch??Math.floor(Date.now()/1e3),t0:t.t0??0,counter:t.counter,guardrails:t.guardrails??y(),hooks:t.hooks}}function or(t){return{...Et(t),token:t.token,epochTolerance:t.epochTolerance??0,counterTolerance:t.counterTolerance??0,afterTimeStep:t.afterTimeStep}}function et(t,e,r){if(t==="totp")return r.totp();if(t==="hotp"){if(e===void 0)throw new O("Counter is required for HOTP strategy. Example: { strategy: 'hotp', counter: 0 }");return r.hotp(e)}throw new O(`Unknown OTP strategy: ${t}. Valid strategies are 'totp' or 'hotp'.`)}function Fr(t){let{crypto:e=se,base32:r=ne,length:n=20}=t||{};return v({crypto:e,base32:r,length:n})}function wt(t){let{strategy:e="totp",issuer:r,label:n,secret:o,algorithm:s="sha1",digits:i=6,period:a=30,counter:c}=t;return et(e,c,{totp:()=>Ve({issuer:r,label:n,secret:o,algorithm:s,digits:i,period:a}),hotp:u=>$e({issuer:r,label:n,secret:o,algorithm:s,digits:i,counter:u})})}async function At(t){let e=Et(t),{secret:r,crypto:n,base32:o,algorithm:s,digits:i,hooks:a}=e,c={secret:r,crypto:n,base32:o,algorithm:s,digits:i,hooks:a};return et(e.strategy,e.counter,{totp:()=>qe({...c,period:e.period,epoch:e.epoch,t0:e.t0,guardrails:e.guardrails}),hotp:u=>X({...c,counter:u,guardrails:e.guardrails})})}function Pt(t){let e=Et(t),{secret:r,crypto:n,base32:o,algorithm:s,digits:i}=e,a={secret:r,crypto:n,base32:o,algorithm:s,digits:i};return et(e.strategy,e.counter,{totp:()=>zt({...a,period:e.period,epoch:e.epoch,t0:e.t0,guardrails:e.guardrails}),hotp:c=>ze({...a,counter:c,guardrails:e.guardrails})})}async function St(t){let e=or(t),{secret:r,token:n,crypto:o,base32:s,algorithm:i,digits:a,hooks:c}=e,u={secret:r,token:n,crypto:o,base32:s,algorithm:i,digits:a,hooks:c};return et(e.strategy,e.counter,{totp:()=>pt({...u,period:e.period,epoch:e.epoch,t0:e.t0,epochTolerance:e.epochTolerance,afterTimeStep:e.afterTimeStep,guardrails:e.guardrails}),hotp:l=>lt({...u,counter:l,counterTolerance:e.counterTolerance,guardrails:e.guardrails})})}function Ct(t){let e=or(t),{secret:r,token:n,crypto:o,base32:s,algorithm:i,digits:a,hooks:c}=e,u={secret:r,token:n,crypto:o,base32:s,algorithm:i,digits:a,hooks:c};return et(e.strategy,e.counter,{totp:()=>Pr({...u,period:e.period,epoch:e.epoch,t0:e.t0,epochTolerance:e.epochTolerance,afterTimeStep:e.afterTimeStep,guardrails:e.guardrails}),hotp:l=>Or({...u,counter:l,counterTolerance:e.counterTolerance,guardrails:e.guardrails})})}var Ht=class{strategy;crypto;base32;guardrails;constructor(e={}){let{strategy:r="totp",crypto:n=se,base32:o=ne,guardrails:s}=e;this.strategy=r,this.crypto=n,this.base32=o,this.guardrails=y(s)}getStrategy(){return this.strategy}generateSecret(e=20){return v({crypto:this.crypto,base32:this.base32,length:e})}async generate(e){return At({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}generateSync(e){return Pt({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}async verify(e){return St({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}verifySync(e){return Ct({...e,strategy:this.strategy,crypto:this.crypto,base32:this.base32,guardrails:e.guardrails??this.guardrails})}generateURI(e){return wt({...e,strategy:this.strategy})}};return Qr(yn);})();
/*! Bundled license information:
@scure/base/index.js:
(*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
*/
//# sourceMappingURL=index.global.js.map