UNPKG

@zkpass/zkfetch-web

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
var EB=Object.defineProperty;var sI=(i,e,t)=>e in i?EB(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var u=(i,e)=>EB(i,"name",{value:e,configurable:!0});var qe=(i,e,t)=>sI(i,typeof e!="symbol"?e+"":e,t);import fb from"aes-js";import{randBytesSync as Bb}from"bigint-crypto-utils";import{Buffer as Eb}from"buffer";var ds=u(i=>{let e="";for(let t of i)e+=String.fromCharCode(t);return e},"u8Array2Str"),he=u(i=>{let e=new Uint8Array(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t);return e},"str2U8Array"),It=u(i=>{let e=Array(i.length*8),t=0;for(let s=i.length-1;s>=0;s--)for(let n=0;n<8;n++)e[t]=i[s]>>n&1,t++;return e},"u8Array2Bits");function Yu(i){return Array.from(i,e=>("0"+(e&255).toString(16)).slice(-2)).join("")}u(Yu,"bytes2Hex");function ju(i){let e=[];for(let t=0;t<i.length;t+=2)e.push(parseInt(i.substring(t,t+2),16));return new Uint8Array(e)}u(ju,"hex2Bytes");var so=u((...i)=>{let e=[];for(let t of i)e=e.concat(Array.from(t));return new Uint8Array(e)},"concatArray"),km=u((i,e)=>{let t=i.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?so(new Uint8Array(e-n).fill(0),new Uint8Array(s)):e&&n>e?new Uint8Array(s.splice(0,e)):new Uint8Array(s)},"int2U8Array");var Ju=u(i=>{let e=new Uint8Array(i.length/8);for(let t=0;t<e.length;t++){let s=0;for(let n=0;n<8;n++)s+=i[t*8+n]*2**n;e[e.length-1-t]=s}return e},"bits2U8Array");var yB=u(i=>i.toString(2).split("").map(e=>+e),"int2Bits");function no(i){try{return/^(-?\d+)(\.\d+)$/.test(i)}catch{return!1}}u(no,"isFloatNumber");function IB(i){try{return/^-?\d+(\.\d+)?$/.test(i)}catch{return!1}}u(IB,"isNumber");function nI(i){let t=new TextEncoder().encode(i),s="";for(let n of Array.from(t))s+=String.fromCharCode(n);return s}u(nI,"recoverStr");function xm(i){return i.forEach(e=>{typeof e.value=="string"&&(e.value=nI(e.value))}),i}u(xm,"formatAsserts");function CB(i){let t=typeof i=="bigint"?i:BigInt(i);return Number(t>>22n)+15768e8}u(CB,"extractTimestamp");function Tm(i){if(i.length==0)return{};if(i[0]!==123&&i[0]!==91)throw"invalid json bytes";let e=0;function t(){for(;i[e]===10||i[e]===32||i[e]===92&&[92,114,116].includes(i[e+1]);)e++}u(t,"skipWhiteSpace");function s(h,d){if(i.slice(e,e+h.length).join("")===Array.from(he(`${d}`)).join(""))return e+=h.length,d}u(s,"parseKeyword");function n(){if(t(),i[e]!==58)throw new Error('Expected ":"');t(),e++}u(n,"parseColon");function r(){if(t(),i[e]!==44)throw new Error('Expected ","');t(),e++}u(r,"parseComma");function a(){if(t(),i[e]===34){e++;let h=[];for(;i[e]!==34||i[e]===34&&i[e-1]===92;)i[e]===92?(h.push(...i.slice(e,e+2)),e+=2):(h.push(i[e]),e++);return e++,ds(new Uint8Array(h))}}u(a,"parseString");function o(){if(t(),i[e]===123&&i[e-1]!==92){let h=[];e++,t();let d={},m=!0;for(;i[e]!==125||i[e]===125&&i[e-1]===92;){m||(r(),t());let E=e,y=a()||"",f=e;t(),n(),m=!1,t();let p=e,{value:B,type:C}=A(),I=e;t(),h.push(y),C==="string"&&(p+=1,I-=1),d[y]={keyStart:E,keyEnd:f,keyStr:ds(new Uint8Array(i.slice(E,f))),start:p,end:I},C==="object"||C==="array"?d[y].children=B:d[y].value=B}return e++,d}}u(o,"parseObject");function c(){if(i[e]===91&&i[e-1]!==92){e++,t();let h=[],d=!0;for(;i[e]!==93||i[e]===93&&i[e-1]===92;){d||r(),t();let m=e,{value:E,type:y}=A(),f=e;t(),y==="string"&&(m+=1,f-=1);let p={value:E,start:m,end:f};y==="object"||y==="array"?p.children=E:p.value=E,h.push(p),d=!1}return e++,{...h}}}u(c,"parseArray");function l(){let h=e;if(i[e]===45&&e++,i[e]===48)e++;else if(i[e]>=49&&i[e]<=57)for(e++;i[e]>=48&&i[e]<=57;)e++;if(i[e]===46)for(e++;i[e]>=48&&i[e]<=57;)e++;if(i[e]===101||i[e]===69)for(e++,(i[e]===45||i[e]===43)&&e++;i[e]>=48&&i[e]<=57;)e++;if(e>h)return ds(new Uint8Array(i.slice(h,e)))}u(l,"parseNumber");function A(){let h=a();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(Tm,"parseJsonGrammarTree");function fa(i){return Tm(Array.from(he(i)))}u(fa,"customJsonParse");import Lu from"lodash";function ro(i,e,t){let s=i-i%16,n=e%16>0?e+16-e%16:e;n>t&&(n=t);let r=s,a=[],o=[];for(;r<n;){let c=r+16,l=Math.ceil(c/16);a.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:a,blockList:o}}u(ro,"padToAes128Block");function rI(i,e){let t=i;for(;e.length>0;){let s=e.shift()||"";if(t=t[s],typeof t>"u")throw"You do not meet the required criteria"}return Lu.toString(t)}u(rI,"pickValueByKeys");function aI(i,e,t){let s=i;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(aI,"pickAllValueByKeys");function iI(i,e){let t=i;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(iI,"isContainKey");function bB(i){return Lu.isArray(i)&&(i=i.filter(e=>!(typeof e>"u"))),Object.keys(i).forEach(e=>{typeof i[e]=="object"&&(i[e]=bB(i[e]))}),i}u(bB,"removeEmptyElements");function NB(i,e=[]){let t=e.filter(r=>r.isPublic);if(t.length===0)return null;let s="",n=Lu.isArray(i)?[]:{};for(let r=0;r<t.length;r++){let a=t[r].key.split("|"),o=aI(i,t[r].key.split("|"));s=`${s}${JSON.stringify(o)}`;let c=n;for(let l=0;l<a.length;l++){let A=isNaN(parseInt(a[l]))?a[l]:parseInt(a[l]),h=isNaN(parseInt(a[l+1]))?a[l+1]:parseInt(a[l+1]);typeof c[A]>"u"&&(typeof h=="number"?c[A]=[]:c[A]={}),l==a.length-1?c[A]=o:c=c[A]}}return n=bB(n),{data:n,str:s}}u(NB,"checkPublicFields");function MB(i,e,t=0){let s=i.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(MB,"findStartIndex");function Vg(i,e,t){let s=Array.from(he(e)),n=0,r=0,a=t.map(c=>{let l=Array.from(he(c)),A=MB(s,l,n);return n=A+l.length,r+=l.length,{start:A,end:n}}),o=0;return i.map((c,l)=>{let A=c.data,h=MB(s,A,o),d=h+A.length;for(let y=0;y<a.length;y++)if(a[y].end>=h&&a[y].end<h+A.length){d=a[y].end;break}let m=0,E=a.find(y=>h<y.start&&y.start<d);return E?m=E.start-h:(a[0].start>=d||a[a.length-1].end<=h)&&(m=d-h),o=h+A.length,{start:h,end:d,headerLen:m,index:l}})}u(Vg,"findBoundaryForRecords");function DB(i,e){let t=i.join(""),s=Math.max(t.lastIndexOf("]"),t.lastIndexOf("}"));t=t.substring(0,s+1);let n=Array.from(he(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(no(l.value)){let d=`${l.value}`.indexOf(".");h.splice(d,1,46)}if(l._containValue){let d=`${l.value}`.indexOf(l._containValue),m=l._containValue.length,E=new Array(m).fill(50);h.splice(d,m,...E)}if(l._dataPattern){let d=l.value,m=`${d}`.match(new RegExp(l._dataPattern.regex)),E=0;Object.entries(l._dataPattern).filter(y=>y[0]!=="regex"&&y[0]!=="order"&&y[0]!=="valRegex").sort((y,f)=>y[1].regexMatchIndex-f[1].regexMatchIndex).forEach(y=>{let f=y[0],p=y[1].regexMatchIndex,B=m[p],C=he(B).length,I=`${l.value}`.indexOf(B,E),b=he(d.substring(0,I)).length,V=new Array(C).fill(f.charCodeAt());h.splice(b,C,...V),E=I+B.length})}n.splice(l.start,A,...h)}}}catch{}},"genMask"),a=fa(t);return e.forEach(o=>{let c=o.key.split("|"),l,A=a;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(a),ds(new Uint8Array(n))}u(DB,"genDataStruct");function Sg(i,e){let t="",s=i.match(new RegExp(e.regex));return e.order.split("|").forEach(r=>{let a=e[r].regexMatchIndex,o=s[a];e[r].map?.forEach(c=>{let l=c.split("|");l[0]===o&&(o=l[1])}),typeof o<"u"&&(t+=`${o}`)}),t}u(Sg,"combineValueByPattern");function Ou(i,e){let t=i.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:a,keyStart:o,keyEnd:c}=e[s]||{};if(n&&t.length>0&&(e=n),t.length==0)return{start:r,end:a,keyStart:o,keyEnd:c}}return{start:-1,end:-1,keyStart:-1,keyEnd:-1}}u(Ou,"getValuePosition");function vB(i,e){let t=[],s=e.filter(n=>!n.isPublic);for(let n=0;n<s.length;n++){let r=s[n].key.split("|"),a=s[n].value,o=s[n].operation||"=",c=s[n].dataPattern,l=s[n].tips,{value:A}=Um(s[n].key,i);c&&(A=Sg(`${A}`,c)),o==="x"?iI(JSON.parse(i),r)&&t.push(l||""):oI(A,a,o)||t.push(l||"")}return t}u(vB,"matchResponseWithCondition");function oI(i,e,t){let s=Lu.toString(i),n=Lu.toString(e);switch(t){case">":return i-e>0;case">=":return i-e>=0;case"<":return i-e<0;case"<=":return i-e<=0;case"=":return s===n;case"!=":return s!==n;case"in":return n.includes(s);case"contain":return s.includes(n)}}u(oI,"compareValue");function Um(i,e){let t=fa(e),s=Ou(i,t),n=he(e);return{key:ds(n.slice(s.keyStart,s.keyEnd)),value:ds(n.slice(s.start,s.end)),prefix:ds(n.slice(s.start-1,s.start)),suffix:ds(n.slice(s.end,s.end+1))}}u(Um,"pickUpValueByFieldPosition");function cI(i,e){let t=[],s=i.split(""),n="";for(let r=0;r<s.length;r++){let a=s[r];if(a==="@"&&s[r+1]==="{"){n&&(t.push({value:n,start:r-n.length,end:r}),n="");let o=r,c=i.indexOf("}",r),l=i.substring(o+4,c).split("|"),A=l[0],h=e[A].json,d=e[A].referred[l[1]],m=rI(h,d.split("|"));i=`${i.substring(0,o)}${m}${i.substring(c+1)}`,r=o+m.length-1,t.push({value:m,start:o,end:o+`${m}`.length,dependInfo:{index:A,referredField:d}})}else n+=a;s=i.split("")}return n&&t.push({value:n,start:s.length-n.length,end:s.length}),{value:i,sliceList:t}}u(cI,"parseReferredString");function qn(i,e,t,s){let n=[],r=0;return s.forEach((a,o)=>{let c=a.data.length,l=a.headerLen;if(l===c||r>=e)return;let A=t-r;if(A==0)return;let h=a.bodyLen,d=h>A?A:h;if(r+d<i){r+=d;return}if(r>i&&r+d>=e)n.push({index:o,len:c,start:l,end:e-r+l});else if(r<=i&&r+d>=e){let m=i-r+l;n.push({index:o,len:c,start:m,end:e-i+m})}else r<=i&&r+d<e&&n.push({index:o,len:c,start:i-r+l,end:d+l});r+=d}),n}u(qn,"getRecordsByPosition");function QB(i){return lI(i,[])}u(QB,"formatAsserts");function lI(i,e){return i.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(a=>({value:a,start:0,end:a.length}))}else{let{value:r,sliceList:a}=cI(s,e);t.value=r,t.targetSlice=a.map(o=>o.dependInfo?{...o.dependInfo,...o}:o).reverse()}return t})}u(lI,"checkTargetValueWithReferred");function Xn(i,e){return i=i.map(t=>{let{index:s,start:n,end:r,len:a}=t,o=e.find(h=>h.index===s),c=o?.counters||[],l=o?.blockLens||[],A=ro(n,r,a);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,m)=>d-m),h.blockLens=l.sort((d,m)=>d.index-m.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:i,responseCounter:e}}u(Xn,"checkCounterAndFormatRecordInfo");function $n(i,e,t,s,n){let r=0;n.forEach(c=>{c.index<i?r+=c.blockLens.reduce((l,A)=>l+A.len,0):c.index===i&&(r+=c.blockLens.filter(l=>l.index<s).reduce((l,A)=>l+A.len,0))});let a=e+r,o=a+t;return{start:a,end:o}}u($n,"findValuePositionInInputMessage");function xg(i,e,t,s,n){let r={},a="",o=new URL(i),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}]},a=`${e} ${l}${A} HTTP/1.1\r Host: ${c}`,n&&n.query&&n.query.forEach(B=>{let{key:C,value:I}=B,b=a.indexOf(`${C}=${I}`);if(b==-1)throw new Error(`Query parameter ${C}=${I} is not allowed in the request.`);r.query||(r.query={}),r.query[C]={value:I,start:b,end:b+`${C}=${I}`.length}});let d=Object.entries(t).find(([B])=>B.toLowerCase()==="content-type"),m="";s&&d&&d.value.includes("application/json")&&(m=JSON.stringify(s));let E=[],y="application/json";switch(Object.entries(t).forEach(([B,C])=>{B.toLowerCase()==="accept-encoding"?C="identity;q=1, *;q=0":B.toLowerCase()==="accept"&&(y=C),E.push(`${B}: ${C}`)}),Object.entries(t).find(([B])=>B.toLowerCase()==="accept-encoding")||E.push("accept-encoding: identity;q=1, *;q=0"),e){case"GET":E.push("","");break;case"POST":let B=m;E.push(`Content-Length: ${B.length}`,"",B);break}a=`${a}\r ${E.join(`\r `)}`,n&&n.headers&&n.headers.forEach(B=>{let{key:C,value:I}=B,b=a.indexOf(`${C}: ${I}`);if(b==-1)throw new Error(`Header ${C}: ${I} is not allowed in the request.`);r.header||(r.header={}),r.header[C]={value:I,start:b,end:b+`${C}: ${I}`.length}}),n&&n.body&&n.body.forEach(B=>{let{key:C,value:I}=B,b=a.indexOf(`${C}: ${I}`);if(b==-1)throw new Error(`Body parameter ${C}: ${I} is not allowed in the request.`);r.body||(r.body={}),r.body[C]={value:I,start:b,end:b+`${C}: ${I}`.length}});let p=uI(a,l,m,r);return{host:c,text:a,verifyMessage:p,accept:y}}u(xg,"buildRequestInfo");function uI(i,e,t,s){let n=i.length,r=[],a=[],o=[],c=0,l=i.indexOf(e)+e.length,A={value:i.substring(c,l),start:c,end:l,sliceList:[]},{value:h,prefixValue:d,sliceList:m=[]}=s.url,E=i.indexOf(h);if(A.sliceList=kg(m,E,d||h),A.sliceList?.forEach(f=>{ro(f.start,f.end,n).blockList.forEach(C=>{r.includes(C.counter)||r.push(C.counter)});let B=a.pop();B===f.start?a.push(f.end):typeof B>"u"?a.push(f.start,f.end):a.push(B,f.start,f.end)}),o.push(A),s.query&&Object.values(s.query).forEach(f=>{let{value:p,prefixValue:B,sliceList:C=[]}=f,I=i.indexOf(p),b=I+p.length;a.push(I,b);let V=ro(I,b,n);V.blockList.forEach(N=>{r.includes(N.counter)||r.push(N.counter)});let G=r.filter(N=>N<V.blockList[0].counter).length,v=I-V.start+G*16,S=v+p.length,Q={value:p,start:v,end:S,sliceList:[]};Q.sliceList=kg(C,v,B||p),o.push(Q)}),s.header&&Object.values(s.header).forEach(f=>{let{value:p,prefixValue:B,sliceList:C=[]}=f,I=i.indexOf(p),b=I+p.length;a.push(I,b);let V=ro(I,b,n);V.blockList.forEach(N=>{r.includes(N.counter)||r.push(N.counter)});let G=r.filter(N=>N<V.blockList[0].counter).length;f.start=I-V.start+G*16,f.end=f.start+p.length;let v=I-V.start+G*16,S=v+p.length,Q={value:p,start:v,end:S,sliceList:[]};Q.sliceList=kg(C,v,B||p),o.push(Q)}),s.body){let f=i.indexOf(t),p=Object.values(s.body).map(B=>{let{key:C,value:I}=B,b=0,V=0,v=u((Q,N)=>{let T=fa(Q);return Ou(N,T)},"getFieldPosition")(t,C);b=f+v.keyStart,V=f+v.end,typeof I=="string"&&V++,a.push(b,V);let S=ro(b,V,n);return S.blockList.forEach(Q=>{r.includes(Q.counter)||r.push(Q.counter)}),{blockInfo:S,keyStart:b,valueEnd:V}});Object.values(s.body).forEach((B,C)=>{let{prefixValue:I,sliceList:b=[]}=B,{blockInfo:V,keyStart:G,valueEnd:v}=p[C],S=r.filter(j=>j<V.blockList[0].counter).length,Q=i.substring(G,v),N=G-V.start+S*16,T={value:Q,start:N,end:N+Q.length,sliceList:[]};T.sliceList=kg(b,N,I||Q),o.push(T)})}let y=r.sort((f,p)=>f-p).map(f=>{let p=(f-1)*16,B=p+16;return he(i.substring(p,B))});return{counters:r,inputMessage:y,verifyMessageIndexList:a,verifyStringPositionList:o}}u(uI,"checkRequestVerifyText");function kg(i,e,t){let s=i[0];return!s||s.dependInfo?i.unshift({value:t,start:0,end:t.length}):(i[0]={value:t+s.value,start:0,end:t.length+s.end},e=0),i.map((r,a)=>{let o=r.start+e,c=r.end+e;a>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(kg,"resetSliceListInfo");function VB(i,e){let{records:t,fullResponse:s,responseSliceList:n}=i,r=n.join("");if(!hI(r))throw new Error("response json is invalid");let a=DB(n,e);return{recordBoundaries:Vg(t,s,n),responseStruct:a,records:t}}u(VB,"maskResponse");function hI(i){try{return JSON.parse(i),!0}catch{return!1}}u(hI,"isValidJSON");function SB(i){return i.map(e=>{let t=new Uint8Array(e);return{nonce:new Uint8Array(12).fill(0),data:t.slice(29),cipherData:t.slice(13)}})}u(SB,"formatRecords");function kB(i,e){let{request:t,asserts:s}=i,{url:n,method:r,headers:a,body:o}=t,c=s?.request||{},l=s?.response||[],A=new URL(n),h=A.origin,d=A.pathname,m=A.search;if(m){let f=AI(m.slice(1));f=wa(f);let p=Object.entries(f);p.length>0&&(m="?"+p.map(([C,I])=>`${C}=${I}`).join("&"))}a&&(a=wa(a)),o&&(o=wa(o));let E=`${h}${d}${m}`,y=VB(e,l);return{request:{url:E,method:r,headers:a,body:o},response:y,requestCipher:e.requestCipherBytes}}u(kB,"maskProofData");function AI(i){let e={};return i&&i.split("&").forEach(t=>{let s=t.split("=");e[s[0]]=s[1]}),e}u(AI,"getQueryParams");function wa(i,e){if(Array.isArray(i))return i.map(t=>wa(t,e));if(typeof i=="object"&&i!==null){let t={};for(let s in i)e&&s===e?t[s]=i[s]:t[s]=wa(i[s],e);return t}else return String(i).replace(/./g,"$")}u(wa,"maskJsonValues");var Tg=[2570,6682,10794,14906,19018,23130,27242,31354,35466,39578,43690,47802,51914,56026,60138],gI=769,Ln=771,dI={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"}},Gi,Ee=(Gi=class{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 Gi?this.val===e.val:typeof e=="number"&&this.val===e}},u(Gi,"i"),Gi),Fi,ug=(Fi=class{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 Fi?this.val===e.val:typeof e=="number"&&this.val===e}},u(Fi,"o"),Fi),Hi,oE=(Hi=class{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 Hi?this.val===e.val:typeof e=="number"&&this.val===e}},u(Hi,"l"),Hi),Wc,Ne=(Wc=class{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 Ee&&(t=e.val),this.write(t,2)}writeUint24(e){let t=e;return e instanceof ug&&(t=e.val),this.write(t,3)}writeUint32(e){let t=e;return e instanceof oE&&(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)}},u(Wc,"c"),Wc);function ki(i){let e=new Uint8Array(i.length);for(let t=0;t<i.length;t++)e[t]=i.charCodeAt(t);return e}u(ki,"h");function ga(i){return Array.from(i,e=>("0"+(255&e).toString(16)).slice(-2)).join("")}u(ga,"u");var Kr,ne=(Kr=class{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=Kr.toUint8Array(e),n=Kr.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 a of t)s+=a.byteLength;let n=new Uint8Array(s),r=0;for(let a of t){let o=this.toUint8Array(a);n.set(o,r),r+=o.length}return e[e.length-1]instanceof Function?this.toView(n,e[e.length-1]):n.buffer}},u(Kr,"A"),Kr),Rm="string",mI=/^[0-9a-f\s]+$/i,fI=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,wI=/^[a-zA-Z0-9-_]+$/,Pc,xB=(Pc=class{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=ne.toUint8Array(e),s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);return decodeURIComponent(escape(s))}},u(Pc,"B"),Pc),zc,ms=(zc=class{static toString(e,t=!1){let s=ne.toArrayBuffer(e),n=new DataView(s),r="";for(let a=0;a<s.byteLength;a+=2){let o=n.getUint16(a,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}},u(zc,"f"),zc),Xt,ie=(Xt=class{static isHex(e){return typeof e===Rm&&mI.test(e)}static isBase64(e){return typeof e===Rm&&fI.test(e)}static isBase64Url(e){return typeof e===Rm&&wI.test(e)}static ToString(e,t="utf8"){let s=ne.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 ms.toString(s,!0);case"utf16":case"utf16be":return ms.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 ms.fromString(e,!0);case"utf16":case"utf16be":return ms.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=ne.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(!Xt.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(!Xt.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=Xt.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return xB.fromString(e);case"utf16":case"utf16be":return ms.fromString(e);case"utf16le":case"usc2":return ms.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=Xt.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return xB.toString(e);case"utf16":case"utf16be":return ms.toString(e);case"utf16le":case"usc2":return ms.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=ne.toUint8Array(e),s="";for(let n=0;n<t.length;n++)s+=String.fromCharCode(t[n]);return s}static ToHex(e){let t=ne.toUint8Array(e),s="",n=t.length;for(let r=0;r<n;r++){let a=t[r];a<16&&(s+="0"),s+=a.toString(16)}return s}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!Xt.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 ms.toString(e,t)}static FromUtf16String(e,t=!1){return ms.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,"")||""}},u(Xt,"E"),Xt);function g(i,e,t){var s;return i instanceof Object&&(s=i[e])!==null&&s!==void 0?s:t}u(g,"p");function TB(i,e=0,t=i.byteLength-e,s=!1){let n="";for(let r of new Uint8Array(i,e,t)){let a=r.toString(16).toUpperCase();a.length===1&&(n+="0"),n+=a,s&&(n+=" ")}return n.trim()}u(TB,"I");function Zi(i,e){let t=0;if(i.length===1)return i[0];for(let s=i.length-1;s>=0;s--)t+=i[i.length-1-s]*Math.pow(2,e*s);return t}u(Zi,"y");function Wn(i,e,t=-1){let s=t,n=i,r=0,a=Math.pow(2,e);for(let o=1;o<8;o++){if(i<a){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}a*=Math.pow(2,e)}return new ArrayBuffer(0)}u(Wn,"C");function Hc(...i){let e=0,t=0;for(let r of i)e+=r.byteLength;let s=new ArrayBuffer(e),n=new Uint8Array(s);for(let r of i)n.set(new Uint8Array(r),t),t+=r.byteLength;return s}u(Hc,"M");function Qf(...i){let e=0,t=0;for(let r of i)e+=r.length;let s=new ArrayBuffer(e),n=new Uint8Array(s);for(let r of i)n.set(r,t),t+=r.length;return n}u(Qf,"D");function cE(){let i=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=i[0]===255&&128&i[1],o=i[0]===0&&!(128&i[1]);(a||o)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=128&i[0];let s=Zi(t,8),n=new ArrayBuffer(this.valueHex.byteLength),r=new Uint8Array(n);for(let a=0;a<this.valueHex.byteLength;a++)r[a]=i[a];return r[0]&=127,Zi(r,8)-s}u(cE,"N");function Qu(i,e){if(i.byteLength!==e.byteLength)return!1;let t=new Uint8Array(i),s=new Uint8Array(e);for(let n=0;n<t.length;n++)if(t[n]!==s[n])return!1;return!0}u(Qu,"b");function St(i,e){let t=i.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(St,"Q");ie.DEFAULT_UTF8_ENCODING="utf8";var lE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",uE="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";function Vf(i,e=!1,t=!1,s=!1){let n=0,r=0,a=0,o="",c=e?uE:lE;if(s){let l=0;for(let A=0;A<i.length;A++)if(i.charCodeAt(A)!==0){l=A;break}i=i.slice(l)}for(;n<i.length;){let l=i.charCodeAt(n++);n>=i.length&&(r=1);let A=i.charCodeAt(n++);n>=i.length&&(a=1);let h=i.charCodeAt(n++),d=l>>2,m=(3&l)<<4|A>>4,E=(15&A)<<2|h>>6,y=63&h;r===1?E=y=64:a===1&&(y=64),o+=t?E===64?`${c.charAt(d)}${c.charAt(m)}`:y===64?`${c.charAt(d)}${c.charAt(m)}${c.charAt(E)}`:`${c.charAt(d)}${c.charAt(m)}${c.charAt(E)}${c.charAt(y)}`:`${c.charAt(d)}${c.charAt(m)}${c.charAt(E)}${c.charAt(y)}`}return o}u(Vf,"S");function hg(i,e=!1,t=!1){let s=e?uE:lE;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 a=0,o="";for(;a<i.length;){let c=n(i.charAt(a++)),l=a>=i.length?0:n(i.charAt(a++)),A=a>=i.length?0:n(i.charAt(a++)),h=a>=i.length?0:n(i.charAt(a++)),d=r(c)<<2|r(l)>>4,m=(15&r(l))<<4|r(A)>>2,E=(3&r(A))<<6|r(h);o+=String.fromCharCode(d),A!==64&&(o+=String.fromCharCode(m)),h!==64&&(o+=String.fromCharCode(E))}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(hg,"k");function Kd(i){let e="",t=new Uint8Array(i);for(let s of t)e+=String.fromCharCode(s);return e}u(Kd,"T");function Vu(i){let e=i.length,t=new ArrayBuffer(e),s=new Uint8Array(t);for(let n=0;n<e;n++)s[n]=i.charCodeAt(n);return t}u(Vu,"U");var BI=Math.log(2);function pI(i){let e=Math.log(i)/BI,t=Math.floor(e),s=Math.round(e);return t===s?t:s}u(pI,"x");function Y(i,e){for(let t of e)delete i[t]}u(Y,"R");function qd(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}u(qd,"F");function xw(i){let e=0,t=0;for(let n=0;n<i.length;n++)e+=i[n].byteLength;let s=new Uint8Array(e);for(let n=0;n<i.length;n++){let r=i[n];s.set(new Uint8Array(r),t),t+=r.byteLength}return s.buffer}u(xw,"H");function Pn(i,e,t,s){return e instanceof Uint8Array?e.byteLength?t<0?(i.error="Wrong parameter: inputOffset less than zero",!1):s<0?(i.error="Wrong parameter: inputLength less than zero",!1):!(e.byteLength-t-s<0)||(i.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):(i.error="Wrong parameter: inputBuffer has zero length",!1):(i.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}u(Pn,"Y");var Zc,Tw=(Zc=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return xw(this.items)}},u(Zc,"J"),Zc),Wu=[new Uint8Array([1])],UB="0123456789",Gm="name",RB="valueHexView",ar="",As=new ArrayBuffer(0),Cm=new Uint8Array(0),Ag="EndOfContent",hE="OCTET STRING",AE="BIT STRING";function zn(i){var t;var e;return(e=(t=class extends i{constructor(...n){var r;super(...n);let a=n[0]||{};this.isHexOnly=(r=a.isHexOnly)!==null&&r!==void 0&&r,this.valueHexView=a.valueHex?ne.toUint8Array(a.valueHex):Cm}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,r,a){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Pn(this,o,r,a))return-1;let c=r+a;return this.valueHexView=o.subarray(r,c),this.valueHexView.length?(this.blockLength=a,c):(this.warnings.push("Zero buffer length"),r)}toBER(n=!1){return this.isHexOnly?n?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",As)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:ie.ToHex(this.valueHexView)}}},u(t,"t"),t)).NAME="hexBlock",e}u(zn,"_");var Kc,Xi=(Kc=class{constructor({blockLength:e=0,error:t="",warnings:s=[],valueBeforeDecode:n=Cm}={}){this.blockLength=e,this.error=t,this.warnings=s,this.valueBeforeDecodeView=ne.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:ie.ToHex(this.valueBeforeDecodeView)}}},u(Kc,"$"),Kc);Xi.NAME="baseBlock";var qc,yt=(qc=class extends Xi{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'")}},u(qc,"ee"),qc);yt.NAME="valueBlock";var Xc,gE=(Xc=class extends zn(Xi){constructor({idBlock:e={}}={}){var t,s,n,r;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0&&t,this.valueHexView=e.valueHex?ne.toUint8Array(e.valueHex):Cm,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",As}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=Wn(this.tagNumber,7),r=new Uint8Array(n),a=n.byteLength,o=new Uint8Array(a+1);if(o[0]=31|t,!e){for(let c=0;c<a-1;c++)o[c+1]=128|r[c];o[a]=r[a-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=ne.toUint8Array(e);if(!Pn(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 a=31&r[0];if(a!==31)this.tagNumber=a,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=Zi(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}}},u(Xc,"te"),Xc);gE.NAME="identificationBlock";var $c,dE=($c=class extends Xi{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=ne.toUint8Array(e);if(!Pn(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 a=127&r[0];if(a>8)return this.error="Too big integer",-1;if(a+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+a);return c[a-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Zi(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=a+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=Wn(this.length,8);if(n.byteLength>127)return this.error="Too big length",As;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 a=0;a<n.byteLength;a++)s[a+1]=r[a];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}}},u($c,"se"),$c);dE.NAME="lengthBlock";var Z={},_c,ht=(_c=class extends Xi{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 gE(n),this.lenBlock=new dE(n),this.valueBlock=r?new r(n):new yt(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 Tw;t||mE(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 a=this.lenBlock.toBER(e);s.write(a),s.write(r)}return t?As: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():ie.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${ie.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){return this===e?!0:e instanceof this.constructor?Qu(this.toBER(),e.toBER()):!1}},u(_c,"re"),_c);function mE(i){if(i instanceof Z.Constructed)for(let e of i.valueBlock.value)mE(e)&&(i.lenBlock.isIndefiniteForm=!0);return!!i.lenBlock.isIndefiniteForm}u(mE,"ae");ht.NAME="BaseBlock";var el,fE=(el=class extends ht{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}'`}},u(el,"ie"),el);fE.NAME="BaseStringBlock";var tl,wE=(tl=class extends zn(yt){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}},u(tl,"oe"),tl),GB,FB,HB,YB,jB,JB,LB,OB,WB,PB,zB,ZB,KB,qB,XB,$B,_B,ep,tp,sp,np,rp,ap,ip,op,cp,lp,up,hp,Ap,gp,dp,mp;wE.NAME="PrimitiveValueBlock";var sl,se=(sl=class extends ht{constructor(e={}){super(e,wE),this.idBlock.isConstructed=!1}},u(sl,"Je"),sl);function Ig(i,e=0,t=i.length){let s=e,n=new ht({},yt),r=new Xi;if(!Pn(r,i,e,t))return n.error=r.error,{offset:-1,result:n};if(!i.subarray(e,e+t).length)return n.error="Zero buffer length",{offset:-1,result:n};let a=n.idBlock.fromBER(i,e,t);if(n.idBlock.warnings.length&&n.warnings.concat(n.idBlock.warnings),a===-1)return n.error=n.idBlock.error,{offset:-1,result:n};if(e=a,t-=n.idBlock.blockLength,a=n.lenBlock.fromBER(i,e,t),n.lenBlock.warnings.length&&n.warnings.concat(n.lenBlock.warnings),a===-1)return n.error=n.lenBlock.error,{offset:-1,result:n};if(e=a,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=ht;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),a=n.fromBER(i,e,n.lenBlock.isIndefiniteForm?t:n.lenBlock.length),n.valueBeforeDecodeView=i.subarray(s,s+n.blockLength),{offset:a,result:n}}u(Ig,"je");function Qe(i){if(!i.byteLength){let e=new ht({},yt);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ig(ne.toUint8Array(i).slice(),0,i.byteLength)}u(Qe,"Oe");GB=se,Z.Primitive=GB,se.NAME="PRIMITIVE";var nl,zr=(nl=class extends yt{constructor({value:e=[],isIndefiniteForm:t=!1,...s}={}){super(s),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,s){let n=ne.toUint8Array(e);if(!Pn(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(;a=this.isIndefiniteForm,o=s,(a?1:o)>0;){let c=Ig(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===Ag)break}var a,o;return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Ag?this.value.pop():this.warnings.push("No EndOfContent block encoded")),r}toBER(e,t){let s=t||new Tw;for(let n=0;n<this.value.length;n++)this.value[n].toBER(e,s);return t?As:s.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}},u(nl,"Le"),nl);zr.NAME="ConstructedValueBlock";var rl,D=(rl=class extends ht{constructor(e={}){super(e,zr),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} :`}},u(rl,"ze"),rl);FB=D,Z.Constructed=FB,D.NAME="CONSTRUCTED";var al,BE=(al=class extends yt{fromBER(e,t,s){return t}toBER(e){return As}},u(al,"We"),al);BE.override="EndOfContentValueBlock";var il,fp=(il=class extends ht{constructor(e={}){super(e,BE),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}},u(il,"Ze"),il);HB=fp,Z.EndOfContent=HB,fp.NAME=Ag;var ol,Ve=(ol=class extends ht{constructor(e={}){super(e,yt),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}`}},u(ol,"Ke"),ol);YB=Ve,Z.Null=YB,Ve.NAME="NULL";var cl,pE=(cl=class extends zn(yt){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=ne.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=ne.toUint8Array(e);return Pn(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,cE.call(this),this.blockLength=s,t+s):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}},u(cl,"Pe"),cl);pE.NAME="BooleanValueBlock";var ll,Ps=(ll=class extends ht{constructor(e={}){super(e,pE),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}`}},u(ll,"Xe"),ll);jB=Ps,Z.Boolean=jB,Ps.NAME="BOOLEAN";var ul,EE=(ul=class extends zn(zr){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=zr.prototype.fromBER.call(this,e,t,s),n===-1)return n;for(let r=0;r<this.value.length;r++){let a=this.value[r].constructor.NAME;if(a===Ag){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(a!==hE)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?zr.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}},u(ul,"qe"),ul);EE.NAME="OctetStringValueBlock";var Yi,J=(Yi=class extends ht{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},EE),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=Ig(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?D.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${ie.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 Yi&&e.push(t.valueBlock.valueHexView);return ne.concat(e)}},u(Yi,"_e"),Yi);JB=J,Z.OctetString=JB,J.NAME=hE;var hl,yE=(hl=class extends zn(zr){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=zr.prototype.fromBER.call(this,e,t,s),n===-1)return n;for(let o of this.value){let c=o.constructor.NAME;if(c===Ag){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==AE)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=ne.toUint8Array(e);if(!Pn(this,r,t,s))return-1;let a=r.subarray(t,t+s);if(this.unusedBits=a[0],this.unusedBits>7)return this.