@vitia.ai/secure-api-client-vue 1.0.21 → 1.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +130 -130
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function lt(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function zr(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function Ve(n,...e){if(!lt(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}const ut=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yr=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function ht(n){if(Ve(n),ut)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=Yr[n[t]];return e}const L={_0:48,_9:57,A:65,F:70,a:97,f:102};function ze(n){if(n>=L._0&&n<=L._9)return n-L._0;if(n>=L.A&&n<=L.F)return n-(L.A-10);if(n>=L.a&&n<=L.f)return n-(L.a-10)}function ft(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(ut)return Uint8Array.fromHex(n);const e=n.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){const o=ze(n.charCodeAt(i)),a=ze(n.charCodeAt(i+1));if(o===void 0||a===void 0){const c=n[i]+n[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}r[s]=o*16+a}return r}function Qr(n=32){if(z&&typeof z.getRandomValues=="function")return z.getRandomValues(new Uint8Array(n));if(z&&typeof z.randomBytes=="function")return Uint8Array.from(z.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dt=BigInt(0),Ye=BigInt(1);function gt(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?dt:BigInt("0x"+n)}function es(n){return gt(ht(n))}function Ee(n){return Ve(n),gt(ht(Uint8Array.from(n).reverse()))}function wt(n,e){return ft(n.toString(16).padStart(e*2,"0"))}function yt(n,e){return wt(n,e).reverse()}function Qe(n,e,t){let r;if(typeof e=="string")try{r=ft(e)}catch(i){throw new Error(n+" must be hex string or Uint8Array, cause: "+i)}else if(lt(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");const s=r.length;if(typeof t=="number"&&s!==t)throw new Error(n+" of length "+t+" expected, got "+s);return r}const Se=n=>typeof n=="bigint"&&dt<=n;function ts(n,e,t){return Se(n)&&Se(e)&&Se(t)&&e<=n&&n<t}function et(n,e,t,r){if(!ts(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}const rs=n=>(Ye<<BigInt(n))-Ye;function ss(n,e,t={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(s,i,o){const a=n[s];if(o&&a===void 0)return;const c=typeof a;if(c!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([s,i])=>r(s,i,!1)),Object.entries(t).forEach(([s,i])=>r(s,i,!0))}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const S=BigInt(0),E=BigInt(1),G=BigInt(2),Bt=BigInt(3),bt=BigInt(4),mt=BigInt(5),ns=BigInt(7),vt=BigInt(8),is=BigInt(9),kt=BigInt(16);function I(n,e){const t=n%e;return t>=S?t:e+t}function T(n,e,t){let r=n;for(;e-- >S;)r*=r,r%=t;return r}function tt(n,e){if(n===S)throw new Error("invert: expected non-zero number");if(e<=S)throw new Error("invert: expected positive modulus, got "+e);let t=I(n,e),r=e,s=S,i=E;for(;t!==S;){const a=r/t,c=r%t,l=s-i*a;r=t,t=c,s=i,i=l}if(r!==E)throw new Error("invert: does not exist");return I(s,e)}function _e(n,e,t){if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function At(n,e){const t=(n.ORDER+E)/bt,r=n.pow(e,t);return _e(n,r,e),r}function os(n,e){const t=(n.ORDER-mt)/vt,r=n.mul(e,G),s=n.pow(r,t),i=n.mul(e,s),o=n.mul(n.mul(i,G),s),a=n.mul(i,n.sub(o,n.ONE));return _e(n,a,e),a}function cs(n){const e=Ce(n),t=St(n),r=t(e,e.neg(e.ONE)),s=t(e,r),i=t(e,e.neg(r)),o=(n+ns)/kt;return(a,c)=>{let l=a.pow(c,o),f=a.mul(l,r);const h=a.mul(l,s),u=a.mul(l,i),g=a.eql(a.sqr(f),c),w=a.eql(a.sqr(h),c);l=a.cmov(l,f,g),f=a.cmov(u,h,w);const m=a.eql(a.sqr(f),c),y=a.cmov(l,f,m);return _e(a,y,c),y}}function St(n){if(n<Bt)throw new Error("sqrt is not defined for small field");let e=n-E,t=0;for(;e%G===S;)e/=G,t++;let r=G;const s=Ce(n);for(;rt(s,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return At;let i=s.pow(r,e);const o=(e+E)/G;return function(c,l){if(c.is0(l))return l;if(rt(c,l)!==1)throw new Error("Cannot find square root");let f=t,h=c.mul(c.ONE,i),u=c.pow(l,e),g=c.pow(l,o);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let w=1,m=c.sqr(u);for(;!c.eql(m,c.ONE);)if(w++,m=c.sqr(m),w===f)throw new Error("Cannot find square root");const y=E<<BigInt(f-w-1),C=c.pow(h,y);f=w,h=c.sqr(C),u=c.mul(u,h),g=c.mul(g,C)}return g}}function as(n){return n%bt===Bt?At:n%vt===mt?os:n%kt===is?cs(n):St(n)}function ls(n,e,t){if(t<S)throw new Error("invalid exponent, negatives unsupported");if(t===S)return n.ONE;if(t===E)return e;let r=n.ONE,s=e;for(;t>S;)t&E&&(r=n.mul(r,s)),s=n.sqr(s),t>>=E;return r}function us(n,e,t=!1){const r=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((o,a,c)=>n.is0(a)?o:(r[c]=o,n.mul(o,a)),n.ONE),i=n.inv(s);return e.reduceRight((o,a,c)=>n.is0(a)?o:(r[c]=n.mul(o,r[c]),n.mul(o,a)),i),r}function rt(n,e){const t=(n.ORDER-E)/G,r=n.pow(e,t),s=n.eql(r,n.ONE),i=n.eql(r,n.ZERO),o=n.eql(r,n.neg(n.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function hs(n,e){e!==void 0&&zr(e);const t=e!==void 0?e:n.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function Ce(n,e,t=!1,r={}){if(n<=S)throw new Error("invalid field: expected ORDER > 0, got "+n);let s,i,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||t)throw new Error("cannot specify opts in two arguments");const u=e;u.BITS&&(s=u.BITS),u.sqrt&&(i=u.sqrt),typeof u.isLE=="boolean"&&(t=u.isLE),typeof u.modFromBytes=="boolean"&&(o=u.modFromBytes),a=u.allowedLengths}else typeof e=="number"&&(s=e),r.sqrt&&(i=r.sqrt);const{nBitLength:c,nByteLength:l}=hs(n,s);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const h=Object.freeze({ORDER:n,isLE:t,BITS:c,BYTES:l,MASK:rs(c),ZERO:S,ONE:E,allowedLengths:a,create:u=>I(u,n),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return S<=u&&u<n},is0:u=>u===S,isValidNot0:u=>!h.is0(u)&&h.isValid(u),isOdd:u=>(u&E)===E,neg:u=>I(-u,n),eql:(u,g)=>u===g,sqr:u=>I(u*u,n),add:(u,g)=>I(u+g,n),sub:(u,g)=>I(u-g,n),mul:(u,g)=>I(u*g,n),pow:(u,g)=>ls(h,u,g),div:(u,g)=>I(u*tt(g,n),n),sqrN:u=>u*u,addN:(u,g)=>u+g,subN:(u,g)=>u-g,mulN:(u,g)=>u*g,inv:u=>tt(u,n),sqrt:i||(u=>(f||(f=as(n)),f(h,u))),toBytes:u=>t?yt(u,l):wt(u,l),fromBytes:(u,g=!0)=>{if(a){if(!a.includes(u.length)||u.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);const m=new Uint8Array(l);m.set(u,t?0:m.length-u.length),u=m}if(u.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+u.length);let w=t?Ee(u):es(u);if(o&&(w=I(w,n)),!g&&!h.isValid(w))throw new Error("invalid field element: outside of range 0..ORDER");return w},invertBatch:u=>us(h,u),cmov:(u,g,w)=>w?g:u});return Object.freeze(h)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ie=BigInt(0),Y=BigInt(1),ge=BigInt(2);function fs(n){return ss(n,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...n})}function ds(n){const e=fs(n),{P:t,type:r,adjustScalarBytes:s,powPminus2:i,randomBytes:o}=e,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=o||Qr,l=a?255:448,f=a?32:56,h=BigInt(a?9:5),u=BigInt(a?121665:39081),g=a?ge**BigInt(254):ge**BigInt(447),w=a?BigInt(8)*ge**BigInt(251)-Y:BigInt(4)*ge**BigInt(445)-Y,m=g+w+Y,y=b=>I(b,t),C=X(h);function X(b){return yt(y(b),f)}function re(b){const k=Qe("u coordinate",b,f);return a&&(k[31]&=127),y(Ee(k))}function se(b){return Ee(s(Qe("scalar",b,f)))}function U(b,k){const H=be(re(k),se(b));if(H===ie)throw new Error("invalid private or public key received");return X(H)}function O(b){return U(b,C)}function D(b,k,H){const de=y(b*(k-H));return k=y(k-de),H=y(H+de),{x_2:k,x_3:H}}function be(b,k){et("u",b,ie,t),et("scalar",k,g,m);const H=k,de=b;let $=Y,P=ie,j=b,q=Y,Z=ie;for(let me=BigInt(l-1);me>=ie;me--){const qe=H>>me&Y;Z^=qe,{x_2:$,x_3:j}=D(Z,$,j),{x_2:P,x_3:q}=D(Z,P,q),Z=qe;const ve=$+P,ke=y(ve*ve),Ae=$-P,Ge=y(Ae*Ae),Je=ke-Ge,Xr=j+q,Zr=j-q,Ke=y(Zr*ve),We=y(Xr*Ae),Xe=Ke+We,Ze=Ke-We;j=y(Xe*Xe),q=y(de*y(Ze*Ze)),$=y(ke*Ge),P=y(Je*(ke+y(u*Je)))}({x_2:$,x_3:j}=D(Z,$,j)),{x_2:P,x_3:q}=D(Z,P,q);const Wr=i(P);return y($*Wr)}const fe={secretKey:f,publicKey:f,seed:f},ne=(b=c(f))=>(Ve(b,fe.seed),b);function Kr(b){const k=ne(b);return{secretKey:k,publicKey:O(k)}}return{keygen:Kr,getSharedSecret:(b,k)=>U(b,k),getPublicKey:b=>O(b),scalarMult:U,scalarMultBase:O,utils:{randomSecretKey:ne,randomPrivateKey:ne},GuBytes:C.slice(),lengths:fe}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const gs=BigInt(1),st=BigInt(2),ws=BigInt(3),ys=BigInt(5),Bs=BigInt(8),xt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),bs={p:xt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Bs,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ms(n){const e=BigInt(10),t=BigInt(20),r=BigInt(40),s=BigInt(80),i=xt,a=n*n%i*n%i,c=T(a,st,i)*a%i,l=T(c,gs,i)*n%i,f=T(l,ys,i)*l%i,h=T(f,e,i)*f%i,u=T(h,t,i)*h%i,g=T(u,r,i)*u%i,w=T(g,s,i)*g%i,m=T(w,s,i)*g%i,y=T(m,e,i)*f%i;return{pow_p_5_8:T(y,st,i)*n%i,b2:a}}function vs(n){return n[0]&=248,n[31]&=127,n[31]|=64,n}const ks=Ce(bs.p,{isLE:!0}),xe=(()=>{const n=ks.ORDER;return ds({P:n,type:"x25519",powPminus2:e=>{const{pow_p_5_8:t,b2:r}=ms(e);return I(T(t,ws,n)*r,n)},adjustScalarBytes:vs})})();/*!
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */function lt(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function zr(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function Ve(n,...e){if(!lt(n))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(n.length))throw new Error("Uint8Array expected of length "+e+", got length="+n.length)}const ut=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yr=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function ht(n){if(Ve(n),ut)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=Yr[n[t]];return e}const R={_0:48,_9:57,A:65,F:70,a:97,f:102};function ze(n){if(n>=R._0&&n<=R._9)return n-R._0;if(n>=R.A&&n<=R.F)return n-(R.A-10);if(n>=R.a&&n<=R.f)return n-(R.a-10)}function ft(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(ut)return Uint8Array.fromHex(n);const e=n.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(t);for(let s=0,i=0;s<t;s++,i+=2){const o=ze(n.charCodeAt(i)),a=ze(n.charCodeAt(i+1));if(o===void 0||a===void 0){const c=n[i]+n[i+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+i)}r[s]=o*16+a}return r}function Qr(n=32){if(z&&typeof z.getRandomValues=="function")return z.getRandomValues(new Uint8Array(n));if(z&&typeof z.randomBytes=="function")return Uint8Array.from(z.randomBytes(n));throw new Error("crypto.getRandomValues must be defined")}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const dt=BigInt(0),Ye=BigInt(1);function gt(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?dt:BigInt("0x"+n)}function es(n){return gt(ht(n))}function Ee(n){return Ve(n),gt(ht(Uint8Array.from(n).reverse()))}function wt(n,e){return ft(n.toString(16).padStart(e*2,"0"))}function yt(n,e){return wt(n,e).reverse()}function Qe(n,e,t){let r;if(typeof e=="string")try{r=ft(e)}catch(i){throw new Error(n+" must be hex string or Uint8Array, cause: "+i)}else if(lt(e))r=Uint8Array.from(e);else throw new Error(n+" must be hex string or Uint8Array");const s=r.length;if(typeof t=="number"&&s!==t)throw new Error(n+" of length "+t+" expected, got "+s);return r}const Se=n=>typeof n=="bigint"&&dt<=n;function ts(n,e,t){return Se(n)&&Se(e)&&Se(t)&&e<=n&&n<t}function et(n,e,t,r){if(!ts(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}const rs=n=>(Ye<<BigInt(n))-Ye;function ss(n,e,t={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(s,i,o){const a=n[s];if(o&&a===void 0)return;const c=typeof a;if(c!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${c}`)}Object.entries(e).forEach(([s,i])=>r(s,i,!1)),Object.entries(t).forEach(([s,i])=>r(s,i,!0))}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const S=BigInt(0),E=BigInt(1),G=BigInt(2),Bt=BigInt(3),bt=BigInt(4),vt=BigInt(5),ns=BigInt(7),mt=BigInt(8),is=BigInt(9),kt=BigInt(16);function I(n,e){const t=n%e;return t>=S?t:e+t}function T(n,e,t){let r=n;for(;e-- >S;)r*=r,r%=t;return r}function tt(n,e){if(n===S)throw new Error("invert: expected non-zero number");if(e<=S)throw new Error("invert: expected positive modulus, got "+e);let t=I(n,e),r=e,s=S,i=E;for(;t!==S;){const a=r/t,c=r%t,l=s-i*a;r=t,t=c,s=i,i=l}if(r!==E)throw new Error("invert: does not exist");return I(s,e)}function _e(n,e,t){if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function At(n,e){const t=(n.ORDER+E)/bt,r=n.pow(e,t);return _e(n,r,e),r}function os(n,e){const t=(n.ORDER-vt)/mt,r=n.mul(e,G),s=n.pow(r,t),i=n.mul(e,s),o=n.mul(n.mul(i,G),s),a=n.mul(i,n.sub(o,n.ONE));return _e(n,a,e),a}function cs(n){const e=Ce(n),t=St(n),r=t(e,e.neg(e.ONE)),s=t(e,r),i=t(e,e.neg(r)),o=(n+ns)/kt;return(a,c)=>{let l=a.pow(c,o),f=a.mul(l,r);const h=a.mul(l,s),u=a.mul(l,i),g=a.eql(a.sqr(f),c),w=a.eql(a.sqr(h),c);l=a.cmov(l,f,g),f=a.cmov(u,h,w);const v=a.eql(a.sqr(f),c),y=a.cmov(l,f,v);return _e(a,y,c),y}}function St(n){if(n<Bt)throw new Error("sqrt is not defined for small field");let e=n-E,t=0;for(;e%G===S;)e/=G,t++;let r=G;const s=Ce(n);for(;rt(s,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return At;let i=s.pow(r,e);const o=(e+E)/G;return function(c,l){if(c.is0(l))return l;if(rt(c,l)!==1)throw new Error("Cannot find square root");let f=t,h=c.mul(c.ONE,i),u=c.pow(l,e),g=c.pow(l,o);for(;!c.eql(u,c.ONE);){if(c.is0(u))return c.ZERO;let w=1,v=c.sqr(u);for(;!c.eql(v,c.ONE);)if(w++,v=c.sqr(v),w===f)throw new Error("Cannot find square root");const y=E<<BigInt(f-w-1),C=c.pow(h,y);f=w,h=c.sqr(C),u=c.mul(u,h),g=c.mul(g,C)}return g}}function as(n){return n%bt===Bt?At:n%mt===vt?os:n%kt===is?cs(n):St(n)}function ls(n,e,t){if(t<S)throw new Error("invalid exponent, negatives unsupported");if(t===S)return n.ONE;if(t===E)return e;let r=n.ONE,s=e;for(;t>S;)t&E&&(r=n.mul(r,s)),s=n.sqr(s),t>>=E;return r}function us(n,e,t=!1){const r=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((o,a,c)=>n.is0(a)?o:(r[c]=o,n.mul(o,a)),n.ONE),i=n.inv(s);return e.reduceRight((o,a,c)=>n.is0(a)?o:(r[c]=n.mul(o,r[c]),n.mul(o,a)),i),r}function rt(n,e){const t=(n.ORDER-E)/G,r=n.pow(e,t),s=n.eql(r,n.ONE),i=n.eql(r,n.ZERO),o=n.eql(r,n.neg(n.ONE));if(!s&&!i&&!o)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function hs(n,e){e!==void 0&&zr(e);const t=e!==void 0?e:n.toString(2).length,r=Math.ceil(t/8);return{nBitLength:t,nByteLength:r}}function Ce(n,e,t=!1,r={}){if(n<=S)throw new Error("invalid field: expected ORDER > 0, got "+n);let s,i,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||t)throw new Error("cannot specify opts in two arguments");const u=e;u.BITS&&(s=u.BITS),u.sqrt&&(i=u.sqrt),typeof u.isLE=="boolean"&&(t=u.isLE),typeof u.modFromBytes=="boolean"&&(o=u.modFromBytes),a=u.allowedLengths}else typeof e=="number"&&(s=e),r.sqrt&&(i=r.sqrt);const{nBitLength:c,nByteLength:l}=hs(n,s);if(l>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const h=Object.freeze({ORDER:n,isLE:t,BITS:c,BYTES:l,MASK:rs(c),ZERO:S,ONE:E,allowedLengths:a,create:u=>I(u,n),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return S<=u&&u<n},is0:u=>u===S,isValidNot0:u=>!h.is0(u)&&h.isValid(u),isOdd:u=>(u&E)===E,neg:u=>I(-u,n),eql:(u,g)=>u===g,sqr:u=>I(u*u,n),add:(u,g)=>I(u+g,n),sub:(u,g)=>I(u-g,n),mul:(u,g)=>I(u*g,n),pow:(u,g)=>ls(h,u,g),div:(u,g)=>I(u*tt(g,n),n),sqrN:u=>u*u,addN:(u,g)=>u+g,subN:(u,g)=>u-g,mulN:(u,g)=>u*g,inv:u=>tt(u,n),sqrt:i||(u=>(f||(f=as(n)),f(h,u))),toBytes:u=>t?yt(u,l):wt(u,l),fromBytes:(u,g=!0)=>{if(a){if(!a.includes(u.length)||u.length>l)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+u.length);const v=new Uint8Array(l);v.set(u,t?0:v.length-u.length),u=v}if(u.length!==l)throw new Error("Field.fromBytes: expected "+l+" bytes, got "+u.length);let w=t?Ee(u):es(u);if(o&&(w=I(w,n)),!g&&!h.isValid(w))throw new Error("invalid field element: outside of range 0..ORDER");return w},invertBatch:u=>us(h,u),cmov:(u,g,w)=>w?g:u});return Object.freeze(h)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ie=BigInt(0),Y=BigInt(1),ge=BigInt(2);function fs(n){return ss(n,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...n})}function ds(n){const e=fs(n),{P:t,type:r,adjustScalarBytes:s,powPminus2:i,randomBytes:o}=e,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=o||Qr,l=a?255:448,f=a?32:56,h=BigInt(a?9:5),u=BigInt(a?121665:39081),g=a?ge**BigInt(254):ge**BigInt(447),w=a?BigInt(8)*ge**BigInt(251)-Y:BigInt(4)*ge**BigInt(445)-Y,v=g+w+Y,y=b=>I(b,t),C=X(h);function X(b){return yt(y(b),f)}function re(b){const k=Qe("u coordinate",b,f);return a&&(k[31]&=127),y(Ee(k))}function se(b){return Ee(s(Qe("scalar",b,f)))}function U(b,k){const H=be(re(k),se(b));if(H===ie)throw new Error("invalid private or public key received");return X(H)}function O(b){return U(b,C)}function D(b,k,H){const de=y(b*(k-H));return k=y(k-de),H=y(H+de),{x_2:k,x_3:H}}function be(b,k){et("u",b,ie,t),et("scalar",k,g,v);const H=k,de=b;let $=Y,P=ie,j=b,q=Y,Z=ie;for(let ve=BigInt(l-1);ve>=ie;ve--){const qe=H>>ve&Y;Z^=qe,{x_2:$,x_3:j}=D(Z,$,j),{x_2:P,x_3:q}=D(Z,P,q),Z=qe;const me=$+P,ke=y(me*me),Ae=$-P,Ge=y(Ae*Ae),Je=ke-Ge,Xr=j+q,Zr=j-q,Ke=y(Zr*me),We=y(Xr*Ae),Xe=Ke+We,Ze=Ke-We;j=y(Xe*Xe),q=y(de*y(Ze*Ze)),$=y(ke*Ge),P=y(Je*(ke+y(u*Je)))}({x_2:$,x_3:j}=D(Z,$,j)),{x_2:P,x_3:q}=D(Z,P,q);const Wr=i(P);return y($*Wr)}const fe={secretKey:f,publicKey:f,seed:f},ne=(b=c(f))=>(Ve(b,fe.seed),b);function Kr(b){const k=ne(b);return{secretKey:k,publicKey:O(k)}}return{keygen:Kr,getSharedSecret:(b,k)=>U(b,k),getPublicKey:b=>O(b),scalarMult:U,scalarMultBase:O,utils:{randomSecretKey:ne,randomPrivateKey:ne},GuBytes:C.slice(),lengths:fe}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const gs=BigInt(1),st=BigInt(2),ws=BigInt(3),ys=BigInt(5),Bs=BigInt(8),xt=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),bs={p:xt,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Bs,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function vs(n){const e=BigInt(10),t=BigInt(20),r=BigInt(40),s=BigInt(80),i=xt,a=n*n%i*n%i,c=T(a,st,i)*a%i,l=T(c,gs,i)*n%i,f=T(l,ys,i)*l%i,h=T(f,e,i)*f%i,u=T(h,t,i)*h%i,g=T(u,r,i)*u%i,w=T(g,s,i)*g%i,v=T(w,s,i)*g%i,y=T(v,e,i)*f%i;return{pow_p_5_8:T(y,st,i)*n%i,b2:a}}function ms(n){return n[0]&=248,n[31]&=127,n[31]|=64,n}const ks=Ce(bs.p,{isLE:!0}),xe=(()=>{const n=ks.ORDER;return ds({P:n,type:"x25519",powPminus2:e=>{const{pow_p_5_8:t,b2:r}=vs(e);return I(T(t,ws,n)*r,n)},adjustScalarBytes:ms})})();/*!
|
|
2
2
|
* MIT License
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*
|
|
24
|
-
*/const As="[object ArrayBuffer]";class B{static isArrayBuffer(e){return Object.prototype.toString.call(e)===As}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){const r=B.toUint8Array(e),s=B.toUint8Array(t);if(r.length!==s.byteLength)return!1;for(let i=0;i<r.length;i++)if(r[i]!==s[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let r=0;for(const o of t)r+=o.byteLength;const s=new Uint8Array(r);let i=0;for(const o of t){const a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}}const pe="string",Ss=/^[0-9a-f\s]+$/i,xs=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ps=/^[a-zA-Z0-9-_]+$/;class nt{static fromString(e){const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r.buffer}static toString(e){const t=B.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return decodeURIComponent(escape(r))}}class V{static toString(e,t=!1){const r=B.toArrayBuffer(e),s=new DataView(r);let i="";for(let o=0;o<r.byteLength;o+=2){const a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){const r=new ArrayBuffer(e.length*2),s=new DataView(r);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return r}}class
|
|
24
|
+
*/const As="[object ArrayBuffer]";class B{static isArrayBuffer(e){return Object.prototype.toString.call(e)===As}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){const r=B.toUint8Array(e),s=B.toUint8Array(t);if(r.length!==s.byteLength)return!1;for(let i=0;i<r.length;i++)if(r[i]!==s[i])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let r=0;for(const o of t)r+=o.byteLength;const s=new Uint8Array(r);let i=0;for(const o of t){const a=this.toUint8Array(o);s.set(a,i),i+=a.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}}const pe="string",Ss=/^[0-9a-f\s]+$/i,xs=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ps=/^[a-zA-Z0-9-_]+$/;class nt{static fromString(e){const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r.buffer}static toString(e){const t=B.toUint8Array(e);let r="";for(let i=0;i<t.length;i++)r+=String.fromCharCode(t[i]);return decodeURIComponent(escape(r))}}class V{static toString(e,t=!1){const r=B.toArrayBuffer(e),s=new DataView(r);let i="";for(let o=0;o<r.byteLength;o+=2){const a=s.getUint16(o,t);i+=String.fromCharCode(a)}return i}static fromString(e,t=!1){const r=new ArrayBuffer(e.length*2),s=new DataView(r);for(let i=0;i<e.length;i++)s.setUint16(i*2,e.charCodeAt(i),t);return r}}class m{static isHex(e){return typeof e===pe&&Ss.test(e)}static isBase64(e){return typeof e===pe&&xs.test(e)}static isBase64Url(e){return typeof e===pe&&ps.test(e)}static ToString(e,t="utf8"){const r=B.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return V.toString(r,!0);case"utf16":case"utf16be":return V.toString(r);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return V.fromString(e,!0);case"utf16":case"utf16be":return V.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=B.toUint8Array(e);if(typeof btoa<"u"){const r=this.ToString(t,"binary");return btoa(r)}else return Buffer.from(t).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!m.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!m.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=m.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return nt.fromString(e);case"utf16":case"utf16be":return V.fromString(e);case"utf16le":case"usc2":return V.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=m.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return nt.toString(e);case"utf16":case"utf16be":return V.toString(e);case"utf16le":case"usc2":return V.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,r=new Uint8Array(t);for(let s=0;s<t;s++)r[s]=e.charCodeAt(s);return r.buffer}static ToBinary(e){const t=B.toUint8Array(e);let r="";for(let s=0;s<t.length;s++)r+=String.fromCharCode(t[s]);return r}static ToHex(e){const t=B.toUint8Array(e);let r="";const s=t.length;for(let i=0;i<s;i++){const o=t[i];o<16&&(r+="0"),r+=o.toString(16)}return r}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!m.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const r=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){const i=t.slice(s,s+2);r[s/2]=parseInt(i,16)}return r.buffer}static ToUtf16String(e,t=!1){return V.toString(e,t)}static FromUtf16String(e,t=!1){return V.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let r=0;r<t;r++)e+="=";return e}static formatString(e){return(e==null?void 0:e.replace(/[\n\r\t ]/g,""))||""}}m.DEFAULT_UTF8_ENCODING="utf8";/*!
|
|
25
25
|
Copyright (c) Peculiar Ventures, LLC
|
|
26
26
|
*/function Q(n,e){let t=0;if(n.length===1)return n[0];for(let r=n.length-1;r>=0;r--)t+=n[n.length-1-r]*Math.pow(2,e*r);return t}function J(n,e,t=-1){const r=t;let s=n,i=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(n<o){let c;if(r<0)c=new ArrayBuffer(a),i=a;else{if(r<a)return new ArrayBuffer(0);c=new ArrayBuffer(r),i=r}const l=new Uint8Array(c);for(let f=a-1;f>=0;f--){const h=Math.pow(2,f*e);l[i-f-1]=Math.floor(s/h),s-=l[i-f-1]*h}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Ne(...n){let e=0,t=0;for(const i of n)e+=i.length;const r=new ArrayBuffer(e),s=new Uint8Array(r);for(const i of n)s.set(i,t),t+=i.length;return s}function pt(){const n=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const a=n[0]===255&&n[1]&128,c=n[0]===0&&(n[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}const e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=n[0]&128;const r=Q(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)i[a]=n[a];return i[0]&=127,Q(i,8)-r}function Es(n){const e=n<0?n*-1:n;let t=128;for(let r=1;r<8;r++){if(e<=t){if(n<0){const o=t-e,a=J(o,8,r),c=new Uint8Array(a);return c[0]|=128,a}let s=J(e,8,r),i=new Uint8Array(s);if(i[0]&128){const o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)i[c+1]=a[c];i[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ns(n,e){if(n.byteLength!==e.byteLength)return!1;const t=new Uint8Array(n),r=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==r[s])return!1;return!0}function p(n,e){const t=n.toString(10);if(e<t.length)return"";const r=e-t.length,s=new Array(r);for(let o=0;o<r;o++)s[o]="0";return s.join("").concat(t)}/*!
|
|
27
27
|
* Copyright (c) 2014, GMO GlobalSign
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
56
56
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
57
57
|
*
|
|
58
|
-
*/function we(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function He(n){let e=0,t=0;for(let s=0;s<n.length;s++){const i=n[s];e+=i.byteLength}const r=new Uint8Array(e);for(let s=0;s<n.length;s++){const i=n[s];r.set(new Uint8Array(i),t),t+=i.byteLength}return r.buffer}function R(n,e,t,r){return e instanceof Uint8Array?e.byteLength?t<0?(n.error="Wrong parameter: inputOffset less than zero",!1):r<0?(n.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-r<0?(n.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(n.error="Wrong parameter: inputBuffer has zero length",!1):(n.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class Le{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return He(this.items)}}const oe=[new Uint8Array([1])],it="0123456789",ee="",_=new ArrayBuffer(0),Re=new Uint8Array(0),he="EndOfContent",Et="OCTET STRING",Nt="BIT STRING";function M(n){var e;return e=class extends n{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(r){this.valueHexView=new Uint8Array(r)}constructor(...r){var s;super(...r);const i=r[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?B.toUint8Array(i.valueHex):Re}fromBER(r,s,i){const o=r instanceof ArrayBuffer?new Uint8Array(r):r;if(!R(this,o,s,i))return-1;const a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(r=!1){return this.isHexOnly?r?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",_)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:v.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class K{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=ee,warnings:r=[],valueBeforeDecode:s=Re}={}){this.blockLength=e,this.error=t,this.warnings=r,this.valueBeforeDecodeView=B.toUint8Array(s)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:v.ToHex(this.valueBeforeDecodeView)}}}K.NAME="baseBlock";class x extends K{fromBER(e,t,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}x.NAME="valueBlock";class It extends M(K){constructor({idBlock:e={}}={}){var t,r,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?B.toUint8Array(e.valueHex):Re,this.tagClass=(r=e.tagClass)!==null&&r!==void 0?r:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",_}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){const s=J(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=t|31,!e){const s=this.valueHexView;for(let i=0;i<s.length-1;i++)r[i+1]=s[i]|128;r[this.valueHexView.byteLength]=s[s.length-1]}return r.buffer}fromBER(e,t,r){const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;const i=s.subarray(t,t+r);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;const a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),f=255;for(;i[c]&128;){if(l[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;const u=new Uint8Array(f);for(let g=0;g<l.length;g++)u[g]=l[g];l=this.valueHexView=new Uint8Array(f)}}this.blockLength=c+1,l[c-1]=i[c]&127;const h=new Uint8Array(c);for(let u=0;u<c;u++)h[u]=l[u];l=this.valueHexView=new Uint8Array(c),l.set(h),this.blockLength<=9?this.tagNumber=Q(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}It.NAME="identificationBlock";class Tt extends K{constructor({lenBlock:e={}}={}){var t,r,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(r=e.longFormUsed)!==null&&r!==void 0?r:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,r){const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;const i=s.subarray(t,t+r);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;const o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;const a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Q(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){const s=J(this.length,8);if(s.byteLength>127)return this.error="Too big length",_;if(t=new ArrayBuffer(s.byteLength+1),e)return t;const i=new Uint8Array(s);r=new Uint8Array(t),r[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)r[o+1]=i[o];return t}return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}Tt.NAME="lengthBlock";const d={};class A extends K{constructor({name:e=ee,optional:t=!1,primitiveSchema:r,...s}={},i){super(s),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new It(s),this.lenBlock=new Tt(s),this.valueBlock=i?new i(s):new x(s)}fromBER(e,t,r){const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(e,t){const r=t||new Le;t||Ut(this);const s=this.idBlock.toBER(e);if(r.write(s),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;const o=this.lenBlock.toBER(e);r.write(o),r.write(i)}return t?_:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():v.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,t=v.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const t=this.toBER(),r=e.toBER();return Ns(t,r)}}A.NAME="BaseBlock";function Ut(n){var e;if(n instanceof d.Constructed)for(const t of n.valueBlock.value)Ut(t)&&(n.lenBlock.isIndefiniteForm=!0);return!!(!((e=n.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class Vt extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=ee,...t}={},r){super(t,r),e&&this.fromString(e)}fromBER(e,t,r){const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}Vt.NAME="BaseStringBlock";class _t extends M(x){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}_t.NAME="PrimitiveValueBlock";var Ct;class Ht extends A{constructor(e={}){super(e,_t),this.idBlock.isConstructed=!1}}Ct=Ht;d.Primitive=Ct;Ht.NAME="PRIMITIVE";function Is(n,e){if(n instanceof e)return n;const t=new e;return t.idBlock=n.idBlock,t.lenBlock=n.lenBlock,t.warnings=n.warnings,t.valueBeforeDecodeView=n.valueBeforeDecodeView,t}function Be(n,e=0,t=n.length){const r=e;let s=new A({},x);const i=new K;if(!R(i,n,e,t))return s.error=i.error,{offset:-1,result:s};if(!n.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(n,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(n,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=A;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=d.EndOfContent;break;case 1:c=d.Boolean;break;case 2:c=d.Integer;break;case 3:c=d.BitString;break;case 4:c=d.OctetString;break;case 5:c=d.Null;break;case 6:c=d.ObjectIdentifier;break;case 10:c=d.Enumerated;break;case 12:c=d.Utf8String;break;case 13:c=d.RelativeObjectIdentifier;break;case 14:c=d.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=d.Sequence;break;case 17:c=d.Set;break;case 18:c=d.NumericString;break;case 19:c=d.PrintableString;break;case 20:c=d.TeletexString;break;case 21:c=d.VideotexString;break;case 22:c=d.IA5String;break;case 23:c=d.UTCTime;break;case 24:c=d.GeneralizedTime;break;case 25:c=d.GraphicString;break;case 26:c=d.VisibleString;break;case 27:c=d.GeneralString;break;case 28:c=d.UniversalString;break;case 29:c=d.CharacterString;break;case 30:c=d.BmpString;break;case 31:c=d.DATE;break;case 32:c=d.TimeOfDay;break;case 33:c=d.DateTime;break;case 34:c=d.Duration;break;default:{const l=s.idBlock.isConstructed?new d.Constructed:new d.Primitive;l.idBlock=s.idBlock,l.lenBlock=s.lenBlock,l.warnings=s.warnings,s=l}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?d.Constructed:d.Primitive}return s=Is(s,c),a=s.fromBER(n,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=n.subarray(r,r+s.blockLength),{offset:a,result:s}}function Ts(n){if(!n.byteLength){const e=new A({},x);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Be(B.toUint8Array(n).slice(),0,n.byteLength)}function Us(n,e){return n?1:e}class F extends x{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r){const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;Us(this.isIndefiniteForm,r)>0;){const o=Be(s,i,r);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,r-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===he)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===he?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){const r=t||new Le;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,r);return t?_:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}F.NAME="ConstructedValueBlock";var Lt;class te extends A{constructor(e={}){super(e,F),this.idBlock.isConstructed=!0}fromBER(e,t,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split(`
|
|
58
|
+
*/function we(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function He(n){let e=0,t=0;for(let s=0;s<n.length;s++){const i=n[s];e+=i.byteLength}const r=new Uint8Array(e);for(let s=0;s<n.length;s++){const i=n[s];r.set(new Uint8Array(i),t),t+=i.byteLength}return r.buffer}function L(n,e,t,r){return e instanceof Uint8Array?e.byteLength?t<0?(n.error="Wrong parameter: inputOffset less than zero",!1):r<0?(n.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-r<0?(n.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(n.error="Wrong parameter: inputBuffer has zero length",!1):(n.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class Re{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return He(this.items)}}const oe=[new Uint8Array([1])],it="0123456789",ee="",_=new ArrayBuffer(0),Le=new Uint8Array(0),he="EndOfContent",Et="OCTET STRING",Nt="BIT STRING";function M(n){var e;return e=class extends n{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(r){this.valueHexView=new Uint8Array(r)}constructor(...r){var s;super(...r);const i=r[0]||{};this.isHexOnly=(s=i.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=i.valueHex?B.toUint8Array(i.valueHex):Le}fromBER(r,s,i){const o=r instanceof ArrayBuffer?new Uint8Array(r):r;if(!L(this,o,s,i))return-1;const a=s+i;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=i,a):(this.warnings.push("Zero buffer length"),s)}toBER(r=!1){return this.isHexOnly?r?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",_)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:m.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class K{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=ee,warnings:r=[],valueBeforeDecode:s=Le}={}){this.blockLength=e,this.error=t,this.warnings=r,this.valueBeforeDecodeView=B.toUint8Array(s)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:m.ToHex(this.valueBeforeDecodeView)}}}K.NAME="baseBlock";class x extends K{fromBER(e,t,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}}x.NAME="valueBlock";class It extends M(K){constructor({idBlock:e={}}={}){var t,r,s,i;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?B.toUint8Array(e.valueHex):Le,this.tagClass=(r=e.tagClass)!==null&&r!==void 0?r:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(i=e.isConstructed)!==null&&i!==void 0?i:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",_}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const s=new Uint8Array(1);if(!e){let i=this.tagNumber;i&=31,t|=i,s[0]=t}return s.buffer}if(!this.isHexOnly){const s=J(this.tagNumber,7),i=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=i[c]|128;a[o]=i[o-1]}return a.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=t|31,!e){const s=this.valueHexView;for(let i=0;i<s.length-1;i++)r[i+1]=s[i]|128;r[this.valueHexView.byteLength]=s[s.length-1]}return r.buffer}fromBER(e,t,r){const s=B.toUint8Array(e);if(!L(this,s,t,r))return-1;const i=s.subarray(t,t+r);if(i.length===0)return this.error="Zero buffer length",-1;switch(i[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(i[0]&32)===32,this.isHexOnly=!1;const a=i[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),f=255;for(;i[c]&128;){if(l[c-1]=i[c]&127,c++,c>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(c===f){f+=255;const u=new Uint8Array(f);for(let g=0;g<l.length;g++)u[g]=l[g];l=this.valueHexView=new Uint8Array(f)}}this.blockLength=c+1,l[c-1]=i[c]&127;const h=new Uint8Array(c);for(let u=0;u<c;u++)h[u]=l[u];l=this.valueHexView=new Uint8Array(c),l.set(h),this.blockLength<=9?this.tagNumber=Q(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}It.NAME="identificationBlock";class Tt extends K{constructor({lenBlock:e={}}={}){var t,r,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(r=e.longFormUsed)!==null&&r!==void 0?r:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,r){const s=B.toUint8Array(e);if(!L(this,s,t,r))return-1;const i=s.subarray(t,t+r);if(i.length===0)return this.error="Zero buffer length",-1;if(i[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=i[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(i[0]&128),this.longFormUsed===!1)return this.length=i[0],this.blockLength=1,t+this.blockLength;const o=i[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>i.length)return this.error="End of input reached before message was fully decoded",-1;const a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Q(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){const s=J(this.length,8);if(s.byteLength>127)return this.error="Too big length",_;if(t=new ArrayBuffer(s.byteLength+1),e)return t;const i=new Uint8Array(s);r=new Uint8Array(t),r[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)r[o+1]=i[o];return t}return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}Tt.NAME="lengthBlock";const d={};class A extends K{constructor({name:e=ee,optional:t=!1,primitiveSchema:r,...s}={},i){super(s),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new It(s),this.lenBlock=new Tt(s),this.valueBlock=i?new i(s):new x(s)}fromBER(e,t,r){const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}toBER(e,t){const r=t||new Re;t||Ut(this);const s=this.idBlock.toBER(e);if(r.write(s),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const i=this.valueBlock.toBER(e);this.lenBlock.length=i.byteLength;const o=this.lenBlock.toBER(e);r.write(o),r.write(i)}return t?_:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():m.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,t=m.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const t=this.toBER(),r=e.toBER();return Ns(t,r)}}A.NAME="BaseBlock";function Ut(n){var e;if(n instanceof d.Constructed)for(const t of n.valueBlock.value)Ut(t)&&(n.lenBlock.isIndefiniteForm=!0);return!!(!((e=n.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class Vt extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=ee,...t}={},r){super(t,r),e&&this.fromString(e)}fromBER(e,t,r){const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}Vt.NAME="BaseStringBlock";class _t extends M(x){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}_t.NAME="PrimitiveValueBlock";var Ct;class Ht extends A{constructor(e={}){super(e,_t),this.idBlock.isConstructed=!1}}Ct=Ht;d.Primitive=Ct;Ht.NAME="PRIMITIVE";function Is(n,e){if(n instanceof e)return n;const t=new e;return t.idBlock=n.idBlock,t.lenBlock=n.lenBlock,t.warnings=n.warnings,t.valueBeforeDecodeView=n.valueBeforeDecodeView,t}function Be(n,e=0,t=n.length){const r=e;let s=new A({},x);const i=new K;if(!L(i,n,e,t))return s.error=i.error,{offset:-1,result:s};if(!n.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(n,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(n,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=A;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=d.EndOfContent;break;case 1:c=d.Boolean;break;case 2:c=d.Integer;break;case 3:c=d.BitString;break;case 4:c=d.OctetString;break;case 5:c=d.Null;break;case 6:c=d.ObjectIdentifier;break;case 10:c=d.Enumerated;break;case 12:c=d.Utf8String;break;case 13:c=d.RelativeObjectIdentifier;break;case 14:c=d.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=d.Sequence;break;case 17:c=d.Set;break;case 18:c=d.NumericString;break;case 19:c=d.PrintableString;break;case 20:c=d.TeletexString;break;case 21:c=d.VideotexString;break;case 22:c=d.IA5String;break;case 23:c=d.UTCTime;break;case 24:c=d.GeneralizedTime;break;case 25:c=d.GraphicString;break;case 26:c=d.VisibleString;break;case 27:c=d.GeneralString;break;case 28:c=d.UniversalString;break;case 29:c=d.CharacterString;break;case 30:c=d.BmpString;break;case 31:c=d.DATE;break;case 32:c=d.TimeOfDay;break;case 33:c=d.DateTime;break;case 34:c=d.Duration;break;default:{const l=s.idBlock.isConstructed?new d.Constructed:new d.Primitive;l.idBlock=s.idBlock,l.lenBlock=s.lenBlock,l.warnings=s.warnings,s=l}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?d.Constructed:d.Primitive}return s=Is(s,c),a=s.fromBER(n,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=n.subarray(r,r+s.blockLength),{offset:a,result:s}}function Ts(n){if(!n.byteLength){const e=new A({},x);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Be(B.toUint8Array(n).slice(),0,n.byteLength)}function Us(n,e){return n?1:e}class F extends x{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r){const s=B.toUint8Array(e);if(!L(this,s,t,r))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let i=t;for(;Us(this.isIndefiniteForm,r)>0;){const o=Be(s,i,r);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(i=o.offset,this.blockLength+=o.result.blockLength,r-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===he)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===he?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){const r=t||new Re;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,r);return t?_:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}F.NAME="ConstructedValueBlock";var Rt;class te extends A{constructor(e={}){super(e,F),this.idBlock.isConstructed=!0}fromBER(e,t,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),s)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split(`
|
|
59
59
|
`).map(s=>` ${s}`).join(`
|
|
60
60
|
`));const t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
61
61
|
${e.join(`
|
|
62
|
-
`)}`:`${t} :`}}Lt=te;d.Constructed=Lt;te.NAME="CONSTRUCTED";class Rt extends x{fromBER(e,t,r){return t}toBER(e){return _}}Rt.override="EndOfContentValueBlock";var Mt;class Ot extends A{constructor(e={}){super(e,Rt),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Mt=Ot;d.EndOfContent=Mt;Ot.NAME=he;var Dt;class $t extends A{constructor(e={}){super(e,x),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const s=new Uint8Array(r);s[0]=5,s[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}Dt=$t;d.Null=Dt;$t.NAME="NULL";class Pt extends M(x){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=B.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const s=B.toUint8Array(e);return R(this,s,t,r)?(this.valueHexView=s.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,pt.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Pt.NAME="BooleanValueBlock";var Ft;class jt extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Pt),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Ft=jt;d.Boolean=Ft;jt.NAME="BOOLEAN";class qt extends M(F){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=F.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(let i=0;i<this.value.length;i++){const o=this.value[i].constructor.NAME;if(o===he){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==Et)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,r),this.blockLength=r;return s}toBER(e,t){return this.isConstructed?F.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}qt.NAME="OctetStringValueBlock";var Me;class Gt extends A{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,i;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},qt),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,r===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(i.byteLength){const o=Be(i,0,i.byteLength);o.offset!==-1&&o.offset===r&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return te.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,t=v.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof Me&&e.push(t.valueBlock.valueHexView);return B.concat(e)}}Me=Gt;d.OctetString=Me;Gt.NAME=Et;class Jt extends M(F){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,r){if(!r)return t;let s=-1;if(this.isConstructed){if(s=F.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(const a of this.value){const c=a.constructor.NAME;if(c===he){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Nt)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}const i=B.toUint8Array(e);if(!R(this,i,t,r))return-1;const o=i.subarray(t,t+r);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const a=o.subarray(1);try{if(a.byteLength){const c=Be(a,0,a.byteLength);c.offset!==-1&&c.offset===r-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return F.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){const s=new Uint8Array(1);return s[0]=0,s.buffer}const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}Jt.NAME="BitStringValueBlock";var Kt;class Oe extends A{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,i;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Jt),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return te.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const o of t)e.push(o.toString(2).padStart(8,"0"));const r=e.join(""),s=this.constructor.NAME,i=r.substring(0,r.length-this.valueBlock.unusedBits);return`${s} : ${i}`}}}Kt=Oe;d.BitString=Kt;Oe.NAME=Nt;var Wt;function Vs(n,e){const t=new Uint8Array([0]),r=new Uint8Array(n),s=new Uint8Array(e);let i=r.slice(0);const o=i.length-1,a=s.slice(0),c=a.length-1;let l=0;const f=c<o?o:c;let h=0;for(let u=f;u>=0;u--,h++){switch(!0){case h<a.length:l=i[o-h]+a[c-h]+t[0];break;default:l=i[o-h]+t[0]}switch(t[0]=l/10,!0){case h>=i.length:i=Ne(new Uint8Array([l%10]),i);break;default:i[o-h]=l%10}}return t[0]>0&&(i=Ne(t,i)),i}function ot(n){if(n>=oe.length)for(let e=oe.length;e<=n;e++){const t=new Uint8Array([0]);let r=oe[e-1].slice(0);for(let s=r.length-1;s>=0;s--){const i=new Uint8Array([(r[s]<<1)+t[0]]);t[0]=i[0]/10,r[s]=i[0]%10}t[0]>0&&(r=Ne(t,r)),oe.push(r)}return oe[n]}function _s(n,e){let t=0;const r=new Uint8Array(n),s=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1;let l,f=0;for(let h=c;h>=0;h--,f++)switch(l=i[o-f]-a[c-f]-t,!0){case l<0:t=1,i[o-f]=l+10;break;default:t=0,i[o-f]=l}if(t>0)for(let h=o-c+1;h>=0;h--,f++)if(l=i[o-f]-t,l<0)t=1,i[o-f]=l+10;else{t=0,i[o-f]=l;break}return i.slice()}class De extends M(x){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=pt.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Es(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,s=0){const i=this.fromBER(e,t,r);if(i===-1)return i;const o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){const t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{const r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(t,1),this.valueHexView=r}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,r){const s=super.fromBER(e,t,r);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let t=new Uint8Array(this.valueHexView.length*8/3),r=0,s;const i=this.valueHexView;let o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let l=0;l<8;l++){if((s&1)===1)switch(r){case e:t=_s(ot(r),t),o="-";break;default:t=Vs(t,ot(r))}r++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=it.charAt(t[c]));return a===!1&&(o+=it.charAt(0)),o}}Wt=De;De.NAME="IntegerValueBlock";Object.defineProperty(Wt.prototype,"valueHex",{set:function(n){this.valueHexView=new Uint8Array(n),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var le;class $e extends A{constructor(e={}){super(e,De),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return we(),BigInt(this.valueBlock.toString())}static fromBigInt(e){we();const t=BigInt(e),r=new Le,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(v.FromHex(s));if(t<0){const a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;const l=BigInt(`0x${v.ToHex(a)}`)+t,f=B.toUint8Array(v.FromHex(l.toString(16)));f[0]|=128,r.write(f)}else i[0]&128&&r.write(new Uint8Array([0])),r.write(i);return new le({valueHex:r.final()})}convertToDER(){const e=new le({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new le({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}le=$e;d.Integer=le;$e.NAME="INTEGER";var Xt;class Zt extends $e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}Xt=Zt;d.Enumerated=Xt;Zt.NAME="ENUMERATED";class Ie extends M(x){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,r){if(!r)return t;const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Q(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){we();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let s=0;s<r.length;s++)r[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}const t=J(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",_;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)r[o]=s[o]|128;r[i]=s[i]}return r}toString(){let e="";if(this.isHexOnly)e=v.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Ie.NAME="sidBlock";class zt extends x{constructor({value:e=ee,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Ie;if(s=i.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return s}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const s=this.value[r].toBER(e);if(s.byteLength===0)return this.error=this.value[r].error,_;t.push(s)}return He(t)}fromString(e){this.value=[];let t=0,r=0,s="",i=!1;do if(r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1,i){const o=this.value[0];let a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}const c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{const o=new Ie;if(s>Number.MAX_SAFE_INTEGER){we();const a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(r!==-1)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[r].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}zt.NAME="ObjectIdentifierValueBlock";var Yt;class Pe extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,zt),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Yt=Pe;d.ObjectIdentifier=Yt;Pe.NAME="OBJECT IDENTIFIER";class Te extends M(K){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(r===0)return t;const s=B.toUint8Array(e);if(!R(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Q(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}const t=J(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",_;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)r[o]=s[o]|128;r[i]=s[i]}return r.buffer}toString(){let e="";return this.isHexOnly?e=v.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Te.NAME="relativeSidBlock";class Qt extends x{constructor({value:e=ee,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Te;if(s=i.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return s}toBER(e,t){const r=[];for(let s=0;s<this.value.length;s++){const i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,_;r.push(i)}return He(r)}fromString(e){this.value=[];let t=0,r=0,s="";do{r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1;const i=new Te;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(r!==-1);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Qt.NAME="RelativeObjectIdentifierValueBlock";var er;class tr extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Qt),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}er=tr;d.RelativeObjectIdentifier=er;tr.NAME="RelativeObjectIdentifier";var rr;class ye extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}rr=ye;d.Sequence=rr;ye.NAME="SEQUENCE";var sr;class nr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}sr=nr;d.Set=sr;nr.NAME="SET";class ir extends M(x){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=ee}toJSON(){return{...super.toJSON(),value:this.value}}}ir.NAME="StringValueBlock";class or extends ir{}or.NAME="SimpleStringValueBlock";class N extends Vt{constructor({...e}={}){super(e,or)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,B.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)r[s]=e.charCodeAt(s);this.valueBlock.value=e}}N.NAME="SIMPLE STRING";class cr extends N{fromBuffer(e){this.valueBlock.valueHexView=B.toUint8Array(e);try{this.valueBlock.value=v.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=v.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(v.FromUtf8String(e)),this.valueBlock.value=e}}cr.NAME="Utf8StringValueBlock";var ar;class W extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}ar=W;d.Utf8String=ar;W.NAME="UTF8String";class lr extends N{fromBuffer(e){this.valueBlock.value=v.ToUtf16String(e),this.valueBlock.valueHexView=B.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(v.FromUtf16String(e))}}lr.NAME="BmpStringValueBlock";var ur;class hr extends lr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}ur=hr;d.BmpString=ur;hr.NAME="BMPString";class fr extends N{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let s=0;s<r.length;s+=4)r[s]=r[s+3],r[s+1]=r[s+2],r[s+2]=0,r[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){const i=J(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;const a=4-o.length;for(let c=o.length-1;c>=0;c--)r[s*4+c+a]=o[c]}this.valueBlock.value=e}}fr.NAME="UniversalStringValueBlock";var dr;class gr extends fr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}dr=gr;d.UniversalString=dr;gr.NAME="UniversalString";var wr;class yr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}wr=yr;d.NumericString=wr;yr.NAME="NumericString";var Br;class br extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Br=br;d.PrintableString=Br;br.NAME="PrintableString";var mr;class vr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}mr=vr;d.TeletexString=mr;vr.NAME="TeletexString";var kr;class Ar extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}kr=Ar;d.VideotexString=kr;Ar.NAME="VideotexString";var Sr;class xr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}Sr=xr;d.IA5String=Sr;xr.NAME="IA5String";var pr;class Er extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}pr=Er;d.GraphicString=pr;Er.NAME="GraphicString";var Nr;class Fe extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}Nr=Fe;d.VisibleString=Nr;Fe.NAME="VisibleString";var Ir;class Tr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Ir=Tr;d.GeneralString=Ir;Tr.NAME="GeneralString";var Ur;class Vr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}Ur=Vr;d.CharacterString=Ur;Vr.NAME="CharacterString";var _r;class je extends Fe{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,B.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let s=0;s<e.length;s++)r[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const r=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(r===null){this.error="Wrong input string for conversion";return}const s=parseInt(r[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){const t=new Array(7);return t[0]=p(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=p(this.month,2),t[2]=p(this.day,2),t[3]=p(this.hour,2),t[4]=p(this.minute,2),t[5]=p(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}_r=je;d.UTCTime=_r;je.NAME="UTCTime";var Cr;class Hr extends je{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,r="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),t=!0;else{const h=new Number(e[e.length-1]);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(t){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let h=1,u=r.indexOf("+"),g="";if(u===-1&&(u=r.indexOf("-"),h=-1),u!==-1){if(g=r.substring(u+1),r=r.substring(0,u),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let w=parseInt(g.substring(0,2),10);if(isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*w,g.length===4){if(w=parseInt(g.substring(2,4),10),isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");c=h*w}}}let l=r.indexOf(".");if(l===-1&&(l=r.indexOf(",")),l!==-1){const h=new Number(`0${r.substring(l)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),s=r.substring(0,l)}else s=r;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let h=60*i;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let h=60*i;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){const h=1e3*i;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}const f=o.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let h=1;h<f.length;h++)switch(h){case 1:this.year=parseInt(f[h],10);break;case 2:this.month=parseInt(f[h],10);break;case 3:this.day=parseInt(f[h],10);break;case 4:this.hour=parseInt(f[h],10)+a;break;case 5:this.minute=parseInt(f[h],10)+c;break;case 6:this.second=parseInt(f[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){const h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const t=[];return t.push(p(this.year,4)),t.push(p(this.month,2)),t.push(p(this.day,2)),t.push(p(this.hour,2)),t.push(p(this.minute,2)),t.push(p(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(p(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}Cr=Hr;d.GeneralizedTime=Cr;Hr.NAME="GeneralizedTime";var Lr;class Rr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}Lr=Rr;d.DATE=Lr;Rr.NAME="DATE";var Mr;class Or extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}Mr=Or;d.TimeOfDay=Mr;Or.NAME="TimeOfDay";var Dr;class $r extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}Dr=$r;d.DateTime=Dr;$r.NAME="DateTime";var Pr;class Fr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}Pr=Fr;d.Duration=Pr;Fr.NAME="Duration";var jr;class qr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}jr=qr;d.TIME=jr;qr.NAME="TIME";function Cs(n){const e=n.slice().buffer,t=new ye({value:[new Pe({value:"1.3.101.110"})]}),r=new Oe({valueHex:e}),s=new ye({value:[t,r]});return new Uint8Array(s.toBER())}function Hs(n){const e=n.slice().buffer,s=Ts(e).result.valueBlock.value[1];return new Uint8Array(s.valueBlock.valueHex)}function ce(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}function ae(n){const e=n.replace(/\s+/g,""),t=atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r}function ct(n){if(n instanceof ArrayBuffer)return n;const e=n,{buffer:t,byteOffset:r,byteLength:s}=e;if(t instanceof ArrayBuffer)return t.slice(r,r+s);const i=new Uint8Array(s);return i.set(new Uint8Array(t,r,s)),i.buffer}function ue(n){return n.buffer}async function Ls(n,e,t,r){const s=await crypto.subtle.importKey("raw",ue(n),"HKDF",!1,["deriveBits"]),i=await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:ue(e),info:ue(t)},s,r*8);return new Uint8Array(i)}async function Rs(n){return crypto.subtle.importKey("raw",ue(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"])}async function Ms(n,e){const t=await crypto.subtle.sign("HMAC",n,ue(e));return new Uint8Array(t)}function Os(n){const e=n.replace(/\r/g,"").match(/-----BEGIN [^-]+-----([\s\S]*?)-----END [^-]+-----/);if(!e)throw new Error("Invalid PEM");const t=e[1].replace(/[\n\r\s]/g,""),r=atob(t),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s.buffer}async function Ds(n,e,t){const r=Os(n),s=await crypto.subtle.importKey("spki",r,{name:"ECDSA",namedCurve:"P-256"},!0,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},s,ct(t),ct(e))}class Ue{constructor(e){this.ws=null,this.listeners={},this.subscriptions={request:{},status:{},topic:{}},this._shouldReconnect=!0,this._reconnectAttempt=0,this._reconnectTimeoutId=null,this.chunkBuffers={},this.generateRandomString=t=>{let r="";for(;r.length<t;)r+=Math.random().toString(36).substring(2,2+(t-r.length));return r},this.distributeMessage=t=>{const{correlation_id:r,status:s,topic:i}=t||{},o=this.subscriptions.request[r];o&&Object.values(o).forEach(l=>l(t));const a=this.subscriptions.status[s];a&&Object.values(a).forEach(l=>l(t));const c=this.subscriptions.topic[i];c&&Object.values(c).forEach(l=>l(t)),Object.values(this.listeners).forEach(l=>l(t))},this.client=e}async executeWithRetry(e,t=3){let r=0,s=1e3;for(;r<=t;)try{return await e()}catch(i){if(r++,r>t)throw i;console.warn(`[WPS] Claim check fetch failed. Retrying in ${s}ms...`),await new Promise(o=>setTimeout(o,s)),s*=2}throw new Error("Retry loop failed")}scheduleReconnect(){if(!this._shouldReconnect||this._reconnectTimeoutId)return;const e=Math.min(3e4,1e3*2**this._reconnectAttempt);this._reconnectAttempt++,console.log(`[WPS] Reconnecting in ${e}ms (Attempt ${this._reconnectAttempt})`),this._reconnectTimeoutId=setTimeout(async()=>{this._reconnectTimeoutId=null;try{await this.connect()}catch(t){console.warn("[WPS] Reconnection loop failed to fetch endpoint. Retrying...",t),this.scheduleReconnect()}},e)}close(){var e;this._shouldReconnect=!1,this._connectPromise=void 0,this._reconnectTimeoutId&&(clearTimeout(this._reconnectTimeoutId),this._reconnectTimeoutId=null),(e=this.ws)==null||e.close(),this.ws=null}async connect(){if(!this.client.getAccessToken())throw new Error("Cannot connect to notifications: user is not logged in.");if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)))return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise(async(e,t)=>{let r=!1;try{const s=await this.client.get("/url/notifications"),{url:i}=s.data[0];if(!this._shouldReconnect){this._connectPromise=void 0,t(new Error("Connection aborted during token generation."));return}const o=new WebSocket(i);this.ws=o,o.onopen=()=>{this._reconnectAttempt=0,this._connectPromise=void 0,r=!0,e(),console.log("[WPS] Notification stream successfully connected.")},o.onmessage=async a=>{try{const c=JSON.parse(a.data);if(!c.ciphertext){const{operation_id:w,iv:m,signature:y,topic:C,correlation_id:X,content_type:re,...se}=c;if(!w)throw new Error("Claim check received but missing operation_id");const U=await this.executeWithRetry(()=>this.client.get(`/responses/${w}`,{},!0)),O={...se,content_type:re,topic:C,correlation_id:X,ciphertext:U.data,tot_pages:U.tot_pages,has_more:U.has_more,page_num:U.page_num,iv:m,signature:y},D=await this.client.decryptAndVerify(O);this.distributeMessage(D);return}const l=c.page_num,f=c.chunk_num,h=c.total_chunks;let u=c;if(h>1){this.chunkBuffers[l]||(this.chunkBuffers[l]={chunks:new Array(h),count:0,total:h});const w=this.chunkBuffers[l];if(w.chunks[f]===void 0&&(w.chunks[f]=c.ciphertext,w.count++),w.count<w.total)return;u={...c,ciphertext:w.chunks.join("")},delete this.chunkBuffers[l]}const g=await this.client.decryptAndVerify(u);this.distributeMessage(g)}catch(c){console.warn("Failed to process notification:",c)}},o.onerror=a=>{console.error("Notifications connection error",a)},o.onclose=()=>{console.log("Notifications socket disconnected"),r||(this._connectPromise=void 0,r=!0,t(new Error("WebSocket disconnected during handshake."))),this.ws===o&&(this.ws=null,this.scheduleReconnect())}}catch(s){this._connectPromise=void 0,r=!0,t(s)}}),this._connectPromise)}unsubscribe(e,t,r){delete this.subscriptions[e][t][r]}unlisten(e){delete this.listeners[e]}subscribe(e,t,r,s){let i=s??this.generateRandomString(16);return this.subscriptions[e]||(this.subscriptions[e]={}),this.subscriptions[e][t]||(this.subscriptions[e][t]={}),this.subscriptions[e][t][i]=r,()=>this.unsubscribe(e,t,i)}onMessage(e,t){let r=t??this.generateRandomString(16);return this.listeners[r]=e,()=>this.unlisten(r)}disconnect(){var e;(e=this.ws)==null||e.close(),this.ws=null}}const at="secure_api_session_v1";class Gr{constructor(e){this.session=null,this.pagingBuffer={},this.baseUrl=e.baseUrl,this.clientId=e.clientId,this.serverPublicKeyPem=e.serverPublicKeyPem,this.clientIdentityKeyPromise=Ps(e.clientIdentityPrivateKeyPem),this.loadPersistedSession(),this.notifications=new Ue(this),this.pagingBuffer={}}loadPersistedSession(){try{const e=localStorage.getItem(at);if(!e)return;const t=JSON.parse(e);if(!t)return;t.sessionId&&t.sessionExpiresAt?this.session={sessionId:t.sessionId,sessionExpiresAt:t.sessionExpiresAt,encKey:void 0,macKey:void 0,userId:t.userId,accessToken:t.accessToken,tokenType:t.tokenType,expiresAt:t.expiresAt,refreshToken:t.refreshToken}:this.session={sessionId:"",sessionExpiresAt:"",encKey:void 0,macKey:void 0,userId:t.userId,accessToken:t.accessToken,tokenType:t.tokenType,expiresAt:t.expiresAt,refreshToken:t.refreshToken}}catch{}}persistSession(){try{const e=this.session,t=e?{sessionId:e.sessionId,sessionExpiresAt:e.sessionExpiresAt,userId:e.userId,accessToken:e.accessToken,tokenType:e.tokenType,expiresAt:e.expiresAt,refreshToken:e.refreshToken}:{};localStorage.setItem(at,JSON.stringify(t))}catch{}}async handshake(){const e=await this.clientIdentityKeyPromise,t=xe.utils.randomSecretKey(),r=xe.getPublicKey(t),s=Cs(r),i=ce(s),o=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,Fs(s)),a=js(new Uint8Array(o)),c=ce(a),l=await fetch(`${this.baseUrl}/handshake`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:this.clientId,user_id:this.getUserId(),client_pub:i,client_sig:c,client_alg:"ES256"})});if(!l.ok)throw new Error(`Handshake failed: ${l.status} ${l.statusText}`);const f=await l.json(),{session_id:h,server_pub:u,server_sig:g,session_expires_at:w}=f;if(window.__akv={server_pub:u,server_sig:g},!h||!u||!g)throw new Error("Handshake response missing fields");const m=ae(u),y=ae(g);if(!await Ds(this.serverPublicKeyPem,m,y))throw new Error("Server signature verification failed");const X=Hs(m),re=xe.getSharedSecret(t,X),se=new Uint8Array(0),U=new TextEncoder().encode("health-api-v1"),O=await Ls(re,se,U,64),D=O.slice(0,32),be=O.slice(32,64),fe=await crypto.subtle.importKey("raw",D,"AES-GCM",!1,["encrypt","decrypt"]),ne=await Rs(be);this.updateSession({sessionId:h,encKey:fe,macKey:ne,sessionExpiresAt:w})}getUserId(){var e;return(e=this.session)==null?void 0:e.userId}getAccessToken(){var e;return(e=this.session)==null?void 0:e.accessToken}updateSession(e){if(!this.session){this.session=e,this.persistSession();return}Object.assign(this.session,e),this.persistSession()}getSession(){if(!this.session)throw new Error("No session");return this.session}async encryptBody(e){if(!e)return{ciphertextB64:"",ivB64:""};await this.ensureSession();const{encKey:t}=this.session,r=crypto.getRandomValues(new Uint8Array(12)),s=new TextEncoder().encode(JSON.stringify(e)),i=await crypto.subtle.encrypt({name:"AES-GCM",iv:r},t,s);return{ciphertextB64:ce(new Uint8Array(i)),ivB64:ce(r)}}async signRequest(e,t,r,s){await this.ensureSession();const{sessionId:i,macKey:o}=this.session,a=e.toUpperCase()==="GET"?"":{data:Array.isArray(r)?r:[r]},{ciphertextB64:c,ivB64:l}=await this.encryptBody(a),f=Math.floor(Date.now()/1e3).toString(),h=t.split("?")[0],u=`${e.toUpperCase()} ${h}
|
|
62
|
+
`)}`:`${t} :`}}Rt=te;d.Constructed=Rt;te.NAME="CONSTRUCTED";class Lt extends x{fromBER(e,t,r){return t}toBER(e){return _}}Lt.override="EndOfContentValueBlock";var Mt;class Ot extends A{constructor(e={}){super(e,Lt),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Mt=Ot;d.EndOfContent=Mt;Ot.NAME=he;var Dt;class $t extends A{constructor(e={}){super(e,x),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const s=new Uint8Array(r);s[0]=5,s[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}Dt=$t;d.Null=Dt;$t.NAME="NULL";class Pt extends M(x){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=B.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const s=B.toUint8Array(e);return L(this,s,t,r)?(this.valueHexView=s.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,pt.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}Pt.NAME="BooleanValueBlock";var Ft;class jt extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,Pt),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Ft=jt;d.Boolean=Ft;jt.NAME="BOOLEAN";class qt extends M(F){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=F.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(let i=0;i<this.value.length;i++){const o=this.value[i].constructor.NAME;if(o===he){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==Et)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,r),this.blockLength=r;return s}toBER(e,t){return this.isConstructed?F.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}qt.NAME="OctetStringValueBlock";var Me;class Gt extends A{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,i;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},qt),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,r===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(i.byteLength){const o=Be(i,0,i.byteLength);o.offset!==-1&&o.offset===r&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return te.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,t=m.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof Me&&e.push(t.valueBlock.valueHexView);return B.concat(e)}}Me=Gt;d.OctetString=Me;Gt.NAME=Et;class Jt extends M(F){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,r){if(!r)return t;let s=-1;if(this.isConstructed){if(s=F.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(const a of this.value){const c=a.constructor.NAME;if(c===he){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==Nt)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}const i=B.toUint8Array(e);if(!L(this,i,t,r))return-1;const o=i.subarray(t,t+r);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const a=o.subarray(1);try{if(a.byteLength){const c=Be(a,0,a.byteLength);c.offset!==-1&&c.offset===r-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return F.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength){const s=new Uint8Array(1);return s[0]=0,s.buffer}const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}Jt.NAME="BitStringValueBlock";var Kt;class Oe extends A{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,i;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((i=r.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Jt),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return te.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const o of t)e.push(o.toString(2).padStart(8,"0"));const r=e.join(""),s=this.constructor.NAME,i=r.substring(0,r.length-this.valueBlock.unusedBits);return`${s} : ${i}`}}}Kt=Oe;d.BitString=Kt;Oe.NAME=Nt;var Wt;function Vs(n,e){const t=new Uint8Array([0]),r=new Uint8Array(n),s=new Uint8Array(e);let i=r.slice(0);const o=i.length-1,a=s.slice(0),c=a.length-1;let l=0;const f=c<o?o:c;let h=0;for(let u=f;u>=0;u--,h++){switch(!0){case h<a.length:l=i[o-h]+a[c-h]+t[0];break;default:l=i[o-h]+t[0]}switch(t[0]=l/10,!0){case h>=i.length:i=Ne(new Uint8Array([l%10]),i);break;default:i[o-h]=l%10}}return t[0]>0&&(i=Ne(t,i)),i}function ot(n){if(n>=oe.length)for(let e=oe.length;e<=n;e++){const t=new Uint8Array([0]);let r=oe[e-1].slice(0);for(let s=r.length-1;s>=0;s--){const i=new Uint8Array([(r[s]<<1)+t[0]]);t[0]=i[0]/10,r[s]=i[0]%10}t[0]>0&&(r=Ne(t,r)),oe.push(r)}return oe[n]}function _s(n,e){let t=0;const r=new Uint8Array(n),s=new Uint8Array(e),i=r.slice(0),o=i.length-1,a=s.slice(0),c=a.length-1;let l,f=0;for(let h=c;h>=0;h--,f++)switch(l=i[o-f]-a[c-f]-t,!0){case l<0:t=1,i[o-f]=l+10;break;default:t=0,i[o-f]=l}if(t>0)for(let h=o-c+1;h>=0;h--,f++)if(l=i[o-f]-t,l<0)t=1,i[o-f]=l+10;else{t=0,i[o-f]=l;break}return i.slice()}class De extends M(x){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=pt.call(this)))}constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Es(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,s=0){const i=this.fromBER(e,t,r);if(i===-1)return i;const o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),i}toDER(e=!1){const t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{const r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(t,1),this.valueHexView=r}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,r){const s=super.fromBER(e,t,r);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let t=new Uint8Array(this.valueHexView.length*8/3),r=0,s;const i=this.valueHexView;let o="",a=!1;for(let c=i.byteLength-1;c>=0;c--){s=i[c];for(let l=0;l<8;l++){if((s&1)===1)switch(r){case e:t=_s(ot(r),t),o="-";break;default:t=Vs(t,ot(r))}r++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=it.charAt(t[c]));return a===!1&&(o+=it.charAt(0)),o}}Wt=De;De.NAME="IntegerValueBlock";Object.defineProperty(Wt.prototype,"valueHex",{set:function(n){this.valueHexView=new Uint8Array(n),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var le;class $e extends A{constructor(e={}){super(e,De),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return we(),BigInt(this.valueBlock.toString())}static fromBigInt(e){we();const t=BigInt(e),r=new Re,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(m.FromHex(s));if(t<0){const a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;const l=BigInt(`0x${m.ToHex(a)}`)+t,f=B.toUint8Array(m.FromHex(l.toString(16)));f[0]|=128,r.write(f)}else i[0]&128&&r.write(new Uint8Array([0])),r.write(i);return new le({valueHex:r.final()})}convertToDER(){const e=new le({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new le({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}le=$e;d.Integer=le;$e.NAME="INTEGER";var Xt;class Zt extends $e{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}Xt=Zt;d.Enumerated=Xt;Zt.NAME="ENUMERATED";class Ie extends M(x){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,r){if(!r)return t;const s=B.toUint8Array(e);if(!L(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Q(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){we();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let s=0;s<r.length;s++)r[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}const t=J(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",_;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)r[o]=s[o]|128;r[i]=s[i]}return r}toString(){let e="";if(this.isHexOnly)e=m.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Ie.NAME="sidBlock";class zt extends x{constructor({value:e=ee,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Ie;if(s=i.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=i.error,s;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return s}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const s=this.value[r].toBER(e);if(s.byteLength===0)return this.error=this.value[r].error,_;t.push(s)}return He(t)}fromString(e){this.value=[];let t=0,r=0,s="",i=!1;do if(r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1,i){const o=this.value[0];let a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}const c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,i=!1}else{const o=new Ie;if(s>Number.MAX_SAFE_INTEGER){we();const a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,i=!0),this.value.push(o)}while(r!==-1)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[r].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}zt.NAME="ObjectIdentifierValueBlock";var Yt;class Pe extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,zt),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Yt=Pe;d.ObjectIdentifier=Yt;Pe.NAME="OBJECT IDENTIFIER";class Te extends M(K){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(r===0)return t;const s=B.toUint8Array(e);if(!L(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,i[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Q(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,i=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)i[o]=s[o]|128;return i[this.blockLength-1]=s[this.blockLength-1],i.buffer}const t=J(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",_;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),i=t.byteLength-1;for(let o=0;o<i;o++)r[o]=s[o]|128;r[i]=s[i]}return r.buffer}toString(){let e="";return this.isHexOnly?e=m.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Te.NAME="relativeSidBlock";class Qt extends x{constructor({value:e=ee,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Te;if(s=i.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=i.error,s;this.blockLength+=i.blockLength,r-=i.blockLength,this.value.push(i)}return s}toBER(e,t){const r=[];for(let s=0;s<this.value.length;s++){const i=this.value[s].toBER(e);if(i.byteLength===0)return this.error=this.value[s].error,_;r.push(i)}return He(r)}fromString(e){this.value=[];let t=0,r=0,s="";do{r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1;const i=new Te;if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(r!==-1);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Qt.NAME="RelativeObjectIdentifierValueBlock";var er;class tr extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Qt),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}er=tr;d.RelativeObjectIdentifier=er;tr.NAME="RelativeObjectIdentifier";var rr;class ye extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}rr=ye;d.Sequence=rr;ye.NAME="SEQUENCE";var sr;class nr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}sr=nr;d.Set=sr;nr.NAME="SET";class ir extends M(x){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=ee}toJSON(){return{...super.toJSON(),value:this.value}}}ir.NAME="StringValueBlock";class or extends ir{}or.NAME="SimpleStringValueBlock";class N extends Vt{constructor({...e}={}){super(e,or)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,B.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)r[s]=e.charCodeAt(s);this.valueBlock.value=e}}N.NAME="SIMPLE STRING";class cr extends N{fromBuffer(e){this.valueBlock.valueHexView=B.toUint8Array(e);try{this.valueBlock.value=m.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=m.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(m.FromUtf8String(e)),this.valueBlock.value=e}}cr.NAME="Utf8StringValueBlock";var ar;class W extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}ar=W;d.Utf8String=ar;W.NAME="UTF8String";class lr extends N{fromBuffer(e){this.valueBlock.value=m.ToUtf16String(e),this.valueBlock.valueHexView=B.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(m.FromUtf16String(e))}}lr.NAME="BmpStringValueBlock";var ur;class hr extends lr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}ur=hr;d.BmpString=ur;hr.NAME="BMPString";class fr extends N{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let s=0;s<r.length;s+=4)r[s]=r[s+3],r[s+1]=r[s+2],r[s+2]=0,r[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){const i=J(e.charCodeAt(s),8),o=new Uint8Array(i);if(o.length>4)continue;const a=4-o.length;for(let c=o.length-1;c>=0;c--)r[s*4+c+a]=o[c]}this.valueBlock.value=e}}fr.NAME="UniversalStringValueBlock";var dr;class gr extends fr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}dr=gr;d.UniversalString=dr;gr.NAME="UniversalString";var wr;class yr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}wr=yr;d.NumericString=wr;yr.NAME="NumericString";var Br;class br extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Br=br;d.PrintableString=Br;br.NAME="PrintableString";var vr;class mr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}vr=mr;d.TeletexString=vr;mr.NAME="TeletexString";var kr;class Ar extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}kr=Ar;d.VideotexString=kr;Ar.NAME="VideotexString";var Sr;class xr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}Sr=xr;d.IA5String=Sr;xr.NAME="IA5String";var pr;class Er extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}pr=Er;d.GraphicString=pr;Er.NAME="GraphicString";var Nr;class Fe extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}Nr=Fe;d.VisibleString=Nr;Fe.NAME="VisibleString";var Ir;class Tr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Ir=Tr;d.GeneralString=Ir;Tr.NAME="GeneralString";var Ur;class Vr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}Ur=Vr;d.CharacterString=Ur;Vr.NAME="CharacterString";var _r;class je extends Fe{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,B.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let s=0;s<e.length;s++)r[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const r=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(r===null){this.error="Wrong input string for conversion";return}const s=parseInt(r[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){const t=new Array(7);return t[0]=p(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=p(this.month,2),t[2]=p(this.day,2),t[3]=p(this.hour,2),t[4]=p(this.minute,2),t[5]=p(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}_r=je;d.UTCTime=_r;je.NAME="UTCTime";var Cr;class Hr extends je{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,r="",s="",i=0,o,a=0,c=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),t=!0;else{const h=new Number(e[e.length-1]);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(t){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let h=1,u=r.indexOf("+"),g="";if(u===-1&&(u=r.indexOf("-"),h=-1),u!==-1){if(g=r.substring(u+1),r=r.substring(0,u),g.length!==2&&g.length!==4)throw new Error("Wrong input string for conversion");let w=parseInt(g.substring(0,2),10);if(isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");if(a=h*w,g.length===4){if(w=parseInt(g.substring(2,4),10),isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");c=h*w}}}let l=r.indexOf(".");if(l===-1&&(l=r.indexOf(",")),l!==-1){const h=new Number(`0${r.substring(l)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),s=r.substring(0,l)}else s=r;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let h=60*i;this.minute=Math.floor(h),h=60*(h-this.minute),this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let h=60*i;this.second=Math.floor(h),h=1e3*(h-this.second),this.millisecond=Math.floor(h)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){const h=1e3*i;this.millisecond=Math.floor(h)}break;default:throw new Error("Wrong input string for conversion")}const f=o.exec(s);if(f===null)throw new Error("Wrong input string for conversion");for(let h=1;h<f.length;h++)switch(h){case 1:this.year=parseInt(f[h],10);break;case 2:this.month=parseInt(f[h],10);break;case 3:this.day=parseInt(f[h],10);break;case 4:this.hour=parseInt(f[h],10)+a;break;case 5:this.minute=parseInt(f[h],10)+c;break;case 6:this.second=parseInt(f[h],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){const h=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=h.getUTCFullYear(),this.month=h.getUTCMonth(),this.day=h.getUTCDay(),this.hour=h.getUTCHours(),this.minute=h.getUTCMinutes(),this.second=h.getUTCSeconds(),this.millisecond=h.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const t=[];return t.push(p(this.year,4)),t.push(p(this.month,2)),t.push(p(this.day,2)),t.push(p(this.hour,2)),t.push(p(this.minute,2)),t.push(p(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(p(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}Cr=Hr;d.GeneralizedTime=Cr;Hr.NAME="GeneralizedTime";var Rr;class Lr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}Rr=Lr;d.DATE=Rr;Lr.NAME="DATE";var Mr;class Or extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}Mr=Or;d.TimeOfDay=Mr;Or.NAME="TimeOfDay";var Dr;class $r extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}Dr=$r;d.DateTime=Dr;$r.NAME="DateTime";var Pr;class Fr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}Pr=Fr;d.Duration=Pr;Fr.NAME="Duration";var jr;class qr extends W{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}jr=qr;d.TIME=jr;qr.NAME="TIME";function Cs(n){const e=n.slice().buffer,t=new ye({value:[new Pe({value:"1.3.101.110"})]}),r=new Oe({valueHex:e}),s=new ye({value:[t,r]});return new Uint8Array(s.toBER())}function Hs(n){const e=n.slice().buffer,s=Ts(e).result.valueBlock.value[1];return new Uint8Array(s.valueBlock.valueHex)}function ce(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}function ae(n){const e=n.replace(/\s+/g,""),t=atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r}function ct(n){if(n instanceof ArrayBuffer)return n;const e=n,{buffer:t,byteOffset:r,byteLength:s}=e;if(t instanceof ArrayBuffer)return t.slice(r,r+s);const i=new Uint8Array(s);return i.set(new Uint8Array(t,r,s)),i.buffer}function ue(n){return n.buffer}async function Rs(n,e,t,r){const s=await crypto.subtle.importKey("raw",ue(n),"HKDF",!1,["deriveBits"]),i=await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:ue(e),info:ue(t)},s,r*8);return new Uint8Array(i)}async function Ls(n){return crypto.subtle.importKey("raw",ue(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"])}async function Ms(n,e){const t=await crypto.subtle.sign("HMAC",n,ue(e));return new Uint8Array(t)}function Os(n){const e=n.replace(/\r/g,"").match(/-----BEGIN [^-]+-----([\s\S]*?)-----END [^-]+-----/);if(!e)throw new Error("Invalid PEM");const t=e[1].replace(/[\n\r\s]/g,""),r=atob(t),s=new Uint8Array(r.length);for(let i=0;i<r.length;i++)s[i]=r.charCodeAt(i);return s.buffer}async function Ds(n,e,t){const r=Os(n),s=await crypto.subtle.importKey("spki",r,{name:"ECDSA",namedCurve:"P-256"},!0,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:"SHA-256"},s,ct(t),ct(e))}class Ue{constructor(e){this.ws=null,this.listeners={},this.subscriptions={request:{},status:{},topic:{}},this._shouldReconnect=!0,this._reconnectAttempt=0,this._reconnectTimeoutId=null,this.chunkBuffers={},this.generateRandomString=t=>{let r="";for(;r.length<t;)r+=Math.random().toString(36).substring(2,2+(t-r.length));return r},this.distributeMessage=t=>{const{correlation_id:r,status:s,topic:i}=t||{},o=this.subscriptions.request[r];o&&Object.values(o).forEach(l=>l(t));const a=this.subscriptions.status[s];a&&Object.values(a).forEach(l=>l(t));const c=this.subscriptions.topic[i];c&&Object.values(c).forEach(l=>l(t)),Object.values(this.listeners).forEach(l=>l(t))},this.client=e}async executeWithRetry(e,t=3){let r=0,s=1e3;for(;r<=t;)try{return await e()}catch(i){if(r++,r>t)throw i;console.warn(`[WPS] Claim check fetch failed. Retrying in ${s}ms...`),await new Promise(o=>setTimeout(o,s)),s*=2}throw new Error("Retry loop failed")}scheduleReconnect(){if(!this._shouldReconnect||this._reconnectTimeoutId)return;const e=Math.min(3e4,1e3*2**this._reconnectAttempt);this._reconnectAttempt++,console.log(`[WPS] Reconnecting in ${e}ms (Attempt ${this._reconnectAttempt})`),this._reconnectTimeoutId=setTimeout(async()=>{this._reconnectTimeoutId=null;try{await this.connect()}catch(t){console.warn("[WPS] Reconnection loop failed to fetch endpoint. Retrying...",t),this.scheduleReconnect()}},e)}close(){var e;this._shouldReconnect=!1,this._connectPromise=void 0,this._reconnectTimeoutId&&(clearTimeout(this._reconnectTimeoutId),this._reconnectTimeoutId=null),(e=this.ws)==null||e.close(),this.ws=null}async connect(){if(!this.client.getAccessToken())throw new Error("Cannot connect to notifications: user is not logged in.");if(!(this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)))return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise(async(e,t)=>{let r=!1;try{const s=await this.client.get("/url/notifications"),{url:i}=s.data[0];if(!this._shouldReconnect){this._connectPromise=void 0,t(new Error("Connection aborted during token generation."));return}const o=new WebSocket(i);this.ws=o,o.onopen=()=>{this._reconnectAttempt=0,this._connectPromise=void 0,r=!0,e(),console.log("[WPS] Notification stream successfully connected.")},o.onmessage=async a=>{try{const c=JSON.parse(a.data);if(!c.ciphertext){const{operation_id:w,iv:v,signature:y,topic:C,correlation_id:X,content_type:re,...se}=c;if(!w)throw new Error("Claim check received but missing operation_id");const U=await this.executeWithRetry(()=>this.client.get(`/responses/${w}`,{},!0)),O={...se,content_type:re,topic:C,correlation_id:X,ciphertext:U.data,tot_pages:U.tot_pages,has_more:U.has_more,page_num:U.page_num,iv:v,signature:y},D=await this.client.decryptAndVerify(O);this.distributeMessage(D);return}const l=c.page_num,f=c.chunk_num,h=c.total_chunks;let u=c;if(h>1){this.chunkBuffers[l]||(this.chunkBuffers[l]={chunks:new Array(h),count:0,total:h});const w=this.chunkBuffers[l];if(w.chunks[f]===void 0&&(w.chunks[f]=c.ciphertext,w.count++),w.count<w.total)return;u={...c,ciphertext:w.chunks.join("")},delete this.chunkBuffers[l]}const g=await this.client.decryptAndVerify(u);this.distributeMessage(g)}catch(c){console.warn("Failed to process notification:",c)}},o.onerror=a=>{console.error("Notifications connection error",a)},o.onclose=()=>{console.log("Notifications socket disconnected"),r||(this._connectPromise=void 0,r=!0,t(new Error("WebSocket disconnected during handshake."))),this.ws===o&&(this.ws=null,this.scheduleReconnect())}}catch(s){this._connectPromise=void 0,r=!0,t(s)}}),this._connectPromise)}unsubscribe(e,t,r){delete this.subscriptions[e][t][r]}unlisten(e){delete this.listeners[e]}subscribe(e,t,r,s){let i=s??this.generateRandomString(16);return this.subscriptions[e]||(this.subscriptions[e]={}),this.subscriptions[e][t]||(this.subscriptions[e][t]={}),this.subscriptions[e][t][i]=r,()=>this.unsubscribe(e,t,i)}onMessage(e,t){let r=t??this.generateRandomString(16);return this.listeners[r]=e,()=>this.unlisten(r)}disconnect(){var e;(e=this.ws)==null||e.close(),this.ws=null}}const at="secure_api_session_v1";class Gr{constructor(e){this.session=null,this.pagingBuffer={},this.baseUrl=e.baseUrl,this.clientId=e.clientId,this.serverPublicKeyPem=e.serverPublicKeyPem,this.clientIdentityKeyPromise=Ps(e.clientIdentityPrivateKeyPem),this.loadPersistedSession(),this.notifications=new Ue(this),this.pagingBuffer={}}loadPersistedSession(){try{const e=localStorage.getItem(at);if(!e)return;const t=JSON.parse(e);if(!t)return;t.sessionId&&t.sessionExpiresAt?this.session={sessionId:t.sessionId,sessionExpiresAt:t.sessionExpiresAt,encKey:void 0,macKey:void 0,userId:t.userId,accessToken:t.accessToken,tokenType:t.tokenType,expiresAt:t.expiresAt,refreshToken:t.refreshToken}:this.session={sessionId:"",sessionExpiresAt:"",encKey:void 0,macKey:void 0,userId:t.userId,accessToken:t.accessToken,tokenType:t.tokenType,expiresAt:t.expiresAt,refreshToken:t.refreshToken}}catch{}}persistSession(){try{const e=this.session,t=e?{sessionId:e.sessionId,sessionExpiresAt:e.sessionExpiresAt,userId:e.userId,accessToken:e.accessToken,tokenType:e.tokenType,expiresAt:e.expiresAt,refreshToken:e.refreshToken}:{};localStorage.setItem(at,JSON.stringify(t))}catch{}}async handshake(){const e=await this.clientIdentityKeyPromise,t=xe.utils.randomSecretKey(),r=xe.getPublicKey(t),s=Cs(r),i=ce(s),o=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,Fs(s)),a=js(new Uint8Array(o)),c=ce(a),l=await fetch(`${this.baseUrl}/handshake`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:this.clientId,user_id:this.getUserId(),client_pub:i,client_sig:c,client_alg:"ES256"})});if(!l.ok)throw new Error(`Handshake failed: ${l.status} ${l.statusText}`);const f=await l.json(),{session_id:h,server_pub:u,server_sig:g,session_expires_at:w}=f;if(window.__akv={server_pub:u,server_sig:g},!h||!u||!g)throw new Error("Handshake response missing fields");const v=ae(u),y=ae(g);if(!await Ds(this.serverPublicKeyPem,v,y))throw new Error("Server signature verification failed");const X=Hs(v),re=xe.getSharedSecret(t,X),se=new Uint8Array(0),U=new TextEncoder().encode("health-api-v1"),O=await Rs(re,se,U,64),D=O.slice(0,32),be=O.slice(32,64),fe=await crypto.subtle.importKey("raw",D,"AES-GCM",!1,["encrypt","decrypt"]),ne=await Ls(be);this.updateSession({sessionId:h,encKey:fe,macKey:ne,sessionExpiresAt:w})}getUserId(){var e;return(e=this.session)==null?void 0:e.userId}getAccessToken(){var e;return(e=this.session)==null?void 0:e.accessToken}updateSession(e){if(!this.session){this.session=e,this.persistSession();return}Object.assign(this.session,e),this.persistSession()}getSession(){if(!this.session)throw new Error("No session");return this.session}async encryptBody(e){if(!e)return{ciphertextB64:"",ivB64:""};await this.ensureSession();const{encKey:t}=this.session,r=crypto.getRandomValues(new Uint8Array(12)),s=new TextEncoder().encode(JSON.stringify(e)),i=await crypto.subtle.encrypt({name:"AES-GCM",iv:r},t,s);return{ciphertextB64:ce(new Uint8Array(i)),ivB64:ce(r)}}async signRequest(e,t,r,s){await this.ensureSession();const{sessionId:i,macKey:o}=this.session,a=e.toUpperCase()==="GET"?"":{data:Array.isArray(r)?r:[r]},{ciphertextB64:c,ivB64:l}=await this.encryptBody(a),f=Math.floor(Date.now()/1e3).toString(),h=t.split("?")[0],u=`${e.toUpperCase()} ${h}
|
|
63
63
|
${f}
|
|
64
|
-
${c}`,g=await Ms(o,new TextEncoder().encode(u)),w=ce(g),
|
|
64
|
+
${c}`,g=await Ms(o,new TextEncoder().encode(u)),w=ce(g),v=new Headers({...s,"X-Session-Id":i,"X-Client-Id":this.clientId,"X-Timestamp":f,"X-Signature":w,"Content-Type":"application/json"});return this.getUserId()&&v.append("X-User-Id",this.getUserId()),this.getAccessToken()&&!this.isTokenExpired()&&v.append("Authorization",`Bearer ${this.getAccessToken()}`),{headers:v,payload:{content:c,iv:l}}}async get(e,t,r){const{headers:s}=await this.signRequest("GET",e,null,t),i=await fetch(`${this.baseUrl}${e}`,{method:"GET",headers:s});if(!i.ok)throw new Error(`GET ${e} failed: ${i.status} ${i.statusText}`);return r?await i.json():this.decryptAndVerify(await i.json())}async post(e,t,r){const{headers:s,payload:i}=await this.signRequest("POST",e,t,r),o=await fetch(`${this.baseUrl}${e}`,{method:"POST",headers:s,body:JSON.stringify(i)});if(!o.ok)throw new Error(`POST ${e} failed: ${o.status} ${o.statusText}`,{cause:o.status});return e.endsWith("/handshake")?await o.json():this.decryptAndVerify(await o.json())}async get_all_pages_async(e,t,r={}){const s=crypto.getRandomValues(new Uint8Array(10)),i=Array.from(s).join("-"),o=r?{...r,"X-Force-Sync":!1,"X-Request-Id":i}:{"X-Force-Sync":!1,"X-Request-Id":i};this.notifications.subscribe("request",i,async a=>{const{data:c,...l}=a;if(Object.keys(this.pagingBuffer).includes(i)||(this.pagingBuffer[i]={pages:new Array(l.tot_pages),count:0,total:l.tot_pages,data:[]}),this.pagingBuffer[i].pages[l.page_num-1]=l,this.pagingBuffer[i].data.push(...c),this.pagingBuffer[i].count++,l.tot_pages>l.page_num&&l.has_more&&this.pagingBuffer[i].count<this.pagingBuffer[i].total){let f=e.includes("?")?"&":"?";this.get(`${e}${f}page_num=${l.page_num+1}`,o);return}if(t)return t({tot_pages:l.tot_pages,page_num:l.tot_pages,has_more:!1,status:l.status,topic:l.topic,correlation_id:l.correlation_id,content_type:l.content_type,data:this.pagingBuffer[i].data})}),await this.get(e,o)}async get_all_pages_sync(e,t={}){const r=t?{...t,"X-Force-Sync":!0}:{"X-Force-Sync":!0};let s=await this.get(e,r);const i=[s];for(;s.tot_pages>s.page_num&&s.has_more;){let o=e.includes("?")?"&":"?";s=await this.get(`${e}${o}page_num=${s.page_num+1}`,{...t,"X-Force-Sync":!0}),i.push(s)}return i}async ensureSession(){var t,r,s;(!this.session||!this.session.sessionId||!this.session.sessionExpiresAt||!this.session.encKey||!this.session.macKey)&&await this.handshake();const e=new Date(Date.now()+5*60*1e3);(t=this.session)!=null&&t.sessionExpiresAt&&new Date((r=this.session)==null?void 0:r.sessionExpiresAt)<e&&await this.extendHandshake(),(s=this.session)!=null&&s.accessToken&&this.isTokenExpired()&&await this.refresh()}async extendHandshake(){await this.post("/handshake/extend",{}).then(async e=>{var t;e&&(e.session_id!==((t=this.session)==null?void 0:t.sessionId)?await this.handshake():this.updateSession({sessionExpiresAt:e.data[0].session_expires_at}))}).catch(async e=>{await this.handshake()})}async decryptAndVerify(e){const{ciphertext:t,iv:r,signature:s,...i}=e;if(!t||!r||!s)throw new Error("Malformed notification");const{encKey:o,macKey:a}=this.getSession(),c=ae(s),l=await crypto.subtle.sign("HMAC",a,new TextEncoder().encode(t));if(!this.constantTimeEqual(c,new Uint8Array(l)))throw new Error("Invalid notification signature");const f=Uint8Array.from(ae(r)),h=Uint8Array.from(ae(t)),u=await crypto.subtle.decrypt({name:"AES-GCM",iv:f},o,h),g=new TextDecoder().decode(u);return{...JSON.parse(g),...i}}constantTimeEqual(e,t){if(e.length!==t.length)return!1;let r=0;for(let s=0;s<e.length;s++)r|=e[s]^t[s];return r===0}async login(e){(!this.session||!this.session.sessionId||!this.session.sessionExpiresAt||!this.session.encKey||!this.session.macKey)&&await this.handshake(),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0});const t={};"username"in e&&"password"in e&&(t.username=e.username,t.password=e.password,t.scope=e.scope,t.oauth_session=e.oauthSession),"username"in e&&"otp"in e&&(t.username=e.username,t.otp=e.otp,t.scope=e.scope,t.oauth_session=e.oauthSession,t.oauth_flow_id=e.oauthFlowId),"email"in e&&"socialToken"in e&&"socialProvider"in e&&(t.email=e.email,t.social_token=e.socialToken,t.social_provider=e.socialProvider,t.scope=e.scope,t.oauth_session=e.oauthSession),"jwt"in e&&this.updateSession({accessToken:e.jwt,tokenType:"Bearer"}),"refreshToken"in e&&(t.refresh_token=e.refreshToken);const r=await this.post("/oauth/authorize",t),{access_token:s,token_type:i,expires_at:o,refresh_token:a}=r.data[0];return s&&this.updateSession({accessToken:s}),i&&this.updateSession({tokenType:i}),o&&this.updateSession({expiresAt:o}),a&&this.updateSession({refreshToken:a}),{accessToken:s,tokenType:i,expiresAt:o,refreshToken:a}}async logout(){await this.post("/oauth/logout",{}),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0}),this.notifications=new Ue(this),await this.handshake()}async refresh(){const e=this.getSession();if(!(e!=null&&e.refreshToken))throw new Error("No refresh token available");if(e&&e.refreshToken)return this.login({refreshToken:e.refreshToken})}isTokenExpired(){const e=this.getSession();if(!(e!=null&&e.expiresAt))return!0;if(e&&e.expiresAt)return Math.floor(Date.now()/1e3)>=e.expiresAt}}function $s(n){const e=n.replace(/-----BEGIN PRIVATE KEY-----/,"").replace(/-----END PRIVATE KEY-----/,"").replace(/\s+/g,""),t=atob(e),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r.buffer}async function Ps(n){const e=$s(n);return crypto.subtle.importKey("pkcs8",e,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"])}function Fs(n){return Uint8Array.from(n).buffer}function js(n){const e=n.slice(0,32),t=n.slice(32,64);function r(f){let h=0;for(;h<f.length-1&&f[h]===0;)h++;return f.slice(h)}function s(f){const h=r(f);if(h[0]&128){const u=new Uint8Array(h.length+1);return u[0]=0,u.set(h,1),u}return h}const i=s(e),o=s(t),a=2+i.length+2+o.length,c=new Uint8Array(2+a);let l=0;return c[l++]=48,c[l++]=a,c[l++]=2,c[l++]=i.length,c.set(i,l),l+=i.length,c[l++]=2,c[l++]=o.length,c.set(o,l),c}const Jr=Symbol("SDK_CLIENT"),qs={install(n,e){const t=new Gr(e);n.provide(Jr,t)}};exports.Notifications=Ue;exports.SDK_CLIENT=Jr;exports.SdkPlugin=qs;exports.SecureApiClient=Gr;
|
|
65
65
|
//# sourceMappingURL=index.cjs.map
|