From 6061b8cb53a98aebb2c9aa9a0920d22871ad15bc Mon Sep 17 00:00:00 2001 From: haad Date: Mon, 11 Dec 2017 19:48:20 +0100 Subject: [PATCH] Fix replication Add tests to make sure a database can be saved and loaded multiple times in a row Add a test to make sure the correct replication progress is emitted Add mem-store for faster development testing Improve tests Improve logging Fix replication benchmark Update packages and build --- benchmarks/benchmark-replication.js | 9 +- dist/es5/OrbitDB.js | 8 +- dist/orbitdb.min.js | 2 +- examples/browser/example.js | 4 +- package-lock.json | 298 +++++++++-------- package.json | 2 +- src/OrbitDB.js | 4 +- test/create-open.test.js | 2 +- test/mocha.opts | 3 +- test/persistency.js | 43 +++ test/replicate-automatically.test.js | 13 +- test/replicate.test.js | 476 ++++++++++++++++++++++++--- test/utils/mem-store.js | 95 ++++++ test/write-permissions.test.js | 17 +- 14 files changed, 774 insertions(+), 202 deletions(-) create mode 100644 test/utils/mem-store.js diff --git a/benchmarks/benchmark-replication.js b/benchmarks/benchmark-replication.js index dac3105..dbaddda 100644 --- a/benchmarks/benchmark-replication.js +++ b/benchmarks/benchmark-replication.js @@ -67,7 +67,7 @@ const queryLoop = async (db) => { try { await db.add(metrics1.totalQueries) } catch (e) { - console.error("!!", e) + console.error(e) } metrics1.totalQueries ++ metrics1.lastTenSeconds ++ @@ -89,7 +89,7 @@ const outputMetrics = (name, db, metrics) => { } const database = 'benchmark-replication' -const updateCount = 2000 +const updateCount = 20000 // Start console.log("Starting IPFS daemons...") @@ -139,8 +139,7 @@ pMapSeries([conf1, conf2], d => startIpfs(d)) let prevCount = 0 setInterval(() => { try { - const result = db2.iterator({ limit: -1 }).collect() - metrics2.totalQueries = result.length + metrics2.totalQueries = db2._oplog.length metrics2.queriesPerSecond = metrics2.totalQueries - prevCount metrics2.lastTenSeconds += metrics2.queriesPerSecond prevCount = metrics2.totalQueries @@ -152,7 +151,7 @@ pMapSeries([conf1, conf2], d => startIpfs(d)) process.exit(0) } } catch (e) { - console.error("!", e) + console.error(e) } }, 1000) } diff --git a/dist/es5/OrbitDB.js b/dist/es5/OrbitDB.js index 030ec87..57ad790 100644 --- a/dist/es5/OrbitDB.js +++ b/dist/es5/OrbitDB.js @@ -213,7 +213,9 @@ var OrbitDB = function () { value: async function _onMessage(address, heads) { var store = this.stores[address]; try { - logger.debug('Received heads for \'' + address + '\':\n', (0, _stringify2.default)(heads, null, 2)); + logger.debug('Received ' + heads.length + ' heads for \'' + address + '\':\n', (0, _stringify2.default)(heads.map(function (e) { + return e.hash; + }), null, 2)); await store.sync(heads); } catch (e) { logger.error(e); @@ -231,7 +233,9 @@ 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 of \'' + address + '\':\n', (0, _stringify2.default)(heads, null, 2)); + logger.debug('Send latest heads of \'' + address + '\':\n', (0, _stringify2.default)(heads.map(function (e) { + return e.hash; + }), null, 2)); room.sendTo(peer, (0, _stringify2.default)(heads)); } store.events.emit('peer', peer); diff --git a/dist/orbitdb.min.js b/dist/orbitdb.min.js index 3faad6d..fdc20bd 100644 --- a/dist/orbitdb.min.js +++ b/dist/orbitdb.min.js @@ -1 +1 @@ -var OrbitDB=function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=69)}([function(e,t){function r(){throw new Error("setTimeout has not been defined")}function n(){throw new Error("clearTimeout has not been defined")}function i(e){if(f===setTimeout)return setTimeout(e,0);if((f===r||!f)&&setTimeout)return f=setTimeout,setTimeout(e,0);try{return f(e,0)}catch(t){try{return f.call(null,e,0)}catch(t){return f.call(this,e,0)}}}function o(){p&&d&&(p=!1,d.length?l=d.concat(l):b=-1,l.length&&s())}function s(){if(!p){var e=i(o);p=!0;for(var t=l.length;t;){for(d=l,l=[];++b1)for(var r=1;r=n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n().toString(16)+" bytes");return 0|e}function h(e,t){if(o.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return N(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return R(e).length;default:if(n)return N(e).length;t=(""+t).toLowerCase(),n=!0}}function d(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,t>>>=0,r<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return function(e,t,r){var n=e.length;(!t||t<0)&&(t=0);(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:b(e,t,r,n,i);if("number"==typeof t)return t&=255,o.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):b(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(e,t,r,n,i){function o(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}var s=1,a=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,r/=2}var f;if(i){var u=-1;for(f=r;fa&&(r=a-c),f=r;f>=0;f--){for(var h=!0,d=0;di&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function S(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i239?4:o>223?3:o>191?2:1;if(i+a<=r){var c,f,u,h;switch(a){case 1:o<128&&(s=o);break;case 2:128==(192&(c=e[i+1]))&&(h=(31&o)<<6|63&c)>127&&(s=h);break;case 3:c=e[i+1],f=e[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=e[i+1],f=e[i+2],u=e[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,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return function(e){var t=e.length;if(t<=L)return String.fromCharCode.apply(String,e);var r="",n=0;for(;nr)throw new RangeError("Trying to access beyond buffer length")}function E(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}function x(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i>>8*(n?i:1-i)}function M(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i>>8*(n?i:3-i)&255}function A(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function O(e,t,r,n,i){return i||A(e,0,r,4),j.write(e,t,r,n,23,4),r+4}function I(e,t,r,n,i){return i||A(e,0,r,8),j.write(e,t,r,n,52,8),r+8}function N(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],s=0;s55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function R(e){return C.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(B,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function P(e,t,r,n){for(var i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}var C=r(70),j=r(71),T=r(35);t.Buffer=o,t.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},t.INSPECT_MAX_BYTES=50,o.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=n(),o.poolSize=8192,o._augment=function(e){return e.__proto__=o.prototype,e},o.from=function(e,t,r){return s(null,e,t,r)},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(e,t,r){return function(e,t,r,n){return a(t),t<=0?i(e,t):void 0!==r?"string"==typeof n?i(e,t).fill(r,n):i(e,t).fill(r):i(e,t)}(null,e,t,r)},o.allocUnsafe=function(e){return c(null,e)},o.allocUnsafeSlow=function(e){return c(null,e)},o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,s=Math.min(r,n);i0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),""},o.prototype.compare=function(e,t,r,n,i){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,i>>>=0,this===e)return 0;for(var s=i-n,a=r-t,c=Math.min(s,a),f=this.slice(n,i),u=e.slice(t,r),h=0;hi)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return y(this,e,t,r);case"utf8":case"utf-8":return g(this,e,t,r);case"ascii":return m(this,e,t,r);case"latin1":case"binary":return v(this,e,t,r);case"base64":return _(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).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(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,e<0?(e+=r)<0&&(e=0):e>r&&(e=r),t<0?(t+=r)<0&&(t=0):t>r&&(t=r),t0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUInt8=function(e,t){return t||k(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||k(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||k(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||k(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||k(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e],i=1,o=0;++o=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||k(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){t||k(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){t||k(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return t||k(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||k(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||k(e,4,this.length),j.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||k(e,4,this.length),j.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||k(e,8,this.length),j.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||k(e,8,this.length),j.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t|=0,r|=0,!n){E(this,e,t,r,Math.pow(2,8*r)-1,0)}var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+r},o.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):x(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):x(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):M(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);E(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o>0)-a&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);E(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):x(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):x(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):M(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,r){return O(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return O(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return I(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return I(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t=0;--i)e[i+t]=this[i+r];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,e||(e=0);var s;if("number"==typeof e)for(s=t;s0&&this._events[e].length>s&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,o,s,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],s=r.length,o=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(a=s;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){o=a;break}if(o<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,r){"use strict";var n=t;n.version=r(85).version,n.utils=r(86),n.rand=r(88),n.curve=r(22),n.curves=r(94),n.ec=r(102),n.eddsa=r(106)},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},function(e,t,r){"use strict";function n(e){return(e>>>24|e>>>8&65280|e<<8&16711680|(255&e)<<24)>>>0}function i(e){return 1===e.length?"0"+e:e}function o(e){return 7===e.length?"0"+e:6===e.length?"00"+e:5===e.length?"000"+e:4===e.length?"0000"+e:3===e.length?"00000"+e:2===e.length?"000000"+e:1===e.length?"0000000"+e:e}var s=r(11),a=r(4);t.inherits=a,t.toArray=function(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];var r=[];if("string"==typeof e)if(t){if("hex"===t)for((e=e.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(e="0"+e),n=0;n>8,s=255&i;o?r.push(o,s):r.push(s)}else for(n=0;n>>0}return o},t.split32=function(e,t){for(var r=new Array(4*e.length),n=0,i=0;n>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=255&o):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=255&o)}return r},t.rotr32=function(e,t){return e>>>t|e<<32-t},t.rotl32=function(e,t){return e<>>32-t},t.sum32=function(e,t){return e+t>>>0},t.sum32_3=function(e,t,r){return e+t+r>>>0},t.sum32_4=function(e,t,r,n){return e+t+r+n>>>0},t.sum32_5=function(e,t,r,n,i){return e+t+r+n+i>>>0},t.sum64=function(e,t,r,n){var i=e[t],o=n+e[t+1]>>>0,s=(o>>0,e[t+1]=o},t.sum64_hi=function(e,t,r,n){return(t+n>>>0>>0},t.sum64_lo=function(e,t,r,n){return t+n>>>0},t.sum64_4_hi=function(e,t,r,n,i,o,s,a){var c=0,f=t;return c+=(f=f+n>>>0)>>0)>>0)>>0},t.sum64_4_lo=function(e,t,r,n,i,o,s,a){return t+n+o+a>>>0},t.sum64_5_hi=function(e,t,r,n,i,o,s,a,c,f){var u=0,h=t;return u+=(h=h+n>>>0)>>0)>>0)>>0)>>0},t.sum64_5_lo=function(e,t,r,n,i,o,s,a,c,f){return t+n+o+a+f>>>0},t.rotr64_hi=function(e,t,r){return(t<<32-r|e>>>r)>>>0},t.rotr64_lo=function(e,t,r){return(e<<32-r|t>>>r)>>>0},t.shr64_hi=function(e,t,r){return e>>>r},t.shr64_lo=function(e,t,r){return(e<<32-r|t>>>r)>>>0}},function(e,t,r){(function(e,n){function i(e,r){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),h(r)?n.showHidden=r:r&&t._extend(n,r),b(n.showHidden)&&(n.showHidden=!1),b(n.depth)&&(n.depth=2),b(n.colors)&&(n.colors=!1),b(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),a(n,e,n.depth)}function o(e,t){var r=i.styles[t];return r?"["+i.colors[r][0]+"m"+e+"["+i.colors[r][1]+"m":e}function s(e,t){return e}function a(e,r,n){if(e.customInspect&&r&&_(r.inspect)&&r.inspect!==t.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,e);return p(i)||(i=a(e,i,n)),i}var o=function(e,t){if(b(t))return e.stylize("undefined","undefined");if(p(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(l(t))return e.stylize(""+t,"number");if(h(t))return e.stylize(""+t,"boolean");if(d(t))return e.stylize("null","null")}(e,r);if(o)return o;var s=Object.keys(r),g=function(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(r)),v(r)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return c(r);if(0===s.length){if(_(r)){var w=r.name?": "+r.name:"";return e.stylize("[Function"+w+"]","special")}if(y(r))return e.stylize(RegExp.prototype.toString.call(r),"regexp");if(m(r))return e.stylize(Date.prototype.toString.call(r),"date");if(v(r))return c(r)}var S="",E=!1,x=["{","}"];if(u(r)&&(E=!0,x=["[","]"]),_(r)){S=" [Function"+(r.name?": "+r.name:"")+"]"}if(y(r)&&(S=" "+RegExp.prototype.toString.call(r)),m(r)&&(S=" "+Date.prototype.toUTCString.call(r)),v(r)&&(S=" "+c(r)),0===s.length&&(!E||0==r.length))return x[0]+S+x[1];if(n<0)return y(r)?e.stylize(RegExp.prototype.toString.call(r),"regexp"):e.stylize("[Object]","special");e.seen.push(r);var M;return M=E?function(e,t,r,n,i){for(var o=[],s=0,a=t.length;s=0&&n++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(M,S,x)}function c(e){return"["+Error.prototype.toString.call(e)+"]"}function f(e,t,r,n,i,o){var s,c,f;if((f=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?c=f.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):f.set&&(c=e.stylize("[Setter]","special")),k(n,i)||(s="["+i+"]"),c||(e.seen.indexOf(f.value)<0?(c=d(r)?a(e,f.value,null):a(e,f.value,r-1)).indexOf("\n")>-1&&(c=o?c.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+c.split("\n").map(function(e){return" "+e}).join("\n")):c=e.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=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+c}function u(e){return Array.isArray(e)}function h(e){return"boolean"==typeof e}function d(e){return null===e}function l(e){return"number"==typeof e}function p(e){return"string"==typeof e}function b(e){return void 0===e}function y(e){return g(e)&&"[object RegExp]"===w(e)}function g(e){return"object"==typeof e&&null!==e}function m(e){return g(e)&&"[object Date]"===w(e)}function v(e){return g(e)&&("[object Error]"===w(e)||e instanceof Error)}function _(e){return"function"==typeof e}function w(e){return Object.prototype.toString.call(e)}function S(e){return e<10?"0"+e.toString(10):e.toString(10)}function k(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var E=/%[sdj%]/g;t.format=function(e){if(!p(e)){for(var t=[],r=0;r=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return e}}),a=n[r];r=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function a(e,t,r,n){for(var i=0,o=Math.min(e.length,r),s=t;s=49?a-49+10:a>=17?a-17+10:a}return i}function c(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var i=0|e.words[0],o=0|t.words[0],s=i*o,a=67108863&s,c=s/67108864|0;r.words[0]=a;for(var f=1;f>>26,h=67108863&c,d=Math.min(f,t.length-1),l=Math.max(0,f-e.length+1);l<=d;l++){var p=f-l|0;u+=(s=(i=0|e.words[p])*(o=0|t.words[l])+h)/67108864|0,h=67108863&s}r.words[f]=0|h,c=0|u}return 0!==c?r.words[f]=0|c:r.length--,r.strip()}function f(e,t,r){return(new u).mulp(e,t,r)}function u(e,t){this.x=e,this.y=t}function h(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function 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(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function g(e){y.call(this,e),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 e?e.exports=o:t.BN=o,o.BN=o,o.wordSize=26;var m;try{m=r(87).Buffer}catch(e){}o.isBN=function(e){return e instanceof o||null!==e&&"object"==typeof e&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return e.cmp(t)>0?e:t},o.min=function(e,t){return e.cmp(t)<0?e:t},o.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&t>=2&&t<=36);var i=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&i++,16===t?this._parseHex(e,i):this._parseBase(e,t,i),"-"===e[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),t,r)},o.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},o.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var i=0;i=0;i-=3)s=e[i]|e[i-1]<<8|e[i-2]<<16,this.words[o]|=s<>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===r)for(i=0,o=0;i>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this.strip()},o.prototype._parseHex=function(e,t){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var r=0;r=t;r-=6)i=s(e,r,r+6),this.words[n]|=i<>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);r+6!==t&&(i=s(e,t,r+6),this.words[n]|=i<>>26-o&4194303),this.strip()},o.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=t)n++;n--,i=i/t|0;for(var o=e.length-r,s=o%n,c=Math.min(o,o-s)+r,f=0,u=r;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(e,t){e=e||10,t=0|t||1;var r;if(16===e||"hex"===e){r="";for(var i=0,o=0,s=0;s>>24-i&16777215)||s!==this.length-1?v[6-c.length]+c+r:c+r,(i+=2)>=26&&(i-=26,s--)}for(0!==o&&(r=o.toString(16)+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(e===(0|e)&&e>=2&&e<=36){var f=_[e],u=w[e];r="";var h=this.clone();for(h.negative=0;!h.isZero();){var d=h.modn(u).toString(e);r=(h=h.idivn(u)).isZero()?d+r:v[f-d.length]+d+r}for(this.isZero()&&(r="0"+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(e,t){return n(void 0!==m),this.toArrayLike(m,e,t)},o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,r){var i=this.byteLength(),o=r||Math.max(1,i);n(i<=o,"byte array longer than desired length"),n(o>0,"Requested array length <= 0"),this.strip();var s,a,c="le"===t,f=new e(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&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;te.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;re.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;ne.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){n("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var i=0;i0&&(this.words[i]=~this.words[i]&67108863>>26-r),this.strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){n("number"==typeof e&&e>=0);var r=e/26|0,i=e%26;return this._expand(r+1),this.words[r]=t?this.words[r]|1<e.length?(r=this,n=e):(r=e,n=this);for(var i=0,o=0;o>>26;for(;0!==i&&o>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;oe.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r=this.cmp(e);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;var n,i;r>0?(n=this,i=e):(n=e,i=this);for(var o=0,s=0;s>26,this.words[s]=67108863&t;for(;0!==o&&s>26,this.words[s]=67108863&t;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,E=S>>>13,x=0|s[5],M=8191&x,A=x>>>13,O=0|s[6],I=8191&O,N=O>>>13,R=0|s[7],P=8191&R,C=R>>>13,j=0|s[8],T=8191&j,L=j>>>13,B=0|s[9],D=8191&B,q=B>>>13,F=0|a[0],z=8191&F,U=F>>>13,K=0|a[1],G=8191&K,W=K>>>13,H=0|a[2],Y=8191&H,V=H>>>13,J=0|a[3],$=8191&J,X=J>>>13,Z=0|a[4],Q=8191&Z,ee=Z>>>13,te=0|a[5],re=8191&te,ne=te>>>13,ie=0|a[6],oe=8191&ie,se=ie>>>13,ae=0|a[7],ce=8191&ae,fe=ae>>>13,ue=0|a[8],he=8191&ue,de=ue>>>13,le=0|a[9],pe=8191&le,be=le>>>13;r.negative=e.negative^t.negative,r.length=19;var ye=(f+(n=Math.imul(h,z))|0)+((8191&(i=(i=Math.imul(h,U))+Math.imul(d,z)|0))<<13)|0;f=((o=Math.imul(d,U))+(i>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(p,z),i=(i=Math.imul(p,U))+Math.imul(b,z)|0,o=Math.imul(b,U);var ge=(f+(n=n+Math.imul(h,G)|0)|0)+((8191&(i=(i=i+Math.imul(h,W)|0)+Math.imul(d,G)|0))<<13)|0;f=((o=o+Math.imul(d,W)|0)+(i>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(g,z),i=(i=Math.imul(g,U))+Math.imul(m,z)|0,o=Math.imul(m,U),n=n+Math.imul(p,G)|0,i=(i=i+Math.imul(p,W)|0)+Math.imul(b,G)|0,o=o+Math.imul(b,W)|0;var me=(f+(n=n+Math.imul(h,Y)|0)|0)+((8191&(i=(i=i+Math.imul(h,V)|0)+Math.imul(d,Y)|0))<<13)|0;f=((o=o+Math.imul(d,V)|0)+(i>>>13)|0)+(me>>>26)|0,me&=67108863,n=Math.imul(_,z),i=(i=Math.imul(_,U))+Math.imul(w,z)|0,o=Math.imul(w,U),n=n+Math.imul(g,G)|0,i=(i=i+Math.imul(g,W)|0)+Math.imul(m,G)|0,o=o+Math.imul(m,W)|0,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,V)|0)+Math.imul(b,Y)|0,o=o+Math.imul(b,V)|0;var ve=(f+(n=n+Math.imul(h,$)|0)|0)+((8191&(i=(i=i+Math.imul(h,X)|0)+Math.imul(d,$)|0))<<13)|0;f=((o=o+Math.imul(d,X)|0)+(i>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(k,z),i=(i=Math.imul(k,U))+Math.imul(E,z)|0,o=Math.imul(E,U),n=n+Math.imul(_,G)|0,i=(i=i+Math.imul(_,W)|0)+Math.imul(w,G)|0,o=o+Math.imul(w,W)|0,n=n+Math.imul(g,Y)|0,i=(i=i+Math.imul(g,V)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,V)|0,n=n+Math.imul(p,$)|0,i=(i=i+Math.imul(p,X)|0)+Math.imul(b,$)|0,o=o+Math.imul(b,X)|0;var _e=(f+(n=n+Math.imul(h,Q)|0)|0)+((8191&(i=(i=i+Math.imul(h,ee)|0)+Math.imul(d,Q)|0))<<13)|0;f=((o=o+Math.imul(d,ee)|0)+(i>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(M,z),i=(i=Math.imul(M,U))+Math.imul(A,z)|0,o=Math.imul(A,U),n=n+Math.imul(k,G)|0,i=(i=i+Math.imul(k,W)|0)+Math.imul(E,G)|0,o=o+Math.imul(E,W)|0,n=n+Math.imul(_,Y)|0,i=(i=i+Math.imul(_,V)|0)+Math.imul(w,Y)|0,o=o+Math.imul(w,V)|0,n=n+Math.imul(g,$)|0,i=(i=i+Math.imul(g,X)|0)+Math.imul(m,$)|0,o=o+Math.imul(m,X)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,ee)|0)+Math.imul(b,Q)|0,o=o+Math.imul(b,ee)|0;var we=(f+(n=n+Math.imul(h,re)|0)|0)+((8191&(i=(i=i+Math.imul(h,ne)|0)+Math.imul(d,re)|0))<<13)|0;f=((o=o+Math.imul(d,ne)|0)+(i>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(I,z),i=(i=Math.imul(I,U))+Math.imul(N,z)|0,o=Math.imul(N,U),n=n+Math.imul(M,G)|0,i=(i=i+Math.imul(M,W)|0)+Math.imul(A,G)|0,o=o+Math.imul(A,W)|0,n=n+Math.imul(k,Y)|0,i=(i=i+Math.imul(k,V)|0)+Math.imul(E,Y)|0,o=o+Math.imul(E,V)|0,n=n+Math.imul(_,$)|0,i=(i=i+Math.imul(_,X)|0)+Math.imul(w,$)|0,o=o+Math.imul(w,X)|0,n=n+Math.imul(g,Q)|0,i=(i=i+Math.imul(g,ee)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,ee)|0,n=n+Math.imul(p,re)|0,i=(i=i+Math.imul(p,ne)|0)+Math.imul(b,re)|0,o=o+Math.imul(b,ne)|0;var Se=(f+(n=n+Math.imul(h,oe)|0)|0)+((8191&(i=(i=i+Math.imul(h,se)|0)+Math.imul(d,oe)|0))<<13)|0;f=((o=o+Math.imul(d,se)|0)+(i>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(P,z),i=(i=Math.imul(P,U))+Math.imul(C,z)|0,o=Math.imul(C,U),n=n+Math.imul(I,G)|0,i=(i=i+Math.imul(I,W)|0)+Math.imul(N,G)|0,o=o+Math.imul(N,W)|0,n=n+Math.imul(M,Y)|0,i=(i=i+Math.imul(M,V)|0)+Math.imul(A,Y)|0,o=o+Math.imul(A,V)|0,n=n+Math.imul(k,$)|0,i=(i=i+Math.imul(k,X)|0)+Math.imul(E,$)|0,o=o+Math.imul(E,X)|0,n=n+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,ee)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,ee)|0,n=n+Math.imul(g,re)|0,i=(i=i+Math.imul(g,ne)|0)+Math.imul(m,re)|0,o=o+Math.imul(m,ne)|0,n=n+Math.imul(p,oe)|0,i=(i=i+Math.imul(p,se)|0)+Math.imul(b,oe)|0,o=o+Math.imul(b,se)|0;var ke=(f+(n=n+Math.imul(h,ce)|0)|0)+((8191&(i=(i=i+Math.imul(h,fe)|0)+Math.imul(d,ce)|0))<<13)|0;f=((o=o+Math.imul(d,fe)|0)+(i>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(T,z),i=(i=Math.imul(T,U))+Math.imul(L,z)|0,o=Math.imul(L,U),n=n+Math.imul(P,G)|0,i=(i=i+Math.imul(P,W)|0)+Math.imul(C,G)|0,o=o+Math.imul(C,W)|0,n=n+Math.imul(I,Y)|0,i=(i=i+Math.imul(I,V)|0)+Math.imul(N,Y)|0,o=o+Math.imul(N,V)|0,n=n+Math.imul(M,$)|0,i=(i=i+Math.imul(M,X)|0)+Math.imul(A,$)|0,o=o+Math.imul(A,X)|0,n=n+Math.imul(k,Q)|0,i=(i=i+Math.imul(k,ee)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,ee)|0,n=n+Math.imul(_,re)|0,i=(i=i+Math.imul(_,ne)|0)+Math.imul(w,re)|0,o=o+Math.imul(w,ne)|0,n=n+Math.imul(g,oe)|0,i=(i=i+Math.imul(g,se)|0)+Math.imul(m,oe)|0,o=o+Math.imul(m,se)|0,n=n+Math.imul(p,ce)|0,i=(i=i+Math.imul(p,fe)|0)+Math.imul(b,ce)|0,o=o+Math.imul(b,fe)|0;var Ee=(f+(n=n+Math.imul(h,he)|0)|0)+((8191&(i=(i=i+Math.imul(h,de)|0)+Math.imul(d,he)|0))<<13)|0;f=((o=o+Math.imul(d,de)|0)+(i>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(D,z),i=(i=Math.imul(D,U))+Math.imul(q,z)|0,o=Math.imul(q,U),n=n+Math.imul(T,G)|0,i=(i=i+Math.imul(T,W)|0)+Math.imul(L,G)|0,o=o+Math.imul(L,W)|0,n=n+Math.imul(P,Y)|0,i=(i=i+Math.imul(P,V)|0)+Math.imul(C,Y)|0,o=o+Math.imul(C,V)|0,n=n+Math.imul(I,$)|0,i=(i=i+Math.imul(I,X)|0)+Math.imul(N,$)|0,o=o+Math.imul(N,X)|0,n=n+Math.imul(M,Q)|0,i=(i=i+Math.imul(M,ee)|0)+Math.imul(A,Q)|0,o=o+Math.imul(A,ee)|0,n=n+Math.imul(k,re)|0,i=(i=i+Math.imul(k,ne)|0)+Math.imul(E,re)|0,o=o+Math.imul(E,ne)|0,n=n+Math.imul(_,oe)|0,i=(i=i+Math.imul(_,se)|0)+Math.imul(w,oe)|0,o=o+Math.imul(w,se)|0,n=n+Math.imul(g,ce)|0,i=(i=i+Math.imul(g,fe)|0)+Math.imul(m,ce)|0,o=o+Math.imul(m,fe)|0,n=n+Math.imul(p,he)|0,i=(i=i+Math.imul(p,de)|0)+Math.imul(b,he)|0,o=o+Math.imul(b,de)|0;var xe=(f+(n=n+Math.imul(h,pe)|0)|0)+((8191&(i=(i=i+Math.imul(h,be)|0)+Math.imul(d,pe)|0))<<13)|0;f=((o=o+Math.imul(d,be)|0)+(i>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(D,G),i=(i=Math.imul(D,W))+Math.imul(q,G)|0,o=Math.imul(q,W),n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,V)|0)+Math.imul(L,Y)|0,o=o+Math.imul(L,V)|0,n=n+Math.imul(P,$)|0,i=(i=i+Math.imul(P,X)|0)+Math.imul(C,$)|0,o=o+Math.imul(C,X)|0,n=n+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,ee)|0)+Math.imul(N,Q)|0,o=o+Math.imul(N,ee)|0,n=n+Math.imul(M,re)|0,i=(i=i+Math.imul(M,ne)|0)+Math.imul(A,re)|0,o=o+Math.imul(A,ne)|0,n=n+Math.imul(k,oe)|0,i=(i=i+Math.imul(k,se)|0)+Math.imul(E,oe)|0,o=o+Math.imul(E,se)|0,n=n+Math.imul(_,ce)|0,i=(i=i+Math.imul(_,fe)|0)+Math.imul(w,ce)|0,o=o+Math.imul(w,fe)|0,n=n+Math.imul(g,he)|0,i=(i=i+Math.imul(g,de)|0)+Math.imul(m,he)|0,o=o+Math.imul(m,de)|0;var Me=(f+(n=n+Math.imul(p,pe)|0)|0)+((8191&(i=(i=i+Math.imul(p,be)|0)+Math.imul(b,pe)|0))<<13)|0;f=((o=o+Math.imul(b,be)|0)+(i>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(D,Y),i=(i=Math.imul(D,V))+Math.imul(q,Y)|0,o=Math.imul(q,V),n=n+Math.imul(T,$)|0,i=(i=i+Math.imul(T,X)|0)+Math.imul(L,$)|0,o=o+Math.imul(L,X)|0,n=n+Math.imul(P,Q)|0,i=(i=i+Math.imul(P,ee)|0)+Math.imul(C,Q)|0,o=o+Math.imul(C,ee)|0,n=n+Math.imul(I,re)|0,i=(i=i+Math.imul(I,ne)|0)+Math.imul(N,re)|0,o=o+Math.imul(N,ne)|0,n=n+Math.imul(M,oe)|0,i=(i=i+Math.imul(M,se)|0)+Math.imul(A,oe)|0,o=o+Math.imul(A,se)|0,n=n+Math.imul(k,ce)|0,i=(i=i+Math.imul(k,fe)|0)+Math.imul(E,ce)|0,o=o+Math.imul(E,fe)|0,n=n+Math.imul(_,he)|0,i=(i=i+Math.imul(_,de)|0)+Math.imul(w,he)|0,o=o+Math.imul(w,de)|0;var Ae=(f+(n=n+Math.imul(g,pe)|0)|0)+((8191&(i=(i=i+Math.imul(g,be)|0)+Math.imul(m,pe)|0))<<13)|0;f=((o=o+Math.imul(m,be)|0)+(i>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(D,$),i=(i=Math.imul(D,X))+Math.imul(q,$)|0,o=Math.imul(q,X),n=n+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,ee)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,ee)|0,n=n+Math.imul(P,re)|0,i=(i=i+Math.imul(P,ne)|0)+Math.imul(C,re)|0,o=o+Math.imul(C,ne)|0,n=n+Math.imul(I,oe)|0,i=(i=i+Math.imul(I,se)|0)+Math.imul(N,oe)|0,o=o+Math.imul(N,se)|0,n=n+Math.imul(M,ce)|0,i=(i=i+Math.imul(M,fe)|0)+Math.imul(A,ce)|0,o=o+Math.imul(A,fe)|0,n=n+Math.imul(k,he)|0,i=(i=i+Math.imul(k,de)|0)+Math.imul(E,he)|0,o=o+Math.imul(E,de)|0;var Oe=(f+(n=n+Math.imul(_,pe)|0)|0)+((8191&(i=(i=i+Math.imul(_,be)|0)+Math.imul(w,pe)|0))<<13)|0;f=((o=o+Math.imul(w,be)|0)+(i>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,n=Math.imul(D,Q),i=(i=Math.imul(D,ee))+Math.imul(q,Q)|0,o=Math.imul(q,ee),n=n+Math.imul(T,re)|0,i=(i=i+Math.imul(T,ne)|0)+Math.imul(L,re)|0,o=o+Math.imul(L,ne)|0,n=n+Math.imul(P,oe)|0,i=(i=i+Math.imul(P,se)|0)+Math.imul(C,oe)|0,o=o+Math.imul(C,se)|0,n=n+Math.imul(I,ce)|0,i=(i=i+Math.imul(I,fe)|0)+Math.imul(N,ce)|0,o=o+Math.imul(N,fe)|0,n=n+Math.imul(M,he)|0,i=(i=i+Math.imul(M,de)|0)+Math.imul(A,he)|0,o=o+Math.imul(A,de)|0;var Ie=(f+(n=n+Math.imul(k,pe)|0)|0)+((8191&(i=(i=i+Math.imul(k,be)|0)+Math.imul(E,pe)|0))<<13)|0;f=((o=o+Math.imul(E,be)|0)+(i>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(D,re),i=(i=Math.imul(D,ne))+Math.imul(q,re)|0,o=Math.imul(q,ne),n=n+Math.imul(T,oe)|0,i=(i=i+Math.imul(T,se)|0)+Math.imul(L,oe)|0,o=o+Math.imul(L,se)|0,n=n+Math.imul(P,ce)|0,i=(i=i+Math.imul(P,fe)|0)+Math.imul(C,ce)|0,o=o+Math.imul(C,fe)|0,n=n+Math.imul(I,he)|0,i=(i=i+Math.imul(I,de)|0)+Math.imul(N,he)|0,o=o+Math.imul(N,de)|0;var Ne=(f+(n=n+Math.imul(M,pe)|0)|0)+((8191&(i=(i=i+Math.imul(M,be)|0)+Math.imul(A,pe)|0))<<13)|0;f=((o=o+Math.imul(A,be)|0)+(i>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,n=Math.imul(D,oe),i=(i=Math.imul(D,se))+Math.imul(q,oe)|0,o=Math.imul(q,se),n=n+Math.imul(T,ce)|0,i=(i=i+Math.imul(T,fe)|0)+Math.imul(L,ce)|0,o=o+Math.imul(L,fe)|0,n=n+Math.imul(P,he)|0,i=(i=i+Math.imul(P,de)|0)+Math.imul(C,he)|0,o=o+Math.imul(C,de)|0;var Re=(f+(n=n+Math.imul(I,pe)|0)|0)+((8191&(i=(i=i+Math.imul(I,be)|0)+Math.imul(N,pe)|0))<<13)|0;f=((o=o+Math.imul(N,be)|0)+(i>>>13)|0)+(Re>>>26)|0,Re&=67108863,n=Math.imul(D,ce),i=(i=Math.imul(D,fe))+Math.imul(q,ce)|0,o=Math.imul(q,fe),n=n+Math.imul(T,he)|0,i=(i=i+Math.imul(T,de)|0)+Math.imul(L,he)|0,o=o+Math.imul(L,de)|0;var Pe=(f+(n=n+Math.imul(P,pe)|0)|0)+((8191&(i=(i=i+Math.imul(P,be)|0)+Math.imul(C,pe)|0))<<13)|0;f=((o=o+Math.imul(C,be)|0)+(i>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(D,he),i=(i=Math.imul(D,de))+Math.imul(q,he)|0,o=Math.imul(q,de);var Ce=(f+(n=n+Math.imul(T,pe)|0)|0)+((8191&(i=(i=i+Math.imul(T,be)|0)+Math.imul(L,pe)|0))<<13)|0;f=((o=o+Math.imul(L,be)|0)+(i>>>13)|0)+(Ce>>>26)|0,Ce&=67108863;var je=(f+(n=Math.imul(D,pe))|0)+((8191&(i=(i=Math.imul(D,be))+Math.imul(q,pe)|0))<<13)|0;return f=((o=Math.imul(q,be))+(i>>>13)|0)+(je>>>26)|0,je&=67108863,c[0]=ye,c[1]=ge,c[2]=me,c[3]=ve,c[4]=_e,c[5]=we,c[6]=Se,c[7]=ke,c[8]=Ee,c[9]=xe,c[10]=Me,c[11]=Ae,c[12]=Oe,c[13]=Ie,c[14]=Ne,c[15]=Re,c[16]=Pe,c[17]=Ce,c[18]=je,0!==f&&(c[19]=f,r.length++),r};Math.imul||(S=c),o.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?S(this,e,t):r<63?c(this,e,t):r<1024?function(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,i=0,o=0;o>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r.strip()}(this,e,t):f(this,e,t)},u.prototype.makeRBT=function(e){for(var t=new Array(e),r=o.prototype._countBits(e)-1,n=0;n>=1;return n},u.prototype.permute=function(e,t,r,n,i,o){for(var s=0;s>>=1)i++;return 1<>>=13,r[2*s+1]=8191&o,o>>>=13;for(s=2*t;s>=26,t+=i/67108864|0,t+=o>>>26,this.words[r]=67108863&o}return 0!==t&&(this.words[r]=t,this.length++),this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r>>i}return t}(e);if(0===t.length)return new o(1);for(var r=this,n=0;n=0);var t,r=e%26,i=(e-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(t=0;t>>26-r}s&&(this.words[t]=s,this.length++)}if(0!==i){for(t=this.length-1;t>=0;t--)this.words[t+i]=this.words[t];for(t=0;t=0);var i;i=t?(t-t%26)/26:0;var o=e%26,s=Math.min((e-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(e,t,r){return n(0===this.negative),this.iushrn(e,t,r)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){n("number"==typeof e&&e>=0);var t=e%26,r=(e-t)/26,i=1<=0);var t=e%26,r=(e-t)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==t&&r++,this.length=Math.min(r,this.length),0!==t){var i=67108863^67108863>>>t<=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},o.prototype.isubn=function(e){if(n("number"==typeof e),n(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t>26)-(c/67108864|0),this.words[i+r]=67108863&s}for(;i>26,this.words[i+r]=67108863&s;if(0===a)return this.strip();for(n(-1===a),a=0,i=0;i>26,this.words[i]=67108863&s;return this.negative=1,this.strip()},o.prototype._wordDiv=function(e,t){var r=this.length-e.length,n=this.clone(),i=e,s=0|i.words[i.length-1];0!==(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,c=n.length-i.length;if("mod"!==t){(a=new o(null)).length=c+1,a.words=new Array(a.length);for(var f=0;f=0;h--){var d=67108864*(0|n.words[i.length+h])+(0|n.words[i.length+h-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(i,d,h);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(i,1,h),n.isZero()||(n.negative^=1);a&&(a.words[h]=d)}return a&&a.strip(),n.strip(),"div"!==t&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(e,t,r){if(n(!e.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var i,s,a;return 0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(i=a.div.neg()),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(e)),{div:i,mod:s}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(e)),{div:a.div,mod:s}):e.length>this.length||this.cmp(e)<0?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modn(e.words[0]))}:this._wordDiv(e,t)},o.prototype.div=function(e){return this.divmod(e,"div",!1).div},o.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var r=0!==t.div.negative?t.mod.isub(e):t.mod,n=e.ushrn(1),i=e.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},o.prototype.modn=function(e){n(e<=67108863);for(var t=(1<<26)%e,r=0,i=this.length-1;i>=0;i--)r=(t*r+(0|this.words[i]))%e;return r},o.prototype.idivn=function(e){n(e<=67108863);for(var t=0,r=this.length-1;r>=0;r--){var i=(0|this.words[r])+67108864*t;this.words[r]=i/e|0,t=i%e}return this.strip()},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i=new o(1),s=new o(0),a=new o(0),c=new o(1),f=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++f;for(var u=r.clone(),h=t.clone();!t.isZero();){for(var d=0,l=1;0==(t.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(t.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==(r.words[0]&b)&&p<26;++p,b<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||c.isOdd())&&(a.iadd(u),c.isub(h)),a.iushrn(1),c.iushrn(1);t.cmp(r)>=0?(t.isub(r),i.isub(a),s.isub(c)):(r.isub(t),a.isub(i),c.isub(s))}return{a:a,b:c,gcd:r.iushln(f)}},o.prototype._invmp=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i=new o(1),s=new o(0),a=r.clone();t.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,f=1;0==(t.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(t.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(a),i.iushrn(1);for(var u=0,h=1;0==(r.words[0]&h)&&u<26;++u,h<<=1);if(u>0)for(r.iushrn(u);u-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);t.cmp(r)>=0?(t.isub(r),i.isub(s)):(r.isub(t),s.isub(i))}var d;return(d=0===t.cmpn(1)?i:s).cmpn(0)<0&&d.iadd(e),d},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),r=e.clone();t.negative=0,r.negative=0;for(var n=0;t.isEven()&&r.isEven();n++)t.iushrn(1),r.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=t.cmp(r);if(i<0){var o=t;t=r,r=o}else if(0===i||0===r.cmpn(1))break;t.isub(r)}return r.iushln(n)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){n("number"==typeof e);var t=e%26,r=(e-t)/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(e){var t=e<0;if(0!==this.negative&&!t)return-1;if(0===this.negative&&t)return 1;this.strip();var r;if(this.length>1)r=1;else{t&&(e=-e),n(e<=67108863,"Number is too big");var i=0|this.words[0];r=i===e?0:ie.length)return 1;if(this.length=0;r--){var n=0|this.words[r],i=0|e.words[r];if(n!==i){ni&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return this.cmpn(e)>=0},o.prototype.gte=function(e){return this.cmp(e)>=0},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return this.cmpn(e)<=0},o.prototype.lte=function(e){return this.cmp(e)<=0},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new y(e)},o.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var k={k256:null,p224:null,p192:null,p25519:null};h.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},h.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t0?r.isub(this.p):r.strip(),r},h.prototype.split=function(e,t){e.iushrn(this.n,0,t)},h.prototype.imulK=function(e){return e.imul(this.k)},i(d,h),d.prototype.split=function(e,t){for(var r=Math.min(e.length,9),n=0;n>>22,i=o}i>>>=22,e.words[n-10]=i,0===i&&e.length>10?e.length-=10:e.length-=9},d.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r>>=26,e.words[r]=i,t=n}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(k[e])return k[e];var t;if("k256"===e)t=new d;else if("p224"===e)t=new l;else if("p192"===e)t=new p;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new b}return k[e]=t,t},y.prototype._verify1=function(e){n(0===e.negative,"red works only with positives"),n(e.red,"red works only with red numbers")},y.prototype._verify2=function(e,t){n(0==(e.negative|t.negative),"red works only with positives"),n(e.red&&e.red===t.red,"red works only with red numbers")},y.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):e.umod(this.m)._forceRed(this)},y.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},y.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},y.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},y.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},y.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},y.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},y.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},y.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},y.prototype.isqr=function(e){return this.imul(e,e.clone())},y.prototype.sqr=function(e){return this.mul(e,e)},y.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(n(t%2==1),3===t){var r=this.m.add(new o(1)).iushrn(2);return this.pow(e,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!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(e,i.addn(1).iushrn(1)),l=this.pow(e,i),p=s;0!==l.cmp(a);){for(var b=l,y=0;0!==b.cmp(a);y++)b=b.redSqr();n(y=0;n--){for(var f=t.words[n],u=c-1;u>=0;u--){var h=f>>u&1;i!==r[0]&&(i=this.sqr(i)),0!==h||0!==s?(s<<=1,s|=h,(4===++a||0===n&&0===u)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}c=26}return i},y.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},y.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new g(e)},i(g,y),g.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},g.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},g.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).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(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).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(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===e||e,this)}).call(t,r(46)(e))},function(e,t,r){function n(e,t){for(var r in e)t[r]=e[r]}function i(e,t,r){return s(e,t,r)}var o=r(1),s=o.Buffer;s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?e.exports=o:(n(o,t),t.Buffer=i),n(s,i),i.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return s(e,t,r)},i.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=s(e);return void 0!==t?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return s(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o.SlowBuffer(e)}},function(e,t,r){"use strict";function n(e){if(!(this instanceof n))return new n(e);f.call(this,e),u.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",i)}function i(){this.allowHalfOpen||this._writableState.ended||s(o,this)}function o(e){e.end()}var s=r(21),a=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};e.exports=n;var c=r(15);c.inherits=r(4);var f=r(36),u=r(23);c.inherits(n,f);for(var h=a(u.prototype),d=0;d=-1&&!i;o--){var s=o>=0?arguments[o]:e.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(t=s+"/"+t,i="/"===s.charAt(0))}return t=r(n(t.split("/"),function(e){return!!e}),!i).join("/"),(i?"/":"")+t||"."},t.normalize=function(e){var i=t.isAbsolute(e),o="/"===s(e,-1);return(e=r(n(e.split("/"),function(e){return!!e}),!i).join("/"))||i||(e="."),e&&o&&(e+="/"),(i?"/":"")+e},t.isAbsolute=function(e){return"/"===e.charAt(0)},t.join=function(){var e=Array.prototype.slice.call(arguments,0);return t.normalize(n(e,function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},t.relative=function(e,r){function n(e){for(var t=0;t=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=t.resolve(e).substr(1),r=t.resolve(r).substr(1);for(var i=n(e.split("/")),o=n(r.split("/")),s=Math.min(i.length,o.length),a=s,c=0;c=this._delta8){var r=(e=this.pending).length%this._delta8;this.pending=e.slice(e.length-r,e.length),0===this.pending.length&&(this.pending=null),e=i.join32(e,0,e.length-r,this.endian);for(var n=0;n>>24&255,n[i++]=e>>>16&255,n[i++]=e>>>8&255,n[i++]=255&e}else for(n[i++]=255&e,n[i++]=e>>>8&255,n[i++]=e>>>16&255,n[i++]=e>>>24&255,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,o=8;o{this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,e.clock?e.clock.time:0]),this.events.emit("replicate",this.address.toString())}),this._loader.on("load.start",(e,t)=>{this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,e.clock?e.clock.time:0])}),this._loader.on("load.progress",(e,t,r,n,i)=>{this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this.events.emit("replicate.progress",this.address.toString(),t,r,this._replicationInfo.progress,this._replicationInfo.have)}),this._loader.on("load.end",async(e,t)=>{try{await this._oplog.join(e,-1,this._oplog.id),this._replicator.replicate(this._oplog),this._index.updateIndex(this._oplog),this._calculateReplicationInfo(t),this.events.emit("replicated",this.address.toString())}catch(e){console.error(e)}}),this._replicator=new h(this._loader),this._replicator.replicate(this._oplog),this.options.replicate&&this._replicator.start()}catch(e){console.error("Store Error:",e)}}_calculateReplicationInfo(e){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),e&&(this._replicationInfo.have=Object.assign(this._replicationInfo.have,e))}get all(){return Array.isArray(this._index._index)?this._index._index:Object.keys(this._index._index).map(e=>this._index._index[e])}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"),await this._cache.close(),this.events.emit("closed",this.address.toString()),Promise.resolve()}async drop(){await this._cache.del(this.address.toString()+"/_manifest",null),await this._cache.del(this.address.toString(),null),await this._cache.del("_localHeads",null),await this._cache.del("_remoteHeads",null),await this._cache.del("snapshot",null),await this._cache.del("queue",null),await this.close(),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 Cache(this.options.path,this.dbname)}async load(e){this._replicator.stop(),e=e||this.options.maxHistory;const t=await this._cache.get("_localHeads")||[],r=await this._cache.get("_remoteHeads")||[],n=t.concat(r);n.length>0&&this.events.emit("load",this.address.toString(),n),await s(n,async t=>{this._replicationInfo.max=Math.max(this._replicationInfo.max,t.clock.time);let r=await a.fromEntryHash(this._ipfs,t.hash,this._oplog.id,e,this._oplog.values,this.key,this.access.write,this._onLoadProgress.bind(this));await this._oplog.join(r,e,this._oplog.id),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length])}),n.length>0&&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(e,r,n,i=!0,o=-1,a=0){return this._stats.syncRequestsReceieved+=1,s(e,e=>{if(!e)return console.warn("Warning: Given input entry was 'null'."),Promise.resolve(null);if(!this.access.write.includes(e.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 r=Object.assign({},e);return r.hash=null,this._ipfs.object.put(t.from(JSON.stringify(r))).then(e=>e.toJSON().multihash).then(t=>(t!==e.hash&&console.warn("\"WARNING! Head hash didn't match the contents"),t)).then(()=>e)}).then(async t=>(await this._cache.set("_remoteHeads",e),this._loader.load(t.filter(e=>null!==e))))}loadMoreFrom(e,t){this._loader.load(t)}async saveSnapshot(){const e=Object.keys(this._loader._fetching).map(e=>this._loader._fetching[e]).concat(this._loader._queue.map(e=>e));let r=this._oplog.toSnapshot(),n=new t(JSON.stringify({id:r.id,heads:r.heads,size:r.values.length,type:this.type}));const i=new o;let s=new Uint16Array([n.length]),a=new t(s.buffer);i.push(a),i.push(n),r.values.forEach(e=>{let r=new t(JSON.stringify(e)),n=new Uint16Array([r.length]);i.push(new t(n.buffer)),i.push(r)}),i.push(null);const c={path:this.address.toString(),content:i},f=await this._ipfs.files.add(c);return await this._cache.set("snapshot",f[f.length-1]),await this._cache.set("queue",e),f}async loadFromSnapshot(e){this.events.emit("load",this.address.toString());const r=await this._cache.get("queue");this.sync(r||[]);const n=await this._cache.get("snapshot");if(!n)throw new Error(`Snapshot for ${this.address} not found!`);{const e=await this._ipfs.files.catReadableStream(n.hash),r=await(()=>new Promise((r,n)=>{let i=new t(0),o=[];e.on("data",e=>{if(this._byteSize+=e.length,o.length<2e3)o.push(e);else{const e=t.concat(o);i=t.concat([i,e]),o=[]}}),e.on("end",()=>{function e(e){for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),n=0;n0){const e=t.concat(o);i=t.concat([i,e])}const n=parseInt(new Uint16Array(e(i.slice(0,2)))),s=JSON.parse(i.slice(2,n+2));let a=[],c=2+n;for(;cMath.max(e,t.clock.time),0)),r({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,(e,t,r,n)=>{this._replicationInfo.max=Math.max(this._replicationInfo.max,t.clock.time),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,r,this._oplog.length]),this._onLoadProgress(e,t,this._replicationInfo.progress,this._replicationInfo.max)});await this._oplog.join(i,-1,this._oplog.id),this._oplog.values.forEach(e=>this._replicationInfo.have[e.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(e,t,r,n){if(this._oplog){const t=await this._oplog.append(e);return this._replicationInfo.max=Math.max(this._replicationInfo.max,t.clock.time),this._replicationInfo.progress++,this.address.toString(),await this._cache.set("_localHeads",[t]),this._index.updateIndex(this._oplog),this.events.emit("write",this.address.toString(),t,this._oplog.heads),n&&n(t),t.hash}}_addOperationBatch(e,t,r,n){throw new Error("Not implemented!")}_onLoadProgress(e,t,r,n){this.events.emit("load.progress",this.address.toString(),e,t,Math.max(this._oplog.length,r),Math.max(this._oplog.length||0,this._replicationInfo.max||0))}}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";(function(t){function r(e,r,n,i){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick(function(){e.call(null,r)});case 3:return t.nextTick(function(){e.call(null,r,n)});case 4:return t.nextTick(function(){e.call(null,r,n,i)});default:for(o=new Array(a-1),s=0;s-1?n:y;c.WritableState=a;var v=r(15);v.inherits=r(4);var _={deprecate:r(75)},w=r(37),S=r(9).Buffer,k=i.Uint8Array||function(){},E=r(38);v.inherits(c,w),a.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(a.prototype,"buffer",{get:_.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}();var x;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(x=Function.prototype[Symbol.hasInstance],Object.defineProperty(c,Symbol.hasInstance,{value:function(e){return!!x.call(this,e)||e&&e._writableState instanceof a}})):x=function(e){return e instanceof this},c.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},c.prototype.write=function(e,t,r){var n=this._writableState,i=!1,o=function(e){return S.isBuffer(e)||e instanceof k}(e)&&!n.objectMode;return o&&!S.isBuffer(e)&&(e=function(e){return S.from(e)}(e)),"function"==typeof t&&(r=t,t=null),o?t="buffer":t||(t=n.defaultEncoding),"function"!=typeof r&&(r=s),n.ended?function(e,t){var r=new Error("write after end");e.emit("error",r),y(t,r)}(this,r):(o||function(e,t,r,n){var i=!0,o=!1;return null===r?o=new TypeError("May not write null values to stream"):"string"==typeof r||void 0===r||t.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(e.emit("error",o),y(n,o),i=!1),i}(this,n,e,r))&&(n.pendingcb++,i=f(this,n,o,e,t,r)),i},c.prototype.cork=function(){this._writableState.corked++},c.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||d(this,e))},c.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},c.prototype._write=function(e,t,r){r(new Error("_write() is not implemented"))},c.prototype._writev=null,c.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!==e&&void 0!==e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||function(e,t,r){t.ending=!0,b(e,t),r&&(t.finished?y(r):e.once("finish",r)),t.ended=!0,e.writable=!1}(this,n,r)},Object.defineProperty(c.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),c.prototype.destroy=E.destroy,c.prototype._undestroy=E.undestroy,c.prototype._destroy=function(e,t){this.end(),t(e)}}).call(t,r(0),r(39).setImmediate,r(7))},function(e,t,r){"use strict";e.exports=((e,t,r)=>new Promise((n,i)=>{if(r=Object.assign({concurrency:1/0},r),"function"!=typeof t)throw new TypeError("Mapper function is required");const o=r.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=e[Symbol.iterator]();let c=!1,f=!1,u=0,h=0;const d=()=>{if(c)return;const e=a.next(),r=h;if(h++,e.done)return f=!0,void(0===u&&n(s));u++,Promise.resolve(e.value).then(e=>t(e,r)).then(e=>{s[r]=e,u--,d()},e=>{c=!0,i(e)})};for(let e=0;enew Error("Ipfs instance not defined");class s{static async create(e,t,r,a=[],c,f){if(!i(e))throw o();if(!i(t))throw new Error("Entry requires an id");if(!i(r))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:t,payload:r,next:a.filter(i).map(e=>e.hash?e.hash:e),v:0,clock:new n(t,c?c.time:null)};return e.keystore&&f&&(u=await s.signEntry(e.keystore,u,f)),u.hash=await s.toMultihash(e,u),u}static async signEntry(e,r,n){const i=await e.sign(n,new t(JSON.stringify(r)));return r.sig=i,r.key=n.getPublic("hex"),r}static async verifyEntry(e,r){const n=Object.assign({},{hash:null,id:e.id,payload:e.payload,next:e.next,v:e.v,clock:e.clock}),i=await r.importPublicKey(e.key);await r.verify(e.sig,i,new t(JSON.stringify(n)))}static toMultihash(e,r){if(!e)throw o();const n=t.from(JSON.stringify(r));return e.object.put(n).then(e=>e.toJSON().multihash)}static fromMultihash(e,t){if(!e)throw o();if(!t)throw new Error(`Invalid hash: ${t}`);return e.object.get(t,{enc:"base58"}).then(e=>JSON.parse(e.toJSON().data)).then(e=>{let r={hash:t,id:e.id,payload:e.payload,next:e.next,v:e.v,clock:e.clock};return e.sig&&Object.assign(r,{sig:e.sig}),e.key&&Object.assign(r,{key:e.key}),r})}static isEntry(e){return void 0!==e.id&&void 0!==e.next&&void 0!==e.hash&&void 0!==e.payload&&void 0!==e.v&&void 0!==e.clock}static compare(e,t){var r=n.compare(e.clock,t.clock);return 0===r?e.clock.id-1}static findChildren(e,t){for(var r=[],n=t.find(t=>s.isParent(e,t)),i=e;n;)r.push(n),i=n,n=t.find(e=>s.isParent(i,e));return r=r.sort((e,t)=>e.clock.time>e.clock.time)}}e.exports=s}).call(t,r(1).Buffer)},function(e,t,r){"use strict";class n{constructor(e,t){this.id=e,this.time=t||0}tick(){return new n(this.id,++this.time)}merge(e){return this.time=Math.max(this.time,e.time),new n(this.id,this.time)}clone(){return new n(this.id,this.time)}static compare(e,t){var r=e.time-t.time;return 0===r&&e.id!==t.id?e.idvoid 0!==e&&null!==e)},function(e,t,r){var n=t;n.utils=r(5),n.common=r(16),n.sha=r(95),n.ripemd=r(99),n.hmac=r(100),n.sha1=n.sha.sha1,n.sha256=n.sha.sha256,n.sha224=n.sha.sha224,n.sha384=n.sha.sha384,n.sha512=n.sha.sha512,n.ripemd160=n.ripemd.ripemd160},function(e,t,r){"use strict";var n=r(58);e.exports=function(e,t){if(!e)return function(e,r){return e?n(r,e,t):r(!0)};Array.isArray(e)||(e=Object.keys(e).map(function(t){return e[t]}));var r=0;return function(i,o){if(i)return n(o,i,t);r>=e.length?o(!0):o(null,e[r++])}}},function(e,t,r){"use strict";var n=r(17);e.exports=function(e,t,r){r||(r=t,t=null);var i=n(function(r){t=e(t,r)},function(e){r(e,t)});return 2===arguments.length?function(e){e(null,function(n,o){if(n)return r(!0===n?null:n);t=o,i(e)})}:i}},function(e,t,r){"use strict";var n=r(60);e.exports=function(e){return e=n(e),function(t){return function r(n,i){for(var o,s=!0;s;)s=!1,o=!0,t(n,function(t,n){if(!t&&!e(n))return o?s=!0:r(t,i);i(t,n)}),o=!1}}}},function(e,t){e.exports=function(){for(var e={},t=0;tt}}_query(e){e||(e={});const t=e.limit?e.limit>-1?e.limit:this._index.get().length:1,r=this._index.get().slice();let n=[];return n=e.gt||e.gte?this._read(r,e.gt?e.gt:e.gte,t,!!e.gte):this._read(r.reverse(),e.lt?e.lt:e.lte,t,e.lte||!e.lt).reverse()}_read(e,t,r,n){const i=e.map(e=>e.hash).indexOf(t);let o=Math.max(i,0);return o+=n?0:1,e.slice(o).slice(0,r)}}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t,r){"use strict";(function(t,n){function i(e,t){w=w||r(10),e=e||{},this.objectMode=!!e.objectMode,t instanceof w&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var n=e.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=n||0===n?n:i,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new R,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=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(N||(N=r(40).StringDecoder),this.decoder=new N(e.encoding),this.encoding=e.encoding)}function o(e){if(w=w||r(10),!(this instanceof o))return new o(e);this._readableState=new i(e,this),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),E.call(this)}function s(e,t,r,n,i){var o=e._readableState;if(null===t)o.reading=!1,function(e,t){if(t.ended)return;if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,f(e)}(e,o);else{var s;i||(s=function(e,t){var r;(function(e){return x.isBuffer(e)||e instanceof M})(t)||"string"==typeof t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk"));return r}(o,t)),s?e.emit("error",s):o.objectMode||t&&t.length>0?("string"==typeof t||o.objectMode||Object.getPrototypeOf(t)===x.prototype||(t=function(e){return x.from(e)}(t)),n?o.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):a(e,o,t,!0):o.ended?e.emit("error",new Error("stream.push() after EOF")):(o.reading=!1,o.decoder&&!r?(t=o.decoder.write(t),o.objectMode||0!==t.length?a(e,o,t,!1):h(e,o)):a(e,o,t,!1))):n||(o.reading=!1)}return function(e){return!e.ended&&(e.needReadable||e.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=j?e=j:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function f(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(I("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?_(u,e):u(e))}function u(e){I("emit readable"),e.emit("readable"),b(e)}function h(e,t){t.readingMore||(t.readingMore=!0,_(d,e,t))}function d(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=function(e,t,r){var n;eo.length?o.length:e;if(s===o.length?i+=o:i+=o.slice(0,e),0===(e-=s)){s===o.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(s));break}++n}return t.length-=n,i}(e,t):function(e,t){var r=x.allocUnsafe(e),n=t.head,i=1;n.data.copy(r),e-=n.data.length;for(;n=n.next;){var o=n.data,s=e>o.length?o.length:e;if(o.copy(r,r.length-e,0,s),0===(e-=s)){s===o.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(s));break}++i}return t.length-=i,r}(e,t);return n}(e,t.buffer,t.decoder),r}function g(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,_(m,t,e))}function m(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function v(e,t){for(var r=0,n=e.length;r=t.highWaterMark||t.ended))return I("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?g(this):f(this),null;if(0===(e=c(e,t))&&t.ended)return 0===t.length&&g(this),null;var n=t.needReadable;I("need readable",n),(0===t.length||t.length-e0?y(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&g(this)),null!==i&&this.emit("data",i),i},o.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},o.prototype.pipe=function(e,t){function r(t,n){I("onunpipe"),t===u&&n&&!1===n.hasUnpiped&&(n.hasUnpiped=!0,I("cleanup"),e.removeListener("close",a),e.removeListener("finish",c),e.removeListener("drain",l),e.removeListener("error",s),e.removeListener("unpipe",r),u.removeListener("end",i),u.removeListener("end",f),u.removeListener("data",o),p=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||l())}function i(){I("onend"),e.end()}function o(t){I("ondata"),y=!1;!1!==e.write(t)||y||((1===h.pipesCount&&h.pipes===e||h.pipesCount>1&&-1!==v(h.pipes,e))&&!p&&(I("false write response, pause",u._readableState.awaitDrain),u._readableState.awaitDrain++,y=!0),u.pause())}function s(t){I("onerror",t),f(),e.removeListener("error",s),0===k(e,"error")&&e.emit("error",t)}function a(){e.removeListener("finish",c),f()}function c(){I("onfinish"),e.removeListener("close",a),f()}function f(){I("unpipe"),u.unpipe(e)}var u=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,I("pipe count=%d opts=%j",h.pipesCount,t);var d=(!t||!1!==t.end)&&e!==n.stdout&&e!==n.stderr?i:f;h.endEmitted?_(d):u.once("end",d),e.on("unpipe",r);var l=function(e){return function(){var t=e._readableState;I("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&k(e,"data")&&(t.flowing=!0,b(e))}}(u);e.on("drain",l);var p=!1,y=!1;return u.on("data",o),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?S(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",s),e.once("close",a),e.once("finish",c),e.emit("pipe",u),h.flowing||(I("pipe resume"),u.resume()),e},o.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r),this);if(!e){var n=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},r(74),t.setImmediate=setImmediate,t.clearImmediate=clearImmediate},function(e,t,r){"use strict";function n(e){this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(d.isEncoding===l||!l(e)))throw new Error("Unknown encoding: "+e);return t||e}(e);var t;switch(this.encoding){case"utf16le":this.text=s,this.end=a,t=4;break;case"utf8":this.fillLast=o,t=4;break;case"base64":this.text=c,this.end=f,t=3;break;default:return this.write=u,void(this.end=h)}this.lastNeed=0,this.lastTotal=0,this.lastChar=d.allocUnsafe(t)}function i(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:-1}function o(e){var t=this.lastTotal-this.lastNeed,r=function(e,t,r){if(128!=(192&t[0]))return e.lastNeed=0,"�".repeat(r);if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�".repeat(r+1);if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�".repeat(r+2)}}(this,e,t);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function s(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function a(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function c(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function u(e){return e.toString(this.encoding)}function h(e){return e&&e.length?this.write(e):""}var d=r(9).Buffer,l=d.isEncoding||function(e){switch((e=""+e)&&e.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}};t.StringDecoder=n,n.prototype.write=function(e){if(0===e.length)return"";var t,r;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r=0?(o>0&&(e.lastNeed=o-1),o):--n=0?(o>0&&(e.lastNeed=o-2),o):--n=0?(o>0&&(2===o?o=0:e.lastNeed=o-3),o):0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)},n.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},function(e,t,r){"use strict";function n(e){this.afterTransform=function(t,r){return function(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("write callback called multiple times"));n.writechunk=null,n.writecb=null,null!==r&&void 0!==r&&e.push(r);i(t);var o=e._readableState;o.reading=!1,(o.needReadable||o.length(new Date).getTime().toString();class d extends i{constructor(e,t,r,n,i,o,s=[]){if(!f(e))throw a.ImmutableDBNotDefinedError();if(f(r)&&!Array.isArray(r))throw new Error("'entries' argument must be an array of Entry instances");if(f(n)&&!Array.isArray(n))throw new Error("'heads' argument must be an array");super(),this._storage=e,this._id=t||h(),this._keystore=this._storage.keystore,this._key=o,this._keys=Array.isArray(s)?s:[s],r=r||[],this._entryIndex=r.reduce((e,t)=>(e[t.hash]=t,e),{}),n=n||d.findHeads(r),this._headsIndex=n.reduce((e,t)=>(e[t.hash]=t,e),{}),this._length=r?r.length:0;const u=Math.max(i?i.time:0,this.heads.reduce((e,t)=>Math.max(e,t.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 d.findTails(this.values)}get tailHashes(){return d.findTailHashes(this.values)}get(e){return this._entryIndex[e]}has(e){return void 0!==this._entryIndex[e.hash||e]}async append(e){if(this._key&&!this._keys.includes(this._key.getPublic("hex"))&&!this._keys.includes("*"))throw new Error("Not allowed to write");const t=Math.max(this.clock.time,this.heads.reduce((e,t)=>Math.max(e,t.clock.time),0))+1;this._clock=new c(this.clock.id,t);const r=await o.create(this._storage,this.id,e,Object.values(this._headsIndex),this.clock,this._key);return this._entryIndex[r.hash]=r,this._headsIndex={},this._headsIndex[r.hash]=r,this._length++,r}async join(e,t=-1,r){if(!f(e))throw a.LogNotDefinedError();if(!d.isLog(e))throw a.NotALogError();const i=async e=>{this._keys.map(e=>e.getPublic?e.getPublic("hex"):e);return(await n(e,async e=>{if(!e.key)throw new Error("Entry doesn't have a public key");if(!e.sig)throw new Error("Entry doesn't have a signature");if(1===this._keys.length&&this._keys[0]===this._key&&e.id!==this.id)throw new Error("Entry doesn't belong in this log (wrong ID)");if(this._keys.length>0&&!this._keys.includes("*")&&!((e,t)=>e.find(e=>e===t.key))(this._keys.concat([this._key]),e))return console.warn("Warning: Input log contains entries that are not allowed in this log. Logs weren't joined."),!1;try{await o.verifyEntry(e,this._keystore)}catch(t){return console.log(t),console.log("Couldn't verify entry:\n",e),!1}return!0})).every(e=>!0===e)},s=(e,t)=>(e[t.hash]=t,e);r=r||[e,this].sort((e,t)=>e.id>t.id)[0].id;const u=((e,t)=>{let r=Object.keys(e._headsIndex),n={},i={};for(;r.length>0;){const o=r.shift(),s=e.get(o);s&&!t.get(o)&&(i[s.hash]=s,n[s.hash]=!0,s.next.forEach(e=>{n[e]||t.get(e)||(r.push(e),n[e]=!0)}))}return i})(e,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,t>-1){let e=this.values;e=e.slice(-t),this._entryIndex=e.reduce(s,{}),this._length=Object.values(this._entryIndex).length}const h=d.findHeads(Object.values(Object.assign({},this._headsIndex,e._headsIndex)));this._headsIndex=h.reduce(s,{});const l=Object.values(this._headsIndex).reduce((e,t)=>e=Math.max(e,t.clock.time),0),p=new c(this.id,Math.max(this.clock.time,l));return this._id=r,this._clock=p,this}toJSON(){return{id:this.id,heads:this.heads.map(e=>e.hash)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return t.from(JSON.stringify(this.toJSON()))}toString(e){return this.values.slice().reverse().map((t,r)=>{const n=o.findChildren(t,this.values).length;let i=new Array(Math.max(n-1,0));return i=n>1?i.fill(" "):i,(i=n>0?i.concat(["└─"]):i).join("")+(e?e(t.payload):t.payload)}).join("\n")}static isLog(e){return void 0!==e.id&&void 0!==e.heads&&void 0!==e._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static fromMultihash(e,t,r=-1,n,i,o){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw new Error(`Invalid hash: ${t}`);return s.fromMultihash(e,t,r,n,o).then(t=>new d(e,t.id,t.values,t.heads,t.clock,i))}static fromEntryHash(e,t,r,n=-1,i,o,c,u){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw new Error("'hash' must be defined");return s.fromEntryHash(e,t,r,n,i,u).then(t=>new d(e,r,t.values,null,null,o,c))}static fromJSON(e,t,r=-1,n,i,o,c){if(!f(e))throw a.ImmutableDBNotDefinedError();return s.fromJSON(e,t,r,n,o,c).then(t=>new d(e,t.id,t.values,null,null,n,i))}static fromEntry(e,t,r=-1,n,i){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw new Error("'sourceEntries' must be defined");return s.fromEntry(e,t,r,n,i).then(t=>new d(e,t.id,t.values))}static expandFrom(e,t,r,n=-1){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw a.LogNotDefinedError();if(!f(r))throw new Error("'entries' must be given as argument");if(!d.isLog(t))throw a.NotALogError();return s.expandFrom(e,t,r,n).then(r=>new d(e,t.id,r.values,null,t.clock))}static expand(e,t,r){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw a.LogNotDefinedError();if(!d.isLog(t))throw a.NotALogError();return s.expand(e,t,r).then(r=>new d(e,t.id,r.values,t.heads,t.clock))}static findHeads(e){var t=e.reduce((e,t,r,n)=>{return t.next.forEach(r=>e[r]=t.hash),e},{});return e.filter(e=>void 0===t[e.hash]).sort((e,t)=>e.id>t.id)}static findTails(e){var t={},r=[],n={},i=[];e.forEach(e=>{0===e.next.length&&r.push(e);e.next.forEach(r=>{t[r]||(t[r]=[]),t[r].push(e)}),i=i.concat(e.next),n[e.hash]=!0});const s=i.filter(e=>void 0===n[e]).map(e=>t[e]).reduce((e,t,r,n)=>e.concat(u(t,"hash")),[]).concat(r);return u(s,"hash").sort(o.compare)}static findTailHashes(e){var t={};return e.forEach(e=>t[e.hash]=!0),e.reduce((e,r,n,i)=>{return r.next.reverse().forEach(r=>{void 0===t[r]&&e.splice(0,0,r)}),e},[])}}e.exports=d}).call(t,r(1).Buffer)},function(e,t,r){"use strict";e.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(e,t,r){"use strict";e.exports=function(e,t){let r={};return e.forEach(e=>r[t?e[t]:e]=e),Object.keys(r).map(e=>r[e])}},function(e,t,r){"use strict";(function(t){const n=r(14),i=new(0,r(3).ec)("secp256k1");e.exports=class{constructor(e="./keystore"){if("undefined"==typeof localStorage||null===localStorage){n.sync(e);const t=r(109).LocalStorage;this._storage=new t(e)}else this._storage=localStorage}createKey(e){const t=i.genKeyPair(),r=t.getPublic("hex"),n=t.getPrivate("hex");return this._storage.setItem(e,JSON.stringify({publicKey:r,privateKey:n})),t}getKey(e){let t=JSON.parse(this._storage.getItem(e));if(t)return i.keyPair({pub:t.publicKey,priv:t.privateKey,privEnc:"hex",pubEnc:"hex"})}static importKeyFromIpfs(e,t){return e.object.get(t,{enc:"base58"}).then(e=>JSON.parse(e.toJSON().Data)).then(e=>OrbitCrypto.importPublicKey(e))}static exportPublicKeyToIpfs(e,r){return r.getPublic("hex"),OrbitCrypto.exportPublicKey(r).then(e=>JSON.stringify(e,null,2)).then(e=>new t(e)).then(t=>e.object.put(t)).then(e=>e.toJSON().multihash)}static getKey(e){let t,r,n,o=JSON.parse(keystore.getItem(e));return o?OrbitCrypto.importPrivateKey(o.privateKey).then(e=>n=e).then(()=>OrbitCrypto.importPublicKey(o.publicKey)).then(e=>r=e).then(()=>i.keyPair({pub:r,priv:n})):OrbitCrypto.generateKey().then(e=>t=e).then(()=>OrbitCrypto.exportPrivateKey(t)).then(e=>n=e).then(()=>OrbitCrypto.exportPublicKey(t)).then(e=>r=e).then(()=>(keystore.setItem(e,JSON.stringify({publicKey:r,privateKey:n})),i.keyPair({pub:r,priv:n})))}generateKey(){return Promise.resolve(i.genKeyPair())}exportPublicKey(e){return Promise.resolve(e.getPublic("hex"))}exportPrivateKey(e){return Promise.resolve(e.getPrivate("hex"))}importPublicKey(e){return Promise.resolve(i.keyFromPublic(e,"hex"))}importPrivateKey(e){return Promise.resolve(i.keyFromPrivate(e,"hex"))}sign(e,t){const r=i.sign(t,e);return Promise.resolve(r.toDER("hex"))}verify(e,t,r){let n=!1;return n=i.verify(r,e,t),Promise.resolve(n)}}}).call(t,r(1).Buffer)},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,r){"use strict";function n(e){return 1===e.length?"0"+e:e}function i(e){for(var t="",r=0;r>8,s=255&i;o?r.push(o,s):r.push(s)}return r},o.zero2=n,o.toHex=i,o.encode=function(e,t){return"hex"===t?i(e):e}},function(e,t,r){"use strict";function n(e,t,r){return e&t^~e&r}function i(e,t,r){return e&t^e&r^t&r}function o(e,t,r){return e^t^r}var s=r(5).rotr32;t.ft_1=function(e,t,r,s){return 0===e?n(t,r,s):1===e||3===e?o(t,r,s):2===e?i(t,r,s):void 0},t.ch32=n,t.maj32=i,t.p32=o,t.s0_256=function(e){return s(e,2)^s(e,13)^s(e,22)},t.s1_256=function(e){return s(e,6)^s(e,11)^s(e,25)},t.g0_256=function(e){return s(e,7)^s(e,18)^e>>>3},t.g1_256=function(e){return s(e,17)^s(e,19)^e>>>10}},function(e,t,r){"use strict";function n(){if(!(this instanceof n))return new n;g.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=m,this.W=new Array(64)}var i=r(5),o=r(16),s=r(48),a=r(11),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(n,g),e.exports=n,n.blockSize=512,n.outSize=256,n.hmacStrength=192,n.padLength=64,n.prototype._update=function(e,t){for(var r=this.W,n=0;n<16;n++)r[n]=e[t+n];for(;n=0;a--)if(c[a]!==f[a])return!1;for(a=c.length-1;a>=0;a--)if(s=c[a],!d(e[s],t[s],r,n))return!1;return!0}(e,t,r,a))}return r?e===t:e==t}function l(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function p(e,t,r){d(e,t,!0)&&u(e,t,r,"notDeepStrictEqual",p)}function b(e,t){if(!e||!t)return!1;if("[object RegExp]"==Object.prototype.toString.call(t))return t.test(e);try{if(e instanceof t)return!0}catch(e){}return!Error.isPrototypeOf(t)&&!0===t.call({},e)}function y(e,t,r,n){var i;if("function"!=typeof t)throw new TypeError('"block" argument must be a function');"string"==typeof r&&(n=r,r=null),i=function(e){var t;try{e()}catch(e){t=e}return t}(t),n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),e&&!i&&u(i,r,"Missing expected exception"+n);var o="string"==typeof n,s=!e&&g.isError(i),a=!e&&i&&!r;if((s&&o&&b(i,r)||a)&&u(i,r,"Got unwanted exception"+n),e&&i&&r&&!b(i,r)||!e&&i)throw i}var g=r(6),m=Object.prototype.hasOwnProperty,v=Array.prototype.slice,_="foo"===function(){}.name,w=e.exports=h,S=/\s*function\s+([^\(\s]*)\s*/;w.AssertionError=function(e){this.name="AssertionError",this.actual=e.actual,this.expected=e.expected,this.operator=e.operator,e.message?(this.message=e.message,this.generatedMessage=!1):(this.message=function(e){return c(f(e.actual),128)+" "+e.operator+" "+c(f(e.expected),128)}(this),this.generatedMessage=!0);var t=e.stackStartFunction||u;if(Error.captureStackTrace)Error.captureStackTrace(this,t);else{var r=new Error;if(r.stack){var n=r.stack,i=a(t),o=n.indexOf("\n"+i);if(o>=0){var s=n.indexOf("\n",o+1);n=n.substring(s+1)}this.stack=n}}},g.inherits(w.AssertionError,Error),w.fail=u,w.ok=h,w.equal=function(e,t,r){e!=t&&u(e,t,r,"==",w.equal)},w.notEqual=function(e,t,r){e==t&&u(e,t,r,"!=",w.notEqual)},w.deepEqual=function(e,t,r){d(e,t,!1)||u(e,t,r,"deepEqual",w.deepEqual)},w.deepStrictEqual=function(e,t,r){d(e,t,!0)||u(e,t,r,"deepStrictEqual",w.deepStrictEqual)},w.notDeepEqual=function(e,t,r){d(e,t,!1)&&u(e,t,r,"notDeepEqual",w.notDeepEqual)},w.notDeepStrictEqual=p,w.strictEqual=function(e,t,r){e!==t&&u(e,t,r,"===",w.strictEqual)},w.notStrictEqual=function(e,t,r){e===t&&u(e,t,r,"!==",w.notStrictEqual)},w.throws=function(e,t,r){y(!0,e,t,r)},w.doesNotThrow=function(e,t,r){y(!1,e,t,r)},w.ifError=function(e){if(e)throw e};var k=Object.keys||function(e){var t=[];for(var r in e)m.call(e,r)&&t.push(r);return t}}).call(t,r(7))},function(e,t){e.exports=function(){var e,t=Array.prototype.slice.call(arguments),r=null;return"object"==typeof t[0]?(r=t.shift(),"string"==typeof(e=t.shift())&&(e=r[e])):e=t.shift(),function(n){e.apply(r,t.concat(n))}}},function(e,t,r){"use strict";const{deepEqual:n}=r(136),i=(e,t)=>e+t;class o{constructor(e,t){this.id=e,this._counters=t||{},this._counters[this.id]=this._counters[this.id]?this._counters[this.id]:0}get value(){return Object.values(this._counters).reduce(i,0)}increment(e){e&&e<1||(void 0!==e&&null!==e||(e=1),this._counters[this.id]=this._counters[this.id]+e)}merge(e){Object.entries(e._counters).forEach(([e,t])=>{this._counters[e]=Math.max(this._counters[e]||0,t)})}toJSON(){return{id:this.id,counters:this._counters}}isEqual(e){return o.isEqual(this,e)}static from(e){return new o(e.id,e.counters)}static isEqual(e,t){return e.id===t.id&&n(e._counters,t._counters)}}e.exports=o},function(e,t,r){(function(e,r){function n(e,t){return e.set(t[0],t[1]),e}function i(e,t){return e.add(t),e}function o(e,t,r,n){var i=-1,o=e?e.length:0;for(n&&o&&(r=e[++i]);++i-1&&e%1==0&&e-1&&e%1==0&&e<=P}(e.length)&&!A(e)}function A(e){var t=O(e)?we.call(e):"";return t==L||t==B}function O(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function I(e){return M(e)?p(e):function(e){if(!k(e))return Pe(e);var t=[];for(var r in Object(e))_e.call(e,r)&&"constructor"!=r&&t.push(r);return t}(e)}var N=200,R="__lodash_hash_undefined__",P=9007199254740991,C="[object Arguments]",j="[object Boolean]",T="[object Date]",L="[object Function]",B="[object GeneratorFunction]",D="[object Map]",q="[object Number]",F="[object Object]",z="[object Promise]",U="[object RegExp]",K="[object Set]",G="[object String]",W="[object Symbol]",H="[object WeakMap]",Y="[object ArrayBuffer]",V="[object DataView]",J="[object Float32Array]",$="[object Float64Array]",X="[object Int8Array]",Z="[object Int16Array]",Q="[object Int32Array]",ee="[object Uint8Array]",te="[object Uint8ClampedArray]",re="[object Uint16Array]",ne="[object Uint32Array]",ie=/\w*$/,oe=/^\[object .+?Constructor\]$/,se=/^(?:0|[1-9]\d*)$/,ae={};ae[C]=ae["[object Array]"]=ae[Y]=ae[V]=ae[j]=ae[T]=ae[J]=ae[$]=ae[X]=ae[Z]=ae[Q]=ae[D]=ae[q]=ae[F]=ae[U]=ae[K]=ae[G]=ae[W]=ae[ee]=ae[te]=ae[re]=ae[ne]=!0,ae["[object Error]"]=ae[L]=ae[H]=!1;var ce="object"==typeof e&&e&&e.Object===Object&&e,fe="object"==typeof self&&self&&self.Object===Object&&self,ue=ce||fe||Function("return this")(),he="object"==typeof t&&t&&!t.nodeType&&t,de=he&&"object"==typeof r&&r&&!r.nodeType&&r,le=de&&de.exports===he,pe=Array.prototype,be=Function.prototype,ye=Object.prototype,ge=ue["__core-js_shared__"],me=function(){var e=/[^.]+$/.exec(ge&&ge.keys&&ge.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ve=be.toString,_e=ye.hasOwnProperty,we=ye.toString,Se=RegExp("^"+ve.call(_e).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ke=le?ue.Buffer:void 0,Ee=ue.Symbol,xe=ue.Uint8Array,Me=c(Object.getPrototypeOf,Object),Ae=Object.create,Oe=ye.propertyIsEnumerable,Ie=pe.splice,Ne=Object.getOwnPropertySymbols,Re=ke?ke.isBuffer:void 0,Pe=c(Object.keys,Object),Ce=S(ue,"DataView"),je=S(ue,"Map"),Te=S(ue,"Promise"),Le=S(ue,"Set"),Be=S(ue,"WeakMap"),De=S(Object,"create"),qe=E(Ce),Fe=E(je),ze=E(Te),Ue=E(Le),Ke=E(Be),Ge=Ee?Ee.prototype:void 0,We=Ge?Ge.valueOf:void 0;u.prototype.clear=function(){this.__data__=De?De(null):{}},u.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},u.prototype.get=function(e){var t=this.__data__;if(De){var r=t[e];return r===R?void 0:r}return _e.call(t,e)?t[e]:void 0},u.prototype.has=function(e){var t=this.__data__;return De?void 0!==t[e]:_e.call(t,e)},u.prototype.set=function(e,t){return this.__data__[e]=De&&void 0===t?R:t,this},h.prototype.clear=function(){this.__data__=[]},h.prototype.delete=function(e){var t=this.__data__,r=y(t,e);return!(r<0||(r==t.length-1?t.pop():Ie.call(t,r,1),0))},h.prototype.get=function(e){var t=this.__data__,r=y(t,e);return r<0?void 0:t[r][1]},h.prototype.has=function(e){return y(this.__data__,e)>-1},h.prototype.set=function(e,t){var r=this.__data__,n=y(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},d.prototype.clear=function(){this.__data__={hash:new u,map:new(je||h),string:new u}},d.prototype.delete=function(e){return w(this,e).delete(e)},d.prototype.get=function(e){return w(this,e).get(e)},d.prototype.has=function(e){return w(this,e).has(e)},d.prototype.set=function(e,t){return w(this,e).set(e,t),this},l.prototype.clear=function(){this.__data__=new h},l.prototype.delete=function(e){return this.__data__.delete(e)},l.prototype.get=function(e){return this.__data__.get(e)},l.prototype.has=function(e){return this.__data__.has(e)},l.prototype.set=function(e,t){var r=this.__data__;if(r instanceof h){var n=r.__data__;if(!je||n.length{let t=e;return n.isBuffer(t)||(t=n.from(t)),t})},function(e,t,r){"use strict";(function(t){const n=r(14),i=r(6).format,o=r(2).EventEmitter;let s=!!t.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};e.exports={Colors:h,LogLevels:a,setLogLevel:e=>{c=e},setLogfile:e=>{f=e},create:(e,r)=>{return new class{constructor(e,t){this.category=e;let r={};Object.assign(r,l),Object.assign(r,t),this.options=r}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(e,t){(this.options.filename||f)&&!this.fileWriter&&s&&(this.fileWriter=n.openSync(this.options.filename||f,this.options.appendFile?"a+":"w+"));let r=this._format(e,t),i=this._createLogMessage(e,t),o=this._createLogMessage(e,t,r.timestamp,r.level,r.category,r.text);this.fileWriter&&s&&n.writeSync(this.fileWriter,i+"\n",null,"utf-8"),s||!this.options.useColors?(console.log(o),u.emit("data",this.category,e,t)):e===a.ERROR?this.options.showTimestamp&&this.options.showLevel?console.error(o,r.timestamp,r.level,r.category,r.text):this.options.showTimestamp&&!this.options.showLevel?console.error(o,r.timestamp,r.category,r.text):!this.options.showTimestamp&&this.options.showLevel?console.error(o,r.level,r.category,r.text):console.error(o,r.category,r.text):this.options.showTimestamp&&this.options.showLevel?console.log(o,r.timestamp,r.level,r.category,r.text):this.options.showTimestamp&&!this.options.showLevel?console.log(o,r.timestamp,r.category,r.text):!this.options.showTimestamp&&this.options.showLevel?console.log(o,r.level,r.category,r.text):console.log(o,r.category,r.text)}_format(e,t){let r="",n="",i="",o=": ";if(this.options.useColors){const t=Object.keys(a).map(e=>a[e]).indexOf(e),c=this.options.color;s?(this.options.showTimestamp&&(r="[3"+h.Grey+"m"),this.options.showLevel&&(n="[3"+d[t]+";22m"),i="[3"+c+";1m",o=": "):(this.options.showTimestamp&&(r="color:"+h.Grey),this.options.showLevel&&(n="color:"+d[t]),i="color:"+c+"; font-weight: bold")}return{timestamp:r,level:n,category:i,text:o}}_createLogMessage(e,t,r,n,i,o){r=r||"",n=n||"",i=i||"",o=o||": ",!s&&this.options.useColors&&(this.options.showTimestamp&&(r="%c"),this.options.showLevel&&(n="%c"),i="%c",o=": %c");let c="";return this.options.showTimestamp&&(c+=(new Date).toISOString()+" "),c=r+c,this.options.showLevel&&(c+=n+"["+e+"]"+(e===a.INFO||e===a.WARN?" ":"")+" "),c+=i+this.category,c+=o+t}_shouldLog(e){let r=void 0!==t&&void 0!==Object({NODE_ENV:void 0})&&void 0!==Object({NODE_ENV:void 0}).LOG?Object({NODE_ENV:void 0}).LOG.toUpperCase():null;const n=(r="undefined"!=typeof window&&window.LOG?window.LOG.toUpperCase():r)||c,i=Object.keys(a).map(e=>a[e]);return i.indexOf(e)>=i.indexOf(n)}}(e,r)},forceBrowserMode:e=>s=!e,events:u}}).call(t,r(0))},function(e,t,r){(function(t,n){function i(e){if(!arguments.length||void 0===e)throw new Error("constructor requires at least a location argument");if("string"!=typeof e)throw new Error("constructor requires a location string argument");this.location=e,this.status="new"}var o=r(32),s=r(65),a=r(66);i.prototype.open=function(e,r){var n=this,i=this.status;if("function"==typeof e&&(r=e),"function"!=typeof r)throw new Error("open() requires a callback argument");"object"!=typeof e&&(e={}),e.createIfMissing=0!=e.createIfMissing,e.errorIfExists=!!e.errorIfExists,"function"==typeof this._open?(this.status="opening",this._open(e,function(e){if(e)return n.status=i,r(e);n.status="open",r()})):(this.status="open",t.nextTick(r))},i.prototype.close=function(e){var r=this,n=this.status;if("function"!=typeof e)throw new Error("close() requires a callback argument");"function"==typeof this._close?(this.status="closing",this._close(function(t){if(t)return r.status=n,e(t);r.status="closed",e()})):(this.status="closed",t.nextTick(e))},i.prototype.get=function(e,r,n){var i;if("function"==typeof r&&(n=r),"function"!=typeof n)throw new Error("get() requires a callback argument");return(i=this._checkKey(e,"key"))?n(i):(e=this._serializeKey(e),"object"!=typeof r&&(r={}),r.asBuffer=0!=r.asBuffer,"function"==typeof this._get?this._get(e,r,n):void t.nextTick(function(){n(new Error("NotFound"))}))},i.prototype.put=function(e,r,n,i){var o;if("function"==typeof n&&(i=n),"function"!=typeof i)throw new Error("put() requires a callback argument");return(o=this._checkKey(e,"key"))?i(o):(e=this._serializeKey(e),r=this._serializeValue(r),"object"!=typeof n&&(n={}),"function"==typeof this._put?this._put(e,r,n,i):void t.nextTick(i))},i.prototype.del=function(e,r,n){var i;if("function"==typeof r&&(n=r),"function"!=typeof n)throw new Error("del() requires a callback argument");return(i=this._checkKey(e,"key"))?n(i):(e=this._serializeKey(e),"object"!=typeof r&&(r={}),"function"==typeof this._del?this._del(e,r,n):void t.nextTick(n))},i.prototype.batch=function(e,r,n){if(!arguments.length)return this._chainedBatch();if("function"==typeof r&&(n=r),"function"==typeof e&&(n=e),"function"!=typeof n)throw new Error("batch(array) requires a callback argument");if(!Array.isArray(e))return n(new Error("batch(array) requires an array argument"));r&&"object"==typeof r||(r={});for(var i,o,s=0,a=e.length;s0&&(y.debug(`Send latest heads of '${e}':\n`,JSON.stringify(i,null,2)),r.sendTo(t,JSON.stringify(i))),n.events.emit("peer",t)}}_onClosed(e){y.debug(`Database '${e}' was closed`),this.stores[e].events.removeAllListeners("closed"),this._pubsub&&this._pubsub.unsubscribe(e),delete this.stores[e]}async create(e,t,r={}){if(y.debug("create()"),!m.isValidType(t))throw new Error(`Invalid database type '${t}'`);const i=r.directory||this.directory;if(y.debug(`Creating database '${e}' as ${t} in '${i}'`),l.isValid(e))throw new Error("Given database name is an address. Please give only the name of the database!");const o=new d(this._ipfs);r&&r.write&&r.write.length>0?r.write.forEach(e=>o.add("write",e)):o.add("write",this.key.getPublic("hex"));const s=await o.save(),a=await p(this._ipfs,e,t,s),c=l.parse(n.join("/orbitdb",a,e));if(await this._loadCache(i,c).then(e=>e?e.get(n.join(c.toString(),"_manifest")):null).then(e=>void 0!==e&&null!==e)&&!r.overwrite)throw new Error(`Database '${c}' already exists!`);return await this._saveDBManifest(i,c),y.debug(`Created database '${c}'`),this.open(c,r)}async open(e,t={}){y.debug("open()"),t=Object.assign({localOnly:!1,create:!1},t),y.debug(`Open database '${e}'`);const r=t.directory||this.directory;if(y.debug(`Look from '${r}'`),!l.isValid(e)){if(t.create){if(t.create&&!t.type)throw new Error(`Database type not provided! Provide a type with 'options.type' (${g.join("|")})`);return y.warn(`Not a valid OrbitDB address '${e}', creating the database`),t.overwrite=!t.overwrite||t.overwrite,this.create(e,t.type,t)}throw new Error("'options.create' set to 'false'. If you want to create a database, set 'options.create' to 'true'.")}const i=l.parse(e),o=await this._loadCache(r,i).then(e=>e?e.get(n.join(i.toString(),"_manifest")):null).then(e=>void 0!==e&&null!==e);if(y.debug((o?"Found":"Didn't find")+` database '${i}'`),t.localOnly&&!o)throw y.error(`Database '${i}' doesn't exist!`),new Error(`Database '${i}' doesn't exist!`);y.debug(`Loading Manifest for '${i}'`);const s=await this._ipfs.object.get(i.root),a=JSON.parse(s.toJSON().data);if(y.debug(`Manifest for '${i}':\n${JSON.stringify(a,null,2)}`),t.type&&a.type!==t.type)throw new Error(`Database '${i}' is type '${a.type}' but was opened as '${t.type}'`);return await this._saveDBManifest(r,i),t=Object.assign({},t,{accessControllerAddress:a.accessController}),this._openDatabase(i,a.type,t)}async _saveDBManifest(e,t){const r=await this._loadCache(e,t);await r.set(n.join(t.toString(),"_manifest"),t.root),y.debug(`Saved manifest to IPFS as '${t.root}'`)}async _loadCache(e,t){let r;try{r=await u.load(e,t)}catch(e){y.warn("Couldn't load Cache:",e)}return r}async _openDatabase(e,t,r){if("counter"===t)return this._createStore(a,e,r);if("eventlog"===t)return this._createStore(i,e,r);if("feed"===t)return this._createStore(o,e,r);if("docstore"===t)return this._createStore(c,e,r);if("keyvalue"===t)return this._createStore(s,e,r);throw new Error(`Invalid database type '${t}'`)}static isValidType(e){return g.includes(e)}static create(){return new Error("Not implemented yet!")}static open(){return new Error("Not implemented yet!")}}e.exports=m},function(e,t,r){"use strict";function n(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function i(e){return s[e>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}function o(e,t,r){for(var n,o=[],s=t;s0?f-4:f;var u=0;for(t=0;t>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=a[e.charCodeAt(t)]<<2|a[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=a[e.charCodeAt(t)]<<10|a[e.charCodeAt(t+1)]<<4|a[e.charCodeAt(t+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s},t.fromByteArray=function(e){for(var t,r=e.length,n=r%3,i="",a=[],c=0,f=r-n;cf?f:c+16383));return 1===n?(t=e[r-1],i+=s[t>>2],i+=s[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=s[t>>10],i+=s[t>>4&63],i+=s[t<<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=r?i-1:0,d=r?-1:1,l=e[t+h];for(h+=d,o=l&(1<<-u)-1,l>>=-u,u+=a;u>0;o=256*o+e[t+h],h+=d,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=n;u>0;s=256*s+e[t+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,n),o-=f}return(l?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,r,n,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=n?0:o-1,p=n?1:-1,b=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=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=(t*c-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[r+l]=255&a,l+=p,a/=256,i-=8);for(s=s<0;e[r+l]=255&s,l+=p,s/=256,f-=8);e[r+l-p]|=128*b}},function(e,t){},function(e,t,r){"use strict";function n(e,t,r){e.copy(t,r)}var i=r(9).Buffer;e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}return e.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},e.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},e.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},e.prototype.clear=function(){this.head=this.tail=null,this.length=0},e.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},e.prototype.concat=function(e){if(0===this.length)return i.alloc(0);if(1===this.length)return this.head.data;for(var t=i.allocUnsafe(e>>>0),r=this.head,o=0;r;)n(r.data,t,o),o+=r.data.length,r=r.next;return t},e}()},function(e,t,r){(function(e,t){!function(e,r){"use strict";function n(e){delete a[e]}function i(e){if(c)setTimeout(i,0,e);else{var t=a[e];if(t){c=!0;try{!function(e){var t=e.callback,n=e.args;switch(n.length){case 0:t();break;case 1:t(n[0]);break;case 2:t(n[0],n[1]);break;case 3:t(n[0],n[1],n[2]);break;default:t.apply(r,n)}}(t)}finally{n(e),c=!1}}}}if(!e.setImmediate){var o,s=1,a={},c=!1,f=e.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(e);u=u&&u.setTimeout?u:e,"[object process]"==={}.toString.call(e.process)?o=function(e){t.nextTick(function(){i(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,r=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=r,t}}()?function(){var t="setImmediate$"+Math.random()+"$",r=function(r){r.source===e&&"string"==typeof r.data&&0===r.data.indexOf(t)&&i(+r.data.slice(t.length))};e.addEventListener?e.addEventListener("message",r,!1):e.attachEvent("onmessage",r),o=function(r){e.postMessage(t+r,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){i(e.data)},o=function(t){e.port2.postMessage(t)}}():f&&"onreadystatechange"in f.createElement("script")?function(){var e=f.documentElement;o=function(t){var r=f.createElement("script");r.onreadystatechange=function(){i(t),r.onreadystatechange=null,e.removeChild(r),r=null},e.appendChild(r)}}():o=function(e){setTimeout(i,0,e)},u.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;rn(e,(e,r,n)=>t(r,n)).then(()=>e))},function(e,t,r){"use strict";e.exports=((e,t,r)=>new Promise((n,i)=>{const o=e[Symbol.iterator]();let s=0;const a=e=>{const r=o.next();r.done?n(e):Promise.all([e,r.value]).then(e=>{a(t(e[0],e[1],s++))}).catch(i)};a(r)}))},function(e,t,r){"use strict";e.exports=class{constuctor(e){}append(e){}merge(e){}get(e){}has(e){}get values(){}get length(){}}},function(e,t,r){"use strict";r(24);const n=r(25),i=r(81),o=r(26),s=r(43),a=r(27),c=r(44),f=r(83),u=r(84),h=(e,t)=>e.slice(e.length-t,e.length);e.exports=class{static toMultihash(e,t){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw s.LogNotDefinedError();if(t.values.length<1)throw new Error("Can't serialize an empty log");return e.object.put(t.toBuffer()).then(e=>e.toJSON().multihash)}static fromMultihash(e,t,r=-1,c,f){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw new Error(`Invalid hash: ${t}`);return e.object.get(t,{enc:"base58"}).then(e=>JSON.parse(e.toJSON().data)).then(t=>{if(!t.heads||!t.id)throw s.NotALogError();return i.fetchAll(e,t.heads,r,c,null,f).then(e=>{const r=e.reduce((e,t)=>t.clock.time>e.time?new o(t.clock.id,t.clock.time):e,new o(t.id)),i=e.slice().sort(n.compare),s=i.filter(e=>t.heads.includes(e.hash));return{id:t.id,values:i,heads:s,clock:r}})})}static fromEntryHash(e,t,r,n=-1,o,c){if(!a(e))throw s.IpfsNotDefinedError();if(!a(t))throw new Error("'entryHash' must be defined");n=n>-1?Math.max(n,1):n;const f=o;return i.fetchParallel(e,[t],n,f,null,null,c).then(e=>({values:n>-1?h(e,n):e}))}static fromJSON(e,t,r=-1,o,c,f){if(!a(e))throw s.ImmutableDBNotDefinedError();return i.fetchParallel(e,t.heads.map(e=>e.hash),r,[],16,c,f).then(e=>{const r=e.slice().sort(n.compare);return e.filter(e=>t.heads.includes(e.hash)),{id:t.id,values:r,heads:t.heads}})}static fromEntry(e,t,r=-1,o,f,h,d){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(t)&&!n.isEntry(t))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(t)||(t=[t]),r=r>-1?Math.max(r,t.length):r;const l=o?o.map(e=>e.hash?e.hash:e):o,p=t.map(e=>e.hash);return i.fetchParallel(e,p,r,l,null,null,d).then(e=>{var i=t.concat(e),o=c(i,"hash").sort(n.compare);const s=o.slice(r>-1?-r:-o.length),a=((e,t)=>{var r=e.slice(t.length,e.length);return t.concat(r)})(s,u(s,t,"hash"));return{id:a[a.length-1].id,values:a}})}static expandFrom(e,t,r,n=-1){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw s.LogNotDefinedError();if(!a(r))throw new Error("'entries' must be given as argument");Array.isArray(r)||(r=[r]);const o=r.map(e=>e.next).filter(e=>e.length>0);return 0===o.length?Promise.resolve({values:t.values}):i.fetchParallel(e,o,n,t.values).then(e=>({values:t.merge(e.slice(0,n))}))}static expand(e,t,r=-1){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw s.LogNotDefinedError();return 0===t.tailHashes.length?Promise.resolve({values:t.values}):i.fetchParallel(e,t.tailHashes,r,t.values).then(e=>{const i=r>-1?t.values.length+r:-1,o=t.values.concat(e).sort(n.compare),s=i>-1?o.slice(-i):o.slice(),a=u(s,t.values,"hash").sort(n.compare),h=u(t.values,s,"hash").sort(n.compare),d=f(t.values,s,"hash").sort(n.compare),l=i-(d.length+a.length),p=(e,t)=>{var r=[];return r=e.concat(t),c(r,"hash").sort(n.compare)};return{values:p(a,p(d,l>-1?h.slice(-l):h))}})}}},function(e,t,r){"use strict";const n=r(82),i=r(24),o=r(25);let s=0,a=0;class c{static fetchParallel(e,t,r,n=[],o,s,a){const f=(e,t)=>e.concat(t);return i(t,t=>c.fetchAll(e,t,r,n,s,a),{concurrency:Math.max(o||t.length,1)}).then(e=>e.reduce(f,[]))}static fetchAll(e,t,r,i=[],c=null,f){let u=[],h={},d=Array.isArray(t)?t.slice():[t];const l=e=>d.push(e);i.forEach(e=>h[e.hash]=e);return n(()=>d.length>0&&(u.length{const t=d.shift();return h[t]?Promise.resolve():new Promise((r,n)=>{const i=c?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${t}', request timed out (${c}ms)`),r()},c):null;s++,o.fromMultihash(e,t).then(e=>{clearTimeout(i),o.isEntry(e)&&(e.next.forEach(l),u.push(e),h[t]=e,a++,f&&f(t,e,u.length))}).then(r).catch(e=>{r()})})}).then(()=>u)}}e.exports=c},function(e,t,r){"use strict";const n=e=>new Promise(t=>{t(e())});e.exports=((e,t)=>n(function r(){if(e())return n(t).then(r)}))},function(e,t,r){"use strict";e.exports=function(e,t,r){var n={},i={};return e.forEach(e=>i[r?e[r]:e]=!0),t.reduce((e,t)=>{var o=void 0!==i[r?t[r]:t],s=void 0!==n[r?t[r]:t];return o&&!s&&(e.push(t),n[r?t[r]:t]=!0),e},[])}},function(e,t,r){"use strict";e.exports=function(e,t,r){var n={},i={};return e.forEach(e=>i[r?e[r]:e]=!0),t.reduce((e,t)=>{var o=void 0!==i[r?t[r]:t],s=void 0!==n[r?t[r]:t];return o||s||(e.push(t),n[r?t[r]:t]=!0),e},[])}},function(e,t){e.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(e,t,r){"use strict";var n=t,i=r(8),o=r(11),s=r(47);n.assert=o,n.toArray=s.toArray,n.zero2=s.zero2,n.toHex=s.toHex,n.encode=s.encode,n.getNAF=function(e,t){for(var r=[],n=1<=0;){var o;if(i.isOdd()){var s=i.andln(n-1);o=s>(n>>1)-1?(n>>1)-s:s,i.isubn(o)}else o=0;r.push(o);for(var a=0!==i.cmpn(0)&&0===i.andln(n-1)?t+1:1,c=1;c0||t.cmpn(-i)>0;){var o=e.andln(3)+n&3,s=t.andln(3)+i&3;3===o&&(o=-1),3===s&&(s=-1);var a;a=0==(1&o)?0:3!=(f=e.andln(7)+n&7)&&5!==f||2!==s?o:-o,r[0].push(a);var c;if(0==(1&s))c=0;else{var f;c=3!=(f=t.andln(7)+i&7)&&5!==f||2!==o?s:-s}r[1].push(c),2*n===a+1&&(n=1-n),2*i===c+1&&(i=1-i),e.iushrn(1),t.iushrn(1)}return r},n.cachedProperty=function(e,t,r){var n="_"+t;e.prototype[t]=function(){return void 0!==this[n]?this[n]:this[n]=r.call(this)}},n.parseBytes=function(e){return"string"==typeof e?n.toArray(e,"hex"):e},n.intFromLE=function(e){return new i(e,"hex","le")}},function(e,t){},function(e,t,r){function n(e){this.rand=e}var i;if(e.exports=function(e){return i||(i=new n(null)),i.generate(e)},e.exports.Rand=n,n.prototype.generate=function(e){return this._rand(e)},n.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var t=new Uint8Array(e),r=0;r0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function i(e,t){this.curve=e,this.type=t,this.precomputed=null}var o=r(8),s=r(3).utils,a=s.getNAF,c=s.getJSF,f=s.assert;e.exports=n,n.prototype.point=function(){throw new Error("Not implemented")},n.prototype.validate=function(){throw new Error("Not implemented")},n.prototype._fixedNafMul=function(e,t){f(e.precomputed);var r=e._getDoubles(),n=a(t,1),i=(1<=s;t--)c=(c<<1)+n[t];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(t=0;c>=0&&0===o[c];c--)t++;if(c>=0&&t++,s=s.dblp(t),c<0)break;var u=o[c];f(0!==u),s="affine"===e.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"===e.type?s.toP():s},n.prototype._wnafMulAdd=function(e,t,r,n,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=[t[l],null,null,t[p]];0===t[l].y.cmp(t[p].y)?(b[1]=t[l].add(t[p]),b[2]=t[l].toJ().mixedAdd(t[p].neg())):0===t[l].y.cmp(t[p].y.redNeg())?(b[1]=t[l].toJ().mixedAdd(t[p]),b[2]=t[l].add(t[p].neg())):(b[1]=t[l].toJ().mixedAdd(t[p]),b[2]=t[l].toJ().mixedAdd(t[p].neg()));var y=[-3,-1,-5,-7,0,7,5,1,3],g=c(r[l],r[p]);u=Math.max(g[0].length,u),f[l]=new Array(u),f[p]=new Array(u);for(var m=0;m=0;h--){for(var k=0;h>=0;){var E=!0;for(m=0;m=0&&k++,w=w.dblp(k),h<0)break;for(m=0;m0?x=s[m][M-1>>1]:M<0&&(x=s[m][-M-1>>1].neg()),w="affine"===x.type?w.mixedAdd(x):w.add(x))}}for(h=0;h=Math.ceil((e.bitLength()+1)/t.step)},i.prototype._getDoubles=function(e,t){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],n=this,i=0;i=0&&(o=t,s=r),n.negative&&(n=n.neg(),i=i.neg()),o.negative&&(o=o.neg(),s=s.neg()),[{a:n,b:i},{a:o,b:s}]},n.prototype._endoSplit=function(e){var t=this.endo.basis,r=t[0],n=t[1],i=n.b.mul(e).divRound(this.n),o=r.b.neg().mul(e).divRound(this.n),s=i.mul(r.a),a=o.mul(n.a),c=i.mul(r.b),f=o.mul(n.b);return{k1:e.sub(s).sub(a),k2:c.add(f).neg()}},n.prototype.pointFromX=function(e,t){(e=new c(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),n=r.redSqrt();if(0!==n.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var i=n.fromRed().isOdd();return(t&&!i||!t&&i)&&(n=n.redNeg()),this.point(e,n)},n.prototype.validate=function(e){if(e.inf)return!0;var t=e.x,r=e.y,n=this.a.redMul(t),i=t.redSqr().redMul(t).redIAdd(n).redIAdd(this.b);return 0===r.redSqr().redISub(i).cmpn(0)},n.prototype._endoWnafMulAdd=function(e,t,r){for(var n=this._endoWnafT1,i=this._endoWnafT2,o=0;o":""},i.prototype.isInfinity=function(){return this.inf},i.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var t=this.y.redSub(e.y);0!==t.cmpn(0)&&(t=t.redMul(this.x.redSub(e.x).redInvm()));var r=t.redSqr().redISub(this.x).redISub(e.x),n=t.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,n)},i.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var t=this.curve.a,r=this.x.redSqr(),n=e.redInvm(),i=r.redAdd(r).redIAdd(r).redIAdd(t).redMul(n),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(e){return e=new c(e,16),this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},i.prototype.mulAdd=function(e,t,r){var n=[this,t],i=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i):this.curve._wnafMulAdd(1,n,i,2)},i.prototype.jmulAdd=function(e,t,r){var n=[this,t],i=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i,!0):this.curve._wnafMulAdd(1,n,i,2,!0)},i.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},i.prototype.neg=function(e){if(this.inf)return this;var t=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var r=this.precomputed,n=function(e){return e.neg()};t.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(n)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(n)}}}return t},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),n.prototype.jpoint=function(e,t,r){return new o(this,e,t,r)},o.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),t=e.redSqr(),r=this.x.redMul(t),n=this.y.redMul(t).redMul(e);return this.curve.point(r,n)},o.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},o.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.z.redSqr(),r=this.z.redSqr(),n=this.x.redMul(t),i=e.x.redMul(r),o=this.y.redMul(t.redMul(e.z)),s=e.y.redMul(r.redMul(this.z)),a=n.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=n.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(e.z).redMul(a);return this.curve.jpoint(d,l,p)},o.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var t=this.z.redSqr(),r=this.x,n=e.x.redMul(t),i=this.y,o=e.y.redMul(t).redMul(this.z),s=r.redSub(n),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=r.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(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var t=this,r=0;r=0)return!1;if(r.redIAdd(i),0===this.x.cmp(r))return!0}return!1},o.prototype.inspect=function(){return this.isInfinity()?"":""},o.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},function(e,t,r){"use strict";function n(e){c.call(this,"mont",e),this.a=new s(e.a,16).toRed(this.red),this.b=new s(e.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(e,t,r){c.BasePoint.call(this,e,"projective"),null===t&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new s(t,16),this.z=new s(r,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=r(22),s=r(8),a=r(4),c=o.base,f=r(3).utils;a(n,c),e.exports=n,n.prototype.validate=function(e){var t=e.normalize().x,r=t.redSqr(),n=r.redMul(t).redAdd(r.redMul(this.a)).redAdd(t);return 0===n.redSqrt().redSqr().cmp(n)},a(i,c.BasePoint),n.prototype.decodePoint=function(e,t){return this.point(f.toArray(e,t),1)},n.prototype.point=function(e,t){return new i(this,e,t)},n.prototype.pointFromJSON=function(e){return i.fromJSON(this,e)},i.prototype.precompute=function(){},i.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},i.fromJSON=function(e,t){return new i(e,t[0],t[1]||e.one)},i.prototype.inspect=function(){return this.isInfinity()?"":""},i.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},i.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),t=this.x.redSub(this.z).redSqr(),r=e.redSub(t),n=e.redMul(t),i=r.redMul(t.redAdd(this.curve.a24.redMul(r)));return this.curve.point(n,i)},i.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.diffAdd=function(e,t){var r=this.x.redAdd(this.z),n=this.x.redSub(this.z),i=e.x.redAdd(e.z),o=e.x.redSub(e.z).redMul(r),s=i.redMul(n),a=t.z.redMul(o.redAdd(s).redSqr()),c=t.x.redMul(o.redISub(s).redSqr());return this.curve.point(a,c)},i.prototype.mul=function(e){for(var t=e.clone(),r=this,n=this.curve.point(null,null),i=[];0!==t.cmpn(0);t.iushrn(1))i.push(t.andln(1));for(var o=i.length-1;o>=0;o--)0===i[o]?(r=r.diffAdd(n,this),n=n.dbl()):(n=r.diffAdd(n,this),r=r.dbl());return n},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(e){return 0===this.getX().cmp(e.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(e,t,r){"use strict";function n(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,f.call(this,"edwards",e),this.a=new a(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new a(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new a(e.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|e.c)}function i(e,t,r,n,i){f.BasePoint.call(this,e,"projective"),null===t&&null===r&&null===n?(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(t,16),this.y=new a(r,16),this.z=n?new a(n,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=r(22),s=r(3),a=r(8),c=r(4),f=o.base,u=s.utils.assert;c(n,f),e.exports=n,n.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},n.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},n.prototype.jpoint=function(e,t,r,n){return this.point(e,t,r,n)},n.prototype.pointFromX=function(e,t){(e=new a(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr(),n=this.c2.redSub(this.a.redMul(r)),i=this.one.redSub(this.c2.redMul(this.d).redMul(r)),o=n.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(t&&!c||!t&&c)&&(s=s.redNeg()),this.point(e,s)},n.prototype.pointFromY=function(e,t){(e=new a(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr(),n=r.redSub(this.one),i=r.redMul(this.d).redAdd(this.one),o=n.redMul(i.redInvm());if(0===o.cmp(this.zero)){if(t)throw new Error("invalid point");return this.point(this.zero,e)}var s=o.redSqrt();if(0!==s.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");return s.isOdd()!==t&&(s=s.redNeg()),this.point(s,e)},n.prototype.validate=function(e){if(e.isInfinity())return!0;e.normalize();var t=e.x.redSqr(),r=e.y.redSqr(),n=t.redMul(this.a).redAdd(r),i=this.c2.redMul(this.one.redAdd(this.d.redMul(t).redMul(r)));return 0===n.cmp(i)},c(i,f.BasePoint),n.prototype.pointFromJSON=function(e){return i.fromJSON(this,e)},n.prototype.point=function(e,t,r,n){return new i(this,e,t,r,n)},i.fromJSON=function(e,t){return new i(e,t[0],t[1],t[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 e=this.x.redSqr(),t=this.y.redSqr(),r=this.z.redSqr();r=r.redIAdd(r);var n=this.curve._mulA(e),i=this.x.redAdd(this.y).redSqr().redISub(e).redISub(t),o=n.redAdd(t),s=o.redSub(r),a=n.redSub(t),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 e,t,r,n=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)e=n.redSub(i).redSub(o).redMul(s.redSub(this.curve.two)),t=s.redMul(f.redSub(o)),r=s.redSqr().redSub(s).redSub(s);else{var a=this.z.redSqr(),c=s.redSub(a).redISub(a);e=n.redSub(i).redISub(o).redMul(c),t=s.redMul(f.redSub(o)),r=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);e=this.curve._mulC(n.redISub(f)).redMul(c),t=this.curve._mulC(f).redMul(i.redISub(o)),r=f.redMul(c)}return this.curve.point(e,t,r)},i.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},i.prototype._extAdd=function(e){var t=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),r=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),n=this.t.redMul(this.curve.dd).redMul(e.t),i=this.z.redMul(e.z.redAdd(e.z)),o=r.redSub(t),s=i.redSub(n),a=i.redAdd(n),c=r.redAdd(t),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(e){var t,r,n=this.z.redMul(e.z),i=n.redSqr(),o=this.x.redMul(e.x),s=this.y.redMul(e.y),a=this.curve.d.redMul(o).redMul(s),c=i.redSub(a),f=i.redAdd(a),u=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(o).redISub(s),h=n.redMul(c).redMul(u);return this.curve.twisted?(t=n.redMul(f).redMul(s.redSub(this.curve._mulA(o))),r=c.redMul(f)):(t=n.redMul(f).redMul(s.redSub(o)),r=this.curve._mulC(c).redMul(f)),this.curve.point(h,t,r)},i.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},i.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},i.prototype.mulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!1)},i.prototype.jmulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!0)},i.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),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(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},i.prototype.eqXToP=function(e){var t=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(t))return!0;for(var r=e.clone(),n=this.curve.redN.redMul(this.z);;){if(r.iadd(this.curve.n),r.cmp(this.curve.p)>=0)return!1;if(t.redIAdd(n),0===this.x.cmp(t))return!0}return!1},i.prototype.toP=i.prototype.normalize,i.prototype.mixedAdd=i.prototype.add},function(e,t,r){"use strict";function n(e){"short"===e.type?this.curve=new a.curve.short(e):"edwards"===e.type?this.curve=new a.curve.edwards(e):this.curve=new a.curve.mont(e),this.g=this.curve.g,this.n=this.curve.n,this.hash=e.hash,c(this.g.validate(),"Invalid curve"),c(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function i(e,t){Object.defineProperty(o,e,{configurable:!0,enumerable:!0,get:function(){var r=new n(t);return Object.defineProperty(o,e,{configurable:!0,enumerable:!0,value:r}),r}})}var o=t,s=r(28),a=r(3),c=a.utils.assert;o.PresetCurve=n,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=r(101)}catch(e){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(e,t,r){"use strict";t.sha1=r(96),t.sha224=r(97),t.sha256=r(49),t.sha384=r(98),t.sha512=r(50)},function(e,t,r){"use strict";function n(){if(!(this instanceof n))return new n;h.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}var i=r(5),o=r(16),s=r(48),a=i.rotl32,c=i.sum32,f=i.sum32_5,u=s.ft_1,h=o.BlockHash,d=[1518500249,1859775393,2400959708,3395469782];i.inherits(n,h),e.exports=n,n.blockSize=512,n.outSize=160,n.hmacStrength=80,n.padLength=64,n.prototype._update=function(e,t){for(var r=this.W,n=0;n<16;n++)r[n]=e[t+n];for(;nthis.blockSize&&(e=(new this.Hash).update(e).digest()),o(e.length<=this.blockSize);for(var t=e.length;t0))return a.iaddn(1),this.keyFromPrivate(a)}},n.prototype._truncateToN=function(e,t){var r=8*e.byteLength()-this.n.bitLength();return r>0&&(e=e.ushrn(r)),!t&&e.cmp(this.n)>=0?e.sub(this.n):e},n.prototype.sign=function(e,t,r,n){"object"==typeof r&&(n=r,r=null),n||(n={}),t=this.keyFromPrivate(t,r),e=this._truncateToN(new i(e,16));for(var s=this.n.byteLength(),a=t.getPrivate().toArray("be",s),c=e.toArray("be",s),u=new o({hash:this.hash,entropy:a,nonce:c,pers:n.pers,persEnc:n.persEnc||"utf8"}),h=this.n.sub(new i(1)),d=0;;d++){var l=n.k?n.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(t.getPrivate()).iadd(e));if(0!==(g=g.umod(this.n)).cmpn(0)){var m=(p.getY().isOdd()?1:0)|(0!==b.cmp(y)?2:0);return n.canonical&&g.cmp(this.nh)>0&&(g=this.n.sub(g),m^=1),new f({r:y,s:g,recoveryParam:m})}}}}}},n.prototype.verify=function(e,t,r,n){e=this._truncateToN(new i(e,16)),r=this.keyFromPublic(r,n);var o=(t=new f(t,"hex")).r,s=t.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(e).umod(this.n),u=a.mul(o).umod(this.n);if(!this.curve._maxwellTrick){return!(h=this.g.mulAdd(c,r.getPublic(),u)).isInfinity()&&0===h.getX().umod(this.n).cmp(o)}var h;return!(h=this.g.jmulAdd(c,r.getPublic(),u)).isInfinity()&&h.eqXToP(o)},n.prototype.recoverPubKey=function(e,t,r,n){a((3&r)===r,"The recovery param is more than two bits"),t=new f(t,n);var o=this.n,s=new i(e),c=t.r,u=t.s,h=1&r,d=r>>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=t.r.invm(o),p=o.sub(s).mul(l).umod(o),b=u.mul(l).umod(o);return this.g.mulAdd(p,c,b)},n.prototype.getKeyRecoveryParam=function(e,t,r,n){if(null!==(t=new f(t,n)).recoveryParam)return t.recoveryParam;for(var i=0;i<4;i++){var o;try{o=this.recoverPubKey(e,t,i)}catch(e){continue}if(o.eq(r))return i}throw new Error("Unable to find valid recovery factor")}},function(e,t,r){"use strict";function n(e){if(!(this instanceof n))return new n(e);this.hash=e.hash,this.predResist=!!e.predResist,this.outLen=this.hash.outSize,this.minEntropy=e.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var t=o.toArray(e.entropy,e.entropyEnc||"hex"),r=o.toArray(e.nonce,e.nonceEnc||"hex"),i=o.toArray(e.pers,e.persEnc||"hex");s(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,r,i)}var i=r(28),o=r(47),s=r(11);e.exports=n,n.prototype._init=function(e,t,r){var n=e.concat(t).concat(r);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(e.concat(r||[])),this._reseed=1},n.prototype.generate=function(e,t,r,n){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof t&&(n=r,r=t,t=null),r&&(r=o.toArray(r,n||"hex"),this._update(r));for(var i=[];i.length"}},function(e,t,r){"use strict";function n(e,t){if(e instanceof n)return e;this._importDER(e,t)||(f(e.r&&e.s,"Signature without r or s"),this.r=new a(e.r,16),this.s=new a(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}function i(e,t){var r=e[t.place++];if(!(128&r))return r;for(var n=15&r,i=0,o=0,s=t.place;o>>3);for(e.push(128|r);--r;)e.push(t>>>(r<<3)&255);e.push(t)}}var a=r(8),c=r(3).utils,f=c.assert;e.exports=n,n.prototype._importDER=function(e,t){e=c.toArray(e,t);var r=new function(){this.place=0};if(48!==e[r.place++])return!1;if(i(e,r)+r.place!==e.length)return!1;if(2!==e[r.place++])return!1;var n=i(e,r),o=e.slice(r.place,n+r.place);if(r.place+=n,2!==e[r.place++])return!1;var s=i(e,r);if(e.length!==s+r.place)return!1;var f=e.slice(r.place,s+r.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},n.prototype.toDER=function(e){var t=this.r.toArray(),r=this.s.toArray();for(128&t[0]&&(t=[0].concat(t)),128&r[0]&&(r=[0].concat(r)),t=o(t),r=o(r);!(r[0]||128&r[1]);)r=r.slice(1);var n=[2];s(n,t.length),(n=n.concat(t)).push(2),s(n,r.length);var i=n.concat(r),a=[48];return s(a,i.length),a=a.concat(i),c.encode(a,e)}},function(e,t,r){"use strict";function n(e){if(a("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof n))return new n(e);e=o.curves[e].curve;this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=i.sha512}var i=r(28),o=r(3),s=o.utils,a=s.assert,c=s.parseBytes,f=r(107),u=r(108);e.exports=n,n.prototype.sign=function(e,t){e=c(e);var r=this.keyFromSecret(t),n=this.hashInt(r.messagePrefix(),e),i=this.g.mul(n),o=this.encodePoint(i),s=this.hashInt(o,r.pubBytes(),e).mul(r.priv()),a=n.add(s).umod(this.curve.n);return this.makeSignature({R:i,S:a,Rencoded:o})},n.prototype.verify=function(e,t,r){e=c(e),t=this.makeSignature(t);var n=this.keyFromPublic(r),i=this.hashInt(t.Rencoded(),n.pubBytes(),e),o=this.g.mul(t.S());return t.R().add(n.pub().mul(i)).eq(o)},n.prototype.hashInt=function(){for(var e=this.hash(),t=0;tthis.quota)throw new a;if(y(o,g,"utf8"),i||((h=new s(r,this._keys.push(e)-1)).size=m,this._metaKeyMap[e]=h,this.length+=1,this._bytesInUse+=m),f)return n=new c(e,p,t,this._eventUrl),this.emit("storage",n)},r.prototype.getItem=function(e){var t,r;return e=u(e),(r=this._metaKeyMap[e])?(t=b.join(this._location,r.key),p.readFileSync(t,"utf8")):null},r.prototype._getStat=function(e){var t;e=u(e),t=b.join(this._location,encodeURIComponent(e));try{return p.statSync(t)}catch(e){return null}},r.prototype.removeItem=function(e){var t,r,n,i,o,s,a,f;if(e=u(e),s=this._metaKeyMap[e]){a=null,(n=l.EventEmitter.listenerCount(this,"storage"))&&(a=this.getItem(e)),delete this._metaKeyMap[e],this.length-=1,this._bytesInUse-=s.size,r=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(r),n)return t=new c(e,a,null,this._eventUrl),this.emit("storage",t)}},r.prototype.key=function(e){return this._keys[e]},r.prototype.clear=function(){var e;if(f(this._location),this._metaKeyMap=d(),this._keys=[],this.length=0,this._bytesInUse=0,l.EventEmitter.listenerCount(this,"storage"))return e=new c(null,null,null,this._eventUrl),this.emit("storage",e)},r.prototype._getBytesInUse=function(){return this._bytesInUse},r.prototype._deleteLocation=function(){return delete n[this._location],h(this._location),this._metaKeyMap={},this._keys=[],this.length=0,this._bytesInUse=0},r}(l.EventEmitter),n=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return g(t,o),t.prototype.setItem=function(e,r){var n;return n=JSON.stringify(r),t.__super__.setItem.call(this,e,n)},t.prototype.getItem=function(e){return JSON.parse(t.__super__.getItem.call(this,e))},t}(),t.LocalStorage=o,t.JSONStorage=n,t.QUOTA_EXCEEDED_ERR=a}).call(this)}).call(t,r(0))},function(e,t,r){"use strict";(function(t,n,i){function o(e){return e+"."+c(t).hash(String(n.pid)).hash(String(++u)).result()}e.exports=function(e,t,r,c){r instanceof Function&&(c=r,r=null),r||(r={}),s.realpath(e,function(u,h){!function(e,t,r,c){function u(){a([[h,d,t,r.mode,r.encoding||"utf8"],r.chown&&[s,s.chown,d,r.chown.uid,r.chown.gid],r.mode&&[s,s.chmod,d,r.mode],[s,s.rename,d,e]],function(e){e?s.unlink(d,function(){c(e)}):c()})}function h(e,t,n,o,a){s.open(e,"w",r.mode,function(e,r){function n(e){if(e)return a(e);s.fsync(r,function(e){if(e)return a(e);s.close(r,a)})}return e?a(e):i.isBuffer(t)?s.write(r,t,0,t.length,0,n):null!=t?s.write(r,String(t),0,String(o),n):n()})}var d=o(e);r.mode&&r.chown?u():s.stat(e,function(e,t){return e||!t?u():((r=f({},r)).mode||(r.mode=t.mode),!r.chown&&n.getuid&&(r.chown={uid:t.uid,gid:t.gid}),u())})}(h||e,t,r,c)})},e.exports.sync=function(e,t,r){r||(r={});try{e=s.realpathSync(e)}catch(e){}var a=o(e);try{if(!r.mode||!r.chown)try{var c=s.statSync(e);(r=f({},r)).mode||(r.mode=c.mode),!r.chown&&n.getuid&&(r.chown={uid:c.uid,gid:c.gid})}catch(e){}var u=s.openSync(a,"w",r.mode);i.isBuffer(t)?s.writeSync(u,t,0,t.length,0):null!=t&&s.writeSync(u,String(t),0,String(r.encoding||"utf8")),s.fsyncSync(u),s.closeSync(u),r.chown&&s.chownSync(a,r.chown.uid,r.chown.gid),r.mode&&s.chmodSync(a,r.mode),s.renameSync(a,e)}catch(e){try{s.unlinkSync(a)}catch(e){}throw e}},e.exports._getTmpname=o;var s=r(111),a=r(122).chain,c=r(125),f=Object.assign||r(6)._extend,u=0}).call(t,"/index.js",r(0),r(1).Buffer)},function(e,t,r){(function(t){function n(e){function r(t){return p.apply(e,t)}function s(e,t){return this instanceof s?(y.apply(this,arguments),this):s.apply(Object.create(s.prototype),arguments)}function f(e,t){return this instanceof f?(g.apply(this,arguments),this):f.apply(Object.create(f.prototype),arguments)}function u(e,t,r,n){function s(e,t,r,n){return m(e,t,r,function(a,c){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof n&&n.apply(this,arguments),o()):i([s,[e,t,r,n]])})}return"function"==typeof r&&(n=r,r=null),s(e,t,r,n)}a(e),e.gracefulify=n,e.FileReadStream=s,e.FileWriteStream=f,e.createReadStream=function(e,t){return new s(e,t)},e.createWriteStream=function(e,t){return new f(e,t)};var h=e.readFile;e.readFile=function(e,t,r){function n(e,t,r){return h(e,t,function(s){!s||"EMFILE"!==s.code&&"ENFILE"!==s.code?("function"==typeof r&&r.apply(this,arguments),o()):i([n,[e,t,r]])})}return"function"==typeof t&&(r=t,t=null),n(e,t,r)};var d=e.writeFile;e.writeFile=function(e,t,r,n){function s(e,t,r,n){return d(e,t,r,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof n&&n.apply(this,arguments),o()):i([s,[e,t,r,n]])})}return"function"==typeof r&&(n=r,r=null),s(e,t,r,n)};var l=e.appendFile;l&&(e.appendFile=function(e,t,r,n){function s(e,t,r,n){return l(e,t,r,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof n&&n.apply(this,arguments),o()):i([s,[e,t,r,n]])})}return"function"==typeof r&&(n=r,r=null),s(e,t,r,n)});var p=e.readdir;if(e.readdir=function(e,t,n){var s=[e];return"function"!=typeof t?s.push(t):n=t,s.push(function(e,t){t&&t.sort&&t.sort(),!e||"EMFILE"!==e.code&&"ENFILE"!==e.code?("function"==typeof n&&n.apply(this,arguments),o()):i([r,[s]])}),r(s)},"v0.8"===t.version.substr(0,4)){var b=c(e);s=b.ReadStream,f=b.WriteStream}var y=e.ReadStream;(s.prototype=Object.create(y.prototype)).open=function(){var e=this;u(e.path,e.flags,e.mode,function(t,r){t?(e.autoClose&&e.destroy(),e.emit("error",t)):(e.fd=r,e.emit("open",r),e.read())})};var g=e.WriteStream;(f.prototype=Object.create(g.prototype)).open=function(){var e=this;u(e.path,e.flags,e.mode,function(t,r){t?(e.destroy(),e.emit("error",t)):(e.fd=r,e.emit("open",r))})},e.ReadStream=s,e.WriteStream=f;var m=e.open;return e.open=u,e}function i(e){h("ENQUEUE",e[0].name,e[1]),f.push(e)}function o(){var e=f.shift();e&&(h("RETRY",e[0].name,e[1]),e[0].apply(null,e[1]))}var s=r(14),a=r(112),c=r(114),f=[],u=r(6),h=function(){};u.debuglog?h=u.debuglog("gfs4"):/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&(h=function(){var e=u.format.apply(u,arguments);e="GFS4: "+e.split(/\n/).join("\nGFS4: "),console.error(e)}),/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&t.on("exit",function(){h(f),r(52).equal(f.length,0)}),e.exports=n(r(51)),Object({NODE_ENV:void 0}).TEST_GRACEFUL_FS_GLOBAL_PATCH&&(e.exports=n(s)),e.exports.close=s.close=function(e){return function(t,r){return e.call(s,t,function(e){e||o(),"function"==typeof r&&r.apply(this,arguments)})}}(s.close),e.exports.closeSync=s.closeSync=function(e){return function(t){var r=e.apply(s,arguments);return o(),r}}(s.closeSync)}).call(t,r(0))},function(e,t,r){(function(t){function n(e){return e?function(t,r,n){return e.call(u,t,r,function(e){f(e)&&(e=null),n&&n.apply(this,arguments)})}:e}function i(e){return e?function(t,r){try{return e.call(u,t,r)}catch(e){if(!f(e))throw e}}:e}function o(e){return e?function(t,r,n,i){return e.call(u,t,r,n,function(e){f(e)&&(e=null),i&&i.apply(this,arguments)})}:e}function s(e){return e?function(t,r,n){try{return e.call(u,t,r,n)}catch(e){if(!f(e))throw e}}:e}function a(e){return e?function(t,r){return e.call(u,t,function(e,t){if(!t)return r.apply(this,arguments);t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296),r&&r.apply(this,arguments)})}:e}function c(e){return e?function(t){var r=e.call(u,t);return r.uid<0&&(r.uid+=4294967296),r.gid<0&&(r.gid+=4294967296),r}:e}function f(e){if(!e)return!0;if("ENOSYS"===e.code)return!0;return!(t.getuid&&0===t.getuid()||"EINVAL"!==e.code&&"EPERM"!==e.code)}var u=r(51),h=r(113),d=t.cwd,l=null,p=Object({NODE_ENV:void 0}).GRACEFUL_FS_PLATFORM||t.platform;t.cwd=function(){return l||(l=d.call(t)),l};try{t.cwd()}catch(e){}var b=t.chdir;t.chdir=function(e){l=null,b.call(t,e)},e.exports=function(e){h.hasOwnProperty("O_SYMLINK")&&t.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&function(e){e.lchmod=function(t,r,n){e.open(t,h.O_WRONLY|h.O_SYMLINK,r,function(t,i){t?n&&n(t):e.fchmod(i,r,function(t){e.close(i,function(e){n&&n(t||e)})})})},e.lchmodSync=function(t,r){var n,i=e.openSync(t,h.O_WRONLY|h.O_SYMLINK,r),o=!0;try{n=e.fchmodSync(i,r),o=!1}finally{if(o)try{e.closeSync(i)}catch(e){}else e.closeSync(i)}return n}}(e),e.lutimes||function(e){h.hasOwnProperty("O_SYMLINK")?(e.lutimes=function(t,r,n,i){e.open(t,h.O_SYMLINK,function(t,o){t?i&&i(t):e.futimes(o,r,n,function(t){e.close(o,function(e){i&&i(t||e)})})})},e.lutimesSync=function(t,r,n){var i,o=e.openSync(t,h.O_SYMLINK),s=!0;try{i=e.futimesSync(o,r,n),s=!1}finally{if(s)try{e.closeSync(o)}catch(e){}else e.closeSync(o)}return i}):(e.lutimes=function(e,r,n,i){i&&t.nextTick(i)},e.lutimesSync=function(){})}(e),e.chown=o(e.chown),e.fchown=o(e.fchown),e.lchown=o(e.lchown),e.chmod=n(e.chmod),e.fchmod=n(e.fchmod),e.lchmod=n(e.lchmod),e.chownSync=s(e.chownSync),e.fchownSync=s(e.fchownSync),e.lchownSync=s(e.lchownSync),e.chmodSync=i(e.chmodSync),e.fchmodSync=i(e.fchmodSync),e.lchmodSync=i(e.lchmodSync),e.stat=a(e.stat),e.fstat=a(e.fstat),e.lstat=a(e.lstat),e.statSync=c(e.statSync),e.fstatSync=c(e.fstatSync),e.lstatSync=c(e.lstatSync),e.lchmod||(e.lchmod=function(e,r,n){n&&t.nextTick(n)},e.lchmodSync=function(){}),e.lchown||(e.lchown=function(e,r,n,i){i&&t.nextTick(i)},e.lchownSync=function(){}),"win32"===p&&(e.rename=function(t){return function(r,n,i){var o=Date.now(),s=0;t(r,n,function a(c){if(c&&("EACCES"===c.code||"EPERM"===c.code)&&Date.now()-o<6e4)return setTimeout(function(){e.stat(n,function(e,o){e&&"ENOENT"===e.code?t(r,n,a):i(c)})},s),void(s<100&&(s+=10));i&&i(c)})}}(e.rename)),e.read=function(t){return function(r,n,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++,t.call(e,r,n,i,o,s,c);a.apply(this,arguments)}}return t.call(e,r,n,i,o,s,c)}}(e.read),e.readSync=function(t){return function(r,n,i,o,s){for(var a=0;;)try{return t.call(e,r,n,i,o,s)}catch(e){if("EAGAIN"===e.code&&a<10){a++;continue}throw e}}}(e.readSync)}}).call(t,r(0))},function(e,t){e.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(e,t,r){(function(t){var n=r(115).Stream;e.exports=function(e){function r(i,o){if(!(this instanceof r))return new r(i,o);n.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?e.open(this.path,this.flags,this.mode,function(e,t){if(e)return s.emit("error",e),void(s.readable=!1);s.fd=t,s.emit("open",t),s._read()}):t.nextTick(function(){s._read()})}function i(t,r){if(!(this instanceof i))return new i(t,r);n.call(this),this.path=t,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,r=r||{};for(var o=Object.keys(r),s=0,a=o.length;s= zero");this.pos=this.start}this.busy=!1,this._queue=[],null===this.fd&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}return{ReadStream:r,WriteStream:i}}}).call(t,r(0))},function(e,t,r){function n(){i.call(this)}e.exports=n;var i=r(2).EventEmitter;r(4)(n,i),n.Readable=r(13),n.Writable=r(116),n.Duplex=r(117),n.Transform=r(118),n.PassThrough=r(119),n.Stream=n,n.prototype.pipe=function(e,t){function r(t){e.writable&&!1===e.write(t)&&f.pause&&f.pause()}function n(){f.readable&&f.resume&&f.resume()}function o(){u||(u=!0,e.end())}function s(){u||(u=!0,"function"==typeof e.destroy&&e.destroy())}function a(e){if(c(),0===i.listenerCount(this,"error"))throw e}function c(){f.removeListener("data",r),e.removeListener("drain",n),f.removeListener("end",o),f.removeListener("close",s),f.removeListener("error",a),e.removeListener("error",a),f.removeListener("end",c),f.removeListener("close",c),e.removeListener("close",c)}var f=this;f.on("data",r),e.on("drain",n),e._isStdio||t&&!1===t.end||(f.on("end",o),f.on("close",s));var u=!1;return f.on("error",a),e.on("error",a),f.on("end",c),f.on("close",c),e.on("close",c),e.emit("pipe",f),e}},function(e,t,r){e.exports=r(23)},function(e,t,r){e.exports=r(10)},function(e,t,r){e.exports=r(13).Transform},function(e,t,r){e.exports=r(13).PassThrough},function(e,t){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},function(e,t,r){t.asyncMap=r(123),t.bindActor=r(53),t.chain=r(124)},function(e,t,r){(function(t){e.exports=function(){function e(u){u&&!a&&(a=u);for(var h=arguments.length,d=1;dc){var l=n.slice(c);f+=(n.length-c)*o,c=n.length,t.nextTick(function(){l.forEach(function(t){r.forEach(function(r){r(t,e)})})})}0==--f&&i.apply(null,[a].concat(s))}var r=Array.prototype.slice.call(arguments),n=r.shift()||[],i=r.pop();if("function"!=typeof i)throw new Error("No callback provided to asyncMap");if(!n)return i(null,[]);Array.isArray(n)||(n=[n]);var o=r.length,s=[],a=null,c=n.length,f=c*o;if(!f)return i(null,[]);n.forEach(function(t){r.forEach(function(r){r(t,e)})})}}).call(t,r(0))},function(e,t,r){function n(e,t){var r=[];!function o(s,a){return s>=a?t(null,r):(Array.isArray(e[s])&&(e[s]=i.apply(null,e[s].map(function(e){return e===n.first?r[0]:e===n.last?r[r.length-1]:e}))),e[s]?void e[s](function(e,n){if(e)return t(e,r);void 0!==n&&(r=r.concat(n)),o(s+1,a)}):o(s+1,a))}(0,e.length)}e.exports=n;var i=r(53);n.first={},n.last={}},function(e,t,r){!function(){function t(e,n){var i=this instanceof t?this:r;if(i.reset(n),"string"==typeof e&&e.length>0&&i.hash(e),i!==this)return i}var r;t.prototype.hash=function(e){var t,r,n,i,o;switch(o=e.length,this.len+=o,r=this.k1,n=0,this.rem){case 0:r^=o>n?65535&e.charCodeAt(n++):0;case 1:r^=o>n?(65535&e.charCodeAt(n++))<<8:0;case 2:r^=o>n?(65535&e.charCodeAt(n++))<<16:0;case 3:r^=o>n?(255&e.charCodeAt(n))<<24:0,r^=o>n?(65280&e.charCodeAt(n++))>>8:0}if(this.rem=o+this.rem&3,(o-=this.rem)>0){for(t=this.h1;r=11601*r+3432906752*(65535&r)&4294967295,r=r<<15|r>>>17,r=13715*r+461832192*(65535&r)&4294967295,t^=r,t=t<<13|t>>>19,t=5*t+3864292196&4294967295,!(n>=o);)r=65535&e.charCodeAt(n++)^(65535&e.charCodeAt(n++))<<8^(65535&e.charCodeAt(n++))<<16,r^=(255&(i=e.charCodeAt(n++)))<<24^(65280&i)>>8;switch(r=0,this.rem){case 3:r^=(65535&e.charCodeAt(n+2))<<16;case 2:r^=(65535&e.charCodeAt(n+1))<<8;case 1:r^=65535&e.charCodeAt(n)}this.h1=t}return this.k1=r,this},t.prototype.result=function(){var e,t;return e=this.k1,t=this.h1,e>0&&(t^=e=13715*(e=(e=11601*e+3432906752*(65535&e)&4294967295)<<15|e>>>17)+461832192*(65535&e)&4294967295),t^=this.len,t^=t>>>16,t=51819*t+2246770688*(65535&t)&4294967295,t^=t>>>13,t=44597*t+3266445312*(65535&t)&4294967295,(t^=t>>>16)>>>0},t.prototype.reset=function(e){return this.h1="number"==typeof e?e:0,this.rem=this.k1=this.len=0,this},r=new t,e.exports=t}()},function(e,t,r){"use strict";e.exports=class{constructor(e){this.id=e,this._index=[]}get(){return this._index}updateIndex(e,t){this._index=e.ops}}},function(e,t,r){const n=r(2).EventEmitter,i=r(42),o=1;e.exports=class extends n{constructor(e,t=8){super(),this._store=e,this._concurrency=t,this._queue=[],this._fetching={},this._tasksRunning=0,this._have={},this._stats={tasksProcessed:0,tasksRequested:0},this._timer=setInterval(()=>{this._queue.length>0&&this._tasksRunningnull!==e&&void 0!==e).sort((e,t)=>(e.clock?e.clock.time:0)-(t.clock?t.clock.time:0)).forEach(e=>{this._store._oplog.has(e.hash||e)||this._queue.find(t=>(t.hash||t)===(e.hash||e))||(this._queue.splice(0,0,e),this.emit("load.added",e))})}catch(e){console.error(e)}}async _processLoop(){if(this._queue.length>0&&this._tasksRunning{this._queue=this._queue.filter(e=>!this._fetching[e.hash||e]);const e=this._queue.shift();return e&&(this._fetching[e.hash||e]=e),e})();if(e){const t=e.hash||e,r=this._store._oplog.values;this._have=Object.assign({},this._have,this._store._replicationInfo.have),this.emit("load.start",e,this._have);const n=await i.fromEntryHash(this._store._ipfs,t,this._store._oplog.id,o,r,this._store.key,this._store.access.write,this._onSyncProgress.bind(this));this._stats.tasksProcessed+=1,delete this._fetching[t],n.values.forEach(e=>{e.next.length>0&&this.load(e.next)}),this.emit("load.end",n,this._have)}}catch(e){console.error("LOADER-ERROR:",e),this.emit("error",e)}this._tasksRunning--,this.emit("load.complete",this._have)}}_onSyncProgress(e,t,r){this._have[t.clock.time]||(this._have[t.clock.time]=!0,this.emit("load.progress",this._id,e,t,r,this._have))}}},function(e,t,r){"use strict";const n=r(2).EventEmitter;e.exports=class extends n{constructor(e,t=1e3){super(),this._loader=e,this._oplog=null,this._interval=t,this._timer=null}start(){this._timer=setInterval(()=>this._checkReplicationStatus(),this._interval)}stop(){clearInterval(this._timer)}replicate(e){this._oplog=e}async _checkReplicationStatus(){this._oplog&&0===this._loader._queue.length&&this._oplog.tails.filter(e=>e.next.length>0).sort((e,t)=>e.clock.time-t.clock.time).reduce((e,t)=>e.concat(t.next),[]).reduce((e,t)=>(e.includes(t)||e.push(t),e),[]).forEach(e=>{this._loader.load([e])})}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index=[]}get(){return this._index.values?this._index.values:[]}updateIndex(e){this._index=e}}},function(e,t,r){"use strict";const n=r(34),i=r(131);e.exports=class extends n{constructor(e,t,r,n){n||(n={}),n.Index||Object.assign(n,{Index:i}),super(e,t,r,n),this._type="feed"}remove(e){return this.del(e)}del(e){const t={op:"DEL",key:null,value:e};return this._addOperation(t)}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index={}}get(){return Object.keys(this._index).map(e=>this._index[e])}updateIndex(e){this._index={},e.values.reduce((e,t)=>(e.includes(t.hash)||(e.push(t.hash),"ADD"===t.payload.op?this._index[t.hash]=t:"DEL"===t.payload.op&&delete this._index[t.payload.value]),e),[])}}},function(e,t,r){"use strict";const n=r(20),i=r(133);e.exports=class extends n{constructor(e,t,r,n){let o=Object.assign({},{Index:i});Object.assign(o,n),super(e,t,r,o),this._type="keyvalue"}get(e){return this._index.get(e)}set(e,t){return this.put(e,t)}put(e,t){return this._addOperation({op:"PUT",key:e,value:t})}del(e){return this._addOperation({op:"DEL",key:e,value:null})}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index={}}get(e){return this._index[e]}updateIndex(e){e.values.slice().reverse().reduce((e,t)=>(e.includes(t.payload.key)||(e.push(t.payload.key),"PUT"===t.payload.op?this._index[t.payload.key]=t.payload.value:"DEL"===t.payload.op&&delete this._index[t.payload.key]),e),[])}}},function(e,t,r){"use strict";const n=r(20),i=r(135),o=r(54);e.exports=class extends n{constructor(e,t,r,n={}){n.Index||Object.assign(n,{Index:i}),super(e,t,r,n),this._type="counter"}get value(){return this._index.get().value}inc(e){const t=new o(this.id,Object.assign({},this._index.get()._counters));return t.increment(e),this._addOperation({op:"COUNTER",key:null,value:t.toJSON()})}}},function(e,t,r){"use strict";const n=r(54);e.exports=class{constructor(e){this._index=new n(e)}get(){return this._index}updateIndex(e){this._index&&e.values.filter(e=>e&&"COUNTER"===e.payload.op).map(e=>n.from(e.payload.value)).forEach(e=>this._index.merge(e))}}},function(e,t,r){"use strict";t.deepEqual=((e,t)=>{const r=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(t);if(r.length!==n.length)return!1;for(let n=0;ne.toString().split(t).join(r));e.exports=class extends n{constructor(e,t,r,n){n||(n={}),n.indexBy||Object.assign(n,{indexBy:"_id"}),n.Index||Object.assign(n,{Index:i}),super(e,t,r,n),this._type="docstore"}get(e,t=!1){const r=(e=e.toString()).split(" ");return e=r.length>1?s(e,"."," ").toLowerCase():e.toLowerCase(),Object.keys(this._index._index).filter(n=>t?-1!==n.indexOf(e):(t=>r.length>1?-1!==s(t,"."," ").toLowerCase().indexOf(e):-1!==t.toLowerCase().indexOf(e))(n)).map(e=>this._index.get(e))}query(e){return Object.keys(this._index._index).map(e=>this._index.get(e)).filter(t=>e(t))}batchPut(e,t){return o(e,(r,n)=>this._addOperationBatch({op:"PUT",key:r[this.options.indexBy],value:r},!0,n===e.length-1,t),{concurrency:1}).then(()=>this.saveSnapshot())}put(e){if(!e[this.options.indexBy])throw new Error(`The provided document doesn't contain field '${this.options.indexBy}'`);return this._addOperation({op:"PUT",key:e[this.options.indexBy],value:e})}del(e){if(!this._index.get(e))throw new Error(`No entry with key '${e}' in the database`);return this._addOperation({op:"DEL",key:e,value:null})}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index={}}get(e){return this._index[e]}updateIndex(e,t){e.values.slice().reverse().reduce((e,r,n)=>(!0!==e[r.payload.key]&&(e[r.payload.key]=!0,"PUT"===r.payload.op?this._index[r.payload.key]=r.payload.value:"DEL"===r.payload.op&&delete this._index[r.payload.key]),t&&t(r,n),e),{})}}},function(e,t,r){"use strict";e.exports=((e,t,r)=>new Promise((n,i)=>{const o=(r=Object.assign({concurrency:1/0},r)).concurrency;if(o<1)throw new TypeError("Expected `concurrency` to be a number from 1 and up");const s=[],a=e[Symbol.iterator]();let c=!1,f=!1,u=0,h=0;const d=()=>{if(c)return;const e=a.next(),r=h;if(h++,e.done)return f=!0,void(0===u&&n(s));u++,Promise.resolve(e.value).then(e=>t(e,r)).then(e=>{s[r]=e,u--,d()},e=>{c=!0,i(e)})};for(let e=0;e{o.error("Pubsub Error:",e)}),i.on("message",e=>{this._handleMessage(e)}),i.on("peer joined",t=>{this._subscriptions[e].onNewPeer(e,t,i)}),i.on("subscribed",()=>{this._subscriptions[e]={room:i,onMessage:t,onNewPeer:r},a++,o.debug("Topics open:",a)})}}unsubscribe(e){this._subscriptions[e]&&(this._subscriptions[e].room.leave(),this._subscriptions[e].room=null,delete this._subscriptions[e],o.debug(`Unsubscribed from '${e}'`),a--,o.debug("Topics open:",a))}publish(e,r){this._subscriptions[e]&&this._subscriptions[e].room&&this._ipfs.pubsub&&this._subscriptions[e].room.broadcast(t.from(JSON.stringify(r)))}disconnect(){Object.keys(this._subscriptions).forEach(e=>this.unsubscribe(e)),this._subscriptions={}}_handleMessage(e){if(e.from===this._id)return;let t,r,n;try{n=e.topicIDs[0],t=JSON.parse(e.data),r=this._subscriptions[n]}catch(t){o.error(t),o.error("Couldn't parse pubsub message:",e)}r&&r.onMessage&&t&&r.onMessage(n,t)}}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";const n=r(143),i=r(2),o=r(39),s=r(55),a=r(9).Buffer,c=r(56),f=r(148),u=r(62),h=r(171),d={pollInterval:1e3};e.exports=((e,t,r)=>new class extends i{constructor(e,t,r){if(super(),this._ipfs=e,this._topic=t,this._options=Object.assign({},s(d),s(r)),this._peers=[],this._connections={},this._handleDirectMessage=this._handleDirectMessage.bind(this),!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(e){return this._peers.indexOf(e)>=0}leave(){o.clearInterval(),Object.keys(this._connections).forEach(e=>{this._connections[e].stop()}),h.emitter.removeListener(this._topic,this._handleDirectMessage),this.emit("stop")}broadcast(e){let t=u(e);this._ipfs.pubsub.publish(this._topic,t,e=>{e&&this.emit("error",e)})}sendTo(e,t){let r=this._connections[e];r||((r=new f(e,this._ipfs,this)).on("error",e=>this.emit("error",e)),this._connections[e]=r);const n=a.from([0]),i={to:e,from:this._ipfs._peerInfo.id.toB58String(),data:a.from(t).toString("hex"),seqno:n.toString("hex"),topicIDs:[this._topic],topicCIDs:[this._topic]};r.push(a.from(JSON.stringify(i)))}_start(){this._interval=o.setInterval(this._pollPeers.bind(this),this._options.pollInterval);const e=this._onMessage.bind(this);this._ipfs.pubsub.subscribe(this._topic,e,e=>{e?this.emit("error",e):this.emit("subscribed",this._topic)}),this.once("stop",()=>{this._ipfs.pubsub.unsubscribe(this._topic,e)}),this._ipfs._libp2pNode.handle(c,h.handler),h.emitter.on(this._topic,this._handleDirectMessage)}_pollPeers(){this._ipfs.pubsub.peers(this._topic,(e,t)=>{if(e)return void this.emit("error",e);const r=t.sort();this._emitChanges(r)&&(this._peers=r)})}_emitChanges(e){const t=n(this._peers,e);return t.added.forEach(e=>this.emit("peer joined",e)),t.removed.forEach(e=>this.emit("peer left",e)),t.added.length>0||t.removed.length>0}_onMessage(e){this.emit("message",e)}_handleDirectMessage(e){if(e.to===this._ipfs._peerInfo.id.toB58String()){const t=Object.assign({},e);delete t.to,this.emit("message",t)}}}(e,t,r))},function(e,t,r){"use strict";const n=r(55),i=r(144)("hyperdiff"),o=r(147),s=e=>-1!==e;e.exports=function(e,t,r){const{first:a,second:c}=function(e,t){return{first:e,second:n(t)}}(e,t),f=function(e){return e?function(e,t,r){return e.findIndex(function(e){return function(e,t,r){return r.every(r=>t[r]===e[r])}(e,t,r)})}:function(e,t,r){return e.indexOf(t)}}(r);i("preconditions first=%j second=%j findIndex=%s",a,c,f.name);const u=a.reduce(function(e,t,n){const a=f(c,t,r),u=s(a)?"common":"removed";return e[u].push(t),o(c,a),i("index=%s value=%s collection=%s",n,t,u),e},{common:[],removed:[]});return u.added=c,i("added=%j removed=%j common%j",u.added,u.removed,u.common),u}},function(e,t,r){(function(n){function i(){var e;try{e=t.storage.debug}catch(e){}return!e&&void 0!==n&&"env"in n&&(e=Object({NODE_ENV:void 0}).DEBUG),e}(t=e.exports=r(145)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var r=this.useColors;if(e[0]=(r?"%c":"")+this.namespace+(r?" %c":" ")+e[0]+(r?"%c ":" ")+"+"+t.humanize(this.diff),r){var n="color: "+this.color;e.splice(1,0,n,"color: inherit");var i=0,o=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(i++,"%c"===e&&(o=i))}),e.splice(o,0,n)}},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=i,t.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+)/))},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.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"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(i())}).call(t,r(0))},function(e,t,r){function n(e){function r(){if(r.enabled){var e=r,i=+new Date,o=i-(n||i);e.diff=o,e.prev=n,e.curr=i,n=i;for(var s=new Array(arguments.length),a=0;a0)return function(e){if(!((e=String(e)).length>100)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*a;case"days":case"day":case"d":return r*s;case"hours":case"hour":case"hrs":case"hr":case"h":return r*o;case"minutes":case"minute":case"mins":case"min":case"m":return r*i;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}(e);if("number"===c&&!1===isNaN(e))return t.long?function(e){return r(e,s,"day")||r(e,o,"hour")||r(e,i,"minute")||r(e,n,"second")||e+" ms"}(e):function(e){return e>=s?Math.round(e/s)+"d":e>=o?Math.round(e/o)+"h":e>=i?Math.round(e/i)+"m":e>=n?Math.round(e/n)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,r){(function(t){function r(e,t){for(var r=-1,n=t.length,i=e.length;++r0&&n(f)?t>1?c(f,t-1,n,i,o):r(o,f):i||(o[o.length]=f)}return o}function f(e,t){for(var r=0,n=(t=m(t,e)?[t]:d(t)).length;null!=e&&ri?0:i+t);(r=r>i?i:r)<0&&(r+=i);i=t>r?0:r-t>>>0,t>>>=0;var o=Array(i);for(;++nt||o&&s&&c&&!a&&!f||n&&s&&c||!r&&c||!i)return 1;if(!n&&!o&&!f&&e-1&&e%1==0&&e<=I}(e.length)&&!w(e)}(e)}(e)&&$.call(e,"callee")&&(!ee.call(e,"callee")||X.call(e)==N)}(e)||!!(re&&e&&e[re])}function g(e,t){return!!(t=null==t?I:t)&&("number"==typeof e||F.test(e))&&e>-1&&e%1==0&&e-1},i.prototype.set=function(e,t){var r=this.__data__,n=s(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},o.prototype.clear=function(){this.__data__={hash:new n,map:new(ie||i),string:new n}},o.prototype.delete=function(e){return p(this,e).delete(e)},o.prototype.get=function(e){return p(this,e).get(e)},o.prototype.has=function(e){return p(this,e).has(e)},o.prototype.set=function(e,t){return p(this,e).set(e,t),this};var ce=_(function(e){e=x(e);var t=[];return L.test(e)&&t.push(""),e.replace(B,function(e,r,n,i){t.push(n?i.replace(D,"$1"):r||e)}),t}),fe=function(e,t){return t=ne(void 0===t?e.length-1:t,0),function(){for(var r=arguments,n=-1,i=ne(r.length-t,0),o=Array(i);++nthis.push(e)),this._getConnection())}stop(){this._connection&&this._connection.end()}_getConnection(){this._connecting=!0,this._getPeerAddresses(this._id,(e,t)=>{e?this.emit("error",e):t.length?this._ipfs._libp2pNode.dial(t[0],s,(e,t)=>{if(e)return void this.emit("error",e);this._connecting=!1;const r=o();this._connection=r,i(r,t,i.onEnd(e=>{delete this._connection,e&&this.emit("error",e)})),this.emit("connect",r)}):this.emit("error",new Error("could not connect to "+this._id))})}_getPeerAddresses(e,t){this._ipfs.swarm.peers((r,n)=>{r?t(r):t(null,n.filter(t=>t.peer.id.toB58String()===e).map(e=>e.peer))})}}},function(e,t,r){"use strict";e.exports={keys:r(150),once:r(59),values:r(29),count:r(151),infinite:r(152),empty:r(153),error:r(154)}},function(e,t,r){"use strict";var n=r(29);e.exports=function(e){return n(Object.keys(e))}},function(e,t,r){"use strict";e.exports=function(e){var t=0;return e=e||1/0,function(r,n){return r?n&&n(r):t>e?n(!0):void n(null,t++)}}},function(e,t,r){"use strict";e.exports=function(e){return e=e||Math.random,function(t,r){return t?r&&r(t):r(null,e())}}},function(e,t,r){"use strict";e.exports=function(){return function(e,t){t(!0)}}},function(e,t,r){"use strict";e.exports=function(e){return function(t,r){r(e)}}},function(e,t,r){"use strict";e.exports={drain:r(17),onEnd:r(156),log:r(157),find:r(158),reduce:r(30),collect:r(159),concat:r(160)}},function(e,t,r){"use strict";var n=r(17);e.exports=function(e){return n(null,e)}},function(e,t,r){"use strict";var n=r(17);e.exports=function(e){return n(function(e){console.log(e)},e)}},function(e,t,r){"use strict";function n(e){return e}var i=r(18),o=r(17);e.exports=function(e,t){var r=!1;return t?e=i(e)||n:(t=e,e=n),o(function(n){if(e(n))return r=!0,t(null,n),!1},function(e){r||t(!0===e?null:e,null)})}},function(e,t,r){"use strict";var n=r(30);e.exports=function(e){return n(function(e,t){return e.push(t),e},[],e)}},function(e,t,r){"use strict";var n=r(30);e.exports=function(e){return n(function(e,t){return e+t},"",e)}},function(e,t,r){"use strict";e.exports={map:r(162),asyncMap:r(163),filter:r(31),filterNot:r(164),through:r(165),take:r(166),unique:r(61),nonUnique:r(167),flatten:r(168)}},function(e,t,r){"use strict";function n(e){return e}var i=r(18);e.exports=function(e){return e?(e=i(e),function(t){return function(r,n){t(r,function(r,i){try{i=r?null:e(i)}catch(e){return t(e,function(){return n(e)})}n(r,i)})}}):n}},function(e,t,r){"use strict";function n(e){return e}var i=r(18);e.exports=function(e){if(!e)return n;e=i(e);var t,r,o=!1;return function(n){return function i(s,a){if(r)return a(r);s?(r=s,o?n(s,function(){o?t=a:a(s)}):n(s,a)):n(null,function(n,s){n?a(n):r?a(r):(o=!0,e(s,function(e,n){o=!1,r?(a(r),t(r)):e?i(e,a):a(null,n)}))})}}}},function(e,t,r){"use strict";var n=r(60),i=r(31);e.exports=function(e){return e=n(e),i(function(t){return!e(t)})}},function(e,t,r){"use strict";e.exports=function(e,t){function r(e){!n&&t&&(n=!0,t(!0===e?null:e))}var n=!1;return function(t){return function(n,i){return n&&r(n),t(n,function(t,n){t?r(t):e&&e(n),i(t,n)})}}}},function(e,t,r){"use strict";e.exports=function(e,t){var r=(t=t||{}).last||!1,n=!1;if("number"==typeof e){r=!0;var i=e;e=function(){return--i}}return function(t){function i(e){t(!0,function(t){r=!1,e(t||!0)})}return function(o,s){n?r?i(s):s(n):(n=o)?t(n,s):t(null,function(t,o){(n=n||t)?s(n):e(o)?s(null,o):(n=!0,r?s(null,o):i(s))})}}}},function(e,t,r){"use strict";var n=r(61);e.exports=function(e){return n(e,!0)}},function(e,t,r){"use strict";var n=r(29),i=r(59);e.exports=function(){return function(e){var t;return function(r,o){function s(){t(null,function(t,r){!0===t?a():t?e(!0,function(e){o(t)}):o(null,r)})}function a(){t=null,e(null,function(e,r){if(e)return o(e);Array.isArray(r)||r&&"object"==typeof r?r=n(r):"function"!=typeof r&&(r=i(r)),t=r,s()})}r?t?t(r,function(t){e(t||r,o)}):e(r,o):t?s():a()}}}},function(e,t,r){"use strict";e.exports=function e(t){var r=arguments.length;if("function"==typeof t&&1===t.length){for(var n=new Array(r),i=0;i{if(e)return this.emit("error",e);const s=r.id.toB58String();n(t,n.map(e=>{let t;try{t=JSON.parse(e.toString())}catch(e){return void o.emit("warning",e.message)}if(s!==t.from)return void o.emit("warning","no peerid match "+t.from);const r=t.topicIDs;if(Array.isArray(r))return t.data=i.from(t.data,"hex"),t.seqno=i.from(t.seqno,"hex"),r.forEach(e=>{o.emit(e,t)}),t;o.emit("warning","no topic IDs")}),n.onEnd(e=>{e&&o.emit("error",e)}))})},emitter:o}},function(e,t,r){"use strict";const n=r(12),i=r(14),o=r(173);let s={};class a{static async load(e,t){const r=n.join(t.root,t.path),i=n.join(e,r);let o=s[i];return o||(o=new a(i,t.toString()),s[i]=o,await o.load()),o}static async close(){return Promise.all(Object.values(s),e=>e.close()).then(()=>s={})}constructor(e,t){this.path=e||"./orbitdb",this.id=t,this._store=null,this._cache={}}async close(){this._store&&await this._store.close(),this._store=null}async get(e){return this._store||await this.load(),new Promise((t,r)=>{this._store.get(e,(e,n)=>{if(e&&-1===e.toString().indexOf("NotFoundError: Key not found in database"))return r(e);t(n?JSON.parse(n):null)})})}async set(e,t){return this._store||await this.load(),this._store.put(e,JSON.stringify(t))}async del(e){return this._store||await this.load(),new Promise((t,r)=>{this._store.del(e,(e,n)=>{if(e&&-1===e.toString().indexOf("NotFoundError: Key not found in database"))return r(e);t()})})}async load(){return new Promise((e,t)=>{i.sync&&i.sync(this.path),o(this.path,(t,r)=>{this._store=r,e()})})}}e.exports=a},function(e,t,r){e.exports=r(174)(r(187))},function(e,t,r){const n=r(175),i=r(184);e.exports=function(e){function t(t,r,o){return"function"==typeof r&&(o=r),"object"==typeof r&&null!==r||(r={}),n(i(e(t),r),r,o)}return["destroy","repair"].forEach(function(r){"function"==typeof e[r]&&(t[r]=function(t,n){e[r](t,n||function(){})})}),t}},function(e,t,r){(function(t){function n(e,r,i){if(!(this instanceof n))return new n(e,r,i);var s;if(a.call(this),this.setMaxListeners(1/0),"function"==typeof r&&(i=r,r={}),r=r||{},!e||"object"!=typeof e){if(s=new _("Must provide db"),"function"==typeof i)return t.nextTick(i,s);throw s}p.equal(typeof e.status,"string",".status required, old abstract-leveldown"),this.options=o(r),this._db=e,this.db=new u(e),this.open(i)}function i(e,t){return"function"==typeof e?e:t}function o(e){return"object"==typeof e&&null!==e?e:{}}function s(e,r){if(!e._isOpening()&&!e.isOpen())return t.nextTick(r,new g("Database is not open")),!0}var a=r(2).EventEmitter,c=r(6).inherits,f=r(32),u=r(176),h=r(179),d=r(180),l=r(33),p=r(52),b=r(67),y=l.WriteError,g=l.ReadError,m=l.NotFoundError,v=l.OpenError,_=l.InitializationError;n.prototype.emit=a.prototype.emit,n.prototype.once=a.prototype.once,c(n,a),n.prototype.open=function(e){var r,n=this;return e||(r=(e=b()).promise),this.isOpen()?(t.nextTick(e,null,n),r):this._isOpening()?(this.once("open",function(){e(null,n)}),r):(this.emit("opening"),this.db.open(this.options,function(t){if(t)return e(new v(t));n.db=n._db,e(null,n),n.emit("open"),n.emit("ready")}),r)},n.prototype.close=function(e){var r,n=this;return e||(r=(e=b()).promise),this.isOpen()?(this.db.close(function(){n.emit("closed"),e.apply(null,arguments)}),this.emit("closing"),this.db=new u(this._db)):this.isClosed()?t.nextTick(e):"closing"===this.db.status?this.once("closed",e):this._isOpening()&&this.once("open",function(){n.close(e)}),r},n.prototype.isOpen=function(){return"open"===this.db.status},n.prototype._isOpening=function(){return"opening"===this.db.status},n.prototype.isClosed=function(){return/^clos|new/.test(this.db.status)},n.prototype.get=function(e,t,r){if(null===e||void 0===e)throw new g("get() requires a key argument");var n;return(r=i(t,r))||(n=(r=b()).promise),s(this,r)?n:(t=o(t),this.db.get(e,t,function(t,n){if(t)return t=/notfound/i.test(t)||t.notFound?new m("Key not found in database ["+e+"]",t):new g(t),r(t);r(null,n)}),n)},n.prototype.put=function(e,t,r,n){if(null===e||void 0===e)throw new y("put() requires a key argument");var a,c=this;return(n=i(r,n))||(a=(n=b()).promise),s(this,n)?a:(r=o(r),this.db.put(e,t,r,function(r){if(r)return n(new y(r));c.emit("put",e,t),n()}),a)},n.prototype.del=function(e,t,r){if(null===e||void 0===e)throw new y("del() requires a key argument");var n,a=this;return(r=i(t,r))||(n=(r=b()).promise),s(this,r)?n:(t=o(t),this.db.del(e,t,function(t){if(t)return r(new y(t));a.emit("del",e),r()}),n)},n.prototype.batch=function(e,t,r){if(!arguments.length)return new d(this);if(!Array.isArray(e))throw new y("batch() requires an array argument");var n,a=this;return(r=i(t,r))||(n=(r=b()).promise),s(this,r)?n:(t=o(t),e=e.map(function(e){return e.type||void 0===e.key||void 0===e.value||(e.type="put"),e}),this.db.batch(e,t,function(t){if(t)return r(new y(t));a.emit("batch",e),r()}),n)},n.prototype.readStream=n.prototype.createReadStream=function(e){return"number"!=typeof(e=f({keys:!0,values:!0},e)).limit&&(e.limit=-1),new h(this.db.iterator(e),e)},n.prototype.keyStream=n.prototype.createKeyStream=function(e){return this.createReadStream(f(e,{keys:!0,values:!1}))},n.prototype.valueStream=n.prototype.createValueStream=function(e){return this.createReadStream(f(e,{keys:!1,values:!0}))},n.prototype.toString=function(){return"LevelUP"},n.errors=l,e.exports=n.default=n}).call(t,r(0))},function(e,t,r){(function(t){function n(e){s.call(this,""),this._db=e,this._operations=[],this._iterators=[]}function i(e){c.forEach(function(t){e["_"+t]=function(){this._operations.push({method:t,args:arguments})}}),e._iterator=function(e){var t=new a(e);return this._iterators.push(t),t}}var o=r(6),s=r(19).AbstractLevelDOWN,a=r(178),c="put get del batch approximateSize".split(" ");o.inherits(n,s),n.prototype._open=function(e,t){var r=this;this._db.open(e,function(e){if(e)return t(e);r._operations.forEach(function(e){r._db[e.method].apply(r._db,e.args)}),r._operations=[],r._iterators.forEach(function(e){e.setDb(r._db)}),r._iterators=[],function(e){c.concat("iterator").forEach(function(t){e["_"+t]=function(){return this._db[t].apply(this._db,arguments)}})}(r),t()})},n.prototype._close=function(e){var t=this;this._db.close(function(r){if(r)return e(r);i(t),e()})},i(n.prototype),n.prototype._isBuffer=function(e){return t.isBuffer(e)},n.prototype._serializeKey=function(e){return e},n.prototype._serializeValue=function(e){return e},e.exports=n,e.exports.DeferredIterator=a}).call(t,r(1).Buffer)},function(e,t,r){var n=r(64);e.exports=function(e){return!(!e||"object"!=typeof e)&&Object.keys(n.prototype).filter(function(e){return"_"!=e[0]&&"approximateSize"!=e}).every(function(t){return"function"==typeof e[t]})}},function(e,t,r){function n(e){o.call(this,e),this._options=e,this._iterator=null,this._operations=[]}var i=r(6),o=r(19).AbstractIterator;i.inherits(n,o),n.prototype.setDb=function(e){var t=this._iterator=e.iterator(this._options);this._operations.forEach(function(e){t[e.method].apply(t,e.args)})},n.prototype._operation=function(e,t){if(this._iterator)return this._iterator[e].apply(this._iterator,t);this._operations.push({method:e,args:t})},"next end".split(" ").forEach(function(e){n.prototype["_"+e]=function(){this._operation(e,arguments)}}),e.exports=n},function(e,t,r){function n(e,t){if(!(this instanceof n))return new n(e,t);t=t||{},o.call(this,s(t,{objectMode:!0})),this._iterator=e,this._destroyed=!1,this._options=t,this.on("end",this._cleanup.bind(this))}var i=r(4),o=r(13).Readable,s=r(32);e.exports=n,i(n,o),n.prototype._read=function(){var e=this,t=this._options;this._destroyed||this._iterator.next(function(r,n,i){if(!e._destroyed)return r?e.emit("error",r):void(void 0===n&&void 0===i?e.push(null):!1!==t.keys&&!1===t.values?e.push(n):!1===t.keys&&!1!==t.values?e.push(i):e.push({key:n,value:i}))})},n.prototype.destroy=n.prototype._cleanup=function(){var e=this;this._destroyed||(this._destroyed=!0,this._iterator.end(function(t){if(t)return e.emit("error",t);e.emit("close")}))}},function(e,t,r){function n(e){this._levelup=e,this.batch=e.db.batch(),this.ops=[],this.length=0}var i=r(33).WriteError,o=r(67);n.prototype.put=function(e,t){try{this.batch.put(e,t)}catch(e){throw new i(e)}return this.ops.push({type:"put",key:e,value:t}),this.length++,this},n.prototype.del=function(e){try{this.batch.del(e)}catch(e){throw new i(e)}return this.ops.push({type:"del",key:e}),this.length++,this},n.prototype.clear=function(){try{this.batch.clear()}catch(e){throw new i(e)}return this.ops=[],this.length=0,this},n.prototype.write=function(e){var t,r=this._levelup,n=this.ops;e||(t=(e=o()).promise);try{this.batch.write(function(t){if(t)return e(new i(t));r.emit("batch",n),e()})}catch(e){throw new i(e)}return t},e.exports=n},function(e,t,r){var n=e.exports.all=[{errno:-2,code:"ENOENT",description:"no such file or directory"},{errno:-1,code:"UNKNOWN",description:"unknown error"},{errno:0,code:"OK",description:"success"},{errno:1,code:"EOF",description:"end of file"},{errno:2,code:"EADDRINFO",description:"getaddrinfo error"},{errno:3,code:"EACCES",description:"permission denied"},{errno:4,code:"EAGAIN",description:"resource temporarily unavailable"},{errno:5,code:"EADDRINUSE",description:"address already in use"},{errno:6,code:"EADDRNOTAVAIL",description:"address not available"},{errno:7,code:"EAFNOSUPPORT",description:"address family not supported"},{errno:8,code:"EALREADY",description:"connection already in progress"},{errno:9,code:"EBADF",description:"bad file descriptor"},{errno:10,code:"EBUSY",description:"resource busy or locked"},{errno:11,code:"ECONNABORTED",description:"software caused connection abort"},{errno:12,code:"ECONNREFUSED",description:"connection refused"},{errno:13,code:"ECONNRESET",description:"connection reset by peer"},{errno:14,code:"EDESTADDRREQ",description:"destination address required"},{errno:15,code:"EFAULT",description:"bad address in system call argument"},{errno:16,code:"EHOSTUNREACH",description:"host is unreachable"},{errno:17,code:"EINTR",description:"interrupted system call"},{errno:18,code:"EINVAL",description:"invalid argument"},{errno:19,code:"EISCONN",description:"socket is already connected"},{errno:20,code:"EMFILE",description:"too many open files"},{errno:21,code:"EMSGSIZE",description:"message too long"},{errno:22,code:"ENETDOWN",description:"network is down"},{errno:23,code:"ENETUNREACH",description:"network is unreachable"},{errno:24,code:"ENFILE",description:"file table overflow"},{errno:25,code:"ENOBUFS",description:"no buffer space available"},{errno:26,code:"ENOMEM",description:"not enough memory"},{errno:27,code:"ENOTDIR",description:"not a directory"},{errno:28,code:"EISDIR",description:"illegal operation on a directory"},{errno:29,code:"ENONET",description:"machine is not on the network"},{errno:31,code:"ENOTCONN",description:"socket is not connected"},{errno:32,code:"ENOTSOCK",description:"socket operation on non-socket"},{errno:33,code:"ENOTSUP",description:"operation not supported on socket"},{errno:34,code:"ENOENT",description:"no such file or directory"},{errno:35,code:"ENOSYS",description:"function not implemented"},{errno:36,code:"EPIPE",description:"broken pipe"},{errno:37,code:"EPROTO",description:"protocol error"},{errno:38,code:"EPROTONOSUPPORT",description:"protocol not supported"},{errno:39,code:"EPROTOTYPE",description:"protocol wrong type for socket"},{errno:40,code:"ETIMEDOUT",description:"connection timed out"},{errno:41,code:"ECHARSET",description:"invalid Unicode character"},{errno:42,code:"EAIFAMNOSUPPORT",description:"address family for hostname not supported"},{errno:44,code:"EAISERVICE",description:"servname not supported for ai_socktype"},{errno:45,code:"EAISOCKTYPE",description:"ai_socktype not supported"},{errno:46,code:"ESHUTDOWN",description:"cannot send after transport endpoint shutdown"},{errno:47,code:"EEXIST",description:"file already exists"},{errno:48,code:"ESRCH",description:"no such process"},{errno:49,code:"ENAMETOOLONG",description:"name too long"},{errno:50,code:"EPERM",description:"operation not permitted"},{errno:51,code:"ELOOP",description:"too many symbolic links encountered"},{errno:52,code:"EXDEV",description:"cross-device link not permitted"},{errno:53,code:"ENOTEMPTY",description:"directory not empty"},{errno:54,code:"ENOSPC",description:"no space left on device"},{errno:55,code:"EIO",description:"i/o error"},{errno:56,code:"EROFS",description:"read-only file system"},{errno:57,code:"ENODEV",description:"no such device"},{errno:58,code:"ESPIPE",description:"invalid seek"},{errno:59,code:"ECANCELED",description:"operation canceled"}];e.exports.errno={},e.exports.code={},n.forEach(function(t){e.exports.errno[t.errno]=t,e.exports.code[t.code]=t}),e.exports.custom=r(182)(e.exports),e.exports.create=e.exports.custom.createError},function(e,t,r){function n(e,t,r){o(this,{type:e,name:e,cause:"string"!=typeof t?t:r,message:t&&"string"!=typeof t?t.message:t},"ewr")}function i(e,t){Error.call(this),Error.captureStackTrace&&Error.captureStackTrace(this,arguments.callee),n.call(this,"CustomError",e,t)}var o=r(183);i.prototype=new Error,e.exports=function(e){var t=function(t,r){return function(e,t,r){var o=function(r,i){n.call(this,t,r,i),"FilesystemError"==t&&(this.code=this.cause.code,this.path=this.cause.path,this.errno=this.cause.errno,this.message=(e.errno[this.cause.errno]?e.errno[this.cause.errno].description:this.cause.message)+(this.cause.path?" ["+this.cause.path+"]":"")),Error.call(this),Error.captureStackTrace&&Error.captureStackTrace(this,arguments.callee)};return o.prototype=r?new r:new i,o}(e,t,r)};return{CustomError:i,FilesystemError:t("FilesystemError"),createError:t}}},function(e,t){!function(t,r,n){void 0!==e&&e.exports?e.exports=n():r.prr=n()}(0,this,function(){var e="function"==typeof Object.defineProperty?function(e,t,r){return Object.defineProperty(e,t,r),e}:function(e,t,r){return e[t]=r.value,e};return function(t,r,n,i){var o;if(i=function(e,t){var r="object"==typeof t,n=!r&&"string"==typeof t,i=function(e){return r?!!t[e]:!!n&&t.indexOf(e[0])>-1};return{enumerable:i("enumerable"),configurable:i("configurable"),writable:i("writable"),value:e}}(n,i),"object"==typeof r){for(o in r)Object.hasOwnProperty.call(r,o)&&(i.value=r[o],e(t,o,i));return t}return e(t,r,i)}})},function(e,t,r){"use strict";function n(e,t){if(!(this instanceof n))return new n(e,t);s.call(this,""),void 0===(t=t||{}).keyEncoding&&(t.keyEncoding="utf8"),void 0===t.valueEncoding&&(t.valueEncoding="utf8"),this.db=e,this.codec=new u(t)}function i(e,t){c.call(this,e),this.codec=e.codec,this.opts=this.codec.encodeLtgt(t),this.it=e.db.iterator(this.opts)}function o(e,t){a.call(this,e),this.codec=e.codec,this.batch=e.db.batch()}var s=r(19).AbstractLevelDOWN,a=r(19).AbstractChainedBatch,c=r(19).AbstractIterator,f=r(6).inherits,u=r(185),h=r(33).EncodingError;e.exports=n.default=n,f(n,s),n.prototype._serializeKey=n.prototype._serializeValue=function(e){return e},n.prototype._open=function(e,t){this.db.open(e,t)},n.prototype._close=function(e){this.db.close(e)},n.prototype._put=function(e,t,r,n){e=this.codec.encodeKey(e,r),t=this.codec.encodeValue(t,r),this.db.put(e,t,r,n)},n.prototype._get=function(e,t,r){var n=this;e=this.codec.encodeKey(e,t),t.asBuffer=this.codec.valueAsBuffer(t),this.db.get(e,t,function(e,i){if(e)return r(e);try{i=n.codec.decodeValue(i,t)}catch(e){return r(new h(e))}r(null,i)})},n.prototype._del=function(e,t,r){e=this.codec.encodeKey(e,t),this.db.del(e,t,r)},n.prototype._chainedBatch=function(){return new o(this)},n.prototype._batch=function(e,t,r){e=this.codec.encodeBatch(e,t),this.db.batch(e,t,r)},n.prototype._iterator=function(e){return e.keyAsBuffer=this.codec.keyAsBuffer(e),e.valueAsBuffer=this.codec.valueAsBuffer(e),new i(this,e)},n.prototype.approximateSize=function(e,t,r,n){return this.db.approximateSize(e,t,r,n)},f(i,c),i.prototype._next=function(e){var t=this;this.it.next(function(r,n,i){if(r)return e(r);try{void 0!==n&&(n=t.codec.decodeKey(n,t.opts)),void 0!==i&&(i=t.codec.decodeValue(i,t.opts))}catch(r){return e(new h(r))}e(null,n,i)})},i.prototype._end=function(e){this.it.end(e)},f(o,a),o.prototype._put=function(e,t){e=this.codec.encodeKey(e),t=this.codec.encodeValue(t),this.batch.put(e,t)},o.prototype._del=function(e){e=this.codec.encodeKey(e),this.batch.del(e)},o.prototype._clear=function(){this.batch.clear()},o.prototype._write=function(e,t){this.batch.write(e,t)}},function(e,t,r){function n(e){this.opts=e||{},this.encodings=i}var i=r(186);e.exports=n,n.prototype._encoding=function(e){return"string"==typeof e&&(e=i[e]),e||(e=i.id),e},n.prototype._keyEncoding=function(e,t){return this._encoding(t&&t.keyEncoding||e&&e.keyEncoding||this.opts.keyEncoding)},n.prototype._valueEncoding=function(e,t){return this._encoding(t&&(t.valueEncoding||t.encoding)||e&&(e.valueEncoding||e.encoding)||this.opts.valueEncoding||this.opts.encoding)},n.prototype.encodeKey=function(e,t,r){return this._keyEncoding(t,r).encode(e)},n.prototype.encodeValue=function(e,t,r){return this._valueEncoding(t,r).encode(e)},n.prototype.decodeKey=function(e,t){return this._keyEncoding(t).decode(e)},n.prototype.decodeValue=function(e,t){return this._valueEncoding(t).decode(e)},n.prototype.encodeBatch=function(e,t){var r=this;return e.map(function(e){var n={type:e.type,key:r.encodeKey(e.key,t,e)};return r.keyAsBuffer(t,e)&&(n.keyEncoding="binary"),e.prefix&&(n.prefix=e.prefix),"value"in e&&(n.value=r.encodeValue(e.value,t,e),r.valueAsBuffer(t,e)&&(n.valueEncoding="binary")),n})};var o=["lt","gt","lte","gte","start","end"];n.prototype.encodeLtgt=function(e){var t=this,r={};return Object.keys(e).forEach(function(n){r[n]=o.indexOf(n)>-1?t.encodeKey(e[n],e):e[n]}),r},n.prototype.createStreamDecoder=function(e){var t=this;return e.keys&&e.values?function(r,n){return{key:t.decodeKey(r,e),value:t.decodeValue(n,e)}}:e.keys?function(r){return t.decodeKey(r,e)}:e.values?function(r,n){return t.decodeValue(n,e)}:function(){}},n.prototype.keyAsBuffer=function(e){return this._keyEncoding(e).buffer},n.prototype.valueAsBuffer=function(e){return this._valueEncoding(e).buffer}},function(e,t,r){(function(e){function r(e){return e}function n(t){return void 0===t||null===t||e.isBuffer(t)}t.utf8=t["utf-8"]={encode:function(e){return n(e)?e:String(e)},decode:r,buffer:!1,type:"utf8"},t.json={encode:JSON.stringify,decode:JSON.parse,buffer:!1,type:"json"},t.binary={encode:function(t){return n(t)?t:new e(t)},decode:r,buffer:!0,type:"binary"},t.none={encode:r,decode:r,buffer:!1,type:"id"},t.id=t.none;["hex","ascii","base64","ucs2","ucs-2","utf16le","utf-16le"].forEach(function(r){t[r]={encode:function(t){return n(t)?t:new e(t,r)},decode:function(e){return e.toString(r)},buffer:!0,type:r}})}).call(t,r(1).Buffer)},function(e,t,r){(function(t){function n(e){if(!(this instanceof n))return new n(e);if(!e)throw new Error("constructor requires at least a location argument");this.IDBOptions={},this.location=e}e.exports=n;var i=r(188),o=r(68).AbstractLevelDOWN,s=r(6),a=r(192),c=r(194),f=r(195),u=r(201);s.inherits(n,o),n.prototype._open=function(e,t){var r=this,n={storeName:this.location,autoIncrement:!1,keyPath:null,onStoreReady:function(){t&&t(null,r.idb)},onError:function(e){t&&t(e)}};f(n,e),this.IDBOptions=n,this.idb=new i(n)},n.prototype._get=function(e,r,n){this.idb.get(e,function(i){if(void 0===i)return n(new Error("NotFound"));var o=!0;return!1===r.asBuffer&&(o=!1),r.raw&&(o=!1),o&&(i=i instanceof Uint8Array?u(i):new t(String(i))),n(null,i,e)},n)},n.prototype._del=function(e,t,r){this.idb.remove(e,r,r)},n.prototype._put=function(e,r,n,i){r instanceof ArrayBuffer&&(r=u(new Uint8Array(r)));var o=this.convertEncoding(e,r,n);t.isBuffer(o.value)&&("function"==typeof r.toArrayBuffer?o.value=new Uint8Array(r.toArrayBuffer()):o.value=new Uint8Array(r)),this.idb.put(o.key,o.value,function(){i()},i)},n.prototype.convertEncoding=function(e,t,r){if(r.raw)return{key:e,value:t};if(t){var n=t.toString();"NaN"===n&&(t="NaN")}var i=r.valueEncoding,o={key:e,value:t};return!t||i&&"binary"===i||"object"!=typeof o.value&&(o.value=n),o},n.prototype.iterator=function(e){return"object"!=typeof e&&(e={}),new a(this.idb,e)},n.prototype._batch=function(e,t,r){var n,i,o,s,a=[];if(0===e.length)return setTimeout(r,0);for(n=0;n0&&this._count++>=this._limit&&(n=!1),n&&this.callback(!1,t.key,t.value),t&&t.continue()},n.prototype._next=function(e){return e?this._keyRangeError?e():(this._started||(this.createIterator(),this._started=!0),void(this.callback=e)):new Error("next() requires a callback argument")}},function(e,t,r){(function(e){function r(e,t){return Object.hasOwnProperty.call(e,t)}function n(e){return void 0!==e&&""!==e}function r(e,t){return Object.hasOwnProperty.call(e,t)}function i(e,t){return Object.hasOwnProperty.call(e,t)&&t}t.compare=function(t,r){if(e.isBuffer(t)){for(var n=Math.min(t.length,r.length),i=0;ir?1:0};var o=t.lowerBoundKey=function(e){return i(e,"gt")||i(e,"gte")||i(e,"min")||(e.reverse?i(e,"end"):i(e,"start"))||void 0},s=t.lowerBound=function(e,t){var r=o(e);return r?e[r]:t},a=t.lowerBoundInclusive=function(e){return!r(e,"gt")},c=t.upperBoundInclusive=function(e){return!r(e,"lt")},f=t.lowerBoundExclusive=function(e){return!a(e)},u=t.upperBoundExclusive=function(e){return!c(e)},h=t.upperBoundKey=function(e){return i(e,"lt")||i(e,"lte")||i(e,"max")||(e.reverse?i(e,"start"):i(e,"end"))||void 0},d=t.upperBound=function(e,t){var r=h(e);return r?e[r]:t};t.start=function(e,t){return e.reverse?d(e,t):s(e,t)},t.end=function(e,t){return e.reverse?s(e,t):d(e,t)},t.startInclusive=function(e){return e.reverse?c(e):a(e)},t.endInclusive=function(e){return e.reverse?a(e):c(e)},t.toLtgt=function(e,n,i,o,s){n=n||{},i=i||function(e){return e};var a=arguments.length>3,c=t.lowerBoundKey(e),f=t.upperBoundKey(e);return c?"gt"===c?n.gt=i(e.gt,!1):n.gte=i(e[c],!1):a&&(n.gte=i(o,!1)),f?"lt"===f?n.lt=i(e.lt,!0):n.lte=i(e[f],!0):a&&(n.lte=i(s,!0)),null!=e.reverse&&(n.reverse=!!e.reverse),r(n,"max")&&delete n.max,r(n,"min")&&delete n.min,r(n,"start")&&delete n.start,r(n,"end")&&delete n.end,n},t.contains=function(e,r,i){i=i||t.compare;var o=s(e);if(n(o)){if((c=i(r,o))<0||0===c&&f(e))return!1}var a=d(e);if(n(a)){var c;if((c=i(r,a))>0||0===c&&u(e))return!1}return!0},t.filter=function(e,r){return function(n){return t.contains(e,n,r)}}}).call(t,r(1).Buffer)},function(e,t,r){var n=r(1).Buffer;e.exports=function(e){return n.isBuffer(e)||/\[object (.+Array|Array.+)\]/.test(Object.prototype.toString.call(e))}},function(e,t,r){var n=r(196),i=r(200);e.exports=function(){for(var e={},t=0;t2?arguments[2]:null;if(a===+a)for(i=0;i=0&&"[object Function]"===r.call(e.callee)),n}},function(e,t){e.exports=function(e){return null!==e&&("object"==typeof e||"function"==typeof e)}},function(e,t,r){(function(t){e.exports=function(e){return"function"==typeof t._augment&&t.TYPED_ARRAY_SUPPORT?t._augment(e):new t(e)}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";(function(t){const n=r(203);e.exports=class extends n{constructor(e){super(),this._ipfs=e}async load(e){0===e.indexOf("/ipfs")&&(e=e.split("/")[2]);try{const t=await this._ipfs.object.get(e),r=JSON.parse(t.toJSON().data);this._access=r}catch(e){console.log("ACCESS ERROR:",e)}}async save(){let e;try{const r=JSON.stringify(this._access,null,2);e=(await this._ipfs.object.put(new t(r))).toJSON().multihash.toString()}catch(e){console.log("ACCESS ERROR:",e)}return e}}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";e.exports=class{constructor(){this._access={admin:[],write:[],read:[]}}async load(e){}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(e,t){switch(e){case"admin":this._access.admin.push(t);break;case"write":this._access.write.push(t);break;case"read":this._access.read.push(t)}}remove(e,t){const r=(e,r)=>e.reduce((e,r)=>(r!==t&&e.push(r),e),[]);switch(e){case"admin":this._access.admin=r(this._access.admin);break;case"write":this._access.write=r(this._access.write);break;case"read":this._access.read=r(this._access.read)}}}},function(e,t,r){"use strict";const n=r(12),i=r(205);class o{constructor(e,t){this.root=e,this.path=t}toString(){return n.join("/orbitdb",this.root,this.path)}static isValid(e){const t=e.toString().split("/").filter((t,r)=>!((0===r||1===r)&&0===e.toString().indexOf("/orbit")&&"orbitdb"===t)).filter(e=>""!==e&&" "!==e),r=t[0].indexOf("Qm")>-1?i.fromB58String(t[0]):null;try{i.validate(r)}catch(e){return!1}return null!==r}static parse(e){if(!e)throw new Error(`Not a valid OrbitDB address: ${e}`);if(!o.isValid(e))throw new Error(`Not a valid OrbitDB address: ${e}`);const t=e.toString().split("/").filter((t,r)=>!((0===r||1===r)&&0===e.toString().indexOf("/orbit")&&"orbitdb"===t)).filter(e=>""!==e&&" "!==e);return new o(t[0],t.slice(1,t.length).join("/"))}}e.exports=o},function(e,t,r){"use strict";(function(e){function n(e){t.decode(e)}const i=r(206),o=r(208);t.names=o.names,t.codes=o.codes,t.defaultLengths=o.defaultLengths;const s=r(209);t.toHexString=function(t){if(!e.isBuffer(t))throw new Error("must be passed a buffer");return t.toString("hex")},t.fromHexString=function(t){return e.from(t,"hex")},t.toB58String=function(t){if(!e.isBuffer(t))throw new Error("must be passed a buffer");return i.encode(t)},t.fromB58String=function(t){let r=t;return e.isBuffer(t)&&(r=t.toString()),e.from(i.decode(r))},t.decode=function(r){if(!e.isBuffer(r))throw new Error("multihash must be a Buffer");if(r.length<3)throw new Error("multihash too short. must be > 3 bytes.");let n=s.decode(r);if(!t.isValidCode(n))throw new Error(`multihash unknown function code: 0x${n.toString(16)}`);r=r.slice(s.decode.bytes);let i=s.decode(r);if(i<1)throw new Error(`multihash invalid length: 0x${i.toString(16)}`);if((r=r.slice(s.decode.bytes)).length!==i)throw new Error(`multihash length inconsistent: 0x${r.toString("hex")}`);return{code:n,name:o.codes[n],length:i,digest:r}},t.encode=function(r,n,i){if(!r||!n)throw new Error("multihash encode requires at least two args: digest, code");const o=t.coerceCode(n);if(!e.isBuffer(r))throw new Error("digest should be a Buffer");if(null==i&&(i=r.length),i&&r.length!==i)throw new Error("digest length should be equal to specified length.");return e.concat([e.from(s.encode(o)),e.from(s.encode(i)),r])},t.coerceCode=function(e){let r=e;if("string"==typeof e){if(!o.names[e])throw new Error(`Unrecognized hash function named: ${e}`);r=o.names[e]}if("number"!=typeof r)throw new Error(`Hash function code should be a number. Got: ${r}`);if(!o.codes[r]&&!t.isAppCode(r))throw new Error(`Unrecognized function code: ${r}`);return r},t.isAppCode=function(e){return e>0&&e<16},t.isValidCode=function(e){return!!t.isAppCode(e)||!!o.codes[e]},t.validate=n,t.prefix=function(e){return n(e),e.slice(0,2)}}).call(t,r(1).Buffer)},function(e,t,r){var n=r(207);e.exports=n("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},function(e,t,r){var n=r(9).Buffer;e.exports=function(e){function t(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return n.allocUnsafe(0);for(var t=[0],s=0;s>=8;for(;f>0;)t.push(255&f),f>>=8}for(var u=0;e[u]===o&&u0;)r.push(s%i),s=s/i|0}for(var a="",c=0;0===t[c]&&c=0;--f)a+=e[r[f]];return a},decodeUnsafe:t,decode:function(e){var r=t(e);if(r)return r;throw new Error("Non-base"+i+" character")}}}},function(e,t,r){"use strict";t.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}),t.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"}),t.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(e,t,r){e.exports={encode:r(210),decode:r(211),encodingLength:r(212)}},function(e,t){function r(e,t,s){t=t||[];for(var a=s=s||0;e>=o;)t[s++]=255&e|n,e/=128;for(;e&i;)t[s++]=255&e|n,e>>>=7;return t[s]=0|e,r.bytes=s-a+1,t}e.exports=r;var n=128,i=-128,o=Math.pow(2,31)},function(e,t){function r(e,t){var o,s=0,a=0,c=t=t||0,f=e.length;do{if(c>=f)throw r.bytes=0,new RangeError("Could not decode varint");o=e[c++],s+=a<28?(o&i)<=n);return r.bytes=c-t,s}e.exports=r;var n=128,i=127},function(e,t){var r=Math.pow(2,7),n=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);e.exports=function(e){return e{const s={name:r,type:i,accessController:n.join("/ipfs",o)};return(await e.object.put(t.from(JSON.stringify(s)))).toJSON().multihash.toString()})}).call(t,r(1).Buffer)}]); \ No newline at end of file +var OrbitDB=function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=69)}([function(e,t){function r(){throw new Error("setTimeout has not been defined")}function n(){throw new Error("clearTimeout has not been defined")}function i(e){if(f===setTimeout)return setTimeout(e,0);if((f===r||!f)&&setTimeout)return f=setTimeout,setTimeout(e,0);try{return f(e,0)}catch(t){try{return f.call(null,e,0)}catch(t){return f.call(this,e,0)}}}function o(){p&&d&&(p=!1,d.length?l=d.concat(l):b=-1,l.length&&s())}function s(){if(!p){var e=i(o);p=!0;for(var t=l.length;t;){for(d=l,l=[];++b1)for(var r=1;r=n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n().toString(16)+" bytes");return 0|e}function h(e,t){if(o.isBuffer(e))return e.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;"string"!=typeof e&&(e=""+e);var r=e.length;if(0===r)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return N(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return R(e).length;default:if(n)return N(e).length;t=(""+t).toLowerCase(),n=!0}}function d(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if(r>>>=0,t>>>=0,r<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return function(e,t,r){var n=e.length;(!t||t<0)&&(t=0);(!r||r<0||r>n)&&(r=n);for(var i="",o=t;o2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:b(e,t,r,n,i);if("number"==typeof t)return t&=255,o.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):b(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function b(e,t,r,n,i){function o(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}var s=1,a=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,r/=2}var f;if(i){var u=-1;for(f=r;fa&&(r=a-c),f=r;f>=0;f--){for(var h=!0,d=0;di&&(n=i):n=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function S(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i239?4:o>223?3:o>191?2:1;if(i+a<=r){var c,f,u,h;switch(a){case 1:o<128&&(s=o);break;case 2:128==(192&(c=e[i+1]))&&(h=(31&o)<<6|63&c)>127&&(s=h);break;case 3:c=e[i+1],f=e[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=e[i+1],f=e[i+2],u=e[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,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),i+=a}return function(e){var t=e.length;if(t<=L)return String.fromCharCode.apply(String,e);var r="",n=0;for(;nr)throw new RangeError("Trying to access beyond buffer length")}function E(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||te.length)throw new RangeError("Index out of range")}function x(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,o=Math.min(e.length-r,2);i>>8*(n?i:1-i)}function M(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,o=Math.min(e.length-r,4);i>>8*(n?i:3-i)&255}function O(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function A(e,t,r,n,i){return i||O(e,0,r,4),j.write(e,t,r,n,23,4),r+4}function I(e,t,r,n,i){return i||O(e,0,r,8),j.write(e,t,r,n,52,8),r+8}function N(e,t){t=t||1/0;for(var r,n=e.length,i=null,o=[],s=0;s55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function R(e){return C.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(B,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function P(e,t,r,n){for(var i=0;i=t.length||i>=e.length);++i)t[i+r]=e[i];return i}var C=r(70),j=r(71),T=r(36);t.Buffer=o,t.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},t.INSPECT_MAX_BYTES=50,o.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(e){return!1}}(),t.kMaxLength=n(),o.poolSize=8192,o._augment=function(e){return e.__proto__=o.prototype,e},o.from=function(e,t,r){return s(null,e,t,r)},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(e,t,r){return function(e,t,r,n){return a(t),t<=0?i(e,t):void 0!==r?"string"==typeof n?i(e,t).fill(r,n):i(e,t).fill(r):i(e,t)}(null,e,t,r)},o.allocUnsafe=function(e){return c(null,e)},o.allocUnsafeSlow=function(e){return c(null,e)},o.isBuffer=function(e){return!(null==e||!e._isBuffer)},o.compare=function(e,t){if(!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var r=e.length,n=t.length,i=0,s=Math.min(r,n);i0&&(e=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(e+=" ... ")),""},o.prototype.compare=function(e,t,r,n,i){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(t>>>=0,r>>>=0,n>>>=0,i>>>=0,this===e)return 0;for(var s=i-n,a=r-t,c=Math.min(s,a),f=this.slice(n,i),u=e.slice(t,r),h=0;hi)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return y(this,e,t,r);case"utf8":case"utf-8":return g(this,e,t,r);case"ascii":return m(this,e,t,r);case"latin1":case"binary":return v(this,e,t,r);case"base64":return _(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return w(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).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(e,t){var r=this.length;e=~~e,t=void 0===t?r:~~t,e<0?(e+=r)<0&&(e=0):e>r&&(e=r),t<0?(t+=r)<0&&(t=0):t>r&&(t=r),t0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUInt8=function(e,t){return t||k(e,1,this.length),this[e]},o.prototype.readUInt16LE=function(e,t){return t||k(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUInt16BE=function(e,t){return t||k(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUInt32LE=function(e,t){return t||k(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUInt32BE=function(e,t){return t||k(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readIntLE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=this[e],i=1,o=0;++o=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e|=0,t|=0,r||k(e,t,this.length);for(var n=t,i=1,o=this[e+--n];n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return t||k(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){t||k(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){t||k(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return t||k(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return t||k(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readFloatLE=function(e,t){return t||k(e,4,this.length),j.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return t||k(e,4,this.length),j.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return t||k(e,8,this.length),j.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return t||k(e,8,this.length),j.read(this,e,!1,52,8)},o.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t|=0,r|=0,!n){E(this,e,t,r,Math.pow(2,8*r)-1,0)}var i=1,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+r},o.prototype.writeUInt8=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,1,255,0),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):x(this,e,t,!0),t+2},o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):x(this,e,t,!1),t+2},o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):M(this,e,t,!0),t+4},o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);E(this,e,t,r,i-1,-i)}var o=0,s=1,a=0;for(this[t]=255&e;++o>0)-a&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t|=0,!n){var i=Math.pow(2,8*r-1);E(this,e,t,r,i-1,-i)}var o=r-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,1,127,-128),o.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):x(this,e,t,!0),t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):x(this,e,t,!1),t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):M(this,e,t,!0),t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t|=0,r||E(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),o.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):M(this,e,t,!1),t+4},o.prototype.writeFloatLE=function(e,t,r){return A(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return A(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return I(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return I(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t=0;--i)e[i+t]=this[i+r];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,e||(e=0);var s;if("number"==typeof e)for(s=t;s0&&this._events[e].length>s&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,o,s,a;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],s=r.length,o=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(a=s;a-- >0;)if(r[a]===t||r[a].listener&&r[a].listener===t){o=a;break}if(o<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},function(e,t,r){"use strict";function n(e){return(e>>>24|e>>>8&65280|e<<8&16711680|(255&e)<<24)>>>0}function i(e){return 1===e.length?"0"+e:e}function o(e){return 7===e.length?"0"+e:6===e.length?"00"+e:5===e.length?"000"+e:4===e.length?"0000"+e:3===e.length?"00000"+e:2===e.length?"000000"+e:1===e.length?"0000000"+e:e}var s=r(11),a=r(4);t.inherits=a,t.toArray=function(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];var r=[];if("string"==typeof e)if(t){if("hex"===t)for((e=e.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(e="0"+e),n=0;n>8,s=255&i;o?r.push(o,s):r.push(s)}else for(n=0;n>>0}return o},t.split32=function(e,t){for(var r=new Array(4*e.length),n=0,i=0;n>>24,r[i+1]=o>>>16&255,r[i+2]=o>>>8&255,r[i+3]=255&o):(r[i+3]=o>>>24,r[i+2]=o>>>16&255,r[i+1]=o>>>8&255,r[i]=255&o)}return r},t.rotr32=function(e,t){return e>>>t|e<<32-t},t.rotl32=function(e,t){return e<>>32-t},t.sum32=function(e,t){return e+t>>>0},t.sum32_3=function(e,t,r){return e+t+r>>>0},t.sum32_4=function(e,t,r,n){return e+t+r+n>>>0},t.sum32_5=function(e,t,r,n,i){return e+t+r+n+i>>>0},t.sum64=function(e,t,r,n){var i=e[t],o=n+e[t+1]>>>0,s=(o>>0,e[t+1]=o},t.sum64_hi=function(e,t,r,n){return(t+n>>>0>>0},t.sum64_lo=function(e,t,r,n){return t+n>>>0},t.sum64_4_hi=function(e,t,r,n,i,o,s,a){var c=0,f=t;return c+=(f=f+n>>>0)>>0)>>0)>>0},t.sum64_4_lo=function(e,t,r,n,i,o,s,a){return t+n+o+a>>>0},t.sum64_5_hi=function(e,t,r,n,i,o,s,a,c,f){var u=0,h=t;return u+=(h=h+n>>>0)>>0)>>0)>>0)>>0},t.sum64_5_lo=function(e,t,r,n,i,o,s,a,c,f){return t+n+o+a+f>>>0},t.rotr64_hi=function(e,t,r){return(t<<32-r|e>>>r)>>>0},t.rotr64_lo=function(e,t,r){return(e<<32-r|t>>>r)>>>0},t.shr64_hi=function(e,t,r){return e>>>r},t.shr64_lo=function(e,t,r){return(e<<32-r|t>>>r)>>>0}},function(e,t,r){(function(e,n){function i(e,r){var n={seen:[],stylize:s};return arguments.length>=3&&(n.depth=arguments[2]),arguments.length>=4&&(n.colors=arguments[3]),h(r)?n.showHidden=r:r&&t._extend(n,r),b(n.showHidden)&&(n.showHidden=!1),b(n.depth)&&(n.depth=2),b(n.colors)&&(n.colors=!1),b(n.customInspect)&&(n.customInspect=!0),n.colors&&(n.stylize=o),a(n,e,n.depth)}function o(e,t){var r=i.styles[t];return r?"["+i.colors[r][0]+"m"+e+"["+i.colors[r][1]+"m":e}function s(e,t){return e}function a(e,r,n){if(e.customInspect&&r&&_(r.inspect)&&r.inspect!==t.inspect&&(!r.constructor||r.constructor.prototype!==r)){var i=r.inspect(n,e);return p(i)||(i=a(e,i,n)),i}var o=function(e,t){if(b(t))return e.stylize("undefined","undefined");if(p(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(l(t))return e.stylize(""+t,"number");if(h(t))return e.stylize(""+t,"boolean");if(d(t))return e.stylize("null","null")}(e,r);if(o)return o;var s=Object.keys(r),g=function(e){var t={};return e.forEach(function(e,r){t[e]=!0}),t}(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(r)),v(r)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return c(r);if(0===s.length){if(_(r)){var w=r.name?": "+r.name:"";return e.stylize("[Function"+w+"]","special")}if(y(r))return e.stylize(RegExp.prototype.toString.call(r),"regexp");if(m(r))return e.stylize(Date.prototype.toString.call(r),"date");if(v(r))return c(r)}var S="",E=!1,x=["{","}"];if(u(r)&&(E=!0,x=["[","]"]),_(r)){S=" [Function"+(r.name?": "+r.name:"")+"]"}if(y(r)&&(S=" "+RegExp.prototype.toString.call(r)),m(r)&&(S=" "+Date.prototype.toUTCString.call(r)),v(r)&&(S=" "+c(r)),0===s.length&&(!E||0==r.length))return x[0]+S+x[1];if(n<0)return y(r)?e.stylize(RegExp.prototype.toString.call(r),"regexp"):e.stylize("[Object]","special");e.seen.push(r);var M;return M=E?function(e,t,r,n,i){for(var o=[],s=0,a=t.length;s=0&&0,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(M,S,x)}function c(e){return"["+Error.prototype.toString.call(e)+"]"}function f(e,t,r,n,i,o){var s,c,f;if((f=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?c=f.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):f.set&&(c=e.stylize("[Setter]","special")),k(n,i)||(s="["+i+"]"),c||(e.seen.indexOf(f.value)<0?(c=d(r)?a(e,f.value,null):a(e,f.value,r-1)).indexOf("\n")>-1&&(c=o?c.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+c.split("\n").map(function(e){return" "+e}).join("\n")):c=e.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=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+c}function u(e){return Array.isArray(e)}function h(e){return"boolean"==typeof e}function d(e){return null===e}function l(e){return"number"==typeof e}function p(e){return"string"==typeof e}function b(e){return void 0===e}function y(e){return g(e)&&"[object RegExp]"===w(e)}function g(e){return"object"==typeof e&&null!==e}function m(e){return g(e)&&"[object Date]"===w(e)}function v(e){return g(e)&&("[object Error]"===w(e)||e instanceof Error)}function _(e){return"function"==typeof e}function w(e){return Object.prototype.toString.call(e)}function S(e){return e<10?"0"+e.toString(10):e.toString(10)}function k(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var E=/%[sdj%]/g;t.format=function(e){if(!p(e)){for(var t=[],r=0;r=o)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return"[Circular]"}default:return e}}),a=n[r];r=49&&s<=54?s-49+10:s>=17&&s<=22?s-17+10:15&s}return n}function a(e,t,r,n){for(var i=0,o=Math.min(e.length,r),s=t;s=49?a-49+10:a>=17?a-17+10:a}return i}function c(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var i=0|e.words[0],o=0|t.words[0],s=i*o,a=67108863&s,c=s/67108864|0;r.words[0]=a;for(var f=1;f>>26,h=67108863&c,d=Math.min(f,t.length-1),l=Math.max(0,f-e.length+1);l<=d;l++){var p=f-l|0;u+=(s=(i=0|e.words[p])*(o=0|t.words[l])+h)/67108864|0,h=67108863&s}r.words[f]=0|h,c=0|u}return 0!==c?r.words[f]=0|c:r.length--,r.strip()}function f(e,t,r){return(new u).mulp(e,t,r)}function u(e,t){this.x=e,this.y=t}function h(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function 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(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else n(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function g(e){y.call(this,e),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 e?e.exports=o:t.BN=o,o.BN=o,o.wordSize=26;var m;try{m=r(87).Buffer}catch(e){}o.isBN=function(e){return e instanceof o||null!==e&&"object"==typeof e&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return e.cmp(t)>0?e:t},o.min=function(e,t){return e.cmp(t)<0?e:t},o.prototype._init=function(e,t,r){if("number"==typeof e)return this._initNumber(e,t,r);if("object"==typeof e)return this._initArray(e,t,r);"hex"===t&&(t=16),n(t===(0|t)&&t>=2&&t<=36);var i=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&i++,16===t?this._parseHex(e,i):this._parseBase(e,t,i),"-"===e[0]&&(this.negative=1),this.strip(),"le"===r&&this._initArray(this.toArray(),t,r)},o.prototype._initNumber=function(e,t,r){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(n(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),t,r)},o.prototype._initArray=function(e,t,r){if(n("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var i=0;i=0;i-=3)s=e[i]|e[i-1]<<8|e[i-2]<<16,this.words[o]|=s<>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===r)for(i=0,o=0;i>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this.strip()},o.prototype._parseHex=function(e,t){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var r=0;r=t;r-=6)i=s(e,r,r+6),this.words[n]|=i<>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);r+6!==t&&(i=s(e,t,r+6),this.words[n]|=i<>>26-o&4194303),this.strip()},o.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var n=0,i=1;i<=67108863;i*=t)n++;n--,i=i/t|0;for(var o=e.length-r,s=o%n,c=Math.min(o,o-s)+r,f=0,u=r;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(e,t){e=e||10,t=0|t||1;var r;if(16===e||"hex"===e){r="";for(var i=0,o=0,s=0;s>>24-i&16777215)||s!==this.length-1?v[6-c.length]+c+r:c+r,(i+=2)>=26&&(i-=26,s--)}for(0!==o&&(r=o.toString(16)+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(e===(0|e)&&e>=2&&e<=36){var f=_[e],u=w[e];r="";var h=this.clone();for(h.negative=0;!h.isZero();){var d=h.modn(u).toString(e);r=(h=h.idivn(u)).isZero()?d+r:v[f-d.length]+d+r}for(this.isZero()&&(r="0"+r);r.length%t!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(e,t){return n(void 0!==m),this.toArrayLike(m,e,t)},o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,r){var i=this.byteLength(),o=r||Math.max(1,i);n(i<=o,"byte array longer than desired length"),n(o>0,"Requested array length <= 0"),this.strip();var s,a,c="le"===t,f=new e(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&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;te.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;re.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;ne.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){n("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),r=e%26;this._expand(t),r>0&&t--;for(var i=0;i0&&(this.words[i]=~this.words[i]&67108863>>26-r),this.strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){n("number"==typeof e&&e>=0);var r=e/26|0,i=e%26;return this._expand(r+1),this.words[r]=t?this.words[r]|1<e.length?(r=this,n=e):(r=e,n=this);for(var i=0,o=0;o>>26;for(;0!==i&&o>>26;if(this.length=r.length,0!==i)this.words[this.length]=i,this.length++;else if(r!==this)for(;oe.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r=this.cmp(e);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;var n,i;r>0?(n=this,i=e):(n=e,i=this);for(var o=0,s=0;s>26,this.words[s]=67108863&t;for(;0!==o&&s>26,this.words[s]=67108863&t;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,E=S>>>13,x=0|s[5],M=8191&x,O=x>>>13,A=0|s[6],I=8191&A,N=A>>>13,R=0|s[7],P=8191&R,C=R>>>13,j=0|s[8],T=8191&j,L=j>>>13,B=0|s[9],D=8191&B,q=B>>>13,F=0|a[0],z=8191&F,U=F>>>13,K=0|a[1],G=8191&K,H=K>>>13,W=0|a[2],Y=8191&W,V=W>>>13,J=0|a[3],$=8191&J,X=J>>>13,Z=0|a[4],Q=8191&Z,ee=Z>>>13,te=0|a[5],re=8191&te,ne=te>>>13,ie=0|a[6],oe=8191&ie,se=ie>>>13,ae=0|a[7],ce=8191&ae,fe=ae>>>13,ue=0|a[8],he=8191&ue,de=ue>>>13,le=0|a[9],pe=8191&le,be=le>>>13;r.negative=e.negative^t.negative,r.length=19;var ye=(f+(n=Math.imul(h,z))|0)+((8191&(i=(i=Math.imul(h,U))+Math.imul(d,z)|0))<<13)|0;f=((o=Math.imul(d,U))+(i>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(p,z),i=(i=Math.imul(p,U))+Math.imul(b,z)|0,o=Math.imul(b,U);var ge=(f+(n=n+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)+(ge>>>26)|0,ge&=67108863,n=Math.imul(g,z),i=(i=Math.imul(g,U))+Math.imul(m,z)|0,o=Math.imul(m,U),n=n+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 me=(f+(n=n+Math.imul(h,Y)|0)|0)+((8191&(i=(i=i+Math.imul(h,V)|0)+Math.imul(d,Y)|0))<<13)|0;f=((o=o+Math.imul(d,V)|0)+(i>>>13)|0)+(me>>>26)|0,me&=67108863,n=Math.imul(_,z),i=(i=Math.imul(_,U))+Math.imul(w,z)|0,o=Math.imul(w,U),n=n+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,n=n+Math.imul(p,Y)|0,i=(i=i+Math.imul(p,V)|0)+Math.imul(b,Y)|0,o=o+Math.imul(b,V)|0;var ve=(f+(n=n+Math.imul(h,$)|0)|0)+((8191&(i=(i=i+Math.imul(h,X)|0)+Math.imul(d,$)|0))<<13)|0;f=((o=o+Math.imul(d,X)|0)+(i>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(k,z),i=(i=Math.imul(k,U))+Math.imul(E,z)|0,o=Math.imul(E,U),n=n+Math.imul(_,G)|0,i=(i=i+Math.imul(_,H)|0)+Math.imul(w,G)|0,o=o+Math.imul(w,H)|0,n=n+Math.imul(g,Y)|0,i=(i=i+Math.imul(g,V)|0)+Math.imul(m,Y)|0,o=o+Math.imul(m,V)|0,n=n+Math.imul(p,$)|0,i=(i=i+Math.imul(p,X)|0)+Math.imul(b,$)|0,o=o+Math.imul(b,X)|0;var _e=(f+(n=n+Math.imul(h,Q)|0)|0)+((8191&(i=(i=i+Math.imul(h,ee)|0)+Math.imul(d,Q)|0))<<13)|0;f=((o=o+Math.imul(d,ee)|0)+(i>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(M,z),i=(i=Math.imul(M,U))+Math.imul(O,z)|0,o=Math.imul(O,U),n=n+Math.imul(k,G)|0,i=(i=i+Math.imul(k,H)|0)+Math.imul(E,G)|0,o=o+Math.imul(E,H)|0,n=n+Math.imul(_,Y)|0,i=(i=i+Math.imul(_,V)|0)+Math.imul(w,Y)|0,o=o+Math.imul(w,V)|0,n=n+Math.imul(g,$)|0,i=(i=i+Math.imul(g,X)|0)+Math.imul(m,$)|0,o=o+Math.imul(m,X)|0,n=n+Math.imul(p,Q)|0,i=(i=i+Math.imul(p,ee)|0)+Math.imul(b,Q)|0,o=o+Math.imul(b,ee)|0;var we=(f+(n=n+Math.imul(h,re)|0)|0)+((8191&(i=(i=i+Math.imul(h,ne)|0)+Math.imul(d,re)|0))<<13)|0;f=((o=o+Math.imul(d,ne)|0)+(i>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(I,z),i=(i=Math.imul(I,U))+Math.imul(N,z)|0,o=Math.imul(N,U),n=n+Math.imul(M,G)|0,i=(i=i+Math.imul(M,H)|0)+Math.imul(O,G)|0,o=o+Math.imul(O,H)|0,n=n+Math.imul(k,Y)|0,i=(i=i+Math.imul(k,V)|0)+Math.imul(E,Y)|0,o=o+Math.imul(E,V)|0,n=n+Math.imul(_,$)|0,i=(i=i+Math.imul(_,X)|0)+Math.imul(w,$)|0,o=o+Math.imul(w,X)|0,n=n+Math.imul(g,Q)|0,i=(i=i+Math.imul(g,ee)|0)+Math.imul(m,Q)|0,o=o+Math.imul(m,ee)|0,n=n+Math.imul(p,re)|0,i=(i=i+Math.imul(p,ne)|0)+Math.imul(b,re)|0,o=o+Math.imul(b,ne)|0;var Se=(f+(n=n+Math.imul(h,oe)|0)|0)+((8191&(i=(i=i+Math.imul(h,se)|0)+Math.imul(d,oe)|0))<<13)|0;f=((o=o+Math.imul(d,se)|0)+(i>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(P,z),i=(i=Math.imul(P,U))+Math.imul(C,z)|0,o=Math.imul(C,U),n=n+Math.imul(I,G)|0,i=(i=i+Math.imul(I,H)|0)+Math.imul(N,G)|0,o=o+Math.imul(N,H)|0,n=n+Math.imul(M,Y)|0,i=(i=i+Math.imul(M,V)|0)+Math.imul(O,Y)|0,o=o+Math.imul(O,V)|0,n=n+Math.imul(k,$)|0,i=(i=i+Math.imul(k,X)|0)+Math.imul(E,$)|0,o=o+Math.imul(E,X)|0,n=n+Math.imul(_,Q)|0,i=(i=i+Math.imul(_,ee)|0)+Math.imul(w,Q)|0,o=o+Math.imul(w,ee)|0,n=n+Math.imul(g,re)|0,i=(i=i+Math.imul(g,ne)|0)+Math.imul(m,re)|0,o=o+Math.imul(m,ne)|0,n=n+Math.imul(p,oe)|0,i=(i=i+Math.imul(p,se)|0)+Math.imul(b,oe)|0,o=o+Math.imul(b,se)|0;var ke=(f+(n=n+Math.imul(h,ce)|0)|0)+((8191&(i=(i=i+Math.imul(h,fe)|0)+Math.imul(d,ce)|0))<<13)|0;f=((o=o+Math.imul(d,fe)|0)+(i>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(T,z),i=(i=Math.imul(T,U))+Math.imul(L,z)|0,o=Math.imul(L,U),n=n+Math.imul(P,G)|0,i=(i=i+Math.imul(P,H)|0)+Math.imul(C,G)|0,o=o+Math.imul(C,H)|0,n=n+Math.imul(I,Y)|0,i=(i=i+Math.imul(I,V)|0)+Math.imul(N,Y)|0,o=o+Math.imul(N,V)|0,n=n+Math.imul(M,$)|0,i=(i=i+Math.imul(M,X)|0)+Math.imul(O,$)|0,o=o+Math.imul(O,X)|0,n=n+Math.imul(k,Q)|0,i=(i=i+Math.imul(k,ee)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,ee)|0,n=n+Math.imul(_,re)|0,i=(i=i+Math.imul(_,ne)|0)+Math.imul(w,re)|0,o=o+Math.imul(w,ne)|0,n=n+Math.imul(g,oe)|0,i=(i=i+Math.imul(g,se)|0)+Math.imul(m,oe)|0,o=o+Math.imul(m,se)|0,n=n+Math.imul(p,ce)|0,i=(i=i+Math.imul(p,fe)|0)+Math.imul(b,ce)|0,o=o+Math.imul(b,fe)|0;var Ee=(f+(n=n+Math.imul(h,he)|0)|0)+((8191&(i=(i=i+Math.imul(h,de)|0)+Math.imul(d,he)|0))<<13)|0;f=((o=o+Math.imul(d,de)|0)+(i>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(D,z),i=(i=Math.imul(D,U))+Math.imul(q,z)|0,o=Math.imul(q,U),n=n+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,n=n+Math.imul(P,Y)|0,i=(i=i+Math.imul(P,V)|0)+Math.imul(C,Y)|0,o=o+Math.imul(C,V)|0,n=n+Math.imul(I,$)|0,i=(i=i+Math.imul(I,X)|0)+Math.imul(N,$)|0,o=o+Math.imul(N,X)|0,n=n+Math.imul(M,Q)|0,i=(i=i+Math.imul(M,ee)|0)+Math.imul(O,Q)|0,o=o+Math.imul(O,ee)|0,n=n+Math.imul(k,re)|0,i=(i=i+Math.imul(k,ne)|0)+Math.imul(E,re)|0,o=o+Math.imul(E,ne)|0,n=n+Math.imul(_,oe)|0,i=(i=i+Math.imul(_,se)|0)+Math.imul(w,oe)|0,o=o+Math.imul(w,se)|0,n=n+Math.imul(g,ce)|0,i=(i=i+Math.imul(g,fe)|0)+Math.imul(m,ce)|0,o=o+Math.imul(m,fe)|0,n=n+Math.imul(p,he)|0,i=(i=i+Math.imul(p,de)|0)+Math.imul(b,he)|0,o=o+Math.imul(b,de)|0;var xe=(f+(n=n+Math.imul(h,pe)|0)|0)+((8191&(i=(i=i+Math.imul(h,be)|0)+Math.imul(d,pe)|0))<<13)|0;f=((o=o+Math.imul(d,be)|0)+(i>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(D,G),i=(i=Math.imul(D,H))+Math.imul(q,G)|0,o=Math.imul(q,H),n=n+Math.imul(T,Y)|0,i=(i=i+Math.imul(T,V)|0)+Math.imul(L,Y)|0,o=o+Math.imul(L,V)|0,n=n+Math.imul(P,$)|0,i=(i=i+Math.imul(P,X)|0)+Math.imul(C,$)|0,o=o+Math.imul(C,X)|0,n=n+Math.imul(I,Q)|0,i=(i=i+Math.imul(I,ee)|0)+Math.imul(N,Q)|0,o=o+Math.imul(N,ee)|0,n=n+Math.imul(M,re)|0,i=(i=i+Math.imul(M,ne)|0)+Math.imul(O,re)|0,o=o+Math.imul(O,ne)|0,n=n+Math.imul(k,oe)|0,i=(i=i+Math.imul(k,se)|0)+Math.imul(E,oe)|0,o=o+Math.imul(E,se)|0,n=n+Math.imul(_,ce)|0,i=(i=i+Math.imul(_,fe)|0)+Math.imul(w,ce)|0,o=o+Math.imul(w,fe)|0,n=n+Math.imul(g,he)|0,i=(i=i+Math.imul(g,de)|0)+Math.imul(m,he)|0,o=o+Math.imul(m,de)|0;var Me=(f+(n=n+Math.imul(p,pe)|0)|0)+((8191&(i=(i=i+Math.imul(p,be)|0)+Math.imul(b,pe)|0))<<13)|0;f=((o=o+Math.imul(b,be)|0)+(i>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(D,Y),i=(i=Math.imul(D,V))+Math.imul(q,Y)|0,o=Math.imul(q,V),n=n+Math.imul(T,$)|0,i=(i=i+Math.imul(T,X)|0)+Math.imul(L,$)|0,o=o+Math.imul(L,X)|0,n=n+Math.imul(P,Q)|0,i=(i=i+Math.imul(P,ee)|0)+Math.imul(C,Q)|0,o=o+Math.imul(C,ee)|0,n=n+Math.imul(I,re)|0,i=(i=i+Math.imul(I,ne)|0)+Math.imul(N,re)|0,o=o+Math.imul(N,ne)|0,n=n+Math.imul(M,oe)|0,i=(i=i+Math.imul(M,se)|0)+Math.imul(O,oe)|0,o=o+Math.imul(O,se)|0,n=n+Math.imul(k,ce)|0,i=(i=i+Math.imul(k,fe)|0)+Math.imul(E,ce)|0,o=o+Math.imul(E,fe)|0,n=n+Math.imul(_,he)|0,i=(i=i+Math.imul(_,de)|0)+Math.imul(w,he)|0,o=o+Math.imul(w,de)|0;var Oe=(f+(n=n+Math.imul(g,pe)|0)|0)+((8191&(i=(i=i+Math.imul(g,be)|0)+Math.imul(m,pe)|0))<<13)|0;f=((o=o+Math.imul(m,be)|0)+(i>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,n=Math.imul(D,$),i=(i=Math.imul(D,X))+Math.imul(q,$)|0,o=Math.imul(q,X),n=n+Math.imul(T,Q)|0,i=(i=i+Math.imul(T,ee)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,ee)|0,n=n+Math.imul(P,re)|0,i=(i=i+Math.imul(P,ne)|0)+Math.imul(C,re)|0,o=o+Math.imul(C,ne)|0,n=n+Math.imul(I,oe)|0,i=(i=i+Math.imul(I,se)|0)+Math.imul(N,oe)|0,o=o+Math.imul(N,se)|0,n=n+Math.imul(M,ce)|0,i=(i=i+Math.imul(M,fe)|0)+Math.imul(O,ce)|0,o=o+Math.imul(O,fe)|0,n=n+Math.imul(k,he)|0,i=(i=i+Math.imul(k,de)|0)+Math.imul(E,he)|0,o=o+Math.imul(E,de)|0;var Ae=(f+(n=n+Math.imul(_,pe)|0)|0)+((8191&(i=(i=i+Math.imul(_,be)|0)+Math.imul(w,pe)|0))<<13)|0;f=((o=o+Math.imul(w,be)|0)+(i>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(D,Q),i=(i=Math.imul(D,ee))+Math.imul(q,Q)|0,o=Math.imul(q,ee),n=n+Math.imul(T,re)|0,i=(i=i+Math.imul(T,ne)|0)+Math.imul(L,re)|0,o=o+Math.imul(L,ne)|0,n=n+Math.imul(P,oe)|0,i=(i=i+Math.imul(P,se)|0)+Math.imul(C,oe)|0,o=o+Math.imul(C,se)|0,n=n+Math.imul(I,ce)|0,i=(i=i+Math.imul(I,fe)|0)+Math.imul(N,ce)|0,o=o+Math.imul(N,fe)|0,n=n+Math.imul(M,he)|0,i=(i=i+Math.imul(M,de)|0)+Math.imul(O,he)|0,o=o+Math.imul(O,de)|0;var Ie=(f+(n=n+Math.imul(k,pe)|0)|0)+((8191&(i=(i=i+Math.imul(k,be)|0)+Math.imul(E,pe)|0))<<13)|0;f=((o=o+Math.imul(E,be)|0)+(i>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(D,re),i=(i=Math.imul(D,ne))+Math.imul(q,re)|0,o=Math.imul(q,ne),n=n+Math.imul(T,oe)|0,i=(i=i+Math.imul(T,se)|0)+Math.imul(L,oe)|0,o=o+Math.imul(L,se)|0,n=n+Math.imul(P,ce)|0,i=(i=i+Math.imul(P,fe)|0)+Math.imul(C,ce)|0,o=o+Math.imul(C,fe)|0,n=n+Math.imul(I,he)|0,i=(i=i+Math.imul(I,de)|0)+Math.imul(N,he)|0,o=o+Math.imul(N,de)|0;var Ne=(f+(n=n+Math.imul(M,pe)|0)|0)+((8191&(i=(i=i+Math.imul(M,be)|0)+Math.imul(O,pe)|0))<<13)|0;f=((o=o+Math.imul(O,be)|0)+(i>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,n=Math.imul(D,oe),i=(i=Math.imul(D,se))+Math.imul(q,oe)|0,o=Math.imul(q,se),n=n+Math.imul(T,ce)|0,i=(i=i+Math.imul(T,fe)|0)+Math.imul(L,ce)|0,o=o+Math.imul(L,fe)|0,n=n+Math.imul(P,he)|0,i=(i=i+Math.imul(P,de)|0)+Math.imul(C,he)|0,o=o+Math.imul(C,de)|0;var Re=(f+(n=n+Math.imul(I,pe)|0)|0)+((8191&(i=(i=i+Math.imul(I,be)|0)+Math.imul(N,pe)|0))<<13)|0;f=((o=o+Math.imul(N,be)|0)+(i>>>13)|0)+(Re>>>26)|0,Re&=67108863,n=Math.imul(D,ce),i=(i=Math.imul(D,fe))+Math.imul(q,ce)|0,o=Math.imul(q,fe),n=n+Math.imul(T,he)|0,i=(i=i+Math.imul(T,de)|0)+Math.imul(L,he)|0,o=o+Math.imul(L,de)|0;var Pe=(f+(n=n+Math.imul(P,pe)|0)|0)+((8191&(i=(i=i+Math.imul(P,be)|0)+Math.imul(C,pe)|0))<<13)|0;f=((o=o+Math.imul(C,be)|0)+(i>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(D,he),i=(i=Math.imul(D,de))+Math.imul(q,he)|0,o=Math.imul(q,de);var Ce=(f+(n=n+Math.imul(T,pe)|0)|0)+((8191&(i=(i=i+Math.imul(T,be)|0)+Math.imul(L,pe)|0))<<13)|0;f=((o=o+Math.imul(L,be)|0)+(i>>>13)|0)+(Ce>>>26)|0,Ce&=67108863;var je=(f+(n=Math.imul(D,pe))|0)+((8191&(i=(i=Math.imul(D,be))+Math.imul(q,pe)|0))<<13)|0;return f=((o=Math.imul(q,be))+(i>>>13)|0)+(je>>>26)|0,je&=67108863,c[0]=ye,c[1]=ge,c[2]=me,c[3]=ve,c[4]=_e,c[5]=we,c[6]=Se,c[7]=ke,c[8]=Ee,c[9]=xe,c[10]=Me,c[11]=Oe,c[12]=Ae,c[13]=Ie,c[14]=Ne,c[15]=Re,c[16]=Pe,c[17]=Ce,c[18]=je,0!==f&&(c[19]=f,r.length++),r};Math.imul||(S=c),o.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?S(this,e,t):r<63?c(this,e,t):r<1024?function(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,i=0,o=0;o>>26)|0)>>>26,s&=67108863}r.words[o]=a,n=s,s=i}return 0!==n?r.words[o]=n:r.length--,r.strip()}(this,e,t):f(this,e,t)},u.prototype.makeRBT=function(e){for(var t=new Array(e),r=o.prototype._countBits(e)-1,n=0;n>=1;return n},u.prototype.permute=function(e,t,r,n,i,o){for(var s=0;s>>=1)i++;return 1<>>=13,r[2*s+1]=8191&o,o>>>=13;for(s=2*t;s>=26,t+=i/67108864|0,t+=o>>>26,this.words[r]=67108863&o}return 0!==t&&(this.words[r]=t,this.length++),this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r>>i}return t}(e);if(0===t.length)return new o(1);for(var r=this,n=0;n=0);var t,r=e%26,i=(e-r)/26,o=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(t=0;t>>26-r}s&&(this.words[t]=s,this.length++)}if(0!==i){for(t=this.length-1;t>=0;t--)this.words[t+i]=this.words[t];for(t=0;t=0);var i;i=t?(t-t%26)/26:0;var o=e%26,s=Math.min((e-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(e,t,r){return n(0===this.negative),this.iushrn(e,t,r)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){n("number"==typeof e&&e>=0);var t=e%26,r=(e-t)/26,i=1<=0);var t=e%26,r=(e-t)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==t&&r++,this.length=Math.min(r,this.length),0!==t){var i=67108863^67108863>>>t<=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},o.prototype.isubn=function(e){if(n("number"==typeof e),n(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t>26)-(c/67108864|0),this.words[i+r]=67108863&s}for(;i>26,this.words[i+r]=67108863&s;if(0===a)return this.strip();for(n(-1===a),a=0,i=0;i>26,this.words[i]=67108863&s;return this.negative=1,this.strip()},o.prototype._wordDiv=function(e,t){var r=this.length-e.length,n=this.clone(),i=e,s=0|i.words[i.length-1];0!==(r=26-this._countBits(s))&&(i=i.ushln(r),n.iushln(r),s=0|i.words[i.length-1]);var a,c=n.length-i.length;if("mod"!==t){(a=new o(null)).length=c+1,a.words=new Array(a.length);for(var f=0;f=0;h--){var d=67108864*(0|n.words[i.length+h])+(0|n.words[i.length+h-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(i,d,h);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(i,1,h),n.isZero()||(n.negative^=1);a&&(a.words[h]=d)}return a&&a.strip(),n.strip(),"div"!==t&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},o.prototype.divmod=function(e,t,r){if(n(!e.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var i,s,a;return 0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(i=a.div.neg()),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(e)),{div:i,mod:s}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(e)),{div:a.div,mod:s}):e.length>this.length||this.cmp(e)<0?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modn(e.words[0]))}:this._wordDiv(e,t)},o.prototype.div=function(e){return this.divmod(e,"div",!1).div},o.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var r=0!==t.div.negative?t.mod.isub(e):t.mod,n=e.ushrn(1),i=e.andln(1),o=r.cmp(n);return o<0||1===i&&0===o?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},o.prototype.modn=function(e){n(e<=67108863);for(var t=(1<<26)%e,r=0,i=this.length-1;i>=0;i--)r=(t*r+(0|this.words[i]))%e;return r},o.prototype.idivn=function(e){n(e<=67108863);for(var t=0,r=this.length-1;r>=0;r--){var i=(0|this.words[r])+67108864*t;this.words[r]=i/e|0,t=i%e}return this.strip()},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i=new o(1),s=new o(0),a=new o(0),c=new o(1),f=0;t.isEven()&&r.isEven();)t.iushrn(1),r.iushrn(1),++f;for(var u=r.clone(),h=t.clone();!t.isZero();){for(var d=0,l=1;0==(t.words[0]&l)&&d<26;++d,l<<=1);if(d>0)for(t.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==(r.words[0]&b)&&p<26;++p,b<<=1);if(p>0)for(r.iushrn(p);p-- >0;)(a.isOdd()||c.isOdd())&&(a.iadd(u),c.isub(h)),a.iushrn(1),c.iushrn(1);t.cmp(r)>=0?(t.isub(r),i.isub(a),s.isub(c)):(r.isub(t),a.isub(i),c.isub(s))}return{a:a,b:c,gcd:r.iushln(f)}},o.prototype._invmp=function(e){n(0===e.negative),n(!e.isZero());var t=this,r=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var i=new o(1),s=new o(0),a=r.clone();t.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,f=1;0==(t.words[0]&f)&&c<26;++c,f<<=1);if(c>0)for(t.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(a),i.iushrn(1);for(var u=0,h=1;0==(r.words[0]&h)&&u<26;++u,h<<=1);if(u>0)for(r.iushrn(u);u-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);t.cmp(r)>=0?(t.isub(r),i.isub(s)):(r.isub(t),s.isub(i))}var d;return(d=0===t.cmpn(1)?i:s).cmpn(0)<0&&d.iadd(e),d},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),r=e.clone();t.negative=0,r.negative=0;for(var n=0;t.isEven()&&r.isEven();n++)t.iushrn(1),r.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;r.isEven();)r.iushrn(1);var i=t.cmp(r);if(i<0){var o=t;t=r,r=o}else if(0===i||0===r.cmpn(1))break;t.isub(r)}return r.iushln(n)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){n("number"==typeof e);var t=e%26,r=(e-t)/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(e){var t=e<0;if(0!==this.negative&&!t)return-1;if(0===this.negative&&t)return 1;this.strip();var r;if(this.length>1)r=1;else{t&&(e=-e),n(e<=67108863,"Number is too big");var i=0|this.words[0];r=i===e?0:ie.length)return 1;if(this.length=0;r--){var n=0|this.words[r],i=0|e.words[r];if(n!==i){ni&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return this.cmpn(e)>=0},o.prototype.gte=function(e){return this.cmp(e)>=0},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return this.cmpn(e)<=0},o.prototype.lte=function(e){return this.cmp(e)<=0},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new y(e)},o.prototype.toRed=function(e){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return n(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return n(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var k={k256:null,p224:null,p192:null,p25519:null};h.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},h.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t0?r.isub(this.p):r.strip(),r},h.prototype.split=function(e,t){e.iushrn(this.n,0,t)},h.prototype.imulK=function(e){return e.imul(this.k)},i(d,h),d.prototype.split=function(e,t){for(var r=Math.min(e.length,9),n=0;n>>22,i=o}i>>>=22,e.words[n-10]=i,0===i&&e.length>10?e.length-=10:e.length-=9},d.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r>>=26,e.words[r]=i,t=n}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(k[e])return k[e];var t;if("k256"===e)t=new d;else if("p224"===e)t=new l;else if("p192"===e)t=new p;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new b}return k[e]=t,t},y.prototype._verify1=function(e){n(0===e.negative,"red works only with positives"),n(e.red,"red works only with red numbers")},y.prototype._verify2=function(e,t){n(0==(e.negative|t.negative),"red works only with positives"),n(e.red&&e.red===t.red,"red works only with red numbers")},y.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):e.umod(this.m)._forceRed(this)},y.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},y.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},y.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},y.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},y.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},y.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},y.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},y.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},y.prototype.isqr=function(e){return this.imul(e,e.clone())},y.prototype.sqr=function(e){return this.mul(e,e)},y.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(n(t%2==1),3===t){var r=this.m.add(new o(1)).iushrn(2);return this.pow(e,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!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(e,i.addn(1).iushrn(1)),l=this.pow(e,i),p=s;0!==l.cmp(a);){for(var b=l,y=0;0!==b.cmp(a);y++)b=b.redSqr();n(y=0;n--){for(var f=t.words[n],u=c-1;u>=0;u--){var h=f>>u&1;i!==r[0]&&(i=this.sqr(i)),0!==h||0!==s?(s<<=1,s|=h,(4===++a||0===n&&0===u)&&(i=this.mul(i,r[s]),a=0,s=0)):a=0}c=26}return i},y.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},y.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new g(e)},i(g,y),g.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},g.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},g.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).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(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=r.isub(n).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(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===e||e,this)}).call(t,r(47)(e))},function(e,t,r){function n(e,t){for(var r in e)t[r]=e[r]}function i(e,t,r){return s(e,t,r)}var o=r(1),s=o.Buffer;s.from&&s.alloc&&s.allocUnsafe&&s.allocUnsafeSlow?e.exports=o:(n(o,t),t.Buffer=i),n(s,i),i.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return s(e,t,r)},i.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=s(e);return void 0!==t?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n},i.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return s(e)},i.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o.SlowBuffer(e)}},function(e,t,r){"use strict";function n(e){if(!(this instanceof n))return new n(e);f.call(this,e),u.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",i)}function i(){this.allowHalfOpen||this._writableState.ended||s(o,this)}function o(e){e.end()}var s=r(21),a=Object.keys||function(e){var t=[];for(var r in e)t.push(r);return t};e.exports=n;var c=r(15);c.inherits=r(4);var f=r(37),u=r(25);c.inherits(n,f);for(var h=a(u.prototype),d=0;d=-1&&!i;o--){var s=o>=0?arguments[o]:e.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(t=s+"/"+t,i="/"===s.charAt(0))}return t=r(n(t.split("/"),function(e){return!!e}),!i).join("/"),(i?"/":"")+t||"."},t.normalize=function(e){var i=t.isAbsolute(e),o="/"===s(e,-1);return(e=r(n(e.split("/"),function(e){return!!e}),!i).join("/"))||i||(e="."),e&&o&&(e+="/"),(i?"/":"")+e},t.isAbsolute=function(e){return"/"===e.charAt(0)},t.join=function(){var e=Array.prototype.slice.call(arguments,0);return t.normalize(n(e,function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},t.relative=function(e,r){function n(e){for(var t=0;t=0&&""===e[r];r--);return t>r?[]:e.slice(t,r-t+1)}e=t.resolve(e).substr(1),r=t.resolve(r).substr(1);for(var i=n(e.split("/")),o=n(r.split("/")),s=Math.min(i.length,o.length),a=s,c=0;c=this._delta8){var r=(e=this.pending).length%this._delta8;this.pending=e.slice(e.length-r,e.length),0===this.pending.length&&(this.pending=null),e=i.join32(e,0,e.length-r,this.endian);for(var n=0;n>>24&255,n[i++]=e>>>16&255,n[i++]=e>>>8&255,n[i++]=255&e}else for(n[i++]=255&e,n[i++]=e>>>8&255,n[i++]=e>>>16&255,n[i++]=e>>>24&255,n[i++]=0,n[i++]=0,n[i++]=0,n[i++]=0,o=8;o{this._replicationInfo.queued++,this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._oplog.length,e.clock?e.clock.time:0]),this.events.emit("replicate",this.address.toString(),e)}),this._loader.on("load.progress",(e,t,r,n,i)=>{this._replicationInfo.buffered>i?this._replicationInfo.progress=this._replicationInfo.progress+i:this._replicationInfo.progress=Math.max.apply(null,[this._oplog.length,this._replicationInfo.progress,this._oplog.length+i]),this._replicationInfo.buffered=i,this._replicationInfo.max=Math.max.apply(null,[this._replicationInfo.max,this._replicationInfo.progress]),this.events.emit("replicate.progress",this.address.toString(),t,r,this._replicationInfo.progress,n)}),this._loader.on("load.end",async(e,t)=>{try{for(let t of e)await this._oplog.join(t,-1,this._oplog.id);this._replicationInfo.max=Math.max(this._replicationInfo.max,this._oplog.length),this._index.updateIndex(this._oplog),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length]),this._replicationInfo.queued-=e.length,this.events.emit("replicated",this.address.toString(),e.length)}catch(e){console.error(e)}})}catch(e){console.error("Store Error:",e)}}get all(){return Array.isArray(this._index._index)?this._index._index:Object.keys(this._index._index).map(e=>this._index._index[e])}get type(){return this._type}get key(){return this._key}async close(){return this._replicationInfo={buffered:0,queued:0,progress:0,max:0},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"),await this._cache.close(),this.events.emit("closed",this.address.toString()),Promise.resolve()}async drop(){await this._cache.del(this.address.toString()+"/_manifest",null),await this._cache.del(this.address.toString(),null),await this._cache.del("_localHeads",null),await this._cache.del("_remoteHeads",null),await this._cache.del("snapshot",null),await this._cache.del("queue",null),await this.close(),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 Cache(this.options.path,this.dbname)}async load(e){e=e||this.options.maxHistory;const t=await this._cache.get("_localHeads")||[],r=await this._cache.get("_remoteHeads")||[],n=t.concat(r);n.length>0&&this.events.emit("load",this.address.toString(),n),await s(n,async t=>{this._replicationInfo.max=Math.max(this._replicationInfo.max,t.clock.time);let r=await a.fromEntryHash(this._ipfs,t.hash,this._oplog.id,e,this._oplog.values,this.key,this.access.write,this._onLoadProgress.bind(this));await this._oplog.join(r,e,this._oplog.id),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,this._oplog.length])}),n.length>0&&this._index.updateIndex(this._oplog),this.events.emit("ready",this.address.toString(),this._oplog.heads)}sync(e){if(this._stats.syncRequestsReceieved+=1,d.debug(`Sync request #${this._stats.syncRequestsReceieved} ${e.length}`),0!==e.length)return s(e,e=>{if(!e)return console.warn("Warning: Given input entry was 'null'."),Promise.resolve(null);if(!this.access.write.includes(e.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 r=Object.assign({},e);return r.hash=null,this._ipfs.object.put(t.from(JSON.stringify(r))).then(e=>e.toJSON().multihash).then(t=>(t!==e.hash&&console.warn("\"WARNING! Head hash didn't match the contents"),t)).then(()=>e)}).then(async t=>(await this._cache.set("_remoteHeads",e),d.debug(`Saved heads ${e.length} [${t.map(e=>e.hash).join(", ")}]`),this._loader.load(t.filter(e=>null!==e))))}loadMoreFrom(e,t){this._loader.load(t)}async saveSnapshot(){const e=this._loader.getQueue();let r=this._oplog.toSnapshot(),n=new t(JSON.stringify({id:r.id,heads:r.heads,size:r.values.length,type:this.type}));const i=new o;let s=new Uint16Array([n.length]),a=new t(s.buffer);i.push(a),i.push(n),r.values.forEach(e=>{let r=new t(JSON.stringify(e)),n=new Uint16Array([r.length]);i.push(new t(n.buffer)),i.push(r)}),i.push(null);const c={path:this.address.toString(),content:i},f=await this._ipfs.files.add(c);return await this._cache.set("snapshot",f[f.length-1]),await this._cache.set("queue",e),d.debug(`Saved snapshot: ${f[f.length-1].hash}, queue length: ${e.length}`),f}async loadFromSnapshot(e){this.events.emit("load",this.address.toString());const r=await this._cache.get("queue");this.sync(r||[]);const n=await this._cache.get("snapshot");if(!n)throw new Error(`Snapshot for ${this.address} not found!`);{const e=await this._ipfs.files.catReadableStream(n.hash),r=(e,t,r,n)=>{this._replicationInfo.max=Math.max(this._replicationInfo.max,t.clock.time),this._replicationInfo.progress=Math.max.apply(null,[this._replicationInfo.progress,r,this._oplog.length]),this._onLoadProgress(e,t,this._replicationInfo.progress,this._replicationInfo.max)},i=await(()=>new Promise((r,n)=>{let i=new t(0),o=[];e.on("data",e=>{if(this._byteSize+=e.length,o.length<2e4)o.push(e);else{const e=t.concat(o);i=t.concat([i,e]),o=[]}}),e.on("end",()=>{function e(e){for(var t=new ArrayBuffer(e.length),r=new Uint8Array(t),n=0;n0){const e=t.concat(o);i=t.concat([i,e])}const n=parseInt(new Uint16Array(e(i.slice(0,2))));let s;try{s=JSON.parse(i.slice(2,n+2))}catch(e){}let a=[],c=2+n;for(;cMath.max(e,t.clock.time),0)),r({values:a,id:s.id,heads:s.heads,type:s.type})):(this._replicationInfo.max=0,r({values:a,id:null,heads:null,type:null}))})}))();if(i){const e=await a.fromJSON(this._ipfs,i,-1,this._key,this.access.write,1e3,r);await this._oplog.join(e,-1,this._oplog.id),this._replicationInfo.max=Math.max(this._replicationInfo.max,this._oplog.length),this._replicationInfo.progress=Math.max(this._replicationInfo.progress,this._oplog.length),this._index.updateIndex(this._oplog),this.events.emit("replicated",this.address.toString())}this.events.emit("ready",this.address.toString(),this._oplog.heads)}return this}async _addOperation(e,t,r,n){if(this._oplog){const t=await this._oplog.append(e,this.options.referenceCount);return this._replicationInfo.max=Math.max(this._replicationInfo.max,t.clock.time),this._replicationInfo.progress++,this.address.toString(),await this._cache.set("_localHeads",[t]),this._index.updateIndex(this._oplog),this.events.emit("write",this.address.toString(),t,this._oplog.heads),n&&n(t),t.hash}}_addOperationBatch(e,t,r,n){throw new Error("Not implemented!")}_onLoadProgress(e,t,r,n){this.events.emit("load.progress",this.address.toString(),e,t,Math.max(this._oplog.length,r),Math.max(this._oplog.length||0,this._replicationInfo.max||0))}}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";(function(t){function r(e,r,n,i){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var o,s,a=arguments.length;switch(a){case 0:case 1:return t.nextTick(e);case 2:return t.nextTick(function(){e.call(null,r)});case 3:return t.nextTick(function(){e.call(null,r,n)});case 4:return t.nextTick(function(){e.call(null,r,n,i)});default:for(o=new Array(a-1),s=0;snew Promise((n,i)=>{if(r=Object.assign({concurrency:1/0},r),"function"!=typeof t)throw new TypeError("Mapper function is required");const o=r.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=e[Symbol.iterator]();let c=!1,f=!1,u=0,h=0;const d=()=>{if(c)return;const e=a.next(),r=h;if(h++,e.done)return f=!0,void(0===u&&n(s));u++,Promise.resolve(e.value).then(e=>t(e,r)).then(e=>{s[r]=e,u--,d()},e=>{c=!0,i(e)})};for(let e=0;e{c=e},setLogfile:e=>{f=e},create:(e,r)=>{return new class{constructor(e,t){this.category=e;let r={};Object.assign(r,l),Object.assign(r,t),this.options=r}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(e,t){(this.options.filename||f)&&!this.fileWriter&&s&&(this.fileWriter=n.openSync(this.options.filename||f,this.options.appendFile?"a+":"w+"));let r=this._format(e,t),i=this._createLogMessage(e,t),o=this._createLogMessage(e,t,r.timestamp,r.level,r.category,r.text);this.fileWriter&&s&&n.writeSync(this.fileWriter,i+"\n",null,"utf-8"),s||!this.options.useColors?(console.log(o),u.emit("data",this.category,e,t)):e===a.ERROR?this.options.showTimestamp&&this.options.showLevel?console.error(o,r.timestamp,r.level,r.category,r.text):this.options.showTimestamp&&!this.options.showLevel?console.error(o,r.timestamp,r.category,r.text):!this.options.showTimestamp&&this.options.showLevel?console.error(o,r.level,r.category,r.text):console.error(o,r.category,r.text):this.options.showTimestamp&&this.options.showLevel?console.log(o,r.timestamp,r.level,r.category,r.text):this.options.showTimestamp&&!this.options.showLevel?console.log(o,r.timestamp,r.category,r.text):!this.options.showTimestamp&&this.options.showLevel?console.log(o,r.level,r.category,r.text):console.log(o,r.category,r.text)}_format(e,t){let r="",n="",i="",o=": ";if(this.options.useColors){const t=Object.keys(a).map(e=>a[e]).indexOf(e),c=this.options.color;s?(this.options.showTimestamp&&(r="[3"+h.Grey+"m"),this.options.showLevel&&(n="[3"+d[t]+";22m"),i="[3"+c+";1m",o=": "):(this.options.showTimestamp&&(r="color:"+h.Grey),this.options.showLevel&&(n="color:"+d[t]),i="color:"+c+"; font-weight: bold")}return{timestamp:r,level:n,category:i,text:o}}_createLogMessage(e,t,r,n,i,o){r=r||"",n=n||"",i=i||"",o=o||": ",!s&&this.options.useColors&&(this.options.showTimestamp&&(r="%c"),this.options.showLevel&&(n="%c"),i="%c",o=": %c");let c="";return this.options.showTimestamp&&(c+=(new Date).toISOString()+" "),c=r+c,this.options.showLevel&&(c+=n+"["+e+"]"+(e===a.INFO||e===a.WARN?" ":"")+" "),c+=i+this.category,c+=o+t}_shouldLog(e){let r=void 0!==t&&void 0!==Object({NODE_ENV:void 0})&&void 0!==Object({NODE_ENV:void 0}).LOG?Object({NODE_ENV:void 0}).LOG.toUpperCase():null;const n=(r="undefined"!=typeof window&&window.LOG?window.LOG.toUpperCase():r)||c,i=Object.keys(a).map(e=>a[e]);return i.indexOf(e)>=i.indexOf(n)}}(e,r)},forceBrowserMode:e=>s=!e,events:u}}).call(t,r(0))},function(e,t,r){"use strict";(function(t,n,i){function o(e){var t=this;this.next=null,this.entry=null,this.finish=function(){!function(e,t,r){var n=e.entry;e.entry=null;for(;n;){var i=n.callback;t.pendingcb--,i(r),n=n.next}t.corkedRequestsFree?t.corkedRequestsFree.next=e:t.corkedRequestsFree=e}(t,e)}}function s(){}function a(e,t){g=g||r(10),e=e||{},this.objectMode=!!e.objectMode,t instanceof g&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var n=e.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=n||0===n?n:i,this.highWaterMark=Math.floor(this.highWaterMark),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var s=!1===e.decodeStrings;this.decodeStrings=!s,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){!function(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if(function(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}(r),t)!function(e,t,r,n,i){--t.pendingcb,r?(y(i,n),y(b,e,t),e._writableState.errorEmitted=!0,e.emit("error",n)):(i(n),e._writableState.errorEmitted=!0,e.emit("error",n),b(e,t))}(e,r,n,t,i);else{var o=l(r);o||r.corked||r.bufferProcessing||!r.bufferedRequest||d(e,r),n?m(h,e,r,o,i):h(e,r,o,i)}}(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new o(this)}function c(e){if(g=g||r(10),!(x.call(c,this)||this instanceof g))return new c(e);this._writableState=new a(e,this),this.writable=!0,e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final)),w.call(this)}function f(e,t,r,n,i,o){if(!r){var s=function(e,t,r){return e.objectMode||!1===e.decodeStrings||"string"!=typeof t||(t=S.from(t,r)),t}(t,n,i);n!==s&&(r=!0,i="buffer",n=s)}var a=t.objectMode?1:n.length;t.length+=a;var c=t.length-1?n:y;c.WritableState=a;var v=r(15);v.inherits=r(4);var _={deprecate:r(75)},w=r(38),S=r(9).Buffer,k=i.Uint8Array||function(){},E=r(39);v.inherits(c,w),a.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(a.prototype,"buffer",{get:_.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}();var x;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(x=Function.prototype[Symbol.hasInstance],Object.defineProperty(c,Symbol.hasInstance,{value:function(e){return!!x.call(this,e)||e&&e._writableState instanceof a}})):x=function(e){return e instanceof this},c.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},c.prototype.write=function(e,t,r){var n=this._writableState,i=!1,o=function(e){return S.isBuffer(e)||e instanceof k}(e)&&!n.objectMode;return o&&!S.isBuffer(e)&&(e=function(e){return S.from(e)}(e)),"function"==typeof t&&(r=t,t=null),o?t="buffer":t||(t=n.defaultEncoding),"function"!=typeof r&&(r=s),n.ended?function(e,t){var r=new Error("write after end");e.emit("error",r),y(t,r)}(this,r):(o||function(e,t,r,n){var i=!0,o=!1;return null===r?o=new TypeError("May not write null values to stream"):"string"==typeof r||void 0===r||t.objectMode||(o=new TypeError("Invalid non-string/buffer chunk")),o&&(e.emit("error",o),y(n,o),i=!1),i}(this,n,e,r))&&(n.pendingcb++,i=f(this,n,o,e,t,r)),i},c.prototype.cork=function(){this._writableState.corked++},c.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||d(this,e))},c.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},c.prototype._write=function(e,t,r){r(new Error("_write() is not implemented"))},c.prototype._writev=null,c.prototype.end=function(e,t,r){var n=this._writableState;"function"==typeof e?(r=e,e=null,t=null):"function"==typeof t&&(r=t,t=null),null!==e&&void 0!==e&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),n.ending||n.finished||function(e,t,r){t.ending=!0,b(e,t),r&&(t.finished?y(r):e.once("finish",r)),t.ended=!0,e.writable=!1}(this,n,r)},Object.defineProperty(c.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),c.prototype.destroy=E.destroy,c.prototype._undestroy=E.undestroy,c.prototype._destroy=function(e,t){this.end(),t(e)}}).call(t,r(0),r(40).setImmediate,r(7))},function(e,t,r){"use strict";(function(t){const n=r(27),i=r(28),o=()=>new Error("Ipfs instance not defined");class s{static async create(e,t,r,a=[],c,f){if(!i(e))throw o();if(!i(t))throw new Error("Entry requires an id");if(!i(r))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:t,payload:r,next:a.filter(i).map(e=>e.hash?e.hash:e),v:0,clock:new n(t,c?c.time:null)};return e.keystore&&f&&(u=await s.signEntry(e.keystore,u,f)),u.hash=await s.toMultihash(e,u),u}static async signEntry(e,r,n){const i=await e.sign(n,new t(JSON.stringify(r)));return r.sig=i,r.key=n.getPublic("hex"),r}static async verifyEntry(e,r){const n=Object.assign({},{hash:null,id:e.id,payload:e.payload,next:e.next,v:e.v,clock:e.clock}),i=await r.importPublicKey(e.key);await r.verify(e.sig,i,new t(JSON.stringify(n)))}static toMultihash(e,r){if(!e)throw o();const n=t.from(JSON.stringify(r));return e.object.put(n).then(e=>e.toJSON().multihash)}static fromMultihash(e,t){if(!e)throw o();if(!t)throw new Error(`Invalid hash: ${t}`);return e.object.get(t,{enc:"base58"}).then(e=>JSON.parse(e.toJSON().data)).then(e=>{let r={hash:t,id:e.id,payload:e.payload,next:e.next,v:e.v,clock:e.clock};return e.sig&&Object.assign(r,{sig:e.sig}),e.key&&Object.assign(r,{key:e.key}),r})}static isEntry(e){return void 0!==e.id&&void 0!==e.next&&void 0!==e.hash&&void 0!==e.payload&&void 0!==e.v&&void 0!==e.clock}static compare(e,t){var r=n.compare(e.clock,t.clock);return 0===r?e.clock.id-1}static findChildren(e,t){for(var r=[],n=t.find(t=>s.isParent(e,t)),i=e;n;)r.push(n),i=n,n=t.find(e=>s.isParent(i,e));return r=r.sort((e,t)=>e.clock.time>e.clock.time)}}e.exports=s}).call(t,r(1).Buffer)},function(e,t,r){"use strict";class n{constructor(e,t){this.id=e,this.time=t||0}tick(){return new n(this.id,++this.time)}merge(e){return this.time=Math.max(this.time,e.time),new n(this.id,this.time)}clone(){return new n(this.id,this.time)}static compare(e,t){var r=e.time-t.time;return 0===r&&e.id!==t.id?e.idvoid 0!==e&&null!==e)},function(e,t,r){var n=t;n.utils=r(5),n.common=r(16),n.sha=r(95),n.ripemd=r(99),n.hmac=r(100),n.sha1=n.sha.sha1,n.sha256=n.sha.sha256,n.sha224=n.sha.sha224,n.sha384=n.sha.sha384,n.sha512=n.sha.sha512,n.ripemd160=n.ripemd.ripemd160},function(e,t,r){"use strict";var n=r(59);e.exports=function(e,t){if(!e)return function(e,r){return e?n(r,e,t):r(!0)};Array.isArray(e)||(e=Object.keys(e).map(function(t){return e[t]}));var r=0;return function(i,o){if(i)return n(o,i,t);r>=e.length?o(!0):o(null,e[r++])}}},function(e,t,r){"use strict";var n=r(17);e.exports=function(e,t,r){r||(r=t,t=null);var i=n(function(r){t=e(t,r)},function(e){r(e,t)});return 2===arguments.length?function(e){e(null,function(n,o){if(n)return r(!0===n?null:n);t=o,i(e)})}:i}},function(e,t,r){"use strict";var n=r(61);e.exports=function(e){return e=n(e),function(t){return function r(n,i){for(var o,s=!0;s;)s=!1,o=!0,t(n,function(t,n){if(!t&&!e(n))return o?s=!0:r(t,i);i(t,n)}),o=!1}}}},function(e,t){e.exports=function(){for(var e={},t=0;tt}}_query(e){e||(e={});const t=e.limit?e.limit>-1?e.limit:this._index.get().length:1,r=this._index.get().slice();let n=[];return n=e.gt||e.gte?this._read(r,e.gt?e.gt:e.gte,t,!!e.gte):this._read(r.reverse(),e.lt?e.lt:e.lte,t,e.lte||!e.lt).reverse()}_read(e,t,r,n){const i=e.map(e=>e.hash).indexOf(t);let o=Math.max(i,0);return o+=n?0:1,e.slice(o).slice(0,r)}}},function(e,t){var r={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==r.call(e)}},function(e,t,r){"use strict";(function(t,n){function i(e,t){w=w||r(10),e=e||{},this.objectMode=!!e.objectMode,t instanceof w&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var n=e.highWaterMark,i=this.objectMode?16:16384;this.highWaterMark=n||0===n?n:i,this.highWaterMark=Math.floor(this.highWaterMark),this.buffer=new R,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=e.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(N||(N=r(41).StringDecoder),this.decoder=new N(e.encoding),this.encoding=e.encoding)}function o(e){if(w=w||r(10),!(this instanceof o))return new o(e);this._readableState=new i(e,this),this.readable=!0,e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy)),E.call(this)}function s(e,t,r,n,i){var o=e._readableState;if(null===t)o.reading=!1,function(e,t){if(t.ended)return;if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,f(e)}(e,o);else{var s;i||(s=function(e,t){var r;(function(e){return x.isBuffer(e)||e instanceof M})(t)||"string"==typeof t||void 0===t||e.objectMode||(r=new TypeError("Invalid non-string/buffer chunk"));return r}(o,t)),s?e.emit("error",s):o.objectMode||t&&t.length>0?("string"==typeof t||o.objectMode||Object.getPrototypeOf(t)===x.prototype||(t=function(e){return x.from(e)}(t)),n?o.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):a(e,o,t,!0):o.ended?e.emit("error",new Error("stream.push() after EOF")):(o.reading=!1,o.decoder&&!r?(t=o.decoder.write(t),o.objectMode||0!==t.length?a(e,o,t,!1):h(e,o)):a(e,o,t,!1))):n||(o.reading=!1)}return function(e){return!e.ended&&(e.needReadable||e.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=j?e=j:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function f(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(I("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?_(u,e):u(e))}function u(e){I("emit readable"),e.emit("readable"),b(e)}function h(e,t){t.readingMore||(t.readingMore=!0,_(d,e,t))}function d(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):r=function(e,t,r){var n;eo.length?o.length:e;if(s===o.length?i+=o:i+=o.slice(0,e),0===(e-=s)){s===o.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=o.slice(s));break}++n}return t.length-=n,i}(e,t):function(e,t){var r=x.allocUnsafe(e),n=t.head,i=1;n.data.copy(r),e-=n.data.length;for(;n=n.next;){var o=n.data,s=e>o.length?o.length:e;if(o.copy(r,r.length-e,0,s),0===(e-=s)){s===o.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(s));break}++i}return t.length-=i,r}(e,t);return n}(e,t.buffer,t.decoder),r}function g(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,_(m,t,e))}function m(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function v(e,t){for(var r=0,n=e.length;r=t.highWaterMark||t.ended))return I("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?g(this):f(this),null;if(0===(e=c(e,t))&&t.ended)return 0===t.length&&g(this),null;var n=t.needReadable;I("need readable",n),(0===t.length||t.length-e0?y(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&g(this)),null!==i&&this.emit("data",i),i},o.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},o.prototype.pipe=function(e,t){function r(t,n){I("onunpipe"),t===u&&n&&!1===n.hasUnpiped&&(n.hasUnpiped=!0,I("cleanup"),e.removeListener("close",a),e.removeListener("finish",c),e.removeListener("drain",l),e.removeListener("error",s),e.removeListener("unpipe",r),u.removeListener("end",i),u.removeListener("end",f),u.removeListener("data",o),p=!0,!h.awaitDrain||e._writableState&&!e._writableState.needDrain||l())}function i(){I("onend"),e.end()}function o(t){I("ondata"),y=!1;!1!==e.write(t)||y||((1===h.pipesCount&&h.pipes===e||h.pipesCount>1&&-1!==v(h.pipes,e))&&!p&&(I("false write response, pause",u._readableState.awaitDrain),u._readableState.awaitDrain++,y=!0),u.pause())}function s(t){I("onerror",t),f(),e.removeListener("error",s),0===k(e,"error")&&e.emit("error",t)}function a(){e.removeListener("finish",c),f()}function c(){I("onfinish"),e.removeListener("close",a),f()}function f(){I("unpipe"),u.unpipe(e)}var u=this,h=this._readableState;switch(h.pipesCount){case 0:h.pipes=e;break;case 1:h.pipes=[h.pipes,e];break;default:h.pipes.push(e)}h.pipesCount+=1,I("pipe count=%d opts=%j",h.pipesCount,t);var d=(!t||!1!==t.end)&&e!==n.stdout&&e!==n.stderr?i:f;h.endEmitted?_(d):u.once("end",d),e.on("unpipe",r);var l=function(e){return function(){var t=e._readableState;I("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&k(e,"data")&&(t.flowing=!0,b(e))}}(u);e.on("drain",l);var p=!1,y=!1;return u.on("data",o),function(e,t,r){if("function"==typeof e.prependListener)return e.prependListener(t,r);e._events&&e._events[t]?S(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]:e.on(t,r)}(e,"error",s),e.once("close",a),e.once("finish",c),e.emit("pipe",u),h.flowing||(I("pipe resume"),u.resume()),e},o.prototype.unpipe=function(e){var t=this._readableState,r={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,r),this);if(!e){var n=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},r(74),t.setImmediate=setImmediate,t.clearImmediate=clearImmediate},function(e,t,r){"use strict";function n(e){this.encoding=function(e){var t=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof t&&(d.isEncoding===l||!l(e)))throw new Error("Unknown encoding: "+e);return t||e}(e);var t;switch(this.encoding){case"utf16le":this.text=s,this.end=a,t=4;break;case"utf8":this.fillLast=o,t=4;break;case"base64":this.text=c,this.end=f,t=3;break;default:return this.write=u,void(this.end=h)}this.lastNeed=0,this.lastTotal=0,this.lastChar=d.allocUnsafe(t)}function i(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:-1}function o(e){var t=this.lastTotal-this.lastNeed,r=function(e,t,r){if(128!=(192&t[0]))return e.lastNeed=0,"�".repeat(r);if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�".repeat(r+1);if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�".repeat(r+2)}}(this,e,t);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function s(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function a(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function c(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function f(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function u(e){return e.toString(this.encoding)}function h(e){return e&&e.length?this.write(e):""}var d=r(9).Buffer,l=d.isEncoding||function(e){switch((e=""+e)&&e.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}};t.StringDecoder=n,n.prototype.write=function(e){if(0===e.length)return"";var t,r;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r=0?(o>0&&(e.lastNeed=o-1),o):--n=0?(o>0&&(e.lastNeed=o-2),o):--n=0?(o>0&&(2===o?o=0:e.lastNeed=o-3),o):0}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)},n.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}},function(e,t,r){"use strict";function n(e){this.afterTransform=function(t,r){return function(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("write callback called multiple times"));n.writechunk=null,n.writecb=null,null!==r&&void 0!==r&&e.push(r);i(t);var o=e._readableState;o.reading=!1,(o.needReadable||o.length(new Date).getTime().toString(),d=e=>e.hash,l=(e,t)=>e.concat(t),p=e=>e.next,b=(e,t)=>Math.max(e,t.clock.time),y=(e,t)=>(e[t.hash]=t,e);class g extends i{constructor(e,t,r,n,i,o,s=[]){if(!f(e))throw a.ImmutableDBNotDefinedError();if(f(r)&&!Array.isArray(r))throw new Error("'entries' argument must be an array of Entry instances");if(f(n)&&!Array.isArray(n))throw new Error("'heads' argument must be an array");super(),this._storage=e,this._id=t||h(),this._keystore=this._storage.keystore,this._key=o,this._keys=Array.isArray(s)?s:[s],r=r||[],this._entryIndex=r.reduce(y,{}),n=n||g.findHeads(r),this._headsIndex=n.reduce(y,{}),this._nextsIndex={},r.forEach(e=>e.next.forEach(t=>this._nextsIndex[t]=e.hash)),this._length=r?r.length:0;const u=Math.max(i?i.time:0,this.heads.reduce(b,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 g.findTails(this.values)}get tailHashes(){return g.findTailHashes(this.values)}get(e){return this._entryIndex[e]}has(e){return void 0!==this._entryIndex[e.hash||e]}traverse(e,t){let r=e.map(p).reduce(l,[]),n={},i={},o=0;const s=e=>{i[e]||n[e]||(r.push(e),n[e]=!0)};for(e.forEach(e=>{i[e.hash]=e.hash,n[e.hash]=!0,o++});r.length>0&&othis._nextsIndex[e]=i.hash),this._headsIndex={},this._headsIndex[i.hash]=i,this._length++,i}async join(e,t=-1,r){if(!f(e))throw a.LogNotDefinedError();if(!g.isLog(e))throw a.NotALogError();const i=async e=>{this._keys.map(e=>e.getPublic?e.getPublic("hex"):e);return(await n(e,async e=>{if(!e.key)throw new Error("Entry doesn't have a public key");if(!e.sig)throw new Error("Entry doesn't have a signature");if(1===this._keys.length&&this._keys[0]===this._key&&e.id!==this.id)throw new Error("Entry doesn't belong in this log (wrong ID)");if(this._keys.length>0&&!this._keys.includes("*")&&!((e,t)=>e.find(e=>e===t.key))(this._keys.concat([this._key]),e))return console.warn("Warning: Input log contains entries that are not allowed in this log. Logs weren't joined."),!1;try{await o.verifyEntry(e,this._keystore)}catch(t){return console.log(t),console.log("Couldn't verify entry:\n",e),!1}return!0})).every(e=>!0===e)};r=r||[e,this].sort((e,t)=>e.id>t.id)[0].id;const s=((e,t)=>{let r=Object.keys(e._headsIndex),n={},i={};const o=e=>{n[e]||t.get(e)||(r.push(e),n[e]=!0)};for(;r.length>0;){const s=r.shift(),a=e.get(s);a&&!t.get(s)&&(i[a.hash]=a,n[a.hash]=!0,a.next.forEach(o))}return i})(e,this);if(this._key){if(!await i(Object.values(s)))return this}this._entryIndex=Object.assign(this._entryIndex,s);if(Object.values(s).forEach(e=>e.next.forEach(t=>this._nextsIndex[t]=e.hash)),this._length+=Object.values(s).length,t>-1){let e=this.values;e=e.slice(-t),this._entryIndex=e.reduce(y,{}),this._length=Object.values(this._entryIndex).length}const u=Object.values(s).map(p).reduce(l,[]),h=g.findHeads(Object.values(Object.assign({},this._headsIndex,e._headsIndex))).filter(e=>!u.find(t=>t===e.hash)).filter(e=>!this._nextsIndex[e.hash]).reduce(y,{});this._headsIndex=h;const d=Object.values(this._headsIndex).reduce(b,0),m=new c(this.id,Math.max(this.clock.time,d));return this._id=r,this._clock=m,this}toJSON(){return{id:this.id,heads:this.heads.map(d)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return t.from(JSON.stringify(this.toJSON()))}toString(e){return this.values.slice().reverse().map((t,r)=>{const n=o.findChildren(t,this.values).length;let i=new Array(Math.max(n-1,0));return i=n>1?i.fill(" "):i,(i=n>0?i.concat(["└─"]):i).join("")+(e?e(t.payload):t.payload)}).join("\n")}static isLog(e){return void 0!==e.id&&void 0!==e.heads&&void 0!==e._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static fromMultihash(e,t,r=-1,n,i,o){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw new Error(`Invalid hash: ${t}`);return s.fromMultihash(e,t,r,n,o).then(t=>new g(e,t.id,t.values,t.heads,t.clock,i))}static fromEntryHash(e,t,r,n=-1,i,o,c,u){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw new Error("'hash' must be defined");return s.fromEntryHash(e,t,r,n,i,u).then(t=>new g(e,r,t.values,null,null,o,c))}static fromJSON(e,t,r=-1,n,i,o,c){if(!f(e))throw a.ImmutableDBNotDefinedError();return s.fromJSON(e,t,r,n,o,c).then(t=>new g(e,t.id,t.values,null,null,n,i))}static fromEntry(e,t,r=-1,n,i){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw new Error("'sourceEntries' must be defined");return s.fromEntry(e,t,r,n,i).then(t=>new g(e,t.id,t.values))}static expandFrom(e,t,r,n=-1){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw a.LogNotDefinedError();if(!f(r))throw new Error("'entries' must be given as argument");if(!g.isLog(t))throw a.NotALogError();return s.expandFrom(e,t,r,n).then(r=>new g(e,t.id,r.values,null,t.clock))}static expand(e,t,r){if(!f(e))throw a.ImmutableDBNotDefinedError();if(!f(t))throw a.LogNotDefinedError();if(!g.isLog(t))throw a.NotALogError();return s.expand(e,t,r).then(r=>new g(e,t.id,r.values,t.heads,t.clock))}static findHeads(e){var t=e.reduce((e,t,r,n)=>{return t.next.forEach(r=>e[r]=t.hash),e},{});return e.filter(e=>void 0===t[e.hash]).sort((e,t)=>e.id>t.id)}static findTails(e){var t={},r=[],n={},i=[];e.forEach(e=>{0===e.next.length&&r.push(e);e.next.forEach(r=>{t[r]||(t[r]=[]),t[r].push(e)}),i=i.concat(e.next),n[e.hash]=!0});const s=i.filter(e=>void 0===n[e]).map(e=>t[e]).reduce((e,t,r,n)=>e.concat(u(t,"hash")),[]).concat(r);return u(s,"hash").sort(o.compare)}static findTailHashes(e){var t={};return e.forEach(e=>t[e.hash]=!0),e.reduce((e,r,n,i)=>{return r.next.reverse().forEach(r=>{void 0===t[r]&&e.splice(0,0,r)}),e},[])}}e.exports=g}).call(t,r(1).Buffer)},function(e,t,r){"use strict";e.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(e,t,r){"use strict";e.exports=function(e,t){let r={};return e.forEach(e=>r[t?e[t]:e]=e),Object.keys(r).map(e=>r[e])}},function(e,t,r){"use strict";(function(t){const n=r(14),i=new(0,r(2).ec)("secp256k1");e.exports=class{constructor(e="./keystore"){if("undefined"==typeof localStorage||null===localStorage){n.sync(e);const t=r(109).LocalStorage;this._storage=new t(e)}else this._storage=localStorage}createKey(e){const t=i.genKeyPair(),r=t.getPublic("hex"),n=t.getPrivate("hex");return this._storage.setItem(e,JSON.stringify({publicKey:r,privateKey:n})),t}getKey(e){let t=JSON.parse(this._storage.getItem(e));if(t)return i.keyPair({pub:t.publicKey,priv:t.privateKey,privEnc:"hex",pubEnc:"hex"})}static importKeyFromIpfs(e,t){return e.object.get(t,{enc:"base58"}).then(e=>JSON.parse(e.toJSON().Data)).then(e=>OrbitCrypto.importPublicKey(e))}static exportPublicKeyToIpfs(e,r){return r.getPublic("hex"),OrbitCrypto.exportPublicKey(r).then(e=>JSON.stringify(e,null,2)).then(e=>new t(e)).then(t=>e.object.put(t)).then(e=>e.toJSON().multihash)}static getKey(e){let t,r,n,o=JSON.parse(keystore.getItem(e));return o?OrbitCrypto.importPrivateKey(o.privateKey).then(e=>n=e).then(()=>OrbitCrypto.importPublicKey(o.publicKey)).then(e=>r=e).then(()=>i.keyPair({pub:r,priv:n})):OrbitCrypto.generateKey().then(e=>t=e).then(()=>OrbitCrypto.exportPrivateKey(t)).then(e=>n=e).then(()=>OrbitCrypto.exportPublicKey(t)).then(e=>r=e).then(()=>(keystore.setItem(e,JSON.stringify({publicKey:r,privateKey:n})),i.keyPair({pub:r,priv:n})))}generateKey(){return Promise.resolve(i.genKeyPair())}exportPublicKey(e){return Promise.resolve(e.getPublic("hex"))}exportPrivateKey(e){return Promise.resolve(e.getPrivate("hex"))}importPublicKey(e){return Promise.resolve(i.keyFromPublic(e,"hex"))}importPrivateKey(e){return Promise.resolve(i.keyFromPrivate(e,"hex"))}sign(e,t){const r=i.sign(t,e);return Promise.resolve(r.toDER("hex"))}verify(e,t,r){let n=!1;return n=i.verify(r,e,t),Promise.resolve(n)}}}).call(t,r(1).Buffer)},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,r){"use strict";function n(e){return 1===e.length?"0"+e:e}function i(e){for(var t="",r=0;r>8,s=255&i;o?r.push(o,s):r.push(s)}return r},o.zero2=n,o.toHex=i,o.encode=function(e,t){return"hex"===t?i(e):e}},function(e,t,r){"use strict";function n(e,t,r){return e&t^~e&r}function i(e,t,r){return e&t^e&r^t&r}function o(e,t,r){return e^t^r}var s=r(5).rotr32;t.ft_1=function(e,t,r,s){return 0===e?n(t,r,s):1===e||3===e?o(t,r,s):2===e?i(t,r,s):void 0},t.ch32=n,t.maj32=i,t.p32=o,t.s0_256=function(e){return s(e,2)^s(e,13)^s(e,22)},t.s1_256=function(e){return s(e,6)^s(e,11)^s(e,25)},t.g0_256=function(e){return s(e,7)^s(e,18)^e>>>3},t.g1_256=function(e){return s(e,17)^s(e,19)^e>>>10}},function(e,t,r){"use strict";function n(){if(!(this instanceof n))return new n;g.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=m,this.W=new Array(64)}var i=r(5),o=r(16),s=r(49),a=r(11),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(n,g),e.exports=n,n.blockSize=512,n.outSize=256,n.hmacStrength=192,n.padLength=64,n.prototype._update=function(e,t){for(var r=this.W,n=0;n<16;n++)r[n]=e[t+n];for(;n=0;a--)if(c[a]!==f[a])return!1;for(a=c.length-1;a>=0;a--)if(s=c[a],!d(e[s],t[s],r,n))return!1;return!0}(e,t,r,a))}return r?e===t:e==t}function l(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function p(e,t,r){d(e,t,!0)&&u(e,t,r,"notDeepStrictEqual",p)}function b(e,t){if(!e||!t)return!1;if("[object RegExp]"==Object.prototype.toString.call(t))return t.test(e);try{if(e instanceof t)return!0}catch(e){}return!Error.isPrototypeOf(t)&&!0===t.call({},e)}function y(e,t,r,n){var i;if("function"!=typeof t)throw new TypeError('"block" argument must be a function');"string"==typeof r&&(n=r,r=null),i=function(e){var t;try{e()}catch(e){t=e}return t}(t),n=(r&&r.name?" ("+r.name+").":".")+(n?" "+n:"."),e&&!i&&u(i,r,"Missing expected exception"+n);var o="string"==typeof n,s=!e&&g.isError(i),a=!e&&i&&!r;if((s&&o&&b(i,r)||a)&&u(i,r,"Got unwanted exception"+n),e&&i&&r&&!b(i,r)||!e&&i)throw i}var g=r(6),m=Object.prototype.hasOwnProperty,v=Array.prototype.slice,_="foo"===function(){}.name,w=e.exports=h,S=/\s*function\s+([^\(\s]*)\s*/;w.AssertionError=function(e){this.name="AssertionError",this.actual=e.actual,this.expected=e.expected,this.operator=e.operator,e.message?(this.message=e.message,this.generatedMessage=!1):(this.message=function(e){return c(f(e.actual),128)+" "+e.operator+" "+c(f(e.expected),128)}(this),this.generatedMessage=!0);var t=e.stackStartFunction||u;if(Error.captureStackTrace)Error.captureStackTrace(this,t);else{var r=new Error;if(r.stack){var n=r.stack,i=a(t),o=n.indexOf("\n"+i);if(o>=0){var s=n.indexOf("\n",o+1);n=n.substring(s+1)}this.stack=n}}},g.inherits(w.AssertionError,Error),w.fail=u,w.ok=h,w.equal=function(e,t,r){e!=t&&u(e,t,r,"==",w.equal)},w.notEqual=function(e,t,r){e==t&&u(e,t,r,"!=",w.notEqual)},w.deepEqual=function(e,t,r){d(e,t,!1)||u(e,t,r,"deepEqual",w.deepEqual)},w.deepStrictEqual=function(e,t,r){d(e,t,!0)||u(e,t,r,"deepStrictEqual",w.deepStrictEqual)},w.notDeepEqual=function(e,t,r){d(e,t,!1)&&u(e,t,r,"notDeepEqual",w.notDeepEqual)},w.notDeepStrictEqual=p,w.strictEqual=function(e,t,r){e!==t&&u(e,t,r,"===",w.strictEqual)},w.notStrictEqual=function(e,t,r){e===t&&u(e,t,r,"!==",w.notStrictEqual)},w.throws=function(e,t,r){y(!0,e,t,r)},w.doesNotThrow=function(e,t,r){y(!1,e,t,r)},w.ifError=function(e){if(e)throw e};var k=Object.keys||function(e){var t=[];for(var r in e)m.call(e,r)&&t.push(r);return t}}).call(t,r(7))},function(e,t){e.exports=function(){var e,t=Array.prototype.slice.call(arguments),r=null;return"object"==typeof t[0]?(r=t.shift(),"string"==typeof(e=t.shift())&&(e=r[e])):e=t.shift(),function(n){e.apply(r,t.concat(n))}}},function(e,t,r){"use strict";const{deepEqual:n}=r(135),i=(e,t)=>e+t;class o{constructor(e,t){this.id=e,this._counters=t||{},this._counters[this.id]=this._counters[this.id]?this._counters[this.id]:0}get value(){return Object.values(this._counters).reduce(i,0)}increment(e){e&&e<1||(void 0!==e&&null!==e||(e=1),this._counters[this.id]=this._counters[this.id]+e)}merge(e){Object.entries(e._counters).forEach(([e,t])=>{this._counters[e]=Math.max(this._counters[e]||0,t)})}toJSON(){return{id:this.id,counters:this._counters}}isEqual(e){return o.isEqual(this,e)}static from(e){return new o(e.id,e.counters)}static isEqual(e,t){return e.id===t.id&&n(e._counters,t._counters)}}e.exports=o},function(e,t,r){(function(e,r){function n(e,t){return e.set(t[0],t[1]),e}function i(e,t){return e.add(t),e}function o(e,t,r,n){var i=-1,o=e?e.length:0;for(n&&o&&(r=e[++i]);++i-1&&e%1==0&&e-1&&e%1==0&&e<=P}(e.length)&&!O(e)}function O(e){var t=A(e)?we.call(e):"";return t==L||t==B}function A(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function I(e){return M(e)?p(e):function(e){if(!k(e))return Pe(e);var t=[];for(var r in Object(e))_e.call(e,r)&&"constructor"!=r&&t.push(r);return t}(e)}var N=200,R="__lodash_hash_undefined__",P=9007199254740991,C="[object Arguments]",j="[object Boolean]",T="[object Date]",L="[object Function]",B="[object GeneratorFunction]",D="[object Map]",q="[object Number]",F="[object Object]",z="[object Promise]",U="[object RegExp]",K="[object Set]",G="[object String]",H="[object Symbol]",W="[object WeakMap]",Y="[object ArrayBuffer]",V="[object DataView]",J="[object Float32Array]",$="[object Float64Array]",X="[object Int8Array]",Z="[object Int16Array]",Q="[object Int32Array]",ee="[object Uint8Array]",te="[object Uint8ClampedArray]",re="[object Uint16Array]",ne="[object Uint32Array]",ie=/\w*$/,oe=/^\[object .+?Constructor\]$/,se=/^(?:0|[1-9]\d*)$/,ae={};ae[C]=ae["[object Array]"]=ae[Y]=ae[V]=ae[j]=ae[T]=ae[J]=ae[$]=ae[X]=ae[Z]=ae[Q]=ae[D]=ae[q]=ae[F]=ae[U]=ae[K]=ae[G]=ae[H]=ae[ee]=ae[te]=ae[re]=ae[ne]=!0,ae["[object Error]"]=ae[L]=ae[W]=!1;var ce="object"==typeof e&&e&&e.Object===Object&&e,fe="object"==typeof self&&self&&self.Object===Object&&self,ue=ce||fe||Function("return this")(),he="object"==typeof t&&t&&!t.nodeType&&t,de=he&&"object"==typeof r&&r&&!r.nodeType&&r,le=de&&de.exports===he,pe=Array.prototype,be=Function.prototype,ye=Object.prototype,ge=ue["__core-js_shared__"],me=function(){var e=/[^.]+$/.exec(ge&&ge.keys&&ge.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ve=be.toString,_e=ye.hasOwnProperty,we=ye.toString,Se=RegExp("^"+ve.call(_e).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ke=le?ue.Buffer:void 0,Ee=ue.Symbol,xe=ue.Uint8Array,Me=c(Object.getPrototypeOf,Object),Oe=Object.create,Ae=ye.propertyIsEnumerable,Ie=pe.splice,Ne=Object.getOwnPropertySymbols,Re=ke?ke.isBuffer:void 0,Pe=c(Object.keys,Object),Ce=S(ue,"DataView"),je=S(ue,"Map"),Te=S(ue,"Promise"),Le=S(ue,"Set"),Be=S(ue,"WeakMap"),De=S(Object,"create"),qe=E(Ce),Fe=E(je),ze=E(Te),Ue=E(Le),Ke=E(Be),Ge=Ee?Ee.prototype:void 0,He=Ge?Ge.valueOf:void 0;u.prototype.clear=function(){this.__data__=De?De(null):{}},u.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},u.prototype.get=function(e){var t=this.__data__;if(De){var r=t[e];return r===R?void 0:r}return _e.call(t,e)?t[e]:void 0},u.prototype.has=function(e){var t=this.__data__;return De?void 0!==t[e]:_e.call(t,e)},u.prototype.set=function(e,t){return this.__data__[e]=De&&void 0===t?R:t,this},h.prototype.clear=function(){this.__data__=[]},h.prototype.delete=function(e){var t=this.__data__,r=y(t,e);return!(r<0||(r==t.length-1?t.pop():Ie.call(t,r,1),0))},h.prototype.get=function(e){var t=this.__data__,r=y(t,e);return r<0?void 0:t[r][1]},h.prototype.has=function(e){return y(this.__data__,e)>-1},h.prototype.set=function(e,t){var r=this.__data__,n=y(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},d.prototype.clear=function(){this.__data__={hash:new u,map:new(je||h),string:new u}},d.prototype.delete=function(e){return w(this,e).delete(e)},d.prototype.get=function(e){return w(this,e).get(e)},d.prototype.has=function(e){return w(this,e).has(e)},d.prototype.set=function(e,t){return w(this,e).set(e,t),this},l.prototype.clear=function(){this.__data__=new h},l.prototype.delete=function(e){return this.__data__.delete(e)},l.prototype.get=function(e){return this.__data__.get(e)},l.prototype.has=function(e){return this.__data__.has(e)},l.prototype.set=function(e,t){var r=this.__data__;if(r instanceof h){var n=r.__data__;if(!je||n.length{let t=e;return n.isBuffer(t)||(t=n.from(t)),t})},function(e,t,r){(function(t,n){function i(e){if(!arguments.length||void 0===e)throw new Error("constructor requires at least a location argument");if("string"!=typeof e)throw new Error("constructor requires a location string argument");this.location=e,this.status="new"}var o=r(33),s=r(65),a=r(66);i.prototype.open=function(e,r){var n=this,i=this.status;if("function"==typeof e&&(r=e),"function"!=typeof r)throw new Error("open() requires a callback argument");"object"!=typeof e&&(e={}),e.createIfMissing=0!=e.createIfMissing,e.errorIfExists=!!e.errorIfExists,"function"==typeof this._open?(this.status="opening",this._open(e,function(e){if(e)return n.status=i,r(e);n.status="open",r()})):(this.status="open",t.nextTick(r))},i.prototype.close=function(e){var r=this,n=this.status;if("function"!=typeof e)throw new Error("close() requires a callback argument");"function"==typeof this._close?(this.status="closing",this._close(function(t){if(t)return r.status=n,e(t);r.status="closed",e()})):(this.status="closed",t.nextTick(e))},i.prototype.get=function(e,r,n){var i;if("function"==typeof r&&(n=r),"function"!=typeof n)throw new Error("get() requires a callback argument");return(i=this._checkKey(e,"key"))?n(i):(e=this._serializeKey(e),"object"!=typeof r&&(r={}),r.asBuffer=0!=r.asBuffer,"function"==typeof this._get?this._get(e,r,n):void t.nextTick(function(){n(new Error("NotFound"))}))},i.prototype.put=function(e,r,n,i){var o;if("function"==typeof n&&(i=n),"function"!=typeof i)throw new Error("put() requires a callback argument");return(o=this._checkKey(e,"key"))?i(o):(e=this._serializeKey(e),r=this._serializeValue(r),"object"!=typeof n&&(n={}),"function"==typeof this._put?this._put(e,r,n,i):void t.nextTick(i))},i.prototype.del=function(e,r,n){var i;if("function"==typeof r&&(n=r),"function"!=typeof n)throw new Error("del() requires a callback argument");return(i=this._checkKey(e,"key"))?n(i):(e=this._serializeKey(e),"object"!=typeof r&&(r={}),"function"==typeof this._del?this._del(e,r,n):void t.nextTick(n))},i.prototype.batch=function(e,r,n){if(!arguments.length)return this._chainedBatch();if("function"==typeof r&&(n=r),"function"==typeof e&&(n=e),"function"!=typeof n)throw new Error("batch(array) requires a callback argument");if(!Array.isArray(e))return n(new Error("batch(array) requires an array argument"));r&&"object"==typeof r||(r={});for(var i,o,s=0,a=e.length;se.hash),null,2)),await r.sync(t)}catch(e){y.error(e)}}_onPeerConnected(e,t,r){y.debug(`New peer '${t}' connected to '${e}'`);const n=this.stores[e];if(n){let i=n._oplog.heads;i.length>0&&(y.debug(`Send latest heads of '${e}':\n`,JSON.stringify(i.map(e=>e.hash),null,2)),r.sendTo(t,JSON.stringify(i))),n.events.emit("peer",t)}}_onClosed(e){y.debug(`Database '${e}' was closed`),this.stores[e].events.removeAllListeners("closed"),this._pubsub&&this._pubsub.unsubscribe(e),delete this.stores[e]}async create(e,t,r={}){if(y.debug("create()"),!m.isValidType(t))throw new Error(`Invalid database type '${t}'`);const i=r.directory||this.directory;if(y.debug(`Creating database '${e}' as ${t} in '${i}'`),l.isValid(e))throw new Error("Given database name is an address. Please give only the name of the database!");const o=new d(this._ipfs);r&&r.write&&r.write.length>0?r.write.forEach(e=>o.add("write",e)):o.add("write",this.key.getPublic("hex"));const s=await o.save(),a=await p(this._ipfs,e,t,s),c=l.parse(n.join("/orbitdb",a,e));if(await this._loadCache(i,c).then(e=>e?e.get(n.join(c.toString(),"_manifest")):null).then(e=>void 0!==e&&null!==e)&&!r.overwrite)throw new Error(`Database '${c}' already exists!`);return await this._saveDBManifest(i,c),y.debug(`Created database '${c}'`),this.open(c,r)}async open(e,t={}){y.debug("open()"),t=Object.assign({localOnly:!1,create:!1},t),y.debug(`Open database '${e}'`);const r=t.directory||this.directory;if(y.debug(`Look from '${r}'`),!l.isValid(e)){if(t.create){if(t.create&&!t.type)throw new Error(`Database type not provided! Provide a type with 'options.type' (${g.join("|")})`);return y.warn(`Not a valid OrbitDB address '${e}', creating the database`),t.overwrite=!t.overwrite||t.overwrite,this.create(e,t.type,t)}throw new Error("'options.create' set to 'false'. If you want to create a database, set 'options.create' to 'true'.")}const i=l.parse(e),o=await this._loadCache(r,i).then(e=>e?e.get(n.join(i.toString(),"_manifest")):null).then(e=>void 0!==e&&null!==e);if(y.debug((o?"Found":"Didn't find")+` database '${i}'`),t.localOnly&&!o)throw y.error(`Database '${i}' doesn't exist!`),new Error(`Database '${i}' doesn't exist!`);y.debug(`Loading Manifest for '${i}'`);const s=await this._ipfs.object.get(i.root),a=JSON.parse(s.toJSON().data);if(y.debug(`Manifest for '${i}':\n${JSON.stringify(a,null,2)}`),t.type&&a.type!==t.type)throw new Error(`Database '${i}' is type '${a.type}' but was opened as '${t.type}'`);return await this._saveDBManifest(r,i),t=Object.assign({},t,{accessControllerAddress:a.accessController}),this._openDatabase(i,a.type,t)}async _saveDBManifest(e,t){const r=await this._loadCache(e,t);await r.set(n.join(t.toString(),"_manifest"),t.root),y.debug(`Saved manifest to IPFS as '${t.root}'`)}async _loadCache(e,t){let r;try{r=await u.load(e,t)}catch(e){y.warn("Couldn't load Cache:",e)}return r}async _openDatabase(e,t,r){if("counter"===t)return this._createStore(a,e,r);if("eventlog"===t)return this._createStore(i,e,r);if("feed"===t)return this._createStore(o,e,r);if("docstore"===t)return this._createStore(c,e,r);if("keyvalue"===t)return this._createStore(s,e,r);throw new Error(`Invalid database type '${t}'`)}static isValidType(e){return g.includes(e)}static create(){return new Error("Not implemented yet!")}static open(){return new Error("Not implemented yet!")}}e.exports=m},function(e,t,r){"use strict";function n(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function i(e){return s[e>>18&63]+s[e>>12&63]+s[e>>6&63]+s[63&e]}function o(e,t,r){for(var n,o=[],s=t;s0?f-4:f;var u=0;for(t=0;t>16&255,s[u++]=i>>8&255,s[u++]=255&i;return 2===o?(i=a[e.charCodeAt(t)]<<2|a[e.charCodeAt(t+1)]>>4,s[u++]=255&i):1===o&&(i=a[e.charCodeAt(t)]<<10|a[e.charCodeAt(t+1)]<<4|a[e.charCodeAt(t+2)]>>2,s[u++]=i>>8&255,s[u++]=255&i),s},t.fromByteArray=function(e){for(var t,r=e.length,n=r%3,i="",a=[],c=0,f=r-n;cf?f:c+16383));return 1===n?(t=e[r-1],i+=s[t>>2],i+=s[t<<4&63],i+="=="):2===n&&(t=(e[r-2]<<8)+e[r-1],i+=s[t>>10],i+=s[t>>4&63],i+=s[t<<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=r?i-1:0,d=r?-1:1,l=e[t+h];for(h+=d,o=l&(1<<-u)-1,l>>=-u,u+=a;u>0;o=256*o+e[t+h],h+=d,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=n;u>0;s=256*s+e[t+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,n),o-=f}return(l?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,r,n,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=n?0:o-1,p=n?1:-1,b=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=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=(t*c-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[r+l]=255&a,l+=p,a/=256,i-=8);for(s=s<0;e[r+l]=255&s,l+=p,s/=256,f-=8);e[r+l-p]|=128*b}},function(e,t){},function(e,t,r){"use strict";function n(e,t,r){e.copy(t,r)}var i=r(9).Buffer;e.exports=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null,this.length=0}return e.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},e.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},e.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},e.prototype.clear=function(){this.head=this.tail=null,this.length=0},e.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},e.prototype.concat=function(e){if(0===this.length)return i.alloc(0);if(1===this.length)return this.head.data;for(var t=i.allocUnsafe(e>>>0),r=this.head,o=0;r;)n(r.data,t,o),o+=r.data.length,r=r.next;return t},e}()},function(e,t,r){(function(e,t){!function(e,r){"use strict";function n(e){delete a[e]}function i(e){if(c)setTimeout(i,0,e);else{var t=a[e];if(t){c=!0;try{!function(e){var t=e.callback,n=e.args;switch(n.length){case 0:t();break;case 1:t(n[0]);break;case 2:t(n[0],n[1]);break;case 3:t(n[0],n[1],n[2]);break;default:t.apply(r,n)}}(t)}finally{n(e),c=!1}}}}if(!e.setImmediate){var o,s=1,a={},c=!1,f=e.document,u=Object.getPrototypeOf&&Object.getPrototypeOf(e);u=u&&u.setTimeout?u:e,"[object process]"==={}.toString.call(e.process)?o=function(e){t.nextTick(function(){i(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,r=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=r,t}}()?function(){var t="setImmediate$"+Math.random()+"$",r=function(r){r.source===e&&"string"==typeof r.data&&0===r.data.indexOf(t)&&i(+r.data.slice(t.length))};e.addEventListener?e.addEventListener("message",r,!1):e.attachEvent("onmessage",r),o=function(r){e.postMessage(t+r,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){i(e.data)},o=function(t){e.port2.postMessage(t)}}():f&&"onreadystatechange"in f.createElement("script")?function(){var e=f.documentElement;o=function(t){var r=f.createElement("script");r.onreadystatechange=function(){i(t),r.onreadystatechange=null,e.removeChild(r),r=null},e.appendChild(r)}}():o=function(e){setTimeout(i,0,e)},u.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;rn(e,(e,r,n)=>t(r,n)).then(()=>e))},function(e,t,r){"use strict";e.exports=((e,t,r)=>new Promise((n,i)=>{const o=e[Symbol.iterator]();let s=0;const a=e=>{const r=o.next();r.done?n(e):Promise.all([e,r.value]).then(e=>{a(t(e[0],e[1],s++))}).catch(i)};a(r)}))},function(e,t,r){"use strict";e.exports=class{constuctor(e){}append(e){}merge(e){}get(e){}has(e){}get values(){}get length(){}}},function(e,t,r){"use strict";r(22);const n=r(26),i=r(81),o=r(27),s=r(44),a=r(28),c=r(45),f=r(83),u=r(84),h=(e,t)=>e.slice(e.length-t,e.length);e.exports=class{static toMultihash(e,t){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw s.LogNotDefinedError();if(t.values.length<1)throw new Error("Can't serialize an empty log");return e.object.put(t.toBuffer()).then(e=>e.toJSON().multihash)}static fromMultihash(e,t,r=-1,c,f){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw new Error(`Invalid hash: ${t}`);return e.object.get(t,{enc:"base58"}).then(e=>JSON.parse(e.toJSON().data)).then(t=>{if(!t.heads||!t.id)throw s.NotALogError();return i.fetchAll(e,t.heads,r,c,null,f).then(e=>{const r=e.reduce((e,t)=>t.clock.time>e.time?new o(t.clock.id,t.clock.time):e,new o(t.id)),i=e.slice().sort(n.compare),s=i.filter(e=>t.heads.includes(e.hash));return{id:t.id,values:i,heads:s,clock:r}})})}static fromEntryHash(e,t,r,n=-1,o,c){if(!a(e))throw s.IpfsNotDefinedError();if(!a(t))throw new Error("'entryHash' must be defined");n=n>-1?Math.max(n,1):n;const f=o;return i.fetchParallel(e,[t],n,f,null,null,c).then(e=>({values:n>-1?h(e,n):e}))}static fromJSON(e,t,r=-1,o,c,f){if(!a(e))throw s.ImmutableDBNotDefinedError();return i.fetchParallel(e,t.heads.map(e=>e.hash),r,[],16,c,f).then(e=>{const r=e.slice().sort(n.compare);return e.filter(e=>t.heads.includes(e.hash)),{id:t.id,values:r,heads:t.heads}})}static fromEntry(e,t,r=-1,o,f,h,d){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(t)&&!n.isEntry(t))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(t)||(t=[t]),r=r>-1?Math.max(r,t.length):r;const l=o?o.map(e=>e.hash?e.hash:e):o,p=t.map(e=>e.hash);return i.fetchParallel(e,p,r,l,null,null,d).then(e=>{var i=t.concat(e),o=c(i,"hash").sort(n.compare);const s=o.slice(r>-1?-r:-o.length),a=((e,t)=>{var r=e.slice(t.length,e.length);return t.concat(r)})(s,u(s,t,"hash"));return{id:a[a.length-1].id,values:a}})}static expandFrom(e,t,r,n=-1){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw s.LogNotDefinedError();if(!a(r))throw new Error("'entries' must be given as argument");Array.isArray(r)||(r=[r]);const o=r.map(e=>e.next).filter(e=>e.length>0);return 0===o.length?Promise.resolve({values:t.values}):i.fetchParallel(e,o,n,t.values).then(e=>({values:t.merge(e.slice(0,n))}))}static expand(e,t,r=-1){if(!a(e))throw s.ImmutableDBNotDefinedError();if(!a(t))throw s.LogNotDefinedError();return 0===t.tailHashes.length?Promise.resolve({values:t.values}):i.fetchParallel(e,t.tailHashes,r,t.values).then(e=>{const i=r>-1?t.values.length+r:-1,o=t.values.concat(e).sort(n.compare),s=i>-1?o.slice(-i):o.slice(),a=u(s,t.values,"hash").sort(n.compare),h=u(t.values,s,"hash").sort(n.compare),d=f(t.values,s,"hash").sort(n.compare),l=i-(d.length+a.length),p=(e,t)=>{var r=[];return r=e.concat(t),c(r,"hash").sort(n.compare)};return{values:p(a,p(d,l>-1?h.slice(-l):h))}})}}},function(e,t,r){"use strict";const n=r(82),i=r(22),o=r(26);class s{static fetchParallel(e,t,r,n=[],o,a,c){const f=(e,t)=>e.concat(t);return i(t,t=>s.fetchAll(e,t,r,n,a,c),{concurrency:Math.max(o||t.length,1)}).then(e=>e.reduce(f,[]))}static fetchAll(e,t,r,i=[],s=null,a){let c=[],f={},u=Array.isArray(t)?t.slice():[t];const h=e=>u.push(e);i.forEach(e=>f[e.hash]=e);return n(()=>u.length>0&&(c.length{const t=u.shift();return f[t]?Promise.resolve():new Promise((r,n)=>{const i=s?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${t}', request timed out (${s}ms)`),r()},s):null;0,o.fromMultihash(e,t).then(e=>{clearTimeout(i),o.isEntry(e)&&(e.next.forEach(h),c.push(e),f[t]=e,0,a&&a(t,e,c.length))}).then(r).catch(e=>{r()})})}).then(()=>c)}}e.exports=s},function(e,t,r){"use strict";const n=e=>new Promise(t=>{t(e())});e.exports=((e,t)=>n(function r(){if(e())return n(t).then(r)}))},function(e,t,r){"use strict";e.exports=function(e,t,r){var n={},i={};return e.forEach(e=>i[r?e[r]:e]=!0),t.reduce((e,t)=>{var o=void 0!==i[r?t[r]:t],s=void 0!==n[r?t[r]:t];return o&&!s&&(e.push(t),n[r?t[r]:t]=!0),e},[])}},function(e,t,r){"use strict";e.exports=function(e,t,r){var n={},i={};return e.forEach(e=>i[r?e[r]:e]=!0),t.reduce((e,t)=>{var o=void 0!==i[r?t[r]:t],s=void 0!==n[r?t[r]:t];return o||s||(e.push(t),n[r?t[r]:t]=!0),e},[])}},function(e,t){e.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(e,t,r){"use strict";var n=t,i=r(8),o=r(11),s=r(48);n.assert=o,n.toArray=s.toArray,n.zero2=s.zero2,n.toHex=s.toHex,n.encode=s.encode,n.getNAF=function(e,t){for(var r=[],n=1<=0;){var o;if(i.isOdd()){var s=i.andln(n-1);o=s>(n>>1)-1?(n>>1)-s:s,i.isubn(o)}else o=0;r.push(o);for(var a=0!==i.cmpn(0)&&0===i.andln(n-1)?t+1:1,c=1;c0||t.cmpn(-i)>0;){var o=e.andln(3)+n&3,s=t.andln(3)+i&3;3===o&&(o=-1),3===s&&(s=-1);var a;a=0==(1&o)?0:3!=(f=e.andln(7)+n&7)&&5!==f||2!==s?o:-o,r[0].push(a);var c;if(0==(1&s))c=0;else{var f;c=3!=(f=t.andln(7)+i&7)&&5!==f||2!==o?s:-s}r[1].push(c),2*n===a+1&&(n=1-n),2*i===c+1&&(i=1-i),e.iushrn(1),t.iushrn(1)}return r},n.cachedProperty=function(e,t,r){var n="_"+t;e.prototype[t]=function(){return void 0!==this[n]?this[n]:this[n]=r.call(this)}},n.parseBytes=function(e){return"string"==typeof e?n.toArray(e,"hex"):e},n.intFromLE=function(e){return new i(e,"hex","le")}},function(e,t){},function(e,t,r){function n(e){this.rand=e}var i;if(e.exports=function(e){return i||(i=new n(null)),i.generate(e)},e.exports.Rand=n,n.prototype.generate=function(e){return this._rand(e)},n.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var t=new Uint8Array(e),r=0;r0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function i(e,t){this.curve=e,this.type=t,this.precomputed=null}var o=r(8),s=r(2).utils,a=s.getNAF,c=s.getJSF,f=s.assert;e.exports=n,n.prototype.point=function(){throw new Error("Not implemented")},n.prototype.validate=function(){throw new Error("Not implemented")},n.prototype._fixedNafMul=function(e,t){f(e.precomputed);var r=e._getDoubles(),n=a(t,1),i=(1<=s;t--)c=(c<<1)+n[t];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(t=0;c>=0&&0===o[c];c--)t++;if(c>=0&&t++,s=s.dblp(t),c<0)break;var u=o[c];f(0!==u),s="affine"===e.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"===e.type?s.toP():s},n.prototype._wnafMulAdd=function(e,t,r,n,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=[t[l],null,null,t[p]];0===t[l].y.cmp(t[p].y)?(b[1]=t[l].add(t[p]),b[2]=t[l].toJ().mixedAdd(t[p].neg())):0===t[l].y.cmp(t[p].y.redNeg())?(b[1]=t[l].toJ().mixedAdd(t[p]),b[2]=t[l].add(t[p].neg())):(b[1]=t[l].toJ().mixedAdd(t[p]),b[2]=t[l].toJ().mixedAdd(t[p].neg()));var y=[-3,-1,-5,-7,0,7,5,1,3],g=c(r[l],r[p]);u=Math.max(g[0].length,u),f[l]=new Array(u),f[p]=new Array(u);for(var m=0;m=0;h--){for(var k=0;h>=0;){var E=!0;for(m=0;m=0&&k++,w=w.dblp(k),h<0)break;for(m=0;m0?x=s[m][M-1>>1]:M<0&&(x=s[m][-M-1>>1].neg()),w="affine"===x.type?w.mixedAdd(x):w.add(x))}}for(h=0;h=Math.ceil((e.bitLength()+1)/t.step)},i.prototype._getDoubles=function(e,t){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var r=[this],n=this,i=0;i=0&&(o=t,s=r),n.negative&&(n=n.neg(),i=i.neg()),o.negative&&(o=o.neg(),s=s.neg()),[{a:n,b:i},{a:o,b:s}]},n.prototype._endoSplit=function(e){var t=this.endo.basis,r=t[0],n=t[1],i=n.b.mul(e).divRound(this.n),o=r.b.neg().mul(e).divRound(this.n),s=i.mul(r.a),a=o.mul(n.a),c=i.mul(r.b),f=o.mul(n.b);return{k1:e.sub(s).sub(a),k2:c.add(f).neg()}},n.prototype.pointFromX=function(e,t){(e=new c(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),n=r.redSqrt();if(0!==n.redSqr().redSub(r).cmp(this.zero))throw new Error("invalid point");var i=n.fromRed().isOdd();return(t&&!i||!t&&i)&&(n=n.redNeg()),this.point(e,n)},n.prototype.validate=function(e){if(e.inf)return!0;var t=e.x,r=e.y,n=this.a.redMul(t),i=t.redSqr().redMul(t).redIAdd(n).redIAdd(this.b);return 0===r.redSqr().redISub(i).cmpn(0)},n.prototype._endoWnafMulAdd=function(e,t,r){for(var n=this._endoWnafT1,i=this._endoWnafT2,o=0;o":""},i.prototype.isInfinity=function(){return this.inf},i.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var t=this.y.redSub(e.y);0!==t.cmpn(0)&&(t=t.redMul(this.x.redSub(e.x).redInvm()));var r=t.redSqr().redISub(this.x).redISub(e.x),n=t.redMul(this.x.redSub(r)).redISub(this.y);return this.curve.point(r,n)},i.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var t=this.curve.a,r=this.x.redSqr(),n=e.redInvm(),i=r.redAdd(r).redIAdd(r).redIAdd(t).redMul(n),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(e){return e=new c(e,16),this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},i.prototype.mulAdd=function(e,t,r){var n=[this,t],i=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i):this.curve._wnafMulAdd(1,n,i,2)},i.prototype.jmulAdd=function(e,t,r){var n=[this,t],i=[e,r];return this.curve.endo?this.curve._endoWnafMulAdd(n,i,!0):this.curve._wnafMulAdd(1,n,i,2,!0)},i.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},i.prototype.neg=function(e){if(this.inf)return this;var t=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var r=this.precomputed,n=function(e){return e.neg()};t.precomputed={naf:r.naf&&{wnd:r.naf.wnd,points:r.naf.points.map(n)},doubles:r.doubles&&{step:r.doubles.step,points:r.doubles.points.map(n)}}}return t},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),n.prototype.jpoint=function(e,t,r){return new o(this,e,t,r)},o.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),t=e.redSqr(),r=this.x.redMul(t),n=this.y.redMul(t).redMul(e);return this.curve.point(r,n)},o.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},o.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.z.redSqr(),r=this.z.redSqr(),n=this.x.redMul(t),i=e.x.redMul(r),o=this.y.redMul(t.redMul(e.z)),s=e.y.redMul(r.redMul(this.z)),a=n.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=n.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(e.z).redMul(a);return this.curve.jpoint(d,l,p)},o.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var t=this.z.redSqr(),r=this.x,n=e.x.redMul(t),i=this.y,o=e.y.redMul(t).redMul(this.z),s=r.redSub(n),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=r.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(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var t=this,r=0;r=0)return!1;if(r.redIAdd(i),0===this.x.cmp(r))return!0}return!1},o.prototype.inspect=function(){return this.isInfinity()?"":""},o.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},function(e,t,r){"use strict";function n(e){c.call(this,"mont",e),this.a=new s(e.a,16).toRed(this.red),this.b=new s(e.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(e,t,r){c.BasePoint.call(this,e,"projective"),null===t&&null===r?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new s(t,16),this.z=new s(r,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=r(23),s=r(8),a=r(4),c=o.base,f=r(2).utils;a(n,c),e.exports=n,n.prototype.validate=function(e){var t=e.normalize().x,r=t.redSqr(),n=r.redMul(t).redAdd(r.redMul(this.a)).redAdd(t);return 0===n.redSqrt().redSqr().cmp(n)},a(i,c.BasePoint),n.prototype.decodePoint=function(e,t){return this.point(f.toArray(e,t),1)},n.prototype.point=function(e,t){return new i(this,e,t)},n.prototype.pointFromJSON=function(e){return i.fromJSON(this,e)},i.prototype.precompute=function(){},i.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},i.fromJSON=function(e,t){return new i(e,t[0],t[1]||e.one)},i.prototype.inspect=function(){return this.isInfinity()?"":""},i.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},i.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),t=this.x.redSub(this.z).redSqr(),r=e.redSub(t),n=e.redMul(t),i=r.redMul(t.redAdd(this.curve.a24.redMul(r)));return this.curve.point(n,i)},i.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},i.prototype.diffAdd=function(e,t){var r=this.x.redAdd(this.z),n=this.x.redSub(this.z),i=e.x.redAdd(e.z),o=e.x.redSub(e.z).redMul(r),s=i.redMul(n),a=t.z.redMul(o.redAdd(s).redSqr()),c=t.x.redMul(o.redISub(s).redSqr());return this.curve.point(a,c)},i.prototype.mul=function(e){for(var t=e.clone(),r=this,n=this.curve.point(null,null),i=[];0!==t.cmpn(0);t.iushrn(1))i.push(t.andln(1));for(var o=i.length-1;o>=0;o--)0===i[o]?(r=r.diffAdd(n,this),n=n.dbl()):(n=r.diffAdd(n,this),r=r.dbl());return n},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(e){return 0===this.getX().cmp(e.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(e,t,r){"use strict";function n(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,f.call(this,"edwards",e),this.a=new a(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new a(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new a(e.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|e.c)}function i(e,t,r,n,i){f.BasePoint.call(this,e,"projective"),null===t&&null===r&&null===n?(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(t,16),this.y=new a(r,16),this.z=n?new a(n,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=r(23),s=r(2),a=r(8),c=r(4),f=o.base,u=s.utils.assert;c(n,f),e.exports=n,n.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},n.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},n.prototype.jpoint=function(e,t,r,n){return this.point(e,t,r,n)},n.prototype.pointFromX=function(e,t){(e=new a(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr(),n=this.c2.redSub(this.a.redMul(r)),i=this.one.redSub(this.c2.redMul(this.d).redMul(r)),o=n.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(t&&!c||!t&&c)&&(s=s.redNeg()),this.point(e,s)},n.prototype.pointFromY=function(e,t){(e=new a(e,16)).red||(e=e.toRed(this.red));var r=e.redSqr(),n=r.redSub(this.one),i=r.redMul(this.d).redAdd(this.one),o=n.redMul(i.redInvm());if(0===o.cmp(this.zero)){if(t)throw new Error("invalid point");return this.point(this.zero,e)}var s=o.redSqrt();if(0!==s.redSqr().redSub(o).cmp(this.zero))throw new Error("invalid point");return s.isOdd()!==t&&(s=s.redNeg()),this.point(s,e)},n.prototype.validate=function(e){if(e.isInfinity())return!0;e.normalize();var t=e.x.redSqr(),r=e.y.redSqr(),n=t.redMul(this.a).redAdd(r),i=this.c2.redMul(this.one.redAdd(this.d.redMul(t).redMul(r)));return 0===n.cmp(i)},c(i,f.BasePoint),n.prototype.pointFromJSON=function(e){return i.fromJSON(this,e)},n.prototype.point=function(e,t,r,n){return new i(this,e,t,r,n)},i.fromJSON=function(e,t){return new i(e,t[0],t[1],t[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 e=this.x.redSqr(),t=this.y.redSqr(),r=this.z.redSqr();r=r.redIAdd(r);var n=this.curve._mulA(e),i=this.x.redAdd(this.y).redSqr().redISub(e).redISub(t),o=n.redAdd(t),s=o.redSub(r),a=n.redSub(t),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 e,t,r,n=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)e=n.redSub(i).redSub(o).redMul(s.redSub(this.curve.two)),t=s.redMul(f.redSub(o)),r=s.redSqr().redSub(s).redSub(s);else{var a=this.z.redSqr(),c=s.redSub(a).redISub(a);e=n.redSub(i).redISub(o).redMul(c),t=s.redMul(f.redSub(o)),r=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);e=this.curve._mulC(n.redISub(f)).redMul(c),t=this.curve._mulC(f).redMul(i.redISub(o)),r=f.redMul(c)}return this.curve.point(e,t,r)},i.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},i.prototype._extAdd=function(e){var t=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),r=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),n=this.t.redMul(this.curve.dd).redMul(e.t),i=this.z.redMul(e.z.redAdd(e.z)),o=r.redSub(t),s=i.redSub(n),a=i.redAdd(n),c=r.redAdd(t),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(e){var t,r,n=this.z.redMul(e.z),i=n.redSqr(),o=this.x.redMul(e.x),s=this.y.redMul(e.y),a=this.curve.d.redMul(o).redMul(s),c=i.redSub(a),f=i.redAdd(a),u=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(o).redISub(s),h=n.redMul(c).redMul(u);return this.curve.twisted?(t=n.redMul(f).redMul(s.redSub(this.curve._mulA(o))),r=c.redMul(f)):(t=n.redMul(f).redMul(s.redSub(o)),r=this.curve._mulC(c).redMul(f)),this.curve.point(h,t,r)},i.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},i.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},i.prototype.mulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!1)},i.prototype.jmulAdd=function(e,t,r){return this.curve._wnafMulAdd(1,[this,t],[e,r],2,!0)},i.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),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(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},i.prototype.eqXToP=function(e){var t=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(t))return!0;for(var r=e.clone(),n=this.curve.redN.redMul(this.z);;){if(r.iadd(this.curve.n),r.cmp(this.curve.p)>=0)return!1;if(t.redIAdd(n),0===this.x.cmp(t))return!0}return!1},i.prototype.toP=i.prototype.normalize,i.prototype.mixedAdd=i.prototype.add},function(e,t,r){"use strict";function n(e){"short"===e.type?this.curve=new a.curve.short(e):"edwards"===e.type?this.curve=new a.curve.edwards(e):this.curve=new a.curve.mont(e),this.g=this.curve.g,this.n=this.curve.n,this.hash=e.hash,c(this.g.validate(),"Invalid curve"),c(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function i(e,t){Object.defineProperty(o,e,{configurable:!0,enumerable:!0,get:function(){var r=new n(t);return Object.defineProperty(o,e,{configurable:!0,enumerable:!0,value:r}),r}})}var o=t,s=r(29),a=r(2),c=a.utils.assert;o.PresetCurve=n,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=r(101)}catch(e){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(e,t,r){"use strict";t.sha1=r(96),t.sha224=r(97),t.sha256=r(50),t.sha384=r(98),t.sha512=r(51)},function(e,t,r){"use strict";function n(){if(!(this instanceof n))return new n;h.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}var i=r(5),o=r(16),s=r(49),a=i.rotl32,c=i.sum32,f=i.sum32_5,u=s.ft_1,h=o.BlockHash,d=[1518500249,1859775393,2400959708,3395469782];i.inherits(n,h),e.exports=n,n.blockSize=512,n.outSize=160,n.hmacStrength=80,n.padLength=64,n.prototype._update=function(e,t){for(var r=this.W,n=0;n<16;n++)r[n]=e[t+n];for(;nthis.blockSize&&(e=(new this.Hash).update(e).digest()),o(e.length<=this.blockSize);for(var t=e.length;t0))return a.iaddn(1),this.keyFromPrivate(a)}},n.prototype._truncateToN=function(e,t){var r=8*e.byteLength()-this.n.bitLength();return r>0&&(e=e.ushrn(r)),!t&&e.cmp(this.n)>=0?e.sub(this.n):e},n.prototype.sign=function(e,t,r,n){"object"==typeof r&&(n=r,r=null),n||(n={}),t=this.keyFromPrivate(t,r),e=this._truncateToN(new i(e,16));for(var s=this.n.byteLength(),a=t.getPrivate().toArray("be",s),c=e.toArray("be",s),u=new o({hash:this.hash,entropy:a,nonce:c,pers:n.pers,persEnc:n.persEnc||"utf8"}),h=this.n.sub(new i(1)),d=0;;d++){var l=n.k?n.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(t.getPrivate()).iadd(e));if(0!==(g=g.umod(this.n)).cmpn(0)){var m=(p.getY().isOdd()?1:0)|(0!==b.cmp(y)?2:0);return n.canonical&&g.cmp(this.nh)>0&&(g=this.n.sub(g),m^=1),new f({r:y,s:g,recoveryParam:m})}}}}}},n.prototype.verify=function(e,t,r,n){e=this._truncateToN(new i(e,16)),r=this.keyFromPublic(r,n);var o=(t=new f(t,"hex")).r,s=t.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(e).umod(this.n),u=a.mul(o).umod(this.n);if(!this.curve._maxwellTrick){return!(h=this.g.mulAdd(c,r.getPublic(),u)).isInfinity()&&0===h.getX().umod(this.n).cmp(o)}var h;return!(h=this.g.jmulAdd(c,r.getPublic(),u)).isInfinity()&&h.eqXToP(o)},n.prototype.recoverPubKey=function(e,t,r,n){a((3&r)===r,"The recovery param is more than two bits"),t=new f(t,n);var o=this.n,s=new i(e),c=t.r,u=t.s,h=1&r,d=r>>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=t.r.invm(o),p=o.sub(s).mul(l).umod(o),b=u.mul(l).umod(o);return this.g.mulAdd(p,c,b)},n.prototype.getKeyRecoveryParam=function(e,t,r,n){if(null!==(t=new f(t,n)).recoveryParam)return t.recoveryParam;for(var i=0;i<4;i++){var o;try{o=this.recoverPubKey(e,t,i)}catch(e){continue}if(o.eq(r))return i}throw new Error("Unable to find valid recovery factor")}},function(e,t,r){"use strict";function n(e){if(!(this instanceof n))return new n(e);this.hash=e.hash,this.predResist=!!e.predResist,this.outLen=this.hash.outSize,this.minEntropy=e.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var t=o.toArray(e.entropy,e.entropyEnc||"hex"),r=o.toArray(e.nonce,e.nonceEnc||"hex"),i=o.toArray(e.pers,e.persEnc||"hex");s(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,r,i)}var i=r(29),o=r(48),s=r(11);e.exports=n,n.prototype._init=function(e,t,r){var n=e.concat(t).concat(r);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(e.concat(r||[])),this._reseed=1},n.prototype.generate=function(e,t,r,n){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof t&&(n=r,r=t,t=null),r&&(r=o.toArray(r,n||"hex"),this._update(r));for(var i=[];i.length"}},function(e,t,r){"use strict";function n(e,t){if(e instanceof n)return e;this._importDER(e,t)||(f(e.r&&e.s,"Signature without r or s"),this.r=new a(e.r,16),this.s=new a(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}function i(e,t){var r=e[t.place++];if(!(128&r))return r;for(var n=15&r,i=0,o=0,s=t.place;o>>3);for(e.push(128|r);--r;)e.push(t>>>(r<<3)&255);e.push(t)}}var a=r(8),c=r(2).utils,f=c.assert;e.exports=n,n.prototype._importDER=function(e,t){e=c.toArray(e,t);var r=new function(){this.place=0};if(48!==e[r.place++])return!1;if(i(e,r)+r.place!==e.length)return!1;if(2!==e[r.place++])return!1;var n=i(e,r),o=e.slice(r.place,n+r.place);if(r.place+=n,2!==e[r.place++])return!1;var s=i(e,r);if(e.length!==s+r.place)return!1;var f=e.slice(r.place,s+r.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},n.prototype.toDER=function(e){var t=this.r.toArray(),r=this.s.toArray();for(128&t[0]&&(t=[0].concat(t)),128&r[0]&&(r=[0].concat(r)),t=o(t),r=o(r);!(r[0]||128&r[1]);)r=r.slice(1);var n=[2];s(n,t.length),(n=n.concat(t)).push(2),s(n,r.length);var i=n.concat(r),a=[48];return s(a,i.length),a=a.concat(i),c.encode(a,e)}},function(e,t,r){"use strict";function n(e){if(a("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof n))return new n(e);e=o.curves[e].curve;this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=i.sha512}var i=r(29),o=r(2),s=o.utils,a=s.assert,c=s.parseBytes,f=r(107),u=r(108);e.exports=n,n.prototype.sign=function(e,t){e=c(e);var r=this.keyFromSecret(t),n=this.hashInt(r.messagePrefix(),e),i=this.g.mul(n),o=this.encodePoint(i),s=this.hashInt(o,r.pubBytes(),e).mul(r.priv()),a=n.add(s).umod(this.curve.n);return this.makeSignature({R:i,S:a,Rencoded:o})},n.prototype.verify=function(e,t,r){e=c(e),t=this.makeSignature(t);var n=this.keyFromPublic(r),i=this.hashInt(t.Rencoded(),n.pubBytes(),e),o=this.g.mul(t.S());return t.R().add(n.pub().mul(i)).eq(o)},n.prototype.hashInt=function(){for(var e=this.hash(),t=0;tthis.quota)throw new a;if(y(o,g,"utf8"),i||((h=new s(r,this._keys.push(e)-1)).size=m,this._metaKeyMap[e]=h,this.length+=1,this._bytesInUse+=m),f)return n=new c(e,p,t,this._eventUrl),this.emit("storage",n)},r.prototype.getItem=function(e){var t,r;return e=u(e),(r=this._metaKeyMap[e])?(t=b.join(this._location,r.key),p.readFileSync(t,"utf8")):null},r.prototype._getStat=function(e){var t;e=u(e),t=b.join(this._location,encodeURIComponent(e));try{return p.statSync(t)}catch(e){return null}},r.prototype.removeItem=function(e){var t,r,n,i,o,s,a,f;if(e=u(e),s=this._metaKeyMap[e]){a=null,(n=l.EventEmitter.listenerCount(this,"storage"))&&(a=this.getItem(e)),delete this._metaKeyMap[e],this.length-=1,this._bytesInUse-=s.size,r=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(r),n)return t=new c(e,a,null,this._eventUrl),this.emit("storage",t)}},r.prototype.key=function(e){return this._keys[e]},r.prototype.clear=function(){var e;if(f(this._location),this._metaKeyMap=d(),this._keys=[],this.length=0,this._bytesInUse=0,l.EventEmitter.listenerCount(this,"storage"))return e=new c(null,null,null,this._eventUrl),this.emit("storage",e)},r.prototype._getBytesInUse=function(){return this._bytesInUse},r.prototype._deleteLocation=function(){return delete n[this._location],h(this._location),this._metaKeyMap={},this._keys=[],this.length=0,this._bytesInUse=0},r}(l.EventEmitter),n=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return g(t,o),t.prototype.setItem=function(e,r){var n;return n=JSON.stringify(r),t.__super__.setItem.call(this,e,n)},t.prototype.getItem=function(e){return JSON.parse(t.__super__.getItem.call(this,e))},t}(),t.LocalStorage=o,t.JSONStorage=n,t.QUOTA_EXCEEDED_ERR=a}).call(this)}).call(t,r(0))},function(e,t,r){"use strict";(function(t,n,i){function o(e){return e+"."+c(t).hash(String(n.pid)).hash(String(++u)).result()}e.exports=function(e,t,r,c){r instanceof Function&&(c=r,r=null),r||(r={}),s.realpath(e,function(u,h){!function(e,t,r,c){function u(){a([[h,d,t,r.mode,r.encoding||"utf8"],r.chown&&[s,s.chown,d,r.chown.uid,r.chown.gid],r.mode&&[s,s.chmod,d,r.mode],[s,s.rename,d,e]],function(e){e?s.unlink(d,function(){c(e)}):c()})}function h(e,t,n,o,a){s.open(e,"w",r.mode,function(e,r){function n(e){if(e)return a(e);s.fsync(r,function(e){if(e)return a(e);s.close(r,a)})}return e?a(e):i.isBuffer(t)?s.write(r,t,0,t.length,0,n):null!=t?s.write(r,String(t),0,String(o),n):n()})}var d=o(e);r.mode&&r.chown?u():s.stat(e,function(e,t){return e||!t?u():((r=f({},r)).mode||(r.mode=t.mode),!r.chown&&n.getuid&&(r.chown={uid:t.uid,gid:t.gid}),u())})}(h||e,t,r,c)})},e.exports.sync=function(e,t,r){r||(r={});try{e=s.realpathSync(e)}catch(e){}var a=o(e);try{if(!r.mode||!r.chown)try{var c=s.statSync(e);(r=f({},r)).mode||(r.mode=c.mode),!r.chown&&n.getuid&&(r.chown={uid:c.uid,gid:c.gid})}catch(e){}var u=s.openSync(a,"w",r.mode);i.isBuffer(t)?s.writeSync(u,t,0,t.length,0):null!=t&&s.writeSync(u,String(t),0,String(r.encoding||"utf8")),s.fsyncSync(u),s.closeSync(u),r.chown&&s.chownSync(a,r.chown.uid,r.chown.gid),r.mode&&s.chmodSync(a,r.mode),s.renameSync(a,e)}catch(e){try{s.unlinkSync(a)}catch(e){}throw e}},e.exports._getTmpname=o;var s=r(111),a=r(122).chain,c=r(125),f=Object.assign||r(6)._extend,u=0}).call(t,"/index.js",r(0),r(1).Buffer)},function(e,t,r){(function(t){function n(e){function r(t){return p.apply(e,t)}function s(e,t){return this instanceof s?(y.apply(this,arguments),this):s.apply(Object.create(s.prototype),arguments)}function f(e,t){return this instanceof f?(g.apply(this,arguments),this):f.apply(Object.create(f.prototype),arguments)}function u(e,t,r,n){function s(e,t,r,n){return m(e,t,r,function(a,c){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof n&&n.apply(this,arguments),o()):i([s,[e,t,r,n]])})}return"function"==typeof r&&(n=r,r=null),s(e,t,r,n)}a(e),e.gracefulify=n,e.FileReadStream=s,e.FileWriteStream=f,e.createReadStream=function(e,t){return new s(e,t)},e.createWriteStream=function(e,t){return new f(e,t)};var h=e.readFile;e.readFile=function(e,t,r){function n(e,t,r){return h(e,t,function(s){!s||"EMFILE"!==s.code&&"ENFILE"!==s.code?("function"==typeof r&&r.apply(this,arguments),o()):i([n,[e,t,r]])})}return"function"==typeof t&&(r=t,t=null),n(e,t,r)};var d=e.writeFile;e.writeFile=function(e,t,r,n){function s(e,t,r,n){return d(e,t,r,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof n&&n.apply(this,arguments),o()):i([s,[e,t,r,n]])})}return"function"==typeof r&&(n=r,r=null),s(e,t,r,n)};var l=e.appendFile;l&&(e.appendFile=function(e,t,r,n){function s(e,t,r,n){return l(e,t,r,function(a){!a||"EMFILE"!==a.code&&"ENFILE"!==a.code?("function"==typeof n&&n.apply(this,arguments),o()):i([s,[e,t,r,n]])})}return"function"==typeof r&&(n=r,r=null),s(e,t,r,n)});var p=e.readdir;if(e.readdir=function(e,t,n){var s=[e];return"function"!=typeof t?s.push(t):n=t,s.push(function(e,t){t&&t.sort&&t.sort(),!e||"EMFILE"!==e.code&&"ENFILE"!==e.code?("function"==typeof n&&n.apply(this,arguments),o()):i([r,[s]])}),r(s)},"v0.8"===t.version.substr(0,4)){var b=c(e);s=b.ReadStream,f=b.WriteStream}var y=e.ReadStream;(s.prototype=Object.create(y.prototype)).open=function(){var e=this;u(e.path,e.flags,e.mode,function(t,r){t?(e.autoClose&&e.destroy(),e.emit("error",t)):(e.fd=r,e.emit("open",r),e.read())})};var g=e.WriteStream;(f.prototype=Object.create(g.prototype)).open=function(){var e=this;u(e.path,e.flags,e.mode,function(t,r){t?(e.destroy(),e.emit("error",t)):(e.fd=r,e.emit("open",r))})},e.ReadStream=s,e.WriteStream=f;var m=e.open;return e.open=u,e}function i(e){h("ENQUEUE",e[0].name,e[1]),f.push(e)}function o(){var e=f.shift();e&&(h("RETRY",e[0].name,e[1]),e[0].apply(null,e[1]))}var s=r(14),a=r(112),c=r(114),f=[],u=r(6),h=function(){};u.debuglog?h=u.debuglog("gfs4"):/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&(h=function(){var e=u.format.apply(u,arguments);e="GFS4: "+e.split(/\n/).join("\nGFS4: "),console.error(e)}),/\bgfs4\b/i.test(Object({NODE_ENV:void 0}).NODE_DEBUG||"")&&t.on("exit",function(){h(f),r(53).equal(f.length,0)}),e.exports=n(r(52)),Object({NODE_ENV:void 0}).TEST_GRACEFUL_FS_GLOBAL_PATCH&&(e.exports=n(s)),e.exports.close=s.close=function(e){return function(t,r){return e.call(s,t,function(e){e||o(),"function"==typeof r&&r.apply(this,arguments)})}}(s.close),e.exports.closeSync=s.closeSync=function(e){return function(t){var r=e.apply(s,arguments);return o(),r}}(s.closeSync)}).call(t,r(0))},function(e,t,r){(function(t){function n(e){return e?function(t,r,n){return e.call(u,t,r,function(e){f(e)&&(e=null),n&&n.apply(this,arguments)})}:e}function i(e){return e?function(t,r){try{return e.call(u,t,r)}catch(e){if(!f(e))throw e}}:e}function o(e){return e?function(t,r,n,i){return e.call(u,t,r,n,function(e){f(e)&&(e=null),i&&i.apply(this,arguments)})}:e}function s(e){return e?function(t,r,n){try{return e.call(u,t,r,n)}catch(e){if(!f(e))throw e}}:e}function a(e){return e?function(t,r){return e.call(u,t,function(e,t){if(!t)return r.apply(this,arguments);t.uid<0&&(t.uid+=4294967296),t.gid<0&&(t.gid+=4294967296),r&&r.apply(this,arguments)})}:e}function c(e){return e?function(t){var r=e.call(u,t);return r.uid<0&&(r.uid+=4294967296),r.gid<0&&(r.gid+=4294967296),r}:e}function f(e){if(!e)return!0;if("ENOSYS"===e.code)return!0;return!(t.getuid&&0===t.getuid()||"EINVAL"!==e.code&&"EPERM"!==e.code)}var u=r(52),h=r(113),d=t.cwd,l=null,p=Object({NODE_ENV:void 0}).GRACEFUL_FS_PLATFORM||t.platform;t.cwd=function(){return l||(l=d.call(t)),l};try{t.cwd()}catch(e){}var b=t.chdir;t.chdir=function(e){l=null,b.call(t,e)},e.exports=function(e){h.hasOwnProperty("O_SYMLINK")&&t.version.match(/^v0\.6\.[0-2]|^v0\.5\./)&&function(e){e.lchmod=function(t,r,n){e.open(t,h.O_WRONLY|h.O_SYMLINK,r,function(t,i){t?n&&n(t):e.fchmod(i,r,function(t){e.close(i,function(e){n&&n(t||e)})})})},e.lchmodSync=function(t,r){var n,i=e.openSync(t,h.O_WRONLY|h.O_SYMLINK,r),o=!0;try{n=e.fchmodSync(i,r),o=!1}finally{if(o)try{e.closeSync(i)}catch(e){}else e.closeSync(i)}return n}}(e),e.lutimes||function(e){h.hasOwnProperty("O_SYMLINK")?(e.lutimes=function(t,r,n,i){e.open(t,h.O_SYMLINK,function(t,o){t?i&&i(t):e.futimes(o,r,n,function(t){e.close(o,function(e){i&&i(t||e)})})})},e.lutimesSync=function(t,r,n){var i,o=e.openSync(t,h.O_SYMLINK),s=!0;try{i=e.futimesSync(o,r,n),s=!1}finally{if(s)try{e.closeSync(o)}catch(e){}else e.closeSync(o)}return i}):(e.lutimes=function(e,r,n,i){i&&t.nextTick(i)},e.lutimesSync=function(){})}(e),e.chown=o(e.chown),e.fchown=o(e.fchown),e.lchown=o(e.lchown),e.chmod=n(e.chmod),e.fchmod=n(e.fchmod),e.lchmod=n(e.lchmod),e.chownSync=s(e.chownSync),e.fchownSync=s(e.fchownSync),e.lchownSync=s(e.lchownSync),e.chmodSync=i(e.chmodSync),e.fchmodSync=i(e.fchmodSync),e.lchmodSync=i(e.lchmodSync),e.stat=a(e.stat),e.fstat=a(e.fstat),e.lstat=a(e.lstat),e.statSync=c(e.statSync),e.fstatSync=c(e.fstatSync),e.lstatSync=c(e.lstatSync),e.lchmod||(e.lchmod=function(e,r,n){n&&t.nextTick(n)},e.lchmodSync=function(){}),e.lchown||(e.lchown=function(e,r,n,i){i&&t.nextTick(i)},e.lchownSync=function(){}),"win32"===p&&(e.rename=function(t){return function(r,n,i){var o=Date.now(),s=0;t(r,n,function a(c){if(c&&("EACCES"===c.code||"EPERM"===c.code)&&Date.now()-o<6e4)return setTimeout(function(){e.stat(n,function(e,o){e&&"ENOENT"===e.code?t(r,n,a):i(c)})},s),void(s<100&&(s+=10));i&&i(c)})}}(e.rename)),e.read=function(t){return function(r,n,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++,t.call(e,r,n,i,o,s,c);a.apply(this,arguments)}}return t.call(e,r,n,i,o,s,c)}}(e.read),e.readSync=function(t){return function(r,n,i,o,s){for(var a=0;;)try{return t.call(e,r,n,i,o,s)}catch(e){if("EAGAIN"===e.code&&a<10){a++;continue}throw e}}}(e.readSync)}}).call(t,r(0))},function(e,t){e.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(e,t,r){(function(t){var n=r(115).Stream;e.exports=function(e){function r(i,o){if(!(this instanceof r))return new r(i,o);n.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?e.open(this.path,this.flags,this.mode,function(e,t){if(e)return s.emit("error",e),void(s.readable=!1);s.fd=t,s.emit("open",t),s._read()}):t.nextTick(function(){s._read()})}function i(t,r){if(!(this instanceof i))return new i(t,r);n.call(this),this.path=t,this.fd=null,this.writable=!0,this.flags="w",this.encoding="binary",this.mode=438,this.bytesWritten=0,r=r||{};for(var o=Object.keys(r),s=0,a=o.length;s= zero");this.pos=this.start}this.busy=!1,this._queue=[],null===this.fd&&(this._open=e.open,this._queue.push([this._open,this.path,this.flags,this.mode,void 0]),this.flush())}return{ReadStream:r,WriteStream:i}}}).call(t,r(0))},function(e,t,r){function n(){i.call(this)}e.exports=n;var i=r(3).EventEmitter;r(4)(n,i),n.Readable=r(13),n.Writable=r(116),n.Duplex=r(117),n.Transform=r(118),n.PassThrough=r(119),n.Stream=n,n.prototype.pipe=function(e,t){function r(t){e.writable&&!1===e.write(t)&&f.pause&&f.pause()}function n(){f.readable&&f.resume&&f.resume()}function o(){u||(u=!0,e.end())}function s(){u||(u=!0,"function"==typeof e.destroy&&e.destroy())}function a(e){if(c(),0===i.listenerCount(this,"error"))throw e}function c(){f.removeListener("data",r),e.removeListener("drain",n),f.removeListener("end",o),f.removeListener("close",s),f.removeListener("error",a),e.removeListener("error",a),f.removeListener("end",c),f.removeListener("close",c),e.removeListener("close",c)}var f=this;f.on("data",r),e.on("drain",n),e._isStdio||t&&!1===t.end||(f.on("end",o),f.on("close",s));var u=!1;return f.on("error",a),e.on("error",a),f.on("end",c),f.on("close",c),e.on("close",c),e.emit("pipe",f),e}},function(e,t,r){e.exports=r(25)},function(e,t,r){e.exports=r(10)},function(e,t,r){e.exports=r(13).Transform},function(e,t,r){e.exports=r(13).PassThrough},function(e,t){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}},function(e,t,r){t.asyncMap=r(123),t.bindActor=r(54),t.chain=r(124)},function(e,t,r){(function(t){e.exports=function(){function e(u){u&&!a&&(a=u);for(var h=arguments.length,d=1;dc){var l=n.slice(c);f+=(n.length-c)*o,c=n.length,t.nextTick(function(){l.forEach(function(t){r.forEach(function(r){r(t,e)})})})}0==--f&&i.apply(null,[a].concat(s))}var r=Array.prototype.slice.call(arguments),n=r.shift()||[],i=r.pop();if("function"!=typeof i)throw new Error("No callback provided to asyncMap");if(!n)return i(null,[]);Array.isArray(n)||(n=[n]);var o=r.length,s=[],a=null,c=n.length,f=c*o;if(!f)return i(null,[]);n.forEach(function(t){r.forEach(function(r){r(t,e)})})}}).call(t,r(0))},function(e,t,r){function n(e,t){var r=[];!function o(s,a){return s>=a?t(null,r):(Array.isArray(e[s])&&(e[s]=i.apply(null,e[s].map(function(e){return e===n.first?r[0]:e===n.last?r[r.length-1]:e}))),e[s]?void e[s](function(e,n){if(e)return t(e,r);void 0!==n&&(r=r.concat(n)),o(s+1,a)}):o(s+1,a))}(0,e.length)}e.exports=n;var i=r(54);n.first={},n.last={}},function(e,t,r){!function(){function t(e,n){var i=this instanceof t?this:r;if(i.reset(n),"string"==typeof e&&e.length>0&&i.hash(e),i!==this)return i}var r;t.prototype.hash=function(e){var t,r,n,i,o;switch(o=e.length,this.len+=o,r=this.k1,n=0,this.rem){case 0:r^=o>n?65535&e.charCodeAt(n++):0;case 1:r^=o>n?(65535&e.charCodeAt(n++))<<8:0;case 2:r^=o>n?(65535&e.charCodeAt(n++))<<16:0;case 3:r^=o>n?(255&e.charCodeAt(n))<<24:0,r^=o>n?(65280&e.charCodeAt(n++))>>8:0}if(this.rem=o+this.rem&3,(o-=this.rem)>0){for(t=this.h1;r=11601*r+3432906752*(65535&r)&4294967295,r=r<<15|r>>>17,r=13715*r+461832192*(65535&r)&4294967295,t^=r,t=t<<13|t>>>19,t=5*t+3864292196&4294967295,!(n>=o);)r=65535&e.charCodeAt(n++)^(65535&e.charCodeAt(n++))<<8^(65535&e.charCodeAt(n++))<<16,r^=(255&(i=e.charCodeAt(n++)))<<24^(65280&i)>>8;switch(r=0,this.rem){case 3:r^=(65535&e.charCodeAt(n+2))<<16;case 2:r^=(65535&e.charCodeAt(n+1))<<8;case 1:r^=65535&e.charCodeAt(n)}this.h1=t}return this.k1=r,this},t.prototype.result=function(){var e,t;return e=this.k1,t=this.h1,e>0&&(t^=e=13715*(e=(e=11601*e+3432906752*(65535&e)&4294967295)<<15|e>>>17)+461832192*(65535&e)&4294967295),t^=this.len,t^=t>>>16,t=51819*t+2246770688*(65535&t)&4294967295,t^=t>>>13,t=44597*t+3266445312*(65535&t)&4294967295,(t^=t>>>16)>>>0},t.prototype.reset=function(e){return this.h1="number"==typeof e?e:0,this.rem=this.k1=this.len=0,this},r=new t,e.exports=t}()},function(e,t,r){"use strict";e.exports=class{constructor(e){this.id=e,this._index=[]}get(){return this._index}updateIndex(e,t){this._index=e.values}}},function(e,t,r){const n=r(3).EventEmitter,i=r(22),o=r(43),s=r(24),a=s.create("orbit-db.replicator",{color:s.Colors.Cyan});s.setLogLevel("ERROR");const c=e=>e.next,f=(e,t)=>e.concat(t),u=e=>null!==e&&void 0!==e,h=(e,t)=>(e[t]=t,e),d=1;e.exports=class extends n{constructor(e,t){super(),this._store=e,this._fetching={},this._stats={tasksRequested:0,tasksStarted:0,tasksProcessed:0,a:0,b:0,c:0,d:0},this._buffer=[],this._concurrency=t||128,this._queue={},this._q=new Set,this._flushTimer=setInterval(()=>{0===this.tasksRunning&&Object.keys(this._queue).length>0&&(a.error("Had to flush the queue!",Object.keys(this._queue).length,"items in the queue, ",this.tasksRequested,this.tasksFinished," tasks requested/finished"),setTimeout(()=>this._processQueue(),0))},3e3)}get tasksRequested(){return this._stats.tasksRequested}get tasksStarted(){return this._stats.tasksStarted}get tasksRunning(){return this._stats.tasksStarted-this._stats.tasksProcessed}get tasksQueued(){return Object.keys(this._queue).length-this.tasksRunning}get tasksFinished(){return this._stats.tasksProcessed}getQueue(){return Object.values(this._queue)}load(e){this._stats.a+=1;const t=e=>!this._store._oplog.has(e.hash||e)&&!this._queue[e.hash||e];try{e.filter(u).filter(t).forEach(this._addToQueue.bind(this)),setTimeout(()=>this._processQueue(),0)}catch(e){console.error(e)}this._stats.a--}_addToQueue(e){this._stats.b++;const t=e.hash||e;this._store._oplog.has(t)||this._fetching[t]||this._queue[t]?this._stats.b--:(this._stats.tasksRequested+=1,this._queue[t]=e,this._stats.b--)}async _processQueue(){if(this._stats.c++,this.tasksRunningdelete this._queue[e.hash||e]),i(t,e=>this._processOne(e)).then(e=>e.reduce(f,[]).reduce(h,{})).then(e=>{const r=Object.values(e).filter(u);if(t.length>0&&this._buffer.length>0||0===this.tasksRunning&&this._buffer.length>0){const e=this._buffer.slice();this._buffer=[],this.emit("load.end",e)}r.length>0&&this.load(r),this._stats.c--})}}async _processOne(e){this._stats.d++;const t=e.hash||e;if(this._store._oplog.has(t)||this._fetching[t])return void this._stats.d--;this._fetching[t]=t,this.emit("load.added",e),this._stats.tasksStarted+=1;const r=await o.fromEntryHash(this._store._ipfs,t,this._store._oplog.id,d,[],this._store.key,this._store.access.write);this._buffer.push(r);const n=r.values[0];return delete this._queue[t],this._stats.tasksProcessed+=1,this.emit("load.progress",this._id,t,n,null,this._buffer.length),this._stats.d--,r.values.map(c).reduce(f,[])}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index=null}get(){return this._index?this._index.values:[]}updateIndex(e){this._index=e}}},function(e,t,r){"use strict";const n=r(35),i=r(130);e.exports=class extends n{constructor(e,t,r,n){n||(n={}),n.Index||Object.assign(n,{Index:i}),super(e,t,r,n),this._type="feed"}remove(e){return this.del(e)}del(e){const t={op:"DEL",key:null,value:e};return this._addOperation(t)}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index={}}get(){return Object.keys(this._index).map(e=>this._index[e])}updateIndex(e){this._index={},e.values.reduce((e,t)=>(e.includes(t.hash)||(e.push(t.hash),"ADD"===t.payload.op?this._index[t.hash]=t:"DEL"===t.payload.op&&delete this._index[t.payload.value]),e),[])}}},function(e,t,r){"use strict";const n=r(20),i=r(132);e.exports=class extends n{constructor(e,t,r,n){let o=Object.assign({},{Index:i});Object.assign(o,n),super(e,t,r,o),this._type="keyvalue"}get(e){return this._index.get(e)}set(e,t){return this.put(e,t)}put(e,t){return this._addOperation({op:"PUT",key:e,value:t})}del(e){return this._addOperation({op:"DEL",key:e,value:null})}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index={}}get(e){return this._index[e]}updateIndex(e){e.values.slice().reverse().reduce((e,t)=>(e.includes(t.payload.key)||(e.push(t.payload.key),"PUT"===t.payload.op?this._index[t.payload.key]=t.payload.value:"DEL"===t.payload.op&&delete this._index[t.payload.key]),e),[])}}},function(e,t,r){"use strict";const n=r(20),i=r(134),o=r(55);e.exports=class extends n{constructor(e,t,r,n={}){n.Index||Object.assign(n,{Index:i}),super(e,t,r,n),this._type="counter"}get value(){return this._index.get().value}inc(e){const t=new o(this.id,Object.assign({},this._index.get()._counters));return t.increment(e),this._addOperation({op:"COUNTER",key:null,value:t.toJSON()})}}},function(e,t,r){"use strict";const n=r(55);e.exports=class{constructor(e){this._index=new n(e)}get(){return this._index}updateIndex(e){this._index&&e.values.filter(e=>e&&"COUNTER"===e.payload.op).map(e=>n.from(e.payload.value)).forEach(e=>this._index.merge(e))}}},function(e,t,r){"use strict";t.deepEqual=((e,t)=>{const r=Object.getOwnPropertyNames(e),n=Object.getOwnPropertyNames(t);if(r.length!==n.length)return!1;for(let n=0;ne.toString().split(t).join(r));e.exports=class extends n{constructor(e,t,r,n){n||(n={}),n.indexBy||Object.assign(n,{indexBy:"_id"}),n.Index||Object.assign(n,{Index:i}),super(e,t,r,n),this._type="docstore"}get(e,t=!1){const r=(e=e.toString()).split(" ");return e=r.length>1?s(e,"."," ").toLowerCase():e.toLowerCase(),Object.keys(this._index._index).filter(n=>t?-1!==n.indexOf(e):(t=>r.length>1?-1!==s(t,"."," ").toLowerCase().indexOf(e):-1!==t.toLowerCase().indexOf(e))(n)).map(e=>this._index.get(e))}query(e){return Object.keys(this._index._index).map(e=>this._index.get(e)).filter(t=>e(t))}batchPut(e,t){return o(e,(r,n)=>this._addOperationBatch({op:"PUT",key:r[this.options.indexBy],value:r},!0,n===e.length-1,t),{concurrency:1}).then(()=>this.saveSnapshot())}put(e){if(!e[this.options.indexBy])throw new Error(`The provided document doesn't contain field '${this.options.indexBy}'`);return this._addOperation({op:"PUT",key:e[this.options.indexBy],value:e})}del(e){if(!this._index.get(e))throw new Error(`No entry with key '${e}' in the database`);return this._addOperation({op:"DEL",key:e,value:null})}}},function(e,t,r){"use strict";e.exports=class{constructor(){this._index={}}get(e){return this._index[e]}updateIndex(e,t){e.values.slice().reverse().reduce((e,r,n)=>(!0!==e[r.payload.key]&&(e[r.payload.key]=!0,"PUT"===r.payload.op?this._index[r.payload.key]=r.payload.value:"DEL"===r.payload.op&&delete this._index[r.payload.key]),t&&t(r,n),e),{})}}},function(e,t,r){"use strict";e.exports=((e,t,r)=>new Promise((n,i)=>{const o=(r=Object.assign({concurrency:1/0},r)).concurrency;if(o<1)throw new TypeError("Expected `concurrency` to be a number from 1 and up");const s=[],a=e[Symbol.iterator]();let c=!1,f=!1,u=0,h=0;const d=()=>{if(c)return;const e=a.next(),r=h;if(h++,e.done)return f=!0,void(0===u&&n(s));u++,Promise.resolve(e.value).then(e=>t(e,r)).then(e=>{s[r]=e,u--,d()},e=>{c=!0,i(e)})};for(let e=0;e{o.error("Pubsub Error:",e)}),i.on("message",e=>{this._handleMessage(e)}),i.on("peer joined",t=>{o.debug("Peer connected:",e,e===i._topic),this._subscriptions[e]?this._subscriptions[e].onNewPeer(e,t,i):(o.warn("Peer joined a room we don't have a subscription for"),o.warn(t,i._topic,e))}),i.on("subscribed",()=>{this._subscriptions[e]={room:i,onMessage:t,onNewPeer:r},a++,o.debug("Topics open:",a)})}}unsubscribe(e){this._subscriptions[e]&&(this._subscriptions[e].room.leave(),this._subscriptions[e].room=null,delete this._subscriptions[e],o.debug(`Unsubscribed from '${e}'`),a--,o.debug("Topics open:",a))}publish(e,r){this._subscriptions[e]&&this._subscriptions[e].room&&this._ipfs.pubsub&&this._subscriptions[e].room.broadcast(t.from(JSON.stringify(r)))}disconnect(){Object.keys(this._subscriptions).forEach(e=>this.unsubscribe(e)),this._subscriptions={}}_handleMessage(e){if(e.from===this._id)return;let t,r,n;try{n=e.topicIDs[0],t=JSON.parse(e.data),r=this._subscriptions[n]}catch(t){o.error(t),o.error("Couldn't parse pubsub message:",e)}r&&r.onMessage&&t&&r.onMessage(n,t)}}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";const n=r(142),i=r(3),o=r(40),s=r(56),a=r(9).Buffer,c=r(57),f=r(147),u=r(63),h=r(170),d={pollInterval:1e3};e.exports=((e,t,r)=>new class extends i{constructor(e,t,r){if(super(),this._ipfs=e,this._topic=t,this._options=Object.assign({},s(d),s(r)),this._peers=[],this._connections={},this._handleDirectMessage=this._handleDirectMessage.bind(this),!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(e){return this._peers.indexOf(e)>=0}leave(){o.clearInterval(),Object.keys(this._connections).forEach(e=>{this._connections[e].stop()}),h.emitter.removeListener(this._topic,this._handleDirectMessage),this.emit("stop")}broadcast(e){let t=u(e);this._ipfs.pubsub.publish(this._topic,t,e=>{e&&this.emit("error",e)})}sendTo(e,t){let r=this._connections[e];r||((r=new f(e,this._ipfs,this)).on("error",e=>this.emit("error",e)),this._connections[e]=r,r.once("disconnect",()=>{delete this._connections[e],this._peers=this._peers.filter(t=>t!==e),this.emit("peer left",e)}));const n=a.from([0]),i={to:e,from:this._ipfs._peerInfo.id.toB58String(),data:a.from(t).toString("hex"),seqno:n.toString("hex"),topicIDs:[this._topic],topicCIDs:[this._topic]};r.push(a.from(JSON.stringify(i)))}_start(){this._interval=o.setInterval(this._pollPeers.bind(this),this._options.pollInterval);const e=this._onMessage.bind(this);this._ipfs.pubsub.subscribe(this._topic,e,e=>{e?this.emit("error",e):this.emit("subscribed",this._topic)}),this.once("stop",()=>{this._ipfs.pubsub.unsubscribe(this._topic,e)}),this._ipfs._libp2pNode.handle(c,h.handler),h.emitter.on(this._topic,this._handleDirectMessage)}_pollPeers(){this._ipfs.pubsub.peers(this._topic,(e,t)=>{if(e)return void this.emit("error",e);const r=t.sort();this._emitChanges(r)&&(this._peers=r)})}_emitChanges(e){const t=n(this._peers,e);return t.added.forEach(e=>this.emit("peer joined",e)),t.removed.forEach(e=>this.emit("peer left",e)),t.added.length>0||t.removed.length>0}_onMessage(e){this.emit("message",e)}_handleDirectMessage(e){if(e.to===this._ipfs._peerInfo.id.toB58String()){const t=Object.assign({},e);delete t.to,this.emit("message",t)}}}(e,t,r))},function(e,t,r){"use strict";function n(e,t,r){return e.indexOf(t)}function i(e,t,r){return e.findIndex(function(e){return function(e,t,r){return r.every(r=>t[r]===e[r])}(e,t,r)})}const o=r(56),s=r(143)("hyperdiff"),a=r(146),c=e=>-1!==e;e.exports=function(e,t,r){const{first:f,second:u}=function(e,t){return{first:e,second:o(t)}}(e,t),h=function(e){return e?i:n}(r);s("preconditions first=%j second=%j findIndex=%s",f,u,h.name);const d=f.reduce(function(e,t,n){const i=h(u,t,r),o=c(i)?"common":"removed";return e[o].push(t),a(u,i),s("index=%s value=%s collection=%s",n,t,o),e},{common:[],removed:[]});return d.added=u,s("added=%j removed=%j common%j",d.added,d.removed,d.common),d}},function(e,t,r){(function(n){function i(){var e;try{e=t.storage.debug}catch(e){}return!e&&void 0!==n&&"env"in n&&(e=Object({NODE_ENV:void 0}).DEBUG),e}(t=e.exports=r(144)).log=function(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)},t.formatArgs=function(e){var r=this.useColors;if(e[0]=(r?"%c":"")+this.namespace+(r?" %c":" ")+e[0]+(r?"%c ":" ")+"+"+t.humanize(this.diff),r){var n="color: "+this.color;e.splice(1,0,n,"color: inherit");var i=0,o=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(i++,"%c"===e&&(o=i))}),e.splice(o,0,n)}},t.save=function(e){try{null==e?t.storage.removeItem("debug"):t.storage.debug=e}catch(e){}},t.load=i,t.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+)/))},t.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),t.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"],t.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},t.enable(i())}).call(t,r(0))},function(e,t,r){function n(e){function r(){if(r.enabled){var e=r,i=+new Date,o=i-(n||i);e.diff=o,e.prev=n,e.curr=i,n=i;for(var s=new Array(arguments.length),a=0;a0)return function(e){if(!((e=String(e)).length>100)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return r*a;case"days":case"day":case"d":return r*s;case"hours":case"hour":case"hrs":case"hr":case"h":return r*o;case"minutes":case"minute":case"mins":case"min":case"m":return r*i;case"seconds":case"second":case"secs":case"sec":case"s":return r*n;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}(e);if("number"===c&&!1===isNaN(e))return t.long?function(e){return r(e,s,"day")||r(e,o,"hour")||r(e,i,"minute")||r(e,n,"second")||e+" ms"}(e):function(e){return e>=s?Math.round(e/s)+"d":e>=o?Math.round(e/o)+"h":e>=i?Math.round(e/i)+"m":e>=n?Math.round(e/n)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},function(e,t,r){(function(t){function r(e,t){for(var r=-1,n=t.length,i=e.length;++r0&&n(f)?t>1?c(f,t-1,n,i,o):r(o,f):i||(o[o.length]=f)}return o}function f(e,t){for(var r=0,n=(t=m(t,e)?[t]:d(t)).length;null!=e&&ri?0:i+t);(r=r>i?i:r)<0&&(r+=i);i=t>r?0:r-t>>>0,t>>>=0;var o=Array(i);for(;++nt||o&&s&&c&&!a&&!f||n&&s&&c||!r&&c||!i)return 1;if(!n&&!o&&!f&&e-1&&e%1==0&&e<=I}(e.length)&&!w(e)}(e)}(e)&&$.call(e,"callee")&&(!ee.call(e,"callee")||X.call(e)==N)}(e)||!!(re&&e&&e[re])}function g(e,t){return!!(t=null==t?I:t)&&("number"==typeof e||F.test(e))&&e>-1&&e%1==0&&e-1},i.prototype.set=function(e,t){var r=this.__data__,n=s(r,e);return n<0?r.push([e,t]):r[n][1]=t,this},o.prototype.clear=function(){this.__data__={hash:new n,map:new(ie||i),string:new n}},o.prototype.delete=function(e){return p(this,e).delete(e)},o.prototype.get=function(e){return p(this,e).get(e)},o.prototype.has=function(e){return p(this,e).has(e)},o.prototype.set=function(e,t){return p(this,e).set(e,t),this};var ce=_(function(e){e=x(e);var t=[];return L.test(e)&&t.push(""),e.replace(B,function(e,r,n,i){t.push(n?i.replace(D,"$1"):r||e)}),t}),fe=function(e,t){return t=ne(void 0===t?e.length-1:t,0),function(){for(var r=arguments,n=-1,i=ne(r.length-t,0),o=Array(i);++nthis.push(e)),this._getConnection())}stop(){this._connection&&this._connection.end()}_getConnection(){this._connecting=!0,this._getPeerAddresses(this._id,(e,t)=>{e?this.emit("error",e):t.length?this._ipfs._libp2pNode.dial(t[0],s,(e,t)=>{if(e)return void this.emit("error",e);this._connecting=!1;const r=o(!1,e=>{this._closed=!0,e&&this.emit("error",e)});this._connection=r,i(r,t,i.onEnd(e=>{delete this._connection,e&&!this._closed&&this.emit("error",e)})),this.emit("connect",r)}):this.emit("error",new Error("could not connect to "+this._id))})}_getPeerAddresses(e,t){this._ipfs.swarm.peers((r,n)=>{r?t(r):t(null,n.filter(t=>t.peer.id.toB58String()===e).map(e=>e.peer))})}}},function(e,t,r){"use strict";e.exports={keys:r(149),once:r(60),values:r(30),count:r(150),infinite:r(151),empty:r(152),error:r(153)}},function(e,t,r){"use strict";var n=r(30);e.exports=function(e){return n(Object.keys(e))}},function(e,t,r){"use strict";e.exports=function(e){var t=0;return e=e||1/0,function(r,n){return r?n&&n(r):t>e?n(!0):void n(null,t++)}}},function(e,t,r){"use strict";e.exports=function(e){return e=e||Math.random,function(t,r){return t?r&&r(t):r(null,e())}}},function(e,t,r){"use strict";e.exports=function(){return function(e,t){t(!0)}}},function(e,t,r){"use strict";e.exports=function(e){return function(t,r){r(e)}}},function(e,t,r){"use strict";e.exports={drain:r(17),onEnd:r(155),log:r(156),find:r(157),reduce:r(31),collect:r(158),concat:r(159)}},function(e,t,r){"use strict";var n=r(17);e.exports=function(e){return n(null,e)}},function(e,t,r){"use strict";var n=r(17);e.exports=function(e){return n(function(e){console.log(e)},e)}},function(e,t,r){"use strict";function n(e){return e}var i=r(18),o=r(17);e.exports=function(e,t){var r=!1;return t?e=i(e)||n:(t=e,e=n),o(function(n){if(e(n))return r=!0,t(null,n),!1},function(e){r||t(!0===e?null:e,null)})}},function(e,t,r){"use strict";var n=r(31);e.exports=function(e){return n(function(e,t){return e.push(t),e},[],e)}},function(e,t,r){"use strict";var n=r(31);e.exports=function(e){return n(function(e,t){return e+t},"",e)}},function(e,t,r){"use strict";e.exports={map:r(161),asyncMap:r(162),filter:r(32),filterNot:r(163),through:r(164),take:r(165),unique:r(62),nonUnique:r(166),flatten:r(167)}},function(e,t,r){"use strict";function n(e){return e}var i=r(18);e.exports=function(e){return e?(e=i(e),function(t){return function(r,n){t(r,function(r,i){try{i=r?null:e(i)}catch(e){return t(e,function(){return n(e)})}n(r,i)})}}):n}},function(e,t,r){"use strict";function n(e){return e}var i=r(18);e.exports=function(e){if(!e)return n;e=i(e);var t,r,o=!1;return function(n){return function i(s,a){if(r)return a(r);s?(r=s,n(s,o?function(){o?t=a:a(s)}:a)):n(null,function(n,s){n?a(n):r?a(r):(o=!0,e(s,function(e,n){o=!1,r?(a(r),t(r)):e?i(e,a):a(null,n)}))})}}}},function(e,t,r){"use strict";var n=r(61),i=r(32);e.exports=function(e){return e=n(e),i(function(t){return!e(t)})}},function(e,t,r){"use strict";e.exports=function(e,t){function r(e){!n&&t&&(n=!0,t(!0===e?null:e))}var n=!1;return function(t){return function(n,i){return n&&r(n),t(n,function(t,n){t?r(t):e&&e(n),i(t,n)})}}}},function(e,t,r){"use strict";e.exports=function(e,t){var r=(t=t||{}).last||!1,n=!1;if("number"==typeof e){r=!0;var i=e;e=function(){return--i}}return function(t){function i(e){t(!0,function(t){r=!1,e(t||!0)})}return function(o,s){n?r?i(s):s(n):(n=o)?t(n,s):t(null,function(t,o){(n=n||t)?s(n):e(o)?s(null,o):(n=!0,r?s(null,o):i(s))})}}}},function(e,t,r){"use strict";var n=r(62);e.exports=function(e){return n(e,!0)}},function(e,t,r){"use strict";var n=r(30),i=r(60);e.exports=function(){return function(e){var t;return function(r,o){function s(){t(null,function(t,r){!0===t?a():t?e(!0,function(e){o(t)}):o(null,r)})}function a(){t=null,e(null,function(e,r){if(e)return o(e);Array.isArray(r)||r&&"object"==typeof r?r=n(r):"function"!=typeof r&&(r=i(r)),t=r,s()})}r?t?t(r,function(t){e(t||r,o)}):e(r,o):t?s():a()}}}},function(e,t,r){"use strict";e.exports=function e(t){var r=arguments.length;if("function"==typeof t&&1===t.length){for(var n=new Array(r),i=0;i{if(e)return void console.log(e);const s=r.id.toB58String();n(t,n.map(e=>{let t;try{t=JSON.parse(e.toString())}catch(e){return void o.emit("warning",e.message)}if(s!==t.from)return void o.emit("warning","no peerid match "+t.from);const r=t.topicIDs;if(Array.isArray(r))return t.data=i.from(t.data,"hex"),t.seqno=i.from(t.seqno,"hex"),r.forEach(e=>{o.emit(e,t)}),t;o.emit("warning","no topic IDs")}),n.onEnd(()=>{}))})},emitter:o}},function(e,t,r){"use strict";const n=r(12),i=r(14),o=r(172);let s={};class a{static async load(e,t){const r=n.join(t.root,t.path),i=n.join(e,r);let o=s[i];return o||(o=new a(i,t.toString()),s[i]=o,await o.load()),o}static async close(){return Promise.all(Object.values(s),e=>e.close()).then(()=>s={})}constructor(e,t){this.path=e||"./orbitdb",this.id=t,this._store=null,this._cache={}}async close(){this._store&&await this._store.close(),this._store=null}async get(e){return this._store||await this.load(),new Promise((t,r)=>{this._store.get(e,(e,n)=>{if(e&&-1===e.toString().indexOf("NotFoundError: Key not found in database"))return r(e);t(n?JSON.parse(n):null)})})}async set(e,t){return this._store||await this.load(),this._store.put(e,JSON.stringify(t))}async del(e){return this._store||await this.load(),new Promise((t,r)=>{this._store.del(e,(e,n)=>{if(e&&-1===e.toString().indexOf("NotFoundError: Key not found in database"))return r(e);t()})})}async load(){return new Promise((e,t)=>{i&&i.sync&&i.sync(this.path),o(this.path,(t,r)=>{this._store=r,e()})})}}e.exports=a},function(e,t,r){e.exports=r(173)(r(186))},function(e,t,r){const n=r(174),i=r(183);e.exports=function(e){function t(t,r,o){return"function"==typeof r&&(o=r),"object"==typeof r&&null!==r||(r={}),n(i(e(t),r),r,o)}return["destroy","repair"].forEach(function(r){"function"==typeof e[r]&&(t[r]=function(t,n){e[r](t,n||function(){})})}),t.errors=n.errors,t}},function(e,t,r){(function(t){function n(e,r,i){if(!(this instanceof n))return new n(e,r,i);var s;if(a.call(this),this.setMaxListeners(1/0),"function"==typeof r&&(i=r,r={}),r=r||{},!e||"object"!=typeof e){if(s=new _("Must provide db"),"function"==typeof i)return t.nextTick(i,s);throw s}p.equal(typeof e.status,"string",".status required, old abstract-leveldown"),this.options=o(r),this._db=e,this.db=new u(e),this.open(i)}function i(e,t){return"function"==typeof e?e:t}function o(e){return"object"==typeof e&&null!==e?e:{}}function s(e,r){if(!e._isOpening()&&!e.isOpen())return t.nextTick(r,new g("Database is not open")),!0}var a=r(3).EventEmitter,c=r(6).inherits,f=r(33),u=r(175),h=r(178),d=r(179),l=r(34),p=r(53),b=r(67),y=l.WriteError,g=l.ReadError,m=l.NotFoundError,v=l.OpenError,_=l.InitializationError;n.prototype.emit=a.prototype.emit,n.prototype.once=a.prototype.once,c(n,a),n.prototype.open=function(e){var r,n=this;return e||(r=(e=b()).promise),this.isOpen()?(t.nextTick(e,null,n),r):this._isOpening()?(this.once("open",function(){e(null,n)}),r):(this.emit("opening"),this.db.open(this.options,function(t){if(t)return e(new v(t));n.db=n._db,e(null,n),n.emit("open"),n.emit("ready")}),r)},n.prototype.close=function(e){var r,n=this;return e||(r=(e=b()).promise),this.isOpen()?(this.db.close(function(){n.emit("closed"),e.apply(null,arguments)}),this.emit("closing"),this.db=new u(this._db)):this.isClosed()?t.nextTick(e):"closing"===this.db.status?this.once("closed",e):this._isOpening()&&this.once("open",function(){n.close(e)}),r},n.prototype.isOpen=function(){return"open"===this.db.status},n.prototype._isOpening=function(){return"opening"===this.db.status},n.prototype.isClosed=function(){return/^clos|new/.test(this.db.status)},n.prototype.get=function(e,t,r){if(null===e||void 0===e)throw new g("get() requires a key argument");var n;return(r=i(t,r))||(n=(r=b()).promise),s(this,r)?n:(t=o(t),this.db.get(e,t,function(t,n){if(t)return t=/notfound/i.test(t)||t.notFound?new m("Key not found in database ["+e+"]",t):new g(t),r(t);r(null,n)}),n)},n.prototype.put=function(e,t,r,n){if(null===e||void 0===e)throw new y("put() requires a key argument");var a,c=this;return(n=i(r,n))||(a=(n=b()).promise),s(this,n)?a:(r=o(r),this.db.put(e,t,r,function(r){if(r)return n(new y(r));c.emit("put",e,t),n()}),a)},n.prototype.del=function(e,t,r){if(null===e||void 0===e)throw new y("del() requires a key argument");var n,a=this;return(r=i(t,r))||(n=(r=b()).promise),s(this,r)?n:(t=o(t),this.db.del(e,t,function(t){if(t)return r(new y(t));a.emit("del",e),r()}),n)},n.prototype.batch=function(e,t,r){if(!arguments.length)return new d(this);if(!Array.isArray(e))throw new y("batch() requires an array argument");var n,a=this;return(r=i(t,r))||(n=(r=b()).promise),s(this,r)?n:(t=o(t),e=e.map(function(e){return e.type||void 0===e.key||void 0===e.value||(e.type="put"),e}),this.db.batch(e,t,function(t){if(t)return r(new y(t));a.emit("batch",e),r()}),n)},n.prototype.readStream=n.prototype.createReadStream=function(e){return"number"!=typeof(e=f({keys:!0,values:!0},e)).limit&&(e.limit=-1),new h(this.db.iterator(e),e)},n.prototype.keyStream=n.prototype.createKeyStream=function(e){return this.createReadStream(f(e,{keys:!0,values:!1}))},n.prototype.valueStream=n.prototype.createValueStream=function(e){return this.createReadStream(f(e,{keys:!1,values:!0}))},n.prototype.toString=function(){return"LevelUP"},n.errors=l,e.exports=n.default=n}).call(t,r(0))},function(e,t,r){(function(t){function n(e){s.call(this,""),this._db=e,this._operations=[],this._iterators=[]}function i(e){c.forEach(function(t){e["_"+t]=function(){this._operations.push({method:t,args:arguments})}}),e._iterator=function(e){var t=new a(e);return this._iterators.push(t),t}}var o=r(6),s=r(19).AbstractLevelDOWN,a=r(177),c="put get del batch approximateSize".split(" ");o.inherits(n,s),n.prototype._open=function(e,t){var r=this;this._db.open(e,function(e){if(e)return t(e);r._operations.forEach(function(e){r._db[e.method].apply(r._db,e.args)}),r._operations=[],r._iterators.forEach(function(e){e.setDb(r._db)}),r._iterators=[],function(e){c.concat("iterator").forEach(function(t){e["_"+t]=function(){return this._db[t].apply(this._db,arguments)}})}(r),t()})},n.prototype._close=function(e){var t=this;this._db.close(function(r){if(r)return e(r);i(t),e()})},i(n.prototype),n.prototype._isBuffer=function(e){return t.isBuffer(e)},n.prototype._serializeKey=function(e){return e},n.prototype._serializeValue=function(e){return e},e.exports=n,e.exports.DeferredIterator=a}).call(t,r(1).Buffer)},function(e,t,r){var n=r(64);e.exports=function(e){return!(!e||"object"!=typeof e)&&Object.keys(n.prototype).filter(function(e){return"_"!=e[0]&&"approximateSize"!=e}).every(function(t){return"function"==typeof e[t]})}},function(e,t,r){function n(e){o.call(this,e),this._options=e,this._iterator=null,this._operations=[]}var i=r(6),o=r(19).AbstractIterator;i.inherits(n,o),n.prototype.setDb=function(e){var t=this._iterator=e.iterator(this._options);this._operations.forEach(function(e){t[e.method].apply(t,e.args)})},n.prototype._operation=function(e,t){if(this._iterator)return this._iterator[e].apply(this._iterator,t);this._operations.push({method:e,args:t})},"next end".split(" ").forEach(function(e){n.prototype["_"+e]=function(){this._operation(e,arguments)}}),e.exports=n},function(e,t,r){function n(e,t){if(!(this instanceof n))return new n(e,t);t=t||{},o.call(this,s(t,{objectMode:!0})),this._iterator=e,this._destroyed=!1,this._options=t,this.on("end",this._cleanup.bind(this))}var i=r(4),o=r(13).Readable,s=r(33);e.exports=n,i(n,o),n.prototype._read=function(){var e=this,t=this._options;this._destroyed||this._iterator.next(function(r,n,i){if(!e._destroyed)return r?e.emit("error",r):void(void 0===n&&void 0===i?e.push(null):!1!==t.keys&&!1===t.values?e.push(n):!1===t.keys&&!1!==t.values?e.push(i):e.push({key:n,value:i}))})},n.prototype.destroy=n.prototype._cleanup=function(){var e=this;this._destroyed||(this._destroyed=!0,this._iterator.end(function(t){if(t)return e.emit("error",t);e.emit("close")}))}},function(e,t,r){function n(e){this._levelup=e,this.batch=e.db.batch(),this.ops=[],this.length=0}var i=r(34).WriteError,o=r(67);n.prototype.put=function(e,t){try{this.batch.put(e,t)}catch(e){throw new i(e)}return this.ops.push({type:"put",key:e,value:t}),this.length++,this},n.prototype.del=function(e){try{this.batch.del(e)}catch(e){throw new i(e)}return this.ops.push({type:"del",key:e}),this.length++,this},n.prototype.clear=function(){try{this.batch.clear()}catch(e){throw new i(e)}return this.ops=[],this.length=0,this},n.prototype.write=function(e){var t,r=this._levelup,n=this.ops;e||(t=(e=o()).promise);try{this.batch.write(function(t){if(t)return e(new i(t));r.emit("batch",n),e()})}catch(e){throw new i(e)}return t},e.exports=n},function(e,t,r){var n=e.exports.all=[{errno:-2,code:"ENOENT",description:"no such file or directory"},{errno:-1,code:"UNKNOWN",description:"unknown error"},{errno:0,code:"OK",description:"success"},{errno:1,code:"EOF",description:"end of file"},{errno:2,code:"EADDRINFO",description:"getaddrinfo error"},{errno:3,code:"EACCES",description:"permission denied"},{errno:4,code:"EAGAIN",description:"resource temporarily unavailable"},{errno:5,code:"EADDRINUSE",description:"address already in use"},{errno:6,code:"EADDRNOTAVAIL",description:"address not available"},{errno:7,code:"EAFNOSUPPORT",description:"address family not supported"},{errno:8,code:"EALREADY",description:"connection already in progress"},{errno:9,code:"EBADF",description:"bad file descriptor"},{errno:10,code:"EBUSY",description:"resource busy or locked"},{errno:11,code:"ECONNABORTED",description:"software caused connection abort"},{errno:12,code:"ECONNREFUSED",description:"connection refused"},{errno:13,code:"ECONNRESET",description:"connection reset by peer"},{errno:14,code:"EDESTADDRREQ",description:"destination address required"},{errno:15,code:"EFAULT",description:"bad address in system call argument"},{errno:16,code:"EHOSTUNREACH",description:"host is unreachable"},{errno:17,code:"EINTR",description:"interrupted system call"},{errno:18,code:"EINVAL",description:"invalid argument"},{errno:19,code:"EISCONN",description:"socket is already connected"},{errno:20,code:"EMFILE",description:"too many open files"},{errno:21,code:"EMSGSIZE",description:"message too long"},{errno:22,code:"ENETDOWN",description:"network is down"},{errno:23,code:"ENETUNREACH",description:"network is unreachable"},{errno:24,code:"ENFILE",description:"file table overflow"},{errno:25,code:"ENOBUFS",description:"no buffer space available"},{errno:26,code:"ENOMEM",description:"not enough memory"},{errno:27,code:"ENOTDIR",description:"not a directory"},{errno:28,code:"EISDIR",description:"illegal operation on a directory"},{errno:29,code:"ENONET",description:"machine is not on the network"},{errno:31,code:"ENOTCONN",description:"socket is not connected"},{errno:32,code:"ENOTSOCK",description:"socket operation on non-socket"},{errno:33,code:"ENOTSUP",description:"operation not supported on socket"},{errno:34,code:"ENOENT",description:"no such file or directory"},{errno:35,code:"ENOSYS",description:"function not implemented"},{errno:36,code:"EPIPE",description:"broken pipe"},{errno:37,code:"EPROTO",description:"protocol error"},{errno:38,code:"EPROTONOSUPPORT",description:"protocol not supported"},{errno:39,code:"EPROTOTYPE",description:"protocol wrong type for socket"},{errno:40,code:"ETIMEDOUT",description:"connection timed out"},{errno:41,code:"ECHARSET",description:"invalid Unicode character"},{errno:42,code:"EAIFAMNOSUPPORT",description:"address family for hostname not supported"},{errno:44,code:"EAISERVICE",description:"servname not supported for ai_socktype"},{errno:45,code:"EAISOCKTYPE",description:"ai_socktype not supported"},{errno:46,code:"ESHUTDOWN",description:"cannot send after transport endpoint shutdown"},{errno:47,code:"EEXIST",description:"file already exists"},{errno:48,code:"ESRCH",description:"no such process"},{errno:49,code:"ENAMETOOLONG",description:"name too long"},{errno:50,code:"EPERM",description:"operation not permitted"},{errno:51,code:"ELOOP",description:"too many symbolic links encountered"},{errno:52,code:"EXDEV",description:"cross-device link not permitted"},{errno:53,code:"ENOTEMPTY",description:"directory not empty"},{errno:54,code:"ENOSPC",description:"no space left on device"},{errno:55,code:"EIO",description:"i/o error"},{errno:56,code:"EROFS",description:"read-only file system"},{errno:57,code:"ENODEV",description:"no such device"},{errno:58,code:"ESPIPE",description:"invalid seek"},{errno:59,code:"ECANCELED",description:"operation canceled"}];e.exports.errno={},e.exports.code={},n.forEach(function(t){e.exports.errno[t.errno]=t,e.exports.code[t.code]=t}),e.exports.custom=r(181)(e.exports),e.exports.create=e.exports.custom.createError},function(e,t,r){function n(e,t,r){o(this,{type:e,name:e,cause:"string"!=typeof t?t:r,message:t&&"string"!=typeof t?t.message:t},"ewr")}function i(e,t){Error.call(this),Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor),n.call(this,"CustomError",e,t)}var o=r(182);i.prototype=new Error,e.exports=function(e){var t=function(t,r){return function(e,t,r){var o=function(r,i){n.call(this,t,r,i),"FilesystemError"==t&&(this.code=this.cause.code,this.path=this.cause.path,this.errno=this.cause.errno,this.message=(e.errno[this.cause.errno]?e.errno[this.cause.errno].description:this.cause.message)+(this.cause.path?" ["+this.cause.path+"]":"")),Error.call(this),Error.captureStackTrace&&Error.captureStackTrace(this,o)};return o.prototype=r?new r:new i,o}(e,t,r)};return{CustomError:i,FilesystemError:t("FilesystemError"),createError:t}}},function(e,t){!function(t,r,n){void 0!==e&&e.exports?e.exports=n():r.prr=n()}(0,this,function(){var e="function"==typeof Object.defineProperty?function(e,t,r){return Object.defineProperty(e,t,r),e}:function(e,t,r){return e[t]=r.value,e};return function(t,r,n,i){var o;if(i=function(e,t){var r="object"==typeof t,n=!r&&"string"==typeof t,i=function(e){return r?!!t[e]:!!n&&t.indexOf(e[0])>-1};return{enumerable:i("enumerable"),configurable:i("configurable"),writable:i("writable"),value:e}}(n,i),"object"==typeof r){for(o in r)Object.hasOwnProperty.call(r,o)&&(i.value=r[o],e(t,o,i));return t}return e(t,r,i)}})},function(e,t,r){"use strict";function n(e,t){if(!(this instanceof n))return new n(e,t);s.call(this,""),void 0===(t=t||{}).keyEncoding&&(t.keyEncoding="utf8"),void 0===t.valueEncoding&&(t.valueEncoding="utf8"),this.db=e,this.codec=new u(t)}function i(e,t){c.call(this,e),this.codec=e.codec,this.keys=t.keys,this.values=t.values,this.opts=this.codec.encodeLtgt(t),this.it=e.db.iterator(this.opts)}function o(e,t){a.call(this,e),this.codec=e.codec,this.batch=e.db.batch()}var s=r(19).AbstractLevelDOWN,a=r(19).AbstractChainedBatch,c=r(19).AbstractIterator,f=r(6).inherits,u=r(184),h=r(34).EncodingError;e.exports=n.default=n,f(n,s),n.prototype._serializeKey=n.prototype._serializeValue=function(e){return e},n.prototype._open=function(e,t){this.db.open(e,t)},n.prototype._close=function(e){this.db.close(e)},n.prototype._put=function(e,t,r,n){e=this.codec.encodeKey(e,r),t=this.codec.encodeValue(t,r),this.db.put(e,t,r,n)},n.prototype._get=function(e,t,r){var n=this;e=this.codec.encodeKey(e,t),t.asBuffer=this.codec.valueAsBuffer(t),this.db.get(e,t,function(e,i){if(e)return r(e);try{i=n.codec.decodeValue(i,t)}catch(e){return r(new h(e))}r(null,i)})},n.prototype._del=function(e,t,r){e=this.codec.encodeKey(e,t),this.db.del(e,t,r)},n.prototype._chainedBatch=function(){return new o(this)},n.prototype._batch=function(e,t,r){e=this.codec.encodeBatch(e,t),this.db.batch(e,t,r)},n.prototype._iterator=function(e){return e.keyAsBuffer=this.codec.keyAsBuffer(e),e.valueAsBuffer=this.codec.valueAsBuffer(e),new i(this,e)},n.prototype.approximateSize=function(e,t,r,n){return this.db.approximateSize(e,t,r,n)},f(i,c),i.prototype._next=function(e){var t=this;this.it.next(function(r,n,i){if(r)return e(r);try{n=t.keys&&void 0!==n?t.codec.decodeKey(n,t.opts):void 0,i=t.values&&void 0!==i?t.codec.decodeValue(i,t.opts):void 0}catch(r){return e(new h(r))}e(null,n,i)})},i.prototype._end=function(e){this.it.end(e)},f(o,a),o.prototype._put=function(e,t){e=this.codec.encodeKey(e),t=this.codec.encodeValue(t),this.batch.put(e,t)},o.prototype._del=function(e){e=this.codec.encodeKey(e),this.batch.del(e)},o.prototype._clear=function(){this.batch.clear()},o.prototype._write=function(e,t){this.batch.write(e,t)}},function(e,t,r){function n(e){this.opts=e||{},this.encodings=i}var i=r(185);e.exports=n,n.prototype._encoding=function(e){return"string"==typeof e&&(e=i[e]),e||(e=i.id),e},n.prototype._keyEncoding=function(e,t){return this._encoding(t&&t.keyEncoding||e&&e.keyEncoding||this.opts.keyEncoding)},n.prototype._valueEncoding=function(e,t){return this._encoding(t&&(t.valueEncoding||t.encoding)||e&&(e.valueEncoding||e.encoding)||this.opts.valueEncoding||this.opts.encoding)},n.prototype.encodeKey=function(e,t,r){return this._keyEncoding(t,r).encode(e)},n.prototype.encodeValue=function(e,t,r){return this._valueEncoding(t,r).encode(e)},n.prototype.decodeKey=function(e,t){return this._keyEncoding(t).decode(e)},n.prototype.decodeValue=function(e,t){return this._valueEncoding(t).decode(e)},n.prototype.encodeBatch=function(e,t){var r=this;return e.map(function(e){var n={type:e.type,key:r.encodeKey(e.key,t,e)};return r.keyAsBuffer(t,e)&&(n.keyEncoding="binary"),e.prefix&&(n.prefix=e.prefix),"value"in e&&(n.value=r.encodeValue(e.value,t,e),r.valueAsBuffer(t,e)&&(n.valueEncoding="binary")),n})};var o=["lt","gt","lte","gte","start","end"];n.prototype.encodeLtgt=function(e){var t=this,r={};return Object.keys(e).forEach(function(n){r[n]=o.indexOf(n)>-1?t.encodeKey(e[n],e):e[n]}),r},n.prototype.createStreamDecoder=function(e){var t=this;return e.keys&&e.values?function(r,n){return{key:t.decodeKey(r,e),value:t.decodeValue(n,e)}}:e.keys?function(r){return t.decodeKey(r,e)}:e.values?function(r,n){return t.decodeValue(n,e)}:function(){}},n.prototype.keyAsBuffer=function(e){return this._keyEncoding(e).buffer},n.prototype.valueAsBuffer=function(e){return this._valueEncoding(e).buffer}},function(e,t,r){(function(e){function r(e){return e}function n(t){return void 0===t||null===t||e.isBuffer(t)}t.utf8=t["utf-8"]={encode:function(e){return n(e)?e:String(e)},decode:r,buffer:!1,type:"utf8"},t.json={encode:JSON.stringify,decode:JSON.parse,buffer:!1,type:"json"},t.binary={encode:function(t){return n(t)?t:new e(t)},decode:r,buffer:!0,type:"binary"},t.none={encode:r,decode:r,buffer:!1,type:"id"},t.id=t.none;["hex","ascii","base64","ucs2","ucs-2","utf16le","utf-16le"].forEach(function(r){t[r]={encode:function(t){return n(t)?t:new e(t,r)},decode:function(e){return e.toString(r)},buffer:!0,type:r}})}).call(t,r(1).Buffer)},function(e,t,r){(function(t){function n(e){if(!(this instanceof n))return new n(e);if(!e)throw new Error("constructor requires at least a location argument");this.IDBOptions={},this.location=e}e.exports=n;var i=r(187),o=r(68).AbstractLevelDOWN,s=r(6),a=r(191),c=r(193),f=r(194),u=r(200);s.inherits(n,o),n.prototype._open=function(e,t){var r=this,n={storeName:this.location,autoIncrement:!1,keyPath:null,onStoreReady:function(){t&&t(null,r.idb)},onError:function(e){t&&t(e)}};f(n,e),this.IDBOptions=n,this.idb=new i(n)},n.prototype._get=function(e,r,n){this.idb.get(e,function(i){if(void 0===i)return n(new Error("NotFound"));var o=!0;return!1===r.asBuffer&&(o=!1),r.raw&&(o=!1),o&&(i=i instanceof Uint8Array?u(i):new t(String(i))),n(null,i,e)},n)},n.prototype._del=function(e,t,r){this.idb.remove(e,r,r)},n.prototype._put=function(e,r,n,i){r instanceof ArrayBuffer&&(r=u(new Uint8Array(r)));var o=this.convertEncoding(e,r,n);t.isBuffer(o.value)&&("function"==typeof r.toArrayBuffer?o.value=new Uint8Array(r.toArrayBuffer()):o.value=new Uint8Array(r)),this.idb.put(o.key,o.value,function(){i()},i)},n.prototype.convertEncoding=function(e,t,r){if(r.raw)return{key:e,value:t};if(t){var n=t.toString();"NaN"===n&&(t="NaN")}var i=r.valueEncoding,o={key:e,value:t};return!t||i&&"binary"===i||"object"!=typeof o.value&&(o.value=n),o},n.prototype.iterator=function(e){return"object"!=typeof e&&(e={}),new a(this.idb,e)},n.prototype._batch=function(e,t,r){var n,i,o,s,a=[];if(0===e.length)return setTimeout(r,0);for(n=0;n0&&this._count++>=this._limit&&(n=!1),n&&this.callback(!1,t.key,t.value),t&&t.continue()},n.prototype._next=function(e){return e?this._keyRangeError?e():(this._started||(this.createIterator(),this._started=!0),void(this.callback=e)):new Error("next() requires a callback argument")}},function(e,t,r){(function(e){function r(e,t){return Object.hasOwnProperty.call(e,t)}function n(e){return void 0!==e&&""!==e}function r(e,t){return Object.hasOwnProperty.call(e,t)}function i(e,t){return Object.hasOwnProperty.call(e,t)&&t}t.compare=function(t,r){if(e.isBuffer(t)){for(var n=Math.min(t.length,r.length),i=0;ir?1:0};var o=t.lowerBoundKey=function(e){return i(e,"gt")||i(e,"gte")||i(e,"min")||(e.reverse?i(e,"end"):i(e,"start"))||void 0},s=t.lowerBound=function(e,t){var r=o(e);return r?e[r]:t},a=t.lowerBoundInclusive=function(e){return!r(e,"gt")},c=t.upperBoundInclusive=function(e){return!r(e,"lt")},f=t.lowerBoundExclusive=function(e){return!a(e)},u=t.upperBoundExclusive=function(e){return!c(e)},h=t.upperBoundKey=function(e){return i(e,"lt")||i(e,"lte")||i(e,"max")||(e.reverse?i(e,"start"):i(e,"end"))||void 0},d=t.upperBound=function(e,t){var r=h(e);return r?e[r]:t};t.start=function(e,t){return e.reverse?d(e,t):s(e,t)},t.end=function(e,t){return e.reverse?s(e,t):d(e,t)},t.startInclusive=function(e){return e.reverse?c(e):a(e)},t.endInclusive=function(e){return e.reverse?a(e):c(e)},t.toLtgt=function(e,n,i,o,s){n=n||{},i=i||function(e){return e};var a=arguments.length>3,c=t.lowerBoundKey(e),f=t.upperBoundKey(e);return c?"gt"===c?n.gt=i(e.gt,!1):n.gte=i(e[c],!1):a&&(n.gte=i(o,!1)),f?"lt"===f?n.lt=i(e.lt,!0):n.lte=i(e[f],!0):a&&(n.lte=i(s,!0)),null!=e.reverse&&(n.reverse=!!e.reverse),r(n,"max")&&delete n.max,r(n,"min")&&delete n.min,r(n,"start")&&delete n.start,r(n,"end")&&delete n.end,n},t.contains=function(e,r,i){i=i||t.compare;var o=s(e);if(n(o)){if((c=i(r,o))<0||0===c&&f(e))return!1}var a=d(e);if(n(a)){var c;if((c=i(r,a))>0||0===c&&u(e))return!1}return!0},t.filter=function(e,r){return function(n){return t.contains(e,n,r)}}}).call(t,r(1).Buffer)},function(e,t,r){var n=r(1).Buffer;e.exports=function(e){return n.isBuffer(e)||/\[object (.+Array|Array.+)\]/.test(Object.prototype.toString.call(e))}},function(e,t,r){var n=r(195),i=r(199);e.exports=function(){for(var e={},t=0;t2?arguments[2]:null;if(a===+a)for(i=0;i=0&&"[object Function]"===r.call(e.callee)),n}},function(e,t){e.exports=function(e){return null!==e&&("object"==typeof e||"function"==typeof e)}},function(e,t,r){(function(t){e.exports=function(e){return"function"==typeof t._augment&&t.TYPED_ARRAY_SUPPORT?t._augment(e):new t(e)}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";(function(t){const n=r(202);e.exports=class extends n{constructor(e){super(),this._ipfs=e}async load(e){0===e.indexOf("/ipfs")&&(e=e.split("/")[2]);try{const t=await this._ipfs.object.get(e),r=JSON.parse(t.toJSON().data);this._access=r}catch(e){console.log("ACCESS ERROR:",e)}}async save(){let e;try{const r=JSON.stringify(this._access,null,2);e=(await this._ipfs.object.put(new t(r))).toJSON().multihash.toString()}catch(e){console.log("ACCESS ERROR:",e)}return e}}}).call(t,r(1).Buffer)},function(e,t,r){"use strict";e.exports=class{constructor(){this._access={admin:[],write:[],read:[]}}async load(e){}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(e,t){switch(e){case"admin":this._access.admin.push(t);break;case"write":this._access.write.push(t);break;case"read":this._access.read.push(t)}}remove(e,t){const r=(e,r)=>e.reduce((e,r)=>(r!==t&&e.push(r),e),[]);switch(e){case"admin":this._access.admin=r(this._access.admin);break;case"write":this._access.write=r(this._access.write);break;case"read":this._access.read=r(this._access.read)}}}},function(e,t,r){"use strict";const n=r(12),i=r(204);class o{constructor(e,t){this.root=e,this.path=t}toString(){return n.join("/orbitdb",this.root,this.path)}static isValid(e){const t=e.toString().split("/").filter((t,r)=>!((0===r||1===r)&&0===e.toString().indexOf("/orbit")&&"orbitdb"===t)).filter(e=>""!==e&&" "!==e),r=t[0].indexOf("Qm")>-1?i.fromB58String(t[0]):null;try{i.validate(r)}catch(e){return!1}return null!==r}static parse(e){if(!e)throw new Error(`Not a valid OrbitDB address: ${e}`);if(!o.isValid(e))throw new Error(`Not a valid OrbitDB address: ${e}`);const t=e.toString().split("/").filter((t,r)=>!((0===r||1===r)&&0===e.toString().indexOf("/orbit")&&"orbitdb"===t)).filter(e=>""!==e&&" "!==e);return new o(t[0],t.slice(1,t.length).join("/"))}}e.exports=o},function(e,t,r){"use strict";(function(e){function n(e){t.decode(e)}const i=r(205),o=r(207);t.names=o.names,t.codes=o.codes,t.defaultLengths=o.defaultLengths;const s=r(208);t.toHexString=function(t){if(!e.isBuffer(t))throw new Error("must be passed a buffer");return t.toString("hex")},t.fromHexString=function(t){return e.from(t,"hex")},t.toB58String=function(t){if(!e.isBuffer(t))throw new Error("must be passed a buffer");return i.encode(t)},t.fromB58String=function(t){let r=t;return e.isBuffer(t)&&(r=t.toString()),e.from(i.decode(r))},t.decode=function(r){if(!e.isBuffer(r))throw new Error("multihash must be a Buffer");if(r.length<3)throw new Error("multihash too short. must be > 3 bytes.");let n=s.decode(r);if(!t.isValidCode(n))throw new Error(`multihash unknown function code: 0x${n.toString(16)}`);r=r.slice(s.decode.bytes);let i=s.decode(r);if(i<1)throw new Error(`multihash invalid length: 0x${i.toString(16)}`);if((r=r.slice(s.decode.bytes)).length!==i)throw new Error(`multihash length inconsistent: 0x${r.toString("hex")}`);return{code:n,name:o.codes[n],length:i,digest:r}},t.encode=function(r,n,i){if(!r||!n)throw new Error("multihash encode requires at least two args: digest, code");const o=t.coerceCode(n);if(!e.isBuffer(r))throw new Error("digest should be a Buffer");if(null==i&&(i=r.length),i&&r.length!==i)throw new Error("digest length should be equal to specified length.");return e.concat([e.from(s.encode(o)),e.from(s.encode(i)),r])},t.coerceCode=function(e){let r=e;if("string"==typeof e){if(!o.names[e])throw new Error(`Unrecognized hash function named: ${e}`);r=o.names[e]}if("number"!=typeof r)throw new Error(`Hash function code should be a number. Got: ${r}`);if(!o.codes[r]&&!t.isAppCode(r))throw new Error(`Unrecognized function code: ${r}`);return r},t.isAppCode=function(e){return e>0&&e<16},t.isValidCode=function(e){return!!t.isAppCode(e)||!!o.codes[e]},t.validate=n,t.prefix=function(e){return n(e),e.slice(0,2)}}).call(t,r(1).Buffer)},function(e,t,r){var n=r(206);e.exports=n("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},function(e,t,r){var n=r(9).Buffer;e.exports=function(e){function t(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return n.allocUnsafe(0);for(var t=[0],s=0;s>=8;for(;f>0;)t.push(255&f),f>>=8}for(var u=0;e[u]===o&&u0;)r.push(s%i),s=s/i|0}for(var a="",c=0;0===t[c]&&c=0;--f)a+=e[r[f]];return a},decodeUnsafe:t,decode:function(e){var r=t(e);if(r)return r;throw new Error("Non-base"+i+" character")}}}},function(e,t,r){"use strict";t.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}),t.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"}),t.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(e,t,r){e.exports={encode:r(209),decode:r(210),encodingLength:r(211)}},function(e,t){function r(e,t,s){t=t||[];for(var a=s=s||0;e>=o;)t[s++]=255&e|n,e/=128;for(;e&i;)t[s++]=255&e|n,e>>>=7;return t[s]=0|e,r.bytes=s-a+1,t}e.exports=r;var n=128,i=-128,o=Math.pow(2,31)},function(e,t){function r(e,t){var o,s=0,a=0,c=t=t||0,f=e.length;do{if(c>=f)throw r.bytes=0,new RangeError("Could not decode varint");o=e[c++],s+=a<28?(o&i)<=n);return r.bytes=c-t,s}e.exports=r;var n=128,i=127},function(e,t){var r=Math.pow(2,7),n=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);e.exports=function(e){return e{const s={name:r,type:i,accessController:n.join("/ipfs",o)};return(await e.object.put(t.from(JSON.stringify(s)))).toJSON().multihash.toString()})}).call(t,r(1).Buffer)}]); \ No newline at end of file diff --git a/examples/browser/example.js b/examples/browser/example.js index dead1ae..c4c8453 100644 --- a/examples/browser/example.js +++ b/examples/browser/example.js @@ -81,6 +81,8 @@ const main = (IPFS, ORBITDB) => { // When we update the database, display result db.events.on('write', () => queryAndRender(db)) + db.events.on('replicate.progress', () => queryAndRender(db)) + // Hook up to the load progress event and render the progress let maxTotal = 0, loaded = 0 db.events.on('load.progress', (address, hash, entry, progress, total) => { @@ -242,7 +244,7 @@ const main = (IPFS, ORBITDB) => {
Peer ID: ${orbitdb.id}
Peers (database/network): ${databasePeers.length} / ${networkPeers.length}
-
Oplog Size: ${db._oplog.length} / ${db._replicationInfo.max}
+
Oplog Size: ${db._replicationInfo.progress} / ${db._replicationInfo.max}

Results

diff --git a/package-lock.json b/package-lock.json index 701a5af..ea18ce8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -86,9 +86,9 @@ "dev": true }, "ajv": { - "version": "5.5.1", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.1.tgz", - "integrity": "sha1-s4u4h22ehr7plJVqBOch6IskjrI=", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", "dev": true, "requires": { "co": "4.6.0", @@ -791,7 +791,7 @@ "dev": true, "requires": { "babel-runtime": "6.26.0", - "core-js": "2.5.2", + "core-js": "2.5.3", "regenerator-runtime": "0.10.5" }, "dependencies": { @@ -843,7 +843,7 @@ "requires": { "babel-core": "6.26.0", "babel-runtime": "6.26.0", - "core-js": "2.5.2", + "core-js": "2.5.3", "home-or-tmp": "2.0.0", "lodash": "4.17.4", "mkdirp": "0.5.1", @@ -856,7 +856,7 @@ "integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=", "dev": true, "requires": { - "core-js": "2.5.2", + "core-js": "2.5.3", "regenerator-runtime": "0.11.1" } }, @@ -1767,9 +1767,9 @@ } }, "core-js": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.2.tgz", - "integrity": "sha1-vEZIZW59ydyA19PHu8Fy2W50TmM=", + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.5.3.tgz", + "integrity": "sha1-isw4NFgk8W2DZbfJtCWRaOjtYD4=", "dev": true }, "core-util-is": { @@ -2023,7 +2023,7 @@ "integrity": "sha512-/cLUpQduF6bNrWuAC4pwtUKA5t669pCsCi2XbmojG2tFeOr9j6ShtdDCtFFQO1DRt+EVZhx9gPzP9G2bUaG4ig==", "dev": true, "requires": { - "errno": "0.1.4" + "errno": "0.1.6" } }, "level-iterator-stream": { @@ -2072,12 +2072,6 @@ "integrity": "sha1-2Vv3IeyHfgjbJ27T/G63j5CDrUY=", "dev": true }, - "prr": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", - "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=", - "dev": true - }, "readable-stream": { "version": "1.1.14", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", @@ -2320,13 +2314,13 @@ "dev": true }, "encoding-down": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-3.0.0.tgz", - "integrity": "sha1-IGjLZ7E3G14frJtfF44FpVUr+l4=", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-3.0.1.tgz", + "integrity": "sha512-uvx+39YNqiPLqhXAvOSGBVy/oYBh4p2ShwG9YFCipwgfOhnVIOxuOPE3R9dEGM44bn0VHIrC3ojXq6lNf2ulwg==", "requires": { "abstract-leveldown": "3.0.0", "level-codec": "8.0.0", - "level-errors": "1.1.1" + "level-errors": "1.1.2" } }, "end-of-stream": { @@ -2349,7 +2343,7 @@ "debug": "2.6.9", "engine.io-parser": "2.1.1", "uws": "0.14.5", - "ws": "3.3.2" + "ws": "3.3.3" }, "dependencies": { "debug": { @@ -2377,7 +2371,7 @@ "indexof": "0.0.1", "parseqs": "0.0.5", "parseuri": "0.0.5", - "ws": "3.3.2", + "ws": "3.3.3", "xmlhttprequest-ssl": "1.5.4", "yeast": "0.1.2" }, @@ -2428,11 +2422,11 @@ } }, "errno": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.4.tgz", - "integrity": "sha1-uJbiOp5ei6M4cfyZar02NfyaHH0=", + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.6.tgz", + "integrity": "sha512-IsORQDpaaSwcDP4ZZnHxgE85werpo34VYn1Ud3mq+eUsF593faR8oCZNXrROVkpFu2TsbrNhHin0aUrTsQ9vNw==", "requires": { - "prr": "0.0.0" + "prr": "1.0.1" } }, "error-ex": { @@ -4172,7 +4166,7 @@ "dev": true, "optional": true, "requires": { - "ajv": "5.5.1", + "ajv": "5.5.2", "har-schema": "2.0.0" } }, @@ -4564,9 +4558,9 @@ } }, "ipfs": { - "version": "0.27.3", - "resolved": "https://registry.npmjs.org/ipfs/-/ipfs-0.27.3.tgz", - "integrity": "sha512-pUvmBE/Vo5vGPuChJchl/1AQBldjmtJU7iddtbR9iLz8f1qdtz2y7p9HyHsPM8N7t+VjB1Y+B2JchUap4wPdUg==", + "version": "0.27.5", + "resolved": "https://registry.npmjs.org/ipfs/-/ipfs-0.27.5.tgz", + "integrity": "sha512-msXTU+vgXArtC9PVEvOIv9auSfNRpGwFFgcoTB0ZLkmGDkG0LuUieRHMuibjYySqVE5rP0upUdqPeBXzOx40NA==", "dev": true, "requires": { "async": "2.6.0", @@ -4586,23 +4580,23 @@ "hapi-set-header": "1.0.2", "hoek": "5.0.2", "ipfs-api": "17.2.4", - "ipfs-bitswap": "0.17.4", + "ipfs-bitswap": "0.18.0", "ipfs-block": "0.6.1", "ipfs-block-service": "0.13.0", "ipfs-multipart": "0.1.0", - "ipfs-repo": "0.18.4", + "ipfs-repo": "0.18.5", "ipfs-unixfs": "0.1.14", - "ipfs-unixfs-engine": "0.24.1", + "ipfs-unixfs-engine": "0.24.2", "ipld-resolver": "0.14.1", "is-ipfs": "0.3.2", "is-stream": "1.1.0", "joi": "13.0.2", - "libp2p": "0.13.3", + "libp2p": "0.14.3", "libp2p-circuit": "0.1.4", "libp2p-floodsub": "0.13.1", "libp2p-kad-dht": "0.6.0", "libp2p-mdns": "0.9.1", - "libp2p-multiplex": "0.5.0", + "libp2p-multiplex": "0.5.1", "libp2p-railing": "0.7.1", "libp2p-secio": "0.8.1", "libp2p-tcp": "0.11.1", @@ -4622,12 +4616,13 @@ "path-exists": "3.0.0", "peer-book": "0.5.2", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "progress": "2.0.0", "prom-client": "10.2.2", "prometheus-gc-stats": "0.5.0", "promisify-es6": "1.0.3", "pull-abortable": "4.1.1", + "pull-defer": "0.2.2", "pull-file": "1.1.0", "pull-ndjson": "0.1.1", "pull-paramap": "1.2.2", @@ -4673,7 +4668,7 @@ "ndjson": "1.5.0", "once": "1.4.0", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "promisify-es6": "1.0.3", "pull-defer": "0.2.2", "pull-pushable": "2.1.1", @@ -4687,12 +4682,13 @@ } }, "ipfs-bitswap": { - "version": "0.17.4", - "resolved": "https://registry.npmjs.org/ipfs-bitswap/-/ipfs-bitswap-0.17.4.tgz", - "integrity": "sha512-IMDA0dr377fVaDdi6tVOTPlmbPQkWxe/KBsL85epjIhsKtFoZwz9WvY2INpNotT6OdTA/Wiwr2pWrFQsymDIeA==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/ipfs-bitswap/-/ipfs-bitswap-0.18.0.tgz", + "integrity": "sha512-nPtMoIA68J/vwEiGHVTiWscG1QtyHCwyl+OhNlqArHw6EGeNLIE+6/Gm2F/jc1keboNstJo+mGMHF5L7YR0eYw==", "dev": true, "requires": { "async": "2.6.0", + "big.js": "5.0.3", "cids": "0.5.2", "debug": "3.1.0", "ipfs-block": "0.6.1", @@ -4705,6 +4701,7 @@ "lodash.sortby": "4.7.0", "lodash.uniqwith": "4.5.0", "lodash.values": "4.3.0", + "moving-average": "1.0.0", "multicodec": "0.2.5", "multihashing-async": "0.4.7", "protons": "1.0.1", @@ -4714,6 +4711,14 @@ "pull-stream": "3.6.1", "safe-buffer": "5.1.1", "varint-decoder": "0.1.1" + }, + "dependencies": { + "big.js": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.0.3.tgz", + "integrity": "sha512-av8LNZGBl4cg2r4ZhWqghJOxi2P8UCcWhdmrFgcHPMmUJ6jx1FbnyxjwL4URYzMK3QJg60qeMefQhv9G14oYKA==", + "dev": true + } } }, "ipfs-block": { @@ -4732,9 +4737,9 @@ "dev": true }, "ipfs-log": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/ipfs-log/-/ipfs-log-4.0.5.tgz", - "integrity": "sha512-ZCf1dE8HsLs0G7hNrRs2ICZ5+e83pcddEH2ZY/VPsbrShZumsq4zHLL0QN+bmgm1AbdAZrzpS7wuqHPNeFRO7g==", + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ipfs-log/-/ipfs-log-4.0.6.tgz", + "integrity": "sha512-LcCFq8AF8CDCKFAM78QkbH5+6VHk0sX5qu6k7/b7wVetuaTx3Xq85axfFjj7D5YeQdssBGLqex1x6EAx9MX9+Q==", "requires": { "p-map": "1.2.0", "p-whilst": "1.0.0" @@ -4751,9 +4756,7 @@ } }, "ipfs-pubsub-room": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/ipfs-pubsub-room/-/ipfs-pubsub-room-1.0.1.tgz", - "integrity": "sha512-kuEjjrKIIWiK0JNW+NA684g3k/hMR9qYG93WXGMzsVGLcy2+nPxLSv680itAie3wJxtFtXcYzD4VjRO9rhygyQ==", + "version": "github:haadcode/ipfs-pubsub-room#68aecffc0c89b2430349d59c2556c0f70b2f96e5", "requires": { "hyperdiff": "2.0.4", "lodash.clonedeep": "4.5.0", @@ -4763,9 +4766,9 @@ } }, "ipfs-repo": { - "version": "0.18.4", - "resolved": "https://registry.npmjs.org/ipfs-repo/-/ipfs-repo-0.18.4.tgz", - "integrity": "sha512-sBrde6bIpzywv2hxqkTsOT4njJjme4cXuFNKbcaH/hGuz17MUpX+bGgeZsOhc4lVBSWh6VM/uVbS+vFfqEVdzw==", + "version": "0.18.5", + "resolved": "https://registry.npmjs.org/ipfs-repo/-/ipfs-repo-0.18.5.tgz", + "integrity": "sha512-QELzb2fLqM2t9WQuiD60iRbC8KrxQ3GKODAOxTSnfrT+KKWls/2n/yw70mW80eemCRz6/9HSWXZdjmG2eISSaA==", "dev": true, "requires": { "async": "2.6.0", @@ -4847,9 +4850,9 @@ } }, "ipfs-unixfs-engine": { - "version": "0.24.1", - "resolved": "https://registry.npmjs.org/ipfs-unixfs-engine/-/ipfs-unixfs-engine-0.24.1.tgz", - "integrity": "sha512-Xm4jxdZFsBe7mwKhpqPxGaH2rMvoAbdovYKrA75ZZJwHT7rocepE+4Tx0Gpr+0mJnmGO9eZ2bzbvtqA71nNWmw==", + "version": "0.24.2", + "resolved": "https://registry.npmjs.org/ipfs-unixfs-engine/-/ipfs-unixfs-engine-0.24.2.tgz", + "integrity": "sha512-9HCnC+gkXqK35eARGYm77hnHZwIk9MoHiTG6eaXFueP341EIvuTWy6o1NJ0dw5Hp6AiK1fwN0AG6P8GqnZIWZA==", "dev": true, "requires": { "async": "2.6.0", @@ -4868,7 +4871,7 @@ "pull-cat": "1.1.11", "pull-pair": "1.1.0", "pull-paramap": "1.2.2", - "pull-pause": "0.0.1", + "pull-pause": "0.0.2", "pull-pushable": "2.1.1", "pull-stream": "3.6.1", "pull-traverse": "1.0.3", @@ -4973,7 +4976,7 @@ "interface-datastore": "0.4.2", "ipfs-block": "0.6.1", "ipfs-block-service": "0.13.0", - "ipfs-repo": "0.18.4", + "ipfs-repo": "0.18.5", "ipld-dag-cbor": "0.11.2", "ipld-dag-pb": "0.11.4", "ipld-ethereum": "1.4.4", @@ -5454,11 +5457,11 @@ } }, "level": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/level/-/level-2.1.0.tgz", - "integrity": "sha512-J1MuO0iJuG93xsJjugr2qrAcC95RVKMqrAiio1AcoM2FaAxrUJacAbtfLqYqr7xwQ/NiTXCMfBX71gNmGROXOA==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/level/-/level-2.1.1.tgz", + "integrity": "sha512-jhsItEs/L5bf5ctKsvIPcMzeh4nwXxnL3Tsxm4E9My07jcFfqEYwKP57Y9AZu7tmtECdyK6bvCqoClwuOBuY9w==", "requires": { - "level-packager": "2.0.2", + "level-packager": "2.1.0", "leveldown": "2.1.1" } }, @@ -5468,11 +5471,11 @@ "integrity": "sha512-gNZlo1HRHz0BWxzGCyNf7xntAs2HKOPvvRBWtXsoDvEX4vMYnSTBS6ZnxoaiX7nhxSBPpegRa8CQ/hnfGBKk3Q==" }, "level-errors": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-1.1.1.tgz", - "integrity": "sha512-9MIIbizlJgWFQ6m45ehVuSrpzFxwJQmZYD6sfmiizhdmWMNUf41mBYpUJEeCslIa3sB4vdsIFCimPdDZkWznwA==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-1.1.2.tgz", + "integrity": "sha512-Sw/IJwWbPKF5Ai4Wz60B52yj0zYeqzObLh8k1Tk88jVmD51cJSKWSYpRyhVIvFzZdvsPqlH5wfhp/yxdsaQH4w==", "requires": { - "errno": "0.1.4" + "errno": "0.1.6" } }, "level-iterator-stream": { @@ -5528,11 +5531,11 @@ } }, "level-packager": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-2.0.2.tgz", - "integrity": "sha1-AztxFnhELPlWyVFFYnPcY+QXQEc=", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-2.1.0.tgz", + "integrity": "sha512-I97zvGOZ6fJ9OFfYv+QmgBpDWbC+UaP5ERJ3oraTyk1v+ABAL4tazris5ym5qL2iLe+qNjXNM/iP8LQcoZMEWw==", "requires": { - "encoding-down": "3.0.0", + "encoding-down": "3.0.1", "levelup": "2.0.1" } }, @@ -5599,25 +5602,25 @@ "integrity": "sha1-PckbPmMtN8nlRiOchkEYsATJ+GA=", "requires": { "deferred-leveldown": "2.0.3", - "level-errors": "1.1.1", + "level-errors": "1.1.2", "level-iterator-stream": "2.0.0", "xtend": "4.0.1" } }, "libp2p": { - "version": "0.13.3", - "resolved": "https://registry.npmjs.org/libp2p/-/libp2p-0.13.3.tgz", - "integrity": "sha512-u2STVP3FcC7kL16RykcS1ik5fBgNYgLVpPERpObRtwVpfnWgqWT9/faaJ649LGHBlH/4z/4piOrvgIeIdlnDVg==", + "version": "0.14.3", + "resolved": "https://registry.npmjs.org/libp2p/-/libp2p-0.14.3.tgz", + "integrity": "sha512-5eL/gA1XuYAo0XrqznvkJvagF/nHakNX+bC7Ksuqq574k1cNZYiqnFc0O+zdD8up0BJt0LAXgd9IPB4TX3rUVg==", "dev": true, "requires": { "async": "2.6.0", "libp2p-ping": "0.6.0", - "libp2p-swarm": "0.33.2", + "libp2p-swarm": "0.34.0", "mafmt": "3.0.2", "multiaddr": "3.0.1", "peer-book": "0.5.2", "peer-id": "0.10.3", - "peer-info": "0.11.3" + "peer-info": "0.11.4" } }, "libp2p-circuit": { @@ -5635,7 +5638,7 @@ "multiaddr": "3.0.1", "multistream-select": "0.14.1", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "protons": "1.0.1", "pull-abortable": "4.1.1", "pull-handshake": "1.1.4", @@ -5701,7 +5704,7 @@ "requires": { "multiaddr": "3.0.1", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "protons": "1.0.1", "pull-length-prefixed": "1.3.0", "pull-stream": "3.6.1" @@ -5725,7 +5728,7 @@ "libp2p-record": "0.5.1", "multihashing-async": "0.4.7", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "priorityqueue": "0.2.0", "protons": "1.0.1", "pull-length-prefixed": "1.3.0", @@ -5745,13 +5748,13 @@ "multiaddr": "3.0.1", "multicast-dns": "6.2.1", "peer-id": "0.10.3", - "peer-info": "0.11.3" + "peer-info": "0.11.4" } }, "libp2p-multiplex": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/libp2p-multiplex/-/libp2p-multiplex-0.5.0.tgz", - "integrity": "sha512-cZjK66wr2zcaC5sW0QjBZ/lXouBlYQ9Hr3Y6j2DImTtOjPufccnaULkCxbnpnfQ/g52AEsIQh0DlwW4L0gZ8Ag==", + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/libp2p-multiplex/-/libp2p-multiplex-0.5.1.tgz", + "integrity": "sha512-XZagf1B31Vkbd+iAai8cOfRkcZWba+MtSRf/xQJ7uOz7O4heLMNC4orcDqT0n+Hkkn3zfqllH75Kp1xJ+Vog2w==", "dev": true, "requires": { "async": "2.6.0", @@ -5759,7 +5762,20 @@ "pull-catch": "1.0.0", "pull-stream": "3.6.1", "pull-stream-to-stream": "1.3.4", + "pump": "2.0.0", "stream-to-pull-stream": "1.7.2" + }, + "dependencies": { + "pump": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/pump/-/pump-2.0.0.tgz", + "integrity": "sha512-6MYypjOvtiXhBSTOD0Zs5eNjCGfnqi5mPsCsW+dgKTxrZzQMZQNpBo3XRkLx7id753f3EeyHLBqzqqUymIolgw==", + "dev": true, + "requires": { + "end-of-stream": "1.4.0", + "once": "1.4.0" + } + } } }, "libp2p-ping": { @@ -5784,7 +5800,7 @@ "lodash": "4.17.4", "multiaddr": "3.0.1", "peer-id": "0.10.3", - "peer-info": "0.11.3" + "peer-info": "0.11.4" } }, "libp2p-record": { @@ -5822,9 +5838,9 @@ } }, "libp2p-swarm": { - "version": "0.33.2", - "resolved": "https://registry.npmjs.org/libp2p-swarm/-/libp2p-swarm-0.33.2.tgz", - "integrity": "sha512-+detttstBXcQFiUqKv2kEYf08QntKqLIlRVDjFERMQsLp2ce4wRIymd75Hj5CvqAjdlcjh8WU/sjsNsPU/Dd+A==", + "version": "0.34.0", + "resolved": "https://registry.npmjs.org/libp2p-swarm/-/libp2p-swarm-0.34.0.tgz", + "integrity": "sha512-4I4T3+Zajb1uhdGMU5m1vel07AQY2m/RmIpC9WsheQsWh1AL86keMw6fL5iijrpMUWAU6mlfyuL6r73kdAaBfw==", "dev": true, "requires": { "async": "2.6.0", @@ -5838,7 +5854,7 @@ "multistream-select": "0.14.1", "once": "1.4.0", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "pull-stream": "3.6.1" } }, @@ -5876,7 +5892,7 @@ "multiaddr": "3.0.1", "once": "1.4.0", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "pull-stream": "3.6.1", "simple-peer": "8.2.0", "socket.io": "2.0.4", @@ -5901,7 +5917,7 @@ "multiaddr": "3.0.1", "once": "1.4.0", "peer-id": "0.10.3", - "peer-info": "0.11.3", + "peer-info": "0.11.4", "pull-stream": "3.6.1", "socket.io-client": "2.0.4", "socket.io-pull-stream": "0.1.3", @@ -6266,7 +6282,7 @@ "integrity": "sha1-OpoguEYlI+RHz7x+i7gO1me/xVI=", "dev": true, "requires": { - "errno": "0.1.4", + "errno": "0.1.6", "readable-stream": "2.3.3" } }, @@ -6350,7 +6366,7 @@ "integrity": "sha512-/cLUpQduF6bNrWuAC4pwtUKA5t669pCsCi2XbmojG2tFeOr9j6ShtdDCtFFQO1DRt+EVZhx9gPzP9G2bUaG4ig==", "dev": true, "requires": { - "errno": "0.1.4" + "errno": "0.1.6" } }, "level-iterator-stream": { @@ -6394,12 +6410,6 @@ "xtend": "4.0.1" } }, - "prr": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", - "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=", - "dev": true - }, "string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", @@ -6592,6 +6602,12 @@ "run-queue": "1.0.3" } }, + "moving-average": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/moving-average/-/moving-average-1.0.0.tgz", + "integrity": "sha512-97cgMz0U2zciiDp4xRl/n+MYgrm9l7UiYbtsBLPr0rhw6KH3m4LyK2w4d96V6+UwKo+ph7KtQSoL2qgnqZVgvA==", + "dev": true + }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -6955,11 +6971,11 @@ "dev": true }, "orbit-db-cache": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/orbit-db-cache/-/orbit-db-cache-0.1.1.tgz", - "integrity": "sha512-iDzcLMSzuUTdypiaP0fXcIHtxdqJJrlwkYhTpAnpIr+3f+t+hRtyC99/ZwGdHOuWIIFiajDDoC8JPYCv4Rfkqg==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/orbit-db-cache/-/orbit-db-cache-0.1.2.tgz", + "integrity": "sha512-0I2o6VEPJ/kYMFTLWRqB7ek7G28GbewEFzGP1wOP1o3Uy+P2B/MKBT7sfa9yZ2pJRq4X0R5xZLtVWldpYK5nzQ==", "requires": { - "level": "2.1.0", + "level": "2.1.1", "mkdirp": "0.5.1" } }, @@ -6969,7 +6985,7 @@ "integrity": "sha512-25CtAWuT5Ni4rDLziNj5qbjgAP0d+nyWWV9Tx30VqPXgCA4hYG3hAgIs3EYCVLWIRFZH7xdCfLyHfXY/v8pQvg==", "requires": { "crdts": "0.1.5", - "orbit-db-store": "2.1.0" + "orbit-db-store": "2.1.1" } }, "orbit-db-docstore": { @@ -6977,7 +6993,7 @@ "resolved": "https://registry.npmjs.org/orbit-db-docstore/-/orbit-db-docstore-1.1.0.tgz", "integrity": "sha512-cELdzNVMZcjXP6QalX5xjd5a0ajy1gI+d837z8VEZJiJSqokJXgj7jhsEV6nZYtF3yTS5ky5eGD6f446cVrmzA==", "requires": { - "orbit-db-store": "2.1.0", + "orbit-db-store": "2.1.1", "p-map": "1.1.1" }, "dependencies": { @@ -6989,11 +7005,11 @@ } }, "orbit-db-eventstore": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/orbit-db-eventstore/-/orbit-db-eventstore-1.1.0.tgz", - "integrity": "sha512-+ND1O52dztkpeSrUWFT5IzkW0w13EUOEeUvil13ML0SIyMEEdpIHLDbF4/eNqdfO4wJYthtu1AryP1nTzK8hmQ==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/orbit-db-eventstore/-/orbit-db-eventstore-1.1.3.tgz", + "integrity": "sha512-5R01vEl98iztagCab7Wu+futTR2Ud6g8YaoHzNEZBtDdaJQ7UZhJCzzD0T42oIw9VchEeRUpZjChYSLrv7DgNw==", "requires": { - "orbit-db-store": "2.1.0" + "orbit-db-store": "2.1.1" } }, "orbit-db-feedstore": { @@ -7001,7 +7017,7 @@ "resolved": "https://registry.npmjs.org/orbit-db-feedstore/-/orbit-db-feedstore-1.1.0.tgz", "integrity": "sha512-dbE7eCVd9sGPx+cGtQjdnNoysavbe5HT7fst4CNsr5Ks4Nbrp+Y/e7kj4lkh/Ltl6TokSqoKtA5mEdmlsQA/Ew==", "requires": { - "orbit-db-eventstore": "1.1.0" + "orbit-db-eventstore": "1.1.3" } }, "orbit-db-keystore": { @@ -7019,24 +7035,25 @@ "resolved": "https://registry.npmjs.org/orbit-db-kvstore/-/orbit-db-kvstore-1.1.0.tgz", "integrity": "sha512-P9SKWklMcdyc1ZPQmsHJzKTfyLwNvTp/3tlVtPOllHlOwopDt3ItwQnIR4s163RtUQoRDyYEmft3F/FDKhNdbg==", "requires": { - "orbit-db-store": "2.1.0" + "orbit-db-store": "2.1.1" } }, "orbit-db-pubsub": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/orbit-db-pubsub/-/orbit-db-pubsub-0.3.6.tgz", - "integrity": "sha512-8hrnwJe6JjzIycUHoBUYYEY6LEtSYkUTX6VcJsneLooqRm5nbIXHwe9Bcoimyui9uH1GJ67+AZKUEePUvdBFFg==", + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/orbit-db-pubsub/-/orbit-db-pubsub-0.3.9.tgz", + "integrity": "sha512-0Pxq7Z3nGP20H9JWqfvFfyjAAnwr8sRNquU2aUIPsBb0jrcHw+fAtaj0m9/5ML2ift4IO17Mn9lydHxkS4M5Ug==", "requires": { - "ipfs-pubsub-room": "1.0.1", + "ipfs-pubsub-room": "github:haadcode/ipfs-pubsub-room#68aecffc0c89b2430349d59c2556c0f70b2f96e5", "logplease": "1.2.14" } }, "orbit-db-store": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/orbit-db-store/-/orbit-db-store-2.1.0.tgz", - "integrity": "sha512-GSmxqPPNL3JkR1e2Gwd11PejXWqircpy239hwOg4qThUBo05Y6YG6/G92cIgxypu5VgUe0QolCa+C3GOme4c5Q==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/orbit-db-store/-/orbit-db-store-2.1.1.tgz", + "integrity": "sha512-rW/LiEr0W7i51BDprJNIB1BKqLZhFp74ksxIalQBckZvY7/QmYw3ZNsrO5zaZI2GMRgj+XVKbyikURn5VP7q7A==", "requires": { - "ipfs-log": "4.0.5", + "ipfs-log": "4.0.6", + "logplease": "1.2.14", "orbit-db-keystore": "0.0.2", "p-each-series": "1.0.0", "readable-stream": "2.3.3" @@ -7289,7 +7306,7 @@ "requires": { "bs58": "4.0.1", "peer-id": "0.10.3", - "peer-info": "0.11.3" + "peer-info": "0.11.4" } }, "peer-id": { @@ -7305,9 +7322,9 @@ } }, "peer-info": { - "version": "0.11.3", - "resolved": "https://registry.npmjs.org/peer-info/-/peer-info-0.11.3.tgz", - "integrity": "sha512-FzNzL5PYGr7rpHFpoSMdEGwRVb7X9D88YDmTkamXd4CO05bNeHITlrwIV7ctshBhVRTvokpnI59HUSEQly5rnA==", + "version": "0.11.4", + "resolved": "https://registry.npmjs.org/peer-info/-/peer-info-0.11.4.tgz", + "integrity": "sha512-p+NpRgZpnlz0BGz6ZLFF8vVlqOBDxGwN7AA+QCc4nCICxVpbf4PlmtzwePVtkDqlNwUXYCDKK8pG0FGC5E8B2g==", "dev": true, "requires": { "lodash.uniqby": "4.7.0", @@ -7549,9 +7566,9 @@ } }, "prr": { - "version": "0.0.0", - "resolved": "https://registry.npmjs.org/prr/-/prr-0.0.0.tgz", - "integrity": "sha1-GoS4WQgyVQFBGFPQCB7j+obikmo=" + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", + "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=" }, "pseudomap": { "version": "1.0.2", @@ -7691,9 +7708,9 @@ } }, "pull-pause": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/pull-pause/-/pull-pause-0.0.1.tgz", - "integrity": "sha1-xJm0Fhqt2+qE9S6JjlcPol1foiw=", + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/pull-pause/-/pull-pause-0.0.2.tgz", + "integrity": "sha1-GdRb6PqmFfpVbxSpb9czRiw3+6M=", "dev": true }, "pull-pushable": { @@ -8222,7 +8239,7 @@ "integrity": "sha1-9YdyIs4+kx7a4DnxfrNxbnE3+M8=", "dev": true, "requires": { - "ajv": "5.5.1" + "ajv": "5.5.2" } }, "secp256k1": { @@ -8261,6 +8278,12 @@ "semver": "5.4.1" } }, + "serialize-javascript": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-1.4.0.tgz", + "integrity": "sha1-fJWFFNtqwkQ6irwGLcn3iGp/YAU=", + "dev": true + }, "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", @@ -9103,9 +9126,9 @@ "dev": true }, "uglify-es": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.2.1.tgz", - "integrity": "sha512-c+Fy4VuGvPmT7mj7vEPjRR/iNFuXuOAkufhCtCvTGX0Hr4gCM9YwCnLgHkxr1ngqSODQaDObU3g8SF8uE/tY1w==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.2.2.tgz", + "integrity": "sha512-l+s5VLzFwGJfS+fbqaGf/Dfwo1MF13jLOF2ekL0PytzqEqQ6cVppvHf4jquqFok+35USMpKjqkYxy6pQyUcuug==", "dev": true, "requires": { "commander": "2.12.2", @@ -9128,16 +9151,17 @@ "optional": true }, "uglifyjs-webpack-plugin": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.1.2.tgz", - "integrity": "sha512-k07cmJTj+8vZMSc3BaQ9uW7qVl2MqDts4ti4KaNACXEcXSw2vQM2S8olSk/CODxvcSFGvUHzNSqA8JQlhgUJPw==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-1.1.4.tgz", + "integrity": "sha512-fRrOJ5tv6YCsJIhP9mPRnfgyo4DVNSIfNOa7Gs9aT1NNpeJc85W7GcbVxQgc+9rU3No6tnkbMqZ4xsgRBU+HGQ==", "dev": true, "requires": { "cacache": "10.0.1", "find-cache-dir": "1.0.0", "schema-utils": "0.3.0", + "serialize-javascript": "1.4.0", "source-map": "0.6.1", - "uglify-es": "3.2.1", + "uglify-es": "3.2.2", "webpack-sources": "1.1.0", "worker-farm": "1.5.2" }, @@ -9390,7 +9414,7 @@ "requires": { "acorn": "5.2.1", "acorn-dynamic-import": "2.0.2", - "ajv": "5.5.1", + "ajv": "5.5.2", "ajv-keywords": "2.1.1", "async": "2.6.0", "enhanced-resolve": "3.4.1", @@ -9747,7 +9771,7 @@ "integrity": "sha512-XxiQ9kZN5n6mmnW+mFJ+wXjNNI/Nx4DIdaAKLX1Bn6LYBWlN/zaBhu34DQYPZ1AJobQuu67S2OfDdNSVULvXkQ==", "dev": true, "requires": { - "errno": "0.1.4", + "errno": "0.1.6", "xtend": "4.0.1" } }, @@ -9804,9 +9828,9 @@ } }, "ws": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.2.tgz", - "integrity": "sha512-t+WGpsNxhMR4v6EClXS8r8km5ZljKJzyGhJf7goJz9k5Ye3+b5Bvno5rjqPuIBn5mnn5GBb7o8IrIWHxX1qOLQ==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", + "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", "dev": true, "requires": { "async-limiter": "1.0.0", diff --git a/package.json b/package.json index 8eb393b..867b897 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "orbit-db-feedstore": "~1.1.0", "orbit-db-keystore": "~0.0.2", "orbit-db-kvstore": "~1.1.0", - "orbit-db-pubsub": "~0.3.6" + "orbit-db-pubsub": "~0.3.8" }, "devDependencies": { "babel-core": "^6.26.0", diff --git a/src/OrbitDB.js b/src/OrbitDB.js index 16bdf96..0acbcac 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -132,7 +132,7 @@ class OrbitDB { async _onMessage (address, heads) { const store = this.stores[address] try { - logger.debug(`Received heads for '${address}':\n`, JSON.stringify(heads, null, 2)) + logger.debug(`Received ${heads.length} heads for '${address}':\n`, JSON.stringify(heads.map(e => e.hash), null, 2)) await store.sync(heads) } catch (e) { logger.error(e) @@ -147,7 +147,7 @@ class OrbitDB { // Send the newly connected peer our latest heads let heads = store._oplog.heads if (heads.length > 0) { - logger.debug(`Send latest heads of '${address}':\n`, JSON.stringify(heads, null, 2)) + logger.debug(`Send latest heads of '${address}':\n`, JSON.stringify(heads.map(e => e.hash), null, 2)) room.sendTo(peer, JSON.stringify(heads)) } store.events.emit('peer', peer) diff --git a/test/create-open.test.js b/test/create-open.test.js index 1054441..98467fc 100644 --- a/test/create-open.test.js +++ b/test/create-open.test.js @@ -227,7 +227,7 @@ describe('orbit-db - Create & Open', function() { it('doesn\'t open a database if we don\'t have it locally', async () => { const address = new OrbitDBAddress(db.address.root.slice(0, -1) + 'A', 'non-existent') return new Promise((resolve, reject) => { - setTimeout(resolve, 1000) + setTimeout(resolve, 900) orbitdb.open(address) .then(() => reject(new Error('Shouldn\'t open the database'))) }) diff --git a/test/mocha.opts b/test/mocha.opts index 3c31715..31787ab 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1,4 +1,5 @@ --reporter spec --colors --recursive ---exit \ No newline at end of file +--exit +--slow 1000 \ No newline at end of file diff --git a/test/persistency.js b/test/persistency.js index 0fd6cda..50efeed 100644 --- a/test/persistency.js +++ b/test/persistency.js @@ -68,9 +68,37 @@ describe('orbit-db - Persistency', function() { const items = db.iterator({ limit: -1 }).collect() assert.equal(items.length, amount) assert.equal(items[0].payload.value, 'hello' + (entryCount - amount)) + assert.equal(items[1].payload.value, 'hello' + (entryCount - amount + 1)) assert.equal(items[items.length - 1].payload.value, 'hello99') }) + it('load and close several times', async () => { + const amount = 16 + for (let i = 0; i < amount; i ++) { + db = await orbitdb1.eventlog(address) + await db.load() + const items = db.iterator({ limit: -1 }).collect() + assert.equal(items.length, entryCount) + assert.equal(items[0].payload.value, 'hello0') + assert.equal(items[1].payload.value, 'hello1') + assert.equal(items[items.length - 1].payload.value, 'hello99') + await db.close() + } + }) + + it('load, add one, close - several times', async () => { + const amount = 8 + for (let i = 0; i < amount; i ++) { + db = await orbitdb1.eventlog(address) + await db.load() + await db.add('hello' + (entryCount + i)) + const items = db.iterator({ limit: -1 }).collect() + assert.equal(items.length, entryCount + i + 1) + assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount + i)) + await db.close() + } + }) + it('loading a database emits \'ready\' event', async () => { db = await orbitdb1.eventlog(address) return new Promise(async (resolve) => { @@ -155,6 +183,21 @@ describe('orbit-db - Persistency', function() { assert.equal(items[entryCount - 1].payload.value, 'hello99') }) + it('load, add one and save snapshot several times', async () => { + const amount = 8 + for (let i = 0; i < amount; i ++) { + db = await orbitdb1.eventlog(address) + await db.loadFromSnapshot() + await db.add('hello' + (entryCount + i)) + const items = db.iterator({ limit: -1 }).collect() + assert.equal(items.length, entryCount + i + 1) + assert.equal(items[0].payload.value, 'hello0') + assert.equal(items[items.length - 1].payload.value, 'hello' + (entryCount + i)) + await db.saveSnapshot() + await db.close() + } + }) + it('throws an error when trying to load a missing snapshot', async () => { db = await orbitdb1.eventlog(address) await db.drop() diff --git a/test/replicate-automatically.test.js b/test/replicate-automatically.test.js index 40751aa..74a32ff 100644 --- a/test/replicate-automatically.test.js +++ b/test/replicate-automatically.test.js @@ -41,11 +41,16 @@ describe('orbit-db - Automatic Replication', function() { if(orbitdb2) await orbitdb2.stop() - if (ipfs1) - await ipfs1.stop() + return new Promise((resolve) => { + setTimeout(async () => { + if (ipfs1) + await ipfs1.stop() - if (ipfs2) - await ipfs2.stop() + if (ipfs2) + await ipfs2.stop() + resolve() + }, 2000) + }) }) beforeEach(async () => { diff --git a/test/replicate.test.js b/test/replicate.test.js index 5dbb095..9e36304 100644 --- a/test/replicate.test.js +++ b/test/replicate.test.js @@ -10,47 +10,44 @@ const waitForPeers = require('./utils/wait-for-peers') const dbPath1 = './orbitdb/tests/replication/1' const dbPath2 = './orbitdb/tests/replication/2' -const ipfsPath1 = './orbitdb/tests/replication/1/ipfs' -const ipfsPath2 = './orbitdb/tests/replication/2/ipfs' +const ipfsPath1 = './orbitdb/tests/replication/ipfs/1' +const ipfsPath2 = './orbitdb/tests/replication/ipfs/2' + +const MemStore = require('./utils/mem-store') describe('orbit-db - Replication', function() { - this.timeout(config.timeout) + this.timeout(config.timeout * 2) let ipfs1, ipfs2, orbitdb1, orbitdb2, db1, db2 - before(async () => { - config.daemon1.repo = ipfsPath1 - config.daemon2.repo = ipfsPath2 - rmrf.sync(config.daemon1.repo) - rmrf.sync(config.daemon2.repo) - rmrf.sync(dbPath1) - 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) - }) - - after(async () => { - if(orbitdb1) - await orbitdb1.stop() - - if(orbitdb2) - await orbitdb2.stop() - - if (ipfs1) - await ipfs1.stop() - - if (ipfs2) - await ipfs2.stop() - }) - describe('two peers', function() { + let timer + let options + beforeEach(async () => { - let options = { + clearInterval(timer) + + config.daemon1.repo = ipfsPath1 + config.daemon2.repo = ipfsPath2 + rmrf.sync(config.daemon1.repo) + rmrf.sync(config.daemon2.repo) + rmrf.sync(dbPath1) + rmrf.sync(dbPath2) + ipfs1 = await startIpfs(config.daemon1) + ipfs2 = await startIpfs(config.daemon2) + // Use memory store for quicker tests + const memstore = new MemStore() + ipfs1.object.put = memstore.put.bind(memstore) + ipfs1.object.get = memstore.get.bind(memstore) + ipfs2.object.put = memstore.put.bind(memstore) + ipfs2.object.get = memstore.get.bind(memstore) + // 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) + + options = { // Set write access for both clients write: [ orbitdb1.key.getPublic('hex'), @@ -59,24 +56,52 @@ describe('orbit-db - Replication', function() { } options = Object.assign({}, options, { path: dbPath1 }) - db1 = await orbitdb1.eventlog('replication tests', options) + db1 = await orbitdb1.eventlog('replication-tests', options) // Set 'sync' flag on. It'll prevent creating a new local database and rather // fetch the database from the network - options = Object.assign({}, options, { path: dbPath2, sync: true }) - db2 = await orbitdb2.eventlog(db1.address.toString(), options) +// options = Object.assign({}, options, { path: dbPath2, sync: true }) +// db2 = await orbitdb2.eventlog(db1.address.toString(), options) - assert.equal(db1.address.toString(), db2.address.toString()) +// assert.equal(db1.address.toString(), db2.address.toString()) - await waitForPeers(ipfs1, [orbitdb2.id], db1.address.toString()) - await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) +// await waitForPeers(ipfs1, [orbitdb2.id], db1.address.toString()) +// await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) }) afterEach(async () => { - await db1.drop() - await db2.drop() + clearInterval(timer) + options = {} + + if (db1) + await db1.drop() + + if (db2) + await db2.drop() + + if(orbitdb1) + await orbitdb1.stop() + + if(orbitdb2) + await orbitdb2.stop() + + return new Promise((resolve) => { + setTimeout(async () => { + if (ipfs1) + await ipfs1.stop() + + if (ipfs2) + await ipfs2.stop() + + resolve() + }, 2000) + }) }) it('replicates database of 1 entry', async () => { + options = Object.assign({}, options, { path: dbPath2, sync: true }) + db2 = await orbitdb2.eventlog(db1.address.toString(), options) + await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) + await db1.add('hello') return new Promise(resolve => { setTimeout(() => { @@ -89,9 +114,12 @@ describe('orbit-db - Replication', function() { }) it('replicates database of 100 entries', async () => { + options = Object.assign({}, options, { path: dbPath2, sync: true }) + db2 = await orbitdb2.eventlog(db1.address.toString(), options) + await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) + const entryCount = 100 const entryArr = [] - let timer for (let i = 0; i < entryCount; i ++) entryArr.push(i) @@ -111,5 +139,367 @@ describe('orbit-db - Replication', function() { }, 1000) }) }) + + it('emits correct replication info', async () => { + options = Object.assign({}, options, { path: dbPath2, sync: true }) + db2 = await orbitdb2.eventlog(db1.address.toString(), options) + await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) + + let finished = false + let eventCount = { 'replicate': 0, 'replicate.progress': 0, 'replicated': 0 } + let events = [] + let expectedEventCount = 99 + + db2.events.on('replicate', (address, entry) => { + eventCount['replicate'] ++ + events.push({ + event: 'replicate', + count: eventCount['replicate'], + entry: entry, + }) + }) + + db2.events.on('replicate.progress', (address, hash, entry, progress) => { + eventCount['replicate.progress'] ++ + events.push({ + event: 'replicate.progress', + count: eventCount['replicate.progress'], + entry: entry , + replicationInfo: { + max: db2._replicationInfo.max, + progress: db2._replicationInfo.progress, + have: db2._replicationInfo.have, + }, + }) + }) + + db2.events.on('replicated', (address) => { + eventCount['replicated'] ++ + events.push({ + event: 'replicated', + count: eventCount['replicate'], + replicationInfo: { + max: db2._replicationInfo.max, + progress: db2._replicationInfo.progress, + have: db2._replicationInfo.have, + }, + }) + // Resolve with a little timeout to make sure we + // don't receive more than one event + setTimeout(() => { + finished = db2.iterator({ limit: -1 }).collect().length === expectedEventCount + }, 500) + }) + + return new Promise((resolve, reject) => { + timer = setInterval(() => { + if (finished) { + clearInterval(timer) + + assert.equal(eventCount['replicate'], expectedEventCount) + assert.equal(eventCount['replicate.progress'], expectedEventCount) + + const replicateEvents = events.filter(e => e.event === 'replicate') + assert.equal(replicateEvents.length, expectedEventCount) + assert.equal(replicateEvents[0].entry.payload.value.split(' ')[0], 'hello') + assert.equal(replicateEvents[0].entry.clock.time, 1) + + const replicateProgressEvents = events.filter(e => e.event === 'replicate.progress') + assert.equal(replicateProgressEvents.length, expectedEventCount) + assert.equal(replicateProgressEvents[0].entry.payload.value.split(' ')[0], 'hello') + assert.equal(replicateProgressEvents[0].entry.clock.time, 1) + assert.equal(replicateProgressEvents[0].replicationInfo.max, 1) + assert.equal(replicateProgressEvents[0].replicationInfo.progress, 1) + + const replicatedEvents = events.filter(e => e.event === 'replicated') + assert.equal(replicatedEvents[0].replicationInfo.max, 1) + assert.equal(replicatedEvents[0].replicationInfo.progress, 1) + + resolve() + } + }, 100) + + // Trigger replication + let adds = [] + for (let i = 0; i < expectedEventCount; i ++) { + adds.push(i) + } + + mapSeries(adds, i => db1.add('hello ' + i)) + }) + }) + + it('emits correct replication info on fresh replication', async () => { + return new Promise(async (resolve, reject) => { + let finished = false + let eventCount = { 'replicate': 0, 'replicate.progress': 0, 'replicated': 0 } + let events = [] + let expectedEventCount = 512 + + // Close second instance +// await db2.close() +// await db2.drop() + + // Trigger replication + let adds = [] + for (let i = 0; i < expectedEventCount; i ++) { + adds.push(i) + } + + const add = async (i) => { + process.stdout.write("\rWriting " + (i + 1) + " / " + expectedEventCount) + await db1.add('hello ' + i) + } + + await mapSeries(adds, add) + console.log() + + // Open second instance again + options = { + path: dbPath2, + overwrite: true, + sync: true, + // Set write access for both clients + write: [ + orbitdb1.key.getPublic('hex'), + orbitdb2.key.getPublic('hex') + ], + } + + db2 = await orbitdb2.eventlog(db1.address.toString(), options) + + let current = 0 + let total = 0 + + db2.events.on('replicate', (address, entry) => { + eventCount['replicate'] ++ + total = db2._replicationInfo.max + // console.log("[replicate] ", '#' + eventCount['replicate'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished) + events.push({ + event: 'replicate', + count: eventCount['replicate'], + entry: entry, + }) + }) + + db2.events.on('replicate.progress', (address, hash, entry) => { + eventCount['replicate.progress'] ++ + current = db2._replicationInfo.progress + // console.log("[progress] ", '#' + eventCount['replicate.progress'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished) + // assert.equal(db2._replicationInfo.progress, eventCount['replicate.progress']) + events.push({ + event: 'replicate.progress', + count: eventCount['replicate.progress'], + entry: entry , + replicationInfo: { + max: db2._replicationInfo.max, + progress: db2._replicationInfo.progress, + have: db2._replicationInfo.have, + }, + }) + }) + + db2.events.on('replicated', (address, length) => { + eventCount['replicated'] += length + current = db2._replicationInfo.progress + // console.log("[replicated]", '#' + eventCount['replicated'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished, "|", db2._loader._stats.a, db2._loader._stats.b, db2._loader._stats.c, db2._loader._stats.d) + assert.equal(current, eventCount['replicated']) + assert.equal(total, expectedEventCount) + + // Test the replicator state + assert.equal(db2._loader.tasksRequested >= current, true) + assert.equal(db2._loader.tasksQueued <= db2.options.referenceCount, true) + assert.equal(db2.options.referenceCount, 64) + assert.equal(db2._loader.tasksRunning, 0) + assert.equal(db2._loader.tasksFinished, current) + + events.push({ + event: 'replicated', + count: eventCount['replicate'], + replicationInfo: { + max: db2._replicationInfo.max, + progress: db2._replicationInfo.progress, + have: db2._replicationInfo.have, + }, + }) + // Resolve with a little timeout to make sure we + // don't receive more than one event + setTimeout(() => { + //console.log(eventCount['replicate.progress'], expectedEventCount) + + if (eventCount['replicate.progress'] === expectedEventCount) + finished = true + }, 500) + }) + + const st = new Date().getTime() + timer = setInterval(async () => { + if (finished) { + clearInterval(timer) + + const et = new Date().getTime() + console.log("Duration:", et - st, "ms") + + assert.equal(eventCount['replicate'], expectedEventCount) + assert.equal(eventCount['replicate.progress'], expectedEventCount) + + const replicateEvents = events.filter(e => e.event === 'replicate') + assert.equal(replicateEvents.length, expectedEventCount) + assert.equal(replicateEvents[0].entry.payload.value.split(' ')[0], 'hello') + assert.equal(replicateEvents[0].entry.clock.time, expectedEventCount) + + const replicateProgressEvents = events.filter(e => e.event === 'replicate.progress') + assert.equal(replicateProgressEvents.length, expectedEventCount) + assert.equal(replicateProgressEvents[0].entry.payload.value.split(' ')[0], 'hello') + assert.equal(replicateProgressEvents[0].entry.clock.time, expectedEventCount) + assert.equal(replicateProgressEvents[0].replicationInfo.max, expectedEventCount) + assert.equal(replicateProgressEvents[0].replicationInfo.progress, 1) + + const replicatedEvents = events.filter(e => e.event === 'replicated') + assert.equal(replicatedEvents[0].replicationInfo.max, expectedEventCount) + assert.equal(replicatedEvents[replicatedEvents.length - 1].replicationInfo.progress, expectedEventCount) + + resolve() + } + }, 100) + }) + }) + + it('emits correct replication info in two-way replication', async () => { + return new Promise(async (resolve, reject) => { + let finished = false + let eventCount = { 'replicate': 0, 'replicate.progress': 0, 'replicated': 0 } + let events = [] + let expectedEventCount = 100 + + // Trigger replication + let adds = [] + for (let i = 0; i < expectedEventCount; i ++) { + adds.push(i) + } + + const add = async (i) => { + // process.stdout.write("\rWriting " + (i + 1) + " / " + expectedEventCount) + await Promise.all([db1.add('hello-1-' + i), db2.add('hello-2-' + i)]) + } + + // Open second instance again + let options = { + path: dbPath2, + overwrite: true, + sync: true, + // Set write access for both clients + write: [ + orbitdb1.key.getPublic('hex'), + orbitdb2.key.getPublic('hex') + ], + } + db2 = await orbitdb2.eventlog(db1.address.toString(), options) + await waitForPeers(ipfs2, [orbitdb1.id], db1.address.toString()) + + let current = 0 + let total = 0 + + db2.events.on('replicate', (address, entry) => { + eventCount['replicate'] ++ + current = db2._replicationInfo.progress + total = db2._replicationInfo.max + // console.log("[replicate] ", '#' + eventCount['replicate'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished) + events.push({ + event: 'replicate', + count: eventCount['replicate'], + entry: entry, + }) + }) + + let prevProgress = 0 + db2.events.on('replicate.progress', (address, hash, entry) => { + eventCount['replicate.progress'] ++ + current = db2._replicationInfo.progress + total = db2._replicationInfo.max + // console.log("[progress] ", '#' + eventCount['replicate.progress'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished) + // assert.equal(current, total) + events.push({ + event: 'replicate.progress', + count: eventCount['replicate.progress'], + entry: entry , + replicationInfo: { + max: db2._replicationInfo.max, + progress: db2._replicationInfo.progress, + have: db2._replicationInfo.have, + }, + }) + }) + + db2.events.on('replicated', (address, length) => { + eventCount['replicated'] += length + current = db2._replicationInfo.progress + total = db2._replicationInfo.max + const values = db2.iterator({limit: -1}).collect() + // console.log(current, "/", total, "/", values.length) + //console.log("[replicated]", '#' + eventCount['replicated'] + ':', current, '/', total, '| Tasks (in/queued/running/out):', db2._loader.tasksRequested, '/', db2._loader.tasksQueued, '/', db2._loader.tasksRunning, '/', db2._loader.tasksFinished, "|", db2._loader._stats.a, db2._loader._stats.b, db2._loader._stats.c, db2._loader._stats.d) + assert.equal(current <= total, true) + events.push({ + event: 'replicated', + count: eventCount['replicate'], + replicationInfo: { + max: db2._replicationInfo.max, + progress: db2._replicationInfo.progress, + have: db2._replicationInfo.have, + }, + }) + + if (db2._replicationInfo.max >= expectedEventCount * 2 + && db2._replicationInfo.progress >= expectedEventCount * 2) + finished = true + }) + + const st = new Date().getTime() + + await mapSeries(adds, add) + + timer = setInterval(async () => { + if (finished) { + clearInterval(timer) + + const et = new Date().getTime() + console.log("Duration:", et - st, "ms") + + assert.equal(eventCount['replicate'], expectedEventCount) + assert.equal(eventCount['replicate.progress'], expectedEventCount) + assert.equal(eventCount['replicated'], expectedEventCount) + + const replicateEvents = events.filter(e => e.event === 'replicate') + assert.equal(replicateEvents.length, expectedEventCount) + + const replicateProgressEvents = events.filter(e => e.event === 'replicate.progress') + assert.equal(replicateProgressEvents.length, expectedEventCount) + assert.equal(replicateProgressEvents[replicateProgressEvents.length - 1].entry.clock.time, expectedEventCount) + assert.equal(replicateProgressEvents[replicateProgressEvents.length - 1].replicationInfo.max, expectedEventCount * 2) + assert.equal(replicateProgressEvents[replicateProgressEvents.length - 1].replicationInfo.progress, expectedEventCount * 2) + + const replicatedEvents = events.filter(e => e.event === 'replicated') + assert.equal(replicatedEvents[replicatedEvents.length - 1].replicationInfo.progress, expectedEventCount * 2) + assert.equal(replicatedEvents[replicatedEvents.length - 1].replicationInfo.max, expectedEventCount * 2) + + const values1 = db1.iterator({limit: -1}).collect() + const values2 = db2.iterator({limit: -1}).collect() + assert.deepEqual(values1, values2) + + // Test the replicator state + assert.equal(db1._loader.tasksRequested, expectedEventCount) + assert.equal(db1._loader.tasksQueued, 0) + assert.equal(db1._loader.tasksRunning, 0) + assert.equal(db1._loader.tasksFinished, expectedEventCount) + assert.equal(db2._loader.tasksRequested, expectedEventCount) + assert.equal(db2._loader.tasksQueued, 0) + assert.equal(db2._loader.tasksRunning, 0) + assert.equal(db2._loader.tasksFinished, expectedEventCount) + + resolve() + } + }, 100) + }) + }) }) }) diff --git a/test/utils/mem-store.js b/test/utils/mem-store.js new file mode 100644 index 0000000..412cbc5 --- /dev/null +++ b/test/utils/mem-store.js @@ -0,0 +1,95 @@ +'use strict' + +const multihashing = require('multihashing-async') +const mh = require('multihashes') + +const defaultHashAlg = 'sha2-256' + +// 'use strict' + +// const ImmutableDB = require('./immutabledb-interface') + +const defaultFormat = { format: 'dag-cbor', hashAlg: 'sha2-256' } + +/* ImmutableDB using IPLD (through IPFS) */ +class IPLDStore { + constructor (ipfs) { + // super() + this._ipfs = ipfs + } + + async put (value) { + const cid = await this._ipfs.dag.put(value, defaultFormat) + return cid.toBaseEncodedString() + } + + async get (key) { + const result = await this._ipfs.dag.get(key) + return result.value + } +} + +const createMultihash = (data, hashAlg) => { + return new Promise((resolve, reject) => { + multihashing(data, hashAlg || defaultHashAlg, (err, multihash) => { + if (err) + return reject(err) + + resolve(mh.toB58String(multihash)) + }) + }) +} + +// const LRU = require('lru') +// const ImmutableDB = require('./immutabledb-interface') +// const createMultihash = require('./create-multihash') + +/* Memory store using an LRU cache */ +class MemStore { + constructor () { + this._store = {}//new LRU(1000) + } + + async put (value) { + const data = value//new Buffer(JSON.stringify(value)) + const hash = await createMultihash(data) + // console.log(this._store) + // this._store.set(hash, data) + if (!this._store) this._store = {} + // console.log(this._store) + // console.log(hash, data) + this._store[hash] = data + // return hash + return { + toJSON: () => { + return { + data: value, + multihash: hash, + } + } + } + } + + async get (key) { + // const data = this._store.get(key) + const data = this._store[key] + + // if (data) { + // const value = JSON.parse(data) + // return value + // } + + // return data + return { + toJSON: () => { + return { + data: this._store[key], + multihash: key, + } + } + } + } +} + + +module.exports = MemStore diff --git a/test/write-permissions.test.js b/test/write-permissions.test.js index 1ba61b6..8249130 100644 --- a/test/write-permissions.test.js +++ b/test/write-permissions.test.js @@ -97,6 +97,9 @@ describe('orbit-db - Write Permissions', function() { assert.deepEqual(database.getTestValue(db1), database.expectedValue) assert.deepEqual(database.getTestValue(db2), database.expectedValue) + + await db1.close() + await db2.close() }) }) }) @@ -122,9 +125,11 @@ describe('orbit-db - Write Permissions', function() { db1.sync(db2._oplog.heads) return new Promise(resolve => { - setTimeout(() => { + setTimeout(async () => { const value = database.getTestValue(db1) assert.deepEqual(value, database.expectedValue) + await db1.close() + await db2.close() resolve() }, 300) }) @@ -150,9 +155,11 @@ describe('orbit-db - Write Permissions', function() { db1.sync(db2._oplog.heads) return new Promise(resolve => { - setTimeout(() => { + setTimeout(async () => { const value = database.getTestValue(db1) assert.deepEqual(value, database.expectedValue) + await db1.close() + await db2.close() resolve() }, 300) }) @@ -194,9 +201,11 @@ describe('orbit-db - Write Permissions', function() { db1.sync(db2._oplog.heads) return new Promise((resolve, reject) => { - setTimeout(() => { + setTimeout(async () => { // Make sure nothing was added assert.equal(database.query(db1).length, 0) + await db1.close() + await db2.close() if (err) { reject(err) } else { @@ -219,7 +228,7 @@ describe('orbit-db - Write Permissions', function() { let err try { const db1 = await database.create(orbitdb1, 'write error test 2', options) - options = Object.assign({}, options, { sync: true }) + options = Object.assign({}, options, { sync: true }) const db2 = await database.create(orbitdb2, db1.address.toString(), options) await database.tryInsert(db2) } catch (e) {