From b3b219c51ab433695be463a95c90c3ac963246d9 Mon Sep 17 00:00:00 2001 From: shamb0t Date: Thu, 20 Dec 2018 10:40:31 +0400 Subject: [PATCH] Update build --- dist/ipfslog.min.js | 4 ++-- lib/es5/entry.js | 8 ++++---- lib/es5/g-set.js | 3 ++- lib/es5/log-io.js | 8 ++++---- lib/es5/log.js | 20 +++++++------------- lib/es5/utils/index.js | 2 -- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/dist/ipfslog.min.js b/dist/ipfslog.min.js index 48e0d92d..c895e2ce 100644 --- a/dist/ipfslog.min.js +++ b/dist/ipfslog.min.js @@ -1,8 +1,8 @@ -var Log=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=7)}([function(t,r,e){"use strict";class n{constructor(t,r){this.id=t,this.time=r||0}tick(){return new n(this.id,++this.time)}merge(t){return this.time=Math.max(this.time,t.time),new n(this.id,this.time)}clone(){return new n(this.id,this.time)}static compare(t,r){var e=t.time-r.time;return 0===e&&t.id!==r.id?t.idnew Error("Ipfs instance not defined");class s{static async create(t,r,e,a,h=[],u){if(!i(t))throw o();if(!i(r))throw new Error("Identity is required, cannot create entry");if(!i(e))throw new Error("Entry requires an id");if(!i(a))throw new Error("Entry requires data");if(!i(h)||!Array.isArray(h))throw new Error("'next' argument is not an array");const c={hash:null,id:e,payload:a,next:h.filter(i).map(t=>t.hash?t.hash:t),v:0,clock:u||new n(r.publicKey)},f=await r.provider.sign(r,s.toBuffer(c));return c.key=r.publicKey,c.identity=r.toJSON(),c.sig=f,c.hash=await s.toMultihash(t,c),c}static async verify(t,r){if(!t)throw new Error("Identity-provider is required, cannot verify entry");if(!s.isEntry(r))throw new Error("Invalid Log entry");if(!r.key)throw new Error("Entry doesn't have a key");if(!r.sig)throw new Error("Entry doesn't have a signature");const e=Object.assign({},{hash:null,id:r.id,payload:r.payload,next:r.next,v:r.v,clock:new n(r.clock.id,r.clock.time)});return t.verify(r.sig,r.key,s.toBuffer(e))}static toBuffer(t){return r.from(JSON.stringify(t))}static async toMultihash(t,r){if(!t)throw o();if(!(t=>t.id&&t.clock&&t.next&&t.payload&&t.v>=0)(r))throw new Error("Invalid object format, cannot generate entry multihash");const e={hash:null,id:r.id,payload:r.payload,next:r.next,v:r.v,clock:r.clock};r.key&&Object.assign(e,{key:r.key}),r.identity&&Object.assign(e,{identity:r.identity}),r.sig&&Object.assign(e,{sig:r.sig});const n=s.toBuffer(e);return(await t.object.put(n)).toJSON().multihash}static async fromMultihash(t,r){if(!t)throw o();if(!r)throw new Error(`Invalid hash: ${r}`);const e=await t.object.get(r,{enc:"base58"}),i=JSON.parse(e.toJSON().data);let s={hash:r,id:i.id,payload:i.payload,next:i.next,v:i.v,clock:new n(i.clock.id,i.clock.time)};return i.key&&Object.assign(s,{key:i.key}),i.identity&&Object.assign(s,{identity:i.identity}),i.sig&&Object.assign(s,{sig:i.sig}),s}static isEntry(t){return t&&void 0!==t.id&&void 0!==t.next&&void 0!==t.hash&&void 0!==t.payload&&void 0!==t.v&&void 0!==t.clock}static compare(t,r){var e=n.compare(t.clock,r.clock);return 0===e?t.clock.id-1}static findChildren(t,r){for(var e=[],n=r.find(r=>s.isParent(t,r)),i=t;n;)e.push(n),i=n,n=r.find(t=>s.isParent(i,t));return e=e.sort((t,r)=>t.clock.time>r.clock.time)}}t.exports=s}).call(r,e(3).Buffer)},function(t,r,e){"use strict";const n=e(13),i=e(14),o=e(15),s=e(16);t.exports={difference:n,findUniques:i,intersection:o,isDefined:s}},function(t,r,e){"use strict";(function(t){ +var Log=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=6)}([function(t,r,e){"use strict";class n{constructor(t,r){this.id=t,this.time=r||0}tick(){return new n(this.id,++this.time)}merge(t){return this.time=Math.max(this.time,t.time),new n(this.id,this.time)}clone(){return new n(this.id,this.time)}static compare(t,r){var e=t.time-r.time;return 0===e&&t.id!==r.id?t.idnew Error("Ipfs instance not defined");class s{static async create(t,r,e,a,h=[],u){if(!i(t))throw o();if(!i(r))throw new Error("Identity is required, cannot create entry");if(!i(e))throw new Error("Entry requires an id");if(!i(a))throw new Error("Entry requires data");if(!i(h)||!Array.isArray(h))throw new Error("'next' argument is not an array");const f={hash:null,id:e,payload:a,next:h.filter(i).map(t=>t.hash?t.hash:t),v:0,clock:u||new n(r.publicKey)},c=await r.provider.sign(r,s.toBuffer(f));return f.key=r.publicKey,f.identity=r.toJSON(),f.sig=c,f.hash=await s.toMultihash(t,f),f}static async verify(t,r){if(!t)throw new Error("Identity-provider is required, cannot verify entry");if(!s.isEntry(r))throw new Error("Invalid Log entry");if(!r.key)throw new Error("Entry doesn't have a key");if(!r.sig)throw new Error("Entry doesn't have a signature");const e=Object.assign({},{hash:null,id:r.id,payload:r.payload,next:r.next,v:r.v,clock:new n(r.clock.id,r.clock.time)});return t.verify(r.sig,r.key,s.toBuffer(e))}static toBuffer(t){return r.from(JSON.stringify(t))}static async toMultihash(t,r){if(!t)throw o();if(!(t=>t.id&&t.clock&&t.next&&t.payload&&t.v>=0)(r))throw new Error("Invalid object format, cannot generate entry multihash");const e={hash:null,id:r.id,payload:r.payload,next:r.next,v:r.v,clock:r.clock};r.key&&Object.assign(e,{key:r.key}),r.identity&&Object.assign(e,{identity:r.identity}),r.sig&&Object.assign(e,{sig:r.sig});const n=s.toBuffer(e);return(await t.dag.put(n)).toBaseEncodedString()}static async fromMultihash(t,r){if(!t)throw o();if(!r)throw new Error(`Invalid hash: ${r}`);const e=await t.dag.get(r),i=JSON.parse(e.value);let s={hash:r,id:i.id,payload:i.payload,next:i.next,v:i.v,clock:new n(i.clock.id,i.clock.time)};return i.key&&Object.assign(s,{key:i.key}),i.identity&&Object.assign(s,{identity:i.identity}),i.sig&&Object.assign(s,{sig:i.sig}),s}static isEntry(t){return t&&void 0!==t.id&&void 0!==t.next&&void 0!==t.hash&&void 0!==t.payload&&void 0!==t.v&&void 0!==t.clock}static compare(t,r){var e=n.compare(t.clock,r.clock);return 0===e?t.clock.id-1}static findChildren(t,r){for(var e=[],n=r.find(r=>s.isParent(t,r)),i=t;n;)e.push(n),i=n,n=r.find(t=>s.isParent(i,t));return e=e.sort((t,r)=>t.clock.time>r.clock.time)}}t.exports=s}).call(r,e(3).Buffer)},function(t,r,e){"use strict";const n=e(12),i=e(13),o=e(14);t.exports={difference:n,findUniques:i,isDefined:o}},function(t,r,e){"use strict";(function(t){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ -var n=e(9),i=e(10),o=e(11);function s(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,r){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function p(t,r){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return j(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return q(t).length;default:if(n)return j(t).length;r=(""+r).toLowerCase(),n=!0}}function y(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function g(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=h.from(r,n)),h.isBuffer(r))return 0===r.length?-1:w(t,r,e,n,i);if("number"==typeof r)return r&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):w(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function w(t,r,e,n,i){var o,s=1,a=t.length,h=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;s=2,a/=2,h/=2,e/=2}function u(t,r){return 1===s?t[r]:t.readUInt16BE(r*s)}if(i){var c=-1;for(o=e;oa&&(e=a-h),o=e;o>=0;o--){for(var f=!0,l=0;li&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function x(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function I(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:u>223?3:u>191?2:1;if(i+f<=e)switch(f){case 1:u<128&&(c=u);break;case 2:128==(192&(o=t[i+1]))&&(h=(31&u)<<6|63&o)>127&&(c=h);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(h=(15&u)<<12|(63&o)<<6|63&s)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(h=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&h<1114112&&(c=h)}null===c?(c=65533,f=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=f}return function(t){var r=t.length;if(r<=P)return String.fromCharCode.apply(String,t);var e="",n=0;for(;nthis.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return k(this,r,e);case"utf8":case"utf-8":return I(this,r,e);case"ascii":return S(this,r,e);case"latin1":case"binary":return R(this,r,e);case"base64":return x(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},h.prototype.equals=function(t){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===h.compare(this,t)},h.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},h.prototype.compare=function(t,r,e,n,i){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(r>>>=0,e>>>=0,n>>>=0,i>>>=0,this===t)return 0;for(var o=i-n,s=e-r,a=Math.min(o,s),u=this.slice(n,i),c=t.slice(r,e),f=0;fi)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,r,e);case"utf8":case"utf-8":return E(this,t,r,e);case"ascii":return m(this,t,r,e);case"latin1":case"binary":return _(this,t,r,e);case"base64":return b(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var P=4096;function S(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;in)&&(e=n);for(var i="",o=r;oe)throw new RangeError("Trying to access beyond buffer length")}function T(t,r,e,n,i,o){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||rt.length)throw new RangeError("Index out of range")}function U(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i>>8*(n?i:1-i)}function M(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i>>8*(n?i:3-i)&255}function N(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Y(t,r,e,n,o){return o||N(t,0,e,4),i.write(t,r,e,n,23,4),e+4}function D(t,r,e,n,o){return o||N(t,0,e,8),i.write(t,r,e,n,52,8),e+8}h.prototype.slice=function(t,r){var e,n=this.length;if(t=~~t,r=void 0===r?n:~~r,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),r<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(i*=256);)n+=this[t+--r]*i;return n},h.prototype.readUInt8=function(t,r){return r||O(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,r){return r||O(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,r){return r||O(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,r){return r||O(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,r){return r||O(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||O(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},h.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||O(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},h.prototype.readInt8=function(t,r){return r||O(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,r){r||O(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},h.prototype.readInt16BE=function(t,r){r||O(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},h.prototype.readInt32LE=function(t,r){return r||O(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,r){return r||O(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,r){return r||O(t,4,this.length),i.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,r){return r||O(t,4,this.length),i.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,r){return r||O(t,8,this.length),i.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,r){return r||O(t,8,this.length),i.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||T(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o=0&&(o*=256);)this[r+i]=t/o&255;return r+e},h.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},h.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):U(this,t,r,!0),r+2},h.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):U(this,t,r,!1),r+2},h.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):M(this,t,r,!0),r+4},h.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):M(this,t,r,!1),r+4},h.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);T(this,t,r,e,i-1,-i)}var o=0,s=1,a=0;for(this[r]=255&t;++o>0)-a&255;return r+e},h.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);T(this,t,r,e,i-1,-i)}var o=e-1,s=1,a=0;for(this[r+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[r+o+1]&&(a=1),this[r+o]=(t/s>>0)-a&255;return r+e},h.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},h.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):U(this,t,r,!0),r+2},h.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):U(this,t,r,!1),r+2},h.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):M(this,t,r,!0),r+4},h.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||T(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):M(this,t,r,!1),r+4},h.prototype.writeFloatLE=function(t,r,e){return Y(this,t,r,!0,e)},h.prototype.writeFloatBE=function(t,r,e){return Y(this,t,r,!1,e)},h.prototype.writeDoubleLE=function(t,r,e){return D(this,t,r,!0,e)},h.prototype.writeDoubleBE=function(t,r,e){return D(this,t,r,!1,e)},h.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=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),t.length-r=0;--i)t[i+r]=this[i+e];else if(o<1e3||!h.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function q(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(L,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function F(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}}).call(r,e(8))},function(t,r,e){"use strict";t.exports=((t,r,e)=>new Promise((n,i)=>{if(e=Object.assign({concurrency:1/0},e),"function"!=typeof r)throw new TypeError("Mapper function is required");const o=e.concurrency;if(!("number"==typeof o&&o>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${o}\` (${typeof o})`);const s=[],a=t[Symbol.iterator]();let h=!1,u=!1,c=0,f=0;const l=()=>{if(h)return;const t=a.next(),e=f;if(f++,t.done)return u=!0,void(0===c&&n(s));c++,Promise.resolve(t.value).then(t=>r(t,e)).then(t=>{s[e]=t,c--,l()},t=>{h=!0,i(t)})};for(let t=0;tnew Error("IPFS instance not defined"),LogNotDefinedError:()=>new Error("Log instance not defined"),NotALogError:()=>new Error("Given argument is not an instance of Log")}},function(t,r,e){"use strict";t.exports=(t=>void 0!==t&&null!==t)},function(t,r,e){"use strict";(function(r){const n=e(4),i=e(12),o=e(1),s=e(17),a=e(5),h=e(0),{LastWriteWins:u}=e(20),c=e(21),f=e(22),{isDefined:l,findUniques:d}=e(2),p=()=>(new Date).getTime().toString(),y=t=>t.hash,g=(t,r)=>t.concat(r),w=t=>t.next,v=(t,r)=>Math.max(t,r.clock.time),E=(t,r)=>(t[r.hash]=r,t);class m extends i{constructor(t,r,e,n,i,o,s){if(!l(t))throw a.IPFSNotDefinedError();if(!l(r))throw new Error("Access controller is required");if(!l(e))throw new Error("Identity is required");if(l(i)&&!Array.isArray(i))throw new Error("'entries' argument must be an array of Entry instances");if(l(o)&&!Array.isArray(o))throw new Error("'heads' argument must be an array");super(),this._storage=t,this._id=n||p(),this._access=r,this._identity=e,i=i||[],this._entryIndex=i.reduce(E,{}),o=o||m.findHeads(i),this._headsIndex=o.reduce(E,{}),this._nextsIndex={};i.forEach(t=>t.next.forEach(r=>this._nextsIndex[r]=t.hash)),this._length=i?i.length:0;const u=Math.max(s?s.time:0,this.heads.reduce(v,0));this._clock=new h(this._identity.publicKey,u)}get id(){return this._id}get clock(){return this._clock}get length(){return this._length}get values(){return Object.values(this._entryIndex).sort(u)}get heads(){return Object.values(this._headsIndex)||[]}get tails(){return m.findTails(this.values)}get tailHashes(){return m.findTailHashes(this.values)}get(t){return this._entryIndex[t]}has(t){return void 0!==this._entryIndex[t.hash||t]}traverse(t,r){let e=t.map(w).reduce(g,[]),n={},i={},o=0;const s=t=>{i[t]||n[t]||(e.push(t),n[t]=!0)};for(t.forEach(t=>{i[t.hash]=t.hash,n[t.hash]=!0,o++});e.length>0&&othis._nextsIndex[t]=i.hash),this._headsIndex={},this._headsIndex[i.hash]=i,this._length++,i}async join(t,r=-1){if(!l(t))throw a.LogNotDefinedError();if(!m.isLog(t))throw a.NotALogError();const e=m.difference(t,this),i=this._identity.provider,s=Object.values(e);await n(s,async t=>{if(!await this._access.canAppend(t,i))throw new Error("Append not permitted")},{concurrency:1}),await n(s,async t=>{const r=await o.verify(i,t),e=t.identity?t.identity.publicKey:t.key;if(!r)throw new Error(`Could not validate signature "${t.sig}" for entry "${t.hash}" and key "${e}"`)},{concurrency:1}),this._entryIndex=Object.assign(this._entryIndex,e);if(Object.values(e).forEach(t=>t.next.forEach(r=>this._nextsIndex[r]=t.hash)),this._length+=Object.values(e).length,r>-1){let t=this.values;t=t.slice(-r),this._entryIndex=t.reduce(E,{}),this._length=Object.values(this._entryIndex).length}const u=Object.values(e).map(w).reduce(g,[]),c=m.findHeads(Object.values(Object.assign({},this._headsIndex,t._headsIndex))).filter(t=>!u.find(r=>r===t.hash)).filter(t=>!this._nextsIndex[t.hash]).reduce(E,{});this._headsIndex=c;const f=Object.values(this._headsIndex).reduce(v,0);return this._clock=new h(this.clock.id,Math.max(this.clock.time,f)),this}toJSON(){return{id:this.id,heads:this.heads.map(y)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return r.from(JSON.stringify(this.toJSON()))}toString(t){return this.values.slice().reverse().map((r,e)=>{const n=o.findChildren(r,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("")+(t?t(r.payload):r.payload)}).join("\n")}static isLog(t){return void 0!==t.id&&void 0!==t.heads&&void 0!==t._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static async fromMultihash(t,r,e,n,i=-1,o,h){if(!l(t))throw a.IPFSNotDefinedError();if(!l(n))throw new Error(`Invalid hash: ${n}`);const u=await s.fromMultihash(t,n,i,o,h);return new m(t,r,e,u.id,u.values,u.heads,u.clock)}static async fromEntryHash(t,r,e,n,i,o=-1,h,u){if(!l(t))throw a.IPFSNotDefinedError();if(!l(n))throw new Error("'hash' must be defined");const c=await s.fromEntryHash(t,n,i,o,h,u);return new m(t,r,e,i,c.values)}static async fromJSON(t,r,e,n,i=-1,o,h){if(!l(t))throw a.IPFSNotDefinedError();const u=await s.fromJSON(t,n,i,o,h);return new m(t,r,e,u.id,u.values)}static async fromEntry(t,r,e,n,i=-1,o,h){if(!l(t))throw a.IPFSNotDefinedError();if(!l(n))throw new Error("'sourceEntries' must be defined");const u=await s.fromEntry(t,n,i,o,h);return new m(t,r,e,u.id,u.values)}static findHeads(t){var r=t.reduce((t,r,e,n)=>{return r.next.forEach(e=>t[e]=r.hash),t},{});return t.filter(t=>void 0===r[t.hash]).sort((t,r)=>t.clock.id>r.clock.id)}static findTails(t){var r={},e=[],n={},i=[];t.forEach(t=>{0===t.next.length&&e.push(t);t.next.forEach(e=>{r[e]||(r[e]=[]),r[e].push(t)}),i=i.concat(t.next),n[t.hash]=!0});const s=i.filter(t=>void 0===n[t]).map(t=>r[t]).reduce((t,r,e,n)=>t.concat(d(r,"hash")),[]).concat(e);return d(s,"hash").sort(o.compare)}static findTailHashes(t){var r={};return t.forEach(t=>r[t.hash]=!0),t.reduce((t,e,n,i)=>{return e.next.reverse().forEach(e=>{void 0===r[e]&&t.splice(0,0,e)}),t},[])}static difference(t,r){let e=Object.keys(t._headsIndex),n={},i={};const o=t=>{n[t]||r.get(t)||(e.push(t),n[t]=!0)};for(;e.length>0;){const s=e.shift(),a=t.get(s);a&&!r.get(s)&&a.id===r.id&&(i[a.hash]=a,n[a.hash]=!0,a.next.forEach(o))}return i}}t.exports=m,t.exports.AccessController=c,t.exports.IdentityProvider=f}).call(r,e(3).Buffer)},function(t,r){var e;e=function(){return this}();try{e=e||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";r.byteLength=function(t){var r=u(t),e=r[0],n=r[1];return 3*(e+n)/4-n},r.toByteArray=function(t){for(var r,e=u(t),n=e[0],s=e[1],a=new o(function(t,r,e){return 3*(r+e)/4-e}(0,n,s)),h=0,c=s>0?n-4:n,f=0;f>16&255,a[h++]=r>>8&255,a[h++]=255&r;2===s&&(r=i[t.charCodeAt(f)]<<2|i[t.charCodeAt(f+1)]>>4,a[h++]=255&r);1===s&&(r=i[t.charCodeAt(f)]<<10|i[t.charCodeAt(f+1)]<<4|i[t.charCodeAt(f+2)]>>2,a[h++]=r>>8&255,a[h++]=255&r);return a},r.fromByteArray=function(t){for(var r,e=t.length,i=e%3,o=[],s=0,a=e-i;sa?a:s+16383));1===i?(r=t[e-1],o.push(n[r>>2]+n[r<<4&63]+"==")):2===i&&(r=(t[e-2]<<8)+t[e-1],o.push(n[r>>10]+n[r>>4&63]+n[r<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function c(t){return n[t>>18&63]+n[t>>12&63]+n[t>>6&63]+n[63&t]}function f(t,r,e){for(var n,i=[],o=r;o>1,c=-7,f=e?i-1:0,l=e?-1:1,d=t[r+f];for(f+=l,o=d&(1<<-c)-1,d>>=-c,c+=a;c>0;o=256*o+t[r+f],f+=l,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=256*s+t[r+f],f+=l,c-=8);if(0===o)o=1-u;else{if(o===h)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=u}return(d?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var s,a,h,u=8*o-i-1,c=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,y=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,s=c):(s=Math.floor(Math.log(r)/Math.LN2),r*(h=Math.pow(2,-s))<1&&(s--,h*=2),(r+=s+f>=1?l/h:l*Math.pow(2,1-f))*h>=2&&(s++,h/=2),s+f>=c?(a=0,s=c):s+f>=1?(a=(r*h-1)*Math.pow(2,i),s+=f):(a=r*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[e+d]=255&a,d+=p,a/=256,i-=8);for(s=s<0;t[e+d]=255&s,d+=p,s/=256,u-=8);t[e+d-p]|=128*y}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r,e){"use strict";t.exports=class{constuctor(t){}append(t){}merge(t){}get(t){}has(t){}get values(){}get length(){}}},function(t,r,e){"use strict";t.exports=function(t,r,e){var n={},i={};return t.forEach(t=>i[e?t[e]:t]=!0),r.reduce((t,r)=>{var o=void 0!==i[e?r[e]:r],s=void 0!==n[e?r[e]:r];return o||s||(t.push(r),n[e?r[e]:r]=!0),t},[])}},function(t,r,e){"use strict";t.exports=function(t,r){let e={};return t.forEach(t=>e[r?t[r]:t]=t),Object.keys(e).map(t=>e[t])}},function(t,r,e){"use strict";t.exports=function(t,r,e){var n={},i={};return t.forEach(t=>i[e?t[e]:t]=!0),r.reduce((t,r)=>{var o=void 0!==i[e?r[e]:r],s=void 0!==n[e?r[e]:r];return o&&!s&&(t.push(r),n[e?r[e]:r]=!0),t},[])}},function(t,r,e){"use strict";t.exports=(t=>void 0!==t&&null!==t)},function(t,r,e){"use strict";const n=e(1),i=e(18),o=e(0),s=e(5),{isDefined:a,findUniques:h,difference:u}=e(2),c=(t,r)=>t.slice(t.length-r,t.length);t.exports=class{static async toMultihash(t,r){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw s.LogNotDefinedError();if(r.values.length<1)throw new Error("Can't serialize an empty log");return(await t.object.put(r.toBuffer())).toJSON().multihash}static async fromMultihash(t,r,e=-1,h,u){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw new Error(`Invalid hash: ${r}`);const c=await t.object.get(r,{enc:"base58"}),f=JSON.parse(c.toJSON().data);if(!f.heads||!f.id)throw s.NotALogError();const l=await i.fetchAll(t,f.heads,e,h,null,u),d=l.reduce((t,r)=>r.clock.time>t.time?new o(r.clock.id,r.clock.time):t,new o(f.id)),p=l.slice().sort(n.compare),y=p.filter(t=>f.heads.includes(t.hash));return{id:f.id,values:p,heads:y,clock:d}}static async fromEntryHash(t,r,e,n=-1,o,h){if(!a(t))throw s.IpfsNotDefinedError();if(!a(r))throw new Error("'entryHash' must be defined");n=n>-1?Math.max(n,1):n;const u=o,f=await i.fetchParallel(t,[r],n,u,null,null,h);return{values:n>-1?c(f,n):f}}static async fromJSON(t,r,e=-1,o,h){if(!a(t))throw s.IPFSNotDefinedError();const u=r.heads.map(t=>t.hash),c=(await i.fetchParallel(t,u,e,[],16,o,h)).slice().sort(n.compare);return{id:r.id,values:c,heads:r.heads}}static async fromEntry(t,r,e=-1,o,c){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(r)&&!n.isEntry(r))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(r)||(r=[r]),e=e>-1?Math.max(e,r.length):e;const f=o?o.map(t=>t.hash?t.hash:t):o,l=r.map(t=>t.hash),d=await i.fetchParallel(t,l,e,f,null,null,c),p=r.concat(d),y=h(p,"hash").sort(n.compare),g=y.slice(e>-1?-e:-y.length),w=((t,r)=>{var e=t.slice(r.length,t.length);return r.concat(e)})(g,u(g,r,"hash"));return{id:w[w.length-1].id,values:w}}}},function(t,r,e){"use strict";const n=e(19),i=e(4),o=e(1);class s{static async fetchParallel(t,r,e,n=[],o,a,h){const u=(t,r)=>t.concat(r);return o=Math.max(o||r.length,1),(t=>t.reduce(u,[]))(await i(r,r=>s.fetchAll(t,r,e,n,a,h),{concurrency:o}))}static async fetchAll(t,r,e,i=[],s=null,a){let h=[],u={},c=Array.isArray(r)?r.slice():[r];const f=t=>c.push(t);(i=i&&Array.isArray(i)?i:[]).forEach(t=>u[t.hash]=t);return await n(()=>c.length>0&&(h.length{const r=c.shift();return u[r]?Promise.resolve():new Promise(async(e,n)=>{const i=s?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${r}', request timed out (${s}ms)`),e()},s):null;try{(t=>{clearTimeout(i),o.isEntry(t)&&(t.next.forEach(f),h.push(t),u[r]=t,a&&a(r,t,h.length))})(await o.fromMultihash(t,r)),e()}catch(t){n(t)}})}),h}}t.exports=s},function(t,r,e){"use strict";const n=t=>new Promise(r=>{r(t())});t.exports=((t,r)=>n(function e(){if(t())return n(r).then(e)}))},function(t,r,e){"use strict";const n=e(0);function i(t,r,e){const i=n.compare(t.clock,r.clock);return 0===i?e(t,r):i}function o(t,r,e){return t.clock.id===r.clock.id?e(t,r):t.clock.idt,n=(t,r)=>o(t,r,e);return((t,r)=>i(t,r,n))(t,r)}},function(t,r,e){"use strict";t.exports=class{async canAppend(t,r){return!0}}},function(t,r,e){"use strict";const n=e(23);t.exports=n},function(t,r,e){"use strict";const n=e(6),i=e(24),o="orbitdb";class s{constructor(t){if(!n(t))throw new Error("Keystore is required");this._keystore=t}async createIdentity(t,r,e){const s=await this._keystore.getKey(t)||await this._keystore.createKey(t);r=n(r)?r:o,e=n(e)?e:async(t,r)=>await this._keystore.sign(s,r);const a=await this._keystore.sign(s,t),h=s.getPublic("hex"),u=await e(t,h+a);return new i(t,h,a,u,r,this)}static async createIdentity(t,r,e,n){const i=new s(t);return await i.createIdentity(r,e,n)}static async verifyIdentity(t,r){return r(t)}async sign(t,r){const e=await this._keystore.getKey(t.id);if(!e)throw new Error("Private signing key not found from Keystore");return await this._keystore.sign(e,r)}async verify(t,r,e){return this._keystore.verify(t,r,e)}}t.exports=s},function(t,r,e){"use strict";const n=e(6);t.exports=class{constructor(t,r,e,i,o,s){if(!n(t))throw new Error("Identity id is required");if(!n(r))throw new Error("Invalid public key");if(!n(e))throw new Error("Signature of the id (idSignature) is required");if(!n(i))throw new Error("Signature of (publicKey + idSignature) is required");if(!n(o))throw new Error("Identity type is required");if(!n(s))throw new Error("Identity provider is required");this._id=t,this._publicKey=r,this._signatures=Object.assign({},{id:e},{publicKey:i}),this._type=o,this._provider=s}get id(){return this._id}get publicKey(){return this._publicKey}get signatures(){return this._signatures}get type(){return this._type}get provider(){return this._provider}toJSON(){return{id:this._id,publicKey:this._publicKey,signatures:this._signatures,type:this._type}}}}]); \ No newline at end of file +var n=e(8),i=e(9),o=e(10);function s(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,r){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function p(t,r){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return j(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return F(t).length;default:if(n)return j(t).length;r=(""+r).toLowerCase(),n=!0}}function y(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function g(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=h.from(r,n)),h.isBuffer(r))return 0===r.length?-1:w(t,r,e,n,i);if("number"==typeof r)return r&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):w(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function w(t,r,e,n,i){var o,s=1,a=t.length,h=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;s=2,a/=2,h/=2,e/=2}function u(t,r){return 1===s?t[r]:t.readUInt16BE(r*s)}if(i){var f=-1;for(o=e;oa&&(e=a-h),o=e;o>=0;o--){for(var c=!0,l=0;li&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function x(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function P(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:u>223?3:u>191?2:1;if(i+c<=e)switch(c){case 1:u<128&&(f=u);break;case 2:128==(192&(o=t[i+1]))&&(h=(31&u)<<6|63&o)>127&&(f=h);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(h=(15&u)<<12|(63&o)<<6|63&s)>2047&&(h<55296||h>57343)&&(f=h);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(h=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&h<1114112&&(f=h)}null===f?(f=65533,c=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),i+=c}return function(t){var r=t.length;if(r<=I)return String.fromCharCode.apply(String,t);var e="",n=0;for(;nthis.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return k(this,r,e);case"utf8":case"utf-8":return P(this,r,e);case"ascii":return R(this,r,e);case"latin1":case"binary":return S(this,r,e);case"base64":return x(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},h.prototype.equals=function(t){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===h.compare(this,t)},h.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},h.prototype.compare=function(t,r,e,n,i){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(r>>>=0,e>>>=0,n>>>=0,i>>>=0,this===t)return 0;for(var o=i-n,s=e-r,a=Math.min(o,s),u=this.slice(n,i),f=t.slice(r,e),c=0;ci)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,r,e);case"utf8":case"utf-8":return E(this,t,r,e);case"ascii":return m(this,t,r,e);case"latin1":case"binary":return _(this,t,r,e);case"base64":return b(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var I=4096;function R(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;in)&&(e=n);for(var i="",o=r;oe)throw new RangeError("Trying to access beyond buffer length")}function O(t,r,e,n,i,o){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||rt.length)throw new RangeError("Index out of range")}function U(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i>>8*(n?i:1-i)}function M(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i>>8*(n?i:3-i)&255}function D(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function Y(t,r,e,n,o){return o||D(t,0,e,4),i.write(t,r,e,n,23,4),e+4}function C(t,r,e,n,o){return o||D(t,0,e,8),i.write(t,r,e,n,52,8),e+8}h.prototype.slice=function(t,r){var e,n=this.length;if(t=~~t,r=void 0===r?n:~~r,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),r<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(i*=256);)n+=this[t+--r]*i;return n},h.prototype.readUInt8=function(t,r){return r||T(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,r){return r||T(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,r){return r||T(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,r){return r||T(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,r){return r||T(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||T(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},h.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||T(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},h.prototype.readInt8=function(t,r){return r||T(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,r){r||T(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},h.prototype.readInt16BE=function(t,r){r||T(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},h.prototype.readInt32LE=function(t,r){return r||T(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,r){return r||T(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,r){return r||T(t,4,this.length),i.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,r){return r||T(t,4,this.length),i.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,r){return r||T(t,8,this.length),i.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,r){return r||T(t,8,this.length),i.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||O(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o=0&&(o*=256);)this[r+i]=t/o&255;return r+e},h.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},h.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):U(this,t,r,!0),r+2},h.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):U(this,t,r,!1),r+2},h.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):M(this,t,r,!0),r+4},h.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):M(this,t,r,!1),r+4},h.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);O(this,t,r,e,i-1,-i)}var o=0,s=1,a=0;for(this[r]=255&t;++o>0)-a&255;return r+e},h.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);O(this,t,r,e,i-1,-i)}var o=e-1,s=1,a=0;for(this[r+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[r+o+1]&&(a=1),this[r+o]=(t/s>>0)-a&255;return r+e},h.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},h.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):U(this,t,r,!0),r+2},h.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):U(this,t,r,!1),r+2},h.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):M(this,t,r,!0),r+4},h.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||O(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):M(this,t,r,!1),r+4},h.prototype.writeFloatLE=function(t,r,e){return Y(this,t,r,!0,e)},h.prototype.writeFloatBE=function(t,r,e){return Y(this,t,r,!1,e)},h.prototype.writeDoubleLE=function(t,r,e){return C(this,t,r,!0,e)},h.prototype.writeDoubleBE=function(t,r,e){return C(this,t,r,!1,e)},h.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=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),t.length-r=0;--i)t[i+r]=this[i+e];else if(o<1e3||!h.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function F(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(L,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function q(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}}).call(r,e(7))},function(t,r,e){"use strict";t.exports=((t,r,e)=>new Promise((n,i)=>{if(e=Object.assign({concurrency:1/0},e),"function"!=typeof r)throw new TypeError("Mapper function is required");const o=e.concurrency;if(!("number"==typeof o&&o>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${o}\` (${typeof o})`);const s=[],a=t[Symbol.iterator]();let h=!1,u=!1,f=0,c=0;const l=()=>{if(h)return;const t=a.next(),e=c;if(c++,t.done)return u=!0,void(0===f&&n(s));f++,Promise.resolve(t.value).then(t=>r(t,e)).then(t=>{s[e]=t,f--,l()},t=>{h=!0,i(t)})};for(let t=0;tnew Error("IPFS instance not defined"),LogNotDefinedError:()=>new Error("Log instance not defined"),NotALogError:()=>new Error("Given argument is not an instance of Log"),CannotJoinWithDifferentId:()=>new Error("Can't join logs with different IDs")}},function(t,r,e){"use strict";(function(r){const n=e(4),i=e(11),o=e(1),s=e(15),a=e(5),h=e(0),{LastWriteWins:u}=e(18),f=e(19),{isDefined:c,findUniques:l}=e(2),d=()=>(new Date).getTime().toString(),p=t=>t.hash,y=(t,r)=>t.concat(r),g=t=>t.next,w=(t,r)=>Math.max(t,r.clock.time),v=(t,r)=>(t[r.hash]=r,t);class E extends i{constructor(t,r,e,n,i,o,s){if(!c(t))throw a.IPFSNotDefinedError();if(!c(r))throw new Error("Access controller is required");if(!c(e))throw new Error("Identity is required");if(c(i)&&!Array.isArray(i))throw new Error("'entries' argument must be an array of Entry instances");if(c(o)&&!Array.isArray(o))throw new Error("'heads' argument must be an array");super(),this._storage=t,this._id=n||d(),this._access=r,this._identity=e,i=i||[],this._entryIndex=i.reduce(v,{}),o=o||E.findHeads(i),this._headsIndex=o.reduce(v,{}),this._nextsIndex={};i.forEach(t=>t.next.forEach(r=>this._nextsIndex[r]=t.hash)),this._length=i.length;const u=Math.max(s?s.time:0,this.heads.reduce(w,0));this._clock=new h(this._identity.publicKey,u)}get id(){return this._id}get clock(){return this._clock}get length(){return this._length}get values(){return Object.values(this.traverse(this.heads)).reverse()}get heads(){return Object.values(this._headsIndex).sort(u).reverse()}get tails(){return E.findTails(this.values)}get tailHashes(){return E.findTailHashes(this.values)}get(t){return this._entryIndex[t]}has(t){return void 0!==this._entryIndex[t.hash||t]}traverse(t,r=-1){let e=t.sort(u).reverse(),n={},i={},o=0;const s=t=>this.get(t),a=t=>{t&&!n[t.hash]&&(e=[t,...e].sort(u).reverse(),n[t.hash]=!0)};for(;e.length>0&&(-1===r||othis._nextsIndex[t]=s.hash),this._headsIndex={},this._headsIndex[s.hash]=s,this._length++,s}async join(t,r=-1){if(!c(t))throw a.LogNotDefinedError();if(!E.isLog(t))throw a.NotALogError();if(this.id!==t.id)return;const e=E.difference(t,this),i=this._identity.provider,s=Object.values(e);await n(s,async t=>{if(!await this._access.canAppend(t,i))throw new Error(`Could not append entry, key "${t.identity.id}" is not allowed to write to the log`)},{concurrency:1}),await n(s,async t=>{const r=await o.verify(i,t),e=t.identity?t.identity.publicKey:t.key;if(!r)throw new Error(`Could not validate signature "${t.sig}" for entry "${t.hash}" and key "${e}"`)},{concurrency:1});Object.values(e).forEach(t=>{this.get(t.hash)||this._length++,t.next.forEach(r=>this._nextsIndex[r]=t.hash)}),this._entryIndex=Object.assign(this._entryIndex,e);const u=Object.values(e).map(g).reduce(y,[]),f=E.findHeads(Object.values(Object.assign({},this._headsIndex,t._headsIndex))).filter(t=>!u.find(r=>r===t.hash)).filter(t=>!this._nextsIndex[t.hash]).reduce(v,{});if(this._headsIndex=f,r>-1){let t=this.values;t=t.slice(-r),this._entryIndex=t.reduce(v,{}),this._headsIndex=E.findHeads(t),this._length=Object.values(this._entryIndex).length}const l=Object.values(this._headsIndex).reduce(w,0);return this._clock=new h(this.clock.id,Math.max(this.clock.time,l)),this}toJSON(){return{id:this.id,heads:this.heads.sort(u).reverse().map(p)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return r.from(JSON.stringify(this.toJSON()))}toString(t){return this.values.slice().reverse().map((r,e)=>{const n=o.findChildren(r,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("")+(t?t(r.payload):r.payload)}).join("\n")}static isLog(t){return void 0!==t.id&&void 0!==t.heads&&void 0!==t._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static async fromMultihash(t,r,e,n,i=-1,o,h){if(!c(t))throw a.IPFSNotDefinedError();if(!c(n))throw new Error(`Invalid hash: ${n}`);const u=await s.fromMultihash(t,n,i,o,h);return new E(t,r,e,u.id,u.values,u.heads,u.clock)}static async fromEntryHash(t,r,e,n,i,o=-1,h,u){if(!c(t))throw a.IPFSNotDefinedError();if(!c(n))throw new Error("'hash' must be defined");const f=await s.fromEntryHash(t,n,i,o,h,u);return new E(t,r,e,i,f.values)}static async fromJSON(t,r,e,n,i=-1,o,h){if(!c(t))throw a.IPFSNotDefinedError();const u=await s.fromJSON(t,n,i,o,h);return new E(t,r,e,u.id,u.values)}static async fromEntry(t,r,e,n,i=-1,o,h){if(!c(t))throw a.IPFSNotDefinedError();if(!c(n))throw new Error("'sourceEntries' must be defined");const u=await s.fromEntry(t,n,i,o,h);return new E(t,r,e,u.id,u.values)}static findHeads(t){var r=t.reduce((t,r,e,n)=>{return r.next.forEach(e=>t[e]=r.hash),t},{});return t.filter(t=>void 0===r[t.hash]).sort((t,r)=>t.clock.id>r.clock.id)}static findTails(t){var r={},e=[],n={},i=[];t.forEach(t=>{0===t.next.length&&e.push(t);t.next.forEach(e=>{r[e]||(r[e]=[]),r[e].push(t)}),i=i.concat(t.next),n[t.hash]=!0});const s=i.filter(t=>void 0===n[t]).map(t=>r[t]).reduce((t,r,e,n)=>t.concat(l(r,"hash")),[]).concat(e);return l(s,"hash").sort(o.compare)}static findTailHashes(t){var r={};return t.forEach(t=>r[t.hash]=!0),t.reduce((t,e,n,i)=>{return e.next.reverse().forEach(e=>{void 0===r[e]&&t.splice(0,0,e)}),t},[])}static difference(t,r){let e=Object.keys(t._headsIndex),n={},i={};const o=t=>{n[t]||r.get(t)||(e.push(t),n[t]=!0)};for(;e.length>0;){const s=e.shift(),a=t.get(s);a&&!r.get(s)&&a.id===r.id&&(i[a.hash]=a,n[a.hash]=!0,a.next.forEach(o))}return i}}t.exports=E,t.exports.AccessController=f}).call(r,e(3).Buffer)},function(t,r){var e;e=function(){return this}();try{e=e||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";r.byteLength=function(t){var r=u(t),e=r[0],n=r[1];return 3*(e+n)/4-n},r.toByteArray=function(t){for(var r,e=u(t),n=e[0],s=e[1],a=new o(function(t,r,e){return 3*(r+e)/4-e}(0,n,s)),h=0,f=s>0?n-4:n,c=0;c>16&255,a[h++]=r>>8&255,a[h++]=255&r;2===s&&(r=i[t.charCodeAt(c)]<<2|i[t.charCodeAt(c+1)]>>4,a[h++]=255&r);1===s&&(r=i[t.charCodeAt(c)]<<10|i[t.charCodeAt(c+1)]<<4|i[t.charCodeAt(c+2)]>>2,a[h++]=r>>8&255,a[h++]=255&r);return a},r.fromByteArray=function(t){for(var r,e=t.length,i=e%3,o=[],s=0,a=e-i;sa?a:s+16383));1===i?(r=t[e-1],o.push(n[r>>2]+n[r<<4&63]+"==")):2===i&&(r=(t[e-2]<<8)+t[e-1],o.push(n[r>>10]+n[r>>4&63]+n[r<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function f(t){return n[t>>18&63]+n[t>>12&63]+n[t>>6&63]+n[63&t]}function c(t,r,e){for(var n,i=[],o=r;o>1,f=-7,c=e?i-1:0,l=e?-1:1,d=t[r+c];for(c+=l,o=d&(1<<-f)-1,d>>=-f,f+=a;f>0;o=256*o+t[r+c],c+=l,f-=8);for(s=o&(1<<-f)-1,o>>=-f,f+=n;f>0;s=256*s+t[r+c],c+=l,f-=8);if(0===o)o=1-u;else{if(o===h)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),o-=u}return(d?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var s,a,h,u=8*o-i-1,f=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:o-1,p=n?1:-1,y=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,s=f):(s=Math.floor(Math.log(r)/Math.LN2),r*(h=Math.pow(2,-s))<1&&(s--,h*=2),(r+=s+c>=1?l/h:l*Math.pow(2,1-c))*h>=2&&(s++,h/=2),s+c>=f?(a=0,s=f):s+c>=1?(a=(r*h-1)*Math.pow(2,i),s+=c):(a=r*Math.pow(2,c-1)*Math.pow(2,i),s=0));i>=8;t[e+d]=255&a,d+=p,a/=256,i-=8);for(s=s<0;t[e+d]=255&s,d+=p,s/=256,u-=8);t[e+d-p]|=128*y}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r,e){"use strict";t.exports=class{constructor(t){}append(t){}merge(t){}get(t){}has(t){}get values(){}get length(){}}},function(t,r,e){"use strict";t.exports=function(t,r,e){var n={},i={};return t.forEach(t=>i[e?t[e]:t]=!0),r.reduce((t,r)=>{var o=void 0!==i[e?r[e]:r],s=void 0!==n[e?r[e]:r];return o||s||(t.push(r),n[e?r[e]:r]=!0),t},[])}},function(t,r,e){"use strict";t.exports=function(t,r){let e={};return t.forEach(t=>e[r?t[r]:t]=t),Object.keys(e).map(t=>e[t])}},function(t,r,e){"use strict";t.exports=(t=>void 0!==t&&null!==t)},function(t,r,e){"use strict";const n=e(1),i=e(16),o=e(0),s=e(5),{isDefined:a,findUniques:h,difference:u}=e(2),f=(t,r)=>t.slice(t.length-r,t.length);t.exports=class{static async toMultihash(t,r){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw s.LogNotDefinedError();if(r.values.length<1)throw new Error("Can't serialize an empty log");return(await t.dag.put(r.toBuffer())).toBaseEncodedString()}static async fromMultihash(t,r,e=-1,h,u){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw new Error(`Invalid hash: ${r}`);const f=await t.dag.get(r),c=JSON.parse(f.value);if(!c.heads||!c.id)throw s.NotALogError();const l=await i.fetchAll(t,c.heads,e,h,null,u),d=l.reduce((t,r)=>r.clock.time>t.time?new o(r.clock.id,r.clock.time):t,new o(c.id)),p=l.slice().sort(n.compare),y=p.filter(t=>c.heads.includes(t.hash));return{id:c.id,values:p,heads:y,clock:d}}static async fromEntryHash(t,r,e,n=-1,o,h){if(!a(t))throw s.IpfsNotDefinedError();if(!a(r))throw new Error("'entryHash' must be defined");const u=Array.isArray(r)?r:[r];n=n>-1?Math.max(n,1):n;const c=o,l=await i.fetchParallel(t,u,n,c,null,null,h);return{values:n>-1?f(l,n):l}}static async fromJSON(t,r,e=-1,o,h){if(!a(t))throw s.IPFSNotDefinedError();const u=r.heads.map(t=>t.hash),f=(await i.fetchParallel(t,u,e,[],16,o,h)).slice().sort(n.compare);return{id:r.id,values:f,heads:r.heads}}static async fromEntry(t,r,e=-1,o,f){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(r)&&!n.isEntry(r))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(r)||(r=[r]),e=e>-1?Math.max(e,r.length):e;const c=o?o.map(t=>t.hash?t.hash:t):o,l=r.map(t=>t.hash),d=await i.fetchParallel(t,l,e,c,null,null,f),p=r.concat(d),y=h(p,"hash").sort(n.compare),g=y.slice(e>-1?-e:-y.length),w=((t,r)=>{var e=t.slice(r.length,t.length);return r.concat(e)})(g,u(g,r,"hash"));return{id:w[w.length-1].id,values:w}}}},function(t,r,e){"use strict";const n=e(17),i=e(4),o=e(1);class s{static async fetchParallel(t,r,e,n=[],o,a,h){const u=(t,r)=>t.concat(r);return o=Math.max(o||r.length,1),(t=>t.reduce(u,[]))(await i(r,r=>s.fetchAll(t,r,e,n,a,h),{concurrency:o}))}static async fetchAll(t,r,e,i=[],s=null,a){let h=[],u={},f=Array.isArray(r)?r.slice():[r];const c=t=>f.push(t);(i=i&&Array.isArray(i)?i:[]).forEach(t=>u[t.hash]=t);return await n(()=>f.length>0&&(h.length{const r=f.shift();return u[r]?Promise.resolve():new Promise(async(e,n)=>{const i=s?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${r}', request timed out (${s}ms)`),e()},s):null;try{(t=>{clearTimeout(i),o.isEntry(t)&&(t.next.forEach(c),h.push(t),u[r]=t,a&&a(r,t,h.length))})(await o.fromMultihash(t,r)),e()}catch(t){n(t)}})}),h}}t.exports=s},function(t,r,e){"use strict";const n=t=>new Promise(r=>{r(t())});t.exports=((t,r)=>n(function e(){if(t())return n(r).then(e)}))},function(t,r,e){"use strict";const n=e(0);function i(t,r,e){const i=n.compare(t.clock,r.clock);return 0===i?e(t,r):i}function o(t,r,e){return t.clock.id===r.clock.id?e(t,r):t.clock.idt,n=(t,r)=>o(t,r,e);return((t,r)=>i(t,r,n))(t,r)}},function(t,r,e){"use strict";t.exports=class{async canAppend(t,r){return!0}}}]); \ No newline at end of file diff --git a/lib/es5/entry.js b/lib/es5/entry.js index 04167576..25fb7831 100644 --- a/lib/es5/entry.js +++ b/lib/es5/entry.js @@ -284,11 +284,11 @@ var Entry = function () { data = Entry.toBuffer(e); _context3.next = 12; - return ipfs.object.put(data); + return ipfs.dag.put(data); case 12: object = _context3.sent; - return _context3.abrupt('return', object.toJSON().multihash); + return _context3.abrupt('return', object.toBaseEncodedString()); case 14: case 'end': @@ -342,11 +342,11 @@ var Entry = function () { case 4: _context4.next = 6; - return ipfs.object.get(hash, { enc: 'base58' }); + return ipfs.dag.get(hash); case 6: obj = _context4.sent; - data = JSON.parse(obj.toJSON().data); + data = JSON.parse(obj.value); entry = { hash: hash, id: data.id, diff --git a/lib/es5/g-set.js b/lib/es5/g-set.js index 43be37cd..f6c1f5b2 100644 --- a/lib/es5/g-set.js +++ b/lib/es5/g-set.js @@ -21,7 +21,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de var GSet = function () { function GSet(values) { (0, _classCallCheck3.default)(this, GSet); - } + } // eslint-disable-line + (0, _createClass3.default)(GSet, [{ key: 'append', diff --git a/lib/es5/log-io.js b/lib/es5/log-io.js index 177fb3d8..69f01751 100644 --- a/lib/es5/log-io.js +++ b/lib/es5/log-io.js @@ -71,11 +71,11 @@ var LogIO = function () { case 6: _context.next = 8; - return ipfs.object.put(log.toBuffer()); + return ipfs.dag.put(log.toBuffer()); case 8: dagNode = _context.sent; - return _context.abrupt('return', dagNode.toJSON().multihash); + return _context.abrupt('return', dagNode.toBaseEncodedString()); case 10: case 'end': @@ -130,11 +130,11 @@ var LogIO = function () { case 4: _context2.next = 6; - return ipfs.object.get(hash, { enc: 'base58' }); + return ipfs.dag.get(hash); case 6: dagNode = _context2.sent; - logData = JSON.parse(dagNode.toJSON().data); + logData = JSON.parse(dagNode.value); if (!(!logData.heads || !logData.id)) { _context2.next = 10; diff --git a/lib/es5/log.js b/lib/es5/log.js index 323583dd..a0731c6a 100644 --- a/lib/es5/log.js +++ b/lib/es5/log.js @@ -61,7 +61,6 @@ var _require = require('./log-sorting'), LastWriteWins = _require.LastWriteWins; var AccessController = require('./default-access-controller'); -var IdentityProvider = require('orbit-db-identity-provider'); var _require2 = require('./utils'), isDefined = _require2.isDefined, @@ -163,7 +162,7 @@ var Log = function (_GSet) { entries.forEach(addToNextsIndex); // Set the length, we calculate the length manually internally - _this._length = entries ? entries.length : 0; + _this._length = entries.length; // Set the clock var maxTime = Math.max(clock ? clock.time : 0, _this.heads.reduce(maxClockTimeReducer, 0)); @@ -221,7 +220,7 @@ var Log = function (_GSet) { // Add an entry to the stack and traversed nodes index var addToStack = function addToStack(entry) { // If we've already processed the entry, don't add it to the stack - if (traversed[entry.hash]) { + if (!entry || traversed[entry.hash]) { return; } @@ -241,11 +240,6 @@ var Log = function (_GSet) { // Get the next element from the stack var entry = stack.shift(); - // Is the stack empty? - if (!entry) { - return; - } - // Add to the result count++; result[entry.hash] = entry; @@ -409,7 +403,7 @@ var Log = function (_GSet) { break; } - throw new Error('Append not permitted'); + throw new Error('Could not append entry, key "' + entry.identity.id + '" is not allowed to write to the log'); case 5: case 'end': @@ -474,7 +468,7 @@ var Log = function (_GSet) { // Update the internal next pointers index addToNextsIndex = function addToNextsIndex(e) { var entry = _this4.get(e.hash); - if (!entry) _this4._length++; + if (!entry) _this4._length++; /* istanbul ignore else */ e.next.forEach(function (a) { return _this4._nextsIndex[a] = e.hash; }); @@ -589,6 +583,7 @@ var Log = function (_GSet) { var padding = new Array(Math.max(len - 1, 0)); padding = len > 1 ? padding.fill(' ') : padding; padding = len > 0 ? padding.concat(['└─']) : padding; + /* istanbul ignore next */ return padding.join('') + (payloadMapper ? payloadMapper(e.payload) : e.payload); }).join('\n'); } @@ -667,7 +662,7 @@ var Log = function (_GSet) { }, { key: 'heads', get: function get() { - return (0, _values2.default)(this._headsIndex).sort(LastWriteWins).reverse() || []; + return (0, _values2.default)(this._headsIndex).sort(LastWriteWins).reverse(); } /** @@ -1062,5 +1057,4 @@ var Log = function (_GSet) { }(GSet); module.exports = Log; -module.exports.AccessController = AccessController; -module.exports.IdentityProvider = IdentityProvider; \ No newline at end of file +module.exports.AccessController = AccessController; \ No newline at end of file diff --git a/lib/es5/utils/index.js b/lib/es5/utils/index.js index 742f33b1..7b5e60c9 100644 --- a/lib/es5/utils/index.js +++ b/lib/es5/utils/index.js @@ -2,12 +2,10 @@ var difference = require('./difference'); var findUniques = require('./find-uniques'); -var intersection = require('./intersection'); var isDefined = require('./is-defined'); module.exports = { difference: difference, findUniques: findUniques, - intersection: intersection, isDefined: isDefined }; \ No newline at end of file