@metamask/ethjs-query
Version:
A simple query layer for the Ethereum RPC.
1 lines • 85.9 kB
JavaScript
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("Eth",[],r):"object"==typeof exports?exports.Eth=r():t.Eth=r()}("undefined"!=typeof self?self:this,function(){return function(t){function r(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}var e={};return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},r.n=function(t){var e=t&&t.__esModule?function(){return t["default"]}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},r.p="",r(r.s=4)}([function(t,r,e){var i=e(2);t.exports=function(t){return"string"!=typeof t?t:i(t)?t.slice(2):t}},function(t,r){var e;e=function(){return this}();try{e=e||Function("return this")()||(0,eval)("this")}catch(i){"object"==typeof window&&(e=window)}t.exports=e},function(t,r){t.exports=function(t){if("string"!=typeof t)throw Error("[is-hex-prefixed] value must be type 'string', is currently type "+typeof t+", while checking isHexPrefixed.");return"0x"===t.slice(0,2)}},function(t,r,e){"use strict";var i=e(17),n=e(18);t.exports=function(t){if(!i(t.then))throw new TypeError("Expected a promise");return function(r){t.then(function(t){n(r,null,t)},function(t){n(r,t)})}}},function(t,r,e){"use strict";function i(t,r){var e=this,n=r||{};if(!(this instanceof i))throw Error('[ethjs-query] the Eth object requires the "new" flag in order to function normally (i.e. `const eth = new Eth(provider);`).');if("object"!=typeof t)throw Error("[ethjs-query] the Eth object requires that the first input 'provider' must be an object, got '"+typeof t+"' (i.e. 'const eth = new Eth(provider);')");e.options=Object.assign({debug:n.debug||!1,logger:n.logger||console,jsonSpace:n.jsonSpace||0}),e.rpc=new s(t),e.setProvider=e.rpc.setProvider}function n(t,r){return function(){function e(){var e=this;return new Promise(function(i,h){if(r[2]>u.length)return void h(Error("[ethjs-query] method '"+a+"' requires at least "+r[2]+" input (format type "+r[0][0]+"), "+u.length+" provided. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#"+t.toLowerCase()));if(u.length>r[0].length)return void h(Error("[ethjs-query] method '"+a+"' requires at most "+r[0].length+" params, "+u.length+" provided '"+JSON.stringify(u,null,s.options.jsonSpace)+"'. For more information visit: https://github.com/ethereum/wiki/wiki/JSON-RPC#"+t.toLowerCase()));r[3]&&r[3]>u.length&&u.push("latest"),e.log("attempting method formatting for '"+a+"' with inputs "+JSON.stringify(u,null,e.options.jsonSpace));try{n=o.formatInputs(t,u),e.log("method formatting success for '"+a+"' with formatted result: "+JSON.stringify(n,null,e.options.jsonSpace))}catch(f){return void h(Error("[ethjs-query] while formatting inputs '"+JSON.stringify(u,null,e.options.jsonSpace)+"' for method '"+a+"' error: "+f))}e.rpc.sendAsync({method:t,params:n}).then(function(r){e.log("attempting method formatting for '"+a+"' with raw outputs: "+JSON.stringify(r,null,e.options.jsonSpace));var n=o.formatOutputs(t,r);e.log("method formatting success for '"+a+"' formatted result: "+JSON.stringify(n,null,e.options.jsonSpace)),i(n)})["catch"](function(t){h(t)})})}var i=null,n=null,s=this,u=[].slice.call(arguments),a=t.replace("eth_","");u.length>0&&"function"==typeof u[u.length-1]&&(i=u.pop());var f=e.call(this);return i?h(f)(i):f}}var o=e(5),s=e(16),h=e(3);t.exports=i,i.prototype.log=function(t){var r=this;r.options.debug&&r.options.logger.log("[ethjs-query log] "+t)},Object.keys(o.schema.methods).forEach(function(t){Object.defineProperty(i.prototype,t.replace("eth_",""),{enumerable:!0,value:n(t,o.schema.methods[t])})})},function(t,r,e){"use strict";function i(t,r,e){if(-1===["string","number","object"].indexOf(typeof t)||null===t)return t;var i=l(t),n=e&&i.toString(16).length%2?"0":"";if(l(t).isNeg())throw Error("[ethjs-format] while formatting quantity '"+i.toString(10)+"', invalid negative number. Number must be positive or zero.");return r?"0x"+n+i.toString(16):i}function n(t,r){var e=t;return-1===c.tags.indexOf(t)&&(e=i(t,r)),e}function o(t,r){var e=t,i=0;if("string"==typeof t&&(e="0x"+g(y(t)),i=d(e)),"0x00"===e&&(e="0x0"),"number"==typeof r&&null!==t&&"0x"!==e&&"0x0"!==e&&(!/^[0-9A-Fa-f]+$/.test(y(e))||i!==2+2*r))throw Error("[ethjs-format] hex string '"+e+"' must be an alphanumeric "+(2+2*r)+" utf8 byte hex (chars: a-fA-F) string, is "+i+" bytes");return e}function s(t,r,e){var i=Object.assign({},r),n=null;if("string"==typeof t&&(n="Boolean|EthSyncing"===t?Object.assign({},c.objects.EthSyncing):"DATA|Transaction"===t?Object.assign({},c.objects.Transaction):Object.assign({},c.objects[t])),!m(Object.keys(r),n.__required))throw Error("[ethjs-format] object "+JSON.stringify(r)+" must contain properties: "+n.__required.join(", "));return Object.keys(n).forEach(function(t){"__required"!==t&&"undefined"!=typeof r[t]&&(i[t]=u(n[t],r[t],e))}),i}function h(t,r,e,i){var n=r.slice(),o=t;if("Array|DATA"===t&&(o=["D"]),"FilterChange"===t&&"string"==typeof r[0]&&(o=["D32"]),!0===e&&"number"==typeof i&&i>r.length)throw Error("array "+JSON.stringify(r)+" must contain at least "+i+" params, but only contains "+r.length+".");return o=o.slice(),r.forEach(function(t,r){var i=0;o.length>1&&(i=r),n[r]=u(o[i],t,e)}),n}function u(t,r,e,u){var a=r;return"Q"===t?a=i(r,e):"QP"===t?a=i(r,e,!0):"Q|T"===t?a=n(r,e):"D"===t?a=o(r):"D20"===t?a=o(r,20):"D32"===t?a=o(r,32):"object"==typeof r&&null!==r&&!1===Array.isArray(r)?a=s(t,r,e):Array.isArray(r)&&(a=h(t,r,e,u)),a}function a(t,r){return u(c.methods[t][0],r,!0,c.methods[t][2])}function f(t,r){return u(c.methods[t][1],r,!1)}var l=e(6),c=e(10),p=e(11),m=p.arrayContainsArray,d=p.getBinarySize,g=p.padToEven,y=e(0);t.exports={schema:c,formatQuantity:i,formatQuantityOrTag:n,formatObject:s,formatArray:h,format:u,formatInputs:a,formatOutputs:f}},function(t,r,e){var i=e(7),n=e(0);t.exports=function(t){if("string"==typeof t||"number"==typeof t){var r=new i(1),e=(t+"").toLowerCase().trim(),o="0x"===e.substr(0,2)||"-0x"===e.substr(0,3),s=n(e);if("-"===s.substr(0,1)&&(s=n(s.slice(1)),r=new i(-1,10)),s=""===s?"0":s,!s.match(/^-?[0-9]+$/)&&s.match(/^[0-9A-Fa-f]+$/)||s.match(/^[a-fA-F]+$/)||!0===o&&s.match(/^[0-9A-Fa-f]+$/))return new i(s,16).mul(r);if((s.match(/^-?[0-9]+$/)||""===s)&&!1===o)return new i(s,10).mul(r)}else if("object"==typeof t&&t.toString&&!t.pop&&!t.push&&t.toString(10).match(/^-?[0-9]+$/)&&(t.mul||t.dividedToIntegerBy))return new i(t.toString(10),10);throw 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.")}},function(t,r,e){(function(t){!function(t,r){"use strict";function i(t,r){if(!t)throw Error(r||"Assertion failed")}function n(t,r){t.super_=r;var e=function(){};e.prototype=r.prototype,t.prototype=new e,t.prototype.constructor=t}function o(t,r,e){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==r&&"be"!==r||(e=r,r=10),this._init(t||0,r||10,e||"be"))}function s(t,r){var e=t.charCodeAt(r);return 48>e||e>57?65>e||e>70?97>e||e>102?void i(!1,"Invalid character in "+t):e-87:e-55:e-48}function h(t,r,e){var i=s(t,e);return r>e-1||(i|=s(t,e-1)<<4),i}function u(t,r,e,n){for(var o=0,s=0,h=Math.min(t.length,e),u=r;h>u;u++){var a=t.charCodeAt(u)-48;o*=n,s=49>a?17>a?a:a-17+10:a-49+10,i(a>=0&&n>s,"Invalid character"),o+=s}return o}function a(t,r){t.words=r.words,t.length=r.length,t.negative=r.negative,t.red=r.red}function f(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}function l(t){for(var r=Array(t.bitLength()),e=0;r.length>e;e++){r[e]=t.words[e/26|0]>>>e%26&1}return r}function c(t,r,e){e.negative=r.negative^t.negative;var i=t.length+r.length|0;e.length=i,i=i-1|0;var n=0|t.words[0],o=0|r.words[0],s=n*o,h=67108863&s,u=s/67108864|0;e.words[0]=h;for(var a=1;i>a;a++){for(var f=u>>>26,l=67108863&u,c=Math.min(a,r.length-1),p=Math.max(0,a-t.length+1);c>=p;p++){n=0|t.words[a-p|0],o=0|r.words[p],s=n*o+l,f+=s/67108864|0,l=67108863&s}e.words[a]=0|l,u=0|f}return 0!==u?e.words[a]=0|u:e.length--,e._strip()}function p(t,r,e){e.negative=r.negative^t.negative,e.length=t.length+r.length;for(var i=0,n=0,o=0;e.length-1>o;o++){var s=n;n=0;for(var h=67108863&i,u=Math.min(o,r.length-1),a=Math.max(0,o-t.length+1);u>=a;a++){var f=o-a,l=0|t.words[f],c=0|r.words[a],p=l*c,m=67108863&p;s=s+(p/67108864|0)|0,m=m+h|0,h=67108863&m,s=s+(m>>>26)|0,n+=s>>>26,s&=67108863}e.words[o]=h,i=s,s=n}return 0!==i?e.words[o]=i:e.length--,e._strip()}function m(t,r,e){return p(t,r,e)}function d(t,r){this.x=t,this.y=r}function g(t,r){this.name=t,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function y(){g.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){g.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function w(){g.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){g.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function b(t){if("string"==typeof t){var r=o._prime(t);this.m=r.p,this.prime=r}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function _(t){b.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(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)}"object"==typeof t?t.exports=o:r.BN=o,o.BN=o,o.wordSize=26;var A;try{A="undefined"!=typeof window&&"undefined"!=typeof window.Buffer?window.Buffer:e(9).Buffer}catch(R){}if(o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,r){return t.cmp(r)>0?t:r},o.min=function(t,r){return 0>t.cmp(r)?t:r},o.prototype._init=function(t,r,e){if("number"==typeof t)return this._initNumber(t,r,e);if("object"==typeof t)return this._initArray(t,r,e);"hex"===r&&(r=16),i(r===(0|r)&&r>=2&&36>=r),t=(""+t).replace(/\s+/g,"");var n=0;"-"===t[0]&&(n++,this.negative=1),t.length>n&&(16===r?this._parseHex(t,n,e):(this._parseBase(t,r,n),"le"===e&&this._initArray(this.toArray(),r,e)))},o.prototype._initNumber=function(t,r,e){0>t&&(this.negative=1,t=-t),67108864>t?(this.words=[67108863&t],this.length=1):4503599627370496>t?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(i(9007199254740992>t),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===e&&this._initArray(this.toArray(),r,e)},o.prototype._initArray=function(t,r,e){if(i("number"==typeof t.length),0>=t.length)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=Array(this.length);for(var n=0;this.length>n;n++)this.words[n]=0;var o,s,h=0;if("be"===e)for(n=t.length-1,o=0;n>=0;n-=3)s=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[o]|=s<<h&67108863,this.words[o+1]=s>>>26-h&67108863,26>(h+=24)||(h-=26,o++);else if("le"===e)for(n=0,o=0;t.length>n;n+=3)s=t[n]|t[n+1]<<8|t[n+2]<<16,this.words[o]|=s<<h&67108863,this.words[o+1]=s>>>26-h&67108863,26>(h+=24)||(h-=26,o++);return this._strip()},o.prototype._parseHex=function(t,r,e){this.length=Math.ceil((t.length-r)/6),this.words=Array(this.length);for(var i=0;this.length>i;i++)this.words[i]=0;var n,o=0,s=0;if("be"===e)for(i=t.length-1;i>=r;i-=2)n=h(t,r,i)<<o,this.words[s]|=67108863&n,18>o?o+=8:(o-=18,s+=1,this.words[s]|=n>>>26);else{var u=t.length-r;for(i=u%2==0?r+1:r;t.length>i;i+=2)n=h(t,r,i)<<o,this.words[s]|=67108863&n,18>o?o+=8:(o-=18,s+=1,this.words[s]|=n>>>26)}this._strip()},o.prototype._parseBase=function(t,r,e){this.words=[0],this.length=1;for(var i=0,n=1;67108863>=n;n*=r)i++;i--,n=n/r|0;for(var o=t.length-e,s=o%i,h=Math.min(o,o-s)+e,a=0,f=e;h>f;f+=i)a=u(t,f,f+i,r),this.imuln(n),67108864>this.words[0]+a?this.words[0]+=a:this._iaddn(a);if(0!==s){var l=1;for(a=u(t,f,t.length,r),f=0;s>f;f++)l*=r;this.imuln(l),67108864>this.words[0]+a?this.words[0]+=a:this._iaddn(a)}this._strip()},o.prototype.copy=function(t){t.words=Array(this.length);for(var r=0;this.length>r;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype._move=function(t){a(t,this)},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;t>this.length;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol["for"])try{o.prototype[Symbol["for"]("nodejs.util.inspect.custom")]=f}catch(R){o.prototype.inspect=f}else o.prototype.inspect=f;var E=["","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"],S=[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],T=[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];o.prototype.toString=function(t,r){t=t||10,r=0|r||1;var e;if(16===t||"hex"===t){e="";for(var n=0,o=0,s=0;this.length>s;s++){var h=this.words[s],u=(16777215&(h<<n|o)).toString(16);o=h>>>24-n&16777215,n+=2,26>n||(n-=26,s--),e=0!==o||s!==this.length-1?E[6-u.length]+u+e:u+e}for(0!==o&&(e=o.toString(16)+e);e.length%r!=0;)e="0"+e;return 0!==this.negative&&(e="-"+e),e}if(t===(0|t)&&t>=2&&36>=t){var a=S[t],f=T[t];e="";var l=this.clone();for(l.negative=0;!l.isZero();){var c=l.modrn(f).toString(t);l=l.idivn(f),e=l.isZero()?c+e:E[a-c.length]+c+e}for(this.isZero()&&(e="0"+e);e.length%r!=0;)e="0"+e;return 0!==this.negative&&(e="-"+e),e}i(!1,"Base should be between 2 and 36")},o.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},o.prototype.toJSON=function(){return this.toString(16,2)},A&&(o.prototype.toBuffer=function(t,r){return this.toArrayLike(A,t,r)}),o.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)};var B=function(t,r){return t.allocUnsafe?t.allocUnsafe(r):new t(r)};o.prototype.toArrayLike=function(t,r,e){this._strip();var n=this.byteLength(),o=e||Math.max(1,n);i(o>=n,"byte array longer than desired length"),i(o>0,"Requested array length <= 0");var s=B(t,o);return this["_toArrayLike"+("le"===r?"LE":"BE")](s,n),s},o.prototype._toArrayLikeLE=function(t,r){for(var e=0,i=0,n=0,o=0;this.length>n;n++){var s=this.words[n]<<o|i;t[e++]=255&s,t.length>e&&(t[e++]=s>>8&255),t.length>e&&(t[e++]=s>>16&255),6===o?(t.length>e&&(t[e++]=s>>24&255),i=0,o=0):(i=s>>>24,o+=2)}if(t.length>e)for(t[e++]=i;t.length>e;)t[e++]=0},o.prototype._toArrayLikeBE=function(t,r){for(var e=t.length-1,i=0,n=0,o=0;this.length>n;n++){var s=this.words[n]<<o|i;t[e--]=255&s,0>e||(t[e--]=s>>8&255),0>e||(t[e--]=s>>16&255),6===o?(0>e||(t[e--]=s>>24&255),i=0,o=0):(i=s>>>24,o+=2)}if(e>=0)for(t[e--]=i;e>=0;)t[e--]=0},o.prototype._countBits=Math.clz32?function(t){return 32-Math.clz32(t)}:function(t){var r=t,e=0;return 4096>r||(e+=13,r>>>=13),64>r||(e+=7,r>>>=7),8>r||(e+=4,r>>>=4),2>r||(e+=2,r>>>=2),e+r},o.prototype._zeroBits=function(t){if(0===t)return 26;var r=t,e=0;return 0==(8191&r)&&(e+=13,r>>>=13),0==(127&r)&&(e+=7,r>>>=7),0==(15&r)&&(e+=4,r>>>=4),0==(3&r)&&(e+=2,r>>>=2),0==(1&r)&&e++,e},o.prototype.bitLength=function(){return 26*(this.length-1)+this._countBits(this.words[this.length-1])},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;this.length>r;r++){var e=this._zeroBits(this.words[r]);if(t+=e,26!==e)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;t.length>this.length;)this.words[this.length++]=0;for(var r=0;t.length>r;r++)this.words[r]=this.words[r]|t.words[r];return this._strip()},o.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var r;r=this.length>t.length?t:this;for(var e=0;r.length>e;e++)this.words[e]=this.words[e]&t.words[e];return this.length=r.length,this._strip()},o.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var r,e;this.length>t.length?(r=this,e=t):(r=t,e=this);for(var i=0;e.length>i;i++)this.words[i]=r.words[i]^e.words[i];if(this!==r)for(;r.length>i;i++)this.words[i]=r.words[i];return this.length=r.length,this._strip()},o.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var r=0|Math.ceil(t/26),e=t%26;this._expand(r),e>0&&r--;for(var n=0;r>n;n++)this.words[n]=67108863&~this.words[n];return e>0&&(this.words[n]=~this.words[n]&67108863>>26-e),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,r){i("number"==typeof t&&t>=0);var e=t/26|0,n=t%26;return this._expand(e+1),this.words[e]=r?this.words[e]|1<<n:this.words[e]&~(1<<n),this._strip()},o.prototype.iadd=function(t){var r;if(0!==this.negative&&0===t.negative)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var n=0,o=0;i.length>o;o++)r=(0|e.words[o])+(0|i.words[o])+n,this.words[o]=67108863&r,n=r>>>26;for(;0!==n&&e.length>o;o++)r=(0|e.words[o])+n,this.words[o]=67108863&r,n=r>>>26;if(this.length=e.length,0!==n)this.words[this.length]=n,this.length++;else if(e!==this)for(;e.length>o;o++)this.words[o]=e.words[o];return this},o.prototype.add=function(t){var r;return 0!==t.negative&&0===this.negative?(t.negative=0,r=this.sub(t),t.negative^=1,r):0===t.negative&&0!==this.negative?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var e=this.cmp(t);if(0===e)return this.negative=0,this.length=1,this.words[0]=0,this;var i,n;e>0?(i=this,n=t):(i=t,n=this);for(var o=0,s=0;n.length>s;s++)r=(0|i.words[s])-(0|n.words[s])+o,o=r>>26,this.words[s]=67108863&r;for(;0!==o&&i.length>s;s++)r=(0|i.words[s])+o,o=r>>26,this.words[s]=67108863&r;if(0===o&&i.length>s&&i!==this)for(;i.length>s;s++)this.words[s]=i.words[s];return this.length=Math.max(this.length,s),i!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var D=function(t,r,e){var i,n,o,s=t.words,h=r.words,u=e.words,a=0,f=0|s[0],l=8191&f,c=f>>>13,p=0|s[1],m=8191&p,d=p>>>13,g=0|s[2],y=8191&g,v=g>>>13,w=0|s[3],M=8191&w,b=w>>>13,_=0|s[4],A=8191&_,E=_>>>13,S=0|s[5],T=8191&S,B=S>>>13,D=0|s[6],x=8191&D,R=D>>>13,P=0|s[7],k=8191&P,I=P>>>13,Q=0|s[8],j=8191&Q,O=Q>>>13,C=0|s[9],U=8191&C,L=C>>>13,N=0|h[0],q=8191&N,F=N>>>13,Y=0|h[1],H=8191&Y,Z=Y>>>13,z=0|h[2],J=8191&z,$=z>>>13,K=0|h[3],V=8191&K,G=K>>>13,W=0|h[4],X=8191&W,tt=W>>>13,rt=0|h[5],et=8191&rt,it=rt>>>13,nt=0|h[6],ot=8191&nt,st=nt>>>13,ht=0|h[7],ut=8191&ht,at=ht>>>13,ft=0|h[8],lt=8191&ft,ct=ft>>>13,pt=0|h[9],mt=8191&pt,dt=pt>>>13;e.negative=t.negative^r.negative,e.length=19,i=Math.imul(l,q),n=Math.imul(l,F),n=n+Math.imul(c,q)|0,o=Math.imul(c,F);var gt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(gt>>>26)|0,gt&=67108863,i=Math.imul(m,q),n=Math.imul(m,F),n=n+Math.imul(d,q)|0,o=Math.imul(d,F),i=i+Math.imul(l,H)|0,n=n+Math.imul(l,Z)|0,n=n+Math.imul(c,H)|0,o=o+Math.imul(c,Z)|0;var yt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(y,q),n=Math.imul(y,F),n=n+Math.imul(v,q)|0,o=Math.imul(v,F),i=i+Math.imul(m,H)|0,n=n+Math.imul(m,Z)|0,n=n+Math.imul(d,H)|0,o=o+Math.imul(d,Z)|0,i=i+Math.imul(l,J)|0,n=n+Math.imul(l,$)|0,n=n+Math.imul(c,J)|0,o=o+Math.imul(c,$)|0;var vt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(M,q),n=Math.imul(M,F),n=n+Math.imul(b,q)|0,o=Math.imul(b,F),i=i+Math.imul(y,H)|0,n=n+Math.imul(y,Z)|0,n=n+Math.imul(v,H)|0,o=o+Math.imul(v,Z)|0,i=i+Math.imul(m,J)|0,n=n+Math.imul(m,$)|0,n=n+Math.imul(d,J)|0,o=o+Math.imul(d,$)|0,i=i+Math.imul(l,V)|0,n=n+Math.imul(l,G)|0,n=n+Math.imul(c,V)|0,o=o+Math.imul(c,G)|0;var wt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(A,q),n=Math.imul(A,F),n=n+Math.imul(E,q)|0,o=Math.imul(E,F),i=i+Math.imul(M,H)|0,n=n+Math.imul(M,Z)|0,n=n+Math.imul(b,H)|0,o=o+Math.imul(b,Z)|0,i=i+Math.imul(y,J)|0,n=n+Math.imul(y,$)|0,n=n+Math.imul(v,J)|0,o=o+Math.imul(v,$)|0,i=i+Math.imul(m,V)|0,n=n+Math.imul(m,G)|0,n=n+Math.imul(d,V)|0,o=o+Math.imul(d,G)|0,i=i+Math.imul(l,X)|0,n=n+Math.imul(l,tt)|0,n=n+Math.imul(c,X)|0,o=o+Math.imul(c,tt)|0;var Mt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(T,q),n=Math.imul(T,F),n=n+Math.imul(B,q)|0,o=Math.imul(B,F),i=i+Math.imul(A,H)|0,n=n+Math.imul(A,Z)|0,n=n+Math.imul(E,H)|0,o=o+Math.imul(E,Z)|0,i=i+Math.imul(M,J)|0,n=n+Math.imul(M,$)|0,n=n+Math.imul(b,J)|0,o=o+Math.imul(b,$)|0,i=i+Math.imul(y,V)|0,n=n+Math.imul(y,G)|0,n=n+Math.imul(v,V)|0,o=o+Math.imul(v,G)|0,i=i+Math.imul(m,X)|0,n=n+Math.imul(m,tt)|0,n=n+Math.imul(d,X)|0,o=o+Math.imul(d,tt)|0,i=i+Math.imul(l,et)|0,n=n+Math.imul(l,it)|0,n=n+Math.imul(c,et)|0,o=o+Math.imul(c,it)|0;var bt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(x,q),n=Math.imul(x,F),n=n+Math.imul(R,q)|0,o=Math.imul(R,F),i=i+Math.imul(T,H)|0,n=n+Math.imul(T,Z)|0,n=n+Math.imul(B,H)|0,o=o+Math.imul(B,Z)|0,i=i+Math.imul(A,J)|0,n=n+Math.imul(A,$)|0,n=n+Math.imul(E,J)|0,o=o+Math.imul(E,$)|0,i=i+Math.imul(M,V)|0,n=n+Math.imul(M,G)|0,n=n+Math.imul(b,V)|0,o=o+Math.imul(b,G)|0,i=i+Math.imul(y,X)|0,n=n+Math.imul(y,tt)|0,n=n+Math.imul(v,X)|0,o=o+Math.imul(v,tt)|0,i=i+Math.imul(m,et)|0,n=n+Math.imul(m,it)|0,n=n+Math.imul(d,et)|0,o=o+Math.imul(d,it)|0,i=i+Math.imul(l,ot)|0,n=n+Math.imul(l,st)|0,n=n+Math.imul(c,ot)|0,o=o+Math.imul(c,st)|0;var _t=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(k,q),n=Math.imul(k,F),n=n+Math.imul(I,q)|0,o=Math.imul(I,F),i=i+Math.imul(x,H)|0,n=n+Math.imul(x,Z)|0,n=n+Math.imul(R,H)|0,o=o+Math.imul(R,Z)|0,i=i+Math.imul(T,J)|0,n=n+Math.imul(T,$)|0,n=n+Math.imul(B,J)|0,o=o+Math.imul(B,$)|0,i=i+Math.imul(A,V)|0,n=n+Math.imul(A,G)|0,n=n+Math.imul(E,V)|0,o=o+Math.imul(E,G)|0,i=i+Math.imul(M,X)|0,n=n+Math.imul(M,tt)|0,n=n+Math.imul(b,X)|0,o=o+Math.imul(b,tt)|0,i=i+Math.imul(y,et)|0,n=n+Math.imul(y,it)|0,n=n+Math.imul(v,et)|0,o=o+Math.imul(v,it)|0,i=i+Math.imul(m,ot)|0,n=n+Math.imul(m,st)|0,n=n+Math.imul(d,ot)|0,o=o+Math.imul(d,st)|0,i=i+Math.imul(l,ut)|0,n=n+Math.imul(l,at)|0,n=n+Math.imul(c,ut)|0,o=o+Math.imul(c,at)|0;var At=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(j,q),n=Math.imul(j,F),n=n+Math.imul(O,q)|0,o=Math.imul(O,F),i=i+Math.imul(k,H)|0,n=n+Math.imul(k,Z)|0,n=n+Math.imul(I,H)|0,o=o+Math.imul(I,Z)|0,i=i+Math.imul(x,J)|0,n=n+Math.imul(x,$)|0,n=n+Math.imul(R,J)|0,o=o+Math.imul(R,$)|0,i=i+Math.imul(T,V)|0,n=n+Math.imul(T,G)|0,n=n+Math.imul(B,V)|0,o=o+Math.imul(B,G)|0,i=i+Math.imul(A,X)|0,n=n+Math.imul(A,tt)|0,n=n+Math.imul(E,X)|0,o=o+Math.imul(E,tt)|0,i=i+Math.imul(M,et)|0,n=n+Math.imul(M,it)|0,n=n+Math.imul(b,et)|0,o=o+Math.imul(b,it)|0,i=i+Math.imul(y,ot)|0,n=n+Math.imul(y,st)|0,n=n+Math.imul(v,ot)|0,o=o+Math.imul(v,st)|0,i=i+Math.imul(m,ut)|0,n=n+Math.imul(m,at)|0,n=n+Math.imul(d,ut)|0,o=o+Math.imul(d,at)|0,i=i+Math.imul(l,lt)|0,n=n+Math.imul(l,ct)|0,n=n+Math.imul(c,lt)|0,o=o+Math.imul(c,ct)|0;var Et=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(U,q),n=Math.imul(U,F),n=n+Math.imul(L,q)|0,o=Math.imul(L,F),i=i+Math.imul(j,H)|0,n=n+Math.imul(j,Z)|0,n=n+Math.imul(O,H)|0,o=o+Math.imul(O,Z)|0,i=i+Math.imul(k,J)|0,n=n+Math.imul(k,$)|0,n=n+Math.imul(I,J)|0,o=o+Math.imul(I,$)|0,i=i+Math.imul(x,V)|0,n=n+Math.imul(x,G)|0,n=n+Math.imul(R,V)|0,o=o+Math.imul(R,G)|0,i=i+Math.imul(T,X)|0,n=n+Math.imul(T,tt)|0,n=n+Math.imul(B,X)|0,o=o+Math.imul(B,tt)|0,i=i+Math.imul(A,et)|0,n=n+Math.imul(A,it)|0,n=n+Math.imul(E,et)|0,o=o+Math.imul(E,it)|0,i=i+Math.imul(M,ot)|0,n=n+Math.imul(M,st)|0,n=n+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,i=i+Math.imul(y,ut)|0,n=n+Math.imul(y,at)|0,n=n+Math.imul(v,ut)|0,o=o+Math.imul(v,at)|0,i=i+Math.imul(m,lt)|0,n=n+Math.imul(m,ct)|0,n=n+Math.imul(d,lt)|0,o=o+Math.imul(d,ct)|0,i=i+Math.imul(l,mt)|0,n=n+Math.imul(l,dt)|0,n=n+Math.imul(c,mt)|0,o=o+Math.imul(c,dt)|0;var St=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(U,H),n=Math.imul(U,Z),n=n+Math.imul(L,H)|0,o=Math.imul(L,Z),i=i+Math.imul(j,J)|0,n=n+Math.imul(j,$)|0,n=n+Math.imul(O,J)|0,o=o+Math.imul(O,$)|0,i=i+Math.imul(k,V)|0,n=n+Math.imul(k,G)|0,n=n+Math.imul(I,V)|0,o=o+Math.imul(I,G)|0,i=i+Math.imul(x,X)|0,n=n+Math.imul(x,tt)|0,n=n+Math.imul(R,X)|0,o=o+Math.imul(R,tt)|0,i=i+Math.imul(T,et)|0,n=n+Math.imul(T,it)|0,n=n+Math.imul(B,et)|0,o=o+Math.imul(B,it)|0,i=i+Math.imul(A,ot)|0,n=n+Math.imul(A,st)|0,n=n+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,i=i+Math.imul(M,ut)|0,n=n+Math.imul(M,at)|0,n=n+Math.imul(b,ut)|0,o=o+Math.imul(b,at)|0,i=i+Math.imul(y,lt)|0,n=n+Math.imul(y,ct)|0,n=n+Math.imul(v,lt)|0,o=o+Math.imul(v,ct)|0,i=i+Math.imul(m,mt)|0,n=n+Math.imul(m,dt)|0,n=n+Math.imul(d,mt)|0,o=o+Math.imul(d,dt)|0;var Tt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,i=Math.imul(U,J),n=Math.imul(U,$),n=n+Math.imul(L,J)|0,o=Math.imul(L,$),i=i+Math.imul(j,V)|0,n=n+Math.imul(j,G)|0,n=n+Math.imul(O,V)|0,o=o+Math.imul(O,G)|0,i=i+Math.imul(k,X)|0,n=n+Math.imul(k,tt)|0,n=n+Math.imul(I,X)|0,o=o+Math.imul(I,tt)|0,i=i+Math.imul(x,et)|0,n=n+Math.imul(x,it)|0,n=n+Math.imul(R,et)|0,o=o+Math.imul(R,it)|0,i=i+Math.imul(T,ot)|0,n=n+Math.imul(T,st)|0,n=n+Math.imul(B,ot)|0,o=o+Math.imul(B,st)|0,i=i+Math.imul(A,ut)|0,n=n+Math.imul(A,at)|0,n=n+Math.imul(E,ut)|0,o=o+Math.imul(E,at)|0,i=i+Math.imul(M,lt)|0,n=n+Math.imul(M,ct)|0,n=n+Math.imul(b,lt)|0,o=o+Math.imul(b,ct)|0,i=i+Math.imul(y,mt)|0,n=n+Math.imul(y,dt)|0,n=n+Math.imul(v,mt)|0,o=o+Math.imul(v,dt)|0;var Bt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,i=Math.imul(U,V),n=Math.imul(U,G),n=n+Math.imul(L,V)|0,o=Math.imul(L,G),i=i+Math.imul(j,X)|0,n=n+Math.imul(j,tt)|0,n=n+Math.imul(O,X)|0,o=o+Math.imul(O,tt)|0,i=i+Math.imul(k,et)|0,n=n+Math.imul(k,it)|0,n=n+Math.imul(I,et)|0,o=o+Math.imul(I,it)|0,i=i+Math.imul(x,ot)|0,n=n+Math.imul(x,st)|0,n=n+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,i=i+Math.imul(T,ut)|0,n=n+Math.imul(T,at)|0,n=n+Math.imul(B,ut)|0,o=o+Math.imul(B,at)|0,i=i+Math.imul(A,lt)|0,n=n+Math.imul(A,ct)|0,n=n+Math.imul(E,lt)|0,o=o+Math.imul(E,ct)|0,i=i+Math.imul(M,mt)|0,n=n+Math.imul(M,dt)|0,n=n+Math.imul(b,mt)|0,o=o+Math.imul(b,dt)|0;var Dt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,i=Math.imul(U,X),n=Math.imul(U,tt),n=n+Math.imul(L,X)|0,o=Math.imul(L,tt),i=i+Math.imul(j,et)|0,n=n+Math.imul(j,it)|0,n=n+Math.imul(O,et)|0,o=o+Math.imul(O,it)|0,i=i+Math.imul(k,ot)|0,n=n+Math.imul(k,st)|0,n=n+Math.imul(I,ot)|0,o=o+Math.imul(I,st)|0,i=i+Math.imul(x,ut)|0,n=n+Math.imul(x,at)|0,n=n+Math.imul(R,ut)|0,o=o+Math.imul(R,at)|0,i=i+Math.imul(T,lt)|0,n=n+Math.imul(T,ct)|0,n=n+Math.imul(B,lt)|0,o=o+Math.imul(B,ct)|0,i=i+Math.imul(A,mt)|0,n=n+Math.imul(A,dt)|0,n=n+Math.imul(E,mt)|0,o=o+Math.imul(E,dt)|0;var xt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(U,et),n=Math.imul(U,it),n=n+Math.imul(L,et)|0,o=Math.imul(L,it),i=i+Math.imul(j,ot)|0,n=n+Math.imul(j,st)|0,n=n+Math.imul(O,ot)|0,o=o+Math.imul(O,st)|0,i=i+Math.imul(k,ut)|0,n=n+Math.imul(k,at)|0,n=n+Math.imul(I,ut)|0,o=o+Math.imul(I,at)|0,i=i+Math.imul(x,lt)|0,n=n+Math.imul(x,ct)|0,n=n+Math.imul(R,lt)|0,o=o+Math.imul(R,ct)|0,i=i+Math.imul(T,mt)|0,n=n+Math.imul(T,dt)|0,n=n+Math.imul(B,mt)|0,o=o+Math.imul(B,dt)|0;var Rt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,i=Math.imul(U,ot),n=Math.imul(U,st),n=n+Math.imul(L,ot)|0,o=Math.imul(L,st),i=i+Math.imul(j,ut)|0,n=n+Math.imul(j,at)|0,n=n+Math.imul(O,ut)|0,o=o+Math.imul(O,at)|0,i=i+Math.imul(k,lt)|0,n=n+Math.imul(k,ct)|0,n=n+Math.imul(I,lt)|0,o=o+Math.imul(I,ct)|0,i=i+Math.imul(x,mt)|0,n=n+Math.imul(x,dt)|0,n=n+Math.imul(R,mt)|0,o=o+Math.imul(R,dt)|0;var Pt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,i=Math.imul(U,ut),n=Math.imul(U,at),n=n+Math.imul(L,ut)|0,o=Math.imul(L,at),i=i+Math.imul(j,lt)|0,n=n+Math.imul(j,ct)|0,n=n+Math.imul(O,lt)|0,o=o+Math.imul(O,ct)|0,i=i+Math.imul(k,mt)|0,n=n+Math.imul(k,dt)|0,n=n+Math.imul(I,mt)|0,o=o+Math.imul(I,dt)|0;var kt=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,i=Math.imul(U,lt),n=Math.imul(U,ct),n=n+Math.imul(L,lt)|0,o=Math.imul(L,ct),i=i+Math.imul(j,mt)|0,n=n+Math.imul(j,dt)|0,n=n+Math.imul(O,mt)|0,o=o+Math.imul(O,dt)|0;var It=(a+i|0)+((8191&n)<<13)|0;a=(o+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(U,mt),n=Math.imul(U,dt),n=n+Math.imul(L,mt)|0,o=Math.imul(L,dt);var Qt=(a+i|0)+((8191&n)<<13)|0;return a=(o+(n>>>13)|0)+(Qt>>>26)|0,Qt&=67108863,u[0]=gt,u[1]=yt,u[2]=vt,u[3]=wt,u[4]=Mt,u[5]=bt,u[6]=_t,u[7]=At,u[8]=Et,u[9]=St,u[10]=Tt,u[11]=Bt,u[12]=Dt,u[13]=xt,u[14]=Rt,u[15]=Pt,u[16]=kt,u[17]=It,u[18]=Qt,0!==a&&(u[19]=a,e.length++),e};Math.imul||(D=c),o.prototype.mulTo=function(t,r){var e=this.length+t.length;return 10===this.length&&10===t.length?D(this,t,r):63>e?c(this,t,r):1024>e?p(this,t,r):m(this,t,r)},d.prototype.makeRBT=function(t){for(var r=Array(t),e=o.prototype._countBits(t)-1,i=0;t>i;i++)r[i]=this.revBin(i,e,t);return r},d.prototype.revBin=function(t,r,e){if(0===t||t===e-1)return t;for(var i=0,n=0;r>n;n++)i|=(1&t)<<r-n-1,t>>=1;return i},d.prototype.permute=function(t,r,e,i,n,o){for(var s=0;o>s;s++)i[s]=r[t[s]],n[s]=e[t[s]]},d.prototype.transform=function(t,r,e,i,n,o){this.permute(o,t,r,e,i,n);for(var s=1;n>s;s<<=1)for(var h=s<<1,u=Math.cos(2*Math.PI/h),a=Math.sin(2*Math.PI/h),f=0;n>f;f+=h)for(var l=u,c=a,p=0;s>p;p++){var m=e[f+p],d=i[f+p],g=e[f+p+s],y=i[f+p+s],v=l*g-c*y;y=l*y+c*g,g=v,e[f+p]=m+g,i[f+p]=d+y,e[f+p+s]=m-g,i[f+p+s]=d-y,p!==h&&(v=u*l-a*c,c=u*c+a*l,l=v)}},d.prototype.guessLen13b=function(t,r){var e=1|Math.max(r,t),i=1&e,n=0;for(e=e/2|0;e;e>>>=1)n++;return 1<<n+1+i},d.prototype.conjugate=function(t,r,e){if(e>1)for(var i=0;e/2>i;i++){var n=t[i];t[i]=t[e-i-1],t[e-i-1]=n,n=r[i],r[i]=-r[e-i-1],r[e-i-1]=-n}},d.prototype.normalize13b=function(t,r){for(var e=0,i=0;r/2>i;i++){var n=8192*Math.round(t[2*i+1]/r)+Math.round(t[2*i]/r)+e;t[i]=67108863&n,e=67108864>n?0:n/67108864|0}return t},d.prototype.convert13b=function(t,r,e,n){for(var o=0,s=0;r>s;s++)o+=0|t[s],e[2*s]=8191&o,o>>>=13,e[2*s+1]=8191&o,o>>>=13;for(s=2*r;n>s;++s)e[s]=0;i(0===o),i(0==(-8192&o))},d.prototype.stub=function(t){for(var r=Array(t),e=0;t>e;e++)r[e]=0;return r},d.prototype.mulp=function(t,r,e){var i=2*this.guessLen13b(t.length,r.length),n=this.makeRBT(i),o=this.stub(i),s=Array(i),h=Array(i),u=Array(i),a=Array(i),f=Array(i),l=Array(i),c=e.words;c.length=i,this.convert13b(t.words,t.length,s,i),this.convert13b(r.words,r.length,a,i),this.transform(s,o,h,u,i,n),this.transform(a,o,f,l,i,n);for(var p=0;i>p;p++){var m=h[p]*f[p]-u[p]*l[p];u[p]=h[p]*l[p]+u[p]*f[p],h[p]=m}return this.conjugate(h,u,i),this.transform(h,u,c,o,i,n),this.conjugate(c,o,i),this.normalize13b(c,i),e.negative=t.negative^r.negative,e.length=t.length+r.length,e._strip()},o.prototype.mul=function(t){var r=new o(null);return r.words=Array(this.length+t.length),this.mulTo(t,r)},o.prototype.mulf=function(t){var r=new o(null);return r.words=Array(this.length+t.length),m(this,t,r)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var r=0>t;r&&(t=-t),i("number"==typeof t),i(67108864>t);for(var e=0,n=0;this.length>n;n++){var o=(0|this.words[n])*t,s=(67108863&o)+(67108863&e);e>>=26,e+=o/67108864|0,e+=s>>>26,this.words[n]=67108863&s}return 0!==e&&(this.words[n]=e,this.length++),r?this.ineg():this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var r=l(t);if(0===r.length)return new o(1);for(var e=this,i=0;r.length>i&&0===r[i];i++,e=e.sqr());if(++i<r.length)for(var n=e.sqr();r.length>i;i++,n=n.sqr())0!==r[i]&&(e=e.mul(n));return e},o.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var r,e=t%26,n=(t-e)/26,o=67108863>>>26-e<<26-e;if(0!==e){var s=0;for(r=0;this.length>r;r++){var h=this.words[r]&o;this.words[r]=(0|this.words[r])-h<<e|s,s=h>>>26-e}s&&(this.words[r]=s,this.length++)}if(0!==n){for(r=this.length-1;r>=0;r--)this.words[r+n]=this.words[r];for(r=0;n>r;r++)this.words[r]=0;this.length+=n}return this._strip()},o.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,r,e){i("number"==typeof t&&t>=0);var n;n=r?(r-r%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),h=67108863^67108863>>>o<<o,u=e;if(n-=s,n=Math.max(0,n),u){for(var a=0;s>a;a++)u.words[a]=this.words[a];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,a=0;this.length>a;a++)this.words[a]=this.words[a+s];else this.words[0]=0,this.length=1;var f=0;for(a=this.length-1;!(0>a||0===f&&n>a);a--){var l=0|this.words[a];this.words[a]=f<<26-o|l>>>o,f=l&h}return u&&0!==f&&(u.words[u.length++]=f),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,r,e){return i(0===this.negative),this.iushrn(t,r,e)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){i("number"==typeof t&&t>=0);var r=t%26,e=(t-r)/26,n=1<<r;return this.length>e&&!!(this.words[e]&n)},o.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var r=t%26,e=(t-r)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),e>=this.length)return this;if(0!==r&&e++,this.length=Math.min(e,this.length),0!==r){this.words[this.length-1]&=67108863^67108863>>>r<<r}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return i("number"==typeof t),i(67108864>t),0>t?this.isubn(-t):0!==this.negative?1!==this.length||(0|this.words[0])>t?(this.negative=0,this.isubn(t),this.negative=1,this):(this.words[0]=t-(0|this.words[0]),this.negative=0,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;this.length>r&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},o.prototype.isubn=function(t){if(i("number"==typeof t),i(67108864>t),0>t)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&&0>this.words[0])this.words[0]=-this.words[0],this.negative=1;else for(var r=0;this.length>r&&0>this.words[r];r++)this.words[r]+=67108864,this.words[r+1]-=1;return this._strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,r,e){var n,o=t.length+e;this._expand(o);var s,h=0;for(n=0;t.length>n;n++){s=(0|this.words[n+e])+h;var u=(0|t.words[n])*r;s-=67108863&u,h=(s>>26)-(u/67108864|0),this.words[n+e]=67108863&s}for(;this.length-e>n;n++)s=(0|this.words[n+e])+h,h=s>>26,this.words[n+e]=67108863&s;if(0===h)return this._strip();for(i(-1===h),h=0,n=0;this.length>n;n++)s=-(0|this.words[n])+h,h=s>>26,this.words[n]=67108863&s;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,r){var e=this.length-t.length,i=this.clone(),n=t,s=0|n.words[n.length-1];0!==(e=26-this._countBits(s))&&(n=n.ushln(e),i.iushln(e),s=0|n.words[n.length-1]);var h,u=i.length-n.length;if("mod"!==r){h=new o(null),h.length=u+1,h.words=Array(h.length);for(var a=0;h.length>a;a++)h.words[a]=0}var f=i.clone()._ishlnsubmul(n,1,u);0===f.negative&&(i=f,h&&(h.words[u]=1));for(var l=u-1;l>=0;l--){var c=67108864*(0|i.words[n.length+l])+(0|i.words[n.length+l-1]);for(c=Math.min(c/s|0,67108863),i._ishlnsubmul(n,c,l);0!==i.negative;)c--,i.negative=0,i._ishlnsubmul(n,1,l),i.isZero()||(i.negative^=1);h&&(h.words[l]=c)}return h&&h._strip(),i._strip(),"div"!==r&&0!==e&&i.iushrn(e),{div:h||null,mod:i}},o.prototype.divmod=function(t,r,e){if(i(!t.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var n,s,h;return 0!==this.negative&&0===t.negative?(h=this.neg().divmod(t,r),"mod"!==r&&(n=h.div.neg()),"div"!==r&&(s=h.mod.neg(),e&&0!==s.negative&&s.iadd(t)),{div:n,mod:s}):0===this.negative&&0!==t.negative?(h=this.divmod(t.neg(),r),"mod"!==r&&(n=h.div.neg()),{div:n,mod:h.mod}):0!=(this.negative&t.negative)?(h=this.neg().divmod(t.neg(),r),"div"!==r&&(s=h.mod.neg(),e&&0!==s.negative&&s.isub(t)),{div:h.div,mod:s}):t.length>this.length||0>this.cmp(t)?{div:new o(0),mod:this}:1===t.length?"div"===r?{div:this.divn(t.words[0]),mod:null}:"mod"===r?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,r)},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var e=0!==r.div.negative?r.mod.isub(t):r.mod,i=t.ushrn(1),n=t.andln(1),o=e.cmp(i);return 0>o||1===n&&0===o?r.div:0!==r.div.negative?r.div.isubn(1):r.div.iaddn(1)},o.prototype.modrn=function(t){var r=0>t;r&&(t=-t),i(67108863>=t);for(var e=(1<<26)%t,n=0,o=this.length-1;o>=0;o--)n=(e*n+(0|this.words[o]))%t;return r?-n:n},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var r=0>t;r&&(t=-t),i(67108863>=t);for(var e=0,n=this.length-1;n>=0;n--){var o=(0|this.words[n])+67108864*e;this.words[n]=o/t|0,e=o%t}return this._strip(),r?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var r=this,e=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var n=new o(1),s=new o(0),h=new o(0),u=new o(1),a=0;r.isEven()&&e.isEven();)r.iushrn(1),e.iushrn(1),++a;for(var f=e.clone(),l=r.clone();!r.isZero();){for(var c=0,p=1;0==(r.words[0]&p)&&26>c;++c,p<<=1);if(c>0)for(r.iushrn(c);c-- >0;)(n.isOdd()||s.isOdd())&&(n.iadd(f),s.isub(l)),n.iushrn(1),s.iushrn(1);for(var m=0,d=1;0==(e.words[0]&d)&&26>m;++m,d<<=1);if(m>0)for(e.iushrn(m);m-- >0;)(h.isOdd()||u.isOdd())&&(h.iadd(f),u.isub(l)),h.iushrn(1),u.iushrn(1);0>r.cmp(e)?(e.isub(r),h.isub(n),u.isub(s)):(r.isub(e),n.isub(h),s.isub(u))}return{a:h,b:u,gcd:e.iushln(a)}},o.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var r=this,e=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var n=new o(1),s=new o(0),h=e.clone();r.cmpn(1)>0&&e.cmpn(1)>0;){for(var u=0,a=1;0==(r.words[0]&a)&&26>u;++u,a<<=1);if(u>0)for(r.iushrn(u);u-- >0;)n.isOdd()&&n.iadd(h),n.iushrn(1);for(var f=0,l=1;0==(e.words[0]&l)&&26>f;++f,l<<=1);if(f>0)for(e.iushrn(f);f-- >0;)s.isOdd()&&s.iadd(h),s.iushrn(1);0>r.cmp(e)?(e.isub(r),s.isub(n)):(r.isub(e),n.isub(s))}var c;return c=0===r.cmpn(1)?n:s,0>c.cmpn(0)&&c.iadd(t),c},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),e=t.clone();r.negative=0,e.negative=0;for(var i=0;r.isEven()&&e.isEven();i++)r.iushrn(1),e.iushrn(1);for(;;){for(;r.isEven();)r.iushrn(1);for(;e.isEven();)e.iushrn(1);var n=r.cmp(e);if(0>n){var o=r;r=e,e=o}else if(0===n||0===e.cmpn(1))break;r.isub(e)}return e.iushln(i)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){i("number"==typeof t);var r=t%26,e=(t-r)/26,n=1<<r;if(e>=this.length)return this._expand(e+1),this.words[e]|=n,this;for(var o=n,s=e;0!==o&&this.length>s;s++){var h=0|this.words[s];h+=o,o=h>>>26,h&=67108863,this.words[s]=h}return 0!==o&&(this.words[s]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var r=0>t;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;this._strip();var e;if(this.length>1)e=1;else{r&&(t=-t),i(67108863>=t,"Number is too big");var n=0|this.words[0];e=n===t?0:t>n?-1:1}return 0!==this.negative?0|-e:e},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var r=this.ucmp(t);return 0!==this.negative?0|-r:r},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(t.length>this.length)return-1;for(var r=0,e=this.length-1;e>=0;e--){var i=0|this.words[e],n=0|t.words[e];if(i!==n){n>i?r=-1:i>n&&(r=1);break}}return r},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return 0>=this.cmpn(t)},o.prototype.lte=function(t){return 0>=this.cmp(t)},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new b(t)},o.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)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var x={k256:null,p224:null,p192:null,p25519:null};g.prototype._tmp=function(){var t=new o(null);return t.words=Array(Math.ceil(this.n/13)),t},g.prototype.ireduce=function(t){var r,e=t;do{this.split(e,this.tmp),e=this.imulK(e),e=e.iadd(this.tmp),r=e.bitLength()}while(r>this.n);var i=this.n>r?-1:e.ucmp(this.p);return 0===i?(e.words[0]=0,e.length=1):i>0?e.isub(this.p):e.strip!==undefined?e.strip():e._strip(),e},g.prototype.split=function(t,r){t.iushrn(this.n,0,r)},g.prototype.imulK=function(t){return t.imul(this.k)},n(y,g),y.prototype.split=function(t,r){for(var e=Math.min(t.length,9),i=0;e>i;i++)r.words[i]=t.words[i];if(r.length=e,9>=t.length)return t.words[0]=0,void(t.length=1);var n=t.words[9];for(r.words[r.length++]=4194303&n,i=10;t.length>i;i++){var o=0|t.words[i];t.words[i-10]=(4194303&o)<<4|n>>>22,n=o}n>>>=22,t.words[i-10]=n,t.length-=0===n&&t.length>10?10:9},y.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var r=0,e=0;t.length>e;e++){var i=0|t.words[e];r+=977*i,t.words[e]=67108863&r,r=64*i+(r/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(v,g),n(w,g),n(M,g),M.prototype.imulK=function(t){for(var r=0,e=0;t.length>e;e++){var i=19*(0|t.words[e])+r,n=67108863&i;i>>>=26,t.words[e]=n,r=i}return 0!==r&&(t.words[t.length++]=r),t},o._prime=function(t){if(x[t])return x[t];var r;if("k256"===t)r=new y;else if("p224"===t)r=new v;else if("p192"===t)r=new w;else{if("p25519"!==t)throw Error("Unknown prime "+t);r=new M}return x[t]=r,r},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,r){i(0==(t.negative|r.negative),"red works only with positives"),i(t.red&&t.red===r.red,"red works only with red numbers")},b.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(a(t,t.umod(this.m)._forceRed(this)),t)},b.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},b.prototype.add=function(t,r){this._verify2(t,r);var e=t.add(r);return 0>e.cmp(this.m)||e.isub(this.m),e._forceRed(this)},b.prototype.iadd=function(t,r){this._verify2(t,r);var e=t.iadd(r);return 0>e.cmp(this.m)||e.isub(this.m),e},b.prototype.sub=function(t,r){this._verify2(t,r);var e=t.sub(r);return 0>e.cmpn(0)&&e.iadd(this.m),e._forceRed(this)},b.prototype.isub=function(t,r){this._verify2(t,r);var e=t.isub(r);return 0>e.cmpn(0)&&e.iadd(this.m),e},b.prototype.shl=function(t,r){return this._verify1(t),this.imod(t.ushln(r))},b.prototype.imul=function(t,r){return this._verify2(t,r),this.imod(t.imul(r))},b.prototype.mul=function(t,r){return this._verify2(t,r),this.imod(t.mul(r))},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 r=this.m.andln(3);if(i(r%2==1),3===r){return this.pow(t,this.m.add(new o(1)).iushrn(2))}for(var e=this.m.subn(1),n=0;!e.isZero()&&0===e.andln(1);)n++,e.iushrn(1);i(!e.isZero());var s=new o(1).toRed(this),h=s.redNeg(),u=this.m.subn(1).iushrn(1),a=this.m.bitLength();for(a=new o(2*a*a).toRed(this);0!==this.pow(a,u).cmp(h);)a.redIAdd(h);for(var f=this.pow(a,e),l=this.pow(t,e.addn(1).iushrn(1)),c=this.pow(t,e),p=n;0!==c.cmp(s);){for(var m=c,d=0;0!==m.cmp(s);d++)m=m.redSqr();i(p>d);var g=this.pow(f,new o(1).iushln(p-d-1));l=l.redMul(g),f=g.redSqr(),c=c.redMul(f),p=d}return l},b.prototype.invm=function(t){var r=t._invmp(this.m);return 0!==r.negative?(r.negative=0,this.imod(r).redNeg()):this.imod(r)},b.prototype.pow=function(t,r){if(r.isZero())return new o(1).toRed(this);if(0===r.cmpn(1))return t.clone();var e=Array(16);e[0]=new o(1).toRed(this),e[1]=t;for(var i=2;e.length>i;i++)e[i]=this.mul(e[i-1],t);var n=e[0],s=0,h=0,u=r.bitLength()%26;for(0===u&&(u=26),i=r.length-1;i>=0;i--){for(var a=r.words[i],f=u-1;f>=0;f--){var l=a>>f&1;n!==e[0]&&(n=this.sqr(n)),0!==l||0!==s?(s<<=1,s|=l,(4===++h||0===i&&0===f)&&(n=this.mul(n,e[s]),h=0,s=0)):h=0}u=26}return n},b.prototype.convertTo=function(t){var r=t.umod(this.m);return r===t?r.clone():r},b.prototype.convertFrom=function(t){var r=t.clone();return r.red=null,r},o.mont=function(t){return new _(t)},n(_,b),_.prototype.convertTo=f