From bdc826061086fe9db17a9858d1c2dc75c67a53bf Mon Sep 17 00:00:00 2001 From: haad Date: Sat, 2 Dec 2017 12:20:06 +0100 Subject: [PATCH] Fix replication starting from wrong heads Use ipfs-pubsub-room branch with a fix for the wrong heads Add a test tocheck that the automatic replication receives the right heads Add more logging --- dist/es5/OrbitDB.js | 12 +- dist/orbitdb.min.js | 2 +- package-lock.json | 300 +++++++++++++++------------ package.json | 2 +- src/OrbitDB.js | 2 +- test/replicate-automatically.test.js | 64 +++++- test/utils/config.js | 6 +- 7 files changed, 231 insertions(+), 157 deletions(-) diff --git a/dist/es5/OrbitDB.js b/dist/es5/OrbitDB.js index f89f533..0424d59 100644 --- a/dist/es5/OrbitDB.js +++ b/dist/es5/OrbitDB.js @@ -4,10 +4,6 @@ var _stringify = require('babel-runtime/core-js/json/stringify'); var _stringify2 = _interopRequireDefault(_stringify); -var _setImmediate2 = require('babel-runtime/core-js/set-immediate'); - -var _setImmediate3 = _interopRequireDefault(_setImmediate2); - var _getIterator2 = require('babel-runtime/core-js/get-iterator'); var _getIterator3 = _interopRequireDefault(_getIterator2); @@ -203,12 +199,8 @@ var OrbitDB = function () { }, { key: '_onWrite', value: function _onWrite(address, entry, heads) { - var _this = this; - if (!heads) throw new Error("'heads' not defined"); - if (this._pubsub) (0, _setImmediate3.default)(function () { - return _this._pubsub.publish(address, heads); - }); + if (this._pubsub) this._pubsub.publish(address, heads); } // Callback for receiving a message from the network @@ -236,7 +228,7 @@ var OrbitDB = function () { // Send the newly connected peer our latest heads var heads = store._oplog.heads; if (heads.length > 0) { - logger.debug('Send latest heads:\n', (0, _stringify2.default)(heads, null, 2)); + logger.debug('Send latest heads of \'' + address + '\':\n', (0, _stringify2.default)(heads, null, 2)); room.sendTo(peer, new Buffer((0, _stringify2.default)(heads))); } store.events.emit('peer', peer); diff --git a/dist/orbitdb.min.js b/dist/orbitdb.min.js index d7ff980..ba67b35 100644 --- a/dist/orbitdb.min.js +++ b/dist/orbitdb.min.js @@ -1 +1 @@ -var OrbitDB=function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=61)}([function(t,e){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function i(t){if(f===setTimeout)return setTimeout(t,0);if((f===n||!f)&&setTimeout)return f=setTimeout,setTimeout(t,0);try{return f(t,0)}catch(e){try{return f.call(null,t,0)}catch(e){return f.call(this,t,0)}}}function o(){p&&d&&(p=!1,d.length?l=d.concat(l):b=-1,l.length&&s())}function s(){if(!p){var t=i(o);p=!0;for(var e=l.length;e;){for(d=l,l=[];++b1)for(var n=1;n=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|t}function h(t,e){if(o.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return P(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return C(t).length;default:if(r)return P(t).length;e=(""+e).toLowerCase(),r=!0}}function d(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return function(t,e,n){var r=t.length;(!e||e<0)&&(e=0);(!n||n<0||n>r)&&(n=r);for(var i="",o=e;o2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=o.from(e,r)),o.isBuffer(e))return 0===e.length?-1:b(t,e,n,r,i);if("number"==typeof e)return e&=255,o.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):b(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,n,r,i){function o(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}var f;if(i){var u=-1;for(f=n;fa&&(n=a-c),f=n;f>=0;f--){for(var h=!0,d=0;di&&(r=i):r=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s>8,i=n%256,o.push(i),o.push(r);return o}(e,t.length-n),t,n,r)}function S(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i239?4:o>223?3:o>191?2:1;if(i+a<=n){var c,f,u,h;switch(a){case 1:o<128&&(s=o);break;case 2:128==(192&(c=t[i+1]))&&(h=(31&o)<<6|63&c)>127&&(s=h);break;case 3:c=t[i+1],f=t[i+2],128==(192&c)&&128==(192&f)&&(h=(15&o)<<12|(63&c)<<6|63&f)>2047&&(h<55296||h>57343)&&(s=h);break;case 4:c=t[i+1],f=t[i+2],u=t[i+3],128==(192&c)&&128==(192&f)&&128==(192&u)&&(h=(15&o)<<18|(63&c)<<12|(63&f)<<6|63&u)>65535&&h<1114112&&(s=h)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=a}return function(t){var e=t.length;if(e<=L)return String.fromCharCode.apply(String,t);var n="",r=0;for(;rn)throw new RangeError("Trying to access beyond buffer length")}function x(t,e,n,r,i,s){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function E(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-n,2);i>>8*(r?i:1-i)}function M(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-n,4);i>>8*(r?i:3-i)&255}function A(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function O(t,e,n,r,i){return i||A(t,0,n,4),j.write(t,e,n,r,23,4),n+4}function I(t,e,n,r,i){return i||A(t,0,n,8),j.write(t,e,n,r,52,8),n+8}function P(t,e){e=e||1/0;for(var n,r=t.length,i=null,o=[],s=0;s55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function C(t){return R.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(D,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function N(t,e,n,r){for(var i=0;i=e.length||i>=t.length);++i)e[i+n]=t[i];return i}var R=n(63),j=n(64),T=n(33);e.Buffer=o,e.SlowBuffer=function(t){return+t!=t&&(t=0),o.alloc(+t)},e.INSPECT_MAX_BYTES=50,o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=r(),o.poolSize=8192,o._augment=function(t){return t.__proto__=o.prototype,t},o.from=function(t,e,n){return s(null,t,e,n)},o.TYPED_ARRAY_SUPPORT&&(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0})),o.alloc=function(t,e,n){return function(t,e,n,r){return a(e),e<=0?i(t,e):void 0!==n?"string"==typeof r?i(t,e).fill(n,r):i(t,e).fill(n):i(t,e)}(null,t,e,n)},o.allocUnsafe=function(t){return c(null,t)},o.allocUnsafeSlow=function(t){return c(null,t)},o.isBuffer=function(t){return!(null==t||!t._isBuffer)},o.compare=function(t,e){if(!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,i=0,s=Math.min(n,r);i0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},o.prototype.compare=function(t,e,n,r,i){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,i>>>=0,this===t)return 0;for(var s=i-r,a=n-e,c=Math.min(s,a),f=this.slice(r,i),u=t.slice(e,n),h=0;hi)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return y(this,t,e,n);case"utf8":case"utf-8":return m(this,t,e,n);case"ascii":return g(this,t,e,n);case"latin1":case"binary":return v(this,t,e,n);case"base64":return _(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,t,e,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var L=4096;o.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(i*=256);)r+=this[t+--e]*i;return r},o.prototype.readUInt8=function(t,e){return e||k(t,1,this.length),this[t]},o.prototype.readUInt16LE=function(t,e){return e||k(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUInt16BE=function(t,e){return e||k(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUInt32LE=function(t,e){return e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUInt32BE=function(t,e){return e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t],i=1,o=0;++o=i&&(r-=Math.pow(2,8*e)),r},o.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=e,i=1,o=this[t+--r];r>0&&(i*=256);)o+=this[t+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},o.prototype.readInt8=function(t,e){return e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){e||k(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(t,e){e||k(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(t,e){return e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,e){return e||k(t,4,this.length),j.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return e||k(t,4,this.length),j.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return e||k(t,8,this.length),j.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return e||k(t,8,this.length),j.read(this,t,!1,52,8)},o.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){x(this,t,e,n,Math.pow(2,8*n)-1,0)}var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+n},o.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,1,255,0),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},o.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):E(this,t,e,!0),e+2},o.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):E(this,t,e,!1),e+2},o.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},o.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},o.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);x(this,t,e,n,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+n},o.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);x(this,t,e,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+n},o.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,1,127,-128),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):E(this,t,e,!0),e+2},o.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):E(this,t,e,!1),e+2},o.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},o.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},o.prototype.writeFloatLE=function(t,e,n){return O(this,t,e,!0,n)},o.prototype.writeFloatBE=function(t,e,n){return O(this,t,e,!1,n)},o.prototype.writeDoubleLE=function(t,e,n){return I(this,t,e,!0,n)},o.prototype.writeDoubleBE=function(t,e,n){return I(this,t,e,!1,n)},o.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--i)t[i+e]=this[i+n];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var s;if("number"==typeof t)for(s=e;s0&&this._events[t].length>s&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),i||(i=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var i=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,o,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,o=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(i(n)){for(a=s;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){o=a;break}if(o<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e,n){"use strict";function r(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function i(t){return 1===t.length?"0"+t:t}function o(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}var s=n(9),a=n(5);e.inherits=a,e.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var n=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),r=0;r>8,s=255&i;o?n.push(o,s):n.push(s)}else for(r=0;r>>0}return o},e.split32=function(t,e){for(var n=new Array(4*t.length),r=0,i=0;r>>24,n[i+1]=o>>>16&255,n[i+2]=o>>>8&255,n[i+3]=255&o):(n[i+3]=o>>>24,n[i+2]=o>>>16&255,n[i+1]=o>>>8&255,n[i]=255&o)}return n},e.rotr32=function(t,e){return t>>>e|t<<32-e},e.rotl32=function(t,e){return t<>>32-e},e.sum32=function(t,e){return t+e>>>0},e.sum32_3=function(t,e,n){return t+e+n>>>0},e.sum32_4=function(t,e,n,r){return t+e+n+r>>>0},e.sum32_5=function(t,e,n,r,i){return t+e+n+r+i>>>0},e.sum64=function(t,e,n,r){var i=t[e],o=r+t[e+1]>>>0,s=(o>>0,t[e+1]=o},e.sum64_hi=function(t,e,n,r){return(e+r>>>0>>0},e.sum64_lo=function(t,e,n,r){return e+r>>>0},e.sum64_4_hi=function(t,e,n,r,i,o,s,a){var c=0,f=e;return c+=(f=f+r>>>0)>>0)>>0)>>0},e.sum64_4_lo=function(t,e,n,r,i,o,s,a){return e+r+o+a>>>0},e.sum64_5_hi=function(t,e,n,r,i,o,s,a,c,f){var u=0,h=e;return u+=(h=h+r>>>0)>>0)>>0)>>0)>>0},e.sum64_5_lo=function(t,e,n,r,i,o,s,a,c,f){return e+r+o+a+f>>>0},e.rotr64_hi=function(t,e,n){return(e<<32-n|t>>>n)>>>0},e.rotr64_lo=function(t,e,n){return(t<<32-n|e>>>n)>>>0},e.shr64_hi=function(t,e,n){return t>>>n},e.shr64_lo=function(t,e,n){return(t<<32-n|e>>>n)>>>0}},function(t,e,n){(function(t){!function(t,e){"use strict";function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}function o(t,e,n){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(n=e,e=10),this._init(t||0,e||10,n||"be"))}function s(t,e,n){for(var r=0,i=Math.min(t.length,n),o=e;o=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return r}function a(t,e,n,r){for(var i=0,o=Math.min(t.length,n),s=e;s=49?a-49+10:a>=17?a-17+10:a}return i}function c(t,e,n){n.negative=e.negative^t.negative;var r=t.length+e.length|0;n.length=r,r=r-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,c=s/67108864|0;n.words[0]=a;for(var f=1;f>>26,h=67108863&c,d=Math.min(f,e.length-1),l=Math.max(0,f-t.length+1);l<=d;l++){var p=f-l|0;u+=(s=(i=0|t.words[p])*(o=0|e.words[l])+h)/67108864|0,h=67108863&s}n.words[f]=0|h,c=0|u}return 0!==c?n.words[f]=0|c:n.length--,n.strip()}function f(t,e,n){return(new u).mulp(t,e,n)}function u(t,e){this.x=t,this.y=e}function h(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function d(){h.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function l(){h.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function p(){h.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){h.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function y(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function m(t){y.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)}"object"==typeof t?t.exports=o:e.BN=o,o.BN=o,o.wordSize=26;var g;try{g=n(111).Buffer}catch(t){}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,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&i++,16===e?this._parseHex(t,i):this._parseBase(t,e,i),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),e,n)},o.prototype._initNumber=function(t,e,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):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},o.prototype._initArray=function(t,e,n){if(r("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=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===n)for(i=0,o=0;i>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this.strip()},o.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n=e;n-=6)i=s(t,n,n+6),this.words[r]|=i<>>26-o&4194303,(o+=24)>=26&&(o-=26,r++);n+6!==e&&(i=s(t,e,n+6),this.words[r]|=i<>>26-o&4194303),this.strip()},o.prototype._parseBase=function(t,e,n){this.words=[0],this.length=1;for(var r=0,i=1;i<=67108863;i*=e)r++;r--,i=i/e|0;for(var o=t.length-n,s=o%r,c=Math.min(o,o-s)+n,f=0,u=n;u1&&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?""};var v=["","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"],_=[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],w=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(t,e){t=t||10,e=0|e||1;var n;if(16===t||"hex"===t){n="";for(var i=0,o=0,s=0;s>>24-i&16777215)||s!==this.length-1?v[6-c.length]+c+n:c+n,(i+=2)>=26&&(i-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var f=_[t],u=w[t];n="";var h=this.clone();for(h.negative=0;!h.isZero();){var d=h.modn(u).toString(t);n=(h=h.idivn(u)).isZero()?d+n:v[f-d.length]+d+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(!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&&r(!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,e){return r(void 0!==g),this.toArrayLike(g,t,e)},o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,n){var i=this.byteLength(),o=n||Math.max(1,i);r(i<=o,"byte array longer than desired length"),r(o>0,"Requested array length <= 0"),this.strip();var s,a,c="le"===e,f=new t(o),u=this.clone();if(c){for(a=0;!u.isZero();a++)s=u.andln(255),u.iushrn(8),f[a]=s;for(;a=4096&&(n+=13,e>>>=13),e>=64&&(n+=7,e>>>=7),e>=8&&(n+=4,e>>>=4),e>=2&&(n+=2,e>>>=2),n+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,n=0;return 0==(8191&e)&&(n+=13,e>>>=13),0==(127&e)&&(n+=7,e>>>=7),0==(15&e)&&(n+=4,e>>>=4),0==(3&e)&&(n+=2,e>>>=2),0==(1&e)&&n++,n},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.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 e;e=this.length>t.length?t:this;for(var n=0;nt.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 e,n;this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0;rt.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){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var i=0;i0&&(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,e){r("number"==typeof t&&t>=0);var n=t/26|0,i=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<t.length?(n=this,r=t):(n=t,r=this);for(var i=0,o=0;o>>26;for(;0!==i&&o>>26;if(this.length=n.length,0!==i)this.words[this.length]=i,this.length++;else if(n!==this)for(;ot.length?this.clone().iadd(t):t.clone().iadd(this)},o.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 n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;var r,i;n>0?(r=this,i=t):(r=t,i=this);for(var o=0,s=0;s>26,this.words[s]=67108863&e;for(;0!==o&&s>26,this.words[s]=67108863&e;if(0===o&&s>>13,l=0|s[1],p=8191&l,b=l>>>13,y=0|s[2],m=8191&y,g=y>>>13,v=0|s[3],_=8191&v,w=v>>>13,S=0|s[4],k=8191&S,x=S>>>13,E=0|s[5],M=8191&E,A=E>>>13,O=0|s[6],I=8191&O,P=O>>>13,C=0|s[7],N=8191&C,R=C>>>13,j=0|s[8],T=8191&j,L=j>>>13,D=0|s[9],B=8191&D,F=D>>>13,q=0|a[0],U=8191&q,z=q>>>13,K=0|a[1],G=8191&K,H=K>>>13,Y=0|a[2],W=8191&Y,J=Y>>>13,$=0|a[3],V=8191&$,X=$>>>13,Z=0|a[4],Q=8191&Z,tt=Z>>>13,et=0|a[5],nt=8191&et,rt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ct=8191&at,ft=at>>>13,ut=0|a[8],ht=8191&ut,dt=ut>>>13,lt=0|a[9],pt=8191<,bt=lt>>>13;n.negative=t.negative^e.negative,n.length=19;var yt=(f+(r=Math.imul(h,U))|0)+((8191&(i=(i=Math.imul(h,z))+Math.imul(d,U)|0))<<13)|0;f=((o=Math.imul(d,z))+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(p,U),i=(i=Math.imul(p,z))+Math.imul(b,U)|0,o=Math.imul(b,z);var mt=(f+(r=r+Math.imul(h,G)|0)|0)+((8191&(i=(i=i+Math.imul(h,H)|0)+Math.imul(d,G)|0))<<13)|0;f=((o=o+Math.imul(d,H)|0)+(i>>>13)|0)+(mt>>>26)|0,mt&=67108863,r=Math.imul(m,U),i=(i=Math.imul(m,z))+Math.imul(g,U)|0,o=Math.imul(g,z),r=r+Math.imul(p,G)|0,i=(i=i+Math.imul(p,H)|0)+Math.imul(b,G)|0,o=o+Math.imul(b,H)|0;var gt=(f+(r=r+Math.imul(h,W)|0)|0)+((8191&(i=(i=i+Math.imul(h,J)|0)+Math.imul(d,W)|0))<<13)|0;f=((o=o+Math.imul(d,J)|0)+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,r=Math.imul(_,U),i=(i=Math.imul(_,z))+Math.imul(w,U)|0,o=Math.imul(w,z),r=r+Math.imul(m,G)|0,i=(i=i+Math.imul(m,H)|0)+Math.imul(g,G)|0,o=o+Math.imul(g,H)|0,r=r+Math.imul(p,W)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(b,W)|0,o=o+Math.imul(b,J)|0;var vt=(f+(r=r+Math.imul(h,V)|0)|0)+((8191&(i=(i=i+Math.imul(h,X)|0)+Math.imul(d,V)|0))<<13)|0;f=((o=o+Math.imul(d,X)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(k,U),i=(i=Math.imul(k,z))+Math.imul(x,U)|0,o=Math.imul(x,z),r=r+Math.imul(_,G)|0,i=(i=i+Math.imul(_,H)|0)+Math.imul(w,G)|0,o=o+Math.imul(w,H)|0,r=r+Math.imul(m,W)|0,i=(i=i+Math.imul(m,J)|0)+Math.imul(g,W)|0,o=o+Math.imul(g,J)|0,r=r+Math.imul(p,V)|0,i=(i=i+Math.imul(p,X)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,X)|0;var _t=(f+(r=r+Math.imul(h,Q)|0)|0)+((8191&(i=(i=i+Math.imul(h,tt)|0)+Math.imul(d,Q)|0))<<13)|0;f=((o=o+Math.imul(d,tt)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,r=Math.imul(M,U),i=(i=Math.imul(M,z))+Math.imul(A,U)|0,o=Math.imul(A,z),r=r+Math.imul(k,G)|0,i=(i=i+Math.imul(k,H)|0)+Math.imul(x,G)|0,o=o+Math.imul(x,H)|0,r=r+Math.imul(_,W)|0,i=(i=i+Math.imul(_,J)|0)+Math.imul(w,W)|0,o=o+Math.imul(w,J)|0,r=r+Math.imul(m,V)|0,i=(i=i+Math.imul(m,X)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,X)|0,r=r+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(b,Q)|0,o=o+Math.imul(b,tt)|0;var wt=(f+(r=r+Math.imul(h,nt)|0)|0)+((8191&(i=(i=i+Math.imul(h,rt)|0)+Math.imul(d,nt)|0))<<13)|0;f=((o=o+Math.imul(d,rt)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(I,U),i=(i=Math.imul(I,z))+Math.imul(P,U)|0,o=Math.imul(P,z),r=r+Math.imul(M,G)|0,i=(i=i+Math.imul(M,H)|0)+Math.imul(A,G)|0,o=o+Math.imul(A,H)|0,r=r+Math.imul(k,W)|0,i=(i=i+Math.imul(k,J)|0)+Math.imul(x,W)|0,o=o+Math.imul(x,J)|0,r=r+Math.imul(_,V)|0,i=(i=i+Math.imul(_,X)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,X)|0,r=r+Math.imul(m,Q)|0,i=(i=i+Math.imul(m,tt)|0)+Math.imul(g,Q)|0,o=o+Math.imul(g,tt)|0,r=r+Math.imul(p,nt)|0,i=(i=i+Math.imul(p,rt)|0)+Math.imul(b,nt)|0,o=o+Math.imul(b,rt)|0;var St=(f+(r=r+Math.imul(h,ot)|0)|0)+((8191&(i=(i=i+Math.imul(h,st)|0)+Math.imul(d,ot)|0))<<13)|0;f=((o=o+Math.imul(d,st)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(N,U),i=(i=Math.imul(N,z))+Math.imul(R,U)|0,o=Math.imul(R,z),r=r+Math.imul(I,G)|0,i=(i=i+Math.imul(I,H)|0)+Math.imul(P,G)|0,o=o+Math.imul(P,H)|0,r=r+Math.imul(M,W)|0,i=(i=i+Math.imul(M,J)|0)+Math.imul(A,W)|0,o=o+Math.imul(A,J)|0,r=r+Math.imul(k,V)|0,i=(i=i+Math.imul(k,X)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,X)|0,r=r+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,tt)|0,r=r+Math.imul(m,nt)|0,i=(i=i+Math.imul(m,rt)|0)+Math.imul(g,nt)|0,o=o+Math.imul(g,rt)|0,r=r+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0;var kt=(f+(r=r+Math.imul(h,ct)|0)|0)+((8191&(i=(i=i+Math.imul(h,ft)|0)+Math.imul(d,ct)|0))<<13)|0;f=((o=o+Math.imul(d,ft)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(T,U),i=(i=Math.imul(T,z))+Math.imul(L,U)|0,o=Math.imul(L,z),r=r+Math.imul(N,G)|0,i=(i=i+Math.imul(N,H)|0)+Math.imul(R,G)|0,o=o+Math.imul(R,H)|0,r=r+Math.imul(I,W)|0,i=(i=i+Math.imul(I,J)|0)+Math.imul(P,W)|0,o=o+Math.imul(P,J)|0,r=r+Math.imul(M,V)|0,i=(i=i+Math.imul(M,X)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,X)|0,r=r+Math.imul(k,Q)|0,i=(i=i+Math.imul(k,tt)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,tt)|0,r=r+Math.imul(_,nt)|0,i=(i=i+Math.imul(_,rt)|0)+Math.imul(w,nt)|0,o=o+Math.imul(w,rt)|0,r=r+Math.imul(m,ot)|0,i=(i=i+Math.imul(m,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0,r=r+Math.imul(p,ct)|0,i=(i=i+Math.imul(p,ft)|0)+Math.imul(b,ct)|0,o=o+Math.imul(b,ft)|0;var xt=(f+(r=r+Math.imul(h,ht)|0)|0)+((8191&(i=(i=i+Math.imul(h,dt)|0)+Math.imul(d,ht)|0))<<13)|0;f=((o=o+Math.imul(d,dt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(B,U),i=(i=Math.imul(B,z))+Math.imul(F,U)|0,o=Math.imul(F,z),r=r+Math.imul(T,G)|0,i=(i=i+Math.imul(T,H)|0)+Math.imul(L,G)|0,o=o+Math.imul(L,H)|0,r=r+Math.imul(N,W)|0,i=(i=i+Math.imul(N,J)|0)+Math.imul(R,W)|0,o=o+Math.imul(R,J)|0,r=r+Math.imul(I,V)|0,i=(i=i+Math.imul(I,X)|0)+Math.imul(P,V)|0,o=o+Math.imul(P,X)|0,r=r+Math.imul(M,Q)|0,i=(i=i+Math.imul(M,tt)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,tt)|0,r=r+Math.imul(k,nt)|0,i=(i=i+Math.imul(k,rt)|0)+Math.imul(x,nt)|0,o=o+Math.imul(x,rt)|0,r=r+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,r=r+Math.imul(m,ct)|0,i=(i=i+Math.imul(m,ft)|0)+Math.imul(g,ct)|0,o=o+Math.imul(g,ft)|0,r=r+Math.imul(p,ht)|0,i=(i=i+Math.imul(p,dt)|0)+Math.imul(b,ht)|0,o=o+Math.imul(b,dt)|0;var Et=(f+(r=r+Math.imul(h,pt)|0)|0)+((8191&(i=(i=i+Math.imul(h,bt)|0)+Math.imul(d,pt)|0))<<13)|0;f=((o=o+Math.imul(d,bt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(B,G),i=(i=Math.imul(B,H))+Math.imul(F,G)|0,o=Math.imul(F,H),r=r+Math.imul(T,W)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,W)|0,o=o+Math.imul(L,J)|0,r=r+Math.imul(N,V)|0,i=(i=i+Math.imul(N,X)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,X)|0,r=r+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,r=r+Math.imul(M,nt)|0,i=(i=i+Math.imul(M,rt)|0)+Math.imul(A,nt)|0,o=o+Math.imul(A,rt)|0,r=r+Math.imul(k,ot)|0,i=(i=i+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,r=r+Math.imul(_,ct)|0,i=(i=i+Math.imul(_,ft)|0)+Math.imul(w,ct)|0,o=o+Math.imul(w,ft)|0,r=r+Math.imul(m,ht)|0,i=(i=i+Math.imul(m,dt)|0)+Math.imul(g,ht)|0,o=o+Math.imul(g,dt)|0;var Mt=(f+(r=r+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,bt)|0)+Math.imul(b,pt)|0))<<13)|0;f=((o=o+Math.imul(b,bt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(B,W),i=(i=Math.imul(B,J))+Math.imul(F,W)|0,o=Math.imul(F,J),r=r+Math.imul(T,V)|0,i=(i=i+Math.imul(T,X)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,X)|0,r=r+Math.imul(N,Q)|0,i=(i=i+Math.imul(N,tt)|0)+Math.imul(R,Q)|0,o=o+Math.imul(R,tt)|0,r=r+Math.imul(I,nt)|0,i=(i=i+Math.imul(I,rt)|0)+Math.imul(P,nt)|0,o=o+Math.imul(P,rt)|0,r=r+Math.imul(M,ot)|0,i=(i=i+Math.imul(M,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,r=r+Math.imul(k,ct)|0,i=(i=i+Math.imul(k,ft)|0)+Math.imul(x,ct)|0,o=o+Math.imul(x,ft)|0,r=r+Math.imul(_,ht)|0,i=(i=i+Math.imul(_,dt)|0)+Math.imul(w,ht)|0,o=o+Math.imul(w,dt)|0;var At=(f+(r=r+Math.imul(m,pt)|0)|0)+((8191&(i=(i=i+Math.imul(m,bt)|0)+Math.imul(g,pt)|0))<<13)|0;f=((o=o+Math.imul(g,bt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(B,V),i=(i=Math.imul(B,X))+Math.imul(F,V)|0,o=Math.imul(F,X),r=r+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,tt)|0,r=r+Math.imul(N,nt)|0,i=(i=i+Math.imul(N,rt)|0)+Math.imul(R,nt)|0,o=o+Math.imul(R,rt)|0,r=r+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,st)|0,r=r+Math.imul(M,ct)|0,i=(i=i+Math.imul(M,ft)|0)+Math.imul(A,ct)|0,o=o+Math.imul(A,ft)|0,r=r+Math.imul(k,ht)|0,i=(i=i+Math.imul(k,dt)|0)+Math.imul(x,ht)|0,o=o+Math.imul(x,dt)|0;var Ot=(f+(r=r+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,bt)|0)+Math.imul(w,pt)|0))<<13)|0;f=((o=o+Math.imul(w,bt)|0)+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(B,Q),i=(i=Math.imul(B,tt))+Math.imul(F,Q)|0,o=Math.imul(F,tt),r=r+Math.imul(T,nt)|0,i=(i=i+Math.imul(T,rt)|0)+Math.imul(L,nt)|0,o=o+Math.imul(L,rt)|0,r=r+Math.imul(N,ot)|0,i=(i=i+Math.imul(N,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,r=r+Math.imul(I,ct)|0,i=(i=i+Math.imul(I,ft)|0)+Math.imul(P,ct)|0,o=o+Math.imul(P,ft)|0,r=r+Math.imul(M,ht)|0,i=(i=i+Math.imul(M,dt)|0)+Math.imul(A,ht)|0,o=o+Math.imul(A,dt)|0;var It=(f+(r=r+Math.imul(k,pt)|0)|0)+((8191&(i=(i=i+Math.imul(k,bt)|0)+Math.imul(x,pt)|0))<<13)|0;f=((o=o+Math.imul(x,bt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(B,nt),i=(i=Math.imul(B,rt))+Math.imul(F,nt)|0,o=Math.imul(F,rt),r=r+Math.imul(T,ot)|0,i=(i=i+Math.imul(T,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,r=r+Math.imul(N,ct)|0,i=(i=i+Math.imul(N,ft)|0)+Math.imul(R,ct)|0,o=o+Math.imul(R,ft)|0,r=r+Math.imul(I,ht)|0,i=(i=i+Math.imul(I,dt)|0)+Math.imul(P,ht)|0,o=o+Math.imul(P,dt)|0;var Pt=(f+(r=r+Math.imul(M,pt)|0)|0)+((8191&(i=(i=i+Math.imul(M,bt)|0)+Math.imul(A,pt)|0))<<13)|0;f=((o=o+Math.imul(A,bt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,r=Math.imul(B,ot),i=(i=Math.imul(B,st))+Math.imul(F,ot)|0,o=Math.imul(F,st),r=r+Math.imul(T,ct)|0,i=(i=i+Math.imul(T,ft)|0)+Math.imul(L,ct)|0,o=o+Math.imul(L,ft)|0,r=r+Math.imul(N,ht)|0,i=(i=i+Math.imul(N,dt)|0)+Math.imul(R,ht)|0,o=o+Math.imul(R,dt)|0;var Ct=(f+(r=r+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,bt)|0)+Math.imul(P,pt)|0))<<13)|0;f=((o=o+Math.imul(P,bt)|0)+(i>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(B,ct),i=(i=Math.imul(B,ft))+Math.imul(F,ct)|0,o=Math.imul(F,ft),r=r+Math.imul(T,ht)|0,i=(i=i+Math.imul(T,dt)|0)+Math.imul(L,ht)|0,o=o+Math.imul(L,dt)|0;var Nt=(f+(r=r+Math.imul(N,pt)|0)|0)+((8191&(i=(i=i+Math.imul(N,bt)|0)+Math.imul(R,pt)|0))<<13)|0;f=((o=o+Math.imul(R,bt)|0)+(i>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,r=Math.imul(B,ht),i=(i=Math.imul(B,dt))+Math.imul(F,ht)|0,o=Math.imul(F,dt);var Rt=(f+(r=r+Math.imul(T,pt)|0)|0)+((8191&(i=(i=i+Math.imul(T,bt)|0)+Math.imul(L,pt)|0))<<13)|0;f=((o=o+Math.imul(L,bt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863;var jt=(f+(r=Math.imul(B,pt))|0)+((8191&(i=(i=Math.imul(B,bt))+Math.imul(F,pt)|0))<<13)|0;return f=((o=Math.imul(F,bt))+(i>>>13)|0)+(jt>>>26)|0,jt&=67108863,c[0]=yt,c[1]=mt,c[2]=gt,c[3]=vt,c[4]=_t,c[5]=wt,c[6]=St,c[7]=kt,c[8]=xt,c[9]=Et,c[10]=Mt,c[11]=At,c[12]=Ot,c[13]=It,c[14]=Pt,c[15]=Ct,c[16]=Nt,c[17]=Rt,c[18]=jt,0!==f&&(c[19]=f,n.length++),n};Math.imul||(S=c),o.prototype.mulTo=function(t,e){var n=this.length+t.length;return 10===this.length&&10===t.length?S(this,t,e):n<63?c(this,t,e):n<1024?function(t,e,n){n.negative=e.negative^t.negative,n.length=t.length+e.length;for(var r=0,i=0,o=0;o>>26)|0)>>>26,s&=67108863}n.words[o]=a,r=s,s=i}return 0!==r?n.words[o]=r:n.length--,n.strip()}(this,t,e):f(this,t,e)},u.prototype.makeRBT=function(t){for(var e=new Array(t),n=o.prototype._countBits(t)-1,r=0;r>=1;return r},u.prototype.permute=function(t,e,n,r,i,o){for(var s=0;s>>=1)i++;return 1<>>=13,n[2*s+1]=8191&o,o>>>=13;for(s=2*e;s>=26,e+=i/67108864|0,e+=o>>>26,this.words[n]=67108863&o}return 0!==e&&(this.words[n]=e,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 e=function(t){for(var e=new Array(t.bitLength()),n=0;n>>i}return e}(t);if(0===e.length)return new o(1);for(var n=this,r=0;r=0);var e,n=t%26,i=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e=0);var i;i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<s)for(this.length-=s,f=0;f=0&&(0!==u||f>=i);f--){var h=0|this.words[f];this.words[f]=u<<26-o|h>>>o,u=h&a}return c&&0!==u&&(c.words[c.length++]=u),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(t,e,n){return r(0===this.negative),this.iushrn(t,e,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){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,i=1<=0);var e=t%26,n=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var i=67108863^67108863>>>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},o.prototype.isubn=function(t){if(r("number"==typeof t),r(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>26)-(c/67108864|0),this.words[i+n]=67108863&s}for(;i>26,this.words[i+n]=67108863&s;if(0===a)return this.strip();for(r(-1===a),a=0,i=0;i>26,this.words[i]=67108863&s;return this.negative=1,this.strip()},o.prototype._wordDiv=function(t,e){var n=this.length-t.length,r=this.clone(),i=t,s=0|i.words[i.length-1];0!==(n=26-this._countBits(s))&&(i=i.ushln(n),r.iushln(n),s=0|i.words[i.length-1]);var a,c=r.length-i.length;if("mod"!==e){(a=new o(null)).length=c+1,a.words=new Array(a.length);for(var f=0;f=0;h--){var d=67108864*(0|r.words[i.length+h])+(0|r.words[i.length+h-1]);for(d=Math.min(d/s|0,67108863),r._ishlnsubmul(i,d,h);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(i,1,h),r.isZero()||(r.negative^=1);a&&(a.words[h]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==n&&r.iushrn(n),{div:a||null,mod:r}},o.prototype.divmod=function(t,e,n){if(r(!t.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var i,s,a;return 0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{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,e)},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 e=this.divmod(t);if(e.mod.isZero())return e.div;var n=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),i=t.andln(1),o=n.cmp(r);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modn=function(t){r(t<=67108863);for(var e=(1<<26)%t,n=0,i=this.length-1;i>=0;i--)n=(e*n+(0|this.words[i]))%t;return n},o.prototype.idivn=function(t){r(t<=67108863);for(var e=0,n=this.length-1;n>=0;n--){var i=(0|this.words[n])+67108864*e;this.words[n]=i/t|0,e=i%t}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),c=new o(1),f=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++f;for(var u=n.clone(),h=e.clone();!e.isZero();){for(var d=0,l=1;0==(e.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(u),s.isub(h)),i.iushrn(1),s.iushrn(1);for(var p=0,b=1;0==(n.words[0]&b)&&p<26;++p,b<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(a.isOdd()||c.isOdd())&&(a.iadd(u),c.isub(h)),a.iushrn(1),c.iushrn(1);e.cmp(n)>=0?(e.isub(n),i.isub(a),s.isub(c)):(n.isub(e),a.isub(i),c.isub(s))}return{a:a,b:c,gcd:n.iushln(f)}},o.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var c=0,f=1;0==(e.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(e.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(a),i.iushrn(1);for(var u=0,h=1;0==(n.words[0]&h)&&u<26;++u,h<<=1);if(u>0)for(n.iushrn(u);u-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);e.cmp(n)>=0?(e.isub(n),i.isub(s)):(n.isub(e),s.isub(i))}var d;return(d=0===e.cmpn(1)?i:s).cmpn(0)<0&&d.iadd(t),d},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),n=t.clone();e.negative=0,n.negative=0;for(var r=0;e.isEven()&&n.isEven();r++)e.iushrn(1),n.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;n.isEven();)n.iushrn(1);var i=e.cmp(n);if(i<0){var o=e;e=n,n=o}else if(0===i||0===n.cmpn(1))break;e.isub(n)}return n.iushln(r)},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){r("number"==typeof t);var e=t%26,n=(t-e)/26,i=1<>>26,a&=67108863,this.words[s]=a}return 0!==o&&(this.words[s]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var e=t<0;if(0!==this.negative&&!e)return-1;if(0===this.negative&&e)return 1;this.strip();var n;if(this.length>1)n=1;else{e&&(t=-t),r(t<=67108863,"Number is too big");var i=0|this.words[0];n=i===t?0:it.length)return 1;if(this.length=0;n--){var r=0|this.words[n],i=0|t.words[n];if(r!==i){ri&&(e=1);break}}return e},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 y(t)},o.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return r(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 r(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var k={k256:null,p224:null,p192:null,p25519:null};h.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},h.prototype.ireduce=function(t){var e,n=t;do{this.split(n,this.tmp),e=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e0?n.isub(this.p):n.strip(),n},h.prototype.split=function(t,e){t.iushrn(this.n,0,e)},h.prototype.imulK=function(t){return t.imul(this.k)},i(d,h),d.prototype.split=function(t,e){for(var n=Math.min(t.length,9),r=0;r>>22,i=o}i>>>=22,t.words[r-10]=i,0===i&&t.length>10?t.length-=10:t.length-=9},d.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,n=0;n>>=26,t.words[n]=i,e=r}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(k[t])return k[t];var e;if("k256"===t)e=new d;else if("p224"===t)e=new l;else if("p192"===t)e=new p;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new b}return k[t]=e,e},y.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},y.prototype._verify2=function(t,e){r(0==(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},y.prototype.add=function(t,e){this._verify2(t,e);var n=t.add(e);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},y.prototype.iadd=function(t,e){this._verify2(t,e);var n=t.iadd(e);return n.cmp(this.m)>=0&&n.isub(this.m),n},y.prototype.sub=function(t,e){this._verify2(t,e);var n=t.sub(e);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},y.prototype.isub=function(t,e){this._verify2(t,e);var n=t.isub(e);return n.cmpn(0)<0&&n.iadd(this.m),n},y.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},y.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},y.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},y.prototype.isqr=function(t){return this.imul(t,t.clone())},y.prototype.sqr=function(t){return this.mul(t,t)},y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var n=this.m.add(new o(1)).iushrn(2);return this.pow(t,n)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);r(!i.isZero());var a=new o(1).toRed(this),c=a.redNeg(),f=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new o(2*u*u).toRed(this);0!==this.pow(u,f).cmp(c);)u.redIAdd(c);for(var h=this.pow(u,i),d=this.pow(t,i.addn(1).iushrn(1)),l=this.pow(t,i),p=s;0!==l.cmp(a);){for(var b=l,y=0;0!==b.cmp(a);y++)b=b.redSqr();r(y=0;r--){for(var f=e.words[r],u=c-1;u>=0;u--){var h=f>>u&1;i!==n[0]&&(i=this.sqr(i)),0!==h||0!==s?(s<<=1,s|=h,(4===++a||0===r&&0===u)&&(i=this.mul(i,n[s]),a=0,s=0)):a=0}c=26}return i},y.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},y.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new m(t)},i(m,y),m.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},m.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},m.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var n=t.imul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},m.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var n=t.mul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},m.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===t||t,this)}).call(e,n(50)(t))},function(t,e,n){"use strict";function r(t){if(!(this instanceof r))return new r(t);f.call(this,t),u.call(this,t),t&&!1===t.readable&&(this.readable=!1),t&&!1===t.writable&&(this.writable=!1),this.allowHalfOpen=!0,t&&!1===t.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",i)}function i(){this.allowHalfOpen||this._writableState.ended||s(o,this)}function o(t){t.end()}var s=n(20),a=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e};t.exports=r;var c=n(14);c.inherits=n(5);var f=n(35),u=n(25);c.inherits(r,f);for(var h=a(u.prototype),d=0;d=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},n(62),e.setImmediate=setImmediate,e.clearImmediate=clearImmediate},function(t,e,n){(function(t){function n(t,e){for(var n=0,r=t.length-1;r>=0;r--){var i=t[r];"."===i?t.splice(r,1):".."===i?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function r(t,e){if(t.filter)return t.filter(e);for(var n=[],r=0;r=-1&&!i;o--){var s=o>=0?arguments[o]:t.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(e=s+"/"+e,i="/"===s.charAt(0))}return e=n(r(e.split("/"),function(t){return!!t}),!i).join("/"),(i?"/":"")+e||"."},e.normalize=function(t){var i=e.isAbsolute(t),o="/"===s(t,-1);return(t=n(r(t.split("/"),function(t){return!!t}),!i).join("/"))||i||(t="."),t&&o&&(t+="/"),(i?"/":"")+t},e.isAbsolute=function(t){return"/"===t.charAt(0)},e.join=function(){var t=Array.prototype.slice.call(arguments,0);return e.normalize(r(t,function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))},e.relative=function(t,n){function r(t){for(var e=0;e=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=e.resolve(t).substr(1),n=e.resolve(n).substr(1);for(var i=r(t.split("/")),o=r(n.split("/")),s=Math.min(i.length,o.length),a=s,c=0;c=this._delta8){var n=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-n,t.length),0===this.pending.length&&(this.pending=null),t=i.join32(t,0,t.length-n,this.endian);for(var r=0;r>>24&255,r[i++]=t>>>16&255,r[i++]=t>>>8&255,r[i++]=255&t}else for(r[i++]=255&t,r[i++]=t>>>8&255,r[i++]=t>>>16&255,r[i++]=t>>>24&255,r[i++]=0,r[i++]=0,r[i++]=0,r[i++]=0,o=8;o{this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,t.clock?t.clock.time:0]),this.events.emit("replicate",this.address.toString())}),this._loader.on("load.start",(t,e)=>{this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,t.clock?t.clock.time:0])}),this._loader.on("load.progress",(t,e,n,r,i)=>{this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this.events.emit("replicate.progress",this.address.toString(),e,n,this._replicationInfo.progress,this._replicationInfo.have)}),this._loader.on("load.end",async(t,e)=>{try{await this._oplog.join(t,-1,this._oplog.id),this._replicator.replicate(this._oplog),this._index.updateIndex(this._oplog),this._calculateReplicationInfo(e),this.events.emit("replicated",this.address.toString())}catch(t){console.error(t)}}),this._replicator=new d(this._loader),this._replicator.replicate(this._oplog),this.options.replicate&&this._replicator.start()}catch(t){console.error("Store Error:",t)}}_calculateReplicationInfo(t){this._replicationInfo.progress=Math.min(this._oplog.length,Math.max(this._replicationInfo.progress,this._oplog.length)),this._replicationInfo.max=Math.max(this._replicationInfo.max,this._oplog.length),t&&(this._replicationInfo.have=Object.assign(this._replicationInfo.have,t))}get all(){return Array.isArray(this._index._index)?this._index._index:Object.keys(this._index._index).map(t=>this._index._index[t])}get type(){return this._type}get key(){return this._key}async close(){return this._loader.stop(),this._replicator.stop(),this._replicationInfo={progress:0,max:0,have:{}},this._stats={snapshot:{bytesLoaded:-1},syncRequestsReceieved:0},this.events.removeAllListeners("load"),this.events.removeAllListeners("load.progress"),this.events.removeAllListeners("replicate"),this.events.removeAllListeners("replicate.progress"),this.events.removeAllListeners("replicated"),this.events.removeAllListeners("ready"),this.events.removeAllListeners("write"),this.events.emit("closed",this.address.toString()),Promise.resolve()}async drop(){const t=this.address.toString();await this._cache.set(t,{}),this._index=new this.options.Index(this.id),this._oplog=new a(this._ipfs,this.id,null,null,null,this._key,this.access.write),this._cache=this.options&&this.options.cache?this.options.cache:new c(this.options.path,this.dbname)}async load(t){this._replicator.stop();try{await this._cache.load()}catch(t){console.warn("Couldn't load Cache:",t)}const e=this._cache.get(this.address.toString())||e,n=e.localHeads||[],r=e.remoteHeads||[];if(this._replicationInfo.max=Math.max(this._replicationInfo.max,n.concat(r).reduce((t,e)=>Math.max(t,e.clock.time),0)),n||r){this.events.emit("load",this.address.toString()),t=t||this.options.maxHistory;let e,i;if(n&&n.length>0)for(const r of n){e=await a.fromEntryHash(this._ipfs,r.hash,this._oplog.id,t,this._oplog.values,this.key,this.access.write,this._onLoadProgress.bind(this)),await this._oplog.join(e,-1,this._oplog.id);const n=this._oplog.values[this._oplog.length-1];this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,this._oplog.values[this._oplog.length-1].clock.time,0]),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this._onLoadProgress(n.hash,n,this._replicationInfo.progress,this._replicationInfo.max)}if(r&&r.length>0){this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,r[0].clock.time,0]);for(const e of r){i=await a.fromEntryHash(this._ipfs,e.hash,this._oplog.id,t,this._oplog.values,this.key,this.access.write,this._onLoadProgress.bind(this)),await this._oplog.join(i,-1,this._oplog.id);const n=this._oplog.values[this._oplog.length-1];this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,this._oplog.values[this._oplog.length-1].clock.time,0]),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this._onLoadProgress(n.hash,n,this._replicationInfo.progress,this._replicationInfo.max)}}const o=this._oplog.values[this._oplog.length-1];o&&this._onLoadProgress(o.hash,o,this._replicationInfo.progress,this._replicationInfo.max),this._index.updateIndex(this._oplog)}this.options.replicate&&(this._replicator.replicate(this._oplog),this._replicator.start()),this.events.emit("ready",this.address.toString(),this._oplog.heads)}sync(t,n,r,i=!0,o=-1,a=0){this._stats.syncRequestsReceieved+=1;return s(t,t=>{if(!t)return console.warn("Warning: Given input entry was 'null'."),Promise.resolve(null);if(!this.access.write.includes(t.key)&&!this.access.write.includes("*"))return console.warn("Warning: Given input entry is not allowed in this log and was discarded (no write access)."),Promise.resolve(null);const n=Object.assign({},t);return n.hash=null,this._ipfs.object.put(e.from(JSON.stringify(n))).then(t=>t.toJSON().multihash).then(e=>(e!==t.hash&&console.warn("\"WARNING! Head hash didn't match the contents"),e)).then(()=>t)}).then(async e=>{const n=this.address.toString();let r=Object.assign({},this._cache.get(n),{remoteHeads:t});return await this._cache.set(n,r),this._loader.load(e.filter(t=>null!==t))})}loadMoreFrom(t,e){this._loader.load(e)}async saveSnapshot(){const t=Object.keys(this._loader._fetching).map(t=>this._loader._fetching[t]).concat(this._loader._queue.map(t=>t));let n=this._oplog.toSnapshot(),r=new e(JSON.stringify({id:n.id,heads:n.heads,size:n.values.length,type:this.type}));const i=new o;let s=new Uint16Array([r.length]),a=new e(s.buffer);i.push(a),i.push(r),n.values.forEach(t=>{let n=new e(JSON.stringify(t)),r=new Uint16Array([n.length]);i.push(new e(r.buffer)),i.push(n)}),i.push(null);const c={path:this.address.toString(),content:i},f=await this._ipfs.files.add(c),u=this.address.toString();let h=Object.assign({},this._cache.get(u),{snapshot:f[f.length-1],queue:t,type:this.type,max:this._replicationInfo.max});return await this._cache.set(u,h),f}async loadFromSnapshot(t){this.events.emit("load",this.address.toString()),await this._cache.load();const n=this._cache.get(this.address.toString());if(this._replicationInfo.max=Math.max(this._replicationInfo.max,n.max||0),this.sync(n.queue||[]),!n.snapshot)throw new Error(`Snapshot for ${this.address} not found!`);{const t=await this._ipfs.files.cat(n.snapshot.hash),r=await(()=>new Promise((n,r)=>{let i=new e(0),o=[];t.on("data",t=>{if(this._byteSize+=t.length,o.length<2e3)o.push(t);else{const t=e.concat(o);i=e.concat([i,t]),o=[]}}),t.on("end",()=>{function t(t){for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),r=0;r0){const t=e.concat(o);i=e.concat([i,t])}const r=parseInt(new Uint16Array(t(i.slice(0,2)))),s=JSON.parse(i.slice(2,r+2));let a=[],c=2+r;for(;cMath.max(t,e.clock.time),0)),n({values:a,id:s.id,heads:s.heads,type:s.type})})}))(),i=await a.fromJSON(this._ipfs,r,-1,this._key,this.access.write,1e3,(t,e,n,r)=>{this._replicationInfo.max=Math.max(this._replicationInfo.max,e.clock.time),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,n,this._oplog.length]),this._onLoadProgress(t,e,this._replicationInfo.progress,this._replicationInfo.max)});await this._oplog.join(i,-1,this._oplog.id),this._oplog.values.forEach(t=>this._replicationInfo.have[t.clock.time]=!0),this._replicationInfo.max=Math.max(this._replicationInfo.max,this._oplog.length),this._replicationInfo.progress=Math.max(this._replicationInfo.progress,this._oplog.length),this._replicator.replicate(this._oplog),this._index.updateIndex(this._oplog),this.events.emit("ready",this.address.toString(),this._oplog.heads),this.events.emit("replicated",this.address.toString())}return this}async _addOperation(t,e,n,r){if(this._oplog){const e=await this._oplog.append(t);this._replicationInfo.max=Math.max(this._replicationInfo.max,e.clock.time),this._replicationInfo.progress++;const n=this.address.toString();let i=Object.assign({},this._cache.get(n),{localHeads:[e],max:this._replicationInfo.max});return await this._cache.set(n,i),this._index.updateIndex(this._oplog),this.events.emit("write",this.address.toString(),e,this._oplog.heads),r&&r(e),e.hash}}_addOperationBatch(t,e,n,r){throw new Error("Not implemented!")}_onLoadProgress(t,e,n,r){this.events.emit("load.progress",this.address.toString(),t,e,Math.max(this._oplog.length,n),Math.max(this._oplog.length||0,this._replicationInfo.max||0))}}t.exports=p}).call(e,n(1).Buffer)},function(t,e,n){"use strict";(function(e){function n(t,n,r,i){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick(function(){t.call(null,n)});case 3:return e.nextTick(function(){t.call(null,n,r)});case 4:return e.nextTick(function(){t.call(null,n,r,i)});default:for(o=new Array(a-1),s=0;snew Promise((r,i)=>{if(n=Object.assign({concurrency:1/0},n),"function"!=typeof e)throw new TypeError("Mapper function is required");const o=n.concurrency;if(!("number"==typeof o&&o>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${o}\` (${typeof o})`);const s=[],a=t[Symbol.iterator]();let c=!1,f=!1,u=0,h=0;const d=()=>{if(c)return;const t=a.next(),n=h;if(h++,t.done)return f=!0,void(0===u&&r(s));u++,Promise.resolve(t.value).then(t=>e(t,n)).then(t=>{s[n]=t,u--,d()},t=>{c=!0,i(t)})};for(let t=0;t=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),h(n)?r.showHidden=n:n&&e._extend(r,n),b(r.showHidden)&&(r.showHidden=!1),b(r.depth)&&(r.depth=2),b(r.colors)&&(r.colors=!1),b(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),a(r,t,r.depth)}function o(t,e){var n=i.styles[e];return n?"["+i.colors[n][0]+"m"+t+"["+i.colors[n][1]+"m":t}function s(t,e){return t}function a(t,n,r){if(t.customInspect&&n&&_(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return p(i)||(i=a(t,i,r)),i}var o=function(t,e){if(b(e))return t.stylize("undefined","undefined");if(p(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(l(e))return t.stylize(""+e,"number");if(h(e))return t.stylize(""+e,"boolean");if(d(e))return t.stylize("null","null")}(t,n);if(o)return o;var s=Object.keys(n),m=function(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),v(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return c(n);if(0===s.length){if(_(n)){var w=n.name?": "+n.name:"";return t.stylize("[Function"+w+"]","special")}if(y(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(g(n))return t.stylize(Date.prototype.toString.call(n),"date");if(v(n))return c(n)}var S="",x=!1,E=["{","}"];if(u(n)&&(x=!0,E=["[","]"]),_(n)){S=" [Function"+(n.name?": "+n.name:"")+"]"}if(y(n)&&(S=" "+RegExp.prototype.toString.call(n)),g(n)&&(S=" "+Date.prototype.toUTCString.call(n)),v(n)&&(S=" "+c(n)),0===s.length&&(!x||0==n.length))return E[0]+S+E[1];if(r<0)return y(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var M;return M=x?function(t,e,n,r,i){for(var o=[],s=0,a=e.length;s=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(M,S,E)}function c(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,n,r,i,o){var s,c,f;if((f=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?c=f.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):f.set&&(c=t.stylize("[Setter]","special")),k(r,i)||(s="["+i+"]"),c||(t.seen.indexOf(f.value)<0?(c=d(n)?a(t,f.value,null):a(t,f.value,n-1)).indexOf("\n")>-1&&(c=o?c.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+c.split("\n").map(function(t){return" "+t}).join("\n")):c=t.stylize("[Circular]","special")),b(s)){if(o&&i.match(/^\d+$/))return c;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+c}function u(t){return Array.isArray(t)}function h(t){return"boolean"==typeof t}function d(t){return null===t}function l(t){return"number"==typeof t}function p(t){return"string"==typeof t}function b(t){return void 0===t}function y(t){return m(t)&&"[object RegExp]"===w(t)}function m(t){return"object"==typeof t&&null!==t}function g(t){return m(t)&&"[object Date]"===w(t)}function v(t){return m(t)&&("[object Error]"===w(t)||t instanceof Error)}function _(t){return"function"==typeof t}function w(t){return Object.prototype.toString.call(t)}function S(t){return t<10?"0"+t.toString(10):t.toString(10)}function k(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var x=/%[sdj%]/g;e.format=function(t){if(!p(t)){for(var e=[],n=0;n=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),a=r[n];n-1?r:y;c.WritableState=a;var v=n(14);v.inherits=n(5);var _={deprecate:n(67)},w=n(36),S=n(10).Buffer,k=i.Uint8Array||function(){},x=n(37);v.inherits(c,w),a.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(a.prototype,"buffer",{get:_.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}();var E;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(E=Function.prototype[Symbol.hasInstance],Object.defineProperty(c,Symbol.hasInstance,{value:function(t){return!!E.call(this,t)||t&&t._writableState instanceof a}})):E=function(t){return t instanceof this},c.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},c.prototype.write=function(t,e,n){var r=this._writableState,i=!1,o=function(t){return S.isBuffer(t)||t instanceof k}(t)&&!r.objectMode;return o&&!S.isBuffer(t)&&(t=function(t){return S.from(t)}(t)),"function"==typeof e&&(n=e,e=null),o?e="buffer":e||(e=r.defaultEncoding),"function"!=typeof n&&(n=s),r.ended?function(t,e){var n=new Error("write after end");t.emit("error",n),y(e,n)}(this,n):(o||function(t,e,n,r){var i=!0,o=!1;return null===n?o=new TypeError("May not write null values to stream"):"string"==typeof n||void 0===n||e.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(t.emit("error",o),y(r,o),i=!1),i}(this,r,t,n))&&(r.pendingcb++,i=f(this,r,o,t,e,n)),i},c.prototype.cork=function(){this._writableState.corked++},c.prototype.uncork=function(){var t=this._writableState;t.corked&&(t.corked--,t.writing||t.corked||t.finished||t.bufferProcessing||!t.bufferedRequest||d(this,t))},c.prototype.setDefaultEncoding=function(t){if("string"==typeof t&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this},c.prototype._write=function(t,e,n){n(new Error("_write() is not implemented"))},c.prototype._writev=null,c.prototype.end=function(t,e,n){var r=this._writableState;"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!==t&&void 0!==t&&this.write(t,e),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||function(t,e,n){e.ending=!0,b(t,e),n&&(e.finished?y(n):t.once("finish",n)),e.ended=!0,t.writable=!1}(this,r,n)},Object.defineProperty(c.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),c.prototype.destroy=x.destroy,c.prototype._undestroy=x.undestroy,c.prototype._destroy=function(t,e){this.end(),e(t)}}).call(e,n(0),n(11).setImmediate,n(3))},function(t,e,n){"use strict";(function(e){const r=n(27),i=n(28),o=()=>new Error("Ipfs instance not defined");class s{static async create(t,e,n,a=[],c,f){if(!i(t))throw o();if(!i(e))throw new Error("Entry requires an id");if(!i(n))throw new Error("Entry requires data");if(!i(a)||!Array.isArray(a))throw new Error("'next' argument is not an array");let u={hash:null,id:e,payload:n,next:a.filter(i).map(t=>t.hash?t.hash:t),v:0,clock:new r(e,c?c.time:null)};return t.keystore&&f&&(u=await s.signEntry(t.keystore,u,f)),u.hash=await s.toMultihash(t,u),u}static async signEntry(t,n,r){const i=await t.sign(r,new e(JSON.stringify(n)));return n.sig=i,n.key=r.getPublic("hex"),n}static async verifyEntry(t,n){const r=Object.assign({},{hash:null,id:t.id,payload:t.payload,next:t.next,v:t.v,clock:t.clock}),i=await n.importPublicKey(t.key);await n.verify(t.sig,i,new e(JSON.stringify(r)))}static toMultihash(t,n){if(!t)throw o();const r=e.from(JSON.stringify(n));return t.object.put(r).then(t=>t.toJSON().multihash)}static fromMultihash(t,e){if(!t)throw o();if(!e)throw new Error(`Invalid hash: ${e}`);return t.object.get(e,{enc:"base58"}).then(t=>JSON.parse(t.toJSON().data)).then(t=>{let n={hash:e,id:t.id,payload:t.payload,next:t.next,v:t.v,clock:t.clock};return t.sig&&Object.assign(n,{sig:t.sig}),t.key&&Object.assign(n,{key:t.key}),n})}static isEntry(t){return void 0!==t.id&&void 0!==t.next&&void 0!==t.hash&&void 0!==t.payload&&void 0!==t.v&&void 0!==t.clock}static compare(t,e){var n=r.compare(t.clock,e.clock);return 0===n?t.clock.id-1}static findChildren(t,e){for(var n=[],r=e.find(e=>s.isParent(t,e)),i=t;r;)n.push(r),i=r,r=e.find(t=>s.isParent(i,t));return n=n.sort((t,e)=>t.clock.time>t.clock.time)}}t.exports=s}).call(e,n(1).Buffer)},function(t,e,n){"use strict";class r{constructor(t,e){this.id=t,this.time=e||0}tick(){return new r(this.id,++this.time)}merge(t){return this.time=Math.max(this.time,t.time),new r(this.id,this.time)}clone(){return new r(this.id,this.time)}static compare(t,e){var n=t.time-e.time;return 0===n&&t.id!==e.id?t.idvoid 0!==t&&null!==t)},function(t,e,n){"use strict";var r=n(44);t.exports=function(t,e){if(!t)return function(t,n){return t?r(n,t,e):n(!0)};Array.isArray(t)||(t=Object.keys(t).map(function(e){return t[e]}));var n=0;return function(i,o){if(i)return r(o,i,e);n>=t.length?o(!0):o(null,t[n++])}}},function(t,e,n){"use strict";var r=n(15);t.exports=function(t,e,n){n||(n=e,e=null);var i=r(function(n){e=t(e,n)},function(t){n(t,e)});return 2===arguments.length?function(t){t(null,function(r,o){if(r)return n(!0===r?null:r);e=o,i(t)})}:i}},function(t,e,n){"use strict";var r=n(46);t.exports=function(t){return t=r(t),function(e){return function n(r,i){for(var o,s=!0;s;)s=!1,o=!0,e(r,function(e,r){if(!e&&!t(r))return o?s=!0:n(e,i);i(e,r)}),o=!1}}}},function(t,e,n){var r=e;r.utils=n(6),r.common=n(18),r.sha=n(119),r.ripemd=n(123),r.hmac=n(124),r.sha1=r.sha.sha1,r.sha256=r.sha.sha256,r.sha224=r.sha.sha224,r.sha384=r.sha.sha384,r.sha512=r.sha.sha512,r.ripemd160=r.ripemd.ripemd160},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";const r=n(19),i=n(154);class o extends r{constructor(t,e,n,r={}){void 0===r.Index&&Object.assign(r,{Index:i}),super(t,e,n,r),this._type="eventlog"}add(t){return this._addOperation({op:"ADD",key:null,value:t})}get(t){return this.iterator({gte:t,limit:1}).collect()[0]}iterator(t){const e=this._query(t);let n=0;return{[Symbol.iterator](){return this},next(){let t={value:null,done:!0};return ne}}_query(t){t||(t={});const e=t.limit?t.limit>-1?t.limit:this._index.get().length:1,n=this._index.get().slice();let r=[];return r=t.gt||t.gte?this._read(n,t.gt?t.gt:t.gte,e,!!t.gte):this._read(n.reverse(),t.lt?t.lt:t.lte,e,t.lte||!t.lt).reverse()}_read(t,e,n,r){const i=t.map(t=>t.hash).indexOf(e);let o=Math.max(i,0);o+=r?0:1;return t.slice(o).slice(0,n)}}t.exports=o},function(t,e,n){"use strict";(function(e,r){function i(t,e){w=w||n(8),t=t||{},this.objectMode=!!t.objectMode,e instanceof w&&(this.objectMode=this.objectMode||!!t.readableObjectMode);var r=t.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:i,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new C,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.destroyed=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(P||(P=n(38).StringDecoder),this.decoder=new P(t.encoding),this.encoding=t.encoding)}function o(t){if(w=w||n(8),!(this instanceof o))return new o(t);this._readableState=new i(t,this),this.readable=!0,t&&("function"==typeof t.read&&(this._read=t.read),"function"==typeof t.destroy&&(this._destroy=t.destroy)),x.call(this)}function s(t,e,n,r,i){var o=t._readableState;if(null===e)o.reading=!1,function(t,e){if(e.ended)return;if(e.decoder){var n=e.decoder.end();n&&n.length&&(e.buffer.push(n),e.length+=e.objectMode?1:n.length)}e.ended=!0,f(t)}(t,o);else{var s;i||(s=function(t,e){var n;(function(t){return E.isBuffer(t)||t instanceof M})(e)||"string"==typeof e||void 0===e||t.objectMode||(n=new TypeError("Invalid non-string/buffer chunk"));return n}(o,e)),s?t.emit("error",s):o.objectMode||e&&e.length>0?("string"==typeof e||o.objectMode||Object.getPrototypeOf(e)===E.prototype||(e=function(t){return E.from(t)}(e)),r?o.endEmitted?t.emit("error",new Error("stream.unshift() after end event")):a(t,o,e,!0):o.ended?t.emit("error",new Error("stream.push() after EOF")):(o.reading=!1,o.decoder&&!n?(e=o.decoder.write(e),o.objectMode||0!==e.length?a(t,o,e,!1):h(t,o)):a(t,o,e,!1))):r||(o.reading=!1)}return function(t){return!t.ended&&(t.needReadable||t.lengthe.highWaterMark&&(e.highWaterMark=function(t){return t>=j?t=j:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function f(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(I("emitReadable",e.flowing),e.emittedReadable=!0,e.sync?_(u,t):u(t))}function u(t){I("emit readable"),t.emit("readable"),b(t)}function h(t,e){e.readingMore||(e.readingMore=!0,_(d,t,e))}function d(t,e){for(var n=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length=e.length?(n=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.head.data:e.buffer.concat(e.length),e.buffer.clear()):n=function(t,e,n){var r;to.length?o.length:t;if(s===o.length?i+=o:i+=o.slice(0,t),0===(t-=s)){s===o.length?(++r,n.next?e.head=n.next:e.head=e.tail=null):(e.head=n,n.data=o.slice(s));break}++r}return e.length-=r,i}(t,e):function(t,e){var n=E.allocUnsafe(t),r=e.head,i=1;r.data.copy(n),t-=r.data.length;for(;r=r.next;){var o=r.data,s=t>o.length?o.length:t;if(o.copy(n,n.length-t,0,s),0===(t-=s)){s===o.length?(++i,r.next?e.head=r.next:e.head=e.tail=null):(e.head=r,r.data=o.slice(s));break}++i}return e.length-=i,n}(t,e);return r}(t,e.buffer,e.decoder),n}function m(t){var e=t._readableState;if(e.length>0)throw new Error('"endReadable()" called on non-empty stream');e.endEmitted||(e.ended=!0,_(g,e,t))}function g(t,e){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}function v(t,e){for(var n=0,r=t.length;n=e.highWaterMark||e.ended))return I("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?m(this):f(this),null;if(0===(t=c(t,e))&&e.ended)return 0===e.length&&m(this),null;var r=e.needReadable;I("need readable",r),(0===e.length||e.length-t0?y(t,e):null)?(e.needReadable=!0,t=0):e.length-=t,0===e.length&&(e.ended||(e.needReadable=!0),n!==t&&e.ended&&m(this)),null!==i&&this.emit("data",i),i},o.prototype._read=function(t){this.emit("error",new Error("_read() is not implemented"))},o.prototype.pipe=function(t,e){function n(e,r){I("onunpipe"),e===u&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,I("cleanup"),t.removeListener("close",a),t.removeListener("finish",c),t.removeListener("drain",l),t.removeListener("error",s),t.removeListener("unpipe",n),u.removeListener("end",i),u.removeListener("end",f),u.removeListener("data",o),p=!0,!h.awaitDrain||t._writableState&&!t._writableState.needDrain||l())}function i(){I("onend"),t.end()}function o(e){I("ondata"),y=!1;!1!==t.write(e)||y||((1===h.pipesCount&&h.pipes===t||h.pipesCount>1&&-1!==v(h.pipes,t))&&!p&&(I("false write response, pause",u._readableState.awaitDrain),u._readableState.awaitDrain++,y=!0),u.pause())}function s(e){I("onerror",e),f(),t.removeListener("error",s),0===k(t,"error")&&t.emit("error",e)}function a(){t.removeListener("finish",c),f()}function c(){I("onfinish"),t.removeListener("close",a),f()}function f(){I("unpipe"),u.unpipe(t)}var u=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=t;break;case 1:h.pipes=[h.pipes,t];break;default:h.pipes.push(t)}h.pipesCount+=1,I("pipe count=%d opts=%j",h.pipesCount,e);var d=(!e||!1!==e.end)&&t!==r.stdout&&t!==r.stderr?i:f;h.endEmitted?_(d):u.once("end",d),t.on("unpipe",n);var l=function(t){return function(){var e=t._readableState;I("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&k(t,"data")&&(e.flowing=!0,b(t))}}(u);t.on("drain",l);var p=!1,y=!1;return u.on("data",o),function(t,e,n){if("function"==typeof t.prependListener)return t.prependListener(e,n);t._events&&t._events[e]?S(t._events[e])?t._events[e].unshift(n):t._events[e]=[n,t._events[e]]:t.on(e,n)}(t,"error",s),t.once("close",a),t.once("finish",c),t.emit("pipe",u),h.flowing||(I("pipe resume"),u.resume()),t},o.prototype.unpipe=function(t){var e=this._readableState,n={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes?this:(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,n),this);if(!t){var r=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o>5==6?2:t>>4==14?3:t>>3==30?4:-1}function o(t){var e=this.lastTotal-this.lastNeed,n=function(t,e,n){if(128!=(192&e[0]))return t.lastNeed=0,"�".repeat(n);if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�".repeat(n+1);if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�".repeat(n+2)}}(this,t,e);return void 0!==n?n:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function s(t,e){if((t.length-e)%2==0){var n=t.toString("utf16le",e);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function a(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,n)}return e}function c(t,e){var n=(t.length-e)%3;return 0===n?t.toString("base64",e):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-n))}function f(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function u(t){return t.toString(this.encoding)}function h(t){return t&&t.length?this.write(t):""}var d=n(10).Buffer,l=d.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};e.StringDecoder=r,r.prototype.write=function(t){if(0===t.length)return"";var e,n;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n=0?(o>0&&(t.lastNeed=o-1),o):--r=0?(o>0&&(t.lastNeed=o-2),o):--r=0?(o>0&&(2===o?o=0:t.lastNeed=o-3),o):0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=n;var r=t.length-(n-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)},r.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},function(t,e,n){"use strict";function r(t){this.afterTransform=function(e,n){return function(t,e,n){var r=t._transformState;r.transforming=!1;var i=r.writecb;if(!i)return t.emit("error",new Error("write callback called multiple times"));r.writechunk=null,r.writecb=null,null!==n&&void 0!==n&&t.push(n);i(e);var o=t._readableState;o.reading=!1,(o.needReadable||o.length(t[e.hash]=e,t),{}),r=r||h.findHeads(n),this._headsIndex=r.reduce((t,e)=>(t[e.hash]=e,t),{}),this._length=n?n.length:0;const u=Math.max(i?i.time:0,this.heads.reduce((t,e)=>Math.max(t,e.clock.time),0));this._clock=new c(this.id,u)}get id(){return this._id}get clock(){return this._clock}get length(){return this._length}get values(){return Object.values(this._entryIndex).sort(o.compare)||[]}get heads(){return Object.values(this._headsIndex)||[]}get tails(){return h.findTails(this.values)}get tailHashes(){return h.findTailHashes(this.values)}get(t){return this._entryIndex[t]}has(t){return void 0!==this._entryIndex[t.hash||t]}async append(t){if(this._key&&!this._keys.includes(this._key.getPublic("hex"))&&!this._keys.includes("*"))throw new Error("Not allowed to write");const e=Math.max(this.clock.time,this.heads.reduce((t,e)=>Math.max(t,e.clock.time),0))+1;this._clock=new c(this.clock.id,e);const n=await o.create(this._storage,this.id,t,Object.values(this._headsIndex),this.clock,this._key);return this._entryIndex[n.hash]=n,this._headsIndex={},this._headsIndex[n.hash]=n,this._length++,n}async join(t,e=-1,n){if(!f(t))throw a.LogNotDefinedError();if(!h.isLog(t))throw a.NotALogError();const i=async t=>{this._keys.map(t=>t.getPublic?t.getPublic("hex"):t);return(await r(t,async t=>{if(!t.key)throw new Error("Entry doesn't have a public key");if(!t.sig)throw new Error("Entry doesn't have a signature");if(1===this._keys.length&&this._keys[0]===this._key&&t.id!==this.id)throw new Error("Entry doesn't belong in this log (wrong ID)");if(this._keys.length>0&&!this._keys.includes("*")&&!((t,e)=>t.find(t=>t===e.key))(this._keys.concat([this._key]),t))return console.warn("Warning: Input log contains entries that are not allowed in this log. Logs weren't joined."),!1;try{await o.verifyEntry(t,this._keystore)}catch(e){return console.log(e),console.log("Couldn't verify entry:\n",t),!1}return!0})).every(t=>!0===t)},s=(t,e)=>(t[e.hash]=e,t);n=n||[t,this].sort((t,e)=>t.id>e.id)[0].id;const u=((t,e)=>{let n=Object.keys(t._headsIndex),r={},i={};for(;n.length>0;){const o=n.shift(),s=t.get(o);s&&!e.get(o)&&(i[s.hash]=s,r[s.hash]=!0,s.next.forEach(t=>{r[t]||e.get(t)||(n.push(t),r[t]=!0)}))}return i})(t,this);if(this._key){if(!await i(Object.values(u)))return this}if(this._entryIndex=Object.assign(this._entryIndex,u),this._length+=Object.values(u).length,e>-1){let t=this.values;t=t.slice(-e),this._entryIndex=t.reduce(s,{}),this._length=Object.values(this._entryIndex).length}const d=h.findHeads(Object.values(Object.assign({},this._headsIndex,t._headsIndex)));this._headsIndex=d.reduce(s,{});const l=Object.values(this._headsIndex).reduce((t,e)=>t=Math.max(t,e.clock.time),0),p=new c(this.id,Math.max(this.clock.time,l));return this._id=n,this._clock=p,this}toJSON(){return{id:this.id,heads:this.heads.map(t=>t.hash)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return e.from(JSON.stringify(this.toJSON()))}toString(t){return this.values.slice().reverse().map((e,n)=>{const r=o.findChildren(e,this.values).length;let i=new Array(Math.max(r-1,0));return i=r>1?i.fill(" "):i,(i=r>0?i.concat(["└─"]):i).join("")+(t?t(e.payload):e.payload)}).join("\n")}static isLog(t){return void 0!==t.id&&void 0!==t.heads&&void 0!==t._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static fromMultihash(t,e,n=-1,r,i,o){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw new Error(`Invalid hash: ${e}`);return s.fromMultihash(t,e,n,r,o).then(e=>new h(t,e.id,e.values,e.heads,e.clock,i))}static fromEntryHash(t,e,n,r=-1,i,o,c,u){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw new Error("'hash' must be defined");return s.fromEntryHash(t,e,n,r,i,u).then(e=>new h(t,n,e.values,null,null,o,c))}static fromJSON(t,e,n=-1,r,i,o,c){if(!f(t))throw a.ImmutableDBNotDefinedError();return s.fromJSON(t,e,n,r,o,c).then(e=>new h(t,e.id,e.values,null,null,r,i))}static fromEntry(t,e,n=-1,r,i){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw new Error("'sourceEntries' must be defined");return s.fromEntry(t,e,n,r,i).then(e=>new h(t,e.id,e.values))}static expandFrom(t,e,n,r=-1){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw a.LogNotDefinedError();if(!f(n))throw new Error("'entries' must be given as argument");if(!h.isLog(e))throw a.NotALogError();return s.expandFrom(t,e,n,r).then(n=>new h(t,e.id,n.values,null,e.clock))}static expand(t,e,n){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw a.LogNotDefinedError();if(!h.isLog(e))throw a.NotALogError();return s.expand(t,e,n).then(n=>new h(t,e.id,n.values,e.heads,e.clock))}static findHeads(t){var e=t.reduce((t,e,n,r)=>{return e.next.forEach(n=>t[n]=e.hash),t},{});return t.filter(t=>void 0===e[t.hash]).sort((t,e)=>t.id>e.id)}static findTails(t){var e={},n=[],r={},i=[];t.forEach(t=>{0===t.next.length&&n.push(t);t.next.forEach(n=>{e[n]||(e[n]=[]),e[n].push(t)}),i=i.concat(t.next),r[t.hash]=!0});const s=i.filter(t=>void 0===r[t]).map(t=>e[t]).reduce((t,e,n,r)=>t.concat(u(e,"hash")),[]).concat(n);return u(s,"hash").sort(o.compare)}static findTailHashes(t){var e={};return t.forEach(t=>e[t.hash]=!0),t.reduce((t,n,r,i)=>{return n.next.reverse().forEach(n=>{void 0===e[n]&&t.splice(0,0,n)}),t},[])}}t.exports=h}).call(e,n(1).Buffer)},function(t,e,n){"use strict";t.exports={ImmutableDBNotDefinedError:()=>new Error("ImmutableDB instance not defined"),LogNotDefinedError:()=>new Error("Log instance not defined"),NotALogError:()=>new Error("Given argument is not an instance of Log")}},function(t,e,n){"use strict";t.exports=function(t,e){let n={};return t.forEach(t=>n[e?t[e]:t]=t),Object.keys(n).map(t=>n[t])}},function(t,e,n){"use strict";(function(e){const r=n(22),i=n(98),o=n(107);class s{constructor(t,e="data"){this.path=t||"./orbitdb",this.filename=e+".orbitdb",this._store=new i(this.path),this._cache={},this._lock=new o}get(t){return this._cache[t]}set(t,e){return new Promise((n,i)=>{if(this._cache[t]===e)return n(e);this._cache[t]=e,this._lock(this.filename,t=>{r(r.values([this._cache]),r.map(t=>JSON.stringify(t,null,2)),this._store.write(this.filename,t(t=>{if(t)return i(t);n(e)})))})})}load(){return this._cache={},new Promise((t,n)=>{this._store.exists(this.filename,(i,o)=>{if(i||!o)return t();this._lock(this.filename,i=>{r(this._store.read(this.filename),r.collect(i((r,i)=>{if(r)return n(r);try{this._cache=JSON.parse(e.concat(i).toString()||"{}")}catch(t){return n(t)}t()})))})})})}reset(){this._cache={},this._store=null}}t.exports=s}).call(e,n(1).Buffer)},function(t,e){t.exports=function(t,e,n){t(e),n&&n(!0===e?null:e)}},function(t,e,n){"use strict";var r=n(44);t.exports=function(t,e){return function(n,i){if(n)return r(i,n,e);if(null!=t){var o=t;t=null,i(null,o)}else i(!0)}}},function(t,e,n){var r=n(16);t.exports=function(t){return"object"==typeof t&&"function"==typeof t.test?function(e){return t.test(e)}:r(t)||function(t){return t}}},function(t,e,n){"use strict";var r=n(16),i=n(31);t.exports=function(t,e){t=r(t)||function(t){return t};var n={};return i(function(r){var i=t(r);return n[i]?!!e:(n[i]=!0,!e)})}},function(t,e){t.exports=function(t,e){function n(t,e){t&&(a=t,c&&s(a)),c=e,o()}function r(t){f=f||t||!0,o()}function i(t){f||(c?s(a,t):(u.push(t),o()))}function o(){c&&(a?s(a):!u.length&&f?s(f):u.length&&s(null,u.shift()))}function s(t,n){var r=c;if(t&&e){var i=e;e=null,i(!0===t?null:t)}c=null,r(t,n)}"function"==typeof t&&(e=t,t=!1);var a,c,f,u=[];return t?{push:i,end:r,source:n}:(n.push=i,n.end=r,n)}},function(t,e,n){"use strict";(function(e){const r=n(108),i=new(0,n(2).ec)("secp256k1");class o{constructor(t="./keystore"){if("undefined"==typeof localStorage||null===localStorage){r.sync(t);const e=n(133).LocalStorage;this._storage=new e(t)}else this._storage=localStorage}createKey(t){const e=i.genKeyPair(),n=e.getPublic("hex"),r=e.getPrivate("hex");return this._storage.setItem(t,JSON.stringify({publicKey:n,privateKey:r})),e}getKey(t){let e=JSON.parse(this._storage.getItem(t));if(!e)return;return i.keyPair({pub:e.publicKey,priv:e.privateKey,privEnc:"hex",pubEnc:"hex"})}static importKeyFromIpfs(t,e){return t.object.get(e,{enc:"base58"}).then(t=>JSON.parse(t.toJSON().Data)).then(t=>OrbitCrypto.importPublicKey(t))}static exportPublicKeyToIpfs(t,n){n.getPublic("hex");return OrbitCrypto.exportPublicKey(n).then(t=>JSON.stringify(t,null,2)).then(t=>new e(t)).then(e=>t.object.put(e)).then(t=>t.toJSON().multihash)}static getKey(t){let e,n,r,o=JSON.parse(keystore.getItem(t));return o?OrbitCrypto.importPrivateKey(o.privateKey).then(t=>r=t).then(()=>OrbitCrypto.importPublicKey(o.publicKey)).then(t=>n=t).then(()=>i.keyPair({pub:n,priv:r})):OrbitCrypto.generateKey().then(t=>e=t).then(()=>OrbitCrypto.exportPrivateKey(e)).then(t=>r=t).then(()=>OrbitCrypto.exportPublicKey(e)).then(t=>n=t).then(()=>(keystore.setItem(t,JSON.stringify({publicKey:n,privateKey:r})),i.keyPair({pub:n,priv:r})))}generateKey(){return Promise.resolve(i.genKeyPair())}exportPublicKey(t){return Promise.resolve(t.getPublic("hex"))}exportPrivateKey(t){return Promise.resolve(t.getPrivate("hex"))}importPublicKey(t){return Promise.resolve(i.keyFromPublic(t,"hex"))}importPrivateKey(t){return Promise.resolve(i.keyFromPrivate(t,"hex"))}sign(t,e){const n=i.sign(e,t);return Promise.resolve(n.toDER("hex"))}verify(t,e,n){let r=!1;return r=i.verify(n,t,e),Promise.resolve(r)}}t.exports=o}).call(e,n(1).Buffer)},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";function r(t){return 1===t.length?"0"+t:t}function i(t){for(var e="",n=0;n>8,s=255&i;o?n.push(o,s):n.push(s)}return n},o.zero2=r,o.toHex=i,o.encode=function(t,e){return"hex"===e?i(t):t}},function(t,e,n){"use strict";function r(t,e,n){return t&e^~t&n}function i(t,e,n){return t&e^t&n^e&n}function o(t,e,n){return t^e^n}var s=n(6).rotr32;e.ft_1=function(t,e,n,s){return 0===t?r(e,n,s):1===t||3===t?o(e,n,s):2===t?i(e,n,s):void 0},e.ch32=r,e.maj32=i,e.p32=o,e.s0_256=function(t){return s(t,2)^s(t,13)^s(t,22)},e.s1_256=function(t){return s(t,6)^s(t,11)^s(t,25)},e.g0_256=function(t){return s(t,7)^s(t,18)^t>>>3},e.g1_256=function(t){return s(t,17)^s(t,19)^t>>>10}},function(t,e,n){"use strict";function r(){if(!(this instanceof r))return new r;m.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=g,this.W=new Array(64)}var i=n(6),o=n(18),s=n(52),a=n(9),c=i.sum32,f=i.sum32_4,u=i.sum32_5,h=s.ch32,d=s.maj32,l=s.s0_256,p=s.s1_256,b=s.g0_256,y=s.g1_256,m=o.BlockHash,g=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];i.inherits(r,m),t.exports=r,r.blockSize=512,r.outSize=256,r.hmacStrength=192,r.padLength=64,r.prototype._update=function(t,e){for(var n=this.W,r=0;r<16;r++)n[r]=t[e+r];for(;r-1&&t%1==0&&t-1&&t%1==0&&t<=N}(t.length)&&!A(t)}function A(t){var e=O(t)?wt.call(t):"";return e==L||e==D}function O(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function I(t){return M(t)?p(t):function(t){if(!k(t))return Nt(t);var e=[];for(var n in Object(t))_t.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}var P=200,C="__lodash_hash_undefined__",N=9007199254740991,R="[object Arguments]",j="[object Boolean]",T="[object Date]",L="[object Function]",D="[object GeneratorFunction]",B="[object Map]",F="[object Number]",q="[object Object]",U="[object Promise]",z="[object RegExp]",K="[object Set]",G="[object String]",H="[object Symbol]",Y="[object WeakMap]",W="[object ArrayBuffer]",J="[object DataView]",$="[object Float32Array]",V="[object Float64Array]",X="[object Int8Array]",Z="[object Int16Array]",Q="[object Int32Array]",tt="[object Uint8Array]",et="[object Uint8ClampedArray]",nt="[object Uint16Array]",rt="[object Uint32Array]",it=/\w*$/,ot=/^\[object .+?Constructor\]$/,st=/^(?:0|[1-9]\d*)$/,at={};at[R]=at["[object Array]"]=at[W]=at[J]=at[j]=at[T]=at[$]=at[V]=at[X]=at[Z]=at[Q]=at[B]=at[F]=at[q]=at[z]=at[K]=at[G]=at[H]=at[tt]=at[et]=at[nt]=at[rt]=!0,at["[object Error]"]=at[L]=at[Y]=!1;var ct="object"==typeof t&&t&&t.Object===Object&&t,ft="object"==typeof self&&self&&self.Object===Object&&self,ut=ct||ft||Function("return this")(),ht="object"==typeof e&&e&&!e.nodeType&&e,dt=ht&&"object"==typeof n&&n&&!n.nodeType&&n,lt=dt&&dt.exports===ht,pt=Array.prototype,bt=Function.prototype,yt=Object.prototype,mt=ut["__core-js_shared__"],gt=function(){var t=/[^.]+$/.exec(mt&&mt.keys&&mt.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),vt=bt.toString,_t=yt.hasOwnProperty,wt=yt.toString,St=RegExp("^"+vt.call(_t).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),kt=lt?ut.Buffer:void 0,xt=ut.Symbol,Et=ut.Uint8Array,Mt=c(Object.getPrototypeOf,Object),At=Object.create,Ot=yt.propertyIsEnumerable,It=pt.splice,Pt=Object.getOwnPropertySymbols,Ct=kt?kt.isBuffer:void 0,Nt=c(Object.keys,Object),Rt=S(ut,"DataView"),jt=S(ut,"Map"),Tt=S(ut,"Promise"),Lt=S(ut,"Set"),Dt=S(ut,"WeakMap"),Bt=S(Object,"create"),Ft=x(Rt),qt=x(jt),Ut=x(Tt),zt=x(Lt),Kt=x(Dt),Gt=xt?xt.prototype:void 0,Ht=Gt?Gt.valueOf:void 0;u.prototype.clear=function(){this.__data__=Bt?Bt(null):{}},u.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},u.prototype.get=function(t){var e=this.__data__;if(Bt){var n=e[t];return n===C?void 0:n}return _t.call(e,t)?e[t]:void 0},u.prototype.has=function(t){var e=this.__data__;return Bt?void 0!==e[t]:_t.call(e,t)},u.prototype.set=function(t,e){return this.__data__[t]=Bt&&void 0===e?C:e,this},h.prototype.clear=function(){this.__data__=[]},h.prototype.delete=function(t){var e=this.__data__,n=y(e,t);return!(n<0||(n==e.length-1?e.pop():It.call(e,n,1),0))},h.prototype.get=function(t){var e=this.__data__,n=y(e,t);return n<0?void 0:e[n][1]},h.prototype.has=function(t){return y(this.__data__,t)>-1},h.prototype.set=function(t,e){var n=this.__data__,r=y(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},d.prototype.clear=function(){this.__data__={hash:new u,map:new(jt||h),string:new u}},d.prototype.delete=function(t){return w(this,t).delete(t)},d.prototype.get=function(t){return w(this,t).get(t)},d.prototype.has=function(t){return w(this,t).has(t)},d.prototype.set=function(t,e){return w(this,t).set(t,e),this},l.prototype.clear=function(){this.__data__=new h},l.prototype.delete=function(t){return this.__data__.delete(t)},l.prototype.get=function(t){return this.__data__.get(t)},l.prototype.has=function(t){return this.__data__.has(t)},l.prototype.set=function(t,e){var n=this.__data__;if(n instanceof h){var r=n.__data__;if(!jt||r.length{let e=t;return r.isBuffer(e)||(e=r.from(e)),e})},function(t,e,n){"use strict";(function(e){const r=n(17),i=n(24).format,o=n(4).EventEmitter;let s=!!e.version;const a={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR",NONE:"NONE"};let c=a.DEBUG,f=null,u=new o,h={Black:0,Red:1,Green:2,Yellow:3,Blue:4,Magenta:5,Cyan:6,Grey:7,White:9,Default:9};s||(h={Black:"Black",Red:"IndianRed",Green:"LimeGreen",Yellow:"Orange",Blue:"RoyalBlue",Magenta:"Orchid",Cyan:"SkyBlue",Grey:"DimGrey",White:"White",Default:"Black"});const d=[h.Cyan,h.Green,h.Yellow,h.Red,h.Default],l={useColors:!0,color:h.Default,showTimestamp:!0,showLevel:!0,filename:f,appendFile:!0};class p{constructor(t,e){this.category=t;let n={};Object.assign(n,l),Object.assign(n,e),this.options=n}debug(){this._shouldLog(a.DEBUG)&&this._write(a.DEBUG,i.apply(null,arguments))}log(){this._shouldLog(a.DEBUG)&&this.debug.apply(this,arguments)}info(){this._shouldLog(a.INFO)&&this._write(a.INFO,i.apply(null,arguments))}warn(){this._shouldLog(a.WARN)&&this._write(a.WARN,i.apply(null,arguments))}error(){this._shouldLog(a.ERROR)&&this._write(a.ERROR,i.apply(null,arguments))}_write(t,e){(this.options.filename||f)&&!this.fileWriter&&s&&(this.fileWriter=r.openSync(this.options.filename||f,this.options.appendFile?"a+":"w+"));let n=this._format(t,e),i=this._createLogMessage(t,e),o=this._createLogMessage(t,e,n.timestamp,n.level,n.category,n.text);this.fileWriter&&s&&r.writeSync(this.fileWriter,i+"\n",null,"utf-8"),s||!this.options.useColors?(console.log(o),u.emit("data",this.category,t,e)):t===a.ERROR?this.options.showTimestamp&&this.options.showLevel?console.error(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.error(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.error(o,n.level,n.category,n.text):console.error(o,n.category,n.text):this.options.showTimestamp&&this.options.showLevel?console.log(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.log(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.log(o,n.level,n.category,n.text):console.log(o,n.category,n.text)}_format(t,e){let n="",r="",i="",o=": ";if(this.options.useColors){const e=Object.keys(a).map(t=>a[t]).indexOf(t),c=this.options.color;s?(this.options.showTimestamp&&(n="[3"+h.Grey+"m"),this.options.showLevel&&(r="[3"+d[e]+";22m"),i="[3"+c+";1m",o=": "):(this.options.showTimestamp&&(n="color:"+h.Grey),this.options.showLevel&&(r="color:"+d[e]),i="color:"+c+"; font-weight: bold")}return{timestamp:n,level:r,category:i,text:o}}_createLogMessage(t,e,n,r,i,o){n=n||"",r=r||"",i=i||"",o=o||": ",!s&&this.options.useColors&&(this.options.showTimestamp&&(n="%c"),this.options.showLevel&&(r="%c"),i="%c",o=": %c");let c="";return this.options.showTimestamp&&(c+=(new Date).toISOString()+" "),c=n+c,this.options.showLevel&&(c+=r+"["+t+"]"+(t===a.INFO||t===a.WARN?" ":"")+" "),c+=i+this.category,c+=o+e}_shouldLog(t){let n=void 0!==e&&void 0!==Object({NODE_ENV:void 0})&&void 0!==Object({NODE_ENV:void 0}).LOG?Object({NODE_ENV:void 0}).LOG.toUpperCase():null;const r=(n="undefined"!=typeof window&&window.LOG?window.LOG.toUpperCase():n)||c,i=Object.keys(a).map(t=>a[t]);return i.indexOf(t)>=i.indexOf(r)}}t.exports={Colors:h,LogLevels:a,setLogLevel:t=>{c=t},setLogfile:t=>{f=t},create:(t,e)=>{return new p(t,e)},forceBrowserMode:t=>s=!t,events:u}}).call(e,n(0))},function(t,e,n){"use strict";(function(e,r){const i=n(12),o=n(34),s=n(155),a=n(157),c=n(159),f=n(163),u=n(165),h=n(43),d=n(49),l=n(174),p=n(176),b=n(60),y=b.create("orbit-db");b.setLogLevel("NONE");const m=["eventlog","feed","docstore","counter","keyvalue"];class g{constructor(t,e,n={}){this._ipfs=t,this.id=n.peerId||(this._ipfs._peerInfo?this._ipfs._peerInfo.id._idB58String:"default"),this._pubsub=n&&n.broker?new n.broker(this._ipfs):new u(this._ipfs,this.id),this.stores={},this.types=m,this.directory=e||"./orbitdb",this.keystore=new d(i.join(this.directory,this.id,"/keystore")),this.key=this.keystore.getKey(this.id)||this.keystore.createKey(this.id)}async feed(t,e={}){return e=Object.assign({create:!0,type:"feed"},e),this.open(t,e)}async log(t,e){return e=Object.assign({create:!0,type:"eventlog"},e),this.open(t,e)}async eventlog(t,e={}){return this.log(t,e)}async keyvalue(t,e){return e=Object.assign({create:!0,type:"keyvalue"},e),this.open(t,e)}async kvstore(t,e){return this.keyvalue(t,e)}async counter(t,e={}){return e=Object.assign({create:!0,type:"counter"},e),this.open(t,e)}async docs(t,e={}){return e=Object.assign({create:!0,type:"docstore"},e),this.open(t,e)}async docstore(t,e={}){return this.docs(t,e)}async disconnect(){const t=Object.values(this.stores);for(let e of t)await e.close(),delete this.stores[e.address.toString()];this._pubsub&&this._pubsub.disconnect(),this.stores={}}async stop(){await this.disconnect()}async _createStore(t,e,n){const r=e.toString();let i;n.accessControllerAddress&&(i=new l(this._ipfs),await i.load(n.accessControllerAddress));const o=Object.assign({replicate:!0},n,{accessController:i,keystore:this.keystore,cache:this._cache}),s=new t(this._ipfs,this.id,e,o);return s.events.on("write",this._onWrite.bind(this)),s.events.on("closed",this._onClosed.bind(this)),this.stores[r]=s,o.replicate&&this._pubsub&&this._pubsub.subscribe(r,this._onMessage.bind(this),this._onPeerConnected.bind(this)),s}_onWrite(t,n,r){if(!r)throw new Error("'heads' not defined");this._pubsub&&e(()=>this._pubsub.publish(t,r))}async _onMessage(t,e){const n=this.stores[t];try{y.debug(`Received heads for '${t}':\n`,JSON.stringify(e,null,2)),await n.sync(e)}catch(t){y.error(t)}}_onPeerConnected(t,e,n){y.debug(`New peer '${e}' connected to '${t}'`);const i=this.stores[t];if(i){let t=i._oplog.heads;t.length>0&&(y.debug("Send latest heads:\n",JSON.stringify(t,null,2)),n.sendTo(e,new r(JSON.stringify(t)))),i.events.emit("peer",e)}}_onClosed(t){y.debug(`Database '${t}' was closed`),this.stores[t].events.removeAllListeners("closed"),this._pubsub&&this._pubsub.unsubscribe(t),delete this.stores[t]}async create(t,e,n={}){if(!g.isValidType(e))throw new Error(`Invalid database type '${e}'`);const o=n.directory||this.directory;if(y.debug(`Creating database '${t}' as ${e} in '${o}'`),p.isValid(t))throw new Error("Given database name is an address. Please give only the name of the database!");const s=new l(this._ipfs);n&&n.write?n.write.forEach(t=>s.add("write",t)):s.add("write",this.key.getPublic("hex"));const a=await s.save(),c={name:t,type:e,accessController:i.join("/ipfs",a)},f=(await this._ipfs.object.put(new r(JSON.stringify(c)))).toJSON().multihash.toString(),u=i.join("/orbitdb",f,t),d=p.parse(u);try{const t=i.join(d.root,d.path);this._cache=new h(i.join(o),t),await this._cache.load()}catch(t){y.warn("Couldn't load Cache:",t)}let b=await this._cache.get(d.toString());if(b&&b.manifest&&!n.overwrite)throw new Error(`Database '${d}' already exists!`);return b=Object.assign({},this._cache.get(d.toString()),{manifest:d.root}),await this._cache.set(d.toString(),b),y.debug(`Saved manifest to IPFS as '${d.root}'`),y.debug(`Created database '${d}'`),this.open(d,n)}async open(t,e={}){e=Object.assign({localOnly:!1,create:!1},e),y.debug(`Open database '${t}'`);const n=e.directory||this.directory;if(y.debug(`Look from '${n}'`),!p.isValid(t)){if(e.create){if(e.create&&!e.type)throw new Error(`Database type not provided! Provide a type with 'options.type' (${m.join("|")})`);return y.warn(`Not a valid OrbitDB address '${t}', creating the database`),e.overwrite=!e.overwrite||e.overwrite,this.create(t,e.type,e)}throw new Error("'options.create' set to 'false'. If you want to create a database, set 'options.create' to 'true'.")}const r=p.parse(t);try{const t=i.join(r.root,r.path);this._cache=new h(i.join(n),t),await this._cache.load()}catch(t){console.warn(t),y.warn("Couldn't load Cache:",t)}let o=await this._cache.get(r.toString());const s=o&&o.manifest;if(y.debug((s?"Found":"Didn't find")+` database '${r}'`),e.localOnly&&!s)throw y.error(`Database '${r}' doesn't exist!`),new Error(`Database '${r}' doesn't exist!`);y.debug(`Loading Manifest for '${r}'`);const a=await this._ipfs.object.get(r.root),c=JSON.parse(a.toJSON().data);if(y.debug(`Manifest for '${r}':\n${JSON.stringify(c,null,2)}`),e.type&&c.type!==e.type)throw new Error(`Database '${r}' is type '${c.type}' but was opened as '${e.type}'`);return o=Object.assign({},this._cache.get(r.toString()),{manifest:r.root}),await this._cache.set(r.toString(),o),y.debug(`Saved manifest to IPFS as '${r.root}'`),e=Object.assign({},e,{accessControllerAddress:c.accessController}),this._openDatabase(r,c.type,e)}async _openDatabase(t,e,n){if("counter"===e)return this._createStore(c,t,n);if("eventlog"===e)return this._createStore(o,t,n);if("feed"===e)return this._createStore(s,t,n);if("docstore"===e)return this._createStore(f,t,n);if("keyvalue"===e)return this._createStore(a,t,n);throw new Error(`Invalid database type '${e}'`)}static isValidType(t){return m.includes(t)}static create(){return new Error("Not implemented yet!")}static open(){return new Error("Not implemented yet!")}}t.exports=g}).call(e,n(11).setImmediate,n(1).Buffer)},function(t,e,n){(function(t,e){!function(t,n){"use strict";function r(t){delete a[t]}function i(t){if(c)setTimeout(i,0,t);else{var e=a[t];if(e){c=!0;try{!function(t){var e=t.callback,r=t.args;switch(r.length){case 0:e();break;case 1:e(r[0]);break;case 2:e(r[0],r[1]);break;case 3:e(r[0],r[1],r[2]);break;default:e.apply(n,r)}}(e)}finally{r(t),c=!1}}}}if(!t.setImmediate){var o,s=1,a={},c=!1,f=t.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(t);u=u&&u.setTimeout?u:t,"[object process]"==={}.toString.call(t.process)?o=function(t){e.nextTick(function(){i(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,n=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=n,e}}()?function(){var e="setImmediate$"+Math.random()+"$",n=function(n){n.source===t&&"string"==typeof n.data&&0===n.data.indexOf(e)&&i(+n.data.slice(e.length))};t.addEventListener?t.addEventListener("message",n,!1):t.attachEvent("onmessage",n),o=function(n){t.postMessage(e+n,"*")}}():t.MessageChannel?function(){var t=new MessageChannel;t.port1.onmessage=function(t){i(t.data)},o=function(e){t.port2.postMessage(e)}}():f&&"onreadystatechange"in f.createElement("script")?function(){var t=f.documentElement;o=function(e){var n=f.createElement("script");n.onreadystatechange=function(){i(e),n.onreadystatechange=null,t.removeChild(n),n=null},t.appendChild(n)}}():o=function(t){setTimeout(i,0,t)},u.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;n0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function i(t){return s[t>>18&63]+s[t>>12&63]+s[t>>6&63]+s[63&t]}function o(t,e,n){for(var r,o=[],s=e;s0?f-4:f;var u=0;for(e=0;e>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=a[t.charCodeAt(e)]<<2|a[t.charCodeAt(e+1)]>>4,s[u++]=255&i):1===o&&(i=a[t.charCodeAt(e)]<<10|a[t.charCodeAt(e+1)]<<4|a[t.charCodeAt(e+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s},e.fromByteArray=function(t){for(var e,n=t.length,r=n%3,i="",a=[],c=0,f=n-r;cf?f:c+16383));return 1===r?(e=t[n-1],i+=s[e>>2],i+=s[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=s[e>>10],i+=s[e>>4&63],i+=s[e<<2&63],i+="="),a.push(i),a.join("")};for(var s=[],a=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,h=f.length;u>1,u=-7,h=n?i-1:0,d=n?-1:1,l=t[e+h];for(h+=d,o=l&(1<<-u)-1,l>>=-u,u+=a;u>0;o=256*o+t[e+h],h+=d,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=r;u>0;s=256*s+t[e+h],h+=d,u-=8);if(0===o)o=1-f;else{if(o===c)return s?NaN:1/0*(l?-1:1);s+=Math.pow(2,r),o-=f}return(l?-1:1)*s*Math.pow(2,o-r)},e.write=function(t,e,n,r,i,o){var s,a,c,f=8*o-i-1,u=(1<>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=r?0:o-1,p=r?1:-1,b=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=u):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),(e+=s+h>=1?d/c:d*Math.pow(2,1-h))*c>=2&&(s++,c/=2),s+h>=u?(a=0,s=u):s+h>=1?(a=(e*c-1)*Math.pow(2,i),s+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;t[n+l]=255&a,l+=p,a/=256,i-=8);for(s=s<0;t[n+l]=255&s,l+=p,s/=256,f-=8);t[n+l-p]|=128*b}},function(t,e){},function(t,e,n){"use strict";function r(t,e,n){t.copy(e,n)}var i=n(10).Buffer;t.exports=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null,this.length=0}return t.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,n=""+e.data;e=e.next;)n+=t+e.data;return n},t.prototype.concat=function(t){if(0===this.length)return i.alloc(0);if(1===this.length)return this.head.data;for(var e=i.allocUnsafe(t>>>0),n=this.head,o=0;n;)r(n.data,e,o),o+=n.data.length,n=n.next;return e},t}()},function(t,e,n){(function(e){function n(t){try{if(!e.localStorage)return!1}catch(t){return!1}var n=e.localStorage[t];return null!=n&&"true"===String(n).toLowerCase()}t.exports=function(t,e){if(n("noDeprecation"))return t;var r=!1;return function(){if(!r){if(n("throwDeprecation"))throw new Error(e);n("traceDeprecation")?console.trace(e):console.warn(e),r=!0}return t.apply(this,arguments)}}}).call(e,n(3))},function(t,e,n){"use strict";function r(t){if(!(this instanceof r))return new r(t);i.call(this,t)}t.exports=r;var i=n(39),o=n(14);o.inherits=n(5),o.inherits(r,i),r.prototype._transform=function(t,e,n){n(null,t)}},function(t,e,n){"use strict";const r=n(70);t.exports=((t,e)=>r(t,(t,n,r)=>e(n,r)).then(()=>t))},function(t,e,n){"use strict";t.exports=((t,e,n)=>new Promise((r,i)=>{const o=t[Symbol.iterator]();let s=0;const a=t=>{const n=o.next();n.done?r(t):Promise.all([t,n.value]).then(t=>{a(e(t[0],t[1],s++))}).catch(i)};a(n)}))},function(t,e,n){"use strict";class r{constuctor(t){}append(t){}merge(t){}get(t){}has(t){}get values(){}get length(){}}t.exports=r},function(t,e,n){"use strict";n(21);const r=n(26),i=n(73),o=n(27),s=n(41),a=n(28),c=n(42),f=n(75),u=n(76);class h{static toMultihash(t,e){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw s.LogNotDefinedError();if(e.values.length<1)throw new Error("Can't serialize an empty log");return t.object.put(e.toBuffer()).then(t=>t.toJSON().multihash)}static fromMultihash(t,e,n=-1,c,f){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw new Error(`Invalid hash: ${e}`);return t.object.get(e,{enc:"base58"}).then(t=>JSON.parse(t.toJSON().data)).then(e=>{if(!e.heads||!e.id)throw s.NotALogError();return i.fetchAll(t,e.heads,n,c,null,f).then(t=>{const n=t.reduce((t,e)=>e.clock.time>t.time?new o(e.clock.id,e.clock.time):t,new o(e.id)),i=t.slice().sort(r.compare),s=i.filter(t=>e.heads.includes(t.hash));return{id:e.id,values:i,heads:s,clock:n}})})}static fromEntryHash(t,e,n,r=-1,o,c){if(!a(t))throw s.IpfsNotDefinedError();if(!a(e))throw new Error("'entryHash' must be defined");r=r>-1?Math.max(r,1):r;const f=o;return i.fetchParallel(t,[e],r,f,null,null,c).then(t=>{return{values:r>-1?((t,e)=>t.slice(t.length-e,t.length))(t,r):t}})}static fromJSON(t,e,n=-1,o,c,f){if(!a(t))throw s.ImmutableDBNotDefinedError();return i.fetchParallel(t,e.heads.map(t=>t.hash),n,[],16,c,f).then(t=>{const n=t.slice().sort(r.compare);t.filter(t=>e.heads.includes(t.hash));return{id:e.id,values:n,heads:e.heads}})}static fromEntry(t,e,n=-1,o,f,h,d){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(e)&&!r.isEntry(e))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(e)||(e=[e]),n=n>-1?Math.max(n,e.length):n;const l=o?o.map(t=>t.hash?t.hash:t):o,p=e.map(t=>t.hash);return i.fetchParallel(t,p,n,l,null,null,d).then(t=>{var i=e.concat(t),o=c(i,"hash").sort(r.compare);const s=o.slice(n>-1?-n:-o.length),a=((t,e)=>{var n=t.slice(e.length,t.length);return e.concat(n)})(s,u(s,e,"hash"));return{id:a[a.length-1].id,values:a}})}static expandFrom(t,e,n,r=-1){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw s.LogNotDefinedError();if(!a(n))throw new Error("'entries' must be given as argument");Array.isArray(n)||(n=[n]);const o=n.map(t=>t.next).filter(t=>t.length>0);return 0===o.length?Promise.resolve({values:e.values}):i.fetchParallel(t,o,r,e.values).then(t=>{return{values:e.merge(t.slice(0,r))}})}static expand(t,e,n=-1){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw s.LogNotDefinedError();return 0===e.tailHashes.length?Promise.resolve({values:e.values}):i.fetchParallel(t,e.tailHashes,n,e.values).then(t=>{const i=n>-1?e.values.length+n:-1,o=e.values.concat(t).sort(r.compare),s=i>-1?o.slice(-i):o.slice(),a=u(s,e.values,"hash").sort(r.compare),h=u(e.values,s,"hash").sort(r.compare),d=f(e.values,s,"hash").sort(r.compare),l=i-(d.length+a.length),p=(t,e)=>{var n=[];n=t.concat(e);return c(n,"hash").sort(r.compare)};return{values:p(a,p(d,l>-1?h.slice(-l):h))}})}}t.exports=h},function(t,e,n){"use strict";const r=n(74),i=n(21),o=n(26);let s=0,a=0;class c{static fetchParallel(t,e,n,r=[],o,s,a){const f=(t,e)=>t.concat(e);return i(e,e=>c.fetchAll(t,e,n,r,s,a),{concurrency:Math.max(o||e.length,1)}).then(t=>t.reduce(f,[]))}static fetchAll(t,e,n,i=[],c=null,f){let u=[],h={},d=Array.isArray(e)?e.slice():[e];const l=t=>d.push(t);i.forEach(t=>h[t.hash]=t);return r(()=>d.length>0&&(u.length{const e=d.shift();return h[e]?Promise.resolve():new Promise((n,r)=>{const i=c?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${e}', request timed out (${c}ms)`),n()},c):null;s++,o.fromMultihash(t,e).then(t=>{clearTimeout(i),o.isEntry(t)&&(t.next.forEach(l),u.push(t),h[e]=t,a++,f&&f(e,t,u.length))}).then(n).catch(t=>{n()})})}).then(()=>u)}}t.exports=c},function(t,e,n){"use strict";const r=t=>new Promise(e=>{e(t())});t.exports=((t,e)=>r(function n(){if(t())return r(e).then(n)}))},function(t,e,n){"use strict";t.exports=function(t,e,n){var r={},i={};return t.forEach(t=>i[n?t[n]:t]=!0),e.reduce((t,e)=>{var o=void 0!==i[n?e[n]:e],s=void 0!==r[n?e[n]:e];return o&&!s&&(t.push(e),r[n?e[n]:e]=!0),t},[])}},function(t,e,n){"use strict";t.exports=function(t,e,n){var r={},i={};return t.forEach(t=>i[n?t[n]:t]=!0),e.reduce((t,e)=>{var o=void 0!==i[n?e[n]:e],s=void 0!==r[n?e[n]:e];return o||s||(t.push(e),r[n?e[n]:e]=!0),t},[])}},function(t,e,n){"use strict";t.exports={keys:n(78),once:n(45),values:n(29),count:n(79),infinite:n(80),empty:n(81),error:n(82)}},function(t,e,n){"use strict";var r=n(29);t.exports=function(t){return r(Object.keys(t))}},function(t,e,n){"use strict";t.exports=function(t){var e=0;return t=t||1/0,function(n,r){return n?r&&r(n):e>t?r(!0):void r(null,e++)}}},function(t,e,n){"use strict";t.exports=function(t){return t=t||Math.random,function(e,n){return e?n&&n(e):n(null,t())}}},function(t,e,n){"use strict";t.exports=function(){return function(t,e){e(!0)}}},function(t,e,n){"use strict";t.exports=function(t){return function(e,n){n(t)}}},function(t,e,n){"use strict";t.exports={drain:n(15),onEnd:n(84),log:n(85),find:n(86),reduce:n(30),collect:n(87),concat:n(88)}},function(t,e,n){"use strict";var r=n(15);t.exports=function(t){return r(null,t)}},function(t,e,n){"use strict";var r=n(15);t.exports=function(t){return r(function(t){console.log(t)},t)}},function(t,e,n){"use strict";function r(t){return t}var i=n(16),o=n(15);t.exports=function(t,e){var n=!1;return e?t=i(t)||r:(e=t,t=r),o(function(r){if(t(r))return n=!0,e(null,r),!1},function(t){n||e(!0===t?null:t,null)})}},function(t,e,n){"use strict";var r=n(30);t.exports=function(t){return r(function(t,e){return t.push(e),t},[],t)}},function(t,e,n){"use strict";var r=n(30);t.exports=function(t){return r(function(t,e){return t+e},"",t)}},function(t,e,n){"use strict";t.exports={map:n(90),asyncMap:n(91),filter:n(31),filterNot:n(92),through:n(93),take:n(94),unique:n(47),nonUnique:n(95),flatten:n(96)}},function(t,e,n){"use strict";function r(t){return t}var i=n(16);t.exports=function(t){return t?(t=i(t),function(e){return function(n,r){e(n,function(n,i){try{i=n?null:t(i)}catch(t){return e(t,function(){return r(t)})}r(n,i)})}}):r}},function(t,e,n){"use strict";function r(t){return t}var i=n(16);t.exports=function(t){if(!t)return r;t=i(t);var e,n,o=!1;return function(r){return function i(s,a){if(n)return a(n);s?(n=s,o?r(s,function(){o?e=a:a(s)}):r(s,a)):r(null,function(r,s){r?a(r):n?a(n):(o=!0,t(s,function(t,r){o=!1,n?(a(n),e(n)):t?i(t,a):a(null,r)}))})}}}},function(t,e,n){"use strict";var r=n(46),i=n(31);t.exports=function(t){return t=r(t),i(function(e){return!t(e)})}},function(t,e,n){"use strict";t.exports=function(t,e){function n(t){!r&&e&&(r=!0,e(!0===t?null:t))}var r=!1;return function(e){return function(r,i){return r&&n(r),e(r,function(e,r){e?n(e):t&&t(r),i(e,r)})}}}},function(t,e,n){"use strict";t.exports=function(t,e){var n=(e=e||{}).last||!1,r=!1;if("number"==typeof t){n=!0;var i=t;t=function(){return--i}}return function(e){function i(t){e(!0,function(e){n=!1,t(e||!0)})}return function(o,s){r?n?i(s):s(r):(r=o)?e(r,s):e(null,function(e,o){(r=r||e)?s(r):t(o)?s(null,o):(r=!0,n?s(null,o):i(s))})}}}},function(t,e,n){"use strict";var r=n(47);t.exports=function(t){return r(t,!0)}},function(t,e,n){"use strict";var r=n(29),i=n(45);t.exports=function(){return function(t){var e;return function(n,o){function s(){e(null,function(e,n){!0===e?a():e?t(!0,function(t){o(e)}):o(null,n)})}function a(){e=null,t(null,function(t,n){if(t)return o(t);Array.isArray(n)||n&&"object"==typeof n?n=r(n):"function"!=typeof n&&(n=i(n)),e=n,s()})}n?e?e(n,function(e){t(e||n,o)}):t(n,o):e?s():a()}}}},function(t,e,n){"use strict";t.exports=function t(e){var n=arguments.length;if("function"==typeof e&&1===e.length){for(var r=new Array(n),i=0;i99?t.push(e.concat(n)):t[r(t)]=e.concat(i(t).concat(n)),t},100,n)))}),a):(n(new Error("Missing key")),a)}},{key:"read",value:function(t){var e=this,n=f();return t?(this.exists(t,function(r,i){return r?n.end(r):i?void e.table.where("key").equals(t).each(function(t){return n.push(u(t.blob))}).catch(function(t){return n.end(t)}).then(function(){return n.end()}):n.end(new Error("Not found"))}),n):(n.end(new Error("Missing key")),n)}},{key:"exists",value:function(t,e){if(e=e||function(){},!t)return e(new Error("Missing key"));this.table.where("key").equals(t).count().then(function(t){return e(null,Boolean(t))}).catch(e)}},{key:"remove",value:function(t,e){if(e=e||function(){},!t)return e(new Error("Missing key"));var n=this.table.where("key").equals(t);n.count(function(t){return t>0?n.delete():null}).then(function(){return e()}).catch(e)}},{key:"table",get:function(){return this.db[this.path]}}]),t}()}).call(e,n(1).Buffer)},function(t,e,n){(function(e,n){!function(e,n){t.exports=n()}(0,function(){"use strict";function t(t,e){return"object"!=typeof e?t:(gt(e).forEach(function(n){t[n]=e[n]}),t)}function r(t,e){return St.call(t,e)}function i(t,e){"function"==typeof e&&(e=e(wt(t))),gt(e).forEach(function(n){o(t,n,e[n])})}function o(e,n,i,o){Object.defineProperty(e,n,t(i&&r(i,"get")&&"function"==typeof i.get?{get:i.get,set:i.set,configurable:!0}:{value:i,configurable:!0,writable:!0},o))}function s(t){return{from:function(e){return t.prototype=Object.create(e.prototype),o(t.prototype,"constructor",t),{extend:i.bind(null,t.prototype)}}}}function a(t,e){var n;return kt(t,e)||(n=wt(t))&&a(n,e)}function c(t,e,n){return xt.call(t,e,n)}function f(t,e){return e(t)}function u(t){var e=setTimeout(t,1e3);clearTimeout(e)}function h(t){if(!t)throw new Error("Assertion Failed")}function d(t){_t.setImmediate?n(t):setTimeout(t,0)}function l(t,e){return t.reduce(function(t,n,r){var i=e(n,r);return i&&(t[i[0]]=i[1]),t},{})}function p(t,e){return function(){try{t.apply(this,arguments)}catch(t){e(t)}}}function b(t,e,n){try{t.apply(null,n)}catch(t){e&&e(t)}}function y(t,e){if(r(t,e))return t[e];if(!e)return t;if("string"!=typeof e){for(var n=[],i=0,o=e.length;i0;)for(t=Zt,Zt=[],n=t.length,e=0;e0);Ht=!0,Yt=!0}function X(){var t=Wt;Wt=[],t.forEach(function(t){t._PSD.onunhandled.call(null,t._value,t)});for(var e=te.slice(0),n=e.length;n;)e[--n]()}function Z(t){return new F(qt,!1,t)}function Q(t,e){var n=Xt;return function(){var r=$(),i=Xt;try{return i!==n&&(Xt=n),t.apply(this,arguments)}catch(t){e&&e(t)}finally{i!==n&&(Xt=i),r&&V()}}}function tt(t,e,n,r){var i=Xt,o=Object.create(i);o.parent=i,o.ref=0,o.global=!1,++i.ref,o.finalize=function(){--this.parent.ref||this.parent.finalize()};var s=et(o,t,e,n,r);return 0===o.ref&&o.finalize(),s}function et(t,e,n,r,i){var o=Xt;try{return t!==o&&(Xt=t),e(n,r,i)}finally{t!==o&&(Xt=o)}}function nt(e,n){var r;try{r=n.onuncatched(e)}catch(t){}if(!1!==r)try{var i,o={promise:n,reason:e};if(_t.document&&document.createEvent?((i=document.createEvent("Event")).initEvent(ne,!0,!0),t(i,o)):_t.CustomEvent&&t(i=new CustomEvent(ne,{detail:o}),o),i&&_t.dispatchEvent&&(dispatchEvent(i),!_t.PromiseRejectionEvent&&_t.onunhandledrejection))try{_t.onunhandledrejection(i)}catch(t){}i.defaultPrevented||F.on.error.fire(e,n)}catch(t){}}function rt(t,e){var n=F.reject(t);return e?n.uncaught(e):n}function it(e,n){function a(t){this._cfg={version:t,storesSource:null,dbschema:{},tables:{},contentUpgrade:null},this.stores({})}function d(t,e,n){var r=Ht._createTransaction(Gt,Lt,jt);r.create(e),r._completion.catch(n);var i=r._reject.bind(r);tt(function(){Xt.trans=r,0===t?(gt(jt).forEach(function(t){E(e,t,jt[t].primKey,jt[t].indexes)}),F.follow(function(){return Ht.on.populate.fire(r)}).catch(i)):function(t,e,n){function r(){return i.length?F.resolve(i.shift()(e.idbtrans)).then(r):F.resolve()}var i=[],o=Tt.filter(function(e){return e._cfg.version===t})[0];if(!o)throw new Dt.Upgrade("Dexie specification of currently installed DB version is missing");jt=Ht._dbSchema=o._cfg.dbschema;var s=!1;Tt.filter(function(e){return e._cfg.version>t}).forEach(function(t){i.push(function(){var r=jt,i=t._cfg.dbschema;_t(r,n),_t(i,n),jt=Ht._dbSchema=i;var o=function(t,e){var n={del:[],add:[],change:[]};for(var r in t)e[r]||n.del.push(r);for(r in e){var i=t[r],o=e[r];if(i){var s={name:r,def:o,recreate:!1,del:[],add:[],change:[]};if(i.primKey.src!==o.primKey.src)s.recreate=!0,n.change.push(s);else{var a=i.idxByName,c=o.idxByName;for(var f in a)c[f]||s.del.push(f);for(f in c){var u=a[f],h=c[f];u?u.src!==h.src&&s.change.push(h):s.add.push(h)}(s.del.length>0||s.add.length>0||s.change.length>0)&&n.change.push(s)}}else n.add.push([r,o])}return n}(r,i);if(o.add.forEach(function(t){E(n,t[0],t[1].primKey,t[1].indexes)}),o.change.forEach(function(t){if(t.recreate)throw new Dt.Upgrade("Not yet support for changing primary key");var e=n.objectStore(t.name);t.add.forEach(function(t){I(e,t)}),t.change.forEach(function(t){e.deleteIndex(t.name),I(e,t)}),t.del.forEach(function(t){e.deleteIndex(t)})}),t._cfg.contentUpgrade)return s=!0,F.follow(function(){t._cfg.contentUpgrade(e)})}),i.push(function(e){if(!s||!fe){!function(t,e){for(var n=0;n0&&(Jt=!1),!Nt)throw new Dt.MissingAPI("indexedDB API not found. If using IE10+, make sure to run your code on a server URL (not locally). If using old Safari versions, make sure to include indexedDB polyfill.");var i=Jt?Nt.open(e):Nt.open(e,Math.round(10*Ht.verno));if(!i)throw new Dt.MissingAPI("IndexedDB API not available");i.onerror=Q(ft(r)),i.onblocked=Q(wt),i.onupgradeneeded=Q(function(t){if(n=i.transaction,Jt&&!Ht._allowEmptyDB){i.onerror=ht,n.abort(),i.result.close();var o=Nt.deleteDatabase(e);o.onsuccess=o.onerror=Q(function(){r(new Dt.NoSuchDatabase("Database "+e+" doesnt exist"))})}else{n.onerror=Q(ft(r));d((t.oldVersion>Math.pow(2,62)?0:t.oldVersion)/10,n,r)}},r),i.onsuccess=Q(function(){if(n=null,Ft=i.result,ae.push(Ht),Jt)!function(){if(Ht.verno=Ft.version/10,Ht._dbSchema=jt={},0!==(Lt=c(Ft.objectStoreNames,0)).length){var t=Ft.transaction(yt(Lt),"readonly");Lt.forEach(function(e){for(var n=t.objectStore(e),r=n.keyPath,i=r&&"string"==typeof r&&-1!==r.indexOf("."),o=new pt(r,r||"",!1,!1,!!n.autoIncrement,r&&"string"!=typeof r,i),s=[],a=0;a0)try{_t(jt,Ft.transaction(yt(Ft.objectStoreNames),Kt))}catch(t){}Ft.onversionchange=Q(function(t){Ht._vcFired=!0,Ht.on("versionchange").fire(t)}),$t||dt(function(t){if(-1===t.indexOf(e))return t.push(e)}),t()},r)})]).then(function(){return it.vip(Ht.on.ready.fire)}).then(function(){return Ut=!1,Ht}).catch(function(t){try{n&&n.abort()}catch(t){}return Ut=!1,Ht.close(),qt=t,rt(qt,C)}).finally(function(){zt=!0,t()})},this.close=function(){var t=ae.indexOf(Ht);if(t>=0&&ae.splice(t,1),Ft){try{Ft.close()}catch(t){}Ft=null}Ct=!1,qt=new Dt.DatabaseClosed,Ut&&kt(qt),Yt=new F(function(t){St=t}),Wt=new F(function(t,e){kt=e})},this.delete=function(){var t=arguments.length>0;return new F(function(n,r){function i(){Ht.close();var t=Nt.deleteDatabase(e);t.onsuccess=Q(function(){$t||dt(function(t){var n=t.indexOf(e);if(n>=0)return t.splice(n,1)}),n()}),t.onerror=Q(ft(r)),t.onblocked=wt}if(t)throw new Dt.InvalidArgument("Arguments not allowed in db.delete()");Ut?Yt.then(i):i()}).uncaught(C)},this.backendDB=function(){return Ft},this.isOpen=function(){return null!==Ft},this.hasFailed=function(){return null!==qt},this.dynamicallyOpened=function(){return Jt},this.name=e,o(this,"tables",{get:function(){return gt(Bt).map(function(t){return Bt[t]})}}),this.on=B(this,"error","populate","blocked","versionchange",{ready:[P,S]}),this.on.error.subscribe=j("Dexie.on.error",this.on.error.subscribe),this.on.error.unsubscribe=j("Dexie.on.error.unsubscribe",this.on.error.unsubscribe),this.on.ready.subscribe=f(this.on.ready.subscribe,function(t){return function(e,n){it.vip(function(){zt?(qt||F.resolve().then(e),n&&t(e)):(t(e),n||t(function t(){Ht.on.ready.unsubscribe(e),Ht.on.ready.unsubscribe(t)}))})}}),de(function(){Ht.on("populate").fire(Ht._createTransaction(Gt,Lt,jt)),Ht.on("error").fire(new Error)}),this.transaction=function(t,e,n){function i(e){var i=Xt;e(F.resolve().then(function(){return tt(function(){Xt.transless=Xt.transless||i;var e=Ht._createTransaction(t,u,jt,c);Xt.trans=e,c?e.idbtrans=c.idbtrans:e.create();var o=u.map(function(t){return Bt[t]});o.push(e);var s;return F.follow(function(){if(s=n.apply(e,o))if("function"==typeof s.next&&"function"==typeof s.throw)s=lt(s);else if("function"==typeof s.then&&!r(s,"_PSD"))throw new Dt.IncompatiblePromise("Incompatible Promise returned from transaction scope (read more at http://tinyurl.com/znyqjqc). Transaction scope: "+n.toString())}).uncaught(C).then(function(){return c&&e._resolve(),e._completion}).then(function(){return s}).catch(function(t){return e._reject(t),rt(t)})})}))}var o=arguments.length;if(o<2)throw new Dt.InvalidArgument("Too few arguments");for(var s=new Array(o-1);--o;)s[o-1]=arguments[o];n=s.pop();var a=function(t){return Ot.apply([],t)}(s),c=Xt.trans;c&&c.db===Ht&&-1===t.indexOf("!")||(c=null);var f=-1!==t.indexOf("?");t=t.replace("!","").replace("?","");try{var u=a.map(function(t){var e=t instanceof T?t.name:t;if("string"!=typeof e)throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return e});if("r"==t||t==Kt)t=Kt;else{if("rw"!=t&&t!=Gt)throw new Dt.InvalidArgument("Invalid transaction mode: "+t);t=Gt}if(c){if(c.mode===Kt&&t===Gt){if(!f)throw new Dt.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");c=null}c&&u.forEach(function(t){if(c&&-1===c.storeNames.indexOf(t)){if(!f)throw new Dt.SubTransaction("Table "+t+" not included in parent transaction.");c=null}})}}catch(t){return c?c._promise(null,function(e,n){n(t)}):rt(t,C)}return c?c._promise(t,i,"lock"):Ht._whenReady(i)},this.table=function(t){if(le&&Jt)return new q(t);if(!r(Bt,t))throw new Dt.InvalidTable("Table "+t+" does not exist");return Bt[t]},i(T.prototype,{_trans:function(t,e,n){var r=Xt.trans;return r&&r.db===Ht?r._promise(t,e,n):R(t,[this.name],e)},_idbstore:function(t,e,n){function r(t,n,r){e(t,n,r.idbtrans.objectStore(o),r)}if(le)return new F(e);var i=Xt.trans,o=this.name;return i&&i.db===Ht?i._promise(t,r,n):R(t,[this.name],r)},get:function(t,e){var n=this;return this._idbstore(Kt,function(e,r,i){le&&e(n.schema.instanceTemplate);var o=i.get(t);o.onerror=ft(r),o.onsuccess=Q(function(){e(n.hook.reading.fire(o.result))},r)}).then(e)},where:function(t){return new G(this,t)},count:function(t){return this.toCollection().count(t)},offset:function(t){return this.toCollection().offset(t)},limit:function(t){return this.toCollection().limit(t)},reverse:function(){return this.toCollection().reverse()},filter:function(t){return this.toCollection().and(t)},each:function(t){return this.toCollection().each(t)},toArray:function(t){return this.toCollection().toArray(t)},orderBy:function(t){return new this._collClass(new G(this,t))},toCollection:function(){return new this._collClass(new G(this))},mapToClass:function(t,e){this.schema.mappedClass=t;var n=Object.create(t.prototype);e&&st(n,e),this.schema.instanceTemplate=n;var i=function(e){if(!e)return e;var n=Object.create(t.prototype);for(var i in e)if(r(e,i))try{n[i]=e[i]}catch(t){}return n};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=i,this.hook("reading",i),t},defineClass:function(t){return this.mapToClass(it.defineClass(t),t)}}),s(q).from(T).extend({bulkDelete:function(t){return this.hook.deleting.fire===S?this._idbstore(Gt,function(e,n,r,i){e(z(r,i,t,!1,S))}):this.where(":id").anyOf(t).delete().then(function(){})},bulkPut:function(t,e){var n=this;return this._idbstore(Gt,function(r,i,o){if(!o.keyPath&&!n.schema.primKey.auto&&!e)throw new Dt.InvalidArgument("bulkPut() with non-inbound keys requires keys array in second argument");if(o.keyPath&&e)throw new Dt.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(e&&e.length!==t.length)throw new Dt.InvalidArgument("Arguments objects and keys must have the same length");if(0===t.length)return r();var s,a,c=function(t){0===f.length?r(t):i(new D(n.name+".bulkPut(): "+f.length+" of "+u+" operations failed",f))},f=[],u=t.length,h=n;if(n.hook.creating.fire===S&&n.hook.updating.fire===S){a=U(f);for(var d=0,p=t.length;d=0;--i){var o=b[i];(null==o||m[o])&&(n.push(t[i]),e&&r.push(o),null!=o&&(m[o]=null))}return n.reverse(),e&&r.reverse(),h.bulkAdd(n,r)}).then(function(t){var e=b[b.length-1];return null!=e?e:t}):h.bulkAdd(t)).then(c).catch(D,function(t){f=f.concat(t.failures),c()}).catch(i)}},"locked")},bulkAdd:function(t,e){var n=this,r=this.hook.creating.fire;return this._idbstore(Gt,function(i,o,s,a){function c(t){0===d.length?i(t):o(new D(n.name+".bulkAdd(): "+d.length+" of "+l+" operations failed",d))}if(!s.keyPath&&!n.schema.primKey.auto&&!e)throw new Dt.InvalidArgument("bulkAdd() with non-inbound keys requires keys array in second argument");if(s.keyPath&&e)throw new Dt.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(e&&e.length!==t.length)throw new Dt.InvalidArgument("Arguments objects and keys must have the same length");if(0===t.length)return i();var f,u,h,d=[],l=t.length;if(r!==S){var p,g=s.keyPath;u=U(d,null,!0),h=ct(null),b(function(){for(var n=0,i=t.length;n0&&!this._locked();){var t=this._blockedFuncs.shift();try{et(t[1],t[0])}catch(t){}}return this},_locked:function(){return this._reculock&&Xt.lockOwnerFor!==this},create:function(t){var e=this;if(h(!this.idbtrans),!t&&!Ft)switch(qt&&qt.name){case"DatabaseClosedError":throw new Dt.DatabaseClosed(qt);case"MissingAPIError":throw new Dt.MissingAPI(qt.message,qt);default:throw new Dt.OpenFailed(qt)}if(!this.active)throw new Dt.TransactionInactive;return h(null===this._completion._state),t=this.idbtrans=t||Ft.transaction(yt(this.storeNames),this.mode),t.onerror=Q(function(n){ht(n),e._reject(t.error)}),t.onabort=Q(function(t){ht(t),e.active&&e._reject(new Dt.Abort),e.active=!1,e.on("abort").fire(t)}),t.oncomplete=Q(function(){e.active=!1,e._resolve()}),this},_promise:function(t,e,n){var r=this,i=r._locked()?new F(function(i,o){r._blockedFuncs.push([function(){r._promise(t,e,n).then(i,o)},Xt])}):tt(function(){var i=r.active?new F(function(i,o){if(t===Gt&&r.mode!==Gt)throw new Dt.ReadOnly("Transaction is readonly");!r.idbtrans&&t&&r.create(),n&&r._lock(),e(i,o,r)}):rt(new Dt.TransactionInactive);return r.active&&n&&i.finally(function(){r._unlock()}),i});return i._lib=!0,i.uncaught(C)},abort:function(){this.active&&this._reject(new Dt.Abort),this.active=!1},tables:{get:j("Transaction.tables",function(){return l(this.storeNames,function(t){return[t,Bt[t]]})})},complete:j("Transaction.complete()",function(t){return this.on("complete",t)}),error:j("Transaction.error()",function(t){return this.on("error",t)}),table:j("Transaction.table()",function(t){if(-1===this.storeNames.indexOf(t))throw new Dt.InvalidTable("Table "+t+" not in transaction");return Bt[t]})}),i(G.prototype,function(){function t(t,e,n){var r=t instanceof G?new t._ctx.collClass(t):t;return r._ctx.error=n?new n(e):new TypeError(e),r}function e(t){return new t._ctx.collClass(t,function(){return Rt.only("")}).limit(0)}function n(t,e,n,r,i,o){for(var s=Math.min(t.length,r.length),a=-1,c=0;c=0?t.substr(0,a)+e[a]+n.substr(a+1):null;i(t[c],f)<0&&(a=c)}return se?-1:t===e?0:1};var e=i.map(function(t){return{lower:c(t),upper:a(t)}}).sort(function(t,e){return f(t.lower,e.lower)});u=e.map(function(t){return t.upper}),h=e.map(function(t){return t.lower}),d=t,l="next"===t?"":o}var a,c,f,u,h,d,l,p=i.length;if(!i.every(function(t){return"string"==typeof t}))return t(e,se);s("next");var b=new e._ctx.collClass(e,function(){return Rt.bound(u[0],h[p-1]+o)});b._ondirectionchange=function(t){s(t)};var y=0;return b._addAlgorithm(function(t,e,i){var o=t.key;if("string"!=typeof o)return!1;var s=c(o);if(r(s,h,y))return!0;for(var a=null,b=y;b0)&&(a=m)}return e(null!==a?function(){t.continue(a+l)}:i),!1}),b}return{between:function(n,r,i,o){i=!1!==i,o=!0===o;try{return X(n,r)>0||0===X(n,r)&&(i||o)&&(!i||!o)?e(this):new this._ctx.collClass(this,function(){return Rt.bound(n,r,!i,!o)})}catch(e){return t(this,oe)}},equals:function(t){return new this._ctx.collClass(this,function(){return Rt.only(t)})},above:function(t){return new this._ctx.collClass(this,function(){return Rt.lowerBound(t,!0)})},aboveOrEqual:function(t){return new this._ctx.collClass(this,function(){return Rt.lowerBound(t)})},below:function(t){return new this._ctx.collClass(this,function(){return Rt.upperBound(t,!0)})},belowOrEqual:function(t){return new this._ctx.collClass(this,function(){return Rt.upperBound(t)})},startsWith:function(e){return"string"!=typeof e?t(this,se):this.between(e,e+re,!0,!0)},startsWithIgnoreCase:function(t){return""===t?this.startsWith(t):r(this,function(t,e){return 0===t.indexOf(e[0])},[t],re)},equalsIgnoreCase:function(t){return r(this,function(t,e){return t===e[0]},[t],"")},anyOfIgnoreCase:function(){var t=w.apply(At,arguments);return 0===t.length?e(this):r(this,function(t,e){return-1!==e.indexOf(t)},t,"")},startsWithAnyOfIgnoreCase:function(){var t=w.apply(At,arguments);return 0===t.length?e(this):r(this,function(t,e){return e.some(function(e){return 0===t.indexOf(e)})},t,re)},anyOf:function(){var n=w.apply(At,arguments),r=Z;try{n.sort(r)}catch(e){return t(this,oe)}if(0===n.length)return e(this);var i=new this._ctx.collClass(this,function(){return Rt.bound(n[0],n[n.length-1])});i._ondirectionchange=function(t){r="next"===t?Z:nt,n.sort(r)};var o=0;return i._addAlgorithm(function(t,e,i){for(var s=t.key;r(s,n[o])>0;)if(++o===n.length)return e(i),!1;return 0===r(s,n[o])||(e(function(){t.continue(n[o])}),!1)}),i},notEqual:function(t){return this.inAnyRange([[-1/0,t],[t,ie]],{includeLowers:!1,includeUppers:!1})},noneOf:function(){var e=w.apply(At,arguments);if(0===e.length)return new this._ctx.collClass(this);try{e.sort(Z)}catch(e){return t(this,oe)}var n=e.reduce(function(t,e){return t?t.concat([[t[t.length-1][1],e]]):[[-1/0,e]]},null);return n.push([e[e.length-1],ie]),this.inAnyRange(n,{includeLowers:!1,includeUppers:!1})},inAnyRange:function(n,r){function i(t,e){for(var n=0,r=t.length;n0){i[0]=function(t,e){return X(t,e)<0?t:e}(i[0],e[0]),i[1]=function(t,e){return X(t,e)>0?t:e}(i[1],e[1]);break}}return n===r&&t.push(e),t}function o(t,e){return u(t[0],e[0])}var s=this._ctx;if(0===n.length)return e(this);if(!n.every(function(t){return void 0!==t[0]&&void 0!==t[1]&&Z(t[0],t[1])<=0}))return t(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",Dt.InvalidArgument);var a,c=!r||!1!==r.includeLowers,f=r&&!0===r.includeUppers,u=Z;try{(a=n.reduce(i,[])).sort(o)}catch(e){return t(this,oe)}var h=0,d=f?function(t){return Z(t,a[h][1])>0}:function(t){return Z(t,a[h][1])>=0},l=c?function(t){return nt(t,a[h][0])>0}:function(t){return nt(t,a[h][0])>=0},p=d,b=new s.collClass(this,function(){return Rt.bound(a[0][0],a[a.length-1][1],!c,!f)});return b._ondirectionchange=function(t){"next"===t?(p=d,u=Z):(p=l,u=nt),a.sort(o)},b._addAlgorithm(function(t,e,n){for(var r=t.key;p(r);)if(++h===a.length)return e(n),!1;return!!function(t){return!d(t)&&!l(t)}(r)||0!==X(r,a[h][1])&&0!==X(r,a[h][0])&&(e(function(){u===Z?t.continue(a[h][0]):t.continue(a[h][1])}),!1)}),b},startsWithAnyOf:function(){var n=w.apply(At,arguments);return n.every(function(t){return"string"==typeof t})?0===n.length?e(this):this.inAnyRange(n.map(function(t){return[t,t+re]})):t(this,"startsWithAnyOf() only works with strings")}}}),i(H.prototype,function(){function e(t,e){t.filter=ot(t.filter,e)}function n(t,e,n){var r=t.replayFilter;t.replayFilter=r?function(){return ot(r(),e())}:e,t.justLimit=n&&!r}function i(t,e){if(t.isPrimKey)return e;var n=t.table.schema.idxByName[t.index];if(!n)throw new Dt.Schema("KeyPath "+t.index+" on object store "+e.name+" is not indexed");return e.index(n.name)}function o(t,e){var n=i(t,e);return t.keysOnly&&"openKeyCursor"in n?n.openKeyCursor(t.range||null,t.dir+t.unique):n.openCursor(t.range||null,t.dir+t.unique)}function s(t,e,n,i,s){var a=t.replayFilter?ot(t.filter,t.replayFilter()):t.filter;t.or?function(){function c(){2==++h&&n()}function f(t,n,o){if(!a||a(n,o,c,i)){var s=n.primaryKey.toString();r(u,s)||(u[s]=!0,e(t,n,o))}}var u={},h=0;t.or._iterate(f,c,i,s),V(o(t,s),t.algorithm,f,c,i,!t.keysOnly&&t.valueMapper)}():V(o(t,s),ot(t.algorithm,a),e,n,i,!t.keysOnly&&t.valueMapper)}function a(t){return t.table.schema.instanceTemplate}return{_read:function(t,e){var n=this._ctx;return n.error?n.table._trans(null,function(t,e){e(n.error)}):n.table._idbstore(Kt,t).then(e)},_write:function(t){var e=this._ctx;return e.error?e.table._trans(null,function(t,n){n(e.error)}):e.table._idbstore(Gt,t,"locked")},_addAlgorithm:function(t){var e=this._ctx;e.algorithm=ot(e.algorithm,t)},_iterate:function(t,e,n,r){return s(this._ctx,t,e,n,r)},clone:function(e){var n=Object.create(this.constructor.prototype),r=Object.create(this._ctx);return e&&t(r,e),n._ctx=r,n},raw:function(){return this._ctx.valueMapper=null,this},each:function(t){var e=this._ctx;if(le){var n=a(e),r=e.table.schema.primKey.keyPath,i=y(n,e.index?e.table.schema.idxByName[e.index].keyPath:r),o=y(n,r);t(n,{key:i,primaryKey:o})}return this._read(function(n,r,i){s(e,t,n,r,i)})},count:function(t){if(le)return F.resolve(0).then(t);var e=this._ctx;if(Y(e,!0))return this._read(function(t,n,r){var o=i(e,r),s=e.range?o.count(e.range):o.count();s.onerror=ft(n),s.onsuccess=function(n){t(Math.min(n.target.result,e.limit))}},t);var n=0;return this._read(function(t,r,i){s(e,function(){return++n,!1},function(){t(n)},r,i)},t)},sortBy:function(t,e){function n(t,e){return e?n(t[i[e]],e-1):t[o]}function r(t,e){var r=n(t,s),i=n(e,s);return ri?a:0}var i=t.split(".").reverse(),o=i[0],s=i.length-1,a="next"===this._ctx.dir?1:-1;return this.toArray(function(t){return t.sort(r)}).then(e)},toArray:function(t){var e=this._ctx;return this._read(function(t,n,r){if(le&&t([a(e)]),xt&&"next"===e.dir&&Y(e,!0)&&e.limit>0){var o=e.table.hook.reading.fire,c=i(e,r),f=e.limit<1/0?c.getAll(e.range,e.limit):c.getAll(e.range);f.onerror=ft(n),f.onsuccess=o===k?at(t):Q(at(function(e){try{t(e.map(o))}catch(t){n(t)}}))}else{var u=[];s(e,function(t){u.push(t)},function(){t(u)},n,r)}},t)},offset:function(t){var e=this._ctx;return t<=0?this:(e.offset+=t,Y(e)?n(e,function(){var e=t;return function(t,n){return 0===e||(1===e?(--e,!1):(n(function(){t.advance(e),e=0}),!1))}}):n(e,function(){var e=t;return function(){return--e<0}}),this)},limit:function(t){return this._ctx.limit=Math.min(this._ctx.limit,t),n(this._ctx,function(){var e=t;return function(t,n,r){return--e<=0&&n(r),e>=0}},!0),this},until:function(t,n){var r=this._ctx;return le&&t(a(r)),e(this._ctx,function(e,r,i){return!t(e.value)||(r(i),n)}),this},first:function(t){return this.limit(1).toArray(function(t){return t[0]}).then(t)},last:function(t){return this.reverse().first(t)},filter:function(t){return le&&t(a(this._ctx)),e(this._ctx,function(e){return t(e.value)}),function(t,e){t.isMatch=ot(t.isMatch,e)}(this._ctx,t),this},and:function(t){return this.filter(t)},or:function(t){return new G(this._ctx.table,t,this)},reverse:function(){return this._ctx.dir="prev"===this._ctx.dir?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},desc:function(){return this.reverse()},eachKey:function(t){var e=this._ctx;return e.keysOnly=!e.isMatch,this.each(function(e,n){t(n.key,n)})},eachUniqueKey:function(t){return this._ctx.unique="unique",this.eachKey(t)},eachPrimaryKey:function(t){var e=this._ctx;return e.keysOnly=!e.isMatch,this.each(function(e,n){t(n.primaryKey,n)})},keys:function(t){var e=this._ctx;e.keysOnly=!e.isMatch;var n=[];return this.each(function(t,e){n.push(e.key)}).then(function(){return n}).then(t)},primaryKeys:function(t){var e=this._ctx;if(xt&&"next"===e.dir&&Y(e,!0)&&e.limit>0)return this._read(function(t,n,r){var o=i(e,r),s=e.limit<1/0?o.getAllKeys(e.range,e.limit):o.getAllKeys(e.range);s.onerror=ft(n),s.onsuccess=at(t)}).then(t);e.keysOnly=!e.isMatch;var n=[];return this.each(function(t,e){n.push(e.primaryKey)}).then(function(){return n}).then(t)},uniqueKeys:function(t){return this._ctx.unique="unique",this.keys(t)},firstKey:function(t){return this.limit(1).keys(function(t){return t[0]}).then(t)},lastKey:function(t){return this.reverse().firstKey(t)},distinct:function(){var t=this._ctx,n=t.index&&t.table.schema.idxByName[t.index];if(!n||!n.multi)return this;var i={};return e(this._ctx,function(t){var e=t.primaryKey.toString(),n=r(i,e);return i[e]=!0,!n}),this}}}),s(W).from(H).extend({modify:function(e){var n=this,i=this._ctx,o=i.table.hook,s=o.updating.fire,a=o.deleting.fire;return le&&"function"==typeof e&&e.call({value:i.table.schema.instanceTemplate},i.table.schema.instanceTemplate),this._write(function(i,o,c,f){function u(t){return t&&(M.push(t),A.push(O)),o(new L("Error modifying one or more objects",M,x,A))}function h(){E&&x+M.length===k&&(M.length>0?u():i(x))}var d;if("function"==typeof e)d=s===S&&a===S?e:function(t){var n=v(t);if(!1===e.call(this,t,this))return!1;if(r(this,"value")){var i=_(n,this.value),o=s.call(this,i,this.primKey,n,f);o&&(t=this.value,gt(o).forEach(function(e){m(t,e,o[e])}))}else a.call(this,this.primKey,t,f)};else if(s===S){var l=gt(e),p=l.length;d=function(t){for(var n=!1,r=0;r0?console.warn("Another connection wants to upgrade database '"+Ht.name+"'. Closing db now to resume the upgrade."):console.warn("Another connection wants to delete database '"+Ht.name+"'. Closing db now to resume the delete request."),Ht.close()}),Ht.on("blocked",function(t){!t.newVersion||t.newVersion=t&&o()}}},function(t,e){return e})},i.sliding=function(t,e){e=e||10;var n=0;return i(function(r,i){var o,s=0;n++;return function(n,r){n||(o=t(o,r),e<=++s&&i(null,o))}})}},function(t,e){t.exports=function(t){return function e(n,r,i){var o=!0,s=!1;do{s=!0,o=!1,t.call(function(t,a,c){s?(n=t,r=a,i=c,o=!0):e(t,a,c)},n,r,i),s=!1}while(o)}}},function(t,e,n){(function(e){t.exports=function(){function t(t,e){return function(r){return function(){n(t,e),r&&r.apply(null,arguments)}}}function n(e,n){var r=a[e].indexOf(n);~r&&(a[e].splice(r,1),o(e)?s(function(){a[e][0](t(e,a[e][0]))}):delete a[e])}function r(t,e){return o(t)?(a[t].push(e),!1):(a[t]=[e],!0)}function i(e,i){if(Array.isArray(e)){var o=e.length,s={};function a(t){return function(){var e=[].slice.call(arguments);for(var r in s)n(r,s[r]);t.apply(this,e)}}e.forEach(function(t){function e(){n++||--o||i(a)}var n=0;s[t]=e,r(t,e)&&e()})}else r(e,i)&&i(t(e,i))}function o(t){return!!Array.isArray(a[t])&&!!a[t].length}var s=void 0===e?setTimeout:e,a={};return i.isLocked=o,i}}).call(e,n(11).setImmediate)},function(t,e,n){(function(e){function r(t,n,a,c){"function"==typeof n?(a=n,n={}):n&&"object"==typeof n||(n={mode:n});var f=n.mode,u=n.fs||o;void 0===f&&(f=s&~e.umask()),c||(c=null);var h=a||function(){};t=i.resolve(t),u.mkdir(t,f,function(e){if(!e)return c=c||t,h(null,c);switch(e.code){case"ENOENT":r(i.dirname(t),n,function(e,i){e?h(e,i):r(t,n,h,i)});break;default:u.stat(t,function(t,n){t||!n.isDirectory()?h(e,c):h(null,c)})}})}var i=n(12),o=n(17),s=parseInt("0777",8);t.exports=r.mkdirp=r.mkdirP=r,r.sync=function t(n,r,a){r&&"object"==typeof r||(r={mode:r});var c=r.mode,f=r.fs||o;void 0===c&&(c=s&~e.umask()),a||(a=null),n=i.resolve(n);try{f.mkdirSync(n,c),a=a||n}catch(e){switch(e.code){case"ENOENT":t(n,r,a=t(i.dirname(n),r,a));break;default:var u;try{u=f.statSync(n)}catch(t){throw e}if(!u.isDirectory())throw e}}return a}}).call(e,n(0))},function(t,e){t.exports={_from:"elliptic@^6.4.0",_id:"elliptic@6.4.0",_inBundle:!1,_integrity:"sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=",_location:"/elliptic",_phantomChildren:{},_requested:{type:"range",registry:!0,raw:"elliptic@^6.4.0",name:"elliptic",escapedName:"elliptic",rawSpec:"^6.4.0",saveSpec:null,fetchSpec:"^6.4.0"},_requiredBy:["/browserify-sign","/create-ecdh","/orbit-db-keystore","/secp256k1"],_resolved:"https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz",_shasum:"cac9af8762c85836187003c8dfe193e5e2eae5df",_spec:"elliptic@^6.4.0",_where:"/Users/samuli/code/orbit-db/node_modules/orbit-db-keystore",author:{name:"Fedor Indutny",email:"fedor@indutny.com"},bugs:{url:"https://github.com/indutny/elliptic/issues"},bundleDependencies:!1,dependencies:{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"},deprecated:!1,description:"EC cryptography",devDependencies:{brfs:"^1.4.3",coveralls:"^2.11.3",grunt:"^0.4.5","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^8.6.2",istanbul:"^0.4.2",jscs:"^2.9.0",jshint:"^2.6.0",mocha:"^2.1.0"},files:["lib"],homepage:"https://github.com/indutny/elliptic",keywords:["EC","Elliptic","curve","Cryptography"],license:"MIT",main:"lib/elliptic.js",name:"elliptic",repository:{type:"git",url:"git+ssh://git@github.com/indutny/elliptic.git"},scripts:{jscs:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",jshint:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",lint:"npm run jscs && npm run jshint",test:"npm run lint && npm run unit",unit:"istanbul test _mocha --reporter=spec test/index.js",version:"grunt dist && git add dist/"},version:"6.4.0"}},function(t,e,n){"use strict";var r=e,i=n(7),o=n(9),s=n(51);r.assert=o,r.toArray=s.toArray,r.zero2=s.zero2,r.toHex=s.toHex,r.encode=s.encode,r.getNAF=function(t,e){for(var n=[],r=1<=0;){var o;if(i.isOdd()){var s=i.andln(r-1);o=s>(r>>1)-1?(r>>1)-s:s,i.isubn(o)}else o=0;n.push(o);for(var a=0!==i.cmpn(0)&&0===i.andln(r-1)?e+1:1,c=1;c0||e.cmpn(-i)>0;){var o=t.andln(3)+r&3,s=e.andln(3)+i&3;3===o&&(o=-1),3===s&&(s=-1);var a;a=0==(1&o)?0:3!=(f=t.andln(7)+r&7)&&5!==f||2!==s?o:-o,n[0].push(a);var c;if(0==(1&s))c=0;else{var f=e.andln(7)+i&7;c=3!==f&&5!==f||2!==o?s:-s}n[1].push(c),2*r===a+1&&(r=1-r),2*i===c+1&&(i=1-i),t.iushrn(1),e.iushrn(1)}return n},r.cachedProperty=function(t,e,n){var r="_"+e;t.prototype[e]=function(){return void 0!==this[r]?this[r]:this[r]=n.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new i(t,"hex","le")}},function(t,e){},function(t,e,n){function r(t){this.rand=t}var i;if(t.exports=function(t){return i||(i=new r(null)),i.generate(t)},t.exports.Rand=r,r.prototype.generate=function(t){return this._rand(t)},r.prototype._rand=function(t){if(this.rand.getBytes)return this.rand.getBytes(t);for(var e=new Uint8Array(t),n=0;n0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function i(t,e){this.curve=t,this.type=e,this.precomputed=null}var o=n(7),s=n(2).utils,a=s.getNAF,c=s.getJSF,f=s.assert;t.exports=r,r.prototype.point=function(){throw new Error("Not implemented")},r.prototype.validate=function(){throw new Error("Not implemented")},r.prototype._fixedNafMul=function(t,e){f(t.precomputed);var n=t._getDoubles(),r=a(e,1),i=(1<=s;e--)c=(c<<1)+r[e];o.push(c)}for(var u=this.jpoint(null,null,null),h=this.jpoint(null,null,null),d=i;d>0;d--){for(s=0;s=0;c--){for(e=0;c>=0&&0===o[c];c--)e++;if(c>=0&&e++,s=s.dblp(e),c<0)break;var u=o[c];f(0!==u),s="affine"===t.type?u>0?s.mixedAdd(i[u-1>>1]):s.mixedAdd(i[-u-1>>1].neg()):u>0?s.add(i[u-1>>1]):s.add(i[-u-1>>1].neg())}return"affine"===t.type?s.toP():s},r.prototype._wnafMulAdd=function(t,e,n,r,i){for(var o=this._wnafT1,s=this._wnafT2,f=this._wnafT3,u=0,h=0;h=1;h-=2){var l=h-1,p=h;if(1===o[l]&&1===o[p]){var b=[e[l],null,null,e[p]];0===e[l].y.cmp(e[p].y)?(b[1]=e[l].add(e[p]),b[2]=e[l].toJ().mixedAdd(e[p].neg())):0===e[l].y.cmp(e[p].y.redNeg())?(b[1]=e[l].toJ().mixedAdd(e[p]),b[2]=e[l].add(e[p].neg())):(b[1]=e[l].toJ().mixedAdd(e[p]),b[2]=e[l].toJ().mixedAdd(e[p].neg()));var y=[-3,-1,-5,-7,0,7,5,1,3],m=c(n[l],n[p]);u=Math.max(m[0].length,u),f[l]=new Array(u),f[p]=new Array(u);for(x=0;x=0;h--){for(var S=0;h>=0;){for(var k=!0,x=0;x=0&&S++,_=_.dblp(S),h<0)break;for(x=0;x0?E=s[x][M-1>>1]:M<0&&(E=s[x][-M-1>>1].neg()),_="affine"===E.type?_.mixedAdd(E):_.add(E))}}for(h=0;h=Math.ceil((t.bitLength()+1)/e.step)},i.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var n=[this],r=this,i=0;i=0&&(o=e,s=n),r.negative&&(r=r.neg(),i=i.neg()),o.negative&&(o=o.neg(),s=s.neg()),[{a:r,b:i},{a:o,b:s}]},r.prototype._endoSplit=function(t){var e=this.endo.basis,n=e[0],r=e[1],i=r.b.mul(t).divRound(this.n),o=n.b.neg().mul(t).divRound(this.n),s=i.mul(n.a),a=o.mul(r.a),c=i.mul(n.b),f=o.mul(r.b);return{k1:t.sub(s).sub(a),k2:c.add(f).neg()}},r.prototype.pointFromX=function(t,e){(t=new c(t,16)).red||(t=t.toRed(this.red));var n=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),r=n.redSqrt();if(0!==r.redSqr().redSub(n).cmp(this.zero))throw new Error("invalid point");var i=r.fromRed().isOdd();return(e&&!i||!e&&i)&&(r=r.redNeg()),this.point(t,r)},r.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,n=t.y,r=this.a.redMul(e),i=e.redSqr().redMul(e).redIAdd(r).redIAdd(this.b);return 0===n.redSqr().redISub(i).cmpn(0)},r.prototype._endoWnafMulAdd=function(t,e,n){for(var r=this._endoWnafT1,i=this._endoWnafT2,o=0;o":""},i.prototype.isInfinity=function(){return this.inf},i.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var n=e.redSqr().redISub(this.x).redISub(t.x),r=e.redMul(this.x.redSub(n)).redISub(this.y);return this.curve.point(n,r)},i.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,n=this.x.redSqr(),r=t.redInvm(),i=n.redAdd(n).redIAdd(n).redIAdd(e).redMul(r),o=i.redSqr().redISub(this.x.redAdd(this.x)),s=i.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,s)},i.prototype.getX=function(){return this.x.fromRed()},i.prototype.getY=function(){return this.y.fromRed()},i.prototype.mul=function(t){return t=new c(t,16),this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},i.prototype.mulAdd=function(t,e,n){var r=[this,e],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(r,i):this.curve._wnafMulAdd(1,r,i,2)},i.prototype.jmulAdd=function(t,e,n){var r=[this,e],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(r,i,!0):this.curve._wnafMulAdd(1,r,i,2,!0)},i.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},i.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var n=this.precomputed,r=function(t){return t.neg()};e.precomputed={naf:n.naf&&{wnd:n.naf.wnd,points:n.naf.points.map(r)},doubles:n.doubles&&{step:n.doubles.step,points:n.doubles.points.map(r)}}}return e},i.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);return this.curve.jpoint(this.x,this.y,this.curve.one)},f(o,u.BasePoint),r.prototype.jpoint=function(t,e,n){return new o(this,t,e,n)},o.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),n=this.x.redMul(e),r=this.y.redMul(e).redMul(t);return this.curve.point(n,r)},o.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},o.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),n=this.z.redSqr(),r=this.x.redMul(e),i=t.x.redMul(n),o=this.y.redMul(e.redMul(t.z)),s=t.y.redMul(n.redMul(this.z)),a=r.redSub(i),c=o.redSub(s);if(0===a.cmpn(0))return 0!==c.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var f=a.redSqr(),u=f.redMul(a),h=r.redMul(f),d=c.redSqr().redIAdd(u).redISub(h).redISub(h),l=c.redMul(h.redISub(d)).redISub(o.redMul(u)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(d,l,p)},o.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),n=this.x,r=t.x.redMul(e),i=this.y,o=t.y.redMul(e).redMul(this.z),s=n.redSub(r),a=i.redSub(o);if(0===s.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=s.redSqr(),f=c.redMul(s),u=n.redMul(c),h=a.redSqr().redIAdd(f).redISub(u).redISub(u),d=a.redMul(u.redISub(h)).redISub(i.redMul(f)),l=this.z.redMul(s);return this.curve.jpoint(h,d,l)},o.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var e=this,n=0;n=0)return!1;if(n.redIAdd(i),0===this.x.cmp(n))return!0}return!1},o.prototype.inspect=function(){return this.isInfinity()?"":""},o.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},function(t,e,n){"use strict";function r(t){c.call(this,"mont",t),this.a=new s(t.a,16).toRed(this.red),this.b=new s(t.b,16).toRed(this.red),this.i4=new s(4).toRed(this.red).redInvm(),this.two=new s(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}function i(t,e,n){c.BasePoint.call(this,t,"projective"),null===e&&null===n?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new s(e,16),this.z=new s(n,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}var o=n(23),s=n(7),a=n(5),c=o.base,f=n(2).utils;a(r,c),t.exports=r,r.prototype.validate=function(t){var e=t.normalize().x,n=e.redSqr(),r=n.redMul(e).redAdd(n.redMul(this.a)).redAdd(e);return 0===r.redSqrt().redSqr().cmp(r)},a(i,c.BasePoint),r.prototype.decodePoint=function(t,e){return this.point(f.toArray(t,e),1)},r.prototype.point=function(t,e){return new i(this,t,e)},r.prototype.pointFromJSON=function(t){return i.fromJSON(this,t)},i.prototype.precompute=function(){},i.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},i.fromJSON=function(t,e){return new i(t,e[0],e[1]||t.one)},i.prototype.inspect=function(){return this.isInfinity()?"":""},i.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},i.prototype.dbl=function(){var t=this.x.redAdd(this.z).redSqr(),e=this.x.redSub(this.z).redSqr(),n=t.redSub(e),r=t.redMul(e),i=n.redMul(e.redAdd(this.curve.a24.redMul(n)));return this.curve.point(r,i)},i.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.diffAdd=function(t,e){var n=this.x.redAdd(this.z),r=this.x.redSub(this.z),i=t.x.redAdd(t.z),o=t.x.redSub(t.z).redMul(n),s=i.redMul(r),a=e.z.redMul(o.redAdd(s).redSqr()),c=e.x.redMul(o.redISub(s).redSqr());return this.curve.point(a,c)},i.prototype.mul=function(t){for(var e=t.clone(),n=this,r=this.curve.point(null,null),i=this,o=[];0!==e.cmpn(0);e.iushrn(1))o.push(e.andln(1));for(var s=o.length-1;s>=0;s--)0===o[s]?(n=n.diffAdd(r,i),r=r.dbl()):(r=n.diffAdd(r,i),n=n.dbl());return r},i.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.eq=function(t){return 0===this.getX().cmp(t.getX())},i.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},i.prototype.getX=function(){return this.normalize(),this.x.fromRed()}},function(t,e,n){"use strict";function r(t){this.twisted=1!=(0|t.a),this.mOneA=this.twisted&&-1==(0|t.a),this.extended=this.mOneA,f.call(this,"edwards",t),this.a=new a(t.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new a(t.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new a(t.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),u(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|t.c)}function i(t,e,n,r,i){f.BasePoint.call(this,t,"projective"),null===e&&null===n&&null===r?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new a(e,16),this.y=new a(n,16),this.z=r?new a(r,16):this.curve.one,this.t=i&&new a(i,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}var o=n(23),s=n(2),a=n(7),c=n(5),f=o.base,u=s.utils.assert;c(r,f),t.exports=r,r.prototype._mulA=function(t){return this.mOneA?t.redNeg():this.a.redMul(t)},r.prototype._mulC=function(t){return this.oneC?t:this.c.redMul(t)},r.prototype.jpoint=function(t,e,n,r){return this.point(t,e,n,r)},r.prototype.pointFromX=function(t,e){(t=new a(t,16)).red||(t=t.toRed(this.red));var n=t.redSqr(),r=this.c2.redSub(this.a.redMul(n)),i=this.one.redSub(this.c2.redMul(this.d).redMul(n)),o=r.redMul(i.redInvm()),s=o.redSqrt();if(0!==s.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");var c=s.fromRed().isOdd();return(e&&!c||!e&&c)&&(s=s.redNeg()),this.point(t,s)},r.prototype.pointFromY=function(t,e){(t=new a(t,16)).red||(t=t.toRed(this.red));var n=t.redSqr(),r=n.redSub(this.one),i=n.redMul(this.d).redAdd(this.one),o=r.redMul(i.redInvm());if(0===o.cmp(this.zero)){if(e)throw new Error("invalid point");return this.point(this.zero,t)}var s=o.redSqrt();if(0!==s.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");return s.isOdd()!==e&&(s=s.redNeg()),this.point(s,t)},r.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();var e=t.x.redSqr(),n=t.y.redSqr(),r=e.redMul(this.a).redAdd(n),i=this.c2.redMul(this.one.redAdd(this.d.redMul(e).redMul(n)));return 0===r.cmp(i)},c(i,f.BasePoint),r.prototype.pointFromJSON=function(t){return i.fromJSON(this,t)},r.prototype.point=function(t,e,n,r){return new i(this,t,e,n,r)},i.fromJSON=function(t,e){return new i(t,e[0],e[1],e[2])},i.prototype.inspect=function(){return this.isInfinity()?"":""},i.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&0===this.y.cmp(this.z)},i.prototype._extDbl=function(){var t=this.x.redSqr(),e=this.y.redSqr(),n=this.z.redSqr();n=n.redIAdd(n);var r=this.curve._mulA(t),i=this.x.redAdd(this.y).redSqr().redISub(t).redISub(e),o=r.redAdd(e),s=o.redSub(n),a=r.redSub(e),c=i.redMul(s),f=o.redMul(a),u=i.redMul(a),h=s.redMul(o);return this.curve.point(c,f,h,u)},i.prototype._projDbl=function(){var t,e,n,r=this.x.redAdd(this.y).redSqr(),i=this.x.redSqr(),o=this.y.redSqr();if(this.curve.twisted){var s=(f=this.curve._mulA(i)).redAdd(o);if(this.zOne)t=r.redSub(i).redSub(o).redMul(s.redSub(this.curve.two)),e=s.redMul(f.redSub(o)),n=s.redSqr().redSub(s).redSub(s);else{var a=this.z.redSqr(),c=s.redSub(a).redISub(a);t=r.redSub(i).redISub(o).redMul(c),e=s.redMul(f.redSub(o)),n=s.redMul(c)}}else{var f=i.redAdd(o),a=this.curve._mulC(this.c.redMul(this.z)).redSqr(),c=f.redSub(a).redSub(a);t=this.curve._mulC(r.redISub(f)).redMul(c),e=this.curve._mulC(f).redMul(i.redISub(o)),n=f.redMul(c)}return this.curve.point(t,e,n)},i.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},i.prototype._extAdd=function(t){var e=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),n=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),r=this.t.redMul(this.curve.dd).redMul(t.t),i=this.z.redMul(t.z.redAdd(t.z)),o=n.redSub(e),s=i.redSub(r),a=i.redAdd(r),c=n.redAdd(e),f=o.redMul(s),u=a.redMul(c),h=o.redMul(c),d=s.redMul(a);return this.curve.point(f,u,d,h)},i.prototype._projAdd=function(t){var e,n,r=this.z.redMul(t.z),i=r.redSqr(),o=this.x.redMul(t.x),s=this.y.redMul(t.y),a=this.curve.d.redMul(o).redMul(s),c=i.redSub(a),f=i.redAdd(a),u=this.x.redAdd(this.y).redMul(t.x.redAdd(t.y)).redISub(o).redISub(s),h=r.redMul(c).redMul(u);return this.curve.twisted?(e=r.redMul(f).redMul(s.redSub(this.curve._mulA(o))),n=c.redMul(f)):(e=r.redMul(f).redMul(s.redSub(o)),n=this.curve._mulC(c).redMul(f)),this.curve.point(h,e,n)},i.prototype.add=function(t){return this.isInfinity()?t:t.isInfinity()?this:this.curve.extended?this._extAdd(t):this._projAdd(t)},i.prototype.mul=function(t){return this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve._wnafMul(this,t)},i.prototype.mulAdd=function(t,e,n){return this.curve._wnafMulAdd(1,[this,e],[t,n],2,!1)},i.prototype.jmulAdd=function(t,e,n){return this.curve._wnafMulAdd(1,[this,e],[t,n],2,!0)},i.prototype.normalize=function(){if(this.zOne)return this;var t=this.z.redInvm();return this.x=this.x.redMul(t),this.y=this.y.redMul(t),this.t&&(this.t=this.t.redMul(t)),this.z=this.curve.one,this.zOne=!0,this},i.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},i.prototype.getX=function(){return this.normalize(),this.x.fromRed()},i.prototype.getY=function(){return this.normalize(),this.y.fromRed()},i.prototype.eq=function(t){return this===t||0===this.getX().cmp(t.getX())&&0===this.getY().cmp(t.getY())},i.prototype.eqXToP=function(t){var e=t.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(e))return!0;for(var n=t.clone(),r=this.curve.redN.redMul(this.z);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(e.redIAdd(r),0===this.x.cmp(e))return!0}return!1},i.prototype.toP=i.prototype.normalize,i.prototype.mixedAdd=i.prototype.add},function(t,e,n){"use strict";function r(t){"short"===t.type?this.curve=new a.curve.short(t):"edwards"===t.type?this.curve=new a.curve.edwards(t):this.curve=new a.curve.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,c(this.g.validate(),"Invalid curve"),c(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function i(t,e){Object.defineProperty(o,t,{configurable:!0,enumerable:!0,get:function(){var n=new r(e);return Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:n}),n}})}var o=e,s=n(32),a=n(2),c=a.utils.assert;o.PresetCurve=r,i("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:s.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),i("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:s.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),i("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:s.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),i("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:s.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),i("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:s.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),i("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:s.sha256,gRed:!1,g:["9"]}),i("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:s.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var f;try{f=n(125)}catch(t){f=void 0}i("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:s.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",f]})},function(t,e,n){"use strict";e.sha1=n(120),e.sha224=n(121),e.sha256=n(53),e.sha384=n(122),e.sha512=n(54)},function(t,e,n){"use strict";function r(){if(!(this instanceof r))return new r;h.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}var i=n(6),o=n(18),s=n(52),a=i.rotl32,c=i.sum32,f=i.sum32_5,u=s.ft_1,h=o.BlockHash,d=[1518500249,1859775393,2400959708,3395469782];i.inherits(r,h),t.exports=r,r.blockSize=512,r.outSize=160,r.hmacStrength=80,r.padLength=64,r.prototype._update=function(t,e){for(var n=this.W,r=0;r<16;r++)n[r]=t[e+r];for(;rthis.blockSize&&(t=(new this.Hash).update(t).digest()),o(t.length<=this.blockSize);for(var e=t.length;e0))return a.iaddn(1),this.keyFromPrivate(a)}},r.prototype._truncateToN=function(t,e){var n=8*t.byteLength()-this.n.bitLength();return n>0&&(t=t.ushrn(n)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},r.prototype.sign=function(t,e,n,r){"object"==typeof n&&(r=n,n=null),r||(r={}),e=this.keyFromPrivate(e,n),t=this._truncateToN(new i(t,16));for(var s=this.n.byteLength(),a=e.getPrivate().toArray("be",s),c=t.toArray("be",s),u=new o({hash:this.hash,entropy:a,nonce:c,pers:r.pers,persEnc:r.persEnc||"utf8"}),h=this.n.sub(new i(1)),d=0;!0;d++){var l=r.k?r.k(d):new i(u.generate(this.n.byteLength()));if(!((l=this._truncateToN(l,!0)).cmpn(1)<=0||l.cmp(h)>=0)){var p=this.g.mul(l);if(!p.isInfinity()){var b=p.getX(),y=b.umod(this.n);if(0!==y.cmpn(0)){var m=l.invm(this.n).mul(y.mul(e.getPrivate()).iadd(t));if(0!==(m=m.umod(this.n)).cmpn(0)){var g=(p.getY().isOdd()?1:0)|(0!==b.cmp(y)?2:0);return r.canonical&&m.cmp(this.nh)>0&&(m=this.n.sub(m),g^=1),new f({r:y,s:m,recoveryParam:g})}}}}}},r.prototype.verify=function(t,e,n,r){t=this._truncateToN(new i(t,16)),n=this.keyFromPublic(n,r);var o=(e=new f(e,"hex")).r,s=e.s;if(o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;var a=s.invm(this.n),c=a.mul(t).umod(this.n),u=a.mul(o).umod(this.n);if(!this.curve._maxwellTrick){return!(h=this.g.mulAdd(c,n.getPublic(),u)).isInfinity()&&0===h.getX().umod(this.n).cmp(o)}var h=this.g.jmulAdd(c,n.getPublic(),u);return!h.isInfinity()&&h.eqXToP(o)},r.prototype.recoverPubKey=function(t,e,n,r){a((3&n)===n,"The recovery param is more than two bits"),e=new f(e,r);var o=this.n,s=new i(t),c=e.r,u=e.s,h=1&n,d=n>>1;if(c.cmp(this.curve.p.umod(this.curve.n))>=0&&d)throw new Error("Unable to find sencond key candinate");c=d?this.curve.pointFromX(c.add(this.curve.n),h):this.curve.pointFromX(c,h);var l=e.r.invm(o),p=o.sub(s).mul(l).umod(o),b=u.mul(l).umod(o);return this.g.mulAdd(p,c,b)},r.prototype.getKeyRecoveryParam=function(t,e,n,r){if(null!==(e=new f(e,r)).recoveryParam)return e.recoveryParam;for(var i=0;i<4;i++){var o;try{o=this.recoverPubKey(t,e,i)}catch(t){continue}if(o.eq(n))return i}throw new Error("Unable to find valid recovery factor")}},function(t,e,n){"use strict";function r(t){if(!(this instanceof r))return new r(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=o.toArray(t.entropy,t.entropyEnc||"hex"),n=o.toArray(t.nonce,t.nonceEnc||"hex"),i=o.toArray(t.pers,t.persEnc||"hex");s(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,n,i)}var i=n(32),o=n(51),s=n(9);t.exports=r,r.prototype._init=function(t,e,n){var r=t.concat(e).concat(n);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var i=0;i=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(n||[])),this._reseed=1},r.prototype.generate=function(t,e,n,r){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(r=n,n=e,e=null),n&&(n=o.toArray(n,r||"hex"),this._update(n));for(var i=[];i.length"}},function(t,e,n){"use strict";function r(t,e){if(t instanceof r)return t;this._importDER(t,e)||(f(t.r&&t.s,"Signature without r or s"),this.r=new a(t.r,16),this.s=new a(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}function i(t,e){var n=t[e.place++];if(!(128&n))return n;for(var r=15&n,i=0,o=0,s=e.place;o>>3);for(t.push(128|n);--n;)t.push(e>>>(n<<3)&255);t.push(e)}}var a=n(7),c=n(2).utils,f=c.assert;t.exports=r,r.prototype._importDER=function(t,e){t=c.toArray(t,e);var n=new function(){this.place=0};if(48!==t[n.place++])return!1;if(i(t,n)+n.place!==t.length)return!1;if(2!==t[n.place++])return!1;var r=i(t,n),o=t.slice(n.place,r+n.place);if(n.place+=r,2!==t[n.place++])return!1;var s=i(t,n);if(t.length!==s+n.place)return!1;var f=t.slice(n.place,s+n.place);return 0===o[0]&&128&o[1]&&(o=o.slice(1)),0===f[0]&&128&f[1]&&(f=f.slice(1)),this.r=new a(o),this.s=new a(f),this.recoveryParam=null,!0},r.prototype.toDER=function(t){var e=this.r.toArray(),n=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&n[0]&&(n=[0].concat(n)),e=o(e),n=o(n);!(n[0]||128&n[1]);)n=n.slice(1);var r=[2];s(r,e.length),(r=r.concat(e)).push(2),s(r,n.length);var i=r.concat(n),a=[48];return s(a,i.length),a=a.concat(i),c.encode(a,t)}},function(t,e,n){"use strict";function r(t){if(a("ed25519"===t,"only tested with ed25519 so far"),!(this instanceof r))return new r(t);t=o.curves[t].curve;this.curve=t,this.g=t.g,this.g.precompute(t.n.bitLength()+1),this.pointClass=t.point().constructor,this.encodingLength=Math.ceil(t.n.bitLength()/8),this.hash=i.sha512}var i=n(32),o=n(2),s=o.utils,a=s.assert,c=s.parseBytes,f=n(131),u=n(132);t.exports=r,r.prototype.sign=function(t,e){t=c(t);var n=this.keyFromSecret(e),r=this.hashInt(n.messagePrefix(),t),i=this.g.mul(r),o=this.encodePoint(i),s=this.hashInt(o,n.pubBytes(),t).mul(n.priv()),a=r.add(s).umod(this.curve.n);return this.makeSignature({R:i,S:a,Rencoded:o})},r.prototype.verify=function(t,e,n){t=c(t),e=this.makeSignature(e);var r=this.keyFromPublic(n),i=this.hashInt(e.Rencoded(),r.pubBytes(),t),o=this.g.mul(e.S());return e.R().add(r.pub().mul(i)).eq(o)},r.prototype.hashInt=function(){for(var t=this.hash(),e=0;ethis.quota)throw new a;if(y(o,m,"utf8"),i||((h=new s(n,this._keys.push(t)-1)).size=g,this._metaKeyMap[t]=h,this.length+=1,this._bytesInUse+=g),f)return r=new c(t,p,e,this._eventUrl),this.emit("storage",r)},n.prototype.getItem=function(t){var e,n;return t=u(t),(n=this._metaKeyMap[t])?(e=b.join(this._location,n.key),p.readFileSync(e,"utf8")):null},n.prototype._getStat=function(t){var e;t=u(t),e=b.join(this._location,encodeURIComponent(t));try{return p.statSync(e)}catch(t){return null}},n.prototype.removeItem=function(t){var e,n,r,i,o,s,a,f;if(t=u(t),s=this._metaKeyMap[t]){a=null,(r=l.EventEmitter.listenerCount(this,"storage"))&&(a=this.getItem(t)),delete this._metaKeyMap[t],this.length-=1,this._bytesInUse-=s.size,n=b.join(this._location,s.key),this._keys.splice(s.index,1),f=this._metaKeyMap;for(i in f)f[i],(o=this._metaKeyMap[i]).index>s.index&&(o.index-=1);if(h(n),r)return e=new c(t,a,null,this._eventUrl),this.emit("storage",e)}},n.prototype.key=function(t){return this._keys[t]},n.prototype.clear=function(){var t;if(f(this._location),this._metaKeyMap=d(),this._keys=[],this.length=0,this._bytesInUse=0,l.EventEmitter.listenerCount(this,"storage"))return t=new c(null,null,null,this._eventUrl),this.emit("storage",t)},n.prototype._getBytesInUse=function(){return this._bytesInUse},n.prototype._deleteLocation=function(){return delete r[this._location],h(this._location),this._metaKeyMap={},this._keys=[],this.length=0,this._bytesInUse=0},n}(l.EventEmitter),r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return m(e,o),e.prototype.setItem=function(t,n){var r;return r=JSON.stringify(n),e.__super__.setItem.call(this,t,r)},e.prototype.getItem=function(t){return JSON.parse(e.__super__.getItem.call(this,t))},e}(),e.LocalStorage=o,e.JSONStorage=r,e.QUOTA_EXCEEDED_ERR=a}).call(this)}).call(e,n(0))},function(t,e,n){"use strict";(function(e,r,i){function o(t){return t+"."+c(e).hash(String(r.pid)).hash(String(++u)).result()}t.exports=function(t,e,n,c){n instanceof Function&&(c=n,n=null),n||(n={}),s.realpath(t,function(u,h){!function(t,e,n,c){function u(){a([[h,d,e,n.mode,n.encoding||"utf8"],n.chown&&[s,s.chown,d,n.chown.uid,n.chown.gid],n.mode&&[s,s.chmod,d,n.mode],[s,s.rename,d,t]],function(t){t?s.unlink(d,function(){c(t)}):c()})}function h(t,e,r,o,a){s.open(t,"w",n.mode,function(t,n){function r(t){if(t)return a(t);s.fsync(n,function(t){if(t)return a(t);s.close(n,a)})}return t?a(t):i.isBuffer(e)?s.write(n,e,0,e.length,0,r):null!=e?s.write(n,String(e),0,String(o),r):r()})}var d=o(t);n.mode&&n.chown?u():s.stat(t,function(t,e){return t||!e?u():((n=f({},n)).mode||(n.mode=e.mode),!n.chown&&r.getuid&&(n.chown={uid:e.uid,gid:e.gid}),u())})}(h||t,e,n,c)})},t.exports.sync=function(t,e,n){n||(n={});try{t=s.realpathSync(t)}catch(t){}var a=o(t);try{if(!n.mode||!n.chown)try{var c=s.statSync(t);(n=f({},n)).mode||(n.mode=c.mode),!n.chown&&r.getuid&&(n.chown={uid:c.uid,gid:c.gid})}catch(t){}var u=s.openSync(a,"w",n.mode);i.isBuffer(e)?s.writeSync(u,e,0,e.length,0):null!=e&&s.writeSync(u,String(e),0,String(n.encoding||"utf8")),s.fsyncSync(u),s.closeSync(u),n.chown&&s.chownSync(a,n.chown.uid,n.chown.gid),n.mode&&s.chmodSync(a,n.mode),s.renameSync(a,t)}catch(t){try{s.unlinkSync(a)}catch(t){}throw t}},t.exports._getTmpname=o;var s=n(135),a=n(147).chain,c=n(150),f=Object.assign||n(24)._extend,u=0}).call(e,"/index.js",n(0),n(1).Buffer)},function(t,e,n){(function(e){function r(t){function n(e){return p.apply(t,e)}function s(t,e){return this instanceof s?(y.apply(this,arguments),this):s.apply(Object.create(s.prototype),arguments)}function f(t,e){return this instanceof f?(m.apply(this,arguments),this):f.apply(Object.create(f.prototype),arguments)}function u(t,e,n,r){function s(t,e,n,r){return g(t,e,n,function(a,c){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof r&&r.apply(this,arguments),o()):i([s,[t,e,n,r]])})}return"function"==typeof n&&(r=n,n=null),s(t,e,n,r)}a(t),t.gracefulify=r,t.FileReadStream=s,t.FileWriteStream=f,t.createReadStream=function(t,e){return new s(t,e)},t.createWriteStream=function(t,e){return new f(t,e)};var h=t.readFile;t.readFile=function(t,e,n){function r(t,e,n){return h(t,e,function(s){!s||"EMFILE"!==s.code&&"ENFILE"!==s.code?("function"==typeof n&&n.apply(this,arguments),o()):i([r,[t,e,n]])})}return"function"==typeof e&&(n=e,e=null),r(t,e,n)};var d=t.writeFile;t.writeFile=function(t,e,n,r){function s(t,e,n,r){return d(t,e,n,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof r&&r.apply(this,arguments),o()):i([s,[t,e,n,r]])})}return"function"==typeof n&&(r=n,n=null),s(t,e,n,r)};var l=t.appendFile;l&&(t.appendFile=function(t,e,n,r){function s(t,e,n,r){return l(t,e,n,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof r&&r.apply(this,arguments),o()):i([s,[t,e,n,r]])})}return"function"==typeof n&&(r=n,n=null),s(t,e,n,r)});var p=t.readdir;if(t.readdir=function(t,e,r){var s=[t];return"function"!=typeof e?s.push(e):r=e,s.push(function(t,e){e&&e.sort&&e.sort(),!t||"EMFILE"!==t.code&&"ENFILE"!==t.code?("function"==typeof r&&r.apply(this,arguments),o()):i([n,[s]])}),n(s)},"v0.8"===e.version.substr(0,4)){var b=c(t);s=b.ReadStream,f=b.WriteStream}var y=t.ReadStream;(s.prototype=Object.create(y.prototype)).open=function(){var t=this;u(t.path,t.flags,t.mode,function(e,n){e?(t.autoClose&&t.destroy(),t.emit("error",e)):(t.fd=n,t.emit("open",n),t.read())})};var m=t.WriteStream;(f.prototype=Object.create(m.prototype)).open=function(){var t=this;u(t.path,t.flags,t.mode,function(e,n){e?(t.destroy(),t.emit("error",e)):(t.fd=n,t.emit("open",n))})},t.ReadStream=s,t.WriteStream=f;var g=t.open;return t.open=u,t}function i(t){h("ENQUEUE",t[0].name,t[1]),f.push(t)}function o(){var t=f.shift();t&&(h("RETRY",t[0].name,t[1]),t[0].apply(null,t[1]))}var s=n(17),a=n(136),c=n(138),f=[],u=n(24),h=function(){};u.debuglog?h=u.debuglog("gfs4"):/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&(h=function(){var t=u.format.apply(u,arguments);t="GFS4: "+t.split(/\n/).join("\nGFS4: "),console.error(t)}),/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&e.on("exit",function(){h(f),n(146).equal(f.length,0)}),t.exports=r(n(55)),Object({NODE_ENV:void 0}).TEST_GRACEFUL_FS_GLOBAL_PATCH&&(t.exports=r(s)),t.exports.close=s.close=function(t){return function(e,n){return t.call(s,e,function(t){t||o(),"function"==typeof n&&n.apply(this,arguments)})}}(s.close),t.exports.closeSync=s.closeSync=function(t){return function(e){var n=t.apply(s,arguments);return o(),n}}(s.closeSync)}).call(e,n(0))},function(t,e,n){(function(e){function r(t){return t?function(e,n,r){return t.call(u,e,n,function(t){f(t)&&(t=null),r&&r.apply(this,arguments)})}:t}function i(t){return t?function(e,n){try{return t.call(u,e,n)}catch(t){if(!f(t))throw t}}:t}function o(t){return t?function(e,n,r,i){return t.call(u,e,n,r,function(t){f(t)&&(t=null),i&&i.apply(this,arguments)})}:t}function s(t){return t?function(e,n,r){try{return t.call(u,e,n,r)}catch(t){if(!f(t))throw t}}:t}function a(t){return t?function(e,n){return t.call(u,e,function(t,e){if(!e)return n.apply(this,arguments);e.uid<0&&(e.uid+=4294967296),e.gid<0&&(e.gid+=4294967296),n&&n.apply(this,arguments)})}:t}function c(t){return t?function(e){var n=t.call(u,e);return n.uid<0&&(n.uid+=4294967296),n.gid<0&&(n.gid+=4294967296),n}:t}function f(t){if(!t)return!0;if("ENOSYS"===t.code)return!0;return!(e.getuid&&0===e.getuid()||"EINVAL"!==t.code&&"EPERM"!==t.code)}var u=n(55),h=n(137),d=e.cwd,l=null,p=Object({NODE_ENV:void 0}).GRACEFUL_FS_PLATFORM||e.platform;e.cwd=function(){return l||(l=d.call(e)),l};try{e.cwd()}catch(t){}var b=e.chdir;e.chdir=function(t){l=null,b.call(e,t)},t.exports=function(t){h.hasOwnProperty("O_SYMLINK")&&e.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&function(t){t.lchmod=function(e,n,r){t.open(e,h.O_WRONLY|h.O_SYMLINK,n,function(e,i){e?r&&r(e):t.fchmod(i,n,function(e){t.close(i,function(t){r&&r(e||t)})})})},t.lchmodSync=function(e,n){var r,i=t.openSync(e,h.O_WRONLY|h.O_SYMLINK,n),o=!0;try{r=t.fchmodSync(i,n),o=!1}finally{if(o)try{t.closeSync(i)}catch(t){}else t.closeSync(i)}return r}}(t),t.lutimes||function(t){h.hasOwnProperty("O_SYMLINK")?(t.lutimes=function(e,n,r,i){t.open(e,h.O_SYMLINK,function(e,o){e?i&&i(e):t.futimes(o,n,r,function(e){t.close(o,function(t){i&&i(e||t)})})})},t.lutimesSync=function(e,n,r){var i,o=t.openSync(e,h.O_SYMLINK),s=!0;try{i=t.futimesSync(o,n,r),s=!1}finally{if(s)try{t.closeSync(o)}catch(t){}else t.closeSync(o)}return i}):(t.lutimes=function(t,n,r,i){i&&e.nextTick(i)},t.lutimesSync=function(){})}(t),t.chown=o(t.chown),t.fchown=o(t.fchown),t.lchown=o(t.lchown),t.chmod=r(t.chmod),t.fchmod=r(t.fchmod),t.lchmod=r(t.lchmod),t.chownSync=s(t.chownSync),t.fchownSync=s(t.fchownSync),t.lchownSync=s(t.lchownSync),t.chmodSync=i(t.chmodSync),t.fchmodSync=i(t.fchmodSync),t.lchmodSync=i(t.lchmodSync),t.stat=a(t.stat),t.fstat=a(t.fstat),t.lstat=a(t.lstat),t.statSync=c(t.statSync),t.fstatSync=c(t.fstatSync),t.lstatSync=c(t.lstatSync),t.lchmod||(t.lchmod=function(t,n,r){r&&e.nextTick(r)},t.lchmodSync=function(){}),t.lchown||(t.lchown=function(t,n,r,i){i&&e.nextTick(i)},t.lchownSync=function(){}),"win32"===p&&(t.rename=function(e){return function(n,r,i){var o=Date.now(),s=0;e(n,r,function a(c){if(c&&("EACCES"===c.code||"EPERM"===c.code)&&Date.now()-o<6e4)return setTimeout(function(){t.stat(r,function(t,o){t&&"ENOENT"===t.code?e(n,r,a):i(c)})},s),void(s<100&&(s+=10));i&&i(c)})}}(t.rename)),t.read=function(e){return function(n,r,i,o,s,a){var c;if(a&&"function"==typeof a){var f=0;c=function(u,h,d){if(u&&"EAGAIN"===u.code&&f<10)return f++,e.call(t,n,r,i,o,s,c);a.apply(this,arguments)}}return e.call(t,n,r,i,o,s,c)}}(t.read),t.readSync=function(e){return function(n,r,i,o,s){for(var a=0;;)try{return e.call(t,n,r,i,o,s)}catch(t){if("EAGAIN"===t.code&&a<10){a++;continue}throw t}}}(t.readSync)}}).call(e,n(0))},function(t,e){t.exports={O_RDONLY:0,O_WRONLY:1,O_RDWR:2,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:512,O_EXCL:2048,O_NOCTTY:131072,O_TRUNC:1024,O_APPEND:8,O_DIRECTORY:1048576,O_NOFOLLOW:256,O_SYNC:128,O_SYMLINK:2097152,O_NONBLOCK:4,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,E2BIG:7,EACCES:13,EADDRINUSE:48,EADDRNOTAVAIL:49,EAFNOSUPPORT:47,EAGAIN:35,EALREADY:37,EBADF:9,EBADMSG:94,EBUSY:16,ECANCELED:89,ECHILD:10,ECONNABORTED:53,ECONNREFUSED:61,ECONNRESET:54,EDEADLK:11,EDESTADDRREQ:39,EDOM:33,EDQUOT:69,EEXIST:17,EFAULT:14,EFBIG:27,EHOSTUNREACH:65,EIDRM:90,EILSEQ:92,EINPROGRESS:36,EINTR:4,EINVAL:22,EIO:5,EISCONN:56,EISDIR:21,ELOOP:62,EMFILE:24,EMLINK:31,EMSGSIZE:40,EMULTIHOP:95,ENAMETOOLONG:63,ENETDOWN:50,ENETRESET:52,ENETUNREACH:51,ENFILE:23,ENOBUFS:55,ENODATA:96,ENODEV:19,ENOENT:2,ENOEXEC:8,ENOLCK:77,ENOLINK:97,ENOMEM:12,ENOMSG:91,ENOPROTOOPT:42,ENOSPC:28,ENOSR:98,ENOSTR:99,ENOSYS:78,ENOTCONN:57,ENOTDIR:20,ENOTEMPTY:66,ENOTSOCK:38,ENOTSUP:45,ENOTTY:25,ENXIO:6,EOPNOTSUPP:102,EOVERFLOW:84,EPERM:1,EPIPE:32,EPROTO:100,EPROTONOSUPPORT:43,EPROTOTYPE:41,ERANGE:34,EROFS:30,ESPIPE:29,ESRCH:3,ESTALE:70,ETIME:101,ETIMEDOUT:60,ETXTBSY:26,EWOULDBLOCK:35,EXDEV:18,SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGILL:4,SIGTRAP:5,SIGABRT:6,SIGIOT:6,SIGBUS:10,SIGFPE:8,SIGKILL:9,SIGUSR1:30,SIGSEGV:11,SIGUSR2:31,SIGPIPE:13,SIGALRM:14,SIGTERM:15,SIGCHLD:20,SIGCONT:19,SIGSTOP:17,SIGTSTP:18,SIGTTIN:21,SIGTTOU:22,SIGURG:16,SIGXCPU:24,SIGXFSZ:25,SIGVTALRM:26,SIGPROF:27,SIGWINCH:28,SIGIO:23,SIGSYS:12,SSL_OP_ALL:2147486719,SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,SSL_OP_CISCO_ANYCONNECT:32768,SSL_OP_COOKIE_EXCHANGE:8192,SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,SSL_OP_EPHEMERAL_RSA:0,SSL_OP_LEGACY_SERVER_CONNECT:4,SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER:32,SSL_OP_MICROSOFT_SESS_ID_BUG:1,SSL_OP_MSIE_SSLV2_RSA_PADDING:0,SSL_OP_NETSCAPE_CA_DN_BUG:536870912,SSL_OP_NETSCAPE_CHALLENGE_BUG:2,SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG:1073741824,SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG:8,SSL_OP_NO_COMPRESSION:131072,SSL_OP_NO_QUERY_MTU:4096,SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,SSL_OP_NO_SSLv2:16777216,SSL_OP_NO_SSLv3:33554432,SSL_OP_NO_TICKET:16384,SSL_OP_NO_TLSv1:67108864,SSL_OP_NO_TLSv1_1:268435456,SSL_OP_NO_TLSv1_2:134217728,SSL_OP_PKCS1_CHECK_1:0,SSL_OP_PKCS1_CHECK_2:0,SSL_OP_SINGLE_DH_USE:1048576,SSL_OP_SINGLE_ECDH_USE:524288,SSL_OP_SSLEAY_080_CLIENT_DH_BUG:128,SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG:0,SSL_OP_TLS_BLOCK_PADDING_BUG:512,SSL_OP_TLS_D5_BUG:256,SSL_OP_TLS_ROLLBACK_BUG:8388608,ENGINE_METHOD_DSA:2,ENGINE_METHOD_DH:4,ENGINE_METHOD_RAND:8,ENGINE_METHOD_ECDH:16,ENGINE_METHOD_ECDSA:32,ENGINE_METHOD_CIPHERS:64,ENGINE_METHOD_DIGESTS:128,ENGINE_METHOD_STORE:256,ENGINE_METHOD_PKEY_METHS:512,ENGINE_METHOD_PKEY_ASN1_METHS:1024,ENGINE_METHOD_ALL:65535,ENGINE_METHOD_NONE:0,DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_UDP_REUSEADDR:4}},function(t,e,n){(function(e){var r=n(139).Stream;t.exports=function(t){function n(i,o){if(!(this instanceof n))return new n(i,o);r.call(this);var s=this;this.path=i,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=65536,o=o||{};for(var a=Object.keys(o),c=0,f=a.length;cthis.end)throw new Error("start must be <= end");this.pos=this.start}null===this.fd?t.open(this.path,this.flags,this.mode,function(t,e){if(t)return s.emit("error",t),void(s.readable=!1);s.fd=e,s.emit("open",e),s._read()}):e.nextTick(function(){s._read()})}function i(e,n){if(!(this instanceof i))return new i(e,n);r.call(this),this.path=e,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,n=n||{};for(var o=Object.keys(n),s=0,a=o.length;s= zero");this.pos=this.start}this.busy=!1,this._queue=[],null===this.fd&&(this._open=t.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}return{ReadStream:n,WriteStream:i}}}).call(e,n(0))},function(t,e,n){function r(){i.call(this)}t.exports=r;var i=n(4).EventEmitter;n(5)(r,i),r.Readable=n(13),r.Writable=n(140),r.Duplex=n(141),r.Transform=n(142),r.PassThrough=n(143),r.Stream=r,r.prototype.pipe=function(t,e){function n(e){t.writable&&!1===t.write(e)&&f.pause&&f.pause()}function r(){f.readable&&f.resume&&f.resume()}function o(){u||(u=!0,t.end())}function s(){u||(u=!0,"function"==typeof t.destroy&&t.destroy())}function a(t){if(c(),0===i.listenerCount(this,"error"))throw t}function c(){f.removeListener("data",n),t.removeListener("drain",r),f.removeListener("end",o),f.removeListener("close",s),f.removeListener("error",a),t.removeListener("error",a),f.removeListener("end",c),f.removeListener("close",c),t.removeListener("close",c)}var f=this;f.on("data",n),t.on("drain",r),t._isStdio||e&&!1===e.end||(f.on("end",o),f.on("close",s));var u=!1;return f.on("error",a),t.on("error",a),f.on("end",c),f.on("close",c),t.on("close",c),t.emit("pipe",f),t}},function(t,e,n){t.exports=n(25)},function(t,e,n){t.exports=n(8)},function(t,e,n){t.exports=n(13).Transform},function(t,e,n){t.exports=n(13).PassThrough},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e,n){"use strict";(function(e){function r(t,e){if(t===e)return 0;for(var n=t.length,r=e.length,i=0,o=Math.min(n,r);i=0;a--)if(c[a]!==f[a])return!1;for(a=c.length-1;a>=0;a--)if(s=c[a],!d(t[s],e[s],n,r))return!1;return!0}(t,e,n,a))}return n?t===e:t==e}function l(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function p(t,e,n){d(t,e,!0)&&u(t,e,n,"notDeepStrictEqual",p)}function b(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function y(t,e,n,r){var i;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof n&&(r=n,n=null),i=function(t){var e;try{t()}catch(t){e=t}return e}(e),r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!i&&u(i,n,"Missing expected exception"+r);var o="string"==typeof r,s=!t&&m.isError(i),a=!t&&i&&!n;if((s&&o&&b(i,n)||a)&&u(i,n,"Got unwanted exception"+r),t&&i&&n&&!b(i,n)||!t&&i)throw i}var m=n(24),g=Object.prototype.hasOwnProperty,v=Array.prototype.slice,_="foo"===function(){}.name,w=t.exports=h,S=/\s*function\s+([^\(\s]*)\s*/;w.AssertionError=function(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=function(t){return c(f(t.actual),128)+" "+t.operator+" "+c(f(t.expected),128)}(this),this.generatedMessage=!0);var e=t.stackStartFunction||u;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var n=new Error;if(n.stack){var r=n.stack,i=a(e),o=r.indexOf("\n"+i);if(o>=0){var s=r.indexOf("\n",o+1);r=r.substring(s+1)}this.stack=r}}},m.inherits(w.AssertionError,Error),w.fail=u,w.ok=h,w.equal=function(t,e,n){t!=e&&u(t,e,n,"==",w.equal)},w.notEqual=function(t,e,n){t==e&&u(t,e,n,"!=",w.notEqual)},w.deepEqual=function(t,e,n){d(t,e,!1)||u(t,e,n,"deepEqual",w.deepEqual)},w.deepStrictEqual=function(t,e,n){d(t,e,!0)||u(t,e,n,"deepStrictEqual",w.deepStrictEqual)},w.notDeepEqual=function(t,e,n){d(t,e,!1)&&u(t,e,n,"notDeepEqual",w.notDeepEqual)},w.notDeepStrictEqual=p,w.strictEqual=function(t,e,n){t!==e&&u(t,e,n,"===",w.strictEqual)},w.notStrictEqual=function(t,e,n){t===e&&u(t,e,n,"!==",w.notStrictEqual)},w.throws=function(t,e,n){y(!0,t,e,n)},w.doesNotThrow=function(t,e,n){y(!1,t,e,n)},w.ifError=function(t){if(t)throw t};var k=Object.keys||function(t){var e=[];for(var n in t)g.call(t,n)&&e.push(n);return e}}).call(e,n(3))},function(t,e,n){e.asyncMap=n(148),e.bindActor=n(56),e.chain=n(149)},function(t,e,n){(function(e){t.exports=function(){function t(u){u&&!a&&(a=u);for(var h=arguments.length,d=1;dc){var l=r.slice(c);f+=(r.length-c)*o,c=r.length,e.nextTick(function(){l.forEach(function(e){n.forEach(function(n){n(e,t)})})})}0==--f&&i.apply(null,[a].concat(s))}var n=Array.prototype.slice.call(arguments),r=n.shift()||[],i=n.pop();if("function"!=typeof i)throw new Error("No callback provided to asyncMap");if(!r)return i(null,[]);Array.isArray(r)||(r=[r]);var o=n.length,s=[],a=null,c=r.length,f=c*o;if(!f)return i(null,[]);r.forEach(function(e){n.forEach(function(n){n(e,t)})})}}).call(e,n(0))},function(t,e,n){function r(t,e){var n=[];!function o(s,a){return s>=a?e(null,n):(Array.isArray(t[s])&&(t[s]=i.apply(null,t[s].map(function(t){return t===r.first?n[0]:t===r.last?n[n.length-1]:t}))),t[s]?void t[s](function(t,r){if(t)return e(t,n);void 0!==r&&(n=n.concat(r)),o(s+1,a)}):o(s+1,a))}(0,t.length)}t.exports=r;var i=n(56);r.first={},r.last={}},function(t,e,n){!function(){function e(t,r){var i=this instanceof e?this:n;if(i.reset(r),"string"==typeof t&&t.length>0&&i.hash(t),i!==this)return i}var n;e.prototype.hash=function(t){var e,n,r,i,o;switch(o=t.length,this.len+=o,n=this.k1,r=0,this.rem){case 0:n^=o>r?65535&t.charCodeAt(r++):0;case 1:n^=o>r?(65535&t.charCodeAt(r++))<<8:0;case 2:n^=o>r?(65535&t.charCodeAt(r++))<<16:0;case 3:n^=o>r?(255&t.charCodeAt(r))<<24:0,n^=o>r?(65280&t.charCodeAt(r++))>>8:0}if(this.rem=o+this.rem&3,(o-=this.rem)>0){for(e=this.h1;;){if(n=11601*n+3432906752*(65535&n)&4294967295,n=n<<15|n>>>17,n=13715*n+461832192*(65535&n)&4294967295,e^=n,e=e<<13|e>>>19,e=5*e+3864292196&4294967295,r>=o)break;n=65535&t.charCodeAt(r++)^(65535&t.charCodeAt(r++))<<8^(65535&t.charCodeAt(r++))<<16,n^=(255&(i=t.charCodeAt(r++)))<<24^(65280&i)>>8}switch(n=0,this.rem){case 3:n^=(65535&t.charCodeAt(r+2))<<16;case 2:n^=(65535&t.charCodeAt(r+1))<<8;case 1:n^=65535&t.charCodeAt(r)}this.h1=e}return this.k1=n,this},e.prototype.result=function(){var t,e;return t=this.k1,e=this.h1,t>0&&(e^=t=13715*(t=(t=11601*t+3432906752*(65535&t)&4294967295)<<15|t>>>17)+461832192*(65535&t)&4294967295),e^=this.len,e^=e>>>16,e=51819*e+2246770688*(65535&e)&4294967295,e^=e>>>13,e=44597*e+3266445312*(65535&e)&4294967295,(e^=e>>>16)>>>0},e.prototype.reset=function(t){return this.h1="number"==typeof t?t:0,this.rem=this.k1=this.len=0,this},n=new e,t.exports=e}()},function(t,e,n){"use strict";class r{constructor(t){this.id=t,this._index=[]}get(){return this._index}updateIndex(t,e){this._index=t.ops}}t.exports=r},function(t,e,n){const r=n(4).EventEmitter,i=n(40);class o extends r{constructor(t,e=8){super(),this._store=t,this._concurrency=e,this._queue=[],this._fetching={},this._tasksRunning=0,this._have={},this._stats={tasksProcessed:0,tasksRequested:0},this._timer=setInterval(()=>{this._queue.length>0&&this._tasksRunningnull!==t&&void 0!==t).sort((t,e)=>(t.clock?t.clock.time:0)-(e.clock?e.clock.time:0)).forEach(t=>{this._store._oplog.has(t.hash||t)||this._queue.find(e=>(e.hash||e)===(t.hash||t))||(this._queue.splice(0,0,t),this.emit("load.added",t))})}catch(t){console.error(t)}}async _processLoop(){if(this._queue.length>0&&this._tasksRunning{this._queue=this._queue.filter(t=>!this._fetching[t.hash||t]);const t=this._queue.shift();return t&&(this._fetching[t.hash||t]=t),t})();if(t){const e=t.hash||t,n=this._store._oplog.values;this._have=Object.assign({},this._have,this._store._replicationInfo.have),this.emit("load.start",t,this._have);const r=await i.fromEntryHash(this._store._ipfs,e,this._store._oplog.id,1,n,this._store.key,this._store.access.write,this._onSyncProgress.bind(this));this._stats.tasksProcessed+=1,delete this._fetching[e],r.values.forEach(t=>{t.next.length>0&&this.load(t.next)}),this.emit("load.end",r,this._have)}}catch(t){console.error("LOADER-ERROR:",t),this.emit("error",t)}this._tasksRunning--,this.emit("load.complete",this._have)}}_onSyncProgress(t,e,n){this._have[e.clock.time]||(this._have[e.clock.time]=!0,this.emit("load.progress",this._id,t,e,n,this._have))}}t.exports=o},function(t,e,n){"use strict";const r=n(4).EventEmitter;class i extends r{constructor(t,e=1e3){super(),this._loader=t,this._oplog=null,this._interval=e,this._timer=null}start(){this._timer=setInterval(()=>this._checkReplicationStatus(),this._interval)}stop(){clearInterval(this._timer)}replicate(t){this._oplog=t}async _checkReplicationStatus(){if(this._oplog&&0===this._loader._queue.length){this._oplog.tails.filter(t=>t.next.length>0).sort((t,e)=>t.clock.time-e.clock.time).reduce((t,e)=>t.concat(e.next),[]).reduce((t,e)=>(t.includes(e)||t.push(e),t),[]).forEach(t=>{this._loader.load([t])})}}}t.exports=i},function(t,e,n){"use strict";class r{constructor(){this._index=[]}get(){return this._index.values?this._index.values:[]}updateIndex(t){this._index=t}}t.exports=r},function(t,e,n){"use strict";const r=n(34),i=n(156);class o extends r{constructor(t,e,n,r){r||(r={}),r.Index||Object.assign(r,{Index:i}),super(t,e,n,r),this._type="feed"}remove(t){return this.del(t)}del(t){const e={op:"DEL",key:null,value:t};return this._addOperation(e)}}t.exports=o},function(t,e,n){"use strict";class r{constructor(){this._index={}}get(){return Object.keys(this._index).map(t=>this._index[t])}updateIndex(t){this._index={},t.values.reduce((t,e)=>(t.includes(e.hash)||(t.push(e.hash),"ADD"===e.payload.op?this._index[e.hash]=e:"DEL"===e.payload.op&&delete this._index[e.payload.value]),t),[])}}t.exports=r},function(t,e,n){"use strict";const r=n(19),i=n(158);class o extends r{constructor(t,e,n,r){let o=Object.assign({},{Index:i});Object.assign(o,r),super(t,e,n,o),this._type="keyvalue"}get(t){return this._index.get(t)}set(t,e){return this.put(t,e)}put(t,e){return this._addOperation({op:"PUT",key:t,value:e})}del(t){return this._addOperation({op:"DEL",key:t,value:null})}}t.exports=o},function(t,e,n){"use strict";class r{constructor(){this._index={}}get(t){return this._index[t]}updateIndex(t){t.values.slice().reverse().reduce((t,e)=>(t.includes(e.payload.key)||(t.push(e.payload.key),"PUT"===e.payload.op?this._index[e.payload.key]=e.payload.value:"DEL"===e.payload.op&&delete this._index[e.payload.key]),t),[])}}t.exports=r},function(t,e,n){"use strict";const r=n(19),i=n(160);class o extends r{constructor(t,e,n,r={}){r.Index||Object.assign(r,{Index:i}),super(t,e,n,r),this._type="counter"}get value(){return this._index.get().value}inc(t){const e=this._index.get();if(e)return e.increment(t),this._addOperation({op:"COUNTER",key:null,value:e.payload})}}t.exports=o},function(t,e,n){"use strict";const r=n(161);class i{constructor(t){this._index=new r(t)}get(){return this._index}updateIndex(t){this._index&&t.values.filter(t=>t&&"COUNTER"===t.payload.op).map(t=>r.from(t.payload.value)).forEach(t=>this._index.merge(t))}}t.exports=i},function(t,e,n){"use strict";const r=n(162).isEqual;class i{constructor(t,e){this.id=t,this._counters=e||{},this._counters[this.id]=this._counters[this.id]?this._counters[this.id]:0}increment(t){t||(t=1),this._counters[this.id]=this._counters[this.id]+t}get value(){return Object.keys(this._counters).map(t=>this._counters[t]).reduce((t,e)=>t+e,0)}get payload(){return{id:this.id,counters:this._counters}}compare(t){return t.id===this.id&&r(t._counters,this._counters)}merge(t){Object.keys(t._counters).forEach(e=>{this._counters[e]=Math.max(this._counters[e]?this._counters[e]:0,t._counters[e])})}static from(t){return new i(t.id,t.counters)}}t.exports=i},function(t,e,n){"use strict";e.isEqual=((t,e)=>{const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;rt.toString().split(e).join(n));class a extends r{constructor(t,e,n,r){r||(r={}),r.indexBy||Object.assign(r,{indexBy:"_id"}),r.Index||Object.assign(r,{Index:i}),super(t,e,n,r),this._type="docstore"}get(t,e=!1){const n=(t=t.toString()).split(" ");t=n.length>1?s(t,"."," ").toLowerCase():t.toLowerCase();return Object.keys(this._index._index).filter(r=>e?-1!==r.indexOf(t):(e=>n.length>1?-1!==s(e,"."," ").toLowerCase().indexOf(t):-1!==e.toLowerCase().indexOf(t))(r)).map(t=>this._index.get(t))}query(t){return Object.keys(this._index._index).map(t=>this._index.get(t)).filter(e=>t(e))}batchPut(t,e){return o(t,(n,r)=>this._addOperationBatch({op:"PUT",key:n[this.options.indexBy],value:n},!0,r===t.length-1,e),{concurrency:1}).then(()=>this.saveSnapshot())}put(t){if(!t[this.options.indexBy])throw new Error(`The provided document doesn't contain field '${this.options.indexBy}'`);return this._addOperation({op:"PUT",key:t[this.options.indexBy],value:t})}del(t){if(!this._index.get(t))throw new Error(`No entry with key '${t}' in the database`);return this._addOperation({op:"DEL",key:t,value:null})}}t.exports=a},function(t,e,n){"use strict";class r{constructor(){this._index={}}get(t){return this._index[t]}updateIndex(t,e){t.values.slice().reverse().reduce((t,n,r)=>(!0!==t[n.payload.key]&&(t[n.payload.key]=!0,"PUT"===n.payload.op?this._index[n.payload.key]=n.payload.value:"DEL"===n.payload.op&&delete this._index[n.payload.key]),e&&e(n,r),t),{})}}t.exports=r},function(t,e,n){t.exports=n(166)},function(t,e,n){"use strict";(function(e){const r=n(167),i=n(60),o=i.create("orbit-db.ipfs-pubsub");i.setLogLevel("ERROR");let s=0;class a{constructor(t,e){this._ipfs=t,this._id=e,this._subscriptions={},null===this._ipfs.pubsub&&o.error("The provided version of ipfs doesn't have pubsub support. Messages will not be exchanged."),this._handleMessage=this._handleMessage.bind(this),this._ipfs.setMaxListeners(256)}subscribe(t,e,n){if(!this._subscriptions[t]){const i=r(this._ipfs,t);i.on("error",t=>{o.error("Pubsub Error:",t)}),i.on("message",t=>{this._handleMessage(t)}),i.on("peer joined",e=>{this._subscriptions[t].onNewPeer(t,e,i)}),i.on("subscribed",()=>{this._subscriptions[t]={room:i,onMessage:e,onNewPeer:n},s++,o.debug("Topics open:",s)})}}unsubscribe(t){this._subscriptions[t]&&(this._subscriptions[t].room.leave(),this._subscriptions[t].room=null,delete this._subscriptions[t],o.debug(`Unsubscribed from '${t}'`),s--,o.debug("Topics open:",s))}publish(t,n){this._subscriptions[t]&&this._subscriptions[t].room&&this._ipfs.pubsub&&this._subscriptions[t].room.broadcast(new e(JSON.stringify(n)))}disconnect(){Object.keys(this._subscriptions).forEach(t=>this.unsubscribe(t)),this._subscriptions={}}_handleMessage(t){if(t.from===this._id)return;const e=t.topicCIDs[0];let n,r;try{n=JSON.parse(t.data),r=this._subscriptions[e]}catch(e){console.error("Couldn't parse pubsub message:",t.data)}r&&r.onMessage&&n&&r.onMessage(e,n)}}t.exports=a}).call(e,n(1).Buffer)},function(t,e,n){"use strict";(function(e){const r=n(168),i=n(4),o=n(11),s=n(57),a=n(22),c=n(58),f=n(173),u=n(59),h={pollInterval:1e3};t.exports=((t,e,n)=>new d(t,e,n));class d extends i{constructor(t,e,n){if(super(),this._ipfs=t,this._topic=e,this._options=Object.assign({},s(h),s(n)),this._peers=[],this._connections={},!this._ipfs.pubsub)throw new Error("This IPFS node does not have pubsub.");this._ipfs.isOnline()?this._start():this._ipfs.on("ready",this._start.bind(this)),this._ipfs.on("stop",this.leave.bind(this))}getPeers(){return this._peers.slice(0)}hasPeer(t){return this._peers.indexOf(t)>=0}leave(){o.clearInterval(),clearInterval(this._interval),Object.keys(this._connections).forEach(t=>{this._connections[t].stop(),delete this._connections[t]}),this.emit("stop")}broadcast(t){let e=u(t);this._ipfs.pubsub.publish(this._topic,e,t=>{t&&this.emit("error",t)})}sendTo(t,e){let n=this._connections[t];n||((n=new f(t,this._ipfs,this)).on("error",t=>this.emit("error",t)),this._connections[t]=n),n.push(e)}_start(){this._interval=o.setInterval(this._pollPeers.bind(this),this._options.pollInterval);const t=this._onMessage.bind(this);this._ipfs.pubsub.subscribe(this._topic,t,t=>{t?this.emit("error",t):this.emit("subscribed",this._topic)}),this.once("stop",()=>{this._ipfs.state.stopped()&&this._ipfs.pubsub.unsubscribe(this._topic,t)}),this._ipfs._libp2pNode.handle(c,this._handleDirectConnection.bind(this))}_pollPeers(){this._ipfs.pubsub.peers(this._topic,(t,e)=>{if(t)return void this.emit("error",t);const n=e.sort();this._emitChanges(n)&&(this._peers=n)})}_emitChanges(t){const e=r(this._peers,t);return e.added.forEach(t=>this.emit("peer joined",t)),e.removed.forEach(t=>this.emit("peer left",t)),e.added.length>0||e.removed.length>0}_onMessage(t){this.emit("message",t)}_handleDirectConnection(t,n){n.getPeerInfo((t,r)=>{if(t)throw t;const i=r.id.toB58String();a(n,a.map(t=>{const n=e.from([0]);return this.emit("message",{from:i,data:t,seqno:n,topicCIDs:[this._topic]}),t}),a.onEnd(t=>{t&&this.emit("warning",t)}))})}}}).call(e,n(1).Buffer)},function(t,e,n){"use strict";const r=n(57),i=n(169)("hyperdiff"),o=n(172),s=t=>-1!==t;t.exports=function(t,e,n){const{first:a,second:c}={first:t,second:r(e)},f=n?function(t,e,n){return t.findIndex(function(t){return function(t,e,r){return n.every(n=>e[n]===t[n])}(t,e)})}:function(t,e,n){return t.indexOf(e)};i("preconditions first=%j second=%j findIndex=%s",a,c,f.name);const u=a.reduce(function(t,e,r){const a=f(c,e,n),u=s(a)?"common":"removed";return t[u].push(e),o(c,a),i("index=%s value=%s collection=%s",r,e,u),t},{common:[],removed:[]});return u.added=c,i("added=%j removed=%j common%j",u.added,u.removed,u.common),u}},function(t,e,n){(function(r){function i(){var t;try{t=e.storage.debug}catch(t){}return!t&&void 0!==r&&"env"in r&&(t=Object({NODE_ENV:void 0}).DEBUG),t}(e=t.exports=n(170)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},e.formatArgs=function(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var i=0,o=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(i++,"%c"===t&&(o=i))}),t.splice(o,0,r)}},e.save=function(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}},e.load=i,e.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(i())}).call(e,n(0))},function(t,e,n){function r(t){function n(){if(n.enabled){var t=n,i=+new Date,o=i-(r||i);t.diff=o,t.prev=r,t.curr=i,r=i;for(var s=new Array(arguments.length),a=0;a0)return function(t){if(!((t=String(t)).length>100)){var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(e){var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*a;case"days":case"day":case"d":return n*s;case"hours":case"hour":case"hrs":case"hr":case"h":return n*o;case"minutes":case"minute":case"mins":case"min":case"m":return n*i;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}(t);if("number"===c&&!1===isNaN(t))return e.long?function(t){return n(t,s,"day")||n(t,o,"hour")||n(t,i,"minute")||n(t,r,"second")||t+" ms"}(t):function(t){return t>=s?Math.round(t/s)+"d":t>=o?Math.round(t/o)+"h":t>=i?Math.round(t/i)+"m":t>=r?Math.round(t/r)+"s":t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){(function(e){function n(t,e){for(var n=-1,r=e.length,i=t.length;++n0&&r(f)?e>1?c(f,e-1,r,i,o):n(o,f):i||(o[o.length]=f)}return o}function f(t,e){for(var n=0,r=(e=g(e,t)?[e]:d(e)).length;null!=t&&ni?0:i+e);(n=n>i?i:n)<0&&(n+=i);i=e>n?0:n-e>>>0,e>>>=0;var o=Array(i);for(;++re||o&&s&&c&&!a&&!f||r&&s&&c||!n&&c||!i)return 1;if(!r&&!o&&!f&&t-1&&t%1==0&&t<=I}(t.length)&&!w(t)}(t)}(t)&&V.call(t,"callee")&&(!tt.call(t,"callee")||X.call(t)==P)}(t)||!!(nt&&t&&t[nt])}function m(t,e){return!!(e=null==e?I:e)&&("number"==typeof t||q.test(t))&&t>-1&&t%1==0&&t-1},i.prototype.set=function(t,e){var n=this.__data__,r=s(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},o.prototype.clear=function(){this.__data__={hash:new r,map:new(it||i),string:new r}},o.prototype.delete=function(t){return p(this,t).delete(t)},o.prototype.get=function(t){return p(this,t).get(t)},o.prototype.has=function(t){return p(this,t).has(t)},o.prototype.set=function(t,e){return p(this,t).set(t,e),this};var ct=_(function(t){t=E(t);var e=[];return L.test(t)&&e.push(""),t.replace(D,function(t,n,r,i){e.push(r?i.replace(B,"$1"):n||t)}),e}),ft=function(t,e){return e=rt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,r=-1,i=rt(n.length-e,0),o=Array(i);++r{this.push(t)}))}stop(){this._connection&&this._connection.end()}_getConnection(){this._connecting=!0,this._getPeerAddresses(this._id,(t,e)=>{t?this.emit("error",t):e.length?this._ipfs._libp2pNode.dial(e[0],s,(t,e)=>{if(t)return void this.emit("error",t);this._connecting=!1;const n=o(!1,t=>{this._closed=!0,t&&this.emit("error",t)});this._connection=n,i(n,e,i.onEnd(t=>{delete this._connection,t&&!this._closed&&this.emit("error",t)})),this.emit("connect",n)}):this.emit("error",new Error("could not connect to "+this._id))})}_getPeerAddresses(t,e){this._ipfs.swarm.peers((n,r)=>{n?e(n):e(null,r.filter(e=>e.peer.id.toB58String()===t).map(t=>t.peer))})}}},function(t,e,n){"use strict";(function(e){const r=n(175);class i extends r{constructor(t){super(),this._ipfs=t}async load(t){0===t.indexOf("/ipfs")&&(t=t.split("/")[2]);try{const e=await this._ipfs.object.get(t),n=JSON.parse(e.toJSON().data);this._access=n}catch(t){console.log("ACCESS ERROR:",t)}}async save(){let t;try{const n=JSON.stringify(this._access,null,2);t=(await this._ipfs.object.put(new e(n))).toJSON().multihash.toString()}catch(t){console.log("ACCESS ERROR:",t)}return t}}t.exports=i}).call(e,n(1).Buffer)},function(t,e,n){"use strict";class r{constructor(){this._access={admin:[],write:[],read:[]}}async load(t){}async save(){}get admin(){return this._access.admin}get write(){return this._access.write.concat(this._access.admin)}get read(){return this._access.read}add(t,e){switch(t){case"admin":this._access.admin.push(e);break;case"write":this._access.write.push(e);break;case"read":this._access.read.push(e)}}remove(t,e){const n=(t,n)=>{return t.reduce((t,n)=>(n!==e&&t.push(n),t),[])};switch(t){case"admin":this._access.admin=n(this._access.admin);break;case"write":this._access.write=n(this._access.write);break;case"read":this._access.read=n(this._access.read)}}}t.exports=r},function(t,e,n){"use strict";const r=n(12),i=n(177);class o{constructor(t,e){this.root=t,this.path=e}toString(){return r.join("/orbitdb",this.root,this.path)}static isValid(t){const e=t.toString().split("/").filter((e,n)=>!((0===n||1===n)&&0===t.toString().indexOf("/orbit")&&"orbitdb"===e)).filter(t=>""!==t&&" "!==t),n=e[0].indexOf("Qm")>-1?i.fromB58String(e[0]):null;try{i.validate(n)}catch(t){return!1}return null!==n}static parse(t){if(!t)throw new Error(`Not a valid OrbitDB address: ${t}`);if(!o.isValid(t))throw new Error(`Not a valid OrbitDB address: ${t}`);const e=t.toString().split("/").filter((e,n)=>!((0===n||1===n)&&0===t.toString().indexOf("/orbit")&&"orbitdb"===e)).filter(t=>""!==t&&" "!==t);return new o(e[0],e.slice(1,e.length).join("/"))}}t.exports=o},function(t,e,n){"use strict";(function(t){function r(t){e.decode(t)}const i=n(178),o=n(180);e.names=o.names,e.codes=o.codes,e.defaultLengths=o.defaultLengths;const s=n(181);e.toHexString=function(e){if(!t.isBuffer(e))throw new Error("must be passed a buffer");return e.toString("hex")},e.fromHexString=function(e){return t.from(e,"hex")},e.toB58String=function(e){if(!t.isBuffer(e))throw new Error("must be passed a buffer");return i.encode(e)},e.fromB58String=function(e){let n=e;return t.isBuffer(e)&&(n=e.toString()),t.from(i.decode(n))},e.decode=function(n){if(!t.isBuffer(n))throw new Error("multihash must be a Buffer");if(n.length<3)throw new Error("multihash too short. must be > 3 bytes.");let r=s.decode(n);if(!e.isValidCode(r))throw new Error(`multihash unknown function code: 0x${r.toString(16)}`);n=n.slice(s.decode.bytes);let i=s.decode(n);if(i<1)throw new Error(`multihash invalid length: 0x${i.toString(16)}`);if((n=n.slice(s.decode.bytes)).length!==i)throw new Error(`multihash length inconsistent: 0x${n.toString("hex")}`);return{code:r,name:o.codes[r],length:i,digest:n}},e.encode=function(n,r,i){if(!n||!r)throw new Error("multihash encode requires at least two args: digest, code");const o=e.coerceCode(r);if(!t.isBuffer(n))throw new Error("digest should be a Buffer");if(null==i&&(i=n.length),i&&n.length!==i)throw new Error("digest length should be equal to specified length.");return t.concat([t.from(s.encode(o)),t.from(s.encode(i)),n])},e.coerceCode=function(t){let n=t;if("string"==typeof t){if(!o.names[t])throw new Error(`Unrecognized hash function named: ${t}`);n=o.names[t]}if("number"!=typeof n)throw new Error(`Hash function code should be a number. Got: ${n}`);if(!o.codes[n]&&!e.isAppCode(n))throw new Error(`Unrecognized function code: ${n}`);return n},e.isAppCode=function(t){return t>0&&t<16},e.isValidCode=function(t){return!!e.isAppCode(t)||!!o.codes[t]},e.validate=r,e.prefix=function(t){return r(t),t.slice(0,2)}}).call(e,n(1).Buffer)},function(t,e,n){var r=n(179);t.exports=r("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},function(t,e,n){var r=n(10).Buffer;t.exports=function(t){function e(t){if(0===t.length)return r.allocUnsafe(0);for(var e=[0],s=0;s>=8;for(;f>0;)e.push(255&f),f>>=8}for(var u=0;t[u]===o&&u0;)n.push(s%i),s=s/i|0}for(var a="",c=0;0===e[c]&&c=0;--f)a+=t[n[f]];return a},decodeUnsafe:e,decode:function(t){var n=e(t);if(n)return n;throw new Error("Non-base"+i+" character")}}}},function(t,e,n){"use strict";e.names=Object.freeze({sha1:17,"sha2-256":18,"sha2-512":19,"sha3-224":23,"sha3-256":22,"sha3-384":21,"sha3-512":20,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,"murmur3-128":34,"murmur3-32":35,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"Skein256-8":45825,"Skein256-16":45826,"Skein256-24":45827,"Skein256-32":45828,"Skein256-40":45829,"Skein256-48":45830,"Skein256-56":45831,"Skein256-64":45832,"Skein256-72":45833,"Skein256-80":45834,"Skein256-88":45835,"Skein256-96":45836,"Skein256-104":45837,"Skein256-112":45838,"Skein256-120":45839,"Skein256-128":45840,"Skein256-136":45841,"Skein256-144":45842,"Skein256-152":45843,"Skein256-160":45844,"Skein256-168":45845,"Skein256-176":45846,"Skein256-184":45847,"Skein256-192":45848,"Skein256-200":45849,"Skein256-208":45850,"Skein256-216":45851,"Skein256-224":45852,"Skein256-232":45853,"Skein256-240":45854,"Skein256-248":45855,"Skein256-256":45856,"Skein512-8":45857,"Skein512-16":45858,"Skein512-24":45859,"Skein512-32":45860,"Skein512-40":45861,"Skein512-48":45862,"Skein512-56":45863,"Skein512-64":45864,"Skein512-72":45865,"Skein512-80":45866,"Skein512-88":45867,"Skein512-96":45868,"Skein512-104":45869,"Skein512-112":45870,"Skein512-120":45871,"Skein512-128":45872,"Skein512-136":45873,"Skein512-144":45874,"Skein512-152":45875,"Skein512-160":45876,"Skein512-168":45877,"Skein512-176":45878,"Skein512-184":45879,"Skein512-192":45880,"Skein512-200":45881,"Skein512-208":45882,"Skein512-216":45883,"Skein512-224":45884,"Skein512-232":45885,"Skein512-240":45886,"Skein512-248":45887,"Skein512-256":45888,"Skein512-264":45889,"Skein512-272":45890,"Skein512-280":45891,"Skein512-288":45892,"Skein512-296":45893,"Skein512-304":45894,"Skein512-312":45895,"Skein512-320":45896,"Skein512-328":45897,"Skein512-336":45898,"Skein512-344":45899,"Skein512-352":45900,"Skein512-360":45901,"Skein512-368":45902,"Skein512-376":45903,"Skein512-384":45904,"Skein512-392":45905,"Skein512-400":45906,"Skein512-408":45907,"Skein512-416":45908,"Skein512-424":45909,"Skein512-432":45910,"Skein512-440":45911,"Skein512-448":45912,"Skein512-456":45913,"Skein512-464":45914,"Skein512-472":45915,"Skein512-480":45916,"Skein512-488":45917,"Skein512-496":45918,"Skein512-504":45919,"Skein512-512":45920,"Skein1024-8":45921,"Skein1024-16":45922,"Skein1024-24":45923,"Skein1024-32":45924,"Skein1024-40":45925,"Skein1024-48":45926,"Skein1024-56":45927,"Skein1024-64":45928,"Skein1024-72":45929,"Skein1024-80":45930,"Skein1024-88":45931,"Skein1024-96":45932,"Skein1024-104":45933,"Skein1024-112":45934,"Skein1024-120":45935,"Skein1024-128":45936,"Skein1024-136":45937,"Skein1024-144":45938,"Skein1024-152":45939,"Skein1024-160":45940,"Skein1024-168":45941,"Skein1024-176":45942,"Skein1024-184":45943,"Skein1024-192":45944,"Skein1024-200":45945,"Skein1024-208":45946,"Skein1024-216":45947,"Skein1024-224":45948,"Skein1024-232":45949,"Skein1024-240":45950,"Skein1024-248":45951,"Skein1024-256":45952,"Skein1024-264":45953,"Skein1024-272":45954,"Skein1024-280":45955,"Skein1024-288":45956,"Skein1024-296":45957,"Skein1024-304":45958,"Skein1024-312":45959,"Skein1024-320":45960,"Skein1024-328":45961,"Skein1024-336":45962,"Skein1024-344":45963,"Skein1024-352":45964,"Skein1024-360":45965,"Skein1024-368":45966,"Skein1024-376":45967,"Skein1024-384":45968,"Skein1024-392":45969,"Skein1024-400":45970,"Skein1024-408":45971,"Skein1024-416":45972,"Skein1024-424":45973,"Skein1024-432":45974,"Skein1024-440":45975,"Skein1024-448":45976,"Skein1024-456":45977,"Skein1024-464":45978,"Skein1024-472":45979,"Skein1024-480":45980,"Skein1024-488":45981,"Skein1024-496":45982,"Skein1024-504":45983,"Skein1024-512":45984,"Skein1024-520":45985,"Skein1024-528":45986,"Skein1024-536":45987,"Skein1024-544":45988,"Skein1024-552":45989,"Skein1024-560":45990,"Skein1024-568":45991,"Skein1024-576":45992,"Skein1024-584":45993,"Skein1024-592":45994,"Skein1024-600":45995,"Skein1024-608":45996,"Skein1024-616":45997,"Skein1024-624":45998,"Skein1024-632":45999,"Skein1024-640":46e3,"Skein1024-648":46001,"Skein1024-656":46002,"Skein1024-664":46003,"Skein1024-672":46004,"Skein1024-680":46005,"Skein1024-688":46006,"Skein1024-696":46007,"Skein1024-704":46008,"Skein1024-712":46009,"Skein1024-720":46010,"Skein1024-728":46011,"Skein1024-736":46012,"Skein1024-744":46013,"Skein1024-752":46014,"Skein1024-760":46015,"Skein1024-768":46016,"Skein1024-776":46017,"Skein1024-784":46018,"Skein1024-792":46019,"Skein1024-800":46020,"Skein1024-808":46021,"Skein1024-816":46022,"Skein1024-824":46023,"Skein1024-832":46024,"Skein1024-840":46025,"Skein1024-848":46026,"Skein1024-856":46027,"Skein1024-864":46028,"Skein1024-872":46029,"Skein1024-880":46030,"Skein1024-888":46031,"Skein1024-896":46032,"Skein1024-904":46033,"Skein1024-912":46034,"Skein1024-920":46035,"Skein1024-928":46036,"Skein1024-936":46037,"Skein1024-944":46038,"Skein1024-952":46039,"Skein1024-960":46040,"Skein1024-968":46041,"Skein1024-976":46042,"Skein1024-984":46043,"Skein1024-992":46044,"Skein1024-1000":46045,"Skein1024-1008":46046,"Skein1024-1016":46047,"Skein1024-1024":46048}),e.codes=Object.freeze({17:"sha1",18:"sha2-256",19:"sha2-512",23:"sha3-224",22:"sha3-256",21:"sha3-384",20:"sha3-512",24:"shake-128",25:"shake-256",26:"keccak-224",27:"keccak-256",28:"keccak-384",29:"keccak-512",34:"murmur3-128",35:"murmur3-32",45569:"blake2b-8",45570:"blake2b-16",45571:"blake2b-24",45572:"blake2b-32",45573:"blake2b-40",45574:"blake2b-48",45575:"blake2b-56",45576:"blake2b-64",45577:"blake2b-72",45578:"blake2b-80",45579:"blake2b-88",45580:"blake2b-96",45581:"blake2b-104",45582:"blake2b-112",45583:"blake2b-120",45584:"blake2b-128",45585:"blake2b-136",45586:"blake2b-144",45587:"blake2b-152",45588:"blake2b-160",45589:"blake2b-168",45590:"blake2b-176",45591:"blake2b-184",45592:"blake2b-192",45593:"blake2b-200",45594:"blake2b-208",45595:"blake2b-216",45596:"blake2b-224",45597:"blake2b-232",45598:"blake2b-240",45599:"blake2b-248",45600:"blake2b-256",45601:"blake2b-264",45602:"blake2b-272",45603:"blake2b-280",45604:"blake2b-288",45605:"blake2b-296",45606:"blake2b-304",45607:"blake2b-312",45608:"blake2b-320",45609:"blake2b-328",45610:"blake2b-336",45611:"blake2b-344",45612:"blake2b-352",45613:"blake2b-360",45614:"blake2b-368",45615:"blake2b-376",45616:"blake2b-384",45617:"blake2b-392",45618:"blake2b-400",45619:"blake2b-408",45620:"blake2b-416",45621:"blake2b-424",45622:"blake2b-432",45623:"blake2b-440",45624:"blake2b-448",45625:"blake2b-456",45626:"blake2b-464",45627:"blake2b-472",45628:"blake2b-480",45629:"blake2b-488",45630:"blake2b-496",45631:"blake2b-504",45632:"blake2b-512",45633:"blake2s-8",45634:"blake2s-16",45635:"blake2s-24",45636:"blake2s-32",45637:"blake2s-40",45638:"blake2s-48",45639:"blake2s-56",45640:"blake2s-64",45641:"blake2s-72",45642:"blake2s-80",45643:"blake2s-88",45644:"blake2s-96",45645:"blake2s-104",45646:"blake2s-112",45647:"blake2s-120",45648:"blake2s-128",45649:"blake2s-136",45650:"blake2s-144",45651:"blake2s-152",45652:"blake2s-160",45653:"blake2s-168",45654:"blake2s-176",45655:"blake2s-184",45656:"blake2s-192",45657:"blake2s-200",45658:"blake2s-208",45659:"blake2s-216",45660:"blake2s-224",45661:"blake2s-232",45662:"blake2s-240",45663:"blake2s-248",45664:"blake2s-256",45825:"Skein256-8",45826:"Skein256-16",45827:"Skein256-24",45828:"Skein256-32",45829:"Skein256-40",45830:"Skein256-48",45831:"Skein256-56",45832:"Skein256-64",45833:"Skein256-72",45834:"Skein256-80",45835:"Skein256-88",45836:"Skein256-96",45837:"Skein256-104",45838:"Skein256-112",45839:"Skein256-120",45840:"Skein256-128",45841:"Skein256-136",45842:"Skein256-144",45843:"Skein256-152",45844:"Skein256-160",45845:"Skein256-168",45846:"Skein256-176",45847:"Skein256-184",45848:"Skein256-192",45849:"Skein256-200",45850:"Skein256-208",45851:"Skein256-216",45852:"Skein256-224",45853:"Skein256-232",45854:"Skein256-240",45855:"Skein256-248",45856:"Skein256-256",45857:"Skein512-8",45858:"Skein512-16",45859:"Skein512-24",45860:"Skein512-32",45861:"Skein512-40",45862:"Skein512-48",45863:"Skein512-56",45864:"Skein512-64",45865:"Skein512-72",45866:"Skein512-80",45867:"Skein512-88",45868:"Skein512-96",45869:"Skein512-104",45870:"Skein512-112",45871:"Skein512-120",45872:"Skein512-128",45873:"Skein512-136",45874:"Skein512-144",45875:"Skein512-152",45876:"Skein512-160",45877:"Skein512-168",45878:"Skein512-176",45879:"Skein512-184",45880:"Skein512-192",45881:"Skein512-200",45882:"Skein512-208",45883:"Skein512-216",45884:"Skein512-224",45885:"Skein512-232",45886:"Skein512-240",45887:"Skein512-248",45888:"Skein512-256",45889:"Skein512-264",45890:"Skein512-272",45891:"Skein512-280",45892:"Skein512-288",45893:"Skein512-296",45894:"Skein512-304",45895:"Skein512-312",45896:"Skein512-320",45897:"Skein512-328",45898:"Skein512-336",45899:"Skein512-344",45900:"Skein512-352",45901:"Skein512-360",45902:"Skein512-368",45903:"Skein512-376",45904:"Skein512-384",45905:"Skein512-392",45906:"Skein512-400",45907:"Skein512-408",45908:"Skein512-416",45909:"Skein512-424",45910:"Skein512-432",45911:"Skein512-440",45912:"Skein512-448",45913:"Skein512-456",45914:"Skein512-464",45915:"Skein512-472",45916:"Skein512-480",45917:"Skein512-488",45918:"Skein512-496",45919:"Skein512-504",45920:"Skein512-512",45921:"Skein1024-8",45922:"Skein1024-16",45923:"Skein1024-24",45924:"Skein1024-32",45925:"Skein1024-40",45926:"Skein1024-48",45927:"Skein1024-56",45928:"Skein1024-64",45929:"Skein1024-72",45930:"Skein1024-80",45931:"Skein1024-88",45932:"Skein1024-96",45933:"Skein1024-104",45934:"Skein1024-112",45935:"Skein1024-120",45936:"Skein1024-128",45937:"Skein1024-136",45938:"Skein1024-144",45939:"Skein1024-152",45940:"Skein1024-160",45941:"Skein1024-168",45942:"Skein1024-176",45943:"Skein1024-184",45944:"Skein1024-192",45945:"Skein1024-200",45946:"Skein1024-208",45947:"Skein1024-216",45948:"Skein1024-224",45949:"Skein1024-232",45950:"Skein1024-240",45951:"Skein1024-248",45952:"Skein1024-256",45953:"Skein1024-264",45954:"Skein1024-272",45955:"Skein1024-280",45956:"Skein1024-288",45957:"Skein1024-296",45958:"Skein1024-304",45959:"Skein1024-312",45960:"Skein1024-320",45961:"Skein1024-328",45962:"Skein1024-336",45963:"Skein1024-344",45964:"Skein1024-352",45965:"Skein1024-360",45966:"Skein1024-368",45967:"Skein1024-376",45968:"Skein1024-384",45969:"Skein1024-392",45970:"Skein1024-400",45971:"Skein1024-408",45972:"Skein1024-416",45973:"Skein1024-424",45974:"Skein1024-432",45975:"Skein1024-440",45976:"Skein1024-448",45977:"Skein1024-456",45978:"Skein1024-464",45979:"Skein1024-472",45980:"Skein1024-480",45981:"Skein1024-488",45982:"Skein1024-496",45983:"Skein1024-504",45984:"Skein1024-512",45985:"Skein1024-520",45986:"Skein1024-528",45987:"Skein1024-536",45988:"Skein1024-544",45989:"Skein1024-552",45990:"Skein1024-560",45991:"Skein1024-568",45992:"Skein1024-576",45993:"Skein1024-584",45994:"Skein1024-592",45995:"Skein1024-600",45996:"Skein1024-608",45997:"Skein1024-616",45998:"Skein1024-624",45999:"Skein1024-632",46e3:"Skein1024-640",46001:"Skein1024-648",46002:"Skein1024-656",46003:"Skein1024-664",46004:"Skein1024-672",46005:"Skein1024-680",46006:"Skein1024-688",46007:"Skein1024-696",46008:"Skein1024-704",46009:"Skein1024-712",46010:"Skein1024-720",46011:"Skein1024-728",46012:"Skein1024-736",46013:"Skein1024-744",46014:"Skein1024-752",46015:"Skein1024-760",46016:"Skein1024-768",46017:"Skein1024-776",46018:"Skein1024-784",46019:"Skein1024-792",46020:"Skein1024-800",46021:"Skein1024-808",46022:"Skein1024-816",46023:"Skein1024-824",46024:"Skein1024-832",46025:"Skein1024-840",46026:"Skein1024-848",46027:"Skein1024-856",46028:"Skein1024-864",46029:"Skein1024-872",46030:"Skein1024-880",46031:"Skein1024-888",46032:"Skein1024-896",46033:"Skein1024-904",46034:"Skein1024-912",46035:"Skein1024-920",46036:"Skein1024-928",46037:"Skein1024-936",46038:"Skein1024-944",46039:"Skein1024-952",46040:"Skein1024-960",46041:"Skein1024-968",46042:"Skein1024-976",46043:"Skein1024-984",46044:"Skein1024-992",46045:"Skein1024-1000",46046:"Skein1024-1008",46047:"Skein1024-1016",46048:"Skein1024-1024"}),e.defaultLengths=Object.freeze({17:20,18:32,19:64,23:28,22:32,21:48,20:64,24:32,25:64,26:28,27:32,28:48,29:64,34:32,45569:1,45570:2,45571:3,45572:4,45573:5,45574:6,45575:7,45576:8,45577:9,45578:10,45579:11,45580:12,45581:13,45582:14,45583:15,45584:16,45585:17,45586:18,45587:19,45588:20,45589:21,45590:22,45591:23,45592:24,45593:25,45594:26,45595:27,45596:28,45597:29,45598:30,45599:31,45600:32,45601:33,45602:34,45603:35,45604:36,45605:37,45606:38,45607:39,45608:40,45609:41,45610:42,45611:43,45612:44,45613:45,45614:46,45615:47,45616:48,45617:49,45618:50,45619:51,45620:52,45621:53,45622:54,45623:55,45624:56,45625:57,45626:58,45627:59,45628:60,45629:61,45630:62,45631:63,45632:64,45633:1,45634:2,45635:3,45636:4,45637:5,45638:6,45639:7,45640:8,45641:9,45642:10,45643:11,45644:12,45645:13,45646:14,45647:15,45648:16,45649:17,45650:18,45651:19,45652:20,45653:21,45654:22,45655:23,45656:24,45657:25,45658:26,45659:27,45660:28,45661:29,45662:30,45663:31,45664:32,45825:1,45826:2,45827:3,45828:4,45829:5,45830:6,45831:7,45832:8,45833:9,45834:10,45835:11,45836:12,45837:13,45838:14,45839:15,45840:16,45841:17,45842:18,45843:19,45844:20,45845:21,45846:22,45847:23,45848:24,45849:25,45850:26,45851:27,45852:28,45853:29,45854:30,45855:31,45856:32,45857:1,45858:2,45859:3,45860:4,45861:5,45862:6,45863:7,45864:8,45865:9,45866:10,45867:11,45868:12,45869:13,45870:14,45871:15,45872:16,45873:17,45874:18,45875:19,45876:20,45877:21,45878:22,45879:23,45880:24,45881:25,45882:26,45883:27,45884:28,45885:29,45886:30,45887:31,45888:32,45889:33,45890:34,45891:35,45892:36,45893:37,45894:38,45895:39,45896:40,45897:41,45898:42,45899:43,45900:44,45901:45,45902:46,45903:47,45904:48,45905:49,45906:50,45907:51,45908:52,45909:53,45910:54,45911:55,45912:56,45913:57,45914:58,45915:59,45916:60,45917:61,45918:62,45919:63,45920:64,45921:1,45922:2,45923:3,45924:4,45925:5,45926:6,45927:7,45928:8,45929:9,45930:10,45931:11,45932:12,45933:13,45934:14,45935:15,45936:16,45937:17,45938:18,45939:19,45940:20,45941:21,45942:22,45943:23,45944:24,45945:25,45946:26,45947:27,45948:28,45949:29,45950:30,45951:31,45952:32,45953:33,45954:34,45955:35,45956:36,45957:37,45958:38,45959:39,45960:40,45961:41,45962:42,45963:43,45964:44,45965:45,45966:46,45967:47,45968:48,45969:49,45970:50,45971:51,45972:52,45973:53,45974:54,45975:55,45976:56,45977:57,45978:58,45979:59,45980:60,45981:61,45982:62,45983:63,45984:64,45985:65,45986:66,45987:67,45988:68,45989:69,45990:70,45991:71,45992:72,45993:73,45994:74,45995:75,45996:76,45997:77,45998:78,45999:79,46e3:80,46001:81,46002:82,46003:83,46004:84,46005:85,46006:86,46007:87,46008:88,46009:89,46010:90,46011:91,46012:92,46013:93,46014:94,46015:95,46016:96,46017:97,46018:98,46019:99,46020:100,46021:101,46022:102,46023:103,46024:104,46025:105,46026:106,46027:107,46028:108,46029:109,46030:110,46031:111,46032:112,46033:113,46034:114,46035:115,46036:116,46037:117,46038:118,46039:119,46040:120,46041:121,46042:122,46043:123,46044:124,46045:125,46046:126,46047:127,46048:128})},function(t,e,n){t.exports={encode:n(182),decode:n(183),encodingLength:n(184)}},function(t,e){function n(t,e,s){e=e||[];for(var a=s=s||0;t>=o;)e[s++]=255&t|r,t/=128;for(;t&i;)e[s++]=255&t|r,t>>>=7;return e[s]=0|t,n.bytes=s-a+1,e}t.exports=n;var r=128,i=-128,o=Math.pow(2,31)},function(t,e){function n(t,e){var o,s=0,a=0,c=e=e||0,f=t.length;do{if(c>=f)throw n.bytes=0,new RangeError("Could not decode varint");o=t[c++],s+=a<28?(o&i)<=r);return n.bytes=c-e,s}t.exports=n;var r=128,i=127},function(t,e){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),o=Math.pow(2,28),s=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),f=Math.pow(2,56),u=Math.pow(2,63);t.exports=function(t){return t=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|t}function h(t,e){if(o.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return P(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return C(t).length;default:if(r)return P(t).length;e=(""+e).toLowerCase(),r=!0}}function d(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return function(t,e,n){var r=t.length;(!e||e<0)&&(e=0);(!n||n<0||n>r)&&(n=r);for(var i="",o=e;o2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=o.from(e,r)),o.isBuffer(e))return 0===e.length?-1:b(t,e,n,r,i);if("number"==typeof e)return e&=255,o.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):b(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,n,r,i){function o(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}var f;if(i){var u=-1;for(f=n;fa&&(n=a-c),f=n;f>=0;f--){for(var h=!0,d=0;di&&(r=i):r=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s>8,i=n%256,o.push(i),o.push(r);return o}(e,t.length-n),t,n,r)}function S(t,e,n){n=Math.min(t.length,n);for(var r=[],i=e;i239?4:o>223?3:o>191?2:1;if(i+a<=n){var c,f,u,h;switch(a){case 1:o<128&&(s=o);break;case 2:128==(192&(c=t[i+1]))&&(h=(31&o)<<6|63&c)>127&&(s=h);break;case 3:c=t[i+1],f=t[i+2],128==(192&c)&&128==(192&f)&&(h=(15&o)<<12|(63&c)<<6|63&f)>2047&&(h<55296||h>57343)&&(s=h);break;case 4:c=t[i+1],f=t[i+2],u=t[i+3],128==(192&c)&&128==(192&f)&&128==(192&u)&&(h=(15&o)<<18|(63&c)<<12|(63&f)<<6|63&u)>65535&&h<1114112&&(s=h)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=a}return function(t){var e=t.length;if(e<=L)return String.fromCharCode.apply(String,t);var n="",r=0;for(;rn)throw new RangeError("Trying to access beyond buffer length")}function x(t,e,n,r,i,s){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function E(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-n,2);i>>8*(r?i:1-i)}function M(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-n,4);i>>8*(r?i:3-i)&255}function A(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function O(t,e,n,r,i){return i||A(t,0,n,4),j.write(t,e,n,r,23,4),n+4}function I(t,e,n,r,i){return i||A(t,0,n,8),j.write(t,e,n,r,52,8),n+8}function P(t,e){e=e||1/0;for(var n,r=t.length,i=null,o=[],s=0;s55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function C(t){return R.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(D,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function N(t,e,n,r){for(var i=0;i=e.length||i>=t.length);++i)e[i+n]=t[i];return i}var R=n(62),j=n(63),T=n(33);e.Buffer=o,e.SlowBuffer=function(t){return+t!=t&&(t=0),o.alloc(+t)},e.INSPECT_MAX_BYTES=50,o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=r(),o.poolSize=8192,o._augment=function(t){return t.__proto__=o.prototype,t},o.from=function(t,e,n){return s(null,t,e,n)},o.TYPED_ARRAY_SUPPORT&&(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0})),o.alloc=function(t,e,n){return function(t,e,n,r){return a(e),e<=0?i(t,e):void 0!==n?"string"==typeof r?i(t,e).fill(n,r):i(t,e).fill(n):i(t,e)}(null,t,e,n)},o.allocUnsafe=function(t){return c(null,t)},o.allocUnsafeSlow=function(t){return c(null,t)},o.isBuffer=function(t){return!(null==t||!t._isBuffer)},o.compare=function(t,e){if(!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,i=0,s=Math.min(n,r);i0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},o.prototype.compare=function(t,e,n,r,i){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,i>>>=0,this===t)return 0;for(var s=i-r,a=n-e,c=Math.min(s,a),f=this.slice(r,i),u=t.slice(e,n),h=0;hi)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return y(this,t,e,n);case"utf8":case"utf-8":return g(this,t,e,n);case"ascii":return m(this,t,e,n);case"latin1":case"binary":return v(this,t,e,n);case"base64":return _(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,t,e,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var L=4096;o.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(i*=256);)r+=this[t+--e]*i;return r},o.prototype.readUInt8=function(t,e){return e||k(t,1,this.length),this[t]},o.prototype.readUInt16LE=function(t,e){return e||k(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUInt16BE=function(t,e){return e||k(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUInt32LE=function(t,e){return e||k(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUInt32BE=function(t,e){return e||k(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=this[t],i=1,o=0;++o=i&&(r-=Math.pow(2,8*e)),r},o.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||k(t,e,this.length);for(var r=e,i=1,o=this[t+--r];r>0&&(i*=256);)o+=this[t+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},o.prototype.readInt8=function(t,e){return e||k(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){e||k(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(t,e){e||k(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(t,e){return e||k(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return e||k(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,e){return e||k(t,4,this.length),j.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return e||k(t,4,this.length),j.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return e||k(t,8,this.length),j.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return e||k(t,8,this.length),j.read(this,t,!1,52,8)},o.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){x(this,t,e,n,Math.pow(2,8*n)-1,0)}var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+n},o.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,1,255,0),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},o.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):E(this,t,e,!0),e+2},o.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):E(this,t,e,!1),e+2},o.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):M(this,t,e,!0),e+4},o.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},o.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);x(this,t,e,n,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+n},o.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);x(this,t,e,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+n},o.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,1,127,-128),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):E(this,t,e,!0),e+2},o.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):E(this,t,e,!1),e+2},o.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):M(this,t,e,!0),e+4},o.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||x(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):M(this,t,e,!1),e+4},o.prototype.writeFloatLE=function(t,e,n){return O(this,t,e,!0,n)},o.prototype.writeFloatBE=function(t,e,n){return O(this,t,e,!1,n)},o.prototype.writeDoubleLE=function(t,e,n){return I(this,t,e,!0,n)},o.prototype.writeDoubleBE=function(t,e,n){return I(this,t,e,!1,n)},o.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--i)t[i+e]=this[i+n];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var s;if("number"==typeof t)for(s=e;s1)for(var n=1;n0&&this._events[t].length>s&&(this._events[t].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[t].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),i||(i=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var i=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,o,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,o=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(i(n)){for(a=s;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){o=a;break}if(o<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e,n){"use strict";function r(t){return(t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function i(t){return 1===t.length?"0"+t:t}function o(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}var s=n(9),a=n(5);e.inherits=a,e.toArray=function(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var n=[];if("string"==typeof t)if(e){if("hex"===e)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),r=0;r>8,s=255&i;o?n.push(o,s):n.push(s)}else for(r=0;r>>0}return o},e.split32=function(t,e){for(var n=new Array(4*t.length),r=0,i=0;r>>24,n[i+1]=o>>>16&255,n[i+2]=o>>>8&255,n[i+3]=255&o):(n[i+3]=o>>>24,n[i+2]=o>>>16&255,n[i+1]=o>>>8&255,n[i]=255&o)}return n},e.rotr32=function(t,e){return t>>>e|t<<32-e},e.rotl32=function(t,e){return t<>>32-e},e.sum32=function(t,e){return t+e>>>0},e.sum32_3=function(t,e,n){return t+e+n>>>0},e.sum32_4=function(t,e,n,r){return t+e+n+r>>>0},e.sum32_5=function(t,e,n,r,i){return t+e+n+r+i>>>0},e.sum64=function(t,e,n,r){var i=t[e],o=r+t[e+1]>>>0,s=(o>>0,t[e+1]=o},e.sum64_hi=function(t,e,n,r){return(e+r>>>0>>0},e.sum64_lo=function(t,e,n,r){return e+r>>>0},e.sum64_4_hi=function(t,e,n,r,i,o,s,a){var c=0,f=e;return c+=(f=f+r>>>0)>>0)>>0)>>0},e.sum64_4_lo=function(t,e,n,r,i,o,s,a){return e+r+o+a>>>0},e.sum64_5_hi=function(t,e,n,r,i,o,s,a,c,f){var u=0,h=e;return u+=(h=h+r>>>0)>>0)>>0)>>0)>>0},e.sum64_5_lo=function(t,e,n,r,i,o,s,a,c,f){return e+r+o+a+f>>>0},e.rotr64_hi=function(t,e,n){return(e<<32-n|t>>>n)>>>0},e.rotr64_lo=function(t,e,n){return(t<<32-n|e>>>n)>>>0},e.shr64_hi=function(t,e,n){return t>>>n},e.shr64_lo=function(t,e,n){return(t<<32-n|e>>>n)>>>0}},function(t,e,n){(function(t){!function(t,e){"use strict";function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function i(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}function o(t,e,n){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(n=e,e=10),this._init(t||0,e||10,n||"be"))}function s(t,e,n){for(var r=0,i=Math.min(t.length,n),o=e;o=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return r}function a(t,e,n,r){for(var i=0,o=Math.min(t.length,n),s=e;s=49?a-49+10:a>=17?a-17+10:a}return i}function c(t,e,n){n.negative=e.negative^t.negative;var r=t.length+e.length|0;n.length=r,r=r-1|0;var i=0|t.words[0],o=0|e.words[0],s=i*o,a=67108863&s,c=s/67108864|0;n.words[0]=a;for(var f=1;f>>26,h=67108863&c,d=Math.min(f,e.length-1),l=Math.max(0,f-t.length+1);l<=d;l++){var p=f-l|0;u+=(s=(i=0|t.words[p])*(o=0|e.words[l])+h)/67108864|0,h=67108863&s}n.words[f]=0|h,c=0|u}return 0!==c?n.words[f]=0|c:n.length--,n.strip()}function f(t,e,n){return(new u).mulp(t,e,n)}function u(t,e){this.x=t,this.y=e}function h(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function d(){h.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function l(){h.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function p(){h.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){h.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function y(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else r(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function g(t){y.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)}"object"==typeof t?t.exports=o:e.BN=o,o.BN=o,o.wordSize=26;var m;try{m=n(111).Buffer}catch(t){}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,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),r(e===(0|e)&&e>=2&&e<=36);var i=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&i++,16===e?this._parseHex(t,i):this._parseBase(t,e,i),"-"===t[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),e,n)},o.prototype._initNumber=function(t,e,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):(r(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},o.prototype._initArray=function(t,e,n){if(r("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=0;i-=3)s=t[i]|t[i-1]<<8|t[i-2]<<16,this.words[o]|=s<>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===n)for(i=0,o=0;i>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this.strip()},o.prototype._parseHex=function(t,e){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n=e;n-=6)i=s(t,n,n+6),this.words[r]|=i<>>26-o&4194303,(o+=24)>=26&&(o-=26,r++);n+6!==e&&(i=s(t,e,n+6),this.words[r]|=i<>>26-o&4194303),this.strip()},o.prototype._parseBase=function(t,e,n){this.words=[0],this.length=1;for(var r=0,i=1;i<=67108863;i*=e)r++;r--,i=i/e|0;for(var o=t.length-n,s=o%r,c=Math.min(o,o-s)+n,f=0,u=n;u1&&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?""};var v=["","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"],_=[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],w=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(t,e){t=t||10,e=0|e||1;var n;if(16===t||"hex"===t){n="";for(var i=0,o=0,s=0;s>>24-i&16777215)||s!==this.length-1?v[6-c.length]+c+n:c+n,(i+=2)>=26&&(i-=26,s--)}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var f=_[t],u=w[t];n="";var h=this.clone();for(h.negative=0;!h.isZero();){var d=h.modn(u).toString(t);n=(h=h.idivn(u)).isZero()?d+n:v[f-d.length]+d+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(!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&&r(!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,e){return r(void 0!==m),this.toArrayLike(m,t,e)},o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,n){var i=this.byteLength(),o=n||Math.max(1,i);r(i<=o,"byte array longer than desired length"),r(o>0,"Requested array length <= 0"),this.strip();var s,a,c="le"===e,f=new t(o),u=this.clone();if(c){for(a=0;!u.isZero();a++)s=u.andln(255),u.iushrn(8),f[a]=s;for(;a=4096&&(n+=13,e>>>=13),e>=64&&(n+=7,e>>>=7),e>=8&&(n+=4,e>>>=4),e>=2&&(n+=2,e>>>=2),n+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,n=0;return 0==(8191&e)&&(n+=13,e>>>=13),0==(127&e)&&(n+=7,e>>>=7),0==(15&e)&&(n+=4,e>>>=4),0==(3&e)&&(n+=2,e>>>=2),0==(1&e)&&n++,n},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;et.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 e;e=this.length>t.length?t:this;for(var n=0;nt.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 e,n;this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0;rt.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){r("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var i=0;i0&&(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,e){r("number"==typeof t&&t>=0);var n=t/26|0,i=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<t.length?(n=this,r=t):(n=t,r=this);for(var i=0,o=0;o>>26;for(;0!==i&&o>>26;if(this.length=n.length,0!==i)this.words[this.length]=i,this.length++;else if(n!==this)for(;ot.length?this.clone().iadd(t):t.clone().iadd(this)},o.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 n=this.cmp(t);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;var r,i;n>0?(r=this,i=t):(r=t,i=this);for(var o=0,s=0;s>26,this.words[s]=67108863&e;for(;0!==o&&s>26,this.words[s]=67108863&e;if(0===o&&s>>13,l=0|s[1],p=8191&l,b=l>>>13,y=0|s[2],g=8191&y,m=y>>>13,v=0|s[3],_=8191&v,w=v>>>13,S=0|s[4],k=8191&S,x=S>>>13,E=0|s[5],M=8191&E,A=E>>>13,O=0|s[6],I=8191&O,P=O>>>13,C=0|s[7],N=8191&C,R=C>>>13,j=0|s[8],T=8191&j,L=j>>>13,D=0|s[9],B=8191&D,F=D>>>13,q=0|a[0],U=8191&q,z=q>>>13,K=0|a[1],G=8191&K,H=K>>>13,Y=0|a[2],W=8191&Y,J=Y>>>13,$=0|a[3],V=8191&$,X=$>>>13,Z=0|a[4],Q=8191&Z,tt=Z>>>13,et=0|a[5],nt=8191&et,rt=et>>>13,it=0|a[6],ot=8191&it,st=it>>>13,at=0|a[7],ct=8191&at,ft=at>>>13,ut=0|a[8],ht=8191&ut,dt=ut>>>13,lt=0|a[9],pt=8191<,bt=lt>>>13;n.negative=t.negative^e.negative,n.length=19;var yt=(f+(r=Math.imul(h,U))|0)+((8191&(i=(i=Math.imul(h,z))+Math.imul(d,U)|0))<<13)|0;f=((o=Math.imul(d,z))+(i>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(p,U),i=(i=Math.imul(p,z))+Math.imul(b,U)|0,o=Math.imul(b,z);var gt=(f+(r=r+Math.imul(h,G)|0)|0)+((8191&(i=(i=i+Math.imul(h,H)|0)+Math.imul(d,G)|0))<<13)|0;f=((o=o+Math.imul(d,H)|0)+(i>>>13)|0)+(gt>>>26)|0,gt&=67108863,r=Math.imul(g,U),i=(i=Math.imul(g,z))+Math.imul(m,U)|0,o=Math.imul(m,z),r=r+Math.imul(p,G)|0,i=(i=i+Math.imul(p,H)|0)+Math.imul(b,G)|0,o=o+Math.imul(b,H)|0;var mt=(f+(r=r+Math.imul(h,W)|0)|0)+((8191&(i=(i=i+Math.imul(h,J)|0)+Math.imul(d,W)|0))<<13)|0;f=((o=o+Math.imul(d,J)|0)+(i>>>13)|0)+(mt>>>26)|0,mt&=67108863,r=Math.imul(_,U),i=(i=Math.imul(_,z))+Math.imul(w,U)|0,o=Math.imul(w,z),r=r+Math.imul(g,G)|0,i=(i=i+Math.imul(g,H)|0)+Math.imul(m,G)|0,o=o+Math.imul(m,H)|0,r=r+Math.imul(p,W)|0,i=(i=i+Math.imul(p,J)|0)+Math.imul(b,W)|0,o=o+Math.imul(b,J)|0;var vt=(f+(r=r+Math.imul(h,V)|0)|0)+((8191&(i=(i=i+Math.imul(h,X)|0)+Math.imul(d,V)|0))<<13)|0;f=((o=o+Math.imul(d,X)|0)+(i>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(k,U),i=(i=Math.imul(k,z))+Math.imul(x,U)|0,o=Math.imul(x,z),r=r+Math.imul(_,G)|0,i=(i=i+Math.imul(_,H)|0)+Math.imul(w,G)|0,o=o+Math.imul(w,H)|0,r=r+Math.imul(g,W)|0,i=(i=i+Math.imul(g,J)|0)+Math.imul(m,W)|0,o=o+Math.imul(m,J)|0,r=r+Math.imul(p,V)|0,i=(i=i+Math.imul(p,X)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,X)|0;var _t=(f+(r=r+Math.imul(h,Q)|0)|0)+((8191&(i=(i=i+Math.imul(h,tt)|0)+Math.imul(d,Q)|0))<<13)|0;f=((o=o+Math.imul(d,tt)|0)+(i>>>13)|0)+(_t>>>26)|0,_t&=67108863,r=Math.imul(M,U),i=(i=Math.imul(M,z))+Math.imul(A,U)|0,o=Math.imul(A,z),r=r+Math.imul(k,G)|0,i=(i=i+Math.imul(k,H)|0)+Math.imul(x,G)|0,o=o+Math.imul(x,H)|0,r=r+Math.imul(_,W)|0,i=(i=i+Math.imul(_,J)|0)+Math.imul(w,W)|0,o=o+Math.imul(w,J)|0,r=r+Math.imul(g,V)|0,i=(i=i+Math.imul(g,X)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,X)|0,r=r+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,tt)|0)+Math.imul(b,Q)|0,o=o+Math.imul(b,tt)|0;var wt=(f+(r=r+Math.imul(h,nt)|0)|0)+((8191&(i=(i=i+Math.imul(h,rt)|0)+Math.imul(d,nt)|0))<<13)|0;f=((o=o+Math.imul(d,rt)|0)+(i>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(I,U),i=(i=Math.imul(I,z))+Math.imul(P,U)|0,o=Math.imul(P,z),r=r+Math.imul(M,G)|0,i=(i=i+Math.imul(M,H)|0)+Math.imul(A,G)|0,o=o+Math.imul(A,H)|0,r=r+Math.imul(k,W)|0,i=(i=i+Math.imul(k,J)|0)+Math.imul(x,W)|0,o=o+Math.imul(x,J)|0,r=r+Math.imul(_,V)|0,i=(i=i+Math.imul(_,X)|0)+Math.imul(w,V)|0,o=o+Math.imul(w,X)|0,r=r+Math.imul(g,Q)|0,i=(i=i+Math.imul(g,tt)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,tt)|0,r=r+Math.imul(p,nt)|0,i=(i=i+Math.imul(p,rt)|0)+Math.imul(b,nt)|0,o=o+Math.imul(b,rt)|0;var St=(f+(r=r+Math.imul(h,ot)|0)|0)+((8191&(i=(i=i+Math.imul(h,st)|0)+Math.imul(d,ot)|0))<<13)|0;f=((o=o+Math.imul(d,st)|0)+(i>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(N,U),i=(i=Math.imul(N,z))+Math.imul(R,U)|0,o=Math.imul(R,z),r=r+Math.imul(I,G)|0,i=(i=i+Math.imul(I,H)|0)+Math.imul(P,G)|0,o=o+Math.imul(P,H)|0,r=r+Math.imul(M,W)|0,i=(i=i+Math.imul(M,J)|0)+Math.imul(A,W)|0,o=o+Math.imul(A,J)|0,r=r+Math.imul(k,V)|0,i=(i=i+Math.imul(k,X)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,X)|0,r=r+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,tt)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,tt)|0,r=r+Math.imul(g,nt)|0,i=(i=i+Math.imul(g,rt)|0)+Math.imul(m,nt)|0,o=o+Math.imul(m,rt)|0,r=r+Math.imul(p,ot)|0,i=(i=i+Math.imul(p,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0;var kt=(f+(r=r+Math.imul(h,ct)|0)|0)+((8191&(i=(i=i+Math.imul(h,ft)|0)+Math.imul(d,ct)|0))<<13)|0;f=((o=o+Math.imul(d,ft)|0)+(i>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(T,U),i=(i=Math.imul(T,z))+Math.imul(L,U)|0,o=Math.imul(L,z),r=r+Math.imul(N,G)|0,i=(i=i+Math.imul(N,H)|0)+Math.imul(R,G)|0,o=o+Math.imul(R,H)|0,r=r+Math.imul(I,W)|0,i=(i=i+Math.imul(I,J)|0)+Math.imul(P,W)|0,o=o+Math.imul(P,J)|0,r=r+Math.imul(M,V)|0,i=(i=i+Math.imul(M,X)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,X)|0,r=r+Math.imul(k,Q)|0,i=(i=i+Math.imul(k,tt)|0)+Math.imul(x,Q)|0,o=o+Math.imul(x,tt)|0,r=r+Math.imul(_,nt)|0,i=(i=i+Math.imul(_,rt)|0)+Math.imul(w,nt)|0,o=o+Math.imul(w,rt)|0,r=r+Math.imul(g,ot)|0,i=(i=i+Math.imul(g,st)|0)+Math.imul(m,ot)|0,o=o+Math.imul(m,st)|0,r=r+Math.imul(p,ct)|0,i=(i=i+Math.imul(p,ft)|0)+Math.imul(b,ct)|0,o=o+Math.imul(b,ft)|0;var xt=(f+(r=r+Math.imul(h,ht)|0)|0)+((8191&(i=(i=i+Math.imul(h,dt)|0)+Math.imul(d,ht)|0))<<13)|0;f=((o=o+Math.imul(d,dt)|0)+(i>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(B,U),i=(i=Math.imul(B,z))+Math.imul(F,U)|0,o=Math.imul(F,z),r=r+Math.imul(T,G)|0,i=(i=i+Math.imul(T,H)|0)+Math.imul(L,G)|0,o=o+Math.imul(L,H)|0,r=r+Math.imul(N,W)|0,i=(i=i+Math.imul(N,J)|0)+Math.imul(R,W)|0,o=o+Math.imul(R,J)|0,r=r+Math.imul(I,V)|0,i=(i=i+Math.imul(I,X)|0)+Math.imul(P,V)|0,o=o+Math.imul(P,X)|0,r=r+Math.imul(M,Q)|0,i=(i=i+Math.imul(M,tt)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,tt)|0,r=r+Math.imul(k,nt)|0,i=(i=i+Math.imul(k,rt)|0)+Math.imul(x,nt)|0,o=o+Math.imul(x,rt)|0,r=r+Math.imul(_,ot)|0,i=(i=i+Math.imul(_,st)|0)+Math.imul(w,ot)|0,o=o+Math.imul(w,st)|0,r=r+Math.imul(g,ct)|0,i=(i=i+Math.imul(g,ft)|0)+Math.imul(m,ct)|0,o=o+Math.imul(m,ft)|0,r=r+Math.imul(p,ht)|0,i=(i=i+Math.imul(p,dt)|0)+Math.imul(b,ht)|0,o=o+Math.imul(b,dt)|0;var Et=(f+(r=r+Math.imul(h,pt)|0)|0)+((8191&(i=(i=i+Math.imul(h,bt)|0)+Math.imul(d,pt)|0))<<13)|0;f=((o=o+Math.imul(d,bt)|0)+(i>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(B,G),i=(i=Math.imul(B,H))+Math.imul(F,G)|0,o=Math.imul(F,H),r=r+Math.imul(T,W)|0,i=(i=i+Math.imul(T,J)|0)+Math.imul(L,W)|0,o=o+Math.imul(L,J)|0,r=r+Math.imul(N,V)|0,i=(i=i+Math.imul(N,X)|0)+Math.imul(R,V)|0,o=o+Math.imul(R,X)|0,r=r+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,tt)|0)+Math.imul(P,Q)|0,o=o+Math.imul(P,tt)|0,r=r+Math.imul(M,nt)|0,i=(i=i+Math.imul(M,rt)|0)+Math.imul(A,nt)|0,o=o+Math.imul(A,rt)|0,r=r+Math.imul(k,ot)|0,i=(i=i+Math.imul(k,st)|0)+Math.imul(x,ot)|0,o=o+Math.imul(x,st)|0,r=r+Math.imul(_,ct)|0,i=(i=i+Math.imul(_,ft)|0)+Math.imul(w,ct)|0,o=o+Math.imul(w,ft)|0,r=r+Math.imul(g,ht)|0,i=(i=i+Math.imul(g,dt)|0)+Math.imul(m,ht)|0,o=o+Math.imul(m,dt)|0;var Mt=(f+(r=r+Math.imul(p,pt)|0)|0)+((8191&(i=(i=i+Math.imul(p,bt)|0)+Math.imul(b,pt)|0))<<13)|0;f=((o=o+Math.imul(b,bt)|0)+(i>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(B,W),i=(i=Math.imul(B,J))+Math.imul(F,W)|0,o=Math.imul(F,J),r=r+Math.imul(T,V)|0,i=(i=i+Math.imul(T,X)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,X)|0,r=r+Math.imul(N,Q)|0,i=(i=i+Math.imul(N,tt)|0)+Math.imul(R,Q)|0,o=o+Math.imul(R,tt)|0,r=r+Math.imul(I,nt)|0,i=(i=i+Math.imul(I,rt)|0)+Math.imul(P,nt)|0,o=o+Math.imul(P,rt)|0,r=r+Math.imul(M,ot)|0,i=(i=i+Math.imul(M,st)|0)+Math.imul(A,ot)|0,o=o+Math.imul(A,st)|0,r=r+Math.imul(k,ct)|0,i=(i=i+Math.imul(k,ft)|0)+Math.imul(x,ct)|0,o=o+Math.imul(x,ft)|0,r=r+Math.imul(_,ht)|0,i=(i=i+Math.imul(_,dt)|0)+Math.imul(w,ht)|0,o=o+Math.imul(w,dt)|0;var At=(f+(r=r+Math.imul(g,pt)|0)|0)+((8191&(i=(i=i+Math.imul(g,bt)|0)+Math.imul(m,pt)|0))<<13)|0;f=((o=o+Math.imul(m,bt)|0)+(i>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(B,V),i=(i=Math.imul(B,X))+Math.imul(F,V)|0,o=Math.imul(F,X),r=r+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,tt)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,tt)|0,r=r+Math.imul(N,nt)|0,i=(i=i+Math.imul(N,rt)|0)+Math.imul(R,nt)|0,o=o+Math.imul(R,rt)|0,r=r+Math.imul(I,ot)|0,i=(i=i+Math.imul(I,st)|0)+Math.imul(P,ot)|0,o=o+Math.imul(P,st)|0,r=r+Math.imul(M,ct)|0,i=(i=i+Math.imul(M,ft)|0)+Math.imul(A,ct)|0,o=o+Math.imul(A,ft)|0,r=r+Math.imul(k,ht)|0,i=(i=i+Math.imul(k,dt)|0)+Math.imul(x,ht)|0,o=o+Math.imul(x,dt)|0;var Ot=(f+(r=r+Math.imul(_,pt)|0)|0)+((8191&(i=(i=i+Math.imul(_,bt)|0)+Math.imul(w,pt)|0))<<13)|0;f=((o=o+Math.imul(w,bt)|0)+(i>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(B,Q),i=(i=Math.imul(B,tt))+Math.imul(F,Q)|0,o=Math.imul(F,tt),r=r+Math.imul(T,nt)|0,i=(i=i+Math.imul(T,rt)|0)+Math.imul(L,nt)|0,o=o+Math.imul(L,rt)|0,r=r+Math.imul(N,ot)|0,i=(i=i+Math.imul(N,st)|0)+Math.imul(R,ot)|0,o=o+Math.imul(R,st)|0,r=r+Math.imul(I,ct)|0,i=(i=i+Math.imul(I,ft)|0)+Math.imul(P,ct)|0,o=o+Math.imul(P,ft)|0,r=r+Math.imul(M,ht)|0,i=(i=i+Math.imul(M,dt)|0)+Math.imul(A,ht)|0,o=o+Math.imul(A,dt)|0;var It=(f+(r=r+Math.imul(k,pt)|0)|0)+((8191&(i=(i=i+Math.imul(k,bt)|0)+Math.imul(x,pt)|0))<<13)|0;f=((o=o+Math.imul(x,bt)|0)+(i>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(B,nt),i=(i=Math.imul(B,rt))+Math.imul(F,nt)|0,o=Math.imul(F,rt),r=r+Math.imul(T,ot)|0,i=(i=i+Math.imul(T,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,r=r+Math.imul(N,ct)|0,i=(i=i+Math.imul(N,ft)|0)+Math.imul(R,ct)|0,o=o+Math.imul(R,ft)|0,r=r+Math.imul(I,ht)|0,i=(i=i+Math.imul(I,dt)|0)+Math.imul(P,ht)|0,o=o+Math.imul(P,dt)|0;var Pt=(f+(r=r+Math.imul(M,pt)|0)|0)+((8191&(i=(i=i+Math.imul(M,bt)|0)+Math.imul(A,pt)|0))<<13)|0;f=((o=o+Math.imul(A,bt)|0)+(i>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,r=Math.imul(B,ot),i=(i=Math.imul(B,st))+Math.imul(F,ot)|0,o=Math.imul(F,st),r=r+Math.imul(T,ct)|0,i=(i=i+Math.imul(T,ft)|0)+Math.imul(L,ct)|0,o=o+Math.imul(L,ft)|0,r=r+Math.imul(N,ht)|0,i=(i=i+Math.imul(N,dt)|0)+Math.imul(R,ht)|0,o=o+Math.imul(R,dt)|0;var Ct=(f+(r=r+Math.imul(I,pt)|0)|0)+((8191&(i=(i=i+Math.imul(I,bt)|0)+Math.imul(P,pt)|0))<<13)|0;f=((o=o+Math.imul(P,bt)|0)+(i>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(B,ct),i=(i=Math.imul(B,ft))+Math.imul(F,ct)|0,o=Math.imul(F,ft),r=r+Math.imul(T,ht)|0,i=(i=i+Math.imul(T,dt)|0)+Math.imul(L,ht)|0,o=o+Math.imul(L,dt)|0;var Nt=(f+(r=r+Math.imul(N,pt)|0)|0)+((8191&(i=(i=i+Math.imul(N,bt)|0)+Math.imul(R,pt)|0))<<13)|0;f=((o=o+Math.imul(R,bt)|0)+(i>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,r=Math.imul(B,ht),i=(i=Math.imul(B,dt))+Math.imul(F,ht)|0,o=Math.imul(F,dt);var Rt=(f+(r=r+Math.imul(T,pt)|0)|0)+((8191&(i=(i=i+Math.imul(T,bt)|0)+Math.imul(L,pt)|0))<<13)|0;f=((o=o+Math.imul(L,bt)|0)+(i>>>13)|0)+(Rt>>>26)|0,Rt&=67108863;var jt=(f+(r=Math.imul(B,pt))|0)+((8191&(i=(i=Math.imul(B,bt))+Math.imul(F,pt)|0))<<13)|0;return f=((o=Math.imul(F,bt))+(i>>>13)|0)+(jt>>>26)|0,jt&=67108863,c[0]=yt,c[1]=gt,c[2]=mt,c[3]=vt,c[4]=_t,c[5]=wt,c[6]=St,c[7]=kt,c[8]=xt,c[9]=Et,c[10]=Mt,c[11]=At,c[12]=Ot,c[13]=It,c[14]=Pt,c[15]=Ct,c[16]=Nt,c[17]=Rt,c[18]=jt,0!==f&&(c[19]=f,n.length++),n};Math.imul||(S=c),o.prototype.mulTo=function(t,e){var n=this.length+t.length;return 10===this.length&&10===t.length?S(this,t,e):n<63?c(this,t,e):n<1024?function(t,e,n){n.negative=e.negative^t.negative,n.length=t.length+e.length;for(var r=0,i=0,o=0;o>>26)|0)>>>26,s&=67108863}n.words[o]=a,r=s,s=i}return 0!==r?n.words[o]=r:n.length--,n.strip()}(this,t,e):f(this,t,e)},u.prototype.makeRBT=function(t){for(var e=new Array(t),n=o.prototype._countBits(t)-1,r=0;r>=1;return r},u.prototype.permute=function(t,e,n,r,i,o){for(var s=0;s>>=1)i++;return 1<>>=13,n[2*s+1]=8191&o,o>>>=13;for(s=2*e;s>=26,e+=i/67108864|0,e+=o>>>26,this.words[n]=67108863&o}return 0!==e&&(this.words[n]=e,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 e=function(t){for(var e=new Array(t.bitLength()),n=0;n>>i}return e}(t);if(0===e.length)return new o(1);for(var n=this,r=0;r=0);var e,n=t%26,i=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==i){for(e=this.length-1;e>=0;e--)this.words[e+i]=this.words[e];for(e=0;e=0);var i;i=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<s)for(this.length-=s,f=0;f=0&&(0!==u||f>=i);f--){var h=0|this.words[f];this.words[f]=u<<26-o|h>>>o,u=h&a}return c&&0!==u&&(c.words[c.length++]=u),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(t,e,n){return r(0===this.negative),this.iushrn(t,e,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){r("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,i=1<=0);var e=t%26,n=(t-e)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var i=67108863^67108863>>>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},o.prototype.isubn=function(t){if(r("number"==typeof t),r(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>26)-(c/67108864|0),this.words[i+n]=67108863&s}for(;i>26,this.words[i+n]=67108863&s;if(0===a)return this.strip();for(r(-1===a),a=0,i=0;i>26,this.words[i]=67108863&s;return this.negative=1,this.strip()},o.prototype._wordDiv=function(t,e){var n=this.length-t.length,r=this.clone(),i=t,s=0|i.words[i.length-1];0!==(n=26-this._countBits(s))&&(i=i.ushln(n),r.iushln(n),s=0|i.words[i.length-1]);var a,c=r.length-i.length;if("mod"!==e){(a=new o(null)).length=c+1,a.words=new Array(a.length);for(var f=0;f=0;h--){var d=67108864*(0|r.words[i.length+h])+(0|r.words[i.length+h-1]);for(d=Math.min(d/s|0,67108863),r._ishlnsubmul(i,d,h);0!==r.negative;)d--,r.negative=0,r._ishlnsubmul(i,1,h),r.isZero()||(r.negative^=1);a&&(a.words[h]=d)}return a&&a.strip(),r.strip(),"div"!==e&&0!==n&&r.iushrn(n),{div:a||null,mod:r}},o.prototype.divmod=function(t,e,n){if(r(!t.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var i,s,a;return 0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{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,e)},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 e=this.divmod(t);if(e.mod.isZero())return e.div;var n=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),i=t.andln(1),o=n.cmp(r);return o<0||1===i&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modn=function(t){r(t<=67108863);for(var e=(1<<26)%t,n=0,i=this.length-1;i>=0;i--)n=(e*n+(0|this.words[i]))%t;return n},o.prototype.idivn=function(t){r(t<=67108863);for(var e=0,n=this.length-1;n>=0;n--){var i=(0|this.words[n])+67108864*e;this.words[n]=i/t|0,e=i%t}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),c=new o(1),f=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++f;for(var u=n.clone(),h=e.clone();!e.isZero();){for(var d=0,l=1;0==(e.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(u),s.isub(h)),i.iushrn(1),s.iushrn(1);for(var p=0,b=1;0==(n.words[0]&b)&&p<26;++p,b<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(a.isOdd()||c.isOdd())&&(a.iadd(u),c.isub(h)),a.iushrn(1),c.iushrn(1);e.cmp(n)>=0?(e.isub(n),i.isub(a),s.isub(c)):(n.isub(e),a.isub(i),c.isub(s))}return{a:a,b:c,gcd:n.iushln(f)}},o.prototype._invmp=function(t){r(0===t.negative),r(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var c=0,f=1;0==(e.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(e.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(a),i.iushrn(1);for(var u=0,h=1;0==(n.words[0]&h)&&u<26;++u,h<<=1);if(u>0)for(n.iushrn(u);u-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);e.cmp(n)>=0?(e.isub(n),i.isub(s)):(n.isub(e),s.isub(i))}var d;return(d=0===e.cmpn(1)?i:s).cmpn(0)<0&&d.iadd(t),d},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),n=t.clone();e.negative=0,n.negative=0;for(var r=0;e.isEven()&&n.isEven();r++)e.iushrn(1),n.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;n.isEven();)n.iushrn(1);var i=e.cmp(n);if(i<0){var o=e;e=n,n=o}else if(0===i||0===n.cmpn(1))break;e.isub(n)}return n.iushln(r)},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){r("number"==typeof t);var e=t%26,n=(t-e)/26,i=1<>>26,a&=67108863,this.words[s]=a}return 0!==o&&(this.words[s]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var e=t<0;if(0!==this.negative&&!e)return-1;if(0===this.negative&&e)return 1;this.strip();var n;if(this.length>1)n=1;else{e&&(t=-t),r(t<=67108863,"Number is too big");var i=0|this.words[0];n=i===t?0:it.length)return 1;if(this.length=0;n--){var r=0|this.words[n],i=0|t.words[n];if(r!==i){ri&&(e=1);break}}return e},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 y(t)},o.prototype.toRed=function(t){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return r(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 r(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return r(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var k={k256:null,p224:null,p192:null,p25519:null};h.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},h.prototype.ireduce=function(t){var e,n=t;do{this.split(n,this.tmp),e=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e0?n.isub(this.p):n.strip(),n},h.prototype.split=function(t,e){t.iushrn(this.n,0,e)},h.prototype.imulK=function(t){return t.imul(this.k)},i(d,h),d.prototype.split=function(t,e){for(var n=Math.min(t.length,9),r=0;r>>22,i=o}i>>>=22,t.words[r-10]=i,0===i&&t.length>10?t.length-=10:t.length-=9},d.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,n=0;n>>=26,t.words[n]=i,e=r}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(k[t])return k[t];var e;if("k256"===t)e=new d;else if("p224"===t)e=new l;else if("p192"===t)e=new p;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new b}return k[t]=e,e},y.prototype._verify1=function(t){r(0===t.negative,"red works only with positives"),r(t.red,"red works only with red numbers")},y.prototype._verify2=function(t,e){r(0==(t.negative|e.negative),"red works only with positives"),r(t.red&&t.red===e.red,"red works only with red numbers")},y.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):t.umod(this.m)._forceRed(this)},y.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},y.prototype.add=function(t,e){this._verify2(t,e);var n=t.add(e);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},y.prototype.iadd=function(t,e){this._verify2(t,e);var n=t.iadd(e);return n.cmp(this.m)>=0&&n.isub(this.m),n},y.prototype.sub=function(t,e){this._verify2(t,e);var n=t.sub(e);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},y.prototype.isub=function(t,e){this._verify2(t,e);var n=t.isub(e);return n.cmpn(0)<0&&n.iadd(this.m),n},y.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},y.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},y.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},y.prototype.isqr=function(t){return this.imul(t,t.clone())},y.prototype.sqr=function(t){return this.mul(t,t)},y.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(r(e%2==1),3===e){var n=this.m.add(new o(1)).iushrn(2);return this.pow(t,n)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);r(!i.isZero());var a=new o(1).toRed(this),c=a.redNeg(),f=this.m.subn(1).iushrn(1),u=this.m.bitLength();for(u=new o(2*u*u).toRed(this);0!==this.pow(u,f).cmp(c);)u.redIAdd(c);for(var h=this.pow(u,i),d=this.pow(t,i.addn(1).iushrn(1)),l=this.pow(t,i),p=s;0!==l.cmp(a);){for(var b=l,y=0;0!==b.cmp(a);y++)b=b.redSqr();r(y=0;r--){for(var f=e.words[r],u=c-1;u>=0;u--){var h=f>>u&1;i!==n[0]&&(i=this.sqr(i)),0!==h||0!==s?(s<<=1,s|=h,(4===++a||0===r&&0===u)&&(i=this.mul(i,n[s]),a=0,s=0)):a=0}c=26}return i},y.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},y.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new g(t)},i(g,y),g.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},g.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},g.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var n=t.imul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),o=i;return i.cmp(this.m)>=0?o=i.isub(this.m):i.cmpn(0)<0&&(o=i.iadd(this.m)),o._forceRed(this)},g.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var n=t.mul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},g.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===t||t,this)}).call(e,n(50)(t))},function(t,e,n){"use strict";function r(t){if(!(this instanceof r))return new r(t);f.call(this,t),u.call(this,t),t&&!1===t.readable&&(this.readable=!1),t&&!1===t.writable&&(this.writable=!1),this.allowHalfOpen=!0,t&&!1===t.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",i)}function i(){this.allowHalfOpen||this._writableState.ended||s(o,this)}function o(t){t.end()}var s=n(19),a=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e};t.exports=r;var c=n(13);c.inherits=n(5);var f=n(35),u=n(25);c.inherits(r,f);for(var h=a(u.prototype),d=0;d=0;r--){var i=t[r];"."===i?t.splice(r,1):".."===i?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function r(t,e){if(t.filter)return t.filter(e);for(var n=[],r=0;r=-1&&!i;o--){var s=o>=0?arguments[o]:t.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(e=s+"/"+e,i="/"===s.charAt(0))}return e=n(r(e.split("/"),function(t){return!!t}),!i).join("/"),(i?"/":"")+e||"."},e.normalize=function(t){var i=e.isAbsolute(t),o="/"===s(t,-1);return(t=n(r(t.split("/"),function(t){return!!t}),!i).join("/"))||i||(t="."),t&&o&&(t+="/"),(i?"/":"")+t},e.isAbsolute=function(t){return"/"===t.charAt(0)},e.join=function(){var t=Array.prototype.slice.call(arguments,0);return e.normalize(r(t,function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))},e.relative=function(t,n){function r(t){for(var e=0;e=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=e.resolve(t).substr(1),n=e.resolve(n).substr(1);for(var i=r(t.split("/")),o=r(n.split("/")),s=Math.min(i.length,o.length),a=s,c=0;c=this._delta8){var n=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-n,t.length),0===this.pending.length&&(this.pending=null),t=i.join32(t,0,t.length-n,this.endian);for(var r=0;r>>24&255,r[i++]=t>>>16&255,r[i++]=t>>>8&255,r[i++]=255&t}else for(r[i++]=255&t,r[i++]=t>>>8&255,r[i++]=t>>>16&255,r[i++]=t>>>24&255,r[i++]=0,r[i++]=0,r[i++]=0,r[i++]=0,o=8;o{this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,t.clock?t.clock.time:0]),this.events.emit("replicate",this.address.toString())}),this._loader.on("load.start",(t,e)=>{this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,t.clock?t.clock.time:0])}),this._loader.on("load.progress",(t,e,n,r,i)=>{this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this.events.emit("replicate.progress",this.address.toString(),e,n,this._replicationInfo.progress,this._replicationInfo.have)}),this._loader.on("load.end",async(t,e)=>{try{await this._oplog.join(t,-1,this._oplog.id),this._replicator.replicate(this._oplog),this._index.updateIndex(this._oplog),this._calculateReplicationInfo(e),this.events.emit("replicated",this.address.toString())}catch(t){console.error(t)}}),this._replicator=new d(this._loader),this._replicator.replicate(this._oplog),this.options.replicate&&this._replicator.start()}catch(t){console.error("Store Error:",t)}}_calculateReplicationInfo(t){this._replicationInfo.progress=Math.min(this._oplog.length,Math.max(this._replicationInfo.progress,this._oplog.length)),this._replicationInfo.max=Math.max(this._replicationInfo.max,this._oplog.length),t&&(this._replicationInfo.have=Object.assign(this._replicationInfo.have,t))}get all(){return Array.isArray(this._index._index)?this._index._index:Object.keys(this._index._index).map(t=>this._index._index[t])}get type(){return this._type}get key(){return this._key}async close(){return this._loader.stop(),this._replicator.stop(),this._replicationInfo={progress:0,max:0,have:{}},this._stats={snapshot:{bytesLoaded:-1},syncRequestsReceieved:0},this.events.removeAllListeners("load"),this.events.removeAllListeners("load.progress"),this.events.removeAllListeners("replicate"),this.events.removeAllListeners("replicate.progress"),this.events.removeAllListeners("replicated"),this.events.removeAllListeners("ready"),this.events.removeAllListeners("write"),this.events.emit("closed",this.address.toString()),Promise.resolve()}async drop(){await this.close();const t=this.address.toString();await this._cache.set(t,{}),this._index=new this.options.Index(this.id),this._oplog=new a(this._ipfs,this.id,null,null,null,this._key,this.access.write),this._cache=this.options&&this.options.cache?this.options.cache:new c(this.options.path,this.dbname)}async load(t){this._replicator.stop();try{await this._cache.load()}catch(t){console.warn("Couldn't load Cache:",t)}const e=this._cache.get(this.address.toString())||e,n=e.localHeads||[],r=e.remoteHeads||[];if(this._replicationInfo.max=Math.max(this._replicationInfo.max,n.concat(r).reduce((t,e)=>Math.max(t,e.clock.time),0)),n||r){this.events.emit("load",this.address.toString()),t=t||this.options.maxHistory;let e,i;if(n&&n.length>0)for(const r of n){e=await a.fromEntryHash(this._ipfs,r.hash,this._oplog.id,t,this._oplog.values,this.key,this.access.write,this._onLoadProgress.bind(this)),await this._oplog.join(e,-1,this._oplog.id);const n=this._oplog.values[this._oplog.length-1];this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,this._oplog.values[this._oplog.length-1].clock.time,0]),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this._onLoadProgress(n.hash,n,this._replicationInfo.progress,this._replicationInfo.max)}if(r&&r.length>0){this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,r[0].clock.time,0]);for(const e of r){i=await a.fromEntryHash(this._ipfs,e.hash,this._oplog.id,t,this._oplog.values,this.key,this.access.write,this._onLoadProgress.bind(this)),await this._oplog.join(i,-1,this._oplog.id);const n=this._oplog.values[this._oplog.length-1];this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,this._oplog.values[this._oplog.length-1].clock.time,0]),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this._onLoadProgress(n.hash,n,this._replicationInfo.progress,this._replicationInfo.max)}}const o=this._oplog.values[this._oplog.length-1];o&&this._onLoadProgress(o.hash,o,this._replicationInfo.progress,this._replicationInfo.max),this._index.updateIndex(this._oplog)}this.options.replicate&&(this._replicator.replicate(this._oplog),this._replicator.start()),this.events.emit("ready",this.address.toString(),this._oplog.heads)}sync(t,n,r,i=!0,o=-1,a=0){this._stats.syncRequestsReceieved+=1;return s(t,t=>{if(!t)return console.warn("Warning: Given input entry was 'null'."),Promise.resolve(null);if(!this.access.write.includes(t.key)&&!this.access.write.includes("*"))return console.warn("Warning: Given input entry is not allowed in this log and was discarded (no write access)."),Promise.resolve(null);const n=Object.assign({},t);return n.hash=null,this._ipfs.object.put(e.from(JSON.stringify(n))).then(t=>t.toJSON().multihash).then(e=>(e!==t.hash&&console.warn("\"WARNING! Head hash didn't match the contents"),e)).then(()=>t)}).then(async e=>{const n=this.address.toString();let r=Object.assign({},this._cache.get(n),{remoteHeads:t});return await this._cache.set(n,r),this._loader.load(e.filter(t=>null!==t))})}loadMoreFrom(t,e){this._loader.load(e)}async saveSnapshot(){const t=Object.keys(this._loader._fetching).map(t=>this._loader._fetching[t]).concat(this._loader._queue.map(t=>t));let n=this._oplog.toSnapshot(),r=new e(JSON.stringify({id:n.id,heads:n.heads,size:n.values.length,type:this.type}));const i=new o;let s=new Uint16Array([r.length]),a=new e(s.buffer);i.push(a),i.push(r),n.values.forEach(t=>{let n=new e(JSON.stringify(t)),r=new Uint16Array([n.length]);i.push(new e(r.buffer)),i.push(n)}),i.push(null);const c={path:this.address.toString(),content:i},f=await this._ipfs.files.add(c),u=this.address.toString();let h=Object.assign({},this._cache.get(u),{snapshot:f[f.length-1],queue:t,type:this.type,max:this._replicationInfo.max});return await this._cache.set(u,h),f}async loadFromSnapshot(t){this.events.emit("load",this.address.toString()),await this._cache.load();const n=this._cache.get(this.address.toString());if(this._replicationInfo.max=Math.max(this._replicationInfo.max,n.max||0),this.sync(n.queue||[]),!n.snapshot)throw new Error(`Snapshot for ${this.address} not found!`);{const t=await this._ipfs.files.cat(n.snapshot.hash),r=await(()=>new Promise((n,r)=>{let i=new e(0),o=[];t.on("data",t=>{if(this._byteSize+=t.length,o.length<2e3)o.push(t);else{const t=e.concat(o);i=e.concat([i,t]),o=[]}}),t.on("end",()=>{function t(t){for(var e=new ArrayBuffer(t.length),n=new Uint8Array(e),r=0;r0){const t=e.concat(o);i=e.concat([i,t])}const r=parseInt(new Uint16Array(t(i.slice(0,2)))),s=JSON.parse(i.slice(2,r+2));let a=[],c=2+r;for(;cMath.max(t,e.clock.time),0)),n({values:a,id:s.id,heads:s.heads,type:s.type})})}))(),i=await a.fromJSON(this._ipfs,r,-1,this._key,this.access.write,1e3,(t,e,n,r)=>{this._replicationInfo.max=Math.max(this._replicationInfo.max,e.clock.time),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,n,this._oplog.length]),this._onLoadProgress(t,e,this._replicationInfo.progress,this._replicationInfo.max)});await this._oplog.join(i,-1,this._oplog.id),this._oplog.values.forEach(t=>this._replicationInfo.have[t.clock.time]=!0),this._replicationInfo.max=Math.max(this._replicationInfo.max,this._oplog.length),this._replicationInfo.progress=Math.max(this._replicationInfo.progress,this._oplog.length),this._replicator.replicate(this._oplog),this._index.updateIndex(this._oplog),this.events.emit("ready",this.address.toString(),this._oplog.heads),this.events.emit("replicated",this.address.toString())}return this}async _addOperation(t,e,n,r){if(this._oplog){const e=await this._oplog.append(t);this._replicationInfo.max=Math.max(this._replicationInfo.max,e.clock.time),this._replicationInfo.progress++;const n=this.address.toString();let i=Object.assign({},this._cache.get(n),{localHeads:[e],max:this._replicationInfo.max});return await this._cache.set(n,i),this._index.updateIndex(this._oplog),this.events.emit("write",this.address.toString(),e,this._oplog.heads),r&&r(e),e.hash}}_addOperationBatch(t,e,n,r){throw new Error("Not implemented!")}_onLoadProgress(t,e,n,r){this.events.emit("load.progress",this.address.toString(),t,e,Math.max(this._oplog.length,n),Math.max(this._oplog.length||0,this._replicationInfo.max||0))}}t.exports=p}).call(e,n(0).Buffer)},function(t,e,n){"use strict";(function(e){function n(t,n,r,i){if("function"!=typeof t)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return e.nextTick(t);case 2:return e.nextTick(function(){t.call(null,n)});case 3:return e.nextTick(function(){t.call(null,n,r)});case 4:return e.nextTick(function(){t.call(null,n,r,i)});default:for(o=new Array(a-1),s=0;s=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},n(66),e.setImmediate=setImmediate,e.clearImmediate=clearImmediate},function(t,e,n){"use strict";t.exports=((t,e,n)=>new Promise((r,i)=>{if(n=Object.assign({concurrency:1/0},n),"function"!=typeof e)throw new TypeError("Mapper function is required");const o=n.concurrency;if(!("number"==typeof o&&o>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${o}\` (${typeof o})`);const s=[],a=t[Symbol.iterator]();let c=!1,f=!1,u=0,h=0;const d=()=>{if(c)return;const t=a.next(),n=h;if(h++,t.done)return f=!0,void(0===u&&r(s));u++,Promise.resolve(t.value).then(t=>e(t,n)).then(t=>{s[n]=t,u--,d()},t=>{c=!0,i(t)})};for(let t=0;t=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),h(n)?r.showHidden=n:n&&e._extend(r,n),b(r.showHidden)&&(r.showHidden=!1),b(r.depth)&&(r.depth=2),b(r.colors)&&(r.colors=!1),b(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),a(r,t,r.depth)}function o(t,e){var n=i.styles[e];return n?"["+i.colors[n][0]+"m"+t+"["+i.colors[n][1]+"m":t}function s(t,e){return t}function a(t,n,r){if(t.customInspect&&n&&_(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return p(i)||(i=a(t,i,r)),i}var o=function(t,e){if(b(e))return t.stylize("undefined","undefined");if(p(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}if(l(e))return t.stylize(""+e,"number");if(h(e))return t.stylize(""+e,"boolean");if(d(e))return t.stylize("null","null")}(t,n);if(o)return o;var s=Object.keys(n),g=function(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),v(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return c(n);if(0===s.length){if(_(n)){var w=n.name?": "+n.name:"";return t.stylize("[Function"+w+"]","special")}if(y(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(m(n))return t.stylize(Date.prototype.toString.call(n),"date");if(v(n))return c(n)}var S="",x=!1,E=["{","}"];if(u(n)&&(x=!0,E=["[","]"]),_(n)){S=" [Function"+(n.name?": "+n.name:"")+"]"}if(y(n)&&(S=" "+RegExp.prototype.toString.call(n)),m(n)&&(S=" "+Date.prototype.toUTCString.call(n)),v(n)&&(S=" "+c(n)),0===s.length&&(!x||0==n.length))return E[0]+S+E[1];if(r<0)return y(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var M;return M=x?function(t,e,n,r,i){for(var o=[],s=0,a=e.length;s=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1];return n[0]+e+" "+t.join(", ")+" "+n[1]}(M,S,E)}function c(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,n,r,i,o){var s,c,f;if((f=Object.getOwnPropertyDescriptor(e,i)||{value:e[i]}).get?c=f.set?t.stylize("[Getter/Setter]","special"):t.stylize("[Getter]","special"):f.set&&(c=t.stylize("[Setter]","special")),k(r,i)||(s="["+i+"]"),c||(t.seen.indexOf(f.value)<0?(c=d(n)?a(t,f.value,null):a(t,f.value,n-1)).indexOf("\n")>-1&&(c=o?c.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+c.split("\n").map(function(t){return" "+t}).join("\n")):c=t.stylize("[Circular]","special")),b(s)){if(o&&i.match(/^\d+$/))return c;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+c}function u(t){return Array.isArray(t)}function h(t){return"boolean"==typeof t}function d(t){return null===t}function l(t){return"number"==typeof t}function p(t){return"string"==typeof t}function b(t){return void 0===t}function y(t){return g(t)&&"[object RegExp]"===w(t)}function g(t){return"object"==typeof t&&null!==t}function m(t){return g(t)&&"[object Date]"===w(t)}function v(t){return g(t)&&("[object Error]"===w(t)||t instanceof Error)}function _(t){return"function"==typeof t}function w(t){return Object.prototype.toString.call(t)}function S(t){return t<10?"0"+t.toString(10):t.toString(10)}function k(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var x=/%[sdj%]/g;e.format=function(t){if(!p(t)){for(var e=[],n=0;n=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),a=r[n];n-1?r:y;c.WritableState=a;var v=n(13);v.inherits=n(5);var _={deprecate:n(67)},w=n(36),S=n(10).Buffer,k=i.Uint8Array||function(){},x=n(37);v.inherits(c,w),a.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(a.prototype,"buffer",{get:_.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}();var E;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(E=Function.prototype[Symbol.hasInstance],Object.defineProperty(c,Symbol.hasInstance,{value:function(t){return!!E.call(this,t)||t&&t._writableState instanceof a}})):E=function(t){return t instanceof this},c.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},c.prototype.write=function(t,e,n){var r=this._writableState,i=!1,o=function(t){return S.isBuffer(t)||t instanceof k}(t)&&!r.objectMode;return o&&!S.isBuffer(t)&&(t=function(t){return S.from(t)}(t)),"function"==typeof e&&(n=e,e=null),o?e="buffer":e||(e=r.defaultEncoding),"function"!=typeof n&&(n=s),r.ended?function(t,e){var n=new Error("write after end");t.emit("error",n),y(e,n)}(this,n):(o||function(t,e,n,r){var i=!0,o=!1;return null===n?o=new TypeError("May not write null values to stream"):"string"==typeof n||void 0===n||e.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(t.emit("error",o),y(r,o),i=!1),i}(this,r,t,n))&&(r.pendingcb++,i=f(this,r,o,t,e,n)),i},c.prototype.cork=function(){this._writableState.corked++},c.prototype.uncork=function(){var t=this._writableState;t.corked&&(t.corked--,t.writing||t.corked||t.finished||t.bufferProcessing||!t.bufferedRequest||d(this,t))},c.prototype.setDefaultEncoding=function(t){if("string"==typeof t&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this},c.prototype._write=function(t,e,n){n(new Error("_write() is not implemented"))},c.prototype._writev=null,c.prototype.end=function(t,e,n){var r=this._writableState;"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!==t&&void 0!==t&&this.write(t,e),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||function(t,e,n){e.ending=!0,b(t,e),n&&(e.finished?y(n):t.once("finish",n)),e.ended=!0,t.writable=!1}(this,r,n)},Object.defineProperty(c.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),c.prototype.destroy=x.destroy,c.prototype._undestroy=x.undestroy,c.prototype._destroy=function(t,e){this.end(),e(t)}}).call(e,n(1),n(20).setImmediate,n(3))},function(t,e,n){"use strict";(function(e){const r=n(27),i=n(28),o=()=>new Error("Ipfs instance not defined");class s{static async create(t,e,n,a=[],c,f){if(!i(t))throw o();if(!i(e))throw new Error("Entry requires an id");if(!i(n))throw new Error("Entry requires data");if(!i(a)||!Array.isArray(a))throw new Error("'next' argument is not an array");let u={hash:null,id:e,payload:n,next:a.filter(i).map(t=>t.hash?t.hash:t),v:0,clock:new r(e,c?c.time:null)};return t.keystore&&f&&(u=await s.signEntry(t.keystore,u,f)),u.hash=await s.toMultihash(t,u),u}static async signEntry(t,n,r){const i=await t.sign(r,new e(JSON.stringify(n)));return n.sig=i,n.key=r.getPublic("hex"),n}static async verifyEntry(t,n){const r=Object.assign({},{hash:null,id:t.id,payload:t.payload,next:t.next,v:t.v,clock:t.clock}),i=await n.importPublicKey(t.key);await n.verify(t.sig,i,new e(JSON.stringify(r)))}static toMultihash(t,n){if(!t)throw o();const r=e.from(JSON.stringify(n));return t.object.put(r).then(t=>t.toJSON().multihash)}static fromMultihash(t,e){if(!t)throw o();if(!e)throw new Error(`Invalid hash: ${e}`);return t.object.get(e,{enc:"base58"}).then(t=>JSON.parse(t.toJSON().data)).then(t=>{let n={hash:e,id:t.id,payload:t.payload,next:t.next,v:t.v,clock:t.clock};return t.sig&&Object.assign(n,{sig:t.sig}),t.key&&Object.assign(n,{key:t.key}),n})}static isEntry(t){return void 0!==t.id&&void 0!==t.next&&void 0!==t.hash&&void 0!==t.payload&&void 0!==t.v&&void 0!==t.clock}static compare(t,e){var n=r.compare(t.clock,e.clock);return 0===n?t.clock.id-1}static findChildren(t,e){for(var n=[],r=e.find(e=>s.isParent(t,e)),i=t;r;)n.push(r),i=r,r=e.find(t=>s.isParent(i,t));return n=n.sort((t,e)=>t.clock.time>t.clock.time)}}t.exports=s}).call(e,n(0).Buffer)},function(t,e,n){"use strict";class r{constructor(t,e){this.id=t,this.time=e||0}tick(){return new r(this.id,++this.time)}merge(t){return this.time=Math.max(this.time,t.time),new r(this.id,this.time)}clone(){return new r(this.id,this.time)}static compare(t,e){var n=t.time-e.time;return 0===n&&t.id!==e.id?t.idvoid 0!==t&&null!==t)},function(t,e,n){"use strict";var r=n(44);t.exports=function(t,e){if(!t)return function(t,n){return t?r(n,t,e):n(!0)};Array.isArray(t)||(t=Object.keys(t).map(function(e){return t[e]}));var n=0;return function(i,o){if(i)return r(o,i,e);n>=t.length?o(!0):o(null,t[n++])}}},function(t,e,n){"use strict";var r=n(14);t.exports=function(t,e,n){n||(n=e,e=null);var i=r(function(n){e=t(e,n)},function(t){n(t,e)});return 2===arguments.length?function(t){t(null,function(r,o){if(r)return n(!0===r?null:r);e=o,i(t)})}:i}},function(t,e,n){"use strict";var r=n(46);t.exports=function(t){return t=r(t),function(e){return function n(r,i){for(var o,s=!0;s;)s=!1,o=!0,e(r,function(e,r){if(!e&&!t(r))return o?s=!0:n(e,i);i(e,r)}),o=!1}}}},function(t,e,n){var r=e;r.utils=n(6),r.common=n(17),r.sha=n(119),r.ripemd=n(123),r.hmac=n(124),r.sha1=r.sha.sha1,r.sha256=r.sha.sha256,r.sha224=r.sha.sha224,r.sha384=r.sha.sha384,r.sha512=r.sha.sha512,r.ripemd160=r.ripemd.ripemd160},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";const r=n(18),i=n(154);class o extends r{constructor(t,e,n,r={}){void 0===r.Index&&Object.assign(r,{Index:i}),super(t,e,n,r),this._type="eventlog"}add(t){return this._addOperation({op:"ADD",key:null,value:t})}get(t){return this.iterator({gte:t,limit:1}).collect()[0]}iterator(t){const e=this._query(t);let n=0;return{[Symbol.iterator](){return this},next(){let t={value:null,done:!0};return ne}}_query(t){t||(t={});const e=t.limit?t.limit>-1?t.limit:this._index.get().length:1,n=this._index.get().slice();let r=[];return r=t.gt||t.gte?this._read(n,t.gt?t.gt:t.gte,e,!!t.gte):this._read(n.reverse(),t.lt?t.lt:t.lte,e,t.lte||!t.lt).reverse()}_read(t,e,n,r){const i=t.map(t=>t.hash).indexOf(e);let o=Math.max(i,0);o+=r?0:1;return t.slice(o).slice(0,n)}}t.exports=o},function(t,e,n){"use strict";(function(e,r){function i(t,e){w=w||n(8),t=t||{},this.objectMode=!!t.objectMode,e instanceof w&&(this.objectMode=this.objectMode||!!t.readableObjectMode);var r=t.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=r||0===r?r:i,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new C,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.destroyed=!1,this.defaultEncoding=t.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,t.encoding&&(P||(P=n(38).StringDecoder),this.decoder=new P(t.encoding),this.encoding=t.encoding)}function o(t){if(w=w||n(8),!(this instanceof o))return new o(t);this._readableState=new i(t,this),this.readable=!0,t&&("function"==typeof t.read&&(this._read=t.read),"function"==typeof t.destroy&&(this._destroy=t.destroy)),x.call(this)}function s(t,e,n,r,i){var o=t._readableState;if(null===e)o.reading=!1,function(t,e){if(e.ended)return;if(e.decoder){var n=e.decoder.end();n&&n.length&&(e.buffer.push(n),e.length+=e.objectMode?1:n.length)}e.ended=!0,f(t)}(t,o);else{var s;i||(s=function(t,e){var n;(function(t){return E.isBuffer(t)||t instanceof M})(e)||"string"==typeof e||void 0===e||t.objectMode||(n=new TypeError("Invalid non-string/buffer chunk"));return n}(o,e)),s?t.emit("error",s):o.objectMode||e&&e.length>0?("string"==typeof e||o.objectMode||Object.getPrototypeOf(e)===E.prototype||(e=function(t){return E.from(t)}(e)),r?o.endEmitted?t.emit("error",new Error("stream.unshift() after end event")):a(t,o,e,!0):o.ended?t.emit("error",new Error("stream.push() after EOF")):(o.reading=!1,o.decoder&&!n?(e=o.decoder.write(e),o.objectMode||0!==e.length?a(t,o,e,!1):h(t,o)):a(t,o,e,!1))):r||(o.reading=!1)}return function(t){return!t.ended&&(t.needReadable||t.lengthe.highWaterMark&&(e.highWaterMark=function(t){return t>=j?t=j:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function f(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(I("emitReadable",e.flowing),e.emittedReadable=!0,e.sync?_(u,t):u(t))}function u(t){I("emit readable"),t.emit("readable"),b(t)}function h(t,e){e.readingMore||(e.readingMore=!0,_(d,t,e))}function d(t,e){for(var n=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length=e.length?(n=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.head.data:e.buffer.concat(e.length),e.buffer.clear()):n=function(t,e,n){var r;to.length?o.length:t;if(s===o.length?i+=o:i+=o.slice(0,t),0===(t-=s)){s===o.length?(++r,n.next?e.head=n.next:e.head=e.tail=null):(e.head=n,n.data=o.slice(s));break}++r}return e.length-=r,i}(t,e):function(t,e){var n=E.allocUnsafe(t),r=e.head,i=1;r.data.copy(n),t-=r.data.length;for(;r=r.next;){var o=r.data,s=t>o.length?o.length:t;if(o.copy(n,n.length-t,0,s),0===(t-=s)){s===o.length?(++i,r.next?e.head=r.next:e.head=e.tail=null):(e.head=r,r.data=o.slice(s));break}++i}return e.length-=i,n}(t,e);return r}(t,e.buffer,e.decoder),n}function g(t){var e=t._readableState;if(e.length>0)throw new Error('"endReadable()" called on non-empty stream');e.endEmitted||(e.ended=!0,_(m,e,t))}function m(t,e){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}function v(t,e){for(var n=0,r=t.length;n=e.highWaterMark||e.ended))return I("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?g(this):f(this),null;if(0===(t=c(t,e))&&e.ended)return 0===e.length&&g(this),null;var r=e.needReadable;I("need readable",r),(0===e.length||e.length-t0?y(t,e):null)?(e.needReadable=!0,t=0):e.length-=t,0===e.length&&(e.ended||(e.needReadable=!0),n!==t&&e.ended&&g(this)),null!==i&&this.emit("data",i),i},o.prototype._read=function(t){this.emit("error",new Error("_read() is not implemented"))},o.prototype.pipe=function(t,e){function n(e,r){I("onunpipe"),e===u&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,I("cleanup"),t.removeListener("close",a),t.removeListener("finish",c),t.removeListener("drain",l),t.removeListener("error",s),t.removeListener("unpipe",n),u.removeListener("end",i),u.removeListener("end",f),u.removeListener("data",o),p=!0,!h.awaitDrain||t._writableState&&!t._writableState.needDrain||l())}function i(){I("onend"),t.end()}function o(e){I("ondata"),y=!1;!1!==t.write(e)||y||((1===h.pipesCount&&h.pipes===t||h.pipesCount>1&&-1!==v(h.pipes,t))&&!p&&(I("false write response, pause",u._readableState.awaitDrain),u._readableState.awaitDrain++,y=!0),u.pause())}function s(e){I("onerror",e),f(),t.removeListener("error",s),0===k(t,"error")&&t.emit("error",e)}function a(){t.removeListener("finish",c),f()}function c(){I("onfinish"),t.removeListener("close",a),f()}function f(){I("unpipe"),u.unpipe(t)}var u=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=t;break;case 1:h.pipes=[h.pipes,t];break;default:h.pipes.push(t)}h.pipesCount+=1,I("pipe count=%d opts=%j",h.pipesCount,e);var d=(!e||!1!==e.end)&&t!==r.stdout&&t!==r.stderr?i:f;h.endEmitted?_(d):u.once("end",d),t.on("unpipe",n);var l=function(t){return function(){var e=t._readableState;I("pipeOnDrain",e.awaitDrain),e.awaitDrain&&e.awaitDrain--,0===e.awaitDrain&&k(t,"data")&&(e.flowing=!0,b(t))}}(u);t.on("drain",l);var p=!1,y=!1;return u.on("data",o),function(t,e,n){if("function"==typeof t.prependListener)return t.prependListener(e,n);t._events&&t._events[e]?S(t._events[e])?t._events[e].unshift(n):t._events[e]=[n,t._events[e]]:t.on(e,n)}(t,"error",s),t.once("close",a),t.once("finish",c),t.emit("pipe",u),h.flowing||(I("pipe resume"),u.resume()),t},o.prototype.unpipe=function(t){var e=this._readableState,n={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes?this:(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,n),this);if(!t){var r=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o>5==6?2:t>>4==14?3:t>>3==30?4:-1}function o(t){var e=this.lastTotal-this.lastNeed,n=function(t,e,n){if(128!=(192&e[0]))return t.lastNeed=0,"�".repeat(n);if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�".repeat(n+1);if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�".repeat(n+2)}}(this,t,e);return void 0!==n?n:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function s(t,e){if((t.length-e)%2==0){var n=t.toString("utf16le",e);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function a(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,n)}return e}function c(t,e){var n=(t.length-e)%3;return 0===n?t.toString("base64",e):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-n))}function f(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function u(t){return t.toString(this.encoding)}function h(t){return t&&t.length?this.write(t):""}var d=n(10).Buffer,l=d.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};e.StringDecoder=r,r.prototype.write=function(t){if(0===t.length)return"";var e,n;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n=0?(o>0&&(t.lastNeed=o-1),o):--r=0?(o>0&&(t.lastNeed=o-2),o):--r=0?(o>0&&(2===o?o=0:t.lastNeed=o-3),o):0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=n;var r=t.length-(n-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)},r.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},function(t,e,n){"use strict";function r(t){this.afterTransform=function(e,n){return function(t,e,n){var r=t._transformState;r.transforming=!1;var i=r.writecb;if(!i)return t.emit("error",new Error("write callback called multiple times"));r.writechunk=null,r.writecb=null,null!==n&&void 0!==n&&t.push(n);i(e);var o=t._readableState;o.reading=!1,(o.needReadable||o.length(t[e.hash]=e,t),{}),r=r||h.findHeads(n),this._headsIndex=r.reduce((t,e)=>(t[e.hash]=e,t),{}),this._length=n?n.length:0;const u=Math.max(i?i.time:0,this.heads.reduce((t,e)=>Math.max(t,e.clock.time),0));this._clock=new c(this.id,u)}get id(){return this._id}get clock(){return this._clock}get length(){return this._length}get values(){return Object.values(this._entryIndex).sort(o.compare)||[]}get heads(){return Object.values(this._headsIndex)||[]}get tails(){return h.findTails(this.values)}get tailHashes(){return h.findTailHashes(this.values)}get(t){return this._entryIndex[t]}has(t){return void 0!==this._entryIndex[t.hash||t]}async append(t){if(this._key&&!this._keys.includes(this._key.getPublic("hex"))&&!this._keys.includes("*"))throw new Error("Not allowed to write");const e=Math.max(this.clock.time,this.heads.reduce((t,e)=>Math.max(t,e.clock.time),0))+1;this._clock=new c(this.clock.id,e);const n=await o.create(this._storage,this.id,t,Object.values(this._headsIndex),this.clock,this._key);return this._entryIndex[n.hash]=n,this._headsIndex={},this._headsIndex[n.hash]=n,this._length++,n}async join(t,e=-1,n){if(!f(t))throw a.LogNotDefinedError();if(!h.isLog(t))throw a.NotALogError();const i=async t=>{this._keys.map(t=>t.getPublic?t.getPublic("hex"):t);return(await r(t,async t=>{if(!t.key)throw new Error("Entry doesn't have a public key");if(!t.sig)throw new Error("Entry doesn't have a signature");if(1===this._keys.length&&this._keys[0]===this._key&&t.id!==this.id)throw new Error("Entry doesn't belong in this log (wrong ID)");if(this._keys.length>0&&!this._keys.includes("*")&&!((t,e)=>t.find(t=>t===e.key))(this._keys.concat([this._key]),t))return console.warn("Warning: Input log contains entries that are not allowed in this log. Logs weren't joined."),!1;try{await o.verifyEntry(t,this._keystore)}catch(e){return console.log(e),console.log("Couldn't verify entry:\n",t),!1}return!0})).every(t=>!0===t)},s=(t,e)=>(t[e.hash]=e,t);n=n||[t,this].sort((t,e)=>t.id>e.id)[0].id;const u=((t,e)=>{let n=Object.keys(t._headsIndex),r={},i={};for(;n.length>0;){const o=n.shift(),s=t.get(o);s&&!e.get(o)&&(i[s.hash]=s,r[s.hash]=!0,s.next.forEach(t=>{r[t]||e.get(t)||(n.push(t),r[t]=!0)}))}return i})(t,this);if(this._key){if(!await i(Object.values(u)))return this}if(this._entryIndex=Object.assign(this._entryIndex,u),this._length+=Object.values(u).length,e>-1){let t=this.values;t=t.slice(-e),this._entryIndex=t.reduce(s,{}),this._length=Object.values(this._entryIndex).length}const d=h.findHeads(Object.values(Object.assign({},this._headsIndex,t._headsIndex)));this._headsIndex=d.reduce(s,{});const l=Object.values(this._headsIndex).reduce((t,e)=>t=Math.max(t,e.clock.time),0),p=new c(this.id,Math.max(this.clock.time,l));return this._id=n,this._clock=p,this}toJSON(){return{id:this.id,heads:this.heads.map(t=>t.hash)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return e.from(JSON.stringify(this.toJSON()))}toString(t){return this.values.slice().reverse().map((e,n)=>{const r=o.findChildren(e,this.values).length;let i=new Array(Math.max(r-1,0));return i=r>1?i.fill(" "):i,(i=r>0?i.concat(["└─"]):i).join("")+(t?t(e.payload):e.payload)}).join("\n")}static isLog(t){return void 0!==t.id&&void 0!==t.heads&&void 0!==t._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static fromMultihash(t,e,n=-1,r,i,o){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw new Error(`Invalid hash: ${e}`);return s.fromMultihash(t,e,n,r,o).then(e=>new h(t,e.id,e.values,e.heads,e.clock,i))}static fromEntryHash(t,e,n,r=-1,i,o,c,u){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw new Error("'hash' must be defined");return s.fromEntryHash(t,e,n,r,i,u).then(e=>new h(t,n,e.values,null,null,o,c))}static fromJSON(t,e,n=-1,r,i,o,c){if(!f(t))throw a.ImmutableDBNotDefinedError();return s.fromJSON(t,e,n,r,o,c).then(e=>new h(t,e.id,e.values,null,null,r,i))}static fromEntry(t,e,n=-1,r,i){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw new Error("'sourceEntries' must be defined");return s.fromEntry(t,e,n,r,i).then(e=>new h(t,e.id,e.values))}static expandFrom(t,e,n,r=-1){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw a.LogNotDefinedError();if(!f(n))throw new Error("'entries' must be given as argument");if(!h.isLog(e))throw a.NotALogError();return s.expandFrom(t,e,n,r).then(n=>new h(t,e.id,n.values,null,e.clock))}static expand(t,e,n){if(!f(t))throw a.ImmutableDBNotDefinedError();if(!f(e))throw a.LogNotDefinedError();if(!h.isLog(e))throw a.NotALogError();return s.expand(t,e,n).then(n=>new h(t,e.id,n.values,e.heads,e.clock))}static findHeads(t){var e=t.reduce((t,e,n,r)=>{return e.next.forEach(n=>t[n]=e.hash),t},{});return t.filter(t=>void 0===e[t.hash]).sort((t,e)=>t.id>e.id)}static findTails(t){var e={},n=[],r={},i=[];t.forEach(t=>{0===t.next.length&&n.push(t);t.next.forEach(n=>{e[n]||(e[n]=[]),e[n].push(t)}),i=i.concat(t.next),r[t.hash]=!0});const s=i.filter(t=>void 0===r[t]).map(t=>e[t]).reduce((t,e,n,r)=>t.concat(u(e,"hash")),[]).concat(n);return u(s,"hash").sort(o.compare)}static findTailHashes(t){var e={};return t.forEach(t=>e[t.hash]=!0),t.reduce((t,n,r,i)=>{return n.next.reverse().forEach(n=>{void 0===e[n]&&t.splice(0,0,n)}),t},[])}}t.exports=h}).call(e,n(0).Buffer)},function(t,e,n){"use strict";t.exports={ImmutableDBNotDefinedError:()=>new Error("ImmutableDB instance not defined"),LogNotDefinedError:()=>new Error("Log instance not defined"),NotALogError:()=>new Error("Given argument is not an instance of Log")}},function(t,e,n){"use strict";t.exports=function(t,e){let n={};return t.forEach(t=>n[e?t[e]:t]=t),Object.keys(n).map(t=>n[t])}},function(t,e,n){"use strict";(function(e){const r=n(22),i=n(98),o=n(107);class s{constructor(t,e="data"){this.path=t||"./orbitdb",this.filename=e+".orbitdb",this._store=new i(this.path),this._cache={},this._lock=new o}get(t){return this._cache[t]}set(t,e){return new Promise((n,i)=>{if(this._cache[t]===e)return n(e);this._cache[t]=e,this._lock(this.filename,t=>{r(r.values([this._cache]),r.map(t=>JSON.stringify(t,null,2)),this._store.write(this.filename,t(t=>{if(t)return i(t);n(e)})))})})}load(){return this._cache={},new Promise((t,n)=>{this._store.exists(this.filename,(i,o)=>{if(i||!o)return t();this._lock(this.filename,i=>{r(this._store.read(this.filename),r.collect(i((r,i)=>{if(r)return n(r);try{this._cache=JSON.parse(e.concat(i).toString()||"{}")}catch(t){return n(t)}t()})))})})})}reset(){this._cache={},this._store=null}}t.exports=s}).call(e,n(0).Buffer)},function(t,e){t.exports=function(t,e,n){t(e),n&&n(!0===e?null:e)}},function(t,e,n){"use strict";var r=n(44);t.exports=function(t,e){return function(n,i){if(n)return r(i,n,e);if(null!=t){var o=t;t=null,i(null,o)}else i(!0)}}},function(t,e,n){var r=n(15);t.exports=function(t){return"object"==typeof t&&"function"==typeof t.test?function(e){return t.test(e)}:r(t)||function(t){return t}}},function(t,e,n){"use strict";var r=n(15),i=n(31);t.exports=function(t,e){t=r(t)||function(t){return t};var n={};return i(function(r){var i=t(r);return n[i]?!!e:(n[i]=!0,!e)})}},function(t,e){t.exports=function(t,e){function n(t,e){t&&(a=t,c&&s(a)),c=e,o()}function r(t){f=f||t||!0,o()}function i(t){f||(c?s(a,t):(u.push(t),o()))}function o(){c&&(a?s(a):!u.length&&f?s(f):u.length&&s(null,u.shift()))}function s(t,n){var r=c;if(t&&e){var i=e;e=null,i(!0===t?null:t)}c=null,r(t,n)}"function"==typeof t&&(e=t,t=!1);var a,c,f,u=[];return t?{push:i,end:r,source:n}:(n.push=i,n.end=r,n)}},function(t,e,n){"use strict";(function(e){const r=n(108),i=new(0,n(2).ec)("secp256k1");class o{constructor(t="./keystore"){if("undefined"==typeof localStorage||null===localStorage){r.sync(t);const e=n(133).LocalStorage;this._storage=new e(t)}else this._storage=localStorage}createKey(t){const e=i.genKeyPair(),n=e.getPublic("hex"),r=e.getPrivate("hex");return this._storage.setItem(t,JSON.stringify({publicKey:n,privateKey:r})),e}getKey(t){let e=JSON.parse(this._storage.getItem(t));if(!e)return;return i.keyPair({pub:e.publicKey,priv:e.privateKey,privEnc:"hex",pubEnc:"hex"})}static importKeyFromIpfs(t,e){return t.object.get(e,{enc:"base58"}).then(t=>JSON.parse(t.toJSON().Data)).then(t=>OrbitCrypto.importPublicKey(t))}static exportPublicKeyToIpfs(t,n){n.getPublic("hex");return OrbitCrypto.exportPublicKey(n).then(t=>JSON.stringify(t,null,2)).then(t=>new e(t)).then(e=>t.object.put(e)).then(t=>t.toJSON().multihash)}static getKey(t){let e,n,r,o=JSON.parse(keystore.getItem(t));return o?OrbitCrypto.importPrivateKey(o.privateKey).then(t=>r=t).then(()=>OrbitCrypto.importPublicKey(o.publicKey)).then(t=>n=t).then(()=>i.keyPair({pub:n,priv:r})):OrbitCrypto.generateKey().then(t=>e=t).then(()=>OrbitCrypto.exportPrivateKey(e)).then(t=>r=t).then(()=>OrbitCrypto.exportPublicKey(e)).then(t=>n=t).then(()=>(keystore.setItem(t,JSON.stringify({publicKey:n,privateKey:r})),i.keyPair({pub:n,priv:r})))}generateKey(){return Promise.resolve(i.genKeyPair())}exportPublicKey(t){return Promise.resolve(t.getPublic("hex"))}exportPrivateKey(t){return Promise.resolve(t.getPrivate("hex"))}importPublicKey(t){return Promise.resolve(i.keyFromPublic(t,"hex"))}importPrivateKey(t){return Promise.resolve(i.keyFromPrivate(t,"hex"))}sign(t,e){const n=i.sign(e,t);return Promise.resolve(n.toDER("hex"))}verify(t,e,n){let r=!1;return r=i.verify(n,t,e),Promise.resolve(r)}}t.exports=o}).call(e,n(0).Buffer)},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";function r(t){return 1===t.length?"0"+t:t}function i(t){for(var e="",n=0;n>8,s=255&i;o?n.push(o,s):n.push(s)}return n},o.zero2=r,o.toHex=i,o.encode=function(t,e){return"hex"===e?i(t):t}},function(t,e,n){"use strict";function r(t,e,n){return t&e^~t&n}function i(t,e,n){return t&e^t&n^e&n}function o(t,e,n){return t^e^n}var s=n(6).rotr32;e.ft_1=function(t,e,n,s){return 0===t?r(e,n,s):1===t||3===t?o(e,n,s):2===t?i(e,n,s):void 0},e.ch32=r,e.maj32=i,e.p32=o,e.s0_256=function(t){return s(t,2)^s(t,13)^s(t,22)},e.s1_256=function(t){return s(t,6)^s(t,11)^s(t,25)},e.g0_256=function(t){return s(t,7)^s(t,18)^t>>>3},e.g1_256=function(t){return s(t,17)^s(t,19)^t>>>10}},function(t,e,n){"use strict";function r(){if(!(this instanceof r))return new r;g.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=m,this.W=new Array(64)}var i=n(6),o=n(17),s=n(52),a=n(9),c=i.sum32,f=i.sum32_4,u=i.sum32_5,h=s.ch32,d=s.maj32,l=s.s0_256,p=s.s1_256,b=s.g0_256,y=s.g1_256,g=o.BlockHash,m=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];i.inherits(r,g),t.exports=r,r.blockSize=512,r.outSize=256,r.hmacStrength=192,r.padLength=64,r.prototype._update=function(t,e){for(var n=this.W,r=0;r<16;r++)n[r]=t[e+r];for(;r-1&&t%1==0&&t-1&&t%1==0&&t<=N}(t.length)&&!A(t)}function A(t){var e=O(t)?wt.call(t):"";return e==L||e==D}function O(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function I(t){return M(t)?p(t):function(t){if(!k(t))return Nt(t);var e=[];for(var n in Object(t))_t.call(t,n)&&"constructor"!=n&&e.push(n);return e}(t)}var P=200,C="__lodash_hash_undefined__",N=9007199254740991,R="[object Arguments]",j="[object Boolean]",T="[object Date]",L="[object Function]",D="[object GeneratorFunction]",B="[object Map]",F="[object Number]",q="[object Object]",U="[object Promise]",z="[object RegExp]",K="[object Set]",G="[object String]",H="[object Symbol]",Y="[object WeakMap]",W="[object ArrayBuffer]",J="[object DataView]",$="[object Float32Array]",V="[object Float64Array]",X="[object Int8Array]",Z="[object Int16Array]",Q="[object Int32Array]",tt="[object Uint8Array]",et="[object Uint8ClampedArray]",nt="[object Uint16Array]",rt="[object Uint32Array]",it=/\w*$/,ot=/^\[object .+?Constructor\]$/,st=/^(?:0|[1-9]\d*)$/,at={};at[R]=at["[object Array]"]=at[W]=at[J]=at[j]=at[T]=at[$]=at[V]=at[X]=at[Z]=at[Q]=at[B]=at[F]=at[q]=at[z]=at[K]=at[G]=at[H]=at[tt]=at[et]=at[nt]=at[rt]=!0,at["[object Error]"]=at[L]=at[Y]=!1;var ct="object"==typeof t&&t&&t.Object===Object&&t,ft="object"==typeof self&&self&&self.Object===Object&&self,ut=ct||ft||Function("return this")(),ht="object"==typeof e&&e&&!e.nodeType&&e,dt=ht&&"object"==typeof n&&n&&!n.nodeType&&n,lt=dt&&dt.exports===ht,pt=Array.prototype,bt=Function.prototype,yt=Object.prototype,gt=ut["__core-js_shared__"],mt=function(){var t=/[^.]+$/.exec(gt&>.keys&>.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),vt=bt.toString,_t=yt.hasOwnProperty,wt=yt.toString,St=RegExp("^"+vt.call(_t).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),kt=lt?ut.Buffer:void 0,xt=ut.Symbol,Et=ut.Uint8Array,Mt=c(Object.getPrototypeOf,Object),At=Object.create,Ot=yt.propertyIsEnumerable,It=pt.splice,Pt=Object.getOwnPropertySymbols,Ct=kt?kt.isBuffer:void 0,Nt=c(Object.keys,Object),Rt=S(ut,"DataView"),jt=S(ut,"Map"),Tt=S(ut,"Promise"),Lt=S(ut,"Set"),Dt=S(ut,"WeakMap"),Bt=S(Object,"create"),Ft=x(Rt),qt=x(jt),Ut=x(Tt),zt=x(Lt),Kt=x(Dt),Gt=xt?xt.prototype:void 0,Ht=Gt?Gt.valueOf:void 0;u.prototype.clear=function(){this.__data__=Bt?Bt(null):{}},u.prototype.delete=function(t){return this.has(t)&&delete this.__data__[t]},u.prototype.get=function(t){var e=this.__data__;if(Bt){var n=e[t];return n===C?void 0:n}return _t.call(e,t)?e[t]:void 0},u.prototype.has=function(t){var e=this.__data__;return Bt?void 0!==e[t]:_t.call(e,t)},u.prototype.set=function(t,e){return this.__data__[t]=Bt&&void 0===e?C:e,this},h.prototype.clear=function(){this.__data__=[]},h.prototype.delete=function(t){var e=this.__data__,n=y(e,t);return!(n<0||(n==e.length-1?e.pop():It.call(e,n,1),0))},h.prototype.get=function(t){var e=this.__data__,n=y(e,t);return n<0?void 0:e[n][1]},h.prototype.has=function(t){return y(this.__data__,t)>-1},h.prototype.set=function(t,e){var n=this.__data__,r=y(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},d.prototype.clear=function(){this.__data__={hash:new u,map:new(jt||h),string:new u}},d.prototype.delete=function(t){return w(this,t).delete(t)},d.prototype.get=function(t){return w(this,t).get(t)},d.prototype.has=function(t){return w(this,t).has(t)},d.prototype.set=function(t,e){return w(this,t).set(t,e),this},l.prototype.clear=function(){this.__data__=new h},l.prototype.delete=function(t){return this.__data__.delete(t)},l.prototype.get=function(t){return this.__data__.get(t)},l.prototype.has=function(t){return this.__data__.has(t)},l.prototype.set=function(t,e){var n=this.__data__;if(n instanceof h){var r=n.__data__;if(!jt||r.length{let e=t;return r.isBuffer(e)||(e=r.from(e)),e})},function(t,e,n){"use strict";(function(e){const r=n(16),i=n(24).format,o=n(4).EventEmitter;let s=!!e.version;const a={DEBUG:"DEBUG",INFO:"INFO",WARN:"WARN",ERROR:"ERROR",NONE:"NONE"};let c=a.DEBUG,f=null,u=new o,h={Black:0,Red:1,Green:2,Yellow:3,Blue:4,Magenta:5,Cyan:6,Grey:7,White:9,Default:9};s||(h={Black:"Black",Red:"IndianRed",Green:"LimeGreen",Yellow:"Orange",Blue:"RoyalBlue",Magenta:"Orchid",Cyan:"SkyBlue",Grey:"DimGrey",White:"White",Default:"Black"});const d=[h.Cyan,h.Green,h.Yellow,h.Red,h.Default],l={useColors:!0,color:h.Default,showTimestamp:!0,showLevel:!0,filename:f,appendFile:!0};class p{constructor(t,e){this.category=t;let n={};Object.assign(n,l),Object.assign(n,e),this.options=n}debug(){this._shouldLog(a.DEBUG)&&this._write(a.DEBUG,i.apply(null,arguments))}log(){this._shouldLog(a.DEBUG)&&this.debug.apply(this,arguments)}info(){this._shouldLog(a.INFO)&&this._write(a.INFO,i.apply(null,arguments))}warn(){this._shouldLog(a.WARN)&&this._write(a.WARN,i.apply(null,arguments))}error(){this._shouldLog(a.ERROR)&&this._write(a.ERROR,i.apply(null,arguments))}_write(t,e){(this.options.filename||f)&&!this.fileWriter&&s&&(this.fileWriter=r.openSync(this.options.filename||f,this.options.appendFile?"a+":"w+"));let n=this._format(t,e),i=this._createLogMessage(t,e),o=this._createLogMessage(t,e,n.timestamp,n.level,n.category,n.text);this.fileWriter&&s&&r.writeSync(this.fileWriter,i+"\n",null,"utf-8"),s||!this.options.useColors?(console.log(o),u.emit("data",this.category,t,e)):t===a.ERROR?this.options.showTimestamp&&this.options.showLevel?console.error(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.error(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.error(o,n.level,n.category,n.text):console.error(o,n.category,n.text):this.options.showTimestamp&&this.options.showLevel?console.log(o,n.timestamp,n.level,n.category,n.text):this.options.showTimestamp&&!this.options.showLevel?console.log(o,n.timestamp,n.category,n.text):!this.options.showTimestamp&&this.options.showLevel?console.log(o,n.level,n.category,n.text):console.log(o,n.category,n.text)}_format(t,e){let n="",r="",i="",o=": ";if(this.options.useColors){const e=Object.keys(a).map(t=>a[t]).indexOf(t),c=this.options.color;s?(this.options.showTimestamp&&(n="[3"+h.Grey+"m"),this.options.showLevel&&(r="[3"+d[e]+";22m"),i="[3"+c+";1m",o=": "):(this.options.showTimestamp&&(n="color:"+h.Grey),this.options.showLevel&&(r="color:"+d[e]),i="color:"+c+"; font-weight: bold")}return{timestamp:n,level:r,category:i,text:o}}_createLogMessage(t,e,n,r,i,o){n=n||"",r=r||"",i=i||"",o=o||": ",!s&&this.options.useColors&&(this.options.showTimestamp&&(n="%c"),this.options.showLevel&&(r="%c"),i="%c",o=": %c");let c="";return this.options.showTimestamp&&(c+=(new Date).toISOString()+" "),c=n+c,this.options.showLevel&&(c+=r+"["+t+"]"+(t===a.INFO||t===a.WARN?" ":"")+" "),c+=i+this.category,c+=o+e}_shouldLog(t){let n=void 0!==e&&void 0!==Object({NODE_ENV:void 0})&&void 0!==Object({NODE_ENV:void 0}).LOG?Object({NODE_ENV:void 0}).LOG.toUpperCase():null;const r=(n="undefined"!=typeof window&&window.LOG?window.LOG.toUpperCase():n)||c,i=Object.keys(a).map(t=>a[t]);return i.indexOf(t)>=i.indexOf(r)}}t.exports={Colors:h,LogLevels:a,setLogLevel:t=>{c=t},setLogfile:t=>{f=t},create:(t,e)=>{return new p(t,e)},forceBrowserMode:t=>s=!t,events:u}}).call(e,n(1))},function(t,e,n){"use strict";(function(e){const r=n(11),i=n(34),o=n(155),s=n(157),a=n(159),c=n(163),f=n(165),u=n(43),h=n(49),d=n(174),l=n(176),p=n(60),b=p.create("orbit-db");p.setLogLevel("NONE");const y=["eventlog","feed","docstore","counter","keyvalue"];class g{constructor(t,e,n={}){this._ipfs=t,this.id=n.peerId||(this._ipfs._peerInfo?this._ipfs._peerInfo.id._idB58String:"default"),this._pubsub=n&&n.broker?new n.broker(this._ipfs):new f(this._ipfs,this.id),this.stores={},this.types=y,this.directory=e||"./orbitdb",this.keystore=new h(r.join(this.directory,this.id,"/keystore")),this.key=this.keystore.getKey(this.id)||this.keystore.createKey(this.id)}async feed(t,e={}){return e=Object.assign({create:!0,type:"feed"},e),this.open(t,e)}async log(t,e){return e=Object.assign({create:!0,type:"eventlog"},e),this.open(t,e)}async eventlog(t,e={}){return this.log(t,e)}async keyvalue(t,e){return e=Object.assign({create:!0,type:"keyvalue"},e),this.open(t,e)}async kvstore(t,e){return this.keyvalue(t,e)}async counter(t,e={}){return e=Object.assign({create:!0,type:"counter"},e),this.open(t,e)}async docs(t,e={}){return e=Object.assign({create:!0,type:"docstore"},e),this.open(t,e)}async docstore(t,e={}){return this.docs(t,e)}async disconnect(){const t=Object.values(this.stores);for(let e of t)await e.close(),delete this.stores[e.address.toString()];this._pubsub&&this._pubsub.disconnect(),this.stores={}}async stop(){await this.disconnect()}async _createStore(t,e,n){const r=e.toString();let i;n.accessControllerAddress&&(i=new d(this._ipfs),await i.load(n.accessControllerAddress));const o=Object.assign({replicate:!0},n,{accessController:i,keystore:this.keystore,cache:this._cache}),s=new t(this._ipfs,this.id,e,o);return s.events.on("write",this._onWrite.bind(this)),s.events.on("closed",this._onClosed.bind(this)),this.stores[r]=s,o.replicate&&this._pubsub&&this._pubsub.subscribe(r,this._onMessage.bind(this),this._onPeerConnected.bind(this)),s}_onWrite(t,e,n){if(!n)throw new Error("'heads' not defined");this._pubsub&&this._pubsub.publish(t,n)}async _onMessage(t,e){const n=this.stores[t];try{b.debug(`Received heads for '${t}':\n`,JSON.stringify(e,null,2)),await n.sync(e)}catch(t){b.error(t)}}_onPeerConnected(t,n,r){b.debug(`New peer '${n}' connected to '${t}'`);const i=this.stores[t];if(i){let o=i._oplog.heads;o.length>0&&(b.debug(`Send latest heads of '${t}':\n`,JSON.stringify(o,null,2)),r.sendTo(n,new e(JSON.stringify(o)))),i.events.emit("peer",n)}}_onClosed(t){b.debug(`Database '${t}' was closed`),this.stores[t].events.removeAllListeners("closed"),this._pubsub&&this._pubsub.unsubscribe(t),delete this.stores[t]}async create(t,n,i={}){if(!g.isValidType(n))throw new Error(`Invalid database type '${n}'`);const o=i.directory||this.directory;if(b.debug(`Creating database '${t}' as ${n} in '${o}'`),l.isValid(t))throw new Error("Given database name is an address. Please give only the name of the database!");const s=new d(this._ipfs);i&&i.write?i.write.forEach(t=>s.add("write",t)):s.add("write",this.key.getPublic("hex"));const a=await s.save(),c={name:t,type:n,accessController:r.join("/ipfs",a)},f=(await this._ipfs.object.put(new e(JSON.stringify(c)))).toJSON().multihash.toString(),h=r.join("/orbitdb",f,t),p=l.parse(h);try{const t=r.join(p.root,p.path);this._cache=new u(r.join(o),t),await this._cache.load()}catch(t){b.warn("Couldn't load Cache:",t)}let y=await this._cache.get(p.toString());if(y&&y.manifest&&!i.overwrite)throw new Error(`Database '${p}' already exists!`);return y=Object.assign({},this._cache.get(p.toString()),{manifest:p.root}),await this._cache.set(p.toString(),y),b.debug(`Saved manifest to IPFS as '${p.root}'`),b.debug(`Created database '${p}'`),this.open(p,i)}async open(t,e={}){e=Object.assign({localOnly:!1,create:!1},e),b.debug(`Open database '${t}'`);const n=e.directory||this.directory;if(b.debug(`Look from '${n}'`),!l.isValid(t)){if(e.create){if(e.create&&!e.type)throw new Error(`Database type not provided! Provide a type with 'options.type' (${y.join("|")})`);return b.warn(`Not a valid OrbitDB address '${t}', creating the database`),e.overwrite=!e.overwrite||e.overwrite,this.create(t,e.type,e)}throw new Error("'options.create' set to 'false'. If you want to create a database, set 'options.create' to 'true'.")}const i=l.parse(t);try{const t=r.join(i.root,i.path);this._cache=new u(r.join(n),t),await this._cache.load()}catch(t){console.warn(t),b.warn("Couldn't load Cache:",t)}let o=await this._cache.get(i.toString());const s=o&&o.manifest;if(b.debug((s?"Found":"Didn't find")+` database '${i}'`),e.localOnly&&!s)throw b.error(`Database '${i}' doesn't exist!`),new Error(`Database '${i}' doesn't exist!`);b.debug(`Loading Manifest for '${i}'`);const a=await this._ipfs.object.get(i.root),c=JSON.parse(a.toJSON().data);if(b.debug(`Manifest for '${i}':\n${JSON.stringify(c,null,2)}`),e.type&&c.type!==e.type)throw new Error(`Database '${i}' is type '${c.type}' but was opened as '${e.type}'`);return o=Object.assign({},this._cache.get(i.toString()),{manifest:i.root}),await this._cache.set(i.toString(),o),b.debug(`Saved manifest to IPFS as '${i.root}'`),e=Object.assign({},e,{accessControllerAddress:c.accessController}),this._openDatabase(i,c.type,e)}async _openDatabase(t,e,n){if("counter"===e)return this._createStore(a,t,n);if("eventlog"===e)return this._createStore(i,t,n);if("feed"===e)return this._createStore(o,t,n);if("docstore"===e)return this._createStore(c,t,n);if("keyvalue"===e)return this._createStore(s,t,n);throw new Error(`Invalid database type '${e}'`)}static isValidType(t){return y.includes(t)}static create(){return new Error("Not implemented yet!")}static open(){return new Error("Not implemented yet!")}}t.exports=g}).call(e,n(0).Buffer)},function(t,e,n){"use strict";function r(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function i(t){return s[t>>18&63]+s[t>>12&63]+s[t>>6&63]+s[63&t]}function o(t,e,n){for(var r,o=[],s=e;s0?f-4:f;var u=0;for(e=0;e>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=a[t.charCodeAt(e)]<<2|a[t.charCodeAt(e+1)]>>4,s[u++]=255&i):1===o&&(i=a[t.charCodeAt(e)]<<10|a[t.charCodeAt(e+1)]<<4|a[t.charCodeAt(e+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s},e.fromByteArray=function(t){for(var e,n=t.length,r=n%3,i="",a=[],c=0,f=n-r;cf?f:c+16383));return 1===r?(e=t[n-1],i+=s[e>>2],i+=s[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=s[e>>10],i+=s[e>>4&63],i+=s[e<<2&63],i+="="),a.push(i),a.join("")};for(var s=[],a=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u=0,h=f.length;u>1,u=-7,h=n?i-1:0,d=n?-1:1,l=t[e+h];for(h+=d,o=l&(1<<-u)-1,l>>=-u,u+=a;u>0;o=256*o+t[e+h],h+=d,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=r;u>0;s=256*s+t[e+h],h+=d,u-=8);if(0===o)o=1-f;else{if(o===c)return s?NaN:1/0*(l?-1:1);s+=Math.pow(2,r),o-=f}return(l?-1:1)*s*Math.pow(2,o-r)},e.write=function(t,e,n,r,i,o){var s,a,c,f=8*o-i-1,u=(1<>1,d=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=r?0:o-1,p=r?1:-1,b=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=u):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),(e+=s+h>=1?d/c:d*Math.pow(2,1-h))*c>=2&&(s++,c/=2),s+h>=u?(a=0,s=u):s+h>=1?(a=(e*c-1)*Math.pow(2,i),s+=h):(a=e*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;t[n+l]=255&a,l+=p,a/=256,i-=8);for(s=s<0;t[n+l]=255&s,l+=p,s/=256,f-=8);t[n+l-p]|=128*b}},function(t,e){},function(t,e,n){"use strict";function r(t,e,n){t.copy(e,n)}var i=n(10).Buffer;t.exports=function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.head=null,this.tail=null,this.length=0}return t.prototype.push=function(t){var e={data:t,next:null};this.length>0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,n=""+e.data;e=e.next;)n+=t+e.data;return n},t.prototype.concat=function(t){if(0===this.length)return i.alloc(0);if(1===this.length)return this.head.data;for(var e=i.allocUnsafe(t>>>0),n=this.head,o=0;n;)r(n.data,e,o),o+=n.data.length,n=n.next;return e},t}()},function(t,e,n){(function(t,e){!function(t,n){"use strict";function r(t){delete a[t]}function i(t){if(c)setTimeout(i,0,t);else{var e=a[t];if(e){c=!0;try{!function(t){var e=t.callback,r=t.args;switch(r.length){case 0:e();break;case 1:e(r[0]);break;case 2:e(r[0],r[1]);break;case 3:e(r[0],r[1],r[2]);break;default:e.apply(n,r)}}(e)}finally{r(t),c=!1}}}}if(!t.setImmediate){var o,s=1,a={},c=!1,f=t.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(t);u=u&&u.setTimeout?u:t,"[object process]"==={}.toString.call(t.process)?o=function(t){e.nextTick(function(){i(t)})}:function(){if(t.postMessage&&!t.importScripts){var e=!0,n=t.onmessage;return t.onmessage=function(){e=!1},t.postMessage("","*"),t.onmessage=n,e}}()?function(){var e="setImmediate$"+Math.random()+"$",n=function(n){n.source===t&&"string"==typeof n.data&&0===n.data.indexOf(e)&&i(+n.data.slice(e.length))};t.addEventListener?t.addEventListener("message",n,!1):t.attachEvent("onmessage",n),o=function(n){t.postMessage(e+n,"*")}}():t.MessageChannel?function(){var t=new MessageChannel;t.port1.onmessage=function(t){i(t.data)},o=function(e){t.port2.postMessage(e)}}():f&&"onreadystatechange"in f.createElement("script")?function(){var t=f.documentElement;o=function(e){var n=f.createElement("script");n.onreadystatechange=function(){i(e),n.onreadystatechange=null,t.removeChild(n),n=null},t.appendChild(n)}}():o=function(t){setTimeout(i,0,t)},u.setImmediate=function(t){"function"!=typeof t&&(t=new Function(""+t));for(var e=new Array(arguments.length-1),n=0;nr(t,(t,n,r)=>e(n,r)).then(()=>t))},function(t,e,n){"use strict";t.exports=((t,e,n)=>new Promise((r,i)=>{const o=t[Symbol.iterator]();let s=0;const a=t=>{const n=o.next();n.done?r(t):Promise.all([t,n.value]).then(t=>{a(e(t[0],t[1],s++))}).catch(i)};a(n)}))},function(t,e,n){"use strict";class r{constuctor(t){}append(t){}merge(t){}get(t){}has(t){}get values(){}get length(){}}t.exports=r},function(t,e,n){"use strict";n(21);const r=n(26),i=n(73),o=n(27),s=n(41),a=n(28),c=n(42),f=n(75),u=n(76);class h{static toMultihash(t,e){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw s.LogNotDefinedError();if(e.values.length<1)throw new Error("Can't serialize an empty log");return t.object.put(e.toBuffer()).then(t=>t.toJSON().multihash)}static fromMultihash(t,e,n=-1,c,f){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw new Error(`Invalid hash: ${e}`);return t.object.get(e,{enc:"base58"}).then(t=>JSON.parse(t.toJSON().data)).then(e=>{if(!e.heads||!e.id)throw s.NotALogError();return i.fetchAll(t,e.heads,n,c,null,f).then(t=>{const n=t.reduce((t,e)=>e.clock.time>t.time?new o(e.clock.id,e.clock.time):t,new o(e.id)),i=t.slice().sort(r.compare),s=i.filter(t=>e.heads.includes(t.hash));return{id:e.id,values:i,heads:s,clock:n}})})}static fromEntryHash(t,e,n,r=-1,o,c){if(!a(t))throw s.IpfsNotDefinedError();if(!a(e))throw new Error("'entryHash' must be defined");r=r>-1?Math.max(r,1):r;const f=o;return i.fetchParallel(t,[e],r,f,null,null,c).then(t=>{return{values:r>-1?((t,e)=>t.slice(t.length-e,t.length))(t,r):t}})}static fromJSON(t,e,n=-1,o,c,f){if(!a(t))throw s.ImmutableDBNotDefinedError();return i.fetchParallel(t,e.heads.map(t=>t.hash),n,[],16,c,f).then(t=>{const n=t.slice().sort(r.compare);t.filter(t=>e.heads.includes(t.hash));return{id:e.id,values:n,heads:e.heads}})}static fromEntry(t,e,n=-1,o,f,h,d){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(e)&&!r.isEntry(e))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(e)||(e=[e]),n=n>-1?Math.max(n,e.length):n;const l=o?o.map(t=>t.hash?t.hash:t):o,p=e.map(t=>t.hash);return i.fetchParallel(t,p,n,l,null,null,d).then(t=>{var i=e.concat(t),o=c(i,"hash").sort(r.compare);const s=o.slice(n>-1?-n:-o.length),a=((t,e)=>{var n=t.slice(e.length,t.length);return e.concat(n)})(s,u(s,e,"hash"));return{id:a[a.length-1].id,values:a}})}static expandFrom(t,e,n,r=-1){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw s.LogNotDefinedError();if(!a(n))throw new Error("'entries' must be given as argument");Array.isArray(n)||(n=[n]);const o=n.map(t=>t.next).filter(t=>t.length>0);return 0===o.length?Promise.resolve({values:e.values}):i.fetchParallel(t,o,r,e.values).then(t=>{return{values:e.merge(t.slice(0,r))}})}static expand(t,e,n=-1){if(!a(t))throw s.ImmutableDBNotDefinedError();if(!a(e))throw s.LogNotDefinedError();return 0===e.tailHashes.length?Promise.resolve({values:e.values}):i.fetchParallel(t,e.tailHashes,n,e.values).then(t=>{const i=n>-1?e.values.length+n:-1,o=e.values.concat(t).sort(r.compare),s=i>-1?o.slice(-i):o.slice(),a=u(s,e.values,"hash").sort(r.compare),h=u(e.values,s,"hash").sort(r.compare),d=f(e.values,s,"hash").sort(r.compare),l=i-(d.length+a.length),p=(t,e)=>{var n=[];n=t.concat(e);return c(n,"hash").sort(r.compare)};return{values:p(a,p(d,l>-1?h.slice(-l):h))}})}}t.exports=h},function(t,e,n){"use strict";const r=n(74),i=n(21),o=n(26);let s=0,a=0;class c{static fetchParallel(t,e,n,r=[],o,s,a){const f=(t,e)=>t.concat(e);return i(e,e=>c.fetchAll(t,e,n,r,s,a),{concurrency:Math.max(o||e.length,1)}).then(t=>t.reduce(f,[]))}static fetchAll(t,e,n,i=[],c=null,f){let u=[],h={},d=Array.isArray(e)?e.slice():[e];const l=t=>d.push(t);i.forEach(t=>h[t.hash]=t);return r(()=>d.length>0&&(u.length{const e=d.shift();return h[e]?Promise.resolve():new Promise((n,r)=>{const i=c?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${e}', request timed out (${c}ms)`),n()},c):null;s++,o.fromMultihash(t,e).then(t=>{clearTimeout(i),o.isEntry(t)&&(t.next.forEach(l),u.push(t),h[e]=t,a++,f&&f(e,t,u.length))}).then(n).catch(t=>{n()})})}).then(()=>u)}}t.exports=c},function(t,e,n){"use strict";const r=t=>new Promise(e=>{e(t())});t.exports=((t,e)=>r(function n(){if(t())return r(e).then(n)}))},function(t,e,n){"use strict";t.exports=function(t,e,n){var r={},i={};return t.forEach(t=>i[n?t[n]:t]=!0),e.reduce((t,e)=>{var o=void 0!==i[n?e[n]:e],s=void 0!==r[n?e[n]:e];return o&&!s&&(t.push(e),r[n?e[n]:e]=!0),t},[])}},function(t,e,n){"use strict";t.exports=function(t,e,n){var r={},i={};return t.forEach(t=>i[n?t[n]:t]=!0),e.reduce((t,e)=>{var o=void 0!==i[n?e[n]:e],s=void 0!==r[n?e[n]:e];return o||s||(t.push(e),r[n?e[n]:e]=!0),t},[])}},function(t,e,n){"use strict";t.exports={keys:n(78),once:n(45),values:n(29),count:n(79),infinite:n(80),empty:n(81),error:n(82)}},function(t,e,n){"use strict";var r=n(29);t.exports=function(t){return r(Object.keys(t))}},function(t,e,n){"use strict";t.exports=function(t){var e=0;return t=t||1/0,function(n,r){return n?r&&r(n):e>t?r(!0):void r(null,e++)}}},function(t,e,n){"use strict";t.exports=function(t){return t=t||Math.random,function(e,n){return e?n&&n(e):n(null,t())}}},function(t,e,n){"use strict";t.exports=function(){return function(t,e){e(!0)}}},function(t,e,n){"use strict";t.exports=function(t){return function(e,n){n(t)}}},function(t,e,n){"use strict";t.exports={drain:n(14),onEnd:n(84),log:n(85),find:n(86),reduce:n(30),collect:n(87),concat:n(88)}},function(t,e,n){"use strict";var r=n(14);t.exports=function(t){return r(null,t)}},function(t,e,n){"use strict";var r=n(14);t.exports=function(t){return r(function(t){console.log(t)},t)}},function(t,e,n){"use strict";function r(t){return t}var i=n(15),o=n(14);t.exports=function(t,e){var n=!1;return e?t=i(t)||r:(e=t,t=r),o(function(r){if(t(r))return n=!0,e(null,r),!1},function(t){n||e(!0===t?null:t,null)})}},function(t,e,n){"use strict";var r=n(30);t.exports=function(t){return r(function(t,e){return t.push(e),t},[],t)}},function(t,e,n){"use strict";var r=n(30);t.exports=function(t){return r(function(t,e){return t+e},"",t)}},function(t,e,n){"use strict";t.exports={map:n(90),asyncMap:n(91),filter:n(31),filterNot:n(92),through:n(93),take:n(94),unique:n(47),nonUnique:n(95),flatten:n(96)}},function(t,e,n){"use strict";function r(t){return t}var i=n(15);t.exports=function(t){return t?(t=i(t),function(e){return function(n,r){e(n,function(n,i){try{i=n?null:t(i)}catch(t){return e(t,function(){return r(t)})}r(n,i)})}}):r}},function(t,e,n){"use strict";function r(t){return t}var i=n(15);t.exports=function(t){if(!t)return r;t=i(t);var e,n,o=!1;return function(r){return function i(s,a){if(n)return a(n);s?(n=s,o?r(s,function(){o?e=a:a(s)}):r(s,a)):r(null,function(r,s){r?a(r):n?a(n):(o=!0,t(s,function(t,r){o=!1,n?(a(n),e(n)):t?i(t,a):a(null,r)}))})}}}},function(t,e,n){"use strict";var r=n(46),i=n(31);t.exports=function(t){return t=r(t),i(function(e){return!t(e)})}},function(t,e,n){"use strict";t.exports=function(t,e){function n(t){!r&&e&&(r=!0,e(!0===t?null:t))}var r=!1;return function(e){return function(r,i){return r&&n(r),e(r,function(e,r){e?n(e):t&&t(r),i(e,r)})}}}},function(t,e,n){"use strict";t.exports=function(t,e){var n=(e=e||{}).last||!1,r=!1;if("number"==typeof t){n=!0;var i=t;t=function(){return--i}}return function(e){function i(t){e(!0,function(e){n=!1,t(e||!0)})}return function(o,s){r?n?i(s):s(r):(r=o)?e(r,s):e(null,function(e,o){(r=r||e)?s(r):t(o)?s(null,o):(r=!0,n?s(null,o):i(s))})}}}},function(t,e,n){"use strict";var r=n(47);t.exports=function(t){return r(t,!0)}},function(t,e,n){"use strict";var r=n(29),i=n(45);t.exports=function(){return function(t){var e;return function(n,o){function s(){e(null,function(e,n){!0===e?a():e?t(!0,function(t){o(e)}):o(null,n)})}function a(){e=null,t(null,function(t,n){if(t)return o(t);Array.isArray(n)||n&&"object"==typeof n?n=r(n):"function"!=typeof n&&(n=i(n)),e=n,s()})}n?e?e(n,function(e){t(e||n,o)}):t(n,o):e?s():a()}}}},function(t,e,n){"use strict";t.exports=function t(e){var n=arguments.length;if("function"==typeof e&&1===e.length){for(var r=new Array(n),i=0;i99?t.push(e.concat(n)):t[r(t)]=e.concat(i(t).concat(n)),t},100,n)))}),a):(n(new Error("Missing key")),a)}},{key:"read",value:function(t){var e=this,n=f();return t?(this.exists(t,function(r,i){return r?n.end(r):i?void e.table.where("key").equals(t).each(function(t){return n.push(u(t.blob))}).catch(function(t){return n.end(t)}).then(function(){return n.end()}):n.end(new Error("Not found"))}),n):(n.end(new Error("Missing key")),n)}},{key:"exists",value:function(t,e){if(e=e||function(){},!t)return e(new Error("Missing key"));this.table.where("key").equals(t).count().then(function(t){return e(null,Boolean(t))}).catch(e)}},{key:"remove",value:function(t,e){if(e=e||function(){},!t)return e(new Error("Missing key"));var n=this.table.where("key").equals(t);n.count(function(t){return t>0?n.delete():null}).then(function(){return e()}).catch(e)}},{key:"table",get:function(){return this.db[this.path]}}]),t}()}).call(e,n(0).Buffer)},function(t,e,n){(function(e,n){!function(e,n){t.exports=n()}(0,function(){"use strict";function t(t,e){return"object"!=typeof e?t:(mt(e).forEach(function(n){t[n]=e[n]}),t)}function r(t,e){return St.call(t,e)}function i(t,e){"function"==typeof e&&(e=e(wt(t))),mt(e).forEach(function(n){o(t,n,e[n])})}function o(e,n,i,o){Object.defineProperty(e,n,t(i&&r(i,"get")&&"function"==typeof i.get?{get:i.get,set:i.set,configurable:!0}:{value:i,configurable:!0,writable:!0},o))}function s(t){return{from:function(e){return t.prototype=Object.create(e.prototype),o(t.prototype,"constructor",t),{extend:i.bind(null,t.prototype)}}}}function a(t,e){var n;return kt(t,e)||(n=wt(t))&&a(n,e)}function c(t,e,n){return xt.call(t,e,n)}function f(t,e){return e(t)}function u(t){var e=setTimeout(t,1e3);clearTimeout(e)}function h(t){if(!t)throw new Error("Assertion Failed")}function d(t){_t.setImmediate?n(t):setTimeout(t,0)}function l(t,e){return t.reduce(function(t,n,r){var i=e(n,r);return i&&(t[i[0]]=i[1]),t},{})}function p(t,e){return function(){try{t.apply(this,arguments)}catch(t){e(t)}}}function b(t,e,n){try{t.apply(null,n)}catch(t){e&&e(t)}}function y(t,e){if(r(t,e))return t[e];if(!e)return t;if("string"!=typeof e){for(var n=[],i=0,o=e.length;i0;)for(t=Zt,Zt=[],n=t.length,e=0;e0);Ht=!0,Yt=!0}function X(){var t=Wt;Wt=[],t.forEach(function(t){t._PSD.onunhandled.call(null,t._value,t)});for(var e=te.slice(0),n=e.length;n;)e[--n]()}function Z(t){return new F(qt,!1,t)}function Q(t,e){var n=Xt;return function(){var r=$(),i=Xt;try{return i!==n&&(Xt=n),t.apply(this,arguments)}catch(t){e&&e(t)}finally{i!==n&&(Xt=i),r&&V()}}}function tt(t,e,n,r){var i=Xt,o=Object.create(i);o.parent=i,o.ref=0,o.global=!1,++i.ref,o.finalize=function(){--this.parent.ref||this.parent.finalize()};var s=et(o,t,e,n,r);return 0===o.ref&&o.finalize(),s}function et(t,e,n,r,i){var o=Xt;try{return t!==o&&(Xt=t),e(n,r,i)}finally{t!==o&&(Xt=o)}}function nt(e,n){var r;try{r=n.onuncatched(e)}catch(t){}if(!1!==r)try{var i,o={promise:n,reason:e};if(_t.document&&document.createEvent?((i=document.createEvent("Event")).initEvent(ne,!0,!0),t(i,o)):_t.CustomEvent&&t(i=new CustomEvent(ne,{detail:o}),o),i&&_t.dispatchEvent&&(dispatchEvent(i),!_t.PromiseRejectionEvent&&_t.onunhandledrejection))try{_t.onunhandledrejection(i)}catch(t){}i.defaultPrevented||F.on.error.fire(e,n)}catch(t){}}function rt(t,e){var n=F.reject(t);return e?n.uncaught(e):n}function it(e,n){function a(t){this._cfg={version:t,storesSource:null,dbschema:{},tables:{},contentUpgrade:null},this.stores({})}function d(t,e,n){var r=Ht._createTransaction(Gt,Lt,jt);r.create(e),r._completion.catch(n);var i=r._reject.bind(r);tt(function(){Xt.trans=r,0===t?(mt(jt).forEach(function(t){E(e,t,jt[t].primKey,jt[t].indexes)}),F.follow(function(){return Ht.on.populate.fire(r)}).catch(i)):function(t,e,n){function r(){return i.length?F.resolve(i.shift()(e.idbtrans)).then(r):F.resolve()}var i=[],o=Tt.filter(function(e){return e._cfg.version===t})[0];if(!o)throw new Dt.Upgrade("Dexie specification of currently installed DB version is missing");jt=Ht._dbSchema=o._cfg.dbschema;var s=!1;Tt.filter(function(e){return e._cfg.version>t}).forEach(function(t){i.push(function(){var r=jt,i=t._cfg.dbschema;_t(r,n),_t(i,n),jt=Ht._dbSchema=i;var o=function(t,e){var n={del:[],add:[],change:[]};for(var r in t)e[r]||n.del.push(r);for(r in e){var i=t[r],o=e[r];if(i){var s={name:r,def:o,recreate:!1,del:[],add:[],change:[]};if(i.primKey.src!==o.primKey.src)s.recreate=!0,n.change.push(s);else{var a=i.idxByName,c=o.idxByName;for(var f in a)c[f]||s.del.push(f);for(f in c){var u=a[f],h=c[f];u?u.src!==h.src&&s.change.push(h):s.add.push(h)}(s.del.length>0||s.add.length>0||s.change.length>0)&&n.change.push(s)}}else n.add.push([r,o])}return n}(r,i);if(o.add.forEach(function(t){E(n,t[0],t[1].primKey,t[1].indexes)}),o.change.forEach(function(t){if(t.recreate)throw new Dt.Upgrade("Not yet support for changing primary key");var e=n.objectStore(t.name);t.add.forEach(function(t){I(e,t)}),t.change.forEach(function(t){e.deleteIndex(t.name),I(e,t)}),t.del.forEach(function(t){e.deleteIndex(t)})}),t._cfg.contentUpgrade)return s=!0,F.follow(function(){t._cfg.contentUpgrade(e)})}),i.push(function(e){if(!s||!fe){!function(t,e){for(var n=0;n0&&(Jt=!1),!Nt)throw new Dt.MissingAPI("indexedDB API not found. If using IE10+, make sure to run your code on a server URL (not locally). If using old Safari versions, make sure to include indexedDB polyfill.");var i=Jt?Nt.open(e):Nt.open(e,Math.round(10*Ht.verno));if(!i)throw new Dt.MissingAPI("IndexedDB API not available");i.onerror=Q(ft(r)),i.onblocked=Q(wt),i.onupgradeneeded=Q(function(t){if(n=i.transaction,Jt&&!Ht._allowEmptyDB){i.onerror=ht,n.abort(),i.result.close();var o=Nt.deleteDatabase(e);o.onsuccess=o.onerror=Q(function(){r(new Dt.NoSuchDatabase("Database "+e+" doesnt exist"))})}else{n.onerror=Q(ft(r));d((t.oldVersion>Math.pow(2,62)?0:t.oldVersion)/10,n,r)}},r),i.onsuccess=Q(function(){if(n=null,Ft=i.result,ae.push(Ht),Jt)!function(){if(Ht.verno=Ft.version/10,Ht._dbSchema=jt={},0!==(Lt=c(Ft.objectStoreNames,0)).length){var t=Ft.transaction(yt(Lt),"readonly");Lt.forEach(function(e){for(var n=t.objectStore(e),r=n.keyPath,i=r&&"string"==typeof r&&-1!==r.indexOf("."),o=new pt(r,r||"",!1,!1,!!n.autoIncrement,r&&"string"!=typeof r,i),s=[],a=0;a0)try{_t(jt,Ft.transaction(yt(Ft.objectStoreNames),Kt))}catch(t){}Ft.onversionchange=Q(function(t){Ht._vcFired=!0,Ht.on("versionchange").fire(t)}),$t||dt(function(t){if(-1===t.indexOf(e))return t.push(e)}),t()},r)})]).then(function(){return it.vip(Ht.on.ready.fire)}).then(function(){return Ut=!1,Ht}).catch(function(t){try{n&&n.abort()}catch(t){}return Ut=!1,Ht.close(),qt=t,rt(qt,C)}).finally(function(){zt=!0,t()})},this.close=function(){var t=ae.indexOf(Ht);if(t>=0&&ae.splice(t,1),Ft){try{Ft.close()}catch(t){}Ft=null}Ct=!1,qt=new Dt.DatabaseClosed,Ut&&kt(qt),Yt=new F(function(t){St=t}),Wt=new F(function(t,e){kt=e})},this.delete=function(){var t=arguments.length>0;return new F(function(n,r){function i(){Ht.close();var t=Nt.deleteDatabase(e);t.onsuccess=Q(function(){$t||dt(function(t){var n=t.indexOf(e);if(n>=0)return t.splice(n,1)}),n()}),t.onerror=Q(ft(r)),t.onblocked=wt}if(t)throw new Dt.InvalidArgument("Arguments not allowed in db.delete()");Ut?Yt.then(i):i()}).uncaught(C)},this.backendDB=function(){return Ft},this.isOpen=function(){return null!==Ft},this.hasFailed=function(){return null!==qt},this.dynamicallyOpened=function(){return Jt},this.name=e,o(this,"tables",{get:function(){return mt(Bt).map(function(t){return Bt[t]})}}),this.on=B(this,"error","populate","blocked","versionchange",{ready:[P,S]}),this.on.error.subscribe=j("Dexie.on.error",this.on.error.subscribe),this.on.error.unsubscribe=j("Dexie.on.error.unsubscribe",this.on.error.unsubscribe),this.on.ready.subscribe=f(this.on.ready.subscribe,function(t){return function(e,n){it.vip(function(){zt?(qt||F.resolve().then(e),n&&t(e)):(t(e),n||t(function t(){Ht.on.ready.unsubscribe(e),Ht.on.ready.unsubscribe(t)}))})}}),de(function(){Ht.on("populate").fire(Ht._createTransaction(Gt,Lt,jt)),Ht.on("error").fire(new Error)}),this.transaction=function(t,e,n){function i(e){var i=Xt;e(F.resolve().then(function(){return tt(function(){Xt.transless=Xt.transless||i;var e=Ht._createTransaction(t,u,jt,c);Xt.trans=e,c?e.idbtrans=c.idbtrans:e.create();var o=u.map(function(t){return Bt[t]});o.push(e);var s;return F.follow(function(){if(s=n.apply(e,o))if("function"==typeof s.next&&"function"==typeof s.throw)s=lt(s);else if("function"==typeof s.then&&!r(s,"_PSD"))throw new Dt.IncompatiblePromise("Incompatible Promise returned from transaction scope (read more at http://tinyurl.com/znyqjqc). Transaction scope: "+n.toString())}).uncaught(C).then(function(){return c&&e._resolve(),e._completion}).then(function(){return s}).catch(function(t){return e._reject(t),rt(t)})})}))}var o=arguments.length;if(o<2)throw new Dt.InvalidArgument("Too few arguments");for(var s=new Array(o-1);--o;)s[o-1]=arguments[o];n=s.pop();var a=function(t){return Ot.apply([],t)}(s),c=Xt.trans;c&&c.db===Ht&&-1===t.indexOf("!")||(c=null);var f=-1!==t.indexOf("?");t=t.replace("!","").replace("?","");try{var u=a.map(function(t){var e=t instanceof T?t.name:t;if("string"!=typeof e)throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return e});if("r"==t||t==Kt)t=Kt;else{if("rw"!=t&&t!=Gt)throw new Dt.InvalidArgument("Invalid transaction mode: "+t);t=Gt}if(c){if(c.mode===Kt&&t===Gt){if(!f)throw new Dt.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");c=null}c&&u.forEach(function(t){if(c&&-1===c.storeNames.indexOf(t)){if(!f)throw new Dt.SubTransaction("Table "+t+" not included in parent transaction.");c=null}})}}catch(t){return c?c._promise(null,function(e,n){n(t)}):rt(t,C)}return c?c._promise(t,i,"lock"):Ht._whenReady(i)},this.table=function(t){if(le&&Jt)return new q(t);if(!r(Bt,t))throw new Dt.InvalidTable("Table "+t+" does not exist");return Bt[t]},i(T.prototype,{_trans:function(t,e,n){var r=Xt.trans;return r&&r.db===Ht?r._promise(t,e,n):R(t,[this.name],e)},_idbstore:function(t,e,n){function r(t,n,r){e(t,n,r.idbtrans.objectStore(o),r)}if(le)return new F(e);var i=Xt.trans,o=this.name;return i&&i.db===Ht?i._promise(t,r,n):R(t,[this.name],r)},get:function(t,e){var n=this;return this._idbstore(Kt,function(e,r,i){le&&e(n.schema.instanceTemplate);var o=i.get(t);o.onerror=ft(r),o.onsuccess=Q(function(){e(n.hook.reading.fire(o.result))},r)}).then(e)},where:function(t){return new G(this,t)},count:function(t){return this.toCollection().count(t)},offset:function(t){return this.toCollection().offset(t)},limit:function(t){return this.toCollection().limit(t)},reverse:function(){return this.toCollection().reverse()},filter:function(t){return this.toCollection().and(t)},each:function(t){return this.toCollection().each(t)},toArray:function(t){return this.toCollection().toArray(t)},orderBy:function(t){return new this._collClass(new G(this,t))},toCollection:function(){return new this._collClass(new G(this))},mapToClass:function(t,e){this.schema.mappedClass=t;var n=Object.create(t.prototype);e&&st(n,e),this.schema.instanceTemplate=n;var i=function(e){if(!e)return e;var n=Object.create(t.prototype);for(var i in e)if(r(e,i))try{n[i]=e[i]}catch(t){}return n};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=i,this.hook("reading",i),t},defineClass:function(t){return this.mapToClass(it.defineClass(t),t)}}),s(q).from(T).extend({bulkDelete:function(t){return this.hook.deleting.fire===S?this._idbstore(Gt,function(e,n,r,i){e(z(r,i,t,!1,S))}):this.where(":id").anyOf(t).delete().then(function(){})},bulkPut:function(t,e){var n=this;return this._idbstore(Gt,function(r,i,o){if(!o.keyPath&&!n.schema.primKey.auto&&!e)throw new Dt.InvalidArgument("bulkPut() with non-inbound keys requires keys array in second argument");if(o.keyPath&&e)throw new Dt.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(e&&e.length!==t.length)throw new Dt.InvalidArgument("Arguments objects and keys must have the same length");if(0===t.length)return r();var s,a,c=function(t){0===f.length?r(t):i(new D(n.name+".bulkPut(): "+f.length+" of "+u+" operations failed",f))},f=[],u=t.length,h=n;if(n.hook.creating.fire===S&&n.hook.updating.fire===S){a=U(f);for(var d=0,p=t.length;d=0;--i){var o=b[i];(null==o||g[o])&&(n.push(t[i]),e&&r.push(o),null!=o&&(g[o]=null))}return n.reverse(),e&&r.reverse(),h.bulkAdd(n,r)}).then(function(t){var e=b[b.length-1];return null!=e?e:t}):h.bulkAdd(t)).then(c).catch(D,function(t){f=f.concat(t.failures),c()}).catch(i)}},"locked")},bulkAdd:function(t,e){var n=this,r=this.hook.creating.fire;return this._idbstore(Gt,function(i,o,s,a){function c(t){0===d.length?i(t):o(new D(n.name+".bulkAdd(): "+d.length+" of "+l+" operations failed",d))}if(!s.keyPath&&!n.schema.primKey.auto&&!e)throw new Dt.InvalidArgument("bulkAdd() with non-inbound keys requires keys array in second argument");if(s.keyPath&&e)throw new Dt.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(e&&e.length!==t.length)throw new Dt.InvalidArgument("Arguments objects and keys must have the same length");if(0===t.length)return i();var f,u,h,d=[],l=t.length;if(r!==S){var p,m=s.keyPath;u=U(d,null,!0),h=ct(null),b(function(){for(var n=0,i=t.length;n0&&!this._locked();){var t=this._blockedFuncs.shift();try{et(t[1],t[0])}catch(t){}}return this},_locked:function(){return this._reculock&&Xt.lockOwnerFor!==this},create:function(t){var e=this;if(h(!this.idbtrans),!t&&!Ft)switch(qt&&qt.name){case"DatabaseClosedError":throw new Dt.DatabaseClosed(qt);case"MissingAPIError":throw new Dt.MissingAPI(qt.message,qt);default:throw new Dt.OpenFailed(qt)}if(!this.active)throw new Dt.TransactionInactive;return h(null===this._completion._state),t=this.idbtrans=t||Ft.transaction(yt(this.storeNames),this.mode),t.onerror=Q(function(n){ht(n),e._reject(t.error)}),t.onabort=Q(function(t){ht(t),e.active&&e._reject(new Dt.Abort),e.active=!1,e.on("abort").fire(t)}),t.oncomplete=Q(function(){e.active=!1,e._resolve()}),this},_promise:function(t,e,n){var r=this,i=r._locked()?new F(function(i,o){r._blockedFuncs.push([function(){r._promise(t,e,n).then(i,o)},Xt])}):tt(function(){var i=r.active?new F(function(i,o){if(t===Gt&&r.mode!==Gt)throw new Dt.ReadOnly("Transaction is readonly");!r.idbtrans&&t&&r.create(),n&&r._lock(),e(i,o,r)}):rt(new Dt.TransactionInactive);return r.active&&n&&i.finally(function(){r._unlock()}),i});return i._lib=!0,i.uncaught(C)},abort:function(){this.active&&this._reject(new Dt.Abort),this.active=!1},tables:{get:j("Transaction.tables",function(){return l(this.storeNames,function(t){return[t,Bt[t]]})})},complete:j("Transaction.complete()",function(t){return this.on("complete",t)}),error:j("Transaction.error()",function(t){return this.on("error",t)}),table:j("Transaction.table()",function(t){if(-1===this.storeNames.indexOf(t))throw new Dt.InvalidTable("Table "+t+" not in transaction");return Bt[t]})}),i(G.prototype,function(){function t(t,e,n){var r=t instanceof G?new t._ctx.collClass(t):t;return r._ctx.error=n?new n(e):new TypeError(e),r}function e(t){return new t._ctx.collClass(t,function(){return Rt.only("")}).limit(0)}function n(t,e,n,r,i,o){for(var s=Math.min(t.length,r.length),a=-1,c=0;c=0?t.substr(0,a)+e[a]+n.substr(a+1):null;i(t[c],f)<0&&(a=c)}return se?-1:t===e?0:1};var e=i.map(function(t){return{lower:c(t),upper:a(t)}}).sort(function(t,e){return f(t.lower,e.lower)});u=e.map(function(t){return t.upper}),h=e.map(function(t){return t.lower}),d=t,l="next"===t?"":o}var a,c,f,u,h,d,l,p=i.length;if(!i.every(function(t){return"string"==typeof t}))return t(e,se);s("next");var b=new e._ctx.collClass(e,function(){return Rt.bound(u[0],h[p-1]+o)});b._ondirectionchange=function(t){s(t)};var y=0;return b._addAlgorithm(function(t,e,i){var o=t.key;if("string"!=typeof o)return!1;var s=c(o);if(r(s,h,y))return!0;for(var a=null,b=y;b0)&&(a=g)}return e(null!==a?function(){t.continue(a+l)}:i),!1}),b}return{between:function(n,r,i,o){i=!1!==i,o=!0===o;try{return X(n,r)>0||0===X(n,r)&&(i||o)&&(!i||!o)?e(this):new this._ctx.collClass(this,function(){return Rt.bound(n,r,!i,!o)})}catch(e){return t(this,oe)}},equals:function(t){return new this._ctx.collClass(this,function(){return Rt.only(t)})},above:function(t){return new this._ctx.collClass(this,function(){return Rt.lowerBound(t,!0)})},aboveOrEqual:function(t){return new this._ctx.collClass(this,function(){return Rt.lowerBound(t)})},below:function(t){return new this._ctx.collClass(this,function(){return Rt.upperBound(t,!0)})},belowOrEqual:function(t){return new this._ctx.collClass(this,function(){return Rt.upperBound(t)})},startsWith:function(e){return"string"!=typeof e?t(this,se):this.between(e,e+re,!0,!0)},startsWithIgnoreCase:function(t){return""===t?this.startsWith(t):r(this,function(t,e){return 0===t.indexOf(e[0])},[t],re)},equalsIgnoreCase:function(t){return r(this,function(t,e){return t===e[0]},[t],"")},anyOfIgnoreCase:function(){var t=w.apply(At,arguments);return 0===t.length?e(this):r(this,function(t,e){return-1!==e.indexOf(t)},t,"")},startsWithAnyOfIgnoreCase:function(){var t=w.apply(At,arguments);return 0===t.length?e(this):r(this,function(t,e){return e.some(function(e){return 0===t.indexOf(e)})},t,re)},anyOf:function(){var n=w.apply(At,arguments),r=Z;try{n.sort(r)}catch(e){return t(this,oe)}if(0===n.length)return e(this);var i=new this._ctx.collClass(this,function(){return Rt.bound(n[0],n[n.length-1])});i._ondirectionchange=function(t){r="next"===t?Z:nt,n.sort(r)};var o=0;return i._addAlgorithm(function(t,e,i){for(var s=t.key;r(s,n[o])>0;)if(++o===n.length)return e(i),!1;return 0===r(s,n[o])||(e(function(){t.continue(n[o])}),!1)}),i},notEqual:function(t){return this.inAnyRange([[-1/0,t],[t,ie]],{includeLowers:!1,includeUppers:!1})},noneOf:function(){var e=w.apply(At,arguments);if(0===e.length)return new this._ctx.collClass(this);try{e.sort(Z)}catch(e){return t(this,oe)}var n=e.reduce(function(t,e){return t?t.concat([[t[t.length-1][1],e]]):[[-1/0,e]]},null);return n.push([e[e.length-1],ie]),this.inAnyRange(n,{includeLowers:!1,includeUppers:!1})},inAnyRange:function(n,r){function i(t,e){for(var n=0,r=t.length;n0){i[0]=function(t,e){return X(t,e)<0?t:e}(i[0],e[0]),i[1]=function(t,e){return X(t,e)>0?t:e}(i[1],e[1]);break}}return n===r&&t.push(e),t}function o(t,e){return u(t[0],e[0])}var s=this._ctx;if(0===n.length)return e(this);if(!n.every(function(t){return void 0!==t[0]&&void 0!==t[1]&&Z(t[0],t[1])<=0}))return t(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",Dt.InvalidArgument);var a,c=!r||!1!==r.includeLowers,f=r&&!0===r.includeUppers,u=Z;try{(a=n.reduce(i,[])).sort(o)}catch(e){return t(this,oe)}var h=0,d=f?function(t){return Z(t,a[h][1])>0}:function(t){return Z(t,a[h][1])>=0},l=c?function(t){return nt(t,a[h][0])>0}:function(t){return nt(t,a[h][0])>=0},p=d,b=new s.collClass(this,function(){return Rt.bound(a[0][0],a[a.length-1][1],!c,!f)});return b._ondirectionchange=function(t){"next"===t?(p=d,u=Z):(p=l,u=nt),a.sort(o)},b._addAlgorithm(function(t,e,n){for(var r=t.key;p(r);)if(++h===a.length)return e(n),!1;return!!function(t){return!d(t)&&!l(t)}(r)||0!==X(r,a[h][1])&&0!==X(r,a[h][0])&&(e(function(){u===Z?t.continue(a[h][0]):t.continue(a[h][1])}),!1)}),b},startsWithAnyOf:function(){var n=w.apply(At,arguments);return n.every(function(t){return"string"==typeof t})?0===n.length?e(this):this.inAnyRange(n.map(function(t){return[t,t+re]})):t(this,"startsWithAnyOf() only works with strings")}}}),i(H.prototype,function(){function e(t,e){t.filter=ot(t.filter,e)}function n(t,e,n){var r=t.replayFilter;t.replayFilter=r?function(){return ot(r(),e())}:e,t.justLimit=n&&!r}function i(t,e){if(t.isPrimKey)return e;var n=t.table.schema.idxByName[t.index];if(!n)throw new Dt.Schema("KeyPath "+t.index+" on object store "+e.name+" is not indexed");return e.index(n.name)}function o(t,e){var n=i(t,e);return t.keysOnly&&"openKeyCursor"in n?n.openKeyCursor(t.range||null,t.dir+t.unique):n.openCursor(t.range||null,t.dir+t.unique)}function s(t,e,n,i,s){var a=t.replayFilter?ot(t.filter,t.replayFilter()):t.filter;t.or?function(){function c(){2==++h&&n()}function f(t,n,o){if(!a||a(n,o,c,i)){var s=n.primaryKey.toString();r(u,s)||(u[s]=!0,e(t,n,o))}}var u={},h=0;t.or._iterate(f,c,i,s),V(o(t,s),t.algorithm,f,c,i,!t.keysOnly&&t.valueMapper)}():V(o(t,s),ot(t.algorithm,a),e,n,i,!t.keysOnly&&t.valueMapper)}function a(t){return t.table.schema.instanceTemplate}return{_read:function(t,e){var n=this._ctx;return n.error?n.table._trans(null,function(t,e){e(n.error)}):n.table._idbstore(Kt,t).then(e)},_write:function(t){var e=this._ctx;return e.error?e.table._trans(null,function(t,n){n(e.error)}):e.table._idbstore(Gt,t,"locked")},_addAlgorithm:function(t){var e=this._ctx;e.algorithm=ot(e.algorithm,t)},_iterate:function(t,e,n,r){return s(this._ctx,t,e,n,r)},clone:function(e){var n=Object.create(this.constructor.prototype),r=Object.create(this._ctx);return e&&t(r,e),n._ctx=r,n},raw:function(){return this._ctx.valueMapper=null,this},each:function(t){var e=this._ctx;if(le){var n=a(e),r=e.table.schema.primKey.keyPath,i=y(n,e.index?e.table.schema.idxByName[e.index].keyPath:r),o=y(n,r);t(n,{key:i,primaryKey:o})}return this._read(function(n,r,i){s(e,t,n,r,i)})},count:function(t){if(le)return F.resolve(0).then(t);var e=this._ctx;if(Y(e,!0))return this._read(function(t,n,r){var o=i(e,r),s=e.range?o.count(e.range):o.count();s.onerror=ft(n),s.onsuccess=function(n){t(Math.min(n.target.result,e.limit))}},t);var n=0;return this._read(function(t,r,i){s(e,function(){return++n,!1},function(){t(n)},r,i)},t)},sortBy:function(t,e){function n(t,e){return e?n(t[i[e]],e-1):t[o]}function r(t,e){var r=n(t,s),i=n(e,s);return ri?a:0}var i=t.split(".").reverse(),o=i[0],s=i.length-1,a="next"===this._ctx.dir?1:-1;return this.toArray(function(t){return t.sort(r)}).then(e)},toArray:function(t){var e=this._ctx;return this._read(function(t,n,r){if(le&&t([a(e)]),xt&&"next"===e.dir&&Y(e,!0)&&e.limit>0){var o=e.table.hook.reading.fire,c=i(e,r),f=e.limit<1/0?c.getAll(e.range,e.limit):c.getAll(e.range);f.onerror=ft(n),f.onsuccess=o===k?at(t):Q(at(function(e){try{t(e.map(o))}catch(t){n(t)}}))}else{var u=[];s(e,function(t){u.push(t)},function(){t(u)},n,r)}},t)},offset:function(t){var e=this._ctx;return t<=0?this:(e.offset+=t,Y(e)?n(e,function(){var e=t;return function(t,n){return 0===e||(1===e?(--e,!1):(n(function(){t.advance(e),e=0}),!1))}}):n(e,function(){var e=t;return function(){return--e<0}}),this)},limit:function(t){return this._ctx.limit=Math.min(this._ctx.limit,t),n(this._ctx,function(){var e=t;return function(t,n,r){return--e<=0&&n(r),e>=0}},!0),this},until:function(t,n){var r=this._ctx;return le&&t(a(r)),e(this._ctx,function(e,r,i){return!t(e.value)||(r(i),n)}),this},first:function(t){return this.limit(1).toArray(function(t){return t[0]}).then(t)},last:function(t){return this.reverse().first(t)},filter:function(t){return le&&t(a(this._ctx)),e(this._ctx,function(e){return t(e.value)}),function(t,e){t.isMatch=ot(t.isMatch,e)}(this._ctx,t),this},and:function(t){return this.filter(t)},or:function(t){return new G(this._ctx.table,t,this)},reverse:function(){return this._ctx.dir="prev"===this._ctx.dir?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},desc:function(){return this.reverse()},eachKey:function(t){var e=this._ctx;return e.keysOnly=!e.isMatch,this.each(function(e,n){t(n.key,n)})},eachUniqueKey:function(t){return this._ctx.unique="unique",this.eachKey(t)},eachPrimaryKey:function(t){var e=this._ctx;return e.keysOnly=!e.isMatch,this.each(function(e,n){t(n.primaryKey,n)})},keys:function(t){var e=this._ctx;e.keysOnly=!e.isMatch;var n=[];return this.each(function(t,e){n.push(e.key)}).then(function(){return n}).then(t)},primaryKeys:function(t){var e=this._ctx;if(xt&&"next"===e.dir&&Y(e,!0)&&e.limit>0)return this._read(function(t,n,r){var o=i(e,r),s=e.limit<1/0?o.getAllKeys(e.range,e.limit):o.getAllKeys(e.range);s.onerror=ft(n),s.onsuccess=at(t)}).then(t);e.keysOnly=!e.isMatch;var n=[];return this.each(function(t,e){n.push(e.primaryKey)}).then(function(){return n}).then(t)},uniqueKeys:function(t){return this._ctx.unique="unique",this.keys(t)},firstKey:function(t){return this.limit(1).keys(function(t){return t[0]}).then(t)},lastKey:function(t){return this.reverse().firstKey(t)},distinct:function(){var t=this._ctx,n=t.index&&t.table.schema.idxByName[t.index];if(!n||!n.multi)return this;var i={};return e(this._ctx,function(t){var e=t.primaryKey.toString(),n=r(i,e);return i[e]=!0,!n}),this}}}),s(W).from(H).extend({modify:function(e){var n=this,i=this._ctx,o=i.table.hook,s=o.updating.fire,a=o.deleting.fire;return le&&"function"==typeof e&&e.call({value:i.table.schema.instanceTemplate},i.table.schema.instanceTemplate),this._write(function(i,o,c,f){function u(t){return t&&(M.push(t),A.push(O)),o(new L("Error modifying one or more objects",M,x,A))}function h(){E&&x+M.length===k&&(M.length>0?u():i(x))}var d;if("function"==typeof e)d=s===S&&a===S?e:function(t){var n=v(t);if(!1===e.call(this,t,this))return!1;if(r(this,"value")){var i=_(n,this.value),o=s.call(this,i,this.primKey,n,f);o&&(t=this.value,mt(o).forEach(function(e){g(t,e,o[e])}))}else a.call(this,this.primKey,t,f)};else if(s===S){var l=mt(e),p=l.length;d=function(t){for(var n=!1,r=0;r0?console.warn("Another connection wants to upgrade database '"+Ht.name+"'. Closing db now to resume the upgrade."):console.warn("Another connection wants to delete database '"+Ht.name+"'. Closing db now to resume the delete request."),Ht.close()}),Ht.on("blocked",function(t){!t.newVersion||t.newVersion=t&&o()}}},function(t,e){return e})},i.sliding=function(t,e){e=e||10;var n=0;return i(function(r,i){var o,s=0;n++;return function(n,r){n||(o=t(o,r),e<=++s&&i(null,o))}})}},function(t,e){t.exports=function(t){return function e(n,r,i){var o=!0,s=!1;do{s=!0,o=!1,t.call(function(t,a,c){s?(n=t,r=a,i=c,o=!0):e(t,a,c)},n,r,i),s=!1}while(o)}}},function(t,e,n){(function(e){t.exports=function(){function t(t,e){return function(r){return function(){n(t,e),r&&r.apply(null,arguments)}}}function n(e,n){var r=a[e].indexOf(n);~r&&(a[e].splice(r,1),o(e)?s(function(){a[e][0](t(e,a[e][0]))}):delete a[e])}function r(t,e){return o(t)?(a[t].push(e),!1):(a[t]=[e],!0)}function i(e,i){if(Array.isArray(e)){var o=e.length,s={};function a(t){return function(){var e=[].slice.call(arguments);for(var r in s)n(r,s[r]);t.apply(this,e)}}e.forEach(function(t){function e(){n++||--o||i(a)}var n=0;s[t]=e,r(t,e)&&e()})}else r(e,i)&&i(t(e,i))}function o(t){return!!Array.isArray(a[t])&&!!a[t].length}var s=void 0===e?setTimeout:e,a={};return i.isLocked=o,i}}).call(e,n(20).setImmediate)},function(t,e,n){(function(e){function r(t,n,a,c){"function"==typeof n?(a=n,n={}):n&&"object"==typeof n||(n={mode:n});var f=n.mode,u=n.fs||o;void 0===f&&(f=s&~e.umask()),c||(c=null);var h=a||function(){};t=i.resolve(t),u.mkdir(t,f,function(e){if(!e)return c=c||t,h(null,c);switch(e.code){case"ENOENT":r(i.dirname(t),n,function(e,i){e?h(e,i):r(t,n,h,i)});break;default:u.stat(t,function(t,n){t||!n.isDirectory()?h(e,c):h(null,c)})}})}var i=n(11),o=n(16),s=parseInt("0777",8);t.exports=r.mkdirp=r.mkdirP=r,r.sync=function t(n,r,a){r&&"object"==typeof r||(r={mode:r});var c=r.mode,f=r.fs||o;void 0===c&&(c=s&~e.umask()),a||(a=null),n=i.resolve(n);try{f.mkdirSync(n,c),a=a||n}catch(e){switch(e.code){case"ENOENT":t(n,r,a=t(i.dirname(n),r,a));break;default:var u;try{u=f.statSync(n)}catch(t){throw e}if(!u.isDirectory())throw e}}return a}}).call(e,n(1))},function(t,e){t.exports={_from:"elliptic@^6.4.0",_id:"elliptic@6.4.0",_inBundle:!1,_integrity:"sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=",_location:"/elliptic",_phantomChildren:{},_requested:{type:"range",registry:!0,raw:"elliptic@^6.4.0",name:"elliptic",escapedName:"elliptic",rawSpec:"^6.4.0",saveSpec:null,fetchSpec:"^6.4.0"},_requiredBy:["/browserify-sign","/create-ecdh","/orbit-db-keystore","/secp256k1"],_resolved:"https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz",_shasum:"cac9af8762c85836187003c8dfe193e5e2eae5df",_spec:"elliptic@^6.4.0",_where:"/Users/samuli/code/orbit-db/node_modules/orbit-db-keystore",author:{name:"Fedor Indutny",email:"fedor@indutny.com"},bugs:{url:"https://github.com/indutny/elliptic/issues"},bundleDependencies:!1,dependencies:{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"},deprecated:!1,description:"EC cryptography",devDependencies:{brfs:"^1.4.3",coveralls:"^2.11.3",grunt:"^0.4.5","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^8.6.2",istanbul:"^0.4.2",jscs:"^2.9.0",jshint:"^2.6.0",mocha:"^2.1.0"},files:["lib"],homepage:"https://github.com/indutny/elliptic",keywords:["EC","Elliptic","curve","Cryptography"],license:"MIT",main:"lib/elliptic.js",name:"elliptic",repository:{type:"git",url:"git+ssh://git@github.com/indutny/elliptic.git"},scripts:{jscs:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",jshint:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",lint:"npm run jscs && npm run jshint",test:"npm run lint && npm run unit",unit:"istanbul test _mocha --reporter=spec test/index.js",version:"grunt dist && git add dist/"},version:"6.4.0"}},function(t,e,n){"use strict";var r=e,i=n(7),o=n(9),s=n(51);r.assert=o,r.toArray=s.toArray,r.zero2=s.zero2,r.toHex=s.toHex,r.encode=s.encode,r.getNAF=function(t,e){for(var n=[],r=1<=0;){var o;if(i.isOdd()){var s=i.andln(r-1);o=s>(r>>1)-1?(r>>1)-s:s,i.isubn(o)}else o=0;n.push(o);for(var a=0!==i.cmpn(0)&&0===i.andln(r-1)?e+1:1,c=1;c0||e.cmpn(-i)>0;){var o=t.andln(3)+r&3,s=e.andln(3)+i&3;3===o&&(o=-1),3===s&&(s=-1);var a;a=0==(1&o)?0:3!=(f=t.andln(7)+r&7)&&5!==f||2!==s?o:-o,n[0].push(a);var c;if(0==(1&s))c=0;else{var f=e.andln(7)+i&7;c=3!==f&&5!==f||2!==o?s:-s}n[1].push(c),2*r===a+1&&(r=1-r),2*i===c+1&&(i=1-i),t.iushrn(1),e.iushrn(1)}return n},r.cachedProperty=function(t,e,n){var r="_"+e;t.prototype[e]=function(){return void 0!==this[r]?this[r]:this[r]=n.call(this)}},r.parseBytes=function(t){return"string"==typeof t?r.toArray(t,"hex"):t},r.intFromLE=function(t){return new i(t,"hex","le")}},function(t,e){},function(t,e,n){function r(t){this.rand=t}var i;if(t.exports=function(t){return i||(i=new r(null)),i.generate(t)},t.exports.Rand=r,r.prototype.generate=function(t){return this._rand(t)},r.prototype._rand=function(t){if(this.rand.getBytes)return this.rand.getBytes(t);for(var e=new Uint8Array(t),n=0;n0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function i(t,e){this.curve=t,this.type=e,this.precomputed=null}var o=n(7),s=n(2).utils,a=s.getNAF,c=s.getJSF,f=s.assert;t.exports=r,r.prototype.point=function(){throw new Error("Not implemented")},r.prototype.validate=function(){throw new Error("Not implemented")},r.prototype._fixedNafMul=function(t,e){f(t.precomputed);var n=t._getDoubles(),r=a(e,1),i=(1<=s;e--)c=(c<<1)+r[e];o.push(c)}for(var u=this.jpoint(null,null,null),h=this.jpoint(null,null,null),d=i;d>0;d--){for(s=0;s=0;c--){for(e=0;c>=0&&0===o[c];c--)e++;if(c>=0&&e++,s=s.dblp(e),c<0)break;var u=o[c];f(0!==u),s="affine"===t.type?u>0?s.mixedAdd(i[u-1>>1]):s.mixedAdd(i[-u-1>>1].neg()):u>0?s.add(i[u-1>>1]):s.add(i[-u-1>>1].neg())}return"affine"===t.type?s.toP():s},r.prototype._wnafMulAdd=function(t,e,n,r,i){for(var o=this._wnafT1,s=this._wnafT2,f=this._wnafT3,u=0,h=0;h=1;h-=2){var l=h-1,p=h;if(1===o[l]&&1===o[p]){var b=[e[l],null,null,e[p]];0===e[l].y.cmp(e[p].y)?(b[1]=e[l].add(e[p]),b[2]=e[l].toJ().mixedAdd(e[p].neg())):0===e[l].y.cmp(e[p].y.redNeg())?(b[1]=e[l].toJ().mixedAdd(e[p]),b[2]=e[l].add(e[p].neg())):(b[1]=e[l].toJ().mixedAdd(e[p]),b[2]=e[l].toJ().mixedAdd(e[p].neg()));var y=[-3,-1,-5,-7,0,7,5,1,3],g=c(n[l],n[p]);u=Math.max(g[0].length,u),f[l]=new Array(u),f[p]=new Array(u);for(x=0;x=0;h--){for(var S=0;h>=0;){for(var k=!0,x=0;x=0&&S++,_=_.dblp(S),h<0)break;for(x=0;x0?E=s[x][M-1>>1]:M<0&&(E=s[x][-M-1>>1].neg()),_="affine"===E.type?_.mixedAdd(E):_.add(E))}}for(h=0;h=Math.ceil((t.bitLength()+1)/e.step)},i.prototype._getDoubles=function(t,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var n=[this],r=this,i=0;i=0&&(o=e,s=n),r.negative&&(r=r.neg(),i=i.neg()),o.negative&&(o=o.neg(),s=s.neg()),[{a:r,b:i},{a:o,b:s}]},r.prototype._endoSplit=function(t){var e=this.endo.basis,n=e[0],r=e[1],i=r.b.mul(t).divRound(this.n),o=n.b.neg().mul(t).divRound(this.n),s=i.mul(n.a),a=o.mul(r.a),c=i.mul(n.b),f=o.mul(r.b);return{k1:t.sub(s).sub(a),k2:c.add(f).neg()}},r.prototype.pointFromX=function(t,e){(t=new c(t,16)).red||(t=t.toRed(this.red));var n=t.redSqr().redMul(t).redIAdd(t.redMul(this.a)).redIAdd(this.b),r=n.redSqrt();if(0!==r.redSqr().redSub(n).cmp(this.zero))throw new Error("invalid point");var i=r.fromRed().isOdd();return(e&&!i||!e&&i)&&(r=r.redNeg()),this.point(t,r)},r.prototype.validate=function(t){if(t.inf)return!0;var e=t.x,n=t.y,r=this.a.redMul(e),i=e.redSqr().redMul(e).redIAdd(r).redIAdd(this.b);return 0===n.redSqr().redISub(i).cmpn(0)},r.prototype._endoWnafMulAdd=function(t,e,n){for(var r=this._endoWnafT1,i=this._endoWnafT2,o=0;o":""},i.prototype.isInfinity=function(){return this.inf},i.prototype.add=function(t){if(this.inf)return t;if(t.inf)return this;if(this.eq(t))return this.dbl();if(this.neg().eq(t))return this.curve.point(null,null);if(0===this.x.cmp(t.x))return this.curve.point(null,null);var e=this.y.redSub(t.y);0!==e.cmpn(0)&&(e=e.redMul(this.x.redSub(t.x).redInvm()));var n=e.redSqr().redISub(this.x).redISub(t.x),r=e.redMul(this.x.redSub(n)).redISub(this.y);return this.curve.point(n,r)},i.prototype.dbl=function(){if(this.inf)return this;var t=this.y.redAdd(this.y);if(0===t.cmpn(0))return this.curve.point(null,null);var e=this.curve.a,n=this.x.redSqr(),r=t.redInvm(),i=n.redAdd(n).redIAdd(n).redIAdd(e).redMul(r),o=i.redSqr().redISub(this.x.redAdd(this.x)),s=i.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,s)},i.prototype.getX=function(){return this.x.fromRed()},i.prototype.getY=function(){return this.y.fromRed()},i.prototype.mul=function(t){return t=new c(t,16),this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve.endo?this.curve._endoWnafMulAdd([this],[t]):this.curve._wnafMul(this,t)},i.prototype.mulAdd=function(t,e,n){var r=[this,e],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(r,i):this.curve._wnafMulAdd(1,r,i,2)},i.prototype.jmulAdd=function(t,e,n){var r=[this,e],i=[t,n];return this.curve.endo?this.curve._endoWnafMulAdd(r,i,!0):this.curve._wnafMulAdd(1,r,i,2,!0)},i.prototype.eq=function(t){return this===t||this.inf===t.inf&&(this.inf||0===this.x.cmp(t.x)&&0===this.y.cmp(t.y))},i.prototype.neg=function(t){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(t&&this.precomputed){var n=this.precomputed,r=function(t){return t.neg()};e.precomputed={naf:n.naf&&{wnd:n.naf.wnd,points:n.naf.points.map(r)},doubles:n.doubles&&{step:n.doubles.step,points:n.doubles.points.map(r)}}}return e},i.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);return this.curve.jpoint(this.x,this.y,this.curve.one)},f(o,u.BasePoint),r.prototype.jpoint=function(t,e,n){return new o(this,t,e,n)},o.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var t=this.z.redInvm(),e=t.redSqr(),n=this.x.redMul(e),r=this.y.redMul(e).redMul(t);return this.curve.point(n,r)},o.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},o.prototype.add=function(t){if(this.isInfinity())return t;if(t.isInfinity())return this;var e=t.z.redSqr(),n=this.z.redSqr(),r=this.x.redMul(e),i=t.x.redMul(n),o=this.y.redMul(e.redMul(t.z)),s=t.y.redMul(n.redMul(this.z)),a=r.redSub(i),c=o.redSub(s);if(0===a.cmpn(0))return 0!==c.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var f=a.redSqr(),u=f.redMul(a),h=r.redMul(f),d=c.redSqr().redIAdd(u).redISub(h).redISub(h),l=c.redMul(h.redISub(d)).redISub(o.redMul(u)),p=this.z.redMul(t.z).redMul(a);return this.curve.jpoint(d,l,p)},o.prototype.mixedAdd=function(t){if(this.isInfinity())return t.toJ();if(t.isInfinity())return this;var e=this.z.redSqr(),n=this.x,r=t.x.redMul(e),i=this.y,o=t.y.redMul(e).redMul(this.z),s=n.redSub(r),a=i.redSub(o);if(0===s.cmpn(0))return 0!==a.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=s.redSqr(),f=c.redMul(s),u=n.redMul(c),h=a.redSqr().redIAdd(f).redISub(u).redISub(u),d=a.redMul(u.redISub(h)).redISub(i.redMul(f)),l=this.z.redMul(s);return this.curve.jpoint(h,d,l)},o.prototype.dblp=function(t){if(0===t)return this;if(this.isInfinity())return this;if(!t)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var e=this,n=0;n=0)return!1;if(n.redIAdd(i),0===this.x.cmp(n))return!0}return!1},o.prototype.inspect=function(){return this.isInfinity()?"":""},o.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},function(t,e,n){"use strict";function r(t){c.call(this,"mont",t),this.a=new s(t.a,16).toRed(this.red),this.b=new s(t.b,16).toRed(this.red),this.i4=new s(4).toRed(this.red).redInvm(),this.two=new s(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}function i(t,e,n){c.BasePoint.call(this,t,"projective"),null===e&&null===n?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new s(e,16),this.z=new s(n,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}var o=n(23),s=n(7),a=n(5),c=o.base,f=n(2).utils;a(r,c),t.exports=r,r.prototype.validate=function(t){var e=t.normalize().x,n=e.redSqr(),r=n.redMul(e).redAdd(n.redMul(this.a)).redAdd(e);return 0===r.redSqrt().redSqr().cmp(r)},a(i,c.BasePoint),r.prototype.decodePoint=function(t,e){return this.point(f.toArray(t,e),1)},r.prototype.point=function(t,e){return new i(this,t,e)},r.prototype.pointFromJSON=function(t){return i.fromJSON(this,t)},i.prototype.precompute=function(){},i.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},i.fromJSON=function(t,e){return new i(t,e[0],e[1]||t.one)},i.prototype.inspect=function(){return this.isInfinity()?"":""},i.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},i.prototype.dbl=function(){var t=this.x.redAdd(this.z).redSqr(),e=this.x.redSub(this.z).redSqr(),n=t.redSub(e),r=t.redMul(e),i=n.redMul(e.redAdd(this.curve.a24.redMul(n)));return this.curve.point(r,i)},i.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.diffAdd=function(t,e){var n=this.x.redAdd(this.z),r=this.x.redSub(this.z),i=t.x.redAdd(t.z),o=t.x.redSub(t.z).redMul(n),s=i.redMul(r),a=e.z.redMul(o.redAdd(s).redSqr()),c=e.x.redMul(o.redISub(s).redSqr());return this.curve.point(a,c)},i.prototype.mul=function(t){for(var e=t.clone(),n=this,r=this.curve.point(null,null),i=this,o=[];0!==e.cmpn(0);e.iushrn(1))o.push(e.andln(1));for(var s=o.length-1;s>=0;s--)0===o[s]?(n=n.diffAdd(r,i),r=r.dbl()):(r=n.diffAdd(r,i),n=n.dbl());return r},i.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.eq=function(t){return 0===this.getX().cmp(t.getX())},i.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},i.prototype.getX=function(){return this.normalize(),this.x.fromRed()}},function(t,e,n){"use strict";function r(t){this.twisted=1!=(0|t.a),this.mOneA=this.twisted&&-1==(0|t.a),this.extended=this.mOneA,f.call(this,"edwards",t),this.a=new a(t.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new a(t.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new a(t.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),u(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|t.c)}function i(t,e,n,r,i){f.BasePoint.call(this,t,"projective"),null===e&&null===n&&null===r?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new a(e,16),this.y=new a(n,16),this.z=r?new a(r,16):this.curve.one,this.t=i&&new a(i,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}var o=n(23),s=n(2),a=n(7),c=n(5),f=o.base,u=s.utils.assert;c(r,f),t.exports=r,r.prototype._mulA=function(t){return this.mOneA?t.redNeg():this.a.redMul(t)},r.prototype._mulC=function(t){return this.oneC?t:this.c.redMul(t)},r.prototype.jpoint=function(t,e,n,r){return this.point(t,e,n,r)},r.prototype.pointFromX=function(t,e){(t=new a(t,16)).red||(t=t.toRed(this.red));var n=t.redSqr(),r=this.c2.redSub(this.a.redMul(n)),i=this.one.redSub(this.c2.redMul(this.d).redMul(n)),o=r.redMul(i.redInvm()),s=o.redSqrt();if(0!==s.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");var c=s.fromRed().isOdd();return(e&&!c||!e&&c)&&(s=s.redNeg()),this.point(t,s)},r.prototype.pointFromY=function(t,e){(t=new a(t,16)).red||(t=t.toRed(this.red));var n=t.redSqr(),r=n.redSub(this.one),i=n.redMul(this.d).redAdd(this.one),o=r.redMul(i.redInvm());if(0===o.cmp(this.zero)){if(e)throw new Error("invalid point");return this.point(this.zero,t)}var s=o.redSqrt();if(0!==s.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");return s.isOdd()!==e&&(s=s.redNeg()),this.point(s,t)},r.prototype.validate=function(t){if(t.isInfinity())return!0;t.normalize();var e=t.x.redSqr(),n=t.y.redSqr(),r=e.redMul(this.a).redAdd(n),i=this.c2.redMul(this.one.redAdd(this.d.redMul(e).redMul(n)));return 0===r.cmp(i)},c(i,f.BasePoint),r.prototype.pointFromJSON=function(t){return i.fromJSON(this,t)},r.prototype.point=function(t,e,n,r){return new i(this,t,e,n,r)},i.fromJSON=function(t,e){return new i(t,e[0],e[1],e[2])},i.prototype.inspect=function(){return this.isInfinity()?"":""},i.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&0===this.y.cmp(this.z)},i.prototype._extDbl=function(){var t=this.x.redSqr(),e=this.y.redSqr(),n=this.z.redSqr();n=n.redIAdd(n);var r=this.curve._mulA(t),i=this.x.redAdd(this.y).redSqr().redISub(t).redISub(e),o=r.redAdd(e),s=o.redSub(n),a=r.redSub(e),c=i.redMul(s),f=o.redMul(a),u=i.redMul(a),h=s.redMul(o);return this.curve.point(c,f,h,u)},i.prototype._projDbl=function(){var t,e,n,r=this.x.redAdd(this.y).redSqr(),i=this.x.redSqr(),o=this.y.redSqr();if(this.curve.twisted){var s=(f=this.curve._mulA(i)).redAdd(o);if(this.zOne)t=r.redSub(i).redSub(o).redMul(s.redSub(this.curve.two)),e=s.redMul(f.redSub(o)),n=s.redSqr().redSub(s).redSub(s);else{var a=this.z.redSqr(),c=s.redSub(a).redISub(a);t=r.redSub(i).redISub(o).redMul(c),e=s.redMul(f.redSub(o)),n=s.redMul(c)}}else{var f=i.redAdd(o),a=this.curve._mulC(this.c.redMul(this.z)).redSqr(),c=f.redSub(a).redSub(a);t=this.curve._mulC(r.redISub(f)).redMul(c),e=this.curve._mulC(f).redMul(i.redISub(o)),n=f.redMul(c)}return this.curve.point(t,e,n)},i.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},i.prototype._extAdd=function(t){var e=this.y.redSub(this.x).redMul(t.y.redSub(t.x)),n=this.y.redAdd(this.x).redMul(t.y.redAdd(t.x)),r=this.t.redMul(this.curve.dd).redMul(t.t),i=this.z.redMul(t.z.redAdd(t.z)),o=n.redSub(e),s=i.redSub(r),a=i.redAdd(r),c=n.redAdd(e),f=o.redMul(s),u=a.redMul(c),h=o.redMul(c),d=s.redMul(a);return this.curve.point(f,u,d,h)},i.prototype._projAdd=function(t){var e,n,r=this.z.redMul(t.z),i=r.redSqr(),o=this.x.redMul(t.x),s=this.y.redMul(t.y),a=this.curve.d.redMul(o).redMul(s),c=i.redSub(a),f=i.redAdd(a),u=this.x.redAdd(this.y).redMul(t.x.redAdd(t.y)).redISub(o).redISub(s),h=r.redMul(c).redMul(u);return this.curve.twisted?(e=r.redMul(f).redMul(s.redSub(this.curve._mulA(o))),n=c.redMul(f)):(e=r.redMul(f).redMul(s.redSub(o)),n=this.curve._mulC(c).redMul(f)),this.curve.point(h,e,n)},i.prototype.add=function(t){return this.isInfinity()?t:t.isInfinity()?this:this.curve.extended?this._extAdd(t):this._projAdd(t)},i.prototype.mul=function(t){return this._hasDoubles(t)?this.curve._fixedNafMul(this,t):this.curve._wnafMul(this,t)},i.prototype.mulAdd=function(t,e,n){return this.curve._wnafMulAdd(1,[this,e],[t,n],2,!1)},i.prototype.jmulAdd=function(t,e,n){return this.curve._wnafMulAdd(1,[this,e],[t,n],2,!0)},i.prototype.normalize=function(){if(this.zOne)return this;var t=this.z.redInvm();return this.x=this.x.redMul(t),this.y=this.y.redMul(t),this.t&&(this.t=this.t.redMul(t)),this.z=this.curve.one,this.zOne=!0,this},i.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},i.prototype.getX=function(){return this.normalize(),this.x.fromRed()},i.prototype.getY=function(){return this.normalize(),this.y.fromRed()},i.prototype.eq=function(t){return this===t||0===this.getX().cmp(t.getX())&&0===this.getY().cmp(t.getY())},i.prototype.eqXToP=function(t){var e=t.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(e))return!0;for(var n=t.clone(),r=this.curve.redN.redMul(this.z);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(e.redIAdd(r),0===this.x.cmp(e))return!0}return!1},i.prototype.toP=i.prototype.normalize,i.prototype.mixedAdd=i.prototype.add},function(t,e,n){"use strict";function r(t){"short"===t.type?this.curve=new a.curve.short(t):"edwards"===t.type?this.curve=new a.curve.edwards(t):this.curve=new a.curve.mont(t),this.g=this.curve.g,this.n=this.curve.n,this.hash=t.hash,c(this.g.validate(),"Invalid curve"),c(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function i(t,e){Object.defineProperty(o,t,{configurable:!0,enumerable:!0,get:function(){var n=new r(e);return Object.defineProperty(o,t,{configurable:!0,enumerable:!0,value:n}),n}})}var o=e,s=n(32),a=n(2),c=a.utils.assert;o.PresetCurve=r,i("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:s.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),i("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:s.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),i("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:s.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),i("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:s.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),i("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:s.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),i("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:s.sha256,gRed:!1,g:["9"]}),i("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:s.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var f;try{f=n(125)}catch(t){f=void 0}i("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:s.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",f]})},function(t,e,n){"use strict";e.sha1=n(120),e.sha224=n(121),e.sha256=n(53),e.sha384=n(122),e.sha512=n(54)},function(t,e,n){"use strict";function r(){if(!(this instanceof r))return new r;h.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}var i=n(6),o=n(17),s=n(52),a=i.rotl32,c=i.sum32,f=i.sum32_5,u=s.ft_1,h=o.BlockHash,d=[1518500249,1859775393,2400959708,3395469782];i.inherits(r,h),t.exports=r,r.blockSize=512,r.outSize=160,r.hmacStrength=80,r.padLength=64,r.prototype._update=function(t,e){for(var n=this.W,r=0;r<16;r++)n[r]=t[e+r];for(;rthis.blockSize&&(t=(new this.Hash).update(t).digest()),o(t.length<=this.blockSize);for(var e=t.length;e0))return a.iaddn(1),this.keyFromPrivate(a)}},r.prototype._truncateToN=function(t,e){var n=8*t.byteLength()-this.n.bitLength();return n>0&&(t=t.ushrn(n)),!e&&t.cmp(this.n)>=0?t.sub(this.n):t},r.prototype.sign=function(t,e,n,r){"object"==typeof n&&(r=n,n=null),r||(r={}),e=this.keyFromPrivate(e,n),t=this._truncateToN(new i(t,16));for(var s=this.n.byteLength(),a=e.getPrivate().toArray("be",s),c=t.toArray("be",s),u=new o({hash:this.hash,entropy:a,nonce:c,pers:r.pers,persEnc:r.persEnc||"utf8"}),h=this.n.sub(new i(1)),d=0;!0;d++){var l=r.k?r.k(d):new i(u.generate(this.n.byteLength()));if(!((l=this._truncateToN(l,!0)).cmpn(1)<=0||l.cmp(h)>=0)){var p=this.g.mul(l);if(!p.isInfinity()){var b=p.getX(),y=b.umod(this.n);if(0!==y.cmpn(0)){var g=l.invm(this.n).mul(y.mul(e.getPrivate()).iadd(t));if(0!==(g=g.umod(this.n)).cmpn(0)){var m=(p.getY().isOdd()?1:0)|(0!==b.cmp(y)?2:0);return r.canonical&&g.cmp(this.nh)>0&&(g=this.n.sub(g),m^=1),new f({r:y,s:g,recoveryParam:m})}}}}}},r.prototype.verify=function(t,e,n,r){t=this._truncateToN(new i(t,16)),n=this.keyFromPublic(n,r);var o=(e=new f(e,"hex")).r,s=e.s;if(o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return!1;var a=s.invm(this.n),c=a.mul(t).umod(this.n),u=a.mul(o).umod(this.n);if(!this.curve._maxwellTrick){return!(h=this.g.mulAdd(c,n.getPublic(),u)).isInfinity()&&0===h.getX().umod(this.n).cmp(o)}var h=this.g.jmulAdd(c,n.getPublic(),u);return!h.isInfinity()&&h.eqXToP(o)},r.prototype.recoverPubKey=function(t,e,n,r){a((3&n)===n,"The recovery param is more than two bits"),e=new f(e,r);var o=this.n,s=new i(t),c=e.r,u=e.s,h=1&n,d=n>>1;if(c.cmp(this.curve.p.umod(this.curve.n))>=0&&d)throw new Error("Unable to find sencond key candinate");c=d?this.curve.pointFromX(c.add(this.curve.n),h):this.curve.pointFromX(c,h);var l=e.r.invm(o),p=o.sub(s).mul(l).umod(o),b=u.mul(l).umod(o);return this.g.mulAdd(p,c,b)},r.prototype.getKeyRecoveryParam=function(t,e,n,r){if(null!==(e=new f(e,r)).recoveryParam)return e.recoveryParam;for(var i=0;i<4;i++){var o;try{o=this.recoverPubKey(t,e,i)}catch(t){continue}if(o.eq(n))return i}throw new Error("Unable to find valid recovery factor")}},function(t,e,n){"use strict";function r(t){if(!(this instanceof r))return new r(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=o.toArray(t.entropy,t.entropyEnc||"hex"),n=o.toArray(t.nonce,t.nonceEnc||"hex"),i=o.toArray(t.pers,t.persEnc||"hex");s(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,n,i)}var i=n(32),o=n(51),s=n(9);t.exports=r,r.prototype._init=function(t,e,n){var r=t.concat(e).concat(n);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var i=0;i=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(n||[])),this._reseed=1},r.prototype.generate=function(t,e,n,r){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(r=n,n=e,e=null),n&&(n=o.toArray(n,r||"hex"),this._update(n));for(var i=[];i.length"}},function(t,e,n){"use strict";function r(t,e){if(t instanceof r)return t;this._importDER(t,e)||(f(t.r&&t.s,"Signature without r or s"),this.r=new a(t.r,16),this.s=new a(t.s,16),void 0===t.recoveryParam?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}function i(t,e){var n=t[e.place++];if(!(128&n))return n;for(var r=15&n,i=0,o=0,s=e.place;o>>3);for(t.push(128|n);--n;)t.push(e>>>(n<<3)&255);t.push(e)}}var a=n(7),c=n(2).utils,f=c.assert;t.exports=r,r.prototype._importDER=function(t,e){t=c.toArray(t,e);var n=new function(){this.place=0};if(48!==t[n.place++])return!1;if(i(t,n)+n.place!==t.length)return!1;if(2!==t[n.place++])return!1;var r=i(t,n),o=t.slice(n.place,r+n.place);if(n.place+=r,2!==t[n.place++])return!1;var s=i(t,n);if(t.length!==s+n.place)return!1;var f=t.slice(n.place,s+n.place);return 0===o[0]&&128&o[1]&&(o=o.slice(1)),0===f[0]&&128&f[1]&&(f=f.slice(1)),this.r=new a(o),this.s=new a(f),this.recoveryParam=null,!0},r.prototype.toDER=function(t){var e=this.r.toArray(),n=this.s.toArray();for(128&e[0]&&(e=[0].concat(e)),128&n[0]&&(n=[0].concat(n)),e=o(e),n=o(n);!(n[0]||128&n[1]);)n=n.slice(1);var r=[2];s(r,e.length),(r=r.concat(e)).push(2),s(r,n.length);var i=r.concat(n),a=[48];return s(a,i.length),a=a.concat(i),c.encode(a,t)}},function(t,e,n){"use strict";function r(t){if(a("ed25519"===t,"only tested with ed25519 so far"),!(this instanceof r))return new r(t);t=o.curves[t].curve;this.curve=t,this.g=t.g,this.g.precompute(t.n.bitLength()+1),this.pointClass=t.point().constructor,this.encodingLength=Math.ceil(t.n.bitLength()/8),this.hash=i.sha512}var i=n(32),o=n(2),s=o.utils,a=s.assert,c=s.parseBytes,f=n(131),u=n(132);t.exports=r,r.prototype.sign=function(t,e){t=c(t);var n=this.keyFromSecret(e),r=this.hashInt(n.messagePrefix(),t),i=this.g.mul(r),o=this.encodePoint(i),s=this.hashInt(o,n.pubBytes(),t).mul(n.priv()),a=r.add(s).umod(this.curve.n);return this.makeSignature({R:i,S:a,Rencoded:o})},r.prototype.verify=function(t,e,n){t=c(t),e=this.makeSignature(e);var r=this.keyFromPublic(n),i=this.hashInt(e.Rencoded(),r.pubBytes(),t),o=this.g.mul(e.S());return e.R().add(r.pub().mul(i)).eq(o)},r.prototype.hashInt=function(){for(var t=this.hash(),e=0;ethis.quota)throw new a;if(y(o,g,"utf8"),i||((h=new s(n,this._keys.push(t)-1)).size=m,this._metaKeyMap[t]=h,this.length+=1,this._bytesInUse+=m),f)return r=new c(t,p,e,this._eventUrl),this.emit("storage",r)},n.prototype.getItem=function(t){var e,n;return t=u(t),(n=this._metaKeyMap[t])?(e=b.join(this._location,n.key),p.readFileSync(e,"utf8")):null},n.prototype._getStat=function(t){var e;t=u(t),e=b.join(this._location,encodeURIComponent(t));try{return p.statSync(e)}catch(t){return null}},n.prototype.removeItem=function(t){var e,n,r,i,o,s,a,f;if(t=u(t),s=this._metaKeyMap[t]){a=null,(r=l.EventEmitter.listenerCount(this,"storage"))&&(a=this.getItem(t)),delete this._metaKeyMap[t],this.length-=1,this._bytesInUse-=s.size,n=b.join(this._location,s.key),this._keys.splice(s.index,1),f=this._metaKeyMap;for(i in f)f[i],(o=this._metaKeyMap[i]).index>s.index&&(o.index-=1);if(h(n),r)return e=new c(t,a,null,this._eventUrl),this.emit("storage",e)}},n.prototype.key=function(t){return this._keys[t]},n.prototype.clear=function(){var t;if(f(this._location),this._metaKeyMap=d(),this._keys=[],this.length=0,this._bytesInUse=0,l.EventEmitter.listenerCount(this,"storage"))return t=new c(null,null,null,this._eventUrl),this.emit("storage",t)},n.prototype._getBytesInUse=function(){return this._bytesInUse},n.prototype._deleteLocation=function(){return delete r[this._location],h(this._location),this._metaKeyMap={},this._keys=[],this.length=0,this._bytesInUse=0},n}(l.EventEmitter),r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return g(e,o),e.prototype.setItem=function(t,n){var r;return r=JSON.stringify(n),e.__super__.setItem.call(this,t,r)},e.prototype.getItem=function(t){return JSON.parse(e.__super__.getItem.call(this,t))},e}(),e.LocalStorage=o,e.JSONStorage=r,e.QUOTA_EXCEEDED_ERR=a}).call(this)}).call(e,n(1))},function(t,e,n){"use strict";(function(e,r,i){function o(t){return t+"."+c(e).hash(String(r.pid)).hash(String(++u)).result()}t.exports=function(t,e,n,c){n instanceof Function&&(c=n,n=null),n||(n={}),s.realpath(t,function(u,h){!function(t,e,n,c){function u(){a([[h,d,e,n.mode,n.encoding||"utf8"],n.chown&&[s,s.chown,d,n.chown.uid,n.chown.gid],n.mode&&[s,s.chmod,d,n.mode],[s,s.rename,d,t]],function(t){t?s.unlink(d,function(){c(t)}):c()})}function h(t,e,r,o,a){s.open(t,"w",n.mode,function(t,n){function r(t){if(t)return a(t);s.fsync(n,function(t){if(t)return a(t);s.close(n,a)})}return t?a(t):i.isBuffer(e)?s.write(n,e,0,e.length,0,r):null!=e?s.write(n,String(e),0,String(o),r):r()})}var d=o(t);n.mode&&n.chown?u():s.stat(t,function(t,e){return t||!e?u():((n=f({},n)).mode||(n.mode=e.mode),!n.chown&&r.getuid&&(n.chown={uid:e.uid,gid:e.gid}),u())})}(h||t,e,n,c)})},t.exports.sync=function(t,e,n){n||(n={});try{t=s.realpathSync(t)}catch(t){}var a=o(t);try{if(!n.mode||!n.chown)try{var c=s.statSync(t);(n=f({},n)).mode||(n.mode=c.mode),!n.chown&&r.getuid&&(n.chown={uid:c.uid,gid:c.gid})}catch(t){}var u=s.openSync(a,"w",n.mode);i.isBuffer(e)?s.writeSync(u,e,0,e.length,0):null!=e&&s.writeSync(u,String(e),0,String(n.encoding||"utf8")),s.fsyncSync(u),s.closeSync(u),n.chown&&s.chownSync(a,n.chown.uid,n.chown.gid),n.mode&&s.chmodSync(a,n.mode),s.renameSync(a,t)}catch(t){try{s.unlinkSync(a)}catch(t){}throw t}},t.exports._getTmpname=o;var s=n(135),a=n(147).chain,c=n(150),f=Object.assign||n(24)._extend,u=0}).call(e,"/index.js",n(1),n(0).Buffer)},function(t,e,n){(function(e){function r(t){function n(e){return p.apply(t,e)}function s(t,e){return this instanceof s?(y.apply(this,arguments),this):s.apply(Object.create(s.prototype),arguments)}function f(t,e){return this instanceof f?(g.apply(this,arguments),this):f.apply(Object.create(f.prototype),arguments)}function u(t,e,n,r){function s(t,e,n,r){return m(t,e,n,function(a,c){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof r&&r.apply(this,arguments),o()):i([s,[t,e,n,r]])})}return"function"==typeof n&&(r=n,n=null),s(t,e,n,r)}a(t),t.gracefulify=r,t.FileReadStream=s,t.FileWriteStream=f,t.createReadStream=function(t,e){return new s(t,e)},t.createWriteStream=function(t,e){return new f(t,e)};var h=t.readFile;t.readFile=function(t,e,n){function r(t,e,n){return h(t,e,function(s){!s||"EMFILE"!==s.code&&"ENFILE"!==s.code?("function"==typeof n&&n.apply(this,arguments),o()):i([r,[t,e,n]])})}return"function"==typeof e&&(n=e,e=null),r(t,e,n)};var d=t.writeFile;t.writeFile=function(t,e,n,r){function s(t,e,n,r){return d(t,e,n,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof r&&r.apply(this,arguments),o()):i([s,[t,e,n,r]])})}return"function"==typeof n&&(r=n,n=null),s(t,e,n,r)};var l=t.appendFile;l&&(t.appendFile=function(t,e,n,r){function s(t,e,n,r){return l(t,e,n,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof r&&r.apply(this,arguments),o()):i([s,[t,e,n,r]])})}return"function"==typeof n&&(r=n,n=null),s(t,e,n,r)});var p=t.readdir;if(t.readdir=function(t,e,r){var s=[t];return"function"!=typeof e?s.push(e):r=e,s.push(function(t,e){e&&e.sort&&e.sort(),!t||"EMFILE"!==t.code&&"ENFILE"!==t.code?("function"==typeof r&&r.apply(this,arguments),o()):i([n,[s]])}),n(s)},"v0.8"===e.version.substr(0,4)){var b=c(t);s=b.ReadStream,f=b.WriteStream}var y=t.ReadStream;(s.prototype=Object.create(y.prototype)).open=function(){var t=this;u(t.path,t.flags,t.mode,function(e,n){e?(t.autoClose&&t.destroy(),t.emit("error",e)):(t.fd=n,t.emit("open",n),t.read())})};var g=t.WriteStream;(f.prototype=Object.create(g.prototype)).open=function(){var t=this;u(t.path,t.flags,t.mode,function(e,n){e?(t.destroy(),t.emit("error",e)):(t.fd=n,t.emit("open",n))})},t.ReadStream=s,t.WriteStream=f;var m=t.open;return t.open=u,t}function i(t){h("ENQUEUE",t[0].name,t[1]),f.push(t)}function o(){var t=f.shift();t&&(h("RETRY",t[0].name,t[1]),t[0].apply(null,t[1]))}var s=n(16),a=n(136),c=n(138),f=[],u=n(24),h=function(){};u.debuglog?h=u.debuglog("gfs4"):/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&(h=function(){var t=u.format.apply(u,arguments);t="GFS4: "+t.split(/\n/).join("\nGFS4: "),console.error(t)}),/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&e.on("exit",function(){h(f),n(146).equal(f.length,0)}),t.exports=r(n(55)),Object({NODE_ENV:void 0}).TEST_GRACEFUL_FS_GLOBAL_PATCH&&(t.exports=r(s)),t.exports.close=s.close=function(t){return function(e,n){return t.call(s,e,function(t){t||o(),"function"==typeof n&&n.apply(this,arguments)})}}(s.close),t.exports.closeSync=s.closeSync=function(t){return function(e){var n=t.apply(s,arguments);return o(),n}}(s.closeSync)}).call(e,n(1))},function(t,e,n){(function(e){function r(t){return t?function(e,n,r){return t.call(u,e,n,function(t){f(t)&&(t=null),r&&r.apply(this,arguments)})}:t}function i(t){return t?function(e,n){try{return t.call(u,e,n)}catch(t){if(!f(t))throw t}}:t}function o(t){return t?function(e,n,r,i){return t.call(u,e,n,r,function(t){f(t)&&(t=null),i&&i.apply(this,arguments)})}:t}function s(t){return t?function(e,n,r){try{return t.call(u,e,n,r)}catch(t){if(!f(t))throw t}}:t}function a(t){return t?function(e,n){return t.call(u,e,function(t,e){if(!e)return n.apply(this,arguments);e.uid<0&&(e.uid+=4294967296),e.gid<0&&(e.gid+=4294967296),n&&n.apply(this,arguments)})}:t}function c(t){return t?function(e){var n=t.call(u,e);return n.uid<0&&(n.uid+=4294967296),n.gid<0&&(n.gid+=4294967296),n}:t}function f(t){if(!t)return!0;if("ENOSYS"===t.code)return!0;return!(e.getuid&&0===e.getuid()||"EINVAL"!==t.code&&"EPERM"!==t.code)}var u=n(55),h=n(137),d=e.cwd,l=null,p=Object({NODE_ENV:void 0}).GRACEFUL_FS_PLATFORM||e.platform;e.cwd=function(){return l||(l=d.call(e)),l};try{e.cwd()}catch(t){}var b=e.chdir;e.chdir=function(t){l=null,b.call(e,t)},t.exports=function(t){h.hasOwnProperty("O_SYMLINK")&&e.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&function(t){t.lchmod=function(e,n,r){t.open(e,h.O_WRONLY|h.O_SYMLINK,n,function(e,i){e?r&&r(e):t.fchmod(i,n,function(e){t.close(i,function(t){r&&r(e||t)})})})},t.lchmodSync=function(e,n){var r,i=t.openSync(e,h.O_WRONLY|h.O_SYMLINK,n),o=!0;try{r=t.fchmodSync(i,n),o=!1}finally{if(o)try{t.closeSync(i)}catch(t){}else t.closeSync(i)}return r}}(t),t.lutimes||function(t){h.hasOwnProperty("O_SYMLINK")?(t.lutimes=function(e,n,r,i){t.open(e,h.O_SYMLINK,function(e,o){e?i&&i(e):t.futimes(o,n,r,function(e){t.close(o,function(t){i&&i(e||t)})})})},t.lutimesSync=function(e,n,r){var i,o=t.openSync(e,h.O_SYMLINK),s=!0;try{i=t.futimesSync(o,n,r),s=!1}finally{if(s)try{t.closeSync(o)}catch(t){}else t.closeSync(o)}return i}):(t.lutimes=function(t,n,r,i){i&&e.nextTick(i)},t.lutimesSync=function(){})}(t),t.chown=o(t.chown),t.fchown=o(t.fchown),t.lchown=o(t.lchown),t.chmod=r(t.chmod),t.fchmod=r(t.fchmod),t.lchmod=r(t.lchmod),t.chownSync=s(t.chownSync),t.fchownSync=s(t.fchownSync),t.lchownSync=s(t.lchownSync),t.chmodSync=i(t.chmodSync),t.fchmodSync=i(t.fchmodSync),t.lchmodSync=i(t.lchmodSync),t.stat=a(t.stat),t.fstat=a(t.fstat),t.lstat=a(t.lstat),t.statSync=c(t.statSync),t.fstatSync=c(t.fstatSync),t.lstatSync=c(t.lstatSync),t.lchmod||(t.lchmod=function(t,n,r){r&&e.nextTick(r)},t.lchmodSync=function(){}),t.lchown||(t.lchown=function(t,n,r,i){i&&e.nextTick(i)},t.lchownSync=function(){}),"win32"===p&&(t.rename=function(e){return function(n,r,i){var o=Date.now(),s=0;e(n,r,function a(c){if(c&&("EACCES"===c.code||"EPERM"===c.code)&&Date.now()-o<6e4)return setTimeout(function(){t.stat(r,function(t,o){t&&"ENOENT"===t.code?e(n,r,a):i(c)})},s),void(s<100&&(s+=10));i&&i(c)})}}(t.rename)),t.read=function(e){return function(n,r,i,o,s,a){var c;if(a&&"function"==typeof a){var f=0;c=function(u,h,d){if(u&&"EAGAIN"===u.code&&f<10)return f++,e.call(t,n,r,i,o,s,c);a.apply(this,arguments)}}return e.call(t,n,r,i,o,s,c)}}(t.read),t.readSync=function(e){return function(n,r,i,o,s){for(var a=0;;)try{return e.call(t,n,r,i,o,s)}catch(t){if("EAGAIN"===t.code&&a<10){a++;continue}throw t}}}(t.readSync)}}).call(e,n(1))},function(t,e){t.exports={O_RDONLY:0,O_WRONLY:1,O_RDWR:2,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,O_CREAT:512,O_EXCL:2048,O_NOCTTY:131072,O_TRUNC:1024,O_APPEND:8,O_DIRECTORY:1048576,O_NOFOLLOW:256,O_SYNC:128,O_SYMLINK:2097152,O_NONBLOCK:4,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1,E2BIG:7,EACCES:13,EADDRINUSE:48,EADDRNOTAVAIL:49,EAFNOSUPPORT:47,EAGAIN:35,EALREADY:37,EBADF:9,EBADMSG:94,EBUSY:16,ECANCELED:89,ECHILD:10,ECONNABORTED:53,ECONNREFUSED:61,ECONNRESET:54,EDEADLK:11,EDESTADDRREQ:39,EDOM:33,EDQUOT:69,EEXIST:17,EFAULT:14,EFBIG:27,EHOSTUNREACH:65,EIDRM:90,EILSEQ:92,EINPROGRESS:36,EINTR:4,EINVAL:22,EIO:5,EISCONN:56,EISDIR:21,ELOOP:62,EMFILE:24,EMLINK:31,EMSGSIZE:40,EMULTIHOP:95,ENAMETOOLONG:63,ENETDOWN:50,ENETRESET:52,ENETUNREACH:51,ENFILE:23,ENOBUFS:55,ENODATA:96,ENODEV:19,ENOENT:2,ENOEXEC:8,ENOLCK:77,ENOLINK:97,ENOMEM:12,ENOMSG:91,ENOPROTOOPT:42,ENOSPC:28,ENOSR:98,ENOSTR:99,ENOSYS:78,ENOTCONN:57,ENOTDIR:20,ENOTEMPTY:66,ENOTSOCK:38,ENOTSUP:45,ENOTTY:25,ENXIO:6,EOPNOTSUPP:102,EOVERFLOW:84,EPERM:1,EPIPE:32,EPROTO:100,EPROTONOSUPPORT:43,EPROTOTYPE:41,ERANGE:34,EROFS:30,ESPIPE:29,ESRCH:3,ESTALE:70,ETIME:101,ETIMEDOUT:60,ETXTBSY:26,EWOULDBLOCK:35,EXDEV:18,SIGHUP:1,SIGINT:2,SIGQUIT:3,SIGILL:4,SIGTRAP:5,SIGABRT:6,SIGIOT:6,SIGBUS:10,SIGFPE:8,SIGKILL:9,SIGUSR1:30,SIGSEGV:11,SIGUSR2:31,SIGPIPE:13,SIGALRM:14,SIGTERM:15,SIGCHLD:20,SIGCONT:19,SIGSTOP:17,SIGTSTP:18,SIGTTIN:21,SIGTTOU:22,SIGURG:16,SIGXCPU:24,SIGXFSZ:25,SIGVTALRM:26,SIGPROF:27,SIGWINCH:28,SIGIO:23,SIGSYS:12,SSL_OP_ALL:2147486719,SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,SSL_OP_CISCO_ANYCONNECT:32768,SSL_OP_COOKIE_EXCHANGE:8192,SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,SSL_OP_EPHEMERAL_RSA:0,SSL_OP_LEGACY_SERVER_CONNECT:4,SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER:32,SSL_OP_MICROSOFT_SESS_ID_BUG:1,SSL_OP_MSIE_SSLV2_RSA_PADDING:0,SSL_OP_NETSCAPE_CA_DN_BUG:536870912,SSL_OP_NETSCAPE_CHALLENGE_BUG:2,SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG:1073741824,SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG:8,SSL_OP_NO_COMPRESSION:131072,SSL_OP_NO_QUERY_MTU:4096,SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,SSL_OP_NO_SSLv2:16777216,SSL_OP_NO_SSLv3:33554432,SSL_OP_NO_TICKET:16384,SSL_OP_NO_TLSv1:67108864,SSL_OP_NO_TLSv1_1:268435456,SSL_OP_NO_TLSv1_2:134217728,SSL_OP_PKCS1_CHECK_1:0,SSL_OP_PKCS1_CHECK_2:0,SSL_OP_SINGLE_DH_USE:1048576,SSL_OP_SINGLE_ECDH_USE:524288,SSL_OP_SSLEAY_080_CLIENT_DH_BUG:128,SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG:0,SSL_OP_TLS_BLOCK_PADDING_BUG:512,SSL_OP_TLS_D5_BUG:256,SSL_OP_TLS_ROLLBACK_BUG:8388608,ENGINE_METHOD_DSA:2,ENGINE_METHOD_DH:4,ENGINE_METHOD_RAND:8,ENGINE_METHOD_ECDH:16,ENGINE_METHOD_ECDSA:32,ENGINE_METHOD_CIPHERS:64,ENGINE_METHOD_DIGESTS:128,ENGINE_METHOD_STORE:256,ENGINE_METHOD_PKEY_METHS:512,ENGINE_METHOD_PKEY_ASN1_METHS:1024,ENGINE_METHOD_ALL:65535,ENGINE_METHOD_NONE:0,DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6,F_OK:0,R_OK:4,W_OK:2,X_OK:1,UV_UDP_REUSEADDR:4}},function(t,e,n){(function(e){var r=n(139).Stream;t.exports=function(t){function n(i,o){if(!(this instanceof n))return new n(i,o);r.call(this);var s=this;this.path=i,this.fd=null,this.readable=!0,this.paused=!1,this.flags="r",this.mode=438,this.bufferSize=65536,o=o||{};for(var a=Object.keys(o),c=0,f=a.length;cthis.end)throw new Error("start must be <= end");this.pos=this.start}null===this.fd?t.open(this.path,this.flags,this.mode,function(t,e){if(t)return s.emit("error",t),void(s.readable=!1);s.fd=e,s.emit("open",e),s._read()}):e.nextTick(function(){s._read()})}function i(e,n){if(!(this instanceof i))return new i(e,n);r.call(this),this.path=e,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,n=n||{};for(var o=Object.keys(n),s=0,a=o.length;s= zero");this.pos=this.start}this.busy=!1,this._queue=[],null===this.fd&&(this._open=t.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}return{ReadStream:n,WriteStream:i}}}).call(e,n(1))},function(t,e,n){function r(){i.call(this)}t.exports=r;var i=n(4).EventEmitter;n(5)(r,i),r.Readable=n(12),r.Writable=n(140),r.Duplex=n(141),r.Transform=n(142),r.PassThrough=n(143),r.Stream=r,r.prototype.pipe=function(t,e){function n(e){t.writable&&!1===t.write(e)&&f.pause&&f.pause()}function r(){f.readable&&f.resume&&f.resume()}function o(){u||(u=!0,t.end())}function s(){u||(u=!0,"function"==typeof t.destroy&&t.destroy())}function a(t){if(c(),0===i.listenerCount(this,"error"))throw t}function c(){f.removeListener("data",n),t.removeListener("drain",r),f.removeListener("end",o),f.removeListener("close",s),f.removeListener("error",a),t.removeListener("error",a),f.removeListener("end",c),f.removeListener("close",c),t.removeListener("close",c)}var f=this;f.on("data",n),t.on("drain",r),t._isStdio||e&&!1===e.end||(f.on("end",o),f.on("close",s));var u=!1;return f.on("error",a),t.on("error",a),f.on("end",c),f.on("close",c),t.on("close",c),t.emit("pipe",f),t}},function(t,e,n){t.exports=n(25)},function(t,e,n){t.exports=n(8)},function(t,e,n){t.exports=n(12).Transform},function(t,e,n){t.exports=n(12).PassThrough},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e,n){"use strict";(function(e){function r(t,e){if(t===e)return 0;for(var n=t.length,r=e.length,i=0,o=Math.min(n,r);i=0;a--)if(c[a]!==f[a])return!1;for(a=c.length-1;a>=0;a--)if(s=c[a],!d(t[s],e[s],n,r))return!1;return!0}(t,e,n,a))}return n?t===e:t==e}function l(t){return"[object Arguments]"==Object.prototype.toString.call(t)}function p(t,e,n){d(t,e,!0)&&u(t,e,n,"notDeepStrictEqual",p)}function b(t,e){if(!t||!e)return!1;if("[object RegExp]"==Object.prototype.toString.call(e))return e.test(t);try{if(t instanceof e)return!0}catch(t){}return!Error.isPrototypeOf(e)&&!0===e.call({},t)}function y(t,e,n,r){var i;if("function"!=typeof e)throw new TypeError('"block" argument must be a function');"string"==typeof n&&(r=n,n=null),i=function(t){var e;try{t()}catch(t){e=t}return e}(e),r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),t&&!i&&u(i,n,"Missing expected exception"+r);var o="string"==typeof r,s=!t&&g.isError(i),a=!t&&i&&!n;if((s&&o&&b(i,n)||a)&&u(i,n,"Got unwanted exception"+r),t&&i&&n&&!b(i,n)||!t&&i)throw i}var g=n(24),m=Object.prototype.hasOwnProperty,v=Array.prototype.slice,_="foo"===function(){}.name,w=t.exports=h,S=/\s*function\s+([^\(\s]*)\s*/;w.AssertionError=function(t){this.name="AssertionError",this.actual=t.actual,this.expected=t.expected,this.operator=t.operator,t.message?(this.message=t.message,this.generatedMessage=!1):(this.message=function(t){return c(f(t.actual),128)+" "+t.operator+" "+c(f(t.expected),128)}(this),this.generatedMessage=!0);var e=t.stackStartFunction||u;if(Error.captureStackTrace)Error.captureStackTrace(this,e);else{var n=new Error;if(n.stack){var r=n.stack,i=a(e),o=r.indexOf("\n"+i);if(o>=0){var s=r.indexOf("\n",o+1);r=r.substring(s+1)}this.stack=r}}},g.inherits(w.AssertionError,Error),w.fail=u,w.ok=h,w.equal=function(t,e,n){t!=e&&u(t,e,n,"==",w.equal)},w.notEqual=function(t,e,n){t==e&&u(t,e,n,"!=",w.notEqual)},w.deepEqual=function(t,e,n){d(t,e,!1)||u(t,e,n,"deepEqual",w.deepEqual)},w.deepStrictEqual=function(t,e,n){d(t,e,!0)||u(t,e,n,"deepStrictEqual",w.deepStrictEqual)},w.notDeepEqual=function(t,e,n){d(t,e,!1)&&u(t,e,n,"notDeepEqual",w.notDeepEqual)},w.notDeepStrictEqual=p,w.strictEqual=function(t,e,n){t!==e&&u(t,e,n,"===",w.strictEqual)},w.notStrictEqual=function(t,e,n){t===e&&u(t,e,n,"!==",w.notStrictEqual)},w.throws=function(t,e,n){y(!0,t,e,n)},w.doesNotThrow=function(t,e,n){y(!1,t,e,n)},w.ifError=function(t){if(t)throw t};var k=Object.keys||function(t){var e=[];for(var n in t)m.call(t,n)&&e.push(n);return e}}).call(e,n(3))},function(t,e,n){e.asyncMap=n(148),e.bindActor=n(56),e.chain=n(149)},function(t,e,n){(function(e){t.exports=function(){function t(u){u&&!a&&(a=u);for(var h=arguments.length,d=1;dc){var l=r.slice(c);f+=(r.length-c)*o,c=r.length,e.nextTick(function(){l.forEach(function(e){n.forEach(function(n){n(e,t)})})})}0==--f&&i.apply(null,[a].concat(s))}var n=Array.prototype.slice.call(arguments),r=n.shift()||[],i=n.pop();if("function"!=typeof i)throw new Error("No callback provided to asyncMap");if(!r)return i(null,[]);Array.isArray(r)||(r=[r]);var o=n.length,s=[],a=null,c=r.length,f=c*o;if(!f)return i(null,[]);r.forEach(function(e){n.forEach(function(n){n(e,t)})})}}).call(e,n(1))},function(t,e,n){function r(t,e){var n=[];!function o(s,a){return s>=a?e(null,n):(Array.isArray(t[s])&&(t[s]=i.apply(null,t[s].map(function(t){return t===r.first?n[0]:t===r.last?n[n.length-1]:t}))),t[s]?void t[s](function(t,r){if(t)return e(t,n);void 0!==r&&(n=n.concat(r)),o(s+1,a)}):o(s+1,a))}(0,t.length)}t.exports=r;var i=n(56);r.first={},r.last={}},function(t,e,n){!function(){function e(t,r){var i=this instanceof e?this:n;if(i.reset(r),"string"==typeof t&&t.length>0&&i.hash(t),i!==this)return i}var n;e.prototype.hash=function(t){var e,n,r,i,o;switch(o=t.length,this.len+=o,n=this.k1,r=0,this.rem){case 0:n^=o>r?65535&t.charCodeAt(r++):0;case 1:n^=o>r?(65535&t.charCodeAt(r++))<<8:0;case 2:n^=o>r?(65535&t.charCodeAt(r++))<<16:0;case 3:n^=o>r?(255&t.charCodeAt(r))<<24:0,n^=o>r?(65280&t.charCodeAt(r++))>>8:0}if(this.rem=o+this.rem&3,(o-=this.rem)>0){for(e=this.h1;;){if(n=11601*n+3432906752*(65535&n)&4294967295,n=n<<15|n>>>17,n=13715*n+461832192*(65535&n)&4294967295,e^=n,e=e<<13|e>>>19,e=5*e+3864292196&4294967295,r>=o)break;n=65535&t.charCodeAt(r++)^(65535&t.charCodeAt(r++))<<8^(65535&t.charCodeAt(r++))<<16,n^=(255&(i=t.charCodeAt(r++)))<<24^(65280&i)>>8}switch(n=0,this.rem){case 3:n^=(65535&t.charCodeAt(r+2))<<16;case 2:n^=(65535&t.charCodeAt(r+1))<<8;case 1:n^=65535&t.charCodeAt(r)}this.h1=e}return this.k1=n,this},e.prototype.result=function(){var t,e;return t=this.k1,e=this.h1,t>0&&(e^=t=13715*(t=(t=11601*t+3432906752*(65535&t)&4294967295)<<15|t>>>17)+461832192*(65535&t)&4294967295),e^=this.len,e^=e>>>16,e=51819*e+2246770688*(65535&e)&4294967295,e^=e>>>13,e=44597*e+3266445312*(65535&e)&4294967295,(e^=e>>>16)>>>0},e.prototype.reset=function(t){return this.h1="number"==typeof t?t:0,this.rem=this.k1=this.len=0,this},n=new e,t.exports=e}()},function(t,e,n){"use strict";class r{constructor(t){this.id=t,this._index=[]}get(){return this._index}updateIndex(t,e){this._index=t.ops}}t.exports=r},function(t,e,n){const r=n(4).EventEmitter,i=n(40);class o extends r{constructor(t,e=8){super(),this._store=t,this._concurrency=e,this._queue=[],this._fetching={},this._tasksRunning=0,this._have={},this._stats={tasksProcessed:0,tasksRequested:0},this._timer=setInterval(()=>{this._queue.length>0&&this._tasksRunningnull!==t&&void 0!==t).sort((t,e)=>(t.clock?t.clock.time:0)-(e.clock?e.clock.time:0)).forEach(t=>{this._store._oplog.has(t.hash||t)||this._queue.find(e=>(e.hash||e)===(t.hash||t))||(this._queue.splice(0,0,t),this.emit("load.added",t))})}catch(t){console.error(t)}}async _processLoop(){if(this._queue.length>0&&this._tasksRunning{this._queue=this._queue.filter(t=>!this._fetching[t.hash||t]);const t=this._queue.shift();return t&&(this._fetching[t.hash||t]=t),t})();if(t){const e=t.hash||t,n=this._store._oplog.values;this._have=Object.assign({},this._have,this._store._replicationInfo.have),this.emit("load.start",t,this._have);const r=await i.fromEntryHash(this._store._ipfs,e,this._store._oplog.id,1,n,this._store.key,this._store.access.write,this._onSyncProgress.bind(this));this._stats.tasksProcessed+=1,delete this._fetching[e],r.values.forEach(t=>{t.next.length>0&&this.load(t.next)}),this.emit("load.end",r,this._have)}}catch(t){console.error("LOADER-ERROR:",t),this.emit("error",t)}this._tasksRunning--,this.emit("load.complete",this._have)}}_onSyncProgress(t,e,n){this._have[e.clock.time]||(this._have[e.clock.time]=!0,this.emit("load.progress",this._id,t,e,n,this._have))}}t.exports=o},function(t,e,n){"use strict";const r=n(4).EventEmitter;class i extends r{constructor(t,e=1e3){super(),this._loader=t,this._oplog=null,this._interval=e,this._timer=null}start(){this._timer=setInterval(()=>this._checkReplicationStatus(),this._interval)}stop(){clearInterval(this._timer)}replicate(t){this._oplog=t}async _checkReplicationStatus(){if(this._oplog&&0===this._loader._queue.length){this._oplog.tails.filter(t=>t.next.length>0).sort((t,e)=>t.clock.time-e.clock.time).reduce((t,e)=>t.concat(e.next),[]).reduce((t,e)=>(t.includes(e)||t.push(e),t),[]).forEach(t=>{this._loader.load([t])})}}}t.exports=i},function(t,e,n){"use strict";class r{constructor(){this._index=[]}get(){return this._index.values?this._index.values:[]}updateIndex(t){this._index=t}}t.exports=r},function(t,e,n){"use strict";const r=n(34),i=n(156);class o extends r{constructor(t,e,n,r){r||(r={}),r.Index||Object.assign(r,{Index:i}),super(t,e,n,r),this._type="feed"}remove(t){return this.del(t)}del(t){const e={op:"DEL",key:null,value:t};return this._addOperation(e)}}t.exports=o},function(t,e,n){"use strict";class r{constructor(){this._index={}}get(){return Object.keys(this._index).map(t=>this._index[t])}updateIndex(t){this._index={},t.values.reduce((t,e)=>(t.includes(e.hash)||(t.push(e.hash),"ADD"===e.payload.op?this._index[e.hash]=e:"DEL"===e.payload.op&&delete this._index[e.payload.value]),t),[])}}t.exports=r},function(t,e,n){"use strict";const r=n(18),i=n(158);class o extends r{constructor(t,e,n,r){let o=Object.assign({},{Index:i});Object.assign(o,r),super(t,e,n,o),this._type="keyvalue"}get(t){return this._index.get(t)}set(t,e){return this.put(t,e)}put(t,e){return this._addOperation({op:"PUT",key:t,value:e})}del(t){return this._addOperation({op:"DEL",key:t,value:null})}}t.exports=o},function(t,e,n){"use strict";class r{constructor(){this._index={}}get(t){return this._index[t]}updateIndex(t){t.values.slice().reverse().reduce((t,e)=>(t.includes(e.payload.key)||(t.push(e.payload.key),"PUT"===e.payload.op?this._index[e.payload.key]=e.payload.value:"DEL"===e.payload.op&&delete this._index[e.payload.key]),t),[])}}t.exports=r},function(t,e,n){"use strict";const r=n(18),i=n(160);class o extends r{constructor(t,e,n,r={}){r.Index||Object.assign(r,{Index:i}),super(t,e,n,r),this._type="counter"}get value(){return this._index.get().value}inc(t){const e=this._index.get();if(e)return e.increment(t),this._addOperation({op:"COUNTER",key:null,value:e.payload})}}t.exports=o},function(t,e,n){"use strict";const r=n(161);class i{constructor(t){this._index=new r(t)}get(){return this._index}updateIndex(t){this._index&&t.values.filter(t=>t&&"COUNTER"===t.payload.op).map(t=>r.from(t.payload.value)).forEach(t=>this._index.merge(t))}}t.exports=i},function(t,e,n){"use strict";const r=n(162).isEqual;class i{constructor(t,e){this.id=t,this._counters=e||{},this._counters[this.id]=this._counters[this.id]?this._counters[this.id]:0}increment(t){t||(t=1),this._counters[this.id]=this._counters[this.id]+t}get value(){return Object.keys(this._counters).map(t=>this._counters[t]).reduce((t,e)=>t+e,0)}get payload(){return{id:this.id,counters:this._counters}}compare(t){return t.id===this.id&&r(t._counters,this._counters)}merge(t){Object.keys(t._counters).forEach(e=>{this._counters[e]=Math.max(this._counters[e]?this._counters[e]:0,t._counters[e])})}static from(t){return new i(t.id,t.counters)}}t.exports=i},function(t,e,n){"use strict";e.isEqual=((t,e)=>{const n=Object.getOwnPropertyNames(t),r=Object.getOwnPropertyNames(e);if(n.length!==r.length)return!1;for(let r=0;rt.toString().split(e).join(n));class a extends r{constructor(t,e,n,r){r||(r={}),r.indexBy||Object.assign(r,{indexBy:"_id"}),r.Index||Object.assign(r,{Index:i}),super(t,e,n,r),this._type="docstore"}get(t,e=!1){const n=(t=t.toString()).split(" ");t=n.length>1?s(t,"."," ").toLowerCase():t.toLowerCase();return Object.keys(this._index._index).filter(r=>e?-1!==r.indexOf(t):(e=>n.length>1?-1!==s(e,"."," ").toLowerCase().indexOf(t):-1!==e.toLowerCase().indexOf(t))(r)).map(t=>this._index.get(t))}query(t){return Object.keys(this._index._index).map(t=>this._index.get(t)).filter(e=>t(e))}batchPut(t,e){return o(t,(n,r)=>this._addOperationBatch({op:"PUT",key:n[this.options.indexBy],value:n},!0,r===t.length-1,e),{concurrency:1}).then(()=>this.saveSnapshot())}put(t){if(!t[this.options.indexBy])throw new Error(`The provided document doesn't contain field '${this.options.indexBy}'`);return this._addOperation({op:"PUT",key:t[this.options.indexBy],value:t})}del(t){if(!this._index.get(t))throw new Error(`No entry with key '${t}' in the database`);return this._addOperation({op:"DEL",key:t,value:null})}}t.exports=a},function(t,e,n){"use strict";class r{constructor(){this._index={}}get(t){return this._index[t]}updateIndex(t,e){t.values.slice().reverse().reduce((t,n,r)=>(!0!==t[n.payload.key]&&(t[n.payload.key]=!0,"PUT"===n.payload.op?this._index[n.payload.key]=n.payload.value:"DEL"===n.payload.op&&delete this._index[n.payload.key]),e&&e(n,r),t),{})}}t.exports=r},function(t,e,n){t.exports=n(166)},function(t,e,n){"use strict";(function(e){const r=n(167),i=n(60),o=i.create("orbit-db.ipfs-pubsub");i.setLogLevel("ERROR");let s=0;class a{constructor(t,e){this._ipfs=t,this._id=e,this._subscriptions={},null===this._ipfs.pubsub&&o.error("The provided version of ipfs doesn't have pubsub support. Messages will not be exchanged."),this._handleMessage=this._handleMessage.bind(this),this._ipfs.setMaxListeners(256)}subscribe(t,e,n){if(!this._subscriptions[t]){const i=r(this._ipfs,t);i.on("error",t=>{o.error("Pubsub Error:",t)}),i.on("message",t=>{this._handleMessage(t)}),i.on("peer joined",e=>{this._subscriptions[t].onNewPeer(t,e,i)}),i.on("subscribed",()=>{this._subscriptions[t]={room:i,onMessage:e,onNewPeer:n},s++,o.debug("Topics open:",s)})}}unsubscribe(t){this._subscriptions[t]&&(this._subscriptions[t].room.leave(),this._subscriptions[t].room=null,delete this._subscriptions[t],o.debug(`Unsubscribed from '${t}'`),s--,o.debug("Topics open:",s))}publish(t,n){this._subscriptions[t]&&this._subscriptions[t].room&&this._ipfs.pubsub&&this._subscriptions[t].room.broadcast(new e(JSON.stringify(n)))}disconnect(){Object.keys(this._subscriptions).forEach(t=>this.unsubscribe(t)),this._subscriptions={}}_handleMessage(t){if(t.from===this._id)return;const e=t.topicCIDs[0];let n,r;try{n=JSON.parse(t.data),r=this._subscriptions[e]}catch(e){console.error("Couldn't parse pubsub message:",t.data)}r&&r.onMessage&&n&&r.onMessage(e,n)}}t.exports=a}).call(e,n(0).Buffer)},function(t,e,n){"use strict";(function(e){const r=n(168),i=n(4),o=n(20),s=n(57),a=n(22),c=n(58),f=n(173),u=n(59),h={pollInterval:1e3};t.exports=((t,e,n)=>new d(t,e,n));class d extends i{constructor(t,e,n){if(super(),this._ipfs=t,this._topic=e,this._options=Object.assign({},s(h),s(n)),this._peers=[],this._connections={},!this._ipfs.pubsub)throw new Error("This IPFS node does not have pubsub.");this._ipfs.isOnline()?this._start():this._ipfs.on("ready",this._start.bind(this)),this._ipfs.on("stop",this.leave.bind(this))}getPeers(){return this._peers.slice(0)}hasPeer(t){return this._peers.indexOf(t)>=0}leave(){o.clearInterval(),clearInterval(this._interval),Object.keys(this._connections).forEach(t=>{this._connections[t].stop(),delete this._connections[t]}),this.emit("stop")}broadcast(t){let e=u(t);this._ipfs.pubsub.publish(this._topic,e,t=>{t&&this.emit("error",t)})}sendTo(t,n){let r=this._connections[t];r||((r=new f(t,this._ipfs,this)).on("error",t=>this.emit("error",t)),this._connections[t]=r);const i=e.from([0]),o={from:this._ipfs._peerInfo.id._idB58String,data:n,seqno:i,topicCIDs:[this._topic]};r.push(e.from(JSON.stringify(o)))}_start(){this._interval=o.setInterval(this._pollPeers.bind(this),this._options.pollInterval);const t=this._onMessage.bind(this);this._ipfs.pubsub.subscribe(this._topic,t,t=>{t?this.emit("error",t):this.emit("subscribed",this._topic)}),this.once("stop",()=>{this._ipfs.state.stopped()&&this._ipfs.pubsub.unsubscribe(this._topic,t)}),this._ipfs._libp2pNode.handle(c,this._handleDirectConnection.bind(this))}_pollPeers(){this._ipfs.pubsub.peers(this._topic,(t,e)=>{if(t)return void this.emit("error",t);const n=e.sort();this._emitChanges(n)&&(this._peers=n)})}_emitChanges(t){const e=r(this._peers,t);return e.added.forEach(t=>this.emit("peer joined",t)),e.removed.forEach(t=>this.emit("peer left",t)),e.added.length>0||e.removed.length>0}_onMessage(t){this.emit("message",t)}_handleDirectConnection(t,n){n.getPeerInfo((t,r)=>{if(t)throw t;r.id.toB58String();a(n,a.map(t=>{let n=JSON.parse(t);return n.data=e.from(n.data),this.emit("message",n),n}),a.onEnd(t=>{t&&this.emit("warning",t)}))})}}}).call(e,n(0).Buffer)},function(t,e,n){"use strict";const r=n(57),i=n(169)("hyperdiff"),o=n(172),s=t=>-1!==t;t.exports=function(t,e,n){const{first:a,second:c}={first:t,second:r(e)},f=n?function(t,e,n){return t.findIndex(function(t){return function(t,e,r){return n.every(n=>e[n]===t[n])}(t,e)})}:function(t,e,n){return t.indexOf(e)};i("preconditions first=%j second=%j findIndex=%s",a,c,f.name);const u=a.reduce(function(t,e,r){const a=f(c,e,n),u=s(a)?"common":"removed";return t[u].push(e),o(c,a),i("index=%s value=%s collection=%s",r,e,u),t},{common:[],removed:[]});return u.added=c,i("added=%j removed=%j common%j",u.added,u.removed,u.common),u}},function(t,e,n){(function(r){function i(){var t;try{t=e.storage.debug}catch(t){}return!t&&void 0!==r&&"env"in r&&(t=Object({NODE_ENV:void 0}).DEBUG),t}(e=t.exports=n(170)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},e.formatArgs=function(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var i=0,o=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(i++,"%c"===t&&(o=i))}),t.splice(o,0,r)}},e.save=function(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}},e.load=i,e.useColors=function(){return!("undefined"==typeof window||!window.process||"renderer"!==window.process.type)||("undefined"==typeof navigator||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&("undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(i())}).call(e,n(1))},function(t,e,n){function r(t){function n(){if(n.enabled){var t=n,i=+new Date,o=i-(r||i);t.diff=o,t.prev=r,t.curr=i,r=i;for(var s=new Array(arguments.length),a=0;a0)return function(t){if(!((t=String(t)).length>100)){var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(e){var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*a;case"days":case"day":case"d":return n*s;case"hours":case"hour":case"hrs":case"hr":case"h":return n*o;case"minutes":case"minute":case"mins":case"min":case"m":return n*i;case"seconds":case"second":case"secs":case"sec":case"s":return n*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}(t);if("number"===c&&!1===isNaN(t))return e.long?function(t){return n(t,s,"day")||n(t,o,"hour")||n(t,i,"minute")||n(t,r,"second")||t+" ms"}(t):function(t){return t>=s?Math.round(t/s)+"d":t>=o?Math.round(t/o)+"h":t>=i?Math.round(t/i)+"m":t>=r?Math.round(t/r)+"s":t+"ms"}(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){(function(e){function n(t,e){for(var n=-1,r=e.length,i=t.length;++n0&&r(f)?e>1?c(f,e-1,r,i,o):n(o,f):i||(o[o.length]=f)}return o}function f(t,e){for(var n=0,r=(e=m(e,t)?[e]:d(e)).length;null!=t&&ni?0:i+e);(n=n>i?i:n)<0&&(n+=i);i=e>n?0:n-e>>>0,e>>>=0;var o=Array(i);for(;++re||o&&s&&c&&!a&&!f||r&&s&&c||!n&&c||!i)return 1;if(!r&&!o&&!f&&t-1&&t%1==0&&t<=I}(t.length)&&!w(t)}(t)}(t)&&V.call(t,"callee")&&(!tt.call(t,"callee")||X.call(t)==P)}(t)||!!(nt&&t&&t[nt])}function g(t,e){return!!(e=null==e?I:e)&&("number"==typeof t||q.test(t))&&t>-1&&t%1==0&&t-1},i.prototype.set=function(t,e){var n=this.__data__,r=s(n,t);return r<0?n.push([t,e]):n[r][1]=e,this},o.prototype.clear=function(){this.__data__={hash:new r,map:new(it||i),string:new r}},o.prototype.delete=function(t){return p(this,t).delete(t)},o.prototype.get=function(t){return p(this,t).get(t)},o.prototype.has=function(t){return p(this,t).has(t)},o.prototype.set=function(t,e){return p(this,t).set(t,e),this};var ct=_(function(t){t=E(t);var e=[];return L.test(t)&&e.push(""),t.replace(D,function(t,n,r,i){e.push(r?i.replace(B,"$1"):n||t)}),e}),ft=function(t,e){return e=rt(void 0===e?t.length-1:e,0),function(){for(var n=arguments,r=-1,i=rt(n.length-e,0),o=Array(i);++r{this.push(t)}))}stop(){this._connection&&this._connection.end()}_getConnection(){this._connecting=!0,this._getPeerAddresses(this._id,(t,e)=>{t?this.emit("error",t):e.length?this._ipfs._libp2pNode.dial(e[0],s,(t,e)=>{if(t)return void this.emit("error",t);this._connecting=!1;const n=o(!1,t=>{this._closed=!0,t&&this.emit("error",t)});this._connection=n,i(n,e,i.onEnd(t=>{delete this._connection,t&&!this._closed&&this.emit("error",t)})),this.emit("connect",n)}):this.emit("error",new Error("could not connect to "+this._id))})}_getPeerAddresses(t,e){this._ipfs.swarm.peers((n,r)=>{n?e(n):e(null,r.filter(e=>e.peer.id.toB58String()===t).map(t=>t.peer))})}}},function(t,e,n){"use strict";(function(e){const r=n(175);class i extends r{constructor(t){super(),this._ipfs=t}async load(t){0===t.indexOf("/ipfs")&&(t=t.split("/")[2]);try{const e=await this._ipfs.object.get(t),n=JSON.parse(e.toJSON().data);this._access=n}catch(t){console.log("ACCESS ERROR:",t)}}async save(){let t;try{const n=JSON.stringify(this._access,null,2);t=(await this._ipfs.object.put(new e(n))).toJSON().multihash.toString()}catch(t){console.log("ACCESS ERROR:",t)}return t}}t.exports=i}).call(e,n(0).Buffer)},function(t,e,n){"use strict";class r{constructor(){this._access={admin:[],write:[],read:[]}}async load(t){}async save(){}get admin(){return this._access.admin}get write(){return this._access.write.concat(this._access.admin)}get read(){return this._access.read}add(t,e){switch(t){case"admin":this._access.admin.push(e);break;case"write":this._access.write.push(e);break;case"read":this._access.read.push(e)}}remove(t,e){const n=(t,n)=>{return t.reduce((t,n)=>(n!==e&&t.push(n),t),[])};switch(t){case"admin":this._access.admin=n(this._access.admin);break;case"write":this._access.write=n(this._access.write);break;case"read":this._access.read=n(this._access.read)}}}t.exports=r},function(t,e,n){"use strict";const r=n(11),i=n(177);class o{constructor(t,e){this.root=t,this.path=e}toString(){return r.join("/orbitdb",this.root,this.path)}static isValid(t){const e=t.toString().split("/").filter((e,n)=>!((0===n||1===n)&&0===t.toString().indexOf("/orbit")&&"orbitdb"===e)).filter(t=>""!==t&&" "!==t),n=e[0].indexOf("Qm")>-1?i.fromB58String(e[0]):null;try{i.validate(n)}catch(t){return!1}return null!==n}static parse(t){if(!t)throw new Error(`Not a valid OrbitDB address: ${t}`);if(!o.isValid(t))throw new Error(`Not a valid OrbitDB address: ${t}`);const e=t.toString().split("/").filter((e,n)=>!((0===n||1===n)&&0===t.toString().indexOf("/orbit")&&"orbitdb"===e)).filter(t=>""!==t&&" "!==t);return new o(e[0],e.slice(1,e.length).join("/"))}}t.exports=o},function(t,e,n){"use strict";(function(t){function r(t){e.decode(t)}const i=n(178),o=n(180);e.names=o.names,e.codes=o.codes,e.defaultLengths=o.defaultLengths;const s=n(181);e.toHexString=function(e){if(!t.isBuffer(e))throw new Error("must be passed a buffer");return e.toString("hex")},e.fromHexString=function(e){return t.from(e,"hex")},e.toB58String=function(e){if(!t.isBuffer(e))throw new Error("must be passed a buffer");return i.encode(e)},e.fromB58String=function(e){let n=e;return t.isBuffer(e)&&(n=e.toString()),t.from(i.decode(n))},e.decode=function(n){if(!t.isBuffer(n))throw new Error("multihash must be a Buffer");if(n.length<3)throw new Error("multihash too short. must be > 3 bytes.");let r=s.decode(n);if(!e.isValidCode(r))throw new Error(`multihash unknown function code: 0x${r.toString(16)}`);n=n.slice(s.decode.bytes);let i=s.decode(n);if(i<1)throw new Error(`multihash invalid length: 0x${i.toString(16)}`);if((n=n.slice(s.decode.bytes)).length!==i)throw new Error(`multihash length inconsistent: 0x${n.toString("hex")}`);return{code:r,name:o.codes[r],length:i,digest:n}},e.encode=function(n,r,i){if(!n||!r)throw new Error("multihash encode requires at least two args: digest, code");const o=e.coerceCode(r);if(!t.isBuffer(n))throw new Error("digest should be a Buffer");if(null==i&&(i=n.length),i&&n.length!==i)throw new Error("digest length should be equal to specified length.");return t.concat([t.from(s.encode(o)),t.from(s.encode(i)),n])},e.coerceCode=function(t){let n=t;if("string"==typeof t){if(!o.names[t])throw new Error(`Unrecognized hash function named: ${t}`);n=o.names[t]}if("number"!=typeof n)throw new Error(`Hash function code should be a number. Got: ${n}`);if(!o.codes[n]&&!e.isAppCode(n))throw new Error(`Unrecognized function code: ${n}`);return n},e.isAppCode=function(t){return t>0&&t<16},e.isValidCode=function(t){return!!e.isAppCode(t)||!!o.codes[t]},e.validate=r,e.prefix=function(t){return r(t),t.slice(0,2)}}).call(e,n(0).Buffer)},function(t,e,n){var r=n(179);t.exports=r("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},function(t,e,n){var r=n(10).Buffer;t.exports=function(t){function e(t){if(0===t.length)return r.allocUnsafe(0);for(var e=[0],s=0;s>=8;for(;f>0;)e.push(255&f),f>>=8}for(var u=0;t[u]===o&&u0;)n.push(s%i),s=s/i|0}for(var a="",c=0;0===e[c]&&c=0;--f)a+=t[n[f]];return a},decodeUnsafe:e,decode:function(t){var n=e(t);if(n)return n;throw new Error("Non-base"+i+" character")}}}},function(t,e,n){"use strict";e.names=Object.freeze({sha1:17,"sha2-256":18,"sha2-512":19,"sha3-224":23,"sha3-256":22,"sha3-384":21,"sha3-512":20,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,"murmur3-128":34,"murmur3-32":35,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"Skein256-8":45825,"Skein256-16":45826,"Skein256-24":45827,"Skein256-32":45828,"Skein256-40":45829,"Skein256-48":45830,"Skein256-56":45831,"Skein256-64":45832,"Skein256-72":45833,"Skein256-80":45834,"Skein256-88":45835,"Skein256-96":45836,"Skein256-104":45837,"Skein256-112":45838,"Skein256-120":45839,"Skein256-128":45840,"Skein256-136":45841,"Skein256-144":45842,"Skein256-152":45843,"Skein256-160":45844,"Skein256-168":45845,"Skein256-176":45846,"Skein256-184":45847,"Skein256-192":45848,"Skein256-200":45849,"Skein256-208":45850,"Skein256-216":45851,"Skein256-224":45852,"Skein256-232":45853,"Skein256-240":45854,"Skein256-248":45855,"Skein256-256":45856,"Skein512-8":45857,"Skein512-16":45858,"Skein512-24":45859,"Skein512-32":45860,"Skein512-40":45861,"Skein512-48":45862,"Skein512-56":45863,"Skein512-64":45864,"Skein512-72":45865,"Skein512-80":45866,"Skein512-88":45867,"Skein512-96":45868,"Skein512-104":45869,"Skein512-112":45870,"Skein512-120":45871,"Skein512-128":45872,"Skein512-136":45873,"Skein512-144":45874,"Skein512-152":45875,"Skein512-160":45876,"Skein512-168":45877,"Skein512-176":45878,"Skein512-184":45879,"Skein512-192":45880,"Skein512-200":45881,"Skein512-208":45882,"Skein512-216":45883,"Skein512-224":45884,"Skein512-232":45885,"Skein512-240":45886,"Skein512-248":45887,"Skein512-256":45888,"Skein512-264":45889,"Skein512-272":45890,"Skein512-280":45891,"Skein512-288":45892,"Skein512-296":45893,"Skein512-304":45894,"Skein512-312":45895,"Skein512-320":45896,"Skein512-328":45897,"Skein512-336":45898,"Skein512-344":45899,"Skein512-352":45900,"Skein512-360":45901,"Skein512-368":45902,"Skein512-376":45903,"Skein512-384":45904,"Skein512-392":45905,"Skein512-400":45906,"Skein512-408":45907,"Skein512-416":45908,"Skein512-424":45909,"Skein512-432":45910,"Skein512-440":45911,"Skein512-448":45912,"Skein512-456":45913,"Skein512-464":45914,"Skein512-472":45915,"Skein512-480":45916,"Skein512-488":45917,"Skein512-496":45918,"Skein512-504":45919,"Skein512-512":45920,"Skein1024-8":45921,"Skein1024-16":45922,"Skein1024-24":45923,"Skein1024-32":45924,"Skein1024-40":45925,"Skein1024-48":45926,"Skein1024-56":45927,"Skein1024-64":45928,"Skein1024-72":45929,"Skein1024-80":45930,"Skein1024-88":45931,"Skein1024-96":45932,"Skein1024-104":45933,"Skein1024-112":45934,"Skein1024-120":45935,"Skein1024-128":45936,"Skein1024-136":45937,"Skein1024-144":45938,"Skein1024-152":45939,"Skein1024-160":45940,"Skein1024-168":45941,"Skein1024-176":45942,"Skein1024-184":45943,"Skein1024-192":45944,"Skein1024-200":45945,"Skein1024-208":45946,"Skein1024-216":45947,"Skein1024-224":45948,"Skein1024-232":45949,"Skein1024-240":45950,"Skein1024-248":45951,"Skein1024-256":45952,"Skein1024-264":45953,"Skein1024-272":45954,"Skein1024-280":45955,"Skein1024-288":45956,"Skein1024-296":45957,"Skein1024-304":45958,"Skein1024-312":45959,"Skein1024-320":45960,"Skein1024-328":45961,"Skein1024-336":45962,"Skein1024-344":45963,"Skein1024-352":45964,"Skein1024-360":45965,"Skein1024-368":45966,"Skein1024-376":45967,"Skein1024-384":45968,"Skein1024-392":45969,"Skein1024-400":45970,"Skein1024-408":45971,"Skein1024-416":45972,"Skein1024-424":45973,"Skein1024-432":45974,"Skein1024-440":45975,"Skein1024-448":45976,"Skein1024-456":45977,"Skein1024-464":45978,"Skein1024-472":45979,"Skein1024-480":45980,"Skein1024-488":45981,"Skein1024-496":45982,"Skein1024-504":45983,"Skein1024-512":45984,"Skein1024-520":45985,"Skein1024-528":45986,"Skein1024-536":45987,"Skein1024-544":45988,"Skein1024-552":45989,"Skein1024-560":45990,"Skein1024-568":45991,"Skein1024-576":45992,"Skein1024-584":45993,"Skein1024-592":45994,"Skein1024-600":45995,"Skein1024-608":45996,"Skein1024-616":45997,"Skein1024-624":45998,"Skein1024-632":45999,"Skein1024-640":46e3,"Skein1024-648":46001,"Skein1024-656":46002,"Skein1024-664":46003,"Skein1024-672":46004,"Skein1024-680":46005,"Skein1024-688":46006,"Skein1024-696":46007,"Skein1024-704":46008,"Skein1024-712":46009,"Skein1024-720":46010,"Skein1024-728":46011,"Skein1024-736":46012,"Skein1024-744":46013,"Skein1024-752":46014,"Skein1024-760":46015,"Skein1024-768":46016,"Skein1024-776":46017,"Skein1024-784":46018,"Skein1024-792":46019,"Skein1024-800":46020,"Skein1024-808":46021,"Skein1024-816":46022,"Skein1024-824":46023,"Skein1024-832":46024,"Skein1024-840":46025,"Skein1024-848":46026,"Skein1024-856":46027,"Skein1024-864":46028,"Skein1024-872":46029,"Skein1024-880":46030,"Skein1024-888":46031,"Skein1024-896":46032,"Skein1024-904":46033,"Skein1024-912":46034,"Skein1024-920":46035,"Skein1024-928":46036,"Skein1024-936":46037,"Skein1024-944":46038,"Skein1024-952":46039,"Skein1024-960":46040,"Skein1024-968":46041,"Skein1024-976":46042,"Skein1024-984":46043,"Skein1024-992":46044,"Skein1024-1000":46045,"Skein1024-1008":46046,"Skein1024-1016":46047,"Skein1024-1024":46048}),e.codes=Object.freeze({17:"sha1",18:"sha2-256",19:"sha2-512",23:"sha3-224",22:"sha3-256",21:"sha3-384",20:"sha3-512",24:"shake-128",25:"shake-256",26:"keccak-224",27:"keccak-256",28:"keccak-384",29:"keccak-512",34:"murmur3-128",35:"murmur3-32",45569:"blake2b-8",45570:"blake2b-16",45571:"blake2b-24",45572:"blake2b-32",45573:"blake2b-40",45574:"blake2b-48",45575:"blake2b-56",45576:"blake2b-64",45577:"blake2b-72",45578:"blake2b-80",45579:"blake2b-88",45580:"blake2b-96",45581:"blake2b-104",45582:"blake2b-112",45583:"blake2b-120",45584:"blake2b-128",45585:"blake2b-136",45586:"blake2b-144",45587:"blake2b-152",45588:"blake2b-160",45589:"blake2b-168",45590:"blake2b-176",45591:"blake2b-184",45592:"blake2b-192",45593:"blake2b-200",45594:"blake2b-208",45595:"blake2b-216",45596:"blake2b-224",45597:"blake2b-232",45598:"blake2b-240",45599:"blake2b-248",45600:"blake2b-256",45601:"blake2b-264",45602:"blake2b-272",45603:"blake2b-280",45604:"blake2b-288",45605:"blake2b-296",45606:"blake2b-304",45607:"blake2b-312",45608:"blake2b-320",45609:"blake2b-328",45610:"blake2b-336",45611:"blake2b-344",45612:"blake2b-352",45613:"blake2b-360",45614:"blake2b-368",45615:"blake2b-376",45616:"blake2b-384",45617:"blake2b-392",45618:"blake2b-400",45619:"blake2b-408",45620:"blake2b-416",45621:"blake2b-424",45622:"blake2b-432",45623:"blake2b-440",45624:"blake2b-448",45625:"blake2b-456",45626:"blake2b-464",45627:"blake2b-472",45628:"blake2b-480",45629:"blake2b-488",45630:"blake2b-496",45631:"blake2b-504",45632:"blake2b-512",45633:"blake2s-8",45634:"blake2s-16",45635:"blake2s-24",45636:"blake2s-32",45637:"blake2s-40",45638:"blake2s-48",45639:"blake2s-56",45640:"blake2s-64",45641:"blake2s-72",45642:"blake2s-80",45643:"blake2s-88",45644:"blake2s-96",45645:"blake2s-104",45646:"blake2s-112",45647:"blake2s-120",45648:"blake2s-128",45649:"blake2s-136",45650:"blake2s-144",45651:"blake2s-152",45652:"blake2s-160",45653:"blake2s-168",45654:"blake2s-176",45655:"blake2s-184",45656:"blake2s-192",45657:"blake2s-200",45658:"blake2s-208",45659:"blake2s-216",45660:"blake2s-224",45661:"blake2s-232",45662:"blake2s-240",45663:"blake2s-248",45664:"blake2s-256",45825:"Skein256-8",45826:"Skein256-16",45827:"Skein256-24",45828:"Skein256-32",45829:"Skein256-40",45830:"Skein256-48",45831:"Skein256-56",45832:"Skein256-64",45833:"Skein256-72",45834:"Skein256-80",45835:"Skein256-88",45836:"Skein256-96",45837:"Skein256-104",45838:"Skein256-112",45839:"Skein256-120",45840:"Skein256-128",45841:"Skein256-136",45842:"Skein256-144",45843:"Skein256-152",45844:"Skein256-160",45845:"Skein256-168",45846:"Skein256-176",45847:"Skein256-184",45848:"Skein256-192",45849:"Skein256-200",45850:"Skein256-208",45851:"Skein256-216",45852:"Skein256-224",45853:"Skein256-232",45854:"Skein256-240",45855:"Skein256-248",45856:"Skein256-256",45857:"Skein512-8",45858:"Skein512-16",45859:"Skein512-24",45860:"Skein512-32",45861:"Skein512-40",45862:"Skein512-48",45863:"Skein512-56",45864:"Skein512-64",45865:"Skein512-72",45866:"Skein512-80",45867:"Skein512-88",45868:"Skein512-96",45869:"Skein512-104",45870:"Skein512-112",45871:"Skein512-120",45872:"Skein512-128",45873:"Skein512-136",45874:"Skein512-144",45875:"Skein512-152",45876:"Skein512-160",45877:"Skein512-168",45878:"Skein512-176",45879:"Skein512-184",45880:"Skein512-192",45881:"Skein512-200",45882:"Skein512-208",45883:"Skein512-216",45884:"Skein512-224",45885:"Skein512-232",45886:"Skein512-240",45887:"Skein512-248",45888:"Skein512-256",45889:"Skein512-264",45890:"Skein512-272",45891:"Skein512-280",45892:"Skein512-288",45893:"Skein512-296",45894:"Skein512-304",45895:"Skein512-312",45896:"Skein512-320",45897:"Skein512-328",45898:"Skein512-336",45899:"Skein512-344",45900:"Skein512-352",45901:"Skein512-360",45902:"Skein512-368",45903:"Skein512-376",45904:"Skein512-384",45905:"Skein512-392",45906:"Skein512-400",45907:"Skein512-408",45908:"Skein512-416",45909:"Skein512-424",45910:"Skein512-432",45911:"Skein512-440",45912:"Skein512-448",45913:"Skein512-456",45914:"Skein512-464",45915:"Skein512-472",45916:"Skein512-480",45917:"Skein512-488",45918:"Skein512-496",45919:"Skein512-504",45920:"Skein512-512",45921:"Skein1024-8",45922:"Skein1024-16",45923:"Skein1024-24",45924:"Skein1024-32",45925:"Skein1024-40",45926:"Skein1024-48",45927:"Skein1024-56",45928:"Skein1024-64",45929:"Skein1024-72",45930:"Skein1024-80",45931:"Skein1024-88",45932:"Skein1024-96",45933:"Skein1024-104",45934:"Skein1024-112",45935:"Skein1024-120",45936:"Skein1024-128",45937:"Skein1024-136",45938:"Skein1024-144",45939:"Skein1024-152",45940:"Skein1024-160",45941:"Skein1024-168",45942:"Skein1024-176",45943:"Skein1024-184",45944:"Skein1024-192",45945:"Skein1024-200",45946:"Skein1024-208",45947:"Skein1024-216",45948:"Skein1024-224",45949:"Skein1024-232",45950:"Skein1024-240",45951:"Skein1024-248",45952:"Skein1024-256",45953:"Skein1024-264",45954:"Skein1024-272",45955:"Skein1024-280",45956:"Skein1024-288",45957:"Skein1024-296",45958:"Skein1024-304",45959:"Skein1024-312",45960:"Skein1024-320",45961:"Skein1024-328",45962:"Skein1024-336",45963:"Skein1024-344",45964:"Skein1024-352",45965:"Skein1024-360",45966:"Skein1024-368",45967:"Skein1024-376",45968:"Skein1024-384",45969:"Skein1024-392",45970:"Skein1024-400",45971:"Skein1024-408",45972:"Skein1024-416",45973:"Skein1024-424",45974:"Skein1024-432",45975:"Skein1024-440",45976:"Skein1024-448",45977:"Skein1024-456",45978:"Skein1024-464",45979:"Skein1024-472",45980:"Skein1024-480",45981:"Skein1024-488",45982:"Skein1024-496",45983:"Skein1024-504",45984:"Skein1024-512",45985:"Skein1024-520",45986:"Skein1024-528",45987:"Skein1024-536",45988:"Skein1024-544",45989:"Skein1024-552",45990:"Skein1024-560",45991:"Skein1024-568",45992:"Skein1024-576",45993:"Skein1024-584",45994:"Skein1024-592",45995:"Skein1024-600",45996:"Skein1024-608",45997:"Skein1024-616",45998:"Skein1024-624",45999:"Skein1024-632",46e3:"Skein1024-640",46001:"Skein1024-648",46002:"Skein1024-656",46003:"Skein1024-664",46004:"Skein1024-672",46005:"Skein1024-680",46006:"Skein1024-688",46007:"Skein1024-696",46008:"Skein1024-704",46009:"Skein1024-712",46010:"Skein1024-720",46011:"Skein1024-728",46012:"Skein1024-736",46013:"Skein1024-744",46014:"Skein1024-752",46015:"Skein1024-760",46016:"Skein1024-768",46017:"Skein1024-776",46018:"Skein1024-784",46019:"Skein1024-792",46020:"Skein1024-800",46021:"Skein1024-808",46022:"Skein1024-816",46023:"Skein1024-824",46024:"Skein1024-832",46025:"Skein1024-840",46026:"Skein1024-848",46027:"Skein1024-856",46028:"Skein1024-864",46029:"Skein1024-872",46030:"Skein1024-880",46031:"Skein1024-888",46032:"Skein1024-896",46033:"Skein1024-904",46034:"Skein1024-912",46035:"Skein1024-920",46036:"Skein1024-928",46037:"Skein1024-936",46038:"Skein1024-944",46039:"Skein1024-952",46040:"Skein1024-960",46041:"Skein1024-968",46042:"Skein1024-976",46043:"Skein1024-984",46044:"Skein1024-992",46045:"Skein1024-1000",46046:"Skein1024-1008",46047:"Skein1024-1016",46048:"Skein1024-1024"}),e.defaultLengths=Object.freeze({17:20,18:32,19:64,23:28,22:32,21:48,20:64,24:32,25:64,26:28,27:32,28:48,29:64,34:32,45569:1,45570:2,45571:3,45572:4,45573:5,45574:6,45575:7,45576:8,45577:9,45578:10,45579:11,45580:12,45581:13,45582:14,45583:15,45584:16,45585:17,45586:18,45587:19,45588:20,45589:21,45590:22,45591:23,45592:24,45593:25,45594:26,45595:27,45596:28,45597:29,45598:30,45599:31,45600:32,45601:33,45602:34,45603:35,45604:36,45605:37,45606:38,45607:39,45608:40,45609:41,45610:42,45611:43,45612:44,45613:45,45614:46,45615:47,45616:48,45617:49,45618:50,45619:51,45620:52,45621:53,45622:54,45623:55,45624:56,45625:57,45626:58,45627:59,45628:60,45629:61,45630:62,45631:63,45632:64,45633:1,45634:2,45635:3,45636:4,45637:5,45638:6,45639:7,45640:8,45641:9,45642:10,45643:11,45644:12,45645:13,45646:14,45647:15,45648:16,45649:17,45650:18,45651:19,45652:20,45653:21,45654:22,45655:23,45656:24,45657:25,45658:26,45659:27,45660:28,45661:29,45662:30,45663:31,45664:32,45825:1,45826:2,45827:3,45828:4,45829:5,45830:6,45831:7,45832:8,45833:9,45834:10,45835:11,45836:12,45837:13,45838:14,45839:15,45840:16,45841:17,45842:18,45843:19,45844:20,45845:21,45846:22,45847:23,45848:24,45849:25,45850:26,45851:27,45852:28,45853:29,45854:30,45855:31,45856:32,45857:1,45858:2,45859:3,45860:4,45861:5,45862:6,45863:7,45864:8,45865:9,45866:10,45867:11,45868:12,45869:13,45870:14,45871:15,45872:16,45873:17,45874:18,45875:19,45876:20,45877:21,45878:22,45879:23,45880:24,45881:25,45882:26,45883:27,45884:28,45885:29,45886:30,45887:31,45888:32,45889:33,45890:34,45891:35,45892:36,45893:37,45894:38,45895:39,45896:40,45897:41,45898:42,45899:43,45900:44,45901:45,45902:46,45903:47,45904:48,45905:49,45906:50,45907:51,45908:52,45909:53,45910:54,45911:55,45912:56,45913:57,45914:58,45915:59,45916:60,45917:61,45918:62,45919:63,45920:64,45921:1,45922:2,45923:3,45924:4,45925:5,45926:6,45927:7,45928:8,45929:9,45930:10,45931:11,45932:12,45933:13,45934:14,45935:15,45936:16,45937:17,45938:18,45939:19,45940:20,45941:21,45942:22,45943:23,45944:24,45945:25,45946:26,45947:27,45948:28,45949:29,45950:30,45951:31,45952:32,45953:33,45954:34,45955:35,45956:36,45957:37,45958:38,45959:39,45960:40,45961:41,45962:42,45963:43,45964:44,45965:45,45966:46,45967:47,45968:48,45969:49,45970:50,45971:51,45972:52,45973:53,45974:54,45975:55,45976:56,45977:57,45978:58,45979:59,45980:60,45981:61,45982:62,45983:63,45984:64,45985:65,45986:66,45987:67,45988:68,45989:69,45990:70,45991:71,45992:72,45993:73,45994:74,45995:75,45996:76,45997:77,45998:78,45999:79,46e3:80,46001:81,46002:82,46003:83,46004:84,46005:85,46006:86,46007:87,46008:88,46009:89,46010:90,46011:91,46012:92,46013:93,46014:94,46015:95,46016:96,46017:97,46018:98,46019:99,46020:100,46021:101,46022:102,46023:103,46024:104,46025:105,46026:106,46027:107,46028:108,46029:109,46030:110,46031:111,46032:112,46033:113,46034:114,46035:115,46036:116,46037:117,46038:118,46039:119,46040:120,46041:121,46042:122,46043:123,46044:124,46045:125,46046:126,46047:127,46048:128})},function(t,e,n){t.exports={encode:n(182),decode:n(183),encodingLength:n(184)}},function(t,e){function n(t,e,s){e=e||[];for(var a=s=s||0;t>=o;)e[s++]=255&t|r,t/=128;for(;t&i;)e[s++]=255&t|r,t>>>=7;return e[s]=0|t,n.bytes=s-a+1,e}t.exports=n;var r=128,i=-128,o=Math.pow(2,31)},function(t,e){function n(t,e){var o,s=0,a=0,c=e=e||0,f=t.length;do{if(c>=f)throw n.bytes=0,new RangeError("Could not decode varint");o=t[c++],s+=a<28?(o&i)<=r);return n.bytes=c-e,s}t.exports=n;var r=128,i=127},function(t,e){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),o=Math.pow(2,28),s=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),f=Math.pow(2,56),u=Math.pow(2,63);t.exports=function(t){return t 0) { - logger.debug(`Send latest heads:\n`, JSON.stringify(heads, null, 2)) + logger.debug(`Send latest heads of '${address}':\n`, JSON.stringify(heads, null, 2)) room.sendTo(peer, new Buffer(JSON.stringify(heads))) } store.events.emit('peer', peer) diff --git a/test/replicate-automatically.test.js b/test/replicate-automatically.test.js index eb6908e..39c44c9 100644 --- a/test/replicate-automatically.test.js +++ b/test/replicate-automatically.test.js @@ -17,7 +17,7 @@ const ipfsPath2 = './orbitdb/tests/replicate-automatically/2/ipfs' describe('orbit-db - Automatic Replication', function() { this.timeout(config.timeout) - let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2 + let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2, db3, db4 before(async () => { config.daemon1.repo = ipfsPath1 @@ -28,6 +28,9 @@ describe('orbit-db - Automatic Replication', function() { rmrf.sync(dbPath2) ipfs1 = await startIpfs(config.daemon1) ipfs2 = await startIpfs(config.daemon2) + // Connect the peers manually to speed up test times + await ipfs2.swarm.connect(ipfs1._peerInfo.multiaddrs._multiaddrs[0].toString()) + await ipfs1.swarm.connect(ipfs2._peerInfo.multiaddrs._multiaddrs[0].toString()) orbitdb1 = new OrbitDB(ipfs1, dbPath1) orbitdb2 = new OrbitDB(ipfs2, dbPath2) }) @@ -56,11 +59,14 @@ describe('orbit-db - Automatic Replication', function() { options = Object.assign({}, options, { path: dbPath1 }) db1 = await orbitdb1.eventlog('replicate-automatically-tests', options) + db3 = await orbitdb1.keyvalue('replicate-automatically-tests-kv', options) }) afterEach(async () => { - await db1.drop() - await db2.drop() + if (db1) await db1.drop() + if (db2) await db2.drop() + if (db3) await db3.drop() + if (db4) await db4.drop() }) it('starts replicating the database when peers connect', async () => { @@ -97,4 +103,56 @@ describe('orbit-db - Automatic Replication', function() { }) }) }) + + it('automatic replication exchanges the correct heads', async () => { + const entryCount = 33 + const entryArr = [] + let options = {} + let timer + + // Create the entries in the first database + for (let i = 0; i < entryCount; i ++) + entryArr.push(i) + + await mapSeries(entryArr, (i) => db1.add('hello' + i)) + + // Open the second database + options = Object.assign({}, options, { path: dbPath2, sync: true }) + db2 = await orbitdb2.eventlog(db1.address.toString(), options) + db4 = await orbitdb2.keyvalue(db3.address.toString(), options) + + // Listen for the 'replicated' events and check that all the entries + // were replicated to the second database + return new Promise(async (resolve, reject) => { + db4.events.on('replicated', (address, hash, entry) => { + reject(new Error("Should not receive the 'replicated' event!")) + }) + + // Can't check this for now as db1 might've sent the heads to db2 + // before we subscribe to the event + // db2.events.on('replicate.progress', (address, hash, entry) => { + // try { + // // Check that the head we received from the first peer is the latest + // assert.equal(entry.payload.value, 'hello' + (entryCount - 1)) + // assert.equal(entry.clock.time, entryCount) + // } catch (e) { + // reject(e) + // } + // }) + + db2.events.on('replicated', (address) => { + try { + const result1 = db1.iterator({ limit: -1 }).collect() + const result2 = db2.iterator({ limit: -1 }).collect() + // Make sure we have all the entries + if (result1.length === entryCount && result2.length === entryCount) { + assert.deepEqual(result1, result2) + resolve() + } + } catch (e) { + reject(e) + } + }) + }) + }) }) diff --git a/test/utils/config.js b/test/utils/config.js index 90e3926..bc49962 100644 --- a/test/utils/config.js +++ b/test/utils/config.js @@ -16,7 +16,7 @@ module.exports = { Discovery: { MDNS: { Enabled: true, - Interval: 10 + Interval: 1 }, webRTCStar: { Enabled: false @@ -40,7 +40,7 @@ module.exports = { Discovery: { MDNS: { Enabled: true, - Interval: 10 + Interval: 1 }, webRTCStar: { Enabled: false @@ -64,7 +64,7 @@ module.exports = { Discovery: { MDNS: { Enabled: true, - Interval: 10 + Interval: 1 }, webRTCStar: { Enabled: false