@zkpass/zkfetch
Version:
zkFetch using zkTLS is a system that enables verifiable fetching of HTTPS data using zero-knowledge proofs (ZKPs). It ensures that the response from a remote TLS server (like a Web2 API) is authentic, integrity-preserved, and can be publicly verified—with
10 lines • 739 kB
JavaScript
var dE=Object.defineProperty;var u=(a,e)=>dE(a,"name",{value:e,configurable:!0});import NC from"aes-js";import{randBytesSync as DC}from"bigint-crypto-utils";import{Buffer as VC}from"buffer";var Ut=u(a=>{let e="";for(let t of a)e+=String.fromCharCode(t);return e},"u8Array2Str"),le=u(a=>{let e=new Uint8Array(a.length);for(let t=0;t<a.length;t++)e[t]=a.charCodeAt(t);return e},"str2U8Array"),_e=u(a=>{let e=Array(a.length*8),t=0;for(let s=a.length-1;s>=0;s--)for(let n=0;n<8;n++)e[t]=a[s]>>n&1,t++;return e},"u8Array2Bits");function bo(a){return Array.from(a,e=>("0"+(e&255).toString(16)).slice(-2)).join("")}u(bo,"bytes2Hex");function No(a){let e=[];for(let t=0;t<a.length;t+=2)e.push(parseInt(a.substring(t,t+2),16));return new Uint8Array(e)}u(No,"hex2Bytes");var Is=u((...a)=>{let e=[];for(let t of a)e=e.concat(Array.from(t));return new Uint8Array(e)},"concatArray"),vo=u((a,e)=>{let t=a.toString(16);t.length%2===1&&(t=`0${t}`);let s=[];for(let r=0;r<t.length/2;r++)s.push(parseInt(t.slice(2*r,2*r+2),16));let n=s.length;return e&&n<e?Is(new Uint8Array(e-n).fill(0),new Uint8Array(s)):e&&n>e?new Uint8Array(s.splice(0,e)):new Uint8Array(s)},"int2U8Array");var Do=u(a=>{let e=new Uint8Array(a.length/8);for(let t=0;t<e.length;t++){let s=0;for(let n=0;n<8;n++)s+=a[t*8+n]*2**n;e[e.length-1-t]=s}return e},"bits2U8Array");var yf=u(a=>a.toString(2).split("").map(e=>+e),"int2Bits");function da(a){try{return/^(-?\d+)(\.\d+)$/.test(a)}catch{return!1}}u(da,"isFloatNumber");function If(a){try{return/^-?\d+(\.\d+)?$/.test(a)}catch{return!1}}u(If,"isNumber");function mE(a){let t=new TextEncoder().encode(a),s="";for(let n of Array.from(t))s+=String.fromCharCode(n);return s}u(mE,"recoverStr");function Ig(a){return a.forEach(e=>{typeof e.value=="string"&&(e.value=mE(e.value))}),a}u(Ig,"formatAsserts");function Cf(a){let t=typeof a=="bigint"?a:BigInt(a);return Number(t>>22n)+15768e8}u(Cf,"extractTimestamp");function Cg(a){if(a.length==0)return{};if(a[0]!==123&&a[0]!==91)throw"invalid json bytes";let e=0;function t(){for(;a[e]===10||a[e]===32||a[e]===92&&[92,114,116].includes(a[e+1]);)e++}u(t,"skipWhiteSpace");function s(h,d){if(a.slice(e,e+h.length).join("")===Array.from(le(`${d}`)).join(""))return e+=h.length,d}u(s,"parseKeyword");function n(){if(t(),a[e]!==58)throw new Error('Expected ":"');t(),e++}u(n,"parseColon");function r(){if(t(),a[e]!==44)throw new Error('Expected ","');t(),e++}u(r,"parseComma");function i(){if(t(),a[e]===34){e++;let h=[];for(;a[e]!==34||a[e]===34&&a[e-1]===92;)a[e]===92?(h.push(...a.slice(e,e+2)),e+=2):(h.push(a[e]),e++);return e++,Ut(new Uint8Array(h))}}u(i,"parseString");function o(){if(t(),a[e]===123&&a[e-1]!==92){let h=[];e++,t();let d={},f=!0;for(;a[e]!==125||a[e]===125&&a[e-1]===92;){f||(r(),t());let p=e,E=i()||"",m=e;t(),n(),f=!1,t();let B=e,{value:I,type:y}=A(),C=e;t(),h.push(E),y==="string"&&(B+=1,C-=1),d[E]={keyStart:p,keyEnd:m,keyStr:Ut(new Uint8Array(a.slice(p,m))),start:B,end:C},y==="object"||y==="array"?d[E].children=I:d[E].value=I}return e++,d}}u(o,"parseObject");function c(){if(a[e]===91&&a[e-1]!==92){e++,t();let h=[],d=!0;for(;a[e]!==93||a[e]===93&&a[e-1]===92;){d||r(),t();let f=e,{value:p,type:E}=A(),m=e;t(),E==="string"&&(f+=1,m-=1);let B={value:p,start:f,end:m};E==="object"||E==="array"?B.children=p:B.value=p,h.push(B),d=!1}return e++,{...h}}}u(c,"parseArray");function l(){let h=e;if(a[e]===45&&e++,a[e]===48)e++;else if(a[e]>=49&&a[e]<=57)for(e++;a[e]>=48&&a[e]<=57;)e++;if(a[e]===46)for(e++;a[e]>=48&&a[e]<=57;)e++;if(a[e]===101||a[e]===69)for(e++,(a[e]===45||a[e]===43)&&e++;a[e]>=48&&a[e]<=57;)e++;if(e>h)return Ut(new Uint8Array(a.slice(h,e)))}u(l,"parseNumber");function A(){let h=i();return typeof h<"u"?{value:h,type:"string"}:(h=o(),typeof h<"u"?{value:h,type:"object"}:(h=c(),typeof h<"u"?{value:h,type:"array"}:(h=l(),typeof h<"u"?{value:h,type:"number"}:(h=s("true",!0),typeof h<"u"?{value:h,type:"boolean"}:(h=s("null",null),typeof h<"u"?{value:h,type:"null"}:(h=s("false",!1),typeof h<"u"?{value:h,type:"boolean"}:(t(),{value:h,type:"undefined"})))))))}return u(A,"parseValue"),t(),A().value}u(Cg,"parseJsonGrammarTree");function kn(a){return Cg(Array.from(le(a)))}u(kn,"customJsonParse");import Qo from"lodash";function ma(a,e,t){let s=a-a%16,n=e%16>0?e+16-e%16:e;n>t&&(n=t);let r=s,i=[],o=[];for(;r<n;){let c=r+16,l=Math.ceil(c/16);i.push(l);let A=c>n?n:c;o.push({counter:l,start:r,end:A,len:A-r}),r+=A-r}return{start:o[0].start,end:o[o.length-1].end,counterList:i,blockList:o}}u(ma,"padToAes128Block");function fE(a,e){let t=a;for(;e.length>0;){let s=e.shift()||"";if(t=t[s],typeof t>"u")throw"You do not meet the required criteria"}return Qo.toString(t)}u(fE,"pickValueByKeys");function wE(a,e,t){let s=a;for(;e.length>0;){let n=e.shift()||"";if(s=s[n],typeof s>"u")throw t?`You do not meet the required criteria. Please check the following criteria. \r
\r
${t}`:"You do not meet the required criteria"}return s}u(wE,"pickAllValueByKeys");function BE(a,e){let t=a;for(;e.length>0;){let s=e.shift()||"";if(e.length===0)return Object.keys(t).includes(s);if(t=t[s],typeof t>"u"&&e.length>0)throw"You do not meet the required criteria"}return!0}u(BE,"isContainKey");function bf(a){return Qo.isArray(a)&&(a=a.filter(e=>!(typeof e>"u"))),Object.keys(a).forEach(e=>{typeof a[e]=="object"&&(a[e]=bf(a[e]))}),a}u(bf,"removeEmptyElements");function Nf(a,e=[]){let t=e.filter(r=>r.isPublic);if(t.length===0)return null;let s="",n=Qo.isArray(a)?[]:{};for(let r=0;r<t.length;r++){let i=t[r].key.split("|"),o=wE(a,t[r].key.split("|"));s=`${s}${JSON.stringify(o)}`;let c=n;for(let l=0;l<i.length;l++){let A=isNaN(parseInt(i[l]))?i[l]:parseInt(i[l]),h=isNaN(parseInt(i[l+1]))?i[l+1]:parseInt(i[l+1]);typeof c[A]>"u"&&(typeof h=="number"?c[A]=[]:c[A]={}),l==i.length-1?c[A]=o:c=c[A]}}return n=bf(n),{data:n,str:s}}u(Nf,"checkPublicFields");function Mf(a,e,t=0){let s=a.slice(t).join(","),n=e.join(","),r=s.indexOf(n);return r===0?t:r<0?-1:s.substring(0,r-1).split(",").length+t}u(Mf,"findStartIndex");function Lu(a,e,t){let s=Array.from(le(e)),n=0,r=0,i=t.map(c=>{let l=Array.from(le(c)),A=Mf(s,l,n);return n=A+l.length,r+=l.length,{start:A,end:n}}),o=0;return a.map((c,l)=>{let A=c.data,h=Mf(s,A,o),d=h+A.length;for(let E=0;E<i.length;E++)if(i[E].end>=h&&i[E].end<h+A.length){d=i[E].end;break}let f=0,p=i.find(E=>h<E.start&&E.start<d);return p?f=p.start-h:(i[0].start>=d||i[i.length-1].end<=h)&&(f=d-h),o=h+A.length,{start:h,end:d,headerLen:f,index:l}})}u(Lu,"findBoundaryForRecords");function vf(a,e){let t=a.join(""),s=Math.max(t.lastIndexOf("]"),t.lastIndexOf("}"));t=t.substring(0,s+1);let n=Array.from(le(t)),r=u(o=>{try{for(let c of Object.keys(o)){let l=o[c];if(l.children)r(l.children);else{let A=l.end-l.start,h=new Array(A).fill(49);if(da(l.value)){let d=`${l.value}`.indexOf(".");h.splice(d,1,46)}if(l._containValue){let d=`${l.value}`.indexOf(l._containValue),f=l._containValue.length,p=new Array(f).fill(50);h.splice(d,f,...p)}if(l._dataPattern){let d=l.value,f=`${d}`.match(new RegExp(l._dataPattern.regex)),p=0;Object.entries(l._dataPattern).filter(E=>E[0]!=="regex"&&E[0]!=="order"&&E[0]!=="valRegex").sort((E,m)=>E[1].regexMatchIndex-m[1].regexMatchIndex).forEach(E=>{let m=E[0],B=E[1].regexMatchIndex,I=f[B],y=le(I).length,C=`${l.value}`.indexOf(I,p),b=le(d.substring(0,C)).length,k=new Array(y).fill(m.charCodeAt());h.splice(b,y,...k),p=C+I.length})}n.splice(l.start,A,...h)}}}catch{}},"genMask"),i=kn(t);return e.forEach(o=>{let c=o.key.split("|"),l,A=i;for(;c.length>0;){l=c.shift()||"";let{children:h}=A[l];h&&c.length>0&&(A=h),c.length==0&&(o.dataPattern&&(A[l]._dataPattern=o.dataPattern),o.operation==="contain"&&(A[l]._containValue=o.value))}}),r(i),Ut(new Uint8Array(n))}u(vf,"genDataStruct");function Ou(a,e){let t="",s=a.match(new RegExp(e.regex));return e.order.split("|").forEach(r=>{let i=e[r].regexMatchIndex,o=s[i];e[r].map?.forEach(c=>{let l=c.split("|");l[0]===o&&(o=l[1])}),typeof o<"u"&&(t+=`${o}`)}),t}u(Ou,"combineValueByPattern");function Vo(a,e){let t=a.split("|"),s;for(;t.length>0;){if(s=t.shift()||"",typeof e[s]>"u")return{start:-1,end:-1,keyStart:-1,keyEnd:-1};let{children:n,start:r,end:i,keyStart:o,keyEnd:c}=e[s]||{};if(n&&t.length>0&&(e=n),t.length==0)return{start:r,end:i,keyStart:o,keyEnd:c}}return{start:-1,end:-1,keyStart:-1,keyEnd:-1}}u(Vo,"getValuePosition");function Df(a,e){let t=[],s=e.filter(n=>!n.isPublic);for(let n=0;n<s.length;n++){let r=s[n].key.split("|"),i=s[n].value,o=s[n].operation||"=",c=s[n].dataPattern,l=s[n].tips,{value:A}=Mg(s[n].key,a);c&&(A=Ou(`${A}`,c)),o==="x"?BE(JSON.parse(a),r)&&t.push(l||""):pE(A,i,o)||t.push(l||"")}return t}u(Df,"matchResponseWithCondition");function pE(a,e,t){let s=Qo.toString(a),n=Qo.toString(e);switch(t){case">":return a-e>0;case">=":return a-e>=0;case"<":return a-e<0;case"<=":return a-e<=0;case"=":return s===n;case"!=":return s!==n;case"in":return n.includes(s);case"contain":return s.includes(n)}}u(pE,"compareValue");function Mg(a,e){let t=kn(e),s=Vo(a,t),n=le(e);return{key:Ut(n.slice(s.keyStart,s.keyEnd)),value:Ut(n.slice(s.start,s.end)),prefix:Ut(n.slice(s.start-1,s.start)),suffix:Ut(n.slice(s.end,s.end+1))}}u(Mg,"pickUpValueByFieldPosition");function EE(a,e){let t=[],s=a.split(""),n="";for(let r=0;r<s.length;r++){let i=s[r];if(i==="@"&&s[r+1]==="{"){n&&(t.push({value:n,start:r-n.length,end:r}),n="");let o=r,c=a.indexOf("}",r),l=a.substring(o+4,c).split("|"),A=l[0],h=e[A].json,d=e[A].referred[l[1]],f=fE(h,d.split("|"));a=`${a.substring(0,o)}${f}${a.substring(c+1)}`,r=o+f.length-1,t.push({value:f,start:o,end:o+`${f}`.length,dependInfo:{index:A,referredField:d}})}else n+=i;s=a.split("")}return n&&t.push({value:n,start:s.length-n.length,end:s.length}),{value:a,sliceList:t}}u(EE,"parseReferredString");function Cs(a,e,t,s){let n=[],r=0;return s.forEach((i,o)=>{let c=i.data.length,l=i.headerLen;if(l===c||r>=e)return;let A=t-r;if(A==0)return;let h=i.bodyLen,d=h>A?A:h;if(r+d<a){r+=d;return}if(r>a&&r+d>=e)n.push({index:o,len:c,start:l,end:e-r+l});else if(r<=a&&r+d>=e){let f=a-r+l;n.push({index:o,len:c,start:f,end:e-a+f})}else r<=a&&r+d<e&&n.push({index:o,len:c,start:a-r+l,end:d+l});r+=d}),n}u(Cs,"getRecordsByPosition");function Qf(a){return yE(a,[])}u(Qf,"formatAsserts");function yE(a,e){return a.map(t=>{if(t.isPublic)return t;let{value:s="",operation:n}=t;if(n==="in"){let r=s.split("|");t.value=s,t.targetSlice=r.map(i=>({value:i,start:0,end:i.length}))}else{let{value:r,sliceList:i}=EE(s,e);t.value=r,t.targetSlice=i.map(o=>o.dependInfo?{...o.dependInfo,...o}:o).reverse()}return t})}u(yE,"checkTargetValueWithReferred");function Ms(a,e){return a=a.map(t=>{let{index:s,start:n,end:r,len:i}=t,o=e.find(h=>h.index===s),c=o?.counters||[],l=o?.blockLens||[],A=ma(n,r,i);return A.blockList.forEach(h=>{c.includes(h.counter)||(c.push(h.counter),l.push({index:h.counter,len:h.len}))}),o?e=e.map(h=>(h.index===s&&(h.counters=c.sort((d,f)=>d-f),h.blockLens=l.sort((d,f)=>d.index-f.index)),h)):e.push({index:s,counters:c.sort((h,d)=>h-d),blockLens:l.sort((h,d)=>h.index-d.index)}),{recordIndex:s,startCounter:A.blockList[0].counter,start:n-A.start,valueLen:r-n}}),e=e.sort((t,s)=>t.index-s.index),{usedRecords:a,responseCounter:e}}u(Ms,"checkCounterAndFormatRecordInfo");function bs(a,e,t,s,n){let r=0;n.forEach(c=>{c.index<a?r+=c.blockLens.reduce((l,A)=>l+A.len,0):c.index===a&&(r+=c.blockLens.filter(l=>l.index<s).reduce((l,A)=>l+A.len,0))});let i=e+r,o=i+t;return{start:i,end:o}}u(bs,"findValuePositionInInputMessage");function Pu(a,e,t,s,n){let r={},i="",o=new URL(a),c=o.host,l=o.pathname,A=o.search,h=`${l}`;r.url={value:h,prefixValue:`${e} `,sliceList:[{value:h,start:0,end:h.length}]},i=`${e} ${l}${A} HTTP/1.1\r
Host: ${c}`,n&&n.query&&n.query.forEach(I=>{let{key:y,value:C}=I,b=i.indexOf(`${y}=${C}`);if(b==-1)throw new Error(`Query parameter ${y}=${C} is not allowed in the request.`);r.query||(r.query={}),r.query[y]={value:C,start:b,end:b+`${y}=${C}`.length}});let d=Object.entries(t).find(([I])=>I.toLowerCase()==="content-type"),f="";s&&d&&d.value.includes("application/json")&&(f=JSON.stringify(s));let p=[],E="application/json";switch(Object.entries(t).forEach(([I,y])=>{I.toLowerCase()==="accept-encoding"?y="identity;q=1, *;q=0":I.toLowerCase()==="accept"&&(E=y),p.push(`${I}: ${y}`)}),Object.entries(t).find(([I])=>I.toLowerCase()==="accept-encoding")||p.push("accept-encoding: identity;q=1, *;q=0"),e){case"GET":p.push("","");break;case"POST":let I=f;p.push(`Content-Length: ${I.length}`,"",I);break}i=`${i}\r
${p.join(`\r
`)}`,n&&n.headers&&n.headers.forEach(I=>{let{key:y,value:C}=I,b=i.indexOf(`${y}: ${C}`);if(b==-1)throw new Error(`Header ${y}: ${C} is not allowed in the request.`);r.header||(r.header={}),r.header[y]={value:C,start:b,end:b+`${y}: ${C}`.length}}),n&&n.body&&n.body.forEach(I=>{let{key:y,value:C}=I,b=i.indexOf(`${y}: ${C}`);if(b==-1)throw new Error(`Body parameter ${y}: ${C} is not allowed in the request.`);r.body||(r.body={}),r.body[y]={value:C,start:b,end:b+`${y}: ${C}`.length}});let B=IE(i,l,f,r);return{host:c,text:i,verifyMessage:B,accept:E}}u(Pu,"buildRequestInfo");function IE(a,e,t,s){let n=a.length,r=[],i=[],o=[],c=0,l=a.indexOf(e)+e.length,A={value:a.substring(c,l),start:c,end:l,sliceList:[]},{value:h,prefixValue:d,sliceList:f=[]}=s.url,p=a.indexOf(h);if(A.sliceList=Wu(f,p,d||h),A.sliceList?.forEach(m=>{ma(m.start,m.end,n).blockList.forEach(y=>{r.includes(y.counter)||r.push(y.counter)});let I=i.pop();I===m.start?i.push(m.end):typeof I>"u"?i.push(m.start,m.end):i.push(I,m.start,m.end)}),o.push(A),s.query&&Object.values(s.query).forEach(m=>{let{value:B,prefixValue:I,sliceList:y=[]}=m,C=a.indexOf(B),b=C+B.length;i.push(C,b);let k=ma(C,b,n);k.blockList.forEach(V=>{r.includes(V.counter)||r.push(V.counter)});let U=r.filter(V=>V<k.blockList[0].counter).length,v=C-k.start+U*16,N=v+B.length,D={value:B,start:v,end:N,sliceList:[]};D.sliceList=Wu(y,v,I||B),o.push(D)}),s.header&&Object.values(s.header).forEach(m=>{let{value:B,prefixValue:I,sliceList:y=[]}=m,C=a.indexOf(B),b=C+B.length;i.push(C,b);let k=ma(C,b,n);k.blockList.forEach(V=>{r.includes(V.counter)||r.push(V.counter)});let U=r.filter(V=>V<k.blockList[0].counter).length;m.start=C-k.start+U*16,m.end=m.start+B.length;let v=C-k.start+U*16,N=v+B.length,D={value:B,start:v,end:N,sliceList:[]};D.sliceList=Wu(y,v,I||B),o.push(D)}),s.body){let m=a.indexOf(t),B=Object.values(s.body).map(I=>{let{key:y,value:C}=I,b=0,k=0,v=u((D,V)=>{let R=kn(D);return Vo(V,R)},"getFieldPosition")(t,y);b=m+v.keyStart,k=m+v.end,typeof C=="string"&&k++,i.push(b,k);let N=ma(b,k,n);return N.blockList.forEach(D=>{r.includes(D.counter)||r.push(D.counter)}),{blockInfo:N,keyStart:b,valueEnd:k}});Object.values(s.body).forEach((I,y)=>{let{prefixValue:C,sliceList:b=[]}=I,{blockInfo:k,keyStart:U,valueEnd:v}=B[y],N=r.filter(Y=>Y<k.blockList[0].counter).length,D=a.substring(U,v),V=U-k.start+N*16,R={value:D,start:V,end:V+D.length,sliceList:[]};R.sliceList=Wu(b,V,C||D),o.push(R)})}let E=r.sort((m,B)=>m-B).map(m=>{let B=(m-1)*16,I=B+16;return le(a.substring(B,I))});return{counters:r,inputMessage:E,verifyMessageIndexList:i,verifyStringPositionList:o}}u(IE,"checkRequestVerifyText");function Wu(a,e,t){let s=a[0];return!s||s.dependInfo?a.unshift({value:t,start:0,end:t.length}):(a[0]={value:t+s.value,start:0,end:t.length+s.end},e=0),a.map((r,i)=>{let o=r.start+e,c=r.end+e;i>0&&(o+=t.length,c+=t.length);let l={...r,value:r.value,start:o,end:c,isNullifier:r.isNullifier};return r.dependInfo&&(l={...r.dependInfo,...l}),l})}u(Wu,"resetSliceListInfo");function Vf(a,e){let{records:t,fullResponse:s,responseSliceList:n}=a,r=n.join("");if(!CE(r))throw new Error("response json is invalid");let i=vf(n,e);return{recordBoundaries:Lu(t,s,n),responseStruct:i,records:t}}u(Vf,"maskResponse");function CE(a){try{return JSON.parse(a),!0}catch{return!1}}u(CE,"isValidJSON");function Sf(a){return a.map(e=>{let t=new Uint8Array(e);return{nonce:new Uint8Array(12).fill(0),data:t.slice(29),cipherData:t.slice(13)}})}u(Sf,"formatRecords");function kf(a,e){let{request:t,asserts:s}=a,{url:n,method:r,headers:i,body:o}=t,c=s?.request||{},l=s?.response||[],A=new URL(n),h=A.origin,d=A.pathname,f=A.search;if(f){let m=ME(f.slice(1));m=xn(m);let B=Object.entries(m);B.length>0&&(f="?"+B.map(([y,C])=>`${y}=${C}`).join("&"))}i&&(i=xn(i)),o&&(o=xn(o));let p=`${h}${d}${f}`,E=Vf(e,l);return{request:{url:p,method:r,headers:i,body:o},response:E,requestCipher:e.requestCipherBytes}}u(kf,"maskProofData");function ME(a){let e={};return a&&a.split("&").forEach(t=>{let s=t.split("=");e[s[0]]=s[1]}),e}u(ME,"getQueryParams");function xn(a,e){if(Array.isArray(a))return a.map(t=>xn(t,e));if(typeof a=="object"&&a!==null){let t={};for(let s in a)e&&s===e?t[s]=a[s]:t[s]=xn(a[s],e);return t}else return String(a).replace(/./g,"$")}u(xn,"maskJsonValues");var zu=[2570,6682,10794,14906,19018,23130,27242,31354,35466,39578,43690,47802,51914,56026,60138],bE=769,ms=771,NE={1025:{Name:"rsa_pkcs1_sha256",Hashing:"SHA-256",Type:"RSASSA-PKCS1-v1_5"},1281:{Name:"rsa_pkcs1_sha384",Hashing:"SHA-384",Type:"RSASSA-PKCS1-v1_5"},1537:{Name:"rsa_pkcs1_sha512",Hashing:"SHA-512",Type:"RSASSA-PKCS1-v1_5"},2052:{SaltLength:32,Name:"rsa_pss_rsae_sha256",Hashing:"SHA-256",Type:"RSA-PSS"},2053:{SaltLength:48,Name:"rsa_pss_rsae_sha384",Hashing:"SHA-384",Type:"RSA-PSS"},2054:{SaltLength:64,Name:"rsa_pss_rsae_sha512",Hashing:"SHA-512",Type:"RSA-PSS"},1027:{Name:"ecdsa_secp256r1_sha256",Curve:"P-256",Hashing:"SHA-256",Type:"ECDSA"},1283:{Name:"ecdsa_secp384r1_sha384",Hashing:"SHA-384",Curve:"P-384",Type:"ECDSA"}},pe=class oB{static{u(this,"i")}constructor(e){if(this.val=0,e instanceof Uint8Array||e instanceof Array){if(e.length!=2)throw new Error("Invalid value");this.val=(e[0]<<8)+e[1]}else{if(typeof e!="number")throw new Error("Invalid value");if(e<0||e>65535)throw new Error("Invalid value");this.val=e}}hex(){return"0x"+this.val.toString(16).padStart(4,"0")}bytes(){return new Uint8Array([this.val>>8&255,255&this.val])}equals(e){return e instanceof oB?this.val===e.val:typeof e=="number"&&this.val===e}},Mu=class cB{static{u(this,"o")}constructor(e){if(this.val=0,e instanceof Uint8Array||e instanceof Array){if(e.length!=3)throw new Error("Invalid value");this.val=(e[0]<<16)+(e[1]<<8)+e[2]}else{if(typeof e!="number")throw new Error("Invalid value");if(e<0||e>16777215)throw new Error("Invalid value");this.val=e}}hex(){return"0x"+this.val.toString(16).padStart(6,"0")}bytes(){return new Uint8Array([this.val>>16&255,this.val>>8&255,255&this.val])}equals(e){return e instanceof cB?this.val===e.val:typeof e=="number"&&this.val===e}},lB=class uB{static{u(this,"l")}constructor(e){if(this.val=0,e instanceof Uint8Array||e instanceof Array){if(e.length!==4)throw new Error("Invalid value");this.val=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3]}else{if(typeof e!="number")throw new Error("Invalid value");if(e<0||e>4294967295)throw new Error("Invalid value");this.val=e}}hex(){return"0x"+this.val.toString(16).padStart(8,"0")}bytes(){return new Uint8Array([this.val>>24&255,this.val>>16&255,this.val>>8&255,255&this.val])}equals(e){return e instanceof uB?this.val===e.val:typeof e=="number"&&this.val===e}},Me=class{static{u(this,"c")}constructor(e){if(e=e||[],!(Array.isArray(e)||e instanceof Uint8Array))throw new TypeError("bytes should be an array");this.bytes=Array.from(e),this.bytes_read=0}size(){return this.bytes.length}drain(){let e=[...this.bytes];return this.bytes=[],this.bytes_read=0,e}bytesRead(){return this.bytes_read}write(e,t){if(typeof e!="number")throw new TypeError(`value should be a number: ${e}`);if(e<0||e>Number.MAX_SAFE_INTEGER)throw new RangeError(`value is out of bounds: ${e}`);e=+e,t>>>=0;let s=new Array(t);for(let n=t-1;n>=0;n--)s[n]=255&e,e>>>=8;return this.writeBytes(s)}writeBytes(e){return this.bytes.push(...e),this}writeUint8(e){return this.write(e,1)}writeUint16(e){let t=e;return e instanceof pe&&(t=e.val),this.write(t,2)}writeUint24(e){let t=e;return e instanceof Mu&&(t=e.val),this.write(t,3)}writeUint32(e){let t=e;return e instanceof lB&&(t=e.val),this.write(t,4)}writeUint64(e){return this.write(e,8)}read(e){let t=0;for(let s=0;s<e;s++)t=t<<8|this.bytes[s];return this.bytes.splice(0,e),this.bytes_read+=e,t}readBytes(e){let t=this.bytes.splice(0,e);return this.bytes_read+=e,t}readUint8(){return this.read(1)}readUint16(){return this.read(2)}readUint24(){return this.read(3)}readUint32(){return this.read(4)}readUint64(){return this.read(8)}skip(e){return this.bytes.splice(0,e),this.bytes_read+=e,this}Bytes(){return new Uint8Array(this.bytes)}};function ta(a){let e=new Uint8Array(a.length);for(let t=0;t<a.length;t++)e[t]=a.charCodeAt(t);return e}u(ta,"h");function Qn(a){return Array.from(a,e=>("0"+(255&e).toString(16)).slice(-2)).join("")}u(Qn,"u");var te=class wd{static{u(this,"A")}static isArrayBuffer(e){return Object.prototype.toString.call(e)==="[object ArrayBuffer]"}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){let s=wd.toUint8Array(e),n=wd.toUint8Array(t);if(s.length!==n.byteLength)return!1;for(let r=0;r<s.length;r++)if(s[r]!==n[r])return!1;return!0}static concat(...e){let t;t=!Array.isArray(e[0])||e[1]instanceof Function?Array.isArray(e[0])&&e[1]instanceof Function?e[0]:e[e.length-1]instanceof Function?e.slice(0,e.length-1):e:e[0];let s=0;for(let i of t)s+=i.byteLength;let n=new Uint8Array(s),r=0;for(let i of t){let o=this.toUint8Array(i);n.set(o,r),r+=o.length}return e[e.length-1]instanceof Function?this.toView(n,e[e.length-1]):n.buffer}},bg="string",vE=/^[0-9a-f\s]+$/i,DE=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,QE=/^[a-zA-Z0-9-_]+$/,xf=class{static{u(this,"B")}static fromString(e){let t=unescape(encodeURIComponent(e)),s=new Uint8Array(t.length);for(let n=0;n<t.length;n++)s[n]=t.charCodeAt(n);return s.buffer}static toString(e){let t=te.toUint8Array(e),s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);return decodeURIComponent(escape(s))}},Rt=class{static{u(this,"f")}static toString(e,t=!1){let s=te.toArrayBuffer(e),n=new DataView(s),r="";for(let i=0;i<s.byteLength;i+=2){let o=n.getUint16(i,t);r+=String.fromCharCode(o)}return r}static fromString(e,t=!1){let s=new ArrayBuffer(2*e.length),n=new DataView(s);for(let r=0;r<e.length;r++)n.setUint16(2*r,e.charCodeAt(r),t);return s}},ae=class ba{static{u(this,"E")}static isHex(e){return typeof e===bg&&vE.test(e)}static isBase64(e){return typeof e===bg&&DE.test(e)}static isBase64Url(e){return typeof e===bg&&QE.test(e)}static ToString(e,t="utf8"){let s=te.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(s);case"binary":return this.ToBinary(s);case"hex":return this.ToHex(s);case"base64":return this.ToBase64(s);case"base64url":return this.ToBase64Url(s);case"utf16le":return Rt.toString(s,!0);case"utf16":case"utf16be":return Rt.toString(s);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 Rt.fromString(e,!0);case"utf16":case"utf16be":return Rt.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=te.toUint8Array(e);if(typeof btoa<"u"){let s=this.ToString(t,"binary");return btoa(s)}return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!ba.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){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!ba.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=ba.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return xf.fromString(e);case"utf16":case"utf16be":return Rt.fromString(e);case"utf16le":case"usc2":return Rt.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=ba.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return xf.toString(e);case"utf16":case"utf16be":return Rt.toString(e);case"utf16le":case"usc2":return Rt.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,s=new Uint8Array(t);for(let n=0;n<t;n++)s[n]=e.charCodeAt(n);return s.buffer}static ToBinary(e){let t=te.toUint8Array(e),s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);return s}static ToHex(e){let t=te.toUint8Array(e),s="",n=t.length;for(let r=0;r<n;r++){let i=t[r];i<16&&(s+="0"),s+=i.toString(16)}return s}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!ba.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let s=new Uint8Array(t.length/2);for(let n=0;n<t.length;n+=2){let r=t.slice(n,n+2);s[n/2]=parseInt(r,16)}return s.buffer}static ToUtf16String(e,t=!1){return Rt.toString(e,t)}static FromUtf16String(e,t=!1){return Rt.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let s=0;s<t;s++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};function g(a,e,t){var s;return a instanceof Object&&(s=a[e])!==null&&s!==void 0?s:t}u(g,"p");function Tf(a,e=0,t=a.byteLength-e,s=!1){let n="";for(let r of new Uint8Array(a,e,t)){let i=r.toString(16).toUpperCase();i.length===1&&(n+="0"),n+=i,s&&(n+=" ")}return n.trim()}u(Tf,"I");function ia(a,e){let t=0;if(a.length===1)return a[0];for(let s=a.length-1;s>=0;s--)t+=a[a.length-1-s]*Math.pow(2,e*s);return t}u(ia,"y");function ws(a,e,t=-1){let s=t,n=a,r=0,i=Math.pow(2,e);for(let o=1;o<8;o++){if(a<i){let c;if(s<0)c=new ArrayBuffer(o),r=o;else{if(s<o)return new ArrayBuffer(0);c=new ArrayBuffer(s),r=s}let l=new Uint8Array(c);for(let A=o-1;A>=0;A--){let h=Math.pow(2,A*e);l[r-A-1]=Math.floor(n/h),n-=l[r-A-1]*h}return c}i*=Math.pow(2,e)}return new ArrayBuffer(0)}u(ws,"C");function io(...a){let e=0,t=0;for(let r of a)e+=r.byteLength;let s=new ArrayBuffer(e),n=new Uint8Array(s);for(let r of a)n.set(new Uint8Array(r),t),t+=r.byteLength;return s}u(io,"M");function Bd(...a){let e=0,t=0;for(let r of a)e+=r.length;let s=new ArrayBuffer(e),n=new Uint8Array(s);for(let r of a)n.set(r,t),t+=r.length;return n}u(Bd,"D");function hB(){let a=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let i=a[0]===255&&128&a[1],o=a[0]===0&&!(128&a[1]);(i||o)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let i=0;i<this.valueHex.byteLength;i++)t[i]=0;t[0]=128&a[0];let s=ia(t,8),n=new ArrayBuffer(this.valueHex.byteLength),r=new Uint8Array(n);for(let i=0;i<this.valueHex.byteLength;i++)r[i]=a[i];return r[0]&=127,ia(r,8)-s}u(hB,"N");function Ao(a,e){if(a.byteLength!==e.byteLength)return!1;let t=new Uint8Array(a),s=new Uint8Array(e);for(let n=0;n<t.length;n++)if(t[n]!==s[n])return!1;return!0}u(Ao,"b");function ct(a,e){let t=a.toString(10);if(e<t.length)return"";let s=e-t.length,n=new Array(s);for(let r=0;r<s;r++)n[r]="0";return n.join("").concat(t)}u(ct,"Q");ae.DEFAULT_UTF8_ENCODING="utf8";var AB="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",gB="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";function pd(a,e=!1,t=!1,s=!1){let n=0,r=0,i=0,o="",c=e?gB:AB;if(s){let l=0;for(let A=0;A<a.length;A++)if(a.charCodeAt(A)!==0){l=A;break}a=a.slice(l)}for(;n<a.length;){let l=a.charCodeAt(n++);n>=a.length&&(r=1);let A=a.charCodeAt(n++);n>=a.length&&(i=1);let h=a.charCodeAt(n++),d=l>>2,f=(3&l)<<4|A>>4,p=(15&A)<<2|h>>6,E=63&h;r===1?p=E=64:i===1&&(E=64),o+=t?p===64?`${c.charAt(d)}${c.charAt(f)}`:E===64?`${c.charAt(d)}${c.charAt(f)}${c.charAt(p)}`:`${c.charAt(d)}${c.charAt(f)}${c.charAt(p)}${c.charAt(E)}`:`${c.charAt(d)}${c.charAt(f)}${c.charAt(p)}${c.charAt(E)}`}return o}u(pd,"S");function bu(a,e=!1,t=!1){let s=e?gB:AB;function n(c){for(let l=0;l<64;l++)if(s.charAt(l)===c)return l;return 64}u(n,"r");function r(c){return c===64?0:c}u(r,"a");let i=0,o="";for(;i<a.length;){let c=n(a.charAt(i++)),l=i>=a.length?0:n(a.charAt(i++)),A=i>=a.length?0:n(a.charAt(i++)),h=i>=a.length?0:n(a.charAt(i++)),d=r(c)<<2|r(l)>>4,f=(15&r(l))<<4|r(A)>>2,p=(3&r(A))<<6|r(h);o+=String.fromCharCode(d),A!==64&&(o+=String.fromCharCode(f)),h!==64&&(o+=String.fromCharCode(p))}if(t){let c=-1;for(let l=o.length-1;l>=0;l--)if(o.charCodeAt(l)!==0){c=l;break}o=c!==-1?o.slice(0,c+1):""}return o}u(bu,"k");function FA(a){let e="",t=new Uint8Array(a);for(let s of t)e+=String.fromCharCode(s);return e}u(FA,"T");function go(a){let e=a.length,t=new ArrayBuffer(e),s=new Uint8Array(t);for(let n=0;n<e;n++)s[n]=a.charCodeAt(n);return t}u(go,"U");var VE=Math.log(2);function SE(a){let e=Math.log(a)/VE,t=Math.floor(e),s=Math.round(e);return t===s?t:s}u(SE,"x");function H(a,e){for(let t of e)delete a[t]}u(H,"R");function HA(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}u(HA,"F");function Hm(a){let e=0,t=0;for(let n=0;n<a.length;n++)e+=a[n].byteLength;let s=new Uint8Array(e);for(let n=0;n<a.length;n++){let r=a[n];s.set(new Uint8Array(r),t),t+=r.byteLength}return s.buffer}u(Hm,"H");function Bs(a,e,t,s){return e instanceof Uint8Array?e.byteLength?t<0?(a.error="Wrong parameter: inputOffset less than zero",!1):s<0?(a.error="Wrong parameter: inputLength less than zero",!1):!(e.byteLength-t-s<0)||(a.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(a.error="Wrong parameter: inputBuffer has zero length",!1):(a.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}u(Bs,"Y");var Ym=class{static{u(this,"J")}constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Hm(this.items)}},So=[new Uint8Array([1])],Uf="0123456789",Ng="name",Rf="valueHexView",ks="",xt=new ArrayBuffer(0),Ag=new Uint8Array(0),Nu="EndOfContent",dB="OCTET STRING",mB="BIT STRING";function ps(a){var e;return(e=class extends a{static{u(this,"t")}constructor(...t){var s;super(...t);let n=t[0]||{};this.isHexOnly=(s=n.isHexOnly)!==null&&s!==void 0&&s,this.valueHexView=n.valueHex?te.toUint8Array(n.valueHex):Ag}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(t){this.valueHexView=new Uint8Array(t)}fromBER(t,s,n){let r=t instanceof ArrayBuffer?new Uint8Array(t):t;if(!Bs(this,r,s,n))return-1;let i=s+n;return this.valueHexView=r.subarray(s,i),this.valueHexView.length?(this.blockLength=n,i):(this.warnings.push("Zero buffer length"),s)}toBER(t=!1){return this.isHexOnly?t?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",xt)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ae.ToHex(this.valueHexView)}}}).NAME="hexBlock",e}u(ps,"_");var la=class{static{u(this,"$")}constructor({blockLength:e=0,error:t="",warnings:s=[],valueBeforeDecode:n=Ag}={}){this.blockLength=e,this.error=t,this.warnings=s,this.valueBeforeDecodeView=te.toUint8Array(n)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:ae.ToHex(this.valueBeforeDecodeView)}}};la.NAME="baseBlock";var at=class extends la{static{u(this,"ee")}fromBER(e,t,s){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'")}};at.NAME="valueBlock";var fB=class extends ps(la){static{u(this,"te")}constructor({idBlock:e={}}={}){var t,s,n,r;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0&&t,this.valueHexView=e.valueHex?te.toUint8Array(e.valueHex):Ag,this.tagClass=(s=e.tagClass)!==null&&s!==void 0?s:-1,this.tagNumber=(n=e.tagNumber)!==null&&n!==void 0?n:-1,this.isConstructed=(r=e.isConstructed)!==null&&r!==void 0&&r):(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",xt}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let n=new Uint8Array(1);if(!e){let r=this.tagNumber;r&=31,t|=r,n[0]=t}return n.buffer}if(!this.isHexOnly){let n=ws(this.tagNumber,7),r=new Uint8Array(n),i=n.byteLength,o=new Uint8Array(i+1);if(o[0]=31|t,!e){for(let c=0;c<i-1;c++)o[c+1]=128|r[c];o[i]=r[i-1]}return o.buffer}let s=new Uint8Array(this.valueHexView.byteLength+1);if(s[0]=31|t,!e){let n=this.valueHexView;for(let r=0;r<n.length-1;r++)s[r+1]=128|n[r];s[this.valueHexView.byteLength]=n[n.length-1]}return s.buffer}fromBER(e,t,s){let n=te.toUint8Array(e);if(!Bs(this,n,t,s))return-1;let r=n.subarray(t,t+s);if(r.length===0)return this.error="Zero buffer length",-1;switch(192&r[0]){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=!(32&~r[0]),this.isHexOnly=!1;let i=31&r[0];if(i!==31)this.tagNumber=i,this.blockLength=1;else{let o=1,c=this.valueHexView=new Uint8Array(255),l=255;for(;128&r[o];){if(c[o-1]=127&r[o],o++,o>=r.length)return this.error="End of input reached before message was fully decoded",-1;if(o===l){l+=255;let h=new Uint8Array(l);for(let d=0;d<c.length;d++)h[d]=c[d];c=this.valueHexView=new Uint8Array(l)}}this.blockLength=o+1,c[o-1]=127&r[o];let A=new Uint8Array(o);for(let h=0;h<o;h++)A[h]=c[h];c=this.valueHexView=new Uint8Array(o),c.set(A),this.blockLength<=9?this.tagNumber=ia(c,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}}};fB.NAME="identificationBlock";var wB=class extends la{static{u(this,"se")}constructor({lenBlock:e={}}={}){var t,s,n;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0&&t,this.longFormUsed=(s=e.longFormUsed)!==null&&s!==void 0&&s,this.length=(n=e.length)!==null&&n!==void 0?n:0}fromBER(e,t,s){let n=te.toUint8Array(e);if(!Bs(this,n,t,s))return-1;let r=n.subarray(t,t+s);if(r.length===0)return this.error="Zero buffer length",-1;if(r[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=r[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(128&r[0]),this.longFormUsed===!1)return this.length=r[0],this.blockLength=1,t+this.blockLength;let i=127&r[0];if(i>8)return this.error="Too big integer",-1;if(i+1>r.length)return this.error="End of input reached before message was fully decoded",-1;let o=t+1,c=n.subarray(o,o+i);return c[i-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=ia(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=i+1,t+this.blockLength}toBER(e=!1){let t,s;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(s=new Uint8Array(t),s[0]=128),t;if(this.longFormUsed){let n=ws(this.length,8);if(n.byteLength>127)return this.error="Too big length",xt;if(t=new ArrayBuffer(n.byteLength+1),e)return t;let r=new Uint8Array(n);s=new Uint8Array(t),s[0]=128|n.byteLength;for(let i=0;i<n.byteLength;i++)s[i+1]=r[i];return t}return t=new ArrayBuffer(1),e===!1&&(s=new Uint8Array(t),s[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};wB.NAME="lengthBlock";var Z={},qe=class extends la{static{u(this,"re")}constructor({name:e="",optional:t=!1,primitiveSchema:s,...n}={},r){super(n),this.name=e,this.optional=t,s&&(this.primitiveSchema=s),this.idBlock=new fB(n),this.lenBlock=new wB(n),this.valueBlock=r?new r(n):new at(n)}fromBER(e,t,s){let n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?s:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(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),n)}toBER(e,t){let s=t||new Ym;t||BB(this);let n=this.idBlock.toBER(e);if(s.write(n),this.lenBlock.isIndefiniteForm)s.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,s),s.write(new ArrayBuffer(2));else{let r=this.valueBlock.toBER(e);this.lenBlock.length=r.byteLength;let i=this.lenBlock.toBER(e);s.write(i),s.write(r)}return t?xt:s.final()}toJSON(){let 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():ae.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${ae.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){return this===e?!0:e instanceof this.constructor?Ao(this.toBER(),e.toBER()):!1}};function BB(a){if(a instanceof Z.Constructed)for(let e of a.valueBlock.value)BB(e)&&(a.lenBlock.isIndefiniteForm=!0);return!!a.lenBlock.isIndefiniteForm}u(BB,"ae");qe.NAME="BaseBlock";var pB=class extends qe{static{u(this,"ie")}constructor({value:e="",...t}={},s){super(t,s),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,s){let n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?s:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(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),n)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};pB.NAME="BaseStringBlock";var EB=class extends ps(at){static{u(this,"oe")}constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}},Gf,Ff,Hf,Yf,jf,Jf,Lf,Of,Wf,Pf,zf,Zf,Kf,qf,Xf,$f,_f,ew,tw,sw,nw,rw,aw,iw,ow,cw,lw,uw,hw,Aw,gw,dw,mw;EB.NAME="PrimitiveValueBlock";var $=class extends qe{static{u(this,"Je")}constructor(e={}){super(e,EB),this.idBlock.isConstructed=!1}};function Ru(a,e=0,t=a.length){let s=e,n=new qe({},at),r=new la;if(!Bs(r,a,e,t))return n.error=r.error,{offset:-1,result:n};if(!a.subarray(e,e+t).length)return n.error="Zero buffer length",{offset:-1,result:n};let i=n.idBlock.fromBER(a,e,t);if(n.idBlock.warnings.length&&n.warnings.concat(n.idBlock.warnings),i===-1)return n.error=n.idBlock.error,{offset:-1,result:n};if(e=i,t-=n.idBlock.blockLength,i=n.lenBlock.fromBER(a,e,t),n.lenBlock.warnings.length&&n.warnings.concat(n.lenBlock.warnings),i===-1)return n.error=n.lenBlock.error,{offset:-1,result:n};if(e=i,t-=n.lenBlock.blockLength,!n.idBlock.isConstructed&&n.lenBlock.isIndefiniteForm)return n.error="Indefinite length form used for primitive encoding form",{offset:-1,result:n};let o=qe;if(n.idBlock.tagClass===1){if(n.idBlock.tagNumber>=37&&n.idBlock.isHexOnly===!1)return n.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:n};switch(n.idBlock.tagNumber){case 0:if(n.idBlock.isConstructed&&n.lenBlock.length>0)return n.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:n};o=Z.EndOfContent;break;case 1:o=Z.Boolean;break;case 2:o=Z.Integer;break;case 3:o=Z.BitString;break;case 4:o=Z.OctetString;break;case 5:o=Z.Null;break;case 6:o=Z.ObjectIdentifier;break;case 10:o=Z.Enumerated;break;case 12:o=Z.Utf8String;break;case 13:o=Z.RelativeObjectIdentifier;break;case 14:o=Z.TIME;break;case 15:return n.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:n};case 16:o=Z.Sequence;break;case 17:o=Z.Set;break;case 18:o=Z.NumericString;break;case 19:o=Z.PrintableString;break;case 20:o=Z.TeletexString;break;case 21:o=Z.VideotexString;break;case 22:o=Z.IA5String;break;case 23:o=Z.UTCTime;break;case 24:o=Z.GeneralizedTime;break;case 25:o=Z.GraphicString;break;case 26:o=Z.VisibleString;break;case 27:o=Z.GeneralString;break;case 28:o=Z.UniversalString;break;case 29:o=Z.CharacterString;break;case 30:o=Z.BmpString;break;case 31:o=Z.DATE;break;case 32:o=Z.TimeOfDay;break;case 33:o=Z.DateTime;break;case 34:o=Z.Duration;break;default:{let c=n.idBlock.isConstructed?new Z.Constructed:new Z.Primitive;c.idBlock=n.idBlock,c.lenBlock=n.lenBlock,c.warnings=n.warnings,n=c}}}else o=n.idBlock.isConstructed?Z.Constructed:Z.Primitive;return n=(function(c,l){if(c instanceof l)return c;let A=new l;return A.idBlock=c.idBlock,A.lenBlock=c.lenBlock,A.warnings=c.warnings,A.valueBeforeDecodeView=c.valueBeforeDecodeView,A})(n,o),i=n.fromBER(a,e,n.lenBlock.isIndefiniteForm?t:n.lenBlock.length),n.valueBeforeDecodeView=a.subarray(s,s+n.blockLength),{offset:i,result:n}}u(Ru,"je");function De(a){if(!a.byteLength){let e=new qe({},at);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ru(te.toUint8Array(a).slice(),0,a.byteLength)}u(De,"Oe");Gf=$,Z.Primitive=Gf,$.NAME="PRIMITIVE";var vn=class extends at{static{u(this,"Le")}constructor({value:e=[],isIndefiniteForm:t=!1,...s}={}){super(s),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,s){let n=te.toUint8Array(e);if(!Bs(this,n,t,s))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+s),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let r=t;for(;i=this.isIndefiniteForm,o=s,(i?1:o)>0;){let c=Ru(n,r,s);if(c.offset===-1)return this.error=c.result.error,this.warnings.concat(c.result.warnings),-1;if(r=c.offset,this.blockLength+=c.result.blockLength,s-=c.result.blockLength,this.value.push(c.result),this.isIndefiniteForm&&c.result.constructor.NAME===Nu)break}var i,o;return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Nu?this.value.pop():this.warnings.push("No EndOfContent block encoded")),r}toBER(e,t){let s=t||new Ym;for(let n=0;n<this.value.length;n++)this.value[n].toBER(e,s);return t?xt:s.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};vn.NAME="ConstructedValueBlock";var Q=class extends qe{static{u(this,"ze")}constructor(e={}){super(e,vn),this.idBlock.isConstructed=!0}fromBER(e,t,s){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?s:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(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),n)}onAsciiEncoding(){let e=[];for(let s of this.valueBlock.value)e.push(s.toString("ascii").split(`
`).map(n=>` ${n}`).join(`
`));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
${e.join(`
`)}`:`${t} :`}};Ff=Q,Z.Constructed=Ff,Q.NAME="CONSTRUCTED";var yB=class extends at{static{u(this,"We")}fromBER(e,t,s){return t}toBER(e){return xt}};yB.override="EndOfContentValueBlock";var fw=class extends qe{static{u(this,"Ze")}constructor(e={}){super(e,yB),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Hf=fw,Z.EndOfContent=Hf,fw.NAME=Nu;var Ve=class extends qe{static{u(this,"Ke")}constructor(e={}){super(e,at),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,s){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+=s,t+s>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+s}toBER(e,t){let s=new ArrayBuffer(2);if(!e){let n=new Uint8Array(s);n[0]=5,n[1]=0}return t&&t.write(s),s}onAsciiEncoding(){return`${this.constructor.NAME}`}};Yf=Ve,Z.Null=Yf,Ve.NAME="NULL";var IB=class extends ps(at){static{u(this,"Pe")}constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=te.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,s){let n=te.toUint8Array(e);return Bs(this,n,t,s)?(this.valueHexView=n.subarray(t,t+s),s>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,hB.call(this),this.blockLength=s,t+s):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};IB.NAME="BooleanValueBlock";var Wt=class extends qe{static{u(this,"Xe")}constructor(e={}){super(e,IB),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};jf=Wt,Z.Boolean=jf,Wt.NAME="BOOLEAN";var CB=class extends ps(vn){static{u(this,"qe")}constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,s){let n=0;if(this.isConstructed){if(this.isHexOnly=!1,n=vn.prototype.fromBER.call(this,e,t,s),n===-1)return n;for(let r=0;r<this.value.length;r++){let i=this.value[r].constructor.NAME;if(i===Nu){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==dB)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,n=super.fromBER(e,t,s),this.blockLength=s;return n}toBER(e,t){return this.isConstructed?vn.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};CB.NAME="OctetStringValueBlock";var j=class MB extends qe{static{u(this,"_e")}constructor({idBlock:e={},lenBlock:t={},...s}={}){var n,r;(n=s.isConstructed)!==null&&n!==void 0||(s.isConstructed=!!(!((r=s.value)===null||r===void 0)&&r.length)),super({idBlock:{isConstructed:s.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!s.isIndefiniteForm},...s},CB),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,s){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,s===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){let n=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+s);try{if(n.byteLength){let r=Ru(n,0,n.byteLength);r.offset!==-1&&r.offset===s&&(this.valueBlock.value=[r.result])}}catch{}}return super.fromBER(e,t,s)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Q.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${ae.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof MB&&e.push(t.valueBlock.valueHexView);return te.concat(e)}};Jf=j,Z.OctetString=Jf,j.NAME=dB;var bB=class extends ps(vn){static{u(this,"$e")}constructor({unusedBits:e=0,isConstructed:t=!1,...s}={}){super(s),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,s){if(!s)return t;let n=-1;if(this.isConstructed){if(n=vn.prototype.fromBER.call(this,e,t,s),n===-1)return n;for(let o of this.value){let c=o.constructor.NAME;if(c===Nu){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==mB)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=o.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 n}let r=te.toUint8Array(e);if(!Bs(this,r,t,s))return-1;let i=r.subarray(t,t+s);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let o=i.subarray(1);try{if(o.byteLength){let c=Ru(o,0,o.byteLength);c.offset!==-1&&c.