@deficonnect/iso-crypto
Version:
Isomorphic Crypto for WalletConnect
1 lines • 127 kB
JavaScript
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define("WalletConnectIsoCrypto",[],r):"object"==typeof exports?exports.WalletConnectIsoCrypto=r():t.WalletConnectIsoCrypto=r()}(this,(function(){return function(t){var r={};function n(e){if(r[e])return r[e].exports;var i=r[e]={i:e,l:!1,exports:{}};return t[e].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=r,n.d=function(t,r,e){n.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:e})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,r){if(1&r&&(t=n(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var e=Object.create(null);if(n.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)n.d(e,i,function(r){return t[r]}.bind(null,i));return e},n.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(r,"a",r),r},n.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},n.p="",n(n.s=38)}([function(t,r,n){"use strict";n.r(r),function(t){n.d(r,"bufferToArray",(function(){return s})),n.d(r,"bufferToHex",(function(){return a})),n.d(r,"bufferToUtf8",(function(){return f})),n.d(r,"bufferToNumber",(function(){return h})),n.d(r,"bufferToBinary",(function(){return c})),n.d(r,"arrayToBuffer",(function(){return l})),n.d(r,"arrayToHex",(function(){return d})),n.d(r,"arrayToUtf8",(function(){return p})),n.d(r,"arrayToNumber",(function(){return m})),n.d(r,"arrayToBinary",(function(){return y})),n.d(r,"hexToBuffer",(function(){return g})),n.d(r,"hexToArray",(function(){return v})),n.d(r,"hexToUtf8",(function(){return w})),n.d(r,"hexToNumber",(function(){return b})),n.d(r,"hexToBinary",(function(){return M})),n.d(r,"utf8ToBuffer",(function(){return _})),n.d(r,"utf8ToArray",(function(){return A})),n.d(r,"utf8ToHex",(function(){return T})),n.d(r,"utf8ToNumber",(function(){return S})),n.d(r,"utf8ToBinary",(function(){return O})),n.d(r,"numberToBuffer",(function(){return x})),n.d(r,"numberToArray",(function(){return E})),n.d(r,"numberToHex",(function(){return B})),n.d(r,"numberToUtf8",(function(){return R})),n.d(r,"numberToBinary",(function(){return k})),n.d(r,"binaryToBuffer",(function(){return C})),n.d(r,"binaryToArray",(function(){return P})),n.d(r,"binaryToHex",(function(){return N})),n.d(r,"binaryToUtf8",(function(){return L})),n.d(r,"binaryToNumber",(function(){return j})),n.d(r,"isBinaryString",(function(){return I})),n.d(r,"isHexString",(function(){return U})),n.d(r,"isBuffer",(function(){return H})),n.d(r,"isTypedArray",(function(){return D})),n.d(r,"isArrayBuffer",(function(){return W})),n.d(r,"getType",(function(){return F})),n.d(r,"getEncoding",(function(){return Y})),n.d(r,"concatBuffers",(function(){return z})),n.d(r,"concatArrays",(function(){return q})),n.d(r,"trimLeft",(function(){return G})),n.d(r,"trimRight",(function(){return Z})),n.d(r,"calcByteLength",(function(){return $})),n.d(r,"splitBytes",(function(){return V})),n.d(r,"swapBytes",(function(){return J})),n.d(r,"swapHex",(function(){return K})),n.d(r,"sanitizeBytes",(function(){return X})),n.d(r,"padLeft",(function(){return Q})),n.d(r,"padRight",(function(){return tt})),n.d(r,"removeHexPrefix",(function(){return rt})),n.d(r,"addHexPrefix",(function(){return nt})),n.d(r,"sanitizeHex",(function(){return et})),n.d(r,"removeHexLeadingZeros",(function(){return it}));var e=n(12),i=n.n(e),o=n(33),u=n.n(o);function s(t){return new Uint8Array(t)}function a(t,r=!1){const n=t.toString("hex");return r?nt(n):n}function f(t){return t.toString("utf8")}function h(t){return t.readUIntBE(0,t.length)}function c(t){return y(s(t))}function l(t){return u()(t)}function d(t,r=!1){return a(l(t),r)}function p(t){return f(l(t))}function m(t){return h(l(t))}function y(t){return Array.from(t).map(k).join("")}function g(r){return t.from(rt(r),"hex")}function v(t){return s(g(t))}function w(t){return f(g(t))}function b(t){return m(v(t))}function M(t){return y(v(t))}function _(r){return t.from(r,"utf8")}function A(t){return s(_(t))}function T(t,r=!1){return a(_(t),r)}function S(t){const r=parseInt(t,10);return function(t,r){if(!t)throw new Error(r)}(!function(t){return void 0===t}(r),"Number can only safely store up to 53 bits"),r}function O(t){return y(A(t))}function x(t){return C(k(t))}function E(t){return P(k(t))}function B(t,r){return N(k(t),r)}function R(t){return""+t}function k(t){return X((t>>>0).toString(2))}function C(t){return l(P(t))}function P(t){return new Uint8Array(V(t).map(t=>parseInt(t,2)))}function N(t,r){return d(P(t),r)}function L(t){return p(P(t))}function j(t){return m(P(t))}function I(t){return!("string"!=typeof t||!new RegExp(/^[01]+$/).test(t))&&t.length%8==0}function U(t,r){return!("string"!=typeof t||!t.match(/^0x[0-9A-Fa-f]*$/))&&(!r||t.length===2+2*r)}function H(r){return t.isBuffer(r)}function D(t){return i.a.strict(t)&&!H(t)}function W(t){return!D(t)&&!H(t)&&void 0!==t.byteLength}function F(t){return H(t)?"buffer":D(t)?"typed-array":W(t)?"array-buffer":Array.isArray(t)?"array":typeof t}function Y(t){return I(t)?"binary":U(t)?"hex":"utf8"}function z(...r){return t.concat(r)}function q(...t){let r=[];return t.forEach(t=>r=r.concat(Array.from(t))),new Uint8Array([...r])}function G(t,r){const n=t.length-r;return n>0&&(t=t.slice(n)),t}function Z(t,r){return t.slice(0,r)}function $(t,r=8){const n=t%r;return n?(t-n)/r*r+r:t}function V(t,r=8){const n=X(t).match(new RegExp(`.{${r}}`,"gi"));return Array.from(n||[])}function J(t){return V(t).map(ot).join("")}function K(t){return N(J(M(t)))}function X(t,r=8,n="0"){return Q(t,$(t.length,r),n)}function Q(t,r,n="0"){return ut(t,r,!0,n)}function tt(t,r,n="0"){return ut(t,r,!1,n)}function rt(t){return t.replace(/^0x/,"")}function nt(t){return t.startsWith("0x")?t:"0x"+t}function et(t){return(t=X(t=rt(t),2))&&(t=nt(t)),t}function it(t){const r=t.startsWith("0x");return t=(t=rt(t)).startsWith("0")?t.substring(1):t,r?nt(t):t}function ot(t){return t.split("").reverse().join("")}function ut(t,r,n,e="0"){const i=r-t.length;let o=t;if(i>0){const r=e.repeat(i);o=n?r+t:t+r}return o}}.call(this,n(22).Buffer)},function(t,r,n){"use strict";n.d(r,"b",(function(){return 256})),n.d(r,"j",(function(){return 256})),n.d(r,"a",(function(){return"AES-CBC"})),n.d(r,"i",(function(){return"SHA-256"})),n.d(r,"h",(function(){return"HMAC"})),n.d(r,"z",(function(){return"SHA-256"})),n.d(r,"B",(function(){return"SHA-512"})),n.d(r,"c",(function(){return"aes-256-cbc"})),n.d(r,"k",(function(){return"sha256"})),n.d(r,"A",(function(){return"sha256"})),n.d(r,"C",(function(){return"sha512"})),n.d(r,"y",(function(){return"ripemd160"})),n.d(r,"x",(function(){return 1})),n.d(r,"m",(function(){return 32})),n.d(r,"l",(function(){return 16})),n.d(r,"w",(function(){return 32})),n.d(r,"g",(function(){return"hex"})),n.d(r,"E",(function(){return"utf8"})),n.d(r,"f",(function(){return"Bad MAC"})),n.d(r,"n",(function(){return 0})),n.d(r,"o",(function(){return 1})),n.d(r,"r",(function(){return 16})),n.d(r,"t",(function(){return 32})),n.d(r,"v",(function(){return 64})),n.d(r,"q",(function(){return 128})),n.d(r,"s",(function(){return 256})),n.d(r,"u",(function(){return 512})),n.d(r,"p",(function(){return 1024})),n.d(r,"e",(function(){return"encrypt"})),n.d(r,"d",(function(){return"decrypt"})),n.d(r,"D",(function(){return"sign"})),n.d(r,"F",(function(){return"verify"}))},function(t,r,n){"use strict";n.d(r,"a",(function(){return e})),n.d(r,"c",(function(){return i})),n.d(r,"b",(function(){return o})),n.d(r,"d",(function(){return u})),n.d(r,"e",(function(){return s}));const e="INTERNAL_ERROR",i="SERVER_ERROR",o=[-32700,-32600,-32601,-32602,-32603],u=[-32e3,-32099],s={PARSE_ERROR:{code:-32700,message:"Parse error"},INVALID_REQUEST:{code:-32600,message:"Invalid Request"},METHOD_NOT_FOUND:{code:-32601,message:"Method not found"},INVALID_PARAMS:{code:-32602,message:"Invalid params"},[e]:{code:-32603,message:"Internal error"},[i]:{code:-32e3,message:"Server error"}}},function(t,r,n){"use strict";var e=this&&this.__createBinding||(Object.create?function(t,r,n,e){void 0===e&&(e=n),Object.defineProperty(t,e,{enumerable:!0,get:function(){return r[n]}})}:function(t,r,n,e){void 0===e&&(e=n),t[e]=r[n]}),i=this&&this.__exportStar||function(t,r){for(var n in t)"default"===n||r.hasOwnProperty(n)||e(r,t,n)};Object.defineProperty(r,"__esModule",{value:!0}),i(n(41),r),i(n(42),r)},function(t,r,n){"use strict";function e(t){let r=void 0;return"undefined"!=typeof window&&void 0!==window[t]&&(r=window[t]),r}function i(t){const r=e(t);if(!r)throw new Error(t+" is not defined in Window");return r}Object.defineProperty(r,"__esModule",{value:!0}),r.getLocalStorage=r.getLocalStorageOrThrow=r.getCrypto=r.getCryptoOrThrow=r.getLocation=r.getLocationOrThrow=r.getNavigator=r.getNavigatorOrThrow=r.getDocument=r.getDocumentOrThrow=r.getFromWindowOrThrow=r.getFromWindow=void 0,r.getFromWindow=e,r.getFromWindowOrThrow=i,r.getDocumentOrThrow=function(){return i("document")},r.getDocument=function(){return e("document")},r.getNavigatorOrThrow=function(){return i("navigator")},r.getNavigator=function(){return e("navigator")},r.getLocationOrThrow=function(){return i("location")},r.getLocation=function(){return e("location")},r.getCryptoOrThrow=function(){return i("crypto")},r.getCrypto=function(){return e("crypto")},r.getLocalStorageOrThrow=function(){return i("localStorage")},r.getLocalStorage=function(){return e("localStorage")}},function(t,r,n){"use strict";n.d(r,"b",(function(){return u})),n.d(r,"a",(function(){return s})),n.d(r,"c",(function(){return a})),n.d(r,"d",(function(){return f})),n.d(r,"e",(function(){return h})),n.d(r,"f",(function(){return c}));var e=n(3),i=n(1);async function o(t,r=i.a){return e.getSubtleCrypto().importKey("raw",t,function(t){return t===i.a?{length:i.b,name:i.a}:{hash:{name:i.i},name:i.h}}(r),!0,function(t){return t===i.a?[i.e,i.d]:[i.D,i.F]}(r))}async function u(t,r,n){const u=e.getSubtleCrypto(),s=await o(r,i.a),a=await u.encrypt({iv:t,name:i.a},s,n);return new Uint8Array(a)}async function s(t,r,n){const u=e.getSubtleCrypto(),s=await o(r,i.a),a=await u.decrypt({iv:t,name:i.a},s,n);return new Uint8Array(a)}async function a(t,r){const n=e.getSubtleCrypto(),u=await o(t,i.h),s=await n.sign({length:i.j,name:i.h},u,r);return new Uint8Array(s)}async function f(t,r){const n=e.getSubtleCrypto(),u=await o(t,i.h),s=await n.sign({length:i.u,name:i.h},u,r);return new Uint8Array(s)}async function h(t){const r=e.getSubtleCrypto(),n=await r.digest({name:i.z},t);return new Uint8Array(n)}async function c(t){const r=e.getSubtleCrypto(),n=await r.digest({name:i.B},t);return new Uint8Array(n)}},function(t,r,n){"use strict";n.d(r,"c",(function(){return i})),n.d(r,"a",(function(){return o})),n.d(r,"b",(function(){return u}));var e=n(2);function i(t){return e.b.includes(t)}function o(t){return Object.keys(e.e).includes(t)?e.e[t]:e.e[e.a]}function u(t){const r=Object.values(e.e).find(r=>r.code===t);return r||e.e[e.a]}},function(t,r,n){"use strict";n.r(r);var e=n(17);for(var i in e)"default"!==i&&function(t){n.d(r,t,(function(){return e[t]}))}(i);var o=n(18);n.d(r,"pkcs7",(function(){return o.a}));var u=n(19);for(var i in u)["pkcs7","default"].indexOf(i)<0&&function(t){n.d(r,t,(function(){return u[t]}))}(i);var s=n(20);n.d(r,"assert",(function(){return s.a})),n.d(r,"isConstantTime",(function(){return s.b}))},function(t,r,n){"use strict";n.d(r,"a",(function(){return e}));class e{}},function(t,r,n){(function(t){!function(t,r){"use strict";function e(t,r){if(!t)throw new Error(r||"Assertion failed")}function i(t,r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t}function o(t,r,n){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==r&&"be"!==r||(n=r,r=10),this._init(t||0,r||10,n||"be"))}var u;"object"==typeof t?t.exports=o:r.BN=o,o.BN=o,o.wordSize=26;try{u=n(47).Buffer}catch(t){}function s(t,r,n){for(var e=0,i=Math.min(t.length,n),o=r;o<i;o++){var u=t.charCodeAt(o)-48;e<<=4,e|=u>=49&&u<=54?u-49+10:u>=17&&u<=22?u-17+10:15&u}return e}function a(t,r,n,e){for(var i=0,o=Math.min(t.length,n),u=r;u<o;u++){var s=t.charCodeAt(u)-48;i*=e,i+=s>=49?s-49+10:s>=17?s-17+10:s}return i}o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,r){return t.cmp(r)>0?t:r},o.min=function(t,r){return t.cmp(r)<0?t:r},o.prototype._init=function(t,r,n){if("number"==typeof t)return this._initNumber(t,r,n);if("object"==typeof t)return this._initArray(t,r,n);"hex"===r&&(r=16),e(r===(0|r)&&r>=2&&r<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&i++,16===r?this._parseHex(t,i):this._parseBase(t,r,i),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),r,n)},o.prototype._initNumber=function(t,r,n){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(e(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),r,n)},o.prototype._initArray=function(t,r,n){if(e("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var i=0;i<this.length;i++)this.words[i]=0;var o,u,s=0;if("be"===n)for(i=t.length-1,o=0;i>=0;i-=3)u=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=u<<s&67108863,this.words[o+1]=u>>>26-s&67108863,(s+=24)>=26&&(s-=26,o++);else if("le"===n)for(i=0,o=0;i<t.length;i+=3)u=t[i]|t[i+1]<<8|t[i+2]<<16,this.words[o]|=u<<s&67108863,this.words[o+1]=u>>>26-s&67108863,(s+=24)>=26&&(s-=26,o++);return this.strip()},o.prototype._parseHex=function(t,r){this.length=Math.ceil((t.length-r)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var e,i,o=0;for(n=t.length-6,e=0;n>=r;n-=6)i=s(t,n,n+6),this.words[e]|=i<<o&67108863,this.words[e+1]|=i>>>26-o&4194303,(o+=24)>=26&&(o-=26,e++);n+6!==r&&(i=s(t,r,n+6),this.words[e]|=i<<o&67108863,this.words[e+1]|=i>>>26-o&4194303),this.strip()},o.prototype._parseBase=function(t,r,n){this.words=[0],this.length=1;for(var e=0,i=1;i<=67108863;i*=r)e++;e--,i=i/r|0;for(var o=t.length-n,u=o%e,s=Math.min(o,o-u)+n,f=0,h=n;h<s;h+=e)f=a(t,h,h+e,r),this.imuln(i),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f);if(0!==u){var c=1;for(f=a(t,h,t.length,r),h=0;h<u;h++)c*=r;this.imuln(c),this.words[0]+f<67108864?this.words[0]+=f:this._iaddn(f)}},o.prototype.copy=function(t){t.words=new Array(this.length);for(var r=0;r<this.length;r++)t.words[r]=this.words[r];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},o.prototype.strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},o.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var f=["","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"],h=[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],c=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function l(t,r,n){n.negative=r.negative^t.negative;var e=t.length+r.length|0;n.length=e,e=e-1|0;var i=0|t.words[0],o=0|r.words[0],u=i*o,s=67108863&u,a=u/67108864|0;n.words[0]=s;for(var f=1;f<e;f++){for(var h=a>>>26,c=67108863&a,l=Math.min(f,r.length-1),d=Math.max(0,f-t.length+1);d<=l;d++){var p=f-d|0;h+=(u=(i=0|t.words[p])*(o=0|r.words[d])+c)/67108864|0,c=67108863&u}n.words[f]=0|c,a=0|h}return 0!==a?n.words[f]=0|a:n.length--,n.strip()}o.prototype.toString=function(t,r){var n;if(r=0|r||1,16===(t=t||10)||"hex"===t){n="";for(var i=0,o=0,u=0;u<this.length;u++){var s=this.words[u],a=(16777215&(s<<i|o)).toString(16);n=0!==(o=s>>>24-i&16777215)||u!==this.length-1?f[6-a.length]+a+n:a+n,(i+=2)>=26&&(i-=26,u--)}for(0!==o&&(n=o.toString(16)+n);n.length%r!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var l=h[t],d=c[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var m=p.modn(d).toString(t);n=(p=p.idivn(d)).isZero()?m+n:f[l-m.length]+m+n}for(this.isZero()&&(n="0"+n);n.length%r!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}e(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(t,r){return e(void 0!==u),this.toArrayLike(u,t,r)},o.prototype.toArray=function(t,r){return this.toArrayLike(Array,t,r)},o.prototype.toArrayLike=function(t,r,n){var i=this.byteLength(),o=n||Math.max(1,i);e(i<=o,"byte array longer than desired length"),e(o>0,"Requested array length <= 0"),this.strip();var u,s,a="le"===r,f=new t(o),h=this.clone();if(a){for(s=0;!h.isZero();s++)u=h.andln(255),h.iushrn(8),f[s]=u;for(;s<o;s++)f[s]=0}else{for(s=0;s<o-i;s++)f[s]=0;for(s=0;!h.isZero();s++)u=h.andln(255),h.iushrn(8),f[o-s-1]=u}return f},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var r=t,n=0;return r>=4096&&(n+=13,r>>>=13),r>=64&&(n+=7,r>>>=7),r>=8&&(n+=4,r>>>=4),r>=2&&(n+=2,r>>>=2),n+r},o.prototype._zeroBits=function(t){if(0===t)return 26;var r=t,n=0;return 0==(8191&r)&&(n+=13,r>>>=13),0==(127&r)&&(n+=7,r>>>=7),0==(15&r)&&(n+=4,r>>>=4),0==(3&r)&&(n+=2,r>>>=2),0==(1&r)&&n++,n},o.prototype.bitLength=function(){var t=this.words[this.length-1],r=this._countBits(t);return 26*(this.length-1)+r},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<this.length;r++){var n=this._zeroBits(this.words[r]);if(t+=n,26!==n)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]|t.words[r];return this.strip()},o.prototype.ior=function(t){return e(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var r;r=this.length>t.length?t:this;for(var n=0;n<r.length;n++)this.words[n]=this.words[n]&t.words[n];return this.length=r.length,this.strip()},o.prototype.iand=function(t){return e(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var r,n;this.length>t.length?(r=this,n=t):(r=t,n=this);for(var e=0;e<n.length;e++)this.words[e]=r.words[e]^n.words[e];if(this!==r)for(;e<r.length;e++)this.words[e]=r.words[e];return this.length=r.length,this.strip()},o.prototype.ixor=function(t){return e(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){e("number"==typeof t&&t>=0);var r=0|Math.ceil(t/26),n=t%26;this._expand(r),n>0&&r--;for(var i=0;i<r;i++)this.words[i]=67108863&~this.words[i];return n>0&&(this.words[i]=~this.words[i]&67108863>>26-n),this.strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,r){e("number"==typeof t&&t>=0);var n=t/26|0,i=t%26;return this._expand(n+1),this.words[n]=r?this.words[n]|1<<i:this.words[n]&~(1<<i),this.strip()},o.prototype.iadd=function(t){var r,n,e;if(0!==this.negative&&0===t.negative)return this.negative=0,r=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,r=this.isub(t),t.negative=1,r._normSign();this.length>t.length?(n=this,e=t):(n=t,e=this);for(var i=0,o=0;o<e.length;o++)r=(0|n.words[o])+(0|e.words[o])+i,this.words[o]=67108863&r,i=r>>>26;for(;0!==i&&o<n.length;o++)r=(0|n.words[o])+i,this.words[o]=67108863&r,i=r>>>26;if(this.length=n.length,0!==i)this.words[this.length]=i,this.length++;else if(n!==this)for(;o<n.length;o++)this.words[o]=n.words[o];return this},o.prototype.add=function(t){var r;return 0!==t.negative&&0===this.negative?(t.negative=0,r=this.sub(t),t.negative^=1,r):0===t.negative&&0!==this.negative?(this.negative=0,r=t.sub(this),this.negative=1,r):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var n,e,i=this.cmp(t);if(0===i)return this.negative=0,this.length=1,this.words[0]=0,this;i>0?(n=this,e=t):(n=t,e=this);for(var o=0,u=0;u<e.length;u++)o=(r=(0|n.words[u])-(0|e.words[u])+o)>>26,this.words[u]=67108863&r;for(;0!==o&&u<n.length;u++)o=(r=(0|n.words[u])+o)>>26,this.words[u]=67108863&r;if(0===o&&u<n.length&&n!==this)for(;u<n.length;u++)this.words[u]=n.words[u];return this.length=Math.max(this.length,u),n!==this&&(this.negative=1),this.strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var d=function(t,r,n){var e,i,o,u=t.words,s=r.words,a=n.words,f=0,h=0|u[0],c=8191&h,l=h>>>13,d=0|u[1],p=8191&d,m=d>>>13,y=0|u[2],g=8191&y,v=y>>>13,w=0|u[3],b=8191&w,M=w>>>13,_=0|u[4],A=8191&_,T=_>>>13,S=0|u[5],O=8191&S,x=S>>>13,E=0|u[6],B=8191&E,R=E>>>13,k=0|u[7],C=8191&k,P=k>>>13,N=0|u[8],L=8191&N,j=N>>>13,I=0|u[9],U=8191&I,H=I>>>13,D=0|s[0],W=8191&D,F=D>>>13,Y=0|s[1],z=8191&Y,q=Y>>>13,G=0|s[2],Z=8191&G,$=G>>>13,V=0|s[3],J=8191&V,K=V>>>13,X=0|s[4],Q=8191&X,tt=X>>>13,rt=0|s[5],nt=8191&rt,et=rt>>>13,it=0|s[6],ot=8191&it,ut=it>>>13,st=0|s[7],at=8191&st,ft=st>>>13,ht=0|s[8],ct=8191&ht,lt=ht>>>13,dt=0|s[9],pt=8191&dt,mt=dt>>>13;n.negative=t.negative^r.negative,n.length=19;var yt=(f+(e=Math.imul(c,W))|0)+((8191&(i=(i=Math.imul(c,F))+Math.imul(l,W)|0))<<13)|0;f=((o=Math.imul(l,F))+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,e=Math.imul(p,W),i=(i=Math.imul(p,F))+Math.imul(m,W)|0,o=Math.imul(m,F);var gt=(f+(e=e+Math.imul(c,z)|0)|0)+((8191&(i=(i=i+Math.imul(c,q)|0)+Math.imul(l,z)|0))<<13)|0;f=((o=o+Math.imul(l,q)|0)+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,e=Math.imul(g,W),i=(i=Math.imul(g,F))+Math.imul(v,W)|0,o=Math.imul(v,F),e=e+Math.imul(p,z)|0,i=(i=i+Math.imul(p,q)|0)+Math.imul(m,z)|0,o=o+Math.imul(m,q)|0;var vt=(f+(e=e+Math.imul(c,Z)|0)|0)+((8191&(i=(i=i+Math.imul(c,$)|0)+Math.imul(l,Z)|0))<<13)|0;f=((o=o+Math.imul(l,$)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,e=Math.imul(b,W),i=(i=Math.imul(b,F))+Math.imul(M,W)|0,o=Math.imul(M,F),e=e+Math.imul(g,z)|0,i=(i=i+Math.imul(g,q)|0)+Math.imul(v,z)|0,o=o+Math.imul(v,q)|0,e=e+Math.imul(p,Z)|0,i=(i=i+Math.imul(p,$)|0)+Math.imul(m,Z)|0,o=o+Math.imul(m,$)|0;var wt=(f+(e=e+Math.imul(c,J)|0)|0)+((8191&(i=(i=i+Math.imul(c,K)|0)+Math.imul(l,J)|0))<<13)|0;f=((o=o+Math.imul(l,K)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,e=Math.imul(A,W),i=(i=Math.imul(A,F))+Math.imul(T,W)|0,o=Math.imul(T,F),e=e+Math.imul(b,z)|0,i=(i=i+Math.imul(b,q)|0)+Math.imul(M,z)|0,o=o+Math.imul(M,q)|0,e=e+Math.imul(g,Z)|0,i=(i=i+Math.imul(g,$)|0)+Math.imul(v,Z)|0,o=o+Math.imul(v,$)|0,e=e+Math.imul(p,J)|0,i=(i=i+Math.imul(p,K)|0)+Math.imul(m,J)|0,o=o+Math.imul(m,K)|0;var bt=(f+(e=e+Math.imul(c,Q)|0)|0)+((8191&(i=(i=i+Math.imul(c,tt)|0)+Math.imul(l,Q)|0))<<13)|0;f=((o=o+Math.imul(l,tt)|0)+(i>>>13)|0)+(bt>>>26)|0,bt&=67108863,e=Math.imul(O,W),i=(i=Math.imul(O,F))+Math.imul(x,W)|0,o=Math.imul(x,F),e=e+Math.imul(A,z)|0,i=(i=i+Math.imul(A,q)|0)+Math.imul(T,z)|0,o=o+Math.imul(T,q)|0,e=e+Math.imul(b,Z)|0,i=(i=i+Math.imul(b,$)|0)+Math.imul(M,Z)|0,o=o+Math.imul(M,$)|0,e=e+Math.imul(g,J)|0,i=(i=i+Math.imul(g,K)|0)+Math.imul(v,J)|0,o=o+Math.imul(v,K)|0,e=e+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0;var Mt=(f+(e=e+Math.imul(c,nt)|0)|0)+((8191&(i=(i=i+Math.imul(c,et)|0)+Math.imul(l,nt)|0))<<13)|0;f=((o=o+Math.imul(l,et)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,e=Math.imul(B,W),i=(i=Math.imul(B,F))+Math.imul(R,W)|0,o=Math.imul(R,F),e=e+Math.imul(O,z)|0,i=(i=i+Math.imul(O,q)|0)+Math.imul(x,z)|0,o=o+Math.imul(x,q)|0,e=e+Math.imul(A,Z)|0,i=(i=i+Math.imul(A,$)|0)+Math.imul(T,Z)|0,o=o+Math.imul(T,$)|0,e=e+Math.imul(b,J)|0,i=(i=i+Math.imul(b,K)|0)+Math.imul(M,J)|0,o=o+Math.imul(M,K)|0,e=e+Math.imul(g,Q)|0,i=(i=i+Math.imul(g,tt)|0)+Math.imul(v,Q)|0,o=o+Math.imul(v,tt)|0,e=e+Math.imul(p,nt)|0,i=(i=i+Math.imul(p,et)|0)+Math.imul(m,nt)|0,o=o+Math.imul(m,et)|0;var _t=(f+(e=e+Math.imul(c,ot)|0)|0)+((8191&(i=(i=i+Math.imul(c,ut)|0)+Math.imul(l,ot)|0))<<13)|0;f=((o=o+Math.imul(l,ut)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,e=Math.imul(C,W),i=(i=Math.imul(C,F))+Math.imul(P,W)|0,o=Math.imul(P,F),e=e+Math.imul(B,z)|0,i=(i=i+Math.imul(B,q)|0)+Math.imul(R,z)|0,o=o+Math.imul(R,q)|0,e=e+Math.imul(O,Z)|0,i=(i=i+Math.imul(O,$)|0)+Math.imul(x,Z)|0,o=o+Math.imul(x,$)|0,e=e+Math.imul(A,J)|0,i=(i=i+Math.imul(A,K)|0)+Math.imul(T,J)|0,o=o+Math.imul(T,K)|0,e=e+Math.imul(b,Q)|0,i=(i=i+Math.imul(b,tt)|0)+Math.imul(M,Q)|0,o=o+Math.imul(M,tt)|0,e=e+Math.imul(g,nt)|0,i=(i=i+Math.imul(g,et)|0)+Math.imul(v,nt)|0,o=o+Math.imul(v,et)|0,e=e+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,ut)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,ut)|0;var At=(f+(e=e+Math.imul(c,at)|0)|0)+((8191&(i=(i=i+Math.imul(c,ft)|0)+Math.imul(l,at)|0))<<13)|0;f=((o=o+Math.imul(l,ft)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,e=Math.imul(L,W),i=(i=Math.imul(L,F))+Math.imul(j,W)|0,o=Math.imul(j,F),e=e+Math.imul(C,z)|0,i=(i=i+Math.imul(C,q)|0)+Math.imul(P,z)|0,o=o+Math.imul(P,q)|0,e=e+Math.imul(B,Z)|0,i=(i=i+Math.imul(B,$)|0)+Math.imul(R,Z)|0,o=o+Math.imul(R,$)|0,e=e+Math.imul(O,J)|0,i=(i=i+Math.imul(O,K)|0)+Math.imul(x,J)|0,o=o+Math.imul(x,K)|0,e=e+Math.imul(A,Q)|0,i=(i=i+Math.imul(A,tt)|0)+Math.imul(T,Q)|0,o=o+Math.imul(T,tt)|0,e=e+Math.imul(b,nt)|0,i=(i=i+Math.imul(b,et)|0)+Math.imul(M,nt)|0,o=o+Math.imul(M,et)|0,e=e+Math.imul(g,ot)|0,i=(i=i+Math.imul(g,ut)|0)+Math.imul(v,ot)|0,o=o+Math.imul(v,ut)|0,e=e+Math.imul(p,at)|0,i=(i=i+Math.imul(p,ft)|0)+Math.imul(m,at)|0,o=o+Math.imul(m,ft)|0;var Tt=(f+(e=e+Math.imul(c,ct)|0)|0)+((8191&(i=(i=i+Math.imul(c,lt)|0)+Math.imul(l,ct)|0))<<13)|0;f=((o=o+Math.imul(l,lt)|0)+(i>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,e=Math.imul(U,W),i=(i=Math.imul(U,F))+Math.imul(H,W)|0,o=Math.imul(H,F),e=e+Math.imul(L,z)|0,i=(i=i+Math.imul(L,q)|0)+Math.imul(j,z)|0,o=o+Math.imul(j,q)|0,e=e+Math.imul(C,Z)|0,i=(i=i+Math.imul(C,$)|0)+Math.imul(P,Z)|0,o=o+Math.imul(P,$)|0,e=e+Math.imul(B,J)|0,i=(i=i+Math.imul(B,K)|0)+Math.imul(R,J)|0,o=o+Math.imul(R,K)|0,e=e+Math.imul(O,Q)|0,i=(i=i+Math.imul(O,tt)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,tt)|0,e=e+Math.imul(A,nt)|0,i=(i=i+Math.imul(A,et)|0)+Math.imul(T,nt)|0,o=o+Math.imul(T,et)|0,e=e+Math.imul(b,ot)|0,i=(i=i+Math.imul(b,ut)|0)+Math.imul(M,ot)|0,o=o+Math.imul(M,ut)|0,e=e+Math.imul(g,at)|0,i=(i=i+Math.imul(g,ft)|0)+Math.imul(v,at)|0,o=o+Math.imul(v,ft)|0,e=e+Math.imul(p,ct)|0,i=(i=i+Math.imul(p,lt)|0)+Math.imul(m,ct)|0,o=o+Math.imul(m,lt)|0;var St=(f+(e=e+Math.imul(c,pt)|0)|0)+((8191&(i=(i=i+Math.imul(c,mt)|0)+Math.imul(l,pt)|0))<<13)|0;f=((o=o+Math.imul(l,mt)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,e=Math.imul(U,z),i=(i=Math.imul(U,q))+Math.imul(H,z)|0,o=Math.imul(H,q),e=e+Math.imul(L,Z)|0,i=(i=i+Math.imul(L,$)|0)+Math.imul(j,Z)|0,o=o+Math.imul(j,$)|0,e=e+Math.imul(C,J)|0,i=(i=i+Math.imul(C,K)|0)+Math.imul(P,J)|0,o=o+Math.imul(P,K)|0,e=e+Math.imul(B,Q)|0,i=(i=i+Math.imul(B,tt)|0)+Math.imul(R,Q)|0,o=o+Math.imul(R,tt)|0,e=e+Math.imul(O,nt)|0,i=(i=i+Math.imul(O,et)|0)+Math.imul(x,nt)|0,o=o+Math.imul(x,et)|0,e=e+Math.imul(A,ot)|0,i=(i=i+Math.imul(A,ut)|0)+Math.imul(T,ot)|0,o=o+Math.imul(T,ut)|0,e=e+Math.imul(b,at)|0,i=(i=i+Math.imul(b,ft)|0)+Math.imul(M,at)|0,o=o+Math.imul(M,ft)|0,e=e+Math.imul(g,ct)|0,i=(i=i+Math.imul(g,lt)|0)+Math.imul(v,ct)|0,o=o+Math.imul(v,lt)|0;var Ot=(f+(e=e+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;f=((o=o+Math.imul(m,mt)|0)+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,e=Math.imul(U,Z),i=(i=Math.imul(U,$))+Math.imul(H,Z)|0,o=Math.imul(H,$),e=e+Math.imul(L,J)|0,i=(i=i+Math.imul(L,K)|0)+Math.imul(j,J)|0,o=o+Math.imul(j,K)|0,e=e+Math.imul(C,Q)|0,i=(i=i+Math.imul(C,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,e=e+Math.imul(B,nt)|0,i=(i=i+Math.imul(B,et)|0)+Math.imul(R,nt)|0,o=o+Math.imul(R,et)|0,e=e+Math.imul(O,ot)|0,i=(i=i+Math.imul(O,ut)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,ut)|0,e=e+Math.imul(A,at)|0,i=(i=i+Math.imul(A,ft)|0)+Math.imul(T,at)|0,o=o+Math.imul(T,ft)|0,e=e+Math.imul(b,ct)|0,i=(i=i+Math.imul(b,lt)|0)+Math.imul(M,ct)|0,o=o+Math.imul(M,lt)|0;var xt=(f+(e=e+Math.imul(g,pt)|0)|0)+((8191&(i=(i=i+Math.imul(g,mt)|0)+Math.imul(v,pt)|0))<<13)|0;f=((o=o+Math.imul(v,mt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,e=Math.imul(U,J),i=(i=Math.imul(U,K))+Math.imul(H,J)|0,o=Math.imul(H,K),e=e+Math.imul(L,Q)|0,i=(i=i+Math.imul(L,tt)|0)+Math.imul(j,Q)|0,o=o+Math.imul(j,tt)|0,e=e+Math.imul(C,nt)|0,i=(i=i+Math.imul(C,et)|0)+Math.imul(P,nt)|0,o=o+Math.imul(P,et)|0,e=e+Math.imul(B,ot)|0,i=(i=i+Math.imul(B,ut)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,ut)|0,e=e+Math.imul(O,at)|0,i=(i=i+Math.imul(O,ft)|0)+Math.imul(x,at)|0,o=o+Math.imul(x,ft)|0,e=e+Math.imul(A,ct)|0,i=(i=i+Math.imul(A,lt)|0)+Math.imul(T,ct)|0,o=o+Math.imul(T,lt)|0;var Et=(f+(e=e+Math.imul(b,pt)|0)|0)+((8191&(i=(i=i+Math.imul(b,mt)|0)+Math.imul(M,pt)|0))<<13)|0;f=((o=o+Math.imul(M,mt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,e=Math.imul(U,Q),i=(i=Math.imul(U,tt))+Math.imul(H,Q)|0,o=Math.imul(H,tt),e=e+Math.imul(L,nt)|0,i=(i=i+Math.imul(L,et)|0)+Math.imul(j,nt)|0,o=o+Math.imul(j,et)|0,e=e+Math.imul(C,ot)|0,i=(i=i+Math.imul(C,ut)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,ut)|0,e=e+Math.imul(B,at)|0,i=(i=i+Math.imul(B,ft)|0)+Math.imul(R,at)|0,o=o+Math.imul(R,ft)|0,e=e+Math.imul(O,ct)|0,i=(i=i+Math.imul(O,lt)|0)+Math.imul(x,ct)|0,o=o+Math.imul(x,lt)|0;var Bt=(f+(e=e+Math.imul(A,pt)|0)|0)+((8191&(i=(i=i+Math.imul(A,mt)|0)+Math.imul(T,pt)|0))<<13)|0;f=((o=o+Math.imul(T,mt)|0)+(i>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,e=Math.imul(U,nt),i=(i=Math.imul(U,et))+Math.imul(H,nt)|0,o=Math.imul(H,et),e=e+Math.imul(L,ot)|0,i=(i=i+Math.imul(L,ut)|0)+Math.imul(j,ot)|0,o=o+Math.imul(j,ut)|0,e=e+Math.imul(C,at)|0,i=(i=i+Math.imul(C,ft)|0)+Math.imul(P,at)|0,o=o+Math.imul(P,ft)|0,e=e+Math.imul(B,ct)|0,i=(i=i+Math.imul(B,lt)|0)+Math.imul(R,ct)|0,o=o+Math.imul(R,lt)|0;var Rt=(f+(e=e+Math.imul(O,pt)|0)|0)+((8191&(i=(i=i+Math.imul(O,mt)|0)+Math.imul(x,pt)|0))<<13)|0;f=((o=o+Math.imul(x,mt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,e=Math.imul(U,ot),i=(i=Math.imul(U,ut))+Math.imul(H,ot)|0,o=Math.imul(H,ut),e=e+Math.imul(L,at)|0,i=(i=i+Math.imul(L,ft)|0)+Math.imul(j,at)|0,o=o+Math.imul(j,ft)|0,e=e+Math.imul(C,ct)|0,i=(i=i+Math.imul(C,lt)|0)+Math.imul(P,ct)|0,o=o+Math.imul(P,lt)|0;var kt=(f+(e=e+Math.imul(B,pt)|0)|0)+((8191&(i=(i=i+Math.imul(B,mt)|0)+Math.imul(R,pt)|0))<<13)|0;f=((o=o+Math.imul(R,mt)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,e=Math.imul(U,at),i=(i=Math.imul(U,ft))+Math.imul(H,at)|0,o=Math.imul(H,ft),e=e+Math.imul(L,ct)|0,i=(i=i+Math.imul(L,lt)|0)+Math.imul(j,ct)|0,o=o+Math.imul(j,lt)|0;var Ct=(f+(e=e+Math.imul(C,pt)|0)|0)+((8191&(i=(i=i+Math.imul(C,mt)|0)+Math.imul(P,pt)|0))<<13)|0;f=((o=o+Math.imul(P,mt)|0)+(i>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,e=Math.imul(U,ct),i=(i=Math.imul(U,lt))+Math.imul(H,ct)|0,o=Math.imul(H,lt);var Pt=(f+(e=e+Math.imul(L,pt)|0)|0)+((8191&(i=(i=i+Math.imul(L,mt)|0)+Math.imul(j,pt)|0))<<13)|0;f=((o=o+Math.imul(j,mt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863;var Nt=(f+(e=Math.imul(U,pt))|0)+((8191&(i=(i=Math.imul(U,mt))+Math.imul(H,pt)|0))<<13)|0;return f=((o=Math.imul(H,mt))+(i>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,a[0]=yt,a[1]=gt,a[2]=vt,a[3]=wt,a[4]=bt,a[5]=Mt,a[6]=_t,a[7]=At,a[8]=Tt,a[9]=St,a[10]=Ot,a[11]=xt,a[12]=Et,a[13]=Bt,a[14]=Rt,a[15]=kt,a[16]=Ct,a[17]=Pt,a[18]=Nt,0!==f&&(a[19]=f,n.length++),n};function p(t,r,n){return(new m).mulp(t,r,n)}function m(t,r){this.x=t,this.y=r}Math.imul||(d=l),o.prototype.mulTo=function(t,r){var n=this.length+t.length;return 10===this.length&&10===t.length?d(this,t,r):n<63?l(this,t,r):n<1024?function(t,r,n){n.negative=r.negative^t.negative,n.length=t.length+r.length;for(var e=0,i=0,o=0;o<n.length-1;o++){var u=i;i=0;for(var s=67108863&e,a=Math.min(o,r.length-1),f=Math.max(0,o-t.length+1);f<=a;f++){var h=o-f,c=(0|t.words[h])*(0|r.words[f]),l=67108863&c;s=67108863&(l=l+s|0),i+=(u=(u=u+(c/67108864|0)|0)+(l>>>26)|0)>>>26,u&=67108863}n.words[o]=s,e=u,u=i}return 0!==e?n.words[o]=e:n.length--,n.strip()}(this,t,r):p(this,t,r)},m.prototype.makeRBT=function(t){for(var r=new Array(t),n=o.prototype._countBits(t)-1,e=0;e<t;e++)r[e]=this.revBin(e,n,t);return r},m.prototype.revBin=function(t,r,n){if(0===t||t===n-1)return t;for(var e=0,i=0;i<r;i++)e|=(1&t)<<r-i-1,t>>=1;return e},m.prototype.permute=function(t,r,n,e,i,o){for(var u=0;u<o;u++)e[u]=r[t[u]],i[u]=n[t[u]]},m.prototype.transform=function(t,r,n,e,i,o){this.permute(o,t,r,n,e,i);for(var u=1;u<i;u<<=1)for(var s=u<<1,a=Math.cos(2*Math.PI/s),f=Math.sin(2*Math.PI/s),h=0;h<i;h+=s)for(var c=a,l=f,d=0;d<u;d++){var p=n[h+d],m=e[h+d],y=n[h+d+u],g=e[h+d+u],v=c*y-l*g;g=c*g+l*y,y=v,n[h+d]=p+y,e[h+d]=m+g,n[h+d+u]=p-y,e[h+d+u]=m-g,d!==s&&(v=a*c-f*l,l=a*l+f*c,c=v)}},m.prototype.guessLen13b=function(t,r){var n=1|Math.max(r,t),e=1&n,i=0;for(n=n/2|0;n;n>>>=1)i++;return 1<<i+1+e},m.prototype.conjugate=function(t,r,n){if(!(n<=1))for(var e=0;e<n/2;e++){var i=t[e];t[e]=t[n-e-1],t[n-e-1]=i,i=r[e],r[e]=-r[n-e-1],r[n-e-1]=-i}},m.prototype.normalize13b=function(t,r){for(var n=0,e=0;e<r/2;e++){var i=8192*Math.round(t[2*e+1]/r)+Math.round(t[2*e]/r)+n;t[e]=67108863&i,n=i<67108864?0:i/67108864|0}return t},m.prototype.convert13b=function(t,r,n,i){for(var o=0,u=0;u<r;u++)o+=0|t[u],n[2*u]=8191&o,o>>>=13,n[2*u+1]=8191&o,o>>>=13;for(u=2*r;u<i;++u)n[u]=0;e(0===o),e(0==(-8192&o))},m.prototype.stub=function(t){for(var r=new Array(t),n=0;n<t;n++)r[n]=0;return r},m.prototype.mulp=function(t,r,n){var e=2*this.guessLen13b(t.length,r.length),i=this.makeRBT(e),o=this.stub(e),u=new Array(e),s=new Array(e),a=new Array(e),f=new Array(e),h=new Array(e),c=new Array(e),l=n.words;l.length=e,this.convert13b(t.words,t.length,u,e),this.convert13b(r.words,r.length,f,e),this.transform(u,o,s,a,e,i),this.transform(f,o,h,c,e,i);for(var d=0;d<e;d++){var p=s[d]*h[d]-a[d]*c[d];a[d]=s[d]*c[d]+a[d]*h[d],s[d]=p}return this.conjugate(s,a,e),this.transform(s,a,l,o,e,i),this.conjugate(l,o,e),this.normalize13b(l,e),n.negative=t.negative^r.negative,n.length=t.length+r.length,n.strip()},o.prototype.mul=function(t){var r=new o(null);return r.words=new Array(this.length+t.length),this.mulTo(t,r)},o.prototype.mulf=function(t){var r=new o(null);return r.words=new Array(this.length+t.length),p(this,t,r)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){e("number"==typeof t),e(t<67108864);for(var r=0,n=0;n<this.length;n++){var i=(0|this.words[n])*t,o=(67108863&i)+(67108863&r);r>>=26,r+=i/67108864|0,r+=o>>>26,this.words[n]=67108863&o}return 0!==r&&(this.words[n]=r,this.length++),this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var r=function(t){for(var r=new Array(t.bitLength()),n=0;n<r.length;n++){var e=n/26|0,i=n%26;r[n]=(t.words[e]&1<<i)>>>i}return r}(t);if(0===r.length)return new o(1);for(var n=this,e=0;e<r.length&&0===r[e];e++,n=n.sqr());if(++e<r.length)for(var i=n.sqr();e<r.length;e++,i=i.sqr())0!==r[e]&&(n=n.mul(i));return n},o.prototype.iushln=function(t){e("number"==typeof t&&t>=0);var r,n=t%26,i=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var u=0;for(r=0;r<this.length;r++){var s=this.words[r]&o,a=(0|this.words[r])-s<<n;this.words[r]=a|u,u=s>>>26-n}u&&(this.words[r]=u,this.length++)}if(0!==i){for(r=this.length-1;r>=0;r--)this.words[r+i]=this.words[r];for(r=0;r<i;r++)this.words[r]=0;this.length+=i}return this.strip()},o.prototype.ishln=function(t){return e(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,r,n){var i;e("number"==typeof t&&t>=0),i=r?(r-r%26)/26:0;var o=t%26,u=Math.min((t-o)/26,this.length),s=67108863^67108863>>>o<<o,a=n;if(i-=u,i=Math.max(0,i),a){for(var f=0;f<u;f++)a.words[f]=this.words[f];a.length=u}if(0===u);else if(this.length>u)for(this.length-=u,f=0;f<this.length;f++)this.words[f]=this.words[f+u];else this.words[0]=0,this.length=1;var h=0;for(f=this.length-1;f>=0&&(0!==h||f>=i);f--){var c=0|this.words[f];this.words[f]=h<<26-o|c>>>o,h=c&s}return a&&0!==h&&(a.words[a.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(t,r,n){return e(0===this.negative),this.iushrn(t,r,n)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){e("number"==typeof t&&t>=0);var r=t%26,n=(t-r)/26,i=1<<r;return!(this.length<=n)&&!!(this.words[n]&i)},o.prototype.imaskn=function(t){e("number"==typeof t&&t>=0);var r=t%26,n=(t-r)/26;if(e(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==r&&n++,this.length=Math.min(n,this.length),0!==r){var i=67108863^67108863>>>r<<r;this.words[this.length-1]&=i}return this.strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return e("number"==typeof t),e(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var r=0;r<this.length&&this.words[r]>=67108864;r++)this.words[r]-=67108864,r===this.length-1?this.words[r+1]=1:this.words[r+1]++;return this.length=Math.max(this.length,r+1),this},o.prototype.isubn=function(t){if(e("number"==typeof t),e(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var r=0;r<this.length&&this.words[r]<0;r++)this.words[r]+=67108864,this.words[r+1]-=1;return this.strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,r,n){var i,o,u=t.length+n;this._expand(u);var s=0;for(i=0;i<t.length;i++){o=(0|this.words[i+n])+s;var a=(0|t.words[i])*r;s=((o-=67108863&a)>>26)-(a/67108864|0),this.words[i+n]=67108863&o}for(;i<this.length-n;i++)s=(o=(0|this.words[i+n])+s)>>26,this.words[i+n]=67108863&o;if(0===s)return this.strip();for(e(-1===s),s=0,i=0;i<this.length;i++)s=(o=-(0|this.words[i])+s)>>26,this.words[i]=67108863&o;return this.negative=1,this.strip()},o.prototype._wordDiv=function(t,r){var n=(this.length,t.length),e=this.clone(),i=t,u=0|i.words[i.length-1];0!==(n=26-this._countBits(u))&&(i=i.ushln(n),e.iushln(n),u=0|i.words[i.length-1]);var s,a=e.length-i.length;if("mod"!==r){(s=new o(null)).length=a+1,s.words=new Array(s.length);for(var f=0;f<s.length;f++)s.words[f]=0}var h=e.clone()._ishlnsubmul(i,1,a);0===h.negative&&(e=h,s&&(s.words[a]=1));for(var c=a-1;c>=0;c--){var l=67108864*(0|e.words[i.length+c])+(0|e.words[i.length+c-1]);for(l=Math.min(l/u|0,67108863),e._ishlnsubmul(i,l,c);0!==e.negative;)l--,e.negative=0,e._ishlnsubmul(i,1,c),e.isZero()||(e.negative^=1);s&&(s.words[c]=l)}return s&&s.strip(),e.strip(),"div"!==r&&0!==n&&e.iushrn(n),{div:s||null,mod:e}},o.prototype.divmod=function(t,r,n){return e(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(s=this.neg().divmod(t,r),"mod"!==r&&(i=s.div.neg()),"div"!==r&&(u=s.mod.neg(),n&&0!==u.negative&&u.iadd(t)),{div:i,mod:u}):0===this.negative&&0!==t.negative?(s=this.divmod(t.neg(),r),"mod"!==r&&(i=s.div.neg()),{div:i,mod:s.mod}):0!=(this.negative&t.negative)?(s=this.neg().divmod(t.neg(),r),"div"!==r&&(u=s.mod.neg(),n&&0!==u.negative&&u.isub(t)),{div:s.div,mod:u}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===r?{div:this.divn(t.words[0]),mod:null}:"mod"===r?{div:null,mod:new o(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modn(t.words[0]))}:this._wordDiv(t,r);var i,u,s},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var r=this.divmod(t);if(r.mod.isZero())return r.div;var n=0!==r.div.negative?r.mod.isub(t):r.mod,e=t.ushrn(1),i=t.andln(1),o=n.cmp(e);return o<0||1===i&&0===o?r.div:0!==r.div.negative?r.div.isubn(1):r.div.iaddn(1)},o.prototype.modn=function(t){e(t<=67108863);for(var r=(1<<26)%t,n=0,i=this.length-1;i>=0;i--)n=(r*n+(0|this.words[i]))%t;return n},o.prototype.idivn=function(t){e(t<=67108863);for(var r=0,n=this.length-1;n>=0;n--){var i=(0|this.words[n])+67108864*r;this.words[n]=i/t|0,r=i%t}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){e(0===t.negative),e(!t.isZero());var r=this,n=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var i=new o(1),u=new o(0),s=new o(0),a=new o(1),f=0;r.isEven()&&n.isEven();)r.iushrn(1),n.iushrn(1),++f;for(var h=n.clone(),c=r.clone();!r.isZero();){for(var l=0,d=1;0==(r.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(r.iushrn(l);l-- >0;)(i.isOdd()||u.isOdd())&&(i.iadd(h),u.isub(c)),i.iushrn(1),u.iushrn(1);for(var p=0,m=1;0==(n.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(s.isOdd()||a.isOdd())&&(s.iadd(h),a.isub(c)),s.iushrn(1),a.iushrn(1);r.cmp(n)>=0?(r.isub(n),i.isub(s),u.isub(a)):(n.isub(r),s.isub(i),a.isub(u))}return{a:s,b:a,gcd:n.iushln(f)}},o.prototype._invmp=function(t){e(0===t.negative),e(!t.isZero());var r=this,n=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var i,u=new o(1),s=new o(0),a=n.clone();r.cmpn(1)>0&&n.cmpn(1)>0;){for(var f=0,h=1;0==(r.words[0]&h)&&f<26;++f,h<<=1);if(f>0)for(r.iushrn(f);f-- >0;)u.isOdd()&&u.iadd(a),u.iushrn(1);for(var c=0,l=1;0==(n.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(n.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);r.cmp(n)>=0?(r.isub(n),u.isub(s)):(n.isub(r),s.isub(u))}return(i=0===r.cmpn(1)?u:s).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var r=this.clone(),n=t.clone();r.negative=0,n.negative=0;for(var e=0;r.isEven()&&n.isEven();e++)r.iushrn(1),n.iushrn(1);for(;;){for(;r.isEven();)r.iushrn(1);for(;n.isEven();)n.iushrn(1);var i=r.cmp(n);if(i<0){var o=r;r=n,n=o}else if(0===i||0===n.cmpn(1))break;r.isub(n)}return n.iushln(e)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){e("number"==typeof t);var r=t%26,n=(t-r)/26,i=1<<r;if(this.length<=n)return this._expand(n+1),this.words[n]|=i,this;for(var o=i,u=n;0!==o&&u<this.length;u++){var s=0|this.words[u];o=(s+=o)>>>26,s&=67108863,this.words[u]=s}return 0!==o&&(this.words[u]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var r,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this.strip(),this.length>1)r=1;else{n&&(t=-t),e(t<=67108863,"Number is too big");var i=0|this.words[0];r=i===t?0:i<t?-1:1}return 0!==this.negative?0|-r:r},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var r=this.ucmp(t);return 0!==this.negative?0|-r:r},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var r=0,n=this.length-1;n>=0;n--){var e=0|this.words[n],i=0|t.words[n];if(e!==i){e<i?r=-1:e>i&&(r=1);break}}return r},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new _(t)},o.prototype.toRed=function(t){return e(!this.red,"Already a number in reduction context"),e(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return e(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return e(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var y={k256:null,p224:null,p192:null,p25519:null};function g(t,r){this.name=t,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function v(){g.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function w(){g.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function b(){g.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){g.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function _(t){if("string"==typeof t){var r=o._prime(t);this.m=r.p,this.prime=r}else e(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function A(t){_.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}g.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},g.prototype.ireduce=function(t){var r,n=t;do{this.split(n,this.tmp),r=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(r>this.n);var e=r<this.n?-1:n.ucmp(this.p);return 0===e?(n.words[0]=0,n.length=1):e>0?n.isub(this.p):n.strip(),n},g.prototype.split=function(t,r){t.iushrn(this.n,0,r)},g.prototype.imulK=function(t){return t.imul(this.k)},i(v,g),v.prototype.split=fun