"use strict";var m=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var U=(t,e)=>{for(var s in e)m(t,s,{get:e[s],enumerable:!0})},R=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of b(e))!x.call(t,i)&&i!==s&&m(t,i,{get:()=>e[i],enumerable:!(r=T(e,i))||r.enumerable});return t};var A=t=>R(m({},"__esModule",{value:!0}),t);var v={};U(v,{InvalidParameterError:()=>c,InvalidURIError:()=>a,MissingParameterError:()=>u,URIParseError:()=>l,generate:()=>h,generateHOTP:()=>O,generateTOTP:()=>y,parse:()=>d,parseURI:()=>d});module.exports=A(v);var l=class extends Error{constructor(e){super(e),this.name="URIParseError"}},a=class extends l{constructor(e){super(`Invalid otpauth URI: ${e}`),this.name="InvalidURIError"}},u=class extends l{constructor(e){super(`Missing required parameter: ${e}`),this.name="MissingParameterError"}},c=class extends l{constructor(e,s){super(`Invalid value for parameter '${e}': ${s}`),this.name="InvalidParameterError"}};var f=2048,I=512,w=1024;function $(t,e){let s=t instanceof Error?t.message:String(t);return`Invalid URI encoding in ${e}: ${s}`}function g(t,e,s){if(t.length>e*3)throw new a(`${s} exceeds maximum length`);try{let r=decodeURIComponent(t);if(r.length>e)throw new a(`${s} exceeds maximum length of ${e} characters`);return r}catch(r){throw r instanceof a?r:new a($(r,s))}}function d(t){if(t.length>f)throw new a(`URI exceeds maximum length of ${f} characters`);if(!t.startsWith("otpauth://"))throw new a(t);let e=t.slice(10),s=e.indexOf("/");if(s===-1)throw new a(t);let r=e.slice(0,s);if(r!=="hotp"&&r!=="totp")throw new c("type",r);let i=e.slice(s+1),o=i.indexOf("?"),n,p;o===-1?(n=g(i,I,"label"),p=""):(n=g(i.slice(0,o),I,"label"),p=i.slice(o+1));let P=H(p);return{type:r,label:n,params:P}}function H(t){let e={};if(!t)return e;let s=t.split("&");for(let r of s){let i=r.indexOf("=");if(i===-1)continue;let o=g(r.slice(0,i),64,"parameter key"),n=g(r.slice(i+1),w,`parameter '${o}'`);switch(o){case"secret":e.secret=n;break;case"issuer":e.issuer=n;break;case"algorithm":e.algorithm=E(n);break;case"digits":e.digits=k(n);break;case"counter":e.counter=parseInt(n,10);break;case"period":e.period=parseInt(n,10);break}}return e}function E(t){let e=t.toLowerCase();if(e==="sha1"||e==="sha-1")return"sha1";if(e==="sha256"||e==="sha-256")return"sha256";if(e==="sha512"||e==="sha-512")return"sha512";throw new c("algorithm",t)}function k(t){let e=parseInt(t,10);if(e===6||e===7||e===8)return e;throw new c("digits",t)}function h(t){let{type:e,label:s,params:r}=t,i=s.split(":").map(p=>encodeURIComponent(p)).join(":"),o=`otpauth://${e}/${i}?`,n=[];return r.secret&&n.push(`secret=${r.secret}`),r.issuer&&n.push(`issuer=${encodeURIComponent(r.issuer)}`),r.algorithm&&r.algorithm!=="sha1"&&n.push(`algorithm=${r.algorithm.toUpperCase()}`),r.digits&&r.digits!==6&&n.push(`digits=${r.digits}`),e==="hotp"&&r.counter!==void 0&&n.push(`counter=${r.counter}`),e==="totp"&&r.period!==void 0&&r.period!==30&&n.push(`period=${r.period}`),o+=n.join("&"),o}function y(t){let{issuer:e,label:s,secret:r,algorithm:i="sha1",digits:o=6,period:n=30}=t,p=e?`${e}:${s}`:s;return h({type:"totp",label:p,params:{secret:r,issuer:e,algorithm:i,digits:o,period:n}})}function O(t){let{issuer:e,label:s,secret:r,counter:i=0,algorithm:o="sha1",digits:n=6}=t,p=e?`${e}:${s}`:s;return h({type:"hotp",label:p,params:{secret:r,issuer:e,algorithm:o,digits:n,counter:i}})}0&&(module.exports={InvalidParameterError,InvalidURIError,MissingParameterError,URIParseError,generate,generateHOTP,generateTOTP,parse,parseURI});
//# sourceMappingURL=index.cjs.map