diff --git a/dist/ipfslog.min.js b/dist/ipfslog.min.js index eb3fadcd..eec876c5 100644 --- a/dist/ipfslog.min.js +++ b/dist/ipfslog.min.js @@ -1,16 +1,16 @@ -var Log=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=37)}([function(e,t,n){"use strict";e.exports=function(e,t,n,r){return t.bytes=n.bytes=0,{type:e,encode:t,decode:n,encodingLength:r}}},function(e,t,n){e.exports={encode:n(73),decode:n(74),encodingLength:n(75)}},function(e,t,n){"use strict";e.exports={isArray:Array.isArray,assign:Object.assign,isObject:e=>"object"==typeof e,isFunction:e=>"function"==typeof e,isBoolean:e=>"boolean"==typeof e,isRegex:e=>e instanceof RegExp,keys:Object.keys}},function(e,t,n){"use strict";const{names:r}=n(13),{TextEncoder:i}=n(15),s=new i;e.exports=function(e,t="utf8"){if("utf8"===t||"utf-8"===t)return s.encode(e);if("ascii"===t)return function(e){const t=new Uint8Array(e.length);for(let n=0;n`}toJSON(){return this._json||(this._json=Object.freeze({name:this.Name,size:this.Tsize,cid:this.Hash.toBaseEncodedString()})),Object.assign({},this._json)}get nameAsBuffer(){return null!==this._nameBuf||(this._nameBuf=s(this.Name)),this._nameBuf}},{className:"DAGLink",symbolName:"@ipld/js-ipld-dag-pb/daglink"})},function(e,t,n){"use strict";const r=n(9),i=n(22),s=n(23),{baseTable:o}=n(7),a=n(61),c=n(17),u=n(6),f=n(18),h=Object.keys(o).reduce((e,t)=>(e[o[t]]=t,e),{}),l=Symbol.for("@ipld/js-cid/CID");class d{constructor(e,t,n,o){if(Object.defineProperty(this,l,{value:!0}),d.isCID(e)){const t=e;return this.version=t.version,this.codec=t.codec,this.multihash=t.multihash,void(this.multibaseName=t.multibaseName||(0===t.version?"base58btc":"base32"))}if("string"==typeof e){const t=i.isEncoded(e);if(t){const n=i.decode(e);this.version=parseInt(n[0].toString(),16),this.codec=s.getCodec(n.slice(1)),this.multihash=s.rmPrefix(n.slice(1)),this.multibaseName=t}else this.version=0,this.codec="dag-pb",this.multihash=r.fromB58String(e),this.multibaseName="base58btc";return d.validateCID(this),void Object.defineProperty(this,"string",{value:e})}if(e instanceof Uint8Array){const t=parseInt(e[0].toString(),16);if(1===t){const n=e;this.version=t,this.codec=s.getCodec(n.slice(1)),this.multihash=s.rmPrefix(n.slice(1)),this.multibaseName="base32"}else this.version=0,this.codec="dag-pb",this.multihash=e,this.multibaseName="base58btc";d.validateCID(this)}else this.version=e,"number"==typeof t&&(t=h[t]),this.codec=t,this.multihash=n,this.multibaseName=o||(0===e?"base58btc":"base32"),d.validateCID(this)}get bytes(){let e=this._bytes;if(!e){if(0===this.version)e=this.multihash;else{if(1!==this.version)throw new Error("unsupported version");{const t=s.getCodeVarint(this.codec);e=c([[1],t,this.multihash],1+t.byteLength+this.multihash.byteLength)}}Object.defineProperty(this,"_bytes",{value:e})}return e}get prefix(){const e=s.getCodeVarint(this.codec),t=r.prefix(this.multihash);return c([[this.version],e,t],1+e.byteLength+t.byteLength)}get code(){return o[this.codec]}toV0(){if("dag-pb"!==this.codec)throw new Error("Cannot convert a non dag-pb CID to CIDv0");const{name:e,length:t}=r.decode(this.multihash);if("sha2-256"!==e)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");if(32!==t)throw new Error("Cannot convert non 32 byte multihash CID to CIDv0");return new d(0,this.codec,this.multihash)}toV1(){return new d(1,this.codec,this.multihash)}toBaseEncodedString(e=this.multibaseName){if(this.string&&0!==this.string.length&&e===this.multibaseName)return this.string;let t;if(0===this.version){if("base58btc"!==e)throw new Error("not supported with CIDv0, to support different bases, please migrate the instance do CIDv1, you can do that through cid.toV1()");t=r.toB58String(this.multihash)}else{if(1!==this.version)throw new Error("unsupported version");t=u(i.encode(e,this.bytes))}return e===this.multibaseName&&Object.defineProperty(this,"string",{value:t}),t}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}toString(e){return this.toBaseEncodedString(e)}toJSON(){return{codec:this.codec,version:this.version,hash:this.multihash}}equals(e){return this.codec===e.codec&&this.version===e.version&&f(this.multihash,e.multihash)}static validateCID(e){const t=a.checkCIDComponents(e);if(t)throw new Error(t)}static isCID(e){return e instanceof d||Boolean(e&&e[l])}}d.codecs=o,e.exports=d},function(e,t,n){"use strict";const{names:r}=n(13),{TextDecoder:i}=n(15),s=new i("utf8");e.exports=function(e,t="utf8"){if("utf8"===t||"utf-8"===t)return s.decode(e);if("ascii"===t)return function(e){let t="";for(let n=0;n"object"==typeof e,isFunction:e=>"function"==typeof e,isBoolean:e=>"boolean"==typeof e,isRegex:e=>e instanceof RegExp,keys:Object.keys}},function(e,t,n){"use strict";const{names:r}=n(13),{TextEncoder:i}=n(15),s=new i;e.exports=function(e,t="utf8"){if("utf8"===t||"utf-8"===t)return s.encode(e);if("ascii"===t)return function(e){const t=new Uint8Array(e.length);for(let n=0;n`}toJSON(){return this._json||(this._json=Object.freeze({name:this.Name,size:this.Tsize,cid:this.Hash.toBaseEncodedString()})),Object.assign({},this._json)}get nameAsBuffer(){return null!==this._nameBuf||(this._nameBuf=s(this.Name)),this._nameBuf}},{className:"DAGLink",symbolName:"@ipld/js-ipld-dag-pb/daglink"})},function(e,t,n){"use strict";const r=n(9),i=n(22),s=n(23),{baseTable:o}=n(7),a=n(61),c=n(17),u=n(6),h=n(18),f=Object.keys(o).reduce((e,t)=>(e[o[t]]=t,e),{}),l=Symbol.for("@ipld/js-cid/CID");class d{constructor(e,t,n,o){if(Object.defineProperty(this,l,{value:!0}),d.isCID(e)){const t=e;return this.version=t.version,this.codec=t.codec,this.multihash=t.multihash,void(this.multibaseName=t.multibaseName||(0===t.version?"base58btc":"base32"))}if("string"==typeof e){const t=i.isEncoded(e);if(t){const n=i.decode(e);this.version=parseInt(n[0].toString(),16),this.codec=s.getCodec(n.slice(1)),this.multihash=s.rmPrefix(n.slice(1)),this.multibaseName=t}else this.version=0,this.codec="dag-pb",this.multihash=r.fromB58String(e),this.multibaseName="base58btc";return d.validateCID(this),void Object.defineProperty(this,"string",{value:e})}if(e instanceof Uint8Array){const t=parseInt(e[0].toString(),16);if(1===t){const n=e;this.version=t,this.codec=s.getCodec(n.slice(1)),this.multihash=s.rmPrefix(n.slice(1)),this.multibaseName="base32"}else this.version=0,this.codec="dag-pb",this.multihash=e,this.multibaseName="base58btc";d.validateCID(this)}else this.version=e,"number"==typeof t&&(t=f[t]),this.codec=t,this.multihash=n,this.multibaseName=o||(0===e?"base58btc":"base32"),d.validateCID(this)}get bytes(){let e=this._bytes;if(!e){if(0===this.version)e=this.multihash;else{if(1!==this.version)throw new Error("unsupported version");{const t=s.getCodeVarint(this.codec);e=c([[1],t,this.multihash],1+t.byteLength+this.multihash.byteLength)}}Object.defineProperty(this,"_bytes",{value:e})}return e}get prefix(){const e=s.getCodeVarint(this.codec),t=r.prefix(this.multihash);return c([[this.version],e,t],1+e.byteLength+t.byteLength)}get code(){return o[this.codec]}toV0(){if("dag-pb"!==this.codec)throw new Error("Cannot convert a non dag-pb CID to CIDv0");const{name:e,length:t}=r.decode(this.multihash);if("sha2-256"!==e)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");if(32!==t)throw new Error("Cannot convert non 32 byte multihash CID to CIDv0");return new d(0,this.codec,this.multihash)}toV1(){return new d(1,this.codec,this.multihash)}toBaseEncodedString(e=this.multibaseName){if(this.string&&0!==this.string.length&&e===this.multibaseName)return this.string;let t;if(0===this.version){if("base58btc"!==e)throw new Error("not supported with CIDv0, to support different bases, please migrate the instance do CIDv1, you can do that through cid.toV1()");t=r.toB58String(this.multihash)}else{if(1!==this.version)throw new Error("unsupported version");t=u(i.encode(e,this.bytes))}return e===this.multibaseName&&Object.defineProperty(this,"string",{value:t}),t}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}toString(e){return this.toBaseEncodedString(e)}toJSON(){return{codec:this.codec,version:this.version,hash:this.multihash}}equals(e){return this.codec===e.codec&&this.version===e.version&&h(this.multihash,e.multihash)}static validateCID(e){const t=a.checkCIDComponents(e);if(t)throw new Error(t)}static isCID(e){return e instanceof d||Boolean(e&&e[l])}}d.codecs=o,e.exports=d},function(e,t,n){"use strict";const{names:r}=n(13),{TextDecoder:i}=n(15),s=new i("utf8");e.exports=function(e,t="utf8"){if("utf8"===t||"utf-8"===t)return s.decode(e);if("ascii"===t)return function(e){let t="";for(let n=0;n * @license MIT */ -var r=n(38),i=n(39),s=n(40);function o(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(o()=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|e}function p(e,t){if(c.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 n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return z(e).length;t=(""+t).toLowerCase(),r=!0}}function b(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,n);case"utf8":case"utf-8":return S(this,t,n);case"ascii":return U(this,t,n);case"latin1":case"binary":return O(this,t,n);case"base64":return _(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function k(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function g(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:y(e,t,n,r,i);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):y(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function y(e,t,n,r,i){var s,o=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;o=2,a/=2,c/=2,n/=2}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){var f=-1;for(s=n;sa&&(n=a-c),s=n;s>=0;s--){for(var h=!0,l=0;li&&(r=i):r=i;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o>8,i=n%256,s.push(i),s.push(r);return s}(t,e.length-n),e,n,r)}function _(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function S(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i239?4:u>223?3:u>191?2:1;if(i+h<=n)switch(h){case 1:u<128&&(f=u);break;case 2:128==(192&(s=e[i+1]))&&(c=(31&u)<<6|63&s)>127&&(f=c);break;case 3:s=e[i+1],o=e[i+2],128==(192&s)&&128==(192&o)&&(c=(15&u)<<12|(63&s)<<6|63&o)>2047&&(c<55296||c>57343)&&(f=c);break;case 4:s=e[i+1],o=e[i+2],a=e[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(c=(15&u)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&c<1114112&&(f=c)}null===f?(f=65533,h=1):f>65535&&(f-=65536,r.push(f>>>10&1023|55296),f=56320|1023&f),r.push(f),i+=h}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),""},c.prototype.compare=function(e,t,n,r,i){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(t>>>=0),a=Math.min(s,o),u=this.slice(r,i),f=e.slice(t,n),h=0;hi)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return w(this,e,t,n);case"utf8":case"utf-8":return m(this,e,t,n);case"ascii":return v(this,e,t,n);case"latin1":case"binary":return E(this,e,t,n);case"base64":return x(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function U(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;ir)&&(n=r);for(var i="",s=t;sn)throw new RangeError("Trying to access beyond buffer length")}function T(e,t,n,r,i,s){if(!c.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 L(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,s=Math.min(e.length-n,2);i>>8*(r?i:1-i)}function P(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,s=Math.min(e.length-n,4);i>>8*(r?i:3-i)&255}function j(e,t,n,r,i,s){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function N(e,t,n,r,s){return s||j(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function D(e,t,n,r,s){return s||j(e,0,n,8),i.write(e,t,n,r,52,8),n+8}c.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t0&&(i*=256);)r+=this[e+--t]*i;return r},c.prototype.readUInt8=function(e,t){return t||C(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||C(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||C(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||C(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||C(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||C(e,t,this.length);for(var r=this[e],i=1,s=0;++s=(i*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||C(e,t,this.length);for(var r=t,i=1,s=this[e+--r];r>0&&(i*=256);)s+=this[e+--r]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*t)),s},c.prototype.readInt8=function(e,t){return t||C(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||C(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){t||C(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return t||C(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||C(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||C(e,4,this.length),i.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||C(e,4,this.length),i.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||C(e,8,this.length),i.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||C(e,8,this.length),i.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||T(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,s=0;for(this[t]=255&e;++s=0&&(s*=256);)this[t+i]=e/s&255;return t+n},c.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):P(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):P(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);T(this,e,t,n,i-1,-i)}var s=0,o=1,a=0;for(this[t]=255&e;++s>0)-a&255;return t+n},c.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);T(this,e,t,n,i-1,-i)}var s=n-1,o=1,a=0;for(this[t+s]=255&e;--s>=0&&(o*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},c.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):P(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):P(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,n){return N(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return N(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return D(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return D(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t=0;--i)e[i+t]=this[i+n];else if(s<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=t;s55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&s.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function H(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(M,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function F(e,t,n,r){for(var i=0;i=t.length||i>=e.length);++i)t[i+n]=e[i];return i}}).call(this,n(20))},function(e,t,n){"use strict";const r=n(22),i=n(16),{names:s}=n(56),o=n(6),a=n(3),c=n(17),u={};for(const e in s)u[s[e]]=e;function f(e){if(!(e instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(e.length<2)throw new Error("multihash too short. must be > 2 bytes.");const t=i.decode(e);if(!d(t))throw new Error("multihash unknown function code: 0x"+t.toString(16));e=e.slice(i.decode.bytes);const n=i.decode(e);if(n<0)throw new Error("multihash invalid length: "+n);if((e=e.slice(i.decode.bytes)).length!==n)throw new Error("multihash length inconsistent: 0x"+o(e,"base16"));return{code:t,name:u[t],length:n,digest:e}}function h(e){let t=e;if("string"==typeof e){if(void 0===s[e])throw new Error("Unrecognized hash function named: "+e);t=s[e]}if("number"!=typeof t)throw new Error("Hash function code should be a number. Got: "+t);if(void 0===u[t]&&!l(t))throw new Error("Unrecognized function code: "+t);return t}function l(e){return e>0&&e<16}function d(e){return!!l(e)||!!u[e]}function p(e){f(e)}e.exports={names:s,codes:Object.freeze(u),toHexString:function(e){if(!(e instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return o(e,"base16")},fromHexString:function(e){return a(e,"base16")},toB58String:function(e){if(!(e instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return o(r.encode("base58btc",e)).slice(1)},fromB58String:function(e){const t=e instanceof Uint8Array?o(e):e;return r.decode("z"+t)},decode:f,encode:function(e,t,n){if(!e||void 0===t)throw new Error("multihash encode requires at least two args: digest, code");const r=h(t);if(!(e instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(null==n&&(n=e.length),n&&e.length!==n)throw new Error("digest length should be equal to specified length.");const s=i.encode(r),o=i.encode(n);return c([s,o,e],s.length+o.length+e.length)},coerceCode:h,isAppCode:l,validate:p,prefix:function(e){return p(e),e.subarray(0,2)},isValidCode:d}},function(e,t,n){"use strict";(function(t){const r=n(11),{isDefined:i,io:s}=n(12),o=n(114),a=()=>new Error("Ipfs instance not defined"),c=["next","refs"],u=e=>0===e?"dag-pb":"dag-cbor",f=e=>h.isEntry(e)?u(e.v):u(e);class h{static async create(e,t,n,s,o=[],c,u=[],f){if(!i(e))throw a();if(!i(t))throw new Error("Identity is required, cannot create entry");if(!i(n))throw new Error("Entry requires an id");if(!i(s))throw new Error("Entry requires data");if(!i(o)||!Array.isArray(o))throw new Error("'next' argument is not an array");const l={hash:null,id:n,payload:s,next:o.filter(i).map(e=>e.hash?e.hash:e),refs:u,v:2,clock:c||new r(t.publicKey)},d=await t.provider.sign(t,h.toBuffer(l));return l.key=t.publicKey,l.identity=t.toJSON(),l.sig=d,l.hash=await h.toMultihash(e,l,f),l}static async verify(e,t){if(!e)throw new Error("Identity-provider is required, cannot verify entry");if(!h.isEntry(t))throw new Error("Invalid Log entry");if(!t.key)throw new Error("Entry doesn't have a key");if(!t.sig)throw new Error("Entry doesn't have a signature");const n=h.toEntry(t,{presigned:!0}),r=t.v<1?"v0":"v1";return e.verify(t.sig,t.key,h.toBuffer(n),r)}static toBuffer(e){const n=0===e.v?JSON.stringify(e):o(e);return t.from(n)}static async toMultihash(e,t,n=!1){if(!e)throw a();if(!h.isEntry(t))throw new Error("Invalid object format, cannot generate entry hash");const r=h.toEntry(t);return s.write(e,f(r.v),r,{links:c,pin:n})}static toEntry(e,{presigned:t=!1,includeHash:n=!1}={}){const i={hash:n?e.hash:null,id:e.id,payload:e.payload,next:e.next},s=e.v;return s>1&&(i.refs=e.refs),i.v=e.v,i.clock=new r(e.clock.id,e.clock.time),t||(i.key=e.key,s>0&&(i.identity=e.identity),i.sig=e.sig),i}static async fromMultihash(e,t){if(!e)throw a();if(!t)throw new Error("Invalid hash: "+t);const n=await s.read(e,t,{links:c}),r=h.toEntry(n);return r.hash=t,r}static isEntry(e){return e&&void 0!==e.id&&void 0!==e.next&&void 0!==e.payload&&void 0!==e.v&&void 0!==e.hash&&void 0!==e.clock&&(void 0!==e.refs||e.v<2)}static compare(e,t){var n=r.compare(e.clock,t.clock);return 0===n?e.clock.id-1}static findChildren(e,t){for(var n=[],r=t.find(t=>h.isParent(e,t)),i=e;r;)n.push(r),i=r,r=t.find(e=>h.isParent(i,e));return n=n.sort((e,t)=>e.clock.time>t.clock.time)}}e.exports=h,e.exports.IPLD_LINKS=c,e.exports.getWriteFormat=f}).call(this,n(8).Buffer)},function(e,t,n){"use strict";class r{constructor(e,t){this.id=e,this.time=t||0}tick(){return new r(this.id,++this.time)}merge(e){return this.time=Math.max(this.time,e.time),new r(this.id,this.time)}clone(){return new r(this.id,this.time)}static compare(e,t){var n=e.time-t.time;return 0===n&&e.id!==t.id?e.id({encode:o,decode:a}),""],["base2","0",s(1),"01"],["base8","7",s(3),"01234567"],["base10","9",r,"0123456789"],["base16","f",s(4),"0123456789abcdef"],["base16upper","F",s(4),"0123456789ABCDEF"],["base32hex","v",s(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",s(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",s(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",s(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",s(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",s(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",s(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",s(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",s(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",r,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",r,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",r,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",r,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],u=c.reduce((e,t)=>(e[t[0]]=new i(t[0],t[1],t[2],t[3]),e),{}),f=c.reduce((e,t)=>(e[t[1]]=u[t[0]],e),{});e.exports={names:u,codes:f}},function(e,t,n){"use strict";const{TextEncoder:r,TextDecoder:i}=n(15),s=new i,o=new r;e.exports={decodeText:e=>s.decode(e),encodeText:e=>o.encode(e),concat:function(e,t){const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}}},function(e,t,n){"use strict";t.TextEncoder=TextEncoder,t.TextDecoder=TextDecoder},function(e,t,n){e.exports={encode:n(53),decode:n(54),encodingLength:n(55)}},function(e,t,n){"use strict";e.exports=function(e,t){t||(t=e.reduce((e,t)=>e+t.length,0));const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}},function(e,t,n){"use strict";e.exports=function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;nnew Promise((s,o)=>{if("function"!=typeof t)throw new TypeError("Mapper function is required");if(!Number.isSafeInteger(n)&&n!==1/0||!(n>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${n}\` (${typeof n})`);const a=[],c=[],u=e[Symbol.iterator]();let f=!1,h=!1,l=0,d=0;const p=()=>{if(f)return;const e=u.next(),n=d;if(d++,e.done)return h=!0,void(0===l&&(i||0===c.length?s(a):o(new r(c))));l++,(async()=>{try{const r=await e.value;a[n]=await t(r,n),l--,p()}catch(e){i?(f=!0,o(e)):(c.push(e),l--,p())}})()};for(let e=0;es.isDAGLink(e)?e:s.util.createDagLinkFromB58EncodedHash(e)),i(t),Object.defineProperties(this,{Data:{value:e,writable:!1,enumerable:!0},Links:{value:t,writable:!1,enumerable:!0},_serializedSize:{value:n,writable:!0,enumerable:!1},_size:{value:null,writable:!0,enumerable:!1}})}toJSON(){return this._json||(this._json=Object.freeze({data:this.Data,links:this.Links.map(e=>e.toJSON()),size:this.size})),Object.assign({},this._json)}toString(){return`DAGNode `}_invalidateCached(){this._serializedSize=null,this._size=null}addLink(e){return this._invalidateCached(),c(this,e)}rmLink(e){return this._invalidateCached(),u(this,e)}toDAGLink(e){return a(this,e)}serialize(){return o(this)}get size(){return null===this._size&&(null===this._serializedSize&&(this._serializedSize=this.serialize().length),this._size=this.Links.reduce((e,t)=>e+t.Tsize,this._serializedSize)),this._size}set size(e){throw new Error("Can't set property: 'size' is immutable")}},{className:"DAGNode",symbolName:"@ipld/js-ipld-dag-pb/dagnode"})},function(e,t,n){"use strict";e.exports=function(e,{className:t,symbolName:n}){const r=Symbol.for(n),i={[t]:class extends e{constructor(...e){super(...e),Object.defineProperty(this,r,{value:!0})}get[Symbol.toStringTag](){return t}}}[t];return i["is"+t]=e=>!(!e||!e[r]),i},e.exports.proto=function(e,{className:t,symbolName:n,withoutNew:r}){const i=Symbol.for(n),s={[t]:function(...t){if(r&&!(this instanceof s))return new s(...t);const n=e.call(this,...t)||this;return n&&!n[i]&&Object.defineProperty(n,i,{value:!0}),n}}[t];return s.prototype=Object.create(e.prototype),s.prototype.constructor=s,Object.defineProperty(s.prototype,Symbol.toStringTag,{get:()=>t}),s["is"+t]=e=>!(!e||!e[i]),s}},function(e,t,n){"use strict";const r=n(64),i=n(65),s=(e,t)=>{const n=e.nameAsBuffer,r=t.nameAsBuffer;return i(n,r)};e.exports=e=>{r.inplace(e,s)}},function(e,t,n){"use strict";const r=n(29)(n(30)),i=n(4);t=e.exports;const s=e=>{const t=e.Data,n=e.Links||[];return r.PBNode.encode((e=>{const t={};return e.Data&&e.Data.byteLength>0?t.Data=e.Data:t.Data=null,e.Links&&e.Links.length>0?t.Links=e.Links.map(e=>({Hash:e.Hash.bytes,Name:e.Name,Tsize:e.Tsize})):t.Links=null,t})({Data:t,Links:n}))};t.serializeDAGNode=s,t.serializeDAGNodeLike=(e,t=[])=>{const n={Data:e};return n.Links=t.map(e=>i.isDAGLink(e)?e:i.util.createDagLinkFromB58EncodedHash(e)),s(n)}},function(e,t,n){"use strict";var r=n(66),i=n(70);e.exports=function(e,t){if(t||(t={}),!e)throw new Error("Pass in a .proto string or a protobuf-schema parsed object");var n="object"!=typeof e||e instanceof Uint8Array?r.parse(e):e,s=function(){var e=this;i(n,t.encodings||{}).forEach((function(t){e[t.name]=function(e){if(!e)return null;var t={};return Object.keys(e).forEach((function(n){t[n]=e[n].value})),t}(t.values)||t}))};return s.prototype.toString=function(){return r.stringify(n)},s.prototype.toJSON=function(){return n},new s}},function(e,t,n){"use strict";e.exports="// An IPFS MerkleDAG Link\nmessage PBLink {\n\n // multihash of the target object\n optional bytes Hash = 1;\n\n // utf string name. should be unique per object\n optional string Name = 2;\n\n // cumulative size of target object\n optional uint64 Tsize = 3;\n}\n\n// An IPFS MerkleDAG Node\nmessage PBNode {\n\n // refs to other objects\n repeated PBLink Links = 2;\n\n // opaque user data\n optional bytes Data = 1;\n}"},function(e,t,n){"use strict";const r=n(5),i=n(23),s=n(96);(t=e.exports).codec=i.DAG_PB,t.defaultHashAlg=i.SHA2_256;t.cid=async(e,n)=>{const o={cidVersion:1,hashAlg:t.defaultHashAlg},a=Object.assign(o,n),c=await s(e,a.hashAlg),u=i.print[t.codec];return new r(a.cidVersion,u,c)}},function(e,t,n){(function(t){function n(e){return(4294967296+e).toString(16).substring(1)}e.exports={normalizeInput:function(e){var n;if(e instanceof Uint8Array)n=e;else if(e instanceof t)n=new Uint8Array(e);else{if("string"!=typeof e)throw new Error("Input must be an string, Buffer or Uint8Array");n=new Uint8Array(t.from(e,"utf8"))}return n},toHex:function(e){return Array.prototype.map.call(e,(function(e){return(e<16?"0":"")+e.toString(16)})).join("")},debugPrint:function(e,t,r){for(var i="\n"+e+" = ",s=0;ss.isDAGNode(e)?e.serialize():o(e.Data,e.Links),t.deserialize=e=>{const t=r.PBNode.decode(e),n=t.Links.map(e=>new i(e.Name,e.Tsize,e.Hash)),o=null==t.Data?new Uint8Array(0):t.Data;return new s(o,n,e.byteLength)},t.cid=(e,t)=>a.cid(e,t)},function(e,t,n){"use strict";const r=n(11);function i(e,t,n){const i=r.compare(e.clock,t.clock);return 0===i?n(e,t):i}function s(e,t,n){return e.clock.id===t.clock.id?n(e,t):e.clock.ide,r=(e,t)=>s(e,t,n);return((e,t)=>i(e,t,r))(e,t)},t.SortByEntryHash=function(e,t){const n=(e,t)=>e.hashs(e,t,n);return((e,t)=>i(e,t,r))(e,t)},t.NoZeroes=function(e){const t=`Your log's tiebreaker function, ${e.name}, has returned zero and therefore cannot be`;return(n,r)=>{const i=e(n,r);if(0===i)throw Error(t);return i}}},function(e,t,n){"use strict";e.exports={IPFSNotDefinedError:()=>new 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"),LtOrLteMustBeStringOrArray:()=>new Error("lt or lte must be a string or array of Entries")}},function(e,t,n){"use strict";(function(t){const r=n(21),i=n(45),s=n(10),o=n(116),a=n(36),c=n(11),u=n(35),{LastWriteWins:f,NoZeroes:h}=u,l=n(119),{isDefined:d,findUniques:p}=n(12),b=n(120),k=e=>e.hash,g=(e,t)=>e.concat(t),y=e=>e.next,w=(e,t)=>Math.max(e,t.clock.time),m=(e,t)=>(e[t.hash]=t,e);class v extends i{constructor(e,t,{logId:n,access:r,entries:i,heads:s,clock:o,sortFn:u,concurrency:p}={}){if(!d(e))throw a.IPFSNotDefinedError();if(!d(t))throw new Error("Identity is required");if(d(r)||(r=new l),d(i)&&!Array.isArray(i))throw new Error("'entries' argument must be an array of Entry instances");if(d(s)&&!Array.isArray(s))throw new Error("'heads' argument must be an array");d(u)||(u=f),super(),this._sortFn=h(u),this._storage=e,this._id=n||(new Date).getTime().toString(),this._access=r,this._identity=t;const k=(i||[]).reduce(m,{});this._entryIndex=new b(k),i=Object.values(k)||[],s=s||v.findHeads(i),this._headsIndex=s.reduce(m,{}),this._nextsIndex={};i.forEach(e=>e.next.forEach(t=>this._nextsIndex[t]=e.hash)),this._length=i.length;const g=Math.max(o?o.time:0,this.heads.reduce(w,0));this._clock=new c(this._identity.publicKey,g),this.joinConcurrency=p||16}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(this._sortFn).reverse()}get tails(){return v.findTails(this.values)}get tailHashes(){return v.findTailHashes(this.values)}setIdentity(e){this._identity=e;const t=Math.max(this.clock.time,this.heads.reduce(w,0));this._clock=new c(this._identity.publicKey,t)}get(e){return this._entryIndex.get(e)}has(e){return void 0!==this._entryIndex.get(e.hash||e)}traverse(e,t=-1,n){let r=e.sort(this._sortFn).reverse(),i={};const s={};let o=0;const a=e=>this.get(e),c=e=>{e&&!i[e.hash]&&(r=[e,...r].sort(this._sortFn).reverse(),i[e.hash]=!0)};for(;r.length>0&&(o{const t=new Set;for(let n=1;n<=e;n*=2){const e=Math.min(n-1,i.length-1);t.add(i[e])}return t})(Math.min(t,i.length));i.length!a.includes(e)),f=await s.create(this._storage,this._identity,this.id,e,a,this.clock,u,n);if(!await this._access.canAppend(f,this._identity.provider))throw new Error(`Could not append entry, key "${this._identity.id}" is not allowed to write to the log`);return this._entryIndex.set(f.hash,f),a.forEach(e=>this._nextsIndex[e]=f.hash),this._headsIndex={},this._headsIndex[f.hash]=f,this._length++,f}iterator({gt:e,gte:t,lt:n,lte:r,amount:i=-1}={}){if(0===i)return function*(){}();if("string"==typeof r&&(r=[this.get(r)]),"string"==typeof n&&(n=[this.get(this.get(n).next)]),r&&!Array.isArray(r))throw a.LtOrLteMustBeStringOrArray();if(n&&!Array.isArray(n))throw a.LtOrLteMustBeStringOrArray();const s=(r||n||this.heads).filter(d),o=t?this.get(t).hash:e?this.get(e).hash:null,c=o?-1:i||-1,u=this.traverse(s,c,o);let f=Object.values(u);return e&&f.pop(),(e||t)&&i>-1&&(f=f.slice(f.length-i,f.length)),function*(){for(const e in f)yield f[e]}()}async join(e,t=-1){if(!d(e))throw a.LogNotDefinedError();if(!v.isLog(e))throw a.NotALogError();if(this.id!==e.id)return;const n=v.difference(e,this),i=this._identity.provider,o=async e=>{if(!await this._access.canAppend(e,i))throw new Error(`Could not append entry, key "${e.identity.id}" is not allowed to write to the log`)},u=Object.values(n);await r(u,async e=>{await o(e),await(async e=>{const t=await s.verify(i,e),n=e.identity?e.identity.publicKey:e.key;if(!t)throw new Error(`Could not validate signature "${e.sig}" for entry "${e.hash}" and key "${n}"`)})(e)},{concurrency:this.joinConcurrency});Object.values(n).forEach(e=>{this.get(e.hash)||this._length++,e.next.forEach(t=>this._nextsIndex[t]=e.hash)}),this._entryIndex.add(n);const f=Object.values(n).map(y).reduce(g,[]),h=v.findHeads(Object.values(Object.assign({},this._headsIndex,e._headsIndex))).filter(e=>!f.find(t=>t===e.hash)).filter(e=>!this._nextsIndex[e.hash]).reduce(m,{});if(this._headsIndex=h,t>-1){let e=this.values;e=e.slice(-t),this._entryIndex=null,this._entryIndex=new b(e.reduce(m,{})),this._headsIndex=v.findHeads(e).reduce(m,{}),this._length=this._entryIndex.length}const l=Object.values(this._headsIndex).reduce(w,0);return this._clock=new c(this.clock.id,Math.max(this.clock.time,l)),this}toJSON(){return{id:this.id,heads:this.heads.sort(this._sortFn).reverse().map(k)}}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,n)=>{const r=s.findChildren(t,this.values).length;let i=new Array(Math.max(r-1,0));return i=r>1?i.fill(" "):i,i=r>0?i.concat(["└─"]):i,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({format:e}={}){return o.toMultihash(this._storage,this,{format:e})}static async fromMultihash(e,t,n,{access:r,length:i=-1,exclude:s=[],timeout:a,concurrency:c,sortFn:u,onProgressCallback:f}={}){const{logId:h,entries:l,heads:d}=await o.fromMultihash(e,n,{length:i,exclude:s,timeout:a,onProgressCallback:f,concurrency:c,sortFn:u});return new v(e,t,{logId:h,access:r,entries:l,heads:d,sortFn:u})}static async fromEntryHash(e,t,n,{logId:r,access:i,length:s=-1,exclude:a=[],timeout:c,concurrency:u,sortFn:f,onProgressCallback:h}={}){const{entries:l}=await o.fromEntryHash(e,n,{length:s,exclude:a,timeout:c,concurrency:u,onProgressCallback:h});return new v(e,t,{logId:r,access:i,entries:l,sortFn:f})}static async fromJSON(e,t,n,{access:r,length:i=-1,timeout:s,sortFn:a,onProgressCallback:c}={}){const{logId:u,entries:f}=await o.fromJSON(e,n,{length:i,timeout:s,onProgressCallback:c});return new v(e,t,{logId:u,access:r,entries:f,sortFn:a})}static async fromEntry(e,t,n,{access:r,length:i=-1,exclude:s=[],timeout:a,concurrency:c,sortFn:u,onProgressCallback:f}={}){const{logId:h,entries:l}=await o.fromEntry(e,n,{length:i,exclude:s,timeout:a,concurrency:c,onProgressCallback:f});return new v(e,t,{logId:h,access:r,entries:l,sortFn:u})}static findHeads(e){var t=e.reduce((e,t,n,r)=>(t.next.forEach(n=>e[n]=t.hash),e),{});return e.filter(e=>void 0===t[e.hash]).sort((e,t)=>e.clock.id>t.clock.id)}static findTails(e){var t={},n=[],r={},i=[];e.forEach(e=>{0===e.next.length&&n.push(e);e.next.forEach(n=>{t[n]||(t[n]=[]),t[n].push(e)}),i=i.concat(e.next),r[e.hash]=!0});const o=i.filter(e=>void 0===r[e]).map(e=>t[e]).reduce((e,t,n,r)=>e.concat(p(t,"hash")),[]).concat(n);return p(o,"hash").sort(s.compare)}static findTailHashes(e){var t={};return e.forEach(e=>t[e.hash]=!0),e.reduce((e,n,r,i)=>(n.next.reverse().forEach(n=>{void 0===t[n]&&e.splice(0,0,n)}),e),[])}static difference(e,t){const n=Object.keys(e._headsIndex),r={},i={},s=e=>{r[e]||t.get(e)||(n.push(e),r[e]=!0)};for(;n.length>0;){const o=n.shift(),a=e.get(o);a&&!t.get(o)&&a.id===t.id&&(i[a.hash]=a,r[a.hash]=!0,a.next.forEach(s))}return i}}e.exports=v,e.exports.Sorting=u,e.exports.Entry=s,e.exports.AccessController=l}).call(this,n(8).Buffer)},function(e,t,n){"use strict";t.byteLength=function(e){var t=u(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=u(e),o=r[0],a=r[1],c=new s(function(e,t,n){return 3*(t+n)/4-n}(0,o,a)),f=0,h=a>0?o-4:o;for(n=0;n>16&255,c[f++]=t>>8&255,c[f++]=255&t;2===a&&(t=i[e.charCodeAt(n)]<<2|i[e.charCodeAt(n+1)]>>4,c[f++]=255&t);1===a&&(t=i[e.charCodeAt(n)]<<10|i[e.charCodeAt(n+1)]<<4|i[e.charCodeAt(n+2)]>>2,c[f++]=t>>8&255,c[f++]=255&t);return c},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,s=[],o=0,a=n-i;oa?a:o+16383));1===i?(t=e[n-1],s.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],s.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return s.join("")};for(var r=[],i=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=o.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function f(e,t,n){for(var i,s,o=[],a=t;a>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return o.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){ +var r=n(38),i=n(39),s=n(40);function o(){return c.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(o()=o())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o().toString(16)+" bytes");return 0|e}function p(e,t){if(c.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 n=e.length;if(0===n)return 0;for(var r=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return z(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return H(e).length;default:if(r)return z(e).length;t=(""+t).toLowerCase(),r=!0}}function b(e,t,n){var r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return O(this,t,n);case"utf8":case"utf-8":return S(this,t,n);case"ascii":return U(this,t,n);case"latin1":case"binary":return I(this,t,n);case"base64":return _(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function g(e,t,n){var r=e[t];e[t]=e[n],e[n]=r}function k(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=c.from(t,r)),c.isBuffer(t))return 0===t.length?-1:y(e,t,n,r,i);if("number"==typeof t)return t&=255,c.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):y(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function y(e,t,n,r,i){var s,o=1,a=e.length,c=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;o=2,a/=2,c/=2,n/=2}function u(e,t){return 1===o?e[t]:e.readUInt16BE(t*o)}if(i){var h=-1;for(s=n;sa&&(n=a-c),s=n;s>=0;s--){for(var f=!0,l=0;li&&(r=i):r=i;var s=t.length;if(s%2!=0)throw new TypeError("Invalid hex string");r>s/2&&(r=s/2);for(var o=0;o>8,i=n%256,s.push(i),s.push(r);return s}(t,e.length-n),e,n,r)}function _(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function S(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i239?4:u>223?3:u>191?2:1;if(i+f<=n)switch(f){case 1:u<128&&(h=u);break;case 2:128==(192&(s=e[i+1]))&&(c=(31&u)<<6|63&s)>127&&(h=c);break;case 3:s=e[i+1],o=e[i+2],128==(192&s)&&128==(192&o)&&(c=(15&u)<<12|(63&s)<<6|63&o)>2047&&(c<55296||c>57343)&&(h=c);break;case 4:s=e[i+1],o=e[i+2],a=e[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(c=(15&u)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&c<1114112&&(h=c)}null===h?(h=65533,f=1):h>65535&&(h-=65536,r.push(h>>>10&1023|55296),h=56320|1023&h),r.push(h),i+=f}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var n="",r=0;for(;r0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),""},c.prototype.compare=function(e,t,n,r,i){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;for(var s=(i>>>=0)-(r>>>=0),o=(n>>>=0)-(t>>>=0),a=Math.min(s,o),u=this.slice(r,i),h=e.slice(t,n),f=0;fi)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var s=!1;;)switch(r){case"hex":return w(this,e,t,n);case"utf8":case"utf-8":return m(this,e,t,n);case"ascii":return v(this,e,t,n);case"latin1":case"binary":return x(this,e,t,n);case"base64":return E(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,e,t,n);default:if(s)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),s=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function U(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;ir)&&(n=r);for(var i="",s=t;sn)throw new RangeError("Trying to access beyond buffer length")}function C(e,t,n,r,i,s){if(!c.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 L(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,s=Math.min(e.length-n,2);i>>8*(r?i:1-i)}function P(e,t,n,r){t<0&&(t=4294967295+t+1);for(var i=0,s=Math.min(e.length-n,4);i>>8*(r?i:3-i)&255}function N(e,t,n,r,i,s){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function j(e,t,n,r,s){return s||N(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function D(e,t,n,r,s){return s||N(e,0,n,8),i.write(e,t,n,r,52,8),n+8}c.prototype.slice=function(e,t){var n,r=this.length;if((e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t0&&(i*=256);)r+=this[e+--t]*i;return r},c.prototype.readUInt8=function(e,t){return t||T(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return t||T(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return t||T(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return t||T(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return t||T(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||T(e,t,this.length);for(var r=this[e],i=1,s=0;++s=(i*=128)&&(r-=Math.pow(2,8*t)),r},c.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||T(e,t,this.length);for(var r=t,i=1,s=this[e+--r];r>0&&(i*=256);)s+=this[e+--r]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*t)),s},c.prototype.readInt8=function(e,t){return t||T(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){t||T(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt16BE=function(e,t){t||T(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},c.prototype.readInt32LE=function(e,t){return t||T(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return t||T(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return t||T(e,4,this.length),i.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return t||T(e,4,this.length),i.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return t||T(e,8,this.length),i.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return t||T(e,8,this.length),i.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,n,r){(e=+e,t|=0,n|=0,r)||C(this,e,t,n,Math.pow(2,8*n)-1,0);var i=1,s=0;for(this[t]=255&e;++s=0&&(s*=256);)this[t+i]=e/s&255;return t+n},c.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,1,255,0),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,2,65535,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e):P(this,e,t,!0),t+4},c.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,4,4294967295,0),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):P(this,e,t,!1),t+4},c.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);C(this,e,t,n,i-1,-i)}var s=0,o=1,a=0;for(this[t]=255&e;++s>0)-a&255;return t+n},c.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t|=0,!r){var i=Math.pow(2,8*n-1);C(this,e,t,n,i-1,-i)}var s=n-1,o=1,a=0;for(this[t+s]=255&e;--s>=0&&(o*=256);)e<0&&0===a&&0!==this[t+s+1]&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n},c.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,1,127,-128),c.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):L(this,e,t,!0),t+2},c.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,2,32767,-32768),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):L(this,e,t,!1),t+2},c.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,4,2147483647,-2147483648),c.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):P(this,e,t,!0),t+4},c.prototype.writeInt32BE=function(e,t,n){return e=+e,t|=0,n||C(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),c.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e):P(this,e,t,!1),t+4},c.prototype.writeFloatLE=function(e,t,n){return j(this,e,t,!0,n)},c.prototype.writeFloatBE=function(e,t,n){return j(this,e,t,!1,n)},c.prototype.writeDoubleLE=function(e,t,n){return D(this,e,t,!0,n)},c.prototype.writeDoubleBE=function(e,t,n){return D(this,e,t,!1,n)},c.prototype.copy=function(e,t,n,r){if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t=0;--i)e[i+t]=this[i+n];else if(s<1e3||!c.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(s=t;s55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&s.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&s.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&s.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&s.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;s.push(n)}else if(n<2048){if((t-=2)<0)break;s.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;s.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;s.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return s}function H(e){return r.toByteArray(function(e){if((e=function(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}(e).replace(M,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function F(e,t,n,r){for(var i=0;i=t.length||i>=e.length);++i)t[i+n]=e[i];return i}}).call(this,n(20))},function(e,t,n){"use strict";const r=n(22),i=n(16),{names:s}=n(56),o=n(6),a=n(3),c=n(17),u={};for(const e in s)u[s[e]]=e;function h(e){if(!(e instanceof Uint8Array))throw new Error("multihash must be a Uint8Array");if(e.length<2)throw new Error("multihash too short. must be > 2 bytes.");const t=i.decode(e);if(!d(t))throw new Error("multihash unknown function code: 0x"+t.toString(16));e=e.slice(i.decode.bytes);const n=i.decode(e);if(n<0)throw new Error("multihash invalid length: "+n);if((e=e.slice(i.decode.bytes)).length!==n)throw new Error("multihash length inconsistent: 0x"+o(e,"base16"));return{code:t,name:u[t],length:n,digest:e}}function f(e){let t=e;if("string"==typeof e){if(void 0===s[e])throw new Error("Unrecognized hash function named: "+e);t=s[e]}if("number"!=typeof t)throw new Error("Hash function code should be a number. Got: "+t);if(void 0===u[t]&&!l(t))throw new Error("Unrecognized function code: "+t);return t}function l(e){return e>0&&e<16}function d(e){return!!l(e)||!!u[e]}function p(e){h(e)}e.exports={names:s,codes:Object.freeze(u),toHexString:function(e){if(!(e instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return o(e,"base16")},fromHexString:function(e){return a(e,"base16")},toB58String:function(e){if(!(e instanceof Uint8Array))throw new Error("must be passed a Uint8Array");return o(r.encode("base58btc",e)).slice(1)},fromB58String:function(e){const t=e instanceof Uint8Array?o(e):e;return r.decode("z"+t)},decode:h,encode:function(e,t,n){if(!e||void 0===t)throw new Error("multihash encode requires at least two args: digest, code");const r=f(t);if(!(e instanceof Uint8Array))throw new Error("digest should be a Uint8Array");if(null==n&&(n=e.length),n&&e.length!==n)throw new Error("digest length should be equal to specified length.");const s=i.encode(r),o=i.encode(n);return c([s,o,e],s.length+o.length+e.length)},coerceCode:f,isAppCode:l,validate:p,prefix:function(e){return p(e),e.subarray(0,2)},isValidCode:d}},function(e,t,n){"use strict";(function(t){const r=n(11),{isDefined:i,io:s}=n(12),o=n(114),a=()=>new Error("Ipfs instance not defined"),c=["next","refs"],u=e=>0===e?"dag-pb":"dag-cbor",h=e=>f.isEntry(e)?u(e.v):u(e);class f{static async create(e,t,n,s,o=[],c,u=[],h){if(!i(e))throw a();if(!i(t))throw new Error("Identity is required, cannot create entry");if(!i(n))throw new Error("Entry requires an id");if(!i(s))throw new Error("Entry requires data");if(!i(o)||!Array.isArray(o))throw new Error("'next' argument is not an array");const l={hash:null,id:n,payload:s,next:o.filter(i).map(e=>e.hash?e.hash:e),refs:u,v:2,clock:c||new r(t.publicKey)},d=await t.provider.sign(t,f.toBuffer(l));return l.key=t.publicKey,l.identity=t.toJSON(),l.sig=d,l.hash=await f.toMultihash(e,l,h),l}static async verify(e,t){if(!e)throw new Error("Identity-provider is required, cannot verify entry");if(!f.isEntry(t))throw new Error("Invalid Log entry");if(!t.key)throw new Error("Entry doesn't have a key");if(!t.sig)throw new Error("Entry doesn't have a signature");const n=f.toEntry(t,{presigned:!0}),r=t.v<1?"v0":"v1";return e.verify(t.sig,t.key,f.toBuffer(n),r)}static toBuffer(e){const n=0===e.v?JSON.stringify(e):o(e);return t.from(n)}static async toMultihash(e,t,n=!1){if(!e)throw a();if(!f.isEntry(t))throw new Error("Invalid object format, cannot generate entry hash");const r=f.toEntry(t);return s.write(e,h(r.v),r,{links:c,pin:n})}static toEntry(e,{presigned:t=!1,includeHash:n=!1}={}){const i={hash:n?e.hash:null,id:e.id,payload:e.payload,next:e.next},s=e.v;return s>1&&(i.refs=e.refs),i.v=e.v,i.clock=new r(e.clock.id,e.clock.time),t||(i.key=e.key,s>0&&(i.identity=e.identity),i.sig=e.sig),i}static async fromMultihash(e,t){if(!e)throw a();if(!t)throw new Error("Invalid hash: "+t);const n=await s.read(e,t,{links:c}),r=f.toEntry(n);return r.hash=t,r}static isEntry(e){return e&&void 0!==e.id&&void 0!==e.next&&void 0!==e.payload&&void 0!==e.v&&void 0!==e.hash&&void 0!==e.clock&&(void 0!==e.refs||e.v<2)}static compare(e,t){const n=r.compare(e.clock,t.clock);return 0===n?e.clock.id-1}static findChildren(e,t){let n=[],r=t.find(t=>f.isParent(e,t)),i=e;for(;r;)n.push(r),i=r,r=t.find(e=>f.isParent(i,e));return n=n.sort((e,t)=>e.clock.time>t.clock.time),n}}e.exports=f,e.exports.IPLD_LINKS=c,e.exports.getWriteFormat=h}).call(this,n(8).Buffer)},function(e,t,n){"use strict";class r{constructor(e,t){this.id=e,this.time=t||0}tick(){return new r(this.id,++this.time)}merge(e){return this.time=Math.max(this.time,e.time),new r(this.id,this.time)}clone(){return new r(this.id,this.time)}static compare(e,t){const n=e.time-t.time;return 0===n&&e.id!==t.id?e.id({encode:o,decode:a}),""],["base2","0",s(1),"01"],["base8","7",s(3),"01234567"],["base10","9",r,"0123456789"],["base16","f",s(4),"0123456789abcdef"],["base16upper","F",s(4),"0123456789ABCDEF"],["base32hex","v",s(5),"0123456789abcdefghijklmnopqrstuv"],["base32hexupper","V",s(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV"],["base32hexpad","t",s(5),"0123456789abcdefghijklmnopqrstuv="],["base32hexpadupper","T",s(5),"0123456789ABCDEFGHIJKLMNOPQRSTUV="],["base32","b",s(5),"abcdefghijklmnopqrstuvwxyz234567"],["base32upper","B",s(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"],["base32pad","c",s(5),"abcdefghijklmnopqrstuvwxyz234567="],["base32padupper","C",s(5),"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="],["base32z","h",s(5),"ybndrfg8ejkmcpqxot1uwisza345h769"],["base36","k",r,"0123456789abcdefghijklmnopqrstuvwxyz"],["base36upper","K",r,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"],["base58btc","z",r,"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"],["base58flickr","Z",r,"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"],["base64","m",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"],["base64pad","M",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="],["base64url","u",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"],["base64urlpad","U",s(6),"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="]],u=c.reduce((e,t)=>(e[t[0]]=new i(t[0],t[1],t[2],t[3]),e),{}),h=c.reduce((e,t)=>(e[t[1]]=u[t[0]],e),{});e.exports={names:u,codes:h}},function(e,t,n){"use strict";const{TextEncoder:r,TextDecoder:i}=n(15),s=new i,o=new r;e.exports={decodeText:e=>s.decode(e),encodeText:e=>o.encode(e),concat:function(e,t){const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}}},function(e,t,n){"use strict";t.TextEncoder=TextEncoder,t.TextDecoder=TextDecoder},function(e,t,n){e.exports={encode:n(53),decode:n(54),encodingLength:n(55)}},function(e,t,n){"use strict";e.exports=function(e,t){t||(t=e.reduce((e,t)=>e+t.length,0));const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}},function(e,t,n){"use strict";e.exports=function(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;nnew Promise((s,o)=>{if("function"!=typeof t)throw new TypeError("Mapper function is required");if(!Number.isSafeInteger(n)&&n!==1/0||!(n>=1))throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${n}\` (${typeof n})`);const a=[],c=[],u=e[Symbol.iterator]();let h=!1,f=!1,l=0,d=0;const p=()=>{if(h)return;const e=u.next(),n=d;if(d++,e.done)return f=!0,void(0===l&&(i||0===c.length?s(a):o(new r(c))));l++,(async()=>{try{const r=await e.value;a[n]=await t(r,n),l--,p()}catch(e){i?(h=!0,o(e)):(c.push(e),l--,p())}})()};for(let e=0;es.isDAGLink(e)?e:s.util.createDagLinkFromB58EncodedHash(e)),i(t),Object.defineProperties(this,{Data:{value:e,writable:!1,enumerable:!0},Links:{value:t,writable:!1,enumerable:!0},_serializedSize:{value:n,writable:!0,enumerable:!1},_size:{value:null,writable:!0,enumerable:!1}})}toJSON(){return this._json||(this._json=Object.freeze({data:this.Data,links:this.Links.map(e=>e.toJSON()),size:this.size})),Object.assign({},this._json)}toString(){return`DAGNode `}_invalidateCached(){this._serializedSize=null,this._size=null}addLink(e){return this._invalidateCached(),c(this,e)}rmLink(e){return this._invalidateCached(),u(this,e)}toDAGLink(e){return a(this,e)}serialize(){return o(this)}get size(){return null===this._size&&(null===this._serializedSize&&(this._serializedSize=this.serialize().length),this._size=this.Links.reduce((e,t)=>e+t.Tsize,this._serializedSize)),this._size}set size(e){throw new Error("Can't set property: 'size' is immutable")}},{className:"DAGNode",symbolName:"@ipld/js-ipld-dag-pb/dagnode"})},function(e,t,n){"use strict";e.exports=function(e,{className:t,symbolName:n}){const r=Symbol.for(n),i={[t]:class extends e{constructor(...e){super(...e),Object.defineProperty(this,r,{value:!0})}get[Symbol.toStringTag](){return t}}}[t];return i["is"+t]=e=>!(!e||!e[r]),i},e.exports.proto=function(e,{className:t,symbolName:n,withoutNew:r}){const i=Symbol.for(n),s={[t]:function(...t){if(r&&!(this instanceof s))return new s(...t);const n=e.call(this,...t)||this;return n&&!n[i]&&Object.defineProperty(n,i,{value:!0}),n}}[t];return s.prototype=Object.create(e.prototype),s.prototype.constructor=s,Object.defineProperty(s.prototype,Symbol.toStringTag,{get:()=>t}),s["is"+t]=e=>!(!e||!e[i]),s}},function(e,t,n){"use strict";const r=n(64),i=n(65),s=(e,t)=>{const n=e.nameAsBuffer,r=t.nameAsBuffer;return i(n,r)};e.exports=e=>{r.inplace(e,s)}},function(e,t,n){"use strict";const r=n(29)(n(30)),i=n(4);t=e.exports;const s=e=>{const t=e.Data,n=e.Links||[];return r.PBNode.encode((e=>{const t={};return e.Data&&e.Data.byteLength>0?t.Data=e.Data:t.Data=null,e.Links&&e.Links.length>0?t.Links=e.Links.map(e=>({Hash:e.Hash.bytes,Name:e.Name,Tsize:e.Tsize})):t.Links=null,t})({Data:t,Links:n}))};t.serializeDAGNode=s,t.serializeDAGNodeLike=(e,t=[])=>{const n={Data:e};return n.Links=t.map(e=>i.isDAGLink(e)?e:i.util.createDagLinkFromB58EncodedHash(e)),s(n)}},function(e,t,n){"use strict";var r=n(66),i=n(70);e.exports=function(e,t){if(t||(t={}),!e)throw new Error("Pass in a .proto string or a protobuf-schema parsed object");var n="object"!=typeof e||e instanceof Uint8Array?r.parse(e):e,s=function(){var e=this;i(n,t.encodings||{}).forEach((function(t){e[t.name]=function(e){if(!e)return null;var t={};return Object.keys(e).forEach((function(n){t[n]=e[n].value})),t}(t.values)||t}))};return s.prototype.toString=function(){return r.stringify(n)},s.prototype.toJSON=function(){return n},new s}},function(e,t,n){"use strict";e.exports="// An IPFS MerkleDAG Link\nmessage PBLink {\n\n // multihash of the target object\n optional bytes Hash = 1;\n\n // utf string name. should be unique per object\n optional string Name = 2;\n\n // cumulative size of target object\n optional uint64 Tsize = 3;\n}\n\n// An IPFS MerkleDAG Node\nmessage PBNode {\n\n // refs to other objects\n repeated PBLink Links = 2;\n\n // opaque user data\n optional bytes Data = 1;\n}"},function(e,t,n){"use strict";const r=n(5),i=n(23),s=n(96);(t=e.exports).codec=i.DAG_PB,t.defaultHashAlg=i.SHA2_256;t.cid=async(e,n)=>{const o={cidVersion:1,hashAlg:t.defaultHashAlg},a=Object.assign(o,n),c=await s(e,a.hashAlg),u=i.print[t.codec];return new r(a.cidVersion,u,c)}},function(e,t,n){(function(t){function n(e){return(4294967296+e).toString(16).substring(1)}e.exports={normalizeInput:function(e){var n;if(e instanceof Uint8Array)n=e;else if(e instanceof t)n=new Uint8Array(e);else{if("string"!=typeof e)throw new Error("Input must be an string, Buffer or Uint8Array");n=new Uint8Array(t.from(e,"utf8"))}return n},toHex:function(e){return Array.prototype.map.call(e,(function(e){return(e<16?"0":"")+e.toString(16)})).join("")},debugPrint:function(e,t,r){for(var i="\n"+e+" = ",s=0;ss.isDAGNode(e)?e.serialize():o(e.Data,e.Links),t.deserialize=e=>{const t=r.PBNode.decode(e),n=t.Links.map(e=>new i(e.Name,e.Tsize,e.Hash)),o=null==t.Data?new Uint8Array(0):t.Data;return new s(o,n,e.byteLength)},t.cid=(e,t)=>a.cid(e,t)},function(e,t,n){"use strict";const r=n(11);function i(e,t,n){const i=r.compare(e.clock,t.clock);return 0===i?n(e,t):i}function s(e,t,n){return e.clock.id===t.clock.id?n(e,t):e.clock.ide,r=(e,t)=>s(e,t,n);return((e,t)=>i(e,t,r))(e,t)},t.SortByEntryHash=function(e,t){const n=(e,t)=>e.hashs(e,t,n);return((e,t)=>i(e,t,r))(e,t)},t.NoZeroes=function(e){const t=`Your log's tiebreaker function, ${e.name}, has returned zero and therefore cannot be`;return(n,r)=>{const i=e(n,r);if(0===i)throw Error(t);return i}}},function(e,t,n){"use strict";e.exports={IPFSNotDefinedError:()=>new 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"),LtOrLteMustBeStringOrArray:()=>new Error("lt or lte must be a string or array of Entries")}},function(e,t,n){"use strict";(function(t){const r=n(21),i=n(45),s=n(10),o=n(116),a=n(36),c=n(11),u=n(35),{LastWriteWins:h,NoZeroes:f}=u,l=n(119),{isDefined:d,findUniques:p}=n(12),b=n(120),g=e=>e.hash,k=(e,t)=>e.concat(t),y=e=>e.next,w=(e,t)=>Math.max(e,t.clock.time),m=(e,t)=>(e[t.hash]=t,e);class v extends i{constructor(e,t,{logId:n,access:r,entries:i,heads:s,clock:o,sortFn:u,concurrency:p,hashIndex:g=new Map}={}){if(!d(e))throw a.IPFSNotDefinedError();if(!d(t))throw new Error("Identity is required");if(d(r)||(r=new l),d(i)&&!Array.isArray(i))throw new Error("'entries' argument must be an array of Entry instances");if(d(s)&&!Array.isArray(s))throw new Error("'heads' argument must be an array");d(u)||(u=h),super(),this._sortFn=f(u),this._storage=e,this._id=n||(new Date).getTime().toString(),this._access=r,this._identity=t;const k=(i||[]).reduce(m,{});this._entryIndex=new b(k),i=Object.values(k)||[],s=s||v.findHeads(i),this._headsIndex=s.reduce(m,{}),this._hashIndex=g,i.forEach(e=>this._hashIndex.set(e.hash,e.next)),this._nextsIndex={};i.forEach(e=>e.next.forEach(t=>this._nextsIndex[t]=e.hash)),g.forEach((e,t)=>e.forEach(e=>this._nextsIndex[e]=t));const y=Math.max(o?o.time:0,this.heads.reduce(w,0));this._clock=new c(this._identity.publicKey,y),this.joinConcurrency=p||16}get id(){return this._id}get clock(){return this._clock}get length(){return this._hashIndex.size}async values(){return Object.values(await this.traverse(this.heads)).reverse()}get heads(){return Object.values(this._headsIndex).sort(this._sortFn).reverse()}async tails(){const e=await this.values();return v.findTails(e)}async tailHashes(){const e=await this.values();return v.findTailHashes(e)}setIdentity(e){this._identity=e;const t=Math.max(this.clock.time,this.heads.reduce(w,0));this._clock=new c(this._identity.publicKey,t)}async get(e){if(!this.has(e))return;const t=this._entryIndex.get(e);if(t)return t;let n;try{n=await s.fromMultihash(this._storage,e),this._entryIndex.set(n.hash,n)}catch(e){}return n}has(e){return this._hashIndex.has(e.hash||e)}async traverse(e,t=-1,n){let i=e.sort(this._sortFn).reverse(),s={};const o={};let a=0;const c=async e=>this.get(e),u=e=>{e&&!s[e.hash]&&(i=[e,...i].sort(this._sortFn).reverse(),s[e.hash]=!0)};for(;i.length>0&&(a{const t=new Set;for(let n=1;n<=e;n*=2){const e=Math.min(n-1,i.length-1);t.add(i[e])}return t})(Math.min(t,i.length));i.length!a.includes(e)),h=await s.create(this._storage,this._identity,this.id,e,a,this.clock,u,n);if(!await this._access.canAppend(h,this._identity.provider))throw new Error(`Could not append entry, key "${this._identity.id}" is not allowed to write to the log`);return this._entryIndex.set(h.hash,h),a.forEach(e=>this._nextsIndex[e]=h.hash),this._headsIndex={},this._headsIndex[h.hash]=h,this._hashIndex.set(h.hash,a),h}iterator({gt:e,gte:t,lt:n,lte:r,amount:i=-1}={}){if(0===i)return async function*(){}();if(r&&"string"!=typeof r&&!Array.isArray(r))throw a.LtOrLteMustBeStringOrArray();if(n&&"string"!=typeof n&&!Array.isArray(n))throw a.LtOrLteMustBeStringOrArray();const s=this;return async function*(){if("string"==typeof r){const e=await s.get(r);r=[e]}if("string"==typeof n){const e=await s.get(n),t=await s.get(e.next[0]);n=[t]}const o=(r||n||s.heads).filter(d);let a=null;if(t){a=(await s.get(t)).hash}else if(e){a=(await s.get(e)).hash}const c=a?-1:i||-1,u=await s.traverse(o,c,a);let h=Object.values(u);e&&h.pop(),(e||t)&&i>-1&&(h=h.slice(h.length-i,h.length));for await(const e of h)yield e}()}async join(e,t=-1){if(!d(e))throw a.LogNotDefinedError();if(!v.isLog(e))throw a.NotALogError();if(this.id!==e.id)return;const n=await v.difference(e,this),i=this._identity.provider,o=async e=>{if(!await this._access.canAppend(e,i))throw new Error(`Could not append entry, key "${e.identity.id}" is not allowed to write to the log`)},u=Object.values(n);await r(u,async e=>{await o(e),await(async e=>{const t=await s.verify(i,e),n=e.identity?e.identity.publicKey:e.key;if(!t)throw new Error(`Could not validate signature "${e.sig}" for entry "${e.hash}" and key "${n}"`)})(e)},{concurrency:this.joinConcurrency});u.forEach(e=>{e.next.forEach(t=>this._nextsIndex[t]=e.hash),this._hashIndex.set(e.hash,e.next)}),this._entryIndex.add(n);const h=Object.values(n).map(y).reduce(k,[]),f=v.findHeads(Object.values(Object.assign({},this._headsIndex,e._headsIndex))).filter(e=>!h.find(t=>t===e.hash)).filter(e=>!this._nextsIndex[e.hash]).reduce(m,{});if(this._headsIndex=f,t>-1){let e=await this.values();e=e.slice(-t),this._entryIndex=null,this._entryIndex=new b(e.reduce(m,{})),this._hashIndex=new Map,e.forEach(e=>this._hashIndex.set(e.hash,e.next)),this._nextsIndex={};const n=e=>e.next.forEach(t=>this._nextsIndex[t]=e.hash);e.forEach(n),this._headsIndex=v.findHeads(e).reduce(m,{})}const l=Object.values(this._headsIndex).reduce(w,0);return this._clock=new c(this.clock.id,Math.max(this.clock.time,l)),this}toJSON(){return{id:this.id,heads:this.heads.sort(this._sortFn).reverse().map(g)}}async toSnapshot(){const e=await this.values();return{id:this.id,heads:this.heads,values:e}}toBuffer(){return t.from(JSON.stringify(this.toJSON()))}async toString(e){const t=await this.values();return t.slice().reverse().map((n,r)=>{const i=s.findChildren(n,t).length;let o=new Array(Math.max(i-1,0));return o=i>1?o.fill(" "):o,o=i>0?o.concat(["└─"]):o,o.join("")+(e?e(n.payload):n.payload)}).join("\n")}static isLog(e){return void 0!==e.id&&void 0!==e.heads}toMultihash({format:e}={}){return o.toMultihash(this._storage,this,{format:e})}static async fromMultihash(e,t,n,{access:r,length:i=-1,exclude:s=[],timeout:a,concurrency:c,sortFn:u,onProgressCallback:h}={}){const{logId:f,entries:l,heads:d}=await o.fromMultihash(e,n,{length:i,exclude:s,timeout:a,onProgressCallback:h,concurrency:c,sortFn:u});return new v(e,t,{logId:f,access:r,entries:l,heads:d,sortFn:u})}static async fromEntryHash(e,t,n,{logId:r,access:i,length:s=-1,exclude:a=[],timeout:c,concurrency:u,sortFn:h,onProgressCallback:f}={}){const{entries:l}=await o.fromEntryHash(e,n,{length:s,exclude:a,timeout:c,concurrency:u,onProgressCallback:f});return new v(e,t,{logId:r,access:i,entries:l,sortFn:h})}static async fromJSON(e,t,n,{access:r,length:i=-1,timeout:s,sortFn:a,onProgressCallback:c}={}){const{logId:u,entries:h}=await o.fromJSON(e,n,{length:i,timeout:s,onProgressCallback:c});return new v(e,t,{logId:u,access:r,entries:h,sortFn:a})}static async fromEntry(e,t,n,{access:r,length:i=-1,exclude:s=[],timeout:a,concurrency:c,sortFn:u,onProgressCallback:h}={}){const{logId:f,entries:l}=await o.fromEntry(e,n,{length:i,exclude:s,timeout:a,concurrency:c,onProgressCallback:h});return new v(e,t,{logId:f,access:r,entries:l,sortFn:u})}static findHeads(e){const t=e.reduce((e,t,n,r)=>(t.next.forEach(n=>e[n]=t.hash),e),{});return e.filter(e=>void 0===t[e.hash]).sort((e,t)=>e.clock.id>t.clock.id)}static findTails(e){const t={},n=[],r={};let i=[];e.forEach(e=>{0===e.next.length&&n.push(e);e.next.forEach(n=>{t[n]||(t[n]=[]),t[n].push(e)}),i=i.concat(e.next),r[e.hash]=!0});const o=i.filter(e=>void 0===r[e]).map(e=>t[e]).reduce((e,t,n,r)=>e.concat(p(t,"hash")),[]).concat(n);return p(o,"hash").sort(s.compare)}static findTailHashes(e){const t={};return e.forEach(e=>t[e.hash]=!0),e.reduce((e,n,r,i)=>(n.next.reverse().forEach(n=>{void 0===t[n]&&e.splice(0,0,n)}),e),[])}static async difference(e,t){const n={},i=Array.from(e._hashIndex.keys()).filter(e=>!t.has(e));return(await r(i,t=>e.get(t))).forEach(e=>{n[e.hash]=e}),n}}v.Entry=s,e.exports=v,e.exports.Sorting=u,e.exports.Entry=s,e.exports.AccessController=l}).call(this,n(8).Buffer)},function(e,t,n){"use strict";t.byteLength=function(e){var t=u(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){var t,n,r=u(e),o=r[0],a=r[1],c=new s(function(e,t,n){return 3*(t+n)/4-n}(0,o,a)),h=0,f=a>0?o-4:o;for(n=0;n>16&255,c[h++]=t>>8&255,c[h++]=255&t;2===a&&(t=i[e.charCodeAt(n)]<<2|i[e.charCodeAt(n+1)]>>4,c[h++]=255&t);1===a&&(t=i[e.charCodeAt(n)]<<10|i[e.charCodeAt(n+1)]<<4|i[e.charCodeAt(n+2)]>>2,c[h++]=t>>8&255,c[h++]=255&t);return c},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,s=[],o=0,a=n-i;oa?a:o+16383));1===i?(t=e[n-1],s.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],s.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return s.join("")};for(var r=[],i=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,c=o.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}function h(e,t,n){for(var i,s,o=[],a=t;a>18&63]+r[s>>12&63]+r[s>>6&63]+r[63&s]);return o.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ -t.read=function(e,t,n,r,i){var s,o,a=8*i-r-1,c=(1<>1,f=-7,h=n?i-1:0,l=n?-1:1,d=e[t+h];for(h+=l,s=d&(1<<-f)-1,d>>=-f,f+=a;f>0;s=256*s+e[t+h],h+=l,f-=8);for(o=s&(1<<-f)-1,s>>=-f,f+=r;f>0;o=256*o+e[t+h],h+=l,f-=8);if(0===s)s=1-u;else{if(s===c)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),s-=u}return(d?-1:1)*o*Math.pow(2,s-r)},t.write=function(e,t,n,r,i,s){var o,a,c,u=8*s-i-1,f=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:s-1,p=r?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,o=f):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),(t+=o+h>=1?l/c:l*Math.pow(2,1-h))*c>=2&&(o++,c/=2),o+h>=f?(a=0,o=f):o+h>=1?(a=(t*c-1)*Math.pow(2,i),o+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(o=o<0;e[n+d]=255&o,d+=p,o/=256,u-=8);e[n+d-p]|=128*b}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){"use strict";const r=n(42),i=n(43);class s extends Error{constructor(e){if(!Array.isArray(e))throw new TypeError("Expected input to be an Array, got "+typeof e);let t=(e=[...e].map(e=>e instanceof Error?e:null!==e&&"object"==typeof e?Object.assign(new Error(e.message),e):new Error(e))).map(e=>"string"==typeof e.stack?i(e.stack).replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g,""):String(e)).join("\n");t="\n"+r(t,4),super(t),this.name="AggregateError",Object.defineProperty(this,"_errors",{value:e})}*[Symbol.iterator](){for(const e of this._errors)yield e}}e.exports=s},function(e,t,n){"use strict";e.exports=(e,t=1,n)=>{if(n={indent:" ",includeEmptyLines:!1,...n},"string"!=typeof e)throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof e}\``);if("number"!=typeof t)throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof t}\``);if("string"!=typeof n.indent)throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof n.indent}\``);if(0===t)return e;const r=n.includeEmptyLines?/^/gm:/^(?!\s*$)/gm;return e.replace(r,n.indent.repeat(t))}},function(e,t,n){"use strict";const r=n(44),i=/\s+at.*(?:\(|\s)(.*)\)?/,s=/^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/,o=void 0===r.homedir?"":r.homedir();e.exports=(e,t)=>(t=Object.assign({pretty:!1},t),e.replace(/\\/g,"/").split("\n").filter(e=>{const t=e.match(i);if(null===t||!t[1])return!0;const n=t[1];return!n.includes(".app/Contents/Resources/electron.asar")&&!n.includes(".app/Contents/Resources/default_app.asar")&&!s.test(n)}).filter(e=>""!==e.trim()).map(e=>t.pretty?e.replace(i,(e,t)=>e.replace(t,t.replace(o,"~"))):e).join("\n"))},function(e,t){},function(e,t,n){"use strict";e.exports=class{constructor(e){}append(e){}merge(e){}get(e){}has(e){}get values(){}get length(){}}},function(e,t,n){"use strict";e.exports=function(e,t,n){var r={},i={};return e.forEach(e=>i[n?e[n]:e]=!0),t.reduce((e,t)=>{var s=void 0!==i[n?t[n]:t],o=void 0!==r[n?t[n]:t];return s||o||(e.push(t),r[n?t[n]:t]=!0),e},[])}},function(e,t,n){"use strict";e.exports=function(e,t){const n={};return e.forEach(e=>n[t?e[t]:e]=e),Object.keys(n).map(e=>n[e])}},function(e,t,n){"use strict";e.exports=e=>null!=e},function(e,t,n){(function(t){const r=n(5),i=n(62),s=e=>e?Array.isArray(e)?e.map(s):new r(e):e,o=(e,t)=>{if(!e||"string"==typeof e)return e;if(Array.isArray(e))return e.map(o);if(e["/"])return e["/"];const n=t.base||"base58btc";return e.toBaseEncodedString(n)},a={"dag-pb":{read:async(e,n)=>{const r=(await e.dag.get(n)).value;return JSON.parse(t.from(r.Data).toString())},write:async(e,n,r)=>{const s=t.from(JSON.stringify(n)),o=new i.DAGNode(s),a=(await e.dag.put(o,{format:"dag-pb",hashAlg:"sha2-256"})).toV0().toBaseEncodedString();return(r.pin||!1)&&await e.pin.add(a),a}},"dag-cbor":{write:async(e,t,n)=>{const r=Object.assign({},t);(n.links||[]).forEach(e=>{r[e]&&(r[e]=s(r[e]))});const i=n.base||"base58btc",o=n.onlyHash||!1,a=(await e.dag.put(r,{onlyHash:o})).toBaseEncodedString(i);return(n.pin||!1)&&await e.pin.add(a),a},read:async(e,t,n)=>{const r=(await e.dag.get(t)).value;return(n.links||[]).forEach(e=>{r[e]&&(r[e]=o(r[e],n))}),r}},raw:{write:async(e,t,n)=>{const r=n.onlyHash||!1,s=n.base||"base58btc",o=Object.assign({},{onlyHash:r},n.format?{format:n.format,hashAlg:"sha2-256"}:{});"dag-pb"===o.format&&(t=new i.DAGNode(t));const a=(await e.dag.put(t,o)).toBaseEncodedString(s);return(n.pin||!1)&&await e.pin.add(a),a}}};e.exports={read:(e,t,n={})=>{t=new r(t);const i=a[t.codec];if(!i)throw new Error("Unsupported codec");return i.read(e,t,n)},write:(e,t,n,r={})=>{const i=a[t];if(!i)throw new Error("Unsupported codec");return i.write(e,n,r)}}}).call(this,n(8).Buffer)},function(e,t,n){"use strict";e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n>>0,u=new Uint8Array(s);e[n];){var f=t[e.charCodeAt(n)];if(255===f)return;for(var h=0,l=s-1;(0!==f||h>>0,u[l]=f%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");i=h,n++}if(" "!==e[n]){for(var d=s-i;d!==s&&0===u[d];)d++;for(var p=new Uint8Array(r+(s-d)),b=r;d!==s;)p[b++]=u[d++];return p}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,i=0,s=t.length;i!==s&&0===t[i];)i++,n++;for(var c=(s-i)*u+1>>>0,f=new Uint8Array(c);i!==s;){for(var h=t[i],l=0,d=c-1;(0!==h||l>>0,f[d]=h%o>>>0,h=h/o>>>0;if(0!==h)throw new Error("Non-zero carry");r=l,i++}for(var p=c-r;p!==c&&0===f[p];)p++;for(var b=a.repeat(n);pt=>({encode:n=>((e,t,n)=>{const r="="===t[t.length-1],i=(1<n;)o-=n,s+=t[i&a>>o];if(o&&(s+=t[i&a<((e,t,n)=>{const r={};for(let e=0;e=8&&(o-=8,s[c++]=255&a>>o)}if(o>=n||255&a<<8-o)throw new SyntaxError("Unexpected end of data");return s})(n,t,e)})}},function(e,t){e.exports=function e(t,r,i){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw e.bytes=0,new RangeError("Could not encode varint");r=r||[];var s=i=i||0;for(;t>=n;)r[i++]=255&t|128,t/=128;for(;-128&t;)r[i++]=255&t|128,t>>>=7;return r[i]=0|t,e.bytes=i-s+1,r};var n=Math.pow(2,31)},function(e,t){e.exports=function e(t,n){var r,i=0,s=0,o=n=n||0,a=t.length;do{if(o>=a||s>49)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=s<28?(127&r)<=128);return e.bytes=o-n,i}},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),s=Math.pow(2,28),o=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),u=Math.pow(2,56),f=Math.pow(2,63);e.exports=function(e){return e>1,h=-7,f=n?i-1:0,l=n?-1:1,d=e[t+f];for(f+=l,s=d&(1<<-h)-1,d>>=-h,h+=a;h>0;s=256*s+e[t+f],f+=l,h-=8);for(o=s&(1<<-h)-1,s>>=-h,h+=r;h>0;o=256*o+e[t+f],f+=l,h-=8);if(0===s)s=1-u;else{if(s===c)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,r),s-=u}return(d?-1:1)*o*Math.pow(2,s-r)},t.write=function(e,t,n,r,i,s){var o,a,c,u=8*s-i-1,h=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:s-1,p=r?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,o=h):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-o))<1&&(o--,c*=2),(t+=o+f>=1?l/c:l*Math.pow(2,1-f))*c>=2&&(o++,c/=2),o+f>=h?(a=0,o=h):o+f>=1?(a=(t*c-1)*Math.pow(2,i),o+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,i),o=0));i>=8;e[n+d]=255&a,d+=p,a/=256,i-=8);for(o=o<0;e[n+d]=255&o,d+=p,o/=256,u-=8);e[n+d-p]|=128*b}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},function(e,t,n){"use strict";const r=n(42),i=n(43);class s extends Error{constructor(e){if(!Array.isArray(e))throw new TypeError("Expected input to be an Array, got "+typeof e);let t=(e=[...e].map(e=>e instanceof Error?e:null!==e&&"object"==typeof e?Object.assign(new Error(e.message),e):new Error(e))).map(e=>"string"==typeof e.stack?i(e.stack).replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g,""):String(e)).join("\n");t="\n"+r(t,4),super(t),this.name="AggregateError",Object.defineProperty(this,"_errors",{value:e})}*[Symbol.iterator](){for(const e of this._errors)yield e}}e.exports=s},function(e,t,n){"use strict";e.exports=(e,t=1,n)=>{if(n={indent:" ",includeEmptyLines:!1,...n},"string"!=typeof e)throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof e}\``);if("number"!=typeof t)throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof t}\``);if("string"!=typeof n.indent)throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof n.indent}\``);if(0===t)return e;const r=n.includeEmptyLines?/^/gm:/^(?!\s*$)/gm;return e.replace(r,n.indent.repeat(t))}},function(e,t,n){"use strict";const r=n(44),i=/\s+at.*(?:\(|\s)(.*)\)?/,s=/^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/,o=void 0===r.homedir?"":r.homedir();e.exports=(e,t)=>(t=Object.assign({pretty:!1},t),e.replace(/\\/g,"/").split("\n").filter(e=>{const t=e.match(i);if(null===t||!t[1])return!0;const n=t[1];return!n.includes(".app/Contents/Resources/electron.asar")&&!n.includes(".app/Contents/Resources/default_app.asar")&&!s.test(n)}).filter(e=>""!==e.trim()).map(e=>t.pretty?e.replace(i,(e,t)=>e.replace(t,t.replace(o,"~"))):e).join("\n"))},function(e,t){},function(e,t,n){"use strict";e.exports=class{constructor(e){}append(e){}merge(e){}get(e){}has(e){}get values(){}get length(){}}},function(e,t,n){"use strict";e.exports=function(e,t,n){const r={},i={};return e.forEach(e=>i[n?e[n]:e]=!0),t.reduce((e,t)=>{const s=void 0!==i[n?t[n]:t],o=void 0!==r[n?t[n]:t];return s||o||(e.push(t),r[n?t[n]:t]=!0),e},[])}},function(e,t,n){"use strict";e.exports=function(e,t){const n={};return e.forEach(e=>n[t?e[t]:e]=e),Object.keys(n).map(e=>n[e])}},function(e,t,n){"use strict";e.exports=e=>null!=e},function(e,t,n){(function(t){const r=n(5),i=n(62),s=e=>e?Array.isArray(e)?e.map(s):new r(e):e,o=(e,t)=>{if(!e||"string"==typeof e)return e;if(Array.isArray(e))return e.map(o);if(e["/"])return e["/"];const n=t.base||"base58btc";return e.toBaseEncodedString(n)},a={"dag-pb":{read:async(e,n)=>{const r=(await e.dag.get(n)).value;return JSON.parse(t.from(r.Data).toString())},write:async(e,n,r)=>{const s=t.from(JSON.stringify(n)),o=new i.DAGNode(s),a=(await e.dag.put(o,{format:"dag-pb",hashAlg:"sha2-256"})).toV0().toBaseEncodedString();return(r.pin||!1)&&await e.pin.add(a),a}},"dag-cbor":{write:async(e,t,n)=>{const r=Object.assign({},t);(n.links||[]).forEach(e=>{r[e]&&(r[e]=s(r[e]))});const i=n.base||"base58btc",o=n.onlyHash||!1,a=(await e.dag.put(r,{onlyHash:o})).toBaseEncodedString(i);return(n.pin||!1)&&await e.pin.add(a),a},read:async(e,t,n)=>{const r=(await e.dag.get(t)).value;return(n.links||[]).forEach(e=>{r[e]&&(r[e]=o(r[e],n))}),r}},raw:{write:async(e,t,n)=>{const r=n.onlyHash||!1,s=n.base||"base58btc",o=Object.assign({},{onlyHash:r},n.format?{format:n.format,hashAlg:"sha2-256"}:{});"dag-pb"===o.format&&(t=new i.DAGNode(t));const a=(await e.dag.put(t,o)).toBaseEncodedString(s);return(n.pin||!1)&&await e.pin.add(a),a}}};e.exports={read:(e,t,n={})=>{t=new r(t);const i=a[t.codec];if(!i)throw new Error("Unsupported codec");return i.read(e,t,n)},write:(e,t,n,r={})=>{const i=a[t];if(!i)throw new Error("Unsupported codec");return i.write(e,n,r)}}}).call(this,n(8).Buffer)},function(e,t,n){"use strict";e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n>>0,u=new Uint8Array(s);e[n];){var h=t[e.charCodeAt(n)];if(255===h)return;for(var f=0,l=s-1;(0!==h||f>>0,u[l]=h%256>>>0,h=h/256>>>0;if(0!==h)throw new Error("Non-zero carry");i=f,n++}if(" "!==e[n]){for(var d=s-i;d!==s&&0===u[d];)d++;for(var p=new Uint8Array(r+(s-d)),b=r;d!==s;)p[b++]=u[d++];return p}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,i=0,s=t.length;i!==s&&0===t[i];)i++,n++;for(var c=(s-i)*u+1>>>0,h=new Uint8Array(c);i!==s;){for(var f=t[i],l=0,d=c-1;(0!==f||l>>0,h[d]=f%o>>>0,f=f/o>>>0;if(0!==f)throw new Error("Non-zero carry");r=l,i++}for(var p=c-r;p!==c&&0===h[p];)p++;for(var b=a.repeat(n);pt=>({encode:n=>((e,t,n)=>{const r="="===t[t.length-1],i=(1<n;)o-=n,s+=t[i&a>>o];if(o&&(s+=t[i&a<((e,t,n)=>{const r={};for(let e=0;e=8&&(o-=8,s[c++]=255&a>>o)}if(o>=n||255&a<<8-o)throw new SyntaxError("Unexpected end of data");return s})(n,t,e)})}},function(e,t){e.exports=function e(t,r,i){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw e.bytes=0,new RangeError("Could not encode varint");r=r||[];var s=i=i||0;for(;t>=n;)r[i++]=255&t|128,t/=128;for(;-128&t;)r[i++]=255&t|128,t>>>=7;return r[i]=0|t,e.bytes=i-s+1,r};var n=Math.pow(2,31)},function(e,t){e.exports=function e(t,n){var r,i=0,s=0,o=n=n||0,a=t.length;do{if(o>=a||s>49)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=s<28?(127&r)<=128);return e.bytes=o-n,i}},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),s=Math.pow(2,28),o=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),u=Math.pow(2,56),h=Math.pow(2,63);e.exports=function(e){return eu&&(s=u),o>u&&(o=u),a=i,c=s;;)if(at[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength"!==e[0])throw new Error("Unexpected token in map type: "+e[0]);e.shift(),t.name=e.shift();break;case"repeated":case"required":case"optional":var n=e.shift();t.required="required"===n,t.repeated="repeated"===n,t.type=e.shift(),t.name=e.shift();break;case"[":t.options=s(e);break;case";":if(null===t.name)throw new Error("Missing field name");if(null===t.type)throw new Error("Missing type in message field: "+t.name);if(-1===t.tag)throw new Error("Missing tag number in message field: "+t.name);return e.shift(),t;default:throw new Error("Unexpected token in message field: "+e[0])}throw new Error("No ; found for message field")},a=function(e){for(var t={enums:[],options:{},messages:[],fields:[],extends:[],extensions:null};e.length;)switch(e[0]){case"map":case"repeated":case"optional":case"required":t.fields.push(o(e));break;case"enum":t.enums.push(p(e));break;case"message":t.messages.push(f(e));break;case"extensions":t.extensions=u(e);break;case"oneof":e.shift();var n=e.shift();if("{"!==e[0])throw new Error("Unexpected token in oneof: "+e[0]);for(e.shift();"}"!==e[0];){e.unshift("optional");var r=o(e);r.oneof=n,t.fields.push(r)}e.shift();break;case"extend":t.extends.push(c(e));break;case";":e.shift();break;case"reserved":for(e.shift();";"!==e[0];)e.shift();break;case"option":var i=b(e);if(void 0!==t.options[i.name])throw new Error("Duplicate option "+i.name);t.options[i.name]=i.value;break;default:e.unshift("optional"),t.fields.push(o(e))}return t},c=function(e){return{name:e[1],message:f(e)}},u=function(e){e.shift();var t=Number(e.shift());if(isNaN(t))throw new Error("Invalid from in extensions definition");if("to"!==e.shift())throw new Error("Expected keyword 'to' in extensions definition");var n=e.shift();if("max"===n&&(n=536870911),n=Number(n),isNaN(n))throw new Error("Invalid to in extensions definition");if(";"!==e.shift())throw new Error("Missing ; in extensions definition");return{from:t,to:n}},f=function(e){e.shift();var t=1,n=[],r={name:e.shift(),options:{},enums:[],extends:[],messages:[],fields:[]};if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("{"===e[0]?t++:"}"===e[0]&&t--,!t)return e.shift(),n=a(n),r.enums=n.enums,r.messages=n.messages,r.fields=n.fields,r.extends=n.extends,r.extensions=n.extensions,r.options=n.options,r;n.push(e.shift())}if(t)throw new Error("No closing tag for message")},h=function(e){e.shift();var t=e.shift();if(";"!==e[0])throw new Error("Expected ; but found "+e[0]);return e.shift(),t},l=function(e){if(e.shift(),"="!==e[0])throw new Error("Expected = but found "+e[0]);e.shift();var t=e.shift();switch(t){case'"proto2"':t=2;break;case'"proto3"':t=3;break;default:throw new Error("Expected protobuf syntax version but found "+t)}if(";"!==e[0])throw new Error("Expected ; but found "+e[0]);return e.shift(),t},d=function(e){if(e.length<4)throw new Error("Invalid enum value: "+e.slice(0,3).join(" "));if("="!==e[1])throw new Error("Expected = but found "+e[1]);if(";"!==e[3]&&"["!==e[3])throw new Error("Expected ; or [ but found "+e[1]);var t=e.shift();e.shift();var n={value:null,options:{}};return n.value=Number(e.shift()),"["===e[0]&&(n.options=s(e)),e.shift(),{name:t,val:n}},p=function(e){e.shift();var t={},n={name:e.shift(),values:{},options:{}};if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("}"===e[0])return e.shift(),";"===e[0]&&e.shift(),n;if("option"!==e[0]){var r=d(e);n.values[r.name]=r.val}else t=b(e),n.options[t.name]=t.value}throw new Error("No closing tag for enum")},b=function(e){for(var t=null,n=null,r=function(e){return"true"===e||"false"!==e&&e.replace(/^"+|"+$/gm,"")};e.length;){if(";"===e[0])return e.shift(),{name:t,value:n};switch(e[0]){case"option":e.shift();var i="("===e[0];if(i&&e.shift(),t=e.shift(),i){if(")"!==e[0])throw new Error("Expected ) but found "+e[0]);e.shift()}"."===e[0][0]&&(t+=e.shift());break;case"=":if(e.shift(),null===t)throw new Error("Expected key for option with value: "+e[0]);if(n=r(e.shift()),"optimize_for"===t&&!/^(SPEED|CODE_SIZE|LITE_RUNTIME)$/.test(n))throw new Error("Unexpected value for option optimize_for: "+n);"{"===n&&(n=k(e));break;default:throw new Error("Unexpected token in option: "+e[0])}}},k=function(e){for(var t=function(e){return"true"===e||"false"!==e&&e.replace(/^"+|"+$/gm,"")},n={};e.length;){if("}"===e[0])return e.shift(),n;var r="("===e[0];r&&e.shift();var i=e.shift();if(r){if(")"!==e[0])throw new Error("Expected ) but found "+e[0]);e.shift()}var s=null;switch(e[0]){case":":if(void 0!==n[i])throw new Error("Duplicate option map key "+i);e.shift(),"{"===(s=t(e.shift()))&&(s=k(e)),n[i]=s,";"===e[0]&&e.shift();break;case"{":if(e.shift(),s=k(e),void 0===n[i]&&(n[i]=[]),!Array.isArray(n[i]))throw new Error("Duplicate option map key "+i);n[i].push(s);break;default:throw new Error("Unexpected token in option map: "+e[0])}}throw new Error("No closing tag for option map")},g=function(e){e.shift();var t=e.shift().replace(/^"+|"+$/gm,"");if(";"!==e[0])throw new Error("Unexpected token: "+e[0]+'. Expected ";"');return e.shift(),t},y=function(e){e.shift();var t={name:e.shift(),methods:[],options:{}};if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("}"===e[0])return e.shift(),";"===e[0]&&e.shift(),t;switch(e[0]){case"option":var n=b(e);if(void 0!==t.options[n.name])throw new Error("Duplicate option "+n.name);t.options[n.name]=n.value;break;case"rpc":t.methods.push(w(e));break;default:throw new Error("Unexpected token in service: "+e[0])}}throw new Error("No closing tag for service")},w=function(e){e.shift();var t={name:e.shift(),input_type:null,output_type:null,client_streaming:!1,server_streaming:!1,options:{}};if("("!==e[0])throw new Error("Expected ( but found "+e[0]);if(e.shift(),"stream"===e[0]&&(e.shift(),t.client_streaming=!0),t.input_type=e.shift(),")"!==e[0])throw new Error("Expected ) but found "+e[0]);if(e.shift(),"returns"!==e[0])throw new Error("Expected returns but found "+e[0]);if(e.shift(),"("!==e[0])throw new Error("Expected ( but found "+e[0]);if(e.shift(),"stream"===e[0]&&(e.shift(),t.server_streaming=!0),t.output_type=e.shift(),")"!==e[0])throw new Error("Expected ) but found "+e[0]);if(e.shift(),";"===e[0])return e.shift(),t;if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("}"===e[0])return e.shift(),";"===e[0]&&e.shift(),t;if("option"!==e[0])throw new Error("Unexpected token in rpc options: "+e[0]);var n=b(e);if(void 0!==t.options[n.name])throw new Error("Duplicate option "+n.name);t.options[n.name]=n.value}throw new Error("No closing tag for rpc")};e.exports=function(e){for(var t=r(e.toString()),n=0;nt.extensions.to)throw new Error(t.name+" does not declare "+e.tag+" as an extension number");t.fields.push(e)}))}))})),o.messages.forEach((function(e){e.fields.forEach((function(t){var n,r,s,a;if(t.options&&"true"===t.options.packed&&-1===i.indexOf(t.type)){if(-1===t.type.indexOf(".")){if(e.enums&&e.enums.some((function(e){return e.name===t.type})))return}else{if((n=t.type.split(".")).length>2)throw new Error("what is this?");if(r=n[0],s=n[1],o.messages.some((function(e){if(e.name===r)return a=e,e})),a&&a.enums&&a.enums.some((function(e){return e.name===s})))return}throw new Error("Fields of type "+t.type+' cannot be declared [packed=true]. Only repeated fields of primitive numeric types (types which use the varint, 32-bit, or 64-bit wire types) can be declared "packed". See https://developers.google.com/protocol-buffers/docs/encoding#optional')}}))})),o}},function(e,t){e.exports=function(e){var t,n=function(e){return e.trim()};return e.replace(/([;,{}()=:[\]<>]|\/\*|\*\/)/g," $1 ").split(/\n/).map(n).filter(Boolean).map((function(e){var t=e.indexOf("//");return t>-1?e.slice(0,t):e})).map(n).filter(Boolean).join("\n").split(/\s+|\n+/gm).filter((t=!1,function(e){return"/*"===e?(t=!0,!1):"*/"===e?(t=!1,!1):!t}))}},function(e,t){var n=function(e,t){var n=e.repeated?"repeated":e.required?"required":"optional";"map"===e.type&&(n="map<"+e.map.from+","+e.map.to+">"),e.oneof&&(n="");var r=Object.keys(e.options||{}).map((function(t){return t+" = "+e.options[t]})).join(",");return r&&(r=" ["+r+"]"),t.push((n?n+" ":"")+("map"===e.map?"":e.type+" ")+e.name+" = "+e.tag+r+";"),t},r=function(e,t){t.push("message "+e.name+" {"),e.options||(e.options={}),o(e.options,t),e.enums||(e.enums=[]),e.enums.forEach((function(e){t.push(i(e,[]))})),e.messages||(e.messages=[]),e.messages.forEach((function(e){t.push(r(e,[]))}));var s={};return e.fields||(e.fields=[]),e.fields.forEach((function(e){e.oneof?(s[e.oneof]||(s[e.oneof]=[]),s[e.oneof].push(n(e,[]))):t.push(n(e,[]))})),Object.keys(s).forEach((function(e){s[e].unshift("oneof "+e+" {"),s[e].push("}"),t.push(s[e])})),t.push("}",""),t},i=function(e,t){t.push("enum "+e.name+" {"),e.options||(e.options={});var n=o(e.options,[]);return n.length>1&&t.push(n.slice(0,-1)),Object.keys(e.values).map((function(n){var r=s(e.values[n]);t.push([n+" = "+r+";"])})),t.push("}",""),t},s=function(e,t){var n=Object.keys(e.options||{}).map((function(t){return t+" = "+e.options[t]})).join(",");return n&&(n=" ["+n+"]"),e.value+n},o=function(e,t){var n=Object.keys(e);return n.forEach((function(n){var r=e[n];~n.indexOf(".")&&(n="("+n+")");var i=typeof r;"object"===i?(r=a(r,[])).length&&t.push("option "+n+" = {",r,"};"):("string"===i&&"optimize_for"!==n&&(r='"'+r+'"'),t.push("option "+n+" = "+r+";"))})),n.length>0&&t.push(""),t},a=function(e,t){return Object.keys(e).forEach((function(n){var r=e[n],i=typeof r;"object"===i?Array.isArray(r)?r.forEach((function(e){(e=a(e,[])).length&&t.push(n+" {",e,"}")})):(r=a(r,[])).length&&t.push(n+" {",r,"}"):("string"===i&&(r='"'+r+'"'),t.push(n+": "+r))})),t},c=function(e,t){var n="rpc "+e.name+"(";e.client_streaming&&(n+="stream "),n+=e.input_type+") returns (",e.server_streaming&&(n+="stream "),n+=e.output_type+")",e.options||(e.options={});var r=o(e.options,[]);return r.length>1?t.push(n+" {",r.slice(0,-1),"}"):t.push(n+";"),t},u=function(e){return function(t){return Array.isArray(t)?t.map(u(e+" ")).join("\n"):e+t}};e.exports=function(e){var t=[];return t.push('syntax = "proto'+e.syntax+'";',""),e.package&&t.push("package "+e.package+";",""),e.options||(e.options={}),o(e.options,t),e.enums||(e.enums=[]),e.enums.forEach((function(e){i(e,t)})),e.messages||(e.messages=[]),e.messages.forEach((function(e){r(e,t)})),e.services&&e.services.forEach((function(e){!function(e,t){t.push("service "+e.name+" {"),e.options||(e.options={}),o(e.options,t),e.methods||(e.methods=[]),e.methods.forEach((function(e){t.push(c(e,[]))})),t.push("}","")}(e,t)})),t.map(u("")).join("\n")}},function(e,t,n){"use strict";const r=n(71),i=n(92),s=n(93),o=n(94),a=n(1);e.exports=function(e,t){const n={},c={},u={},f=function(e,t){e.enums&&e.enums.forEach((function(e){e.id=t+(t?".":"")+e.name,c[e.id]=e,f(e,e.id)})),e.messages&&e.messages.forEach((function(r){r.id=t+(t?".":"")+r.name,n[r.id]=r,r.fields.forEach((function(r){if(!r.map)return;const i="Map_"+r.map.from+"_"+r.map.to,s={name:i,enums:[],messages:[],fields:[{name:"key",type:r.map.from,tag:1,repeated:!1,required:!0},{name:"value",type:r.map.to,tag:2,repeated:!1,required:!1}],extensions:null,id:t+(t?".":"")+i};n[s.id]||(n[s.id]=s,e.messages.push(s)),r.type=i,r.repeated=!0})),f(r,r.id)}))};f(e,"");const h=function(e,t){e.messages.forEach((function(n){t[n.name]=l(n.name,e.id)})),e.enums.forEach((function(e){t[e.name]=function(e){if(!e)return null;const t={};return Object.keys(e).forEach((function(n){t[n]=e[n].value})),t}(e.values)})),t.type=2,t.message=!0,t.name=e.name;const n={};e.fields.forEach((function(e){e.oneof&&(n[e.oneof]||(n[e.oneof]=[]),n[e.oneof].push(e.name))}));const r=e.fields.map((function(t){return l(t.type,e.id)})),a=o(e,r,n),c=s(e,l,r,n,a),u=i(e,l,r);return c.bytes=u.bytes=0,t.buffer=!0,t.encode=c,t.decode=u,t.encodingLength=a,t},l=function(e,i,s){if(t&&t[e])return t[e];if(r[e])return r[e];const o=(i?i+"."+e:e).split(".").map((function(t,n,r){return r.slice(0,n).concat(e).join(".")})).reverse().reduce((function(e,t){return e||n[t]||c[t]}),null);if(!1===s)return o;if(!o)throw new Error("Could not resolve "+e);if(o.values)return function(e){const t=Object.keys(e.values||[]).map((function(t){return parseInt(e.values[t].value,10)}));return r.make(0,(function e(n,r,i,s){if(!t.length||-1===t.indexOf(n))throw new Error("Invalid enum value: "+n);return a.encode(n,r,s),e.bytes=a.encode.bytes,r}),(function e(n,r,i){var s=a.decode(n,i);if(!t.length||-1===t.indexOf(s))throw new Error("Invalid enum value: "+s);return e.bytes=a.decode.bytes,s}),a.encodingLength)}(o);return u[o.id]||h(o,u[o.id]={})};return(e.enums||[]).concat((e.messages||[]).map((function(e){return l(e.id)})))}},function(e,t,n){"use strict";t.make=n(0),t.bytes=n(72),t.string=n(76),t.bool=n(77),t.int32=n(78),t.int64=n(79),t.sint32=t.sint64=n(80),t.uint32=t.uint64=t.enum=t.varint=n(86),t.fixed64=t.sfixed64=n(87),t.double=n(88),t.fixed32=n(89),t.sfixed32=n(90),t.float=n(91)},function(e,t,n){"use strict";const r=n(1),i=n(0);function s(e){return e.byteLength}e.exports=i(2,(function e(t,n,i,o){const a=o,c=s(t);r.encode(c,n,o),o+=r.encode.bytes,n.set(t,o),e.bytes=(o+=c)-a}),(function e(t,n,i){const s=i,o=r.decode(t,i);i+=r.decode.bytes;const a=t.slice(i,i+o);return i+=a.length,e.bytes=i-s,a}),(function(e){const t=s(e);return r.encodingLength(t)+t}))},function(e,t){e.exports=function e(t,r,i){r=r||[];var s=i=i||0;for(;t>=n;)r[i++]=255&t|128,t/=128;for(;-128&t;)r[i++]=255&t|128,t>>>=7;return r[i]=0|t,e.bytes=i-s+1,r};var n=Math.pow(2,31)},function(e,t){e.exports=function e(t,n){var r,i=0,s=0,o=n=n||0,a=t.length;do{if(o>=a)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=s<28?(127&r)<=128);return e.bytes=o-n,i}},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),s=Math.pow(2,28),o=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),u=Math.pow(2,56),f=Math.pow(2,63);e.exports=function(e){return e0;return e.bytes=1,i}),(function(){return 1}))},function(e,t,n){"use strict";const r=n(1),i=n(0);e.exports=i(0,(function e(t,n,i,s){r.encode(t<0?t+4294967296:t,n,s),e.bytes=r.encode.bytes}),(function e(t,n,i){const s=r.decode(t,i);return e.bytes=r.decode.bytes,s>2147483647?s-4294967296:s}),(function(e){return r.encodingLength(e<0?e+4294967296:e)}))},function(e,t,n){"use strict";const r=n(1),i=n(0);e.exports=i(0,(function e(t,n,i,s){if(t<0){const i=s+9;for(r.encode(-1*t,n,s),n[s+=r.encode.bytes-1]=128|n[s];s=Math.pow(2,63)){let n=9;for(;255===t[i+n-1];)n--;n=n||9;const o=t.subarray(i,i+n);o[n-1]=127&o[n-1],s=-1*r.decode(o,0),e.bytes=10}else e.bytes=r.decode.bytes;return s}),(function(e){return e<0?10:r.encodingLength(e)}))},function(e,t,n){"use strict";const r=n(81),i=n(0);e.exports=i(0,(function e(t,n,i,s){r.encode(t,n,s),e.bytes=r.encode.bytes}),(function e(t,n,i){const s=r.decode(t,i);return e.bytes=r.decode.bytes,s}),r.encodingLength)},function(e,t,n){var r=n(82);t.encode=function e(t,n,i){t=t>=0?2*t:-2*t-1;var s=r.encode(t,n,i);return e.bytes=r.encode.bytes,s},t.decode=function e(t,n){var i=r.decode(t,n);return e.bytes=r.decode.bytes,1&i?(i+1)/-2:i/2},t.encodingLength=function(e){return r.encodingLength(e>=0?2*e:-2*e-1)}},function(e,t,n){e.exports={encode:n(83),decode:n(84),encodingLength:n(85)}},function(e,t){e.exports=function e(t,r,i){r=r||[];var s=i=i||0;for(;t>=n;)r[i++]=255&t|128,t/=128;for(;-128&t;)r[i++]=255&t|128,t>>>=7;return r[i]=0|t,e.bytes=i-s+1,r};var n=Math.pow(2,31)},function(e,t){e.exports=function e(t,n){var r,i=0,s=0,o=n=n||0,a=t.length;do{if(o>=a)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=s<28?(127&r)<=128);return e.bytes=o-n,i}},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),s=Math.pow(2,28),o=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),u=Math.pow(2,56),f=Math.pow(2,63);e.exports=function(e){return e{n=e},get:()=>void 0===n?r:n},["has"+i]:{configurable:!0,value:()=>void 0!==n},["set"+i]:{configurable:!0,value:e=>{n=e}},["get"+i]:{configurable:!0,value:()=>n},["clear"+i]:{configurable:!0,value:()=>{n=void 0,e[t]=void 0}}})}var a=function(e,t,n,i){switch(e){case 0:return r.decode(t,i),i+r.decode.bytes;case 1:return i+8;case 2:var s=r.decode(t,i);return i+r.decode.bytes+s;case 3:case 4:throw new Error("Groups are not supported");case 5:return i+4;default:throw new Error("Unknown wire type: "+e)}},c=function(e){if(e.map)return{};if(e.repeated)return[];switch(e.type){case"string":return"";case"bool":return!1;case"float":case"double":case"sfixed32":case"fixed32":case"varint":case"enum":case"uint64":case"uint32":case"int64":case"int32":case"sint64":case"sint32":return 0;default:return null}},u=function(e,t){if(void 0===t)return t;switch(e.type){case"bool":return"true"===t;case"float":case"double":case"sfixed32":case"fixed32":case"varint":case"enum":case"uint64":case"uint32":case"int64":case"int32":case"sint64":case"sint32":return parseInt(t,10);default:return t}};e.exports=function(e,t,n){const f=[],h={},l=[],d=[];for(var p=0;p-1){const t=s(e[h]);delete n["has"+t],delete n["get"+t],delete n["set"+t],delete n["clear"+t],delete n[e[h]]}}let d;if(e.message){const s=r.decode(i,c);c+=r.decode.bytes;const o=e.decode(i,a,c,c+s);t.map?(d=n[f]||{},d[o.key]=o.value):t.repeated?(d=n[f]||[],d.push(o)):d=o}else t.repeated?(d=n[f]||[],d.push(e.decode(i,a,c))):d=e.decode(i,a,c);return o(n,f,d),c+=e.decode.bytes}return function t(s,p,k,g){if(null==k&&(k=0),null==g&&(g=s.length),!(g<=s.length&&k<=s.length))throw new Error("Decoded message is not valid");p||(p=new DataView(s.buffer,s.byteOffset,s.byteLength));for(var y,w=k,m={};;){if(g<=k){var v,E,x="",A=0;for(A=0;A-1){_=!0;break}_||(v?y.repeated?E=[]:(E=E&&v[E]?v[E].value:v[Object.keys(v)[0]].value,E=parseInt(E||0,10)):(t=c(y),E=u(y,E)),o(m,x,E,t))}}return t.bytes=k-w,m}var O=r.decode(s,k);k+=r.decode.bytes;var I=h[O>>3];if(null!=I){var B=n[I];if((y=e.fields[I]).packed){var C=r.decode(s,k);for(C+=k+=r.decode.bytes;k-1){if(y)throw new Error("only one of the properties defined in oneof "+e+" can be set");y=!0}}for(g=0;g{const n=await i.cid(e.serialize(),t);return new r(t.name||"",e.size,n)}},function(e,t,n){"use strict";const r=n(97),i=n(9),s=n(98),o=n(18);async function a(e,t,n){const r=await a.digest(e,t,n);return i.encode(r,t,n)}a.multihash=i,a.digest=async(e,t,n)=>{const r=a.createHash(t),i=await r(e);return n?i.slice(0,n):i},a.createHash=function(e){if(!e)throw r(new Error("hash algorithm must be specified"),"ERR_HASH_ALGORITHM_NOT_SPECIFIED");if(e=i.coerceCode(e),!a.functions[e])throw r(new Error(`multihash function '${e}' not yet supported`),"ERR_HASH_ALGORITHM_NOT_SUPPORTED");return a.functions[e]},a.functions={0:s.identity,17:s.sha1,18:s.sha2256,19:s.sha2512,20:s.sha3512,21:s.sha3384,22:s.sha3256,23:s.sha3224,24:s.shake128,25:s.shake256,26:s.keccak224,27:s.keccak256,28:s.keccak384,29:s.keccak512,34:s.murmur3128,35:s.murmur332,86:s.dblSha2256},s.addBlake(a.functions),a.validate=async(e,t)=>{const n=await a(e,i.decode(t).name);return o(t,n)},e.exports=a},function(e,t,n){"use strict";function r(e,t){for(const n in t)Object.defineProperty(e,n,{value:t[n],enumerable:!0,configurable:!0});return e}e.exports=function(e,t,n){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");n||(n={}),"object"==typeof t&&(n=t,t=void 0),null!=t&&(n.code=t);try{return r(e,n)}catch(t){n.message=e.message,n.stack=e.stack;const i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(e)),r(new i,n)}}},function(e,t,n){"use strict";const r=n(99),i=n(102),{factory:s}=n(104),{fromNumberTo32BitBuf:o}=n(105),a=n(3),c=e=>async t=>{switch(e){case"sha3-224":return new Uint8Array(r.sha3_224.arrayBuffer(t));case"sha3-256":return new Uint8Array(r.sha3_256.arrayBuffer(t));case"sha3-384":return new Uint8Array(r.sha3_384.arrayBuffer(t));case"sha3-512":return new Uint8Array(r.sha3_512.arrayBuffer(t));case"shake-128":return new Uint8Array(r.shake128.create(128).update(t).arrayBuffer());case"shake-256":return new Uint8Array(r.shake256.create(256).update(t).arrayBuffer());case"keccak-224":return new Uint8Array(r.keccak224.arrayBuffer(t));case"keccak-256":return new Uint8Array(r.keccak256.arrayBuffer(t));case"keccak-384":return new Uint8Array(r.keccak384.arrayBuffer(t));case"keccak-512":return new Uint8Array(r.keccak512.arrayBuffer(t));case"murmur3-128":return a(i.x64.hash128(t),"base16");case"murmur3-32":return o(i.x86.hash32(t));default:throw new TypeError(e+" is not a supported algorithm")}};e.exports={identity:e=>e,sha1:s("sha1"),sha2256:s("sha2-256"),sha2512:s("sha2-512"),dblSha2256:s("dbl-sha2-256"),sha3224:c("sha3-224"),sha3256:c("sha3-256"),sha3384:c("sha3-384"),sha3512:c("sha3-512"),shake128:c("shake-128"),shake256:c("shake-256"),keccak224:c("keccak-224"),keccak256:c("keccak-256"),keccak384:c("keccak-384"),keccak512:c("keccak-512"),murmur3128:c("murmur3-128"),murmur332:c("murmur3-32"),addBlake:n(106)}},function(e,t,n){(function(r,i){var s; +e.exports=function(){"use strict";var e=function(e,n){return t(e.slice(),n)};function t(e,t){"function"!=typeof t&&(t=function(e,t){return String(e).localeCompare(t)});var r=e.length;if(r<=1)return e;for(var i=new Array(r),s=1;su&&(s=u),o>u&&(o=u),a=i,c=s;;)if(at[n])return 1}return e.byteLength>t.byteLength?1:e.byteLength"!==e[0])throw new Error("Unexpected token in map type: "+e[0]);e.shift(),t.name=e.shift();break;case"repeated":case"required":case"optional":var n=e.shift();t.required="required"===n,t.repeated="repeated"===n,t.type=e.shift(),t.name=e.shift();break;case"[":t.options=s(e);break;case";":if(null===t.name)throw new Error("Missing field name");if(null===t.type)throw new Error("Missing type in message field: "+t.name);if(-1===t.tag)throw new Error("Missing tag number in message field: "+t.name);return e.shift(),t;default:throw new Error("Unexpected token in message field: "+e[0])}throw new Error("No ; found for message field")},a=function(e){for(var t={enums:[],options:{},messages:[],fields:[],extends:[],extensions:null};e.length;)switch(e[0]){case"map":case"repeated":case"optional":case"required":t.fields.push(o(e));break;case"enum":t.enums.push(p(e));break;case"message":t.messages.push(h(e));break;case"extensions":t.extensions=u(e);break;case"oneof":e.shift();var n=e.shift();if("{"!==e[0])throw new Error("Unexpected token in oneof: "+e[0]);for(e.shift();"}"!==e[0];){e.unshift("optional");var r=o(e);r.oneof=n,t.fields.push(r)}e.shift();break;case"extend":t.extends.push(c(e));break;case";":e.shift();break;case"reserved":for(e.shift();";"!==e[0];)e.shift();break;case"option":var i=b(e);if(void 0!==t.options[i.name])throw new Error("Duplicate option "+i.name);t.options[i.name]=i.value;break;default:e.unshift("optional"),t.fields.push(o(e))}return t},c=function(e){return{name:e[1],message:h(e)}},u=function(e){e.shift();var t=Number(e.shift());if(isNaN(t))throw new Error("Invalid from in extensions definition");if("to"!==e.shift())throw new Error("Expected keyword 'to' in extensions definition");var n=e.shift();if("max"===n&&(n=536870911),n=Number(n),isNaN(n))throw new Error("Invalid to in extensions definition");if(";"!==e.shift())throw new Error("Missing ; in extensions definition");return{from:t,to:n}},h=function(e){e.shift();var t=1,n=[],r={name:e.shift(),options:{},enums:[],extends:[],messages:[],fields:[]};if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("{"===e[0]?t++:"}"===e[0]&&t--,!t)return e.shift(),n=a(n),r.enums=n.enums,r.messages=n.messages,r.fields=n.fields,r.extends=n.extends,r.extensions=n.extensions,r.options=n.options,r;n.push(e.shift())}if(t)throw new Error("No closing tag for message")},f=function(e){e.shift();var t=e.shift();if(";"!==e[0])throw new Error("Expected ; but found "+e[0]);return e.shift(),t},l=function(e){if(e.shift(),"="!==e[0])throw new Error("Expected = but found "+e[0]);e.shift();var t=e.shift();switch(t){case'"proto2"':t=2;break;case'"proto3"':t=3;break;default:throw new Error("Expected protobuf syntax version but found "+t)}if(";"!==e[0])throw new Error("Expected ; but found "+e[0]);return e.shift(),t},d=function(e){if(e.length<4)throw new Error("Invalid enum value: "+e.slice(0,3).join(" "));if("="!==e[1])throw new Error("Expected = but found "+e[1]);if(";"!==e[3]&&"["!==e[3])throw new Error("Expected ; or [ but found "+e[1]);var t=e.shift();e.shift();var n={value:null,options:{}};return n.value=Number(e.shift()),"["===e[0]&&(n.options=s(e)),e.shift(),{name:t,val:n}},p=function(e){e.shift();var t={},n={name:e.shift(),values:{},options:{}};if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("}"===e[0])return e.shift(),";"===e[0]&&e.shift(),n;if("option"!==e[0]){var r=d(e);n.values[r.name]=r.val}else t=b(e),n.options[t.name]=t.value}throw new Error("No closing tag for enum")},b=function(e){for(var t=null,n=null,r=function(e){return"true"===e||"false"!==e&&e.replace(/^"+|"+$/gm,"")};e.length;){if(";"===e[0])return e.shift(),{name:t,value:n};switch(e[0]){case"option":e.shift();var i="("===e[0];if(i&&e.shift(),t=e.shift(),i){if(")"!==e[0])throw new Error("Expected ) but found "+e[0]);e.shift()}"."===e[0][0]&&(t+=e.shift());break;case"=":if(e.shift(),null===t)throw new Error("Expected key for option with value: "+e[0]);if(n=r(e.shift()),"optimize_for"===t&&!/^(SPEED|CODE_SIZE|LITE_RUNTIME)$/.test(n))throw new Error("Unexpected value for option optimize_for: "+n);"{"===n&&(n=g(e));break;default:throw new Error("Unexpected token in option: "+e[0])}}},g=function(e){for(var t=function(e){return"true"===e||"false"!==e&&e.replace(/^"+|"+$/gm,"")},n={};e.length;){if("}"===e[0])return e.shift(),n;var r="("===e[0];r&&e.shift();var i=e.shift();if(r){if(")"!==e[0])throw new Error("Expected ) but found "+e[0]);e.shift()}var s=null;switch(e[0]){case":":if(void 0!==n[i])throw new Error("Duplicate option map key "+i);e.shift(),"{"===(s=t(e.shift()))&&(s=g(e)),n[i]=s,";"===e[0]&&e.shift();break;case"{":if(e.shift(),s=g(e),void 0===n[i]&&(n[i]=[]),!Array.isArray(n[i]))throw new Error("Duplicate option map key "+i);n[i].push(s);break;default:throw new Error("Unexpected token in option map: "+e[0])}}throw new Error("No closing tag for option map")},k=function(e){e.shift();var t=e.shift().replace(/^"+|"+$/gm,"");if(";"!==e[0])throw new Error("Unexpected token: "+e[0]+'. Expected ";"');return e.shift(),t},y=function(e){e.shift();var t={name:e.shift(),methods:[],options:{}};if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("}"===e[0])return e.shift(),";"===e[0]&&e.shift(),t;switch(e[0]){case"option":var n=b(e);if(void 0!==t.options[n.name])throw new Error("Duplicate option "+n.name);t.options[n.name]=n.value;break;case"rpc":t.methods.push(w(e));break;default:throw new Error("Unexpected token in service: "+e[0])}}throw new Error("No closing tag for service")},w=function(e){e.shift();var t={name:e.shift(),input_type:null,output_type:null,client_streaming:!1,server_streaming:!1,options:{}};if("("!==e[0])throw new Error("Expected ( but found "+e[0]);if(e.shift(),"stream"===e[0]&&(e.shift(),t.client_streaming=!0),t.input_type=e.shift(),")"!==e[0])throw new Error("Expected ) but found "+e[0]);if(e.shift(),"returns"!==e[0])throw new Error("Expected returns but found "+e[0]);if(e.shift(),"("!==e[0])throw new Error("Expected ( but found "+e[0]);if(e.shift(),"stream"===e[0]&&(e.shift(),t.server_streaming=!0),t.output_type=e.shift(),")"!==e[0])throw new Error("Expected ) but found "+e[0]);if(e.shift(),";"===e[0])return e.shift(),t;if("{"!==e[0])throw new Error("Expected { but found "+e[0]);for(e.shift();e.length;){if("}"===e[0])return e.shift(),";"===e[0]&&e.shift(),t;if("option"!==e[0])throw new Error("Unexpected token in rpc options: "+e[0]);var n=b(e);if(void 0!==t.options[n.name])throw new Error("Duplicate option "+n.name);t.options[n.name]=n.value}throw new Error("No closing tag for rpc")};e.exports=function(e){for(var t=r(e.toString()),n=0;nt.extensions.to)throw new Error(t.name+" does not declare "+e.tag+" as an extension number");t.fields.push(e)}))}))})),o.messages.forEach((function(e){e.fields.forEach((function(t){var n,r,s,a;if(t.options&&"true"===t.options.packed&&-1===i.indexOf(t.type)){if(-1===t.type.indexOf(".")){if(e.enums&&e.enums.some((function(e){return e.name===t.type})))return}else{if((n=t.type.split(".")).length>2)throw new Error("what is this?");if(r=n[0],s=n[1],o.messages.some((function(e){if(e.name===r)return a=e,e})),a&&a.enums&&a.enums.some((function(e){return e.name===s})))return}throw new Error("Fields of type "+t.type+' cannot be declared [packed=true]. Only repeated fields of primitive numeric types (types which use the varint, 32-bit, or 64-bit wire types) can be declared "packed". See https://developers.google.com/protocol-buffers/docs/encoding#optional')}}))})),o}},function(e,t){e.exports=function(e){var t,n=function(e){return e.trim()};return e.replace(/([;,{}()=:[\]<>]|\/\*|\*\/)/g," $1 ").split(/\n/).map(n).filter(Boolean).map((function(e){var t=e.indexOf("//");return t>-1?e.slice(0,t):e})).map(n).filter(Boolean).join("\n").split(/\s+|\n+/gm).filter((t=!1,function(e){return"/*"===e?(t=!0,!1):"*/"===e?(t=!1,!1):!t}))}},function(e,t){var n=function(e,t){var n=e.repeated?"repeated":e.required?"required":"optional";"map"===e.type&&(n="map<"+e.map.from+","+e.map.to+">"),e.oneof&&(n="");var r=Object.keys(e.options||{}).map((function(t){return t+" = "+e.options[t]})).join(",");return r&&(r=" ["+r+"]"),t.push((n?n+" ":"")+("map"===e.map?"":e.type+" ")+e.name+" = "+e.tag+r+";"),t},r=function(e,t){t.push("message "+e.name+" {"),e.options||(e.options={}),o(e.options,t),e.enums||(e.enums=[]),e.enums.forEach((function(e){t.push(i(e,[]))})),e.messages||(e.messages=[]),e.messages.forEach((function(e){t.push(r(e,[]))}));var s={};return e.fields||(e.fields=[]),e.fields.forEach((function(e){e.oneof?(s[e.oneof]||(s[e.oneof]=[]),s[e.oneof].push(n(e,[]))):t.push(n(e,[]))})),Object.keys(s).forEach((function(e){s[e].unshift("oneof "+e+" {"),s[e].push("}"),t.push(s[e])})),t.push("}",""),t},i=function(e,t){t.push("enum "+e.name+" {"),e.options||(e.options={});var n=o(e.options,[]);return n.length>1&&t.push(n.slice(0,-1)),Object.keys(e.values).map((function(n){var r=s(e.values[n]);t.push([n+" = "+r+";"])})),t.push("}",""),t},s=function(e,t){var n=Object.keys(e.options||{}).map((function(t){return t+" = "+e.options[t]})).join(",");return n&&(n=" ["+n+"]"),e.value+n},o=function(e,t){var n=Object.keys(e);return n.forEach((function(n){var r=e[n];~n.indexOf(".")&&(n="("+n+")");var i=typeof r;"object"===i?(r=a(r,[])).length&&t.push("option "+n+" = {",r,"};"):("string"===i&&"optimize_for"!==n&&(r='"'+r+'"'),t.push("option "+n+" = "+r+";"))})),n.length>0&&t.push(""),t},a=function(e,t){return Object.keys(e).forEach((function(n){var r=e[n],i=typeof r;"object"===i?Array.isArray(r)?r.forEach((function(e){(e=a(e,[])).length&&t.push(n+" {",e,"}")})):(r=a(r,[])).length&&t.push(n+" {",r,"}"):("string"===i&&(r='"'+r+'"'),t.push(n+": "+r))})),t},c=function(e,t){var n="rpc "+e.name+"(";e.client_streaming&&(n+="stream "),n+=e.input_type+") returns (",e.server_streaming&&(n+="stream "),n+=e.output_type+")",e.options||(e.options={});var r=o(e.options,[]);return r.length>1?t.push(n+" {",r.slice(0,-1),"}"):t.push(n+";"),t},u=function(e){return function(t){return Array.isArray(t)?t.map(u(e+" ")).join("\n"):e+t}};e.exports=function(e){var t=[];return t.push('syntax = "proto'+e.syntax+'";',""),e.package&&t.push("package "+e.package+";",""),e.options||(e.options={}),o(e.options,t),e.enums||(e.enums=[]),e.enums.forEach((function(e){i(e,t)})),e.messages||(e.messages=[]),e.messages.forEach((function(e){r(e,t)})),e.services&&e.services.forEach((function(e){!function(e,t){t.push("service "+e.name+" {"),e.options||(e.options={}),o(e.options,t),e.methods||(e.methods=[]),e.methods.forEach((function(e){t.push(c(e,[]))})),t.push("}","")}(e,t)})),t.map(u("")).join("\n")}},function(e,t,n){"use strict";const r=n(71),i=n(92),s=n(93),o=n(94),a=n(1);e.exports=function(e,t){const n={},c={},u={},h=function(e,t){e.enums&&e.enums.forEach((function(e){e.id=t+(t?".":"")+e.name,c[e.id]=e,h(e,e.id)})),e.messages&&e.messages.forEach((function(r){r.id=t+(t?".":"")+r.name,n[r.id]=r,r.fields.forEach((function(r){if(!r.map)return;const i="Map_"+r.map.from+"_"+r.map.to,s={name:i,enums:[],messages:[],fields:[{name:"key",type:r.map.from,tag:1,repeated:!1,required:!0},{name:"value",type:r.map.to,tag:2,repeated:!1,required:!1}],extensions:null,id:t+(t?".":"")+i};n[s.id]||(n[s.id]=s,e.messages.push(s)),r.type=i,r.repeated=!0})),h(r,r.id)}))};h(e,"");const f=function(e,t){e.messages.forEach((function(n){t[n.name]=l(n.name,e.id)})),e.enums.forEach((function(e){t[e.name]=function(e){if(!e)return null;const t={};return Object.keys(e).forEach((function(n){t[n]=e[n].value})),t}(e.values)})),t.type=2,t.message=!0,t.name=e.name;const n={};e.fields.forEach((function(e){e.oneof&&(n[e.oneof]||(n[e.oneof]=[]),n[e.oneof].push(e.name))}));const r=e.fields.map((function(t){return l(t.type,e.id)})),a=o(e,r,n),c=s(e,l,r,n,a),u=i(e,l,r);return c.bytes=u.bytes=0,t.buffer=!0,t.encode=c,t.decode=u,t.encodingLength=a,t},l=function(e,i,s){if(t&&t[e])return t[e];if(r[e])return r[e];const o=(i?i+"."+e:e).split(".").map((function(t,n,r){return r.slice(0,n).concat(e).join(".")})).reverse().reduce((function(e,t){return e||n[t]||c[t]}),null);if(!1===s)return o;if(!o)throw new Error("Could not resolve "+e);if(o.values)return function(e){const t=Object.keys(e.values||[]).map((function(t){return parseInt(e.values[t].value,10)}));return r.make(0,(function e(n,r,i,s){if(!t.length||-1===t.indexOf(n))throw new Error("Invalid enum value: "+n);return a.encode(n,r,s),e.bytes=a.encode.bytes,r}),(function e(n,r,i){var s=a.decode(n,i);if(!t.length||-1===t.indexOf(s))throw new Error("Invalid enum value: "+s);return e.bytes=a.decode.bytes,s}),a.encodingLength)}(o);return u[o.id]||f(o,u[o.id]={})};return(e.enums||[]).concat((e.messages||[]).map((function(e){return l(e.id)})))}},function(e,t,n){"use strict";t.make=n(0),t.bytes=n(72),t.string=n(76),t.bool=n(77),t.int32=n(78),t.int64=n(79),t.sint32=t.sint64=n(80),t.uint32=t.uint64=t.enum=t.varint=n(86),t.fixed64=t.sfixed64=n(87),t.double=n(88),t.fixed32=n(89),t.sfixed32=n(90),t.float=n(91)},function(e,t,n){"use strict";const r=n(1),i=n(0);function s(e){return e.byteLength}e.exports=i(2,(function e(t,n,i,o){const a=o,c=s(t);r.encode(c,n,o),o+=r.encode.bytes,n.set(t,o),e.bytes=(o+=c)-a}),(function e(t,n,i){const s=i,o=r.decode(t,i);i+=r.decode.bytes;const a=t.slice(i,i+o);return i+=a.length,e.bytes=i-s,a}),(function(e){const t=s(e);return r.encodingLength(t)+t}))},function(e,t){e.exports=function e(t,r,i){r=r||[];var s=i=i||0;for(;t>=n;)r[i++]=255&t|128,t/=128;for(;-128&t;)r[i++]=255&t|128,t>>>=7;return r[i]=0|t,e.bytes=i-s+1,r};var n=Math.pow(2,31)},function(e,t){e.exports=function e(t,n){var r,i=0,s=0,o=n=n||0,a=t.length;do{if(o>=a)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=s<28?(127&r)<=128);return e.bytes=o-n,i}},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),s=Math.pow(2,28),o=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),u=Math.pow(2,56),h=Math.pow(2,63);e.exports=function(e){return e0;return e.bytes=1,i}),(function(){return 1}))},function(e,t,n){"use strict";const r=n(1),i=n(0);e.exports=i(0,(function e(t,n,i,s){r.encode(t<0?t+4294967296:t,n,s),e.bytes=r.encode.bytes}),(function e(t,n,i){const s=r.decode(t,i);return e.bytes=r.decode.bytes,s>2147483647?s-4294967296:s}),(function(e){return r.encodingLength(e<0?e+4294967296:e)}))},function(e,t,n){"use strict";const r=n(1),i=n(0);e.exports=i(0,(function e(t,n,i,s){if(t<0){const i=s+9;for(r.encode(-1*t,n,s),n[s+=r.encode.bytes-1]=128|n[s];s=Math.pow(2,63)){let n=9;for(;255===t[i+n-1];)n--;n=n||9;const o=t.subarray(i,i+n);o[n-1]=127&o[n-1],s=-1*r.decode(o,0),e.bytes=10}else e.bytes=r.decode.bytes;return s}),(function(e){return e<0?10:r.encodingLength(e)}))},function(e,t,n){"use strict";const r=n(81),i=n(0);e.exports=i(0,(function e(t,n,i,s){r.encode(t,n,s),e.bytes=r.encode.bytes}),(function e(t,n,i){const s=r.decode(t,i);return e.bytes=r.decode.bytes,s}),r.encodingLength)},function(e,t,n){var r=n(82);t.encode=function e(t,n,i){t=t>=0?2*t:-2*t-1;var s=r.encode(t,n,i);return e.bytes=r.encode.bytes,s},t.decode=function e(t,n){var i=r.decode(t,n);return e.bytes=r.decode.bytes,1&i?(i+1)/-2:i/2},t.encodingLength=function(e){return r.encodingLength(e>=0?2*e:-2*e-1)}},function(e,t,n){e.exports={encode:n(83),decode:n(84),encodingLength:n(85)}},function(e,t){e.exports=function e(t,r,i){r=r||[];var s=i=i||0;for(;t>=n;)r[i++]=255&t|128,t/=128;for(;-128&t;)r[i++]=255&t|128,t>>>=7;return r[i]=0|t,e.bytes=i-s+1,r};var n=Math.pow(2,31)},function(e,t){e.exports=function e(t,n){var r,i=0,s=0,o=n=n||0,a=t.length;do{if(o>=a)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],i+=s<28?(127&r)<=128);return e.bytes=o-n,i}},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),s=Math.pow(2,28),o=Math.pow(2,35),a=Math.pow(2,42),c=Math.pow(2,49),u=Math.pow(2,56),h=Math.pow(2,63);e.exports=function(e){return e{n=e},get:()=>void 0===n?r:n},["has"+i]:{configurable:!0,value:()=>void 0!==n},["set"+i]:{configurable:!0,value:e=>{n=e}},["get"+i]:{configurable:!0,value:()=>n},["clear"+i]:{configurable:!0,value:()=>{n=void 0,e[t]=void 0}}})}var a=function(e,t,n,i){switch(e){case 0:return r.decode(t,i),i+r.decode.bytes;case 1:return i+8;case 2:var s=r.decode(t,i);return i+r.decode.bytes+s;case 3:case 4:throw new Error("Groups are not supported");case 5:return i+4;default:throw new Error("Unknown wire type: "+e)}},c=function(e){if(e.map)return{};if(e.repeated)return[];switch(e.type){case"string":return"";case"bool":return!1;case"float":case"double":case"sfixed32":case"fixed32":case"varint":case"enum":case"uint64":case"uint32":case"int64":case"int32":case"sint64":case"sint32":return 0;default:return null}},u=function(e,t){if(void 0===t)return t;switch(e.type){case"bool":return"true"===t;case"float":case"double":case"sfixed32":case"fixed32":case"varint":case"enum":case"uint64":case"uint32":case"int64":case"int32":case"sint64":case"sint32":return parseInt(t,10);default:return t}};e.exports=function(e,t,n){const h=[],f={},l=[],d=[];for(var p=0;p-1){const t=s(e[f]);delete n["has"+t],delete n["get"+t],delete n["set"+t],delete n["clear"+t],delete n[e[f]]}}let d;if(e.message){const s=r.decode(i,c);c+=r.decode.bytes;const o=e.decode(i,a,c,c+s);t.map?(d=n[h]||{},d[o.key]=o.value):t.repeated?(d=n[h]||[],d.push(o)):d=o}else t.repeated?(d=n[h]||[],d.push(e.decode(i,a,c))):d=e.decode(i,a,c);return o(n,h,d),c+=e.decode.bytes}return function t(s,p,g,k){if(null==g&&(g=0),null==k&&(k=s.length),!(k<=s.length&&g<=s.length))throw new Error("Decoded message is not valid");p||(p=new DataView(s.buffer,s.byteOffset,s.byteLength));for(var y,w=g,m={};;){if(k<=g){var v,x,E="",A=0;for(A=0;A-1){_=!0;break}_||(v?y.repeated?x=[]:(x=x&&v[x]?v[x].value:v[Object.keys(v)[0]].value,x=parseInt(x||0,10)):(t=c(y),x=u(y,x)),o(m,E,x,t))}}return t.bytes=g-w,m}var I=r.decode(s,g);g+=r.decode.bytes;var O=f[I>>3];if(null!=O){var B=n[O];if((y=e.fields[O]).packed){var T=r.decode(s,g);for(T+=g+=r.decode.bytes;g-1){if(y)throw new Error("only one of the properties defined in oneof "+e+" can be set");y=!0}}for(k=0;k{const n=await i.cid(e.serialize(),t);return new r(t.name||"",e.size,n)}},function(e,t,n){"use strict";const r=n(97),i=n(9),s=n(98),o=n(18);async function a(e,t,n){const r=await a.digest(e,t,n);return i.encode(r,t,n)}a.multihash=i,a.digest=async(e,t,n)=>{const r=a.createHash(t),i=await r(e);return n?i.slice(0,n):i},a.createHash=function(e){if(!e)throw r(new Error("hash algorithm must be specified"),"ERR_HASH_ALGORITHM_NOT_SPECIFIED");if(e=i.coerceCode(e),!a.functions[e])throw r(new Error(`multihash function '${e}' not yet supported`),"ERR_HASH_ALGORITHM_NOT_SUPPORTED");return a.functions[e]},a.functions={0:s.identity,17:s.sha1,18:s.sha2256,19:s.sha2512,20:s.sha3512,21:s.sha3384,22:s.sha3256,23:s.sha3224,24:s.shake128,25:s.shake256,26:s.keccak224,27:s.keccak256,28:s.keccak384,29:s.keccak512,34:s.murmur3128,35:s.murmur332,86:s.dblSha2256},s.addBlake(a.functions),a.validate=async(e,t)=>{const n=await a(e,i.decode(t).name);return o(t,n)},e.exports=a},function(e,t,n){"use strict";function r(e,t){for(const n in t)Object.defineProperty(e,n,{value:t[n],enumerable:!0,configurable:!0});return e}e.exports=function(e,t,n){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");n||(n={}),"object"==typeof t&&(n=t,t=void 0),null!=t&&(n.code=t);try{return r(e,n)}catch(t){n.message=e.message,n.stack=e.stack;const i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(e)),r(new i,n)}}},function(e,t,n){"use strict";const r=n(99),i=n(102),{factory:s}=n(104),{fromNumberTo32BitBuf:o}=n(105),a=n(3),c=e=>async t=>{switch(e){case"sha3-224":return new Uint8Array(r.sha3_224.arrayBuffer(t));case"sha3-256":return new Uint8Array(r.sha3_256.arrayBuffer(t));case"sha3-384":return new Uint8Array(r.sha3_384.arrayBuffer(t));case"sha3-512":return new Uint8Array(r.sha3_512.arrayBuffer(t));case"shake-128":return new Uint8Array(r.shake128.create(128).update(t).arrayBuffer());case"shake-256":return new Uint8Array(r.shake256.create(256).update(t).arrayBuffer());case"keccak-224":return new Uint8Array(r.keccak224.arrayBuffer(t));case"keccak-256":return new Uint8Array(r.keccak256.arrayBuffer(t));case"keccak-384":return new Uint8Array(r.keccak384.arrayBuffer(t));case"keccak-512":return new Uint8Array(r.keccak512.arrayBuffer(t));case"murmur3-128":return a(i.x64.hash128(t),"base16");case"murmur3-32":return o(i.x86.hash32(t));default:throw new TypeError(e+" is not a supported algorithm")}};e.exports={identity:e=>e,sha1:s("sha1"),sha2256:s("sha2-256"),sha2512:s("sha2-512"),dblSha2256:s("dbl-sha2-256"),sha3224:c("sha3-224"),sha3256:c("sha3-256"),sha3384:c("sha3-384"),sha3512:c("sha3-512"),shake128:c("shake-128"),shake256:c("shake-256"),keccak224:c("keccak-224"),keccak256:c("keccak-256"),keccak384:c("keccak-384"),keccak512:c("keccak-512"),murmur3128:c("murmur3-128"),murmur332:c("murmur3-32"),addBlake:n(106)}},function(e,t,n){(function(r,i){var s; /** * [js-sha3]{@link https://github.com/emn178/js-sha3} * @@ -18,5 +18,5 @@ e.exports=function(){"use strict";var e=function(e,n){return t(e.slice(),n)};fun * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2015-2018 * @license MIT - */!function(){"use strict";var o="input is invalid type",a="object"==typeof window,c=a?window:{};c.JS_SHA3_NO_WINDOW&&(a=!1);var u=!a&&"object"==typeof self;!c.JS_SHA3_NO_NODE_JS&&"object"==typeof r&&r.versions&&r.versions.node?c=i:u&&(c=self);var f=!c.JS_SHA3_NO_COMMON_JS&&"object"==typeof e&&e.exports,h=n(101),l=!c.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,d="0123456789abcdef".split(""),p=[4,1024,262144,67108864],b=[0,8,16,24],k=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],g=[224,256,384,512],y=[128,256],w=["hex","buffer","arrayBuffer","array","digest"],m={128:168,256:136};!c.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!l||!c.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer});for(var v=function(e,t,n){return function(r){return new N(e,t,e).update(r)[n]()}},E=function(e,t,n){return function(r,i){return new N(e,t,i).update(r)[n]()}},x=function(e,t,n){return function(t,r,i,s){return O["cshake"+e].update(t,r,i,s)[n]()}},A=function(e,t,n){return function(t,r,i,s){return O["kmac"+e].update(t,r,i,s)[n]()}},_=function(e,t,n,r){for(var i=0;i>5,this.byteCount=this.blockCount<<2,this.outputBlocks=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0}function D(e,t,n){N.call(this,e,t,n)}N.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var t,n=typeof e;if("string"!==n){if("object"!==n)throw new Error(o);if(null===e)throw new Error(o);if(l&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||l&&ArrayBuffer.isView(e)))throw new Error(o);t=!0}for(var r,i,s=this.blocks,a=this.byteCount,c=e.length,u=this.blockCount,f=0,h=this.s;f>2]|=e[f]<>2]|=i<>2]|=(192|i>>6)<>2]|=(128|63&i)<=57344?(s[r>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<=a){for(this.start=r-a,this.block=s[u],r=0;r>=8);n>0;)i.unshift(n),n=255&(e>>=8),++r;return t?i.push(r):i.unshift(r),this.update(i),i.length},N.prototype.encodeString=function(e){var t,n=typeof e;if("string"!==n){if("object"!==n)throw new Error(o);if(null===e)throw new Error(o);if(l&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||l&&ArrayBuffer.isView(e)))throw new Error(o);t=!0}var r=0,i=e.length;if(t)r=i;else for(var s=0;s=57344?r+=3:(a=65536+((1023&a)<<10|1023&e.charCodeAt(++s)),r+=4)}return r+=this.encode(8*r),this.update(e),r},N.prototype.bytepad=function(e,t){for(var n=this.encode(t),r=0;r>2]|=this.padding[3&t],this.lastByteIndex===this.byteCount)for(e[0]=e[n],t=1;t>4&15]+d[15&e]+d[e>>12&15]+d[e>>8&15]+d[e>>20&15]+d[e>>16&15]+d[e>>28&15]+d[e>>24&15];o%t==0&&(M(n),s=0)}return i&&(e=n[s],a+=d[e>>4&15]+d[15&e],i>1&&(a+=d[e>>12&15]+d[e>>8&15]),i>2&&(a+=d[e>>20&15]+d[e>>16&15])),a},N.prototype.arrayBuffer=function(){this.finalize();var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,s=0,o=0,a=this.outputBits>>3;e=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(a);for(var c=new Uint32Array(e);o>8&255,c[e+2]=t>>16&255,c[e+3]=t>>24&255;a%n==0&&M(r)}return s&&(e=a<<2,t=r[o],c[e]=255&t,s>1&&(c[e+1]=t>>8&255),s>2&&(c[e+2]=t>>16&255)),c},D.prototype=new N,D.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var M=function(e){var t,n,r,i,s,o,a,c,u,f,h,l,d,p,b,g,y,w,m,v,E,x,A,_,S,U,O,I,B,C,T,L,P,j,N,D,M,R,z,H,F,Y,q,G,J,V,$,W,K,Z,X,Q,ee,te,ne,re,ie,se,oe,ae,ce,ue,fe;for(r=0;r<48;r+=2)i=e[0]^e[10]^e[20]^e[30]^e[40],s=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],a=e[3]^e[13]^e[23]^e[33]^e[43],c=e[4]^e[14]^e[24]^e[34]^e[44],u=e[5]^e[15]^e[25]^e[35]^e[45],f=e[6]^e[16]^e[26]^e[36]^e[46],h=e[7]^e[17]^e[27]^e[37]^e[47],t=(l=e[8]^e[18]^e[28]^e[38]^e[48])^(o<<1|a>>>31),n=(d=e[9]^e[19]^e[29]^e[39]^e[49])^(a<<1|o>>>31),e[0]^=t,e[1]^=n,e[10]^=t,e[11]^=n,e[20]^=t,e[21]^=n,e[30]^=t,e[31]^=n,e[40]^=t,e[41]^=n,t=i^(c<<1|u>>>31),n=s^(u<<1|c>>>31),e[2]^=t,e[3]^=n,e[12]^=t,e[13]^=n,e[22]^=t,e[23]^=n,e[32]^=t,e[33]^=n,e[42]^=t,e[43]^=n,t=o^(f<<1|h>>>31),n=a^(h<<1|f>>>31),e[4]^=t,e[5]^=n,e[14]^=t,e[15]^=n,e[24]^=t,e[25]^=n,e[34]^=t,e[35]^=n,e[44]^=t,e[45]^=n,t=c^(l<<1|d>>>31),n=u^(d<<1|l>>>31),e[6]^=t,e[7]^=n,e[16]^=t,e[17]^=n,e[26]^=t,e[27]^=n,e[36]^=t,e[37]^=n,e[46]^=t,e[47]^=n,t=f^(i<<1|s>>>31),n=h^(s<<1|i>>>31),e[8]^=t,e[9]^=n,e[18]^=t,e[19]^=n,e[28]^=t,e[29]^=n,e[38]^=t,e[39]^=n,e[48]^=t,e[49]^=n,p=e[0],b=e[1],V=e[11]<<4|e[10]>>>28,$=e[10]<<4|e[11]>>>28,I=e[20]<<3|e[21]>>>29,B=e[21]<<3|e[20]>>>29,ae=e[31]<<9|e[30]>>>23,ce=e[30]<<9|e[31]>>>23,Y=e[40]<<18|e[41]>>>14,q=e[41]<<18|e[40]>>>14,j=e[2]<<1|e[3]>>>31,N=e[3]<<1|e[2]>>>31,g=e[13]<<12|e[12]>>>20,y=e[12]<<12|e[13]>>>20,W=e[22]<<10|e[23]>>>22,K=e[23]<<10|e[22]>>>22,C=e[33]<<13|e[32]>>>19,T=e[32]<<13|e[33]>>>19,ue=e[42]<<2|e[43]>>>30,fe=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,D=e[14]<<6|e[15]>>>26,M=e[15]<<6|e[14]>>>26,w=e[25]<<11|e[24]>>>21,m=e[24]<<11|e[25]>>>21,Z=e[34]<<15|e[35]>>>17,X=e[35]<<15|e[34]>>>17,L=e[45]<<29|e[44]>>>3,P=e[44]<<29|e[45]>>>3,_=e[6]<<28|e[7]>>>4,S=e[7]<<28|e[6]>>>4,re=e[17]<<23|e[16]>>>9,ie=e[16]<<23|e[17]>>>9,R=e[26]<<25|e[27]>>>7,z=e[27]<<25|e[26]>>>7,v=e[36]<<21|e[37]>>>11,E=e[37]<<21|e[36]>>>11,Q=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,G=e[8]<<27|e[9]>>>5,J=e[9]<<27|e[8]>>>5,U=e[18]<<20|e[19]>>>12,O=e[19]<<20|e[18]>>>12,se=e[29]<<7|e[28]>>>25,oe=e[28]<<7|e[29]>>>25,H=e[38]<<8|e[39]>>>24,F=e[39]<<8|e[38]>>>24,x=e[48]<<14|e[49]>>>18,A=e[49]<<14|e[48]>>>18,e[0]=p^~g&w,e[1]=b^~y&m,e[10]=_^~U&I,e[11]=S^~O&B,e[20]=j^~D&R,e[21]=N^~M&z,e[30]=G^~V&W,e[31]=J^~$&K,e[40]=te^~re&se,e[41]=ne^~ie&oe,e[2]=g^~w&v,e[3]=y^~m&E,e[12]=U^~I&C,e[13]=O^~B&T,e[22]=D^~R&H,e[23]=M^~z&F,e[32]=V^~W&Z,e[33]=$^~K&X,e[42]=re^~se&ae,e[43]=ie^~oe&ce,e[4]=w^~v&x,e[5]=m^~E&A,e[14]=I^~C&L,e[15]=B^~T&P,e[24]=R^~H&Y,e[25]=z^~F&q,e[34]=W^~Z&Q,e[35]=K^~X&ee,e[44]=se^~ae&ue,e[45]=oe^~ce&fe,e[6]=v^~x&p,e[7]=E^~A&b,e[16]=C^~L&_,e[17]=T^~P&S,e[26]=H^~Y&j,e[27]=F^~q&N,e[36]=Z^~Q&G,e[37]=X^~ee&J,e[46]=ae^~ue&te,e[47]=ce^~fe&ne,e[8]=x^~p&g,e[9]=A^~b&y,e[18]=L^~_&U,e[19]=P^~S&O,e[28]=Y^~j&D,e[29]=q^~N&M,e[38]=Q^~G&V,e[39]=ee^~J&$,e[48]=ue^~te&re,e[49]=fe^~ne&ie,e[0]^=k[r],e[1]^=k[r+1]};if(f)e.exports=O;else{for(B=0;B1)for(var n=1;n255)return!1;return!0}function o(e,t){return(65535&e)*t+(((e>>>16)*t&65535)<<16)}function a(e,t){return e<>>32-t}function c(e){return e=o(e^=e>>>16,2246822507),e=o(e^=e>>>13,3266489909),e^=e>>>16}function u(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,65535&e[1]],t=[t[0]>>>16,65535&t[0],t[1]>>>16,65535&t[1]];var n=[0,0,0,0];return n[3]+=e[3]+t[3],n[2]+=n[3]>>>16,n[3]&=65535,n[2]+=e[2]+t[2],n[1]+=n[2]>>>16,n[2]&=65535,n[1]+=e[1]+t[1],n[0]+=n[1]>>>16,n[1]&=65535,n[0]+=e[0]+t[0],n[0]&=65535,[n[0]<<16|n[1],n[2]<<16|n[3]]}function f(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,65535&e[1]],t=[t[0]>>>16,65535&t[0],t[1]>>>16,65535&t[1]];var n=[0,0,0,0];return n[3]+=e[3]*t[3],n[2]+=n[3]>>>16,n[3]&=65535,n[2]+=e[2]*t[3],n[1]+=n[2]>>>16,n[2]&=65535,n[2]+=e[3]*t[2],n[1]+=n[2]>>>16,n[2]&=65535,n[1]+=e[1]*t[3],n[0]+=n[1]>>>16,n[1]&=65535,n[1]+=e[2]*t[2],n[0]+=n[1]>>>16,n[1]&=65535,n[1]+=e[3]*t[1],n[0]+=n[1]>>>16,n[1]&=65535,n[0]+=e[0]*t[3]+e[1]*t[2]+e[2]*t[1]+e[3]*t[0],n[0]&=65535,[n[0]<<16|n[1],n[2]<<16|n[3]]}function h(e,t){return 32===(t%=64)?[e[1],e[0]]:t<32?[e[0]<>>32-t,e[1]<>>32-t]:(t-=32,[e[1]<>>32-t,e[0]<>>32-t])}function l(e,t){return 0===(t%=64)?e:t<32?[e[0]<>>32-t,e[1]<>>1]),e=d(e=f(e,[4283543511,3981806797]),[0,e[0]>>>1]),e=d(e=f(e,[3301882366,444984403]),[0,e[0]>>>1])}i.x86.hash32=function(e,t){if(!i.inputValidation||s(e)){t=t||0;for(var n=e.length%4,r=e.length-n,u=t,f=0,h=3432918353,l=461845907,d=0;d>>0}},i.x86.hash128=function(e,t){if(!i.inputValidation||s(e)){t=t||0;for(var n=e.length%16,r=e.length-n,u=t,f=t,h=t,l=t,d=0,p=0,b=0,k=0,g=597399067,y=2869860233,w=951274213,m=2716044179,v=0;v>>0).toString(16)).slice(-8)+("00000000"+(f>>>0).toString(16)).slice(-8)+("00000000"+(h>>>0).toString(16)).slice(-8)+("00000000"+(l>>>0).toString(16)).slice(-8)}},i.x64.hash128=function(e,t){if(!i.inputValidation||s(e)){t=t||0;for(var n=e.length%16,r=e.length-n,o=[0,t],a=[0,t],c=[0,0],b=[0,0],k=[2277735313,289559509],g=[1291169091,658871167],y=0;y>>0).toString(16)).slice(-8)+("00000000"+(o[1]>>>0).toString(16)).slice(-8)+("00000000"+(a[0]>>>0).toString(16)).slice(-8)+("00000000"+(a[1]>>>0).toString(16)).slice(-8)}},e.exports&&(t=e.exports=i),t.murmurHash3=i}()},function(e,t,n){"use strict";const r=n(9),i=self.crypto||self.msCrypto,s=async(e,t)=>{if("undefined"==typeof self||!self.crypto&&!self.msCrypto)throw new Error("Please use a browser with webcrypto support and ensure the code has been delivered securely via HTTPS/TLS and run within a Secure Context");switch(t){case"sha1":return new Uint8Array(await i.subtle.digest({name:"SHA-1"},e));case"sha2-256":return new Uint8Array(await i.subtle.digest({name:"SHA-256"},e));case"sha2-512":return new Uint8Array(await i.subtle.digest({name:"SHA-512"},e));case"dbl-sha2-256":{const t=await i.subtle.digest({name:"SHA-256"},e);return new Uint8Array(await i.subtle.digest({name:"SHA-256"},t))}default:throw new Error(t+" is not a supported algorithm")}};e.exports={factory:e=>async t=>s(t,e),digest:s,multihashing:async(e,t,n)=>{const i=await s(e,t);return r.encode(i,t,n)}}},function(e,t,n){"use strict";e.exports={fromNumberTo32BitBuf:e=>{const t=new Uint8Array(4);for(let n=0;n<4;n++)t[n]=255&e,e>>=8;return t}}},function(e,t,n){"use strict";const r=n(107),i={init:r.blake2bInit,update:r.blake2bUpdate,digest:r.blake2bFinal},s={init:r.blake2sInit,update:r.blake2sUpdate,digest:r.blake2sFinal},o=(e,t)=>async n=>{const r=t.init(e,null);return t.update(r,n),t.digest(r)};e.exports=e=>{for(let t=0;t<64;t++)e[45569+t]=o(t+1,i);for(let t=0;t<32;t++)e[45633+t]=o(t+1,s)}},function(e,t,n){var r=n(108),i=n(109);e.exports={blake2b:r.blake2b,blake2bHex:r.blake2bHex,blake2bInit:r.blake2bInit,blake2bUpdate:r.blake2bUpdate,blake2bFinal:r.blake2bFinal,blake2s:i.blake2s,blake2sHex:i.blake2sHex,blake2sInit:i.blake2sInit,blake2sUpdate:i.blake2sUpdate,blake2sFinal:i.blake2sFinal}},function(e,t,n){var r=n(32);function i(e,t,n){var r=e[t]+e[n],i=e[t+1]+e[n+1];r>=4294967296&&i++,e[t]=r,e[t+1]=i}function s(e,t,n,r){var i=e[t]+n;n<0&&(i+=4294967296);var s=e[t+1]+r;i>=4294967296&&s++,e[t]=i,e[t+1]=s}function o(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function a(e,t,n,r,o,a){var c=h[o],u=h[o+1],l=h[a],d=h[a+1];i(f,e,t),s(f,e,c,u);var p=f[r]^f[e],b=f[r+1]^f[e+1];f[r]=b,f[r+1]=p,i(f,n,r),p=f[t]^f[n],b=f[t+1]^f[n+1],f[t]=p>>>24^b<<8,f[t+1]=b>>>24^p<<8,i(f,e,t),s(f,e,l,d),p=f[r]^f[e],b=f[r+1]^f[e+1],f[r]=p>>>16^b<<16,f[r+1]=b>>>16^p<<16,i(f,n,r),p=f[t]^f[n],b=f[t+1]^f[n+1],f[t]=b>>>31^p<<1,f[t+1]=p>>>31^b<<1}var c=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),u=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map((function(e){return 2*e}))),f=new Uint32Array(32),h=new Uint32Array(32);function l(e,t){var n=0;for(n=0;n<16;n++)f[n]=e.h[n],f[n+16]=c[n];for(f[24]=f[24]^e.t,f[25]=f[25]^e.t/4294967296,t&&(f[28]=~f[28],f[29]=~f[29]),n=0;n<32;n++)h[n]=o(e.b,4*n);for(n=0;n<12;n++)a(0,8,16,24,u[16*n+0],u[16*n+1]),a(2,10,18,26,u[16*n+2],u[16*n+3]),a(4,12,20,28,u[16*n+4],u[16*n+5]),a(6,14,22,30,u[16*n+6],u[16*n+7]),a(0,10,20,30,u[16*n+8],u[16*n+9]),a(2,12,22,24,u[16*n+10],u[16*n+11]),a(4,14,16,26,u[16*n+12],u[16*n+13]),a(6,8,18,28,u[16*n+14],u[16*n+15]);for(n=0;n<16;n++)e.h[n]=e.h[n]^f[n]^f[n+16]}function d(e,t){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(t&&t.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");for(var n={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:e},r=0;r<16;r++)n.h[r]=c[r];var i=t?t.length:0;return n.h[0]^=16842752^i<<8^e,t&&(p(n,t),n.c=128),n}function p(e,t){for(var n=0;n>2]>>8*(3&n);return t}function k(e,t,n){n=n||64,e=r.normalizeInput(e);var i=d(n,t);return p(i,e),b(i)}e.exports={blake2b:k,blake2bHex:function(e,t,n){var i=k(e,t,n);return r.toHex(i)},blake2bInit:d,blake2bUpdate:p,blake2bFinal:b}},function(e,t,n){var r=n(32);function i(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function s(e,t,n,r,i,s){u[e]=u[e]+u[t]+i,u[r]=o(u[r]^u[e],16),u[n]=u[n]+u[r],u[t]=o(u[t]^u[n],12),u[e]=u[e]+u[t]+s,u[r]=o(u[r]^u[e],8),u[n]=u[n]+u[r],u[t]=o(u[t]^u[n],7)}function o(e,t){return e>>>t^e<<32-t}var a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),c=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),u=new Uint32Array(16),f=new Uint32Array(16);function h(e,t){var n=0;for(n=0;n<8;n++)u[n]=e.h[n],u[n+8]=a[n];for(u[12]^=e.t,u[13]^=e.t/4294967296,t&&(u[14]=~u[14]),n=0;n<16;n++)f[n]=i(e.b,4*n);for(n=0;n<10;n++)s(0,4,8,12,f[c[16*n+0]],f[c[16*n+1]]),s(1,5,9,13,f[c[16*n+2]],f[c[16*n+3]]),s(2,6,10,14,f[c[16*n+4]],f[c[16*n+5]]),s(3,7,11,15,f[c[16*n+6]],f[c[16*n+7]]),s(0,5,10,15,f[c[16*n+8]],f[c[16*n+9]]),s(1,6,11,12,f[c[16*n+10]],f[c[16*n+11]]),s(2,7,8,13,f[c[16*n+12]],f[c[16*n+13]]),s(3,4,9,14,f[c[16*n+14]],f[c[16*n+15]]);for(n=0;n<8;n++)e.h[n]^=u[n]^u[n+8]}function l(e,t){if(!(e>0&&e<=32))throw new Error("Incorrect output length, should be in [1, 32]");var n=t?t.length:0;if(t&&!(n>0&&n<=32))throw new Error("Incorrect key length, should be in [1, 32]");var r={h:new Uint32Array(a),b:new Uint32Array(64),c:0,t:0,outlen:e};return r.h[0]^=16842752^n<<8^e,n>0&&(d(r,t),r.c=64),r}function d(e,t){for(var n=0;n>2]>>8*(3&n)&255;return t}function b(e,t,n){n=n||32,e=r.normalizeInput(e);var i=l(n,t);return d(i,e),p(i)}e.exports={blake2s:b,blake2sHex:function(e,t,n){var i=b(e,t,n);return r.toHex(i)},blake2sInit:l,blake2sUpdate:d,blake2sFinal:p}},function(e,t,n){"use strict";const r=n(27),i=n(33);e.exports=(e,t)=>{const n=(e=>{if(i.isDAGLink(e))return e;if(!("cid"in e||"hash"in e||"Hash"in e||"multihash"in e))throw new Error("Link must be a DAGLink or DAGLink-like. Convert the DAGNode into a DAGLink via `node.toDAGLink()`.");return new i(e.Name||e.name,e.Tsize||e.size,e.Hash||e.multihash||e.hash||e.cid)})(t);e.Links.push(n),r(e.Links)}},function(e,t,n){"use strict";const r=n(4);e.exports.createDagLinkFromB58EncodedHash=function(e){return new r(e.Name||e.name||"",e.Tsize||e.Size||e.size||0,e.Hash||e.hash||e.multihash||e.cid)}},function(e,t,n){"use strict";const r=n(5),i=n(18);e.exports=(e,t)=>{let n=null;if("string"==typeof t?n=e=>e.Name===t:(t instanceof Uint8Array||r.isCID(t))&&(n=e=>i(e.Hash,t)),!n)throw new Error("second arg needs to be a name or CID");{const t=e.Links;let r=0;for(;r{let n=i.deserialize(e);const s=t.split("/").filter(Boolean);for(;s.length;){const e=s.shift();if(void 0===n[e]){for(const t of n.Links)if(t.Name===e)return{value:t.Hash,remainderPath:s.join("/")};throw new Error(`Object has no property '${e}'`)}if(n=n[e],r.isCID(n))return{value:n,remainderPath:s.join("/")}}return{value:n,remainderPath:""}},t.tree=function*(e){const t=i.deserialize(e);yield"Data",yield"Links";for(let e=0;et,stringify:JSON.stringify}},function(e,t,n){"use strict";const r=n(10),i=n(117),s=n(35),{LastWriteWins:o,NoZeroes:a}=s,c=n(36),{isDefined:u,findUniques:f,difference:h,io:l}=n(12),d=["heads"],p=(e,t)=>e.slice(e.length-Math.min(e.length,t),e.length);e.exports=class{static async toMultihash(e,t,{format:n}={}){if(!u(e))throw c.IPFSNotDefinedError();if(!u(t))throw c.LogNotDefinedError();if(u(n)||(n="dag-cbor"),t.values.length<1)throw new Error("Can't serialize an empty log");return l.write(e,n,t.toJSON(),{links:d})}static async fromMultihash(e,t,{length:n=-1,exclude:r=[],timeout:s,concurrency:f,sortFn:h,onProgressCallback:b}){if(!u(e))throw c.IPFSNotDefinedError();if(!u(t))throw new Error("Invalid hash: "+t);const k=await l.read(e,t,{links:d});if(!k.heads||!k.id)throw c.NotALogError();h=h||a(o);const g=await i.fetchAll(e,k.heads,{length:n,exclude:r,timeout:s,concurrency:f,onProgressCallback:b}),y=k.id,w=n>-1?p(g.sort(h),n):g,m=w.filter(e=>k.heads.includes(e.hash));return{logId:y,entries:w,heads:m}}static async fromEntryHash(e,t,{length:n=-1,exclude:r=[],timeout:s,concurrency:f,sortFn:h,onProgressCallback:l}){if(!u(e))throw c.IpfsNotDefinedError();if(!u(t))throw new Error("'hash' must be defined");const d=Array.isArray(t)?t:[t];n=n>-1?Math.max(n,1):n;const b=await i.fetchParallel(e,d,{length:n,exclude:r,timeout:s,concurrency:f,onProgressCallback:l});h=h||a(o);return{entries:n>-1?p(b.sort(h),n):b}}static async fromJSON(e,t,{length:n=-1,timeout:s,concurrency:o,onProgressCallback:a}){if(!u(e))throw c.IPFSNotDefinedError();const{id:f,heads:h}=t,l=h.map(e=>e.hash);return{logId:f,entries:(await i.fetchParallel(e,l,{length:n,timeout:s,concurrency:o,onProgressCallback:a})).sort(r.compare),heads:h}}static async fromEntry(e,t,{length:n=-1,exclude:s=[],timeout:o,concurrency:a,onProgressCallback:l}){if(!u(e))throw c.IPFSNotDefinedError();if(!u(t))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(t)&&!r.isEntry(t))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(t)||(t=[t]),n=n>-1?Math.max(n,t.length):n;const d=t.map(e=>e.hash),p=await i.fetchParallel(e,d,{length:n,exclude:s,timeout:o,concurrency:a,onProgressCallback:l}),b=t.concat(p).concat(s),k=f(b,"hash").sort(r.compare),g=k.slice(n>-1?-n:-k.length),y=((e,t)=>{var n=e.slice(t.length,e.length);return t.concat(n)})(g,h(g,t,"hash"));return{logId:y[y.length-1].id,entries:y}}}},function(e,t,n){"use strict";const r=n(21),i=n(118),s=n(10),o=e=>e&&e.length>0;class a{static async fetchParallel(e,t,{length:n,exclude:i=[],timeout:s,concurrency:o,onProgressCallback:c}){const u=(e,t)=>e.concat(t),f=await r(t,async t=>a.fetchAll(e,t,{length:n,exclude:i,timeout:s,onProgressCallback:c,concurrency:o}),{concurrency:Math.max(o||t.length,1)});return f.reduce(u,[])}static async fetchAll(e,t,{length:n=-1,exclude:a=[],timeout:c,onProgressCallback:u,onStartProgressCallback:f,concurrency:h=32,delay:l=0}={}){const d=[],p={},b={},k=Array.isArray(t)?{0:t.slice()}:{0:[t]};let g=0,y=0,w=0;const m=(e,t)=>{b[e]||(k[t]||(k[t]=[]),k[t].includes(e)||k[t].push(e),b[e]=!0)},v=async t=>{if(t&&!p[t])return new Promise((r,i)=>{const o=c&&c>0?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${t}', request timed out (${c}ms)`),r()},c):null;f&&f(t,null,0,d.length),s.fromMultihash(e,t).then(async e=>{try{if((e=>{if(s.isEntry(e)){const r=e.clock.time;y=Math.max(y,r),w=d.length>0?Math.min(d[d.length-1].clock.time,w):y;const i=d.length>=n&&r>=w,s=e=>y-r+(e+1)*e;(n<0||d.lengthw||r===w&&!p[e.hash])&&e.next.forEach(e=>m(e,s(0))),e.refs&&d.length+e.refs.length<=n&&e.refs.forEach((e,t)=>m(e,s(t))))}})(e),l>0){const e=(e=0)=>new Promise(t=>setTimeout(t,e));await e(l)}r()}catch(e){i(e)}finally{clearTimeout(o)}}).catch(i)})};return a.forEach(e=>{p[e.hash]=!0}),await i(async()=>{if(gObject.keys(k).reduce((t,n,r)=>{const i=k[n];for(;i.length>0&&t.lengthvoid 0!==Object.values(k).find(o)),d}}e.exports=a},function(e,t,n){"use strict";const r=async(e,t)=>{if(t(await e()))return r(e,t)};e.exports=r,e.exports.default=r},function(e,t,n){"use strict";e.exports=class{async canAppend(e,t){return!0}}},function(e,t,n){"use strict";e.exports=class{constructor(e={}){this._cache=e}set(e,t){this._cache[e]=t}get(e){return this._cache[e]}delete(e){return delete this._cache[e]}add(e){this._cache=Object.assign(this._cache,e)}get length(){return Object.values(this._cache).length}}}]); + */!function(){"use strict";var o="input is invalid type",a="object"==typeof window,c=a?window:{};c.JS_SHA3_NO_WINDOW&&(a=!1);var u=!a&&"object"==typeof self;!c.JS_SHA3_NO_NODE_JS&&"object"==typeof r&&r.versions&&r.versions.node?c=i:u&&(c=self);var h=!c.JS_SHA3_NO_COMMON_JS&&"object"==typeof e&&e.exports,f=n(101),l=!c.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,d="0123456789abcdef".split(""),p=[4,1024,262144,67108864],b=[0,8,16,24],g=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],k=[224,256,384,512],y=[128,256],w=["hex","buffer","arrayBuffer","array","digest"],m={128:168,256:136};!c.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!l||!c.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(e){return"object"==typeof e&&e.buffer&&e.buffer.constructor===ArrayBuffer});for(var v=function(e,t,n){return function(r){return new j(e,t,e).update(r)[n]()}},x=function(e,t,n){return function(r,i){return new j(e,t,i).update(r)[n]()}},E=function(e,t,n){return function(t,r,i,s){return I["cshake"+e].update(t,r,i,s)[n]()}},A=function(e,t,n){return function(t,r,i,s){return I["kmac"+e].update(t,r,i,s)[n]()}},_=function(e,t,n,r){for(var i=0;i>5,this.byteCount=this.blockCount<<2,this.outputBlocks=n>>5,this.extraBytes=(31&n)>>3;for(var r=0;r<50;++r)this.s[r]=0}function D(e,t,n){j.call(this,e,t,n)}j.prototype.update=function(e){if(this.finalized)throw new Error("finalize already called");var t,n=typeof e;if("string"!==n){if("object"!==n)throw new Error(o);if(null===e)throw new Error(o);if(l&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||l&&ArrayBuffer.isView(e)))throw new Error(o);t=!0}for(var r,i,s=this.blocks,a=this.byteCount,c=e.length,u=this.blockCount,h=0,f=this.s;h>2]|=e[h]<>2]|=i<>2]|=(192|i>>6)<>2]|=(128|63&i)<=57344?(s[r>>2]|=(224|i>>12)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<>2]|=(240|i>>18)<>2]|=(128|i>>12&63)<>2]|=(128|i>>6&63)<>2]|=(128|63&i)<=a){for(this.start=r-a,this.block=s[u],r=0;r>=8);n>0;)i.unshift(n),n=255&(e>>=8),++r;return t?i.push(r):i.unshift(r),this.update(i),i.length},j.prototype.encodeString=function(e){var t,n=typeof e;if("string"!==n){if("object"!==n)throw new Error(o);if(null===e)throw new Error(o);if(l&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||l&&ArrayBuffer.isView(e)))throw new Error(o);t=!0}var r=0,i=e.length;if(t)r=i;else for(var s=0;s=57344?r+=3:(a=65536+((1023&a)<<10|1023&e.charCodeAt(++s)),r+=4)}return r+=this.encode(8*r),this.update(e),r},j.prototype.bytepad=function(e,t){for(var n=this.encode(t),r=0;r>2]|=this.padding[3&t],this.lastByteIndex===this.byteCount)for(e[0]=e[n],t=1;t>4&15]+d[15&e]+d[e>>12&15]+d[e>>8&15]+d[e>>20&15]+d[e>>16&15]+d[e>>28&15]+d[e>>24&15];o%t==0&&(M(n),s=0)}return i&&(e=n[s],a+=d[e>>4&15]+d[15&e],i>1&&(a+=d[e>>12&15]+d[e>>8&15]),i>2&&(a+=d[e>>20&15]+d[e>>16&15])),a},j.prototype.arrayBuffer=function(){this.finalize();var e,t=this.blockCount,n=this.s,r=this.outputBlocks,i=this.extraBytes,s=0,o=0,a=this.outputBits>>3;e=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(a);for(var c=new Uint32Array(e);o>8&255,c[e+2]=t>>16&255,c[e+3]=t>>24&255;a%n==0&&M(r)}return s&&(e=a<<2,t=r[o],c[e]=255&t,s>1&&(c[e+1]=t>>8&255),s>2&&(c[e+2]=t>>16&255)),c},D.prototype=new j,D.prototype.finalize=function(){return this.encode(this.outputBits,!0),j.prototype.finalize.call(this)};var M=function(e){var t,n,r,i,s,o,a,c,u,h,f,l,d,p,b,k,y,w,m,v,x,E,A,_,S,U,I,O,B,T,C,L,P,N,j,D,M,R,z,H,F,Y,q,G,J,V,$,W,K,Z,X,Q,ee,te,ne,re,ie,se,oe,ae,ce,ue,he;for(r=0;r<48;r+=2)i=e[0]^e[10]^e[20]^e[30]^e[40],s=e[1]^e[11]^e[21]^e[31]^e[41],o=e[2]^e[12]^e[22]^e[32]^e[42],a=e[3]^e[13]^e[23]^e[33]^e[43],c=e[4]^e[14]^e[24]^e[34]^e[44],u=e[5]^e[15]^e[25]^e[35]^e[45],h=e[6]^e[16]^e[26]^e[36]^e[46],f=e[7]^e[17]^e[27]^e[37]^e[47],t=(l=e[8]^e[18]^e[28]^e[38]^e[48])^(o<<1|a>>>31),n=(d=e[9]^e[19]^e[29]^e[39]^e[49])^(a<<1|o>>>31),e[0]^=t,e[1]^=n,e[10]^=t,e[11]^=n,e[20]^=t,e[21]^=n,e[30]^=t,e[31]^=n,e[40]^=t,e[41]^=n,t=i^(c<<1|u>>>31),n=s^(u<<1|c>>>31),e[2]^=t,e[3]^=n,e[12]^=t,e[13]^=n,e[22]^=t,e[23]^=n,e[32]^=t,e[33]^=n,e[42]^=t,e[43]^=n,t=o^(h<<1|f>>>31),n=a^(f<<1|h>>>31),e[4]^=t,e[5]^=n,e[14]^=t,e[15]^=n,e[24]^=t,e[25]^=n,e[34]^=t,e[35]^=n,e[44]^=t,e[45]^=n,t=c^(l<<1|d>>>31),n=u^(d<<1|l>>>31),e[6]^=t,e[7]^=n,e[16]^=t,e[17]^=n,e[26]^=t,e[27]^=n,e[36]^=t,e[37]^=n,e[46]^=t,e[47]^=n,t=h^(i<<1|s>>>31),n=f^(s<<1|i>>>31),e[8]^=t,e[9]^=n,e[18]^=t,e[19]^=n,e[28]^=t,e[29]^=n,e[38]^=t,e[39]^=n,e[48]^=t,e[49]^=n,p=e[0],b=e[1],V=e[11]<<4|e[10]>>>28,$=e[10]<<4|e[11]>>>28,O=e[20]<<3|e[21]>>>29,B=e[21]<<3|e[20]>>>29,ae=e[31]<<9|e[30]>>>23,ce=e[30]<<9|e[31]>>>23,Y=e[40]<<18|e[41]>>>14,q=e[41]<<18|e[40]>>>14,N=e[2]<<1|e[3]>>>31,j=e[3]<<1|e[2]>>>31,k=e[13]<<12|e[12]>>>20,y=e[12]<<12|e[13]>>>20,W=e[22]<<10|e[23]>>>22,K=e[23]<<10|e[22]>>>22,T=e[33]<<13|e[32]>>>19,C=e[32]<<13|e[33]>>>19,ue=e[42]<<2|e[43]>>>30,he=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,D=e[14]<<6|e[15]>>>26,M=e[15]<<6|e[14]>>>26,w=e[25]<<11|e[24]>>>21,m=e[24]<<11|e[25]>>>21,Z=e[34]<<15|e[35]>>>17,X=e[35]<<15|e[34]>>>17,L=e[45]<<29|e[44]>>>3,P=e[44]<<29|e[45]>>>3,_=e[6]<<28|e[7]>>>4,S=e[7]<<28|e[6]>>>4,re=e[17]<<23|e[16]>>>9,ie=e[16]<<23|e[17]>>>9,R=e[26]<<25|e[27]>>>7,z=e[27]<<25|e[26]>>>7,v=e[36]<<21|e[37]>>>11,x=e[37]<<21|e[36]>>>11,Q=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,G=e[8]<<27|e[9]>>>5,J=e[9]<<27|e[8]>>>5,U=e[18]<<20|e[19]>>>12,I=e[19]<<20|e[18]>>>12,se=e[29]<<7|e[28]>>>25,oe=e[28]<<7|e[29]>>>25,H=e[38]<<8|e[39]>>>24,F=e[39]<<8|e[38]>>>24,E=e[48]<<14|e[49]>>>18,A=e[49]<<14|e[48]>>>18,e[0]=p^~k&w,e[1]=b^~y&m,e[10]=_^~U&O,e[11]=S^~I&B,e[20]=N^~D&R,e[21]=j^~M&z,e[30]=G^~V&W,e[31]=J^~$&K,e[40]=te^~re&se,e[41]=ne^~ie&oe,e[2]=k^~w&v,e[3]=y^~m&x,e[12]=U^~O&T,e[13]=I^~B&C,e[22]=D^~R&H,e[23]=M^~z&F,e[32]=V^~W&Z,e[33]=$^~K&X,e[42]=re^~se&ae,e[43]=ie^~oe&ce,e[4]=w^~v&E,e[5]=m^~x&A,e[14]=O^~T&L,e[15]=B^~C&P,e[24]=R^~H&Y,e[25]=z^~F&q,e[34]=W^~Z&Q,e[35]=K^~X&ee,e[44]=se^~ae&ue,e[45]=oe^~ce&he,e[6]=v^~E&p,e[7]=x^~A&b,e[16]=T^~L&_,e[17]=C^~P&S,e[26]=H^~Y&N,e[27]=F^~q&j,e[36]=Z^~Q&G,e[37]=X^~ee&J,e[46]=ae^~ue&te,e[47]=ce^~he&ne,e[8]=E^~p&k,e[9]=A^~b&y,e[18]=L^~_&U,e[19]=P^~S&I,e[28]=Y^~N&D,e[29]=q^~j&M,e[38]=Q^~G&V,e[39]=ee^~J&$,e[48]=ue^~te&re,e[49]=he^~ne&ie,e[0]^=g[r],e[1]^=g[r+1]};if(h)e.exports=I;else{for(B=0;B1)for(var n=1;n255)return!1;return!0}function o(e,t){return(65535&e)*t+(((e>>>16)*t&65535)<<16)}function a(e,t){return e<>>32-t}function c(e){return e=o(e^=e>>>16,2246822507),e=o(e^=e>>>13,3266489909),e^=e>>>16}function u(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,65535&e[1]],t=[t[0]>>>16,65535&t[0],t[1]>>>16,65535&t[1]];var n=[0,0,0,0];return n[3]+=e[3]+t[3],n[2]+=n[3]>>>16,n[3]&=65535,n[2]+=e[2]+t[2],n[1]+=n[2]>>>16,n[2]&=65535,n[1]+=e[1]+t[1],n[0]+=n[1]>>>16,n[1]&=65535,n[0]+=e[0]+t[0],n[0]&=65535,[n[0]<<16|n[1],n[2]<<16|n[3]]}function h(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,65535&e[1]],t=[t[0]>>>16,65535&t[0],t[1]>>>16,65535&t[1]];var n=[0,0,0,0];return n[3]+=e[3]*t[3],n[2]+=n[3]>>>16,n[3]&=65535,n[2]+=e[2]*t[3],n[1]+=n[2]>>>16,n[2]&=65535,n[2]+=e[3]*t[2],n[1]+=n[2]>>>16,n[2]&=65535,n[1]+=e[1]*t[3],n[0]+=n[1]>>>16,n[1]&=65535,n[1]+=e[2]*t[2],n[0]+=n[1]>>>16,n[1]&=65535,n[1]+=e[3]*t[1],n[0]+=n[1]>>>16,n[1]&=65535,n[0]+=e[0]*t[3]+e[1]*t[2]+e[2]*t[1]+e[3]*t[0],n[0]&=65535,[n[0]<<16|n[1],n[2]<<16|n[3]]}function f(e,t){return 32===(t%=64)?[e[1],e[0]]:t<32?[e[0]<>>32-t,e[1]<>>32-t]:(t-=32,[e[1]<>>32-t,e[0]<>>32-t])}function l(e,t){return 0===(t%=64)?e:t<32?[e[0]<>>32-t,e[1]<>>1]),e=d(e=h(e,[4283543511,3981806797]),[0,e[0]>>>1]),e=d(e=h(e,[3301882366,444984403]),[0,e[0]>>>1])}i.x86.hash32=function(e,t){if(!i.inputValidation||s(e)){t=t||0;for(var n=e.length%4,r=e.length-n,u=t,h=0,f=3432918353,l=461845907,d=0;d>>0}},i.x86.hash128=function(e,t){if(!i.inputValidation||s(e)){t=t||0;for(var n=e.length%16,r=e.length-n,u=t,h=t,f=t,l=t,d=0,p=0,b=0,g=0,k=597399067,y=2869860233,w=951274213,m=2716044179,v=0;v>>0).toString(16)).slice(-8)+("00000000"+(h>>>0).toString(16)).slice(-8)+("00000000"+(f>>>0).toString(16)).slice(-8)+("00000000"+(l>>>0).toString(16)).slice(-8)}},i.x64.hash128=function(e,t){if(!i.inputValidation||s(e)){t=t||0;for(var n=e.length%16,r=e.length-n,o=[0,t],a=[0,t],c=[0,0],b=[0,0],g=[2277735313,289559509],k=[1291169091,658871167],y=0;y>>0).toString(16)).slice(-8)+("00000000"+(o[1]>>>0).toString(16)).slice(-8)+("00000000"+(a[0]>>>0).toString(16)).slice(-8)+("00000000"+(a[1]>>>0).toString(16)).slice(-8)}},e.exports&&(t=e.exports=i),t.murmurHash3=i}()},function(e,t,n){"use strict";const r=n(9),i=self.crypto||self.msCrypto,s=async(e,t)=>{if("undefined"==typeof self||!self.crypto&&!self.msCrypto)throw new Error("Please use a browser with webcrypto support and ensure the code has been delivered securely via HTTPS/TLS and run within a Secure Context");switch(t){case"sha1":return new Uint8Array(await i.subtle.digest({name:"SHA-1"},e));case"sha2-256":return new Uint8Array(await i.subtle.digest({name:"SHA-256"},e));case"sha2-512":return new Uint8Array(await i.subtle.digest({name:"SHA-512"},e));case"dbl-sha2-256":{const t=await i.subtle.digest({name:"SHA-256"},e);return new Uint8Array(await i.subtle.digest({name:"SHA-256"},t))}default:throw new Error(t+" is not a supported algorithm")}};e.exports={factory:e=>async t=>s(t,e),digest:s,multihashing:async(e,t,n)=>{const i=await s(e,t);return r.encode(i,t,n)}}},function(e,t,n){"use strict";e.exports={fromNumberTo32BitBuf:e=>{const t=new Uint8Array(4);for(let n=0;n<4;n++)t[n]=255&e,e>>=8;return t}}},function(e,t,n){"use strict";const r=n(107),i={init:r.blake2bInit,update:r.blake2bUpdate,digest:r.blake2bFinal},s={init:r.blake2sInit,update:r.blake2sUpdate,digest:r.blake2sFinal},o=(e,t)=>async n=>{const r=t.init(e,null);return t.update(r,n),t.digest(r)};e.exports=e=>{for(let t=0;t<64;t++)e[45569+t]=o(t+1,i);for(let t=0;t<32;t++)e[45633+t]=o(t+1,s)}},function(e,t,n){var r=n(108),i=n(109);e.exports={blake2b:r.blake2b,blake2bHex:r.blake2bHex,blake2bInit:r.blake2bInit,blake2bUpdate:r.blake2bUpdate,blake2bFinal:r.blake2bFinal,blake2s:i.blake2s,blake2sHex:i.blake2sHex,blake2sInit:i.blake2sInit,blake2sUpdate:i.blake2sUpdate,blake2sFinal:i.blake2sFinal}},function(e,t,n){var r=n(32);function i(e,t,n){var r=e[t]+e[n],i=e[t+1]+e[n+1];r>=4294967296&&i++,e[t]=r,e[t+1]=i}function s(e,t,n,r){var i=e[t]+n;n<0&&(i+=4294967296);var s=e[t+1]+r;i>=4294967296&&s++,e[t]=i,e[t+1]=s}function o(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function a(e,t,n,r,o,a){var c=f[o],u=f[o+1],l=f[a],d=f[a+1];i(h,e,t),s(h,e,c,u);var p=h[r]^h[e],b=h[r+1]^h[e+1];h[r]=b,h[r+1]=p,i(h,n,r),p=h[t]^h[n],b=h[t+1]^h[n+1],h[t]=p>>>24^b<<8,h[t+1]=b>>>24^p<<8,i(h,e,t),s(h,e,l,d),p=h[r]^h[e],b=h[r+1]^h[e+1],h[r]=p>>>16^b<<16,h[r+1]=b>>>16^p<<16,i(h,n,r),p=h[t]^h[n],b=h[t+1]^h[n+1],h[t]=b>>>31^p<<1,h[t+1]=p>>>31^b<<1}var c=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),u=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3].map((function(e){return 2*e}))),h=new Uint32Array(32),f=new Uint32Array(32);function l(e,t){var n=0;for(n=0;n<16;n++)h[n]=e.h[n],h[n+16]=c[n];for(h[24]=h[24]^e.t,h[25]=h[25]^e.t/4294967296,t&&(h[28]=~h[28],h[29]=~h[29]),n=0;n<32;n++)f[n]=o(e.b,4*n);for(n=0;n<12;n++)a(0,8,16,24,u[16*n+0],u[16*n+1]),a(2,10,18,26,u[16*n+2],u[16*n+3]),a(4,12,20,28,u[16*n+4],u[16*n+5]),a(6,14,22,30,u[16*n+6],u[16*n+7]),a(0,10,20,30,u[16*n+8],u[16*n+9]),a(2,12,22,24,u[16*n+10],u[16*n+11]),a(4,14,16,26,u[16*n+12],u[16*n+13]),a(6,8,18,28,u[16*n+14],u[16*n+15]);for(n=0;n<16;n++)e.h[n]=e.h[n]^h[n]^h[n+16]}function d(e,t){if(0===e||e>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(t&&t.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");for(var n={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:e},r=0;r<16;r++)n.h[r]=c[r];var i=t?t.length:0;return n.h[0]^=16842752^i<<8^e,t&&(p(n,t),n.c=128),n}function p(e,t){for(var n=0;n>2]>>8*(3&n);return t}function g(e,t,n){n=n||64,e=r.normalizeInput(e);var i=d(n,t);return p(i,e),b(i)}e.exports={blake2b:g,blake2bHex:function(e,t,n){var i=g(e,t,n);return r.toHex(i)},blake2bInit:d,blake2bUpdate:p,blake2bFinal:b}},function(e,t,n){var r=n(32);function i(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function s(e,t,n,r,i,s){u[e]=u[e]+u[t]+i,u[r]=o(u[r]^u[e],16),u[n]=u[n]+u[r],u[t]=o(u[t]^u[n],12),u[e]=u[e]+u[t]+s,u[r]=o(u[r]^u[e],8),u[n]=u[n]+u[r],u[t]=o(u[t]^u[n],7)}function o(e,t){return e>>>t^e<<32-t}var a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),c=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),u=new Uint32Array(16),h=new Uint32Array(16);function f(e,t){var n=0;for(n=0;n<8;n++)u[n]=e.h[n],u[n+8]=a[n];for(u[12]^=e.t,u[13]^=e.t/4294967296,t&&(u[14]=~u[14]),n=0;n<16;n++)h[n]=i(e.b,4*n);for(n=0;n<10;n++)s(0,4,8,12,h[c[16*n+0]],h[c[16*n+1]]),s(1,5,9,13,h[c[16*n+2]],h[c[16*n+3]]),s(2,6,10,14,h[c[16*n+4]],h[c[16*n+5]]),s(3,7,11,15,h[c[16*n+6]],h[c[16*n+7]]),s(0,5,10,15,h[c[16*n+8]],h[c[16*n+9]]),s(1,6,11,12,h[c[16*n+10]],h[c[16*n+11]]),s(2,7,8,13,h[c[16*n+12]],h[c[16*n+13]]),s(3,4,9,14,h[c[16*n+14]],h[c[16*n+15]]);for(n=0;n<8;n++)e.h[n]^=u[n]^u[n+8]}function l(e,t){if(!(e>0&&e<=32))throw new Error("Incorrect output length, should be in [1, 32]");var n=t?t.length:0;if(t&&!(n>0&&n<=32))throw new Error("Incorrect key length, should be in [1, 32]");var r={h:new Uint32Array(a),b:new Uint32Array(64),c:0,t:0,outlen:e};return r.h[0]^=16842752^n<<8^e,n>0&&(d(r,t),r.c=64),r}function d(e,t){for(var n=0;n>2]>>8*(3&n)&255;return t}function b(e,t,n){n=n||32,e=r.normalizeInput(e);var i=l(n,t);return d(i,e),p(i)}e.exports={blake2s:b,blake2sHex:function(e,t,n){var i=b(e,t,n);return r.toHex(i)},blake2sInit:l,blake2sUpdate:d,blake2sFinal:p}},function(e,t,n){"use strict";const r=n(27),i=n(33);e.exports=(e,t)=>{const n=(e=>{if(i.isDAGLink(e))return e;if(!("cid"in e||"hash"in e||"Hash"in e||"multihash"in e))throw new Error("Link must be a DAGLink or DAGLink-like. Convert the DAGNode into a DAGLink via `node.toDAGLink()`.");return new i(e.Name||e.name,e.Tsize||e.size,e.Hash||e.multihash||e.hash||e.cid)})(t);e.Links.push(n),r(e.Links)}},function(e,t,n){"use strict";const r=n(4);e.exports.createDagLinkFromB58EncodedHash=function(e){return new r(e.Name||e.name||"",e.Tsize||e.Size||e.size||0,e.Hash||e.hash||e.multihash||e.cid)}},function(e,t,n){"use strict";const r=n(5),i=n(18);e.exports=(e,t)=>{let n=null;if("string"==typeof t?n=e=>e.Name===t:(t instanceof Uint8Array||r.isCID(t))&&(n=e=>i(e.Hash,t)),!n)throw new Error("second arg needs to be a name or CID");{const t=e.Links;let r=0;for(;r{let n=i.deserialize(e);const s=t.split("/").filter(Boolean);for(;s.length;){const e=s.shift();if(void 0===n[e]){for(const t of n.Links)if(t.Name===e)return{value:t.Hash,remainderPath:s.join("/")};throw new Error(`Object has no property '${e}'`)}if(n=n[e],r.isCID(n))return{value:n,remainderPath:s.join("/")}}return{value:n,remainderPath:""}},t.tree=function*(e){const t=i.deserialize(e);yield"Data",yield"Links";for(let e=0;et,stringify:JSON.stringify}},function(e,t,n){"use strict";const r=n(10),i=n(117),s=n(35),{LastWriteWins:o,NoZeroes:a}=s,c=n(36),{isDefined:u,findUniques:h,difference:f,io:l}=n(12),d=["heads"],p=(e,t)=>e.slice(e.length-Math.min(e.length,t),e.length);e.exports=class{static async toMultihash(e,t,{format:n}={}){if(!u(e))throw c.IPFSNotDefinedError();if(!u(t))throw c.LogNotDefinedError();u(n)||(n="dag-cbor");if((await t.values()).length<1)throw new Error("Can't serialize an empty log");return l.write(e,n,t.toJSON(),{links:d})}static async fromMultihash(e,t,{length:n=-1,exclude:r=[],timeout:s,concurrency:h,sortFn:f,onProgressCallback:b}){if(!u(e))throw c.IPFSNotDefinedError();if(!u(t))throw new Error("Invalid hash: "+t);const g=await l.read(e,t,{links:d});if(!g.heads||!g.id)throw c.NotALogError();f=f||a(o);const k=await i.fetchAll(e,g.heads,{length:n,exclude:r,timeout:s,concurrency:h,onProgressCallback:b}),y=g.id,w=n>-1?p(k.sort(f),n):k,m=w.filter(e=>g.heads.includes(e.hash));return{logId:y,entries:w,heads:m}}static async fromEntryHash(e,t,{length:n=-1,exclude:r=[],timeout:s,concurrency:h,sortFn:f,onProgressCallback:l}){if(!u(e))throw c.IpfsNotDefinedError();if(!u(t))throw new Error("'hash' must be defined");const d=Array.isArray(t)?t:[t];n=n>-1?Math.max(n,1):n;const b=await i.fetchParallel(e,d,{length:n,exclude:r,timeout:s,concurrency:h,onProgressCallback:l});f=f||a(o);return{entries:n>-1?p(b.sort(f),n):b}}static async fromJSON(e,t,{length:n=-1,timeout:s,concurrency:o,onProgressCallback:a}){if(!u(e))throw c.IPFSNotDefinedError();const{id:h,heads:f}=t,l=f.map(e=>e.hash);return{logId:h,entries:(await i.fetchParallel(e,l,{length:n,timeout:s,concurrency:o,onProgressCallback:a})).sort(r.compare),heads:f}}static async fromEntry(e,t,{length:n=-1,exclude:s=[],timeout:o,concurrency:a,onProgressCallback:l}){if(!u(e))throw c.IPFSNotDefinedError();if(!u(t))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(t)&&!r.isEntry(t))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(t)||(t=[t]),n=n>-1?Math.max(n,t.length):n;const d=t.map(e=>e.hash),p=await i.fetchParallel(e,d,{length:n,exclude:s,timeout:o,concurrency:a,onProgressCallback:l}),b=t.concat(p).concat(s),g=h(b,"hash").sort(r.compare),k=g.slice(n>-1?-n:-g.length),y=((e,t)=>{const n=e.slice(t.length,e.length);return t.concat(n)})(k,f(k,t,"hash"));return{logId:y[y.length-1].id,entries:y}}}},function(e,t,n){"use strict";const r=n(21),i=n(118),s=n(10),o=e=>e&&e.length>0;class a{static async fetchParallel(e,t,{length:n,exclude:i=[],timeout:s,concurrency:o,onProgressCallback:c}){const u=(e,t)=>e.concat(t),h=await r(t,async t=>a.fetchAll(e,t,{length:n,exclude:i,timeout:s,onProgressCallback:c,concurrency:o}),{concurrency:Math.max(o||t.length,1)});return h.reduce(u,[])}static async fetchAll(e,t,{length:n=-1,exclude:a=[],timeout:c,onProgressCallback:u,onStartProgressCallback:h,concurrency:f=32,delay:l=0}={}){const d=[],p={},b={},g=Array.isArray(t)?{0:t.slice()}:{0:[t]};let k=0,y=0,w=0;const m=(e,t)=>{b[e]||(g[t]||(g[t]=[]),g[t].includes(e)||g[t].push(e),b[e]=!0)},v=async t=>{if(t&&!p[t])return new Promise((r,i)=>{const o=c&&c>0?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${t}', request timed out (${c}ms)`),r()},c):null;h&&h(t,null,0,d.length),s.fromMultihash(e,t).then(async e=>{try{if((e=>{if(s.isEntry(e)){const r=e.clock.time;y=Math.max(y,r),w=d.length>0?Math.min(d[d.length-1].clock.time,w):y;const i=d.length>=n&&r>=w,s=e=>y-r+(e+1)*e;(n<0||d.lengthw||r===w&&!p[e.hash])&&e.next.forEach(e=>m(e,s(0))),e.refs&&d.length+e.refs.length<=n&&e.refs.forEach((e,t)=>m(e,s(t))))}})(e),l>0){const e=(e=0)=>new Promise(t=>setTimeout(t,e));await e(l)}r()}catch(e){i(e)}finally{clearTimeout(o)}}).catch(i)})};return a.forEach(e=>{p[e.hash]=!0}),await i(async()=>{if(kObject.keys(g).reduce((t,n,r)=>{const i=g[n];for(;i.length>0&&t.lengthvoid 0!==Object.values(g).find(o)),d}}e.exports=a},function(e,t,n){"use strict";const r=async(e,t)=>{if(t(await e()))return r(e,t)};e.exports=r,e.exports.default=r},function(e,t,n){"use strict";e.exports=class{async canAppend(e,t){return!0}}},function(e,t,n){"use strict";const r=n(121);e.exports=class{constructor(e={},t=1/0){this._cache=new r({max:t}),this.add(e)}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}delete(e){this._cache.del(e)}add(e){for(const t in e)this._cache.set(t,e[t])}get length(){return this._cache.length}}},function(e,t,n){"use strict";const r=n(122),i=Symbol("max"),s=Symbol("length"),o=Symbol("lengthCalculator"),a=Symbol("allowStale"),c=Symbol("maxAge"),u=Symbol("dispose"),h=Symbol("noDisposeOnSet"),f=Symbol("lruList"),l=Symbol("cache"),d=Symbol("updateAgeOnGet"),p=()=>1;const b=(e,t,n)=>{const r=e[l].get(t);if(r){const t=r.value;if(g(e,t)){if(y(e,r),!e[a])return}else n&&(e[d]&&(r.value.now=Date.now()),e[f].unshiftNode(r));return t.value}},g=(e,t)=>{if(!t||!t.maxAge&&!e[c])return!1;const n=Date.now()-t.now;return t.maxAge?n>t.maxAge:e[c]&&n>e[c]},k=e=>{if(e[s]>e[i])for(let t=e[f].tail;e[s]>e[i]&&null!==t;){const n=t.prev;y(e,t),t=n}},y=(e,t)=>{if(t){const n=t.value;e[u]&&e[u](n.key,n.value),e[s]-=n.length,e[l].delete(n.key),e[f].removeNode(t)}};class w{constructor(e,t,n,r,i){this.key=e,this.value=t,this.length=n,this.now=r,this.maxAge=i||0}}const m=(e,t,n,r)=>{let i=n.value;g(e,i)&&(y(e,n),e[a]||(i=void 0)),i&&t.call(r,i.value,i.key,e)};e.exports=class{constructor(e){if("number"==typeof e&&(e={max:e}),e||(e={}),e.max&&("number"!=typeof e.max||e.max<0))throw new TypeError("max must be a non-negative number");this[i]=e.max||1/0;const t=e.length||p;if(this[o]="function"!=typeof t?p:t,this[a]=e.stale||!1,e.maxAge&&"number"!=typeof e.maxAge)throw new TypeError("maxAge must be a number");this[c]=e.maxAge||0,this[u]=e.dispose,this[h]=e.noDisposeOnSet||!1,this[d]=e.updateAgeOnGet||!1,this.reset()}set max(e){if("number"!=typeof e||e<0)throw new TypeError("max must be a non-negative number");this[i]=e||1/0,k(this)}get max(){return this[i]}set allowStale(e){this[a]=!!e}get allowStale(){return this[a]}set maxAge(e){if("number"!=typeof e)throw new TypeError("maxAge must be a non-negative number");this[c]=e,k(this)}get maxAge(){return this[c]}set lengthCalculator(e){"function"!=typeof e&&(e=p),e!==this[o]&&(this[o]=e,this[s]=0,this[f].forEach(e=>{e.length=this[o](e.value,e.key),this[s]+=e.length})),k(this)}get lengthCalculator(){return this[o]}get length(){return this[s]}get itemCount(){return this[f].length}rforEach(e,t){t=t||this;for(let n=this[f].tail;null!==n;){const r=n.prev;m(this,e,n,t),n=r}}forEach(e,t){t=t||this;for(let n=this[f].head;null!==n;){const r=n.next;m(this,e,n,t),n=r}}keys(){return this[f].toArray().map(e=>e.key)}values(){return this[f].toArray().map(e=>e.value)}reset(){this[u]&&this[f]&&this[f].length&&this[f].forEach(e=>this[u](e.key,e.value)),this[l]=new Map,this[f]=new r,this[s]=0}dump(){return this[f].map(e=>!g(this,e)&&{k:e.key,v:e.value,e:e.now+(e.maxAge||0)}).toArray().filter(e=>e)}dumpLru(){return this[f]}set(e,t,n){if((n=n||this[c])&&"number"!=typeof n)throw new TypeError("maxAge must be a number");const r=n?Date.now():0,a=this[o](t,e);if(this[l].has(e)){if(a>this[i])return y(this,this[l].get(e)),!1;const o=this[l].get(e).value;return this[u]&&(this[h]||this[u](e,o.value)),o.now=r,o.maxAge=n,o.value=t,this[s]+=a-o.length,o.length=a,this.get(e),k(this),!0}const d=new w(e,t,a,r,n);return d.length>this[i]?(this[u]&&this[u](e,t),!1):(this[s]+=d.length,this[f].unshift(d),this[l].set(e,this[f].head),k(this),!0)}has(e){if(!this[l].has(e))return!1;const t=this[l].get(e).value;return!g(this,t)}get(e){return b(this,e,!0)}peek(e){return b(this,e,!1)}pop(){const e=this[f].tail;return e?(y(this,e),e.value):null}del(e){y(this,this[l].get(e))}load(e){this.reset();const t=Date.now();for(let n=e.length-1;n>=0;n--){const r=e[n],i=r.e||0;if(0===i)this.set(r.k,r.v);else{const e=i-t;e>0&&this.set(r.k,r.v,e)}}}prune(){this[l].forEach((e,t)=>b(this,t,!1))}}},function(e,t,n){"use strict";function r(e){var t=this;if(t instanceof r||(t=new r),t.tail=null,t.head=null,t.length=0,e&&"function"==typeof e.forEach)e.forEach((function(e){t.push(e)}));else if(arguments.length>0)for(var n=0,i=arguments.length;n1)n=t;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");r=this.head.next,n=this.head.value}for(var i=0;null!==r;i++)n=e(n,r.value,i),r=r.next;return n},r.prototype.reduceReverse=function(e,t){var n,r=this.tail;if(arguments.length>1)n=t;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");r=this.tail.prev,n=this.tail.value}for(var i=this.length-1;null!==r;i--)n=e(n,r.value,i),r=r.prev;return n},r.prototype.toArray=function(){for(var e=new Array(this.length),t=0,n=this.head;null!==n;t++)e[t]=n.value,n=n.next;return e},r.prototype.toArrayReverse=function(){for(var e=new Array(this.length),t=0,n=this.tail;null!==n;t++)e[t]=n.value,n=n.prev;return e},r.prototype.slice=function(e,t){(t=t||this.length)<0&&(t+=this.length),(e=e||0)<0&&(e+=this.length);var n=new r;if(tthis.length&&(t=this.length);for(var i=0,s=this.head;null!==s&&ithis.length&&(t=this.length);for(var i=this.length,s=this.tail;null!==s&&i>t;i--)s=s.prev;for(;null!==s&&i>e;i--,s=s.prev)n.push(s.value);return n},r.prototype.splice=function(e,t,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);for(var r=0,s=this.head;null!==s&&r 0 && arguments[0] !== undefined ? arguments[0] : {}; + var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity; (0, _classCallCheck2["default"])(this, EntryIndex); - this._cache = entries; + this._cache = new LRU({ + max: cacheSize + }); + this.add(entries); } (0, _createClass2["default"])(EntryIndex, [{ key: "set", value: function set(k, v) { - this._cache[k] = v; + this._cache.set(k, v); } }, { key: "get", value: function get(k) { - return this._cache[k]; + return this._cache.get(k); } }, { key: "delete", value: function _delete(k) { - return delete this._cache[k]; + this._cache.del(k); } }, { key: "add", - value: function add(newItems) { - this._cache = Object.assign(this._cache, newItems); + value: function add(items) { + for (var k in items) { + this._cache.set(k, items[k]); + } } }, { key: "length", get: function get() { - return Object.values(this._cache).length; + return this._cache.length; } }]); return EntryIndex; diff --git a/lib/es5/entry.js b/lib/es5/entry.js index 6f0c1b1e..32143133 100644 --- a/lib/es5/entry.js +++ b/lib/es5/entry.js @@ -31,6 +31,11 @@ var getWriteFormatForVersion = function getWriteFormatForVersion(v) { var getWriteFormat = function getWriteFormat(e) { return Entry.isEntry(e) ? getWriteFormatForVersion(e.v) : getWriteFormatForVersion(e); }; +/* + * @description + * An ipfs-log entry + */ + var Entry = /*#__PURE__*/function () { function Entry() { diff --git a/lib/es5/log-io.js b/lib/es5/log-io.js index b3a2b35c..a33d619b 100644 --- a/lib/es5/log-io.js +++ b/lib/es5/log-io.js @@ -53,6 +53,7 @@ var LogIO = /*#__PURE__*/function () { var _toMultihash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(ipfs, log) { var _ref, format, + values, _args = arguments; return _regenerator["default"].wrap(function _callee$(_context) { @@ -78,20 +79,25 @@ var LogIO = /*#__PURE__*/function () { case 5: if (!isDefined(format)) format = 'dag-cbor'; + _context.next = 8; + return log.values(); - if (!(log.values.length < 1)) { - _context.next = 8; + case 8: + values = _context.sent; + + if (!(values.length < 1)) { + _context.next = 11; break; } throw new Error('Can\'t serialize an empty log'); - case 8: + case 11: return _context.abrupt("return", io.write(ipfs, format, log.toJSON(), { links: IPLD_LINKS })); - case 9: + case 12: case "end": return _context.stop(); } diff --git a/lib/es5/log.js b/lib/es5/log.js index 08cbfa27..660ebc91 100644 --- a/lib/es5/log.js +++ b/lib/es5/log.js @@ -2,12 +2,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); + var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); -var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); - var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); @@ -18,6 +18,12 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); +var _asyncIterator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncIterator")); + +var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator")); + +var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator")); + function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } @@ -72,8 +78,6 @@ var uniqueEntriesReducer = function uniqueEntriesReducer(res, acc) { return res; }; /** - * Log. - * * @description * Log implements a G-Set CRDT and adds ordering. * @@ -104,14 +108,16 @@ var Log = /*#__PURE__*/function (_GSet) { function Log(ipfs, identity) { var _this; - var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, - logId = _ref.logId, - access = _ref.access, - entries = _ref.entries, - heads = _ref.heads, - clock = _ref.clock, - sortFn = _ref.sortFn, - concurrency = _ref.concurrency; + var _ref3 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + logId = _ref3.logId, + access = _ref3.access, + entries = _ref3.entries, + heads = _ref3.heads, + clock = _ref3.clock, + sortFn = _ref3.sortFn, + concurrency = _ref3.concurrency, + _ref3$hashIndex = _ref3.hashIndex, + hashIndex = _ref3$hashIndex === void 0 ? new Map() : _ref3$hashIndex; (0, _classCallCheck2["default"])(this, Log); @@ -153,7 +159,12 @@ var Log = /*#__PURE__*/function (_GSet) { entries = Object.values(uniqueEntries) || []; // Set heads if not passed as an argument heads = heads || Log.findHeads(entries); - _this._headsIndex = heads.reduce(uniqueEntriesReducer, {}); // Index of all next pointers in this log + _this._headsIndex = heads.reduce(uniqueEntriesReducer, {}); // Index of log hashes + + _this._hashIndex = hashIndex; + entries.forEach(function (e) { + return _this._hashIndex.set(e.hash, e.next); + }); // Index of all next pointers in this log _this._nextsIndex = {}; @@ -163,9 +174,12 @@ var Log = /*#__PURE__*/function (_GSet) { }); }; - entries.forEach(addToNextsIndex); // Set the length, we calculate the length manually internally - - _this._length = entries.length; // Set the clock + entries.forEach(addToNextsIndex); + hashIndex.forEach(function (nexts, hash) { + return nexts.forEach(function (a) { + return _this._nextsIndex[a] = hash; + }); + }); // Set the clock var maxTime = Math.max(clock ? clock.time : 0, _this.heads.reduce(maxClockTimeReducer, 0)); // Take the given key as the clock id is it's a Key instance, // otherwise if key was given, take whatever it is, @@ -182,12 +196,124 @@ var Log = /*#__PURE__*/function (_GSet) { (0, _createClass2["default"])(Log, [{ - key: "setIdentity", + key: "values", + + /** + * Returns the values in the log. + * @returns {Array} + */ + value: function () { + var _values = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { + return _regenerator["default"].wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _context.t0 = Object; + _context.next = 3; + return this.traverse(this.heads); + + case 3: + _context.t1 = _context.sent; + return _context.abrupt("return", _context.t0.values.call(_context.t0, _context.t1).reverse()); + + case 5: + case "end": + return _context.stop(); + } + } + }, _callee, this); + })); + + function values() { + return _values.apply(this, arguments); + } + + return values; + }() + /** + * Returns an array of heads as hashes. + * @returns {Array} + */ + + }, { + key: "tails", + + /** + * Returns an array of Entry objects that reference entries which + * are not in the log currently. + * @returns {Array} + */ + value: function () { + var _tails = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { + var values; + return _regenerator["default"].wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return this.values(); + + case 2: + values = _context2.sent; + return _context2.abrupt("return", Log.findTails(values)); + + case 4: + case "end": + return _context2.stop(); + } + } + }, _callee2, this); + })); + function tails() { + return _tails.apply(this, arguments); + } + + return tails; + }() + /** + * Returns an array of hashes that are referenced by entries which + * are not in the log currently. + * @returns {Array} Array of hashes + */ + + }, { + key: "tailHashes", + value: function () { + var _tailHashes = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() { + var values; + return _regenerator["default"].wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + _context3.next = 2; + return this.values(); + + case 2: + values = _context3.sent; + return _context3.abrupt("return", Log.findTailHashes(values)); + + case 4: + case "end": + return _context3.stop(); + } + } + }, _callee3, this); + })); + + function tailHashes() { + return _tailHashes.apply(this, arguments); + } + + return tailHashes; + }() /** * Set the identity for the log * @param {Identity} [identity] The identity to be set */ + + }, { + key: "setIdentity", value: function setIdentity(identity) { this._identity = identity; // Find the latest clock from the heads @@ -202,9 +328,64 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "get", - value: function get(hash) { - return this._entryIndex.get(hash); - } + value: function () { + var _get = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(hash) { + var haveCache, entry; + return _regenerator["default"].wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + if (this.has(hash)) { + _context4.next = 2; + break; + } + + return _context4.abrupt("return", undefined); + + case 2: + haveCache = this._entryIndex.get(hash); + + if (!haveCache) { + _context4.next = 5; + break; + } + + return _context4.abrupt("return", haveCache); + + case 5: + _context4.prev = 5; + _context4.next = 8; + return Entry.fromMultihash(this._storage, hash); + + case 8: + entry = _context4.sent; + + this._entryIndex.set(entry.hash, entry); + + _context4.next = 14; + break; + + case 12: + _context4.prev = 12; + _context4.t0 = _context4["catch"](5); + + case 14: + return _context4.abrupt("return", entry); + + case 15: + case "end": + return _context4.stop(); + } + } + }, _callee4, this, [[5, 12]]); + })); + + function get(_x) { + return _get.apply(this, arguments); + } + + return get; + }() /** * Checks if a entry is part of the log * @param {string} hash The hash of the entry @@ -214,69 +395,135 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "has", value: function has(entry) { - return this._entryIndex.get(entry.hash || entry) !== undefined; + return this._hashIndex.has(entry.hash || entry); } }, { key: "traverse", - value: function traverse(rootEntries) { - var _this2 = this; + value: function () { + var _traverse = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(rootEntries) { + var _this2 = this; + + var amount, + endHash, + stack, + traversed, + result, + count, + getEntry, + addToStack, + addEntry, + entry, + entries, + defined, + _args6 = arguments; + return _regenerator["default"].wrap(function _callee6$(_context6) { + while (1) { + switch (_context6.prev = _context6.next) { + case 0: + amount = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : -1; + endHash = _args6.length > 2 ? _args6[2] : undefined; + // Sort the given given root entries and use as the starting stack + stack = rootEntries.sort(this._sortFn).reverse(); // Cache for checking if we've processed an entry already + + traversed = {}; // End result + + result = {}; + count = 0; // Named function for getting an entry from the log + + getEntry = /*#__PURE__*/function () { + var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(e) { + return _regenerator["default"].wrap(function _callee5$(_context5) { + while (1) { + switch (_context5.prev = _context5.next) { + case 0: + return _context5.abrupt("return", _this2.get(e)); + + case 1: + case "end": + return _context5.stop(); + } + } + }, _callee5); + })); - var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; - var endHash = arguments.length > 2 ? arguments[2] : undefined; - // Sort the given given root entries and use as the starting stack - var stack = rootEntries.sort(this._sortFn).reverse(); // Cache for checking if we've processed an entry already + return function getEntry(_x3) { + return _ref4.apply(this, arguments); + }; + }(); // Add an entry to the stack and traversed nodes index - var traversed = {}; // End result - var result = {}; - var count = 0; // Named function for getting an entry from the log + addToStack = function addToStack(entry) { + // If we've already processed the entry, don't add it to the stack + if (!entry || traversed[entry.hash]) { + return; + } // Add the entry in front of the stack and sort - var getEntry = function getEntry(e) { - return _this2.get(e); - }; // Add an entry to the stack and traversed nodes index + stack = [entry].concat((0, _toConsumableArray2["default"])(stack)).sort(_this2._sortFn).reverse(); // Add to the cache of processed entries - var addToStack = function addToStack(entry) { - // If we've already processed the entry, don't add it to the stack - if (!entry || traversed[entry.hash]) { - return; - } // Add the entry in front of the stack and sort + traversed[entry.hash] = true; + }; + addEntry = function addEntry(rootEntry) { + result[rootEntry.hash] = rootEntry; + traversed[rootEntry.hash] = true; + count++; + }; // Start traversal + // Process stack until it's empty (traversed the full log) + // or when we have the requested amount of entries + // If requested entry amount is -1, traverse all - stack = [entry].concat((0, _toConsumableArray2["default"])(stack)).sort(_this2._sortFn).reverse(); // Add to the cache of processed entries - traversed[entry.hash] = true; - }; + case 9: + if (!(stack.length > 0 && (count < amount || amount < 0))) { + _context6.next = 21; + break; + } - var addEntry = function addEntry(rootEntry) { - result[rootEntry.hash] = rootEntry; - traversed[rootEntry.hash] = true; - count++; - }; // Start traversal - // Process stack until it's empty (traversed the full log) - // or when we have the requested amount of entries - // If requested entry amount is -1, traverse all + // eslint-disable-line no-unmodified-loop-condition + // Get the next element from the stack + entry = stack.shift(); // Add to the result + addEntry(entry); // If it is the specified end hash, break out of the while loop - while (stack.length > 0 && (count < amount || amount < 0)) { - // eslint-disable-line no-unmodified-loop-condition - // Get the next element from the stack - var entry = stack.shift(); // Add to the result + if (!(endHash && endHash === entry.hash)) { + _context6.next = 14; + break; + } - addEntry(entry); // If it is the specified end hash, break out of the while loop + return _context6.abrupt("break", 21); - if (endHash && endHash === entry.hash) break; // Add entry's next references to the stack + case 14: + _context6.next = 16; + return pMap(entry.next, getEntry); - var entries = entry.next.map(getEntry); - var defined = entries.filter(isDefined); - defined.forEach(addToStack); - } + case 16: + entries = _context6.sent; + defined = entries.filter(isDefined); + defined.forEach(addToStack); + _context6.next = 9; + break; - stack = []; - traversed = {}; // End result + case 21: + stack = []; + traversed = {}; // End result - return result; - } + return _context6.abrupt("return", result); + + case 24: + case "end": + return _context6.stop(); + } + } + }, _callee6, this); + })); + + function traverse(_x2) { + return _traverse.apply(this, arguments); + } + + return traverse; + }() /** * Append an entry to the log. * @param {Entry} entry Entry to add @@ -286,7 +533,7 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "append", value: function () { - var _append = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(data) { + var _append = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(data) { var _this3 = this; var pointerCount, @@ -300,21 +547,28 @@ var Log = /*#__PURE__*/function (_GSet) { refs, entry, canAppend, - _args = arguments; - return _regenerator["default"].wrap(function _callee$(_context) { + _args7 = arguments; + return _regenerator["default"].wrap(function _callee7$(_context7) { while (1) { - switch (_context.prev = _context.next) { + switch (_context7.prev = _context7.next) { case 0: - pointerCount = _args.length > 1 && _args[1] !== undefined ? _args[1] : 1; - pin = _args.length > 2 && _args[2] !== undefined ? _args[2] : false; + pointerCount = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : 1; + pin = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : false; // Update the clock (find the latest clock) newTime = Math.max(this.clock.time, this.heads.reduce(maxClockTimeReducer, 0)) + 1; this._clock = new Clock(this.clock.id, newTime); - all = Object.values(this.traverse(this.heads, Math.max(pointerCount, this.heads.length))); // If pointer count is 4, returns 2 + _context7.t0 = Object; + _context7.next = 7; + return this.traverse(this.heads, Math.max(pointerCount, this.heads.length)); + + case 7: + _context7.t1 = _context7.sent; + all = _context7.t0.values.call(_context7.t0, _context7.t1); + + // If pointer count is 4, returns 2 // If pointer count is 8, returns 3 references // If pointer count is 512, returns 9 references // If pointer count is 2048, returns 11 references - getEveryPow2 = function getEveryPow2(maxDistance) { var entries = new Set(); @@ -343,45 +597,46 @@ var Log = /*#__PURE__*/function (_GSet) { refs = Array.from(references).map(getHash).filter(isNext); // @TODO: Split Entry.create into creating object, checking permission, signing and then posting to IPFS // Create the entry and add it to the internal cache - _context.next = 13; + _context7.next = 17; return Entry.create(this._storage, this._identity, this.id, data, nexts, this.clock, refs, pin); - case 13: - entry = _context.sent; - _context.next = 16; + case 17: + entry = _context7.sent; + _context7.next = 20; return this._access.canAppend(entry, this._identity.provider); - case 16: - canAppend = _context.sent; + case 20: + canAppend = _context7.sent; if (canAppend) { - _context.next = 19; + _context7.next = 23; break; } throw new Error("Could not append entry, key \"".concat(this._identity.id, "\" is not allowed to write to the log")); - case 19: + case 23: this._entryIndex.set(entry.hash, entry); nexts.forEach(function (e) { return _this3._nextsIndex[e] = entry.hash; }); this._headsIndex = {}; - this._headsIndex[entry.hash] = entry; // Update the length + this._headsIndex[entry.hash] = entry; - this._length++; - return _context.abrupt("return", entry); + this._hashIndex.set(entry.hash, nexts); - case 25: + return _context7.abrupt("return", entry); + + case 29: case "end": - return _context.stop(); + return _context7.stop(); } } - }, _callee, this); + }, _callee7, this); })); - function append(_x) { + function append(_x4) { return _append.apply(this, arguments); } @@ -396,7 +651,7 @@ var Log = /*#__PURE__*/function (_GSet) { * @param {string|Array} options.lt Ending hash of the iterator, non-inclusive * @param {string|Array} options.lte Ending hash of the iterator, inclusive * @param {amount} options.amount Number of entried to return to / from the gte / lte hash - * @returns {Symbol.Iterator} Iterator object containing log entries + * @returns {Symbol.asyncIterator} asyncIterator object containing log entries * * @examples * @@ -421,74 +676,200 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "iterator", value: function iterator() { - var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - _ref2$gt = _ref2.gt, - gt = _ref2$gt === void 0 ? undefined : _ref2$gt, - _ref2$gte = _ref2.gte, - gte = _ref2$gte === void 0 ? undefined : _ref2$gte, - _ref2$lt = _ref2.lt, - lt = _ref2$lt === void 0 ? undefined : _ref2$lt, - _ref2$lte = _ref2.lte, - lte = _ref2$lte === void 0 ? undefined : _ref2$lte, - _ref2$amount = _ref2.amount, - amount = _ref2$amount === void 0 ? -1 : _ref2$amount; - - if (amount === 0) return /*#__PURE__*/_regenerator["default"].mark(function _callee2() { - return _regenerator["default"].wrap(function _callee2$(_context2) { + var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref5$gt = _ref5.gt, + gt = _ref5$gt === void 0 ? undefined : _ref5$gt, + _ref5$gte = _ref5.gte, + gte = _ref5$gte === void 0 ? undefined : _ref5$gte, + _ref5$lt = _ref5.lt, + lt = _ref5$lt === void 0 ? undefined : _ref5$lt, + _ref5$lte = _ref5.lte, + lte = _ref5$lte === void 0 ? undefined : _ref5$lte, + _ref5$amount = _ref5.amount, + amount = _ref5$amount === void 0 ? -1 : _ref5$amount; + + if (amount === 0) return (0, _wrapAsyncGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8() { + return _regenerator["default"].wrap(function _callee8$(_context8) { while (1) { - switch (_context2.prev = _context2.next) { + switch (_context8.prev = _context8.next) { case 0: case "end": - return _context2.stop(); + return _context8.stop(); } } - }, _callee2); - })(); - if (typeof lte === 'string') lte = [this.get(lte)]; - if (typeof lt === 'string') lt = [this.get(this.get(lt).next)]; - if (lte && !Array.isArray(lte)) throw LogError.LtOrLteMustBeStringOrArray(); - if (lt && !Array.isArray(lt)) throw LogError.LtOrLteMustBeStringOrArray(); - var start = (lte || lt || this.heads).filter(isDefined); - var endHash = gte ? this.get(gte).hash : gt ? this.get(gt).hash : null; - var count = endHash ? -1 : amount || -1; - var entries = this.traverse(start, count, endHash); - var entryValues = Object.values(entries); // Strip off last entry if gt is non-inclusive - - if (gt) entryValues.pop(); // Deal with the amount argument working backwards from gt/gte - - if ((gt || gte) && amount > -1) { - entryValues = entryValues.slice(entryValues.length - amount, entryValues.length); + }, _callee8); + }))(); + + if (lte && typeof lte !== 'string' && !Array.isArray(lte)) { + throw LogError.LtOrLteMustBeStringOrArray(); } - return /*#__PURE__*/_regenerator["default"].mark(function _callee3() { - var i; - return _regenerator["default"].wrap(function _callee3$(_context3) { + if (lt && typeof lt !== 'string' && !Array.isArray(lt)) { + throw LogError.LtOrLteMustBeStringOrArray(); + } + + var self = this; + return (0, _wrapAsyncGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() { + var value, _value2, next, start, endHash, _value3, _value4, count, entries, entryValues, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _value, _value5; + + return _regenerator["default"].wrap(function _callee9$(_context9) { while (1) { - switch (_context3.prev = _context3.next) { + switch (_context9.prev = _context9.next) { case 0: - _context3.t0 = _regenerator["default"].keys(entryValues); - - case 1: - if ((_context3.t1 = _context3.t0()).done) { - _context3.next = 7; + if (!(typeof lte === 'string')) { + _context9.next = 5; break; } - i = _context3.t1.value; - _context3.next = 5; - return entryValues[i]; + _context9.next = 3; + return (0, _awaitAsyncGenerator2["default"])(self.get(lte)); + + case 3: + value = _context9.sent; + lte = [value]; case 5: - _context3.next = 1; + if (!(typeof lt === 'string')) { + _context9.next = 13; + break; + } + + _context9.next = 8; + return (0, _awaitAsyncGenerator2["default"])(self.get(lt)); + + case 8: + _value2 = _context9.sent; + _context9.next = 11; + return (0, _awaitAsyncGenerator2["default"])(self.get(_value2.next[0])); + + case 11: + next = _context9.sent; + lt = [next]; + + case 13: + start = (lte || lt || self.heads).filter(isDefined); + endHash = null; + + if (!gte) { + _context9.next = 22; + break; + } + + _context9.next = 18; + return (0, _awaitAsyncGenerator2["default"])(self.get(gte)); + + case 18: + _value3 = _context9.sent; + endHash = _value3.hash; + _context9.next = 27; break; - case 7: + case 22: + if (!gt) { + _context9.next = 27; + break; + } + + _context9.next = 25; + return (0, _awaitAsyncGenerator2["default"])(self.get(gt)); + + case 25: + _value4 = _context9.sent; + endHash = _value4.hash; + + case 27: + count = endHash ? -1 : amount || -1; + _context9.next = 30; + return (0, _awaitAsyncGenerator2["default"])(self.traverse(start, count, endHash)); + + case 30: + entries = _context9.sent; + entryValues = Object.values(entries); // Strip off last entry if gt is non-inclusive + + if (gt) entryValues.pop(); // Deal with the amount argument working backwards from gt/gte + + if ((gt || gte) && amount > -1) { + entryValues = entryValues.slice(entryValues.length - amount, entryValues.length); + } // TODO convert traverse into async iterator + + + _iteratorNormalCompletion = true; + _didIteratorError = false; + _context9.prev = 36; + _iterator = (0, _asyncIterator2["default"])(entryValues); + + case 38: + _context9.next = 40; + return (0, _awaitAsyncGenerator2["default"])(_iterator.next()); + + case 40: + _step = _context9.sent; + _iteratorNormalCompletion = _step.done; + _context9.next = 44; + return (0, _awaitAsyncGenerator2["default"])(_step.value); + + case 44: + _value = _context9.sent; + + if (_iteratorNormalCompletion) { + _context9.next = 52; + break; + } + + _value5 = _value; + _context9.next = 49; + return _value5; + + case 49: + _iteratorNormalCompletion = true; + _context9.next = 38; + break; + + case 52: + _context9.next = 58; + break; + + case 54: + _context9.prev = 54; + _context9.t0 = _context9["catch"](36); + _didIteratorError = true; + _iteratorError = _context9.t0; + + case 58: + _context9.prev = 58; + _context9.prev = 59; + + if (!(!_iteratorNormalCompletion && _iterator["return"] != null)) { + _context9.next = 63; + break; + } + + _context9.next = 63; + return (0, _awaitAsyncGenerator2["default"])(_iterator["return"]()); + + case 63: + _context9.prev = 63; + + if (!_didIteratorError) { + _context9.next = 66; + break; + } + + throw _iteratorError; + + case 66: + return _context9.finish(63); + + case 67: + return _context9.finish(58); + + case 68: case "end": - return _context3.stop(); + return _context9.stop(); } } - }, _callee3); - })(); + }, _callee9, null, [[36, 54, 58, 68], [59,, 63, 67]]); + }))(); } /** * Join two logs. @@ -505,7 +886,7 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "join", value: function () { - var _join = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(log) { + var _join = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(log) { var _this4 = this; var size, @@ -514,22 +895,23 @@ var Log = /*#__PURE__*/function (_GSet) { permitted, verify, entriesToJoin, - addToNextsIndex, + addToIndexes, notReferencedByNewItems, notInCurrentNexts, nextsFromNewItems, mergedHeads, tmp, + addToNextsIndex, maxClock, - _args7 = arguments; - return _regenerator["default"].wrap(function _callee7$(_context7) { + _args13 = arguments; + return _regenerator["default"].wrap(function _callee13$(_context13) { while (1) { - switch (_context7.prev = _context7.next) { + switch (_context13.prev = _context13.next) { case 0: - size = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : -1; + size = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : -1; if (isDefined(log)) { - _context7.next = 3; + _context13.next = 3; break; } @@ -537,7 +919,7 @@ var Log = /*#__PURE__*/function (_GSet) { case 3: if (Log.isLog(log)) { - _context7.next = 5; + _context13.next = 5; break; } @@ -545,33 +927,36 @@ var Log = /*#__PURE__*/function (_GSet) { case 5: if (!(this.id !== log.id)) { - _context7.next = 7; + _context13.next = 7; break; } - return _context7.abrupt("return"); + return _context13.abrupt("return"); case 7: - // Get the difference of the logs - newItems = Log.difference(log, this); + _context13.next = 9; + return Log.difference(log, this); + + case 9: + newItems = _context13.sent; identityProvider = this._identity.provider; // Verify if entries are allowed to be added to the log and throws if // there's an invalid entry permitted = /*#__PURE__*/function () { - var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(entry) { + var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(entry) { var canAppend; - return _regenerator["default"].wrap(function _callee4$(_context4) { + return _regenerator["default"].wrap(function _callee10$(_context10) { while (1) { - switch (_context4.prev = _context4.next) { + switch (_context10.prev = _context10.next) { case 0: - _context4.next = 2; + _context10.next = 2; return _this4._access.canAppend(entry, identityProvider); case 2: - canAppend = _context4.sent; + canAppend = _context10.sent; if (canAppend) { - _context4.next = 5; + _context10.next = 5; break; } @@ -579,34 +964,34 @@ var Log = /*#__PURE__*/function (_GSet) { case 5: case "end": - return _context4.stop(); + return _context10.stop(); } } - }, _callee4); + }, _callee10); })); - return function permitted(_x3) { - return _ref3.apply(this, arguments); + return function permitted(_x6) { + return _ref6.apply(this, arguments); }; }(); // Verify signature for each entry and throws if there's an invalid signature verify = /*#__PURE__*/function () { - var _ref4 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(entry) { + var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(entry) { var isValid, publicKey; - return _regenerator["default"].wrap(function _callee5$(_context5) { + return _regenerator["default"].wrap(function _callee11$(_context11) { while (1) { - switch (_context5.prev = _context5.next) { + switch (_context11.prev = _context11.next) { case 0: - _context5.next = 2; + _context11.next = 2; return Entry.verify(identityProvider, entry); case 2: - isValid = _context5.sent; + isValid = _context11.sent; publicKey = entry.identity ? entry.identity.publicKey : entry.key; if (isValid) { - _context5.next = 6; + _context11.next = 6; break; } @@ -614,61 +999,58 @@ var Log = /*#__PURE__*/function (_GSet) { case 6: case "end": - return _context5.stop(); + return _context11.stop(); } } - }, _callee5); + }, _callee11); })); - return function verify(_x4) { - return _ref4.apply(this, arguments); + return function verify(_x7) { + return _ref7.apply(this, arguments); }; }(); entriesToJoin = Object.values(newItems); - _context7.next = 14; + _context13.next = 16; return pMap(entriesToJoin, /*#__PURE__*/function () { - var _ref5 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(e) { - return _regenerator["default"].wrap(function _callee6$(_context6) { + var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(e) { + return _regenerator["default"].wrap(function _callee12$(_context12) { while (1) { - switch (_context6.prev = _context6.next) { + switch (_context12.prev = _context12.next) { case 0: - _context6.next = 2; + _context12.next = 2; return permitted(e); case 2: - _context6.next = 4; + _context12.next = 4; return verify(e); case 4: case "end": - return _context6.stop(); + return _context12.stop(); } } - }, _callee6); + }, _callee12); })); - return function (_x5) { - return _ref5.apply(this, arguments); + return function (_x8) { + return _ref8.apply(this, arguments); }; }(), { concurrency: this.joinConcurrency }); - case 14: - // Update the internal next pointers index - addToNextsIndex = function addToNextsIndex(e) { - var entry = _this4.get(e.hash); - - if (!entry) _this4._length++; - /* istanbul ignore else */ - + case 16: + // Update internal indexes + addToIndexes = function addToIndexes(e) { e.next.forEach(function (a) { return _this4._nextsIndex[a] = e.hash; }); + + _this4._hashIndex.set(e.hash, e.next); }; - Object.values(newItems).forEach(addToNextsIndex); // Update the internal entry index + entriesToJoin.forEach(addToIndexes); // Update the internal entry index this._entryIndex.add(newItems); // Merge the heads @@ -687,29 +1069,49 @@ var Log = /*#__PURE__*/function (_GSet) { mergedHeads = Log.findHeads(Object.values(Object.assign({}, this._headsIndex, log._headsIndex))).filter(notReferencedByNewItems).filter(notInCurrentNexts).reduce(uniqueEntriesReducer, {}); this._headsIndex = mergedHeads; // Slice to the requested size - if (size > -1) { - tmp = this.values; - tmp = tmp.slice(-size); - this._entryIndex = null; - this._entryIndex = new EntryIndex(tmp.reduce(uniqueEntriesReducer, {})); - this._headsIndex = Log.findHeads(tmp).reduce(uniqueEntriesReducer, {}); - this._length = this._entryIndex.length; - } // Find the latest clock from the heads + if (!(size > -1)) { + _context13.next = 37; + break; + } + _context13.next = 27; + return this.values(); + + case 27: + tmp = _context13.sent; + tmp = tmp.slice(-size); + this._entryIndex = null; + this._entryIndex = new EntryIndex(tmp.reduce(uniqueEntriesReducer, {})); + this._hashIndex = new Map(); + tmp.forEach(function (e) { + return _this4._hashIndex.set(e.hash, e.next); + }); + this._nextsIndex = {}; + addToNextsIndex = function addToNextsIndex(e) { + return e.next.forEach(function (a) { + return _this4._nextsIndex[a] = e.hash; + }); + }; + + tmp.forEach(addToNextsIndex); + this._headsIndex = Log.findHeads(tmp).reduce(uniqueEntriesReducer, {}); + + case 37: + // Find the latest clock from the heads maxClock = Object.values(this._headsIndex).reduce(maxClockTimeReducer, 0); this._clock = new Clock(this.clock.id, Math.max(this.clock.time, maxClock)); - return _context7.abrupt("return", this); + return _context13.abrupt("return", this); - case 26: + case 40: case "end": - return _context7.stop(); + return _context13.stop(); } } - }, _callee7, this); + }, _callee13, this); })); - function join(_x2) { + function join(_x5) { return _join.apply(this, arguments); } @@ -738,13 +1140,38 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "toSnapshot", - value: function toSnapshot() { - return { - id: this.id, - heads: this.heads, - values: this.values - }; - } + value: function () { + var _toSnapshot = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14() { + var values; + return _regenerator["default"].wrap(function _callee14$(_context14) { + while (1) { + switch (_context14.prev = _context14.next) { + case 0: + _context14.next = 2; + return this.values(); + + case 2: + values = _context14.sent; + return _context14.abrupt("return", { + id: this.id, + heads: this.heads, + values: values + }); + + case 4: + case "end": + return _context14.stop(); + } + } + }, _callee14, this); + })); + + function toSnapshot() { + return _toSnapshot.apply(this, arguments); + } + + return toSnapshot; + }() /** * Get the log as a Buffer. * @returns {Buffer} @@ -766,20 +1193,43 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "toString", - value: function toString(payloadMapper) { - var _this5 = this; - - return this.values.slice().reverse().map(function (e, idx) { - var parents = Entry.findChildren(e, _this5.values); - var len = parents.length; - 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'); - } + value: function () { + var _toString = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(payloadMapper) { + var values; + return _regenerator["default"].wrap(function _callee15$(_context15) { + while (1) { + switch (_context15.prev = _context15.next) { + case 0: + _context15.next = 2; + return this.values(); + + case 2: + values = _context15.sent; + return _context15.abrupt("return", values.slice().reverse().map(function (e, idx) { + var parents = Entry.findChildren(e, values); + var len = parents.length; + 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')); + + case 4: + case "end": + return _context15.stop(); + } + } + }, _callee15, this); + })); + + function toString(_x9) { + return _toString.apply(this, arguments); + } + + return toString; + }() /** * Check whether an object is a Log instance. * @param {Object} log An object to check @@ -794,8 +1244,8 @@ var Log = /*#__PURE__*/function (_GSet) { * @returns {Promise} Multihash of the Log as Base58 encoded string. */ value: function toMultihash() { - var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, - format = _ref6.format; + var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + format = _ref9.format; return LogIO.toMultihash(this._storage, this, { format: format @@ -838,64 +1288,27 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "length", get: function get() { - return this._length; + return this._hashIndex.size; } - /** - * Returns the values in the log. - * @returns {Array} - */ - - }, { - key: "values", - get: function get() { - return Object.values(this.traverse(this.heads)).reverse(); - } - /** - * Returns an array of heads as hashes. - * @returns {Array} - */ - }, { key: "heads", get: function get() { return Object.values(this._headsIndex).sort(this._sortFn).reverse(); } - /** - * Returns an array of Entry objects that reference entries which - * are not in the log currently. - * @returns {Array} - */ - - }, { - key: "tails", - get: function get() { - return Log.findTails(this.values); - } - /** - * Returns an array of hashes that are referenced by entries which - * are not in the log currently. - * @returns {Array} Array of hashes - */ - - }, { - key: "tailHashes", - get: function get() { - return Log.findTailHashes(this.values); - } }], [{ key: "isLog", value: function isLog(log) { - return log.id !== undefined && log.heads !== undefined && log._entryIndex !== undefined; + return log.id !== undefined && log.heads !== undefined; } }, { key: "fromMultihash", value: function () { - var _fromMultihash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(ipfs, identity, hash) { - var _ref7, + var _fromMultihash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(ipfs, identity, hash) { + var _ref10, access, - _ref7$length, + _ref10$length, length, - _ref7$exclude, + _ref10$exclude, exclude, timeout, concurrency, @@ -905,14 +1318,14 @@ var Log = /*#__PURE__*/function (_GSet) { logId, entries, heads, - _args8 = arguments; + _args16 = arguments; - return _regenerator["default"].wrap(function _callee8$(_context8) { + return _regenerator["default"].wrap(function _callee16$(_context16) { while (1) { - switch (_context8.prev = _context8.next) { + switch (_context16.prev = _context16.next) { case 0: - _ref7 = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : {}, access = _ref7.access, _ref7$length = _ref7.length, length = _ref7$length === void 0 ? -1 : _ref7$length, _ref7$exclude = _ref7.exclude, exclude = _ref7$exclude === void 0 ? [] : _ref7$exclude, timeout = _ref7.timeout, concurrency = _ref7.concurrency, sortFn = _ref7.sortFn, onProgressCallback = _ref7.onProgressCallback; - _context8.next = 3; + _ref10 = _args16.length > 3 && _args16[3] !== undefined ? _args16[3] : {}, access = _ref10.access, _ref10$length = _ref10.length, length = _ref10$length === void 0 ? -1 : _ref10$length, _ref10$exclude = _ref10.exclude, exclude = _ref10$exclude === void 0 ? [] : _ref10$exclude, timeout = _ref10.timeout, concurrency = _ref10.concurrency, sortFn = _ref10.sortFn, onProgressCallback = _ref10.onProgressCallback; + _context16.next = 3; return LogIO.fromMultihash(ipfs, hash, { length: length, exclude: exclude, @@ -923,11 +1336,11 @@ var Log = /*#__PURE__*/function (_GSet) { }); case 3: - _yield$LogIO$fromMult = _context8.sent; + _yield$LogIO$fromMult = _context16.sent; logId = _yield$LogIO$fromMult.logId; entries = _yield$LogIO$fromMult.entries; heads = _yield$LogIO$fromMult.heads; - return _context8.abrupt("return", new Log(ipfs, identity, { + return _context16.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, entries: entries, @@ -937,13 +1350,13 @@ var Log = /*#__PURE__*/function (_GSet) { case 8: case "end": - return _context8.stop(); + return _context16.stop(); } } - }, _callee8); + }, _callee16); })); - function fromMultihash(_x6, _x7, _x8) { + function fromMultihash(_x10, _x11, _x12) { return _fromMultihash.apply(this, arguments); } @@ -967,13 +1380,13 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "fromEntryHash", value: function () { - var _fromEntryHash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(ipfs, identity, hash) { - var _ref8, + var _fromEntryHash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17(ipfs, identity, hash) { + var _ref11, logId, access, - _ref8$length, + _ref11$length, length, - _ref8$exclude, + _ref11$exclude, exclude, timeout, concurrency, @@ -981,14 +1394,14 @@ var Log = /*#__PURE__*/function (_GSet) { onProgressCallback, _yield$LogIO$fromEntr, entries, - _args9 = arguments; + _args17 = arguments; - return _regenerator["default"].wrap(function _callee9$(_context9) { + return _regenerator["default"].wrap(function _callee17$(_context17) { while (1) { - switch (_context9.prev = _context9.next) { + switch (_context17.prev = _context17.next) { case 0: - _ref8 = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : {}, logId = _ref8.logId, access = _ref8.access, _ref8$length = _ref8.length, length = _ref8$length === void 0 ? -1 : _ref8$length, _ref8$exclude = _ref8.exclude, exclude = _ref8$exclude === void 0 ? [] : _ref8$exclude, timeout = _ref8.timeout, concurrency = _ref8.concurrency, sortFn = _ref8.sortFn, onProgressCallback = _ref8.onProgressCallback; - _context9.next = 3; + _ref11 = _args17.length > 3 && _args17[3] !== undefined ? _args17[3] : {}, logId = _ref11.logId, access = _ref11.access, _ref11$length = _ref11.length, length = _ref11$length === void 0 ? -1 : _ref11$length, _ref11$exclude = _ref11.exclude, exclude = _ref11$exclude === void 0 ? [] : _ref11$exclude, timeout = _ref11.timeout, concurrency = _ref11.concurrency, sortFn = _ref11.sortFn, onProgressCallback = _ref11.onProgressCallback; + _context17.next = 3; return LogIO.fromEntryHash(ipfs, hash, { length: length, exclude: exclude, @@ -998,9 +1411,9 @@ var Log = /*#__PURE__*/function (_GSet) { }); case 3: - _yield$LogIO$fromEntr = _context9.sent; + _yield$LogIO$fromEntr = _context17.sent; entries = _yield$LogIO$fromEntr.entries; - return _context9.abrupt("return", new Log(ipfs, identity, { + return _context17.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, entries: entries, @@ -1009,13 +1422,13 @@ var Log = /*#__PURE__*/function (_GSet) { case 6: case "end": - return _context9.stop(); + return _context17.stop(); } } - }, _callee9); + }, _callee17); })); - function fromEntryHash(_x9, _x10, _x11) { + function fromEntryHash(_x13, _x14, _x15) { return _fromEntryHash.apply(this, arguments); } @@ -1037,10 +1450,10 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "fromJSON", value: function () { - var _fromJSON = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(ipfs, identity, json) { - var _ref9, + var _fromJSON = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18(ipfs, identity, json) { + var _ref12, access, - _ref9$length, + _ref12$length, length, timeout, sortFn, @@ -1048,14 +1461,14 @@ var Log = /*#__PURE__*/function (_GSet) { _yield$LogIO$fromJSON, logId, entries, - _args10 = arguments; + _args18 = arguments; - return _regenerator["default"].wrap(function _callee10$(_context10) { + return _regenerator["default"].wrap(function _callee18$(_context18) { while (1) { - switch (_context10.prev = _context10.next) { + switch (_context18.prev = _context18.next) { case 0: - _ref9 = _args10.length > 3 && _args10[3] !== undefined ? _args10[3] : {}, access = _ref9.access, _ref9$length = _ref9.length, length = _ref9$length === void 0 ? -1 : _ref9$length, timeout = _ref9.timeout, sortFn = _ref9.sortFn, onProgressCallback = _ref9.onProgressCallback; - _context10.next = 3; + _ref12 = _args18.length > 3 && _args18[3] !== undefined ? _args18[3] : {}, access = _ref12.access, _ref12$length = _ref12.length, length = _ref12$length === void 0 ? -1 : _ref12$length, timeout = _ref12.timeout, sortFn = _ref12.sortFn, onProgressCallback = _ref12.onProgressCallback; + _context18.next = 3; return LogIO.fromJSON(ipfs, json, { length: length, timeout: timeout, @@ -1063,10 +1476,10 @@ var Log = /*#__PURE__*/function (_GSet) { }); case 3: - _yield$LogIO$fromJSON = _context10.sent; + _yield$LogIO$fromJSON = _context18.sent; logId = _yield$LogIO$fromJSON.logId; entries = _yield$LogIO$fromJSON.entries; - return _context10.abrupt("return", new Log(ipfs, identity, { + return _context18.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, entries: entries, @@ -1075,13 +1488,13 @@ var Log = /*#__PURE__*/function (_GSet) { case 7: case "end": - return _context10.stop(); + return _context18.stop(); } } - }, _callee10); + }, _callee18); })); - function fromJSON(_x12, _x13, _x14) { + function fromJSON(_x16, _x17, _x18) { return _fromJSON.apply(this, arguments); } @@ -1104,12 +1517,12 @@ var Log = /*#__PURE__*/function (_GSet) { }, { key: "fromEntry", value: function () { - var _fromEntry = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(ipfs, identity, sourceEntries) { - var _ref10, + var _fromEntry = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(ipfs, identity, sourceEntries) { + var _ref13, access, - _ref10$length, + _ref13$length, length, - _ref10$exclude, + _ref13$exclude, exclude, timeout, concurrency, @@ -1118,14 +1531,14 @@ var Log = /*#__PURE__*/function (_GSet) { _yield$LogIO$fromEntr2, logId, entries, - _args11 = arguments; + _args19 = arguments; - return _regenerator["default"].wrap(function _callee11$(_context11) { + return _regenerator["default"].wrap(function _callee19$(_context19) { while (1) { - switch (_context11.prev = _context11.next) { + switch (_context19.prev = _context19.next) { case 0: - _ref10 = _args11.length > 3 && _args11[3] !== undefined ? _args11[3] : {}, access = _ref10.access, _ref10$length = _ref10.length, length = _ref10$length === void 0 ? -1 : _ref10$length, _ref10$exclude = _ref10.exclude, exclude = _ref10$exclude === void 0 ? [] : _ref10$exclude, timeout = _ref10.timeout, concurrency = _ref10.concurrency, sortFn = _ref10.sortFn, onProgressCallback = _ref10.onProgressCallback; - _context11.next = 3; + _ref13 = _args19.length > 3 && _args19[3] !== undefined ? _args19[3] : {}, access = _ref13.access, _ref13$length = _ref13.length, length = _ref13$length === void 0 ? -1 : _ref13$length, _ref13$exclude = _ref13.exclude, exclude = _ref13$exclude === void 0 ? [] : _ref13$exclude, timeout = _ref13.timeout, concurrency = _ref13.concurrency, sortFn = _ref13.sortFn, onProgressCallback = _ref13.onProgressCallback; + _context19.next = 3; return LogIO.fromEntry(ipfs, sourceEntries, { length: length, exclude: exclude, @@ -1135,10 +1548,10 @@ var Log = /*#__PURE__*/function (_GSet) { }); case 3: - _yield$LogIO$fromEntr2 = _context11.sent; + _yield$LogIO$fromEntr2 = _context19.sent; logId = _yield$LogIO$fromEntr2.logId; entries = _yield$LogIO$fromEntr2.entries; - return _context11.abrupt("return", new Log(ipfs, identity, { + return _context19.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, entries: entries, @@ -1147,13 +1560,13 @@ var Log = /*#__PURE__*/function (_GSet) { case 7: case "end": - return _context11.stop(); + return _context19.stop(); } } - }, _callee11); + }, _callee19); })); - function fromEntry(_x15, _x16, _x17) { + function fromEntry(_x19, _x20, _x21) { return _fromEntry.apply(this, arguments); } @@ -1278,35 +1691,49 @@ var Log = /*#__PURE__*/function (_GSet) { } }, { key: "difference", - value: function difference(a, b) { - var stack = Object.keys(a._headsIndex); - var traversed = {}; - var res = {}; - - var pushToStack = function pushToStack(hash) { - if (!traversed[hash] && !b.get(hash)) { - stack.push(hash); - traversed[hash] = true; - } - }; + value: function () { + var _difference = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20(a, b) { + var res, hashesFromA, diff, entries; + return _regenerator["default"].wrap(function _callee20$(_context20) { + while (1) { + switch (_context20.prev = _context20.next) { + case 0: + res = {}; + hashesFromA = Array.from(a._hashIndex.keys()); + diff = hashesFromA.filter(function (hash) { + return !b.has(hash); + }); + _context20.next = 5; + return pMap(diff, function (hash) { + return a.get(hash); + }); - while (stack.length > 0) { - var hash = stack.shift(); - var entry = a.get(hash); + case 5: + entries = _context20.sent; + entries.forEach(function (e) { + res[e.hash] = e; + }); + return _context20.abrupt("return", res); - if (entry && !b.get(hash) && entry.id === b.id) { - res[entry.hash] = entry; - traversed[entry.hash] = true; - entry.next.forEach(pushToStack); - } + case 8: + case "end": + return _context20.stop(); + } + } + }, _callee20); + })); + + function difference(_x22, _x23) { + return _difference.apply(this, arguments); } - return res; - } + return difference; + }() }]); return Log; }(GSet); +Log.Entry = Entry; module.exports = Log; module.exports.Sorting = Sorting; module.exports.Entry = Entry; diff --git a/package-lock.json b/package-lock.json index 2d3994ff..e4b88aae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13074,7 +13074,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "requires": { "yallist": "^4.0.0" } @@ -20288,8 +20287,7 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yargs": { "version": "16.2.0", diff --git a/package.json b/package.json index 97b5b82d..0ee39ad0 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ ], "dependencies": { "json-stringify-deterministic": "^1.0.1", + "lru-cache": "^6.0.0", "multihashing-async": "^2.0.1", "orbit-db-identity-provider": "~0.3.1", "orbit-db-io": "~0.4.0", diff --git a/src/entry-index.js b/src/entry-index.js index 1568729e..066da7a9 100644 --- a/src/entry-index.js +++ b/src/entry-index.js @@ -1,28 +1,33 @@ 'use strict' +const LRU = require('lru-cache') + class EntryIndex { - constructor (entries = {}) { - this._cache = entries + constructor (entries = {}, cacheSize = Infinity) { + this._cache = new LRU({ max: cacheSize }) + this.add(entries) } set (k, v) { - this._cache[k] = v + this._cache.set(k, v) } get (k) { - return this._cache[k] + return this._cache.get(k) } delete (k) { - return delete this._cache[k] + this._cache.del(k) } - add (newItems) { - this._cache = Object.assign(this._cache, newItems) + add (items) { + for (const k in items) { + this._cache.set(k, items[k]) + } } get length () { - return Object.values(this._cache).length + return this._cache.length } } diff --git a/src/log-io.js b/src/log-io.js index ed1ea4c9..0e58d595 100644 --- a/src/log-io.js +++ b/src/log-io.js @@ -23,7 +23,9 @@ class LogIO { if (!isDefined(ipfs)) throw LogError.IPFSNotDefinedError() if (!isDefined(log)) throw LogError.LogNotDefinedError() if (!isDefined(format)) format = 'dag-cbor' - if (log.values.length < 1) throw new Error('Can\'t serialize an empty log') + + const values = await log.values() + if (values.length < 1) throw new Error('Can\'t serialize an empty log') return io.write(ipfs, format, log.toJSON(), { links: IPLD_LINKS }) } diff --git a/src/log.js b/src/log.js index 7401f6c2..eafe9275 100644 --- a/src/log.js +++ b/src/log.js @@ -41,9 +41,10 @@ class Log extends GSet { * @param {Array} options.heads Set the heads of the log * @param {Clock} options.clock Set the clock of the log * @param {Function} options.sortFn The sort function - by default LastWriteWins + * @param {Map} options.hashIndex A Map of entry hashes to next pointers * @return {Log} The log instance */ - constructor (ipfs, identity, { logId, access, entries, heads, clock, sortFn, concurrency } = {}) { + constructor (ipfs, identity, { logId, access, entries, heads, clock, sortFn, concurrency, hashIndex = new Map() } = {}) { if (!isDefined(ipfs)) { throw LogError.IPFSNotDefinedError() } @@ -89,13 +90,15 @@ class Log extends GSet { heads = heads || Log.findHeads(entries) this._headsIndex = heads.reduce(uniqueEntriesReducer, {}) + // Index of log hashes + this._hashIndex = hashIndex + entries.forEach(e => this._hashIndex.set(e.hash, e.next)) + // Index of all next pointers in this log this._nextsIndex = {} const addToNextsIndex = e => e.next.forEach(a => (this._nextsIndex[a] = e.hash)) entries.forEach(addToNextsIndex) - - // Set the length, we calculate the length manually internally - this._length = entries.length + hashIndex.forEach((nexts, hash) => nexts.forEach(a => (this._nextsIndex[a] = hash))) // Set the clock const maxTime = Math.max(clock ? clock.time : 0, this.heads.reduce(maxClockTimeReducer, 0)) @@ -128,15 +131,15 @@ class Log extends GSet { * @return {number} Length */ get length () { - return this._length + return this._hashIndex.size } /** * Returns the values in the log. - * @returns {Array} + * @returns {Promise>} */ - get values () { - return Object.values(this.traverse(this.heads)).reverse() + async values () { + return Object.values(await this.traverse(this.heads)).reverse() } /** @@ -150,19 +153,21 @@ class Log extends GSet { /** * Returns an array of Entry objects that reference entries which * are not in the log currently. - * @returns {Array} + * @returns {Promise>} */ - get tails () { - return Log.findTails(this.values) + async tails () { + const values = await this.values() + return Log.findTails(values) } /** * Returns an array of hashes that are referenced by entries which * are not in the log currently. - * @returns {Array} Array of hashes + * @returns {Promise>} Array of hashes */ - get tailHashes () { - return Log.findTailHashes(this.values) + async tailHashes () { + const values = await this.values() + return Log.findTailHashes(values) } /** @@ -179,10 +184,27 @@ class Log extends GSet { /** * Find an entry. * @param {string} [hash] The hashes of the entry - * @returns {Entry|undefined} + * @returns {Promise} */ - get (hash) { - return this._entryIndex.get(hash) + async get (hash) { + if (!this.has(hash)) { + return undefined + } + + const haveCache = this._entryIndex.get(hash) + if (haveCache) { + return haveCache + } + + let entry + try { + entry = await Entry.fromMultihash(this._storage, hash) + this._entryIndex.set(entry.hash, entry) + } catch (error) { + // TODO + } + + return entry } /** @@ -191,10 +213,10 @@ class Log extends GSet { * @returns {boolean} */ has (entry) { - return this._entryIndex.get(entry.hash || entry) !== undefined + return this._hashIndex.has(entry.hash || entry) } - traverse (rootEntries, amount = -1, endHash) { + async traverse (rootEntries, amount = -1, endHash) { // Sort the given given root entries and use as the starting stack let stack = rootEntries.sort(this._sortFn).reverse() @@ -204,7 +226,7 @@ class Log extends GSet { const result = {} let count = 0 // Named function for getting an entry from the log - const getEntry = e => this.get(e) + const getEntry = async e => this.get(e) // Add an entry to the stack and traversed nodes index const addToStack = entry => { @@ -240,7 +262,7 @@ class Log extends GSet { if (endHash && endHash === entry.hash) break // Add entry's next references to the stack - const entries = entry.next.map(getEntry) + const entries = await pMap(entry.next, getEntry) const defined = entries.filter(isDefined) defined.forEach(addToStack) } @@ -254,14 +276,14 @@ class Log extends GSet { /** * Append an entry to the log. * @param {Entry} entry Entry to add - * @return {Log} New Log containing the appended value + * @return {Promise} New Log containing the appended value */ async append (data, pointerCount = 1, pin = false) { // Update the clock (find the latest clock) const newTime = Math.max(this.clock.time, this.heads.reduce(maxClockTimeReducer, 0)) + 1 this._clock = new Clock(this.clock.id, newTime) - const all = Object.values(this.traverse(this.heads, Math.max(pointerCount, this.heads.length))) + const all = Object.values(await this.traverse(this.heads, Math.max(pointerCount, this.heads.length))) // If pointer count is 4, returns 2 // If pointer count is 8, returns 3 references @@ -310,8 +332,7 @@ class Log extends GSet { nexts.forEach(e => (this._nextsIndex[e] = entry.hash)) this._headsIndex = {} this._headsIndex[entry.hash] = entry - // Update the length - this._length++ + this._hashIndex.set(entry.hash, nexts) return entry } @@ -324,7 +345,7 @@ class Log extends GSet { * @param {string|Array} options.lt Ending hash of the iterator, non-inclusive * @param {string|Array} options.lte Ending hash of the iterator, inclusive * @param {amount} options.amount Number of entried to return to / from the gte / lte hash - * @returns {Symbol.Iterator} Iterator object containing log entries + * @returns {Symbol.asyncIterator} asyncIterator object containing log entries * * @examples * @@ -347,31 +368,51 @@ class Log extends GSet { */ iterator ({ gt = undefined, gte = undefined, lt = undefined, lte = undefined, amount = -1 } = {}) { - if (amount === 0) return (function * () {})() - if (typeof lte === 'string') lte = [this.get(lte)] - if (typeof lt === 'string') lt = [this.get(this.get(lt).next)] + if (amount === 0) return (async function * () {})() + if (lte && (typeof lte !== 'string' && !Array.isArray(lte))) { + throw LogError.LtOrLteMustBeStringOrArray() + } + if (lt && (typeof lt !== 'string' && !Array.isArray(lt))) { + throw LogError.LtOrLteMustBeStringOrArray() + } - if (lte && !Array.isArray(lte)) throw LogError.LtOrLteMustBeStringOrArray() - if (lt && !Array.isArray(lt)) throw LogError.LtOrLteMustBeStringOrArray() + const self = this + return (async function * () { + if (typeof lte === 'string') { + const value = await self.get(lte) + lte = [value] + } + if (typeof lt === 'string') { + const value = await self.get(lt) + const next = await self.get(value.next[0]) + lt = [next] + } - const start = (lte || (lt || this.heads)).filter(isDefined) - const endHash = gte ? this.get(gte).hash : gt ? this.get(gt).hash : null - const count = endHash ? -1 : amount || -1 + const start = (lte || (lt || self.heads)).filter(isDefined) + let endHash = null + if (gte) { + const value = await self.get(gte) + endHash = value.hash + } else if (gt) { + const value = await self.get(gt) + endHash = value.hash + } + const count = endHash ? -1 : amount || -1 - const entries = this.traverse(start, count, endHash) - let entryValues = Object.values(entries) + const entries = await self.traverse(start, count, endHash) + let entryValues = Object.values(entries) - // Strip off last entry if gt is non-inclusive - if (gt) entryValues.pop() + // Strip off last entry if gt is non-inclusive + if (gt) entryValues.pop() - // Deal with the amount argument working backwards from gt/gte - if ((gt || gte) && amount > -1) { - entryValues = entryValues.slice(entryValues.length - amount, entryValues.length) - } + // Deal with the amount argument working backwards from gt/gte + if ((gt || gte) && amount > -1) { + entryValues = entryValues.slice(entryValues.length - amount, entryValues.length) + } - return (function * () { - for (const i in entryValues) { - yield entryValues[i] + // TODO convert traverse into async iterator + for await (const value of entryValues) { + yield value } })() } @@ -393,7 +434,7 @@ class Log extends GSet { if (this.id !== log.id) return // Get the difference of the logs - const newItems = Log.difference(log, this) + const newItems = await Log.difference(log, this) const identityProvider = this._identity.provider // Verify if entries are allowed to be added to the log and throws if @@ -418,13 +459,12 @@ class Log extends GSet { await verify(e) }, { concurrency: this.joinConcurrency }) - // Update the internal next pointers index - const addToNextsIndex = e => { - const entry = this.get(e.hash) - if (!entry) this._length++ /* istanbul ignore else */ + // Update internal indexes + const addToIndexes = e => { e.next.forEach(a => (this._nextsIndex[a] = e.hash)) + this._hashIndex.set(e.hash, e.next) } - Object.values(newItems).forEach(addToNextsIndex) + entriesToJoin.forEach(addToIndexes) // Update the internal entry index this._entryIndex.add(newItems) @@ -442,12 +482,16 @@ class Log extends GSet { // Slice to the requested size if (size > -1) { - let tmp = this.values + let tmp = await this.values() tmp = tmp.slice(-size) this._entryIndex = null this._entryIndex = new EntryIndex(tmp.reduce(uniqueEntriesReducer, {})) + this._hashIndex = new Map() + tmp.forEach(e => this._hashIndex.set(e.hash, e.next)) + this._nextsIndex = {} + const addToNextsIndex = e => e.next.forEach(a => (this._nextsIndex[a] = e.hash)) + tmp.forEach(addToNextsIndex) this._headsIndex = Log.findHeads(tmp).reduce(uniqueEntriesReducer, {}) - this._length = this._entryIndex.length } // Find the latest clock from the heads @@ -474,11 +518,12 @@ class Log extends GSet { * Get the log in JSON format as a snapshot. * @returns {Object} An object with the id, heads and value properties */ - toSnapshot () { + async toSnapshot () { + const values = await this.values() return { id: this.id, heads: this.heads, - values: this.values + values: values } } @@ -498,12 +543,13 @@ class Log extends GSet { * └─one * └─three */ - toString (payloadMapper) { - return this.values + async toString (payloadMapper) { + const values = await this.values() + return values .slice() .reverse() .map((e, idx) => { - const parents = Entry.findChildren(e, this.values) + const parents = Entry.findChildren(e, values) const len = parents.length let padding = new Array(Math.max(len - 1, 0)) padding = len > 1 ? padding.fill(' ') : padding @@ -521,8 +567,7 @@ class Log extends GSet { */ static isLog (log) { return log.id !== undefined && - log.heads !== undefined && - log._entryIndex !== undefined + log.heads !== undefined } /** @@ -708,31 +753,18 @@ class Log extends GSet { return entries.reduce(reduceTailHashes, []) } - static difference (a, b) { - const stack = Object.keys(a._headsIndex) - const traversed = {} + static async difference (a, b) { const res = {} - - const pushToStack = hash => { - if (!traversed[hash] && !b.get(hash)) { - stack.push(hash) - traversed[hash] = true - } - } - - while (stack.length > 0) { - const hash = stack.shift() - const entry = a.get(hash) - if (entry && !b.get(hash) && entry.id === b.id) { - res[entry.hash] = entry - traversed[entry.hash] = true - entry.next.forEach(pushToStack) - } - } + const hashesFromA = Array.from(a._hashIndex.keys()) + const diff = hashesFromA.filter(hash => !b.has(hash)) + const entries = await pMap(diff, hash => a.get(hash)) + entries.forEach(e => { res[e.hash] = e }) return res } } +Log.Entry = Entry + module.exports = Log module.exports.Sorting = Sorting module.exports.Entry = Entry diff --git a/test/entry-io.spec.js b/test/entry-io.spec.js index a4d00dd6..b8c50360 100644 --- a/test/entry-io.spec.js +++ b/test/entry-io.spec.js @@ -68,7 +68,8 @@ Object.keys(testAPIs).forEach((IPFS) => { it('log with one entry', async () => { const log = new Log(ipfs, testIdentity, { logId: 'X' }) await log.append('one') - const hash = log.values[0].hash + const values = await log.values() + const hash = values[0].hash const res = await EntryIO.fetchAll(ipfs, hash, { length: 1 }) assert.strictEqual(res.length, 1) }) @@ -77,7 +78,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const log = new Log(ipfs, testIdentity, { logId: 'X' }) await log.append('one') await log.append('two') - const hash = last(log.values).hash + const values = await log.values() + const hash = last(values).hash const res = await EntryIO.fetchAll(ipfs, hash, { length: 2 }) assert.strictEqual(res.length, 2) }) @@ -86,7 +88,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const log = new Log(ipfs, testIdentity, { logId: 'X' }) await log.append('one') await log.append('two') - const hash = last(log.values).hash + const values = await log.values() + const hash = last(values).hash const res = await EntryIO.fetchAll(ipfs, hash, { length: 1 }) assert.strictEqual(res.length, 1) }) @@ -108,9 +111,10 @@ Object.keys(testAPIs).forEach((IPFS) => { let log2 = new Log(ipfs, testIdentity, { logId: 'X' }) for (let i = 1; i <= count; i++) { await log.append('hello' + i) + const values2 = await log2.values() if (i % 10 === 0) { log2 = new Log(ipfs, testIdentity, - { logId: log2.id, entries: log2.values, heads: log2.heads.concat(log.heads) }) + { logId: log2.id, entries: values2, heads: log2.heads.concat(log.heads) }) await log2.append('hi' + i) } } @@ -127,7 +131,8 @@ Object.keys(testAPIs).forEach((IPFS) => { for (let i = 1; i <= count; i++) { await log.append('hello' + i) if (i % 10 === 0) { - log2 = new Log(ipfs, testIdentity, { logId: log2.id, entries: log2.values }) + const values2 = await log2.values() + log2 = new Log(ipfs, testIdentity, { logId: log2.id, entries: values2 }) await log2.append('hi' + i) await log2.join(log) } @@ -146,14 +151,16 @@ Object.keys(testAPIs).forEach((IPFS) => { for (let i = 1; i <= count; i++) { await log.append('hello' + i) if (i % 10 === 0) { + const values2 = await log2.values() log2 = new Log(ipfs, testIdentity, - { logId: log2.id, entries: log2.values, heads: log2.heads }) + { logId: log2.id, entries: values2, heads: log2.heads }) await log2.append('hi' + i) await log2.join(log) } if (i % 25 === 0) { + const values3 = await log3.values() log3 = new Log(ipfs, testIdentity, - { logId: log3.id, entries: log3.values, heads: log3.heads.concat(log2.heads) }) + { logId: log3.id, entries: values3, heads: log3.heads.concat(log2.heads) }) await log3.append('--' + i) } } @@ -177,8 +184,9 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.join(log) } if (i % 25 === 0) { + const values3 = await log3.values() log3 = new Log(ipfs, testIdentity3, - { logId: log3.id, entries: log3.values, heads: log3.heads.concat(log2.heads) }) + { logId: log3.id, entries: values3, heads: log3.heads.concat(log2.heads) }) await log3.append('--' + i) } } @@ -189,10 +197,13 @@ Object.keys(testAPIs).forEach((IPFS) => { await log4.join(log2) await log4.join(log3) - const values3 = log3.values.map((e) => e.payload) - const values4 = log4.values.map((e) => e.payload) + const values3 = await log3.values() + const values4 = await log4.values() - assert.deepStrictEqual(values3, values4) + const entryPayloads3 = values3.map((e) => e.payload) + const entryPayloads4 = values4.map((e) => e.payload) + + assert.deepStrictEqual(entryPayloads3, entryPayloads4) }) }) }) diff --git a/test/log-append.spec.js b/test/log-append.spec.js index 426f79dd..c16f1255 100644 --- a/test/log-append.spec.js +++ b/test/log-append.spec.js @@ -55,11 +55,12 @@ Object.keys(testAPIs).forEach((IPFS) => { describe('append', () => { describe('append one', async () => { - let log + let log, values before(async () => { log = new Log(ipfs, testIdentity, 'A') await log.append('hello1') + values = await log.values() }) it('added the correct amount of items', () => { @@ -67,25 +68,25 @@ Object.keys(testAPIs).forEach((IPFS) => { }) it('added the correct values', async () => { - log.values.forEach((entry) => { + values.forEach((entry) => { assert.strictEqual(entry.payload, 'hello1') }) }) it('added the correct amount of next pointers', async () => { - log.values.forEach((entry) => { + values.forEach((entry) => { assert.strictEqual(entry.next.length, 0) }) }) it('has the correct heads', async () => { log.heads.forEach((head) => { - assert.strictEqual(head.hash, log.values[0].hash) + assert.strictEqual(head.hash, values[0].hash) }) }) it('updated the clocks correctly', async () => { - log.values.forEach((entry) => { + values.forEach((entry) => { assert.strictEqual(entry.clock.id, testIdentity.publicKey) assert.strictEqual(entry.clock.time, 1) }) @@ -96,14 +97,14 @@ Object.keys(testAPIs).forEach((IPFS) => { const amount = 100 const nextPointerAmount = 64 - let log + let log, values before(async () => { log = new Log(ipfs, testIdentity, 'A') for (let i = 0; i < amount; i++) { await log.append('hello' + i, nextPointerAmount) // Make sure the log has the right heads after each append - const values = log.values + values = await log.values() assert.strictEqual(log.heads.length, 1) assert.strictEqual(log.heads[0].hash, values[values.length - 1].hash) } @@ -114,20 +115,20 @@ Object.keys(testAPIs).forEach((IPFS) => { }) it('added the correct values', async () => { - log.values.forEach((entry, index) => { + values.forEach((entry, index) => { assert.strictEqual(entry.payload, 'hello' + index) }) }) it('updated the clocks correctly', async () => { - log.values.forEach((entry, index) => { + values.forEach((entry, index) => { assert.strictEqual(entry.clock.time, index + 1) assert.strictEqual(entry.clock.id, testIdentity.publicKey) }) }) it('added the correct amount of refs pointers', async () => { - log.values.forEach((entry, index) => { + values.forEach((entry, index) => { assert.strictEqual(entry.refs.length, index > 0 ? Math.ceil(Math.log2(Math.min(nextPointerAmount, index))) : 0) }) }) diff --git a/test/log-crdt.spec.js b/test/log-crdt.spec.js index 9769efb0..98e0bf72 100644 --- a/test/log-crdt.spec.js +++ b/test/log-crdt.spec.js @@ -78,7 +78,8 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.join(log3) await log1.join(log2) - const res1 = log1.values.slice() + const values1 = await log1.values() + const res1 = values1.slice() log1 = new Log(ipfs, testIdentity, { logId: 'X' }) log2 = new Log(ipfs, testIdentity2, { logId: 'X' }) @@ -94,7 +95,8 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.join(log2) await log3.join(log1) - const res2 = log3.values.slice() + const values3 = await log3.values() + const res2 = values3.slice() // associativity: a + (b + c) == (a + b) + c assert.strictEqual(res1.length, expectedElementsCount) @@ -112,7 +114,8 @@ Object.keys(testAPIs).forEach((IPFS) => { // b + a await log2.join(log1) - const res1 = log2.values.slice() + const values2 = await log2.values() + const res1 = values2.slice() log1 = new Log(ipfs, testIdentity, { logId: 'X' }) log2 = new Log(ipfs, testIdentity2, { logId: 'X' }) @@ -123,7 +126,8 @@ Object.keys(testAPIs).forEach((IPFS) => { // a + b await log1.join(log2) - const res2 = log1.values.slice() + const values1 = await log1.values() + const res2 = values1.slice() // commutativity: a + b == b + a assert.strictEqual(res1.length, expectedElementsCount) @@ -140,7 +144,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.append('helloB1') await log2.append('helloB2') await log2.join(log1) - const resA1 = log2.toString() + const resA1 = await log2.toString() log1 = new Log(ipfs, testIdentity, { logId: 'X' }) log2 = new Log(ipfs, testIdentity2, { logId: 'X' }) @@ -149,7 +153,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.append('helloB1') await log2.append('helloB2') await log1.join(log2) - const resA2 = log1.toString() + const resA2 = await log1.toString() assert.strictEqual(resA1, resA2) @@ -161,7 +165,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.append('helloB1') await log2.append('helloB2') await log1.join(log2) - const resB1 = log1.toString() + const resB1 = await log1.toString() log1 = new Log(ipfs, testIdentity, { logId: 'X' }) log2 = new Log(ipfs, testIdentity2, { logId: 'X' }) @@ -170,7 +174,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.append('helloB1') await log2.append('helloB2') await log2.join(log1) - const resB2 = log2.toString() + const resB2 = await log2.toString() assert.strictEqual(resB1, resB2) @@ -182,7 +186,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.append('helloC1') await log3.append('helloC2') await log3.join(log1) - const resC1 = log3.toString() + const resC1 = await log3.toString() log1 = new Log(ipfs, testIdentity, { logId: 'X' }) log3 = new Log(ipfs, testIdentity3, { logId: 'X' }) @@ -191,7 +195,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.append('helloC1') await log3.append('helloC2') await log1.join(log3) - const resC2 = log1.toString() + const resC2 = await log1.toString() assert.strictEqual(resC1, resC2) @@ -204,7 +208,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.append('helloC1') await log3.append('helloC2') await log3.join(log2) - const resD1 = log3.toString() + const resD1 = await log3.toString() log2 = new Log(ipfs, testIdentity2, { logId: 'X' }) log3 = new Log(ipfs, testIdentity3, { logId: 'X' }) @@ -213,7 +217,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.append('helloC1') await log3.append('helloC2') await log2.join(log3) - const resD2 = log2.toString() + const resD2 = await log2.toString() assert.strictEqual(resD1, resD2) @@ -229,7 +233,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.append('helloC2') await log1.join(log2) await log1.join(log3) - const logLeft = log1.toString() + const logLeft = await log1.toString() log1 = new Log(ipfs, testIdentity, { logId: 'X' }) log2 = new Log(ipfs, testIdentity2, { logId: 'X' }) @@ -242,7 +246,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.append('helloC2') await log3.join(log2) await log3.join(log1) - const logRight = log3.toString() + const logRight = await log3.toString() assert.strictEqual(logLeft, logRight) }) diff --git a/test/log-heads-tails.spec.js b/test/log-heads-tails.spec.js index f61bd27c..96097ca3 100644 --- a/test/log-heads-tails.spec.js +++ b/test/log-heads-tails.spec.js @@ -79,7 +79,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const log1 = new Log(ipfs, testIdentity, { logId: 'A' }) await log1.append('helloA1') await log1.append('helloA2') - assert.deepStrictEqual(log1.get(log1.heads[0].hash), log1.heads[0]) + const entry = await log1.get(log1.heads[0].hash) + assert.deepStrictEqual(entry, log1.heads[0]) }) it('finds head after a join and append', async () => { @@ -92,7 +93,8 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.join(log1) await log2.append('helloB2') - const expectedHead = last(log2.values) + const values2 = await log2.values() + const expectedHead = last(values2) assert.strictEqual(log2.heads.length, 1) assert.deepStrictEqual(log2.heads[0].hash, expectedHead.hash) @@ -104,11 +106,13 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.append('helloA1') await log1.append('helloA2') - const expectedHead1 = last(log1.values) + const values1 = await log1.values() + const expectedHead1 = last(values1) await log2.append('helloB1') await log2.append('helloB2') - const expectedHead2 = last(log2.values) + const values2 = await log2.values() + const expectedHead2 = last(values2) await log1.join(log2) @@ -134,8 +138,10 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.append('helloA3') await log1.append('helloA4') - const expectedHead2 = last(log2.values) - const expectedHead1 = last(log1.values) + const values1 = await log1.values() + const values2 = await log2.values() + const expectedHead2 = last(values2) + const expectedHead1 = last(values1) await log1.join(log2) @@ -157,12 +163,14 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.join(log2) await log1.append('helloA3') await log1.append('helloA4') - const expectedHead1 = last(log1.values) + const values1 = await log1.values() + const expectedHead1 = last(values1) await log3.append('helloC1') await log3.append('helloC2') await log2.join(log3) await log2.append('helloB3') - const expectedHead2 = last(log2.values) + const values2 = await log2.values() + const expectedHead2 = last(values2) await log1.join(log2) const heads = log1.heads @@ -183,12 +191,15 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.join(log2) await log1.append('helloA3') await log1.append('helloA4') - const expectedHead1 = last(log1.values) + const values1 = await log1.values() + const expectedHead1 = last(values1) await log3.append('helloC1') await log2.append('helloB3') await log3.append('helloC2') - const expectedHead2 = last(log2.values) - const expectedHead3 = last(log3.values) + const values2 = await log2.values() + const values3 = await log3.values() + const expectedHead2 = last(values2) + const expectedHead3 = last(values3) await log1.join(log2) await log1.join(log3) @@ -204,13 +215,15 @@ Object.keys(testAPIs).forEach((IPFS) => { it('returns a tail', async () => { const log1 = new Log(ipfs, testIdentity, { logId: 'A' }) await log1.append('helloA1') - assert.strictEqual(log1.tails.length, 1) + const tails1 = await log1.tails() + assert.strictEqual(tails1.length, 1) }) it('tail is a Entry', async () => { const log1 = new Log(ipfs, testIdentity, { logId: 'A' }) await log1.append('helloA1') - assert.strictEqual(Entry.isEntry(log1.tails[0]), true) + const tails1 = await log1.tails() + assert.strictEqual(Entry.isEntry(tails1[0]), true) }) it('returns tail entries', async () => { @@ -219,9 +232,10 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.append('helloA1') await log2.append('helloB1') await log1.join(log2) - assert.strictEqual(log1.tails.length, 2) - assert.strictEqual(Entry.isEntry(log1.tails[0]), true) - assert.strictEqual(Entry.isEntry(log1.tails[1]), true) + const tails1 = await log1.tails() + assert.strictEqual(tails1.length, 2) + assert.strictEqual(Entry.isEntry(tails1[0]), true) + assert.strictEqual(Entry.isEntry(tails1[1]), true) }) it('returns tail hashes', async () => { @@ -232,7 +246,8 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.append('helloB1') await log2.append('helloB2') await log1.join(log2, 2) - assert.strictEqual(log1.tailHashes.length, 2) + const tailHashes = await log1.tailHashes() + assert.strictEqual(tailHashes.length, 2) }) it('returns no tail hashes if all entries point to empty nexts', async () => { @@ -241,7 +256,8 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.append('helloA1') await log2.append('helloB1') await log1.join(log2) - assert.strictEqual(log1.tailHashes.length, 0) + const tailHashes = await log1.tailHashes() + assert.strictEqual(tailHashes.length, 0) }) it('returns tails after loading a partial log', async () => { @@ -254,9 +270,11 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.join(log2) const log4 = await Log.fromEntry(ipfs, testIdentity, log1.heads, { length: 2 }) assert.strictEqual(log4.length, 2) - assert.strictEqual(log4.tails.length, 2) - assert.strictEqual(log4.tails[0].hash, log4.values[0].hash) - assert.strictEqual(log4.tails[1].hash, log4.values[1].hash) + const tails4 = await log4.tails() + assert.strictEqual(tails4.length, 2) + const values4 = await log4.values() + assert.strictEqual(tails4[0].hash, values4[0].hash) + assert.strictEqual(tails4[1].hash, values4[1].hash) }) it('returns tails sorted by public key', async () => { @@ -270,11 +288,12 @@ Object.keys(testAPIs).forEach((IPFS) => { await log3.join(log1) await log3.join(log2) await log4.join(log3) - assert.strictEqual(log4.tails.length, 3) - assert.strictEqual(log4.tails[0].id, 'XX') - assert.strictEqual(log4.tails[0].clock.id, testIdentity3.publicKey) - assert.strictEqual(log4.tails[1].clock.id, testIdentity2.publicKey) - assert.strictEqual(log4.tails[2].clock.id, testIdentity.publicKey) + const tails4 = await log4.tails() + assert.strictEqual(tails4.length, 3) + assert.strictEqual(tails4[0].id, 'XX') + assert.strictEqual(tails4[0].clock.id, testIdentity3.publicKey) + assert.strictEqual(tails4[1].clock.id, testIdentity2.publicKey) + assert.strictEqual(tails4[2].clock.id, testIdentity.publicKey) assert.strictEqual(log4.clock.id, testIdentity4.publicKey) }) }) diff --git a/test/log-iterator.spec.js b/test/log-iterator.spec.js index e3031894..7de699d0 100644 --- a/test/log-iterator.spec.js +++ b/test/log-iterator.spec.js @@ -16,6 +16,16 @@ const { stopIpfs } = require('orbit-db-test-utils') +const toArray = async (iterator) => { + const arr = [] + + for await (const entry of iterator) { + arr.push(entry) + } + + return arr +} + let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3 Object.keys(testAPIs).forEach((IPFS) => { @@ -67,14 +77,14 @@ Object.keys(testAPIs).forEach((IPFS) => { } }) - it('returns a Symbol.iterator object', async () => { + it('returns a Symbol.asyncIterator object', async () => { const it = log1.iterator({ lte: 'zdpuAuNuQ4YBeXY5YStfrsJx6ykz4yBV2XnNcBR4uGmiojQde', amount: 0 }) - assert.strictEqual(typeof it[Symbol.iterator], 'function') - assert.deepStrictEqual(it.next(), { value: undefined, done: true }) + assert.strictEqual(typeof it[Symbol.asyncIterator], 'function') + assert.deepStrictEqual(await it.next(), { value: undefined, done: true }) }) it('returns length with lte and amount', async () => { @@ -84,7 +94,8 @@ Object.keys(testAPIs).forEach((IPFS) => { amount: amount }) - assert.strictEqual([...it].length, 10) + const values = await toArray(it) + assert.strictEqual(values.length, 10) }) it('returns entries with lte and amount', async () => { @@ -96,7 +107,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (67 - i++)) } }) @@ -109,7 +120,8 @@ Object.keys(testAPIs).forEach((IPFS) => { amount: amount }) - assert.strictEqual([...it].length, amount) + const values = await toArray(it) + assert.strictEqual(values.length, amount) }) it('returns entries with lt and amount', async () => { @@ -121,7 +133,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 1 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (67 - i++)) } }) @@ -135,7 +147,7 @@ Object.keys(testAPIs).forEach((IPFS) => { let i = 0 let count = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (72 - i++)) count++ } @@ -150,7 +162,8 @@ Object.keys(testAPIs).forEach((IPFS) => { amount: amount }) - assert.strictEqual([...it].length, amount) + const values = await toArray(it) + assert.strictEqual(values.length, amount) }) it('returns entries with gte and amount', async () => { @@ -162,7 +175,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (79 - i++)) } }) @@ -173,7 +186,8 @@ Object.keys(testAPIs).forEach((IPFS) => { gt: 'zdpuAymZUrYbHgwfYK76xXYhzxNqwaXRWWrn5kmRsZJFdqBEz', lt: 'zdpuAoDcWRiChLXnGskymcGrM1VdAjsaFrsXvNZmcDattA7AF' }) - const hashes = [...it].map(e => e.hash) + const values = await toArray(it) + const hashes = values.map(e => e.hash) // neither hash should appear in the array assert.strictEqual(hashes.indexOf('zdpuAymZUrYbHgwfYK76xXYhzxNqwaXRWWrn5kmRsZJFdqBEz'), -1) @@ -186,7 +200,8 @@ Object.keys(testAPIs).forEach((IPFS) => { gte: 'zdpuAt7YtNE1i9APJitGyKomcmxjc2BDHa57wkrjq4onqBNaR', lt: 'zdpuAr8N4vzqcB5sh5JLcr6Eszo4HnYefBWDbBBwwrTPo6kU6' }) - const hashes = [...it].map(e => e.hash) + const values = await toArray(it) + const hashes = values.map(e => e.hash) // only the gte hash should appear in the array assert.strictEqual(hashes.indexOf('zdpuAt7YtNE1i9APJitGyKomcmxjc2BDHa57wkrjq4onqBNaR'), 24) @@ -199,7 +214,8 @@ Object.keys(testAPIs).forEach((IPFS) => { gt: 'zdpuAqUrGrPa4AaZAQbCH4yxQfEjB32rdFY743XCgyGW8iAuU', lte: 'zdpuAwkagwE9D2jUtLnDiCPqBGh9xhpnaX8iEDQ3K7HRmjggi' }) - const hashes = [...it].map(e => e.hash) + const values = await toArray(it) + const hashes = values.map(e => e.hash) // only the lte hash should appear in the array assert.strictEqual(hashes.indexOf('zdpuAqUrGrPa4AaZAQbCH4yxQfEjB32rdFY743XCgyGW8iAuU'), -1) @@ -212,7 +228,8 @@ Object.keys(testAPIs).forEach((IPFS) => { gte: 'zdpuAzG5AD1GdeNffSskTErjjPbAb95QiNyoaQSrbB62eqYSD', lte: 'zdpuAuujURnUUxVw338Xwh47zGEFjjbaZXXARHPik6KYUcUVk' }) - const hashes = [...it].map(e => e.hash) + const values = await toArray(it) + const hashes = values.map(e => e.hash) // neither hash should appear in the array assert.strictEqual(hashes.indexOf('zdpuAzG5AD1GdeNffSskTErjjPbAb95QiNyoaQSrbB62eqYSD'), 9) @@ -225,7 +242,8 @@ Object.keys(testAPIs).forEach((IPFS) => { gt: 'zdpuAuNuQ4YBeXY5YStfrsJx6ykz4yBV2XnNcBR4uGmiojQde' }) - assert.strictEqual([...it].length, 33) + const values = await toArray(it) + assert.strictEqual(values.length, 33) }) it('returns entries with gt and default amount', async () => { @@ -234,7 +252,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (100 - i++)) } }) @@ -244,7 +262,8 @@ Object.keys(testAPIs).forEach((IPFS) => { gte: 'zdpuAuNuQ4YBeXY5YStfrsJx6ykz4yBV2XnNcBR4uGmiojQde' }) - assert.strictEqual([...it].length, 34) + const values = await toArray(it) + assert.strictEqual(values.length, 34) }) it('returns entries with gte and default amount', async () => { @@ -253,7 +272,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (100 - i++)) } }) @@ -263,7 +282,8 @@ Object.keys(testAPIs).forEach((IPFS) => { lt: 'zdpuAuNuQ4YBeXY5YStfrsJx6ykz4yBV2XnNcBR4uGmiojQde' }) - assert.strictEqual([...it].length, 67) + const values = await toArray(it) + assert.strictEqual(values.length, 67) }) it('returns entries with lt and default amount value', async () => { @@ -272,7 +292,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (66 - i++)) } }) @@ -282,7 +302,8 @@ Object.keys(testAPIs).forEach((IPFS) => { lte: 'zdpuAuNuQ4YBeXY5YStfrsJx6ykz4yBV2XnNcBR4uGmiojQde' }) - assert.strictEqual([...it].length, 68) + const values = await toArray(it) + assert.strictEqual(values.length, 68) }) it('returns entries with lte and default amount value', async () => { @@ -291,7 +312,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) let i = 0 - for (const entry of it) { + for await (const entry of it) { assert.strictEqual(entry.payload, 'entry' + (67 - i++)) } }) @@ -310,7 +331,8 @@ Object.keys(testAPIs).forEach((IPFS) => { lte: fixture.log.heads }) - assert.strictEqual([...it].length, 16) + const values = await toArray(it) + assert.strictEqual(values.length, 16) }) it('returns partial entries from all heads', async () => { @@ -319,7 +341,8 @@ Object.keys(testAPIs).forEach((IPFS) => { amount: 6 }) - assert.deepStrictEqual([...it].map(e => e.payload), + const values = await toArray(it) + assert.deepStrictEqual(values.map(e => e.payload), ['entryA10', 'entryA9', 'entryA8', 'entryA7', 'entryC0', 'entryA6']) }) @@ -328,7 +351,8 @@ Object.keys(testAPIs).forEach((IPFS) => { lte: [fixture.log.heads[0]] }) - assert.strictEqual([...it].length, 10) + const values = await toArray(it) + assert.strictEqual(values.length, 10) }) it('returns partial logs from single heads #2', async () => { @@ -336,7 +360,8 @@ Object.keys(testAPIs).forEach((IPFS) => { lte: [fixture.log.heads[1]] }) - assert.strictEqual([...it].length, 11) + const values = await toArray(it) + assert.strictEqual(values.length, 11) }) it('throws error if lt/lte not a string or array of entries', async () => { diff --git a/test/log-join-concurrent.spec.js b/test/log-join-concurrent.spec.js index 97ace10a..79b4f209 100644 --- a/test/log-join-concurrent.spec.js +++ b/test/log-join-concurrent.spec.js @@ -65,9 +65,12 @@ Object.keys(testAPIs).forEach(IPFS => { const hash1 = await log1.toMultihash() const hash2 = await log2.toMultihash() + const values1 = await log1.values() + const values2 = await log2.values() + assert.strictEqual(hash1, hash2) assert.strictEqual(log1.length, 20) - assert.deepStrictEqual(log1.values.map(e => e.payload), log2.values.map(e => e.payload)) + assert.deepStrictEqual(values1.map(e => e.payload), values2.map(e => e.payload)) }) it('Concurrently appending same payload after join results in same state', async () => { @@ -85,19 +88,25 @@ Object.keys(testAPIs).forEach(IPFS => { const hash1 = await log1.toMultihash() const hash2 = await log2.toMultihash() + const values1 = await log1.values() + const values2 = await log2.values() + assert.strictEqual(hash1, hash2) assert.strictEqual(log1.length, 41) assert.strictEqual(log2.length, 41) - assert.deepStrictEqual(log1.values.map(e => e.payload), log2.values.map(e => e.payload)) + assert.deepStrictEqual(values1.map(e => e.payload), values2.map(e => e.payload)) }) it('Joining after concurrently appending same payload joins entry once', async () => { await log1.join(log2) await log2.join(log1) + const values1 = await log1.values() + const values2 = await log2.values() + assert.strictEqual(log1.length, log2.length) assert.strictEqual(log1.length, 41) - assert.deepStrictEqual(log1.values.map(e => e.payload), log2.values.map(e => e.payload)) + assert.deepStrictEqual(values1.map(e => e.payload), values2.map(e => e.payload)) }) }) }) diff --git a/test/log-join.spec.js b/test/log-join.spec.js index 8d60d85a..b568783e 100644 --- a/test/log-join.spec.js +++ b/test/log-join.spec.js @@ -141,10 +141,11 @@ Object.keys(testAPIs).forEach((IPFS) => { 'helloA1', 'helloB1', 'helloA2', 'helloB2' ] + const values1 = await log1.values() assert.strictEqual(log1.length, 4) - assert.deepStrictEqual(log1.values.map((e) => e.payload), expectedData) + assert.deepStrictEqual(values1.map((e) => e.payload), expectedData) - const item = last(log1.values) + const item = last(values1) assert.strictEqual(item.next.length, 1) }) @@ -160,9 +161,11 @@ Object.keys(testAPIs).forEach((IPFS) => { 'helloA1', 'helloB1', 'helloA2', 'helloB2' ] - assert.deepStrictEqual(log1.values.map((e) => e.hash), log2.values.map((e) => e.hash)) - assert.deepStrictEqual(log1.values.map((e) => e.payload), expectedData) - assert.deepStrictEqual(log2.values.map((e) => e.payload), expectedData) + const values1 = await log1.values() + const values2 = await log2.values() + assert.deepStrictEqual(values1.map((e) => e.hash), values2.map((e) => e.hash)) + assert.deepStrictEqual(values1.map((e) => e.payload), expectedData) + assert.deepStrictEqual(values2.map((e) => e.payload), expectedData) }) it('joins logs twice', async () => { @@ -179,7 +182,8 @@ Object.keys(testAPIs).forEach((IPFS) => { ] assert.strictEqual(log2.length, 4) - assert.deepStrictEqual(log2.values.map((e) => e.payload), expectedData) + const values2 = await log2.values() + assert.deepStrictEqual(values2.map((e) => e.payload), expectedData) }) it('joins 2 logs two ways', async () => { @@ -196,7 +200,8 @@ Object.keys(testAPIs).forEach((IPFS) => { ] assert.strictEqual(log2.length, 4) - assert.deepStrictEqual(log2.values.map((e) => e.payload), expectedData) + const values2 = await log2.values() + assert.deepStrictEqual(values2.map((e) => e.payload), expectedData) }) it('joins 2 logs two ways and has the right heads at every step', async () => { @@ -261,7 +266,8 @@ Object.keys(testAPIs).forEach((IPFS) => { ] assert.strictEqual(log1.length, 8) - assert.deepStrictEqual(log1.values.map(e => e.payload), expectedData) + const values1 = await log1.values() + assert.deepStrictEqual(values1.map(e => e.payload), expectedData) }) it('joins 4 logs to one is commutative', async () => { @@ -281,7 +287,9 @@ Object.keys(testAPIs).forEach((IPFS) => { await log2.join(log4) assert.strictEqual(log1.length, 8) - assert.deepStrictEqual(log1.values.map(e => e.payload), log2.values.map(e => e.payload)) + const values1 = await log1.values() + const values2 = await log2.values() + assert.deepStrictEqual(values1.map(e => e.payload), values2.map(e => e.payload)) }) it('joins logs and updates clocks', async () => { @@ -340,7 +348,8 @@ Object.keys(testAPIs).forEach((IPFS) => { { payload: 'helloD6', id: 'X', clock: new Clock(testIdentity4.publicKey, 8) } ] - const transformed = log4.values.map((e) => { + const values4 = await log4.values() + const transformed = values4.map((e) => { return { payload: e.payload, id: e.id, clock: e.clock } }) @@ -395,7 +404,8 @@ Object.keys(testAPIs).forEach((IPFS) => { ] assert.strictEqual(log4.length, 10) - assert.deepStrictEqual(log4.values.map((e) => e.payload), expectedData) + const values4 = await log4.values() + assert.deepStrictEqual(values4.map((e) => e.payload), expectedData) }) describe('takes length as an argument', async () => { @@ -412,10 +422,11 @@ Object.keys(testAPIs).forEach((IPFS) => { const expectedData = [ 'helloB2' ] - const lastEntry = last(log1.values) + const values1 = await log1.values() + const lastEntry = last(values1) assert.strictEqual(log1.length, 1) - assert.deepStrictEqual(log1.values.map((e) => e.payload), expectedData) + assert.deepStrictEqual(values1.map((e) => e.payload), expectedData) assert.strictEqual(lastEntry.next.length, 1) }) @@ -425,10 +436,11 @@ Object.keys(testAPIs).forEach((IPFS) => { const expectedData = [ 'helloA2', 'helloB2' ] - const lastEntry = last(log1.values) + const values1 = await log1.values() + const lastEntry = last(values1) assert.strictEqual(log1.length, 2) - assert.deepStrictEqual(log1.values.map((e) => e.payload), expectedData) + assert.deepStrictEqual(values1.map((e) => e.payload), expectedData) assert.strictEqual(lastEntry.next.length, 1) }) @@ -438,10 +450,11 @@ Object.keys(testAPIs).forEach((IPFS) => { const expectedData = [ 'helloB1', 'helloA2', 'helloB2' ] - const lastEntry = last(log1.values) + const values1 = await log1.values() + const lastEntry = last(values1) assert.strictEqual(log1.length, 3) - assert.deepStrictEqual(log1.values.map((e) => e.payload), expectedData) + assert.deepStrictEqual(values1.map((e) => e.payload), expectedData) assert.strictEqual(lastEntry.next.length, 1) }) @@ -451,10 +464,11 @@ Object.keys(testAPIs).forEach((IPFS) => { const expectedData = [ 'helloA1', 'helloB1', 'helloA2', 'helloB2' ] - const lastEntry = last(log1.values) + const values1 = await log1.values() + const lastEntry = last(values1) assert.strictEqual(log1.length, 4) - assert.deepStrictEqual(log1.values.map((e) => e.payload), expectedData) + assert.deepStrictEqual(values1.map((e) => e.payload), expectedData) assert.strictEqual(lastEntry.next.length, 1) }) }) diff --git a/test/log-load.spec.js b/test/log-load.spec.js index adbf9b5b..6f62daa5 100644 --- a/test/log-load.spec.js +++ b/test/log-load.spec.js @@ -98,10 +98,10 @@ Object.keys(testAPIs).forEach((IPFS) => { json.heads = await Promise.all(json.heads.map(headHash => Entry.fromMultihash(ipfs, headHash))) const log = await Log.fromJSON(ipfs, testIdentity, json, { logId: 'X' }) - + const values = await log.values() assert.strictEqual(log.id, data.heads[0].id) assert.strictEqual(log.length, 16) - assert.deepStrictEqual(log.values.map(e => e.payload), fixture.expectedData) + assert.deepStrictEqual(values.map(e => e.payload), fixture.expectedData) }) it('creates a log from an entry with custom tiebreaker', async () => { @@ -114,9 +114,10 @@ Object.keys(testAPIs).forEach((IPFS) => { const log = await Log.fromJSON(ipfs, testIdentity, json, { length: -1, logId: 'X', sortFn: FirstWriteWins }) + const values = await log.values() assert.strictEqual(log.id, data.heads[0].id) assert.strictEqual(log.length, 16) - assert.deepStrictEqual(log.values.map(e => e.payload), firstWriteExpectedData) + assert.deepStrictEqual(values.map(e => e.payload), firstWriteExpectedData) }) it('respects timeout parameter', async () => { @@ -128,9 +129,10 @@ Object.keys(testAPIs).forEach((IPFS) => { const st = new Date().getTime() const log = await Log.fromJSON(ipfs, testIdentity, json, { logId: 'X', timeout }) const et = new Date().getTime() + const values = await log.values() assert.strictEqual((et - st) >= timeout, true, '' + (et - st) + ' should be greater than timeout ' + timeout) assert.strictEqual(log.length, 0) - assert.deepStrictEqual(log.values.map(e => e.payload), []) + assert.deepStrictEqual(values.map(e => e.payload), []) }) }) @@ -152,10 +154,10 @@ Object.keys(testAPIs).forEach((IPFS) => { { logId: 'X' }) await log1.join(log2) - + const values1 = await log1.values() assert.strictEqual(log1.id, data.heads[0].id) assert.strictEqual(log1.length, 16) - assert.deepStrictEqual(log1.values.map(e => e.payload), fixture.expectedData) + assert.deepStrictEqual(values1.map(e => e.payload), fixture.expectedData) }) it('creates a log from an entry hash with custom tiebreaker', async () => { @@ -168,20 +170,21 @@ Object.keys(testAPIs).forEach((IPFS) => { { logId: 'X', sortFn: FirstWriteWins }) await log1.join(log2) - + const values1 = await log1.values() assert.strictEqual(log1.id, data.heads[0].id) assert.strictEqual(log1.length, 16) - assert.deepStrictEqual(log1.values.map(e => e.payload), firstWriteExpectedData) + assert.deepStrictEqual(values1.map(e => e.payload), firstWriteExpectedData) }) it('respects timeout parameter', async () => { const timeout = 500 const st = new Date().getTime() - const log = await Log.fromEntryHash(ipfs, testIdentity, 'zdpuAwNuRc2Kc1aNDdcdSWuxfNpHRJQw8L8APBNHCEFXbogus', { logId: 'X', timeout }) + const log1 = await Log.fromEntryHash(ipfs, testIdentity, 'zdpuAwNuRc2Kc1aNDdcdSWuxfNpHRJQw8L8APBNHCEFXbogus', { logId: 'X', timeout }) const et = new Date().getTime() + const values1 = await log1.values() assert.strictEqual((et - st) >= timeout, true, '' + (et - st) + ' should be greater than timeout ' + timeout) - assert.strictEqual(log.length, 0) - assert.deepStrictEqual(log.values.map(e => e.payload), []) + assert.strictEqual(log1.length, 0) + assert.deepStrictEqual(values1.map(e => e.payload), []) }) }) @@ -196,21 +199,24 @@ Object.keys(testAPIs).forEach((IPFS) => { const fixture = await LogCreator.createLogWithSixteenEntries(Log, ipfs, identities) const data = fixture.log - const log = await Log.fromEntry(ipfs, testIdentity, data.heads, { length: -1 }) - assert.strictEqual(log.id, data.heads[0].id) - assert.strictEqual(log.length, 16) - assert.deepStrictEqual(log.values.map(e => e.payload), fixture.expectedData) + const log1 = await Log.fromEntry(ipfs, testIdentity, data.heads, { length: -1 }) + const values1 = await log1.values() + assert.strictEqual(log1.id, data.heads[0].id) + assert.strictEqual(log1.length, 16) + assert.deepStrictEqual(values1.map(e => e.payload), fixture.expectedData) }) it('creates a log from an entry with custom tiebreaker', async () => { const fixture = await LogCreator.createLogWithSixteenEntries(Log, ipfs, identities) const data = fixture.log - const log = await Log.fromEntry(ipfs, testIdentity, data.heads, + const log1 = await Log.fromEntry(ipfs, testIdentity, data.heads, { length: -1, sortFn: FirstWriteWins }) - assert.strictEqual(log.id, data.heads[0].id) - assert.strictEqual(log.length, 16) - assert.deepStrictEqual(log.values.map(e => e.payload), firstWriteExpectedData) + + const values1 = await log1.values() + assert.strictEqual(log1.id, data.heads[0].id) + assert.strictEqual(log1.length, 16) + assert.deepStrictEqual(values1.map(e => e.payload), firstWriteExpectedData) }) it('keeps the original heads', async () => { @@ -219,29 +225,33 @@ Object.keys(testAPIs).forEach((IPFS) => { const log1 = await Log.fromEntry(ipfs, testIdentity, data.heads, { length: data.heads.length }) + + const values1 = await log1.values() assert.strictEqual(log1.id, data.heads[0].id) assert.strictEqual(log1.length, data.heads.length) - assert.strictEqual(log1.values[0].payload, 'entryC0') - assert.strictEqual(log1.values[1].payload, 'entryA10') + assert.strictEqual(values1[0].payload, 'entryC0') + assert.strictEqual(values1[1].payload, 'entryA10') const log2 = await Log.fromEntry(ipfs, testIdentity, data.heads, { length: 4 }) + const values2 = await log2.values() assert.strictEqual(log2.id, data.heads[0].id) assert.strictEqual(log2.length, 4) - assert.strictEqual(log2.values[0].payload, 'entryC0') - assert.strictEqual(log2.values[1].payload, 'entryA8') - assert.strictEqual(log2.values[2].payload, 'entryA9') - assert.strictEqual(log2.values[3].payload, 'entryA10') + assert.strictEqual(values2[0].payload, 'entryC0') + assert.strictEqual(values2[1].payload, 'entryA8') + assert.strictEqual(values2[2].payload, 'entryA9') + assert.strictEqual(values2[3].payload, 'entryA10') const log3 = await Log.fromEntry(ipfs, testIdentity, data.heads, { length: 7 }) + const values3 = await log3.values() assert.strictEqual(log3.id, data.heads[0].id) assert.strictEqual(log3.length, 7) - assert.strictEqual(log3.values[0].payload, 'entryB5') - assert.strictEqual(log3.values[1].payload, 'entryA6') - assert.strictEqual(log3.values[2].payload, 'entryC0') - assert.strictEqual(log3.values[3].payload, 'entryA7') - assert.strictEqual(log3.values[4].payload, 'entryA8') - assert.strictEqual(log3.values[5].payload, 'entryA9') - assert.strictEqual(log3.values[6].payload, 'entryA10') + assert.strictEqual(values3[0].payload, 'entryB5') + assert.strictEqual(values3[1].payload, 'entryA6') + assert.strictEqual(values3[2].payload, 'entryC0') + assert.strictEqual(values3[3].payload, 'entryA7') + assert.strictEqual(values3[4].payload, 'entryA8') + assert.strictEqual(values3[5].payload, 'entryA9') + assert.strictEqual(values3[6].payload, 'entryA10') }) it('onProgress callback is fired for each entry', async () => { @@ -439,8 +449,9 @@ Object.keys(testAPIs).forEach((IPFS) => { const b = await Log.fromEntry(ipfs, testIdentity2, last(items2), { length: amount * 2 }) + const bValues = await b.values() assert.strictEqual(b.length, amount * 2) - assert.deepStrictEqual(b.values.map((e) => e.payload), itemsInB) + assert.deepStrictEqual(bValues.map((e) => e.payload), itemsInB) const c = await Log.fromEntry(ipfs, testIdentity4, last(items3), { length: amount * 3 }) @@ -480,14 +491,16 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC10', 'EOF' ] - assert.deepStrictEqual(c.values.map(e => e.payload), tmp) + let cValues = await c.values() + assert.deepStrictEqual(cValues.map(e => e.payload), tmp) // make sure logX comes after A, B and C const logX = new Log(ipfs, testIdentity4, { logId: 'X' }) await logX.append('1') await logX.append('2') await logX.append('3') - const d = await Log.fromEntry(ipfs, testIdentity3, last(logX.values), + const xValues = await logX.values() + const d = await Log.fromEntry(ipfs, testIdentity3, last(xValues), { length: -1 }) await c.join(d) @@ -495,13 +508,17 @@ Object.keys(testAPIs).forEach((IPFS) => { await c.append('DONE') await d.append('DONE') - const f = await Log.fromEntry(ipfs, testIdentity3, last(c.values), + cValues = await c.values() + const f = await Log.fromEntry(ipfs, testIdentity3, last(cValues), { amount: -1, exclude: [] }) - const g = await Log.fromEntry(ipfs, testIdentity3, last(d.values), + const dValues = await d.values() + const g = await Log.fromEntry(ipfs, testIdentity3, last(dValues), { length: -1, exclude: [] }) - assert.strictEqual(f.toString(), bigLogString) - assert.strictEqual(g.toString(), bigLogString) + const fString = await f.toString() + const gString = await g.toString() + assert.strictEqual(fString, bigLogString) + assert.strictEqual(gString, bigLogString) }) it('retrieves full log of randomly joined log', async () => { @@ -538,7 +555,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryA11', 'entryA12', 'entryA13', 'entryA14', 'entryA15' ] - assert.deepStrictEqual(log1.values.map(e => e.payload), expectedData) + const values1 = await log1.values() + assert.deepStrictEqual(values1.map(e => e.payload), expectedData) }) it('retrieves randomly joined log deterministically', async () => { @@ -574,7 +592,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC0', 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(log.values.map(e => e.payload), expectedData) + const values = await log.values() + assert.deepStrictEqual(values.map(e => e.payload), expectedData) }) it('sorts', async () => { @@ -603,26 +622,27 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryA8', 'entryA9', 'entryA10' ] - const fetchOrder = log.values.slice().sort(Entry.compare) + const values = await log.values() + const fetchOrder = values.slice().sort(Entry.compare) assert.deepStrictEqual(fetchOrder.map(e => e.payload), expectedData) - const reverseOrder = log.values.slice().reverse().sort(Entry.compare) + const reverseOrder = values.slice().reverse().sort(Entry.compare) assert.deepStrictEqual(fetchOrder, reverseOrder) - const hashOrder = log.values.slice().sort((a, b) => a.hash > b.hash).sort(Entry.compare) + const hashOrder = values.slice().sort((a, b) => a.hash > b.hash).sort(Entry.compare) assert.deepStrictEqual(fetchOrder, hashOrder) - const randomOrder2 = log.values.slice().sort((a, b) => 0.5 - Math.random()).sort(Entry.compare) + const randomOrder2 = values.slice().sort((a, b) => 0.5 - Math.random()).sort(Entry.compare) assert.deepStrictEqual(fetchOrder, randomOrder2) // partial data - const partialLog = log.values.filter(e => e.payload !== 'entryC0').sort(Entry.compare) + const partialLog = values.filter(e => e.payload !== 'entryC0').sort(Entry.compare) assert.deepStrictEqual(partialLog.map(e => e.payload), expectedData2) - const partialLog2 = log.values.filter(e => e.payload !== 'entryA10').sort(Entry.compare) + const partialLog2 = values.filter(e => e.payload !== 'entryA10').sort(Entry.compare) assert.deepStrictEqual(partialLog2.map(e => e.payload), expectedData3) - const partialLog3 = log.values.filter(e => e.payload !== 'entryB5').sort(Entry.compare) + const partialLog3 = values.filter(e => e.payload !== 'entryB5').sort(Entry.compare) assert.deepStrictEqual(partialLog3.map(e => e.payload), expectedData4) }) @@ -631,12 +651,14 @@ Object.keys(testAPIs).forEach((IPFS) => { const log = testLog.log const expectedData = testLog.expectedData - const fetchOrder = log.values.slice().sort(Entry.compare) + const values = await log.values() + const fetchOrder = values.slice().sort(Entry.compare) assert.deepStrictEqual(fetchOrder.map(e => e.payload), expectedData) let sorted for (let i = 0; i < 1000; i++) { - const randomOrder = log.values.slice().sort((a, b) => 0.5 - Math.random()) + const values = await log.values() + const randomOrder = values.slice().sort((a, b) => 0.5 - Math.random()) sorted = randomOrder.sort(Entry.compare) assert.deepStrictEqual(sorted.map(e => e.payload), expectedData) } @@ -646,7 +668,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const testLog = await LogCreator.createLogWithTwoHundredEntries(Log, ipfs, identities) const log = testLog.log const expectedData = testLog.expectedData - assert.deepStrictEqual(log.values.map(e => e.payload), expectedData) + const values = await log.values() + assert.deepStrictEqual(values.map(e => e.payload), expectedData) }) it('sorts entries according to custom tiebreaker function', async () => { @@ -655,7 +678,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const firstWriteWinsLog = new Log(ipfs, identities[0], { logId: 'X', sortFn: FirstWriteWins }) await firstWriteWinsLog.join(testLog.log) - assert.deepStrictEqual(firstWriteWinsLog.values.map(e => e.payload), + const firstWriteWinsLogValues = await firstWriteWinsLog.values() + assert.deepStrictEqual(firstWriteWinsLogValues.map(e => e.payload), firstWriteExpectedData) }) @@ -664,7 +688,14 @@ Object.keys(testAPIs).forEach((IPFS) => { const firstWriteWinsLog = new Log(ipfs, identities[0], { logId: 'X', sortFn: BadComparatorReturnsZero }) await firstWriteWinsLog.join(testLog.log) - assert.throws(() => firstWriteWinsLog.values, Error, 'Error Thrown') + + let err + try { + await firstWriteWinsLog.values() + } catch (e) { + err = e + } + assert.notStrictEqual(err, undefined) }) it('retrieves partially joined log deterministically - single next pointer', async () => { @@ -704,7 +735,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC0', 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(res.values.map(e => e.payload), first5) + const values = await res.values() + assert.deepStrictEqual(values.map(e => e.payload), first5) // First 11 res = await Log.fromMultihash(ipfs, testIdentity2, hash, { length: 11 }) @@ -716,7 +748,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC0', 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(res.values.map(e => e.payload), first11) + const values2 = await res.values() + assert.deepStrictEqual(values2.map(e => e.payload), first11) // All but one res = await Log.fromMultihash(ipfs, testIdentity2, hash, { length: 16 - 1 }) @@ -728,7 +761,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC0', 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(res.values.map(e => e.payload), all) + const values3 = await res.values() + assert.deepStrictEqual(values3.map(e => e.payload), all) }) it('retrieves partially joined log deterministically - multiple next pointers', async () => { @@ -768,7 +802,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC0', 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(res.values.map(e => e.payload), first5) + const values = await res.values() + assert.deepStrictEqual(values.map(e => e.payload), first5) // First 11 res = await Log.fromMultihash(ipfs, testIdentity2, hash, { length: 11 }) @@ -780,7 +815,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(res.values.map(e => e.payload), first11) + const values1 = await res.values() + assert.deepStrictEqual(values1.map(e => e.payload), first11) // All but one res = await Log.fromMultihash(ipfs, testIdentity2, hash, { length: 16 - 1 }) @@ -792,7 +828,8 @@ Object.keys(testAPIs).forEach((IPFS) => { 'entryC0', 'entryA7', 'entryA8', 'entryA9', 'entryA10' ] - assert.deepStrictEqual(res.values.map(e => e.payload), all) + const values2 = await res.values() + assert.deepStrictEqual(values2.map(e => e.payload), all) }) it('throws an error if ipfs is not defined', async () => { @@ -847,21 +884,24 @@ Object.keys(testAPIs).forEach((IPFS) => { const a = await Log.fromEntry(ipfs, testIdentity, last(items1), { length: -1 }) assert.strictEqual(a.length, amount) - assert.strictEqual(a.values[0].hash, items1[0].hash) + const values = await a.values() + assert.strictEqual(values[0].hash, items1[0].hash) }) it('returns all entries - including excluded entries', async () => { // One entry const a = await Log.fromEntry(ipfs, testIdentity, last(items1), { length: -1, exclude: [items1[0]] }) + const aValues = await a.values() assert.strictEqual(a.length, amount) - assert.strictEqual(a.values[0].hash, items1[0].hash) + assert.strictEqual(aValues[0].hash, items1[0].hash) // All entries const b = await Log.fromEntry(ipfs, testIdentity, last(items1), { length: -1, exclude: items1 }) + const bValues = await b.values() assert.strictEqual(b.length, amount) - assert.strictEqual(b.values[0].hash, items1[0].hash) + assert.strictEqual(bValues[0].hash, items1[0].hash) }) it('respects timeout parameter', async () => { @@ -873,7 +913,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const et = new Date().getTime() assert.strictEqual((et - st) >= timeout, true, '' + (et - st) + ' should be greater than timeout ' + timeout) assert.strictEqual(log.length, 1) - assert.deepStrictEqual(log.values.map(e => e.payload), [e.payload]) + const values = await log.values() + assert.deepStrictEqual(values.map(e => e.payload), [e.payload]) }) }) }) @@ -922,19 +963,22 @@ Object.keys(testAPIs).forEach((IPFS) => { json.heads = await Promise.all(json.heads.map(headHash => Entry.fromMultihash(ipfs, headHash))) const log = await Log.fromJSON(ipfs, testIdentity, json, { logId: 'A' }) assert.strictEqual(log.length, 5) - assert.deepStrictEqual(log.values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) + const values = await log.values() + assert.deepStrictEqual(values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) }) it('creates a log from v1 entry', async () => { const log = await Log.fromEntry(ipfs, testIdentity, v1Entries[v1Entries.length - 1], { logId: 'A' }) assert.strictEqual(log.length, 5) - assert.deepStrictEqual(log.values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) + const values = await log.values() + assert.deepStrictEqual(values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) }) it('creates a log from v1 entry hash', async () => { const log = await Log.fromEntryHash(ipfs, testIdentity, v1Entries[v1Entries.length - 1].hash, { logId: 'A' }) assert.strictEqual(log.length, 5) - assert.deepStrictEqual(log.values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) + const values = await log.values() + assert.deepStrictEqual(values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) }) it('creates a log from log hash of v1 entries', async () => { @@ -942,7 +986,8 @@ Object.keys(testAPIs).forEach((IPFS) => { const hash = await log1.toMultihash() const log = await Log.fromMultihash(ipfs, testIdentity, hash, { logId: 'A' }) assert.strictEqual(log.length, 5) - assert.deepStrictEqual(log.values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) + const values = await log.values() + assert.deepStrictEqual(values, v1Entries.map(e => Entry.toEntry(e, { includeHash: true }))) }) }) }) diff --git a/test/log-references.spec.js b/test/log-references.spec.js index df1d621f..e43d939f 100644 --- a/test/log-references.spec.js +++ b/test/log-references.spec.js @@ -77,14 +77,19 @@ Object.keys(testAPIs).forEach((IPFS) => { await log4.append(i.toString(), Math.pow(maxReferenceDistance, 4)) } - assert.strict.equal(log1.values[log1.length - 1].next.length, 1) - assert.strict.equal(log2.values[log2.length - 1].next.length, 1) - assert.strict.equal(log3.values[log3.length - 1].next.length, 1) - assert.strict.equal(log4.values[log4.length - 1].next.length, 1) - assert.strict.equal(log1.values[log1.length - 1].refs.length, 1) - assert.strict.equal(log2.values[log2.length - 1].refs.length, 2) - assert.strict.equal(log3.values[log3.length - 1].refs.length, 3) - assert.strict.equal(log4.values[log4.length - 1].refs.length, 4) + const values1 = await log1.values() + const values2 = await log2.values() + const values3 = await log3.values() + const values4 = await log4.values() + + assert.strict.equal(values1[log1.length - 1].next.length, 1) + assert.strict.equal(values2[log2.length - 1].next.length, 1) + assert.strict.equal(values3[log3.length - 1].next.length, 1) + assert.strict.equal(values4[log4.length - 1].next.length, 1) + assert.strict.equal(values1[log1.length - 1].refs.length, 1) + assert.strict.equal(values2[log2.length - 1].refs.length, 2) + assert.strict.equal(values3[log3.length - 1].refs.length, 3) + assert.strict.equal(values4[log4.length - 1].refs.length, 4) }) const inputs = [ @@ -119,31 +124,32 @@ Object.keys(testAPIs).forEach((IPFS) => { await log1.append((i + 1).toString(), referenceCount) } - assert.strict.equal(log1.values.length, input.amount) - assert.strict.equal(log1.values[log1.length - 1].clock.time, input.amount) + const values1 = await log1.values() + assert.strict.equal(values1.length, input.amount) + assert.strict.equal(values1[log1.length - 1].clock.time, input.amount) for (let k = 0; k < input.amount; k++) { const idx = log1.length - k - 1 - assert.strict.equal(log1.values[idx].clock.time, idx + 1) + assert.strict.equal(values1[idx].clock.time, idx + 1) // Check the first ref (distance 2) - if (log1.values[idx].refs.length > 0) { assert.strict.equal(log1.values[idx].refs[0], log1.values[idx - 2].hash) } + if (values1[idx].refs.length > 0) { assert.strict.equal(values1[idx].refs[0], values1[idx - 2].hash) } // Check the second ref (distance 2) - if (log1.values[idx].refs.length > 1 && idx > referenceCount) { assert.strict.equal(log1.values[idx].refs[1], log1.values[idx - 4].hash) } + if (values1[idx].refs.length > 1 && idx > referenceCount) { assert.strict.equal(values1[idx].refs[1], values1[idx - 4].hash) } // Check the third ref (distance 4) - if (log1.values[idx].refs.length > 2 && idx > referenceCount) { assert.strict.equal(log1.values[idx].refs[2], log1.values[idx - 8].hash) } + if (values1[idx].refs.length > 2 && idx > referenceCount) { assert.strict.equal(values1[idx].refs[2], values1[idx - 8].hash) } // Check the fourth ref (distance 8) - if (log1.values[idx].refs.length > 3 && idx > referenceCount) { assert.strict.equal(log1.values[idx].refs[3], log1.values[idx - 16].hash) } + if (values1[idx].refs.length > 3 && idx > referenceCount) { assert.strict.equal(values1[idx].refs[3], values1[idx - 16].hash) } // Check the fifth ref (distance 16) - if (log1.values[idx].refs.length > 4 && idx > referenceCount) { assert.strict.equal(log1.values[idx].refs[4], log1.values[idx - 32].hash) } + if (values1[idx].refs.length > 4 && idx > referenceCount) { assert.strict.equal(values1[idx].refs[4], values1[idx - 32].hash) } // Check the reference of each entry - if (idx > referenceCount) { assert.strict.equal(log1.values[idx].refs.length, refLength) } + if (idx > referenceCount) { assert.strict.equal(values1[idx].refs.length, refLength) } } } diff --git a/test/log.spec.js b/test/log.spec.js index 5355ea00..a43ef436 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -65,16 +65,17 @@ Object.keys(testAPIs).forEach((IPFS) => { const log = new Log(ipfs, testIdentity) assert.notStrictEqual(log._entryIndex, null) assert.notStrictEqual(log._headsIndex, null) + assert.notStrictEqual(log._hashIndex, new Map()) assert.notStrictEqual(log._id, null) assert.notStrictEqual(log.id, null) assert.notStrictEqual(log.clock, null) - assert.notStrictEqual(log.values, null) + // assert.notStrictEqual(log.values, new Promise(() => {})) //TODO assert.notStrictEqual(log.heads, null) - assert.notStrictEqual(log.tails, null) + // assert.notStrictEqual(log.tails, null) // TODO assert.notStrictEqual(log.tailCids, null) - assert.deepStrictEqual(log.values, []) + // assert.deepStrictEqual(log.values, []) // TODO assert.deepStrictEqual(log.heads, []) - assert.deepStrictEqual(log.tails, []) + // assert.deepStrictEqual(log.tails, []) // TODO }) it('throws an error if IPFS instance is not passed as an argument', () => { @@ -109,10 +110,11 @@ Object.keys(testAPIs).forEach((IPFS) => { const three = await Entry.create(ipfs, testIdentity, 'A', 'entryC', [], new Clock('C', 0)) const log = new Log(ipfs, testIdentity, { logId: 'A', entries: [one, two, three] }) + const values = await log.values() assert.strictEqual(log.length, 3) - assert.strictEqual(log.values[0].payload, 'entryA') - assert.strictEqual(log.values[1].payload, 'entryB') - assert.strictEqual(log.values[2].payload, 'entryC') + assert.strictEqual(values[0].payload, 'entryA') + assert.strictEqual(values[1].payload, 'entryB') + assert.strictEqual(values[2].payload, 'entryC') }) it('sets heads if given as params', async () => { @@ -191,8 +193,9 @@ Object.keys(testAPIs).forEach((IPFS) => { await log.append('five') }) - it('returns a nicely formatted string', () => { - assert.strictEqual(log.toString(), expectedData) + it('returns a nicely formatted string', async () => { + const logString = await log.toString() + assert.strictEqual(logString, expectedData) }) }) @@ -204,13 +207,14 @@ Object.keys(testAPIs).forEach((IPFS) => { await log.append('one') }) - it('returns an Entry', () => { - const entry = log.get(log.values[0].hash) + it('returns an Entry', async () => { + const values = await log.values() + const entry = await log.get(values[0].hash) assert.deepStrictEqual(entry.hash, 'zdpuAoFzNYcuuQHk1gLcB8fomHGrqT9k1uQeAvewZJ1cSYrms') }) - it('returns undefined when Entry is not in the log', () => { - const entry = log.get('QmFoo') + it('returns undefined when Entry is not in the log', async () => { + const entry = await log.get('QmFoo') assert.deepStrictEqual(entry, undefined) }) }) @@ -224,16 +228,19 @@ Object.keys(testAPIs).forEach((IPFS) => { }) it('changes identity', async () => { - assert.strictEqual(log.values[0].clock.id, testIdentity.publicKey) - assert.strictEqual(log.values[0].clock.time, 1) + let values = await log.values() + assert.strictEqual(values[0].clock.id, testIdentity.publicKey) + assert.strictEqual(values[0].clock.time, 1) log.setIdentity(testIdentity2) await log.append('two') - assert.strictEqual(log.values[1].clock.id, testIdentity2.publicKey) - assert.strictEqual(log.values[1].clock.time, 2) + values = await log.values() + assert.strictEqual(values[1].clock.id, testIdentity2.publicKey) + assert.strictEqual(values[1].clock.time, 2) log.setIdentity(testIdentity3) await log.append('three') - assert.strictEqual(log.values[2].clock.id, testIdentity3.publicKey) - assert.strictEqual(log.values[2].clock.time, 3) + values = await log.values() + assert.strictEqual(values[2].clock.id, testIdentity3.publicKey) + assert.strictEqual(values[2].clock.time, 3) }) }) @@ -304,8 +311,8 @@ Object.keys(testAPIs).forEach((IPFS) => { ] } - it('returns the log snapshot', () => { - const snapshot = log.toSnapshot() + it('returns the log snapshot', async () => { + const snapshot = await log.toSnapshot() assert.strictEqual(snapshot.id, expectedData.id) assert.strictEqual(snapshot.heads.length, expectedData.heads.length) assert.strictEqual(snapshot.heads[0].hash, expectedData.heads[0]) @@ -406,23 +413,25 @@ Object.keys(testAPIs).forEach((IPFS) => { await log.append('one') const hash = await log.toMultihash() const res = await Log.fromMultihash(ipfs, testIdentity, hash, -1) + const values = await res.values() assert.strictEqual(JSON.stringify(res.toJSON()), JSON.stringify(expectedData)) assert.strictEqual(res.length, 1) - assert.strictEqual(res.values[0].payload, 'one') - assert.strictEqual(res.values[0].clock.id, testIdentity.publicKey) - assert.strictEqual(res.values[0].clock.time, 1) + assert.strictEqual(values[0].payload, 'one') + assert.strictEqual(values[0].clock.id, testIdentity.publicKey) + assert.strictEqual(values[0].clock.time, 1) }) it('creates a log from ipfs CID - three entries', async () => { const hash = await log.toMultihash() const res = await Log.fromMultihash(ipfs, testIdentity, hash, -1) + const values = await res.values() assert.strictEqual(res.length, 3) - assert.strictEqual(res.values[0].payload, 'one') - assert.strictEqual(res.values[0].clock.time, 1) - assert.strictEqual(res.values[1].payload, 'two') - assert.strictEqual(res.values[1].clock.time, 2) - assert.strictEqual(res.values[2].payload, 'three') - assert.strictEqual(res.values[2].clock.time, 3) + assert.strictEqual(values[0].payload, 'one') + assert.strictEqual(values[0].clock.time, 1) + assert.strictEqual(values[1].payload, 'two') + assert.strictEqual(values[1].clock.time, 2) + assert.strictEqual(values[2].payload, 'three') + assert.strictEqual(values[2].clock.time, 3) }) it('creates a log from ipfs multihash (backwards compat)', async () => { @@ -434,21 +443,24 @@ Object.keys(testAPIs).forEach((IPFS) => { await log.append('one') const multihash = await log.toMultihash() const res = await Log.fromMultihash(ipfs, testIdentity, multihash, { length: -1 }) + const values = await res.values() assert.strictEqual(JSON.stringify(res.toJSON()), JSON.stringify(expectedData)) assert.strictEqual(res.length, 1) - assert.strictEqual(res.values[0].payload, 'one') - assert.strictEqual(res.values[0].clock.id, testIdentity.publicKey) - assert.strictEqual(res.values[0].clock.time, 1) + assert.strictEqual(values[0].payload, 'one') + assert.strictEqual(values[0].clock.id, testIdentity.publicKey) + assert.strictEqual(values[0].clock.time, 1) }) it('has the right sequence number after creation and appending', async () => { const hash = await log.toMultihash() const res = await Log.fromMultihash(ipfs, testIdentity, hash, { length: -1 }) + let values = await res.values() assert.strictEqual(res.length, 3) await res.append('four') + values = await res.values() assert.strictEqual(res.length, 4) - assert.strictEqual(res.values[3].payload, 'four') - assert.strictEqual(res.values[3].clock.time, 4) + assert.strictEqual(values[3].payload, 'four') + assert.strictEqual(values[3].clock.time, 4) }) it('creates a log from ipfs CID that has three heads', async () => { @@ -567,7 +579,7 @@ Object.keys(testAPIs).forEach((IPFS) => { await log.append(i.toString()) } - const items = log.values + const items = await log.values() let i = 0 const loadProgressCallback = (hash, entry, depth) => { assert.notStrictEqual(entry, null) @@ -582,13 +594,14 @@ Object.keys(testAPIs).forEach((IPFS) => { const result = await Log.fromMultihash(ipfs, testIdentity, hash, { length: -1, exclude: [], onProgressCallback: loadProgressCallback }) + const values = await result.values() // Make sure the onProgress callback was called for each entry assert.strictEqual(i, amount) // Make sure the log entries are correct ones - assert.strictEqual(result.values[0].clock.time, 1) - assert.strictEqual(result.values[0].payload, '0') - assert.strictEqual(result.values[result.length - 1].clock.time, 100) - assert.strictEqual(result.values[result.length - 1].payload, '99') + assert.strictEqual(values[0].clock.time, 1) + assert.strictEqual(values[0].payload, '0') + assert.strictEqual(values[result.length - 1].clock.time, 100) + assert.strictEqual(values[result.length - 1].payload, '99') }) }) @@ -649,16 +662,18 @@ Object.keys(testAPIs).forEach((IPFS) => { describe('values', () => { it('returns all entries in the log', async () => { const log = new Log(ipfs, testIdentity) - assert.strictEqual(log.values instanceof Array, true) + let values = await log.values() + assert.strictEqual(values instanceof Array, true) assert.strictEqual(log.length, 0) await log.append('hello1') await log.append('hello2') await log.append('hello3') - assert.strictEqual(log.values instanceof Array, true) + values = await log.values() + assert.strictEqual(values instanceof Array, true) assert.strictEqual(log.length, 3) - assert.strictEqual(log.values[0].payload, 'hello1') - assert.strictEqual(log.values[1].payload, 'hello2') - assert.strictEqual(log.values[2].payload, 'hello3') + assert.strictEqual(values[0].payload, 'hello1') + assert.strictEqual(values[1].payload, 'hello2') + assert.strictEqual(values[2].payload, 'hello3') }) }) }) diff --git a/test/replicate.spec.js b/test/replicate.spec.js index 652bb6a0..fa71c9be 100644 --- a/test/replicate.spec.js +++ b/test/replicate.spec.js @@ -150,19 +150,21 @@ Object.keys(testAPIs).forEach((IPFS) => { await result.join(log1) await result.join(log2) + const values = await result.values() + assert.strictEqual(buffer1.length, amount) assert.strictEqual(buffer2.length, amount) assert.strictEqual(result.length, amount * 2) assert.strictEqual(log1.length, amount) assert.strictEqual(log2.length, amount) - assert.strictEqual(result.values[0].payload, 'A1') - assert.strictEqual(result.values[1].payload, 'B1') - assert.strictEqual(result.values[2].payload, 'A2') - assert.strictEqual(result.values[3].payload, 'B2') - assert.strictEqual(result.values[99].payload, 'B50') - assert.strictEqual(result.values[100].payload, 'A51') - assert.strictEqual(result.values[198].payload, 'A100') - assert.strictEqual(result.values[199].payload, 'B100') + assert.strictEqual(values[0].payload, 'A1') + assert.strictEqual(values[1].payload, 'B1') + assert.strictEqual(values[2].payload, 'A2') + assert.strictEqual(values[3].payload, 'B2') + assert.strictEqual(values[99].payload, 'B50') + assert.strictEqual(values[100].payload, 'A51') + assert.strictEqual(values[198].payload, 'A100') + assert.strictEqual(values[199].payload, 'B100') }) }) }) diff --git a/test/signed-log.spec.js b/test/signed-log.spec.js index 7e925673..b3077cb0 100644 --- a/test/signed-log.spec.js +++ b/test/signed-log.spec.js @@ -87,8 +87,9 @@ Object.keys(testAPIs).forEach((IPFS) => { it('entries contain an identity', async () => { const log = new Log(ipfs, testIdentity, { logId: 'A' }) await log.append('one') - assert.notStrictEqual(log.values[0].sig, null) - assert.deepStrictEqual(log.values[0].identity, testIdentity.toJSON()) + const values = await log.values() + assert.notStrictEqual(values[0].sig, null) + assert.deepStrictEqual(values[0].identity, testIdentity.toJSON()) }) it('doesn\'t sign entries when identity is not defined', async () => { @@ -116,10 +117,11 @@ Object.keys(testAPIs).forEach((IPFS) => { throw e } + const values1 = await log1.values() assert.strictEqual(err, undefined) assert.strictEqual(log1.id, 'A') - assert.strictEqual(log1.values.length, 1) - assert.strictEqual(log1.values[0].payload, 'one') + assert.strictEqual(values1.length, 1) + assert.strictEqual(values1[0].payload, 'one') }) it('throws an error if log is signed but trying to merge with an entry that doesn\'t have public signing key', async () => { @@ -130,7 +132,8 @@ Object.keys(testAPIs).forEach((IPFS) => { try { await log1.append('one') await log2.append('two') - delete log2.values[0].key + const values2 = await log2.values() + delete values2[0].key await log1.join(log2) } catch (e) { err = e.toString() @@ -146,7 +149,8 @@ Object.keys(testAPIs).forEach((IPFS) => { try { await log1.append('one') await log2.append('two') - delete log2.values[0].sig + const values2 = await log2.values() + delete values2[0].sig await log1.join(log2) } catch (e) { err = e.toString() @@ -162,16 +166,21 @@ Object.keys(testAPIs).forEach((IPFS) => { try { await log1.append('one') await log2.append('two') - log2.values[0].sig = log1.values[0].sig + const values1 = await log1.values() + const values2 = await log2.values() + values2[0].sig = values1[0].sig await log1.join(log2) } catch (e) { err = e.toString() } - const entry = log2.values[0] + const values1 = await log1.values() + const values2 = await log2.values() + + const entry = values2[0] assert.strictEqual(err, `Error: Could not validate signature "${entry.sig}" for entry "${entry.hash}" and key "${entry.key}"`) - assert.strictEqual(log1.values.length, 1) - assert.strictEqual(log1.values[0].payload, 'one') + assert.strictEqual(values1.length, 1) + assert.strictEqual(values1[0].payload, 'one') }) it('throws an error if entry doesn\'t have append access', async () => {