UNPKG

@swipewallet/venus-js

Version:

A JavaScript SDK for Ethereum and the Venus Protocol.

1 lines 659 kB
var Venus=function(t,n){'use strict';var h=Math.pow,b=Math.round,v=Math.sin,w=Math.cos,_=Math.PI,T=Math.imul,x=Math.clz32,A=Math.ceil,E=Math.max,P=Math.min,S=Math.floor,C=String.fromCharCode;function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}function a(e,t){return t={exports:{}},e(t,t.exports),t.exports}function o(e){return!!e.toHexString}function i(e){return e.slice?e:(e.slice=function(){const t=Array.prototype.slice.call(arguments);return i(new Uint8Array(Array.prototype.slice.apply(e,t)))},e)}function s(e){return y(e)&&!(e.length%2)||d(e)}function d(e){if(null==e)return!1;if(e.constructor===Uint8Array)return!0;if("string"==typeof e)return!1;if(null==e.length)return!1;for(let t=0;t<e.length;t++){const n=e[t];if(0>n||256<=n||n%1)return!1}return!0}function p(e,t){if(t||(t={}),"number"==typeof e){ve.checkSafeUint53(e,"invalid arrayify value");const t=[];for(;e;)t.unshift(255&e),e=parseInt(e/256+"");return 0===t.length&&t.push(0),i(new Uint8Array(t))}if(t.allowMissingPrefix&&"string"==typeof e&&"0x"!==e.substring(0,2)&&(e="0x"+e),o(e)&&(e=e.toHexString()),y(e)){let n=e.substring(2);n.length%2&&("left"===t.hexPad?n="0x0"+n.substring(2):"right"===t.hexPad?n+="0":ve.throwArgumentError("hex data is odd-length","value",e));const r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(n.substring(e,e+2),16));return i(new Uint8Array(r))}return d(e)?i(new Uint8Array(e)):ve.throwArgumentError("invalid arrayify value","value",e)}function l(e){const t=e.map(e=>p(e)),n=t.reduce((e,t)=>e+t.length,0),r=new Uint8Array(n);return t.reduce((e,t)=>(r.set(t,e),e+t.length),0),i(r)}function u(e,t){e=p(e),e.length>t&&ve.throwArgumentError("value out of range","value",arguments[0]);const n=new Uint8Array(t);return n.set(e,t-e.length),i(n)}function y(e,t){return!!("string"==typeof e&&e.match(/^0x[0-9A-Fa-f]*$/))&&!(t&&e.length!==2+2*t)}function c(e,t){if(t||(t={}),"number"==typeof e){ve.checkSafeUint53(e,"invalid hexlify value");let t="";for(;e;)t=we[15&e]+t,e=S(e/16);return t.length?(t.length%2&&(t="0"+t),"0x"+t):"0x00"}if(t.allowMissingPrefix&&"string"==typeof e&&"0x"!==e.substring(0,2)&&(e="0x"+e),o(e))return e.toHexString();if(y(e))return e.length%2&&("left"===t.hexPad?e="0x0"+e.substring(2):"right"===t.hexPad?e+="0":ve.throwArgumentError("hex data is odd-length","value",e)),e.toLowerCase();if(d(e)){let t="0x";for(let n=0,r;n<e.length;n++)r=e[n],t+=we[(240&r)>>4]+we[15&r];return t}return ve.throwArgumentError("invalid hexlify value","value",e)}function m(e){"string"!=typeof e&&(e=c(e)),y(e)||ve.throwArgumentError("invalid hex string","value",e),e=e.substring(2);let t=0;for(;t<e.length&&"0"===e[t];)t++;return"0x"+e.substring(t)}function f(e,t){for("string"==typeof e?!y(e)&&ve.throwArgumentError("invalid hex string","value",e):e=c(e),e.length>2*t+2&&ve.throwArgumentError("value out of range","value",arguments[1]);e.length<2*t+2;)e="0x0"+e.substring(2);return e}function g(e){const t={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0};if(s(e)){const n=p(e);65!==n.length&&ve.throwArgumentError("invalid signature string; must be 65 bytes","signature",e),t.r=c(n.slice(0,32)),t.s=c(n.slice(32,64)),t.v=n[64],27>t.v&&(0===t.v||1===t.v?t.v+=27:ve.throwArgumentError("signature invalid v byte","signature",e)),t.recoveryParam=1-t.v%2,t.recoveryParam&&(n[32]|=128),t._vs=c(n.slice(32,64))}else{if(t.r=e.r,t.s=e.s,t.v=e.v,t.recoveryParam=e.recoveryParam,t._vs=e._vs,null!=t._vs){const n=u(p(t._vs),32);t._vs=c(n);const r=128<=n[0]?1:0;null==t.recoveryParam?t.recoveryParam=r:t.recoveryParam!==r&&ve.throwArgumentError("signature recoveryParam mismatch _vs","signature",e),n[0]&=127;const a=c(n);null==t.s?t.s=a:t.s!==a&&ve.throwArgumentError("signature v mismatch _vs","signature",e)}null==t.recoveryParam?null==t.v?ve.throwArgumentError("signature missing v and recoveryParam","signature",e):t.recoveryParam=1-t.v%2:null==t.v?t.v=27+t.recoveryParam:t.recoveryParam!==1-t.v%2&&ve.throwArgumentError("signature recoveryParam mismatch v","signature",e),null!=t.r&&y(t.r)?t.r=f(t.r,32):ve.throwArgumentError("signature missing or invalid r","signature",e),null!=t.s&&y(t.s)?t.s=f(t.s,32):ve.throwArgumentError("signature missing or invalid s","signature",e);const n=p(t.s);128<=n[0]&&ve.throwArgumentError("signature s out of range","signature",e),t.recoveryParam&&(n[0]|=128);const r=c(n);t._vs&&(!y(t._vs)&&ve.throwArgumentError("signature invalid _vs","signature",e),t._vs=f(t._vs,32)),null==t._vs?t._vs=r:t._vs!==r&&ve.throwArgumentError("signature _vs mismatch v and s","signature",e)}return t}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t["default"]:t,n=n&&Object.prototype.hasOwnProperty.call(n,"default")?n["default"]:n;var N="undefined"==typeof globalThis?"undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?{}:self:global:window:globalThis,B=a(function(e,t){(function(e,n){n(t)})(N,function(e){var oe=Math.abs,ie=Math.log;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}function n(e,t){return t={exports:{}},e(t,t.exports),t.exports}function a(e){return e&&e["default"]||e}function o(e,t){if(!e)throw new Error(t||"Assertion failed")}function d(e){return(e>>>24|65280&e>>>8|16711680&e<<8|(255&e)<<24)>>>0}function p(e){return 1===e.length?"0"+e:e}function l(e){return 7===e.length?"0"+e:6===e.length?"00"+e:5===e.length?"000"+e:4===e.length?"0000"+e:3===e.length?"00000"+e:2===e.length?"000000"+e:1===e.length?"0000000"+e:e}function u(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}function c(e,t,n){return e&t^~e&n}function m(e,t,n){return e&t^e&n^t&n}function g(e,t,n){return e^t^n}function k(){return this instanceof k?void(to.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=no,this.W=Array(64)):new k}function B(){return this instanceof B?void(fo.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=go,this.W=Array(160)):new B}function R(e,t,n,a,o){var i=e&n^~e&o;return 0>i&&(i+=4294967296),i}function M(e,t,n,a,o,i){var s=t&a^~t&i;return 0>s&&(s+=4294967296),s}function I(e,t,n,a,o){var i=e&n^e&o^n&o;return 0>i&&(i+=4294967296),i}function F(e,t,n,a,o,i){var s=t&a^t&i^a&i;return 0>s&&(s+=4294967296),s}function O(e,t){var n=ro(e,t,28),a=ro(t,e,2),o=ro(t,e,7),i=n^a^o;return 0>i&&(i+=4294967296),i}function D(e,t){var n=ao(e,t,28),a=ao(t,e,2),o=ao(t,e,7),i=n^a^o;return 0>i&&(i+=4294967296),i}function L(e,t){var n=ro(e,t,14),a=ro(e,t,18),o=ro(t,e,9),i=n^a^o;return 0>i&&(i+=4294967296),i}function U(e,t){var n=ao(e,t,14),a=ao(e,t,18),o=ao(t,e,9),i=n^a^o;return 0>i&&(i+=4294967296),i}function V(e,t){var n=ro(e,t,1),a=ro(e,t,8),o=oo(e,t,7),i=n^a^o;return 0>i&&(i+=4294967296),i}function z(e,t){var n=ao(e,t,1),a=ao(e,t,8),o=io(e,t,7),i=n^a^o;return 0>i&&(i+=4294967296),i}function H(e,t){var n=ro(e,t,19),a=ro(t,e,29),o=oo(e,t,6),i=n^a^o;return 0>i&&(i+=4294967296),i}function q(e,t){var n=ao(e,t,19),a=ao(t,e,29),o=io(e,t,6),i=n^a^o;return 0>i&&(i+=4294967296),i}function G(){return this instanceof G?void(To.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"):new G}function W(e,t,n,r){return 15>=e?t^n^r:31>=e?t&n|~t&r:47>=e?(t|~n)^r:63>=e?t&r|n&~r:t^(n|~r)}function i(e){return 15>=e?0:31>=e?1518500249:47>=e?1859775393:63>=e?2400959708:2840853838}function y(e){return 15>=e?1352829926:31>=e?1548603684:47>=e?1836072691:63>=e?2053994217:0}function f(e,t,n){return this instanceof f?void(this.Hash=e,this.blockSize=e.blockSize/8,this.outSize=e.outSize/8,this.inner=null,this.outer=null,this._init(Ha.toArray(t,n))):new f(e,t,n)}function K(e,t){this.type=e,this.p=new jo(t.p,16),this.red=t.prime?jo.red(t.prime):jo.mont(this.p),this.zero=new jo(0).toRed(this.red),this.one=new jo(1).toRed(this.red),this.two=new jo(2).toRed(this.red),this.n=t.n&&new jo(t.n,16),this.g=t.g&&this.pointFromJSON(t.g,t.gRed),this._wnafT1=[,,,,],this._wnafT2=[,,,,],this._wnafT3=[,,,,],this._wnafT4=[,,,,],this._bitLength=this.n?this.n.bitLength():0;var n=this.n&&this.p.div(this.n);!n||0<n.cmpn(100)?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function j(e,t){this.curve=e,this.type=t,this.precomputed=null}function Z(e){$o.call(this,"short",e),this.a=new jo(e.a,16).toRed(this.red),this.b=new jo(e.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=0===this.a.fromRed().cmpn(0),this.threeA=0===this.a.fromRed().sub(this.p).cmpn(-3),this.endo=this._getEndomorphism(e),this._endoWnafT1=[,,,,],this._endoWnafT2=[,,,,]}function J(e,t,n,r){$o.BasePoint.call(this,e,"affine"),null===t&&null===n?(this.x=null,this.y=null,this.inf=!0):(this.x=new jo(t,16),this.y=new jo(n,16),r&&(this.x.forceRed(this.curve.red),this.y.forceRed(this.curve.red)),!this.x.red&&(this.x=this.x.toRed(this.curve.red)),!this.y.red&&(this.y=this.y.toRed(this.curve.red)),this.inf=!1)}function X(e,t,n,r){$o.BasePoint.call(this,e,"jacobian"),null===t&&null===n&&null===r?(this.x=this.curve.one,this.y=this.curve.one,this.z=new jo(0)):(this.x=new jo(t,16),this.y=new jo(n,16),this.z=new jo(r,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}function Y(e){if(!(this instanceof Y))return new Y(e);this.hash=e.hash,this.predResist=!!e.predResist,this.outLen=this.hash.outSize,this.minEntropy=e.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var t=Wo.toArray(e.entropy,e.entropyEnc||"hex"),n=Wo.toArray(e.nonce,e.nonceEnc||"hex"),r=Wo.toArray(e.pers,e.persEnc||"hex");Va(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,n,r)}function Q(e,t){this.ec=e,this.priv=null,this.pub=null,t.priv&&this._importPrivate(t.priv,t.privEnc),t.pub&&this._importPublic(t.pub,t.pubEnc)}function $(e,t){return e instanceof $?e:void(this._importDER(e,t)||(di(e.r&&e.s,"Signature without r or s"),this.r=new jo(e.r,16),this.s=new jo(e.s,16),this.recoveryParam=void 0===e.recoveryParam?null:e.recoveryParam))}function ee(){this.place=0}function te(e,t){var n=e[t.place++];if(!(128&n))return n;var r=15&n;if(0==r||4<r)return!1;for(var a=0,o=0,s=t.place;o<r;o++,s++)a<<=8,a|=e[s],a>>>=0;return!(127>=a)&&(t.place=s,a)}function ne(e){for(var t=0,n=e.length-1;!e[t]&&!(128&e[t+1])&&t<n;)t++;return 0===t?e:e.slice(t)}function re(e,t){if(128>t)return void e.push(t);var n=1+(ie(t)/Math.LN2>>>3);for(e.push(128|n);--n;)e.push(255&t>>>(n<<3));e.push(t)}function ae(e){return this instanceof ae?void("string"==typeof e&&(li(ai.hasOwnProperty(e),"Unknown curve "+e),e=ai[e]),e instanceof ai.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash):new ae(e)}var se="undefined"==typeof globalThis?"undefined"==typeof window?"undefined"==typeof N?"undefined"==typeof self?{}:self:N:window:globalThis,de=Object.freeze({default:{}}),pe=a(de),le=n(function(e){(function(e,t){function n(e,t){if(!e)throw new Error(t||"Assertion failed")}function r(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}function o(e,t,n){return o.isBN(e)?e:void(this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&(("le"===t||"be"===t)&&(n=t,t=10),this._init(e||0,t||10,n||"be")))}function a(e,t,n){for(var a=0,o=P(e.length,n),s=t,d;s<o;s++)d=e.charCodeAt(s)-48,a<<=4,a|=49<=d&&54>=d?d-49+10:17<=d&&22>=d?d-17+10:15&d;return a}function s(e,t,n,a){for(var o=0,s=P(e.length,n),d=t,p;d<s;d++)p=e.charCodeAt(d)-48,o*=a,o+=49<=p?p-49+10:17<=p?p-17+10:p;return o}function d(e){for(var t=Array(e.bitLength()),n=0;n<t.length;n++){var r=0|n/26,a=n%26;t[n]=(e.words[r]&1<<a)>>>a}return t}function p(e,t,n){n.negative=t.negative^e.negative;var o=0|e.length+t.length;n.length=o,o=0|o-1;var s=0|e.words[0],d=0|t.words[0],p=s*d,l=67108863&p,u=0|p/67108864;n.words[0]=l;for(var y=1;y<o;y++){for(var c=u>>>26,m=67108863&u,f=P(y,t.length-1),g=E(0,y-e.length+1),h;g<=f;g++)h=0|y-g,s=0|e.words[h],d=0|t.words[g],p=s*d+m,c+=0|p/67108864,m=67108863&p;n.words[y]=0|m,u=0|c}return 0===u?n.length--:n.words[y]=0|u,n.strip()}function l(e,t,n){n.negative=t.negative^e.negative,n.length=e.length+t.length;for(var o=0,s=0,d=0,p;d<n.length-1;d++){p=s,s=0;for(var l=67108863&o,u=P(d,t.length-1),y=E(0,d-e.length+1);y<=u;y++){var c=d-y,i=0|e.words[c],a=0|t.words[y],m=i*a,r=67108863&m;p=0|p+(0|m/67108864),r=0|r+l,l=67108863&r,p=0|p+(r>>>26),s+=p>>>26,p&=67108863}n.words[d]=l,o=p,p=s}return 0===o?n.length--:n.words[d]=o,n.strip()}function u(e,t,n){var r=new y;return r.mulp(e,t,n)}function y(e,t){this.x=e,this.y=t}function c(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function m(){c.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function f(){c.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function g(){c.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function h(){c.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function k(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function S(e){k.call(this,e),this.shift=this.m.bitLength(),0!=this.shift%26&&(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 e?e.exports=o:t.BN=o,o.BN=o,o.wordSize=26;var C;try{C=pe.Buffer}catch(t){}o.isBN=function(e){return!!(e instanceof o)||null!==e&&"object"==typeof e&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return 0<e.cmp(t)?e:t},o.min=function(e,t){return 0>e.cmp(t)?e:t},o.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&2<=t&&36>=t),e=e.toString().replace(/\s+/g,"");var a=0;"-"===e[0]&&a++,16===t?this._parseHex(e,a):this._parseBase(e,t,a),"-"===e[0]&&(this.negative=1),this.strip();"le"!==r||this._initArray(this.toArray(),t,r)},o.prototype._initNumber=function(e,t,r){0>e&&(this.negative=1,e=-e),67108864>e?(this.words=[67108863&e],this.length=1):4503599627370496>e?(this.words=[67108863&e,67108863&e/67108864],this.length=2):(n(9007199254740992>e),this.words=[67108863&e,67108863&e/67108864,1],this.length=3);"le"!==r||this._initArray(this.toArray(),t,r)},o.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),0>=e.length)return this.words=[0],this.length=1,this;this.length=A(e.length/3),this.words=Array(this.length);for(var a=0;a<this.length;a++)this.words[a]=0;var o=0,s,d;if("be"===r)for(a=e.length-1,s=0;0<=a;a-=3)d=e[a]|e[a-1]<<8|e[a-2]<<16,this.words[s]|=67108863&d<<o,this.words[s+1]=67108863&d>>>26-o,o+=24,26<=o&&(o-=26,s++);else if("le"===r)for(a=0,s=0;a<e.length;a+=3)d=e[a]|e[a+1]<<8|e[a+2]<<16,this.words[s]|=67108863&d<<o,this.words[s+1]=67108863&d>>>26-o,o+=24,26<=o&&(o-=26,s++);return this.strip()},o.prototype._parseHex=function(e,t){this.length=A((e.length-t)/6),this.words=Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var r=0,o,s;for(n=e.length-6,o=0;n>=t;n-=6)s=a(e,n,n+6),this.words[o]|=67108863&s<<r,this.words[o+1]|=4194303&s>>>26-r,r+=24,26<=r&&(r-=26,o++);n+6!==t&&(s=a(e,t,n+6),this.words[o]|=67108863&s<<r,this.words[o+1]|=4194303&s>>>26-r),this.strip()},o.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var r=0,a=1;67108863>=a;a*=t)r++;r--,a=0|a/t;for(var o=e.length-n,d=o%r,p=P(o,o-d)+n,l=0,u=n;u<p;u+=r)l=s(e,u,u+r,t),this.imuln(a),67108864>this.words[0]+l?this.words[0]+=l:this._iaddn(l);if(0!==d){var y=1;for(l=s(e,u,e.length,t),u=0;u<d;u++)y*=t;this.imuln(y),67108864>this.words[0]+l?this.words[0]+=l:this._iaddn(l)}},o.prototype.copy=function(e){e.words=Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},o.prototype.clone=function(){var e=new o(null);return this.copy(e),e},o.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},o.prototype.strip=function(){for(;1<this.length&&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},o.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var N=["","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"],B=[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],R=[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(e,t){e=e||10,t=0|t||1;var a;if(16===e||"hex"===e){a="";for(var o=0,s=0,d=0;d<this.length;d++){var p=this.words[d],l=(16777215&(p<<o|s)).toString(16);s=16777215&p>>>24-o,a=0!==s||d!==this.length-1?N[6-l.length]+l+a:l+a,o+=2,26<=o&&(o-=26,d--)}for(0!==s&&(a=s.toString(16)+a);0!=a.length%t;)a="0"+a;return 0!==this.negative&&(a="-"+a),a}if(e===(0|e)&&2<=e&&36>=e){var u=B[e],y=R[e];a="";var m=this.clone();for(m.negative=0;!m.isZero();){var f=m.modn(y).toString(e);m=m.idivn(y),a=m.isZero()?f+a:N[u-f.length]+f+a}for(this.isZero()&&(a="0"+a);0!=a.length%t;)a="0"+a;return 0!==this.negative&&(a="-"+a),a}n(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:2<this.length&&n(!1,"Number can only safely store up to 53 bits"),0===this.negative?e:-e},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(e,t){return n("undefined"!=typeof C),this.toArrayLike(C,e,t)},o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,r){var a=this.byteLength(),o=r||E(1,a);n(a<=o,"byte array longer than desired length"),n(0<o,"Requested array length <= 0"),this.strip();var s=new e(o),d=this.clone(),p,l;if(!("le"===t)){for(l=0;l<o-a;l++)s[l]=0;for(l=0;!d.isZero();l++)p=d.andln(255),d.iushrn(8),s[o-l-1]=p}else{for(l=0;!d.isZero();l++)p=d.andln(255),d.iushrn(8),s[l]=p;for(;l<o;l++)s[l]=0}return s},o.prototype._countBits=x?function(e){return 32-x(e)}:function(e){var n=e,a=0;return 4096<=n&&(a+=13,n>>>=13),64<=n&&(a+=7,n>>>=7),8<=n&&(a+=4,n>>>=4),2<=n&&(a+=2,n>>>=2),a+n},o.prototype._zeroBits=function(e){if(0===e)return 26;var n=e,a=0;return 0==(8191&n)&&(a+=13,n>>>=13),0==(127&n)&&(a+=7,n>>>=7),0==(15&n)&&(a+=4,n>>>=4),0==(3&n)&&(a+=2,n>>>=2),0==(1&n)&&a++,a},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0,n;t<this.length&&(n=this._zeroBits(this.words[t]),e+=n,26===n);t++);return e},o.prototype.byteLength=function(){return A(this.bitLength()/8)},o.prototype.toTwos=function(e){return 0===this.negative?this.clone():this.abs().inotn(e).iaddn(1)},o.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).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(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]|=e.words[t];return this.strip()},o.prototype.ior=function(e){return n(0==(this.negative|e.negative)),this.iuor(e)},o.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t=this.length>e.length?e:this;for(var n=0;n<t.length;n++)this.words[n]&=e.words[n];return this.length=t.length,this.strip()},o.prototype.iand=function(e){return n(0==(this.negative|e.negative)),this.iuand(e)},o.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.prototype.iuxor=function(e){var t,n;this.length>e.length?(t=this,n=e):(t=e,n=this);for(var r=0;r<n.length;r++)this.words[r]=t.words[r]^n.words[r];if(this!==t)for(;r<t.length;r++)this.words[r]=t.words[r];return this.length=t.length,this.strip()},o.prototype.ixor=function(e){return n(0==(this.negative|e.negative)),this.iuxor(e)},o.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){n("number"==typeof e&&0<=e);var t=0|A(e/26),r=e%26;this._expand(t),0<r&&t--;for(var a=0;a<t;a++)this.words[a]=67108863&~this.words[a];return 0<r&&(this.words[a]=~this.words[a]&67108863>>26-r),this.strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){n("number"==typeof e&&0<=e);var r=0|e/26,a=e%26;return this._expand(r+1),t?this.words[r]|=1<<a:this.words[r]&=~(1<<a),this.strip()},o.prototype.iadd=function(e){var t;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();var n,o;this.length>e.length?(n=this,o=e):(n=e,o=this);for(var s=0,d=0;d<o.length;d++)t=(0|n.words[d])+(0|o.words[d])+s,this.words[d]=67108863&t,s=t>>>26;for(;0!==s&&d<n.length;d++)t=(0|n.words[d])+s,this.words[d]=67108863&t,s=t>>>26;if(this.length=n.length,0!==s)this.words[this.length]=s,this.length++;else if(n!==this)for(;d<n.length;d++)this.words[d]=n.words[d];return this},o.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var n=this.cmp(e);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;var o,s;0<n?(o=this,s=e):(o=e,s=this);for(var d=0,p=0;p<s.length;p++)t=(0|o.words[p])-(0|s.words[p])+d,d=t>>26,this.words[p]=67108863&t;for(;0!==d&&p<o.length;p++)t=(0|o.words[p])+d,d=t>>26,this.words[p]=67108863&t;if(0===d&&p<o.length&&o!==this)for(;p<o.length;p++)this.words[p]=o.words[p];return this.length=E(this.length,p),o!==this&&(this.negative=1),this.strip()},o.prototype.sub=function(e){return this.clone().isub(e)};var M=function(e,t,n){var r=e.words,a=t.words,i=n.words,o=0,s=0|r[0],d=8191&s,p=s>>>13,l=0|r[1],u=8191&l,y=l>>>13,m=0|r[2],f=8191&m,g=m>>>13,h=0|r[3],b=8191&h,v=h>>>13,w=0|r[4],_=8191&w,x=w>>>13,A=0|r[5],E=8191&A,k=A>>>13,P=0|r[6],S=8191&P,C=P>>>13,N=0|r[7],B=8191&N,R=N>>>13,M=0|r[8],I=8191&M,F=M>>>13,O=0|r[9],D=8191&O,L=O>>>13,U=0|a[0],V=8191&U,z=U>>>13,H=0|a[1],q=8191&H,K=H>>>13,G=0|a[2],j=8191&G,W=G>>>13,Z=0|a[3],J=8191&Z,X=Z>>>13,Y=0|a[4],Q=8191&Y,$=Y>>>13,ee=0|a[5],te=8191&ee,ne=ee>>>13,re=0|a[6],ae=8191&re,oe=re>>>13,ie=0|a[7],se=8191&ie,de=ie>>>13,pe=0|a[8],le=8191&pe,ue=pe>>>13,ye=0|a[9],ce=8191&ye,me=ye>>>13,fe,ge,he;n.negative=e.negative^t.negative,n.length=19,fe=T(d,V),ge=T(d,z),ge=0|ge+T(p,V),he=T(p,z);var be=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(be>>>26),be&=67108863,fe=T(u,V),ge=T(u,z),ge=0|ge+T(y,V),he=T(y,z),fe=0|fe+T(d,q),ge=0|ge+T(d,K),ge=0|ge+T(p,q),he=0|he+T(p,K);var ve=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(ve>>>26),ve&=67108863,fe=T(f,V),ge=T(f,z),ge=0|ge+T(g,V),he=T(g,z),fe=0|fe+T(u,q),ge=0|ge+T(u,K),ge=0|ge+T(y,q),he=0|he+T(y,K),fe=0|fe+T(d,j),ge=0|ge+T(d,W),ge=0|ge+T(p,j),he=0|he+T(p,W);var we=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(we>>>26),we&=67108863,fe=T(b,V),ge=T(b,z),ge=0|ge+T(v,V),he=T(v,z),fe=0|fe+T(f,q),ge=0|ge+T(f,K),ge=0|ge+T(g,q),he=0|he+T(g,K),fe=0|fe+T(u,j),ge=0|ge+T(u,W),ge=0|ge+T(y,j),he=0|he+T(y,W),fe=0|fe+T(d,J),ge=0|ge+T(d,X),ge=0|ge+T(p,J),he=0|he+T(p,X);var _e=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(_e>>>26),_e&=67108863,fe=T(_,V),ge=T(_,z),ge=0|ge+T(x,V),he=T(x,z),fe=0|fe+T(b,q),ge=0|ge+T(b,K),ge=0|ge+T(v,q),he=0|he+T(v,K),fe=0|fe+T(f,j),ge=0|ge+T(f,W),ge=0|ge+T(g,j),he=0|he+T(g,W),fe=0|fe+T(u,J),ge=0|ge+T(u,X),ge=0|ge+T(y,J),he=0|he+T(y,X),fe=0|fe+T(d,Q),ge=0|ge+T(d,$),ge=0|ge+T(p,Q),he=0|he+T(p,$);var Te=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Te>>>26),Te&=67108863,fe=T(E,V),ge=T(E,z),ge=0|ge+T(k,V),he=T(k,z),fe=0|fe+T(_,q),ge=0|ge+T(_,K),ge=0|ge+T(x,q),he=0|he+T(x,K),fe=0|fe+T(b,j),ge=0|ge+T(b,W),ge=0|ge+T(v,j),he=0|he+T(v,W),fe=0|fe+T(f,J),ge=0|ge+T(f,X),ge=0|ge+T(g,J),he=0|he+T(g,X),fe=0|fe+T(u,Q),ge=0|ge+T(u,$),ge=0|ge+T(y,Q),he=0|he+T(y,$),fe=0|fe+T(d,te),ge=0|ge+T(d,ne),ge=0|ge+T(p,te),he=0|he+T(p,ne);var xe=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(xe>>>26),xe&=67108863,fe=T(S,V),ge=T(S,z),ge=0|ge+T(C,V),he=T(C,z),fe=0|fe+T(E,q),ge=0|ge+T(E,K),ge=0|ge+T(k,q),he=0|he+T(k,K),fe=0|fe+T(_,j),ge=0|ge+T(_,W),ge=0|ge+T(x,j),he=0|he+T(x,W),fe=0|fe+T(b,J),ge=0|ge+T(b,X),ge=0|ge+T(v,J),he=0|he+T(v,X),fe=0|fe+T(f,Q),ge=0|ge+T(f,$),ge=0|ge+T(g,Q),he=0|he+T(g,$),fe=0|fe+T(u,te),ge=0|ge+T(u,ne),ge=0|ge+T(y,te),he=0|he+T(y,ne),fe=0|fe+T(d,ae),ge=0|ge+T(d,oe),ge=0|ge+T(p,ae),he=0|he+T(p,oe);var Ae=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Ae>>>26),Ae&=67108863,fe=T(B,V),ge=T(B,z),ge=0|ge+T(R,V),he=T(R,z),fe=0|fe+T(S,q),ge=0|ge+T(S,K),ge=0|ge+T(C,q),he=0|he+T(C,K),fe=0|fe+T(E,j),ge=0|ge+T(E,W),ge=0|ge+T(k,j),he=0|he+T(k,W),fe=0|fe+T(_,J),ge=0|ge+T(_,X),ge=0|ge+T(x,J),he=0|he+T(x,X),fe=0|fe+T(b,Q),ge=0|ge+T(b,$),ge=0|ge+T(v,Q),he=0|he+T(v,$),fe=0|fe+T(f,te),ge=0|ge+T(f,ne),ge=0|ge+T(g,te),he=0|he+T(g,ne),fe=0|fe+T(u,ae),ge=0|ge+T(u,oe),ge=0|ge+T(y,ae),he=0|he+T(y,oe),fe=0|fe+T(d,se),ge=0|ge+T(d,de),ge=0|ge+T(p,se),he=0|he+T(p,de);var Ee=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Ee>>>26),Ee&=67108863,fe=T(I,V),ge=T(I,z),ge=0|ge+T(F,V),he=T(F,z),fe=0|fe+T(B,q),ge=0|ge+T(B,K),ge=0|ge+T(R,q),he=0|he+T(R,K),fe=0|fe+T(S,j),ge=0|ge+T(S,W),ge=0|ge+T(C,j),he=0|he+T(C,W),fe=0|fe+T(E,J),ge=0|ge+T(E,X),ge=0|ge+T(k,J),he=0|he+T(k,X),fe=0|fe+T(_,Q),ge=0|ge+T(_,$),ge=0|ge+T(x,Q),he=0|he+T(x,$),fe=0|fe+T(b,te),ge=0|ge+T(b,ne),ge=0|ge+T(v,te),he=0|he+T(v,ne),fe=0|fe+T(f,ae),ge=0|ge+T(f,oe),ge=0|ge+T(g,ae),he=0|he+T(g,oe),fe=0|fe+T(u,se),ge=0|ge+T(u,de),ge=0|ge+T(y,se),he=0|he+T(y,de),fe=0|fe+T(d,le),ge=0|ge+T(d,ue),ge=0|ge+T(p,le),he=0|he+T(p,ue);var ke=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(ke>>>26),ke&=67108863,fe=T(D,V),ge=T(D,z),ge=0|ge+T(L,V),he=T(L,z),fe=0|fe+T(I,q),ge=0|ge+T(I,K),ge=0|ge+T(F,q),he=0|he+T(F,K),fe=0|fe+T(B,j),ge=0|ge+T(B,W),ge=0|ge+T(R,j),he=0|he+T(R,W),fe=0|fe+T(S,J),ge=0|ge+T(S,X),ge=0|ge+T(C,J),he=0|he+T(C,X),fe=0|fe+T(E,Q),ge=0|ge+T(E,$),ge=0|ge+T(k,Q),he=0|he+T(k,$),fe=0|fe+T(_,te),ge=0|ge+T(_,ne),ge=0|ge+T(x,te),he=0|he+T(x,ne),fe=0|fe+T(b,ae),ge=0|ge+T(b,oe),ge=0|ge+T(v,ae),he=0|he+T(v,oe),fe=0|fe+T(f,se),ge=0|ge+T(f,de),ge=0|ge+T(g,se),he=0|he+T(g,de),fe=0|fe+T(u,le),ge=0|ge+T(u,ue),ge=0|ge+T(y,le),he=0|he+T(y,ue),fe=0|fe+T(d,ce),ge=0|ge+T(d,me),ge=0|ge+T(p,ce),he=0|he+T(p,me);var Pe=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Pe>>>26),Pe&=67108863,fe=T(D,q),ge=T(D,K),ge=0|ge+T(L,q),he=T(L,K),fe=0|fe+T(I,j),ge=0|ge+T(I,W),ge=0|ge+T(F,j),he=0|he+T(F,W),fe=0|fe+T(B,J),ge=0|ge+T(B,X),ge=0|ge+T(R,J),he=0|he+T(R,X),fe=0|fe+T(S,Q),ge=0|ge+T(S,$),ge=0|ge+T(C,Q),he=0|he+T(C,$),fe=0|fe+T(E,te),ge=0|ge+T(E,ne),ge=0|ge+T(k,te),he=0|he+T(k,ne),fe=0|fe+T(_,ae),ge=0|ge+T(_,oe),ge=0|ge+T(x,ae),he=0|he+T(x,oe),fe=0|fe+T(b,se),ge=0|ge+T(b,de),ge=0|ge+T(v,se),he=0|he+T(v,de),fe=0|fe+T(f,le),ge=0|ge+T(f,ue),ge=0|ge+T(g,le),he=0|he+T(g,ue),fe=0|fe+T(u,ce),ge=0|ge+T(u,me),ge=0|ge+T(y,ce),he=0|he+T(y,me);var Se=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Se>>>26),Se&=67108863,fe=T(D,j),ge=T(D,W),ge=0|ge+T(L,j),he=T(L,W),fe=0|fe+T(I,J),ge=0|ge+T(I,X),ge=0|ge+T(F,J),he=0|he+T(F,X),fe=0|fe+T(B,Q),ge=0|ge+T(B,$),ge=0|ge+T(R,Q),he=0|he+T(R,$),fe=0|fe+T(S,te),ge=0|ge+T(S,ne),ge=0|ge+T(C,te),he=0|he+T(C,ne),fe=0|fe+T(E,ae),ge=0|ge+T(E,oe),ge=0|ge+T(k,ae),he=0|he+T(k,oe),fe=0|fe+T(_,se),ge=0|ge+T(_,de),ge=0|ge+T(x,se),he=0|he+T(x,de),fe=0|fe+T(b,le),ge=0|ge+T(b,ue),ge=0|ge+T(v,le),he=0|he+T(v,ue),fe=0|fe+T(f,ce),ge=0|ge+T(f,me),ge=0|ge+T(g,ce),he=0|he+T(g,me);var Ce=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Ce>>>26),Ce&=67108863,fe=T(D,J),ge=T(D,X),ge=0|ge+T(L,J),he=T(L,X),fe=0|fe+T(I,Q),ge=0|ge+T(I,$),ge=0|ge+T(F,Q),he=0|he+T(F,$),fe=0|fe+T(B,te),ge=0|ge+T(B,ne),ge=0|ge+T(R,te),he=0|he+T(R,ne),fe=0|fe+T(S,ae),ge=0|ge+T(S,oe),ge=0|ge+T(C,ae),he=0|he+T(C,oe),fe=0|fe+T(E,se),ge=0|ge+T(E,de),ge=0|ge+T(k,se),he=0|he+T(k,de),fe=0|fe+T(_,le),ge=0|ge+T(_,ue),ge=0|ge+T(x,le),he=0|he+T(x,ue),fe=0|fe+T(b,ce),ge=0|ge+T(b,me),ge=0|ge+T(v,ce),he=0|he+T(v,me);var Ne=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Ne>>>26),Ne&=67108863,fe=T(D,Q),ge=T(D,$),ge=0|ge+T(L,Q),he=T(L,$),fe=0|fe+T(I,te),ge=0|ge+T(I,ne),ge=0|ge+T(F,te),he=0|he+T(F,ne),fe=0|fe+T(B,ae),ge=0|ge+T(B,oe),ge=0|ge+T(R,ae),he=0|he+T(R,oe),fe=0|fe+T(S,se),ge=0|ge+T(S,de),ge=0|ge+T(C,se),he=0|he+T(C,de),fe=0|fe+T(E,le),ge=0|ge+T(E,ue),ge=0|ge+T(k,le),he=0|he+T(k,ue),fe=0|fe+T(_,ce),ge=0|ge+T(_,me),ge=0|ge+T(x,ce),he=0|he+T(x,me);var Be=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Be>>>26),Be&=67108863,fe=T(D,te),ge=T(D,ne),ge=0|ge+T(L,te),he=T(L,ne),fe=0|fe+T(I,ae),ge=0|ge+T(I,oe),ge=0|ge+T(F,ae),he=0|he+T(F,oe),fe=0|fe+T(B,se),ge=0|ge+T(B,de),ge=0|ge+T(R,se),he=0|he+T(R,de),fe=0|fe+T(S,le),ge=0|ge+T(S,ue),ge=0|ge+T(C,le),he=0|he+T(C,ue),fe=0|fe+T(E,ce),ge=0|ge+T(E,me),ge=0|ge+T(k,ce),he=0|he+T(k,me);var Re=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Re>>>26),Re&=67108863,fe=T(D,ae),ge=T(D,oe),ge=0|ge+T(L,ae),he=T(L,oe),fe=0|fe+T(I,se),ge=0|ge+T(I,de),ge=0|ge+T(F,se),he=0|he+T(F,de),fe=0|fe+T(B,le),ge=0|ge+T(B,ue),ge=0|ge+T(R,le),he=0|he+T(R,ue),fe=0|fe+T(S,ce),ge=0|ge+T(S,me),ge=0|ge+T(C,ce),he=0|he+T(C,me);var Me=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Me>>>26),Me&=67108863,fe=T(D,se),ge=T(D,de),ge=0|ge+T(L,se),he=T(L,de),fe=0|fe+T(I,le),ge=0|ge+T(I,ue),ge=0|ge+T(F,le),he=0|he+T(F,ue),fe=0|fe+T(B,ce),ge=0|ge+T(B,me),ge=0|ge+T(R,ce),he=0|he+T(R,me);var Ie=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Ie>>>26),Ie&=67108863,fe=T(D,le),ge=T(D,ue),ge=0|ge+T(L,le),he=T(L,ue),fe=0|fe+T(I,ce),ge=0|ge+T(I,me),ge=0|ge+T(F,ce),he=0|he+T(F,me);var Fe=0|(0|o+fe)+((8191&ge)<<13);o=0|(0|he+(ge>>>13))+(Fe>>>26),Fe&=67108863,fe=T(D,ce),ge=T(D,me),ge=0|ge+T(L,ce),he=T(L,me);var Oe=0|(0|o+fe)+((8191&ge)<<13);return o=0|(0|he+(ge>>>13))+(Oe>>>26),Oe&=67108863,i[0]=be,i[1]=ve,i[2]=we,i[3]=_e,i[4]=Te,i[5]=xe,i[6]=Ae,i[7]=Ee,i[8]=ke,i[9]=Pe,i[10]=Se,i[11]=Ce,i[12]=Ne,i[13]=Be,i[14]=Re,i[15]=Me,i[16]=Ie,i[17]=Fe,i[18]=Oe,0!==o&&(i[19]=o,n.length++),n};T||(M=p),o.prototype.mulTo=function(e,t){var n=this.length+e.length,r;return r=10===this.length&&10===e.length?M(this,e,t):63>n?p(this,e,t):1024>n?l(this,e,t):u(this,e,t),r},y.prototype.makeRBT=function(e){for(var n=Array(e),t=o.prototype._countBits(e)-1,r=0;r<e;r++)n[r]=this.revBin(r,t,e);return n},y.prototype.revBin=function(e,t,n){if(0===e||e===n-1)return e;for(var r=0,a=0;a<t;a++)r|=(1&e)<<t-a-1,e>>=1;return r},y.prototype.permute=function(e,t,n,r,a,o){for(var s=0;s<o;s++)r[s]=t[e[s]],a[s]=n[e[s]]},y.prototype.transform=function(e,t,n,r,a,o){this.permute(o,e,t,n,r,a);for(var i=1;i<a;i<<=1)for(var d=i<<1,l=w(2*_/d),u=v(2*_/d),y=0;y<a;y+=d)for(var c=l,m=u,f=0;f<i;f++){var g=n[y+f],h=r[y+f],b=n[y+f+i],T=r[y+f+i],x=c*b-m*T;T=c*T+m*b,b=x,n[y+f]=g+b,r[y+f]=h+T,n[y+f+i]=g-b,r[y+f+i]=h-T,f!==d&&(x=l*c-u*m,m=l*m+u*c,c=x)}},y.prototype.guessLen13b=function(e,t){var n=1|E(t,e),r=1&n,a=0;for(n=0|n/2;n;n>>>=1)a++;return 1<<a+1+r},y.prototype.conjugate=function(e,n,r){if(!(1>=r))for(var a=0,o;a<r/2;a++)o=e[a],e[a]=e[r-a-1],e[r-a-1]=o,o=n[a],n[a]=-n[r-a-1],n[r-a-1]=-o},y.prototype.normalize13b=function(e,t){for(var n=0,r=0,a;r<t/2;r++)a=8192*b(e[2*r+1]/t)+b(e[2*r]/t)+n,e[r]=67108863&a,n=67108864>a?0:0|a/67108864;return e},y.prototype.convert13b=function(e,t,r,a){for(var o=0,s=0;s<t;s++)o+=0|e[s],r[2*s]=8191&o,o>>>=13,r[2*s+1]=8191&o,o>>>=13;for(s=2*t;s<a;++s)r[s]=0;n(0===o),n(0==(-8192&o))},y.prototype.stub=function(e){for(var t=Array(e),n=0;n<e;n++)t[n]=0;return t},y.prototype.mulp=function(e,t,n){var r=2*this.guessLen13b(e.length,t.length),a=this.makeRBT(r),o=this.stub(r),s=Array(r),d=Array(r),p=Array(r),l=Array(r),u=Array(r),y=Array(r),c=n.words;c.length=r,this.convert13b(e.words,e.length,s,r),this.convert13b(t.words,t.length,l,r),this.transform(s,o,d,p,r,a),this.transform(l,o,u,y,r,a);for(var m=0,f;m<r;m++)f=d[m]*u[m]-p[m]*y[m],p[m]=d[m]*y[m]+p[m]*u[m],d[m]=f;return this.conjugate(d,p,r),this.transform(d,p,c,o,r,a),this.conjugate(c,o,r),this.normalize13b(c,r),n.negative=e.negative^t.negative,n.length=e.length+t.length,n.strip()},o.prototype.mul=function(e){var t=new o(null);return t.words=Array(this.length+e.length),this.mulTo(e,t)},o.prototype.mulf=function(e){var t=new o(null);return t.words=Array(this.length+e.length),u(this,e,t)},o.prototype.imul=function(e){return this.clone().mulTo(e,this)},o.prototype.imuln=function(e){n("number"==typeof e),n(67108864>e);for(var t=0,r=0;r<this.length;r++){var a=(0|this.words[r])*e,o=(67108863&a)+(67108863&t);t>>=26,t+=0|a/67108864,t+=o>>>26,this.words[r]=67108863&o}return 0!==t&&(this.words[r]=t,this.length++),this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=d(e);if(0===t.length)return new o(1);for(var n=this,r=0;r<t.length&&!(0!==t[r]);r++,n=n.sqr());if(++r<t.length)for(var a=n.sqr();r<t.length;r++,a=a.sqr())0!==t[r]&&(n=n.mul(a));return n},o.prototype.iushln=function(e){n("number"==typeof e&&0<=e);var t=e%26,r=(e-t)/26,a;if(0!=t){var o=0;for(a=0;a<this.length;a++){var s=this.words[a]&67108863>>>26-t<<26-t,d=(0|this.words[a])-s<<t;this.words[a]=d|o,o=s>>>26-t}o&&(this.words[a]=o,this.length++)}if(0!==r){for(a=this.length-1;0<=a;a--)this.words[a+r]=this.words[a];for(a=0;a<r;a++)this.words[a]=0;this.length+=r}return this.strip()},o.prototype.ishln=function(e){return n(0===this.negative),this.iushln(e)},o.prototype.iushrn=function(e,t,a){n("number"==typeof e&&0<=e);var o=t?(t-t%26)/26:0;var d=e%26,r=P((e-d)/26,this.length),s=a;if(o-=r,o=E(0,o),s){for(var p=0;p<r;p++)s.words[p]=this.words[p];s.length=r}if(0===r);else if(this.length>r)for(this.length-=r,p=0;p<this.length;p++)this.words[p]=this.words[p+r];else this.words[0]=0,this.length=1;var l=0;for(p=this.length-1;0<=p&&(0!==l||p>=o);p--){var u=0|this.words[p];this.words[p]=l<<26-d|u>>>d,l=u&(67108863^67108863>>>d<<d)}return s&&0!==l&&(s.words[s.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(e,t,r){return n(0===this.negative),this.iushrn(e,t,r)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){n("number"==typeof e&&0<=e);var t=e%26,r=(e-t)/26;if(this.length<=r)return!1;var a=this.words[r];return!!(a&1<<t)},o.prototype.imaskn=function(e){n("number"==typeof e&&0<=e);var t=e%26,r=(e-t)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!=t&&r++,this.length=P(r,this.length),0!=t){this.words[this.length-1]&=67108863^67108863>>>t<<t}return this.strip()},o.prototype.maskn=function(e){return this.clone().imaskn(e)},o.prototype.iaddn=function(e){return n("number"==typeof e),n(67108864>e),0>e?this.isubn(-e):0===this.negative?this._iaddn(e):1===this.length&&(0|this.words[0])<e?(this.words[0]=e-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this)},o.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&67108864<=this.words[t];t++)this.words[t]-=67108864,t==this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=E(this.length,t+1),this},o.prototype.isubn=function(e){if(n("number"==typeof e),n(67108864>e),0>e)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&0>this.words[0])this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&0>this.words[t];t++)this.words[t]+=67108864,this.words[t+1]-=1;return this.strip()},o.prototype.addn=function(e){return this.clone().iaddn(e)},o.prototype.subn=function(e){return this.clone().isubn(e)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(e,t,r){var a=e.length+r,o;this._expand(a);var s=0,d;for(o=0;o<e.length;o++){d=(0|this.words[o+r])+s;var p=(0|e.words[o])*t;d-=67108863&p,s=(d>>26)-(0|p/67108864),this.words[o+r]=67108863&d}for(;o<this.length-r;o++)d=(0|this.words[o+r])+s,s=d>>26,this.words[o+r]=67108863&d;if(0===s)return this.strip();for(n(-1===s),s=0,o=0;o<this.length;o++)d=-(0|this.words[o])+s,s=d>>26,this.words[o]=67108863&d;return this.negative=1,this.strip()},o.prototype._wordDiv=function(e,t){var n=this.length-e.length,r=this.clone(),s=e,d=0|s.words[s.length-1],p=this._countBits(d);n=26-p,0!=n&&(s=s.ushln(n),r.iushln(n),d=0|s.words[s.length-1]);var l=r.length-s.length,u;if("mod"!==t){u=new o(null),u.length=l+1,u.words=Array(u.length);for(var y=0;y<u.length;y++)u.words[y]=0}var c=r.clone()._ishlnsubmul(s,1,l);0===c.negative&&(r=c,u&&(u.words[l]=1));for(var m=l-1,f;0<=m;m--){for(f=67108864*(0|r.words[s.length+m])+(0|r.words[s.length+m-1]),f=P(0|f/d,67108863),r._ishlnsubmul(s,f,m);0!==r.negative;)f--,r.negative=0,r._ishlnsubmul(s,1,m),r.isZero()||(r.negative^=1);u&&(u.words[m]=f)}return u&&u.strip(),r.strip(),"div"!==t&&0!==n&&r.iushrn(n),{div:u||null,mod:r}},o.prototype.divmod=function(e,t,r){if(n(!e.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var a,i,s;return 0!==this.negative&&0===e.negative?(s=this.neg().divmod(e,t),"mod"!==t&&(a=s.div.neg()),"div"!==t&&(i=s.mod.neg(),r&&0!==i.negative&&i.iadd(e)),{div:a,mod:i}):0===this.negative&&0!==e.negative?(s=this.divmod(e.neg(),t),"mod"!==t&&(a=s.div.neg()),{div:a,mod:s.mod}):0==(this.negative&e.negative)?e.length>this.length||0>this.cmp(e)?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modn(e.words[0]))}:this._wordDiv(e,t):(s=this.neg().divmod(e.neg(),t),"div"!==t&&(i=s.mod.neg(),r&&0!==i.negative&&i.isub(e)),{div:s.div,mod:i})},o.prototype.div=function(e){return this.divmod(e,"div",!1).div},o.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var n=0===t.div.negative?t.mod:t.mod.isub(e),r=e.ushrn(1),a=e.andln(1),o=n.cmp(r);return 0>o||1===a&&0===o?t.div:0===t.div.negative?t.div.iaddn(1):t.div.isubn(1)},o.prototype.modn=function(e){n(67108863>=e);for(var t=0,r=this.length-1;0<=r;r--)t=(67108864%e*t+(0|this.words[r]))%e;return t},o.prototype.idivn=function(e){n(67108863>=e);for(var t=0,r=this.length-1,a;0<=r;r--)a=(0|this.words[r])+67108864*t,this.words[r]=0|a/e,t=a%e;return this.strip()},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0===t.negative?t.clone():t.umod(e);for(var a=new o(1),s=new o(0),d=new o(0),p=new o(1),l=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++l;for(var u=r.clone(),y=t.clone();!t.isZero();){for(var c=0,m=1;0==(t.words[0]&m)&&26>c;++c,m<<=1);if(0<c)for(t.iushrn(c);0<c--;)(a.isOdd()||s.isOdd())&&(a.iadd(u),s.isub(y)),a.iushrn(1),s.iushrn(1);for(var f=0,h=1;0==(r.words[0]&h)&&26>f;++f,h<<=1);if(0<f)for(r.iushrn(f);0<f--;)(d.isOdd()||p.isOdd())&&(d.iadd(u),p.isub(y)),d.iushrn(1),p.iushrn(1);0<=t.cmp(r)?(t.isub(r),a.isub(d),s.isub(p)):(r.isub(t),d.isub(a),p.isub(s))}return{a:d,b:p,gcd:r.iushln(l)}},o.prototype._invmp=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0===t.negative?t.clone():t.umod(e);for(var s=new o(1),d=new o(0),p=r.clone();0<t.cmpn(1)&&0<r.cmpn(1);){for(var l=0,u=1;0==(t.words[0]&u)&&26>l;++l,u<<=1);if(0<l)for(t.iushrn(l);0<l--;)s.isOdd()&&s.iadd(p),s.iushrn(1);for(var y=0,c=1;0==(r.words[0]&c)&&26>y;++y,c<<=1);if(0<y)for(r.iushrn(y);0<y--;)d.isOdd()&&d.iadd(p),d.iushrn(1);0<=t.cmp(r)?(t.isub(r),s.isub(d)):(r.isub(t),d.isub(s))}var m;return m=0===t.cmpn(1)?s:d,0>m.cmpn(0)&&m.iadd(e),m},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var n=this.clone(),o=e.clone();n.negative=0,o.negative=0;for(var i=0;n.isEven()&&o.isEven();i++)n.iushrn(1),o.iushrn(1);do{for(;n.isEven();)n.iushrn(1);for(;o.isEven();)o.iushrn(1);var s=n.cmp(o);if(0>s){var r=n;n=o,o=r}else if(0===s||0===o.cmpn(1))break;n.isub(o)}while(!0);return o.iushln(i)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){n("number"==typeof e);var t=e%26,r=(e-t)/26,a=1<<t;if(this.length<=r)return this._expand(r+1),this.words[r]|=a,this;for(var o=a,s=r,d;0!==o&&s<this.length;s++)d=0|this.words[s],d+=o,o=d>>>26,d&=67108863,this.words[s]=d;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(e){var t=0>e;if(0!==this.negative&&!t)return-1;if(0===this.negative&&t)return 1;this.strip();var r;if(1<this.length)r=1;else{t&&(e=-e),n(67108863>=e,"Number is too big");var a=0|this.words[0];r=a===e?0:a<e?-1:1}return 0===this.negative?r:0|-r},o.prototype.cmp=function(e){if(0!==this.negative&&0===e.negative)return-1;if(0===this.negative&&0!==e.negative)return 1;var t=this.ucmp(e);return 0===this.negative?t:0|-t},o.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,n=this.length-1;0<=n;n--){var r=0|this.words[n],a=0|e.words[n];if(r!==a){r<a?t=-1:r>a&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return 0<=this.cmpn(e)},o.prototype.gte=function(e){return 0<=this.cmp(e)},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return 0>=this.cmpn(e)},o.prototype.lte=function(e){return 0>=this.cmp(e)},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new k(e)},o.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var I={k256:null,p224:null,p192:null,p25519:null};c.prototype._tmp=function(){var e=new o(null);return e.words=Array(A(this.n/13)),e},c.prototype.ireduce=function(e){var t=e,n;do this.split(t,this.tmp),t=this.imulK(t),t=t.iadd(this.tmp),n=t.bitLength();while(n>this.n);var a=n<this.n?-1:t.ucmp(this.p);return 0===a?(t.words[0]=0,t.length=1):0<a?t.isub(this.p):void 0===t.strip?t._strip():t.strip(),t},c.prototype.split=function(e,t){e.iushrn(this.n,0,t)},c.prototype.imulK=function(e){return e.imul(this.k)},r(m,c),m.prototype.split=function(e,t){for(var n=4194303,r=P(e.length,9),a=0;a<r;a++)t.words[a]=e.words[a];if(t.length=r,9>=e.length)return e.words[0]=0,void(e.length=1);var o=e.words[9];for(t.words[t.length++]=o&n,a=10;a<e.length;a++){var s=0|e.words[a];e.words[a-10]=(s&n)<<4|o>>>22,o=s}o>>>=22,e.words[a-10]=o,e.length-=0===o&&10<e.length?10:9},m.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,n=0,r;n<e.length;n++)r=0|e.words[n],t+=977*r,e.words[n]=67108863&t,t=64*r+(0|t/67108864);return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},r(f,c),r(g,c),r(h,c),h.prototype.imulK=function(e){for(var t=0,n=0;n<e.length;n++){var r=19*(0|e.words[n])+t,a=67108863&r;r>>>=26,e.words[n]=a,t=r}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function e(t){if(I[t])return I[t];var e;if("k256"===t)e=new m;else if("p224"===t)e=new f;else if("p192"===t)e=new g;else if("p25519"===t)e=new h;else throw new Error("Unknown prime "+t);return I[t]=e,e},k.prototype._verify1=function(e){n(0===e.negative,"red works only with positives"),n(e.red,"red works only with red numbers")},k.prototype._verify2=function(e,t){n(0==(e.negative|t.negative),"red works only with positives"),n(e.red&&e.red===t.red,"red works only with red numbers")},k.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):e.umod(this.m)._forceRed(this)},k.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},k.prototype.add=function(e,t){this._verify2(e,t);var n=e.add(t);return 0<=n.cmp(this.m)&&n.isub(this.m),n._forceRed(this)},k.prototype.iadd=function(e,t){this._verify2(e,t);var n=e.iadd(t);return 0<=n.cmp(this.m)&&n.isub(this.m),n},k.prototype.sub=function(e,t){this._verify2(e,t);var n=e.sub(t);return 0>n.cmpn(0)&&n.iadd(this.m),n._forceRed(this)},k.prototype.isub=function(e,t){this._verify2(e,t);var n=e.isub(t);return 0>n.cmpn(0)&&n.iadd(this.m),n},k.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},k.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},k.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},k.prototype.isqr=function(e){return this.imul(e,e.clone())},k.prototype.sqr=function(e){return this.mul(e,e)},k.prototype.sqrt=function(e){if(e.isZero())return e.clone();var a=this.m.andln(3);if(n(1==a%2),3===a){var d=this.m.add(new o(1)).iushrn(2);return this.pow(e,d)}for(var p=this.m.subn(1),l=0;!p.isZero()&&0===p.andln(1);)l++,p.iushrn(1);n(!p.isZero());var u=new o(1).toRed(this),y=u.redNeg(),f=this.m.subn(1).iushrn(1),g=this.m.bitLength();for(g=new o(2*g*g).toRed(this);0!==this.pow(g,f).cmp(y);)g.redIAdd(y);for(var h=this.pow(g,p),v=this.pow(e,p.addn(1).iushrn(1)),w=this.pow(e,p),_=l;0!==w.cmp(u);){for(var T=w,x=0;0!==T.cmp(u);x++)T=T.redSqr();n(x<_);var A=this.pow(h,new o(1).iu