gun-eth 1.4.30 → 1.4.32
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/gun-eth.cjs.js +16 -12626
- package/dist/gun-eth.cjs.js.map +1 -1
- package/dist/gun-eth.esm.js +1368 -9
- package/dist/gun-eth.esm.js.map +1 -1
- package/dist/gun-eth.min.js +1 -9
- package/dist/gun-eth.min.js.map +1 -1
- package/dist/gun-eth.mjs +16 -12626
- package/dist/gun-eth.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.js +8 -8
package/dist/gun-eth.esm.js
CHANGED
@@ -1,10 +1,1369 @@
|
|
1
|
-
import t from"gun";export{default}from"gun";import e from"gun/sea.js";import{fileURLToPath as r}from"url";import{dirname as n}from"path";import{readFileSync as i}from"fs";var o="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function s(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function a(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})})),r}var h={exports:{}},u=a(Object.freeze({__proto__:null,default:{}}));!function(t,e){function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function i(t,e,r){if(i.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof t?t.exports=i:e.BN=i,i.BN=i,i.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:u.Buffer}catch(t){}function s(t,e){var n=t.charCodeAt(e);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void r(!1,"Invalid character in "+t)}function a(t,e,r){var n=s(t,r);return r-1>=e&&(n|=s(t,r-1)<<4),n}function h(t,e,n,i){for(var o=0,s=0,a=Math.min(t.length,n),h=e;h<a;h++){var u=t.charCodeAt(h)-48;o*=i,s=u>=49?u-49+10:u>=17?u-17+10:u,r(u>=0&&s<i,"Invalid character"),o+=s}return o}function f(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(i.isBN=function(t){return t instanceof i||null!==t&&"object"==typeof t&&t.constructor.wordSize===i.wordSize&&Array.isArray(t.words)},i.max=function(t,e){return t.cmp(e)>0?t:e},i.min=function(t,e){return t.cmp(e)<0?t:e},i.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(i++,this.negative=1),i<t.length&&(16===e?this._parseHex(t,i,n):(this._parseBase(t,e,i),"le"===n&&this._initArray(this.toArray(),e,n)))},i.prototype._initNumber=function(t,e,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},i.prototype._initArray=function(t,e,n){if(r("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var o,s,a=0;if("be"===n)for(i=t.length-1,o=0;i>=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===n)for(i=0,o=0;i<t.length;i+=3)s=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},i.prototype._parseHex=function(t,e,r){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var i,o=0,s=0;if("be"===r)for(n=t.length-1;n>=e;n-=2)i=a(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)i=a(t,e,n)<<o,this.words[s]|=67108863&i,o>=18?(o-=18,s+=1,this.words[s]|=i>>>26):o+=8;this._strip()},i.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=e)n++;n--,i=i/e|0;for(var o=t.length-r,s=o%n,a=Math.min(o,o-s)+r,u=0,f=r;f<a;f+=n)u=h(t,f,f+n,e),this.imuln(i),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==s){var l=1;for(u=h(t,f,t.length,e),f=0;f<s;f++)l*=e;this.imuln(l),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},i.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},i.prototype._move=function(t){f(t,this)},i.prototype.clone=function(){var t=new i(null);return this.copy(t),t},i.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},i.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},i.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{i.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){i.prototype.inspect=l}else i.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var c=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],p=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function m(t,e,r){r.negative=e.negative^t.negative;var n=t.length+e.length|0;r.length=n,n=n-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,h=s/67108864|0;r.words[0]=a;for(var u=1;u<n;u++){for(var f=h>>>26,l=67108863&h,c=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=c;d++){var p=u-d|0;f+=(s=(i=0|t.words[p])*(o=0|e.words[d])+l)/67108864|0,l=67108863&s}r.words[u]=0|l,h=0|f}return 0!==h?r.words[u]=0|h:r.length--,r._strip()}i.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var i=0,o=0,s=0;s<this.length;s++){var a=this.words[s],h=(16777215&(a<<i|o)).toString(16);o=a>>>24-i&16777215,(i+=2)>=26&&(i-=26,s--),n=0!==o||s!==this.length-1?c[6-h.length]+h+n:h+n}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var u=d[t],f=p[t];n="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modrn(f).toString(t);n=(l=l.idivn(f)).isZero()?m+n:c[u-m.length]+m+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&r(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},i.prototype.toJSON=function(){return this.toString(16,2)},o&&(i.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),i.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},i.prototype.toArrayLike=function(t,e,n){this._strip();var i=this.byteLength(),o=n||Math.max(1,i);r(i<=o,"byte array longer than desired length"),r(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,i),s},i.prototype._toArrayLikeLE=function(t,e){for(var r=0,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r++]=255&s,r<t.length&&(t[r++]=s>>8&255),r<t.length&&(t[r++]=s>>16&255),6===o?(r<t.length&&(t[r++]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r<t.length)for(t[r++]=n;r<t.length;)t[r++]=0},i.prototype._toArrayLikeBE=function(t,e){for(var r=t.length-1,n=0,i=0,o=0;i<this.length;i++){var s=this.words[i]<<o|n;t[r--]=255&s,r>=0&&(t[r--]=s>>8&255),r>=0&&(t[r--]=s>>16&255),6===o?(r>=0&&(t[r--]=s>>24&255),n=0,o=0):(n=s>>>24,o+=2)}if(r>=0)for(t[r--]=n;r>=0;)t[r--]=0},Math.clz32?i.prototype._countBits=function(t){return 32-Math.clz32(t)}:i.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},i.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 8191&e||(r+=13,e>>>=13),127&e||(r+=7,e>>>=7),15&e||(r+=4,e>>>=4),3&e||(r+=2,e>>>=2),1&e||r++,r},i.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)break}return t},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},i.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return 0!==this.negative},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},i.prototype.ior=function(t){return r(!(this.negative|t.negative)),this.iuor(t)},i.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},i.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},i.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},i.prototype.iand=function(t){return r(!(this.negative|t.negative)),this.iuand(t)},i.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},i.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},i.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var n=0;n<r.length;n++)this.words[n]=e.words[n]^r.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},i.prototype.ixor=function(t){return r(!(this.negative|t.negative)),this.iuxor(t)},i.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},i.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},i.prototype.inotn=function(t){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var i=0;i<e;i++)this.words[i]=67108863&~this.words[i];return n>0&&(this.words[i]=~this.words[i]&67108863>>26-n),this._strip()},i.prototype.notn=function(t){return this.clone().inotn(t)},i.prototype.setn=function(t,e){r("number"==typeof t&&t>=0);var n=t/26|0,i=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<i:this.words[n]&~(1<<i),this._strip()},i.prototype.iadd=function(t){var e,r,n;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(r=this,n=t):(r=t,n=this);for(var i=0,o=0;o<n.length;o++)e=(0|r.words[o])+(0|n.words[o])+i,this.words[o]=67108863&e,i=e>>>26;for(;0!==i&&o<r.length;o++)e=(0|r.words[o])+i,this.words[o]=67108863&e,i=e>>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this},i.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},i.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,n,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(r=this,n=t):(r=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|r.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<r.length;s++)o=(e=(0|r.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<r.length&&r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this.length=Math.max(this.length,s),r!==this&&(this.negative=1),this._strip()},i.prototype.sub=function(t){return this.clone().isub(t)};var g=function(t,e,r){var n,i,o,s=t.words,a=e.words,h=r.words,u=0,f=0|s[0],l=8191&f,c=f>>>13,d=0|s[1],p=8191&d,m=d>>>13,g=0|s[2],y=8191&g,v=g>>>13,w=0|s[3],b=8191&w,S=w>>>13,A=0|s[4],M=8191&A,E=A>>>13,_=0|s[5],P=8191&_,x=_>>>13,I=0|s[6],C=8191&I,N=I>>>13,R=0|s[7],k=8191&R,T=R>>>13,D=0|s[8],O=8191&D,F=D>>>13,B=0|s[9],L=8191&B,U=B>>>13,K=0|a[0],G=8191&K,z=K>>>13,H=0|a[1],q=8191&H,j=H>>>13,W=0|a[2],V=8191&W,J=W>>>13,$=0|a[3],Z=8191&$,X=$>>>13,Y=0|a[4],Q=8191&Y,tt=Y>>>13,et=0|a[5],rt=8191&et,nt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,ft=0|a[8],lt=8191&ft,ct=ft>>>13,dt=0|a[9],pt=8191&dt,mt=dt>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(u+(n=Math.imul(l,G))|0)+((8191&(i=(i=Math.imul(l,z))+Math.imul(c,G)|0))<<13)|0;u=((o=Math.imul(c,z))+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,n=Math.imul(p,G),i=(i=Math.imul(p,z))+Math.imul(m,G)|0,o=Math.imul(m,z);var yt=(u+(n=n+Math.imul(l,q)|0)|0)+((8191&(i=(i=i+Math.imul(l,j)|0)+Math.imul(c,q)|0))<<13)|0;u=((o=o+Math.imul(c,j)|0)+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,G),i=(i=Math.imul(y,z))+Math.imul(v,G)|0,o=Math.imul(v,z),n=n+Math.imul(p,q)|0,i=(i=i+Math.imul(p,j)|0)+Math.imul(m,q)|0,o=o+Math.imul(m,j)|0;var vt=(u+(n=n+Math.imul(l,V)|0)|0)+((8191&(i=(i=i+Math.imul(l,J)|0)+Math.imul(c,V)|0))<<13)|0;u=((o=o+Math.imul(c,J)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(b,G),i=(i=Math.imul(b,z))+Math.imul(S,G)|0,o=Math.imul(S,z),n=n+Math.imul(y,q)|0,i=(i=i+Math.imul(y,j)|0)+Math.imul(v,q)|0,o=o+Math.imul(v,j)|0,n=n+Math.imul(p,V)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,J)|0;var wt=(u+(n=n+Math.imul(l,Z)|0)|0)+((8191&(i=(i=i+Math.imul(l,X)|0)+Math.imul(c,Z)|0))<<13)|0;u=((o=o+Math.imul(c,X)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(M,G),i=(i=Math.imul(M,z))+Math.imul(E,G)|0,o=Math.imul(E,z),n=n+Math.imul(b,q)|0,i=(i=i+Math.imul(b,j)|0)+Math.imul(S,q)|0,o=o+Math.imul(S,j)|0,n=n+Math.imul(y,V)|0,i=(i=i+Math.imul(y,J)|0)+Math.imul(v,V)|0,o=o+Math.imul(v,J)|0,n=n+Math.imul(p,Z)|0,i=(i=i+Math.imul(p,X)|0)+Math.imul(m,Z)|0,o=o+Math.imul(m,X)|0;var bt=(u+(n=n+Math.imul(l,Q)|0)|0)+((8191&(i=(i=i+Math.imul(l,tt)|0)+Math.imul(c,Q)|0))<<13)|0;u=((o=o+Math.imul(c,tt)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(P,G),i=(i=Math.imul(P,z))+Math.imul(x,G)|0,o=Math.imul(x,z),n=n+Math.imul(M,q)|0,i=(i=i+Math.imul(M,j)|0)+Math.imul(E,q)|0,o=o+Math.imul(E,j)|0,n=n+Math.imul(b,V)|0,i=(i=i+Math.imul(b,J)|0)+Math.imul(S,V)|0,o=o+Math.imul(S,J)|0,n=n+Math.imul(y,Z)|0,i=(i=i+Math.imul(y,X)|0)+Math.imul(v,Z)|0,o=o+Math.imul(v,X)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var St=(u+(n=n+Math.imul(l,rt)|0)|0)+((8191&(i=(i=i+Math.imul(l,nt)|0)+Math.imul(c,rt)|0))<<13)|0;u=((o=o+Math.imul(c,nt)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(C,G),i=(i=Math.imul(C,z))+Math.imul(N,G)|0,o=Math.imul(N,z),n=n+Math.imul(P,q)|0,i=(i=i+Math.imul(P,j)|0)+Math.imul(x,q)|0,o=o+Math.imul(x,j)|0,n=n+Math.imul(M,V)|0,i=(i=i+Math.imul(M,J)|0)+Math.imul(E,V)|0,o=o+Math.imul(E,J)|0,n=n+Math.imul(b,Z)|0,i=(i=i+Math.imul(b,X)|0)+Math.imul(S,Z)|0,o=o+Math.imul(S,X)|0,n=n+Math.imul(y,Q)|0,i=(i=i+Math.imul(y,tt)|0)+Math.imul(v,Q)|0,o=o+Math.imul(v,tt)|0,n=n+Math.imul(p,rt)|0,i=(i=i+Math.imul(p,nt)|0)+Math.imul(m,rt)|0,o=o+Math.imul(m,nt)|0;var At=(u+(n=n+Math.imul(l,ot)|0)|0)+((8191&(i=(i=i+Math.imul(l,st)|0)+Math.imul(c,ot)|0))<<13)|0;u=((o=o+Math.imul(c,st)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(k,G),i=(i=Math.imul(k,z))+Math.imul(T,G)|0,o=Math.imul(T,z),n=n+Math.imul(C,q)|0,i=(i=i+Math.imul(C,j)|0)+Math.imul(N,q)|0,o=o+Math.imul(N,j)|0,n=n+Math.imul(P,V)|0,i=(i=i+Math.imul(P,J)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,J)|0,n=n+Math.imul(M,Z)|0,i=(i=i+Math.imul(M,X)|0)+Math.imul(E,Z)|0,o=o+Math.imul(E,X)|0,n=n+Math.imul(b,Q)|0,i=(i=i+Math.imul(b,tt)|0)+Math.imul(S,Q)|0,o=o+Math.imul(S,tt)|0,n=n+Math.imul(y,rt)|0,i=(i=i+Math.imul(y,nt)|0)+Math.imul(v,rt)|0,o=o+Math.imul(v,nt)|0,n=n+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0;var Mt=(u+(n=n+Math.imul(l,ht)|0)|0)+((8191&(i=(i=i+Math.imul(l,ut)|0)+Math.imul(c,ht)|0))<<13)|0;u=((o=o+Math.imul(c,ut)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(O,G),i=(i=Math.imul(O,z))+Math.imul(F,G)|0,o=Math.imul(F,z),n=n+Math.imul(k,q)|0,i=(i=i+Math.imul(k,j)|0)+Math.imul(T,q)|0,o=o+Math.imul(T,j)|0,n=n+Math.imul(C,V)|0,i=(i=i+Math.imul(C,J)|0)+Math.imul(N,V)|0,o=o+Math.imul(N,J)|0,n=n+Math.imul(P,Z)|0,i=(i=i+Math.imul(P,X)|0)+Math.imul(x,Z)|0,o=o+Math.imul(x,X)|0,n=n+Math.imul(M,Q)|0,i=(i=i+Math.imul(M,tt)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(b,rt)|0,i=(i=i+Math.imul(b,nt)|0)+Math.imul(S,rt)|0,o=o+Math.imul(S,nt)|0,n=n+Math.imul(y,ot)|0,i=(i=i+Math.imul(y,st)|0)+Math.imul(v,ot)|0,o=o+Math.imul(v,st)|0,n=n+Math.imul(p,ht)|0,i=(i=i+Math.imul(p,ut)|0)+Math.imul(m,ht)|0,o=o+Math.imul(m,ut)|0;var Et=(u+(n=n+Math.imul(l,lt)|0)|0)+((8191&(i=(i=i+Math.imul(l,ct)|0)+Math.imul(c,lt)|0))<<13)|0;u=((o=o+Math.imul(c,ct)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,n=Math.imul(L,G),i=(i=Math.imul(L,z))+Math.imul(U,G)|0,o=Math.imul(U,z),n=n+Math.imul(O,q)|0,i=(i=i+Math.imul(O,j)|0)+Math.imul(F,q)|0,o=o+Math.imul(F,j)|0,n=n+Math.imul(k,V)|0,i=(i=i+Math.imul(k,J)|0)+Math.imul(T,V)|0,o=o+Math.imul(T,J)|0,n=n+Math.imul(C,Z)|0,i=(i=i+Math.imul(C,X)|0)+Math.imul(N,Z)|0,o=o+Math.imul(N,X)|0,n=n+Math.imul(P,Q)|0,i=(i=i+Math.imul(P,tt)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,tt)|0,n=n+Math.imul(M,rt)|0,i=(i=i+Math.imul(M,nt)|0)+Math.imul(E,rt)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(b,ot)|0,i=(i=i+Math.imul(b,st)|0)+Math.imul(S,ot)|0,o=o+Math.imul(S,st)|0,n=n+Math.imul(y,ht)|0,i=(i=i+Math.imul(y,ut)|0)+Math.imul(v,ht)|0,o=o+Math.imul(v,ut)|0,n=n+Math.imul(p,lt)|0,i=(i=i+Math.imul(p,ct)|0)+Math.imul(m,lt)|0,o=o+Math.imul(m,ct)|0;var _t=(u+(n=n+Math.imul(l,pt)|0)|0)+((8191&(i=(i=i+Math.imul(l,mt)|0)+Math.imul(c,pt)|0))<<13)|0;u=((o=o+Math.imul(c,mt)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(L,q),i=(i=Math.imul(L,j))+Math.imul(U,q)|0,o=Math.imul(U,j),n=n+Math.imul(O,V)|0,i=(i=i+Math.imul(O,J)|0)+Math.imul(F,V)|0,o=o+Math.imul(F,J)|0,n=n+Math.imul(k,Z)|0,i=(i=i+Math.imul(k,X)|0)+Math.imul(T,Z)|0,o=o+Math.imul(T,X)|0,n=n+Math.imul(C,Q)|0,i=(i=i+Math.imul(C,tt)|0)+Math.imul(N,Q)|0,o=o+Math.imul(N,tt)|0,n=n+Math.imul(P,rt)|0,i=(i=i+Math.imul(P,nt)|0)+Math.imul(x,rt)|0,o=o+Math.imul(x,nt)|0,n=n+Math.imul(M,ot)|0,i=(i=i+Math.imul(M,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(b,ht)|0,i=(i=i+Math.imul(b,ut)|0)+Math.imul(S,ht)|0,o=o+Math.imul(S,ut)|0,n=n+Math.imul(y,lt)|0,i=(i=i+Math.imul(y,ct)|0)+Math.imul(v,lt)|0,o=o+Math.imul(v,ct)|0;var Pt=(u+(n=n+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;u=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(L,V),i=(i=Math.imul(L,J))+Math.imul(U,V)|0,o=Math.imul(U,J),n=n+Math.imul(O,Z)|0,i=(i=i+Math.imul(O,X)|0)+Math.imul(F,Z)|0,o=o+Math.imul(F,X)|0,n=n+Math.imul(k,Q)|0,i=(i=i+Math.imul(k,tt)|0)+Math.imul(T,Q)|0,o=o+Math.imul(T,tt)|0,n=n+Math.imul(C,rt)|0,i=(i=i+Math.imul(C,nt)|0)+Math.imul(N,rt)|0,o=o+Math.imul(N,nt)|0,n=n+Math.imul(P,ot)|0,i=(i=i+Math.imul(P,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,n=n+Math.imul(M,ht)|0,i=(i=i+Math.imul(M,ut)|0)+Math.imul(E,ht)|0,o=o+Math.imul(E,ut)|0,n=n+Math.imul(b,lt)|0,i=(i=i+Math.imul(b,ct)|0)+Math.imul(S,lt)|0,o=o+Math.imul(S,ct)|0;var xt=(u+(n=n+Math.imul(y,pt)|0)|0)+((8191&(i=(i=i+Math.imul(y,mt)|0)+Math.imul(v,pt)|0))<<13)|0;u=((o=o+Math.imul(v,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(L,Z),i=(i=Math.imul(L,X))+Math.imul(U,Z)|0,o=Math.imul(U,X),n=n+Math.imul(O,Q)|0,i=(i=i+Math.imul(O,tt)|0)+Math.imul(F,Q)|0,o=o+Math.imul(F,tt)|0,n=n+Math.imul(k,rt)|0,i=(i=i+Math.imul(k,nt)|0)+Math.imul(T,rt)|0,o=o+Math.imul(T,nt)|0,n=n+Math.imul(C,ot)|0,i=(i=i+Math.imul(C,st)|0)+Math.imul(N,ot)|0,o=o+Math.imul(N,st)|0,n=n+Math.imul(P,ht)|0,i=(i=i+Math.imul(P,ut)|0)+Math.imul(x,ht)|0,o=o+Math.imul(x,ut)|0,n=n+Math.imul(M,lt)|0,i=(i=i+Math.imul(M,ct)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,ct)|0;var It=(u+(n=n+Math.imul(b,pt)|0)|0)+((8191&(i=(i=i+Math.imul(b,mt)|0)+Math.imul(S,pt)|0))<<13)|0;u=((o=o+Math.imul(S,mt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(L,Q),i=(i=Math.imul(L,tt))+Math.imul(U,Q)|0,o=Math.imul(U,tt),n=n+Math.imul(O,rt)|0,i=(i=i+Math.imul(O,nt)|0)+Math.imul(F,rt)|0,o=o+Math.imul(F,nt)|0,n=n+Math.imul(k,ot)|0,i=(i=i+Math.imul(k,st)|0)+Math.imul(T,ot)|0,o=o+Math.imul(T,st)|0,n=n+Math.imul(C,ht)|0,i=(i=i+Math.imul(C,ut)|0)+Math.imul(N,ht)|0,o=o+Math.imul(N,ut)|0,n=n+Math.imul(P,lt)|0,i=(i=i+Math.imul(P,ct)|0)+Math.imul(x,lt)|0,o=o+Math.imul(x,ct)|0;var Ct=(u+(n=n+Math.imul(M,pt)|0)|0)+((8191&(i=(i=i+Math.imul(M,mt)|0)+Math.imul(E,pt)|0))<<13)|0;u=((o=o+Math.imul(E,mt)|0)+(i>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,n=Math.imul(L,rt),i=(i=Math.imul(L,nt))+Math.imul(U,rt)|0,o=Math.imul(U,nt),n=n+Math.imul(O,ot)|0,i=(i=i+Math.imul(O,st)|0)+Math.imul(F,ot)|0,o=o+Math.imul(F,st)|0,n=n+Math.imul(k,ht)|0,i=(i=i+Math.imul(k,ut)|0)+Math.imul(T,ht)|0,o=o+Math.imul(T,ut)|0,n=n+Math.imul(C,lt)|0,i=(i=i+Math.imul(C,ct)|0)+Math.imul(N,lt)|0,o=o+Math.imul(N,ct)|0;var Nt=(u+(n=n+Math.imul(P,pt)|0)|0)+((8191&(i=(i=i+Math.imul(P,mt)|0)+Math.imul(x,pt)|0))<<13)|0;u=((o=o+Math.imul(x,mt)|0)+(i>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,n=Math.imul(L,ot),i=(i=Math.imul(L,st))+Math.imul(U,ot)|0,o=Math.imul(U,st),n=n+Math.imul(O,ht)|0,i=(i=i+Math.imul(O,ut)|0)+Math.imul(F,ht)|0,o=o+Math.imul(F,ut)|0,n=n+Math.imul(k,lt)|0,i=(i=i+Math.imul(k,ct)|0)+Math.imul(T,lt)|0,o=o+Math.imul(T,ct)|0;var Rt=(u+(n=n+Math.imul(C,pt)|0)|0)+((8191&(i=(i=i+Math.imul(C,mt)|0)+Math.imul(N,pt)|0))<<13)|0;u=((o=o+Math.imul(N,mt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,n=Math.imul(L,ht),i=(i=Math.imul(L,ut))+Math.imul(U,ht)|0,o=Math.imul(U,ut),n=n+Math.imul(O,lt)|0,i=(i=i+Math.imul(O,ct)|0)+Math.imul(F,lt)|0,o=o+Math.imul(F,ct)|0;var kt=(u+(n=n+Math.imul(k,pt)|0)|0)+((8191&(i=(i=i+Math.imul(k,mt)|0)+Math.imul(T,pt)|0))<<13)|0;u=((o=o+Math.imul(T,mt)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(L,lt),i=(i=Math.imul(L,ct))+Math.imul(U,lt)|0,o=Math.imul(U,ct);var Tt=(u+(n=n+Math.imul(O,pt)|0)|0)+((8191&(i=(i=i+Math.imul(O,mt)|0)+Math.imul(F,pt)|0))<<13)|0;u=((o=o+Math.imul(F,mt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863;var Dt=(u+(n=Math.imul(L,pt))|0)+((8191&(i=(i=Math.imul(L,mt))+Math.imul(U,pt)|0))<<13)|0;return u=((o=Math.imul(U,mt))+(i>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,h[0]=gt,h[1]=yt,h[2]=vt,h[3]=wt,h[4]=bt,h[5]=St,h[6]=At,h[7]=Mt,h[8]=Et,h[9]=_t,h[10]=Pt,h[11]=xt,h[12]=It,h[13]=Ct,h[14]=Nt,h[15]=Rt,h[16]=kt,h[17]=Tt,h[18]=Dt,0!==u&&(h[19]=u,r.length++),r};function y(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var n=0,i=0,o=0;o<r.length-1;o++){var s=i;i=0;for(var a=67108863&n,h=Math.min(o,e.length-1),u=Math.max(0,o-t.length+1);u<=h;u++){var f=o-u,l=(0|t.words[f])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),i+=(s=(s=s+(l/67108864|0)|0)+(c>>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r._strip()}function v(t,e,r){return y(t,e,r)}Math.imul||(g=m),i.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?g(this,t,e):r<63?m(this,t,e):r<1024?y(this,t,e):v(this,t,e)},i.prototype.mul=function(t){var e=new i(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},i.prototype.mulf=function(t){var e=new i(null);return e.words=new Array(this.length+t.length),v(this,t,e)},i.prototype.imul=function(t){return this.clone().mulTo(t,this)},i.prototype.imuln=function(t){var e=t<0;e&&(t=-t),r("number"==typeof t),r(t<67108864);for(var n=0,i=0;i<this.length;i++){var o=(0|this.words[i])*t,s=(67108863&o)+(67108863&n);n>>=26,n+=o/67108864|0,n+=s>>>26,this.words[i]=67108863&s}return 0!==n&&(this.words[i]=n,this.length++),e?this.ineg():this},i.prototype.muln=function(t){return this.clone().imuln(t)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var n=r/26|0,i=r%26;e[r]=t.words[n]>>>i&1}return e}(t);if(0===e.length)return new i(1);for(var r=this,n=0;n<e.length&&0===e[n];n++,r=r.sqr());if(++n<e.length)for(var o=r.sqr();n<e.length;n++,o=o.sqr())0!==e[n]&&(r=r.mul(o));return r},i.prototype.iushln=function(t){r("number"==typeof t&&t>=0);var e,n=t%26,i=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,h=(0|this.words[e])-a<<n;this.words[e]=h|s,s=a>>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e<i;e++)this.words[e]=0;this.length+=i}return this._strip()},i.prototype.ishln=function(t){return r(0===this.negative),this.iushln(t)},i.prototype.iushrn=function(t,e,n){var i;r("number"==typeof t&&t>=0),i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,h=n;if(i-=s,i=Math.max(0,i),h){for(var u=0;u<s;u++)h.words[u]=this.words[u];h.length=s}if(0===s);else if(this.length>s)for(this.length-=s,u=0;u<this.length;u++)this.words[u]=this.words[u+s];else this.words[0]=0,this.length=1;var f=0;for(u=this.length-1;u>=0&&(0!==f||u>=i);u--){var l=0|this.words[u];this.words[u]=f<<26-o|l>>>o,f=l&a}return h&&0!==f&&(h.words[h.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},i.prototype.ishrn=function(t,e,n){return r(0===this.negative),this.iushrn(t,e,n)},i.prototype.shln=function(t){return this.clone().ishln(t)},i.prototype.ushln=function(t){return this.clone().iushln(t)},i.prototype.shrn=function(t){return this.clone().ishrn(t)},i.prototype.ushrn=function(t){return this.clone().iushrn(t)},i.prototype.testn=function(t){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,i=1<<e;return!(this.length<=n||!(this.words[n]&i))},i.prototype.imaskn=function(t){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var i=67108863^67108863>>>e<<e;this.words[this.length-1]&=i}return this._strip()},i.prototype.maskn=function(t){return this.clone().imaskn(t)},i.prototype.iaddn=function(t){return r("number"==typeof t),r(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<=t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},i.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},i.prototype.isubn=function(t){if(r("number"==typeof t),r(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},i.prototype.addn=function(t){return this.clone().iaddn(t)},i.prototype.subn=function(t){return this.clone().isubn(t)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(t,e,n){var i,o,s=t.length+n;this._expand(s);var a=0;for(i=0;i<t.length;i++){o=(0|this.words[i+n])+a;var h=(0|t.words[i])*e;a=((o-=67108863&h)>>26)-(h/67108864|0),this.words[i+n]=67108863&o}for(;i<this.length-n;i++)a=(o=(0|this.words[i+n])+a)>>26,this.words[i+n]=67108863&o;if(0===a)return this._strip();for(r(-1===a),a=0,i=0;i<this.length;i++)a=(o=-(0|this.words[i])+a)>>26,this.words[i]=67108863&o;return this.negative=1,this._strip()},i.prototype._wordDiv=function(t,e){var r=(this.length,t.length),n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(r=26-this._countBits(s))&&(o=o.ushln(r),n.iushln(r),s=0|o.words[o.length-1]);var a,h=n.length-o.length;if("mod"!==e){(a=new i(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var f=n.clone()._ishlnsubmul(o,1,h);0===f.negative&&(n=f,a&&(a.words[h]=1));for(var l=h-1;l>=0;l--){var c=67108864*(0|n.words[o.length+l])+(0|n.words[o.length+l-1]);for(c=Math.min(c/s|0,67108863),n._ishlnsubmul(o,c,l);0!==n.negative;)c--,n.negative=0,n._ishlnsubmul(o,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=c)}return a&&a._strip(),n._strip(),"div"!==e&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},i.prototype.divmod=function(t,e,n){return r(!t.isZero()),this.isZero()?{div:new i(0),mod:new i(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(o=a.div.neg()),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(o=a.div.neg()),{div:o,mod:a.mod}):this.negative&t.negative?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new i(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new i(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new i(this.modrn(t.words[0]))}:this._wordDiv(t,e);var o,s,a},i.prototype.div=function(t){return this.divmod(t,"div",!1).div},i.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},i.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},i.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),i=t.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},i.prototype.modrn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var n=(1<<26)%t,i=0,o=this.length-1;o>=0;o--)i=(n*i+(0|this.words[o]))%t;return e?-i:i},i.prototype.modn=function(t){return this.modrn(t)},i.prototype.idivn=function(t){var e=t<0;e&&(t=-t),r(t<=67108863);for(var n=0,i=this.length-1;i>=0;i--){var o=(0|this.words[i])+67108864*n;this.words[i]=o/t|0,n=o%t}return this._strip(),e?this.ineg():this},i.prototype.divn=function(t){return this.clone().idivn(t)},i.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o=new i(1),s=new i(0),a=new i(0),h=new i(1),u=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++u;for(var f=n.clone(),l=e.clone();!e.isZero();){for(var c=0,d=1;!(e.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(e.iushrn(c);c-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(f),s.isub(l)),o.iushrn(1),s.iushrn(1);for(var p=0,m=1;!(n.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(f),h.isub(l)),a.iushrn(1),h.iushrn(1);e.cmp(n)>=0?(e.isub(n),o.isub(a),s.isub(h)):(n.isub(e),a.isub(o),h.isub(s))}return{a:a,b:h,gcd:n.iushln(u)}},i.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o,s=new i(1),a=new i(0),h=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var u=0,f=1;!(e.words[0]&f)&&u<26;++u,f<<=1);if(u>0)for(e.iushrn(u);u-- >0;)s.isOdd()&&s.iadd(h),s.iushrn(1);for(var l=0,c=1;!(n.words[0]&c)&&l<26;++l,c<<=1);if(l>0)for(n.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(a)):(n.isub(e),a.isub(s))}return(o=0===e.cmpn(1)?s:a).cmpn(0)<0&&o.iadd(t),o},i.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var n=0;e.isEven()&&r.isEven();n++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=e.cmp(r);if(i<0){var o=e;e=r,r=o}else if(0===i||0===r.cmpn(1))break;e.isub(r)}return r.iushln(n)},i.prototype.invm=function(t){return this.egcd(t).a.umod(t)},i.prototype.isEven=function(){return!(1&this.words[0])},i.prototype.isOdd=function(){return!(1&~this.words[0])},i.prototype.andln=function(t){return this.words[0]&t},i.prototype.bincn=function(t){r("number"==typeof t);var e=t%26,n=(t-e)/26,i=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=i,this;for(var o=i,s=n;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}return 0!==o&&(this.words[s]=o,this.length++),this},i.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},i.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)e=1;else{n&&(t=-t),r(t<=67108863,"Number is too big");var i=0|this.words[0];e=i===t?0:i<t?-1:1}return 0!==this.negative?0|-e:e},i.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},i.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],i=0|t.words[r];if(n!==i){n<i?e=-1:n>i&&(e=1);break}}return e},i.prototype.gtn=function(t){return 1===this.cmpn(t)},i.prototype.gt=function(t){return 1===this.cmp(t)},i.prototype.gten=function(t){return this.cmpn(t)>=0},i.prototype.gte=function(t){return this.cmp(t)>=0},i.prototype.ltn=function(t){return-1===this.cmpn(t)},i.prototype.lt=function(t){return-1===this.cmp(t)},i.prototype.lten=function(t){return this.cmpn(t)<=0},i.prototype.lte=function(t){return this.cmp(t)<=0},i.prototype.eqn=function(t){return 0===this.cmpn(t)},i.prototype.eq=function(t){return 0===this.cmp(t)},i.red=function(t){return new _(t)},i.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},i.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(t){return this.red=t,this},i.prototype.forceRed=function(t){return r(!this.red,"Already a number in reduction context"),this._forceRed(t)},i.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},i.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},i.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},i.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},i.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},i.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},i.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},i.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function b(t,e){this.name=t,this.p=new i(e,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function S(){b.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function A(){b.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function M(){b.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function E(){b.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var e=i._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function P(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}b.prototype._tmp=function(){var t=new i(null);return t.words=new Array(Math.ceil(this.n/13)),t},b.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},b.prototype.split=function(t,e){t.iushrn(this.n,0,e)},b.prototype.imulK=function(t){return t.imul(this.k)},n(S,b),S.prototype.split=function(t,e){for(var r=4194303,n=Math.min(t.length,9),i=0;i<n;i++)e.words[i]=t.words[i];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&r,i=10;i<t.length;i++){var s=0|t.words[i];t.words[i-10]=(s&r)<<4|o>>>22,o=s}o>>>=22,t.words[i-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},S.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var n=0|t.words[r];e+=977*n,t.words[r]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(A,b),n(M,b),n(E,b),E.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var n=19*(0|t.words[r])+e,i=67108863&n;n>>>=26,t.words[r]=i,e=n}return 0!==e&&(t.words[t.length++]=e),t},i._prime=function(t){if(w[t])return w[t];var e;if("k256"===t)e=new S;else if("p224"===t)e=new A;else if("p192"===t)e=new M;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new E}return w[t]=e,e},_.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},_.prototype._verify2=function(t,e){r(!(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},_.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(f(t,t.umod(this.m)._forceRed(this)),t)},_.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},_.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},_.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},_.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},_.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},_.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},_.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},_.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},_.prototype.isqr=function(t){return this.imul(t,t.clone())},_.prototype.sqr=function(t){return this.mul(t,t)},_.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var n=this.m.add(new i(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);r(!o.isZero());var a=new i(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),f=this.m.bitLength();for(f=new i(2*f*f).toRed(this);0!==this.pow(f,u).cmp(h);)f.redIAdd(h);for(var l=this.pow(f,o),c=this.pow(t,o.addn(1).iushrn(1)),d=this.pow(t,o),p=s;0!==d.cmp(a);){for(var m=d,g=0;0!==m.cmp(a);g++)m=m.redSqr();r(g<p);var y=this.pow(l,new i(1).iushln(p-g-1));c=c.redMul(y),l=y.redSqr(),d=d.redMul(l),p=g}return c},_.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},_.prototype.pow=function(t,e){if(e.isZero())return new i(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new i(1).toRed(this),r[1]=t;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],t);var o=r[0],s=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),n=e.length-1;n>=0;n--){for(var u=e.words[n],f=h-1;f>=0;f--){var l=u>>f&1;o!==r[0]&&(o=this.sqr(o)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===f)&&(o=this.mul(o,r[s]),a=0,s=0)):a=0}h=26}return o},_.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},_.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},i.mont=function(t){return new P(t)},n(P,_),P.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},P.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},P.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},P.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new i(0)._forceRed(this);var r=t.mul(e),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},P.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(h,o);var f=s(h.exports);let l=!1,c=!1;const d={debug:1,default:2,info:2,warning:3,error:4,off:5};let p=d.default,m=null;const g=function(){try{const t=[];if(["NFD","NFC","NFKD","NFKC"].forEach((e=>{try{if("test"!=="test".normalize(e))throw new Error("bad normalize")}catch(r){t.push(e)}})),t.length)throw new Error("missing "+t.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(t){return t.message}return null}();var y,v;!function(t){t.DEBUG="DEBUG",t.INFO="INFO",t.WARNING="WARNING",t.ERROR="ERROR",t.OFF="OFF"}(y||(y={})),function(t){t.UNKNOWN_ERROR="UNKNOWN_ERROR",t.NOT_IMPLEMENTED="NOT_IMPLEMENTED",t.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",t.NETWORK_ERROR="NETWORK_ERROR",t.SERVER_ERROR="SERVER_ERROR",t.TIMEOUT="TIMEOUT",t.BUFFER_OVERRUN="BUFFER_OVERRUN",t.NUMERIC_FAULT="NUMERIC_FAULT",t.MISSING_NEW="MISSING_NEW",t.INVALID_ARGUMENT="INVALID_ARGUMENT",t.MISSING_ARGUMENT="MISSING_ARGUMENT",t.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",t.CALL_EXCEPTION="CALL_EXCEPTION",t.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",t.NONCE_EXPIRED="NONCE_EXPIRED",t.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",t.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",t.TRANSACTION_REPLACED="TRANSACTION_REPLACED",t.ACTION_REJECTED="ACTION_REJECTED"}(v||(v={}));const w="0123456789abcdef";class b{constructor(t){Object.defineProperty(this,"version",{enumerable:!0,value:t,writable:!1})}_log(t,e){const r=t.toLowerCase();null==d[r]&&this.throwArgumentError("invalid log level name","logLevel",t),p>d[r]||console.log.apply(console,e)}debug(...t){this._log(b.levels.DEBUG,t)}info(...t){this._log(b.levels.INFO,t)}warn(...t){this._log(b.levels.WARNING,t)}makeError(t,e,r){if(c)return this.makeError("censored error",e,{});e||(e=b.errors.UNKNOWN_ERROR),r||(r={});const n=[];Object.keys(r).forEach((t=>{const e=r[t];try{if(e instanceof Uint8Array){let r="";for(let t=0;t<e.length;t++)r+=w[e[t]>>4],r+=w[15&e[t]];n.push(t+"=Uint8Array(0x"+r+")")}else n.push(t+"="+JSON.stringify(e))}catch(e){n.push(t+"="+JSON.stringify(r[t].toString()))}})),n.push(`code=${e}`),n.push(`version=${this.version}`);const i=t;let o="";switch(e){case v.NUMERIC_FAULT:{o="NUMERIC_FAULT";const e=t;switch(e){case"overflow":case"underflow":case"division-by-zero":o+="-"+e;break;case"negative-power":case"negative-width":o+="-unsupported";break;case"unbound-bitwise-result":o+="-unbound-result"}break}case v.CALL_EXCEPTION:case v.INSUFFICIENT_FUNDS:case v.MISSING_NEW:case v.NONCE_EXPIRED:case v.REPLACEMENT_UNDERPRICED:case v.TRANSACTION_REPLACED:case v.UNPREDICTABLE_GAS_LIMIT:o=e}o&&(t+=" [ See: https://links.ethers.org/v5-errors-"+o+" ]"),n.length&&(t+=" ("+n.join(", ")+")");const s=new Error(t);return s.reason=i,s.code=e,Object.keys(r).forEach((function(t){s[t]=r[t]})),s}throwError(t,e,r){throw this.makeError(t,e,r)}throwArgumentError(t,e,r){return this.throwError(t,b.errors.INVALID_ARGUMENT,{argument:e,value:r})}assert(t,e,r,n){t||this.throwError(e,r,n)}assertArgument(t,e,r,n){t||this.throwArgumentError(e,r,n)}checkNormalize(t){g&&this.throwError("platform missing String.prototype.normalize",b.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:g})}checkSafeUint53(t,e){"number"==typeof t&&(null==e&&(e="value not safe"),(t<0||t>=9007199254740991)&&this.throwError(e,b.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:t}),t%1&&this.throwError(e,b.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:t}))}checkArgumentCount(t,e,r){r=r?": "+r:"",t<e&&this.throwError("missing argument"+r,b.errors.MISSING_ARGUMENT,{count:t,expectedCount:e}),t>e&&this.throwError("too many arguments"+r,b.errors.UNEXPECTED_ARGUMENT,{count:t,expectedCount:e})}checkNew(t,e){t!==Object&&null!=t||this.throwError("missing new",b.errors.MISSING_NEW,{name:e.name})}checkAbstract(t,e){t===e?this.throwError("cannot instantiate abstract class "+JSON.stringify(e.name)+" directly; use a sub-class",b.errors.UNSUPPORTED_OPERATION,{name:t.name,operation:"new"}):t!==Object&&null!=t||this.throwError("missing new",b.errors.MISSING_NEW,{name:e.name})}static globalLogger(){return m||(m=new b("logger/5.7.0")),m}static setCensorship(t,e){if(!t&&e&&this.globalLogger().throwError("cannot permanently disable censorship",b.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),l){if(!t)return;this.globalLogger().throwError("error censorship permanent",b.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}c=!!t,l=!!e}static setLogLevel(t){const e=d[t.toLowerCase()];null!=e?p=e:b.globalLogger().warn("invalid log level - "+t)}static from(t){return new b(t)}}b.errors=v,b.levels=y;const S=new b("bytes/5.7.0");function A(t){return!!t.toHexString}function M(t){return t.slice||(t.slice=function(){const e=Array.prototype.slice.call(arguments);return M(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}function E(t){return N(t)&&!(t.length%2)||P(t)}function _(t){return"number"==typeof t&&t==t&&t%1==0}function P(t){if(null==t)return!1;if(t.constructor===Uint8Array)return!0;if("string"==typeof t)return!1;if(!_(t.length)||t.length<0)return!1;for(let e=0;e<t.length;e++){const r=t[e];if(!_(r)||r<0||r>=256)return!1}return!0}function x(t,e){if(e||(e={}),"number"==typeof t){S.checkSafeUint53(t,"invalid arrayify value");const e=[];for(;t;)e.unshift(255&t),t=parseInt(String(t/256));return 0===e.length&&e.push(0),M(new Uint8Array(e))}if(e.allowMissingPrefix&&"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),A(t)&&(t=t.toHexString()),N(t)){let r=t.substring(2);r.length%2&&("left"===e.hexPad?r="0"+r:"right"===e.hexPad?r+="0":S.throwArgumentError("hex data is odd-length","value",t));const n=[];for(let t=0;t<r.length;t+=2)n.push(parseInt(r.substring(t,t+2),16));return M(new Uint8Array(n))}return P(t)?M(new Uint8Array(t)):S.throwArgumentError("invalid arrayify value","value",t)}function I(t){const e=t.map((t=>x(t))),r=e.reduce(((t,e)=>t+e.length),0),n=new Uint8Array(r);return e.reduce(((t,e)=>(n.set(e,t),t+e.length)),0),M(n)}function C(t){let e=x(t);if(0===e.length)return e;let r=0;for(;r<e.length&&0===e[r];)r++;return r&&(e=e.slice(r)),e}function N(t,e){return!("string"!=typeof t||!t.match(/^0x[0-9A-Fa-f]*$/))&&(!e||t.length===2+2*e)}const R="0123456789abcdef";function k(t,e){if(e||(e={}),"number"==typeof t){S.checkSafeUint53(t,"invalid hexlify value");let e="";for(;t;)e=R[15&t]+e,t=Math.floor(t/16);return e.length?(e.length%2&&(e="0"+e),"0x"+e):"0x00"}if("bigint"==typeof t)return(t=t.toString(16)).length%2?"0x0"+t:"0x"+t;if(e.allowMissingPrefix&&"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),A(t))return t.toHexString();if(N(t))return t.length%2&&("left"===e.hexPad?t="0x0"+t.substring(2):"right"===e.hexPad?t+="0":S.throwArgumentError("hex data is odd-length","value",t)),t.toLowerCase();if(P(t)){let e="0x";for(let r=0;r<t.length;r++){let n=t[r];e+=R[(240&n)>>4]+R[15&n]}return e}return S.throwArgumentError("invalid hexlify value","value",t)}function T(t){if("string"!=typeof t)t=k(t);else if(!N(t)||t.length%2)return null;return(t.length-2)/2}function D(t,e,r){return"string"!=typeof t?t=k(t):(!N(t)||t.length%2)&&S.throwArgumentError("invalid hexData","value",t),e=2+2*e,null!=r?"0x"+t.substring(e,2+2*r):"0x"+t.substring(e)}function O(t){let e="0x";return t.forEach((t=>{e+=k(t).substring(2)})),e}function F(t,e){for("string"!=typeof t?t=k(t):N(t)||S.throwArgumentError("invalid hex string","value",t),t.length>2*e+2&&S.throwArgumentError("value out of range","value",arguments[1]);t.length<2*e+2;)t="0x0"+t.substring(2);return t}function B(t){const e={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(E(t)){let r=x(t);64===r.length?(e.v=27+(r[32]>>7),r[32]&=127,e.r=k(r.slice(0,32)),e.s=k(r.slice(32,64))):65===r.length?(e.r=k(r.slice(0,32)),e.s=k(r.slice(32,64)),e.v=r[64]):S.throwArgumentError("invalid signature string","signature",t),e.v<27&&(0===e.v||1===e.v?e.v+=27:S.throwArgumentError("signature invalid v byte","signature",t)),e.recoveryParam=1-e.v%2,e.recoveryParam&&(r[32]|=128),e._vs=k(r.slice(32,64))}else{if(e.r=t.r,e.s=t.s,e.v=t.v,e.recoveryParam=t.recoveryParam,e._vs=t._vs,null!=e._vs){const r=function(t,e){(t=x(t)).length>e&&S.throwArgumentError("value out of range","value",arguments[0]);const r=new Uint8Array(e);return r.set(t,e-t.length),M(r)}(x(e._vs),32);e._vs=k(r);const n=r[0]>=128?1:0;null==e.recoveryParam?e.recoveryParam=n:e.recoveryParam!==n&&S.throwArgumentError("signature recoveryParam mismatch _vs","signature",t),r[0]&=127;const i=k(r);null==e.s?e.s=i:e.s!==i&&S.throwArgumentError("signature v mismatch _vs","signature",t)}if(null==e.recoveryParam)null==e.v?S.throwArgumentError("signature missing v and recoveryParam","signature",t):0===e.v||1===e.v?e.recoveryParam=e.v:e.recoveryParam=1-e.v%2;else if(null==e.v)e.v=27+e.recoveryParam;else{const r=0===e.v||1===e.v?e.v:1-e.v%2;e.recoveryParam!==r&&S.throwArgumentError("signature recoveryParam mismatch v","signature",t)}null!=e.r&&N(e.r)?e.r=F(e.r,32):S.throwArgumentError("signature missing or invalid r","signature",t),null!=e.s&&N(e.s)?e.s=F(e.s,32):S.throwArgumentError("signature missing or invalid s","signature",t);const r=x(e.s);r[0]>=128&&S.throwArgumentError("signature s out of range","signature",t),e.recoveryParam&&(r[0]|=128);const n=k(r);e._vs&&(N(e._vs)||S.throwArgumentError("signature invalid _vs","signature",t),e._vs=F(e._vs,32)),null==e._vs?e._vs=n:e._vs!==n&&S.throwArgumentError("signature _vs mismatch v and s","signature",t)}return e.yParityAndS=e._vs,e.compact=e.r+e.yParityAndS.substring(2),e}function L(t){return k(I([(t=B(t)).r,t.s,t.recoveryParam?"0x1c":"0x1b"]))}var U=f.BN;const K=new b("bignumber/5.7.0"),G={},z=9007199254740991;let H=!1;class q{constructor(t,e){t!==G&&K.throwError("cannot call constructor directly; use BigNumber.from",b.errors.UNSUPPORTED_OPERATION,{operation:"new (BigNumber)"}),this._hex=e,this._isBigNumber=!0,Object.freeze(this)}fromTwos(t){return W(V(this).fromTwos(t))}toTwos(t){return W(V(this).toTwos(t))}abs(){return"-"===this._hex[0]?q.from(this._hex.substring(1)):this}add(t){return W(V(this).add(V(t)))}sub(t){return W(V(this).sub(V(t)))}div(t){return q.from(t).isZero()&&J("division-by-zero","div"),W(V(this).div(V(t)))}mul(t){return W(V(this).mul(V(t)))}mod(t){const e=V(t);return e.isNeg()&&J("division-by-zero","mod"),W(V(this).umod(e))}pow(t){const e=V(t);return e.isNeg()&&J("negative-power","pow"),W(V(this).pow(e))}and(t){const e=V(t);return(this.isNegative()||e.isNeg())&&J("unbound-bitwise-result","and"),W(V(this).and(e))}or(t){const e=V(t);return(this.isNegative()||e.isNeg())&&J("unbound-bitwise-result","or"),W(V(this).or(e))}xor(t){const e=V(t);return(this.isNegative()||e.isNeg())&&J("unbound-bitwise-result","xor"),W(V(this).xor(e))}mask(t){return(this.isNegative()||t<0)&&J("negative-width","mask"),W(V(this).maskn(t))}shl(t){return(this.isNegative()||t<0)&&J("negative-width","shl"),W(V(this).shln(t))}shr(t){return(this.isNegative()||t<0)&&J("negative-width","shr"),W(V(this).shrn(t))}eq(t){return V(this).eq(V(t))}lt(t){return V(this).lt(V(t))}lte(t){return V(this).lte(V(t))}gt(t){return V(this).gt(V(t))}gte(t){return V(this).gte(V(t))}isNegative(){return"-"===this._hex[0]}isZero(){return V(this).isZero()}toNumber(){try{return V(this).toNumber()}catch(t){J("overflow","toNumber",this.toString())}return null}toBigInt(){try{return BigInt(this.toString())}catch(t){}return K.throwError("this platform does not support BigInt",b.errors.UNSUPPORTED_OPERATION,{value:this.toString()})}toString(){return arguments.length>0&&(10===arguments[0]?H||(H=!0,K.warn("BigNumber.toString does not accept any parameters; base-10 is assumed")):16===arguments[0]?K.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()",b.errors.UNEXPECTED_ARGUMENT,{}):K.throwError("BigNumber.toString does not accept parameters",b.errors.UNEXPECTED_ARGUMENT,{})),V(this).toString(10)}toHexString(){return this._hex}toJSON(t){return{type:"BigNumber",hex:this.toHexString()}}static from(t){if(t instanceof q)return t;if("string"==typeof t)return t.match(/^-?0x[0-9a-f]+$/i)?new q(G,j(t)):t.match(/^-?[0-9]+$/)?new q(G,j(new U(t))):K.throwArgumentError("invalid BigNumber string","value",t);if("number"==typeof t)return t%1&&J("underflow","BigNumber.from",t),(t>=z||t<=-z)&&J("overflow","BigNumber.from",t),q.from(String(t));const e=t;if("bigint"==typeof e)return q.from(e.toString());if(P(e))return q.from(k(e));if(e)if(e.toHexString){const t=e.toHexString();if("string"==typeof t)return q.from(t)}else{let t=e._hex;if(null==t&&"BigNumber"===e.type&&(t=e.hex),"string"==typeof t&&(N(t)||"-"===t[0]&&N(t.substring(1))))return q.from(t)}return K.throwArgumentError("invalid BigNumber value","value",t)}static isBigNumber(t){return!(!t||!t._isBigNumber)}}function j(t){if("string"!=typeof t)return j(t.toString(16));if("-"===t[0])return"-"===(t=t.substring(1))[0]&&K.throwArgumentError("invalid hex","value",t),"0x00"===(t=j(t))?t:"-"+t;if("0x"!==t.substring(0,2)&&(t="0x"+t),"0x"===t)return"0x00";for(t.length%2&&(t="0x0"+t.substring(2));t.length>4&&"0x00"===t.substring(0,4);)t="0x"+t.substring(4);return t}function W(t){return q.from(j(t))}function V(t){const e=q.from(t).toHexString();return"-"===e[0]?new U("-"+e.substring(3),16):new U(e.substring(2),16)}function J(t,e,r){const n={fault:t,operation:e};return null!=r&&(n.value=r),K.throwError(t,b.errors.NUMERIC_FAULT,n)}var $=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))};const Z=new b("properties/5.7.0");function X(t,e,r){Object.defineProperty(t,e,{enumerable:!0,value:r,writable:!1})}function Y(t){return $(this,void 0,void 0,(function*(){const e=Object.keys(t).map((e=>{const r=t[e];return Promise.resolve(r).then((t=>({key:e,value:t})))}));return(yield Promise.all(e)).reduce(((t,e)=>(t[e.key]=e.value,t)),{})}))}function Q(t){const e={};for(const r in t)e[r]=t[r];return e}const tt={bigint:!0,boolean:!0,function:!0,number:!0,string:!0};function et(t){if(null==t||tt[typeof t])return!0;if(Array.isArray(t)||"object"==typeof t){if(!Object.isFrozen(t))return!1;const e=Object.keys(t);for(let r=0;r<e.length;r++){let n=null;try{n=t[e[r]]}catch(t){continue}if(!et(n))return!1}return!0}return Z.throwArgumentError("Cannot deepCopy "+typeof t,"object",t)}function rt(t){if(et(t))return t;if(Array.isArray(t))return Object.freeze(t.map((t=>nt(t))));if("object"==typeof t){const e={};for(const r in t){const n=t[r];void 0!==n&&X(e,r,nt(n))}return e}return Z.throwArgumentError("Cannot deepCopy "+typeof t,"object",t)}function nt(t){return rt(t)}class it{constructor(t){for(const e in t)this[e]=nt(t[e])}}var ot,st={exports:{}};
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
*/ot=st,function(){var t="input is invalid type",e="object"==typeof window,r=e?window:{};r.JS_SHA3_NO_WINDOW&&(e=!1);var n=!e&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?r=o:n&&(r=self);var i=!r.JS_SHA3_NO_COMMON_JS&&ot.exports,s=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,a="0123456789abcdef".split(""),h=[4,1024,262144,67108864],u=[0,8,16,24],f=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],l=[224,256,384,512],c=[128,256],d=["hex","buffer","arrayBuffer","array","digest"],p={128:168,256:136};!r.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!s||!r.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});for(var m=function(t,e,r){return function(n){return new N(t,e,t).update(n)[r]()}},g=function(t,e,r){return function(n,i){return new N(t,e,i).update(n)[r]()}},y=function(t,e,r){return function(e,n,i,o){return A["cshake"+t].update(e,n,i,o)[r]()}},v=function(t,e,r){return function(e,n,i,o){return A["kmac"+t].update(e,n,i,o)[r]()}},w=function(t,e,r,n){for(var i=0;i<d.length;++i){var o=d[i];t[o]=e(r,n,o)}return t},b=function(t,e){var r=m(t,e,"hex");return r.create=function(){return new N(t,e,t)},r.update=function(t){return r.create().update(t)},w(r,m,t,e)},S=[{name:"keccak",padding:[1,256,65536,16777216],bits:l,createMethod:b},{name:"sha3",padding:[6,1536,393216,100663296],bits:l,createMethod:b},{name:"shake",padding:[31,7936,2031616,520093696],bits:c,createMethod:function(t,e){var r=g(t,e,"hex");return r.create=function(r){return new N(t,e,r)},r.update=function(t,e){return r.create(e).update(t)},w(r,g,t,e)}},{name:"cshake",padding:h,bits:c,createMethod:function(t,e){var r=p[t],n=y(t,0,"hex");return n.create=function(n,i,o){return i||o?new N(t,e,n).bytepad([i,o],r):A["shake"+t].create(n)},n.update=function(t,e,r,i){return n.create(e,r,i).update(t)},w(n,y,t,e)}},{name:"kmac",padding:h,bits:c,createMethod:function(t,e){var r=p[t],n=v(t,0,"hex");return n.create=function(n,i,o){return new R(t,e,i).bytepad(["KMAC",o],r).bytepad([n],r)},n.update=function(t,e,r,i){return n.create(t,r,i).update(e)},w(n,v,t,e)}}],A={},M=[],E=0;E<S.length;++E)for(var _=S[E],P=_.bits,x=0;x<P.length;++x){var I=_.name+"_"+P[x];if(M.push(I),A[I]=_.createMethod(P[x],_.padding),"sha3"!==_.name){var C=_.name+P[x];M.push(C),A[C]=A[I]}}function N(t,e,r){this.blocks=[],this.s=[],this.padding=e,this.outputBits=r,this.reset=!0,this.finalized=!1,this.block=0,this.start=0,this.blockCount=1600-(t<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=r>>5,this.extraBytes=(31&r)>>3;for(var n=0;n<50;++n)this.s[n]=0}function R(t,e,r){N.call(this,t,e,r)}N.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var r,n=typeof e;if("string"!==n){if("object"!==n)throw new Error(t);if(null===e)throw new Error(t);if(s&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||s&&ArrayBuffer.isView(e)))throw new Error(t);r=!0}for(var i,o,a=this.blocks,h=this.byteCount,f=e.length,l=this.blockCount,c=0,d=this.s;c<f;){if(this.reset)for(this.reset=!1,a[0]=this.block,i=1;i<l+1;++i)a[i]=0;if(r)for(i=this.start;c<f&&i<h;++c)a[i>>2]|=e[c]<<u[3&i++];else for(i=this.start;c<f&&i<h;++c)(o=e.charCodeAt(c))<128?a[i>>2]|=o<<u[3&i++]:o<2048?(a[i>>2]|=(192|o>>6)<<u[3&i++],a[i>>2]|=(128|63&o)<<u[3&i++]):o<55296||o>=57344?(a[i>>2]|=(224|o>>12)<<u[3&i++],a[i>>2]|=(128|o>>6&63)<<u[3&i++],a[i>>2]|=(128|63&o)<<u[3&i++]):(o=65536+((1023&o)<<10|1023&e.charCodeAt(++c)),a[i>>2]|=(240|o>>18)<<u[3&i++],a[i>>2]|=(128|o>>12&63)<<u[3&i++],a[i>>2]|=(128|o>>6&63)<<u[3&i++],a[i>>2]|=(128|63&o)<<u[3&i++]);if(this.lastByteIndex=i,i>=h){for(this.start=i-h,this.block=a[l],i=0;i<l;++i)d[i]^=a[i];k(d),this.reset=!0}else this.start=i}return this},N.prototype.encode=function(t,e){var r=255&t,n=1,i=[r];for(r=255&(t>>=8);r>0;)i.unshift(r),r=255&(t>>=8),++n;return e?i.push(n):i.unshift(n),this.update(i),i.length},N.prototype.encodeString=function(e){var r,n=typeof e;if("string"!==n){if("object"!==n)throw new Error(t);if(null===e)throw new Error(t);if(s&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||s&&ArrayBuffer.isView(e)))throw new Error(t);r=!0}var i=0,o=e.length;if(r)i=o;else for(var a=0;a<e.length;++a){var h=e.charCodeAt(a);h<128?i+=1:h<2048?i+=2:h<55296||h>=57344?i+=3:(h=65536+((1023&h)<<10|1023&e.charCodeAt(++a)),i+=4)}return i+=this.encode(8*i),this.update(e),i},N.prototype.bytepad=function(t,e){for(var r=this.encode(e),n=0;n<t.length;++n)r+=this.encodeString(t[n]);var i=e-r%e,o=[];return o.length=i,this.update(o),this},N.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,r=this.blockCount,n=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[r],e=1;e<r+1;++e)t[e]=0;for(t[r-1]|=2147483648,e=0;e<r;++e)n[e]^=t[e];k(n)}},N.prototype.toString=N.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,s=0,h="";s<n;){for(o=0;o<e&&s<n;++o,++s)t=r[o],h+=a[t>>4&15]+a[15&t]+a[t>>12&15]+a[t>>8&15]+a[t>>20&15]+a[t>>16&15]+a[t>>28&15]+a[t>>24&15];s%e==0&&(k(r),o=0)}return i&&(t=r[o],h+=a[t>>4&15]+a[15&t],i>1&&(h+=a[t>>12&15]+a[t>>8&15]),i>2&&(h+=a[t>>20&15]+a[t>>16&15])),h},N.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,r=this.s,n=this.outputBlocks,i=this.extraBytes,o=0,s=0,a=this.outputBits>>3;t=i?new ArrayBuffer(n+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);s<n;){for(o=0;o<e&&s<n;++o,++s)h[s]=r[o];s%e==0&&k(r)}return i&&(h[o]=r[o],t=t.slice(0,a)),t},N.prototype.buffer=N.prototype.arrayBuffer,N.prototype.digest=N.prototype.array=function(){this.finalize();for(var t,e,r=this.blockCount,n=this.s,i=this.outputBlocks,o=this.extraBytes,s=0,a=0,h=[];a<i;){for(s=0;s<r&&a<i;++s,++a)t=a<<2,e=n[s],h[t]=255&e,h[t+1]=e>>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%r==0&&k(n)}return o&&(t=a<<2,e=n[s],h[t]=255&e,o>1&&(h[t+1]=e>>8&255),o>2&&(h[t+2]=e>>16&255)),h},R.prototype=new N,R.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var k=function(t){var e,r,n,i,o,s,a,h,u,l,c,d,p,m,g,y,v,w,b,S,A,M,E,_,P,x,I,C,N,R,k,T,D,O,F,B,L,U,K,G,z,H,q,j,W,V,J,$,Z,X,Y,Q,tt,et,rt,nt,it,ot,st,at,ht,ut,ft;for(n=0;n<48;n+=2)i=t[0]^t[10]^t[20]^t[30]^t[40],o=t[1]^t[11]^t[21]^t[31]^t[41],s=t[2]^t[12]^t[22]^t[32]^t[42],a=t[3]^t[13]^t[23]^t[33]^t[43],h=t[4]^t[14]^t[24]^t[34]^t[44],u=t[5]^t[15]^t[25]^t[35]^t[45],l=t[6]^t[16]^t[26]^t[36]^t[46],c=t[7]^t[17]^t[27]^t[37]^t[47],e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(s<<1|a>>>31),r=(p=t[9]^t[19]^t[29]^t[39]^t[49])^(a<<1|s>>>31),t[0]^=e,t[1]^=r,t[10]^=e,t[11]^=r,t[20]^=e,t[21]^=r,t[30]^=e,t[31]^=r,t[40]^=e,t[41]^=r,e=i^(h<<1|u>>>31),r=o^(u<<1|h>>>31),t[2]^=e,t[3]^=r,t[12]^=e,t[13]^=r,t[22]^=e,t[23]^=r,t[32]^=e,t[33]^=r,t[42]^=e,t[43]^=r,e=s^(l<<1|c>>>31),r=a^(c<<1|l>>>31),t[4]^=e,t[5]^=r,t[14]^=e,t[15]^=r,t[24]^=e,t[25]^=r,t[34]^=e,t[35]^=r,t[44]^=e,t[45]^=r,e=h^(d<<1|p>>>31),r=u^(p<<1|d>>>31),t[6]^=e,t[7]^=r,t[16]^=e,t[17]^=r,t[26]^=e,t[27]^=r,t[36]^=e,t[37]^=r,t[46]^=e,t[47]^=r,e=l^(i<<1|o>>>31),r=c^(o<<1|i>>>31),t[8]^=e,t[9]^=r,t[18]^=e,t[19]^=r,t[28]^=e,t[29]^=r,t[38]^=e,t[39]^=r,t[48]^=e,t[49]^=r,m=t[0],g=t[1],V=t[11]<<4|t[10]>>>28,J=t[10]<<4|t[11]>>>28,C=t[20]<<3|t[21]>>>29,N=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,H=t[40]<<18|t[41]>>>14,q=t[41]<<18|t[40]>>>14,O=t[2]<<1|t[3]>>>31,F=t[3]<<1|t[2]>>>31,y=t[13]<<12|t[12]>>>20,v=t[12]<<12|t[13]>>>20,$=t[22]<<10|t[23]>>>22,Z=t[23]<<10|t[22]>>>22,R=t[33]<<13|t[32]>>>19,k=t[32]<<13|t[33]>>>19,ut=t[42]<<2|t[43]>>>30,ft=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,rt=t[4]<<30|t[5]>>>2,B=t[14]<<6|t[15]>>>26,L=t[15]<<6|t[14]>>>26,w=t[25]<<11|t[24]>>>21,b=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Y=t[35]<<15|t[34]>>>17,T=t[45]<<29|t[44]>>>3,D=t[44]<<29|t[45]>>>3,_=t[6]<<28|t[7]>>>4,P=t[7]<<28|t[6]>>>4,nt=t[17]<<23|t[16]>>>9,it=t[16]<<23|t[17]>>>9,U=t[26]<<25|t[27]>>>7,K=t[27]<<25|t[26]>>>7,S=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Q=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,j=t[8]<<27|t[9]>>>5,W=t[9]<<27|t[8]>>>5,x=t[18]<<20|t[19]>>>12,I=t[19]<<20|t[18]>>>12,ot=t[29]<<7|t[28]>>>25,st=t[28]<<7|t[29]>>>25,G=t[38]<<8|t[39]>>>24,z=t[39]<<8|t[38]>>>24,M=t[48]<<14|t[49]>>>18,E=t[49]<<14|t[48]>>>18,t[0]=m^~y&w,t[1]=g^~v&b,t[10]=_^~x&C,t[11]=P^~I&N,t[20]=O^~B&U,t[21]=F^~L&K,t[30]=j^~V&$,t[31]=W^~J&Z,t[40]=et^~nt&ot,t[41]=rt^~it&st,t[2]=y^~w&S,t[3]=v^~b&A,t[12]=x^~C&R,t[13]=I^~N&k,t[22]=B^~U&G,t[23]=L^~K&z,t[32]=V^~$&X,t[33]=J^~Z&Y,t[42]=nt^~ot&at,t[43]=it^~st&ht,t[4]=w^~S&M,t[5]=b^~A&E,t[14]=C^~R&T,t[15]=N^~k&D,t[24]=U^~G&H,t[25]=K^~z&q,t[34]=$^~X&Q,t[35]=Z^~Y&tt,t[44]=ot^~at&ut,t[45]=st^~ht&ft,t[6]=S^~M&m,t[7]=A^~E&g,t[16]=R^~T&_,t[17]=k^~D&P,t[26]=G^~H&O,t[27]=z^~q&F,t[36]=X^~Q&j,t[37]=Y^~tt&W,t[46]=at^~ut&et,t[47]=ht^~ft&rt,t[8]=M^~m&y,t[9]=E^~g&v,t[18]=T^~_&x,t[19]=D^~P&I,t[28]=H^~O&B,t[29]=q^~F&L,t[38]=Q^~j&V,t[39]=tt^~W&J,t[48]=ut^~et&nt,t[49]=ft^~rt&it,t[0]^=f[n],t[1]^=f[n+1]};if(i)ot.exports=A;else for(E=0;E<M.length;++E)r[M[E]]=A[M[E]]}();var at=s(st.exports);function ht(t){return"0x"+at.keccak_256(x(t))}const ut=new b("rlp/5.7.0");function ft(t){const e=[];for(;t;)e.unshift(255&t),t>>=8;return e}function lt(t){if(Array.isArray(t)){let e=[];if(t.forEach((function(t){e=e.concat(lt(t))})),e.length<=55)return e.unshift(192+e.length),e;const r=ft(e.length);return r.unshift(247+r.length),r.concat(e)}E(t)||ut.throwArgumentError("RLP object must be BytesLike","object",t);const e=Array.prototype.slice.call(x(t));if(1===e.length&&e[0]<=127)return e;if(e.length<=55)return e.unshift(128+e.length),e;const r=ft(e.length);return r.unshift(183+r.length),r.concat(e)}function ct(t){return k(lt(t))}const dt=new b("address/5.7.0");function pt(t){N(t,20)||dt.throwArgumentError("invalid address","address",t);const e=(t=t.toLowerCase()).substring(2).split(""),r=new Uint8Array(40);for(let t=0;t<40;t++)r[t]=e[t].charCodeAt(0);const n=x(ht(r));for(let t=0;t<40;t+=2)n[t>>1]>>4>=8&&(e[t]=e[t].toUpperCase()),(15&n[t>>1])>=8&&(e[t+1]=e[t+1].toUpperCase());return"0x"+e.join("")}const mt={};for(let t=0;t<10;t++)mt[String(t)]=String(t);for(let t=0;t<26;t++)mt[String.fromCharCode(65+t)]=String(10+t);const gt=Math.floor((yt=9007199254740991,Math.log10?Math.log10(yt):Math.log(yt)/Math.LN10));var yt;function vt(t){let e=null;if("string"!=typeof t&&dt.throwArgumentError("invalid address","address",t),t.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==t.substring(0,2)&&(t="0x"+t),e=pt(t),t.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&e!==t&&dt.throwArgumentError("bad address checksum","address",t);else if(t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(t.substring(2,4)!==function(t){let e=(t=(t=t.toUpperCase()).substring(4)+t.substring(0,2)+"00").split("").map((t=>mt[t])).join("");for(;e.length>=gt;){let t=e.substring(0,gt);e=parseInt(t,10)%97+e.substring(t.length)}let r=String(98-parseInt(e,10)%97);for(;r.length<2;)r="0"+r;return r}(t)&&dt.throwArgumentError("bad icap checksum","address",t),r=t.substring(4),e=new U(r,36).toString(16);e.length<40;)e="0"+e;e=pt("0x"+e)}else dt.throwArgumentError("invalid address","address",t);var r;return e}const wt=new b("strings/5.7.0");var bt,St;function At(t,e=bt.current){e!=bt.current&&(wt.checkNormalize(),t=t.normalize(e));let r=[];for(let e=0;e<t.length;e++){const n=t.charCodeAt(e);if(n<128)r.push(n);else if(n<2048)r.push(n>>6|192),r.push(63&n|128);else if(55296==(64512&n)){e++;const i=t.charCodeAt(e);if(e>=t.length||56320!=(64512&i))throw new Error("invalid utf-8 string");const o=65536+((1023&n)<<10)+(1023&i);r.push(o>>18|240),r.push(o>>12&63|128),r.push(o>>6&63|128),r.push(63&o|128)}else r.push(n>>12|224),r.push(n>>6&63|128),r.push(63&n|128)}return x(r)}function Mt(t){return ht(At(t))}!function(t){t.current="",t.NFC="NFC",t.NFD="NFD",t.NFKC="NFKC",t.NFKD="NFKD"}(bt||(bt={})),function(t){t.UNEXPECTED_CONTINUE="unexpected continuation byte",t.BAD_PREFIX="bad codepoint prefix",t.OVERRUN="string overrun",t.MISSING_CONTINUE="missing continuation byte",t.OUT_OF_RANGE="out of UTF-8 range",t.UTF16_SURROGATE="UTF-16 surrogate",t.OVERLONG="overlong representation"}(St||(St={}));var Et=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))};const _t=new b("hash/5.7.0"),Pt=new Uint8Array(32);Pt.fill(0);const xt=q.from(-1),It=q.from(0),Ct=q.from(1),Nt=q.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");const Rt=F(Ct.toHexString(),32),kt=F(It.toHexString(),32),Tt={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},Dt=["name","version","chainId","verifyingContract","salt"];function Ot(t){return function(e){return"string"!=typeof e&&_t.throwArgumentError(`invalid domain value for ${JSON.stringify(t)}`,`domain.${t}`,e),e}}const Ft={name:Ot("name"),version:Ot("version"),chainId:function(t){try{return q.from(t).toString()}catch(t){}return _t.throwArgumentError('invalid domain value for "chainId"',"domain.chainId",t)},verifyingContract:function(t){try{return vt(t).toLowerCase()}catch(t){}return _t.throwArgumentError('invalid domain value "verifyingContract"',"domain.verifyingContract",t)},salt:function(t){try{const e=x(t);if(32!==e.length)throw new Error("bad length");return k(e)}catch(t){}return _t.throwArgumentError('invalid domain value "salt"',"domain.salt",t)}};function Bt(t){{const e=t.match(/^(u?)int(\d*)$/);if(e){const r=""===e[1],n=parseInt(e[2]||"256");(n%8!=0||n>256||e[2]&&e[2]!==String(n))&&_t.throwArgumentError("invalid numeric width","type",t);const i=Nt.mask(r?n-1:n),o=r?i.add(Ct).mul(xt):It;return function(e){const r=q.from(e);return(r.lt(o)||r.gt(i))&&_t.throwArgumentError(`value out-of-bounds for ${t}`,"value",e),F(r.toTwos(256).toHexString(),32)}}}{const e=t.match(/^bytes(\d+)$/);if(e){const r=parseInt(e[1]);return(0===r||r>32||e[1]!==String(r))&&_t.throwArgumentError("invalid bytes width","type",t),function(e){return x(e).length!==r&&_t.throwArgumentError(`invalid length for ${t}`,"value",e),function(t){const e=x(t),r=e.length%32;return r?O([e,Pt.slice(r)]):k(e)}(e)}}}switch(t){case"address":return function(t){return F(vt(t),32)};case"bool":return function(t){return t?Rt:kt};case"bytes":return function(t){return ht(t)};case"string":return function(t){return Mt(t)}}return null}function Lt(t,e){return`${t}(${e.map((({name:t,type:e})=>e+" "+t)).join(",")})`}class Ut{constructor(t){X(this,"types",Object.freeze(nt(t))),X(this,"_encoderCache",{}),X(this,"_types",{});const e={},r={},n={};Object.keys(t).forEach((t=>{e[t]={},r[t]=[],n[t]={}}));for(const n in t){const i={};t[n].forEach((o=>{i[o.name]&&_t.throwArgumentError(`duplicate variable name ${JSON.stringify(o.name)} in ${JSON.stringify(n)}`,"types",t),i[o.name]=!0;const s=o.type.match(/^([^\x5b]*)(\x5b|$)/)[1];s===n&&_t.throwArgumentError(`circular type reference to ${JSON.stringify(s)}`,"types",t);Bt(s)||(r[s]||_t.throwArgumentError(`unknown type ${JSON.stringify(s)}`,"types",t),r[s].push(n),e[n][s]=!0)}))}const i=Object.keys(r).filter((t=>0===r[t].length));0===i.length?_t.throwArgumentError("missing primary type","types",t):i.length>1&&_t.throwArgumentError(`ambiguous primary types or unused types: ${i.map((t=>JSON.stringify(t))).join(", ")}`,"types",t),X(this,"primaryType",i[0]),function i(o,s){s[o]&&_t.throwArgumentError(`circular type reference to ${JSON.stringify(o)}`,"types",t),s[o]=!0,Object.keys(e[o]).forEach((t=>{r[t]&&(i(t,s),Object.keys(s).forEach((e=>{n[e][t]=!0})))})),delete s[o]}(this.primaryType,{});for(const e in n){const r=Object.keys(n[e]);r.sort(),this._types[e]=Lt(e,t[e])+r.map((e=>Lt(e,t[e]))).join("")}}getEncoder(t){let e=this._encoderCache[t];return e||(e=this._encoderCache[t]=this._getEncoder(t)),e}_getEncoder(t){{const e=Bt(t);if(e)return e}const e=t.match(/^(.*)(\x5b(\d*)\x5d)$/);if(e){const t=e[1],r=this.getEncoder(t),n=parseInt(e[3]);return e=>{n>=0&&e.length!==n&&_t.throwArgumentError("array length mismatch; expected length ${ arrayLength }","value",e);let i=e.map(r);return this._types[t]&&(i=i.map(ht)),ht(O(i))}}const r=this.types[t];if(r){const e=Mt(this._types[t]);return t=>{const n=r.map((({name:e,type:r})=>{const n=this.getEncoder(r)(t[e]);return this._types[r]?ht(n):n}));return n.unshift(e),O(n)}}return _t.throwArgumentError(`unknown type: ${t}`,"type",t)}encodeType(t){const e=this._types[t];return e||_t.throwArgumentError(`unknown type: ${JSON.stringify(t)}`,"name",t),e}encodeData(t,e){return this.getEncoder(t)(e)}hashStruct(t,e){return ht(this.encodeData(t,e))}encode(t){return this.encodeData(this.primaryType,t)}hash(t){return this.hashStruct(this.primaryType,t)}_visit(t,e,r){if(Bt(t))return r(t,e);const n=t.match(/^(.*)(\x5b(\d*)\x5d)$/);if(n){const t=n[1],i=parseInt(n[3]);return i>=0&&e.length!==i&&_t.throwArgumentError("array length mismatch; expected length ${ arrayLength }","value",e),e.map((e=>this._visit(t,e,r)))}const i=this.types[t];return i?i.reduce(((t,{name:n,type:i})=>(t[n]=this._visit(i,e[n],r),t)),{}):_t.throwArgumentError(`unknown type: ${t}`,"type",t)}visit(t,e){return this._visit(this.primaryType,t,e)}static from(t){return new Ut(t)}static getPrimaryType(t){return Ut.from(t).primaryType}static hashStruct(t,e,r){return Ut.from(e).hashStruct(t,r)}static hashDomain(t){const e=[];for(const r in t){const n=Tt[r];n||_t.throwArgumentError(`invalid typed-data domain key: ${JSON.stringify(r)}`,"domain",t),e.push({name:r,type:n})}return e.sort(((t,e)=>Dt.indexOf(t.name)-Dt.indexOf(e.name))),Ut.hashStruct("EIP712Domain",{EIP712Domain:e},t)}static encode(t,e,r){return O(["0x1901",Ut.hashDomain(t),Ut.from(e).hash(r)])}static hash(t,e,r){return ht(Ut.encode(t,e,r))}static resolveNames(t,e,r,n){return Et(this,void 0,void 0,(function*(){t=Q(t);const i={};t.verifyingContract&&!N(t.verifyingContract,20)&&(i[t.verifyingContract]="0x");const o=Ut.from(e);o.visit(r,((t,e)=>("address"!==t||N(e,20)||(i[e]="0x"),e)));for(const t in i)i[t]=yield n(t);return t.verifyingContract&&i[t.verifyingContract]&&(t.verifyingContract=i[t.verifyingContract]),r=o.visit(r,((t,e)=>"address"===t&&i[e]?i[e]:e)),{domain:t,value:r}}))}static getPayload(t,e,r){Ut.hashDomain(t);const n={},i=[];Dt.forEach((e=>{const r=t[e];null!=r&&(n[e]=Ft[e](r),i.push({name:e,type:Tt[e]}))}));const o=Ut.from(e),s=Q(e);return s.EIP712Domain?_t.throwArgumentError("types must not contain EIP712Domain type","types.EIP712Domain",e):s.EIP712Domain=i,o.encode(r),{types:s,domain:n,primaryType:o.primaryType,message:o.visit(r,((t,e)=>{if(t.match(/^bytes(\d*)/))return k(x(e));if(t.match(/^u?int/))return q.from(e).toString();switch(t){case"address":return e.toLowerCase();case"bool":return!!e;case"string":return"string"!=typeof e&&_t.throwArgumentError("invalid string","value",e),e}return _t.throwArgumentError("unsupported type","type",t)}))}}}var Kt=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))};const Gt=new b("abstract-provider/5.7.0");class zt{constructor(){Gt.checkAbstract(new.target,zt),X(this,"_isProvider",!0)}getFeeData(){return Kt(this,void 0,void 0,(function*(){const{block:t,gasPrice:e}=yield Y({block:this.getBlock("latest"),gasPrice:this.getGasPrice().catch((t=>null))});let r=null,n=null,i=null;return t&&t.baseFeePerGas&&(r=t.baseFeePerGas,i=q.from("1500000000"),n=t.baseFeePerGas.mul(2).add(i)),{lastBaseFeePerGas:r,maxFeePerGas:n,maxPriorityFeePerGas:i,gasPrice:e}}))}addListener(t,e){return this.on(t,e)}removeListener(t,e){return this.off(t,e)}static isProvider(t){return!(!t||!t._isProvider)}}var Ht=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))};const qt=new b("abstract-signer/5.7.0"),jt=["accessList","ccipReadEnabled","chainId","customData","data","from","gasLimit","gasPrice","maxFeePerGas","maxPriorityFeePerGas","nonce","to","type","value"],Wt=[b.errors.INSUFFICIENT_FUNDS,b.errors.NONCE_EXPIRED,b.errors.REPLACEMENT_UNDERPRICED];class Vt{constructor(){qt.checkAbstract(new.target,Vt),X(this,"_isSigner",!0)}getBalance(t){return Ht(this,void 0,void 0,(function*(){return this._checkProvider("getBalance"),yield this.provider.getBalance(this.getAddress(),t)}))}getTransactionCount(t){return Ht(this,void 0,void 0,(function*(){return this._checkProvider("getTransactionCount"),yield this.provider.getTransactionCount(this.getAddress(),t)}))}estimateGas(t){return Ht(this,void 0,void 0,(function*(){this._checkProvider("estimateGas");const e=yield Y(this.checkTransaction(t));return yield this.provider.estimateGas(e)}))}call(t,e){return Ht(this,void 0,void 0,(function*(){this._checkProvider("call");const r=yield Y(this.checkTransaction(t));return yield this.provider.call(r,e)}))}sendTransaction(t){return Ht(this,void 0,void 0,(function*(){this._checkProvider("sendTransaction");const e=yield this.populateTransaction(t),r=yield this.signTransaction(e);return yield this.provider.sendTransaction(r)}))}getChainId(){return Ht(this,void 0,void 0,(function*(){this._checkProvider("getChainId");return(yield this.provider.getNetwork()).chainId}))}getGasPrice(){return Ht(this,void 0,void 0,(function*(){return this._checkProvider("getGasPrice"),yield this.provider.getGasPrice()}))}getFeeData(){return Ht(this,void 0,void 0,(function*(){return this._checkProvider("getFeeData"),yield this.provider.getFeeData()}))}resolveName(t){return Ht(this,void 0,void 0,(function*(){return this._checkProvider("resolveName"),yield this.provider.resolveName(t)}))}checkTransaction(t){for(const e in t)-1===jt.indexOf(e)&&qt.throwArgumentError("invalid transaction key: "+e,"transaction",t);const e=Q(t);return null==e.from?e.from=this.getAddress():e.from=Promise.all([Promise.resolve(e.from),this.getAddress()]).then((e=>(e[0].toLowerCase()!==e[1].toLowerCase()&&qt.throwArgumentError("from address mismatch","transaction",t),e[0]))),e}populateTransaction(t){return Ht(this,void 0,void 0,(function*(){const e=yield Y(this.checkTransaction(t));null!=e.to&&(e.to=Promise.resolve(e.to).then((t=>Ht(this,void 0,void 0,(function*(){if(null==t)return null;const e=yield this.resolveName(t);return null==e&&qt.throwArgumentError("provided ENS name resolves to null","tx.to",t),e})))),e.to.catch((t=>{})));const r=null!=e.maxFeePerGas||null!=e.maxPriorityFeePerGas;if(null==e.gasPrice||2!==e.type&&!r?0!==e.type&&1!==e.type||!r||qt.throwArgumentError("pre-eip-1559 transaction do not support maxFeePerGas/maxPriorityFeePerGas","transaction",t):qt.throwArgumentError("eip-1559 transaction do not support gasPrice","transaction",t),2!==e.type&&null!=e.type||null==e.maxFeePerGas||null==e.maxPriorityFeePerGas)if(0===e.type||1===e.type)null==e.gasPrice&&(e.gasPrice=this.getGasPrice());else{const t=yield this.getFeeData();if(null==e.type)if(null!=t.maxFeePerGas&&null!=t.maxPriorityFeePerGas)if(e.type=2,null!=e.gasPrice){const t=e.gasPrice;delete e.gasPrice,e.maxFeePerGas=t,e.maxPriorityFeePerGas=t}else null==e.maxFeePerGas&&(e.maxFeePerGas=t.maxFeePerGas),null==e.maxPriorityFeePerGas&&(e.maxPriorityFeePerGas=t.maxPriorityFeePerGas);else null!=t.gasPrice?(r&&qt.throwError("network does not support EIP-1559",b.errors.UNSUPPORTED_OPERATION,{operation:"populateTransaction"}),null==e.gasPrice&&(e.gasPrice=t.gasPrice),e.type=0):qt.throwError("failed to get consistent fee data",b.errors.UNSUPPORTED_OPERATION,{operation:"signer.getFeeData"});else 2===e.type&&(null==e.maxFeePerGas&&(e.maxFeePerGas=t.maxFeePerGas),null==e.maxPriorityFeePerGas&&(e.maxPriorityFeePerGas=t.maxPriorityFeePerGas))}else e.type=2;return null==e.nonce&&(e.nonce=this.getTransactionCount("pending")),null==e.gasLimit&&(e.gasLimit=this.estimateGas(e).catch((t=>{if(Wt.indexOf(t.code)>=0)throw t;return qt.throwError("cannot estimate gas; transaction may fail or may require manual gas limit",b.errors.UNPREDICTABLE_GAS_LIMIT,{error:t,tx:e})}))),null==e.chainId?e.chainId=this.getChainId():e.chainId=Promise.all([Promise.resolve(e.chainId),this.getChainId()]).then((e=>(0!==e[1]&&e[0]!==e[1]&&qt.throwArgumentError("chainId address mismatch","transaction",t),e[0]))),yield Y(e)}))}_checkProvider(t){this.provider||qt.throwError("missing provider",b.errors.UNSUPPORTED_OPERATION,{operation:t||"_checkProvider"})}static isSigner(t){return!(!t||!t._isSigner)}}var Jt={},$t={},Zt=Xt;function Xt(t,e){if(!t)throw new Error(e||"Assertion failed")}Xt.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var Yt={exports:{}};"function"==typeof Object.create?Yt.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:Yt.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}};var Qt=Yt.exports,te=Zt,ee=Qt;function re(t,e){return 55296==(64512&t.charCodeAt(e))&&(!(e<0||e+1>=t.length)&&56320==(64512&t.charCodeAt(e+1)))}function ne(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function ie(t){return 1===t.length?"0"+t:t}function oe(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}$t.inherits=ee,$t.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),i=0;i<t.length;i+=2)r.push(parseInt(t[i]+t[i+1],16))}else for(var n=0,i=0;i<t.length;i++){var o=t.charCodeAt(i);o<128?r[n++]=o:o<2048?(r[n++]=o>>6|192,r[n++]=63&o|128):re(t,i)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++i)),r[n++]=o>>18|240,r[n++]=o>>12&63|128,r[n++]=o>>6&63|128,r[n++]=63&o|128):(r[n++]=o>>12|224,r[n++]=o>>6&63|128,r[n++]=63&o|128)}else for(i=0;i<t.length;i++)r[i]=0|t[i];return r},$t.toHex=function(t){for(var e="",r=0;r<t.length;r++)e+=ie(t[r].toString(16));return e},$t.htonl=ne,$t.toHex32=function(t,e){for(var r="",n=0;n<t.length;n++){var i=t[n];"little"===e&&(i=ne(i)),r+=oe(i.toString(16))}return r},$t.zero2=ie,$t.zero8=oe,$t.join32=function(t,e,r,n){var i=r-e;te(i%4==0);for(var o=new Array(i/4),s=0,a=e;s<o.length;s++,a+=4){var h;h="big"===n?t[a]<<24|t[a+1]<<16|t[a+2]<<8|t[a+3]:t[a+3]<<24|t[a+2]<<16|t[a+1]<<8|t[a],o[s]=h>>>0}return o},$t.split32=function(t,e){for(var r=new Array(4*t.length),n=0,i=0;n<t.length;n++,i+=4){var o=t[n];"big"===e?(r[i]=o>>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=255&o):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=255&o)}return r},$t.rotr32=function(t,e){return t>>>e|t<<32-e},$t.rotl32=function(t,e){return t<<e|t>>>32-e},$t.sum32=function(t,e){return t+e>>>0},$t.sum32_3=function(t,e,r){return t+e+r>>>0},$t.sum32_4=function(t,e,r,n){return t+e+r+n>>>0},$t.sum32_5=function(t,e,r,n,i){return t+e+r+n+i>>>0},$t.sum64=function(t,e,r,n){var i=t[e],o=n+t[e+1]>>>0,s=(o<n?1:0)+r+i;t[e]=s>>>0,t[e+1]=o},$t.sum64_hi=function(t,e,r,n){return(e+n>>>0<e?1:0)+t+r>>>0},$t.sum64_lo=function(t,e,r,n){return e+n>>>0},$t.sum64_4_hi=function(t,e,r,n,i,o,s,a){var h=0,u=e;return h+=(u=u+n>>>0)<e?1:0,h+=(u=u+o>>>0)<o?1:0,t+r+i+s+(h+=(u=u+a>>>0)<a?1:0)>>>0},$t.sum64_4_lo=function(t,e,r,n,i,o,s,a){return e+n+o+a>>>0},$t.sum64_5_hi=function(t,e,r,n,i,o,s,a,h,u){var f=0,l=e;return f+=(l=l+n>>>0)<e?1:0,f+=(l=l+o>>>0)<o?1:0,f+=(l=l+a>>>0)<a?1:0,t+r+i+s+h+(f+=(l=l+u>>>0)<u?1:0)>>>0},$t.sum64_5_lo=function(t,e,r,n,i,o,s,a,h,u){return e+n+o+a+u>>>0},$t.rotr64_hi=function(t,e,r){return(e<<32-r|t>>>r)>>>0},$t.rotr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0},$t.shr64_hi=function(t,e,r){return t>>>r},$t.shr64_lo=function(t,e,r){return(t<<32-r|e>>>r)>>>0};var se={},ae=$t,he=Zt;function ue(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}se.BlockHash=ue,ue.prototype.update=function(t,e){if(t=ae.toArray(t,e),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=ae.join32(t,0,t.length-r,this.endian);for(var n=0;n<t.length;n+=this._delta32)this._update(t,n,n+this._delta32)}return this},ue.prototype.digest=function(t){return this.update(this._pad()),he(null===this.pending),this._digest(t)},ue.prototype._pad=function(){var t=this.pendingTotal,e=this._delta8,r=e-(t+this.padLength)%e,n=new Array(r+this.padLength);n[0]=128;for(var i=1;i<r;i++)n[i]=0;if(t<<=3,"big"===this.endian){for(var o=8;o<this.padLength;o++)n[i++]=0;n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=t>>>24&255,n[i++]=t>>>16&255,n[i++]=t>>>8&255,n[i++]=255&t}else for(n[i++]=255&t,n[i++]=t>>>8&255,n[i++]=t>>>16&255,n[i++]=t>>>24&255,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,o=8;o<this.padLength;o++)n[i++]=0;return n};var fe={},le={},ce=$t.rotr32;function de(t,e,r){return t&e^~t&r}function pe(t,e,r){return t&e^t&r^e&r}function me(t,e,r){return t^e^r}le.ft_1=function(t,e,r,n){return 0===t?de(e,r,n):1===t||3===t?me(e,r,n):2===t?pe(e,r,n):void 0},le.ch32=de,le.maj32=pe,le.p32=me,le.s0_256=function(t){return ce(t,2)^ce(t,13)^ce(t,22)},le.s1_256=function(t){return ce(t,6)^ce(t,11)^ce(t,25)},le.g0_256=function(t){return ce(t,7)^ce(t,18)^t>>>3},le.g1_256=function(t){return ce(t,17)^ce(t,19)^t>>>10};var ge=$t,ye=se,ve=le,we=ge.rotl32,be=ge.sum32,Se=ge.sum32_5,Ae=ve.ft_1,Me=ye.BlockHash,Ee=[1518500249,1859775393,2400959708,3395469782];function _e(){if(!(this instanceof _e))return new _e;Me.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}ge.inherits(_e,Me);var Pe=_e;_e.blockSize=512,_e.outSize=160,_e.hmacStrength=80,_e.padLength=64,_e.prototype._update=function(t,e){for(var r=this.W,n=0;n<16;n++)r[n]=t[e+n];for(;n<r.length;n++)r[n]=we(r[n-3]^r[n-8]^r[n-14]^r[n-16],1);var i=this.h[0],o=this.h[1],s=this.h[2],a=this.h[3],h=this.h[4];for(n=0;n<r.length;n++){var u=~~(n/20),f=Se(we(i,5),Ae(u,o,s,a),h,r[n],Ee[u]);h=a,a=s,s=we(o,30),o=i,i=f}this.h[0]=be(this.h[0],i),this.h[1]=be(this.h[1],o),this.h[2]=be(this.h[2],s),this.h[3]=be(this.h[3],a),this.h[4]=be(this.h[4],h)},_e.prototype._digest=function(t){return"hex"===t?ge.toHex32(this.h,"big"):ge.split32(this.h,"big")};var xe=$t,Ie=se,Ce=le,Ne=Zt,Re=xe.sum32,ke=xe.sum32_4,Te=xe.sum32_5,De=Ce.ch32,Oe=Ce.maj32,Fe=Ce.s0_256,Be=Ce.s1_256,Le=Ce.g0_256,Ue=Ce.g1_256,Ke=Ie.BlockHash,Ge=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function ze(){if(!(this instanceof ze))return new ze;Ke.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=Ge,this.W=new Array(64)}xe.inherits(ze,Ke);var He=ze;ze.blockSize=512,ze.outSize=256,ze.hmacStrength=192,ze.padLength=64,ze.prototype._update=function(t,e){for(var r=this.W,n=0;n<16;n++)r[n]=t[e+n];for(;n<r.length;n++)r[n]=ke(Ue(r[n-2]),r[n-7],Le(r[n-15]),r[n-16]);var i=this.h[0],o=this.h[1],s=this.h[2],a=this.h[3],h=this.h[4],u=this.h[5],f=this.h[6],l=this.h[7];for(Ne(this.k.length===r.length),n=0;n<r.length;n++){var c=Te(l,Be(h),De(h,u,f),this.k[n],r[n]),d=Re(Fe(i),Oe(i,o,s));l=f,f=u,u=h,h=Re(a,c),a=s,s=o,o=i,i=Re(c,d)}this.h[0]=Re(this.h[0],i),this.h[1]=Re(this.h[1],o),this.h[2]=Re(this.h[2],s),this.h[3]=Re(this.h[3],a),this.h[4]=Re(this.h[4],h),this.h[5]=Re(this.h[5],u),this.h[6]=Re(this.h[6],f),this.h[7]=Re(this.h[7],l)},ze.prototype._digest=function(t){return"hex"===t?xe.toHex32(this.h,"big"):xe.split32(this.h,"big")};var qe=$t,je=He;function We(){if(!(this instanceof We))return new We;je.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}qe.inherits(We,je);var Ve=We;We.blockSize=512,We.outSize=224,We.hmacStrength=192,We.padLength=64,We.prototype._digest=function(t){return"hex"===t?qe.toHex32(this.h.slice(0,7),"big"):qe.split32(this.h.slice(0,7),"big")};var Je=$t,$e=se,Ze=Zt,Xe=Je.rotr64_hi,Ye=Je.rotr64_lo,Qe=Je.shr64_hi,tr=Je.shr64_lo,er=Je.sum64,rr=Je.sum64_hi,nr=Je.sum64_lo,ir=Je.sum64_4_hi,or=Je.sum64_4_lo,sr=Je.sum64_5_hi,ar=Je.sum64_5_lo,hr=$e.BlockHash,ur=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function fr(){if(!(this instanceof fr))return new fr;hr.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=ur,this.W=new Array(160)}Je.inherits(fr,hr);var lr=fr;function cr(t,e,r,n,i){var o=t&r^~t&i;return o<0&&(o+=4294967296),o}function dr(t,e,r,n,i,o){var s=e&n^~e&o;return s<0&&(s+=4294967296),s}function pr(t,e,r,n,i){var o=t&r^t&i^r&i;return o<0&&(o+=4294967296),o}function mr(t,e,r,n,i,o){var s=e&n^e&o^n&o;return s<0&&(s+=4294967296),s}function gr(t,e){var r=Xe(t,e,28)^Xe(e,t,2)^Xe(e,t,7);return r<0&&(r+=4294967296),r}function yr(t,e){var r=Ye(t,e,28)^Ye(e,t,2)^Ye(e,t,7);return r<0&&(r+=4294967296),r}function vr(t,e){var r=Xe(t,e,14)^Xe(t,e,18)^Xe(e,t,9);return r<0&&(r+=4294967296),r}function wr(t,e){var r=Ye(t,e,14)^Ye(t,e,18)^Ye(e,t,9);return r<0&&(r+=4294967296),r}function br(t,e){var r=Xe(t,e,1)^Xe(t,e,8)^Qe(t,e,7);return r<0&&(r+=4294967296),r}function Sr(t,e){var r=Ye(t,e,1)^Ye(t,e,8)^tr(t,e,7);return r<0&&(r+=4294967296),r}function Ar(t,e){var r=Xe(t,e,19)^Xe(e,t,29)^Qe(t,e,6);return r<0&&(r+=4294967296),r}function Mr(t,e){var r=Ye(t,e,19)^Ye(e,t,29)^tr(t,e,6);return r<0&&(r+=4294967296),r}fr.blockSize=1024,fr.outSize=512,fr.hmacStrength=192,fr.padLength=128,fr.prototype._prepareBlock=function(t,e){for(var r=this.W,n=0;n<32;n++)r[n]=t[e+n];for(;n<r.length;n+=2){var i=Ar(r[n-4],r[n-3]),o=Mr(r[n-4],r[n-3]),s=r[n-14],a=r[n-13],h=br(r[n-30],r[n-29]),u=Sr(r[n-30],r[n-29]),f=r[n-32],l=r[n-31];r[n]=ir(i,o,s,a,h,u,f,l),r[n+1]=or(i,o,s,a,h,u,f,l)}},fr.prototype._update=function(t,e){this._prepareBlock(t,e);var r=this.W,n=this.h[0],i=this.h[1],o=this.h[2],s=this.h[3],a=this.h[4],h=this.h[5],u=this.h[6],f=this.h[7],l=this.h[8],c=this.h[9],d=this.h[10],p=this.h[11],m=this.h[12],g=this.h[13],y=this.h[14],v=this.h[15];Ze(this.k.length===r.length);for(var w=0;w<r.length;w+=2){var b=y,S=v,A=vr(l,c),M=wr(l,c),E=cr(l,c,d,p,m),_=dr(l,c,d,p,m,g),P=this.k[w],x=this.k[w+1],I=r[w],C=r[w+1],N=sr(b,S,A,M,E,_,P,x,I,C),R=ar(b,S,A,M,E,_,P,x,I,C);b=gr(n,i),S=yr(n,i),A=pr(n,i,o,s,a),M=mr(n,i,o,s,a,h);var k=rr(b,S,A,M),T=nr(b,S,A,M);y=m,v=g,m=d,g=p,d=l,p=c,l=rr(u,f,N,R),c=nr(f,f,N,R),u=a,f=h,a=o,h=s,o=n,s=i,n=rr(N,R,k,T),i=nr(N,R,k,T)}er(this.h,0,n,i),er(this.h,2,o,s),er(this.h,4,a,h),er(this.h,6,u,f),er(this.h,8,l,c),er(this.h,10,d,p),er(this.h,12,m,g),er(this.h,14,y,v)},fr.prototype._digest=function(t){return"hex"===t?Je.toHex32(this.h,"big"):Je.split32(this.h,"big")};var Er=$t,_r=lr;function Pr(){if(!(this instanceof Pr))return new Pr;_r.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}Er.inherits(Pr,_r);var xr=Pr;Pr.blockSize=1024,Pr.outSize=384,Pr.hmacStrength=192,Pr.padLength=128,Pr.prototype._digest=function(t){return"hex"===t?Er.toHex32(this.h.slice(0,12),"big"):Er.split32(this.h.slice(0,12),"big")},fe.sha1=Pe,fe.sha224=Ve,fe.sha256=He,fe.sha384=xr,fe.sha512=lr;var Ir={},Cr=$t,Nr=se,Rr=Cr.rotl32,kr=Cr.sum32,Tr=Cr.sum32_3,Dr=Cr.sum32_4,Or=Nr.BlockHash;function Fr(){if(!(this instanceof Fr))return new Fr;Or.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}function Br(t,e,r,n){return t<=15?e^r^n:t<=31?e&r|~e&n:t<=47?(e|~r)^n:t<=63?e&n|r&~n:e^(r|~n)}function Lr(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function Ur(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}Cr.inherits(Fr,Or),Ir.ripemd160=Fr,Fr.blockSize=512,Fr.outSize=160,Fr.hmacStrength=192,Fr.padLength=64,Fr.prototype._update=function(t,e){for(var r=this.h[0],n=this.h[1],i=this.h[2],o=this.h[3],s=this.h[4],a=r,h=n,u=i,f=o,l=s,c=0;c<80;c++){var d=kr(Rr(Dr(r,Br(c,n,i,o),t[Kr[c]+e],Lr(c)),zr[c]),s);r=s,s=o,o=Rr(i,10),i=n,n=d,d=kr(Rr(Dr(a,Br(79-c,h,u,f),t[Gr[c]+e],Ur(c)),Hr[c]),l),a=l,l=f,f=Rr(u,10),u=h,h=d}d=Tr(this.h[1],i,f),this.h[1]=Tr(this.h[2],o,l),this.h[2]=Tr(this.h[3],s,a),this.h[3]=Tr(this.h[4],r,h),this.h[4]=Tr(this.h[0],n,u),this.h[0]=d},Fr.prototype._digest=function(t){return"hex"===t?Cr.toHex32(this.h,"little"):Cr.split32(this.h,"little")};var Kr=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],Gr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],zr=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],Hr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],qr=$t,jr=Zt;function Wr(t,e,r){if(!(this instanceof Wr))return new Wr(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(qr.toArray(e,r))}var Vr=Wr;Wr.prototype._init=function(t){t.length>this.blockSize&&(t=(new this.Hash).update(t).digest()),jr(t.length<=this.blockSize);for(var e=t.length;e<this.blockSize;e++)t.push(0);for(e=0;e<t.length;e++)t[e]^=54;for(this.inner=(new this.Hash).update(t),e=0;e<t.length;e++)t[e]^=106;this.outer=(new this.Hash).update(t)},Wr.prototype.update=function(t,e){return this.inner.update(t,e),this},Wr.prototype.digest=function(t){return this.outer.update(this.inner.digest()),this.outer.digest(t)},function(){var t=Jt;t.utils=$t,t.common=se,t.sha=fe,t.ripemd=Ir,t.hmac=Vr,t.sha1=t.sha.sha1,t.sha256=t.sha.sha256,t.sha224=t.sha.sha224,t.sha384=t.sha.sha384,t.sha512=t.sha.sha512,t.ripemd160=t.ripemd.ripemd160}();var Jr=s(Jt);function $r(t,e,r){return r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},t(r,r.exports),r.exports}var Zr=Xr;function Xr(t,e){if(!t)throw new Error(e||"Assertion failed")}Xr.equal=function(t,e,r){if(t!=e)throw new Error(r||"Assertion failed: "+t+" != "+e)};var Yr=$r((function(t,e){var r=e;function n(t){return 1===t.length?"0"+t:t}function i(t){for(var e="",r=0;r<t.length;r++)e+=n(t[r].toString(16));return e}r.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if("string"!=typeof t){for(var n=0;n<t.length;n++)r[n]=0|t[n];return r}if("hex"===e){(t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t);for(n=0;n<t.length;n+=2)r.push(parseInt(t[n]+t[n+1],16))}else for(n=0;n<t.length;n++){var i=t.charCodeAt(n),o=i>>8,s=255&i;o?r.push(o,s):r.push(s)}return r},r.zero2=n,r.toHex=i,r.encode=function(t,e){return"hex"===e?i(t):t}})),Qr=$r((function(t,e){var r=e;r.assert=Zr,r.toArray=Yr.toArray,r.zero2=Yr.zero2,r.toHex=Yr.toHex,r.encode=Yr.encode,r.getNAF=function(t,e,r){var n=new Array(Math.max(t.bitLength(),r)+1);n.fill(0);for(var i=1<<e+1,o=t.clone(),s=0;s<n.length;s++){var a,h=o.andln(i-1);o.isOdd()?(a=h>(i>>1)-1?(i>>1)-h:h,o.isubn(a)):a=0,n[s]=a,o.iushrn(1)}return n},r.getJSF=function(t,e){var r=[[],[]];t=t.clone(),e=e.clone();for(var n,i=0,o=0;t.cmpn(-i)>0||e.cmpn(-o)>0;){var s,a,h=t.andln(3)+i&3,u=e.andln(3)+o&3;3===h&&(h=-1),3===u&&(u=-1),s=1&h?3!==(n=t.andln(7)+i&7)&&5!==n||2!==u?h:-h:0,r[0].push(s),a=1&u?3!==(n=e.andln(7)+o&7)&&5!==n||2!==h?u:-u:0,r[1].push(a),2*i===s+1&&(i=1-i),2*o===a+1&&(o=1-o),t.iushrn(1),e.iushrn(1)}return r},r.cachedProperty=function(t,e,r){var n="_"+e;t.prototype[e]=function(){return void 0!==this[n]?this[n]:this[n]=r.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new f(t,"hex","le")}})),tn=Qr.getNAF,en=Qr.getJSF,rn=Qr.assert;function nn(t,e){this.type=t,this.p=new f(e.p,16),this.red=e.prime?f.red(e.prime):f.mont(this.p),this.zero=new f(0).toRed(this.red),this.one=new f(1).toRed(this.red),this.two=new f(2).toRed(this.red),this.n=e.n&&new f(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var on=nn;function sn(t,e){this.curve=t,this.type=e,this.precomputed=null}nn.prototype.point=function(){throw new Error("Not implemented")},nn.prototype.validate=function(){throw new Error("Not implemented")},nn.prototype._fixedNafMul=function(t,e){rn(t.precomputed);var r=t._getDoubles(),n=tn(e,1,this._bitLength),i=(1<<r.step+1)-(r.step%2==0?2:1);i/=3;var o,s,a=[];for(o=0;o<n.length;o+=r.step){s=0;for(var h=o+r.step-1;h>=o;h--)s=(s<<1)+n[h];a.push(s)}for(var u=this.jpoint(null,null,null),f=this.jpoint(null,null,null),l=i;l>0;l--){for(o=0;o<a.length;o++)(s=a[o])===l?f=f.mixedAdd(r.points[o]):s===-l&&(f=f.mixedAdd(r.points[o].neg()));u=u.add(f)}return u.toP()},nn.prototype._wnafMul=function(t,e){var r=4,n=t._getNAFPoints(r);r=n.wnd;for(var i=n.points,o=tn(e,r,this._bitLength),s=this.jpoint(null,null,null),a=o.length-1;a>=0;a--){for(var h=0;a>=0&&0===o[a];a--)h++;if(a>=0&&h++,s=s.dblp(h),a<0)break;var u=o[a];rn(0!==u),s="affine"===t.type?u>0?s.mixedAdd(i[u-1>>1]):s.mixedAdd(i[-u-1>>1].neg()):u>0?s.add(i[u-1>>1]):s.add(i[-u-1>>1].neg())}return"affine"===t.type?s.toP():s},nn.prototype._wnafMulAdd=function(t,e,r,n,i){var o,s,a,h=this._wnafT1,u=this._wnafT2,f=this._wnafT3,l=0;for(o=0;o<n;o++){var c=(a=e[o])._getNAFPoints(t);h[o]=c.wnd,u[o]=c.points}for(o=n-1;o>=1;o-=2){var d=o-1,p=o;if(1===h[d]&&1===h[p]){var m=[e[d],null,null,e[p]];0===e[d].y.cmp(e[p].y)?(m[1]=e[d].add(e[p]),m[2]=e[d].toJ().mixedAdd(e[p].neg())):0===e[d].y.cmp(e[p].y.redNeg())?(m[1]=e[d].toJ().mixedAdd(e[p]),m[2]=e[d].add(e[p].neg())):(m[1]=e[d].toJ().mixedAdd(e[p]),m[2]=e[d].toJ().mixedAdd(e[p].neg()));var g=[-3,-1,-5,-7,0,7,5,1,3],y=en(r[d],r[p]);for(l=Math.max(y[0].length,l),f[d]=new Array(l),f[p]=new Array(l),s=0;s<l;s++){var v=0|y[0][s],w=0|y[1][s];f[d][s]=g[3*(v+1)+(w+1)],f[p][s]=0,u[d]=m}}else f[d]=tn(r[d],h[d],this._bitLength),f[p]=tn(r[p],h[p],this._bitLength),l=Math.max(f[d].length,l),l=Math.max(f[p].length,l)}var b=this.jpoint(null,null,null),S=this._wnafT4;for(o=l;o>=0;o--){for(var A=0;o>=0;){var M=!0;for(s=0;s<n;s++)S[s]=0|f[s][o],0!==S[s]&&(M=!1);if(!M)break;A++,o--}if(o>=0&&A++,b=b.dblp(A),o<0)break;for(s=0;s<n;s++){var E=S[s];0!==E&&(E>0?a=u[s][E-1>>1]:E<0&&(a=u[s][-E-1>>1].neg()),b="affine"===a.type?b.mixedAdd(a):b.add(a))}}for(o=0;o<n;o++)u[o]=null;return i?b:b.toP()},nn.BasePoint=sn,sn.prototype.eq=function(){throw new Error("Not implemented")},sn.prototype.validate=function(){return this.curve.validate(this)},nn.prototype.decodePoint=function(t,e){t=Qr.toArray(t,e);var r=this.p.byteLength();if((4===t[0]||6===t[0]||7===t[0])&&t.length-1==2*r)return 6===t[0]?rn(t[t.length-1]%2==0):7===t[0]&&rn(t[t.length-1]%2==1),this.point(t.slice(1,1+r),t.slice(1+r,1+2*r));if((2===t[0]||3===t[0])&&t.length-1===r)return this.pointFromX(t.slice(1,1+r),3===t[0]);throw new Error("Unknown point format")},sn.prototype.encodeCompressed=function(t){return this.encode(t,!0)},sn.prototype._encode=function(t){var e=this.curve.p.byteLength(),r=this.getX().toArray("be",e);return t?[this.getY().isEven()?2:3].concat(r):[4].concat(r,this.getY().toArray("be",e))},sn.prototype.encode=function(t,e){return Qr.encode(this._encode(e),t)},sn.prototype.precompute=function(t){if(this.precomputed)return this;var e={doubles:null,naf:null,beta:null};return e.naf=this._getNAFPoints(8),e.doubles=this._getDoubles(4,t),e.beta=this._getBeta(),this.precomputed=e,this},sn.prototype._hasDoubles=function(t){if(!this.precomputed)return!1;var e=this.precomputed.doubles;return!!e&&e.points.length>=Math.ceil((t.bitLength()+1)/e.step)},sn.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],n=this,i=0;i<e;i+=t){for(var o=0;o<t;o++)n=n.dbl();r.push(n)}return{step:t,points:r}},sn.prototype._getNAFPoints=function(t){if(this.precomputed&&this.precomputed.naf)return this.precomputed.naf;for(var e=[this],r=(1<<t)-1,n=1===r?null:this.dbl(),i=1;i<r;i++)e[i]=e[i-1].add(n);return{wnd:t,points:e}},sn.prototype._getBeta=function(){return null},sn.prototype.dblp=function(t){for(var e=this,r=0;r<t;r++)e=e.dbl();return e};var an=$r((function(t){"function"==typeof Object.create?t.exports=function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(t,e){if(e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}}})),hn=Qr.assert;function un(t){on.call(this,"short",t),this.a=new f(t.a,16).toRed(this.red),this.b=new f(t.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=0===this.a.fromRed().cmpn(0),this.threeA=0===this.a.fromRed().sub(this.p).cmpn(-3),this.endo=this._getEndomorphism(t),this._endoWnafT1=new Array(4),this._endoWnafT2=new Array(4)}an(un,on);var fn=un;function ln(t,e,r,n){on.BasePoint.call(this,t,"affine"),null===e&&null===r?(this.x=null,this.y=null,this.inf=!0):(this.x=new f(e,16),this.y=new f(r,16),n&&(this.x.forceRed(this.curve.red),this.y.forceRed(this.curve.red)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.inf=!1)}function cn(t,e,r,n){on.BasePoint.call(this,t,"jacobian"),null===e&&null===r&&null===n?(this.x=this.curve.one,this.y=this.curve.one,this.z=new f(0)):(this.x=new f(e,16),this.y=new f(r,16),this.z=new f(n,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}un.prototype._getEndomorphism=function(t){if(this.zeroA&&this.g&&this.n&&1===this.p.modn(3)){var e,r;if(t.beta)e=new f(t.beta,16).toRed(this.red);else{var n=this._getEndoRoots(this.p);e=(e=n[0].cmp(n[1])<0?n[0]:n[1]).toRed(this.red)}if(t.lambda)r=new f(t.lambda,16);else{var i=this._getEndoRoots(this.n);0===this.g.mul(i[0]).x.cmp(this.g.x.redMul(e))?r=i[0]:(r=i[1],hn(0===this.g.mul(r).x.cmp(this.g.x.redMul(e))))}return{beta:e,lambda:r,basis:t.basis?t.basis.map((function(t){return{a:new f(t.a,16),b:new f(t.b,16)}})):this._getEndoBasis(r)}}},un.prototype._getEndoRoots=function(t){var e=t===this.p?this.red:f.mont(t),r=new f(2).toRed(e).redInvm(),n=r.redNeg(),i=new f(3).toRed(e).redNeg().redSqrt().redMul(r);return[n.redAdd(i).fromRed(),n.redSub(i).fromRed()]},un.prototype._getEndoBasis=function(t){for(var e,r,n,i,o,s,a,h,u,l=this.n.ushrn(Math.floor(this.n.bitLength()/2)),c=t,d=this.n.clone(),p=new f(1),m=new f(0),g=new f(0),y=new f(1),v=0;0!==c.cmpn(0);){var w=d.div(c);h=d.sub(w.mul(c)),u=g.sub(w.mul(p));var b=y.sub(w.mul(m));if(!n&&h.cmp(l)<0)e=a.neg(),r=p,n=h.neg(),i=u;else if(n&&2==++v)break;a=h,d=c,c=h,g=p,p=u,y=m,m=b}o=h.neg(),s=u;var S=n.sqr().add(i.sqr());return o.sqr().add(s.sqr()).cmp(S)>=0&&(o=e,s=r),n.negative&&(n=n.neg(),i=i.neg()),o.negative&&(o=o.neg(),s=s.neg()),[{a:n,b:i},{a:o,b:s}]},un.prototype._endoSplit=function(t){var e=this.endo.basis,r=e[0],n=e[1],i=n.b.mul(t).divRound(this.n),o=r.b.neg().mul(t).divRound(this.n),s=i.mul(r.a),a=o.mul(n.a),h=i.mul(r.b),u=o.mul(n.b);return{k1:t.sub(s).sub(a),k2:h.add(u).neg()}},un.prototype.pointFromX=function(t,e){(t=new f(t,16)).red||(t=t.toRed(this.red));var r=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),n=r.redSqrt();if(0!==n.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var i=n.fromRed().isOdd();return(e&&!i||!e&&i)&&(n=n.redNeg()),this.point(t,n)},un.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,r=t.y,n=this.a.redMul(e),i=e.redSqr().redMul(e).redIAdd(n).redIAdd(this.b);return 0===r.redSqr().redISub(i).cmpn(0)},un.prototype._endoWnafMulAdd=function(t,e,r){for(var n=this._endoWnafT1,i=this._endoWnafT2,o=0;o<t.length;o++){var s=this._endoSplit(e[o]),a=t[o],h=a._getBeta();s.k1.negative&&(s.k1.ineg(),a=a.neg(!0)),s.k2.negative&&(s.k2.ineg(),h=h.neg(!0)),n[2*o]=a,n[2*o+1]=h,i[2*o]=s.k1,i[2*o+1]=s.k2}for(var u=this._wnafMulAdd(1,n,i,2*o,r),f=0;f<2*o;f++)n[f]=null,i[f]=null;return u},an(ln,on.BasePoint),un.prototype.point=function(t,e,r){return new ln(this,t,e,r)},un.prototype.pointFromJSON=function(t,e){return ln.fromJSON(this,t,e)},ln.prototype._getBeta=function(){if(this.curve.endo){var t=this.precomputed;if(t&&t.beta)return t.beta;var e=this.curve.point(this.x.redMul(this.curve.endo.beta),this.y);if(t){var r=this.curve,n=function(t){return r.point(t.x.redMul(r.endo.beta),t.y)};t.beta=e,e.precomputed={beta:null,naf:t.naf&&{wnd:t.naf.wnd,points:t.naf.points.map(n)},doubles:t.doubles&&{step:t.doubles.step,points:t.doubles.points.map(n)}}}return e}},ln.prototype.toJSON=function(){return this.precomputed?[this.x,this.y,this.precomputed&&{doubles:this.precomputed.doubles&&{step:this.precomputed.doubles.step,points:this.precomputed.doubles.points.slice(1)},naf:this.precomputed.naf&&{wnd:this.precomputed.naf.wnd,points:this.precomputed.naf.points.slice(1)}}]:[this.x,this.y]},ln.fromJSON=function(t,e,r){"string"==typeof e&&(e=JSON.parse(e));var n=t.point(e[0],e[1],r);if(!e[2])return n;function i(e){return t.point(e[0],e[1],r)}var o=e[2];return n.precomputed={beta:null,doubles:o.doubles&&{step:o.doubles.step,points:[n].concat(o.doubles.points.map(i))},naf:o.naf&&{wnd:o.naf.wnd,points:[n].concat(o.naf.points.map(i))}},n},ln.prototype.inspect=function(){return this.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16,2)+" y: "+this.y.fromRed().toString(16,2)+">"},ln.prototype.isInfinity=function(){return this.inf},ln.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var r=e.redSqr().redISub(this.x).redISub(t.x),n=e.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,n)},ln.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,r=this.x.redSqr(),n=t.redInvm(),i=r.redAdd(r).redIAdd(r).redIAdd(e).redMul(n),o=i.redSqr().redISub(this.x.redAdd(this.x)),s=i.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,s)},ln.prototype.getX=function(){return this.x.fromRed()},ln.prototype.getY=function(){return this.y.fromRed()},ln.prototype.mul=function(t){return t=new f(t,16),this.isInfinity()?this:this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},ln.prototype.mulAdd=function(t,e,r){var n=[this,e],i=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i):this.curve._wnafMulAdd(1,n,i,2)},ln.prototype.jmulAdd=function(t,e,r){var n=[this,e],i=[t,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i,!0):this.curve._wnafMulAdd(1,n,i,2,!0)},ln.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},ln.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var r=this.precomputed,n=function(t){return t.neg()};e.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(n)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(n)}}}return e},ln.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},an(cn,on.BasePoint),un.prototype.jpoint=function(t,e,r){return new cn(this,t,e,r)},cn.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),r=this.x.redMul(e),n=this.y.redMul(e).redMul(t);return this.curve.point(r,n)},cn.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},cn.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),r=this.z.redSqr(),n=this.x.redMul(e),i=t.x.redMul(r),o=this.y.redMul(e.redMul(t.z)),s=t.y.redMul(r.redMul(this.z)),a=n.redSub(i),h=o.redSub(s);if(0===a.cmpn(0))return 0!==h.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var u=a.redSqr(),f=u.redMul(a),l=n.redMul(u),c=h.redSqr().redIAdd(f).redISub(l).redISub(l),d=h.redMul(l.redISub(c)).redISub(o.redMul(f)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(c,d,p)},cn.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),r=this.x,n=t.x.redMul(e),i=this.y,o=t.y.redMul(e).redMul(this.z),s=r.redSub(n),a=i.redSub(o);if(0===s.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var h=s.redSqr(),u=h.redMul(s),f=r.redMul(h),l=a.redSqr().redIAdd(u).redISub(f).redISub(f),c=a.redMul(f.redISub(l)).redISub(i.redMul(u)),d=this.z.redMul(s);return this.curve.jpoint(l,c,d)},cn.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var r=this;for(e=0;e<t;e++)r=r.dbl();return r}var n=this.curve.a,i=this.curve.tinv,o=this.x,s=this.y,a=this.z,h=a.redSqr().redSqr(),u=s.redAdd(s);for(e=0;e<t;e++){var f=o.redSqr(),l=u.redSqr(),c=l.redSqr(),d=f.redAdd(f).redIAdd(f).redIAdd(n.redMul(h)),p=o.redMul(l),m=d.redSqr().redISub(p.redAdd(p)),g=p.redISub(m),y=d.redMul(g);y=y.redIAdd(y).redISub(c);var v=u.redMul(a);e+1<t&&(h=h.redMul(c)),o=m,a=v,u=y}return this.curve.jpoint(o,u.redMul(i),a)},cn.prototype.dbl=function(){return this.isInfinity()?this:this.curve.zeroA?this._zeroDbl():this.curve.threeA?this._threeDbl():this._dbl()},cn.prototype._zeroDbl=function(){var t,e,r;if(this.zOne){var n=this.x.redSqr(),i=this.y.redSqr(),o=i.redSqr(),s=this.x.redAdd(i).redSqr().redISub(n).redISub(o);s=s.redIAdd(s);var a=n.redAdd(n).redIAdd(n),h=a.redSqr().redISub(s).redISub(s),u=o.redIAdd(o);u=(u=u.redIAdd(u)).redIAdd(u),t=h,e=a.redMul(s.redISub(h)).redISub(u),r=this.y.redAdd(this.y)}else{var f=this.x.redSqr(),l=this.y.redSqr(),c=l.redSqr(),d=this.x.redAdd(l).redSqr().redISub(f).redISub(c);d=d.redIAdd(d);var p=f.redAdd(f).redIAdd(f),m=p.redSqr(),g=c.redIAdd(c);g=(g=g.redIAdd(g)).redIAdd(g),t=m.redISub(d).redISub(d),e=p.redMul(d.redISub(t)).redISub(g),r=(r=this.y.redMul(this.z)).redIAdd(r)}return this.curve.jpoint(t,e,r)},cn.prototype._threeDbl=function(){var t,e,r;if(this.zOne){var n=this.x.redSqr(),i=this.y.redSqr(),o=i.redSqr(),s=this.x.redAdd(i).redSqr().redISub(n).redISub(o);s=s.redIAdd(s);var a=n.redAdd(n).redIAdd(n).redIAdd(this.curve.a),h=a.redSqr().redISub(s).redISub(s);t=h;var u=o.redIAdd(o);u=(u=u.redIAdd(u)).redIAdd(u),e=a.redMul(s.redISub(h)).redISub(u),r=this.y.redAdd(this.y)}else{var f=this.z.redSqr(),l=this.y.redSqr(),c=this.x.redMul(l),d=this.x.redSub(f).redMul(this.x.redAdd(f));d=d.redAdd(d).redIAdd(d);var p=c.redIAdd(c),m=(p=p.redIAdd(p)).redAdd(p);t=d.redSqr().redISub(m),r=this.y.redAdd(this.z).redSqr().redISub(l).redISub(f);var g=l.redSqr();g=(g=(g=g.redIAdd(g)).redIAdd(g)).redIAdd(g),e=d.redMul(p.redISub(t)).redISub(g)}return this.curve.jpoint(t,e,r)},cn.prototype._dbl=function(){var t=this.curve.a,e=this.x,r=this.y,n=this.z,i=n.redSqr().redSqr(),o=e.redSqr(),s=r.redSqr(),a=o.redAdd(o).redIAdd(o).redIAdd(t.redMul(i)),h=e.redAdd(e),u=(h=h.redIAdd(h)).redMul(s),f=a.redSqr().redISub(u.redAdd(u)),l=u.redISub(f),c=s.redSqr();c=(c=(c=c.redIAdd(c)).redIAdd(c)).redIAdd(c);var d=a.redMul(l).redISub(c),p=r.redAdd(r).redMul(n);return this.curve.jpoint(f,d,p)},cn.prototype.trpl=function(){if(!this.curve.zeroA)return this.dbl().add(this);var t=this.x.redSqr(),e=this.y.redSqr(),r=this.z.redSqr(),n=e.redSqr(),i=t.redAdd(t).redIAdd(t),o=i.redSqr(),s=this.x.redAdd(e).redSqr().redISub(t).redISub(n),a=(s=(s=(s=s.redIAdd(s)).redAdd(s).redIAdd(s)).redISub(o)).redSqr(),h=n.redIAdd(n);h=(h=(h=h.redIAdd(h)).redIAdd(h)).redIAdd(h);var u=i.redIAdd(s).redSqr().redISub(o).redISub(a).redISub(h),f=e.redMul(u);f=(f=f.redIAdd(f)).redIAdd(f);var l=this.x.redMul(a).redISub(f);l=(l=l.redIAdd(l)).redIAdd(l);var c=this.y.redMul(u.redMul(h.redISub(u)).redISub(s.redMul(a)));c=(c=(c=c.redIAdd(c)).redIAdd(c)).redIAdd(c);var d=this.z.redAdd(s).redSqr().redISub(r).redISub(a);return this.curve.jpoint(l,c,d)},cn.prototype.mul=function(t,e){return t=new f(t,e),this.curve._wnafMul(this,t)},cn.prototype.eq=function(t){if("affine"===t.type)return this.eq(t.toJ());if(this===t)return!0;var e=this.z.redSqr(),r=t.z.redSqr();if(0!==this.x.redMul(r).redISub(t.x.redMul(e)).cmpn(0))return!1;var n=e.redMul(this.z),i=r.redMul(t.z);return 0===this.y.redMul(i).redISub(t.y.redMul(n)).cmpn(0)},cn.prototype.eqXToP=function(t){var e=this.z.redSqr(),r=t.toRed(this.curve.red).redMul(e);if(0===this.x.cmp(r))return!0;for(var n=t.clone(),i=this.curve.redN.redMul(e);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(r.redIAdd(i),0===this.x.cmp(r))return!0}},cn.prototype.inspect=function(){return this.isInfinity()?"<EC JPoint Infinity>":"<EC JPoint x: "+this.x.toString(16,2)+" y: "+this.y.toString(16,2)+" z: "+this.z.toString(16,2)+">"},cn.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var dn=$r((function(t,e){var r=e;r.base=on,r.short=fn,r.mont=null,r.edwards=null})),pn=$r((function(t,e){var r,n=e,i=Qr.assert;function o(t){"short"===t.type?this.curve=new dn.short(t):"edwards"===t.type?this.curve=new dn.edwards(t):this.curve=new dn.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,i(this.g.validate(),"Invalid curve"),i(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function s(t,e){Object.defineProperty(n,t,{configurable:!0,enumerable:!0,get:function(){var r=new o(e);return Object.defineProperty(n,t,{configurable:!0,enumerable:!0,value:r}),r}})}n.PresetCurve=o,s("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:Jr.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),s("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:Jr.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),s("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:Jr.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),s("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:Jr.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),s("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:Jr.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),s("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:Jr.sha256,gRed:!1,g:["9"]}),s("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:Jr.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{r=null.crash()}catch(t){r=void 0}s("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:Jr.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",r]})}));function mn(t){if(!(this instanceof mn))return new mn(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=Yr.toArray(t.entropy,t.entropyEnc||"hex"),r=Yr.toArray(t.nonce,t.nonceEnc||"hex"),n=Yr.toArray(t.pers,t.persEnc||"hex");Zr(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,n)}var gn=mn;mn.prototype._init=function(t,e,r){var n=t.concat(e).concat(r);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var i=0;i<this.V.length;i++)this.K[i]=0,this.V[i]=1;this._update(n),this._reseed=1,this.reseedInterval=281474976710656},mn.prototype._hmac=function(){return new Jr.hmac(this.hash,this.K)},mn.prototype._update=function(t){var e=this._hmac().update(this.V).update([0]);t&&(e=e.update(t)),this.K=e.digest(),this.V=this._hmac().update(this.V).digest(),t&&(this.K=this._hmac().update(this.V).update([1]).update(t).digest(),this.V=this._hmac().update(this.V).digest())},mn.prototype.reseed=function(t,e,r,n){"string"!=typeof e&&(n=r,r=e,e=null),t=Yr.toArray(t,e),r=Yr.toArray(r,n),Zr(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(r||[])),this._reseed=1},mn.prototype.generate=function(t,e,r,n){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(n=r,r=e,e=null),r&&(r=Yr.toArray(r,n||"hex"),this._update(r));for(var i=[];i.length<t;)this.V=this._hmac().update(this.V).digest(),i=i.concat(this.V);var o=i.slice(0,t);return this._update(r),this._reseed++,Yr.encode(o,e)};var yn=Qr.assert;function vn(t,e){this.ec=t,this.priv=null,this.pub=null,e.priv&&this._importPrivate(e.priv,e.privEnc),e.pub&&this._importPublic(e.pub,e.pubEnc)}var wn=vn;vn.fromPublic=function(t,e,r){return e instanceof vn?e:new vn(t,{pub:e,pubEnc:r})},vn.fromPrivate=function(t,e,r){return e instanceof vn?e:new vn(t,{priv:e,privEnc:r})},vn.prototype.validate=function(){var t=this.getPublic();return t.isInfinity()?{result:!1,reason:"Invalid public key"}:t.validate()?t.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},vn.prototype.getPublic=function(t,e){return"string"==typeof t&&(e=t,t=null),this.pub||(this.pub=this.ec.g.mul(this.priv)),e?this.pub.encode(e,t):this.pub},vn.prototype.getPrivate=function(t){return"hex"===t?this.priv.toString(16,2):this.priv},vn.prototype._importPrivate=function(t,e){this.priv=new f(t,e||16),this.priv=this.priv.umod(this.ec.curve.n)},vn.prototype._importPublic=function(t,e){if(t.x||t.y)return"mont"===this.ec.curve.type?yn(t.x,"Need x coordinate"):"short"!==this.ec.curve.type&&"edwards"!==this.ec.curve.type||yn(t.x&&t.y,"Need both x and y coordinate"),void(this.pub=this.ec.curve.point(t.x,t.y));this.pub=this.ec.curve.decodePoint(t,e)},vn.prototype.derive=function(t){return t.validate()||yn(t.validate(),"public point not validated"),t.mul(this.priv).getX()},vn.prototype.sign=function(t,e,r){return this.ec.sign(t,this,e,r)},vn.prototype.verify=function(t,e){return this.ec.verify(t,e,this)},vn.prototype.inspect=function(){return"<Key priv: "+(this.priv&&this.priv.toString(16,2))+" pub: "+(this.pub&&this.pub.inspect())+" >"};var bn=Qr.assert;function Sn(t,e){if(t instanceof Sn)return t;this._importDER(t,e)||(bn(t.r&&t.s,"Signature without r or s"),this.r=new f(t.r,16),this.s=new f(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var An=Sn;function Mn(){this.place=0}function En(t,e){var r=t[e.place++];if(!(128&r))return r;var n=15&r;if(0===n||n>4)return!1;for(var i=0,o=0,s=e.place;o<n;o++,s++)i<<=8,i|=t[s],i>>>=0;return!(i<=127)&&(e.place=s,i)}function _n(t){for(var e=0,r=t.length-1;!t[e]&&!(128&t[e+1])&&e<r;)e++;return 0===e?t:t.slice(e)}function Pn(t,e){if(e<128)t.push(e);else{var r=1+(Math.log(e)/Math.LN2>>>3);for(t.push(128|r);--r;)t.push(e>>>(r<<3)&255);t.push(e)}}Sn.prototype._importDER=function(t,e){t=Qr.toArray(t,e);var r=new Mn;if(48!==t[r.place++])return!1;var n=En(t,r);if(!1===n)return!1;if(n+r.place!==t.length)return!1;if(2!==t[r.place++])return!1;var i=En(t,r);if(!1===i)return!1;var o=t.slice(r.place,i+r.place);if(r.place+=i,2!==t[r.place++])return!1;var s=En(t,r);if(!1===s)return!1;if(t.length!==s+r.place)return!1;var a=t.slice(r.place,s+r.place);if(0===o[0]){if(!(128&o[1]))return!1;o=o.slice(1)}if(0===a[0]){if(!(128&a[1]))return!1;a=a.slice(1)}return this.r=new f(o),this.s=new f(a),this.recoveryParam=null,!0},Sn.prototype.toDER=function(t){var e=this.r.toArray(),r=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&r[0]&&(r=[0].concat(r)),e=_n(e),r=_n(r);!(r[0]||128&r[1]);)r=r.slice(1);var n=[2];Pn(n,e.length),(n=n.concat(e)).push(2),Pn(n,r.length);var i=n.concat(r),o=[48];return Pn(o,i.length),o=o.concat(i),Qr.encode(o,t)};var xn=function(){throw new Error("unsupported")},In=Qr.assert;function Cn(t){if(!(this instanceof Cn))return new Cn(t);"string"==typeof t&&(In(Object.prototype.hasOwnProperty.call(pn,t),"Unknown curve "+t),t=pn[t]),t instanceof pn.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}var Nn=Cn;Cn.prototype.keyPair=function(t){return new wn(this,t)},Cn.prototype.keyFromPrivate=function(t,e){return wn.fromPrivate(this,t,e)},Cn.prototype.keyFromPublic=function(t,e){return wn.fromPublic(this,t,e)},Cn.prototype.genKeyPair=function(t){t||(t={});for(var e=new gn({hash:this.hash,pers:t.pers,persEnc:t.persEnc||"utf8",entropy:t.entropy||xn(this.hash.hmacStrength),entropyEnc:t.entropy&&t.entropyEnc||"utf8",nonce:this.n.toArray()}),r=this.n.byteLength(),n=this.n.sub(new f(2));;){var i=new f(e.generate(r));if(!(i.cmp(n)>0))return i.iaddn(1),this.keyFromPrivate(i)}},Cn.prototype._truncateToN=function(t,e){var r=8*t.byteLength()-this.n.bitLength();return r>0&&(t=t.ushrn(r)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},Cn.prototype.sign=function(t,e,r,n){"object"==typeof r&&(n=r,r=null),n||(n={}),e=this.keyFromPrivate(e,r),t=this._truncateToN(new f(t,16));for(var i=this.n.byteLength(),o=e.getPrivate().toArray("be",i),s=t.toArray("be",i),a=new gn({hash:this.hash,entropy:o,nonce:s,pers:n.pers,persEnc:n.persEnc||"utf8"}),h=this.n.sub(new f(1)),u=0;;u++){var l=n.k?n.k(u):new f(a.generate(this.n.byteLength()));if(!((l=this._truncateToN(l,!0)).cmpn(1)<=0||l.cmp(h)>=0)){var c=this.g.mul(l);if(!c.isInfinity()){var d=c.getX(),p=d.umod(this.n);if(0!==p.cmpn(0)){var m=l.invm(this.n).mul(p.mul(e.getPrivate()).iadd(t));if(0!==(m=m.umod(this.n)).cmpn(0)){var g=(c.getY().isOdd()?1:0)|(0!==d.cmp(p)?2:0);return n.canonical&&m.cmp(this.nh)>0&&(m=this.n.sub(m),g^=1),new An({r:p,s:m,recoveryParam:g})}}}}}},Cn.prototype.verify=function(t,e,r,n){t=this._truncateToN(new f(t,16)),r=this.keyFromPublic(r,n);var i=(e=new An(e,"hex")).r,o=e.s;if(i.cmpn(1)<0||i.cmp(this.n)>=0)return!1;if(o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;var s,a=o.invm(this.n),h=a.mul(t).umod(this.n),u=a.mul(i).umod(this.n);return this.curve._maxwellTrick?!(s=this.g.jmulAdd(h,r.getPublic(),u)).isInfinity()&&s.eqXToP(i):!(s=this.g.mulAdd(h,r.getPublic(),u)).isInfinity()&&0===s.getX().umod(this.n).cmp(i)},Cn.prototype.recoverPubKey=function(t,e,r,n){In((3&r)===r,"The recovery param is more than two bits"),e=new An(e,n);var i=this.n,o=new f(t),s=e.r,a=e.s,h=1&r,u=r>>1;if(s.cmp(this.curve.p.umod(this.curve.n))>=0&&u)throw new Error("Unable to find sencond key candinate");s=u?this.curve.pointFromX(s.add(this.curve.n),h):this.curve.pointFromX(s,h);var l=e.r.invm(i),c=i.sub(o).mul(l).umod(i),d=a.mul(l).umod(i);return this.g.mulAdd(c,s,d)},Cn.prototype.getKeyRecoveryParam=function(t,e,r,n){if(null!==(e=new An(e,n)).recoveryParam)return e.recoveryParam;for(var i=0;i<4;i++){var o;try{o=this.recoverPubKey(t,e,i)}catch(t){continue}if(o.eq(r))return i}throw new Error("Unable to find valid recovery factor")};var Rn=$r((function(t,e){var r=e;r.version="6.5.4",r.utils=Qr,r.rand=function(){throw new Error("unsupported")},r.curve=dn,r.curves=pn,r.ec=Nn,r.eddsa=null})).ec;const kn=new b("signing-key/5.7.0");let Tn=null;function Dn(){return Tn||(Tn=new Rn("secp256k1")),Tn}class On{constructor(t){X(this,"curve","secp256k1"),X(this,"privateKey",k(t)),32!==T(this.privateKey)&&kn.throwArgumentError("invalid private key","privateKey","[[ REDACTED ]]");const e=Dn().keyFromPrivate(x(this.privateKey));X(this,"publicKey","0x"+e.getPublic(!1,"hex")),X(this,"compressedPublicKey","0x"+e.getPublic(!0,"hex")),X(this,"_isSigningKey",!0)}_addPoint(t){const e=Dn().keyFromPublic(x(this.publicKey)),r=Dn().keyFromPublic(x(t));return"0x"+e.pub.add(r.pub).encodeCompressed("hex")}signDigest(t){const e=Dn().keyFromPrivate(x(this.privateKey)),r=x(t);32!==r.length&&kn.throwArgumentError("bad digest length","digest",t);const n=e.sign(r,{canonical:!0});return B({recoveryParam:n.recoveryParam,r:F("0x"+n.r.toString(16),32),s:F("0x"+n.s.toString(16),32)})}computeSharedSecret(t){const e=Dn().keyFromPrivate(x(this.privateKey)),r=Dn().keyFromPublic(x(Fn(t)));return F("0x"+e.derive(r.getPublic()).toString(16),32)}static isSigningKey(t){return!(!t||!t._isSigningKey)}}function Fn(t,e){const r=x(t);if(32===r.length){const t=new On(r);return e?"0x"+Dn().keyFromPrivate(r).getPublic(!0,"hex"):t.publicKey}return 33===r.length?e?k(r):"0x"+Dn().keyFromPublic(r).getPublic(!1,"hex"):65===r.length?e?"0x"+Dn().keyFromPublic(r).getPublic(!0,"hex"):k(r):kn.throwArgumentError("invalid public or private key","key","[REDACTED]")}const Bn=new b("transactions/5.7.0");var Ln;!function(t){t[t.legacy=0]="legacy",t[t.eip2930=1]="eip2930",t[t.eip1559=2]="eip1559"}(Ln||(Ln={}));const Un=[{name:"nonce",maxLength:32,numeric:!0},{name:"gasPrice",maxLength:32,numeric:!0},{name:"gasLimit",maxLength:32,numeric:!0},{name:"to",length:20},{name:"value",maxLength:32,numeric:!0},{name:"data"}],Kn={chainId:!0,data:!0,gasLimit:!0,gasPrice:!0,nonce:!0,to:!0,type:!0,value:!0};function Gn(t){return vt(D(ht(D(Fn(t),1)),12))}function zn(t,e){const r=C(q.from(t).toHexString());return r.length>32&&Bn.throwArgumentError("invalid length for "+e,"transaction:"+e,t),r}function Hn(t,e){return{address:vt(t),storageKeys:(e||[]).map(((e,r)=>(32!==T(e)&&Bn.throwArgumentError("invalid access list storageKey",`accessList[${t}:${r}]`,e),e.toLowerCase())))}}function qn(t){return function(t){if(Array.isArray(t))return t.map(((t,e)=>Array.isArray(t)?(t.length>2&&Bn.throwArgumentError("access list expected to be [ address, storageKeys[] ]",`value[${e}]`,t),Hn(t[0],t[1])):Hn(t.address,t.storageKeys)));const e=Object.keys(t).map((e=>{const r=t[e].reduce(((t,e)=>(t[e]=!0,t)),{});return Hn(e,Object.keys(r).sort())}));return e.sort(((t,e)=>t.address.localeCompare(e.address))),e}(t).map((t=>[t.address,t.storageKeys]))}function jn(t,e){var r,n;n=Kn,(r=t)&&"object"==typeof r||Z.throwArgumentError("invalid object","object",r),Object.keys(r).forEach((t=>{n[t]||Z.throwArgumentError("invalid object key - "+t,"transaction:"+t,r)}));const i=[];Un.forEach((function(e){let r=t[e.name]||[];const n={};e.numeric&&(n.hexPad="left"),r=x(k(r,n)),e.length&&r.length!==e.length&&r.length>0&&Bn.throwArgumentError("invalid length for "+e.name,"transaction:"+e.name,r),e.maxLength&&(r=C(r),r.length>e.maxLength&&Bn.throwArgumentError("invalid length for "+e.name,"transaction:"+e.name,r)),i.push(k(r))}));let o=0;if(null!=t.chainId?(o=t.chainId,"number"!=typeof o&&Bn.throwArgumentError("invalid transaction.chainId","transaction",t)):e&&!E(e)&&e.v>28&&(o=Math.floor((e.v-35)/2)),0!==o&&(i.push(k(o)),i.push("0x"),i.push("0x")),!e)return ct(i);const s=B(e);let a=27+s.recoveryParam;return 0!==o?(i.pop(),i.pop(),i.pop(),a+=2*o+8,s.v>28&&s.v!==a&&Bn.throwArgumentError("transaction.chainId/signature.v mismatch","signature",e)):s.v!==a&&Bn.throwArgumentError("transaction.chainId/signature.v mismatch","signature",e),i.push(k(a)),i.push(C(x(s.r))),i.push(C(x(s.s))),ct(i)}function Wn(t,e){if(null==t.type||0===t.type)return null!=t.accessList&&Bn.throwArgumentError("untyped transactions do not support accessList; include type: 1","transaction",t),jn(t,e);switch(t.type){case 1:return function(t,e){const r=[zn(t.chainId||0,"chainId"),zn(t.nonce||0,"nonce"),zn(t.gasPrice||0,"gasPrice"),zn(t.gasLimit||0,"gasLimit"),null!=t.to?vt(t.to):"0x",zn(t.value||0,"value"),t.data||"0x",qn(t.accessList||[])];if(e){const t=B(e);r.push(zn(t.recoveryParam,"recoveryParam")),r.push(C(t.r)),r.push(C(t.s))}return O(["0x01",ct(r)])}(t,e);case 2:return function(t,e){if(null!=t.gasPrice){const e=q.from(t.gasPrice),r=q.from(t.maxFeePerGas||0);e.eq(r)||Bn.throwArgumentError("mismatch EIP-1559 gasPrice != maxFeePerGas","tx",{gasPrice:e,maxFeePerGas:r})}const r=[zn(t.chainId||0,"chainId"),zn(t.nonce||0,"nonce"),zn(t.maxPriorityFeePerGas||0,"maxPriorityFeePerGas"),zn(t.maxFeePerGas||0,"maxFeePerGas"),zn(t.gasLimit||0,"gasLimit"),null!=t.to?vt(t.to):"0x",zn(t.value||0,"value"),t.data||"0x",qn(t.accessList||[])];if(e){const t=B(e);r.push(zn(t.recoveryParam,"recoveryParam")),r.push(C(t.r)),r.push(C(t.s))}return O(["0x02",ct(r)])}(t,e)}return Bn.throwError(`unsupported transaction type: ${t.type}`,b.errors.UNSUPPORTED_OPERATION,{operation:"serializeTransaction",transactionType:t.type})}class Vn{constructor(t){X(this,"alphabet",t),X(this,"base",t.length),X(this,"_alphabetMap",{}),X(this,"_leader",t.charAt(0));for(let e=0;e<t.length;e++)this._alphabetMap[t.charAt(e)]=e}encode(t){let e=x(t);if(0===e.length)return"";let r=[0];for(let t=0;t<e.length;++t){let n=e[t];for(let t=0;t<r.length;++t)n+=r[t]<<8,r[t]=n%this.base,n=n/this.base|0;for(;n>0;)r.push(n%this.base),n=n/this.base|0}let n="";for(let t=0;0===e[t]&&t<e.length-1;++t)n+=this._leader;for(let t=r.length-1;t>=0;--t)n+=this.alphabet[r[t]];return n}decode(t){if("string"!=typeof t)throw new TypeError("Expected String");let e=[];if(0===t.length)return new Uint8Array(e);e.push(0);for(let r=0;r<t.length;r++){let n=this._alphabetMap[t[r]];if(void 0===n)throw new Error("Non-base"+this.base+" character");let i=n;for(let t=0;t<e.length;++t)i+=e[t]*this.base,e[t]=255&i,i>>=8;for(;i>0;)e.push(255&i),i>>=8}for(let r=0;t[r]===this._leader&&r<t.length-1;++r)e.push(0);return x(new Uint8Array(e.reverse()))}}new Vn("abcdefghijklmnopqrstuvwxyz234567");const Jn=new Vn("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");var $n;!function(t){t.sha256="sha256",t.sha512="sha512"}($n||($n={}));const Zn=new b("sha2/5.7.0");function Xn(t){return"0x"+Jr.sha256().update(x(t)).digest("hex")}function Yn(t,e,r){return $n[t]||Zn.throwError("unsupported algorithm "+t,b.errors.UNSUPPORTED_OPERATION,{operation:"hmac",algorithm:t}),"0x"+Jr.hmac(Jr[t],x(e)).update(x(r)).digest("hex")}function Qn(t,e,r,n,i){let o;t=x(t),e=x(e);let s=1;const a=new Uint8Array(n),h=new Uint8Array(e.length+4);let u,f;h.set(e);for(let l=1;l<=s;l++){h[e.length]=l>>24&255,h[e.length+1]=l>>16&255,h[e.length+2]=l>>8&255,h[e.length+3]=255&l;let c=x(Yn(i,t,h));o||(o=c.length,f=new Uint8Array(o),s=Math.ceil(n/o),u=n-(s-1)*o),f.set(c);for(let e=1;e<r;e++){c=x(Yn(i,t,c));for(let t=0;t<o;t++)f[t]^=c[t]}const d=(l-1)*o,p=l===s?u:o;a.set(x(f).slice(0,p),d)}return k(a)}const ti=new b("wordlists/5.7.0");class ei{constructor(t){ti.checkAbstract(new.target,ei),X(this,"locale",t)}split(t){return t.toLowerCase().split(/ +/g)}join(t){return t.join(" ")}static check(t){const e=[];for(let r=0;r<2048;r++){const n=t.getWord(r);if(r!==t.getWordIndex(n))return"0x";e.push(n)}return Mt(e.join("\n")+"\n")}static register(t,e){e||(e=t.locale)}}let ri=null;function ni(t){if(null==ri&&(ri="AbandonAbilityAbleAboutAboveAbsentAbsorbAbstractAbsurdAbuseAccessAccidentAccountAccuseAchieveAcidAcousticAcquireAcrossActActionActorActressActualAdaptAddAddictAddressAdjustAdmitAdultAdvanceAdviceAerobicAffairAffordAfraidAgainAgeAgentAgreeAheadAimAirAirportAisleAlarmAlbumAlcoholAlertAlienAllAlleyAllowAlmostAloneAlphaAlreadyAlsoAlterAlwaysAmateurAmazingAmongAmountAmusedAnalystAnchorAncientAngerAngleAngryAnimalAnkleAnnounceAnnualAnotherAnswerAntennaAntiqueAnxietyAnyApartApologyAppearAppleApproveAprilArchArcticAreaArenaArgueArmArmedArmorArmyAroundArrangeArrestArriveArrowArtArtefactArtistArtworkAskAspectAssaultAssetAssistAssumeAsthmaAthleteAtomAttackAttendAttitudeAttractAuctionAuditAugustAuntAuthorAutoAutumnAverageAvocadoAvoidAwakeAwareAwayAwesomeAwfulAwkwardAxisBabyBachelorBaconBadgeBagBalanceBalconyBallBambooBananaBannerBarBarelyBargainBarrelBaseBasicBasketBattleBeachBeanBeautyBecauseBecomeBeefBeforeBeginBehaveBehindBelieveBelowBeltBenchBenefitBestBetrayBetterBetweenBeyondBicycleBidBikeBindBiologyBirdBirthBitterBlackBladeBlameBlanketBlastBleakBlessBlindBloodBlossomBlouseBlueBlurBlushBoardBoatBodyBoilBombBoneBonusBookBoostBorderBoringBorrowBossBottomBounceBoxBoyBracketBrainBrandBrassBraveBreadBreezeBrickBridgeBriefBrightBringBriskBroccoliBrokenBronzeBroomBrotherBrownBrushBubbleBuddyBudgetBuffaloBuildBulbBulkBulletBundleBunkerBurdenBurgerBurstBusBusinessBusyButterBuyerBuzzCabbageCabinCableCactusCageCakeCallCalmCameraCampCanCanalCancelCandyCannonCanoeCanvasCanyonCapableCapitalCaptainCarCarbonCardCargoCarpetCarryCartCaseCashCasinoCastleCasualCatCatalogCatchCategoryCattleCaughtCauseCautionCaveCeilingCeleryCementCensusCenturyCerealCertainChairChalkChampionChangeChaosChapterChargeChaseChatCheapCheckCheeseChefCherryChestChickenChiefChildChimneyChoiceChooseChronicChuckleChunkChurnCigarCinnamonCircleCitizenCityCivilClaimClapClarifyClawClayCleanClerkCleverClickClientCliffClimbClinicClipClockClogCloseClothCloudClownClubClumpClusterClutchCoachCoastCoconutCodeCoffeeCoilCoinCollectColorColumnCombineComeComfortComicCommonCompanyConcertConductConfirmCongressConnectConsiderControlConvinceCookCoolCopperCopyCoralCoreCornCorrectCostCottonCouchCountryCoupleCourseCousinCoverCoyoteCrackCradleCraftCramCraneCrashCraterCrawlCrazyCreamCreditCreekCrewCricketCrimeCrispCriticCropCrossCrouchCrowdCrucialCruelCruiseCrumbleCrunchCrushCryCrystalCubeCultureCupCupboardCuriousCurrentCurtainCurveCushionCustomCuteCycleDadDamageDampDanceDangerDaringDashDaughterDawnDayDealDebateDebrisDecadeDecemberDecideDeclineDecorateDecreaseDeerDefenseDefineDefyDegreeDelayDeliverDemandDemiseDenialDentistDenyDepartDependDepositDepthDeputyDeriveDescribeDesertDesignDeskDespairDestroyDetailDetectDevelopDeviceDevoteDiagramDialDiamondDiaryDiceDieselDietDifferDigitalDignityDilemmaDinnerDinosaurDirectDirtDisagreeDiscoverDiseaseDishDismissDisorderDisplayDistanceDivertDivideDivorceDizzyDoctorDocumentDogDollDolphinDomainDonateDonkeyDonorDoorDoseDoubleDoveDraftDragonDramaDrasticDrawDreamDressDriftDrillDrinkDripDriveDropDrumDryDuckDumbDuneDuringDustDutchDutyDwarfDynamicEagerEagleEarlyEarnEarthEasilyEastEasyEchoEcologyEconomyEdgeEditEducateEffortEggEightEitherElbowElderElectricElegantElementElephantElevatorEliteElseEmbarkEmbodyEmbraceEmergeEmotionEmployEmpowerEmptyEnableEnactEndEndlessEndorseEnemyEnergyEnforceEngageEngineEnhanceEnjoyEnlistEnoughEnrichEnrollEnsureEnterEntireEntryEnvelopeEpisodeEqualEquipEraEraseErodeErosionErrorEruptEscapeEssayEssenceEstateEternalEthicsEvidenceEvilEvokeEvolveExactExampleExcessExchangeExciteExcludeExcuseExecuteExerciseExhaustExhibitExileExistExitExoticExpandExpectExpireExplainExposeExpressExtendExtraEyeEyebrowFabricFaceFacultyFadeFaintFaithFallFalseFameFamilyFamousFanFancyFantasyFarmFashionFatFatalFatherFatigueFaultFavoriteFeatureFebruaryFederalFeeFeedFeelFemaleFenceFestivalFetchFeverFewFiberFictionFieldFigureFileFilmFilterFinalFindFineFingerFinishFireFirmFirstFiscalFishFitFitnessFixFlagFlameFlashFlatFlavorFleeFlightFlipFloatFlockFloorFlowerFluidFlushFlyFoamFocusFogFoilFoldFollowFoodFootForceForestForgetForkFortuneForumForwardFossilFosterFoundFoxFragileFrameFrequentFreshFriendFringeFrogFrontFrostFrownFrozenFruitFuelFunFunnyFurnaceFuryFutureGadgetGainGalaxyGalleryGameGapGarageGarbageGardenGarlicGarmentGasGaspGateGatherGaugeGazeGeneralGeniusGenreGentleGenuineGestureGhostGiantGiftGiggleGingerGiraffeGirlGiveGladGlanceGlareGlassGlideGlimpseGlobeGloomGloryGloveGlowGlueGoatGoddessGoldGoodGooseGorillaGospelGossipGovernGownGrabGraceGrainGrantGrapeGrassGravityGreatGreenGridGriefGritGroceryGroupGrowGruntGuardGuessGuideGuiltGuitarGunGymHabitHairHalfHammerHamsterHandHappyHarborHardHarshHarvestHatHaveHawkHazardHeadHealthHeartHeavyHedgehogHeightHelloHelmetHelpHenHeroHiddenHighHillHintHipHireHistoryHobbyHockeyHoldHoleHolidayHollowHomeHoneyHoodHopeHornHorrorHorseHospitalHostHotelHourHoverHubHugeHumanHumbleHumorHundredHungryHuntHurdleHurryHurtHusbandHybridIceIconIdeaIdentifyIdleIgnoreIllIllegalIllnessImageImitateImmenseImmuneImpactImposeImproveImpulseInchIncludeIncomeIncreaseIndexIndicateIndoorIndustryInfantInflictInformInhaleInheritInitialInjectInjuryInmateInnerInnocentInputInquiryInsaneInsectInsideInspireInstallIntactInterestIntoInvestInviteInvolveIronIslandIsolateIssueItemIvoryJacketJaguarJarJazzJealousJeansJellyJewelJobJoinJokeJourneyJoyJudgeJuiceJumpJungleJuniorJunkJustKangarooKeenKeepKetchupKeyKickKidKidneyKindKingdomKissKitKitchenKiteKittenKiwiKneeKnifeKnockKnowLabLabelLaborLadderLadyLakeLampLanguageLaptopLargeLaterLatinLaughLaundryLavaLawLawnLawsuitLayerLazyLeaderLeafLearnLeaveLectureLeftLegLegalLegendLeisureLemonLendLengthLensLeopardLessonLetterLevelLiarLibertyLibraryLicenseLifeLiftLightLikeLimbLimitLinkLionLiquidListLittleLiveLizardLoadLoanLobsterLocalLockLogicLonelyLongLoopLotteryLoudLoungeLoveLoyalLuckyLuggageLumberLunarLunchLuxuryLyricsMachineMadMagicMagnetMaidMailMainMajorMakeMammalManManageMandateMangoMansionManualMapleMarbleMarchMarginMarineMarketMarriageMaskMassMasterMatchMaterialMathMatrixMatterMaximumMazeMeadowMeanMeasureMeatMechanicMedalMediaMelodyMeltMemberMemoryMentionMenuMercyMergeMeritMerryMeshMessageMetalMethodMiddleMidnightMilkMillionMimicMindMinimumMinorMinuteMiracleMirrorMiseryMissMistakeMixMixedMixtureMobileModelModifyMomMomentMonitorMonkeyMonsterMonthMoonMoralMoreMorningMosquitoMotherMotionMotorMountainMouseMoveMovieMuchMuffinMuleMultiplyMuscleMuseumMushroomMusicMustMutualMyselfMysteryMythNaiveNameNapkinNarrowNastyNationNatureNearNeckNeedNegativeNeglectNeitherNephewNerveNestNetNetworkNeutralNeverNewsNextNiceNightNobleNoiseNomineeNoodleNormalNorthNoseNotableNoteNothingNoticeNovelNowNuclearNumberNurseNutOakObeyObjectObligeObscureObserveObtainObviousOccurOceanOctoberOdorOffOfferOfficeOftenOilOkayOldOliveOlympicOmitOnceOneOnionOnlineOnlyOpenOperaOpinionOpposeOptionOrangeOrbitOrchardOrderOrdinaryOrganOrientOriginalOrphanOstrichOtherOutdoorOuterOutputOutsideOvalOvenOverOwnOwnerOxygenOysterOzonePactPaddlePagePairPalacePalmPandaPanelPanicPantherPaperParadeParentParkParrotPartyPassPatchPathPatientPatrolPatternPausePavePaymentPeacePeanutPearPeasantPelicanPenPenaltyPencilPeoplePepperPerfectPermitPersonPetPhonePhotoPhrasePhysicalPianoPicnicPicturePiecePigPigeonPillPilotPinkPioneerPipePistolPitchPizzaPlacePlanetPlasticPlatePlayPleasePledgePluckPlugPlungePoemPoetPointPolarPolePolicePondPonyPoolPopularPortionPositionPossiblePostPotatoPotteryPovertyPowderPowerPracticePraisePredictPreferPreparePresentPrettyPreventPricePridePrimaryPrintPriorityPrisonPrivatePrizeProblemProcessProduceProfitProgramProjectPromoteProofPropertyProsperProtectProudProvidePublicPuddingPullPulpPulsePumpkinPunchPupilPuppyPurchasePurityPurposePursePushPutPuzzlePyramidQualityQuantumQuarterQuestionQuickQuitQuizQuoteRabbitRaccoonRaceRackRadarRadioRailRainRaiseRallyRampRanchRandomRangeRapidRareRateRatherRavenRawRazorReadyRealReasonRebelRebuildRecallReceiveRecipeRecordRecycleReduceReflectReformRefuseRegionRegretRegularRejectRelaxReleaseReliefRelyRemainRememberRemindRemoveRenderRenewRentReopenRepairRepeatReplaceReportRequireRescueResembleResistResourceResponseResultRetireRetreatReturnReunionRevealReviewRewardRhythmRibRibbonRiceRichRideRidgeRifleRightRigidRingRiotRippleRiskRitualRivalRiverRoadRoastRobotRobustRocketRomanceRoofRookieRoomRoseRotateRoughRoundRouteRoyalRubberRudeRugRuleRunRunwayRuralSadSaddleSadnessSafeSailSaladSalmonSalonSaltSaluteSameSampleSandSatisfySatoshiSauceSausageSaveSayScaleScanScareScatterSceneSchemeSchoolScienceScissorsScorpionScoutScrapScreenScriptScrubSeaSearchSeasonSeatSecondSecretSectionSecuritySeedSeekSegmentSelectSellSeminarSeniorSenseSentenceSeriesServiceSessionSettleSetupSevenShadowShaftShallowShareShedShellSheriffShieldShiftShineShipShiverShockShoeShootShopShortShoulderShoveShrimpShrugShuffleShySiblingSickSideSiegeSightSignSilentSilkSillySilverSimilarSimpleSinceSingSirenSisterSituateSixSizeSkateSketchSkiSkillSkinSkirtSkullSlabSlamSleepSlenderSliceSlideSlightSlimSloganSlotSlowSlushSmallSmartSmileSmokeSmoothSnackSnakeSnapSniffSnowSoapSoccerSocialSockSodaSoftSolarSoldierSolidSolutionSolveSomeoneSongSoonSorrySortSoulSoundSoupSourceSouthSpaceSpareSpatialSpawnSpeakSpecialSpeedSpellSpendSphereSpiceSpiderSpikeSpinSpiritSplitSpoilSponsorSpoonSportSpotSpraySpreadSpringSpySquareSqueezeSquirrelStableStadiumStaffStageStairsStampStandStartStateStaySteakSteelStemStepStereoStickStillStingStockStomachStoneStoolStoryStoveStrategyStreetStrikeStrongStruggleStudentStuffStumbleStyleSubjectSubmitSubwaySuccessSuchSuddenSufferSugarSuggestSuitSummerSunSunnySunsetSuperSupplySupremeSureSurfaceSurgeSurpriseSurroundSurveySuspectSustainSwallowSwampSwapSwarmSwearSweetSwiftSwimSwingSwitchSwordSymbolSymptomSyrupSystemTableTackleTagTailTalentTalkTankTapeTargetTaskTasteTattooTaxiTeachTeamTellTenTenantTennisTentTermTestTextThankThatThemeThenTheoryThereTheyThingThisThoughtThreeThriveThrowThumbThunderTicketTideTigerTiltTimberTimeTinyTipTiredTissueTitleToastTobaccoTodayToddlerToeTogetherToiletTokenTomatoTomorrowToneTongueTonightToolToothTopTopicToppleTorchTornadoTortoiseTossTotalTouristTowardTowerTownToyTrackTradeTrafficTragicTrainTransferTrapTrashTravelTrayTreatTreeTrendTrialTribeTrickTriggerTrimTripTrophyTroubleTruckTrueTrulyTrumpetTrustTruthTryTubeTuitionTumbleTunaTunnelTurkeyTurnTurtleTwelveTwentyTwiceTwinTwistTwoTypeTypicalUglyUmbrellaUnableUnawareUncleUncoverUnderUndoUnfairUnfoldUnhappyUniformUniqueUnitUniverseUnknownUnlockUntilUnusualUnveilUpdateUpgradeUpholdUponUpperUpsetUrbanUrgeUsageUseUsedUsefulUselessUsualUtilityVacantVacuumVagueValidValleyValveVanVanishVaporVariousVastVaultVehicleVelvetVendorVentureVenueVerbVerifyVersionVeryVesselVeteranViableVibrantViciousVictoryVideoViewVillageVintageViolinVirtualVirusVisaVisitVisualVitalVividVocalVoiceVoidVolcanoVolumeVoteVoyageWageWagonWaitWalkWallWalnutWantWarfareWarmWarriorWashWaspWasteWaterWaveWayWealthWeaponWearWeaselWeatherWebWeddingWeekendWeirdWelcomeWestWetWhaleWhatWheatWheelWhenWhereWhipWhisperWideWidthWifeWildWillWinWindowWineWingWinkWinnerWinterWireWisdomWiseWishWitnessWolfWomanWonderWoodWoolWordWorkWorldWorryWorthWrapWreckWrestleWristWriteWrongYardYearYellowYouYoungYouthZebraZeroZoneZoo".replace(/([A-Z])/g," $1").toLowerCase().substring(1).split(" "),"0x3c8acc1e7b08d8e76f9fda015ef48dc8c710a73cb7e0f77b2c18a9b5a7adde60"!==ei.check(t)))throw ri=null,new Error("BIP39 Wordlist for en (English) FAILED")}const ii=new class extends ei{constructor(){super("en")}getWord(t){return ni(this),ri[t]}getWordIndex(t){return ni(this),ri.indexOf(t)}};ei.register(ii);const oi={en:ii},si=new b("hdnode/5.7.0"),ai=q.from("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),hi=At("Bitcoin seed"),ui=2147483648;function fi(t){return(1<<t)-1<<8-t}function li(t){return F(k(t),32)}function ci(t){return Jn.encode(I([t,D(Xn(Xn(t)),0,4)]))}function di(t){if(null==t)return oi.en;if("string"==typeof t){const e=oi[t];return null==e&&si.throwArgumentError("unknown locale","wordlist",t),e}return t}const pi={},mi="m/44'/60'/0'/0/0";class gi{constructor(t,e,r,n,i,o,s,a){if(t!==pi)throw new Error("HDNode constructor cannot be called directly");if(e){const t=new On(e);X(this,"privateKey",t.privateKey),X(this,"publicKey",t.compressedPublicKey)}else X(this,"privateKey",null),X(this,"publicKey",k(r));var h;X(this,"parentFingerprint",n),X(this,"fingerprint",D((h=Xn(this.publicKey),"0x"+Jr.ripemd160().update(x(h)).digest("hex")),0,4)),X(this,"address",Gn(this.publicKey)),X(this,"chainCode",i),X(this,"index",o),X(this,"depth",s),null==a?(X(this,"mnemonic",null),X(this,"path",null)):"string"==typeof a?(X(this,"mnemonic",null),X(this,"path",a)):(X(this,"mnemonic",a),X(this,"path",a.path))}get extendedKey(){if(this.depth>=256)throw new Error("Depth too large!");return ci(I([null!=this.privateKey?"0x0488ADE4":"0x0488B21E",k(this.depth),this.parentFingerprint,F(k(this.index),4),this.chainCode,null!=this.privateKey?I(["0x00",this.privateKey]):this.publicKey]))}neuter(){return new gi(pi,null,this.publicKey,this.parentFingerprint,this.chainCode,this.index,this.depth,this.path)}_derive(t){if(t>4294967295)throw new Error("invalid index - "+String(t));let e=this.path;e&&(e+="/"+(2147483647&t));const r=new Uint8Array(37);if(t&ui){if(!this.privateKey)throw new Error("cannot derive child of neutered node");r.set(x(this.privateKey),1),e&&(e+="'")}else r.set(x(this.publicKey));for(let e=24;e>=0;e-=8)r[33+(e>>3)]=t>>24-e&255;const n=x(Yn($n.sha512,this.chainCode,r)),i=n.slice(0,32),o=n.slice(32);let s=null,a=null;if(this.privateKey)s=li(q.from(i).add(this.privateKey).mod(ai));else{a=new On(k(i))._addPoint(this.publicKey)}let h=e;const u=this.mnemonic;return u&&(h=Object.freeze({phrase:u.phrase,path:e,locale:u.locale||"en"})),new gi(pi,s,a,this.fingerprint,li(o),t,this.depth+1,h)}derivePath(t){const e=t.split("/");if(0===e.length||"m"===e[0]&&0!==this.depth)throw new Error("invalid path - "+t);"m"===e[0]&&e.shift();let r=this;for(let t=0;t<e.length;t++){const n=e[t];if(n.match(/^[0-9]+'$/)){const t=parseInt(n.substring(0,n.length-1));if(t>=ui)throw new Error("invalid path index - "+n);r=r._derive(ui+t)}else{if(!n.match(/^[0-9]+$/))throw new Error("invalid path component - "+n);{const t=parseInt(n);if(t>=ui)throw new Error("invalid path index - "+n);r=r._derive(t)}}}return r}static _fromSeed(t,e){const r=x(t);if(r.length<16||r.length>64)throw new Error("invalid seed");const n=x(Yn($n.sha512,hi,r));return new gi(pi,li(n.slice(0,32)),null,"0x00000000",li(n.slice(32)),0,0,e)}static fromMnemonic(t,e,r){return t=vi(yi(t,r=di(r)),r),gi._fromSeed(function(t,e){e||(e="");const r=At("mnemonic"+e,bt.NFKD);return Qn(At(t,bt.NFKD),r,2048,64,"sha512")}(t,e),{phrase:t,path:"m",locale:r.locale})}static fromSeed(t){return gi._fromSeed(t,null)}static fromExtendedKey(t){const e=Jn.decode(t);82===e.length&&ci(e.slice(0,78))===t||si.throwArgumentError("invalid extended key","extendedKey","[REDACTED]");const r=e[4],n=k(e.slice(5,9)),i=parseInt(k(e.slice(9,13)).substring(2),16),o=k(e.slice(13,45)),s=e.slice(45,78);switch(k(e.slice(0,4))){case"0x0488b21e":case"0x043587cf":return new gi(pi,null,k(s),n,o,i,r,null);case"0x0488ade4":case"0x04358394 ":if(0!==s[0])break;return new gi(pi,k(s.slice(1)),null,n,o,i,r,null)}return si.throwArgumentError("invalid extended key","extendedKey","[REDACTED]")}}function yi(t,e){e=di(e),si.checkNormalize();const r=e.split(t);if(r.length%3!=0)throw new Error("invalid mnemonic");const n=x(new Uint8Array(Math.ceil(11*r.length/8)));let i=0;for(let t=0;t<r.length;t++){let o=e.getWordIndex(r[t].normalize("NFKD"));if(-1===o)throw new Error("invalid mnemonic");for(let t=0;t<11;t++)o&1<<10-t&&(n[i>>3]|=1<<7-i%8),i++}const o=32*r.length/3,s=fi(r.length/3);if((x(Xn(n.slice(0,o/8)))[0]&s)!==(n[n.length-1]&s))throw new Error("invalid checksum");return k(n.slice(0,o/8))}function vi(t,e){if(e=di(e),(t=x(t)).length%4!=0||t.length<16||t.length>32)throw new Error("invalid entropy");const r=[0];let n=11;for(let e=0;e<t.length;e++)n>8?(r[r.length-1]<<=8,r[r.length-1]|=t[e],n-=8):(r[r.length-1]<<=n,r[r.length-1]|=t[e]>>8-n,r.push(t[e]&(1<<8-n)-1),n+=3);const i=t.length/4,o=x(Xn(t))[0]&fi(i);return r[r.length-1]<<=i,r[r.length-1]|=o>>8-i,e.join(r.map((t=>e.getWord(t))))}const wi=new b("random/5.7.0");const bi=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("unable to locate global object")}();let Si=bi.crypto||bi.msCrypto;function Ai(t){(t<=0||t>1024||t%1||t!=t)&&wi.throwArgumentError("invalid length","length",t);const e=new Uint8Array(t);return Si.getRandomValues(e),x(e)}Si&&Si.getRandomValues||(wi.warn("WARNING: Missing strong random number source"),Si={getRandomValues:function(t){return wi.throwError("no secure random source avaialble",b.errors.UNSUPPORTED_OPERATION,{operation:"crypto.getRandomValues"})}});var Mi={exports:{}};!function(t){!function(){function e(t){return parseInt(t)===t}function r(t){if(!e(t.length))return!1;for(var r=0;r<t.length;r++)if(!e(t[r])||t[r]<0||t[r]>255)return!1;return!0}function n(t,n){if(t.buffer&&ArrayBuffer.isView(t)&&"Uint8Array"===t.name)return n&&(t=t.slice?t.slice():Array.prototype.slice.call(t)),t;if(Array.isArray(t)){if(!r(t))throw new Error("Array contains invalid value: "+t);return new Uint8Array(t)}if(e(t.length)&&r(t))return new Uint8Array(t);throw new Error("unsupported array-like object")}function i(t){return new Uint8Array(t)}function o(t,e,r,n,i){null==n&&null==i||(t=t.slice?t.slice(n,i):Array.prototype.slice.call(t,n,i)),e.set(t,r)}var s,a={toBytes:function(t){var e=[],r=0;for(t=encodeURI(t);r<t.length;){var i=t.charCodeAt(r++);37===i?(e.push(parseInt(t.substr(r,2),16)),r+=2):e.push(i)}return n(e)},fromBytes:function(t){for(var e=[],r=0;r<t.length;){var n=t[r];n<128?(e.push(String.fromCharCode(n)),r++):n>191&&n<224?(e.push(String.fromCharCode((31&n)<<6|63&t[r+1])),r+=2):(e.push(String.fromCharCode((15&n)<<12|(63&t[r+1])<<6|63&t[r+2])),r+=3)}return e.join("")}},h=(s="0123456789abcdef",{toBytes:function(t){for(var e=[],r=0;r<t.length;r+=2)e.push(parseInt(t.substr(r,2),16));return e},fromBytes:function(t){for(var e=[],r=0;r<t.length;r++){var n=t[r];e.push(s[(240&n)>>4]+s[15&n])}return e.join("")}}),u={16:10,24:12,32:14},f=[1,2,4,8,16,32,64,128,27,54,108,216,171,77,154,47,94,188,99,198,151,53,106,212,179,125,250,239,197,145],l=[99,124,119,123,242,107,111,197,48,1,103,43,254,215,171,118,202,130,201,125,250,89,71,240,173,212,162,175,156,164,114,192,183,253,147,38,54,63,247,204,52,165,229,241,113,216,49,21,4,199,35,195,24,150,5,154,7,18,128,226,235,39,178,117,9,131,44,26,27,110,90,160,82,59,214,179,41,227,47,132,83,209,0,237,32,252,177,91,106,203,190,57,74,76,88,207,208,239,170,251,67,77,51,133,69,249,2,127,80,60,159,168,81,163,64,143,146,157,56,245,188,182,218,33,16,255,243,210,205,12,19,236,95,151,68,23,196,167,126,61,100,93,25,115,96,129,79,220,34,42,144,136,70,238,184,20,222,94,11,219,224,50,58,10,73,6,36,92,194,211,172,98,145,149,228,121,231,200,55,109,141,213,78,169,108,86,244,234,101,122,174,8,186,120,37,46,28,166,180,198,232,221,116,31,75,189,139,138,112,62,181,102,72,3,246,14,97,53,87,185,134,193,29,158,225,248,152,17,105,217,142,148,155,30,135,233,206,85,40,223,140,161,137,13,191,230,66,104,65,153,45,15,176,84,187,22],c=[82,9,106,213,48,54,165,56,191,64,163,158,129,243,215,251,124,227,57,130,155,47,255,135,52,142,67,68,196,222,233,203,84,123,148,50,166,194,35,61,238,76,149,11,66,250,195,78,8,46,161,102,40,217,36,178,118,91,162,73,109,139,209,37,114,248,246,100,134,104,152,22,212,164,92,204,93,101,182,146,108,112,72,80,253,237,185,218,94,21,70,87,167,141,157,132,144,216,171,0,140,188,211,10,247,228,88,5,184,179,69,6,208,44,30,143,202,63,15,2,193,175,189,3,1,19,138,107,58,145,17,65,79,103,220,234,151,242,207,206,240,180,230,115,150,172,116,34,231,173,53,133,226,249,55,232,28,117,223,110,71,241,26,113,29,41,197,137,111,183,98,14,170,24,190,27,252,86,62,75,198,210,121,32,154,219,192,254,120,205,90,244,31,221,168,51,136,7,199,49,177,18,16,89,39,128,236,95,96,81,127,169,25,181,74,13,45,229,122,159,147,201,156,239,160,224,59,77,174,42,245,176,200,235,187,60,131,83,153,97,23,43,4,126,186,119,214,38,225,105,20,99,85,33,12,125],d=[3328402341,4168907908,4000806809,4135287693,4294111757,3597364157,3731845041,2445657428,1613770832,33620227,3462883241,1445669757,3892248089,3050821474,1303096294,3967186586,2412431941,528646813,2311702848,4202528135,4026202645,2992200171,2387036105,4226871307,1101901292,3017069671,1604494077,1169141738,597466303,1403299063,3832705686,2613100635,1974974402,3791519004,1033081774,1277568618,1815492186,2118074177,4126668546,2211236943,1748251740,1369810420,3521504564,4193382664,3799085459,2883115123,1647391059,706024767,134480908,2512897874,1176707941,2646852446,806885416,932615841,168101135,798661301,235341577,605164086,461406363,3756188221,3454790438,1311188841,2142417613,3933566367,302582043,495158174,1479289972,874125870,907746093,3698224818,3025820398,1537253627,2756858614,1983593293,3084310113,2108928974,1378429307,3722699582,1580150641,327451799,2790478837,3117535592,0,3253595436,1075847264,3825007647,2041688520,3059440621,3563743934,2378943302,1740553945,1916352843,2487896798,2555137236,2958579944,2244988746,3151024235,3320835882,1336584933,3992714006,2252555205,2588757463,1714631509,293963156,2319795663,3925473552,67240454,4269768577,2689618160,2017213508,631218106,1269344483,2723238387,1571005438,2151694528,93294474,1066570413,563977660,1882732616,4059428100,1673313503,2008463041,2950355573,1109467491,537923632,3858759450,4260623118,3218264685,2177748300,403442708,638784309,3287084079,3193921505,899127202,2286175436,773265209,2479146071,1437050866,4236148354,2050833735,3362022572,3126681063,840505643,3866325909,3227541664,427917720,2655997905,2749160575,1143087718,1412049534,999329963,193497219,2353415882,3354324521,1807268051,672404540,2816401017,3160301282,369822493,2916866934,3688947771,1681011286,1949973070,336202270,2454276571,201721354,1210328172,3093060836,2680341085,3184776046,1135389935,3294782118,965841320,831886756,3554993207,4068047243,3588745010,2345191491,1849112409,3664604599,26054028,2983581028,2622377682,1235855840,3630984372,2891339514,4092916743,3488279077,3395642799,4101667470,1202630377,268961816,1874508501,4034427016,1243948399,1546530418,941366308,1470539505,1941222599,2546386513,3421038627,2715671932,3899946140,1042226977,2521517021,1639824860,227249030,260737669,3765465232,2084453954,1907733956,3429263018,2420656344,100860677,4160157185,470683154,3261161891,1781871967,2924959737,1773779408,394692241,2579611992,974986535,664706745,3655459128,3958962195,731420851,571543859,3530123707,2849626480,126783113,865375399,765172662,1008606754,361203602,3387549984,2278477385,2857719295,1344809080,2782912378,59542671,1503764984,160008576,437062935,1707065306,3622233649,2218934982,3496503480,2185314755,697932208,1512910199,504303377,2075177163,2824099068,1841019862,739644986],p=[2781242211,2230877308,2582542199,2381740923,234877682,3184946027,2984144751,1418839493,1348481072,50462977,2848876391,2102799147,434634494,1656084439,3863849899,2599188086,1167051466,2636087938,1082771913,2281340285,368048890,3954334041,3381544775,201060592,3963727277,1739838676,4250903202,3930435503,3206782108,4149453988,2531553906,1536934080,3262494647,484572669,2923271059,1783375398,1517041206,1098792767,49674231,1334037708,1550332980,4098991525,886171109,150598129,2481090929,1940642008,1398944049,1059722517,201851908,1385547719,1699095331,1587397571,674240536,2704774806,252314885,3039795866,151914247,908333586,2602270848,1038082786,651029483,1766729511,3447698098,2682942837,454166793,2652734339,1951935532,775166490,758520603,3000790638,4004797018,4217086112,4137964114,1299594043,1639438038,3464344499,2068982057,1054729187,1901997871,2534638724,4121318227,1757008337,0,750906861,1614815264,535035132,3363418545,3988151131,3201591914,1183697867,3647454910,1265776953,3734260298,3566750796,3903871064,1250283471,1807470800,717615087,3847203498,384695291,3313910595,3617213773,1432761139,2484176261,3481945413,283769337,100925954,2180939647,4037038160,1148730428,3123027871,3813386408,4087501137,4267549603,3229630528,2315620239,2906624658,3156319645,1215313976,82966005,3747855548,3245848246,1974459098,1665278241,807407632,451280895,251524083,1841287890,1283575245,337120268,891687699,801369324,3787349855,2721421207,3431482436,959321879,1469301956,4065699751,2197585534,1199193405,2898814052,3887750493,724703513,2514908019,2696962144,2551808385,3516813135,2141445340,1715741218,2119445034,2872807568,2198571144,3398190662,700968686,3547052216,1009259540,2041044702,3803995742,487983883,1991105499,1004265696,1449407026,1316239930,504629770,3683797321,168560134,1816667172,3837287516,1570751170,1857934291,4014189740,2797888098,2822345105,2754712981,936633572,2347923833,852879335,1133234376,1500395319,3084545389,2348912013,1689376213,3533459022,3762923945,3034082412,4205598294,133428468,634383082,2949277029,2398386810,3913789102,403703816,3580869306,2297460856,1867130149,1918643758,607656988,4049053350,3346248884,1368901318,600565992,2090982877,2632479860,557719327,3717614411,3697393085,2249034635,2232388234,2430627952,1115438654,3295786421,2865522278,3633334344,84280067,33027830,303828494,2747425121,1600795957,4188952407,3496589753,2434238086,1486471617,658119965,3106381470,953803233,334231800,3005978776,857870609,3151128937,1890179545,2298973838,2805175444,3056442267,574365214,2450884487,550103529,1233637070,4289353045,2018519080,2057691103,2399374476,4166623649,2148108681,387583245,3664101311,836232934,3330556482,3100665960,3280093505,2955516313,2002398509,287182607,3413881008,4238890068,3597515707,975967766],m=[1671808611,2089089148,2006576759,2072901243,4061003762,1807603307,1873927791,3310653893,810573872,16974337,1739181671,729634347,4263110654,3613570519,2883997099,1989864566,3393556426,2191335298,3376449993,2106063485,4195741690,1508618841,1204391495,4027317232,2917941677,3563566036,2734514082,2951366063,2629772188,2767672228,1922491506,3227229120,3082974647,4246528509,2477669779,644500518,911895606,1061256767,4144166391,3427763148,878471220,2784252325,3845444069,4043897329,1905517169,3631459288,827548209,356461077,67897348,3344078279,593839651,3277757891,405286936,2527147926,84871685,2595565466,118033927,305538066,2157648768,3795705826,3945188843,661212711,2999812018,1973414517,152769033,2208177539,745822252,439235610,455947803,1857215598,1525593178,2700827552,1391895634,994932283,3596728278,3016654259,695947817,3812548067,795958831,2224493444,1408607827,3513301457,0,3979133421,543178784,4229948412,2982705585,1542305371,1790891114,3410398667,3201918910,961245753,1256100938,1289001036,1491644504,3477767631,3496721360,4012557807,2867154858,4212583931,1137018435,1305975373,861234739,2241073541,1171229253,4178635257,33948674,2139225727,1357946960,1011120188,2679776671,2833468328,1374921297,2751356323,1086357568,2408187279,2460827538,2646352285,944271416,4110742005,3168756668,3066132406,3665145818,560153121,271589392,4279952895,4077846003,3530407890,3444343245,202643468,322250259,3962553324,1608629855,2543990167,1154254916,389623319,3294073796,2817676711,2122513534,1028094525,1689045092,1575467613,422261273,1939203699,1621147744,2174228865,1339137615,3699352540,577127458,712922154,2427141008,2290289544,1187679302,3995715566,3100863416,339486740,3732514782,1591917662,186455563,3681988059,3762019296,844522546,978220090,169743370,1239126601,101321734,611076132,1558493276,3260915650,3547250131,2901361580,1655096418,2443721105,2510565781,3828863972,2039214713,3878868455,3359869896,928607799,1840765549,2374762893,3580146133,1322425422,2850048425,1823791212,1459268694,4094161908,3928346602,1706019429,2056189050,2934523822,135794696,3134549946,2022240376,628050469,779246638,472135708,2800834470,3032970164,3327236038,3894660072,3715932637,1956440180,522272287,1272813131,3185336765,2340818315,2323976074,1888542832,1044544574,3049550261,1722469478,1222152264,50660867,4127324150,236067854,1638122081,895445557,1475980887,3117443513,2257655686,3243809217,489110045,2662934430,3778599393,4162055160,2561878936,288563729,1773916777,3648039385,2391345038,2493985684,2612407707,505560094,2274497927,3911240169,3460925390,1442818645,678973480,3749357023,2358182796,2717407649,2306869641,219617805,3218761151,3862026214,1120306242,1756942440,1103331905,2578459033,762796589,252780047,2966125488,1425844308,3151392187,372911126],g=[1667474886,2088535288,2004326894,2071694838,4075949567,1802223062,1869591006,3318043793,808472672,16843522,1734846926,724270422,4278065639,3621216949,2880169549,1987484396,3402253711,2189597983,3385409673,2105378810,4210693615,1499065266,1195886990,4042263547,2913856577,3570689971,2728590687,2947541573,2627518243,2762274643,1920112356,3233831835,3082273397,4261223649,2475929149,640051788,909531756,1061110142,4160160501,3435941763,875846760,2779116625,3857003729,4059105529,1903268834,3638064043,825316194,353713962,67374088,3351728789,589522246,3284360861,404236336,2526454071,84217610,2593830191,117901582,303183396,2155911963,3806477791,3958056653,656894286,2998062463,1970642922,151591698,2206440989,741110872,437923380,454765878,1852748508,1515908788,2694904667,1381168804,993742198,3604373943,3014905469,690584402,3823320797,791638366,2223281939,1398011302,3520161977,0,3991743681,538992704,4244381667,2981218425,1532751286,1785380564,3419096717,3200178535,960056178,1246420628,1280103576,1482221744,3486468741,3503319995,4025428677,2863326543,4227536621,1128514950,1296947098,859002214,2240123921,1162203018,4193849577,33687044,2139062782,1347481760,1010582648,2678045221,2829640523,1364325282,2745433693,1077985408,2408548869,2459086143,2644360225,943212656,4126475505,3166494563,3065430391,3671750063,555836226,269496352,4294908645,4092792573,3537006015,3452783745,202118168,320025894,3974901699,1600119230,2543297077,1145359496,387397934,3301201811,2812801621,2122220284,1027426170,1684319432,1566435258,421079858,1936954854,1616945344,2172753945,1330631070,3705438115,572679748,707427924,2425400123,2290647819,1179044492,4008585671,3099120491,336870440,3739122087,1583276732,185277718,3688593069,3772791771,842159716,976899700,168435220,1229577106,101059084,606366792,1549591736,3267517855,3553849021,2897014595,1650632388,2442242105,2509612081,3840161747,2038008818,3890688725,3368567691,926374254,1835907034,2374863873,3587531953,1313788572,2846482505,1819063512,1448540844,4109633523,3941213647,1701162954,2054852340,2930698567,134748176,3132806511,2021165296,623210314,774795868,471606328,2795958615,3031746419,3334885783,3907527627,3722280097,1953799400,522133822,1263263126,3183336545,2341176845,2324333839,1886425312,1044267644,3048588401,1718004428,1212733584,50529542,4143317495,235803164,1633788866,892690282,1465383342,3115962473,2256965911,3250673817,488449850,2661202215,3789633753,4177007595,2560144171,286339874,1768537042,3654906025,2391705863,2492770099,2610673197,505291324,2273808917,3924369609,3469625735,1431699370,673740880,3755965093,2358021891,2711746649,2307489801,218961690,3217021541,3873845719,1111672452,1751693520,1094828930,2576986153,757954394,252645662,2964376443,1414855848,3149649517,370555436],y=[1374988112,2118214995,437757123,975658646,1001089995,530400753,2902087851,1273168787,540080725,2910219766,2295101073,4110568485,1340463100,3307916247,641025152,3043140495,3736164937,632953703,1172967064,1576976609,3274667266,2169303058,2370213795,1809054150,59727847,361929877,3211623147,2505202138,3569255213,1484005843,1239443753,2395588676,1975683434,4102977912,2572697195,666464733,3202437046,4035489047,3374361702,2110667444,1675577880,3843699074,2538681184,1649639237,2976151520,3144396420,4269907996,4178062228,1883793496,2403728665,2497604743,1383856311,2876494627,1917518562,3810496343,1716890410,3001755655,800440835,2261089178,3543599269,807962610,599762354,33778362,3977675356,2328828971,2809771154,4077384432,1315562145,1708848333,101039829,3509871135,3299278474,875451293,2733856160,92987698,2767645557,193195065,1080094634,1584504582,3178106961,1042385657,2531067453,3711829422,1306967366,2438237621,1908694277,67556463,1615861247,429456164,3602770327,2302690252,1742315127,2968011453,126454664,3877198648,2043211483,2709260871,2084704233,4169408201,0,159417987,841739592,504459436,1817866830,4245618683,260388950,1034867998,908933415,168810852,1750902305,2606453969,607530554,202008497,2472011535,3035535058,463180190,2160117071,1641816226,1517767529,470948374,3801332234,3231722213,1008918595,303765277,235474187,4069246893,766945465,337553864,1475418501,2943682380,4003061179,2743034109,4144047775,1551037884,1147550661,1543208500,2336434550,3408119516,3069049960,3102011747,3610369226,1113818384,328671808,2227573024,2236228733,3535486456,2935566865,3341394285,496906059,3702665459,226906860,2009195472,733156972,2842737049,294930682,1206477858,2835123396,2700099354,1451044056,573804783,2269728455,3644379585,2362090238,2564033334,2801107407,2776292904,3669462566,1068351396,742039012,1350078989,1784663195,1417561698,4136440770,2430122216,775550814,2193862645,2673705150,1775276924,1876241833,3475313331,3366754619,270040487,3902563182,3678124923,3441850377,1851332852,3969562369,2203032232,3868552805,2868897406,566021896,4011190502,3135740889,1248802510,3936291284,699432150,832877231,708780849,3332740144,899835584,1951317047,4236429990,3767586992,866637845,4043610186,1106041591,2144161806,395441711,1984812685,1139781709,3433712980,3835036895,2664543715,1282050075,3240894392,1181045119,2640243204,25965917,4203181171,4211818798,3009879386,2463879762,3910161971,1842759443,2597806476,933301370,1509430414,3943906441,3467192302,3076639029,3776767469,2051518780,2631065433,1441952575,404016761,1942435775,1408749034,1610459739,3745345300,2017778566,3400528769,3110650942,941896748,3265478751,371049330,3168937228,675039627,4279080257,967311729,135050206,3635733660,1683407248,2076935265,3576870512,1215061108,3501741890],v=[1347548327,1400783205,3273267108,2520393566,3409685355,4045380933,2880240216,2471224067,1428173050,4138563181,2441661558,636813900,4233094615,3620022987,2149987652,2411029155,1239331162,1730525723,2554718734,3781033664,46346101,310463728,2743944855,3328955385,3875770207,2501218972,3955191162,3667219033,768917123,3545789473,692707433,1150208456,1786102409,2029293177,1805211710,3710368113,3065962831,401639597,1724457132,3028143674,409198410,2196052529,1620529459,1164071807,3769721975,2226875310,486441376,2499348523,1483753576,428819965,2274680428,3075636216,598438867,3799141122,1474502543,711349675,129166120,53458370,2592523643,2782082824,4063242375,2988687269,3120694122,1559041666,730517276,2460449204,4042459122,2706270690,3446004468,3573941694,533804130,2328143614,2637442643,2695033685,839224033,1973745387,957055980,2856345839,106852767,1371368976,4181598602,1033297158,2933734917,1179510461,3046200461,91341917,1862534868,4284502037,605657339,2547432937,3431546947,2003294622,3182487618,2282195339,954669403,3682191598,1201765386,3917234703,3388507166,0,2198438022,1211247597,2887651696,1315723890,4227665663,1443857720,507358933,657861945,1678381017,560487590,3516619604,975451694,2970356327,261314535,3535072918,2652609425,1333838021,2724322336,1767536459,370938394,182621114,3854606378,1128014560,487725847,185469197,2918353863,3106780840,3356761769,2237133081,1286567175,3152976349,4255350624,2683765030,3160175349,3309594171,878443390,1988838185,3704300486,1756818940,1673061617,3403100636,272786309,1075025698,545572369,2105887268,4174560061,296679730,1841768865,1260232239,4091327024,3960309330,3497509347,1814803222,2578018489,4195456072,575138148,3299409036,446754879,3629546796,4011996048,3347532110,3252238545,4270639778,915985419,3483825537,681933534,651868046,2755636671,3828103837,223377554,2607439820,1649704518,3270937875,3901806776,1580087799,4118987695,3198115200,2087309459,2842678573,3016697106,1003007129,2802849917,1860738147,2077965243,164439672,4100872472,32283319,2827177882,1709610350,2125135846,136428751,3874428392,3652904859,3460984630,3572145929,3593056380,2939266226,824852259,818324884,3224740454,930369212,2801566410,2967507152,355706840,1257309336,4148292826,243256656,790073846,2373340630,1296297904,1422699085,3756299780,3818836405,457992840,3099667487,2135319889,77422314,1560382517,1945798516,788204353,1521706781,1385356242,870912086,325965383,2358957921,2050466060,2388260884,2313884476,4006521127,901210569,3990953189,1014646705,1503449823,1062597235,2031621326,3212035895,3931371469,1533017514,350174575,2256028891,2177544179,1052338372,741876788,1606591296,1914052035,213705253,2334669897,1107234197,1899603969,3725069491,2631447780,2422494913,1635502980,1893020342,1950903388,1120974935],w=[2807058932,1699970625,2764249623,1586903591,1808481195,1173430173,1487645946,59984867,4199882800,1844882806,1989249228,1277555970,3623636965,3419915562,1149249077,2744104290,1514790577,459744698,244860394,3235995134,1963115311,4027744588,2544078150,4190530515,1608975247,2627016082,2062270317,1507497298,2200818878,567498868,1764313568,3359936201,2305455554,2037970062,1047239e3,1910319033,1337376481,2904027272,2892417312,984907214,1243112415,830661914,861968209,2135253587,2011214180,2927934315,2686254721,731183368,1750626376,4246310725,1820824798,4172763771,3542330227,48394827,2404901663,2871682645,671593195,3254988725,2073724613,145085239,2280796200,2779915199,1790575107,2187128086,472615631,3029510009,4075877127,3802222185,4107101658,3201631749,1646252340,4270507174,1402811438,1436590835,3778151818,3950355702,3963161475,4020912224,2667994737,273792366,2331590177,104699613,95345982,3175501286,2377486676,1560637892,3564045318,369057872,4213447064,3919042237,1137477952,2658625497,1119727848,2340947849,1530455833,4007360968,172466556,266959938,516552836,0,2256734592,3980931627,1890328081,1917742170,4294704398,945164165,3575528878,958871085,3647212047,2787207260,1423022939,775562294,1739656202,3876557655,2530391278,2443058075,3310321856,547512796,1265195639,437656594,3121275539,719700128,3762502690,387781147,218828297,3350065803,2830708150,2848461854,428169201,122466165,3720081049,1627235199,648017665,4122762354,1002783846,2117360635,695634755,3336358691,4234721005,4049844452,3704280881,2232435299,574624663,287343814,612205898,1039717051,840019705,2708326185,793451934,821288114,1391201670,3822090177,376187827,3113855344,1224348052,1679968233,2361698556,1058709744,752375421,2431590963,1321699145,3519142200,2734591178,188127444,2177869557,3727205754,2384911031,3215212461,2648976442,2450346104,3432737375,1180849278,331544205,3102249176,4150144569,2952102595,2159976285,2474404304,766078933,313773861,2570832044,2108100632,1668212892,3145456443,2013908262,418672217,3070356634,2594734927,1852171925,3867060991,3473416636,3907448597,2614737639,919489135,164948639,2094410160,2997825956,590424639,2486224549,1723872674,3157750862,3399941250,3501252752,3625268135,2555048196,3673637356,1343127501,4130281361,3599595085,2957853679,1297403050,81781910,3051593425,2283490410,532201772,1367295589,3926170974,895287692,1953757831,1093597963,492483431,3528626907,1446242576,1192455638,1636604631,209336225,344873464,1015671571,669961897,3375740769,3857572124,2973530695,3747192018,1933530610,3464042516,935293895,3454686199,2858115069,1863638845,3683022916,4085369519,3292445032,875313188,1080017571,3279033885,621591778,1233856572,2504130317,24197544,3017672716,3835484340,3247465558,2220981195,3060847922,1551124588,1463996600],b=[4104605777,1097159550,396673818,660510266,2875968315,2638606623,4200115116,3808662347,821712160,1986918061,3430322568,38544885,3856137295,718002117,893681702,1654886325,2975484382,3122358053,3926825029,4274053469,796197571,1290801793,1184342925,3556361835,2405426947,2459735317,1836772287,1381620373,3196267988,1948373848,3764988233,3385345166,3263785589,2390325492,1480485785,3111247143,3780097726,2293045232,548169417,3459953789,3746175075,439452389,1362321559,1400849762,1685577905,1806599355,2174754046,137073913,1214797936,1174215055,3731654548,2079897426,1943217067,1258480242,529487843,1437280870,3945269170,3049390895,3313212038,923313619,679998e3,3215307299,57326082,377642221,3474729866,2041877159,133361907,1776460110,3673476453,96392454,878845905,2801699524,777231668,4082475170,2330014213,4142626212,2213296395,1626319424,1906247262,1846563261,562755902,3708173718,1040559837,3871163981,1418573201,3294430577,114585348,1343618912,2566595609,3186202582,1078185097,3651041127,3896688048,2307622919,425408743,3371096953,2081048481,1108339068,2216610296,0,2156299017,736970802,292596766,1517440620,251657213,2235061775,2933202493,758720310,265905162,1554391400,1532285339,908999204,174567692,1474760595,4002861748,2610011675,3234156416,3693126241,2001430874,303699484,2478443234,2687165888,585122620,454499602,151849742,2345119218,3064510765,514443284,4044981591,1963412655,2581445614,2137062819,19308535,1928707164,1715193156,4219352155,1126790795,600235211,3992742070,3841024952,836553431,1669664834,2535604243,3323011204,1243905413,3141400786,4180808110,698445255,2653899549,2989552604,2253581325,3252932727,3004591147,1891211689,2487810577,3915653703,4237083816,4030667424,2100090966,865136418,1229899655,953270745,3399679628,3557504664,4118925222,2061379749,3079546586,2915017791,983426092,2022837584,1607244650,2118541908,2366882550,3635996816,972512814,3283088770,1568718495,3499326569,3576539503,621982671,2895723464,410887952,2623762152,1002142683,645401037,1494807662,2595684844,1335535747,2507040230,4293295786,3167684641,367585007,3885750714,1865862730,2668221674,2960971305,2763173681,1059270954,2777952454,2724642869,1320957812,2194319100,2429595872,2815956275,77089521,3973773121,3444575871,2448830231,1305906550,4021308739,2857194700,2516901860,3518358430,1787304780,740276417,1699839814,1592394909,2352307457,2272556026,188821243,1729977011,3687994002,274084841,3594982253,3613494426,2701949495,4162096729,322734571,2837966542,1640576439,484830689,1202797690,3537852828,4067639125,349075736,3342319475,4157467219,4255800159,1030690015,1155237496,2951971274,1757691577,607398968,2738905026,499347990,3794078908,1011452712,227885567,2818666809,213114376,3034881240,1455525988,3414450555,850817237,1817998408,3092726480],S=[0,235474187,470948374,303765277,941896748,908933415,607530554,708780849,1883793496,2118214995,1817866830,1649639237,1215061108,1181045119,1417561698,1517767529,3767586992,4003061179,4236429990,4069246893,3635733660,3602770327,3299278474,3400528769,2430122216,2664543715,2362090238,2193862645,2835123396,2801107407,3035535058,3135740889,3678124923,3576870512,3341394285,3374361702,3810496343,3977675356,4279080257,4043610186,2876494627,2776292904,3076639029,3110650942,2472011535,2640243204,2403728665,2169303058,1001089995,899835584,666464733,699432150,59727847,226906860,530400753,294930682,1273168787,1172967064,1475418501,1509430414,1942435775,2110667444,1876241833,1641816226,2910219766,2743034109,2976151520,3211623147,2505202138,2606453969,2302690252,2269728455,3711829422,3543599269,3240894392,3475313331,3843699074,3943906441,4178062228,4144047775,1306967366,1139781709,1374988112,1610459739,1975683434,2076935265,1775276924,1742315127,1034867998,866637845,566021896,800440835,92987698,193195065,429456164,395441711,1984812685,2017778566,1784663195,1683407248,1315562145,1080094634,1383856311,1551037884,101039829,135050206,437757123,337553864,1042385657,807962610,573804783,742039012,2531067453,2564033334,2328828971,2227573024,2935566865,2700099354,3001755655,3168937228,3868552805,3902563182,4203181171,4102977912,3736164937,3501741890,3265478751,3433712980,1106041591,1340463100,1576976609,1408749034,2043211483,2009195472,1708848333,1809054150,832877231,1068351396,766945465,599762354,159417987,126454664,361929877,463180190,2709260871,2943682380,3178106961,3009879386,2572697195,2538681184,2236228733,2336434550,3509871135,3745345300,3441850377,3274667266,3910161971,3877198648,4110568485,4211818798,2597806476,2497604743,2261089178,2295101073,2733856160,2902087851,3202437046,2968011453,3936291284,3835036895,4136440770,4169408201,3535486456,3702665459,3467192302,3231722213,2051518780,1951317047,1716890410,1750902305,1113818384,1282050075,1584504582,1350078989,168810852,67556463,371049330,404016761,841739592,1008918595,775550814,540080725,3969562369,3801332234,4035489047,4269907996,3569255213,3669462566,3366754619,3332740144,2631065433,2463879762,2160117071,2395588676,2767645557,2868897406,3102011747,3069049960,202008497,33778362,270040487,504459436,875451293,975658646,675039627,641025152,2084704233,1917518562,1615861247,1851332852,1147550661,1248802510,1484005843,1451044056,933301370,967311729,733156972,632953703,260388950,25965917,328671808,496906059,1206477858,1239443753,1543208500,1441952575,2144161806,1908694277,1675577880,1842759443,3610369226,3644379585,3408119516,3307916247,4011190502,3776767469,4077384432,4245618683,2809771154,2842737049,3144396420,3043140495,2673705150,2438237621,2203032232,2370213795],A=[0,185469197,370938394,487725847,741876788,657861945,975451694,824852259,1483753576,1400783205,1315723890,1164071807,1950903388,2135319889,1649704518,1767536459,2967507152,3152976349,2801566410,2918353863,2631447780,2547432937,2328143614,2177544179,3901806776,3818836405,4270639778,4118987695,3299409036,3483825537,3535072918,3652904859,2077965243,1893020342,1841768865,1724457132,1474502543,1559041666,1107234197,1257309336,598438867,681933534,901210569,1052338372,261314535,77422314,428819965,310463728,3409685355,3224740454,3710368113,3593056380,3875770207,3960309330,4045380933,4195456072,2471224067,2554718734,2237133081,2388260884,3212035895,3028143674,2842678573,2724322336,4138563181,4255350624,3769721975,3955191162,3667219033,3516619604,3431546947,3347532110,2933734917,2782082824,3099667487,3016697106,2196052529,2313884476,2499348523,2683765030,1179510461,1296297904,1347548327,1533017514,1786102409,1635502980,2087309459,2003294622,507358933,355706840,136428751,53458370,839224033,957055980,605657339,790073846,2373340630,2256028891,2607439820,2422494913,2706270690,2856345839,3075636216,3160175349,3573941694,3725069491,3273267108,3356761769,4181598602,4063242375,4011996048,3828103837,1033297158,915985419,730517276,545572369,296679730,446754879,129166120,213705253,1709610350,1860738147,1945798516,2029293177,1239331162,1120974935,1606591296,1422699085,4148292826,4233094615,3781033664,3931371469,3682191598,3497509347,3446004468,3328955385,2939266226,2755636671,3106780840,2988687269,2198438022,2282195339,2501218972,2652609425,1201765386,1286567175,1371368976,1521706781,1805211710,1620529459,2105887268,1988838185,533804130,350174575,164439672,46346101,870912086,954669403,636813900,788204353,2358957921,2274680428,2592523643,2441661558,2695033685,2880240216,3065962831,3182487618,3572145929,3756299780,3270937875,3388507166,4174560061,4091327024,4006521127,3854606378,1014646705,930369212,711349675,560487590,272786309,457992840,106852767,223377554,1678381017,1862534868,1914052035,2031621326,1211247597,1128014560,1580087799,1428173050,32283319,182621114,401639597,486441376,768917123,651868046,1003007129,818324884,1503449823,1385356242,1333838021,1150208456,1973745387,2125135846,1673061617,1756818940,2970356327,3120694122,2802849917,2887651696,2637442643,2520393566,2334669897,2149987652,3917234703,3799141122,4284502037,4100872472,3309594171,3460984630,3545789473,3629546796,2050466060,1899603969,1814803222,1730525723,1443857720,1560382517,1075025698,1260232239,575138148,692707433,878443390,1062597235,243256656,91341917,409198410,325965383,3403100636,3252238545,3704300486,3620022987,3874428392,3990953189,4042459122,4227665663,2460449204,2578018489,2226875310,2411029155,3198115200,3046200461,2827177882,2743944855],M=[0,218828297,437656594,387781147,875313188,958871085,775562294,590424639,1750626376,1699970625,1917742170,2135253587,1551124588,1367295589,1180849278,1265195639,3501252752,3720081049,3399941250,3350065803,3835484340,3919042237,4270507174,4085369519,3102249176,3051593425,2734591178,2952102595,2361698556,2177869557,2530391278,2614737639,3145456443,3060847922,2708326185,2892417312,2404901663,2187128086,2504130317,2555048196,3542330227,3727205754,3375740769,3292445032,3876557655,3926170974,4246310725,4027744588,1808481195,1723872674,1910319033,2094410160,1608975247,1391201670,1173430173,1224348052,59984867,244860394,428169201,344873464,935293895,984907214,766078933,547512796,1844882806,1627235199,2011214180,2062270317,1507497298,1423022939,1137477952,1321699145,95345982,145085239,532201772,313773861,830661914,1015671571,731183368,648017665,3175501286,2957853679,2807058932,2858115069,2305455554,2220981195,2474404304,2658625497,3575528878,3625268135,3473416636,3254988725,3778151818,3963161475,4213447064,4130281361,3599595085,3683022916,3432737375,3247465558,3802222185,4020912224,4172763771,4122762354,3201631749,3017672716,2764249623,2848461854,2331590177,2280796200,2431590963,2648976442,104699613,188127444,472615631,287343814,840019705,1058709744,671593195,621591778,1852171925,1668212892,1953757831,2037970062,1514790577,1463996600,1080017571,1297403050,3673637356,3623636965,3235995134,3454686199,4007360968,3822090177,4107101658,4190530515,2997825956,3215212461,2830708150,2779915199,2256734592,2340947849,2627016082,2443058075,172466556,122466165,273792366,492483431,1047239e3,861968209,612205898,695634755,1646252340,1863638845,2013908262,1963115311,1446242576,1530455833,1277555970,1093597963,1636604631,1820824798,2073724613,1989249228,1436590835,1487645946,1337376481,1119727848,164948639,81781910,331544205,516552836,1039717051,821288114,669961897,719700128,2973530695,3157750862,2871682645,2787207260,2232435299,2283490410,2667994737,2450346104,3647212047,3564045318,3279033885,3464042516,3980931627,3762502690,4150144569,4199882800,3070356634,3121275539,2904027272,2686254721,2200818878,2384911031,2570832044,2486224549,3747192018,3528626907,3310321856,3359936201,3950355702,3867060991,4049844452,4234721005,1739656202,1790575107,2108100632,1890328081,1402811438,1586903591,1233856572,1149249077,266959938,48394827,369057872,418672217,1002783846,919489135,567498868,752375421,209336225,24197544,376187827,459744698,945164165,895287692,574624663,793451934,1679968233,1764313568,2117360635,1933530610,1343127501,1560637892,1243112415,1192455638,3704280881,3519142200,3336358691,3419915562,3907448597,3857572124,4075877127,4294704398,3029510009,3113855344,2927934315,2744104290,2159976285,2377486676,2594734927,2544078150],E=[0,151849742,303699484,454499602,607398968,758720310,908999204,1059270954,1214797936,1097159550,1517440620,1400849762,1817998408,1699839814,2118541908,2001430874,2429595872,2581445614,2194319100,2345119218,3034881240,3186202582,2801699524,2951971274,3635996816,3518358430,3399679628,3283088770,4237083816,4118925222,4002861748,3885750714,1002142683,850817237,698445255,548169417,529487843,377642221,227885567,77089521,1943217067,2061379749,1640576439,1757691577,1474760595,1592394909,1174215055,1290801793,2875968315,2724642869,3111247143,2960971305,2405426947,2253581325,2638606623,2487810577,3808662347,3926825029,4044981591,4162096729,3342319475,3459953789,3576539503,3693126241,1986918061,2137062819,1685577905,1836772287,1381620373,1532285339,1078185097,1229899655,1040559837,923313619,740276417,621982671,439452389,322734571,137073913,19308535,3871163981,4021308739,4104605777,4255800159,3263785589,3414450555,3499326569,3651041127,2933202493,2815956275,3167684641,3049390895,2330014213,2213296395,2566595609,2448830231,1305906550,1155237496,1607244650,1455525988,1776460110,1626319424,2079897426,1928707164,96392454,213114376,396673818,514443284,562755902,679998e3,865136418,983426092,3708173718,3557504664,3474729866,3323011204,4180808110,4030667424,3945269170,3794078908,2507040230,2623762152,2272556026,2390325492,2975484382,3092726480,2738905026,2857194700,3973773121,3856137295,4274053469,4157467219,3371096953,3252932727,3673476453,3556361835,2763173681,2915017791,3064510765,3215307299,2156299017,2307622919,2459735317,2610011675,2081048481,1963412655,1846563261,1729977011,1480485785,1362321559,1243905413,1126790795,878845905,1030690015,645401037,796197571,274084841,425408743,38544885,188821243,3613494426,3731654548,3313212038,3430322568,4082475170,4200115116,3780097726,3896688048,2668221674,2516901860,2366882550,2216610296,3141400786,2989552604,2837966542,2687165888,1202797690,1320957812,1437280870,1554391400,1669664834,1787304780,1906247262,2022837584,265905162,114585348,499347990,349075736,736970802,585122620,972512814,821712160,2595684844,2478443234,2293045232,2174754046,3196267988,3079546586,2895723464,2777952454,3537852828,3687994002,3234156416,3385345166,4142626212,4293295786,3841024952,3992742070,174567692,57326082,410887952,292596766,777231668,660510266,1011452712,893681702,1108339068,1258480242,1343618912,1494807662,1715193156,1865862730,1948373848,2100090966,2701949495,2818666809,3004591147,3122358053,2235061775,2352307457,2535604243,2653899549,3915653703,3764988233,4219352155,4067639125,3444575871,3294430577,3746175075,3594982253,836553431,953270745,600235211,718002117,367585007,484830689,133361907,251657213,2041877159,1891211689,1806599355,1654886325,1568718495,1418573201,1335535747,1184342925];function _(t){for(var e=[],r=0;r<t.length;r+=4)e.push(t[r]<<24|t[r+1]<<16|t[r+2]<<8|t[r+3]);return e}var P=function(t){if(!(this instanceof P))throw Error("AES must be instanitated with `new`");Object.defineProperty(this,"key",{value:n(t,!0)}),this._prepare()};P.prototype._prepare=function(){var t=u[this.key.length];if(null==t)throw new Error("invalid key size (must be 16, 24 or 32 bytes)");this._Ke=[],this._Kd=[];for(var e=0;e<=t;e++)this._Ke.push([0,0,0,0]),this._Kd.push([0,0,0,0]);var r,n=4*(t+1),i=this.key.length/4,o=_(this.key);for(e=0;e<i;e++)r=e>>2,this._Ke[r][e%4]=o[e],this._Kd[t-r][e%4]=o[e];for(var s,a=0,h=i;h<n;){if(s=o[i-1],o[0]^=l[s>>16&255]<<24^l[s>>8&255]<<16^l[255&s]<<8^l[s>>24&255]^f[a]<<24,a+=1,8!=i)for(e=1;e<i;e++)o[e]^=o[e-1];else{for(e=1;e<i/2;e++)o[e]^=o[e-1];s=o[i/2-1],o[i/2]^=l[255&s]^l[s>>8&255]<<8^l[s>>16&255]<<16^l[s>>24&255]<<24;for(e=i/2+1;e<i;e++)o[e]^=o[e-1]}for(e=0;e<i&&h<n;)c=h>>2,d=h%4,this._Ke[c][d]=o[e],this._Kd[t-c][d]=o[e++],h++}for(var c=1;c<t;c++)for(var d=0;d<4;d++)s=this._Kd[c][d],this._Kd[c][d]=S[s>>24&255]^A[s>>16&255]^M[s>>8&255]^E[255&s]},P.prototype.encrypt=function(t){if(16!=t.length)throw new Error("invalid plaintext size (must be 16 bytes)");for(var e=this._Ke.length-1,r=[0,0,0,0],n=_(t),o=0;o<4;o++)n[o]^=this._Ke[0][o];for(var s=1;s<e;s++){for(o=0;o<4;o++)r[o]=d[n[o]>>24&255]^p[n[(o+1)%4]>>16&255]^m[n[(o+2)%4]>>8&255]^g[255&n[(o+3)%4]]^this._Ke[s][o];n=r.slice()}var a,h=i(16);for(o=0;o<4;o++)a=this._Ke[e][o],h[4*o]=255&(l[n[o]>>24&255]^a>>24),h[4*o+1]=255&(l[n[(o+1)%4]>>16&255]^a>>16),h[4*o+2]=255&(l[n[(o+2)%4]>>8&255]^a>>8),h[4*o+3]=255&(l[255&n[(o+3)%4]]^a);return h},P.prototype.decrypt=function(t){if(16!=t.length)throw new Error("invalid ciphertext size (must be 16 bytes)");for(var e=this._Kd.length-1,r=[0,0,0,0],n=_(t),o=0;o<4;o++)n[o]^=this._Kd[0][o];for(var s=1;s<e;s++){for(o=0;o<4;o++)r[o]=y[n[o]>>24&255]^v[n[(o+3)%4]>>16&255]^w[n[(o+2)%4]>>8&255]^b[255&n[(o+1)%4]]^this._Kd[s][o];n=r.slice()}var a,h=i(16);for(o=0;o<4;o++)a=this._Kd[e][o],h[4*o]=255&(c[n[o]>>24&255]^a>>24),h[4*o+1]=255&(c[n[(o+3)%4]>>16&255]^a>>16),h[4*o+2]=255&(c[n[(o+2)%4]>>8&255]^a>>8),h[4*o+3]=255&(c[255&n[(o+1)%4]]^a);return h};var x=function(t){if(!(this instanceof x))throw Error("AES must be instanitated with `new`");this.description="Electronic Code Block",this.name="ecb",this._aes=new P(t)};x.prototype.encrypt=function(t){if((t=n(t)).length%16!=0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var e=i(t.length),r=i(16),s=0;s<t.length;s+=16)o(t,r,0,s,s+16),o(r=this._aes.encrypt(r),e,s);return e},x.prototype.decrypt=function(t){if((t=n(t)).length%16!=0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var e=i(t.length),r=i(16),s=0;s<t.length;s+=16)o(t,r,0,s,s+16),o(r=this._aes.decrypt(r),e,s);return e};var I=function(t,e){if(!(this instanceof I))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Block Chaining",this.name="cbc",e){if(16!=e.length)throw new Error("invalid initialation vector size (must be 16 bytes)")}else e=i(16);this._lastCipherblock=n(e,!0),this._aes=new P(t)};I.prototype.encrypt=function(t){if((t=n(t)).length%16!=0)throw new Error("invalid plaintext size (must be multiple of 16 bytes)");for(var e=i(t.length),r=i(16),s=0;s<t.length;s+=16){o(t,r,0,s,s+16);for(var a=0;a<16;a++)r[a]^=this._lastCipherblock[a];this._lastCipherblock=this._aes.encrypt(r),o(this._lastCipherblock,e,s)}return e},I.prototype.decrypt=function(t){if((t=n(t)).length%16!=0)throw new Error("invalid ciphertext size (must be multiple of 16 bytes)");for(var e=i(t.length),r=i(16),s=0;s<t.length;s+=16){o(t,r,0,s,s+16),r=this._aes.decrypt(r);for(var a=0;a<16;a++)e[s+a]=r[a]^this._lastCipherblock[a];o(t,this._lastCipherblock,0,s,s+16)}return e};var C=function(t,e,r){if(!(this instanceof C))throw Error("AES must be instanitated with `new`");if(this.description="Cipher Feedback",this.name="cfb",e){if(16!=e.length)throw new Error("invalid initialation vector size (must be 16 size)")}else e=i(16);r||(r=1),this.segmentSize=r,this._shiftRegister=n(e,!0),this._aes=new P(t)};C.prototype.encrypt=function(t){if(t.length%this.segmentSize!=0)throw new Error("invalid plaintext size (must be segmentSize bytes)");for(var e,r=n(t,!0),i=0;i<r.length;i+=this.segmentSize){e=this._aes.encrypt(this._shiftRegister);for(var s=0;s<this.segmentSize;s++)r[i+s]^=e[s];o(this._shiftRegister,this._shiftRegister,0,this.segmentSize),o(r,this._shiftRegister,16-this.segmentSize,i,i+this.segmentSize)}return r},C.prototype.decrypt=function(t){if(t.length%this.segmentSize!=0)throw new Error("invalid ciphertext size (must be segmentSize bytes)");for(var e,r=n(t,!0),i=0;i<r.length;i+=this.segmentSize){e=this._aes.encrypt(this._shiftRegister);for(var s=0;s<this.segmentSize;s++)r[i+s]^=e[s];o(this._shiftRegister,this._shiftRegister,0,this.segmentSize),o(t,this._shiftRegister,16-this.segmentSize,i,i+this.segmentSize)}return r};var N=function(t,e){if(!(this instanceof N))throw Error("AES must be instanitated with `new`");if(this.description="Output Feedback",this.name="ofb",e){if(16!=e.length)throw new Error("invalid initialation vector size (must be 16 bytes)")}else e=i(16);this._lastPrecipher=n(e,!0),this._lastPrecipherIndex=16,this._aes=new P(t)};N.prototype.encrypt=function(t){for(var e=n(t,!0),r=0;r<e.length;r++)16===this._lastPrecipherIndex&&(this._lastPrecipher=this._aes.encrypt(this._lastPrecipher),this._lastPrecipherIndex=0),e[r]^=this._lastPrecipher[this._lastPrecipherIndex++];return e},N.prototype.decrypt=N.prototype.encrypt;var R=function(t){if(!(this instanceof R))throw Error("Counter must be instanitated with `new`");0===t||t||(t=1),"number"==typeof t?(this._counter=i(16),this.setValue(t)):this.setBytes(t)};R.prototype.setValue=function(t){if("number"!=typeof t||parseInt(t)!=t)throw new Error("invalid counter value (must be an integer)");for(var e=15;e>=0;--e)this._counter[e]=t%256,t>>=8},R.prototype.setBytes=function(t){if(16!=(t=n(t,!0)).length)throw new Error("invalid counter bytes size (must be 16 bytes)");this._counter=t},R.prototype.increment=function(){for(var t=15;t>=0;t--){if(255!==this._counter[t]){this._counter[t]++;break}this._counter[t]=0}};var k=function(t,e){if(!(this instanceof k))throw Error("AES must be instanitated with `new`");this.description="Counter",this.name="ctr",e instanceof R||(e=new R(e)),this._counter=e,this._remainingCounter=null,this._remainingCounterIndex=16,this._aes=new P(t)};k.prototype.encrypt=function(t){for(var e=n(t,!0),r=0;r<e.length;r++)16===this._remainingCounterIndex&&(this._remainingCounter=this._aes.encrypt(this._counter._counter),this._remainingCounterIndex=0,this._counter.increment()),e[r]^=this._remainingCounter[this._remainingCounterIndex++];return e},k.prototype.decrypt=k.prototype.encrypt;var T={AES:P,Counter:R,ModeOfOperation:{ecb:x,cbc:I,cfb:C,ofb:N,ctr:k},utils:{hex:h,utf8:a},padding:{pkcs7:{pad:function(t){var e=16-(t=n(t,!0)).length%16,r=i(t.length+e);o(t,r);for(var s=t.length;s<r.length;s++)r[s]=e;return r},strip:function(t){if((t=n(t,!0)).length<16)throw new Error("PKCS#7 invalid length");var e=t[t.length-1];if(e>16)throw new Error("PKCS#7 padding byte out of range");for(var r=t.length-e,s=0;s<e;s++)if(t[r+s]!==e)throw new Error("PKCS#7 invalid padding byte");var a=i(r);return o(t,a,0,0,r),a}}},_arrayTest:{coerceArray:n,createArray:i,copyArray:o}};t.exports=T}()}(Mi);var Ei=s(Mi.exports);const _i="json-wallets/5.7.0";function Pi(t){return"string"==typeof t&&"0x"!==t.substring(0,2)&&(t="0x"+t),x(t)}function xi(t,e){for(t=String(t);t.length<e;)t="0"+t;return t}function Ii(t){return"string"==typeof t?At(t,bt.NFKC):x(t)}function Ci(t,e){let r=t;const n=e.toLowerCase().split("/");for(let t=0;t<n.length;t++){let e=null;for(const i in r)if(i.toLowerCase()===n[t]){e=r[i];break}if(null===e)return null;r=e}return r}function Ni(t){const e=x(t);e[6]=15&e[6]|64,e[8]=63&e[8]|128;const r=k(e);return[r.substring(2,10),r.substring(10,14),r.substring(14,18),r.substring(18,22),r.substring(22,34)].join("-")}const Ri=new b(_i);class ki extends it{isCrowdsaleAccount(t){return!(!t||!t._isCrowdsaleAccount)}}function Ti(t,e){const r=JSON.parse(t);e=Ii(e);const n=vt(Ci(r,"ethaddr")),i=Pi(Ci(r,"encseed"));i&&i.length%16==0||Ri.throwArgumentError("invalid encseed","json",t);const o=x(Qn(e,e,2e3,32,"sha256")).slice(0,16),s=i.slice(0,16),a=i.slice(16),h=new Ei.ModeOfOperation.cbc(o,s),u=Ei.padding.pkcs7.strip(x(h.decrypt(a)));let f="";for(let t=0;t<u.length;t++)f+=String.fromCharCode(u[t]);const l=ht(At(f));return new ki({_isCrowdsaleAccount:!0,address:n,privateKey:l})}function Di(t){let e=null;try{e=JSON.parse(t)}catch(t){return!1}return e.encseed&&e.ethaddr}function Oi(t){let e=null;try{e=JSON.parse(t)}catch(t){return!1}return!(!e.version||parseInt(e.version)!==e.version||3!==parseInt(e.version))}var Fi={exports:{}};!function(t){!function(){const e=2147483647;function r(t){const e=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);let r=1779033703,n=3144134277,i=1013904242,o=2773480762,s=1359893119,a=2600822924,h=528734635,u=1541459225;const f=new Uint32Array(64);function l(t){let l=0,c=t.length;for(;c>=64;){let d,p,m,g,y,v=r,w=n,b=i,S=o,A=s,M=a,E=h,_=u;for(p=0;p<16;p++)m=l+4*p,f[p]=(255&t[m])<<24|(255&t[m+1])<<16|(255&t[m+2])<<8|255&t[m+3];for(p=16;p<64;p++)d=f[p-2],g=(d>>>17|d<<15)^(d>>>19|d<<13)^d>>>10,d=f[p-15],y=(d>>>7|d<<25)^(d>>>18|d<<14)^d>>>3,f[p]=(g+f[p-7]|0)+(y+f[p-16]|0)|0;for(p=0;p<64;p++)g=(((A>>>6|A<<26)^(A>>>11|A<<21)^(A>>>25|A<<7))+(A&M^~A&E)|0)+(_+(e[p]+f[p]|0)|0)|0,y=((v>>>2|v<<30)^(v>>>13|v<<19)^(v>>>22|v<<10))+(v&w^v&b^w&b)|0,_=E,E=M,M=A,A=S+g|0,S=b,b=w,w=v,v=g+y|0;r=r+v|0,n=n+w|0,i=i+b|0,o=o+S|0,s=s+A|0,a=a+M|0,h=h+E|0,u=u+_|0,l+=64,c-=64}}l(t);let c,d=t.length%64,p=t.length/536870912|0,m=t.length<<3,g=d<56?56:120,y=t.slice(t.length-d,t.length);for(y.push(128),c=d+1;c<g;c++)y.push(0);return y.push(p>>>24&255),y.push(p>>>16&255),y.push(p>>>8&255),y.push(p>>>0&255),y.push(m>>>24&255),y.push(m>>>16&255),y.push(m>>>8&255),y.push(m>>>0&255),l(y),[r>>>24&255,r>>>16&255,r>>>8&255,r>>>0&255,n>>>24&255,n>>>16&255,n>>>8&255,n>>>0&255,i>>>24&255,i>>>16&255,i>>>8&255,i>>>0&255,o>>>24&255,o>>>16&255,o>>>8&255,o>>>0&255,s>>>24&255,s>>>16&255,s>>>8&255,s>>>0&255,a>>>24&255,a>>>16&255,a>>>8&255,a>>>0&255,h>>>24&255,h>>>16&255,h>>>8&255,h>>>0&255,u>>>24&255,u>>>16&255,u>>>8&255,u>>>0&255]}function n(t,e,n){t=t.length<=64?t:r(t);const i=64+e.length+4,o=new Array(i),s=new Array(64);let a,h=[];for(a=0;a<64;a++)o[a]=54;for(a=0;a<t.length;a++)o[a]^=t[a];for(a=0;a<e.length;a++)o[64+a]=e[a];for(a=i-4;a<i;a++)o[a]=0;for(a=0;a<64;a++)s[a]=92;for(a=0;a<t.length;a++)s[a]^=t[a];function u(){for(let t=i-1;t>=i-4;t--){if(o[t]++,o[t]<=255)return;o[t]=0}}for(;n>=32;)u(),h=h.concat(r(s.concat(r(o)))),n-=32;return n>0&&(u(),h=h.concat(r(s.concat(r(o))).slice(0,n))),h}function i(t,e,r,n,i){let o;for(h(t,16*(2*r-1),i,0,16),o=0;o<2*r;o++)a(t,16*o,i,16),s(i,n),h(i,0,t,e+16*o,16);for(o=0;o<r;o++)h(t,e+2*o*16,t,16*o,16);for(o=0;o<r;o++)h(t,e+16*(2*o+1),t,16*(o+r),16)}function o(t,e){return t<<e|t>>>32-e}function s(t,e){h(t,0,e,0,16);for(let t=8;t>0;t-=2)e[4]^=o(e[0]+e[12],7),e[8]^=o(e[4]+e[0],9),e[12]^=o(e[8]+e[4],13),e[0]^=o(e[12]+e[8],18),e[9]^=o(e[5]+e[1],7),e[13]^=o(e[9]+e[5],9),e[1]^=o(e[13]+e[9],13),e[5]^=o(e[1]+e[13],18),e[14]^=o(e[10]+e[6],7),e[2]^=o(e[14]+e[10],9),e[6]^=o(e[2]+e[14],13),e[10]^=o(e[6]+e[2],18),e[3]^=o(e[15]+e[11],7),e[7]^=o(e[3]+e[15],9),e[11]^=o(e[7]+e[3],13),e[15]^=o(e[11]+e[7],18),e[1]^=o(e[0]+e[3],7),e[2]^=o(e[1]+e[0],9),e[3]^=o(e[2]+e[1],13),e[0]^=o(e[3]+e[2],18),e[6]^=o(e[5]+e[4],7),e[7]^=o(e[6]+e[5],9),e[4]^=o(e[7]+e[6],13),e[5]^=o(e[4]+e[7],18),e[11]^=o(e[10]+e[9],7),e[8]^=o(e[11]+e[10],9),e[9]^=o(e[8]+e[11],13),e[10]^=o(e[9]+e[8],18),e[12]^=o(e[15]+e[14],7),e[13]^=o(e[12]+e[15],9),e[14]^=o(e[13]+e[12],13),e[15]^=o(e[14]+e[13],18);for(let r=0;r<16;++r)t[r]+=e[r]}function a(t,e,r,n){for(let i=0;i<n;i++)r[i]^=t[e+i]}function h(t,e,r,n,i){for(;i--;)r[n++]=t[e++]}function u(t){if(!t||"number"!=typeof t.length)return!1;for(let e=0;e<t.length;e++){const r=t[e];if("number"!=typeof r||r%1||r<0||r>=256)return!1}return!0}function f(t,e){if("number"!=typeof t||t%1)throw new Error("invalid "+e);return t}function l(t,r,o,s,l,c,d){if(o=f(o,"N"),s=f(s,"r"),l=f(l,"p"),c=f(c,"dkLen"),0===o||o&o-1)throw new Error("N must be power of 2");if(o>e/128/s)throw new Error("N too large");if(s>e/128/l)throw new Error("r too large");if(!u(t))throw new Error("password must be an array or buffer");if(t=Array.prototype.slice.call(t),!u(r))throw new Error("salt must be an array or buffer");r=Array.prototype.slice.call(r);let p=n(t,r,128*l*s);const m=new Uint32Array(32*l*s);for(let t=0;t<m.length;t++){const e=4*t;m[t]=(255&p[e+3])<<24|(255&p[e+2])<<16|(255&p[e+1])<<8|255&p[e+0]}const g=new Uint32Array(64*s),y=new Uint32Array(32*s*o),v=32*s,w=new Uint32Array(16),b=new Uint32Array(16),S=l*o*2;let A,M,E=0,_=null,P=!1,x=0,I=0;const C=d?parseInt(1e3/s):4294967295,N="undefined"!=typeof setImmediate?setImmediate:setTimeout,R=function(){if(P)return d(new Error("cancelled"),E/S);let e;switch(x){case 0:M=32*I*s,h(m,M,g,0,v),x=1,A=0;case 1:e=o-A,e>C&&(e=C);for(let t=0;t<e;t++)h(g,0,y,(A+t)*v,v),i(g,v,s,w,b);if(A+=e,E+=e,d){const t=parseInt(1e3*E/S);if(t!==_){if(P=d(null,E/S),P)break;_=t}}if(A<o)break;A=0,x=2;case 2:e=o-A,e>C&&(e=C);for(let t=0;t<e;t++){const t=g[16*(2*s-1)]&o-1;a(y,t*v,g,v),i(g,v,s,w,b)}if(A+=e,E+=e,d){const t=parseInt(1e3*E/S);if(t!==_){if(P=d(null,E/S),P)break;_=t}}if(A<o)break;if(h(g,0,m,M,v),I++,I<l){x=0;break}p=[];for(let t=0;t<m.length;t++)p.push(255&m[t]),p.push(m[t]>>8&255),p.push(m[t]>>16&255),p.push(m[t]>>24&255);const r=n(t,p,c);return d&&d(null,1,r),r}d&&N(R)};if(!d)for(;;){const t=R();if(null!=t)return t}R()}const c={scrypt:function(t,e,r,n,i,o,s){return new Promise((function(a,h){let u=0;s&&s(0),l(t,e,r,n,i,o,(function(t,e,r){if(t)h(t);else if(r)s&&1!==u&&s(1),a(new Uint8Array(r));else if(s&&e!==u)return u=e,s(e)}))}))},syncScrypt:function(t,e,r,n,i,o){return new Uint8Array(l(t,e,r,n,i,o))}};t.exports=c}()}(Fi);var Bi=s(Fi.exports),Li=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))};const Ui=new b(_i);function Ki(t){return null!=t&&t.mnemonic&&t.mnemonic.phrase}class Gi extends it{isKeystoreAccount(t){return!(!t||!t._isKeystoreAccount)}}function zi(t,e){const r=Pi(Ci(t,"crypto/ciphertext"));if(k(ht(I([e.slice(16,32),r]))).substring(2)!==Ci(t,"crypto/mac").toLowerCase())throw new Error("invalid password");const n=function(t,e,r){if("aes-128-ctr"===Ci(t,"crypto/cipher")){const n=Pi(Ci(t,"crypto/cipherparams/iv")),i=new Ei.Counter(n);return x(new Ei.ModeOfOperation.ctr(e,i).decrypt(r))}return null}(t,e.slice(0,16),r);n||Ui.throwError("unsupported cipher",b.errors.UNSUPPORTED_OPERATION,{operation:"decrypt"});const i=e.slice(32,64),o=Gn(n);if(t.address){let e=t.address.toLowerCase();if("0x"!==e.substring(0,2)&&(e="0x"+e),vt(e)!==o)throw new Error("address mismatch")}const s={_isKeystoreAccount:!0,address:o,privateKey:k(n)};if("0.1"===Ci(t,"x-ethers/version")){const e=Pi(Ci(t,"x-ethers/mnemonicCiphertext")),r=Pi(Ci(t,"x-ethers/mnemonicCounter")),n=new Ei.Counter(r),o=new Ei.ModeOfOperation.ctr(i,n),a=Ci(t,"x-ethers/path")||mi,h=Ci(t,"x-ethers/locale")||"en",u=x(o.decrypt(e));try{const t=vi(u,h),e=gi.fromMnemonic(t,null,h).derivePath(a);if(e.privateKey!=s.privateKey)throw new Error("mnemonic mismatch");s.mnemonic=e.mnemonic}catch(t){if(t.code!==b.errors.INVALID_ARGUMENT||"wordlist"!==t.argument)throw t}}return new Gi(s)}function Hi(t,e,r,n,i){return x(Qn(t,e,r,n,i))}function qi(t,e,r,n,i){return Promise.resolve(Hi(t,e,r,n,i))}function ji(t,e,r,n,i){const o=Ii(e),s=Ci(t,"crypto/kdf");if(s&&"string"==typeof s){const e=function(t,e){return Ui.throwArgumentError("invalid key-derivation function parameters",t,e)};if("scrypt"===s.toLowerCase()){const r=Pi(Ci(t,"crypto/kdfparams/salt")),a=parseInt(Ci(t,"crypto/kdfparams/n")),h=parseInt(Ci(t,"crypto/kdfparams/r")),u=parseInt(Ci(t,"crypto/kdfparams/p"));a&&h&&u||e("kdf",s),a&a-1&&e("N",a);const f=parseInt(Ci(t,"crypto/kdfparams/dklen"));return 32!==f&&e("dklen",f),n(o,r,a,h,u,64,i)}if("pbkdf2"===s.toLowerCase()){const n=Pi(Ci(t,"crypto/kdfparams/salt"));let i=null;const s=Ci(t,"crypto/kdfparams/prf");"hmac-sha256"===s?i="sha256":"hmac-sha512"===s?i="sha512":e("prf",s);const a=parseInt(Ci(t,"crypto/kdfparams/c")),h=parseInt(Ci(t,"crypto/kdfparams/dklen"));return 32!==h&&e("dklen",h),r(o,n,a,h,i)}}return Ui.throwArgumentError("unsupported key-derivation function","kdf",s)}function Wi(t,e,r){if(Di(t)){r&&r(0);const n=Ti(t,e);return r&&r(1),Promise.resolve(n)}return Oi(t)?function(t,e,r){return Li(this,void 0,void 0,(function*(){const n=JSON.parse(t);return zi(n,yield ji(n,e,qi,Bi.scrypt,r))}))}(t,e,r):Promise.reject(new Error("invalid JSON wallet"))}function Vi(t,e){if(Di(t))return Ti(t,e);if(Oi(t))return function(t,e){const r=JSON.parse(t);return zi(r,ji(r,e,Hi,Bi.syncScrypt))}(t,e);throw new Error("invalid JSON wallet")}var Ji=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{h(n.next(t))}catch(t){o(t)}}function a(t){try{h(n.throw(t))}catch(t){o(t)}}function h(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}h((n=n.apply(t,e||[])).next())}))};const $i=new b("wallet/5.7.0");class Zi extends Vt{constructor(t,e){if(super(),null!=(r=t)&&N(r.privateKey,32)&&null!=r.address){const e=new On(t.privateKey);if(X(this,"_signingKey",(()=>e)),X(this,"address",Gn(this.publicKey)),this.address!==vt(t.address)&&$i.throwArgumentError("privateKey/address mismatch","privateKey","[REDACTED]"),function(t){const e=t.mnemonic;return e&&e.phrase}(t)){const e=t.mnemonic;X(this,"_mnemonic",(()=>({phrase:e.phrase,path:e.path||mi,locale:e.locale||"en"})));const r=this.mnemonic;Gn(gi.fromMnemonic(r.phrase,null,r.locale).derivePath(r.path).privateKey)!==this.address&&$i.throwArgumentError("mnemonic/address mismatch","privateKey","[REDACTED]")}else X(this,"_mnemonic",(()=>null))}else{if(On.isSigningKey(t))"secp256k1"!==t.curve&&$i.throwArgumentError("unsupported curve; must be secp256k1","privateKey","[REDACTED]"),X(this,"_signingKey",(()=>t));else{"string"==typeof t&&t.match(/^[0-9a-f]*$/i)&&64===t.length&&(t="0x"+t);const e=new On(t);X(this,"_signingKey",(()=>e))}X(this,"_mnemonic",(()=>null)),X(this,"address",Gn(this.publicKey))}var r;e&&!zt.isProvider(e)&&$i.throwArgumentError("invalid provider","provider",e),X(this,"provider",e||null)}get mnemonic(){return this._mnemonic()}get privateKey(){return this._signingKey().privateKey}get publicKey(){return this._signingKey().publicKey}getAddress(){return Promise.resolve(this.address)}connect(t){return new Zi(this,t)}signTransaction(t){return Y(t).then((e=>{null!=e.from&&(vt(e.from)!==this.address&&$i.throwArgumentError("transaction from address mismatch","transaction.from",t.from),delete e.from);const r=this._signingKey().signDigest(ht(Wn(e)));return Wn(e,r)}))}signMessage(t){return Ji(this,void 0,void 0,(function*(){return L(this._signingKey().signDigest(function(t){return"string"==typeof t&&(t=At(t)),ht(I([At("Ethereum Signed Message:\n"),At(String(t.length)),t]))}(t)))}))}_signTypedData(t,e,r){return Ji(this,void 0,void 0,(function*(){const n=yield Ut.resolveNames(t,e,r,(t=>(null==this.provider&&$i.throwError("cannot resolve ENS names without a provider",b.errors.UNSUPPORTED_OPERATION,{operation:"resolveName",value:t}),this.provider.resolveName(t))));return L(this._signingKey().signDigest(Ut.hash(n.domain,e,n.value)))}))}encrypt(t,e,r){if("function"!=typeof e||r||(r=e,e={}),r&&"function"!=typeof r)throw new Error("invalid callback");return e||(e={}),function(t,e,r,n){try{if(vt(t.address)!==Gn(t.privateKey))throw new Error("address/privateKey mismatch");if(Ki(t)){const e=t.mnemonic;if(gi.fromMnemonic(e.phrase,null,e.locale).derivePath(e.path||mi).privateKey!=t.privateKey)throw new Error("mnemonic mismatch")}}catch(t){return Promise.reject(t)}"function"!=typeof r||n||(n=r,r={}),r||(r={});const i=x(t.privateKey),o=Ii(e);let s=null,a=null,h=null;if(Ki(t)){const e=t.mnemonic;s=x(yi(e.phrase,e.locale||"en")),a=e.path||mi,h=e.locale||"en"}let u=r.client;u||(u="ethers.js");let f=null;f=r.salt?x(r.salt):Ai(32);let l=null;if(r.iv){if(l=x(r.iv),16!==l.length)throw new Error("invalid iv")}else l=Ai(16);let c=null;if(r.uuid){if(c=x(r.uuid),16!==c.length)throw new Error("invalid uuid")}else c=Ai(16);let d=1<<17,p=8,m=1;return r.scrypt&&(r.scrypt.N&&(d=r.scrypt.N),r.scrypt.r&&(p=r.scrypt.r),r.scrypt.p&&(m=r.scrypt.p)),Bi.scrypt(o,f,d,p,m,64,n).then((e=>{const r=(e=x(e)).slice(0,16),n=e.slice(16,32),o=e.slice(32,64),g=new Ei.Counter(l),y=x(new Ei.ModeOfOperation.ctr(r,g).encrypt(i)),v=ht(I([n,y])),w={address:t.address.substring(2).toLowerCase(),id:Ni(c),version:3,crypto:{cipher:"aes-128-ctr",cipherparams:{iv:k(l).substring(2)},ciphertext:k(y).substring(2),kdf:"scrypt",kdfparams:{salt:k(f).substring(2),n:d,dklen:32,p:m,r:p},mac:v.substring(2)}};if(s){const t=Ai(16),e=new Ei.Counter(t),r=x(new Ei.ModeOfOperation.ctr(o,e).encrypt(s)),n=new Date,i=n.getUTCFullYear()+"-"+xi(n.getUTCMonth()+1,2)+"-"+xi(n.getUTCDate(),2)+"T"+xi(n.getUTCHours(),2)+"-"+xi(n.getUTCMinutes(),2)+"-"+xi(n.getUTCSeconds(),2)+".0Z";w["x-ethers"]={client:u,gethFilename:"UTC--"+i+"--"+w.address,mnemonicCounter:k(t).substring(2),mnemonicCiphertext:k(r).substring(2),path:a,locale:h,version:"0.1"}}return JSON.stringify(w)}))}(this,t,e,r)}static createRandom(t){let e=Ai(16);t||(t={}),t.extraEntropy&&(e=x(D(ht(I([e,t.extraEntropy])),0,16)));const r=vi(e,t.locale);return Zi.fromMnemonic(r,t.path,t.locale)}static fromEncryptedJson(t,e,r){return Wi(t,e,r).then((t=>new Zi(t)))}static fromEncryptedJsonSync(t,e){return new Zi(Vi(t,e))}static fromMnemonic(t,e,r){return e||(e=mi),new Zi(gi.fromMnemonic(t,null,r).derivePath(e))}}let Xi={PROOF_OF_INTEGRITY_ADDRESS:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",STEALTH_ANNOUNCER_ADDRESS:"0x5FbDB2315678afecb367f032d93F642f64180aa3"};if("undefined"==typeof window){const{fileURLToPath:t}=require("url"),{dirname:e}=require("path"),{readFileSync:r}=require("fs"),{join:n}=require("path");try{const i=t(import.meta.url),o=r(n(e(i),"contract-address.json"),"utf8");Xi=JSON.parse(o),console.log("Loaded contract addresses:",Xi)}catch(t){console.warn("Warning: contract-address.json not found or invalid")}}const Yi={CHAIN_ID:1337,PROOF_OF_INTEGRITY_ADDRESS:Xi.PROOF_OF_INTEGRITY_ADDRESS,STEALTH_ANNOUNCER_ADDRESS:Xi.STEALTH_ANNOUNCER_ADDRESS,RPC_URL:"http://127.0.0.1:8545",GUN_PEER:"http://localhost:8765/gun"},Qi={optimismSepolia:{STEALTH_ANNOUNCER_ADDRESS:"0xD0F2e9DA59d2DFECFdE67CcF17300BB6093A72f8",PROOF_OF_INTEGRITY_ADDRESS:"0x...",RPC_URL:"https://sepolia.optimism.io",CHAIN_ID:11155420},arbitrumSepolia:{STEALTH_ANNOUNCER_ADDRESS:"0x...",PROOF_OF_INTEGRITY_ADDRESS:"0x...",RPC_URL:"https://sepolia-rollup.arbitrum.io/rpc",CHAIN_ID:421614},localhost:{RPC_URL:"http://127.0.0.1:8545",CHAIN_ID:1337}};function to(t){let e;if("localhost"===t)try{const t=require("../config/contract-address.json");return e={...Qi.localhost,...t},console.log("Using local addresses:",e),e}catch(t){throw console.warn("No local addresses found"),new Error("No local addresses found. Did you run local deployment?")}if(e=Qi[t],!e)throw new Error(`Chain ${t} not supported. Supported chains: ${Object.keys(Qi).join(", ")}`);return e}Qi.optimismSepolia.STEALTH_ANNOUNCER_ADDRESS,Qi.optimismSepolia.PROOF_OF_INTEGRITY_ADDRESS;const eo=[{inputs:[{internalType:"address",name:"_devAddress",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{internalType:"string",name:"senderPublicKey",type:"string"},{internalType:"string",name:"spendingPublicKey",type:"string"},{internalType:"address",name:"stealthAddress",type:"address"},{internalType:"uint256",name:"timestamp",type:"uint256"}],name:"StealthPaymentAnnounced",type:"event"},{anonymous:!1,inputs:[{internalType:"address",name:"newAddress",type:"address"}],name:"DevAddressUpdated",type:"event"},{anonymous:!1,inputs:[{internalType:"uint256",name:"newFee",type:"uint256"}],name:"DevFeeUpdated",type:"event"},{inputs:[{internalType:"string",name:"senderPublicKey",type:"string"},{internalType:"string",name:"spendingPublicKey",type:"string"},{internalType:"address",name:"stealthAddress",type:"address"}],name:"announcePayment",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"devAddress",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"devFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getAnnouncementsCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"fromIndex",type:"uint256"},{internalType:"uint256",name:"toIndex",type:"uint256"}],name:"getAnnouncementsInRange",outputs:[{components:[{internalType:"string",name:"senderPublicKey",type:"string"},{internalType:"string",name:"spendingPublicKey",type:"string"},{internalType:"address",name:"stealthAddress",type:"address"},{internalType:"uint256",name:"timestamp",type:"uint256"}],internalType:"struct StealthAnnouncer.StealthAnnouncement[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_newFee",type:"uint256"}],name:"updateDevFee",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"_newAddress",type:"address"}],name:"updateDevAddress",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"withdrawStuckETH",outputs:[],stateMutability:"nonpayable",type:"function"}],ro=[{inputs:[{internalType:"bytes[]",name:"nodeIds",type:"bytes[]"},{internalType:"bytes32[]",name:"contentHashes",type:"bytes32[]"}],name:"batchUpdateData",outputs:[],stateMutability:"nonpayable",type:"function"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes",name:"nodeId",type:"bytes"},{indexed:!1,internalType:"bytes32",name:"contentHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"updater",type:"address"}],name:"DataUpdated",type:"event"},{inputs:[{internalType:"bytes",name:"nodeId",type:"bytes"}],name:"getLatestRecord",outputs:[{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"nodeId",type:"bytes"},{internalType:"bytes32",name:"contentHash",type:"bytes32"}],name:"updateData",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"nodeId",type:"bytes"},{internalType:"bytes32",name:"contentHash",type:"bytes32"}],name:"verifyData",outputs:[{internalType:"bool",name:"",type:"bool"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"}];let no,io="",oo="";const so="Access GunDB with Ethereum";let ao={PROOF_OF_INTEGRITY_ADDRESS:Qi.optimismSepolia.PROOF_OF_INTEGRITY_ADDRESS,STEALTH_ANNOUNCER_ADDRESS:Qi.optimismSepolia.STEALTH_ANNOUNCER_ADDRESS};if("undefined"==typeof window)try{const t=n(r(import.meta.url));try{const e=i(path.join(t,"contract-address.json"),"utf8");ao=JSON.parse(e),console.log("Loaded contract addresses:",ao)}catch(t){console.warn("Warning: contract-address.json not found or invalid")}}catch(t){console.error("Error loading Node.js modules:",t)}function ho(){return(void 0)((void 0)(32)).slice(2)}function uo(t){try{const e=(void 0)((void 0)(t));return console.log("Generated password:",e),e}catch(t){return console.error("Error generating password:",t),null}}function fo(t){const e="0x"+(t=>{const e="=".repeat((4-t.length%4)%4),r=t.replace(/-/g,"+").replace(/_/g,"/")+e,n=atob(r);return Array.from(n,(t=>t.charCodeAt(0).toString(16).padStart(2,"0"))).join("")})(t),r=new Zi(e);return{account:r,publicKey:r.address,privateKey:e}}const lo=async()=>{if(io&&oo){const t=new(void 0)(io,{chainId:Yi.CHAIN_ID,name:"localhost"});return new Zi(oo,t)}if("undefined"!=typeof window&&void 0!==window.ethereum){await window.ethereum.request({method:"eth_requestAccounts"});return new(void 0)(window.ethereum).getSigner()}throw new Error("No valid Ethereum provider found")};function co(t,e){try{const r=(void 0)(t),n=(void 0)((void 0)([r,(void 0)(e)])),i=new Zi(n);return console.log("Debug deriveStealthAddress:",{sharedSecretHex:n,spendingPublicKey:e,stealthPrivateKey:n,stealthAddress:i.address}),{stealthPrivateKey:n,stealthAddress:i.address,wallet:i}}catch(t){throw console.error("Error in deriveStealthAddress:",t),t}}t.chain.MESSAGE_TO_SIGN=so,t.chain.setSigner=function(t,e){return io=t,oo=e,console.log("Standalone configuration set"),this},t.chain.getSigner=lo(),t.chain.verifySignature=async function(t,e){try{return(void 0)(t,e)}catch(t){return console.error("Error verifying signature:",t),null}},t.chain.generatePassword=function(t){return uo(t)},t.chain.createSignature=async function(t){try{if(t!==so)throw new Error("Invalid message, valid message is: "+so);const e=await lo(),r=await e.signMessage(t);return console.log("Signature created:",r),r}catch(t){return console.error("Error creating signature:",t),null}},t.chain.createAndStoreEncryptedPair=async function(t,r){try{const n=this,i=await e.pair(),o=await e.pair(),s=await e.pair(),a=uo(r),h=await e.encrypt(JSON.stringify(i),a),u=await e.encrypt(JSON.stringify(o),a),f=await e.encrypt(JSON.stringify(s),a),l=fo(o.priv),c=fo(s.priv);n.get("gun-eth").get("users").get(t).put({pair:h,v_pair:u,s_pair:f,publicKeys:{viewingPublicKey:o.epub,viewingPublicKey:o.epub,spendingPublicKey:c.publicKey,ethViewingAddress:l.publicKey}}),console.log("Encrypted pairs and public keys stored for:",t)}catch(t){throw console.error("Error creating and storing encrypted pair:",t),t}},t.chain.getAndDecryptPair=async function(t,r){try{const n=this,i=await n.get("gun-eth").get("users").get(t).get("pair").then();if(!i)throw new Error("No encrypted data found for this address");const o=uo(r),s=await e.decrypt(i,o);return console.log(s),s}catch(t){return console.error("Error retrieving and decrypting pair:",t),null}},t.chain.proof=function(t,e,r,n){if(console.log("Proof plugin called with:",{chain:t,nodeId:e,data:r}),"function"!=typeof n)return console.error("Callback must be a function"),this;try{const i="development"===process.env.NODE_ENV&&"undefined"!=typeof window&&"localhost"===window.location.hostname?"localhost":t,o=to(i);console.log(`Using ${i} configuration:`,o);new Contract(o.PROOF_OF_INTEGRITY_ADDRESS,ro,signer);const s=async(t,e)=>{console.log("Verifying on chain:",{nodeId:t,contentHash:e});const r=await lo(),n=new Contract(no,ro,r),[i,o,s]=await n.verifyData(toUtf8Bytes(t),e);return console.log("Verification result:",{isValid:i,timestamp:o,updater:s}),{isValid:i,timestamp:o,updater:s}},a=async(t,e)=>{console.log("Writing on chain:",{nodeId:t,contentHash:e});const r=await lo(),n=new Contract(no,ro,r),i=await n.updateData(toUtf8Bytes(t),e);console.log("Transaction sent:",i.hash);const o=await i.wait();return console.log("Transaction confirmed:",o),i},h=async t=>{const e=await lo(),r=new Contract(no,ro,e),[n,i,o]=await r.getLatestRecord(toUtf8Bytes(t));return console.log("Latest record from blockchain:",{nodeId:t,contentHash:n,timestamp:i,updater:o}),{contentHash:n,timestamp:i,updater:o}};if(e&&!r)gun.get(e).once((async t=>{if(!t)return void(n&&n({err:"Node not found in GunDB"}));console.log("existingData",t);const r=t._contentHash;if(console.log("contentHash",r),r)try{const{isValid:t,timestamp:i,updater:o}=await s(e,r),a=await h(e);t?n&&n({ok:!0,message:"Data verified on blockchain",timestamp:i,updater:o,latestRecord:a}):n&&n({ok:!1,message:"Data not verified on blockchain",latestRecord:a})}catch(t){n&&n({err:t.message})}else n&&n({err:"No content hash found for this node"})}));else if(r&&!e){const t=ho(),e=JSON.stringify(r),i=keccak256(toUtf8Bytes(e));gun.get(t).put({...r,_contentHash:i},(async e=>{if(console.log("ack",e),e.err)n&&n({err:"Error saving data to GunDB"});else try{const e=await a(t,i);n&&n({ok:!0,message:"Data written to GunDB and blockchain",nodeId:t,txHash:e.hash})}catch(t){n&&n({err:t.message})}}))}else n&&n({err:"Invalid input. Provide either nodeId or data, not both."});return gun}catch(t){return n({err:t.message}),this}},t.chain.gunToEthAccount=function(t){return fo(t)},t.chain.generateStealthAddress=async function(t,r){try{const n=this,i=await n.get("gun-eth").get("users").get(t).get("publicKeys").then();if(!i||!i.viewingPublicKey||!i.spendingPublicKey)throw new Error("Recipient's public keys not found");const o=await this.verifySignature(so,r),s=uo(r),a=await n.get("gun-eth").get("users").get(o).then();if(!a||!a.s_pair)throw new Error("Sender's keys not found");let h;try{const t=await e.decrypt(a.s_pair,s);h="string"==typeof t?JSON.parse(t):t}catch(t){throw console.error("Error decrypting spending pair:",t),new Error("Unable to decrypt spending pair")}const u=await e.secret(i.viewingPublicKey,h);if(!u)throw new Error("Unable to generate shared secret");console.log("Generate shared secret:",u);const{stealthAddress:f}=co(u,i.spendingPublicKey);return{stealthAddress:f,senderPublicKey:h.epub,spendingPublicKey:i.spendingPublicKey}}catch(t){throw console.error("Error generating stealth address:",t),t}},t.chain.publishStealthKeys=async function(t){try{const r=this,n=await this.verifySignature(so,t),i=uo(t),o=await r.get("gun-eth").get("users").get(n).then();if(!o||!o.v_pair||!o.s_pair)throw new Error("Keys not found");const s=JSON.parse(await e.decrypt(o.v_pair,i)),a=JSON.parse(await e.decrypt(o.s_pair,i)),h=fo(s.priv),u=fo(a.priv);r.get("gun-eth").get("users").get(n).get("publicKeys").put({viewingPublicKey:h.publicKey,spendingPublicKey:u.publicKey}),console.log("Stealth public keys published successfully")}catch(t){throw console.error("Error publishing stealth keys:",t),t}},t.chain.recoverStealthFunds=async function(t,r,n,i){try{const o=this,s=uo(n),a=await this.verifySignature(so,n),h=await o.get("gun-eth").get("users").get(a).then();if(!h||!h.v_pair||!h.s_pair)throw new Error("Keys not found");let u;try{const t=await e.decrypt(h.v_pair,s);u="string"==typeof t?JSON.parse(t):t}catch(t){throw console.error("Error decrypting keys:",t),new Error("Unable to decrypt keys")}const f=await e.secret(r,u);if(!f)throw new Error("Unable to generate shared secret");console.log("Recover shared secret:",f);const{wallet:l,stealthAddress:c}=co(f,i);if(c.toLowerCase()!==t.toLowerCase())throw console.error("Mismatch:",{recovered:c,expected:t,sharedSecret:f}),new Error("Recovered stealth address does not match");return{wallet:l,address:c}}catch(t){throw console.error("Error recovering stealth funds:",t),t}},t.chain.announceStealthPayment=async function(t,e,r,n,i={onChain:!1,chain:"optimismSepolia"}){try{const o=this,s=await this.verifySignature(so,n);if(i.onChain){const n=await lo(),o=to(i.chain).STEALTH_ANNOUNCER_ADDRESS;console.log("Using contract address:",o);const s=new Contract(o,eo,n),a=await s.devFee();console.log("Dev fee:",a.toString());const h=await s.announcePayment(e,r,t,{value:a});console.log("Transaction sent:",h.hash);const u=await h.wait();console.log("Transaction confirmed:",u.hash),console.log("Stealth payment announced on-chain (dev fee paid)")}else o.get("gun-eth").get("stealth-payments").set({stealthAddress:t,senderAddress:s,senderPublicKey:e,spendingPublicKey:r,timestamp:Date.now()}),console.log("Stealth payment announced off-chain")}catch(t){throw console.error("Error announcing stealth payment:",t),console.error("Error details:",t.stack),t}},t.chain.getStealthPayments=async function(t,e={source:"both"}){try{const r=[];if("onChain"===e.source||"both"===e.source){const n=await lo(),i=to(e.chain||"optimismSepolia").STEALTH_ANNOUNCER_ADDRESS,o=new Contract(i,eo,n);try{const e=await o.getAnnouncementsCount(),n=Number(e.toString());if(console.log("Total on-chain announcements:",n),n>0){const e=100,i=n-1;for(let n=0;n<=i;n+=e){const s=Math.min(n+e-1,i),a=await o.getAnnouncementsInRange(n,s);for(const e of a)try{if(!(e&&e.stealthAddress&&e.senderPublicKey&&e.spendingPublicKey)){console.log("Invalid announcement:",e);continue}const n=await this.recoverStealthFunds(e.stealthAddress,e.senderPublicKey,t,e.spendingPublicKey);r.push({stealthAddress:e.stealthAddress,senderPublicKey:e.senderPublicKey,spendingPublicKey:e.spendingPublicKey,timestamp:Number(e.timestamp),source:"onChain",wallet:n})}catch(t){console.log(`Announcement not for us: ${e.stealthAddress}`);continue}}}}catch(t){console.error("Error retrieving on-chain announcements:",t)}}if("offChain"===e.source||"both"===e.source){const t=this,e=await new Promise((e=>{const r=[];t.get("gun-eth").get("stealth-payments").get(recipientAddress).map().once(((t,e)=>{t?.stealthAddress&&r.push({...t,id:e,source:"offChain"})})),setTimeout((()=>e(r)),2e3)}));r.push(...e)}return console.log(`Found ${r.length} stealth payments`),r}catch(t){throw console.error("Error retrieving stealth payments:",t),t}},t.chain.cleanStealthPayments=async function(t){try{const e=this,r=await e.get("gun-eth").get("stealth-payments").get(t).map().once().then();r&&Object.keys(r).forEach((async n=>{const i=r[n];i&&i.stealthAddress&&i.senderPublicKey&&i.spendingPublicKey||await e.get("gun-eth").get("stealth-payments").get(t).get(n).put(null)}))}catch(t){console.error("Error cleaning stealth payments:",t)}};class po{static generateRandomId=ho;static generatePassword=uo;static gunToEthAccount=fo;static getSigner=lo;static deriveStealthAddress=co;static chainMethods={setSigner:t.chain.setSigner,getSigner:t.chain.getSigner,verifySignature:t.chain.verifySignature,generatePassword:t.chain.generatePassword,createSignature:t.chain.createSignature,createAndStoreEncryptedPair:t.chain.createAndStoreEncryptedPair,getAndDecryptPair:t.chain.getAndDecryptPair,proof:t.chain.proof,gunToEthAccount:t.chain.gunToEthAccount,generateStealthAddress:t.chain.generateStealthAddress,publishStealthKeys:t.chain.publishStealthKeys,recoverStealthFunds:t.chain.recoverStealthFunds,announceStealthPayment:t.chain.announceStealthPayment,getStealthPayments:t.chain.getStealthPayments,cleanStealthPayments:t.chain.cleanStealthPayments};static MESSAGE_TO_SIGN=so;static PROOF_CONTRACT_ADDRESS=no;static LOCAL_CONFIG=Yi}export{po as GunEth,so as MESSAGE_TO_SIGN,co as deriveStealthAddress,uo as generatePassword,ho as generateRandomId,lo as getSigner,fo as gunToEthAccount};
|
1
|
+
import Gun from 'gun';
|
2
|
+
export { default } from 'gun';
|
3
|
+
import SEA from 'gun/sea.js';
|
4
|
+
import { ethers } from 'ethers';
|
5
|
+
import { fileURLToPath } from 'url';
|
6
|
+
import { dirname } from 'path';
|
7
|
+
import { readFileSync } from 'fs';
|
8
|
+
|
9
|
+
let contractAddresses$1 = {
|
10
|
+
PROOF_OF_INTEGRITY_ADDRESS: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
11
|
+
STEALTH_ANNOUNCER_ADDRESS: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
|
12
|
+
};
|
13
|
+
|
14
|
+
if (typeof window === 'undefined') {
|
15
|
+
const { fileURLToPath } = require('url');
|
16
|
+
const { dirname } = require('path');
|
17
|
+
const { readFileSync } = require('fs');
|
18
|
+
const { join } = require('path');
|
19
|
+
|
20
|
+
try {
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
22
|
+
const __dirname = dirname(__filename);
|
23
|
+
const rawdata = readFileSync(join(__dirname, 'contract-address.json'), 'utf8');
|
24
|
+
contractAddresses$1 = JSON.parse(rawdata);
|
25
|
+
console.log("Loaded contract addresses:", contractAddresses$1);
|
26
|
+
} catch (error) {
|
27
|
+
console.warn("Warning: contract-address.json not found or invalid");
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
const LOCAL_CONFIG = {
|
32
|
+
CHAIN_ID: 1337,
|
33
|
+
PROOF_OF_INTEGRITY_ADDRESS: contractAddresses$1.PROOF_OF_INTEGRITY_ADDRESS,
|
34
|
+
STEALTH_ANNOUNCER_ADDRESS: contractAddresses$1.STEALTH_ANNOUNCER_ADDRESS,
|
35
|
+
RPC_URL: "http://127.0.0.1:8545",
|
36
|
+
GUN_PEER: "http://localhost:8765/gun"
|
37
|
+
};
|
38
|
+
|
39
|
+
// Indirizzi di produzione per diverse chain
|
40
|
+
const CHAIN_CONFIG = {
|
41
|
+
optimismSepolia: {
|
42
|
+
STEALTH_ANNOUNCER_ADDRESS: "0xD0F2e9DA59d2DFECFdE67CcF17300BB6093A72f8",
|
43
|
+
PROOF_OF_INTEGRITY_ADDRESS: "0x...",
|
44
|
+
RPC_URL: "https://sepolia.optimism.io",
|
45
|
+
CHAIN_ID: 11155420
|
46
|
+
},
|
47
|
+
arbitrumSepolia: {
|
48
|
+
STEALTH_ANNOUNCER_ADDRESS: "0x...",
|
49
|
+
PROOF_OF_INTEGRITY_ADDRESS: "0x...",
|
50
|
+
RPC_URL: "https://sepolia-rollup.arbitrum.io/rpc",
|
51
|
+
CHAIN_ID: 421614
|
52
|
+
},
|
53
|
+
localhost: {
|
54
|
+
RPC_URL: "http://127.0.0.1:8545",
|
55
|
+
CHAIN_ID: 1337
|
56
|
+
}
|
57
|
+
};
|
58
|
+
|
59
|
+
// Esporta gli indirizzi di default (Optimism Sepolia)
|
60
|
+
CHAIN_CONFIG.optimismSepolia.STEALTH_ANNOUNCER_ADDRESS;
|
61
|
+
CHAIN_CONFIG.optimismSepolia.PROOF_OF_INTEGRITY_ADDRESS;
|
62
|
+
|
63
|
+
// Funzione per ottenere gli indirizzi corretti
|
64
|
+
function getAddressesForChain(chainName) {
|
65
|
+
let config;
|
66
|
+
|
67
|
+
// Se è localhost, prova a caricare gli indirizzi locali
|
68
|
+
if (chainName === 'localhost') {
|
69
|
+
try {
|
70
|
+
// Carica gli indirizzi dal file generato dal deploy locale
|
71
|
+
const localAddresses = require('../config/contract-address.json');
|
72
|
+
config = {
|
73
|
+
...CHAIN_CONFIG.localhost,
|
74
|
+
...localAddresses
|
75
|
+
};
|
76
|
+
console.log("Using local addresses:", config);
|
77
|
+
return config;
|
78
|
+
} catch (err) {
|
79
|
+
console.warn('No local addresses found');
|
80
|
+
throw new Error('No local addresses found. Did you run local deployment?');
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
// Altrimenti usa gli indirizzi di produzione
|
85
|
+
config = CHAIN_CONFIG[chainName];
|
86
|
+
if (!config) {
|
87
|
+
throw new Error(`Chain ${chainName} not supported. Supported chains: ${Object.keys(CHAIN_CONFIG).join(', ')}`);
|
88
|
+
}
|
89
|
+
|
90
|
+
return config;
|
91
|
+
}
|
92
|
+
|
93
|
+
// Funzione helper per verificare se siamo in ambiente locale
|
94
|
+
function isLocalEnvironment() {
|
95
|
+
return process.env.NODE_ENV === 'development' &&
|
96
|
+
typeof window !== 'undefined' &&
|
97
|
+
window.location.hostname === 'localhost';
|
98
|
+
}
|
99
|
+
|
100
|
+
const STEALTH_ANNOUNCER_ABI = [
|
101
|
+
{
|
102
|
+
"inputs": [
|
103
|
+
{
|
104
|
+
"internalType": "address",
|
105
|
+
"name": "_devAddress",
|
106
|
+
"type": "address"
|
107
|
+
}
|
108
|
+
],
|
109
|
+
"stateMutability": "nonpayable",
|
110
|
+
"type": "constructor"
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"anonymous": false,
|
114
|
+
"inputs": [
|
115
|
+
{
|
116
|
+
"internalType": "string",
|
117
|
+
"name": "senderPublicKey",
|
118
|
+
"type": "string"
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"internalType": "string",
|
122
|
+
"name": "spendingPublicKey",
|
123
|
+
"type": "string"
|
124
|
+
},
|
125
|
+
{
|
126
|
+
"internalType": "address",
|
127
|
+
"name": "stealthAddress",
|
128
|
+
"type": "address"
|
129
|
+
},
|
130
|
+
{
|
131
|
+
"internalType": "uint256",
|
132
|
+
"name": "timestamp",
|
133
|
+
"type": "uint256"
|
134
|
+
}
|
135
|
+
],
|
136
|
+
"name": "StealthPaymentAnnounced",
|
137
|
+
"type": "event"
|
138
|
+
},
|
139
|
+
{
|
140
|
+
"anonymous": false,
|
141
|
+
"inputs": [
|
142
|
+
{
|
143
|
+
"internalType": "address",
|
144
|
+
"name": "newAddress",
|
145
|
+
"type": "address"
|
146
|
+
}
|
147
|
+
],
|
148
|
+
"name": "DevAddressUpdated",
|
149
|
+
"type": "event"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"anonymous": false,
|
153
|
+
"inputs": [
|
154
|
+
{
|
155
|
+
"internalType": "uint256",
|
156
|
+
"name": "newFee",
|
157
|
+
"type": "uint256"
|
158
|
+
}
|
159
|
+
],
|
160
|
+
"name": "DevFeeUpdated",
|
161
|
+
"type": "event"
|
162
|
+
},
|
163
|
+
{
|
164
|
+
"inputs": [
|
165
|
+
{
|
166
|
+
"internalType": "string",
|
167
|
+
"name": "senderPublicKey",
|
168
|
+
"type": "string"
|
169
|
+
},
|
170
|
+
{
|
171
|
+
"internalType": "string",
|
172
|
+
"name": "spendingPublicKey",
|
173
|
+
"type": "string"
|
174
|
+
},
|
175
|
+
{
|
176
|
+
"internalType": "address",
|
177
|
+
"name": "stealthAddress",
|
178
|
+
"type": "address"
|
179
|
+
}
|
180
|
+
],
|
181
|
+
"name": "announcePayment",
|
182
|
+
"outputs": [],
|
183
|
+
"stateMutability": "payable",
|
184
|
+
"type": "function"
|
185
|
+
},
|
186
|
+
{
|
187
|
+
"inputs": [],
|
188
|
+
"name": "devAddress",
|
189
|
+
"outputs": [
|
190
|
+
{
|
191
|
+
"internalType": "address",
|
192
|
+
"name": "",
|
193
|
+
"type": "address"
|
194
|
+
}
|
195
|
+
],
|
196
|
+
"stateMutability": "view",
|
197
|
+
"type": "function"
|
198
|
+
},
|
199
|
+
{
|
200
|
+
"inputs": [],
|
201
|
+
"name": "devFee",
|
202
|
+
"outputs": [
|
203
|
+
{
|
204
|
+
"internalType": "uint256",
|
205
|
+
"name": "",
|
206
|
+
"type": "uint256"
|
207
|
+
}
|
208
|
+
],
|
209
|
+
"stateMutability": "view",
|
210
|
+
"type": "function"
|
211
|
+
},
|
212
|
+
{
|
213
|
+
"inputs": [],
|
214
|
+
"name": "getAnnouncementsCount",
|
215
|
+
"outputs": [
|
216
|
+
{
|
217
|
+
"internalType": "uint256",
|
218
|
+
"name": "",
|
219
|
+
"type": "uint256"
|
220
|
+
}
|
221
|
+
],
|
222
|
+
"stateMutability": "view",
|
223
|
+
"type": "function"
|
224
|
+
},
|
225
|
+
{
|
226
|
+
"inputs": [
|
227
|
+
{
|
228
|
+
"internalType": "uint256",
|
229
|
+
"name": "fromIndex",
|
230
|
+
"type": "uint256"
|
231
|
+
},
|
232
|
+
{
|
233
|
+
"internalType": "uint256",
|
234
|
+
"name": "toIndex",
|
235
|
+
"type": "uint256"
|
236
|
+
}
|
237
|
+
],
|
238
|
+
"name": "getAnnouncementsInRange",
|
239
|
+
"outputs": [
|
240
|
+
{
|
241
|
+
"components": [
|
242
|
+
{
|
243
|
+
"internalType": "string",
|
244
|
+
"name": "senderPublicKey",
|
245
|
+
"type": "string"
|
246
|
+
},
|
247
|
+
{
|
248
|
+
"internalType": "string",
|
249
|
+
"name": "spendingPublicKey",
|
250
|
+
"type": "string"
|
251
|
+
},
|
252
|
+
{
|
253
|
+
"internalType": "address",
|
254
|
+
"name": "stealthAddress",
|
255
|
+
"type": "address"
|
256
|
+
},
|
257
|
+
{
|
258
|
+
"internalType": "uint256",
|
259
|
+
"name": "timestamp",
|
260
|
+
"type": "uint256"
|
261
|
+
}
|
262
|
+
],
|
263
|
+
"internalType": "struct StealthAnnouncer.StealthAnnouncement[]",
|
264
|
+
"name": "",
|
265
|
+
"type": "tuple[]"
|
266
|
+
}
|
267
|
+
],
|
268
|
+
"stateMutability": "view",
|
269
|
+
"type": "function"
|
270
|
+
},
|
271
|
+
{
|
272
|
+
"inputs": [
|
273
|
+
{
|
274
|
+
"internalType": "uint256",
|
275
|
+
"name": "_newFee",
|
276
|
+
"type": "uint256"
|
277
|
+
}
|
278
|
+
],
|
279
|
+
"name": "updateDevFee",
|
280
|
+
"outputs": [],
|
281
|
+
"stateMutability": "nonpayable",
|
282
|
+
"type": "function"
|
283
|
+
},
|
284
|
+
{
|
285
|
+
"inputs": [
|
286
|
+
{
|
287
|
+
"internalType": "address",
|
288
|
+
"name": "_newAddress",
|
289
|
+
"type": "address"
|
290
|
+
}
|
291
|
+
],
|
292
|
+
"name": "updateDevAddress",
|
293
|
+
"outputs": [],
|
294
|
+
"stateMutability": "nonpayable",
|
295
|
+
"type": "function"
|
296
|
+
},
|
297
|
+
{
|
298
|
+
"inputs": [],
|
299
|
+
"name": "withdrawStuckETH",
|
300
|
+
"outputs": [],
|
301
|
+
"stateMutability": "nonpayable",
|
302
|
+
"type": "function"
|
303
|
+
}
|
304
|
+
];
|
305
|
+
|
306
|
+
const PROOF_OF_INTEGRITY_ABI = [
|
307
|
+
{
|
308
|
+
"inputs": [
|
309
|
+
{
|
310
|
+
"internalType": "bytes[]",
|
311
|
+
"name": "nodeIds",
|
312
|
+
"type": "bytes[]"
|
313
|
+
},
|
314
|
+
{
|
315
|
+
"internalType": "bytes32[]",
|
316
|
+
"name": "contentHashes",
|
317
|
+
"type": "bytes32[]"
|
318
|
+
}
|
319
|
+
],
|
320
|
+
"name": "batchUpdateData",
|
321
|
+
"outputs": [],
|
322
|
+
"stateMutability": "nonpayable",
|
323
|
+
"type": "function"
|
324
|
+
},
|
325
|
+
{
|
326
|
+
"anonymous": false,
|
327
|
+
"inputs": [
|
328
|
+
{
|
329
|
+
"indexed": true,
|
330
|
+
"internalType": "bytes",
|
331
|
+
"name": "nodeId",
|
332
|
+
"type": "bytes"
|
333
|
+
},
|
334
|
+
{
|
335
|
+
"indexed": false,
|
336
|
+
"internalType": "bytes32",
|
337
|
+
"name": "contentHash",
|
338
|
+
"type": "bytes32"
|
339
|
+
},
|
340
|
+
{
|
341
|
+
"indexed": false,
|
342
|
+
"internalType": "address",
|
343
|
+
"name": "updater",
|
344
|
+
"type": "address"
|
345
|
+
}
|
346
|
+
],
|
347
|
+
"name": "DataUpdated",
|
348
|
+
"type": "event"
|
349
|
+
},
|
350
|
+
{
|
351
|
+
"inputs": [
|
352
|
+
{
|
353
|
+
"internalType": "bytes",
|
354
|
+
"name": "nodeId",
|
355
|
+
"type": "bytes"
|
356
|
+
}
|
357
|
+
],
|
358
|
+
"name": "getLatestRecord",
|
359
|
+
"outputs": [
|
360
|
+
{
|
361
|
+
"internalType": "bytes32",
|
362
|
+
"name": "",
|
363
|
+
"type": "bytes32"
|
364
|
+
},
|
365
|
+
{
|
366
|
+
"internalType": "uint256",
|
367
|
+
"name": "",
|
368
|
+
"type": "uint256"
|
369
|
+
},
|
370
|
+
{
|
371
|
+
"internalType": "address",
|
372
|
+
"name": "",
|
373
|
+
"type": "address"
|
374
|
+
}
|
375
|
+
],
|
376
|
+
"stateMutability": "view",
|
377
|
+
"type": "function"
|
378
|
+
},
|
379
|
+
{
|
380
|
+
"inputs": [
|
381
|
+
{
|
382
|
+
"internalType": "bytes",
|
383
|
+
"name": "nodeId",
|
384
|
+
"type": "bytes"
|
385
|
+
},
|
386
|
+
{
|
387
|
+
"internalType": "bytes32",
|
388
|
+
"name": "contentHash",
|
389
|
+
"type": "bytes32"
|
390
|
+
}
|
391
|
+
],
|
392
|
+
"name": "updateData",
|
393
|
+
"outputs": [],
|
394
|
+
"stateMutability": "nonpayable",
|
395
|
+
"type": "function"
|
396
|
+
},
|
397
|
+
{
|
398
|
+
"inputs": [
|
399
|
+
{
|
400
|
+
"internalType": "bytes",
|
401
|
+
"name": "nodeId",
|
402
|
+
"type": "bytes"
|
403
|
+
},
|
404
|
+
{
|
405
|
+
"internalType": "bytes32",
|
406
|
+
"name": "contentHash",
|
407
|
+
"type": "bytes32"
|
408
|
+
}
|
409
|
+
],
|
410
|
+
"name": "verifyData",
|
411
|
+
"outputs": [
|
412
|
+
{
|
413
|
+
"internalType": "bool",
|
414
|
+
"name": "",
|
415
|
+
"type": "bool"
|
416
|
+
},
|
417
|
+
{
|
418
|
+
"internalType": "uint256",
|
419
|
+
"name": "",
|
420
|
+
"type": "uint256"
|
421
|
+
},
|
422
|
+
{
|
423
|
+
"internalType": "address",
|
424
|
+
"name": "",
|
425
|
+
"type": "address"
|
426
|
+
}
|
427
|
+
],
|
428
|
+
"stateMutability": "view",
|
429
|
+
"type": "function"
|
430
|
+
}
|
431
|
+
];
|
432
|
+
|
433
|
+
// =============================================
|
434
|
+
// IMPORTS AND GLOBAL VARIABLES
|
435
|
+
// =============================================
|
436
|
+
|
437
|
+
let PROOF_CONTRACT_ADDRESS;
|
438
|
+
let rpcUrl = "";
|
439
|
+
let privateKey = "";
|
440
|
+
|
441
|
+
const MESSAGE_TO_SIGN = "Access GunDB with Ethereum";
|
442
|
+
|
443
|
+
let contractAddresses = {
|
444
|
+
PROOF_OF_INTEGRITY_ADDRESS: CHAIN_CONFIG.optimismSepolia.PROOF_OF_INTEGRITY_ADDRESS,
|
445
|
+
STEALTH_ANNOUNCER_ADDRESS: CHAIN_CONFIG.optimismSepolia.STEALTH_ANNOUNCER_ADDRESS
|
446
|
+
};
|
447
|
+
|
448
|
+
// Solo per Node.js
|
449
|
+
if (typeof window === 'undefined') {
|
450
|
+
try {
|
451
|
+
const __filename = fileURLToPath(import.meta.url);
|
452
|
+
const __dirname = dirname(__filename);
|
453
|
+
|
454
|
+
try {
|
455
|
+
const rawdata = readFileSync(path.join(__dirname, 'contract-address.json'), 'utf8');
|
456
|
+
contractAddresses = JSON.parse(rawdata);
|
457
|
+
console.log('Loaded contract addresses:', contractAddresses);
|
458
|
+
} catch (err) {
|
459
|
+
console.warn('Warning: contract-address.json not found or invalid');
|
460
|
+
}
|
461
|
+
} catch (error) {
|
462
|
+
console.error('Error loading Node.js modules:', error);
|
463
|
+
}
|
464
|
+
}
|
465
|
+
|
466
|
+
// =============================================
|
467
|
+
// UTILITY FUNCTIONS
|
468
|
+
// =============================================
|
469
|
+
/**
|
470
|
+
* Generates a random node ID for GunDB
|
471
|
+
* @returns {string} A random hexadecimal string
|
472
|
+
*/
|
473
|
+
function generateRandomId() {
|
474
|
+
const randomBytes = ethers.randomBytes(32);
|
475
|
+
return ethers.hexlify(randomBytes).slice(2);
|
476
|
+
}
|
477
|
+
|
478
|
+
/**
|
479
|
+
* Generates a password from a signature.
|
480
|
+
* @param {string} signature - The signature to derive the password from.
|
481
|
+
* @returns {string|null} The generated password or null if generation fails.
|
482
|
+
*/
|
483
|
+
function generatePassword(signature) {
|
484
|
+
try {
|
485
|
+
const signatureBytes = ethers.toUtf8Bytes(signature);
|
486
|
+
const hash = ethers.keccak256(signatureBytes);
|
487
|
+
console.log("Generated password:", hash);
|
488
|
+
return hash;
|
489
|
+
} catch (error) {
|
490
|
+
console.error("Error generating password:", error);
|
491
|
+
return null;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
|
495
|
+
/**
|
496
|
+
* Converts a Gun private key to an Ethereum account.
|
497
|
+
* @param {string} gunPrivateKey - The Gun private key in base64url format.
|
498
|
+
* @returns {Object} An object containing the Ethereum account and public key.
|
499
|
+
*/
|
500
|
+
function gunToEthAccount(gunPrivateKey) {
|
501
|
+
// Function to convert base64url to hex
|
502
|
+
const base64UrlToHex = (base64url) => {
|
503
|
+
const padding = "=".repeat((4 - (base64url.length % 4)) % 4);
|
504
|
+
const base64 = base64url.replace(/-/g, "+").replace(/_/g, "/") + padding;
|
505
|
+
const binary = atob(base64);
|
506
|
+
return Array.from(binary, (char) =>
|
507
|
+
char.charCodeAt(0).toString(16).padStart(2, "0")
|
508
|
+
).join("");
|
509
|
+
};
|
510
|
+
|
511
|
+
// Convert Gun private key to hex format
|
512
|
+
const hexPrivateKey = "0x" + base64UrlToHex(gunPrivateKey);
|
513
|
+
|
514
|
+
// Create an Ethereum wallet from the private key
|
515
|
+
const wallet = new ethers.Wallet(hexPrivateKey);
|
516
|
+
|
517
|
+
// Get the public address (public key)
|
518
|
+
const publicKey = wallet.address;
|
519
|
+
|
520
|
+
return {
|
521
|
+
account: wallet,
|
522
|
+
publicKey: publicKey,
|
523
|
+
privateKey: hexPrivateKey,
|
524
|
+
};
|
525
|
+
}
|
526
|
+
|
527
|
+
/**
|
528
|
+
* Gets an Ethereum signer based on current configuration
|
529
|
+
* @returns {Promise<ethers.Signer>} The configured signer
|
530
|
+
* @throws {Error} If no valid provider is found
|
531
|
+
*/
|
532
|
+
const getSigner = async () => {
|
533
|
+
if (rpcUrl && privateKey) {
|
534
|
+
const provider = new ethers.JsonRpcProvider(rpcUrl, {
|
535
|
+
chainId: LOCAL_CONFIG.CHAIN_ID,
|
536
|
+
name: "localhost"
|
537
|
+
});
|
538
|
+
return new Wallet(privateKey, provider);
|
539
|
+
} else if (
|
540
|
+
typeof window !== "undefined" &&
|
541
|
+
typeof window.ethereum !== "undefined"
|
542
|
+
) {
|
543
|
+
await window.ethereum.request({ method: "eth_requestAccounts" });
|
544
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
545
|
+
return provider.getSigner();
|
546
|
+
} else {
|
547
|
+
throw new Error("No valid Ethereum provider found");
|
548
|
+
}
|
549
|
+
};
|
550
|
+
|
551
|
+
/**
|
552
|
+
* Utility function to generate stealth address
|
553
|
+
* @param {string} sharedSecret - The shared secret
|
554
|
+
* @param {string} spendingPublicKey - The spending public key
|
555
|
+
* @returns {Object} The stealth address and private key
|
556
|
+
*/
|
557
|
+
function deriveStealthAddress(sharedSecret, spendingPublicKey) {
|
558
|
+
try {
|
559
|
+
const sharedSecretBytes = ethers.toUtf8Bytes(sharedSecret);
|
560
|
+
const spendingPublicKeyBytes = ethers.toUtf8Bytes(spendingPublicKey);
|
561
|
+
|
562
|
+
const stealthPrivateKey = ethers.keccak256(
|
563
|
+
ethers.concat([
|
564
|
+
sharedSecretBytes,
|
565
|
+
spendingPublicKeyBytes
|
566
|
+
])
|
567
|
+
);
|
568
|
+
|
569
|
+
const stealthWallet = new Wallet(stealthPrivateKey);
|
570
|
+
|
571
|
+
console.log("Debug deriveStealthAddress:", {
|
572
|
+
sharedSecretHex: stealthPrivateKey,
|
573
|
+
spendingPublicKey,
|
574
|
+
stealthPrivateKey,
|
575
|
+
stealthAddress: stealthWallet.address
|
576
|
+
});
|
577
|
+
|
578
|
+
return {
|
579
|
+
stealthPrivateKey,
|
580
|
+
stealthAddress: stealthWallet.address,
|
581
|
+
wallet: stealthWallet
|
582
|
+
};
|
583
|
+
} catch (error) {
|
584
|
+
console.error("Error in deriveStealthAddress:", error);
|
585
|
+
throw error;
|
586
|
+
}
|
587
|
+
}
|
588
|
+
|
589
|
+
// =============================================
|
590
|
+
// BASIC GUN-ETH CHAIN METHODS
|
591
|
+
// =============================================
|
592
|
+
|
593
|
+
// Set the message to sign
|
594
|
+
Gun.chain.MESSAGE_TO_SIGN = MESSAGE_TO_SIGN;
|
595
|
+
|
596
|
+
/**
|
597
|
+
* Sets standalone configuration for Gun.
|
598
|
+
* @param {string} newRpcUrl - The new RPC URL.
|
599
|
+
* @param {string} newPrivateKey - The new private key.
|
600
|
+
* @returns {Gun} The Gun instance for chaining.
|
601
|
+
*/
|
602
|
+
Gun.chain.setSigner = function (newRpcUrl, newPrivateKey) {
|
603
|
+
rpcUrl = newRpcUrl;
|
604
|
+
privateKey = newPrivateKey;
|
605
|
+
console.log("Standalone configuration set");
|
606
|
+
return this;
|
607
|
+
};
|
608
|
+
|
609
|
+
Gun.chain.getSigner = getSigner();
|
610
|
+
|
611
|
+
/**
|
612
|
+
* Verifies an Ethereum signature.
|
613
|
+
* @param {string} message - The original message that was signed.
|
614
|
+
* @param {string} signature - The signature to verify.
|
615
|
+
* @returns {Promise<string|null>} The recovered address or null if verification fails.
|
616
|
+
*/
|
617
|
+
Gun.chain.verifySignature = async function (message, signature) {
|
618
|
+
try {
|
619
|
+
const recoveredAddress = ethers.verifyMessage(message, signature);
|
620
|
+
return recoveredAddress;
|
621
|
+
} catch (error) {
|
622
|
+
console.error("Error verifying signature:", error);
|
623
|
+
return null;
|
624
|
+
}
|
625
|
+
};
|
626
|
+
|
627
|
+
/**
|
628
|
+
* Generates a password from a signature.
|
629
|
+
* @param {string} signature - The signature to derive the password from.
|
630
|
+
* @returns {string|null} The generated password or null if generation fails.
|
631
|
+
*/
|
632
|
+
Gun.chain.generatePassword = function (signature) {
|
633
|
+
return generatePassword(signature);
|
634
|
+
};
|
635
|
+
|
636
|
+
/**
|
637
|
+
* Creates an Ethereum signature for a given message.
|
638
|
+
* @param {string} message - The message to sign.
|
639
|
+
* @returns {Promise<string|null>} The signature or null if signing fails.
|
640
|
+
*/
|
641
|
+
Gun.chain.createSignature = async function (message) {
|
642
|
+
try {
|
643
|
+
// Check if message matches MESSAGE_TO_SIGN
|
644
|
+
if (message !== MESSAGE_TO_SIGN) {
|
645
|
+
throw new Error("Invalid message, valid message is: " + MESSAGE_TO_SIGN);
|
646
|
+
}
|
647
|
+
const signer = await getSigner();
|
648
|
+
const signature = await signer.signMessage(message);
|
649
|
+
console.log("Signature created:", signature);
|
650
|
+
return signature;
|
651
|
+
} catch (error) {
|
652
|
+
console.error("Error creating signature:", error);
|
653
|
+
return null;
|
654
|
+
}
|
655
|
+
};
|
656
|
+
|
657
|
+
// =============================================
|
658
|
+
// KEY PAIR MANAGEMENT
|
659
|
+
// =============================================
|
660
|
+
/**
|
661
|
+
* Creates and stores an encrypted key pair for a given address.
|
662
|
+
* @param {string} address - The Ethereum address to associate with the key pair.
|
663
|
+
* @param {string} signature - The signature to use for encryption.
|
664
|
+
* @returns {Promise<void>}
|
665
|
+
*/
|
666
|
+
Gun.chain.createAndStoreEncryptedPair = async function (address, signature) {
|
667
|
+
try {
|
668
|
+
const gun = this;
|
669
|
+
const pair = await SEA.pair();
|
670
|
+
const v_pair = await SEA.pair();
|
671
|
+
const s_pair = await SEA.pair();
|
672
|
+
const password = generatePassword(signature);
|
673
|
+
|
674
|
+
// Save original SEA pairs
|
675
|
+
const encryptedPair = await SEA.encrypt(JSON.stringify(pair), password);
|
676
|
+
const encryptedV_pair = await SEA.encrypt(JSON.stringify(v_pair), password);
|
677
|
+
const encryptedS_pair = await SEA.encrypt(JSON.stringify(s_pair), password);
|
678
|
+
|
679
|
+
// Convert only to get Ethereum addresses
|
680
|
+
const viewingAccount = gunToEthAccount(v_pair.priv);
|
681
|
+
const spendingAccount = gunToEthAccount(s_pair.priv);
|
682
|
+
|
683
|
+
gun.get("gun-eth").get("users").get(address).put({
|
684
|
+
pair: encryptedPair,
|
685
|
+
v_pair: encryptedV_pair,
|
686
|
+
s_pair: encryptedS_pair,
|
687
|
+
publicKeys: {
|
688
|
+
viewingPublicKey: v_pair.epub, // Use SEA encryption public key
|
689
|
+
viewingPublicKey: v_pair.epub, // Use SEA encryption public key
|
690
|
+
spendingPublicKey: spendingAccount.publicKey, // Use Ethereum address
|
691
|
+
ethViewingAddress: viewingAccount.publicKey // Also save Ethereum address
|
692
|
+
}
|
693
|
+
});
|
694
|
+
|
695
|
+
console.log("Encrypted pairs and public keys stored for:", address);
|
696
|
+
} catch (error) {
|
697
|
+
console.error("Error creating and storing encrypted pair:", error);
|
698
|
+
throw error;
|
699
|
+
}
|
700
|
+
};
|
701
|
+
|
702
|
+
/**
|
703
|
+
* Retrieves and decrypts a stored key pair for a given address.
|
704
|
+
* @param {string} address - The Ethereum address associated with the key pair.
|
705
|
+
* @param {string} signature - The signature to use for decryption.
|
706
|
+
* @returns {Promise<Object|null>} The decrypted key pair or null if retrieval fails.
|
707
|
+
*/
|
708
|
+
Gun.chain.getAndDecryptPair = async function (address, signature) {
|
709
|
+
try {
|
710
|
+
const gun = this;
|
711
|
+
const encryptedData = await gun
|
712
|
+
.get("gun-eth")
|
713
|
+
.get("users")
|
714
|
+
.get(address)
|
715
|
+
.get("pair")
|
716
|
+
.then();
|
717
|
+
if (!encryptedData) {
|
718
|
+
throw new Error("No encrypted data found for this address");
|
719
|
+
}
|
720
|
+
const password = generatePassword(signature);
|
721
|
+
const decryptedPair = await SEA.decrypt(encryptedData, password);
|
722
|
+
console.log(decryptedPair);
|
723
|
+
return decryptedPair;
|
724
|
+
} catch (error) {
|
725
|
+
console.error("Error retrieving and decrypting pair:", error);
|
726
|
+
return null;
|
727
|
+
}
|
728
|
+
};
|
729
|
+
|
730
|
+
// =============================================
|
731
|
+
// PROOF OF INTEGRITY
|
732
|
+
// =============================================
|
733
|
+
/**
|
734
|
+
* Proof of Integrity
|
735
|
+
* @param {string} chain - The blockchain to use (e.g., "optimismSepolia").
|
736
|
+
* @param {string} nodeId - The ID of the node to verify or write.
|
737
|
+
* @param {Object} data - The data to write (if writing).
|
738
|
+
* @param {Function} callback - Callback function to handle the result.
|
739
|
+
* @returns {Gun} The Gun instance for chaining.
|
740
|
+
*/
|
741
|
+
Gun.chain.proof = function (chain, nodeId, data, callback) {
|
742
|
+
console.log("Proof plugin called with:", { chain, nodeId, data });
|
743
|
+
|
744
|
+
if (typeof callback !== "function") {
|
745
|
+
console.error("Callback must be a function");
|
746
|
+
return this;
|
747
|
+
}
|
748
|
+
|
749
|
+
try {
|
750
|
+
// Se siamo in localhost e in development, usa automaticamente la chain locale
|
751
|
+
const targetChain = isLocalEnvironment() ? 'localhost' : chain;
|
752
|
+
const chainConfig = getAddressesForChain(targetChain);
|
753
|
+
|
754
|
+
console.log(`Using ${targetChain} configuration:`, chainConfig);
|
755
|
+
|
756
|
+
// Usa gli indirizzi dalla configurazione
|
757
|
+
const contract = new ethers.Contract(
|
758
|
+
chainConfig.PROOF_OF_INTEGRITY_ADDRESS,
|
759
|
+
PROOF_OF_INTEGRITY_ABI,
|
760
|
+
signer
|
761
|
+
);
|
762
|
+
|
763
|
+
// Funzione per verificare on-chain
|
764
|
+
const verifyOnChain = async (nodeId, contentHash) => {
|
765
|
+
console.log("Verifying on chain:", { nodeId, contentHash });
|
766
|
+
const signer = await getSigner();
|
767
|
+
const contract = new Contract(
|
768
|
+
PROOF_CONTRACT_ADDRESS,
|
769
|
+
PROOF_OF_INTEGRITY_ABI,
|
770
|
+
signer
|
771
|
+
);
|
772
|
+
const [isValid, timestamp, updater] = await contract.verifyData(
|
773
|
+
ethers.toUtf8Bytes(nodeId),
|
774
|
+
contentHash
|
775
|
+
);
|
776
|
+
console.log("Verification result:", { isValid, timestamp, updater });
|
777
|
+
return { isValid, timestamp, updater };
|
778
|
+
};
|
779
|
+
|
780
|
+
// Funzione per scrivere on-chain
|
781
|
+
const writeOnChain = async (nodeId, contentHash) => {
|
782
|
+
console.log("Writing on chain:", { nodeId, contentHash });
|
783
|
+
const signer = await getSigner();
|
784
|
+
const contract = new Contract(
|
785
|
+
PROOF_CONTRACT_ADDRESS,
|
786
|
+
PROOF_OF_INTEGRITY_ABI,
|
787
|
+
signer
|
788
|
+
);
|
789
|
+
const tx = await contract.updateData(
|
790
|
+
toUtf8Bytes(nodeId),
|
791
|
+
contentHash
|
792
|
+
);
|
793
|
+
console.log("Transaction sent:", tx.hash);
|
794
|
+
const receipt = await tx.wait();
|
795
|
+
console.log("Transaction confirmed:", receipt);
|
796
|
+
return tx;
|
797
|
+
};
|
798
|
+
|
799
|
+
// Funzione per ottenere l'ultimo record
|
800
|
+
const getLatestRecord = async (nodeId) => {
|
801
|
+
const signer = await getSigner();
|
802
|
+
const contract = new Contract(
|
803
|
+
PROOF_CONTRACT_ADDRESS,
|
804
|
+
PROOF_OF_INTEGRITY_ABI,
|
805
|
+
signer
|
806
|
+
);
|
807
|
+
const [contentHash, timestamp, updater] = await contract.getLatestRecord(
|
808
|
+
toUtf8Bytes(nodeId)
|
809
|
+
);
|
810
|
+
console.log("Latest record from blockchain:", {
|
811
|
+
nodeId,
|
812
|
+
contentHash,
|
813
|
+
timestamp,
|
814
|
+
updater,
|
815
|
+
});
|
816
|
+
return { contentHash, timestamp, updater };
|
817
|
+
};
|
818
|
+
|
819
|
+
|
820
|
+
if (nodeId && !data) {
|
821
|
+
// Case 1: User passes only node
|
822
|
+
gun.get(nodeId).once(async (existingData) => {
|
823
|
+
if (!existingData) {
|
824
|
+
if (callback) callback({ err: "Node not found in GunDB" });
|
825
|
+
return;
|
826
|
+
}
|
827
|
+
|
828
|
+
console.log("existingData", existingData);
|
829
|
+
|
830
|
+
// Use stored contentHash instead of recalculating
|
831
|
+
const contentHash = existingData._contentHash;
|
832
|
+
console.log("contentHash", contentHash);
|
833
|
+
|
834
|
+
if (!contentHash) {
|
835
|
+
if (callback) callback({ err: "No content hash found for this node" });
|
836
|
+
return;
|
837
|
+
}
|
838
|
+
|
839
|
+
try {
|
840
|
+
const { isValid, timestamp, updater } = await verifyOnChain(
|
841
|
+
nodeId,
|
842
|
+
contentHash
|
843
|
+
);
|
844
|
+
const latestRecord = await getLatestRecord(nodeId);
|
845
|
+
|
846
|
+
if (isValid) {
|
847
|
+
if (callback)
|
848
|
+
callback({
|
849
|
+
ok: true,
|
850
|
+
message: "Data verified on blockchain",
|
851
|
+
timestamp,
|
852
|
+
updater,
|
853
|
+
latestRecord,
|
854
|
+
});
|
855
|
+
} else {
|
856
|
+
if (callback)
|
857
|
+
callback({
|
858
|
+
ok: false,
|
859
|
+
message: "Data not verified on blockchain",
|
860
|
+
latestRecord,
|
861
|
+
});
|
862
|
+
}
|
863
|
+
} catch (error) {
|
864
|
+
if (callback) callback({ err: error.message });
|
865
|
+
}
|
866
|
+
});
|
867
|
+
} else if (data && !nodeId) {
|
868
|
+
// Case 2: User passes only text (data)
|
869
|
+
const newNodeId = generateRandomId();
|
870
|
+
const dataString = JSON.stringify(data);
|
871
|
+
const contentHash = ethers.keccak256(ethers.toUtf8Bytes(dataString));
|
872
|
+
|
873
|
+
gun
|
874
|
+
.get(newNodeId)
|
875
|
+
.put({ ...data, _contentHash: contentHash }, async (ack) => {
|
876
|
+
console.log("ack", ack);
|
877
|
+
if (ack.err) {
|
878
|
+
if (callback) callback({ err: "Error saving data to GunDB" });
|
879
|
+
return;
|
880
|
+
}
|
881
|
+
|
882
|
+
try {
|
883
|
+
const tx = await writeOnChain(newNodeId, contentHash);
|
884
|
+
if (callback)
|
885
|
+
callback({
|
886
|
+
ok: true,
|
887
|
+
message: "Data written to GunDB and blockchain",
|
888
|
+
nodeId: newNodeId,
|
889
|
+
txHash: tx.hash,
|
890
|
+
});
|
891
|
+
} catch (error) {
|
892
|
+
if (callback) callback({ err: error.message });
|
893
|
+
}
|
894
|
+
});
|
895
|
+
} else {
|
896
|
+
if (callback)
|
897
|
+
callback({
|
898
|
+
err: "Invalid input. Provide either nodeId or data, not both.",
|
899
|
+
});
|
900
|
+
}
|
901
|
+
|
902
|
+
return gun;
|
903
|
+
} catch (error) {
|
904
|
+
callback({ err: error.message });
|
905
|
+
return this;
|
906
|
+
}
|
907
|
+
};
|
908
|
+
|
909
|
+
// =============================================
|
910
|
+
// STEALTH ADDRESS CORE FUNCTIONS
|
911
|
+
// =============================================
|
912
|
+
/**
|
913
|
+
* Converts a Gun private key to an Ethereum account.
|
914
|
+
* @param {string} gunPrivateKey - The Gun private key in base64url format.
|
915
|
+
* @returns {Object} An object containing the Ethereum account and public key.
|
916
|
+
*/
|
917
|
+
Gun.chain.gunToEthAccount = function (gunPrivateKey) {
|
918
|
+
return gunToEthAccount(gunPrivateKey);
|
919
|
+
};
|
920
|
+
|
921
|
+
/**
|
922
|
+
* Generate a stealth key and related key pairs
|
923
|
+
* @param {string} recipientAddress - The recipient's Ethereum address
|
924
|
+
* @param {string} signature - The sender's signature to access their keys
|
925
|
+
* @returns {Promise<Object>} Object containing stealth addresses and keys
|
926
|
+
*/
|
927
|
+
Gun.chain.generateStealthAddress = async function (recipientAddress, signature) {
|
928
|
+
try {
|
929
|
+
const gun = this;
|
930
|
+
|
931
|
+
// Get recipient's public keys
|
932
|
+
const recipientData = await gun
|
933
|
+
.get("gun-eth")
|
934
|
+
.get("users")
|
935
|
+
.get(recipientAddress)
|
936
|
+
.get("publicKeys")
|
937
|
+
.then();
|
938
|
+
|
939
|
+
if (!recipientData || !recipientData.viewingPublicKey || !recipientData.spendingPublicKey) {
|
940
|
+
throw new Error("Recipient's public keys not found");
|
941
|
+
}
|
942
|
+
|
943
|
+
// Get sender's keys
|
944
|
+
const senderAddress = await this.verifySignature(MESSAGE_TO_SIGN, signature);
|
945
|
+
const password = generatePassword(signature);
|
946
|
+
|
947
|
+
const senderData = await gun
|
948
|
+
.get("gun-eth")
|
949
|
+
.get("users")
|
950
|
+
.get(senderAddress)
|
951
|
+
.then();
|
952
|
+
|
953
|
+
if (!senderData || !senderData.s_pair) {
|
954
|
+
throw new Error("Sender's keys not found");
|
955
|
+
}
|
956
|
+
|
957
|
+
// Decrypt sender's spending pair
|
958
|
+
let spendingKeyPair;
|
959
|
+
try {
|
960
|
+
const decryptedData = await SEA.decrypt(senderData.s_pair, password);
|
961
|
+
spendingKeyPair = typeof decryptedData === 'string' ?
|
962
|
+
JSON.parse(decryptedData) :
|
963
|
+
decryptedData;
|
964
|
+
} catch (error) {
|
965
|
+
console.error("Error decrypting spending pair:", error);
|
966
|
+
throw new Error("Unable to decrypt spending pair");
|
967
|
+
}
|
968
|
+
|
969
|
+
// Generate shared secret using SEA ECDH with encryption public key
|
970
|
+
const sharedSecret = await SEA.secret(recipientData.viewingPublicKey, spendingKeyPair);
|
971
|
+
|
972
|
+
if (!sharedSecret) {
|
973
|
+
throw new Error("Unable to generate shared secret");
|
974
|
+
}
|
975
|
+
|
976
|
+
console.log("Generate shared secret:", sharedSecret);
|
977
|
+
|
978
|
+
const { stealthAddress } = deriveStealthAddress(
|
979
|
+
sharedSecret,
|
980
|
+
recipientData.spendingPublicKey
|
981
|
+
);
|
982
|
+
|
983
|
+
return {
|
984
|
+
stealthAddress,
|
985
|
+
senderPublicKey: spendingKeyPair.epub, // Use encryption public key
|
986
|
+
spendingPublicKey: recipientData.spendingPublicKey
|
987
|
+
};
|
988
|
+
|
989
|
+
} catch (error) {
|
990
|
+
console.error("Error generating stealth address:", error);
|
991
|
+
throw error;
|
992
|
+
}
|
993
|
+
};
|
994
|
+
|
995
|
+
/**
|
996
|
+
* Publish public keys needed to receive stealth payments
|
997
|
+
* @param {string} signature - The signature to authenticate the user
|
998
|
+
* @returns {Promise<void>}
|
999
|
+
*/
|
1000
|
+
Gun.chain.publishStealthKeys = async function (signature) {
|
1001
|
+
try {
|
1002
|
+
const gun = this;
|
1003
|
+
const address = await this.verifySignature(MESSAGE_TO_SIGN, signature);
|
1004
|
+
const password = generatePassword(signature);
|
1005
|
+
|
1006
|
+
// Get encrypted key pairs
|
1007
|
+
const encryptedData = await gun
|
1008
|
+
.get("gun-eth")
|
1009
|
+
.get("users")
|
1010
|
+
.get(address)
|
1011
|
+
.then();
|
1012
|
+
|
1013
|
+
if (!encryptedData || !encryptedData.v_pair || !encryptedData.s_pair) {
|
1014
|
+
throw new Error("Keys not found");
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
// Decrypt viewing and spending pairs
|
1018
|
+
const viewingKeyPair = JSON.parse(
|
1019
|
+
await SEA.decrypt(encryptedData.v_pair, password)
|
1020
|
+
);
|
1021
|
+
const spendingKeyPair = JSON.parse(
|
1022
|
+
await SEA.decrypt(encryptedData.s_pair, password)
|
1023
|
+
);
|
1024
|
+
|
1025
|
+
const viewingAccount = gunToEthAccount(viewingKeyPair.priv);
|
1026
|
+
const spendingAccount = gunToEthAccount(spendingKeyPair.priv);
|
1027
|
+
|
1028
|
+
// Publish only public keys
|
1029
|
+
gun.get("gun-eth").get("users").get(address).get("publicKeys").put({
|
1030
|
+
viewingPublicKey: viewingAccount.publicKey,
|
1031
|
+
spendingPublicKey: spendingAccount.publicKey,
|
1032
|
+
});
|
1033
|
+
|
1034
|
+
console.log("Stealth public keys published successfully");
|
1035
|
+
} catch (error) {
|
1036
|
+
console.error("Error publishing stealth keys:", error);
|
1037
|
+
throw error;
|
1038
|
+
}
|
1039
|
+
};
|
1040
|
+
|
1041
|
+
// =============================================
|
1042
|
+
// STEALTH PAYMENT FUNCTIONS
|
1043
|
+
// =============================================
|
1044
|
+
/**
|
1045
|
+
* Recover funds from a stealth address
|
1046
|
+
* @param {string} stealthAddress - The stealth address to recover funds from
|
1047
|
+
* @param {string} senderPublicKey - The sender's public key used to generate the address
|
1048
|
+
* @param {string} signature - The signature to decrypt private keys
|
1049
|
+
* @returns {Promise<Object>} Object containing wallet to access funds
|
1050
|
+
*/
|
1051
|
+
Gun.chain.recoverStealthFunds = async function (
|
1052
|
+
stealthAddress,
|
1053
|
+
senderPublicKey,
|
1054
|
+
signature,
|
1055
|
+
spendingPublicKey
|
1056
|
+
) {
|
1057
|
+
try {
|
1058
|
+
const gun = this;
|
1059
|
+
const password = generatePassword(signature);
|
1060
|
+
|
1061
|
+
// Get own key pairs
|
1062
|
+
const myAddress = await this.verifySignature(MESSAGE_TO_SIGN, signature);
|
1063
|
+
const encryptedData = await gun
|
1064
|
+
.get("gun-eth")
|
1065
|
+
.get("users")
|
1066
|
+
.get(myAddress)
|
1067
|
+
.then();
|
1068
|
+
|
1069
|
+
if (!encryptedData || !encryptedData.v_pair || !encryptedData.s_pair) {
|
1070
|
+
throw new Error("Keys not found");
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
// Decrypt viewing and spending pairs
|
1074
|
+
let viewingKeyPair;
|
1075
|
+
try {
|
1076
|
+
const decryptedViewingData = await SEA.decrypt(encryptedData.v_pair, password);
|
1077
|
+
viewingKeyPair = typeof decryptedViewingData === 'string' ?
|
1078
|
+
JSON.parse(decryptedViewingData) :
|
1079
|
+
decryptedViewingData;
|
1080
|
+
} catch (error) {
|
1081
|
+
console.error("Error decrypting keys:", error);
|
1082
|
+
throw new Error("Unable to decrypt keys");
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
// Generate shared secret using SEA ECDH
|
1086
|
+
const sharedSecret = await SEA.secret(senderPublicKey, viewingKeyPair);
|
1087
|
+
|
1088
|
+
if (!sharedSecret) {
|
1089
|
+
throw new Error("Unable to generate shared secret");
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
console.log("Recover shared secret:", sharedSecret);
|
1093
|
+
|
1094
|
+
const { wallet, stealthAddress: recoveredAddress } = deriveStealthAddress(
|
1095
|
+
sharedSecret,
|
1096
|
+
spendingPublicKey
|
1097
|
+
);
|
1098
|
+
|
1099
|
+
// Verify address matches
|
1100
|
+
if (recoveredAddress.toLowerCase() !== stealthAddress.toLowerCase()) {
|
1101
|
+
console.error("Mismatch:", {
|
1102
|
+
recovered: recoveredAddress,
|
1103
|
+
expected: stealthAddress,
|
1104
|
+
sharedSecret
|
1105
|
+
});
|
1106
|
+
throw new Error("Recovered stealth address does not match");
|
1107
|
+
}
|
1108
|
+
|
1109
|
+
return {
|
1110
|
+
wallet,
|
1111
|
+
address: recoveredAddress,
|
1112
|
+
};
|
1113
|
+
} catch (error) {
|
1114
|
+
console.error("Error recovering stealth funds:", error);
|
1115
|
+
throw error;
|
1116
|
+
}
|
1117
|
+
};
|
1118
|
+
|
1119
|
+
/**
|
1120
|
+
* Announce a stealth payment
|
1121
|
+
* @param {string} stealthAddress - The generated stealth address
|
1122
|
+
* @param {string} senderPublicKey - The sender's public key
|
1123
|
+
* @param {string} spendingPublicKey - The spending public key
|
1124
|
+
* @param {string} signature - The sender's signature
|
1125
|
+
* @returns {Promise<void>}
|
1126
|
+
*/
|
1127
|
+
Gun.chain.announceStealthPayment = async function (
|
1128
|
+
stealthAddress,
|
1129
|
+
senderPublicKey,
|
1130
|
+
spendingPublicKey,
|
1131
|
+
signature,
|
1132
|
+
options = { onChain: false, chain: 'optimismSepolia' }
|
1133
|
+
) {
|
1134
|
+
try {
|
1135
|
+
const gun = this;
|
1136
|
+
const senderAddress = await this.verifySignature(MESSAGE_TO_SIGN, signature);
|
1137
|
+
|
1138
|
+
if (options.onChain) {
|
1139
|
+
// On-chain announcement
|
1140
|
+
const signer = await getSigner();
|
1141
|
+
const chainConfig = getAddressesForChain(options.chain);
|
1142
|
+
const contractAddress = chainConfig.STEALTH_ANNOUNCER_ADDRESS;
|
1143
|
+
|
1144
|
+
console.log("Using contract address:", contractAddress);
|
1145
|
+
|
1146
|
+
const contract = new Contract(
|
1147
|
+
contractAddress,
|
1148
|
+
STEALTH_ANNOUNCER_ABI,
|
1149
|
+
signer
|
1150
|
+
);
|
1151
|
+
|
1152
|
+
// Get dev fee from contract
|
1153
|
+
const devFee = await contract.devFee();
|
1154
|
+
console.log("Dev fee:", devFee.toString());
|
1155
|
+
|
1156
|
+
// Call contract
|
1157
|
+
const tx = await contract.announcePayment(
|
1158
|
+
senderPublicKey,
|
1159
|
+
spendingPublicKey,
|
1160
|
+
stealthAddress,
|
1161
|
+
{ value: devFee }
|
1162
|
+
);
|
1163
|
+
|
1164
|
+
console.log("Transaction sent:", tx.hash);
|
1165
|
+
const receipt = await tx.wait();
|
1166
|
+
console.log("Transaction confirmed:", receipt.hash);
|
1167
|
+
|
1168
|
+
console.log("Stealth payment announced on-chain (dev fee paid)");
|
1169
|
+
} else {
|
1170
|
+
// Off-chain announcement (GunDB)
|
1171
|
+
gun
|
1172
|
+
.get("gun-eth")
|
1173
|
+
.get("stealth-payments")
|
1174
|
+
.set({
|
1175
|
+
stealthAddress,
|
1176
|
+
senderAddress,
|
1177
|
+
senderPublicKey,
|
1178
|
+
spendingPublicKey,
|
1179
|
+
timestamp: Date.now(),
|
1180
|
+
});
|
1181
|
+
console.log("Stealth payment announced off-chain");
|
1182
|
+
}
|
1183
|
+
} catch (error) {
|
1184
|
+
console.error("Error announcing stealth payment:", error);
|
1185
|
+
console.error("Error details:", error.stack);
|
1186
|
+
throw error;
|
1187
|
+
}
|
1188
|
+
};
|
1189
|
+
|
1190
|
+
/**
|
1191
|
+
* Get all stealth payments for an address
|
1192
|
+
* @param {string} signature - The signature to authenticate the user
|
1193
|
+
* @returns {Promise<Array>} List of stealth payments
|
1194
|
+
*/
|
1195
|
+
Gun.chain.getStealthPayments = async function (signature, options = { source: 'both' }) {
|
1196
|
+
try {
|
1197
|
+
const payments = [];
|
1198
|
+
|
1199
|
+
if (options.source === 'onChain' || options.source === 'both') {
|
1200
|
+
const signer = await getSigner();
|
1201
|
+
const chainConfig = getAddressesForChain(options.chain || 'optimismSepolia');
|
1202
|
+
const contractAddress = chainConfig.STEALTH_ANNOUNCER_ADDRESS;
|
1203
|
+
|
1204
|
+
const contract = new Contract(
|
1205
|
+
contractAddress,
|
1206
|
+
STEALTH_ANNOUNCER_ABI,
|
1207
|
+
signer
|
1208
|
+
);
|
1209
|
+
|
1210
|
+
try {
|
1211
|
+
// Get total number of announcements
|
1212
|
+
const totalAnnouncements = await contract.getAnnouncementsCount();
|
1213
|
+
const totalCount = Number(totalAnnouncements.toString());
|
1214
|
+
console.log("Total on-chain announcements:", totalCount);
|
1215
|
+
|
1216
|
+
if (totalCount > 0) {
|
1217
|
+
// Get announcements in batches of 100
|
1218
|
+
const batchSize = 100;
|
1219
|
+
const lastIndex = totalCount - 1;
|
1220
|
+
|
1221
|
+
for(let i = 0; i <= lastIndex; i += batchSize) {
|
1222
|
+
const toIndex = Math.min(i + batchSize - 1, lastIndex);
|
1223
|
+
const batch = await contract.getAnnouncementsInRange(i, toIndex);
|
1224
|
+
|
1225
|
+
// For each announcement, try to decrypt
|
1226
|
+
for(const announcement of batch) {
|
1227
|
+
try {
|
1228
|
+
// Verify announcement is valid
|
1229
|
+
if (!announcement || !announcement.stealthAddress ||
|
1230
|
+
!announcement.senderPublicKey || !announcement.spendingPublicKey) {
|
1231
|
+
console.log("Invalid announcement:", announcement);
|
1232
|
+
continue;
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
// Try to recover funds to verify if announcement is for us
|
1236
|
+
const recoveredWallet = await this.recoverStealthFunds(
|
1237
|
+
announcement.stealthAddress,
|
1238
|
+
announcement.senderPublicKey,
|
1239
|
+
signature,
|
1240
|
+
announcement.spendingPublicKey
|
1241
|
+
);
|
1242
|
+
|
1243
|
+
// If no errors thrown, announcement is for us
|
1244
|
+
payments.push({
|
1245
|
+
stealthAddress: announcement.stealthAddress,
|
1246
|
+
senderPublicKey: announcement.senderPublicKey,
|
1247
|
+
spendingPublicKey: announcement.spendingPublicKey,
|
1248
|
+
timestamp: Number(announcement.timestamp),
|
1249
|
+
source: 'onChain',
|
1250
|
+
wallet: recoveredWallet
|
1251
|
+
});
|
1252
|
+
|
1253
|
+
} catch (e) {
|
1254
|
+
// Not for us, continue
|
1255
|
+
console.log(`Announcement not for us: ${announcement.stealthAddress}`);
|
1256
|
+
continue;
|
1257
|
+
}
|
1258
|
+
}
|
1259
|
+
}
|
1260
|
+
}
|
1261
|
+
} catch (error) {
|
1262
|
+
console.error("Error retrieving on-chain announcements:", error);
|
1263
|
+
}
|
1264
|
+
}
|
1265
|
+
|
1266
|
+
if (options.source === 'offChain' || options.source === 'both') {
|
1267
|
+
// Get off-chain payments
|
1268
|
+
const gun = this;
|
1269
|
+
const offChainPayments = await new Promise((resolve) => {
|
1270
|
+
const p = [];
|
1271
|
+
gun
|
1272
|
+
.get("gun-eth")
|
1273
|
+
.get("stealth-payments")
|
1274
|
+
.get(recipientAddress)
|
1275
|
+
.map()
|
1276
|
+
.once((payment, id) => {
|
1277
|
+
if (payment?.stealthAddress) {
|
1278
|
+
p.push({ ...payment, id, source: 'offChain' });
|
1279
|
+
}
|
1280
|
+
});
|
1281
|
+
setTimeout(() => resolve(p), 2000);
|
1282
|
+
});
|
1283
|
+
|
1284
|
+
payments.push(...offChainPayments);
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
console.log(`Found ${payments.length} stealth payments`);
|
1288
|
+
return payments;
|
1289
|
+
} catch (error) {
|
1290
|
+
console.error("Error retrieving stealth payments:", error);
|
1291
|
+
throw error;
|
1292
|
+
}
|
1293
|
+
};
|
1294
|
+
|
1295
|
+
/**
|
1296
|
+
* Clean up old stealth payments
|
1297
|
+
* @param {string} recipientAddress - The recipient's address
|
1298
|
+
* @returns {Promise<void>}
|
1299
|
+
*/
|
1300
|
+
Gun.chain.cleanStealthPayments = async function(recipientAddress) {
|
1301
|
+
try {
|
1302
|
+
const gun = this;
|
1303
|
+
const payments = await gun
|
1304
|
+
.get("gun-eth")
|
1305
|
+
.get("stealth-payments")
|
1306
|
+
.get(recipientAddress)
|
1307
|
+
.map()
|
1308
|
+
.once()
|
1309
|
+
.then();
|
1310
|
+
|
1311
|
+
// Remove empty or invalid nodes
|
1312
|
+
if (payments) {
|
1313
|
+
Object.keys(payments).forEach(async (key) => {
|
1314
|
+
const payment = payments[key];
|
1315
|
+
if (!payment || !payment.stealthAddress || !payment.senderPublicKey || !payment.spendingPublicKey) {
|
1316
|
+
await gun
|
1317
|
+
.get("gun-eth")
|
1318
|
+
.get("stealth-payments")
|
1319
|
+
.get(recipientAddress)
|
1320
|
+
.get(key)
|
1321
|
+
.put(null);
|
1322
|
+
}
|
1323
|
+
});
|
1324
|
+
}
|
1325
|
+
} catch (error) {
|
1326
|
+
console.error("Error cleaning stealth payments:", error);
|
1327
|
+
}
|
1328
|
+
};
|
1329
|
+
|
1330
|
+
// =============================================
|
1331
|
+
// EXPORTS
|
1332
|
+
// =============================================
|
1333
|
+
|
1334
|
+
// Crea una classe GunEth che contiene tutti i metodi e le utility
|
1335
|
+
class GunEth {
|
1336
|
+
// Static utility methods
|
1337
|
+
static generateRandomId = generateRandomId;
|
1338
|
+
static generatePassword = generatePassword;
|
1339
|
+
static gunToEthAccount = gunToEthAccount;
|
1340
|
+
static getSigner = getSigner;
|
1341
|
+
static deriveStealthAddress = deriveStealthAddress;
|
1342
|
+
|
1343
|
+
// Chain methods
|
1344
|
+
static chainMethods = {
|
1345
|
+
setSigner: Gun.chain.setSigner,
|
1346
|
+
getSigner: Gun.chain.getSigner,
|
1347
|
+
verifySignature: Gun.chain.verifySignature,
|
1348
|
+
generatePassword: Gun.chain.generatePassword,
|
1349
|
+
createSignature: Gun.chain.createSignature,
|
1350
|
+
createAndStoreEncryptedPair: Gun.chain.createAndStoreEncryptedPair,
|
1351
|
+
getAndDecryptPair: Gun.chain.getAndDecryptPair,
|
1352
|
+
proof: Gun.chain.proof,
|
1353
|
+
gunToEthAccount: Gun.chain.gunToEthAccount,
|
1354
|
+
generateStealthAddress: Gun.chain.generateStealthAddress,
|
1355
|
+
publishStealthKeys: Gun.chain.publishStealthKeys,
|
1356
|
+
recoverStealthFunds: Gun.chain.recoverStealthFunds,
|
1357
|
+
announceStealthPayment: Gun.chain.announceStealthPayment,
|
1358
|
+
getStealthPayments: Gun.chain.getStealthPayments,
|
1359
|
+
cleanStealthPayments: Gun.chain.cleanStealthPayments
|
1360
|
+
};
|
1361
|
+
|
1362
|
+
// Constants
|
1363
|
+
static MESSAGE_TO_SIGN = MESSAGE_TO_SIGN;
|
1364
|
+
static PROOF_CONTRACT_ADDRESS = PROOF_CONTRACT_ADDRESS;
|
1365
|
+
static LOCAL_CONFIG = LOCAL_CONFIG;
|
1366
|
+
}
|
1367
|
+
|
1368
|
+
export { GunEth, MESSAGE_TO_SIGN, deriveStealthAddress, generatePassword, generateRandomId, getSigner, gunToEthAccount };
|
10
1369
|
//# sourceMappingURL=gun-eth.esm.js.map
|