UNPKG

edockit

Version:

A JavaScript library for listing, parsing, and verifying the contents and signatures of electronic documents (eDoc) and Associated Signature Containers (ASiC-E), supporting EU eIDAS standards for digital signatures and electronic seals.

72 lines 170 kB
var Sl=Object.defineProperty,Bl=Object.defineProperties;var kl=Object.getOwnPropertyDescriptors;var ri=Object.getOwnPropertySymbols;var sa=Object.prototype.hasOwnProperty,aa=Object.prototype.propertyIsEnumerable;var oa=(E,$,D)=>$ in E?Sl(E,$,{enumerable:!0,configurable:!0,writable:!0,value:D}):E[$]=D,j=(E,$)=>{for(var D in $||($={}))sa.call($,D)&&oa(E,D,$[D]);if(ri)for(var D of ri($))aa.call($,D)&&oa(E,D,$[D]);return E},P=(E,$)=>Bl(E,kl($));var H=(E,$)=>{var D={};for(var se in E)sa.call(E,se)&&$.indexOf(se)<0&&(D[se]=E[se]);if(E!=null&&ri)for(var se of ri(E))$.indexOf(se)<0&&aa.call(E,se)&&(D[se]=E[se]);return D};/*! * MIT License * Copyright (c) 2025 Edgars Jēkabsons, ZenomyTech SIA */(function(E,$){typeof exports=="object"&&typeof module!="undefined"?$(exports,require("fflate"),require("@peculiar/x509")):typeof define=="function"&&define.amd?define(["exports","fflate","@peculiar/x509"],$):(E=typeof globalThis!="undefined"?globalThis:E||self,$(E.edockit={},E.fflate,E.peculiarX509))})(this,function(E,$,D){"use strict";function se(r,e){const t=[],i=e.split(",").map(s=>s.trim()),n=[];for(const s of i){const c=s.split(/\\:|:/).filter(Boolean);c.length===1?n.push({name:c[0]}):c.length===2&&n.push({ns:c[0],name:c[1]})}function o(s){if(s){if(s.nodeType===1){const c=s,l=c.nodeName,f=c.localName;for(const h of n){if(h.ns&&l===`${h.ns}:${h.name}`){t.push(c);break}if(f===h.name||l===h.name){t.push(c);break}if(l.endsWith(`:${h.name}`)){t.push(c);break}}}if(s.childNodes)for(let c=0;c<s.childNodes.length;c++)o(s.childNodes[c])}}return o(r),t}const Kn={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 Jn(){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 ca(r,e,t=Kn){try{if(typeof document!="undefined"&&typeof document.evaluate=="function"){const i="ownerDocument"in r?r.ownerDocument:r;if(!i||typeof i.evaluate!="function")return null;const n=Yn(t);return i.evaluate(e,r,n,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue}else{const i=require("xpath"),n=t;try{const o=i.select(e,r,n);return o.length>0?o[0]:null}catch(o){if(typeof o=="object"&&o!==null&&"message"in o&&typeof o.message=="string"&&o.message.includes("Cannot resolve QName")){const s=e.match(/local-name\(\)='([^']+)'/);if(s&&s[1]){const c=`.//*[local-name()='${s[1]}']`,l=i.select(c,r);return l.length>0?l[0]:null}}throw o}}}catch(i){return console.error(`XPath evaluation failed for "${e}":`,i),null}}function la(r,e,t=Kn){try{if(typeof document!="undefined"&&typeof document.evaluate=="function"){const i="ownerDocument"in r?r.ownerDocument:r;if(!i||typeof i.evaluate!="function")return[];const n=Yn(t),o=i.evaluate(e,r,n,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),s=[];for(let c=0;c<o.snapshotLength;c++)s.push(o.snapshotItem(c));return s}else{const i=require("xpath"),n=t;try{return i.select(e,r,n)}catch(o){if(typeof o=="object"&&o!==null&&"message"in o&&typeof o.message=="string"&&o.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 o}}}catch(i){return console.error(`XPath evaluation failed for "${e}":`,i),[]}}function Yn(r){return function(e){return e===null?null:r[e]||null}}function Zn(r){const e=r.split(",").map(i=>i.trim()),t=[];for(const i of e){const n=i.split(/\\:|:/).filter(Boolean);n.length===1?t.push(`.//*[local-name()='${n[0]}']`):n.length===2&&t.push(`.//${n[0]}:${n[1]} | .//*[local-name()='${n[1]}']`)}return t.join(" | ")}function Q(r,e){if(typeof r.querySelector=="function")try{const i=r.querySelector(e);if(i)return i}catch(i){}const t=se(r,e);if(t.length>0)return t[0];try{const i=Zn(e);return ca(r,i)}catch(i){return console.warn("XPath query failed, using direct DOM traversal as fallback"),null}}function Wt(r,e){if(typeof r.querySelectorAll=="function")try{const i=r.querySelectorAll(e);if(i.length>0){const n=[];for(let o=0;o<i.length;o++)n.push(i[o]);return n}}catch(i){}const t=se(r,e);if(t.length>0)return t;try{const i=Zn(e);return la(r,i)}catch(i){return console.warn("XPath query failed, using direct DOM traversal as fallback"),[]}}function ua(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 Ze={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"},wt={c14n:{beforeChildren:()=>"",afterChildren:()=>"",betweenChildren:()=>"",afterElement:()=>"",isCanonicalizationMethod:"c14n"},c14n11:{beforeChildren:()=>"",afterChildren:()=>"",betweenChildren:()=>"",afterElement:()=>"",isCanonicalizationMethod:"c14n11"},c14n_exc:{beforeChildren:()=>"",afterChildren:()=>"",betweenChildren:()=>"",afterElement:()=>"",isCanonicalizationMethod:"c14n_exc"}},_={ELEMENT_NODE:1,TEXT_NODE:3};class q{constructor(e=wt.c14n){this.method=e}static fromMethod(e){const t=Ze[e];if(!t)throw new Error(`Unsupported canonicalization method: ${e}`);return new q(wt[t])}setMethod(e){this.method=e}static escapeXml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&apos;")}static collectNamespaces(e,t=new Map){let i=e;for(;i&&i.nodeType===_.ELEMENT_NODE;){const n=i,o=n.getAttribute("xmlns");o!==null&&!t.has("")&&t.set("",o);const s=n.attributes;for(let c=0;c<s.length;c++){const l=s[c];if(l.name.startsWith("xmlns:")){const f=l.name.substring(6);t.has(f)||t.set(f,l.value)}}i=i.parentNode}return t}static collectUsedNamespaces(e,t=new Map,i=[]){const n=new Map,o=new Set;function s(c,l=!1){if(c.nodeType===_.ELEMENT_NODE){const f=c,h=f.namespaceURI,d=f.prefix||"";if(d&&h&&(l||!o.has(d))){o.add(d);const y=t.get(d);y&&y===h&&!n.has(d)&&n.set(d,y)}const g=f.attributes;for(let y=0;y<g.length;y++){const v=g[y];if(v.name.includes(":")&&!v.name.startsWith("xmlns:")){const B=v.name.split(":")[0];if(l||!o.has(B)){o.add(B);const b=t.get(B);b&&!n.has(B)&&n.set(B,b)}}}for(const y of i){const v=t.get(y);v&&!n.has(y)&&n.set(y,v)}for(let y=0;y<c.childNodes.length;y++)s(c.childNodes[y],!1)}}return s(e,!0),n}static isBase64Element(e){if(e.nodeType!==_.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===_.ELEMENT_NODE?e:e.documentElement;function i(n){if(n.nodeType===_.ELEMENT_NODE){n._whitespace={hasMixedContent:!1,hasExistingLinebreaks:!1,originalContent:{}};const o=Array.from(n.childNodes);let s=!1,c=!1,l=!1;for(const f of o)if(f.nodeType===_.TEXT_NODE&&(f.nodeValue||"").trim().length>0){s=!0;break}for(const f of o)if(f.nodeType===_.ELEMENT_NODE){c=!0;break}for(let f=0;f<o.length;f++){const h=o[f];if(h.nodeType===_.TEXT_NODE){const d=h.nodeValue||"";h._originalText=d,d.includes(` `)&&(l=!0)}else h.nodeType===_.ELEMENT_NODE&&i(h)}n._whitespace.hasMixedContent=s&&c,n._whitespace.hasExistingLinebreaks=l}}i(t)}canonicalize(e,t=new Map,i={isStartingNode:!0}){var n,o,s;if(!e)return"";let c="";if(e.nodeType===_.ELEMENT_NODE){const l=new Map(t),f=e,h=f.getAttribute("xmlns");h!==null&&l.set("",h);const d=f.attributes;for(let C=0;C<d.length;C++){const x=d[C];if(x.name.startsWith("xmlns:")){const M=x.name.substring(6);l.set(M,x.value)}}const g=f.prefix||"",y=f.localName||f.nodeName.split(":").pop()||"",v=g?`${g}:${y}`:y;if(c+="<"+v,i.isStartingNode){const C=q.collectNamespaces(e),x=Array.from(C.entries()).sort((M,Se)=>M[0]===""?-1:Se[0]===""?1:M[0].localeCompare(Se[0]));for(const[M,Se]of x)M===""?c+=` xmlns="${Se}"`:c+=` xmlns:${M}="${Se}"`}else{const C=Array.from(l.entries()).filter(([x,M])=>!t.has(x)||t.get(x)!==M).sort((x,M)=>x[0]===""?-1:M[0]===""?1:x[0].localeCompare(M[0]));for(const[x,M]of C)x===""?c+=` xmlns="${M}"`:c+=` xmlns:${x}="${M}"`}const B=f.attributes,b=[];for(let C=0;C<B.length;C++){const x=B[C];x.name.startsWith("xmlns")||b.push(x)}b.sort((C,x)=>C.name.localeCompare(x.name));for(const C of b)c+=` ${C.name}="${q.escapeXml(C.value)}"`;c+=">";const w=Array.from(e.childNodes);let U=!1,K=!1;const N=((n=e._whitespace)==null?void 0:n.hasMixedContent)||!1;for(const C of w)if(C.nodeType===_.ELEMENT_NODE){U=!0;break}const V=this.method.isCanonicalizationMethod==="c14n11"&&U&&!((o=e._whitespace)!=null&&o.hasExistingLinebreaks)&&!N;V&&(c+=this.method.beforeChildren(U,N));for(let C=0;C<w.length;C++){const x=w[C],M=x.nodeType===_.ELEMENT_NODE,Se=C<w.length-1?w[C+1]:null;if(Se&&(Se.nodeType,_.ELEMENT_NODE),x.nodeType===_.TEXT_NODE){const Xt=x.nodeValue||"";q.isBase64Element(e)?c+=Xt.replace(/\r/g,"&#xD;"):c+=x._originalText||Xt,K=!1;continue}M&&(K&&this.method.isCanonicalizationMethod==="c14n11"&&!((s=e._whitespace)!=null&&s.hasExistingLinebreaks)&&!N&&(c+=this.method.betweenChildren(!0,!0,N)),c+=this.canonicalize(x,l,{isStartingNode:!1}),K=!0)}V&&(c+=this.method.afterChildren(U,N)),c+="</"+v+">"}else if(e.nodeType===_.TEXT_NODE){const l=e._originalText||e.nodeValue||"";c+=q.escapeXml(l)}return c}canonicalizeExclusive(e,t=new Map,i={}){if(!e)return"";const{inclusiveNamespacePrefixList:n=[],isStartingNode:o=!0}=i;let s="";if(e.nodeType===_.ELEMENT_NODE){const c=e,l=q.collectNamespaces(c),f=o?q.collectUsedNamespaces(c,l,n):new Map,h=c.prefix||"",d=c.localName||c.nodeName.split(":").pop()||"",g=h?`${h}:${d}`:d;if(s+="<"+g,o){const b=Array.from(f.entries()).sort((w,U)=>w[0]===""?-1:U[0]===""?1:w[0].localeCompare(U[0]));for(const[w,U]of b)w===""?s+=` xmlns="${U}"`:s+=` xmlns:${w}="${U}"`}const y=c.attributes,v=[];for(let b=0;b<y.length;b++){const w=y[b];w.name.startsWith("xmlns")||v.push(w)}v.sort((b,w)=>b.name.localeCompare(w.name));for(const b of v)s+=` ${b.name}="${q.escapeXml(b.value)}"`;s+=">";const B=Array.from(e.childNodes);for(let b=0;b<B.length;b++){const w=B[b];if(w.nodeType===_.TEXT_NODE){const U=w.nodeValue||"";q.isBase64Element(e)?s+=U.replace(/\r/g,"&#xD;"):s+=q.escapeXml(U)}else w.nodeType===_.ELEMENT_NODE&&(s+=this.canonicalizeExclusive(w,new Map([...t,...f]),{inclusiveNamespacePrefixList:n,isStartingNode:!1}))}s+="</"+g+">"}else if(e.nodeType===_.TEXT_NODE){const c=e.nodeValue||"";s+=q.escapeXml(c)}return s}static c14n(e){return this.analyzeWhitespace(e),new q(wt.c14n).canonicalize(e)}static c14n11(e){return this.analyzeWhitespace(e),new q(wt.c14n11).canonicalize(e)}static c14n_exc(e,t=[]){return this.analyzeWhitespace(e),new q(wt.c14n_exc).canonicalizeExclusive(e,new Map,{inclusiveNamespacePrefixList:t})}static canonicalize(e,t,i={}){switch(Ze[t]||Ze.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}`)}}}q.base64Elements=new Set(["DigestValue","X509Certificate","EncapsulatedTimeStamp","EncapsulatedOCSPValue","IssuerSerialV2"]);var fa=(r,e,t)=>new Promise((i,n)=>{var o=l=>{try{c(t.next(l))}catch(f){n(f)}},s=l=>{try{c(t.throw(l))}catch(f){n(f)}},c=l=>l.done?i(l.value):Promise.resolve(l.value).then(o,s);c((t=t.apply(r,e)).next())});function ha(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----- ${t.join(` `)} -----END CERTIFICATE-----`}function Qn(r){var e,t,i,n,o,s,c,l;const f={validFrom:r.notBefore,validTo:r.notAfter,issuer:{}};try{if(typeof r.subject=="object"&&r.subject!==null){const h=r.subject;f.commonName=h.commonName,f.organization=h.organizationName,f.country=h.countryName}if(typeof r.issuer=="object"&&r.issuer!==null){const h=r.issuer;f.issuer.commonName=h.commonName,f.issuer.organization=h.organizationName,f.issuer.country=h.countryName}}catch(h){console.warn("Could not extract subject/issuer as objects:",h)}try{if(typeof r.subject=="string"){const h=r.subject.split(",");for(const d of h){const[g,y]=d.trim().split("=");g==="CN"&&(f.commonName=f.commonName||y),g==="O"&&(f.organization=f.organization||y),g==="C"&&(f.country=f.country||y),g==="SN"&&(f.surname=y),(g==="G"||g==="GN")&&(f.givenName=y),(g==="SERIALNUMBER"||g==="2.5.4.5")&&(f.serialNumber=y==null?void 0:y.replace("PNOLV-",""))}}if(typeof r.issuer=="string"){const h=r.issuer.split(",");for(const d of h){const[g,y]=d.trim().split("=");g==="CN"&&(f.issuer.commonName=f.issuer.commonName||y),g==="O"&&(f.issuer.organization=f.issuer.organization||y),g==="C"&&(f.issuer.country=f.issuer.country||y)}}}catch(h){console.warn("Could not extract subject/issuer as strings:",h)}try{if("subjectName"in r&&(e=r.subjectName)!=null&&e.getField){const h=r.subjectName;f.commonName=f.commonName||((t=h.getField("CN"))==null?void 0:t[0]),f.surname=f.surname||((i=h.getField("SN"))==null?void 0:i[0]),f.givenName=f.givenName||((n=h.getField("G"))==null?void 0:n[0]),f.serialNumber=f.serialNumber||((s=(o=h.getField("2.5.4.5"))==null?void 0:o[0])==null?void 0:s.replace("PNOLV-","")),f.country=f.country||((c=h.getField("C"))==null?void 0:c[0]),f.organization=f.organization||((l=h.getField("O"))==null?void 0:l[0])}}catch(h){console.warn("Could not extract fields using getField method:",h)}return!f.serialNumber&&r.serialNumber&&(f.serialNumber=r.serialNumber),f}function eo(r){return fa(this,null,function*(){try{let e=r;if(!r.includes("-----BEGIN CERTIFICATE-----")){const n=r.replace(/[\r\n\s]/g,"");e=ha(n)}const t=new D.X509Certificate(e),i=Qn(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 pa(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 da(r){const{subject:e}=r;return e.givenName&&e.surname?`${e.givenName} ${e.surname}`:e.commonName?e.commonName:e.serialNumber||"Unknown Signer"}function ya(r){const{validFrom:e,validTo:t}=r,i=n=>n.toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"});return`${i(e)} to ${i(t)}`}function Kt(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----- ${t.join(` `)} -----END CERTIFICATE-----`}var ga=Object.defineProperty,va=Object.defineProperties,ma=Object.getOwnPropertyDescriptors,to=Object.getOwnPropertySymbols,wa=Object.prototype.hasOwnProperty,ba=Object.prototype.propertyIsEnumerable,ro=(r,e,t)=>e in r?ga(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,io=(r,e)=>{for(var t in e||(e={}))wa.call(e,t)&&ro(r,t,e[t]);if(to)for(var t of to(e))ba.call(e,t)&&ro(r,t,e[t]);return r},no=(r,e)=>va(r,ma(e));function Aa(r){return Array.from(r.keys()).filter(e=>e.match(/META-INF\/signatures\d*\.xml$/)||e.match(/META-INF\/.*signatures.*\.xml$/i))}function Sa(r,e){const t=new TextDecoder().decode(r),i=Jn().parseFromString(t,"application/xml"),n=Wt(i,"ds\\:Signature, Signature");if(n.length===0){if(console.warn(`No Signature elements found in ${e}`),t.includes("XAdESSignatures")){const s=i.documentElement;if(s){const l=Q(s,"ds\\:Signature, Signature");if(l){let f=oo(l,i);return f.rawXml=t,f}}const c=Ba(t);if(c)return no(io({},c),{rawXml:t})}return null}let o=oo(n[0],i);return o.rawXml=t,o}function oo(r,e){var t,i,n,o,s;const c=r.getAttribute("Id")||"unknown",l=Q(r,"ds\\:SignedInfo, SignedInfo");if(!l)throw new Error("SignedInfo element not found");const f=Q(l,"ds\\:CanonicalizationMethod, CanonicalizationMethod");let h=Ze.default;f&&(h=f.getAttribute("Algorithm")||h);let d="";d=ua(l);const g=Q(l,"ds\\:SignatureMethod, SignatureMethod"),y=(g==null?void 0:g.getAttribute("Algorithm"))||"",v=Q(r,"ds\\:SignatureValue, SignatureValue"),B=((t=v==null?void 0:v.textContent)==null?void 0:t.replace(/\s+/g,""))||"";let b;if(v)try{b=new q().canonicalize(v)}catch(F){}let w="",U="",K=[],N,V;const C=Q(r,"ds\\:KeyInfo, KeyInfo");if(C){const F=Q(C,"ds\\:X509Data, X509Data");if(F){const J=Wt(F,"ds\\:X509Certificate, X509Certificate");if(J.length>0){w=((i=J[0].textContent)==null?void 0:i.replace(/\s+/g,""))||"";for(let Re=1;Re<J.length;Re++){const Be=((n=J[Re].textContent)==null?void 0:n.replace(/\s+/g,""))||"";Be&&K.push(Kt(Be))}}}}if(!w){const F=Q(r,"ds\\:X509Certificate, X509Certificate");F&&(w=((o=F.textContent)==null?void 0:o.replace(/\s+/g,""))||"")}const x=Q(e,"xades\\:CertificateValues, CertificateValues");if(x){const F=Wt(x,"xades\\:EncapsulatedX509Certificate, EncapsulatedX509Certificate");for(const J of F){const Re=((s=J.textContent)==null?void 0:s.replace(/\s+/g,""))||"";if(Re){const Be=Kt(Re);K.includes(Be)||K.push(Be)}}}if(w){U=Kt(w);try{const F=new D.X509Certificate(U),J=F.publicKey.algorithm;V=no(io({algorithm:J.name},"namedCurve"in J?{namedCurve:J.namedCurve}:{}),{rawData:F.publicKey.rawData}),N=Qn(F)}catch(F){console.error("Failed to extract certificate information:",F)}}const M=Q(e,"xades\\:SigningTime, SigningTime"),Se=M&&M.textContent?new Date(M.textContent.trim()):new Date,Xt=[],ta={},ra={},Al=Wt(l,"ds\\:Reference, Reference");for(const F of Al){const J=F.getAttribute("URI")||"",Re=F.getAttribute("Type")||"";if(!J||J.startsWith("#")||Re.includes("SignedProperties"))continue;let Be=J;try{Be=decodeURIComponent(J)}catch(ti){console.error(`Failed to decode URI: ${J}`,ti)}const Xn=Be.startsWith("./")?Be.substring(2):Be;Xt.push(Xn);const na=Q(F,"ds\\:DigestMethod, DigestMethod");if(na){const ti=na.getAttribute("Algorithm");ti&&(ra[Xn]=ti)}const Wn=Q(F,"ds\\:DigestValue, DigestValue");Wn&&Wn.textContent&&(ta[Xn]=Wn.textContent.replace(/\s+/g,""))}let ia;const zn=Q(e,"xades\\:EncapsulatedTimeStamp, EncapsulatedTimeStamp");return zn&&zn.textContent&&(ia=zn.textContent.replace(/\s+/g,"")),{id:c,signingTime:Se,certificate:w,certificatePEM:U,certificateChain:K.length>0?K:void 0,publicKey:V,signerInfo:N,signedChecksums:ta,digestAlgorithms:ra,references:Xt,algorithm:y,signatureValue:B,canonicalSignatureValue:b,signedInfoXml:d,canonicalizationMethod:h,signatureTimestamp:ia}}function Ba(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>/),n=i&&i[1]?i[1].replace(/\s+/g,""):"",o=r.match(/<ds:X509Certificate>([\s\S]*?)<\/ds:X509Certificate>/),s=o&&o[1]?o[1].replace(/\s+/g,""):"",c=r.match(/<ds:SignatureMethod[^>]*Algorithm=["']([^"']*)["']/),l=c&&c[1]?c[1]:"",f=r.match(/<xades:SigningTime>([\s\S]*?)<\/xades:SigningTime>/),h=f&&f[1]?new Date(f[1].trim()):new Date,d=[],g={},y=/<ds:Reference[^>]*URI=["']([^#][^"']*)["'][^>]*>[\s\S]*?<ds:DigestValue>([\s\S]*?)<\/ds:DigestValue>/g;let v;for(;(v=y.exec(r))!==null;)if(v[1]&&!v[1].startsWith("#")){const b=decodeURIComponent(v[1]);d.push(b),v[2]&&(g[b]=v[2].replace(/\s+/g,""))}const B=Kt(s);return{id:t,signingTime:h,certificate:s,certificatePEM:B,signedChecksums:g,references:d,algorithm:l,signatureValue:n}}catch(e){return console.error("Error in fallback text parsing:",e),null}}function ka(r){try{const e=$.unzipSync(r),t=new Map,i=[],n=[];Object.entries(e).forEach(([f,h])=>{t.set(f,h),f.startsWith("META-INF/")||f==="mimetype"?n.push(f):i.push(f)});const o=[],s=Aa(t),c=new Set;for(const f of s){const h=t.get(f);if(h)try{const d=Sa(h,f);d&&(o.push(d),d.references&&d.references.length>0&&d.references.forEach(g=>{t.has(g)&&c.add(g)}))}catch(d){console.error(`Error parsing signature ${f}:`,d)}}const l=Array.from(c);return{files:t,documentFileList:i,metadataFileList:n,signedFileList:l,signatures:o}}catch(e){throw new Error(`Failed to parse eDoc container: ${e instanceof Error?e.message:String(e)}`)}}function xa(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 n=-1;for(let v=0;v<=t.length-i.length;v++){let B=!0;for(let b=0;b<i.length;b++)if(t[v+b]!==i[b]){B=!1;break}if(B){n=v;break}}if(n===-1)return r;let o=-1;for(let v=n+i.length;v<t.length;v++)if(t[v]===3){o=v;break}if(o===-1)return r;let s=0;(t[o+1]&128)===0?s=1:s=1+(t[o+1]&127);const c=o+1+s;if(c>=t.length)return r;const l=c+1;if(l>=t.length||t[l]!==48)return r;let f=0;(t[l+1]&128)===0?f=1:f=1+(t[l+1]&127);const h=l+1+f;if(h>=t.length||t[h]!==2)return r;let d=0,g=0;if((t[h+1]&128)===0)g=t[h+1],d=1;else{const v=t[h+1]&127;d=1+v,g=0;for(let B=0;B<v;B++)g=g<<8|t[h+2+B]}const y=h+1+d;if(y>=t.length)return r;if((t[y]&128)!==0){const v=new Uint8Array(t.length+1);if(v.set(t.slice(0,y)),v[y]=0,v.set(t.slice(y),y+1),(t[h+1]&128)===0)v[h+1]=t[h+1]+1;else{const B=t[h+1]&127;let b=0;for(let w=0;w<B;w++)b=b<<8|t[h+2+w];b+=1;for(let w=B-1;w>=0;w--)v[h+2+w]=b&255,b>>=8}if((t[l+1]&128)===0)v[l+1]=t[l+1]+1;else{const B=t[l+1]&127;let b=0;for(let w=0;w<B;w++)b=b<<8|t[l+2+w];b+=1;for(let w=B-1;w>=0;w--)v[l+2+w]=b&255,b>>=8}if((t[o+1]&128)===0)v[o+1]=t[o+1]+1;else{const B=t[o+1]&127;let b=0;for(let w=0;w<B;w++)b=b<<8|t[o+2+w];b+=1;for(let w=B-1;w>=0;w--)v[o+2+w]=b&255,b>>=8}if((t[1]&128)===0)v[1]=t[1]+1;else{const B=t[1]&127;let b=0;for(let w=0;w<B;w++)b=b<<8|t[2+w];b+=1;for(let w=B-1;w>=0;w--)v[2+w]=b&255,b>>=8}return e("Fixed key length: "+v.length),v.buffer}return r}const Na={ocspEnabled:!0,crlEnabled:!0,ocspTimeout:5e3,crlTimeout:1e4};/*! * MIT License * * Copyright (c) 2017-2024 Peculiar Ventures, LLC * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */const Ca="[object ArrayBuffer]";class I{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Ca}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=I.toUint8Array(e),n=I.toUint8Array(t);if(i.length!==n.byteLength)return!1;for(let o=0;o<i.length;o++)if(i[o]!==n[o])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 n=new Uint8Array(i);let o=0;for(const s of t){const c=this.toUint8Array(s);n.set(c,o),o+=c.length}return e[e.length-1]instanceof Function?this.toView(n,e[e.length-1]):n.buffer}}const ii="string",Ea=/^[0-9a-f\s]+$/i,Ia=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Oa=/^[a-zA-Z0-9-_]+$/;class so{static fromString(e){const t=unescape(encodeURIComponent(e)),i=new Uint8Array(t.length);for(let n=0;n<t.length;n++)i[n]=t.charCodeAt(n);return i.buffer}static toString(e){const t=I.toUint8Array(e);let i="";for(let o=0;o<t.length;o++)i+=String.fromCharCode(t[o]);return decodeURIComponent(escape(i))}}class me{static toString(e,t=!1){const i=I.toArrayBuffer(e),n=new DataView(i);let o="";for(let s=0;s<i.byteLength;s+=2){const c=n.getUint16(s,t);o+=String.fromCharCode(c)}return o}static fromString(e,t=!1){const i=new ArrayBuffer(e.length*2),n=new DataView(i);for(let o=0;o<e.length;o++)n.setUint16(o*2,e.charCodeAt(o),t);return i}}class L{static isHex(e){return typeof e===ii&&Ea.test(e)}static isBase64(e){return typeof e===ii&&Ia.test(e)}static isBase64Url(e){return typeof e===ii&&Oa.test(e)}static ToString(e,t="utf8"){const i=I.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 me.toString(i,!0);case"utf16":case"utf16be":return me.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 me.fromString(e,!0);case"utf16":case"utf16be":return me.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=I.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(!L.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(!L.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=L.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return so.fromString(e);case"utf16":case"utf16be":return me.fromString(e);case"utf16le":case"usc2":return me.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=L.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return so.toString(e);case"utf16":case"utf16be":return me.toString(e);case"utf16le":case"usc2":return me.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 n=0;n<t;n++)i[n]=e.charCodeAt(n);return i.buffer}static ToBinary(e){const t=I.toUint8Array(e);let i="";for(let n=0;n<t.length;n++)i+=String.fromCharCode(t[n]);return i}static ToHex(e){const t=I.toUint8Array(e);let i="";const n=t.length;for(let o=0;o<n;o++){const s=t[o];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(!L.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 n=0;n<t.length;n=n+2){const o=t.slice(n,n+2);i[n/2]=parseInt(o,16)}return i.buffer}static ToUtf16String(e,t=!1){return me.toString(e,t)}static FromUtf16String(e,t=!1){return me.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,""))||""}}L.DEFAULT_UTF8_ENCODING="utf8";function Ta(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;const t=new Uint8Array(r),i=new Uint8Array(e);for(let n=0;n<r.byteLength;n++)if(t[n]!==i[n])return!1;return!0}/*! Copyright (c) Peculiar Ventures, LLC */function Qe(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 Le(r,e,t=-1){const i=t;let n=r,o=0,s=Math.pow(2,e);for(let c=1;c<8;c++){if(r<s){let l;if(i<0)l=new ArrayBuffer(c),o=c;else{if(i<c)return new ArrayBuffer(0);l=new ArrayBuffer(i),o=i}const f=new Uint8Array(l);for(let h=c-1;h>=0;h--){const d=Math.pow(2,h*e);f[o-h-1]=Math.floor(n/d),n-=f[o-h-1]*d}return l}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function ni(...r){let e=0,t=0;for(const o of r)e+=o.length;const i=new ArrayBuffer(e),n=new Uint8Array(i);for(const o of r)n.set(o,t),t+=o.length;return n}function ao(){const r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const c=r[0]===255&&r[1]&128,l=r[0]===0&&(r[1]&128)===0;(c||l)&&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=Qe(t,8),n=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(n);for(let c=0;c<this.valueHex.byteLength;c++)o[c]=r[c];return o[0]&=127,Qe(o,8)-i}function Va(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=Le(s,8,i),l=new Uint8Array(c);return l[0]|=128,c}let n=Le(e,8,i),o=new Uint8Array(n);if(o[0]&128){const s=n.slice(0),c=new Uint8Array(s);n=new ArrayBuffer(n.byteLength+1),o=new Uint8Array(n);for(let l=0;l<s.byteLength;l++)o[l+1]=c[l];o[0]=0}return n}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function Ua(r,e){if(r.byteLength!==e.byteLength)return!1;const t=new Uint8Array(r),i=new Uint8Array(e);for(let n=0;n<t.length;n++)if(t[n]!==i[n])return!1;return!0}function ie(r,e){const t=r.toString(10);if(e<t.length)return"";const i=e-t.length,n=new Array(i);for(let s=0;s<i;s++)n[s]="0";return n.join("").concat(t)}/*! * Copyright (c) 2014, GMO GlobalSign * Copyright (c) 2015-2022, Peculiar Ventures * All rights reserved. * * Author 2014-2019, Yury Strozhevsky * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. * * * Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */function Jt(){if(typeof BigInt=="undefined")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function oi(r){let e=0,t=0;for(let n=0;n<r.length;n++){const o=r[n];e+=o.byteLength}const i=new Uint8Array(e);for(let n=0;n<r.length;n++){const o=r[n];i.set(new Uint8Array(o),t),t+=o.byteLength}return i.buffer}function ke(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 Yt{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return oi(this.items)}}const bt=[new Uint8Array([1])],co="0123456789",si="name",lo="valueHexView",ja="isHexOnly",Da="idBlock",Ra="tagClass",La="tagNumber",Ha="isConstructed",$a="fromBER",Ma="toBER",Pa="local",ee="",le=new ArrayBuffer(0),Zt=new Uint8Array(0),At="EndOfContent",uo="OCTET STRING",fo="BIT STRING";function we(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 n;super(...i);const o=i[0]||{};this.isHexOnly=(n=o.isHexOnly)!==null&&n!==void 0?n:!1,this.valueHexView=o.valueHex?I.toUint8Array(o.valueHex):Zt}fromBER(i,n,o){const s=i instanceof ArrayBuffer?new Uint8Array(i):i;if(!ke(this,s,n,o))return-1;const c=n+o;return this.valueHexView=s.subarray(n,c),this.valueHexView.length?(this.blockLength=o,c):(this.warnings.push("Zero buffer length"),n)}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",le)}toJSON(){return P(j({},super.toJSON()),{isHexOnly:this.isHexOnly,valueHex:L.ToHex(this.valueHexView)})}},e.NAME="hexBlock",e}class He{static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}constructor({blockLength:e=0,error:t=ee,warnings:i=[],valueBeforeDecode:n=Zt}={}){this.blockLength=e,this.error=t,this.warnings=i,this.valueBeforeDecodeView=I.toUint8Array(n)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:L.ToHex(this.valueBeforeDecodeView)}}}He.NAME="baseBlock";class Y extends He{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'")}}Y.NAME="valueBlock";class ho extends we(He){constructor({idBlock:e={}}={}){var t,i,n,o;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?I.toUint8Array(e.valueHex):Zt,this.tagClass=(i=e.tagClass)!==null&&i!==void 0?i:-1,this.tagNumber=(n=e.tagNumber)!==null&&n!==void 0?n:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!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",le}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const n=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,t|=o,n[0]=t}return n.buffer}if(!this.isHexOnly){const n=Le(this.tagNumber,7),o=new Uint8Array(n),s=n.byteLength,c=new Uint8Array(s+1);if(c[0]=t|31,!e){for(let l=0;l<s-1;l++)c[l+1]=o[l]|128;c[s]=o[s-1]}return c.buffer}const i=new Uint8Array(this.valueHexView.byteLength+1);if(i[0]=t|31,!e){const n=this.valueHexView;for(let o=0;o<n.length-1;o++)i[o+1]=n[o]|128;i[this.valueHexView.byteLength]=n[n.length-1]}return i.buffer}fromBER(e,t,i){const n=I.toUint8Array(e);if(!ke(this,n,t,i))return-1;const o=n.subarray(t,t+i);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[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=(o[0]&32)===32,this.isHexOnly=!1;const c=o[0]&31;if(c!==31)this.tagNumber=c,this.blockLength=1;else{let l=1,f=this.valueHexView=new Uint8Array(255),h=255;for(;o[l]&128;){if(f[l-1]=o[l]&127,l++,l>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(l===h){h+=255;const g=new Uint8Array(h);for(let y=0;y<f.length;y++)g[y]=f[y];f=this.valueHexView=new Uint8Array(h)}}this.blockLength=l+1,f[l-1]=o[l]&127;const d=new Uint8Array(l);for(let g=0;g<l;g++)d[g]=f[g];f=this.valueHexView=new Uint8Array(l),f.set(d),this.blockLength<=9?this.tagNumber=Qe(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 P(j({},super.toJSON()),{tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed})}}ho.NAME="identificationBlock";class po extends He{constructor({lenBlock:e={}}={}){var t,i,n;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=(n=e.length)!==null&&n!==void 0?n:0}fromBER(e,t,i){const n=I.toUint8Array(e);if(!ke(this,n,t,i))return-1;const o=n.subarray(t,t+i);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,t+this.blockLength;const s=o[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>o.length)return this.error="End of input reached before message was fully decoded",-1;const c=t+1,l=n.subarray(c,c+s);return l[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Qe(l,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 n=Le(this.length,8);if(n.byteLength>127)return this.error="Too big length",le;if(t=new ArrayBuffer(n.byteLength+1),e)return t;const o=new Uint8Array(n);i=new Uint8Array(t),i[0]=n.byteLength|128;for(let s=0;s<n.byteLength;s++)i[s+1]=o[s];return t}return t=new ArrayBuffer(1),e===!1&&(i=new Uint8Array(t),i[0]=this.length),t}toJSON(){return P(j({},super.toJSON()),{isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length})}}po.NAME="lengthBlock";const A={};class G extends He{constructor(s={},o){var c=s,{name:e=ee,optional:t=!1,primitiveSchema:i}=c,n=H(c,["name","optional","primitiveSchema"]);super(n),this.name=e,this.optional=t,i&&(this.primitiveSchema=i),this.idBlock=new ho(n),this.lenBlock=new po(n),this.valueBlock=o?new o(n):new Y(n)}fromBER(e,t,i){const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?i:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}toBER(e,t){const i=t||new Yt;t||yo(this);const n=this.idBlock.toBER(e);if(i.write(n),this.lenBlock.isIndefiniteForm)i.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,i),i.write(new ArrayBuffer(2));else{const o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;const s=this.lenBlock.toBER(e);i.write(s),i.write(o)}return t?le:i.final()}toJSON(){const e=P(j({},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():L.ToHex(this.toBER())}onAsciiEncoding(){const e=this.constructor.NAME,t=L.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 Ua(t,i)}}G.NAME="BaseBlock";function yo(r){var e;if(r instanceof A.Constructed)for(const t of r.valueBlock.value)yo(t)&&(r.lenBlock.isIndefiniteForm=!0);return!!(!((e=r.lenBlock)===null||e===void 0)&&e.isIndefiniteForm)}class ai extends G{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(n={},i){var o=n,{value:e=ee}=o,t=H(o,["value"]);super(t,i),e&&this.fromString(e)}fromBER(e,t,i){const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?i:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}ai.NAME="BaseStringBlock";class go extends we(Y){constructor(i={}){var n=i,{isHexOnly:e=!0}=n,t=H(n,["isHexOnly"]);super(t),this.isHexOnly=e}}go.NAME="PrimitiveValueBlock";var vo;class St extends G{constructor(e={}){super(e,go),this.idBlock.isConstructed=!1}}vo=St,A.Primitive=vo,St.NAME="PRIMITIVE";function _a(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 et(r,e=0,t=r.length){const i=e;let n=new G({},Y);const o=new He;if(!ke(o,r,e,t))return n.error=o.error,{offset:-1,result:n};if(!r.subarray(e,e+t).length)return n.error="Zero buffer length",{offset:-1,result:n};let c=n.idBlock.fromBER(r,e,t);if(n.idBlock.warnings.length&&n.warnings.concat(n.idBlock.warnings),c===-1)return n.error=n.idBlock.error,{offset:-1,result:n};if(e=c,t-=n.idBlock.blockLength,c=n.lenBlock.fromBER(r,e,t),n.lenBlock.warnings.length&&n.warnings.concat(n.lenBlock.warnings),c===-1)return n.error=n.lenBlock.error,{offset:-1,result:n};if(e=c,t-=n.lenBlock.blockLength,!n.idBlock.isConstructed&&n.lenBlock.isIndefiniteForm)return n.error="Indefinite length form used for primitive encoding form",{offset:-1,result:n};let l=G;switch(n.idBlock.tagClass){case 1:if(n.idBlock.tagNumber>=37&&n.idBlock.isHexOnly===!1)return n.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:n};switch(n.idBlock.tagNumber){case 0:if(n.idBlock.isConstructed&&n.lenBlock.length>0)return n.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:n};l=A.EndOfContent;break;case 1:l=A.Boolean;break;case 2:l=A.Integer;break;case 3:l=A.BitString;break;case 4:l=A.OctetString;break;case 5:l=A.Null;break;case 6:l=A.ObjectIdentifier;break;case 10:l=A.Enumerated;break;case 12:l=A.Utf8String;break;case 13:l=A.RelativeObjectIdentifier;break;case 14:l=A.TIME;break;case 15:return n.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:n};case 16:l=A.Sequence;break;case 17:l=A.Set;break;case 18:l=A.NumericString;break;case 19:l=A.PrintableString;break;case 20:l=A.TeletexString;break;case 21:l=A.VideotexString;break;case 22:l=A.IA5String;break;case 23:l=A.UTCTime;break;case 24:l=A.GeneralizedTime;break;case 25:l=A.GraphicString;break;case 26:l=A.VisibleString;break;case 27:l=A.GeneralString;break;case 28:l=A.UniversalString;break;case 29:l=A.CharacterString;break;case 30:l=A.BmpString;break;case 31:l=A.DATE;break;case 32:l=A.TimeOfDay;break;case 33:l=A.DateTime;break;case 34:l=A.Duration;break;default:{const f=n.idBlock.isConstructed?new A.Constructed:new A.Primitive;f.idBlock=n.idBlock,f.lenBlock=n.lenBlock,f.warnings=n.warnings,n=f}}break;case 2:case 3:case 4:default:l=n.idBlock.isConstructed?A.Constructed:A.Primitive}return n=_a(n,l),c=n.fromBER(r,e,n.lenBlock.isIndefiniteForm?t:n.lenBlock.length),n.valueBeforeDecodeView=r.subarray(i,i+n.blockLength),{offset:c,result:n}}function tt(r){if(!r.byteLength){const e=new G({},Y);return e.error="Input buffer has zero length",{offset:-1,result:e}}return et(I.toUint8Array(r).slice(),0,r.byteLength)}function qa(r,e){return r?1:e}class Ue extends Y{constructor(n={}){var o=n,{value:e=[],isIndefiniteForm:t=!1}=o,i=H(o,["value","isIndefiniteForm"]);super(i),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,i){const n=I.toUint8Array(e);if(!ke(this,n,t,i))return-1;if(this.valueBeforeDecodeView=n.subarray(t,t+i),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let o=t;for(;qa(this.isIndefiniteForm,i)>0;){const s=et(n,o,i);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,i-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===At)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===At?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,t){const i=t||new Yt;for(let n=0;n<this.value.length;n++)this.value[n].toBER(e,i);return t?le:i.final()}toJSON(){const e=P(j({},super.toJSON()),{isIndefiniteForm:this.isIndefiniteForm,value:[]});for(const t of this.value)e.value.push(t.toJSON());return e}}Ue.NAME="ConstructedValueBlock";var mo;class Z extends G{constructor(e={}){super(e,Ue),this.idBlock.isConstructed=!0}fromBER(e,t,i){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const n=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?i:this.lenBlock.length);return n===-1?(this.error=this.valueBlock.error,n):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),n)}onAsciiEncoding(){const e=[];for(const i of this.valueBlock.value)e.push(i.toString("ascii").split(` `).map(n=>` ${n}`).join(` `));const t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} : ${e.join(` `)}`:`${t} :`}}mo=Z,A.Constructed=mo,Z.NAME="CONSTRUCTED";class wo extends Y{fromBER(e,t,i){return t}toBER(e){return le}}wo.override="EndOfContentValueBlock";var bo;class ci extends G{constructor(e={}){super(e,wo),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}bo=ci,A.EndOfContent=bo,ci.NAME=At;var Ao;class $e extends G{constructor(e={}){super(e,Y),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 n=new Uint8Array(i);n[0]=5,n[1]=0}return t&&t.write(i),i}onAsciiEncoding(){return`${this.constructor.NAME}`}}Ao=$e,A.Null=Ao,$e.NAME="NULL";class So extends we(Y){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 n=i,{value:e}=n,t=H(n,["value"]);super(t),t.valueHex?this.valueHexView=I.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}fromBER(e,t,i){const n=I.toUint8Array(e);return ke(this,n,t,i)?(this.valueHexView=n.subarray(t,t+i),i>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,ao.call(this),this.blockLength=i,t+i):-1}toBER(){return this.valueHexView.slice()}toJSON(){return P(j({},super.toJSON()),{value:this.value})}}So.NAME="BooleanValueBlock";var Bo;class Qt extends G{getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}constructor(e={}){super(e,So),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Bo=Qt,A.Boolean=Bo,Qt.NAME="BOOLEAN";class ko extends we(Ue){constructor(i={}){var n=i,{isConstructed:e=!1}=n,t=H(n,["isConstructed"]);super(t),this.isConstructed=e}fromBER(e,t,i){let n=0;if(this.isConstructed){if(this.isHexOnly=!1,n=Ue.prototype.fromBER.call(this,e,t,i),n===-1)return n;for(let o=0;o<this.value.length;o++){const s=this.value[o].constructor.NAME;if(s===At){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==uo)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=