edockit 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +93 -12
- package/dist/core/parser/types.d.ts +3 -0
- package/dist/core/revocation/check.d.ts +22 -0
- package/dist/core/revocation/crl.d.ts +35 -0
- package/dist/core/revocation/fetch.d.ts +60 -0
- package/dist/core/revocation/index.d.ts +4 -0
- package/dist/core/revocation/ocsp.d.ts +54 -0
- package/dist/core/revocation/types.d.ts +56 -0
- package/dist/core/timestamp/index.d.ts +2 -0
- package/dist/core/timestamp/types.d.ts +48 -0
- package/dist/core/timestamp/verify.d.ts +32 -0
- package/dist/core/verification.d.ts +12 -0
- package/dist/index.cjs.js +8832 -245
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.esm.js +8830 -247
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +76 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/utils/encoding.d.ts +28 -0
- package/package.json +5 -2
package/dist/index.umd.js
CHANGED
|
@@ -1,15 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
var rl=Object.defineProperty,il=Object.defineProperties;var ol=Object.getOwnPropertyDescriptors;var ri=Object.getOwnPropertySymbols;var ra=Object.prototype.hasOwnProperty,ia=Object.prototype.propertyIsEnumerable;var ta=(x,R,V)=>R in x?rl(x,R,{enumerable:!0,configurable:!0,writable:!0,value:V}):x[R]=V,T=(x,R)=>{for(var V in R||(R={}))ra.call(R,V)&&ta(x,V,R[V]);if(ri)for(var V of ri(R))ia.call(R,V)&&ta(x,V,R[V]);return x},L=(x,R)=>il(x,ol(R));var D=(x,R)=>{var V={};for(var ie in x)ra.call(x,ie)&&R.indexOf(ie)<0&&(V[ie]=x[ie]);if(x!=null&&ri)for(var ie of ri(x))R.indexOf(ie)<0&&ia.call(x,ie)&&(V[ie]=x[ie]);return V};/*!
|
|
2
2
|
* MIT License
|
|
3
3
|
* Copyright (c) 2025 Edgars Jēkabsons, ZenomyTech SIA
|
|
4
|
-
*/(function(
|
|
5
|
-
`:"",afterChildren:(
|
|
6
|
-
`:"",betweenChildren:(
|
|
7
|
-
`:"",afterElement:()=>"",isCanonicalizationMethod:"c14n11"},c14n_exc:{beforeChildren:()=>"",afterChildren:()=>"",betweenChildren:()=>"",afterElement:()=>"",isCanonicalizationMethod:"c14n_exc"}},
|
|
8
|
-
`)&&(
|
|
9
|
-
${
|
|
4
|
+
*/(function(x,R){typeof exports=="object"&&typeof module!="undefined"?R(exports,require("fflate"),require("@peculiar/x509")):typeof define=="function"&&define.amd?define(["exports","fflate","@peculiar/x509"],R):(x=typeof globalThis!="undefined"?globalThis:x||self,R(x.edockit={},x.fflate,x.peculiarX509))})(this,function(x,R,V){"use strict";function ie(r,e){const t=[],i=e.split(",").map(s=>s.trim()),o=[];for(const s of i){const c=s.split(/\\:|:/).filter(Boolean);c.length===1?o.push({name:c[0]}):c.length===2&&o.push({ns:c[0],name:c[1]})}function n(s){if(s){if(s.nodeType===1){const c=s,u=c.nodeName,f=c.localName;for(const p of o){if(p.ns&&u===`${p.ns}:${p.name}`){t.push(c);break}if(f===p.name||u===p.name){t.push(c);break}if(u.endsWith(`:${p.name}`)){t.push(c);break}}}if(s.childNodes)for(let c=0;c<s.childNodes.length;c++)n(s.childNodes[c])}}return n(r),t}const Wo={ds:"http://www.w3.org/2000/09/xmldsig#",dsig11:"http://www.w3.org/2009/xmldsig11#",dsig2:"http://www.w3.org/2010/xmldsig2#",ec:"http://www.w3.org/2001/10/xml-exc-c14n#",dsig_more:"http://www.w3.org/2001/04/xmldsig-more#",xenc:"http://www.w3.org/2001/04/xmlenc#",xenc11:"http://www.w3.org/2009/xmlenc11#",xades:"http://uri.etsi.org/01903/v1.3.2#",xades141:"http://uri.etsi.org/01903/v1.4.1#",asic:"http://uri.etsi.org/02918/v1.2.1#"};function Jo(){if(typeof window!="undefined"&&window.DOMParser)return new window.DOMParser;try{const{DOMParser:r}=require("@xmldom/xmldom");return new r}catch(r){throw new Error("XML DOM parser not available. In Node.js environments, please install @xmldom/xmldom package.")}}function oa(r,e,t=Wo){try{if(typeof document!="undefined"&&document.evaluate){const i=Ko(t);return document.evaluate(e,r,i,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}else{const i=require("xpath"),o=t;try{const n=i.select(e,r,o);return n.length>0?n[0]:null}catch(n){if(typeof n=="object"&&n!==null&&"message"in n&&typeof n.message=="string"&&n.message.includes("Cannot resolve QName")){const s=e.match(/local-name\(\)='([^']+)'/);if(s&&s[1]){const c=`.//*[local-name()='${s[1]}']`,u=i.select(c,r);return u.length>0?u[0]:null}}throw n}}}catch(i){return console.error(`XPath evaluation failed for "${e}":`,i),null}}function na(r,e,t=Wo){try{if(typeof document!="undefined"&&document.evaluate){const i=Ko(t),o=document.evaluate(e,r,i,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),n=[];for(let s=0;s<o.snapshotLength;s++)n.push(o.snapshotItem(s));return n}else{const i=require("xpath"),o=t;try{return i.select(e,r,o)}catch(n){if(typeof n=="object"&&n!==null&&"message"in n&&typeof n.message=="string"&&n.message.includes("Cannot resolve QName")){const s=e.match(/local-name\(\)='([^']+)'/);if(s&&s[1]){const c=`.//*[local-name()='${s[1]}']`;return i.select(c,r)}}throw n}}}catch(i){return console.error(`XPath evaluation failed for "${e}":`,i),[]}}function Ko(r){return function(e){return e===null?null:r[e]||null}}function Yo(r){const e=r.split(",").map(i=>i.trim()),t=[];for(const i of e){const o=i.split(/\\:|:/).filter(Boolean);o.length===1?t.push(`.//*[local-name()='${o[0]}']`):o.length===2&&t.push(`.//${o[0]}:${o[1]} | .//*[local-name()='${o[1]}']`)}return t.join(" | ")}function K(r,e){if(typeof r.querySelector=="function")try{const i=r.querySelector(e);if(i)return i}catch(i){}const t=ie(r,e);if(t.length>0)return t[0];try{const i=Yo(e);return oa(r,i)}catch(i){return console.warn("XPath query failed, using direct DOM traversal as fallback"),null}}function Xt(r,e){if(typeof r.querySelectorAll=="function")try{const i=r.querySelectorAll(e);if(i.length>0){const o=[];for(let n=0;n<i.length;n++)o.push(i[n]);return o}}catch(i){}const t=ie(r,e);if(t.length>0)return t;try{const i=Yo(e);return na(r,i)}catch(i){return console.warn("XPath query failed, using direct DOM traversal as fallback"),[]}}function sa(r){if(typeof window!="undefined"&&window.XMLSerializer)return new window.XMLSerializer().serializeToString(r);try{const{XMLSerializer:e}=require("@xmldom/xmldom");return new e().serializeToString(r)}catch(e){throw new Error("XML Serializer not available. In Node.js environments, please install @xmldom/xmldom package.")}}const Je={default:"c14n","http://www.w3.org/TR/2001/REC-xml-c14n-20010315":"c14n","http://www.w3.org/2006/12/xml-c14n11":"c14n11","http://www.w3.org/2001/10/xml-exc-c14n#":"c14n_exc"},mt={c14n:{beforeChildren:()=>"",afterChildren:()=>"",betweenChildren:()=>"",afterElement:()=>"",isCanonicalizationMethod:"c14n"},c14n11:{beforeChildren:(r,e)=>e?"":r?`
|
|
5
|
+
`:"",afterChildren:(r,e)=>e?"":r?`
|
|
6
|
+
`:"",betweenChildren:(r,e,t)=>t?"":r&&e?`
|
|
7
|
+
`:"",afterElement:()=>"",isCanonicalizationMethod:"c14n11"},c14n_exc:{beforeChildren:()=>"",afterChildren:()=>"",betweenChildren:()=>"",afterElement:()=>"",isCanonicalizationMethod:"c14n_exc"}},H={ELEMENT_NODE:1,TEXT_NODE:3};class P{constructor(e=mt.c14n){this.method=e}static fromMethod(e){const t=Je[e];if(!t)throw new Error(`Unsupported canonicalization method: ${e}`);return new P(mt[t])}setMethod(e){this.method=e}static escapeXml(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}static collectNamespaces(e,t=new Map){let i=e;for(;i&&i.nodeType===H.ELEMENT_NODE;){const o=i,n=o.getAttribute("xmlns");n!==null&&!t.has("")&&t.set("",n);const s=o.attributes;for(let c=0;c<s.length;c++){const u=s[c];if(u.name.startsWith("xmlns:")){const f=u.name.substring(6);t.has(f)||t.set(f,u.value)}}i=i.parentNode}return t}static collectUsedNamespaces(e,t=new Map,i=[]){const o=new Map,n=new Set;function s(c,u=!1){if(c.nodeType===H.ELEMENT_NODE){const f=c,p=f.namespaceURI,d=f.prefix||"";if(d&&p&&(u||!n.has(d))){n.add(d);const y=t.get(d);y&&y===p&&!o.has(d)&&o.set(d,y)}const w=f.attributes;for(let y=0;y<w.length;y++){const g=w[y];if(g.name.includes(":")&&!g.name.startsWith("xmlns:")){const B=g.name.split(":")[0];if(u||!n.has(B)){n.add(B);const m=t.get(B);m&&!o.has(B)&&o.set(B,m)}}}for(const y of i){const g=t.get(y);g&&!o.has(y)&&o.set(y,g)}for(let y=0;y<c.childNodes.length;y++)s(c.childNodes[y],!1)}}return s(e,!0),o}static isBase64Element(e){if(e.nodeType!==H.ELEMENT_NODE)return!1;const t=e,i=t.localName||t.nodeName.split(":").pop()||"";return this.base64Elements.has(i)}static analyzeWhitespace(e){const t=e.nodeType===H.ELEMENT_NODE?e:e.documentElement;function i(o){if(o.nodeType===H.ELEMENT_NODE){o._whitespace={hasMixedContent:!1,hasExistingLinebreaks:!1,originalContent:{}};const n=Array.from(o.childNodes);let s=!1,c=!1,u=!1;for(const f of n)if(f.nodeType===H.TEXT_NODE&&(f.nodeValue||"").trim().length>0){s=!0;break}for(const f of n)if(f.nodeType===H.ELEMENT_NODE){c=!0;break}for(let f=0;f<n.length;f++){const p=n[f];if(p.nodeType===H.TEXT_NODE){const d=p.nodeValue||"";p._originalText=d,d.includes(`
|
|
8
|
+
`)&&(u=!0)}else p.nodeType===H.ELEMENT_NODE&&i(p)}o._whitespace.hasMixedContent=s&&c,o._whitespace.hasExistingLinebreaks=u}}i(t)}canonicalize(e,t=new Map,i={isStartingNode:!0}){var o,n,s;if(!e)return"";let c="";if(e.nodeType===H.ELEMENT_NODE){const u=new Map(t),f=e,p=f.getAttribute("xmlns");p!==null&&u.set("",p);const d=f.attributes;for(let O=0;O<d.length;O++){const I=d[O];if(I.name.startsWith("xmlns:")){const M=I.name.substring(6);u.set(M,I.value)}}const w=f.prefix||"",y=f.localName||f.nodeName.split(":").pop()||"",g=w?`${w}:${y}`:y;if(c+="<"+g,i.isStartingNode){const O=P.collectNamespaces(e),I=Array.from(O.entries()).sort((M,ye)=>M[0]===""?-1:ye[0]===""?1:M[0].localeCompare(ye[0]));for(const[M,ye]of I)M===""?c+=` xmlns="${ye}"`:c+=` xmlns:${M}="${ye}"`}else{const O=Array.from(u.entries()).filter(([I,M])=>!t.has(I)||t.get(I)!==M).sort((I,M)=>I[0]===""?-1:M[0]===""?1:I[0].localeCompare(M[0]));for(const[I,M]of O)I===""?c+=` xmlns="${M}"`:c+=` xmlns:${I}="${M}"`}const B=f.attributes,m=[];for(let O=0;O<B.length;O++){const I=B[O];I.name.startsWith("xmlns")||m.push(I)}m.sort((O,I)=>O.name.localeCompare(I.name));for(const O of m)c+=` ${O.name}="${P.escapeXml(O.value)}"`;c+=">";const S=Array.from(e.childNodes);let $=!1,vt=!1;const je=((o=e._whitespace)==null?void 0:o.hasMixedContent)||!1;for(const O of S)if(O.nodeType===H.ELEMENT_NODE){$=!0;break}const Gt=this.method.isCanonicalizationMethod==="c14n11"&&$&&!((n=e._whitespace)!=null&&n.hasExistingLinebreaks)&&!je;Gt&&(c+=this.method.beforeChildren($,je));for(let O=0;O<S.length;O++){const I=S[O],M=I.nodeType===H.ELEMENT_NODE,ye=O<S.length-1?S[O+1]:null;if(ye&&(ye.nodeType,H.ELEMENT_NODE),I.nodeType===H.TEXT_NODE){const zt=I.nodeValue||"";P.isBase64Element(e)?c+=zt.replace(/\r/g,"
"):c+=I._originalText||zt,vt=!1;continue}M&&(vt&&this.method.isCanonicalizationMethod==="c14n11"&&!((s=e._whitespace)!=null&&s.hasExistingLinebreaks)&&!je&&(c+=this.method.betweenChildren(!0,!0,je)),c+=this.canonicalize(I,u,{isStartingNode:!1}),vt=!0)}Gt&&(c+=this.method.afterChildren($,je)),c+="</"+g+">"}else if(e.nodeType===H.TEXT_NODE){const u=e._originalText||e.nodeValue||"";c+=P.escapeXml(u)}return c}canonicalizeExclusive(e,t=new Map,i={}){if(!e)return"";const{inclusiveNamespacePrefixList:o=[],isStartingNode:n=!0}=i;let s="";if(e.nodeType===H.ELEMENT_NODE){const c=e,u=P.collectNamespaces(c),f=n?P.collectUsedNamespaces(c,u,o):new Map,p=c.prefix||"",d=c.localName||c.nodeName.split(":").pop()||"",w=p?`${p}:${d}`:d;if(s+="<"+w,n){const m=Array.from(f.entries()).sort((S,$)=>S[0]===""?-1:$[0]===""?1:S[0].localeCompare($[0]));for(const[S,$]of m)S===""?s+=` xmlns="${$}"`:s+=` xmlns:${S}="${$}"`}const y=c.attributes,g=[];for(let m=0;m<y.length;m++){const S=y[m];S.name.startsWith("xmlns")||g.push(S)}g.sort((m,S)=>m.name.localeCompare(S.name));for(const m of g)s+=` ${m.name}="${P.escapeXml(m.value)}"`;s+=">";const B=Array.from(e.childNodes);for(let m=0;m<B.length;m++){const S=B[m];if(S.nodeType===H.TEXT_NODE){const $=S.nodeValue||"";P.isBase64Element(e)?s+=$.replace(/\r/g,"
"):s+=P.escapeXml($)}else S.nodeType===H.ELEMENT_NODE&&(s+=this.canonicalizeExclusive(S,new Map([...t,...f]),{inclusiveNamespacePrefixList:o,isStartingNode:!1}))}s+="</"+w+">"}else if(e.nodeType===H.TEXT_NODE){const c=e.nodeValue||"";s+=P.escapeXml(c)}return s}static c14n(e){return this.analyzeWhitespace(e),new P(mt.c14n).canonicalize(e)}static c14n11(e){return this.analyzeWhitespace(e),new P(mt.c14n11).canonicalize(e)}static c14n_exc(e,t=[]){return this.analyzeWhitespace(e),new P(mt.c14n_exc).canonicalizeExclusive(e,new Map,{inclusiveNamespacePrefixList:t})}static canonicalize(e,t,i={}){switch(Je[t]||Je.default){case"c14n":return this.c14n(e);case"c14n11":return this.c14n11(e);case"c14n_exc":return this.c14n_exc(e,i.inclusiveNamespacePrefixList||[]);default:throw new Error(`Unsupported canonicalization method: ${t}`)}}}P.base64Elements=new Set(["DigestValue","X509Certificate","EncapsulatedTimeStamp","EncapsulatedOCSPValue","IssuerSerialV2"]);var aa=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});function ca(r){if(!r)return"";const e=r.replace(/\s+/g,""),t=[];for(let i=0;i<e.length;i+=64)t.push(e.substring(i,i+64));return`-----BEGIN CERTIFICATE-----
|
|
9
|
+
${t.join(`
|
|
10
|
+
`)}
|
|
11
|
+
-----END CERTIFICATE-----`}function Zo(r){var e,t,i,o,n,s,c,u;const f={validFrom:r.notBefore,validTo:r.notAfter,issuer:{}};try{if(typeof r.subject=="object"&&r.subject!==null){const p=r.subject;f.commonName=p.commonName,f.organization=p.organizationName,f.country=p.countryName}if(typeof r.issuer=="object"&&r.issuer!==null){const p=r.issuer;f.issuer.commonName=p.commonName,f.issuer.organization=p.organizationName,f.issuer.country=p.countryName}}catch(p){console.warn("Could not extract subject/issuer as objects:",p)}try{if(typeof r.subject=="string"){const p=r.subject.split(",");for(const d of p){const[w,y]=d.trim().split("=");w==="CN"&&(f.commonName=f.commonName||y),w==="O"&&(f.organization=f.organization||y),w==="C"&&(f.country=f.country||y),w==="SN"&&(f.surname=y),(w==="G"||w==="GN")&&(f.givenName=y),(w==="SERIALNUMBER"||w==="2.5.4.5")&&(f.serialNumber=y==null?void 0:y.replace("PNOLV-",""))}}if(typeof r.issuer=="string"){const p=r.issuer.split(",");for(const d of p){const[w,y]=d.trim().split("=");w==="CN"&&(f.issuer.commonName=f.issuer.commonName||y),w==="O"&&(f.issuer.organization=f.issuer.organization||y),w==="C"&&(f.issuer.country=f.issuer.country||y)}}}catch(p){console.warn("Could not extract subject/issuer as strings:",p)}try{if("subjectName"in r&&(e=r.subjectName)!=null&&e.getField){const p=r.subjectName;f.commonName=f.commonName||((t=p.getField("CN"))==null?void 0:t[0]),f.surname=f.surname||((i=p.getField("SN"))==null?void 0:i[0]),f.givenName=f.givenName||((o=p.getField("G"))==null?void 0:o[0]),f.serialNumber=f.serialNumber||((s=(n=p.getField("2.5.4.5"))==null?void 0:n[0])==null?void 0:s.replace("PNOLV-","")),f.country=f.country||((c=p.getField("C"))==null?void 0:c[0]),f.organization=f.organization||((u=p.getField("O"))==null?void 0:u[0])}}catch(p){console.warn("Could not extract fields using getField method:",p)}return!f.serialNumber&&r.serialNumber&&(f.serialNumber=r.serialNumber),f}function Qo(r){return aa(this,null,function*(){try{let e=r;if(!r.includes("-----BEGIN CERTIFICATE-----")){const o=r.replace(/[\r\n\s]/g,"");e=ca(o)}const t=new V.X509Certificate(e),i=Zo(t);return{subject:{commonName:i.commonName,organization:i.organization,country:i.country,surname:i.surname,givenName:i.givenName,serialNumber:i.serialNumber},validFrom:i.validFrom,validTo:i.validTo,issuer:i.issuer,serialNumber:t.serialNumber}}catch(e){throw console.error("Certificate parsing error:",e),new Error("Failed to parse certificate: "+(e instanceof Error?e.message:String(e)))}})}function la(r,e=new Date){const t="notBefore"in r?r.notBefore:r.validFrom,i="notAfter"in r?r.notAfter:r.validTo;return e<t?{isValid:!1,reason:`Certificate not yet valid. Valid from ${t.toISOString()}`}:e>i?{isValid:!1,reason:`Certificate expired. Valid until ${i.toISOString()}`}:{isValid:!0}}function ua(r){const{subject:e}=r;return e.givenName&&e.surname?`${e.givenName} ${e.surname}`:e.commonName?e.commonName:e.serialNumber||"Unknown Signer"}function fa(r){const{validFrom:e,validTo:t}=r,i=o=>o.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"});return`${i(e)} to ${i(t)}`}function Wt(r){if(!r)return"";const e=r.replace(/\s+/g,""),t=[];for(let i=0;i<e.length;i+=64)t.push(e.substring(i,i+64));return`-----BEGIN CERTIFICATE-----
|
|
12
|
+
${t.join(`
|
|
10
13
|
`)}
|
|
11
|
-
-----END CERTIFICATE-----`}
|
|
14
|
+
-----END CERTIFICATE-----`}var ha=Object.defineProperty,pa=Object.defineProperties,da=Object.getOwnPropertyDescriptors,en=Object.getOwnPropertySymbols,ya=Object.prototype.hasOwnProperty,ga=Object.prototype.propertyIsEnumerable,tn=(r,e,t)=>e in r?ha(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,rn=(r,e)=>{for(var t in e||(e={}))ya.call(e,t)&&tn(r,t,e[t]);if(en)for(var t of en(e))ga.call(e,t)&&tn(r,t,e[t]);return r},on=(r,e)=>pa(r,da(e));function va(r){return Array.from(r.keys()).filter(e=>e.match(/META-INF\/signatures\d*\.xml$/)||e.match(/META-INF\/.*signatures.*\.xml$/i))}function ma(r,e){const t=new TextDecoder().decode(r),i=Jo().parseFromString(t,"application/xml"),o=Xt(i,"ds\\:Signature, Signature");if(o.length===0){if(console.warn(`No Signature elements found in ${e}`),t.includes("XAdESSignatures")){const s=i.documentElement;if(s){const u=K(s,"ds\\:Signature, Signature");if(u){let f=nn(u,i);return f.rawXml=t,f}}const c=wa(t);if(c)return on(rn({},c),{rawXml:t})}return null}let n=nn(o[0],i);return n.rawXml=t,n}function nn(r,e){var t,i,o,n,s;const c=r.getAttribute("Id")||"unknown",u=K(r,"ds\\:SignedInfo, SignedInfo");if(!u)throw new Error("SignedInfo element not found");const f=K(u,"ds\\:CanonicalizationMethod, CanonicalizationMethod");let p=Je.default;f&&(p=f.getAttribute("Algorithm")||p);let d="";d=sa(u);const w=K(u,"ds\\:SignatureMethod, SignatureMethod"),y=(w==null?void 0:w.getAttribute("Algorithm"))||"",g=K(r,"ds\\:SignatureValue, SignatureValue"),B=((t=g==null?void 0:g.textContent)==null?void 0:t.replace(/\s+/g,""))||"";let m="",S="",$=[],vt,je;const Gt=K(r,"ds\\:KeyInfo, KeyInfo");if(Gt){const _=K(Gt,"ds\\:X509Data, X509Data");if(_){const X=Xt(_,"ds\\:X509Certificate, X509Certificate");if(X.length>0){m=((i=X[0].textContent)==null?void 0:i.replace(/\s+/g,""))||"";for(let Ue=1;Ue<X.length;Ue++){const be=((o=X[Ue].textContent)==null?void 0:o.replace(/\s+/g,""))||"";be&&$.push(Wt(be))}}}}if(!m){const _=K(r,"ds\\:X509Certificate, X509Certificate");_&&(m=((n=_.textContent)==null?void 0:n.replace(/\s+/g,""))||"")}const O=K(e,"xades\\:CertificateValues, CertificateValues");if(O){const _=Xt(O,"xades\\:EncapsulatedX509Certificate, EncapsulatedX509Certificate");for(const X of _){const Ue=((s=X.textContent)==null?void 0:s.replace(/\s+/g,""))||"";if(Ue){const be=Wt(Ue);$.includes(be)||$.push(be)}}}if(m){S=Wt(m);try{const _=new V.X509Certificate(S),X=_.publicKey.algorithm;je=on(rn({algorithm:X.name},"namedCurve"in X?{namedCurve:X.namedCurve}:{}),{rawData:_.publicKey.rawData}),vt=Zo(_)}catch(_){console.error("Failed to extract certificate information:",_)}}const I=K(e,"xades\\:SigningTime, SigningTime"),M=I&&I.textContent?new Date(I.textContent.trim()):new Date,ye=[],zt={},Zs={},tl=Xt(u,"ds\\:Reference, Reference");for(const _ of tl){const X=_.getAttribute("URI")||"",Ue=_.getAttribute("Type")||"";if(!X||X.startsWith("#")||Ue.includes("SignedProperties"))continue;let be=X;try{be=decodeURIComponent(X)}catch(ti){console.error(`Failed to decode URI: ${X}`,ti)}const zo=be.startsWith("./")?be.substring(2):be;ye.push(zo);const ea=K(_,"ds\\:DigestMethod, DigestMethod");if(ea){const ti=ea.getAttribute("Algorithm");ti&&(Zs[zo]=ti)}const Xo=K(_,"ds\\:DigestValue, DigestValue");Xo&&Xo.textContent&&(zt[zo]=Xo.textContent.replace(/\s+/g,""))}let Qs;const Go=K(e,"xades\\:EncapsulatedTimeStamp, EncapsulatedTimeStamp");return Go&&Go.textContent&&(Qs=Go.textContent.replace(/\s+/g,"")),{id:c,signingTime:M,certificate:m,certificatePEM:S,certificateChain:$.length>0?$:void 0,publicKey:je,signerInfo:vt,signedChecksums:zt,digestAlgorithms:Zs,references:ye,algorithm:y,signatureValue:B,signedInfoXml:d,canonicalizationMethod:p,signatureTimestamp:Qs}}function wa(r){try{const e=r.match(/<ds:Signature[^>]*Id=["']([^"']*)["']/),t=e&&e[1]?e[1]:"unknown",i=r.match(/<ds:SignatureValue[^>]*>([\s\S]*?)<\/ds:SignatureValue>/),o=i&&i[1]?i[1].replace(/\s+/g,""):"",n=r.match(/<ds:X509Certificate>([\s\S]*?)<\/ds:X509Certificate>/),s=n&&n[1]?n[1].replace(/\s+/g,""):"",c=r.match(/<ds:SignatureMethod[^>]*Algorithm=["']([^"']*)["']/),u=c&&c[1]?c[1]:"",f=r.match(/<xades:SigningTime>([\s\S]*?)<\/xades:SigningTime>/),p=f&&f[1]?new Date(f[1].trim()):new Date,d=[],w={},y=/<ds:Reference[^>]*URI=["']([^#][^"']*)["'][^>]*>[\s\S]*?<ds:DigestValue>([\s\S]*?)<\/ds:DigestValue>/g;let g;for(;(g=y.exec(r))!==null;)if(g[1]&&!g[1].startsWith("#")){const m=decodeURIComponent(g[1]);d.push(m),g[2]&&(w[m]=g[2].replace(/\s+/g,""))}const B=Wt(s);return{id:t,signingTime:p,certificate:s,certificatePEM:B,signedChecksums:w,references:d,algorithm:u,signatureValue:o}}catch(e){return console.error("Error in fallback text parsing:",e),null}}function ba(r){try{const e=R.unzipSync(r),t=new Map,i=[],o=[];Object.entries(e).forEach(([f,p])=>{t.set(f,p),f.startsWith("META-INF/")||f==="mimetype"?o.push(f):i.push(f)});const n=[],s=va(t),c=new Set;for(const f of s){const p=t.get(f);if(p)try{const d=ma(p,f);d&&(n.push(d),d.references&&d.references.length>0&&d.references.forEach(w=>{t.has(w)&&c.add(w)}))}catch(d){console.error(`Error parsing signature ${f}:`,d)}}const u=Array.from(c);return{files:t,documentFileList:i,metadataFileList:o,signedFileList:u,signatures:n}}catch(e){throw new Error(`Failed to parse eDoc container: ${e instanceof Error?e.message:String(e)}`)}}function Aa(r){const e=()=>{},t=new Uint8Array(r);if(t[0]!==48)return r;const i=[6,9,42,134,72,134,247,13,1,1,1];let o=-1;for(let g=0;g<=t.length-i.length;g++){let B=!0;for(let m=0;m<i.length;m++)if(t[g+m]!==i[m]){B=!1;break}if(B){o=g;break}}if(o===-1)return r;let n=-1;for(let g=o+i.length;g<t.length;g++)if(t[g]===3){n=g;break}if(n===-1)return r;let s=0;(t[n+1]&128)===0?s=1:s=1+(t[n+1]&127);const c=n+1+s;if(c>=t.length)return r;const u=c+1;if(u>=t.length||t[u]!==48)return r;let f=0;(t[u+1]&128)===0?f=1:f=1+(t[u+1]&127);const p=u+1+f;if(p>=t.length||t[p]!==2)return r;let d=0,w=0;if((t[p+1]&128)===0)w=t[p+1],d=1;else{const g=t[p+1]&127;d=1+g,w=0;for(let B=0;B<g;B++)w=w<<8|t[p+2+B]}const y=p+1+d;if(y>=t.length)return r;if((t[y]&128)!==0){const g=new Uint8Array(t.length+1);if(g.set(t.slice(0,y)),g[y]=0,g.set(t.slice(y),y+1),(t[p+1]&128)===0)g[p+1]=t[p+1]+1;else{const B=t[p+1]&127;let m=0;for(let S=0;S<B;S++)m=m<<8|t[p+2+S];m+=1;for(let S=B-1;S>=0;S--)g[p+2+S]=m&255,m>>=8}if((t[u+1]&128)===0)g[u+1]=t[u+1]+1;else{const B=t[u+1]&127;let m=0;for(let S=0;S<B;S++)m=m<<8|t[u+2+S];m+=1;for(let S=B-1;S>=0;S--)g[u+2+S]=m&255,m>>=8}if((t[n+1]&128)===0)g[n+1]=t[n+1]+1;else{const B=t[n+1]&127;let m=0;for(let S=0;S<B;S++)m=m<<8|t[n+2+S];m+=1;for(let S=B-1;S>=0;S--)g[n+2+S]=m&255,m>>=8}if((t[1]&128)===0)g[1]=t[1]+1;else{const B=t[1]&127;let m=0;for(let S=0;S<B;S++)m=m<<8|t[2+S];m+=1;for(let S=B-1;S>=0;S--)g[2+S]=m&255,m>>=8}return e("Fixed key length: "+g.length),g.buffer}return r}const Sa={ocspEnabled:!0,crlEnabled:!0,ocspTimeout:5e3,crlTimeout:1e4};/*!
|
|
15
|
+
* MIT License
|
|
16
|
+
*
|
|
17
|
+
* Copyright (c) 2017-2024 Peculiar Ventures, LLC
|
|
18
|
+
*
|
|
19
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
21
|
+
* in the Software without restriction, including without limitation the rights
|
|
22
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
24
|
+
* furnished to do so, subject to the following conditions:
|
|
25
|
+
*
|
|
26
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
27
|
+
* copies or substantial portions of the Software.
|
|
28
|
+
*
|
|
29
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
+
* SOFTWARE.
|
|
36
|
+
*
|
|
37
|
+
*/const Ba="[object ArrayBuffer]";class N{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ba}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){const i=N.toUint8Array(e),o=N.toUint8Array(t);if(i.length!==o.byteLength)return!1;for(let n=0;n<i.length;n++)if(i[n]!==o[n])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let i=0;for(const s of t)i+=s.byteLength;const o=new Uint8Array(i);let n=0;for(const s of t){const c=this.toUint8Array(s);o.set(c,n),n+=c.length}return e[e.length-1]instanceof Function?this.toView(o,e[e.length-1]):o.buffer}}const ii="string",ka=/^[0-9a-f\s]+$/i,xa=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Na=/^[a-zA-Z0-9-_]+$/;class sn{static fromString(e){const t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let o=0;o<t.length;o++)i[o]=t.charCodeAt(o);return i.buffer}static toString(e){const t=N.toUint8Array(e);let i="";for(let n=0;n<t.length;n++)i+=String.fromCharCode(t[n]);return decodeURIComponent(escape(i))}}class ge{static toString(e,t=!1){const i=N.toArrayBuffer(e),o=new DataView(i);let n="";for(let s=0;s<i.byteLength;s+=2){const c=o.getUint16(s,t);n+=String.fromCharCode(c)}return n}static fromString(e,t=!1){const i=new ArrayBuffer(e.length*2),o=new DataView(i);for(let n=0;n<e.length;n++)o.setUint16(n*2,e.charCodeAt(n),t);return i}}class U{static isHex(e){return typeof e===ii&&ka.test(e)}static isBase64(e){return typeof e===ii&&xa.test(e)}static isBase64Url(e){return typeof e===ii&&Na.test(e)}static ToString(e,t="utf8"){const i=N.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(i);case"binary":return this.ToBinary(i);case"hex":return this.ToHex(i);case"base64":return this.ToBase64(i);case"base64url":return this.ToBase64Url(i);case"utf16le":return ge.toString(i,!0);case"utf16":case"utf16be":return ge.toString(i);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 ge.fromString(e,!0);case"utf16":case"utf16be":return ge.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=N.toUint8Array(e);if(typeof btoa!="undefined"){const i=this.ToString(t,"binary");return btoa(i)}else return Buffer.from(t).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!U.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob!="undefined"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!U.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=U.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return sn.fromString(e);case"utf16":case"utf16be":return ge.fromString(e);case"utf16le":case"usc2":return ge.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=U.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return sn.toString(e);case"utf16":case"utf16be":return ge.toString(e);case"utf16le":case"usc2":return ge.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,i=new Uint8Array(t);for(let o=0;o<t;o++)i[o]=e.charCodeAt(o);return i.buffer}static ToBinary(e){const t=N.toUint8Array(e);let i="";for(let o=0;o<t.length;o++)i+=String.fromCharCode(t[o]);return i}static ToHex(e){const t=N.toUint8Array(e);let i="";const o=t.length;for(let n=0;n<o;n++){const s=t[n];s<16&&(i+="0"),i+=s.toString(16)}return i}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!U.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const i=new Uint8Array(t.length/2);for(let o=0;o<t.length;o=o+2){const n=t.slice(o,o+2);i[o/2]=parseInt(n,16)}return i.buffer}static ToUtf16String(e,t=!1){return ge.toString(e,t)}static FromUtf16String(e,t=!1){return ge.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let i=0;i<t;i++)e+="=";return e}static formatString(e){return(e==null?void 0:e.replace(/[\n\r\t ]/g,""))||""}}U.DEFAULT_UTF8_ENCODING="utf8";function Ca(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;const t=new Uint8Array(r),i=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==i[o])return!1;return!0}/*!
|
|
38
|
+
Copyright (c) Peculiar Ventures, LLC
|
|
39
|
+
*/function Ke(r,e){let t=0;if(r.length===1)return r[0];for(let i=r.length-1;i>=0;i--)t+=r[r.length-1-i]*Math.pow(2,e*i);return t}function De(r,e,t=-1){const i=t;let o=r,n=0,s=Math.pow(2,e);for(let c=1;c<8;c++){if(r<s){let u;if(i<0)u=new ArrayBuffer(c),n=c;else{if(i<c)return new ArrayBuffer(0);u=new ArrayBuffer(i),n=i}const f=new Uint8Array(u);for(let p=c-1;p>=0;p--){const d=Math.pow(2,p*e);f[n-p-1]=Math.floor(o/d),o-=f[n-p-1]*d}return u}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function oi(...r){let e=0,t=0;for(const n of r)e+=n.length;const i=new ArrayBuffer(e),o=new Uint8Array(i);for(const n of r)o.set(n,t),t+=n.length;return o}function an(){const r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const c=r[0]===255&&r[1]&128,u=r[0]===0&&(r[1]&128)===0;(c||u)&&this.warnings.push("Needlessly long format")}const e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let c=0;c<this.valueHex.byteLength;c++)t[c]=0;t[0]=r[0]&128;const i=Ke(t,8),o=new ArrayBuffer(this.valueHex.byteLength),n=new Uint8Array(o);for(let c=0;c<this.valueHex.byteLength;c++)n[c]=r[c];return n[0]&=127,Ke(n,8)-i}function Ea(r){const e=r<0?r*-1:r;let t=128;for(let i=1;i<8;i++){if(e<=t){if(r<0){const s=t-e,c=De(s,8,i),u=new Uint8Array(c);return u[0]|=128,c}let o=De(e,8,i),n=new Uint8Array(o);if(n[0]&128){const s=o.slice(0),c=new Uint8Array(s);o=new ArrayBuffer(o.byteLength+1),n=new Uint8Array(o);for(let u=0;u<s.byteLength;u++)n[u+1]=c[u];n[0]=0}return o}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ia(r,e){if(r.byteLength!==e.byteLength)return!1;const t=new Uint8Array(r),i=new Uint8Array(e);for(let o=0;o<t.length;o++)if(t[o]!==i[o])return!1;return!0}function ee(r,e){const t=r.toString(10);if(e<t.length)return"";const i=e-t.length,o=new Array(i);for(let s=0;s<i;s++)o[s]="0";return o.join("").concat(t)}/*!
|
|
40
|
+
* Copyright (c) 2014, GMO GlobalSign
|
|
41
|
+
* Copyright (c) 2015-2022, Peculiar Ventures
|
|
42
|
+
* All rights reserved.
|
|
43
|
+
*
|
|
44
|
+
* Author 2014-2019, Yury Strozhevsky
|
|
45
|
+
*
|
|
46
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
47
|
+
* are permitted provided that the following conditions are met:
|
|
48
|
+
*
|
|
49
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
|
50
|
+
* list of conditions and the following disclaimer.
|
|
51
|
+
*
|
|
52
|
+
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
53
|
+
* list of conditions and the following disclaimer in the documentation and/or
|
|
54
|
+
* other materials provided with the distribution.
|
|
55
|
+
*
|
|
56
|
+
* * Neither the name of the copyright holder nor the names of its
|
|
57
|
+
* contributors may be used to endorse or promote products derived from
|
|
58
|
+
* this software without specific prior written permission.
|
|
59
|
+
*
|
|
60
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
61
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
62
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
63
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
64
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
65
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
66
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
67
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
68
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
69
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
70
|
+
*
|
|
71
|
+
*/function Jt(){if(typeof BigInt=="undefined")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function ni(r){let e=0,t=0;for(let o=0;o<r.length;o++){const n=r[o];e+=n.byteLength}const i=new Uint8Array(e);for(let o=0;o<r.length;o++){const n=r[o];i.set(new Uint8Array(n),t),t+=n.byteLength}return i.buffer}function Ae(r,e,t,i){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):i<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-i<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class Kt{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return ni(this.items)}}const wt=[new Uint8Array([1])],cn="0123456789",si="name",ln="valueHexView",Oa="isHexOnly",Ta="idBlock",Va="tagClass",ja="tagNumber",Ua="isConstructed",Da="fromBER",Ra="toBER",La="local",Y="",se=new ArrayBuffer(0),Yt=new Uint8Array(0),bt="EndOfContent",un="OCTET STRING",fn="BIT STRING";function ve(r){var e;return e=class extends r{get valueHex(){return this.valueHexView.slice().buffer}set valueHex(i){this.valueHexView=new Uint8Array(i)}constructor(...i){var o;super(...i);const n=i[0]||{};this.isHexOnly=(o=n.isHexOnly)!==null&&o!==void 0?o:!1,this.valueHexView=n.valueHex?N.toUint8Array(n.valueHex):Yt}fromBER(i,o,n){const s=i instanceof ArrayBuffer?new Uint8Array(i):i;if(!Ae(this,s,o,n))return-1;const c=o+n;return this.valueHexView=s.subarray(o,c),this.valueHexView.length?(this.blockLength=n,c):(this.warnings.push("Zero buffer length"),o)}toBER(i=!1){return this.isHexOnly?i?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",se)}toJSON(){return L(T({},super.toJSON()),{isHexOnly:this.isHexOnly,valueHex:U.ToHex(this.valueHexView)})}},e.NAME="hexBlock",e}class Re{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=Y,warnings:i=[],valueBeforeDecode:o=Yt}={}){this.blockLength=e,this.error=t,this.warnings=i,this.valueBeforeDecodeView=N.toUint8Array(o)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:U.ToHex(this.valueBeforeDecodeView)}}}Re.NAME="baseBlock";class W extends Re{fromBER(e,t,i){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'")}}W.NAME="valueBlock";class hn extends ve(Re){constructor({idBlock:e={}}={}){var t,i,o,n;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?N.toUint8Array(e.valueHex):Yt,this.tagClass=(i=e.tagClass)!==null&&i!==void 0?i:-1,this.tagNumber=(o=e.tagNumber)!==null&&o!==void 0?o:-1,this.isConstructed=(n=e.isConstructed)!==null&&n!==void 0?n:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",se}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const o=new Uint8Array(1);if(!e){let n=this.tagNumber;n&=31,t|=n,o[0]=t}return o.buffer}if(!this.isHexOnly){const o=De(this.tagNumber,7),n=new Uint8Array(o),s=o.byteLength,c=new Uint8Array(s+1);if(c[0]=t|31,!e){for(let u=0;u<s-1;u++)c[u+1]=n[u]|128;c[s]=n[s-1]}return c.buffer}const i=new Uint8Array(this.valueHexView.byteLength+1);if(i[0]=t|31,!e){const o=this.valueHexView;for(let n=0;n<o.length-1;n++)i[n+1]=o[n]|128;i[this.valueHexView.byteLength]=o[o.length-1]}return i.buffer}fromBER(e,t,i){const o=N.toUint8Array(e);if(!Ae(this,o,t,i))return-1;const n=o.subarray(t,t+i);if(n.length===0)return this.error="Zero buffer length",-1;switch(n[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(n[0]&32)===32,this.isHexOnly=!1;const c=n[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let u=1,f=this.valueHexView=new Uint8Array(255),p=255;for(;n[u]&128;){if(f[u-1]=n[u]&127,u++,u>=n.length)return this.error="End of input reached before message was fully decoded",-1;if(u===p){p+=255;const w=new Uint8Array(p);for(let y=0;y<f.length;y++)w[y]=f[y];f=this.valueHexView=new Uint8Array(p)}}this.blockLength=u+1,f[u-1]=n[u]&127;const d=new Uint8Array(u);for(let w=0;w<u;w++)d[w]=f[w];f=this.valueHexView=new Uint8Array(u),f.set(d),this.blockLength<=9?this.tagNumber=Ke(f,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 L(T({},super.toJSON()),{tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed})}}hn.NAME="identificationBlock";class pn extends Re{constructor({lenBlock:e={}}={}){var t,i,o;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(i=e.longFormUsed)!==null&&i!==void 0?i:!1,this.length=(o=e.length)!==null&&o!==void 0?o:0}fromBER(e,t,i){const o=N.toUint8Array(e);if(!Ae(this,o,t,i))return-1;const n=o.subarray(t,t+i);if(n.length===0)return this.error="Zero buffer length",-1;if(n[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=n[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(n[0]&128),this.longFormUsed===!1)return this.length=n[0],this.blockLength=1,t+this.blockLength;const s=n[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>n.length)return this.error="End of input reached before message was fully decoded",-1;const c=t+1,u=o.subarray(c,c+s);return u[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ke(u,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,t+this.blockLength}toBER(e=!1){let t,i;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(i=new Uint8Array(t),i[0]=128),t;if(this.longFormUsed){const o=De(this.length,8);if(o.byteLength>127)return this.error="Too big length",se;if(t=new ArrayBuffer(o.byteLength+1),e)return t;const n=new Uint8Array(o);i=new Uint8Array(t),i[0]=o.byteLength|128;for(let s=0;s<o.byteLength;s++)i[s+1]=n[s];return t}return t=new ArrayBuffer(1),e===!1&&(i=new Uint8Array(t),i[0]=this.length),t}toJSON(){return L(T({},super.toJSON()),{isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length})}}pn.NAME="lengthBlock";const b={};class q extends Re{constructor(s={},n){var c=s,{name:e=Y,optional:t=!1,primitiveSchema:i}=c,o=D(c,["name","optional","primitiveSchema"]);super(o),this.name=e,this.optional=t,i&&(this.primitiveSchema=i),this.idBlock=new hn(o),this.lenBlock=new pn(o),this.valueBlock=n?new n(o):new W(o)}fromBER(e,t,i){const o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?i:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}toBER(e,t){const i=t||new Kt;t||dn(this);const o=this.idBlock.toBER(e);if(i.write(o),this.lenBlock.isIndefiniteForm)i.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,i),i.write(new ArrayBuffer(2));else{const n=this.valueBlock.toBER(e);this.lenBlock.length=n.byteLength;const s=this.lenBlock.toBER(e);i.write(s),i.write(n)}return t?se:i.final()}toJSON(){const e=L(T({},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():U.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,t=U.ToHex(this.valueBlock.valueBeforeDecodeView);return`${e} : ${t}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const t=this.toBER(),i=e.toBER();return Ia(t,i)}}q.NAME="BaseBlock";function dn(r){var e;if(r instanceof b.Constructed)for(const t of r.valueBlock.value)dn(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class ai extends q{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(o={},i){var n=o,{value:e=Y}=n,t=D(n,["value"]);super(t,i),e&&this.fromString(e)}fromBER(e,t,i){const o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?i:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}ai.NAME="BaseStringBlock";class yn extends ve(W){constructor(i={}){var o=i,{isHexOnly:e=!0}=o,t=D(o,["isHexOnly"]);super(t),this.isHexOnly=e}}yn.NAME="PrimitiveValueBlock";var gn;class At extends q{constructor(e={}){super(e,yn),this.idBlock.isConstructed=!1}}gn=At,b.Primitive=gn,At.NAME="PRIMITIVE";function Ha(r,e){if(r instanceof e)return r;const t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function Ye(r,e=0,t=r.length){const i=e;let o=new q({},W);const n=new Re;if(!Ae(n,r,e,t))return o.error=n.error,{offset:-1,result:o};if(!r.subarray(e,e+t).length)return o.error="Zero buffer length",{offset:-1,result:o};let c=o.idBlock.fromBER(r,e,t);if(o.idBlock.warnings.length&&o.warnings.concat(o.idBlock.warnings),c===-1)return o.error=o.idBlock.error,{offset:-1,result:o};if(e=c,t-=o.idBlock.blockLength,c=o.lenBlock.fromBER(r,e,t),o.lenBlock.warnings.length&&o.warnings.concat(o.lenBlock.warnings),c===-1)return o.error=o.lenBlock.error,{offset:-1,result:o};if(e=c,t-=o.lenBlock.blockLength,!o.idBlock.isConstructed&&o.lenBlock.isIndefiniteForm)return o.error="Indefinite length form used for primitive encoding form",{offset:-1,result:o};let u=q;switch(o.idBlock.tagClass){case 1:if(o.idBlock.tagNumber>=37&&o.idBlock.isHexOnly===!1)return o.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:o};switch(o.idBlock.tagNumber){case 0:if(o.idBlock.isConstructed&&o.lenBlock.length>0)return o.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:o};u=b.EndOfContent;break;case 1:u=b.Boolean;break;case 2:u=b.Integer;break;case 3:u=b.BitString;break;case 4:u=b.OctetString;break;case 5:u=b.Null;break;case 6:u=b.ObjectIdentifier;break;case 10:u=b.Enumerated;break;case 12:u=b.Utf8String;break;case 13:u=b.RelativeObjectIdentifier;break;case 14:u=b.TIME;break;case 15:return o.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:o};case 16:u=b.Sequence;break;case 17:u=b.Set;break;case 18:u=b.NumericString;break;case 19:u=b.PrintableString;break;case 20:u=b.TeletexString;break;case 21:u=b.VideotexString;break;case 22:u=b.IA5String;break;case 23:u=b.UTCTime;break;case 24:u=b.GeneralizedTime;break;case 25:u=b.GraphicString;break;case 26:u=b.VisibleString;break;case 27:u=b.GeneralString;break;case 28:u=b.UniversalString;break;case 29:u=b.CharacterString;break;case 30:u=b.BmpString;break;case 31:u=b.DATE;break;case 32:u=b.TimeOfDay;break;case 33:u=b.DateTime;break;case 34:u=b.Duration;break;default:{const f=o.idBlock.isConstructed?new b.Constructed:new b.Primitive;f.idBlock=o.idBlock,f.lenBlock=o.lenBlock,f.warnings=o.warnings,o=f}}break;case 2:case 3:case 4:default:u=o.idBlock.isConstructed?b.Constructed:b.Primitive}return o=Ha(o,u),c=o.fromBER(r,e,o.lenBlock.isIndefiniteForm?t:o.lenBlock.length),o.valueBeforeDecodeView=r.subarray(i,i+o.blockLength),{offset:c,result:o}}function Ze(r){if(!r.byteLength){const e=new q({},W);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ye(N.toUint8Array(r).slice(),0,r.byteLength)}function $a(r,e){return r?1:e}class Oe extends W{constructor(o={}){var n=o,{value:e=[],isIndefiniteForm:t=!1}=n,i=D(n,["value","isIndefiniteForm"]);super(i),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,i){const o=N.toUint8Array(e);if(!Ae(this,o,t,i))return-1;if(this.valueBeforeDecodeView=o.subarray(t,t+i),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let n=t;for(;$a(this.isIndefiniteForm,i)>0;){const s=Ye(o,n,i);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(n=s.offset,this.blockLength+=s.result.blockLength,i-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===bt)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===bt?this.value.pop():this.warnings.push("No EndOfContent block encoded")),n}toBER(e,t){const i=t||new Kt;for(let o=0;o<this.value.length;o++)this.value[o].toBER(e,i);return t?se:i.final()}toJSON(){const e=L(T({},super.toJSON()),{isIndefiniteForm:this.isIndefiniteForm,value:[]});for(const t of this.value)e.value.push(t.toJSON());return e}}Oe.NAME="ConstructedValueBlock";var vn;class J extends q{constructor(e={}){super(e,Oe),this.idBlock.isConstructed=!0}fromBER(e,t,i){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const o=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?i:this.lenBlock.length);return o===-1?(this.error=this.valueBlock.error,o):(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),o)}onAsciiEncoding(){const e=[];for(const i of this.valueBlock.value)e.push(i.toString("ascii").split(`
|
|
72
|
+
`).map(o=>` ${o}`).join(`
|
|
73
|
+
`));const t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
|
|
12
74
|
${e.join(`
|
|
75
|
+
`)}`:`${t} :`}}vn=J,b.Constructed=vn,J.NAME="CONSTRUCTED";class mn extends W{fromBER(e,t,i){return t}toBER(e){return se}}mn.override="EndOfContentValueBlock";var wn;class ci extends q{constructor(e={}){super(e,mn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}wn=ci,b.EndOfContent=wn,ci.NAME=bt;var bn;class Le extends q{constructor(e={}){super(e,W),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,i){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+=i,t+i>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+i}toBER(e,t){const i=new ArrayBuffer(2);if(!e){const o=new Uint8Array(i);o[0]=5,o[1]=0}return t&&t.write(i),i}onAsciiEncoding(){return`${this.constructor.NAME}`}}bn=Le,b.Null=bn,Le.NAME="NULL";class An extends ve(W){get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}constructor(i={}){var o=i,{value:e}=o,t=D(o,["value"]);super(t),t.valueHex?this.valueHexView=N.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,i){const o=N.toUint8Array(e);return Ae(this,o,t,i)?(this.valueHexView=o.subarray(t,t+i),i>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,an.call(this),this.blockLength=i,t+i):-1}toBER(){return this.valueHexView.slice()}toJSON(){return L(T({},super.toJSON()),{value:this.value})}}An.NAME="BooleanValueBlock";var Sn;class Zt extends q{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,An),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Sn=Zt,b.Boolean=Sn,Zt.NAME="BOOLEAN";class Bn extends ve(Oe){constructor(i={}){var o=i,{isConstructed:e=!1}=o,t=D(o,["isConstructed"]);super(t),this.isConstructed=e}fromBER(e,t,i){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=Oe.prototype.fromBER.call(this,e,t,i),o===-1)return o;for(let n=0;n<this.value.length;n++){const s=this.value[n].constructor.NAME;if(s===bt){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==un)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,i),this.blockLength=i;return o}toBER(e,t){return this.isConstructed?Oe.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return L(T({},super.toJSON()),{isConstructed:this.isConstructed})}}Bn.NAME="OctetStringValueBlock";var li;class He extends q{constructor(o={}){var n=o,{idBlock:e={},lenBlock:t={}}=n,i=D(n,["idBlock","lenBlock"]);var s,c;(s=i.isConstructed)!==null&&s!==void 0||(i.isConstructed=!!(!((c=i.value)===null||c===void 0)&&c.length)),super(T({idBlock:T({isConstructed:i.isConstructed},e),lenBlock:L(T({},t),{isIndefiniteForm:!!i.isIndefiniteForm})},i),Bn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,i){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,i===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const n=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+i);try{if(n.byteLength){const s=Ye(n,0,n.byteLength);s.offset!==-1&&s.offset===i&&(this.valueBlock.value=[s.result])}}catch(s){}}return super.fromBER(e,t,i)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return J.prototype.onAsciiEncoding.call(this);const e=this.constructor.NAME,t=U.ToHex(this.valueBlock.valueHexView);return`${e} : ${t}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof li&&e.push(t.valueBlock.valueHexView);return N.concat(e)}}li=He,b.OctetString=li,He.NAME=un;class kn extends ve(Oe){constructor(o={}){var n=o,{unusedBits:e=0,isConstructed:t=!1}=n,i=D(n,["unusedBits","isConstructed"]);super(i),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,i){if(!i)return t;let o=-1;if(this.isConstructed){if(o=Oe.prototype.fromBER.call(this,e,t,i),o===-1)return o;for(const c of this.value){const u=c.constructor.NAME;if(u===bt){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(u!==fn)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const f=c.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}const n=N.toUint8Array(e);if(!Ae(this,n,t,i))return-1;const s=n.subarray(t,t+i);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const c=s.subarray(1);try{if(c.byteLength){const u=Ye(c,0,c.byteLength);u.offset!==-1&&u.offset===i-1&&(this.value=[u.result])}}catch(u){}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,t+i}toBER(e,t){if(this.isConstructed)return Oe.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return se;const i=new Uint8Array(this.valueHexView.length+1);return i[0]=this.unusedBits,i.set(this.valueHexView,1),i.buffer}toJSON(){return L(T({},super.toJSON()),{unusedBits:this.unusedBits,isConstructed:this.isConstructed})}}kn.NAME="BitStringValueBlock";var xn;class $e extends q{constructor(o={}){var n=o,{idBlock:e={},lenBlock:t={}}=n,i=D(n,["idBlock","lenBlock"]);var s,c;(s=i.isConstructed)!==null&&s!==void 0||(i.isConstructed=!!(!((c=i.value)===null||c===void 0)&&c.length)),super(T({idBlock:T({isConstructed:i.isConstructed},e),lenBlock:L(T({},t),{isIndefiniteForm:!!i.isIndefiniteForm})},i),kn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,i){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,i)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return J.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const s of t)e.push(s.toString(2).padStart(8,"0"));const i=e.join(""),o=this.constructor.NAME,n=i.substring(0,i.length-this.valueBlock.unusedBits);return`${o} : ${n}`}}}xn=$e,b.BitString=xn,$e.NAME=fn;var Nn;function Ma(r,e){const t=new Uint8Array([0]),i=new Uint8Array(r),o=new Uint8Array(e);let n=i.slice(0);const s=n.length-1,c=o.slice(0),u=c.length-1;let f=0;const p=u<s?s:u;let d=0;for(let w=p;w>=0;w--,d++){switch(!0){case d<c.length:f=n[s-d]+c[u-d]+t[0];break;default:f=n[s-d]+t[0]}switch(t[0]=f/10,!0){case d>=n.length:n=oi(new Uint8Array([f%10]),n);break;default:n[s-d]=f%10}}return t[0]>0&&(n=oi(t,n)),n}function Cn(r){if(r>=wt.length)for(let e=wt.length;e<=r;e++){const t=new Uint8Array([0]);let i=wt[e-1].slice(0);for(let o=i.length-1;o>=0;o--){const n=new Uint8Array([(i[o]<<1)+t[0]]);t[0]=n[0]/10,i[o]=n[0]%10}t[0]>0&&(i=oi(t,i)),wt.push(i)}return wt[r]}function Pa(r,e){let t=0;const i=new Uint8Array(r),o=new Uint8Array(e),n=i.slice(0),s=n.length-1,c=o.slice(0),u=c.length-1;let f,p=0;for(let d=u;d>=0;d--,p++)switch(f=n[s-p]-c[u-p]-t,!0){case f<0:t=1,n[s-p]=f+10;break;default:t=0,n[s-p]=f}if(t>0)for(let d=s-u+1;d>=0;d--,p++)if(f=n[s-p]-t,f<0)t=1,n[s-p]=f+10;else{t=0,n[s-p]=f;break}return n.slice()}class ui extends ve(W){setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=an.call(this)))}constructor(i={}){var o=i,{value:e}=o,t=D(o,["value"]);super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Ea(e))}get valueDec(){return this._valueDec}fromDER(e,t,i,o=0){const n=this.fromBER(e,t,i);if(n===-1)return n;const s=this.valueHexView;return s[0]===0&&(s[1]&128)!==0?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),n}toDER(e=!1){const t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{const i=new Uint8Array(this.valueHexView.length+1);i[0]=0,i.set(t,1),this.valueHexView=i}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,i){const o=super.fromBER(e,t,i);return o===-1||this.setValueHex(),o}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return L(T({},super.toJSON()),{valueDec:this.valueDec})}toString(){const e=this.valueHexView.length*8-1;let t=new Uint8Array(this.valueHexView.length*8/3),i=0,o;const n=this.valueHexView;let s="",c=!1;for(let u=n.byteLength-1;u>=0;u--){o=n[u];for(let f=0;f<8;f++){if((o&1)===1)switch(i){case e:t=Pa(Cn(i),t),s="-";break;default:t=Ma(t,Cn(i))}i++,o>>=1}}for(let u=0;u<t.length;u++)t[u]&&(c=!0),c&&(s+=cn.charAt(t[u]));return c===!1&&(s+=cn.charAt(0)),s}}Nn=ui,ui.NAME="IntegerValueBlock",Object.defineProperty(Nn.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var St;class Qe extends q{constructor(e={}){super(e,ui),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Jt(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Jt();const t=BigInt(e),i=new Kt,o=t.toString(16).replace(/^-/,""),n=new Uint8Array(U.FromHex(o));if(t<0){const c=new Uint8Array(n.length+(n[0]&128?1:0));c[0]|=128;const f=BigInt(`0x${U.ToHex(c)}`)+t,p=N.toUint8Array(U.FromHex(f.toString(16)));p[0]|=128,i.write(p)}else n[0]&128&&i.write(new Uint8Array([0])),i.write(n);return new St({valueHex:i.final()})}convertToDER(){const e=new St({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new St({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}St=Qe,b.Integer=St,Qe.NAME="INTEGER";var En;class Qt extends Qe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}En=Qt,b.Enumerated=En,Qt.NAME="ENUMERATED";class fi extends ve(W){constructor(o={}){var n=o,{valueDec:e=-1,isFirstSid:t=!1}=n,i=D(n,["valueDec","isFirstSid"]);super(i),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,i){if(!i)return t;const o=N.toUint8Array(e);if(!Ae(this,o,t,i))return-1;const n=o.subarray(t,t+i);this.valueHexView=new Uint8Array(i);for(let c=0;c<i&&(this.valueHexView[c]=n[c]&127,this.blockLength++,(n[c]&128)!==0);c++);const s=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)s[c]=this.valueHexView[c];return this.valueHexView=s,(n[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ke(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){Jt();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const i=new Uint8Array(t.length/7);for(let o=0;o<i.length;o++)i[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+1<i.length?128:0);this.fromBER(i.buffer,0,i.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const o=this.valueHexView,n=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)n[s]=o[s]|128;return n[this.blockLength-1]=o[this.blockLength-1],n.buffer}const t=De(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",se;const i=new Uint8Array(t.byteLength);if(!e){const o=new Uint8Array(t),n=t.byteLength-1;for(let s=0;s<n;s++)i[s]=o[s]|128;i[n]=o[n]}return i}toString(){let e="";if(this.isHexOnly)e=U.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return L(T({},super.toJSON()),{valueDec:this.valueDec,isFirstSid:this.isFirstSid})}}fi.NAME="sidBlock";class In extends W{constructor(i={}){var o=i,{value:e=Y}=o,t=D(o,["value"]);super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,i){let o=t;for(;i>0;){const n=new fi;if(o=n.fromBER(e,o,i),o===-1)return this.blockLength=0,this.error=n.error,o;this.value.length===0&&(n.isFirstSid=!0),this.blockLength+=n.blockLength,i-=n.blockLength,this.value.push(n)}return o}toBER(e){const t=[];for(let i=0;i<this.value.length;i++){const o=this.value[i].toBER(e);if(o.byteLength===0)return this.error=this.value[i].error,se;t.push(o)}return ni(t)}fromString(e){this.value=[];let t=0,i=0,o="",n=!1;do if(i=e.indexOf(".",t),i===-1?o=e.substring(t):o=e.substring(t,i),t=i+1,n){const s=this.value[0];let c=0;switch(s.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}const u=parseInt(o,10);if(isNaN(u))return;s.valueDec=u+c,n=!1}else{const s=new fi;if(o>Number.MAX_SAFE_INTEGER){Jt();const c=BigInt(o);s.valueBigInt=c}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,n=!0),this.value.push(s)}while(i!==-1)}toString(){let e="",t=!1;for(let i=0;i<this.value.length;i++){t=this.value[i].isHexOnly;let o=this.value[i].toString();i!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[i].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){const e=L(T({},super.toJSON()),{value:this.toString(),sidArray:[]});for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}In.NAME="ObjectIdentifierValueBlock";var On;class er extends q{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,In),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return L(T({},super.toJSON()),{value:this.getValue()})}}On=er,b.ObjectIdentifier=On,er.NAME="OBJECT IDENTIFIER";class hi extends ve(Re){constructor(i={}){var o=i,{valueDec:e=0}=o,t=D(o,["valueDec"]);super(t),this.valueDec=e}fromBER(e,t,i){if(i===0)return t;const o=N.toUint8Array(e);if(!Ae(this,o,t,i))return-1;const n=o.subarray(t,t+i);this.valueHexView=new Uint8Array(i);for(let c=0;c<i&&(this.valueHexView[c]=n[c]&127,this.blockLength++,(n[c]&128)!==0);c++);const s=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)s[c]=this.valueHexView[c];return this.valueHexView=s,(n[this.blockLength-1]&128)!==0?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ke(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const o=this.valueHexView,n=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)n[s]=o[s]|128;return n[this.blockLength-1]=o[this.blockLength-1],n.buffer}const t=De(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",se;const i=new Uint8Array(t.byteLength);if(!e){const o=new Uint8Array(t),n=t.byteLength-1;for(let s=0;s<n;s++)i[s]=o[s]|128;i[n]=o[n]}return i.buffer}toString(){let e="";return this.isHexOnly?e=U.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return L(T({},super.toJSON()),{valueDec:this.valueDec})}}hi.NAME="relativeSidBlock";class Tn extends W{constructor(i={}){var o=i,{value:e=Y}=o,t=D(o,["value"]);super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,i){let o=t;for(;i>0;){const n=new hi;if(o=n.fromBER(e,o,i),o===-1)return this.blockLength=0,this.error=n.error,o;this.blockLength+=n.blockLength,i-=n.blockLength,this.value.push(n)}return o}toBER(e,t){const i=[];for(let o=0;o<this.value.length;o++){const n=this.value[o].toBER(e);if(n.byteLength===0)return this.error=this.value[o].error,se;i.push(n)}return ni(i)}fromString(e){this.value=[];let t=0,i=0,o="";do{i=e.indexOf(".",t),i===-1?o=e.substring(t):o=e.substring(t,i),t=i+1;const n=new hi;if(n.valueDec=parseInt(o,10),isNaN(n.valueDec))return!0;this.value.push(n)}while(i!==-1);return!0}toString(){let e="",t=!1;for(let i=0;i<this.value.length;i++){t=this.value[i].isHexOnly;let o=this.value[i].toString();i!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){const e=L(T({},super.toJSON()),{value:this.toString(),sidArray:[]});for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Tn.NAME="RelativeObjectIdentifierValueBlock";var Vn;class pi extends q{getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}constructor(e={}){super(e,Tn),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return L(T({},super.toJSON()),{value:this.getValue()})}}Vn=pi,b.RelativeObjectIdentifier=Vn,pi.NAME="RelativeObjectIdentifier";var jn;class ae extends J{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}jn=ae,b.Sequence=jn,ae.NAME="SEQUENCE";var Un;class me extends J{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}Un=me,b.Set=Un,me.NAME="SET";class Dn extends ve(W){constructor(t={}){var e=D(t,[]);super(e),this.isHexOnly=!0,this.value=Y}toJSON(){return L(T({},super.toJSON()),{value:this.value})}}Dn.NAME="StringValueBlock";class Rn extends Dn{}Rn.NAME="SimpleStringValueBlock";class te extends ai{constructor(t={}){var e=D(t,[]);super(e,Rn)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,N.toUint8Array(e))}fromString(e){const t=e.length,i=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)i[o]=e.charCodeAt(o);this.valueBlock.value=e}}te.NAME="SIMPLE STRING";class Ln extends te{fromBuffer(e){this.valueBlock.valueHexView=N.toUint8Array(e);try{this.valueBlock.value=U.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=U.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(U.FromUtf8String(e)),this.valueBlock.value=e}}Ln.NAME="Utf8StringValueBlock";var Hn;class Se extends Ln{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}Hn=Se,b.Utf8String=Hn,Se.NAME="UTF8String";class $n extends te{fromBuffer(e){this.valueBlock.value=U.ToUtf16String(e),this.valueBlock.valueHexView=N.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(U.FromUtf16String(e))}}$n.NAME="BmpStringValueBlock";var Mn;class tr extends $n{constructor(t={}){var e=D(t,[]);super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}Mn=tr,b.BmpString=Mn,tr.NAME="BMPString";class Pn extends te{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),i=new Uint8Array(t);for(let o=0;o<i.length;o+=4)i[o]=i[o+3],i[o+1]=i[o+2],i[o+2]=0,i[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,i=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){const n=De(e.charCodeAt(o),8),s=new Uint8Array(n);if(s.length>4)continue;const c=4-s.length;for(let u=s.length-1;u>=0;u--)i[o*4+u+c]=s[u]}this.valueBlock.value=e}}Pn.NAME="UniversalStringValueBlock";var _n;class rr extends Pn{constructor(t={}){var e=D(t,[]);super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}_n=rr,b.UniversalString=_n,rr.NAME="UniversalString";var qn;class ir extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}qn=ir,b.NumericString=qn,ir.NAME="NumericString";var Fn;class or extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Fn=or,b.PrintableString=Fn,or.NAME="PrintableString";var Gn;class nr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}Gn=nr,b.TeletexString=Gn,nr.NAME="TeletexString";var zn;class sr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}zn=sr,b.VideotexString=zn,sr.NAME="VideotexString";var Xn;class ar extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}Xn=ar,b.IA5String=Xn,ar.NAME="IA5String";var Wn;class cr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}Wn=cr,b.GraphicString=Wn,cr.NAME="GraphicString";var Jn;class Bt extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}Jn=Bt,b.VisibleString=Jn,Bt.NAME="VisibleString";var Kn;class lr extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}Kn=lr,b.GeneralString=Kn,lr.NAME="GeneralString";var Yn;class ur extends te{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}Yn=ur,b.CharacterString=Yn,ur.NAME="CharacterString";var Zn;class kt extends Bt{constructor(o={}){var n=o,{value:e,valueDate:t}=n,i=D(n,["value","valueDate"]);if(super(i),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,N.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let o=0;o<e.length;o++)i[o]=e.charCodeAt(o);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const i=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(i===null){this.error="Wrong input string for conversion";return}const o=parseInt(i[1],10);o>=50?this.year=1900+o:this.year=2e3+o,this.month=parseInt(i[2],10),this.day=parseInt(i[3],10),this.hour=parseInt(i[4],10),this.minute=parseInt(i[5],10),this.second=parseInt(i[6],10)}toString(e="iso"){if(e==="iso"){const t=new Array(7);return t[0]=ee(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=ee(this.month,2),t[2]=ee(this.day,2),t[3]=ee(this.hour,2),t[4]=ee(this.minute,2),t[5]=ee(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return L(T({},super.toJSON()),{year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second})}}Zn=kt,b.UTCTime=Zn,kt.NAME="UTCTime";var Qn;class fr extends kt{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){const e=Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond);return new Date(e)}fromString(e){let t=!1,i="",o="",n=0,s,c=0,u=0;if(e[e.length-1]==="Z")i=e.substring(0,e.length-1),t=!0;else{const d=new Number(e[e.length-1]);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");i=e}if(t){if(i.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(i.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let d=1,w=i.indexOf("+"),y="";if(w===-1&&(w=i.indexOf("-"),d=-1),w!==-1){if(y=i.substring(w+1),i=i.substring(0,w),y.length!==2&&y.length!==4)throw new Error("Wrong input string for conversion");let g=parseInt(y.substring(0,2),10);if(isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");if(c=d*g,y.length===4){if(g=parseInt(y.substring(2,4),10),isNaN(g.valueOf()))throw new Error("Wrong input string for conversion");u=d*g}}}let f=i.indexOf(".");if(f===-1&&(f=i.indexOf(",")),f!==-1){const d=new Number(`0${i.substring(f)}`);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");n=d.valueOf(),o=i.substring(0,f)}else o=i;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let d=60*n;this.minute=Math.floor(d),d=60*(d-this.minute),this.second=Math.floor(d),d=1e3*(d-this.second),this.millisecond=Math.floor(d)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let d=60*n;this.second=Math.floor(d),d=1e3*(d-this.second),this.millisecond=Math.floor(d)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){const d=1e3*n;this.millisecond=Math.floor(d)}break;default:throw new Error("Wrong input string for conversion")}const p=s.exec(o);if(p===null)throw new Error("Wrong input string for conversion");for(let d=1;d<p.length;d++)switch(d){case 1:this.year=parseInt(p[d],10);break;case 2:this.month=parseInt(p[d],10);break;case 3:this.day=parseInt(p[d],10);break;case 4:this.hour=parseInt(p[d],10)+c;break;case 5:this.minute=parseInt(p[d],10)+u;break;case 6:this.second=parseInt(p[d],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){const d=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=d.getUTCFullYear(),this.month=d.getUTCMonth(),this.day=d.getUTCDay(),this.hour=d.getUTCHours(),this.minute=d.getUTCMinutes(),this.second=d.getUTCSeconds(),this.millisecond=d.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){const t=[];return t.push(ee(this.year,4)),t.push(ee(this.month,2)),t.push(ee(this.day,2)),t.push(ee(this.hour,2)),t.push(ee(this.minute,2)),t.push(ee(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(ee(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return L(T({},super.toJSON()),{millisecond:this.millisecond})}}Qn=fr,b.GeneralizedTime=Qn,fr.NAME="GeneralizedTime";var es;class di extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}}es=di,b.DATE=es,di.NAME="DATE";var ts;class yi extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}}ts=yi,b.TimeOfDay=ts,yi.NAME="TimeOfDay";var rs;class gi extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}}rs=gi,b.DateTime=rs,gi.NAME="DateTime";var is;class vi extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}}is=vi,b.Duration=is,vi.NAME="Duration";var os;class mi extends Se{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}}os=mi,b.TIME=os,mi.NAME="TIME";class Me{constructor({name:e=Y,optional:t=!1}={}){this.name=e,this.optional=t}}class wi extends Me{constructor(i={}){var o=i,{value:e=[]}=o,t=D(o,["value"]);super(t),this.value=e}}class hr extends Me{constructor(o={}){var n=o,{value:e=new Me,local:t=!1}=n,i=D(n,["value","local"]);super(i),this.value=e,this.local=t}}class _a{get data(){return this.dataView.slice().buffer}set data(e){this.dataView=N.toUint8Array(e)}constructor({data:e=Yt}={}){this.dataView=N.toUint8Array(e)}fromBER(e,t,i){const o=t+i;return this.dataView=N.toUint8Array(e).subarray(t,o),o}toBER(e){return this.dataView.slice().buffer}}function Te(r,e,t){if(t instanceof wi){for(const n of t.value)if(Te(r,e,n).verified)return{verified:!0,result:r};{const n={verified:!1,result:{error:"Wrong values for Choice type"}};return t.hasOwnProperty(si)&&(n.name=t.name),n}}if(t instanceof Me)return t.hasOwnProperty(si)&&(r[t.name]=e),{verified:!0,result:r};if(!(r instanceof Object))return{verified:!1,result:{error:"Wrong root object"}};if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 data"}};if(!(t instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Ta in t))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Da in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(!(Ra in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const i=t.idBlock.toBER(!1);if(i.byteLength===0)return{verified:!1,result:{error:"Error encoding idBlock for ASN.1 schema"}};if(t.idBlock.fromBER(i,0,i.byteLength)===-1)return{verified:!1,result:{error:"Error decoding idBlock for ASN.1 schema"}};if(t.idBlock.hasOwnProperty(Va)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagClass!==e.idBlock.tagClass)return{verified:!1,result:r};if(t.idBlock.hasOwnProperty(ja)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.tagNumber!==e.idBlock.tagNumber)return{verified:!1,result:r};if(t.idBlock.hasOwnProperty(Ua)===!1)return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isConstructed!==e.idBlock.isConstructed)return{verified:!1,result:r};if(!(Oa in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};if(t.idBlock.isHexOnly!==e.idBlock.isHexOnly)return{verified:!1,result:r};if(t.idBlock.isHexOnly){if(!(ln in t.idBlock))return{verified:!1,result:{error:"Wrong ASN.1 schema"}};const n=t.idBlock.valueHexView,s=e.idBlock.valueHexView;if(n.length!==s.length)return{verified:!1,result:r};for(let c=0;c<n.length;c++)if(n[c]!==s[1])return{verified:!1,result:r}}if(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&(r[t.name]=e)),t instanceof b.Constructed){let n=0,s={verified:!1,result:{error:"Unknown error"}},c=t.valueBlock.value.length;if(c>0&&t.valueBlock.value[0]instanceof hr&&(c=e.valueBlock.value.length),c===0)return{verified:!0,result:r};if(e.valueBlock.value.length===0&&t.valueBlock.value.length!==0){let u=!0;for(let f=0;f<t.valueBlock.value.length;f++)u=u&&(t.valueBlock.value[f].optional||!1);return u?{verified:!0,result:r}:(t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&delete r[t.name]),r.error="Inconsistent object length",{verified:!1,result:r})}for(let u=0;u<c;u++)if(u-n>=e.valueBlock.value.length){if(t.valueBlock.value[u].optional===!1){const f={verified:!1,result:r};return r.error="Inconsistent length between ASN.1 data and schema",t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&(delete r[t.name],f.name=t.name)),f}}else if(t.valueBlock.value[0]instanceof hr){if(s=Te(r,e.valueBlock.value[u],t.valueBlock.value[0].value),s.verified===!1)if(t.valueBlock.value[0].optional)n++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&delete r[t.name]),s;if(si in t.valueBlock.value[0]&&t.valueBlock.value[0].name.length>0){let f={};La in t.valueBlock.value[0]&&t.valueBlock.value[0].local?f=e:f=r,typeof f[t.valueBlock.value[0].name]=="undefined"&&(f[t.valueBlock.value[0].name]=[]),f[t.valueBlock.value[0].name].push(e.valueBlock.value[u])}}else if(s=Te(r,e.valueBlock.value[u-n],t.valueBlock.value[u]),s.verified===!1)if(t.valueBlock.value[u].optional)n++;else return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&delete r[t.name]),s;if(s.verified===!1){const u={verified:!1,result:r};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&(delete r[t.name],u.name=t.name)),u}return{verified:!0,result:r}}if(t.primitiveSchema&&ln in e.valueBlock){const n=Ye(e.valueBlock.valueHexView);if(n.offset===-1){const s={verified:!1,result:n.result};return t.name&&(t.name=t.name.replace(/^\s+|\s+$/g,Y),t.name&&(delete r[t.name],s.name=t.name)),s}return Te(r,n.result,t.primitiveSchema)}return{verified:!0,result:r}}function qa(r,e){if(!(e instanceof Object))return{verified:!1,result:{error:"Wrong ASN.1 schema type"}};const t=Ye(N.toUint8Array(r));return t.offset===-1?{verified:!1,result:t.result}:Te(t.result,t.result,e)}var ns=Object.freeze({__proto__:null,Any:Me,BaseBlock:q,BaseStringBlock:ai,BitString:$e,BmpString:tr,Boolean:Zt,CharacterString:ur,Choice:wi,Constructed:J,DATE:di,DateTime:gi,Duration:vi,EndOfContent:ci,Enumerated:Qt,GeneralString:lr,GeneralizedTime:fr,GraphicString:cr,HexBlock:ve,IA5String:ar,Integer:Qe,Null:Le,NumericString:ir,ObjectIdentifier:er,OctetString:He,Primitive:At,PrintableString:or,RawData:_a,RelativeObjectIdentifier:pi,Repeated:hr,Sequence:ae,Set:me,TIME:mi,TeletexString:nr,TimeOfDay:yi,UTCTime:kt,UniversalString:rr,Utf8String:Se,ValueBlock:W,VideotexString:sr,ViewWriter:Kt,VisibleString:Bt,compareSchema:Te,fromBER:Ze,verifySchema:qa}),v;(function(r){r[r.Sequence=0]="Sequence",r[r.Set=1]="Set",r[r.Choice=2]="Choice"})(v||(v={}));var h;(function(r){r[r.Any=1]="Any",r[r.Boolean=2]="Boolean",r[r.OctetString=3]="OctetString",r[r.BitString=4]="BitString",r[r.Integer=5]="Integer",r[r.Enumerated=6]="Enumerated",r[r.ObjectIdentifier=7]="ObjectIdentifier",r[r.Utf8String=8]="Utf8String",r[r.BmpString=9]="BmpString",r[r.UniversalString=10]="UniversalString",r[r.NumericString=11]="NumericString",r[r.PrintableString=12]="PrintableString",r[r.TeletexString=13]="TeletexString",r[r.VideotexString=14]="VideotexString",r[r.IA5String=15]="IA5String",r[r.GraphicString=16]="GraphicString",r[r.VisibleString=17]="VisibleString",r[r.GeneralString=18]="GeneralString",r[r.CharacterString=19]="CharacterString",r[r.UTCTime=20]="UTCTime",r[r.GeneralizedTime=21]="GeneralizedTime",r[r.DATE=22]="DATE",r[r.TimeOfDay=23]="TimeOfDay",r[r.DateTime=24]="DateTime",r[r.Duration=25]="Duration",r[r.TIME=26]="TIME",r[r.Null=27]="Null"})(h||(h={}));class pr{constructor(e,t=0){if(this.unusedBits=0,this.value=new ArrayBuffer(0),e)if(typeof e=="number")this.fromNumber(e);else if(N.isBufferSource(e))this.unusedBits=t,this.value=N.toArrayBuffer(e);else throw TypeError("Unsupported type of 'params' argument for BitString")}fromASN(e){if(!(e instanceof $e))throw new TypeError("Argument 'asn' is not instance of ASN.1 BitString");return this.unusedBits=e.valueBlock.unusedBits,this.value=e.valueBlock.valueHex,this}toASN(){return new $e({unusedBits:this.unusedBits,valueHex:this.value})}toSchema(e){return new $e({name:e})}toNumber(){let e="";const t=new Uint8Array(this.value);for(const i of t)e+=i.toString(2).padStart(8,"0");return e=e.split("").reverse().join(""),this.unusedBits&&(e=e.slice(this.unusedBits).padStart(this.unusedBits,"0")),parseInt(e,2)}fromNumber(e){let t=e.toString(2);const i=t.length+7>>3;this.unusedBits=(i<<3)-t.length;const o=new Uint8Array(i);t=t.padStart(i<<3,"0").split("").reverse().join("");let n=0;for(;n<i;)o[n]=parseInt(t.slice(n<<3,(n<<3)+8),2),n++;this.value=o.buffer}}class C{get byteLength(){return this.buffer.byteLength}get byteOffset(){return 0}constructor(e){typeof e=="number"?this.buffer=new ArrayBuffer(e):N.isBufferSource(e)?this.buffer=N.toArrayBuffer(e):Array.isArray(e)?this.buffer=new Uint8Array(e):this.buffer=new ArrayBuffer(0)}fromASN(e){if(!(e instanceof He))throw new TypeError("Argument 'asn' is not instance of ASN.1 OctetString");return this.buffer=e.valueBlock.valueHex,this}toASN(){return new He({valueHex:this.buffer})}toSchema(e){return new He({name:e})}}const Fa={fromASN:r=>r instanceof Le?null:r.valueBeforeDecodeView,toASN:r=>{if(r===null)return new Le;const e=Ze(r);if(e.result.error)throw new Error(e.result.error);return e.result}},Ga={fromASN:r=>r.valueBlock.valueHexView.byteLength>=4?r.valueBlock.toString():r.valueBlock.valueDec,toASN:r=>new Qe({value:+r})},za={fromASN:r=>r.valueBlock.valueDec,toASN:r=>new Qt({value:r})},re={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new Qe({valueHex:r})},Xa={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new $e({valueHex:r})},Wa={fromASN:r=>r.valueBlock.toString(),toASN:r=>new er({value:r})},Ja={fromASN:r=>r.valueBlock.value,toASN:r=>new Zt({value:r})},bi={fromASN:r=>r.valueBlock.valueHexView,toASN:r=>new He({valueHex:r})},Ka={fromASN:r=>new C(r.getValue()),toASN:r=>r.toASN()};function oe(r){return{fromASN:e=>e.valueBlock.value,toASN:e=>new r({value:e})}}const Ya=oe(Se),Za=oe(tr),Qa=oe(rr),ec=oe(ir),tc=oe(or),rc=oe(nr),ic=oe(sr),oc=oe(ar),nc=oe(cr),sc=oe(Bt),ac=oe(lr),cc=oe(ur),lc={fromASN:r=>r.toDate(),toASN:r=>new kt({valueDate:r})},uc={fromASN:r=>r.toDate(),toASN:r=>new fr({valueDate:r})},fc={fromASN:()=>null,toASN:()=>new Le};function xt(r){switch(r){case h.Any:return Fa;case h.BitString:return Xa;case h.BmpString:return Za;case h.Boolean:return Ja;case h.CharacterString:return cc;case h.Enumerated:return za;case h.GeneralString:return ac;case h.GeneralizedTime:return uc;case h.GraphicString:return nc;case h.IA5String:return oc;case h.Integer:return Ga;case h.Null:return fc;case h.NumericString:return ec;case h.ObjectIdentifier:return Wa;case h.OctetString:return bi;case h.PrintableString:return tc;case h.TeletexString:return rc;case h.UTCTime:return lc;case h.UniversalString:return Qa;case h.Utf8String:return Ya;case h.VideotexString:return ic;case h.VisibleString:return sc;default:return null}}function Be(r){return typeof r=="function"&&r.prototype?r.prototype.toASN&&r.prototype.fromASN?!0:Be(r.prototype):!!(r&&typeof r=="object"&&"toASN"in r&&"fromASN"in r)}function ss(r){var e;if(r){const t=Object.getPrototypeOf(r);return((e=t==null?void 0:t.prototype)===null||e===void 0?void 0:e.constructor)===Array?!0:ss(t)}return!1}function hc(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;const t=new Uint8Array(r),i=new Uint8Array(e);for(let o=0;o<r.byteLength;o++)if(t[o]!==i[o])return!1;return!0}class pc{constructor(){this.items=new WeakMap}has(e){return this.items.has(e)}get(e,t=!1){const i=this.items.get(e);if(!i)throw new Error(`Cannot get schema for '${e.prototype.constructor.name}' target`);if(t&&!i.schema)throw new Error(`Schema '${e.prototype.constructor.name}' doesn't contain ASN.1 schema. Call 'AsnSchemaStorage.cache'.`);return i}cache(e){const t=this.get(e);t.schema||(t.schema=this.create(e,!0))}createDefault(e){const t={type:v.Sequence,items:{}},i=this.findParentSchema(e);return i&&(Object.assign(t,i),t.items=Object.assign({},t.items,i.items)),t}create(e,t){const i=this.items.get(e)||this.createDefault(e),o=[];for(const n in i.items){const s=i.items[n],c=t?n:"";let u;if(typeof s.type=="number"){const p=h[s.type],d=ns[p];if(!d)throw new Error(`Cannot get ASN1 class by name '${p}'`);u=new d({name:c})}else Be(s.type)?u=new s.type().toSchema(c):s.optional?this.get(s.type).type===v.Choice?u=new Me({name:c}):(u=this.create(s.type,!1),u.name=c):u=new Me({name:c});const f=!!s.optional||s.defaultValue!==void 0;if(s.repeated){u.name="";const p=s.repeated==="set"?me:ae;u=new p({name:"",value:[new hr({name:c,value:u})]})}if(s.context!==null&&s.context!==void 0)if(s.implicit)if(typeof s.type=="number"||Be(s.type)){const p=s.repeated?J:At;o.push(new p({name:c,optional:f,idBlock:{tagClass:3,tagNumber:s.context}}))}else{this.cache(s.type);const p=!!s.repeated;let d=p?u:this.get(s.type,!0).schema;d="valueBlock"in d?d.valueBlock.value:d.value,o.push(new J({name:p?"":c,optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:d}))}else o.push(new J({optional:f,idBlock:{tagClass:3,tagNumber:s.context},value:[u]}));else u.optional=f,o.push(u)}switch(i.type){case v.Sequence:return new ae({value:o,name:""});case v.Set:return new me({value:o,name:""});case v.Choice:return new wi({value:o,name:""});default:throw new Error("Unsupported ASN1 type in use")}}set(e,t){return this.items.set(e,t),this}findParentSchema(e){const t=Object.getPrototypeOf(e);return t?this.items.get(t)||this.findParentSchema(t):null}}const F=new pc,A=r=>e=>{let t;F.has(e)?t=F.get(e):(t=F.createDefault(e),F.set(e,t)),Object.assign(t,r)},l=r=>(e,t)=>{let i;F.has(e.constructor)?i=F.get(e.constructor):(i=F.createDefault(e.constructor),F.set(e.constructor,i));const o=Object.assign({},r);if(typeof o.type=="number"&&!o.converter){const n=xt(r.type);if(!n)throw new Error(`Cannot get default converter for property '${t}' of ${e.constructor.name}`);o.converter=n}o.raw=r.raw,i.items[t]=o};class Nt extends Error{constructor(){super(...arguments),this.schemas=[]}}class dc{static parse(e,t){const i=Ze(e);if(i.result.error)throw new Error(i.result.error);return this.fromASN(i.result,t)}static fromASN(e,t){try{if(Be(t))return new t().fromASN(e);const i=F.get(t);F.cache(t);let o=i.schema;const n=this.handleChoiceTypes(e,i,t,o);if(n!=null&&n.result)return n.result;n!=null&&n.targetSchema&&(o=n.targetSchema);const s=this.handleSequenceTypes(e,i,t,o),c=new t;return ss(t)?this.handleArrayTypes(e,i,t):(this.processSchemaItems(i,s,c),c)}catch(i){throw i instanceof Nt&&i.schemas.push(t.name),i}}static handleChoiceTypes(e,t,i,o){if(e.constructor===J&&t.type===v.Choice&&e.idBlock.tagClass===3)for(const n in t.items){const s=t.items[n];if(s.context===e.idBlock.tagNumber&&s.implicit&&typeof s.type=="function"&&F.has(s.type)){const c=F.get(s.type);if(c&&c.type===v.Sequence){const u=new ae;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in u.valueBlock){u.valueBlock.value=e.valueBlock.value;const f=this.fromASN(u,s.type),p=new i;return p[n]=f,{result:p}}}}}else if(e.constructor===J&&t.type!==v.Choice){const n=new J({idBlock:{tagClass:3,tagNumber:e.idBlock.tagNumber},value:t.schema.valueBlock.value});for(const s in t.items)delete e[s];return{targetSchema:n}}return null}static handleSequenceTypes(e,t,i,o){if(t.type===v.Sequence){const n=Te({},e,o);if(!n.verified)throw new Nt(`Data does not match to ${i.name} ASN1 schema.${n.result.error?` ${n.result.error}`:""}`);return n}else{const n=Te({},e,o);if(!n.verified)throw new Nt(`Data does not match to ${i.name} ASN1 schema.${n.result.error?` ${n.result.error}`:""}`);return n}}static processRepeatedField(e,t,i){let o=e.slice(t);if(o.length===1&&o[0].constructor.name==="Sequence"){const n=o[0];n.valueBlock&&n.valueBlock.value&&Array.isArray(n.valueBlock.value)&&(o=n.valueBlock.value)}if(typeof i.type=="number"){const n=xt(i.type);if(!n)throw new Error(`No converter for ASN.1 type ${i.type}`);return o.filter(s=>s&&s.valueBlock).map(s=>{try{return n.fromASN(s)}catch(c){return}}).filter(s=>s!==void 0)}else return o.filter(n=>n&&n.valueBlock).map(n=>{try{return this.fromASN(n,i.type)}catch(s){return}}).filter(n=>n!==void 0)}static processPrimitiveField(e,t){const i=xt(t.type);if(!i)throw new Error(`No converter for ASN.1 type ${t.type}`);return i.fromASN(e)}static isOptionalChoiceField(e){return e.optional&&typeof e.type=="function"&&F.has(e.type)&&F.get(e.type).type===v.Choice}static processOptionalChoiceField(e,t){try{return{processed:!0,value:this.fromASN(e,t.type)}}catch(i){if(i instanceof Nt&&/Wrong values for Choice type/.test(i.message))return{processed:!1};throw i}}static handleArrayTypes(e,t,i){if(!("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const o=t.itemType;if(typeof o=="number"){const n=xt(o);if(!n)throw new Error(`Cannot get default converter for array item of ${i.name} ASN1 schema`);return i.from(e.valueBlock.value,s=>n.fromASN(s))}else return i.from(e.valueBlock.value,n=>this.fromASN(n,o))}static processSchemaItems(e,t,i){for(const o in e.items){const n=t.result[o];if(!n)continue;const s=e.items[o],c=s.type;let u;typeof c=="number"||Be(c)?u=this.processPrimitiveSchemaItem(n,s,c):u=this.processComplexSchemaItem(n,s,c),u&&typeof u=="object"&&"value"in u&&"raw"in u?(i[o]=u.value,i[`${o}Raw`]=u.raw):i[o]=u}}static processPrimitiveSchemaItem(e,t,i){var o;const n=(o=t.converter)!==null&&o!==void 0?o:Be(i)?new i:null;if(!n)throw new Error("Converter is empty");return t.repeated?this.processRepeatedPrimitiveItem(e,t,n):this.processSinglePrimitiveItem(e,t,i,n)}static processRepeatedPrimitiveItem(e,t,i){if(t.implicit){const o=t.repeated==="sequence"?ae:me,n=new o;n.valueBlock=e.valueBlock;const s=Ze(n.toBER(!1));if(s.offset===-1)throw new Error(`Cannot parse the child item. ${s.result.error}`);if(!("value"in s.result.valueBlock&&Array.isArray(s.result.valueBlock.value)))throw new Error("Cannot get items from the ASN.1 parsed value. ASN.1 object is not constructed.");const c=s.result.valueBlock.value;return Array.from(c,u=>i.fromASN(u))}else return Array.from(e,o=>i.fromASN(o))}static processSinglePrimitiveItem(e,t,i,o){let n=e;if(t.implicit){let s;if(Be(i))s=new i().toSchema("");else{const c=h[i],u=ns[c];if(!u)throw new Error(`Cannot get '${c}' class from asn1js module`);s=new u}s.valueBlock=n.valueBlock,n=Ze(s.toBER(!1)).result}return o.fromASN(n)}static processComplexSchemaItem(e,t,i){if(t.repeated){if(!Array.isArray(e))throw new Error("Cannot get list of items from the ASN.1 parsed value. ASN.1 value should be iterable.");return Array.from(e,o=>this.fromASN(o,i))}else{const o=this.handleImplicitTagging(e,t,i);if(this.isOptionalChoiceField(t))try{return this.fromASN(o,i)}catch(n){if(n instanceof Nt&&/Wrong values for Choice type/.test(n.message))return;throw n}else{const n=this.fromASN(o,i);return t.raw?{value:n,raw:e.valueBeforeDecodeView}:n}}}static handleImplicitTagging(e,t,i){if(t.implicit&&typeof t.context=="number"){const o=F.get(i);if(o.type===v.Sequence){const n=new ae;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in n.valueBlock)return n.valueBlock.value=e.valueBlock.value,n}else if(o.type===v.Set){const n=new me;if("value"in e.valueBlock&&Array.isArray(e.valueBlock.value)&&"value"in n.valueBlock)return n.valueBlock.value=e.valueBlock.value,n}}return e}}class Ai{static serialize(e){return e instanceof q?e.toBER(!1):this.toASN(e).toBER(!1)}static toASN(e){if(e&&typeof e=="object"&&Be(e))return e.toASN();if(!(e&&typeof e=="object"))throw new TypeError("Parameter 1 should be type of Object.");const t=e.constructor,i=F.get(t);F.cache(t);let o=[];if(i.itemType){if(!Array.isArray(e))throw new TypeError("Parameter 1 should be type of Array.");if(typeof i.itemType=="number"){const s=xt(i.itemType);if(!s)throw new Error(`Cannot get default converter for array item of ${t.name} ASN1 schema`);o=e.map(c=>s.toASN(c))}else o=e.map(s=>this.toAsnItem({type:i.itemType},"[]",t,s))}else for(const s in i.items){const c=i.items[s],u=e[s];if(u===void 0||c.defaultValue===u||typeof c.defaultValue=="object"&&typeof u=="object"&&hc(this.serialize(c.defaultValue),this.serialize(u)))continue;const f=Ai.toAsnItem(c,s,t,u);if(typeof c.context=="number")if(c.implicit)if(!c.repeated&&(typeof c.type=="number"||Be(c.type))){const p={};p.valueHex=f instanceof Le?f.valueBeforeDecodeView:f.valueBlock.toBER(),o.push(new At(T({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context}},p)))}else o.push(new J({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},value:f.valueBlock.value}));else o.push(new J({optional:c.optional,idBlock:{tagClass:3,tagNumber:c.context},value:[f]}));else c.repeated?o=o.concat(f):o.push(f)}let n;switch(i.type){case v.Sequence:n=new ae({value:o});break;case v.Set:n=new me({value:o});break;case v.Choice:if(!o[0])throw new Error(`Schema '${t.name}' has wrong data. Choice cannot be empty.`);n=o[0];break}return n}static toAsnItem(e,t,i,o){let n;if(typeof e.type=="number"){const s=e.converter;if(!s)throw new Error(`Property '${t}' doesn't have converter for type ${h[e.type]} in schema '${i.name}'`);if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");const c=Array.from(o,f=>s.toASN(f)),u=e.repeated==="sequence"?ae:me;n=new u({value:c})}else n=s.toASN(o)}else if(e.repeated){if(!Array.isArray(o))throw new TypeError("Parameter 'objProp' should be type of Array.");const s=Array.from(o,u=>this.toASN(u)),c=e.repeated==="sequence"?ae:me;n=new c({value:s})}else n=this.toASN(o);return n}}class j extends Array{constructor(e=[]){if(typeof e=="number")super(e);else{super();for(const t of e)this.push(t)}}}class ce{static serialize(e){return Ai.serialize(e)}static parse(e,t){return dc.parse(e,t)}static toString(e){const t=N.isBufferSource(e)?N.toArrayBuffer(e):ce.serialize(e),i=Ze(t);if(i.offset===-1)throw new Error(`Cannot decode ASN.1 data. ${i.result.error}`);return i.result.toString()}}function a(r,e,t,i){var o=arguments.length,n=o<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,e,t,i);else for(var c=r.length-1;c>=0;c--)(s=r[c])&&(n=(o<3?s(n):o>3?s(e,t,n):s(e,t))||n);return o>3&&n&&Object.defineProperty(e,t,n),n}typeof SuppressedError=="function"&&SuppressedError;var Si;let as=Si=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Si.prototype)}};as=Si=a([A({type:v.Sequence,itemType:h.ObjectIdentifier})],as);let Bi=class{constructor(e=new Date){this.value=e}};a([l({type:h.GeneralizedTime})],Bi.prototype,"value",void 0),Bi=a([A({type:v.Choice})],Bi);let ki=class{constructor(e=null){this.value=e}};a([l({type:h.Null})],ki.prototype,"value",void 0),ki=a([A({type:v.Choice})],ki);class cs{static isIPv4(e){return/^(\d{1,3}\.){3}\d{1,3}$/.test(e)}static parseIPv4(e){const t=e.split(".");if(t.length!==4)throw new Error("Invalid IPv4 address");return t.map(i=>{const o=parseInt(i,10);if(isNaN(o)||o<0||o>255)throw new Error("Invalid IPv4 address part");return o})}static parseIPv6(e){const i=this.expandIPv6(e).split(":");if(i.length!==8)throw new Error("Invalid IPv6 address");return i.reduce((o,n)=>{const s=parseInt(n,16);if(isNaN(s)||s<0||s>65535)throw new Error("Invalid IPv6 address part");return o.push(s>>8&255),o.push(s&255),o},[])}static expandIPv6(e){if(!e.includes("::"))return e;const t=e.split("::");if(t.length>2)throw new Error("Invalid IPv6 address");const i=t[0]?t[0].split(":"):[],o=t[1]?t[1].split(":"):[],n=8-(i.length+o.length);if(n<0)throw new Error("Invalid IPv6 address");return[...i,...Array(n).fill("0"),...o].join(":")}static formatIPv6(e){const t=[];for(let i=0;i<16;i+=2)t.push((e[i]<<8|e[i+1]).toString(16));return this.compressIPv6(t.join(":"))}static compressIPv6(e){const t=e.split(":");let i=-1,o=0,n=-1,s=0;for(let c=0;c<t.length;c++)t[c]==="0"?(n===-1&&(n=c),s++):(s>o&&(i=n,o=s),n=-1,s=0);if(s>o&&(i=n,o=s),o>1){const c=t.slice(0,i).join(":"),u=t.slice(i+o).join(":");return`${c}::${u}`}return e}static parseCIDR(e){const[t,i]=e.split("/"),o=parseInt(i,10);if(this.isIPv4(t)){if(o<0||o>32)throw new Error("Invalid IPv4 prefix length");return[this.parseIPv4(t),o]}else{if(o<0||o>128)throw new Error("Invalid IPv6 prefix length");return[this.parseIPv6(t),o]}}static decodeIP(e){if(e.length===64&&parseInt(e,16)===0)return"::/0";if(e.length!==16)return e;const t=parseInt(e.slice(8),16).toString(2).split("").reduce((o,n)=>o+ +n,0);let i=e.slice(0,8).replace(/(.{2})/g,o=>`${parseInt(o,16)}.`);return i=i.slice(0,-1),`${i}/${t}`}static toString(e){const t=new Uint8Array(e);if(t.length===4)return Array.from(t).join(".");if(t.length===16)return this.formatIPv6(t);if(t.length===8||t.length===32){const i=t.length/2,o=t.slice(0,i),n=t.slice(i);if(t.every(u=>u===0))return t.length===8?"0.0.0.0/0":"::/0";const c=n.reduce((u,f)=>u+(f.toString(2).match(/1/g)||[]).length,0);return t.length===8?`${Array.from(o).join(".")}/${c}`:`${this.formatIPv6(o)}/${c}`}return this.decodeIP(U.ToHex(e))}static fromString(e){if(e.includes("/")){const[i,o]=this.parseCIDR(e),n=new Uint8Array(i.length);let s=o;for(let u=0;u<n.length;u++)s>=8?(n[u]=255,s-=8):s>0&&(n[u]=255<<8-s,s=0);const c=new Uint8Array(i.length*2);return c.set(i,0),c.set(n,i.length),c.buffer}const t=this.isIPv4(e)?this.parseIPv4(e):this.parseIPv6(e);return new Uint8Array(t).buffer}}var xi,Ni,Ci;let le=class{constructor(e={}){Object.assign(this,e)}toString(){return this.bmpString||this.printableString||this.teletexString||this.universalString||this.utf8String||""}};a([l({type:h.TeletexString})],le.prototype,"teletexString",void 0),a([l({type:h.PrintableString})],le.prototype,"printableString",void 0),a([l({type:h.UniversalString})],le.prototype,"universalString",void 0),a([l({type:h.Utf8String})],le.prototype,"utf8String",void 0),a([l({type:h.BmpString})],le.prototype,"bmpString",void 0),le=a([A({type:v.Choice})],le);let et=class extends le{constructor(e={}){super(e),Object.assign(this,e)}toString(){return this.ia5String||(this.anyValue?U.ToHex(this.anyValue):super.toString())}};a([l({type:h.IA5String})],et.prototype,"ia5String",void 0),a([l({type:h.Any})],et.prototype,"anyValue",void 0),et=a([A({type:v.Choice})],et);class Ei{constructor(e={}){this.type="",this.value=new et,Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Ei.prototype,"type",void 0),a([l({type:et})],Ei.prototype,"value",void 0);let dr=xi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,xi.prototype)}};dr=xi=a([A({type:v.Set,itemType:Ei})],dr);let Ii=Ni=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ni.prototype)}};Ii=Ni=a([A({type:v.Sequence,itemType:dr})],Ii);let Z=Ci=class extends Ii{constructor(e){super(e),Object.setPrototypeOf(this,Ci.prototype)}};Z=Ci=a([A({type:v.Sequence})],Z);const yc={fromASN:r=>cs.toString(bi.fromASN(r)),toASN:r=>bi.toASN(cs.fromString(r))};class Oi{constructor(e={}){this.typeId="",this.value=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Oi.prototype,"typeId",void 0),a([l({type:h.Any,context:0})],Oi.prototype,"value",void 0);class Ti{constructor(e={}){this.partyName=new le,Object.assign(this,e)}}a([l({type:le,optional:!0,context:0,implicit:!0})],Ti.prototype,"nameAssigner",void 0),a([l({type:le,context:1,implicit:!0})],Ti.prototype,"partyName",void 0);let E=class{constructor(e={}){Object.assign(this,e)}};a([l({type:Oi,context:0,implicit:!0})],E.prototype,"otherName",void 0),a([l({type:h.IA5String,context:1,implicit:!0})],E.prototype,"rfc822Name",void 0),a([l({type:h.IA5String,context:2,implicit:!0})],E.prototype,"dNSName",void 0),a([l({type:h.Any,context:3,implicit:!0})],E.prototype,"x400Address",void 0),a([l({type:Z,context:4,implicit:!1})],E.prototype,"directoryName",void 0),a([l({type:Ti,context:5})],E.prototype,"ediPartyName",void 0),a([l({type:h.IA5String,context:6,implicit:!0})],E.prototype,"uniformResourceIdentifier",void 0),a([l({type:h.OctetString,context:7,implicit:!0,converter:yc})],E.prototype,"iPAddress",void 0),a([l({type:h.ObjectIdentifier,context:8,implicit:!0})],E.prototype,"registeredID",void 0),E=a([A({type:v.Choice})],E);var Vi;class yr{constructor(e={}){this.accessMethod="",this.accessLocation=new E,Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],yr.prototype,"accessMethod",void 0),a([l({type:E})],yr.prototype,"accessLocation",void 0);let gr=Vi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Vi.prototype)}};gr=Vi=a([A({type:v.Sequence,itemType:yr})],gr);class ls extends C{}class ji{constructor(e={}){e&&Object.assign(this,e)}}a([l({type:ls,context:0,optional:!0,implicit:!0})],ji.prototype,"keyIdentifier",void 0),a([l({type:E,context:1,optional:!0,implicit:!0,repeated:"sequence"})],ji.prototype,"authorityCertIssuer",void 0),a([l({type:h.Integer,context:2,optional:!0,implicit:!0,converter:re})],ji.prototype,"authorityCertSerialNumber",void 0);class us{constructor(e={}){this.cA=!1,Object.assign(this,e)}}a([l({type:h.Boolean,defaultValue:!1})],us.prototype,"cA",void 0),a([l({type:h.Integer,optional:!0})],us.prototype,"pathLenConstraint",void 0);var Ui;let ue=Ui=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ui.prototype)}};ue=Ui=a([A({type:v.Sequence,itemType:E})],ue);var Di;let fs=Di=class extends ue{constructor(e){super(e),Object.setPrototypeOf(this,Di.prototype)}};fs=Di=a([A({type:v.Sequence})],fs);var Ri;let ke=class{constructor(e={}){Object.assign(this,e)}toString(){return this.ia5String||this.visibleString||this.bmpString||this.utf8String||""}};a([l({type:h.IA5String})],ke.prototype,"ia5String",void 0),a([l({type:h.VisibleString})],ke.prototype,"visibleString",void 0),a([l({type:h.BmpString})],ke.prototype,"bmpString",void 0),a([l({type:h.Utf8String})],ke.prototype,"utf8String",void 0),ke=a([A({type:v.Choice})],ke);class Li{constructor(e={}){this.organization=new ke,this.noticeNumbers=[],Object.assign(this,e)}}a([l({type:ke})],Li.prototype,"organization",void 0),a([l({type:h.Integer,repeated:"sequence"})],Li.prototype,"noticeNumbers",void 0);class Hi{constructor(e={}){Object.assign(this,e)}}a([l({type:Li,optional:!0})],Hi.prototype,"noticeRef",void 0),a([l({type:ke,optional:!0})],Hi.prototype,"explicitText",void 0);let vr=class{constructor(e={}){Object.assign(this,e)}};a([l({type:h.IA5String})],vr.prototype,"cPSuri",void 0),a([l({type:Hi})],vr.prototype,"userNotice",void 0),vr=a([A({type:v.Choice})],vr);class $i{constructor(e={}){this.policyQualifierId="",this.qualifier=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],$i.prototype,"policyQualifierId",void 0),a([l({type:h.Any})],$i.prototype,"qualifier",void 0);class Mi{constructor(e={}){this.policyIdentifier="",Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Mi.prototype,"policyIdentifier",void 0),a([l({type:$i,repeated:"sequence",optional:!0})],Mi.prototype,"policyQualifiers",void 0);let hs=Ri=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ri.prototype)}};hs=Ri=a([A({type:v.Sequence,itemType:Mi})],hs);let mr=class{constructor(e=0){this.value=e}};a([l({type:h.Integer})],mr.prototype,"value",void 0),mr=a([A({type:v.Choice})],mr);let ps=class extends mr{};ps=a([A({type:v.Choice})],ps);var Pi,fe;(function(r){r[r.unused=1]="unused",r[r.keyCompromise=2]="keyCompromise",r[r.cACompromise=4]="cACompromise",r[r.affiliationChanged=8]="affiliationChanged",r[r.superseded=16]="superseded",r[r.cessationOfOperation=32]="cessationOfOperation",r[r.certificateHold=64]="certificateHold",r[r.privilegeWithdrawn=128]="privilegeWithdrawn",r[r.aACompromise=256]="aACompromise"})(fe||(fe={}));class ds extends pr{toJSON(){const e=[],t=this.toNumber();return t&fe.aACompromise&&e.push("aACompromise"),t&fe.affiliationChanged&&e.push("affiliationChanged"),t&fe.cACompromise&&e.push("cACompromise"),t&fe.certificateHold&&e.push("certificateHold"),t&fe.cessationOfOperation&&e.push("cessationOfOperation"),t&fe.keyCompromise&&e.push("keyCompromise"),t&fe.privilegeWithdrawn&&e.push("privilegeWithdrawn"),t&fe.superseded&&e.push("superseded"),t&fe.unused&&e.push("unused"),e}toString(){return`[${this.toJSON().join(", ")}]`}}let tt=class{constructor(e={}){Object.assign(this,e)}};a([l({type:E,context:0,repeated:"sequence",implicit:!0})],tt.prototype,"fullName",void 0),a([l({type:dr,context:1,implicit:!0})],tt.prototype,"nameRelativeToCRLIssuer",void 0),tt=a([A({type:v.Choice})],tt);class Ct{constructor(e={}){Object.assign(this,e)}}a([l({type:tt,context:0,optional:!0})],Ct.prototype,"distributionPoint",void 0),a([l({type:ds,context:1,optional:!0,implicit:!0})],Ct.prototype,"reasons",void 0),a([l({type:E,context:2,optional:!0,repeated:"sequence",implicit:!0})],Ct.prototype,"cRLIssuer",void 0);let _i=Pi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Pi.prototype)}};_i=Pi=a([A({type:v.Sequence,itemType:Ct})],_i);var qi;let ys=qi=class extends _i{constructor(e){super(e),Object.setPrototypeOf(this,qi.prototype)}};ys=qi=a([A({type:v.Sequence,itemType:Ct})],ys);class G{constructor(e={}){this.onlyContainsUserCerts=G.ONLY,this.onlyContainsCACerts=G.ONLY,this.indirectCRL=G.ONLY,this.onlyContainsAttributeCerts=G.ONLY,Object.assign(this,e)}}G.ONLY=!1,a([l({type:tt,context:0,optional:!0})],G.prototype,"distributionPoint",void 0),a([l({type:h.Boolean,context:1,defaultValue:G.ONLY,implicit:!0})],G.prototype,"onlyContainsUserCerts",void 0),a([l({type:h.Boolean,context:2,defaultValue:G.ONLY,implicit:!0})],G.prototype,"onlyContainsCACerts",void 0),a([l({type:ds,context:3,optional:!0,implicit:!0})],G.prototype,"onlySomeReasons",void 0),a([l({type:h.Boolean,context:4,defaultValue:G.ONLY,implicit:!0})],G.prototype,"indirectCRL",void 0),a([l({type:h.Boolean,context:5,defaultValue:G.ONLY,implicit:!0})],G.prototype,"onlyContainsAttributeCerts",void 0);var Et;(function(r){r[r.unspecified=0]="unspecified",r[r.keyCompromise=1]="keyCompromise",r[r.cACompromise=2]="cACompromise",r[r.affiliationChanged=3]="affiliationChanged",r[r.superseded=4]="superseded",r[r.cessationOfOperation=5]="cessationOfOperation",r[r.certificateHold=6]="certificateHold",r[r.removeFromCRL=8]="removeFromCRL",r[r.privilegeWithdrawn=9]="privilegeWithdrawn",r[r.aACompromise=10]="aACompromise"})(Et||(Et={}));let wr=class{constructor(e=Et.unspecified){this.reason=Et.unspecified,this.reason=e}toJSON(){return Et[this.reason]}toString(){return this.toJSON()}};a([l({type:h.Enumerated})],wr.prototype,"reason",void 0),wr=a([A({type:v.Choice})],wr);var Fi;let gs=Fi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Fi.prototype)}};gs=Fi=a([A({type:v.Sequence,itemType:h.ObjectIdentifier})],gs);let Gi=class{constructor(e=new ArrayBuffer(0)){this.value=e}};a([l({type:h.Integer,converter:re})],Gi.prototype,"value",void 0),Gi=a([A({type:v.Choice})],Gi);let zi=class{constructor(e){this.value=new Date,e&&(this.value=e)}};a([l({type:h.GeneralizedTime})],zi.prototype,"value",void 0),zi=a([A({type:v.Choice})],zi);var Xi;let vs=Xi=class extends ue{constructor(e){super(e),Object.setPrototypeOf(this,Xi.prototype)}};vs=Xi=a([A({type:v.Sequence})],vs);var ms;(function(r){r[r.digitalSignature=1]="digitalSignature",r[r.nonRepudiation=2]="nonRepudiation",r[r.keyEncipherment=4]="keyEncipherment",r[r.dataEncipherment=8]="dataEncipherment",r[r.keyAgreement=16]="keyAgreement",r[r.keyCertSign=32]="keyCertSign",r[r.cRLSign=64]="cRLSign",r[r.encipherOnly=128]="encipherOnly",r[r.decipherOnly=256]="decipherOnly"})(ms||(ms={}));var Wi;class br{constructor(e={}){this.base=new E,this.minimum=0,Object.assign(this,e)}}a([l({type:E})],br.prototype,"base",void 0),a([l({type:h.Integer,context:0,defaultValue:0,implicit:!0})],br.prototype,"minimum",void 0),a([l({type:h.Integer,context:1,optional:!0,implicit:!0})],br.prototype,"maximum",void 0);let Ar=Wi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Wi.prototype)}};Ar=Wi=a([A({type:v.Sequence,itemType:br})],Ar);class ws{constructor(e={}){Object.assign(this,e)}}a([l({type:Ar,context:0,optional:!0,implicit:!0})],ws.prototype,"permittedSubtrees",void 0),a([l({type:Ar,context:1,optional:!0,implicit:!0})],ws.prototype,"excludedSubtrees",void 0);class bs{constructor(e={}){Object.assign(this,e)}}a([l({type:h.Integer,context:0,implicit:!0,optional:!0,converter:re})],bs.prototype,"requireExplicitPolicy",void 0),a([l({type:h.Integer,context:1,implicit:!0,optional:!0,converter:re})],bs.prototype,"inhibitPolicyMapping",void 0);var Ji;class Ki{constructor(e={}){this.issuerDomainPolicy="",this.subjectDomainPolicy="",Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Ki.prototype,"issuerDomainPolicy",void 0),a([l({type:h.ObjectIdentifier})],Ki.prototype,"subjectDomainPolicy",void 0);let As=Ji=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ji.prototype)}};As=Ji=a([A({type:v.Sequence,itemType:Ki})],As);var Yi;let Ss=Yi=class extends ue{constructor(e){super(e),Object.setPrototypeOf(this,Yi.prototype)}};Ss=Yi=a([A({type:v.Sequence})],Ss);class It{constructor(e={}){this.type="",this.values=[],Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],It.prototype,"type",void 0),a([l({type:h.Any,repeated:"set"})],It.prototype,"values",void 0);var Zi;let Bs=Zi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Zi.prototype)}};Bs=Zi=a([A({type:v.Sequence,itemType:It})],Bs);class Ot extends ls{}class ks{constructor(e={}){Object.assign(this,e)}}a([l({type:h.GeneralizedTime,context:0,implicit:!0,optional:!0})],ks.prototype,"notBefore",void 0),a([l({type:h.GeneralizedTime,context:1,implicit:!0,optional:!0})],ks.prototype,"notAfter",void 0);var Tt;(function(r){r[r.keyUpdateAllowed=1]="keyUpdateAllowed",r[r.newExtensions=2]="newExtensions",r[r.pKIXCertificate=4]="pKIXCertificate"})(Tt||(Tt={}));class xs extends pr{toJSON(){const e=[],t=this.toNumber();return t&Tt.pKIXCertificate&&e.push("pKIXCertificate"),t&Tt.newExtensions&&e.push("newExtensions"),t&Tt.keyUpdateAllowed&&e.push("keyUpdateAllowed"),e}toString(){return`[${this.toJSON().join(", ")}]`}}class Ns{constructor(e={}){this.entrustVers="",this.entrustInfoFlags=new xs,Object.assign(this,e)}}a([l({type:h.GeneralString})],Ns.prototype,"entrustVers",void 0),a([l({type:xs})],Ns.prototype,"entrustInfoFlags",void 0);var Qi;let Cs=Qi=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Qi.prototype)}};Cs=Qi=a([A({type:v.Sequence,itemType:yr})],Cs);class k{constructor(e={}){this.algorithm="",Object.assign(this,e)}isEqual(e){return e instanceof k&&e.algorithm==this.algorithm&&(e.parameters&&this.parameters&&Ca(e.parameters,this.parameters)||e.parameters===this.parameters)}}a([l({type:h.ObjectIdentifier})],k.prototype,"algorithm",void 0),a([l({type:h.Any,optional:!0})],k.prototype,"parameters",void 0);class Sr{constructor(e={}){this.algorithm=new k,this.subjectPublicKey=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:k})],Sr.prototype,"algorithm",void 0),a([l({type:h.BitString})],Sr.prototype,"subjectPublicKey",void 0);let z=class{constructor(e){if(e)if(typeof e=="string"||typeof e=="number"||e instanceof Date){const t=new Date(e);t.getUTCFullYear()>2049?this.generalTime=t:this.utcTime=t}else Object.assign(this,e)}getTime(){const e=this.utcTime||this.generalTime;if(!e)throw new Error("Cannot get time from CHOICE object");return e}};a([l({type:h.UTCTime})],z.prototype,"utcTime",void 0),a([l({type:h.GeneralizedTime})],z.prototype,"generalTime",void 0),z=a([A({type:v.Choice})],z);class Br{constructor(e){this.notBefore=new z(new Date),this.notAfter=new z(new Date),e&&(this.notBefore=new z(e.notBefore),this.notAfter=new z(e.notAfter))}}a([l({type:z})],Br.prototype,"notBefore",void 0),a([l({type:z})],Br.prototype,"notAfter",void 0);var eo;class Q{constructor(e={}){this.extnID="",this.critical=Q.CRITICAL,this.extnValue=new C,Object.assign(this,e)}}Q.CRITICAL=!1,a([l({type:h.ObjectIdentifier})],Q.prototype,"extnID",void 0),a([l({type:h.Boolean,defaultValue:Q.CRITICAL})],Q.prototype,"critical",void 0),a([l({type:C})],Q.prototype,"extnValue",void 0);let rt=eo=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,eo.prototype)}};rt=eo=a([A({type:v.Sequence,itemType:Q})],rt);var kr;(function(r){r[r.v1=0]="v1",r[r.v2=1]="v2",r[r.v3=2]="v3"})(kr||(kr={}));class ne{constructor(e={}){this.version=kr.v1,this.serialNumber=new ArrayBuffer(0),this.signature=new k,this.issuer=new Z,this.validity=new Br,this.subject=new Z,this.subjectPublicKeyInfo=new Sr,Object.assign(this,e)}}a([l({type:h.Integer,context:0,defaultValue:kr.v1})],ne.prototype,"version",void 0),a([l({type:h.Integer,converter:re})],ne.prototype,"serialNumber",void 0),a([l({type:k})],ne.prototype,"signature",void 0),a([l({type:Z})],ne.prototype,"issuer",void 0),a([l({type:Br})],ne.prototype,"validity",void 0),a([l({type:Z})],ne.prototype,"subject",void 0),a([l({type:Sr})],ne.prototype,"subjectPublicKeyInfo",void 0),a([l({type:h.BitString,context:1,implicit:!0,optional:!0})],ne.prototype,"issuerUniqueID",void 0),a([l({type:h.BitString,context:2,implicit:!0,optional:!0})],ne.prototype,"subjectUniqueID",void 0),a([l({type:rt,context:3,optional:!0})],ne.prototype,"extensions",void 0);class it{constructor(e={}){this.tbsCertificate=new ne,this.signatureAlgorithm=new k,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:ne,raw:!0})],it.prototype,"tbsCertificate",void 0),a([l({type:k})],it.prototype,"signatureAlgorithm",void 0),a([l({type:h.BitString})],it.prototype,"signatureValue",void 0);class xr{constructor(e={}){this.userCertificate=new ArrayBuffer(0),this.revocationDate=new z,Object.assign(this,e)}}a([l({type:h.Integer,converter:re})],xr.prototype,"userCertificate",void 0),a([l({type:z})],xr.prototype,"revocationDate",void 0),a([l({type:Q,optional:!0,repeated:"sequence"})],xr.prototype,"crlEntryExtensions",void 0);class xe{constructor(e={}){this.signature=new k,this.issuer=new Z,this.thisUpdate=new z,Object.assign(this,e)}}a([l({type:h.Integer,optional:!0})],xe.prototype,"version",void 0),a([l({type:k})],xe.prototype,"signature",void 0),a([l({type:Z})],xe.prototype,"issuer",void 0),a([l({type:z})],xe.prototype,"thisUpdate",void 0),a([l({type:z,optional:!0})],xe.prototype,"nextUpdate",void 0),a([l({type:xr,repeated:"sequence",optional:!0})],xe.prototype,"revokedCertificates",void 0),a([l({type:Q,optional:!0,context:0,repeated:"sequence"})],xe.prototype,"crlExtensions",void 0);class to{constructor(e={}){this.tbsCertList=new xe,this.signatureAlgorithm=new k,this.signature=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:xe,raw:!0})],to.prototype,"tbsCertList",void 0),a([l({type:k})],to.prototype,"signatureAlgorithm",void 0),a([l({type:h.BitString})],to.prototype,"signature",void 0);var ro;class io{constructor(e={}){this.sigIdentifier=new k,Object.assign(this,e)}}a([l({type:k})],io.prototype,"sigIdentifier",void 0),a([l({type:k,optional:!0})],io.prototype,"certIdentifier",void 0);let Es=ro=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,ro.prototype)}};Es=ro=a([A({type:v.Sequence,itemType:io})],Es);class Is{constructor(e={}){this.issuer=new Z,this.locator=new gr,Object.assign(this,e)}}a([l({type:Z})],Is.prototype,"issuer",void 0),a([l({type:gr})],Is.prototype,"locator",void 0);class gc extends C{}let ot=class{constructor(e={}){Object.assign(this,e)}};a([l({type:Z,context:1})],ot.prototype,"byName",void 0),a([l({type:gc,context:2})],ot.prototype,"byKey",void 0),ot=a([A({type:v.Choice})],ot);class Ne{constructor(e={}){this.hashAlgorithm=new k,this.issuerNameHash=new C,this.issuerKeyHash=new C,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:k})],Ne.prototype,"hashAlgorithm",void 0),a([l({type:C})],Ne.prototype,"issuerNameHash",void 0),a([l({type:C})],Ne.prototype,"issuerKeyHash",void 0),a([l({type:h.Integer,converter:re})],Ne.prototype,"serialNumber",void 0);class oo{constructor(e={}){this.revocationTime=new Date,Object.assign(this,e)}}a([l({type:h.GeneralizedTime})],oo.prototype,"revocationTime",void 0),a([l({type:wr,context:0,optional:!0})],oo.prototype,"revocationReason",void 0);let Pe=class{constructor(e={}){Object.assign(this,e)}};a([l({type:h.Null,context:0,implicit:!0})],Pe.prototype,"good",void 0),a([l({type:oo,context:1,implicit:!0})],Pe.prototype,"revoked",void 0),a([l({type:h.Null,context:2,implicit:!0})],Pe.prototype,"unknown",void 0),Pe=a([A({type:v.Choice})],Pe);class nt{constructor(e={}){this.certID=new Ne,this.certStatus=new Pe,this.thisUpdate=new Date,Object.assign(this,e)}}a([l({type:Ne})],nt.prototype,"certID",void 0),a([l({type:Pe})],nt.prototype,"certStatus",void 0),a([l({type:h.GeneralizedTime})],nt.prototype,"thisUpdate",void 0),a([l({type:h.GeneralizedTime,context:0,optional:!0})],nt.prototype,"nextUpdate",void 0),a([l({type:Q,context:1,repeated:"sequence",optional:!0})],nt.prototype,"singleExtensions",void 0);var st;(function(r){r[r.v1=0]="v1"})(st||(st={}));class _e{constructor(e={}){this.version=st.v1,this.responderID=new ot,this.producedAt=new Date,this.responses=[],Object.assign(this,e)}}a([l({type:h.Integer,context:0,defaultValue:st.v1})],_e.prototype,"version",void 0),a([l({type:ot})],_e.prototype,"responderID",void 0),a([l({type:h.GeneralizedTime})],_e.prototype,"producedAt",void 0),a([l({type:nt,repeated:"sequence"})],_e.prototype,"responses",void 0),a([l({type:Q,repeated:"sequence",context:1,optional:!0})],_e.prototype,"responseExtensions",void 0);class Vt{constructor(e={}){this.tbsResponseData=new _e,this.signatureAlgorithm=new k,this.signature=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:_e,raw:!0})],Vt.prototype,"tbsResponseData",void 0),a([l({type:k})],Vt.prototype,"signatureAlgorithm",void 0),a([l({type:h.BitString})],Vt.prototype,"signature",void 0),a([l({type:it,repeated:"sequence",optional:!0,context:0})],Vt.prototype,"certs",void 0);class Nr{constructor(e={}){this.signatureAlgorithm=new k,this.signature=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:k})],Nr.prototype,"signatureAlgorithm",void 0),a([l({type:h.BitString})],Nr.prototype,"signature",void 0),a([l({type:it,repeated:"sequence",optional:!0,context:0})],Nr.prototype,"certs",void 0);class Cr{constructor(e={}){this.reqCert=new Ne,Object.assign(this,e)}}a([l({type:Ne})],Cr.prototype,"reqCert",void 0),a([l({type:Q,repeated:"sequence",optional:!0})],Cr.prototype,"singleRequestExtensions",void 0);class qe{constructor(e={}){this.version=st.v1,this.requestList=[],Object.assign(this,e)}}a([l({type:h.Integer,context:0,defaultValue:st.v1})],qe.prototype,"version",void 0),a([l({type:E,context:1,optional:!0})],qe.prototype,"requestorName",void 0),a([l({type:Cr,repeated:"sequence"})],qe.prototype,"requestList",void 0),a([l({type:Q,context:2,optional:!0,repeated:"sequence"})],qe.prototype,"requestExtensions",void 0);class no{constructor(e={}){this.tbsRequest=new qe,Object.assign(this,e)}}a([l({type:qe,raw:!0})],no.prototype,"tbsRequest",void 0),a([l({type:Nr,optional:!0,context:0})],no.prototype,"optionalSignature",void 0);var Ce;(function(r){r[r.successful=0]="successful",r[r.malformedRequest=1]="malformedRequest",r[r.internalError=2]="internalError",r[r.tryLater=3]="tryLater",r[r.sigRequired=5]="sigRequired",r[r.unauthorized=6]="unauthorized"})(Ce||(Ce={}));class so{constructor(e={}){this.responseType="",this.response=new C,Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],so.prototype,"responseType",void 0),a([l({type:C})],so.prototype,"response",void 0);class ao{constructor(e={}){this.responseStatus=Ce.successful,Object.assign(this,e)}}a([l({type:h.Enumerated})],ao.prototype,"responseStatus",void 0),a([l({type:so,context:0,optional:!0})],ao.prototype,"responseBytes",void 0);var Er=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});function co(r){return Er(this,arguments,function*(e,t={}){const{timeout:i=1e4,method:o="GET",body:n,contentType:s,accept:c,proxyUrl:u}=t,f=u?`${u}${encodeURIComponent(e)}`:e,p=new AbortController,d=setTimeout(()=>p.abort(),i);try{const w={};s&&(w["Content-Type"]=s),c&&(w.Accept=c);const y=yield fetch(f,{method:o,headers:w,body:n?new Uint8Array(n):void 0,signal:p.signal});if(clearTimeout(d),!y.ok)return{ok:!1,status:y.status,error:`HTTP ${y.status}: ${y.statusText}`};const g=yield y.arrayBuffer();return{ok:!0,status:y.status,data:g}}catch(w){return clearTimeout(d),w instanceof Error?w.name==="AbortError"?{ok:!1,status:0,error:`Request timeout after ${i}ms`}:{ok:!1,status:0,error:w.message}:{ok:!1,status:0,error:String(w)}}})}function vc(r,e,t=5e3,i){return Er(this,null,function*(){return co(r,{method:"POST",body:e,contentType:"application/ocsp-request",accept:"application/ocsp-response",timeout:t,proxyUrl:i})})}function mc(r,e=1e4,t){return Er(this,null,function*(){return co(r,{method:"GET",accept:"application/pkix-crl",timeout:e,proxyUrl:t})})}function wc(r,e=5e3,t){return Er(this,null,function*(){return co(r,{method:"GET",accept:"application/pkix-cert",timeout:e,proxyUrl:t})})}function Os(r){const e=new Uint8Array(r);if(typeof btoa=="function"){let t="";for(let i=0;i<e.length;i++)t+=String.fromCharCode(e[i]);return btoa(t)}return Buffer.from(e).toString("base64")}function lo(r){if(typeof atob=="function"){const t=atob(r),i=new Uint8Array(t.length);for(let o=0;o<t.length;o++)i[o]=t.charCodeAt(o);return i.buffer}const e=Buffer.from(r,"base64");return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function bc(r){return new Uint8Array(lo(r))}function Ir(r){return Array.from(new Uint8Array(r)).map(e=>e.toString(16).padStart(2,"0")).join("")}function Ac(r){const e=new Uint8Array(r.length/2);for(let t=0;t<r.length;t+=2)e[t/2]=parseInt(r.substring(t,t+2),16);return e.buffer}function Ts(r,e="CERTIFICATE"){const t=Os(r).match(/.{1,64}/g)||[];return`-----BEGIN ${e}-----
|
|
76
|
+
${t.join(`
|
|
77
|
+
`)}
|
|
78
|
+
-----END ${e}-----`}var Or=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});const Vs="1.3.6.1.5.5.7.1.1",Sc="1.3.14.3.2.26";function js(r){return Or(this,null,function*(){if(typeof crypto!="undefined"&&crypto.subtle)return crypto.subtle.digest("SHA-1",r);const e=require("crypto").createHash("sha1");return e.update(Buffer.from(r)),e.digest().buffer})}function Bc(r){try{const e=r.getExtension(Vs);return e?e.ocsp.filter(t=>t.type==="url").map(t=>t.value):[]}catch(e){return[]}}function kc(r){try{const e=r.getExtension(Vs);return e?e.caIssuers.filter(t=>t.type==="url").map(t=>t.value):[]}catch(e){return[]}}function xc(r,e){const t=r.issuer;for(const i of e)try{const o=new V.X509Certificate(i);if(o.subject===t)return o}catch(o){}return null}function Nc(r,e=5e3,t){return Or(this,null,function*(){const i=kc(r);for(const o of i)try{const n=yield wc(o,e,t);if(n.ok&&n.data)try{return new V.X509Certificate(n.data)}catch(s){const c=Ts(n.data);return new V.X509Certificate(c)}}catch(n){}return null})}function Cc(r,e){return Or(this,null,function*(){const t=ce.serialize(e.subjectName.toJSON()),i=yield js(t),o=yield js(e.publicKey.rawData),n=Ac(r.serialNumber),s=new Ne({hashAlgorithm:new k({algorithm:Sc}),issuerNameHash:new C(i),issuerKeyHash:new C(o),serialNumber:n}),c=new Cr({reqCert:s}),u=new qe({requestList:[c]}),f=new no({tbsRequest:u});return ce.serialize(f)})}function Ec(r){const e=new Date;try{const t=ce.parse(r,ao);switch(t.responseStatus){case Ce.successful:break;case Ce.malformedRequest:return{isValid:!1,status:"error",method:"ocsp",reason:"OCSP responder returned: malformed request",checkedAt:e};case Ce.internalError:return{isValid:!1,status:"error",method:"ocsp",reason:"OCSP responder returned: internal error",checkedAt:e};case Ce.tryLater:return{isValid:!1,status:"unknown",method:"ocsp",reason:"OCSP responder returned: try later",checkedAt:e};case Ce.sigRequired:return{isValid:!1,status:"error",method:"ocsp",reason:"OCSP responder requires signature",checkedAt:e};case Ce.unauthorized:return{isValid:!1,status:"error",method:"ocsp",reason:"OCSP responder returned: unauthorized",checkedAt:e};default:return{isValid:!1,status:"error",method:"ocsp",reason:`OCSP responder returned unknown status: ${t.responseStatus}`,checkedAt:e}}if(!t.responseBytes)return{isValid:!1,status:"error",method:"ocsp",reason:"OCSP response has no response bytes",checkedAt:e};const i=ce.parse(t.responseBytes.response.buffer,Vt).tbsResponseData.responses;if(!i||i.length===0)return{isValid:!1,status:"error",method:"ocsp",reason:"OCSP response contains no certificate status",checkedAt:e};const o=i[0].certStatus;return o.good!==void 0?{isValid:!0,status:"good",method:"ocsp",checkedAt:e}:o.revoked?{isValid:!1,status:"revoked",method:"ocsp",reason:o.revoked.revocationReason!==void 0?`Certificate revoked (reason: ${o.revoked.revocationReason})`:"Certificate revoked",revokedAt:o.revoked.revocationTime,checkedAt:e}:o.unknown!==void 0?{isValid:!1,status:"unknown",method:"ocsp",reason:"OCSP responder does not know about this certificate",checkedAt:e}:{isValid:!1,status:"error",method:"ocsp",reason:"Unexpected certificate status in OCSP response",checkedAt:e}}catch(t){return{isValid:!1,status:"error",method:"ocsp",reason:`Failed to parse OCSP response: ${t instanceof Error?t.message:String(t)}`,checkedAt:e}}}function Ic(r,e){return Or(this,arguments,function*(t,i,o={}){const{timeout:n=5e3,certificateChain:s=[],proxyUrl:c}=o,u=new Date,f=Bc(t);if(f.length===0)return{isValid:!1,status:"unknown",method:"ocsp",reason:"Certificate has no OCSP responder URL",checkedAt:u};let p=i;if(p||(p=xc(t,s)),p||(p=yield Nc(t,n,c)),!p)return{isValid:!1,status:"unknown",method:"ocsp",reason:"Could not find or fetch issuer certificate for OCSP",checkedAt:u};let d;try{d=yield Cc(t,p)}catch(w){return{isValid:!1,status:"error",method:"ocsp",reason:`Failed to build OCSP request: ${w instanceof Error?w.message:String(w)}`,checkedAt:u}}for(const w of f)try{const y=yield vc(w,d,n,c);if(y.ok&&y.data)return Ec(y.data)}catch(y){}return{isValid:!1,status:"error",method:"ocsp",reason:"All OCSP requests failed",checkedAt:u}})}var Oc=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});const Tc="2.5.29.31";function Vc(r){try{const e=r.getExtension(Tc);if(!e)return[];const t=[];for(const i of e.distributionPoints)if(i.distributionPoint){const o=i.distributionPoint;if("fullName"in o&&o.fullName)for(const n of o.fullName)n.uniformResourceIdentifier&&t.push(n.uniformResourceIdentifier)}return t}catch(e){return[]}}function jc(r,e){const t=e.toLowerCase().replace(/^0+(?=.)/,"")||"0";for(const i of r.entries)if((i.serialNumber.toLowerCase().replace(/^0+(?=.)/,"")||"0")===t)return{isRevoked:!0,revokedAt:i.revocationDate,reason:i.reason};return{isRevoked:!1}}function Uc(r){try{return new V.X509Crl(r)}catch(e){try{const t=`-----BEGIN X509 CRL-----
|
|
79
|
+
${(Os(r).match(/.{1,64}/g)||[]).join(`
|
|
13
80
|
`)}
|
|
14
|
-
-----END CERTIFICATE-----`}var pe=Object.defineProperty,ye=Object.defineProperties,we=Object.getOwnPropertyDescriptors,Q=Object.getOwnPropertySymbols,Ee=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable,Z=(n,t,e)=>t in n?pe(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,J=(n,t)=>{for(var e in t||(t={}))Ee.call(t,e)&&Z(n,e,t[e]);if(Q)for(var e of Q(t))Ne.call(t,e)&&Z(n,e,t[e]);return n},ee=(n,t)=>ye(n,we(t));function Se(n){return Array.from(n.keys()).filter(t=>t.match(/META-INF\/signatures\d*\.xml$/)||t.match(/META-INF\/.*signatures.*\.xml$/i))}function ve(n,t){const e=new TextDecoder().decode(n),r=U().parseFromString(e,"application/xml"),a=K(r,"ds\\:Signature, Signature");if(a.length===0){if(console.warn(`No Signature elements found in ${t}`),e.includes("XAdESSignatures")){const u=r.documentElement;if(u){const c=A(u,"ds\\:Signature, Signature");if(c){let i=te(c,r);return i.rawXml=e,i}}const o=be(e);if(o)return ee(J({},o),{rawXml:e})}return null}let l=te(a[0],r);return l.rawXml=e,l}function te(n,t){var e,r,a;const l=n.getAttribute("Id")||"unknown",u=A(n,"ds\\:SignedInfo, SignedInfo");if(!u)throw new Error("SignedInfo element not found");const o=A(u,"ds\\:CanonicalizationMethod, CanonicalizationMethod");let c=O.default;o&&(c=o.getAttribute("Algorithm")||c);let i="";i=ue(u);const s=A(u,"ds\\:SignatureMethod, SignatureMethod"),p=(s==null?void 0:s.getAttribute("Algorithm"))||"",g=A(n,"ds\\:SignatureValue, SignatureValue"),f=((e=g==null?void 0:g.textContent)==null?void 0:e.replace(/\s+/g,""))||"",h=A(n,"ds\\:X509Certificate, X509Certificate");let y="",d="",m,C;if(h)y=((a=h.textContent)==null?void 0:a.replace(/\s+/g,""))||"";else{const N=A(n,"ds\\:KeyInfo, KeyInfo");if(N){const x=A(N,"ds\\:X509Data, X509Data");if(x){const P=A(x,"ds\\:X509Certificate, X509Certificate");P&&(y=((r=P.textContent)==null?void 0:r.replace(/\s+/g,""))||"")}}}if(y){d=Y(y);try{const N=new k.X509Certificate(d),x=N.publicKey.algorithm;C=ee(J({algorithm:x.name},"namedCurve"in x?{namedCurve:x.namedCurve}:{}),{rawData:N.publicKey.rawData}),m=W(N)}catch(N){console.error("Failed to extract certificate information:",N)}}const D=A(t,"xades\\:SigningTime, SigningTime"),$=D&&D.textContent?new Date(D.textContent.trim()):new Date,L=[],E={},w={},v=K(u,"ds\\:Reference, Reference");for(const N of v){const x=N.getAttribute("URI")||"",P=N.getAttribute("Type")||"";if(!x||x.startsWith("#")||P.includes("SignedProperties"))continue;let z=x;try{z=decodeURIComponent(x)}catch(_){console.error(`Failed to decode URI: ${x}`,_)}const F=z.startsWith("./")?z.substring(2):z;L.push(F);const se=A(N,"ds\\:DigestMethod, DigestMethod");if(se){const _=se.getAttribute("Algorithm");_&&(w[F]=_)}const j=A(N,"ds\\:DigestValue, DigestValue");j&&j.textContent&&(E[F]=j.textContent.replace(/\s+/g,""))}return{id:l,signingTime:$,certificate:y,certificatePEM:d,publicKey:C,signerInfo:m,signedChecksums:E,digestAlgorithms:w,references:L,algorithm:p,signatureValue:f,signedInfoXml:i,canonicalizationMethod:c}}function be(n){try{const t=n.match(/<ds:Signature[^>]*Id=["']([^"']*)["']/),e=t&&t[1]?t[1]:"unknown",r=n.match(/<ds:SignatureValue[^>]*>([\s\S]*?)<\/ds:SignatureValue>/),a=r&&r[1]?r[1].replace(/\s+/g,""):"",l=n.match(/<ds:X509Certificate>([\s\S]*?)<\/ds:X509Certificate>/),u=l&&l[1]?l[1].replace(/\s+/g,""):"",o=n.match(/<ds:SignatureMethod[^>]*Algorithm=["']([^"']*)["']/),c=o&&o[1]?o[1]:"",i=n.match(/<xades:SigningTime>([\s\S]*?)<\/xades:SigningTime>/),s=i&&i[1]?new Date(i[1].trim()):new Date,p=[],g={},f=/<ds:Reference[^>]*URI=["']([^#][^"']*)["'][^>]*>[\s\S]*?<ds:DigestValue>([\s\S]*?)<\/ds:DigestValue>/g;let h;for(;(h=f.exec(n))!==null;)if(h[1]&&!h[1].startsWith("#")){const d=decodeURIComponent(h[1]);p.push(d),h[2]&&(g[d]=h[2].replace(/\s+/g,""))}const y=Y(u);return{id:e,signingTime:s,certificate:u,certificatePEM:y,signedChecksums:g,references:p,algorithm:c,signatureValue:a}}catch(t){return console.error("Error in fallback text parsing:",t),null}}function Ce(n){try{const t=I.unzipSync(n),e=new Map,r=[],a=[];Object.entries(t).forEach(([i,s])=>{e.set(i,s),i.startsWith("META-INF/")||i==="mimetype"?a.push(i):r.push(i)});const l=[],u=Se(e),o=new Set;for(const i of u){const s=e.get(i);if(s)try{const p=ve(s,i);p&&(l.push(p),p.references&&p.references.length>0&&p.references.forEach(g=>{e.has(g)&&o.add(g)}))}catch(p){console.error(`Error parsing signature ${i}:`,p)}}const c=Array.from(o);return{files:e,documentFileList:r,metadataFileList:a,signedFileList:c,signatures:l}}catch(t){throw new Error(`Failed to parse eDoc container: ${t instanceof Error?t.message:String(t)}`)}}function Te(n){const t=()=>{},e=new Uint8Array(n);if(e[0]!==48)return n;const r=[6,9,42,134,72,134,247,13,1,1,1];let a=-1;for(let h=0;h<=e.length-r.length;h++){let y=!0;for(let d=0;d<r.length;d++)if(e[h+d]!==r[d]){y=!1;break}if(y){a=h;break}}if(a===-1)return n;let l=-1;for(let h=a+r.length;h<e.length;h++)if(e[h]===3){l=h;break}if(l===-1)return n;let u=0;(e[l+1]&128)===0?u=1:u=1+(e[l+1]&127);const o=l+1+u;if(o>=e.length)return n;const c=o+1;if(c>=e.length||e[c]!==48)return n;let i=0;(e[c+1]&128)===0?i=1:i=1+(e[c+1]&127);const s=c+1+i;if(s>=e.length||e[s]!==2)return n;let p=0,g=0;if((e[s+1]&128)===0)g=e[s+1],p=1;else{const h=e[s+1]&127;p=1+h,g=0;for(let y=0;y<h;y++)g=g<<8|e[s+2+y]}const f=s+1+p;if(f>=e.length)return n;if((e[f]&128)!==0){const h=new Uint8Array(e.length+1);if(h.set(e.slice(0,f)),h[f]=0,h.set(e.slice(f),f+1),(e[s+1]&128)===0)h[s+1]=e[s+1]+1;else{const y=e[s+1]&127;let d=0;for(let m=0;m<y;m++)d=d<<8|e[s+2+m];d+=1;for(let m=y-1;m>=0;m--)h[s+2+m]=d&255,d>>=8}if((e[c+1]&128)===0)h[c+1]=e[c+1]+1;else{const y=e[c+1]&127;let d=0;for(let m=0;m<y;m++)d=d<<8|e[c+2+m];d+=1;for(let m=y-1;m>=0;m--)h[c+2+m]=d&255,d>>=8}if((e[l+1]&128)===0)h[l+1]=e[l+1]+1;else{const y=e[l+1]&127;let d=0;for(let m=0;m<y;m++)d=d<<8|e[l+2+m];d+=1;for(let m=y-1;m>=0;m--)h[l+2+m]=d&255,d>>=8}if((e[1]&128)===0)h[1]=e[1]+1;else{const y=e[1]&127;let d=0;for(let m=0;m<y;m++)d=d<<8|e[2+m];d+=1;for(let m=y-1;m>=0;m--)h[2+m]=d&255,d>>=8}return t("Fixed key length: "+h.length),h.buffer}return n}var xe=Object.defineProperty,ne=Object.getOwnPropertySymbols,Ae=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,re=(n,t,e)=>t in n?xe(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,De=(n,t)=>{for(var e in t||(t={}))Ae.call(t,e)&&re(n,e,t[e]);if(ne)for(var e of ne(t))Me.call(t,e)&&re(n,e,t[e]);return n},M=(n,t,e)=>new Promise((r,a)=>{var l=c=>{try{o(e.next(c))}catch(i){a(i)}},u=c=>{try{o(e.throw(c))}catch(i){a(i)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(l,u);o((e=e.apply(n,t)).next())});function X(){return typeof window!="undefined"&&typeof window.crypto!="undefined"&&typeof window.crypto.subtle!="undefined"}function ie(n,t){return M(this,null,function*(){const e=t.replace(/-/g,"").toLowerCase();let r;if(e.includes("sha256"))r="sha256";else if(e.includes("sha1"))r="sha1";else if(e.includes("sha384"))r="sha384";else if(e.includes("sha512"))r="sha512";else throw new Error(`Unsupported digest algorithm: ${t}`);return X()?$e(n,r):Oe(n,r)})}function $e(n,t){return M(this,null,function*(){const e={sha1:"SHA-1",sha256:"SHA-256",sha384:"SHA-384",sha512:"SHA-512"}[t];if(!e)throw new Error(`Unsupported browser digest algorithm: ${t}`);const r=yield window.crypto.subtle.digest(e,n),a=Array.from(new Uint8Array(r));return btoa(String.fromCharCode.apply(null,a))})}function Oe(n,t){return new Promise((e,r)=>{try{const a=require("crypto").createHash(t);a.update(Buffer.from(n)),e(a.digest("base64"))}catch(a){r(new Error(`Node digest computation failed: ${a instanceof Error?a.message:String(a)}`))}})}function Ie(n){const t=n.toLowerCase();return t.includes("sha512")?"SHA-512":t.includes("sha384")?"SHA-384":t.includes("sha256")?"SHA-256":t.includes("sha1")?"SHA-1":"SHA-256"}function oe(n,t){return M(this,null,function*(){const e={};let r=!0,a="SHA-256";n.algorithm&&(n.algorithm.includes("sha1")?a="SHA-1":n.algorithm.includes("sha384")?a="SHA-384":n.algorithm.includes("sha512")&&(a="SHA-512"));const l=Object.entries(n.signedChecksums).map(u=>M(this,[u],function*([o,c]){var i;const s=(i=n.digestAlgorithms)!=null&&i[o]?Ie(n.digestAlgorithms[o]):a,p=t.get(o);if(p){const g=yield ie(p,s),f=c===g;e[o]={expected:c,actual:g,matches:f,fileFound:!0},f||(r=!1)}else{const g=o.includes("/")?o.split("/").pop():o;let f=!1;if(g){for(const[h,y]of t.entries())if(h.endsWith(g)){const d=yield ie(y,s),m=c===d;e[o]={expected:c,actual:d,matches:m,fileFound:!0},m||(r=!1),f=!0;break}}f||(e[o]={expected:c,actual:"",matches:!1,fileFound:!1},r=!1)}}));return yield Promise.all(l),{isValid:r,details:e}})}function Ve(n){return M(this,arguments,function*(t,e=new Date){try{const r=new k.X509Certificate(t),a=me(r,e),l=yield G(t);return{isValid:a.isValid,reason:a.reason,info:l}}catch(r){return{isValid:!1,reason:`Certificate parsing error: ${r instanceof Error?r.message:String(r)}`}}})}function ae(){return X()?window.crypto.subtle:crypto.subtle}function Le(n){if(typeof atob=="function"){const t=atob(n),e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}else{const t=Buffer.from(n,"base64");return new Uint8Array(t)}}function Xe(n,t,e,r,a){return M(this,null,function*(){try{const l=U().parseFromString(n,"application/xml"),u=A(l,"ds:SignedInfo");if(!u)return{isValid:!1,reason:"SignedInfo element not found in provided XML"};const o=a||O.default,c=b.canonicalize(u,o),i=t.replace(/\s+/g,"");let s;try{s=Le(i)}catch(f){return{isValid:!1,reason:`Failed to decode signature value: ${f instanceof Error?f.message:String(f)}`}}let p;try{const f=ae();X()&&r.name==="RSASSA-PKCS1-v1_5"&&(e=Te(e)),p=yield f.importKey("spki",e,r,!1,["verify"])}catch(f){const h=f instanceof Error?f:new Error(String(f));let y="Unknown reason",d="KEY_IMPORT_ERROR";if(h.name==="DataError"?(y="Key data format is invalid or incompatible",d="INVALID_KEY_FORMAT"):h.name==="NotSupportedError"?(y="Algorithm or parameters not supported",d="UNSUPPORTED_ALGORITHM"):h.message.includes("namedCurve")?(y="Missing or invalid namedCurve parameter",d="INVALID_CURVE"):h.message.includes("hash")&&(y="Incompatible or unsupported hash algorithm",d="INVALID_HASH"),r.name==="ECDSA"){const m=e.byteLength;y+=` (Key length: ${m})`}return{isValid:!1,reason:`Failed to import public key: ${y}`,errorDetails:{category:d,originalMessage:h.message,algorithm:De({},r),environment:X()?"browser":"node",keyLength:e.byteLength}}}const g=new TextEncoder().encode(c);try{const f=yield ae().verify(r,p,s,g);return{isValid:f,reason:f?void 0:"Signature verification failed"}}catch(f){return{isValid:!1,reason:`Signature verification error: ${f instanceof Error?f.message:String(f)}`}}}catch(l){return{isValid:!1,reason:`SignedInfo verification error: ${l instanceof Error?l.message:String(l)}`}}})}function Pe(n,t){return M(this,arguments,function*(e,r,a={}){const l=[],u=yield Ve(e.certificatePEM,a.verifyTime||e.signingTime);if(!u.isValid){const i=`Certificate validation error: ${u.reason||"Unknown reason"}`;l.push(i)}const o=a.verifyChecksums!==!1?yield oe(e,r):{isValid:!0,details:{}};if(!o.isValid){const i=Object.entries(o.details).filter(([s,p])=>!p.matches).map(([s])=>s).join(", ");l.push(`Checksum validation failed for files: ${i}`)}let c={isValid:!0};if(a.verifySignatures!==!1&&e.rawXml&&e.signatureValue&&e.publicKey){const i=e.algorithm||"",s={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"};if(i.includes("ecdsa")&&e.publicKey.namedCurve&&(s.namedCurve=e.publicKey.namedCurve,s.name="ECDSA"),i.includes("ecdsa-sha256")?s.hash="SHA-256":i.includes("ecdsa-sha384")?s.hash="SHA-384":i.includes("ecdsa-sha512")?s.hash="SHA-512":i.includes("rsa-sha1")?s.hash="SHA-1":i.includes("rsa-pss")?(s.name="RSA-PSS",s.saltLength=32,i.includes("sha384")?(s.hash="SHA-384",s.saltLength=48):i.includes("sha512")?(s.hash="SHA-512",s.saltLength=64):s.hash="SHA-256"):i.includes("rsa-sha384")?s.hash="SHA-384":i.includes("rsa-sha512")&&(s.hash="SHA-512"),c=yield Xe(e.rawXml,e.signatureValue,e.publicKey.rawData,s,e.canonicalizationMethod),!c.isValid){let p=c.reason||"XML signature verification failed";if(c.errorDetails){const g=c.errorDetails;p+=` [Category: ${g.category}, Environment: ${g.environment}`,g.algorithm&&(p+=`, Algorithm: ${g.algorithm.name}`,g.algorithm.namedCurve&&(p+=`, Curve: ${g.algorithm.namedCurve}`)),g.keyLength&&(p+=`, Key length: ${g.keyLength} bytes`),p+="]"}l.push(p)}}else if(a.verifySignatures!==!1){const i=[];e.rawXml||i.push("Signature XML"),e.signatureValue||i.push("SignatureValue"),e.publicKey||i.push("Public Key"),l.push(`Cannot verify XML signature: missing ${i.join(", ")}`),c={isValid:!1,reason:`Missing required components: ${i.join(", ")}`}}return{isValid:u.isValid&&o.isValid&&c.isValid,certificate:u,checksums:o,signature:a.verifySignatures!==!1?c:void 0,errors:l.length>0?l:void 0}})}T.CANONICALIZATION_METHODS=O,T.XMLCanonicalizer=b,T.formatValidityPeriod=ge,T.getSignerDisplayName=he,T.parseCertificate=G,T.parseEdoc=Ce,T.verifyChecksums=oe,T.verifySignature=Pe,Object.defineProperty(T,"__esModule",{value:!0})});
|
|
81
|
+
-----END X509 CRL-----`;return new V.X509Crl(t)}catch(t){return null}}}function Dc(r){return Oc(this,arguments,function*(e,t={}){const{timeout:i=1e4,proxyUrl:o}=t,n=new Date,s=Vc(e);if(s.length===0)return{isValid:!1,status:"unknown",method:"crl",reason:"Certificate has no CRL distribution point",checkedAt:n};const c=[];for(const u of s)try{const f=yield mc(u,i,o);if(!f.ok||!f.data){c.push(`${u}: ${f.error||"Failed to fetch"}`);continue}const p=Uc(f.data);if(!p){c.push(`${u}: Failed to parse CRL data`);continue}const d=jc(p,e.serialNumber);return d.isRevoked?{isValid:!1,status:"revoked",method:"crl",reason:d.reason!==void 0?`Certificate revoked (reason code: ${d.reason})`:"Certificate revoked",revokedAt:d.revokedAt,checkedAt:n}:{isValid:!0,status:"good",method:"crl",checkedAt:n}}catch(f){c.push(`${u}: ${f instanceof Error?f.message:String(f)}`)}return{isValid:!1,status:"error",method:"crl",reason:`All CRL checks failed: ${c.join("; ")}`,checkedAt:n}})}var Rc=Object.defineProperty,Us=Object.getOwnPropertySymbols,Lc=Object.prototype.hasOwnProperty,Hc=Object.prototype.propertyIsEnumerable,Ds=(r,e,t)=>e in r?Rc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Rs=(r,e)=>{for(var t in e||(e={}))Lc.call(e,t)&&Ds(r,t,e[t]);if(Us)for(var t of Us(e))Hc.call(e,t)&&Ds(r,t,e[t]);return r},$c=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});function uo(r){return $c(this,arguments,function*(e,t={}){const i=new Date,o=Rs(Rs({},Sa),t);let n;try{n=typeof e=="string"?new V.X509Certificate(e):e}catch(f){return{isValid:!1,status:"error",method:"none",reason:`Failed to parse certificate: ${f instanceof Error?f.message:String(f)}`,checkedAt:i}}let s=null,c=null;if(o.ocspEnabled&&(s=yield Ic(n,null,{timeout:o.ocspTimeout,certificateChain:o.certificateChain,proxyUrl:t.proxyUrl}),s.status==="good"||s.status==="revoked"))return s;if(o.crlEnabled&&(c=yield Dc(n,{timeout:o.crlTimeout,proxyUrl:t.proxyUrl}),c.status==="good"||c.status==="revoked"))return c;const u=[];return s!=null&&s.reason&&u.push(`OCSP: ${s.reason}`),c!=null&&c.reason&&u.push(`CRL: ${c.reason}`),{isValid:!1,status:"unknown",method:"none",reason:u.length>0?u.join("; "):"No revocation checking method available",checkedAt:i}})}class at{constructor(e={}){this.issuer=new Z,this.serialNumber=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:Z})],at.prototype,"issuer",void 0),a([l({type:h.Integer,converter:re})],at.prototype,"serialNumber",void 0);let ct=class{constructor(e={}){Object.assign(this,e)}};a([l({type:Ot,context:0,implicit:!0})],ct.prototype,"subjectKeyIdentifier",void 0),a([l({type:at})],ct.prototype,"issuerAndSerialNumber",void 0),ct=a([A({type:v.Choice})],ct);var Ee;(function(r){r[r.v0=0]="v0",r[r.v1=1]="v1",r[r.v2=2]="v2",r[r.v3=3]="v3",r[r.v4=4]="v4",r[r.v5=5]="v5"})(Ee||(Ee={}));let jt=class extends k{};jt=a([A({type:v.Sequence})],jt);let Tr=class extends k{};Tr=a([A({type:v.Sequence})],Tr);let we=class extends k{};we=a([A({type:v.Sequence})],we);let Vr=class extends k{};Vr=a([A({type:v.Sequence})],Vr);let Ls=class extends k{};Ls=a([A({type:v.Sequence})],Ls);let fo=class extends k{};fo=a([A({type:v.Sequence})],fo);class Ut{constructor(e={}){this.attrType="",this.attrValues=[],Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Ut.prototype,"attrType",void 0),a([l({type:h.Any,repeated:"set"})],Ut.prototype,"attrValues",void 0);var ho;class Ie{constructor(e={}){this.version=Ee.v0,this.sid=new ct,this.digestAlgorithm=new jt,this.signatureAlgorithm=new Tr,this.signature=new C,Object.assign(this,e)}}a([l({type:h.Integer})],Ie.prototype,"version",void 0),a([l({type:ct})],Ie.prototype,"sid",void 0),a([l({type:jt})],Ie.prototype,"digestAlgorithm",void 0),a([l({type:Ut,repeated:"set",context:0,implicit:!0,optional:!0,raw:!0})],Ie.prototype,"signedAttrs",void 0),a([l({type:Tr})],Ie.prototype,"signatureAlgorithm",void 0),a([l({type:C})],Ie.prototype,"signature",void 0),a([l({type:Ut,repeated:"set",context:1,implicit:!0,optional:!0})],Ie.prototype,"unsignedAttrs",void 0);let jr=ho=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,ho.prototype)}};jr=ho=a([A({type:v.Set,itemType:Ie})],jr);let Hs=class extends Ie{};Hs=a([A({type:v.Sequence})],Hs);let $s=class extends z{};$s=a([A({type:v.Choice})],$s);class po{constructor(e={}){this.acIssuer=new E,this.acSerial=0,this.attrs=[],Object.assign(this,e)}}a([l({type:E})],po.prototype,"acIssuer",void 0),a([l({type:h.Integer})],po.prototype,"acSerial",void 0),a([l({type:It,repeated:"sequence"})],po.prototype,"attrs",void 0);var yo;let Ur=yo=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,yo.prototype)}};Ur=yo=a([A({type:v.Sequence,itemType:h.ObjectIdentifier})],Ur);class Dr{constructor(e={}){this.permitUnSpecified=!0,Object.assign(this,e)}}a([l({type:h.Integer,optional:!0})],Dr.prototype,"pathLenConstraint",void 0),a([l({type:Ur,implicit:!0,context:0,optional:!0})],Dr.prototype,"permittedAttrs",void 0),a([l({type:Ur,implicit:!0,context:1,optional:!0})],Dr.prototype,"excludedAttrs",void 0),a([l({type:h.Boolean,defaultValue:!0})],Dr.prototype,"permitUnSpecified",void 0);class Fe{constructor(e={}){this.issuer=new ue,this.serial=new ArrayBuffer(0),this.issuerUID=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:ue})],Fe.prototype,"issuer",void 0),a([l({type:h.Integer,converter:re})],Fe.prototype,"serial",void 0),a([l({type:h.BitString,optional:!0})],Fe.prototype,"issuerUID",void 0);var go;(function(r){r[r.publicKey=0]="publicKey",r[r.publicKeyCert=1]="publicKeyCert",r[r.otherObjectTypes=2]="otherObjectTypes"})(go||(go={}));class Ge{constructor(e={}){this.digestedObjectType=go.publicKey,this.digestAlgorithm=new k,this.objectDigest=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.Enumerated})],Ge.prototype,"digestedObjectType",void 0),a([l({type:h.ObjectIdentifier,optional:!0})],Ge.prototype,"otherObjectTypeID",void 0),a([l({type:k})],Ge.prototype,"digestAlgorithm",void 0),a([l({type:h.BitString})],Ge.prototype,"objectDigest",void 0);class Rr{constructor(e={}){Object.assign(this,e)}}a([l({type:ue,optional:!0})],Rr.prototype,"issuerName",void 0),a([l({type:Fe,context:0,implicit:!0,optional:!0})],Rr.prototype,"baseCertificateID",void 0),a([l({type:Ge,context:1,implicit:!0,optional:!0})],Rr.prototype,"objectDigestInfo",void 0);let lt=class{constructor(e={}){Object.assign(this,e)}};a([l({type:E,repeated:"sequence"})],lt.prototype,"v1Form",void 0),a([l({type:Rr,context:0,implicit:!0})],lt.prototype,"v2Form",void 0),lt=a([A({type:v.Choice})],lt);class Lr{constructor(e={}){this.notBeforeTime=new Date,this.notAfterTime=new Date,Object.assign(this,e)}}a([l({type:h.GeneralizedTime})],Lr.prototype,"notBeforeTime",void 0),a([l({type:h.GeneralizedTime})],Lr.prototype,"notAfterTime",void 0);class Dt{constructor(e={}){Object.assign(this,e)}}a([l({type:Fe,implicit:!0,context:0,optional:!0})],Dt.prototype,"baseCertificateID",void 0),a([l({type:ue,implicit:!0,context:1,optional:!0})],Dt.prototype,"entityName",void 0),a([l({type:Ge,implicit:!0,context:2,optional:!0})],Dt.prototype,"objectDigestInfo",void 0);var vo;(function(r){r[r.v2=1]="v2"})(vo||(vo={}));class he{constructor(e={}){this.version=vo.v2,this.holder=new Dt,this.issuer=new lt,this.signature=new k,this.serialNumber=new ArrayBuffer(0),this.attrCertValidityPeriod=new Lr,this.attributes=[],Object.assign(this,e)}}a([l({type:h.Integer})],he.prototype,"version",void 0),a([l({type:Dt})],he.prototype,"holder",void 0),a([l({type:lt})],he.prototype,"issuer",void 0),a([l({type:k})],he.prototype,"signature",void 0),a([l({type:h.Integer,converter:re})],he.prototype,"serialNumber",void 0),a([l({type:Lr})],he.prototype,"attrCertValidityPeriod",void 0),a([l({type:It,repeated:"sequence"})],he.prototype,"attributes",void 0),a([l({type:h.BitString,optional:!0})],he.prototype,"issuerUniqueID",void 0),a([l({type:rt,optional:!0})],he.prototype,"extensions",void 0);class Hr{constructor(e={}){this.acinfo=new he,this.signatureAlgorithm=new k,this.signatureValue=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:he})],Hr.prototype,"acinfo",void 0),a([l({type:k})],Hr.prototype,"signatureAlgorithm",void 0),a([l({type:h.BitString})],Hr.prototype,"signatureValue",void 0);var $r;(function(r){r[r.unmarked=1]="unmarked",r[r.unclassified=2]="unclassified",r[r.restricted=4]="restricted",r[r.confidential=8]="confidential",r[r.secret=16]="secret",r[r.topSecret=32]="topSecret"})($r||($r={}));class mo extends pr{}class wo{constructor(e={}){this.type="",this.value=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier,implicit:!0,context:0})],wo.prototype,"type",void 0),a([l({type:h.Any,implicit:!0,context:1})],wo.prototype,"value",void 0);class bo{constructor(e={}){this.policyId="",this.classList=new mo($r.unclassified),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],bo.prototype,"policyId",void 0),a([l({type:mo,defaultValue:new mo($r.unclassified)})],bo.prototype,"classList",void 0),a([l({type:wo,repeated:"set"})],bo.prototype,"securityCategories",void 0);class Mr{constructor(e={}){Object.assign(this,e)}}a([l({type:C})],Mr.prototype,"cotets",void 0),a([l({type:h.ObjectIdentifier})],Mr.prototype,"oid",void 0),a([l({type:h.Utf8String})],Mr.prototype,"string",void 0);class Ms{constructor(e={}){this.values=[],Object.assign(this,e)}}a([l({type:ue,implicit:!0,context:0,optional:!0})],Ms.prototype,"policyAuthority",void 0),a([l({type:Mr,repeated:"sequence"})],Ms.prototype,"values",void 0);var Ao;class Pr{constructor(e={}){this.targetCertificate=new Fe,Object.assign(this,e)}}a([l({type:Fe})],Pr.prototype,"targetCertificate",void 0),a([l({type:E,optional:!0})],Pr.prototype,"targetName",void 0),a([l({type:Ge,optional:!0})],Pr.prototype,"certDigestInfo",void 0);let ut=class{constructor(e={}){Object.assign(this,e)}};a([l({type:E,context:0,implicit:!0})],ut.prototype,"targetName",void 0),a([l({type:E,context:1,implicit:!0})],ut.prototype,"targetGroup",void 0),a([l({type:Pr,context:2,implicit:!0})],ut.prototype,"targetCert",void 0),ut=a([A({type:v.Choice})],ut);let So=Ao=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ao.prototype)}};So=Ao=a([A({type:v.Sequence,itemType:ut})],So);var Bo;let Ps=Bo=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Bo.prototype)}};Ps=Bo=a([A({type:v.Sequence,itemType:So})],Ps);class _s{constructor(e={}){Object.assign(this,e)}}a([l({type:ue,implicit:!0,context:0,optional:!0})],_s.prototype,"roleAuthority",void 0),a([l({type:E,implicit:!0,context:1})],_s.prototype,"roleName",void 0);class ko{constructor(e={}){this.service=new E,this.ident=new E,Object.assign(this,e)}}a([l({type:E})],ko.prototype,"service",void 0),a([l({type:E})],ko.prototype,"ident",void 0),a([l({type:C,optional:!0})],ko.prototype,"authInfo",void 0);var xo;class No{constructor(e={}){this.otherCertFormat="",this.otherCert=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],No.prototype,"otherCertFormat",void 0),a([l({type:h.Any})],No.prototype,"otherCert",void 0);let ft=class{constructor(e={}){Object.assign(this,e)}};a([l({type:it})],ft.prototype,"certificate",void 0),a([l({type:Hr,context:2,implicit:!0})],ft.prototype,"v2AttrCert",void 0),a([l({type:No,context:3,implicit:!0})],ft.prototype,"other",void 0),ft=a([A({type:v.Choice})],ft);let _r=xo=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,xo.prototype)}};_r=xo=a([A({type:v.Set,itemType:ft})],_r);class qr{constructor(e={}){this.contentType="",this.content=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],qr.prototype,"contentType",void 0),a([l({type:h.Any,context:0})],qr.prototype,"content",void 0);let Rt=class{constructor(e={}){Object.assign(this,e)}};a([l({type:C})],Rt.prototype,"single",void 0),a([l({type:h.Any})],Rt.prototype,"any",void 0),Rt=a([A({type:v.Choice})],Rt);class Fr{constructor(e={}){this.eContentType="",Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Fr.prototype,"eContentType",void 0),a([l({type:Rt,context:0,optional:!0})],Fr.prototype,"eContent",void 0);let Lt=class{constructor(e={}){Object.assign(this,e)}};a([l({type:C,context:0,implicit:!0,optional:!0})],Lt.prototype,"value",void 0),a([l({type:C,converter:Ka,context:0,implicit:!0,optional:!0,repeated:"sequence"})],Lt.prototype,"constructedValue",void 0),Lt=a([A({type:v.Choice})],Lt);class Ht{constructor(e={}){this.contentType="",this.contentEncryptionAlgorithm=new Vr,Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Ht.prototype,"contentType",void 0),a([l({type:Vr})],Ht.prototype,"contentEncryptionAlgorithm",void 0),a([l({type:Lt,optional:!0})],Ht.prototype,"encryptedContent",void 0);class Gr{constructor(e={}){this.keyAttrId="",Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Gr.prototype,"keyAttrId",void 0),a([l({type:h.Any,optional:!0})],Gr.prototype,"keyAttr",void 0);var Co;class zr{constructor(e={}){this.subjectKeyIdentifier=new Ot,Object.assign(this,e)}}a([l({type:Ot})],zr.prototype,"subjectKeyIdentifier",void 0),a([l({type:h.GeneralizedTime,optional:!0})],zr.prototype,"date",void 0),a([l({type:Gr,optional:!0})],zr.prototype,"other",void 0);let ht=class{constructor(e={}){Object.assign(this,e)}};a([l({type:zr,context:0,implicit:!0,optional:!0})],ht.prototype,"rKeyId",void 0),a([l({type:at,optional:!0})],ht.prototype,"issuerAndSerialNumber",void 0),ht=a([A({type:v.Choice})],ht);class Eo{constructor(e={}){this.rid=new ht,this.encryptedKey=new C,Object.assign(this,e)}}a([l({type:ht})],Eo.prototype,"rid",void 0),a([l({type:C})],Eo.prototype,"encryptedKey",void 0);let Xr=Co=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Co.prototype)}};Xr=Co=a([A({type:v.Sequence,itemType:Eo})],Xr);class Io{constructor(e={}){this.algorithm=new k,this.publicKey=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:k})],Io.prototype,"algorithm",void 0),a([l({type:h.BitString})],Io.prototype,"publicKey",void 0);let ze=class{constructor(e={}){Object.assign(this,e)}};a([l({type:Ot,context:0,implicit:!0,optional:!0})],ze.prototype,"subjectKeyIdentifier",void 0),a([l({type:Io,context:1,implicit:!0,optional:!0})],ze.prototype,"originatorKey",void 0),a([l({type:at,optional:!0})],ze.prototype,"issuerAndSerialNumber",void 0),ze=a([A({type:v.Choice})],ze);class pt{constructor(e={}){this.version=Ee.v3,this.originator=new ze,this.keyEncryptionAlgorithm=new we,this.recipientEncryptedKeys=new Xr,Object.assign(this,e)}}a([l({type:h.Integer})],pt.prototype,"version",void 0),a([l({type:ze,context:0})],pt.prototype,"originator",void 0),a([l({type:C,context:1,optional:!0})],pt.prototype,"ukm",void 0),a([l({type:we})],pt.prototype,"keyEncryptionAlgorithm",void 0),a([l({type:Xr})],pt.prototype,"recipientEncryptedKeys",void 0);let dt=class{constructor(e={}){Object.assign(this,e)}};a([l({type:Ot,context:0,implicit:!0})],dt.prototype,"subjectKeyIdentifier",void 0),a([l({type:at})],dt.prototype,"issuerAndSerialNumber",void 0),dt=a([A({type:v.Choice})],dt);class $t{constructor(e={}){this.version=Ee.v0,this.rid=new dt,this.keyEncryptionAlgorithm=new we,this.encryptedKey=new C,Object.assign(this,e)}}a([l({type:h.Integer})],$t.prototype,"version",void 0),a([l({type:dt})],$t.prototype,"rid",void 0),a([l({type:we})],$t.prototype,"keyEncryptionAlgorithm",void 0),a([l({type:C})],$t.prototype,"encryptedKey",void 0);class Mt{constructor(e={}){this.keyIdentifier=new C,Object.assign(this,e)}}a([l({type:C})],Mt.prototype,"keyIdentifier",void 0),a([l({type:h.GeneralizedTime,optional:!0})],Mt.prototype,"date",void 0),a([l({type:Gr,optional:!0})],Mt.prototype,"other",void 0);class Pt{constructor(e={}){this.version=Ee.v4,this.kekid=new Mt,this.keyEncryptionAlgorithm=new we,this.encryptedKey=new C,Object.assign(this,e)}}a([l({type:h.Integer})],Pt.prototype,"version",void 0),a([l({type:Mt})],Pt.prototype,"kekid",void 0),a([l({type:we})],Pt.prototype,"keyEncryptionAlgorithm",void 0),a([l({type:C})],Pt.prototype,"encryptedKey",void 0);class _t{constructor(e={}){this.version=Ee.v0,this.keyEncryptionAlgorithm=new we,this.encryptedKey=new C,Object.assign(this,e)}}a([l({type:h.Integer})],_t.prototype,"version",void 0),a([l({type:fo,context:0,optional:!0})],_t.prototype,"keyDerivationAlgorithm",void 0),a([l({type:we})],_t.prototype,"keyEncryptionAlgorithm",void 0),a([l({type:C})],_t.prototype,"encryptedKey",void 0);class Oo{constructor(e={}){this.oriType="",this.oriValue=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Oo.prototype,"oriType",void 0),a([l({type:h.Any})],Oo.prototype,"oriValue",void 0);let Ve=class{constructor(e={}){Object.assign(this,e)}};a([l({type:$t,optional:!0})],Ve.prototype,"ktri",void 0),a([l({type:pt,context:1,implicit:!0,optional:!0})],Ve.prototype,"kari",void 0),a([l({type:Pt,context:2,implicit:!0,optional:!0})],Ve.prototype,"kekri",void 0),a([l({type:_t,context:3,implicit:!0,optional:!0})],Ve.prototype,"pwri",void 0),a([l({type:Oo,context:4,implicit:!0,optional:!0})],Ve.prototype,"ori",void 0),Ve=a([A({type:v.Choice})],Ve);var To;let Wr=To=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,To.prototype)}};Wr=To=a([A({type:v.Set,itemType:Ve})],Wr);var Vo;class Jr{constructor(e={}){this.otherRevInfoFormat="",this.otherRevInfo=new ArrayBuffer(0),Object.assign(this,e)}}a([l({type:h.ObjectIdentifier})],Jr.prototype,"otherRevInfoFormat",void 0),a([l({type:h.Any})],Jr.prototype,"otherRevInfo",void 0);let Kr=class{constructor(e={}){this.other=new Jr,Object.assign(this,e)}};a([l({type:Jr,context:1,implicit:!0})],Kr.prototype,"other",void 0),Kr=a([A({type:v.Choice})],Kr);let Yr=Vo=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Vo.prototype)}};Yr=Vo=a([A({type:v.Set,itemType:Kr})],Yr);class jo{constructor(e={}){Object.assign(this,e)}}a([l({type:_r,context:0,implicit:!0,optional:!0})],jo.prototype,"certs",void 0),a([l({type:Yr,context:1,implicit:!0,optional:!0})],jo.prototype,"crls",void 0);var Uo;let Do=Uo=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Uo.prototype)}};Do=Uo=a([A({type:v.Set,itemType:Ut})],Do);class qt{constructor(e={}){this.version=Ee.v0,this.recipientInfos=new Wr,this.encryptedContentInfo=new Ht,Object.assign(this,e)}}a([l({type:h.Integer})],qt.prototype,"version",void 0),a([l({type:jo,context:0,implicit:!0,optional:!0})],qt.prototype,"originatorInfo",void 0),a([l({type:Wr})],qt.prototype,"recipientInfos",void 0),a([l({type:Ht})],qt.prototype,"encryptedContentInfo",void 0),a([l({type:Do,context:1,implicit:!0,optional:!0})],qt.prototype,"unprotectedAttrs",void 0);var Ro;let Zr=Ro=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ro.prototype)}};Zr=Ro=a([A({type:v.Set,itemType:jt})],Zr);class Xe{constructor(e={}){this.version=Ee.v0,this.digestAlgorithms=new Zr,this.encapContentInfo=new Fr,this.signerInfos=new jr,Object.assign(this,e)}}a([l({type:h.Integer})],Xe.prototype,"version",void 0),a([l({type:Zr})],Xe.prototype,"digestAlgorithms",void 0),a([l({type:Fr})],Xe.prototype,"encapContentInfo",void 0),a([l({type:_r,context:0,implicit:!0,optional:!0})],Xe.prototype,"certificates",void 0),a([l({type:Yr,context:1,implicit:!0,optional:!0})],Xe.prototype,"crls",void 0),a([l({type:jr})],Xe.prototype,"signerInfos",void 0);class Qr{constructor(e={}){this.seconds=0,Object.assign(this,e)}}a([l({type:h.Integer,optional:!0})],Qr.prototype,"seconds",void 0),a([l({type:h.Integer,context:0,implicit:!0,optional:!0})],Qr.prototype,"millis",void 0),a([l({type:h.Integer,context:1,implicit:!0,optional:!0})],Qr.prototype,"micros",void 0);class yt{constructor(e={}){this.hashAlgorithm=new k,this.hashedMessage=new C,Object.assign(this,e)}}a([l({type:k})],yt.prototype,"hashAlgorithm",void 0),a([l({type:C})],yt.prototype,"hashedMessage",void 0);var pe;(function(r){r[r.badAlg=1]="badAlg",r[r.badRequest=2]="badRequest",r[r.badDataFormat=16]="badDataFormat",r[r.timeNotAvailable=8192]="timeNotAvailable",r[r.unacceptedPolicy=16384]="unacceptedPolicy",r[r.unacceptedExtension=32768]="unacceptedExtension",r[r.addInfoNotAvailable=65536]="addInfoNotAvailable",r[r.systemFailure=16777216]="systemFailure"})(pe||(pe={}));class Mc extends pr{toJSON(){const e=this.toNumber(),t=[];return e&pe.addInfoNotAvailable&&t.push("addInfoNotAvailable"),e&pe.badAlg&&t.push("badAlg"),e&pe.badDataFormat&&t.push("badDataFormat"),e&pe.badRequest&&t.push("badRequest"),e&pe.systemFailure&&t.push("systemFailure"),e&pe.systemFailure&&t.push("systemFailure"),e&pe.timeNotAvailable&&t.push("timeNotAvailable"),e&pe.unacceptedExtension&&t.push("unacceptedExtension"),e&pe.unacceptedPolicy&&t.push("unacceptedPolicy"),t}toString(){return`[${this.toJSON().join(", ")}]`}}var Lo;(function(r){r[r.granted=0]="granted",r[r.grantedWithMods=1]="grantedWithMods",r[r.rejection=2]="rejection",r[r.waiting=3]="waiting",r[r.revocationWarning=4]="revocationWarning",r[r.revocationNotification=5]="revocationNotification"})(Lo||(Lo={}));var Ho;let $o=Ho=class extends j{constructor(e){super(e),Object.setPrototypeOf(this,Ho.prototype)}};$o=Ho=a([A({type:v.Sequence,itemType:h.Utf8String})],$o);class Ft{constructor(e={}){this.status=Lo.granted,Object.assign(this,e)}}a([l({type:h.Integer})],Ft.prototype,"status",void 0),a([l({type:$o,optional:!0})],Ft.prototype,"statusString",void 0),a([l({type:Mc,optional:!0})],Ft.prototype,"failInfo",void 0);var Mo;(function(r){r[r.v1=1]="v1"})(Mo||(Mo={}));class gt{constructor(e={}){this.version=Mo.v1,this.messageImprint=new yt,this.certReq=!1,Object.assign(this,e)}}a([l({type:h.Integer})],gt.prototype,"version",void 0),a([l({type:yt})],gt.prototype,"messageImprint",void 0),a([l({type:h.ObjectIdentifier,optional:!0})],gt.prototype,"reqPolicy",void 0),a([l({type:h.Integer,converter:re,optional:!0})],gt.prototype,"nonce",void 0),a([l({type:h.Boolean,defaultValue:!1})],gt.prototype,"certReq",void 0),a([l({type:rt,optional:!0,context:0,implicit:!0})],gt.prototype,"extensions",void 0);let Po=class extends qr{};Po=a([A({type:v.Sequence})],Po);class qs{constructor(e={}){this.status=new Ft,Object.assign(this,e)}}a([l({type:Ft})],qs.prototype,"status",void 0),a([l({type:Po,optional:!0})],qs.prototype,"timeStampToken",void 0);var _o;(function(r){r[r.v1=1]="v1"})(_o||(_o={}));class de{constructor(e={}){this.version=_o.v1,this.policy="",this.messageImprint=new yt,this.serialNumber=new ArrayBuffer(0),this.genTime=new Date,this.ordering=!1,Object.assign(this,e)}}a([l({type:h.Integer})],de.prototype,"version",void 0),a([l({type:h.ObjectIdentifier})],de.prototype,"policy",void 0),a([l({type:yt})],de.prototype,"messageImprint",void 0),a([l({type:h.Integer,converter:re})],de.prototype,"serialNumber",void 0),a([l({type:h.GeneralizedTime})],de.prototype,"genTime",void 0),a([l({type:Qr,optional:!0})],de.prototype,"accuracy",void 0),a([l({type:h.Boolean,defaultValue:!1})],de.prototype,"ordering",void 0),a([l({type:h.Integer,converter:re,optional:!0})],de.prototype,"nonce",void 0),a([l({type:E,context:0,optional:!0})],de.prototype,"tsa",void 0),a([l({type:rt,context:1,implicit:!0,optional:!0})],de.prototype,"extensions",void 0);var qo=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});const Pc="1.2.840.113549.1.7.2",_c="1.2.840.113549.1.9.16.1.4";function qc(r){return{"1.3.14.3.2.26":"SHA-1","2.16.840.1.101.3.4.2.1":"SHA-256","2.16.840.1.101.3.4.2.2":"SHA-384","2.16.840.1.101.3.4.2.3":"SHA-512"}[r]||r}function Fo(r){try{const e=lo(r),t=ce.parse(e,qr);if(t.contentType!==Pc)return console.warn("Timestamp is not SignedData"),null;const i=ce.parse(t.content,Xe);if(i.encapContentInfo.eContentType!==_c)return console.warn("SignedData does not contain TSTInfo"),null;if(!i.encapContentInfo.eContent)return console.warn("No eContent in SignedData"),null;const o=i.encapContentInfo.eContent;let n;o.single?n=o.single.buffer:o.any?n=o.any:n=ce.serialize(o);const s=ce.parse(n,de);let c;if(i.certificates&&i.certificates.length>0){const p=i.certificates[0];"certificate"in p&&p.certificate&&(c=Ts(ce.serialize(p.certificate)))}let u;s.tsa&&(s.tsa.directoryName?u=s.tsa.directoryName.toString():s.tsa.uniformResourceIdentifier&&(u=s.tsa.uniformResourceIdentifier));let f;return s.accuracy&&(f=(s.accuracy.seconds||0)+(s.accuracy.millis||0)/1e3+(s.accuracy.micros||0)/1e6),{genTime:s.genTime,policy:s.policy,serialNumber:Ir(s.serialNumber),hashAlgorithm:qc(s.messageImprint.hashAlgorithm.algorithm),messageImprint:Ir(s.messageImprint.hashedMessage.buffer),tsaName:u,tsaCertificate:c,accuracy:f}}catch(e){return console.error("Failed to parse timestamp:",e instanceof Error?e.message:String(e)),null}}function Fs(r,e){return qo(this,null,function*(){const t={"SHA-1":"SHA-1","SHA-256":"SHA-256","SHA-384":"SHA-384","SHA-512":"SHA-512"}[e];if(!t)throw new Error(`Unsupported hash algorithm: ${e}`);if(typeof crypto!="undefined"&&crypto.subtle)return crypto.subtle.digest(t,r);const i=require("crypto").createHash(e.toLowerCase().replace("-",""));return i.update(Buffer.from(r)),i.digest().buffer})}function Fc(r,e){return qo(this,null,function*(){try{const t=r.messageImprint.toLowerCase(),i=lo(e),o=yield Fs(i,r.hashAlgorithm);if(Ir(o).toLowerCase()===t)return!0;const n=new TextEncoder().encode(e),s=yield Fs(n.buffer,r.hashAlgorithm);return Ir(s).toLowerCase()===t}catch(t){return console.error("Failed to verify timestamp coverage:",t instanceof Error?t.message:String(t)),!1}})}function Gs(r){return qo(this,arguments,function*(e,t={}){const i=Fo(e);if(!i)return{isValid:!1,reason:"Failed to parse timestamp token"};let o,n;t.signatureValue&&(o=yield Fc(i,t.signatureValue),o||(n="Could not verify timestamp covers signature (implementation-specific hashing)"));let s;if(t.verifyTsaCertificate&&i.tsaCertificate)try{const c=new V.X509Certificate(i.tsaCertificate);if(i.genTime<c.notBefore||i.genTime>c.notAfter)return{isValid:!1,info:i,coversSignature:o,reason:`TSA certificate was not valid at timestamp time (${i.genTime.toISOString()})`};if(t.checkTsaRevocation!==!1)try{if(s=yield uo(c),s.status==="revoked")return{isValid:!1,info:i,coversSignature:o,tsaRevocation:s,reason:`TSA certificate has been revoked: ${s.reason||"No reason provided"}`}}catch(u){s={isValid:!1,status:"error",method:"none",reason:`TSA revocation check failed: ${u instanceof Error?u.message:String(u)}`,checkedAt:new Date}}}catch(c){return{isValid:!1,info:i,coversSignature:o,reason:`Failed to verify TSA certificate: ${c instanceof Error?c.message:String(c)}`}}return{isValid:!0,info:i,coversSignature:o,tsaRevocation:s,reason:n}})}function Gc(r){const e=Fo(r);return(e==null?void 0:e.genTime)||null}var zc=Object.defineProperty,zs=Object.getOwnPropertySymbols,Xc=Object.prototype.hasOwnProperty,Wc=Object.prototype.propertyIsEnumerable,Xs=(r,e,t)=>e in r?zc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ws=(r,e)=>{for(var t in e||(e={}))Xc.call(e,t)&&Xs(r,t,e[t]);if(zs)for(var t of zs(e))Wc.call(e,t)&&Xs(r,t,e[t]);return r},We=(r,e,t)=>new Promise((i,o)=>{var n=u=>{try{c(t.next(u))}catch(f){o(f)}},s=u=>{try{c(t.throw(u))}catch(f){o(f)}},c=u=>u.done?i(u.value):Promise.resolve(u.value).then(n,s);c((t=t.apply(r,e)).next())});function ei(){return typeof window!="undefined"&&typeof window.crypto!="undefined"&&typeof window.crypto.subtle!="undefined"}function Js(r,e){return We(this,null,function*(){const t=e.replace(/-/g,"").toLowerCase();let i;if(t.includes("sha256"))i="sha256";else if(t.includes("sha1"))i="sha1";else if(t.includes("sha384"))i="sha384";else if(t.includes("sha512"))i="sha512";else throw new Error(`Unsupported digest algorithm: ${e}`);return ei()?Jc(r,i):Kc(r,i)})}function Jc(r,e){return We(this,null,function*(){const t={sha1:"SHA-1",sha256:"SHA-256",sha384:"SHA-384",sha512:"SHA-512"}[e];if(!t)throw new Error(`Unsupported browser digest algorithm: ${e}`);const i=yield window.crypto.subtle.digest(t,r),o=Array.from(new Uint8Array(i));return btoa(String.fromCharCode.apply(null,o))})}function Kc(r,e){return new Promise((t,i)=>{try{const o=require("crypto").createHash(e);o.update(Buffer.from(r)),t(o.digest("base64"))}catch(o){i(new Error(`Node digest computation failed: ${o instanceof Error?o.message:String(o)}`))}})}function Yc(r){const e=r.toLowerCase();return e.includes("sha512")?"SHA-512":e.includes("sha384")?"SHA-384":e.includes("sha256")?"SHA-256":e.includes("sha1")?"SHA-1":"SHA-256"}function Ks(r,e){return We(this,null,function*(){const t={};let i=!0,o="SHA-256";r.algorithm&&(r.algorithm.includes("sha1")?o="SHA-1":r.algorithm.includes("sha384")?o="SHA-384":r.algorithm.includes("sha512")&&(o="SHA-512"));const n=Object.entries(r.signedChecksums).map(s=>We(this,[s],function*([c,u]){var f;const p=(f=r.digestAlgorithms)!=null&&f[c]?Yc(r.digestAlgorithms[c]):o,d=e.get(c);if(d){const w=yield Js(d,p),y=u===w;t[c]={expected:u,actual:w,matches:y,fileFound:!0},y||(i=!1)}else{const w=c.includes("/")?c.split("/").pop():c;let y=!1;if(w){for(const[g,B]of e.entries())if(g.endsWith(w)){const m=yield Js(B,p),S=u===m;t[c]={expected:u,actual:m,matches:S,fileFound:!0},S||(i=!1),y=!0;break}}y||(t[c]={expected:u,actual:"",matches:!1,fileFound:!1},i=!1)}}));return yield Promise.all(n),{isValid:i,details:t}})}function Zc(r){return We(this,arguments,function*(e,t=new Date){try{const i=new V.X509Certificate(e),o=la(i,t),n=yield Qo(e);return{isValid:o.isValid,reason:o.reason,info:n}}catch(i){return{isValid:!1,reason:`Certificate parsing error: ${i instanceof Error?i.message:String(i)}`}}})}function Ys(){return ei()?window.crypto.subtle:crypto.subtle}function Qc(r,e,t,i,o){return We(this,null,function*(){try{const n=Jo().parseFromString(r,"application/xml"),s=K(n,"ds:SignedInfo");if(!s)return{isValid:!1,reason:"SignedInfo element not found in provided XML"};const c=o||Je.default,u=P.canonicalize(s,c),f=e.replace(/\s+/g,"");let p;try{p=bc(f)}catch(y){return{isValid:!1,reason:`Failed to decode signature value: ${y instanceof Error?y.message:String(y)}`}}let d;try{const y=Ys();ei()&&i.name==="RSASSA-PKCS1-v1_5"&&(t=Aa(t)),d=yield y.importKey("spki",t,i,!1,["verify"])}catch(y){const g=y instanceof Error?y:new Error(String(y));let B="Unknown reason",m="KEY_IMPORT_ERROR";if(g.name==="DataError"?(B="Key data format is invalid or incompatible",m="INVALID_KEY_FORMAT"):g.name==="NotSupportedError"?(B="Algorithm or parameters not supported",m="UNSUPPORTED_ALGORITHM"):g.message.includes("namedCurve")?(B="Missing or invalid namedCurve parameter",m="INVALID_CURVE"):g.message.includes("hash")&&(B="Incompatible or unsupported hash algorithm",m="INVALID_HASH"),i.name==="ECDSA"){const S=t.byteLength;B+=` (Key length: ${S})`}return{isValid:!1,reason:`Failed to import public key: ${B}`,errorDetails:{category:m,originalMessage:g.message,algorithm:Ws({},i),environment:ei()?"browser":"node",keyLength:t.byteLength}}}const w=new TextEncoder().encode(u);try{const y=yield Ys().verify(i,d,p,w);return{isValid:y,reason:y?void 0:"Signature verification failed"}}catch(y){return{isValid:!1,reason:`Signature verification error: ${y instanceof Error?y.message:String(y)}`}}}catch(n){return{isValid:!1,reason:`SignedInfo verification error: ${n instanceof Error?n.message:String(n)}`}}})}function el(r,e){return We(this,arguments,function*(t,i,o={}){var n;const s=[];let c,u=o.verifyTime||t.signingTime;t.signatureTimestamp&&o.verifyTimestamps!==!1&&(c=yield Gs(t.signatureTimestamp,{signatureValue:t.signatureValue,verifyTsaCertificate:!0}),c.isValid&&c.info?u=c.info.genTime:c.isValid||s.push(`Timestamp verification failed: ${c.reason||"Unknown reason"}`));const f=yield Zc(t.certificatePEM,u);if(!f.isValid){const y=`Certificate validation error: ${f.reason||"Unknown reason"}`;s.push(y)}if(o.checkRevocation!==!1&&f.isValid)try{const y=yield uo(t.certificatePEM,Ws({certificateChain:t.certificateChain},o.revocationOptions));f.revocation=y,y.status==="revoked"&&(f.isValid=!1,f.reason=y.reason||"Certificate has been revoked",s.push(`Certificate revoked: ${y.reason||"No reason provided"}`))}catch(y){f.revocation={isValid:!1,status:"error",method:"none",reason:`Revocation check failed: ${y instanceof Error?y.message:String(y)}`,checkedAt:new Date}}const p=o.verifyChecksums!==!1?yield Ks(t,i):{isValid:!0,details:{}};if(!p.isValid){const y=Object.entries(p.details).filter(([g,B])=>!B.matches).map(([g])=>g).join(", ");s.push(`Checksum validation failed for files: ${y}`)}let d={isValid:!0};if(o.verifySignatures!==!1&&t.rawXml&&t.signatureValue&&t.publicKey){const y=t.algorithm||"",g={name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"};if(y.includes("ecdsa")&&t.publicKey.namedCurve&&(g.namedCurve=t.publicKey.namedCurve,g.name="ECDSA"),y.includes("ecdsa-sha256")?g.hash="SHA-256":y.includes("ecdsa-sha384")?g.hash="SHA-384":y.includes("ecdsa-sha512")?g.hash="SHA-512":y.includes("rsa-sha1")?g.hash="SHA-1":y.includes("rsa-pss")?(g.name="RSA-PSS",g.saltLength=32,y.includes("sha384")?(g.hash="SHA-384",g.saltLength=48):y.includes("sha512")?(g.hash="SHA-512",g.saltLength=64):g.hash="SHA-256"):y.includes("rsa-sha384")?g.hash="SHA-384":y.includes("rsa-sha512")&&(g.hash="SHA-512"),d=yield Qc(t.rawXml,t.signatureValue,t.publicKey.rawData,g,t.canonicalizationMethod),!d.isValid){let B=d.reason||"XML signature verification failed";if(d.errorDetails){const m=d.errorDetails;B+=` [Category: ${m.category}, Environment: ${m.environment}`,m.algorithm&&(B+=`, Algorithm: ${m.algorithm.name}`,m.algorithm.namedCurve&&(B+=`, Curve: ${m.algorithm.namedCurve}`)),m.keyLength&&(B+=`, Key length: ${m.keyLength} bytes`),B+="]"}s.push(B)}}else if(o.verifySignatures!==!1){const y=[];t.rawXml||y.push("Signature XML"),t.signatureValue||y.push("SignatureValue"),t.publicKey||y.push("Public Key"),s.push(`Cannot verify XML signature: missing ${y.join(", ")}`),d={isValid:!1,reason:`Missing required components: ${y.join(", ")}`}}const w=!t.signatureTimestamp||o.verifyTimestamps===!1||((n=c==null?void 0:c.isValid)!=null?n:!0);return{isValid:f.isValid&&p.isValid&&d.isValid&&w,certificate:f,checksums:p,signature:o.verifySignatures!==!1?d:void 0,timestamp:c,errors:s.length>0?s:void 0}})}x.CANONICALIZATION_METHODS=Je,x.XMLCanonicalizer=P,x.checkCertificateRevocation=uo,x.formatValidityPeriod=fa,x.getSignerDisplayName=ua,x.getTimestampTime=Gc,x.parseCertificate=Qo,x.parseEdoc=ba,x.parseTimestamp=Fo,x.verifyChecksums=Ks,x.verifySignature=el,x.verifyTimestamp=Gs,Object.defineProperty(x,"__esModule",{value:!0})});
|
|
15
82
|
//# sourceMappingURL=index.umd.js.map
|