@sparta-utils/cache-util
Version:
统一的浏览器缓存工具类,支持 localStorage、sessionStorage、memory、cookie、indexedDB,内置 SM2 加密与过期机制。A unified browser caching utility supporting localStorage, sessionStorage, memory, cookie, indexedDB with SM2 encryption and expiration.
3 lines (2 loc) • 43.5 kB
JavaScript
function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e,r,i,n,o,s,u,h,a,c,l,f,p,m,y,d,g,v={exports:{}},w=v.exports;function T(){return e||(e=1,t=v,function(){var e;function r(t,e,r){null!=t&&("number"==typeof t?this.fromNumber(t,e,r):null==e&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,e))}function i(){return new r(null)}var n="undefined"!=typeof navigator;n&&"Microsoft Internet Explorer"==navigator.appName?(r.prototype.am=function(t,e,r,i,n,o){for(var s=32767&e,u=e>>15;--o>=0;){var h=32767&this[t],a=this[t++]>>15,c=u*h+a*s;n=((h=s*h+((32767&c)<<15)+r[i]+(1073741823&n))>>>30)+(c>>>15)+u*a+(n>>>30),r[i++]=1073741823&h}return n},e=30):n&&"Netscape"!=navigator.appName?(r.prototype.am=function(t,e,r,i,n,o){for(;--o>=0;){var s=e*this[t++]+r[i]+n;n=Math.floor(s/67108864),r[i++]=67108863&s}return n},e=26):(r.prototype.am=function(t,e,r,i,n,o){for(var s=16383&e,u=e>>14;--o>=0;){var h=16383&this[t],a=this[t++]>>14,c=u*h+a*s;n=((h=s*h+((16383&c)<<14)+r[i]+n)>>28)+(c>>14)+u*a,r[i++]=268435455&h}return n},e=28),r.prototype.DB=e,r.prototype.DM=(1<<e)-1,r.prototype.DV=1<<e,r.prototype.FV=Math.pow(2,52),r.prototype.F1=52-e,r.prototype.F2=2*e-52;var o,s,u=new Array;for(o="0".charCodeAt(0),s=0;s<=9;++s)u[o++]=s;for(o="a".charCodeAt(0),s=10;s<36;++s)u[o++]=s;for(o="A".charCodeAt(0),s=10;s<36;++s)u[o++]=s;function h(t){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t)}function a(t,e){var r=u[t.charCodeAt(e)];return null==r?-1:r}function c(t){var e=i();return e.fromInt(t),e}function l(t){var e,r=1;return 0!=(e=t>>>16)&&(t=e,r+=16),0!=(e=t>>8)&&(t=e,r+=8),0!=(e=t>>4)&&(t=e,r+=4),0!=(e=t>>2)&&(t=e,r+=2),0!=(e=t>>1)&&(t=e,r+=1),r}function f(t){this.m=t}function p(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,e){return t&e}function y(t,e){return t|e}function d(t,e){return t^e}function g(t,e){return t&~e}function v(t){if(0==t)return-1;var e=0;return 65535&t||(t>>=16,e+=16),255&t||(t>>=8,e+=8),15&t||(t>>=4,e+=4),3&t||(t>>=2,e+=2),1&t||++e,e}function w(t){for(var e=0;0!=t;)t&=t-1,++e;return e}function T(){}function F(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}f.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},f.prototype.revert=function(t){return t},f.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},f.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},f.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},p.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},p.prototype.revert=function(t){var e=i();return t.copyTo(e),this.reduce(e),e},p.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var e=0;e<this.m.t;++e){var r=32767&t[e],i=r*this.mpl+((r*this.mph+(t[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[r=e+this.m.t]+=this.m.am(0,i,t,e,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},p.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r),this.reduce(r)},p.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)},r.prototype.copyTo=function(t){for(var e=this.t-1;e>=0;--e)t[e]=this[e];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 n=t.length,o=!1,s=0;--n>=0;){var u=8==i?255&t[n]:a(t,n);u<0?"-"==t.charAt(n)&&(o=!0):(o=!1,0==s?this[this.t++]=u:s+i>this.DB?(this[this.t-1]|=(u&(1<<this.DB-s)-1)<<s,this[this.t++]=u>>this.DB-s):this[this.t-1]|=u<<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(),o&&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,e){var r;for(r=this.t-1;r>=0;--r)e[r+t]=this[r];for(r=t-1;r>=0;--r)e[r]=0;e.t=this.t+t,e.s=this.s},r.prototype.drShiftTo=function(t,e){for(var r=t;r<this.t;++r)e[r-t]=this[r];e.t=Math.max(this.t-t,0),e.s=this.s},r.prototype.lShiftTo=function(t,e){var r,i=t%this.DB,n=this.DB-i,o=(1<<n)-1,s=Math.floor(t/this.DB),u=this.s<<i&this.DM;for(r=this.t-1;r>=0;--r)e[r+s+1]=this[r]>>n|u,u=(this[r]&o)<<i;for(r=s-1;r>=0;--r)e[r]=0;e[s]=u,e.t=this.t+s+1,e.s=this.s,e.clamp()},r.prototype.rShiftTo=function(t,e){e.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)e.t=0;else{var i=t%this.DB,n=this.DB-i,o=(1<<i)-1;e[0]=this[r]>>i;for(var s=r+1;s<this.t;++s)e[s-r-1]|=(this[s]&o)<<n,e[s-r]=this[s]>>i;i>0&&(e[this.t-r-1]|=(this.s&o)<<n),e.t=this.t-r,e.clamp()}},r.prototype.subTo=function(t,e){for(var r=0,i=0,n=Math.min(t.t,this.t);r<n;)i+=this[r]-t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i-=t.s;r<this.t;)i+=this[r],e[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<t.t;)i-=t[r],e[r++]=i&this.DM,i>>=this.DB;i-=t.s}e.s=i<0?-1:0,i<-1?e[r++]=this.DV+i:i>0&&(e[r++]=i),e.t=r,e.clamp()},r.prototype.multiplyTo=function(t,e){var i=this.abs(),n=t.abs(),o=i.t;for(e.t=o+n.t;--o>=0;)e[o]=0;for(o=0;o<n.t;++o)e[o+i.t]=i.am(0,n[o],e,o,0,i.t);e.s=0,e.clamp(),this.s!=t.s&&r.ZERO.subTo(e,e)},r.prototype.squareTo=function(t){for(var e=this.abs(),r=t.t=2*e.t;--r>=0;)t[r]=0;for(r=0;r<e.t-1;++r){var i=e.am(r,e[r],t,2*r,0,1);(t[r+e.t]+=e.am(r+1,2*e[r],t,2*r+1,i,e.t-r-1))>=e.DV&&(t[r+e.t]-=e.DV,t[r+e.t+1]=1)}t.t>0&&(t[t.t-1]+=e.am(r,e[r],t,2*r,0,1)),t.s=0,t.clamp()},r.prototype.divRemTo=function(t,e,n){var o=t.abs();if(!(o.t<=0)){var s=this.abs();if(s.t<o.t)return null!=e&&e.fromInt(0),void(null!=n&&this.copyTo(n));null==n&&(n=i());var u=i(),h=this.s,a=t.s,c=this.DB-l(o[o.t-1]);c>0?(o.lShiftTo(c,u),s.lShiftTo(c,n)):(o.copyTo(u),s.copyTo(n));var f=u.t,p=u[f-1];if(0!=p){var m=p*(1<<this.F1)+(f>1?u[f-2]>>this.F2:0),y=this.FV/m,d=(1<<this.F1)/m,g=1<<this.F2,v=n.t,w=v-f,T=null==e?i():e;for(u.dlShiftTo(w,T),n.compareTo(T)>=0&&(n[n.t++]=1,n.subTo(T,n)),r.ONE.dlShiftTo(f,T),T.subTo(u,u);u.t<f;)u[u.t++]=0;for(;--w>=0;){var F=n[--v]==p?this.DM:Math.floor(n[v]*y+(n[v-1]+g)*d);if((n[v]+=u.am(0,F,n,w,0,f))<F)for(u.dlShiftTo(w,T),n.subTo(T,n);n[v]<--F;)n.subTo(T,n)}null!=e&&(n.drShiftTo(f,e),h!=a&&r.ZERO.subTo(e,e)),n.t=f,n.clamp(),c>0&&n.rShiftTo(c,n),h<0&&r.ZERO.subTo(n,n)}}},r.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(!(1&t))return 0;var e=3&t;return(e=(e=(e=(e=e*(2-(15&t)*e)&15)*(2-(255&t)*e)&255)*(2-((65535&t)*e&65535))&65535)*(2-t*e%this.DV)%this.DV)>0?this.DV-e:-e},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 n=i(),o=i(),s=e.convert(this),u=l(t)-1;for(s.copyTo(n);--u>=0;)if(e.sqrTo(n,o),(t&1<<u)>0)e.mulTo(o,s,n);else{var h=n;n=o,o=h}return e.revert(n)},r.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(16==t)e=4;else if(8==t)e=3;else if(2==t)e=1;else if(32==t)e=5;else{if(4!=t)return this.toRadix(t);e=2}var r,i=(1<<e)-1,n=!1,o="",s=this.t,u=this.DB-s*this.DB%e;if(s-- >0)for(u<this.DB&&(r=this[s]>>u)>0&&(n=!0,o=h(r));s>=0;)u<e?(r=(this[s]&(1<<u)-1)<<e-u,r|=this[--s]>>(u+=this.DB-e)):(r=this[s]>>(u-=e)&i,u<=0&&(u+=this.DB,--s)),r>0&&(n=!0),n&&(o+=h(r));return n?o:"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 e=this.s-t.s;if(0!=e)return e;var r=this.t;if(0!=(e=r-t.t))return this.s<0?-e:e;for(;--r>=0;)if(0!=(e=this[r]-t[r]))return e;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,e){var r;return r=t<256||e.isEven()?new f(e):new p(e),this.exp(t,r)},r.ZERO=c(0),r.ONE=c(1),T.prototype.convert=F,T.prototype.revert=F,T.prototype.mulTo=function(t,e,r){t.multiplyTo(e,r)},T.prototype.sqrTo=function(t,e){t.squareTo(e)},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 e=i();return t.copyTo(e),this.reduce(e),e},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,e,r){t.multiplyTo(e,r),this.reduce(r)},b.prototype.sqrTo=function(t,e){t.squareTo(e),this.reduce(e)};var B,x,S,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 E(){var t;t=(new Date).getTime(),x[S++]^=255&t,x[S++]^=t>>8&255,x[S++]^=t>>16&255,x[S++]^=t>>24&255,S>=M&&(S-=M)}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 e=this.chunkSize(t),r=Math.pow(t,e),n=c(r),o=i(),s=i(),u="";for(this.divRemTo(n,o,s);o.signum()>0;)u=(r+s.intValue()).toString(t).substr(1)+u,o.divRemTo(n,o,s);return s.intValue().toString(t)+u},r.prototype.fromRadix=function(t,e){this.fromInt(0),null==e&&(e=10);for(var i=this.chunkSize(e),n=Math.pow(e,i),o=!1,s=0,u=0,h=0;h<t.length;++h){var c=a(t,h);c<0?"-"==t.charAt(h)&&0==this.signum()&&(o=!0):(u=e*u+c,++s>=i&&(this.dMultiply(n),this.dAddOffset(u,0),s=0,u=0))}s>0&&(this.dMultiply(Math.pow(e,s)),this.dAddOffset(u,0)),o&&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),y,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 n=new Array,o=7&t;n.length=1+(t>>3),e.nextBytes(n),o>0?n[0]&=(1<<o)-1:n[0]=0,this.fromString(n,256)}},r.prototype.bitwiseTo=function(t,e,r){var i,n,o=Math.min(t.t,this.t);for(i=0;i<o;++i)r[i]=e(this[i],t[i]);if(t.t<this.t){for(n=t.s&this.DM,i=o;i<this.t;++i)r[i]=e(this[i],n);r.t=this.t}else{for(n=this.s&this.DM,i=o;i<t.t;++i)r[i]=e(n,t[i]);r.t=t.t}r.s=e(this.s,t.s),r.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,e){for(var r=0,i=0,n=Math.min(t.t,this.t);r<n;)i+=this[r]+t[r],e[r++]=i&this.DM,i>>=this.DB;if(t.t<this.t){for(i+=t.s;r<this.t;)i+=this[r],e[r++]=i&this.DM,i>>=this.DB;i+=this.s}else{for(i+=this.s;r<t.t;)i+=t[r],e[r++]=i&this.DM,i>>=this.DB;i+=t.s}e.s=i<0?-1:0,i>0?e[r++]=i:i<-1&&(e[r++]=this.DV+i),e.t=r,e.clamp()},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,e){if(0!=t){for(;this.t<=e;)this[this.t++]=0;for(this[e]+=t;this[e]>=this.DV;)this[e]-=this.DV,++e>=this.t&&(this[this.t++]=0),++this[e]}},r.prototype.multiplyLowerTo=function(t,e,r){var i,n=Math.min(this.t+t.t,e);for(r.s=0,r.t=n;n>0;)r[--n]=0;for(i=r.t-this.t;n<i;++n)r[n+this.t]=this.am(0,t[n],r,n,0,this.t);for(i=Math.min(t.t,e);n<i;++n)this.am(0,t[n],r,n,0,e-n);r.clamp()},r.prototype.multiplyUpperTo=function(t,e,r){--e;var i=r.t=this.t+t.t-e;for(r.s=0;--i>=0;)r[i]=0;for(i=Math.max(e-this.t,0);i<t.t;++i)r[this.t+i-e]=this.am(e-i,t[i],r,0,0,this.t+i-e);r.clamp(),r.drShiftTo(1,r)},r.prototype.modInt=function(t){if(t<=0)return 0;var e=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(0==e)r=this[0]%t;else for(var i=this.t-1;i>=0;--i)r=(e*r+this[i])%t;return r},r.prototype.millerRabin=function(t){var e=this.subtract(r.ONE),n=e.getLowestSetBit();if(n<=0)return!1;var o=e.shiftRight(n);(t=t+1>>1)>D.length&&(t=D.length);for(var s=i(),u=0;u<t;++u){s.fromInt(D[Math.floor(Math.random()*D.length)]);var h=s.modPow(o,this);if(0!=h.compareTo(r.ONE)&&0!=h.compareTo(e)){for(var a=1;a++<n&&0!=h.compareTo(e);)if(0==(h=h.modPowInt(2,this)).compareTo(r.ONE))return!1;if(0!=h.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,e=new Array;e[0]=this.s;var r,i=this.DB-t*this.DB%8,n=0;if(t-- >0)for(i<this.DB&&(r=this[t]>>i)!=(this.s&this.DM)>>i&&(e[n++]=r|this.s<<this.DB-i);t>=0;)i<8?(r=(this[t]&(1<<i)-1)<<8-i,r|=this[--t]>>(i+=this.DB-8)):(r=this[t]>>(i-=8)&255,i<=0&&(i+=this.DB,--t)),128&r&&(r|=-256),0==n&&(128&this.s)!=(128&r)&&++n,(n>0||r!=this.s)&&(e[n++]=r);return e},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 e=i();return this.bitwiseTo(t,m,e),e},r.prototype.or=function(t){var e=i();return this.bitwiseTo(t,y,e),e},r.prototype.xor=function(t){var e=i();return this.bitwiseTo(t,d,e),e},r.prototype.andNot=function(t){var e=i();return this.bitwiseTo(t,g,e),e},r.prototype.not=function(){for(var t=i(),e=0;e<this.t;++e)t[e]=this.DM&~this[e];return t.t=this.t,t.s=~this.s,t},r.prototype.shiftLeft=function(t){var e=i();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e},r.prototype.shiftRight=function(t){var e=i();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e},r.prototype.getLowestSetBit=function(){for(var t=0;t<this.t;++t)if(0!=this[t])return t*this.DB+v(this[t]);return this.s<0?this.t*this.DB:-1},r.prototype.bitCount=function(){for(var t=0,e=this.s&this.DM,r=0;r<this.t;++r)t+=w(this[r]^e);return t},r.prototype.testBit=function(t){var e=Math.floor(t/this.DB);return e>=this.t?0!=this.s:!!(this[e]&1<<t%this.DB)},r.prototype.setBit=function(t){return this.changeBit(t,y)},r.prototype.clearBit=function(t){return this.changeBit(t,g)},r.prototype.flipBit=function(t){return this.changeBit(t,d)},r.prototype.add=function(t){var e=i();return this.addTo(t,e),e},r.prototype.subtract=function(t){var e=i();return this.subTo(t,e),e},r.prototype.multiply=function(t){var e=i();return this.multiplyTo(t,e),e},r.prototype.divide=function(t){var e=i();return this.divRemTo(t,e,null),e},r.prototype.remainder=function(t){var e=i();return this.divRemTo(t,null,e),e},r.prototype.divideAndRemainder=function(t){var e=i(),r=i();return this.divRemTo(t,e,r),new Array(e,r)},r.prototype.modPow=function(t,e){var r,n,o=t.bitLength(),s=c(1);if(o<=0)return s;r=o<18?1:o<48?3:o<144?4:o<768?5:6,n=o<8?new f(e):e.isEven()?new b(e):new p(e);var u=new Array,h=3,a=r-1,m=(1<<r)-1;if(u[1]=n.convert(this),r>1){var y=i();for(n.sqrTo(u[1],y);h<=m;)u[h]=i(),n.mulTo(y,u[h-2],u[h]),h+=2}var d,g,v=t.t-1,w=!0,T=i();for(o=l(t[v])-1;v>=0;){for(o>=a?d=t[v]>>o-a&m:(d=(t[v]&(1<<o+1)-1)<<a-o,v>0&&(d|=t[v-1]>>this.DB+o-a)),h=r;!(1&d);)d>>=1,--h;if((o-=h)<0&&(o+=this.DB,--v),w)u[d].copyTo(s),w=!1;else{for(;h>1;)n.sqrTo(s,T),n.sqrTo(T,s),h-=2;h>0?n.sqrTo(s,T):(g=s,s=T,T=g),n.mulTo(T,u[d],s)}for(;v>=0&&!(t[v]&1<<o);)n.sqrTo(s,T),g=s,s=T,T=g,--o<0&&(o=this.DB-1,--v)}return n.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(),n=this.clone(),o=c(1),s=c(0),u=c(0),h=c(1);0!=i.signum();){for(;i.isEven();)i.rShiftTo(1,i),e?(o.isEven()&&s.isEven()||(o.addTo(this,o),s.subTo(t,s)),o.rShiftTo(1,o)):s.isEven()||s.subTo(t,s),s.rShiftTo(1,s);for(;n.isEven();)n.rShiftTo(1,n),e?(u.isEven()&&h.isEven()||(u.addTo(this,u),h.subTo(t,h)),u.rShiftTo(1,u)):h.isEven()||h.subTo(t,h),h.rShiftTo(1,h);i.compareTo(n)>=0?(i.subTo(n,i),e&&o.subTo(u,o),s.subTo(h,s)):(n.subTo(i,n),e&&u.subTo(o,u),h.subTo(s,h))}return 0!=n.compareTo(r.ONE)?r.ZERO:h.compareTo(t)>=0?h.subtract(t):h.signum()<0?(h.addTo(t,h),h.signum()<0?h.add(t):h):h},r.prototype.pow=function(t){return this.exp(t,new T)},r.prototype.gcd=function(t){var e=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(e.compareTo(r)<0){var i=e;e=r,r=i}var n=e.getLowestSetBit(),o=r.getLowestSetBit();if(o<0)return e;for(n<o&&(o=n),o>0&&(e.rShiftTo(o,e),r.rShiftTo(o,r));e.signum()>0;)(n=e.getLowestSetBit())>0&&e.rShiftTo(n,e),(n=r.getLowestSetBit())>0&&r.rShiftTo(n,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r},r.prototype.isProbablePrime=function(t){var e,r=this.abs();if(1==r.t&&r[0]<=D[D.length-1]){for(e=0;e<D.length;++e)if(r[0]==D[e])return!0;return!1}if(r.isEven())return!1;for(e=1;e<D.length;){for(var i=D[e],n=e+1;n<D.length&&i<I;)i*=D[n++];for(i=r.modInt(i);e<n;)if(i%D[e++]==0)return!1}return r.millerRabin(t)},r.prototype.square=function(){var t=i();return this.squareTo(t),t},r.prototype.Barrett=b,null==x){var q;if(x=new Array,S=0,"undefined"!=typeof window&&window.crypto)if(window.crypto.getRandomValues){var A=new Uint8Array(32);for(window.crypto.getRandomValues(A),q=0;q<32;++q)x[S++]=A[q]}else if("Netscape"==navigator.appName&&navigator.appVersion<"5"){var P=window.crypto.random(32);for(q=0;q<P.length;++q)x[S++]=255&P.charCodeAt(q)}for(;S<M;)q=Math.floor(65536*Math.random()),x[S++]=q>>>8,x[S++]=255&q;S=0,E()}function O(){if(null==B){for(E(),(B=new N).init(x),S=0;S<x.length;++S)x[S]=0;S=0}return B.next()}function R(){}function N(){this.i=0,this.j=0,this.S=new Array}R.prototype.nextBytes=function(t){var e;for(e=0;e<t.length;++e)t[e]=O()},N.prototype.init=function(t){var e,r,i;for(e=0;e<256;++e)this.S[e]=e;for(r=0,e=0;e<256;++e)r=r+this.S[e]+t[e%t.length]&255,i=this.S[e],this.S[e]=this.S[r],this.S[r]=i;this.i=0,this.j=0},N.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 M=256;t.exports={default:r,BigInteger:r,SecureRandom:R}}.call(w)),v.exports;var t}function F(){if(i)return r;i=1;const{BigInteger:t}=T();class e{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 e=t.toString(16);if(e.length%2==1&&(e="0"+e),t<128)return e;return(128+e.length/2).toString(16)+e}getValue(){return""}}class n extends e{constructor(e){super(),this.t="02",e&&(this.v=function(e){let r=e.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 i=r.length;i%2==1?i+=1:r.match(/^[0-7]/)||(i+=2);let n="";for(let t=0;t<i;t++)n+="f";n=new t(n,16),r=n.xor(e).add(t.ONE),r=r.toString(16).replace(/^-/,"")}return r}(e))}getValue(){return this.v}}class o extends e{constructor(t){super(),this.t="30",this.asn1Array=t}getValue(){return this.v=this.asn1Array.map((t=>t.getEncodedHex())).join(""),this.v}}function s(t,e){return+t[e+2]<8?1:128&+t.substr(e+2,2)}function u(e,r){const i=s(e,r),n=e.substr(r+2,2*i);if(!n)return-1;return(+n[0]<8?new t(n,16):new t(n.substr(2),16)).intValue()}function h(t,e){return e+2*(s(t,e)+1)}return r={encodeDer(t,e){const r=new n(t),i=new n(e);return new o([r,i]).getEncodedHex()},decodeDer(e){const r=h(e,0),i=h(e,r),n=u(e,r),o=e.substr(i,2*n),s=i+o.length,a=h(e,s),c=u(e,s),l=e.substr(a,2*c);return{r:new t(o,16),s:new t(l,16)}}}}function b(){if(u)return s;u=1;const{BigInteger:t,SecureRandom:e}=T(),{ECCurveFp:r}=function(){if(o)return n;o=1;const{BigInteger:t}=T(),e=new t("2"),r=new t("3");class i{constructor(t,e){this.x=e,this.q=t}equals(t){return t===this||this.q.equals(t.q)&&this.x.equals(t.x)}toBigInteger(){return this.x}negate(){return new i(this.q,this.x.negate().mod(this.q))}add(t){return new i(this.q,this.x.add(t.toBigInteger()).mod(this.q))}subtract(t){return new i(this.q,this.x.subtract(t.toBigInteger()).mod(this.q))}multiply(t){return new i(this.q,this.x.multiply(t.toBigInteger()).mod(this.q))}divide(t){return new i(this.q,this.x.multiply(t.toBigInteger().modInverse(this.q)).mod(this.q))}square(){return new i(this.q,this.x.square().mod(this.q))}}class s{constructor(e,r,i,n){this.curve=e,this.x=r,this.y=i,this.z=null==n?t.ONE:n,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(e){return e===this||(this.isInfinity()?e.isInfinity():e.isInfinity()?this.isInfinity():!!e.y.toBigInteger().multiply(this.z).subtract(this.y.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(t.ZERO)&&e.x.toBigInteger().multiply(this.z).subtract(this.x.toBigInteger().multiply(e.z)).mod(this.curve.q).equals(t.ZERO))}isInfinity(){return null===this.x&&null===this.y||this.z.equals(t.ZERO)&&!this.y.toBigInteger().equals(t.ZERO)}negate(){return new s(this.curve,this.x,this.y.negate(),this.z)}add(e){if(this.isInfinity())return e;if(e.isInfinity())return this;const r=this.x.toBigInteger(),i=this.y.toBigInteger(),n=this.z,o=e.x.toBigInteger(),u=e.y.toBigInteger(),h=e.z,a=this.curve.q,c=r.multiply(h).mod(a),l=o.multiply(n).mod(a),f=c.subtract(l),p=i.multiply(h).mod(a),m=u.multiply(n).mod(a),y=p.subtract(m);if(t.ZERO.equals(f))return t.ZERO.equals(y)?this.twice():this.curve.infinity;const d=c.add(l),g=n.multiply(h).mod(a),v=f.square().mod(a),w=f.multiply(v).mod(a),T=g.multiply(y.square()).subtract(d.multiply(v)).mod(a),F=f.multiply(T).mod(a),b=y.multiply(v.multiply(c).subtract(T)).subtract(p.multiply(w)).mod(a),B=w.multiply(g).mod(a);return new s(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(),e=this.y.toBigInteger(),i=this.z,n=this.curve.q,o=this.curve.a.toBigInteger(),u=t.square().multiply(r).add(o.multiply(i.square())).mod(n),h=e.shiftLeft(1).multiply(i).mod(n),a=e.square().mod(n),c=a.multiply(t).multiply(i).mod(n),l=h.square().mod(n),f=u.square().subtract(c.shiftLeft(3)).mod(n),p=h.multiply(f).mod(n),m=u.multiply(c.shiftLeft(2).subtract(f)).subtract(l.shiftLeft(1).multiply(a)).mod(n),y=h.multiply(l).mod(n);return new s(this.curve,this.curve.fromBigInteger(p),this.curve.fromBigInteger(m),y)}multiply(t){if(this.isInfinity())return this;if(!t.signum())return this.curve.infinity;const e=t.multiply(r),i=this.negate();let n=this;for(let r=e.bitLength()-2;r>0;r--){n=n.twice();const o=e.testBit(r);o!==t.testBit(r)&&(n=n.add(o?this:i))}return n}}return n={ECPointFp:s,ECCurveFp:class{constructor(t,e,r){this.q=t,this.a=this.fromBigInteger(e),this.b=this.fromBigInteger(r),this.infinity=new s(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 i(this.q,t)}decodePointHex(r){switch(parseInt(r.substr(0,2),16)){case 0:return this.infinity;case 2:case 3:const i=this.fromBigInteger(new t(r.substr(2),16));let n=this.fromBigInteger(i.multiply(i.square()).add(i.multiply(this.a)).add(this.b).toBigInteger().modPow(this.q.divide(new t("4")).add(t.ONE),this.q));return n.toBigInteger().mod(e).equals(new t(r.substr(0,2),16).subtract(e))||(n=n.negate()),new s(this,i,n);case 4:case 6:case 7:const o=(r.length-2)/2,u=r.substr(2,o),h=r.substr(o+2,o);return new s(this,this.fromBigInteger(new t(u,16)),this.fromBigInteger(new t(h,16)));default:return null}}}}}(),i=new e,{curve:h,G:a,n:c}=l();function l(){const e=new t("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFF",16),i=new t("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000FFFFFFFFFFFFFFFC",16),n=new t("28E9FA9E9D9F5E344D5A9E4BCF6509A7F39789F515AB8F92DDBCBD414D940E93",16),o=new r(e,i,n),s=o.decodePointHex("0432C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0");return{curve:o,G:s,n:new t("FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123",16)}}function f(t,e){return t.length>=e?t:new Array(e-t.length+1).join("0")+t}return s={getGlobalCurve:function(){return h},generateEcparam:l,generateKeyPairHex:function(e,r,n){const o=(e?new t(e,r,n):new t(c.bitLength(),i)).mod(c.subtract(t.ONE)).add(t.ONE),s=f(o.toString(16),64),u=a.multiply(o);return{privateKey:s,publicKey:"04"+f(u.getX().toBigInteger().toString(16),64)+f(u.getY().toBigInteger().toString(16),64)}},compressPublicKeyHex:function(e){if(130!==e.length)throw new Error("Invalid public key to compress");const r=(e.length-2)/2,i=e.substr(2,r);let n="03";return new t(e.substr(r+2,r),16).mod(new t("2")).equals(t.ZERO)&&(n="02"),n+i},utf8ToHex:function(t){const e=(t=unescape(encodeURIComponent(t))).length,r=[];for(let i=0;i<e;i++)r[i>>>2]|=(255&t.charCodeAt(i))<<24-i%4*8;const i=[];for(let t=0;t<e;t++){const e=r[t>>>2]>>>24-t%4*8&255;i.push((e>>>4).toString(16)),i.push((15&e).toString(16))}return i.join("")},leftPad:f,arrayToHex:function(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")},arrayToUtf8:function(t){const e=[];let r=0;for(let i=0;i<2*t.length;i+=2)e[i>>>3]|=parseInt(t[r],10)<<24-i%8*4,r++;try{const r=[];for(let i=0;i<t.length;i++){const t=e[i>>>2]>>>24-i%4*8&255;r.push(String.fromCharCode(t))}return decodeURIComponent(escape(r.join("")))}catch(t){throw new Error("Malformed UTF-8 data")}},hexToArray:function(t){const e=[];let r=t.length;r%2!=0&&(t=f(t,r+1)),r=t.length;for(let i=0;i<r;i+=2)e.push(parseInt(t.substr(i,2),16));return e},verifyPublicKey:function(t){const e=h.decodePointHex(t);if(!e)return!1;const r=e.getX();return e.getY().square().equals(r.multiply(r.square()).add(r.multiply(h.a)).add(h.b))},comparePublicKeyHex:function(t,e){const r=h.decodePointHex(t);if(!r)return!1;const i=h.decodePointHex(e);return!!i&&r.equals(i)}}}function B(){if(a)return h;a=1;const t=new Uint32Array(68),e=new Uint32Array(64);function r(t,e){const r=31&e;return t<<r|t>>>32-r}function i(t,e){const r=[];for(let i=t.length-1;i>=0;i--)r[i]=255&(t[i]^e[i]);return r}function n(t){return t^r(t,9)^r(t,17)}function o(i){let o=8*i.length,s=o%512;s=s>=448?512-s%448-1:448-s-1;const u=new Array((s-7)/8),h=new Array(8);for(let t=0,e=u.length;t<e;t++)u[t]=0;for(let t=0,e=h.length;t<e;t++)h[t]=0;o=o.toString(2);for(let t=7;t>=0;t--)if(o.length>8){const e=o.length-8;h[t]=parseInt(o.substr(e),2),o=o.substr(0,e)}else o.length>0&&(h[t]=parseInt(o,2),o="");const a=new Uint8Array([...i,128,...u,...h]),c=new DataView(a.buffer,0),l=a.length/64,f=new Uint32Array([1937774191,1226093241,388252375,3666478592,2842636476,372324522,3817729613,2969243214]);for(let i=0;i<l;i++){t.fill(0),e.fill(0);const o=16*i;for(let e=0;e<16;e++)t[e]=c.getUint32(4*(o+e),!1);for(let e=16;e<68;e++)t[e]=(p=t[e-16]^t[e-9]^r(t[e-3],15))^r(p,15)^r(p,23)^r(t[e-13],7)^t[e-6];for(let r=0;r<64;r++)e[r]=t[r]^t[r+4];const s=2043430169,u=2055708042;let h,a,l,m,y,d=f[0],g=f[1],v=f[2],w=f[3],T=f[4],F=f[5],b=f[6],B=f[7];for(let i=0;i<64;i++)y=i>=0&&i<=15?s:u,h=r(r(d,12)+T+r(y,i),7),a=h^r(d,12),l=(i>=0&&i<=15?d^g^v:d&g|d&v|g&v)+w+a+e[i],m=(i>=0&&i<=15?T^F^b:T&F|~T&b)+B+h+t[i],w=v,v=r(g,9),g=d,d=l,B=b,b=r(F,19),F=T,T=n(m);f[0]^=d,f[1]^=g,f[2]^=v,f[3]^=w,f[4]^=T,f[5]^=F,f[6]^=b,f[7]^=B}var p;const m=[];for(let t=0,e=f.length;t<e;t++){const e=f[t];m.push((4278190080&e)>>>24,(16711680&e)>>>16,(65280&e)>>>8,255&e)}return m}const s=new Uint8Array(64),u=new Uint8Array(64);for(let t=0;t<64;t++)s[t]=54,u[t]=92;return h={sm3:o,hmac:function(t,e){for(e.length>64&&(e=o(e));e.length<64;)e.push(0);const r=i(e,s),n=i(e,u),h=o([...r,...t]);return o([...n,...h])}}}function x(){if(l)return c;l=1;const{BigInteger:t}=T(),{encodeDer:e,decodeDer:r}=F(),i=b(),n=B().sm3,{G:o,curve:s,n:u}=i.generateEcparam();function h(t,e,r="1234567812345678"){r=i.utf8ToHex(r);const s=i.leftPad(o.curve.a.toBigInteger().toRadix(16),64),u=i.leftPad(o.curve.b.toBigInteger().toRadix(16),64),h=i.leftPad(o.getX().toBigInteger().toRadix(16),64),a=i.leftPad(o.getY().toBigInteger().toRadix(16),64);let c,l;if(128===e.length)c=e.substr(0,64),l=e.substr(64,64);else{const t=o.curve.decodePointHex(e);c=i.leftPad(t.getX().toBigInteger().toRadix(16),64),l=i.leftPad(t.getY().toBigInteger().toRadix(16),64)}const f=i.hexToArray(r+s+u+h+a+c+l),p=4*r.length;f.unshift(255&p),f.unshift(p>>8&255);const m=n(f);return i.arrayToHex(n(m.concat(i.hexToArray(t))))}function a(e){const r=o.multiply(new t(e,16));return"04"+i.leftPad(r.getX().toBigInteger().toString(16),64)+i.leftPad(r.getY().toBigInteger().toString(16),64)}function f(){const e=i.generateKeyPairHex(),r=s.decodePointHex(e.publicKey);return e.k=new t(e.privateKey,16),e.x1=r.getX().toBigInteger(),e}return c={generateKeyPairHex:i.generateKeyPairHex,compressPublicKeyHex:i.compressPublicKeyHex,comparePublicKeyHex:i.comparePublicKeyHex,doEncrypt:function(e,r,o=1){e="string"==typeof e?i.hexToArray(i.utf8ToHex(e)):Array.prototype.slice.call(e),r=i.getGlobalCurve().decodePointHex(r);const s=i.generateKeyPairHex(),u=new t(s.privateKey,16);let h=s.publicKey;h.length>128&&(h=h.substr(h.length-128));const a=r.multiply(u),c=i.hexToArray(i.leftPad(a.getX().toBigInteger().toRadix(16),64)),l=i.hexToArray(i.leftPad(a.getY().toBigInteger().toRadix(16),64)),f=i.arrayToHex(n([].concat(c,e,l)));let p=1,m=0,y=[];const d=[].concat(c,l),g=()=>{y=n([...d,p>>24&255,p>>16&255,p>>8&255,255&p]),p++,m=0};g();for(let t=0,r=e.length;t<r;t++)m===y.length&&g(),e[t]^=255&y[m++];const v=i.arrayToHex(e);return 0===o?h+v+f:h+f+v},doDecrypt:function(e,r,o=1,{output:s="string"}={}){r=new t(r,16);let u=e.substr(128,64),h=e.substr(192);0===o&&(u=e.substr(e.length-64),h=e.substr(128,e.length-128-64));const a=i.hexToArray(h),c=i.getGlobalCurve().decodePointHex("04"+e.substr(0,128)).multiply(r),l=i.hexToArray(i.leftPad(c.getX().toBigInteger().toRadix(16),64)),f=i.hexToArray(i.leftPad(c.getY().toBigInteger().toRadix(16),64));let p=1,m=0,y=[];const d=[].concat(l,f),g=()=>{y=n([...d,p>>24&255,p>>16&255,p>>8&255,255&p]),p++,m=0};g();for(let t=0,e=a.length;t<e;t++)m===y.length&&g(),a[t]^=255&y[m++];return i.arrayToHex(n([].concat(l,a,f)))===u.toLowerCase()?"array"===s?a:i.arrayToUtf8(a):"array"===s?[]:""},doSignature:function(r,n,{pointPool:o,der:s,hash:c,publicKey:l,userId:p}={}){let m="string"==typeof r?i.utf8ToHex(r):i.arrayToHex(r);c&&(m=h(m,l=l||a(n),p));const y=new t(n,16),d=new t(m,16);let g=null,v=null,w=null;do{do{let t;t=o&&o.length?o.pop():f(),g=t.k,v=d.add(t.x1).mod(u)}while(v.equals(t.ZERO)||v.add(g).equals(u));w=y.add(t.ONE).modInverse(u).multiply(g.subtract(v.multiply(y))).mod(u)}while(w.equals(t.ZERO));return s?e(v,w):i.leftPad(v.toString(16),64)+i.leftPad(w.toString(16),64)},doVerifySignature:function(e,n,a,{der:c,hash:l,userId:f}={}){let p,m,y="string"==typeof e?i.utf8ToHex(e):i.arrayToHex(e);if(l&&(y=h(y,a,f)),c){const t=r(n);p=t.r,m=t.s}else p=new t(n.substring(0,64),16),m=new t(n.substring(64),16);const d=s.decodePointHex(a),g=new t(y,16),v=p.add(m).mod(u);if(v.equals(t.ZERO))return!1;const w=o.multiply(m).add(d.multiply(v)),T=g.add(w.getX().toBigInteger()).mod(u);return p.equals(T)},getPublicKeyFromPrivateKey:a,getPoint:f,verifyPublicKey:i.verifyPublicKey}}function S(){if(p)return f;p=1;const{sm3:t,hmac:e}=B();function r(t){return t.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join("")}function i(t){const e=[];let r=t.length;var i,n;r%2!=0&&(n=r+1,t=(i=t).length>=n?i:new Array(n-i.length+1).join("0")+i),r=t.length;for(let i=0;i<r;i+=2)e.push(parseInt(t.substr(i,2),16));return e}return f=function(n,o){if(n="string"==typeof n?function(t){const e=[];for(let r=0,i=t.length;r<i;r++){const i=t.codePointAt(r);if(i<=127)e.push(i);else if(i<=2047)e.push(192|i>>>6),e.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)e.push(224|i>>>12),e.push(128|i>>>6&63),e.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw e.push(i),new Error("input is not supported");r++,e.push(240|i>>>18&28),e.push(128|i>>>12&63),e.push(128|i>>>6&63),e.push(128|63&i)}}return e}(n):Array.prototype.slice.call(n),o){if("hmac"!==(o.mode||"hmac"))throw new Error("invalid mode");let t=o.key;if(!t)throw new Error("invalid key");return t="string"==typeof t?i(t):Array.prototype.slice.call(t),r(e(n,t))}return r(t(n))}}function D(){if(y)return m;y=1;const t=16,e=[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],r=[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 i(t){const e=[];for(let r=0,i=t.length;r<i;r+=2)e.push(parseInt(t.substr(r,2),16));return e}function n(t,e){const r=31&e;return t<<r|t>>>32-r}function o(t){return(255&e[t>>>24&255])<<24|(255&e[t>>>16&255])<<16|(255&e[t>>>8&255])<<8|255&e[255&t]}function s(t){return t^n(t,2)^n(t,10)^n(t,18)^n(t,24)}function u(t){return t^n(t,13)^n(t,23)}function h(t,e,r){const i=new Array(4),n=new Array(4);for(let e=0;e<4;e++)n[0]=255&t[4*e],n[1]=255&t[4*e+1],n[2]=255&t[4*e+2],n[3]=255&t[4*e+3],i[e]=n[0]<<24|n[1]<<16|n[2]<<8|n[3];for(let t,e=0;e<32;e+=4)t=i[1]^i[2]^i[3]^r[e+0],i[0]^=s(o(t)),t=i[2]^i[3]^i[0]^r[e+1],i[1]^=s(o(t)),t=i[3]^i[0]^i[1]^r[e+2],i[2]^=s(o(t)),t=i[0]^i[1]^i[2]^r[e+3],i[3]^=s(o(t));for(let t=0;t<16;t+=4)e[t]=i[3-t/4]>>>24&255,e[t+1]=i[3-t/4]>>>16&255,e[t+2]=i[3-t/4]>>>8&255,e[t+3]=255&i[3-t/4]}function a(e,n,s,{padding:a="pkcs#7",mode:c,iv:l=[],output:f="string"}={}){if("cbc"===c&&("string"==typeof l&&(l=i(l)),16!==l.length))throw new Error("iv is invalid");if("string"==typeof n&&(n=i(n)),16!==n.length)throw new Error("key is invalid");if(e="string"==typeof e?0!==s?function(t){const e=[];for(let r=0,i=t.length;r<i;r++){const i=t.codePointAt(r);if(i<=127)e.push(i);else if(i<=2047)e.push(192|i>>>6),e.push(128|63&i);else if(i<=55295||i>=57344&&i<=65535)e.push(224|i>>>12),e.push(128|i>>>6&63),e.push(128|63&i);else{if(!(i>=65536&&i<=1114111))throw e.push(i),new Error("input is not supported");r++,e.push(240|i>>>18&28),e.push(128|i>>>12&63),e.push(128|i>>>6&63),e.push(128|63&i)}}return e}(e):i(e):[...e],("pkcs#5"===a||"pkcs#7"===a)&&0!==s){const r=t-e.length%t;for(let t=0;t<r;t++)e.push(r)}const p=new Array(32);!function(t,e,i){const n=new Array(4),s=new Array(4);for(let e=0;e<4;e++)s[0]=255&t[0+4*e],s[1]=255&t[1+4*e],s[2]=255&t[2+4*e],s[3]=255&t[3+4*e],n[e]=s[0]<<24|s[1]<<16|s[2]<<8|s[3];n[0]^=2746333894,n[1]^=1453994832,n[2]^=1736282519,n[3]^=2993693404;for(let t,i=0;i<32;i+=4)t=n[1]^n[2]^n[3]^r[i+0],e[i+0]=n[0]^=u(o(t)),t=n[2]^n[3]^n[0]^r[i+1],e[i+1]=n[1]^=u(o(t)),t=n[3]^n[0]^n[1]^r[i+2],e[i+2]=n[2]^=u(o(t)),t=n[0]^n[1]^n[2]^r[i+3],e[i+3]=n[3]^=u(o(t));if(0===i)for(let t,r=0;r<16;r++)t=e[r],e[r]=e[31-r],e[31-r]=t}(n,p,s);const m=[];let y=l,d=e.length,g=0;for(;d>=t;){const r=e.slice(g,g+16),i=new Array(16);if("cbc"===c)for(let e=0;e<t;e++)0!==s&&(r[e]^=y[e]);h(r,i,p);for(let e=0;e<t;e++)"cbc"===c&&0===s&&(i[e]^=y[e]),m[g+e]=i[e];"cbc"===c&&(y=0!==s?i:r),d-=t,g+=t}if(("pkcs#5"===a||"pkcs#7"===a)&&0===s){const t=m.length,e=m[t-1];for(let r=1;r<=e;r++)if(m[t-r]!==e)throw new Error("padding is invalid");m.splice(t-e,e)}return"array"!==f?0!==s?m.map((t=>1===(t=t.toString(16)).length?"0"+t:t)).join(""):function(t){const e=[];for(let r=0,i=t.length;r<i;r++)t[r]>=240&&t[r]<=247?(e.push(String.fromCodePoint(((7&t[r])<<18)+((63&t[r+1])<<12)+((63&t[r+2])<<6)+(63&t[r+3]))),r+=3):t[r]>=224&&t[r]<=239?(e.push(String.fromCodePoint(((15&t[r])<<12)+((63&t[r+1])<<6)+(63&t[r+2]))),r+=2):t[r]>=192&&t[r]<=223?(e.push(String.fromCodePoint(((31&t[r])<<6)+(63&t[r+1]))),r++):e.push(String.fromCodePoint(t[r]));return e.join("")}(m):m}return m={encrypt:(t,e,r)=>a(t,e,1,r),decrypt:(t,e,r)=>a(t,e,0,r)}}var I=t(g?d:(g=1,d={sm2:x(),sm3:S(),sm4:D()}));const{sm2:E}=I;var q=new class{constructor(){this.privateKey="",this.publicKey="","undefined"!=typeof window&&"undefined"!=typeof localStorage?this._initKeys():console.warn("[sm2Util] localStorage not available; SM2 key not initialized.")}_initKeys(){const t=localStorage.getItem("__cacheUtil_sm2_priv"),e=localStorage.getItem("__cacheUtil_sm2_pub");if(t&&e)this.privateKey=t,this.publicKey=e;else{const t=E.generateKeyPairHex();this.privateKey=t.privateKey,this.publicKey=t.publicKey,localStorage.setItem("__cacheUtil_sm2_priv",this.privateKey),localStorage.setItem("__cacheUtil_sm2_pub",this.publicKey)}}encrypt(t){try{return E.doEncrypt(t,this.publicKey,1)}catch(t){return console.error("[sm2Util] encryption failed:",t),""}}decrypt(t){try{return E.doDecrypt(t,this.privateKey,1)}catch(t){return console.error("[sm2Util] decryption failed:",t),""}}resetKeys(){localStorage.removeItem("__cacheUtil_sm2_priv"),localStorage.removeItem("__cacheUtil_sm2_pub"),this._initKeys()}getPublicKey(){return this.publicKey}};const A=window.localStorage;var P={set(t,e,r={}){const{expire:i=0,encrypt:n=!1}=r;let o="string"==typeof e?e:JSON.stringify(e);if(n){const t=q.encrypt(o);if(!t)return!1;o=t}const s=i>0?Date.now()+i:0;return A.setItem(t,function(t,e){const r={data:t,expire:e};return JSON.stringify(r)}(o,s)),!0},get(t,e={}){const{encrypt:r=!1}=e,i=function(t){if(!t)return null;try{return JSON.parse(t)}catch(t){return null}}(A.getItem(t));if(!i)return null;if(i.expire&&i.expire<Date.now())return A.removeItem(t),null;let n=i.data;if(r){const t=q.decrypt(n);if(null===t)return null;n=t}try{return JSON.parse(n)}catch(t){return n}},remove(t){A.removeItem(t)},clear(){A.clear()}};const O=window.sessionStorage;var R={set(t,e,r={}){const{expire:i=0,encrypt:n=!1}=r;let o="string"==typeof e?e:JSON.stringify(e);if(n){const t=q.encrypt(o);if(!t)return!1;o=t}const s=i>0?Date.now()+i:0;return O.setItem(t,function(t,e){const r={data:t,expire:e};return JSON.stringify(r)}(o,s)),!0},get(t,e={}){const{encrypt:r=!1}=e,i=function(t){if(!t)return null;try{return JSON.parse(t)}catch(t){return null}}(O.getItem(t));if(!i)return null;if(i.expire&&i.expire<Date.now())return O.removeItem(t),null;let n=i.data;if(r){const t=q.decrypt(n);if(null===t)return null;n=t}try{return JSON.parse(n)}catch(t){return n}},remove(t){O.removeItem(t)},clear(){O.clear()}};const N={};var M={set(t,e,r={}){const{expire:i=0,encrypt:n=!1}=r;let o="string"==typeof e?e:JSON.stringify(e);if(n){const t=q.encrypt(o);if(!t)return!1;o=t}const s=i>0?Date.now()+i:0;return N[t]={data:o,expire:s},!0},get(t,e={}){const{encrypt:r=!1}=e,i=N[t];if(!i)return null;if(i.expire&&i.expire<Date.now())return delete N[t],null;let n=i.data;if(r){const t=q.decrypt(n);if(null===t)return null;n=t}try{return JSON.parse(n)}catch(t){return n}},remove(t){delete N[t]},clear(){for(const t in N)delete N[t]}};function K(t){document.cookie=`${t}=; Max-Age=-1; path=/`}var C={set(t,e,r={}){const{expire:i=0,encrypt:n=!1}=r;let o="string"==typeof e?e:JSON.stringify(e);if(n){const t=q.encrypt(o);if(!t)return!1;o=t}const s=i>0?Date.now()+i:0;return function(t,e,r){let i="";r>0&&(i="; expires="+new Date(Date.now()+r).toUTCString());document.cookie=`${t}=${encodeURIComponent(e)}${i}; path=/`}(t,JSON.stringify({data:o,expire:s}),i),!0},get(t,e={}){const{encrypt:r=!1}=e,i=function(t){const e=new RegExp("(^| )"+t+"=([^;]+)"),r=document.cookie.match(e);return r?decodeURIComponent(r[2]):null}(t);if(!i)return null;let n;try{n=JSON.parse(i)}catch(t){return null}if(n.expire&&n.expire<Date.now())return K(t),null;let o=n.data;if(r){const t=q.decrypt(o);if(null===t)return null;o=t}try{return JSON.parse(o)}catch(t){return o}},remove(t){K(t)},clear(){document.cookie.split(";").forEach((t=>{const e=t.split("=")[0].trim();e&&K(e)}))}};class H{constructor(t="__cacheUtil_db",e="__cacheUtil_store",r=1){this.db=null,this.dbName=t,this.storeName=e,this.version=r}async init(){return this.db?this.db:new Promise(((t,e)=>{const r=indexedDB.open(this.dbName,this.version);r.onupgradeneeded=()=>{const t=r.result;t.objectStoreNames.contains(this.storeName)||t.createObjectStore(this.storeName)},r.onsuccess=()=>{this.db=r.result,t(this.db)},r.onerror=()=>e(r.error)}))}async set(t,e,r={}){const{expire:i=0,encrypt:n=!1}=r;let o="string"==typeof e?e:JSON.stringify(e);if(n){const t=q.encrypt(o);if(!t)return!1;o=t}const s={data:o,expire:i>0?Date.now()+i:0},u=await this.init();return new Promise(((e,r)=>{const i=u.transaction(this.storeName,"readwrite");i.objectStore(this.storeName).put(s,t),i.oncomplete=()=>e(!0),i.onerror=()=>r(i.error)}))}async get(t,e={}){const{encrypt:r=!1}=e,i=await this.init();return new Promise(((e,n)=>{const o=i.transaction(this.storeName,"readonly").objectStore(this.storeName).get(t);o.onsuccess=async()=>{const i=o.result;if(!i)return e(null);if(i.expire&&i.expire<Date.now())return await this.remove(t),e(null);let n=i.data;if(r){const t=q.decrypt(n);if(null===t)return e(null);n=t}try{e(JSON.parse(n))}catch(t){e(n)}},o.onerror=()=>n(o.error)}))}async remove(t){const e=await this.init();return new Promise(((r,i)=>{const n=e.transaction(this.storeName,"readwrite");n.objectStore(this.storeName).delete(t),n.oncomplete=()=>r(!0),n.onerror=()=>i(n.error)}))}async clear(){const t=await this.init();return new Promise(((e,r)=>{const i=t.transaction(this.storeName,"readwrite");i.objectStore(this.storeName).clear(),i.oncomplete=()=>e(!0),i.onerror=()=>r(i.error)}))}}export{C as cookieStorage,H as indexedDB,P as localStorage,M as memoryStorage,R as sessionStorage};
//# sourceMappingURL=cache-util.esm.js.map