@vitia.ai/secure-api-client-vue 0.1.4 → 0.1.5
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 +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/index.mjs +673 -595
- 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 at(n){return n instanceof Uint8Array||ArrayBuffer.isView(n)&&n.constructor.name==="Uint8Array"}function Xr(n){if(!Number.isSafeInteger(n)||n<0)throw new Error("positive integer expected, got "+n)}function Ve(n,...e){if(!at(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 lt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Yr=Array.from({length:256},(n,e)=>e.toString(16).padStart(2,"0"));function ut(n){if(Ve(n),lt)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=Yr[n[t]];return e}const _={_0:48,_9:57,A:65,F:70,a:97,f:102};function ze(n){if(n>=_._0&&n<=_._9)return n-_._0;if(n>=_.A&&n<=_.F)return n-(_.A-10);if(n>=_.a&&n<=_.f)return n-(_.a-10)}function ht(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);if(lt)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)),c=ze(n.charCodeAt(i+1));if(o===void 0||c===void 0){const a=n[i]+n[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}r[s]=o*16+c}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 ft=BigInt(0),Xe=BigInt(1);function dt(n){if(typeof n!="string")throw new Error("hex string expected, got "+typeof n);return n===""?ft:BigInt("0x"+n)}function es(n){return dt(ut(n))}function pe(n){return Ve(n),dt(ut(Uint8Array.from(n).reverse()))}function gt(n,e){return ht(n.toString(16).padStart(e*2,"0"))}function wt(n,e){return gt(n,e).reverse()}function Ye(n,e,t){let r;if(typeof e=="string")try{r=ht(e)}catch(i){throw new Error(n+" must be hex string or Uint8Array, cause: "+i)}else if(at(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"&&ft<=n;function ts(n,e,t){return Se(n)&&Se(e)&&Se(t)&&e<=n&&n<t}function Qe(n,e,t,r){if(!ts(e,t,r))throw new Error("expected valid "+n+": "+t+" <= n < "+r+", got "+e)}const rs=n=>(Xe<<BigInt(n))-Xe;function ss(n,e,t={}){if(!n||typeof n!="object")throw new Error("expected valid options object");function r(s,i,o){const c=n[s];if(o&&c===void 0)return;const a=typeof c;if(a!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${a}`)}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),p=BigInt(1),F=BigInt(2),yt=BigInt(3),Bt=BigInt(4),bt=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 U(n,e,t){let r=n;for(;e-- >S;)r*=r,r%=t;return r}function et(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=p;for(;t!==S;){const c=r/t,a=r%t,u=s-i*c;r=t,t=a,s=i,i=u}if(r!==p)throw new Error("invert: does not exist");return I(s,e)}function Te(n,e,t){if(!n.eql(n.sqr(e),t))throw new Error("Cannot find square root")}function mt(n,e){const t=(n.ORDER+p)/Bt,r=n.pow(e,t);return Te(n,r,e),r}function os(n,e){const t=(n.ORDER-bt)/vt,r=n.mul(e,F),s=n.pow(r,t),i=n.mul(e,s),o=n.mul(n.mul(i,F),s),c=n.mul(i,n.sub(o,n.ONE));return Te(n,c,e),c}function cs(n){const e=Ce(n),t=At(n),r=t(e,e.neg(e.ONE)),s=t(e,r),i=t(e,e.neg(r)),o=(n+ns)/kt;return(c,a)=>{let u=c.pow(a,o),f=c.mul(u,r);const h=c.mul(u,s),l=c.mul(u,i),g=c.eql(c.sqr(f),a),w=c.eql(c.sqr(h),a);u=c.cmov(u,f,g),f=c.cmov(l,h,w);const m=c.eql(c.sqr(f),a),b=c.cmov(u,f,m);return Te(c,b,a),b}}function At(n){if(n<yt)throw new Error("sqrt is not defined for small field");let e=n-p,t=0;for(;e%F===S;)e/=F,t++;let r=F;const s=Ce(n);for(;tt(s,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(t===1)return mt;let i=s.pow(r,e);const o=(e+p)/F;return function(a,u){if(a.is0(u))return u;if(tt(a,u)!==1)throw new Error("Cannot find square root");let f=t,h=a.mul(a.ONE,i),l=a.pow(u,e),g=a.pow(u,o);for(;!a.eql(l,a.ONE);){if(a.is0(l))return a.ZERO;let w=1,m=a.sqr(l);for(;!a.eql(m,a.ONE);)if(w++,m=a.sqr(m),w===f)throw new Error("Cannot find square root");const b=p<<BigInt(f-w-1),D=a.pow(h,b);f=w,h=a.sqr(D),l=a.mul(l,h),g=a.mul(g,D)}return g}}function as(n){return n%Bt===yt?mt:n%vt===bt?os:n%kt===is?cs(n):At(n)}function ls(n,e,t){if(t<S)throw new Error("invalid exponent, negatives unsupported");if(t===S)return n.ONE;if(t===p)return e;let r=n.ONE,s=e;for(;t>S;)t&p&&(r=n.mul(r,s)),s=n.sqr(s),t>>=p;return r}function us(n,e,t=!1){const r=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((o,c,a)=>n.is0(c)?o:(r[a]=o,n.mul(o,c)),n.ONE),i=n.inv(s);return e.reduceRight((o,c,a)=>n.is0(c)?o:(r[a]=n.mul(o,r[a]),n.mul(o,c)),i),r}function tt(n,e){const t=(n.ORDER-p)/F,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&&Xr(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,c;if(typeof e=="object"&&e!=null){if(r.sqrt||t)throw new Error("cannot specify opts in two arguments");const l=e;l.BITS&&(s=l.BITS),l.sqrt&&(i=l.sqrt),typeof l.isLE=="boolean"&&(t=l.isLE),typeof l.modFromBytes=="boolean"&&(o=l.modFromBytes),c=l.allowedLengths}else typeof e=="number"&&(s=e),r.sqrt&&(i=r.sqrt);const{nBitLength:a,nByteLength:u}=hs(n,s);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let f;const h=Object.freeze({ORDER:n,isLE:t,BITS:a,BYTES:u,MASK:rs(a),ZERO:S,ONE:p,allowedLengths:c,create:l=>I(l,n),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return S<=l&&l<n},is0:l=>l===S,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&p)===p,neg:l=>I(-l,n),eql:(l,g)=>l===g,sqr:l=>I(l*l,n),add:(l,g)=>I(l+g,n),sub:(l,g)=>I(l-g,n),mul:(l,g)=>I(l*g,n),pow:(l,g)=>ls(h,l,g),div:(l,g)=>I(l*et(g,n),n),sqrN:l=>l*l,addN:(l,g)=>l+g,subN:(l,g)=>l-g,mulN:(l,g)=>l*g,inv:l=>et(l,n),sqrt:i||(l=>(f||(f=as(n)),f(h,l))),toBytes:l=>t?wt(l,u):gt(l,u),fromBytes:(l,g=!0)=>{if(c){if(!c.includes(l.length)||l.length>u)throw new Error("Field.fromBytes: expected "+c+" bytes, got "+l.length);const m=new Uint8Array(u);m.set(l,t?0:m.length-l.length),l=m}if(l.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+l.length);let w=t?pe(l):es(l);if(o&&(w=I(w,n)),!g&&!h.isValid(w))throw new Error("invalid field element: outside of range 0..ORDER");return w},invertBatch:l=>us(h,l),cmov:(l,g,w)=>w?g:l});return Object.freeze(h)}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const re=BigInt(0),z=BigInt(1),fe=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,c=r==="x25519";if(!c&&r!=="x448")throw new Error("invalid type");const a=o||Qr,u=c?255:448,f=c?32:56,h=BigInt(c?9:5),l=BigInt(c?121665:39081),g=c?fe**BigInt(254):fe**BigInt(447),w=c?BigInt(8)*fe**BigInt(251)-z:BigInt(4)*fe**BigInt(445)-z,m=g+w+z,b=B=>I(B,t),D=le(h);function le(B){return wt(b(B),f)}function ye(B){const k=Ye("u coordinate",B,f);return c&&(k[31]&=127),b(pe(k))}function Be(B){return pe(s(Ye("scalar",B,f)))}function ee(B,k){const C=be(ye(k),Be(B));if(C===re)throw new Error("invalid private or public key received");return le(C)}function J(B){return ee(B,D)}function K(B,k,C){const he=b(B*(k-C));return k=b(k-he),C=b(C+he),{x_2:k,x_3:C}}function be(B,k){Qe("u",B,re,t),Qe("scalar",k,g,m);const C=k,he=B;let R=z,M=re,$=B,P=z,W=re;for(let ve=BigInt(u-1);ve>=re;ve--){const je=C>>ve&z;W^=je,{x_2:R,x_3:$}=K(W,R,$),{x_2:M,x_3:P}=K(W,M,P),W=je;const ke=R+M,me=b(ke*ke),Ae=R-M,qe=b(Ae*Ae),Ge=me-qe,Zr=$+P,zr=$-P,Je=b(zr*ke),Ke=b(Zr*Ae),We=Je+Ke,Ze=Je-Ke;$=b(We*We),P=b(he*b(Ze*Ze)),R=b(me*qe),M=b(Ge*(me+b(l*Ge)))}({x_2:R,x_3:$}=K(W,R,$)),{x_2:M,x_3:P}=K(W,M,P);const Wr=i(M);return b(R*Wr)}const ue={secretKey:f,publicKey:f,seed:f},te=(B=a(f))=>(Ve(B,ue.seed),B);function Kr(B){const k=te(B);return{secretKey:k,publicKey:J(k)}}return{keygen:Kr,getSharedSecret:(B,k)=>ee(B,k),getPublicKey:B=>J(B),scalarMult:ee,scalarMultBase:J,utils:{randomSecretKey:te,randomPrivateKey:te},GuBytes:D.slice(),lengths:ue}}/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const gs=BigInt(1),rt=BigInt(2),ws=BigInt(3),ys=BigInt(5),Bs=BigInt(8),St=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),bs={p:St,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=St,c=n*n%i*n%i,a=U(c,rt,i)*c%i,u=U(a,gs,i)*n%i,f=U(u,ys,i)*u%i,h=U(f,e,i)*f%i,l=U(h,t,i)*h%i,g=U(l,r,i)*l%i,w=U(g,s,i)*g%i,m=U(w,s,i)*g%i,b=U(m,e,i)*f%i;return{pow_p_5_8:U(b,rt,i)*n%i,b2:c}}function ks(n){return n[0]&=248,n[31]&=127,n[31]|=64,n}const ms=Ce(bs.p,{isLE:!0}),xe=(()=>{const n=ms.ORDER;return ds({P:n,type:"x25519",powPminus2:e=>{const{pow_p_5_8:t,b2:r}=vs(e);return I(U(t,ws,n)*r,n)},adjustScalarBytes:ks})})();/*!
|
|
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 Te(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(Te(n),ut)return n.toHex();let e="";for(let t=0;t<n.length;t++)e+=Yr[n[t]];return e}const H={_0:48,_9:57,A:65,F:70,a:97,f:102};function ze(n){if(n>=H._0&&n<=H._9)return n-H._0;if(n>=H.A&&n<=H.F)return n-(H.A-10);if(n>=H.a&&n<=H.f)return n-(H.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)),c=ze(n.charCodeAt(i+1));if(o===void 0||c===void 0){const a=n[i]+n[i+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+i)}r[s]=o*16+c}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 pe(n){return Te(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 xe=n=>typeof n=="bigint"&&dt<=n;function ts(n,e,t){return xe(n)&&xe(e)&&xe(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 c=n[s];if(o&&c===void 0)return;const a=typeof c;if(a!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${a}`)}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 x=BigInt(0),p=BigInt(1),F=BigInt(2),Bt=BigInt(3),bt=BigInt(4),vt=BigInt(5),ns=BigInt(7),kt=BigInt(8),is=BigInt(9),mt=BigInt(16);function I(n,e){const t=n%e;return t>=x?t:e+t}function U(n,e,t){let r=n;for(;e-- >x;)r*=r,r%=t;return r}function tt(n,e){if(n===x)throw new Error("invert: expected non-zero number");if(e<=x)throw new Error("invert: expected positive modulus, got "+e);let t=I(n,e),r=e,s=x,i=p;for(;t!==x;){const c=r/t,a=r%t,l=s-i*c;r=t,t=a,s=i,i=l}if(r!==p)throw new Error("invert: does not exist");return I(s,e)}function Ce(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+p)/bt,r=n.pow(e,t);return Ce(n,r,e),r}function os(n,e){const t=(n.ORDER-vt)/kt,r=n.mul(e,F),s=n.pow(r,t),i=n.mul(e,s),o=n.mul(n.mul(i,F),s),c=n.mul(i,n.sub(o,n.ONE));return Ce(n,c,e),c}function cs(n){const e=_e(n),t=xt(n),r=t(e,e.neg(e.ONE)),s=t(e,r),i=t(e,e.neg(r)),o=(n+ns)/mt;return(c,a)=>{let l=c.pow(a,o),f=c.mul(l,r);const h=c.mul(l,s),u=c.mul(l,i),g=c.eql(c.sqr(f),a),w=c.eql(c.sqr(h),a);l=c.cmov(l,f,g),f=c.cmov(u,h,w);const v=c.eql(c.sqr(f),a),y=c.cmov(l,f,v);return Ce(c,y,a),y}}function xt(n){if(n<Bt)throw new Error("sqrt is not defined for small field");let e=n-p,t=0;for(;e%F===x;)e/=F,t++;let r=F;const s=_e(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+p)/F;return function(a,l){if(a.is0(l))return l;if(rt(a,l)!==1)throw new Error("Cannot find square root");let f=t,h=a.mul(a.ONE,i),u=a.pow(l,e),g=a.pow(l,o);for(;!a.eql(u,a.ONE);){if(a.is0(u))return a.ZERO;let w=1,v=a.sqr(u);for(;!a.eql(v,a.ONE);)if(w++,v=a.sqr(v),w===f)throw new Error("Cannot find square root");const y=p<<BigInt(f-w-1),C=a.pow(h,y);f=w,h=a.sqr(C),u=a.mul(u,h),g=a.mul(g,C)}return g}}function as(n){return n%bt===Bt?At:n%kt===vt?os:n%mt===is?cs(n):xt(n)}function ls(n,e,t){if(t<x)throw new Error("invalid exponent, negatives unsupported");if(t===x)return n.ONE;if(t===p)return e;let r=n.ONE,s=e;for(;t>x;)t&p&&(r=n.mul(r,s)),s=n.sqr(s),t>>=p;return r}function us(n,e,t=!1){const r=new Array(e.length).fill(t?n.ZERO:void 0),s=e.reduce((o,c,a)=>n.is0(c)?o:(r[a]=o,n.mul(o,c)),n.ONE),i=n.inv(s);return e.reduceRight((o,c,a)=>n.is0(c)?o:(r[a]=n.mul(o,r[a]),n.mul(o,c)),i),r}function rt(n,e){const t=(n.ORDER-p)/F,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 _e(n,e,t=!1,r={}){if(n<=x)throw new Error("invalid field: expected ORDER > 0, got "+n);let s,i,o=!1,c;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),c=u.allowedLengths}else typeof e=="number"&&(s=e),r.sqrt&&(i=r.sqrt);const{nBitLength:a,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:a,BYTES:l,MASK:rs(a),ZERO:x,ONE:p,allowedLengths:c,create:u=>I(u,n),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return x<=u&&u<n},is0:u=>u===x,isValidNot0:u=>!h.is0(u)&&h.isValid(u),isOdd:u=>(u&p)===p,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(c){if(!c.includes(u.length)||u.length>l)throw new Error("Field.fromBytes: expected "+c+" 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?pe(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 ne=BigInt(0),z=BigInt(1),de=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,c=r==="x25519";if(!c&&r!=="x448")throw new Error("invalid type");const a=o||Qr,l=c?255:448,f=c?32:56,h=BigInt(c?9:5),u=BigInt(c?121665:39081),g=c?de**BigInt(254):de**BigInt(447),w=c?BigInt(8)*de**BigInt(251)-z:BigInt(4)*de**BigInt(445)-z,v=g+w+z,y=b=>I(b,t),C=J(h);function J(b){return yt(y(b),f)}function te(b){const m=Qe("u coordinate",b,f);return c&&(m[31]&=127),y(pe(m))}function Be(b){return pe(s(Qe("scalar",b,f)))}function re(b,m){const _=be(te(m),Be(b));if(_===ne)throw new Error("invalid private or public key received");return J(_)}function K(b){return re(b,C)}function W(b,m,_){const fe=y(b*(m-_));return m=y(m-fe),_=y(_+fe),{x_2:m,x_3:_}}function be(b,m){et("u",b,ne,t),et("scalar",m,g,v);const _=m,fe=b;let M=z,O=ne,$=b,P=z,X=ne;for(let ve=BigInt(l-1);ve>=ne;ve--){const qe=_>>ve&z;X^=qe,{x_2:M,x_3:$}=W(X,M,$),{x_2:O,x_3:P}=W(X,O,P),X=qe;const ke=M+O,me=y(ke*ke),Ae=M-O,Ge=y(Ae*Ae),Je=me-Ge,Xr=$+P,Zr=$-P,Ke=y(Zr*ke),We=y(Xr*Ae),Xe=Ke+We,Ze=Ke-We;$=y(Xe*Xe),P=y(fe*y(Ze*Ze)),M=y(me*Ge),O=y(Je*(me+y(u*Je)))}({x_2:M,x_3:$}=W(X,M,$)),{x_2:O,x_3:P}=W(X,O,P);const Wr=i(O);return y(M*Wr)}const he={secretKey:f,publicKey:f,seed:f},se=(b=a(f))=>(Te(b,he.seed),b);function Kr(b){const m=se(b);return{secretKey:m,publicKey:K(m)}}return{keygen:Kr,getSharedSecret:(b,m)=>re(b,m),getPublicKey:b=>K(b),scalarMult:re,scalarMultBase:K,utils:{randomSecretKey:se,randomPrivateKey:se},GuBytes:C.slice(),lengths:he}}/*! 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),St=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),bs={p:St,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=St,c=n*n%i*n%i,a=U(c,st,i)*c%i,l=U(a,gs,i)*n%i,f=U(l,ys,i)*l%i,h=U(f,e,i)*f%i,u=U(h,t,i)*h%i,g=U(u,r,i)*u%i,w=U(g,s,i)*g%i,v=U(w,s,i)*g%i,y=U(v,e,i)*f%i;return{pow_p_5_8:U(y,st,i)*n%i,b2:c}}function ks(n){return n[0]&=248,n[31]&=127,n[31]|=64,n}const ms=_e(bs.p,{isLE:!0}),Se=(()=>{const n=ms.ORDER;return ds({P:n,type:"x25519",powPminus2:e=>{const{pow_p_5_8:t,b2:r}=vs(e);return I(U(t,ws,n)*r,n)},adjustScalarBytes:ks})})();/*!
|
|
2
2
|
* MIT License
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
@@ -21,9 +21,9 @@
|
|
|
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
|
|
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 c=this.toUint8Array(o);s.set(c,i),i+=c.length}return e[e.length-1]instanceof Function?this.toView(s,e[e.length-1]):s.buffer}}const Ee="string",xs=/^[0-9a-f\s]+$/i,Ss=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Es=/^[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 c=s.getUint16(o,t);i+=String.fromCharCode(c)}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 k{static isHex(e){return typeof e===Ee&&xs.test(e)}static isBase64(e){return typeof e===Ee&&Ss.test(e)}static isBase64Url(e){return typeof e===Ee&&Es.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(!k.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(!k.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=k.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=k.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(!k.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,""))||""}}k.DEFAULT_UTF8_ENCODING="utf8";/*!
|
|
25
25
|
Copyright (c) Peculiar Ventures, LLC
|
|
26
|
-
*/function
|
|
26
|
+
*/function Y(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 c=1;c<8;c++){if(n<o){let a;if(r<0)a=new ArrayBuffer(c),i=c;else{if(r<c)return new ArrayBuffer(0);a=new ArrayBuffer(r),i=r}const l=new Uint8Array(a);for(let f=c-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 a}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 Et(){const n=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const c=n[0]===255&&n[1]&128,a=n[0]===0&&(n[1]&128)===0;(c||a)&&this.warnings.push("Needlessly long format")}const e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let c=0;c<this.valueHex.byteLength;c++)t[c]=0;t[0]=n[0]&128;const r=Y(t,8),s=new ArrayBuffer(this.valueHex.byteLength),i=new Uint8Array(s);for(let c=0;c<this.valueHex.byteLength;c++)i[c]=n[c];return i[0]&=127,Y(i,8)-r}function ps(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,c=j(o,8,r),a=new Uint8Array(c);return a[0]|=128,c}let s=j(e,8,r),i=new Uint8Array(s);if(i[0]&128){const o=s.slice(0),c=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),i=new Uint8Array(s);for(let a=0;a<o.byteLength;a++)i[a+1]=c[a];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 E(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
|
|
28
28
|
* Copyright (c) 2015-2022, Peculiar Ventures
|
|
29
29
|
* All rights reserved.
|
|
@@ -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 de(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function _e(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 H(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 He{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return _e(this.items)}}const se=[new Uint8Array([1])],nt="0123456789",Y="",T=new ArrayBuffer(0),Le=new Uint8Array(0),ae="EndOfContent",Et="OCTET STRING",pt="BIT STRING";function L(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?y.toUint8Array(i.valueHex):Le}fromBER(r,s,i){const o=r instanceof ArrayBuffer?new Uint8Array(r):r;if(!H(this,o,s,i))return-1;const c=s+i;return this.valueHexView=o.subarray(s,c),this.valueHexView.length?(this.blockLength=i,c):(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",T)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:v.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class q{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=Y,warnings:r=[],valueBeforeDecode:s=Le}={}){this.blockLength=e,this.error=t,this.warnings=r,this.valueBeforeDecodeView=y.toUint8Array(s)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:v.ToHex(this.valueBeforeDecodeView)}}}q.NAME="baseBlock";class x extends q{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 Nt extends L(q){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?y.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",T}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,c=new Uint8Array(o+1);if(c[0]=t|31,!e){for(let a=0;a<o-1;a++)c[a+1]=i[a]|128;c[o]=i[o-1]}return c.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=y.toUint8Array(e);if(!H(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 c=i[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let a=1,u=this.valueHexView=new Uint8Array(255),f=255;for(;i[a]&128;){if(u[a-1]=i[a]&127,a++,a>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(a===f){f+=255;const l=new Uint8Array(f);for(let g=0;g<u.length;g++)l[g]=u[g];u=this.valueHexView=new Uint8Array(f)}}this.blockLength=a+1,u[a-1]=i[a]&127;const h=new Uint8Array(a);for(let l=0;l<a;l++)h[l]=u[l];u=this.valueHexView=new Uint8Array(a),u.set(h),this.blockLength<=9?this.tagNumber=X(u,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}}}Nt.NAME="identificationBlock";class It extends q{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=y.toUint8Array(e);if(!H(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 c=t+1,a=s.subarray(c,c+o);return a[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=X(a,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",T;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}}}It.NAME="lengthBlock";const d={};class A extends q{constructor({name:e=Y,optional:t=!1,primitiveSchema:r,...s}={},i){super(s),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new Nt(s),this.lenBlock=new It(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 He;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?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=Y,...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 Tt extends L(x){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}Tt.NAME="PrimitiveValueBlock";var Ct;class _t extends A{constructor(e={}){super(e,Tt),this.idBlock.isConstructed=!1}}Ct=_t;d.Primitive=Ct;_t.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 we(n,e=0,t=n.length){const r=e;let s=new A({},x);const i=new q;if(!H(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 c=s.idBlock.fromBER(n,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),c===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=c,t-=s.idBlock.blockLength,c=s.lenBlock.fromBER(n,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),c===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=c,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 a=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};a=d.EndOfContent;break;case 1:a=d.Boolean;break;case 2:a=d.Integer;break;case 3:a=d.BitString;break;case 4:a=d.OctetString;break;case 5:a=d.Null;break;case 6:a=d.ObjectIdentifier;break;case 10:a=d.Enumerated;break;case 12:a=d.Utf8String;break;case 13:a=d.RelativeObjectIdentifier;break;case 14:a=d.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:a=d.Sequence;break;case 17:a=d.Set;break;case 18:a=d.NumericString;break;case 19:a=d.PrintableString;break;case 20:a=d.TeletexString;break;case 21:a=d.VideotexString;break;case 22:a=d.IA5String;break;case 23:a=d.UTCTime;break;case 24:a=d.GeneralizedTime;break;case 25:a=d.GraphicString;break;case 26:a=d.VisibleString;break;case 27:a=d.GeneralString;break;case 28:a=d.UniversalString;break;case 29:a=d.CharacterString;break;case 30:a=d.BmpString;break;case 31:a=d.DATE;break;case 32:a=d.TimeOfDay;break;case 33:a=d.DateTime;break;case 34:a=d.Duration;break;default:{const u=s.idBlock.isConstructed?new d.Constructed:new d.Primitive;u.idBlock=s.idBlock,u.lenBlock=s.lenBlock,u.warnings=s.warnings,s=u}}break;case 2:case 3:case 4:default:a=s.idBlock.isConstructed?d.Constructed:d.Primitive}return s=Is(s,a),c=s.fromBER(n,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=n.subarray(r,r+s.blockLength),{offset:c,result:s}}function Us(n){if(!n.byteLength){const e=new A({},x);return e.error="Input buffer has zero length",{offset:-1,result:e}}return we(y.toUint8Array(n).slice(),0,n.byteLength)}function Vs(n,e){return n?1:e}class O extends x{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r){const s=y.toUint8Array(e);if(!H(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(;Vs(this.isIndefiniteForm,r)>0;){const o=we(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===ae)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===ae?this.value.pop():this.warnings.push("No EndOfContent block encoded")),i}toBER(e,t){const r=t||new He;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,r);return t?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}}O.NAME="ConstructedValueBlock";var Ht;class Q extends A{constructor(e={}){super(e,O),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 ge(){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 Le{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return He(this.items)}}const ie=[new Uint8Array([1])],it="0123456789",Q="",T=new ArrayBuffer(0),Re=new Uint8Array(0),ue="EndOfContent",pt="OCTET STRING",Nt="BIT STRING";function R(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(!L(this,o,s,i))return-1;const c=s+i;return this.valueHexView=o.subarray(s,c),this.valueHexView.length?(this.blockLength=i,c):(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",T)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:k.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class q{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=Q,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:k.ToHex(this.valueBeforeDecodeView)}}}q.NAME="baseBlock";class S extends q{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'")}}S.NAME="valueBlock";class It extends R(q){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",T}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,c=new Uint8Array(o+1);if(c[0]=t|31,!e){for(let a=0;a<o-1;a++)c[a+1]=i[a]|128;c[o]=i[o-1]}return c.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 c=i[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let a=1,l=this.valueHexView=new Uint8Array(255),f=255;for(;i[a]&128;){if(l[a-1]=i[a]&127,a++,a>=i.length)return this.error="End of input reached before message was fully decoded",-1;if(a===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=a+1,l[a-1]=i[a]&127;const h=new Uint8Array(a);for(let u=0;u<a;u++)h[u]=l[u];l=this.valueHexView=new Uint8Array(a),l.set(h),this.blockLength<=9?this.tagNumber=Y(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 Ut extends q{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 c=t+1,a=s.subarray(c,c+o);return a[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Y(a,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",T;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}}}Ut.NAME="lengthBlock";const d={};class A extends q{constructor({name:e=Q,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 Ut(s),this.valueBlock=i?new i(s):new S(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||Vt(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?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():k.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,t=k.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 Vt(n){var e;if(n instanceof d.Constructed)for(const t of n.valueBlock.value)Vt(t)&&(n.lenBlock.isIndefiniteForm=!0);return!!(!((e=n.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class Tt extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor({value:e=Q,...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}'`}}Tt.NAME="BaseStringBlock";class Ct extends R(S){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}Ct.NAME="PrimitiveValueBlock";var _t;class Ht extends A{constructor(e={}){super(e,Ct),this.idBlock.isConstructed=!1}}_t=Ht;d.Primitive=_t;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 ye(n,e=0,t=n.length){const r=e;let s=new A({},S);const i=new q;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 c=s.idBlock.fromBER(n,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),c===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=c,t-=s.idBlock.blockLength,c=s.lenBlock.fromBER(n,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),c===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=c,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 a=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};a=d.EndOfContent;break;case 1:a=d.Boolean;break;case 2:a=d.Integer;break;case 3:a=d.BitString;break;case 4:a=d.OctetString;break;case 5:a=d.Null;break;case 6:a=d.ObjectIdentifier;break;case 10:a=d.Enumerated;break;case 12:a=d.Utf8String;break;case 13:a=d.RelativeObjectIdentifier;break;case 14:a=d.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:a=d.Sequence;break;case 17:a=d.Set;break;case 18:a=d.NumericString;break;case 19:a=d.PrintableString;break;case 20:a=d.TeletexString;break;case 21:a=d.VideotexString;break;case 22:a=d.IA5String;break;case 23:a=d.UTCTime;break;case 24:a=d.GeneralizedTime;break;case 25:a=d.GraphicString;break;case 26:a=d.VisibleString;break;case 27:a=d.GeneralString;break;case 28:a=d.UniversalString;break;case 29:a=d.CharacterString;break;case 30:a=d.BmpString;break;case 31:a=d.DATE;break;case 32:a=d.TimeOfDay;break;case 33:a=d.DateTime;break;case 34:a=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:a=s.idBlock.isConstructed?d.Constructed:d.Primitive}return s=Is(s,a),c=s.fromBER(n,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=n.subarray(r,r+s.blockLength),{offset:c,result:s}}function Us(n){if(!n.byteLength){const e=new A({},S);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ye(B.toUint8Array(n).slice(),0,n.byteLength)}function Vs(n,e){return n?1:e}class D extends S{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(;Vs(this.isIndefiniteForm,r)>0;){const o=ye(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===ue)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===ue?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?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}}D.NAME="ConstructedValueBlock";var Lt;class ee extends A{constructor(e={}){super(e,D),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} :`}}Ht=Q;d.Constructed=Ht;Q.NAME="CONSTRUCTED";class Lt extends x{fromBER(e,t,r){return t}toBER(e){return T}}Lt.override="EndOfContentValueBlock";var Rt;class Mt extends A{constructor(e={}){super(e,Lt),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Rt=Mt;d.EndOfContent=Rt;Mt.NAME=ae;var Ot;class Dt 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}`}}Ot=Dt;d.Null=Ot;Dt.NAME="NULL";class $t extends L(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=y.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,r){const s=y.toUint8Array(e);return H(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,xt.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}$t.NAME="BooleanValueBlock";var Pt;class Ft extends A{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,$t),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Pt=Ft;d.Boolean=Pt;Ft.NAME="BOOLEAN";class jt extends L(O){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=O.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===ae){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?O.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}jt.NAME="OctetStringValueBlock";var Re;class qt 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=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=we(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 Q.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 Re&&e.push(t.valueBlock.valueHexView);return y.concat(e)}}Re=qt;d.OctetString=Re;qt.NAME=Et;class Gt extends L(O){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=O.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(const c of this.value){const a=c.constructor.NAME;if(a===ae){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(a!==pt)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const u=c.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return s}const i=y.toUint8Array(e);if(!H(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 c=o.subarray(1);try{if(c.byteLength){const a=we(c,0,c.byteLength);a.offset!==-1&&a.offset===r-1&&(this.value=[a.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return O.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}}}Gt.NAME="BitStringValueBlock";var Jt;class Me 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},Gt),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 Q.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}`}}}Jt=Me;d.BitString=Jt;Me.NAME=pt;var Kt;function Ts(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,c=s.slice(0),a=c.length-1;let u=0;const f=a<o?o:a;let h=0;for(let l=f;l>=0;l--,h++){switch(!0){case h<c.length:u=i[o-h]+c[a-h]+t[0];break;default:u=i[o-h]+t[0]}switch(t[0]=u/10,!0){case h>=i.length:i=Ne(new Uint8Array([u%10]),i);break;default:i[o-h]=u%10}}return t[0]>0&&(i=Ne(t,i)),i}function it(n){if(n>=se.length)for(let e=se.length;e<=n;e++){const t=new Uint8Array([0]);let r=se[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)),se.push(r)}return se[n]}function Cs(n,e){let t=0;const r=new Uint8Array(n),s=new Uint8Array(e),i=r.slice(0),o=i.length-1,c=s.slice(0),a=c.length-1;let u,f=0;for(let h=a;h>=0;h--,f++)switch(u=i[o-f]-c[a-f]-t,!0){case u<0:t=1,i[o-f]=u+10;break;default:t=0,i[o-f]=u}if(t>0)for(let h=o-a+1;h>=0;h--,f++)if(u=i[o-f]-t,u<0)t=1,i[o-f]=u+10;else{t=0,i[o-f]=u;break}return i.slice()}class Oe extends L(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=xt.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(ps(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="",c=!1;for(let a=i.byteLength-1;a>=0;a--){s=i[a];for(let u=0;u<8;u++){if((s&1)===1)switch(r){case e:t=Cs(it(r),t),o="-";break;default:t=Ts(t,it(r))}r++,s>>=1}}for(let a=0;a<t.length;a++)t[a]&&(c=!0),c&&(o+=nt.charAt(t[a]));return c===!1&&(o+=nt.charAt(0)),o}}Kt=Oe;Oe.NAME="IntegerValueBlock";Object.defineProperty(Kt.prototype,"valueHex",{set:function(n){this.valueHexView=new Uint8Array(n),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var oe;class De extends A{constructor(e={}){super(e,Oe),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return de(),BigInt(this.valueBlock.toString())}static fromBigInt(e){de();const t=BigInt(e),r=new He,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(v.FromHex(s));if(t<0){const c=new Uint8Array(i.length+(i[0]&128?1:0));c[0]|=128;const u=BigInt(`0x${v.ToHex(c)}`)+t,f=y.toUint8Array(v.FromHex(u.toString(16)));f[0]|=128,r.write(f)}else i[0]&128&&r.write(new Uint8Array([0])),r.write(i);return new oe({valueHex:r.final()})}convertToDER(){const e=new oe({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new oe({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}oe=De;d.Integer=oe;De.NAME="INTEGER";var Wt;class Zt extends De{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}Wt=Zt;d.Enumerated=Wt;Zt.NAME="ENUMERATED";class Ie extends L(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=y.toUint8Array(e);if(!H(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let c=0;c<r&&(this.valueHexView[c]=i[c]&127,this.blockLength++,!!(i[c]&128));c++);const o=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)o[c]=this.valueHexView[c];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=X(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){de();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",T;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=Y,...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;t.push(s)}return _e(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 c=0;switch(o.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}const a=parseInt(s,10);if(isNaN(a))return;o.valueDec=a+c,i=!1}else{const o=new Ie;if(s>Number.MAX_SAFE_INTEGER){de();const c=BigInt(s);o.valueBigInt=c}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 Xt;class $e 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()}}}Xt=$e;d.ObjectIdentifier=Xt;$e.NAME="OBJECT IDENTIFIER";class Ue extends L(q){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(r===0)return t;const s=y.toUint8Array(e);if(!H(this,s,t,r))return-1;const i=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let c=0;c<r&&(this.valueHexView[c]=i[c]&127,this.blockLength++,!!(i[c]&128));c++);const o=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)o[c]=this.valueHexView[c];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=X(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",T;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}}}Ue.NAME="relativeSidBlock";class Yt extends x{constructor({value:e=Y,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Ue;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,T;r.push(i)}return _e(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 Ue;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}}Yt.NAME="RelativeObjectIdentifierValueBlock";var Qt;class er extends A{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Yt),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Qt=er;d.RelativeObjectIdentifier=Qt;er.NAME="RelativeObjectIdentifier";var tr;class ge extends Q{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}tr=ge;d.Sequence=tr;ge.NAME="SEQUENCE";var rr;class sr extends Q{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}rr=sr;d.Set=rr;sr.NAME="SET";class nr extends L(x){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Y}toJSON(){return{...super.toJSON(),value:this.value}}}nr.NAME="StringValueBlock";class ir extends nr{}ir.NAME="SimpleStringValueBlock";class N extends Vt{constructor({...e}={}){super(e,ir)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,y.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 or extends N{fromBuffer(e){this.valueBlock.valueHexView=y.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}}or.NAME="Utf8StringValueBlock";var cr;class G extends or{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}cr=G;d.Utf8String=cr;G.NAME="UTF8String";class ar extends N{fromBuffer(e){this.valueBlock.value=v.ToUtf16String(e),this.valueBlock.valueHexView=y.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(v.FromUtf16String(e))}}ar.NAME="BmpStringValueBlock";var lr;class ur extends ar{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}lr=ur;d.BmpString=lr;ur.NAME="BMPString";class hr 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 c=4-o.length;for(let a=o.length-1;a>=0;a--)r[s*4+a+c]=o[a]}this.valueBlock.value=e}}hr.NAME="UniversalStringValueBlock";var fr;class dr extends hr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}fr=dr;d.UniversalString=fr;dr.NAME="UniversalString";var gr;class wr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}gr=wr;d.NumericString=gr;wr.NAME="NumericString";var yr;class Br extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}yr=Br;d.PrintableString=yr;Br.NAME="PrintableString";var br;class vr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}br=vr;d.TeletexString=br;vr.NAME="TeletexString";var kr;class mr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}kr=mr;d.VideotexString=kr;mr.NAME="VideotexString";var Ar;class Sr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}Ar=Sr;d.IA5String=Ar;Sr.NAME="IA5String";var xr;class Er extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}xr=Er;d.GraphicString=xr;Er.NAME="GraphicString";var pr;class Pe extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}pr=Pe;d.VisibleString=pr;Pe.NAME="VisibleString";var Nr;class Ir extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Nr=Ir;d.GeneralString=Nr;Ir.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 Tr;class Fe extends Pe{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,y.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]=E(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=E(this.month,2),t[2]=E(this.day,2),t[3]=E(this.hour,2),t[4]=E(this.minute,2),t[5]=E(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}}}Tr=Fe;d.UTCTime=Tr;Fe.NAME="UTCTime";var Cr;class _r extends Fe{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,c=0,a=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,l=r.indexOf("+"),g="";if(l===-1&&(l=r.indexOf("-"),h=-1),l!==-1){if(g=r.substring(l+1),r=r.substring(0,l),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(c=h*w,g.length===4){if(w=parseInt(g.substring(2,4),10),isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");a=h*w}}}let u=r.indexOf(".");if(u===-1&&(u=r.indexOf(",")),u!==-1){const h=new Number(`0${r.substring(u)}`);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");i=h.valueOf(),s=r.substring(0,u)}else s=r;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,u!==-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,u!==-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,u!==-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,u!==-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)+c;break;case 5:this.minute=parseInt(f[h],10)+a;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(E(this.year,4)),t.push(E(this.month,2)),t.push(E(this.day,2)),t.push(E(this.hour,2)),t.push(E(this.minute,2)),t.push(E(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(E(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}Cr=_r;d.GeneralizedTime=Cr;_r.NAME="GeneralizedTime";var Hr;class Lr extends G{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}Hr=Lr;d.DATE=Hr;Lr.NAME="DATE";var Rr;class Mr extends G{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}Rr=Mr;d.TimeOfDay=Rr;Mr.NAME="TimeOfDay";var Or;class Dr extends G{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}Or=Dr;d.DateTime=Or;Dr.NAME="DateTime";var $r;class Pr extends G{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}$r=Pr;d.Duration=$r;Pr.NAME="Duration";var Fr;class jr extends G{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}Fr=jr;d.TIME=Fr;jr.NAME="TIME";function _s(n){const e=n.slice().buffer,t=new ge({value:[new $e({value:"1.3.101.110"})]}),r=new Me({valueHex:e}),s=new ge({value:[t,r]});return new Uint8Array(s.toBER())}function Hs(n){const e=n.slice().buffer,s=Us(e).result.valueBlock.value[1];return new Uint8Array(s.valueBlock.valueHex)}function ne(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}function ie(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 ot(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 ce(n){return n.buffer}async function Ls(n,e,t,r){const s=await crypto.subtle.importKey("raw",ce(n),"HKDF",!1,["deriveBits"]),i=await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:ce(e),info:ce(t)},s,r*8);return new Uint8Array(i)}async function Rs(n){return crypto.subtle.importKey("raw",ce(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"])}async function Ms(n,e){const t=await crypto.subtle.sign("HMAC",n,ce(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,ot(t),ot(e))}class qr{constructor(e){this.ws=null,this.listeners={},this.subscriptions={request:{},status:{},topic:{}},this._shouldReconnect=!0,this._reconnectAttempt=0,this.generateRandomString=t=>{let r="";for(;r.length<t;)r+=Math.random().toString(36).substring(2,2+(t-r.length));return r},this.client=e}scheduleReconnect(){if(!this._shouldReconnect)return;const e=Math.min(3e4,1e3*2**this._reconnectAttempt);this._reconnectAttempt++,setTimeout(()=>{this._connectPromise=void 0,this.connect().catch(()=>{})},e)}close(){var e;this._shouldReconnect=!1,this._connectPromise=void 0,(e=this.ws)==null||e.close(),this.ws=null}async connect(){var e;if(await this.client.ensureSession(),!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))){if(this._connectPromise)return this._connectPromise;this._connectPromise=(async()=>{const{ans:t}=await this.client.get("/url/notifications"),{url:r}=t.data[0];this.ws=new WebSocket(r),this.ws.onopen=()=>{this._reconnectAttempt=0,console.log("Notifications connected")},this.ws.onmessage=async s=>{try{const i=JSON.parse(s.data),o=await this.client.decryptAndVerify(i),c=this.subscriptions.request[o==null?void 0:o.correlation_id];c&&Object.values(c).length>0&&Object.values(c).forEach(f=>f(o));const a=this.subscriptions.status[o==null?void 0:o.status];a&&Object.values(a).length>0&&Object.values(a).forEach(f=>f(o));const u=this.subscriptions.topic[o==null?void 0:o.topic];u&&Object.values(u).length>0&&Object.values(u).forEach(f=>f(o)),Object.values(this.listeners).forEach(f=>f(o))}catch(i){console.warn("Failed to process notification:",i)}},this.ws.onerror=s=>{console.error("Notifications error",s)},this.ws.onclose=()=>{this.scheduleReconnect(),console.log("Notifications closed")}})();try{await this._connectPromise}finally{((e=this.ws)==null?void 0:e.readyState)===WebSocket.OPEN?this._connectPromise=void 0:(!this.ws||this.ws.readyState===WebSocket.CLOSED)&&(this._connectPromise=void 0)}}}unsuscribe(e,t,r){delete this.subscriptions[e][t][r]}unlisten(e){delete this.listeners[e]}suscribe(e,t,r,s){let i=s;return i==null&&(i=this.generateRandomString(16)),this.subscriptions[e]||(this.subscriptions[e]={}),this.subscriptions[e][t]||(this.subscriptions[e][t]={}),this.subscriptions[e][t][i]=r,()=>this.unsuscribe(e,t,i)}onMessage(e,t){let r=t;return r==null&&(r=this.generateRandomString(16)),this.listeners[r]=e,()=>this.unlisten(r)}disconnect(){var e;(e=this.ws)==null||e.close(),this.ws=null}}const ct="secure_api_session_v1";class Gr{constructor(e){this.session=null,this.baseUrl=e.baseUrl,this.clientId=e.clientId,this.serverPublicKeyPem=e.serverPublicKeyPem,this.clientIdentityKeyPromise=Ps(e.clientIdentityPrivateKeyPem),this.loadPersistedSession(),this.notifications=new qr(this)}loadPersistedSession(){try{const e=localStorage.getItem(ct);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(ct,JSON.stringify(t))}catch{}}async handshake(){const e=await this.clientIdentityKeyPromise,t=xe.utils.randomSecretKey(),r=xe.getPublicKey(t),s=_s(r),i=ne(s),o=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,Fs(s)),c=js(new Uint8Array(o)),a=ne(c),u=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:a,client_alg:"ES256"})});if(!u.ok)throw new Error(`Handshake failed: ${u.status} ${u.statusText}`);const f=await u.json(),{session_id:h,server_pub:l,server_sig:g,session_expires_at:w}=f;if(window.__akv={server_pub:l,server_sig:g},!h||!l||!g)throw new Error("Handshake response missing fields");const m=ie(l),b=ie(g);if(!await Ds(this.serverPublicKeyPem,m,b))throw new Error("Server signature verification failed");const le=Hs(m),ye=xe.getSharedSecret(t,le),Be=new Uint8Array(0),ee=new TextEncoder().encode("health-api-v1"),J=await Ls(ye,Be,ee,64),K=J.slice(0,32),be=J.slice(32,64),ue=await crypto.subtle.importKey("raw",K,"AES-GCM",!1,["encrypt","decrypt"]),te=await Rs(be);this.updateSession({sessionId:h,encKey:ue,macKey:te,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:ne(new Uint8Array(i)),ivB64:ne(r)}}async signRequest(e,t,r){await this.ensureSession();const{sessionId:s,macKey:i}=this.session,o=e.toUpperCase()==="GET"?"":{data:Array.isArray(r)?r:[r]},{ciphertextB64:c,ivB64:a}=await this.encryptBody(o),u=Math.floor(Date.now()/1e3).toString();let f=t;f.includes("?")&&(f=f.split("?")[0]);const h=`${e.toUpperCase()} ${f}
|
|
63
|
-
${
|
|
64
|
-
${
|
|
62
|
+
`)}`:`${t} :`}}Lt=ee;d.Constructed=Lt;ee.NAME="CONSTRUCTED";class Rt extends S{fromBER(e,t,r){return t}toBER(e){return T}}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=ue;var Dt;class $t extends A{constructor(e={}){super(e,S),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 R(S){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,Et.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 R(D){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=D.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===ue){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==pt)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?D.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=ye(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 ee.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,t=k.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=pt;class Jt extends R(D){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=D.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(const c of this.value){const a=c.constructor.NAME;if(a===ue){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(a!==Nt)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const l=c.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 c=o.subarray(1);try{if(c.byteLength){const a=ye(c,0,c.byteLength);a.offset!==-1&&a.offset===r-1&&(this.value=[a.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return D.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 ee.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 Ts(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,c=s.slice(0),a=c.length-1;let l=0;const f=a<o?o:a;let h=0;for(let u=f;u>=0;u--,h++){switch(!0){case h<c.length:l=i[o-h]+c[a-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>=ie.length)for(let e=ie.length;e<=n;e++){const t=new Uint8Array([0]);let r=ie[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)),ie.push(r)}return ie[n]}function Cs(n,e){let t=0;const r=new Uint8Array(n),s=new Uint8Array(e),i=r.slice(0),o=i.length-1,c=s.slice(0),a=c.length-1;let l,f=0;for(let h=a;h>=0;h--,f++)switch(l=i[o-f]-c[a-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-a+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 R(S){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=Et.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(ps(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="",c=!1;for(let a=i.byteLength-1;a>=0;a--){s=i[a];for(let l=0;l<8;l++){if((s&1)===1)switch(r){case e:t=Cs(ot(r),t),o="-";break;default:t=Ts(t,ot(r))}r++,s>>=1}}for(let a=0;a<t.length;a++)t[a]&&(c=!0),c&&(o+=it.charAt(t[a]));return c===!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 ae;class $e extends A{constructor(e={}){super(e,De),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return ge(),BigInt(this.valueBlock.toString())}static fromBigInt(e){ge();const t=BigInt(e),r=new Le,s=t.toString(16).replace(/^-/,""),i=new Uint8Array(k.FromHex(s));if(t<0){const c=new Uint8Array(i.length+(i[0]&128?1:0));c[0]|=128;const l=BigInt(`0x${k.ToHex(c)}`)+t,f=B.toUint8Array(k.FromHex(l.toString(16)));f[0]|=128,r.write(f)}else i[0]&128&&r.write(new Uint8Array([0])),r.write(i);return new ae({valueHex:r.final()})}convertToDER(){const e=new ae({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new ae({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}ae=$e;d.Integer=ae;$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 R(S){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 c=0;c<r&&(this.valueHexView[c]=i[c]&127,this.blockLength++,!!(i[c]&128));c++);const o=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)o[c]=this.valueHexView[c];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=Y(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){ge();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",T;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=k.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 S{constructor({value:e=Q,...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;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 c=0;switch(o.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}const a=parseInt(s,10);if(isNaN(a))return;o.valueDec=a+c,i=!1}else{const o=new Ie;if(s>Number.MAX_SAFE_INTEGER){ge();const c=BigInt(s);o.valueBigInt=c}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 Ue extends R(q){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 c=0;c<r&&(this.valueHexView[c]=i[c]&127,this.blockLength++,!!(i[c]&128));c++);const o=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)o[c]=this.valueHexView[c];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=Y(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",T;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=k.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Ue.NAME="relativeSidBlock";class Qt extends S{constructor({value:e=Q,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const i=new Ue;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,T;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 Ue;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 we extends ee{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}rr=we;d.Sequence=rr;we.NAME="SEQUENCE";var sr;class nr extends ee{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}sr=nr;d.Set=sr;nr.NAME="SET";class ir extends R(S){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Q}toJSON(){return{...super.toJSON(),value:this.value}}}ir.NAME="StringValueBlock";class or extends ir{}or.NAME="SimpleStringValueBlock";class N extends Tt{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=k.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=k.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(k.FromUtf8String(e)),this.valueBlock.value=e}}cr.NAME="Utf8StringValueBlock";var ar;class G extends cr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}ar=G;d.Utf8String=ar;G.NAME="UTF8String";class lr extends N{fromBuffer(e){this.valueBlock.value=k.ToUtf16String(e),this.valueBlock.valueHexView=B.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(k.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 c=4-o.length;for(let a=o.length-1;a>=0;a--)r[s*4+a+c]=o[a]}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 kr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}vr=kr;d.TeletexString=vr;kr.NAME="TeletexString";var mr;class Ar extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}mr=Ar;d.VideotexString=mr;Ar.NAME="VideotexString";var xr;class Sr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}xr=Sr;d.IA5String=xr;Sr.NAME="IA5String";var Er;class pr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}Er=pr;d.GraphicString=Er;pr.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 Ur extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Ir=Ur;d.GeneralString=Ir;Ur.NAME="GeneralString";var Vr;class Tr extends N{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}Vr=Tr;d.CharacterString=Vr;Tr.NAME="CharacterString";var Cr;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]=E(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=E(this.month,2),t[2]=E(this.day,2),t[3]=E(this.hour,2),t[4]=E(this.minute,2),t[5]=E(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}}}Cr=je;d.UTCTime=Cr;je.NAME="UTCTime";var _r;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,c=0,a=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(c=h*w,g.length===4){if(w=parseInt(g.substring(2,4),10),isNaN(w.valueOf()))throw new Error("Wrong input string for conversion");a=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)+c;break;case 5:this.minute=parseInt(f[h],10)+a;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(E(this.year,4)),t.push(E(this.month,2)),t.push(E(this.day,2)),t.push(E(this.hour,2)),t.push(E(this.minute,2)),t.push(E(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(E(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}}_r=Hr;d.GeneralizedTime=_r;Hr.NAME="GeneralizedTime";var Lr;class Rr extends G{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 G{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 G{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 G{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 G{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}jr=qr;d.TIME=jr;qr.NAME="TIME";function _s(n){const e=n.slice().buffer,t=new we({value:[new Pe({value:"1.3.101.110"})]}),r=new Oe({valueHex:e}),s=new we({value:[t,r]});return new Uint8Array(s.toBER())}function Hs(n){const e=n.slice().buffer,s=Us(e).result.valueBlock.value[1];return new Uint8Array(s.valueBlock.valueHex)}function oe(n){let e="";for(let t=0;t<n.length;t++)e+=String.fromCharCode(n[t]);return btoa(e)}function ce(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 le(n){return n.buffer}async function Ls(n,e,t,r){const s=await crypto.subtle.importKey("raw",le(n),"HKDF",!1,["deriveBits"]),i=await crypto.subtle.deriveBits({name:"HKDF",hash:"SHA-256",salt:le(e),info:le(t)},s,r*8);return new Uint8Array(i)}async function Rs(n){return crypto.subtle.importKey("raw",le(n),{name:"HMAC",hash:"SHA-256"},!1,["sign"])}async function Ms(n,e){const t=await crypto.subtle.sign("HMAC",n,le(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 Ve{constructor(e){this.ws=null,this.listeners={},this.subscriptions={request:{},status:{},topic:{}},this._shouldReconnect=!0,this._reconnectAttempt=0,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 c=this.subscriptions.status[s];c&&Object.values(c).forEach(l=>l(t));const a=this.subscriptions.topic[i];a&&Object.values(a).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)return;const e=Math.min(3e4,1e3*2**this._reconnectAttempt);this._reconnectAttempt++,setTimeout(()=>{this._connectPromise=void 0,this.connect().catch(()=>{})},e)}close(){var e;this._shouldReconnect=!1,this._connectPromise=void 0,(e=this.ws)==null||e.close(),this.ws=null}async connect(){var e;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))){if(this._connectPromise)return this._connectPromise;this._connectPromise=(async()=>{const t=await this.client.get("/url/notifications"),{url:r}=t.data[0];this.ws=new WebSocket(r),this.ws.onopen=()=>{this._reconnectAttempt=0},this.ws.onmessage=async s=>{try{const i=JSON.parse(s.data);if(!i.ciphertext){const{operation_id:h,iv:u,signature:g,topic:w,correlation_id:v,...y}=i;if(!h)throw new Error("Claim check received but missing operation_id");const C=await this.executeWithRetry(()=>this.client.get(`/responses/${h}`,{},!0)),J={...y,topic:w,correlation_id:v,ciphertext:C.data,iv:u,signature:g},te=await this.client.decryptAndVerify(J);this.distributeMessage(te);return}const o=i.page_id,c=i.chunk_num,a=i.total_chunks;let l=i;if(a>1){this.chunkBuffers[o]||(this.chunkBuffers[o]={chunks:new Array(a),count:0,total:a});const h=this.chunkBuffers[o];if(h.chunks[c]===void 0&&(h.chunks[c]=i.ciphertext,h.count++),h.count<h.total)return;l={...i,ciphertext:h.chunks.join("")},delete this.chunkBuffers[o]}const f=await this.client.decryptAndVerify(l);this.distributeMessage(f)}catch(i){console.warn("Failed to process notification:",i)}},this.ws.onerror=s=>{console.error("Notifications error",s)},this.ws.onclose=()=>{this.scheduleReconnect(),console.log("Notifications closed")}})();try{await this._connectPromise}finally{((e=this.ws)==null?void 0:e.readyState)===WebSocket.OPEN?this._connectPromise=void 0:(!this.ws||this.ws.readyState===WebSocket.CLOSED)&&(this._connectPromise=void 0)}}}unsubscribe(e,t,r){delete this.subscriptions[e][t][r]}unlisten(e){delete this.listeners[e]}subscribe(e,t,r,s){let i=s;return i==null&&(i=this.generateRandomString(16)),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;return r==null&&(r=this.generateRandomString(16)),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 Ve(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=Se.utils.randomSecretKey(),r=Se.getPublicKey(t),s=_s(r),i=oe(s),o=await crypto.subtle.sign({name:"ECDSA",hash:"SHA-256"},e,Fs(s)),c=js(new Uint8Array(o)),a=oe(c),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:a,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=ce(u),y=ce(g);if(!await Ds(this.serverPublicKeyPem,v,y))throw new Error("Server signature verification failed");const J=Hs(v),te=Se.getSharedSecret(t,J),Be=new Uint8Array(0),re=new TextEncoder().encode("health-api-v1"),K=await Ls(te,Be,re,64),W=K.slice(0,32),be=K.slice(32,64),he=await crypto.subtle.importKey("raw",W,"AES-GCM",!1,["encrypt","decrypt"]),se=await Rs(be);this.updateSession({sessionId:h,encKey:he,macKey:se,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:oe(new Uint8Array(i)),ivB64:oe(r)}}async signRequest(e,t,r,s){await this.ensureSession();const{sessionId:i,macKey:o}=this.session,c=e.toUpperCase()==="GET"?"":{data:Array.isArray(r)?r:[r]},{ciphertextB64:a,ivB64:l}=await this.encryptBody(c),f=Math.floor(Date.now()/1e3).toString();let h=t;h.includes("?")&&(h=h.split("?")[0]);const u=`${e.toUpperCase()} ${h}
|
|
63
|
+
${f}
|
|
64
|
+
${a}`,g=await Ms(o,new TextEncoder().encode(u)),w=oe(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:a,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}`);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 c=>{const{data:a,...l}=c;if(Object.keys(this.pagingBuffer).includes(i)||(this.pagingBuffer[i]={pages:new Array(l.pages),count:0,total:l.pages}),this.pagingBuffer[i].pages[l.page-1]=l,this.pagingBuffer[i].count++,l.pages>l.page&&l.next_page&&this.pagingBuffer[i].count<this.pagingBuffer[i].total){this.get(`/signal/paging/${l.next_page}`,o);return}if(t)return t(this.pagingBuffer[i].pages)}),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.pages>s.page&&s.next_page;)s=await this.get(`/signal/paging/${s.next_page}`,{...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:c}=this.getSession(),a=ce(s),l=await crypto.subtle.sign("HMAC",c,new TextEncoder().encode(t));if(!this.constantTimeEqual(a,new Uint8Array(l)))throw new Error("Invalid notification signature");const f=Uint8Array.from(ce(r)),h=Uint8Array.from(ce(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),"email"in e&&"socialLoginId"in e&&(t.email=e.email,t.social_login_id=e.socialLoginId,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:c}=r.data[0];return s&&this.updateSession({accessToken:s}),i&&this.updateSession({tokenType:i}),o&&this.updateSession({expiresAt:o}),c&&this.updateSession({refreshToken:c}),{accessToken:s,tokenType:i,expiresAt:o,refreshToken:c}}async logout(){await this.post("/oauth/logout",{}),this.updateSession({accessToken:void 0,tokenType:void 0,expiresAt:void 0,refreshToken:void 0}),this.notifications=new Ve(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),c=2+i.length+2+o.length,a=new Uint8Array(2+c);let l=0;return a[l++]=48,a[l++]=c,a[l++]=2,a[l++]=i.length,a.set(i,l),l+=i.length,a[l++]=2,a[l++]=o.length,a.set(o,l),a}const Jr=Symbol("SDK_CLIENT"),qs={install(n,e){const t=new Gr(e);n.provide(Jr,t)}};exports.Notifications=Ve;exports.SDK_CLIENT=Jr;exports.SdkPlugin=qs;exports.SecureApiClient=Gr;
|
|
65
65
|
//# sourceMappingURL=index.cjs.map
|