UNPKG

@vantezzen/pow

Version:

A simple challenge-response proof-of-work implementation for web apps

62 lines 147 kB
/*! * MIT License * * Copyright (c) 2017-2022 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 Fs="[object ArrayBuffer]";class p{static isArrayBuffer(e){return Object.prototype.toString.call(e)===Fs}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e).slice().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 r=p.toUint8Array(e),s=p.toUint8Array(t);if(r.length!==s.byteLength)return!1;for(let n=0;n<r.length;n++)if(r[n]!==s[n])return!1;return!0}static concat(...e){if(Array.isArray(e[0])){const t=e[0];let r=0;for(const o of t)r+=o.byteLength;const s=new Uint8Array(r);let n=0;for(const o of t){const a=this.toUint8Array(o);s.set(a,n),n+=a.length}return e[1]?this.toView(s,e[1]):s.buffer}else return this.concat(e)}}class er{static fromString(e){const t=unescape(encodeURIComponent(e)),r=new Uint8Array(t.length);for(let s=0;s<t.length;s++)r[s]=t.charCodeAt(s);return r.buffer}static toString(e){const t=p.toUint8Array(e);let r="";for(let n=0;n<t.length;n++)r+=String.fromCharCode(t[n]);return decodeURIComponent(escape(r))}}class ne{static toString(e,t=!1){const r=p.toArrayBuffer(e),s=new DataView(r);let n="";for(let o=0;o<r.byteLength;o+=2){const a=s.getUint16(o,t);n+=String.fromCharCode(a)}return n}static fromString(e,t=!1){const r=new ArrayBuffer(e.length*2),s=new DataView(r);for(let n=0;n<e.length;n++)s.setUint16(n*2,e.charCodeAt(n),t);return r}}class v{static isHex(e){return typeof e=="string"&&/^[a-z0-9]+$/i.test(e)}static isBase64(e){return typeof e=="string"&&/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}static isBase64Url(e){return typeof e=="string"&&/^[a-zA-Z0-9-_]+$/i.test(e)}static ToString(e,t="utf8"){const r=p.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(r);case"binary":return this.ToBinary(r);case"hex":return this.ToHex(r);case"base64":return this.ToBase64(r);case"base64url":return this.ToBase64Url(r);case"utf16le":return ne.toString(r,!0);case"utf16":case"utf16be":return ne.toString(r);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 ne.fromString(e,!0);case"utf16":case"utf16be":return ne.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){const t=p.toUint8Array(e);if(typeof btoa<"u"){const r=this.ToString(t,"binary");return btoa(r)}else return Buffer.from(t).toString("base64")}static FromBase64(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!v.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){const t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!v.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=v.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return er.fromString(e);case"utf16":case"utf16be":return ne.fromString(e);case"utf16le":case"usc2":return ne.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=v.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return er.toString(e);case"utf16":case"utf16be":return ne.toString(e);case"utf16le":case"usc2":return ne.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){const t=e.length,r=new Uint8Array(t);for(let s=0;s<t;s++)r[s]=e.charCodeAt(s);return r.buffer}static ToBinary(e){const t=p.toUint8Array(e);let r="";for(let s=0;s<t.length;s++)r+=String.fromCharCode(t[s]);return r}static ToHex(e){const t=p.toUint8Array(e),r="",s=[],n=t.length;for(let o=0;o<n;o++){const a=t[o].toString(16).padStart(2,"0");s.push(a)}return s.join(r)}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!v.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);const r=new Uint8Array(t.length/2);for(let s=0;s<t.length;s=s+2){const n=t.slice(s,s+2);r[s/2]=parseInt(n,16)}return r.buffer}static ToUtf16String(e,t=!1){return ne.toString(e,t)}static FromUtf16String(e,t=!1){return ne.fromString(e,t)}static Base64Padding(e){const t=4-e.length%4;if(t<4)for(let r=0;r<t;r++)e+="=";return e}static formatString(e){return(e==null?void 0:e.replace(/[\n\r\t ]/g,""))||""}}v.DEFAULT_UTF8_ENCODING="utf8";function yr(...i){const e=i.map(s=>s.byteLength).reduce((s,n)=>s+n),t=new Uint8Array(e);let r=0;return i.map(s=>new Uint8Array(s)).forEach(s=>{for(const n of s)t[r++]=n}),t.buffer}/*! Copyright (c) Peculiar Ventures, LLC */function Ce(i,e){let t=0;if(i.length===1)return i[0];for(let r=i.length-1;r>=0;r--)t+=i[i.length-1-r]*Math.pow(2,e*r);return t}function be(i,e,t=-1){const r=t;let s=i,n=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(i<o){let c;if(r<0)c=new ArrayBuffer(a),n=a;else{if(r<a)return new ArrayBuffer(0);c=new ArrayBuffer(r),n=r}const l=new Uint8Array(c);for(let h=a-1;h>=0;h--){const u=Math.pow(2,h*e);l[n-h-1]=Math.floor(s/u),s-=l[n-h-1]*u}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function Nt(...i){let e=0,t=0;for(const n of i)e+=n.length;const r=new ArrayBuffer(e),s=new Uint8Array(r);for(const n of i)s.set(n,t),t+=n.length;return s}function dr(){const i=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){const a=i[0]===255&&i[1]&128,c=i[0]===0&&(i[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}const e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=i[0]&128;const r=Ce(t,8),s=new ArrayBuffer(this.valueHex.byteLength),n=new Uint8Array(s);for(let a=0;a<this.valueHex.byteLength;a++)n[a]=i[a];return n[0]&=127,Ce(n,8)-r}function zs(i){const e=i<0?i*-1:i;let t=128;for(let r=1;r<8;r++){if(e<=t){if(i<0){const o=t-e,a=be(o,8,r),c=new Uint8Array(a);return c[0]|=128,a}let s=be(e,8,r),n=new Uint8Array(s);if(n[0]&128){const o=s.slice(0),a=new Uint8Array(o);s=new ArrayBuffer(s.byteLength+1),n=new Uint8Array(s);for(let c=0;c<o.byteLength;c++)n[c+1]=a[c];n[0]=0}return s}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function js(i,e){if(i.byteLength!==e.byteLength)return!1;const t=new Uint8Array(i),r=new Uint8Array(e);for(let s=0;s<t.length;s++)if(t[s]!==r[s])return!1;return!0}function F(i,e){const t=i.toString(10);if(e<t.length)return"";const r=e-t.length,s=new Array(r);for(let o=0;o<r;o++)s[o]="0";return s.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 We(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Vt(i){let e=0,t=0;for(let s=0;s<i.length;s++){const n=i[s];e+=n.byteLength}const r=new Uint8Array(e);for(let s=0;s<i.length;s++){const n=i[s];r.set(new Uint8Array(n),t),t+=n.byteLength}return r.buffer}function ye(i,e,t,r){return e instanceof Uint8Array?e.byteLength?t<0?(i.error="Wrong parameter: inputOffset less than zero",!1):r<0?(i.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-r<0?(i.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(i.error="Wrong parameter: inputBuffer has zero length",!1):(i.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}class st{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Vt(this.items)}}const Re=[new Uint8Array([1])],tr="0123456789",Kt="name",rr="valueHexView",Gs="isHexOnly",qs="idBlock",Ws="tagClass",Ys="tagNumber",Xs="isConstructed",Zs="fromBER",Qs="toBER",en="local",M="",ee=new ArrayBuffer(0),nt=new Uint8Array(0),Te="EndOfContent",pr="OCTET STRING",gr="BIT STRING";function ae(i){var e;return e=class extends i{constructor(...r){var s;super(...r);const n=r[0]||{};this.isHexOnly=(s=n.isHexOnly)!==null&&s!==void 0?s:!1,this.valueHexView=n.valueHex?p.toUint8Array(n.valueHex):nt}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(r){this.valueHexView=new Uint8Array(r)}fromBER(r,s,n){const o=r instanceof ArrayBuffer?new Uint8Array(r):r;if(!ye(this,o,s,n))return-1;const a=s+n;return this.valueHexView=o.subarray(s,a),this.valueHexView.length?(this.blockLength=n,a):(this.warnings.push("Zero buffer length"),s)}toBER(r=!1){return this.isHexOnly?r?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",ee)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:v.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}class Se{constructor({blockLength:e=0,error:t=M,warnings:r=[],valueBeforeDecode:s=nt}={}){this.blockLength=e,this.error=t,this.warnings=r,this.valueBeforeDecodeView=p.toUint8Array(s)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:v.ToHex(this.valueBeforeDecodeView)}}}Se.NAME="baseBlock";class T extends Se{fromBER(e,t,r){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'")}}T.NAME="valueBlock";class mr extends ae(Se){constructor({idBlock:e={}}={}){var t,r,s,n;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?p.toUint8Array(e.valueHex):nt,this.tagClass=(r=e.tagClass)!==null&&r!==void 0?r:-1,this.tagNumber=(s=e.tagNumber)!==null&&s!==void 0?s:-1,this.isConstructed=(n=e.isConstructed)!==null&&n!==void 0?n:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",ee}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){const s=new Uint8Array(1);if(!e){let n=this.tagNumber;n&=31,t|=n,s[0]=t}return s.buffer}if(!this.isHexOnly){const s=be(this.tagNumber,7),n=new Uint8Array(s),o=s.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=n[c]|128;a[o]=n[o-1]}return a.buffer}const r=new Uint8Array(this.valueHexView.byteLength+1);if(r[0]=t|31,!e){const s=this.valueHexView;for(let n=0;n<s.length-1;n++)r[n+1]=s[n]|128;r[this.valueHexView.byteLength]=s[s.length-1]}return r.buffer}fromBER(e,t,r){const s=p.toUint8Array(e);if(!ye(this,s,t,r))return-1;const n=s.subarray(t,t+r);if(n.length===0)return this.error="Zero buffer length",-1;switch(n[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(n[0]&32)===32,this.isHexOnly=!1;const a=n[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),h=255;for(;n[c]&128;){if(l[c-1]=n[c]&127,c++,c>=n.length)return this.error="End of input reached before message was fully decoded",-1;if(c===h){h+=255;const w=new Uint8Array(h);for(let B=0;B<l.length;B++)w[B]=l[B];l=this.valueHexView=new Uint8Array(h)}}this.blockLength=c+1,l[c-1]=n[c]&127;const u=new Uint8Array(c);for(let w=0;w<c;w++)u[w]=l[w];l=this.valueHexView=new Uint8Array(c),l.set(u),this.blockLength<=9?this.tagNumber=Ce(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}}mr.NAME="identificationBlock";class wr extends Se{constructor({lenBlock:e={}}={}){var t,r,s;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(r=e.longFormUsed)!==null&&r!==void 0?r:!1,this.length=(s=e.length)!==null&&s!==void 0?s:0}fromBER(e,t,r){const s=p.toUint8Array(e);if(!ye(this,s,t,r))return-1;const n=s.subarray(t,t+r);if(n.length===0)return this.error="Zero buffer length",-1;if(n[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=n[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(n[0]&128),this.longFormUsed===!1)return this.length=n[0],this.blockLength=1,t+this.blockLength;const o=n[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>n.length)return this.error="End of input reached before message was fully decoded",-1;const a=t+1,c=s.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=Ce(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,r;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=128),t;if(this.longFormUsed){const s=be(this.length,8);if(s.byteLength>127)return this.error="Too big length",ee;if(t=new ArrayBuffer(s.byteLength+1),e)return t;const n=new Uint8Array(s);r=new Uint8Array(t),r[0]=s.byteLength|128;for(let o=0;o<s.byteLength;o++)r[o+1]=n[o];return t}return t=new ArrayBuffer(1),e===!1&&(r=new Uint8Array(t),r[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}}wr.NAME="lengthBlock";const y={};class O extends Se{constructor({name:e=M,optional:t=!1,primitiveSchema:r,...s}={},n){super(s),this.name=e,this.optional=t,r&&(this.primitiveSchema=r),this.idBlock=new mr(s),this.lenBlock=new wr(s),this.valueBlock=n?new n(s):new T(s)}fromBER(e,t,r){const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}toBER(e,t){const r=t||new st;t||vr(this);const s=this.idBlock.toBER(e);if(r.write(s),this.lenBlock.isIndefiniteForm)r.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,r),r.write(new ArrayBuffer(2));else{const n=this.valueBlock.toBER(e);this.lenBlock.length=n.byteLength;const o=this.lenBlock.toBER(e);r.write(o),r.write(n)}return t?ee:r.final()}toJSON(){const e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():v.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${v.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;const t=this.toBER(),r=e.toBER();return js(t,r)}}O.NAME="BaseBlock";function vr(i){if(i instanceof y.Constructed)for(const e of i.valueBlock.value)vr(e)&&(i.lenBlock.isIndefiniteForm=!0);return!!i.lenBlock.isIndefiniteForm}class Ht extends O{constructor({value:e=M,...t}={},r){super(t,r),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,r){const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}}Ht.NAME="BaseStringBlock";class Ar extends ae(T){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}}Ar.NAME="PrimitiveValueBlock";var br;class _e extends O{constructor(e={}){super(e,Ar),this.idBlock.isConstructed=!1}}br=_e;y.Primitive=br;_e.NAME="PRIMITIVE";function tn(i,e){if(i instanceof e)return i;const t=new e;return t.idBlock=i.idBlock,t.lenBlock=i.lenBlock,t.warnings=i.warnings,t.valueBeforeDecodeView=i.valueBeforeDecodeView,t}function Ie(i,e=0,t=i.length){const r=e;let s=new O({},T);const n=new Se;if(!ye(n,i,e,t))return s.error=n.error,{offset:-1,result:s};if(!i.subarray(e,e+t).length)return s.error="Zero buffer length",{offset:-1,result:s};let a=s.idBlock.fromBER(i,e,t);if(s.idBlock.warnings.length&&s.warnings.concat(s.idBlock.warnings),a===-1)return s.error=s.idBlock.error,{offset:-1,result:s};if(e=a,t-=s.idBlock.blockLength,a=s.lenBlock.fromBER(i,e,t),s.lenBlock.warnings.length&&s.warnings.concat(s.lenBlock.warnings),a===-1)return s.error=s.lenBlock.error,{offset:-1,result:s};if(e=a,t-=s.lenBlock.blockLength,!s.idBlock.isConstructed&&s.lenBlock.isIndefiniteForm)return s.error="Indefinite length form used for primitive encoding form",{offset:-1,result:s};let c=O;switch(s.idBlock.tagClass){case 1:if(s.idBlock.tagNumber>=37&&s.idBlock.isHexOnly===!1)return s.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:s};switch(s.idBlock.tagNumber){case 0:if(s.idBlock.isConstructed&&s.lenBlock.length>0)return s.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:s};c=y.EndOfContent;break;case 1:c=y.Boolean;break;case 2:c=y.Integer;break;case 3:c=y.BitString;break;case 4:c=y.OctetString;break;case 5:c=y.Null;break;case 6:c=y.ObjectIdentifier;break;case 10:c=y.Enumerated;break;case 12:c=y.Utf8String;break;case 13:c=y.RelativeObjectIdentifier;break;case 14:c=y.TIME;break;case 15:return s.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:s};case 16:c=y.Sequence;break;case 17:c=y.Set;break;case 18:c=y.NumericString;break;case 19:c=y.PrintableString;break;case 20:c=y.TeletexString;break;case 21:c=y.VideotexString;break;case 22:c=y.IA5String;break;case 23:c=y.UTCTime;break;case 24:c=y.GeneralizedTime;break;case 25:c=y.GraphicString;break;case 26:c=y.VisibleString;break;case 27:c=y.GeneralString;break;case 28:c=y.UniversalString;break;case 29:c=y.CharacterString;break;case 30:c=y.BmpString;break;case 31:c=y.DATE;break;case 32:c=y.TimeOfDay;break;case 33:c=y.DateTime;break;case 34:c=y.Duration;break;default:{const l=s.idBlock.isConstructed?new y.Constructed:new y.Primitive;l.idBlock=s.idBlock,l.lenBlock=s.lenBlock,l.warnings=s.warnings,s=l}}break;case 2:case 3:case 4:default:c=s.idBlock.isConstructed?y.Constructed:y.Primitive}return s=tn(s,c),a=s.fromBER(i,e,s.lenBlock.isIndefiniteForm?t:s.lenBlock.length),s.valueBeforeDecodeView=i.subarray(r,r+s.blockLength),{offset:a,result:s}}function Ke(i){if(!i.byteLength){const e=new O({},T);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Ie(p.toUint8Array(i).slice(),0,i.byteLength)}function rn(i,e){return i?1:e}class ge extends T{constructor({value:e=[],isIndefiniteForm:t=!1,...r}={}){super(r),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,r){const s=p.toUint8Array(e);if(!ye(this,s,t,r))return-1;if(this.valueBeforeDecodeView=s.subarray(t,t+r),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let n=t;for(;rn(this.isIndefiniteForm,r)>0;){const o=Ie(s,n,r);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(n=o.offset,this.blockLength+=o.result.blockLength,r-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Te)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Te?this.value.pop():this.warnings.push("No EndOfContent block encoded")),n}toBER(e,t){const r=t||new st;for(let s=0;s<this.value.length;s++)this.value[s].toBER(e,r);return t?ee:r.final()}toJSON(){const e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(const t of this.value)e.value.push(t.toJSON());return e}}ge.NAME="ConstructedValueBlock";var kr;class _ extends O{constructor(e={}){super(e,ge),this.idBlock.isConstructed=!0}fromBER(e,t,r){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;const s=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?r:this.lenBlock.length);return s===-1?(this.error=this.valueBlock.error,s):(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),s)}onAsciiEncoding(){const e=[];for(const r of this.valueBlock.value)e.push(r.toString("ascii").split(` `).map(s=>` ${s}`).join(` `));const t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} : ${e.join(` `)}`:`${t} :`}}kr=_;y.Constructed=kr;_.NAME="CONSTRUCTED";class Br extends T{fromBER(e,t,r){return t}toBER(e){return ee}}Br.override="EndOfContentValueBlock";var Sr;class Ot extends O{constructor(e={}){super(e,Br),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}}Sr=Ot;y.EndOfContent=Sr;Ot.NAME=Te;var Er;class ke extends O{constructor(e={}){super(e,T),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,r){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+=r,t+r>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+r}toBER(e,t){const r=new ArrayBuffer(2);if(!e){const s=new Uint8Array(r);s[0]=5,s[1]=0}return t&&t.write(r),r}onAsciiEncoding(){return`${this.constructor.NAME}`}}Er=ke;y.Null=Er;ke.NAME="NULL";class xr extends ae(T){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=p.toUint8Array(t.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(const e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,t,r){const s=p.toUint8Array(e);return ye(this,s,t,r)?(this.valueHexView=s.subarray(t,t+r),r>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,dr.call(this),this.blockLength=r,t+r):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}}xr.NAME="BooleanValueBlock";var Kr;class it extends O{constructor(e={}){super(e,xr),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}}Kr=it;y.Boolean=Kr;it.NAME="BOOLEAN";class Cr extends ae(ge){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,r){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=ge.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(let n=0;n<this.value.length;n++){const o=this.value[n].constructor.NAME;if(o===Te){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(o!==pr)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(e,t,r),this.blockLength=r;return s}toBER(e,t){return this.isConstructed?ge.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}}Cr.NAME="OctetStringValueBlock";var Nr;let ot=class Pr extends O{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,n;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((n=r.value)===null||n===void 0)&&n.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Cr),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,r){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,r===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),t;if(!this.valueBlock.isConstructed){const n=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+r);try{if(n.byteLength){const o=Ie(n,0,n.byteLength);o.offset!==-1&&o.offset===r&&(this.valueBlock.value=[o.result])}}catch{}}return super.fromBER(e,t,r)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?_.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${v.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;const e=[];for(const t of this.valueBlock.value)t instanceof Pr&&e.push(t.valueBlock.valueHexView);return p.concat(e)}};Nr=ot;y.OctetString=Nr;ot.NAME=pr;class Ur extends ae(ge){constructor({unusedBits:e=0,isConstructed:t=!1,...r}={}){super(r),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,r){if(!r)return t;let s=-1;if(this.isConstructed){if(s=ge.prototype.fromBER.call(this,e,t,r),s===-1)return s;for(const a of this.value){const c=a.constructor.NAME;if(c===Te){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==gr)return this.error="BIT STRING may consists of BIT STRINGs only",-1;const l=a.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}const n=p.toUint8Array(e);if(!ye(this,n,t,r))return-1;const o=n.subarray(t,t+r);if(this.unusedBits=o[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){const a=o.subarray(1);try{if(a.byteLength){const c=Ie(a,0,a.byteLength);c.offset!==-1&&c.offset===r-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=o.subarray(1),this.blockLength=o.length,t+r}toBER(e,t){if(this.isConstructed)return ge.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return ee;const r=new Uint8Array(this.valueHexView.length+1);return r[0]=this.unusedBits,r.set(this.valueHexView,1),r.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}}Ur.NAME="BitStringValueBlock";var Ir;let at=class extends O{constructor({idBlock:e={},lenBlock:t={},...r}={}){var s,n;(s=r.isConstructed)!==null&&s!==void 0||(r.isConstructed=!!(!((n=r.value)===null||n===void 0)&&n.length)),super({idBlock:{isConstructed:r.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!r.isIndefiniteForm},...r},Ur),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,r){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,r)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return _.prototype.onAsciiEncoding.call(this);{const e=[],t=this.valueBlock.valueHexView;for(const s of t)e.push(s.toString(2).padStart(8,"0"));const r=e.join("");return`${this.constructor.NAME} : ${r.substring(0,r.length-this.valueBlock.unusedBits)}`}}};Ir=at;y.BitString=Ir;at.NAME=gr;var Vr;function sn(i,e){const t=new Uint8Array([0]),r=new Uint8Array(i),s=new Uint8Array(e);let n=r.slice(0);const o=n.length-1,a=s.slice(0),c=a.length-1;let l=0;const h=c<o?o:c;let u=0;for(let w=h;w>=0;w--,u++){switch(!0){case u<a.length:l=n[o-u]+a[c-u]+t[0];break;default:l=n[o-u]+t[0]}switch(t[0]=l/10,!0){case u>=n.length:n=Nt(new Uint8Array([l%10]),n);break;default:n[o-u]=l%10}}return t[0]>0&&(n=Nt(t,n)),n}function sr(i){if(i>=Re.length)for(let e=Re.length;e<=i;e++){const t=new Uint8Array([0]);let r=Re[e-1].slice(0);for(let s=r.length-1;s>=0;s--){const n=new Uint8Array([(r[s]<<1)+t[0]]);t[0]=n[0]/10,r[s]=n[0]%10}t[0]>0&&(r=Nt(t,r)),Re.push(r)}return Re[i]}function nn(i,e){let t=0;const r=new Uint8Array(i),s=new Uint8Array(e),n=r.slice(0),o=n.length-1,a=s.slice(0),c=a.length-1;let l,h=0;for(let u=c;u>=0;u--,h++)switch(l=n[o-h]-a[c-h]-t,!0){case l<0:t=1,n[o-h]=l+10;break;default:t=0,n[o-h]=l}if(t>0)for(let u=o-c+1;u>=0;u--,h++)if(l=n[o-h]-t,l<0)t=1,n[o-h]=l+10;else{t=0,n[o-h]=l;break}return n.slice()}class Rt extends ae(T){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=dr.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(zs(e))}get valueDec(){return this._valueDec}fromDER(e,t,r,s=0){const n=this.fromBER(e,t,r);if(n===-1)return n;const o=this.valueHexView;return o[0]===0&&o[1]&128?this.valueHexView=o.subarray(1):s!==0&&o.length<s&&(s-o.length>1&&(s=o.length+1),this.valueHexView=o.subarray(s-o.length)),n}toDER(e=!1){const t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{const r=new Uint8Array(this.valueHexView.length+1);r[0]=0,r.set(t,1),this.valueHexView=r}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,r){const s=super.fromBER(e,t,r);return s===-1||this.setValueHex(),s}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){const e=this.valueHexView.length*8-1;let t=new Uint8Array(this.valueHexView.length*8/3),r=0,s;const n=this.valueHexView;let o="",a=!1;for(let c=n.byteLength-1;c>=0;c--){s=n[c];for(let l=0;l<8;l++){if((s&1)===1)switch(r){case e:t=nn(sr(r),t),o="-";break;default:t=sn(t,sr(r))}r++,s>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(o+=tr.charAt(t[c]));return a===!1&&(o+=tr.charAt(0)),o}}Vr=Rt;Rt.NAME="IntegerValueBlock";Object.defineProperty(Vr.prototype,"valueHex",{set:function(i){this.valueHexView=new Uint8Array(i),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Hr;class q extends O{constructor(e={}){super(e,Rt),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return We(),BigInt(this.valueBlock.toString())}static fromBigInt(e){We();const t=BigInt(e),r=new st,s=t.toString(16).replace(/^-/,""),n=new Uint8Array(v.FromHex(s));if(t<0){const a=new Uint8Array(n.length+(n[0]&128?1:0));a[0]|=128;const l=BigInt(`0x${v.ToHex(a)}`)+t,h=p.toUint8Array(v.FromHex(l.toString(16)));h[0]|=128,r.write(h)}else n[0]&128&&r.write(new Uint8Array([0])),r.write(n);return new q({valueHex:r.final()})}convertToDER(){const e=new q({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new q({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}}Hr=q;y.Integer=Hr;q.NAME="INTEGER";var Or;class ct extends q{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}}Or=ct;y.Enumerated=Or;ct.NAME="ENUMERATED";class Pt extends ae(T){constructor({valueDec:e=-1,isFirstSid:t=!1,...r}={}){super(r),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,r){if(!r)return t;const s=p.toUint8Array(e);if(!ye(this,s,t,r))return-1;const n=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=n[a]&127,this.blockLength++,!!(n[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,n[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ce(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){We();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;const r=new Uint8Array(t.length/7);for(let s=0;s<r.length;s++)r[s]=parseInt(t.slice(s*7,s*7+7),2)+(s+1<r.length?128:0);this.fromBER(r.buffer,0,r.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,n=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)n[o]=s[o]|128;return n[this.blockLength-1]=s[this.blockLength-1],n.buffer}const t=be(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ee;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),n=t.byteLength-1;for(let o=0;o<n;o++)r[o]=s[o]|128;r[n]=s[n]}return r}toString(){let e="";if(this.isHexOnly)e=v.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}}Pt.NAME="sidBlock";class Rr extends T{constructor({value:e=M,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const n=new Pt;if(s=n.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=n.error,s;this.value.length===0&&(n.isFirstSid=!0),this.blockLength+=n.blockLength,r-=n.blockLength,this.value.push(n)}return s}toBER(e){const t=[];for(let r=0;r<this.value.length;r++){const s=this.value[r].toBER(e);if(s.byteLength===0)return this.error=this.value[r].error,ee;t.push(s)}return Vt(t)}fromString(e){this.value=[];let t=0,r=0,s="",n=!1;do if(r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1,n){const o=this.value[0];let a=0;switch(o.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}const c=parseInt(s,10);if(isNaN(c))return;o.valueDec=c+a,n=!1}else{const o=new Pt;if(s>Number.MAX_SAFE_INTEGER){We();const a=BigInt(s);o.valueBigInt=a}else if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return;this.value.length||(o.isFirstSid=!0,n=!0),this.value.push(o)}while(r!==-1)}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t?(s=`{${s}}`,this.value[r].isFirstSid?e=`2.{${s} - 80}`:e+=s):e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Rr.NAME="ObjectIdentifierValueBlock";var Lr;let lt=class extends O{constructor(e={}){super(e,Rr),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Lr=lt;y.ObjectIdentifier=Lr;lt.NAME="OBJECT IDENTIFIER";class Ut extends ae(Se){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,r){if(r===0)return t;const s=p.toUint8Array(e);if(!ye(this,s,t,r))return-1;const n=s.subarray(t,t+r);this.valueHexView=new Uint8Array(r);for(let a=0;a<r&&(this.valueHexView[a]=n[a]&127,this.blockLength++,!!(n[a]&128));a++);const o=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)o[a]=this.valueHexView[a];return this.valueHexView=o,n[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ce(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);const s=this.valueHexView,n=new Uint8Array(this.blockLength);for(let o=0;o<this.blockLength-1;o++)n[o]=s[o]|128;return n[this.blockLength-1]=s[this.blockLength-1],n.buffer}const t=be(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",ee;const r=new Uint8Array(t.byteLength);if(!e){const s=new Uint8Array(t),n=t.byteLength-1;for(let o=0;o<n;o++)r[o]=s[o]|128;r[n]=s[n]}return r.buffer}toString(){let e="";return this.isHexOnly?e=v.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}}Ut.NAME="relativeSidBlock";class Dr extends T{constructor({value:e=M,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,r){let s=t;for(;r>0;){const n=new Ut;if(s=n.fromBER(e,s,r),s===-1)return this.blockLength=0,this.error=n.error,s;this.blockLength+=n.blockLength,r-=n.blockLength,this.value.push(n)}return s}toBER(e,t){const r=[];for(let s=0;s<this.value.length;s++){const n=this.value[s].toBER(e);if(n.byteLength===0)return this.error=this.value[s].error,ee;r.push(n)}return Vt(r)}fromString(e){this.value=[];let t=0,r=0,s="";do{r=e.indexOf(".",t),r===-1?s=e.substring(t):s=e.substring(t,r),t=r+1;const n=new Ut;if(n.valueDec=parseInt(s,10),isNaN(n.valueDec))return!0;this.value.push(n)}while(r!==-1);return!0}toString(){let e="",t=!1;for(let r=0;r<this.value.length;r++){t=this.value[r].isHexOnly;let s=this.value[r].toString();r!==0&&(e=`${e}.`),t&&(s=`{${s}}`),e+=s}return e}toJSON(){const e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}}Dr.NAME="RelativeObjectIdentifierValueBlock";var Tr;class Lt extends O{constructor(e={}){super(e,Dr),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}}Tr=Lt;y.RelativeObjectIdentifier=Tr;Lt.NAME="RelativeObjectIdentifier";var $r;class he extends _{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}}$r=he;y.Sequence=$r;he.NAME="SEQUENCE";var Mr;class fe extends _{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}}Mr=fe;y.Set=Mr;fe.NAME="SET";class _r extends ae(T){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=M}toJSON(){return{...super.toJSON(),value:this.value}}}_r.NAME="StringValueBlock";class Jr extends _r{}Jr.NAME="SimpleStringValueBlock";class z extends Ht{constructor({...e}={}){super(e,Jr)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,p.toUint8Array(e))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t);for(let s=0;s<t;s++)r[s]=e.charCodeAt(s);this.valueBlock.value=e}}z.NAME="SIMPLE STRING";class Fr extends z{fromBuffer(e){this.valueBlock.valueHexView=p.toUint8Array(e);try{this.valueBlock.value=v.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=v.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(v.FromUtf8String(e)),this.valueBlock.value=e}}Fr.NAME="Utf8StringValueBlock";var zr;class de extends Fr{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}}zr=de;y.Utf8String=zr;de.NAME="UTF8String";class jr extends z{fromBuffer(e){this.valueBlock.value=v.ToUtf16String(e),this.valueBlock.valueHexView=p.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(v.FromUtf16String(e))}}jr.NAME="BmpStringValueBlock";var Gr;class ut extends jr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}}Gr=ut;y.BmpString=Gr;ut.NAME="BMPString";class qr extends z{fromBuffer(e){const t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),r=new Uint8Array(t);for(let s=0;s<r.length;s+=4)r[s]=r[s+3],r[s+1]=r[s+2],r[s+2]=0,r[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){const t=e.length,r=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let s=0;s<t;s++){const n=be(e.charCodeAt(s),8),o=new Uint8Array(n);if(o.length>4)continue;const a=4-o.length;for(let c=o.length-1;c>=0;c--)r[s*4+c+a]=o[c]}this.valueBlock.value=e}}qr.NAME="UniversalStringValueBlock";var Wr;class ht extends qr{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}}Wr=ht;y.UniversalString=Wr;ht.NAME="UniversalString";var Yr;class ft extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}}Yr=ft;y.NumericString=Yr;ft.NAME="NumericString";var Xr;class yt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}}Xr=yt;y.PrintableString=Xr;yt.NAME="PrintableString";var Zr;class dt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}}Zr=dt;y.TeletexString=Zr;dt.NAME="TeletexString";var Qr;class pt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}}Qr=pt;y.VideotexString=Qr;pt.NAME="VideotexString";var es;class gt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}}es=gt;y.IA5String=es;gt.NAME="IA5String";var ts;class mt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}}ts=mt;y.GraphicString=ts;mt.NAME="GraphicString";var rs;class Je extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}}rs=Je;y.VisibleString=rs;Je.NAME="VisibleString";var ss;class wt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}}ss=wt;y.GeneralString=ss;wt.NAME="GeneralString";var ns;class vt extends z{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}}ns=vt;y.CharacterString=ns;vt.NAME="CharacterString";var is;class Fe extends Je{constructor({value:e,valueDate:t,...r}={}){if(super(r),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let s=0;s<e.length;s++)this.valueBlock.valueHexView[s]=e.charCodeAt(s)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,p.toUint8Array(e)))}toBuffer(){const e=this.toString(),t=new ArrayBuffer(e.length),r=new Uint8Array(t);for(let s=0;s<e.length;s++)r[s]=e.charCodeAt(s);return t}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){const r=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(r===null){this.error="Wrong input string for conversion";return}const s=parseInt(r[1],10);s>=50?this.year=1900+s:this.year=2e3+s,this.month=parseInt(r[2],10),this.day=parseInt(r[3],10),this.hour=parseInt(r[4],10),this.minute=parseInt(r[5],10),this.second=parseInt(r[6],10)}toString(e="iso"){if(e==="iso"){const t=new Array(7);return t[0]=F(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=F(this.month,2),t[2]=F(this.day,2),t[3]=F(this.hour,2),t[4]=F(this.minute,2),t[5]=F(this.second,2),t[6]="Z",t.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}}is=Fe;y.UTCTime=is;Fe.NAME="UTCTime";var os;class At extends Fe{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let t=!1,r="",s="",n=0,o,a=0,c=0;if(e[e.length-1]==="Z")r=e.substring(0,e.length-1),t=!0;else{const u=new Number(e[e.length-1]);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");r=e}if(t){if(r.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(r.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let u=1,w=r.indexOf("+"),B="";if(w===-1&&(w=r.indexOf("-"),u=-1),w!==-1){if(B=r.substring(w+1),r=r.substring(0,w),B.length!==2&&B.length!==4)throw new Error("Wrong input string for conversion");let C=parseInt(B.substring(0,2),10);if(isNaN(C.valueOf()))throw new Error("Wrong input string for conversion");if(a=u*C,B.length===4){if(C=parseInt(B.substring(2,4),10),isNaN(C.valueOf()))throw new Error("Wrong input string for conversion");c=u*C}}}let l=r.indexOf(".");if(l===-1&&(l=r.indexOf(",")),l!==-1){const u=new Number(`0${r.substring(l)}`);if(isNaN(u.valueOf()))throw new Error("Wrong input string for conversion");n=u.valueOf(),s=r.substring(0,l)}else s=r;switch(!0){case s.length===8:if(o=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let u=60*n;this.minute=Math.floor(u),u=60*(u-this.minute),this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===12:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let u=60*n;this.second=Math.floor(u),u=1e3*(u-this.second),this.millisecond=Math.floor(u)}break;case s.length===14:if(o=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){const u=1e3*n;this.millisecond=Math.floor(u)}break;default:throw new Error("Wrong input string for conversion")}const h=o.exec(s);if(h===null)throw new Error("Wrong input string for conversion");for(let u=1;u<h.length;u++)switch(u){case 1