Files
dtx_store/uniCloud-aliyun/cloudfunctions/uniAdCallback/x509.js
2022-06-30 16:02:53 +08:00

2 lines
74 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("net"),e=require("util"),r=require("crypto");function s(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=s(t),n=s(e),a=s(r);var o={},u={};Object.defineProperty(u,"__esModule",{value:!0});const c=i.default;u.bytesFromIP=function(t){switch(c.isIP(t)){case 4:return Buffer.from(t.split(".").map((t=>parseInt(t,10))));case 6:const e=t.split(":"),r=Buffer.alloc(16);let s=0;""===e[e.length-1]&&(e[e.length-1]="0");for(let t=0;t<e.length;t++)""!==e[t]?(r.writeUInt16BE(parseInt(e[t],16),s),s+=2):t+1<e.length&&""!==e[t+1]&&(s=16-2*(e.length-t-1));return r;default:return null}},u.bytesToIP=function(t){switch(t.length){case 4:return[t[0],t[1],t[2],t[3]].join(".");case 16:const e=[];let r=-1,s=0,i=-1,n=0;for(let a=0;a<t.length;a+=2){const o=t[a]<<8|t[a+1];0===o?(s++,-1===r&&(r=e.length),s>n&&(n=s,i=r)):(r=-1,s=0),e.push(o.toString(16))}if(n>0){let t="";const r=e.slice(i+n);e.length=i,0===e.length&&(t+=":"),0===r.length&&(t+=":"),e.push(t,...r)}return e.join(":");default:return""}};const l=Object.create(null),h=/^[0-9.]+$/;function f(t,e){l[t]=e,l[e]=t}u.getOID=function(t){return h.test(t)&&""!==l[t]?t:null==l[t]?"":l[t]},u.getOIDName=function(t){return h.test(t)||""===l[t]?null==l[t]?t:l[t]:t},f("1.2.840.113549.1.1.1","rsaEncryption"),f("1.2.840.113549.1.1.4","md5WithRsaEncryption"),f("1.2.840.113549.1.1.5","sha1WithRsaEncryption"),f("1.2.840.113549.1.1.8","mgf1"),f("1.2.840.113549.1.1.10","RSASSA-PSS"),f("1.2.840.113549.1.1.11","sha256WithRsaEncryption"),f("1.2.840.113549.1.1.12","sha384WithRsaEncryption"),f("1.2.840.113549.1.1.13","sha512WithRsaEncryption"),f("1.2.840.10045.2.1","ecEncryption"),f("1.2.840.10045.4.1","ecdsaWithSha1"),f("1.2.840.10045.4.3.2","ecdsaWithSha256"),f("1.2.840.10045.4.3.3","ecdsaWithSha384"),f("1.2.840.10045.4.3.4","ecdsaWithSha512"),f("1.2.840.10040.4.3","dsaWithSha1"),f("2.16.840.1.101.3.4.3.2","dsaWithSha256"),f("1.3.14.3.2.7","desCBC"),f("1.3.14.3.2.26","sha1"),f("2.16.840.1.101.3.4.2.1","sha256"),f("2.16.840.1.101.3.4.2.2","sha384"),f("2.16.840.1.101.3.4.2.3","sha512"),f("1.2.840.113549.2.5","md5"),f("1.3.101.110","X25519"),f("1.3.101.111","X448"),f("1.3.101.112","Ed25519"),f("1.3.101.113","Ed448"),f("1.2.840.113549.1.7.1","data"),f("1.2.840.113549.1.7.2","signedData"),f("1.2.840.113549.1.7.3","envelopedData"),f("1.2.840.113549.1.7.4","signedAndEnvelopedData"),f("1.2.840.113549.1.7.5","digestedData"),f("1.2.840.113549.1.7.6","encryptedData"),f("1.2.840.113549.1.9.1","emailAddress"),f("1.2.840.113549.1.9.2","unstructuredName"),f("1.2.840.113549.1.9.3","contentType"),f("1.2.840.113549.1.9.4","messageDigest"),f("1.2.840.113549.1.9.5","signingTime"),f("1.2.840.113549.1.9.6","counterSignature"),f("1.2.840.113549.1.9.7","challengePassword"),f("1.2.840.113549.1.9.8","unstructuredAddress"),f("1.2.840.113549.1.9.14","extensionRequest"),f("1.2.840.113549.1.9.20","friendlyName"),f("1.2.840.113549.1.9.21","localKeyId"),f("1.2.840.113549.1.9.22.1","x509Certificate"),f("1.2.840.113549.1.12.10.1.1","keyBag"),f("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag"),f("1.2.840.113549.1.12.10.1.3","certBag"),f("1.2.840.113549.1.12.10.1.4","crlBag"),f("1.2.840.113549.1.12.10.1.5","secretBag"),f("1.2.840.113549.1.12.10.1.6","safeContentsBag"),f("1.2.840.113549.1.5.13","pkcs5PBES2"),f("1.2.840.113549.1.5.12","pkcs5PBKDF2"),f("1.2.840.113549.2.7","hmacWithSha1"),f("1.2.840.113549.2.9","hmacWithSha256"),f("1.2.840.113549.2.10","hmacWithSha384"),f("1.2.840.113549.2.11","hmacWithSha512"),f("1.2.840.113549.3.7","3desCBC"),f("2.16.840.1.101.3.4.1.2","aesCBC128"),f("2.16.840.1.101.3.4.1.42","aesCBC256"),f("2.5.4.3","commonName"),f("2.5.4.5","serialName"),f("2.5.4.6","countryName"),f("2.5.4.7","localityName"),f("2.5.4.8","stateOrProvinceName"),f("2.5.4.10","organizationName"),f("2.5.4.11","organizationalUnitName"),f("2.5.4.15","businessCategory"),f("2.16.840.1.113730.1.1","nsCertType"),f("2.5.29.2","keyAttributes"),f("2.5.29.4","keyUsageRestriction"),f("2.5.29.6","subtreesConstraint"),f("2.5.29.9","subjectDirectoryAttributes"),f("2.5.29.14","subjectKeyIdentifier"),f("2.5.29.15","keyUsage"),f("2.5.29.16","privateKeyUsagePeriod"),f("2.5.29.17","subjectAltName"),f("2.5.29.18","issuerAltName"),f("2.5.29.19","basicConstraints"),f("2.5.29.20","cRLNumber"),f("2.5.29.21","cRLReason"),f("2.5.29.22","expirationDate"),f("2.5.29.23","instructionCode"),f("2.5.29.24","invalidityDate"),f("2.5.29.27","deltaCRLIndicator"),f("2.5.29.28","issuingDistributionPoint"),f("2.5.29.29","certificateIssuer"),f("2.5.29.30","nameConstraints"),f("2.5.29.31","cRLDistributionPoints"),f("2.5.29.32","certificatePolicies"),f("2.5.29.33","policyMappings"),f("2.5.29.35","authorityKeyIdentifier"),f("2.5.29.36","policyConstraints"),f("2.5.29.37","extKeyUsage"),f("2.5.29.46","freshestCRL"),f("2.5.29.54","inhibitAnyPolicy"),f("1.3.6.1.4.1.311.60.2.1.2","jurisdictionST"),f("1.3.6.1.4.1.311.60.2.1.3","jurisdictionC"),f("1.3.6.1.4.1.11129.2.4.2","timestampList"),f("1.3.6.1.5.5.7.1.1","authorityInfoAccess"),f("1.3.6.1.5.5.7.3.1","serverAuth"),f("1.3.6.1.5.5.7.3.2","clientAuth"),f("1.3.6.1.5.5.7.3.3","codeSigning"),f("1.3.6.1.5.5.7.3.4","emailProtection"),f("1.3.6.1.5.5.7.3.8","timeStamping"),f("1.3.6.1.5.5.7.48.1","authorityInfoAccessOcsp"),f("1.3.6.1.5.5.7.48.2","authorityInfoAccessIssuers");var y={},g={exports:{}};!function(t){var e=function(t){var e,r=new Float64Array(16);if(t)for(e=0;e<t.length;e++)r[e]=t[e];return r},r=function(){throw new Error("no PRNG")},s=new Uint8Array(16),i=new Uint8Array(32);i[0]=9;var n=e(),o=e([1]),u=e([56129,1]),c=e([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),l=e([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),h=e([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),f=e([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),y=e([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function g(t,e,r,s){t[e]=r>>24&255,t[e+1]=r>>16&255,t[e+2]=r>>8&255,t[e+3]=255&r,t[e+4]=s>>24&255,t[e+5]=s>>16&255,t[e+6]=s>>8&255,t[e+7]=255&s}function E(t,e,r,s,i){var n,a=0;for(n=0;n<i;n++)a|=t[e+n]^r[s+n];return(1&a-1>>>8)-1}function p(t,e,r,s){return E(t,e,r,s,16)}function d(t,e,r,s){return E(t,e,r,s,32)}function S(t,e,r,s){!function(t,e,r,s){for(var i,n=255&s[0]|(255&s[1])<<8|(255&s[2])<<16|(255&s[3])<<24,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,o=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,c=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,l=255&s[4]|(255&s[5])<<8|(255&s[6])<<16|(255&s[7])<<24,h=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,y=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,g=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,E=255&s[8]|(255&s[9])<<8|(255&s[10])<<16|(255&s[11])<<24,p=255&r[16]|(255&r[17])<<8|(255&r[18])<<16|(255&r[19])<<24,d=255&r[20]|(255&r[21])<<8|(255&r[22])<<16|(255&r[23])<<24,S=255&r[24]|(255&r[25])<<8|(255&r[26])<<16|(255&r[27])<<24,I=255&r[28]|(255&r[29])<<8|(255&r[30])<<16|(255&r[31])<<24,N=255&s[12]|(255&s[13])<<8|(255&s[14])<<16|(255&s[15])<<24,b=n,m=a,A=o,v=u,T=c,w=l,C=h,R=f,U=y,_=g,P=E,O=p,B=d,K=S,D=I,L=N,x=0;x<20;x+=2)b^=(i=(B^=(i=(U^=(i=(T^=(i=b+B|0)<<7|i>>>25)+b|0)<<9|i>>>23)+T|0)<<13|i>>>19)+U|0)<<18|i>>>14,w^=(i=(m^=(i=(K^=(i=(_^=(i=w+m|0)<<7|i>>>25)+w|0)<<9|i>>>23)+_|0)<<13|i>>>19)+K|0)<<18|i>>>14,P^=(i=(C^=(i=(A^=(i=(D^=(i=P+C|0)<<7|i>>>25)+P|0)<<9|i>>>23)+D|0)<<13|i>>>19)+A|0)<<18|i>>>14,L^=(i=(O^=(i=(R^=(i=(v^=(i=L+O|0)<<7|i>>>25)+L|0)<<9|i>>>23)+v|0)<<13|i>>>19)+R|0)<<18|i>>>14,b^=(i=(v^=(i=(A^=(i=(m^=(i=b+v|0)<<7|i>>>25)+b|0)<<9|i>>>23)+m|0)<<13|i>>>19)+A|0)<<18|i>>>14,w^=(i=(T^=(i=(R^=(i=(C^=(i=w+T|0)<<7|i>>>25)+w|0)<<9|i>>>23)+C|0)<<13|i>>>19)+R|0)<<18|i>>>14,P^=(i=(_^=(i=(U^=(i=(O^=(i=P+_|0)<<7|i>>>25)+P|0)<<9|i>>>23)+O|0)<<13|i>>>19)+U|0)<<18|i>>>14,L^=(i=(D^=(i=(K^=(i=(B^=(i=L+D|0)<<7|i>>>25)+L|0)<<9|i>>>23)+B|0)<<13|i>>>19)+K|0)<<18|i>>>14;b=b+n|0,m=m+a|0,A=A+o|0,v=v+u|0,T=T+c|0,w=w+l|0,C=C+h|0,R=R+f|0,U=U+y|0,_=_+g|0,P=P+E|0,O=O+p|0,B=B+d|0,K=K+S|0,D=D+I|0,L=L+N|0,t[0]=b>>>0&255,t[1]=b>>>8&255,t[2]=b>>>16&255,t[3]=b>>>24&255,t[4]=m>>>0&255,t[5]=m>>>8&255,t[6]=m>>>16&255,t[7]=m>>>24&255,t[8]=A>>>0&255,t[9]=A>>>8&255,t[10]=A>>>16&255,t[11]=A>>>24&255,t[12]=v>>>0&255,t[13]=v>>>8&255,t[14]=v>>>16&255,t[15]=v>>>24&255,t[16]=T>>>0&255,t[17]=T>>>8&255,t[18]=T>>>16&255,t[19]=T>>>24&255,t[20]=w>>>0&255,t[21]=w>>>8&255,t[22]=w>>>16&255,t[23]=w>>>24&255,t[24]=C>>>0&255,t[25]=C>>>8&255,t[26]=C>>>16&255,t[27]=C>>>24&255,t[28]=R>>>0&255,t[29]=R>>>8&255,t[30]=R>>>16&255,t[31]=R>>>24&255,t[32]=U>>>0&255,t[33]=U>>>8&255,t[34]=U>>>16&255,t[35]=U>>>24&255,t[36]=_>>>0&255,t[37]=_>>>8&255,t[38]=_>>>16&255,t[39]=_>>>24&255,t[40]=P>>>0&255,t[41]=P>>>8&255,t[42]=P>>>16&255,t[43]=P>>>24&255,t[44]=O>>>0&255,t[45]=O>>>8&255,t[46]=O>>>16&255,t[47]=O>>>24&255,t[48]=B>>>0&255,t[49]=B>>>8&255,t[50]=B>>>16&255,t[51]=B>>>24&255,t[52]=K>>>0&255,t[53]=K>>>8&255,t[54]=K>>>16&255,t[55]=K>>>24&255,t[56]=D>>>0&255,t[57]=D>>>8&255,t[58]=D>>>16&255,t[59]=D>>>24&255,t[60]=L>>>0&255,t[61]=L>>>8&255,t[62]=L>>>16&255,t[63]=L>>>24&255}(t,e,r,s)}function I(t,e,r,s){!function(t,e,r,s){for(var i,n=255&s[0]|(255&s[1])<<8|(255&s[2])<<16|(255&s[3])<<24,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,o=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,u=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,c=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,l=255&s[4]|(255&s[5])<<8|(255&s[6])<<16|(255&s[7])<<24,h=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,f=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,y=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,g=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,E=255&s[8]|(255&s[9])<<8|(255&s[10])<<16|(255&s[11])<<24,p=255&r[16]|(255&r[17])<<8|(255&r[18])<<16|(255&r[19])<<24,d=255&r[20]|(255&r[21])<<8|(255&r[22])<<16|(255&r[23])<<24,S=255&r[24]|(255&r[25])<<8|(255&r[26])<<16|(255&r[27])<<24,I=255&r[28]|(255&r[29])<<8|(255&r[30])<<16|(255&r[31])<<24,N=255&s[12]|(255&s[13])<<8|(255&s[14])<<16|(255&s[15])<<24,b=0;b<20;b+=2)n^=(i=(d^=(i=(y^=(i=(c^=(i=n+d|0)<<7|i>>>25)+n|0)<<9|i>>>23)+c|0)<<13|i>>>19)+y|0)<<18|i>>>14,l^=(i=(a^=(i=(S^=(i=(g^=(i=l+a|0)<<7|i>>>25)+l|0)<<9|i>>>23)+g|0)<<13|i>>>19)+S|0)<<18|i>>>14,E^=(i=(h^=(i=(o^=(i=(I^=(i=E+h|0)<<7|i>>>25)+E|0)<<9|i>>>23)+I|0)<<13|i>>>19)+o|0)<<18|i>>>14,N^=(i=(p^=(i=(f^=(i=(u^=(i=N+p|0)<<7|i>>>25)+N|0)<<9|i>>>23)+u|0)<<13|i>>>19)+f|0)<<18|i>>>14,n^=(i=(u^=(i=(o^=(i=(a^=(i=n+u|0)<<7|i>>>25)+n|0)<<9|i>>>23)+a|0)<<13|i>>>19)+o|0)<<18|i>>>14,l^=(i=(c^=(i=(f^=(i=(h^=(i=l+c|0)<<7|i>>>25)+l|0)<<9|i>>>23)+h|0)<<13|i>>>19)+f|0)<<18|i>>>14,E^=(i=(g^=(i=(y^=(i=(p^=(i=E+g|0)<<7|i>>>25)+E|0)<<9|i>>>23)+p|0)<<13|i>>>19)+y|0)<<18|i>>>14,N^=(i=(I^=(i=(S^=(i=(d^=(i=N+I|0)<<7|i>>>25)+N|0)<<9|i>>>23)+d|0)<<13|i>>>19)+S|0)<<18|i>>>14;t[0]=n>>>0&255,t[1]=n>>>8&255,t[2]=n>>>16&255,t[3]=n>>>24&255,t[4]=l>>>0&255,t[5]=l>>>8&255,t[6]=l>>>16&255,t[7]=l>>>24&255,t[8]=E>>>0&255,t[9]=E>>>8&255,t[10]=E>>>16&255,t[11]=E>>>24&255,t[12]=N>>>0&255,t[13]=N>>>8&255,t[14]=N>>>16&255,t[15]=N>>>24&255,t[16]=h>>>0&255,t[17]=h>>>8&255,t[18]=h>>>16&255,t[19]=h>>>24&255,t[20]=f>>>0&255,t[21]=f>>>8&255,t[22]=f>>>16&255,t[23]=f>>>24&255,t[24]=y>>>0&255,t[25]=y>>>8&255,t[26]=y>>>16&255,t[27]=y>>>24&255,t[28]=g>>>0&255,t[29]=g>>>8&255,t[30]=g>>>16&255,t[31]=g>>>24&255}(t,e,r,s)}var N=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function b(t,e,r,s,i,n,a){var o,u,c=new Uint8Array(16),l=new Uint8Array(64);for(u=0;u<16;u++)c[u]=0;for(u=0;u<8;u++)c[u]=n[u];for(;i>=64;){for(S(l,c,a,N),u=0;u<64;u++)t[e+u]=r[s+u]^l[u];for(o=1,u=8;u<16;u++)o=o+(255&c[u])|0,c[u]=255&o,o>>>=8;i-=64,e+=64,s+=64}if(i>0)for(S(l,c,a,N),u=0;u<i;u++)t[e+u]=r[s+u]^l[u];return 0}function m(t,e,r,s,i){var n,a,o=new Uint8Array(16),u=new Uint8Array(64);for(a=0;a<16;a++)o[a]=0;for(a=0;a<8;a++)o[a]=s[a];for(;r>=64;){for(S(u,o,i,N),a=0;a<64;a++)t[e+a]=u[a];for(n=1,a=8;a<16;a++)n=n+(255&o[a])|0,o[a]=255&n,n>>>=8;r-=64,e+=64}if(r>0)for(S(u,o,i,N),a=0;a<r;a++)t[e+a]=u[a];return 0}function A(t,e,r,s,i){var n=new Uint8Array(32);I(n,s,i,N);for(var a=new Uint8Array(8),o=0;o<8;o++)a[o]=s[o+16];return m(t,e,r,a,n)}function v(t,e,r,s,i,n,a){var o=new Uint8Array(32);I(o,n,a,N);for(var u=new Uint8Array(8),c=0;c<8;c++)u[c]=n[c+16];return b(t,e,r,s,i,u,o)}var T=function(t){var e,r,s,i,n,a,o,u;this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0,e=255&t[0]|(255&t[1])<<8,this.r[0]=8191&e,r=255&t[2]|(255&t[3])<<8,this.r[1]=8191&(e>>>13|r<<3),s=255&t[4]|(255&t[5])<<8,this.r[2]=7939&(r>>>10|s<<6),i=255&t[6]|(255&t[7])<<8,this.r[3]=8191&(s>>>7|i<<9),n=255&t[8]|(255&t[9])<<8,this.r[4]=255&(i>>>4|n<<12),this.r[5]=n>>>1&8190,a=255&t[10]|(255&t[11])<<8,this.r[6]=8191&(n>>>14|a<<2),o=255&t[12]|(255&t[13])<<8,this.r[7]=8065&(a>>>11|o<<5),u=255&t[14]|(255&t[15])<<8,this.r[8]=8191&(o>>>8|u<<8),this.r[9]=u>>>5&127,this.pad[0]=255&t[16]|(255&t[17])<<8,this.pad[1]=255&t[18]|(255&t[19])<<8,this.pad[2]=255&t[20]|(255&t[21])<<8,this.pad[3]=255&t[22]|(255&t[23])<<8,this.pad[4]=255&t[24]|(255&t[25])<<8,this.pad[5]=255&t[26]|(255&t[27])<<8,this.pad[6]=255&t[28]|(255&t[29])<<8,this.pad[7]=255&t[30]|(255&t[31])<<8};function w(t,e,r,s,i,n){var a=new T(n);return a.update(r,s,i),a.finish(t,e),0}function C(t,e,r,s,i,n){var a=new Uint8Array(16);return w(a,0,r,s,i,n),p(t,e,a,0)}function R(t,e,r,s,i){var n;if(r<32)return-1;for(v(t,0,e,0,r,s,i),w(t,16,t,32,r-32,t),n=0;n<16;n++)t[n]=0;return 0}function U(t,e,r,s,i){var n,a=new Uint8Array(32);if(r<32)return-1;if(A(a,0,32,s,i),0!==C(e,16,e,32,r-32,a))return-1;for(v(t,0,e,0,r,s,i),n=0;n<32;n++)t[n]=0;return 0}function _(t,e){var r;for(r=0;r<16;r++)t[r]=0|e[r]}function P(t){var e,r,s=1;for(e=0;e<16;e++)r=t[e]+s+65535,s=Math.floor(r/65536),t[e]=r-65536*s;t[0]+=s-1+37*(s-1)}function O(t,e,r){for(var s,i=~(r-1),n=0;n<16;n++)s=i&(t[n]^e[n]),t[n]^=s,e[n]^=s}function B(t,r){var s,i,n,a=e(),o=e();for(s=0;s<16;s++)o[s]=r[s];for(P(o),P(o),P(o),i=0;i<2;i++){for(a[0]=o[0]-65517,s=1;s<15;s++)a[s]=o[s]-65535-(a[s-1]>>16&1),a[s-1]&=65535;a[15]=o[15]-32767-(a[14]>>16&1),n=a[15]>>16&1,a[14]&=65535,O(o,a,1-n)}for(s=0;s<16;s++)t[2*s]=255&o[s],t[2*s+1]=o[s]>>8}function K(t,e){var r=new Uint8Array(32),s=new Uint8Array(32);return B(r,t),B(s,e),d(r,0,s,0)}function D(t){var e=new Uint8Array(32);return B(e,t),1&e[0]}function L(t,e){var r;for(r=0;r<16;r++)t[r]=e[2*r]+(e[2*r+1]<<8);t[15]&=32767}function x(t,e,r){for(var s=0;s<16;s++)t[s]=e[s]+r[s]}function M(t,e,r){for(var s=0;s<16;s++)t[s]=e[s]-r[s]}function k(t,e,r){var s,i,n=0,a=0,o=0,u=0,c=0,l=0,h=0,f=0,y=0,g=0,E=0,p=0,d=0,S=0,I=0,N=0,b=0,m=0,A=0,v=0,T=0,w=0,C=0,R=0,U=0,_=0,P=0,O=0,B=0,K=0,D=0,L=r[0],x=r[1],M=r[2],k=r[3],V=r[4],G=r[5],j=r[6],F=r[7],W=r[8],Y=r[9],$=r[10],z=r[11],q=r[12],Q=r[13],X=r[14],H=r[15];n+=(s=e[0])*L,a+=s*x,o+=s*M,u+=s*k,c+=s*V,l+=s*G,h+=s*j,f+=s*F,y+=s*W,g+=s*Y,E+=s*$,p+=s*z,d+=s*q,S+=s*Q,I+=s*X,N+=s*H,a+=(s=e[1])*L,o+=s*x,u+=s*M,c+=s*k,l+=s*V,h+=s*G,f+=s*j,y+=s*F,g+=s*W,E+=s*Y,p+=s*$,d+=s*z,S+=s*q,I+=s*Q,N+=s*X,b+=s*H,o+=(s=e[2])*L,u+=s*x,c+=s*M,l+=s*k,h+=s*V,f+=s*G,y+=s*j,g+=s*F,E+=s*W,p+=s*Y,d+=s*$,S+=s*z,I+=s*q,N+=s*Q,b+=s*X,m+=s*H,u+=(s=e[3])*L,c+=s*x,l+=s*M,h+=s*k,f+=s*V,y+=s*G,g+=s*j,E+=s*F,p+=s*W,d+=s*Y,S+=s*$,I+=s*z,N+=s*q,b+=s*Q,m+=s*X,A+=s*H,c+=(s=e[4])*L,l+=s*x,h+=s*M,f+=s*k,y+=s*V,g+=s*G,E+=s*j,p+=s*F,d+=s*W,S+=s*Y,I+=s*$,N+=s*z,b+=s*q,m+=s*Q,A+=s*X,v+=s*H,l+=(s=e[5])*L,h+=s*x,f+=s*M,y+=s*k,g+=s*V,E+=s*G,p+=s*j,d+=s*F,S+=s*W,I+=s*Y,N+=s*$,b+=s*z,m+=s*q,A+=s*Q,v+=s*X,T+=s*H,h+=(s=e[6])*L,f+=s*x,y+=s*M,g+=s*k,E+=s*V,p+=s*G,d+=s*j,S+=s*F,I+=s*W,N+=s*Y,b+=s*$,m+=s*z,A+=s*q,v+=s*Q,T+=s*X,w+=s*H,f+=(s=e[7])*L,y+=s*x,g+=s*M,E+=s*k,p+=s*V,d+=s*G,S+=s*j,I+=s*F,N+=s*W,b+=s*Y,m+=s*$,A+=s*z,v+=s*q,T+=s*Q,w+=s*X,C+=s*H,y+=(s=e[8])*L,g+=s*x,E+=s*M,p+=s*k,d+=s*V,S+=s*G,I+=s*j,N+=s*F,b+=s*W,m+=s*Y,A+=s*$,v+=s*z,T+=s*q,w+=s*Q,C+=s*X,R+=s*H,g+=(s=e[9])*L,E+=s*x,p+=s*M,d+=s*k,S+=s*V,I+=s*G,N+=s*j,b+=s*F,m+=s*W,A+=s*Y,v+=s*$,T+=s*z,w+=s*q,C+=s*Q,R+=s*X,U+=s*H,E+=(s=e[10])*L,p+=s*x,d+=s*M,S+=s*k,I+=s*V,N+=s*G,b+=s*j,m+=s*F,A+=s*W,v+=s*Y,T+=s*$,w+=s*z,C+=s*q,R+=s*Q,U+=s*X,_+=s*H,p+=(s=e[11])*L,d+=s*x,S+=s*M,I+=s*k,N+=s*V,b+=s*G,m+=s*j,A+=s*F,v+=s*W,T+=s*Y,w+=s*$,C+=s*z,R+=s*q,U+=s*Q,_+=s*X,P+=s*H,d+=(s=e[12])*L,S+=s*x,I+=s*M,N+=s*k,b+=s*V,m+=s*G,A+=s*j,v+=s*F,T+=s*W,w+=s*Y,C+=s*$,R+=s*z,U+=s*q,_+=s*Q,P+=s*X,O+=s*H,S+=(s=e[13])*L,I+=s*x,N+=s*M,b+=s*k,m+=s*V,A+=s*G,v+=s*j,T+=s*F,w+=s*W,C+=s*Y,R+=s*$,U+=s*z,_+=s*q,P+=s*Q,O+=s*X,B+=s*H,I+=(s=e[14])*L,N+=s*x,b+=s*M,m+=s*k,A+=s*V,v+=s*G,T+=s*j,w+=s*F,C+=s*W,R+=s*Y,U+=s*$,_+=s*z,P+=s*q,O+=s*Q,B+=s*X,K+=s*H,N+=(s=e[15])*L,a+=38*(m+=s*M),o+=38*(A+=s*k),u+=38*(v+=s*V),c+=38*(T+=s*G),l+=38*(w+=s*j),h+=38*(C+=s*F),f+=38*(R+=s*W),y+=38*(U+=s*Y),g+=38*(_+=s*$),E+=38*(P+=s*z),p+=38*(O+=s*q),d+=38*(B+=s*Q),S+=38*(K+=s*X),I+=38*(D+=s*H),n=(s=(n+=38*(b+=s*x))+(i=1)+65535)-65536*(i=Math.floor(s/65536)),a=(s=a+i+65535)-65536*(i=Math.floor(s/65536)),o=(s=o+i+65535)-65536*(i=Math.floor(s/65536)),u=(s=u+i+65535)-65536*(i=Math.floor(s/65536)),c=(s=c+i+65535)-65536*(i=Math.floor(s/65536)),l=(s=l+i+65535)-65536*(i=Math.floor(s/65536)),h=(s=h+i+65535)-65536*(i=Math.floor(s/65536)),f=(s=f+i+65535)-65536*(i=Math.floor(s/65536)),y=(s=y+i+65535)-65536*(i=Math.floor(s/65536)),g=(s=g+i+65535)-65536*(i=Math.floor(s/65536)),E=(s=E+i+65535)-65536*(i=Math.floor(s/65536)),p=(s=p+i+65535)-65536*(i=Math.floor(s/65536)),d=(s=d+i+65535)-65536*(i=Math.floor(s/65536)),S=(s=S+i+65535)-65536*(i=Math.floor(s/65536)),I=(s=I+i+65535)-65536*(i=Math.floor(s/65536)),N=(s=N+i+65535)-65536*(i=Math.floor(s/65536)),n=(s=(n+=i-1+37*(i-1))+(i=1)+65535)-65536*(i=Math.floor(s/65536)),a=(s=a+i+65535)-65536*(i=Math.floor(s/65536)),o=(s=o+i+65535)-65536*(i=Math.floor(s/65536)),u=(s=u+i+65535)-65536*(i=Math.floor(s/65536)),c=(s=c+i+65535)-65536*(i=Math.floor(s/65536)),l=(s=l+i+65535)-65536*(i=Math.floor(s/65536)),h=(s=h+i+65535)-65536*(i=Math.floor(s/65536)),f=(s=f+i+65535)-65536*(i=Math.floor(s/65536)),y=(s=y+i+65535)-65536*(i=Math.floor(s/65536)),g=(s=g+i+65535)-65536*(i=Math.floor(s/65536)),E=(s=E+i+65535)-65536*(i=Math.floor(s/65536)),p=(s=p+i+65535)-65536*(i=Math.floor(s/65536)),d=(s=d+i+65535)-65536*(i=Math.floor(s/65536)),S=(s=S+i+65535)-65536*(i=Math.floor(s/65536)),I=(s=I+i+65535)-65536*(i=Math.floor(s/65536)),N=(s=N+i+65535)-65536*(i=Math.floor(s/65536)),n+=i-1+37*(i-1),t[0]=n,t[1]=a,t[2]=o,t[3]=u,t[4]=c,t[5]=l,t[6]=h,t[7]=f,t[8]=y,t[9]=g,t[10]=E,t[11]=p,t[12]=d,t[13]=S,t[14]=I,t[15]=N}function V(t,e){k(t,e,e)}function G(t,r){var s,i=e();for(s=0;s<16;s++)i[s]=r[s];for(s=253;s>=0;s--)V(i,i),2!==s&&4!==s&&k(i,i,r);for(s=0;s<16;s++)t[s]=i[s]}function j(t,r){var s,i=e();for(s=0;s<16;s++)i[s]=r[s];for(s=250;s>=0;s--)V(i,i),1!==s&&k(i,i,r);for(s=0;s<16;s++)t[s]=i[s]}function F(t,r,s){var i,n,a=new Uint8Array(32),o=new Float64Array(80),c=e(),l=e(),h=e(),f=e(),y=e(),g=e();for(n=0;n<31;n++)a[n]=r[n];for(a[31]=127&r[31]|64,a[0]&=248,L(o,s),n=0;n<16;n++)l[n]=o[n],f[n]=c[n]=h[n]=0;for(c[0]=f[0]=1,n=254;n>=0;--n)O(c,l,i=a[n>>>3]>>>(7&n)&1),O(h,f,i),x(y,c,h),M(c,c,h),x(h,l,f),M(l,l,f),V(f,y),V(g,c),k(c,h,c),k(h,l,y),x(y,c,h),M(c,c,h),V(l,c),M(h,f,g),k(c,h,u),x(c,c,f),k(h,h,c),k(c,f,g),k(f,l,o),V(l,y),O(c,l,i),O(h,f,i);for(n=0;n<16;n++)o[n+16]=c[n],o[n+32]=h[n],o[n+48]=l[n],o[n+64]=f[n];var E=o.subarray(32),p=o.subarray(16);return G(E,E),k(p,p,E),B(t,p),0}function W(t,e){return F(t,e,i)}function Y(t,e){return r(e,32),W(t,e)}function $(t,e,r){var i=new Uint8Array(32);return F(i,r,e),I(t,s,i,N)}T.prototype.blocks=function(t,e,r){for(var s,i,n,a,o,u,c,l,h,f,y,g,E,p,d,S,I,N,b,m=this.fin?0:2048,A=this.h[0],v=this.h[1],T=this.h[2],w=this.h[3],C=this.h[4],R=this.h[5],U=this.h[6],_=this.h[7],P=this.h[8],O=this.h[9],B=this.r[0],K=this.r[1],D=this.r[2],L=this.r[3],x=this.r[4],M=this.r[5],k=this.r[6],V=this.r[7],G=this.r[8],j=this.r[9];r>=16;)f=h=0,f+=(A+=8191&(s=255&t[e+0]|(255&t[e+1])<<8))*B,f+=(v+=8191&(s>>>13|(i=255&t[e+2]|(255&t[e+3])<<8)<<3))*(5*j),f+=(T+=8191&(i>>>10|(n=255&t[e+4]|(255&t[e+5])<<8)<<6))*(5*G),f+=(w+=8191&(n>>>7|(a=255&t[e+6]|(255&t[e+7])<<8)<<9))*(5*V),h=(f+=(C+=8191&(a>>>4|(o=255&t[e+8]|(255&t[e+9])<<8)<<12))*(5*k))>>>13,f&=8191,f+=(R+=o>>>1&8191)*(5*M),f+=(U+=8191&(o>>>14|(u=255&t[e+10]|(255&t[e+11])<<8)<<2))*(5*x),f+=(_+=8191&(u>>>11|(c=255&t[e+12]|(255&t[e+13])<<8)<<5))*(5*L),f+=(P+=8191&(c>>>8|(l=255&t[e+14]|(255&t[e+15])<<8)<<8))*(5*D),y=h+=(f+=(O+=l>>>5|m)*(5*K))>>>13,y+=A*K,y+=v*B,y+=T*(5*j),y+=w*(5*G),h=(y+=C*(5*V))>>>13,y&=8191,y+=R*(5*k),y+=U*(5*M),y+=_*(5*x),y+=P*(5*L),h+=(y+=O*(5*D))>>>13,y&=8191,g=h,g+=A*D,g+=v*K,g+=T*B,g+=w*(5*j),h=(g+=C*(5*G))>>>13,g&=8191,g+=R*(5*V),g+=U*(5*k),g+=_*(5*M),g+=P*(5*x),E=h+=(g+=O*(5*L))>>>13,E+=A*L,E+=v*D,E+=T*K,E+=w*B,h=(E+=C*(5*j))>>>13,E&=8191,E+=R*(5*G),E+=U*(5*V),E+=_*(5*k),E+=P*(5*M),p=h+=(E+=O*(5*x))>>>13,p+=A*x,p+=v*L,p+=T*D,p+=w*K,h=(p+=C*B)>>>13,p&=8191,p+=R*(5*j),p+=U*(5*G),p+=_*(5*V),p+=P*(5*k),d=h+=(p+=O*(5*M))>>>13,d+=A*M,d+=v*x,d+=T*L,d+=w*D,h=(d+=C*K)>>>13,d&=8191,d+=R*B,d+=U*(5*j),d+=_*(5*G),d+=P*(5*V),S=h+=(d+=O*(5*k))>>>13,S+=A*k,S+=v*M,S+=T*x,S+=w*L,h=(S+=C*D)>>>13,S&=8191,S+=R*K,S+=U*B,S+=_*(5*j),S+=P*(5*G),I=h+=(S+=O*(5*V))>>>13,I+=A*V,I+=v*k,I+=T*M,I+=w*x,h=(I+=C*L)>>>13,I&=8191,I+=R*D,I+=U*K,I+=_*B,I+=P*(5*j),N=h+=(I+=O*(5*G))>>>13,N+=A*G,N+=v*V,N+=T*k,N+=w*M,h=(N+=C*x)>>>13,N&=8191,N+=R*L,N+=U*D,N+=_*K,N+=P*B,b=h+=(N+=O*(5*j))>>>13,b+=A*j,b+=v*G,b+=T*V,b+=w*k,h=(b+=C*M)>>>13,b&=8191,b+=R*x,b+=U*L,b+=_*D,b+=P*K,A=f=8191&(h=(h=((h+=(b+=O*B)>>>13)<<2)+h|0)+(f&=8191)|0),v=y+=h>>>=13,T=g&=8191,w=E&=8191,C=p&=8191,R=d&=8191,U=S&=8191,_=I&=8191,P=N&=8191,O=b&=8191,e+=16,r-=16;this.h[0]=A,this.h[1]=v,this.h[2]=T,this.h[3]=w,this.h[4]=C,this.h[5]=R,this.h[6]=U,this.h[7]=_,this.h[8]=P,this.h[9]=O},T.prototype.finish=function(t,e){var r,s,i,n,a=new Uint16Array(10);if(this.leftover){for(n=this.leftover,this.buffer[n++]=1;n<16;n++)this.buffer[n]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(r=this.h[1]>>>13,this.h[1]&=8191,n=2;n<10;n++)this.h[n]+=r,r=this.h[n]>>>13,this.h[n]&=8191;for(this.h[0]+=5*r,r=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=r,r=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=r,a[0]=this.h[0]+5,r=a[0]>>>13,a[0]&=8191,n=1;n<10;n++)a[n]=this.h[n]+r,r=a[n]>>>13,a[n]&=8191;for(a[9]-=8192,s=(1^r)-1,n=0;n<10;n++)a[n]&=s;for(s=~s,n=0;n<10;n++)this.h[n]=this.h[n]&s|a[n];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),i=this.h[0]+this.pad[0],this.h[0]=65535&i,n=1;n<8;n++)i=(this.h[n]+this.pad[n]|0)+(i>>>16)|0,this.h[n]=65535&i;t[e+0]=this.h[0]>>>0&255,t[e+1]=this.h[0]>>>8&255,t[e+2]=this.h[1]>>>0&255,t[e+3]=this.h[1]>>>8&255,t[e+4]=this.h[2]>>>0&255,t[e+5]=this.h[2]>>>8&255,t[e+6]=this.h[3]>>>0&255,t[e+7]=this.h[3]>>>8&255,t[e+8]=this.h[4]>>>0&255,t[e+9]=this.h[4]>>>8&255,t[e+10]=this.h[5]>>>0&255,t[e+11]=this.h[5]>>>8&255,t[e+12]=this.h[6]>>>0&255,t[e+13]=this.h[6]>>>8&255,t[e+14]=this.h[7]>>>0&255,t[e+15]=this.h[7]>>>8&255},T.prototype.update=function(t,e,r){var s,i;if(this.leftover){for((i=16-this.leftover)>r&&(i=r),s=0;s<i;s++)this.buffer[this.leftover+s]=t[e+s];if(r-=i,e+=i,this.leftover+=i,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(r>=16&&(i=r-r%16,this.blocks(t,e,i),e+=i,r-=i),r){for(s=0;s<r;s++)this.buffer[this.leftover+s]=t[e+s];this.leftover+=r}};var z=R,q=U,Q=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function X(t,e,r,s){for(var i,n,a,o,u,c,l,h,f,y,g,E,p,d,S,I,N,b,m,A,v,T,w,C,R,U,_=new Int32Array(16),P=new Int32Array(16),O=t[0],B=t[1],K=t[2],D=t[3],L=t[4],x=t[5],M=t[6],k=t[7],V=e[0],G=e[1],j=e[2],F=e[3],W=e[4],Y=e[5],$=e[6],z=e[7],q=0;s>=128;){for(m=0;m<16;m++)A=8*m+q,_[m]=r[A+0]<<24|r[A+1]<<16|r[A+2]<<8|r[A+3],P[m]=r[A+4]<<24|r[A+5]<<16|r[A+6]<<8|r[A+7];for(m=0;m<80;m++)if(i=O,n=B,a=K,o=D,u=L,c=x,l=M,f=V,y=G,g=j,E=F,p=W,d=Y,S=$,w=65535&(T=z),C=T>>>16,R=65535&(v=k),U=v>>>16,w+=65535&(T=(W>>>14|L<<18)^(W>>>18|L<<14)^(L>>>9|W<<23)),C+=T>>>16,R+=65535&(v=(L>>>14|W<<18)^(L>>>18|W<<14)^(W>>>9|L<<23)),U+=v>>>16,w+=65535&(T=W&Y^~W&$),C+=T>>>16,R+=65535&(v=L&x^~L&M),U+=v>>>16,w+=65535&(T=Q[2*m+1]),C+=T>>>16,R+=65535&(v=Q[2*m]),U+=v>>>16,v=_[m%16],C+=(T=P[m%16])>>>16,R+=65535&v,U+=v>>>16,R+=(C+=(w+=65535&T)>>>16)>>>16,w=65535&(T=b=65535&w|C<<16),C=T>>>16,R=65535&(v=N=65535&R|(U+=R>>>16)<<16),U=v>>>16,w+=65535&(T=(V>>>28|O<<4)^(O>>>2|V<<30)^(O>>>7|V<<25)),C+=T>>>16,R+=65535&(v=(O>>>28|V<<4)^(V>>>2|O<<30)^(V>>>7|O<<25)),U+=v>>>16,C+=(T=V&G^V&j^G&j)>>>16,R+=65535&(v=O&B^O&K^B&K),U+=v>>>16,h=65535&(R+=(C+=(w+=65535&T)>>>16)>>>16)|(U+=R>>>16)<<16,I=65535&w|C<<16,w=65535&(T=E),C=T>>>16,R=65535&(v=o),U=v>>>16,C+=(T=b)>>>16,R+=65535&(v=N),U+=v>>>16,B=i,K=n,D=a,L=o=65535&(R+=(C+=(w+=65535&T)>>>16)>>>16)|(U+=R>>>16)<<16,x=u,M=c,k=l,O=h,G=f,j=y,F=g,W=E=65535&w|C<<16,Y=p,$=d,z=S,V=I,m%16==15)for(A=0;A<16;A++)v=_[A],w=65535&(T=P[A]),C=T>>>16,R=65535&v,U=v>>>16,v=_[(A+9)%16],w+=65535&(T=P[(A+9)%16]),C+=T>>>16,R+=65535&v,U+=v>>>16,N=_[(A+1)%16],w+=65535&(T=((b=P[(A+1)%16])>>>1|N<<31)^(b>>>8|N<<24)^(b>>>7|N<<25)),C+=T>>>16,R+=65535&(v=(N>>>1|b<<31)^(N>>>8|b<<24)^N>>>7),U+=v>>>16,N=_[(A+14)%16],C+=(T=((b=P[(A+14)%16])>>>19|N<<13)^(N>>>29|b<<3)^(b>>>6|N<<26))>>>16,R+=65535&(v=(N>>>19|b<<13)^(b>>>29|N<<3)^N>>>6),U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,_[A]=65535&R|U<<16,P[A]=65535&w|C<<16;w=65535&(T=V),C=T>>>16,R=65535&(v=O),U=v>>>16,v=t[0],C+=(T=e[0])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[0]=O=65535&R|U<<16,e[0]=V=65535&w|C<<16,w=65535&(T=G),C=T>>>16,R=65535&(v=B),U=v>>>16,v=t[1],C+=(T=e[1])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[1]=B=65535&R|U<<16,e[1]=G=65535&w|C<<16,w=65535&(T=j),C=T>>>16,R=65535&(v=K),U=v>>>16,v=t[2],C+=(T=e[2])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[2]=K=65535&R|U<<16,e[2]=j=65535&w|C<<16,w=65535&(T=F),C=T>>>16,R=65535&(v=D),U=v>>>16,v=t[3],C+=(T=e[3])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[3]=D=65535&R|U<<16,e[3]=F=65535&w|C<<16,w=65535&(T=W),C=T>>>16,R=65535&(v=L),U=v>>>16,v=t[4],C+=(T=e[4])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[4]=L=65535&R|U<<16,e[4]=W=65535&w|C<<16,w=65535&(T=Y),C=T>>>16,R=65535&(v=x),U=v>>>16,v=t[5],C+=(T=e[5])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[5]=x=65535&R|U<<16,e[5]=Y=65535&w|C<<16,w=65535&(T=$),C=T>>>16,R=65535&(v=M),U=v>>>16,v=t[6],C+=(T=e[6])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[6]=M=65535&R|U<<16,e[6]=$=65535&w|C<<16,w=65535&(T=z),C=T>>>16,R=65535&(v=k),U=v>>>16,v=t[7],C+=(T=e[7])>>>16,R+=65535&v,U+=v>>>16,U+=(R+=(C+=(w+=65535&T)>>>16)>>>16)>>>16,t[7]=k=65535&R|U<<16,e[7]=z=65535&w|C<<16,q+=128,s-=128}return s}function H(t,e,r){var s,i=new Int32Array(8),n=new Int32Array(8),a=new Uint8Array(256),o=r;for(i[0]=1779033703,i[1]=3144134277,i[2]=1013904242,i[3]=2773480762,i[4]=1359893119,i[5]=2600822924,i[6]=528734635,i[7]=1541459225,n[0]=4089235720,n[1]=2227873595,n[2]=4271175723,n[3]=1595750129,n[4]=2917565137,n[5]=725511199,n[6]=4215389547,n[7]=327033209,X(i,n,e,r),r%=128,s=0;s<r;s++)a[s]=e[o-r+s];for(a[r]=128,a[(r=256-128*(r<112?1:0))-9]=0,g(a,r-8,o/536870912|0,o<<3),X(i,n,a,r),s=0;s<8;s++)g(t,8*s,i[s],n[s]);return 0}function J(t,r){var s=e(),i=e(),n=e(),a=e(),o=e(),u=e(),c=e(),h=e(),f=e();M(s,t[1],t[0]),M(f,r[1],r[0]),k(s,s,f),x(i,t[0],t[1]),x(f,r[0],r[1]),k(i,i,f),k(n,t[3],r[3]),k(n,n,l),k(a,t[2],r[2]),x(a,a,a),M(o,i,s),M(u,a,n),x(c,a,n),x(h,i,s),k(t[0],o,u),k(t[1],h,c),k(t[2],c,u),k(t[3],o,h)}function Z(t,e,r){var s;for(s=0;s<4;s++)O(t[s],e[s],r)}function tt(t,r){var s=e(),i=e(),n=e();G(n,r[2]),k(s,r[0],n),k(i,r[1],n),B(t,i),t[31]^=D(s)<<7}function et(t,e,r){var s,i;for(_(t[0],n),_(t[1],o),_(t[2],o),_(t[3],n),i=255;i>=0;--i)Z(t,e,s=r[i/8|0]>>(7&i)&1),J(e,t),J(t,t),Z(t,e,s)}function rt(t,r){var s=[e(),e(),e(),e()];_(s[0],h),_(s[1],f),_(s[2],o),k(s[3],h,f),et(t,s,r)}function st(t,s,i){var n,a=new Uint8Array(64),o=[e(),e(),e(),e()];for(i||r(s,32),H(a,s,32),a[0]&=248,a[31]&=127,a[31]|=64,rt(o,a),tt(t,o),n=0;n<32;n++)s[n+32]=t[n];return 0}var it=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function nt(t,e){var r,s,i,n;for(s=63;s>=32;--s){for(r=0,i=s-32,n=s-12;i<n;++i)e[i]+=r-16*e[s]*it[i-(s-32)],r=Math.floor((e[i]+128)/256),e[i]-=256*r;e[i]+=r,e[s]=0}for(r=0,i=0;i<32;i++)e[i]+=r-(e[31]>>4)*it[i],r=e[i]>>8,e[i]&=255;for(i=0;i<32;i++)e[i]-=r*it[i];for(s=0;s<32;s++)e[s+1]+=e[s]>>8,t[s]=255&e[s]}function at(t){var e,r=new Float64Array(64);for(e=0;e<64;e++)r[e]=t[e];for(e=0;e<64;e++)t[e]=0;nt(t,r)}function ot(t,r,s,i){var n,a,o=new Uint8Array(64),u=new Uint8Array(64),c=new Uint8Array(64),l=new Float64Array(64),h=[e(),e(),e(),e()];H(o,i,32),o[0]&=248,o[31]&=127,o[31]|=64;var f=s+64;for(n=0;n<s;n++)t[64+n]=r[n];for(n=0;n<32;n++)t[32+n]=o[32+n];for(H(c,t.subarray(32),s+32),at(c),rt(h,c),tt(t,h),n=32;n<64;n++)t[n]=i[n];for(H(u,t,s+64),at(u),n=0;n<64;n++)l[n]=0;for(n=0;n<32;n++)l[n]=c[n];for(n=0;n<32;n++)for(a=0;a<32;a++)l[n+a]+=u[n]*o[a];return nt(t.subarray(32),l),f}function ut(t,r,s,i){var a,u=new Uint8Array(32),l=new Uint8Array(64),h=[e(),e(),e(),e()],f=[e(),e(),e(),e()];if(s<64)return-1;if(function(t,r){var s=e(),i=e(),a=e(),u=e(),l=e(),h=e(),f=e();return _(t[2],o),L(t[1],r),V(a,t[1]),k(u,a,c),M(a,a,t[2]),x(u,t[2],u),V(l,u),V(h,l),k(f,h,l),k(s,f,a),k(s,s,u),j(s,s),k(s,s,a),k(s,s,u),k(s,s,u),k(t[0],s,u),V(i,t[0]),k(i,i,u),K(i,a)&&k(t[0],t[0],y),V(i,t[0]),k(i,i,u),K(i,a)?-1:(D(t[0])===r[31]>>7&&M(t[0],n,t[0]),k(t[3],t[0],t[1]),0)}(f,i))return-1;for(a=0;a<s;a++)t[a]=r[a];for(a=0;a<32;a++)t[a+32]=i[a];if(H(l,t,s),at(l),et(h,f,l),rt(f,r.subarray(32)),J(h,f),tt(u,h),s-=64,d(r,0,u,0)){for(a=0;a<s;a++)t[a]=0;return-1}for(a=0;a<s;a++)t[a]=r[a+64];return s}var ct,lt=16,ht=64,ft=32,yt=64;function gt(t,e){if(32!==t.length)throw new Error("bad key size");if(24!==e.length)throw new Error("bad nonce size")}function Et(){for(var t=0;t<arguments.length;t++)if(!(arguments[t]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function pt(t){for(var e=0;e<t.length;e++)t[e]=0}t.lowlevel={crypto_core_hsalsa20:I,crypto_stream_xor:v,crypto_stream:A,crypto_stream_salsa20_xor:b,crypto_stream_salsa20:m,crypto_onetimeauth:w,crypto_onetimeauth_verify:C,crypto_verify_16:p,crypto_verify_32:d,crypto_secretbox:R,crypto_secretbox_open:U,crypto_scalarmult:F,crypto_scalarmult_base:W,crypto_box_beforenm:$,crypto_box_afternm:z,crypto_box:function(t,e,r,s,i,n){var a=new Uint8Array(32);return $(a,i,n),z(t,e,r,s,a)},crypto_box_open:function(t,e,r,s,i,n){var a=new Uint8Array(32);return $(a,i,n),q(t,e,r,s,a)},crypto_box_keypair:Y,crypto_hash:H,crypto_sign:ot,crypto_sign_keypair:st,crypto_sign_open:ut,crypto_secretbox_KEYBYTES:32,crypto_secretbox_NONCEBYTES:24,crypto_secretbox_ZEROBYTES:32,crypto_secretbox_BOXZEROBYTES:lt,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_box_PUBLICKEYBYTES:32,crypto_box_SECRETKEYBYTES:32,crypto_box_BEFORENMBYTES:32,crypto_box_NONCEBYTES:24,crypto_box_ZEROBYTES:32,crypto_box_BOXZEROBYTES:16,crypto_sign_BYTES:ht,crypto_sign_PUBLICKEYBYTES:ft,crypto_sign_SECRETKEYBYTES:yt,crypto_sign_SEEDBYTES:32,crypto_hash_BYTES:64,gf:e,D:c,L:it,pack25519:B,unpack25519:L,M:k,A:x,S:V,Z:M,pow2523:j,add:J,set25519:_,modL:nt,scalarmult:et,scalarbase:rt},t.randomBytes=function(t){var e=new Uint8Array(t);return r(e,t),e},t.secretbox=function(t,e,r){Et(t,e,r),gt(r,e);for(var s=new Uint8Array(32+t.length),i=new Uint8Array(s.length),n=0;n<t.length;n++)s[n+32]=t[n];return R(i,s,s.length,e,r),i.subarray(lt)},t.secretbox.open=function(t,e,r){Et(t,e,r),gt(r,e);for(var s=new Uint8Array(lt+t.length),i=new Uint8Array(s.length),n=0;n<t.length;n++)s[n+lt]=t[n];return s.length<32||0!==U(i,s,s.length,e,r)?null:i.subarray(32)},t.secretbox.keyLength=32,t.secretbox.nonceLength=24,t.secretbox.overheadLength=lt,t.scalarMult=function(t,e){if(Et(t,e),32!==t.length)throw new Error("bad n size");if(32!==e.length)throw new Error("bad p size");var r=new Uint8Array(32);return F(r,t,e),r},t.scalarMult.base=function(t){if(Et(t),32!==t.length)throw new Error("bad n size");var e=new Uint8Array(32);return W(e,t),e},t.scalarMult.scalarLength=32,t.scalarMult.groupElementLength=32,t.box=function(e,r,s,i){var n=t.box.before(s,i);return t.secretbox(e,r,n)},t.box.before=function(t,e){Et(t,e),function(t,e){if(32!==t.length)throw new Error("bad public key size");if(32!==e.length)throw new Error("bad secret key size")}(t,e);var r=new Uint8Array(32);return $(r,t,e),r},t.box.after=t.secretbox,t.box.open=function(e,r,s,i){var n=t.box.before(s,i);return t.secretbox.open(e,r,n)},t.box.open.after=t.secretbox.open,t.box.keyPair=function(){var t=new Uint8Array(32),e=new Uint8Array(32);return Y(t,e),{publicKey:t,secretKey:e}},t.box.keyPair.fromSecretKey=function(t){if(Et(t),32!==t.length)throw new Error("bad secret key size");var e=new Uint8Array(32);return W(e,t),{publicKey:e,secretKey:new Uint8Array(t)}},t.box.publicKeyLength=32,t.box.secretKeyLength=32,t.box.sharedKeyLength=32,t.box.nonceLength=24,t.box.overheadLength=t.secretbox.overheadLength,t.sign=function(t,e){if(Et(t,e),e.length!==yt)throw new Error("bad secret key size");var r=new Uint8Array(ht+t.length);return ot(r,t,t.length,e),r},t.sign.open=function(t,e){if(Et(t,e),e.length!==ft)throw new Error("bad public key size");var r=new Uint8Array(t.length),s=ut(r,t,t.length,e);if(s<0)return null;for(var i=new Uint8Array(s),n=0;n<i.length;n++)i[n]=r[n];return i},t.sign.detached=function(e,r){for(var s=t.sign(e,r),i=new Uint8Array(ht),n=0;n<i.length;n++)i[n]=s[n];return i},t.sign.detached.verify=function(t,e,r){if(Et(t,e,r),e.length!==ht)throw new Error("bad signature size");if(r.length!==ft)throw new Error("bad public key size");var s,i=new Uint8Array(ht+t.length),n=new Uint8Array(ht+t.length);for(s=0;s<ht;s++)i[s]=e[s];for(s=0;s<t.length;s++)i[s+ht]=t[s];return ut(n,i,i.length,r)>=0},t.sign.keyPair=function(){var t=new Uint8Array(ft),e=new Uint8Array(yt);return st(t,e),{publicKey:t,secretKey:e}},t.sign.keyPair.fromSecretKey=function(t){if(Et(t),t.length!==yt)throw new Error("bad secret key size");for(var e=new Uint8Array(ft),r=0;r<e.length;r++)e[r]=t[32+r];return{publicKey:e,secretKey:new Uint8Array(t)}},t.sign.keyPair.fromSeed=function(t){if(Et(t),32!==t.length)throw new Error("bad seed size");for(var e=new Uint8Array(ft),r=new Uint8Array(yt),s=0;s<32;s++)r[s]=t[s];return st(e,r,!0),{publicKey:e,secretKey:r}},t.sign.publicKeyLength=ft,t.sign.secretKeyLength=yt,t.sign.seedLength=32,t.sign.signatureLength=ht,t.hash=function(t){Et(t);var e=new Uint8Array(64);return H(e,t,t.length),e},t.hash.hashLength=64,t.verify=function(t,e){return Et(t,e),0!==t.length&&0!==e.length&&t.length===e.length&&0===E(t,0,e,0,t.length)},t.setPRNG=function(t){r=t},(ct=null)&&ct.getRandomValues?t.setPRNG((function(t,e){var r,s=new Uint8Array(e);for(r=0;r<e;r+=65536)ct.getRandomValues(s.subarray(r,r+Math.min(e-r,65536)));for(r=0;r<e;r++)t[r]=s[r];pt(s)})):(ct=a.default)&&ct.randomBytes&&t.setPRNG((function(t,e){var r,s=ct.randomBytes(e);for(r=0;r<e;r++)t[r]=s[r];pt(s)}))}(g.exports?g.exports:self.nacl=self.nacl||{});var E={},p={};Object.defineProperty(p,"__esModule",{value:!0});p.BufferVisitor=class{constructor(t,e=0,r=0){this.start=e,this.end=r>e?r:e,this.buf=t}get length(){return this.buf.length}reset(t=0,e=0){return this.start=t,e>=this.start?this.end=e:this.end<this.start&&(this.end=this.start),this}walk(t){return this.start=this.end,this.end+=t,this}mustHas(t,e="Too few bytes to parse."){const r=this.end+t;if(r>this.buf.length){const t=new Error(e);throw t.available=this.buf.length,t.requested=r,t}return this.walk(0),this}mustWalk(t,e){return this.mustHas(t,e),this.walk(t),this}};var d={};Object.defineProperty(d,"__esModule",{value:!0});const S=n.default;class I{static parse(t){const e=[],r=t.toString("utf8").split("\n").map((t=>t.trim())).filter((t=>""!==t&&!t.startsWith("#")));for(;r.length>0;)e.push(N(r));if(0===e.length)throw new Error("PEM: no block");return e}constructor(t,e){this.type=t,this.body=e,this.headers=Object.create(null)}get procType(){return this.getHeader("Proc-Type")}getHeader(t){const e=this.headers[t];return null==e?"":e}setHeader(t,e){if(t.includes(":"))throw new Error("pem: cannot encode a header key that contains a colon");if(""===t||""===e)throw new Error("pem: invalid header key or value");this.headers[t]=e}toString(){let t="-----BEGIN "+this.type+"-----\n";const e=Object.keys(this.headers);if(e.length>0){const r=this.procType;""!==r&&(t+=`Proc-Type: ${r}\n`),e.sort();for(const r of e)"Proc-Type"!==r&&(t+=`${r}: ${this.headers[r]}\n`);t+="\n"}const r=this.body.toString("base64");let s=0;for(;s<r.length;)t+=r.slice(s,s+64)+"\n",s+=64;return t+="-----END "+this.type+"-----\n",t}toBuffer(){return Buffer.from(this.toString(),"utf8")}valueOf(){return this.body}toJSON(){return{type:this.type,body:this.body,headers:this.headers}}[S.inspect.custom](t,e){return`<${this.constructor.name} ${S.inspect(this.toJSON(),e)}>`}}function N(t){let e=t.shift();if(null==e||!e.startsWith("-----BEGIN ")||!e.endsWith("-----"))throw new Error("pem: invalid BEGIN line");const r=e.slice("-----BEGIN ".length,e.length-"-----".length);if(""===r)throw new Error("pem: invalid type");const s=[];for(e=t.shift();null!=e&&e.includes(": ");){const r=e.split(": ");if(2!==r.length||""===r[0]||""===r[1])throw new Error("pem: invalid Header line");s.push(r),e=t.shift()}let i="";for(;null!=e&&!e.startsWith("-----END ");)i+=e,e=t.shift();if(null==e||e!==`-----END ${r}-----`)throw new Error("pem: invalid END line");const n=new I(r,Buffer.from(i,"base64"));if(""===i||n.body.toString("base64")!==i)throw new Error("pem: invalid base64 body");for(const t of s)n.setHeader(t[0],t[1]);return n}d.PEM=I;var b={};!function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=n.default,r=p;var s,i;!function(t){t[t.UNIVERSAL=0]="UNIVERSAL",t[t.APPLICATION=64]="APPLICATION",t[t.CONTEXT_SPECIFIC=128]="CONTEXT_SPECIFIC",t[t.PRIVATE=192]="PRIVATE"}(s=t.Class||(t.Class={})),function(t){t[t.NONE=0]="NONE",t[t.BOOLEAN=1]="BOOLEAN",t[t.INTEGER=2]="INTEGER",t[t.BITSTRING=3]="BITSTRING",t[t.OCTETSTRING=4]="OCTETSTRING",t[t.NULL=5]="NULL",t[t.OID=6]="OID",t[t.ENUMERATED=10]="ENUMERATED",t[t.UTF8=12]="UTF8",t[t.SEQUENCE=16]="SEQUENCE",t[t.SET=17]="SET",t[t.NUMERICSTRING=18]="NUMERICSTRING",t[t.PRINTABLESTRING=19]="PRINTABLESTRING",t[t.T61STRING=20]="T61STRING",t[t.IA5STRING=22]="IA5STRING",t[t.UTCTIME=23]="UTCTIME",t[t.GENERALIZEDTIME=24]="GENERALIZEDTIME",t[t.GENERALSTRING=27]="GENERALSTRING"}(i=t.Tag||(t.Tag={}));class a{constructor(t,e){this.buf=t,this.bitLen=e}at(t){if(t<0||t>=this.bitLen||!Number.isInteger(t))return 0;const e=Math.floor(t/8),r=7-t%8;return this.buf[e]>>r&1}rightAlign(){const t=8-this.bitLen%8;if(8===t||0===this.buf.length)return this.buf;const e=Buffer.alloc(this.buf.length);e[0]=this.buf[0]>>t;for(let r=1;r<this.buf.length;r++)e[r]=this.buf[r-1]<<8-t,e[r]|=this.buf[r]>>t;return e}}t.BitString=a;class o{static Bool(t){const e=new o(s.UNIVERSAL,i.BOOLEAN,Buffer.from([t?255:0]));return e._value=t,e}static parseBool(t){if(!(t instanceof Buffer)||1!==t.length)throw new Error("ASN1 syntax error: invalid boolean");switch(t[0]){case 0:return!1;case 255:return!0;default:throw new Error("ASN1 syntax error: invalid boolean")}}static Integer(t){if(t instanceof Buffer){const e=new o(s.UNIVERSAL,i.INTEGER,t);return e._value=t.toString("hex"),e}if(!Number.isSafeInteger(t))throw new Error("ASN1 syntax error: invalid integer");let e;if(t>=-128&&t<128)e=Buffer.alloc(1),e.writeInt8(t,0);else if(t>=-32768&&t<32768)e=Buffer.alloc(2),e.writeIntBE(t,0,2);else if(t>=-8388608&&t<8388608)e=Buffer.alloc(3),e.writeIntBE(t,0,3);else if(t>=-2147483648&&t<2147483648)e=Buffer.alloc(4),e.writeIntBE(t,0,4);else if(t>=-549755813888&&t<549755813888)e=Buffer.alloc(5),e.writeIntBE(t,0,5);else{if(!(t>=-0x800000000000&&t<0x800000000000))throw new Error("ASN1 syntax error: invalid Integer");e=Buffer.alloc(6),e.writeIntBE(t,0,6)}const r=new o(s.UNIVERSAL,i.INTEGER,e);return r._value=t,r}static parseInteger(t){if(!(t instanceof Buffer)||0===t.length)throw new Error("ASN1 syntax error: invalid Integer");return t.length>6?t.toString("hex"):t.readIntBE(0,t.length)}static parseIntegerNum(t){const e=o.parseInteger(t);if("number"!=typeof e)throw new Error("ASN1 syntax error: invalid Integer number");return e}static parseIntegerStr(t){const e=o.parseInteger(t);return"number"==typeof e?e.toString(16):e}static BitString(t){t instanceof Buffer&&(t=new a(t,8*t.length));const e=8*t.buf.length-t.bitLen,r=Buffer.alloc(t.buf.length+1);return r.writeInt8(e,0),t.buf.copy(r,1),new o(s.UNIVERSAL,i.BITSTRING,r)}static parseBitString(t){if(!(t instanceof Buffer)||0===t.length)throw new Error("ASN1 syntax error: invalid BitString");const e=t[0];if(e>7||1===t.length&&e>0||0!=(t[t.length-1]&(1<<t[0])-1))throw new Error("ASN1 syntax error: invalid padding bits in BIT STRING");return new a(t.slice(1),8*(t.length-1)-e)}static Null(){const t=new o(s.UNIVERSAL,i.NULL,Buffer.alloc(0));return t._value=null,t}static parseNull(t){if(!(t instanceof Buffer)||0!==t.length)throw new Error("ASN1 syntax error: invalid null");return null}static OID(t){const e=t.split(".");if(0===e.length)throw new Error("ASN1 syntax error: invalid Object Identifier");const r=[];r.push(40*l(e[0])+l(e[1]));const n=[];for(let t=2;t<e.length;++t){let s=l(e[t]);for(n.length=0,n.push(127&s);s>127;)s>>>=7,n.unshift(127&s|128);r.push(...n)}const a=new o(s.UNIVERSAL,i.OID,Buffer.from(r));return a._value=t,a}static parseOID(t){if(!(t instanceof Buffer)||0===t.length)throw new Error("ASN1 syntax error: invalid OID");let e=Math.floor(t[0]/40)+"."+t[0]%40,r=0;for(let s=1;s<t.length;s++)t[s]>=128?(r+=127&t[s],r<<=7):(e+="."+(r+t[s]),r=0);return e}static UTF8(t){const e=new o(s.UNIVERSAL,i.UTF8,Buffer.from(t,"utf8"));return e._value=t,e}static parseUTF8(t){if(!(t instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return t.toString("utf8")}static NumericString(t){if(!u(t))throw new Error("ASN1 syntax error: invalid NumericString");const e=new o(s.UNIVERSAL,i.NUMERICSTRING,Buffer.from(t,"utf8"));return e._value=t,e}static parseNumericString(t){if(!(t instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");const e=t.toString("utf8");if(!u(e))throw new Error("ASN1 syntax error: invalid NumericString");return e}static PrintableString(t){const e=new o(s.UNIVERSAL,i.PRINTABLESTRING,Buffer.from(t,"utf8"));return e._value=t,e}static parsePrintableString(t){if(!(t instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return t.toString("utf8")}static IA5String(t){if(!c(t))throw new Error("ASN1 syntax error: invalid IA5String");const e=new o(s.UNIVERSAL,i.IA5STRING,Buffer.from(t,"utf8"));return e._value=t,e}static parseIA5String(t){if(!(t instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");const e=t.toString("utf8");if(!c(e))throw new Error("ASN1 syntax error: invalid IA5String");return e}static T61String(t){const e=new o(s.UNIVERSAL,i.T61STRING,Buffer.from(t,"utf8"));return e._value=t,e}static parseT61String(t){if(!(t instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return t.toString("utf8")}static GeneralString(t){const e=new o(s.UNIVERSAL,i.GENERALSTRING,Buffer.from(t,"utf8"));return e._value=t,e}static parseGeneralString(t){if(!(t instanceof Buffer))throw new Error("parse ASN1 error: invalid Buffer");return t.toString("utf8")}static UTCTime(t){let e="";const r=[];r.push((""+t.getUTCFullYear()).substr(2)),r.push(""+(t.getUTCMonth()+1)),r.push(""+t.getUTCDate()),r.push(""+t.getUTCHours()),r.push(""+t.getUTCMinutes()),r.push(""+t.getUTCSeconds());for(const t of r)t.length<2&&(e+="0"),e+=t;e+="Z";const n=new o(s.UNIVERSAL,i.UTCTIME,Buffer.from(e,"utf8"));return n._value=t,n}static parseUTCTime(t){if(!(t instanceof Buffer)||0===t.length)throw new Error("ASN1 syntax error: invalid UTC Time");const e=t.toString("utf8"),r=new Date;let s=l(e.substr(0,2));s=s>=50?1900+s:2e3+s;const i=l(e.substr(2,2))-1,n=l(e.substr(4,2)),a=l(e.substr(6,2)),o=l(e.substr(8,2));let u=0,c=0,h="";if(e.length>11&&(c=10,h=e.charAt(c),"+"!==h&&"-"!==h&&(u=l(e.substr(10,2)),c+=2)),r.setUTCFullYear(s,i,n),r.setUTCHours(a,o,u,0),c>0&&(h=e.charAt(c),"+"===h||"-"===h)){let t=60*l(e.substr(c+1,2))+l(e.substr(c+4,2));t*=6e4,"+"===h?r.setTime(+r-t):r.setTime(+r+t)}return r}static GeneralizedTime(t){let e="";const r=[];r.push(""+t.getUTCFullYear()),r.push(""+(t.getUTCMonth()+1)),r.push(""+t.getUTCDate()),r.push(""+t.getUTCHours()),r.push(""+t.getUTCMinutes()),r.push(""+t.getUTCSeconds());for(const t of r)t.length<2&&(e+="0"),e+=t;e+="Z";const n=new o(s.UNIVERSAL,i.GENERALIZEDTIME,Buffer.from(e,"utf8"));return n._value=t,n}static parseGeneralizedTime(t){if(!(t instanceof Buffer)||0===t.length)throw new Error("ASN1 syntax error: invalid Generalized Time");const e=t.toString("utf8"),r=new Date,s=l(e.substr(0,4)),i=l(e.substr(4,2))-1,n=l(e.substr(6,2)),a=l(e.substr(8,2)),o=l(e.substr(10,2)),u=l(e.substr(12,2));let c=0,h=0,f=!1;"Z"===e.charAt(e.length-1)&&(f=!0);const y=e.length-5,g=e.charAt(y);if("+"===g||"-"===g){h=60*l(e.substr(y+1,2))+l(e.substr(y+4,2)),h*=6e4,"+"===g&&(h*=-1),f=!0}return"."===e.charAt(14)&&(c=1e3*parseFloat(e.substr(14))),f?(r.setUTCFullYear(s,i,n),r.setUTCHours(a,o,u,c),r.setTime(+r+h)):(r.setFullYear(s,i,n),r.setHours(a,o,u,c)),r}static parseTime(t,e){switch(t){case i.UTCTIME:return o.parseUTCTime(e);case i.GENERALIZEDTIME:return o.parseGeneralizedTime(e);default:throw new Error("Invalid ASN1 time tag")}}static Set(t){const e=new o(s.UNIVERSAL,i.SET,Buffer.concat(t.map((t=>t.toDER()))));return e._value=t,e}static Seq(t){const e=new o(s.UNIVERSAL,i.SEQUENCE,Buffer.concat(t.map((t=>t.toDER()))));return e._value=t,e}static Spec(t,e,r=!0){const i=Array.isArray(e)?Buffer.concat(e.map((t=>t.toDER()))):e.toDER();Array.isArray(e)&&(r=!0);const n=new o(s.CONTEXT_SPECIFIC,t,i,r);return n._value=e,n}static fromDER(t,e=!1){return o._fromDER(new r.BufferVisitor(t),e)}static parseDER(t,e,s){const i=o._fromDER(new r.BufferVisitor(t),!1);if(i.class!==e&&i.tag!==s)throw new Error(`invalid ASN.1 DER for class ${e} and tag ${s}`);return i}static parseDERWithTemplate(t,e){const s=o._fromDER(new r.BufferVisitor(t),!0),i={},n=s.validate(e,i);if(null!=n)throw n.data=s,n;return i}static _parseCompound(t,e){const s=[],i=t.length,n=new r.BufferVisitor(t);let a=0;for(;a<i;){const t=n.end;s.push(o._fromDER(n,e)),a+=n.end-t}return s}static _fromDER(t,e){if(!(t.buf instanceof Buffer)||0===t.length)throw new Error("ASN1 syntax error: invalid Generalized Time");t.mustWalk(1,"Too few bytes to read ASN.1 tag.");const r=t.start,s=t.buf[r],n=192&s,a=31&s,u=function(t){t.mustWalk(1,"Too few bytes to read ASN.1 value length.");const e=t.buf[t.start];if(0==(128&e))return e;const r=127&e;return t.mustWalk(r,"Too few bytes to read ASN.1 value length."),t.buf.readUIntBE(t.start,r)}(t);if(t.mustHas(u),0!==u&&a===i.NULL)throw new Error("invalid value length or NULL tag.");t.mustWalk(u);const c=32==(32&s),l=new o(n,a,t.buf.slice(t.start,t.end),c);return c&&e&&(l._value=o._parseCompound(l.bytes,e)),l._der=t.buf.slice(r,t.end),l}constructor(t,e,r,s=!1){this.class=t,this.tag=e,this.bytes=r,this.isCompound=s||e===i.SEQUENCE||e===i.SET,this._value=void 0,this._der=null}get value(){return void 0===this._value&&(this._value=this.valueOf()),this._value}get DER(){return null==this._der&&(this._der=this.toDER()),this._der}mustCompound(t="asn1 object value is not compound"){if(!this.isCompound||!Array.isArray(this.value)){const e=new Error(t);throw e.data=this.toJSON(),e}return this.value}equals(t){return t instanceof o&&(this.class===t.class&&this.tag===t.tag&&this.isCompound===t.isCompound&&!!this.bytes.equals(t.bytes))}toDER(){let t=this.class|this.tag;this.isCompound&&(t|=32);const e=function(t){if(t<=127)return 0;if(t<=255)return 1;if(t<=65535)return 2;if(t<=16777215)return 3;if(t<=4294967295)return 4;if(t<=0xffffffffff)return 5;if(t<=0xffffffffffff)return 6;throw new Error("invalid value length")}(this.bytes.length),r=Buffer.allocUnsafe(2+e+this.bytes.length);return r.writeInt8(t,0),0===e?(r.writeUInt8(this.bytes.length,1),this.bytes.copy(r,2)):(r.writeUInt8(128|e,1),r.writeUIntBE(this.bytes.length,2,e),this.bytes.copy(r,2+e)),r}valueOf(){if(this.isCompound)return o._parseCompound(this.bytes,!1);if(this.class!==s.UNIVERSAL)return this.bytes;switch(this.tag){case i.BOOLEAN:return o.parseBool(this.bytes);case i.INTEGER:return o.parseInteger(this.bytes);case i.BITSTRING:return o.parseBitString(this.bytes);case i.NULL:return o.parseNull(this.bytes);case i.OID:return o.parseOID(this.bytes);case i.UTF8:return o.parseUTF8(this.bytes);case i.NUMERICSTRING:return o.parseNumericString(this.bytes);case i.PRINTABLESTRING:return o.parsePrintableString(this.bytes);case i.T61STRING:return o.parseT61String(this.bytes);case i.IA5STRING:return o.parseIA5String(this.bytes);case i.GENERALSTRING:return o.parseGeneralString(this.bytes);case i.UTCTIME:return o.parseUTCTime(this.bytes);case i.GENERALIZEDTIME:return o.parseGeneralizedTime(this.bytes);default:return this.bytes}}validate(t,e={}){if(this.class!==t.class)return new Error(`ASN.1 object validate failure for ${t.name} : error class ${s[this.class]}`);if(!(Array.isArray(t.tag)?t.tag:[t.tag]).includes(this.tag))return new Error(`ASN.1 object validate failure for ${t.name}: error tag ${i[this.tag]}`);if(null!=t.capture&&(e[t.capture]=this),Array.isArray(t.value)){const r=this.mustCompound(`${t.name} need compound ASN1 value`);for(let s=0,i=0;s<t.value.length;s++)if(null!=r[i]){const n=r[i].validate(t.value[s],e);if(null==n)i++;else if(!0!==t.value[s].optional)return n}else if(!0!==t.value[s].optional)return new Error(`ASN.1 object validate failure for ${t.value[s].name}: not exists`)}else if(null!=t.value){const r=this.tag===i.BITSTRING?this.bytes.slice(1):this.bytes;return o.fromDER(r).validate(t.value,e)}return null}toJSON(){let t=this.value;return Array.isArray(t)&&(t=t.map((t=>t.toJSON()))),{class:s[this.class],tag:this.class===s.UNIVERSAL?i[this.tag]:this.tag,value:t}}[e.inspect.custom](t,r){return r.depth<=2&&(r.depth=10),`<${this.constructor.name} ${e.inspect(this.toJSON(),r)}>`}}function u(t){for(const e of t){const t=e.charCodeAt(0);if(32!==t&&(t<48||t>57))return!1}return!0}function c(t){for(const e of t)if(e.charCodeAt(0)>=128)return!1;return!0}function l(t,e=10){const r=parseInt(t,e);if(Number.isNaN(r))throw new Error(`Invalid numeric string "${t}" in radix ${e}.`);return r}t.ASN1=o}(b),Object.defineProperty(E,"__esModule",{value:!0});var m=p;E.BufferVisitor=m.BufferVisitor;var A=d;E.PEM=A.PEM;var v=b;E.ASN1=v.ASN1,E.Class=v.Class,E.Tag=v.Tag,E.BitString=v.BitString,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=n.default,r=a.default,s=g.exports,i=E,o=u;t.publicKeyValidator={name:"PublicKeyInfo",class:i.Class.UNIVERSAL,tag:i.Tag.SEQUENCE,capture:"publicKeyInfo",value:[{name:"PublicKeyInfo.AlgorithmIdentifier",class:i.Class.UNIVERSAL,tag:i.Tag.SEQUENCE,value:[{name:"PublicKeyAlgorithmIdentifier.algorithm",class:i.Class.UNIVERSAL,tag:i.Tag.OID,capture:"publicKeyOID"}]},{name:"PublicKeyInfo.PublicKey",class:i.Class.UNIVERSAL,tag:i.Tag.BITSTRING,capture:"publicKey"}]},t.privateKeyValidator={name:"PrivateKeyInfo",class:i.Class.UNIVERSAL,tag:i.Tag.SEQUENCE,capture:"privateKeyInfo",value:[{name:"PrivateKeyInfo.Version",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.AlgorithmIdentifier",class:i.Class.UNIVERSAL,tag:i.Tag.SEQUENCE,value:[{name:"PrivateKeyAlgorithmIdentifier.algorithm",class:i.Class.UNIVERSAL,tag:i.Tag.OID,capture:"privateKeyOID"}]},{name:"PrivateKeyInfo.PrivateKey",class:i.Class.UNIVERSAL,tag:i.Tag.OCTETSTRING,capture:"privateKey"}]};const c={name:"RSAPublicKey",class:i.Class.UNIVERSAL,tag:i.Tag.SEQUENCE,value:[{name:"RSAPublicKey.modulus",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"publicKeyExponent"}]},l={name:"RSAPrivateKey",class:i.Class.UNIVERSAL,tag:i.Tag.SEQUENCE,value:[{name:"RSAPrivateKey.version",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",class:i.Class.UNIVERSAL,tag:i.Tag.INTEGER,capture:"privateKeyCoefficient"}]},h=[o.getOID("X25519"),o.getOID("X448"),o.getOID("Ed25519"),o.getOID("Ed448")];class f{constructor(e){const r={},s=e.validate(t.publicKeyValidator,r);if(null!=s)throw new Error("Cannot read X.509 public key: "+s.message);this.oid=i.ASN1.parseOID(r.publicKeyOID.bytes),this.algo=o.getOIDName(this.oid),this._pkcs8=e,this._keyRaw=i.ASN1.parseBitString(r.publicKey.bytes).buf,this._finalKey=this._keyRaw,this._finalPEM=""}static fromPEM(t){const e=i.PEM.parse(t)[0];if(e.procType.includes("ENCRYPTED"))throw new Error("Could not convert public key from PEM, PEM is encrypted.");const r=i.ASN1.fromDER(e.body,!0);switch(e.type){case"PUBLIC KEY":return new f(r);case"RSA PUBLIC KEY":const t=i.ASN1.Seq([i.ASN1.Seq([i.ASN1.OID(o.getOID("rsaEncryption")),i.ASN1.Null()]),i.ASN1.BitString(r.DER)]);return new f(t);default:throw new Error("Could not convert public key from PEM, recommend PKCS#8 PEM")}}static addVerifier(t,e){if(""===(t=o.getOID(t)))throw new Error(`Invalid object identifier: ${t}`);if(null!=f._verifiers[t])throw new Error(`Verifier ${t} exists`);f._verifiers[t]=e}get keyRaw(){return this._finalKey}verify(t,e,s){const i=f._verifiers[this.oid];if(null!=i){const n=r.createHash(s).update(t).digest();return i.call(this,n,e)}const n=r.createVerify(s);return n.update(t),n.verify(this.toPEM(),e)}getFingerprint(t,e="PublicKey"){let s;switch(e){case"PublicKeyInfo":s=this._pkcs8.DER;break;case"PublicKey":s=this._keyRaw;break;default:throw new Error(`Unknown fingerprint type "${e}".`)}const i=r.createHash(t);return i.update(s),i.digest()}toASN1(){return this._pkcs8}toDER(){return this._pkcs8.DER}toPEM(){return""===this._finalPEM&&(this._finalPEM=new i.PEM("PUBLIC KEY",this._pkcs8.DER).toString()),this._finalPEM}toJSON(){return{oid:this.oid,algo:this.algo,publicKey:this._keyRaw}}[e.inspect.custom](t,r){return`<${this.constructor.name} ${e.inspect(this.toJSON(),r)}>`}}f._verifiers=Object.create(null),t.PublicKey=f;class y{constructor(e){const r=Object.create(null),n=e.validate(t.privateKeyValidator,r);if(null!=n)throw new Error("Cannot read X.509 private key: "+n.message);if(this.version=i.ASN1.parseIntegerNum(r.privateKeyVersion.bytes)+1,this.oid=i.ASN1.parseOID(r.privateKeyOID.bytes),this.algo=o.getOIDName(this.oid),this._pkcs8=e,this._keyRaw=r.privateKey.bytes,this._publicKeyRaw=null,this._finalKey=this._keyRaw,this._finalPEM="",h.includes(this.oid))if(this._finalKey=this._keyRaw=i.ASN1.parseDER(this._keyRaw,i.Class.UNIVERSAL,i.Tag.OCTETSTRING).bytes,"1.3.101.112"===this.oid){const t=s.sign.keyPair.fromSeed(this._keyRaw);this._publicKeyRaw=Buffer.from(t.publicKey),this._finalKey=Buffer.from(t.secretKey)}else if(2===this.version)for(const t of e.mustCompound())t.class===i.Class.CONTEXT_SPECIFIC&&1===t.tag&&(this._publicKeyRaw=i.ASN1.parseBitString(t.bytes).buf,this._finalKey=Buffer.concat([this._keyRaw,this._publicKeyRaw]))}static fromPEM(t){const e=i.PEM.parse(t)[0];if(e.procType.includes("ENCRYPTED"))throw new Error("Could not convert private key from PEM, PEM is encrypted.");let r=i.ASN1.fromDER(e.body,!0);switch(e.type){case"PRIVATE KEY":return new y(r);case"RSA PRIVATE KEY":return r=i.ASN1.Seq([r.value[0],i.ASN1.Seq([i.ASN1.OID(o.getOID("rsaEncryption")),i.ASN1.Null()]),new i.ASN1(i.Class.UNIVERSAL,i.Tag.OCTETSTRING,r.DER)]),new y(r);default:throw new Error("Could not convert private key from PEM, recommend PKCS#8 PEM")}}static addSigner(t,e){if(""===(t=o.getOID(t)))throw new Error(`Invalid object identifier: ${t}`);if(null!=y._signers[t])throw new Error(`Signer ${t} exists`);y._signers[t]=e}get keyRaw(){return this._finalKey}get publicKeyRaw(){return this._publicKeyRaw}sign(t,e){const s=y._signers[this.oid];if(null!=s){const i=r.createHash(e).update(t).digest();return s.call(this,i)}const i=r.createSign(e);return i.update(t),i.sign(this.toPEM())}toASN1(){return this._pkcs8}toDER(){return this._pkcs8.DER}toPEM(){return""===this._finalPEM&&(this._finalPEM=new i.PEM("PRIVATE KEY",this._pkcs8.DER).toString()),this._finalPEM}toJSON(){return{version:this.version,oid:this.oid,algo:this.algo,privateKey:this._keyRaw,publicKey:this._publicKeyRaw}}[e.inspect.custom](t,r){return`<${this.constructor.name} ${e.inspect(this.toJSON(),r)}>`}}y._signers=Object.create(null),t.PrivateKey=y;class p extends f{static fromPublicKey(t){return new p(t.toASN1())}constructor(t){if(super(t),o.getOID(this.oid)!==o.getOID("rsaEncryption"))throw new Error(`Invalid RSA public key, unknown OID: ${this.oid}`);const e=Object.create(null);this._pkcs1=i.ASN1.fromDER(this._keyRaw,!0);const r=this._pkcs1.validate(c,e);if(null!=r)throw new Error("Cannot read RSA public key: "+r.message);this.modulus=i.ASN1.parseIntegerStr(e.publicKeyModulus.bytes),this.exponent=i.ASN1.parseIntegerNum(e.publicKeyExponent.bytes)}toASN1(){return this._pkcs1}toDER(){return this._keyRaw}toPEM(){return""===this._finalPEM&&(this._finalPEM=new i.PEM("RSA PUBLIC KEY",this._keyRaw).toString()),this._finalPEM}toPublicKeyPEM(){return new i.PEM("PUBLIC KEY",this._pkcs8.DER).toString()}toJSON(){return{oid:this.oid,algo:this.algo,modulus:S(this.modulus),exponent:this.exponent}}[e.inspect.custom](t,r){return`<${this.constructor.name} ${e.inspect(this.toJSON(),r)}>`}}t.RSAPublicKey=p;class d extends y{static fromPrivateKey(t){return new d(t.toASN1())}constructor(t){if(super(t),o.getOID(this.oid)!==o.getOID("rsaEncryption"))throw new Error(`Invalid RSA private key, unknown OID: ${this.oid}`);const e=Object.create(null);this._pkcs1=i.ASN1.fromDER(this._keyRaw,!0);const r=this._pkcs1.validate(l,e);if(null!=r)throw new Error("Cannot read RSA private key: "+r.message);this.publicExponent=i.ASN1.parseIntegerNum(e.privateKeyPublicExponent.bytes),this.privateExponent=i.ASN1.parseIntegerStr(e.privateKeyPrivateExponent.bytes),this.modulus=i.ASN1.parseIntegerStr(e.privateKeyModulus.bytes),this.prime1=i.ASN1.parseIntegerStr(e.privateKeyPrime1.bytes),this.prime2=i.ASN1.parseIntegerStr(e.privateKeyPrime2.bytes),this.exponent1=i.ASN1.parseIntegerStr(e.privateKeyExponent1.bytes),this.exponent2=i.ASN1.parseIntegerStr(e.privateKeyExponent2.bytes),this.coefficient=i.ASN1.parseIntegerStr(e.privateKeyCoefficient.bytes)}toASN1(){return this._pkcs1}toDER(){return this._keyRaw}toPEM(){return""===this._finalPEM&&(this._finalPEM=new i.PEM("RSA PRIVATE KEY",this._keyRaw).toString()),this._finalPEM}toPrivateKeyPEM(){return new i.PEM("PRIVATE KEY",this._pkcs8.DER).toString()}toJSON(){return{version:this.version,oid:this.oid,algo:this.algo,publicExponent:this.publicExponent,privateExponent:S(this.privateExponent),modulus:S(this.modulus),prime1:S(this.prime1),prime2:S(this.prime2),exponent1:S(this.exponent1),exponent2:S(this.exponent2),coefficient:S(this.coefficient)}}[e.inspect.custom](t,r){return`<${this.constructor.name} ${e.inspect(this.toJSON(),r)}>`}}function S(t){return t.length%8!=0&&t.startsWith("00")?t.slice(2):t}t.RSAPrivateKey=d,f.addVerifier(o.getOID("Ed25519"),(function(t,e){return s.sign.detached.verify(t,e,this.keyRaw)})),y.addSigner(o.getOID("Ed25519"),(function(t){const e=this.keyRaw;if(64!==e.length)throw new Error("Invalid signing key.");return Buffer.from(s.sign.detached(t,e))}))}(y);var T={};Object.defineProperty(T,"__esModule",{value:!0});const w=n.default,C=a.default,R=E,U=u,_=y,P=Object.create(null);P.CN=U.getOID("commonName"),P.commonName="CN",P.C=U.getOID("countryName"),P.countryName="C",P.L=U.getOID("localityName"),P.localityName="L",P.ST=U.getOID("stateOrProvinceName"),P.stateOrProvinceName="ST",P.O=U.getOID("organizationName"),P.organizationName="O",P.OU=U.getOID("organizationalUnitName"),P.organizationalUnitName="OU",P.E=U.getOID("emailAddress"),P.emailAddress="E";const O={name:"Certificate",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,value:[{name:"Certificate.TBSCertificate",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,capture:"tbsCertificate",value:[{name:"Certificate.TBSCertificate.version",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.NONE,optional:!0,value:[{name:"Certificate.TBSCertificate.version.integer",class:R.Class.UNIVERSAL,tag:R.Tag.INTEGER,capture:"certVersion"}]},{name:"Certificate.TBSCertificate.serialNumber",class:R.Class.UNIVERSAL,tag:R.Tag.INTEGER,capture:"certSerialNumber"},{name:"Certificate.TBSCertificate.signature",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,value:[{name:"Certificate.TBSCertificate.signature.algorithm",class:R.Class.UNIVERSAL,tag:R.Tag.OID,capture:"certinfoSignatureOID"},{name:"Certificate.TBSCertificate.signature.parameters",class:R.Class.UNIVERSAL,tag:R.Tag.OCTETSTRING,optional:!0,capture:"certinfoSignatureParams"}]},{name:"Certificate.TBSCertificate.issuer",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,capture:"certIssuer"},{name:"Certificate.TBSCertificate.validity",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,value:[{name:"Certificate.TBSCertificate.validity.notBefore",class:R.Class.UNIVERSAL,tag:[R.Tag.UTCTIME,R.Tag.GENERALIZEDTIME],capture:"certValidityNotBefore"},{name:"Certificate.TBSCertificate.validity.notAfter",class:R.Class.UNIVERSAL,tag:[R.Tag.UTCTIME,R.Tag.GENERALIZEDTIME],capture:"certValidityNotAfter"}]},{name:"Certificate.TBSCertificate.subject",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,capture:"certSubject"},_.publicKeyValidator,{name:"Certificate.TBSCertificate.issuerUniqueID",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.BOOLEAN,optional:!0,value:[{name:"Certificate.TBSCertificate.issuerUniqueID.id",class:R.Class.UNIVERSAL,tag:R.Tag.BITSTRING,capture:"certIssuerUniqueId"}]},{name:"Certificate.TBSCertificate.subjectUniqueID",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.INTEGER,optional:!0,value:[{name:"Certificate.TBSCertificate.subjectUniqueID.id",class:R.Class.UNIVERSAL,tag:R.Tag.BITSTRING,capture:"certSubjectUniqueId"}]},{name:"Certificate.TBSCertificate.extensions",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.BITSTRING,capture:"certExtensions",optional:!0}]},{name:"Certificate.signatureAlgorithm",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,value:[{name:"Certificate.signatureAlgorithm.algorithm",class:R.Class.UNIVERSAL,tag:R.Tag.OID,capture:"certSignatureOID"},{name:"Certificate.TBSCertificate.signature.parameters",class:R.Class.UNIVERSAL,tag:R.Tag.OCTETSTRING,optional:!0,capture:"certSignatureParams"}]},{name:"Certificate.signatureValue",class:R.Class.UNIVERSAL,tag:R.Tag.BITSTRING,capture:"certSignature"}]};class B{constructor(){this.attributes=[],this.uniqueId=null}get commonName(){return this.getFieldValue("commonName")}get organizationName(){return this.getFieldValue("organizationName")}get organizationalUnitName(){return this.getFieldValue("organizationalUnitName")}get countryName(){return this.getFieldValue("countryName")}get localityName(){return this.getFieldValue("localityName")}get serialName(){return this.getFieldValue("serialName")}getHash(){const t=C.createHash("sha1");for(const e of this.attributes)t.update(e.oid),t.update(e.value);return t.digest()}getField(t){for(const e of this.attributes)if(t===e.oid||t===e.name||t===e.shortName)return e;return null}addField(t){V([t]),this.attributes.push(t)}setAttrs(t){V(t),this.attributes=t}toJSON(){const t={};for(const e of this.attributes){const r=e.shortName;"string"==typeof r&&""!==r&&(t[r]=e.value)}return t.uniqueId=this.uniqueId,t.attributes=this.attributes,t}getFieldValue(t){const e=this.getField(t);return null!=e?e.value:""}}T.DistinguishedName=B;class K{static fromPEMs(t){const e=[],r=R.PEM.parse(t);for(const t of r){if("CERTIFICATE"!==t.type&&"X509 CERTIFICATE"!==t.type&&"TRUSTED CERTIFICATE"!==t.type)throw new Error("Could not convert certificate from PEM: invalid type");if(t.procType.includes("ENCRYPTED"))throw new Error("Could not convert certificate from PEM: PEM is encrypted.");const r=R.ASN1.fromDER(t.body);e.push(new K(r))}if(0===e.length)throw new Error("No Certificate");return e}static fromPEM(t){return K.fromPEMs(t)[0]}constructor(t){const e=Object.create(null),r=t.validate(O,e);if(null!=r)throw new Error("Cannot read X.509 certificate: "+r.message);if(this.raw=t.DER,this.version=null==e.certVersion?0:R.ASN1.parseIntegerNum(e.certVersion.bytes)+1,this.serialNumber=R.ASN1.parseIntegerStr(e.certSerialNumber.bytes),this.signatureOID=R.ASN1.parseOID(e.certSignatureOID.bytes),this.signatureAlgorithm=U.getOIDName(this.signatureOID),this.infoSignatureOID=R.ASN1.parseOID(e.certinfoSignatureOID.bytes),this.signature=R.ASN1.parseBitString(e.certSignature.bytes).buf,this.validFrom=R.ASN1.parseTime(e.certValidityNotBefore.tag,e.certValidityNotBefore.bytes),this.validTo=R.ASN1.parseTime(e.certValidityNotAfter.tag,e.certValidityNotAfter.bytes),this.issuer=new B,this.issuer.setAttrs(G(e.certIssuer)),null!=e.certIssuerUniqueId&&(this.issuer.uniqueId=R.ASN1.parseBitString(e.certIssuerUniqueId.bytes)),this.subject=new B,this.subject.setAttrs(G(e.certSubject)),null!=e.certSubjectUniqueId&&(this.subject.uniqueId=R.ASN1.parseBitString(e.certSubjectUniqueId.bytes)),this.extensions=[],this.subjectKeyIdentifier="",this.authorityKeyIdentifier="",this.ocspServer="",this.issuingCertificateURL="",this.isCA=!1,this.maxPathLen=-1,this.basicConstraintsValid=!1,this.keyUsage=0,this.dnsNames=[],this.emailAddresses=[],this.ipAddresses=[],this.uris=[],null!=e.certExtensions){this.extensions=function(t){const e=[];for(const r of t.mustCompound())for(const t of r.mustCompound())e.push(D(t));return e}(e.certExtensions);for(const t of this.extensions)if("string"==typeof t.subjectKeyIdentifier&&(this.subjectKeyIdentifier=t.subjectKeyIdentifier),"string"==typeof t.authorityKeyIdentifier&&(this.authorityKeyIdentifier=t.authorityKeyIdentifier),"string"==typeof t.authorityInfoAccessOcsp&&(this.ocspServer=t.authorityInfoAccessOcsp),"string"==typeof t.authorityInfoAccessIssuers&&(this.issuingCertificateURL=t.authorityInfoAccessIssuers),"boolean"==typeof t.basicConstraintsValid&&(this.isCA=t.isCA,this.maxPathLen=t.maxPathLen,this.basicConstraintsValid=t.basicConstraintsValid),"number"==typeof t.keyUsage&&(this.keyUsage=t.keyUsage),Array.isArray(t.altNames))for(const e of t.altNames)null!=e.dnsName&&this.dnsNames.push(e.dnsName),null!=e.email&&this.emailAddresses.push(e.email),null!=e.ip&&this.ipAddresses.push(e.ip),null!=e.uri&&this.uris.push(e.uri)}this.publicKey=new _.PublicKey(e.publicKeyInfo),this.publicKeyRaw=this.publicKey.toDER(),this.tbsCertificate=e.tbsCertificate}getExtension(t,e=""){for(const r of this.extensions)if(t===r.oid||t===r.name)return""===e?r:r[e];return null}checkSignature(t){if(3===this.version&&!this.basicConstraintsValid||this.basicConstraintsValid&&!this.isCA)return new Error("The parent constraint violation error");if(!0!==this.getExtension("keyUsage","keyCertSign"))return new Error("The parent constraint violation error");if(!t.isIssuer(this))return new Error("The parent certificate did not issue the given child certificate");const e=function(t){switch(U.getOIDName(t)){case"sha1WithRsaEncryption":case"ecdsaWithSha1":case"dsaWithSha1":return"sha1";case"md5WithRsaEncryption":return"md5";case"sha256WithRsaEncryption":case"RSASSA-PSS":case"ecdsaWithSha256":case"dsaWithSha256":return"sha256";case"sha384WithRsaEncryption":case"ecdsaWithSha384":return"sha384";case"sha512WithRsaEncryption":case"ecdsaWithSha512":return"sha512";default:return""}}(t.signatureOID);if(""===e)return new Error("Unknown child signature OID.");return!1===this.publicKey.verify(t.tbsCertificate.DER,t.signature,e)?new Error("Child signature not matched"):null}isIssuer(t){return this.issuer.getHash().equals(t.subject.getHash())}verifySubjectKeyIdentifier(){return this.publicKey.getFingerprint("sha1","PublicKey").toString("hex")===this.subjectKeyIdentifier}toJSON(){const t={};for(const e of Object.keys(this))t[e]=j(this[e]);return delete t.tbsCertificate,t}[w.inspect.custom](t,e){return e.depth<=2&&(e.depth=10),`<${this.constructor.name} ${w.inspect(this.toJSON(),e)}>`}}function D(t){const e={};switch(e.oid=R.ASN1.parseOID(t.value[0].bytes),e.critical=!1,t.value[1].tag===R.Tag.BOOLEAN?(e.critical=R.ASN1.parseBool(t.value[1].bytes),e.value=t.value[2].bytes):e.value=t.value[1].bytes,e.name=U.getOIDName(e.oid),e.name){case"keyUsage":!function(t){const e=R.ASN1.parseBitString(R.ASN1.fromDER(t.value).bytes);let r=0,s=0;t.keyUsage=0;for(let r=0;r<9;r++)0!==e.at(r)&&(t.keyUsage|=1<<r);e.buf.length>0&&(r=e.buf[0],s=e.buf.length>1?e.buf[1]:0);t.digitalSignature=128==(128&r),t.nonRepudiation=64==(64&r),t.keyEncipherment=32==(32&r),t.dataEncipherment=16==(16&r),t.keyAgreement=8==(8&r),t.keyCertSign=4==(4&r),t.cRLSign=2==(2&r),t.encipherOnly=1==(1&r),t.decipherOnly=128==(128&s)}(e);break;case"basicConstraints":!function(t){const e=R.ASN1.fromDER(t.value).mustCompound();e.length>0&&e[0].tag===R.Tag.BOOLEAN?t.isCA=R.ASN1.parseBool(e[0].bytes):t.isCA=!1;let r=null;e.length>0&&e[0].tag===R.Tag.INTEGER?r=e[0].bytes:e.length>1&&(r=e[1].bytes);t.maxPathLen=null!==r?R.ASN1.parseInteger(r):-1;t.basicConstraintsValid=!0}(e);break;case"extKeyUsage":!function(t){const e=R.ASN1.fromDER(t.value).mustCompound();for(const r of e)t[U.getOIDName(R.ASN1.parseOID(r.bytes))]=!0}(e);break;case"nsCertType":!function(t){const e=R.ASN1.parseBitString(R.ASN1.fromDER(t.value).bytes);let r=0;e.buf.length>0&&(r=e.buf[0]);t.client=128==(128&r),t.server=64==(64&r),t.email=32==(32&r),t.objsign=16==(16&r),t.reserved=8==(8&r),t.sslCA=4==(4&r),t.emailCA=2==(2&r),t.objCA=1==(1&r)}(e);break;case"subjectAltName":case"issuerAltName":L(e);break;case"subjectKeyIdentifier":!function(t){const e=R.ASN1.parseDERWithTemplate(t.value,x);t.subjectKeyIdentifier=e.subjectKeyIdentifier.bytes.toString("hex")}(e);break;case"authorityKeyIdentifier":!function(t){const e=R.ASN1.parseDERWithTemplate(t.value,M);t.authorityKeyIdentifier=e.authorityKeyIdentifier.bytes.toString("hex")}(e);break;case"authorityInfoAccess":!function(t){const e=R.ASN1.parseDERWithTemplate(t.value,k);null!=e.authorityInfoAccessOcsp&&(t.authorityInfoAccessOcsp=e.authorityInfoAccessOcsp.bytes.toString());null!=e.authorityInfoAccessIssuers&&(t.authorityInfoAccessIssuers=e.authorityInfoAccessIssuers.bytes.toString())}(e)}return e}function L(t){t.altNames=[];const e=R.ASN1.fromDER(t.value).mustCompound();for(const r of e){const e={tag:r.tag,value:r.bytes};switch(t.altNames.push(e),r.tag){case 1:e.email=r.bytes.toString();break;case 2:e.dnsName=r.bytes.toString();break;case 6:e.uri=r.bytes.toString();break;case 7:e.ip=U.bytesToIP(r.bytes);break;case 8:e.oid=R.ASN1.parseOID(r.bytes)}}}T.Certificate=K;const x={name:"subjectKeyIdentifier",class:R.Class.UNIVERSAL,tag:R.Tag.OCTETSTRING,capture:"subjectKeyIdentifier"};const M={name:"authorityKeyIdentifier",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,value:[{name:"authorityKeyIdentifier.value",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.NONE,capture:"authorityKeyIdentifier"}]};const k={name:"authorityInfoAccess",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,value:[{name:"authorityInfoAccess.authorityInfoAccessOcsp",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,optional:!0,value:[{name:"authorityInfoAccess.authorityInfoAccessOcsp.oid",class:R.Class.UNIVERSAL,tag:R.Tag.OID},{name:"authorityInfoAccess.authorityInfoAccessOcsp.value",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.OID,capture:"authorityInfoAccessOcsp"}]},{name:"authorityInfoAccess.authorityInfoAccessIssuers",class:R.Class.UNIVERSAL,tag:R.Tag.SEQUENCE,optional:!0,value:[{name:"authorityInfoAccess.authorityInfoAccessIssuers.oid",class:R.Class.UNIVERSAL,tag:R.Tag.OID},{name:"authorityInfoAccess.authorityInfoAccessIssuers.value",class:R.Class.CONTEXT_SPECIFIC,tag:R.Tag.OID,capture:"authorityInfoAccessIssuers"}]}]};function V(t){for(const e of t){if(null!=e.name&&""!==e.name||(null!=e.oid&&(e.name=U.getOIDName(e.oid)),""===e.name&&null!=e.shortName&&(e.name=U.getOIDName(P[e.shortName]))),null==e.oid||""===e.oid){if(""===e.name)throw new Error("Attribute oid not specified.");e.oid=U.getOID(e.name)}if(null!=e.shortName&&""!==e.shortName||(e.shortName=null==P[e.name]?"":P[e.name]),null==e.value)throw new Error("Attribute value not specified.")}}function G(t){const e=[];for(const s of t.mustCompound())for(const t of s.mustCompound()){const s=t.mustCompound(),i={};i.oid=R.ASN1.parseOID(s[0].bytes),i.value=s[1].value,i.valueTag=s[1].tag,i.name=U.getOIDName(i.oid),i.shortName=(r=i.name,null==P[r]?"":P[r]),e.push(i)}var r;return e}function j(t){return null==t||t instanceof Buffer||"function"!=typeof t.toJSON?t:t.toJSON()}Object.defineProperty(o,"__esModule",{value:!0});var F=u;o.bytesFromIP=F.bytesFromIP,o.bytesToIP=F.bytesToIP,o.getOID=F.getOID,o.getOIDName=F.getOIDName;var W=y,Y=o.PublicKey=W.PublicKey;o.PrivateKey=W.PrivateKey;var $=o.RSAPublicKey=W.RSAPublicKey;o.RSAPrivateKey=W.RSAPrivateKey;var z=T;o.Certificate=z.Certificate,o.DistinguishedName=z.DistinguishedName,exports.PublicKey=Y,exports.RSAPublicKey=$;