tonweb
Version:
TonWeb - JavaScript API for TON blockchain
2 lines • 444 kB
JavaScript
/*! For license information please see tonweb.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.tonweb=e():t.TonWeb=e()}(self,(function(){return(()=>{var t=[(t,e,r)=>{const i=r(1),n=i.Address,s=r(21),o=r(25),a=r(27).default,{Contract:h}=r(26),u=r(30).default,l=r(38).default,c=r(42).default,f=r(45).default,d=r(50).default,{BlockSubscription:p,InMemoryBlockStorage:m}=r(53),{SubscriptionContract:g}=r(56),{Payments:y,PaymentChannel:w}=r(57),v=r(60).default,b=r(115).default,E=r(116).default,{Dns:A,DnsCollection:C,DnsItem:M}=r(231).default,B="0.0.66";class F{constructor(t){this.version=B,this.utils=i,this.Address=n,this.boc=s,this.Contract=h,this.BlockSubscription=p,this.InMemoryBlockStorage=m,this.provider=t||new a,this.dns=new A(this.provider),this.wallet=new u(this.provider),this.payments=new y(this.provider),this.lockupWallet=l}async getTransactions(t,e=20,r,i,n){return this.provider.getTransactions(t.toString(),e,r,i,n)}async getBalance(t){return this.provider.getBalance(t.toString())}async sendBoc(t){return this.provider.sendBoc(i.bytesToBase64(t))}async call(t,e,r=[]){return this.provider.call(t.toString(),e,r)}}F.version=B,F.utils=i,F.Address=n,F.boc=s,F.HttpProvider=a,F.Contract=h,F.Wallets=u,F.LockupWallets=l,F.SubscriptionContract=g,F.BlockSubscription=p,F.InMemoryBlockStorage=m,F.ledger={TransportWebUSB:v,TransportWebHID:b,BluetoothTransport:E,AppTon:o},F.token={nft:f,ft:d,jetton:d},F.HighloadWallets=c,F.dns=A,F.dns.DnsCollection=C,F.dns.DnsItem=M,F.payments=y,F.payments.PaymentChannel=w,t.exports=F},(t,e,r)=>{const{BN:i,nacl:n,sha256:s,fromNano:o,toNano:a,bytesToHex:h,hexToBytes:u,stringToBytes:l,crc32c:c,crc16:f,concatBytes:d,bytesToBase64:p,base64ToBytes:m,base64toString:g,stringToBase64:y,compareBytes:w,readNBytesUIntFromArray:v,keyPairFromSeed:b,newKeyPair:E,newSeed:A}=r(2),C=r(18).default,M=r(19).default,B=r(20).default;t.exports={Address:C,AdnlAddress:M,StorageBagId:B,BN:i,nacl:n,sha256:s,fromNano:o,toNano:a,bytesToHex:h,hexToBytes:u,stringToBytes:l,crc32c:c,crc16:f,concatBytes:d,bytesToBase64:p,base64ToBytes:m,base64toString:g,stringToBase64:y,compareBytes:w,readNBytesUIntFromArray:v,parseTransferUrl:function(t){const e="ton://transfer/";if(!t.startsWith(e))throw new Error("must starts with "+e);const r=t.substring(e.length).split("?");if(r.length>2)throw new Error('multiple "?"');const n=r[0];if(!C.isValid(n))throw new Error("invalid address format "+n);const s={address:n},o=r[1];if(o&&o.length){const t=o.split("&").map((t=>t.split("=")));for(const e of t){if(2!==e.length)throw new Error("invalid url pair");const t=e[0],r=e[1];if("amount"===t){if(s.amount)throw new Error("amount already set");if(new i(r).isNeg())throw new Error("negative amount");s.amount=r}else{if("text"!==t)throw new Error("unknown url var "+t);if(s.text)throw new Error("text already set");s.text=decodeURIComponent(r)}}}return s},formatTransferUrl:function(t,e,r){let i="ton://transfer/"+t;const n=[];return e&&n.push("amount="+e),r&&n.push("text="+encodeURIComponent(r)),0===n.length?i:i+"?"+n.join("&")},keyPairFromSeed:b,newKeyPair:E,newSeed:A}},(t,e,r)=>{var i=r(9).Buffer;const n=r(3),s=r(5),o=r(7),a="undefined"!=typeof self&&self.crypto&&self.crypto.subtle;let h=null;a||(h=r(16));const u=[],l={};for(let t=0;t<=255;t++){let e=t.toString(16);e.length<2&&(e="0"+e),u.push(e),l[e]=t}const c=(()=>{const t=[],e="A".charCodeAt(0),r="a".charCodeAt(0),i="0".charCodeAt(0);for(let r=0;r<26;++r)t.push(String.fromCharCode(e+r));for(let e=0;e<26;++e)t.push(String.fromCharCode(r+e));for(let e=0;e<10;++e)t.push(String.fromCharCode(i+e));return t.push("+"),t.push("/"),t})();function f(t){return"undefined"==typeof self?i.from(t,"base64").toString("binary"):atob(t)}t.exports={BN:n,nacl:s,sha256:function(t){return a?crypto.subtle.digest("SHA-256",t):h.subtle.digest({name:"SHA-256"},t)},fromNano:function(t){if(!n.isBN(t)&&"string"!=typeof t)throw new Error("Please pass numbers as strings or BN objects to avoid precision errors.");return o.fromWei(t,"gwei")},toNano:function(t){if(!n.isBN(t)&&"string"!=typeof t)throw new Error("Please pass numbers as strings or BN objects to avoid precision errors.");return o.toWei(t,"gwei")},bytesToHex:function(t){const e=[];for(let r=0;r<t.byteLength;r++)e.push(u[t[r]]);return e.join("")},hexToBytes:function(t){const e=(t=t.toLowerCase()).length;if(e%2!=0)throw"hex string must have length a multiple of 2";const r=e/2,i=new Uint8Array(r);for(let e=0;e<r;e++){const r=2*e,n=t.substring(r,r+2);if(!l.hasOwnProperty(n))throw new Error("invalid hex character "+n);i[e]=l[n]}return i},stringToBytes:function(t,e=1){let r,i;1===e&&(r=new ArrayBuffer(t.length),i=new Uint8Array(r)),2===e&&(r=new ArrayBuffer(2*t.length),i=new Uint16Array(r)),4===e&&(r=new ArrayBuffer(4*t.length),i=new Uint32Array(r));for(let e=0,r=t.length;e<r;e++)i[e]=t.charCodeAt(e);return new Uint8Array(i.buffer)},crc32c:function(t){const e=function(t,e){const r=2197175160;t^=4294967295;for(let i=0;i<e.length;i++)t=1&(t=1&(t=1&(t=1&(t=1&(t=1&(t=1&(t=1&(t^=e[i])?t>>>1^r:t>>>1)?t>>>1^r:t>>>1)?t>>>1^r:t>>>1)?t>>>1^r:t>>>1)?t>>>1^r:t>>>1)?t>>>1^r:t>>>1)?t>>>1^r:t>>>1)?t>>>1^r:t>>>1;return 4294967295^t}(0,t),r=new ArrayBuffer(4);return new DataView(r).setUint32(0,e,!1),new Uint8Array(r).reverse()},crc16:function(t){let e=0;const r=new Uint8Array(t.length+2);r.set(t);for(let t of r){let r=128;for(;r>0;)e<<=1,t&r&&(e+=1),r>>=1,e>65535&&(e&=65535,e^=4129)}return new Uint8Array([Math.floor(e/256),e%256])},concatBytes:function(t,e){const r=new Uint8Array(t.length+e.length);return r.set(t),r.set(e,t.length),r},bytesToBase64:function(t){let e,r="";const i=t.length;for(e=2;e<i;e+=3)r+=c[t[e-2]>>2],r+=c[(3&t[e-2])<<4|t[e-1]>>4],r+=c[(15&t[e-1])<<2|t[e]>>6],r+=c[63&t[e]];return e===i+1&&(r+=c[t[e-2]>>2],r+=c[(3&t[e-2])<<4],r+="=="),e===i&&(r+=c[t[e-2]>>2],r+=c[(3&t[e-2])<<4|t[e-1]>>4],r+=c[(15&t[e-1])<<2],r+="="),r},base64ToBytes:function(t){const e=f(t),r=e.length,i=new Uint8Array(r);for(let t=0;t<r;t++)i[t]=e.charCodeAt(t);return i},base64toString:f,stringToBase64:function(t){return"undefined"==typeof self?i.from(t,"binary").toString("base64"):btoa(t)},compareBytes:function(t,e){return t.toString()===e.toString()},readNBytesUIntFromArray:function(t,e){let r=0;for(let i=0;i<t;i++)r*=256,r+=e[i];return r},keyPairFromSeed:function(t){return s.sign.keyPair.fromSeed(t)},newKeyPair:function(){return s.sign.keyPair()},newSeed:function(){return s.sign.keyPair().secretKey.slice(0,32)}}},function(t,e,r){!function(t,e){"use strict";function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var r=function(){};r.prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t}function s(t,e,r){if(s.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(r=e,e=10),this._init(t||0,e||10,r||"be"))}var o;"object"==typeof t?t.exports=s:e.BN=s,s.BN=s,s.wordSize=26;try{o=r(4).Buffer}catch(t){}function a(t,e,r){for(var n=0,s=Math.min(t.length,r),o=0,a=e;a<s;a++){var h,u=t.charCodeAt(a)-48;n<<=4,n|=h=u>=49&&u<=54?u-49+10:u>=17&&u<=22?u-17+10:u,o|=h}return i(!(240&o),"Invalid character in "+t),n}function h(t,e,r,n){for(var s=0,o=0,a=Math.min(t.length,r),h=e;h<a;h++){var u=t.charCodeAt(h)-48;s*=n,o=u>=49?u-49+10:u>=17?u-17+10:u,i(u>=0&&o<n,"Invalid character"),s+=o}return s}function u(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}s.isBN=function(t){return t instanceof s||null!==t&&"object"==typeof t&&t.constructor.wordSize===s.wordSize&&Array.isArray(t.words)},s.max=function(t,e){return t.cmp(e)>0?t:e},s.min=function(t,e){return t.cmp(e)<0?t:e},s.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var n=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&n++,16===e?this._parseHex(t,n):this._parseBase(t,e,n),"-"===t[0]&&(this.negative=1),this._strip(),"le"===r&&this._initArray(this.toArray(),e,r)},s.prototype._initNumber=function(t,e,r){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},s.prototype._initArray=function(t,e,r){if(i("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 n=0;n<this.length;n++)this.words[n]=0;var s,o,a=0;if("be"===r)for(n=t.length-1,s=0;n>=0;n-=3)o=t[n]|t[n-1]<<8|t[n-2]<<16,this.words[s]|=o<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===r)for(n=0,s=0;n<t.length;n+=3)o=t[n]|t[n+1]<<8|t[n+2]<<16,this.words[s]|=o<<a&67108863,this.words[s+1]=o>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},s.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var i,n,s=0;for(r=t.length-6,i=0;r>=e;r-=6)n=a(t,r,r+6),this.words[i]|=n<<s&67108863,this.words[i+1]|=n>>>26-s&4194303,(s+=24)>=26&&(s-=26,i++);r+6!==e&&(n=a(t,e,r+6),this.words[i]|=n<<s&67108863,this.words[i+1]|=n>>>26-s&4194303),this._strip()},s.prototype._parseBase=function(t,e,r){this.words=[0],this.length=1;for(var i=0,n=1;n<=67108863;n*=e)i++;i--,n=n/e|0;for(var s=t.length-r,o=s%i,a=Math.min(s,s-o)+r,u=0,l=r;l<a;l+=i)u=h(t,l,l+i,e),this.imuln(n),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==o){var c=1;for(u=h(t,l,t.length,e),l=0;l<o;l++)c*=e;this.imuln(c),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}},s.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},s.prototype._move=function(t){u(t,this)},s.prototype.clone=function(){var t=new s(null);return this.copy(t),t},s.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},s.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for?s.prototype[Symbol.for("nodejs.util.inspect.custom")]=l:s.prototype.inspect=l;var c=["","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"],f=[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],d=[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 p(t,e,r){r.negative=e.negative^t.negative;var i=t.length+e.length|0;r.length=i,i=i-1|0;var n=0|t.words[0],s=0|e.words[0],o=n*s,a=67108863&o,h=o/67108864|0;r.words[0]=a;for(var u=1;u<i;u++){for(var l=h>>>26,c=67108863&h,f=Math.min(u,e.length-1),d=Math.max(0,u-t.length+1);d<=f;d++){var p=u-d|0;l+=(o=(n=0|t.words[p])*(s=0|e.words[d])+c)/67108864|0,c=67108863&o}r.words[u]=0|c,h=0|l}return 0!==h?r.words[u]=0|h:r.length--,r._strip()}s.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var n=0,s=0,o=0;o<this.length;o++){var a=this.words[o],h=(16777215&(a<<n|s)).toString(16);r=0!=(s=a>>>24-n&16777215)||o!==this.length-1?c[6-h.length]+h+r:h+r,(n+=2)>=26&&(n-=26,o--)}for(0!==s&&(r=s.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var u=f[t],l=d[t];r="";var p=this.clone();for(p.negative=0;!p.isZero();){var m=p.modrn(l).toString(t);r=(p=p.idivn(l)).isZero()?m+r:c[u-m.length]+m+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}i(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},s.prototype.toJSON=function(){return this.toString(16,2)},o&&(s.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),s.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},s.prototype.toArrayLike=function(t,e,r){this._strip();var n=this.byteLength(),s=r||Math.max(1,n);i(n<=s,"byte array longer than desired length"),i(s>0,"Requested array length <= 0");var o=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,s);return this["_toArrayLike"+("le"===e?"LE":"BE")](o,n),o},s.prototype._toArrayLikeLE=function(t,e){for(var r=0,i=0,n=0,s=0;n<this.length;n++){var o=this.words[n]<<s|i;t[r++]=255&o,r<t.length&&(t[r++]=o>>8&255),r<t.length&&(t[r++]=o>>16&255),6===s?(r<t.length&&(t[r++]=o>>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r<t.length)for(t[r++]=i;r<t.length;)t[r++]=0},s.prototype._toArrayLikeBE=function(t,e){for(var r=t.length-1,i=0,n=0,s=0;n<this.length;n++){var o=this.words[n]<<s|i;t[r--]=255&o,r>=0&&(t[r--]=o>>8&255),r>=0&&(t[r--]=o>>16&255),6===s?(r>=0&&(t[r--]=o>>24&255),i=0,s=0):(i=o>>>24,s+=2)}if(r>=0)for(t[r--]=i;r>=0;)t[r--]=0},Math.clz32?s.prototype._countBits=function(t){return 32-Math.clz32(t)}:s.prototype._countBits=function(t){var e=t,r=0;return e>=4096&&(r+=13,e>>>=13),e>=64&&(r+=7,e>>>=7),e>=8&&(r+=4,e>>>=4),e>=2&&(r+=2,e>>>=2),r+e},s.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,r=0;return 0==(8191&e)&&(r+=13,e>>>=13),0==(127&e)&&(r+=7,e>>>=7),0==(15&e)&&(r+=4,e>>>=4),0==(3&e)&&(r+=2,e>>>=2),0==(1&e)&&r++,r},s.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var r=this._zeroBits(this.words[e]);if(t+=r,26!==r)break}return t},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},s.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return 0!==this.negative},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},s.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},s.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},s.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},s.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var r=0;r<e.length;r++)this.words[r]=this.words[r]&t.words[r];return this.length=e.length,this._strip()},s.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},s.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},s.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},s.prototype.iuxor=function(t){var e,r;this.length>t.length?(e=this,r=t):(e=t,r=this);for(var i=0;i<r.length;i++)this.words[i]=e.words[i]^r.words[i];if(this!==e)for(;i<e.length;i++)this.words[i]=e.words[i];return this.length=e.length,this._strip()},s.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},s.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},s.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},s.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var n=0;n<e;n++)this.words[n]=67108863&~this.words[n];return r>0&&(this.words[n]=~this.words[n]&67108863>>26-r),this._strip()},s.prototype.notn=function(t){return this.clone().inotn(t)},s.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var r=t/26|0,n=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<n:this.words[r]&~(1<<n),this._strip()},s.prototype.iadd=function(t){var e,r,i;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(r=this,i=t):(r=t,i=this);for(var n=0,s=0;s<i.length;s++)e=(0|r.words[s])+(0|i.words[s])+n,this.words[s]=67108863&e,n=e>>>26;for(;0!==n&&s<r.length;s++)e=(0|r.words[s])+n,this.words[s]=67108863&e,n=e>>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},s.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},s.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var r,i,n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,i=t):(r=t,i=this);for(var s=0,o=0;o<i.length;o++)s=(e=(0|r.words[o])-(0|i.words[o])+s)>>26,this.words[o]=67108863&e;for(;0!==s&&o<r.length;o++)s=(e=(0|r.words[o])+s)>>26,this.words[o]=67108863&e;if(0===s&&o<r.length&&r!==this)for(;o<r.length;o++)this.words[o]=r.words[o];return this.length=Math.max(this.length,o),r!==this&&(this.negative=1),this._strip()},s.prototype.sub=function(t){return this.clone().isub(t)};var m=function(t,e,r){var i,n,s,o=t.words,a=e.words,h=r.words,u=0,l=0|o[0],c=8191&l,f=l>>>13,d=0|o[1],p=8191&d,m=d>>>13,g=0|o[2],y=8191&g,w=g>>>13,v=0|o[3],b=8191&v,E=v>>>13,A=0|o[4],C=8191&A,M=A>>>13,B=0|o[5],F=8191&B,S=B>>>13,_=0|o[6],D=8191&_,I=_>>>13,x=0|o[7],T=8191&x,N=x>>>13,U=0|o[8],R=8191&U,O=U>>>13,k=0|o[9],L=8191&k,P=k>>>13,j=0|a[0],$=8191&j,q=j>>>13,K=0|a[1],H=8191&K,G=K>>>13,V=0|a[2],W=8191&V,z=V>>>13,Z=0|a[3],Y=8191&Z,X=Z>>>13,Q=0|a[4],J=8191&Q,tt=Q>>>13,et=0|a[5],rt=8191&et,it=et>>>13,nt=0|a[6],st=8191&nt,ot=nt>>>13,at=0|a[7],ht=8191&at,ut=at>>>13,lt=0|a[8],ct=8191<,ft=lt>>>13,dt=0|a[9],pt=8191&dt,mt=dt>>>13;r.negative=t.negative^e.negative,r.length=19;var gt=(u+(i=Math.imul(c,$))|0)+((8191&(n=(n=Math.imul(c,q))+Math.imul(f,$)|0))<<13)|0;u=((s=Math.imul(f,q))+(n>>>13)|0)+(gt>>>26)|0,gt&=67108863,i=Math.imul(p,$),n=(n=Math.imul(p,q))+Math.imul(m,$)|0,s=Math.imul(m,q);var yt=(u+(i=i+Math.imul(c,H)|0)|0)+((8191&(n=(n=n+Math.imul(c,G)|0)+Math.imul(f,H)|0))<<13)|0;u=((s=s+Math.imul(f,G)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,i=Math.imul(y,$),n=(n=Math.imul(y,q))+Math.imul(w,$)|0,s=Math.imul(w,q),i=i+Math.imul(p,H)|0,n=(n=n+Math.imul(p,G)|0)+Math.imul(m,H)|0,s=s+Math.imul(m,G)|0;var wt=(u+(i=i+Math.imul(c,W)|0)|0)+((8191&(n=(n=n+Math.imul(c,z)|0)+Math.imul(f,W)|0))<<13)|0;u=((s=s+Math.imul(f,z)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,i=Math.imul(b,$),n=(n=Math.imul(b,q))+Math.imul(E,$)|0,s=Math.imul(E,q),i=i+Math.imul(y,H)|0,n=(n=n+Math.imul(y,G)|0)+Math.imul(w,H)|0,s=s+Math.imul(w,G)|0,i=i+Math.imul(p,W)|0,n=(n=n+Math.imul(p,z)|0)+Math.imul(m,W)|0,s=s+Math.imul(m,z)|0;var vt=(u+(i=i+Math.imul(c,Y)|0)|0)+((8191&(n=(n=n+Math.imul(c,X)|0)+Math.imul(f,Y)|0))<<13)|0;u=((s=s+Math.imul(f,X)|0)+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,i=Math.imul(C,$),n=(n=Math.imul(C,q))+Math.imul(M,$)|0,s=Math.imul(M,q),i=i+Math.imul(b,H)|0,n=(n=n+Math.imul(b,G)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,G)|0,i=i+Math.imul(y,W)|0,n=(n=n+Math.imul(y,z)|0)+Math.imul(w,W)|0,s=s+Math.imul(w,z)|0,i=i+Math.imul(p,Y)|0,n=(n=n+Math.imul(p,X)|0)+Math.imul(m,Y)|0,s=s+Math.imul(m,X)|0;var bt=(u+(i=i+Math.imul(c,J)|0)|0)+((8191&(n=(n=n+Math.imul(c,tt)|0)+Math.imul(f,J)|0))<<13)|0;u=((s=s+Math.imul(f,tt)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,i=Math.imul(F,$),n=(n=Math.imul(F,q))+Math.imul(S,$)|0,s=Math.imul(S,q),i=i+Math.imul(C,H)|0,n=(n=n+Math.imul(C,G)|0)+Math.imul(M,H)|0,s=s+Math.imul(M,G)|0,i=i+Math.imul(b,W)|0,n=(n=n+Math.imul(b,z)|0)+Math.imul(E,W)|0,s=s+Math.imul(E,z)|0,i=i+Math.imul(y,Y)|0,n=(n=n+Math.imul(y,X)|0)+Math.imul(w,Y)|0,s=s+Math.imul(w,X)|0,i=i+Math.imul(p,J)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(m,J)|0,s=s+Math.imul(m,tt)|0;var Et=(u+(i=i+Math.imul(c,rt)|0)|0)+((8191&(n=(n=n+Math.imul(c,it)|0)+Math.imul(f,rt)|0))<<13)|0;u=((s=s+Math.imul(f,it)|0)+(n>>>13)|0)+(Et>>>26)|0,Et&=67108863,i=Math.imul(D,$),n=(n=Math.imul(D,q))+Math.imul(I,$)|0,s=Math.imul(I,q),i=i+Math.imul(F,H)|0,n=(n=n+Math.imul(F,G)|0)+Math.imul(S,H)|0,s=s+Math.imul(S,G)|0,i=i+Math.imul(C,W)|0,n=(n=n+Math.imul(C,z)|0)+Math.imul(M,W)|0,s=s+Math.imul(M,z)|0,i=i+Math.imul(b,Y)|0,n=(n=n+Math.imul(b,X)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,X)|0,i=i+Math.imul(y,J)|0,n=(n=n+Math.imul(y,tt)|0)+Math.imul(w,J)|0,s=s+Math.imul(w,tt)|0,i=i+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,it)|0)+Math.imul(m,rt)|0,s=s+Math.imul(m,it)|0;var At=(u+(i=i+Math.imul(c,st)|0)|0)+((8191&(n=(n=n+Math.imul(c,ot)|0)+Math.imul(f,st)|0))<<13)|0;u=((s=s+Math.imul(f,ot)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,i=Math.imul(T,$),n=(n=Math.imul(T,q))+Math.imul(N,$)|0,s=Math.imul(N,q),i=i+Math.imul(D,H)|0,n=(n=n+Math.imul(D,G)|0)+Math.imul(I,H)|0,s=s+Math.imul(I,G)|0,i=i+Math.imul(F,W)|0,n=(n=n+Math.imul(F,z)|0)+Math.imul(S,W)|0,s=s+Math.imul(S,z)|0,i=i+Math.imul(C,Y)|0,n=(n=n+Math.imul(C,X)|0)+Math.imul(M,Y)|0,s=s+Math.imul(M,X)|0,i=i+Math.imul(b,J)|0,n=(n=n+Math.imul(b,tt)|0)+Math.imul(E,J)|0,s=s+Math.imul(E,tt)|0,i=i+Math.imul(y,rt)|0,n=(n=n+Math.imul(y,it)|0)+Math.imul(w,rt)|0,s=s+Math.imul(w,it)|0,i=i+Math.imul(p,st)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(m,st)|0,s=s+Math.imul(m,ot)|0;var Ct=(u+(i=i+Math.imul(c,ht)|0)|0)+((8191&(n=(n=n+Math.imul(c,ut)|0)+Math.imul(f,ht)|0))<<13)|0;u=((s=s+Math.imul(f,ut)|0)+(n>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,i=Math.imul(R,$),n=(n=Math.imul(R,q))+Math.imul(O,$)|0,s=Math.imul(O,q),i=i+Math.imul(T,H)|0,n=(n=n+Math.imul(T,G)|0)+Math.imul(N,H)|0,s=s+Math.imul(N,G)|0,i=i+Math.imul(D,W)|0,n=(n=n+Math.imul(D,z)|0)+Math.imul(I,W)|0,s=s+Math.imul(I,z)|0,i=i+Math.imul(F,Y)|0,n=(n=n+Math.imul(F,X)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,X)|0,i=i+Math.imul(C,J)|0,n=(n=n+Math.imul(C,tt)|0)+Math.imul(M,J)|0,s=s+Math.imul(M,tt)|0,i=i+Math.imul(b,rt)|0,n=(n=n+Math.imul(b,it)|0)+Math.imul(E,rt)|0,s=s+Math.imul(E,it)|0,i=i+Math.imul(y,st)|0,n=(n=n+Math.imul(y,ot)|0)+Math.imul(w,st)|0,s=s+Math.imul(w,ot)|0,i=i+Math.imul(p,ht)|0,n=(n=n+Math.imul(p,ut)|0)+Math.imul(m,ht)|0,s=s+Math.imul(m,ut)|0;var Mt=(u+(i=i+Math.imul(c,ct)|0)|0)+((8191&(n=(n=n+Math.imul(c,ft)|0)+Math.imul(f,ct)|0))<<13)|0;u=((s=s+Math.imul(f,ft)|0)+(n>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,i=Math.imul(L,$),n=(n=Math.imul(L,q))+Math.imul(P,$)|0,s=Math.imul(P,q),i=i+Math.imul(R,H)|0,n=(n=n+Math.imul(R,G)|0)+Math.imul(O,H)|0,s=s+Math.imul(O,G)|0,i=i+Math.imul(T,W)|0,n=(n=n+Math.imul(T,z)|0)+Math.imul(N,W)|0,s=s+Math.imul(N,z)|0,i=i+Math.imul(D,Y)|0,n=(n=n+Math.imul(D,X)|0)+Math.imul(I,Y)|0,s=s+Math.imul(I,X)|0,i=i+Math.imul(F,J)|0,n=(n=n+Math.imul(F,tt)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,tt)|0,i=i+Math.imul(C,rt)|0,n=(n=n+Math.imul(C,it)|0)+Math.imul(M,rt)|0,s=s+Math.imul(M,it)|0,i=i+Math.imul(b,st)|0,n=(n=n+Math.imul(b,ot)|0)+Math.imul(E,st)|0,s=s+Math.imul(E,ot)|0,i=i+Math.imul(y,ht)|0,n=(n=n+Math.imul(y,ut)|0)+Math.imul(w,ht)|0,s=s+Math.imul(w,ut)|0,i=i+Math.imul(p,ct)|0,n=(n=n+Math.imul(p,ft)|0)+Math.imul(m,ct)|0,s=s+Math.imul(m,ft)|0;var Bt=(u+(i=i+Math.imul(c,pt)|0)|0)+((8191&(n=(n=n+Math.imul(c,mt)|0)+Math.imul(f,pt)|0))<<13)|0;u=((s=s+Math.imul(f,mt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,i=Math.imul(L,H),n=(n=Math.imul(L,G))+Math.imul(P,H)|0,s=Math.imul(P,G),i=i+Math.imul(R,W)|0,n=(n=n+Math.imul(R,z)|0)+Math.imul(O,W)|0,s=s+Math.imul(O,z)|0,i=i+Math.imul(T,Y)|0,n=(n=n+Math.imul(T,X)|0)+Math.imul(N,Y)|0,s=s+Math.imul(N,X)|0,i=i+Math.imul(D,J)|0,n=(n=n+Math.imul(D,tt)|0)+Math.imul(I,J)|0,s=s+Math.imul(I,tt)|0,i=i+Math.imul(F,rt)|0,n=(n=n+Math.imul(F,it)|0)+Math.imul(S,rt)|0,s=s+Math.imul(S,it)|0,i=i+Math.imul(C,st)|0,n=(n=n+Math.imul(C,ot)|0)+Math.imul(M,st)|0,s=s+Math.imul(M,ot)|0,i=i+Math.imul(b,ht)|0,n=(n=n+Math.imul(b,ut)|0)+Math.imul(E,ht)|0,s=s+Math.imul(E,ut)|0,i=i+Math.imul(y,ct)|0,n=(n=n+Math.imul(y,ft)|0)+Math.imul(w,ct)|0,s=s+Math.imul(w,ft)|0;var Ft=(u+(i=i+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,mt)|0)+Math.imul(m,pt)|0))<<13)|0;u=((s=s+Math.imul(m,mt)|0)+(n>>>13)|0)+(Ft>>>26)|0,Ft&=67108863,i=Math.imul(L,W),n=(n=Math.imul(L,z))+Math.imul(P,W)|0,s=Math.imul(P,z),i=i+Math.imul(R,Y)|0,n=(n=n+Math.imul(R,X)|0)+Math.imul(O,Y)|0,s=s+Math.imul(O,X)|0,i=i+Math.imul(T,J)|0,n=(n=n+Math.imul(T,tt)|0)+Math.imul(N,J)|0,s=s+Math.imul(N,tt)|0,i=i+Math.imul(D,rt)|0,n=(n=n+Math.imul(D,it)|0)+Math.imul(I,rt)|0,s=s+Math.imul(I,it)|0,i=i+Math.imul(F,st)|0,n=(n=n+Math.imul(F,ot)|0)+Math.imul(S,st)|0,s=s+Math.imul(S,ot)|0,i=i+Math.imul(C,ht)|0,n=(n=n+Math.imul(C,ut)|0)+Math.imul(M,ht)|0,s=s+Math.imul(M,ut)|0,i=i+Math.imul(b,ct)|0,n=(n=n+Math.imul(b,ft)|0)+Math.imul(E,ct)|0,s=s+Math.imul(E,ft)|0;var St=(u+(i=i+Math.imul(y,pt)|0)|0)+((8191&(n=(n=n+Math.imul(y,mt)|0)+Math.imul(w,pt)|0))<<13)|0;u=((s=s+Math.imul(w,mt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,i=Math.imul(L,Y),n=(n=Math.imul(L,X))+Math.imul(P,Y)|0,s=Math.imul(P,X),i=i+Math.imul(R,J)|0,n=(n=n+Math.imul(R,tt)|0)+Math.imul(O,J)|0,s=s+Math.imul(O,tt)|0,i=i+Math.imul(T,rt)|0,n=(n=n+Math.imul(T,it)|0)+Math.imul(N,rt)|0,s=s+Math.imul(N,it)|0,i=i+Math.imul(D,st)|0,n=(n=n+Math.imul(D,ot)|0)+Math.imul(I,st)|0,s=s+Math.imul(I,ot)|0,i=i+Math.imul(F,ht)|0,n=(n=n+Math.imul(F,ut)|0)+Math.imul(S,ht)|0,s=s+Math.imul(S,ut)|0,i=i+Math.imul(C,ct)|0,n=(n=n+Math.imul(C,ft)|0)+Math.imul(M,ct)|0,s=s+Math.imul(M,ft)|0;var _t=(u+(i=i+Math.imul(b,pt)|0)|0)+((8191&(n=(n=n+Math.imul(b,mt)|0)+Math.imul(E,pt)|0))<<13)|0;u=((s=s+Math.imul(E,mt)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,i=Math.imul(L,J),n=(n=Math.imul(L,tt))+Math.imul(P,J)|0,s=Math.imul(P,tt),i=i+Math.imul(R,rt)|0,n=(n=n+Math.imul(R,it)|0)+Math.imul(O,rt)|0,s=s+Math.imul(O,it)|0,i=i+Math.imul(T,st)|0,n=(n=n+Math.imul(T,ot)|0)+Math.imul(N,st)|0,s=s+Math.imul(N,ot)|0,i=i+Math.imul(D,ht)|0,n=(n=n+Math.imul(D,ut)|0)+Math.imul(I,ht)|0,s=s+Math.imul(I,ut)|0,i=i+Math.imul(F,ct)|0,n=(n=n+Math.imul(F,ft)|0)+Math.imul(S,ct)|0,s=s+Math.imul(S,ft)|0;var Dt=(u+(i=i+Math.imul(C,pt)|0)|0)+((8191&(n=(n=n+Math.imul(C,mt)|0)+Math.imul(M,pt)|0))<<13)|0;u=((s=s+Math.imul(M,mt)|0)+(n>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,i=Math.imul(L,rt),n=(n=Math.imul(L,it))+Math.imul(P,rt)|0,s=Math.imul(P,it),i=i+Math.imul(R,st)|0,n=(n=n+Math.imul(R,ot)|0)+Math.imul(O,st)|0,s=s+Math.imul(O,ot)|0,i=i+Math.imul(T,ht)|0,n=(n=n+Math.imul(T,ut)|0)+Math.imul(N,ht)|0,s=s+Math.imul(N,ut)|0,i=i+Math.imul(D,ct)|0,n=(n=n+Math.imul(D,ft)|0)+Math.imul(I,ct)|0,s=s+Math.imul(I,ft)|0;var It=(u+(i=i+Math.imul(F,pt)|0)|0)+((8191&(n=(n=n+Math.imul(F,mt)|0)+Math.imul(S,pt)|0))<<13)|0;u=((s=s+Math.imul(S,mt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863,i=Math.imul(L,st),n=(n=Math.imul(L,ot))+Math.imul(P,st)|0,s=Math.imul(P,ot),i=i+Math.imul(R,ht)|0,n=(n=n+Math.imul(R,ut)|0)+Math.imul(O,ht)|0,s=s+Math.imul(O,ut)|0,i=i+Math.imul(T,ct)|0,n=(n=n+Math.imul(T,ft)|0)+Math.imul(N,ct)|0,s=s+Math.imul(N,ft)|0;var xt=(u+(i=i+Math.imul(D,pt)|0)|0)+((8191&(n=(n=n+Math.imul(D,mt)|0)+Math.imul(I,pt)|0))<<13)|0;u=((s=s+Math.imul(I,mt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,i=Math.imul(L,ht),n=(n=Math.imul(L,ut))+Math.imul(P,ht)|0,s=Math.imul(P,ut),i=i+Math.imul(R,ct)|0,n=(n=n+Math.imul(R,ft)|0)+Math.imul(O,ct)|0,s=s+Math.imul(O,ft)|0;var Tt=(u+(i=i+Math.imul(T,pt)|0)|0)+((8191&(n=(n=n+Math.imul(T,mt)|0)+Math.imul(N,pt)|0))<<13)|0;u=((s=s+Math.imul(N,mt)|0)+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,i=Math.imul(L,ct),n=(n=Math.imul(L,ft))+Math.imul(P,ct)|0,s=Math.imul(P,ft);var Nt=(u+(i=i+Math.imul(R,pt)|0)|0)+((8191&(n=(n=n+Math.imul(R,mt)|0)+Math.imul(O,pt)|0))<<13)|0;u=((s=s+Math.imul(O,mt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863;var Ut=(u+(i=Math.imul(L,pt))|0)+((8191&(n=(n=Math.imul(L,mt))+Math.imul(P,pt)|0))<<13)|0;return u=((s=Math.imul(P,mt))+(n>>>13)|0)+(Ut>>>26)|0,Ut&=67108863,h[0]=gt,h[1]=yt,h[2]=wt,h[3]=vt,h[4]=bt,h[5]=Et,h[6]=At,h[7]=Ct,h[8]=Mt,h[9]=Bt,h[10]=Ft,h[11]=St,h[12]=_t,h[13]=Dt,h[14]=It,h[15]=xt,h[16]=Tt,h[17]=Nt,h[18]=Ut,0!==u&&(h[19]=u,r.length++),r};function g(t,e,r){r.negative=e.negative^t.negative,r.length=t.length+e.length;for(var i=0,n=0,s=0;s<r.length-1;s++){var o=n;n=0;for(var a=67108863&i,h=Math.min(s,e.length-1),u=Math.max(0,s-t.length+1);u<=h;u++){var l=s-u,c=(0|t.words[l])*(0|e.words[u]),f=67108863&c;a=67108863&(f=f+a|0),n+=(o=(o=o+(c/67108864|0)|0)+(f>>>26)|0)>>>26,o&=67108863}r.words[s]=a,i=o,o=n}return 0!==i?r.words[s]=i:r.length--,r._strip()}function y(t,e,r){return g(t,e,r)}function w(t,e){this.x=t,this.y=e}Math.imul||(m=p),s.prototype.mulTo=function(t,e){var r=this.length+t.length;return 10===this.length&&10===t.length?m(this,t,e):r<63?p(this,t,e):r<1024?g(this,t,e):y(this,t,e)},w.prototype.makeRBT=function(t){for(var e=new Array(t),r=s.prototype._countBits(t)-1,i=0;i<t;i++)e[i]=this.revBin(i,r,t);return e},w.prototype.revBin=function(t,e,r){if(0===t||t===r-1)return t;for(var i=0,n=0;n<e;n++)i|=(1&t)<<e-n-1,t>>=1;return i},w.prototype.permute=function(t,e,r,i,n,s){for(var o=0;o<s;o++)i[o]=e[t[o]],n[o]=r[t[o]]},w.prototype.transform=function(t,e,r,i,n,s){this.permute(s,t,e,r,i,n);for(var o=1;o<n;o<<=1)for(var a=o<<1,h=Math.cos(2*Math.PI/a),u=Math.sin(2*Math.PI/a),l=0;l<n;l+=a)for(var c=h,f=u,d=0;d<o;d++){var p=r[l+d],m=i[l+d],g=r[l+d+o],y=i[l+d+o],w=c*g-f*y;y=c*y+f*g,g=w,r[l+d]=p+g,i[l+d]=m+y,r[l+d+o]=p-g,i[l+d+o]=m-y,d!==a&&(w=h*c-u*f,f=h*f+u*c,c=w)}},w.prototype.guessLen13b=function(t,e){var r=1|Math.max(e,t),i=1&r,n=0;for(r=r/2|0;r;r>>>=1)n++;return 1<<n+1+i},w.prototype.conjugate=function(t,e,r){if(!(r<=1))for(var i=0;i<r/2;i++){var n=t[i];t[i]=t[r-i-1],t[r-i-1]=n,n=e[i],e[i]=-e[r-i-1],e[r-i-1]=-n}},w.prototype.normalize13b=function(t,e){for(var r=0,i=0;i<e/2;i++){var n=8192*Math.round(t[2*i+1]/e)+Math.round(t[2*i]/e)+r;t[i]=67108863&n,r=n<67108864?0:n/67108864|0}return t},w.prototype.convert13b=function(t,e,r,n){for(var s=0,o=0;o<e;o++)s+=0|t[o],r[2*o]=8191&s,s>>>=13,r[2*o+1]=8191&s,s>>>=13;for(o=2*e;o<n;++o)r[o]=0;i(0===s),i(0==(-8192&s))},w.prototype.stub=function(t){for(var e=new Array(t),r=0;r<t;r++)e[r]=0;return e},w.prototype.mulp=function(t,e,r){var i=2*this.guessLen13b(t.length,e.length),n=this.makeRBT(i),s=this.stub(i),o=new Array(i),a=new Array(i),h=new Array(i),u=new Array(i),l=new Array(i),c=new Array(i),f=r.words;f.length=i,this.convert13b(t.words,t.length,o,i),this.convert13b(e.words,e.length,u,i),this.transform(o,s,a,h,i,n),this.transform(u,s,l,c,i,n);for(var d=0;d<i;d++){var p=a[d]*l[d]-h[d]*c[d];h[d]=a[d]*c[d]+h[d]*l[d],a[d]=p}return this.conjugate(a,h,i),this.transform(a,h,f,s,i,n),this.conjugate(f,s,i),this.normalize13b(f,i),r.negative=t.negative^e.negative,r.length=t.length+e.length,r._strip()},s.prototype.mul=function(t){var e=new s(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},s.prototype.mulf=function(t){var e=new s(null);return e.words=new Array(this.length+t.length),y(this,t,e)},s.prototype.imul=function(t){return this.clone().mulTo(t,this)},s.prototype.imuln=function(t){var e=t<0;e&&(t=-t),i("number"==typeof t),i(t<67108864);for(var r=0,n=0;n<this.length;n++){var s=(0|this.words[n])*t,o=(67108863&s)+(67108863&r);r>>=26,r+=s/67108864|0,r+=o>>>26,this.words[n]=67108863&o}return 0!==r&&(this.words[n]=r,this.length++),e?this.ineg():this},s.prototype.muln=function(t){return this.clone().imuln(t)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),r=0;r<e.length;r++){var i=r/26|0,n=r%26;e[r]=t.words[i]>>>n&1}return e}(t);if(0===e.length)return new s(1);for(var r=this,i=0;i<e.length&&0===e[i];i++,r=r.sqr());if(++i<e.length)for(var n=r.sqr();i<e.length;i++,n=n.sqr())0!==e[i]&&(r=r.mul(n));return r},s.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,r=t%26,n=(t-r)/26,s=67108863>>>26-r<<26-r;if(0!==r){var o=0;for(e=0;e<this.length;e++){var a=this.words[e]&s,h=(0|this.words[e])-a<<r;this.words[e]=h|o,o=a>>>26-r}o&&(this.words[e]=o,this.length++)}if(0!==n){for(e=this.length-1;e>=0;e--)this.words[e+n]=this.words[e];for(e=0;e<n;e++)this.words[e]=0;this.length+=n}return this._strip()},s.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},s.prototype.iushrn=function(t,e,r){var n;i("number"==typeof t&&t>=0),n=e?(e-e%26)/26:0;var s=t%26,o=Math.min((t-s)/26,this.length),a=67108863^67108863>>>s<<s,h=r;if(n-=o,n=Math.max(0,n),h){for(var u=0;u<o;u++)h.words[u]=this.words[u];h.length=o}if(0===o);else if(this.length>o)for(this.length-=o,u=0;u<this.length;u++)this.words[u]=this.words[u+o];else this.words[0]=0,this.length=1;var l=0;for(u=this.length-1;u>=0&&(0!==l||u>=n);u--){var c=0|this.words[u];this.words[u]=l<<26-s|c>>>s,l=c&a}return h&&0!==l&&(h.words[h.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},s.prototype.ishrn=function(t,e,r){return i(0===this.negative),this.iushrn(t,e,r)},s.prototype.shln=function(t){return this.clone().ishln(t)},s.prototype.ushln=function(t){return this.clone().iushln(t)},s.prototype.shrn=function(t){return this.clone().ishrn(t)},s.prototype.ushrn=function(t){return this.clone().iushrn(t)},s.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,n=1<<e;return!(this.length<=r||!(this.words[r]&n))},s.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var n=67108863^67108863>>>e<<e;this.words[this.length-1]&=n}return this._strip()},s.prototype.maskn=function(t){return this.clone().imaskn(t)},s.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},s.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},s.prototype.isubn=function(t){if(i("number"==typeof t),i(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 e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},s.prototype.addn=function(t){return this.clone().iaddn(t)},s.prototype.subn=function(t){return this.clone().isubn(t)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(t,e,r){var n,s,o=t.length+r;this._expand(o);var a=0;for(n=0;n<t.length;n++){s=(0|this.words[n+r])+a;var h=(0|t.words[n])*e;a=((s-=67108863&h)>>26)-(h/67108864|0),this.words[n+r]=67108863&s}for(;n<this.length-r;n++)a=(s=(0|this.words[n+r])+a)>>26,this.words[n+r]=67108863&s;if(0===a)return this._strip();for(i(-1===a),a=0,n=0;n<this.length;n++)a=(s=-(0|this.words[n])+a)>>26,this.words[n]=67108863&s;return this.negative=1,this._strip()},s.prototype._wordDiv=function(t,e){var r=(this.length,t.length),i=this.clone(),n=t,o=0|n.words[n.length-1];0!=(r=26-this._countBits(o))&&(n=n.ushln(r),i.iushln(r),o=0|n.words[n.length-1]);var a,h=i.length-n.length;if("mod"!==e){(a=new s(null)).length=h+1,a.words=new Array(a.length);for(var u=0;u<a.length;u++)a.words[u]=0}var l=i.clone()._ishlnsubmul(n,1,h);0===l.negative&&(i=l,a&&(a.words[h]=1));for(var c=h-1;c>=0;c--){var f=67108864*(0|i.words[n.length+c])+(0|i.words[n.length+c-1]);for(f=Math.min(f/o|0,67108863),i._ishlnsubmul(n,f,c);0!==i.negative;)f--,i.negative=0,i._ishlnsubmul(n,1,c),i.isZero()||(i.negative^=1);a&&(a.words[c]=f)}return a&&a._strip(),i._strip(),"div"!==e&&0!==r&&i.iushrn(r),{div:a||null,mod:i}},s.prototype.divmod=function(t,e,r){return i(!t.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(n=a.div.neg()),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.iadd(t)),{div:n,mod:o}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(n=a.div.neg()),{div:n,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(o=a.mod.neg(),r&&0!==o.negative&&o.isub(t)),{div:a.div,mod:o}):t.length>this.length||this.cmp(t)<0?{div:new s(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new s(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new s(this.modrn(t.words[0]))}:this._wordDiv(t,e);var n,o,a},s.prototype.div=function(t){return this.divmod(t,"div",!1).div},s.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},s.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},s.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var r=0!==e.div.negative?e.mod.isub(t):e.mod,i=t.ushrn(1),n=t.andln(1),s=r.cmp(i);return s<0||1===n&&0===s?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},s.prototype.modrn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=(1<<26)%t,n=0,s=this.length-1;s>=0;s--)n=(r*n+(0|this.words[s]))%t;return e?-n:n},s.prototype.modn=function(t){return this.modrn(t)},s.prototype.idivn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var r=0,n=this.length-1;n>=0;n--){var s=(0|this.words[n])+67108864*r;this.words[n]=s/t|0,r=s%t}return this._strip(),e?this.ineg():this},s.prototype.divn=function(t){return this.clone().idivn(t)},s.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n=new s(1),o=new s(0),a=new s(0),h=new s(1),u=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++u;for(var l=r.clone(),c=e.clone();!e.isZero();){for(var f=0,d=1;0==(e.words[0]&d)&&f<26;++f,d<<=1);if(f>0)for(e.iushrn(f);f-- >0;)(n.isOdd()||o.isOdd())&&(n.iadd(l),o.isub(c)),n.iushrn(1),o.iushrn(1);for(var p=0,m=1;0==(r.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||h.isOdd())&&(a.iadd(l),h.isub(c)),a.iushrn(1),h.iushrn(1);e.cmp(r)>=0?(e.isub(r),n.isub(a),o.isub(h)):(r.isub(e),a.isub(n),h.isub(o))}return{a,b:h,gcd:r.iushln(u)}},s.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var n,o=new s(1),a=new s(0),h=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var u=0,l=1;0==(e.words[0]&l)&&u<26;++u,l<<=1);if(u>0)for(e.iushrn(u);u-- >0;)o.isOdd()&&o.iadd(h),o.iushrn(1);for(var c=0,f=1;0==(r.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(r.iushrn(c);c-- >0;)a.isOdd()&&a.iadd(h),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),o.isub(a)):(r.isub(e),a.isub(o))}return(n=0===e.cmpn(1)?o:a).cmpn(0)<0&&n.iadd(t),n},s.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),r=t.clone();e.negative=0,r.negative=0;for(var i=0;e.isEven()&&r.isEven();i++)e.iushrn(1),r.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=e.cmp(r);if(n<0){var s=e;e=r,r=s}else if(0===n||0===r.cmpn(1))break;e.isub(r)}return r.iushln(i)},s.prototype.invm=function(t){return this.egcd(t).a.umod(t)},s.prototype.isEven=function(){return 0==(1&this.words[0])},s.prototype.isOdd=function(){return 1==(1&this.words[0])},s.prototype.andln=function(t){return this.words[0]&t},s.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,r=(t-e)/26,n=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=n,this;for(var s=n,o=r;0!==s&&o<this.length;o++){var a=0|this.words[o];s=(a+=s)>>>26,a&=67108863,this.words[o]=a}return 0!==s&&(this.words[o]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),i(t<=67108863,"Number is too big");var n=0|this.words[0];e=n===t?0:n<t?-1:1}return 0!==this.negative?0|-e:e},s.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},s.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,r=this.length-1;r>=0;r--){var i=0|this.words[r],n=0|t.words[r];if(i!==n){i<n?e=-1:i>n&&(e=1);break}}return e},s.prototype.gtn=function(t){return 1===this.cmpn(t)},s.prototype.gt=function(t){return 1===this.cmp(t)},s.prototype.gten=function(t){return this.cmpn(t)>=0},s.prototype.gte=function(t){return this.cmp(t)>=0},s.prototype.ltn=function(t){return-1===this.cmpn(t)},s.prototype.lt=function(t){return-1===this.cmp(t)},s.prototype.lten=function(t){return this.cmpn(t)<=0},s.prototype.lte=function(t){return this.cmp(t)<=0},s.prototype.eqn=function(t){return 0===this.cmpn(t)},s.prototype.eq=function(t){return 0===this.cmp(t)},s.red=function(t){return new B(t)},s.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},s.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(t){return this.red=t,this},s.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},s.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},s.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},s.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},s.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},s.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},s.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},s.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},s.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var v={k256:null,p224:null,p192:null,p25519:null};function b(t,e){this.name=t,this.p=new s(e,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function E(){b.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function A(){b.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function C(){b.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){b.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function B(t){if("string"==typeof t){var e=s._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function F(t){B.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(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)}b.prototype._tmp=function(){var t=new s(null);return t.words=new Array(Math.ceil(this.n/13)),t},b.prototype.ireduce=function(t){var e,r=t;do{this.split(r,this.tmp),e=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(e>this.n);var i=e<this.n?-1:r.ucmp(this.p);return 0===i?(r.words[0]=0,r.length=1):i>0?r.isub(this.p):r._strip(),r},b.prototype.split=function(t,e){t.iushrn(this.n,0,e)},b.prototype.imulK=function(t){return t.imul(this.k)},n(E,b),E.prototype.split=function(t,e){for(var r=4194303,i=Math.min(t.length,9),n=0;n<i;n++)e.words[n]=t.words[n];if(e.length=i,t.length<=9)return t.words[0]=0,void(t.length=1);var s=t.words[9];for(e.words[e.length++]=s&r,n=10;n<t.length;n++){var o=0|t.words[n];t.words[n-10]=(o&r)<<4|s>>>22,s=o}s>>>=22,t.words[n-10]=s,0===s&&t.length>10?t.length-=10:t.length-=9},E.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,r=0;r<t.length;r++){var i=0|t.words[r];e+=977*i,t.words[r]=67108863&e,e=64*i+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(A,b),n(C,b),n(M,b),M.prototype.imulK=function(t){for(var e=0,r=0;r<t.length;r++){var i=19*(0|t.words[r])+e,n=67108863&i;i>>>=26,t.words[r]=n,e=i}return 0!==e&&(t.words[t.length++]=e),t},s._prime=function(t){if(v[t])return v[t];var e;if("k256"===t)e=new E;else if("p224"===t)e=new A;else if("p192"===t)e=new C;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new M}return v[t]=e,e},B.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},B.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},B.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(u(t,t.umod(this.m)._forceRed(this)),t)},B.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},B.prototype.add=function(t,e){this._verify2(t,e);var r=t.add(e);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},B.prototype.iadd=function(t,e){this._verify2(t,e);var r=t.iadd(e);return r.cmp(this.m)>=0&&r.isub(this.m),r},B.prototype.sub=function(t,e){this._verify2(t,e);var r=t.sub(e);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},B.prototype.isub=function(t,e){this._verify2(t,e);var r=t.isub(e);return r.cmpn(0)<0&&r.iadd(this.m),r},B.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},B.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},B.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},B.prototype.isqr=function(t){return this.imul(t,t.clone())},B.prototype.sqr=function(t){return this.mul(t,t)},B.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var r=this.m.add(new s(1)).iushrn(2);return this.pow(t,r)}for(var n=this.m.subn(1),o=0;!n.isZero()&&0===n.andln(1);)o++,n.iushrn(1);i(!n.isZero());var a=new s(1).toRed(this),h=a.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new s(2*l*l).toRed(this);0!==this.pow(l,u).cmp(h);)l.redIAdd(h);for(var c=this.pow(l,n),f=this.pow(t,n.addn(1).iushrn(1)),d=this.pow(t,n),p=o;0!==d.cmp(a);){for(var m=d,g=0;0!==m.cmp(a);g++)m=m.redSqr();i(g<p);var y=this.pow(c,new s(1).iushln(p-g-1));f=f.redMul(y),c=y.redSqr(),d=d.redMul(c),p=g}return f},B.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},B.prototype.pow=function(t,e){if(e.isZero())return new s(1).toRed(this);if(0===e.cmpn(1))return t.clone();var r=new Array(16);r[0]=new s(1).toRed(this),r[1]=t;for(var i=2;i<r.length;i++)r[i]=this.mul(r[i-1],t);var n=r[0],o=0,a=0,h=e.bitLength()%26;for(0===h&&(h=26),i=e.length-1;i>=0;i--){for(var u=e.words[i],l=h-1;l>=0;l--){var c=u>>l&1;n!==r[0]&&(n=this.sqr(n)),0!==c||0!==o?(o<<=1,o|=c,(4==++a||0===i&&0===l)&&(n=this.mul(n,r[o]),a=0,o=0)):a=0}h=26}return n},B.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},B.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},s.mont=function(t){return new F(t)},n(F,B),F.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},F.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},F.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var r=t.imul(e),i=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(i).