New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

request-crypto

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-crypto - npm Package Compare versions

Comparing version 1.4.3 to 1.4.4

2

dist/index.cjs.js

@@ -1,1 +0,1 @@

"use strict";var t=require("axios"),r=require("buffer");var e,i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o={exports:{}};e=o,function(){var t;function r(t,r,e){null!=t&&("number"==typeof t?this.fromNumber(t,r,e):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}function i(){return new r(null)}var o="undefined"!=typeof navigator;o&&"Microsoft Internet Explorer"==navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(var s=32767&r,h=r>>15;--n>=0;){var u=32767&this[t],a=this[t++]>>15,f=h*u+a*s;o=((u=s*u+((32767&f)<<15)+e[i]+(1073741823&o))>>>30)+(f>>>15)+h*a+(o>>>30),e[i++]=1073741823&u}return o},t=30):o&&"Netscape"!=navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(;--n>=0;){var s=r*this[t++]+e[i]+o;o=Math.floor(s/67108864),e[i++]=67108863&s}return o},t=26):(r.prototype.am=function(t,r,e,i,o,n){for(var s=16383&r,h=r>>14;--n>=0;){var u=16383&this[t],a=this[t++]>>14,f=h*u+a*s;o=((u=s*u+((16383&f)<<14)+e[i]+o)>>28)+(f>>14)+h*a,e[i++]=268435455&u}return o},t=28),r.prototype.DB=t,r.prototype.DM=(1<<t)-1,r.prototype.DV=1<<t,r.prototype.FV=Math.pow(2,52),r.prototype.F1=52-t,r.prototype.F2=2*t-52;var n,s,h="0123456789abcdefghijklmnopqrstuvwxyz",u=new Array;for(n="0".charCodeAt(0),s=0;s<=9;++s)u[n++]=s;for(n="a".charCodeAt(0),s=10;s<36;++s)u[n++]=s;for(n="A".charCodeAt(0),s=10;s<36;++s)u[n++]=s;function a(t){return h.charAt(t)}function f(t,r){var e=u[t.charCodeAt(r)];return null==e?-1:e}function c(t){var r=i();return r.fromInt(t),r}function l(t){var r,e=1;return 0!=(r=t>>>16)&&(t=r,e+=16),0!=(r=t>>8)&&(t=r,e+=8),0!=(r=t>>4)&&(t=r,e+=4),0!=(r=t>>2)&&(t=r,e+=2),0!=(r=t>>1)&&(t=r,e+=1),e}function p(t){this.m=t}function y(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}function m(t,r){return t&r}function g(t,r){return t|r}function d(t,r){return t^r}function v(t,r){return t&~r}function w(t){if(0==t)return-1;var r=0;return 65535&t||(t>>=16,r+=16),255&t||(t>>=8,r+=8),15&t||(t>>=4,r+=4),3&t||(t>>=2,r+=2),1&t||++r,r}function T(t){for(var r=0;0!=t;)t&=t-1,++r;return r}function F(){}function b(t){return t}function B(t){this.r2=i(),this.q3=i(),r.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}p.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},p.prototype.revert=function(t){return t},p.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},p.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},p.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},y.prototype.convert=function(t){var e=i();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(r.ZERO)>0&&this.m.subTo(e,e),e},y.prototype.revert=function(t){var r=i();return t.copyTo(r),this.reduce(r),r},y.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var e=32767&t[r],i=e*this.mpl+((e*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[e=r+this.m.t]+=this.m.am(0,i,t,r,0,this.m.t);t[e]>=t.DV;)t[e]-=t.DV,t[++e]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},y.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},y.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},r.prototype.copyTo=function(t){for(var r=this.t-1;r>=0;--r)t[r]=this[r];t.t=this.t,t.s=this.s},r.prototype.fromInt=function(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},r.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var o=t.length,n=!1,s=0;--o>=0;){var h=8==i?255&t[o]:f(t,o);h<0?"-"==t.charAt(o)&&(n=!0):(n=!1,0==s?this[this.t++]=h:s+i>this.DB?(this[this.t-1]|=(h&(1<<this.DB-s)-1)<<s,this[this.t++]=h>>this.DB-s):this[this.t-1]|=h<<s,(s+=i)>=this.DB&&(s-=this.DB))}8==i&&128&t[0]&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&r.ZERO.subTo(this,this)},r.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},r.prototype.dlShiftTo=function(t,r){var e;for(e=this.t-1;e>=0;--e)r[e+t]=this[e];for(e=t-1;e>=0;--e)r[e]=0;r.t=this.t+t,r.s=this.s},r.prototype.drShiftTo=function(t,r){for(var e=t;e<this.t;++e)r[e-t]=this[e];r.t=Math.max(this.t-t,0),r.s=this.s},r.prototype.lShiftTo=function(t,r){var e,i=t%this.DB,o=this.DB-i,n=(1<<o)-1,s=Math.floor(t/this.DB),h=this.s<<i&this.DM;for(e=this.t-1;e>=0;--e)r[e+s+1]=this[e]>>o|h,h=(this[e]&n)<<i;for(e=s-1;e>=0;--e)r[e]=0;r[s]=h,r.t=this.t+s+1,r.s=this.s,r.clamp()},r.prototype.rShiftTo=function(t,r){r.s=this.s;var e=Math.floor(t/this.DB);if(e>=this.t)r.t=0;else{var i=t%this.DB,o=this.DB-i,n=(1<<i)-1;r[0]=this[e]>>i;for(var s=e+1;s<this.t;++s)r[s-e-1]|=(this[s]&n)<<o,r[s-e]=this[s]>>i;i>0&&(r[this.t-e-1]|=(this.s&n)<<o),r.t=this.t-e,r.clamp()}},r.prototype.subTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]-t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i-=t[e],r[e++]=i&this.DM,i>>=this.DB;i-=t.s}r.s=i<0?-1:0,i<-1?r[e++]=this.DV+i:i>0&&(r[e++]=i),r.t=e,r.clamp()},r.prototype.multiplyTo=function(t,e){var i=this.abs(),o=t.abs(),n=i.t;for(e.t=n+o.t;--n>=0;)e[n]=0;for(n=0;n<o.t;++n)e[n+i.t]=i.am(0,o[n],e,n,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&r.ZERO.subTo(e,e)},r.prototype.squareTo=function(t){for(var r=this.abs(),e=t.t=2*r.t;--e>=0;)t[e]=0;for(e=0;e<r.t-1;++e){var i=r.am(e,r[e],t,2*e,0,1);(t[e+r.t]+=r.am(e+1,2*r[e],t,2*e+1,i,r.t-e-1))>=r.DV&&(t[e+r.t]-=r.DV,t[e+r.t+1]=1)}t.t>0&&(t[t.t-1]+=r.am(e,r[e],t,2*e,0,1)),t.s=0,t.clamp()},r.prototype.divRemTo=function(t,e,o){var n=t.abs();if(!(n.t<=0)){var s=this.abs();if(s.t<n.t)return null!=e&&e.fromInt(0),void(null!=o&&this.copyTo(o));null==o&&(o=i());var h=i(),u=this.s,a=t.s,f=this.DB-l(n[n.t-1]);f>0?(n.lShiftTo(f,h),s.lShiftTo(f,o)):(n.copyTo(h),s.copyTo(o));var c=h.t,p=h[c-1];if(0!=p){var y=p*(1<<this.F1)+(c>1?h[c-2]>>this.F2:0),m=this.FV/y,g=(1<<this.F1)/y,d=1<<this.F2,v=o.t,w=v-c,T=null==e?i():e;for(h.dlShiftTo(w,T),o.compareTo(T)>=0&&(o[o.t++]=1,o.subTo(T,o)),r.ONE.dlShiftTo(c,T),T.subTo(h,h);h.t<c;)h[h.t++]=0;for(;--w>=0;){var F=o[--v]==p?this.DM:Math.floor(o[v]*m+(o[v-1]+d)*g);if((o[v]+=h.am(0,F,o,w,0,c))<F)for(h.dlShiftTo(w,T),o.subTo(T,o);o[v]<--F;)o.subTo(T,o)}null!=e&&(o.drShiftTo(c,e),u!=a&&r.ZERO.subTo(e,e)),o.t=c,o.clamp(),f>0&&o.rShiftTo(f,o),u<0&&r.ZERO.subTo(o,o)}}},r.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var r=3&t;return(r=(r=(r=(r=r*(2-(15&t)*r)&15)*(2-(255&t)*r)&255)*(2-((65535&t)*r&65535))&65535)*(2-t*r%this.DV)%this.DV)>0?this.DV-r:-r},r.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},r.prototype.exp=function(t,e){if(t>4294967295||t<1)return r.ONE;var o=i(),n=i(),s=e.convert(this),h=l(t)-1;for(s.copyTo(o);--h>=0;)if(e.sqrTo(o,n),(t&1<<h)>0)e.mulTo(n,s,o);else{var u=o;o=n,n=u}return e.revert(o)},r.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return this.toRadix(t);r=2}var e,i=(1<<r)-1,o=!1,n="",s=this.t,h=this.DB-s*this.DB%r;if(s-- >0)for(h<this.DB&&(e=this[s]>>h)>0&&(o=!0,n=a(e));s>=0;)h<r?(e=(this[s]&(1<<h)-1)<<r-h,e|=this[--s]>>(h+=this.DB-r)):(e=this[s]>>(h-=r)&i,h<=0&&(h+=this.DB,--s)),e>0&&(o=!0),o&&(n+=a(e));return o?n:"0"},r.prototype.negate=function(){var t=i();return r.ZERO.subTo(this,t),t},r.prototype.abs=function(){return this.s<0?this.negate():this},r.prototype.compareTo=function(t){var r=this.s-t.s;if(0!=r)return r;var e=this.t;if(0!=(r=e-t.t))return this.s<0?-r:r;for(;--e>=0;)if(0!=(r=this[e]-t[e]))return r;return 0},r.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+l(this[this.t-1]^this.s&this.DM)},r.prototype.mod=function(t){var e=i();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(r.ZERO)>0&&t.subTo(e,e),e},r.prototype.modPowInt=function(t,r){var e;return e=t<256||r.isEven()?new p(r):new y(r),this.exp(t,e)},r.ZERO=c(0),r.ONE=c(1),F.prototype.convert=b,F.prototype.revert=b,F.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e)},F.prototype.sqrTo=function(t,r){t.squareTo(r)},B.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=i();return t.copyTo(r),this.reduce(r),r},B.prototype.revert=function(t){return t},B.prototype.reduce=function(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)},B.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},B.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)};var x,q,E,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],I=(1<<26)/D[D.length-1];function S(){var t;t=(new Date).getTime(),q[E++]^=255&t,q[E++]^=t>>8&255,q[E++]^=t>>16&255,q[E++]^=t>>24&255,E>=H&&(E-=H)}if(r.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},r.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var r=this.chunkSize(t),e=Math.pow(t,r),o=c(e),n=i(),s=i(),h="";for(this.divRemTo(o,n,s);n.signum()>0;)h=(e+s.intValue()).toString(t).substr(1)+h,n.divRemTo(o,n,s);return s.intValue().toString(t)+h},r.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),o=Math.pow(e,i),n=!1,s=0,h=0,u=0;u<t.length;++u){var a=f(t,u);a<0?"-"==t.charAt(u)&&0==this.signum()&&(n=!0):(h=e*h+a,++s>=i&&(this.dMultiply(o),this.dAddOffset(h,0),s=0,h=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(h,0)),n&&r.ZERO.subTo(this,this)},r.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(r.ONE.shiftLeft(t-1),g,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(r.ONE.shiftLeft(t-1),this);else{var o=new Array,n=7&t;o.length=1+(t>>3),e.nextBytes(o),n>0?o[0]&=(1<<n)-1:o[0]=0,this.fromString(o,256)}},r.prototype.bitwiseTo=function(t,r,e){var i,o,n=Math.min(t.t,this.t);for(i=0;i<n;++i)e[i]=r(this[i],t[i]);if(t.t<this.t){for(o=t.s&this.DM,i=n;i<this.t;++i)e[i]=r(this[i],o);e.t=this.t}else{for(o=this.s&this.DM,i=n;i<t.t;++i)e[i]=r(o,t[i]);e.t=t.t}e.s=r(this.s,t.s),e.clamp()},r.prototype.changeBit=function(t,e){var i=r.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i},r.prototype.addTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]+t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i+=t[e],r[e++]=i&this.DM,i>>=this.DB;i+=t.s}r.s=i<0?-1:0,i>0?r[e++]=i:i<-1&&(r[e++]=this.DV+i),r.t=e,r.clamp()},r.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},r.prototype.dAddOffset=function(t,r){if(0!=t){for(;this.t<=r;)this[this.t++]=0;for(this[r]+=t;this[r]>=this.DV;)this[r]-=this.DV,++r>=this.t&&(this[this.t++]=0),++this[r]}},r.prototype.multiplyLowerTo=function(t,r,e){var i,o=Math.min(this.t+t.t,r);for(e.s=0,e.t=o;o>0;)e[--o]=0;for(i=e.t-this.t;o<i;++o)e[o+this.t]=this.am(0,t[o],e,o,0,this.t);for(i=Math.min(t.t,r);o<i;++o)this.am(0,t[o],e,o,0,r-o);e.clamp()},r.prototype.multiplyUpperTo=function(t,r,e){--r;var i=e.t=this.t+t.t-r;for(e.s=0;--i>=0;)e[i]=0;for(i=Math.max(r-this.t,0);i<t.t;++i)e[this.t+i-r]=this.am(r-i,t[i],e,0,0,this.t+i-r);e.clamp(),e.drShiftTo(1,e)},r.prototype.modInt=function(t){if(t<=0)return 0;var r=this.DV%t,e=this.s<0?t-1:0;if(this.t>0)if(0==r)e=this[0]%t;else for(var i=this.t-1;i>=0;--i)e=(r*e+this[i])%t;return e},r.prototype.millerRabin=function(t){var e=this.subtract(r.ONE),o=e.getLowestSetBit();if(o<=0)return!1;var n=e.shiftRight(o);(t=t+1>>1)>D.length&&(t=D.length);for(var s=i(),h=0;h<t;++h){s.fromInt(D[Math.floor(Math.random()*D.length)]);var u=s.modPow(n,this);if(0!=u.compareTo(r.ONE)&&0!=u.compareTo(e)){for(var a=1;a++<o&&0!=u.compareTo(e);)if(0==(u=u.modPowInt(2,this)).compareTo(r.ONE))return!1;if(0!=u.compareTo(e))return!1}}return!0},r.prototype.clone=function(){var t=i();return this.copyTo(t),t},r.prototype.intValue=function(){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]},r.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},r.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},r.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},r.prototype.toByteArray=function(){var t=this.t,r=new Array;r[0]=this.s;var e,i=this.DB-t*this.DB%8,o=0;if(t-- >0)for(i<this.DB&&(e=this[t]>>i)!=(this.s&this.DM)>>i&&(r[o++]=e|this.s<<this.DB-i);t>=0;)i<8?(e=(this[t]&(1<<i)-1)<<8-i,e|=this[--t]>>(i+=this.DB-8)):(e=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),128&e&&(e|=-256),0==o&&(128&this.s)!=(128&e)&&++o,(o>0||e!=this.s)&&(r[o++]=e);return r},r.prototype.equals=function(t){return 0==this.compareTo(t)},r.prototype.min=function(t){return this.compareTo(t)<0?this:t},r.prototype.max=function(t){return this.compareTo(t)>0?this:t},r.prototype.and=function(t){var r=i();return this.bitwiseTo(t,m,r),r},r.prototype.or=function(t){var r=i();return this.bitwiseTo(t,g,r),r},r.prototype.xor=function(t){var r=i();return this.bitwiseTo(t,d,r),r},r.prototype.andNot=function(t){var r=i();return this.bitwiseTo(t,v,r),r},r.prototype.not=function(){for(var t=i(),r=0;r<this.t;++r)t[r]=this.DM&~this[r];return t.t=this.t,t.s=~this.s,t},r.prototype.shiftLeft=function(t){var r=i();return t<0?this.rShiftTo(-t,r):this.lShiftTo(t,r),r},r.prototype.shiftRight=function(t){var r=i();return t<0?this.lShiftTo(-t,r):this.rShiftTo(t,r),r},r.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+w(this[t]);return this.s<0?this.t*this.DB:-1},r.prototype.bitCount=function(){for(var t=0,r=this.s&this.DM,e=0;e<this.t;++e)t+=T(this[e]^r);return t},r.prototype.testBit=function(t){var r=Math.floor(t/this.DB);return r>=this.t?0!=this.s:!!(this[r]&1<<t%this.DB)},r.prototype.setBit=function(t){return this.changeBit(t,g)},r.prototype.clearBit=function(t){return this.changeBit(t,v)},r.prototype.flipBit=function(t){return this.changeBit(t,d)},r.prototype.add=function(t){var r=i();return this.addTo(t,r),r},r.prototype.subtract=function(t){var r=i();return this.subTo(t,r),r},r.prototype.multiply=function(t){var r=i();return this.multiplyTo(t,r),r},r.prototype.divide=function(t){var r=i();return this.divRemTo(t,r,null),r},r.prototype.remainder=function(t){var r=i();return this.divRemTo(t,null,r),r},r.prototype.divideAndRemainder=function(t){var r=i(),e=i();return this.divRemTo(t,r,e),new Array(r,e)},r.prototype.modPow=function(t,r){var e,o,n=t.bitLength(),s=c(1);if(n<=0)return s;e=n<18?1:n<48?3:n<144?4:n<768?5:6,o=n<8?new p(r):r.isEven()?new B(r):new y(r);var h=new Array,u=3,a=e-1,f=(1<<e)-1;if(h[1]=o.convert(this),e>1){var m=i();for(o.sqrTo(h[1],m);u<=f;)h[u]=i(),o.mulTo(m,h[u-2],h[u]),u+=2}var g,d,v=t.t-1,w=!0,T=i();for(n=l(t[v])-1;v>=0;){for(n>=a?g=t[v]>>n-a&f:(g=(t[v]&(1<<n+1)-1)<<a-n,v>0&&(g|=t[v-1]>>this.DB+n-a)),u=e;!(1&g);)g>>=1,--u;if((n-=u)<0&&(n+=this.DB,--v),w)h[g].copyTo(s),w=!1;else{for(;u>1;)o.sqrTo(s,T),o.sqrTo(T,s),u-=2;u>0?o.sqrTo(s,T):(d=s,s=T,T=d),o.mulTo(T,h[g],s)}for(;v>=0&&!(t[v]&1<<n);)o.sqrTo(s,T),d=s,s=T,T=d,--n<0&&(n=this.DB-1,--v)}return o.revert(s)},r.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return r.ZERO;for(var i=t.clone(),o=this.clone(),n=c(1),s=c(0),h=c(0),u=c(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),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(;o.isEven();)o.rShiftTo(1,o),e?(h.isEven()&&u.isEven()||(h.addTo(this,h),u.subTo(t,u)),h.rShiftTo(1,h)):u.isEven()||u.subTo(t,u),u.rShiftTo(1,u);i.compareTo(o)>=0?(i.subTo(o,i),e&&n.subTo(h,n),s.subTo(u,s)):(o.subTo(i,o),e&&h.subTo(n,h),u.subTo(s,u))}return 0!=o.compareTo(r.ONE)?r.ZERO:u.compareTo(t)>=0?u.subtract(t):u.signum()<0?(u.addTo(t,u),u.signum()<0?u.add(t):u):u},r.prototype.pow=function(t){return this.exp(t,new F)},r.prototype.gcd=function(t){var r=this.s<0?this.negate():this.clone(),e=t.s<0?t.negate():t.clone();if(r.compareTo(e)<0){var i=r;r=e,e=i}var o=r.getLowestSetBit(),n=e.getLowestSetBit();if(n<0)return r;for(o<n&&(n=o),n>0&&(r.rShiftTo(n,r),e.rShiftTo(n,e));r.signum()>0;)(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),r.compareTo(e)>=0?(r.subTo(e,r),r.rShiftTo(1,r)):(e.subTo(r,e),e.rShiftTo(1,e));return n>0&&e.lShiftTo(n,e),e},r.prototype.isProbablePrime=function(t){var r,e=this.abs();if(1==e.t&&e[0]<=D[D.length-1]){for(r=0;r<D.length;++r)if(e[0]==D[r])return!0;return!1}if(e.isEven())return!1;for(r=1;r<D.length;){for(var i=D[r],o=r+1;o<D.length&&i<I;)i*=D[o++];for(i=e.modInt(i);r<o;)if(i%D[r++]==0)return!1}return e.millerRabin(t)},r.prototype.square=function(){var t=i();return this.squareTo(t),t},r.prototype.Barrett=B,null==q){var A;if(q=new Array,E=0,"undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var R=new Uint8Array(32);for(window.crypto.getRandomValues(R),A=0;A<32;++A)q[E++]=R[A]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var P=window.crypto.random(32);for(A=0;A<P.length;++A)q[E++]=255&P.charCodeAt(A)}for(;E<H;)A=Math.floor(65536*Math.random()),q[E++]=A>>>8,q[E++]=255&A;E=0,S()}function O(){if(null==x){for(S(),(x=new M).init(q),E=0;E<q.length;++E)q[E]=0;E=0}return x.next()}function C(){}function M(){this.i=0,this.j=0,this.S=new Array}C.prototype.nextBytes=function(t){var r;for(r=0;r<t.length;++r)t[r]=O()},M.prototype.init=function(t){var r,e,i;for(r=0;r<256;++r)this.S[r]=r;for(e=0,r=0;r<256;++r)e=e+this.S[r]+t[r%t.length]&255,i=this.S[r],this.S[r]=this.S[e],this.S[e]=i;this.i=0,this.j=0},M.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var H=256;e.exports={default:r,BigInteger:r,SecureRandom:C}}.call(i);var n=o.exports;const{BigInteger:s}=n;class h{constructor(){this.tlv=null,this.t="00",this.l="00",this.v=""}getEncodedHex(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}getLength(){const t=this.v.length/2;let r=t.toString(16);if(r.length%2==1&&(r="0"+r),t<128)return r;return(128+r.length/2).toString(16)+r}getValue(){return""}}class u extends h{constructor(t){super(),this.t="02",t&&(this.v=function(t){let r=t.toString(16);if("-"!==r[0])r.length%2==1?r="0"+r:r.match(/^[0-7]/)||(r="00"+r);else{r=r.substr(1);let e=r.length;e%2==1?e+=1:r.match(/^[0-7]/)||(e+=2);let i="";for(let t=0;t<e;t++)i+="f";i=new s(i,16),r=i.xor(t).add(s.ONE),r=r.toString(16).replace(/^-/,"")}return r}(t))}getValue(){return this.v}}class a extends h{constructor(t){super(),this.t="30",this.asn1Array=t}getValue(){return this.v=this.asn1Array.map((t=>t.getEncodedHex())).join(""),this.v}}function f(t,r){return+t[r+2]<8?1:128&+t.substr(r+2,2)}function c(t,r){const e=f(t,r),i=t.substr(r+2,2*e);if(!i)return-1;return(+i[0]<8?new s(i,16):new s(i.substr(2),16)).intValue()}function l(t,r){return r+2*(f(t,r)+1)}var p={encodeDer(t,r){const e=new u(t),i=new u(r);return new a([e,i]).getEncodedHex()},decodeDer(t){const r=l(t,0),e=l(t,r),i=c(t,r),o=t.substr(e,2*i),n=e+o.length,h=l(t,n),u=c(t,n),a=t.substr(h,2*u);return{r:new s(o,16),s:new s(a,16)}}};const{BigInteger:y}=n,m=new y("2"),g=new y("3");class d{constructor(t,r){this.x=r,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 d(this.q,this.x.negate().mod(this.q))}add(t){return new d(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new d(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new d(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}divide(t){return new d(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}square(){return new d(this.q,this.x.square().mod(this.q))}}class v{constructor(t,r,e,i){this.curve=t,this.x=r,this.y=e,this.z=null==i?y.ONE:i,this.zinv=null}getX(){return null===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&&(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(y.ZERO))return!1;return t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(y.ZERO)}isInfinity(){return null===this.x&&null===this.y||this.z.equals(y.ZERO)&&!this.y.toBigInteger().equals(y.ZERO)}negate(){return new v(this.curve,this.x,this.y.negate(),this.z)}add(t){if(this.isInfinity())return t;if(t.isInfinity())return this;const r=this.x.toBigInteger(),e=this.y.toBigInteger(),i=this.z,o=t.x.toBigInteger(),n=t.y.toBigInteger(),s=t.z,h=this.curve.q,u=r.multiply(s).mod(h),a=o.multiply(i).mod(h),f=u.subtract(a),c=e.multiply(s).mod(h),l=n.multiply(i).mod(h),p=c.subtract(l);if(y.ZERO.equals(f))return y.ZERO.equals(p)?this.twice():this.curve.infinity;const m=u.add(a),g=i.multiply(s).mod(h),d=f.square().mod(h),w=f.multiply(d).mod(h),T=g.multiply(p.square()).subtract(m.multiply(d)).mod(h),F=f.multiply(T).mod(h),b=p.multiply(d.multiply(u).subtract(T)).subtract(c.multiply(w)).mod(h),B=w.multiply(g).mod(h);return new v(this.curve,this.curve.fromBigInteger(F),this.curve.fromBigInteger(b),B)}twice(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;const t=this.x.toBigInteger(),r=this.y.toBigInteger(),e=this.z,i=this.curve.q,o=this.curve.a.toBigInteger(),n=t.square().multiply(g).add(o.multiply(e.square())).mod(i),s=r.shiftLeft(1).multiply(e).mod(i),h=r.square().mod(i),u=h.multiply(t).multiply(e).mod(i),a=s.square().mod(i),f=n.square().subtract(u.shiftLeft(3)).mod(i),c=s.multiply(f).mod(i),l=n.multiply(u.shiftLeft(2).subtract(f)).subtract(a.shiftLeft(1).multiply(h)).mod(i),p=s.multiply(a).mod(i);return new v(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(l),p)}multiply(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;const r=t.multiply(g),e=this.negate();let i=this;for(let o=r.bitLength()-2;o>0;o--){i=i.twice();const n=r.testBit(o);n!==t.testBit(o)&&(i=i.add(n?this:e))}return i}}var w={ECPointFp:v,ECCurveFp:class{constructor(t,r,e){this.q=t,this.a=this.fromBigInteger(r),this.b=this.fromBigInteger(e),this.infinity=new v(this,null,null)}equals(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}fromBigInteger(t){return new d(this.q,t)}decodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:const r=this.fromBigInteger(new y(t.substr(2),16));let e=this.fromBigInteger(r.multiply(r.square()).add(r.multiply(this.a)).add(this.b).toBigInteger().modPow(this.q.divide(new y("4")).add(y.ONE),this.q));return e.toBigInteger().mod(m).equals(new y(t.substr(0,2),16).subtract(m))||(e=e.negate()),new v(this,r,e);case 4:case 6:case 7:const i=(t.length-2)/2,o=t.substr(2,i),n=t.substr(i+2,i);return new v(this,this.fromBigInteger(new y(o,16)),this.fromBigInteger(new y(n,16)));default:return null}}}};const{BigInteger:T,SecureRandom:F}=n,{ECCurveFp:b}=w,B=new F,{curve:x,G:q,n:E}=D();function D(){const t=new T("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),r=new T("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),e=new T("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),i=new b(t,r,e),o=i.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");return{curve:i,G:o,n:new T("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function I(t,r){return t.length>=r?t:new Array(r-t.length+1).join("0")+t}var S={getGlobalCurve:function(){return x},generateEcparam:D,generateKeyPairHex:function(t,r,e){const i=(t?new T(t,r,e):new T(E.bitLength(),B)).mod(E.subtract(T.ONE)).add(T.ONE),o=I(i.toString(16),64),n=q.multiply(i);return{privateKey:o,publicKey:"04"+I(n.getX().toBigInteger().toString(16),64)+I(n.getY().toBigInteger().toString(16),64)}},compressPublicKeyHex:function(t){if(130!==t.length)throw new Error("Invalid public key to compress");const r=(t.length-2)/2,e=t.substr(2,r);let i="03";return new T(t.substr(r+2,r),16).mod(new T("2")).equals(T.ZERO)&&(i="02"),i+e},utf8ToHex:function(t){const r=(t=unescape(encodeURIComponent(t))).length,e=[];for(let i=0;i<r;i++)e[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;const i=[];for(let t=0;t<r;t++){const r=e[t>>>2]>>>24-t%4*8&255;i.push((r>>>4).toString(16)),i.push((15&r).toString(16))}return i.join("")},leftPad:I,arrayToHex:function(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")},arrayToUtf8:function(t){const r=[];let e=0;for(let i=0;i<2*t.length;i+=2)r[i>>>3]|=parseInt(t[e],10)<<24-i%8*4,e++;try{const e=[];for(let i=0;i<t.length;i++){const t=r[i>>>2]>>>24-i%4*8&255;e.push(String.fromCharCode(t))}return decodeURIComponent(escape(e.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}},hexToArray:function(t){const r=[];let e=t.length;e%2!=0&&(t=I(t,e+1)),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r},verifyPublicKey:function(t){const r=x.decodePointHex(t);if(!r)return!1;const e=r.getX();return r.getY().square().equals(e.multiply(e.square()).add(e.multiply(x.a)).add(x.b))},comparePublicKeyHex:function(t,r){const e=x.decodePointHex(t);if(!e)return!1;const i=x.decodePointHex(r);return!!i&&e.equals(i)}};const A=new Uint32Array(68),R=new Uint32Array(64);function P(t,r){const e=31&r;return t<<e|t>>>32-e}function O(t,r){const e=[];for(let i=t.length-1;i>=0;i--)e[i]=255&(t[i]^r[i]);return e}function C(t){return t^P(t,9)^P(t,17)}function M(t){let r=8*t.length,e=r%512;e=e>=448?512-e%448-1:448-e-1;const i=new Array((e-7)/8),o=new Array(8);for(let t=0,r=i.length;t<r;t++)i[t]=0;for(let t=0,r=o.length;t<r;t++)o[t]=0;r=r.toString(2);for(let t=7;t>=0;t--)if(r.length>8){const e=r.length-8;o[t]=parseInt(r.substr(e),2),r=r.substr(0,e)}else r.length>0&&(o[t]=parseInt(r,2),r="");const n=new Uint8Array([...t,128,...i,...o]),s=new DataView(n.buffer,0),h=n.length/64,u=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]);for(let t=0;t<h;t++){A.fill(0),R.fill(0);const r=16*t;for(let t=0;t<16;t++)A[t]=s.getUint32(4*(r+t),!1);for(let t=16;t<68;t++)A[t]=(a=A[t-16]^A[t-9]^P(A[t-3],15))^P(a,15)^P(a,23)^P(A[t-13],7)^A[t-6];for(let t=0;t<64;t++)R[t]=A[t]^A[t+4];const e=2043430169,i=2055708042;let o,n,h,f,c,l=u[0],p=u[1],y=u[2],m=u[3],g=u[4],d=u[5],v=u[6],w=u[7];for(let t=0;t<64;t++)c=t>=0&&t<=15?e:i,o=P(P(l,12)+g+P(c,t),7),n=o^P(l,12),h=(t>=0&&t<=15?l^p^y:l&p|l&y|p&y)+m+n+R[t],f=(t>=0&&t<=15?g^d^v:g&d|~g&v)+w+o+A[t],m=y,y=P(p,9),p=l,l=h,w=v,v=P(d,19),d=g,g=C(f);u[0]^=l,u[1]^=p,u[2]^=y,u[3]^=m,u[4]^=g,u[5]^=d,u[6]^=v,u[7]^=w}var a;const f=[];for(let t=0,r=u.length;t<r;t++){const r=u[t];f.push((4278190080&r)>>>24,(16711680&r)>>>16,(65280&r)>>>8,255&r)}return f}const H=new Uint8Array(64),V=new Uint8Array(64);for(let t=0;t<64;t++)H[t]=54,V[t]=92;var N={sm3:M,hmac:function(t,r){for(r.length>64&&(r=M(r));r.length<64;)r.push(0);const e=O(r,H),i=O(r,V),o=M([...e,...t]);return M([...i,...o])}};const{BigInteger:K}=n,{encodeDer:L,decodeDer:z}=p,k=S,Z=N.sm3,{G:j,curve:U,n:$}=k.generateEcparam();function X(t,r,e="1234567812345678"){e=k.utf8ToHex(e);const i=k.leftPad(j.curve.a.toBigInteger().toRadix(16),64),o=k.leftPad(j.curve.b.toBigInteger().toRadix(16),64),n=k.leftPad(j.getX().toBigInteger().toRadix(16),64),s=k.leftPad(j.getY().toBigInteger().toRadix(16),64);let h,u;if(128===r.length)h=r.substr(0,64),u=r.substr(64,64);else{const t=j.curve.decodePointHex(r);h=k.leftPad(t.getX().toBigInteger().toRadix(16),64),u=k.leftPad(t.getY().toBigInteger().toRadix(16),64)}const a=k.hexToArray(e+i+o+n+s+h+u),f=4*e.length;a.unshift(255&f),a.unshift(f>>8&255);const c=Z(a);return k.arrayToHex(Z(c.concat(k.hexToArray(t))))}function Y(t){const r=j.multiply(new K(t,16));return"04"+k.leftPad(r.getX().toBigInteger().toString(16),64)+k.leftPad(r.getY().toBigInteger().toString(16),64)}function G(){const t=k.generateKeyPairHex(),r=U.decodePointHex(t.publicKey);return t.k=new K(t.privateKey,16),t.x1=r.getX().toBigInteger(),t}var J={generateKeyPairHex:k.generateKeyPairHex,compressPublicKeyHex:k.compressPublicKeyHex,comparePublicKeyHex:k.comparePublicKeyHex,doEncrypt:function(t,r,e=1){t="string"==typeof t?k.hexToArray(k.utf8ToHex(t)):Array.prototype.slice.call(t),r=k.getGlobalCurve().decodePointHex(r);const i=k.generateKeyPairHex(),o=new K(i.privateKey,16);let n=i.publicKey;n.length>128&&(n=n.substr(n.length-128));const s=r.multiply(o),h=k.hexToArray(k.leftPad(s.getX().toBigInteger().toRadix(16),64)),u=k.hexToArray(k.leftPad(s.getY().toBigInteger().toRadix(16),64)),a=k.arrayToHex(Z([].concat(h,t,u)));let f=1,c=0,l=[];const p=[].concat(h,u),y=()=>{l=Z([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let r=0,e=t.length;r<e;r++)c===l.length&&y(),t[r]^=255&l[c++];const m=k.arrayToHex(t);return 0===e?n+m+a:n+a+m},doDecrypt:function(t,r,e=1,{output:i="string"}={}){r=new K(r,16);let o=t.substr(128,64),n=t.substr(192);0===e&&(o=t.substr(t.length-64),n=t.substr(128,t.length-128-64));const s=k.hexToArray(n),h=k.getGlobalCurve().decodePointHex("04"+t.substr(0,128)).multiply(r),u=k.hexToArray(k.leftPad(h.getX().toBigInteger().toRadix(16),64)),a=k.hexToArray(k.leftPad(h.getY().toBigInteger().toRadix(16),64));let f=1,c=0,l=[];const p=[].concat(u,a),y=()=>{l=Z([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let t=0,r=s.length;t<r;t++)c===l.length&&y(),s[t]^=255&l[c++];return k.arrayToHex(Z([].concat(u,s,a)))===o.toLowerCase()?"array"===i?s:k.arrayToUtf8(s):"array"===i?[]:""},doSignature:function(t,r,{pointPool:e,der:i,hash:o,publicKey:n,userId:s}={}){let h="string"==typeof t?k.utf8ToHex(t):k.arrayToHex(t);o&&(h=X(h,n=n||Y(r),s));const u=new K(r,16),a=new K(h,16);let f=null,c=null,l=null;do{do{let t;t=e&&e.length?e.pop():G(),f=t.k,c=a.add(t.x1).mod($)}while(c.equals(K.ZERO)||c.add(f).equals($));l=u.add(K.ONE).modInverse($).multiply(f.subtract(c.multiply(u))).mod($)}while(l.equals(K.ZERO));return i?L(c,l):k.leftPad(c.toString(16),64)+k.leftPad(l.toString(16),64)},doVerifySignature:function(t,r,e,{der:i,hash:o,userId:n}={}){let s,h,u="string"==typeof t?k.utf8ToHex(t):k.arrayToHex(t);if(o&&(u=X(u,e,n)),i){const t=z(r);s=t.r,h=t.s}else s=new K(r.substring(0,64),16),h=new K(r.substring(64),16);const a=U.decodePointHex(e),f=new K(u,16),c=s.add(h).mod($);if(c.equals(K.ZERO))return!1;const l=j.multiply(h).add(a.multiply(c)),p=f.add(l.getX().toBigInteger()).mod($);return s.equals(p)},getPublicKeyFromPrivateKey:Y,getPoint:G,verifyPublicKey:k.verifyPublicKey};const{sm3:W,hmac:Q}=N;function _(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")}function tt(t){const r=[];let e=t.length;var i,o;e%2!=0&&(o=e+1,t=(i=t).length>=o?i:new Array(o-i.length+1).join("0")+i),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r}const rt=0,et=16,it=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],ot=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];function nt(t){const r=[];for(let e=0,i=t.length;e<i;e+=2)r.push(parseInt(t.substr(e,2),16));return r}function st(t,r){const e=31&r;return t<<e|t>>>32-e}function ht(t){return(255&it[t>>>24&255])<<24|(255&it[t>>>16&255])<<16|(255&it[t>>>8&255])<<8|255&it[255&t]}function ut(t){return t^st(t,2)^st(t,10)^st(t,18)^st(t,24)}function at(t){return t^st(t,13)^st(t,23)}function ft(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[4*r],o[1]=255&t[4*r+1],o[2]=255&t[4*r+2],o[3]=255&t[4*r+3],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(let t,r=0;r<32;r+=4)t=i[1]^i[2]^i[3]^e[r+0],i[0]^=ut(ht(t)),t=i[2]^i[3]^i[0]^e[r+1],i[1]^=ut(ht(t)),t=i[3]^i[0]^i[1]^e[r+2],i[2]^=ut(ht(t)),t=i[0]^i[1]^i[2]^e[r+3],i[3]^=ut(ht(t));for(let t=0;t<16;t+=4)r[t]=i[3-t/4]>>>24&255,r[t+1]=i[3-t/4]>>>16&255,r[t+2]=i[3-t/4]>>>8&255,r[t+3]=255&i[3-t/4]}function ct(t,r,e,{padding:i="pkcs#7",mode:o,iv:n=[],output:s="string"}={}){if("cbc"===o&&("string"==typeof n&&(n=nt(n)),16!==n.length))throw new Error("iv is invalid");if("string"==typeof r&&(r=nt(r)),16!==r.length)throw new Error("key is invalid");if(t="string"==typeof t?e!==rt?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):nt(t):[...t],("pkcs#5"===i||"pkcs#7"===i)&&e!==rt){const r=et-t.length%et;for(let e=0;e<r;e++)t.push(r)}const h=new Array(32);!function(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[0+4*r],o[1]=255&t[1+4*r],o[2]=255&t[2+4*r],o[3]=255&t[3+4*r],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];i[0]^=2746333894,i[1]^=1453994832,i[2]^=1736282519,i[3]^=2993693404;for(let t,e=0;e<32;e+=4)t=i[1]^i[2]^i[3]^ot[e+0],r[e+0]=i[0]^=at(ht(t)),t=i[2]^i[3]^i[0]^ot[e+1],r[e+1]=i[1]^=at(ht(t)),t=i[3]^i[0]^i[1]^ot[e+2],r[e+2]=i[2]^=at(ht(t)),t=i[0]^i[1]^i[2]^ot[e+3],r[e+3]=i[3]^=at(ht(t));if(e===rt)for(let t,e=0;e<16;e++)t=r[e],r[e]=r[31-e],r[31-e]=t}(r,h,e);const u=[];let a=n,f=t.length,c=0;for(;f>=et;){const r=t.slice(c,c+16),i=new Array(16);if("cbc"===o)for(let t=0;t<et;t++)e!==rt&&(r[t]^=a[t]);ft(r,i,h);for(let t=0;t<et;t++)"cbc"===o&&e===rt&&(i[t]^=a[t]),u[c+t]=i[t];"cbc"===o&&(a=e!==rt?i:r),f-=et,c+=et}if(("pkcs#5"===i||"pkcs#7"===i)&&e===rt){const t=u.length,r=u[t-1];for(let e=1;e<=r;e++)if(u[t-e]!==r)throw new Error("padding is invalid");u.splice(t-r,r)}return"array"!==s?e!==rt?u.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join(""):function(t){const r=[];for(let e=0,i=t.length;e<i;e++)t[e]>=240&&t[e]<=247?(r.push(String.fromCodePoint(((7&t[e])<<18)+((63&t[e+1])<<12)+((63&t[e+2])<<6)+(63&t[e+3]))),e+=3):t[e]>=224&&t[e]<=239?(r.push(String.fromCodePoint(((15&t[e])<<12)+((63&t[e+1])<<6)+(63&t[e+2]))),e+=2):t[e]>=192&&t[e]<=223?(r.push(String.fromCodePoint(((31&t[e])<<6)+(63&t[e+1]))),e++):r.push(String.fromCodePoint(t[e]));return r.join("")}(u):u}var lt={sm2:J,sm3:function(t,r){if(t="string"==typeof t?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):Array.prototype.slice.call(t),r){if("hmac"!==(r.mode||"hmac"))throw new Error("invalid mode");let e=r.key;if(!e)throw new Error("invalid key");return e="string"==typeof e?tt(e):Array.prototype.slice.call(e),_(Q(t,e))}return _(W(t))},sm4:{encrypt:(t,r,e)=>ct(t,r,1,e),decrypt:(t,r,e)=>ct(t,r,0,e)}};const pt=(t=16,r="high")=>{const e=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],i=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],o=[0,1,2,3,4,5,6,7,8,9],n=["!","@","-","_","=","<",">","#","*","%","+","&","^","$"],s=[];let h="";const u=function(...t){let r="";return t.forEach((t=>{r+=t[Math.floor(Math.random()*t.length)]})),r};switch(r){case"high":h+=u(e,i,o,n),s.push(...e,...i,...o,...n);break;case"medium":h+=u(e,i,o),s.push(...e,...i,...o);break;default:h+=u(e,o),s.push(...e,...o)}const a=t-h.length;for(let t=0;t<a;t++)h+=u(s);return h};function yt(t,r="utf-8"){return new TextDecoder(r).decode(t)}function mt(t){try{return t instanceof ArrayBuffer?gt(yt(t)):t}catch(t){throw console.error("error",t),t}}function gt(t){try{return"string"==typeof t?JSON.parse(t):t}catch(t){throw console.error("error",t),t}}const dt=t=>{let r=!0;return!(t=>/^\/bi-api\/api/.test(t))(t)&&(t.startsWith("/api")&&(r=!1,(t=>/^\/(api\/logmanage|api\/data-source|api\/enterpriseadmin|api\/componentmanager|api\/spacemanager|api\/filemanager)/.test(t))(t)&&(r=!0)),r)},vt=t=>({...{key:pt(16,"high"),algorithm:t||"SM4"}}),wt=()=>({mode:"ecb",padding:"pkcs#7",output:"array"}),Tt=r.Buffer,Ft={mode:"ecb",padding:"pkcs#7",output:"array"};function bt(t,r){if(!r||"string"!=typeof r)throw new Error(`publicKey is required and must be a string ${r}`);t.interceptors.request.use((t=>{const r=t.url,e=t.headers;if(!r)throw new Error("url is required");if({}.hasOwnProperty.call(e,"closeCrypto"))return t;const i=dt(r);return console.log(`url: ${r} shouldCloseCrypto: ${i}`),i||(e.closeCrypto=!0),t})),t.interceptors.request.use((t=>(t.headers.closeCrypto||(t.responseType="arraybuffer"),t))),t.interceptors.request.use((t=>{const e=t.transformRequest,i={info:null,publicKey:[]};if(!e)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(e))throw new Error(`transformRequest ${e} is not an array`);e.push(function(t,r){return(e,i)=>{try{if(i.closeCrypto)return e;if(t.info=vt(),t.publicKey=[...Tt.from(t.info.key)],((t,r)=>{t.set("X-Encrypt-Key",r)})(i,lt.sm2.doEncrypt(JSON.stringify(t.info),r,1)),e){"string"!=typeof e&&(e=JSON.stringify(e));const r=lt.sm4.encrypt(e,t.publicKey,Ft);return Tt.from(r)}return e}catch(t){console.error("encrypt error",t,e,i)}}}(i,r));const o=function(t){return(r,e)=>{try{if((t=>{const r=t.get("X-Encrypt-With");return r&&"string"==typeof r&&"sm4"===r.toLowerCase()})(e)){const e=Tt.from(r);return gt(lt.sm4.decrypt(e,t.publicKey,{mode:"ecb",padding:"pkcs#7"}))}return mt(r)}catch(t){console.error("decrypt error",t,r,e)}}}(i);if(!o)return t;const n=t.transformResponse;if(!n)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof o)throw new Error(`decryptFn ${o} is not a function`);if(!Array.isArray(n))throw new Error(`transformResponse ${n} is not an array`);return n.unshift(o),t})),t.interceptors.response.use((t=>(t.data=mt(t.data),t.data=gt(t.data),t)),(t=>{const r=t.response;throw r?.data&&(r.data=function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){throw console.error("error",t),t}return t instanceof ArrayBuffer?yt(t):t}(r.data)),t}))}exports.createCryptoAxiosInstance=(r,e)=>{const i=t.create(r);return bt(i,e),i},exports.createRequestInstance=(r,e)=>{const i=t.create(r);return function(t,r){if(!r)return t;const{encryptFn:e,decryptFn:i}=r();e&&t.interceptors.request.use((t=>{const r=t.transformRequest;if(!r)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(r))throw new Error(`transformRequest ${r} is not an array`);if(r.push(e),!i)return t;const o=t.transformResponse;if(!o)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof i)throw new Error(`decryptFn ${i} is not a function`);if(!Array.isArray(o))throw new Error(`transformResponse ${o} is not an array`);return o.unshift(i),t}))}(i,e),i},exports.getCryptoInfo=vt,exports.getSm4EncryptConfig=wt,exports.randomPassword=pt,exports.shouldEncrypt=dt;
"use strict";var t=require("axios"),r=require("buffer");var e,i="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o={exports:{}};e=o,function(){var t;function r(t,r,e){null!=t&&("number"==typeof t?this.fromNumber(t,r,e):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}function i(){return new r(null)}var o="undefined"!=typeof navigator;o&&"Microsoft Internet Explorer"==navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(var s=32767&r,h=r>>15;--n>=0;){var u=32767&this[t],a=this[t++]>>15,f=h*u+a*s;o=((u=s*u+((32767&f)<<15)+e[i]+(1073741823&o))>>>30)+(f>>>15)+h*a+(o>>>30),e[i++]=1073741823&u}return o},t=30):o&&"Netscape"!=navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(;--n>=0;){var s=r*this[t++]+e[i]+o;o=Math.floor(s/67108864),e[i++]=67108863&s}return o},t=26):(r.prototype.am=function(t,r,e,i,o,n){for(var s=16383&r,h=r>>14;--n>=0;){var u=16383&this[t],a=this[t++]>>14,f=h*u+a*s;o=((u=s*u+((16383&f)<<14)+e[i]+o)>>28)+(f>>14)+h*a,e[i++]=268435455&u}return o},t=28),r.prototype.DB=t,r.prototype.DM=(1<<t)-1,r.prototype.DV=1<<t,r.prototype.FV=Math.pow(2,52),r.prototype.F1=52-t,r.prototype.F2=2*t-52;var n,s,h="0123456789abcdefghijklmnopqrstuvwxyz",u=new Array;for(n="0".charCodeAt(0),s=0;s<=9;++s)u[n++]=s;for(n="a".charCodeAt(0),s=10;s<36;++s)u[n++]=s;for(n="A".charCodeAt(0),s=10;s<36;++s)u[n++]=s;function a(t){return h.charAt(t)}function f(t,r){var e=u[t.charCodeAt(r)];return null==e?-1:e}function c(t){var r=i();return r.fromInt(t),r}function l(t){var r,e=1;return 0!=(r=t>>>16)&&(t=r,e+=16),0!=(r=t>>8)&&(t=r,e+=8),0!=(r=t>>4)&&(t=r,e+=4),0!=(r=t>>2)&&(t=r,e+=2),0!=(r=t>>1)&&(t=r,e+=1),e}function p(t){this.m=t}function y(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}function m(t,r){return t&r}function g(t,r){return t|r}function d(t,r){return t^r}function v(t,r){return t&~r}function w(t){if(0==t)return-1;var r=0;return 65535&t||(t>>=16,r+=16),255&t||(t>>=8,r+=8),15&t||(t>>=4,r+=4),3&t||(t>>=2,r+=2),1&t||++r,r}function T(t){for(var r=0;0!=t;)t&=t-1,++r;return r}function F(){}function b(t){return t}function B(t){this.r2=i(),this.q3=i(),r.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}p.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},p.prototype.revert=function(t){return t},p.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},p.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},p.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},y.prototype.convert=function(t){var e=i();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(r.ZERO)>0&&this.m.subTo(e,e),e},y.prototype.revert=function(t){var r=i();return t.copyTo(r),this.reduce(r),r},y.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var e=32767&t[r],i=e*this.mpl+((e*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[e=r+this.m.t]+=this.m.am(0,i,t,r,0,this.m.t);t[e]>=t.DV;)t[e]-=t.DV,t[++e]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},y.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},y.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},r.prototype.copyTo=function(t){for(var r=this.t-1;r>=0;--r)t[r]=this[r];t.t=this.t,t.s=this.s},r.prototype.fromInt=function(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},r.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var o=t.length,n=!1,s=0;--o>=0;){var h=8==i?255&t[o]:f(t,o);h<0?"-"==t.charAt(o)&&(n=!0):(n=!1,0==s?this[this.t++]=h:s+i>this.DB?(this[this.t-1]|=(h&(1<<this.DB-s)-1)<<s,this[this.t++]=h>>this.DB-s):this[this.t-1]|=h<<s,(s+=i)>=this.DB&&(s-=this.DB))}8==i&&128&t[0]&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&r.ZERO.subTo(this,this)},r.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},r.prototype.dlShiftTo=function(t,r){var e;for(e=this.t-1;e>=0;--e)r[e+t]=this[e];for(e=t-1;e>=0;--e)r[e]=0;r.t=this.t+t,r.s=this.s},r.prototype.drShiftTo=function(t,r){for(var e=t;e<this.t;++e)r[e-t]=this[e];r.t=Math.max(this.t-t,0),r.s=this.s},r.prototype.lShiftTo=function(t,r){var e,i=t%this.DB,o=this.DB-i,n=(1<<o)-1,s=Math.floor(t/this.DB),h=this.s<<i&this.DM;for(e=this.t-1;e>=0;--e)r[e+s+1]=this[e]>>o|h,h=(this[e]&n)<<i;for(e=s-1;e>=0;--e)r[e]=0;r[s]=h,r.t=this.t+s+1,r.s=this.s,r.clamp()},r.prototype.rShiftTo=function(t,r){r.s=this.s;var e=Math.floor(t/this.DB);if(e>=this.t)r.t=0;else{var i=t%this.DB,o=this.DB-i,n=(1<<i)-1;r[0]=this[e]>>i;for(var s=e+1;s<this.t;++s)r[s-e-1]|=(this[s]&n)<<o,r[s-e]=this[s]>>i;i>0&&(r[this.t-e-1]|=(this.s&n)<<o),r.t=this.t-e,r.clamp()}},r.prototype.subTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]-t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i-=t[e],r[e++]=i&this.DM,i>>=this.DB;i-=t.s}r.s=i<0?-1:0,i<-1?r[e++]=this.DV+i:i>0&&(r[e++]=i),r.t=e,r.clamp()},r.prototype.multiplyTo=function(t,e){var i=this.abs(),o=t.abs(),n=i.t;for(e.t=n+o.t;--n>=0;)e[n]=0;for(n=0;n<o.t;++n)e[n+i.t]=i.am(0,o[n],e,n,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&r.ZERO.subTo(e,e)},r.prototype.squareTo=function(t){for(var r=this.abs(),e=t.t=2*r.t;--e>=0;)t[e]=0;for(e=0;e<r.t-1;++e){var i=r.am(e,r[e],t,2*e,0,1);(t[e+r.t]+=r.am(e+1,2*r[e],t,2*e+1,i,r.t-e-1))>=r.DV&&(t[e+r.t]-=r.DV,t[e+r.t+1]=1)}t.t>0&&(t[t.t-1]+=r.am(e,r[e],t,2*e,0,1)),t.s=0,t.clamp()},r.prototype.divRemTo=function(t,e,o){var n=t.abs();if(!(n.t<=0)){var s=this.abs();if(s.t<n.t)return null!=e&&e.fromInt(0),void(null!=o&&this.copyTo(o));null==o&&(o=i());var h=i(),u=this.s,a=t.s,f=this.DB-l(n[n.t-1]);f>0?(n.lShiftTo(f,h),s.lShiftTo(f,o)):(n.copyTo(h),s.copyTo(o));var c=h.t,p=h[c-1];if(0!=p){var y=p*(1<<this.F1)+(c>1?h[c-2]>>this.F2:0),m=this.FV/y,g=(1<<this.F1)/y,d=1<<this.F2,v=o.t,w=v-c,T=null==e?i():e;for(h.dlShiftTo(w,T),o.compareTo(T)>=0&&(o[o.t++]=1,o.subTo(T,o)),r.ONE.dlShiftTo(c,T),T.subTo(h,h);h.t<c;)h[h.t++]=0;for(;--w>=0;){var F=o[--v]==p?this.DM:Math.floor(o[v]*m+(o[v-1]+d)*g);if((o[v]+=h.am(0,F,o,w,0,c))<F)for(h.dlShiftTo(w,T),o.subTo(T,o);o[v]<--F;)o.subTo(T,o)}null!=e&&(o.drShiftTo(c,e),u!=a&&r.ZERO.subTo(e,e)),o.t=c,o.clamp(),f>0&&o.rShiftTo(f,o),u<0&&r.ZERO.subTo(o,o)}}},r.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var r=3&t;return(r=(r=(r=(r=r*(2-(15&t)*r)&15)*(2-(255&t)*r)&255)*(2-((65535&t)*r&65535))&65535)*(2-t*r%this.DV)%this.DV)>0?this.DV-r:-r},r.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},r.prototype.exp=function(t,e){if(t>4294967295||t<1)return r.ONE;var o=i(),n=i(),s=e.convert(this),h=l(t)-1;for(s.copyTo(o);--h>=0;)if(e.sqrTo(o,n),(t&1<<h)>0)e.mulTo(n,s,o);else{var u=o;o=n,n=u}return e.revert(o)},r.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return this.toRadix(t);r=2}var e,i=(1<<r)-1,o=!1,n="",s=this.t,h=this.DB-s*this.DB%r;if(s-- >0)for(h<this.DB&&(e=this[s]>>h)>0&&(o=!0,n=a(e));s>=0;)h<r?(e=(this[s]&(1<<h)-1)<<r-h,e|=this[--s]>>(h+=this.DB-r)):(e=this[s]>>(h-=r)&i,h<=0&&(h+=this.DB,--s)),e>0&&(o=!0),o&&(n+=a(e));return o?n:"0"},r.prototype.negate=function(){var t=i();return r.ZERO.subTo(this,t),t},r.prototype.abs=function(){return this.s<0?this.negate():this},r.prototype.compareTo=function(t){var r=this.s-t.s;if(0!=r)return r;var e=this.t;if(0!=(r=e-t.t))return this.s<0?-r:r;for(;--e>=0;)if(0!=(r=this[e]-t[e]))return r;return 0},r.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+l(this[this.t-1]^this.s&this.DM)},r.prototype.mod=function(t){var e=i();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(r.ZERO)>0&&t.subTo(e,e),e},r.prototype.modPowInt=function(t,r){var e;return e=t<256||r.isEven()?new p(r):new y(r),this.exp(t,e)},r.ZERO=c(0),r.ONE=c(1),F.prototype.convert=b,F.prototype.revert=b,F.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e)},F.prototype.sqrTo=function(t,r){t.squareTo(r)},B.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=i();return t.copyTo(r),this.reduce(r),r},B.prototype.revert=function(t){return t},B.prototype.reduce=function(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)},B.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},B.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)};var q,x,E,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],I=(1<<26)/D[D.length-1];function S(){var t;t=(new Date).getTime(),x[E++]^=255&t,x[E++]^=t>>8&255,x[E++]^=t>>16&255,x[E++]^=t>>24&255,E>=H&&(E-=H)}if(r.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},r.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var r=this.chunkSize(t),e=Math.pow(t,r),o=c(e),n=i(),s=i(),h="";for(this.divRemTo(o,n,s);n.signum()>0;)h=(e+s.intValue()).toString(t).substr(1)+h,n.divRemTo(o,n,s);return s.intValue().toString(t)+h},r.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),o=Math.pow(e,i),n=!1,s=0,h=0,u=0;u<t.length;++u){var a=f(t,u);a<0?"-"==t.charAt(u)&&0==this.signum()&&(n=!0):(h=e*h+a,++s>=i&&(this.dMultiply(o),this.dAddOffset(h,0),s=0,h=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(h,0)),n&&r.ZERO.subTo(this,this)},r.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(r.ONE.shiftLeft(t-1),g,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(r.ONE.shiftLeft(t-1),this);else{var o=new Array,n=7&t;o.length=1+(t>>3),e.nextBytes(o),n>0?o[0]&=(1<<n)-1:o[0]=0,this.fromString(o,256)}},r.prototype.bitwiseTo=function(t,r,e){var i,o,n=Math.min(t.t,this.t);for(i=0;i<n;++i)e[i]=r(this[i],t[i]);if(t.t<this.t){for(o=t.s&this.DM,i=n;i<this.t;++i)e[i]=r(this[i],o);e.t=this.t}else{for(o=this.s&this.DM,i=n;i<t.t;++i)e[i]=r(o,t[i]);e.t=t.t}e.s=r(this.s,t.s),e.clamp()},r.prototype.changeBit=function(t,e){var i=r.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i},r.prototype.addTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]+t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i+=t[e],r[e++]=i&this.DM,i>>=this.DB;i+=t.s}r.s=i<0?-1:0,i>0?r[e++]=i:i<-1&&(r[e++]=this.DV+i),r.t=e,r.clamp()},r.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},r.prototype.dAddOffset=function(t,r){if(0!=t){for(;this.t<=r;)this[this.t++]=0;for(this[r]+=t;this[r]>=this.DV;)this[r]-=this.DV,++r>=this.t&&(this[this.t++]=0),++this[r]}},r.prototype.multiplyLowerTo=function(t,r,e){var i,o=Math.min(this.t+t.t,r);for(e.s=0,e.t=o;o>0;)e[--o]=0;for(i=e.t-this.t;o<i;++o)e[o+this.t]=this.am(0,t[o],e,o,0,this.t);for(i=Math.min(t.t,r);o<i;++o)this.am(0,t[o],e,o,0,r-o);e.clamp()},r.prototype.multiplyUpperTo=function(t,r,e){--r;var i=e.t=this.t+t.t-r;for(e.s=0;--i>=0;)e[i]=0;for(i=Math.max(r-this.t,0);i<t.t;++i)e[this.t+i-r]=this.am(r-i,t[i],e,0,0,this.t+i-r);e.clamp(),e.drShiftTo(1,e)},r.prototype.modInt=function(t){if(t<=0)return 0;var r=this.DV%t,e=this.s<0?t-1:0;if(this.t>0)if(0==r)e=this[0]%t;else for(var i=this.t-1;i>=0;--i)e=(r*e+this[i])%t;return e},r.prototype.millerRabin=function(t){var e=this.subtract(r.ONE),o=e.getLowestSetBit();if(o<=0)return!1;var n=e.shiftRight(o);(t=t+1>>1)>D.length&&(t=D.length);for(var s=i(),h=0;h<t;++h){s.fromInt(D[Math.floor(Math.random()*D.length)]);var u=s.modPow(n,this);if(0!=u.compareTo(r.ONE)&&0!=u.compareTo(e)){for(var a=1;a++<o&&0!=u.compareTo(e);)if(0==(u=u.modPowInt(2,this)).compareTo(r.ONE))return!1;if(0!=u.compareTo(e))return!1}}return!0},r.prototype.clone=function(){var t=i();return this.copyTo(t),t},r.prototype.intValue=function(){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]},r.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},r.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},r.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},r.prototype.toByteArray=function(){var t=this.t,r=new Array;r[0]=this.s;var e,i=this.DB-t*this.DB%8,o=0;if(t-- >0)for(i<this.DB&&(e=this[t]>>i)!=(this.s&this.DM)>>i&&(r[o++]=e|this.s<<this.DB-i);t>=0;)i<8?(e=(this[t]&(1<<i)-1)<<8-i,e|=this[--t]>>(i+=this.DB-8)):(e=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),128&e&&(e|=-256),0==o&&(128&this.s)!=(128&e)&&++o,(o>0||e!=this.s)&&(r[o++]=e);return r},r.prototype.equals=function(t){return 0==this.compareTo(t)},r.prototype.min=function(t){return this.compareTo(t)<0?this:t},r.prototype.max=function(t){return this.compareTo(t)>0?this:t},r.prototype.and=function(t){var r=i();return this.bitwiseTo(t,m,r),r},r.prototype.or=function(t){var r=i();return this.bitwiseTo(t,g,r),r},r.prototype.xor=function(t){var r=i();return this.bitwiseTo(t,d,r),r},r.prototype.andNot=function(t){var r=i();return this.bitwiseTo(t,v,r),r},r.prototype.not=function(){for(var t=i(),r=0;r<this.t;++r)t[r]=this.DM&~this[r];return t.t=this.t,t.s=~this.s,t},r.prototype.shiftLeft=function(t){var r=i();return t<0?this.rShiftTo(-t,r):this.lShiftTo(t,r),r},r.prototype.shiftRight=function(t){var r=i();return t<0?this.lShiftTo(-t,r):this.rShiftTo(t,r),r},r.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+w(this[t]);return this.s<0?this.t*this.DB:-1},r.prototype.bitCount=function(){for(var t=0,r=this.s&this.DM,e=0;e<this.t;++e)t+=T(this[e]^r);return t},r.prototype.testBit=function(t){var r=Math.floor(t/this.DB);return r>=this.t?0!=this.s:!!(this[r]&1<<t%this.DB)},r.prototype.setBit=function(t){return this.changeBit(t,g)},r.prototype.clearBit=function(t){return this.changeBit(t,v)},r.prototype.flipBit=function(t){return this.changeBit(t,d)},r.prototype.add=function(t){var r=i();return this.addTo(t,r),r},r.prototype.subtract=function(t){var r=i();return this.subTo(t,r),r},r.prototype.multiply=function(t){var r=i();return this.multiplyTo(t,r),r},r.prototype.divide=function(t){var r=i();return this.divRemTo(t,r,null),r},r.prototype.remainder=function(t){var r=i();return this.divRemTo(t,null,r),r},r.prototype.divideAndRemainder=function(t){var r=i(),e=i();return this.divRemTo(t,r,e),new Array(r,e)},r.prototype.modPow=function(t,r){var e,o,n=t.bitLength(),s=c(1);if(n<=0)return s;e=n<18?1:n<48?3:n<144?4:n<768?5:6,o=n<8?new p(r):r.isEven()?new B(r):new y(r);var h=new Array,u=3,a=e-1,f=(1<<e)-1;if(h[1]=o.convert(this),e>1){var m=i();for(o.sqrTo(h[1],m);u<=f;)h[u]=i(),o.mulTo(m,h[u-2],h[u]),u+=2}var g,d,v=t.t-1,w=!0,T=i();for(n=l(t[v])-1;v>=0;){for(n>=a?g=t[v]>>n-a&f:(g=(t[v]&(1<<n+1)-1)<<a-n,v>0&&(g|=t[v-1]>>this.DB+n-a)),u=e;!(1&g);)g>>=1,--u;if((n-=u)<0&&(n+=this.DB,--v),w)h[g].copyTo(s),w=!1;else{for(;u>1;)o.sqrTo(s,T),o.sqrTo(T,s),u-=2;u>0?o.sqrTo(s,T):(d=s,s=T,T=d),o.mulTo(T,h[g],s)}for(;v>=0&&!(t[v]&1<<n);)o.sqrTo(s,T),d=s,s=T,T=d,--n<0&&(n=this.DB-1,--v)}return o.revert(s)},r.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return r.ZERO;for(var i=t.clone(),o=this.clone(),n=c(1),s=c(0),h=c(0),u=c(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),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(;o.isEven();)o.rShiftTo(1,o),e?(h.isEven()&&u.isEven()||(h.addTo(this,h),u.subTo(t,u)),h.rShiftTo(1,h)):u.isEven()||u.subTo(t,u),u.rShiftTo(1,u);i.compareTo(o)>=0?(i.subTo(o,i),e&&n.subTo(h,n),s.subTo(u,s)):(o.subTo(i,o),e&&h.subTo(n,h),u.subTo(s,u))}return 0!=o.compareTo(r.ONE)?r.ZERO:u.compareTo(t)>=0?u.subtract(t):u.signum()<0?(u.addTo(t,u),u.signum()<0?u.add(t):u):u},r.prototype.pow=function(t){return this.exp(t,new F)},r.prototype.gcd=function(t){var r=this.s<0?this.negate():this.clone(),e=t.s<0?t.negate():t.clone();if(r.compareTo(e)<0){var i=r;r=e,e=i}var o=r.getLowestSetBit(),n=e.getLowestSetBit();if(n<0)return r;for(o<n&&(n=o),n>0&&(r.rShiftTo(n,r),e.rShiftTo(n,e));r.signum()>0;)(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),r.compareTo(e)>=0?(r.subTo(e,r),r.rShiftTo(1,r)):(e.subTo(r,e),e.rShiftTo(1,e));return n>0&&e.lShiftTo(n,e),e},r.prototype.isProbablePrime=function(t){var r,e=this.abs();if(1==e.t&&e[0]<=D[D.length-1]){for(r=0;r<D.length;++r)if(e[0]==D[r])return!0;return!1}if(e.isEven())return!1;for(r=1;r<D.length;){for(var i=D[r],o=r+1;o<D.length&&i<I;)i*=D[o++];for(i=e.modInt(i);r<o;)if(i%D[r++]==0)return!1}return e.millerRabin(t)},r.prototype.square=function(){var t=i();return this.squareTo(t),t},r.prototype.Barrett=B,null==x){var A;if(x=new Array,E=0,"undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var R=new Uint8Array(32);for(window.crypto.getRandomValues(R),A=0;A<32;++A)x[E++]=R[A]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var P=window.crypto.random(32);for(A=0;A<P.length;++A)x[E++]=255&P.charCodeAt(A)}for(;E<H;)A=Math.floor(65536*Math.random()),x[E++]=A>>>8,x[E++]=255&A;E=0,S()}function C(){if(null==q){for(S(),(q=new M).init(x),E=0;E<x.length;++E)x[E]=0;E=0}return q.next()}function O(){}function M(){this.i=0,this.j=0,this.S=new Array}O.prototype.nextBytes=function(t){var r;for(r=0;r<t.length;++r)t[r]=C()},M.prototype.init=function(t){var r,e,i;for(r=0;r<256;++r)this.S[r]=r;for(e=0,r=0;r<256;++r)e=e+this.S[r]+t[r%t.length]&255,i=this.S[r],this.S[r]=this.S[e],this.S[e]=i;this.i=0,this.j=0},M.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var H=256;e.exports={default:r,BigInteger:r,SecureRandom:O}}.call(i);var n=o.exports;const{BigInteger:s}=n;class h{constructor(){this.tlv=null,this.t="00",this.l="00",this.v=""}getEncodedHex(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}getLength(){const t=this.v.length/2;let r=t.toString(16);if(r.length%2==1&&(r="0"+r),t<128)return r;return(128+r.length/2).toString(16)+r}getValue(){return""}}class u extends h{constructor(t){super(),this.t="02",t&&(this.v=function(t){let r=t.toString(16);if("-"!==r[0])r.length%2==1?r="0"+r:r.match(/^[0-7]/)||(r="00"+r);else{r=r.substr(1);let e=r.length;e%2==1?e+=1:r.match(/^[0-7]/)||(e+=2);let i="";for(let t=0;t<e;t++)i+="f";i=new s(i,16),r=i.xor(t).add(s.ONE),r=r.toString(16).replace(/^-/,"")}return r}(t))}getValue(){return this.v}}class a extends h{constructor(t){super(),this.t="30",this.asn1Array=t}getValue(){return this.v=this.asn1Array.map((t=>t.getEncodedHex())).join(""),this.v}}function f(t,r){return+t[r+2]<8?1:128&+t.substr(r+2,2)}function c(t,r){const e=f(t,r),i=t.substr(r+2,2*e);if(!i)return-1;return(+i[0]<8?new s(i,16):new s(i.substr(2),16)).intValue()}function l(t,r){return r+2*(f(t,r)+1)}var p={encodeDer(t,r){const e=new u(t),i=new u(r);return new a([e,i]).getEncodedHex()},decodeDer(t){const r=l(t,0),e=l(t,r),i=c(t,r),o=t.substr(e,2*i),n=e+o.length,h=l(t,n),u=c(t,n),a=t.substr(h,2*u);return{r:new s(o,16),s:new s(a,16)}}};const{BigInteger:y}=n,m=new y("2"),g=new y("3");class d{constructor(t,r){this.x=r,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 d(this.q,this.x.negate().mod(this.q))}add(t){return new d(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new d(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new d(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}divide(t){return new d(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}square(){return new d(this.q,this.x.square().mod(this.q))}}class v{constructor(t,r,e,i){this.curve=t,this.x=r,this.y=e,this.z=null==i?y.ONE:i,this.zinv=null}getX(){return null===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&&(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(y.ZERO))return!1;return t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(y.ZERO)}isInfinity(){return null===this.x&&null===this.y||this.z.equals(y.ZERO)&&!this.y.toBigInteger().equals(y.ZERO)}negate(){return new v(this.curve,this.x,this.y.negate(),this.z)}add(t){if(this.isInfinity())return t;if(t.isInfinity())return this;const r=this.x.toBigInteger(),e=this.y.toBigInteger(),i=this.z,o=t.x.toBigInteger(),n=t.y.toBigInteger(),s=t.z,h=this.curve.q,u=r.multiply(s).mod(h),a=o.multiply(i).mod(h),f=u.subtract(a),c=e.multiply(s).mod(h),l=n.multiply(i).mod(h),p=c.subtract(l);if(y.ZERO.equals(f))return y.ZERO.equals(p)?this.twice():this.curve.infinity;const m=u.add(a),g=i.multiply(s).mod(h),d=f.square().mod(h),w=f.multiply(d).mod(h),T=g.multiply(p.square()).subtract(m.multiply(d)).mod(h),F=f.multiply(T).mod(h),b=p.multiply(d.multiply(u).subtract(T)).subtract(c.multiply(w)).mod(h),B=w.multiply(g).mod(h);return new v(this.curve,this.curve.fromBigInteger(F),this.curve.fromBigInteger(b),B)}twice(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;const t=this.x.toBigInteger(),r=this.y.toBigInteger(),e=this.z,i=this.curve.q,o=this.curve.a.toBigInteger(),n=t.square().multiply(g).add(o.multiply(e.square())).mod(i),s=r.shiftLeft(1).multiply(e).mod(i),h=r.square().mod(i),u=h.multiply(t).multiply(e).mod(i),a=s.square().mod(i),f=n.square().subtract(u.shiftLeft(3)).mod(i),c=s.multiply(f).mod(i),l=n.multiply(u.shiftLeft(2).subtract(f)).subtract(a.shiftLeft(1).multiply(h)).mod(i),p=s.multiply(a).mod(i);return new v(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(l),p)}multiply(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;const r=t.multiply(g),e=this.negate();let i=this;for(let o=r.bitLength()-2;o>0;o--){i=i.twice();const n=r.testBit(o);n!==t.testBit(o)&&(i=i.add(n?this:e))}return i}}var w={ECPointFp:v,ECCurveFp:class{constructor(t,r,e){this.q=t,this.a=this.fromBigInteger(r),this.b=this.fromBigInteger(e),this.infinity=new v(this,null,null)}equals(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}fromBigInteger(t){return new d(this.q,t)}decodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:const r=this.fromBigInteger(new y(t.substr(2),16));let e=this.fromBigInteger(r.multiply(r.square()).add(r.multiply(this.a)).add(this.b).toBigInteger().modPow(this.q.divide(new y("4")).add(y.ONE),this.q));return e.toBigInteger().mod(m).equals(new y(t.substr(0,2),16).subtract(m))||(e=e.negate()),new v(this,r,e);case 4:case 6:case 7:const i=(t.length-2)/2,o=t.substr(2,i),n=t.substr(i+2,i);return new v(this,this.fromBigInteger(new y(o,16)),this.fromBigInteger(new y(n,16)));default:return null}}}};const{BigInteger:T,SecureRandom:F}=n,{ECCurveFp:b}=w,B=new F,{curve:q,G:x,n:E}=D();function D(){const t=new T("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),r=new T("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),e=new T("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),i=new b(t,r,e),o=i.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");return{curve:i,G:o,n:new T("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function I(t,r){return t.length>=r?t:new Array(r-t.length+1).join("0")+t}var S={getGlobalCurve:function(){return q},generateEcparam:D,generateKeyPairHex:function(t,r,e){const i=(t?new T(t,r,e):new T(E.bitLength(),B)).mod(E.subtract(T.ONE)).add(T.ONE),o=I(i.toString(16),64),n=x.multiply(i);return{privateKey:o,publicKey:"04"+I(n.getX().toBigInteger().toString(16),64)+I(n.getY().toBigInteger().toString(16),64)}},compressPublicKeyHex:function(t){if(130!==t.length)throw new Error("Invalid public key to compress");const r=(t.length-2)/2,e=t.substr(2,r);let i="03";return new T(t.substr(r+2,r),16).mod(new T("2")).equals(T.ZERO)&&(i="02"),i+e},utf8ToHex:function(t){const r=(t=unescape(encodeURIComponent(t))).length,e=[];for(let i=0;i<r;i++)e[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;const i=[];for(let t=0;t<r;t++){const r=e[t>>>2]>>>24-t%4*8&255;i.push((r>>>4).toString(16)),i.push((15&r).toString(16))}return i.join("")},leftPad:I,arrayToHex:function(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")},arrayToUtf8:function(t){const r=[];let e=0;for(let i=0;i<2*t.length;i+=2)r[i>>>3]|=parseInt(t[e],10)<<24-i%8*4,e++;try{const e=[];for(let i=0;i<t.length;i++){const t=r[i>>>2]>>>24-i%4*8&255;e.push(String.fromCharCode(t))}return decodeURIComponent(escape(e.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}},hexToArray:function(t){const r=[];let e=t.length;e%2!=0&&(t=I(t,e+1)),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r},verifyPublicKey:function(t){const r=q.decodePointHex(t);if(!r)return!1;const e=r.getX();return r.getY().square().equals(e.multiply(e.square()).add(e.multiply(q.a)).add(q.b))},comparePublicKeyHex:function(t,r){const e=q.decodePointHex(t);if(!e)return!1;const i=q.decodePointHex(r);return!!i&&e.equals(i)}};const A=new Uint32Array(68),R=new Uint32Array(64);function P(t,r){const e=31&r;return t<<e|t>>>32-e}function C(t,r){const e=[];for(let i=t.length-1;i>=0;i--)e[i]=255&(t[i]^r[i]);return e}function O(t){return t^P(t,9)^P(t,17)}function M(t){let r=8*t.length,e=r%512;e=e>=448?512-e%448-1:448-e-1;const i=new Array((e-7)/8),o=new Array(8);for(let t=0,r=i.length;t<r;t++)i[t]=0;for(let t=0,r=o.length;t<r;t++)o[t]=0;r=r.toString(2);for(let t=7;t>=0;t--)if(r.length>8){const e=r.length-8;o[t]=parseInt(r.substr(e),2),r=r.substr(0,e)}else r.length>0&&(o[t]=parseInt(r,2),r="");const n=new Uint8Array([...t,128,...i,...o]),s=new DataView(n.buffer,0),h=n.length/64,u=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]);for(let t=0;t<h;t++){A.fill(0),R.fill(0);const r=16*t;for(let t=0;t<16;t++)A[t]=s.getUint32(4*(r+t),!1);for(let t=16;t<68;t++)A[t]=(a=A[t-16]^A[t-9]^P(A[t-3],15))^P(a,15)^P(a,23)^P(A[t-13],7)^A[t-6];for(let t=0;t<64;t++)R[t]=A[t]^A[t+4];const e=2043430169,i=2055708042;let o,n,h,f,c,l=u[0],p=u[1],y=u[2],m=u[3],g=u[4],d=u[5],v=u[6],w=u[7];for(let t=0;t<64;t++)c=t>=0&&t<=15?e:i,o=P(P(l,12)+g+P(c,t),7),n=o^P(l,12),h=(t>=0&&t<=15?l^p^y:l&p|l&y|p&y)+m+n+R[t],f=(t>=0&&t<=15?g^d^v:g&d|~g&v)+w+o+A[t],m=y,y=P(p,9),p=l,l=h,w=v,v=P(d,19),d=g,g=O(f);u[0]^=l,u[1]^=p,u[2]^=y,u[3]^=m,u[4]^=g,u[5]^=d,u[6]^=v,u[7]^=w}var a;const f=[];for(let t=0,r=u.length;t<r;t++){const r=u[t];f.push((4278190080&r)>>>24,(16711680&r)>>>16,(65280&r)>>>8,255&r)}return f}const H=new Uint8Array(64),V=new Uint8Array(64);for(let t=0;t<64;t++)H[t]=54,V[t]=92;var N={sm3:M,hmac:function(t,r){for(r.length>64&&(r=M(r));r.length<64;)r.push(0);const e=C(r,H),i=C(r,V),o=M([...e,...t]);return M([...i,...o])}};const{BigInteger:K}=n,{encodeDer:L,decodeDer:z}=p,k=S,Z=N.sm3,{G:j,curve:U,n:$}=k.generateEcparam();function X(t,r,e="1234567812345678"){e=k.utf8ToHex(e);const i=k.leftPad(j.curve.a.toBigInteger().toRadix(16),64),o=k.leftPad(j.curve.b.toBigInteger().toRadix(16),64),n=k.leftPad(j.getX().toBigInteger().toRadix(16),64),s=k.leftPad(j.getY().toBigInteger().toRadix(16),64);let h,u;if(128===r.length)h=r.substr(0,64),u=r.substr(64,64);else{const t=j.curve.decodePointHex(r);h=k.leftPad(t.getX().toBigInteger().toRadix(16),64),u=k.leftPad(t.getY().toBigInteger().toRadix(16),64)}const a=k.hexToArray(e+i+o+n+s+h+u),f=4*e.length;a.unshift(255&f),a.unshift(f>>8&255);const c=Z(a);return k.arrayToHex(Z(c.concat(k.hexToArray(t))))}function Y(t){const r=j.multiply(new K(t,16));return"04"+k.leftPad(r.getX().toBigInteger().toString(16),64)+k.leftPad(r.getY().toBigInteger().toString(16),64)}function G(){const t=k.generateKeyPairHex(),r=U.decodePointHex(t.publicKey);return t.k=new K(t.privateKey,16),t.x1=r.getX().toBigInteger(),t}var J={generateKeyPairHex:k.generateKeyPairHex,compressPublicKeyHex:k.compressPublicKeyHex,comparePublicKeyHex:k.comparePublicKeyHex,doEncrypt:function(t,r,e=1){t="string"==typeof t?k.hexToArray(k.utf8ToHex(t)):Array.prototype.slice.call(t),r=k.getGlobalCurve().decodePointHex(r);const i=k.generateKeyPairHex(),o=new K(i.privateKey,16);let n=i.publicKey;n.length>128&&(n=n.substr(n.length-128));const s=r.multiply(o),h=k.hexToArray(k.leftPad(s.getX().toBigInteger().toRadix(16),64)),u=k.hexToArray(k.leftPad(s.getY().toBigInteger().toRadix(16),64)),a=k.arrayToHex(Z([].concat(h,t,u)));let f=1,c=0,l=[];const p=[].concat(h,u),y=()=>{l=Z([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let r=0,e=t.length;r<e;r++)c===l.length&&y(),t[r]^=255&l[c++];const m=k.arrayToHex(t);return 0===e?n+m+a:n+a+m},doDecrypt:function(t,r,e=1,{output:i="string"}={}){r=new K(r,16);let o=t.substr(128,64),n=t.substr(192);0===e&&(o=t.substr(t.length-64),n=t.substr(128,t.length-128-64));const s=k.hexToArray(n),h=k.getGlobalCurve().decodePointHex("04"+t.substr(0,128)).multiply(r),u=k.hexToArray(k.leftPad(h.getX().toBigInteger().toRadix(16),64)),a=k.hexToArray(k.leftPad(h.getY().toBigInteger().toRadix(16),64));let f=1,c=0,l=[];const p=[].concat(u,a),y=()=>{l=Z([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let t=0,r=s.length;t<r;t++)c===l.length&&y(),s[t]^=255&l[c++];return k.arrayToHex(Z([].concat(u,s,a)))===o.toLowerCase()?"array"===i?s:k.arrayToUtf8(s):"array"===i?[]:""},doSignature:function(t,r,{pointPool:e,der:i,hash:o,publicKey:n,userId:s}={}){let h="string"==typeof t?k.utf8ToHex(t):k.arrayToHex(t);o&&(h=X(h,n=n||Y(r),s));const u=new K(r,16),a=new K(h,16);let f=null,c=null,l=null;do{do{let t;t=e&&e.length?e.pop():G(),f=t.k,c=a.add(t.x1).mod($)}while(c.equals(K.ZERO)||c.add(f).equals($));l=u.add(K.ONE).modInverse($).multiply(f.subtract(c.multiply(u))).mod($)}while(l.equals(K.ZERO));return i?L(c,l):k.leftPad(c.toString(16),64)+k.leftPad(l.toString(16),64)},doVerifySignature:function(t,r,e,{der:i,hash:o,userId:n}={}){let s,h,u="string"==typeof t?k.utf8ToHex(t):k.arrayToHex(t);if(o&&(u=X(u,e,n)),i){const t=z(r);s=t.r,h=t.s}else s=new K(r.substring(0,64),16),h=new K(r.substring(64),16);const a=U.decodePointHex(e),f=new K(u,16),c=s.add(h).mod($);if(c.equals(K.ZERO))return!1;const l=j.multiply(h).add(a.multiply(c)),p=f.add(l.getX().toBigInteger()).mod($);return s.equals(p)},getPublicKeyFromPrivateKey:Y,getPoint:G,verifyPublicKey:k.verifyPublicKey};const{sm3:W,hmac:Q}=N;function _(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")}function tt(t){const r=[];let e=t.length;var i,o;e%2!=0&&(o=e+1,t=(i=t).length>=o?i:new Array(o-i.length+1).join("0")+i),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r}const rt=0,et=16,it=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],ot=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];function nt(t){const r=[];for(let e=0,i=t.length;e<i;e+=2)r.push(parseInt(t.substr(e,2),16));return r}function st(t,r){const e=31&r;return t<<e|t>>>32-e}function ht(t){return(255&it[t>>>24&255])<<24|(255&it[t>>>16&255])<<16|(255&it[t>>>8&255])<<8|255&it[255&t]}function ut(t){return t^st(t,2)^st(t,10)^st(t,18)^st(t,24)}function at(t){return t^st(t,13)^st(t,23)}function ft(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[4*r],o[1]=255&t[4*r+1],o[2]=255&t[4*r+2],o[3]=255&t[4*r+3],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(let t,r=0;r<32;r+=4)t=i[1]^i[2]^i[3]^e[r+0],i[0]^=ut(ht(t)),t=i[2]^i[3]^i[0]^e[r+1],i[1]^=ut(ht(t)),t=i[3]^i[0]^i[1]^e[r+2],i[2]^=ut(ht(t)),t=i[0]^i[1]^i[2]^e[r+3],i[3]^=ut(ht(t));for(let t=0;t<16;t+=4)r[t]=i[3-t/4]>>>24&255,r[t+1]=i[3-t/4]>>>16&255,r[t+2]=i[3-t/4]>>>8&255,r[t+3]=255&i[3-t/4]}function ct(t,r,e,{padding:i="pkcs#7",mode:o,iv:n=[],output:s="string"}={}){if("cbc"===o&&("string"==typeof n&&(n=nt(n)),16!==n.length))throw new Error("iv is invalid");if("string"==typeof r&&(r=nt(r)),16!==r.length)throw new Error("key is invalid");if(t="string"==typeof t?e!==rt?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):nt(t):[...t],("pkcs#5"===i||"pkcs#7"===i)&&e!==rt){const r=et-t.length%et;for(let e=0;e<r;e++)t.push(r)}const h=new Array(32);!function(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[0+4*r],o[1]=255&t[1+4*r],o[2]=255&t[2+4*r],o[3]=255&t[3+4*r],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];i[0]^=2746333894,i[1]^=1453994832,i[2]^=1736282519,i[3]^=2993693404;for(let t,e=0;e<32;e+=4)t=i[1]^i[2]^i[3]^ot[e+0],r[e+0]=i[0]^=at(ht(t)),t=i[2]^i[3]^i[0]^ot[e+1],r[e+1]=i[1]^=at(ht(t)),t=i[3]^i[0]^i[1]^ot[e+2],r[e+2]=i[2]^=at(ht(t)),t=i[0]^i[1]^i[2]^ot[e+3],r[e+3]=i[3]^=at(ht(t));if(e===rt)for(let t,e=0;e<16;e++)t=r[e],r[e]=r[31-e],r[31-e]=t}(r,h,e);const u=[];let a=n,f=t.length,c=0;for(;f>=et;){const r=t.slice(c,c+16),i=new Array(16);if("cbc"===o)for(let t=0;t<et;t++)e!==rt&&(r[t]^=a[t]);ft(r,i,h);for(let t=0;t<et;t++)"cbc"===o&&e===rt&&(i[t]^=a[t]),u[c+t]=i[t];"cbc"===o&&(a=e!==rt?i:r),f-=et,c+=et}if(("pkcs#5"===i||"pkcs#7"===i)&&e===rt){const t=u.length,r=u[t-1];for(let e=1;e<=r;e++)if(u[t-e]!==r)throw new Error("padding is invalid");u.splice(t-r,r)}return"array"!==s?e!==rt?u.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join(""):function(t){const r=[];for(let e=0,i=t.length;e<i;e++)t[e]>=240&&t[e]<=247?(r.push(String.fromCodePoint(((7&t[e])<<18)+((63&t[e+1])<<12)+((63&t[e+2])<<6)+(63&t[e+3]))),e+=3):t[e]>=224&&t[e]<=239?(r.push(String.fromCodePoint(((15&t[e])<<12)+((63&t[e+1])<<6)+(63&t[e+2]))),e+=2):t[e]>=192&&t[e]<=223?(r.push(String.fromCodePoint(((31&t[e])<<6)+(63&t[e+1]))),e++):r.push(String.fromCodePoint(t[e]));return r.join("")}(u):u}var lt={sm2:J,sm3:function(t,r){if(t="string"==typeof t?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):Array.prototype.slice.call(t),r){if("hmac"!==(r.mode||"hmac"))throw new Error("invalid mode");let e=r.key;if(!e)throw new Error("invalid key");return e="string"==typeof e?tt(e):Array.prototype.slice.call(e),_(Q(t,e))}return _(W(t))},sm4:{encrypt:(t,r,e)=>ct(t,r,1,e),decrypt:(t,r,e)=>ct(t,r,0,e)}};const pt=(t=16,r="high")=>{const e=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],i=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],o=[0,1,2,3,4,5,6,7,8,9],n=["!","@","-","_","=","<",">","#","*","%","+","&","^","$"],s=[];let h="";const u=function(...t){let r="";return t.forEach((t=>{r+=t[Math.floor(Math.random()*t.length)]})),r};switch(r){case"high":h+=u(e,i,o,n),s.push(...e,...i,...o,...n);break;case"medium":h+=u(e,i,o),s.push(...e,...i,...o);break;default:h+=u(e,o),s.push(...e,...o)}const a=t-h.length;for(let t=0;t<a;t++)h+=u(s);return h};function yt(t,r="utf-8"){return new TextDecoder(r).decode(t)}function mt(t){try{return t instanceof ArrayBuffer?gt(yt(t)):t}catch(t){throw console.error("error",t),t}}function gt(t){try{return"string"==typeof t?JSON.parse(t):t}catch(t){throw console.error("error",t),t}}const dt=t=>{let r=!0;return!(t=>/^\/bi-api\/api/.test(t))(t)&&(t.startsWith("/api")&&(r=!1,(t=>/^\/(api\/logmanage|api\/data-source|api\/enterpriseadmin|api\/componentmanager|api\/spacemanager|api\/filemanager)/.test(t))(t)&&(r=!0)),r)},vt=t=>({...{key:pt(16,"high"),algorithm:t||"SM4"}}),wt=()=>({mode:"ecb",padding:"pkcs#7",output:"array"}),Tt=r.Buffer,Ft={mode:"ecb",padding:"pkcs#7",output:"array"};function bt(t,r){if(!r||"string"!=typeof r)throw new Error(`publicKey is required and must be a string ${r}`);t.interceptors.request.use((t=>{const r=t.url,e=t.headers;if(!r)throw new Error("url is required");if({}.hasOwnProperty.call(e,"closeCrypto"))return t;const i=dt(r);return console.log(`url: ${r} shouldCloseCrypto: ${i}`),i||(e.closeCrypto=!0),t})),t.interceptors.request.use((t=>{const r=t.data,e=t.headers;return r instanceof FormData&&(console.log(`body of request: ${t.url} is FormData: ${r}`),e.closeCrypto=!0),t})),t.interceptors.request.use((t=>(t.headers.closeCrypto||(t.responseType="arraybuffer"),t))),t.interceptors.request.use((t=>{const e=t.transformRequest,i={info:null,publicKey:[]};if(!e)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(e))throw new Error(`transformRequest ${e} is not an array`);e.push(function(t,r){return(e,i)=>{try{if(i.closeCrypto)return e;if(t.info=vt(),t.publicKey=[...Tt.from(t.info.key)],((t,r)=>{t.set("X-Encrypt-Key",r)})(i,lt.sm2.doEncrypt(JSON.stringify(t.info),r,1)),e){"string"!=typeof e&&(e=JSON.stringify(e));const r=lt.sm4.encrypt(e,t.publicKey,Ft);return Tt.from(r)}return e}catch(t){console.error("encrypt error",t,e,i)}}}(i,r));const o=function(t){return(r,e)=>{try{if((t=>{const r=t.get("X-Encrypt-With");return r&&"string"==typeof r&&"sm4"===r.toLowerCase()})(e)){const e=Tt.from(r);return gt(lt.sm4.decrypt(e,t.publicKey,{mode:"ecb",padding:"pkcs#7"}))}return mt(r)}catch(t){console.error("decrypt error",t,r,e)}}}(i);if(!o)return t;const n=t.transformResponse;if(!n)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof o)throw new Error(`decryptFn ${o} is not a function`);if(!Array.isArray(n))throw new Error(`transformResponse ${n} is not an array`);return n.unshift(o),t})),t.interceptors.response.use((t=>(t.data=mt(t.data),t.data=gt(t.data),t)),(t=>{const r=t.response;throw r?.data&&(r.data=function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){throw console.error("error",t),t}return t instanceof ArrayBuffer?yt(t):t}(r.data)),t}))}exports.createCryptoAxiosInstance=(r,e)=>{const i=t.create(r);return bt(i,e),i},exports.createRequestInstance=(r,e)=>{const i=t.create(r);return function(t,r){if(!r)return t;const{encryptFn:e,decryptFn:i}=r();e&&t.interceptors.request.use((t=>{const r=t.transformRequest;if(!r)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(r))throw new Error(`transformRequest ${r} is not an array`);if(r.push(e),!i)return t;const o=t.transformResponse;if(!o)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof i)throw new Error(`decryptFn ${i} is not a function`);if(!Array.isArray(o))throw new Error(`transformResponse ${o} is not an array`);return o.unshift(i),t}))}(i,e),i},exports.getCryptoInfo=vt,exports.getSm4EncryptConfig=wt,exports.randomPassword=pt,exports.shouldEncrypt=dt;

@@ -1,1 +0,1 @@

import t from"axios";import r from"buffer";const e=(r,e)=>{const i=t.create(r);return function(t,r){if(!r)return t;const{encryptFn:e,decryptFn:i}=r();e&&t.interceptors.request.use((t=>{const r=t.transformRequest;if(!r)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(r))throw new Error(`transformRequest ${r} is not an array`);if(r.push(e),!i)return t;const o=t.transformResponse;if(!o)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof i)throw new Error(`decryptFn ${i} is not a function`);if(!Array.isArray(o))throw new Error(`transformResponse ${o} is not an array`);return o.unshift(i),t}))}(i,e),i};var i,o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={exports:{}};i=n,function(){var t;function r(t,r,e){null!=t&&("number"==typeof t?this.fromNumber(t,r,e):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}function e(){return new r(null)}var o="undefined"!=typeof navigator;o&&"Microsoft Internet Explorer"==navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(var s=32767&r,h=r>>15;--n>=0;){var u=32767&this[t],a=this[t++]>>15,f=h*u+a*s;o=((u=s*u+((32767&f)<<15)+e[i]+(1073741823&o))>>>30)+(f>>>15)+h*a+(o>>>30),e[i++]=1073741823&u}return o},t=30):o&&"Netscape"!=navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(;--n>=0;){var s=r*this[t++]+e[i]+o;o=Math.floor(s/67108864),e[i++]=67108863&s}return o},t=26):(r.prototype.am=function(t,r,e,i,o,n){for(var s=16383&r,h=r>>14;--n>=0;){var u=16383&this[t],a=this[t++]>>14,f=h*u+a*s;o=((u=s*u+((16383&f)<<14)+e[i]+o)>>28)+(f>>14)+h*a,e[i++]=268435455&u}return o},t=28),r.prototype.DB=t,r.prototype.DM=(1<<t)-1,r.prototype.DV=1<<t,r.prototype.FV=Math.pow(2,52),r.prototype.F1=52-t,r.prototype.F2=2*t-52;var n,s,h="0123456789abcdefghijklmnopqrstuvwxyz",u=new Array;for(n="0".charCodeAt(0),s=0;s<=9;++s)u[n++]=s;for(n="a".charCodeAt(0),s=10;s<36;++s)u[n++]=s;for(n="A".charCodeAt(0),s=10;s<36;++s)u[n++]=s;function a(t){return h.charAt(t)}function f(t,r){var e=u[t.charCodeAt(r)];return null==e?-1:e}function c(t){var r=e();return r.fromInt(t),r}function l(t){var r,e=1;return 0!=(r=t>>>16)&&(t=r,e+=16),0!=(r=t>>8)&&(t=r,e+=8),0!=(r=t>>4)&&(t=r,e+=4),0!=(r=t>>2)&&(t=r,e+=2),0!=(r=t>>1)&&(t=r,e+=1),e}function p(t){this.m=t}function y(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}function m(t,r){return t&r}function g(t,r){return t|r}function d(t,r){return t^r}function v(t,r){return t&~r}function w(t){if(0==t)return-1;var r=0;return 65535&t||(t>>=16,r+=16),255&t||(t>>=8,r+=8),15&t||(t>>=4,r+=4),3&t||(t>>=2,r+=2),1&t||++r,r}function T(t){for(var r=0;0!=t;)t&=t-1,++r;return r}function F(){}function b(t){return t}function B(t){this.r2=e(),this.q3=e(),r.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}p.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},p.prototype.revert=function(t){return t},p.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},p.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},p.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},y.prototype.convert=function(t){var i=e();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(r.ZERO)>0&&this.m.subTo(i,i),i},y.prototype.revert=function(t){var r=e();return t.copyTo(r),this.reduce(r),r},y.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var e=32767&t[r],i=e*this.mpl+((e*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[e=r+this.m.t]+=this.m.am(0,i,t,r,0,this.m.t);t[e]>=t.DV;)t[e]-=t.DV,t[++e]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},y.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},y.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},r.prototype.copyTo=function(t){for(var r=this.t-1;r>=0;--r)t[r]=this[r];t.t=this.t,t.s=this.s},r.prototype.fromInt=function(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},r.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var o=t.length,n=!1,s=0;--o>=0;){var h=8==i?255&t[o]:f(t,o);h<0?"-"==t.charAt(o)&&(n=!0):(n=!1,0==s?this[this.t++]=h:s+i>this.DB?(this[this.t-1]|=(h&(1<<this.DB-s)-1)<<s,this[this.t++]=h>>this.DB-s):this[this.t-1]|=h<<s,(s+=i)>=this.DB&&(s-=this.DB))}8==i&&128&t[0]&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&r.ZERO.subTo(this,this)},r.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},r.prototype.dlShiftTo=function(t,r){var e;for(e=this.t-1;e>=0;--e)r[e+t]=this[e];for(e=t-1;e>=0;--e)r[e]=0;r.t=this.t+t,r.s=this.s},r.prototype.drShiftTo=function(t,r){for(var e=t;e<this.t;++e)r[e-t]=this[e];r.t=Math.max(this.t-t,0),r.s=this.s},r.prototype.lShiftTo=function(t,r){var e,i=t%this.DB,o=this.DB-i,n=(1<<o)-1,s=Math.floor(t/this.DB),h=this.s<<i&this.DM;for(e=this.t-1;e>=0;--e)r[e+s+1]=this[e]>>o|h,h=(this[e]&n)<<i;for(e=s-1;e>=0;--e)r[e]=0;r[s]=h,r.t=this.t+s+1,r.s=this.s,r.clamp()},r.prototype.rShiftTo=function(t,r){r.s=this.s;var e=Math.floor(t/this.DB);if(e>=this.t)r.t=0;else{var i=t%this.DB,o=this.DB-i,n=(1<<i)-1;r[0]=this[e]>>i;for(var s=e+1;s<this.t;++s)r[s-e-1]|=(this[s]&n)<<o,r[s-e]=this[s]>>i;i>0&&(r[this.t-e-1]|=(this.s&n)<<o),r.t=this.t-e,r.clamp()}},r.prototype.subTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]-t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i-=t[e],r[e++]=i&this.DM,i>>=this.DB;i-=t.s}r.s=i<0?-1:0,i<-1?r[e++]=this.DV+i:i>0&&(r[e++]=i),r.t=e,r.clamp()},r.prototype.multiplyTo=function(t,e){var i=this.abs(),o=t.abs(),n=i.t;for(e.t=n+o.t;--n>=0;)e[n]=0;for(n=0;n<o.t;++n)e[n+i.t]=i.am(0,o[n],e,n,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&r.ZERO.subTo(e,e)},r.prototype.squareTo=function(t){for(var r=this.abs(),e=t.t=2*r.t;--e>=0;)t[e]=0;for(e=0;e<r.t-1;++e){var i=r.am(e,r[e],t,2*e,0,1);(t[e+r.t]+=r.am(e+1,2*r[e],t,2*e+1,i,r.t-e-1))>=r.DV&&(t[e+r.t]-=r.DV,t[e+r.t+1]=1)}t.t>0&&(t[t.t-1]+=r.am(e,r[e],t,2*e,0,1)),t.s=0,t.clamp()},r.prototype.divRemTo=function(t,i,o){var n=t.abs();if(!(n.t<=0)){var s=this.abs();if(s.t<n.t)return null!=i&&i.fromInt(0),void(null!=o&&this.copyTo(o));null==o&&(o=e());var h=e(),u=this.s,a=t.s,f=this.DB-l(n[n.t-1]);f>0?(n.lShiftTo(f,h),s.lShiftTo(f,o)):(n.copyTo(h),s.copyTo(o));var c=h.t,p=h[c-1];if(0!=p){var y=p*(1<<this.F1)+(c>1?h[c-2]>>this.F2:0),m=this.FV/y,g=(1<<this.F1)/y,d=1<<this.F2,v=o.t,w=v-c,T=null==i?e():i;for(h.dlShiftTo(w,T),o.compareTo(T)>=0&&(o[o.t++]=1,o.subTo(T,o)),r.ONE.dlShiftTo(c,T),T.subTo(h,h);h.t<c;)h[h.t++]=0;for(;--w>=0;){var F=o[--v]==p?this.DM:Math.floor(o[v]*m+(o[v-1]+d)*g);if((o[v]+=h.am(0,F,o,w,0,c))<F)for(h.dlShiftTo(w,T),o.subTo(T,o);o[v]<--F;)o.subTo(T,o)}null!=i&&(o.drShiftTo(c,i),u!=a&&r.ZERO.subTo(i,i)),o.t=c,o.clamp(),f>0&&o.rShiftTo(f,o),u<0&&r.ZERO.subTo(o,o)}}},r.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var r=3&t;return(r=(r=(r=(r=r*(2-(15&t)*r)&15)*(2-(255&t)*r)&255)*(2-((65535&t)*r&65535))&65535)*(2-t*r%this.DV)%this.DV)>0?this.DV-r:-r},r.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},r.prototype.exp=function(t,i){if(t>4294967295||t<1)return r.ONE;var o=e(),n=e(),s=i.convert(this),h=l(t)-1;for(s.copyTo(o);--h>=0;)if(i.sqrTo(o,n),(t&1<<h)>0)i.mulTo(n,s,o);else{var u=o;o=n,n=u}return i.revert(o)},r.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return this.toRadix(t);r=2}var e,i=(1<<r)-1,o=!1,n="",s=this.t,h=this.DB-s*this.DB%r;if(s-- >0)for(h<this.DB&&(e=this[s]>>h)>0&&(o=!0,n=a(e));s>=0;)h<r?(e=(this[s]&(1<<h)-1)<<r-h,e|=this[--s]>>(h+=this.DB-r)):(e=this[s]>>(h-=r)&i,h<=0&&(h+=this.DB,--s)),e>0&&(o=!0),o&&(n+=a(e));return o?n:"0"},r.prototype.negate=function(){var t=e();return r.ZERO.subTo(this,t),t},r.prototype.abs=function(){return this.s<0?this.negate():this},r.prototype.compareTo=function(t){var r=this.s-t.s;if(0!=r)return r;var e=this.t;if(0!=(r=e-t.t))return this.s<0?-r:r;for(;--e>=0;)if(0!=(r=this[e]-t[e]))return r;return 0},r.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+l(this[this.t-1]^this.s&this.DM)},r.prototype.mod=function(t){var i=e();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(r.ZERO)>0&&t.subTo(i,i),i},r.prototype.modPowInt=function(t,r){var e;return e=t<256||r.isEven()?new p(r):new y(r),this.exp(t,e)},r.ZERO=c(0),r.ONE=c(1),F.prototype.convert=b,F.prototype.revert=b,F.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e)},F.prototype.sqrTo=function(t,r){t.squareTo(r)},B.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=e();return t.copyTo(r),this.reduce(r),r},B.prototype.revert=function(t){return t},B.prototype.reduce=function(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)},B.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},B.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)};var q,x,E,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],S=(1<<26)/D[D.length-1];function I(){var t;t=(new Date).getTime(),x[E++]^=255&t,x[E++]^=t>>8&255,x[E++]^=t>>16&255,x[E++]^=t>>24&255,E>=H&&(E-=H)}if(r.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},r.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var r=this.chunkSize(t),i=Math.pow(t,r),o=c(i),n=e(),s=e(),h="";for(this.divRemTo(o,n,s);n.signum()>0;)h=(i+s.intValue()).toString(t).substr(1)+h,n.divRemTo(o,n,s);return s.intValue().toString(t)+h},r.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),o=Math.pow(e,i),n=!1,s=0,h=0,u=0;u<t.length;++u){var a=f(t,u);a<0?"-"==t.charAt(u)&&0==this.signum()&&(n=!0):(h=e*h+a,++s>=i&&(this.dMultiply(o),this.dAddOffset(h,0),s=0,h=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(h,0)),n&&r.ZERO.subTo(this,this)},r.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(r.ONE.shiftLeft(t-1),g,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(r.ONE.shiftLeft(t-1),this);else{var o=new Array,n=7&t;o.length=1+(t>>3),e.nextBytes(o),n>0?o[0]&=(1<<n)-1:o[0]=0,this.fromString(o,256)}},r.prototype.bitwiseTo=function(t,r,e){var i,o,n=Math.min(t.t,this.t);for(i=0;i<n;++i)e[i]=r(this[i],t[i]);if(t.t<this.t){for(o=t.s&this.DM,i=n;i<this.t;++i)e[i]=r(this[i],o);e.t=this.t}else{for(o=this.s&this.DM,i=n;i<t.t;++i)e[i]=r(o,t[i]);e.t=t.t}e.s=r(this.s,t.s),e.clamp()},r.prototype.changeBit=function(t,e){var i=r.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i},r.prototype.addTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]+t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i+=t[e],r[e++]=i&this.DM,i>>=this.DB;i+=t.s}r.s=i<0?-1:0,i>0?r[e++]=i:i<-1&&(r[e++]=this.DV+i),r.t=e,r.clamp()},r.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},r.prototype.dAddOffset=function(t,r){if(0!=t){for(;this.t<=r;)this[this.t++]=0;for(this[r]+=t;this[r]>=this.DV;)this[r]-=this.DV,++r>=this.t&&(this[this.t++]=0),++this[r]}},r.prototype.multiplyLowerTo=function(t,r,e){var i,o=Math.min(this.t+t.t,r);for(e.s=0,e.t=o;o>0;)e[--o]=0;for(i=e.t-this.t;o<i;++o)e[o+this.t]=this.am(0,t[o],e,o,0,this.t);for(i=Math.min(t.t,r);o<i;++o)this.am(0,t[o],e,o,0,r-o);e.clamp()},r.prototype.multiplyUpperTo=function(t,r,e){--r;var i=e.t=this.t+t.t-r;for(e.s=0;--i>=0;)e[i]=0;for(i=Math.max(r-this.t,0);i<t.t;++i)e[this.t+i-r]=this.am(r-i,t[i],e,0,0,this.t+i-r);e.clamp(),e.drShiftTo(1,e)},r.prototype.modInt=function(t){if(t<=0)return 0;var r=this.DV%t,e=this.s<0?t-1:0;if(this.t>0)if(0==r)e=this[0]%t;else for(var i=this.t-1;i>=0;--i)e=(r*e+this[i])%t;return e},r.prototype.millerRabin=function(t){var i=this.subtract(r.ONE),o=i.getLowestSetBit();if(o<=0)return!1;var n=i.shiftRight(o);(t=t+1>>1)>D.length&&(t=D.length);for(var s=e(),h=0;h<t;++h){s.fromInt(D[Math.floor(Math.random()*D.length)]);var u=s.modPow(n,this);if(0!=u.compareTo(r.ONE)&&0!=u.compareTo(i)){for(var a=1;a++<o&&0!=u.compareTo(i);)if(0==(u=u.modPowInt(2,this)).compareTo(r.ONE))return!1;if(0!=u.compareTo(i))return!1}}return!0},r.prototype.clone=function(){var t=e();return this.copyTo(t),t},r.prototype.intValue=function(){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]},r.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},r.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},r.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},r.prototype.toByteArray=function(){var t=this.t,r=new Array;r[0]=this.s;var e,i=this.DB-t*this.DB%8,o=0;if(t-- >0)for(i<this.DB&&(e=this[t]>>i)!=(this.s&this.DM)>>i&&(r[o++]=e|this.s<<this.DB-i);t>=0;)i<8?(e=(this[t]&(1<<i)-1)<<8-i,e|=this[--t]>>(i+=this.DB-8)):(e=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),128&e&&(e|=-256),0==o&&(128&this.s)!=(128&e)&&++o,(o>0||e!=this.s)&&(r[o++]=e);return r},r.prototype.equals=function(t){return 0==this.compareTo(t)},r.prototype.min=function(t){return this.compareTo(t)<0?this:t},r.prototype.max=function(t){return this.compareTo(t)>0?this:t},r.prototype.and=function(t){var r=e();return this.bitwiseTo(t,m,r),r},r.prototype.or=function(t){var r=e();return this.bitwiseTo(t,g,r),r},r.prototype.xor=function(t){var r=e();return this.bitwiseTo(t,d,r),r},r.prototype.andNot=function(t){var r=e();return this.bitwiseTo(t,v,r),r},r.prototype.not=function(){for(var t=e(),r=0;r<this.t;++r)t[r]=this.DM&~this[r];return t.t=this.t,t.s=~this.s,t},r.prototype.shiftLeft=function(t){var r=e();return t<0?this.rShiftTo(-t,r):this.lShiftTo(t,r),r},r.prototype.shiftRight=function(t){var r=e();return t<0?this.lShiftTo(-t,r):this.rShiftTo(t,r),r},r.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+w(this[t]);return this.s<0?this.t*this.DB:-1},r.prototype.bitCount=function(){for(var t=0,r=this.s&this.DM,e=0;e<this.t;++e)t+=T(this[e]^r);return t},r.prototype.testBit=function(t){var r=Math.floor(t/this.DB);return r>=this.t?0!=this.s:!!(this[r]&1<<t%this.DB)},r.prototype.setBit=function(t){return this.changeBit(t,g)},r.prototype.clearBit=function(t){return this.changeBit(t,v)},r.prototype.flipBit=function(t){return this.changeBit(t,d)},r.prototype.add=function(t){var r=e();return this.addTo(t,r),r},r.prototype.subtract=function(t){var r=e();return this.subTo(t,r),r},r.prototype.multiply=function(t){var r=e();return this.multiplyTo(t,r),r},r.prototype.divide=function(t){var r=e();return this.divRemTo(t,r,null),r},r.prototype.remainder=function(t){var r=e();return this.divRemTo(t,null,r),r},r.prototype.divideAndRemainder=function(t){var r=e(),i=e();return this.divRemTo(t,r,i),new Array(r,i)},r.prototype.modPow=function(t,r){var i,o,n=t.bitLength(),s=c(1);if(n<=0)return s;i=n<18?1:n<48?3:n<144?4:n<768?5:6,o=n<8?new p(r):r.isEven()?new B(r):new y(r);var h=new Array,u=3,a=i-1,f=(1<<i)-1;if(h[1]=o.convert(this),i>1){var m=e();for(o.sqrTo(h[1],m);u<=f;)h[u]=e(),o.mulTo(m,h[u-2],h[u]),u+=2}var g,d,v=t.t-1,w=!0,T=e();for(n=l(t[v])-1;v>=0;){for(n>=a?g=t[v]>>n-a&f:(g=(t[v]&(1<<n+1)-1)<<a-n,v>0&&(g|=t[v-1]>>this.DB+n-a)),u=i;!(1&g);)g>>=1,--u;if((n-=u)<0&&(n+=this.DB,--v),w)h[g].copyTo(s),w=!1;else{for(;u>1;)o.sqrTo(s,T),o.sqrTo(T,s),u-=2;u>0?o.sqrTo(s,T):(d=s,s=T,T=d),o.mulTo(T,h[g],s)}for(;v>=0&&!(t[v]&1<<n);)o.sqrTo(s,T),d=s,s=T,T=d,--n<0&&(n=this.DB-1,--v)}return o.revert(s)},r.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return r.ZERO;for(var i=t.clone(),o=this.clone(),n=c(1),s=c(0),h=c(0),u=c(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),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(;o.isEven();)o.rShiftTo(1,o),e?(h.isEven()&&u.isEven()||(h.addTo(this,h),u.subTo(t,u)),h.rShiftTo(1,h)):u.isEven()||u.subTo(t,u),u.rShiftTo(1,u);i.compareTo(o)>=0?(i.subTo(o,i),e&&n.subTo(h,n),s.subTo(u,s)):(o.subTo(i,o),e&&h.subTo(n,h),u.subTo(s,u))}return 0!=o.compareTo(r.ONE)?r.ZERO:u.compareTo(t)>=0?u.subtract(t):u.signum()<0?(u.addTo(t,u),u.signum()<0?u.add(t):u):u},r.prototype.pow=function(t){return this.exp(t,new F)},r.prototype.gcd=function(t){var r=this.s<0?this.negate():this.clone(),e=t.s<0?t.negate():t.clone();if(r.compareTo(e)<0){var i=r;r=e,e=i}var o=r.getLowestSetBit(),n=e.getLowestSetBit();if(n<0)return r;for(o<n&&(n=o),n>0&&(r.rShiftTo(n,r),e.rShiftTo(n,e));r.signum()>0;)(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),r.compareTo(e)>=0?(r.subTo(e,r),r.rShiftTo(1,r)):(e.subTo(r,e),e.rShiftTo(1,e));return n>0&&e.lShiftTo(n,e),e},r.prototype.isProbablePrime=function(t){var r,e=this.abs();if(1==e.t&&e[0]<=D[D.length-1]){for(r=0;r<D.length;++r)if(e[0]==D[r])return!0;return!1}if(e.isEven())return!1;for(r=1;r<D.length;){for(var i=D[r],o=r+1;o<D.length&&i<S;)i*=D[o++];for(i=e.modInt(i);r<o;)if(i%D[r++]==0)return!1}return e.millerRabin(t)},r.prototype.square=function(){var t=e();return this.squareTo(t),t},r.prototype.Barrett=B,null==x){var A;if(x=new Array,E=0,"undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var R=new Uint8Array(32);for(window.crypto.getRandomValues(R),A=0;A<32;++A)x[E++]=R[A]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var P=window.crypto.random(32);for(A=0;A<P.length;++A)x[E++]=255&P.charCodeAt(A)}for(;E<H;)A=Math.floor(65536*Math.random()),x[E++]=A>>>8,x[E++]=255&A;E=0,I()}function O(){if(null==q){for(I(),(q=new C).init(x),E=0;E<x.length;++E)x[E]=0;E=0}return q.next()}function M(){}function C(){this.i=0,this.j=0,this.S=new Array}M.prototype.nextBytes=function(t){var r;for(r=0;r<t.length;++r)t[r]=O()},C.prototype.init=function(t){var r,e,i;for(r=0;r<256;++r)this.S[r]=r;for(e=0,r=0;r<256;++r)e=e+this.S[r]+t[r%t.length]&255,i=this.S[r],this.S[r]=this.S[e],this.S[e]=i;this.i=0,this.j=0},C.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var H=256;i.exports={default:r,BigInteger:r,SecureRandom:M}}.call(o);var s=n.exports;const{BigInteger:h}=s;class u{constructor(){this.tlv=null,this.t="00",this.l="00",this.v=""}getEncodedHex(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}getLength(){const t=this.v.length/2;let r=t.toString(16);if(r.length%2==1&&(r="0"+r),t<128)return r;return(128+r.length/2).toString(16)+r}getValue(){return""}}class a extends u{constructor(t){super(),this.t="02",t&&(this.v=function(t){let r=t.toString(16);if("-"!==r[0])r.length%2==1?r="0"+r:r.match(/^[0-7]/)||(r="00"+r);else{r=r.substr(1);let e=r.length;e%2==1?e+=1:r.match(/^[0-7]/)||(e+=2);let i="";for(let t=0;t<e;t++)i+="f";i=new h(i,16),r=i.xor(t).add(h.ONE),r=r.toString(16).replace(/^-/,"")}return r}(t))}getValue(){return this.v}}class f extends u{constructor(t){super(),this.t="30",this.asn1Array=t}getValue(){return this.v=this.asn1Array.map((t=>t.getEncodedHex())).join(""),this.v}}function c(t,r){return+t[r+2]<8?1:128&+t.substr(r+2,2)}function l(t,r){const e=c(t,r),i=t.substr(r+2,2*e);if(!i)return-1;return(+i[0]<8?new h(i,16):new h(i.substr(2),16)).intValue()}function p(t,r){return r+2*(c(t,r)+1)}var y={encodeDer(t,r){const e=new a(t),i=new a(r);return new f([e,i]).getEncodedHex()},decodeDer(t){const r=p(t,0),e=p(t,r),i=l(t,r),o=t.substr(e,2*i),n=e+o.length,s=p(t,n),u=l(t,n),a=t.substr(s,2*u);return{r:new h(o,16),s:new h(a,16)}}};const{BigInteger:m}=s,g=new m("2"),d=new m("3");class v{constructor(t,r){this.x=r,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 v(this.q,this.x.negate().mod(this.q))}add(t){return new v(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new v(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new v(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}divide(t){return new v(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}square(){return new v(this.q,this.x.square().mod(this.q))}}class w{constructor(t,r,e,i){this.curve=t,this.x=r,this.y=e,this.z=null==i?m.ONE:i,this.zinv=null}getX(){return null===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&&(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(m.ZERO))return!1;return t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(m.ZERO)}isInfinity(){return null===this.x&&null===this.y||this.z.equals(m.ZERO)&&!this.y.toBigInteger().equals(m.ZERO)}negate(){return new w(this.curve,this.x,this.y.negate(),this.z)}add(t){if(this.isInfinity())return t;if(t.isInfinity())return this;const r=this.x.toBigInteger(),e=this.y.toBigInteger(),i=this.z,o=t.x.toBigInteger(),n=t.y.toBigInteger(),s=t.z,h=this.curve.q,u=r.multiply(s).mod(h),a=o.multiply(i).mod(h),f=u.subtract(a),c=e.multiply(s).mod(h),l=n.multiply(i).mod(h),p=c.subtract(l);if(m.ZERO.equals(f))return m.ZERO.equals(p)?this.twice():this.curve.infinity;const y=u.add(a),g=i.multiply(s).mod(h),d=f.square().mod(h),v=f.multiply(d).mod(h),T=g.multiply(p.square()).subtract(y.multiply(d)).mod(h),F=f.multiply(T).mod(h),b=p.multiply(d.multiply(u).subtract(T)).subtract(c.multiply(v)).mod(h),B=v.multiply(g).mod(h);return new w(this.curve,this.curve.fromBigInteger(F),this.curve.fromBigInteger(b),B)}twice(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;const t=this.x.toBigInteger(),r=this.y.toBigInteger(),e=this.z,i=this.curve.q,o=this.curve.a.toBigInteger(),n=t.square().multiply(d).add(o.multiply(e.square())).mod(i),s=r.shiftLeft(1).multiply(e).mod(i),h=r.square().mod(i),u=h.multiply(t).multiply(e).mod(i),a=s.square().mod(i),f=n.square().subtract(u.shiftLeft(3)).mod(i),c=s.multiply(f).mod(i),l=n.multiply(u.shiftLeft(2).subtract(f)).subtract(a.shiftLeft(1).multiply(h)).mod(i),p=s.multiply(a).mod(i);return new w(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(l),p)}multiply(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;const r=t.multiply(d),e=this.negate();let i=this;for(let o=r.bitLength()-2;o>0;o--){i=i.twice();const n=r.testBit(o);n!==t.testBit(o)&&(i=i.add(n?this:e))}return i}}var T={ECPointFp:w,ECCurveFp:class{constructor(t,r,e){this.q=t,this.a=this.fromBigInteger(r),this.b=this.fromBigInteger(e),this.infinity=new w(this,null,null)}equals(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}fromBigInteger(t){return new v(this.q,t)}decodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:const r=this.fromBigInteger(new m(t.substr(2),16));let e=this.fromBigInteger(r.multiply(r.square()).add(r.multiply(this.a)).add(this.b).toBigInteger().modPow(this.q.divide(new m("4")).add(m.ONE),this.q));return e.toBigInteger().mod(g).equals(new m(t.substr(0,2),16).subtract(g))||(e=e.negate()),new w(this,r,e);case 4:case 6:case 7:const i=(t.length-2)/2,o=t.substr(2,i),n=t.substr(i+2,i);return new w(this,this.fromBigInteger(new m(o,16)),this.fromBigInteger(new m(n,16)));default:return null}}}};const{BigInteger:F,SecureRandom:b}=s,{ECCurveFp:B}=T,q=new b,{curve:x,G:E,n:D}=S();function S(){const t=new F("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),r=new F("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),e=new F("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),i=new B(t,r,e),o=i.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");return{curve:i,G:o,n:new F("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function I(t,r){return t.length>=r?t:new Array(r-t.length+1).join("0")+t}var A={getGlobalCurve:function(){return x},generateEcparam:S,generateKeyPairHex:function(t,r,e){const i=(t?new F(t,r,e):new F(D.bitLength(),q)).mod(D.subtract(F.ONE)).add(F.ONE),o=I(i.toString(16),64),n=E.multiply(i);return{privateKey:o,publicKey:"04"+I(n.getX().toBigInteger().toString(16),64)+I(n.getY().toBigInteger().toString(16),64)}},compressPublicKeyHex:function(t){if(130!==t.length)throw new Error("Invalid public key to compress");const r=(t.length-2)/2,e=t.substr(2,r);let i="03";return new F(t.substr(r+2,r),16).mod(new F("2")).equals(F.ZERO)&&(i="02"),i+e},utf8ToHex:function(t){const r=(t=unescape(encodeURIComponent(t))).length,e=[];for(let i=0;i<r;i++)e[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;const i=[];for(let t=0;t<r;t++){const r=e[t>>>2]>>>24-t%4*8&255;i.push((r>>>4).toString(16)),i.push((15&r).toString(16))}return i.join("")},leftPad:I,arrayToHex:function(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")},arrayToUtf8:function(t){const r=[];let e=0;for(let i=0;i<2*t.length;i+=2)r[i>>>3]|=parseInt(t[e],10)<<24-i%8*4,e++;try{const e=[];for(let i=0;i<t.length;i++){const t=r[i>>>2]>>>24-i%4*8&255;e.push(String.fromCharCode(t))}return decodeURIComponent(escape(e.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}},hexToArray:function(t){const r=[];let e=t.length;e%2!=0&&(t=I(t,e+1)),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r},verifyPublicKey:function(t){const r=x.decodePointHex(t);if(!r)return!1;const e=r.getX();return r.getY().square().equals(e.multiply(e.square()).add(e.multiply(x.a)).add(x.b))},comparePublicKeyHex:function(t,r){const e=x.decodePointHex(t);if(!e)return!1;const i=x.decodePointHex(r);return!!i&&e.equals(i)}};const R=new Uint32Array(68),P=new Uint32Array(64);function O(t,r){const e=31&r;return t<<e|t>>>32-e}function M(t,r){const e=[];for(let i=t.length-1;i>=0;i--)e[i]=255&(t[i]^r[i]);return e}function C(t){return t^O(t,9)^O(t,17)}function H(t){let r=8*t.length,e=r%512;e=e>=448?512-e%448-1:448-e-1;const i=new Array((e-7)/8),o=new Array(8);for(let t=0,r=i.length;t<r;t++)i[t]=0;for(let t=0,r=o.length;t<r;t++)o[t]=0;r=r.toString(2);for(let t=7;t>=0;t--)if(r.length>8){const e=r.length-8;o[t]=parseInt(r.substr(e),2),r=r.substr(0,e)}else r.length>0&&(o[t]=parseInt(r,2),r="");const n=new Uint8Array([...t,128,...i,...o]),s=new DataView(n.buffer,0),h=n.length/64,u=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]);for(let t=0;t<h;t++){R.fill(0),P.fill(0);const r=16*t;for(let t=0;t<16;t++)R[t]=s.getUint32(4*(r+t),!1);for(let t=16;t<68;t++)R[t]=(a=R[t-16]^R[t-9]^O(R[t-3],15))^O(a,15)^O(a,23)^O(R[t-13],7)^R[t-6];for(let t=0;t<64;t++)P[t]=R[t]^R[t+4];const e=2043430169,i=2055708042;let o,n,h,f,c,l=u[0],p=u[1],y=u[2],m=u[3],g=u[4],d=u[5],v=u[6],w=u[7];for(let t=0;t<64;t++)c=t>=0&&t<=15?e:i,o=O(O(l,12)+g+O(c,t),7),n=o^O(l,12),h=(t>=0&&t<=15?l^p^y:l&p|l&y|p&y)+m+n+P[t],f=(t>=0&&t<=15?g^d^v:g&d|~g&v)+w+o+R[t],m=y,y=O(p,9),p=l,l=h,w=v,v=O(d,19),d=g,g=C(f);u[0]^=l,u[1]^=p,u[2]^=y,u[3]^=m,u[4]^=g,u[5]^=d,u[6]^=v,u[7]^=w}var a;const f=[];for(let t=0,r=u.length;t<r;t++){const r=u[t];f.push((4278190080&r)>>>24,(16711680&r)>>>16,(65280&r)>>>8,255&r)}return f}const V=new Uint8Array(64),N=new Uint8Array(64);for(let t=0;t<64;t++)V[t]=54,N[t]=92;var K={sm3:H,hmac:function(t,r){for(r.length>64&&(r=H(r));r.length<64;)r.push(0);const e=M(r,V),i=M(r,N),o=H([...e,...t]);return H([...i,...o])}};const{BigInteger:L}=s,{encodeDer:z,decodeDer:k}=y,Z=A,j=K.sm3,{G:U,curve:$,n:X}=Z.generateEcparam();function Y(t,r,e="1234567812345678"){e=Z.utf8ToHex(e);const i=Z.leftPad(U.curve.a.toBigInteger().toRadix(16),64),o=Z.leftPad(U.curve.b.toBigInteger().toRadix(16),64),n=Z.leftPad(U.getX().toBigInteger().toRadix(16),64),s=Z.leftPad(U.getY().toBigInteger().toRadix(16),64);let h,u;if(128===r.length)h=r.substr(0,64),u=r.substr(64,64);else{const t=U.curve.decodePointHex(r);h=Z.leftPad(t.getX().toBigInteger().toRadix(16),64),u=Z.leftPad(t.getY().toBigInteger().toRadix(16),64)}const a=Z.hexToArray(e+i+o+n+s+h+u),f=4*e.length;a.unshift(255&f),a.unshift(f>>8&255);const c=j(a);return Z.arrayToHex(j(c.concat(Z.hexToArray(t))))}function G(t){const r=U.multiply(new L(t,16));return"04"+Z.leftPad(r.getX().toBigInteger().toString(16),64)+Z.leftPad(r.getY().toBigInteger().toString(16),64)}function J(){const t=Z.generateKeyPairHex(),r=$.decodePointHex(t.publicKey);return t.k=new L(t.privateKey,16),t.x1=r.getX().toBigInteger(),t}var W={generateKeyPairHex:Z.generateKeyPairHex,compressPublicKeyHex:Z.compressPublicKeyHex,comparePublicKeyHex:Z.comparePublicKeyHex,doEncrypt:function(t,r,e=1){t="string"==typeof t?Z.hexToArray(Z.utf8ToHex(t)):Array.prototype.slice.call(t),r=Z.getGlobalCurve().decodePointHex(r);const i=Z.generateKeyPairHex(),o=new L(i.privateKey,16);let n=i.publicKey;n.length>128&&(n=n.substr(n.length-128));const s=r.multiply(o),h=Z.hexToArray(Z.leftPad(s.getX().toBigInteger().toRadix(16),64)),u=Z.hexToArray(Z.leftPad(s.getY().toBigInteger().toRadix(16),64)),a=Z.arrayToHex(j([].concat(h,t,u)));let f=1,c=0,l=[];const p=[].concat(h,u),y=()=>{l=j([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let r=0,e=t.length;r<e;r++)c===l.length&&y(),t[r]^=255&l[c++];const m=Z.arrayToHex(t);return 0===e?n+m+a:n+a+m},doDecrypt:function(t,r,e=1,{output:i="string"}={}){r=new L(r,16);let o=t.substr(128,64),n=t.substr(192);0===e&&(o=t.substr(t.length-64),n=t.substr(128,t.length-128-64));const s=Z.hexToArray(n),h=Z.getGlobalCurve().decodePointHex("04"+t.substr(0,128)).multiply(r),u=Z.hexToArray(Z.leftPad(h.getX().toBigInteger().toRadix(16),64)),a=Z.hexToArray(Z.leftPad(h.getY().toBigInteger().toRadix(16),64));let f=1,c=0,l=[];const p=[].concat(u,a),y=()=>{l=j([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let t=0,r=s.length;t<r;t++)c===l.length&&y(),s[t]^=255&l[c++];return Z.arrayToHex(j([].concat(u,s,a)))===o.toLowerCase()?"array"===i?s:Z.arrayToUtf8(s):"array"===i?[]:""},doSignature:function(t,r,{pointPool:e,der:i,hash:o,publicKey:n,userId:s}={}){let h="string"==typeof t?Z.utf8ToHex(t):Z.arrayToHex(t);o&&(h=Y(h,n=n||G(r),s));const u=new L(r,16),a=new L(h,16);let f=null,c=null,l=null;do{do{let t;t=e&&e.length?e.pop():J(),f=t.k,c=a.add(t.x1).mod(X)}while(c.equals(L.ZERO)||c.add(f).equals(X));l=u.add(L.ONE).modInverse(X).multiply(f.subtract(c.multiply(u))).mod(X)}while(l.equals(L.ZERO));return i?z(c,l):Z.leftPad(c.toString(16),64)+Z.leftPad(l.toString(16),64)},doVerifySignature:function(t,r,e,{der:i,hash:o,userId:n}={}){let s,h,u="string"==typeof t?Z.utf8ToHex(t):Z.arrayToHex(t);if(o&&(u=Y(u,e,n)),i){const t=k(r);s=t.r,h=t.s}else s=new L(r.substring(0,64),16),h=new L(r.substring(64),16);const a=$.decodePointHex(e),f=new L(u,16),c=s.add(h).mod(X);if(c.equals(L.ZERO))return!1;const l=U.multiply(h).add(a.multiply(c)),p=f.add(l.getX().toBigInteger()).mod(X);return s.equals(p)},getPublicKeyFromPrivateKey:G,getPoint:J,verifyPublicKey:Z.verifyPublicKey};const{sm3:Q,hmac:_}=K;function tt(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")}function rt(t){const r=[];let e=t.length;var i,o;e%2!=0&&(o=e+1,t=(i=t).length>=o?i:new Array(o-i.length+1).join("0")+i),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r}const et=0,it=16,ot=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],nt=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];function st(t){const r=[];for(let e=0,i=t.length;e<i;e+=2)r.push(parseInt(t.substr(e,2),16));return r}function ht(t,r){const e=31&r;return t<<e|t>>>32-e}function ut(t){return(255&ot[t>>>24&255])<<24|(255&ot[t>>>16&255])<<16|(255&ot[t>>>8&255])<<8|255&ot[255&t]}function at(t){return t^ht(t,2)^ht(t,10)^ht(t,18)^ht(t,24)}function ft(t){return t^ht(t,13)^ht(t,23)}function ct(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[4*r],o[1]=255&t[4*r+1],o[2]=255&t[4*r+2],o[3]=255&t[4*r+3],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(let t,r=0;r<32;r+=4)t=i[1]^i[2]^i[3]^e[r+0],i[0]^=at(ut(t)),t=i[2]^i[3]^i[0]^e[r+1],i[1]^=at(ut(t)),t=i[3]^i[0]^i[1]^e[r+2],i[2]^=at(ut(t)),t=i[0]^i[1]^i[2]^e[r+3],i[3]^=at(ut(t));for(let t=0;t<16;t+=4)r[t]=i[3-t/4]>>>24&255,r[t+1]=i[3-t/4]>>>16&255,r[t+2]=i[3-t/4]>>>8&255,r[t+3]=255&i[3-t/4]}function lt(t,r,e,{padding:i="pkcs#7",mode:o,iv:n=[],output:s="string"}={}){if("cbc"===o&&("string"==typeof n&&(n=st(n)),16!==n.length))throw new Error("iv is invalid");if("string"==typeof r&&(r=st(r)),16!==r.length)throw new Error("key is invalid");if(t="string"==typeof t?e!==et?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):st(t):[...t],("pkcs#5"===i||"pkcs#7"===i)&&e!==et){const r=it-t.length%it;for(let e=0;e<r;e++)t.push(r)}const h=new Array(32);!function(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[0+4*r],o[1]=255&t[1+4*r],o[2]=255&t[2+4*r],o[3]=255&t[3+4*r],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];i[0]^=2746333894,i[1]^=1453994832,i[2]^=1736282519,i[3]^=2993693404;for(let t,e=0;e<32;e+=4)t=i[1]^i[2]^i[3]^nt[e+0],r[e+0]=i[0]^=ft(ut(t)),t=i[2]^i[3]^i[0]^nt[e+1],r[e+1]=i[1]^=ft(ut(t)),t=i[3]^i[0]^i[1]^nt[e+2],r[e+2]=i[2]^=ft(ut(t)),t=i[0]^i[1]^i[2]^nt[e+3],r[e+3]=i[3]^=ft(ut(t));if(e===et)for(let t,e=0;e<16;e++)t=r[e],r[e]=r[31-e],r[31-e]=t}(r,h,e);const u=[];let a=n,f=t.length,c=0;for(;f>=it;){const r=t.slice(c,c+16),i=new Array(16);if("cbc"===o)for(let t=0;t<it;t++)e!==et&&(r[t]^=a[t]);ct(r,i,h);for(let t=0;t<it;t++)"cbc"===o&&e===et&&(i[t]^=a[t]),u[c+t]=i[t];"cbc"===o&&(a=e!==et?i:r),f-=it,c+=it}if(("pkcs#5"===i||"pkcs#7"===i)&&e===et){const t=u.length,r=u[t-1];for(let e=1;e<=r;e++)if(u[t-e]!==r)throw new Error("padding is invalid");u.splice(t-r,r)}return"array"!==s?e!==et?u.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join(""):function(t){const r=[];for(let e=0,i=t.length;e<i;e++)t[e]>=240&&t[e]<=247?(r.push(String.fromCodePoint(((7&t[e])<<18)+((63&t[e+1])<<12)+((63&t[e+2])<<6)+(63&t[e+3]))),e+=3):t[e]>=224&&t[e]<=239?(r.push(String.fromCodePoint(((15&t[e])<<12)+((63&t[e+1])<<6)+(63&t[e+2]))),e+=2):t[e]>=192&&t[e]<=223?(r.push(String.fromCodePoint(((31&t[e])<<6)+(63&t[e+1]))),e++):r.push(String.fromCodePoint(t[e]));return r.join("")}(u):u}var pt={sm2:W,sm3:function(t,r){if(t="string"==typeof t?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):Array.prototype.slice.call(t),r){if("hmac"!==(r.mode||"hmac"))throw new Error("invalid mode");let e=r.key;if(!e)throw new Error("invalid key");return e="string"==typeof e?rt(e):Array.prototype.slice.call(e),tt(_(t,e))}return tt(Q(t))},sm4:{encrypt:(t,r,e)=>lt(t,r,1,e),decrypt:(t,r,e)=>lt(t,r,0,e)}};const yt=(t=16,r="high")=>{const e=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],i=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],o=[0,1,2,3,4,5,6,7,8,9],n=["!","@","-","_","=","<",">","#","*","%","+","&","^","$"],s=[];let h="";const u=function(...t){let r="";return t.forEach((t=>{r+=t[Math.floor(Math.random()*t.length)]})),r};switch(r){case"high":h+=u(e,i,o,n),s.push(...e,...i,...o,...n);break;case"medium":h+=u(e,i,o),s.push(...e,...i,...o);break;default:h+=u(e,o),s.push(...e,...o)}const a=t-h.length;for(let t=0;t<a;t++)h+=u(s);return h};function mt(t,r="utf-8"){return new TextDecoder(r).decode(t)}function gt(t){try{return t instanceof ArrayBuffer?dt(mt(t)):t}catch(t){throw console.error("error",t),t}}function dt(t){try{return"string"==typeof t?JSON.parse(t):t}catch(t){throw console.error("error",t),t}}const vt=t=>{let r=!0;return!(t=>/^\/bi-api\/api/.test(t))(t)&&(t.startsWith("/api")&&(r=!1,(t=>/^\/(api\/logmanage|api\/data-source|api\/enterpriseadmin|api\/componentmanager|api\/spacemanager|api\/filemanager)/.test(t))(t)&&(r=!0)),r)},wt=t=>({...{key:yt(16,"high"),algorithm:t||"SM4"}}),Tt=()=>({mode:"ecb",padding:"pkcs#7",output:"array"}),Ft=r.Buffer,bt={mode:"ecb",padding:"pkcs#7",output:"array"};function Bt(t,r){if(!r||"string"!=typeof r)throw new Error(`publicKey is required and must be a string ${r}`);t.interceptors.request.use((t=>{const r=t.url,e=t.headers;if(!r)throw new Error("url is required");if({}.hasOwnProperty.call(e,"closeCrypto"))return t;const i=vt(r);return console.log(`url: ${r} shouldCloseCrypto: ${i}`),i||(e.closeCrypto=!0),t})),t.interceptors.request.use((t=>(t.headers.closeCrypto||(t.responseType="arraybuffer"),t))),t.interceptors.request.use((t=>{const e=t.transformRequest,i={info:null,publicKey:[]};if(!e)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(e))throw new Error(`transformRequest ${e} is not an array`);e.push(function(t,r){return(e,i)=>{try{if(i.closeCrypto)return e;if(t.info=wt(),t.publicKey=[...Ft.from(t.info.key)],((t,r)=>{t.set("X-Encrypt-Key",r)})(i,pt.sm2.doEncrypt(JSON.stringify(t.info),r,1)),e){"string"!=typeof e&&(e=JSON.stringify(e));const r=pt.sm4.encrypt(e,t.publicKey,bt);return Ft.from(r)}return e}catch(t){console.error("encrypt error",t,e,i)}}}(i,r));const o=function(t){return(r,e)=>{try{if((t=>{const r=t.get("X-Encrypt-With");return r&&"string"==typeof r&&"sm4"===r.toLowerCase()})(e)){const e=Ft.from(r);return dt(pt.sm4.decrypt(e,t.publicKey,{mode:"ecb",padding:"pkcs#7"}))}return gt(r)}catch(t){console.error("decrypt error",t,r,e)}}}(i);if(!o)return t;const n=t.transformResponse;if(!n)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof o)throw new Error(`decryptFn ${o} is not a function`);if(!Array.isArray(n))throw new Error(`transformResponse ${n} is not an array`);return n.unshift(o),t})),t.interceptors.response.use((t=>(t.data=gt(t.data),t.data=dt(t.data),t)),(t=>{const r=t.response;throw r?.data&&(r.data=function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){throw console.error("error",t),t}return t instanceof ArrayBuffer?mt(t):t}(r.data)),t}))}const qt=(r,e)=>{const i=t.create(r);return Bt(i,e),i};export{qt as createCryptoAxiosInstance,e as createRequestInstance,wt as getCryptoInfo,Tt as getSm4EncryptConfig,yt as randomPassword,vt as shouldEncrypt};
import t from"axios";import r from"buffer";const e=(r,e)=>{const i=t.create(r);return function(t,r){if(!r)return t;const{encryptFn:e,decryptFn:i}=r();e&&t.interceptors.request.use((t=>{const r=t.transformRequest;if(!r)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(r))throw new Error(`transformRequest ${r} is not an array`);if(r.push(e),!i)return t;const o=t.transformResponse;if(!o)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof i)throw new Error(`decryptFn ${i} is not a function`);if(!Array.isArray(o))throw new Error(`transformResponse ${o} is not an array`);return o.unshift(i),t}))}(i,e),i};var i,o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n={exports:{}};i=n,function(){var t;function r(t,r,e){null!=t&&("number"==typeof t?this.fromNumber(t,r,e):null==r&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,r))}function e(){return new r(null)}var o="undefined"!=typeof navigator;o&&"Microsoft Internet Explorer"==navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(var s=32767&r,h=r>>15;--n>=0;){var u=32767&this[t],a=this[t++]>>15,f=h*u+a*s;o=((u=s*u+((32767&f)<<15)+e[i]+(1073741823&o))>>>30)+(f>>>15)+h*a+(o>>>30),e[i++]=1073741823&u}return o},t=30):o&&"Netscape"!=navigator.appName?(r.prototype.am=function(t,r,e,i,o,n){for(;--n>=0;){var s=r*this[t++]+e[i]+o;o=Math.floor(s/67108864),e[i++]=67108863&s}return o},t=26):(r.prototype.am=function(t,r,e,i,o,n){for(var s=16383&r,h=r>>14;--n>=0;){var u=16383&this[t],a=this[t++]>>14,f=h*u+a*s;o=((u=s*u+((16383&f)<<14)+e[i]+o)>>28)+(f>>14)+h*a,e[i++]=268435455&u}return o},t=28),r.prototype.DB=t,r.prototype.DM=(1<<t)-1,r.prototype.DV=1<<t,r.prototype.FV=Math.pow(2,52),r.prototype.F1=52-t,r.prototype.F2=2*t-52;var n,s,h="0123456789abcdefghijklmnopqrstuvwxyz",u=new Array;for(n="0".charCodeAt(0),s=0;s<=9;++s)u[n++]=s;for(n="a".charCodeAt(0),s=10;s<36;++s)u[n++]=s;for(n="A".charCodeAt(0),s=10;s<36;++s)u[n++]=s;function a(t){return h.charAt(t)}function f(t,r){var e=u[t.charCodeAt(r)];return null==e?-1:e}function c(t){var r=e();return r.fromInt(t),r}function l(t){var r,e=1;return 0!=(r=t>>>16)&&(t=r,e+=16),0!=(r=t>>8)&&(t=r,e+=8),0!=(r=t>>4)&&(t=r,e+=4),0!=(r=t>>2)&&(t=r,e+=2),0!=(r=t>>1)&&(t=r,e+=1),e}function p(t){this.m=t}function y(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}function m(t,r){return t&r}function g(t,r){return t|r}function d(t,r){return t^r}function v(t,r){return t&~r}function w(t){if(0==t)return-1;var r=0;return 65535&t||(t>>=16,r+=16),255&t||(t>>=8,r+=8),15&t||(t>>=4,r+=4),3&t||(t>>=2,r+=2),1&t||++r,r}function T(t){for(var r=0;0!=t;)t&=t-1,++r;return r}function F(){}function b(t){return t}function B(t){this.r2=e(),this.q3=e(),r.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}p.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},p.prototype.revert=function(t){return t},p.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},p.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},p.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},y.prototype.convert=function(t){var i=e();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(r.ZERO)>0&&this.m.subTo(i,i),i},y.prototype.revert=function(t){var r=e();return t.copyTo(r),this.reduce(r),r},y.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var r=0;r<this.m.t;++r){var e=32767&t[r],i=e*this.mpl+((e*this.mph+(t[r]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[e=r+this.m.t]+=this.m.am(0,i,t,r,0,this.m.t);t[e]>=t.DV;)t[e]-=t.DV,t[++e]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},y.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},y.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)},r.prototype.copyTo=function(t){for(var r=this.t-1;r>=0;--r)t[r]=this[r];t.t=this.t,t.s=this.s},r.prototype.fromInt=function(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},r.prototype.fromString=function(t,e){var i;if(16==e)i=4;else if(8==e)i=3;else if(256==e)i=8;else if(2==e)i=1;else if(32==e)i=5;else{if(4!=e)return void this.fromRadix(t,e);i=2}this.t=0,this.s=0;for(var o=t.length,n=!1,s=0;--o>=0;){var h=8==i?255&t[o]:f(t,o);h<0?"-"==t.charAt(o)&&(n=!0):(n=!1,0==s?this[this.t++]=h:s+i>this.DB?(this[this.t-1]|=(h&(1<<this.DB-s)-1)<<s,this[this.t++]=h>>this.DB-s):this[this.t-1]|=h<<s,(s+=i)>=this.DB&&(s-=this.DB))}8==i&&128&t[0]&&(this.s=-1,s>0&&(this[this.t-1]|=(1<<this.DB-s)-1<<s)),this.clamp(),n&&r.ZERO.subTo(this,this)},r.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},r.prototype.dlShiftTo=function(t,r){var e;for(e=this.t-1;e>=0;--e)r[e+t]=this[e];for(e=t-1;e>=0;--e)r[e]=0;r.t=this.t+t,r.s=this.s},r.prototype.drShiftTo=function(t,r){for(var e=t;e<this.t;++e)r[e-t]=this[e];r.t=Math.max(this.t-t,0),r.s=this.s},r.prototype.lShiftTo=function(t,r){var e,i=t%this.DB,o=this.DB-i,n=(1<<o)-1,s=Math.floor(t/this.DB),h=this.s<<i&this.DM;for(e=this.t-1;e>=0;--e)r[e+s+1]=this[e]>>o|h,h=(this[e]&n)<<i;for(e=s-1;e>=0;--e)r[e]=0;r[s]=h,r.t=this.t+s+1,r.s=this.s,r.clamp()},r.prototype.rShiftTo=function(t,r){r.s=this.s;var e=Math.floor(t/this.DB);if(e>=this.t)r.t=0;else{var i=t%this.DB,o=this.DB-i,n=(1<<i)-1;r[0]=this[e]>>i;for(var s=e+1;s<this.t;++s)r[s-e-1]|=(this[s]&n)<<o,r[s-e]=this[s]>>i;i>0&&(r[this.t-e-1]|=(this.s&n)<<o),r.t=this.t-e,r.clamp()}},r.prototype.subTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]-t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i-=t[e],r[e++]=i&this.DM,i>>=this.DB;i-=t.s}r.s=i<0?-1:0,i<-1?r[e++]=this.DV+i:i>0&&(r[e++]=i),r.t=e,r.clamp()},r.prototype.multiplyTo=function(t,e){var i=this.abs(),o=t.abs(),n=i.t;for(e.t=n+o.t;--n>=0;)e[n]=0;for(n=0;n<o.t;++n)e[n+i.t]=i.am(0,o[n],e,n,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&r.ZERO.subTo(e,e)},r.prototype.squareTo=function(t){for(var r=this.abs(),e=t.t=2*r.t;--e>=0;)t[e]=0;for(e=0;e<r.t-1;++e){var i=r.am(e,r[e],t,2*e,0,1);(t[e+r.t]+=r.am(e+1,2*r[e],t,2*e+1,i,r.t-e-1))>=r.DV&&(t[e+r.t]-=r.DV,t[e+r.t+1]=1)}t.t>0&&(t[t.t-1]+=r.am(e,r[e],t,2*e,0,1)),t.s=0,t.clamp()},r.prototype.divRemTo=function(t,i,o){var n=t.abs();if(!(n.t<=0)){var s=this.abs();if(s.t<n.t)return null!=i&&i.fromInt(0),void(null!=o&&this.copyTo(o));null==o&&(o=e());var h=e(),u=this.s,a=t.s,f=this.DB-l(n[n.t-1]);f>0?(n.lShiftTo(f,h),s.lShiftTo(f,o)):(n.copyTo(h),s.copyTo(o));var c=h.t,p=h[c-1];if(0!=p){var y=p*(1<<this.F1)+(c>1?h[c-2]>>this.F2:0),m=this.FV/y,g=(1<<this.F1)/y,d=1<<this.F2,v=o.t,w=v-c,T=null==i?e():i;for(h.dlShiftTo(w,T),o.compareTo(T)>=0&&(o[o.t++]=1,o.subTo(T,o)),r.ONE.dlShiftTo(c,T),T.subTo(h,h);h.t<c;)h[h.t++]=0;for(;--w>=0;){var F=o[--v]==p?this.DM:Math.floor(o[v]*m+(o[v-1]+d)*g);if((o[v]+=h.am(0,F,o,w,0,c))<F)for(h.dlShiftTo(w,T),o.subTo(T,o);o[v]<--F;)o.subTo(T,o)}null!=i&&(o.drShiftTo(c,i),u!=a&&r.ZERO.subTo(i,i)),o.t=c,o.clamp(),f>0&&o.rShiftTo(f,o),u<0&&r.ZERO.subTo(o,o)}}},r.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var r=3&t;return(r=(r=(r=(r=r*(2-(15&t)*r)&15)*(2-(255&t)*r)&255)*(2-((65535&t)*r&65535))&65535)*(2-t*r%this.DV)%this.DV)>0?this.DV-r:-r},r.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},r.prototype.exp=function(t,i){if(t>4294967295||t<1)return r.ONE;var o=e(),n=e(),s=i.convert(this),h=l(t)-1;for(s.copyTo(o);--h>=0;)if(i.sqrTo(o,n),(t&1<<h)>0)i.mulTo(n,s,o);else{var u=o;o=n,n=u}return i.revert(o)},r.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var r;if(16==t)r=4;else if(8==t)r=3;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return this.toRadix(t);r=2}var e,i=(1<<r)-1,o=!1,n="",s=this.t,h=this.DB-s*this.DB%r;if(s-- >0)for(h<this.DB&&(e=this[s]>>h)>0&&(o=!0,n=a(e));s>=0;)h<r?(e=(this[s]&(1<<h)-1)<<r-h,e|=this[--s]>>(h+=this.DB-r)):(e=this[s]>>(h-=r)&i,h<=0&&(h+=this.DB,--s)),e>0&&(o=!0),o&&(n+=a(e));return o?n:"0"},r.prototype.negate=function(){var t=e();return r.ZERO.subTo(this,t),t},r.prototype.abs=function(){return this.s<0?this.negate():this},r.prototype.compareTo=function(t){var r=this.s-t.s;if(0!=r)return r;var e=this.t;if(0!=(r=e-t.t))return this.s<0?-r:r;for(;--e>=0;)if(0!=(r=this[e]-t[e]))return r;return 0},r.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+l(this[this.t-1]^this.s&this.DM)},r.prototype.mod=function(t){var i=e();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(r.ZERO)>0&&t.subTo(i,i),i},r.prototype.modPowInt=function(t,r){var e;return e=t<256||r.isEven()?new p(r):new y(r),this.exp(t,e)},r.ZERO=c(0),r.ONE=c(1),F.prototype.convert=b,F.prototype.revert=b,F.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e)},F.prototype.sqrTo=function(t,r){t.squareTo(r)},B.prototype.convert=function(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var r=e();return t.copyTo(r),this.reduce(r),r},B.prototype.revert=function(t){return t},B.prototype.reduce=function(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)},B.prototype.mulTo=function(t,r,e){t.multiplyTo(r,e),this.reduce(e)},B.prototype.sqrTo=function(t,r){t.squareTo(r),this.reduce(r)};var q,x,E,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],S=(1<<26)/D[D.length-1];function I(){var t;t=(new Date).getTime(),x[E++]^=255&t,x[E++]^=t>>8&255,x[E++]^=t>>16&255,x[E++]^=t>>24&255,E>=H&&(E-=H)}if(r.prototype.chunkSize=function(t){return Math.floor(Math.LN2*this.DB/Math.log(t))},r.prototype.toRadix=function(t){if(null==t&&(t=10),0==this.signum()||t<2||t>36)return"0";var r=this.chunkSize(t),i=Math.pow(t,r),o=c(i),n=e(),s=e(),h="";for(this.divRemTo(o,n,s);n.signum()>0;)h=(i+s.intValue()).toString(t).substr(1)+h,n.divRemTo(o,n,s);return s.intValue().toString(t)+h},r.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),o=Math.pow(e,i),n=!1,s=0,h=0,u=0;u<t.length;++u){var a=f(t,u);a<0?"-"==t.charAt(u)&&0==this.signum()&&(n=!0):(h=e*h+a,++s>=i&&(this.dMultiply(o),this.dAddOffset(h,0),s=0,h=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(h,0)),n&&r.ZERO.subTo(this,this)},r.prototype.fromNumber=function(t,e,i){if("number"==typeof e)if(t<2)this.fromInt(1);else for(this.fromNumber(t,i),this.testBit(t-1)||this.bitwiseTo(r.ONE.shiftLeft(t-1),g,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(r.ONE.shiftLeft(t-1),this);else{var o=new Array,n=7&t;o.length=1+(t>>3),e.nextBytes(o),n>0?o[0]&=(1<<n)-1:o[0]=0,this.fromString(o,256)}},r.prototype.bitwiseTo=function(t,r,e){var i,o,n=Math.min(t.t,this.t);for(i=0;i<n;++i)e[i]=r(this[i],t[i]);if(t.t<this.t){for(o=t.s&this.DM,i=n;i<this.t;++i)e[i]=r(this[i],o);e.t=this.t}else{for(o=this.s&this.DM,i=n;i<t.t;++i)e[i]=r(o,t[i]);e.t=t.t}e.s=r(this.s,t.s),e.clamp()},r.prototype.changeBit=function(t,e){var i=r.ONE.shiftLeft(t);return this.bitwiseTo(i,e,i),i},r.prototype.addTo=function(t,r){for(var e=0,i=0,o=Math.min(t.t,this.t);e<o;)i+=this[e]+t[e],r[e++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;e<this.t;)i+=this[e],r[e++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;e<t.t;)i+=t[e],r[e++]=i&this.DM,i>>=this.DB;i+=t.s}r.s=i<0?-1:0,i>0?r[e++]=i:i<-1&&(r[e++]=this.DV+i),r.t=e,r.clamp()},r.prototype.dMultiply=function(t){this[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()},r.prototype.dAddOffset=function(t,r){if(0!=t){for(;this.t<=r;)this[this.t++]=0;for(this[r]+=t;this[r]>=this.DV;)this[r]-=this.DV,++r>=this.t&&(this[this.t++]=0),++this[r]}},r.prototype.multiplyLowerTo=function(t,r,e){var i,o=Math.min(this.t+t.t,r);for(e.s=0,e.t=o;o>0;)e[--o]=0;for(i=e.t-this.t;o<i;++o)e[o+this.t]=this.am(0,t[o],e,o,0,this.t);for(i=Math.min(t.t,r);o<i;++o)this.am(0,t[o],e,o,0,r-o);e.clamp()},r.prototype.multiplyUpperTo=function(t,r,e){--r;var i=e.t=this.t+t.t-r;for(e.s=0;--i>=0;)e[i]=0;for(i=Math.max(r-this.t,0);i<t.t;++i)e[this.t+i-r]=this.am(r-i,t[i],e,0,0,this.t+i-r);e.clamp(),e.drShiftTo(1,e)},r.prototype.modInt=function(t){if(t<=0)return 0;var r=this.DV%t,e=this.s<0?t-1:0;if(this.t>0)if(0==r)e=this[0]%t;else for(var i=this.t-1;i>=0;--i)e=(r*e+this[i])%t;return e},r.prototype.millerRabin=function(t){var i=this.subtract(r.ONE),o=i.getLowestSetBit();if(o<=0)return!1;var n=i.shiftRight(o);(t=t+1>>1)>D.length&&(t=D.length);for(var s=e(),h=0;h<t;++h){s.fromInt(D[Math.floor(Math.random()*D.length)]);var u=s.modPow(n,this);if(0!=u.compareTo(r.ONE)&&0!=u.compareTo(i)){for(var a=1;a++<o&&0!=u.compareTo(i);)if(0==(u=u.modPowInt(2,this)).compareTo(r.ONE))return!1;if(0!=u.compareTo(i))return!1}}return!0},r.prototype.clone=function(){var t=e();return this.copyTo(t),t},r.prototype.intValue=function(){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]},r.prototype.byteValue=function(){return 0==this.t?this.s:this[0]<<24>>24},r.prototype.shortValue=function(){return 0==this.t?this.s:this[0]<<16>>16},r.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this[0]<=0?0:1},r.prototype.toByteArray=function(){var t=this.t,r=new Array;r[0]=this.s;var e,i=this.DB-t*this.DB%8,o=0;if(t-- >0)for(i<this.DB&&(e=this[t]>>i)!=(this.s&this.DM)>>i&&(r[o++]=e|this.s<<this.DB-i);t>=0;)i<8?(e=(this[t]&(1<<i)-1)<<8-i,e|=this[--t]>>(i+=this.DB-8)):(e=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),128&e&&(e|=-256),0==o&&(128&this.s)!=(128&e)&&++o,(o>0||e!=this.s)&&(r[o++]=e);return r},r.prototype.equals=function(t){return 0==this.compareTo(t)},r.prototype.min=function(t){return this.compareTo(t)<0?this:t},r.prototype.max=function(t){return this.compareTo(t)>0?this:t},r.prototype.and=function(t){var r=e();return this.bitwiseTo(t,m,r),r},r.prototype.or=function(t){var r=e();return this.bitwiseTo(t,g,r),r},r.prototype.xor=function(t){var r=e();return this.bitwiseTo(t,d,r),r},r.prototype.andNot=function(t){var r=e();return this.bitwiseTo(t,v,r),r},r.prototype.not=function(){for(var t=e(),r=0;r<this.t;++r)t[r]=this.DM&~this[r];return t.t=this.t,t.s=~this.s,t},r.prototype.shiftLeft=function(t){var r=e();return t<0?this.rShiftTo(-t,r):this.lShiftTo(t,r),r},r.prototype.shiftRight=function(t){var r=e();return t<0?this.lShiftTo(-t,r):this.rShiftTo(t,r),r},r.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+w(this[t]);return this.s<0?this.t*this.DB:-1},r.prototype.bitCount=function(){for(var t=0,r=this.s&this.DM,e=0;e<this.t;++e)t+=T(this[e]^r);return t},r.prototype.testBit=function(t){var r=Math.floor(t/this.DB);return r>=this.t?0!=this.s:!!(this[r]&1<<t%this.DB)},r.prototype.setBit=function(t){return this.changeBit(t,g)},r.prototype.clearBit=function(t){return this.changeBit(t,v)},r.prototype.flipBit=function(t){return this.changeBit(t,d)},r.prototype.add=function(t){var r=e();return this.addTo(t,r),r},r.prototype.subtract=function(t){var r=e();return this.subTo(t,r),r},r.prototype.multiply=function(t){var r=e();return this.multiplyTo(t,r),r},r.prototype.divide=function(t){var r=e();return this.divRemTo(t,r,null),r},r.prototype.remainder=function(t){var r=e();return this.divRemTo(t,null,r),r},r.prototype.divideAndRemainder=function(t){var r=e(),i=e();return this.divRemTo(t,r,i),new Array(r,i)},r.prototype.modPow=function(t,r){var i,o,n=t.bitLength(),s=c(1);if(n<=0)return s;i=n<18?1:n<48?3:n<144?4:n<768?5:6,o=n<8?new p(r):r.isEven()?new B(r):new y(r);var h=new Array,u=3,a=i-1,f=(1<<i)-1;if(h[1]=o.convert(this),i>1){var m=e();for(o.sqrTo(h[1],m);u<=f;)h[u]=e(),o.mulTo(m,h[u-2],h[u]),u+=2}var g,d,v=t.t-1,w=!0,T=e();for(n=l(t[v])-1;v>=0;){for(n>=a?g=t[v]>>n-a&f:(g=(t[v]&(1<<n+1)-1)<<a-n,v>0&&(g|=t[v-1]>>this.DB+n-a)),u=i;!(1&g);)g>>=1,--u;if((n-=u)<0&&(n+=this.DB,--v),w)h[g].copyTo(s),w=!1;else{for(;u>1;)o.sqrTo(s,T),o.sqrTo(T,s),u-=2;u>0?o.sqrTo(s,T):(d=s,s=T,T=d),o.mulTo(T,h[g],s)}for(;v>=0&&!(t[v]&1<<n);)o.sqrTo(s,T),d=s,s=T,T=d,--n<0&&(n=this.DB-1,--v)}return o.revert(s)},r.prototype.modInverse=function(t){var e=t.isEven();if(this.isEven()&&e||0==t.signum())return r.ZERO;for(var i=t.clone(),o=this.clone(),n=c(1),s=c(0),h=c(0),u=c(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),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(;o.isEven();)o.rShiftTo(1,o),e?(h.isEven()&&u.isEven()||(h.addTo(this,h),u.subTo(t,u)),h.rShiftTo(1,h)):u.isEven()||u.subTo(t,u),u.rShiftTo(1,u);i.compareTo(o)>=0?(i.subTo(o,i),e&&n.subTo(h,n),s.subTo(u,s)):(o.subTo(i,o),e&&h.subTo(n,h),u.subTo(s,u))}return 0!=o.compareTo(r.ONE)?r.ZERO:u.compareTo(t)>=0?u.subtract(t):u.signum()<0?(u.addTo(t,u),u.signum()<0?u.add(t):u):u},r.prototype.pow=function(t){return this.exp(t,new F)},r.prototype.gcd=function(t){var r=this.s<0?this.negate():this.clone(),e=t.s<0?t.negate():t.clone();if(r.compareTo(e)<0){var i=r;r=e,e=i}var o=r.getLowestSetBit(),n=e.getLowestSetBit();if(n<0)return r;for(o<n&&(n=o),n>0&&(r.rShiftTo(n,r),e.rShiftTo(n,e));r.signum()>0;)(o=r.getLowestSetBit())>0&&r.rShiftTo(o,r),(o=e.getLowestSetBit())>0&&e.rShiftTo(o,e),r.compareTo(e)>=0?(r.subTo(e,r),r.rShiftTo(1,r)):(e.subTo(r,e),e.rShiftTo(1,e));return n>0&&e.lShiftTo(n,e),e},r.prototype.isProbablePrime=function(t){var r,e=this.abs();if(1==e.t&&e[0]<=D[D.length-1]){for(r=0;r<D.length;++r)if(e[0]==D[r])return!0;return!1}if(e.isEven())return!1;for(r=1;r<D.length;){for(var i=D[r],o=r+1;o<D.length&&i<S;)i*=D[o++];for(i=e.modInt(i);r<o;)if(i%D[r++]==0)return!1}return e.millerRabin(t)},r.prototype.square=function(){var t=e();return this.squareTo(t),t},r.prototype.Barrett=B,null==x){var A;if(x=new Array,E=0,"undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var R=new Uint8Array(32);for(window.crypto.getRandomValues(R),A=0;A<32;++A)x[E++]=R[A]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var P=window.crypto.random(32);for(A=0;A<P.length;++A)x[E++]=255&P.charCodeAt(A)}for(;E<H;)A=Math.floor(65536*Math.random()),x[E++]=A>>>8,x[E++]=255&A;E=0,I()}function O(){if(null==q){for(I(),(q=new C).init(x),E=0;E<x.length;++E)x[E]=0;E=0}return q.next()}function M(){}function C(){this.i=0,this.j=0,this.S=new Array}M.prototype.nextBytes=function(t){var r;for(r=0;r<t.length;++r)t[r]=O()},C.prototype.init=function(t){var r,e,i;for(r=0;r<256;++r)this.S[r]=r;for(e=0,r=0;r<256;++r)e=e+this.S[r]+t[r%t.length]&255,i=this.S[r],this.S[r]=this.S[e],this.S[e]=i;this.i=0,this.j=0},C.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var H=256;i.exports={default:r,BigInteger:r,SecureRandom:M}}.call(o);var s=n.exports;const{BigInteger:h}=s;class u{constructor(){this.tlv=null,this.t="00",this.l="00",this.v=""}getEncodedHex(){return this.tlv||(this.v=this.getValue(),this.l=this.getLength(),this.tlv=this.t+this.l+this.v),this.tlv}getLength(){const t=this.v.length/2;let r=t.toString(16);if(r.length%2==1&&(r="0"+r),t<128)return r;return(128+r.length/2).toString(16)+r}getValue(){return""}}class a extends u{constructor(t){super(),this.t="02",t&&(this.v=function(t){let r=t.toString(16);if("-"!==r[0])r.length%2==1?r="0"+r:r.match(/^[0-7]/)||(r="00"+r);else{r=r.substr(1);let e=r.length;e%2==1?e+=1:r.match(/^[0-7]/)||(e+=2);let i="";for(let t=0;t<e;t++)i+="f";i=new h(i,16),r=i.xor(t).add(h.ONE),r=r.toString(16).replace(/^-/,"")}return r}(t))}getValue(){return this.v}}class f extends u{constructor(t){super(),this.t="30",this.asn1Array=t}getValue(){return this.v=this.asn1Array.map((t=>t.getEncodedHex())).join(""),this.v}}function c(t,r){return+t[r+2]<8?1:128&+t.substr(r+2,2)}function l(t,r){const e=c(t,r),i=t.substr(r+2,2*e);if(!i)return-1;return(+i[0]<8?new h(i,16):new h(i.substr(2),16)).intValue()}function p(t,r){return r+2*(c(t,r)+1)}var y={encodeDer(t,r){const e=new a(t),i=new a(r);return new f([e,i]).getEncodedHex()},decodeDer(t){const r=p(t,0),e=p(t,r),i=l(t,r),o=t.substr(e,2*i),n=e+o.length,s=p(t,n),u=l(t,n),a=t.substr(s,2*u);return{r:new h(o,16),s:new h(a,16)}}};const{BigInteger:m}=s,g=new m("2"),d=new m("3");class v{constructor(t,r){this.x=r,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 v(this.q,this.x.negate().mod(this.q))}add(t){return new v(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new v(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new v(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}divide(t){return new v(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}square(){return new v(this.q,this.x.square().mod(this.q))}}class w{constructor(t,r,e,i){this.curve=t,this.x=r,this.y=e,this.z=null==i?m.ONE:i,this.zinv=null}getX(){return null===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&&(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(m.ZERO))return!1;return t.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(t.z)).mod(this.curve.q).equals(m.ZERO)}isInfinity(){return null===this.x&&null===this.y||this.z.equals(m.ZERO)&&!this.y.toBigInteger().equals(m.ZERO)}negate(){return new w(this.curve,this.x,this.y.negate(),this.z)}add(t){if(this.isInfinity())return t;if(t.isInfinity())return this;const r=this.x.toBigInteger(),e=this.y.toBigInteger(),i=this.z,o=t.x.toBigInteger(),n=t.y.toBigInteger(),s=t.z,h=this.curve.q,u=r.multiply(s).mod(h),a=o.multiply(i).mod(h),f=u.subtract(a),c=e.multiply(s).mod(h),l=n.multiply(i).mod(h),p=c.subtract(l);if(m.ZERO.equals(f))return m.ZERO.equals(p)?this.twice():this.curve.infinity;const y=u.add(a),g=i.multiply(s).mod(h),d=f.square().mod(h),v=f.multiply(d).mod(h),T=g.multiply(p.square()).subtract(y.multiply(d)).mod(h),F=f.multiply(T).mod(h),b=p.multiply(d.multiply(u).subtract(T)).subtract(c.multiply(v)).mod(h),B=v.multiply(g).mod(h);return new w(this.curve,this.curve.fromBigInteger(F),this.curve.fromBigInteger(b),B)}twice(){if(this.isInfinity())return this;if(!this.y.toBigInteger().signum())return this.curve.infinity;const t=this.x.toBigInteger(),r=this.y.toBigInteger(),e=this.z,i=this.curve.q,o=this.curve.a.toBigInteger(),n=t.square().multiply(d).add(o.multiply(e.square())).mod(i),s=r.shiftLeft(1).multiply(e).mod(i),h=r.square().mod(i),u=h.multiply(t).multiply(e).mod(i),a=s.square().mod(i),f=n.square().subtract(u.shiftLeft(3)).mod(i),c=s.multiply(f).mod(i),l=n.multiply(u.shiftLeft(2).subtract(f)).subtract(a.shiftLeft(1).multiply(h)).mod(i),p=s.multiply(a).mod(i);return new w(this.curve,this.curve.fromBigInteger(c),this.curve.fromBigInteger(l),p)}multiply(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;const r=t.multiply(d),e=this.negate();let i=this;for(let o=r.bitLength()-2;o>0;o--){i=i.twice();const n=r.testBit(o);n!==t.testBit(o)&&(i=i.add(n?this:e))}return i}}var T={ECPointFp:w,ECCurveFp:class{constructor(t,r,e){this.q=t,this.a=this.fromBigInteger(r),this.b=this.fromBigInteger(e),this.infinity=new w(this,null,null)}equals(t){return t===this||this.q.equals(t.q)&&this.a.equals(t.a)&&this.b.equals(t.b)}fromBigInteger(t){return new v(this.q,t)}decodePointHex(t){switch(parseInt(t.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:const r=this.fromBigInteger(new m(t.substr(2),16));let e=this.fromBigInteger(r.multiply(r.square()).add(r.multiply(this.a)).add(this.b).toBigInteger().modPow(this.q.divide(new m("4")).add(m.ONE),this.q));return e.toBigInteger().mod(g).equals(new m(t.substr(0,2),16).subtract(g))||(e=e.negate()),new w(this,r,e);case 4:case 6:case 7:const i=(t.length-2)/2,o=t.substr(2,i),n=t.substr(i+2,i);return new w(this,this.fromBigInteger(new m(o,16)),this.fromBigInteger(new m(n,16)));default:return null}}}};const{BigInteger:F,SecureRandom:b}=s,{ECCurveFp:B}=T,q=new b,{curve:x,G:E,n:D}=S();function S(){const t=new F("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),r=new F("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),e=new F("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),i=new B(t,r,e),o=i.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");return{curve:i,G:o,n:new F("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function I(t,r){return t.length>=r?t:new Array(r-t.length+1).join("0")+t}var A={getGlobalCurve:function(){return x},generateEcparam:S,generateKeyPairHex:function(t,r,e){const i=(t?new F(t,r,e):new F(D.bitLength(),q)).mod(D.subtract(F.ONE)).add(F.ONE),o=I(i.toString(16),64),n=E.multiply(i);return{privateKey:o,publicKey:"04"+I(n.getX().toBigInteger().toString(16),64)+I(n.getY().toBigInteger().toString(16),64)}},compressPublicKeyHex:function(t){if(130!==t.length)throw new Error("Invalid public key to compress");const r=(t.length-2)/2,e=t.substr(2,r);let i="03";return new F(t.substr(r+2,r),16).mod(new F("2")).equals(F.ZERO)&&(i="02"),i+e},utf8ToHex:function(t){const r=(t=unescape(encodeURIComponent(t))).length,e=[];for(let i=0;i<r;i++)e[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;const i=[];for(let t=0;t<r;t++){const r=e[t>>>2]>>>24-t%4*8&255;i.push((r>>>4).toString(16)),i.push((15&r).toString(16))}return i.join("")},leftPad:I,arrayToHex:function(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")},arrayToUtf8:function(t){const r=[];let e=0;for(let i=0;i<2*t.length;i+=2)r[i>>>3]|=parseInt(t[e],10)<<24-i%8*4,e++;try{const e=[];for(let i=0;i<t.length;i++){const t=r[i>>>2]>>>24-i%4*8&255;e.push(String.fromCharCode(t))}return decodeURIComponent(escape(e.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}},hexToArray:function(t){const r=[];let e=t.length;e%2!=0&&(t=I(t,e+1)),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r},verifyPublicKey:function(t){const r=x.decodePointHex(t);if(!r)return!1;const e=r.getX();return r.getY().square().equals(e.multiply(e.square()).add(e.multiply(x.a)).add(x.b))},comparePublicKeyHex:function(t,r){const e=x.decodePointHex(t);if(!e)return!1;const i=x.decodePointHex(r);return!!i&&e.equals(i)}};const R=new Uint32Array(68),P=new Uint32Array(64);function O(t,r){const e=31&r;return t<<e|t>>>32-e}function M(t,r){const e=[];for(let i=t.length-1;i>=0;i--)e[i]=255&(t[i]^r[i]);return e}function C(t){return t^O(t,9)^O(t,17)}function H(t){let r=8*t.length,e=r%512;e=e>=448?512-e%448-1:448-e-1;const i=new Array((e-7)/8),o=new Array(8);for(let t=0,r=i.length;t<r;t++)i[t]=0;for(let t=0,r=o.length;t<r;t++)o[t]=0;r=r.toString(2);for(let t=7;t>=0;t--)if(r.length>8){const e=r.length-8;o[t]=parseInt(r.substr(e),2),r=r.substr(0,e)}else r.length>0&&(o[t]=parseInt(r,2),r="");const n=new Uint8Array([...t,128,...i,...o]),s=new DataView(n.buffer,0),h=n.length/64,u=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]);for(let t=0;t<h;t++){R.fill(0),P.fill(0);const r=16*t;for(let t=0;t<16;t++)R[t]=s.getUint32(4*(r+t),!1);for(let t=16;t<68;t++)R[t]=(a=R[t-16]^R[t-9]^O(R[t-3],15))^O(a,15)^O(a,23)^O(R[t-13],7)^R[t-6];for(let t=0;t<64;t++)P[t]=R[t]^R[t+4];const e=2043430169,i=2055708042;let o,n,h,f,c,l=u[0],p=u[1],y=u[2],m=u[3],g=u[4],d=u[5],v=u[6],w=u[7];for(let t=0;t<64;t++)c=t>=0&&t<=15?e:i,o=O(O(l,12)+g+O(c,t),7),n=o^O(l,12),h=(t>=0&&t<=15?l^p^y:l&p|l&y|p&y)+m+n+P[t],f=(t>=0&&t<=15?g^d^v:g&d|~g&v)+w+o+R[t],m=y,y=O(p,9),p=l,l=h,w=v,v=O(d,19),d=g,g=C(f);u[0]^=l,u[1]^=p,u[2]^=y,u[3]^=m,u[4]^=g,u[5]^=d,u[6]^=v,u[7]^=w}var a;const f=[];for(let t=0,r=u.length;t<r;t++){const r=u[t];f.push((4278190080&r)>>>24,(16711680&r)>>>16,(65280&r)>>>8,255&r)}return f}const V=new Uint8Array(64),N=new Uint8Array(64);for(let t=0;t<64;t++)V[t]=54,N[t]=92;var K={sm3:H,hmac:function(t,r){for(r.length>64&&(r=H(r));r.length<64;)r.push(0);const e=M(r,V),i=M(r,N),o=H([...e,...t]);return H([...i,...o])}};const{BigInteger:L}=s,{encodeDer:z,decodeDer:k}=y,Z=A,j=K.sm3,{G:U,curve:$,n:X}=Z.generateEcparam();function Y(t,r,e="1234567812345678"){e=Z.utf8ToHex(e);const i=Z.leftPad(U.curve.a.toBigInteger().toRadix(16),64),o=Z.leftPad(U.curve.b.toBigInteger().toRadix(16),64),n=Z.leftPad(U.getX().toBigInteger().toRadix(16),64),s=Z.leftPad(U.getY().toBigInteger().toRadix(16),64);let h,u;if(128===r.length)h=r.substr(0,64),u=r.substr(64,64);else{const t=U.curve.decodePointHex(r);h=Z.leftPad(t.getX().toBigInteger().toRadix(16),64),u=Z.leftPad(t.getY().toBigInteger().toRadix(16),64)}const a=Z.hexToArray(e+i+o+n+s+h+u),f=4*e.length;a.unshift(255&f),a.unshift(f>>8&255);const c=j(a);return Z.arrayToHex(j(c.concat(Z.hexToArray(t))))}function G(t){const r=U.multiply(new L(t,16));return"04"+Z.leftPad(r.getX().toBigInteger().toString(16),64)+Z.leftPad(r.getY().toBigInteger().toString(16),64)}function J(){const t=Z.generateKeyPairHex(),r=$.decodePointHex(t.publicKey);return t.k=new L(t.privateKey,16),t.x1=r.getX().toBigInteger(),t}var W={generateKeyPairHex:Z.generateKeyPairHex,compressPublicKeyHex:Z.compressPublicKeyHex,comparePublicKeyHex:Z.comparePublicKeyHex,doEncrypt:function(t,r,e=1){t="string"==typeof t?Z.hexToArray(Z.utf8ToHex(t)):Array.prototype.slice.call(t),r=Z.getGlobalCurve().decodePointHex(r);const i=Z.generateKeyPairHex(),o=new L(i.privateKey,16);let n=i.publicKey;n.length>128&&(n=n.substr(n.length-128));const s=r.multiply(o),h=Z.hexToArray(Z.leftPad(s.getX().toBigInteger().toRadix(16),64)),u=Z.hexToArray(Z.leftPad(s.getY().toBigInteger().toRadix(16),64)),a=Z.arrayToHex(j([].concat(h,t,u)));let f=1,c=0,l=[];const p=[].concat(h,u),y=()=>{l=j([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let r=0,e=t.length;r<e;r++)c===l.length&&y(),t[r]^=255&l[c++];const m=Z.arrayToHex(t);return 0===e?n+m+a:n+a+m},doDecrypt:function(t,r,e=1,{output:i="string"}={}){r=new L(r,16);let o=t.substr(128,64),n=t.substr(192);0===e&&(o=t.substr(t.length-64),n=t.substr(128,t.length-128-64));const s=Z.hexToArray(n),h=Z.getGlobalCurve().decodePointHex("04"+t.substr(0,128)).multiply(r),u=Z.hexToArray(Z.leftPad(h.getX().toBigInteger().toRadix(16),64)),a=Z.hexToArray(Z.leftPad(h.getY().toBigInteger().toRadix(16),64));let f=1,c=0,l=[];const p=[].concat(u,a),y=()=>{l=j([...p,f>>24&255,f>>16&255,f>>8&255,255&f]),f++,c=0};y();for(let t=0,r=s.length;t<r;t++)c===l.length&&y(),s[t]^=255&l[c++];return Z.arrayToHex(j([].concat(u,s,a)))===o.toLowerCase()?"array"===i?s:Z.arrayToUtf8(s):"array"===i?[]:""},doSignature:function(t,r,{pointPool:e,der:i,hash:o,publicKey:n,userId:s}={}){let h="string"==typeof t?Z.utf8ToHex(t):Z.arrayToHex(t);o&&(h=Y(h,n=n||G(r),s));const u=new L(r,16),a=new L(h,16);let f=null,c=null,l=null;do{do{let t;t=e&&e.length?e.pop():J(),f=t.k,c=a.add(t.x1).mod(X)}while(c.equals(L.ZERO)||c.add(f).equals(X));l=u.add(L.ONE).modInverse(X).multiply(f.subtract(c.multiply(u))).mod(X)}while(l.equals(L.ZERO));return i?z(c,l):Z.leftPad(c.toString(16),64)+Z.leftPad(l.toString(16),64)},doVerifySignature:function(t,r,e,{der:i,hash:o,userId:n}={}){let s,h,u="string"==typeof t?Z.utf8ToHex(t):Z.arrayToHex(t);if(o&&(u=Y(u,e,n)),i){const t=k(r);s=t.r,h=t.s}else s=new L(r.substring(0,64),16),h=new L(r.substring(64),16);const a=$.decodePointHex(e),f=new L(u,16),c=s.add(h).mod(X);if(c.equals(L.ZERO))return!1;const l=U.multiply(h).add(a.multiply(c)),p=f.add(l.getX().toBigInteger()).mod(X);return s.equals(p)},getPublicKeyFromPrivateKey:G,getPoint:J,verifyPublicKey:Z.verifyPublicKey};const{sm3:Q,hmac:_}=K;function tt(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")}function rt(t){const r=[];let e=t.length;var i,o;e%2!=0&&(o=e+1,t=(i=t).length>=o?i:new Array(o-i.length+1).join("0")+i),e=t.length;for(let i=0;i<e;i+=2)r.push(parseInt(t.substr(i,2),16));return r}const et=0,it=16,ot=[214,144,233,254,204,225,61,183,22,182,20,194,40,251,44,5,43,103,154,118,42,190,4,195,170,68,19,38,73,134,6,153,156,66,80,244,145,239,152,122,51,84,11,67,237,207,172,98,228,179,28,169,201,8,232,149,128,223,148,250,117,143,63,166,71,7,167,252,243,115,23,186,131,89,60,25,230,133,79,168,104,107,129,178,113,100,218,139,248,235,15,75,112,86,157,53,30,36,14,94,99,88,209,162,37,34,124,59,1,33,120,135,212,0,70,87,159,211,39,82,76,54,2,231,160,196,200,158,234,191,138,210,64,199,56,181,163,247,242,206,249,97,21,161,224,174,93,164,155,52,26,85,173,147,50,48,245,140,177,227,29,246,226,46,130,102,202,96,192,41,35,171,13,83,78,111,213,219,55,69,222,253,142,47,3,255,106,114,109,108,91,81,141,27,175,146,187,221,188,127,17,217,92,65,31,16,90,216,10,193,49,136,165,205,123,189,45,116,208,18,184,229,180,176,137,105,151,74,12,150,119,126,101,185,241,9,197,110,198,132,24,240,125,236,58,220,77,32,121,238,95,62,215,203,57,72],nt=[462357,472066609,943670861,1415275113,1886879365,2358483617,2830087869,3301692121,3773296373,4228057617,404694573,876298825,1347903077,1819507329,2291111581,2762715833,3234320085,3705924337,4177462797,337322537,808926789,1280531041,1752135293,2223739545,2695343797,3166948049,3638552301,4110090761,269950501,741554753,1213159005,1684763257];function st(t){const r=[];for(let e=0,i=t.length;e<i;e+=2)r.push(parseInt(t.substr(e,2),16));return r}function ht(t,r){const e=31&r;return t<<e|t>>>32-e}function ut(t){return(255&ot[t>>>24&255])<<24|(255&ot[t>>>16&255])<<16|(255&ot[t>>>8&255])<<8|255&ot[255&t]}function at(t){return t^ht(t,2)^ht(t,10)^ht(t,18)^ht(t,24)}function ft(t){return t^ht(t,13)^ht(t,23)}function ct(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[4*r],o[1]=255&t[4*r+1],o[2]=255&t[4*r+2],o[3]=255&t[4*r+3],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];for(let t,r=0;r<32;r+=4)t=i[1]^i[2]^i[3]^e[r+0],i[0]^=at(ut(t)),t=i[2]^i[3]^i[0]^e[r+1],i[1]^=at(ut(t)),t=i[3]^i[0]^i[1]^e[r+2],i[2]^=at(ut(t)),t=i[0]^i[1]^i[2]^e[r+3],i[3]^=at(ut(t));for(let t=0;t<16;t+=4)r[t]=i[3-t/4]>>>24&255,r[t+1]=i[3-t/4]>>>16&255,r[t+2]=i[3-t/4]>>>8&255,r[t+3]=255&i[3-t/4]}function lt(t,r,e,{padding:i="pkcs#7",mode:o,iv:n=[],output:s="string"}={}){if("cbc"===o&&("string"==typeof n&&(n=st(n)),16!==n.length))throw new Error("iv is invalid");if("string"==typeof r&&(r=st(r)),16!==r.length)throw new Error("key is invalid");if(t="string"==typeof t?e!==et?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):st(t):[...t],("pkcs#5"===i||"pkcs#7"===i)&&e!==et){const r=it-t.length%it;for(let e=0;e<r;e++)t.push(r)}const h=new Array(32);!function(t,r,e){const i=new Array(4),o=new Array(4);for(let r=0;r<4;r++)o[0]=255&t[0+4*r],o[1]=255&t[1+4*r],o[2]=255&t[2+4*r],o[3]=255&t[3+4*r],i[r]=o[0]<<24|o[1]<<16|o[2]<<8|o[3];i[0]^=2746333894,i[1]^=1453994832,i[2]^=1736282519,i[3]^=2993693404;for(let t,e=0;e<32;e+=4)t=i[1]^i[2]^i[3]^nt[e+0],r[e+0]=i[0]^=ft(ut(t)),t=i[2]^i[3]^i[0]^nt[e+1],r[e+1]=i[1]^=ft(ut(t)),t=i[3]^i[0]^i[1]^nt[e+2],r[e+2]=i[2]^=ft(ut(t)),t=i[0]^i[1]^i[2]^nt[e+3],r[e+3]=i[3]^=ft(ut(t));if(e===et)for(let t,e=0;e<16;e++)t=r[e],r[e]=r[31-e],r[31-e]=t}(r,h,e);const u=[];let a=n,f=t.length,c=0;for(;f>=it;){const r=t.slice(c,c+16),i=new Array(16);if("cbc"===o)for(let t=0;t<it;t++)e!==et&&(r[t]^=a[t]);ct(r,i,h);for(let t=0;t<it;t++)"cbc"===o&&e===et&&(i[t]^=a[t]),u[c+t]=i[t];"cbc"===o&&(a=e!==et?i:r),f-=it,c+=it}if(("pkcs#5"===i||"pkcs#7"===i)&&e===et){const t=u.length,r=u[t-1];for(let e=1;e<=r;e++)if(u[t-e]!==r)throw new Error("padding is invalid");u.splice(t-r,r)}return"array"!==s?e!==et?u.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join(""):function(t){const r=[];for(let e=0,i=t.length;e<i;e++)t[e]>=240&&t[e]<=247?(r.push(String.fromCodePoint(((7&t[e])<<18)+((63&t[e+1])<<12)+((63&t[e+2])<<6)+(63&t[e+3]))),e+=3):t[e]>=224&&t[e]<=239?(r.push(String.fromCodePoint(((15&t[e])<<12)+((63&t[e+1])<<6)+(63&t[e+2]))),e+=2):t[e]>=192&&t[e]<=223?(r.push(String.fromCodePoint(((31&t[e])<<6)+(63&t[e+1]))),e++):r.push(String.fromCodePoint(t[e]));return r.join("")}(u):u}var pt={sm2:W,sm3:function(t,r){if(t="string"==typeof t?function(t){const r=[];for(let e=0,i=t.length;e<i;e++){const i=t.codePointAt(e);if(i<=127)r.push(i);else if(i<=2047)r.push(192|i>>>6),r.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)r.push(224|i>>>12),r.push(128|i>>>6&63),r.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw r.push(i),new Error("input is not supported");e++,r.push(240|i>>>18&28),r.push(128|i>>>12&63),r.push(128|i>>>6&63),r.push(128|63&i)}}return r}(t):Array.prototype.slice.call(t),r){if("hmac"!==(r.mode||"hmac"))throw new Error("invalid mode");let e=r.key;if(!e)throw new Error("invalid key");return e="string"==typeof e?rt(e):Array.prototype.slice.call(e),tt(_(t,e))}return tt(Q(t))},sm4:{encrypt:(t,r,e)=>lt(t,r,1,e),decrypt:(t,r,e)=>lt(t,r,0,e)}};const yt=(t=16,r="high")=>{const e=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],i=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],o=[0,1,2,3,4,5,6,7,8,9],n=["!","@","-","_","=","<",">","#","*","%","+","&","^","$"],s=[];let h="";const u=function(...t){let r="";return t.forEach((t=>{r+=t[Math.floor(Math.random()*t.length)]})),r};switch(r){case"high":h+=u(e,i,o,n),s.push(...e,...i,...o,...n);break;case"medium":h+=u(e,i,o),s.push(...e,...i,...o);break;default:h+=u(e,o),s.push(...e,...o)}const a=t-h.length;for(let t=0;t<a;t++)h+=u(s);return h};function mt(t,r="utf-8"){return new TextDecoder(r).decode(t)}function gt(t){try{return t instanceof ArrayBuffer?dt(mt(t)):t}catch(t){throw console.error("error",t),t}}function dt(t){try{return"string"==typeof t?JSON.parse(t):t}catch(t){throw console.error("error",t),t}}const vt=t=>{let r=!0;return!(t=>/^\/bi-api\/api/.test(t))(t)&&(t.startsWith("/api")&&(r=!1,(t=>/^\/(api\/logmanage|api\/data-source|api\/enterpriseadmin|api\/componentmanager|api\/spacemanager|api\/filemanager)/.test(t))(t)&&(r=!0)),r)},wt=t=>({...{key:yt(16,"high"),algorithm:t||"SM4"}}),Tt=()=>({mode:"ecb",padding:"pkcs#7",output:"array"}),Ft=r.Buffer,bt={mode:"ecb",padding:"pkcs#7",output:"array"};function Bt(t,r){if(!r||"string"!=typeof r)throw new Error(`publicKey is required and must be a string ${r}`);t.interceptors.request.use((t=>{const r=t.url,e=t.headers;if(!r)throw new Error("url is required");if({}.hasOwnProperty.call(e,"closeCrypto"))return t;const i=vt(r);return console.log(`url: ${r} shouldCloseCrypto: ${i}`),i||(e.closeCrypto=!0),t})),t.interceptors.request.use((t=>{const r=t.data,e=t.headers;return r instanceof FormData&&(console.log(`body of request: ${t.url} is FormData: ${r}`),e.closeCrypto=!0),t})),t.interceptors.request.use((t=>(t.headers.closeCrypto||(t.responseType="arraybuffer"),t))),t.interceptors.request.use((t=>{const e=t.transformRequest,i={info:null,publicKey:[]};if(!e)throw new Error(`request ${t} has no transformRequest`);if(!Array.isArray(e))throw new Error(`transformRequest ${e} is not an array`);e.push(function(t,r){return(e,i)=>{try{if(i.closeCrypto)return e;if(t.info=wt(),t.publicKey=[...Ft.from(t.info.key)],((t,r)=>{t.set("X-Encrypt-Key",r)})(i,pt.sm2.doEncrypt(JSON.stringify(t.info),r,1)),e){"string"!=typeof e&&(e=JSON.stringify(e));const r=pt.sm4.encrypt(e,t.publicKey,bt);return Ft.from(r)}return e}catch(t){console.error("encrypt error",t,e,i)}}}(i,r));const o=function(t){return(r,e)=>{try{if((t=>{const r=t.get("X-Encrypt-With");return r&&"string"==typeof r&&"sm4"===r.toLowerCase()})(e)){const e=Ft.from(r);return dt(pt.sm4.decrypt(e,t.publicKey,{mode:"ecb",padding:"pkcs#7"}))}return gt(r)}catch(t){console.error("decrypt error",t,r,e)}}}(i);if(!o)return t;const n=t.transformResponse;if(!n)throw new Error(`request ${t} has no transformResponse`);if("function"!=typeof o)throw new Error(`decryptFn ${o} is not a function`);if(!Array.isArray(n))throw new Error(`transformResponse ${n} is not an array`);return n.unshift(o),t})),t.interceptors.response.use((t=>(t.data=gt(t.data),t.data=dt(t.data),t)),(t=>{const r=t.response;throw r?.data&&(r.data=function(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(t){throw console.error("error",t),t}return t instanceof ArrayBuffer?mt(t):t}(r.data)),t}))}const qt=(r,e)=>{const i=t.create(r);return Bt(i,e),i};export{qt as createCryptoAxiosInstance,e as createRequestInstance,wt as getCryptoInfo,Tt as getSm4EncryptConfig,yt as randomPassword,vt as shouldEncrypt};
{
"name": "request-crypto",
"description": "axios with crypto callback",
"version": "1.4.3",
"version": "1.4.4",
"main": "index.cjs.js",

@@ -6,0 +6,0 @@ "module": "index.esm.js",

{
"name": "request-crypto",
"version": "1.4.3",
"version": "1.4.4",
"description": "axios with crypto callback",

@@ -18,3 +18,2 @@ "main": "dist/index.cjs.js",

"package.json",
"packages/*",
"dist/*"

@@ -21,0 +20,0 @@ ],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc