UNPKG

@martins-finance/venus-js

Version:

A JavaScript SDK for Ethereum and the Venus Protocol.

1 lines 795 kB
var Venus=function(t,n){'use strict';var g=Math.pow,h=Math.round,v=Math.sin,T=Math.cos,w=Math.PI,_=Math.imul,x=Math.clz32,A=Math.ceil,M=Math.max,E=Math.min,P=Math.floor,C=String.fromCharCode;function a(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e["default"]:e}function r(e,t){return t={exports:{}},e(t,t.exports),t.exports}function i(e){return!!e.toHexString}function o(e){return e.slice?e:(e.slice=function(){const t=Array.prototype.slice.call(arguments);return o(new Uint8Array(Array.prototype.slice.apply(e,t)))},e)}function s(e){return y(e)&&!(e.length%2)||p(e)}function p(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 d(e,t){if(t||(t={}),"number"==typeof e){Ie.checkSafeUint53(e,"invalid arrayify value");const t=[];for(;e;)t.unshift(255&e),e=parseInt(e/256+"");return 0===t.length&&t.push(0),o(new Uint8Array(t))}if(t.allowMissingPrefix&&"string"==typeof e&&"0x"!==e.substring(0,2)&&(e="0x"+e),i(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":Ie.throwArgumentError("hex data is odd-length","value",e));const a=[];for(let e=0;e<n.length;e+=2)a.push(parseInt(n.substring(e,e+2),16));return o(new Uint8Array(a))}return p(e)?o(new Uint8Array(e)):Ie.throwArgumentError("invalid arrayify value","value",e)}function l(e){const t=e.map(e=>d(e)),n=t.reduce((e,t)=>e+t.length,0),a=new Uint8Array(n);return t.reduce((e,t)=>(a.set(t,e),e+t.length),0),o(a)}function u(e,t){e=d(e),e.length>t&&Ie.throwArgumentError("value out of range","value",arguments[0]);const n=new Uint8Array(t);return n.set(e,t-e.length),o(n)}function y(e,t){return!!("string"==typeof e&&e.match(/^0x[0-9A-Fa-f]*$/))&&!(t&&e.length!==2+2*t)}function m(e,t){if(t||(t={}),"number"==typeof e){Ie.checkSafeUint53(e,"invalid hexlify value");let t="";for(;e;)t=Fe[15&e]+t,e=P(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),i(e))return e.toHexString();if(y(e))return e.length%2&&("left"===t.hexPad?e="0x0"+e.substring(2):"right"===t.hexPad?e+="0":Ie.throwArgumentError("hex data is odd-length","value",e)),e.toLowerCase();if(p(e)){let t="0x";for(let n=0,a;n<e.length;n++)a=e[n],t+=Fe[(240&a)>>4]+Fe[15&a];return t}return Ie.throwArgumentError("invalid hexlify value","value",e)}function c(e){"string"!=typeof e&&(e=m(e)),y(e)||Ie.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)&&Ie.throwArgumentError("invalid hex string","value",e):e=m(e),e.length>2*t+2&&Ie.throwArgumentError("value out of range","value",arguments[1]);e.length<2*t+2;)e="0x0"+e.substring(2);return e}function b(e){const t={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0};if(s(e)){const n=d(e);65!==n.length&&Ie.throwArgumentError("invalid signature string; must be 65 bytes","signature",e),t.r=m(n.slice(0,32)),t.s=m(n.slice(32,64)),t.v=n[64],27>t.v&&(0===t.v||1===t.v?t.v+=27:Ie.throwArgumentError("signature invalid v byte","signature",e)),t.recoveryParam=1-t.v%2,t.recoveryParam&&(n[32]|=128),t._vs=m(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(d(t._vs),32);t._vs=m(n);const a=128<=n[0]?1:0;null==t.recoveryParam?t.recoveryParam=a:t.recoveryParam!==a&&Ie.throwArgumentError("signature recoveryParam mismatch _vs","signature",e),n[0]&=127;const r=m(n);null==t.s?t.s=r:t.s!==r&&Ie.throwArgumentError("signature v mismatch _vs","signature",e)}null==t.recoveryParam?null==t.v?Ie.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&&Ie.throwArgumentError("signature recoveryParam mismatch v","signature",e),null!=t.r&&y(t.r)?t.r=f(t.r,32):Ie.throwArgumentError("signature missing or invalid r","signature",e),null!=t.s&&y(t.s)?t.s=f(t.s,32):Ie.throwArgumentError("signature missing or invalid s","signature",e);const n=d(t.s);128<=n[0]&&Ie.throwArgumentError("signature s out of range","signature",e),t.recoveryParam&&(n[0]|=128);const a=m(n);t._vs&&(!y(t._vs)&&Ie.throwArgumentError("signature invalid _vs","signature",e),t._vs=f(t._vs,32)),null==t._vs?t._vs=a:t._vs!==a&&Ie.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 S="undefined"==typeof globalThis?"undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?{}:self:global:window:globalThis,B=r(function(e,t){(function(e,n){n(t)})(S,function(e){var ie=Math.abs,oe=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 i(e,t){if(!e)throw new Error(t||"Assertion failed")}function o(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 d(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 l(){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 u(e,t,n){return e&t^~e&n}function m(e,t,n){return e&t^e&n^t&n}function c(e,t,n){return e^t^n}function b(){return this instanceof b?void(ti.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=ni,this.W=Array(64)):new b}function k(){return this instanceof k?void(ci.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=fi,this.W=Array(160)):new k}function B(e,t,n,a,i){var o=e&n^~e&i;return 0>o&&(o+=4294967296),o}function R(e,t,n,a,i,o){var s=t&a^~t&o;return 0>s&&(s+=4294967296),s}function N(e,t,n,a,i){var o=e&n^e&i^n&i;return 0>o&&(o+=4294967296),o}function I(e,t,n,a,i,o){var s=t&a^t&o^a&o;return 0>s&&(s+=4294967296),s}function F(e,t){var n=ai(e,t,28),a=ai(t,e,2),i=ai(t,e,7),o=n^a^i;return 0>o&&(o+=4294967296),o}function O(e,t){var n=ri(e,t,28),a=ri(t,e,2),i=ri(t,e,7),o=n^a^i;return 0>o&&(o+=4294967296),o}function D(e,t){var n=ai(e,t,14),a=ai(e,t,18),i=ai(t,e,9),o=n^a^i;return 0>o&&(o+=4294967296),o}function L(e,t){var n=ri(e,t,14),a=ri(e,t,18),i=ri(t,e,9),o=n^a^i;return 0>o&&(o+=4294967296),o}function U(e,t){var n=ai(e,t,1),a=ai(e,t,8),i=ii(e,t,7),o=n^a^i;return 0>o&&(o+=4294967296),o}function V(e,t){var n=ri(e,t,1),a=ri(e,t,8),i=oi(e,t,7),o=n^a^i;return 0>o&&(o+=4294967296),o}function q(e,t){var n=ai(e,t,19),a=ai(t,e,29),i=ii(e,t,6),o=n^a^i;return 0>o&&(o+=4294967296),o}function z(e,t){var n=ri(e,t,19),a=ri(t,e,29),i=oi(e,t,6),o=n^a^i;return 0>o&&(o+=4294967296),o}function H(){return this instanceof H?void(wi.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"):new H}function G(e,t,n,a){return 15>=e?t^n^a:31>=e?t&n|~t&a:47>=e?(t|~n)^a:63>=e?t&a|n&~a:t^(n|~a)}function y(e){return 15>=e?0:31>=e?1518500249:47>=e?1859775393:63>=e?2400959708:2840853838}function f(e){return 15>=e?1352829926:31>=e?1548603684:47>=e?1836072691:63>=e?2053994217:0}function K(e,t,n){return this instanceof K?void(this.Hash=e,this.blockSize=e.blockSize/8,this.outSize=e.outSize/8,this.inner=null,this.outer=null,this._init(zr.toArray(t,n))):new K(e,t,n)}function j(e,t){this.type=e,this.p=new Ki(t.p,16),this.red=t.prime?Ki.red(t.prime):Ki.mont(this.p),this.zero=new Ki(0).toRed(this.red),this.one=new Ki(1).toRed(this.red),this.two=new Ki(2).toRed(this.red),this.n=t.n&&new Ki(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 W(e,t){this.curve=e,this.type=t,this.precomputed=null}function Z(e){Qi.call(this,"short",e),this.a=new Ki(e.a,16).toRed(this.red),this.b=new Ki(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,a){Qi.BasePoint.call(this,e,"affine"),null===t&&null===n?(this.x=null,this.y=null,this.inf=!0):(this.x=new Ki(t,16),this.y=new Ki(n,16),a&&(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,a){Qi.BasePoint.call(this,e,"jacobian"),null===t&&null===n&&null===a?(this.x=this.curve.one,this.y=this.curve.one,this.z=new Ki(0)):(this.x=new Ki(t,16),this.y=new Ki(n,16),this.z=new Ki(a,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=ji.toArray(e.entropy,e.entropyEnc||"hex"),n=ji.toArray(e.nonce,e.nonceEnc||"hex"),a=ji.toArray(e.pers,e.persEnc||"hex");Vr(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,n,a)}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)||(so(e.r&&e.s,"Signature without r or s"),this.r=new Ki(e.r,16),this.s=new Ki(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 a=15&n;if(0==a||4<a)return!1;for(var r=0,o=0,s=t.place;o<a;o++,s++)r<<=8,r|=e[s],r>>>=0;return!(127>=r)&&(t.place=s,r)}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 ae(e,t){if(128>t)return void e.push(t);var n=1+(oe(t)/Math.LN2>>>3);for(e.push(128|n);--n;)e.push(255&t>>>(n<<3));e.push(t)}function re(e){return this instanceof re?void("string"==typeof e&&(lo(ao.hasOwnProperty(e),"Unknown curve "+e),e=ao[e]),e instanceof ao.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 re(e)}var se="undefined"==typeof globalThis?"undefined"==typeof window?"undefined"==typeof S?"undefined"==typeof self?{}:self:S:window:globalThis,pe=Object.freeze({default:{}}),de=a(pe),le=n(function(e){(function(e,t){function n(e,t){if(!e)throw new Error(t||"Assertion failed")}function a(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 r(e,t,n){for(var a=0,o=E(e.length,n),s=t,p;s<o;s++)p=e.charCodeAt(s)-48,a<<=4,a|=49<=p&&54>=p?p-49+10:17<=p&&22>=p?p-17+10:15&p;return a}function s(e,t,n,a){for(var o=0,s=E(e.length,n),p=t,d;p<s;p++)d=e.charCodeAt(p)-48,o*=a,o+=49<=d?d-49+10:17<=d?d-17+10:d;return o}function p(e){for(var t=Array(e.bitLength()),n=0;n<t.length;n++){var a=0|n/26,r=n%26;t[n]=(e.words[a]&1<<r)>>>r}return t}function d(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],p=0|t.words[0],d=s*p,l=67108863&d,u=0|d/67108864;n.words[0]=l;for(var y=1;y<o;y++){for(var m=u>>>26,c=67108863&u,f=E(y,t.length-1),g=M(0,y-e.length+1),h;g<=f;g++)h=0|y-g,s=0|e.words[h],p=0|t.words[g],d=s*p+c,m+=0|d/67108864,c=67108863&d;n.words[y]=0|c,u=0|m}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,p=0,d;p<n.length-1;p++){d=s,s=0;for(var l=67108863&o,u=E(p,t.length-1),y=M(0,p-e.length+1);y<=u;y++){var m=p-y,i=0|e.words[m],a=0|t.words[y],c=i*a,r=67108863&c;d=0|d+(0|c/67108864),r=0|r+l,l=67108863&r,d=0|d+(r>>>26),s+=d>>>26,d&=67108863}n.words[p]=l,o=d,d=s}return 0===o?n.length--:n.words[p]=o,n.strip()}function u(e,t,n){var a=new y;return a.mulp(e,t,n)}function y(e,t){this.x=e,this.y=t}function m(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 c(){m.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function f(){m.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function b(){m.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function g(){m.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 P(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=de.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,a){if("number"==typeof e)return this._initNumber(e,t,a);if("object"==typeof e)return this._initArray(e,t,a);"hex"===t&&(t=16),n(t===(0|t)&&2<=t&&36>=t),e=e.toString().replace(/\s+/g,"");var r=0;"-"===e[0]&&r++,16===t?this._parseHex(e,r):this._parseBase(e,t,r),"-"===e[0]&&(this.negative=1),this.strip();"le"!==a||this._initArray(this.toArray(),t,a)},o.prototype._initNumber=function(e,t,a){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"!==a||this._initArray(this.toArray(),t,a)},o.prototype._initArray=function(e,t,a){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 r=0;r<this.length;r++)this.words[r]=0;var o=0,s,p;if("be"===a)for(r=e.length-1,s=0;0<=r;r-=3)p=e[r]|e[r-1]<<8|e[r-2]<<16,this.words[s]|=67108863&p<<o,this.words[s+1]=67108863&p>>>26-o,o+=24,26<=o&&(o-=26,s++);else if("le"===a)for(r=0,s=0;r<e.length;r+=3)p=e[r]|e[r+1]<<8|e[r+2]<<16,this.words[s]|=67108863&p<<o,this.words[s+1]=67108863&p>>>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 a=0,o,s;for(n=e.length-6,o=0;n>=t;n-=6)s=r(e,n,n+6),this.words[o]|=67108863&s<<a,this.words[o+1]|=4194303&s>>>26-a,a+=24,26<=a&&(a-=26,o++);n+6!==t&&(s=r(e,t,n+6),this.words[o]|=67108863&s<<a,this.words[o+1]|=4194303&s>>>26-a),this.strip()},o.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var a=0,r=1;67108863>=r;r*=t)a++;a--,r=0|r/t;for(var o=e.length-n,p=o%a,d=E(o,o-p)+n,l=0,u=n;u<d;u+=a)l=s(e,u,u+a,t),this.imuln(r),67108864>this.words[0]+l?this.words[0]+=l:this._iaddn(l);if(0!==p){var y=1;for(l=s(e,u,e.length,t),u=0;u<p;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 S=["","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,p=0;p<this.length;p++){var d=this.words[p],l=(16777215&(d<<o|s)).toString(16);s=16777215&d>>>24-o,a=0!==s||p!==this.length-1?S[6-l.length]+l+a:l+a,o+=2,26<=o&&(o-=26,p--)}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:S[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,a){var r=this.byteLength(),o=a||M(1,r);n(r<=o,"byte array longer than desired length"),n(0<o,"Requested array length <= 0"),this.strip();var s=new e(o),p=this.clone(),d,l;if(!("le"===t)){for(l=0;l<o-r;l++)s[l]=0;for(l=0;!p.isZero();l++)d=p.andln(255),p.iushrn(8),s[o-l-1]=d}else{for(l=0;!p.isZero();l++)d=p.andln(255),p.iushrn(8),s[l]=d;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),a=e%26;this._expand(t),0<a&&t--;for(var r=0;r<t;r++)this.words[r]=67108863&~this.words[r];return 0<a&&(this.words[r]=~this.words[r]&67108863>>26-a),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 a=0|e/26,r=e%26;return this._expand(a+1),t?this.words[a]|=1<<r:this.words[a]&=~(1<<r),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,p=0;p<o.length;p++)t=(0|n.words[p])+(0|o.words[p])+s,this.words[p]=67108863&t,s=t>>>26;for(;0!==s&&p<n.length;p++)t=(0|n.words[p])+s,this.words[p]=67108863&t,s=t>>>26;if(this.length=n.length,0!==s)this.words[this.length]=s,this.length++;else if(n!==this)for(;p<n.length;p++)this.words[p]=n.words[p];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 p=0,d=0;d<s.length;d++)t=(0|o.words[d])-(0|s.words[d])+p,p=t>>26,this.words[d]=67108863&t;for(;0!==p&&d<o.length;d++)t=(0|o.words[d])+p,p=t>>26,this.words[d]=67108863&t;if(0===p&&d<o.length&&o!==this)for(;d<o.length;d++)this.words[d]=o.words[d];return this.length=M(this.length,d),o!==this&&(this.negative=1),this.strip()},o.prototype.sub=function(e){return this.clone().isub(e)};var N=function(e,t,n){var r=e.words,a=t.words,i=n.words,o=0,s=0|r[0],p=8191&s,d=s>>>13,l=0|r[1],u=8191&l,y=l>>>13,m=0|r[2],f=8191&m,b=m>>>13,g=0|r[3],h=8191&g,v=g>>>13,T=0|r[4],w=8191&T,x=T>>>13,A=0|r[5],k=8191&A,M=A>>>13,E=0|r[6],P=8191&E,C=E>>>13,S=0|r[7],B=8191&S,R=S>>>13,N=0|r[8],I=8191&N,F=N>>>13,O=0|r[9],D=8191&O,L=O>>>13,U=0|a[0],V=8191&U,q=U>>>13,z=0|a[1],H=8191&z,G=z>>>13,K=0|a[2],j=8191&K,W=K>>>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,ae=0|a[6],re=8191&ae,ie=ae>>>13,oe=0|a[7],se=8191&oe,pe=oe>>>13,de=0|a[8],le=8191&de,ue=de>>>13,ye=0|a[9],me=8191&ye,ce=ye>>>13,fe,be,ge;n.negative=e.negative^t.negative,n.length=19,fe=_(p,V),be=_(p,q),be=0|be+_(d,V),ge=_(d,q);var he=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(he>>>26),he&=67108863,fe=_(u,V),be=_(u,q),be=0|be+_(y,V),ge=_(y,q),fe=0|fe+_(p,H),be=0|be+_(p,G),be=0|be+_(d,H),ge=0|ge+_(d,G);var ve=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(ve>>>26),ve&=67108863,fe=_(f,V),be=_(f,q),be=0|be+_(b,V),ge=_(b,q),fe=0|fe+_(u,H),be=0|be+_(u,G),be=0|be+_(y,H),ge=0|ge+_(y,G),fe=0|fe+_(p,j),be=0|be+_(p,W),be=0|be+_(d,j),ge=0|ge+_(d,W);var Te=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Te>>>26),Te&=67108863,fe=_(h,V),be=_(h,q),be=0|be+_(v,V),ge=_(v,q),fe=0|fe+_(f,H),be=0|be+_(f,G),be=0|be+_(b,H),ge=0|ge+_(b,G),fe=0|fe+_(u,j),be=0|be+_(u,W),be=0|be+_(y,j),ge=0|ge+_(y,W),fe=0|fe+_(p,J),be=0|be+_(p,X),be=0|be+_(d,J),ge=0|ge+_(d,X);var we=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(we>>>26),we&=67108863,fe=_(w,V),be=_(w,q),be=0|be+_(x,V),ge=_(x,q),fe=0|fe+_(h,H),be=0|be+_(h,G),be=0|be+_(v,H),ge=0|ge+_(v,G),fe=0|fe+_(f,j),be=0|be+_(f,W),be=0|be+_(b,j),ge=0|ge+_(b,W),fe=0|fe+_(u,J),be=0|be+_(u,X),be=0|be+_(y,J),ge=0|ge+_(y,X),fe=0|fe+_(p,Q),be=0|be+_(p,$),be=0|be+_(d,Q),ge=0|ge+_(d,$);var _e=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(_e>>>26),_e&=67108863,fe=_(k,V),be=_(k,q),be=0|be+_(M,V),ge=_(M,q),fe=0|fe+_(w,H),be=0|be+_(w,G),be=0|be+_(x,H),ge=0|ge+_(x,G),fe=0|fe+_(h,j),be=0|be+_(h,W),be=0|be+_(v,j),ge=0|ge+_(v,W),fe=0|fe+_(f,J),be=0|be+_(f,X),be=0|be+_(b,J),ge=0|ge+_(b,X),fe=0|fe+_(u,Q),be=0|be+_(u,$),be=0|be+_(y,Q),ge=0|ge+_(y,$),fe=0|fe+_(p,te),be=0|be+_(p,ne),be=0|be+_(d,te),ge=0|ge+_(d,ne);var xe=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(xe>>>26),xe&=67108863,fe=_(P,V),be=_(P,q),be=0|be+_(C,V),ge=_(C,q),fe=0|fe+_(k,H),be=0|be+_(k,G),be=0|be+_(M,H),ge=0|ge+_(M,G),fe=0|fe+_(w,j),be=0|be+_(w,W),be=0|be+_(x,j),ge=0|ge+_(x,W),fe=0|fe+_(h,J),be=0|be+_(h,X),be=0|be+_(v,J),ge=0|ge+_(v,X),fe=0|fe+_(f,Q),be=0|be+_(f,$),be=0|be+_(b,Q),ge=0|ge+_(b,$),fe=0|fe+_(u,te),be=0|be+_(u,ne),be=0|be+_(y,te),ge=0|ge+_(y,ne),fe=0|fe+_(p,re),be=0|be+_(p,ie),be=0|be+_(d,re),ge=0|ge+_(d,ie);var Ae=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Ae>>>26),Ae&=67108863,fe=_(B,V),be=_(B,q),be=0|be+_(R,V),ge=_(R,q),fe=0|fe+_(P,H),be=0|be+_(P,G),be=0|be+_(C,H),ge=0|ge+_(C,G),fe=0|fe+_(k,j),be=0|be+_(k,W),be=0|be+_(M,j),ge=0|ge+_(M,W),fe=0|fe+_(w,J),be=0|be+_(w,X),be=0|be+_(x,J),ge=0|ge+_(x,X),fe=0|fe+_(h,Q),be=0|be+_(h,$),be=0|be+_(v,Q),ge=0|ge+_(v,$),fe=0|fe+_(f,te),be=0|be+_(f,ne),be=0|be+_(b,te),ge=0|ge+_(b,ne),fe=0|fe+_(u,re),be=0|be+_(u,ie),be=0|be+_(y,re),ge=0|ge+_(y,ie),fe=0|fe+_(p,se),be=0|be+_(p,pe),be=0|be+_(d,se),ge=0|ge+_(d,pe);var ke=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(ke>>>26),ke&=67108863,fe=_(I,V),be=_(I,q),be=0|be+_(F,V),ge=_(F,q),fe=0|fe+_(B,H),be=0|be+_(B,G),be=0|be+_(R,H),ge=0|ge+_(R,G),fe=0|fe+_(P,j),be=0|be+_(P,W),be=0|be+_(C,j),ge=0|ge+_(C,W),fe=0|fe+_(k,J),be=0|be+_(k,X),be=0|be+_(M,J),ge=0|ge+_(M,X),fe=0|fe+_(w,Q),be=0|be+_(w,$),be=0|be+_(x,Q),ge=0|ge+_(x,$),fe=0|fe+_(h,te),be=0|be+_(h,ne),be=0|be+_(v,te),ge=0|ge+_(v,ne),fe=0|fe+_(f,re),be=0|be+_(f,ie),be=0|be+_(b,re),ge=0|ge+_(b,ie),fe=0|fe+_(u,se),be=0|be+_(u,pe),be=0|be+_(y,se),ge=0|ge+_(y,pe),fe=0|fe+_(p,le),be=0|be+_(p,ue),be=0|be+_(d,le),ge=0|ge+_(d,ue);var Me=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Me>>>26),Me&=67108863,fe=_(D,V),be=_(D,q),be=0|be+_(L,V),ge=_(L,q),fe=0|fe+_(I,H),be=0|be+_(I,G),be=0|be+_(F,H),ge=0|ge+_(F,G),fe=0|fe+_(B,j),be=0|be+_(B,W),be=0|be+_(R,j),ge=0|ge+_(R,W),fe=0|fe+_(P,J),be=0|be+_(P,X),be=0|be+_(C,J),ge=0|ge+_(C,X),fe=0|fe+_(k,Q),be=0|be+_(k,$),be=0|be+_(M,Q),ge=0|ge+_(M,$),fe=0|fe+_(w,te),be=0|be+_(w,ne),be=0|be+_(x,te),ge=0|ge+_(x,ne),fe=0|fe+_(h,re),be=0|be+_(h,ie),be=0|be+_(v,re),ge=0|ge+_(v,ie),fe=0|fe+_(f,se),be=0|be+_(f,pe),be=0|be+_(b,se),ge=0|ge+_(b,pe),fe=0|fe+_(u,le),be=0|be+_(u,ue),be=0|be+_(y,le),ge=0|ge+_(y,ue),fe=0|fe+_(p,me),be=0|be+_(p,ce),be=0|be+_(d,me),ge=0|ge+_(d,ce);var Ee=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Ee>>>26),Ee&=67108863,fe=_(D,H),be=_(D,G),be=0|be+_(L,H),ge=_(L,G),fe=0|fe+_(I,j),be=0|be+_(I,W),be=0|be+_(F,j),ge=0|ge+_(F,W),fe=0|fe+_(B,J),be=0|be+_(B,X),be=0|be+_(R,J),ge=0|ge+_(R,X),fe=0|fe+_(P,Q),be=0|be+_(P,$),be=0|be+_(C,Q),ge=0|ge+_(C,$),fe=0|fe+_(k,te),be=0|be+_(k,ne),be=0|be+_(M,te),ge=0|ge+_(M,ne),fe=0|fe+_(w,re),be=0|be+_(w,ie),be=0|be+_(x,re),ge=0|ge+_(x,ie),fe=0|fe+_(h,se),be=0|be+_(h,pe),be=0|be+_(v,se),ge=0|ge+_(v,pe),fe=0|fe+_(f,le),be=0|be+_(f,ue),be=0|be+_(b,le),ge=0|ge+_(b,ue),fe=0|fe+_(u,me),be=0|be+_(u,ce),be=0|be+_(y,me),ge=0|ge+_(y,ce);var Pe=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Pe>>>26),Pe&=67108863,fe=_(D,j),be=_(D,W),be=0|be+_(L,j),ge=_(L,W),fe=0|fe+_(I,J),be=0|be+_(I,X),be=0|be+_(F,J),ge=0|ge+_(F,X),fe=0|fe+_(B,Q),be=0|be+_(B,$),be=0|be+_(R,Q),ge=0|ge+_(R,$),fe=0|fe+_(P,te),be=0|be+_(P,ne),be=0|be+_(C,te),ge=0|ge+_(C,ne),fe=0|fe+_(k,re),be=0|be+_(k,ie),be=0|be+_(M,re),ge=0|ge+_(M,ie),fe=0|fe+_(w,se),be=0|be+_(w,pe),be=0|be+_(x,se),ge=0|ge+_(x,pe),fe=0|fe+_(h,le),be=0|be+_(h,ue),be=0|be+_(v,le),ge=0|ge+_(v,ue),fe=0|fe+_(f,me),be=0|be+_(f,ce),be=0|be+_(b,me),ge=0|ge+_(b,ce);var Ce=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Ce>>>26),Ce&=67108863,fe=_(D,J),be=_(D,X),be=0|be+_(L,J),ge=_(L,X),fe=0|fe+_(I,Q),be=0|be+_(I,$),be=0|be+_(F,Q),ge=0|ge+_(F,$),fe=0|fe+_(B,te),be=0|be+_(B,ne),be=0|be+_(R,te),ge=0|ge+_(R,ne),fe=0|fe+_(P,re),be=0|be+_(P,ie),be=0|be+_(C,re),ge=0|ge+_(C,ie),fe=0|fe+_(k,se),be=0|be+_(k,pe),be=0|be+_(M,se),ge=0|ge+_(M,pe),fe=0|fe+_(w,le),be=0|be+_(w,ue),be=0|be+_(x,le),ge=0|ge+_(x,ue),fe=0|fe+_(h,me),be=0|be+_(h,ce),be=0|be+_(v,me),ge=0|ge+_(v,ce);var Se=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Se>>>26),Se&=67108863,fe=_(D,Q),be=_(D,$),be=0|be+_(L,Q),ge=_(L,$),fe=0|fe+_(I,te),be=0|be+_(I,ne),be=0|be+_(F,te),ge=0|ge+_(F,ne),fe=0|fe+_(B,re),be=0|be+_(B,ie),be=0|be+_(R,re),ge=0|ge+_(R,ie),fe=0|fe+_(P,se),be=0|be+_(P,pe),be=0|be+_(C,se),ge=0|ge+_(C,pe),fe=0|fe+_(k,le),be=0|be+_(k,ue),be=0|be+_(M,le),ge=0|ge+_(M,ue),fe=0|fe+_(w,me),be=0|be+_(w,ce),be=0|be+_(x,me),ge=0|ge+_(x,ce);var Be=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Be>>>26),Be&=67108863,fe=_(D,te),be=_(D,ne),be=0|be+_(L,te),ge=_(L,ne),fe=0|fe+_(I,re),be=0|be+_(I,ie),be=0|be+_(F,re),ge=0|ge+_(F,ie),fe=0|fe+_(B,se),be=0|be+_(B,pe),be=0|be+_(R,se),ge=0|ge+_(R,pe),fe=0|fe+_(P,le),be=0|be+_(P,ue),be=0|be+_(C,le),ge=0|ge+_(C,ue),fe=0|fe+_(k,me),be=0|be+_(k,ce),be=0|be+_(M,me),ge=0|ge+_(M,ce);var Re=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Re>>>26),Re&=67108863,fe=_(D,re),be=_(D,ie),be=0|be+_(L,re),ge=_(L,ie),fe=0|fe+_(I,se),be=0|be+_(I,pe),be=0|be+_(F,se),ge=0|ge+_(F,pe),fe=0|fe+_(B,le),be=0|be+_(B,ue),be=0|be+_(R,le),ge=0|ge+_(R,ue),fe=0|fe+_(P,me),be=0|be+_(P,ce),be=0|be+_(C,me),ge=0|ge+_(C,ce);var Ne=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Ne>>>26),Ne&=67108863,fe=_(D,se),be=_(D,pe),be=0|be+_(L,se),ge=_(L,pe),fe=0|fe+_(I,le),be=0|be+_(I,ue),be=0|be+_(F,le),ge=0|ge+_(F,ue),fe=0|fe+_(B,me),be=0|be+_(B,ce),be=0|be+_(R,me),ge=0|ge+_(R,ce);var Ie=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Ie>>>26),Ie&=67108863,fe=_(D,le),be=_(D,ue),be=0|be+_(L,le),ge=_(L,ue),fe=0|fe+_(I,me),be=0|be+_(I,ce),be=0|be+_(F,me),ge=0|ge+_(F,ce);var Fe=0|(0|o+fe)+((8191&be)<<13);o=0|(0|ge+(be>>>13))+(Fe>>>26),Fe&=67108863,fe=_(D,me),be=_(D,ce),be=0|be+_(L,me),ge=_(L,ce);var Oe=0|(0|o+fe)+((8191&be)<<13);return o=0|(0|ge+(be>>>13))+(Oe>>>26),Oe&=67108863,i[0]=he,i[1]=ve,i[2]=Te,i[3]=we,i[4]=_e,i[5]=xe,i[6]=Ae,i[7]=ke,i[8]=Me,i[9]=Ee,i[10]=Pe,i[11]=Ce,i[12]=Se,i[13]=Be,i[14]=Re,i[15]=Ne,i[16]=Ie,i[17]=Fe,i[18]=Oe,0!==o&&(i[19]=o,n.length++),n};_||(N=d),o.prototype.mulTo=function(e,t){var n=this.length+e.length,a;return a=10===this.length&&10===e.length?N(this,e,t):63>n?d(this,e,t):1024>n?l(this,e,t):u(this,e,t),a},y.prototype.makeRBT=function(e){for(var n=Array(e),t=o.prototype._countBits(e)-1,a=0;a<e;a++)n[a]=this.revBin(a,t,e);return n},y.prototype.revBin=function(e,t,n){if(0===e||e===n-1)return e;for(var a=0,r=0;r<t;r++)a|=(1&e)<<t-r-1,e>>=1;return a},y.prototype.permute=function(e,t,n,a,r,o){for(var s=0;s<o;s++)a[s]=t[e[s]],r[s]=n[e[s]]},y.prototype.transform=function(e,t,n,a,r,i){this.permute(i,e,t,n,a,r);for(var o=1;o<r;o<<=1)for(var d=o<<1,l=T(2*w/d),u=v(2*w/d),y=0;y<r;y+=d)for(var m=l,c=u,f=0;f<o;f++){var b=n[y+f],g=a[y+f],h=n[y+f+o],_=a[y+f+o],x=m*h-c*_;_=m*_+c*h,h=x,n[y+f]=b+h,a[y+f]=g+_,n[y+f+o]=b-h,a[y+f+o]=g-_,f!==d&&(x=l*m-u*c,c=l*c+u*m,m=x)}},y.prototype.guessLen13b=function(e,t){var n=1|M(t,e),a=1&n,r=0;for(n=0|n/2;n;n>>>=1)r++;return 1<<r+1+a},y.prototype.conjugate=function(e,n,a){if(!(1>=a))for(var r=0,o;r<a/2;r++)o=e[r],e[r]=e[a-r-1],e[a-r-1]=o,o=n[r],n[r]=-n[a-r-1],n[a-r-1]=-o},y.prototype.normalize13b=function(e,t){for(var n=0,a=0,r;a<t/2;a++)r=8192*h(e[2*a+1]/t)+h(e[2*a]/t)+n,e[a]=67108863&r,n=67108864>r?0:0|r/67108864;return e},y.prototype.convert13b=function(e,t,a,r){for(var o=0,s=0;s<t;s++)o+=0|e[s],a[2*s]=8191&o,o>>>=13,a[2*s+1]=8191&o,o>>>=13;for(s=2*t;s<r;++s)a[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 a=2*this.guessLen13b(e.length,t.length),r=this.makeRBT(a),o=this.stub(a),s=Array(a),p=Array(a),d=Array(a),l=Array(a),u=Array(a),y=Array(a),m=n.words;m.length=a,this.convert13b(e.words,e.length,s,a),this.convert13b(t.words,t.length,l,a),this.transform(s,o,p,d,a,r),this.transform(l,o,u,y,a,r);for(var c=0,f;c<a;c++)f=p[c]*u[c]-d[c]*y[c],d[c]=p[c]*y[c]+d[c]*u[c],p[c]=f;return this.conjugate(p,d,a),this.transform(p,d,m,o,a,r),this.conjugate(m,o,a),this.normalize13b(m,a),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,a=0;a<this.length;a++){var r=(0|this.words[a])*e,o=(67108863&r)+(67108863&t);t>>=26,t+=0|r/67108864,t+=o>>>26,this.words[a]=67108863&o}return 0!==t&&(this.words[a]=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=p(e);if(0===t.length)return new o(1);for(var n=this,a=0;a<t.length&&!(0!==t[a]);a++,n=n.sqr());if(++a<t.length)for(var r=n.sqr();a<t.length;a++,r=r.sqr())0!==t[a]&&(n=n.mul(r));return n},o.prototype.iushln=function(e){n("number"==typeof e&&0<=e);var t=e%26,a=(e-t)/26,r;if(0!=t){var o=0;for(r=0;r<this.length;r++){var s=this.words[r]&67108863>>>26-t<<26-t,p=(0|this.words[r])-s<<t;this.words[r]=p|o,o=s>>>26-t}o&&(this.words[r]=o,this.length++)}if(0!==a){for(r=this.length-1;0<=r;r--)this.words[r+a]=this.words[r];for(r=0;r<a;r++)this.words[r]=0;this.length+=a}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 p=e%26,r=E((e-p)/26,this.length),s=a;if(o-=r,o=M(0,o),s){for(var d=0;d<r;d++)s.words[d]=this.words[d];s.length=r}if(0===r);else if(this.length>r)for(this.length-=r,d=0;d<this.length;d++)this.words[d]=this.words[d+r];else this.words[0]=0,this.length=1;var l=0;for(d=this.length-1;0<=d&&(0!==l||d>=o);d--){var u=0|this.words[d];this.words[d]=l<<26-p|u>>>p,l=u&(67108863^67108863>>>p<<p)}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,a){return n(0===this.negative),this.iushrn(e,t,a)},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,a=(e-t)/26;if(this.length<=a)return!1;var r=this.words[a];return!!(r&1<<t)},o.prototype.imaskn=function(e){n("number"==typeof e&&0<=e);var t=e%26,a=(e-t)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=a)return this;if(0!=t&&a++,this.length=E(a,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=M(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,a){var r=e.length+a,o;this._expand(r);var s=0,p;for(o=0;o<e.length;o++){p=(0|this.words[o+a])+s;var d=(0|e.words[o])*t;p-=67108863&d,s=(p>>26)-(0|d/67108864),this.words[o+a]=67108863&p}for(;o<this.length-a;o++)p=(0|this.words[o+a])+s,s=p>>26,this.words[o+a]=67108863&p;if(0===s)return this.strip();for(n(-1===s),s=0,o=0;o<this.length;o++)p=-(0|this.words[o])+s,s=p>>26,this.words[o]=67108863&p;return this.negative=1,this.strip()},o.prototype._wordDiv=function(e,t){var n=this.length-e.length,r=this.clone(),s=e,p=0|s.words[s.length-1],d=this._countBits(p);n=26-d,0!=n&&(s=s.ushln(n),r.iushln(n),p=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 m=r.clone()._ishlnsubmul(s,1,l);0===m.negative&&(r=m,u&&(u.words[l]=1));for(var c=l-1,f;0<=c;c--){for(f=67108864*(0|r.words[s.length+c])+(0|r.words[s.length+c-1]),f=E(0|f/p,67108863),r._ishlnsubmul(s,f,c);0!==r.negative;)f--,r.negative=0,r._ishlnsubmul(s,1,c),r.isZero()||(r.negative^=1);u&&(u.words[c]=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,a){if(n(!e.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var r,i,s;return 0!==this.negative&&0===e.negative?(s=this.neg().divmod(e,t),"mod"!==t&&(r=s.div.neg()),"div"!==t&&(i=s.mod.neg(),a&&0!==i.negative&&i.iadd(e)),{div:r,mod:i}):0===this.negative&&0!==e.negative?(s=this.divmod(e.neg(),t),"mod"!==t&&(r=s.div.neg()),{div:r,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(),a&&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),a=e.ushrn(1),r=e.andln(1),i=n.cmp(a);return 0>i||1===r&&0===i?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,a=this.length-1;0<=a;a--)t=(67108864%e*t+(0|this.words[a]))%e;return t},o.prototype.idivn=function(e){n(67108863>=e);for(var t=0,a=this.length-1,r;0<=a;a--)r=(0|this.words[a])+67108864*t,this.words[a]=0|r/e,t=r%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,a=e.clone();t=0===t.negative?t.clone():t.umod(e);for(var r=new o(1),s=new o(0),p=new o(0),d=new o(1),l=0;t.isEven()&&a.isEven();)t.iushrn(1),a.iushrn(1),++l;for(var u=a.clone(),y=t.clone();!t.isZero();){for(var m=0,c=1;0==(t.words[0]&c)&&26>m;++m,c<<=1);if(0<m)for(t.iushrn(m);0<m--;)(r.isOdd()||s.isOdd())&&(r.iadd(u),s.isub(y)),r.iushrn(1),s.iushrn(1);for(var f=0,b=1;0==(a.words[0]&b)&&26>f;++f,b<<=1);if(0<f)for(a.iushrn(f);0<f--;)(p.isOdd()||d.isOdd())&&(p.iadd(u),d.isub(y)),p.iushrn(1),d.iushrn(1);0<=t.cmp(a)?(t.isub(a),r.isub(p),s.isub(d)):(a.isub(t),p.isub(r),d.isub(s))}return{a:p,b:d,gcd:a.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),p=new o(0),d=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(d),s.iushrn(1);for(var y=0,m=1;0==(r.words[0]&m)&&26>y;++y,m<<=1);if(0<y)for(r.iushrn(y);0<y--;)p.isOdd()&&p.iadd(d),p.iushrn(1);0<=t.cmp(r)?(t.isub(r),s.isub(p)):(r.isub(t),p.isub(s))}var c;return c=0===t.cmpn(1)?s:p,0>c.cmpn(0)&&c.iadd(e),c},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var n=this.clone(),i=e.clone();n.negative=0,i.negative=0;for(var o=0;n.isEven()&&i.isEven();o++)n.iushrn(1),i.iushrn(1);do{for(;n.isEven();)n.iushrn(1);for(;i.isEven();)i.iushrn(1);var s=n.cmp(i);if(0>s){var r=n;n=i,i=r}else if(0===s||0===i.cmpn(1))break;n.isub(i)}while(!0);return i.iushln(o)},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,a=(e-t)/26,r=1<<t;if(this.length<=a)return this._expand(a+1),this.words[a]|=r,this;for(var o=r,s=a,p;0!==o&&s<this.length;s++)p=0|this.words[s],p+=o,o=p>>>26,p&=67108863,this.words[s]=p;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 a;if(1<this.length)a=1;else{t&&(e=-e),n(67108863>=e,"Number is too big");var r=0|this.words[0];a=r===e?0:r<e?-1:1}return 0===this.negative?a:0|-a},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};m.prototype._tmp=function(){var e=new o(null);return e.words=Array(A(this.n/13)),e},m.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},m.prototype.split=function(e,t){e.iushrn(this.n,0,t)},m.prototype.imulK=function(e){return e.imul(this.k)},a(c,m),c.prototype.split=function(e,t){for(var n=4194303,a=E(e.length,9),r=0;r<a;r++)t.words[r]=e.words[r];if(t.length=a,9>=e.length)return e.words[0]=0,void(e.length=1);var o=e.words[9];for(t.words[t.length++]=o&n,r=10;r<e.length;r++){var s=0|e.words[r];e.words[r-10]=(s&n)<<4|o>>>22,o=s}o>>>=22,e.words[r-10]=o,e.length-=0===o&&10<e.length?10:9},c.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,n=0,a;n<e.length;n++)a=0|e.words[n],t+=977*a,e.words[n]=67108863&t,t=64*a+(0|t/67108864);return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},a(f,m),a(b,m),a(g,m),g.prototype.imulK=function(e){for(var t=0,n=0;n<e.length;n++){var a=19*(0|e.words[n])+t,r=67108863&a;a>>>=26,e.words[n]=r,t=a}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 c;else if("p224"===t)e=new f;else if("p192"===t)e=new b;else if("p25519"===t)e=new g;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 p=this.m.add(new o(1)).iushrn(2);return this.pow(e,p)}for(var d=this.m.subn(1),l=0;!d.isZero()&&0===d.andln(1);)l++,d.iushrn(1);n(!d.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,d),v=this.pow(e,d.addn(1).iushrn(1)),T=this.pow(e,d),w=l;0!==T.cmp(u);){for(var _=T,x=0;0!==_.cmp(u);x++)_=_.redSqr();n(x<w);var A=this.pow(h,new o(1).iu