"use strict";var P=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var k=(o,e)=>{for(var t in e)P(o,t,{get:e[t],enumerable:!0})},A=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of w(e))!D.call(o,n)&&n!==t&&P(o,n,{get:()=>e[n],enumerable:!(i=I(e,n))||i.enumerable});return o};var H=o=>A(P({},"__esModule",{value:!0}),o);var L={};k(L,{TOTP:()=>f,generate:()=>O,generateSync:()=>G,getRemainingTime:()=>E,getTimeStepUsed:()=>U,verify:()=>b,verifySync:()=>B,wrapResult:()=>d.wrapResult,wrapResultAsync:()=>d.wrapResultAsync});module.exports=H(L);var r=require("@otplib/core"),y=require("@otplib/hotp");var u=require("@otplib/core"),C=require("@otplib/uri");var f=class{options;guardrails;constructor(e={}){this.options=e,this.guardrails=(0,u.createGuardrails)(e.guardrails)}generateSecret(){let{crypto:e,base32:t}=this.options;return(0,u.requireCryptoPlugin)(e),(0,u.requireBase32Plugin)(t),(0,u.generateSecret)({crypto:e,base32:t})}async generate(e){let t={...this.options,...e},{secret:i,crypto:n,base32:a,algorithm:p="sha1",digits:T=6,period:l=30,epoch:s,t0:c=0}=t;(0,u.requireSecret)(i),(0,u.requireCryptoPlugin)(n),(0,u.requireBase32Plugin)(a);let g=e?.guardrails??this.guardrails;return O({secret:i,algorithm:p,digits:T,period:l,epoch:s??Math.floor(Date.now()/1e3),t0:c,crypto:n,base32:a,guardrails:g})}async verify(e,t){let i={...this.options,...t},{secret:n,crypto:a,base32:p,algorithm:T="sha1",digits:l=6,period:s=30,epoch:c,t0:g=0,epochTolerance:m=0}=i;(0,u.requireSecret)(n),(0,u.requireCryptoPlugin)(a),(0,u.requireBase32Plugin)(p);let h=t?.guardrails??this.guardrails;return b({secret:n,token:e,algorithm:T,digits:l,period:s,epoch:c??Math.floor(Date.now()/1e3),t0:g,epochTolerance:m,crypto:a,base32:p,guardrails:h})}toURI(e){let{issuer:t,label:i,secret:n,algorithm:a="sha1",digits:p=6,period:T=30}=this.options,l=e?.label??i,s=e?.issuer??t,c=e?.secret??n;return(0,u.requireSecret)(c),(0,u.requireLabel)(l),(0,u.requireIssuer)(s),(0,u.requireBase32String)(c),(0,C.generateTOTP)({issuer:s,label:l,secret:c,algorithm:a,digits:p,period:T})}};var d=require("@otplib/core");function x(o){let{secret:e,epoch:t=Math.floor(Date.now()/1e3),t0:i=0,period:n=30,algorithm:a="sha1",digits:p=6,crypto:T,base32:l,guardrails:s=(0,r.createGuardrails)()}=o;(0,r.requireSecret)(e),(0,r.requireCryptoPlugin)(T);let c=(0,r.normalizeSecret)(e,l);(0,r.validateSecret)(c,s),(0,r.validateTime)(t),(0,r.validatePeriod)(n,s);let g=Math.floor((t-i)/n);return{secret:c,counter:g,algorithm:a,digits:p,crypto:T,guardrails:s}}async function O(o){let e=x(o);return(0,y.generate)(e)}function G(o){let e=x(o);return(0,y.generateSync)(e)}function V(o){let{secret:e,token:t,epoch:i=Math.floor(Date.now()/1e3),t0:n=0,period:a=30,algorithm:p="sha1",digits:T=6,crypto:l,base32:s,epochTolerance:c=0,guardrails:g=(0,r.createGuardrails)()}=o;(0,r.requireSecret)(e),(0,r.requireCryptoPlugin)(l);let m=(0,r.normalizeSecret)(e,s);(0,r.validateSecret)(m,g),(0,r.validateTime)(i),(0,r.validatePeriod)(a,g),(0,r.validateToken)(t,T),(0,r.validateEpochTolerance)(c,a,g);let h=Math.floor((i-n)/a),[v,S]=(0,r.normalizeEpochTolerance)(c),R=Math.max(0,Math.floor((i-v-n)/a)),M=Math.floor((i+S-n)/a);return{token:t,crypto:l,minCounter:R,maxCounter:M,currentCounter:h,t0:n,period:a,getGenerateOptions:q=>({secret:m,epoch:q*a+n,t0:n,period:a,algorithm:p,digits:T,crypto:l,guardrails:g})}}async function b(o){let{token:e,crypto:t,minCounter:i,maxCounter:n,currentCounter:a,t0:p,period:T,getGenerateOptions:l}=V(o);for(let s=i;s<=n;s++){let c=await O(l(s));if(t.constantTimeEqual(c,e))return{valid:!0,delta:s-a,epoch:s*T+p}}return{valid:!1}}function B(o){let{token:e,crypto:t,minCounter:i,maxCounter:n,currentCounter:a,t0:p,period:T,getGenerateOptions:l}=V(o);for(let s=i;s<=n;s++){let c=G(l(s));if(t.constantTimeEqual(c,e))return{valid:!0,delta:s-a,epoch:s*T+p}}return{valid:!1}}function E(o=Math.floor(Date.now()/1e3),e=30,t=0,i=(0,r.createGuardrails)()){return(0,r.validateTime)(o),(0,r.validatePeriod)(e,i),(Math.floor((o-t)/e)+1)*e+t-o}function U(o=Math.floor(Date.now()/1e3),e=30,t=0,i=(0,r.createGuardrails)()){return(0,r.validateTime)(o),(0,r.validatePeriod)(e,i),Math.floor((o-t)/e)}0&&(module.exports={TOTP,generate,generateSync,getRemainingTime,getTimeStepUsed,verify,verifySync,wrapResult,wrapResultAsync});
//# sourceMappingURL=index.cjs.map