@oceanprotocol/lib 0.20.1 → 0.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/node/lib.js +1 -1
- package/dist/node/lib.js.map +1 -1
- package/dist/node/lib.module.js +1 -1
- package/dist/node/lib.module.js.map +1 -1
- package/dist/node/lib.umd.js +1 -1
- package/dist/node/lib.umd.js.map +1 -1
- package/dist/node/ocean/Assets.d.ts +1 -1
- package/dist/node/ocean/Compute.d.ts +1 -1
- package/dist/node/ocean/interfaces/Compute.d.ts +3 -0
- package/docs/beginners_guide.md +2 -2
- package/docs/quickstart_simple.md +2 -2
- package/package.json +10 -10
package/dist/node/lib.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t=require("uuid"),e=require("decimal.js"),i=require("web3"),r=require("fs"),n=require("save-file"),s=require("node-abort-controller"),o=require("buffer"),a=require("crypto"),h=require("cross-fetch"),u=require("@oceanprotocol/contracts/artifacts/Metadata.json"),l=require("lzma/src/lzma-c"),c=require("@oceanprotocol/contracts/artifacts/DTFactory.json"),d=require("@oceanprotocol/contracts/artifacts/DataTokenTemplate.json"),f=require("@ethereum-navigator/navigator"),m=require("crypto-js"),g=require("@oceanprotocol/contracts/artifacts/BPool.json"),p=require("@oceanprotocol/contracts/artifacts/BFactory.json"),w=require("@oceanprotocol/contracts/artifacts/FixedRateExchange.json"),v=require("@oceanprotocol/contracts/artifacts/Dispenser.json"),y=require("os"),M=require("@oceanprotocol/contracts/artifacts/address.json");function b(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var A,x=/*#__PURE__*/b(e),E=/*#__PURE__*/b(i),R=/*#__PURE__*/b(r),S=/*#__PURE__*/b(n),k=/*#__PURE__*/b(s),I=/*#__PURE__*/b(o),T=/*#__PURE__*/b(a),O=/*#__PURE__*/b(u),B=/*#__PURE__*/b(c),C=/*#__PURE__*/b(d),_=/*#__PURE__*/b(g),P=/*#__PURE__*/b(p),D=/*#__PURE__*/b(w),L=/*#__PURE__*/b(v),N=/*#__PURE__*/b(M);function W(){return(W=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t}).apply(this,arguments)}exports.LogLevel=void 0,(A=exports.LogLevel||(exports.LogLevel={}))[A.None=-1]="None",A[A.Error=0]="Error",A[A.Warn=1]="Warn",A[A.Log=2]="Log",A[A.Verbose=3]="Verbose";class F{constructor(t=exports.LogLevel.Error){this.logLevel=void 0,this.logLevel=t}setLevel(t){this.logLevel=t}bypass(...t){this.dispatch("log",-Infinity,...t)}debug(...t){this.dispatch("debug",exports.LogLevel.Verbose,...t)}log(...t){this.dispatch("log",exports.LogLevel.Log,...t)}warn(...t){this.dispatch("warn",exports.LogLevel.Warn,...t)}error(...t){this.dispatch("error",exports.LogLevel.Error,...t)}dispatch(t,e,...i){this.logLevel>=e&&console[t](...i)}}const U=new F,q=t=>j(t,!0),$=t=>j(t,!1);function j(t="",e){const{valid:i,output:r}=V(t,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(e&&i?"0x":"")+r}const G=t=>z(t,!0);function z(t="",e){const{valid:i,output:r}=V(t,/^(?:0x|did:op:)*([a-f0-9]{40})$/i,"didTransformer");return(e&&i?"did:op:":"")+r}const H=t=>q(z(t,!1)),Z=t=>$(z(t,!1));function V(t,e,i){if("string"!=typeof t)throw U.debug("Not input string:"),U.debug(t),new Error(`[${i}] Expected string, input type: ${typeof t}`);const r=t.match(e);return r?{valid:!0,output:r[1]}:(U.warn(`[${i}] Input transformation failed.`),{valid:!1,output:t})}class J{constructor(){this.completed=!1,this.subscriptions=new Set}subscribe(t,e,i){if(this.completed)throw new Error("Observer completed.");const r={onNext:t,onComplete:e,onError:i};return this.subscriptions.add(r),{unsubscribe:()=>this.subscriptions.delete(r)}}next(t){this.emit("onNext",t)}complete(t){this.emit("onComplete",t),this.unsubscribe()}error(t){this.emit("onError",t),this.unsubscribe()}emit(t,e){Array.from(this.subscriptions).map(e=>e[t]).filter(t=>t&&"function"==typeof t).forEach(t=>t(e))}unsubscribe(){this.completed=!0,this.subscriptions.clear()}}class K{constructor(t){this.observer=new J,this.promise=Object.assign(new Promise((t,e)=>{setTimeout(()=>{this.observer.subscribe(void 0,t,e)},0)}),this),setTimeout(()=>this.init(t),1)}subscribe(t){return this.observer.subscribe(t)}next(t){return this.observer.subscribe(t),this}then(t,e){return Object.assign(this.promise.then(t,e),this)}catch(t){return Object.assign(this.promise.catch(t),this)}finally(t){return Object.assign(this.promise.finally(t),this)}init(t){const e=t(this.observer);Promise.resolve(e).then(t=>{"function"==typeof e.then&&this.observer.complete(t)}).catch(t=>{"function"==typeof e.then&&this.observer.error(t)})}}var X=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Q=Math.ceil,Y=Math.floor,tt="[BigNumber Error] ",et=tt+"Number primitive has more than 15 significant digits: ",it=1e14,rt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],nt=1e9;function st(t){var e=0|t;return t>0||t===e?e:e-1}function ot(t){for(var e,i,r=1,n=t.length,s=t[0]+"";r<n;){for(i=14-(e=t[r++]+"").length;i--;e="0"+e);s+=e}for(n=s.length;48===s.charCodeAt(--n););return s.slice(0,n+1||1)}function at(t,e){var i,r,n=t.c,s=e.c,o=t.s,a=e.s,h=t.e,u=e.e;if(!o||!a)return null;if(r=s&&!s[0],(i=n&&!n[0])||r)return i?r?0:-a:o;if(o!=a)return o;if(i=o<0,r=h==u,!n||!s)return r?0:!n^i?1:-1;if(!r)return h>u^i?1:-1;for(a=(h=n.length)<(u=s.length)?h:u,o=0;o<a;o++)if(n[o]!=s[o])return n[o]>s[o]^i?1:-1;return h==u?0:h>u^i?1:-1}function ht(t,e,i,r){if(t<e||t>i||t!==Y(t))throw Error(tt+(r||"Argument")+("number"==typeof t?t<e||t>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function ut(t){var e=t.c.length-1;return st(t.e/14)==e&&t.c[e]%2!=0}function lt(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function ct(t,e,i){var r,n;if(e<0){for(n=i+".";++e;n+=i);t=n+t}else if(++e>(r=t.length)){for(n=i,e-=r;--e;n+=i);t+=n}else e<r&&(t=t.slice(0,e)+"."+t.slice(e));return t}var dt=function t(e){var i,r,n,s,o,a,h,u,l,c,d=R.prototype={constructor:R,toString:null,valueOf:null},f=new R(1),m=20,g=4,p=-7,w=21,v=-1e7,y=1e7,M=!1,b=1,A=0,x={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},E="0123456789abcdefghijklmnopqrstuvwxyz";function R(t,e){var i,s,o,a,h,u,l,c,d=this;if(!(d instanceof R))return new R(t,e);if(null==e){if(t&&!0===t._isBigNumber)return d.s=t.s,void(!t.c||t.e>y?d.c=d.e=null:t.e<v?d.c=[d.e=0]:(d.e=t.e,d.c=t.c.slice()));if((u="number"==typeof t)&&0*t==0){if(d.s=1/t<0?(t=-t,-1):1,t===~~t){for(a=0,h=t;h>=10;h/=10,a++);return void(a>y?d.c=d.e=null:(d.e=a,d.c=[t]))}c=String(t)}else{if(!X.test(c=String(t)))return n(d,c,u);d.s=45==c.charCodeAt(0)?(c=c.slice(1),-1):1}(a=c.indexOf("."))>-1&&(c=c.replace(".","")),(h=c.search(/e/i))>0?(a<0&&(a=h),a+=+c.slice(h+1),c=c.substring(0,h)):a<0&&(a=c.length)}else{if(ht(e,2,E.length,"Base"),10==e)return T(d=new R(t),m+d.e+1,g);if(c=String(t),u="number"==typeof t){if(0*t!=0)return n(d,c,u,e);if(d.s=1/t<0?(c=c.slice(1),-1):1,R.DEBUG&&c.replace(/^0\.0*|\./,"").length>15)throw Error(et+t)}else d.s=45===c.charCodeAt(0)?(c=c.slice(1),-1):1;for(i=E.slice(0,e),a=h=0,l=c.length;h<l;h++)if(i.indexOf(s=c.charAt(h))<0){if("."==s){if(h>a){a=l;continue}}else if(!o&&(c==c.toUpperCase()&&(c=c.toLowerCase())||c==c.toLowerCase()&&(c=c.toUpperCase()))){o=!0,h=-1,a=0;continue}return n(d,String(t),u,e)}u=!1,(a=(c=r(c,e,10,d.s)).indexOf("."))>-1?c=c.replace(".",""):a=c.length}for(h=0;48===c.charCodeAt(h);h++);for(l=c.length;48===c.charCodeAt(--l););if(c=c.slice(h,++l)){if(l-=h,u&&R.DEBUG&&l>15&&(t>9007199254740991||t!==Y(t)))throw Error(et+d.s*t);if((a=a-h-1)>y)d.c=d.e=null;else if(a<v)d.c=[d.e=0];else{if(d.e=a,d.c=[],h=(a+1)%14,a<0&&(h+=14),h<l){for(h&&d.c.push(+c.slice(0,h)),l-=14;h<l;)d.c.push(+c.slice(h,h+=14));h=14-(c=c.slice(h)).length}else h-=l;for(;h--;c+="0");d.c.push(+c)}}else d.c=[d.e=0]}function S(t,e,i,r){var n,s,o,a,h;if(null==i?i=g:ht(i,0,8),!t.c)return t.toString();if(n=t.c[0],o=t.e,null==e)h=ot(t.c),h=1==r||2==r&&(o<=p||o>=w)?lt(h,o):ct(h,o,"0");else if(s=(t=T(new R(t),e,i)).e,a=(h=ot(t.c)).length,1==r||2==r&&(e<=s||s<=p)){for(;a<e;h+="0",a++);h=lt(h,s)}else if(e-=o,h=ct(h,s,"0"),s+1>a){if(--e>0)for(h+=".";e--;h+="0");}else if((e+=s-a)>0)for(s+1==a&&(h+=".");e--;h+="0");return t.s<0&&n?"-"+h:h}function k(t,e){for(var i,r=1,n=new R(t[0]);r<t.length;r++){if(!(i=new R(t[r])).s){n=i;break}e.call(n,i)&&(n=i)}return n}function I(t,e,i){for(var r=1,n=e.length;!e[--n];e.pop());for(n=e[0];n>=10;n/=10,r++);return(i=r+14*i-1)>y?t.c=t.e=null:i<v?t.c=[t.e=0]:(t.e=i,t.c=e),t}function T(t,e,i,r){var n,s,o,a,h,u,l,c=t.c,d=rt;if(c){t:{for(n=1,a=c[0];a>=10;a/=10,n++);if((s=e-n)<0)s+=14,l=(h=c[u=0])/d[n-(o=e)-1]%10|0;else if((u=Q((s+1)/14))>=c.length){if(!r)break t;for(;c.length<=u;c.push(0));h=l=0,n=1,o=(s%=14)-14+1}else{for(h=a=c[u],n=1;a>=10;a/=10,n++);l=(o=(s%=14)-14+n)<0?0:h/d[n-o-1]%10|0}if(r=r||e<0||null!=c[u+1]||(o<0?h:h%d[n-o-1]),r=i<4?(l||r)&&(0==i||i==(t.s<0?3:2)):l>5||5==l&&(4==i||r||6==i&&(s>0?o>0?h/d[n-o]:0:c[u-1])%10&1||i==(t.s<0?8:7)),e<1||!c[0])return c.length=0,r?(c[0]=d[(14-(e-=t.e+1)%14)%14],t.e=-e||0):c[0]=t.e=0,t;if(0==s?(c.length=u,a=1,u--):(c.length=u+1,a=d[14-s],c[u]=o>0?Y(h/d[n-o]%d[o])*a:0),r)for(;;){if(0==u){for(s=1,o=c[0];o>=10;o/=10,s++);for(o=c[0]+=a,a=1;o>=10;o/=10,a++);s!=a&&(t.e++,c[0]==it&&(c[0]=1));break}if(c[u]+=a,c[u]!=it)break;c[u--]=0,a=1}for(s=c.length;0===c[--s];c.pop());}t.e>y?t.c=t.e=null:t.e<v&&(t.c=[t.e=0])}return t}function O(t){var e,i=t.e;return null===i?t.toString():(e=ot(t.c),e=i<=p||i>=w?lt(e,i):ct(e,i,"0"),t.s<0?"-"+e:e)}return R.clone=t,R.ROUND_UP=0,R.ROUND_DOWN=1,R.ROUND_CEIL=2,R.ROUND_FLOOR=3,R.ROUND_HALF_UP=4,R.ROUND_HALF_DOWN=5,R.ROUND_HALF_EVEN=6,R.ROUND_HALF_CEIL=7,R.ROUND_HALF_FLOOR=8,R.EUCLID=9,R.config=R.set=function(t){var e,i;if(null!=t){if("object"!=typeof t)throw Error(tt+"Object expected: "+t);if(t.hasOwnProperty(e="DECIMAL_PLACES")&&(ht(i=t[e],0,nt,e),m=i),t.hasOwnProperty(e="ROUNDING_MODE")&&(ht(i=t[e],0,8,e),g=i),t.hasOwnProperty(e="EXPONENTIAL_AT")&&((i=t[e])&&i.pop?(ht(i[0],-nt,0,e),ht(i[1],0,nt,e),p=i[0],w=i[1]):(ht(i,-nt,nt,e),p=-(w=i<0?-i:i))),t.hasOwnProperty(e="RANGE"))if((i=t[e])&&i.pop)ht(i[0],-nt,-1,e),ht(i[1],1,nt,e),v=i[0],y=i[1];else{if(ht(i,-nt,nt,e),!i)throw Error(tt+e+" cannot be zero: "+i);v=-(y=i<0?-i:i)}if(t.hasOwnProperty(e="CRYPTO")){if((i=t[e])!==!!i)throw Error(tt+e+" not true or false: "+i);if(i){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw M=!i,Error(tt+"crypto unavailable");M=i}else M=i}if(t.hasOwnProperty(e="MODULO_MODE")&&(ht(i=t[e],0,9,e),b=i),t.hasOwnProperty(e="POW_PRECISION")&&(ht(i=t[e],0,nt,e),A=i),t.hasOwnProperty(e="FORMAT")){if("object"!=typeof(i=t[e]))throw Error(tt+e+" not an object: "+i);x=i}if(t.hasOwnProperty(e="ALPHABET")){if("string"!=typeof(i=t[e])||/^.$|[+-.\s]|(.).*\1/.test(i))throw Error(tt+e+" invalid: "+i);E=i}}return{DECIMAL_PLACES:m,ROUNDING_MODE:g,EXPONENTIAL_AT:[p,w],RANGE:[v,y],CRYPTO:M,MODULO_MODE:b,POW_PRECISION:A,FORMAT:x,ALPHABET:E}},R.isBigNumber=function(t){if(!t||!0!==t._isBigNumber)return!1;if(!R.DEBUG)return!0;var e,i,r=t.c,n=t.e,s=t.s;t:if("[object Array]"=={}.toString.call(r)){if((1===s||-1===s)&&n>=-nt&&n<=nt&&n===Y(n)){if(0===r[0]){if(0===n&&1===r.length)return!0;break t}if((e=(n+1)%14)<1&&(e+=14),String(r[0]).length==e){for(e=0;e<r.length;e++)if((i=r[e])<0||i>=it||i!==Y(i))break t;if(0!==i)return!0}}}else if(null===r&&null===n&&(null===s||1===s||-1===s))return!0;throw Error(tt+"Invalid BigNumber: "+t)},R.maximum=R.max=function(){return k(arguments,d.lt)},R.minimum=R.min=function(){return k(arguments,d.gt)},R.random=(s=9007199254740992,o=Math.random()*s&2097151?function(){return Y(Math.random()*s)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(t){var e,i,r,n,s,a=0,h=[],u=new R(f);if(null==t?t=m:ht(t,0,nt),n=Q(t/14),M)if(crypto.getRandomValues){for(e=crypto.getRandomValues(new Uint32Array(n*=2));a<n;)(s=131072*e[a]+(e[a+1]>>>11))>=9e15?(i=crypto.getRandomValues(new Uint32Array(2)),e[a]=i[0],e[a+1]=i[1]):(h.push(s%1e14),a+=2);a=n/2}else{if(!crypto.randomBytes)throw M=!1,Error(tt+"crypto unavailable");for(e=crypto.randomBytes(n*=7);a<n;)(s=281474976710656*(31&e[a])+1099511627776*e[a+1]+4294967296*e[a+2]+16777216*e[a+3]+(e[a+4]<<16)+(e[a+5]<<8)+e[a+6])>=9e15?crypto.randomBytes(7).copy(e,a):(h.push(s%1e14),a+=7);a=n/7}if(!M)for(;a<n;)(s=o())<9e15&&(h[a++]=s%1e14);for(t%=14,(n=h[--a])&&t&&(h[a]=Y(n/(s=rt[14-t]))*s);0===h[a];h.pop(),a--);if(a<0)h=[r=0];else{for(r=-1;0===h[0];h.splice(0,1),r-=14);for(a=1,s=h[0];s>=10;s/=10,a++);a<14&&(r-=14-a)}return u.e=r,u.c=h,u}),R.sum=function(){for(var t=1,e=arguments,i=new R(e[0]);t<e.length;)i=i.plus(e[t++]);return i},r=function(){var t="0123456789";function e(t,e,i,r){for(var n,s,o=[0],a=0,h=t.length;a<h;){for(s=o.length;s--;o[s]*=e);for(o[0]+=r.indexOf(t.charAt(a++)),n=0;n<o.length;n++)o[n]>i-1&&(null==o[n+1]&&(o[n+1]=0),o[n+1]+=o[n]/i|0,o[n]%=i)}return o.reverse()}return function(r,n,s,o,a){var h,u,l,c,d,f,p,w,v=r.indexOf("."),y=m,M=g;for(v>=0&&(c=A,A=0,r=r.replace(".",""),f=(w=new R(n)).pow(r.length-v),A=c,w.c=e(ct(ot(f.c),f.e,"0"),10,s,t),w.e=w.c.length),l=c=(p=e(r,n,s,a?(h=E,t):(h=t,E))).length;0==p[--c];p.pop());if(!p[0])return h.charAt(0);if(v<0?--l:(f.c=p,f.e=l,f.s=o,p=(f=i(f,w,y,M,s)).c,d=f.r,l=f.e),v=p[u=l+y+1],c=s/2,d=d||u<0||null!=p[u+1],d=M<4?(null!=v||d)&&(0==M||M==(f.s<0?3:2)):v>c||v==c&&(4==M||d||6==M&&1&p[u-1]||M==(f.s<0?8:7)),u<1||!p[0])r=d?ct(h.charAt(1),-y,h.charAt(0)):h.charAt(0);else{if(p.length=u,d)for(--s;++p[--u]>s;)p[u]=0,u||(++l,p=[1].concat(p));for(c=p.length;!p[--c];);for(v=0,r="";v<=c;r+=h.charAt(p[v++]));r=ct(r,l,h.charAt(0))}return r}}(),i=function(){function t(t,e,i){var r,n,s,o,a=0,h=t.length,u=e%1e7,l=e/1e7|0;for(t=t.slice();h--;)a=((n=u*(s=t[h]%1e7)+(r=l*s+(o=t[h]/1e7|0)*u)%1e7*1e7+a)/i|0)+(r/1e7|0)+l*o,t[h]=n%i;return a&&(t=[a].concat(t)),t}function e(t,e,i,r){var n,s;if(i!=r)s=i>r?1:-1;else for(n=s=0;n<i;n++)if(t[n]!=e[n]){s=t[n]>e[n]?1:-1;break}return s}function i(t,e,i,r){for(var n=0;i--;)t[i]-=n,t[i]=(n=t[i]<e[i]?1:0)*r+t[i]-e[i];for(;!t[0]&&t.length>1;t.splice(0,1));}return function(r,n,s,o,a){var h,u,l,c,d,f,m,g,p,w,v,y,M,b,A,x,E,S=r.s==n.s?1:-1,k=r.c,I=n.c;if(!(k&&k[0]&&I&&I[0]))return new R(r.s&&n.s&&(k?!I||k[0]!=I[0]:I)?k&&0==k[0]||!I?0*S:S/0:NaN);for(p=(g=new R(S)).c=[],S=s+(u=r.e-n.e)+1,a||(a=it,u=st(r.e/14)-st(n.e/14),S=S/14|0),l=0;I[l]==(k[l]||0);l++);if(I[l]>(k[l]||0)&&u--,S<0)p.push(1),c=!0;else{for(b=k.length,x=I.length,l=0,S+=2,(d=Y(a/(I[0]+1)))>1&&(I=t(I,d,a),k=t(k,d,a),x=I.length,b=k.length),M=x,v=(w=k.slice(0,x)).length;v<x;w[v++]=0);E=I.slice(),E=[0].concat(E),A=I[0],I[1]>=a/2&&A++;do{if(d=0,(h=e(I,w,x,v))<0){if(y=w[0],x!=v&&(y=y*a+(w[1]||0)),(d=Y(y/A))>1)for(d>=a&&(d=a-1),m=(f=t(I,d,a)).length,v=w.length;1==e(f,w,m,v);)d--,i(f,x<m?E:I,m,a),m=f.length,h=1;else 0==d&&(h=d=1),m=(f=I.slice()).length;if(m<v&&(f=[0].concat(f)),i(w,f,v,a),v=w.length,-1==h)for(;e(I,w,x,v)<1;)d++,i(w,x<v?E:I,v,a),v=w.length}else 0===h&&(d++,w=[0]);p[l++]=d,w[0]?w[v++]=k[M]||0:(w=[k[M]],v=1)}while((M++<b||null!=w[0])&&S--);c=null!=w[0],p[0]||p.splice(0,1)}if(a==it){for(l=1,S=p[0];S>=10;S/=10,l++);T(g,s+(g.e=l+14*u-1)+1,o,c)}else g.e=u,g.r=+c;return g}}(),a=/^(-?)0([xbo])(?=\w[\w.]*$)/i,h=/^([^.]+)\.$/,u=/^\.([^.]+)$/,l=/^-?(Infinity|NaN)$/,c=/^\s*\+(?=[\w.])|^\s+|\s+$/g,n=function(t,e,i,r){var n,s=i?e:e.replace(c,"");if(l.test(s))t.s=isNaN(s)?null:s<0?-1:1;else{if(!i&&(s=s.replace(a,function(t,e,i){return n="x"==(i=i.toLowerCase())?16:"b"==i?2:8,r&&r!=n?t:e}),r&&(n=r,s=s.replace(h,"$1").replace(u,"0.$1")),e!=s))return new R(s,n);if(R.DEBUG)throw Error(tt+"Not a"+(r?" base "+r:"")+" number: "+e);t.s=null}t.c=t.e=null},d.absoluteValue=d.abs=function(){var t=new R(this);return t.s<0&&(t.s=1),t},d.comparedTo=function(t,e){return at(this,new R(t,e))},d.decimalPlaces=d.dp=function(t,e){var i,r,n,s=this;if(null!=t)return ht(t,0,nt),null==e?e=g:ht(e,0,8),T(new R(s),t+s.e+1,e);if(!(i=s.c))return null;if(r=14*((n=i.length-1)-st(this.e/14)),n=i[n])for(;n%10==0;n/=10,r--);return r<0&&(r=0),r},d.dividedBy=d.div=function(t,e){return i(this,new R(t,e),m,g)},d.dividedToIntegerBy=d.idiv=function(t,e){return i(this,new R(t,e),0,1)},d.exponentiatedBy=d.pow=function(t,e){var i,r,n,s,o,a,h,u,l=this;if((t=new R(t)).c&&!t.isInteger())throw Error(tt+"Exponent not an integer: "+O(t));if(null!=e&&(e=new R(e)),o=t.e>14,!l.c||!l.c[0]||1==l.c[0]&&!l.e&&1==l.c.length||!t.c||!t.c[0])return u=new R(Math.pow(+O(l),o?2-ut(t):+O(t))),e?u.mod(e):u;if(a=t.s<0,e){if(e.c?!e.c[0]:!e.s)return new R(NaN);(r=!a&&l.isInteger()&&e.isInteger())&&(l=l.mod(e))}else{if(t.e>9&&(l.e>0||l.e<-1||(0==l.e?l.c[0]>1||o&&l.c[1]>=24e7:l.c[0]<8e13||o&&l.c[0]<=9999975e7)))return s=l.s<0&&ut(t)?-0:0,l.e>-1&&(s=1/s),new R(a?1/s:s);A&&(s=Q(A/14+2))}for(o?(i=new R(.5),a&&(t.s=1),h=ut(t)):h=(n=Math.abs(+O(t)))%2,u=new R(f);;){if(h){if(!(u=u.times(l)).c)break;s?u.c.length>s&&(u.c.length=s):r&&(u=u.mod(e))}if(n){if(0===(n=Y(n/2)))break;h=n%2}else if(T(t=t.times(i),t.e+1,1),t.e>14)h=ut(t);else{if(0==(n=+O(t)))break;h=n%2}l=l.times(l),s?l.c&&l.c.length>s&&(l.c.length=s):r&&(l=l.mod(e))}return r?u:(a&&(u=f.div(u)),e?u.mod(e):s?T(u,A,g,void 0):u)},d.integerValue=function(t){var e=new R(this);return null==t?t=g:ht(t,0,8),T(e,e.e+1,t)},d.isEqualTo=d.eq=function(t,e){return 0===at(this,new R(t,e))},d.isFinite=function(){return!!this.c},d.isGreaterThan=d.gt=function(t,e){return at(this,new R(t,e))>0},d.isGreaterThanOrEqualTo=d.gte=function(t,e){return 1===(e=at(this,new R(t,e)))||0===e},d.isInteger=function(){return!!this.c&&st(this.e/14)>this.c.length-2},d.isLessThan=d.lt=function(t,e){return at(this,new R(t,e))<0},d.isLessThanOrEqualTo=d.lte=function(t,e){return-1===(e=at(this,new R(t,e)))||0===e},d.isNaN=function(){return!this.s},d.isNegative=function(){return this.s<0},d.isPositive=function(){return this.s>0},d.isZero=function(){return!!this.c&&0==this.c[0]},d.minus=function(t,e){var i,r,n,s,o=this,a=o.s;if(e=(t=new R(t,e)).s,!a||!e)return new R(NaN);if(a!=e)return t.s=-e,o.plus(t);var h=o.e/14,u=t.e/14,l=o.c,c=t.c;if(!h||!u){if(!l||!c)return l?(t.s=-e,t):new R(c?o:NaN);if(!l[0]||!c[0])return c[0]?(t.s=-e,t):new R(l[0]?o:3==g?-0:0)}if(h=st(h),u=st(u),l=l.slice(),a=h-u){for((s=a<0)?(a=-a,n=l):(u=h,n=c),n.reverse(),e=a;e--;n.push(0));n.reverse()}else for(r=(s=(a=l.length)<(e=c.length))?a:e,a=e=0;e<r;e++)if(l[e]!=c[e]){s=l[e]<c[e];break}if(s&&(n=l,l=c,c=n,t.s=-t.s),(e=(r=c.length)-(i=l.length))>0)for(;e--;l[i++]=0);for(e=it-1;r>a;){if(l[--r]<c[r]){for(i=r;i&&!l[--i];l[i]=e);--l[i],l[r]+=it}l[r]-=c[r]}for(;0==l[0];l.splice(0,1),--u);return l[0]?I(t,l,u):(t.s=3==g?-1:1,t.c=[t.e=0],t)},d.modulo=d.mod=function(t,e){var r,n,s=this;return t=new R(t,e),!s.c||!t.s||t.c&&!t.c[0]?new R(NaN):!t.c||s.c&&!s.c[0]?new R(s):(9==b?(n=t.s,t.s=1,r=i(s,t,0,3),t.s=n,r.s*=n):r=i(s,t,0,b),(t=s.minus(r.times(t))).c[0]||1!=b||(t.s=s.s),t)},d.multipliedBy=d.times=function(t,e){var i,r,n,s,o,a,h,u,l,c,d,f,m,g,p,w=this,v=w.c,y=(t=new R(t,e)).c;if(!(v&&y&&v[0]&&y[0]))return!w.s||!t.s||v&&!v[0]&&!y||y&&!y[0]&&!v?t.c=t.e=t.s=null:(t.s*=w.s,v&&y?(t.c=[0],t.e=0):t.c=t.e=null),t;for(r=st(w.e/14)+st(t.e/14),t.s*=w.s,(h=v.length)<(c=y.length)&&(m=v,v=y,y=m,n=h,h=c,c=n),n=h+c,m=[];n--;m.push(0));for(g=it,p=1e7,n=c;--n>=0;){for(i=0,d=y[n]%p,f=y[n]/p|0,s=n+(o=h);s>n;)i=((u=d*(u=v[--o]%p)+(a=f*u+(l=v[o]/p|0)*d)%p*p+m[s]+i)/g|0)+(a/p|0)+f*l,m[s--]=u%g;m[s]=i}return i?++r:m.splice(0,1),I(t,m,r)},d.negated=function(){var t=new R(this);return t.s=-t.s||null,t},d.plus=function(t,e){var i,r=this,n=r.s;if(e=(t=new R(t,e)).s,!n||!e)return new R(NaN);if(n!=e)return t.s=-e,r.minus(t);var s=r.e/14,o=t.e/14,a=r.c,h=t.c;if(!s||!o){if(!a||!h)return new R(n/0);if(!a[0]||!h[0])return h[0]?t:new R(a[0]?r:0*n)}if(s=st(s),o=st(o),a=a.slice(),n=s-o){for(n>0?(o=s,i=h):(n=-n,i=a),i.reverse();n--;i.push(0));i.reverse()}for((n=a.length)-(e=h.length)<0&&(i=h,h=a,a=i,e=n),n=0;e;)n=(a[--e]=a[e]+h[e]+n)/it|0,a[e]=it===a[e]?0:a[e]%it;return n&&(a=[n].concat(a),++o),I(t,a,o)},d.precision=d.sd=function(t,e){var i,r,n,s=this;if(null!=t&&t!==!!t)return ht(t,1,nt),null==e?e=g:ht(e,0,8),T(new R(s),t,e);if(!(i=s.c))return null;if(r=14*(n=i.length-1)+1,n=i[n]){for(;n%10==0;n/=10,r--);for(n=i[0];n>=10;n/=10,r++);}return t&&s.e+1>r&&(r=s.e+1),r},d.shiftedBy=function(t){return ht(t,-9007199254740991,9007199254740991),this.times("1e"+t)},d.squareRoot=d.sqrt=function(){var t,e,r,n,s,o=this,a=o.c,h=o.s,u=o.e,l=m+4,c=new R("0.5");if(1!==h||!a||!a[0])return new R(!h||h<0&&(!a||a[0])?NaN:a?o:1/0);if(0==(h=Math.sqrt(+O(o)))||h==1/0?(((e=ot(a)).length+u)%2==0&&(e+="0"),h=Math.sqrt(+e),u=st((u+1)/2)-(u<0||u%2),r=new R(e=h==1/0?"5e"+u:(e=h.toExponential()).slice(0,e.indexOf("e")+1)+u)):r=new R(h+""),r.c[0])for((h=(u=r.e)+l)<3&&(h=0);;)if(r=c.times((s=r).plus(i(o,s,l,1))),ot(s.c).slice(0,h)===(e=ot(r.c)).slice(0,h)){if(r.e<u&&--h,"9999"!=(e=e.slice(h-3,h+1))&&(n||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(T(r,r.e+m+2,1),t=!r.times(r).eq(o));break}if(!n&&(T(s,s.e+m+2,0),s.times(s).eq(o))){r=s;break}l+=4,h+=4,n=1}return T(r,r.e+m+1,g,t)},d.toExponential=function(t,e){return null!=t&&(ht(t,0,nt),t++),S(this,t,e,1)},d.toFixed=function(t,e){return null!=t&&(ht(t,0,nt),t=t+this.e+1),S(this,t,e)},d.toFormat=function(t,e,i){var r,n=this;if(null==i)null!=t&&e&&"object"==typeof e?(i=e,e=null):t&&"object"==typeof t?(i=t,t=e=null):i=x;else if("object"!=typeof i)throw Error(tt+"Argument not an object: "+i);if(r=n.toFixed(t,e),n.c){var s,o=r.split("."),a=+i.groupSize,h=+i.secondaryGroupSize,u=i.groupSeparator||"",l=o[0],c=o[1],d=n.s<0,f=d?l.slice(1):l,m=f.length;if(h&&(s=a,a=h,h=s,m-=s),a>0&&m>0){for(l=f.substr(0,s=m%a||a);s<m;s+=a)l+=u+f.substr(s,a);h>0&&(l+=u+f.slice(s)),d&&(l="-"+l)}r=c?l+(i.decimalSeparator||"")+((h=+i.fractionGroupSize)?c.replace(new RegExp("\\d{"+h+"}\\B","g"),"$&"+(i.fractionGroupSeparator||"")):c):l}return(i.prefix||"")+r+(i.suffix||"")},d.toFraction=function(t){var e,r,n,s,o,a,h,u,l,c,d,m,p=this,w=p.c;if(null!=t&&(!(h=new R(t)).isInteger()&&(h.c||1!==h.s)||h.lt(f)))throw Error(tt+"Argument "+(h.isInteger()?"out of range: ":"not an integer: ")+O(h));if(!w)return new R(p);for(e=new R(f),l=r=new R(f),n=u=new R(f),m=ot(w),o=e.e=m.length-p.e-1,e.c[0]=rt[(a=o%14)<0?14+a:a],t=!t||h.comparedTo(e)>0?o>0?e:l:h,a=y,y=1/0,h=new R(m),u.c[0]=0;c=i(h,e,0,1),1!=(s=r.plus(c.times(n))).comparedTo(t);)r=n,n=s,l=u.plus(c.times(s=l)),u=s,e=h.minus(c.times(s=e)),h=s;return s=i(t.minus(r),n,0,1),u=u.plus(s.times(l)),r=r.plus(s.times(n)),u.s=l.s=p.s,d=i(l,n,o*=2,g).minus(p).abs().comparedTo(i(u,r,o,g).minus(p).abs())<1?[l,n]:[u,r],y=a,d},d.toNumber=function(){return+O(this)},d.toPrecision=function(t,e){return null!=t&&ht(t,1,nt),S(this,t,e,2)},d.toString=function(t){var e,i=this,n=i.s,s=i.e;return null===s?n?(e="Infinity",n<0&&(e="-"+e)):e="NaN":(null==t?e=s<=p||s>=w?lt(ot(i.c),s):ct(ot(i.c),s,"0"):10===t?e=ct(ot((i=T(new R(i),m+s+1,g)).c),i.e,"0"):(ht(t,2,E.length,"Base"),e=r(ct(ot(i.c),s,"0"),10,t,n,!0)),n<0&&i.c[0]&&(e="-"+e)),e},d.valueOf=d.toJSON=function(){return O(this)},d._isBigNumber=!0,d[Symbol.toStringTag]="BigNumber",d[Symbol.for("nodejs.util.inspect.custom")]=d.valueOf,null!=e&&R.set(e),R}();async function ft(t,e){const i=new dt(await t.eth.getGasPrice());return e&&e.gasFeeMultiplier?i.multipliedBy(e.gasFeeMultiplier).integerValue(dt.ROUND_DOWN).toString(10):i.toString(10)}function mt(t,e){return e&&(t.transactionBlockTimeout=e.transactionBlockTimeout,t.transactionConfirmationBlocks=e.transactionConfirmationBlocks,t.transactionPollingTimeout=e.transactionPollingTimeout),t}function gt(t){return void 0!==t.id}async function pt(t,e){if(gt(t))return{did:t.id,ddo:t};{const i=await e.assets.resolve(t);return{did:i.id,ddo:i}}}var wt={nouns:["Crab","Fish","Seal","Octopus","Shark","Seahorse","Walrus","Starfish","Whale","Orca","Penguin","Jellyfish","Squid","Lobster","Pelican","Shrimp","Oyster","Clam","Seagull","Dolphin","Shell","Cormorant","Otter","Anemone","Turtle","Coral","Ray","Barracuda","Krill","Anchovy","Angelfish","Barnacle","Clownfish","Cod","Cuttlefish","Eel","Fugu","Herring","Haddock","Ling","Mackerel","Manatee","Narwhal","Nautilus","Plankton","Porpoise","Prawn","Pufferfish","Swordfish","Tuna"],adjectives:["adamant","adroit","amatory","ambitious","amused","animistic","antic","arcadian","artistic","astonishing","astounding","baleful","bellicose","bilious","blissful","boorish","brave","breathtaking","brilliant","calamitous","caustic","cerulean","clever","charming","comely","competent","concomitant","confident","contumacious","corpulent","crapulous","creative","dazzling","dedicated","defamatory","delighted","delightful","determined","didactic","dilatory","dowdy","efficacious","effulgent","egregious","empowered","endemic","enthusiastic","equanimous","exceptional","execrable","fabulous","fantastic","fastidious","feckless","fecund","friable","fulsome","garrulous","generous","gentle","guileless","gustatory","heuristic","histrionic","hubristic","incendiary","incredible","insidious","insolent","inspired","intransigent","inveterate","invidious","invigorated","irksome","jejune","juicy","jocular","joyful","judicious","kind","lachrymose","limpid","loquacious","lovely","luminous","mannered","marvelous","mendacious","meretricious","minatory","mordant","motivated","munificent","nefarious","noxious","obtuse","optimistic","parsimonious","pendulous","pernicious","pervasive","petulant","passionate","phenomenal","platitudinous","pleasant","powerful","precipitate","propitious","puckish","querulous","quiescent","rebarbative","recalcitant","redolent","rhadamanthine","risible","ruminative","sagacious","salubrious","sartorial","sclerotic","serpentine","smart","spasmodic","strident","stunning","stupendous","taciturn","tactful","tasty","tenacious","tremendous","tremulous","trenchant","turbulent","turgid","ubiquitous","uxorious","verdant","vibrant","voluble","voracious","wheedling","withering","wonderful","zealous"]};function vt(t){const e=t||wt,i=Math.floor(Math.random()*e.adjectives.length),r=Math.floor(Math.random()*e.nouns.length),n=Math.floor(100*Math.random()),s=e.adjectives[i].replace(/^\w/,t=>t.toUpperCase()),o=e.nouns[r].replace(/^\w/,t=>t.toUpperCase());return{name:`${s} ${o} Token`,symbol:`${(s.substring(0,3)+o.substring(0,3)).toUpperCase()}-${n}`}}var yt={__proto__:null,objectPromiseAll:async t=>((t=[],e=[])=>t.reduce((t,i,r)=>W({},t,{[i]:e[r]}),{}))(Object.keys(t),await Promise.all(Object.values(t))),get LogLevel(){return exports.LogLevel},Logger:F,LoggerInstance:U,zeroX:q,noZeroX:$,zeroXTransformer:j,didPrefixed:G,noDidPrefixed:t=>z(t,!1),didTransformer:z,didZeroX:H,didNoZeroX:Z,generateId:function(e=64){let i="";for(;i.length<e;)i+=t.v4().replace(/-/g,"");return i.substr(0,e)},SubscribablePromise:K,SubscribableObserver:J,getFairGasPrice:ft,setContractDefaults:mt,isDdo:gt,assetResolve:pt,generateDatatokenName:vt};class Mt{constructor(){this._ocean=void 0,this._web3=void 0,this._config=void 0,this._logger=void 0}get ocean(){return this._ocean||U.error("Ocean instance is not defined."),this._ocean}get web3(){return this._web3||U.error("Web3 instance is not defined."),this._web3}get config(){return this._config||U.error("Config instance is not defined."),this._config}get logger(){return U}get instanceConfig(){const{ocean:t,web3:e,config:i,logger:r}=this;return{ocean:t,web3:e,config:i,logger:r}}static async getInstance(t){U.warn("getInstance() methods has needs to be added to child class.")}static setInstanceConfig(t,{ocean:e,config:i,web3:r,logger:n}){t._ocean=e,t._config=i,t._web3=r,t._logger=n}setInstanceConfig(t){Mt.setInstanceConfig(this,t)}}class bt extends Mt{constructor(t="0x0",e){super(),this.id=void 0,this.password=void 0,this.token=void 0,this.id=t,e&&this.setInstanceConfig(e)}getId(){return this.id}setId(t){this.id=t}setPassword(t){this.password=t}getPassword(){return this.password}async getTokenBalance(t){if(null===t)return null;const e=[{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];let i=null;const r=await this.getTokenDecimals(t);try{const n=new this.web3.eth.Contract(e,t,{from:this.id}),s=await n.methods.balanceOf(this.id).call();i=new x.default(s).div(10**r).toString()}catch(t){this.logger.error(`ERROR: Failed to get the balance: ${t.message}`)}return i}async getTokenDecimals(t){let e=18;if(null===t)return e;const i=[{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],type:"function"}];try{const r=new this.web3.eth.Contract(i,t,{from:this.id});e=await r.methods.decimals().call()}catch(t){this.logger.error(`ERROR: Failed to get decimals : ${t.message}`)}return e}async getOceanBalance(){return this.getTokenBalance(this.config.oceanTokenAddress)}async getTokenSymbol(t){return""}async getEtherBalance(){const t=await this.web3.eth.getBalance(this.id,"latest");return this.web3.utils.fromWei(t)}}class At{static parse(t){let e;t instanceof At&&(t=t.getDid());const i=t.match(/^did:op:([a-f0-9]{40})$/i);if(i&&(e=new At(i[1])),!e)throw new Error(`Parsing DID failed, ${t}`);return e}static generate(t){return new At($(t))}constructor(t){this.id=void 0,this.id=t}getDid(){return`did:op:${this.id}`}getId(){return this.id}}class xt extends Mt{static async getInstance(t){const e=new xt;return e.setInstanceConfig(t),e}async list(){const t=(await this.web3.eth.getAccounts()).map(t=>new bt(t,this.instanceConfig));return Promise.all(t)}getTokenBalance(t,e){return e.getTokenBalance(t)}getOceanBalance(t){return t.getOceanBalance()}getEtherBalance(t){return t.getEtherBalance()}}class Et{static getWeb3(t={}){return new E.default(t.web3Provider||E.default.givenProvider||new E.default.providers.HttpProvider(t.nodeUri))}}class Rt{static serialize(t){return JSON.stringify(t,null,2)}static deserialize(t){const e=JSON.parse(t);return new Rt(e)}constructor(t={}){this["@context"]="https://w3id.org/did/v1",this.id=null,this.created=void 0,this.updated=void 0,this.dataToken=void 0,this.publicKey=[],this.authentication=[],this.service=[],this.proof=void 0,this.price=void 0,this.isInPurgatory=void 0,this.purgatoryData=void 0,this.dataTokenInfo=void 0,this.credentials=void 0,this.chainId=void 0,this.event=void 0,Object.assign(this,t,{created:t&&t.created||(new Date).toISOString().replace(/\.[0-9]{3}/,"")})}shortId(){return this.id.replace("did:op:","")}findServiceById(t){if(isNaN(t))throw new Error("index is not set");return this.service.find(e=>e.index===t)}findServiceByType(t){if(!t)throw new Error("serviceType not set");return this.service.find(e=>e.type===t)}getChecksum(){const{attributes:t}=this.findServiceByType("metadata"),{files:e,name:i,author:r,license:n}=t.main,s=[...(e||[]).map(({checksum:t})=>t).filter(t=>!!t),i,r,n,this.id];return Et.getWeb3().utils.sha3(s.join("")).replace(/^0x([a-f0-9]{64})(:!.+)?$/i,"0x$1")}async addProof(t,e,i){if(this.proof)throw new Error("Proof already exists");this.proof={created:(new Date).toISOString().replace(/\.[0-9]{3}/,""),creator:e,type:"AddressHash",signatureValue:Et.getWeb3().utils.sha3(e).replace(/^0x([a-f0-9]{64})(:!.+)?$/i,"0x$1")}}}function St(t){if(!Number.isInteger(t))throw new TypeError("Expected an integer, got "+typeof t);const e=new WeakMap,i=new k.default,r=setTimeout(()=>{i.abort()},t);return e.set(i.signal,r),i.signal}const kt=require("cross-fetch");class It{constructor(t,e){this.logger=void 0,this.requestTimeout=5e3,this.logger=t,this.requestTimeout=e||this.requestTimeout}post(t,e){return this.postWithHeaders(t,e,{"Content-type":"application/json"})}postWithOctet(t,e){return this.postWithHeaders(t,e,{"Content-type":"application/octet-stream"})}postWithHeaders(t,e,i){return this.fetch(t,null!=e?{method:"POST",body:e,headers:i,signal:St(this.requestTimeout)}:{method:"POST",signal:St(this.requestTimeout)})}get(t){return this.fetch(t,{method:"GET",headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)})}put(t,e){return this.fetch(t,null!=e?{method:"PUT",body:e,headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)}:{method:"PUT",headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)})}delete(t,e){return this.fetch(t,null!=e?{method:"DELETE",body:e,headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)}:{method:"DELETE",headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)})}async downloadFile(t,e,i){const r=await this.get(t);if(!r.ok)throw new Error("Response error.");let n;try{n=r.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(e){try{n=t.split("/").pop()}catch(t){n=`file${i}`}}if(e)return await new Promise(async(t,i)=>{R.default.mkdirSync(e,{recursive:!0});const s=R.default.createWriteStream(`${e}${n}`);r.body.pipe(s),r.body.on("error",i),s.on("finish",t)}),e;S.default(await r.arrayBuffer(),n)}async downloadFileBrowser(t){const e=document.createElement("a");e.download="",e.href=t,e.click()}async fetch(t,e){const i=await kt(t,e);if(!i.ok)throw this.logger.error(`Error requesting [${e.method}] ${t}`),this.logger.error(`Response message: \n${await i.text()}`),i;return i}}class Tt extends Mt{constructor(...t){super(...t),this.nonce=void 0,this.baseUrl=void 0,this.servicesEndpoints=void 0,this.computeAddress=void 0,this.providerAddress=void 0,this.providerVersion=void 0,this.computeLimits=void 0}static async getInstance(t){const e=new Tt;return e.setInstanceConfig(t),e.nonce="0",await e.setBaseUrl(t.config.providerUri),e}async setBaseUrl(t){return this.baseUrl=t,this.servicesEndpoints=await this.getServiceEndpoints(),!0}get url(){return this.baseUrl}async getServiceEndpoints(){const t=[];try{const e=await(await this.ocean.utils.fetch.get(this.url)).json();this.providerAddress=e.providerAddress,"computeAddress"in e&&(this.computeAddress=e.computeAddress),"version"in e&&(this.providerVersion=e.version),"computeLimits"in e&&(this.computeLimits=e.computeLimits);for(const i in e.serviceEndpoints)t.push({serviceName:i,method:e.serviceEndpoints[i][0],urlPath:this.url+e.serviceEndpoints[i][1]});return t}catch(t){return this.logger.error("Finding the service endpoints failed:",t),null}}getEndpointURL(t){return this.servicesEndpoints?this.servicesEndpoints.find(e=>e.serviceName===t):null}async createSignature(t,e){return await this.ocean.utils.signature.signText($(e),t.getId())}async createHashSignature(t,e){return await this.ocean.utils.signature.signWithHash(e,t.getId())}async encrypt(t,e,i){await this.getNonce(i.getId());const r={documentId:t,document:JSON.stringify(e),publisherAddress:i.getId()},n=this.getEncryptEndpoint()?this.getEncryptEndpoint().urlPath:null;if(!n)return null;try{const t=await this.ocean.utils.fetch.post(n,decodeURI(JSON.stringify(r)));return(await t.json()).encryptedDocument}catch(t){throw this.logger.error(t),new Error("HTTP request failed")}}async fileinfo(t){const e={url:t},i=[],r=this.getFileinfoEndpoint()?this.getFileinfoEndpoint().urlPath:null;if(!r)return null;try{const t=await this.ocean.utils.fetch.post(r,JSON.stringify(e)),n=await t.json();for(const t of n)i.push(t);return i}catch(t){return null}}async isFileConsumable(t,e){const i={did:t.getDid()},r=await this.ocean.metadataCache.retrieveDDO(t);if(!r)return!1;const n=r.findServiceById(e);if(!n)return!1;const s=n.serviceEndpoint+"/api/v1/services/fileinfo";try{const t=await this.ocean.utils.fetch.post(s,JSON.stringify(i));return(await t.json())[0].valid}catch(t){return!1}}async getNonce(t){const e=this.getNonceEndpoint()?this.getNonceEndpoint().urlPath:null;if(!e)return null;try{const i=await this.ocean.utils.fetch.get(e+`?userAddress=${t}`);return this.nonce=String((await i.json()).nonce),this.nonce}catch(t){throw this.logger.error(t),new Error("HTTP request failed")}}async initialize(t,e,i,r,n){const{did:s,ddo:o}=await pt(t,this.ocean);let a=this.getInitializeEndpoint()?this.getInitializeEndpoint().urlPath:null;if(!a)return null;a+=`?documentId=${s}`,a+=`&serviceId=${e}`,a+=`&serviceType=${i}`,a+=`&dataToken=${o.dataToken}`,a+=`&consumerAddress=${r}`,n&&(a+="&userdata="+encodeURI(JSON.stringify(n)));try{const t=await this.ocean.utils.fetch.get(a);return await t.text()}catch(t){throw this.logger.error(t),new Error("Asset URL not found or not available.")}}async download(t,e,i,r,n,s,o,a,h=-1,u){await this.getNonce(o.getId());const l=await this.createSignature(o,t+this.nonce),c=this.getDownloadEndpoint()?this.getDownloadEndpoint().urlPath:null;if(!c)return null;const d=a.filter((t,e)=>-1===h||e===h).map(async({index:a})=>{let h=c;h+=`?fileIndex=${a}`,h+=`&documentId=${t}`,h+=`&serviceId=${n}`,h+=`&serviceType=${r}`,h+=`&dataToken=${i}`,h+=`&transferTxId=${e}`,h+=`&consumerAddress=${o.getId()}`,h+=`&signature=${l}`,u&&(h+="&userdata="+encodeURI(JSON.stringify(u)));try{s?await this.ocean.utils.fetch.downloadFile(h,s,a):await this.ocean.utils.fetch.downloadFileBrowser(h)}catch(t){throw this.logger.error("Error consuming assets"),this.logger.error(t),t}});return await Promise.all(d),s}async computeStart(t,e,i,r,n,s,o,a,h,u){const l=e.getId();await this.getNonce(e.getId());const c=Object();c.documentId=$(t);let d=l;d+=t&&`${$(t)}`||"",d+=this.nonce;const f=await this.createHashSignature(e,d);c.signature=f,r&&(c.output=r),i.did&&(c.algorithmDid=i.did),i.meta&&(c.algorithmMeta=i.meta),c.consumerAddress=l,n&&(c.transferTxId=n),i.transferTxId&&(c.algorithmTransferTxId=i.transferTxId),i.dataToken&&(c.algorithmDataToken=i.dataToken),s&&(c.serviceId=s),o&&(c.serviceType=o),a&&(c.dataToken=a),h&&(c.additionalInputs=h),u&&(c.userData=u),i.algoCustomParameters&&(c.algouserdata=i.algoCustomParameters);const m=this.getComputeStartEndpoint()?this.getComputeStartEndpoint().urlPath:null;if(!m)return null;try{const t=await this.ocean.utils.fetch.post(m,JSON.stringify(c));return null!=t&&t.ok?await t.json():(console.error("Compute start failed:",t.status,t.statusText),this.logger.error("Payload was:",c),null)}catch(t){return this.logger.error("Compute start failed:"),this.logger.error(t),this.logger.error("Payload was:",c),null}}async computeStop(t,e,i){const r=e.getId();await this.getNonce(e.getId());const n=Object();n.documentId=$(t);let s=r;s+=i||"",s+=t&&`${$(t)}`||"",s+=this.nonce;const o=await this.createHashSignature(e,s);n.signature=o,n.jobId=i,n.consumerAddress=r;const a=this.getComputeStopEndpoint()?this.getComputeStopEndpoint().urlPath:null;if(!a)return null;try{const t=await this.ocean.utils.fetch.put(a,JSON.stringify(n));return null!=t&&t.ok?await t.json():(this.logger.error("Compute stop failed:",t.status,t.statusText),this.logger.error("Payload was:",n),null)}catch(t){return this.logger.error("Compute stop failed:"),this.logger.error(t),this.logger.error("Payload was:",n),null}}async computeDelete(t,e,i){const r=e.getId();await this.getNonce(e.getId());const n=Object();n.documentId=$(t);let s=r;s+=i||"",s+=t&&`${$(t)}`||"",s+=this.nonce;const o=await this.createHashSignature(e,s);n.signature=o,n.jobId=i,n.consumerAddress=r;const a=this.getComputeDeleteEndpoint()?this.getComputeDeleteEndpoint().urlPath:null;if(!a)return null;try{const t=await this.ocean.utils.fetch.delete(a,JSON.stringify(n));return null!=t&&t.ok?await t.json():(this.logger.error("Delete compute job failed:",t.status,t.statusText),this.logger.error("Payload was:",n),null)}catch(t){return this.logger.error("Delete compute job failed:"),this.logger.error(t),this.logger.error("Payload was:",n),null}}async computeStatus(t,e,i,r){const n=e.getId();await this.getNonce(e.getId());let s="?documentId="+$(t);s+=i&&`&jobId=${i}`||"",s+=`&consumerAddress=${n}`,s+=r&&`&transferTxId=${r}`||"";const o=this.getComputeStatusEndpoint()?this.getComputeStatusEndpoint().urlPath:null;if(!o)return null;try{const t=await this.ocean.utils.fetch.get(o+s);return null!=t&&t.ok?await t.json():(this.logger.error("Get compute status failed:",t.status,t.statusText),null)}catch(t){return this.logger.error("Get compute status failed"),this.logger.error(t),null}}async computeResult(t,e,i,r){await this.getNonce(r.getId());let n=r.getId();n+=t,n+=String(e),n+=this.nonce;const s=await this.createHashSignature(r,n),o=this.getComputeResultEndpoint()?this.getComputeResultEndpoint().urlPath:null;if(!o)return null;let a=o;a+=`?jobId=${t}`,a+=`&index=${String(e)}`,a+=`&signature=${s}`,a+=`&consumerAddress=${r.getId()}`;try{i?await this.ocean.utils.fetch.downloadFile(a,i,e):await this.ocean.utils.fetch.downloadFileBrowser(a)}catch(t){throw this.logger.error("Error getting job result"),this.logger.error(t),t}return i}getInitializeEndpoint(){return this.getEndpointURL("initialize")}getNonceEndpoint(){return this.getEndpointURL("nonce")}getEncryptEndpoint(){return this.getEndpointURL("encrypt")}getFileinfoEndpoint(){return this.getEndpointURL("fileinfo")}getComputeStartEndpoint(){return this.getEndpointURL("computeStart")}getComputeStopEndpoint(){return this.getEndpointURL("computeStop")}getComputeStatusEndpoint(){return this.getEndpointURL("computeStatus")}getComputeDeleteEndpoint(){return this.getEndpointURL("computeDelete")}getComputeResultEndpoint(){return this.getEndpointURL("computeResult")}getDownloadEndpoint(){return this.getEndpointURL("download")}async isValidProvider(t){try{const e=await this.ocean.utils.fetch.get(t);if(null!=e&&e.ok){const t=await e.json();if(t&&t.providerAddress)return!0}return!1}catch(t){return this.logger.error(`Error validating provider: ${t.message}`),!1}}}var Ot="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Bt(t){var e={exports:{}};return t(e,e.exports),e.exports}function Ct(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.')}var _t=Bt(function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function n(t,e,i){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var s;"object"==typeof t?t.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=Ct("buffer").Buffer}catch(t){}function o(t,e,i){for(var r=0,n=Math.min(t.length,i),s=e;s<n;s++){var o=t.charCodeAt(s)-48;r<<=4,r|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return r}function a(t,e,i,r){for(var n=0,s=Math.min(t.length,i),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=r,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}n.isBN=function(t){return t instanceof n||null!==t&&"object"==typeof t&&t.constructor.wordSize===n.wordSize&&Array.isArray(t.words)},n.max=function(t,e){return t.cmp(e)>0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)this.words[s]|=(o=t[n]|t[n-1]<<8|t[n-2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)this.words[s]|=(o=t[n]|t[n+1]<<8|t[n+2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},n.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var r,n,s=0;for(i=t.length-6,r=0;i>=e;i-=6)n=o(t,i,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,r++);i+6!==e&&(n=o(t,e,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303),this.strip()},n.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var r=0,n=1;n<=67108863;n*=e)r++;r--,n=n/e|0;for(var s=t.length-i,o=s%r,h=Math.min(s,s-o)+i,u=0,l=i;l<h;l+=r)u=a(t,l,l+r,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=a(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},n.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},n.prototype.clone=function(){var t=new n(null);return this.copy(t),t},n.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},n.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},n.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","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"],u=[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],l=[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 c(t,e,i){i.negative=e.negative^t.negative;var r=t.length+e.length|0;i.length=r,r=r-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=o/67108864|0;i.words[0]=67108863&o;for(var h=1;h<r;h++){for(var u=a>>>26,l=67108863&a,c=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=c;d++)u+=(o=(n=0|t.words[h-d|0])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o;i.words[h]=0|l,a=0|u}return 0!==a?i.words[h]=0|a:i.length--,i.strip()}n.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],c=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?h[6-c.length]+c+r:c+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var d=u[t],f=l[t];r="";var m=this.clone();for(m.negative=0;!m.isZero();){var g=m.modn(f).toString(t);r=(m=m.idivn(f)).isZero()?g+r:h[d-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},n.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16)},n.prototype.toBuffer=function(t,e){return i(void 0!==s),this.toArrayLike(s,t,e)},n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,u=new t(s),l=this.clone();if(h){for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[a]=o;for(;a<s;a++)u[a]=0}else{for(a=0;a<s-n;a++)u[a]=0;for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[s-a-1]=o}return u},n.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},n.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},n.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.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()},n.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},n.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},n.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},n.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var r=0;r<i.length;r++)this.words[r]=e.words[r]^i.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this.strip()},n.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},n.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},n.prototype.iadd=function(t){var e,i,r;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?(i=this,r=t):(i=t,r=this);for(var n=0,s=0;s<r.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+(0|r.words[s])+n),n=e>>>26;for(;0!==n&&s<i.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+n),n=e>>>26;if(this.length=i.length,0!==n)this.words[this.length]=n,this.length++;else if(i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this},n.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)},n.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 i,r,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(i=this,r=t):(i=t,r=this);for(var s=0,o=0;o<r.length;o++)s=(e=(0|i.words[o])-(0|r.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<i.length;o++)s=(e=(0|i.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<i.length&&i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this.length=Math.max(this.length,o),i!==this&&(this.negative=1),this.strip()},n.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,i){var r,n,s,o=t.words,a=e.words,h=i.words,u=0,l=0|o[0],c=8191&l,d=l>>>13,f=0|o[1],m=8191&f,g=f>>>13,p=0|o[2],w=8191&p,v=p>>>13,y=0|o[3],M=8191&y,b=y>>>13,A=0|o[4],x=8191&A,E=A>>>13,R=0|o[5],S=8191&R,k=R>>>13,I=0|o[6],T=8191&I,O=I>>>13,B=0|o[7],C=8191&B,_=B>>>13,P=0|o[8],D=8191&P,L=P>>>13,N=0|o[9],W=8191&N,F=N>>>13,U=0|a[0],q=8191&U,$=U>>>13,j=0|a[1],G=8191&j,z=j>>>13,H=0|a[2],Z=8191&H,V=H>>>13,J=0|a[3],K=8191&J,X=J>>>13,Q=0|a[4],Y=8191&Q,tt=Q>>>13,et=0|a[5],it=8191&et,rt=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,dt=lt>>>13,ft=0|a[9],mt=8191&ft,gt=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var pt=(u+(r=Math.imul(c,q))|0)+((8191&(n=(n=Math.imul(c,$))+Math.imul(d,q)|0))<<13)|0;u=((s=Math.imul(d,$))+(n>>>13)|0)+(pt>>>26)|0,pt&=67108863,r=Math.imul(m,q),n=(n=Math.imul(m,$))+Math.imul(g,q)|0,s=Math.imul(g,$);var wt=(u+(r=r+Math.imul(c,G)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(d,G)|0))<<13)|0;u=((s=s+Math.imul(d,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(w,q),n=(n=Math.imul(w,$))+Math.imul(v,q)|0,s=Math.imul(v,$),r=r+Math.imul(m,G)|0,n=(n=n+Math.imul(m,z)|0)+Math.imul(g,G)|0,s=s+Math.imul(g,z)|0;var vt=(u+(r=r+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,Z)|0))<<13)|0;u=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(M,q),n=(n=Math.imul(M,$))+Math.imul(b,q)|0,s=Math.imul(b,$),r=r+Math.imul(w,G)|0,n=(n=n+Math.imul(w,z)|0)+Math.imul(v,G)|0,s=s+Math.imul(v,z)|0,r=r+Math.imul(m,Z)|0,n=(n=n+Math.imul(m,V)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,V)|0;var yt=(u+(r=r+Math.imul(c,K)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,K)|0))<<13)|0;u=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(x,q),n=(n=Math.imul(x,$))+Math.imul(E,q)|0,s=Math.imul(E,$),r=r+Math.imul(M,G)|0,n=(n=n+Math.imul(M,z)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,z)|0,r=r+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,V)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,V)|0,r=r+Math.imul(m,K)|0,n=(n=n+Math.imul(m,X)|0)+Math.imul(g,K)|0,s=s+Math.imul(g,X)|0;var Mt=(u+(r=r+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(S,q),n=(n=Math.imul(S,$))+Math.imul(k,q)|0,s=Math.imul(k,$),r=r+Math.imul(x,G)|0,n=(n=n+Math.imul(x,z)|0)+Math.imul(E,G)|0,s=s+Math.imul(E,z)|0,r=r+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,V)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,V)|0,r=r+Math.imul(w,K)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(v,K)|0,s=s+Math.imul(v,X)|0,r=r+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,tt)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,tt)|0;var bt=(u+(r=r+Math.imul(c,it)|0)|0)+((8191&(n=(n=n+Math.imul(c,rt)|0)+Math.imul(d,it)|0))<<13)|0;u=((s=s+Math.imul(d,rt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(T,q),n=(n=Math.imul(T,$))+Math.imul(O,q)|0,s=Math.imul(O,$),r=r+Math.imul(S,G)|0,n=(n=n+Math.imul(S,z)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,z)|0,r=r+Math.imul(x,Z)|0,n=(n=n+Math.imul(x,V)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,V)|0,r=r+Math.imul(M,K)|0,n=(n=n+Math.imul(M,X)|0)+Math.imul(b,K)|0,s=s+Math.imul(b,X)|0,r=r+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,tt)|0,r=r+Math.imul(m,it)|0,n=(n=n+Math.imul(m,rt)|0)+Math.imul(g,it)|0,s=s+Math.imul(g,rt)|0;var At=(u+(r=r+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,q),n=(n=Math.imul(C,$))+Math.imul(_,q)|0,s=Math.imul(_,$),r=r+Math.imul(T,G)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(O,G)|0,s=s+Math.imul(O,z)|0,r=r+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,V)|0,r=r+Math.imul(x,K)|0,n=(n=n+Math.imul(x,X)|0)+Math.imul(E,K)|0,s=s+Math.imul(E,X)|0,r=r+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,tt)|0,r=r+Math.imul(w,it)|0,n=(n=n+Math.imul(w,rt)|0)+Math.imul(v,it)|0,s=s+Math.imul(v,rt)|0,r=r+Math.imul(m,st)|0,n=(n=n+Math.imul(m,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var xt=(u+(r=r+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(d,ht)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(D,q),n=(n=Math.imul(D,$))+Math.imul(L,q)|0,s=Math.imul(L,$),r=r+Math.imul(C,G)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(_,G)|0,s=s+Math.imul(_,z)|0,r=r+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,V)|0,r=r+Math.imul(S,K)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(k,K)|0,s=s+Math.imul(k,X)|0,r=r+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,r=r+Math.imul(M,it)|0,n=(n=n+Math.imul(M,rt)|0)+Math.imul(b,it)|0,s=s+Math.imul(b,rt)|0,r=r+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,r=r+Math.imul(m,ht)|0,n=(n=n+Math.imul(m,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var Et=(u+(r=r+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(W,q),n=(n=Math.imul(W,$))+Math.imul(F,q)|0,s=Math.imul(F,$),r=r+Math.imul(D,G)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,z)|0,r=r+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,V)|0,r=r+Math.imul(T,K)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(O,K)|0,s=s+Math.imul(O,X)|0,r=r+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,r=r+Math.imul(x,it)|0,n=(n=n+Math.imul(x,rt)|0)+Math.imul(E,it)|0,s=s+Math.imul(E,rt)|0,r=r+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,r=r+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,r=r+Math.imul(m,ct)|0,n=(n=n+Math.imul(m,dt)|0)+Math.imul(g,ct)|0,s=s+Math.imul(g,dt)|0;var Rt=(u+(r=r+Math.imul(c,mt)|0)|0)+((8191&(n=(n=n+Math.imul(c,gt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,r=Math.imul(W,G),n=(n=Math.imul(W,z))+Math.imul(F,G)|0,s=Math.imul(F,z),r=r+Math.imul(D,Z)|0,n=(n=n+Math.imul(D,V)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,V)|0,r=r+Math.imul(C,K)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(_,K)|0,s=s+Math.imul(_,X)|0,r=r+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,r=r+Math.imul(S,it)|0,n=(n=n+Math.imul(S,rt)|0)+Math.imul(k,it)|0,s=s+Math.imul(k,rt)|0,r=r+Math.imul(x,st)|0,n=(n=n+Math.imul(x,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,r=r+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ut)|0)+Math.imul(b,ht)|0,s=s+Math.imul(b,ut)|0,r=r+Math.imul(w,ct)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(v,ct)|0,s=s+Math.imul(v,dt)|0;var St=(u+(r=r+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,gt)|0)+Math.imul(g,mt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(W,Z),n=(n=Math.imul(W,V))+Math.imul(F,Z)|0,s=Math.imul(F,V),r=r+Math.imul(D,K)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,X)|0,r=r+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,tt)|0,r=r+Math.imul(T,it)|0,n=(n=n+Math.imul(T,rt)|0)+Math.imul(O,it)|0,s=s+Math.imul(O,rt)|0,r=r+Math.imul(S,st)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,r=r+Math.imul(x,ht)|0,n=(n=n+Math.imul(x,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,r=r+Math.imul(M,ct)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(b,ct)|0,s=s+Math.imul(b,dt)|0;var kt=(u+(r=r+Math.imul(w,mt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(v,mt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(W,K),n=(n=Math.imul(W,X))+Math.imul(F,K)|0,s=Math.imul(F,X),r=r+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,tt)|0,r=r+Math.imul(C,it)|0,n=(n=n+Math.imul(C,rt)|0)+Math.imul(_,it)|0,s=s+Math.imul(_,rt)|0,r=r+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,r=r+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,s=s+Math.imul(k,ut)|0,r=r+Math.imul(x,ct)|0,n=(n=n+Math.imul(x,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var It=(u+(r=r+Math.imul(M,mt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(b,mt)|0))<<13)|0;u=((s=s+Math.imul(b,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(W,Y),n=(n=Math.imul(W,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),r=r+Math.imul(D,it)|0,n=(n=n+Math.imul(D,rt)|0)+Math.imul(L,it)|0,s=s+Math.imul(L,rt)|0,r=r+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,r=r+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,r=r+Math.imul(S,ct)|0,n=(n=n+Math.imul(S,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var Tt=(u+(r=r+Math.imul(x,mt)|0)|0)+((8191&(n=(n=n+Math.imul(x,gt)|0)+Math.imul(E,mt)|0))<<13)|0;u=((s=s+Math.imul(E,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(W,it),n=(n=Math.imul(W,rt))+Math.imul(F,it)|0,s=Math.imul(F,rt),r=r+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,r=r+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,r=r+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Ot=(u+(r=r+Math.imul(S,mt)|0)|0)+((8191&(n=(n=n+Math.imul(S,gt)|0)+Math.imul(k,mt)|0))<<13)|0;u=((s=s+Math.imul(k,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(W,st),n=(n=Math.imul(W,ot))+Math.imul(F,st)|0,s=Math.imul(F,ot),r=r+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,r=r+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,dt)|0)+Math.imul(_,ct)|0,s=s+Math.imul(_,dt)|0;var Bt=(u+(r=r+Math.imul(T,mt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(O,mt)|0))<<13)|0;u=((s=s+Math.imul(O,gt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,r=Math.imul(W,ht),n=(n=Math.imul(W,ut))+Math.imul(F,ht)|0,s=Math.imul(F,ut),r=r+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,dt)|0)+Math.imul(L,ct)|0,s=s+Math.imul(L,dt)|0;var Ct=(u+(r=r+Math.imul(C,mt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(_,mt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(W,ct),n=(n=Math.imul(W,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var _t=(u+(r=r+Math.imul(D,mt)|0)|0)+((8191&(n=(n=n+Math.imul(D,gt)|0)+Math.imul(L,mt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863;var Pt=(u+(r=Math.imul(W,mt))|0)+((8191&(n=(n=Math.imul(W,gt))+Math.imul(F,mt)|0))<<13)|0;return u=((s=Math.imul(F,gt))+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,h[0]=pt,h[1]=wt,h[2]=vt,h[3]=yt,h[4]=Mt,h[5]=bt,h[6]=At,h[7]=xt,h[8]=Et,h[9]=Rt,h[10]=St,h[11]=kt,h[12]=It,h[13]=Tt,h[14]=Ot,h[15]=Bt,h[16]=Ct,h[17]=_t,h[18]=Pt,0!==u&&(h[19]=u,i.length++),i};function f(t,e,i){return(new m).mulp(t,e,i)}function m(t,e){this.x=t,this.y=e}Math.imul||(d=c),n.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):i<63?c(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var r=0,n=0,s=0;s<i.length-1;s++){var o=n;n=0;for(var a=67108863&r,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=(0|t.words[s-u])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),n+=(o=(o=o+(l/67108864|0)|0)+(c>>>26)|0)>>>26,o&=67108863}i.words[s]=a,r=o,o=n}return 0!==r?i.words[s]=r:i.length--,i.strip()}(this,t,e):f(this,t,e)},m.prototype.makeRBT=function(t){for(var e=new Array(t),i=n.prototype._countBits(t)-1,r=0;r<t;r++)e[r]=this.revBin(r,i,t);return e},m.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var r=0,n=0;n<e;n++)r|=(1&t)<<e-n-1,t>>=1;return r},m.prototype.permute=function(t,e,i,r,n,s){for(var o=0;o<s;o++)r[o]=e[t[o]],n[o]=i[t[o]]},m.prototype.transform=function(t,e,i,r,n,s){this.permute(s,t,e,i,r,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,d=u,f=0;f<o;f++){var m=i[l+f],g=r[l+f],p=i[l+f+o],w=r[l+f+o],v=c*p-d*w;w=c*w+d*p,i[l+f]=m+(p=v),r[l+f]=g+w,i[l+f+o]=m-p,r[l+f+o]=g-w,f!==a&&(v=h*c-u*d,d=h*d+u*c,c=v)}},m.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),r=1&i,n=0;for(i=i/2|0;i;i>>>=1)n++;return 1<<n+1+r},m.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var r=0;r<i/2;r++){var n=t[r];t[r]=t[i-r-1],t[i-r-1]=n,n=e[r],e[r]=-e[i-r-1],e[i-r-1]=-n}},m.prototype.normalize13b=function(t,e){for(var i=0,r=0;r<e/2;r++){var n=8192*Math.round(t[2*r+1]/e)+Math.round(t[2*r]/e)+i;t[r]=67108863&n,i=n<67108864?0:n/67108864|0}return t},m.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)r[2*o]=8191&(s+=0|t[o]),r[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},m.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},m.prototype.mulp=function(t,e,i){var r=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(r),s=this.stub(r),o=new Array(r),a=new Array(r),h=new Array(r),u=new Array(r),l=new Array(r),c=new Array(r),d=i.words;d.length=r,this.convert13b(t.words,t.length,o,r),this.convert13b(e.words,e.length,u,r),this.transform(o,s,a,h,r,n),this.transform(u,s,l,c,r,n);for(var f=0;f<r;f++){var m=a[f]*l[f]-h[f]*c[f];h[f]=a[f]*c[f]+h[f]*l[f],a[f]=m}return this.conjugate(a,h,r),this.transform(a,h,d,s,r,n),this.conjugate(d,s,r),this.normalize13b(d,r),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),f(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,r=0;r<this.length;r++){var n=(0|this.words[r])*t,s=(67108863&n)+(67108863&e);e>>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var r=i%26;e[i]=(t.words[i/26|0]&1<<r)>>>r}return e}(t);if(0===e.length)return new n(1);for(var i=this,r=0;r<e.length&&0===e[r];r++,i=i.sqr());if(++r<e.length)for(var s=i.sqr();r<e.length;r++,s=s.sqr())0!==e[r]&&(i=i.mul(s));return i},n.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s;this.words[e]=(0|this.words[e])-a<<r|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this.strip()},n.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},n.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},n.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return!(this.length<=r||!(this.words[r]&1<<e))},n.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r?this:(0!==e&&r++,this.length=Math.min(r,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},n.prototype.maskn=function(t){return this.clone().imaskn(t)},n.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},n.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},n.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},n.prototype.addn=function(t){return this.clone().iaddn(t)},n.prototype.subn=function(t){return this.clone().isubn(t)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(t,e,r){var n,s;this._expand(t.length+r);var o=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+o;var a=(0|t.words[n])*e;o=((s-=67108863&a)>>26)-(a/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)o=(s=(0|this.words[n+r])+o)>>26,this.words[n+r]=67108863&s;if(0===o)return this.strip();for(i(-1===o),o=0,n=0;n<this.length;n++)o=(s=-(0|this.words[n])+o)>>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},n.prototype._wordDiv=function(t,e){var i,r=this.clone(),s=t,o=0|s.words[s.length-1];0!=(i=26-this._countBits(o))&&(s=s.ushln(i),r.iushln(i),o=0|s.words[s.length-1]);var a,h=r.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=r.clone()._ishlnsubmul(s,1,h);0===l.negative&&(r=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var d=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]);for(d=Math.min(d/o|0,67108863),r._ishlnsubmul(s,d,c);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);a&&(a.words[c]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==i&&r.iushrn(i),{div:a||null,mod:r}},n.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),n=t.andln(1),s=i.cmp(r);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},n.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(l),o.isub(c)),s.iushrn(1),o.iushrn(1);for(var m=0,g=1;0==(r.words[0]&g)&&m<26;++m,g<<=1);if(m>0)for(r.iushrn(m);m-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a),o.isub(h)):(r.isub(e),a.isub(s),h.isub(o))}return{a:a,b:h,gcd:r.iushln(u)}},n.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,o=new n(1),a=new n(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,d=1;0==(r.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(s=0===e.cmpn(1)?o:a).cmpn(0)<0&&s.iadd(t),s},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var r=0;e.isEven()&&i.isEven();r++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var n=e.cmp(i);if(n<0){var s=e;e=i,i=s}else if(0===n||0===i.cmpn(1))break;e.isub(i)}return i.iushln(r)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,this.words[o]=a&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},n.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},n.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var r=0|this.words[i],n=0|t.words[i];if(r!==n){r<n?e=-1:r>n&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new b(t)},n.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var g={k256:null,p224:null,p192:null,p25519:null};function p(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}p.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:i.ucmp(this.p);return 0===r?(i.words[0]=0,i.length=1):r>0?i.isub(this.p):i.strip(),i},p.prototype.split=function(t,e){t.iushrn(this.n,0,e)},p.prototype.imulK=function(t){return t.imul(this.k)},r(w,p),w.prototype.split=function(t,e){for(var i=4194303,r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&i,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&i)<<4|s>>>22,s=o}t.words[n-10]=s>>>=22,t.length-=0===s&&t.length>10?10:9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var r=0|t.words[i];t.words[i]=67108863&(e+=977*r),e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,p),r(y,p),r(M,p),M.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var r=19*(0|t.words[i])+e,n=67108863&r;r>>>=26,t.words[i]=n,e=r}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new v;else if("p192"===t)e=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return g[t]=e,e},b.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},b.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},b.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},b.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},b.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},b.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},b.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},b.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},b.prototype.isqr=function(t){return this.imul(t,t.clone())},b.prototype.sqr=function(t){return this.mul(t,t)},b.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new n(1)).iushrn(2);return this.pow(t,r)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);i(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),m=o;0!==f.cmp(a);){for(var g=f,p=0;0!==g.cmp(a);p++)g=g.redSqr();i(p<m);var w=this.pow(c,new n(1).iushln(m-p-1));d=d.redMul(w),c=w.redSqr(),f=f.redMul(c),m=p}return d},b.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},b.prototype.pow=function(t,e){if(e.isZero())return new n(1);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new n(1).toRed(this),i[1]=t;for(var r=2;r<i.length;r++)i[r]=this.mul(i[r-1],t);var s=i[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),r=e.length-1;r>=0;r--){for(var u=e.words[r],l=h-1;l>=0;l--){var c=u>>l&1;s!==i[0]&&(s=this.sqr(s)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===r&&0===l)&&(s=this.mul(s,i[o]),a=0,o=0)):a=0}h=26}return s},b.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},b.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new A(t)},r(A,b),A.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},A.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},A.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=i.isub(r).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},A.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var i=t.mul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=i.isub(r).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},A.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,Ot)}),Pt=Bt(function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function n(t,e,i){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var s;"object"==typeof t?t.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=Ct("buffer").Buffer}catch(t){}function o(t,e,i){for(var r=0,n=Math.min(t.length,i),s=e;s<n;s++){var o=t.charCodeAt(s)-48;r<<=4,r|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return r}function a(t,e,i,r){for(var n=0,s=Math.min(t.length,i),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=r,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}n.isBN=function(t){return t instanceof n||null!==t&&"object"==typeof t&&t.constructor.wordSize===n.wordSize&&Array.isArray(t.words)},n.max=function(t,e){return t.cmp(e)>0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)this.words[s]|=(o=t[n]|t[n-1]<<8|t[n-2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)this.words[s]|=(o=t[n]|t[n+1]<<8|t[n+2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},n.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var r,n,s=0;for(i=t.length-6,r=0;i>=e;i-=6)n=o(t,i,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,r++);i+6!==e&&(n=o(t,e,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303),this.strip()},n.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var r=0,n=1;n<=67108863;n*=e)r++;r--,n=n/e|0;for(var s=t.length-i,o=s%r,h=Math.min(s,s-o)+i,u=0,l=i;l<h;l+=r)u=a(t,l,l+r,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=a(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},n.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},n.prototype.clone=function(){var t=new n(null);return this.copy(t),t},n.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},n.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},n.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","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"],u=[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],l=[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 c(t,e,i){i.negative=e.negative^t.negative;var r=t.length+e.length|0;i.length=r,r=r-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=o/67108864|0;i.words[0]=67108863&o;for(var h=1;h<r;h++){for(var u=a>>>26,l=67108863&a,c=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=c;d++)u+=(o=(n=0|t.words[h-d|0])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o;i.words[h]=0|l,a=0|u}return 0!==a?i.words[h]=0|a:i.length--,i.strip()}n.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],c=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?h[6-c.length]+c+r:c+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var d=u[t],f=l[t];r="";var m=this.clone();for(m.negative=0;!m.isZero();){var g=m.modn(f).toString(t);r=(m=m.idivn(f)).isZero()?g+r:h[d-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},n.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16)},n.prototype.toBuffer=function(t,e){return i(void 0!==s),this.toArrayLike(s,t,e)},n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,u=new t(s),l=this.clone();if(h){for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[a]=o;for(;a<s;a++)u[a]=0}else{for(a=0;a<s-n;a++)u[a]=0;for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[s-a-1]=o}return u},n.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},n.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},n.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.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()},n.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},n.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},n.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},n.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var r=0;r<i.length;r++)this.words[r]=e.words[r]^i.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this.strip()},n.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},n.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},n.prototype.iadd=function(t){var e,i,r;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?(i=this,r=t):(i=t,r=this);for(var n=0,s=0;s<r.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+(0|r.words[s])+n),n=e>>>26;for(;0!==n&&s<i.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+n),n=e>>>26;if(this.length=i.length,0!==n)this.words[this.length]=n,this.length++;else if(i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this},n.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)},n.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 i,r,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(i=this,r=t):(i=t,r=this);for(var s=0,o=0;o<r.length;o++)s=(e=(0|i.words[o])-(0|r.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<i.length;o++)s=(e=(0|i.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<i.length&&i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this.length=Math.max(this.length,o),i!==this&&(this.negative=1),this.strip()},n.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,i){var r,n,s,o=t.words,a=e.words,h=i.words,u=0,l=0|o[0],c=8191&l,d=l>>>13,f=0|o[1],m=8191&f,g=f>>>13,p=0|o[2],w=8191&p,v=p>>>13,y=0|o[3],M=8191&y,b=y>>>13,A=0|o[4],x=8191&A,E=A>>>13,R=0|o[5],S=8191&R,k=R>>>13,I=0|o[6],T=8191&I,O=I>>>13,B=0|o[7],C=8191&B,_=B>>>13,P=0|o[8],D=8191&P,L=P>>>13,N=0|o[9],W=8191&N,F=N>>>13,U=0|a[0],q=8191&U,$=U>>>13,j=0|a[1],G=8191&j,z=j>>>13,H=0|a[2],Z=8191&H,V=H>>>13,J=0|a[3],K=8191&J,X=J>>>13,Q=0|a[4],Y=8191&Q,tt=Q>>>13,et=0|a[5],it=8191&et,rt=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,dt=lt>>>13,ft=0|a[9],mt=8191&ft,gt=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var pt=(u+(r=Math.imul(c,q))|0)+((8191&(n=(n=Math.imul(c,$))+Math.imul(d,q)|0))<<13)|0;u=((s=Math.imul(d,$))+(n>>>13)|0)+(pt>>>26)|0,pt&=67108863,r=Math.imul(m,q),n=(n=Math.imul(m,$))+Math.imul(g,q)|0,s=Math.imul(g,$);var wt=(u+(r=r+Math.imul(c,G)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(d,G)|0))<<13)|0;u=((s=s+Math.imul(d,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(w,q),n=(n=Math.imul(w,$))+Math.imul(v,q)|0,s=Math.imul(v,$),r=r+Math.imul(m,G)|0,n=(n=n+Math.imul(m,z)|0)+Math.imul(g,G)|0,s=s+Math.imul(g,z)|0;var vt=(u+(r=r+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,Z)|0))<<13)|0;u=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(M,q),n=(n=Math.imul(M,$))+Math.imul(b,q)|0,s=Math.imul(b,$),r=r+Math.imul(w,G)|0,n=(n=n+Math.imul(w,z)|0)+Math.imul(v,G)|0,s=s+Math.imul(v,z)|0,r=r+Math.imul(m,Z)|0,n=(n=n+Math.imul(m,V)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,V)|0;var yt=(u+(r=r+Math.imul(c,K)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,K)|0))<<13)|0;u=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(x,q),n=(n=Math.imul(x,$))+Math.imul(E,q)|0,s=Math.imul(E,$),r=r+Math.imul(M,G)|0,n=(n=n+Math.imul(M,z)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,z)|0,r=r+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,V)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,V)|0,r=r+Math.imul(m,K)|0,n=(n=n+Math.imul(m,X)|0)+Math.imul(g,K)|0,s=s+Math.imul(g,X)|0;var Mt=(u+(r=r+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(S,q),n=(n=Math.imul(S,$))+Math.imul(k,q)|0,s=Math.imul(k,$),r=r+Math.imul(x,G)|0,n=(n=n+Math.imul(x,z)|0)+Math.imul(E,G)|0,s=s+Math.imul(E,z)|0,r=r+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,V)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,V)|0,r=r+Math.imul(w,K)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(v,K)|0,s=s+Math.imul(v,X)|0,r=r+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,tt)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,tt)|0;var bt=(u+(r=r+Math.imul(c,it)|0)|0)+((8191&(n=(n=n+Math.imul(c,rt)|0)+Math.imul(d,it)|0))<<13)|0;u=((s=s+Math.imul(d,rt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(T,q),n=(n=Math.imul(T,$))+Math.imul(O,q)|0,s=Math.imul(O,$),r=r+Math.imul(S,G)|0,n=(n=n+Math.imul(S,z)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,z)|0,r=r+Math.imul(x,Z)|0,n=(n=n+Math.imul(x,V)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,V)|0,r=r+Math.imul(M,K)|0,n=(n=n+Math.imul(M,X)|0)+Math.imul(b,K)|0,s=s+Math.imul(b,X)|0,r=r+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,tt)|0,r=r+Math.imul(m,it)|0,n=(n=n+Math.imul(m,rt)|0)+Math.imul(g,it)|0,s=s+Math.imul(g,rt)|0;var At=(u+(r=r+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,q),n=(n=Math.imul(C,$))+Math.imul(_,q)|0,s=Math.imul(_,$),r=r+Math.imul(T,G)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(O,G)|0,s=s+Math.imul(O,z)|0,r=r+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,V)|0,r=r+Math.imul(x,K)|0,n=(n=n+Math.imul(x,X)|0)+Math.imul(E,K)|0,s=s+Math.imul(E,X)|0,r=r+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,tt)|0,r=r+Math.imul(w,it)|0,n=(n=n+Math.imul(w,rt)|0)+Math.imul(v,it)|0,s=s+Math.imul(v,rt)|0,r=r+Math.imul(m,st)|0,n=(n=n+Math.imul(m,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var xt=(u+(r=r+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(d,ht)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(D,q),n=(n=Math.imul(D,$))+Math.imul(L,q)|0,s=Math.imul(L,$),r=r+Math.imul(C,G)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(_,G)|0,s=s+Math.imul(_,z)|0,r=r+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,V)|0,r=r+Math.imul(S,K)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(k,K)|0,s=s+Math.imul(k,X)|0,r=r+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,r=r+Math.imul(M,it)|0,n=(n=n+Math.imul(M,rt)|0)+Math.imul(b,it)|0,s=s+Math.imul(b,rt)|0,r=r+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,r=r+Math.imul(m,ht)|0,n=(n=n+Math.imul(m,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var Et=(u+(r=r+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(W,q),n=(n=Math.imul(W,$))+Math.imul(F,q)|0,s=Math.imul(F,$),r=r+Math.imul(D,G)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,z)|0,r=r+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,V)|0,r=r+Math.imul(T,K)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(O,K)|0,s=s+Math.imul(O,X)|0,r=r+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,r=r+Math.imul(x,it)|0,n=(n=n+Math.imul(x,rt)|0)+Math.imul(E,it)|0,s=s+Math.imul(E,rt)|0,r=r+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,r=r+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,r=r+Math.imul(m,ct)|0,n=(n=n+Math.imul(m,dt)|0)+Math.imul(g,ct)|0,s=s+Math.imul(g,dt)|0;var Rt=(u+(r=r+Math.imul(c,mt)|0)|0)+((8191&(n=(n=n+Math.imul(c,gt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,r=Math.imul(W,G),n=(n=Math.imul(W,z))+Math.imul(F,G)|0,s=Math.imul(F,z),r=r+Math.imul(D,Z)|0,n=(n=n+Math.imul(D,V)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,V)|0,r=r+Math.imul(C,K)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(_,K)|0,s=s+Math.imul(_,X)|0,r=r+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,r=r+Math.imul(S,it)|0,n=(n=n+Math.imul(S,rt)|0)+Math.imul(k,it)|0,s=s+Math.imul(k,rt)|0,r=r+Math.imul(x,st)|0,n=(n=n+Math.imul(x,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,r=r+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ut)|0)+Math.imul(b,ht)|0,s=s+Math.imul(b,ut)|0,r=r+Math.imul(w,ct)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(v,ct)|0,s=s+Math.imul(v,dt)|0;var St=(u+(r=r+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,gt)|0)+Math.imul(g,mt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(W,Z),n=(n=Math.imul(W,V))+Math.imul(F,Z)|0,s=Math.imul(F,V),r=r+Math.imul(D,K)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,X)|0,r=r+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,tt)|0,r=r+Math.imul(T,it)|0,n=(n=n+Math.imul(T,rt)|0)+Math.imul(O,it)|0,s=s+Math.imul(O,rt)|0,r=r+Math.imul(S,st)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,r=r+Math.imul(x,ht)|0,n=(n=n+Math.imul(x,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,r=r+Math.imul(M,ct)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(b,ct)|0,s=s+Math.imul(b,dt)|0;var kt=(u+(r=r+Math.imul(w,mt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(v,mt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(W,K),n=(n=Math.imul(W,X))+Math.imul(F,K)|0,s=Math.imul(F,X),r=r+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,tt)|0,r=r+Math.imul(C,it)|0,n=(n=n+Math.imul(C,rt)|0)+Math.imul(_,it)|0,s=s+Math.imul(_,rt)|0,r=r+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,r=r+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,s=s+Math.imul(k,ut)|0,r=r+Math.imul(x,ct)|0,n=(n=n+Math.imul(x,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var It=(u+(r=r+Math.imul(M,mt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(b,mt)|0))<<13)|0;u=((s=s+Math.imul(b,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(W,Y),n=(n=Math.imul(W,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),r=r+Math.imul(D,it)|0,n=(n=n+Math.imul(D,rt)|0)+Math.imul(L,it)|0,s=s+Math.imul(L,rt)|0,r=r+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,r=r+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,r=r+Math.imul(S,ct)|0,n=(n=n+Math.imul(S,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var Tt=(u+(r=r+Math.imul(x,mt)|0)|0)+((8191&(n=(n=n+Math.imul(x,gt)|0)+Math.imul(E,mt)|0))<<13)|0;u=((s=s+Math.imul(E,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(W,it),n=(n=Math.imul(W,rt))+Math.imul(F,it)|0,s=Math.imul(F,rt),r=r+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,r=r+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,r=r+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Ot=(u+(r=r+Math.imul(S,mt)|0)|0)+((8191&(n=(n=n+Math.imul(S,gt)|0)+Math.imul(k,mt)|0))<<13)|0;u=((s=s+Math.imul(k,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(W,st),n=(n=Math.imul(W,ot))+Math.imul(F,st)|0,s=Math.imul(F,ot),r=r+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,r=r+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,dt)|0)+Math.imul(_,ct)|0,s=s+Math.imul(_,dt)|0;var Bt=(u+(r=r+Math.imul(T,mt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(O,mt)|0))<<13)|0;u=((s=s+Math.imul(O,gt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,r=Math.imul(W,ht),n=(n=Math.imul(W,ut))+Math.imul(F,ht)|0,s=Math.imul(F,ut),r=r+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,dt)|0)+Math.imul(L,ct)|0,s=s+Math.imul(L,dt)|0;var Ct=(u+(r=r+Math.imul(C,mt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(_,mt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(W,ct),n=(n=Math.imul(W,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var _t=(u+(r=r+Math.imul(D,mt)|0)|0)+((8191&(n=(n=n+Math.imul(D,gt)|0)+Math.imul(L,mt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863;var Pt=(u+(r=Math.imul(W,mt))|0)+((8191&(n=(n=Math.imul(W,gt))+Math.imul(F,mt)|0))<<13)|0;return u=((s=Math.imul(F,gt))+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,h[0]=pt,h[1]=wt,h[2]=vt,h[3]=yt,h[4]=Mt,h[5]=bt,h[6]=At,h[7]=xt,h[8]=Et,h[9]=Rt,h[10]=St,h[11]=kt,h[12]=It,h[13]=Tt,h[14]=Ot,h[15]=Bt,h[16]=Ct,h[17]=_t,h[18]=Pt,0!==u&&(h[19]=u,i.length++),i};function f(t,e,i){return(new m).mulp(t,e,i)}function m(t,e){this.x=t,this.y=e}Math.imul||(d=c),n.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):i<63?c(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var r=0,n=0,s=0;s<i.length-1;s++){var o=n;n=0;for(var a=67108863&r,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=(0|t.words[s-u])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),n+=(o=(o=o+(l/67108864|0)|0)+(c>>>26)|0)>>>26,o&=67108863}i.words[s]=a,r=o,o=n}return 0!==r?i.words[s]=r:i.length--,i.strip()}(this,t,e):f(this,t,e)},m.prototype.makeRBT=function(t){for(var e=new Array(t),i=n.prototype._countBits(t)-1,r=0;r<t;r++)e[r]=this.revBin(r,i,t);return e},m.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var r=0,n=0;n<e;n++)r|=(1&t)<<e-n-1,t>>=1;return r},m.prototype.permute=function(t,e,i,r,n,s){for(var o=0;o<s;o++)r[o]=e[t[o]],n[o]=i[t[o]]},m.prototype.transform=function(t,e,i,r,n,s){this.permute(s,t,e,i,r,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,d=u,f=0;f<o;f++){var m=i[l+f],g=r[l+f],p=i[l+f+o],w=r[l+f+o],v=c*p-d*w;w=c*w+d*p,i[l+f]=m+(p=v),r[l+f]=g+w,i[l+f+o]=m-p,r[l+f+o]=g-w,f!==a&&(v=h*c-u*d,d=h*d+u*c,c=v)}},m.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),r=1&i,n=0;for(i=i/2|0;i;i>>>=1)n++;return 1<<n+1+r},m.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var r=0;r<i/2;r++){var n=t[r];t[r]=t[i-r-1],t[i-r-1]=n,n=e[r],e[r]=-e[i-r-1],e[i-r-1]=-n}},m.prototype.normalize13b=function(t,e){for(var i=0,r=0;r<e/2;r++){var n=8192*Math.round(t[2*r+1]/e)+Math.round(t[2*r]/e)+i;t[r]=67108863&n,i=n<67108864?0:n/67108864|0}return t},m.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)r[2*o]=8191&(s+=0|t[o]),r[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},m.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},m.prototype.mulp=function(t,e,i){var r=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(r),s=this.stub(r),o=new Array(r),a=new Array(r),h=new Array(r),u=new Array(r),l=new Array(r),c=new Array(r),d=i.words;d.length=r,this.convert13b(t.words,t.length,o,r),this.convert13b(e.words,e.length,u,r),this.transform(o,s,a,h,r,n),this.transform(u,s,l,c,r,n);for(var f=0;f<r;f++){var m=a[f]*l[f]-h[f]*c[f];h[f]=a[f]*c[f]+h[f]*l[f],a[f]=m}return this.conjugate(a,h,r),this.transform(a,h,d,s,r,n),this.conjugate(d,s,r),this.normalize13b(d,r),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),f(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,r=0;r<this.length;r++){var n=(0|this.words[r])*t,s=(67108863&n)+(67108863&e);e>>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var r=i%26;e[i]=(t.words[i/26|0]&1<<r)>>>r}return e}(t);if(0===e.length)return new n(1);for(var i=this,r=0;r<e.length&&0===e[r];r++,i=i.sqr());if(++r<e.length)for(var s=i.sqr();r<e.length;r++,s=s.sqr())0!==e[r]&&(i=i.mul(s));return i},n.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s;this.words[e]=(0|this.words[e])-a<<r|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this.strip()},n.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},n.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},n.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return!(this.length<=r||!(this.words[r]&1<<e))},n.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r?this:(0!==e&&r++,this.length=Math.min(r,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},n.prototype.maskn=function(t){return this.clone().imaskn(t)},n.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},n.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},n.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},n.prototype.addn=function(t){return this.clone().iaddn(t)},n.prototype.subn=function(t){return this.clone().isubn(t)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(t,e,r){var n,s;this._expand(t.length+r);var o=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+o;var a=(0|t.words[n])*e;o=((s-=67108863&a)>>26)-(a/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)o=(s=(0|this.words[n+r])+o)>>26,this.words[n+r]=67108863&s;if(0===o)return this.strip();for(i(-1===o),o=0,n=0;n<this.length;n++)o=(s=-(0|this.words[n])+o)>>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},n.prototype._wordDiv=function(t,e){var i,r=this.clone(),s=t,o=0|s.words[s.length-1];0!=(i=26-this._countBits(o))&&(s=s.ushln(i),r.iushln(i),o=0|s.words[s.length-1]);var a,h=r.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=r.clone()._ishlnsubmul(s,1,h);0===l.negative&&(r=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var d=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]);for(d=Math.min(d/o|0,67108863),r._ishlnsubmul(s,d,c);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);a&&(a.words[c]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==i&&r.iushrn(i),{div:a||null,mod:r}},n.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),n=t.andln(1),s=i.cmp(r);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},n.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(l),o.isub(c)),s.iushrn(1),o.iushrn(1);for(var m=0,g=1;0==(r.words[0]&g)&&m<26;++m,g<<=1);if(m>0)for(r.iushrn(m);m-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a),o.isub(h)):(r.isub(e),a.isub(s),h.isub(o))}return{a:a,b:h,gcd:r.iushln(u)}},n.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,o=new n(1),a=new n(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,d=1;0==(r.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(s=0===e.cmpn(1)?o:a).cmpn(0)<0&&s.iadd(t),s},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var r=0;e.isEven()&&i.isEven();r++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var n=e.cmp(i);if(n<0){var s=e;e=i,i=s}else if(0===n||0===i.cmpn(1))break;e.isub(i)}return i.iushln(r)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,this.words[o]=a&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},n.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},n.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var r=0|this.words[i],n=0|t.words[i];if(r!==n){r<n?e=-1:r>n&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new b(t)},n.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var g={k256:null,p224:null,p192:null,p25519:null};function p(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}p.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:i.ucmp(this.p);return 0===r?(i.words[0]=0,i.length=1):r>0?i.isub(this.p):i.strip(),i},p.prototype.split=function(t,e){t.iushrn(this.n,0,e)},p.prototype.imulK=function(t){return t.imul(this.k)},r(w,p),w.prototype.split=function(t,e){for(var i=4194303,r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&i,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&i)<<4|s>>>22,s=o}t.words[n-10]=s>>>=22,t.length-=0===s&&t.length>10?10:9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var r=0|t.words[i];t.words[i]=67108863&(e+=977*r),e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,p),r(y,p),r(M,p),M.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var r=19*(0|t.words[i])+e,n=67108863&r;r>>>=26,t.words[i]=n,e=r}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new v;else if("p192"===t)e=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return g[t]=e,e},b.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},b.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},b.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},b.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},b.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},b.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},b.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},b.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},b.prototype.isqr=function(t){return this.imul(t,t.clone())},b.prototype.sqr=function(t){return this.mul(t,t)},b.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new n(1)).iushrn(2);return this.pow(t,r)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);i(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),m=o;0!==f.cmp(a);){for(var g=f,p=0;0!==g.cmp(a);p++)g=g.redSqr();i(p<m);var w=this.pow(c,new n(1).iushln(m-p-1));d=d.redMul(w),c=w.redSqr(),f=f.redMul(c),m=p}return d},b.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},b.prototype.pow=function(t,e){if(e.isZero())return new n(1);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new n(1).toRed(this),i[1]=t;for(var r=2;r<i.length;r++)i[r]=this.mul(i[r-1],t);var s=i[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),r=e.length-1;r>=0;r--){for(var u=e.words[r],l=h-1;l>=0;l--){var c=u>>l&1;s!==i[0]&&(s=this.sqr(s)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===r&&0===l)&&(s=this.mul(s,i[o]),a=0,o=0)):a=0}h=26}return s},b.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},b.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new A(t)},r(A,b),A.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},A.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},A.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=i.isub(r).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},A.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var i=t.mul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=i.isub(r).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},A.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,Ot)}),Dt=function(t){return"string"!=typeof t?t:function(t){if("string"!=typeof t)throw new Error("[is-hex-prefixed] value must be type 'string', is currently type "+typeof t+", while checking isHexPrefixed.");return"0x"===t.slice(0,2)}(t)?t.slice(2):t},Lt=function(t){if("string"==typeof t||"number"==typeof t){var e=new Pt(1),i=String(t).toLowerCase().trim(),r="0x"===i.substr(0,2)||"-0x"===i.substr(0,3),n=Dt(i);if("-"===n.substr(0,1)&&(n=Dt(n.slice(1)),e=new Pt(-1,10)),!(n=""===n?"0":n).match(/^-?[0-9]+$/)&&n.match(/^[0-9A-Fa-f]+$/)||n.match(/^[a-fA-F]+$/)||!0===r&&n.match(/^[0-9A-Fa-f]+$/))return new Pt(n,16).mul(e);if((n.match(/^-?[0-9]+$/)||""===n)&&!1===r)return new Pt(n,10).mul(e)}else if("object"==typeof t&&t.toString&&!t.pop&&!t.push&&t.toString(10).match(/^-?[0-9]+$/)&&(t.mul||t.dividedToIntegerBy))return new Pt(t.toString(10),10);throw new Error("[number-to-bn] while converting number "+JSON.stringify(t)+" to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.")},Nt=new _t(0),Wt=new _t(-1),Ft={noether:"0",wei:"1",kwei:"1000",Kwei:"1000",babbage:"1000",femtoether:"1000",mwei:"1000000",Mwei:"1000000",lovelace:"1000000",picoether:"1000000",gwei:"1000000000",Gwei:"1000000000",shannon:"1000000000",nanoether:"1000000000",nano:"1000000000",szabo:"1000000000000",microether:"1000000000000",micro:"1000000000000",finney:"1000000000000000",milliether:"1000000000000000",milli:"1000000000000000",ether:"1000000000000000000",kether:"1000000000000000000000",grand:"1000000000000000000000",mether:"1000000000000000000000000",gether:"1000000000000000000000000000",tether:"1000000000000000000000000000000"};function Ut(t){var e=t?t.toLowerCase():"ether",i=Ft[e];if("string"!=typeof i)throw new Error("[ethjs-unit] the unit provided "+t+" doesn't exists, please use the one of the following units "+JSON.stringify(Ft,null,2));return new _t(i,10)}function qt(t){if("string"==typeof t){if(!t.match(/^-?[0-9.]+$/))throw new Error("while converting number to string, invalid number value '"+t+"', should be a number matching (^-?[0-9.]+).");return t}if("number"==typeof t)return String(t);if("object"==typeof t&&t.toString&&(t.toTwos||t.dividedToIntegerBy))return t.toPrecision?String(t.toPrecision()):t.toString(10);throw new Error("while converting number to string, invalid number value '"+t+"' type "+typeof t+".")}var $t={unitMap:Ft,numberToString:qt,getValueOfUnit:Ut,fromWei:function(t,e,i){var r=Lt(t),n=r.lt(Nt),s=Ut(e),o=Ft[e].length-1||1,a=i||{};n&&(r=r.mul(Wt));for(var h=r.mod(s).toString(10);h.length<o;)h="0"+h;a.pad||(h=h.match(/^([0-9]*[1-9]|0)(0*)/)[1]);var u=r.div(s).toString(10);a.commify&&(u=u.replace(/\B(?=(\d{3})+(?!\d))/g,","));var l=u+("0"==h?"":"."+h);return n&&(l="-"+l),l},toWei:function(t,e){var i=qt(t),r=Ut(e),n=Ft[e].length-1||1,s="-"===i.substring(0,1);if(s&&(i=i.substring(1)),"."===i)throw new Error("[ethjs-unit] while converting number "+t+" to wei, invalid value");var o=i.split(".");if(o.length>2)throw new Error("[ethjs-unit] while converting number "+t+" to wei, too many decimal points");var a=o[0],h=o[1];if(a||(a="0"),h||(h="0"),h.length>n)throw new Error("[ethjs-unit] while converting number "+t+" to wei, too many decimal places");for(;h.length<n;)h+="0";a=new _t(a),h=new _t(h);var u=a.mul(r).add(h);return s&&(u=u.mul(Wt)),new _t(u.toString(10),10)}},jt=Bt(function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function n(t,e,i){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var s;"object"==typeof t?t.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=I.default.Buffer}catch(t){}function o(t,e,i){for(var r=0,n=Math.min(t.length,i),s=e;s<n;s++){var o=t.charCodeAt(s)-48;r<<=4,r|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return r}function a(t,e,i,r){for(var n=0,s=Math.min(t.length,i),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=r,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}n.isBN=function(t){return t instanceof n||null!==t&&"object"==typeof t&&t.constructor.wordSize===n.wordSize&&Array.isArray(t.words)},n.max=function(t,e){return t.cmp(e)>0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)this.words[s]|=(o=t[n]|t[n-1]<<8|t[n-2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)this.words[s]|=(o=t[n]|t[n+1]<<8|t[n+2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},n.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var r,n,s=0;for(i=t.length-6,r=0;i>=e;i-=6)n=o(t,i,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,r++);i+6!==e&&(n=o(t,e,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303),this.strip()},n.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var r=0,n=1;n<=67108863;n*=e)r++;r--,n=n/e|0;for(var s=t.length-i,o=s%r,h=Math.min(s,s-o)+i,u=0,l=i;l<h;l+=r)u=a(t,l,l+r,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=a(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},n.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},n.prototype.clone=function(){var t=new n(null);return this.copy(t),t},n.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},n.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},n.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","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"],u=[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],l=[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 c(t,e,i){i.negative=e.negative^t.negative;var r=t.length+e.length|0;i.length=r,r=r-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=o/67108864|0;i.words[0]=67108863&o;for(var h=1;h<r;h++){for(var u=a>>>26,l=67108863&a,c=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=c;d++)u+=(o=(n=0|t.words[h-d|0])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o;i.words[h]=0|l,a=0|u}return 0!==a?i.words[h]=0|a:i.length--,i.strip()}n.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],c=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?h[6-c.length]+c+r:c+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var d=u[t],f=l[t];r="";var m=this.clone();for(m.negative=0;!m.isZero();){var g=m.modn(f).toString(t);r=(m=m.idivn(f)).isZero()?g+r:h[d-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},n.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16)},n.prototype.toBuffer=function(t,e){return i(void 0!==s),this.toArrayLike(s,t,e)},n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,u=new t(s),l=this.clone();if(h){for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[a]=o;for(;a<s;a++)u[a]=0}else{for(a=0;a<s-n;a++)u[a]=0;for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[s-a-1]=o}return u},n.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},n.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},n.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.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()},n.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},n.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},n.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},n.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var r=0;r<i.length;r++)this.words[r]=e.words[r]^i.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this.strip()},n.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},n.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},n.prototype.iadd=function(t){var e,i,r;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?(i=this,r=t):(i=t,r=this);for(var n=0,s=0;s<r.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+(0|r.words[s])+n),n=e>>>26;for(;0!==n&&s<i.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+n),n=e>>>26;if(this.length=i.length,0!==n)this.words[this.length]=n,this.length++;else if(i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this},n.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)},n.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 i,r,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(i=this,r=t):(i=t,r=this);for(var s=0,o=0;o<r.length;o++)s=(e=(0|i.words[o])-(0|r.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<i.length;o++)s=(e=(0|i.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<i.length&&i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this.length=Math.max(this.length,o),i!==this&&(this.negative=1),this.strip()},n.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,i){var r,n,s,o=t.words,a=e.words,h=i.words,u=0,l=0|o[0],c=8191&l,d=l>>>13,f=0|o[1],m=8191&f,g=f>>>13,p=0|o[2],w=8191&p,v=p>>>13,y=0|o[3],M=8191&y,b=y>>>13,A=0|o[4],x=8191&A,E=A>>>13,R=0|o[5],S=8191&R,k=R>>>13,I=0|o[6],T=8191&I,O=I>>>13,B=0|o[7],C=8191&B,_=B>>>13,P=0|o[8],D=8191&P,L=P>>>13,N=0|o[9],W=8191&N,F=N>>>13,U=0|a[0],q=8191&U,$=U>>>13,j=0|a[1],G=8191&j,z=j>>>13,H=0|a[2],Z=8191&H,V=H>>>13,J=0|a[3],K=8191&J,X=J>>>13,Q=0|a[4],Y=8191&Q,tt=Q>>>13,et=0|a[5],it=8191&et,rt=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,dt=lt>>>13,ft=0|a[9],mt=8191&ft,gt=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var pt=(u+(r=Math.imul(c,q))|0)+((8191&(n=(n=Math.imul(c,$))+Math.imul(d,q)|0))<<13)|0;u=((s=Math.imul(d,$))+(n>>>13)|0)+(pt>>>26)|0,pt&=67108863,r=Math.imul(m,q),n=(n=Math.imul(m,$))+Math.imul(g,q)|0,s=Math.imul(g,$);var wt=(u+(r=r+Math.imul(c,G)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(d,G)|0))<<13)|0;u=((s=s+Math.imul(d,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(w,q),n=(n=Math.imul(w,$))+Math.imul(v,q)|0,s=Math.imul(v,$),r=r+Math.imul(m,G)|0,n=(n=n+Math.imul(m,z)|0)+Math.imul(g,G)|0,s=s+Math.imul(g,z)|0;var vt=(u+(r=r+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,Z)|0))<<13)|0;u=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(M,q),n=(n=Math.imul(M,$))+Math.imul(b,q)|0,s=Math.imul(b,$),r=r+Math.imul(w,G)|0,n=(n=n+Math.imul(w,z)|0)+Math.imul(v,G)|0,s=s+Math.imul(v,z)|0,r=r+Math.imul(m,Z)|0,n=(n=n+Math.imul(m,V)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,V)|0;var yt=(u+(r=r+Math.imul(c,K)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,K)|0))<<13)|0;u=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(x,q),n=(n=Math.imul(x,$))+Math.imul(E,q)|0,s=Math.imul(E,$),r=r+Math.imul(M,G)|0,n=(n=n+Math.imul(M,z)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,z)|0,r=r+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,V)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,V)|0,r=r+Math.imul(m,K)|0,n=(n=n+Math.imul(m,X)|0)+Math.imul(g,K)|0,s=s+Math.imul(g,X)|0;var Mt=(u+(r=r+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(S,q),n=(n=Math.imul(S,$))+Math.imul(k,q)|0,s=Math.imul(k,$),r=r+Math.imul(x,G)|0,n=(n=n+Math.imul(x,z)|0)+Math.imul(E,G)|0,s=s+Math.imul(E,z)|0,r=r+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,V)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,V)|0,r=r+Math.imul(w,K)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(v,K)|0,s=s+Math.imul(v,X)|0,r=r+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,tt)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,tt)|0;var bt=(u+(r=r+Math.imul(c,it)|0)|0)+((8191&(n=(n=n+Math.imul(c,rt)|0)+Math.imul(d,it)|0))<<13)|0;u=((s=s+Math.imul(d,rt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(T,q),n=(n=Math.imul(T,$))+Math.imul(O,q)|0,s=Math.imul(O,$),r=r+Math.imul(S,G)|0,n=(n=n+Math.imul(S,z)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,z)|0,r=r+Math.imul(x,Z)|0,n=(n=n+Math.imul(x,V)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,V)|0,r=r+Math.imul(M,K)|0,n=(n=n+Math.imul(M,X)|0)+Math.imul(b,K)|0,s=s+Math.imul(b,X)|0,r=r+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,tt)|0,r=r+Math.imul(m,it)|0,n=(n=n+Math.imul(m,rt)|0)+Math.imul(g,it)|0,s=s+Math.imul(g,rt)|0;var At=(u+(r=r+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,q),n=(n=Math.imul(C,$))+Math.imul(_,q)|0,s=Math.imul(_,$),r=r+Math.imul(T,G)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(O,G)|0,s=s+Math.imul(O,z)|0,r=r+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,V)|0,r=r+Math.imul(x,K)|0,n=(n=n+Math.imul(x,X)|0)+Math.imul(E,K)|0,s=s+Math.imul(E,X)|0,r=r+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,tt)|0,r=r+Math.imul(w,it)|0,n=(n=n+Math.imul(w,rt)|0)+Math.imul(v,it)|0,s=s+Math.imul(v,rt)|0,r=r+Math.imul(m,st)|0,n=(n=n+Math.imul(m,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var xt=(u+(r=r+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(d,ht)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(D,q),n=(n=Math.imul(D,$))+Math.imul(L,q)|0,s=Math.imul(L,$),r=r+Math.imul(C,G)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(_,G)|0,s=s+Math.imul(_,z)|0,r=r+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,V)|0,r=r+Math.imul(S,K)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(k,K)|0,s=s+Math.imul(k,X)|0,r=r+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,r=r+Math.imul(M,it)|0,n=(n=n+Math.imul(M,rt)|0)+Math.imul(b,it)|0,s=s+Math.imul(b,rt)|0,r=r+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,r=r+Math.imul(m,ht)|0,n=(n=n+Math.imul(m,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var Et=(u+(r=r+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(W,q),n=(n=Math.imul(W,$))+Math.imul(F,q)|0,s=Math.imul(F,$),r=r+Math.imul(D,G)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,z)|0,r=r+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,V)|0,r=r+Math.imul(T,K)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(O,K)|0,s=s+Math.imul(O,X)|0,r=r+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,r=r+Math.imul(x,it)|0,n=(n=n+Math.imul(x,rt)|0)+Math.imul(E,it)|0,s=s+Math.imul(E,rt)|0,r=r+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,r=r+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,r=r+Math.imul(m,ct)|0,n=(n=n+Math.imul(m,dt)|0)+Math.imul(g,ct)|0,s=s+Math.imul(g,dt)|0;var Rt=(u+(r=r+Math.imul(c,mt)|0)|0)+((8191&(n=(n=n+Math.imul(c,gt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,r=Math.imul(W,G),n=(n=Math.imul(W,z))+Math.imul(F,G)|0,s=Math.imul(F,z),r=r+Math.imul(D,Z)|0,n=(n=n+Math.imul(D,V)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,V)|0,r=r+Math.imul(C,K)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(_,K)|0,s=s+Math.imul(_,X)|0,r=r+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,r=r+Math.imul(S,it)|0,n=(n=n+Math.imul(S,rt)|0)+Math.imul(k,it)|0,s=s+Math.imul(k,rt)|0,r=r+Math.imul(x,st)|0,n=(n=n+Math.imul(x,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,r=r+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ut)|0)+Math.imul(b,ht)|0,s=s+Math.imul(b,ut)|0,r=r+Math.imul(w,ct)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(v,ct)|0,s=s+Math.imul(v,dt)|0;var St=(u+(r=r+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,gt)|0)+Math.imul(g,mt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(W,Z),n=(n=Math.imul(W,V))+Math.imul(F,Z)|0,s=Math.imul(F,V),r=r+Math.imul(D,K)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,X)|0,r=r+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,tt)|0,r=r+Math.imul(T,it)|0,n=(n=n+Math.imul(T,rt)|0)+Math.imul(O,it)|0,s=s+Math.imul(O,rt)|0,r=r+Math.imul(S,st)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,r=r+Math.imul(x,ht)|0,n=(n=n+Math.imul(x,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,r=r+Math.imul(M,ct)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(b,ct)|0,s=s+Math.imul(b,dt)|0;var kt=(u+(r=r+Math.imul(w,mt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(v,mt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(W,K),n=(n=Math.imul(W,X))+Math.imul(F,K)|0,s=Math.imul(F,X),r=r+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,tt)|0,r=r+Math.imul(C,it)|0,n=(n=n+Math.imul(C,rt)|0)+Math.imul(_,it)|0,s=s+Math.imul(_,rt)|0,r=r+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,r=r+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,s=s+Math.imul(k,ut)|0,r=r+Math.imul(x,ct)|0,n=(n=n+Math.imul(x,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var It=(u+(r=r+Math.imul(M,mt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(b,mt)|0))<<13)|0;u=((s=s+Math.imul(b,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(W,Y),n=(n=Math.imul(W,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),r=r+Math.imul(D,it)|0,n=(n=n+Math.imul(D,rt)|0)+Math.imul(L,it)|0,s=s+Math.imul(L,rt)|0,r=r+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,r=r+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,r=r+Math.imul(S,ct)|0,n=(n=n+Math.imul(S,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var Tt=(u+(r=r+Math.imul(x,mt)|0)|0)+((8191&(n=(n=n+Math.imul(x,gt)|0)+Math.imul(E,mt)|0))<<13)|0;u=((s=s+Math.imul(E,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(W,it),n=(n=Math.imul(W,rt))+Math.imul(F,it)|0,s=Math.imul(F,rt),r=r+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,r=r+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,r=r+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Ot=(u+(r=r+Math.imul(S,mt)|0)|0)+((8191&(n=(n=n+Math.imul(S,gt)|0)+Math.imul(k,mt)|0))<<13)|0;u=((s=s+Math.imul(k,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(W,st),n=(n=Math.imul(W,ot))+Math.imul(F,st)|0,s=Math.imul(F,ot),r=r+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,r=r+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,dt)|0)+Math.imul(_,ct)|0,s=s+Math.imul(_,dt)|0;var Bt=(u+(r=r+Math.imul(T,mt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(O,mt)|0))<<13)|0;u=((s=s+Math.imul(O,gt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,r=Math.imul(W,ht),n=(n=Math.imul(W,ut))+Math.imul(F,ht)|0,s=Math.imul(F,ut),r=r+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,dt)|0)+Math.imul(L,ct)|0,s=s+Math.imul(L,dt)|0;var Ct=(u+(r=r+Math.imul(C,mt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(_,mt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(W,ct),n=(n=Math.imul(W,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var _t=(u+(r=r+Math.imul(D,mt)|0)|0)+((8191&(n=(n=n+Math.imul(D,gt)|0)+Math.imul(L,mt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863;var Pt=(u+(r=Math.imul(W,mt))|0)+((8191&(n=(n=Math.imul(W,gt))+Math.imul(F,mt)|0))<<13)|0;return u=((s=Math.imul(F,gt))+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,h[0]=pt,h[1]=wt,h[2]=vt,h[3]=yt,h[4]=Mt,h[5]=bt,h[6]=At,h[7]=xt,h[8]=Et,h[9]=Rt,h[10]=St,h[11]=kt,h[12]=It,h[13]=Tt,h[14]=Ot,h[15]=Bt,h[16]=Ct,h[17]=_t,h[18]=Pt,0!==u&&(h[19]=u,i.length++),i};function f(t,e,i){return(new m).mulp(t,e,i)}function m(t,e){this.x=t,this.y=e}Math.imul||(d=c),n.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):i<63?c(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var r=0,n=0,s=0;s<i.length-1;s++){var o=n;n=0;for(var a=67108863&r,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=(0|t.words[s-u])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),n+=(o=(o=o+(l/67108864|0)|0)+(c>>>26)|0)>>>26,o&=67108863}i.words[s]=a,r=o,o=n}return 0!==r?i.words[s]=r:i.length--,i.strip()}(this,t,e):f(this,t,e)},m.prototype.makeRBT=function(t){for(var e=new Array(t),i=n.prototype._countBits(t)-1,r=0;r<t;r++)e[r]=this.revBin(r,i,t);return e},m.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var r=0,n=0;n<e;n++)r|=(1&t)<<e-n-1,t>>=1;return r},m.prototype.permute=function(t,e,i,r,n,s){for(var o=0;o<s;o++)r[o]=e[t[o]],n[o]=i[t[o]]},m.prototype.transform=function(t,e,i,r,n,s){this.permute(s,t,e,i,r,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,d=u,f=0;f<o;f++){var m=i[l+f],g=r[l+f],p=i[l+f+o],w=r[l+f+o],v=c*p-d*w;w=c*w+d*p,i[l+f]=m+(p=v),r[l+f]=g+w,i[l+f+o]=m-p,r[l+f+o]=g-w,f!==a&&(v=h*c-u*d,d=h*d+u*c,c=v)}},m.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),r=1&i,n=0;for(i=i/2|0;i;i>>>=1)n++;return 1<<n+1+r},m.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var r=0;r<i/2;r++){var n=t[r];t[r]=t[i-r-1],t[i-r-1]=n,n=e[r],e[r]=-e[i-r-1],e[i-r-1]=-n}},m.prototype.normalize13b=function(t,e){for(var i=0,r=0;r<e/2;r++){var n=8192*Math.round(t[2*r+1]/e)+Math.round(t[2*r]/e)+i;t[r]=67108863&n,i=n<67108864?0:n/67108864|0}return t},m.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)r[2*o]=8191&(s+=0|t[o]),r[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},m.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},m.prototype.mulp=function(t,e,i){var r=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(r),s=this.stub(r),o=new Array(r),a=new Array(r),h=new Array(r),u=new Array(r),l=new Array(r),c=new Array(r),d=i.words;d.length=r,this.convert13b(t.words,t.length,o,r),this.convert13b(e.words,e.length,u,r),this.transform(o,s,a,h,r,n),this.transform(u,s,l,c,r,n);for(var f=0;f<r;f++){var m=a[f]*l[f]-h[f]*c[f];h[f]=a[f]*c[f]+h[f]*l[f],a[f]=m}return this.conjugate(a,h,r),this.transform(a,h,d,s,r,n),this.conjugate(d,s,r),this.normalize13b(d,r),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),f(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,r=0;r<this.length;r++){var n=(0|this.words[r])*t,s=(67108863&n)+(67108863&e);e>>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var r=i%26;e[i]=(t.words[i/26|0]&1<<r)>>>r}return e}(t);if(0===e.length)return new n(1);for(var i=this,r=0;r<e.length&&0===e[r];r++,i=i.sqr());if(++r<e.length)for(var s=i.sqr();r<e.length;r++,s=s.sqr())0!==e[r]&&(i=i.mul(s));return i},n.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s;this.words[e]=(0|this.words[e])-a<<r|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this.strip()},n.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},n.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},n.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return!(this.length<=r||!(this.words[r]&1<<e))},n.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r?this:(0!==e&&r++,this.length=Math.min(r,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},n.prototype.maskn=function(t){return this.clone().imaskn(t)},n.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},n.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},n.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},n.prototype.addn=function(t){return this.clone().iaddn(t)},n.prototype.subn=function(t){return this.clone().isubn(t)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(t,e,r){var n,s;this._expand(t.length+r);var o=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+o;var a=(0|t.words[n])*e;o=((s-=67108863&a)>>26)-(a/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)o=(s=(0|this.words[n+r])+o)>>26,this.words[n+r]=67108863&s;if(0===o)return this.strip();for(i(-1===o),o=0,n=0;n<this.length;n++)o=(s=-(0|this.words[n])+o)>>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},n.prototype._wordDiv=function(t,e){var i,r=this.clone(),s=t,o=0|s.words[s.length-1];0!=(i=26-this._countBits(o))&&(s=s.ushln(i),r.iushln(i),o=0|s.words[s.length-1]);var a,h=r.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=r.clone()._ishlnsubmul(s,1,h);0===l.negative&&(r=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var d=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]);for(d=Math.min(d/o|0,67108863),r._ishlnsubmul(s,d,c);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);a&&(a.words[c]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==i&&r.iushrn(i),{div:a||null,mod:r}},n.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),n=t.andln(1),s=i.cmp(r);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},n.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(l),o.isub(c)),s.iushrn(1),o.iushrn(1);for(var m=0,g=1;0==(r.words[0]&g)&&m<26;++m,g<<=1);if(m>0)for(r.iushrn(m);m-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a),o.isub(h)):(r.isub(e),a.isub(s),h.isub(o))}return{a:a,b:h,gcd:r.iushln(u)}},n.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,o=new n(1),a=new n(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,d=1;0==(r.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(s=0===e.cmpn(1)?o:a).cmpn(0)<0&&s.iadd(t),s},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var r=0;e.isEven()&&i.isEven();r++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var n=e.cmp(i);if(n<0){var s=e;e=i,i=s}else if(0===n||0===i.cmpn(1))break;e.isub(i)}return i.iushln(r)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,this.words[o]=a&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},n.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},n.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var r=0|this.words[i],n=0|t.words[i];if(r!==n){r<n?e=-1:r>n&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new b(t)},n.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var g={k256:null,p224:null,p192:null,p25519:null};function p(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}p.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:i.ucmp(this.p);return 0===r?(i.words[0]=0,i.length=1):r>0?i.isub(this.p):void 0!==i.strip?i.strip():i._strip(),i},p.prototype.split=function(t,e){t.iushrn(this.n,0,e)},p.prototype.imulK=function(t){return t.imul(this.k)},r(w,p),w.prototype.split=function(t,e){for(var i=4194303,r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&i,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&i)<<4|s>>>22,s=o}t.words[n-10]=s>>>=22,t.length-=0===s&&t.length>10?10:9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var r=0|t.words[i];t.words[i]=67108863&(e+=977*r),e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,p),r(y,p),r(M,p),M.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var r=19*(0|t.words[i])+e,n=67108863&r;r>>>=26,t.words[i]=n,e=r}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new v;else if("p192"===t)e=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return g[t]=e,e},b.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},b.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},b.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},b.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},b.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},b.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},b.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},b.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},b.prototype.isqr=function(t){return this.imul(t,t.clone())},b.prototype.sqr=function(t){return this.mul(t,t)},b.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new n(1)).iushrn(2);return this.pow(t,r)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);i(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),m=o;0!==f.cmp(a);){for(var g=f,p=0;0!==g.cmp(a);p++)g=g.redSqr();i(p<m);var w=this.pow(c,new n(1).iushln(m-p-1));d=d.redMul(w),c=w.redSqr(),f=f.redMul(c),m=p}return d},b.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},b.prototype.pow=function(t,e){if(e.isZero())return new n(1).toRed(this);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new n(1).toRed(this),i[1]=t;for(var r=2;r<i.length;r++)i[r]=this.mul(i[r-1],t);var s=i[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),r=e.length-1;r>=0;r--){for(var u=e.words[r],l=h-1;l>=0;l--){var c=u>>l&1;s!==i[0]&&(s=this.sqr(s)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===r&&0===l)&&(s=this.mul(s,i[o]),a=0,o=0)):a=0}h=26}return s},b.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},b.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new A(t)},r(A,b),A.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},A.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},A.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=i.isub(r).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},A.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var i=t.mul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=i.isub(r).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},A.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,Ot)}),Gt=Bt(function(t,e){!function(t){var e,i,r,n=String.fromCharCode;function s(t){for(var e,i,r=[],n=0,s=t.length;n<s;)(e=t.charCodeAt(n++))>=55296&&e<=56319&&n<s?56320==(64512&(i=t.charCodeAt(n++)))?r.push(((1023&e)<<10)+(1023&i)+65536):(r.push(e),n--):r.push(e);return r}function o(t){if(t>=55296&&t<=57343)throw Error("Lone surrogate U+"+t.toString(16).toUpperCase()+" is not a scalar value")}function a(t,e){return n(t>>e&63|128)}function h(t){if(0==(4294967168&t))return n(t);var e="";return 0==(4294965248&t)?e=n(t>>6&31|192):0==(4294901760&t)?(o(t),e=n(t>>12&15|224),e+=a(t,6)):0==(4292870144&t)&&(e=n(t>>18&7|240),e+=a(t,12),e+=a(t,6)),e+n(63&t|128)}function u(){if(r>=i)throw Error("Invalid byte index");var t=255&e[r];if(r++,128==(192&t))return 63&t;throw Error("Invalid continuation byte")}function l(){var t,n;if(r>i)throw Error("Invalid byte index");if(r==i)return!1;if(t=255&e[r],r++,0==(128&t))return t;if(192==(224&t)){if((n=(31&t)<<6|u())>=128)return n;throw Error("Invalid continuation byte")}if(224==(240&t)){if((n=(15&t)<<12|u()<<6|u())>=2048)return o(n),n;throw Error("Invalid continuation byte")}if(240==(248&t)&&(n=(7&t)<<18|u()<<12|u()<<6|u())>=65536&&n<=1114111)return n;throw Error("Invalid UTF-8 detected")}t.version="3.0.0",t.encode=function(t){for(var e=s(t),i=e.length,r=-1,n="";++r<i;)n+=h(e[r]);return n},t.decode=function(t){e=s(t),i=e.length,r=0;for(var o,a=[];!1!==(o=l());)a.push(o);return function(t){for(var e,i=t.length,r=-1,s="";++r<i;)(e=t[r])>65535&&(s+=n((e-=65536)>>>10&1023|55296),e=56320|1023&e),s+=n(e);return s}(a)}}(e)});const zt="0123456789abcdef".split(""),Ht=[1,256,65536,16777216],Zt=[0,8,16,24],Vt=[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],Jt=t=>{var e,i,r,n,s,o,a,h,u,l,c,d,f,m,g,p,w,v,y,M,b,A,x,E,R,S,k,I,T,O,B,C,_,P,D,L,N,W,F,U,q,$,j,G,z,H,Z,V,J,K,X,Q,Y,tt,et,it,rt,nt,st,ot,at,ht,ut;for(r=0;r<48;r+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],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],i=(f=t[9]^t[19]^t[29]^t[39]^t[49])^((a=t[3]^t[13]^t[23]^t[33]^t[43])<<1|(o=t[2]^t[12]^t[22]^t[32]^t[42])>>>31),t[0]^=e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),t[1]^=i,t[10]^=e,t[11]^=i,t[20]^=e,t[21]^=i,t[30]^=e,t[31]^=i,t[40]^=e,t[41]^=i,i=s^(u<<1|h>>>31),t[2]^=e=n^(h<<1|u>>>31),t[3]^=i,t[12]^=e,t[13]^=i,t[22]^=e,t[23]^=i,t[32]^=e,t[33]^=i,t[42]^=e,t[43]^=i,i=a^(c<<1|l>>>31),t[4]^=e=o^(l<<1|c>>>31),t[5]^=i,t[14]^=e,t[15]^=i,t[24]^=e,t[25]^=i,t[34]^=e,t[35]^=i,t[44]^=e,t[45]^=i,i=u^(f<<1|d>>>31),t[6]^=e=h^(d<<1|f>>>31),t[7]^=i,t[16]^=e,t[17]^=i,t[26]^=e,t[27]^=i,t[36]^=e,t[37]^=i,t[46]^=e,t[47]^=i,i=c^(s<<1|n>>>31),t[8]^=e=l^(n<<1|s>>>31),t[9]^=i,t[18]^=e,t[19]^=i,t[28]^=e,t[29]^=i,t[38]^=e,t[39]^=i,t[48]^=e,t[49]^=i,g=t[1],H=t[11]<<4|t[10]>>>28,Z=t[10]<<4|t[11]>>>28,I=t[20]<<3|t[21]>>>29,T=t[21]<<3|t[20]>>>29,ot=t[31]<<9|t[30]>>>23,at=t[30]<<9|t[31]>>>23,$=t[40]<<18|t[41]>>>14,j=t[41]<<18|t[40]>>>14,P=t[2]<<1|t[3]>>>31,D=t[3]<<1|t[2]>>>31,w=t[12]<<12|t[13]>>>20,V=t[22]<<10|t[23]>>>22,J=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,B=t[32]<<13|t[33]>>>19,ht=t[42]<<2|t[43]>>>30,ut=t[43]<<2|t[42]>>>30,tt=t[5]<<30|t[4]>>>2,et=t[4]<<30|t[5]>>>2,L=t[14]<<6|t[15]>>>26,N=t[15]<<6|t[14]>>>26,y=t[24]<<11|t[25]>>>21,K=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,C=t[45]<<29|t[44]>>>3,_=t[44]<<29|t[45]>>>3,E=t[6]<<28|t[7]>>>4,R=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,rt=t[16]<<23|t[17]>>>9,W=t[26]<<25|t[27]>>>7,F=t[27]<<25|t[26]>>>7,M=t[36]<<21|t[37]>>>11,b=t[37]<<21|t[36]>>>11,Q=t[47]<<24|t[46]>>>8,Y=t[46]<<24|t[47]>>>8,G=t[8]<<27|t[9]>>>5,z=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,k=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,st=t[28]<<7|t[29]>>>25,U=t[38]<<8|t[39]>>>24,q=t[39]<<8|t[38]>>>24,A=t[48]<<14|t[49]>>>18,x=t[49]<<14|t[48]>>>18,t[0]=(m=t[0])^~(p=t[13]<<12|t[12]>>>20)&(v=t[25]<<11|t[24]>>>21),t[1]=g^~w&y,t[10]=E^~S&I,t[11]=R^~k&T,t[20]=P^~L&W,t[21]=D^~N&F,t[30]=G^~H&V,t[31]=z^~Z&J,t[40]=tt^~it&nt,t[41]=et^~rt&st,t[2]=p^~v&M,t[3]=w^~y&b,t[12]=S^~I&O,t[13]=k^~T&B,t[22]=L^~W&U,t[23]=N^~F&q,t[32]=H^~V&K,t[33]=Z^~J&X,t[42]=it^~nt&ot,t[43]=rt^~st&at,t[4]=v^~M&A,t[5]=y^~b&x,t[14]=I^~O&C,t[15]=T^~B&_,t[24]=W^~U&$,t[25]=F^~q&j,t[34]=V^~K&Q,t[35]=J^~X&Y,t[44]=nt^~ot&ht,t[45]=st^~at&ut,t[6]=M^~A&m,t[7]=b^~x&g,t[16]=O^~C&E,t[17]=B^~_&R,t[26]=U^~$&P,t[27]=q^~j&D,t[36]=K^~Q&G,t[37]=X^~Y&z,t[46]=ot^~ht&tt,t[47]=at^~ut&et,t[8]=A^~m&p,t[9]=x^~g&w,t[18]=C^~E&S,t[19]=_^~R&k,t[28]=$^~P&L,t[29]=j^~D&N,t[38]=Q^~G&H,t[39]=Y^~z&Z,t[48]=ht^~tt&it,t[49]=ut^~et&rt,t[0]^=Vt[r],t[1]^=Vt[r+1]},Kt=t=>e=>{var i;if("0x"===e.slice(0,2)){i=[];for(var r=2,n=e.length;r<n;r+=2)i.push(parseInt(e.slice(r,r+2),16))}else i=e;return((t,e)=>{for(var i,r=e.length,n=t.blocks,s=t.blockCount<<2,o=t.blockCount,a=t.outputBlocks,h=t.s,u=0;u<r;){if(t.reset)for(t.reset=!1,n[0]=t.block,d=1;d<o+1;++d)n[d]=0;if("string"!=typeof e)for(d=t.start;u<r&&d<s;++u)n[d>>2]|=e[u]<<Zt[3&d++];else for(d=t.start;u<r&&d<s;++u)(i=e.charCodeAt(u))<128?n[d>>2]|=i<<Zt[3&d++]:i<2048?(n[d>>2]|=(192|i>>6)<<Zt[3&d++],n[d>>2]|=(128|63&i)<<Zt[3&d++]):i<55296||i>=57344?(n[d>>2]|=(224|i>>12)<<Zt[3&d++],n[d>>2]|=(128|i>>6&63)<<Zt[3&d++],n[d>>2]|=(128|63&i)<<Zt[3&d++]):(i=65536+((1023&i)<<10|1023&e.charCodeAt(++u)),n[d>>2]|=(240|i>>18)<<Zt[3&d++],n[d>>2]|=(128|i>>12&63)<<Zt[3&d++],n[d>>2]|=(128|i>>6&63)<<Zt[3&d++],n[d>>2]|=(128|63&i)<<Zt[3&d++]);if(t.lastByteIndex=d,d>=s){for(t.start=d-s,t.block=n[o],d=0;d<o;++d)h[d]^=n[d];Jt(h),t.reset=!0}else t.start=d}if(n[(d=t.lastByteIndex)>>2]|=Ht[3&d],t.lastByteIndex===s)for(n[0]=n[o],d=1;d<o+1;++d)n[d]=0;for(n[o-1]|=2147483648,d=0;d<o;++d)h[d]^=n[d];Jt(h);for(var l,c="",d=0,f=0;f<a;){for(d=0;d<o&&f<a;++d,++f)c+=zt[(l=h[d])>>4&15]+zt[15&l]+zt[l>>12&15]+zt[l>>8&15]+zt[l>>20&15]+zt[l>>16&15]+zt[l>>28&15]+zt[l>>24&15];f%o==0&&(Jt(h),d=0)}return"0x"+c})((t=>{return{blocks:[],reset:!0,block:0,start:0,blockCount:1600-(t<<1)>>5,outputBlocks:t>>5,s:(e=[0,0,0,0,0,0,0,0,0,0],[].concat(e,e,e,e,e))};var e})(t),i)};var Xt={keccak256:Kt(256),keccak512:Kt(512),keccak256s:Kt(256),keccak512s:Kt(512)},Qt=Bt(function(t){!function(){var e="input is invalid type",i="object"==typeof window,r=i?window:{};r.JS_SHA3_NO_WINDOW&&(i=!1);var n=!i&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?r=Ot:n&&(r=self);var s=!r.JS_SHA3_NO_COMMON_JS&&t.exports,o=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,a="0123456789abcdef".split(""),h=[4,1024,262144,67108864],u=[0,8,16,24],l=[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],c=[224,256,384,512],d=[128,256],f=["hex","buffer","arrayBuffer","array","digest"],m={128:168,256:136};!r.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!o||!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 g=function(t,e,i){return function(r){return new O(t,e,t).update(r)[i]()}},p=function(t,e,i){return function(r,n){return new O(t,e,n).update(r)[i]()}},w=function(t,e,i){return function(e,r,n,s){return A["cshake"+t].update(e,r,n,s)[i]()}},v=function(t,e,i){return function(e,r,n,s){return A["kmac"+t].update(e,r,n,s)[i]()}},y=function(t,e,i,r){for(var n=0;n<f.length;++n){var s=f[n];t[s]=e(i,r,s)}return t},M=function(t,e){var i=g(t,e,"hex");return i.create=function(){return new O(t,e,t)},i.update=function(t){return i.create().update(t)},y(i,g,t,e)},b=[{name:"keccak",padding:[1,256,65536,16777216],bits:c,createMethod:M},{name:"sha3",padding:[6,1536,393216,100663296],bits:c,createMethod:M},{name:"shake",padding:[31,7936,2031616,520093696],bits:d,createMethod:function(t,e){var i=p(t,e,"hex");return i.create=function(i){return new O(t,e,i)},i.update=function(t,e){return i.create(e).update(t)},y(i,p,t,e)}},{name:"cshake",padding:h,bits:d,createMethod:function(t,e){var i=m[t],r=w(t,0,"hex");return r.create=function(r,n,s){return n||s?new O(t,e,r).bytepad([n,s],i):A["shake"+t].create(r)},r.update=function(t,e,i,n){return r.create(e,i,n).update(t)},y(r,w,t,e)}},{name:"kmac",padding:h,bits:d,createMethod:function(t,e){var i=m[t],r=v(t,0,"hex");return r.create=function(r,n,s){return new B(t,e,n).bytepad(["KMAC",s],i).bytepad([r],i)},r.update=function(t,e,i,n){return r.create(t,i,n).update(e)},y(r,v,t,e)}}],A={},x=[],E=0;E<b.length;++E)for(var R=b[E],S=R.bits,k=0;k<S.length;++k){var I=R.name+"_"+S[k];if(x.push(I),A[I]=R.createMethod(S[k],R.padding),"sha3"!==R.name){var T=R.name+S[k];x.push(T),A[T]=A[I]}}function O(t,e,i){this.blocks=[],this.s=[],this.padding=e,this.outputBits=i,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=i>>5,this.extraBytes=(31&i)>>3;for(var r=0;r<50;++r)this.s[r]=0}function B(t,e,i){O.call(this,t,e,i)}O.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var i,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(e);if(null===t)throw new Error(e);if(o&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||o&&ArrayBuffer.isView(t)))throw new Error(e);i=!0}for(var n,s,a=this.blocks,h=this.byteCount,l=t.length,c=this.blockCount,d=0,f=this.s;d<l;){if(this.reset)for(this.reset=!1,a[0]=this.block,n=1;n<c+1;++n)a[n]=0;if(i)for(n=this.start;d<l&&n<h;++d)a[n>>2]|=t[d]<<u[3&n++];else for(n=this.start;d<l&&n<h;++d)(s=t.charCodeAt(d))<128?a[n>>2]|=s<<u[3&n++]:s<2048?(a[n>>2]|=(192|s>>6)<<u[3&n++],a[n>>2]|=(128|63&s)<<u[3&n++]):s<55296||s>=57344?(a[n>>2]|=(224|s>>12)<<u[3&n++],a[n>>2]|=(128|s>>6&63)<<u[3&n++],a[n>>2]|=(128|63&s)<<u[3&n++]):(s=65536+((1023&s)<<10|1023&t.charCodeAt(++d)),a[n>>2]|=(240|s>>18)<<u[3&n++],a[n>>2]|=(128|s>>12&63)<<u[3&n++],a[n>>2]|=(128|s>>6&63)<<u[3&n++],a[n>>2]|=(128|63&s)<<u[3&n++]);if(this.lastByteIndex=n,n>=h){for(this.start=n-h,this.block=a[c],n=0;n<c;++n)f[n]^=a[n];C(f),this.reset=!0}else this.start=n}return this},O.prototype.encode=function(t,e){var i=255&t,r=1,n=[i];for(i=255&(t>>=8);i>0;)n.unshift(i),i=255&(t>>=8),++r;return e?n.push(r):n.unshift(r),this.update(n),n.length},O.prototype.encodeString=function(t){var i,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(e);if(null===t)throw new Error(e);if(o&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||o&&ArrayBuffer.isView(t)))throw new Error(e);i=!0}var n=0;if(i)n=t.length;else for(var s=0;s<t.length;++s){var a=t.charCodeAt(s);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++s)),n+=4)}return n+=this.encode(8*n),this.update(t),n},O.prototype.bytepad=function(t,e){for(var i=this.encode(e),r=0;r<t.length;++r)i+=this.encodeString(t[r]);var n=[];return n.length=e-i%e,this.update(n),this},O.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,i=this.blockCount,r=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[i],e=1;e<i+1;++e)t[e]=0;for(t[i-1]|=2147483648,e=0;e<i;++e)r[e]^=t[e];C(r)}},O.prototype.toString=O.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,i=this.s,r=this.outputBlocks,n=this.extraBytes,s=0,o=0,h="";o<r;){for(s=0;s<e&&o<r;++s,++o)h+=a[(t=i[s])>>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];o%e==0&&(C(i),s=0)}return n&&(h+=a[(t=i[s])>>4&15]+a[15&t],n>1&&(h+=a[t>>12&15]+a[t>>8&15]),n>2&&(h+=a[t>>20&15]+a[t>>16&15])),h},O.prototype.buffer=O.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,i=this.s,r=this.outputBlocks,n=this.extraBytes,s=0,o=0,a=this.outputBits>>3;t=n?new ArrayBuffer(r+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);o<r;){for(s=0;s<e&&o<r;++s,++o)h[o]=i[s];o%e==0&&C(i)}return n&&(h[s]=i[s],t=t.slice(0,a)),t},O.prototype.digest=O.prototype.array=function(){this.finalize();for(var t,e,i=this.blockCount,r=this.s,n=this.outputBlocks,s=this.extraBytes,o=0,a=0,h=[];a<n;){for(o=0;o<i&&a<n;++o,++a)h[t=a<<2]=255&(e=r[o]),h[t+1]=e>>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%i==0&&C(r)}return s&&(h[t=a<<2]=255&(e=r[o]),s>1&&(h[t+1]=e>>8&255),s>2&&(h[t+2]=e>>16&255)),h},(B.prototype=new O).finalize=function(){return this.encode(this.outputBits,!0),O.prototype.finalize.call(this)};var C=function(t){var e,i,r,n,s,o,a,h,u,c,d,f,m,g,p,w,v,y,M,b,A,x,E,R,S,k,I,T,O,B,C,_,P,D,L,N,W,F,U,q,$,j,G,z,H,Z,V,J,K,X,Q,Y,tt,et,it,rt,nt,st,ot,at,ht,ut,lt;for(r=0;r<48;r+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],h=t[4]^t[14]^t[24]^t[34]^t[44],u=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],d=t[7]^t[17]^t[27]^t[37]^t[47],i=(m=t[9]^t[19]^t[29]^t[39]^t[49])^((a=t[3]^t[13]^t[23]^t[33]^t[43])<<1|(o=t[2]^t[12]^t[22]^t[32]^t[42])>>>31),t[0]^=e=(f=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),t[1]^=i,t[10]^=e,t[11]^=i,t[20]^=e,t[21]^=i,t[30]^=e,t[31]^=i,t[40]^=e,t[41]^=i,i=s^(u<<1|h>>>31),t[2]^=e=n^(h<<1|u>>>31),t[3]^=i,t[12]^=e,t[13]^=i,t[22]^=e,t[23]^=i,t[32]^=e,t[33]^=i,t[42]^=e,t[43]^=i,i=a^(d<<1|c>>>31),t[4]^=e=o^(c<<1|d>>>31),t[5]^=i,t[14]^=e,t[15]^=i,t[24]^=e,t[25]^=i,t[34]^=e,t[35]^=i,t[44]^=e,t[45]^=i,i=u^(m<<1|f>>>31),t[6]^=e=h^(f<<1|m>>>31),t[7]^=i,t[16]^=e,t[17]^=i,t[26]^=e,t[27]^=i,t[36]^=e,t[37]^=i,t[46]^=e,t[47]^=i,i=d^(s<<1|n>>>31),t[8]^=e=c^(n<<1|s>>>31),t[9]^=i,t[18]^=e,t[19]^=i,t[28]^=e,t[29]^=i,t[38]^=e,t[39]^=i,t[48]^=e,t[49]^=i,p=t[1],Z=t[11]<<4|t[10]>>>28,V=t[10]<<4|t[11]>>>28,T=t[20]<<3|t[21]>>>29,O=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,j=t[40]<<18|t[41]>>>14,G=t[41]<<18|t[40]>>>14,D=t[2]<<1|t[3]>>>31,L=t[3]<<1|t[2]>>>31,v=t[12]<<12|t[13]>>>20,J=t[22]<<10|t[23]>>>22,K=t[23]<<10|t[22]>>>22,B=t[33]<<13|t[32]>>>19,C=t[32]<<13|t[33]>>>19,ut=t[42]<<2|t[43]>>>30,lt=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,it=t[4]<<30|t[5]>>>2,N=t[14]<<6|t[15]>>>26,W=t[15]<<6|t[14]>>>26,M=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Q=t[35]<<15|t[34]>>>17,_=t[45]<<29|t[44]>>>3,P=t[44]<<29|t[45]>>>3,R=t[6]<<28|t[7]>>>4,S=t[7]<<28|t[6]>>>4,rt=t[17]<<23|t[16]>>>9,nt=t[16]<<23|t[17]>>>9,F=t[26]<<25|t[27]>>>7,U=t[27]<<25|t[26]>>>7,b=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Y=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,z=t[8]<<27|t[9]>>>5,H=t[9]<<27|t[8]>>>5,k=t[18]<<20|t[19]>>>12,I=t[19]<<20|t[18]>>>12,st=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,q=t[38]<<8|t[39]>>>24,$=t[39]<<8|t[38]>>>24,x=t[48]<<14|t[49]>>>18,E=t[49]<<14|t[48]>>>18,t[0]=(g=t[0])^~(w=t[13]<<12|t[12]>>>20)&(y=t[25]<<11|t[24]>>>21),t[1]=p^~v&M,t[10]=R^~k&T,t[11]=S^~I&O,t[20]=D^~N&F,t[21]=L^~W&U,t[30]=z^~Z&J,t[31]=H^~V&K,t[40]=et^~rt&st,t[41]=it^~nt&ot,t[2]=w^~y&b,t[3]=v^~M&A,t[12]=k^~T&B,t[13]=I^~O&C,t[22]=N^~F&q,t[23]=W^~U&$,t[32]=Z^~J&X,t[33]=V^~K&Q,t[42]=rt^~st&at,t[43]=nt^~ot&ht,t[4]=y^~b&x,t[5]=M^~A&E,t[14]=T^~B&_,t[15]=O^~C&P,t[24]=F^~q&j,t[25]=U^~$&G,t[34]=J^~X&Y,t[35]=K^~Q&tt,t[44]=st^~at&ut,t[45]=ot^~ht<,t[6]=b^~x&g,t[7]=A^~E&p,t[16]=B^~_&R,t[17]=C^~P&S,t[26]=q^~j&D,t[27]=$^~G&L,t[36]=X^~Y&z,t[37]=Q^~tt&H,t[46]=at^~ut&et,t[47]=ht^~lt&it,t[8]=x^~g&w,t[9]=E^~p&v,t[18]=_^~R&k,t[19]=P^~S&I,t[28]=j^~D&N,t[29]=G^~L&W,t[38]=Y^~z&Z,t[39]=tt^~H&V,t[48]=ut^~et&rt,t[49]=lt^~it&nt,t[0]^=l[r],t[1]^=l[r+1]};if(s)t.exports=A;else for(E=0;E<x.length;++E)r[x[E]]=A[x[E]]}()});function Yt(t){if(null==t)throw new Error("cannot convert null value to array");if("string"==typeof t){const e=t.match(/^(0x)?[0-9a-fA-F]*$/);if(!e)throw new Error("invalid hexidecimal string");if("0x"!==e[1])throw new Error("hex string must have 0x prefix");(t=t.substring(2)).length%2&&(t="0"+t);const i=[];for(let e=0;e<t.length;e+=2)i.push(parseInt(t.substr(e,2),16));return te(new Uint8Array(i))}if(function(t){if(!t||parseInt(String(t.length))!=t.length||"string"==typeof t)return!1;for(let e=0;e<t.length;e++){const i=t[e];if(i<0||i>=256||parseInt(String(i))!=i)return!1}return!0}(t))return te(new Uint8Array(t));throw new Error("invalid arrayify value")}function te(t){return void 0!==t.slice||(t.slice=()=>{const e=Array.prototype.slice.call(arguments);return te(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}var ee=/*#__PURE__*/Object.defineProperty({keccak256:function(t){return"0x"+Qt.keccak_256(Yt(t))},padLeft:(t,e)=>{const i=/^0x/i.test(t)||"number"==typeof t;return t=t.toString().replace(/^0x/i,""),(i?"0x":"")+new Array(e-t.length+1>=0?e-t.length+1:0).join("0")+t},bytesToHex:function(t){const e=[];for(let i=0;i<t.length;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return`0x${e.join("").replace(/^0+/,"")}`},toByteArray:Yt},"__esModule",{value:!0});function ie(t){return!("string"!=typeof t||!/^(0x)?[0-9a-f]{512}$/i.test(t)||!/^(0x)?[0-9a-f]{512}$/.test(t)&&!/^(0x)?[0-9A-F]{512}$/.test(t))}function re(t,e){"object"==typeof e&&e.constructor===Uint8Array&&(e=ee.bytesToHex(e));const i=ee.keccak256(e).replace("0x","");for(let e=0;e<12;e+=4){const r=(parseInt(i.substr(e,2),16)<<8)+parseInt(i.substr(e+2,2),16)&2047,n=1<<r%4;if((ne(t.charCodeAt(t.length-1-Math.floor(r/4)))&n)!==n)return!1}return!0}function ne(t){if(t>=48&&t<=57)return t-48;if(t>=65&&t<=70)return t-55;if(t>=97&&t<=102)return t-87;throw new Error("invalid bloom")}function se(t){return!("string"!=typeof t||!/^(0x)?[0-9a-f]{64}$/i.test(t)||!/^(0x)?[0-9a-f]{64}$/.test(t)&&!/^(0x)?[0-9A-F]{64}$/.test(t))}function oe(t){return!("string"!=typeof t||!t.match(/^(0x)?[0-9a-fA-F]{40}$/)&&!t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/))}var ae=/*#__PURE__*/Object.defineProperty({isBloom:ie,isInBloom:re,isUserEthereumAddressInBloom:function(t,e){if(!ie(t))throw new Error("Invalid bloom given");if(!oe(e))throw new Error(`Invalid ethereum address given: "${e}"`);return re(t,ee.padLeft(e,64))},isContractAddressInBloom:function(t,e){if(!ie(t))throw new Error("Invalid bloom given");if(!oe(e))throw new Error(`Invalid contract address given: "${e}"`);return re(t,e)},isTopicInBloom:function(t,e){if(!ie(t))throw new Error("Invalid bloom given");if(!se(e))throw new Error("Invalid topic");return re(t,e)},isTopic:se,isAddress:oe},"__esModule",{value:!0}),he=function(t){return jt.isBN(t)},ue=function(t){return t&&t.constructor&&"BigNumber"===t.constructor.name},le=function(t){try{return Lt.apply(null,arguments)}catch(e){throw new Error(e+' Given value: "'+t+'"')}},ce=function(t){return!!/^(0x)?[0-9a-f]{40}$/i.test(t)&&(!(!/^(0x|0X)?[0-9a-f]{40}$/.test(t)&&!/^(0x|0X)?[0-9A-F]{40}$/.test(t))||de(t))},de=function(t){t=t.replace(/^0x/i,"");for(var e=be(t.toLowerCase()).replace(/^0x/i,""),i=0;i<40;i++)if(parseInt(e[i],16)>7&&t[i].toUpperCase()!==t[i]||parseInt(e[i],16)<=7&&t[i].toLowerCase()!==t[i])return!1;return!0},fe=function(t){var e="";t=(t=(t=(t=(t=Gt.encode(t)).replace(/^(?:\u0000)*/,"")).split("").reverse().join("")).replace(/^(?:\u0000)*/,"")).split("").reverse().join("");for(var i=0;i<t.length;i++){var r=t.charCodeAt(i).toString(16);e+=r.length<2?"0"+r:r}return"0x"+e},me=function(t){if(!t)return t;if("string"==typeof t&&!ve(t))throw new Error('Given value "'+t+'" is not a valid hex string.');return le(t).toNumber()},ge=function(t){if(null==t)return t;if(!isFinite(t)&&!ve(t))throw new Error('Given input "'+t+'" is not a number.');var e=le(t),i=e.toString(16);return e.lt(new jt(0))?"-0x"+i.substr(1):"0x"+i},pe=function(t){if(t=t.toString(16),!ve(t))throw new Error('Given value "'+t+'" is not a valid hex string.');t=t.replace(/^0x/i,"");for(var e=[],i=0;i<t.length;i+=2)e.push(parseInt(t.substr(i,2),16));return e},we=function(t,e){if(ce(t))return e?"address":"0x"+t.toLowerCase().replace(/^0x/i,"");if("boolean"==typeof t)return e?"bool":t?"0x01":"0x00";if(Buffer.isBuffer(t))return"0x"+t.toString("hex");if("object"==typeof t&&t&&!ue(t)&&!he(t))return e?"string":fe(JSON.stringify(t));if("string"==typeof t){if(0===t.indexOf("-0x")||0===t.indexOf("-0X"))return e?"int256":ge(t);if(0===t.indexOf("0x")||0===t.indexOf("0X"))return e?"bytes":t;if(!isFinite(t))return e?"string":fe(t)}return e?t<0?"int256":"uint256":ge(t)},ve=function(t){return("string"==typeof t||"number"==typeof t)&&/^(-)?0x[0-9a-f]*$/i.test(t)},ye=function(t){return("string"==typeof t||"number"==typeof t)&&/^(-0x|0x)?[0-9a-f]*$/i.test(t)},Me="0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",be=function(t){he(t)&&(t=t.toString()),ve(t)&&/^0x/i.test(t.toString())&&(t=pe(t));var e=Xt.keccak256(t);return e===Me?null:e};be._Hash=Xt;var Ae,xe,Ee={BN:jt,isBN:he,isBigNumber:ue,toBN:le,isAddress:ce,isBloom:function(t){return ae.isBloom(t)},isUserEthereumAddressInBloom:function(t,e){return ae.isUserEthereumAddressInBloom(t,e)},isContractAddressInBloom:function(t,e){return ae.isContractAddressInBloom(t,e)},isTopic:function(t){return ae.isTopic(t)},isTopicInBloom:function(t,e){return ae.isTopicInBloom(t,e)},isInBloom:function(t,e){return ae.isInBloom(t,e)},checkAddressChecksum:de,utf8ToHex:fe,hexToUtf8:function(t){if(!ve(t))throw new Error('The parameter "'+t+'" must be a valid HEX string.');for(var e="",i=0,r=(t=(t=(t=(t=(t=t.replace(/^0x/i,"")).replace(/^(?:00)*/,"")).split("").reverse().join("")).replace(/^(?:00)*/,"")).split("").reverse().join("")).length,n=0;n<r;n+=2)i=parseInt(t.substr(n,2),16),e+=String.fromCharCode(i);return Gt.decode(e)},hexToNumber:me,hexToNumberString:function(t){if(!t)return t;if("string"==typeof t&&!ve(t))throw new Error('Given value "'+t+'" is not a valid hex string.');return le(t).toString(10)},numberToHex:ge,toHex:we,hexToBytes:pe,bytesToHex:function(t){for(var e=[],i=0;i<t.length;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return"0x"+e.join("")},isHex:ye,isHexStrict:ve,stripHexPrefix:function(t){return 0!==t&&ye(t)?t.replace(/^(-)?0x/i,"$1"):t},leftPad:function(t,e,i){var r=/^0x/i.test(t)||"number"==typeof t;return t=t.toString(16).replace(/^0x/i,""),(r?"0x":"")+new Array(e-t.length+1>=0?e-t.length+1:0).join(i||"0")+t},rightPad:function(t,e,i){return(/^0x/i.test(t)||"number"==typeof t?"0x":"")+(t=t.toString(16).replace(/^0x/i,""))+new Array(e-t.length+1>=0?e-t.length+1:0).join(i||"0")},toTwosComplement:function(t){return"0x"+le(t).toTwos(256).toString(16,64)},sha3:be,sha3Raw:function(t){return null===(t=be(t))?Me:t},toNumber:function(t){return"number"==typeof t?t:me(we(t))}},Re=function(t){var e=typeof t;if("string"===e)return Ee.isHexStrict(t)?new jt(t.replace(/0x/i,""),16):new jt(t,10);if("number"===e)return new jt(t);if(Ee.isBigNumber(t))return new jt(t.toString(10));if(Ee.isBN(t))return t;throw new Error(t+" is not a number")},Se=function(t,e,i){var r,n,s;if("bytes"===(t=(s=t).startsWith("int[")?"int256"+s.slice(3):"int"===s?"int256":s.startsWith("uint[")?"uint256"+s.slice(4):"uint"===s?"uint256":s.startsWith("fixed[")?"fixed128x128"+s.slice(5):"fixed"===s?"fixed128x128":s.startsWith("ufixed[")?"ufixed128x128"+s.slice(6):"ufixed"===s?"ufixed128x128":s)){if(e.replace(/^0x/i,"").length%2!=0)throw new Error("Invalid bytes characters "+e.length);return e}if("string"===t)return Ee.utf8ToHex(e);if("bool"===t)return e?"01":"00";if(t.startsWith("address")){if(r=i?64:40,!Ee.isAddress(e))throw new Error(e+" is not a valid address, or the checksum is invalid.");return Ee.leftPad(e.toLowerCase(),r)}if(r=function(t){var e=/^\D+(\d+).*$/.exec(t);return e?parseInt(e[1],10):null}(t),t.startsWith("bytes")){if(!r)throw new Error("bytes[] not yet supported in solidity");if(i&&(r=32),r<1||r>32||r<e.replace(/^0x/i,"").length/2)throw new Error("Invalid bytes"+r+" for "+e);return Ee.rightPad(e,2*r)}if(t.startsWith("uint")){if(r%8||r<8||r>256)throw new Error("Invalid uint"+r+" size");if((n=Re(e)).bitLength()>r)throw new Error("Supplied uint exceeds width: "+r+" vs "+n.bitLength());if(n.lt(new jt(0)))throw new Error("Supplied uint "+n.toString()+" is negative");return r?Ee.leftPad(n.toString("hex"),r/8*2):n}if(t.startsWith("int")){if(r%8||r<8||r>256)throw new Error("Invalid int"+r+" size");if((n=Re(e)).bitLength()>r)throw new Error("Supplied int exceeds width: "+r+" vs "+n.bitLength());return n.lt(new jt(0))?n.toTwos(r).toString("hex"):r?Ee.leftPad(n.toString("hex"),r/8*2):n}throw new Error("Unsupported or invalid type: "+t)},ke=function(t){if(Array.isArray(t))throw new Error("Autodetection of array types is not supported.");var e,i,r="";if(t&&"object"==typeof t&&(t.hasOwnProperty("v")||t.hasOwnProperty("t")||t.hasOwnProperty("value")||t.hasOwnProperty("type"))?(e=t.hasOwnProperty("t")?t.t:t.type,r=t.hasOwnProperty("v")?t.v:t.value):(e=Ee.toHex(t,!0),r=Ee.toHex(t),e.startsWith("int")||e.startsWith("uint")||(e="bytes")),!e.startsWith("int")&&!e.startsWith("uint")||"string"!=typeof r||/^(-)?0x/i.test(r)||(r=new jt(r)),Array.isArray(r)){if((i=function(t){var e=/^\D+\d*\[(\d+)\]$/.exec(t);return e?parseInt(e[1],10):null}(e))&&r.length!==i)throw new Error(e+" is not matching the given array "+JSON.stringify(r));i=r.length}return Array.isArray(r)?r.map(function(t){return Se(e,t,i).toString("hex").replace("0x","")}).join(""):Se(e,r,i).toString("hex").replace("0x","")},Ie={soliditySha3:function(){var t=Array.prototype.slice.call(arguments),e=t.map(ke);return Ee.sha3("0x"+e.join(""))},soliditySha3Raw:function(){return Ee.sha3Raw("0x"+Array.prototype.slice.call(arguments).map(ke).join(""))},encodePacked:function(){var t=Array.prototype.slice.call(arguments),e=t.map(ke);return"0x"+e.join("").toLowerCase()}},Te=T.default.randomBytes,Oe=function(t,e){var i=[];return e.forEach(function(e){if("object"==typeof e.components){if("tuple"!==e.type.substring(0,5))throw new Error("components found but type is not tuple; report on GitHub");var r="",n=e.type.indexOf("[");n>=0&&(r=e.type.substring(n));var s=Oe(t,e.components);Array.isArray(s)&&t?i.push("tuple("+s.join(",")+")"+r):i.push(t?"("+s+")":"("+s.join(",")+")"+r)}else i.push(e.type)}),i},Be=function(t){if(!Ee.isHexStrict(t))throw new Error("The parameter must be a valid HEX string.");var e="",i=0,r=t.length;for("0x"===t.substring(0,2)&&(i=2);i<r;i+=2){var n=parseInt(t.substr(i,2),16);e+=String.fromCharCode(n)}return e},Ce=function(t){if(!t)return"0x00";for(var e="",i=0;i<t.length;i++){var r=t.charCodeAt(i).toString(16);e+=r.length<2?"0"+r:r}return"0x"+e},_e=function(t){if(t=t?t.toLowerCase():"ether",!$t.unitMap[t])throw new Error('This unit "'+t+"\" doesn't exist, please use the one of the following units"+JSON.stringify($t.unitMap,null,2));return t},Pe={_fireError:function(t,e,i,r,n){return!t||"object"!=typeof t||t instanceof Error||!t.data||((t.data&&"object"==typeof t.data||Array.isArray(t.data))&&(t.data=JSON.stringify(t.data,null,2)),t=t.message+"\n"+t.data),"string"==typeof t&&(t=new Error(t)),"function"==typeof r&&r(t,n),"function"==typeof i&&((e&&"function"==typeof e.listeners&&e.listeners("error").length||"function"==typeof r)&&e.catch(function(){}),setTimeout(function(){i(t)},1)),e&&"function"==typeof e.emit&&setTimeout(function(){e.emit("error",t,n),e.removeAllListeners()},1),e},_jsonInterfaceMethodToString:function(t){return t&&"object"==typeof t&&t.name&&-1!==t.name.indexOf("(")?t.name:t.name+"("+Oe(!1,t.inputs).join(",")+")"},_flattenTypes:Oe,randomHex:function(t){return"0x"+Te(t).toString("hex")},BN:Ee.BN,isBN:Ee.isBN,isBigNumber:Ee.isBigNumber,isHex:Ee.isHex,isHexStrict:Ee.isHexStrict,sha3:Ee.sha3,sha3Raw:Ee.sha3Raw,keccak256:Ee.sha3,soliditySha3:Ie.soliditySha3,soliditySha3Raw:Ie.soliditySha3Raw,encodePacked:Ie.encodePacked,isAddress:Ee.isAddress,checkAddressChecksum:Ee.checkAddressChecksum,toChecksumAddress:function(t){if(void 0===t)return"";if(!/^(0x)?[0-9a-f]{40}$/i.test(t))throw new Error('Given address "'+t+'" is not a valid Ethereum address.');t=t.toLowerCase().replace(/^0x/i,"");for(var e=Ee.sha3(t).replace(/^0x/i,""),i="0x",r=0;r<t.length;r++)parseInt(e[r],16)>7?i+=t[r].toUpperCase():i+=t[r];return i},toHex:Ee.toHex,toBN:Ee.toBN,bytesToHex:Ee.bytesToHex,hexToBytes:Ee.hexToBytes,hexToNumberString:Ee.hexToNumberString,hexToNumber:Ee.hexToNumber,toDecimal:Ee.hexToNumber,numberToHex:Ee.numberToHex,fromDecimal:Ee.numberToHex,hexToUtf8:Ee.hexToUtf8,hexToString:Ee.hexToUtf8,toUtf8:Ee.hexToUtf8,stripHexPrefix:Ee.stripHexPrefix,utf8ToHex:Ee.utf8ToHex,stringToHex:Ee.utf8ToHex,fromUtf8:Ee.utf8ToHex,hexToAscii:Be,toAscii:Be,asciiToHex:Ce,fromAscii:Ce,unitMap:$t.unitMap,toWei:function(t,e){if(e=_e(e),!Ee.isBN(t)&&"string"!=typeof t)throw new Error("Please pass numbers as strings or BN objects to avoid precision errors.");return Ee.isBN(t)?$t.toWei(t,e):$t.toWei(t,e).toString(10)},fromWei:function(t,e){if(e=_e(e),!Ee.isBN(t)&&"string"!=typeof t)throw new Error("Please pass numbers as strings or BN objects to avoid precision errors.");return Ee.isBN(t)?$t.fromWei(t,e):$t.fromWei(t,e).toString(10)},padLeft:Ee.leftPad,leftPad:Ee.leftPad,padRight:Ee.rightPad,rightPad:Ee.rightPad,toTwosComplement:Ee.toTwosComplement,isBloom:Ee.isBloom,isUserEthereumAddressInBloom:Ee.isUserEthereumAddressInBloom,isContractAddressInBloom:Ee.isContractAddressInBloom,isTopic:Ee.isTopic,isTopicInBloom:Ee.isTopicInBloom,isInBloom:Ee.isInBloom,compareBlockNumbers:function(t,e){if(t==e)return 0;if("genesis"!=t&&"earliest"!=t&&0!=t||"genesis"!=e&&"earliest"!=e&&0!=e){if("genesis"==t||"earliest"==t)return-1;if("genesis"==e||"earliest"==e)return 1;if("latest"==t)return"pending"==e?-1:1;if("latest"===e)return"pending"==t?1:-1;if("pending"==t)return 1;if("pending"==e)return-1;{let i=new jt(t),r=new jt(e);return i.lt(r)?-1:i.eq(r)?0:1}}return 0},toNumber:Ee.toNumber};function De(t,e,i){let r=!1;if("allow"===i){if(t&&t.allow){const i=t.allow.find(t=>t.type===e);r=i&&i.values.length>0}return r}if(t&&t.deny){const i=t.deny.find(t=>t.type===e);r=i&&i.values.length>0}return r}function Le(t,e,i){const r=De(t.credentials,e,i);return"allow"===i?(r&&(t.credentials.allow=t.credentials.allow.filter(t=>t.type!==e)),t.credentials&&!t.credentials.allow&&(t.credentials={deny:t.credentials&&t.credentials.deny})):(r&&(t.credentials.deny=t.credentials.deny.filter(t=>t.type!==e)),t.credentials&&!t.credentials.deny&&(t.credentials={allow:t.credentials&&t.credentials.allow})),t}function Ne(t,e,i,r){const n=De(t.credentials,e,r);return"allow"===r?n?t.credentials.allow.find(t=>{t.type===e&&(t.values=i)}):t=We(t,e,i,r):n?t.credentials.deny.find(t=>{t.type===e&&(t.values=i)}):t=We(t,e,i,r),t}function We(t,e,i,r){const n={type:e,values:i};return"allow"===r?t.credentials&&t.credentials.allow?t.credentials.allow.push(n):t.credentials={allow:[n],deny:t.credentials&&t.credentials.deny}:t.credentials&&t.credentials.deny?t.credentials.deny.push(n):t.credentials={allow:t.credentials&&t.credentials.allow,deny:[n]},t}class Fe extends Mt{constructor(...t){super(...t),this.baseUrl=void 0}static async getInstance(t){var e;const i=new Fe;return i.setInstanceConfig(t),await i.setBaseUrl(null==(e=t.config)?void 0:e.rbacUri),i}async setBaseUrl(t){this.baseUrl=t}get url(){return this.baseUrl}getIsPermitArgs(t,e,i,r,n,s){return"consume"===e?{component:t,eventType:e,authService:i,did:s,credentials:{type:n,value:r}}:{component:t,eventType:e,authService:i,credentials:{type:n,value:r}}}async isPermit(t,e,i,r,n,s){if(!this.url)return!0;const o=this.getIsPermitArgs(t,e,i,r,n,s);try{const t=await this.ocean.utils.fetch.post(this.url,JSON.stringify(o));let e=await t.json();return e=JSON.stringify(e),"true"===e}catch(t){throw this.logger.error(t),new Error("ERROR: Asset URL not found or not available.")}}}exports.CreateProgressStep=void 0,(Ae=exports.CreateProgressStep||(exports.CreateProgressStep={}))[Ae.CreatingDataToken=0]="CreatingDataToken",Ae[Ae.DataTokenCreated=1]="DataTokenCreated",Ae[Ae.EncryptingFiles=2]="EncryptingFiles",Ae[Ae.FilesEncrypted=3]="FilesEncrypted",Ae[Ae.StoringDdo=4]="StoringDdo",Ae[Ae.DdoStored=5]="DdoStored",exports.OrderProgressStep=void 0,function(t){t[t.TransferDataToken=0]="TransferDataToken"}(exports.OrderProgressStep||(exports.OrderProgressStep={}));class Ue extends Mt{static async getInstance(t){const e=new Ue;return e.setInstanceConfig(t),e}create(t,e,i=[],r,n,s,o,a){return r&&!Pe.isAddress(r)?(this.logger.error(`Passed Data Token address ${r} is not valid. Aborting publishing.`),null):(this.logger.log("Creating asset"),new K(async h=>{0===i.length&&this.logger.log("You have no services. Are you sure about this?");const{datatokens:u}=this.ocean;if(!r){if(this.logger.log("Creating datatoken"),h.next(exports.CreateProgressStep.CreatingDataToken),r=await u.create("",e.getId(),n,s,o),!Pe.isAddress(r))return this.logger.error(`Created Data Token address ${r} is not valid. Aborting publishing.`),null;this.logger.log(`DataToken ${r} created`),h.next(exports.CreateProgressStep.DataTokenCreated)}const l=At.generate(r);let c;this.logger.log("Encrypting files"),h.next(exports.CreateProgressStep.EncryptingFiles),a?(c=await Tt.getInstance(this.instanceConfig),await c.setBaseUrl(a)):c=this.ocean.provider;const d=await c.encrypt(l.getDid(),t.main.files,e);this.logger.log("Files encrypted"),h.next(exports.CreateProgressStep.FilesEncrypted);let f=0;const m=new Rt({id:l.getDid(),dataToken:r,authentication:[{type:"RsaSignatureAuthentication2018",publicKey:l.getDid()}],publicKey:[{id:l.getDid(),type:"EthereumECDSAKey",owner:e.getId()}],service:[{type:"metadata",attributes:W({status:{isListed:!0,isRetired:!1,isOrderDisabled:!1}},t,{encryptedFiles:d,main:W({},t.main,{files:t.main.files.map((t,e)=>W({},t,{index:e,url:void 0}))})})},...i].reverse().filter(({type:t},e,i)=>i.findIndex(({type:e})=>e===t)===e).reverse().map(t=>W({},t,{index:f++}))});return await m.addProof(this.ocean,e.getId()),m.dataTokenInfo={name:await u.getName(r),symbol:await u.getSymbol(r),address:r,cap:parseFloat(await u.getCap(r))},m}))}async resolve(t){return this.ocean.metadataCache.retrieveDDO(t)}async editMetadata(t,e){if(!t)return null;for(let r=0;r<t.service.length;r++){var i;"metadata"===t.service[r].type&&(e.title&&(t.service[r].attributes.main.name=e.title),e.author&&(t.service[r].attributes.main.author=e.author),t.service[r].attributes.additionalInformation||(t.service[r].attributes.additionalInformation=Object()),e.description&&(t.service[r].attributes.additionalInformation.description=e.description),t.service[r].attributes.additionalInformation.links=e.links?e.links:[],void 0!==(null==(i=e.status)?void 0:i.isOrderDisabled)&&(t.service[r].attributes.status?t.service[r].attributes.status.isOrderDisabled=e.status.isOrderDisabled:t.service[r].attributes.status={isOrderDisabled:e.status.isOrderDisabled}))}return t}async updateCredentials(t,e,i,r){let n;return n=i&&i.length>0?Ne(t,e,i,"allow"):Le(t,e,"allow"),n=r&&r.length>0?Ne(t,e,r,"deny"):Le(t,e,"deny"),n}checkCredential(t,e,i){let r=0,n="All good",s=!0;if(t.credentials){if(t.credentials.allow&&t.credentials.allow.length>0){const o=t.credentials.allow.find(t=>t.type===e);o&&!o.values.includes(i)&&(r=2,n="Access is denied, your wallet address is not found on allow list",s=!1)}if(t.credentials.deny&&t.credentials.deny.length>0){const o=t.credentials.deny.find(t=>t.type===e);o&&o.values.includes(i)&&(r=3,n="Access is denied, your wallet address is found on deny list",s=!1)}}return{status:r,message:n,result:s}}async publishDdo(t,e,i=!1){return await this.ocean.onChainMetadata.publish(t.id,t,e,i)}async updateMetadata(t,e){return await this.ocean.onChainMetadata.update(t.id,t,e)}async editServiceTimeout(t,e,i){return t?void 0===t.service[e]||i<0?null:(t.service[e].attributes.main.timeout=parseInt(i.toFixed()),t):null}async creator(t){const{did:e,ddo:i}=await pt(t,this.ocean),r=i.getChecksum(),{creator:n,signatureValue:s}=i.proof,o=await this.ocean.utils.signature.verifyText(r,s);return o.toLowerCase()!==n.toLowerCase()&&this.logger.warn(`Owner of ${e} doesn't match. Expected ${n} instead of ${o}.`),n}async getServiceByType(t,e){const{ddo:i}=await pt(t,this.ocean);let r;return i.service.forEach(t=>{t.type.toString()===e&&(r=t)}),r}async getServiceByIndex(t,e){const{ddo:i}=await pt(t,this.ocean);let r;return i.service.forEach(t=>{t.index===e&&(r=t)}),r}async query(t){return this.ocean.metadataCache.queryMetadata(t)}async createAccessServiceAttributes(t,e,i,r=0,n,s){const o={type:"access",index:2,serviceEndpoint:n||this.ocean.provider.url,attributes:{main:{creator:t.getId(),datePublished:i,cost:e,timeout:r,name:"dataAssetAccess"}}};return null!=s&&s.userCustomParameters&&(o.attributes.userCustomParameters=s.userCustomParameters),null!=s&&s.algoCustomParameters&&(o.attributes.algoCustomParameters=s.algoCustomParameters),o}async initialize(t,e,i,r=-1,n,s){const o=await Tt.getInstance(this.instanceConfig);await o.setBaseUrl(n);const a=await o.initialize(t,r,e,i,s);return null===a?null:JSON.parse(a)}async order(t,e,i,r=-1,n,s,o,a="json",h=!0){let u;const{ddo:l}=await pt(t,this.ocean),c=await this.isConsumable(l,i,"address",a);if(!c.result)throw new Error("Order asset failed, "+c.message);if(s||(s=i),-1===r?(u=await this.getServiceByType(l,e),r=u.index):(u=await this.getServiceByIndex(l,r),e=u.type),!await this.isUserCustomParametersValid(u.attributes.userCustomParameters,o))throw new Error("Order asset failed, Missing required fiels in userCustomParameters");try{const t=await this.initialize(l,e,i,r,u.serviceEndpoint,o);if(!t)throw new Error("Order asset failed, Failed to initialize service to compute totalCost for ordering");if(h){const e=await this.ocean.datatokens.getPreviousValidOrders(t.dataToken,t.numTokens,r,u.attributes.main.timeout,s);if(e)return e}const a=new dt(await this.ocean.datatokens.balance(t.dataToken,i)),c=new dt(String(t.numTokens));if(a.isLessThan(c))throw this.logger.error("ERROR: Not enough funds Needed "+c.toString()+" but balance is "+a.toString()),new Error("ERROR: Not enough funds Needed "+c.toString()+" but balance is "+a.toString());const d=await this.ocean.datatokens.startOrder(t.dataToken,s,String(t.numTokens),r,n,i);if(d)return d.transactionHash}catch(t){throw this.logger.error(`ERROR: Failed to order a service : ${t.message}`),new Error(`${t.message}`)}}async download(t,e,i,r,n){const{did:s,ddo:o}=await pt(t,this.ocean),{attributes:a}=o.findServiceByType("metadata"),h=o.findServiceByType("access"),{files:u}=a.main,{serviceEndpoint:l}=h;if(!l)throw new Error("Consume asset failed, service definition is missing the `serviceEndpoint`.");this.logger.log("Consuming files"),n=n?`${n}/datafile.${o.shortId()}.${h.index}/`:void 0;const c=await Tt.getInstance(this.instanceConfig);return await c.setBaseUrl(l),await c.download(s,e,i,h.type,h.index.toString(),n,r,u),!0}async simpleDownload(t,e,i,r){var n,s;let o=e;o+=`?consumerAddress=${r}`,o+=`&tokenAddress=${t}`,o+=`&transferTxId=${i}`;const a=new It(this.logger,null==(n=this.instanceConfig)||null==(s=n.config)?void 0:s.requestTimeout);try{await a.downloadFile(o)}catch(t){throw this.logger.error("Error consuming assets"),this.logger.error(t),t}return e}async getOrderHistory(t,e,i){const r=[],n=t.getId().toLowerCase(),{datatokens:s}=this.ocean,o="0x000000000000000000000000"+n.substring(2),a=s.getStartOrderEventSignature(),h=await this.web3.eth.getPastLogs({topics:[a,null,o],fromBlock:i||0,toBlock:"latest"});for(let t=0;t<h.length;t++){const i={dtAddress:h[t].address,timestamp:0,transactionHash:h[t].transactionHash,amount:null,consumer:"0x"+h[t].topics[1].substring(h[t].topics[1].length-40),payer:"0x"+h[t].topics[2].substring(h[t].topics[2].length-40)};try{const n=this.web3.eth.abi.decodeParameters(["uint256","uint256","uint256","uint256"],h[t].data);i.serviceId=parseInt(n[1]),i.timestamp=parseInt(n[2]),i.amount=this.web3.utils.fromWei(n[0]),i.did=G(Z(i.dtAddress));const s=await this.getServiceByIndex(i.did,i.serviceId);i.serviceType=s.type,(!e||e&&e===s.type)&&r.push(i)}catch(t){}}return r}async isConsumable(t,e,i,r){var n,s;if(!t)throw new Error("ERROR: DDO does not exist");const o={status:2,message:"Consume access is denied.",result:!1};if(null!=(n=t.findServiceByType("metadata").attributes.status)&&n.isOrderDisabled)return{status:1,message:"Ordering this asset has been temporarily disabled by the publisher.",result:!1};const a=this.instanceConfig;if(e&&null!=a&&null!=(s=a.config)&&s.rbacUri){const n=await Fe.getInstance(this.instanceConfig);if(!await n.isPermit("market","consume",r,e,i,t.id))return o}return{status:0,message:"All good",result:!0}}async isUserCustomParametersValid(t,e){if(t)for(const i of t){const t=i.name;if(i.required&&(!e||!e[t]))return this.logger.error("Missing key: "+t+" from customData"),!1}return!0}}exports.OceanPlatformTechStatus=void 0,(xe=exports.OceanPlatformTechStatus||(exports.OceanPlatformTechStatus={})).Loading="Loading",xe.Unknown="Unknown",xe.Stopped="Stopped",xe.Working="Working";class qe extends Mt{static async getInstance(t){const e=new qe;return e.setInstanceConfig(t),e}async get(){const t={};t.lib={name:"Lib",version:"0.20.1",commit:"e216090394721358ce2bf9126c94f0b8069158db",status:exports.OceanPlatformTechStatus.Working};try{const{software:e,version:i}=await this.ocean.metadataCache.getVersionInfo();t.metadataCache={name:e,status:exports.OceanPlatformTechStatus.Working,version:i}}catch(e){t.metadataCache={name:"MetadataCache",status:exports.OceanPlatformTechStatus.Stopped}}const e=Object.values(t);return t.status={ok:!e.find(({status:t})=>t!==exports.OceanPlatformTechStatus.Working)},t}}class $e{constructor(t,e){this.web3=void 0,this.logger=void 0,this.web3=t,this.logger=e}async signText(t,e,i){const r=this.web3&&this.web3.currentProvider&&this.web3.currentProvider.isMetaMask;try{return await this.web3.eth.personal.sign(t,e,i)}catch(i){if(r)throw i;this.logger.warn("Error on personal sign."),this.logger.warn(i);try{return await this.web3.eth.sign(t,e)}catch(t){throw this.logger.error("Error on sign."),this.logger.error(t),new Error("Error executing personal sign")}}}async signWithHash(t,e,i){const r=this.web3.utils.utf8ToHex(t),n=this.web3&&this.web3.currentProvider&&this.web3.currentProvider.isMetaMask;try{return await this.web3.eth.personal.sign(r,e,i)}catch(t){if(n)throw t;this.logger.warn("Error on personal sign."),this.logger.warn(t);try{return await this.web3.eth.sign(r,e)}catch(t){throw this.logger.error("Error on sign."),this.logger.error(t),new Error("Error executing personal sign")}}}async verifyText(t,e){return this.web3.eth.personal.ecRecover(t,e)}async getHash(t){let e="";for(let i=0;i<t.length;i++)e+=""+t.charCodeAt(i).toString(16);return"0x"+e}async signForAquarius(t,e){const i=await this.getHash(t),r=this.web3&&this.web3.currentProvider&&this.web3.currentProvider.isMetaMask;try{return this.web3.eth.personal.sign(i,e.getId(),e.getPassword())}catch(t){if(r)throw t;return this.logger.warn("Error on personal sign."),this.logger.warn(t),null}}}class je extends Mt{constructor(...t){super(...t),this.signature=void 0,this.fetch=void 0}static async getInstance(t){var e;const i=new je;return i.setInstanceConfig(t),i.signature=new $e(t.web3,t.logger),i.fetch=new It(t.logger,null==(e=t.config)?void 0:e.requestTimeout),i}}const Ge="/api/v1/aquarius/assets/ddo";class ze{get url(){return this.metadataCacheUri}constructor(t,e,i){this.fetch=void 0,this.logger=void 0,this.metadataCacheUri=void 0,this.fetch=new It(e,i),this.logger=e,this.metadataCacheUri=t}async getVersionInfo(){return(await this.fetch.get(this.url)).json()}async getAccessUrl(t,e){return await this.fetch.post(`${t.service_endpoint}/${t.resource_id}`,e).then(t=>t.ok?t.text():(this.logger.error("Failed: ",t.status,t.statusText),null)).then(t=>(this.logger.error("Success accessing consume endpoint: ",t),t)).catch(t=>(this.logger.error("Error fetching the data asset consumption url: ",t),null))}async queryMetadata(t){return await this.fetch.post(`${this.url}/api/v1/aquarius/assets/query`,JSON.stringify(t)).then(t=>t.ok?t.json():(this.logger.error("queryMetadata failed:",t.status,t.statusText),null)).then(t=>t).catch(t=>(this.logger.error("Error fetching querying metadata: ",t),null))}async encryptDDO(t){const e=`${this.url}/api/v1/aquarius/assets/ddo/encryptashex `;return await this.fetch.postWithOctet(e,t).then(e=>e.ok?e.text():(this.logger.error("encryptDDO failed:",e.status,e.statusText,t),null)).catch(t=>(this.logger.error("Error encryptDDO: ",t),null))}async validateMetadata(t){const e={valid:!1},i=gt(t)?"/validate-remote":"/validate";try{const r=await this.fetch.post(`${this.url}${Ge}${i}`,JSON.stringify(t));if(r.ok){const t=await r.json();!0===t?e.valid=!0:e.errors=t}else this.logger.error("validate Metadata failed:",r.status,r.statusText)}catch(t){this.logger.error("Error validating metadata: ",t)}return e}async retrieveDDO(t,e){t=t&&At.parse(t);const i=e||`${this.url}${Ge}/${t.getDid()}`;return await this.fetch.get(i).then(e=>e.ok?e.json():(this.logger.log("retrieveDDO failed:",e.status,e.statusText,t),null)).then(t=>new Rt(t)).catch(t=>(this.logger.error("Error fetching querying metadata: ",t),null))}async retrieveDDOByUrl(t){return this.retrieveDDO(void 0,t)}getServiceEndpoint(t){return`${this.url}/api/v1/aquarius/assets/ddo/did:op:${t.getId()}`}getURI(){return`${this.url}`}sleep(t){return new Promise(e=>{setTimeout(e,t)})}async waitForAqua(t,e){let i=0;do{try{const i=await h.fetch(this.getURI()+"/api/v1/aquarius/assets/ddo/"+t);if(i.ok){if(!e)break;{const t=await i.json();if(t.event&&t.event.txid===e)break}}}catch(t){}await this.sleep(1500),i++}while(i<100)}}class He{constructor(t,e,i=null,r=null,n,s){this.GASLIMIT_DEFAULT=1e6,this.DDOContractAddress=void 0,this.DDOContractABI=void 0,this.web3=void 0,this.DDOContract=null,this.logger=void 0,this.metadataCache=void 0,this.config=void 0,this.web3=t,this.config=s,this.DDOContractAddress=i,this.DDOContractABI=r||O.default.abi,t&&(this.DDOContract=mt(new this.web3.eth.Contract(this.DDOContractABI,this.DDOContractAddress),this.config)),this.logger=e,this.metadataCache=n}async compressDDO(t){return l.LZMA.disableEndMark=!0,l.LZMA.compress(t,9)}async publish(t,e,i,r=!1,n=!0){if(n&&!(await this.metadataCache.validateMetadata(e)).valid)throw new Error("DDO has failed validation");const s=await this.prepareRawData(e,r);if(s)return this.publishRaw(H(t),s.flags,s.data,i);throw new Error("Could not prepare raw data for publish")}async update(t,e,i,r=!1,n=!0){if(n&&!(await this.metadataCache.validateMetadata(e)).valid)throw new Error("DDO has failed validation");const s=await this.prepareRawData(e,r);if(s)return this.updateRaw(H(t),s.flags,s.data,i);throw new Error("Could not prepare raw data for udate")}async prepareRawData(t,e=!1){let i=0,r=Rt.serialize(t);if(!1===e)r=await this.compressDDO(r),i|=1,r=this.getHex(r);else{if(r=await this.metadataCache.encryptDDO(r),!r)return null;i|=2}return{flags:i,data:r}}async publishRaw(t,e,i,r){if(!this.DDOContract)return this.logger.error("ERROR: Missing DDOContract"),null;const n=this.GASLIMIT_DEFAULT;let s;try{s=await this.DDOContract.methods.create(H(t),e,i).estimateGas({from:r},(t,e)=>t?n:e)}catch(t){s=n}try{return await this.DDOContract.methods.create(H(t),e,i).send({from:r,gas:s+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error(`ERROR: Failed to publish raw DDO : ${t.message}`),null}}async updateRaw(t,e,i,r){if(!this.DDOContract)return this.logger.error("ERROR: Missing DDOContract"),null;const n=this.GASLIMIT_DEFAULT;let s;try{s=await this.DDOContract.methods.update(H(t),e,i).estimateGas({from:r},(t,e)=>t?n:e)}catch(t){s=n}try{return await this.DDOContract.methods.update(H(t),e,i).send({from:r,gas:s+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error(`ERROR: Failed to update raw DDO : ${t.message}`),null}}async transferOwnership(t,e,i){if(!this.DDOContract)return null;try{return await this.DDOContract.methods.transferOwnership(H(t),e).send({from:i})}catch(t){return this.logger.error(`ERROR: Failed to transfer DDO ownership : ${t.message}`),null}}getHex(t){const e=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];let i="";try{for(let r=0;r<t.length;r++)i+=""+e[t[r]>>4&15]+e[15&t[r]]}catch(t){this.logger.error(`ERROR: Failed to get hex message value : ${t.message}`)}return"0x"+i}}class Ze{constructor(t,e,i,r,n,s){this.GASLIMIT_DEFAULT=1e6,this.factoryAddress=void 0,this.factoryABI=void 0,this.datatokensABI=void 0,this.web3=void 0,this.logger=void 0,this.startBlock=void 0,this.config=void 0,this.factoryAddress=t,this.factoryABI=e||B.default.abi,this.datatokensABI=i||C.default.abi,this.web3=r,this.logger=n,this.config=s,this.startBlock=s&&s.startBlock||0}generateDtName(t){const{name:e,symbol:i}=vt(t);return{name:e,symbol:i}}async create(t,e,i,r,n){i||(i="1000"),r&&n||({name:r,symbol:n}=this.generateDtName());const s=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress,{from:e}),this.config),o=this.GASLIMIT_DEFAULT;let a;try{a=await s.methods.createToken(t,r,n,this.web3.utils.toWei(i)).estimateGas({from:e},(t,e)=>t?o:e)}catch(t){a=o}const h=await s.methods.createToken(t,r,n,this.web3.utils.toWei(i)).send({from:e,gas:a+1,gasPrice:await ft(this.web3,this.config)});let u=null;try{u=h.events.TokenCreated.returnValues[0]}catch(t){this.logger.error(`ERROR: Failed to create datatoken : ${t.message}`)}return u}async approve(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:r}),this.config),s=this.GASLIMIT_DEFAULT;let o;try{o=await n.methods.approve(e,this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){o=s}return await n.methods.approve(e,this.web3.utils.toWei(i)).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)})}async mint(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:e}),this.config),s=await this.getCap(t);if(new x.default(s).gte(i)){const t=this.GASLIMIT_DEFAULT;let s;try{s=await n.methods.mint(r||e,this.web3.utils.toWei(i)).estimateGas({from:e},(e,i)=>e?t:i)}catch(e){s=t}return await n.methods.mint(r||e,this.web3.utils.toWei(i)).send({from:e,gas:s+1,gasPrice:await ft(this.web3,this.config)})}throw new Error("Mint amount exceeds cap available")}async transfer(t,e,i,r){return this.transferToken(t,e,i,r)}async transferToken(t,e,i,r){const n=this.web3.utils.toWei(i);return this.transferWei(t,e,n,r)}async transferWei(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:r}),this.config),s=this.GASLIMIT_DEFAULT;let o;try{o=await n.methods.transfer(e,i).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){o=s}return await n.methods.transfer(e,i).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)})}async transferFrom(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:r}),this.config),s=this.GASLIMIT_DEFAULT;let o;try{o=await n.methods.transferFrom(e,r,this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){o=s}return await n.methods.transferFrom(e,r,this.web3.utils.toWei(i)).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)})}async balance(t,e){const i=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:e}),this.config),r=await i.methods.balanceOf(e).call();return this.web3.utils.fromWei(r)}async allowance(t,e,i){const r=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:i}),this.config),n=await r.methods.allowance(e,i).call();return this.web3.utils.fromWei(n)}async getBlob(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await e.methods.blob().call()}async getName(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await e.methods.name().call()}async getSymbol(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await e.methods.symbol().call()}async getCap(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config),i=await e.methods.cap().call();return this.web3.utils.fromWei(i)}toWei(t){return this.web3.utils.toWei(t)}fromWei(t){return this.web3.utils.fromWei(t)}async startOrder(t,e,i,r,n,s){const o=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:s}),this.config);n||(n="0x0000000000000000000000000000000000000000");try{const t=this.GASLIMIT_DEFAULT;let a;try{a=await o.methods.startOrder(e,this.web3.utils.toWei(i),String(r),n).estimateGas({from:s},(e,i)=>e?t:i)}catch(e){a=t}return await o.methods.startOrder(e,this.web3.utils.toWei(i),String(r),n).send({from:s,gas:a+1,gasPrice:await ft(this.web3,this.config)})}catch(t){throw this.logger.error(`ERROR: Failed to start order : ${t.message}`),new Error(`Failed to start order: ${t.message}`)}}async getPreviousValidOrders(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:n}),this.config);let o;r>0?(o=await this.web3.eth.getBlockNumber()-r,o<this.startBlock&&(o=this.startBlock)):o=this.startBlock;const a=await s.getPastEvents("OrderStarted",{filter:{consumer:n},fromBlock:o,toBlock:"latest"});for(let t=0;t<a.length;t++)if(String(a[t].returnValues.amount)===this.web3.utils.toWei(String(e))&&String(a[t].returnValues.serviceId)===String(i)&&a[t].returnValues.consumer.toLowerCase()===n.toLowerCase()){if(0===r)return a[t].transactionHash;const e=await this.web3.eth.getBlock(a[t].blockHash),i=new dt(e.timestamp).plus(r);if(new dt(Math.floor(Date.now()/1e3)).isLessThan(i))return a[t].transactionHash}return null}getStartOrderEventSignature(){const t=this.datatokensABI.find(function(t){if("OrderStarted"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}async proposeMinter(t,e,i){const r=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:i}),this.config),n=this.GASLIMIT_DEFAULT;let s;try{s=await r.methods.proposeMinter(e).estimateGas({from:i},(t,e)=>t?n:e)}catch(t){s=n}try{return await r.methods.proposeMinter(e).send({from:i,gas:s+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error("ERROR: Propose minter failed"),null}}async approveMinter(t,e){const i=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:e}),this.config),r=this.GASLIMIT_DEFAULT;let n;try{n=await i.methods.approveMinter().estimateGas({from:e},(t,e)=>t?r:e)}catch(t){n=r}try{return await i.methods.approveMinter().send({from:e,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return null}}async isMinter(t,e){const i=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await i.methods.isMinter(e).call()}}class Ve extends Mt{getNetworkId(){return this.web3.eth.net.getId()}async getNetworkName(){return this.web3.eth.net.getId().then(t=>{const e=f.lookup(t);return e&&e.name?e.name:"Development"})}}var Je;!function(t){t[t.TransferDataToken=0]="TransferDataToken"}(Je||(Je={})),Object.freeze({WarmingUp:1,Started:10,ConfiguringVolumes:20,ProvisioningSuccess:30,DataProvisioningFailed:31,AlgorithmProvisioningFailed:32,RunningAlgorithm:40,FilteringResults:50,PublishingResult:60,Completed:70,Stopped:80,Deleted:90});class Ke extends Mt{static async getInstance(t){const e=new Ke;return e.setInstanceConfig(t),e}async getComputeAddress(t,e=-1){let i,r="compute";-1===e?(i=await this.ocean.assets.getServiceByType(t,r),e=i.index):(i=await this.ocean.assets.getServiceByIndex(t,e),r=i.type);const{serviceEndpoint:n}=i,s=await Tt.getInstance(this.instanceConfig);return await s.setBaseUrl(n),s.computeAddress}async start(t,e,i,r,n,s,o,a,h){s=this.checkOutput(r,s);const{did:u,ddo:l}=await pt(t,this.ocean),c=l.findServiceByType("compute"),{serviceEndpoint:d}=c;if(n.serviceIndex){const{ddo:t}=await pt(n.did,this.ocean),e=t.findServiceById(n.serviceIndex);if(!await this.ocean.assets.isUserCustomParametersValid(e.attributes.algoCustomParameters,n.algoCustomParameters))return null}if(u&&e){const t=await Tt.getInstance(this.instanceConfig);await t.setBaseUrl(d);const l=await t.computeStart(u,r,n,s,e,o,a,i,h);return l?l[0]:null}return null}async stop(t,e,i){const{did:r,ddo:n}=await pt(e,this.ocean),s=n.findServiceByType("compute"),{serviceEndpoint:o}=s,a=await Tt.getInstance(this.instanceConfig);await a.setBaseUrl(o);const h=await a.computeStop(r,t,i);return h?h[0]:null}async delete(t,e,i){const{did:r,ddo:n}=await pt(e,this.ocean),s=n.findServiceByType("compute"),{serviceEndpoint:o}=s,a=await Tt.getInstance(this.instanceConfig);await a.setBaseUrl(o);const h=await a.computeDelete(r,t,i);return h?h[0]:null}async status(t,e,i,r,n,s){let o;if(e||r||i){if(!r){if(!i&&!(i=await this.ocean.assets.resolve(e)))throw new Error(`Couldn't resolve the did ${e}`);if(!(r=i.findServiceByType("compute")))throw new Error(`Couldn't find a compute service on the asset with did ${e}`)}const{serviceEndpoint:t}=r;o=await Tt.getInstance(this.instanceConfig),await o.setBaseUrl(t)}else o=this.ocean.provider;return await o.computeStatus(e,t,n,s)}async getResult(t,e,i,r,n,s,o){let a;if(n||o||s){if(!o){if(!s&&!(s=await this.ocean.assets.resolve(n)))throw new Error(`Couldn't resolve the did ${n}`);if(!(o=s.findServiceByType("compute")))throw new Error(`Couldn't find a compute service on the asset with did ${n}`)}const{serviceEndpoint:t}=o;a=await Tt.getInstance(this.instanceConfig),await a.setBaseUrl(t)}else a=this.ocean.provider;return await a.computeResult(e,i,r,t)}createServerAttributes(t,e,i,r,n,s,o,a){return{serverId:t,serverType:e,cost:i,cpu:r,gpu:n,memory:s,disk:o,maxExecutionTime:a}}createContainerAttributes(t,e,i){return{image:t,tag:e,checksum:i}}createClusterAttributes(t,e){return{type:t,url:e}}createProviderAttributes(t,e,i,r,n){return{type:t,description:e,environment:{cluster:i,supportedServers:n,supportedContainers:r}}}createComputeService(t,e,i,r,n,s,o,a){s||(s=3600);const h={type:"compute",index:3,serviceEndpoint:o||this.ocean.provider.url,attributes:{main:{name:"dataAssetComputingService",creator:t.getId(),datePublished:i,cost:e,timeout:s,provider:r,privacy:{}}}};return n&&(h.attributes.main.privacy=n),null!=a&&a.userCustomParameters&&(h.attributes.userCustomParameters=a.userCustomParameters),null!=a&&a.algoCustomParameters&&(h.attributes.algoCustomParameters=a.algoCustomParameters),h}checkOutput(t,e){return e&&(e.publishAlgorithmLog||e.publishOutput)?{publishAlgorithmLog:e.publishAlgorithmLog,publishOutput:e.publishOutput,providerAddress:e.providerAddress||this.config.providerAddress,providerUri:e.providerUri||this.config.providerUri,metadataUri:e.metadataUri||this.config.metadataCacheUri,nodeUri:e.nodeUri||this.config.nodeUri,owner:e.owner||t.getId()}:{publishAlgorithmLog:!1,publishOutput:!1}}async isOrderable(t,e,i,r){const n=await pt(t,this.ocean),s=n.ddo.findServiceById(e);if(!s)return!1;if("compute"===s.type){if(i.meta)return!(!s.attributes.main.privacy||!s.attributes.main.privacy.allowRawAlgorithm)||(this.logger.error("ERROR: This service does not allow raw algorithm"),!1);if(i.did){if(i.serviceIndex){if(!r&&!(r=await this.ocean.assets.resolve(i.did)))throw new Error(`Couldn't resolve the did ${i.did}`);const t=r.findServiceById(i.serviceIndex);if(t&&"compute"===t.type){const e=await Tt.getInstance(this.instanceConfig);await e.setBaseUrl(t.serviceEndpoint);const i=await Tt.getInstance(this.instanceConfig);if(await i.setBaseUrl(s.serviceEndpoint),e.providerAddress!==i.providerAddress)return this.logger.error("ERROR: Both assets with compute service are not served by the same provider"),!1}}if(s.attributes.main.privacy){if(s.attributes.main.privacy.allowAllPublishedAlgorithms)return!0;if(!s.attributes.main.privacy.publisherTrustedAlgorithms)return!1;let t;for(t of s.attributes.main.privacy.publisherTrustedAlgorithms)if(t.did===i.did){const e=await this.createPublisherTrustedAlgorithmfromDID(i.did);return t.containerSectionChecksum&&t.containerSectionChecksum!==e.containerSectionChecksum?(this.logger.error("ERROR: Algorithm container section was altered since it was added as trusted by "+n.did),!1):!t.filesChecksum||t.filesChecksum===e.filesChecksum||(this.logger.error("ERROR: Algorithm files section was altered since it was added as trusted by "+n.ddo),!1)}return this.logger.error("ERROR: Algorithm "+i.did+" is not allowed by "+n.did),!1}console.error("Algo Index:"+i.serviceIndex)}}return!0}orderAsset(t,e,i,r,n,s,o,a="json",h=!0){return new K(async u=>{const{ddo:l}=await pt(e,this.ocean);if(!await this.isOrderable(l,i,r))throw new Error("Dataset order failed, dataset is not orderable with the specified algorithm");const c=l.findServiceById(i);if(!c)throw new Error("Dataset order failed, Could not find service for the DDO");try{return await this.ocean.assets.order(l,c.type,t,-1,n,s,o,a,h)}catch(t){throw this.logger.error(`ERROR: Failed to order: ${t.message}`),new Error(`Failed to order dataset: ${t.message}`)}})}async orderAlgorithm(t,e,i,r=-1,n,s,o,a="json",h=!0){try{return await this.ocean.assets.order(t,e,i,r,n,s,o,a,h)}catch(t){throw this.logger.error(`ERROR: Failed to orderAlgorithm: ${t.message}`),new Error(`Failed to order algorithm: ${t.message}`)}}async editComputePrivacy(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return null;e=i.index}return void 0===t.service[e]||"compute"!==t.service[e].type?null:(t.service[e].attributes.main.privacy.allowRawAlgorithm=i.allowRawAlgorithm,t.service[e].attributes.main.privacy.allowAllPublishedAlgorithms=i.allowAllPublishedAlgorithms,t.service[e].attributes.main.privacy.allowNetworkAccess=i.allowNetworkAccess,t.service[e].attributes.main.privacy.publisherTrustedAlgorithms=i.publisherTrustedAlgorithms,t)}async toggleAllowAllPublishedAlgorithms(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return null;e=i.index}return void 0===t.service[e]||"compute"!==t.service[e].type?null:(t.service[e].attributes.main.privacy.allowAllPublishedAlgorithms=i,t)}async createPublisherTrustedAlgorithmfromDID(t,e){if(!e&&!(e=await this.ocean.assets.resolve(t)))return null;const i=e.findServiceByType("metadata");return i&&i.attributes.main.algorithm&&i.attributes.encryptedFiles&&i.attributes.main.files?{did:t,containerSectionChecksum:m.SHA256(JSON.stringify(i.attributes.main.algorithm.container)).toString(),filesChecksum:m.SHA256(i.attributes.encryptedFiles+JSON.stringify(i.attributes.main.files)).toString()}:null}async addTrustedAlgorithmtoAsset(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return null;e=i.index}if(void 0===t.service[e])return null;if("compute"!==t.service[e].type)return null;t.service[e].attributes.main.privacy.publisherTrustedAlgorithms||(t.service[e].attributes.main.privacy.publisherTrustedAlgorithms=[]);const r=await this.createPublisherTrustedAlgorithmfromDID(i);return r&&t.service[e].attributes.main.privacy.publisherTrustedAlgorithms.push(r),t}async isAlgorithmTrusted(t,e,i){if(!t)return!1;if(-1===e){const i=t.findServiceByType("compute");if(!i)return!1;e=i.index}if(void 0===t.service[e])return!1;if("compute"!==t.service[e].type)return!1;if(t.service[e].attributes.main.privacy.allowAllPublishedAlgorithms)return!0;let r;for(r of t.service[e].attributes.main.privacy.publisherTrustedAlgorithms)if(r.did===i)return!0;return!1}async removeTrustedAlgorithmFromAsset(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return t;e=i.index}return void 0===t.service[e]||"compute"!==t.service[e].type?t:t.service[e].attributes.main.privacy.publisherTrustedAlgorithms?(t.service[e].attributes.main.privacy.publisherTrustedAlgorithms=t.service[e].attributes.main.privacy.publisherTrustedAlgorithms.filter(function(t){return t.did!==i}),t):t}}const Xe="115792089237316195423570985008687907853269984665640564039457584007913129639934";var Qe,Ye,ti,ei;!function(t){t[t.CreatingPool=0]="CreatingPool",t[t.ApprovingDatatoken=1]="ApprovingDatatoken",t[t.ApprovingOcean=2]="ApprovingOcean",t[t.SetupPool=3]="SetupPool"}(Qe||(Qe={}));class ii extends class extends class{constructor(t,e,i=null,r=null,n){this.GASLIMIT_DEFAULT=1e6,this.web3=null,this.factoryABI=void 0,this.factoryAddress=void 0,this.logger=void 0,this.config=void 0,this.web3=t,this.factoryABI=i||P.default.abi,r&&(this.factoryAddress=r),this.logger=e,this.config=n}async createPool(t){if(null===this.web3)return this.logger.error("ERROR: Web3 object is null"),null;if(null===this.factoryAddress)return this.logger.error("ERROR: bfactoryAddress is null"),null;const e=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress,{from:t}),this.config);let i=null;const r=this.GASLIMIT_DEFAULT;let n;try{n=await e.methods.newBPool().estimateGas({from:t},(t,e)=>t?r:e)}catch(t){this.logger.log("Error estimate gas newBPool"),this.logger.log(t),n=r}try{i=await e.methods.newBPool().send({from:t,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to create new pool: ${t.message}`)}return i}}{constructor(t,e,i=null,r=null,n=null,s){super(t,e,i,n,s),this.poolABI=void 0,this.poolABI=r||_.default.abi}async createPool(t){return await super.createPool(t)}async setup(t,e,i,r,n,s,o,a,h){const u=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let l=null;const c=this.GASLIMIT_DEFAULT;let d;try{d=await u.methods.setup(i,r,n,s,o,a,h).estimateGas({from:t},(t,e)=>t?c:e)}catch(t){d=c}try{l=await u.methods.setup(i,r,n,s,o,a,h).send({from:t,gas:d,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to setup a pool: ${t.message}`)}return l}async allowance(t,e,i){const r=mt(new this.web3.eth.Contract(C.default.abi,t,{from:i}),this.config),n=await r.methods.allowance(e,i).call();return this.web3.utils.fromWei(n)}async approve(t,e,i,r,n=!1){const s=mt(new this.web3.eth.Contract([{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],e,{from:t}),this.config);if(!n){const n=await this.allowance(e,t,i);if(new x.default(this.web3.utils.toWei(n)).greaterThanOrEqualTo(r))return n}let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.approve(i,r).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.approve(i,r).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERRPR: Failed to approve spender to spend tokens : ${t.message}`)}return o}async sharesBalance(t,e){let i=null;try{const r=mt(new this.web3.eth.Contract(this.poolABI,e),this.config),n=await r.methods.balanceOf(t).call();i=this.web3.utils.fromWei(n)}catch(t){this.logger.error(`ERROR: Failed to get shares of pool : ${t.message}`)}return i}async addToPool(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let n;for(n of i)try{await this.approve(t,n.address,e,this.web3.utils.toWei(`${n.amount}`)),await r.methods.bind(n.address,this.web3.utils.toWei(n.amount),this.web3.utils.toWei(n.weight)).send({from:t,gas:this.GASLIMIT_DEFAULT,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to add tokens to pool: ${t.message}`)}}async setSwapFee(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let n=null;try{n=await r.methods.setSwapFee(this.web3.utils.toWei(i)).send({from:t,gas:this.GASLIMIT_DEFAULT,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to set pool swap fee: ${t.message}`)}return n}async finalize(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let r=null;try{r=await i.methods.finalize().send({from:t,gas:this.GASLIMIT_DEFAULT,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to finalize pool: ${t.message}`)}return r}async getNumTokens(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getNumTokens().call()}catch(t){this.logger.error(`ERROR: Failed to get number of tokens: ${t.message}`)}return i}async getPoolSharesTotalSupply(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{const t=await e.methods.totalSupply().call();i=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to get total supply of pool shares: ${t.message}`)}return i}async getCurrentTokens(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getCurrentTokens().call()}catch(t){this.logger.error(`ERROR: Failed to get tokens composing this pool: ${t.message}`)}return i}async getFinalTokens(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getFinalTokens().call()}catch(t){this.logger.error("ERROR: Failed to get the final tokens composing this pool")}return i}async getController(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getController().call()}catch(t){this.logger.error(`ERROR: Failed to get pool controller address: ${t.message}`)}return i}async setController(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let n=null;try{n=await r.methods.setController(i).send({from:t,gas:this.GASLIMIT_DEFAULT})}catch(t){this.logger.error(`ERROR: Failed to set pool controller: ${t.message}`)}return n}async isBound(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let r=null;try{r=await i.methods.isBound(e).call()}catch(t){this.logger.error(`ERROR: Failed to check whether a token bounded to a pool. ${t.message}`)}return r}async getReserve(t,e){let i=null;try{const r=mt(new this.web3.eth.Contract(this.poolABI,t),this.config),n=await r.methods.getBalance(e).call();i=this.web3.utils.fromWei(n)}catch(t){this.logger.error(`ERROR: Failed to get how many tokens are in the pool: ${t.message}`)}return i}async isFinalized(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.isFinalized().call()}catch(t){this.logger.error(`ERROR: Failed to check whether pool is finalized: ${t.message}`)}return i}async getSwapFee(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{const t=await e.methods.getSwapFee().call();i=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to get pool fee: ${t.message}`)}return i}async getNormalizedWeight(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let r=null;try{const t=await i.methods.getNormalizedWeight(e).call();r=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to get normalized weight of a token: ${t.message}`)}return r}async getDenormalizedWeight(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let r=null;try{const t=await i.methods.getDenormalizedWeight(e).call();r=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to get denormalized weight of a token in pool")}return r}async getTotalDenormalizedWeight(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{const t=await e.methods.getTotalDenormalizedWeight().call();i=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to get total denormalized weight in pool")}return i}async swapExactAmountIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let h=null;const u=this.GASLIMIT_DEFAULT;let l;try{l=await a.methods.swapExactAmountIn(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).estimateGas({from:t},(t,e)=>t?u:e)}catch(t){this.logger.log("Error estimate gas swapExactAmountIn"),this.logger.log(t),l=u}try{h=await a.methods.swapExactAmountIn(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).send({from:t,gas:l+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to swap exact amount in : ${t.message}`)}return h}async swapExactAmountOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let h=null;const u=this.GASLIMIT_DEFAULT;let l;try{l=await a.methods.swapExactAmountOut(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).estimateGas({from:t},(t,e)=>t?u:e)}catch(t){l=u,this.logger.log("Error estimate gas swapExactAmountIn"),this.logger.log(t)}try{h=await a.methods.swapExactAmountOut(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).send({from:t,gas:l+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to swap exact amount out: ${t.message}`)}return h}async joinPool(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config),s=[];let o;for(o of r)s.push(this.web3.utils.toWei(o));let a=null;const h=this.GASLIMIT_DEFAULT;let u;try{u=await n.methods.joinPool(this.web3.utils.toWei(i),s).estimateGas({from:t},(t,e)=>t?h:e)}catch(t){u=h}try{a=await n.methods.joinPool(this.web3.utils.toWei(i),s).send({from:t,gas:u+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to join pool: ${t.message}`)}return a}async exitPool(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config),s=[];let o;for(o of r)s.push(this.web3.utils.toWei(o));let a=null;const h=this.GASLIMIT_DEFAULT;let u;try{u=await n.methods.exitPool(this.web3.utils.toWei(i),s).estimateGas({from:t},(t,e)=>t?h:e)}catch(t){u=h}try{a=await n.methods.exitPool(this.web3.utils.toWei(i),s).send({from:t,gas:u,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to exit pool: ${t.message}`)}return a}async joinswapExternAmountIn(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.joinswapExternAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.joinswapExternAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to pay tokens in order to join the pool: ${t.message}`)}return o}async joinswapPoolAmountOut(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.joinswapPoolAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.joinswapPoolAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error("ERROR: Failed to join swap pool amount out")}return o}async exitswapPoolAmountIn(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.exitswapPoolAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.exitswapPoolAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to pay pool shares into the pool: ${t.message}`)}return o}async exitswapExternAmountOut(t,e,i,r,n){const s=this.GASLIMIT_DEFAULT,o=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let a,h=null;try{a=await o.methods.exitswapExternAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?s:e)}catch(t){a=s}try{h=await o.methods.exitswapExternAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:a+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error("ERROR: Failed to exitswapExternAmountOut")}return h}async getSpotPrice(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let n=null;try{const t=await r.methods.getSpotPrice(e,i).call();n=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to get spot price of swapping tokenIn to tokenOut")}return n}async getSpotPriceSansFee(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let n=null;try{const t=await r.methods.getSpotPriceSansFee(e,i).call();n=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to getSpotPriceSansFee")}return n}async calcSpotPrice(t,e,i,r,n,s){const o=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let a="0";try{const t=await o.methods.calcSpotPrice(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s)).call();a=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to call calcSpotPrice")}return a}async calcInGivenOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;if(new x.default(s).gte(r))return null;try{const t=await a.methods.calcInGivenOut(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to calcInGivenOut")}return h}async calcOutGivenIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcOutGivenIn(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to calcOutGivenIn")}return h}async calcPoolOutGivenSingleIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcPoolOutGivenSingleIn(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate PoolOutGivenSingleIn : ${t.message}`)}return h}async calcSingleInGivenPoolOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcSingleInGivenPoolOut(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${t.message}`)}return h}async calcSingleOutGivenPoolIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcSingleOutGivenPoolIn(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${t.message}`)}return h}async calcPoolInGivenSingleOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcPoolInGivenSingleOut(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate PoolInGivenSingleOut : ${t.message}`)}return h}getSwapEventSignature(){const t=this.poolABI.find(function(t){if("LOG_SWAP"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}getJoinEventSignature(){const t=this.poolABI.find(function(t){if("LOG_JOIN"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}getExitEventSignature(){const t=this.poolABI.find(function(t){if("LOG_EXIT"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}}{constructor(t,e,i=null,r=null,n=null,s=null,o){super(t,e,i,r,n,o),this.oceanAddress=null,this.dtAddress=null,this.startBlock=void 0,s&&(this.oceanAddress=s),this.startBlock=o&&o.startBlock||0}create(t,e,i,r,n,s){if(null==this.oceanAddress)throw this.logger.error("ERROR: oceanAddress is not defined"),new Error("ERROR: oceanAddress is not defined");if(parseFloat(s)>.1)throw this.logger.error("ERROR: Swap fee too high. The maximum allowed swapFee is 10%"),new Error("ERROR: Swap fee too high. The maximum allowed swapFee is 10%");if(parseFloat(i)<2)throw this.logger.error("ERROR: Amount of DT is too low"),new Error("ERROR: Amount of DT is too low");if(parseFloat(r)>9||parseFloat(r)<1)throw this.logger.error("ERROR: Weight out of bounds (min 1, max9)"),new Error("ERROR: Weight out of bounds (min 1, max9)");return new K(async o=>{o.next(Qe.CreatingPool);const a=await super.createPool(t);if(!a)throw this.logger.error("ERROR: Failed to call create pool"),new Error("ERROR: Failed to call create pool");const h=a.events.BPoolRegistered.returnValues[0],u=10-parseFloat(r);let l;if(this.dtAddress=e,o.next(Qe.ApprovingDatatoken),l=await this.approve(t,e,h,this.web3.utils.toWei(String(i))),!l)throw this.logger.error("ERROR: Failed to call approve DT token"),new Error("ERROR: Failed to call approve DT token");if(o.next(Qe.ApprovingOcean),l=await this.approve(t,this.oceanAddress,h,this.web3.utils.toWei(String(n))),!l)throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");if(o.next(Qe.SetupPool),l=await super.setup(t,h,e,this.web3.utils.toWei(String(i)),this.web3.utils.toWei(String(r)),this.oceanAddress,this.web3.utils.toWei(String(n)),this.web3.utils.toWei(String(u)),this.web3.utils.toWei(s)),!l)throw this.logger.error("ERROR: Failed to create a new pool"),new Error("ERROR: Failed to create a new pool");return a})}async getDTAddress(t){this.dtAddress=null;const e=await this.getCurrentTokens(t);let i;if(null!=e)for(i of e)i.toLowerCase()!==this.oceanAddress.toLowerCase()&&(this.dtAddress=i);return this.dtAddress}async getOceanReserve(t){return null==this.oceanAddress?(this.logger.error("ERROR: oceanAddress is not defined"),null):super.getReserve(t,this.oceanAddress)}async getDTReserve(t){const e=await this.getDTAddress(t);return super.getReserve(t,e)}async getMaxBuyQuantity(t,e){const i=await super.getReserve(t,e);return new x.default(i).div(3).toString()}async getOceanMaxBuyQuantity(t){return this.getMaxBuyQuantity(t,this.oceanAddress)}async getDTMaxBuyQuantity(t){return this.getMaxBuyQuantity(t,await this.getDTAddress(t))}async calcInGivenOut(t,e,i,r){return await super.calcInGivenOut(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getReserve(t,i),await super.getDenormalizedWeight(t,i),r,await this.getSwapFee(t))}async calcOutGivenIn(t,e,i,r){return await super.calcOutGivenIn(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getReserve(t,i),await super.getDenormalizedWeight(t,i),r,await super.getSwapFee(t))}async calcPoolOutGivenSingleIn(t,e,i){return super.calcPoolOutGivenSingleIn(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async calcSingleInGivenPoolOut(t,e,i){return super.calcSingleInGivenPoolOut(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async calcSingleOutGivenPoolIn(t,e,i){return super.calcSingleOutGivenPoolIn(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async calcPoolInGivenSingleOut(t,e,i){return super.calcPoolInGivenSingleOut(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async getPoolSharesRequiredToRemoveDT(t,e){const i=await this.getDTAddress(t);return this.calcPoolInGivenSingleOut(t,i,e)}async getDTRemovedforPoolShares(t,e){const i=await this.getDTAddress(t);return this.calcSingleOutGivenPoolIn(t,i,e)}async getPoolSharesRequiredToRemoveOcean(t,e){return this.calcPoolInGivenSingleOut(t,this.oceanAddress,e)}async getOceanRemovedforPoolShares(t,e){return this.calcSingleOutGivenPoolIn(t,this.oceanAddress,e)}async getTokensRemovedforPoolShares(t,e){try{const i=await this.getPoolSharesTotalSupply(t),r=await this.getDTReserve(t),n=await this.getOceanReserve(t);return{dtAmount:new x.default(e).div(i).mul(r).toString(),oceanAmount:new x.default(e).div(i).mul(n).toString()}}catch(t){this.logger.error(`ERROR: Unable to get token info. ${t.message}`)}}async getDTMaxAddLiquidity(t){const e=await this.getDTAddress(t);return this.getMaxAddLiquidity(t,e)}async getOceanMaxAddLiquidity(t){return this.getMaxAddLiquidity(t,this.oceanAddress)}async getMaxAddLiquidity(t,e){const i=await super.getReserve(t,e);return parseFloat(i)>0?new x.default(i).mul(.25).toString():"0"}async getMaxRemoveLiquidity(t,e){const i=await super.getReserve(t,e);return parseFloat(i)>0?new x.default(i).mul(.25).toString():"0"}async getDTMaxRemoveLiquidity(t){const e=await this.getDTAddress(t);return this.getMaxRemoveLiquidity(t,e)}async getOceanMaxRemoveLiquidity(t){return this.getMaxRemoveLiquidity(t,this.oceanAddress)}async buyDT(t,e,i,r,n){if(null==this.oceanAddress)return this.logger.error("ERROR: undefined ocean token contract address"),null;const s=await this.getDTAddress(e);if(new x.default(i).greaterThan(await this.getDTMaxBuyQuantity(e)))return this.logger.error("ERROR: Buy quantity exceeds quantity allowed"),null;const o=await this.getOceanNeeded(e,i);if(new x.default(o).greaterThan(r))return this.logger.error("ERROR: Not enough Ocean Tokens"),null;if(!await super.approve(t,this.oceanAddress,e,this.web3.utils.toWei(r)))throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");return await super.swapExactAmountOut(t,e,this.oceanAddress,r,s,i,n)}async buyDTWithExactOcean(t,e,i,r,n){if(null==this.oceanAddress)return this.logger.error("ERROR: undefined ocean token contract address"),null;const s=await this.getDTAddress(e);if(new x.default(i).greaterThan(await this.getDTMaxBuyQuantity(e)))return this.logger.error("ERROR: Buy quantity exceeds quantity allowed"),null;const o=await this.getOceanNeeded(e,i);if(new x.default(o).greaterThan(r))return this.logger.error("ERROR: Not enough Ocean Tokens"),null;if(!await super.approve(t,this.oceanAddress,e,this.web3.utils.toWei(r)))throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");return await super.swapExactAmountIn(t,e,this.oceanAddress,r,s,i,n)}async sellDT(t,e,i,r,n){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const s=await this.getDTAddress(e);if(new x.default(r).greaterThan(await this.getOceanMaxBuyQuantity(e)))return this.logger.error("ERROR: Buy quantity exceeds quantity allowed"),null;const o=await this.getOceanReceived(e,i);if(new x.default(o).lessThan(r))return this.logger.error("ERROR: Not enough datatokens"),null;if(!await super.approve(t,s,e,this.web3.utils.toWei(i)))throw this.logger.error("ERROR: Failed to call approve DT token"),new Error("ERROR: Failed to call approve DT token");return await super.swapExactAmountIn(t,e,s,i,this.oceanAddress,r,n)}async addDTLiquidity(t,e,i){const r=await this.getDTAddress(e),n=await this.getMaxAddLiquidity(e,r);if(new x.default(i).greaterThan(n))return this.logger.error("ERROR: Too much reserve to add"),null;if(!await super.approve(t,r,e,this.web3.utils.toWei(i)))throw this.logger.error("ERROR: Failed to call approve DT token"),new Error("ERROR: Failed to call approve DT token");return await super.joinswapExternAmountIn(t,e,r,i,"0")}async removeDTLiquidity(t,e,i,r){const n=await this.getDTAddress(e),s=await this.getDTMaxRemoveLiquidity(e);if(new x.default(i).greaterThan(s))return this.logger.error("ERROR: Too much reserve to remove"),null;const o=await this.sharesBalance(t,e);if(new x.default(o).lessThan(r))return this.logger.error("ERROR: Not enough poolShares"),null;const a=await this.getPoolSharesRequiredToRemoveDT(e,i);return new x.default(r).lessThan(a)?(this.logger.error("ERROR: Not enough poolShares"),null):(new x.default(r).lessThan(a)&&(r=new x.default(r).mul(.9999).toString()),this.exitswapExternAmountOut(t,e,n,i,r))}async addOceanLiquidity(t,e,i){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const r=await this.getOceanMaxAddLiquidity(e);if(new x.default(i).greaterThan(r))return this.logger.error("ERROR: Too much reserve to add"),null;if(!await super.approve(t,this.oceanAddress,e,this.web3.utils.toWei(i)))throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");return await super.joinswapExternAmountIn(t,e,this.oceanAddress,i,"0")}async removeOceanLiquidityWithMinimum(t,e,i,r){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const n=await this.sharesBalance(t,e);return new x.default(n).lessThan(i)?(this.logger.error("ERROR: Not enough poolShares"),null):super.exitswapPoolAmountIn(t,e,this.oceanAddress,i,r)}async removeOceanLiquidity(t,e,i,r){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const n=await this.getOceanMaxRemoveLiquidity(e);if(new x.default(i).greaterThan(n))return this.logger.error("ERROR: Too much reserve to remove"),null;const s=await this.sharesBalance(t,e);if(new x.default(s).lessThan(r))return this.logger.error("ERROR: Not enough poolShares"),null;const o=await this.getPoolSharesRequiredToRemoveOcean(e,i);return new x.default(r).lessThan(o)?(this.logger.error("ERROR: Not enough poolShares"),null):(new x.default(r).lessThan(o)&&(r=new x.default(r).mul(.9999).toString()),super.exitswapExternAmountOut(t,e,this.oceanAddress,i,r))}async removePoolLiquidity(t,e,i,r="0",n="0"){const s=await this.sharesBalance(t,e);return new x.default(s).lessThan(i)?(this.logger.error("ERROR: Not enough poolShares"),null):(new x.default(s).equals(i)&&(i=new x.default(i).mul(.9999).toString()),this.exitPool(t,e,i,[r,n]))}async getDTPrice(t){return null==this.oceanAddress?(this.logger.error("ERROR: oceanAddress is not defined"),"0"):this.getOceanNeeded(t,"1")}async searchPoolforDT(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});r.sort((t,e)=>t.blockNumber>e.blockNumber?1:-1);for(let i=0;i<r.length;i++)(await super.getCurrentTokens(r[i].returnValues[0])).includes(t)&&e.push(r[i].returnValues[0]);return e}async getOceanNeeded(t,e){const i=await this.getDTAddress(t);return new x.default(e).greaterThan(await this.getDTMaxBuyQuantity(t))?"0":this.calcInGivenOut(t,this.oceanAddress,i,e)}async getOceanReceived(t,e){const i=await this.getDTAddress(t);return this.calcOutGivenIn(t,i,this.oceanAddress,e)}async getDTReceived(t,e){const i=await this.getDTAddress(t);return this.calcOutGivenIn(t,this.oceanAddress,i,e)}async getDTNeeded(t,e){const i=await this.getDTAddress(t);return new x.default(e).greaterThan(await this.getOceanMaxBuyQuantity(t))?"0":this.calcInGivenOut(t,i,this.oceanAddress,e)}async getPoolsbyCreator(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:t?{registeredBy:t}:{},fromBlock:this.startBlock,toBlock:"latest"});for(let i=0;i<r.length;i++)t&&r[i].returnValues[1].toLowerCase()!==t.toLowerCase()||e.push(await this.getPoolDetails(r[i].returnValues[0]));return e}async getResult(t,e){const i=await super.sharesBalance(t,e.returnValues[0]);if(parseFloat(i)>0){const t=await this.getDTAddress(e.returnValues[0]);if(t)return{shares:i,poolAddress:e.returnValues[0],did:G(Z(t))}}}async getPoolSharesByAddress(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});let n=[];for(let i=0;i<r.length;i++)if(n.push(this.getResult(t,r[i])),n.length>10){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}if(n.length>0){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}return e.filter(t=>void 0!==t)}async getPoolDetails(t){return{poolAddress:t,tokens:await super.getFinalTokens(t)}}async getPoolLogs(t,e=0,i){const r=[],n=await this.getDTAddress(t);0===e&&(e=this.startBlock);const s=super.getSwapEventSignature(),o=super.getJoinEventSignature(),a=super.getExitEventSignature();let h;h=i?"0x000000000000000000000000"+i.substring(2).toLowerCase():null;const u=await this.web3.eth.getPastLogs({address:t,topics:[[s,o,a],h],fromBlock:e,toBlock:"latest"});let l=[];for(let e=0;e<u.length;e++)if(l.push(this.getEventData(t,n,u[e])),l.length>10){const t=await Promise.all(l);for(let e=0;e<t.length;e++)r.push(t[e]);l=[]}if(l.length>0){const t=await Promise.all(l);for(let e=0;e<t.length;e++)r.push(t[e]);l=[]}return r.filter(t=>void 0!==t)}async getAllPoolLogs(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});let n=[];for(let i=0;i<r.length;i++)if(n.push(this.getPoolLogs(r[i].returnValues[0],r[i].blockNumber,t)),n.length>10){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}if(n.length>0){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}return e.reduce((t,e)=>t.concat(e))}async getEventData(t,e,i){const r=await this.web3.eth.getBlock(i.blockNumber),n=super.getSwapEventSignature(),s=super.getJoinEventSignature(),o=super.getExitEventSignature();let a;switch(i.topics[0]){case n:a="swap";break;case s:a="join";break;case o:a="exit"}let h,u={poolAddress:t,dtAddress:e,caller:i.topics[1],transactionHash:i.transactionHash,blockNumber:i.blockNumber,timestamp:parseInt(String(r.timestamp)),type:a};switch(a){case"swap":h=this.web3.eth.abi.decodeParameters(["uint256","uint256"],i.data),u=W({},u,{tokenIn:"0x"+i.topics[2].substring(i.topics[2].length-40),tokenOut:"0x"+i.topics[3].substring(i.topics[3].length-40),tokenAmountIn:this.web3.utils.fromWei(h[0]),tokenAmountOut:this.web3.utils.fromWei(h[1])});break;case"join":h=this.web3.eth.abi.decodeParameters(["uint256"],i.data),u=W({},u,{tokenIn:"0x"+i.topics[2].substring(i.topics[2].length-40),tokenAmountIn:this.web3.utils.fromWei(h[0])});break;case"exit":h=this.web3.eth.abi.decodeParameters(["uint256"],i.data),u=W({},u,{tokenOut:"0x"+i.topics[2].substring(i.topics[2].length-40),tokenAmountOut:this.web3.utils.fromWei(h[0])})}return u}async computeSlippage(t,e,i,r,n,s,o,a){const h=await super.calcSpotPrice(t,e,i,r,n,a),u=await super.calcSpotPrice(t,s,i,o,n,a);return new x.default(u).mul(100).div(h).minus(100).toString()}async computeBuySlippage(t,e){const i=await this.getDTAddress(t),r=await super.getDenormalizedWeight(t,i),n=await super.getDenormalizedWeight(t,this.oceanAddress),s=await super.getReserve(t,i),o=await super.getReserve(t,i),a=await super.getSwapFee(t),h=await super.calcOutGivenIn(t,o,n,s,r,e,a),u=new dt(this.web3.utils.toWei(s)).minus(this.web3.utils.toWei(h)),l=new dt(this.web3.utils.toWei(o)).plus(this.web3.utils.toWei(e));return await this.computeSlippage(t,o,n,s,r,this.web3.utils.fromWei(l.toString()),this.web3.utils.fromWei(u.toString()),a)}async computeSellSlippage(t,e){const i=await this.getDTAddress(t),r=await super.getDenormalizedWeight(t,i),n=await super.getDenormalizedWeight(t,this.oceanAddress),s=await super.getReserve(t,i),o=await super.getReserve(t,i),a=await super.getSwapFee(t),h=await super.calcOutGivenIn(t,s,r,o,n,e,a),u=new dt(this.web3.utils.toWei(s)).plus(this.web3.utils.toWei(e)),l=new dt(this.web3.utils.toWei(o)).minus(this.web3.utils.toWei(h));return await this.computeSlippage(t,s,r,o,n,this.web3.utils.fromWei(u.toString()),this.web3.utils.fromWei(l.toString()),a)}}!function(t){t[t.CreatingExchange=0]="CreatingExchange",t[t.ApprovingDatatoken=1]="ApprovingDatatoken"}(Ye||(Ye={}));class ri{constructor(t,e,i=null,r=null,n=null,s,o){this.GASLIMIT_DEFAULT=1e6,this.oceanAddress=null,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeABI=void 0,this.web3=void 0,this.contract=null,this.logger=void 0,this.datatokens=void 0,this.startBlock=void 0,this.config=void 0,this.web3=t,this.fixedRateExchangeAddress=i,this.config=o,this.startBlock=o&&o.startBlock||0,this.fixedRateExchangeABI=r||D.default.abi,this.oceanAddress=n,this.datatokens=s,t&&(this.contract=mt(new this.web3.eth.Contract(this.fixedRateExchangeABI,this.fixedRateExchangeAddress),this.config)),this.logger=e}create(t,e,i,r){return this.createExchange(this.oceanAddress,t,e,i,r)}createExchange(t,e,i,r,n){return new K(async s=>{let o;s.next(Ye.CreatingExchange);const a=this.GASLIMIT_DEFAULT;try{o=await this.contract.methods.create(t,e,this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?a:e)}catch(t){o=a}let h=null,u=null;try{u=await this.contract.methods.create(t,e,this.web3.utils.toWei(i)).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)}),h=u.events.ExchangeCreated.returnValues[0]}catch(t){this.logger.error(`ERROR: Failed to create new exchange: ${t.message}`)}return n&&h&&(s.next(Ye.ApprovingDatatoken),this.datatokens.approve(e,this.fixedRateExchangeAddress,n,r)),u})}async generateExchangeId(t,e){return await this.contract.methods.generateExchangeId(this.oceanAddress,t,e).call()}async buyDT(t,e,i){const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.swap(t,this.web3.utils.toWei(String(e))).estimateGas({from:i},(t,e)=>t?r:e)}catch(t){n=r}try{return await this.contract.methods.swap(t,this.web3.utils.toWei(String(e))).send({from:i,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error(`ERROR: Failed to buy datatokens: ${t.message}`),null}}async getNumberOfExchanges(){return await this.contract.methods.getNumberOfExchanges().call()}async setRate(t,e,i){const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.setRate(t,this.web3.utils.toWei(String(e))).estimateGas({from:i},(t,e)=>t?r:e)}catch(t){n=r}return await this.contract.methods.setRate(t,this.web3.utils.toWei(String(e))).send({from:i,gas:n+1,gasPrice:await ft(this.web3,this.config)})}async activate(t,e){const i=await this.getExchange(t);if(!i)return null;if(!0===i.active)return null;const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.toggleExchangeState(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){n=r}return await this.contract.methods.toggleExchangeState(t).send({from:e,gas:n+1,gasPrice:await ft(this.web3,this.config)})}async deactivate(t,e){const i=await this.getExchange(t);if(!i)return null;if(!1===i.active)return null;const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.toggleExchangeState(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){n=r}return await this.contract.methods.toggleExchangeState(t).send({from:e,gas:n+1,gasPrice:await ft(this.web3,this.config)})}async getRate(t){const e=await this.contract.methods.getRate(t).call();return this.web3.utils.fromWei(e)}async getSupply(t){const e=await this.contract.methods.getSupply(t).call();return this.web3.utils.fromWei(e)}async getOceanNeeded(t,e){const i=await this.contract.methods.CalcInGivenOut(t,this.web3.utils.toWei(e)).call();return this.web3.utils.fromWei(i)}async getExchange(t){const e=await this.contract.methods.getExchange(t).call();return e.fixedRate=this.web3.utils.fromWei(e.fixedRate),e.supply=this.web3.utils.fromWei(e.supply),e.exchangeID=t,e}async getExchanges(){return await this.contract.methods.getExchanges().call()}async isActive(t){return await this.contract.methods.isActive(t).call()}async CalcInGivenOut(t,e){const i=await this.contract.methods.CalcInGivenOut(t,this.web3.utils.toWei(e)).call();return this.web3.utils.fromWei(i)}async searchforDT(t,e){const i=[],r=await this.contract.getPastEvents("ExchangeCreated",{filter:{datatoken:t.toLowerCase()},fromBlock:this.startBlock,toBlock:"latest"});let n=[];for(let s=0;s<r.length;s++)if(n.push(this.getExchange(r[s].returnValues[0])),n.length>10||s===r.length-1){const r=await Promise.all(n);for(let n=0;n<r.length;n++){const s=r[n];if(!0===s.active&&s.dataToken.toLowerCase()===t.toLowerCase()){const t=new dt(s.supply),r=new dt(e);t.gte(r)&&i.push(s)}}n=[]}return i}async getExchangesbyCreator(t){const e=[],i=await this.contract.getPastEvents("ExchangeCreated",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});for(let r=0;r<i.length;r++)t&&i[r].returnValues[3].toLowerCase()!==t.toLowerCase()||e.push(await this.getExchange(i[r].returnValues[0]));return e}async getExchangeSwaps(t,e){const i=[],r=await this.contract.getPastEvents("Swapped",{filter:{exchangeId:t},fromBlock:this.startBlock,toBlock:"latest"});for(let t=0;t<r.length;t++)e&&r[t].returnValues[1].toLowerCase()!==e.toLowerCase()||i.push(this.getEventData(r[t]));return i}async getAllExchangesSwaps(t){const e=[],i=await this.contract.getPastEvents("ExchangeCreated",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});for(let r=0;r<i.length;r++)(await this.getExchangeSwaps(i[r].returnValues[0],t)).forEach(t=>{e.push(t)});return e}getEventData(t){return{exchangeID:t.returnValues[0],caller:t.returnValues[1],baseTokenAmount:this.web3.utils.fromWei(t.returnValues[2]),dataTokenAmount:this.web3.utils.fromWei(t.returnValues[3])}}}!function(t){t[t.MakeDispenserMinter=0]="MakeDispenserMinter",t[t.AcceptingNewMinter=1]="AcceptingNewMinter"}(ti||(ti={})),function(t){t[t.MakeOwnerMinter=0]="MakeOwnerMinter",t[t.AcceptingNewMinter=1]="AcceptingNewMinter"}(ei||(ei={}));class ni{constructor(t,e,i=null,r=null,n,s){this.GASLIMIT_DEFAULT=1e6,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.web3=void 0,this.contract=null,this.logger=void 0,this.datatokens=void 0,this.startBlock=void 0,this.config=void 0,this.web3=t,this.config=s,this.dispenserAddress=i,this.startBlock=s&&s.startBlock||0,this.dispenserABI=r||L.default.abi,this.datatokens=n,t&&(this.contract=mt(new this.web3.eth.Contract(this.dispenserABI,this.dispenserAddress),this.config)),this.logger=e}async status(t){try{const e=await this.contract.methods.status(t).call();return e.maxTokens=this.web3.utils.fromWei(e.maxTokens),e.maxBalance=this.web3.utils.fromWei(e.maxBalance),e.balance=this.web3.utils.fromWei(e.balance),e}catch(e){this.logger.warn(`No dispenser available for data token: ${t}`)}return null}async activate(t,e,i,r){let n;const s=this.GASLIMIT_DEFAULT;try{n=await this.contract.methods.activate(t,this.web3.utils.toWei(e),this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){n=s}let o=null;try{o=await this.contract.methods.activate(t,this.web3.utils.toWei(e),this.web3.utils.toWei(i)).send({from:r,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to activate dispenser: ${t.message}`)}return o}async deactivate(t,e){let i;const r=this.GASLIMIT_DEFAULT;try{i=await this.contract.methods.deactivate(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){i=r}let n=null;try{n=await this.contract.methods.deactivate(t).send({from:e,gas:i+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to deactivate dispenser: ${t.message}`)}return n}makeMinter(t,e){return new K(async i=>{let r;i.next(ti.MakeDispenserMinter);const n=this.GASLIMIT_DEFAULT;if(!await this.datatokens.proposeMinter(t,this.dispenserAddress,e))return null;i.next(ti.AcceptingNewMinter);try{r=await this.contract.methods.acceptMinter(t).estimateGas({from:e},(t,e)=>t?n:e)}catch(t){r=n}let s=null;try{s=await this.contract.methods.acceptMinter(t).send({from:e,gas:r+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to accept minter role: ${t.message}`)}return s})}cancelMinter(t,e){return new K(async i=>{let r;i.next(ei.MakeOwnerMinter);const n=this.GASLIMIT_DEFAULT;try{r=await this.contract.methods.removeMinter(t).estimateGas({from:e},(t,e)=>t?n:e)}catch(t){r=n}let s=null;try{s=await this.contract.methods.removeMinter(t).send({from:e,gas:r+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to remove minter role: ${t.message}`)}return s?(i.next(ei.AcceptingNewMinter),await this.datatokens.approveMinter(t,e)):null})}async dispense(t,e,i="1"){let r;const n=this.GASLIMIT_DEFAULT;try{r=await this.contract.methods.dispense(t,this.web3.utils.toWei(i)).estimateGas({from:e},(t,e)=>t?n:e)}catch(t){r=n}let s=null;try{s=await this.contract.methods.dispense(t,this.web3.utils.toWei(i)).send({from:e,gas:r+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to dispense tokens: ${t.message}`)}return s}async ownerWithdraw(t,e){let i;const r=this.GASLIMIT_DEFAULT;try{i=await this.contract.methods.ownerWithdraw(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){i=r}let n=null;try{n=await this.contract.methods.ownerWithdraw(t).send({from:e,gas:i+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to withdraw tokens: ${t.message}`)}return n}async isDispensable(t,e,i="1"){const r=await this.status(t);return!(!r||!1===r.active||new x.default(await this.datatokens.balance(t,e)).greaterThanOrEqualTo(r.maxBalance)||new x.default(String(i)).greaterThan(r.maxTokens)||!new x.default(r.balance).greaterThanOrEqualTo(i)&&!0!==r.isTrueMinter)}}class si extends Mt{constructor(...t){super(...t),this.network=void 0,this.provider=void 0,this.eventAccessControl=void 0,this.web3Provider=void 0,this.metadataCache=void 0,this.onChainMetadata=void 0,this.accounts=void 0,this.assets=void 0,this.compute=void 0,this.datatokens=void 0,this.pool=void 0,this.fixedRateExchange=void 0,this.OceanDispenser=void 0,this.versions=void 0,this.utils=void 0}static async getInstance(t){var e;const i=new si,r=W({},function(t){return{config:t,web3:t.web3Provider,logger:U}}(t),{ocean:i});return i.setInstanceConfig(r),i.utils=await je.getInstance(r),i.provider=await Tt.getInstance(r),i.eventAccessControl=await Fe.getInstance(r),i.metadataCache=new ze(r.config.metadataCacheUri,r.logger,null==(e=r.config)?void 0:e.requestTimeout),i.accounts=await xt.getInstance(r),i.assets=await Ue.getInstance(r),i.compute=await Ke.getInstance(r),i.datatokens=new Ze(r.config.factoryAddress,r.config.factoryABI,r.config.datatokensABI,r.config.web3Provider,r.logger,r.config),i.pool=new ii(r.config.web3Provider,r.logger,r.config.poolFactoryABI,r.config.poolABI,r.config.poolFactoryAddress,r.config.oceanTokenAddress,r.config),i.fixedRateExchange=new ri(r.config.web3Provider,r.logger,r.config.fixedRateExchangeAddress,r.config.fixedRateExchangeAddressABI,r.config.oceanTokenAddress,i.datatokens,r.config),i.OceanDispenser=new ni(r.config.web3Provider,r.logger,r.config.dispenserAddress,r.config.dispenserABI,i.datatokens,r.config),i.onChainMetadata=new He(r.config.web3Provider,r.logger,r.config.metadataContractAddress,r.config.metadataContractABI,i.metadataCache,r.config),i.versions=await qe.getInstance(r),i.network=new Ve,i}}const oi={networkId:null,network:"unknown",metadataCacheUri:"https://aquarius.oceanprotocol.com",nodeUri:"http://localhost:8545",providerUri:"http://127.0.0.1:8030",subgraphUri:null,explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",factoryAddress:"0x1234",poolFactoryAddress:null,fixedRateExchangeAddress:null,dispenserAddress:null,metadataContractAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},ai=[W({},oi),W({},oi,{networkId:8996,network:"development",metadataCacheUri:"http://127.0.0.1:5000",rbacUri:"http://127.0.0.1:3000"}),W({},oi,{networkId:3,network:"ropsten",nodeUri:"https://ropsten.infura.io/v3",providerUri:"https://provider.ropsten.oceanprotocol.com",subgraphUri:"https://subgraph.ropsten.oceanprotocol.com",explorerUri:"https://ropsten.etherscan.io",startBlock:9227563}),W({},oi,{networkId:4,network:"rinkeby",nodeUri:"https://rinkeby.infura.io/v3",providerUri:"https://provider.rinkeby.oceanprotocol.com",subgraphUri:"https://subgraph.rinkeby.oceanprotocol.com",explorerUri:"https://rinkeby.etherscan.io",startBlock:7294090}),W({},oi,{networkId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",providerUri:"https://provider.mainnet.oceanprotocol.com",subgraphUri:"https://subgraph.mainnet.oceanprotocol.com",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05}),W({},oi,{networkId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",providerUri:"https://provider.polygon.oceanprotocol.com",subgraphUri:"https://subgraph.polygon.oceanprotocol.com",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",startBlock:11005222,gasFeeMultiplier:1.05}),W({},oi,{networkId:1287,network:"moonbeamalpha",nodeUri:"https://rpc.testnet.moonbeam.network",providerUri:"https://provider.moonbeamalpha.oceanprotocol.com",subgraphUri:"https://subgraph.moonbeamalpha.oceanprotocol.com",explorerUri:"https://moonbase-blockscout.testnet.moonbeam.network/",startBlock:90707}),W({},oi,{networkId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",providerUri:"https://provider.gaiaxtestnet.oceanprotocol.com",subgraphUri:"https://subgraph.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com"}),W({},oi,{networkId:2021001,network:"catenaxtestnet",nodeUri:"https://rpc.catenaxtestnet.oceanprotocol.com",providerUri:"https://provider.catenaxtestnet.oceanprotocol.com",subgraphUri:"https://subgraph.catenaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.catenaxtestnet.oceanprotocol.com",metadataCacheUri:"https://aquarius.catenaxtestnet.oceanprotocol.com"}),W({},oi,{networkId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",providerUri:"https://provider.mumbai.oceanprotocol.com",subgraphUri:"https://subgraph.mumbai.oceanprotocol.com",explorerUri:"https://mumbai.polygonscan.com"}),W({},oi,{networkId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",providerUri:"https://provider.bsc.oceanprotocol.com",subgraphUri:"https://subgraph.bsc.oceanprotocol.com",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05}),W({},oi,{networkId:44787,network:"celoalfajores",nodeUri:"https://alfajores-forno.celo-testnet.org",providerUri:"https://provider.celoalfajores.oceanprotocol.com",subgraphUri:"https://subgraph.celoalfajores.oceanprotocol.com",explorerUri:"https://alfajores-blockscout.celo-testnet.org"}),W({},oi,{networkId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",providerUri:"https://provider.energyweb.oceanprotocol.com",subgraphUri:"https://subgraph.energyweb.oceanprotocol.com",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05}),W({},oi,{networkId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",providerUri:"https://provider.moonriver.oceanprotocol.com",subgraphUri:"https://subgraph.moonriver.oceanprotocol.com",explorerUri:"https://blockscout.moonriver.moonbeam.network",gasFeeMultiplier:1.05})];exports.Account=bt,exports.Config=class{constructor(){this.nodeUri=void 0,this.providerAddress=void 0,this.metadataCacheUri=void 0,this.providerUri=void 0,this.rbacUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.factoryAddress=void 0,this.factoryABI=void 0,this.datatokensABI=void 0,this.poolFactoryAddress=void 0,this.poolFactoryABI=void 0,this.poolABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.metadataContractAddress=void 0,this.metadataContractABI=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.requestTimeout=void 0}},exports.ConfigHelper=class{getAddressesFromEnv(t){let e;if(N.default[t]){const{DTFactory:i,BFactory:r,FixedRateExchange:n,Dispenser:s,Metadata:o,Ocean:a,chainId:h,startBlock:u}=N.default[t];e=W({factoryAddress:i,poolFactoryAddress:r,fixedRateExchangeAddress:n,dispenserAddress:s,metadataContractAddress:o,oceanTokenAddress:a,networkId:h,startBlock:u},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}if(R.default&&process.env.ADDRESS_FILE)try{const i=JSON.parse(R.default.readFileSync(process.env.ADDRESS_FILE||`${y.homedir}/.ocean/ocean-contracts/artifacts/address.json`,"utf8")),{DTFactory:r,BFactory:n,FixedRateExchange:s,Dispenser:o,Metadata:a,Ocean:h,chainId:u,startBlock:l}=i[t];e=W({factoryAddress:r,poolFactoryAddress:n,fixedRateExchangeAddress:s,dispenserAddress:o,metadataContractAddress:a,oceanTokenAddress:h,networkId:u,startBlock:l},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}catch(t){}return e}getConfig(t,e){const i="string"==typeof t?"network":"networkId";let r=ai.find(e=>e[i]===t);return r?(r=W({},r,this.getAddressesFromEnv(r.network)),W({},r,{nodeUri:e?`${r.nodeUri}/${e}`:r.nodeUri})):(U.error(`No config found for given network '${t}'`),null)}},exports.DDO=Rt,exports.DID=At,exports.DataTokens=Ze,exports.Logger=U,exports.MetadataCache=ze,exports.Ocean=si,exports.Provider=Tt,exports.utils=yt;
|
|
1
|
+
var t=require("uuid"),e=require("decimal.js"),i=require("web3"),r=require("fs"),n=require("save-file"),s=require("node-abort-controller"),o=require("buffer"),a=require("crypto"),h=require("cross-fetch"),u=require("@oceanprotocol/contracts/artifacts/Metadata.json"),l=require("lzma/src/lzma-c"),c=require("@oceanprotocol/contracts/artifacts/DTFactory.json"),d=require("@oceanprotocol/contracts/artifacts/DataTokenTemplate.json"),f=require("@ethereum-navigator/navigator"),m=require("crypto-js"),g=require("@oceanprotocol/contracts/artifacts/BPool.json"),p=require("@oceanprotocol/contracts/artifacts/BFactory.json"),w=require("@oceanprotocol/contracts/artifacts/FixedRateExchange.json"),v=require("@oceanprotocol/contracts/artifacts/Dispenser.json"),y=require("os"),M=require("@oceanprotocol/contracts/artifacts/address.json");function b(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var A,x=/*#__PURE__*/b(e),E=/*#__PURE__*/b(i),R=/*#__PURE__*/b(r),S=/*#__PURE__*/b(n),k=/*#__PURE__*/b(s),I=/*#__PURE__*/b(o),T=/*#__PURE__*/b(a),O=/*#__PURE__*/b(u),B=/*#__PURE__*/b(c),C=/*#__PURE__*/b(d),_=/*#__PURE__*/b(g),P=/*#__PURE__*/b(p),D=/*#__PURE__*/b(w),L=/*#__PURE__*/b(v),N=/*#__PURE__*/b(M);function W(){return(W=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t}).apply(this,arguments)}exports.LogLevel=void 0,(A=exports.LogLevel||(exports.LogLevel={}))[A.None=-1]="None",A[A.Error=0]="Error",A[A.Warn=1]="Warn",A[A.Log=2]="Log",A[A.Verbose=3]="Verbose";class F{constructor(t=exports.LogLevel.Error){this.logLevel=void 0,this.logLevel=t}setLevel(t){this.logLevel=t}bypass(...t){this.dispatch("log",-Infinity,...t)}debug(...t){this.dispatch("debug",exports.LogLevel.Verbose,...t)}log(...t){this.dispatch("log",exports.LogLevel.Log,...t)}warn(...t){this.dispatch("warn",exports.LogLevel.Warn,...t)}error(...t){this.dispatch("error",exports.LogLevel.Error,...t)}dispatch(t,e,...i){this.logLevel>=e&&console[t](...i)}}const U=new F,q=t=>j(t,!0),$=t=>j(t,!1);function j(t="",e){const{valid:i,output:r}=V(t,/^(?:0x)*([a-f0-9]+)$/i,"zeroXTransformer");return(e&&i?"0x":"")+r}const G=t=>z(t,!0);function z(t="",e){const{valid:i,output:r}=V(t,/^(?:0x|did:op:)*([a-f0-9]{40})$/i,"didTransformer");return(e&&i?"did:op:":"")+r}const H=t=>q(z(t,!1)),Z=t=>$(z(t,!1));function V(t,e,i){if("string"!=typeof t)throw U.debug("Not input string:"),U.debug(t),new Error(`[${i}] Expected string, input type: ${typeof t}`);const r=t.match(e);return r?{valid:!0,output:r[1]}:(U.warn(`[${i}] Input transformation failed.`),{valid:!1,output:t})}class J{constructor(){this.completed=!1,this.subscriptions=new Set}subscribe(t,e,i){if(this.completed)throw new Error("Observer completed.");const r={onNext:t,onComplete:e,onError:i};return this.subscriptions.add(r),{unsubscribe:()=>this.subscriptions.delete(r)}}next(t){this.emit("onNext",t)}complete(t){this.emit("onComplete",t),this.unsubscribe()}error(t){this.emit("onError",t),this.unsubscribe()}emit(t,e){Array.from(this.subscriptions).map(e=>e[t]).filter(t=>t&&"function"==typeof t).forEach(t=>t(e))}unsubscribe(){this.completed=!0,this.subscriptions.clear()}}class K{constructor(t){this.observer=new J,this.promise=Object.assign(new Promise((t,e)=>{setTimeout(()=>{this.observer.subscribe(void 0,t,e)},0)}),this),setTimeout(()=>this.init(t),1)}subscribe(t){return this.observer.subscribe(t)}next(t){return this.observer.subscribe(t),this}then(t,e){return Object.assign(this.promise.then(t,e),this)}catch(t){return Object.assign(this.promise.catch(t),this)}finally(t){return Object.assign(this.promise.finally(t),this)}init(t){const e=t(this.observer);Promise.resolve(e).then(t=>{"function"==typeof e.then&&this.observer.complete(t)}).catch(t=>{"function"==typeof e.then&&this.observer.error(t)})}}var X=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,Q=Math.ceil,Y=Math.floor,tt="[BigNumber Error] ",et=tt+"Number primitive has more than 15 significant digits: ",it=1e14,rt=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],nt=1e9;function st(t){var e=0|t;return t>0||t===e?e:e-1}function ot(t){for(var e,i,r=1,n=t.length,s=t[0]+"";r<n;){for(i=14-(e=t[r++]+"").length;i--;e="0"+e);s+=e}for(n=s.length;48===s.charCodeAt(--n););return s.slice(0,n+1||1)}function at(t,e){var i,r,n=t.c,s=e.c,o=t.s,a=e.s,h=t.e,u=e.e;if(!o||!a)return null;if(r=s&&!s[0],(i=n&&!n[0])||r)return i?r?0:-a:o;if(o!=a)return o;if(i=o<0,r=h==u,!n||!s)return r?0:!n^i?1:-1;if(!r)return h>u^i?1:-1;for(a=(h=n.length)<(u=s.length)?h:u,o=0;o<a;o++)if(n[o]!=s[o])return n[o]>s[o]^i?1:-1;return h==u?0:h>u^i?1:-1}function ht(t,e,i,r){if(t<e||t>i||t!==Y(t))throw Error(tt+(r||"Argument")+("number"==typeof t?t<e||t>i?" out of range: ":" not an integer: ":" not a primitive number: ")+String(t))}function ut(t){var e=t.c.length-1;return st(t.e/14)==e&&t.c[e]%2!=0}function lt(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(e<0?"e":"e+")+e}function ct(t,e,i){var r,n;if(e<0){for(n=i+".";++e;n+=i);t=n+t}else if(++e>(r=t.length)){for(n=i,e-=r;--e;n+=i);t+=n}else e<r&&(t=t.slice(0,e)+"."+t.slice(e));return t}var dt=function t(e){var i,r,n,s,o,a,h,u,l,c,d=R.prototype={constructor:R,toString:null,valueOf:null},f=new R(1),m=20,g=4,p=-7,w=21,v=-1e7,y=1e7,M=!1,b=1,A=0,x={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:" ",suffix:""},E="0123456789abcdefghijklmnopqrstuvwxyz";function R(t,e){var i,s,o,a,h,u,l,c,d=this;if(!(d instanceof R))return new R(t,e);if(null==e){if(t&&!0===t._isBigNumber)return d.s=t.s,void(!t.c||t.e>y?d.c=d.e=null:t.e<v?d.c=[d.e=0]:(d.e=t.e,d.c=t.c.slice()));if((u="number"==typeof t)&&0*t==0){if(d.s=1/t<0?(t=-t,-1):1,t===~~t){for(a=0,h=t;h>=10;h/=10,a++);return void(a>y?d.c=d.e=null:(d.e=a,d.c=[t]))}c=String(t)}else{if(!X.test(c=String(t)))return n(d,c,u);d.s=45==c.charCodeAt(0)?(c=c.slice(1),-1):1}(a=c.indexOf("."))>-1&&(c=c.replace(".","")),(h=c.search(/e/i))>0?(a<0&&(a=h),a+=+c.slice(h+1),c=c.substring(0,h)):a<0&&(a=c.length)}else{if(ht(e,2,E.length,"Base"),10==e)return T(d=new R(t),m+d.e+1,g);if(c=String(t),u="number"==typeof t){if(0*t!=0)return n(d,c,u,e);if(d.s=1/t<0?(c=c.slice(1),-1):1,R.DEBUG&&c.replace(/^0\.0*|\./,"").length>15)throw Error(et+t)}else d.s=45===c.charCodeAt(0)?(c=c.slice(1),-1):1;for(i=E.slice(0,e),a=h=0,l=c.length;h<l;h++)if(i.indexOf(s=c.charAt(h))<0){if("."==s){if(h>a){a=l;continue}}else if(!o&&(c==c.toUpperCase()&&(c=c.toLowerCase())||c==c.toLowerCase()&&(c=c.toUpperCase()))){o=!0,h=-1,a=0;continue}return n(d,String(t),u,e)}u=!1,(a=(c=r(c,e,10,d.s)).indexOf("."))>-1?c=c.replace(".",""):a=c.length}for(h=0;48===c.charCodeAt(h);h++);for(l=c.length;48===c.charCodeAt(--l););if(c=c.slice(h,++l)){if(l-=h,u&&R.DEBUG&&l>15&&(t>9007199254740991||t!==Y(t)))throw Error(et+d.s*t);if((a=a-h-1)>y)d.c=d.e=null;else if(a<v)d.c=[d.e=0];else{if(d.e=a,d.c=[],h=(a+1)%14,a<0&&(h+=14),h<l){for(h&&d.c.push(+c.slice(0,h)),l-=14;h<l;)d.c.push(+c.slice(h,h+=14));h=14-(c=c.slice(h)).length}else h-=l;for(;h--;c+="0");d.c.push(+c)}}else d.c=[d.e=0]}function S(t,e,i,r){var n,s,o,a,h;if(null==i?i=g:ht(i,0,8),!t.c)return t.toString();if(n=t.c[0],o=t.e,null==e)h=ot(t.c),h=1==r||2==r&&(o<=p||o>=w)?lt(h,o):ct(h,o,"0");else if(s=(t=T(new R(t),e,i)).e,a=(h=ot(t.c)).length,1==r||2==r&&(e<=s||s<=p)){for(;a<e;h+="0",a++);h=lt(h,s)}else if(e-=o,h=ct(h,s,"0"),s+1>a){if(--e>0)for(h+=".";e--;h+="0");}else if((e+=s-a)>0)for(s+1==a&&(h+=".");e--;h+="0");return t.s<0&&n?"-"+h:h}function k(t,e){for(var i,r=1,n=new R(t[0]);r<t.length;r++){if(!(i=new R(t[r])).s){n=i;break}e.call(n,i)&&(n=i)}return n}function I(t,e,i){for(var r=1,n=e.length;!e[--n];e.pop());for(n=e[0];n>=10;n/=10,r++);return(i=r+14*i-1)>y?t.c=t.e=null:i<v?t.c=[t.e=0]:(t.e=i,t.c=e),t}function T(t,e,i,r){var n,s,o,a,h,u,l,c=t.c,d=rt;if(c){t:{for(n=1,a=c[0];a>=10;a/=10,n++);if((s=e-n)<0)s+=14,l=(h=c[u=0])/d[n-(o=e)-1]%10|0;else if((u=Q((s+1)/14))>=c.length){if(!r)break t;for(;c.length<=u;c.push(0));h=l=0,n=1,o=(s%=14)-14+1}else{for(h=a=c[u],n=1;a>=10;a/=10,n++);l=(o=(s%=14)-14+n)<0?0:h/d[n-o-1]%10|0}if(r=r||e<0||null!=c[u+1]||(o<0?h:h%d[n-o-1]),r=i<4?(l||r)&&(0==i||i==(t.s<0?3:2)):l>5||5==l&&(4==i||r||6==i&&(s>0?o>0?h/d[n-o]:0:c[u-1])%10&1||i==(t.s<0?8:7)),e<1||!c[0])return c.length=0,r?(c[0]=d[(14-(e-=t.e+1)%14)%14],t.e=-e||0):c[0]=t.e=0,t;if(0==s?(c.length=u,a=1,u--):(c.length=u+1,a=d[14-s],c[u]=o>0?Y(h/d[n-o]%d[o])*a:0),r)for(;;){if(0==u){for(s=1,o=c[0];o>=10;o/=10,s++);for(o=c[0]+=a,a=1;o>=10;o/=10,a++);s!=a&&(t.e++,c[0]==it&&(c[0]=1));break}if(c[u]+=a,c[u]!=it)break;c[u--]=0,a=1}for(s=c.length;0===c[--s];c.pop());}t.e>y?t.c=t.e=null:t.e<v&&(t.c=[t.e=0])}return t}function O(t){var e,i=t.e;return null===i?t.toString():(e=ot(t.c),e=i<=p||i>=w?lt(e,i):ct(e,i,"0"),t.s<0?"-"+e:e)}return R.clone=t,R.ROUND_UP=0,R.ROUND_DOWN=1,R.ROUND_CEIL=2,R.ROUND_FLOOR=3,R.ROUND_HALF_UP=4,R.ROUND_HALF_DOWN=5,R.ROUND_HALF_EVEN=6,R.ROUND_HALF_CEIL=7,R.ROUND_HALF_FLOOR=8,R.EUCLID=9,R.config=R.set=function(t){var e,i;if(null!=t){if("object"!=typeof t)throw Error(tt+"Object expected: "+t);if(t.hasOwnProperty(e="DECIMAL_PLACES")&&(ht(i=t[e],0,nt,e),m=i),t.hasOwnProperty(e="ROUNDING_MODE")&&(ht(i=t[e],0,8,e),g=i),t.hasOwnProperty(e="EXPONENTIAL_AT")&&((i=t[e])&&i.pop?(ht(i[0],-nt,0,e),ht(i[1],0,nt,e),p=i[0],w=i[1]):(ht(i,-nt,nt,e),p=-(w=i<0?-i:i))),t.hasOwnProperty(e="RANGE"))if((i=t[e])&&i.pop)ht(i[0],-nt,-1,e),ht(i[1],1,nt,e),v=i[0],y=i[1];else{if(ht(i,-nt,nt,e),!i)throw Error(tt+e+" cannot be zero: "+i);v=-(y=i<0?-i:i)}if(t.hasOwnProperty(e="CRYPTO")){if((i=t[e])!==!!i)throw Error(tt+e+" not true or false: "+i);if(i){if("undefined"==typeof crypto||!crypto||!crypto.getRandomValues&&!crypto.randomBytes)throw M=!i,Error(tt+"crypto unavailable");M=i}else M=i}if(t.hasOwnProperty(e="MODULO_MODE")&&(ht(i=t[e],0,9,e),b=i),t.hasOwnProperty(e="POW_PRECISION")&&(ht(i=t[e],0,nt,e),A=i),t.hasOwnProperty(e="FORMAT")){if("object"!=typeof(i=t[e]))throw Error(tt+e+" not an object: "+i);x=i}if(t.hasOwnProperty(e="ALPHABET")){if("string"!=typeof(i=t[e])||/^.$|[+-.\s]|(.).*\1/.test(i))throw Error(tt+e+" invalid: "+i);E=i}}return{DECIMAL_PLACES:m,ROUNDING_MODE:g,EXPONENTIAL_AT:[p,w],RANGE:[v,y],CRYPTO:M,MODULO_MODE:b,POW_PRECISION:A,FORMAT:x,ALPHABET:E}},R.isBigNumber=function(t){if(!t||!0!==t._isBigNumber)return!1;if(!R.DEBUG)return!0;var e,i,r=t.c,n=t.e,s=t.s;t:if("[object Array]"=={}.toString.call(r)){if((1===s||-1===s)&&n>=-nt&&n<=nt&&n===Y(n)){if(0===r[0]){if(0===n&&1===r.length)return!0;break t}if((e=(n+1)%14)<1&&(e+=14),String(r[0]).length==e){for(e=0;e<r.length;e++)if((i=r[e])<0||i>=it||i!==Y(i))break t;if(0!==i)return!0}}}else if(null===r&&null===n&&(null===s||1===s||-1===s))return!0;throw Error(tt+"Invalid BigNumber: "+t)},R.maximum=R.max=function(){return k(arguments,d.lt)},R.minimum=R.min=function(){return k(arguments,d.gt)},R.random=(s=9007199254740992,o=Math.random()*s&2097151?function(){return Y(Math.random()*s)}:function(){return 8388608*(1073741824*Math.random()|0)+(8388608*Math.random()|0)},function(t){var e,i,r,n,s,a=0,h=[],u=new R(f);if(null==t?t=m:ht(t,0,nt),n=Q(t/14),M)if(crypto.getRandomValues){for(e=crypto.getRandomValues(new Uint32Array(n*=2));a<n;)(s=131072*e[a]+(e[a+1]>>>11))>=9e15?(i=crypto.getRandomValues(new Uint32Array(2)),e[a]=i[0],e[a+1]=i[1]):(h.push(s%1e14),a+=2);a=n/2}else{if(!crypto.randomBytes)throw M=!1,Error(tt+"crypto unavailable");for(e=crypto.randomBytes(n*=7);a<n;)(s=281474976710656*(31&e[a])+1099511627776*e[a+1]+4294967296*e[a+2]+16777216*e[a+3]+(e[a+4]<<16)+(e[a+5]<<8)+e[a+6])>=9e15?crypto.randomBytes(7).copy(e,a):(h.push(s%1e14),a+=7);a=n/7}if(!M)for(;a<n;)(s=o())<9e15&&(h[a++]=s%1e14);for(t%=14,(n=h[--a])&&t&&(h[a]=Y(n/(s=rt[14-t]))*s);0===h[a];h.pop(),a--);if(a<0)h=[r=0];else{for(r=-1;0===h[0];h.splice(0,1),r-=14);for(a=1,s=h[0];s>=10;s/=10,a++);a<14&&(r-=14-a)}return u.e=r,u.c=h,u}),R.sum=function(){for(var t=1,e=arguments,i=new R(e[0]);t<e.length;)i=i.plus(e[t++]);return i},r=function(){var t="0123456789";function e(t,e,i,r){for(var n,s,o=[0],a=0,h=t.length;a<h;){for(s=o.length;s--;o[s]*=e);for(o[0]+=r.indexOf(t.charAt(a++)),n=0;n<o.length;n++)o[n]>i-1&&(null==o[n+1]&&(o[n+1]=0),o[n+1]+=o[n]/i|0,o[n]%=i)}return o.reverse()}return function(r,n,s,o,a){var h,u,l,c,d,f,p,w,v=r.indexOf("."),y=m,M=g;for(v>=0&&(c=A,A=0,r=r.replace(".",""),f=(w=new R(n)).pow(r.length-v),A=c,w.c=e(ct(ot(f.c),f.e,"0"),10,s,t),w.e=w.c.length),l=c=(p=e(r,n,s,a?(h=E,t):(h=t,E))).length;0==p[--c];p.pop());if(!p[0])return h.charAt(0);if(v<0?--l:(f.c=p,f.e=l,f.s=o,p=(f=i(f,w,y,M,s)).c,d=f.r,l=f.e),v=p[u=l+y+1],c=s/2,d=d||u<0||null!=p[u+1],d=M<4?(null!=v||d)&&(0==M||M==(f.s<0?3:2)):v>c||v==c&&(4==M||d||6==M&&1&p[u-1]||M==(f.s<0?8:7)),u<1||!p[0])r=d?ct(h.charAt(1),-y,h.charAt(0)):h.charAt(0);else{if(p.length=u,d)for(--s;++p[--u]>s;)p[u]=0,u||(++l,p=[1].concat(p));for(c=p.length;!p[--c];);for(v=0,r="";v<=c;r+=h.charAt(p[v++]));r=ct(r,l,h.charAt(0))}return r}}(),i=function(){function t(t,e,i){var r,n,s,o,a=0,h=t.length,u=e%1e7,l=e/1e7|0;for(t=t.slice();h--;)a=((n=u*(s=t[h]%1e7)+(r=l*s+(o=t[h]/1e7|0)*u)%1e7*1e7+a)/i|0)+(r/1e7|0)+l*o,t[h]=n%i;return a&&(t=[a].concat(t)),t}function e(t,e,i,r){var n,s;if(i!=r)s=i>r?1:-1;else for(n=s=0;n<i;n++)if(t[n]!=e[n]){s=t[n]>e[n]?1:-1;break}return s}function i(t,e,i,r){for(var n=0;i--;)t[i]-=n,t[i]=(n=t[i]<e[i]?1:0)*r+t[i]-e[i];for(;!t[0]&&t.length>1;t.splice(0,1));}return function(r,n,s,o,a){var h,u,l,c,d,f,m,g,p,w,v,y,M,b,A,x,E,S=r.s==n.s?1:-1,k=r.c,I=n.c;if(!(k&&k[0]&&I&&I[0]))return new R(r.s&&n.s&&(k?!I||k[0]!=I[0]:I)?k&&0==k[0]||!I?0*S:S/0:NaN);for(p=(g=new R(S)).c=[],S=s+(u=r.e-n.e)+1,a||(a=it,u=st(r.e/14)-st(n.e/14),S=S/14|0),l=0;I[l]==(k[l]||0);l++);if(I[l]>(k[l]||0)&&u--,S<0)p.push(1),c=!0;else{for(b=k.length,x=I.length,l=0,S+=2,(d=Y(a/(I[0]+1)))>1&&(I=t(I,d,a),k=t(k,d,a),x=I.length,b=k.length),M=x,v=(w=k.slice(0,x)).length;v<x;w[v++]=0);E=I.slice(),E=[0].concat(E),A=I[0],I[1]>=a/2&&A++;do{if(d=0,(h=e(I,w,x,v))<0){if(y=w[0],x!=v&&(y=y*a+(w[1]||0)),(d=Y(y/A))>1)for(d>=a&&(d=a-1),m=(f=t(I,d,a)).length,v=w.length;1==e(f,w,m,v);)d--,i(f,x<m?E:I,m,a),m=f.length,h=1;else 0==d&&(h=d=1),m=(f=I.slice()).length;if(m<v&&(f=[0].concat(f)),i(w,f,v,a),v=w.length,-1==h)for(;e(I,w,x,v)<1;)d++,i(w,x<v?E:I,v,a),v=w.length}else 0===h&&(d++,w=[0]);p[l++]=d,w[0]?w[v++]=k[M]||0:(w=[k[M]],v=1)}while((M++<b||null!=w[0])&&S--);c=null!=w[0],p[0]||p.splice(0,1)}if(a==it){for(l=1,S=p[0];S>=10;S/=10,l++);T(g,s+(g.e=l+14*u-1)+1,o,c)}else g.e=u,g.r=+c;return g}}(),a=/^(-?)0([xbo])(?=\w[\w.]*$)/i,h=/^([^.]+)\.$/,u=/^\.([^.]+)$/,l=/^-?(Infinity|NaN)$/,c=/^\s*\+(?=[\w.])|^\s+|\s+$/g,n=function(t,e,i,r){var n,s=i?e:e.replace(c,"");if(l.test(s))t.s=isNaN(s)?null:s<0?-1:1;else{if(!i&&(s=s.replace(a,function(t,e,i){return n="x"==(i=i.toLowerCase())?16:"b"==i?2:8,r&&r!=n?t:e}),r&&(n=r,s=s.replace(h,"$1").replace(u,"0.$1")),e!=s))return new R(s,n);if(R.DEBUG)throw Error(tt+"Not a"+(r?" base "+r:"")+" number: "+e);t.s=null}t.c=t.e=null},d.absoluteValue=d.abs=function(){var t=new R(this);return t.s<0&&(t.s=1),t},d.comparedTo=function(t,e){return at(this,new R(t,e))},d.decimalPlaces=d.dp=function(t,e){var i,r,n,s=this;if(null!=t)return ht(t,0,nt),null==e?e=g:ht(e,0,8),T(new R(s),t+s.e+1,e);if(!(i=s.c))return null;if(r=14*((n=i.length-1)-st(this.e/14)),n=i[n])for(;n%10==0;n/=10,r--);return r<0&&(r=0),r},d.dividedBy=d.div=function(t,e){return i(this,new R(t,e),m,g)},d.dividedToIntegerBy=d.idiv=function(t,e){return i(this,new R(t,e),0,1)},d.exponentiatedBy=d.pow=function(t,e){var i,r,n,s,o,a,h,u,l=this;if((t=new R(t)).c&&!t.isInteger())throw Error(tt+"Exponent not an integer: "+O(t));if(null!=e&&(e=new R(e)),o=t.e>14,!l.c||!l.c[0]||1==l.c[0]&&!l.e&&1==l.c.length||!t.c||!t.c[0])return u=new R(Math.pow(+O(l),o?2-ut(t):+O(t))),e?u.mod(e):u;if(a=t.s<0,e){if(e.c?!e.c[0]:!e.s)return new R(NaN);(r=!a&&l.isInteger()&&e.isInteger())&&(l=l.mod(e))}else{if(t.e>9&&(l.e>0||l.e<-1||(0==l.e?l.c[0]>1||o&&l.c[1]>=24e7:l.c[0]<8e13||o&&l.c[0]<=9999975e7)))return s=l.s<0&&ut(t)?-0:0,l.e>-1&&(s=1/s),new R(a?1/s:s);A&&(s=Q(A/14+2))}for(o?(i=new R(.5),a&&(t.s=1),h=ut(t)):h=(n=Math.abs(+O(t)))%2,u=new R(f);;){if(h){if(!(u=u.times(l)).c)break;s?u.c.length>s&&(u.c.length=s):r&&(u=u.mod(e))}if(n){if(0===(n=Y(n/2)))break;h=n%2}else if(T(t=t.times(i),t.e+1,1),t.e>14)h=ut(t);else{if(0==(n=+O(t)))break;h=n%2}l=l.times(l),s?l.c&&l.c.length>s&&(l.c.length=s):r&&(l=l.mod(e))}return r?u:(a&&(u=f.div(u)),e?u.mod(e):s?T(u,A,g,void 0):u)},d.integerValue=function(t){var e=new R(this);return null==t?t=g:ht(t,0,8),T(e,e.e+1,t)},d.isEqualTo=d.eq=function(t,e){return 0===at(this,new R(t,e))},d.isFinite=function(){return!!this.c},d.isGreaterThan=d.gt=function(t,e){return at(this,new R(t,e))>0},d.isGreaterThanOrEqualTo=d.gte=function(t,e){return 1===(e=at(this,new R(t,e)))||0===e},d.isInteger=function(){return!!this.c&&st(this.e/14)>this.c.length-2},d.isLessThan=d.lt=function(t,e){return at(this,new R(t,e))<0},d.isLessThanOrEqualTo=d.lte=function(t,e){return-1===(e=at(this,new R(t,e)))||0===e},d.isNaN=function(){return!this.s},d.isNegative=function(){return this.s<0},d.isPositive=function(){return this.s>0},d.isZero=function(){return!!this.c&&0==this.c[0]},d.minus=function(t,e){var i,r,n,s,o=this,a=o.s;if(e=(t=new R(t,e)).s,!a||!e)return new R(NaN);if(a!=e)return t.s=-e,o.plus(t);var h=o.e/14,u=t.e/14,l=o.c,c=t.c;if(!h||!u){if(!l||!c)return l?(t.s=-e,t):new R(c?o:NaN);if(!l[0]||!c[0])return c[0]?(t.s=-e,t):new R(l[0]?o:3==g?-0:0)}if(h=st(h),u=st(u),l=l.slice(),a=h-u){for((s=a<0)?(a=-a,n=l):(u=h,n=c),n.reverse(),e=a;e--;n.push(0));n.reverse()}else for(r=(s=(a=l.length)<(e=c.length))?a:e,a=e=0;e<r;e++)if(l[e]!=c[e]){s=l[e]<c[e];break}if(s&&(n=l,l=c,c=n,t.s=-t.s),(e=(r=c.length)-(i=l.length))>0)for(;e--;l[i++]=0);for(e=it-1;r>a;){if(l[--r]<c[r]){for(i=r;i&&!l[--i];l[i]=e);--l[i],l[r]+=it}l[r]-=c[r]}for(;0==l[0];l.splice(0,1),--u);return l[0]?I(t,l,u):(t.s=3==g?-1:1,t.c=[t.e=0],t)},d.modulo=d.mod=function(t,e){var r,n,s=this;return t=new R(t,e),!s.c||!t.s||t.c&&!t.c[0]?new R(NaN):!t.c||s.c&&!s.c[0]?new R(s):(9==b?(n=t.s,t.s=1,r=i(s,t,0,3),t.s=n,r.s*=n):r=i(s,t,0,b),(t=s.minus(r.times(t))).c[0]||1!=b||(t.s=s.s),t)},d.multipliedBy=d.times=function(t,e){var i,r,n,s,o,a,h,u,l,c,d,f,m,g,p,w=this,v=w.c,y=(t=new R(t,e)).c;if(!(v&&y&&v[0]&&y[0]))return!w.s||!t.s||v&&!v[0]&&!y||y&&!y[0]&&!v?t.c=t.e=t.s=null:(t.s*=w.s,v&&y?(t.c=[0],t.e=0):t.c=t.e=null),t;for(r=st(w.e/14)+st(t.e/14),t.s*=w.s,(h=v.length)<(c=y.length)&&(m=v,v=y,y=m,n=h,h=c,c=n),n=h+c,m=[];n--;m.push(0));for(g=it,p=1e7,n=c;--n>=0;){for(i=0,d=y[n]%p,f=y[n]/p|0,s=n+(o=h);s>n;)i=((u=d*(u=v[--o]%p)+(a=f*u+(l=v[o]/p|0)*d)%p*p+m[s]+i)/g|0)+(a/p|0)+f*l,m[s--]=u%g;m[s]=i}return i?++r:m.splice(0,1),I(t,m,r)},d.negated=function(){var t=new R(this);return t.s=-t.s||null,t},d.plus=function(t,e){var i,r=this,n=r.s;if(e=(t=new R(t,e)).s,!n||!e)return new R(NaN);if(n!=e)return t.s=-e,r.minus(t);var s=r.e/14,o=t.e/14,a=r.c,h=t.c;if(!s||!o){if(!a||!h)return new R(n/0);if(!a[0]||!h[0])return h[0]?t:new R(a[0]?r:0*n)}if(s=st(s),o=st(o),a=a.slice(),n=s-o){for(n>0?(o=s,i=h):(n=-n,i=a),i.reverse();n--;i.push(0));i.reverse()}for((n=a.length)-(e=h.length)<0&&(i=h,h=a,a=i,e=n),n=0;e;)n=(a[--e]=a[e]+h[e]+n)/it|0,a[e]=it===a[e]?0:a[e]%it;return n&&(a=[n].concat(a),++o),I(t,a,o)},d.precision=d.sd=function(t,e){var i,r,n,s=this;if(null!=t&&t!==!!t)return ht(t,1,nt),null==e?e=g:ht(e,0,8),T(new R(s),t,e);if(!(i=s.c))return null;if(r=14*(n=i.length-1)+1,n=i[n]){for(;n%10==0;n/=10,r--);for(n=i[0];n>=10;n/=10,r++);}return t&&s.e+1>r&&(r=s.e+1),r},d.shiftedBy=function(t){return ht(t,-9007199254740991,9007199254740991),this.times("1e"+t)},d.squareRoot=d.sqrt=function(){var t,e,r,n,s,o=this,a=o.c,h=o.s,u=o.e,l=m+4,c=new R("0.5");if(1!==h||!a||!a[0])return new R(!h||h<0&&(!a||a[0])?NaN:a?o:1/0);if(0==(h=Math.sqrt(+O(o)))||h==1/0?(((e=ot(a)).length+u)%2==0&&(e+="0"),h=Math.sqrt(+e),u=st((u+1)/2)-(u<0||u%2),r=new R(e=h==1/0?"5e"+u:(e=h.toExponential()).slice(0,e.indexOf("e")+1)+u)):r=new R(h+""),r.c[0])for((h=(u=r.e)+l)<3&&(h=0);;)if(r=c.times((s=r).plus(i(o,s,l,1))),ot(s.c).slice(0,h)===(e=ot(r.c)).slice(0,h)){if(r.e<u&&--h,"9999"!=(e=e.slice(h-3,h+1))&&(n||"4999"!=e)){+e&&(+e.slice(1)||"5"!=e.charAt(0))||(T(r,r.e+m+2,1),t=!r.times(r).eq(o));break}if(!n&&(T(s,s.e+m+2,0),s.times(s).eq(o))){r=s;break}l+=4,h+=4,n=1}return T(r,r.e+m+1,g,t)},d.toExponential=function(t,e){return null!=t&&(ht(t,0,nt),t++),S(this,t,e,1)},d.toFixed=function(t,e){return null!=t&&(ht(t,0,nt),t=t+this.e+1),S(this,t,e)},d.toFormat=function(t,e,i){var r,n=this;if(null==i)null!=t&&e&&"object"==typeof e?(i=e,e=null):t&&"object"==typeof t?(i=t,t=e=null):i=x;else if("object"!=typeof i)throw Error(tt+"Argument not an object: "+i);if(r=n.toFixed(t,e),n.c){var s,o=r.split("."),a=+i.groupSize,h=+i.secondaryGroupSize,u=i.groupSeparator||"",l=o[0],c=o[1],d=n.s<0,f=d?l.slice(1):l,m=f.length;if(h&&(s=a,a=h,h=s,m-=s),a>0&&m>0){for(l=f.substr(0,s=m%a||a);s<m;s+=a)l+=u+f.substr(s,a);h>0&&(l+=u+f.slice(s)),d&&(l="-"+l)}r=c?l+(i.decimalSeparator||"")+((h=+i.fractionGroupSize)?c.replace(new RegExp("\\d{"+h+"}\\B","g"),"$&"+(i.fractionGroupSeparator||"")):c):l}return(i.prefix||"")+r+(i.suffix||"")},d.toFraction=function(t){var e,r,n,s,o,a,h,u,l,c,d,m,p=this,w=p.c;if(null!=t&&(!(h=new R(t)).isInteger()&&(h.c||1!==h.s)||h.lt(f)))throw Error(tt+"Argument "+(h.isInteger()?"out of range: ":"not an integer: ")+O(h));if(!w)return new R(p);for(e=new R(f),l=r=new R(f),n=u=new R(f),m=ot(w),o=e.e=m.length-p.e-1,e.c[0]=rt[(a=o%14)<0?14+a:a],t=!t||h.comparedTo(e)>0?o>0?e:l:h,a=y,y=1/0,h=new R(m),u.c[0]=0;c=i(h,e,0,1),1!=(s=r.plus(c.times(n))).comparedTo(t);)r=n,n=s,l=u.plus(c.times(s=l)),u=s,e=h.minus(c.times(s=e)),h=s;return s=i(t.minus(r),n,0,1),u=u.plus(s.times(l)),r=r.plus(s.times(n)),u.s=l.s=p.s,d=i(l,n,o*=2,g).minus(p).abs().comparedTo(i(u,r,o,g).minus(p).abs())<1?[l,n]:[u,r],y=a,d},d.toNumber=function(){return+O(this)},d.toPrecision=function(t,e){return null!=t&&ht(t,1,nt),S(this,t,e,2)},d.toString=function(t){var e,i=this,n=i.s,s=i.e;return null===s?n?(e="Infinity",n<0&&(e="-"+e)):e="NaN":(null==t?e=s<=p||s>=w?lt(ot(i.c),s):ct(ot(i.c),s,"0"):10===t?e=ct(ot((i=T(new R(i),m+s+1,g)).c),i.e,"0"):(ht(t,2,E.length,"Base"),e=r(ct(ot(i.c),s,"0"),10,t,n,!0)),n<0&&i.c[0]&&(e="-"+e)),e},d.valueOf=d.toJSON=function(){return O(this)},d._isBigNumber=!0,d[Symbol.toStringTag]="BigNumber",d[Symbol.for("nodejs.util.inspect.custom")]=d.valueOf,null!=e&&R.set(e),R}();async function ft(t,e){const i=new dt(await t.eth.getGasPrice());return e&&e.gasFeeMultiplier?i.multipliedBy(e.gasFeeMultiplier).integerValue(dt.ROUND_DOWN).toString(10):i.toString(10)}function mt(t,e){return e&&(t.transactionBlockTimeout=e.transactionBlockTimeout,t.transactionConfirmationBlocks=e.transactionConfirmationBlocks,t.transactionPollingTimeout=e.transactionPollingTimeout),t}function gt(t){return void 0!==t.id}async function pt(t,e){if(gt(t))return{did:t.id,ddo:t};{const i=await e.assets.resolve(t);return{did:i.id,ddo:i}}}var wt={nouns:["Crab","Fish","Seal","Octopus","Shark","Seahorse","Walrus","Starfish","Whale","Orca","Penguin","Jellyfish","Squid","Lobster","Pelican","Shrimp","Oyster","Clam","Seagull","Dolphin","Shell","Cormorant","Otter","Anemone","Turtle","Coral","Ray","Barracuda","Krill","Anchovy","Angelfish","Barnacle","Clownfish","Cod","Cuttlefish","Eel","Fugu","Herring","Haddock","Ling","Mackerel","Manatee","Narwhal","Nautilus","Plankton","Porpoise","Prawn","Pufferfish","Swordfish","Tuna"],adjectives:["adamant","adroit","amatory","ambitious","amused","animistic","antic","arcadian","artistic","astonishing","astounding","baleful","bellicose","bilious","blissful","boorish","brave","breathtaking","brilliant","calamitous","caustic","cerulean","clever","charming","comely","competent","concomitant","confident","contumacious","corpulent","crapulous","creative","dazzling","dedicated","defamatory","delighted","delightful","determined","didactic","dilatory","dowdy","efficacious","effulgent","egregious","empowered","endemic","enthusiastic","equanimous","exceptional","execrable","fabulous","fantastic","fastidious","feckless","fecund","friable","fulsome","garrulous","generous","gentle","guileless","gustatory","heuristic","histrionic","hubristic","incendiary","incredible","insidious","insolent","inspired","intransigent","inveterate","invidious","invigorated","irksome","jejune","juicy","jocular","joyful","judicious","kind","lachrymose","limpid","loquacious","lovely","luminous","mannered","marvelous","mendacious","meretricious","minatory","mordant","motivated","munificent","nefarious","noxious","obtuse","optimistic","parsimonious","pendulous","pernicious","pervasive","petulant","passionate","phenomenal","platitudinous","pleasant","powerful","precipitate","propitious","puckish","querulous","quiescent","rebarbative","recalcitant","redolent","rhadamanthine","risible","ruminative","sagacious","salubrious","sartorial","sclerotic","serpentine","smart","spasmodic","strident","stunning","stupendous","taciturn","tactful","tasty","tenacious","tremendous","tremulous","trenchant","turbulent","turgid","ubiquitous","uxorious","verdant","vibrant","voluble","voracious","wheedling","withering","wonderful","zealous"]};function vt(t){const e=t||wt,i=Math.floor(Math.random()*e.adjectives.length),r=Math.floor(Math.random()*e.nouns.length),n=Math.floor(100*Math.random()),s=e.adjectives[i].replace(/^\w/,t=>t.toUpperCase()),o=e.nouns[r].replace(/^\w/,t=>t.toUpperCase());return{name:`${s} ${o} Token`,symbol:`${(s.substring(0,3)+o.substring(0,3)).toUpperCase()}-${n}`}}var yt={__proto__:null,objectPromiseAll:async t=>((t=[],e=[])=>t.reduce((t,i,r)=>W({},t,{[i]:e[r]}),{}))(Object.keys(t),await Promise.all(Object.values(t))),get LogLevel(){return exports.LogLevel},Logger:F,LoggerInstance:U,zeroX:q,noZeroX:$,zeroXTransformer:j,didPrefixed:G,noDidPrefixed:t=>z(t,!1),didTransformer:z,didZeroX:H,didNoZeroX:Z,generateId:function(e=64){let i="";for(;i.length<e;)i+=t.v4().replace(/-/g,"");return i.substr(0,e)},SubscribablePromise:K,SubscribableObserver:J,getFairGasPrice:ft,setContractDefaults:mt,isDdo:gt,assetResolve:pt,generateDatatokenName:vt};class Mt{constructor(){this._ocean=void 0,this._web3=void 0,this._config=void 0,this._logger=void 0}get ocean(){return this._ocean||U.error("Ocean instance is not defined."),this._ocean}get web3(){return this._web3||U.error("Web3 instance is not defined."),this._web3}get config(){return this._config||U.error("Config instance is not defined."),this._config}get logger(){return U}get instanceConfig(){const{ocean:t,web3:e,config:i,logger:r}=this;return{ocean:t,web3:e,config:i,logger:r}}static async getInstance(t){U.warn("getInstance() methods has needs to be added to child class.")}static setInstanceConfig(t,{ocean:e,config:i,web3:r,logger:n}){t._ocean=e,t._config=i,t._web3=r,t._logger=n}setInstanceConfig(t){Mt.setInstanceConfig(this,t)}}class bt extends Mt{constructor(t="0x0",e){super(),this.id=void 0,this.password=void 0,this.token=void 0,this.id=t,e&&this.setInstanceConfig(e)}getId(){return this.id}setId(t){this.id=t}setPassword(t){this.password=t}getPassword(){return this.password}async getTokenBalance(t){if(null===t)return null;const e=[{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"}];let i=null;const r=await this.getTokenDecimals(t);try{const n=new this.web3.eth.Contract(e,t,{from:this.id}),s=await n.methods.balanceOf(this.id).call();i=new x.default(s).div(10**r).toString()}catch(t){this.logger.error(`ERROR: Failed to get the balance: ${t.message}`)}return i}async getTokenDecimals(t){let e=18;if(null===t)return e;const i=[{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],type:"function"}];try{const r=new this.web3.eth.Contract(i,t,{from:this.id});e=await r.methods.decimals().call()}catch(t){this.logger.error(`ERROR: Failed to get decimals : ${t.message}`)}return e}async getOceanBalance(){return this.getTokenBalance(this.config.oceanTokenAddress)}async getTokenSymbol(t){return""}async getEtherBalance(){const t=await this.web3.eth.getBalance(this.id,"latest");return this.web3.utils.fromWei(t)}}class At{static parse(t){let e;t instanceof At&&(t=t.getDid());const i=t.match(/^did:op:([a-f0-9]{40})$/i);if(i&&(e=new At(i[1])),!e)throw new Error(`Parsing DID failed, ${t}`);return e}static generate(t){return new At($(t))}constructor(t){this.id=void 0,this.id=t}getDid(){return`did:op:${this.id}`}getId(){return this.id}}class xt extends Mt{static async getInstance(t){const e=new xt;return e.setInstanceConfig(t),e}async list(){const t=(await this.web3.eth.getAccounts()).map(t=>new bt(t,this.instanceConfig));return Promise.all(t)}getTokenBalance(t,e){return e.getTokenBalance(t)}getOceanBalance(t){return t.getOceanBalance()}getEtherBalance(t){return t.getEtherBalance()}}class Et{static getWeb3(t={}){return new E.default(t.web3Provider||E.default.givenProvider||new E.default.providers.HttpProvider(t.nodeUri))}}class Rt{static serialize(t){return JSON.stringify(t,null,2)}static deserialize(t){const e=JSON.parse(t);return new Rt(e)}constructor(t={}){this["@context"]="https://w3id.org/did/v1",this.id=null,this.created=void 0,this.updated=void 0,this.dataToken=void 0,this.publicKey=[],this.authentication=[],this.service=[],this.proof=void 0,this.price=void 0,this.isInPurgatory=void 0,this.purgatoryData=void 0,this.dataTokenInfo=void 0,this.credentials=void 0,this.chainId=void 0,this.event=void 0,Object.assign(this,t,{created:t&&t.created||(new Date).toISOString().replace(/\.[0-9]{3}/,"")})}shortId(){return this.id.replace("did:op:","")}findServiceById(t){if(isNaN(t))throw new Error("index is not set");return this.service.find(e=>e.index===t)}findServiceByType(t){if(!t)throw new Error("serviceType not set");return this.service.find(e=>e.type===t)}getChecksum(){const{attributes:t}=this.findServiceByType("metadata"),{files:e,name:i,author:r,license:n}=t.main,s=[...(e||[]).map(({checksum:t})=>t).filter(t=>!!t),i,r,n,this.id];return Et.getWeb3().utils.sha3(s.join("")).replace(/^0x([a-f0-9]{64})(:!.+)?$/i,"0x$1")}async addProof(t,e,i){if(this.proof)throw new Error("Proof already exists");this.proof={created:(new Date).toISOString().replace(/\.[0-9]{3}/,""),creator:e,type:"AddressHash",signatureValue:Et.getWeb3().utils.sha3(e).replace(/^0x([a-f0-9]{64})(:!.+)?$/i,"0x$1")}}}function St(t){if(!Number.isInteger(t))throw new TypeError("Expected an integer, got "+typeof t);const e=new WeakMap,i=new k.default,r=setTimeout(()=>{i.abort()},t);return e.set(i.signal,r),i.signal}const kt=require("cross-fetch");class It{constructor(t,e){this.logger=void 0,this.requestTimeout=5e3,this.logger=t,this.requestTimeout=e||this.requestTimeout}post(t,e){return this.postWithHeaders(t,e,{"Content-type":"application/json"})}postWithOctet(t,e){return this.postWithHeaders(t,e,{"Content-type":"application/octet-stream"})}postWithHeaders(t,e,i){return this.fetch(t,null!=e?{method:"POST",body:e,headers:i,signal:St(this.requestTimeout)}:{method:"POST",signal:St(this.requestTimeout)})}get(t){return this.fetch(t,{method:"GET",headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)})}put(t,e){return this.fetch(t,null!=e?{method:"PUT",body:e,headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)}:{method:"PUT",headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)})}delete(t,e){return this.fetch(t,null!=e?{method:"DELETE",body:e,headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)}:{method:"DELETE",headers:{"Content-type":"application/json"},signal:St(this.requestTimeout)})}async downloadFile(t,e,i){const r=await this.get(t);if(!r.ok)throw new Error("Response error.");let n;try{n=r.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]}catch(e){try{n=t.split("/").pop()}catch(t){n=`file${i}`}}if(e)return await new Promise(async(t,i)=>{R.default.mkdirSync(e,{recursive:!0});const s=R.default.createWriteStream(`${e}${n}`);r.body.pipe(s),r.body.on("error",i),s.on("finish",t)}),e;S.default(await r.arrayBuffer(),n)}async downloadFileBrowser(t){const e=document.createElement("a");e.download="",e.href=t,e.click()}async fetch(t,e){const i=await kt(t,e);if(!i.ok)throw this.logger.error(`Error requesting [${e.method}] ${t}`),this.logger.error(`Response message: \n${await i.text()}`),i;return i}}class Tt extends Mt{constructor(...t){super(...t),this.nonce=void 0,this.baseUrl=void 0,this.servicesEndpoints=void 0,this.computeAddress=void 0,this.providerAddress=void 0,this.providerVersion=void 0,this.computeLimits=void 0}static async getInstance(t){const e=new Tt;return e.setInstanceConfig(t),e.nonce="0",await e.setBaseUrl(t.config.providerUri),e}async setBaseUrl(t){return this.baseUrl=t,this.servicesEndpoints=await this.getServiceEndpoints(),!0}get url(){return this.baseUrl}async getServiceEndpoints(){const t=[];try{const e=await(await this.ocean.utils.fetch.get(this.url)).json();this.providerAddress=e.providerAddress,"computeAddress"in e&&(this.computeAddress=e.computeAddress),"version"in e&&(this.providerVersion=e.version),"computeLimits"in e&&(this.computeLimits=e.computeLimits);for(const i in e.serviceEndpoints)t.push({serviceName:i,method:e.serviceEndpoints[i][0],urlPath:this.url+e.serviceEndpoints[i][1]});return t}catch(t){return this.logger.error("Finding the service endpoints failed:",t),null}}getEndpointURL(t){return this.servicesEndpoints?this.servicesEndpoints.find(e=>e.serviceName===t):null}async createSignature(t,e){return await this.ocean.utils.signature.signText($(e),t.getId())}async createHashSignature(t,e){return await this.ocean.utils.signature.signWithHash(e,t.getId())}async encrypt(t,e,i){await this.getNonce(i.getId());const r={documentId:t,document:JSON.stringify(e),publisherAddress:i.getId()},n=this.getEncryptEndpoint()?this.getEncryptEndpoint().urlPath:null;if(!n)return null;try{const t=await this.ocean.utils.fetch.post(n,decodeURI(JSON.stringify(r)));return(await t.json()).encryptedDocument}catch(t){throw this.logger.error(t),new Error("HTTP request failed")}}async fileinfo(t){const e={url:t},i=[],r=this.getFileinfoEndpoint()?this.getFileinfoEndpoint().urlPath:null;if(!r)return null;try{const t=await this.ocean.utils.fetch.post(r,JSON.stringify(e)),n=await t.json();for(const t of n)i.push(t);return i}catch(t){return null}}async isFileConsumable(t,e){const i={did:t.getDid()},r=await this.ocean.metadataCache.retrieveDDO(t);if(!r)return!1;const n=r.findServiceById(e);if(!n)return!1;const s=n.serviceEndpoint+"/api/v1/services/fileinfo";try{const t=await this.ocean.utils.fetch.post(s,JSON.stringify(i));return(await t.json())[0].valid}catch(t){return!1}}async getNonce(t){const e=this.getNonceEndpoint()?this.getNonceEndpoint().urlPath:null;if(!e)return null;try{const i=await this.ocean.utils.fetch.get(e+`?userAddress=${t}`);return this.nonce=String((await i.json()).nonce),this.nonce}catch(t){throw this.logger.error(t),new Error("HTTP request failed")}}async initialize(t,e,i,r,n){const{did:s,ddo:o}=await pt(t,this.ocean);let a=this.getInitializeEndpoint()?this.getInitializeEndpoint().urlPath:null;if(!a)return null;a+=`?documentId=${s}`,a+=`&serviceId=${e}`,a+=`&serviceType=${i}`,a+=`&dataToken=${o.dataToken}`,a+=`&consumerAddress=${r}`,n&&(a+="&userdata="+encodeURI(JSON.stringify(n)));try{const t=await this.ocean.utils.fetch.get(a);return await t.text()}catch(t){throw this.logger.error(t),new Error("Asset URL not found or not available.")}}async download(t,e,i,r,n,s,o,a,h=-1,u){await this.getNonce(o.getId());const l=await this.createSignature(o,t+this.nonce),c=this.getDownloadEndpoint()?this.getDownloadEndpoint().urlPath:null;if(!c)return null;const d=a.filter((t,e)=>-1===h||e===h).map(async({index:a})=>{let h=c;h+=`?fileIndex=${a}`,h+=`&documentId=${t}`,h+=`&serviceId=${n}`,h+=`&serviceType=${r}`,h+=`&dataToken=${i}`,h+=`&transferTxId=${e}`,h+=`&consumerAddress=${o.getId()}`,h+=`&signature=${l}`,u&&(h+="&userdata="+encodeURI(JSON.stringify(u)));try{s?await this.ocean.utils.fetch.downloadFile(h,s,a):await this.ocean.utils.fetch.downloadFileBrowser(h)}catch(t){throw this.logger.error("Error consuming assets"),this.logger.error(t),t}});return await Promise.all(d),s}async computeStart(t,e,i,r,n,s,o,a,h,u){const l=e.getId();await this.getNonce(e.getId());const c=Object();c.documentId=$(t);let d=l;d+=t&&`${$(t)}`||"",d+=this.nonce;const f=await this.createHashSignature(e,d);c.signature=f,r&&(c.output=r),i.did&&(c.algorithmDid=i.did),i.meta&&(c.algorithmMeta=i.meta),c.consumerAddress=l,n&&(c.transferTxId=n),i.transferTxId&&(c.algorithmTransferTxId=i.transferTxId),i.dataToken&&(c.algorithmDataToken=i.dataToken),s&&(c.serviceId=s),o&&(c.serviceType=o),a&&(c.dataToken=a),h&&(c.additionalInputs=h),u&&(c.userdata=u),i.algoCustomParameters&&(c.algocustomdata=i.algoCustomParameters),i.userCustomParameters&&(c.algouserdata=i.userCustomParameters);const m=this.getComputeStartEndpoint()?this.getComputeStartEndpoint().urlPath:null;if(!m)return null;try{const t=await this.ocean.utils.fetch.post(m,JSON.stringify(c));return null!=t&&t.ok?await t.json():(console.error("Compute start failed:",t.status,t.statusText),this.logger.error("Payload was:",c),null)}catch(t){return this.logger.error("Compute start failed:"),this.logger.error(t),this.logger.error("Payload was:",c),null}}async computeStop(t,e,i){const r=e.getId();await this.getNonce(e.getId());const n=Object();n.documentId=$(t);let s=r;s+=i||"",s+=t&&`${$(t)}`||"",s+=this.nonce;const o=await this.createHashSignature(e,s);n.signature=o,n.jobId=i,n.consumerAddress=r;const a=this.getComputeStopEndpoint()?this.getComputeStopEndpoint().urlPath:null;if(!a)return null;try{const t=await this.ocean.utils.fetch.put(a,JSON.stringify(n));return null!=t&&t.ok?await t.json():(this.logger.error("Compute stop failed:",t.status,t.statusText),this.logger.error("Payload was:",n),null)}catch(t){return this.logger.error("Compute stop failed:"),this.logger.error(t),this.logger.error("Payload was:",n),null}}async computeDelete(t,e,i){const r=e.getId();await this.getNonce(e.getId());const n=Object();n.documentId=$(t);let s=r;s+=i||"",s+=t&&`${$(t)}`||"",s+=this.nonce;const o=await this.createHashSignature(e,s);n.signature=o,n.jobId=i,n.consumerAddress=r;const a=this.getComputeDeleteEndpoint()?this.getComputeDeleteEndpoint().urlPath:null;if(!a)return null;try{const t=await this.ocean.utils.fetch.delete(a,JSON.stringify(n));return null!=t&&t.ok?await t.json():(this.logger.error("Delete compute job failed:",t.status,t.statusText),this.logger.error("Payload was:",n),null)}catch(t){return this.logger.error("Delete compute job failed:"),this.logger.error(t),this.logger.error("Payload was:",n),null}}async computeStatus(t,e,i,r){const n=e.getId();await this.getNonce(e.getId());let s="?documentId="+$(t);s+=i&&`&jobId=${i}`||"",s+=`&consumerAddress=${n}`,s+=r&&`&transferTxId=${r}`||"";const o=this.getComputeStatusEndpoint()?this.getComputeStatusEndpoint().urlPath:null;if(!o)return null;try{const t=await this.ocean.utils.fetch.get(o+s);return null!=t&&t.ok?await t.json():(this.logger.error("Get compute status failed:",t.status,t.statusText),null)}catch(t){return this.logger.error("Get compute status failed"),this.logger.error(t),null}}async computeResult(t,e,i,r){await this.getNonce(r.getId());let n=r.getId();n+=t,n+=String(e),n+=this.nonce;const s=await this.createHashSignature(r,n),o=this.getComputeResultEndpoint()?this.getComputeResultEndpoint().urlPath:null;if(!o)return null;let a=o;a+=`?jobId=${t}`,a+=`&index=${String(e)}`,a+=`&signature=${s}`,a+=`&consumerAddress=${r.getId()}`;try{i?await this.ocean.utils.fetch.downloadFile(a,i,e):await this.ocean.utils.fetch.downloadFileBrowser(a)}catch(t){throw this.logger.error("Error getting job result"),this.logger.error(t),t}return i}getInitializeEndpoint(){return this.getEndpointURL("initialize")}getNonceEndpoint(){return this.getEndpointURL("nonce")}getEncryptEndpoint(){return this.getEndpointURL("encrypt")}getFileinfoEndpoint(){return this.getEndpointURL("fileinfo")}getComputeStartEndpoint(){return this.getEndpointURL("computeStart")}getComputeStopEndpoint(){return this.getEndpointURL("computeStop")}getComputeStatusEndpoint(){return this.getEndpointURL("computeStatus")}getComputeDeleteEndpoint(){return this.getEndpointURL("computeDelete")}getComputeResultEndpoint(){return this.getEndpointURL("computeResult")}getDownloadEndpoint(){return this.getEndpointURL("download")}async isValidProvider(t){try{const e=await this.ocean.utils.fetch.get(t);if(null!=e&&e.ok){const t=await e.json();if(t&&t.providerAddress)return!0}return!1}catch(t){return this.logger.error(`Error validating provider: ${t.message}`),!1}}}var Ot="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Bt(t){var e={exports:{}};return t(e,e.exports),e.exports}function Ct(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets option of @rollup/plugin-commonjs appropriately for this require call to behave properly.')}var _t=Bt(function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function n(t,e,i){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var s;"object"==typeof t?t.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=Ct("buffer").Buffer}catch(t){}function o(t,e,i){for(var r=0,n=Math.min(t.length,i),s=e;s<n;s++){var o=t.charCodeAt(s)-48;r<<=4,r|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return r}function a(t,e,i,r){for(var n=0,s=Math.min(t.length,i),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=r,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}n.isBN=function(t){return t instanceof n||null!==t&&"object"==typeof t&&t.constructor.wordSize===n.wordSize&&Array.isArray(t.words)},n.max=function(t,e){return t.cmp(e)>0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)this.words[s]|=(o=t[n]|t[n-1]<<8|t[n-2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)this.words[s]|=(o=t[n]|t[n+1]<<8|t[n+2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},n.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var r,n,s=0;for(i=t.length-6,r=0;i>=e;i-=6)n=o(t,i,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,r++);i+6!==e&&(n=o(t,e,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303),this.strip()},n.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var r=0,n=1;n<=67108863;n*=e)r++;r--,n=n/e|0;for(var s=t.length-i,o=s%r,h=Math.min(s,s-o)+i,u=0,l=i;l<h;l+=r)u=a(t,l,l+r,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=a(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},n.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},n.prototype.clone=function(){var t=new n(null);return this.copy(t),t},n.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},n.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},n.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","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"],u=[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],l=[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 c(t,e,i){i.negative=e.negative^t.negative;var r=t.length+e.length|0;i.length=r,r=r-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=o/67108864|0;i.words[0]=67108863&o;for(var h=1;h<r;h++){for(var u=a>>>26,l=67108863&a,c=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=c;d++)u+=(o=(n=0|t.words[h-d|0])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o;i.words[h]=0|l,a=0|u}return 0!==a?i.words[h]=0|a:i.length--,i.strip()}n.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],c=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?h[6-c.length]+c+r:c+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var d=u[t],f=l[t];r="";var m=this.clone();for(m.negative=0;!m.isZero();){var g=m.modn(f).toString(t);r=(m=m.idivn(f)).isZero()?g+r:h[d-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},n.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16)},n.prototype.toBuffer=function(t,e){return i(void 0!==s),this.toArrayLike(s,t,e)},n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,u=new t(s),l=this.clone();if(h){for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[a]=o;for(;a<s;a++)u[a]=0}else{for(a=0;a<s-n;a++)u[a]=0;for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[s-a-1]=o}return u},n.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},n.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},n.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.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()},n.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},n.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},n.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},n.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var r=0;r<i.length;r++)this.words[r]=e.words[r]^i.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this.strip()},n.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},n.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},n.prototype.iadd=function(t){var e,i,r;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?(i=this,r=t):(i=t,r=this);for(var n=0,s=0;s<r.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+(0|r.words[s])+n),n=e>>>26;for(;0!==n&&s<i.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+n),n=e>>>26;if(this.length=i.length,0!==n)this.words[this.length]=n,this.length++;else if(i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this},n.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)},n.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 i,r,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(i=this,r=t):(i=t,r=this);for(var s=0,o=0;o<r.length;o++)s=(e=(0|i.words[o])-(0|r.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<i.length;o++)s=(e=(0|i.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<i.length&&i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this.length=Math.max(this.length,o),i!==this&&(this.negative=1),this.strip()},n.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,i){var r,n,s,o=t.words,a=e.words,h=i.words,u=0,l=0|o[0],c=8191&l,d=l>>>13,f=0|o[1],m=8191&f,g=f>>>13,p=0|o[2],w=8191&p,v=p>>>13,y=0|o[3],M=8191&y,b=y>>>13,A=0|o[4],x=8191&A,E=A>>>13,R=0|o[5],S=8191&R,k=R>>>13,I=0|o[6],T=8191&I,O=I>>>13,B=0|o[7],C=8191&B,_=B>>>13,P=0|o[8],D=8191&P,L=P>>>13,N=0|o[9],W=8191&N,F=N>>>13,U=0|a[0],q=8191&U,$=U>>>13,j=0|a[1],G=8191&j,z=j>>>13,H=0|a[2],Z=8191&H,V=H>>>13,J=0|a[3],K=8191&J,X=J>>>13,Q=0|a[4],Y=8191&Q,tt=Q>>>13,et=0|a[5],it=8191&et,rt=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,dt=lt>>>13,ft=0|a[9],mt=8191&ft,gt=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var pt=(u+(r=Math.imul(c,q))|0)+((8191&(n=(n=Math.imul(c,$))+Math.imul(d,q)|0))<<13)|0;u=((s=Math.imul(d,$))+(n>>>13)|0)+(pt>>>26)|0,pt&=67108863,r=Math.imul(m,q),n=(n=Math.imul(m,$))+Math.imul(g,q)|0,s=Math.imul(g,$);var wt=(u+(r=r+Math.imul(c,G)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(d,G)|0))<<13)|0;u=((s=s+Math.imul(d,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(w,q),n=(n=Math.imul(w,$))+Math.imul(v,q)|0,s=Math.imul(v,$),r=r+Math.imul(m,G)|0,n=(n=n+Math.imul(m,z)|0)+Math.imul(g,G)|0,s=s+Math.imul(g,z)|0;var vt=(u+(r=r+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,Z)|0))<<13)|0;u=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(M,q),n=(n=Math.imul(M,$))+Math.imul(b,q)|0,s=Math.imul(b,$),r=r+Math.imul(w,G)|0,n=(n=n+Math.imul(w,z)|0)+Math.imul(v,G)|0,s=s+Math.imul(v,z)|0,r=r+Math.imul(m,Z)|0,n=(n=n+Math.imul(m,V)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,V)|0;var yt=(u+(r=r+Math.imul(c,K)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,K)|0))<<13)|0;u=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(x,q),n=(n=Math.imul(x,$))+Math.imul(E,q)|0,s=Math.imul(E,$),r=r+Math.imul(M,G)|0,n=(n=n+Math.imul(M,z)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,z)|0,r=r+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,V)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,V)|0,r=r+Math.imul(m,K)|0,n=(n=n+Math.imul(m,X)|0)+Math.imul(g,K)|0,s=s+Math.imul(g,X)|0;var Mt=(u+(r=r+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(S,q),n=(n=Math.imul(S,$))+Math.imul(k,q)|0,s=Math.imul(k,$),r=r+Math.imul(x,G)|0,n=(n=n+Math.imul(x,z)|0)+Math.imul(E,G)|0,s=s+Math.imul(E,z)|0,r=r+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,V)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,V)|0,r=r+Math.imul(w,K)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(v,K)|0,s=s+Math.imul(v,X)|0,r=r+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,tt)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,tt)|0;var bt=(u+(r=r+Math.imul(c,it)|0)|0)+((8191&(n=(n=n+Math.imul(c,rt)|0)+Math.imul(d,it)|0))<<13)|0;u=((s=s+Math.imul(d,rt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(T,q),n=(n=Math.imul(T,$))+Math.imul(O,q)|0,s=Math.imul(O,$),r=r+Math.imul(S,G)|0,n=(n=n+Math.imul(S,z)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,z)|0,r=r+Math.imul(x,Z)|0,n=(n=n+Math.imul(x,V)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,V)|0,r=r+Math.imul(M,K)|0,n=(n=n+Math.imul(M,X)|0)+Math.imul(b,K)|0,s=s+Math.imul(b,X)|0,r=r+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,tt)|0,r=r+Math.imul(m,it)|0,n=(n=n+Math.imul(m,rt)|0)+Math.imul(g,it)|0,s=s+Math.imul(g,rt)|0;var At=(u+(r=r+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,q),n=(n=Math.imul(C,$))+Math.imul(_,q)|0,s=Math.imul(_,$),r=r+Math.imul(T,G)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(O,G)|0,s=s+Math.imul(O,z)|0,r=r+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,V)|0,r=r+Math.imul(x,K)|0,n=(n=n+Math.imul(x,X)|0)+Math.imul(E,K)|0,s=s+Math.imul(E,X)|0,r=r+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,tt)|0,r=r+Math.imul(w,it)|0,n=(n=n+Math.imul(w,rt)|0)+Math.imul(v,it)|0,s=s+Math.imul(v,rt)|0,r=r+Math.imul(m,st)|0,n=(n=n+Math.imul(m,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var xt=(u+(r=r+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(d,ht)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(D,q),n=(n=Math.imul(D,$))+Math.imul(L,q)|0,s=Math.imul(L,$),r=r+Math.imul(C,G)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(_,G)|0,s=s+Math.imul(_,z)|0,r=r+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,V)|0,r=r+Math.imul(S,K)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(k,K)|0,s=s+Math.imul(k,X)|0,r=r+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,r=r+Math.imul(M,it)|0,n=(n=n+Math.imul(M,rt)|0)+Math.imul(b,it)|0,s=s+Math.imul(b,rt)|0,r=r+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,r=r+Math.imul(m,ht)|0,n=(n=n+Math.imul(m,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var Et=(u+(r=r+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(W,q),n=(n=Math.imul(W,$))+Math.imul(F,q)|0,s=Math.imul(F,$),r=r+Math.imul(D,G)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,z)|0,r=r+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,V)|0,r=r+Math.imul(T,K)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(O,K)|0,s=s+Math.imul(O,X)|0,r=r+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,r=r+Math.imul(x,it)|0,n=(n=n+Math.imul(x,rt)|0)+Math.imul(E,it)|0,s=s+Math.imul(E,rt)|0,r=r+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,r=r+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,r=r+Math.imul(m,ct)|0,n=(n=n+Math.imul(m,dt)|0)+Math.imul(g,ct)|0,s=s+Math.imul(g,dt)|0;var Rt=(u+(r=r+Math.imul(c,mt)|0)|0)+((8191&(n=(n=n+Math.imul(c,gt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,r=Math.imul(W,G),n=(n=Math.imul(W,z))+Math.imul(F,G)|0,s=Math.imul(F,z),r=r+Math.imul(D,Z)|0,n=(n=n+Math.imul(D,V)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,V)|0,r=r+Math.imul(C,K)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(_,K)|0,s=s+Math.imul(_,X)|0,r=r+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,r=r+Math.imul(S,it)|0,n=(n=n+Math.imul(S,rt)|0)+Math.imul(k,it)|0,s=s+Math.imul(k,rt)|0,r=r+Math.imul(x,st)|0,n=(n=n+Math.imul(x,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,r=r+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ut)|0)+Math.imul(b,ht)|0,s=s+Math.imul(b,ut)|0,r=r+Math.imul(w,ct)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(v,ct)|0,s=s+Math.imul(v,dt)|0;var St=(u+(r=r+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,gt)|0)+Math.imul(g,mt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(W,Z),n=(n=Math.imul(W,V))+Math.imul(F,Z)|0,s=Math.imul(F,V),r=r+Math.imul(D,K)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,X)|0,r=r+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,tt)|0,r=r+Math.imul(T,it)|0,n=(n=n+Math.imul(T,rt)|0)+Math.imul(O,it)|0,s=s+Math.imul(O,rt)|0,r=r+Math.imul(S,st)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,r=r+Math.imul(x,ht)|0,n=(n=n+Math.imul(x,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,r=r+Math.imul(M,ct)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(b,ct)|0,s=s+Math.imul(b,dt)|0;var kt=(u+(r=r+Math.imul(w,mt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(v,mt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(W,K),n=(n=Math.imul(W,X))+Math.imul(F,K)|0,s=Math.imul(F,X),r=r+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,tt)|0,r=r+Math.imul(C,it)|0,n=(n=n+Math.imul(C,rt)|0)+Math.imul(_,it)|0,s=s+Math.imul(_,rt)|0,r=r+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,r=r+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,s=s+Math.imul(k,ut)|0,r=r+Math.imul(x,ct)|0,n=(n=n+Math.imul(x,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var It=(u+(r=r+Math.imul(M,mt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(b,mt)|0))<<13)|0;u=((s=s+Math.imul(b,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(W,Y),n=(n=Math.imul(W,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),r=r+Math.imul(D,it)|0,n=(n=n+Math.imul(D,rt)|0)+Math.imul(L,it)|0,s=s+Math.imul(L,rt)|0,r=r+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,r=r+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,r=r+Math.imul(S,ct)|0,n=(n=n+Math.imul(S,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var Tt=(u+(r=r+Math.imul(x,mt)|0)|0)+((8191&(n=(n=n+Math.imul(x,gt)|0)+Math.imul(E,mt)|0))<<13)|0;u=((s=s+Math.imul(E,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(W,it),n=(n=Math.imul(W,rt))+Math.imul(F,it)|0,s=Math.imul(F,rt),r=r+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,r=r+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,r=r+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Ot=(u+(r=r+Math.imul(S,mt)|0)|0)+((8191&(n=(n=n+Math.imul(S,gt)|0)+Math.imul(k,mt)|0))<<13)|0;u=((s=s+Math.imul(k,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(W,st),n=(n=Math.imul(W,ot))+Math.imul(F,st)|0,s=Math.imul(F,ot),r=r+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,r=r+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,dt)|0)+Math.imul(_,ct)|0,s=s+Math.imul(_,dt)|0;var Bt=(u+(r=r+Math.imul(T,mt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(O,mt)|0))<<13)|0;u=((s=s+Math.imul(O,gt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,r=Math.imul(W,ht),n=(n=Math.imul(W,ut))+Math.imul(F,ht)|0,s=Math.imul(F,ut),r=r+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,dt)|0)+Math.imul(L,ct)|0,s=s+Math.imul(L,dt)|0;var Ct=(u+(r=r+Math.imul(C,mt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(_,mt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(W,ct),n=(n=Math.imul(W,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var _t=(u+(r=r+Math.imul(D,mt)|0)|0)+((8191&(n=(n=n+Math.imul(D,gt)|0)+Math.imul(L,mt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863;var Pt=(u+(r=Math.imul(W,mt))|0)+((8191&(n=(n=Math.imul(W,gt))+Math.imul(F,mt)|0))<<13)|0;return u=((s=Math.imul(F,gt))+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,h[0]=pt,h[1]=wt,h[2]=vt,h[3]=yt,h[4]=Mt,h[5]=bt,h[6]=At,h[7]=xt,h[8]=Et,h[9]=Rt,h[10]=St,h[11]=kt,h[12]=It,h[13]=Tt,h[14]=Ot,h[15]=Bt,h[16]=Ct,h[17]=_t,h[18]=Pt,0!==u&&(h[19]=u,i.length++),i};function f(t,e,i){return(new m).mulp(t,e,i)}function m(t,e){this.x=t,this.y=e}Math.imul||(d=c),n.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):i<63?c(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var r=0,n=0,s=0;s<i.length-1;s++){var o=n;n=0;for(var a=67108863&r,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=(0|t.words[s-u])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),n+=(o=(o=o+(l/67108864|0)|0)+(c>>>26)|0)>>>26,o&=67108863}i.words[s]=a,r=o,o=n}return 0!==r?i.words[s]=r:i.length--,i.strip()}(this,t,e):f(this,t,e)},m.prototype.makeRBT=function(t){for(var e=new Array(t),i=n.prototype._countBits(t)-1,r=0;r<t;r++)e[r]=this.revBin(r,i,t);return e},m.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var r=0,n=0;n<e;n++)r|=(1&t)<<e-n-1,t>>=1;return r},m.prototype.permute=function(t,e,i,r,n,s){for(var o=0;o<s;o++)r[o]=e[t[o]],n[o]=i[t[o]]},m.prototype.transform=function(t,e,i,r,n,s){this.permute(s,t,e,i,r,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,d=u,f=0;f<o;f++){var m=i[l+f],g=r[l+f],p=i[l+f+o],w=r[l+f+o],v=c*p-d*w;w=c*w+d*p,i[l+f]=m+(p=v),r[l+f]=g+w,i[l+f+o]=m-p,r[l+f+o]=g-w,f!==a&&(v=h*c-u*d,d=h*d+u*c,c=v)}},m.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),r=1&i,n=0;for(i=i/2|0;i;i>>>=1)n++;return 1<<n+1+r},m.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var r=0;r<i/2;r++){var n=t[r];t[r]=t[i-r-1],t[i-r-1]=n,n=e[r],e[r]=-e[i-r-1],e[i-r-1]=-n}},m.prototype.normalize13b=function(t,e){for(var i=0,r=0;r<e/2;r++){var n=8192*Math.round(t[2*r+1]/e)+Math.round(t[2*r]/e)+i;t[r]=67108863&n,i=n<67108864?0:n/67108864|0}return t},m.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)r[2*o]=8191&(s+=0|t[o]),r[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},m.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},m.prototype.mulp=function(t,e,i){var r=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(r),s=this.stub(r),o=new Array(r),a=new Array(r),h=new Array(r),u=new Array(r),l=new Array(r),c=new Array(r),d=i.words;d.length=r,this.convert13b(t.words,t.length,o,r),this.convert13b(e.words,e.length,u,r),this.transform(o,s,a,h,r,n),this.transform(u,s,l,c,r,n);for(var f=0;f<r;f++){var m=a[f]*l[f]-h[f]*c[f];h[f]=a[f]*c[f]+h[f]*l[f],a[f]=m}return this.conjugate(a,h,r),this.transform(a,h,d,s,r,n),this.conjugate(d,s,r),this.normalize13b(d,r),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),f(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,r=0;r<this.length;r++){var n=(0|this.words[r])*t,s=(67108863&n)+(67108863&e);e>>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var r=i%26;e[i]=(t.words[i/26|0]&1<<r)>>>r}return e}(t);if(0===e.length)return new n(1);for(var i=this,r=0;r<e.length&&0===e[r];r++,i=i.sqr());if(++r<e.length)for(var s=i.sqr();r<e.length;r++,s=s.sqr())0!==e[r]&&(i=i.mul(s));return i},n.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s;this.words[e]=(0|this.words[e])-a<<r|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this.strip()},n.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},n.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},n.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return!(this.length<=r||!(this.words[r]&1<<e))},n.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r?this:(0!==e&&r++,this.length=Math.min(r,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},n.prototype.maskn=function(t){return this.clone().imaskn(t)},n.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},n.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},n.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},n.prototype.addn=function(t){return this.clone().iaddn(t)},n.prototype.subn=function(t){return this.clone().isubn(t)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(t,e,r){var n,s;this._expand(t.length+r);var o=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+o;var a=(0|t.words[n])*e;o=((s-=67108863&a)>>26)-(a/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)o=(s=(0|this.words[n+r])+o)>>26,this.words[n+r]=67108863&s;if(0===o)return this.strip();for(i(-1===o),o=0,n=0;n<this.length;n++)o=(s=-(0|this.words[n])+o)>>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},n.prototype._wordDiv=function(t,e){var i,r=this.clone(),s=t,o=0|s.words[s.length-1];0!=(i=26-this._countBits(o))&&(s=s.ushln(i),r.iushln(i),o=0|s.words[s.length-1]);var a,h=r.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=r.clone()._ishlnsubmul(s,1,h);0===l.negative&&(r=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var d=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]);for(d=Math.min(d/o|0,67108863),r._ishlnsubmul(s,d,c);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);a&&(a.words[c]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==i&&r.iushrn(i),{div:a||null,mod:r}},n.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),n=t.andln(1),s=i.cmp(r);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},n.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(l),o.isub(c)),s.iushrn(1),o.iushrn(1);for(var m=0,g=1;0==(r.words[0]&g)&&m<26;++m,g<<=1);if(m>0)for(r.iushrn(m);m-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a),o.isub(h)):(r.isub(e),a.isub(s),h.isub(o))}return{a:a,b:h,gcd:r.iushln(u)}},n.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,o=new n(1),a=new n(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,d=1;0==(r.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(s=0===e.cmpn(1)?o:a).cmpn(0)<0&&s.iadd(t),s},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var r=0;e.isEven()&&i.isEven();r++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var n=e.cmp(i);if(n<0){var s=e;e=i,i=s}else if(0===n||0===i.cmpn(1))break;e.isub(i)}return i.iushln(r)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,this.words[o]=a&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},n.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},n.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var r=0|this.words[i],n=0|t.words[i];if(r!==n){r<n?e=-1:r>n&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new b(t)},n.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var g={k256:null,p224:null,p192:null,p25519:null};function p(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}p.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:i.ucmp(this.p);return 0===r?(i.words[0]=0,i.length=1):r>0?i.isub(this.p):i.strip(),i},p.prototype.split=function(t,e){t.iushrn(this.n,0,e)},p.prototype.imulK=function(t){return t.imul(this.k)},r(w,p),w.prototype.split=function(t,e){for(var i=4194303,r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&i,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&i)<<4|s>>>22,s=o}t.words[n-10]=s>>>=22,t.length-=0===s&&t.length>10?10:9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var r=0|t.words[i];t.words[i]=67108863&(e+=977*r),e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,p),r(y,p),r(M,p),M.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var r=19*(0|t.words[i])+e,n=67108863&r;r>>>=26,t.words[i]=n,e=r}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new v;else if("p192"===t)e=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return g[t]=e,e},b.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},b.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},b.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},b.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},b.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},b.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},b.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},b.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},b.prototype.isqr=function(t){return this.imul(t,t.clone())},b.prototype.sqr=function(t){return this.mul(t,t)},b.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new n(1)).iushrn(2);return this.pow(t,r)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);i(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),m=o;0!==f.cmp(a);){for(var g=f,p=0;0!==g.cmp(a);p++)g=g.redSqr();i(p<m);var w=this.pow(c,new n(1).iushln(m-p-1));d=d.redMul(w),c=w.redSqr(),f=f.redMul(c),m=p}return d},b.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},b.prototype.pow=function(t,e){if(e.isZero())return new n(1);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new n(1).toRed(this),i[1]=t;for(var r=2;r<i.length;r++)i[r]=this.mul(i[r-1],t);var s=i[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),r=e.length-1;r>=0;r--){for(var u=e.words[r],l=h-1;l>=0;l--){var c=u>>l&1;s!==i[0]&&(s=this.sqr(s)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===r&&0===l)&&(s=this.mul(s,i[o]),a=0,o=0)):a=0}h=26}return s},b.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},b.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new A(t)},r(A,b),A.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},A.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},A.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=i.isub(r).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},A.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var i=t.mul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=i.isub(r).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},A.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,Ot)}),Pt=Bt(function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function n(t,e,i){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var s;"object"==typeof t?t.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=Ct("buffer").Buffer}catch(t){}function o(t,e,i){for(var r=0,n=Math.min(t.length,i),s=e;s<n;s++){var o=t.charCodeAt(s)-48;r<<=4,r|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return r}function a(t,e,i,r){for(var n=0,s=Math.min(t.length,i),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=r,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}n.isBN=function(t){return t instanceof n||null!==t&&"object"==typeof t&&t.constructor.wordSize===n.wordSize&&Array.isArray(t.words)},n.max=function(t,e){return t.cmp(e)>0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)this.words[s]|=(o=t[n]|t[n-1]<<8|t[n-2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)this.words[s]|=(o=t[n]|t[n+1]<<8|t[n+2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},n.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var r,n,s=0;for(i=t.length-6,r=0;i>=e;i-=6)n=o(t,i,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,r++);i+6!==e&&(n=o(t,e,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303),this.strip()},n.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var r=0,n=1;n<=67108863;n*=e)r++;r--,n=n/e|0;for(var s=t.length-i,o=s%r,h=Math.min(s,s-o)+i,u=0,l=i;l<h;l+=r)u=a(t,l,l+r,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=a(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},n.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},n.prototype.clone=function(){var t=new n(null);return this.copy(t),t},n.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},n.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},n.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","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"],u=[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],l=[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 c(t,e,i){i.negative=e.negative^t.negative;var r=t.length+e.length|0;i.length=r,r=r-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=o/67108864|0;i.words[0]=67108863&o;for(var h=1;h<r;h++){for(var u=a>>>26,l=67108863&a,c=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=c;d++)u+=(o=(n=0|t.words[h-d|0])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o;i.words[h]=0|l,a=0|u}return 0!==a?i.words[h]=0|a:i.length--,i.strip()}n.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],c=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?h[6-c.length]+c+r:c+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var d=u[t],f=l[t];r="";var m=this.clone();for(m.negative=0;!m.isZero();){var g=m.modn(f).toString(t);r=(m=m.idivn(f)).isZero()?g+r:h[d-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},n.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16)},n.prototype.toBuffer=function(t,e){return i(void 0!==s),this.toArrayLike(s,t,e)},n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,u=new t(s),l=this.clone();if(h){for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[a]=o;for(;a<s;a++)u[a]=0}else{for(a=0;a<s-n;a++)u[a]=0;for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[s-a-1]=o}return u},n.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},n.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},n.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.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()},n.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},n.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},n.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},n.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var r=0;r<i.length;r++)this.words[r]=e.words[r]^i.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this.strip()},n.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},n.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},n.prototype.iadd=function(t){var e,i,r;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?(i=this,r=t):(i=t,r=this);for(var n=0,s=0;s<r.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+(0|r.words[s])+n),n=e>>>26;for(;0!==n&&s<i.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+n),n=e>>>26;if(this.length=i.length,0!==n)this.words[this.length]=n,this.length++;else if(i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this},n.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)},n.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 i,r,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(i=this,r=t):(i=t,r=this);for(var s=0,o=0;o<r.length;o++)s=(e=(0|i.words[o])-(0|r.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<i.length;o++)s=(e=(0|i.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<i.length&&i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this.length=Math.max(this.length,o),i!==this&&(this.negative=1),this.strip()},n.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,i){var r,n,s,o=t.words,a=e.words,h=i.words,u=0,l=0|o[0],c=8191&l,d=l>>>13,f=0|o[1],m=8191&f,g=f>>>13,p=0|o[2],w=8191&p,v=p>>>13,y=0|o[3],M=8191&y,b=y>>>13,A=0|o[4],x=8191&A,E=A>>>13,R=0|o[5],S=8191&R,k=R>>>13,I=0|o[6],T=8191&I,O=I>>>13,B=0|o[7],C=8191&B,_=B>>>13,P=0|o[8],D=8191&P,L=P>>>13,N=0|o[9],W=8191&N,F=N>>>13,U=0|a[0],q=8191&U,$=U>>>13,j=0|a[1],G=8191&j,z=j>>>13,H=0|a[2],Z=8191&H,V=H>>>13,J=0|a[3],K=8191&J,X=J>>>13,Q=0|a[4],Y=8191&Q,tt=Q>>>13,et=0|a[5],it=8191&et,rt=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,dt=lt>>>13,ft=0|a[9],mt=8191&ft,gt=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var pt=(u+(r=Math.imul(c,q))|0)+((8191&(n=(n=Math.imul(c,$))+Math.imul(d,q)|0))<<13)|0;u=((s=Math.imul(d,$))+(n>>>13)|0)+(pt>>>26)|0,pt&=67108863,r=Math.imul(m,q),n=(n=Math.imul(m,$))+Math.imul(g,q)|0,s=Math.imul(g,$);var wt=(u+(r=r+Math.imul(c,G)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(d,G)|0))<<13)|0;u=((s=s+Math.imul(d,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(w,q),n=(n=Math.imul(w,$))+Math.imul(v,q)|0,s=Math.imul(v,$),r=r+Math.imul(m,G)|0,n=(n=n+Math.imul(m,z)|0)+Math.imul(g,G)|0,s=s+Math.imul(g,z)|0;var vt=(u+(r=r+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,Z)|0))<<13)|0;u=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(M,q),n=(n=Math.imul(M,$))+Math.imul(b,q)|0,s=Math.imul(b,$),r=r+Math.imul(w,G)|0,n=(n=n+Math.imul(w,z)|0)+Math.imul(v,G)|0,s=s+Math.imul(v,z)|0,r=r+Math.imul(m,Z)|0,n=(n=n+Math.imul(m,V)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,V)|0;var yt=(u+(r=r+Math.imul(c,K)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,K)|0))<<13)|0;u=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(x,q),n=(n=Math.imul(x,$))+Math.imul(E,q)|0,s=Math.imul(E,$),r=r+Math.imul(M,G)|0,n=(n=n+Math.imul(M,z)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,z)|0,r=r+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,V)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,V)|0,r=r+Math.imul(m,K)|0,n=(n=n+Math.imul(m,X)|0)+Math.imul(g,K)|0,s=s+Math.imul(g,X)|0;var Mt=(u+(r=r+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(S,q),n=(n=Math.imul(S,$))+Math.imul(k,q)|0,s=Math.imul(k,$),r=r+Math.imul(x,G)|0,n=(n=n+Math.imul(x,z)|0)+Math.imul(E,G)|0,s=s+Math.imul(E,z)|0,r=r+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,V)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,V)|0,r=r+Math.imul(w,K)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(v,K)|0,s=s+Math.imul(v,X)|0,r=r+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,tt)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,tt)|0;var bt=(u+(r=r+Math.imul(c,it)|0)|0)+((8191&(n=(n=n+Math.imul(c,rt)|0)+Math.imul(d,it)|0))<<13)|0;u=((s=s+Math.imul(d,rt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(T,q),n=(n=Math.imul(T,$))+Math.imul(O,q)|0,s=Math.imul(O,$),r=r+Math.imul(S,G)|0,n=(n=n+Math.imul(S,z)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,z)|0,r=r+Math.imul(x,Z)|0,n=(n=n+Math.imul(x,V)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,V)|0,r=r+Math.imul(M,K)|0,n=(n=n+Math.imul(M,X)|0)+Math.imul(b,K)|0,s=s+Math.imul(b,X)|0,r=r+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,tt)|0,r=r+Math.imul(m,it)|0,n=(n=n+Math.imul(m,rt)|0)+Math.imul(g,it)|0,s=s+Math.imul(g,rt)|0;var At=(u+(r=r+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,q),n=(n=Math.imul(C,$))+Math.imul(_,q)|0,s=Math.imul(_,$),r=r+Math.imul(T,G)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(O,G)|0,s=s+Math.imul(O,z)|0,r=r+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,V)|0,r=r+Math.imul(x,K)|0,n=(n=n+Math.imul(x,X)|0)+Math.imul(E,K)|0,s=s+Math.imul(E,X)|0,r=r+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,tt)|0,r=r+Math.imul(w,it)|0,n=(n=n+Math.imul(w,rt)|0)+Math.imul(v,it)|0,s=s+Math.imul(v,rt)|0,r=r+Math.imul(m,st)|0,n=(n=n+Math.imul(m,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var xt=(u+(r=r+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(d,ht)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(D,q),n=(n=Math.imul(D,$))+Math.imul(L,q)|0,s=Math.imul(L,$),r=r+Math.imul(C,G)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(_,G)|0,s=s+Math.imul(_,z)|0,r=r+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,V)|0,r=r+Math.imul(S,K)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(k,K)|0,s=s+Math.imul(k,X)|0,r=r+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,r=r+Math.imul(M,it)|0,n=(n=n+Math.imul(M,rt)|0)+Math.imul(b,it)|0,s=s+Math.imul(b,rt)|0,r=r+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,r=r+Math.imul(m,ht)|0,n=(n=n+Math.imul(m,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var Et=(u+(r=r+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(W,q),n=(n=Math.imul(W,$))+Math.imul(F,q)|0,s=Math.imul(F,$),r=r+Math.imul(D,G)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,z)|0,r=r+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,V)|0,r=r+Math.imul(T,K)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(O,K)|0,s=s+Math.imul(O,X)|0,r=r+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,r=r+Math.imul(x,it)|0,n=(n=n+Math.imul(x,rt)|0)+Math.imul(E,it)|0,s=s+Math.imul(E,rt)|0,r=r+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,r=r+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,r=r+Math.imul(m,ct)|0,n=(n=n+Math.imul(m,dt)|0)+Math.imul(g,ct)|0,s=s+Math.imul(g,dt)|0;var Rt=(u+(r=r+Math.imul(c,mt)|0)|0)+((8191&(n=(n=n+Math.imul(c,gt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,r=Math.imul(W,G),n=(n=Math.imul(W,z))+Math.imul(F,G)|0,s=Math.imul(F,z),r=r+Math.imul(D,Z)|0,n=(n=n+Math.imul(D,V)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,V)|0,r=r+Math.imul(C,K)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(_,K)|0,s=s+Math.imul(_,X)|0,r=r+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,r=r+Math.imul(S,it)|0,n=(n=n+Math.imul(S,rt)|0)+Math.imul(k,it)|0,s=s+Math.imul(k,rt)|0,r=r+Math.imul(x,st)|0,n=(n=n+Math.imul(x,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,r=r+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ut)|0)+Math.imul(b,ht)|0,s=s+Math.imul(b,ut)|0,r=r+Math.imul(w,ct)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(v,ct)|0,s=s+Math.imul(v,dt)|0;var St=(u+(r=r+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,gt)|0)+Math.imul(g,mt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(W,Z),n=(n=Math.imul(W,V))+Math.imul(F,Z)|0,s=Math.imul(F,V),r=r+Math.imul(D,K)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,X)|0,r=r+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,tt)|0,r=r+Math.imul(T,it)|0,n=(n=n+Math.imul(T,rt)|0)+Math.imul(O,it)|0,s=s+Math.imul(O,rt)|0,r=r+Math.imul(S,st)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,r=r+Math.imul(x,ht)|0,n=(n=n+Math.imul(x,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,r=r+Math.imul(M,ct)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(b,ct)|0,s=s+Math.imul(b,dt)|0;var kt=(u+(r=r+Math.imul(w,mt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(v,mt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(W,K),n=(n=Math.imul(W,X))+Math.imul(F,K)|0,s=Math.imul(F,X),r=r+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,tt)|0,r=r+Math.imul(C,it)|0,n=(n=n+Math.imul(C,rt)|0)+Math.imul(_,it)|0,s=s+Math.imul(_,rt)|0,r=r+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,r=r+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,s=s+Math.imul(k,ut)|0,r=r+Math.imul(x,ct)|0,n=(n=n+Math.imul(x,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var It=(u+(r=r+Math.imul(M,mt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(b,mt)|0))<<13)|0;u=((s=s+Math.imul(b,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(W,Y),n=(n=Math.imul(W,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),r=r+Math.imul(D,it)|0,n=(n=n+Math.imul(D,rt)|0)+Math.imul(L,it)|0,s=s+Math.imul(L,rt)|0,r=r+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,r=r+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,r=r+Math.imul(S,ct)|0,n=(n=n+Math.imul(S,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var Tt=(u+(r=r+Math.imul(x,mt)|0)|0)+((8191&(n=(n=n+Math.imul(x,gt)|0)+Math.imul(E,mt)|0))<<13)|0;u=((s=s+Math.imul(E,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(W,it),n=(n=Math.imul(W,rt))+Math.imul(F,it)|0,s=Math.imul(F,rt),r=r+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,r=r+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,r=r+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Ot=(u+(r=r+Math.imul(S,mt)|0)|0)+((8191&(n=(n=n+Math.imul(S,gt)|0)+Math.imul(k,mt)|0))<<13)|0;u=((s=s+Math.imul(k,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(W,st),n=(n=Math.imul(W,ot))+Math.imul(F,st)|0,s=Math.imul(F,ot),r=r+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,r=r+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,dt)|0)+Math.imul(_,ct)|0,s=s+Math.imul(_,dt)|0;var Bt=(u+(r=r+Math.imul(T,mt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(O,mt)|0))<<13)|0;u=((s=s+Math.imul(O,gt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,r=Math.imul(W,ht),n=(n=Math.imul(W,ut))+Math.imul(F,ht)|0,s=Math.imul(F,ut),r=r+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,dt)|0)+Math.imul(L,ct)|0,s=s+Math.imul(L,dt)|0;var Ct=(u+(r=r+Math.imul(C,mt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(_,mt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(W,ct),n=(n=Math.imul(W,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var _t=(u+(r=r+Math.imul(D,mt)|0)|0)+((8191&(n=(n=n+Math.imul(D,gt)|0)+Math.imul(L,mt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863;var Pt=(u+(r=Math.imul(W,mt))|0)+((8191&(n=(n=Math.imul(W,gt))+Math.imul(F,mt)|0))<<13)|0;return u=((s=Math.imul(F,gt))+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,h[0]=pt,h[1]=wt,h[2]=vt,h[3]=yt,h[4]=Mt,h[5]=bt,h[6]=At,h[7]=xt,h[8]=Et,h[9]=Rt,h[10]=St,h[11]=kt,h[12]=It,h[13]=Tt,h[14]=Ot,h[15]=Bt,h[16]=Ct,h[17]=_t,h[18]=Pt,0!==u&&(h[19]=u,i.length++),i};function f(t,e,i){return(new m).mulp(t,e,i)}function m(t,e){this.x=t,this.y=e}Math.imul||(d=c),n.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):i<63?c(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var r=0,n=0,s=0;s<i.length-1;s++){var o=n;n=0;for(var a=67108863&r,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=(0|t.words[s-u])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),n+=(o=(o=o+(l/67108864|0)|0)+(c>>>26)|0)>>>26,o&=67108863}i.words[s]=a,r=o,o=n}return 0!==r?i.words[s]=r:i.length--,i.strip()}(this,t,e):f(this,t,e)},m.prototype.makeRBT=function(t){for(var e=new Array(t),i=n.prototype._countBits(t)-1,r=0;r<t;r++)e[r]=this.revBin(r,i,t);return e},m.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var r=0,n=0;n<e;n++)r|=(1&t)<<e-n-1,t>>=1;return r},m.prototype.permute=function(t,e,i,r,n,s){for(var o=0;o<s;o++)r[o]=e[t[o]],n[o]=i[t[o]]},m.prototype.transform=function(t,e,i,r,n,s){this.permute(s,t,e,i,r,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,d=u,f=0;f<o;f++){var m=i[l+f],g=r[l+f],p=i[l+f+o],w=r[l+f+o],v=c*p-d*w;w=c*w+d*p,i[l+f]=m+(p=v),r[l+f]=g+w,i[l+f+o]=m-p,r[l+f+o]=g-w,f!==a&&(v=h*c-u*d,d=h*d+u*c,c=v)}},m.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),r=1&i,n=0;for(i=i/2|0;i;i>>>=1)n++;return 1<<n+1+r},m.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var r=0;r<i/2;r++){var n=t[r];t[r]=t[i-r-1],t[i-r-1]=n,n=e[r],e[r]=-e[i-r-1],e[i-r-1]=-n}},m.prototype.normalize13b=function(t,e){for(var i=0,r=0;r<e/2;r++){var n=8192*Math.round(t[2*r+1]/e)+Math.round(t[2*r]/e)+i;t[r]=67108863&n,i=n<67108864?0:n/67108864|0}return t},m.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)r[2*o]=8191&(s+=0|t[o]),r[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},m.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},m.prototype.mulp=function(t,e,i){var r=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(r),s=this.stub(r),o=new Array(r),a=new Array(r),h=new Array(r),u=new Array(r),l=new Array(r),c=new Array(r),d=i.words;d.length=r,this.convert13b(t.words,t.length,o,r),this.convert13b(e.words,e.length,u,r),this.transform(o,s,a,h,r,n),this.transform(u,s,l,c,r,n);for(var f=0;f<r;f++){var m=a[f]*l[f]-h[f]*c[f];h[f]=a[f]*c[f]+h[f]*l[f],a[f]=m}return this.conjugate(a,h,r),this.transform(a,h,d,s,r,n),this.conjugate(d,s,r),this.normalize13b(d,r),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),f(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,r=0;r<this.length;r++){var n=(0|this.words[r])*t,s=(67108863&n)+(67108863&e);e>>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var r=i%26;e[i]=(t.words[i/26|0]&1<<r)>>>r}return e}(t);if(0===e.length)return new n(1);for(var i=this,r=0;r<e.length&&0===e[r];r++,i=i.sqr());if(++r<e.length)for(var s=i.sqr();r<e.length;r++,s=s.sqr())0!==e[r]&&(i=i.mul(s));return i},n.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s;this.words[e]=(0|this.words[e])-a<<r|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this.strip()},n.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},n.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},n.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return!(this.length<=r||!(this.words[r]&1<<e))},n.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r?this:(0!==e&&r++,this.length=Math.min(r,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},n.prototype.maskn=function(t){return this.clone().imaskn(t)},n.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},n.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},n.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},n.prototype.addn=function(t){return this.clone().iaddn(t)},n.prototype.subn=function(t){return this.clone().isubn(t)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(t,e,r){var n,s;this._expand(t.length+r);var o=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+o;var a=(0|t.words[n])*e;o=((s-=67108863&a)>>26)-(a/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)o=(s=(0|this.words[n+r])+o)>>26,this.words[n+r]=67108863&s;if(0===o)return this.strip();for(i(-1===o),o=0,n=0;n<this.length;n++)o=(s=-(0|this.words[n])+o)>>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},n.prototype._wordDiv=function(t,e){var i,r=this.clone(),s=t,o=0|s.words[s.length-1];0!=(i=26-this._countBits(o))&&(s=s.ushln(i),r.iushln(i),o=0|s.words[s.length-1]);var a,h=r.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=r.clone()._ishlnsubmul(s,1,h);0===l.negative&&(r=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var d=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]);for(d=Math.min(d/o|0,67108863),r._ishlnsubmul(s,d,c);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);a&&(a.words[c]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==i&&r.iushrn(i),{div:a||null,mod:r}},n.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),n=t.andln(1),s=i.cmp(r);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},n.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(l),o.isub(c)),s.iushrn(1),o.iushrn(1);for(var m=0,g=1;0==(r.words[0]&g)&&m<26;++m,g<<=1);if(m>0)for(r.iushrn(m);m-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a),o.isub(h)):(r.isub(e),a.isub(s),h.isub(o))}return{a:a,b:h,gcd:r.iushln(u)}},n.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,o=new n(1),a=new n(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,d=1;0==(r.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(s=0===e.cmpn(1)?o:a).cmpn(0)<0&&s.iadd(t),s},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var r=0;e.isEven()&&i.isEven();r++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var n=e.cmp(i);if(n<0){var s=e;e=i,i=s}else if(0===n||0===i.cmpn(1))break;e.isub(i)}return i.iushln(r)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,this.words[o]=a&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},n.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},n.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var r=0|this.words[i],n=0|t.words[i];if(r!==n){r<n?e=-1:r>n&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new b(t)},n.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var g={k256:null,p224:null,p192:null,p25519:null};function p(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}p.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:i.ucmp(this.p);return 0===r?(i.words[0]=0,i.length=1):r>0?i.isub(this.p):i.strip(),i},p.prototype.split=function(t,e){t.iushrn(this.n,0,e)},p.prototype.imulK=function(t){return t.imul(this.k)},r(w,p),w.prototype.split=function(t,e){for(var i=4194303,r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&i,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&i)<<4|s>>>22,s=o}t.words[n-10]=s>>>=22,t.length-=0===s&&t.length>10?10:9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var r=0|t.words[i];t.words[i]=67108863&(e+=977*r),e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,p),r(y,p),r(M,p),M.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var r=19*(0|t.words[i])+e,n=67108863&r;r>>>=26,t.words[i]=n,e=r}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new v;else if("p192"===t)e=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return g[t]=e,e},b.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},b.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},b.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},b.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},b.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},b.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},b.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},b.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},b.prototype.isqr=function(t){return this.imul(t,t.clone())},b.prototype.sqr=function(t){return this.mul(t,t)},b.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new n(1)).iushrn(2);return this.pow(t,r)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);i(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),m=o;0!==f.cmp(a);){for(var g=f,p=0;0!==g.cmp(a);p++)g=g.redSqr();i(p<m);var w=this.pow(c,new n(1).iushln(m-p-1));d=d.redMul(w),c=w.redSqr(),f=f.redMul(c),m=p}return d},b.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},b.prototype.pow=function(t,e){if(e.isZero())return new n(1);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new n(1).toRed(this),i[1]=t;for(var r=2;r<i.length;r++)i[r]=this.mul(i[r-1],t);var s=i[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),r=e.length-1;r>=0;r--){for(var u=e.words[r],l=h-1;l>=0;l--){var c=u>>l&1;s!==i[0]&&(s=this.sqr(s)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===r&&0===l)&&(s=this.mul(s,i[o]),a=0,o=0)):a=0}h=26}return s},b.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},b.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new A(t)},r(A,b),A.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},A.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},A.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=i.isub(r).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},A.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var i=t.mul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=i.isub(r).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},A.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,Ot)}),Dt=function(t){return"string"!=typeof t?t:function(t){if("string"!=typeof t)throw new Error("[is-hex-prefixed] value must be type 'string', is currently type "+typeof t+", while checking isHexPrefixed.");return"0x"===t.slice(0,2)}(t)?t.slice(2):t},Lt=function(t){if("string"==typeof t||"number"==typeof t){var e=new Pt(1),i=String(t).toLowerCase().trim(),r="0x"===i.substr(0,2)||"-0x"===i.substr(0,3),n=Dt(i);if("-"===n.substr(0,1)&&(n=Dt(n.slice(1)),e=new Pt(-1,10)),!(n=""===n?"0":n).match(/^-?[0-9]+$/)&&n.match(/^[0-9A-Fa-f]+$/)||n.match(/^[a-fA-F]+$/)||!0===r&&n.match(/^[0-9A-Fa-f]+$/))return new Pt(n,16).mul(e);if((n.match(/^-?[0-9]+$/)||""===n)&&!1===r)return new Pt(n,10).mul(e)}else if("object"==typeof t&&t.toString&&!t.pop&&!t.push&&t.toString(10).match(/^-?[0-9]+$/)&&(t.mul||t.dividedToIntegerBy))return new Pt(t.toString(10),10);throw new Error("[number-to-bn] while converting number "+JSON.stringify(t)+" to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.")},Nt=new _t(0),Wt=new _t(-1),Ft={noether:"0",wei:"1",kwei:"1000",Kwei:"1000",babbage:"1000",femtoether:"1000",mwei:"1000000",Mwei:"1000000",lovelace:"1000000",picoether:"1000000",gwei:"1000000000",Gwei:"1000000000",shannon:"1000000000",nanoether:"1000000000",nano:"1000000000",szabo:"1000000000000",microether:"1000000000000",micro:"1000000000000",finney:"1000000000000000",milliether:"1000000000000000",milli:"1000000000000000",ether:"1000000000000000000",kether:"1000000000000000000000",grand:"1000000000000000000000",mether:"1000000000000000000000000",gether:"1000000000000000000000000000",tether:"1000000000000000000000000000000"};function Ut(t){var e=t?t.toLowerCase():"ether",i=Ft[e];if("string"!=typeof i)throw new Error("[ethjs-unit] the unit provided "+t+" doesn't exists, please use the one of the following units "+JSON.stringify(Ft,null,2));return new _t(i,10)}function qt(t){if("string"==typeof t){if(!t.match(/^-?[0-9.]+$/))throw new Error("while converting number to string, invalid number value '"+t+"', should be a number matching (^-?[0-9.]+).");return t}if("number"==typeof t)return String(t);if("object"==typeof t&&t.toString&&(t.toTwos||t.dividedToIntegerBy))return t.toPrecision?String(t.toPrecision()):t.toString(10);throw new Error("while converting number to string, invalid number value '"+t+"' type "+typeof t+".")}var $t={unitMap:Ft,numberToString:qt,getValueOfUnit:Ut,fromWei:function(t,e,i){var r=Lt(t),n=r.lt(Nt),s=Ut(e),o=Ft[e].length-1||1,a=i||{};n&&(r=r.mul(Wt));for(var h=r.mod(s).toString(10);h.length<o;)h="0"+h;a.pad||(h=h.match(/^([0-9]*[1-9]|0)(0*)/)[1]);var u=r.div(s).toString(10);a.commify&&(u=u.replace(/\B(?=(\d{3})+(?!\d))/g,","));var l=u+("0"==h?"":"."+h);return n&&(l="-"+l),l},toWei:function(t,e){var i=qt(t),r=Ut(e),n=Ft[e].length-1||1,s="-"===i.substring(0,1);if(s&&(i=i.substring(1)),"."===i)throw new Error("[ethjs-unit] while converting number "+t+" to wei, invalid value");var o=i.split(".");if(o.length>2)throw new Error("[ethjs-unit] while converting number "+t+" to wei, too many decimal points");var a=o[0],h=o[1];if(a||(a="0"),h||(h="0"),h.length>n)throw new Error("[ethjs-unit] while converting number "+t+" to wei, too many decimal places");for(;h.length<n;)h+="0";a=new _t(a),h=new _t(h);var u=a.mul(r).add(h);return s&&(u=u.mul(Wt)),new _t(u.toString(10),10)}},jt=Bt(function(t){!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function n(t,e,i){if(n.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var s;"object"==typeof t?t.exports=n:e.BN=n,n.BN=n,n.wordSize=26;try{s=I.default.Buffer}catch(t){}function o(t,e,i){for(var r=0,n=Math.min(t.length,i),s=e;s<n;s++){var o=t.charCodeAt(s)-48;r<<=4,r|=o>=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o}return r}function a(t,e,i,r){for(var n=0,s=Math.min(t.length,i),o=e;o<s;o++){var a=t.charCodeAt(o)-48;n*=r,n+=a>=49?a-49+10:a>=17?a-17+10:a}return n}n.isBN=function(t){return t instanceof n||null!==t&&"object"==typeof t&&t.constructor.wordSize===n.wordSize&&Array.isArray(t.words)},n.max=function(t,e){return t.cmp(e)>0?t:e},n.min=function(t,e){return t.cmp(e)<0?t:e},n.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},n.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)this.words[s]|=(o=t[n]|t[n-1]<<8|t[n-2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)this.words[s]|=(o=t[n]|t[n+1]<<8|t[n+2]<<16)<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this.strip()},n.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var r,n,s=0;for(i=t.length-6,r=0;i>=e;i-=6)n=o(t,i,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,r++);i+6!==e&&(n=o(t,e,i+6),this.words[r]|=n<<s&67108863,this.words[r+1]|=n>>>26-s&4194303),this.strip()},n.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var r=0,n=1;n<=67108863;n*=e)r++;r--,n=n/e|0;for(var s=t.length-i,o=s%r,h=Math.min(s,s-o)+i,u=0,l=i;l<h;l+=r)u=a(t,l,l+r,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=a(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},n.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},n.prototype.clone=function(){var t=new n(null);return this.copy(t),t},n.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},n.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},n.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var h=["","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"],u=[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],l=[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 c(t,e,i){i.negative=e.negative^t.negative;var r=t.length+e.length|0;i.length=r,r=r-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=o/67108864|0;i.words[0]=67108863&o;for(var h=1;h<r;h++){for(var u=a>>>26,l=67108863&a,c=Math.min(h,e.length-1),d=Math.max(0,h-t.length+1);d<=c;d++)u+=(o=(n=0|t.words[h-d|0])*(s=0|e.words[d])+l)/67108864|0,l=67108863&o;i.words[h]=0|l,a=0|u}return 0!==a?i.words[h]=0|a:i.length--,i.strip()}n.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],c=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?h[6-c.length]+c+r:c+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var d=u[t],f=l[t];r="";var m=this.clone();for(m.negative=0;!m.isZero();){var g=m.modn(f).toString(t);r=(m=m.idivn(f)).isZero()?g+r:h[d-g.length]+g+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},n.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&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},n.prototype.toJSON=function(){return this.toString(16)},n.prototype.toBuffer=function(t,e){return i(void 0!==s),this.toArrayLike(s,t,e)},n.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},n.prototype.toArrayLike=function(t,e,r){var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0"),this.strip();var o,a,h="le"===e,u=new t(s),l=this.clone();if(h){for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[a]=o;for(;a<s;a++)u[a]=0}else{for(a=0;a<s-n;a++)u[a]=0;for(a=0;!l.isZero();a++)o=l.andln(255),l.iushrn(8),u[s-a-1]=o}return u},n.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},n.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},n.prototype.bitLength=function(){var t=this._countBits(this.words[this.length-1]);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},n.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.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()},n.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},n.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},n.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},n.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this.strip()},n.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},n.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},n.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},n.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var r=0;r<i.length;r++)this.words[r]=e.words[r]^i.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this.strip()},n.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},n.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},n.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},n.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this.strip()},n.prototype.notn=function(t){return this.clone().inotn(t)},n.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this.strip()},n.prototype.iadd=function(t){var e,i,r;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?(i=this,r=t):(i=t,r=this);for(var n=0,s=0;s<r.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+(0|r.words[s])+n),n=e>>>26;for(;0!==n&&s<i.length;s++)this.words[s]=67108863&(e=(0|i.words[s])+n),n=e>>>26;if(this.length=i.length,0!==n)this.words[this.length]=n,this.length++;else if(i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this},n.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)},n.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 i,r,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(i=this,r=t):(i=t,r=this);for(var s=0,o=0;o<r.length;o++)s=(e=(0|i.words[o])-(0|r.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<i.length;o++)s=(e=(0|i.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<i.length&&i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this.length=Math.max(this.length,o),i!==this&&(this.negative=1),this.strip()},n.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,e,i){var r,n,s,o=t.words,a=e.words,h=i.words,u=0,l=0|o[0],c=8191&l,d=l>>>13,f=0|o[1],m=8191&f,g=f>>>13,p=0|o[2],w=8191&p,v=p>>>13,y=0|o[3],M=8191&y,b=y>>>13,A=0|o[4],x=8191&A,E=A>>>13,R=0|o[5],S=8191&R,k=R>>>13,I=0|o[6],T=8191&I,O=I>>>13,B=0|o[7],C=8191&B,_=B>>>13,P=0|o[8],D=8191&P,L=P>>>13,N=0|o[9],W=8191&N,F=N>>>13,U=0|a[0],q=8191&U,$=U>>>13,j=0|a[1],G=8191&j,z=j>>>13,H=0|a[2],Z=8191&H,V=H>>>13,J=0|a[3],K=8191&J,X=J>>>13,Q=0|a[4],Y=8191&Q,tt=Q>>>13,et=0|a[5],it=8191&et,rt=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,dt=lt>>>13,ft=0|a[9],mt=8191&ft,gt=ft>>>13;i.negative=t.negative^e.negative,i.length=19;var pt=(u+(r=Math.imul(c,q))|0)+((8191&(n=(n=Math.imul(c,$))+Math.imul(d,q)|0))<<13)|0;u=((s=Math.imul(d,$))+(n>>>13)|0)+(pt>>>26)|0,pt&=67108863,r=Math.imul(m,q),n=(n=Math.imul(m,$))+Math.imul(g,q)|0,s=Math.imul(g,$);var wt=(u+(r=r+Math.imul(c,G)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(d,G)|0))<<13)|0;u=((s=s+Math.imul(d,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(w,q),n=(n=Math.imul(w,$))+Math.imul(v,q)|0,s=Math.imul(v,$),r=r+Math.imul(m,G)|0,n=(n=n+Math.imul(m,z)|0)+Math.imul(g,G)|0,s=s+Math.imul(g,z)|0;var vt=(u+(r=r+Math.imul(c,Z)|0)|0)+((8191&(n=(n=n+Math.imul(c,V)|0)+Math.imul(d,Z)|0))<<13)|0;u=((s=s+Math.imul(d,V)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(M,q),n=(n=Math.imul(M,$))+Math.imul(b,q)|0,s=Math.imul(b,$),r=r+Math.imul(w,G)|0,n=(n=n+Math.imul(w,z)|0)+Math.imul(v,G)|0,s=s+Math.imul(v,z)|0,r=r+Math.imul(m,Z)|0,n=(n=n+Math.imul(m,V)|0)+Math.imul(g,Z)|0,s=s+Math.imul(g,V)|0;var yt=(u+(r=r+Math.imul(c,K)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(d,K)|0))<<13)|0;u=((s=s+Math.imul(d,X)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(x,q),n=(n=Math.imul(x,$))+Math.imul(E,q)|0,s=Math.imul(E,$),r=r+Math.imul(M,G)|0,n=(n=n+Math.imul(M,z)|0)+Math.imul(b,G)|0,s=s+Math.imul(b,z)|0,r=r+Math.imul(w,Z)|0,n=(n=n+Math.imul(w,V)|0)+Math.imul(v,Z)|0,s=s+Math.imul(v,V)|0,r=r+Math.imul(m,K)|0,n=(n=n+Math.imul(m,X)|0)+Math.imul(g,K)|0,s=s+Math.imul(g,X)|0;var Mt=(u+(r=r+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(d,Y)|0))<<13)|0;u=((s=s+Math.imul(d,tt)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(S,q),n=(n=Math.imul(S,$))+Math.imul(k,q)|0,s=Math.imul(k,$),r=r+Math.imul(x,G)|0,n=(n=n+Math.imul(x,z)|0)+Math.imul(E,G)|0,s=s+Math.imul(E,z)|0,r=r+Math.imul(M,Z)|0,n=(n=n+Math.imul(M,V)|0)+Math.imul(b,Z)|0,s=s+Math.imul(b,V)|0,r=r+Math.imul(w,K)|0,n=(n=n+Math.imul(w,X)|0)+Math.imul(v,K)|0,s=s+Math.imul(v,X)|0,r=r+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,tt)|0)+Math.imul(g,Y)|0,s=s+Math.imul(g,tt)|0;var bt=(u+(r=r+Math.imul(c,it)|0)|0)+((8191&(n=(n=n+Math.imul(c,rt)|0)+Math.imul(d,it)|0))<<13)|0;u=((s=s+Math.imul(d,rt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(T,q),n=(n=Math.imul(T,$))+Math.imul(O,q)|0,s=Math.imul(O,$),r=r+Math.imul(S,G)|0,n=(n=n+Math.imul(S,z)|0)+Math.imul(k,G)|0,s=s+Math.imul(k,z)|0,r=r+Math.imul(x,Z)|0,n=(n=n+Math.imul(x,V)|0)+Math.imul(E,Z)|0,s=s+Math.imul(E,V)|0,r=r+Math.imul(M,K)|0,n=(n=n+Math.imul(M,X)|0)+Math.imul(b,K)|0,s=s+Math.imul(b,X)|0,r=r+Math.imul(w,Y)|0,n=(n=n+Math.imul(w,tt)|0)+Math.imul(v,Y)|0,s=s+Math.imul(v,tt)|0,r=r+Math.imul(m,it)|0,n=(n=n+Math.imul(m,rt)|0)+Math.imul(g,it)|0,s=s+Math.imul(g,rt)|0;var At=(u+(r=r+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(d,st)|0))<<13)|0;u=((s=s+Math.imul(d,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,q),n=(n=Math.imul(C,$))+Math.imul(_,q)|0,s=Math.imul(_,$),r=r+Math.imul(T,G)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(O,G)|0,s=s+Math.imul(O,z)|0,r=r+Math.imul(S,Z)|0,n=(n=n+Math.imul(S,V)|0)+Math.imul(k,Z)|0,s=s+Math.imul(k,V)|0,r=r+Math.imul(x,K)|0,n=(n=n+Math.imul(x,X)|0)+Math.imul(E,K)|0,s=s+Math.imul(E,X)|0,r=r+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,tt)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,tt)|0,r=r+Math.imul(w,it)|0,n=(n=n+Math.imul(w,rt)|0)+Math.imul(v,it)|0,s=s+Math.imul(v,rt)|0,r=r+Math.imul(m,st)|0,n=(n=n+Math.imul(m,ot)|0)+Math.imul(g,st)|0,s=s+Math.imul(g,ot)|0;var xt=(u+(r=r+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(d,ht)|0))<<13)|0;u=((s=s+Math.imul(d,ut)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(D,q),n=(n=Math.imul(D,$))+Math.imul(L,q)|0,s=Math.imul(L,$),r=r+Math.imul(C,G)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(_,G)|0,s=s+Math.imul(_,z)|0,r=r+Math.imul(T,Z)|0,n=(n=n+Math.imul(T,V)|0)+Math.imul(O,Z)|0,s=s+Math.imul(O,V)|0,r=r+Math.imul(S,K)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(k,K)|0,s=s+Math.imul(k,X)|0,r=r+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,tt)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,tt)|0,r=r+Math.imul(M,it)|0,n=(n=n+Math.imul(M,rt)|0)+Math.imul(b,it)|0,s=s+Math.imul(b,rt)|0,r=r+Math.imul(w,st)|0,n=(n=n+Math.imul(w,ot)|0)+Math.imul(v,st)|0,s=s+Math.imul(v,ot)|0,r=r+Math.imul(m,ht)|0,n=(n=n+Math.imul(m,ut)|0)+Math.imul(g,ht)|0,s=s+Math.imul(g,ut)|0;var Et=(u+(r=r+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,dt)|0)+Math.imul(d,ct)|0))<<13)|0;u=((s=s+Math.imul(d,dt)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(W,q),n=(n=Math.imul(W,$))+Math.imul(F,q)|0,s=Math.imul(F,$),r=r+Math.imul(D,G)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(L,G)|0,s=s+Math.imul(L,z)|0,r=r+Math.imul(C,Z)|0,n=(n=n+Math.imul(C,V)|0)+Math.imul(_,Z)|0,s=s+Math.imul(_,V)|0,r=r+Math.imul(T,K)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(O,K)|0,s=s+Math.imul(O,X)|0,r=r+Math.imul(S,Y)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(k,Y)|0,s=s+Math.imul(k,tt)|0,r=r+Math.imul(x,it)|0,n=(n=n+Math.imul(x,rt)|0)+Math.imul(E,it)|0,s=s+Math.imul(E,rt)|0,r=r+Math.imul(M,st)|0,n=(n=n+Math.imul(M,ot)|0)+Math.imul(b,st)|0,s=s+Math.imul(b,ot)|0,r=r+Math.imul(w,ht)|0,n=(n=n+Math.imul(w,ut)|0)+Math.imul(v,ht)|0,s=s+Math.imul(v,ut)|0,r=r+Math.imul(m,ct)|0,n=(n=n+Math.imul(m,dt)|0)+Math.imul(g,ct)|0,s=s+Math.imul(g,dt)|0;var Rt=(u+(r=r+Math.imul(c,mt)|0)|0)+((8191&(n=(n=n+Math.imul(c,gt)|0)+Math.imul(d,mt)|0))<<13)|0;u=((s=s+Math.imul(d,gt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,r=Math.imul(W,G),n=(n=Math.imul(W,z))+Math.imul(F,G)|0,s=Math.imul(F,z),r=r+Math.imul(D,Z)|0,n=(n=n+Math.imul(D,V)|0)+Math.imul(L,Z)|0,s=s+Math.imul(L,V)|0,r=r+Math.imul(C,K)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(_,K)|0,s=s+Math.imul(_,X)|0,r=r+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,tt)|0,r=r+Math.imul(S,it)|0,n=(n=n+Math.imul(S,rt)|0)+Math.imul(k,it)|0,s=s+Math.imul(k,rt)|0,r=r+Math.imul(x,st)|0,n=(n=n+Math.imul(x,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,r=r+Math.imul(M,ht)|0,n=(n=n+Math.imul(M,ut)|0)+Math.imul(b,ht)|0,s=s+Math.imul(b,ut)|0,r=r+Math.imul(w,ct)|0,n=(n=n+Math.imul(w,dt)|0)+Math.imul(v,ct)|0,s=s+Math.imul(v,dt)|0;var St=(u+(r=r+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,gt)|0)+Math.imul(g,mt)|0))<<13)|0;u=((s=s+Math.imul(g,gt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(W,Z),n=(n=Math.imul(W,V))+Math.imul(F,Z)|0,s=Math.imul(F,V),r=r+Math.imul(D,K)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(L,K)|0,s=s+Math.imul(L,X)|0,r=r+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,tt)|0,r=r+Math.imul(T,it)|0,n=(n=n+Math.imul(T,rt)|0)+Math.imul(O,it)|0,s=s+Math.imul(O,rt)|0,r=r+Math.imul(S,st)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(k,st)|0,s=s+Math.imul(k,ot)|0,r=r+Math.imul(x,ht)|0,n=(n=n+Math.imul(x,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,r=r+Math.imul(M,ct)|0,n=(n=n+Math.imul(M,dt)|0)+Math.imul(b,ct)|0,s=s+Math.imul(b,dt)|0;var kt=(u+(r=r+Math.imul(w,mt)|0)|0)+((8191&(n=(n=n+Math.imul(w,gt)|0)+Math.imul(v,mt)|0))<<13)|0;u=((s=s+Math.imul(v,gt)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(W,K),n=(n=Math.imul(W,X))+Math.imul(F,K)|0,s=Math.imul(F,X),r=r+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,tt)|0,r=r+Math.imul(C,it)|0,n=(n=n+Math.imul(C,rt)|0)+Math.imul(_,it)|0,s=s+Math.imul(_,rt)|0,r=r+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,r=r+Math.imul(S,ht)|0,n=(n=n+Math.imul(S,ut)|0)+Math.imul(k,ht)|0,s=s+Math.imul(k,ut)|0,r=r+Math.imul(x,ct)|0,n=(n=n+Math.imul(x,dt)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,dt)|0;var It=(u+(r=r+Math.imul(M,mt)|0)|0)+((8191&(n=(n=n+Math.imul(M,gt)|0)+Math.imul(b,mt)|0))<<13)|0;u=((s=s+Math.imul(b,gt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(W,Y),n=(n=Math.imul(W,tt))+Math.imul(F,Y)|0,s=Math.imul(F,tt),r=r+Math.imul(D,it)|0,n=(n=n+Math.imul(D,rt)|0)+Math.imul(L,it)|0,s=s+Math.imul(L,rt)|0,r=r+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(_,st)|0,s=s+Math.imul(_,ot)|0,r=r+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,r=r+Math.imul(S,ct)|0,n=(n=n+Math.imul(S,dt)|0)+Math.imul(k,ct)|0,s=s+Math.imul(k,dt)|0;var Tt=(u+(r=r+Math.imul(x,mt)|0)|0)+((8191&(n=(n=n+Math.imul(x,gt)|0)+Math.imul(E,mt)|0))<<13)|0;u=((s=s+Math.imul(E,gt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(W,it),n=(n=Math.imul(W,rt))+Math.imul(F,it)|0,s=Math.imul(F,rt),r=r+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(L,st)|0,s=s+Math.imul(L,ot)|0,r=r+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(_,ht)|0,s=s+Math.imul(_,ut)|0,r=r+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,dt)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,dt)|0;var Ot=(u+(r=r+Math.imul(S,mt)|0)|0)+((8191&(n=(n=n+Math.imul(S,gt)|0)+Math.imul(k,mt)|0))<<13)|0;u=((s=s+Math.imul(k,gt)|0)+(n>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(W,st),n=(n=Math.imul(W,ot))+Math.imul(F,st)|0,s=Math.imul(F,ot),r=r+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(L,ht)|0,s=s+Math.imul(L,ut)|0,r=r+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,dt)|0)+Math.imul(_,ct)|0,s=s+Math.imul(_,dt)|0;var Bt=(u+(r=r+Math.imul(T,mt)|0)|0)+((8191&(n=(n=n+Math.imul(T,gt)|0)+Math.imul(O,mt)|0))<<13)|0;u=((s=s+Math.imul(O,gt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,r=Math.imul(W,ht),n=(n=Math.imul(W,ut))+Math.imul(F,ht)|0,s=Math.imul(F,ut),r=r+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,dt)|0)+Math.imul(L,ct)|0,s=s+Math.imul(L,dt)|0;var Ct=(u+(r=r+Math.imul(C,mt)|0)|0)+((8191&(n=(n=n+Math.imul(C,gt)|0)+Math.imul(_,mt)|0))<<13)|0;u=((s=s+Math.imul(_,gt)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(W,ct),n=(n=Math.imul(W,dt))+Math.imul(F,ct)|0,s=Math.imul(F,dt);var _t=(u+(r=r+Math.imul(D,mt)|0)|0)+((8191&(n=(n=n+Math.imul(D,gt)|0)+Math.imul(L,mt)|0))<<13)|0;u=((s=s+Math.imul(L,gt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863;var Pt=(u+(r=Math.imul(W,mt))|0)+((8191&(n=(n=Math.imul(W,gt))+Math.imul(F,mt)|0))<<13)|0;return u=((s=Math.imul(F,gt))+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,h[0]=pt,h[1]=wt,h[2]=vt,h[3]=yt,h[4]=Mt,h[5]=bt,h[6]=At,h[7]=xt,h[8]=Et,h[9]=Rt,h[10]=St,h[11]=kt,h[12]=It,h[13]=Tt,h[14]=Ot,h[15]=Bt,h[16]=Ct,h[17]=_t,h[18]=Pt,0!==u&&(h[19]=u,i.length++),i};function f(t,e,i){return(new m).mulp(t,e,i)}function m(t,e){this.x=t,this.y=e}Math.imul||(d=c),n.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,e):i<63?c(this,t,e):i<1024?function(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var r=0,n=0,s=0;s<i.length-1;s++){var o=n;n=0;for(var a=67108863&r,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=(0|t.words[s-u])*(0|e.words[u]),c=67108863&l;a=67108863&(c=c+a|0),n+=(o=(o=o+(l/67108864|0)|0)+(c>>>26)|0)>>>26,o&=67108863}i.words[s]=a,r=o,o=n}return 0!==r?i.words[s]=r:i.length--,i.strip()}(this,t,e):f(this,t,e)},m.prototype.makeRBT=function(t){for(var e=new Array(t),i=n.prototype._countBits(t)-1,r=0;r<t;r++)e[r]=this.revBin(r,i,t);return e},m.prototype.revBin=function(t,e,i){if(0===t||t===i-1)return t;for(var r=0,n=0;n<e;n++)r|=(1&t)<<e-n-1,t>>=1;return r},m.prototype.permute=function(t,e,i,r,n,s){for(var o=0;o<s;o++)r[o]=e[t[o]],n[o]=i[t[o]]},m.prototype.transform=function(t,e,i,r,n,s){this.permute(s,t,e,i,r,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,d=u,f=0;f<o;f++){var m=i[l+f],g=r[l+f],p=i[l+f+o],w=r[l+f+o],v=c*p-d*w;w=c*w+d*p,i[l+f]=m+(p=v),r[l+f]=g+w,i[l+f+o]=m-p,r[l+f+o]=g-w,f!==a&&(v=h*c-u*d,d=h*d+u*c,c=v)}},m.prototype.guessLen13b=function(t,e){var i=1|Math.max(e,t),r=1&i,n=0;for(i=i/2|0;i;i>>>=1)n++;return 1<<n+1+r},m.prototype.conjugate=function(t,e,i){if(!(i<=1))for(var r=0;r<i/2;r++){var n=t[r];t[r]=t[i-r-1],t[i-r-1]=n,n=e[r],e[r]=-e[i-r-1],e[i-r-1]=-n}},m.prototype.normalize13b=function(t,e){for(var i=0,r=0;r<e/2;r++){var n=8192*Math.round(t[2*r+1]/e)+Math.round(t[2*r]/e)+i;t[r]=67108863&n,i=n<67108864?0:n/67108864|0}return t},m.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)r[2*o]=8191&(s+=0|t[o]),r[2*o+1]=8191&(s>>>=13),s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},m.prototype.stub=function(t){for(var e=new Array(t),i=0;i<t;i++)e[i]=0;return e},m.prototype.mulp=function(t,e,i){var r=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(r),s=this.stub(r),o=new Array(r),a=new Array(r),h=new Array(r),u=new Array(r),l=new Array(r),c=new Array(r),d=i.words;d.length=r,this.convert13b(t.words,t.length,o,r),this.convert13b(e.words,e.length,u,r),this.transform(o,s,a,h,r,n),this.transform(u,s,l,c,r,n);for(var f=0;f<r;f++){var m=a[f]*l[f]-h[f]*c[f];h[f]=a[f]*c[f]+h[f]*l[f],a[f]=m}return this.conjugate(a,h,r),this.transform(a,h,d,s,r,n),this.conjugate(d,s,r),this.normalize13b(d,r),i.negative=t.negative^e.negative,i.length=t.length+e.length,i.strip()},n.prototype.mul=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},n.prototype.mulf=function(t){var e=new n(null);return e.words=new Array(this.length+t.length),f(this,t,e)},n.prototype.imul=function(t){return this.clone().mulTo(t,this)},n.prototype.imuln=function(t){i("number"==typeof t),i(t<67108864);for(var e=0,r=0;r<this.length;r++){var n=(0|this.words[r])*t,s=(67108863&n)+(67108863&e);e>>=26,e+=n/67108864|0,e+=s>>>26,this.words[r]=67108863&s}return 0!==e&&(this.words[r]=e,this.length++),this},n.prototype.muln=function(t){return this.clone().imuln(t)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var r=i%26;e[i]=(t.words[i/26|0]&1<<r)>>>r}return e}(t);if(0===e.length)return new n(1);for(var i=this,r=0;r<e.length&&0===e[r];r++,i=i.sqr());if(++r<e.length)for(var s=i.sqr();r<e.length;r++,s=s.sqr())0!==e[r]&&(i=i.mul(s));return i},n.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s;this.words[e]=(0|this.words[e])-a<<r|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this.strip()},n.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},n.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},n.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},n.prototype.shln=function(t){return this.clone().ishln(t)},n.prototype.ushln=function(t){return this.clone().iushln(t)},n.prototype.shrn=function(t){return this.clone().ishrn(t)},n.prototype.ushrn=function(t){return this.clone().iushrn(t)},n.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return!(this.length<=r||!(this.words[r]&1<<e))},n.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;return i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r?this:(0!==e&&r++,this.length=Math.min(r,this.length),0!==e&&(this.words[this.length-1]&=67108863^67108863>>>e<<e),this.strip())},n.prototype.maskn=function(t){return this.clone().imaskn(t)},n.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},n.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},n.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},n.prototype.addn=function(t){return this.clone().iaddn(t)},n.prototype.subn=function(t){return this.clone().isubn(t)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(t,e,r){var n,s;this._expand(t.length+r);var o=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+o;var a=(0|t.words[n])*e;o=((s-=67108863&a)>>26)-(a/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)o=(s=(0|this.words[n+r])+o)>>26,this.words[n+r]=67108863&s;if(0===o)return this.strip();for(i(-1===o),o=0,n=0;n<this.length;n++)o=(s=-(0|this.words[n])+o)>>26,this.words[n]=67108863&s;return this.negative=1,this.strip()},n.prototype._wordDiv=function(t,e){var i,r=this.clone(),s=t,o=0|s.words[s.length-1];0!=(i=26-this._countBits(o))&&(s=s.ushln(i),r.iushln(i),o=0|s.words[s.length-1]);var a,h=r.length-s.length;if("mod"!==e){(a=new n(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=r.clone()._ishlnsubmul(s,1,h);0===l.negative&&(r=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var d=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]);for(d=Math.min(d/o|0,67108863),r._ishlnsubmul(s,d,c);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);a&&(a.words[c]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==i&&r.iushrn(i),{div:a||null,mod:r}},n.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(s=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:s,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new n(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new n(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new n(this.modn(t.words[0]))}:this._wordDiv(t,e);var s,o,a},n.prototype.div=function(t){return this.divmod(t,"div",!1).div},n.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},n.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},n.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),n=t.andln(1),s=i.cmp(r);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},n.prototype.modn=function(t){i(t<=67108863);for(var e=(1<<26)%t,r=0,n=this.length-1;n>=0;n--)r=(e*r+(0|this.words[n]))%t;return r},n.prototype.idivn=function(t){i(t<=67108863);for(var e=0,r=this.length-1;r>=0;r--){var n=(0|this.words[r])+67108864*e;this.words[r]=n/t|0,e=n%t}return this.strip()},n.prototype.divn=function(t){return this.clone().idivn(t)},n.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s=new n(1),o=new n(0),a=new n(0),h=new n(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var d=0,f=1;0==(e.words[0]&f)&&d<26;++d,f<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(s.isOdd()||o.isOdd())&&(s.iadd(l),o.isub(c)),s.iushrn(1),o.iushrn(1);for(var m=0,g=1;0==(r.words[0]&g)&&m<26;++m,g<<=1);if(m>0)for(r.iushrn(m);m-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a),o.isub(h)):(r.isub(e),a.isub(s),h.isub(o))}return{a:a,b:h,gcd:r.iushln(u)}},n.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var s,o=new n(1),a=new n(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,d=1;0==(r.words[0]&d)&&c<26;++c,d<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(s=0===e.cmpn(1)?o:a).cmpn(0)<0&&s.iadd(t),s},n.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var r=0;e.isEven()&&i.isEven();r++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var n=e.cmp(i);if(n<0){var s=e;e=i,i=s}else if(0===n||0===i.cmpn(1))break;e.isub(i)}return i.iushln(r)},n.prototype.invm=function(t){return this.egcd(t).a.umod(t)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(t){return this.words[0]&t},n.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,this.words[o]=a&=67108863}return 0!==s&&(this.words[o]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this.strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},n.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},n.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var r=0|this.words[i],n=0|t.words[i];if(r!==n){r<n?e=-1:r>n&&(e=1);break}}return e},n.prototype.gtn=function(t){return 1===this.cmpn(t)},n.prototype.gt=function(t){return 1===this.cmp(t)},n.prototype.gten=function(t){return this.cmpn(t)>=0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.ltn=function(t){return-1===this.cmpn(t)},n.prototype.lt=function(t){return-1===this.cmp(t)},n.prototype.lten=function(t){return this.cmpn(t)<=0},n.prototype.lte=function(t){return this.cmp(t)<=0},n.prototype.eqn=function(t){return 0===this.cmpn(t)},n.prototype.eq=function(t){return 0===this.cmp(t)},n.red=function(t){return new b(t)},n.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},n.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(t){return this.red=t,this},n.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},n.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},n.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},n.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},n.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},n.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},n.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},n.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},n.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var g={k256:null,p224:null,p192:null,p25519:null};function p(t,e){this.name=t,this.p=new n(e,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function w(){p.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){p.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function y(){p.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){p.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var e=n._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}p.prototype._tmp=function(){var t=new n(null);return t.words=new Array(Math.ceil(this.n/13)),t},p.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:i.ucmp(this.p);return 0===r?(i.words[0]=0,i.length=1):r>0?i.isub(this.p):void 0!==i.strip?i.strip():i._strip(),i},p.prototype.split=function(t,e){t.iushrn(this.n,0,e)},p.prototype.imulK=function(t){return t.imul(this.k)},r(w,p),w.prototype.split=function(t,e){for(var i=4194303,r=Math.min(t.length,9),n=0;n<r;n++)e.words[n]=t.words[n];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&i,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&i)<<4|s>>>22,s=o}t.words[n-10]=s>>>=22,t.length-=0===s&&t.length>10?10:9},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var r=0|t.words[i];t.words[i]=67108863&(e+=977*r),e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,p),r(y,p),r(M,p),M.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var r=19*(0|t.words[i])+e,n=67108863&r;r>>>=26,t.words[i]=n,e=r}return 0!==e&&(t.words[t.length++]=e),t},n._prime=function(t){if(g[t])return g[t];var e;if("k256"===t)e=new w;else if("p224"===t)e=new v;else if("p192"===t)e=new y;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return g[t]=e,e},b.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},b.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},b.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},b.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},b.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},b.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},b.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},b.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},b.prototype.isqr=function(t){return this.imul(t,t.clone())},b.prototype.sqr=function(t){return this.mul(t,t)},b.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new n(1)).iushrn(2);return this.pow(t,r)}for(var s=this.m.subn(1),o=0;!s.isZero()&&0===s.andln(1);)o++,s.iushrn(1);i(!s.isZero());var a=new n(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,s),d=this.pow(t,s.addn(1).iushrn(1)),f=this.pow(t,s),m=o;0!==f.cmp(a);){for(var g=f,p=0;0!==g.cmp(a);p++)g=g.redSqr();i(p<m);var w=this.pow(c,new n(1).iushln(m-p-1));d=d.redMul(w),c=w.redSqr(),f=f.redMul(c),m=p}return d},b.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},b.prototype.pow=function(t,e){if(e.isZero())return new n(1).toRed(this);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new n(1).toRed(this),i[1]=t;for(var r=2;r<i.length;r++)i[r]=this.mul(i[r-1],t);var s=i[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),r=e.length-1;r>=0;r--){for(var u=e.words[r],l=h-1;l>=0;l--){var c=u>>l&1;s!==i[0]&&(s=this.sqr(s)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===r&&0===l)&&(s=this.mul(s,i[o]),a=0,o=0)):a=0}h=26}return s},b.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},b.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},n.mont=function(t){return new A(t)},r(A,b),A.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},A.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},A.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=i.isub(r).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},A.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new n(0)._forceRed(this);var i=t.mul(e),r=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=i.isub(r).iushrn(this.shift),o=s;return s.cmp(this.m)>=0?o=s.isub(this.m):s.cmpn(0)<0&&(o=s.iadd(this.m)),o._forceRed(this)},A.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(t,Ot)}),Gt=Bt(function(t,e){!function(t){var e,i,r,n=String.fromCharCode;function s(t){for(var e,i,r=[],n=0,s=t.length;n<s;)(e=t.charCodeAt(n++))>=55296&&e<=56319&&n<s?56320==(64512&(i=t.charCodeAt(n++)))?r.push(((1023&e)<<10)+(1023&i)+65536):(r.push(e),n--):r.push(e);return r}function o(t){if(t>=55296&&t<=57343)throw Error("Lone surrogate U+"+t.toString(16).toUpperCase()+" is not a scalar value")}function a(t,e){return n(t>>e&63|128)}function h(t){if(0==(4294967168&t))return n(t);var e="";return 0==(4294965248&t)?e=n(t>>6&31|192):0==(4294901760&t)?(o(t),e=n(t>>12&15|224),e+=a(t,6)):0==(4292870144&t)&&(e=n(t>>18&7|240),e+=a(t,12),e+=a(t,6)),e+n(63&t|128)}function u(){if(r>=i)throw Error("Invalid byte index");var t=255&e[r];if(r++,128==(192&t))return 63&t;throw Error("Invalid continuation byte")}function l(){var t,n;if(r>i)throw Error("Invalid byte index");if(r==i)return!1;if(t=255&e[r],r++,0==(128&t))return t;if(192==(224&t)){if((n=(31&t)<<6|u())>=128)return n;throw Error("Invalid continuation byte")}if(224==(240&t)){if((n=(15&t)<<12|u()<<6|u())>=2048)return o(n),n;throw Error("Invalid continuation byte")}if(240==(248&t)&&(n=(7&t)<<18|u()<<12|u()<<6|u())>=65536&&n<=1114111)return n;throw Error("Invalid UTF-8 detected")}t.version="3.0.0",t.encode=function(t){for(var e=s(t),i=e.length,r=-1,n="";++r<i;)n+=h(e[r]);return n},t.decode=function(t){e=s(t),i=e.length,r=0;for(var o,a=[];!1!==(o=l());)a.push(o);return function(t){for(var e,i=t.length,r=-1,s="";++r<i;)(e=t[r])>65535&&(s+=n((e-=65536)>>>10&1023|55296),e=56320|1023&e),s+=n(e);return s}(a)}}(e)});const zt="0123456789abcdef".split(""),Ht=[1,256,65536,16777216],Zt=[0,8,16,24],Vt=[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],Jt=t=>{var e,i,r,n,s,o,a,h,u,l,c,d,f,m,g,p,w,v,y,M,b,A,x,E,R,S,k,I,T,O,B,C,_,P,D,L,N,W,F,U,q,$,j,G,z,H,Z,V,J,K,X,Q,Y,tt,et,it,rt,nt,st,ot,at,ht,ut;for(r=0;r<48;r+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],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],i=(f=t[9]^t[19]^t[29]^t[39]^t[49])^((a=t[3]^t[13]^t[23]^t[33]^t[43])<<1|(o=t[2]^t[12]^t[22]^t[32]^t[42])>>>31),t[0]^=e=(d=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),t[1]^=i,t[10]^=e,t[11]^=i,t[20]^=e,t[21]^=i,t[30]^=e,t[31]^=i,t[40]^=e,t[41]^=i,i=s^(u<<1|h>>>31),t[2]^=e=n^(h<<1|u>>>31),t[3]^=i,t[12]^=e,t[13]^=i,t[22]^=e,t[23]^=i,t[32]^=e,t[33]^=i,t[42]^=e,t[43]^=i,i=a^(c<<1|l>>>31),t[4]^=e=o^(l<<1|c>>>31),t[5]^=i,t[14]^=e,t[15]^=i,t[24]^=e,t[25]^=i,t[34]^=e,t[35]^=i,t[44]^=e,t[45]^=i,i=u^(f<<1|d>>>31),t[6]^=e=h^(d<<1|f>>>31),t[7]^=i,t[16]^=e,t[17]^=i,t[26]^=e,t[27]^=i,t[36]^=e,t[37]^=i,t[46]^=e,t[47]^=i,i=c^(s<<1|n>>>31),t[8]^=e=l^(n<<1|s>>>31),t[9]^=i,t[18]^=e,t[19]^=i,t[28]^=e,t[29]^=i,t[38]^=e,t[39]^=i,t[48]^=e,t[49]^=i,g=t[1],H=t[11]<<4|t[10]>>>28,Z=t[10]<<4|t[11]>>>28,I=t[20]<<3|t[21]>>>29,T=t[21]<<3|t[20]>>>29,ot=t[31]<<9|t[30]>>>23,at=t[30]<<9|t[31]>>>23,$=t[40]<<18|t[41]>>>14,j=t[41]<<18|t[40]>>>14,P=t[2]<<1|t[3]>>>31,D=t[3]<<1|t[2]>>>31,w=t[12]<<12|t[13]>>>20,V=t[22]<<10|t[23]>>>22,J=t[23]<<10|t[22]>>>22,O=t[33]<<13|t[32]>>>19,B=t[32]<<13|t[33]>>>19,ht=t[42]<<2|t[43]>>>30,ut=t[43]<<2|t[42]>>>30,tt=t[5]<<30|t[4]>>>2,et=t[4]<<30|t[5]>>>2,L=t[14]<<6|t[15]>>>26,N=t[15]<<6|t[14]>>>26,y=t[24]<<11|t[25]>>>21,K=t[34]<<15|t[35]>>>17,X=t[35]<<15|t[34]>>>17,C=t[45]<<29|t[44]>>>3,_=t[44]<<29|t[45]>>>3,E=t[6]<<28|t[7]>>>4,R=t[7]<<28|t[6]>>>4,it=t[17]<<23|t[16]>>>9,rt=t[16]<<23|t[17]>>>9,W=t[26]<<25|t[27]>>>7,F=t[27]<<25|t[26]>>>7,M=t[36]<<21|t[37]>>>11,b=t[37]<<21|t[36]>>>11,Q=t[47]<<24|t[46]>>>8,Y=t[46]<<24|t[47]>>>8,G=t[8]<<27|t[9]>>>5,z=t[9]<<27|t[8]>>>5,S=t[18]<<20|t[19]>>>12,k=t[19]<<20|t[18]>>>12,nt=t[29]<<7|t[28]>>>25,st=t[28]<<7|t[29]>>>25,U=t[38]<<8|t[39]>>>24,q=t[39]<<8|t[38]>>>24,A=t[48]<<14|t[49]>>>18,x=t[49]<<14|t[48]>>>18,t[0]=(m=t[0])^~(p=t[13]<<12|t[12]>>>20)&(v=t[25]<<11|t[24]>>>21),t[1]=g^~w&y,t[10]=E^~S&I,t[11]=R^~k&T,t[20]=P^~L&W,t[21]=D^~N&F,t[30]=G^~H&V,t[31]=z^~Z&J,t[40]=tt^~it&nt,t[41]=et^~rt&st,t[2]=p^~v&M,t[3]=w^~y&b,t[12]=S^~I&O,t[13]=k^~T&B,t[22]=L^~W&U,t[23]=N^~F&q,t[32]=H^~V&K,t[33]=Z^~J&X,t[42]=it^~nt&ot,t[43]=rt^~st&at,t[4]=v^~M&A,t[5]=y^~b&x,t[14]=I^~O&C,t[15]=T^~B&_,t[24]=W^~U&$,t[25]=F^~q&j,t[34]=V^~K&Q,t[35]=J^~X&Y,t[44]=nt^~ot&ht,t[45]=st^~at&ut,t[6]=M^~A&m,t[7]=b^~x&g,t[16]=O^~C&E,t[17]=B^~_&R,t[26]=U^~$&P,t[27]=q^~j&D,t[36]=K^~Q&G,t[37]=X^~Y&z,t[46]=ot^~ht&tt,t[47]=at^~ut&et,t[8]=A^~m&p,t[9]=x^~g&w,t[18]=C^~E&S,t[19]=_^~R&k,t[28]=$^~P&L,t[29]=j^~D&N,t[38]=Q^~G&H,t[39]=Y^~z&Z,t[48]=ht^~tt&it,t[49]=ut^~et&rt,t[0]^=Vt[r],t[1]^=Vt[r+1]},Kt=t=>e=>{var i;if("0x"===e.slice(0,2)){i=[];for(var r=2,n=e.length;r<n;r+=2)i.push(parseInt(e.slice(r,r+2),16))}else i=e;return((t,e)=>{for(var i,r=e.length,n=t.blocks,s=t.blockCount<<2,o=t.blockCount,a=t.outputBlocks,h=t.s,u=0;u<r;){if(t.reset)for(t.reset=!1,n[0]=t.block,d=1;d<o+1;++d)n[d]=0;if("string"!=typeof e)for(d=t.start;u<r&&d<s;++u)n[d>>2]|=e[u]<<Zt[3&d++];else for(d=t.start;u<r&&d<s;++u)(i=e.charCodeAt(u))<128?n[d>>2]|=i<<Zt[3&d++]:i<2048?(n[d>>2]|=(192|i>>6)<<Zt[3&d++],n[d>>2]|=(128|63&i)<<Zt[3&d++]):i<55296||i>=57344?(n[d>>2]|=(224|i>>12)<<Zt[3&d++],n[d>>2]|=(128|i>>6&63)<<Zt[3&d++],n[d>>2]|=(128|63&i)<<Zt[3&d++]):(i=65536+((1023&i)<<10|1023&e.charCodeAt(++u)),n[d>>2]|=(240|i>>18)<<Zt[3&d++],n[d>>2]|=(128|i>>12&63)<<Zt[3&d++],n[d>>2]|=(128|i>>6&63)<<Zt[3&d++],n[d>>2]|=(128|63&i)<<Zt[3&d++]);if(t.lastByteIndex=d,d>=s){for(t.start=d-s,t.block=n[o],d=0;d<o;++d)h[d]^=n[d];Jt(h),t.reset=!0}else t.start=d}if(n[(d=t.lastByteIndex)>>2]|=Ht[3&d],t.lastByteIndex===s)for(n[0]=n[o],d=1;d<o+1;++d)n[d]=0;for(n[o-1]|=2147483648,d=0;d<o;++d)h[d]^=n[d];Jt(h);for(var l,c="",d=0,f=0;f<a;){for(d=0;d<o&&f<a;++d,++f)c+=zt[(l=h[d])>>4&15]+zt[15&l]+zt[l>>12&15]+zt[l>>8&15]+zt[l>>20&15]+zt[l>>16&15]+zt[l>>28&15]+zt[l>>24&15];f%o==0&&(Jt(h),d=0)}return"0x"+c})((t=>{return{blocks:[],reset:!0,block:0,start:0,blockCount:1600-(t<<1)>>5,outputBlocks:t>>5,s:(e=[0,0,0,0,0,0,0,0,0,0],[].concat(e,e,e,e,e))};var e})(t),i)};var Xt={keccak256:Kt(256),keccak512:Kt(512),keccak256s:Kt(256),keccak512s:Kt(512)},Qt=Bt(function(t){!function(){var e="input is invalid type",i="object"==typeof window,r=i?window:{};r.JS_SHA3_NO_WINDOW&&(i=!1);var n=!i&&"object"==typeof self;!r.JS_SHA3_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node?r=Ot:n&&(r=self);var s=!r.JS_SHA3_NO_COMMON_JS&&t.exports,o=!r.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,a="0123456789abcdef".split(""),h=[4,1024,262144,67108864],u=[0,8,16,24],l=[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],c=[224,256,384,512],d=[128,256],f=["hex","buffer","arrayBuffer","array","digest"],m={128:168,256:136};!r.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!o||!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 g=function(t,e,i){return function(r){return new O(t,e,t).update(r)[i]()}},p=function(t,e,i){return function(r,n){return new O(t,e,n).update(r)[i]()}},w=function(t,e,i){return function(e,r,n,s){return A["cshake"+t].update(e,r,n,s)[i]()}},v=function(t,e,i){return function(e,r,n,s){return A["kmac"+t].update(e,r,n,s)[i]()}},y=function(t,e,i,r){for(var n=0;n<f.length;++n){var s=f[n];t[s]=e(i,r,s)}return t},M=function(t,e){var i=g(t,e,"hex");return i.create=function(){return new O(t,e,t)},i.update=function(t){return i.create().update(t)},y(i,g,t,e)},b=[{name:"keccak",padding:[1,256,65536,16777216],bits:c,createMethod:M},{name:"sha3",padding:[6,1536,393216,100663296],bits:c,createMethod:M},{name:"shake",padding:[31,7936,2031616,520093696],bits:d,createMethod:function(t,e){var i=p(t,e,"hex");return i.create=function(i){return new O(t,e,i)},i.update=function(t,e){return i.create(e).update(t)},y(i,p,t,e)}},{name:"cshake",padding:h,bits:d,createMethod:function(t,e){var i=m[t],r=w(t,0,"hex");return r.create=function(r,n,s){return n||s?new O(t,e,r).bytepad([n,s],i):A["shake"+t].create(r)},r.update=function(t,e,i,n){return r.create(e,i,n).update(t)},y(r,w,t,e)}},{name:"kmac",padding:h,bits:d,createMethod:function(t,e){var i=m[t],r=v(t,0,"hex");return r.create=function(r,n,s){return new B(t,e,n).bytepad(["KMAC",s],i).bytepad([r],i)},r.update=function(t,e,i,n){return r.create(t,i,n).update(e)},y(r,v,t,e)}}],A={},x=[],E=0;E<b.length;++E)for(var R=b[E],S=R.bits,k=0;k<S.length;++k){var I=R.name+"_"+S[k];if(x.push(I),A[I]=R.createMethod(S[k],R.padding),"sha3"!==R.name){var T=R.name+S[k];x.push(T),A[T]=A[I]}}function O(t,e,i){this.blocks=[],this.s=[],this.padding=e,this.outputBits=i,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=i>>5,this.extraBytes=(31&i)>>3;for(var r=0;r<50;++r)this.s[r]=0}function B(t,e,i){O.call(this,t,e,i)}O.prototype.update=function(t){if(this.finalized)throw new Error("finalize already called");var i,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(e);if(null===t)throw new Error(e);if(o&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||o&&ArrayBuffer.isView(t)))throw new Error(e);i=!0}for(var n,s,a=this.blocks,h=this.byteCount,l=t.length,c=this.blockCount,d=0,f=this.s;d<l;){if(this.reset)for(this.reset=!1,a[0]=this.block,n=1;n<c+1;++n)a[n]=0;if(i)for(n=this.start;d<l&&n<h;++d)a[n>>2]|=t[d]<<u[3&n++];else for(n=this.start;d<l&&n<h;++d)(s=t.charCodeAt(d))<128?a[n>>2]|=s<<u[3&n++]:s<2048?(a[n>>2]|=(192|s>>6)<<u[3&n++],a[n>>2]|=(128|63&s)<<u[3&n++]):s<55296||s>=57344?(a[n>>2]|=(224|s>>12)<<u[3&n++],a[n>>2]|=(128|s>>6&63)<<u[3&n++],a[n>>2]|=(128|63&s)<<u[3&n++]):(s=65536+((1023&s)<<10|1023&t.charCodeAt(++d)),a[n>>2]|=(240|s>>18)<<u[3&n++],a[n>>2]|=(128|s>>12&63)<<u[3&n++],a[n>>2]|=(128|s>>6&63)<<u[3&n++],a[n>>2]|=(128|63&s)<<u[3&n++]);if(this.lastByteIndex=n,n>=h){for(this.start=n-h,this.block=a[c],n=0;n<c;++n)f[n]^=a[n];C(f),this.reset=!0}else this.start=n}return this},O.prototype.encode=function(t,e){var i=255&t,r=1,n=[i];for(i=255&(t>>=8);i>0;)n.unshift(i),i=255&(t>>=8),++r;return e?n.push(r):n.unshift(r),this.update(n),n.length},O.prototype.encodeString=function(t){var i,r=typeof t;if("string"!==r){if("object"!==r)throw new Error(e);if(null===t)throw new Error(e);if(o&&t.constructor===ArrayBuffer)t=new Uint8Array(t);else if(!(Array.isArray(t)||o&&ArrayBuffer.isView(t)))throw new Error(e);i=!0}var n=0;if(i)n=t.length;else for(var s=0;s<t.length;++s){var a=t.charCodeAt(s);a<128?n+=1:a<2048?n+=2:a<55296||a>=57344?n+=3:(a=65536+((1023&a)<<10|1023&t.charCodeAt(++s)),n+=4)}return n+=this.encode(8*n),this.update(t),n},O.prototype.bytepad=function(t,e){for(var i=this.encode(e),r=0;r<t.length;++r)i+=this.encodeString(t[r]);var n=[];return n.length=e-i%e,this.update(n),this},O.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,e=this.lastByteIndex,i=this.blockCount,r=this.s;if(t[e>>2]|=this.padding[3&e],this.lastByteIndex===this.byteCount)for(t[0]=t[i],e=1;e<i+1;++e)t[e]=0;for(t[i-1]|=2147483648,e=0;e<i;++e)r[e]^=t[e];C(r)}},O.prototype.toString=O.prototype.hex=function(){this.finalize();for(var t,e=this.blockCount,i=this.s,r=this.outputBlocks,n=this.extraBytes,s=0,o=0,h="";o<r;){for(s=0;s<e&&o<r;++s,++o)h+=a[(t=i[s])>>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];o%e==0&&(C(i),s=0)}return n&&(h+=a[(t=i[s])>>4&15]+a[15&t],n>1&&(h+=a[t>>12&15]+a[t>>8&15]),n>2&&(h+=a[t>>20&15]+a[t>>16&15])),h},O.prototype.buffer=O.prototype.arrayBuffer=function(){this.finalize();var t,e=this.blockCount,i=this.s,r=this.outputBlocks,n=this.extraBytes,s=0,o=0,a=this.outputBits>>3;t=n?new ArrayBuffer(r+1<<2):new ArrayBuffer(a);for(var h=new Uint32Array(t);o<r;){for(s=0;s<e&&o<r;++s,++o)h[o]=i[s];o%e==0&&C(i)}return n&&(h[s]=i[s],t=t.slice(0,a)),t},O.prototype.digest=O.prototype.array=function(){this.finalize();for(var t,e,i=this.blockCount,r=this.s,n=this.outputBlocks,s=this.extraBytes,o=0,a=0,h=[];a<n;){for(o=0;o<i&&a<n;++o,++a)h[t=a<<2]=255&(e=r[o]),h[t+1]=e>>8&255,h[t+2]=e>>16&255,h[t+3]=e>>24&255;a%i==0&&C(r)}return s&&(h[t=a<<2]=255&(e=r[o]),s>1&&(h[t+1]=e>>8&255),s>2&&(h[t+2]=e>>16&255)),h},(B.prototype=new O).finalize=function(){return this.encode(this.outputBits,!0),O.prototype.finalize.call(this)};var C=function(t){var e,i,r,n,s,o,a,h,u,c,d,f,m,g,p,w,v,y,M,b,A,x,E,R,S,k,I,T,O,B,C,_,P,D,L,N,W,F,U,q,$,j,G,z,H,Z,V,J,K,X,Q,Y,tt,et,it,rt,nt,st,ot,at,ht,ut,lt;for(r=0;r<48;r+=2)n=t[0]^t[10]^t[20]^t[30]^t[40],s=t[1]^t[11]^t[21]^t[31]^t[41],h=t[4]^t[14]^t[24]^t[34]^t[44],u=t[5]^t[15]^t[25]^t[35]^t[45],c=t[6]^t[16]^t[26]^t[36]^t[46],d=t[7]^t[17]^t[27]^t[37]^t[47],i=(m=t[9]^t[19]^t[29]^t[39]^t[49])^((a=t[3]^t[13]^t[23]^t[33]^t[43])<<1|(o=t[2]^t[12]^t[22]^t[32]^t[42])>>>31),t[0]^=e=(f=t[8]^t[18]^t[28]^t[38]^t[48])^(o<<1|a>>>31),t[1]^=i,t[10]^=e,t[11]^=i,t[20]^=e,t[21]^=i,t[30]^=e,t[31]^=i,t[40]^=e,t[41]^=i,i=s^(u<<1|h>>>31),t[2]^=e=n^(h<<1|u>>>31),t[3]^=i,t[12]^=e,t[13]^=i,t[22]^=e,t[23]^=i,t[32]^=e,t[33]^=i,t[42]^=e,t[43]^=i,i=a^(d<<1|c>>>31),t[4]^=e=o^(c<<1|d>>>31),t[5]^=i,t[14]^=e,t[15]^=i,t[24]^=e,t[25]^=i,t[34]^=e,t[35]^=i,t[44]^=e,t[45]^=i,i=u^(m<<1|f>>>31),t[6]^=e=h^(f<<1|m>>>31),t[7]^=i,t[16]^=e,t[17]^=i,t[26]^=e,t[27]^=i,t[36]^=e,t[37]^=i,t[46]^=e,t[47]^=i,i=d^(s<<1|n>>>31),t[8]^=e=c^(n<<1|s>>>31),t[9]^=i,t[18]^=e,t[19]^=i,t[28]^=e,t[29]^=i,t[38]^=e,t[39]^=i,t[48]^=e,t[49]^=i,p=t[1],Z=t[11]<<4|t[10]>>>28,V=t[10]<<4|t[11]>>>28,T=t[20]<<3|t[21]>>>29,O=t[21]<<3|t[20]>>>29,at=t[31]<<9|t[30]>>>23,ht=t[30]<<9|t[31]>>>23,j=t[40]<<18|t[41]>>>14,G=t[41]<<18|t[40]>>>14,D=t[2]<<1|t[3]>>>31,L=t[3]<<1|t[2]>>>31,v=t[12]<<12|t[13]>>>20,J=t[22]<<10|t[23]>>>22,K=t[23]<<10|t[22]>>>22,B=t[33]<<13|t[32]>>>19,C=t[32]<<13|t[33]>>>19,ut=t[42]<<2|t[43]>>>30,lt=t[43]<<2|t[42]>>>30,et=t[5]<<30|t[4]>>>2,it=t[4]<<30|t[5]>>>2,N=t[14]<<6|t[15]>>>26,W=t[15]<<6|t[14]>>>26,M=t[24]<<11|t[25]>>>21,X=t[34]<<15|t[35]>>>17,Q=t[35]<<15|t[34]>>>17,_=t[45]<<29|t[44]>>>3,P=t[44]<<29|t[45]>>>3,R=t[6]<<28|t[7]>>>4,S=t[7]<<28|t[6]>>>4,rt=t[17]<<23|t[16]>>>9,nt=t[16]<<23|t[17]>>>9,F=t[26]<<25|t[27]>>>7,U=t[27]<<25|t[26]>>>7,b=t[36]<<21|t[37]>>>11,A=t[37]<<21|t[36]>>>11,Y=t[47]<<24|t[46]>>>8,tt=t[46]<<24|t[47]>>>8,z=t[8]<<27|t[9]>>>5,H=t[9]<<27|t[8]>>>5,k=t[18]<<20|t[19]>>>12,I=t[19]<<20|t[18]>>>12,st=t[29]<<7|t[28]>>>25,ot=t[28]<<7|t[29]>>>25,q=t[38]<<8|t[39]>>>24,$=t[39]<<8|t[38]>>>24,x=t[48]<<14|t[49]>>>18,E=t[49]<<14|t[48]>>>18,t[0]=(g=t[0])^~(w=t[13]<<12|t[12]>>>20)&(y=t[25]<<11|t[24]>>>21),t[1]=p^~v&M,t[10]=R^~k&T,t[11]=S^~I&O,t[20]=D^~N&F,t[21]=L^~W&U,t[30]=z^~Z&J,t[31]=H^~V&K,t[40]=et^~rt&st,t[41]=it^~nt&ot,t[2]=w^~y&b,t[3]=v^~M&A,t[12]=k^~T&B,t[13]=I^~O&C,t[22]=N^~F&q,t[23]=W^~U&$,t[32]=Z^~J&X,t[33]=V^~K&Q,t[42]=rt^~st&at,t[43]=nt^~ot&ht,t[4]=y^~b&x,t[5]=M^~A&E,t[14]=T^~B&_,t[15]=O^~C&P,t[24]=F^~q&j,t[25]=U^~$&G,t[34]=J^~X&Y,t[35]=K^~Q&tt,t[44]=st^~at&ut,t[45]=ot^~ht<,t[6]=b^~x&g,t[7]=A^~E&p,t[16]=B^~_&R,t[17]=C^~P&S,t[26]=q^~j&D,t[27]=$^~G&L,t[36]=X^~Y&z,t[37]=Q^~tt&H,t[46]=at^~ut&et,t[47]=ht^~lt&it,t[8]=x^~g&w,t[9]=E^~p&v,t[18]=_^~R&k,t[19]=P^~S&I,t[28]=j^~D&N,t[29]=G^~L&W,t[38]=Y^~z&Z,t[39]=tt^~H&V,t[48]=ut^~et&rt,t[49]=lt^~it&nt,t[0]^=l[r],t[1]^=l[r+1]};if(s)t.exports=A;else for(E=0;E<x.length;++E)r[x[E]]=A[x[E]]}()});function Yt(t){if(null==t)throw new Error("cannot convert null value to array");if("string"==typeof t){const e=t.match(/^(0x)?[0-9a-fA-F]*$/);if(!e)throw new Error("invalid hexidecimal string");if("0x"!==e[1])throw new Error("hex string must have 0x prefix");(t=t.substring(2)).length%2&&(t="0"+t);const i=[];for(let e=0;e<t.length;e+=2)i.push(parseInt(t.substr(e,2),16));return te(new Uint8Array(i))}if(function(t){if(!t||parseInt(String(t.length))!=t.length||"string"==typeof t)return!1;for(let e=0;e<t.length;e++){const i=t[e];if(i<0||i>=256||parseInt(String(i))!=i)return!1}return!0}(t))return te(new Uint8Array(t));throw new Error("invalid arrayify value")}function te(t){return void 0!==t.slice||(t.slice=()=>{const e=Array.prototype.slice.call(arguments);return te(new Uint8Array(Array.prototype.slice.apply(t,e)))}),t}var ee=/*#__PURE__*/Object.defineProperty({keccak256:function(t){return"0x"+Qt.keccak_256(Yt(t))},padLeft:(t,e)=>{const i=/^0x/i.test(t)||"number"==typeof t;return t=t.toString().replace(/^0x/i,""),(i?"0x":"")+new Array(e-t.length+1>=0?e-t.length+1:0).join("0")+t},bytesToHex:function(t){const e=[];for(let i=0;i<t.length;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return`0x${e.join("").replace(/^0+/,"")}`},toByteArray:Yt},"__esModule",{value:!0});function ie(t){return!("string"!=typeof t||!/^(0x)?[0-9a-f]{512}$/i.test(t)||!/^(0x)?[0-9a-f]{512}$/.test(t)&&!/^(0x)?[0-9A-F]{512}$/.test(t))}function re(t,e){"object"==typeof e&&e.constructor===Uint8Array&&(e=ee.bytesToHex(e));const i=ee.keccak256(e).replace("0x","");for(let e=0;e<12;e+=4){const r=(parseInt(i.substr(e,2),16)<<8)+parseInt(i.substr(e+2,2),16)&2047,n=1<<r%4;if((ne(t.charCodeAt(t.length-1-Math.floor(r/4)))&n)!==n)return!1}return!0}function ne(t){if(t>=48&&t<=57)return t-48;if(t>=65&&t<=70)return t-55;if(t>=97&&t<=102)return t-87;throw new Error("invalid bloom")}function se(t){return!("string"!=typeof t||!/^(0x)?[0-9a-f]{64}$/i.test(t)||!/^(0x)?[0-9a-f]{64}$/.test(t)&&!/^(0x)?[0-9A-F]{64}$/.test(t))}function oe(t){return!("string"!=typeof t||!t.match(/^(0x)?[0-9a-fA-F]{40}$/)&&!t.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/))}var ae=/*#__PURE__*/Object.defineProperty({isBloom:ie,isInBloom:re,isUserEthereumAddressInBloom:function(t,e){if(!ie(t))throw new Error("Invalid bloom given");if(!oe(e))throw new Error(`Invalid ethereum address given: "${e}"`);return re(t,ee.padLeft(e,64))},isContractAddressInBloom:function(t,e){if(!ie(t))throw new Error("Invalid bloom given");if(!oe(e))throw new Error(`Invalid contract address given: "${e}"`);return re(t,e)},isTopicInBloom:function(t,e){if(!ie(t))throw new Error("Invalid bloom given");if(!se(e))throw new Error("Invalid topic");return re(t,e)},isTopic:se,isAddress:oe},"__esModule",{value:!0}),he=function(t){return jt.isBN(t)},ue=function(t){return t&&t.constructor&&"BigNumber"===t.constructor.name},le=function(t){try{return Lt.apply(null,arguments)}catch(e){throw new Error(e+' Given value: "'+t+'"')}},ce=function(t){return!!/^(0x)?[0-9a-f]{40}$/i.test(t)&&(!(!/^(0x|0X)?[0-9a-f]{40}$/.test(t)&&!/^(0x|0X)?[0-9A-F]{40}$/.test(t))||de(t))},de=function(t){t=t.replace(/^0x/i,"");for(var e=be(t.toLowerCase()).replace(/^0x/i,""),i=0;i<40;i++)if(parseInt(e[i],16)>7&&t[i].toUpperCase()!==t[i]||parseInt(e[i],16)<=7&&t[i].toLowerCase()!==t[i])return!1;return!0},fe=function(t){var e="";t=(t=(t=(t=(t=Gt.encode(t)).replace(/^(?:\u0000)*/,"")).split("").reverse().join("")).replace(/^(?:\u0000)*/,"")).split("").reverse().join("");for(var i=0;i<t.length;i++){var r=t.charCodeAt(i).toString(16);e+=r.length<2?"0"+r:r}return"0x"+e},me=function(t){if(!t)return t;if("string"==typeof t&&!ve(t))throw new Error('Given value "'+t+'" is not a valid hex string.');return le(t).toNumber()},ge=function(t){if(null==t)return t;if(!isFinite(t)&&!ve(t))throw new Error('Given input "'+t+'" is not a number.');var e=le(t),i=e.toString(16);return e.lt(new jt(0))?"-0x"+i.substr(1):"0x"+i},pe=function(t){if(t=t.toString(16),!ve(t))throw new Error('Given value "'+t+'" is not a valid hex string.');t=t.replace(/^0x/i,"");for(var e=[],i=0;i<t.length;i+=2)e.push(parseInt(t.substr(i,2),16));return e},we=function(t,e){if(ce(t))return e?"address":"0x"+t.toLowerCase().replace(/^0x/i,"");if("boolean"==typeof t)return e?"bool":t?"0x01":"0x00";if(Buffer.isBuffer(t))return"0x"+t.toString("hex");if("object"==typeof t&&t&&!ue(t)&&!he(t))return e?"string":fe(JSON.stringify(t));if("string"==typeof t){if(0===t.indexOf("-0x")||0===t.indexOf("-0X"))return e?"int256":ge(t);if(0===t.indexOf("0x")||0===t.indexOf("0X"))return e?"bytes":t;if(!isFinite(t))return e?"string":fe(t)}return e?t<0?"int256":"uint256":ge(t)},ve=function(t){return("string"==typeof t||"number"==typeof t)&&/^(-)?0x[0-9a-f]*$/i.test(t)},ye=function(t){return("string"==typeof t||"number"==typeof t)&&/^(-0x|0x)?[0-9a-f]*$/i.test(t)},Me="0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",be=function(t){he(t)&&(t=t.toString()),ve(t)&&/^0x/i.test(t.toString())&&(t=pe(t));var e=Xt.keccak256(t);return e===Me?null:e};be._Hash=Xt;var Ae,xe,Ee={BN:jt,isBN:he,isBigNumber:ue,toBN:le,isAddress:ce,isBloom:function(t){return ae.isBloom(t)},isUserEthereumAddressInBloom:function(t,e){return ae.isUserEthereumAddressInBloom(t,e)},isContractAddressInBloom:function(t,e){return ae.isContractAddressInBloom(t,e)},isTopic:function(t){return ae.isTopic(t)},isTopicInBloom:function(t,e){return ae.isTopicInBloom(t,e)},isInBloom:function(t,e){return ae.isInBloom(t,e)},checkAddressChecksum:de,utf8ToHex:fe,hexToUtf8:function(t){if(!ve(t))throw new Error('The parameter "'+t+'" must be a valid HEX string.');for(var e="",i=0,r=(t=(t=(t=(t=(t=t.replace(/^0x/i,"")).replace(/^(?:00)*/,"")).split("").reverse().join("")).replace(/^(?:00)*/,"")).split("").reverse().join("")).length,n=0;n<r;n+=2)i=parseInt(t.substr(n,2),16),e+=String.fromCharCode(i);return Gt.decode(e)},hexToNumber:me,hexToNumberString:function(t){if(!t)return t;if("string"==typeof t&&!ve(t))throw new Error('Given value "'+t+'" is not a valid hex string.');return le(t).toString(10)},numberToHex:ge,toHex:we,hexToBytes:pe,bytesToHex:function(t){for(var e=[],i=0;i<t.length;i++)e.push((t[i]>>>4).toString(16)),e.push((15&t[i]).toString(16));return"0x"+e.join("")},isHex:ye,isHexStrict:ve,stripHexPrefix:function(t){return 0!==t&&ye(t)?t.replace(/^(-)?0x/i,"$1"):t},leftPad:function(t,e,i){var r=/^0x/i.test(t)||"number"==typeof t;return t=t.toString(16).replace(/^0x/i,""),(r?"0x":"")+new Array(e-t.length+1>=0?e-t.length+1:0).join(i||"0")+t},rightPad:function(t,e,i){return(/^0x/i.test(t)||"number"==typeof t?"0x":"")+(t=t.toString(16).replace(/^0x/i,""))+new Array(e-t.length+1>=0?e-t.length+1:0).join(i||"0")},toTwosComplement:function(t){return"0x"+le(t).toTwos(256).toString(16,64)},sha3:be,sha3Raw:function(t){return null===(t=be(t))?Me:t},toNumber:function(t){return"number"==typeof t?t:me(we(t))}},Re=function(t){var e=typeof t;if("string"===e)return Ee.isHexStrict(t)?new jt(t.replace(/0x/i,""),16):new jt(t,10);if("number"===e)return new jt(t);if(Ee.isBigNumber(t))return new jt(t.toString(10));if(Ee.isBN(t))return t;throw new Error(t+" is not a number")},Se=function(t,e,i){var r,n,s;if("bytes"===(t=(s=t).startsWith("int[")?"int256"+s.slice(3):"int"===s?"int256":s.startsWith("uint[")?"uint256"+s.slice(4):"uint"===s?"uint256":s.startsWith("fixed[")?"fixed128x128"+s.slice(5):"fixed"===s?"fixed128x128":s.startsWith("ufixed[")?"ufixed128x128"+s.slice(6):"ufixed"===s?"ufixed128x128":s)){if(e.replace(/^0x/i,"").length%2!=0)throw new Error("Invalid bytes characters "+e.length);return e}if("string"===t)return Ee.utf8ToHex(e);if("bool"===t)return e?"01":"00";if(t.startsWith("address")){if(r=i?64:40,!Ee.isAddress(e))throw new Error(e+" is not a valid address, or the checksum is invalid.");return Ee.leftPad(e.toLowerCase(),r)}if(r=function(t){var e=/^\D+(\d+).*$/.exec(t);return e?parseInt(e[1],10):null}(t),t.startsWith("bytes")){if(!r)throw new Error("bytes[] not yet supported in solidity");if(i&&(r=32),r<1||r>32||r<e.replace(/^0x/i,"").length/2)throw new Error("Invalid bytes"+r+" for "+e);return Ee.rightPad(e,2*r)}if(t.startsWith("uint")){if(r%8||r<8||r>256)throw new Error("Invalid uint"+r+" size");if((n=Re(e)).bitLength()>r)throw new Error("Supplied uint exceeds width: "+r+" vs "+n.bitLength());if(n.lt(new jt(0)))throw new Error("Supplied uint "+n.toString()+" is negative");return r?Ee.leftPad(n.toString("hex"),r/8*2):n}if(t.startsWith("int")){if(r%8||r<8||r>256)throw new Error("Invalid int"+r+" size");if((n=Re(e)).bitLength()>r)throw new Error("Supplied int exceeds width: "+r+" vs "+n.bitLength());return n.lt(new jt(0))?n.toTwos(r).toString("hex"):r?Ee.leftPad(n.toString("hex"),r/8*2):n}throw new Error("Unsupported or invalid type: "+t)},ke=function(t){if(Array.isArray(t))throw new Error("Autodetection of array types is not supported.");var e,i,r="";if(t&&"object"==typeof t&&(t.hasOwnProperty("v")||t.hasOwnProperty("t")||t.hasOwnProperty("value")||t.hasOwnProperty("type"))?(e=t.hasOwnProperty("t")?t.t:t.type,r=t.hasOwnProperty("v")?t.v:t.value):(e=Ee.toHex(t,!0),r=Ee.toHex(t),e.startsWith("int")||e.startsWith("uint")||(e="bytes")),!e.startsWith("int")&&!e.startsWith("uint")||"string"!=typeof r||/^(-)?0x/i.test(r)||(r=new jt(r)),Array.isArray(r)){if((i=function(t){var e=/^\D+\d*\[(\d+)\]$/.exec(t);return e?parseInt(e[1],10):null}(e))&&r.length!==i)throw new Error(e+" is not matching the given array "+JSON.stringify(r));i=r.length}return Array.isArray(r)?r.map(function(t){return Se(e,t,i).toString("hex").replace("0x","")}).join(""):Se(e,r,i).toString("hex").replace("0x","")},Ie={soliditySha3:function(){var t=Array.prototype.slice.call(arguments),e=t.map(ke);return Ee.sha3("0x"+e.join(""))},soliditySha3Raw:function(){return Ee.sha3Raw("0x"+Array.prototype.slice.call(arguments).map(ke).join(""))},encodePacked:function(){var t=Array.prototype.slice.call(arguments),e=t.map(ke);return"0x"+e.join("").toLowerCase()}},Te=T.default.randomBytes,Oe=function(t,e){var i=[];return e.forEach(function(e){if("object"==typeof e.components){if("tuple"!==e.type.substring(0,5))throw new Error("components found but type is not tuple; report on GitHub");var r="",n=e.type.indexOf("[");n>=0&&(r=e.type.substring(n));var s=Oe(t,e.components);Array.isArray(s)&&t?i.push("tuple("+s.join(",")+")"+r):i.push(t?"("+s+")":"("+s.join(",")+")"+r)}else i.push(e.type)}),i},Be=function(t){if(!Ee.isHexStrict(t))throw new Error("The parameter must be a valid HEX string.");var e="",i=0,r=t.length;for("0x"===t.substring(0,2)&&(i=2);i<r;i+=2){var n=parseInt(t.substr(i,2),16);e+=String.fromCharCode(n)}return e},Ce=function(t){if(!t)return"0x00";for(var e="",i=0;i<t.length;i++){var r=t.charCodeAt(i).toString(16);e+=r.length<2?"0"+r:r}return"0x"+e},_e=function(t){if(t=t?t.toLowerCase():"ether",!$t.unitMap[t])throw new Error('This unit "'+t+"\" doesn't exist, please use the one of the following units"+JSON.stringify($t.unitMap,null,2));return t},Pe={_fireError:function(t,e,i,r,n){return!t||"object"!=typeof t||t instanceof Error||!t.data||((t.data&&"object"==typeof t.data||Array.isArray(t.data))&&(t.data=JSON.stringify(t.data,null,2)),t=t.message+"\n"+t.data),"string"==typeof t&&(t=new Error(t)),"function"==typeof r&&r(t,n),"function"==typeof i&&((e&&"function"==typeof e.listeners&&e.listeners("error").length||"function"==typeof r)&&e.catch(function(){}),setTimeout(function(){i(t)},1)),e&&"function"==typeof e.emit&&setTimeout(function(){e.emit("error",t,n),e.removeAllListeners()},1),e},_jsonInterfaceMethodToString:function(t){return t&&"object"==typeof t&&t.name&&-1!==t.name.indexOf("(")?t.name:t.name+"("+Oe(!1,t.inputs).join(",")+")"},_flattenTypes:Oe,randomHex:function(t){return"0x"+Te(t).toString("hex")},BN:Ee.BN,isBN:Ee.isBN,isBigNumber:Ee.isBigNumber,isHex:Ee.isHex,isHexStrict:Ee.isHexStrict,sha3:Ee.sha3,sha3Raw:Ee.sha3Raw,keccak256:Ee.sha3,soliditySha3:Ie.soliditySha3,soliditySha3Raw:Ie.soliditySha3Raw,encodePacked:Ie.encodePacked,isAddress:Ee.isAddress,checkAddressChecksum:Ee.checkAddressChecksum,toChecksumAddress:function(t){if(void 0===t)return"";if(!/^(0x)?[0-9a-f]{40}$/i.test(t))throw new Error('Given address "'+t+'" is not a valid Ethereum address.');t=t.toLowerCase().replace(/^0x/i,"");for(var e=Ee.sha3(t).replace(/^0x/i,""),i="0x",r=0;r<t.length;r++)parseInt(e[r],16)>7?i+=t[r].toUpperCase():i+=t[r];return i},toHex:Ee.toHex,toBN:Ee.toBN,bytesToHex:Ee.bytesToHex,hexToBytes:Ee.hexToBytes,hexToNumberString:Ee.hexToNumberString,hexToNumber:Ee.hexToNumber,toDecimal:Ee.hexToNumber,numberToHex:Ee.numberToHex,fromDecimal:Ee.numberToHex,hexToUtf8:Ee.hexToUtf8,hexToString:Ee.hexToUtf8,toUtf8:Ee.hexToUtf8,stripHexPrefix:Ee.stripHexPrefix,utf8ToHex:Ee.utf8ToHex,stringToHex:Ee.utf8ToHex,fromUtf8:Ee.utf8ToHex,hexToAscii:Be,toAscii:Be,asciiToHex:Ce,fromAscii:Ce,unitMap:$t.unitMap,toWei:function(t,e){if(e=_e(e),!Ee.isBN(t)&&"string"!=typeof t)throw new Error("Please pass numbers as strings or BN objects to avoid precision errors.");return Ee.isBN(t)?$t.toWei(t,e):$t.toWei(t,e).toString(10)},fromWei:function(t,e){if(e=_e(e),!Ee.isBN(t)&&"string"!=typeof t)throw new Error("Please pass numbers as strings or BN objects to avoid precision errors.");return Ee.isBN(t)?$t.fromWei(t,e):$t.fromWei(t,e).toString(10)},padLeft:Ee.leftPad,leftPad:Ee.leftPad,padRight:Ee.rightPad,rightPad:Ee.rightPad,toTwosComplement:Ee.toTwosComplement,isBloom:Ee.isBloom,isUserEthereumAddressInBloom:Ee.isUserEthereumAddressInBloom,isContractAddressInBloom:Ee.isContractAddressInBloom,isTopic:Ee.isTopic,isTopicInBloom:Ee.isTopicInBloom,isInBloom:Ee.isInBloom,compareBlockNumbers:function(t,e){if(t==e)return 0;if("genesis"!=t&&"earliest"!=t&&0!=t||"genesis"!=e&&"earliest"!=e&&0!=e){if("genesis"==t||"earliest"==t)return-1;if("genesis"==e||"earliest"==e)return 1;if("latest"==t)return"pending"==e?-1:1;if("latest"===e)return"pending"==t?1:-1;if("pending"==t)return 1;if("pending"==e)return-1;{let i=new jt(t),r=new jt(e);return i.lt(r)?-1:i.eq(r)?0:1}}return 0},toNumber:Ee.toNumber};function De(t,e,i){let r=!1;if("allow"===i){if(t&&t.allow){const i=t.allow.find(t=>t.type===e);r=i&&i.values.length>0}return r}if(t&&t.deny){const i=t.deny.find(t=>t.type===e);r=i&&i.values.length>0}return r}function Le(t,e,i){const r=De(t.credentials,e,i);return"allow"===i?(r&&(t.credentials.allow=t.credentials.allow.filter(t=>t.type!==e)),t.credentials&&!t.credentials.allow&&(t.credentials={deny:t.credentials&&t.credentials.deny})):(r&&(t.credentials.deny=t.credentials.deny.filter(t=>t.type!==e)),t.credentials&&!t.credentials.deny&&(t.credentials={allow:t.credentials&&t.credentials.allow})),t}function Ne(t,e,i,r){const n=De(t.credentials,e,r);return"allow"===r?n?t.credentials.allow.find(t=>{t.type===e&&(t.values=i)}):t=We(t,e,i,r):n?t.credentials.deny.find(t=>{t.type===e&&(t.values=i)}):t=We(t,e,i,r),t}function We(t,e,i,r){const n={type:e,values:i};return"allow"===r?t.credentials&&t.credentials.allow?t.credentials.allow.push(n):t.credentials={allow:[n],deny:t.credentials&&t.credentials.deny}:t.credentials&&t.credentials.deny?t.credentials.deny.push(n):t.credentials={allow:t.credentials&&t.credentials.allow,deny:[n]},t}class Fe extends Mt{constructor(...t){super(...t),this.baseUrl=void 0}static async getInstance(t){var e;const i=new Fe;return i.setInstanceConfig(t),await i.setBaseUrl(null==(e=t.config)?void 0:e.rbacUri),i}async setBaseUrl(t){this.baseUrl=t}get url(){return this.baseUrl}getIsPermitArgs(t,e,i,r,n,s){return"consume"===e?{component:t,eventType:e,authService:i,did:s,credentials:{type:n,value:r}}:{component:t,eventType:e,authService:i,credentials:{type:n,value:r}}}async isPermit(t,e,i,r,n,s){if(!this.url)return!0;const o=this.getIsPermitArgs(t,e,i,r,n,s);try{const t=await this.ocean.utils.fetch.post(this.url,JSON.stringify(o));let e=await t.json();return e=JSON.stringify(e),"true"===e}catch(t){throw this.logger.error(t),new Error("ERROR: Asset URL not found or not available.")}}}exports.CreateProgressStep=void 0,(Ae=exports.CreateProgressStep||(exports.CreateProgressStep={}))[Ae.CreatingDataToken=0]="CreatingDataToken",Ae[Ae.DataTokenCreated=1]="DataTokenCreated",Ae[Ae.EncryptingFiles=2]="EncryptingFiles",Ae[Ae.FilesEncrypted=3]="FilesEncrypted",Ae[Ae.StoringDdo=4]="StoringDdo",Ae[Ae.DdoStored=5]="DdoStored",exports.OrderProgressStep=void 0,function(t){t[t.TransferDataToken=0]="TransferDataToken"}(exports.OrderProgressStep||(exports.OrderProgressStep={}));class Ue extends Mt{static async getInstance(t){const e=new Ue;return e.setInstanceConfig(t),e}create(t,e,i=[],r,n,s,o,a){return r&&!Pe.isAddress(r)?(this.logger.error(`Passed Data Token address ${r} is not valid. Aborting publishing.`),null):(this.logger.log("Creating asset"),new K(async h=>{0===i.length&&this.logger.log("You have no services. Are you sure about this?");const{datatokens:u}=this.ocean;if(!r){if(this.logger.log("Creating datatoken"),h.next(exports.CreateProgressStep.CreatingDataToken),r=await u.create("",e.getId(),n,s,o),!Pe.isAddress(r))return this.logger.error(`Created Data Token address ${r} is not valid. Aborting publishing.`),null;this.logger.log(`DataToken ${r} created`),h.next(exports.CreateProgressStep.DataTokenCreated)}const l=At.generate(r);let c;this.logger.log("Encrypting files"),h.next(exports.CreateProgressStep.EncryptingFiles),a?(c=await Tt.getInstance(this.instanceConfig),await c.setBaseUrl(a)):c=this.ocean.provider;const d=await c.encrypt(l.getDid(),t.main.files,e);this.logger.log("Files encrypted"),h.next(exports.CreateProgressStep.FilesEncrypted);let f=0;const m=new Rt({id:l.getDid(),dataToken:r,authentication:[{type:"RsaSignatureAuthentication2018",publicKey:l.getDid()}],publicKey:[{id:l.getDid(),type:"EthereumECDSAKey",owner:e.getId()}],service:[{type:"metadata",attributes:W({status:{isListed:!0,isRetired:!1,isOrderDisabled:!1}},t,{encryptedFiles:d,main:W({},t.main,{files:t.main.files.map((t,e)=>W({},t,{index:e,url:void 0}))})})},...i].reverse().filter(({type:t},e,i)=>i.findIndex(({type:e})=>e===t)===e).reverse().map(t=>W({},t,{index:f++}))});return await m.addProof(this.ocean,e.getId()),m.dataTokenInfo={name:s,symbol:o,address:r,cap:parseFloat(n)},m}))}async resolve(t){return this.ocean.metadataCache.retrieveDDO(t)}async editMetadata(t,e){if(!t)return null;for(let r=0;r<t.service.length;r++){var i;"metadata"===t.service[r].type&&(e.title&&(t.service[r].attributes.main.name=e.title),e.author&&(t.service[r].attributes.main.author=e.author),t.service[r].attributes.additionalInformation||(t.service[r].attributes.additionalInformation=Object()),e.description&&(t.service[r].attributes.additionalInformation.description=e.description),t.service[r].attributes.additionalInformation.links=e.links?e.links:[],void 0!==(null==(i=e.status)?void 0:i.isOrderDisabled)&&(t.service[r].attributes.status?t.service[r].attributes.status.isOrderDisabled=e.status.isOrderDisabled:t.service[r].attributes.status={isOrderDisabled:e.status.isOrderDisabled}))}return t}async updateCredentials(t,e,i,r){let n;return n=i&&i.length>0?Ne(t,e,i,"allow"):Le(t,e,"allow"),n=r&&r.length>0?Ne(t,e,r,"deny"):Le(t,e,"deny"),n}checkCredential(t,e,i){let r=0,n="All good",s=!0;if(t.credentials){if(t.credentials.allow&&t.credentials.allow.length>0){const o=t.credentials.allow.find(t=>t.type===e);o&&!o.values.includes(i)&&(r=2,n="Access is denied, your wallet address is not found on allow list",s=!1)}if(t.credentials.deny&&t.credentials.deny.length>0){const o=t.credentials.deny.find(t=>t.type===e);o&&o.values.includes(i)&&(r=3,n="Access is denied, your wallet address is found on deny list",s=!1)}}return{status:r,message:n,result:s}}async publishDdo(t,e,i=!1){return await this.ocean.onChainMetadata.publish(t.id,t,e,i)}async updateMetadata(t,e){return await this.ocean.onChainMetadata.update(t.id,t,e)}async editServiceTimeout(t,e,i){return t?void 0===t.service[e]||i<0?null:(t.service[e].attributes.main.timeout=parseInt(i.toFixed()),t):null}async creator(t){const{did:e,ddo:i}=await pt(t,this.ocean),r=i.getChecksum(),{creator:n,signatureValue:s}=i.proof,o=await this.ocean.utils.signature.verifyText(r,s);return o.toLowerCase()!==n.toLowerCase()&&this.logger.warn(`Owner of ${e} doesn't match. Expected ${n} instead of ${o}.`),n}async getServiceByType(t,e){const{ddo:i}=await pt(t,this.ocean);let r;return i.service.forEach(t=>{t.type.toString()===e&&(r=t)}),r}async getServiceByIndex(t,e){const{ddo:i}=await pt(t,this.ocean);let r;return i.service.forEach(t=>{t.index===e&&(r=t)}),r}async query(t){return this.ocean.metadataCache.queryMetadata(t)}async createAccessServiceAttributes(t,e,i,r=0,n,s){const o={type:"access",index:2,serviceEndpoint:n||this.ocean.provider.url,attributes:{main:{creator:t.getId(),datePublished:i,cost:e,timeout:r,name:"dataAssetAccess"}}};return null!=s&&s.userCustomParameters&&(o.attributes.userCustomParameters=s.userCustomParameters),null!=s&&s.algoCustomParameters&&(o.attributes.algoCustomParameters=s.algoCustomParameters),o}async initialize(t,e,i,r=-1,n,s){const o=await Tt.getInstance(this.instanceConfig);await o.setBaseUrl(n);const a=await o.initialize(t,r,e,i,s);return null===a?null:JSON.parse(a)}async order(t,e,i,r=-1,n,s,o,a="json",h=!0){let u;const{ddo:l}=await pt(t,this.ocean),c=await this.isConsumable(l,i,"address",a);if(!c.result)throw new Error("Order asset failed, "+c.message);if(s||(s=i),-1===r?(u=await this.getServiceByType(l,e),r=u.index):(u=await this.getServiceByIndex(l,r),e=u.type),!await this.isUserCustomParametersValid(u.attributes.userCustomParameters,o))throw new Error("Order asset failed, Missing required fiels in userCustomParameters");try{const t=await this.initialize(l,e,i,r,u.serviceEndpoint,o);if(!t)throw new Error("Order asset failed, Failed to initialize service to compute totalCost for ordering");if(h){const e=await this.ocean.datatokens.getPreviousValidOrders(t.dataToken,t.numTokens,r,u.attributes.main.timeout,s);if(e)return e}const a=new dt(await this.ocean.datatokens.balance(t.dataToken,i)),c=new dt(String(t.numTokens));if(a.isLessThan(c))throw this.logger.error("ERROR: Not enough funds Needed "+c.toString()+" but balance is "+a.toString()),new Error("ERROR: Not enough funds Needed "+c.toString()+" but balance is "+a.toString());const d=await this.ocean.datatokens.startOrder(t.dataToken,s,String(t.numTokens),r,n,i);if(d)return d.transactionHash}catch(t){throw this.logger.error(`ERROR: Failed to order a service : ${t.message}`),new Error(`${t.message}`)}}async download(t,e,i,r,n,s=-1,o){const{did:a,ddo:h}=await pt(t,this.ocean),{attributes:u}=h.findServiceByType("metadata"),l=h.findServiceByType("access"),{files:c}=u.main,{serviceEndpoint:d}=l;if(!d)throw new Error("Consume asset failed, service definition is missing the `serviceEndpoint`.");this.logger.log("Consuming files"),n=n?`${n}/datafile.${h.shortId()}.${l.index}/`:void 0;const f=await Tt.getInstance(this.instanceConfig);return await f.setBaseUrl(d),await f.download(a,e,i,l.type,l.index.toString(),n,r,c,s,o),!0}async simpleDownload(t,e,i,r){var n,s;let o=e;o+=`?consumerAddress=${r}`,o+=`&tokenAddress=${t}`,o+=`&transferTxId=${i}`;const a=new It(this.logger,null==(n=this.instanceConfig)||null==(s=n.config)?void 0:s.requestTimeout);try{await a.downloadFile(o)}catch(t){throw this.logger.error("Error consuming assets"),this.logger.error(t),t}return e}async getOrderHistory(t,e,i){const r=[],n=t.getId().toLowerCase(),{datatokens:s}=this.ocean,o="0x000000000000000000000000"+n.substring(2),a=s.getStartOrderEventSignature(),h=await this.web3.eth.getPastLogs({topics:[a,null,o],fromBlock:i||0,toBlock:"latest"});for(let t=0;t<h.length;t++){const i={dtAddress:h[t].address,timestamp:0,transactionHash:h[t].transactionHash,amount:null,consumer:"0x"+h[t].topics[1].substring(h[t].topics[1].length-40),payer:"0x"+h[t].topics[2].substring(h[t].topics[2].length-40)};try{const n=this.web3.eth.abi.decodeParameters(["uint256","uint256","uint256","uint256"],h[t].data);i.serviceId=parseInt(n[1]),i.timestamp=parseInt(n[2]),i.amount=this.web3.utils.fromWei(n[0]),i.did=G(Z(i.dtAddress));const s=await this.getServiceByIndex(i.did,i.serviceId);i.serviceType=s.type,(!e||e&&e===s.type)&&r.push(i)}catch(t){}}return r}async isConsumable(t,e,i,r){var n,s;if(!t)throw new Error("ERROR: DDO does not exist");const o={status:2,message:"Consume access is denied.",result:!1};if(null!=(n=t.findServiceByType("metadata").attributes.status)&&n.isOrderDisabled)return{status:1,message:"Ordering this asset has been temporarily disabled by the publisher.",result:!1};const a=this.instanceConfig;if(e&&null!=a&&null!=(s=a.config)&&s.rbacUri){const n=await Fe.getInstance(this.instanceConfig);if(!await n.isPermit("market","consume",r,e,i,t.id))return o}return{status:0,message:"All good",result:!0}}async isUserCustomParametersValid(t,e){if(t)for(const i of t){const t=i.name;if(i.required&&(!e||!e[t]))return this.logger.error("Missing key: "+t+" from customData"),!1}return!0}}exports.OceanPlatformTechStatus=void 0,(xe=exports.OceanPlatformTechStatus||(exports.OceanPlatformTechStatus={})).Loading="Loading",xe.Unknown="Unknown",xe.Stopped="Stopped",xe.Working="Working";class qe extends Mt{static async getInstance(t){const e=new qe;return e.setInstanceConfig(t),e}async get(){const t={};t.lib={name:"Lib",version:"0.20.2",commit:"62490dcdbb734b304522f4bccf1c761ed84ab7ff",status:exports.OceanPlatformTechStatus.Working};try{const{software:e,version:i}=await this.ocean.metadataCache.getVersionInfo();t.metadataCache={name:e,status:exports.OceanPlatformTechStatus.Working,version:i}}catch(e){t.metadataCache={name:"MetadataCache",status:exports.OceanPlatformTechStatus.Stopped}}const e=Object.values(t);return t.status={ok:!e.find(({status:t})=>t!==exports.OceanPlatformTechStatus.Working)},t}}class $e{constructor(t,e){this.web3=void 0,this.logger=void 0,this.web3=t,this.logger=e}async signText(t,e,i){const r=this.web3&&this.web3.currentProvider&&this.web3.currentProvider.isMetaMask;try{return await this.web3.eth.personal.sign(t,e,i)}catch(i){if(r)throw i;this.logger.warn("Error on personal sign."),this.logger.warn(i);try{return await this.web3.eth.sign(t,e)}catch(t){throw this.logger.error("Error on sign."),this.logger.error(t),new Error("Error executing personal sign")}}}async signWithHash(t,e,i){const r=this.web3.utils.utf8ToHex(t),n=this.web3&&this.web3.currentProvider&&this.web3.currentProvider.isMetaMask;try{return await this.web3.eth.personal.sign(r,e,i)}catch(t){if(n)throw t;this.logger.warn("Error on personal sign."),this.logger.warn(t);try{return await this.web3.eth.sign(r,e)}catch(t){throw this.logger.error("Error on sign."),this.logger.error(t),new Error("Error executing personal sign")}}}async verifyText(t,e){return this.web3.eth.personal.ecRecover(t,e)}async getHash(t){let e="";for(let i=0;i<t.length;i++)e+=""+t.charCodeAt(i).toString(16);return"0x"+e}async signForAquarius(t,e){const i=await this.getHash(t),r=this.web3&&this.web3.currentProvider&&this.web3.currentProvider.isMetaMask;try{return this.web3.eth.personal.sign(i,e.getId(),e.getPassword())}catch(t){if(r)throw t;return this.logger.warn("Error on personal sign."),this.logger.warn(t),null}}}class je extends Mt{constructor(...t){super(...t),this.signature=void 0,this.fetch=void 0}static async getInstance(t){var e;const i=new je;return i.setInstanceConfig(t),i.signature=new $e(t.web3,t.logger),i.fetch=new It(t.logger,null==(e=t.config)?void 0:e.requestTimeout),i}}const Ge="/api/v1/aquarius/assets/ddo";class ze{get url(){return this.metadataCacheUri}constructor(t,e,i){this.fetch=void 0,this.logger=void 0,this.metadataCacheUri=void 0,this.fetch=new It(e,i),this.logger=e,this.metadataCacheUri=t}async getVersionInfo(){return(await this.fetch.get(this.url)).json()}async getAccessUrl(t,e){return await this.fetch.post(`${t.service_endpoint}/${t.resource_id}`,e).then(t=>t.ok?t.text():(this.logger.error("Failed: ",t.status,t.statusText),null)).then(t=>(this.logger.error("Success accessing consume endpoint: ",t),t)).catch(t=>(this.logger.error("Error fetching the data asset consumption url: ",t),null))}async queryMetadata(t){return await this.fetch.post(`${this.url}/api/v1/aquarius/assets/query`,JSON.stringify(t)).then(t=>t.ok?t.json():(this.logger.error("queryMetadata failed:",t.status,t.statusText),null)).then(t=>t).catch(t=>(this.logger.error("Error fetching querying metadata: ",t),null))}async encryptDDO(t){const e=`${this.url}/api/v1/aquarius/assets/ddo/encryptashex `;return await this.fetch.postWithOctet(e,t).then(e=>e.ok?e.text():(this.logger.error("encryptDDO failed:",e.status,e.statusText,t),null)).catch(t=>(this.logger.error("Error encryptDDO: ",t),null))}async validateMetadata(t){const e={valid:!1},i=gt(t)?"/validate-remote":"/validate";try{const r=await this.fetch.post(`${this.url}${Ge}${i}`,JSON.stringify(t));if(r.ok){const t=await r.json();!0===t?e.valid=!0:e.errors=t}else this.logger.error("validate Metadata failed:",r.status,r.statusText)}catch(t){this.logger.error("Error validating metadata: ",t)}return e}async retrieveDDO(t,e){t=t&&At.parse(t);const i=e||`${this.url}${Ge}/${t.getDid()}`;return await this.fetch.get(i).then(e=>e.ok?e.json():(this.logger.log("retrieveDDO failed:",e.status,e.statusText,t),null)).then(t=>new Rt(t)).catch(t=>(this.logger.error("Error fetching querying metadata: ",t),null))}async retrieveDDOByUrl(t){return this.retrieveDDO(void 0,t)}getServiceEndpoint(t){return`${this.url}/api/v1/aquarius/assets/ddo/did:op:${t.getId()}`}getURI(){return`${this.url}`}sleep(t){return new Promise(e=>{setTimeout(e,t)})}async waitForAqua(t,e){let i=0;do{try{const i=await h.fetch(this.getURI()+"/api/v1/aquarius/assets/ddo/"+t);if(i.ok){if(!e)break;{const t=await i.json();if(t.event&&t.event.txid===e)break}}}catch(t){}await this.sleep(1500),i++}while(i<100)}}class He{constructor(t,e,i=null,r=null,n,s){this.GASLIMIT_DEFAULT=1e6,this.DDOContractAddress=void 0,this.DDOContractABI=void 0,this.web3=void 0,this.DDOContract=null,this.logger=void 0,this.metadataCache=void 0,this.config=void 0,this.web3=t,this.config=s,this.DDOContractAddress=i,this.DDOContractABI=r||O.default.abi,t&&(this.DDOContract=mt(new this.web3.eth.Contract(this.DDOContractABI,this.DDOContractAddress),this.config)),this.logger=e,this.metadataCache=n}async compressDDO(t){return l.LZMA.disableEndMark=!0,l.LZMA.compress(t,9)}async publish(t,e,i,r=!1,n=!0){if(n&&!(await this.metadataCache.validateMetadata(e)).valid)throw new Error("DDO has failed validation");const s=await this.prepareRawData(e,r);if(s)return this.publishRaw(H(t),s.flags,s.data,i);throw new Error("Could not prepare raw data for publish")}async update(t,e,i,r=!1,n=!0){if(n&&!(await this.metadataCache.validateMetadata(e)).valid)throw new Error("DDO has failed validation");const s=await this.prepareRawData(e,r);if(s)return this.updateRaw(H(t),s.flags,s.data,i);throw new Error("Could not prepare raw data for udate")}async prepareRawData(t,e=!1){let i=0,r=Rt.serialize(t);if(!1===e)r=await this.compressDDO(r),i|=1,r=this.getHex(r);else{if(r=await this.metadataCache.encryptDDO(r),!r)return null;i|=2}return{flags:i,data:r}}async publishRaw(t,e,i,r){if(!this.DDOContract)return this.logger.error("ERROR: Missing DDOContract"),null;const n=this.GASLIMIT_DEFAULT;let s;try{s=await this.DDOContract.methods.create(H(t),e,i).estimateGas({from:r},(t,e)=>t?n:e)}catch(t){s=n}try{return await this.DDOContract.methods.create(H(t),e,i).send({from:r,gas:s+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error(`ERROR: Failed to publish raw DDO : ${t.message}`),null}}async updateRaw(t,e,i,r){if(!this.DDOContract)return this.logger.error("ERROR: Missing DDOContract"),null;const n=this.GASLIMIT_DEFAULT;let s;try{s=await this.DDOContract.methods.update(H(t),e,i).estimateGas({from:r},(t,e)=>t?n:e)}catch(t){s=n}try{return await this.DDOContract.methods.update(H(t),e,i).send({from:r,gas:s+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error(`ERROR: Failed to update raw DDO : ${t.message}`),null}}async transferOwnership(t,e,i){if(!this.DDOContract)return null;try{return await this.DDOContract.methods.transferOwnership(H(t),e).send({from:i})}catch(t){return this.logger.error(`ERROR: Failed to transfer DDO ownership : ${t.message}`),null}}getHex(t){const e=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"];let i="";try{for(let r=0;r<t.length;r++)i+=""+e[t[r]>>4&15]+e[15&t[r]]}catch(t){this.logger.error(`ERROR: Failed to get hex message value : ${t.message}`)}return"0x"+i}}class Ze{constructor(t,e,i,r,n,s){this.GASLIMIT_DEFAULT=1e6,this.factoryAddress=void 0,this.factoryABI=void 0,this.datatokensABI=void 0,this.web3=void 0,this.logger=void 0,this.startBlock=void 0,this.config=void 0,this.factoryAddress=t,this.factoryABI=e||B.default.abi,this.datatokensABI=i||C.default.abi,this.web3=r,this.logger=n,this.config=s,this.startBlock=s&&s.startBlock||0}generateDtName(t){const{name:e,symbol:i}=vt(t);return{name:e,symbol:i}}async create(t,e,i,r,n){i||(i="1000"),r&&n||({name:r,symbol:n}=this.generateDtName());const s=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress,{from:e}),this.config),o=this.GASLIMIT_DEFAULT;let a;try{a=await s.methods.createToken(t,r,n,this.web3.utils.toWei(i)).estimateGas({from:e},(t,e)=>t?o:e)}catch(t){a=o}const h=await s.methods.createToken(t,r,n,this.web3.utils.toWei(i)).send({from:e,gas:a+1,gasPrice:await ft(this.web3,this.config)});let u=null;try{u=h.events.TokenCreated.returnValues[0]}catch(t){this.logger.error(`ERROR: Failed to create datatoken : ${t.message}`)}return u}async approve(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:r}),this.config),s=this.GASLIMIT_DEFAULT;let o;try{o=await n.methods.approve(e,this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){o=s}return await n.methods.approve(e,this.web3.utils.toWei(i)).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)})}async mint(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:e}),this.config),s=await this.getCap(t);if(new x.default(s).gte(i)){const t=this.GASLIMIT_DEFAULT;let s;try{s=await n.methods.mint(r||e,this.web3.utils.toWei(i)).estimateGas({from:e},(e,i)=>e?t:i)}catch(e){s=t}return await n.methods.mint(r||e,this.web3.utils.toWei(i)).send({from:e,gas:s+1,gasPrice:await ft(this.web3,this.config)})}throw new Error("Mint amount exceeds cap available")}async transfer(t,e,i,r){return this.transferToken(t,e,i,r)}async transferToken(t,e,i,r){const n=this.web3.utils.toWei(i);return this.transferWei(t,e,n,r)}async transferWei(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:r}),this.config),s=this.GASLIMIT_DEFAULT;let o;try{o=await n.methods.transfer(e,i).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){o=s}return await n.methods.transfer(e,i).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)})}async transferFrom(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:r}),this.config),s=this.GASLIMIT_DEFAULT;let o;try{o=await n.methods.transferFrom(e,r,this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){o=s}return await n.methods.transferFrom(e,r,this.web3.utils.toWei(i)).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)})}async balance(t,e){const i=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:e}),this.config),r=await i.methods.balanceOf(e).call();return this.web3.utils.fromWei(r)}async allowance(t,e,i){const r=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:i}),this.config),n=await r.methods.allowance(e,i).call();return this.web3.utils.fromWei(n)}async getBlob(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await e.methods.blob().call()}async getName(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await e.methods.name().call()}async getSymbol(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await e.methods.symbol().call()}async getCap(t){const e=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config),i=await e.methods.cap().call();return this.web3.utils.fromWei(i)}toWei(t){return this.web3.utils.toWei(t)}fromWei(t){return this.web3.utils.fromWei(t)}async startOrder(t,e,i,r,n,s){const o=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:s}),this.config);n||(n="0x0000000000000000000000000000000000000000");try{const t=this.GASLIMIT_DEFAULT;let a;try{a=await o.methods.startOrder(e,this.web3.utils.toWei(i),String(r),n).estimateGas({from:s},(e,i)=>e?t:i)}catch(e){a=t}return await o.methods.startOrder(e,this.web3.utils.toWei(i),String(r),n).send({from:s,gas:a+1,gasPrice:await ft(this.web3,this.config)})}catch(t){throw this.logger.error(`ERROR: Failed to start order : ${t.message}`),new Error(`Failed to start order: ${t.message}`)}}async getPreviousValidOrders(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:n}),this.config);let o;r>0?(o=await this.web3.eth.getBlockNumber()-r,o<this.startBlock&&(o=this.startBlock)):o=this.startBlock;const a=await s.getPastEvents("OrderStarted",{filter:{consumer:n},fromBlock:o,toBlock:"latest"});for(let t=0;t<a.length;t++)if(String(a[t].returnValues.amount)===this.web3.utils.toWei(String(e))&&String(a[t].returnValues.serviceId)===String(i)&&a[t].returnValues.consumer.toLowerCase()===n.toLowerCase()){if(0===r)return a[t].transactionHash;const e=await this.web3.eth.getBlock(a[t].blockHash),i=new dt(e.timestamp).plus(r);if(new dt(Math.floor(Date.now()/1e3)).isLessThan(i))return a[t].transactionHash}return null}getStartOrderEventSignature(){const t=this.datatokensABI.find(function(t){if("OrderStarted"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}async proposeMinter(t,e,i){const r=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:i}),this.config),n=this.GASLIMIT_DEFAULT;let s;try{s=await r.methods.proposeMinter(e).estimateGas({from:i},(t,e)=>t?n:e)}catch(t){s=n}try{return await r.methods.proposeMinter(e).send({from:i,gas:s+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error("ERROR: Propose minter failed"),null}}async approveMinter(t,e){const i=mt(new this.web3.eth.Contract(this.datatokensABI,t,{from:e}),this.config),r=this.GASLIMIT_DEFAULT;let n;try{n=await i.methods.approveMinter().estimateGas({from:e},(t,e)=>t?r:e)}catch(t){n=r}try{return await i.methods.approveMinter().send({from:e,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return null}}async isMinter(t,e){const i=mt(new this.web3.eth.Contract(this.datatokensABI,t),this.config);return await i.methods.isMinter(e).call()}}class Ve extends Mt{getNetworkId(){return this.web3.eth.net.getId()}async getNetworkName(){return this.web3.eth.net.getId().then(t=>{const e=f.lookup(t);return e&&e.name?e.name:"Development"})}}var Je;!function(t){t[t.TransferDataToken=0]="TransferDataToken"}(Je||(Je={})),Object.freeze({WarmingUp:1,Started:10,ConfiguringVolumes:20,ProvisioningSuccess:30,DataProvisioningFailed:31,AlgorithmProvisioningFailed:32,RunningAlgorithm:40,FilteringResults:50,PublishingResult:60,Completed:70,Stopped:80,Deleted:90});class Ke extends Mt{static async getInstance(t){const e=new Ke;return e.setInstanceConfig(t),e}async getComputeAddress(t,e=-1){let i,r="compute";-1===e?(i=await this.ocean.assets.getServiceByType(t,r),e=i.index):(i=await this.ocean.assets.getServiceByIndex(t,e),r=i.type);const{serviceEndpoint:n}=i,s=await Tt.getInstance(this.instanceConfig);return await s.setBaseUrl(n),s.computeAddress}async start(t,e,i,r,n,s,o,a,h,u){s=this.checkOutput(r,s);const{did:l,ddo:c}=await pt(t,this.ocean),d=c.findServiceByType("compute"),{serviceEndpoint:f}=d;if(n.serviceIndex){const{ddo:t}=await pt(n.did,this.ocean),e=t.findServiceById(n.serviceIndex);if(!await this.ocean.assets.isUserCustomParametersValid(e.attributes.algoCustomParameters,n.algoCustomParameters))return null}if(l&&e){const t=await Tt.getInstance(this.instanceConfig);await t.setBaseUrl(f);const c=await t.computeStart(l,r,n,s,e,o,a,i,h,u);return c?c[0]:null}return null}async stop(t,e,i){const{did:r,ddo:n}=await pt(e,this.ocean),s=n.findServiceByType("compute"),{serviceEndpoint:o}=s,a=await Tt.getInstance(this.instanceConfig);await a.setBaseUrl(o);const h=await a.computeStop(r,t,i);return h?h[0]:null}async delete(t,e,i){const{did:r,ddo:n}=await pt(e,this.ocean),s=n.findServiceByType("compute"),{serviceEndpoint:o}=s,a=await Tt.getInstance(this.instanceConfig);await a.setBaseUrl(o);const h=await a.computeDelete(r,t,i);return h?h[0]:null}async status(t,e,i,r,n,s){let o;if(e||r||i){if(!r){if(!i&&!(i=await this.ocean.assets.resolve(e)))throw new Error(`Couldn't resolve the did ${e}`);if(!(r=i.findServiceByType("compute")))throw new Error(`Couldn't find a compute service on the asset with did ${e}`)}const{serviceEndpoint:t}=r;o=await Tt.getInstance(this.instanceConfig),await o.setBaseUrl(t)}else o=this.ocean.provider;return await o.computeStatus(e,t,n,s)}async getResult(t,e,i,r,n,s,o){let a;if(n||o||s){if(!o){if(!s&&!(s=await this.ocean.assets.resolve(n)))throw new Error(`Couldn't resolve the did ${n}`);if(!(o=s.findServiceByType("compute")))throw new Error(`Couldn't find a compute service on the asset with did ${n}`)}const{serviceEndpoint:t}=o;a=await Tt.getInstance(this.instanceConfig),await a.setBaseUrl(t)}else a=this.ocean.provider;return await a.computeResult(e,i,r,t)}createServerAttributes(t,e,i,r,n,s,o,a){return{serverId:t,serverType:e,cost:i,cpu:r,gpu:n,memory:s,disk:o,maxExecutionTime:a}}createContainerAttributes(t,e,i){return{image:t,tag:e,checksum:i}}createClusterAttributes(t,e){return{type:t,url:e}}createProviderAttributes(t,e,i,r,n){return{type:t,description:e,environment:{cluster:i,supportedServers:n,supportedContainers:r}}}createComputeService(t,e,i,r,n,s,o,a){s||(s=3600);const h={type:"compute",index:3,serviceEndpoint:o||this.ocean.provider.url,attributes:{main:{name:"dataAssetComputingService",creator:t.getId(),datePublished:i,cost:e,timeout:s,provider:r,privacy:{}}}};return n&&(h.attributes.main.privacy=n),null!=a&&a.userCustomParameters&&(h.attributes.userCustomParameters=a.userCustomParameters),null!=a&&a.algoCustomParameters&&(h.attributes.algoCustomParameters=a.algoCustomParameters),h}checkOutput(t,e){return e&&(e.publishAlgorithmLog||e.publishOutput)?{publishAlgorithmLog:e.publishAlgorithmLog,publishOutput:e.publishOutput,providerAddress:e.providerAddress||this.config.providerAddress,providerUri:e.providerUri||this.config.providerUri,metadataUri:e.metadataUri||this.config.metadataCacheUri,nodeUri:e.nodeUri||this.config.nodeUri,owner:e.owner||t.getId()}:{publishAlgorithmLog:!1,publishOutput:!1}}async isOrderable(t,e,i,r){const n=await pt(t,this.ocean),s=n.ddo.findServiceById(e);if(!s)return!1;if("compute"===s.type){if(i.meta)return!(!s.attributes.main.privacy||!s.attributes.main.privacy.allowRawAlgorithm)||(this.logger.error("ERROR: This service does not allow raw algorithm"),!1);if(i.did){if(i.serviceIndex){if(!r&&!(r=await this.ocean.assets.resolve(i.did)))throw new Error(`Couldn't resolve the did ${i.did}`);const t=r.findServiceById(i.serviceIndex);if(t&&"compute"===t.type){const e=await Tt.getInstance(this.instanceConfig);await e.setBaseUrl(t.serviceEndpoint);const i=await Tt.getInstance(this.instanceConfig);if(await i.setBaseUrl(s.serviceEndpoint),e.providerAddress!==i.providerAddress)return this.logger.error("ERROR: Both assets with compute service are not served by the same provider"),!1}}if(s.attributes.main.privacy){if(s.attributes.main.privacy.allowAllPublishedAlgorithms)return!0;if(!s.attributes.main.privacy.publisherTrustedAlgorithms)return!1;let t;for(t of s.attributes.main.privacy.publisherTrustedAlgorithms)if(t.did===i.did){const e=await this.createPublisherTrustedAlgorithmfromDID(i.did);return t.containerSectionChecksum&&t.containerSectionChecksum!==e.containerSectionChecksum?(this.logger.error("ERROR: Algorithm container section was altered since it was added as trusted by "+n.did),!1):!t.filesChecksum||t.filesChecksum===e.filesChecksum||(this.logger.error("ERROR: Algorithm files section was altered since it was added as trusted by "+n.ddo),!1)}return this.logger.error("ERROR: Algorithm "+i.did+" is not allowed by "+n.did),!1}console.error("Algo Index:"+i.serviceIndex)}}return!0}orderAsset(t,e,i,r,n,s,o,a="json",h=!0){return new K(async u=>{const{ddo:l}=await pt(e,this.ocean);if(!await this.isOrderable(l,i,r))throw new Error("Dataset order failed, dataset is not orderable with the specified algorithm");const c=l.findServiceById(i);if(!c)throw new Error("Dataset order failed, Could not find service for the DDO");try{return await this.ocean.assets.order(l,c.type,t,-1,n,s,o,a,h)}catch(t){throw this.logger.error(`ERROR: Failed to order: ${t.message}`),new Error(`Failed to order dataset: ${t.message}`)}})}async orderAlgorithm(t,e,i,r=-1,n,s,o,a="json",h=!0){try{return await this.ocean.assets.order(t,e,i,r,n,s,o,a,h)}catch(t){throw this.logger.error(`ERROR: Failed to orderAlgorithm: ${t.message}`),new Error(`Failed to order algorithm: ${t.message}`)}}async editComputePrivacy(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return null;e=i.index}return void 0===t.service[e]||"compute"!==t.service[e].type?null:(t.service[e].attributes.main.privacy.allowRawAlgorithm=i.allowRawAlgorithm,t.service[e].attributes.main.privacy.allowAllPublishedAlgorithms=i.allowAllPublishedAlgorithms,t.service[e].attributes.main.privacy.allowNetworkAccess=i.allowNetworkAccess,t.service[e].attributes.main.privacy.publisherTrustedAlgorithms=i.publisherTrustedAlgorithms,t)}async toggleAllowAllPublishedAlgorithms(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return null;e=i.index}return void 0===t.service[e]||"compute"!==t.service[e].type?null:(t.service[e].attributes.main.privacy.allowAllPublishedAlgorithms=i,t)}async createPublisherTrustedAlgorithmfromDID(t,e){if(!e&&!(e=await this.ocean.assets.resolve(t)))return null;const i=e.findServiceByType("metadata");return i&&i.attributes.main.algorithm&&i.attributes.encryptedFiles&&i.attributes.main.files?{did:t,containerSectionChecksum:m.SHA256(JSON.stringify(i.attributes.main.algorithm.container)).toString(),filesChecksum:m.SHA256(i.attributes.encryptedFiles+JSON.stringify(i.attributes.main.files)).toString()}:null}async addTrustedAlgorithmtoAsset(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return null;e=i.index}if(void 0===t.service[e])return null;if("compute"!==t.service[e].type)return null;t.service[e].attributes.main.privacy.publisherTrustedAlgorithms||(t.service[e].attributes.main.privacy.publisherTrustedAlgorithms=[]);const r=await this.createPublisherTrustedAlgorithmfromDID(i);return r&&t.service[e].attributes.main.privacy.publisherTrustedAlgorithms.push(r),t}async isAlgorithmTrusted(t,e,i){if(!t)return!1;if(-1===e){const i=t.findServiceByType("compute");if(!i)return!1;e=i.index}if(void 0===t.service[e])return!1;if("compute"!==t.service[e].type)return!1;if(t.service[e].attributes.main.privacy.allowAllPublishedAlgorithms)return!0;let r;for(r of t.service[e].attributes.main.privacy.publisherTrustedAlgorithms)if(r.did===i)return!0;return!1}async removeTrustedAlgorithmFromAsset(t,e,i){if(!t)return null;if(-1===e){const i=t.findServiceByType("compute");if(!i)return t;e=i.index}return void 0===t.service[e]||"compute"!==t.service[e].type?t:t.service[e].attributes.main.privacy.publisherTrustedAlgorithms?(t.service[e].attributes.main.privacy.publisherTrustedAlgorithms=t.service[e].attributes.main.privacy.publisherTrustedAlgorithms.filter(function(t){return t.did!==i}),t):t}}const Xe="115792089237316195423570985008687907853269984665640564039457584007913129639934";var Qe,Ye,ti,ei;!function(t){t[t.CreatingPool=0]="CreatingPool",t[t.ApprovingDatatoken=1]="ApprovingDatatoken",t[t.ApprovingOcean=2]="ApprovingOcean",t[t.SetupPool=3]="SetupPool"}(Qe||(Qe={}));class ii extends class extends class{constructor(t,e,i=null,r=null,n){this.GASLIMIT_DEFAULT=1e6,this.web3=null,this.factoryABI=void 0,this.factoryAddress=void 0,this.logger=void 0,this.config=void 0,this.web3=t,this.factoryABI=i||P.default.abi,r&&(this.factoryAddress=r),this.logger=e,this.config=n}async createPool(t){if(null===this.web3)return this.logger.error("ERROR: Web3 object is null"),null;if(null===this.factoryAddress)return this.logger.error("ERROR: bfactoryAddress is null"),null;const e=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress,{from:t}),this.config);let i=null;const r=this.GASLIMIT_DEFAULT;let n;try{n=await e.methods.newBPool().estimateGas({from:t},(t,e)=>t?r:e)}catch(t){this.logger.log("Error estimate gas newBPool"),this.logger.log(t),n=r}try{i=await e.methods.newBPool().send({from:t,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to create new pool: ${t.message}`)}return i}}{constructor(t,e,i=null,r=null,n=null,s){super(t,e,i,n,s),this.poolABI=void 0,this.poolABI=r||_.default.abi}async createPool(t){return await super.createPool(t)}async setup(t,e,i,r,n,s,o,a,h){const u=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let l=null;const c=this.GASLIMIT_DEFAULT;let d;try{d=await u.methods.setup(i,r,n,s,o,a,h).estimateGas({from:t},(t,e)=>t?c:e)}catch(t){d=c}try{l=await u.methods.setup(i,r,n,s,o,a,h).send({from:t,gas:d,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to setup a pool: ${t.message}`)}return l}async allowance(t,e,i){const r=mt(new this.web3.eth.Contract(C.default.abi,t,{from:i}),this.config),n=await r.methods.allowance(e,i).call();return this.web3.utils.fromWei(n)}async approve(t,e,i,r,n=!1){const s=mt(new this.web3.eth.Contract([{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"}],e,{from:t}),this.config);if(!n){const n=await this.allowance(e,t,i);if(new x.default(this.web3.utils.toWei(n)).greaterThanOrEqualTo(r))return n}let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.approve(i,r).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.approve(i,r).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERRPR: Failed to approve spender to spend tokens : ${t.message}`)}return o}async sharesBalance(t,e){let i=null;try{const r=mt(new this.web3.eth.Contract(this.poolABI,e),this.config),n=await r.methods.balanceOf(t).call();i=this.web3.utils.fromWei(n)}catch(t){this.logger.error(`ERROR: Failed to get shares of pool : ${t.message}`)}return i}async addToPool(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let n;for(n of i)try{await this.approve(t,n.address,e,this.web3.utils.toWei(`${n.amount}`)),await r.methods.bind(n.address,this.web3.utils.toWei(n.amount),this.web3.utils.toWei(n.weight)).send({from:t,gas:this.GASLIMIT_DEFAULT,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to add tokens to pool: ${t.message}`)}}async setSwapFee(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let n=null;try{n=await r.methods.setSwapFee(this.web3.utils.toWei(i)).send({from:t,gas:this.GASLIMIT_DEFAULT,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to set pool swap fee: ${t.message}`)}return n}async finalize(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let r=null;try{r=await i.methods.finalize().send({from:t,gas:this.GASLIMIT_DEFAULT,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to finalize pool: ${t.message}`)}return r}async getNumTokens(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getNumTokens().call()}catch(t){this.logger.error(`ERROR: Failed to get number of tokens: ${t.message}`)}return i}async getPoolSharesTotalSupply(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{const t=await e.methods.totalSupply().call();i=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to get total supply of pool shares: ${t.message}`)}return i}async getCurrentTokens(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getCurrentTokens().call()}catch(t){this.logger.error(`ERROR: Failed to get tokens composing this pool: ${t.message}`)}return i}async getFinalTokens(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getFinalTokens().call()}catch(t){this.logger.error("ERROR: Failed to get the final tokens composing this pool")}return i}async getController(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.getController().call()}catch(t){this.logger.error(`ERROR: Failed to get pool controller address: ${t.message}`)}return i}async setController(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let n=null;try{n=await r.methods.setController(i).send({from:t,gas:this.GASLIMIT_DEFAULT})}catch(t){this.logger.error(`ERROR: Failed to set pool controller: ${t.message}`)}return n}async isBound(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let r=null;try{r=await i.methods.isBound(e).call()}catch(t){this.logger.error(`ERROR: Failed to check whether a token bounded to a pool. ${t.message}`)}return r}async getReserve(t,e){let i=null;try{const r=mt(new this.web3.eth.Contract(this.poolABI,t),this.config),n=await r.methods.getBalance(e).call();i=this.web3.utils.fromWei(n)}catch(t){this.logger.error(`ERROR: Failed to get how many tokens are in the pool: ${t.message}`)}return i}async isFinalized(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{i=await e.methods.isFinalized().call()}catch(t){this.logger.error(`ERROR: Failed to check whether pool is finalized: ${t.message}`)}return i}async getSwapFee(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{const t=await e.methods.getSwapFee().call();i=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to get pool fee: ${t.message}`)}return i}async getNormalizedWeight(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let r=null;try{const t=await i.methods.getNormalizedWeight(e).call();r=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to get normalized weight of a token: ${t.message}`)}return r}async getDenormalizedWeight(t,e){const i=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let r=null;try{const t=await i.methods.getDenormalizedWeight(e).call();r=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to get denormalized weight of a token in pool")}return r}async getTotalDenormalizedWeight(t){const e=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let i=null;try{const t=await e.methods.getTotalDenormalizedWeight().call();i=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to get total denormalized weight in pool")}return i}async swapExactAmountIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let h=null;const u=this.GASLIMIT_DEFAULT;let l;try{l=await a.methods.swapExactAmountIn(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).estimateGas({from:t},(t,e)=>t?u:e)}catch(t){this.logger.log("Error estimate gas swapExactAmountIn"),this.logger.log(t),l=u}try{h=await a.methods.swapExactAmountIn(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).send({from:t,gas:l+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to swap exact amount in : ${t.message}`)}return h}async swapExactAmountOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let h=null;const u=this.GASLIMIT_DEFAULT;let l;try{l=await a.methods.swapExactAmountOut(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).estimateGas({from:t},(t,e)=>t?u:e)}catch(t){l=u,this.logger.log("Error estimate gas swapExactAmountIn"),this.logger.log(t)}try{h=await a.methods.swapExactAmountOut(i,this.web3.utils.toWei(r),n,this.web3.utils.toWei(s),o?this.web3.utils.toWei(o):Xe).send({from:t,gas:l+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to swap exact amount out: ${t.message}`)}return h}async joinPool(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config),s=[];let o;for(o of r)s.push(this.web3.utils.toWei(o));let a=null;const h=this.GASLIMIT_DEFAULT;let u;try{u=await n.methods.joinPool(this.web3.utils.toWei(i),s).estimateGas({from:t},(t,e)=>t?h:e)}catch(t){u=h}try{a=await n.methods.joinPool(this.web3.utils.toWei(i),s).send({from:t,gas:u+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to join pool: ${t.message}`)}return a}async exitPool(t,e,i,r){const n=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config),s=[];let o;for(o of r)s.push(this.web3.utils.toWei(o));let a=null;const h=this.GASLIMIT_DEFAULT;let u;try{u=await n.methods.exitPool(this.web3.utils.toWei(i),s).estimateGas({from:t},(t,e)=>t?h:e)}catch(t){u=h}try{a=await n.methods.exitPool(this.web3.utils.toWei(i),s).send({from:t,gas:u,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to exit pool: ${t.message}`)}return a}async joinswapExternAmountIn(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.joinswapExternAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.joinswapExternAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to pay tokens in order to join the pool: ${t.message}`)}return o}async joinswapPoolAmountOut(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.joinswapPoolAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.joinswapPoolAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error("ERROR: Failed to join swap pool amount out")}return o}async exitswapPoolAmountIn(t,e,i,r,n){const s=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let o=null;const a=this.GASLIMIT_DEFAULT;let h;try{h=await s.methods.exitswapPoolAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?a:e)}catch(t){h=a}try{o=await s.methods.exitswapPoolAmountIn(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:h+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to pay pool shares into the pool: ${t.message}`)}return o}async exitswapExternAmountOut(t,e,i,r,n){const s=this.GASLIMIT_DEFAULT,o=mt(new this.web3.eth.Contract(this.poolABI,e,{from:t}),this.config);let a,h=null;try{a=await o.methods.exitswapExternAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).estimateGas({from:t},(t,e)=>t?s:e)}catch(t){a=s}try{h=await o.methods.exitswapExternAmountOut(i,this.web3.utils.toWei(r),this.web3.utils.toWei(n)).send({from:t,gas:a+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error("ERROR: Failed to exitswapExternAmountOut")}return h}async getSpotPrice(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let n=null;try{const t=await r.methods.getSpotPrice(e,i).call();n=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to get spot price of swapping tokenIn to tokenOut")}return n}async getSpotPriceSansFee(t,e,i){const r=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let n=null;try{const t=await r.methods.getSpotPriceSansFee(e,i).call();n=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to getSpotPriceSansFee")}return n}async calcSpotPrice(t,e,i,r,n,s){const o=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let a="0";try{const t=await o.methods.calcSpotPrice(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s)).call();a=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to call calcSpotPrice")}return a}async calcInGivenOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;if(new x.default(s).gte(r))return null;try{const t=await a.methods.calcInGivenOut(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to calcInGivenOut")}return h}async calcOutGivenIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcOutGivenIn(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error("ERROR: Failed to calcOutGivenIn")}return h}async calcPoolOutGivenSingleIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcPoolOutGivenSingleIn(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate PoolOutGivenSingleIn : ${t.message}`)}return h}async calcSingleInGivenPoolOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcSingleInGivenPoolOut(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${t.message}`)}return h}async calcSingleOutGivenPoolIn(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcSingleOutGivenPoolIn(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${t.message}`)}return h}async calcPoolInGivenSingleOut(t,e,i,r,n,s,o){const a=mt(new this.web3.eth.Contract(this.poolABI,t),this.config);let h=null;try{const t=await a.methods.calcPoolInGivenSingleOut(this.web3.utils.toWei(e),this.web3.utils.toWei(i),this.web3.utils.toWei(r),this.web3.utils.toWei(n),this.web3.utils.toWei(s),this.web3.utils.toWei(o)).call();h=this.web3.utils.fromWei(t)}catch(t){this.logger.error(`ERROR: Failed to calculate PoolInGivenSingleOut : ${t.message}`)}return h}getSwapEventSignature(){const t=this.poolABI.find(function(t){if("LOG_SWAP"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}getJoinEventSignature(){const t=this.poolABI.find(function(t){if("LOG_JOIN"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}getExitEventSignature(){const t=this.poolABI.find(function(t){if("LOG_EXIT"===t.name&&"event"===t.type)return t});return this.web3.eth.abi.encodeEventSignature(t)}}{constructor(t,e,i=null,r=null,n=null,s=null,o){super(t,e,i,r,n,o),this.oceanAddress=null,this.dtAddress=null,this.startBlock=void 0,s&&(this.oceanAddress=s),this.startBlock=o&&o.startBlock||0}create(t,e,i,r,n,s){if(null==this.oceanAddress)throw this.logger.error("ERROR: oceanAddress is not defined"),new Error("ERROR: oceanAddress is not defined");if(parseFloat(s)>.1)throw this.logger.error("ERROR: Swap fee too high. The maximum allowed swapFee is 10%"),new Error("ERROR: Swap fee too high. The maximum allowed swapFee is 10%");if(parseFloat(i)<2)throw this.logger.error("ERROR: Amount of DT is too low"),new Error("ERROR: Amount of DT is too low");if(parseFloat(r)>9||parseFloat(r)<1)throw this.logger.error("ERROR: Weight out of bounds (min 1, max9)"),new Error("ERROR: Weight out of bounds (min 1, max9)");return new K(async o=>{o.next(Qe.CreatingPool);const a=await super.createPool(t);if(!a)throw this.logger.error("ERROR: Failed to call create pool"),new Error("ERROR: Failed to call create pool");const h=a.events.BPoolRegistered.returnValues[0],u=10-parseFloat(r);let l;if(this.dtAddress=e,o.next(Qe.ApprovingDatatoken),l=await this.approve(t,e,h,this.web3.utils.toWei(String(i))),!l)throw this.logger.error("ERROR: Failed to call approve DT token"),new Error("ERROR: Failed to call approve DT token");if(o.next(Qe.ApprovingOcean),l=await this.approve(t,this.oceanAddress,h,this.web3.utils.toWei(String(n))),!l)throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");if(o.next(Qe.SetupPool),l=await super.setup(t,h,e,this.web3.utils.toWei(String(i)),this.web3.utils.toWei(String(r)),this.oceanAddress,this.web3.utils.toWei(String(n)),this.web3.utils.toWei(String(u)),this.web3.utils.toWei(s)),!l)throw this.logger.error("ERROR: Failed to create a new pool"),new Error("ERROR: Failed to create a new pool");return a})}async getDTAddress(t){this.dtAddress=null;const e=await this.getCurrentTokens(t);let i;if(null!=e)for(i of e)i.toLowerCase()!==this.oceanAddress.toLowerCase()&&(this.dtAddress=i);return this.dtAddress}async getOceanReserve(t){return null==this.oceanAddress?(this.logger.error("ERROR: oceanAddress is not defined"),null):super.getReserve(t,this.oceanAddress)}async getDTReserve(t){const e=await this.getDTAddress(t);return super.getReserve(t,e)}async getMaxBuyQuantity(t,e){const i=await super.getReserve(t,e);return new x.default(i).div(3).toString()}async getOceanMaxBuyQuantity(t){return this.getMaxBuyQuantity(t,this.oceanAddress)}async getDTMaxBuyQuantity(t){return this.getMaxBuyQuantity(t,await this.getDTAddress(t))}async calcInGivenOut(t,e,i,r){return await super.calcInGivenOut(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getReserve(t,i),await super.getDenormalizedWeight(t,i),r,await this.getSwapFee(t))}async calcOutGivenIn(t,e,i,r){return await super.calcOutGivenIn(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getReserve(t,i),await super.getDenormalizedWeight(t,i),r,await super.getSwapFee(t))}async calcPoolOutGivenSingleIn(t,e,i){return super.calcPoolOutGivenSingleIn(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async calcSingleInGivenPoolOut(t,e,i){return super.calcSingleInGivenPoolOut(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async calcSingleOutGivenPoolIn(t,e,i){return super.calcSingleOutGivenPoolIn(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async calcPoolInGivenSingleOut(t,e,i){return super.calcPoolInGivenSingleOut(t,await super.getReserve(t,e),await super.getDenormalizedWeight(t,e),await super.getPoolSharesTotalSupply(t),await super.getTotalDenormalizedWeight(t),i,await super.getSwapFee(t))}async getPoolSharesRequiredToRemoveDT(t,e){const i=await this.getDTAddress(t);return this.calcPoolInGivenSingleOut(t,i,e)}async getDTRemovedforPoolShares(t,e){const i=await this.getDTAddress(t);return this.calcSingleOutGivenPoolIn(t,i,e)}async getPoolSharesRequiredToRemoveOcean(t,e){return this.calcPoolInGivenSingleOut(t,this.oceanAddress,e)}async getOceanRemovedforPoolShares(t,e){return this.calcSingleOutGivenPoolIn(t,this.oceanAddress,e)}async getTokensRemovedforPoolShares(t,e){try{const i=await this.getPoolSharesTotalSupply(t),r=await this.getDTReserve(t),n=await this.getOceanReserve(t);return{dtAmount:new x.default(e).div(i).mul(r).toString(),oceanAmount:new x.default(e).div(i).mul(n).toString()}}catch(t){this.logger.error(`ERROR: Unable to get token info. ${t.message}`)}}async getDTMaxAddLiquidity(t){const e=await this.getDTAddress(t);return this.getMaxAddLiquidity(t,e)}async getOceanMaxAddLiquidity(t){return this.getMaxAddLiquidity(t,this.oceanAddress)}async getMaxAddLiquidity(t,e){const i=await super.getReserve(t,e);return parseFloat(i)>0?new x.default(i).mul(.25).toString():"0"}async getMaxRemoveLiquidity(t,e){const i=await super.getReserve(t,e);return parseFloat(i)>0?new x.default(i).mul(.25).toString():"0"}async getDTMaxRemoveLiquidity(t){const e=await this.getDTAddress(t);return this.getMaxRemoveLiquidity(t,e)}async getOceanMaxRemoveLiquidity(t){return this.getMaxRemoveLiquidity(t,this.oceanAddress)}async buyDT(t,e,i,r,n){if(null==this.oceanAddress)return this.logger.error("ERROR: undefined ocean token contract address"),null;const s=await this.getDTAddress(e);if(new x.default(i).greaterThan(await this.getDTMaxBuyQuantity(e)))return this.logger.error("ERROR: Buy quantity exceeds quantity allowed"),null;const o=await this.getOceanNeeded(e,i);if(new x.default(o).greaterThan(r))return this.logger.error("ERROR: Not enough Ocean Tokens"),null;if(!await super.approve(t,this.oceanAddress,e,this.web3.utils.toWei(r)))throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");return await super.swapExactAmountOut(t,e,this.oceanAddress,r,s,i,n)}async buyDTWithExactOcean(t,e,i,r,n){if(null==this.oceanAddress)return this.logger.error("ERROR: undefined ocean token contract address"),null;const s=await this.getDTAddress(e);if(new x.default(i).greaterThan(await this.getDTMaxBuyQuantity(e)))return this.logger.error("ERROR: Buy quantity exceeds quantity allowed"),null;const o=await this.getOceanNeeded(e,i);if(new x.default(o).greaterThan(r))return this.logger.error("ERROR: Not enough Ocean Tokens"),null;if(!await super.approve(t,this.oceanAddress,e,this.web3.utils.toWei(r)))throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");return await super.swapExactAmountIn(t,e,this.oceanAddress,r,s,i,n)}async sellDT(t,e,i,r,n){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const s=await this.getDTAddress(e);if(new x.default(r).greaterThan(await this.getOceanMaxBuyQuantity(e)))return this.logger.error("ERROR: Buy quantity exceeds quantity allowed"),null;const o=await this.getOceanReceived(e,i);if(new x.default(o).lessThan(r))return this.logger.error("ERROR: Not enough datatokens"),null;if(!await super.approve(t,s,e,this.web3.utils.toWei(i)))throw this.logger.error("ERROR: Failed to call approve DT token"),new Error("ERROR: Failed to call approve DT token");return await super.swapExactAmountIn(t,e,s,i,this.oceanAddress,r,n)}async addDTLiquidity(t,e,i){const r=await this.getDTAddress(e),n=await this.getMaxAddLiquidity(e,r);if(new x.default(i).greaterThan(n))return this.logger.error("ERROR: Too much reserve to add"),null;if(!await super.approve(t,r,e,this.web3.utils.toWei(i)))throw this.logger.error("ERROR: Failed to call approve DT token"),new Error("ERROR: Failed to call approve DT token");return await super.joinswapExternAmountIn(t,e,r,i,"0")}async removeDTLiquidity(t,e,i,r){const n=await this.getDTAddress(e),s=await this.getDTMaxRemoveLiquidity(e);if(new x.default(i).greaterThan(s))return this.logger.error("ERROR: Too much reserve to remove"),null;const o=await this.sharesBalance(t,e);if(new x.default(o).lessThan(r))return this.logger.error("ERROR: Not enough poolShares"),null;const a=await this.getPoolSharesRequiredToRemoveDT(e,i);return new x.default(r).lessThan(a)?(this.logger.error("ERROR: Not enough poolShares"),null):(new x.default(r).lessThan(a)&&(r=new x.default(r).mul(.9999).toString()),this.exitswapExternAmountOut(t,e,n,i,r))}async addOceanLiquidity(t,e,i){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const r=await this.getOceanMaxAddLiquidity(e);if(new x.default(i).greaterThan(r))return this.logger.error("ERROR: Too much reserve to add"),null;if(!await super.approve(t,this.oceanAddress,e,this.web3.utils.toWei(i)))throw this.logger.error("ERROR: Failed to call approve OCEAN token"),new Error("ERROR: Failed to call approve OCEAN token");return await super.joinswapExternAmountIn(t,e,this.oceanAddress,i,"0")}async removeOceanLiquidityWithMinimum(t,e,i,r){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const n=await this.sharesBalance(t,e);return new x.default(n).lessThan(i)?(this.logger.error("ERROR: Not enough poolShares"),null):super.exitswapPoolAmountIn(t,e,this.oceanAddress,i,r)}async removeOceanLiquidity(t,e,i,r){if(null==this.oceanAddress)return this.logger.error("ERROR: oceanAddress is not defined"),null;const n=await this.getOceanMaxRemoveLiquidity(e);if(new x.default(i).greaterThan(n))return this.logger.error("ERROR: Too much reserve to remove"),null;const s=await this.sharesBalance(t,e);if(new x.default(s).lessThan(r))return this.logger.error("ERROR: Not enough poolShares"),null;const o=await this.getPoolSharesRequiredToRemoveOcean(e,i);return new x.default(r).lessThan(o)?(this.logger.error("ERROR: Not enough poolShares"),null):(new x.default(r).lessThan(o)&&(r=new x.default(r).mul(.9999).toString()),super.exitswapExternAmountOut(t,e,this.oceanAddress,i,r))}async removePoolLiquidity(t,e,i,r="0",n="0"){const s=await this.sharesBalance(t,e);return new x.default(s).lessThan(i)?(this.logger.error("ERROR: Not enough poolShares"),null):(new x.default(s).equals(i)&&(i=new x.default(i).mul(.9999).toString()),this.exitPool(t,e,i,[r,n]))}async getDTPrice(t){return null==this.oceanAddress?(this.logger.error("ERROR: oceanAddress is not defined"),"0"):this.getOceanNeeded(t,"1")}async searchPoolforDT(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});r.sort((t,e)=>t.blockNumber>e.blockNumber?1:-1);for(let i=0;i<r.length;i++)(await super.getCurrentTokens(r[i].returnValues[0])).includes(t)&&e.push(r[i].returnValues[0]);return e}async getOceanNeeded(t,e){const i=await this.getDTAddress(t);return new x.default(e).greaterThan(await this.getDTMaxBuyQuantity(t))?"0":this.calcInGivenOut(t,this.oceanAddress,i,e)}async getOceanReceived(t,e){const i=await this.getDTAddress(t);return this.calcOutGivenIn(t,i,this.oceanAddress,e)}async getDTReceived(t,e){const i=await this.getDTAddress(t);return this.calcOutGivenIn(t,this.oceanAddress,i,e)}async getDTNeeded(t,e){const i=await this.getDTAddress(t);return new x.default(e).greaterThan(await this.getOceanMaxBuyQuantity(t))?"0":this.calcInGivenOut(t,i,this.oceanAddress,e)}async getPoolsbyCreator(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:t?{registeredBy:t}:{},fromBlock:this.startBlock,toBlock:"latest"});for(let i=0;i<r.length;i++)t&&r[i].returnValues[1].toLowerCase()!==t.toLowerCase()||e.push(await this.getPoolDetails(r[i].returnValues[0]));return e}async getResult(t,e){const i=await super.sharesBalance(t,e.returnValues[0]);if(parseFloat(i)>0){const t=await this.getDTAddress(e.returnValues[0]);if(t)return{shares:i,poolAddress:e.returnValues[0],did:G(Z(t))}}}async getPoolSharesByAddress(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});let n=[];for(let i=0;i<r.length;i++)if(n.push(this.getResult(t,r[i])),n.length>10){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}if(n.length>0){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}return e.filter(t=>void 0!==t)}async getPoolDetails(t){return{poolAddress:t,tokens:await super.getFinalTokens(t)}}async getPoolLogs(t,e=0,i){const r=[],n=await this.getDTAddress(t);0===e&&(e=this.startBlock);const s=super.getSwapEventSignature(),o=super.getJoinEventSignature(),a=super.getExitEventSignature();let h;h=i?"0x000000000000000000000000"+i.substring(2).toLowerCase():null;const u=await this.web3.eth.getPastLogs({address:t,topics:[[s,o,a],h],fromBlock:e,toBlock:"latest"});let l=[];for(let e=0;e<u.length;e++)if(l.push(this.getEventData(t,n,u[e])),l.length>10){const t=await Promise.all(l);for(let e=0;e<t.length;e++)r.push(t[e]);l=[]}if(l.length>0){const t=await Promise.all(l);for(let e=0;e<t.length;e++)r.push(t[e]);l=[]}return r.filter(t=>void 0!==t)}async getAllPoolLogs(t){const e=[],i=mt(new this.web3.eth.Contract(this.factoryABI,this.factoryAddress),this.config),r=await i.getPastEvents("BPoolRegistered",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});let n=[];for(let i=0;i<r.length;i++)if(n.push(this.getPoolLogs(r[i].returnValues[0],r[i].blockNumber,t)),n.length>10){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}if(n.length>0){const t=await Promise.all(n);for(let i=0;i<t.length;i++)e.push(t[i]);n=[]}return e.reduce((t,e)=>t.concat(e))}async getEventData(t,e,i){const r=await this.web3.eth.getBlock(i.blockNumber),n=super.getSwapEventSignature(),s=super.getJoinEventSignature(),o=super.getExitEventSignature();let a;switch(i.topics[0]){case n:a="swap";break;case s:a="join";break;case o:a="exit"}let h,u={poolAddress:t,dtAddress:e,caller:i.topics[1],transactionHash:i.transactionHash,blockNumber:i.blockNumber,timestamp:parseInt(String(r.timestamp)),type:a};switch(a){case"swap":h=this.web3.eth.abi.decodeParameters(["uint256","uint256"],i.data),u=W({},u,{tokenIn:"0x"+i.topics[2].substring(i.topics[2].length-40),tokenOut:"0x"+i.topics[3].substring(i.topics[3].length-40),tokenAmountIn:this.web3.utils.fromWei(h[0]),tokenAmountOut:this.web3.utils.fromWei(h[1])});break;case"join":h=this.web3.eth.abi.decodeParameters(["uint256"],i.data),u=W({},u,{tokenIn:"0x"+i.topics[2].substring(i.topics[2].length-40),tokenAmountIn:this.web3.utils.fromWei(h[0])});break;case"exit":h=this.web3.eth.abi.decodeParameters(["uint256"],i.data),u=W({},u,{tokenOut:"0x"+i.topics[2].substring(i.topics[2].length-40),tokenAmountOut:this.web3.utils.fromWei(h[0])})}return u}async computeSlippage(t,e,i,r,n,s,o,a){const h=await super.calcSpotPrice(t,e,i,r,n,a),u=await super.calcSpotPrice(t,s,i,o,n,a);return new x.default(u).mul(100).div(h).minus(100).toString()}async computeBuySlippage(t,e){const i=await this.getDTAddress(t),r=await super.getDenormalizedWeight(t,i),n=await super.getDenormalizedWeight(t,this.oceanAddress),s=await super.getReserve(t,i),o=await super.getReserve(t,i),a=await super.getSwapFee(t),h=await super.calcOutGivenIn(t,o,n,s,r,e,a),u=new dt(this.web3.utils.toWei(s)).minus(this.web3.utils.toWei(h)),l=new dt(this.web3.utils.toWei(o)).plus(this.web3.utils.toWei(e));return await this.computeSlippage(t,o,n,s,r,this.web3.utils.fromWei(l.toString()),this.web3.utils.fromWei(u.toString()),a)}async computeSellSlippage(t,e){const i=await this.getDTAddress(t),r=await super.getDenormalizedWeight(t,i),n=await super.getDenormalizedWeight(t,this.oceanAddress),s=await super.getReserve(t,i),o=await super.getReserve(t,i),a=await super.getSwapFee(t),h=await super.calcOutGivenIn(t,s,r,o,n,e,a),u=new dt(this.web3.utils.toWei(s)).plus(this.web3.utils.toWei(e)),l=new dt(this.web3.utils.toWei(o)).minus(this.web3.utils.toWei(h));return await this.computeSlippage(t,s,r,o,n,this.web3.utils.fromWei(u.toString()),this.web3.utils.fromWei(l.toString()),a)}}!function(t){t[t.CreatingExchange=0]="CreatingExchange",t[t.ApprovingDatatoken=1]="ApprovingDatatoken"}(Ye||(Ye={}));class ri{constructor(t,e,i=null,r=null,n=null,s,o){this.GASLIMIT_DEFAULT=1e6,this.oceanAddress=null,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeABI=void 0,this.web3=void 0,this.contract=null,this.logger=void 0,this.datatokens=void 0,this.startBlock=void 0,this.config=void 0,this.web3=t,this.fixedRateExchangeAddress=i,this.config=o,this.startBlock=o&&o.startBlock||0,this.fixedRateExchangeABI=r||D.default.abi,this.oceanAddress=n,this.datatokens=s,t&&(this.contract=mt(new this.web3.eth.Contract(this.fixedRateExchangeABI,this.fixedRateExchangeAddress),this.config)),this.logger=e}create(t,e,i,r){return this.createExchange(this.oceanAddress,t,e,i,r)}createExchange(t,e,i,r,n){return new K(async s=>{let o;s.next(Ye.CreatingExchange);const a=this.GASLIMIT_DEFAULT;try{o=await this.contract.methods.create(t,e,this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?a:e)}catch(t){o=a}let h=null,u=null;try{u=await this.contract.methods.create(t,e,this.web3.utils.toWei(i)).send({from:r,gas:o+1,gasPrice:await ft(this.web3,this.config)}),h=u.events.ExchangeCreated.returnValues[0]}catch(t){this.logger.error(`ERROR: Failed to create new exchange: ${t.message}`)}return n&&h&&(s.next(Ye.ApprovingDatatoken),this.datatokens.approve(e,this.fixedRateExchangeAddress,n,r)),u})}async generateExchangeId(t,e){return await this.contract.methods.generateExchangeId(this.oceanAddress,t,e).call()}async buyDT(t,e,i){const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.swap(t,this.web3.utils.toWei(String(e))).estimateGas({from:i},(t,e)=>t?r:e)}catch(t){n=r}try{return await this.contract.methods.swap(t,this.web3.utils.toWei(String(e))).send({from:i,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){return this.logger.error(`ERROR: Failed to buy datatokens: ${t.message}`),null}}async getNumberOfExchanges(){return await this.contract.methods.getNumberOfExchanges().call()}async setRate(t,e,i){const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.setRate(t,this.web3.utils.toWei(String(e))).estimateGas({from:i},(t,e)=>t?r:e)}catch(t){n=r}return await this.contract.methods.setRate(t,this.web3.utils.toWei(String(e))).send({from:i,gas:n+1,gasPrice:await ft(this.web3,this.config)})}async activate(t,e){const i=await this.getExchange(t);if(!i)return null;if(!0===i.active)return null;const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.toggleExchangeState(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){n=r}return await this.contract.methods.toggleExchangeState(t).send({from:e,gas:n+1,gasPrice:await ft(this.web3,this.config)})}async deactivate(t,e){const i=await this.getExchange(t);if(!i)return null;if(!1===i.active)return null;const r=this.GASLIMIT_DEFAULT;let n;try{n=await this.contract.methods.toggleExchangeState(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){n=r}return await this.contract.methods.toggleExchangeState(t).send({from:e,gas:n+1,gasPrice:await ft(this.web3,this.config)})}async getRate(t){const e=await this.contract.methods.getRate(t).call();return this.web3.utils.fromWei(e)}async getSupply(t){const e=await this.contract.methods.getSupply(t).call();return this.web3.utils.fromWei(e)}async getOceanNeeded(t,e){const i=await this.contract.methods.CalcInGivenOut(t,this.web3.utils.toWei(e)).call();return this.web3.utils.fromWei(i)}async getExchange(t){const e=await this.contract.methods.getExchange(t).call();return e.fixedRate=this.web3.utils.fromWei(e.fixedRate),e.supply=this.web3.utils.fromWei(e.supply),e.exchangeID=t,e}async getExchanges(){return await this.contract.methods.getExchanges().call()}async isActive(t){return await this.contract.methods.isActive(t).call()}async CalcInGivenOut(t,e){const i=await this.contract.methods.CalcInGivenOut(t,this.web3.utils.toWei(e)).call();return this.web3.utils.fromWei(i)}async searchforDT(t,e){const i=[],r=await this.contract.getPastEvents("ExchangeCreated",{filter:{datatoken:t.toLowerCase()},fromBlock:this.startBlock,toBlock:"latest"});let n=[];for(let s=0;s<r.length;s++)if(n.push(this.getExchange(r[s].returnValues[0])),n.length>10||s===r.length-1){const r=await Promise.all(n);for(let n=0;n<r.length;n++){const s=r[n];if(!0===s.active&&s.dataToken.toLowerCase()===t.toLowerCase()){const t=new dt(s.supply),r=new dt(e);t.gte(r)&&i.push(s)}}n=[]}return i}async getExchangesbyCreator(t){const e=[],i=await this.contract.getPastEvents("ExchangeCreated",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});for(let r=0;r<i.length;r++)t&&i[r].returnValues[3].toLowerCase()!==t.toLowerCase()||e.push(await this.getExchange(i[r].returnValues[0]));return e}async getExchangeSwaps(t,e){const i=[],r=await this.contract.getPastEvents("Swapped",{filter:{exchangeId:t},fromBlock:this.startBlock,toBlock:"latest"});for(let t=0;t<r.length;t++)e&&r[t].returnValues[1].toLowerCase()!==e.toLowerCase()||i.push(this.getEventData(r[t]));return i}async getAllExchangesSwaps(t){const e=[],i=await this.contract.getPastEvents("ExchangeCreated",{filter:{},fromBlock:this.startBlock,toBlock:"latest"});for(let r=0;r<i.length;r++)(await this.getExchangeSwaps(i[r].returnValues[0],t)).forEach(t=>{e.push(t)});return e}getEventData(t){return{exchangeID:t.returnValues[0],caller:t.returnValues[1],baseTokenAmount:this.web3.utils.fromWei(t.returnValues[2]),dataTokenAmount:this.web3.utils.fromWei(t.returnValues[3])}}}!function(t){t[t.MakeDispenserMinter=0]="MakeDispenserMinter",t[t.AcceptingNewMinter=1]="AcceptingNewMinter"}(ti||(ti={})),function(t){t[t.MakeOwnerMinter=0]="MakeOwnerMinter",t[t.AcceptingNewMinter=1]="AcceptingNewMinter"}(ei||(ei={}));class ni{constructor(t,e,i=null,r=null,n,s){this.GASLIMIT_DEFAULT=1e6,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.web3=void 0,this.contract=null,this.logger=void 0,this.datatokens=void 0,this.startBlock=void 0,this.config=void 0,this.web3=t,this.config=s,this.dispenserAddress=i,this.startBlock=s&&s.startBlock||0,this.dispenserABI=r||L.default.abi,this.datatokens=n,t&&(this.contract=mt(new this.web3.eth.Contract(this.dispenserABI,this.dispenserAddress),this.config)),this.logger=e}async status(t){try{const e=await this.contract.methods.status(t).call();return e.maxTokens=this.web3.utils.fromWei(e.maxTokens),e.maxBalance=this.web3.utils.fromWei(e.maxBalance),e.balance=this.web3.utils.fromWei(e.balance),e}catch(e){this.logger.warn(`No dispenser available for data token: ${t}`)}return null}async activate(t,e,i,r){let n;const s=this.GASLIMIT_DEFAULT;try{n=await this.contract.methods.activate(t,this.web3.utils.toWei(e),this.web3.utils.toWei(i)).estimateGas({from:r},(t,e)=>t?s:e)}catch(t){n=s}let o=null;try{o=await this.contract.methods.activate(t,this.web3.utils.toWei(e),this.web3.utils.toWei(i)).send({from:r,gas:n+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to activate dispenser: ${t.message}`)}return o}async deactivate(t,e){let i;const r=this.GASLIMIT_DEFAULT;try{i=await this.contract.methods.deactivate(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){i=r}let n=null;try{n=await this.contract.methods.deactivate(t).send({from:e,gas:i+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to deactivate dispenser: ${t.message}`)}return n}makeMinter(t,e){return new K(async i=>{let r;i.next(ti.MakeDispenserMinter);const n=this.GASLIMIT_DEFAULT;if(!await this.datatokens.proposeMinter(t,this.dispenserAddress,e))return null;i.next(ti.AcceptingNewMinter);try{r=await this.contract.methods.acceptMinter(t).estimateGas({from:e},(t,e)=>t?n:e)}catch(t){r=n}let s=null;try{s=await this.contract.methods.acceptMinter(t).send({from:e,gas:r+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to accept minter role: ${t.message}`)}return s})}cancelMinter(t,e){return new K(async i=>{let r;i.next(ei.MakeOwnerMinter);const n=this.GASLIMIT_DEFAULT;try{r=await this.contract.methods.removeMinter(t).estimateGas({from:e},(t,e)=>t?n:e)}catch(t){r=n}let s=null;try{s=await this.contract.methods.removeMinter(t).send({from:e,gas:r+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to remove minter role: ${t.message}`)}return s?(i.next(ei.AcceptingNewMinter),await this.datatokens.approveMinter(t,e)):null})}async dispense(t,e,i="1"){let r;const n=this.GASLIMIT_DEFAULT;try{r=await this.contract.methods.dispense(t,this.web3.utils.toWei(i)).estimateGas({from:e},(t,e)=>t?n:e)}catch(t){r=n}let s=null;try{s=await this.contract.methods.dispense(t,this.web3.utils.toWei(i)).send({from:e,gas:r+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to dispense tokens: ${t.message}`)}return s}async ownerWithdraw(t,e){let i;const r=this.GASLIMIT_DEFAULT;try{i=await this.contract.methods.ownerWithdraw(t).estimateGas({from:e},(t,e)=>t?r:e)}catch(t){i=r}let n=null;try{n=await this.contract.methods.ownerWithdraw(t).send({from:e,gas:i+1,gasPrice:await ft(this.web3,this.config)})}catch(t){this.logger.error(`ERROR: Failed to withdraw tokens: ${t.message}`)}return n}async isDispensable(t,e,i="1"){const r=await this.status(t);return!(!r||!1===r.active||new x.default(await this.datatokens.balance(t,e)).greaterThanOrEqualTo(r.maxBalance)||new x.default(String(i)).greaterThan(r.maxTokens)||!new x.default(r.balance).greaterThanOrEqualTo(i)&&!0!==r.isTrueMinter)}}class si extends Mt{constructor(...t){super(...t),this.network=void 0,this.provider=void 0,this.eventAccessControl=void 0,this.web3Provider=void 0,this.metadataCache=void 0,this.onChainMetadata=void 0,this.accounts=void 0,this.assets=void 0,this.compute=void 0,this.datatokens=void 0,this.pool=void 0,this.fixedRateExchange=void 0,this.OceanDispenser=void 0,this.versions=void 0,this.utils=void 0}static async getInstance(t){var e;const i=new si,r=W({},function(t){return{config:t,web3:t.web3Provider,logger:U}}(t),{ocean:i});return i.setInstanceConfig(r),i.utils=await je.getInstance(r),i.provider=await Tt.getInstance(r),i.eventAccessControl=await Fe.getInstance(r),i.metadataCache=new ze(r.config.metadataCacheUri,r.logger,null==(e=r.config)?void 0:e.requestTimeout),i.accounts=await xt.getInstance(r),i.assets=await Ue.getInstance(r),i.compute=await Ke.getInstance(r),i.datatokens=new Ze(r.config.factoryAddress,r.config.factoryABI,r.config.datatokensABI,r.config.web3Provider,r.logger,r.config),i.pool=new ii(r.config.web3Provider,r.logger,r.config.poolFactoryABI,r.config.poolABI,r.config.poolFactoryAddress,r.config.oceanTokenAddress,r.config),i.fixedRateExchange=new ri(r.config.web3Provider,r.logger,r.config.fixedRateExchangeAddress,r.config.fixedRateExchangeAddressABI,r.config.oceanTokenAddress,i.datatokens,r.config),i.OceanDispenser=new ni(r.config.web3Provider,r.logger,r.config.dispenserAddress,r.config.dispenserABI,i.datatokens,r.config),i.onChainMetadata=new He(r.config.web3Provider,r.logger,r.config.metadataContractAddress,r.config.metadataContractABI,i.metadataCache,r.config),i.versions=await qe.getInstance(r),i.network=new Ve,i}}const oi={networkId:null,network:"unknown",metadataCacheUri:"https://aquarius.oceanprotocol.com",nodeUri:"http://localhost:8545",providerUri:"http://127.0.0.1:8030",subgraphUri:null,explorerUri:null,oceanTokenAddress:null,oceanTokenSymbol:"OCEAN",factoryAddress:"0x1234",poolFactoryAddress:null,fixedRateExchangeAddress:null,dispenserAddress:null,metadataContractAddress:null,startBlock:0,transactionBlockTimeout:50,transactionConfirmationBlocks:1,transactionPollingTimeout:750,gasFeeMultiplier:1},ai=[W({},oi),W({},oi,{networkId:8996,network:"development",metadataCacheUri:"http://127.0.0.1:5000",rbacUri:"http://127.0.0.1:3000"}),W({},oi,{networkId:3,network:"ropsten",nodeUri:"https://ropsten.infura.io/v3",providerUri:"https://provider.ropsten.oceanprotocol.com",subgraphUri:"https://subgraph.ropsten.oceanprotocol.com",explorerUri:"https://ropsten.etherscan.io",startBlock:9227563}),W({},oi,{networkId:4,network:"rinkeby",nodeUri:"https://rinkeby.infura.io/v3",providerUri:"https://provider.rinkeby.oceanprotocol.com",subgraphUri:"https://subgraph.rinkeby.oceanprotocol.com",explorerUri:"https://rinkeby.etherscan.io",startBlock:7294090}),W({},oi,{networkId:1,network:"mainnet",nodeUri:"https://mainnet.infura.io/v3",providerUri:"https://provider.mainnet.oceanprotocol.com",subgraphUri:"https://subgraph.mainnet.oceanprotocol.com",explorerUri:"https://etherscan.io",startBlock:11105459,transactionBlockTimeout:150,transactionConfirmationBlocks:5,transactionPollingTimeout:1750,gasFeeMultiplier:1.05}),W({},oi,{networkId:137,network:"polygon",nodeUri:"https://polygon-mainnet.infura.io/v3",providerUri:"https://provider.polygon.oceanprotocol.com",subgraphUri:"https://subgraph.polygon.oceanprotocol.com",explorerUri:"https://polygonscan.com",oceanTokenSymbol:"mOCEAN",startBlock:11005222,gasFeeMultiplier:1.05}),W({},oi,{networkId:1287,network:"moonbeamalpha",nodeUri:"https://rpc.testnet.moonbeam.network",providerUri:"https://provider.moonbeamalpha.oceanprotocol.com",subgraphUri:"https://subgraph.moonbeamalpha.oceanprotocol.com",explorerUri:"https://moonbase-blockscout.testnet.moonbeam.network/",startBlock:90707}),W({},oi,{networkId:2021e3,network:"gaiaxtestnet",nodeUri:"https://rpc.gaiaxtestnet.oceanprotocol.com",providerUri:"https://provider.gaiaxtestnet.oceanprotocol.com",subgraphUri:"https://subgraph.gaiaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.gaiaxtestnet.oceanprotocol.com"}),W({},oi,{networkId:2021001,network:"catenaxtestnet",nodeUri:"https://rpc.catenaxtestnet.oceanprotocol.com",providerUri:"https://provider.catenaxtestnet.oceanprotocol.com",subgraphUri:"https://subgraph.catenaxtestnet.oceanprotocol.com",explorerUri:"https://blockscout.catenaxtestnet.oceanprotocol.com",metadataCacheUri:"https://aquarius.catenaxtestnet.oceanprotocol.com"}),W({},oi,{networkId:80001,network:"mumbai",nodeUri:"https://polygon-mumbai.infura.io/v3",providerUri:"https://provider.mumbai.oceanprotocol.com",subgraphUri:"https://subgraph.mumbai.oceanprotocol.com",explorerUri:"https://mumbai.polygonscan.com"}),W({},oi,{networkId:56,network:"bsc",nodeUri:"https://bsc-dataseed.binance.org",providerUri:"https://provider.bsc.oceanprotocol.com",subgraphUri:"https://subgraph.bsc.oceanprotocol.com",explorerUri:"https://bscscan.com/",gasFeeMultiplier:1.05}),W({},oi,{networkId:44787,network:"celoalfajores",nodeUri:"https://alfajores-forno.celo-testnet.org",providerUri:"https://provider.celoalfajores.oceanprotocol.com",subgraphUri:"https://subgraph.celoalfajores.oceanprotocol.com",explorerUri:"https://alfajores-blockscout.celo-testnet.org"}),W({},oi,{networkId:246,network:"energyweb",nodeUri:"https://rpc.energyweb.org",providerUri:"https://provider.energyweb.oceanprotocol.com",subgraphUri:"https://subgraph.energyweb.oceanprotocol.com",explorerUri:"https://explorer.energyweb.org",gasFeeMultiplier:1.05}),W({},oi,{networkId:1285,network:"moonriver",nodeUri:"https://moonriver.api.onfinality.io/public",providerUri:"https://provider.moonriver.oceanprotocol.com",subgraphUri:"https://subgraph.moonriver.oceanprotocol.com",explorerUri:"https://blockscout.moonriver.moonbeam.network",gasFeeMultiplier:1.05})];exports.Account=bt,exports.Config=class{constructor(){this.nodeUri=void 0,this.providerAddress=void 0,this.metadataCacheUri=void 0,this.providerUri=void 0,this.rbacUri=void 0,this.web3Provider=void 0,this.oceanTokenAddress=void 0,this.factoryAddress=void 0,this.factoryABI=void 0,this.datatokensABI=void 0,this.poolFactoryAddress=void 0,this.poolFactoryABI=void 0,this.poolABI=void 0,this.fixedRateExchangeAddress=void 0,this.fixedRateExchangeAddressABI=void 0,this.dispenserAddress=void 0,this.dispenserABI=void 0,this.metadataContractAddress=void 0,this.metadataContractABI=void 0,this.startBlock=void 0,this.verbose=void 0,this.authMessage=void 0,this.authTokenExpiration=void 0,this.parityUri=void 0,this.threshold=void 0,this.requestTimeout=void 0}},exports.ConfigHelper=class{getAddressesFromEnv(t){let e;if(N.default[t]){const{DTFactory:i,BFactory:r,FixedRateExchange:n,Dispenser:s,Metadata:o,Ocean:a,chainId:h,startBlock:u}=N.default[t];e=W({factoryAddress:i,poolFactoryAddress:r,fixedRateExchangeAddress:n,dispenserAddress:s,metadataContractAddress:o,oceanTokenAddress:a,networkId:h,startBlock:u},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}if(R.default&&process.env.ADDRESS_FILE)try{const i=JSON.parse(R.default.readFileSync(process.env.ADDRESS_FILE||`${y.homedir}/.ocean/ocean-contracts/artifacts/address.json`,"utf8")),{DTFactory:r,BFactory:n,FixedRateExchange:s,Dispenser:o,Metadata:a,Ocean:h,chainId:u,startBlock:l}=i[t];e=W({factoryAddress:r,poolFactoryAddress:n,fixedRateExchangeAddress:s,dispenserAddress:o,metadataContractAddress:a,oceanTokenAddress:h,networkId:u,startBlock:l},process.env.AQUARIUS_URI&&{metadataCacheUri:process.env.AQUARIUS_URI})}catch(t){}return e}getConfig(t,e){const i="string"==typeof t?"network":"networkId";let r=ai.find(e=>e[i]===t);return r?(r=W({},r,this.getAddressesFromEnv(r.network)),W({},r,{nodeUri:e?`${r.nodeUri}/${e}`:r.nodeUri})):(U.error(`No config found for given network '${t}'`),null)}},exports.DDO=Rt,exports.DID=At,exports.DataTokens=Ze,exports.Logger=U,exports.MetadataCache=ze,exports.Ocean=si,exports.Provider=Tt,exports.utils=yt;
|
|
2
2
|
//# sourceMappingURL=lib.js.map
|