-
Notifications
You must be signed in to change notification settings - Fork 11
/
assets_js_lib_cashaddr.js
2 lines (2 loc) · 22.2 KB
/
assets_js_lib_cashaddr.js
1
2
/*! For license information please see cashaddrjs-0.4.4.min.js.LICENSE.txt */
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.cashaddr=r():t.cashaddr=r()}(this,(function(){return(()=>{var t={60:(t,r,e)=>{"use strict";var n=e(744).validate,o={q:0,p:1,z:2,r:3,y:4,9:5,x:6,8:7,g:8,f:9,2:10,t:11,v:12,d:13,w:14,0:15,s:16,3:17,j:18,n:19,5:20,4:21,k:22,h:23,c:24,e:25,6:26,m:27,u:28,a:29,7:30,l:31};t.exports={encode:function(t){n(t instanceof Uint8Array,"Invalid data: "+t+".");for(var r="",e=0;e<t.length;++e){var o=t[e];n(0<=o&&o<32,"Invalid value: "+o+"."),r+="qpzry9x8gf2tvdw0s3jn54khce6mua7l"[o]}return r},decode:function(t){n("string"==typeof t,"Invalid base32-encoded string: "+t+".");for(var r=new Uint8Array(t.length),e=0;e<t.length;++e){var i=t[e];n(i in o,"Invalid value: "+i+"."),r[e]=o[i]}return r}}},146:(t,r,e)=>{"use strict";var n=e(60),o=e(736),i=e(574),a=e(744),u=a.validate,s=a.ValidationError,p=["bitcoincash","bchtest","bchreg","kaspa"];function l(t){for(var r=new Uint8Array(t.length),e=0;e<t.length;++e)r[e]=31&t[e].charCodeAt(0);return r}function f(t,r){var e=new Uint8Array(t.length+r.length);return e.set(t),e.set(r,t.length),e}function h(t){for(var r=[656907472481,522768456162,0xf33e5fb3c4,748107326120,130178868336],e=o(1),n=0;n<t.length;++n){var i=t[n],a=e.shiftRight(35);e=e.and(34359738367).shiftLeft(5).xor(i);for(var u=0;u<r.length;++u)a.shiftRight(u).and(1).equals(1)&&(e=e.xor(r[u]))}return e.xor(1)}function v(t){return t===t.toLowerCase()||t===t.toUpperCase()}t.exports={encode:function(t,r,e){u("string"==typeof t&&function(t){return v(t)&&-1!==p.indexOf(t.toLowerCase())}(t),"Invalid prefix: "+t+"."),u("string"==typeof r,"Invalid type: "+r+"."),u(e instanceof Uint8Array,"Invalid hash: "+e+".");var o,a=f(l(t),new Uint8Array(1)),c=function(t){switch(t){case"P2PKH":return 0;case"P2SH":return 8;default:throw new s("Invalid type: "+t+".")}}(r)+function(t){switch(8*t.length){case 160:return 0;case 192:return 1;case 224:return 2;case 256:return 3;case 320:return 4;case 384:return 5;case 448:return 6;case 512:return 7;default:throw new s("Invalid hash size: "+t.length+".")}}(e),y=(o=f(new Uint8Array([c]),e),i(o,8,5)),g=f(f(a,y),new Uint8Array(8)),d=f(y,function(t){for(var r=new Uint8Array(8),e=0;e<8;++e)r[7-e]=t.and(31).toJSNumber(),t=t.shiftRight(5);return r}(h(g)));return t+":"+n.encode(d)},decode:function(t){u("string"==typeof t&&v(t),"Invalid address: "+t+".");var r=t.toLowerCase().split(":");u(2===r.length,"Missing prefix: "+t+".");var e=r[0],o=n.decode(r[1]);u(function(t,r){var e=f(l(t),new Uint8Array(1));return h(f(e,r)).equals(0)}(e,o),"Invalid checksum: "+t+".");var a,p=(a=o.subarray(0,-8),i(a,5,8,!0)),c=p[0],y=p.subarray(1);return u(function(t){switch(7&t){case 0:return 160;case 1:return 192;case 2:return 224;case 3:return 256;case 4:return 320;case 5:return 384;case 6:return 448;case 7:return 512}}(c)===8*y.length,"Invalid hash size: "+t+"."),{prefix:e,type:function(t){switch(120&t){case 0:return"P2PKH";case 8:return"P2SH";default:throw new s("Invalid address type in version byte: "+t+".")}}(c),hash:y}},ValidationError:s}},574:(t,r,e)=>{"use strict";var n=e(744).validate;t.exports=function(t,r,e,o){for(var i=o?Math.floor(t.length*r/e):Math.ceil(t.length*r/e),a=(1<<e)-1,u=new Uint8Array(i),s=0,p=0,l=0,f=0;f<t.length;++f){var h=t[f];for(n(0<=h&&h>>r==0,"Invalid value: "+h+"."),p=p<<r|h,l+=r;l>=e;)l-=e,u[s]=p>>l&a,++s}return o?n(l<r&&0==(p<<e-l&a),"Input cannot be converted to "+e+" bits without padding, but strict mode was used."):l>0&&(u[s]=p<<e-l&a,++s),u}},744:t=>{"use strict";function r(t){var r=new Error;this.name=r.name="ValidationError",this.message=r.message=t,this.stack=r.stack}r.prototype=Object.create(Error.prototype),t.exports={ValidationError:r,validate:function(t,e){if(!t)throw new r(e)}}},736:(t,r,e)=>{var n;t=e.nmd(t);var o=function(t){"use strict";var r=1e7,e=9007199254740992,n=l(e),i=Math.log(e);function a(t,r){return void 0===t?a[0]:void 0!==r?10==+r?$(t):T(t,r):$(t)}function u(t,r){this.value=t,this.sign=r,this.isSmall=!1}function s(t){this.value=t,this.sign=t<0,this.isSmall=!0}function p(t){return-e<t&&t<e}function l(t){return t<1e7?[t]:t<1e14?[t%1e7,Math.floor(t/1e7)]:[t%1e7,Math.floor(t/1e7)%1e7,Math.floor(t/1e14)]}function f(t){h(t);var e=t.length;if(e<4&&I(t,n)<0)switch(e){case 0:return 0;case 1:return t[0];case 2:return t[0]+t[1]*r;default:return t[0]+(t[1]+t[2]*r)*r}return t}function h(t){for(var r=t.length;0===t[--r];);t.length=r+1}function v(t){for(var r=new Array(t),e=-1;++e<t;)r[e]=0;return r}function c(t){return t>0?Math.floor(t):Math.ceil(t)}function y(t,e){var n,o,i=t.length,a=e.length,u=new Array(i),s=0,p=r;for(o=0;o<a;o++)s=(n=t[o]+e[o]+s)>=p?1:0,u[o]=n-s*p;for(;o<i;)s=(n=t[o]+s)===p?1:0,u[o++]=n-s*p;return s>0&&u.push(s),u}function g(t,r){return t.length>=r.length?y(t,r):y(r,t)}function d(t,e){var n,o,i=t.length,a=new Array(i),u=r;for(o=0;o<i;o++)n=t[o]-u+e,e=Math.floor(n/u),a[o]=n-e*u,e+=1;for(;e>0;)a[o++]=e%u,e=Math.floor(e/u);return a}function m(t,e){var n,o,i=t.length,a=e.length,u=new Array(i),s=0,p=r;for(n=0;n<a;n++)(o=t[n]-s-e[n])<0?(o+=p,s=1):s=0,u[n]=o;for(n=a;n<i;n++){if(!((o=t[n]-s)<0)){u[n++]=o;break}o+=p,u[n]=o}for(;n<i;n++)u[n]=t[n];return h(u),u}function w(t,e,n){var o,i,a=t.length,p=new Array(a),l=-e,h=r;for(o=0;o<a;o++)i=t[o]+l,l=Math.floor(i/h),i%=h,p[o]=i<0?i+h:i;return"number"==typeof(p=f(p))?(n&&(p=-p),new s(p)):new u(p,n)}function b(t,e){var n,o,i,a,u=t.length,s=e.length,p=v(u+s),l=r;for(i=0;i<u;++i){a=t[i];for(var f=0;f<s;++f)n=a*e[f]+p[i+f],o=Math.floor(n/l),p[i+f]=n-o*l,p[i+f+1]+=o}return h(p),p}function M(t,e){var n,o,i=t.length,a=new Array(i),u=r,s=0;for(o=0;o<i;o++)n=t[o]*e+s,s=Math.floor(n/u),a[o]=n-s*u;for(;s>0;)a[o++]=s%u,s=Math.floor(s/u);return a}function q(t,r){for(var e=[];r-- >0;)e.push(0);return e.concat(t)}function S(t,r){var e=Math.max(t.length,r.length);if(e<=30)return b(t,r);e=Math.ceil(e/2);var n=t.slice(e),o=t.slice(0,e),i=r.slice(e),a=r.slice(0,e),u=S(o,a),s=S(n,i),p=S(g(o,n),g(a,i)),l=g(g(u,q(m(m(p,u),s),e)),q(s,2*e));return h(l),l}function E(t,e,n){return new u(t<r?M(e,t):b(e,l(t)),n)}function x(t){var e,n,o,i,a=t.length,u=v(a+a),s=r;for(o=0;o<a;o++){n=0-(i=t[o])*i;for(var p=o;p<a;p++)e=i*t[p]*2+u[o+p]+n,n=Math.floor(e/s),u[o+p]=e-n*s;u[o+a]=n}return h(u),u}function A(t,r){var e,n,o,i,a=t.length,u=v(a);for(o=0,e=a-1;e>=0;--e)o=(i=1e7*o+t[e])-(n=c(i/r))*r,u[e]=0|n;return[u,0|o]}function N(t,e){var n,o,i=$(e),p=t.value,y=i.value;if(0===y)throw new Error("Cannot divide by zero");if(t.isSmall)return i.isSmall?[new s(c(p/y)),new s(p%y)]:[a[0],t];if(i.isSmall){if(1===y)return[t,a[0]];if(-1==y)return[t.negate(),a[0]];var g=Math.abs(y);if(g<r){o=f((n=A(p,g))[0]);var d=n[1];return t.sign&&(d=-d),"number"==typeof o?(t.sign!==i.sign&&(o=-o),[new s(o),new s(d)]):[new u(o,t.sign!==i.sign),new s(d)]}y=l(g)}var w=I(p,y);if(-1===w)return[a[0],t];if(0===w)return[a[t.sign===i.sign?1:-1],a[0]];o=(n=p.length+y.length<=200?function(t,e){var n,o,i,a,u,s,p,l=t.length,h=e.length,c=r,y=v(e.length),g=e[h-1],d=Math.ceil(c/(2*g)),m=M(t,d),w=M(e,d);for(m.length<=l&&m.push(0),w.push(0),g=w[h-1],o=l-h;o>=0;o--){for(n=c-1,m[o+h]!==g&&(n=Math.floor((m[o+h]*c+m[o+h-1])/g)),i=0,a=0,s=w.length,u=0;u<s;u++)i+=n*w[u],p=Math.floor(i/c),a+=m[o+u]-(i-p*c),i=p,a<0?(m[o+u]=a+c,a=-1):(m[o+u]=a,a=0);for(;0!==a;){for(n-=1,i=0,u=0;u<s;u++)(i+=m[o+u]-c+w[u])<0?(m[o+u]=i+c,i=0):(m[o+u]=i,i=1);a+=i}y[o]=n}return m=A(m,d)[0],[f(y),f(m)]}(p,y):function(t,e){for(var n,o,i,a,u,s=t.length,p=e.length,l=[],v=[],c=r;s;)if(v.unshift(t[--s]),h(v),I(v,e)<0)l.push(0);else{i=v[(o=v.length)-1]*c+v[o-2],a=e[p-1]*c+e[p-2],o>p&&(i=(i+1)*c),n=Math.ceil(i/a);do{if(I(u=M(e,n),v)<=0)break;n--}while(n);l.push(n),v=m(v,u)}return l.reverse(),[f(l),f(v)]}(p,y))[0];var b=t.sign!==i.sign,q=n[1],S=t.sign;return"number"==typeof o?(b&&(o=-o),o=new s(o)):o=new u(o,b),"number"==typeof q?(S&&(q=-q),q=new s(q)):q=new u(q,S),[o,q]}function I(t,r){if(t.length!==r.length)return t.length>r.length?1:-1;for(var e=t.length-1;e>=0;e--)if(t[e]!==r[e])return t[e]>r[e]?1:-1;return 0}function O(t){var r=t.abs();return!r.isUnit()&&(!!(r.equals(2)||r.equals(3)||r.equals(5))||!(r.isEven()||r.isDivisibleBy(3)||r.isDivisibleBy(5))&&(!!r.lesser(49)||void 0))}function P(t,r){for(var e,n,i,u=t.prev(),s=u,p=0;s.isEven();)s=s.divide(2),p++;t:for(n=0;n<r.length;n++)if(!t.lesser(r[n])&&!(i=o(r[n]).modPow(s,t)).equals(a[1])&&!i.equals(u)){for(e=p-1;0!=e;e--){if((i=i.square().mod(t)).isUnit())return!1;if(i.equals(u))continue t}return!1}return!0}u.prototype=Object.create(a.prototype),s.prototype=Object.create(a.prototype),u.prototype.add=function(t){var r=$(t);if(this.sign!==r.sign)return this.subtract(r.negate());var e=this.value,n=r.value;return r.isSmall?new u(d(e,Math.abs(n)),this.sign):new u(g(e,n),this.sign)},u.prototype.plus=u.prototype.add,s.prototype.add=function(t){var r=$(t),e=this.value;if(e<0!==r.sign)return this.subtract(r.negate());var n=r.value;if(r.isSmall){if(p(e+n))return new s(e+n);n=l(Math.abs(n))}return new u(d(n,Math.abs(e)),e<0)},s.prototype.plus=s.prototype.add,u.prototype.subtract=function(t){var r=$(t);if(this.sign!==r.sign)return this.add(r.negate());var e=this.value,n=r.value;return r.isSmall?w(e,Math.abs(n),this.sign):function(t,r,e){var n;return I(t,r)>=0?n=m(t,r):(n=m(r,t),e=!e),"number"==typeof(n=f(n))?(e&&(n=-n),new s(n)):new u(n,e)}(e,n,this.sign)},u.prototype.minus=u.prototype.subtract,s.prototype.subtract=function(t){var r=$(t),e=this.value;if(e<0!==r.sign)return this.add(r.negate());var n=r.value;return r.isSmall?new s(e-n):w(n,Math.abs(e),e>=0)},s.prototype.minus=s.prototype.subtract,u.prototype.negate=function(){return new u(this.value,!this.sign)},s.prototype.negate=function(){var t=this.sign,r=new s(-this.value);return r.sign=!t,r},u.prototype.abs=function(){return new u(this.value,!1)},s.prototype.abs=function(){return new s(Math.abs(this.value))},u.prototype.multiply=function(t){var e,n,o,i=$(t),s=this.value,p=i.value,f=this.sign!==i.sign;if(i.isSmall){if(0===p)return a[0];if(1===p)return this;if(-1===p)return this.negate();if((e=Math.abs(p))<r)return new u(M(s,e),f);p=l(e)}return new u(-.012*(n=s.length)-.012*(o=p.length)+15e-6*n*o>0?S(s,p):b(s,p),f)},u.prototype.times=u.prototype.multiply,s.prototype._multiplyBySmall=function(t){return p(t.value*this.value)?new s(t.value*this.value):E(Math.abs(t.value),l(Math.abs(this.value)),this.sign!==t.sign)},u.prototype._multiplyBySmall=function(t){return 0===t.value?a[0]:1===t.value?this:-1===t.value?this.negate():E(Math.abs(t.value),this.value,this.sign!==t.sign)},s.prototype.multiply=function(t){return $(t)._multiplyBySmall(this)},s.prototype.times=s.prototype.multiply,u.prototype.square=function(){return new u(x(this.value),!1)},s.prototype.square=function(){var t=this.value*this.value;return p(t)?new s(t):new u(x(l(Math.abs(this.value))),!1)},u.prototype.divmod=function(t){var r=N(this,t);return{quotient:r[0],remainder:r[1]}},s.prototype.divmod=u.prototype.divmod,u.prototype.divide=function(t){return N(this,t)[0]},s.prototype.over=s.prototype.divide=u.prototype.over=u.prototype.divide,u.prototype.mod=function(t){return N(this,t)[1]},s.prototype.remainder=s.prototype.mod=u.prototype.remainder=u.prototype.mod,u.prototype.pow=function(t){var r,e,n,o=$(t),i=this.value,u=o.value;if(0===u)return a[1];if(0===i)return a[0];if(1===i)return a[1];if(-1===i)return o.isEven()?a[1]:a[-1];if(o.sign)return a[0];if(!o.isSmall)throw new Error("The exponent "+o.toString()+" is too large.");if(this.isSmall&&p(r=Math.pow(i,u)))return new s(c(r));for(e=this,n=a[1];!0&u&&(n=n.times(e),--u),0!==u;)u/=2,e=e.square();return n},s.prototype.pow=u.prototype.pow,u.prototype.modPow=function(t,r){if(t=$(t),(r=$(r)).isZero())throw new Error("Cannot take modPow with modulus 0");for(var e=a[1],n=this.mod(r);t.isPositive();){if(n.isZero())return a[0];t.isOdd()&&(e=e.multiply(n).mod(r)),t=t.divide(2),n=n.square().mod(r)}return e},s.prototype.modPow=u.prototype.modPow,u.prototype.compareAbs=function(t){var r=$(t),e=this.value,n=r.value;return r.isSmall?1:I(e,n)},s.prototype.compareAbs=function(t){var r=$(t),e=Math.abs(this.value),n=r.value;return r.isSmall?e===(n=Math.abs(n))?0:e>n?1:-1:-1},u.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var r=$(t),e=this.value,n=r.value;return this.sign!==r.sign?r.sign?1:-1:r.isSmall?this.sign?-1:1:I(e,n)*(this.sign?-1:1)},u.prototype.compareTo=u.prototype.compare,s.prototype.compare=function(t){if(t===1/0)return-1;if(t===-1/0)return 1;var r=$(t),e=this.value,n=r.value;return r.isSmall?e==n?0:e>n?1:-1:e<0!==r.sign?e<0?-1:1:e<0?1:-1},s.prototype.compareTo=s.prototype.compare,u.prototype.equals=function(t){return 0===this.compare(t)},s.prototype.eq=s.prototype.equals=u.prototype.eq=u.prototype.equals,u.prototype.notEquals=function(t){return 0!==this.compare(t)},s.prototype.neq=s.prototype.notEquals=u.prototype.neq=u.prototype.notEquals,u.prototype.greater=function(t){return this.compare(t)>0},s.prototype.gt=s.prototype.greater=u.prototype.gt=u.prototype.greater,u.prototype.lesser=function(t){return this.compare(t)<0},s.prototype.lt=s.prototype.lesser=u.prototype.lt=u.prototype.lesser,u.prototype.greaterOrEquals=function(t){return this.compare(t)>=0},s.prototype.geq=s.prototype.greaterOrEquals=u.prototype.geq=u.prototype.greaterOrEquals,u.prototype.lesserOrEquals=function(t){return this.compare(t)<=0},s.prototype.leq=s.prototype.lesserOrEquals=u.prototype.leq=u.prototype.lesserOrEquals,u.prototype.isEven=function(){return 0==(1&this.value[0])},s.prototype.isEven=function(){return 0==(1&this.value)},u.prototype.isOdd=function(){return 1==(1&this.value[0])},s.prototype.isOdd=function(){return 1==(1&this.value)},u.prototype.isPositive=function(){return!this.sign},s.prototype.isPositive=function(){return this.value>0},u.prototype.isNegative=function(){return this.sign},s.prototype.isNegative=function(){return this.value<0},u.prototype.isUnit=function(){return!1},s.prototype.isUnit=function(){return 1===Math.abs(this.value)},u.prototype.isZero=function(){return!1},s.prototype.isZero=function(){return 0===this.value},u.prototype.isDivisibleBy=function(t){var r=$(t),e=r.value;return 0!==e&&(1===e||(2===e?this.isEven():this.mod(r).equals(a[0])))},s.prototype.isDivisibleBy=u.prototype.isDivisibleBy,u.prototype.isPrime=function(r){var e=O(this);if(e!==t)return e;var n=this.abs(),i=n.bitLength();if(i<=64)return P(n,[2,325,9375,28178,450775,9780504,1795265022]);for(var a=Math.log(2)*i,u=Math.ceil(!0===r?2*Math.pow(a,2):a),s=[],p=0;p<u;p++)s.push(o(p+2));return P(n,s)},s.prototype.isPrime=u.prototype.isPrime,u.prototype.isProbablePrime=function(r){var e=O(this);if(e!==t)return e;for(var n=this.abs(),i=r===t?5:r,a=[],u=0;u<i;u++)a.push(o.randBetween(2,n.minus(2)));return P(n,a)},s.prototype.isProbablePrime=u.prototype.isProbablePrime,u.prototype.modInv=function(t){for(var r,e,n,i=o.zero,a=o.one,u=$(t),s=this.abs();!s.equals(o.zero);)r=u.divide(s),e=i,n=u,i=a,u=s,a=e.subtract(r.multiply(a)),s=n.subtract(r.multiply(s));if(!u.equals(1))throw new Error(this.toString()+" and "+t.toString()+" are not co-prime");return-1===i.compare(0)&&(i=i.add(t)),this.isNegative()?i.negate():i},s.prototype.modInv=u.prototype.modInv,u.prototype.next=function(){var t=this.value;return this.sign?w(t,1,this.sign):new u(d(t,1),this.sign)},s.prototype.next=function(){var t=this.value;return t+1<e?new s(t+1):new u(n,!1)},u.prototype.prev=function(){var t=this.value;return this.sign?new u(d(t,1),!0):w(t,1,this.sign)},s.prototype.prev=function(){var t=this.value;return t-1>-e?new s(t-1):new u(n,!0)};for(var U=[1];2*U[U.length-1]<=r;)U.push(2*U[U.length-1]);var Z=U.length,C=U[Z-1];function L(t){return("number"==typeof t||"string"==typeof t)&&+Math.abs(t)<=r||t instanceof u&&t.value.length<=1}function j(t,r,e){r=$(r);for(var n=t.isNegative(),i=r.isNegative(),a=n?t.not():t,u=i?r.not():r,s=0,p=0,l=null,f=null,h=[];!a.isZero()||!u.isZero();)s=(l=N(a,C))[1].toJSNumber(),n&&(s=C-1-s),p=(f=N(u,C))[1].toJSNumber(),i&&(p=C-1-p),a=l[0],u=f[0],h.push(e(s,p));for(var v=0!==e(n?1:0,i?1:0)?o(-1):o(0),c=h.length-1;c>=0;c-=1)v=v.multiply(C).add(o(h[c]));return v}u.prototype.shiftLeft=function(t){if(!L(t))throw new Error(String(t)+" is too large for shifting.");if((t=+t)<0)return this.shiftRight(-t);var r=this;if(r.isZero())return r;for(;t>=Z;)r=r.multiply(C),t-=Z-1;return r.multiply(U[t])},s.prototype.shiftLeft=u.prototype.shiftLeft,u.prototype.shiftRight=function(t){var r;if(!L(t))throw new Error(String(t)+" is too large for shifting.");if((t=+t)<0)return this.shiftLeft(-t);for(var e=this;t>=Z;){if(e.isZero()||e.isNegative()&&e.isUnit())return e;e=(r=N(e,C))[1].isNegative()?r[0].prev():r[0],t-=Z-1}return(r=N(e,U[t]))[1].isNegative()?r[0].prev():r[0]},s.prototype.shiftRight=u.prototype.shiftRight,u.prototype.not=function(){return this.negate().prev()},s.prototype.not=u.prototype.not,u.prototype.and=function(t){return j(this,t,(function(t,r){return t&r}))},s.prototype.and=u.prototype.and,u.prototype.or=function(t){return j(this,t,(function(t,r){return t|r}))},s.prototype.or=u.prototype.or,u.prototype.xor=function(t){return j(this,t,(function(t,r){return t^r}))},s.prototype.xor=u.prototype.xor;function z(t){var e=t.value,n="number"==typeof e?1073741824|e:e[0]+e[1]*r|1073758208;return n&-n}function B(t,r){if(r.compareTo(t)<=0){var e=B(t,r.square(r)),n=e.p,i=e.e,a=n.multiply(r);return a.compareTo(t)<=0?{p:a,e:2*i+1}:{p:n,e:2*i}}return{p:o(1),e:0}}function k(t,r){return t=$(t),r=$(r),t.greater(r)?t:r}function J(t,r){return t=$(t),r=$(r),t.lesser(r)?t:r}function R(t,r){if(t=$(t).abs(),r=$(r).abs(),t.equals(r))return t;if(t.isZero())return r;if(r.isZero())return t;for(var e,n,o=a[1];t.isEven()&&r.isEven();)e=Math.min(z(t),z(r)),t=t.divide(e),r=r.divide(e),o=o.multiply(e);for(;t.isEven();)t=t.divide(z(t));do{for(;r.isEven();)r=r.divide(z(r));t.greater(r)&&(n=r,r=t,t=n),r=r.subtract(t)}while(!r.isZero());return o.isUnit()?t:t.multiply(o)}u.prototype.bitLength=function(){var t=this;return t.compareTo(o(0))<0&&(t=t.negate().subtract(o(1))),0===t.compareTo(o(0))?o(0):o(B(t,o(2)).e).add(o(1))},s.prototype.bitLength=u.prototype.bitLength;var T=function(t,r){for(var e=t.length,n=Math.abs(r),o=0;o<e;o++)if("-"!==(l=t[o].toLowerCase())&&/[a-z0-9]/.test(l)){if(/[0-9]/.test(l)&&+l>=n){if("1"===l&&1===n)continue;throw new Error(l+" is not a valid digit in base "+r+".")}if(l.charCodeAt(0)-87>=n)throw new Error(l+" is not a valid digit in base "+r+".")}if(2<=r&&r<=36&&e<=i/Math.log(r)){var a=parseInt(t,r);if(isNaN(a))throw new Error(l+" is not a valid digit in base "+r+".");return new s(parseInt(t,r))}r=$(r);var u=[],p="-"===t[0];for(o=p?1:0;o<t.length;o++){var l,f=(l=t[o].toLowerCase()).charCodeAt(0);if(48<=f&&f<=57)u.push($(l));else if(97<=f&&f<=122)u.push($(l.charCodeAt(0)-87));else{if("<"!==l)throw new Error(l+" is not a valid character");var h=o;do{o++}while(">"!==t[o]);u.push($(t.slice(h+1,o)))}}return D(u,r,p)};function D(t,r,e){var n,o=a[0],i=a[1];for(n=t.length-1;n>=0;n--)o=o.add(t[n].times(i)),i=i.times(r);return e?o.negate():o}function H(t){return t<=35?"0123456789abcdefghijklmnopqrstuvwxyz".charAt(t):"<"+t+">"}function V(t,r){if((r=o(r)).isZero()){if(t.isZero())return{value:[0],isNegative:!1};throw new Error("Cannot convert nonzero numbers to base 0.")}if(r.equals(-1)){if(t.isZero())return{value:[0],isNegative:!1};if(t.isNegative())return{value:[].concat.apply([],Array.apply(null,Array(-t)).map(Array.prototype.valueOf,[1,0])),isNegative:!1};var e=Array.apply(null,Array(+t-1)).map(Array.prototype.valueOf,[0,1]);return e.unshift([1]),{value:[].concat.apply([],e),isNegative:!1}}var n=!1;if(t.isNegative()&&r.isPositive()&&(n=!0,t=t.abs()),r.equals(1))return t.isZero()?{value:[0],isNegative:!1}:{value:Array.apply(null,Array(+t)).map(Number.prototype.valueOf,1),isNegative:n};for(var i,a=[],u=t;u.isNegative()||u.compareAbs(r)>=0;){i=u.divmod(r),u=i.quotient;var s=i.remainder;s.isNegative()&&(s=r.minus(s).abs(),u=u.next()),a.push(s.toJSNumber())}return a.push(u.toJSNumber()),{value:a.reverse(),isNegative:n}}function _(t,r){var e=V(t,r);return(e.isNegative?"-":"")+e.value.map(H).join("")}function K(t){if(p(+t)){var r=+t;if(r===c(r))return new s(r);throw new Error("Invalid integer: "+t)}var e="-"===t[0];e&&(t=t.slice(1));var n=t.split(/e/i);if(n.length>2)throw new Error("Invalid integer: "+n.join("e"));if(2===n.length){var o=n[1];if("+"===o[0]&&(o=o.slice(1)),(o=+o)!==c(o)||!p(o))throw new Error("Invalid integer: "+o+" is not a valid exponent.");var i=n[0],a=i.indexOf(".");if(a>=0&&(o-=i.length-a-1,i=i.slice(0,a)+i.slice(a+1)),o<0)throw new Error("Cannot include negative exponent part for integers");t=i+=new Array(o+1).join("0")}if(!/^([0-9][0-9]*)$/.test(t))throw new Error("Invalid integer: "+t);for(var l=[],f=t.length,v=f-7;f>0;)l.push(+t.slice(v,f)),(v-=7)<0&&(v=0),f-=7;return h(l),new u(l,e)}function $(t){return"number"==typeof t?function(t){if(p(t)){if(t!==c(t))throw new Error(t+" is not an integer.");return new s(t)}return K(t.toString())}(t):"string"==typeof t?K(t):t}u.prototype.toArray=function(t){return V(this,t)},s.prototype.toArray=function(t){return V(this,t)},u.prototype.toString=function(r){if(r===t&&(r=10),10!==r)return _(this,r);for(var e,n=this.value,o=n.length,i=String(n[--o]);--o>=0;)e=String(n[o]),i+="0000000".slice(e.length)+e;return(this.sign?"-":"")+i},s.prototype.toString=function(r){return r===t&&(r=10),10!=r?_(this,r):String(this.value)},u.prototype.toJSON=s.prototype.toJSON=function(){return this.toString()},u.prototype.valueOf=function(){return parseInt(this.toString(),10)},u.prototype.toJSNumber=u.prototype.valueOf,s.prototype.valueOf=function(){return this.value},s.prototype.toJSNumber=s.prototype.valueOf;for(var F=0;F<1e3;F++)a[F]=new s(F),F>0&&(a[-F]=new s(-F));return a.one=a[1],a.zero=a[0],a.minusOne=a[-1],a.max=k,a.min=J,a.gcd=R,a.lcm=function(t,r){return t=$(t).abs(),r=$(r).abs(),t.divide(R(t,r)).multiply(r)},a.isInstance=function(t){return t instanceof u||t instanceof s},a.randBetween=function(t,e){var n=J(t=$(t),e=$(e)),o=k(t,e).subtract(n).add(1);if(o.isSmall)return n.add(Math.floor(Math.random()*o));for(var i=[],a=!0,p=o.value.length-1;p>=0;p--){var l=a?o.value[p]:r,h=c(Math.random()*l);i.unshift(h),h<l&&(a=!1)}return i=f(i),n.add("number"==typeof i?new s(i):new u(i,!1))},a.fromArray=function(t,r,e){return D(t.map($),$(r||10),e)},a}();t.hasOwnProperty("exports")&&(t.exports=o),void 0===(n=function(){return o}.apply(r,[]))||(t.exports=n)}},r={};function e(n){if(r[n])return r[n].exports;var o=r[n]={id:n,loaded:!1,exports:{}};return t[n](o,o.exports,e),o.loaded=!0,o.exports}return e.nmd=t=>(t.paths=[],t.children||(t.children=[]),t),e(146)})()}));