@blueking/crypto-js-sdk
Version:
crypto-js-sdk
1 lines • 65.8 kB
JavaScript
"use strict";class t{constructor(t){this.m=t}convert(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}revert(t){return t}reduce(t){t.divRemTo(this.m,null,t)}mulTo(t,e,r){t.multiplyTo(e,r),this.reduce(r)}sqrTo(t,e){t.squareTo(e),this.reduce(e)}}class e{constructor(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}convert(t){const e=new f(null);return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(f.ZERO)>0&&this.m.subTo(e,e),e}revert(t){const e=new f(null);return t.copyTo(e),this.reduce(e),e}reduce(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(let e=0;e<this.m.t;++e){let r=32767&t[e];const i=r*this.mpl+((r*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=e+this.m.t,t[r]+=this.m.am(0,i,t,e,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}sqrTo(t,e){t.squareTo(e),this.reduce(e)}mulTo(t,e,r){t.multiplyTo(e,r),this.reduce(r)}}class r{constructor(t){this.r2=new f(null),this.q3=new f(null),f.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}convert(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;const e=new f(null);return t.copyTo(e),this.reduce(e),e}revert(t){return t}reduce(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}sqrTo(t,e){t.squareTo(e),this.reduce(e)}mulTo(t,e,r){t.multiplyTo(e,r),this.reduce(r)}}class i{convert(t){return t}revert(t){return t}mulTo(t,e,r){t.multiplyTo(e,r)}sqrTo(t,e){t.squareTo(e)}reduce(t){}}const n=[];let s,o;for(s="0".charCodeAt(0),o=0;o<=9;++o)n[s++]=o;for(s="a".charCodeAt(0),o=10;o<36;++o)n[s++]=o;for(s="A".charCodeAt(0),o=10;o<36;++o)n[s++]=o;function h(){return new f(null)}function u(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function a(t,e){const r=n[t.charCodeAt(e)];return null==r?-1:r}class f{static get ZERO(){return l(0)}static get ONE(){return l(1)}constructor(t,e,r){this.DB=28,this.DM=268435455,this.DV=1<<28,this.FV=Math.pow(2,52),this.F1=24,this.F2=4,null!==t&&("number"==typeof t?this.fromNumber(t,e,r):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}am(t,e,r,i,n,s){const o=16383&e,h=e>>14;for(;--s>=0;){let e=16383&this[t];const s=this[t++]>>14,u=h*e+s*o;e=o*e+((16383&u)<<14)+r[i]+n,n=(e>>28)+(u>>14)+h*s,r[i++]=268435455&e}return n}fromNumber(t,e,r){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(f.ONE.shiftLeft(t-1),g.or,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(f.ONE.shiftLeft(t-1),this);else{const r=[],i=7&t;r.length=1+(t>>3),e.nextBytes(r),i>0?r[0]&=(1<<i)-1:r[0]=0,this.fromString(r,256)}}bitwiseTo(t,e,r){let i,n;const s=Math.min(t.t,this.t);for(i=0;i<s;++i)r[i]=e(this[i],t[i]);if(t.t<this.t){for(n=t.s&this.DM,i=s;i<this.t;++i)r[i]=e(this[i],n);r.t=this.t}else{for(n=this.s&this.DM,i=s;i<t.t;++i)r[i]=e(n,t[i]);r.t=t.t}r.s=e(this.s,t.s),r.clamp()}chunkSize(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}toRadix(t){if(null==t&&(t=10),0===this.signum()||t<2||t>36)return"0";const e=this.chunkSize(t),r=Math.pow(t,e),i=l(r),n=h(),s=h();let o="";for(this.divRemTo(i,n,s);n.signum()>0;)o=(r+s.intValue()).toString(t).substr(1)+o,n.divRemTo(i,n,s);return s.intValue().toString(t)+o}fromRadix(t,e){this.fromInt(0),null==e&&(e=10);const r=this.chunkSize(e),i=Math.pow(e,r);let n=!1,s=0,o=0;for(let h=0;h<t.length;++h){const u=a(t,h);u<0?"-"===t.charAt(h)&&0===this.signum()&&(n=!0):(o=e*o+u,++s>=r&&(this.dMultiply(i),this.dAddOffset(o,0),s=0,o=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(o,0)),n&&f.ZERO.subTo(this,this)}changeBit(t,e){const r=f.ONE.shiftLeft(t);return this.bitwiseTo(r,e,r),r}addTo(t,e){let r=0,i=0;const n=Math.min(t.t,this.t);for(;r<n;)i+=this[r]+t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;r<this.t;)i+=this[r],e[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<t.t;)i+=t[r],e[r++]=i&this.DM,i>>=this.DB;i+=t.s}e.s=i<0?-1:0,i>0?e[r++]=i:i<-1&&(e[r++]=this.DV+i),e.t=r,e.clamp()}dMultiply(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}dAddOffset(t,e){if(0!==t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}}multiplyLowerTo(t,e,r){let i,n=Math.min(this.t+t.t,e);for(r.s=0,r.t=n;n>0;)r[--n]=0;for(i=r.t-this.t;n<i;++n)r[n+this.t]=this.am(0,t[n],r,n,0,this.t);for(i=Math.min(t.t,e);n<i;++n)this.am(0,t[n],r,n,0,e-n);r.clamp()}multiplyUpperTo(t,e,r){--e;let i=r.t=this.t+t.t-e;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(e-this.t,0);i<t.t;++i)r[this.t+i-e]=this.am(e-i,t[i],r,0,0,this.t+i-e);r.clamp(),r.drShiftTo(1,r)}modInt(t){if(t<=0)return 0;const e=this.DV%t;let r=this.s<0?t-1:0;if(this.t>0)0===e&&(r=this[0]%t);else for(let i=this.t-1;i>=0;--i)r=(e*r+this[i])%t;return r}millerRabin(t){const e=this.subtract(f.ONE),r=e.getLowestSetBit();if(r<=0)return!1;const i=e.shiftRight(r);(t=t+1>>1)>d.length&&(t=d.length);const n=h();for(let s=0;s<t;++s){n.fromInt(d[Math.floor(Math.random()*d.length)]);let t=n.modPow(i,this);if(0!==t.compareTo(f.ONE)&&0!==t.compareTo(e)){let i=1;for(;i++<r&&0!==t.compareTo(e);)if(t=t.modPowInt(2,this),0===t.compareTo(f.ONE))return!1;if(0!==t.compareTo(e))return!1}}return!0}fromInt(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0}fromString(t,e){let r;if(16===e)r=4;else if(8===e)r=3;else if(256===e)r=8;else if(2===e)r=1;else if(32===e)r=5;else{if(4!==e)return void this.fromRadix(t,e);r=2}this.t=0,this.s=0;let i=t.length,n=!1,s=0;for(;--i>=0;){const e=8===r?255&t[i]:a(t,i);e<0?"-"===t.charAt(i)&&(n=!0):(n=!1,0===s?this[this.t++]=e:s+r>this.DB?(this[this.t-1]|=(e&(1<<this.DB-s)-1)<<s,this[this.t++]=e>>this.DB-s):this[this.t-1]|=e<<s,s+=r,s>=this.DB&&(s-=this.DB))}8===r&&0!=(128&t[0])&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&f.ZERO.subTo(this,this)}lShiftTo(t,e){const r=t%this.DB,i=this.DB-r,n=(1<<i)-1,s=Math.floor(t/this.DB);let o,h=this.s<<r&this.DM;for(o=this.t-1;o>=0;--o)e[o+s+1]=this[o]>>i|h,h=(this[o]&n)<<r;for(o=s-1;o>=0;--o)e[o]=0;e[s]=h,e.t=this.t+s+1,e.s=this.s,e.clamp()}rShiftTo(t,e){e.s=this.s;const r=Math.floor(t/this.DB);if(r>=this.t)return void(e.t=0);const i=t%this.DB,n=this.DB-i,s=(1<<i)-1;e[0]=this[r]>>i;for(let t=r+1;t<this.t;++t)e[t-r-1]|=(this[t]&s)<<n,e[t-r]=this[t]>>i;i>0&&(e[this.t-r-1]|=(this.s&s)<<n),e.t=this.t-r,e.clamp()}isEven(){return 0===(this.t>0?1&this[0]:this.s)}exp(t,e){if(t>4294967295||t<1)return f.ONE;let r=h(),i=h();const n=e.convert(this);let s=c(t)-1;for(n.copyTo(r);--s>=0;)if(e.sqrTo(r,i),(t&1<<s)>0)e.mulTo(i,n,r);else{const t=r;r=i,i=t}return e.revert(r)}copyTo(t){for(let e=this.t-1;e>=0;--e)t[e]=this[e];t.t=this.t,t.s=this.s}squareTo(t){const e=this.abs();let r=t.t=2*e.t;for(;--r>=0;)t[r]=0;for(r=0;r<e.t-1;++r){const i=e.am(r,e[r],t,2*r,0,1);(t[r+e.t]+=e.am(r+1,2*e[r],t,2*r+1,i,e.t-r-1))>=e.DV&&(t[r+e.t]-=e.DV,t[r+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(r,e[r],t,2*r,0,1)),t.s=0,t.clamp()}divRemTo(t,e,r){const i=t.abs();if(i.t<=0)return;const n=this.abs();if(n.t<i.t)return null!==e&&e.fromInt(0),void(null!==r&&this.copyTo(r));null==r&&(r=h());const s=h(),o=this.s,u=t.s,a=this.DB-c(i[i.t-1]);a>0?(i.lShiftTo(a,s),n.lShiftTo(a,r)):(i.copyTo(s),n.copyTo(r));const l=s.t,g=s[l-1];if(0===g)return;const p=g*(1<<this.F1)+(l>1?s[l-2]>>this.F2:0),y=this.FV/p,d=(1<<this.F1)/p,m=1<<this.F2;let b=r.t,B=b-l;const T=null==e?h():e;for(s.dlShiftTo(B,T),r.compareTo(T)>=0&&(r[r.t++]=1,r.subTo(T,r)),f.ONE.dlShiftTo(l,T),T.subTo(s,s);s.t<l;)s[s.t++]=0;for(;--B>=0;){let t=r[--b]===g?this.DM:Math.floor(r[b]*y+(r[b-1]+m)*d);if((r[b]+=s.am(0,t,r,B,0,l))<t)for(s.dlShiftTo(B,T),r.subTo(T,r);r[b]<--t;)r.subTo(T,r)}null!==e&&(r.drShiftTo(l,e),o!==u&&f.ZERO.subTo(e,e)),r.t=l,r.clamp(),a>0&&r.rShiftTo(a,r),o<0&&f.ZERO.subTo(r,r)}invDigit(){if(this.t<1)return 0;const t=this[0];if(0==(1&t))return 0;let e=3&t;return e=e*(2-(15&t)*e)&15,e=e*(2-(255&t)*e)&255,e=e*(2-((65535&t)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e}clamp(){const t=this.s&this.DM;for(;this.t>0&&this[this.t-1]===t;)--this.t}dlShiftTo(t,e){let r;for(r=this.t-1;r>=0;--r)e[r+t]=this[r];for(r=t-1;r>=0;--r)e[r]=0;e.t=this.t+t,e.s=this.s}drShiftTo(t,e){for(let r=t;r<this.t;++r)e[r-t]=this[r];e.t=Math.max(this.t-t,0),e.s=this.s}subTo(t,e){let r=0,i=0;const n=Math.min(t.t,this.t);for(;r<n;)i+=this[r]-t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;r<this.t;)i+=this[r],e[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<t.t;)i-=t[r],e[r++]=i&this.DM,i>>=this.DB;i-=t.s}e.s=i<0?-1:0,i<-1?e[r++]=this.DV+i:i>0&&(e[r++]=i),e.t=r,e.clamp()}multiplyTo(t,e){const r=this.abs(),i=t.abs();let n=r.t;for(e.t=n+i.t;--n>=0;)e[n]=0;for(n=0;n<i.t;++n)e[n+r.t]=r.am(0,i[n],e,n,0,r.t);e.s=0,e.clamp(),this.s!==t.s&&f.ZERO.subTo(e,e)}clone(){const t=h();return this.copyTo(t),t}intValue(){if(this.s<0){if(1===this.t)return this[0]-this.DV;if(0===this.t)return-1}else{if(1===this.t)return this[0];if(0===this.t)return 0}return(this[1]&(1<<32-this.DB)-1)<<this.DB|this[0]}byteValue(){return 0===this.t?this.s:this[0]<<24>>24}shortValue(){return 0===this.t?this.s:this[0]<<16>>16}signum(){return this.s<0?-1:this.t<=0||1===this.t&&this[0]<=0?0:1}toByteArray(){let t=this.t;const e=[];e[0]=this.s;let r,i=this.DB-t*this.DB%8,n=0;if(t-- >0)for(i<this.DB&&(r=this[t]>>i)!=(this.s&this.DM)>>i&&(e[n++]=r|this.s<<this.DB-i);t>=0;)i<8?(r=(this[t]&(1<<i)-1)<<8-i,r|=this[--t]>>(i+=this.DB-8)):(r=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),0!=(128&r)&&(r|=-256),0===n&&(128&this.s)!=(128&r)&&++n,(n>0||r!==this.s)&&(e[n++]=r);return e}equals(t){return 0===this.compareTo(t)}min(t){return this.compareTo(t)<0?this:t}max(t){return this.compareTo(t)>0?this:t}and(t){const e=h();return this.bitwiseTo(t,g.and,e),e}or(t){const e=h();return this.bitwiseTo(t,g.or,e),e}xor(t){const e=h();return this.bitwiseTo(t,g.xor,e),e}andNot(t){const e=h();return this.bitwiseTo(t,g.andNot,e),e}not(){const t=h();for(let e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t}shiftLeft(t){const e=h();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}shiftRight(t){const e=h();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}getLowestSetBit(){for(let t=0;t<this.t;++t)if(0!==this[t])return t*this.DB+p(this[t]);return this.s<0?this.t*this.DB:-1}bitCount(){let t=0;const e=this.s&this.DM;for(let r=0;r<this.t;++r)t+=y(this[r]^e);return t}testBit(t){const e=Math.floor(t/this.DB);return e>=this.t?0!==this.s:0!=(this[e]&1<<t%this.DB)}setBit(t){return this.changeBit(t,g.or)}clearBit(t){return this.changeBit(t,g.andNot)}flipBit(t){return this.changeBit(t,g.xor)}add(t){const e=h();return this.addTo(t,e),e}subtract(t){const e=h();return this.subTo(t,e),e}multiply(t){const e=h();return this.multiplyTo(t,e),e}divide(t){const e=h();return this.divRemTo(t,e,null),e}square(){const t=h();return this.squareTo(t),t}remainder(t){const e=h();return this.divRemTo(t,null,e),e}divideAndRemainder(t){const e=h(),r=h();return this.divRemTo(t,e,r),[e,r]}modPow(i,n){let s,o,u=i.bitLength(),a=l(1);if(u<=0)return a;s=u<18?1:u<48?3:u<144?4:u<768?5:6,o=u<8?new t(n):n.isEven()?new r(n):new e(n);const f=[];let g=3;const p=s-1,y=(1<<s)-1;if(f[1]=o.convert(this),s>1){const t=h();for(o.sqrTo(f[1],t);g<=y;)f[g]=h(),o.mulTo(t,f[g-2],f[g]),g+=2}let d,m,b=i.t-1,B=!0,T=h();for(u=c(i[b])-1;b>=0;){for(u>=p?d=i[b]>>u-p&y:(d=(i[b]&(1<<u+1)-1)<<p-u,b>0&&(d|=i[b-1]>>this.DB+u-p)),g=s;0==(1&d);)d>>=1,--g;if((u-=g)<0&&(u+=this.DB,--b),B)f[d].copyTo(a),B=!1;else{for(;g>1;)o.sqrTo(a,T),o.sqrTo(T,a),g-=2;g>0?o.sqrTo(a,T):(m=a,a=T,T=m),o.mulTo(T,f[d],a)}for(;b>=0&&0==(i[b]&1<<u);)o.sqrTo(a,T),m=a,a=T,T=m,--u<0&&(u=this.DB-1,--b)}return o.revert(a)}modInverse(t){const e=t.isEven();if(this.isEven()&&e||0===t.signum())return f.ZERO;const r=t.clone(),i=this.clone(),n=l(1),s=l(0),o=l(0),h=l(1);for(;0!==r.signum();){for(;r.isEven();)r.rShiftTo(1,r),e?(n.isEven()&&s.isEven()||(n.addTo(this,n),s.subTo(t,s)),n.rShiftTo(1,n)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;i.isEven();)i.rShiftTo(1,i),e?(o.isEven()&&h.isEven()||(o.addTo(this,o),h.subTo(t,h)),o.rShiftTo(1,o)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);r.compareTo(i)>=0?(r.subTo(i,r),e&&n.subTo(o,n),s.subTo(h,s)):(i.subTo(r,i),e&&o.subTo(n,o),h.subTo(s,h))}return 0!==i.compareTo(f.ONE)?f.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h}pow(t){return this.exp(t,new i)}gcd(t){let e=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(e.compareTo(r)<0){const t=e;e=r,r=t}let i=e.getLowestSetBit(),n=r.getLowestSetBit();if(n<0)return e;for(i<n&&(n=i),n>0&&(e.rShiftTo(n,e),r.rShiftTo(n,r));e.signum()>0;)(i=e.getLowestSetBit())>0&&e.rShiftTo(i,e),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return n>0&&r.lShiftTo(n,r),r}isProbablePrime(t){let e;const r=this.abs();if(1===r.t&&r[0]<=d[d.length-1]){for(e=0;e<d.length;++e)if(r[0]===d[e])return!0;return!1}if(r.isEven())return!1;for(e=1;e<d.length;){let t=d[e],i=e+1;for(;i<d.length&&t<m;)t*=d[i++];for(t=r.modInt(t);e<i;)if(t%d[e++]==0)return!1}return r.millerRabin(t)}toString(t){if(this.s<0)return`-${this.negate().toString(t)}`;let e;if(16===t)e=4;else if(8===t)e=3;else if(2===t)e=1;else if(32===t)e=5;else{if(4!==t)return this.toRadix(t);e=2}const r=(1<<e)-1;let i,n=!1,s="",o=this.t,h=this.DB-o*this.DB%e;if(o-- >0)for(h<this.DB&&(i=this[o]>>h)>0&&(n=!0,s=u(i));o>=0;)h<e?(i=(this[o]&(1<<h)-1)<<e-h,i|=this[--o]>>(h+=this.DB-e)):(i=this[o]>>(h-=e)&r,h<=0&&(h+=this.DB,--o)),i>0&&(n=!0),n&&(s+=u(i));return n?s:"0"}negate(){const t=h();return f.ZERO.subTo(this,t),t}abs(){return this.s<0?this.negate():this}compareTo(t){let e=this.s-t.s;if(0!==e)return e;let r=this.t;if(e=r-t.t,0!==e)return this.s<0?-e:e;for(;--r>=0;)if(0!=(e=this[r]-t[r]))return e;return 0}bitLength(){return this.t<=0?0:this.DB*(this.t-1)+c(this[this.t-1]^this.s&this.DM)}mod(t){const e=h();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(f.ZERO)>0&&t.subTo(e,e),e}modPowInt(r,i){let n;return n=r<256||i.isEven()?new t(i):new e(i),this.exp(r,n)}}function l(t){const e=h();return e.fromInt(t),e}function c(t){let e,r=1;return 0!=(e=t>>>16)&&(t=e,r+=16),0!=(e=t>>8)&&(t=e,r+=8),0!=(e=t>>4)&&(t=e,r+=4),0!=(e=t>>2)&&(t=e,r+=2),0!=(e=t>>1)&&(t=e,r+=1),r}const g={and:(t,e)=>t&e,or:(t,e)=>t|e,xor:(t,e)=>t^e,andNot:(t,e)=>t&~e};function p(t){if(0===t)return-1;let e=0;return 0==(65535&t)&&(t>>=16,e+=16),0==(255&t)&&(t>>=8,e+=8),0==(15&t)&&(t>>=4,e+=4),0==(3&t)&&(t>>=2,e+=2),0==(1&t)&&++e,e}function y(t){let e=0;for(;0!==t;)t&=t-1,++e;return e}const d=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997],m=(1<<26)/d[d.length-1];let b,B=null,T=0;const w=256;if(null==b||void 0===b){let t;for(b=[],T=0;T<w;)t=Math.floor(65536*Math.random()),b[T++]=t>>>8,b[T++]=255&t;T=0,A()}function v(){if(null===B){for(A(),B=new F,B.init(b),T=0;T<b.length;++T)b[T]=0;T=0}return B.next()}function E(t){let e;for(e=0;e<t.length;++e)t[e]=v()}function A(){var t;t=(new Date).getTime(),b[T++]^=255&t,b[T++]^=t>>8&255,b[T++]^=t>>16&255,b[T++]^=t>>24&255,T>=w&&(T-=w)}class F{constructor(){this.i=0,this.j=0,this.S=[]}init(t){let e,r,i;for(e=0;e<256;++e)this.S[e]=e;for(r=0,e=0;e<256;++e)r=r+this.S[e]+t[e%t.length]&255,i=this.S[e],this.S[e]=this.S[r],this.S[r]=i;this.i=0,this.j=0}next(){this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255;const t=this.S[this.i];return this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]}}class I{constructor(){this.nextBytes=E}}class S{constructor(t,e){this.x=e,this.q=t}equals(t){return t===this||this.q.equals(t.q)&&this.x.equals(t.x)}toBigInteger(){return this.x}negate(){return new S(this.q,this.x.negate().mod(this.q))}add(t){return new S(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new S(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new S(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}square(){return new S(this.q,this.x.square().mod(this.q))}divide(t){return new S(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}getByteLength(){return Math.floor((this.toBigInteger().bitLength()+7)/8)}}class R{static decodeFrom(t,e){const r=e.length-1,i=e.slice(1,1+r/2),n=e.slice(1+r/2,1+r);i.unshift(0),n.unshift(0);const s=new f(i),o=new f(n);return new R(t,t.fromBigInteger(s),t.fromBigInteger(o))}static decodeFromHex(t,e){const r=e.length-2,i=e.substr(2,r/2),n=e.substr(2+r/2,r/2),s=new f(i,16),o=new f(n,16);return new R(t,t.fromBigInteger(s),t.fromBigInteger(o))}constructor(t,e,r,i){this.curve=t,this.x=e,this.y=r,this.z=null==i?f.ONE:i,this.zinv=null}getX(){return null!==this.zinv&&void 0!==this.zinv||(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.x.toBigInteger().multiply(this.zinv).mod(this.curve.q))}getY(){return null!==this.zinv&&void 0!==this.zinv||(this.zinv=this.z.modInverse(this.curve.q)),this.curve.fromBigInteger(this.y.toBigInteger().multiply(this.zinv).mod(this.curve.q))}equals(t){if(t===this)return!0;if(this.isInfinity())return t.isInfinity();if(t.isInfinity())return this.isInfinity();if(!t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(f.ZERO))return!1;return t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(f.ZERO)}isInfinity(){return!(null!==this.x&&void 0!==this.x||null!==this.y&&void 0!==this.y)||this.z.equals(f.ZERO)&&!this.y.toBigInteger().equals(f.ZERO)}negate(){return new R(this.curve,this.x,this.y.negate(),this.z)}add(t){if(this.isInfinity())return t;if(t.isInfinity())return this;const e=t.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(t.z)).mod(this.curve.q),r=t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q);if(f.ZERO.equals(r))return f.ZERO.equals(e)?this.twice():this.curve.getInfinity();const i=new f("3"),n=this.x.toBigInteger(),s=this.y.toBigInteger(),o=r.square(),h=o.multiply(r),u=n.multiply(o),a=e.square().multiply(this.z),l=a.subtract(u.shiftLeft(1)).multiply(t.z).subtract(h).multiply(r).mod(this.curve.q),c=u.multiply(i).multiply(e).subtract(s.multiply(h)).subtract(a.multiply(e)).multiply(t.z).add(e.multiply(h)).mod(this.curve.q),g=h.multiply(this.z).multiply(t.z).mod(this.curve.q);return new R(this.curve,this.curve.fromBigInteger(l),this.curve.fromBigInteger(c),g)}twice(){if(this.isInfinity())return this;if(0===this.y.toBigInteger().signum())return this.curve.getInfinity();const t=new f("3"),e=this.x.toBigInteger(),r=this.y.toBigInteger(),i=r.multiply(this.z),n=i.multiply(r).mod(this.curve.q),s=this.curve.a.toBigInteger();let o=e.square().multiply(t);f.ZERO.equals(s)||(o=o.add(this.z.square().multiply(s))),o=o.mod(this.curve.q);const h=o.square().subtract(e.shiftLeft(3).multiply(n)).shiftLeft(1).multiply(i).mod(this.curve.q),u=o.multiply(t).multiply(e).subtract(n.shiftLeft(1)).shiftLeft(2).multiply(n).subtract(o.square().multiply(o)).mod(this.curve.q),a=i.square().multiply(i).shiftLeft(3).mod(this.curve.q);return new R(this.curve,this.curve.fromBigInteger(h),this.curve.fromBigInteger(u),a)}multiply(t){if(this.isInfinity())return this;if(0===t.signum())return this.curve.getInfinity();const e=t,r=e.multiply(new f("3")),i=this.negate();let n,s=this;for(n=r.bitLength()-2;n>0;--n){s=s.twice();const t=r.testBit(n);t!==e.testBit(n)&&(s=s.add(t?this:i))}return s}multiplyTwo(t,e,r){let i;i=t.bitLength()>r.bitLength()?t.bitLength()-1:r.bitLength()-1;let n=this.curve.getInfinity();const s=this.add(e);for(;i>=0;)n=n.twice(),t.testBit(i)?n=r.testBit(i)?n.add(s):n.add(this):r.testBit(i)&&(n=n.add(e)),i-=1;return n}getEncoded(t){const e=function(t,e){let r=t.toByteArrayUnsigned();if(e<r.length)r=r.slice(r.length-e);else for(;e>r.length;)r.unshift(0);return r},r=this.getX().toBigInteger(),i=this.getY().toBigInteger();let n=e(r,32);return t?i.isEven()?n.unshift(2):n.unshift(3):(n.unshift(4),n=n.concat(e(i,32))),n}add2D(t){if(this.isInfinity())return t;if(t.isInfinity())return this;if(this.x.equals(t.x))return this.y.equals(t.y)?this.twice():this.curve.getInfinity();const e=t.x.subtract(this.x),r=t.y.subtract(this.y).divide(e),i=r.square().subtract(this.x).subtract(t.x),n=r.multiply(this.x.subtract(i)).subtract(this.y);return new R(this.curve,i,n)}twice2D(){if(this.isInfinity())return this;if(0===this.y.toBigInteger().signum())return this.curve.getInfinity();const t=this.curve.fromBigInteger(f.valueOf()),e=this.curve.fromBigInteger(f.valueOf()),r=this.x.square().multiply(e).add(this.curve.a).divide(this.y.multiply(t)),i=r.square().subtract(this.x.multiply(t)),n=r.multiply(this.x.subtract(i)).subtract(this.y);return new R(this.curve,i,n)}multiply2D(t){if(this.isInfinity())return this;if(0===t.signum())return this.curve.getInfinity();const e=t,r=e.multiply(new f("3")),i=this.negate();let n,s=this;for(n=r.bitLength()-2;n>0;--n){s=s.twice();const t=r.testBit(n);t!==e.testBit(n)&&(s=s.add2D(t?this:i))}return s}isOnCurve(){const t=this.getX().toBigInteger(),e=this.getY().toBigInteger(),r=this.curve.getA().toBigInteger(),i=this.curve.getB().toBigInteger(),n=this.curve.getQ(),s=e.multiply(e).mod(n),o=t.multiply(t).multiply(t).add(r.multiply(t)).add(i).mod(n);return s.equals(o)}toString(){return`(${this.getX().toBigInteger().toString()},${this.getY().toBigInteger().toString()})`}validate(){const t=this.curve.getQ();if(this.isInfinity())throw new Error("Point is at infinity.");const e=this.getX().toBigInteger(),r=this.getY().toBigInteger();if(e.compareTo(f.ONE)<0||e.compareTo(t.subtract(f.ONE))>0)throw new Error("x coordinate out of bounds");if(r.compareTo(f.ONE)<0||r.compareTo(t.subtract(f.ONE))>0)throw new Error("y coordinate out of bounds");if(!this.isOnCurve())throw new Error("Point is not on the curve.");if(this.multiply(t).isInfinity())throw new Error("Point is not a scalar multiple of G.");return!0}}class C{constructor(t,e,r){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(r),this.infinity=new R(this,null,null)}getQ(){return this.q}getA(){return this.a}getB(){return this.b}equals(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}getInfinity(){return this.infinity}fromBigInteger(t){return new S(this.q,t)}decodePointHex(t){const e=(t.length-2)/2,r=t.substr(2,e),i=t.substr(e+2,e);switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:default:return null;case 4:case 6:case 7:return new R(this,this.fromBigInteger(new f(r,16)),this.fromBigInteger(new f(i,16)))}}}function x(t,e,r,i,n){let s=n;s=e+n>t.length&&i+n<=r.length?t.length-e:i+n>r.length&&e+n<=t.length?r.length-i:e+n<=t.length&&i+n<=r.length?n:r.length<t.length?r.length-i:t.length-i;for(let n=0;n<s;n++)r[n+i]=t[n+e]}function D(t){return[t>>24&255,t>>16&255,t>>8&255,255&t]}function L(t,e){return e+3<t.length?t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3]:e+2<t.length?t[e+1]<<16|t[e+2]<<8|t[e+3]:e+1<t.length?t[e]<<8|t[e+1]:t[e]}var _="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},O=[],P=[],q="undefined"!=typeof Uint8Array?Uint8Array:Array,M=!1;function U(){M=!0;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)O[e]=t[e],P[t.charCodeAt(e)]=e;P["-".charCodeAt(0)]=62,P["_".charCodeAt(0)]=63}function k(t,e,r){for(var i,n,s=[],o=e;o<r;o+=3)i=(t[o]<<16)+(t[o+1]<<8)+t[o+2],s.push(O[(n=i)>>18&63]+O[n>>12&63]+O[n>>6&63]+O[63&n]);return s.join("")}function $(t){var e;M||U();for(var r=t.length,i=r%3,n="",s=[],o=16383,h=0,u=r-i;h<u;h+=o)s.push(k(t,h,h+o>u?u:h+o));return 1===i?(e=t[r-1],n+=O[e>>2],n+=O[e<<4&63],n+="=="):2===i&&(e=(t[r-2]<<8)+t[r-1],n+=O[e>>10],n+=O[e>>4&63],n+=O[e<<2&63],n+="="),s.push(n),s.join("")}function N(t,e,r,i,n){var s,o,h=8*n-i-1,u=(1<<h)-1,a=u>>1,f=-7,l=r?n-1:0,c=r?-1:1,g=t[e+l];for(l+=c,s=g&(1<<-f)-1,g>>=-f,f+=h;f>0;s=256*s+t[e+l],l+=c,f-=8);for(o=s&(1<<-f)-1,s>>=-f,f+=i;f>0;o=256*o+t[e+l],l+=c,f-=8);if(0===s)s=1-a;else{if(s===u)return o?NaN:1/0*(g?-1:1);o+=Math.pow(2,i),s-=a}return(g?-1:1)*o*Math.pow(2,s-i)}function Y(t,e,r,i,n,s){var o,h,u,a=8*s-n-1,f=(1<<a)-1,l=f>>1,c=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,g=i?0:s-1,p=i?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(h=isNaN(e)?1:0,o=f):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),(e+=o+l>=1?c/u:c*Math.pow(2,1-l))*u>=2&&(o++,u/=2),o+l>=f?(h=0,o=f):o+l>=1?(h=(e*u-1)*Math.pow(2,n),o+=l):(h=e*Math.pow(2,l-1)*Math.pow(2,n),o=0));n>=8;t[r+g]=255&h,g+=p,h/=256,n-=8);for(o=o<<n|h,a+=n;a>0;t[r+g]=255&o,g+=p,o/=256,a-=8);t[r+g-p]|=128*y}var z={}.toString,V=Array.isArray||function(t){return"[object Array]"==z.call(t)};function j(){return H.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Z(t,e){if(j()<e)throw new RangeError("Invalid typed array length");return H.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=H.prototype:(null===t&&(t=new H(e)),t.length=e),t}function H(t,e,r){if(!(H.TYPED_ARRAY_SUPPORT||this instanceof H))return new H(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return G(this,t)}return K(this,t,e,r)}function K(t,e,r,i){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,i){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(i||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===i?new Uint8Array(e):void 0===i?new Uint8Array(e,r):new Uint8Array(e,r,i);H.TYPED_ARRAY_SUPPORT?(t=e).__proto__=H.prototype:t=Q(t,e);return t}(t,e,r,i):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!H.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var i=0|tt(e,r);t=Z(t,i);var n=t.write(e,r);n!==i&&(t=t.slice(0,n));return t}(t,e,r):function(t,e){if(W(e)){var r=0|J(e.length);return 0===(t=Z(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(i=e.length)!=i?Z(t,0):Q(t,e);if("Buffer"===e.type&&V(e.data))return Q(t,e.data)}var i;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function X(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function G(t,e){if(X(e),t=Z(t,e<0?0:0|J(e)),!H.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function Q(t,e){var r=e.length<0?0:0|J(e.length);t=Z(t,r);for(var i=0;i<r;i+=1)t[i]=255&e[i];return t}function J(t){if(t>=j())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+j().toString(16)+" bytes");return 0|t}function W(t){return!(null==t||!t._isBuffer)}function tt(t,e){if(W(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var i=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return St(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return Rt(t).length;default:if(i)return St(t).length;e=(""+e).toLowerCase(),i=!0}}function et(t,e,r){var i=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return dt(this,e,r);case"utf8":case"utf-8":return ct(this,e,r);case"ascii":return pt(this,e,r);case"latin1":case"binary":return yt(this,e,r);case"base64":return lt(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return mt(this,e,r);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}function rt(t,e,r){var i=t[e];t[e]=t[r],t[r]=i}function it(t,e,r,i,n){if(0===t.length)return-1;if("string"==typeof r?(i=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=n?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(n)return-1;r=t.length-1}else if(r<0){if(!n)return-1;r=0}if("string"==typeof e&&(e=H.from(e,i)),W(e))return 0===e.length?-1:nt(t,e,r,i,n);if("number"==typeof e)return e&=255,H.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):nt(t,[e],r,i,n);throw new TypeError("val must be string, number or Buffer")}function nt(t,e,r,i,n){var s,o=1,h=t.length,u=e.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(t.length<2||e.length<2)return-1;o=2,h/=2,u/=2,r/=2}function a(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(n){var f=-1;for(s=r;s<h;s++)if(a(t,s)===a(e,-1===f?0:s-f)){if(-1===f&&(f=s),s-f+1===u)return f*o}else-1!==f&&(s-=s-f),f=-1}else for(r+u>h&&(r=h-u),s=r;s>=0;s--){for(var l=!0,c=0;c<u;c++)if(a(t,s+c)!==a(e,c)){l=!1;break}if(l)return s}return-1}function st(t,e,r,i){r=Number(r)||0;var n=t.length-r;i?(i=Number(i))>n&&(i=n):i=n;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");i>s/2&&(i=s/2);for(var o=0;o<i;++o){var h=parseInt(e.substr(2*o,2),16);if(isNaN(h))return o;t[r+o]=h}return o}function ot(t,e,r,i){return Ct(St(e,t.length-r),t,r,i)}function ht(t,e,r,i){return Ct(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,i)}function ut(t,e,r,i){return ht(t,e,r,i)}function at(t,e,r,i){return Ct(Rt(e),t,r,i)}function ft(t,e,r,i){return Ct(function(t,e){for(var r,i,n,s=[],o=0;o<t.length&&!((e-=2)<0);++o)i=(r=t.charCodeAt(o))>>8,n=r%256,s.push(n),s.push(i);return s}(e,t.length-r),t,r,i)}function lt(t,e,r){return 0===e&&r===t.length?$(t):$(t.slice(e,r))}function ct(t,e,r){r=Math.min(t.length,r);for(var i=[],n=e;n<r;){var s,o,h,u,a=t[n],f=null,l=a>239?4:a>223?3:a>191?2:1;if(n+l<=r)switch(l){case 1:a<128&&(f=a);break;case 2:128==(192&(s=t[n+1]))&&(u=(31&a)<<6|63&s)>127&&(f=u);break;case 3:s=t[n+1],o=t[n+2],128==(192&s)&&128==(192&o)&&(u=(15&a)<<12|(63&s)<<6|63&o)>2047&&(u<55296||u>57343)&&(f=u);break;case 4:s=t[n+1],o=t[n+2],h=t[n+3],128==(192&s)&&128==(192&o)&&128==(192&h)&&(u=(15&a)<<18|(63&s)<<12|(63&o)<<6|63&h)>65535&&u<1114112&&(f=u)}null===f?(f=65533,l=1):f>65535&&(f-=65536,i.push(f>>>10&1023|55296),f=56320|1023&f),i.push(f),n+=l}return function(t){var e=t.length;if(e<=gt)return String.fromCharCode.apply(String,t);var r="",i=0;for(;i<e;)r+=String.fromCharCode.apply(String,t.slice(i,i+=gt));return r}(i)}H.TYPED_ARRAY_SUPPORT=void 0===_.TYPED_ARRAY_SUPPORT||_.TYPED_ARRAY_SUPPORT,j(),H.poolSize=8192,H._augment=function(t){return t.__proto__=H.prototype,t},H.from=function(t,e,r){return K(null,t,e,r)},H.TYPED_ARRAY_SUPPORT&&(H.prototype.__proto__=Uint8Array.prototype,H.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&H[Symbol.species]),H.alloc=function(t,e,r){return function(t,e,r,i){return X(e),e<=0?Z(t,e):void 0!==r?"string"==typeof i?Z(t,e).fill(r,i):Z(t,e).fill(r):Z(t,e)}(null,t,e,r)},H.allocUnsafe=function(t){return G(null,t)},H.allocUnsafeSlow=function(t){return G(null,t)},H.isBuffer=function(t){return null!=t&&(!!t._isBuffer||xt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&xt(t.slice(0,0))}(t))},H.compare=function(t,e){if(!W(t)||!W(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,i=e.length,n=0,s=Math.min(r,i);n<s;++n)if(t[n]!==e[n]){r=t[n],i=e[n];break}return r<i?-1:i<r?1:0},H.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},H.concat=function(t,e){if(!V(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return H.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var i=H.allocUnsafe(e),n=0;for(r=0;r<t.length;++r){var s=t[r];if(!W(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(i,n),n+=s.length}return i},H.byteLength=tt,H.prototype._isBuffer=!0,H.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)rt(this,e,e+1);return this},H.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)rt(this,e,e+3),rt(this,e+1,e+2);return this},H.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)rt(this,e,e+7),rt(this,e+1,e+6),rt(this,e+2,e+5),rt(this,e+3,e+4);return this},H.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?ct(this,0,t):et.apply(this,arguments)},H.prototype.equals=function(t){if(!W(t))throw new TypeError("Argument must be a Buffer");return this===t||0===H.compare(this,t)},H.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},H.prototype.compare=function(t,e,r,i,n){if(!W(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===i&&(i=0),void 0===n&&(n=this.length),e<0||r>t.length||i<0||n>this.length)throw new RangeError("out of range index");if(i>=n&&e>=r)return 0;if(i>=n)return-1;if(e>=r)return 1;if(this===t)return 0;for(var s=(n>>>=0)-(i>>>=0),o=(r>>>=0)-(e>>>=0),h=Math.min(s,o),u=this.slice(i,n),a=t.slice(e,r),f=0;f<h;++f)if(u[f]!==a[f]){s=u[f],o=a[f];break}return s<o?-1:o<s?1:0},H.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},H.prototype.indexOf=function(t,e,r){return it(this,t,e,r,!0)},H.prototype.lastIndexOf=function(t,e,r){return it(this,t,e,r,!1)},H.prototype.write=function(t,e,r,i){if(void 0===e)i="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)i=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===i&&(i="utf8")):(i=r,r=void 0)}var n=this.length-e;if((void 0===r||r>n)&&(r=n),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var s=!1;;)switch(i){case"hex":return st(this,t,e,r);case"utf8":case"utf-8":return ot(this,t,e,r);case"ascii":return ht(this,t,e,r);case"latin1":case"binary":return ut(this,t,e,r);case"base64":return at(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ft(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),s=!0}},H.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var gt=4096;function pt(t,e,r){var i="";r=Math.min(t.length,r);for(var n=e;n<r;++n)i+=String.fromCharCode(127&t[n]);return i}function yt(t,e,r){var i="";r=Math.min(t.length,r);for(var n=e;n<r;++n)i+=String.fromCharCode(t[n]);return i}function dt(t,e,r){var i=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>i)&&(r=i);for(var n="",s=e;s<r;++s)n+=It(t[s]);return n}function mt(t,e,r){for(var i=t.slice(e,r),n="",s=0;s<i.length;s+=2)n+=String.fromCharCode(i[s]+256*i[s+1]);return n}function bt(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function Bt(t,e,r,i,n,s){if(!W(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>n||e<s)throw new RangeError('"value" argument is out of bounds');if(r+i>t.length)throw new RangeError("Index out of range")}function Tt(t,e,r,i){e<0&&(e=65535+e+1);for(var n=0,s=Math.min(t.length-r,2);n<s;++n)t[r+n]=(e&255<<8*(i?n:1-n))>>>8*(i?n:1-n)}function wt(t,e,r,i){e<0&&(e=4294967295+e+1);for(var n=0,s=Math.min(t.length-r,4);n<s;++n)t[r+n]=e>>>8*(i?n:3-n)&255}function vt(t,e,r,i,n,s){if(r+i>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Et(t,e,r,i,n){return n||vt(t,0,r,4),Y(t,e,r,i,23,4),r+4}function At(t,e,r,i,n){return n||vt(t,0,r,8),Y(t,e,r,i,52,8),r+8}H.prototype.slice=function(t,e){var r,i=this.length;if((t=~~t)<0?(t+=i)<0&&(t=0):t>i&&(t=i),(e=void 0===e?i:~~e)<0?(e+=i)<0&&(e=0):e>i&&(e=i),e<t&&(e=t),H.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=H.prototype;else{var n=e-t;r=new H(n,void 0);for(var s=0;s<n;++s)r[s]=this[s+t]}return r},H.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var i=this[t],n=1,s=0;++s<e&&(n*=256);)i+=this[t+s]*n;return i},H.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var i=this[t+--e],n=1;e>0&&(n*=256);)i+=this[t+--e]*n;return i},H.prototype.readUInt8=function(t,e){return e||bt(t,1,this.length),this[t]},H.prototype.readUInt16LE=function(t,e){return e||bt(t,2,this.length),this[t]|this[t+1]<<8},H.prototype.readUInt16BE=function(t,e){return e||bt(t,2,this.length),this[t]<<8|this[t+1]},H.prototype.readUInt32LE=function(t,e){return e||bt(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},H.prototype.readUInt32BE=function(t,e){return e||bt(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},H.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var i=this[t],n=1,s=0;++s<e&&(n*=256);)i+=this[t+s]*n;return i>=(n*=128)&&(i-=Math.pow(2,8*e)),i},H.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||bt(t,e,this.length);for(var i=e,n=1,s=this[t+--i];i>0&&(n*=256);)s+=this[t+--i]*n;return s>=(n*=128)&&(s-=Math.pow(2,8*e)),s},H.prototype.readInt8=function(t,e){return e||bt(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},H.prototype.readInt16LE=function(t,e){e||bt(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},H.prototype.readInt16BE=function(t,e){e||bt(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},H.prototype.readInt32LE=function(t,e){return e||bt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},H.prototype.readInt32BE=function(t,e){return e||bt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},H.prototype.readFloatLE=function(t,e){return e||bt(t,4,this.length),N(this,t,!0,23,4)},H.prototype.readFloatBE=function(t,e){return e||bt(t,4,this.length),N(this,t,!1,23,4)},H.prototype.readDoubleLE=function(t,e){return e||bt(t,8,this.length),N(this,t,!0,52,8)},H.prototype.readDoubleBE=function(t,e){return e||bt(t,8,this.length),N(this,t,!1,52,8)},H.prototype.writeUIntLE=function(t,e,r,i){(t=+t,e|=0,r|=0,i)||Bt(this,t,e,r,Math.pow(2,8*r)-1,0);var n=1,s=0;for(this[e]=255&t;++s<r&&(n*=256);)this[e+s]=t/n&255;return e+r},H.prototype.writeUIntBE=function(t,e,r,i){(t=+t,e|=0,r|=0,i)||Bt(this,t,e,r,Math.pow(2,8*r)-1,0);var n=r-1,s=1;for(this[e+n]=255&t;--n>=0&&(s*=256);)this[e+n]=t/s&255;return e+r},H.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,1,255,0),H.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},H.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,2,65535,0),H.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Tt(this,t,e,!0),e+2},H.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,2,65535,0),H.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Tt(this,t,e,!1),e+2},H.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,4,4294967295,0),H.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):wt(this,t,e,!0),e+4},H.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,4,4294967295,0),H.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):wt(this,t,e,!1),e+4},H.prototype.writeIntLE=function(t,e,r,i){if(t=+t,e|=0,!i){var n=Math.pow(2,8*r-1);Bt(this,t,e,r,n-1,-n)}var s=0,o=1,h=0;for(this[e]=255&t;++s<r&&(o*=256);)t<0&&0===h&&0!==this[e+s-1]&&(h=1),this[e+s]=(t/o>>0)-h&255;return e+r},H.prototype.writeIntBE=function(t,e,r,i){if(t=+t,e|=0,!i){var n=Math.pow(2,8*r-1);Bt(this,t,e,r,n-1,-n)}var s=r-1,o=1,h=0;for(this[e+s]=255&t;--s>=0&&(o*=256);)t<0&&0===h&&0!==this[e+s+1]&&(h=1),this[e+s]=(t/o>>0)-h&255;return e+r},H.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,1,127,-128),H.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},H.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,2,32767,-32768),H.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):Tt(this,t,e,!0),e+2},H.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,2,32767,-32768),H.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):Tt(this,t,e,!1),e+2},H.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,4,2147483647,-2147483648),H.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):wt(this,t,e,!0),e+4},H.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||Bt(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),H.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):wt(this,t,e,!1),e+4},H.prototype.writeFloatLE=function(t,e,r){return Et(this,t,e,!0,r)},H.prototype.writeFloatBE=function(t,e,r){return Et(this,t,e,!1,r)},H.prototype.writeDoubleLE=function(t,e,r){return At(this,t,e,!0,r)},H.prototype.writeDoubleBE=function(t,e,r){return At(this,t,e,!1,r)},H.prototype.copy=function(t,e,r,i){if(r||(r=0),i||0===i||(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&i<r&&(i=r),i===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-e<i-r&&(i=t.length-e+r);var n,s=i-r;if(this===t&&r<e&&e<i)for(n=s-1;n>=0;--n)t[n+e]=this[n+r];else if(s<1e3||!H.TYPED_ARRAY_SUPPORT)for(n=0;n<s;++n)t[n+e]=this[n+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+s),e);return s},H.prototype.fill=function(t,e,r,i){if("string"==typeof t){if("string"==typeof e?(i=e,e=0,r=this.length):"string"==typeof r&&(i=r,r=this.length),1===t.length){var n=t.charCodeAt(0);n<256&&(t=n)}if(void 0!==i&&"string"!=typeof i)throw new TypeError("encoding must be a string");if("string"==typeof i&&!H.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var s;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(s=e;s<r;++s)this[s]=t;else{var o=W(t)?t:St(new H(t,i).toString()),h=o.length;for(s=0;s<r-e;++s)this[s+e]=o[s%h]}return this};var Ft=/[^+\/0-9A-Za-z-_]/g;function It(t){return t<16?"0"+t.toString(16):t.toString(16)}function St(t,e){var r;e=e||1/0;for(var i=t.length,n=null,s=[],o=0;o<i;++o){if((r=t.charCodeAt(o))>55295&&r<57344){if(!n){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===i){(e-=3)>-1&&s.push(239,191,189);continue}n=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),n=r;continue}r=65536+(n-55296<<10|r-56320)}else n&&(e-=3)>-1&&s.push(239,191,189);if(n=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function Rt(t){return function(t){var e,r,i,n,s,o;M||U();var h=t.length;if(h%4>0)throw new Error("Invalid string. Length must be a multiple of 4");s="="===t[h-2]?2:"="===t[h-1]?1:0,o=new q(3*h/4-s),i=s>0?h-4:h;var u=0;for(e=0,r=0;e<i;e+=4,r+=3)n=P[t.charCodeAt(e)]<<18|P[t.charCodeAt(e+1)]<<12|P[t.charCodeAt(e+2)]<<6|P[t.charCodeAt(e+3)],o[u++]=n>>16&255,o[u++]=n>>8&255,o[u++]=255&n;return 2===s?(n=P[t.charCodeAt(e)]<<2|P[t.charCodeAt(e+1)]>>4,o[u++]=255&n):1===s&&(n=P[t.charCodeAt(e)]<<10|P[t.charCodeAt(e+1)]<<4|P[t.charCodeAt(e+2)]>>2,o[u++]=n>>8&255,o[u++]=255&n),o}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Ft,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Ct(t,e,r,i){for(var n=0;n<i&&!(n+r>=e.length||n>=t.length);++n)e[n+r]=t[n];return n}function xt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}const Dt="undefined"!=typeof process&&null!==process.versions&&null!==process.versions.node,Lt=(()=>{let t;return("undefined"==typeof navigator||"ReactNative"!==(t=navigator.product)&&"NativeScript"!==t&&"NS"!==t)&&("undefined"!=typeof window&&"undefined"!=typeof document)})();const _t={bufToBin(t){if(Lt){let e="";return t.forEach((t=>{e+=String.fromCharCode(t)})),e}return Buffer.from(t).toString("binary")},strToBin(t){if(Lt){return encodeURIComponent(t).replace(/%([0-9A-F]{2})/g,((t,e)=>String.fromCharCode(`0x${e}`)))}return Buffer.from(t).toString("binary")},binToBuf(t){if(Lt){return t.split("").map((t=>t.charCodeAt(0)))}return Buffer.from(t,"binary")},strToBuf:t=>Lt?_t.binToBuf(_t.strToBin(t)):Buffer.from(t),binToStr(t){if(Lt){const e=t.replace(/(.)/g,((t,e)=>{let r=e.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r=`0${r}`),`%${r}`}));return decodeURIComponent(e)}return _t.binToBuf(t).toString("utf8")},bufToStr:t=>Lt?_t.binToStr(_t.bufToBin(t)):Buffer.from(t).toString("utf8")},Ot={bufToBase64(t){if(Lt){let e="";return t.forEach((t=>{e+=String.fromCharCode(t)})),btoa(e)}return Buffer.from(t).toString("base64")},strToBase64:t=>Lt?btoa(_t.strToBin(t)):Buffer.from(t).toString("base64"),urlBase64ToBase64(t){let e=t.replace(/^\s+|\s+$/g,"");const r=e.length%4;return 2===r?e+="==":3===r&&(e+="="),e.replace(/-/g,"+").replace(/_/g,"/")},base64ToUrlBase64:t=>t.replace(/^\s+|\s+$/g,"").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),_base64ToBin:t=>atob(Ot.urlBase64ToBase64(t)),base64ToBuf:t=>Lt?_t.binToBuf(Ot._base64ToBin(t)):Buffer.from(t,"base64"),base64ToStr:t=>_t.binToStr(Ot._base64ToBin(t)),bufToUrlBase64:t=>Ot.base64ToUrlBase64(Ot.bufToBase64(t)),strToUrlBase64:t=>Lt?Ot.bufToUrlBase64(_t.strToBuf(t)):Ot.base64ToUrlBase64(Ot.bufToBase64(Buffer.from(t))),base64ToHex:t=>Lt?Pt.bufToHex(Ot.base64ToBuf(t)):Buffer.from(t,"base64").toString("hex")},Pt={bufToHex(t){if(Lt){const e=new Uint8Array(t);let r="";for(const t of e){const e=t.toString(16);r+=1===e.length?`0${e}`:e}return r}return Buffer.from(t).toString("hex")},numToHex(t){const e=t.toString(16);return e.length%2?`0${t}`:e},_binToHex:t=>t.split("").map((t=>{let e=t.charCodeAt(0).toString(16);return 2!==e.length&&(e=`0${e}`),e})).join(""),strToHex:t=>Lt?Pt._binToHex(_t.strToBin(t)):Buffer.from(t).toString("hex"),hexToBuf(t){if(Lt){const e=[];return t.match(/.{2}/g).forEach((t=>{e.push(parseInt(t,16))})),"undefined"!=typeof Uint8Array?new Uint8Array(e):e}return Buffer.from(t,"hex")},_hexToBin:t=>t.replace(/([0-9A-F]{2})/gi,((t,e)=>String.fromCharCode(`0x${e}`))),hexToStr:t=>Lt?_t.binToStr(Pt._hexToBin(t)):Pt.hexToBuf(t).toString("utf8"),hexToBase64:t=>Lt?btoa(Pt._hexToBin(t)):Buffer.from(t,"hex").toString("base64")};var qt=Object.assign(Object.assign(Object.assign({},_t),Ot),Pt);function Mt(t){let e="";switch(t){case 0:e="EOC";break;case 1:e="BOOLEAN";break;case 2:e="INTEGER";break;case 3:e="BIT_STRING";break;case 4:e="OCTET_STRING";break;case 5:e="NULL";break;case 6:e="OBJECT_IDENTIFIER";break;case 7:e="ObjectDescriptor";break;case 8:e="EXTERNAL";break;case 9:e="REAL";break;case 10:e="ENUMERATED";break;case 11:e="EMBEDDED_PDV";break;case 12:e="UTF8String";break;case 13:e="RELATIVE_OID";break;case 16:e="SEQUENCE";break;case 17:e="SET";break;case 18:e="NumericString";break;case 19:e="PrintableString";break;case 20:e="TeletexString";break;case 21:e="VideotexString";break;case 22:e="IA5String";break;case 23:e="UTCTime";break;case 24:e="GeneralizedTime";break;case 25:e="GraphicString";break;case 26:e="VisibleString";break;case 27:e="GeneralString";break;case 28:e="UniversalString";break;case 29:e="CHARACTERString";break;case 30:e="BMPString";break;default:e=`Universal_${t.toString()}`}return e}const Ut=4;function kt(t){let e="",r=0;for(let i=0;i<t.length;i+=2){if(r=parseInt(t.substr(i,2),16),10!==r&&(r<32||r>126))return t;e+=String.fromCharCode(r)}return e}function $t(t){let e=0,r="";for(;e<t.length;){const i=parseInt(`0x${t.substr(e,2)}`,16),n=32&i,s=128&i,o=31&i;let h=s?`[${o}]`:Mt(o);void 0===h&&(h=`[${t.substr(e,2)}]`),e+=2;let u=0;if(5!==o){const r=127&parseInt(`0x${t.substr(e,2)}`,16);if(128&parseInt(`0x${t.substr(e,2)}`,16)){if(r>2)return`!TagLengthTooBig4BytesMax: ${kt(t)}`;u=parseInt(`0x${t.substr(e+2,2*r)}`,16),e+=2*r+2}else 0!==r&&(u=parseInt(`0x${t.substr(e,2)}`,16),e+=2);if(u>t.length-e)return`!TagLengthBiggerThanData(Overflow): ${kt(t)}`}else