From 4228b6f87a8e65a003a96e547ba9fbe3b52afedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Cruz?= Date: Tue, 15 Jan 2019 16:37:55 +0000 Subject: [PATCH] Remove unused LogIO.fromMultihash method --- dist/ipfslog.min.js | 31 ++- lib/es5/entry-io.js | 98 ++++--- lib/es5/entry.js | 300 ++++++++++++++-------- lib/es5/log-io.js | 319 +++++++++++++---------- lib/es5/log-sorting.js | 34 +-- lib/es5/log.js | 520 +++++++++++++++++++++----------------- lib/es5/utils/dag-node.js | 212 ++++++++++++++++ lib/es5/utils/index.js | 5 +- src/log-io.js | 14 - 9 files changed, 998 insertions(+), 535 deletions(-) create mode 100644 lib/es5/utils/dag-node.js diff --git a/dist/ipfslog.min.js b/dist/ipfslog.min.js index e49023dd..00f84626 100644 --- a/dist/ipfslog.min.js +++ b/dist/ipfslog.min.js @@ -1,9 +1,36 @@ -var Log=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=6)}([function(t,r,e){"use strict";class n{constructor(t,r){this.id=t,this.time=r||0}tick(){return new n(this.id,++this.time)}merge(t){return this.time=Math.max(this.time,t.time),new n(this.id,this.time)}clone(){return new n(this.id,this.time)}static compare(t,r){var e=t.time-r.time;return 0===e&&t.id!==r.id?t.idnew Error("Ipfs instance not defined");class s{static async create(t,r,e,a,h=[],u){if(!i(t))throw o();if(!i(r))throw new Error("Identity is required, cannot create entry");if(!i(e))throw new Error("Entry requires an id");if(!i(a))throw new Error("Entry requires data");if(!i(h)||!Array.isArray(h))throw new Error("'next' argument is not an array");const c={hash:null,id:e,payload:a,next:h.filter(i).map(t=>t.hash?t.hash:t),v:0,clock:u||new n(r.publicKey)},f=await r.provider.sign(r,s.toBuffer(c));return c.key=r.publicKey,c.identity=r.toJSON(),c.sig=f,c.hash=await s.toMultihash(t,c),c}static async verify(t,r){if(!t)throw new Error("Identity-provider is required, cannot verify entry");if(!s.isEntry(r))throw new Error("Invalid Log entry");if(!r.key)throw new Error("Entry doesn't have a key");if(!r.sig)throw new Error("Entry doesn't have a signature");const e=Object.assign({},{hash:null,id:r.id,payload:r.payload,next:r.next,v:r.v,clock:new n(r.clock.id,r.clock.time)});return t.verify(r.sig,r.key,s.toBuffer(e))}static toBuffer(t){return r.from(JSON.stringify(t))}static async toMultihash(t,r){if(!t)throw o();if(!(t=>t.id&&t.clock&&t.next&&t.payload&&t.v>=0)(r))throw new Error("Invalid object format, cannot generate entry multihash");const e={hash:null,id:r.id,payload:r.payload,next:r.next,v:r.v,clock:r.clock};r.key&&Object.assign(e,{key:r.key}),r.identity&&Object.assign(e,{identity:r.identity}),r.sig&&Object.assign(e,{sig:r.sig});const n=s.toBuffer(e);return(await t.object.put(n)).toJSON().multihash}static async fromMultihash(t,r){if(!t)throw o();if(!r)throw new Error(`Invalid hash: ${r}`);const e=await t.object.get(r,{enc:"base58"}),i=JSON.parse(e.toJSON().data);let s={hash:r,id:i.id,payload:i.payload,next:i.next,v:i.v,clock:new n(i.clock.id,i.clock.time)};return i.key&&Object.assign(s,{key:i.key}),i.identity&&Object.assign(s,{identity:i.identity}),i.sig&&Object.assign(s,{sig:i.sig}),s}static isEntry(t){return t&&void 0!==t.id&&void 0!==t.next&&void 0!==t.hash&&void 0!==t.payload&&void 0!==t.v&&void 0!==t.clock}static compare(t,r){var e=n.compare(t.clock,r.clock);return 0===e?t.clock.id-1}static findChildren(t,r){for(var e=[],n=r.find(r=>s.isParent(t,r)),i=t;n;)e.push(n),i=n,n=r.find(t=>s.isParent(i,t));return e=e.sort((t,r)=>t.clock.time>r.clock.time)}}t.exports=s}).call(this,e(3).Buffer)},function(t,r,e){"use strict";const n=e(12),i=e(13),o=e(14);t.exports={difference:n,findUniques:i,isDefined:o}},function(t,r,e){"use strict";(function(t){ +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=30)}([function(e,t,n){"use strict";(function(e){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ -var n=e(8),i=e(9),o=e(10);function s(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,r){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|t}function y(t,r){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return L(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return F(t).length;default:if(n)return L(t).length;r=(""+r).toLowerCase(),n=!0}}function w(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function g(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=h.from(r,n)),h.isBuffer(r))return 0===r.length?-1:d(t,r,e,n,i);if("number"==typeof r)return r&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):d(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function d(t,r,e,n,i){var o,s=1,a=t.length,h=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;s=2,a/=2,h/=2,e/=2}function u(t,r){return 1===s?t[r]:t.readUInt16BE(r*s)}if(i){var c=-1;for(o=e;oa&&(e=a-h),o=e;o>=0;o--){for(var f=!0,l=0;li&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var s=0;s>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function R(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function k(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:u>223?3:u>191?2:1;if(i+f<=e)switch(f){case 1:u<128&&(c=u);break;case 2:128==(192&(o=t[i+1]))&&(h=(31&u)<<6|63&o)>127&&(c=h);break;case 3:o=t[i+1],s=t[i+2],128==(192&o)&&128==(192&s)&&(h=(15&u)<<12|(63&o)<<6|63&s)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:o=t[i+1],s=t[i+2],a=t[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(h=(15&u)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&h<1114112&&(c=h)}null===c?(c=65533,f=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),i+=f}return function(t){var r=t.length;if(r<=T)return String.fromCharCode.apply(String,t);var e="",n=0;for(;nthis.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return S(this,r,e);case"utf8":case"utf-8":return k(this,r,e);case"ascii":return P(this,r,e);case"latin1":case"binary":return O(this,r,e);case"base64":return R(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},h.prototype.equals=function(t){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===h.compare(this,t)},h.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},h.prototype.compare=function(t,r,e,n,i){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),s=(e>>>=0)-(r>>>=0),a=Math.min(o,s),u=this.slice(n,i),c=t.slice(r,e),f=0;fi)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,r,e);case"utf8":case"utf-8":return E(this,t,r,e);case"ascii":return m(this,t,r,e);case"latin1":case"binary":return _(this,t,r,e);case"base64":return A(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return b(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var T=4096;function P(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;in)&&(e=n);for(var i="",o=r;oe)throw new RangeError("Trying to access beyond buffer length")}function x(t,r,e,n,i,o){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||rt.length)throw new RangeError("Index out of range")}function M(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i>>8*(n?i:1-i)}function N(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i>>8*(n?i:3-i)&255}function D(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function I(t,r,e,n,o){return o||D(t,0,e,4),i.write(t,r,e,n,23,4),e+4}function Y(t,r,e,n,o){return o||D(t,0,e,8),i.write(t,r,e,n,52,8),e+8}h.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r0&&(i*=256);)n+=this[t+--r]*i;return n},h.prototype.readUInt8=function(t,r){return r||U(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,r){return r||U(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,r){return r||U(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,r){return r||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,r){return r||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},h.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},h.prototype.readInt8=function(t,r){return r||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,r){r||U(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},h.prototype.readInt16BE=function(t,r){r||U(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},h.prototype.readInt32LE=function(t,r){return r||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,r){return r||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,r){return r||U(t,4,this.length),i.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,r){return r||U(t,4,this.length),i.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,r){return r||U(t,8,this.length),i.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,r){return r||U(t,8,this.length),i.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||x(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o=0&&(o*=256);)this[r+i]=t/o&255;return r+e},h.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},h.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):M(this,t,r,!0),r+2},h.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):M(this,t,r,!1),r+2},h.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):N(this,t,r,!0),r+4},h.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):N(this,t,r,!1),r+4},h.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);x(this,t,r,e,i-1,-i)}var o=0,s=1,a=0;for(this[r]=255&t;++o>0)-a&255;return r+e},h.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);x(this,t,r,e,i-1,-i)}var o=e-1,s=1,a=0;for(this[r+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[r+o+1]&&(a=1),this[r+o]=(t/s>>0)-a&255;return r+e},h.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},h.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):M(this,t,r,!0),r+2},h.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):M(this,t,r,!1),r+2},h.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):N(this,t,r,!0),r+4},h.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||x(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):N(this,t,r,!1),r+4},h.prototype.writeFloatLE=function(t,r,e){return I(this,t,r,!0,e)},h.prototype.writeFloatBE=function(t,r,e){return I(this,t,r,!1,e)},h.prototype.writeDoubleLE=function(t,r,e){return Y(this,t,r,!0,e)},h.prototype.writeDoubleBE=function(t,r,e){return Y(this,t,r,!1,e)},h.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--i)t[i+r]=this[i+e];else if(o<1e3||!h.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function F(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(j,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function J(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}}).call(this,e(7))},function(t,r,e){"use strict";t.exports=((t,r,e)=>new Promise((n,i)=>{if(e=Object.assign({concurrency:1/0},e),"function"!=typeof r)throw new TypeError("Mapper function is required");const o=e.concurrency;if(!("number"==typeof o&&o>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${o}\` (${typeof o})`);const s=[],a=t[Symbol.iterator]();let h=!1,u=!1,c=0,f=0;const l=()=>{if(h)return;const t=a.next(),e=f;if(f++,t.done)return u=!0,void(0===c&&n(s));c++,Promise.resolve(t.value).then(t=>r(t,e)).then(t=>{s[e]=t,c--,l()},t=>{h=!0,i(t)})};for(let t=0;tnew Error("IPFS instance not defined"),LogNotDefinedError:()=>new Error("Log instance not defined"),NotALogError:()=>new Error("Given argument is not an instance of Log"),CannotJoinWithDifferentId:()=>new Error("Can't join logs with different IDs")}},function(t,r,e){"use strict";(function(r){const n=e(4),i=e(11),o=e(1),s=e(15),a=e(5),h=e(0),{LastWriteWins:u,NoZeroes:c}=e(18),f=e(19),{isDefined:l,findUniques:p}=e(2),y=()=>(new Date).getTime().toString(),w=t=>t.hash,g=(t,r)=>t.concat(r),d=t=>t.next,v=(t,r)=>Math.max(t,r.clock.time),E=(t,r)=>(t[r.hash]=r,t);class m extends i{constructor(t,r,e,n,i,o,s,f){if(!l(t))throw a.IPFSNotDefinedError();if(!l(r))throw new Error("Access controller is required");if(!l(e))throw new Error("Identity is required");if(l(i)&&!Array.isArray(i))throw new Error("'entries' argument must be an array of Entry instances");if(l(o)&&!Array.isArray(o))throw new Error("'heads' argument must be an array");l(f)||(f=u),super(),this._sortFn=c(f),this._storage=t,this._id=n||y(),this._access=r,this._identity=e,i=i||[],this._entryIndex=i.reduce(E,{}),o=o||m.findHeads(i),this._headsIndex=o.reduce(E,{}),this._nextsIndex={};i.forEach(t=>t.next.forEach(r=>this._nextsIndex[r]=t.hash)),this._length=i.length;const p=Math.max(s?s.time:0,this.heads.reduce(v,0));this._clock=new h(this._identity.publicKey,p)}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 m.findTails(this.values)}get tailHashes(){return m.findTailHashes(this.values)}get(t){return this._entryIndex[t]}has(t){return void 0!==this._entryIndex[t.hash||t]}traverse(t,r=-1){var e=t.sort(this._sortFn).reverse();let n={},i={},o=0;const s=t=>this.get(t),a=t=>{t&&!n[t.hash]&&(e=[t,...e].sort(this._sortFn).reverse(),n[t.hash]=!0)};for(;e.length>0&&(-1===r||othis._nextsIndex[t]=s.hash),this._headsIndex={},this._headsIndex[s.hash]=s,this._length++,s}async join(t,r=-1){if(!l(t))throw a.LogNotDefinedError();if(!m.isLog(t))throw a.NotALogError();if(this.id!==t.id)return;const e=m.difference(t,this),i=this._identity.provider,s=Object.values(e);await n(s,async t=>{if(!await this._access.canAppend(t,i))throw new Error(`Could not append entry, key "${t.identity.id}" is not allowed to write to the log`)},{concurrency:1}),await n(s,async t=>{const r=await o.verify(i,t),e=t.identity?t.identity.publicKey:t.key;if(!r)throw new Error(`Could not validate signature "${t.sig}" for entry "${t.hash}" and key "${e}"`)},{concurrency:1});Object.values(e).forEach(t=>{this.get(t.hash)||this._length++,t.next.forEach(r=>this._nextsIndex[r]=t.hash)}),this._entryIndex=Object.assign(this._entryIndex,e);const u=Object.values(e).map(d).reduce(g,[]),c=m.findHeads(Object.values(Object.assign({},this._headsIndex,t._headsIndex))).filter(t=>!u.find(r=>r===t.hash)).filter(t=>!this._nextsIndex[t.hash]).reduce(E,{});if(this._headsIndex=c,r>-1){let t=this.values;t=t.slice(-r),this._entryIndex=t.reduce(E,{}),this._headsIndex=m.findHeads(t),this._length=Object.values(this._entryIndex).length}const f=Object.values(this._headsIndex).reduce(v,0);return this._clock=new h(this.clock.id,Math.max(this.clock.time,f)),this}toJSON(){return{id:this.id,heads:this.heads.sort(this._sortFn).reverse().map(w)}}toSnapshot(){return{id:this.id,heads:this.heads,values:this.values}}toBuffer(){return r.from(JSON.stringify(this.toJSON()))}toString(t){return this.values.slice().reverse().map((r,e)=>{const n=o.findChildren(r,this.values).length;let i=new Array(Math.max(n-1,0));return i=n>1?i.fill(" "):i,(i=n>0?i.concat(["└─"]):i).join("")+(t?t(r.payload):r.payload)}).join("\n")}static isLog(t){return void 0!==t.id&&void 0!==t.heads&&void 0!==t._entryIndex}toMultihash(){return s.toMultihash(this._storage,this)}static async fromMultihash(t,r,e,n,i=-1,o,h){if(!l(t))throw a.IPFSNotDefinedError();if(!l(n))throw new Error(`Invalid hash: ${n}`);const u=await s.fromMultihash(t,n,i,o,h);return new m(t,r,e,u.id,u.values,u.heads,u.clock)}static async fromEntryHash(t,r,e,n,i,o=-1,h,u){if(!l(t))throw a.IPFSNotDefinedError();if(!l(n))throw new Error("'hash' must be defined");const c=await s.fromEntryHash(t,n,i,o,h,u);return new m(t,r,e,i,c.values)}static async fromJSON(t,r,e,n,i=-1,o,h){if(!l(t))throw a.IPFSNotDefinedError();const u=await s.fromJSON(t,n,i,o,h);return new m(t,r,e,u.id,u.values)}static async fromEntry(t,r,e,n,i=-1,o,h){if(!l(t))throw a.IPFSNotDefinedError();if(!l(n))throw new Error("'sourceEntries' must be defined");const u=await s.fromEntry(t,n,i,o,h);return new m(t,r,e,u.id,u.values)}static findHeads(t){var r=t.reduce((t,r,e,n)=>{return r.next.forEach(e=>t[e]=r.hash),t},{});return t.filter(t=>void 0===r[t.hash]).sort((t,r)=>t.clock.id>r.clock.id)}static findTails(t){var r={},e=[],n={},i=[];t.forEach(t=>{0===t.next.length&&e.push(t);t.next.forEach(e=>{r[e]||(r[e]=[]),r[e].push(t)}),i=i.concat(t.next),n[t.hash]=!0});const s=i.filter(t=>void 0===n[t]).map(t=>r[t]).reduce((t,r,e,n)=>t.concat(p(r,"hash")),[]).concat(e);return p(s,"hash").sort(o.compare)}static findTailHashes(t){var r={};return t.forEach(t=>r[t.hash]=!0),t.reduce((t,e,n,i)=>{return e.next.reverse().forEach(e=>{void 0===r[e]&&t.splice(0,0,e)}),t},[])}static difference(t,r){let e=Object.keys(t._headsIndex),n={},i={};const o=t=>{n[t]||r.get(t)||(e.push(t),n[t]=!0)};for(;e.length>0;){const s=e.shift(),a=t.get(s);a&&!r.get(s)&&a.id===r.id&&(i[a.hash]=a,n[a.hash]=!0,a.next.forEach(o))}return i}}t.exports=m,t.exports.AccessController=f}).call(this,e(3).Buffer)},function(t,r){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";r.byteLength=function(t){var r=u(t),e=r[0],n=r[1];return 3*(e+n)/4-n},r.toByteArray=function(t){for(var r,e=u(t),n=e[0],s=e[1],a=new o(function(t,r,e){return 3*(r+e)/4-e}(0,n,s)),h=0,c=s>0?n-4:n,f=0;f>16&255,a[h++]=r>>8&255,a[h++]=255&r;2===s&&(r=i[t.charCodeAt(f)]<<2|i[t.charCodeAt(f+1)]>>4,a[h++]=255&r);1===s&&(r=i[t.charCodeAt(f)]<<10|i[t.charCodeAt(f+1)]<<4|i[t.charCodeAt(f+2)]>>2,a[h++]=r>>8&255,a[h++]=255&r);return a},r.fromByteArray=function(t){for(var r,e=t.length,i=e%3,o=[],s=0,a=e-i;sa?a:s+16383));1===i?(r=t[e-1],o.push(n[r>>2]+n[r<<4&63]+"==")):2===i&&(r=(t[e-2]<<8)+t[e-1],o.push(n[r>>10]+n[r>>4&63]+n[r<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=s.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function c(t,r,e){for(var i,o,s=[],a=r;a>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,r){r.read=function(t,r,e,n,i){var o,s,a=8*i-n-1,h=(1<>1,c=-7,f=e?i-1:0,l=e?-1:1,p=t[r+f];for(f+=l,o=p&(1<<-c)-1,p>>=-c,c+=a;c>0;o=256*o+t[r+f],f+=l,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=256*s+t[r+f],f+=l,c-=8);if(0===o)o=1-u;else{if(o===h)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=u}return(p?-1:1)*s*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var s,a,h,u=8*o-i-1,c=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,y=n?1:-1,w=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(a=isNaN(r)?1:0,s=c):(s=Math.floor(Math.log(r)/Math.LN2),r*(h=Math.pow(2,-s))<1&&(s--,h*=2),(r+=s+f>=1?l/h:l*Math.pow(2,1-f))*h>=2&&(s++,h/=2),s+f>=c?(a=0,s=c):s+f>=1?(a=(r*h-1)*Math.pow(2,i),s+=f):(a=r*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[e+p]=255&a,p+=y,a/=256,i-=8);for(s=s<0;t[e+p]=255&s,p+=y,s/=256,u-=8);t[e+p-y]|=128*w}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r,e){"use strict";t.exports=class{constructor(t){}append(t){}merge(t){}get(t){}has(t){}get values(){}get length(){}}},function(t,r,e){"use strict";t.exports=function(t,r,e){var n={},i={};return t.forEach(t=>i[e?t[e]:t]=!0),r.reduce((t,r)=>{var o=void 0!==i[e?r[e]:r],s=void 0!==n[e?r[e]:r];return o||s||(t.push(r),n[e?r[e]:r]=!0),t},[])}},function(t,r,e){"use strict";t.exports=function(t,r){let e={};return t.forEach(t=>e[r?t[r]:t]=t),Object.keys(e).map(t=>e[t])}},function(t,r,e){"use strict";t.exports=(t=>null!=t)},function(t,r,e){"use strict";const n=e(1),i=e(16),o=e(0),s=e(5),{isDefined:a,findUniques:h,difference:u}=e(2),c=(t,r)=>t.slice(t.length-r,t.length);t.exports=class{static async toMultihash(t,r){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw s.LogNotDefinedError();if(r.values.length<1)throw new Error("Can't serialize an empty log");return(await t.object.put(r.toBuffer())).toJSON().multihash}static async fromMultihash(t,r,e=-1,h,u){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw new Error(`Invalid hash: ${r}`);const c=await t.object.get(r,{enc:"base58"}),f=JSON.parse(c.toJSON().data);if(!f.heads||!f.id)throw s.NotALogError();const l=await i.fetchAll(t,f.heads,e,h,null,u),p=l.reduce((t,r)=>r.clock.time>t.time?new o(r.clock.id,r.clock.time):t,new o(f.id)),y=l.slice().sort(n.compare),w=y.filter(t=>f.heads.includes(t.hash));return{id:f.id,values:y,heads:w,clock:p}}static async fromEntryHash(t,r,e,n=-1,o,h){if(!a(t))throw s.IpfsNotDefinedError();if(!a(r))throw new Error("'entryHash' must be defined");const u=Array.isArray(r)?r:[r];n=n>-1?Math.max(n,1):n;const f=o,l=await i.fetchParallel(t,u,n,f,null,null,h);return{values:n>-1?c(l,n):l}}static async fromJSON(t,r,e=-1,o,h){if(!a(t))throw s.IPFSNotDefinedError();const u=r.heads.map(t=>t.hash),c=(await i.fetchParallel(t,u,e,[],16,o,h)).slice().sort(n.compare);return{id:r.id,values:c,heads:r.heads}}static async fromEntry(t,r,e=-1,o,c){if(!a(t))throw s.IPFSNotDefinedError();if(!a(r))throw new Error("'sourceEntries' must be defined");if(!Array.isArray(r)&&!n.isEntry(r))throw new Error("'sourceEntries' argument must be an array of Entry instances or a single Entry");Array.isArray(r)||(r=[r]),e=e>-1?Math.max(e,r.length):e;const f=o?o.map(t=>t.hash?t.hash:t):o,l=r.map(t=>t.hash),p=await i.fetchParallel(t,l,e,f,null,null,c),y=r.concat(p),w=h(y,"hash").sort(n.compare),g=w.slice(e>-1?-e:-w.length),d=((t,r)=>{var e=t.slice(r.length,t.length);return r.concat(e)})(g,u(g,r,"hash"));return{id:d[d.length-1].id,values:d}}}},function(t,r,e){"use strict";const n=e(17),i=e(4),o=e(1);class s{static async fetchParallel(t,r,e,n=[],o,a,h){const u=(t,r)=>t.concat(r);return o=Math.max(o||r.length,1),(t=>t.reduce(u,[]))(await i(r,r=>s.fetchAll(t,r,e,n,a,h),{concurrency:o}))}static async fetchAll(t,r,e,i=[],s=null,a){let h=[],u={},c=Array.isArray(r)?r.slice():[r];const f=t=>c.push(t);(i=i&&Array.isArray(i)?i:[]).forEach(t=>u[t.hash]=t);return await n(()=>c.length>0&&(h.length{const r=c.shift();return u[r]?Promise.resolve():new Promise(async(e,n)=>{const i=s?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${r}', request timed out (${s}ms)`),e()},s):null;try{(t=>{clearTimeout(i),o.isEntry(t)&&(t.next.forEach(f),h.push(t),u[r]=t,a&&a(r,t,h.length))})(await o.fromMultihash(t,r)),e()}catch(t){n(t)}})}),h}}t.exports=s},function(t,r,e){"use strict";const n=t=>new Promise(r=>{r(t())});t.exports=((t,r)=>n(function e(){if(t())return n(r).then(e)}))},function(t,r,e){"use strict";const n=e(0);function i(t,r,e){const i=n.compare(t.clock,r.clock);return 0===i?e(t,r):i}function o(t,r,e){return t.clock.id===r.clock.id?e(t,r):t.clock.idt,n=(t,r)=>o(t,r,e);return((t,r)=>i(t,r,n))(t,r)},r.NoZeroes=function(t){const r=`Your log's tiebreaker function, ${t.name}, has returned zero and therefore cannot be`;return(e,n)=>{const i=t(e,n);if(0===i)throw Error(r);return i}}},function(t,r,e){"use strict";t.exports=class{async canAppend(t,r){return!0}}}]); +var r=n(31),i=n(32),o=n(33);function s(){return f.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(e,t){if(s()=s())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s().toString(16)+" bytes");return 0|e}function b(e,t){if(f.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 R(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return q(e).length;default:if(r)return R(e).length;t=(""+t).toLowerCase(),r=!0}}function p(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=f.from(t,r)),f.isBuffer(t))return 0===t.length?-1:m(e,t,n,r,i);if("number"==typeof t)return t&=255,f.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):m(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function m(e,t,n,r,i){var o,s=1,a=e.length,f=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;s=2,a/=2,f/=2,n/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){var u=-1;for(o=n;oa&&(n=a-f),o=n;o>=0;o--){for(var h=!0,l=0;li&&(r=i):r=i;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s>8,i=n%256,o.push(i),o.push(r);return o}(t,e.length-n),e,n,r)}function E(e,t,n){return 0===t&&n===e.length?r.fromByteArray(e):r.fromByteArray(e.slice(t,n))}function A(e,t,n){n=Math.min(e.length,n);for(var r=[],i=t;i239?4:c>223?3:c>191?2:1;if(i+h<=n)switch(h){case 1:c<128&&(u=c);break;case 2:128==(192&(o=e[i+1]))&&(f=(31&c)<<6|63&o)>127&&(u=f);break;case 3:o=e[i+1],s=e[i+2],128==(192&o)&&128==(192&s)&&(f=(15&c)<<12|(63&o)<<6|63&s)>2047&&(f<55296||f>57343)&&(u=f);break;case 4:o=e[i+1],s=e[i+2],a=e[i+3],128==(192&o)&&128==(192&s)&&128==(192&a)&&(f=(15&c)<<18|(63&o)<<12|(63&s)<<6|63&a)>65535&&f<1114112&&(u=f)}null===u?(u=65533,h=1):u>65535&&(u-=65536,r.push(u>>>10&1023|55296),u=56320|1023&u),r.push(u),i+=h}return function(e){var t=e.length;if(t<=_)return String.fromCharCode.apply(String,e);var n="",r=0;for(;rthis.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 A(this,t,n);case"ascii":return C(this,t,n);case"latin1":case"binary":return B(this,t,n);case"base64":return E(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}.apply(this,arguments)},f.prototype.equals=function(e){if(!f.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===f.compare(this,e)},f.prototype.inspect=function(){var e="",n=t.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(e+=" ... ")),""},f.prototype.compare=function(e,t,n,r,i){if(!f.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 o=(i>>>=0)-(r>>>=0),s=(n>>>=0)-(t>>>=0),a=Math.min(o,s),c=this.slice(r,i),u=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 o=!1;;)switch(r){case"hex":return g(this,e,t,n);case"utf8":case"utf-8":return y(this,e,t,n);case"ascii":return x(this,e,t,n);case"latin1":case"binary":return w(this,e,t,n);case"base64":return v(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var _=4096;function C(e,t,n){var r="";n=Math.min(e.length,n);for(var i=t;ir)&&(n=r);for(var i="",o=t;on)throw new RangeError("Trying to access beyond buffer length")}function T(e,t,n,r,i,o){if(!f.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 D(e,t,n,r){t<0&&(t=65535+t+1);for(var i=0,o=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,o=Math.min(e.length-n,4);i>>8*(r?i:3-i)&255}function U(e,t,n,r,i,o){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,o){return o||U(e,0,n,4),i.write(e,t,n,r,23,4),n+4}function L(e,t,n,r,o){return o||U(e,0,n,8),i.write(e,t,n,r,52,8),n+8}f.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},f.prototype.readUInt8=function(e,t){return t||j(e,1,this.length),this[e]},f.prototype.readUInt16LE=function(e,t){return t||j(e,2,this.length),this[e]|this[e+1]<<8},f.prototype.readUInt16BE=function(e,t){return t||j(e,2,this.length),this[e]<<8|this[e+1]},f.prototype.readUInt32LE=function(e,t){return t||j(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},f.prototype.readUInt32BE=function(e,t){return t||j(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},f.prototype.readIntLE=function(e,t,n){e|=0,t|=0,n||j(e,t,this.length);for(var r=this[e],i=1,o=0;++o=(i*=128)&&(r-=Math.pow(2,8*t)),r},f.prototype.readIntBE=function(e,t,n){e|=0,t|=0,n||j(e,t,this.length);for(var r=t,i=1,o=this[e+--r];r>0&&(i*=256);)o+=this[e+--r]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*t)),o},f.prototype.readInt8=function(e,t){return t||j(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},f.prototype.readInt16LE=function(e,t){t||j(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},f.prototype.readInt16BE=function(e,t){t||j(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},f.prototype.readInt32LE=function(e,t){return t||j(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},f.prototype.readInt32BE=function(e,t){return t||j(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},f.prototype.readFloatLE=function(e,t){return t||j(e,4,this.length),i.read(this,e,!0,23,4)},f.prototype.readFloatBE=function(e,t){return t||j(e,4,this.length),i.read(this,e,!1,23,4)},f.prototype.readDoubleLE=function(e,t){return t||j(e,8,this.length),i.read(this,e,!0,52,8)},f.prototype.readDoubleBE=function(e,t){return t||j(e,8,this.length),i.read(this,e,!1,52,8)},f.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,o=0;for(this[t]=255&e;++o=0&&(o*=256);)this[t+i]=e/o&255;return t+n},f.prototype.writeUInt8=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,1,255,0),f.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=255&e,t+1},f.prototype.writeUInt16LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):D(this,e,t,!0),t+2},f.prototype.writeUInt16BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,65535,0),f.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):D(this,e,t,!1),t+2},f.prototype.writeUInt32LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,4294967295,0),f.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},f.prototype.writeUInt32BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,4294967295,0),f.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},f.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 o=0,s=1,a=0;for(this[t]=255&e;++o>0)-a&255;return t+n},f.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 o=n-1,s=1,a=0;for(this[t+o]=255&e;--o>=0&&(s*=256);)e<0&&0===a&&0!==this[t+o+1]&&(a=1),this[t+o]=(e/s>>0)-a&255;return t+n},f.prototype.writeInt8=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,1,127,-128),f.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),e<0&&(e=255+e+1),this[t]=255&e,t+1},f.prototype.writeInt16LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[t]=255&e,this[t+1]=e>>>8):D(this,e,t,!0),t+2},f.prototype.writeInt16BE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,2,32767,-32768),f.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=255&e):D(this,e,t,!1),t+2},f.prototype.writeInt32LE=function(e,t,n){return e=+e,t|=0,n||T(this,e,t,4,2147483647,-2147483648),f.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},f.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),f.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},f.prototype.writeFloatLE=function(e,t,n){return N(this,e,t,!0,n)},f.prototype.writeFloatBE=function(e,t,n){return N(this,e,t,!1,n)},f.prototype.writeDoubleLE=function(e,t,n){return L(this,e,t,!0,n)},f.prototype.writeDoubleBE=function(e,t,n){return L(this,e,t,!1,n)},f.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(o<1e3||!f.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(o=t;o55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function q(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(4))},function(e,t,n){e.exports={encode:n(41),decode:n(42),encodingLength:n(43)}},function(e,t){var n,r,i=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===o||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:o}catch(e){n=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var f,c=[],u=!1,h=-1;function l(){u&&f&&(u=!1,f.length?c=f.concat(c):h=-1,c.length&&d())}function d(){if(!u){var e=a(l);u=!0;for(var t=c.length;t;){for(f=c,c=[];++h1)for(var n=1;n`}toJSON(){return this._json||(this._json=Object.freeze({name:this.name,size:this.size,cid:this._cid.toBaseEncodedString()})),Object.assign({},this._json)}get name(){return this._name}get nameAsBuffer(){return null!==this._nameBuf?this._nameBuf:(this._nameBuf=r.from(this._name),this._nameBuf)}set name(e){throw new Error("Can't set property: 'name' is immutable")}get size(){return this._size}set size(e){throw new Error("Can't set property: 'size' is immutable")}get cid(){return this._cid}set cid(e){throw new Error("Can't set property: 'cid' is immutable")}},{className:"DAGLink",symbolName:"@ipld/js-ipld-dag-pb/daglink"})).create=n(81),t.util=n(82)}).call(this,n(0).Buffer)},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){"use strict";(function(t){const r=n(13),i=n(44),o=n(50),s=n(14),a=n(53);class f{constructor(n,s,a){if(e.exports.isCID(n)){let e=n;return this.version=e.version,this.codec=e.codec,void(this.multihash=t.from(e.multihash))}if("string"==typeof n)if(i.isEncoded(n)){const e=i.decode(n);n=parseInt(e.slice(0,1).toString("hex"),16),s=o.getCodec(e.slice(1)),a=o.rmPrefix(e.slice(1))}else s="dag-pb",a=r.fromB58String(n),n=0;else if(t.isBuffer(n)){const e=n.slice(0,1),t=parseInt(e.toString("hex"),16);if(0===t||1===t){const e=n;n=t,s=o.getCodec(e.slice(1)),a=o.rmPrefix(e.slice(1))}else s="dag-pb",a=n,n=0}this.codec=s,this.version=n,this.multihash=a,f.validateCID(this)}get buffer(){switch(this.version){case 0:return this.multihash;case 1:return t.concat([t.from("01","hex"),o.getCodeVarint(this.codec),this.multihash]);default:throw new Error("unsupported version")}}get prefix(){return t.concat([t.from(`0${this.version}`,"hex"),o.getCodeVarint(this.codec),r.prefix(this.multihash)])}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 c(0,this.codec,this.multihash)}toV1(){return new c(1,this.codec,this.multihash)}toBaseEncodedString(e){switch(e=e||"base58btc",this.version){case 0: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()");return r.toB58String(this.multihash);case 1:return i.encode(e,this.buffer).toString();default:throw new Error("Unsupported version")}}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&&this.multihash.equals(e.multihash)}static validateCID(e){let t=a.checkCIDComponents(e);if(t)throw new Error(t)}}const c=n(15)(f,{className:"CID",symbolName:"@ipld/js-cid/CID"});c.codecs=s,e.exports=c}).call(this,n(0).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.ide.toJSON()),size:this.size})),Object.assign({},this._json)}toString(){return`DAGNode `}get data(){return this._data}set data(e){throw new Error("Can't set property: 'data' is immutable")}get links(){return this._links}set links(e){throw new Error("Can't set property: 'links' is immutable")}get size(){return void 0===this._size&&(this._size=this.links.reduce((e,t)=>e+t.size,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"})).create=n(8),t.clone=n(96),t.addLink=n(97),t.rmLink=n(98)}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(t){const r=n(58),{serialize:i}=n(9),o=n(10).linkSort,s=n(7),a=n(3);e.exports=function(e,n,f){if("function"==typeof e?(f=e,e=void 0):"string"==typeof e&&(e=t.from(e)),"function"==typeof n&&(f=n,n=[]),!t.isBuffer(e))return f(new Error("Passed 'data' is not a buffer or a string!"));n=n.map(e=>a.isDAGLink(e)?e:a.util.createDagLinkFromB58EncodedHash(e)),n=r(n,o),i({data:e,links:n},(t,r)=>{if(t)return f(t);f(null,new s(e,n,r.length))})}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(r,i){const o=n(5),s=n(60)(n(71)),a=n(24),f=n(3),c=n(7),u=n(83),h=n(25);function l(e,t){let n,{data:r,links:i=[]}=e;!c.isDAGNode(e)&&i&&(i=i.map(e=>f.isDAGLink(e)?e:f.util.createDagLinkFromB58EncodedHash(e)));try{n=s.PBNode.encode(function(e){const t={};e.data&&e.data.length>0?t.Data=e.data:t.Data=null;e.links&&e.links.length>0?t.Links=e.links.map(e=>({Hash:e.cid.buffer,Name:e.name,Tsize:e.size})):t.Links=null;return t}({data:r,links:i}))}catch(e){return t(e)}t(null,n)}(t=e.exports).serialize=l,t.deserialize=function(e,t){const n=s.PBNode.decode(e),o=n.Links.map(e=>new f(e.Name,e.Tsize,e.Hash)),a=null==n.Data?r.alloc(0):n.Data;i(()=>t(null,new c(a,o,e.length)))},t.cid=function(e,t,n){"function"==typeof t&&(n=t,t={});const i=(t=t||{}).hashAlg||a.defaultHashAlg;let s=t.version;void 0===s&&(s="sha2-256"===i?0:1),h([t=>{if(r.isBuffer(e))return t(null,e);l(e,t)},(e,t)=>u(e,i,t),(e,t)=>t(null,new o(s,a.multicodec,e))],n)}}).call(this,n(0).Buffer,n(16).setImmediate)},function(e,t,n){"use strict";(function(r){const i=n(3),{cid:o}=n(9);(t=e.exports).cloneData=function(e){let t;return e.data&&e.data.length>0?(t=r.alloc(e.data.length),e.data.copy(t)):t=r.alloc(0),t},t.cloneLinks=function(e){return e.links.slice()},t.linkSort=function(e,t){return r.compare(e.nameAsBuffer,t.nameAsBuffer)},t.toDAGLink=function(e,t,n){"function"==typeof t&&(n=t,t={}),o(e,t,(r,o)=>{if(r)return n(r);n(null,new i(t.name||"",e.size,o))})}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(t){const r=n(6),{isDefined:i,dagNode:o}=n(12),s=["next"],a=()=>new Error("Ipfs instance not defined"),f=e=>0===e.v?"hash":"cid";class c{static async create(e,t,n,o,s=[],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(o))throw new Error("Entry requires data");if(!i(s)||!Array.isArray(s))throw new Error("'next' argument is not an array");const u={cid:null,id:n,payload:o,next:s.filter(i).map(e=>e.cid?e.cid:e),v:1,clock:f||new r(t.publicKey)},h=await t.provider.sign(t,c.toBuffer(u));return u.key=t.publicKey,u.identity=t.toJSON(),u.sig=h,u.cid=await c.toCID(e,u),c.ensureInterop(u)}static async verify(e,t){if(!e)throw new Error("Identity-provider is required, cannot verify entry");if(!c.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(t)]:null,id:t.id,payload:t.payload,next:t.next,v:t.v,clock:t.clock};return e.verify(t.sig,t.key,c.toBuffer(n))}static toBuffer(e){return t.from(JSON.stringify(e))}static toCID(e,t){if(!e)throw a();if(!c.isEntry(t))throw new Error("Invalid object format, cannot generate entry CID");const n={cid:null,id:t.id,payload:t.payload,next:t.next,v:t.v,clock:t.clock};return t.key&&Object.assign(n,{key:t.key}),t.identity&&Object.assign(n,{identity:t.identity}),t.sig&&Object.assign(n,{sig:t.sig}),o.write(e,"dag-cbor",n,s)}static async toMultihash(e,t){if(!e)throw a();if(!c.isEntry(t))throw new Error("Invalid object format, cannot generate entry CID");const n={hash:null,id:t.id,payload:t.payload,next:t.next,v:0,clock:t.clock};return t.key&&Object.assign(n,{key:t.key}),t.identity&&Object.assign(n,{identity:t.identity}),t.sig&&Object.assign(n,{sig:t.sig}),o.write(e,"dag-pb",n,s)}static async fromCID(e,t){if(!e)throw a();if(!t)throw new Error(`Invalid CID: ${t}`);const n=await o.read(e,t,s);let i={[f(n)]:t,id:n.id,payload:n.payload,next:n.next,v:n.v,clock:new r(n.clock.id,n.clock.time)};return n.key&&Object.assign(i,{key:n.key}),n.identity&&Object.assign(i,{identity:n.identity}),n.sig&&Object.assign(i,{sig:n.sig}),c.ensureInterop(i)}static async fromMultihash(e,t){return c.fromCID(e,t)}static isEntry(e){return e&&void 0!==e.id&&void 0!==e.next&&void 0!==e.payload&&void 0!==e.v&&void 0!==e[f(e)]&&void 0!==e.clock}static ensureInterop(e){if(e.cid&&e.hash)return e;const t=f(e),n="hash"===t?"cid":"hash";return Object.defineProperty(e,n,{get(){return this[t]},set(e){this[t]=e}}),e}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=>c.isParent(e,t)),i=e;r;)n.push(r),i=r,r=t.find(e=>c.isParent(i,e));return n=n.sort((e,t)=>e.clock.time>t.clock.time)}}e.exports=c}).call(this,n(0).Buffer)},function(e,t,n){"use strict";const r=n(35),i=n(36),o=n(37),s=n(38);e.exports={difference:r,findUniques:i,isDefined:o,dagNode:s}},function(e,t,n){"use strict";(function(e){const r=n(39),i=n(40);t.names=i.names,t.codes=i.codes,t.defaultLengths=i.defaultLengths;const o=n(1);function s(e){t.decode(e)}t.toHexString=function(t){if(!e.isBuffer(t))throw new Error("must be passed a buffer");return t.toString("hex")},t.fromHexString=function(t){return e.from(t,"hex")},t.toB58String=function(t){if(!e.isBuffer(t))throw new Error("must be passed a buffer");return r.encode(t)},t.fromB58String=function(t){let n=t;return e.isBuffer(t)&&(n=t.toString()),e.from(r.decode(n))},t.decode=function(n){if(!e.isBuffer(n))throw new Error("multihash must be a Buffer");if(n.length<3)throw new Error("multihash too short. must be > 3 bytes.");let r=o.decode(n);if(!t.isValidCode(r))throw new Error(`multihash unknown function code: 0x${r.toString(16)}`);n=n.slice(o.decode.bytes);let s=o.decode(n);if(s<1)throw new Error(`multihash invalid length: 0x${s.toString(16)}`);if((n=n.slice(o.decode.bytes)).length!==s)throw new Error(`multihash length inconsistent: 0x${n.toString("hex")}`);return{code:r,name:i.codes[r],length:s,digest:n}},t.encode=function(n,r,i){if(!n||!r)throw new Error("multihash encode requires at least two args: digest, code");const s=t.coerceCode(r);if(!e.isBuffer(n))throw new Error("digest should be a Buffer");if(null==i&&(i=n.length),i&&n.length!==i)throw new Error("digest length should be equal to specified length.");return e.concat([e.from(o.encode(s)),e.from(o.encode(i)),n])},t.coerceCode=function(e){let n=e;if("string"==typeof e){if(!i.names[e])throw new Error(`Unrecognized hash function named: ${e}`);n=i.names[e]}if("number"!=typeof n)throw new Error(`Hash function code should be a number. Got: ${n}`);if(!i.codes[n]&&!t.isAppCode(n))throw new Error(`Unrecognized function code: ${n}`);return n},t.isAppCode=function(e){return e>0&&e<16},t.isValidCode=function(e){return!!t.isAppCode(e)||!!i.codes[e]},t.validate=s,t.prefix=function(e){return s(e),e.slice(0,2)}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(n){(t=e.exports).raw=n.from("55","hex"),t.base1=n.from("01","hex"),t.base2=n.from("00","hex"),t.base8=n.from("07","hex"),t.base10=n.from("09","hex"),t.cbor=n.from("51","hex"),t.protobuf=n.from("50","hex"),t.rlp=n.from("60","hex"),t.bencode=n.from("63","hex"),t.multicodec=n.from("30","hex"),t.multihash=n.from("31","hex"),t.multiaddr=n.from("32","hex"),t.multibase=n.from("33","hex"),t.md4=n.from("d4","hex"),t.md5=n.from("d5","hex"),t.sha1=n.from("11","hex"),t["sha2-256"]=n.from("12","hex"),t["sha2-512"]=n.from("13","hex"),t["dbl-sha2-256"]=n.from("56","hex"),t["sha3-224"]=n.from("17","hex"),t["sha3-256"]=n.from("16","hex"),t["sha3-384"]=n.from("15","hex"),t["sha3-512"]=n.from("14","hex"),t["shake-128"]=n.from("18","hex"),t["shake-256"]=n.from("19","hex"),t["keccak-224"]=n.from("1a","hex"),t["keccak-256"]=n.from("1b","hex"),t["keccak-384"]=n.from("1c","hex"),t["keccak-512"]=n.from("1d","hex"),t.murmur3=n.from("22","hex"),t["blake2b-8"]=n.from("b201","hex"),t["blake2b-16"]=n.from("b202","hex"),t["blake2b-24"]=n.from("b203","hex"),t["blake2b-32"]=n.from("b204","hex"),t["blake2b-40"]=n.from("b205","hex"),t["blake2b-48"]=n.from("b206","hex"),t["blake2b-56"]=n.from("b207","hex"),t["blake2b-64"]=n.from("b208","hex"),t["blake2b-72"]=n.from("b209","hex"),t["blake2b-80"]=n.from("b20a","hex"),t["blake2b-88"]=n.from("b20b","hex"),t["blake2b-96"]=n.from("b20c","hex"),t["blake2b-104"]=n.from("b20d","hex"),t["blake2b-112"]=n.from("b20e","hex"),t["blake2b-120"]=n.from("b20f","hex"),t["blake2b-128"]=n.from("b210","hex"),t["blake2b-136"]=n.from("b211","hex"),t["blake2b-144"]=n.from("b212","hex"),t["blake2b-152"]=n.from("b213","hex"),t["blake2b-160"]=n.from("b214","hex"),t["blake2b-168"]=n.from("b215","hex"),t["blake2b-176"]=n.from("b216","hex"),t["blake2b-184"]=n.from("b217","hex"),t["blake2b-192"]=n.from("b218","hex"),t["blake2b-200"]=n.from("b219","hex"),t["blake2b-208"]=n.from("b21a","hex"),t["blake2b-216"]=n.from("b21b","hex"),t["blake2b-224"]=n.from("b21c","hex"),t["blake2b-232"]=n.from("b21d","hex"),t["blake2b-240"]=n.from("b21e","hex"),t["blake2b-248"]=n.from("b21f","hex"),t["blake2b-256"]=n.from("b220","hex"),t["blake2b-264"]=n.from("b221","hex"),t["blake2b-272"]=n.from("b222","hex"),t["blake2b-280"]=n.from("b223","hex"),t["blake2b-288"]=n.from("b224","hex"),t["blake2b-296"]=n.from("b225","hex"),t["blake2b-304"]=n.from("b226","hex"),t["blake2b-312"]=n.from("b227","hex"),t["blake2b-320"]=n.from("b228","hex"),t["blake2b-328"]=n.from("b229","hex"),t["blake2b-336"]=n.from("b22a","hex"),t["blake2b-344"]=n.from("b22b","hex"),t["blake2b-352"]=n.from("b22c","hex"),t["blake2b-360"]=n.from("b22d","hex"),t["blake2b-368"]=n.from("b22e","hex"),t["blake2b-376"]=n.from("b22f","hex"),t["blake2b-384"]=n.from("b230","hex"),t["blake2b-392"]=n.from("b231","hex"),t["blake2b-400"]=n.from("b232","hex"),t["blake2b-408"]=n.from("b233","hex"),t["blake2b-416"]=n.from("b234","hex"),t["blake2b-424"]=n.from("b235","hex"),t["blake2b-432"]=n.from("b236","hex"),t["blake2b-440"]=n.from("b237","hex"),t["blake2b-448"]=n.from("b238","hex"),t["blake2b-456"]=n.from("b239","hex"),t["blake2b-464"]=n.from("b23a","hex"),t["blake2b-472"]=n.from("b23b","hex"),t["blake2b-480"]=n.from("b23c","hex"),t["blake2b-488"]=n.from("b23d","hex"),t["blake2b-496"]=n.from("b23e","hex"),t["blake2b-504"]=n.from("b23f","hex"),t["blake2b-512"]=n.from("b240","hex"),t["blake2s-8"]=n.from("b241","hex"),t["blake2s-16"]=n.from("b242","hex"),t["blake2s-24"]=n.from("b243","hex"),t["blake2s-32"]=n.from("b244","hex"),t["blake2s-40"]=n.from("b245","hex"),t["blake2s-48"]=n.from("b246","hex"),t["blake2s-56"]=n.from("b247","hex"),t["blake2s-64"]=n.from("b248","hex"),t["blake2s-72"]=n.from("b249","hex"),t["blake2s-80"]=n.from("b24a","hex"),t["blake2s-88"]=n.from("b24b","hex"),t["blake2s-96"]=n.from("b24c","hex"),t["blake2s-104"]=n.from("b24d","hex"),t["blake2s-112"]=n.from("b24e","hex"),t["blake2s-120"]=n.from("b24f","hex"),t["blake2s-128"]=n.from("b250","hex"),t["blake2s-136"]=n.from("b251","hex"),t["blake2s-144"]=n.from("b252","hex"),t["blake2s-152"]=n.from("b253","hex"),t["blake2s-160"]=n.from("b254","hex"),t["blake2s-168"]=n.from("b255","hex"),t["blake2s-176"]=n.from("b256","hex"),t["blake2s-184"]=n.from("b257","hex"),t["blake2s-192"]=n.from("b258","hex"),t["blake2s-200"]=n.from("b259","hex"),t["blake2s-208"]=n.from("b25a","hex"),t["blake2s-216"]=n.from("b25b","hex"),t["blake2s-224"]=n.from("b25c","hex"),t["blake2s-232"]=n.from("b25d","hex"),t["blake2s-240"]=n.from("b25e","hex"),t["blake2s-248"]=n.from("b25f","hex"),t["blake2s-256"]=n.from("b260","hex"),t["skein256-8"]=n.from("b301","hex"),t["skein256-16"]=n.from("b302","hex"),t["skein256-24"]=n.from("b303","hex"),t["skein256-32"]=n.from("b304","hex"),t["skein256-40"]=n.from("b305","hex"),t["skein256-48"]=n.from("b306","hex"),t["skein256-56"]=n.from("b307","hex"),t["skein256-64"]=n.from("b308","hex"),t["skein256-72"]=n.from("b309","hex"),t["skein256-80"]=n.from("b30a","hex"),t["skein256-88"]=n.from("b30b","hex"),t["skein256-96"]=n.from("b30c","hex"),t["skein256-104"]=n.from("b30d","hex"),t["skein256-112"]=n.from("b30e","hex"),t["skein256-120"]=n.from("b30f","hex"),t["skein256-128"]=n.from("b310","hex"),t["skein256-136"]=n.from("b311","hex"),t["skein256-144"]=n.from("b312","hex"),t["skein256-152"]=n.from("b313","hex"),t["skein256-160"]=n.from("b314","hex"),t["skein256-168"]=n.from("b315","hex"),t["skein256-176"]=n.from("b316","hex"),t["skein256-184"]=n.from("b317","hex"),t["skein256-192"]=n.from("b318","hex"),t["skein256-200"]=n.from("b319","hex"),t["skein256-208"]=n.from("b31a","hex"),t["skein256-216"]=n.from("b31b","hex"),t["skein256-224"]=n.from("b31c","hex"),t["skein256-232"]=n.from("b31d","hex"),t["skein256-240"]=n.from("b31e","hex"),t["skein256-248"]=n.from("b31f","hex"),t["skein256-256"]=n.from("b320","hex"),t["skein512-8"]=n.from("b321","hex"),t["skein512-16"]=n.from("b322","hex"),t["skein512-24"]=n.from("b323","hex"),t["skein512-32"]=n.from("b324","hex"),t["skein512-40"]=n.from("b325","hex"),t["skein512-48"]=n.from("b326","hex"),t["skein512-56"]=n.from("b327","hex"),t["skein512-64"]=n.from("b328","hex"),t["skein512-72"]=n.from("b329","hex"),t["skein512-80"]=n.from("b32a","hex"),t["skein512-88"]=n.from("b32b","hex"),t["skein512-96"]=n.from("b32c","hex"),t["skein512-104"]=n.from("b32d","hex"),t["skein512-112"]=n.from("b32e","hex"),t["skein512-120"]=n.from("b32f","hex"),t["skein512-128"]=n.from("b330","hex"),t["skein512-136"]=n.from("b331","hex"),t["skein512-144"]=n.from("b332","hex"),t["skein512-152"]=n.from("b333","hex"),t["skein512-160"]=n.from("b334","hex"),t["skein512-168"]=n.from("b335","hex"),t["skein512-176"]=n.from("b336","hex"),t["skein512-184"]=n.from("b337","hex"),t["skein512-192"]=n.from("b338","hex"),t["skein512-200"]=n.from("b339","hex"),t["skein512-208"]=n.from("b33a","hex"),t["skein512-216"]=n.from("b33b","hex"),t["skein512-224"]=n.from("b33c","hex"),t["skein512-232"]=n.from("b33d","hex"),t["skein512-240"]=n.from("b33e","hex"),t["skein512-248"]=n.from("b33f","hex"),t["skein512-256"]=n.from("b340","hex"),t["skein512-264"]=n.from("b341","hex"),t["skein512-272"]=n.from("b342","hex"),t["skein512-280"]=n.from("b343","hex"),t["skein512-288"]=n.from("b344","hex"),t["skein512-296"]=n.from("b345","hex"),t["skein512-304"]=n.from("b346","hex"),t["skein512-312"]=n.from("b347","hex"),t["skein512-320"]=n.from("b348","hex"),t["skein512-328"]=n.from("b349","hex"),t["skein512-336"]=n.from("b34a","hex"),t["skein512-344"]=n.from("b34b","hex"),t["skein512-352"]=n.from("b34c","hex"),t["skein512-360"]=n.from("b34d","hex"),t["skein512-368"]=n.from("b34e","hex"),t["skein512-376"]=n.from("b34f","hex"),t["skein512-384"]=n.from("b350","hex"),t["skein512-392"]=n.from("b351","hex"),t["skein512-400"]=n.from("b352","hex"),t["skein512-408"]=n.from("b353","hex"),t["skein512-416"]=n.from("b354","hex"),t["skein512-424"]=n.from("b355","hex"),t["skein512-432"]=n.from("b356","hex"),t["skein512-440"]=n.from("b357","hex"),t["skein512-448"]=n.from("b358","hex"),t["skein512-456"]=n.from("b359","hex"),t["skein512-464"]=n.from("b35a","hex"),t["skein512-472"]=n.from("b35b","hex"),t["skein512-480"]=n.from("b35c","hex"),t["skein512-488"]=n.from("b35d","hex"),t["skein512-496"]=n.from("b35e","hex"),t["skein512-504"]=n.from("b35f","hex"),t["skein512-512"]=n.from("b360","hex"),t["skein1024-8"]=n.from("b361","hex"),t["skein1024-16"]=n.from("b362","hex"),t["skein1024-24"]=n.from("b363","hex"),t["skein1024-32"]=n.from("b364","hex"),t["skein1024-40"]=n.from("b365","hex"),t["skein1024-48"]=n.from("b366","hex"),t["skein1024-56"]=n.from("b367","hex"),t["skein1024-64"]=n.from("b368","hex"),t["skein1024-72"]=n.from("b369","hex"),t["skein1024-80"]=n.from("b36a","hex"),t["skein1024-88"]=n.from("b36b","hex"),t["skein1024-96"]=n.from("b36c","hex"),t["skein1024-104"]=n.from("b36d","hex"),t["skein1024-112"]=n.from("b36e","hex"),t["skein1024-120"]=n.from("b36f","hex"),t["skein1024-128"]=n.from("b370","hex"),t["skein1024-136"]=n.from("b371","hex"),t["skein1024-144"]=n.from("b372","hex"),t["skein1024-152"]=n.from("b373","hex"),t["skein1024-160"]=n.from("b374","hex"),t["skein1024-168"]=n.from("b375","hex"),t["skein1024-176"]=n.from("b376","hex"),t["skein1024-184"]=n.from("b377","hex"),t["skein1024-192"]=n.from("b378","hex"),t["skein1024-200"]=n.from("b379","hex"),t["skein1024-208"]=n.from("b37a","hex"),t["skein1024-216"]=n.from("b37b","hex"),t["skein1024-224"]=n.from("b37c","hex"),t["skein1024-232"]=n.from("b37d","hex"),t["skein1024-240"]=n.from("b37e","hex"),t["skein1024-248"]=n.from("b37f","hex"),t["skein1024-256"]=n.from("b380","hex"),t["skein1024-264"]=n.from("b381","hex"),t["skein1024-272"]=n.from("b382","hex"),t["skein1024-280"]=n.from("b383","hex"),t["skein1024-288"]=n.from("b384","hex"),t["skein1024-296"]=n.from("b385","hex"),t["skein1024-304"]=n.from("b386","hex"),t["skein1024-312"]=n.from("b387","hex"),t["skein1024-320"]=n.from("b388","hex"),t["skein1024-328"]=n.from("b389","hex"),t["skein1024-336"]=n.from("b38a","hex"),t["skein1024-344"]=n.from("b38b","hex"),t["skein1024-352"]=n.from("b38c","hex"),t["skein1024-360"]=n.from("b38d","hex"),t["skein1024-368"]=n.from("b38e","hex"),t["skein1024-376"]=n.from("b38f","hex"),t["skein1024-384"]=n.from("b390","hex"),t["skein1024-392"]=n.from("b391","hex"),t["skein1024-400"]=n.from("b392","hex"),t["skein1024-408"]=n.from("b393","hex"),t["skein1024-416"]=n.from("b394","hex"),t["skein1024-424"]=n.from("b395","hex"),t["skein1024-432"]=n.from("b396","hex"),t["skein1024-440"]=n.from("b397","hex"),t["skein1024-448"]=n.from("b398","hex"),t["skein1024-456"]=n.from("b399","hex"),t["skein1024-464"]=n.from("b39a","hex"),t["skein1024-472"]=n.from("b39b","hex"),t["skein1024-480"]=n.from("b39c","hex"),t["skein1024-488"]=n.from("b39d","hex"),t["skein1024-496"]=n.from("b39e","hex"),t["skein1024-504"]=n.from("b39f","hex"),t["skein1024-512"]=n.from("b3a0","hex"),t["skein1024-520"]=n.from("b3a1","hex"),t["skein1024-528"]=n.from("b3a2","hex"),t["skein1024-536"]=n.from("b3a3","hex"),t["skein1024-544"]=n.from("b3a4","hex"),t["skein1024-552"]=n.from("b3a5","hex"),t["skein1024-560"]=n.from("b3a6","hex"),t["skein1024-568"]=n.from("b3a7","hex"),t["skein1024-576"]=n.from("b3a8","hex"),t["skein1024-584"]=n.from("b3a9","hex"),t["skein1024-592"]=n.from("b3aa","hex"),t["skein1024-600"]=n.from("b3ab","hex"),t["skein1024-608"]=n.from("b3ac","hex"),t["skein1024-616"]=n.from("b3ad","hex"),t["skein1024-624"]=n.from("b3ae","hex"),t["skein1024-632"]=n.from("b3af","hex"),t["skein1024-640"]=n.from("b3b0","hex"),t["skein1024-648"]=n.from("b3b1","hex"),t["skein1024-656"]=n.from("b3b2","hex"),t["skein1024-664"]=n.from("b3b3","hex"),t["skein1024-672"]=n.from("b3b4","hex"),t["skein1024-680"]=n.from("b3b5","hex"),t["skein1024-688"]=n.from("b3b6","hex"),t["skein1024-696"]=n.from("b3b7","hex"),t["skein1024-704"]=n.from("b3b8","hex"),t["skein1024-712"]=n.from("b3b9","hex"),t["skein1024-720"]=n.from("b3ba","hex"),t["skein1024-728"]=n.from("b3bb","hex"),t["skein1024-736"]=n.from("b3bc","hex"),t["skein1024-744"]=n.from("b3bd","hex"),t["skein1024-752"]=n.from("b3be","hex"),t["skein1024-760"]=n.from("b3bf","hex"),t["skein1024-768"]=n.from("b3c0","hex"),t["skein1024-776"]=n.from("b3c1","hex"),t["skein1024-784"]=n.from("b3c2","hex"),t["skein1024-792"]=n.from("b3c3","hex"),t["skein1024-800"]=n.from("b3c4","hex"),t["skein1024-808"]=n.from("b3c5","hex"),t["skein1024-816"]=n.from("b3c6","hex"),t["skein1024-824"]=n.from("b3c7","hex"),t["skein1024-832"]=n.from("b3c8","hex"),t["skein1024-840"]=n.from("b3c9","hex"),t["skein1024-848"]=n.from("b3ca","hex"),t["skein1024-856"]=n.from("b3cb","hex"),t["skein1024-864"]=n.from("b3cc","hex"),t["skein1024-872"]=n.from("b3cd","hex"),t["skein1024-880"]=n.from("b3ce","hex"),t["skein1024-888"]=n.from("b3cf","hex"),t["skein1024-896"]=n.from("b3d0","hex"),t["skein1024-904"]=n.from("b3d1","hex"),t["skein1024-912"]=n.from("b3d2","hex"),t["skein1024-920"]=n.from("b3d3","hex"),t["skein1024-928"]=n.from("b3d4","hex"),t["skein1024-936"]=n.from("b3d5","hex"),t["skein1024-944"]=n.from("b3d6","hex"),t["skein1024-952"]=n.from("b3d7","hex"),t["skein1024-960"]=n.from("b3d8","hex"),t["skein1024-968"]=n.from("b3d9","hex"),t["skein1024-976"]=n.from("b3da","hex"),t["skein1024-984"]=n.from("b3db","hex"),t["skein1024-992"]=n.from("b3dc","hex"),t["skein1024-1000"]=n.from("b3dd","hex"),t["skein1024-1008"]=n.from("b3de","hex"),t["skein1024-1016"]=n.from("b3df","hex"),t["skein1024-1024"]=n.from("b3e0","hex"),t.ip4=n.from("04","hex"),t.ip6=n.from("29","hex"),t.tcp=n.from("06","hex"),t.udp=n.from("0111","hex"),t.dccp=n.from("21","hex"),t.sctp=n.from("84","hex"),t.udt=n.from("012d","hex"),t.utp=n.from("012e","hex"),t.ipfs=n.from("01a5","hex"),t.http=n.from("01e0","hex"),t.https=n.from("01bb","hex"),t.quic=n.from("01cc","hex"),t.ws=n.from("01dd","hex"),t.onion=n.from("01bc","hex"),t["p2p-circuit"]=n.from("0122","hex"),t["git-raw"]=n.from("78","hex"),t["dag-pb"]=n.from("70","hex"),t["dag-cbor"]=n.from("71","hex"),t["git-raw"]=n.from("78","hex"),t["eth-block"]=n.from("90","hex"),t["eth-block-list"]=n.from("91","hex"),t["eth-tx-trie"]=n.from("92","hex"),t["eth-tx"]=n.from("93","hex"),t["eth-tx-receipt-trie"]=n.from("94","hex"),t["eth-tx-receipt"]=n.from("95","hex"),t["eth-state-trie"]=n.from("96","hex"),t["eth-account-snapshot"]=n.from("97","hex"),t["eth-storage-trie"]=n.from("98","hex"),t["bitcoin-block"]=n.from("b0","hex"),t["bitcoin-tx"]=n.from("b1","hex"),t["zcash-block"]=n.from("c0","hex"),t["zcash-tx"]=n.from("c1","hex"),t["stellar-block"]=n.from("d0","hex"),t["stellar-tx"]=n.from("d1","hex"),t["torrent-info"]=n.from("7b","hex"),t["torrent-file"]=n.from("7c","hex"),t["ed25519-pub"]=n.from("ed","hex")}).call(this,n(0).Buffer)},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),o={[t]:function(...t){if(r&&!(this instanceof o))return new o(...t);const n=e.call(this,...t)||this;return n&&!n[i]&&Object.defineProperty(n,i,{value:!0}),n}}[t];return o.prototype=Object.create(e.prototype),o.prototype.constructor=o,Object.defineProperty(o.prototype,Symbol.toStringTag,{get:()=>t}),o[`is${t}`]=(e=>!(!e||!e[i])),o}},function(e,t,n){(function(e){var r=void 0!==e&&e||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function o(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new o(i.call(setTimeout,r,arguments),clearTimeout)},t.setInterval=function(){return new o(i.call(setInterval,r,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},o.prototype.unref=o.prototype.ref=function(){},o.prototype.close=function(){this._clearFn.call(r,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},n(59),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,n(4))},function(e,t,n){"use strict";t.defined=function(e){return null!=e&&("number"!=typeof e||!isNaN(e))}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){t|=0;for(var n=Math.max(e.length-t,0),r=Array(n),i=0;inew Promise((r,i)=>{if(n=Object.assign({concurrency:1/0},n),"function"!=typeof t)throw new TypeError("Mapper function is required");const o=n.concurrency;if(!("number"==typeof o&&o>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${o}\` (${typeof o})`);const s=[],a=e[Symbol.iterator]();let f=!1,c=!1,u=0,h=0;const l=()=>{if(f)return;const e=a.next(),n=h;if(h++,e.done)return c=!0,void(0===u&&r(s));u++,Promise.resolve(e.value).then(e=>t(e,n)).then(e=>{s[n]=e,u--,l()},e=>{f=!0,i(e)})};for(let e=0;e>=8;for(;c>0;)o.push(255&c),c>>=8}for(var u=0;e[u]===i&&u0;)r.push(a%n),a=a/n|0}for(var f="",c=0;0===t[c]&&c=0;--u)f+=e[r[u]];return f},decodeUnsafe:a,decode:function(e){var t=a(e);if(t)return t;throw new Error("Non-base"+n+" character")}}}},function(e,t,n){var r=n(0),i=r.Buffer;function o(e,t){for(var n in e)t[n]=e[n]}function s(e,t,n){return i(e,t,n)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=r:(o(r,t),t.Buffer=s),o(i,s),s.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,n)},s.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var r=i(e);return void 0!==t?"string"==typeof n?r.fill(t,n):r.fill(t):r.fill(0),r},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}},function(e,t,n){"use strict";(function(t){const r=n(1);function i(e){return parseInt(e.toString("hex"),16)}function o(e){let n=e.toString(16);return n.length%2==1&&(n="0"+n),t.from(n,"hex")}e.exports={numberToBuffer:o,bufferToNumber:i,varintBufferEncode:function(e){return t.from(r.encode(i(e)))},varintBufferDecode:function(e){return o(r.decode(e))}}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(t){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +function r(e,t){if(e===t)return 0;for(var n=e.length,r=t.length,i=0,o=Math.min(n,r);i=0;c--)if(u[c]!==h[c])return!1;for(c=u.length-1;c>=0;c--)if(f=u[c],!g(e[f],t[f],n,r))return!1;return!0}(e,t,n,s))}return n?e===t:e==t}function y(e){return"[object Arguments]"==Object.prototype.toString.call(e)}function x(e,t){if(!e||!t)return!1;if("[object RegExp]"==Object.prototype.toString.call(t))return t.test(e);try{if(e instanceof t)return!0}catch(e){}return!Error.isPrototypeOf(t)&&!0===t.call({},e)}function w(e,t,n,r){var i;if("function"!=typeof t)throw new TypeError('"block" argument must be a function');"string"==typeof n&&(r=n,n=null),i=function(e){var t;try{e()}catch(e){t=e}return t}(t),r=(n&&n.name?" ("+n.name+").":".")+(r?" "+r:"."),e&&!i&&k(i,n,"Missing expected exception"+r);var s="string"==typeof r,a=!e&&i&&!n;if((!e&&o.isError(i)&&s&&x(i,n)||a)&&k(i,n,"Got unwanted exception"+r),e&&i&&n&&!x(i,n)||!e&&i)throw i}h.AssertionError=function(e){var t;this.name="AssertionError",this.actual=e.actual,this.expected=e.expected,this.operator=e.operator,e.message?(this.message=e.message,this.generatedMessage=!1):(this.message=b(p((t=this).actual),128)+" "+t.operator+" "+b(p(t.expected),128),this.generatedMessage=!0);var n=e.stackStartFunction||k;if(Error.captureStackTrace)Error.captureStackTrace(this,n);else{var r=new Error;if(r.stack){var i=r.stack,o=d(n),s=i.indexOf("\n"+o);if(s>=0){var a=i.indexOf("\n",s+1);i=i.substring(a+1)}this.stack=i}}},o.inherits(h.AssertionError,Error),h.fail=k,h.ok=m,h.equal=function(e,t,n){e!=t&&k(e,t,n,"==",h.equal)},h.notEqual=function(e,t,n){e==t&&k(e,t,n,"!=",h.notEqual)},h.deepEqual=function(e,t,n){g(e,t,!1)||k(e,t,n,"deepEqual",h.deepEqual)},h.deepStrictEqual=function(e,t,n){g(e,t,!0)||k(e,t,n,"deepStrictEqual",h.deepStrictEqual)},h.notDeepEqual=function(e,t,n){g(e,t,!1)&&k(e,t,n,"notDeepEqual",h.notDeepEqual)},h.notDeepStrictEqual=function e(t,n,r){g(t,n,!0)&&k(t,n,r,"notDeepStrictEqual",e)},h.strictEqual=function(e,t,n){e!==t&&k(e,t,n,"===",h.strictEqual)},h.notStrictEqual=function(e,t,n){e===t&&k(e,t,n,"!==",h.notStrictEqual)},h.throws=function(e,t,n){w(!0,e,t,n)},h.doesNotThrow=function(e,t,n){w(!1,e,t,n)},h.ifError=function(e){if(e)throw e};var v=Object.keys||function(e){var t=[];for(var n in e)s.call(e,n)&&t.push(n);return t}}).call(this,n(4))},function(e,t,n){"use strict";const r=n(25),i=n(5),o=n(9);(t=e.exports).multicodec="dag-pb",t.defaultHashAlg="sha2-256",t.resolve=((e,t,n)=>{r([t=>o.deserialize(e,t),(e,r)=>{if(!t)return n(null,{value:e,remainderPath:""});const i=t.split("/");if("Links"===i[0]){let t="";if(!i[1])return r(null,{value:e.links.map(e=>e.toJSON()),remainderPath:""});const n={};e.links.forEach((e,t)=>{const r=e.toJSON();n[t]=n[r.name]={cid:r.cid,name:r.name,size:r.size}});let o=n[i[1]];"Hash"===i[2]?o={"/":o.cid}:"Tsize"===i[2]?o=o.size:"Name"===i[2]&&(o=o.name),r(null,{value:o,remainderPath:t=i.slice(3).join("/")})}else if("Data"===i[0])r(null,{value:e.data,remainderPath:""});else{const t={};e.links.forEach((e,n)=>{const r=e.toJSON();t[r.name]={cid:r.cid,name:r.name,size:r.size}});const n=t[i[0]];if(n)return r(null,{value:{"/":n.cid},remainderPath:i.slice(1).join("/")});r(new Error("path not available"))}}],n)}),t.tree=((e,t,n)=>{"function"==typeof t&&(n=t,t={}),t=t||{},o.deserialize(e,(e,t)=>{if(e)return n(e);const r=[];r.push("Links"),t.links.forEach((e,t)=>{r.push(`Links/${t}/Name`),r.push(`Links/${t}/Tsize`),r.push(`Links/${t}/Hash`)}),r.push("Data"),n(null,r)})}),t.isLink=((e,n,r)=>{t.resolve(e,n,(e,t)=>{if(e)return r(e);if(t.remainderPath.length>0)return r(new Error("path out of scope"));if("object"==typeof t.value&&t.value["/"]){let n;try{n=i.isCID(new i(t.value["/"]))}catch(e){n=!1}if(n)return r(null,t.value)}r(null,!1)})})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){if(t=(0,o.default)(t||i.default),!(0,r.default)(e))return t(new Error("First argument to waterfall must be an array of functions"));if(!e.length)return t();var n=0;function c(t){var r=(0,f.default)(e[n++]);t.push((0,a.default)(u)),r.apply(null,t)}function u(r){if(r||n===e.length)return t.apply(null,arguments);c((0,s.default)(arguments,1))}c([])};var r=c(n(72)),i=c(n(73)),o=c(n(74)),s=c(n(18)),a=c(n(75)),f=c(n(76));function c(e){return e&&e.__esModule?e:{default:e}}e.exports=t.default},function(e,t,n){"use strict";(function(e,n){t.toCallback=(t=>(function(n,r){let i;try{i=t(n)}catch(t){return void e.nextTick(r,t)}e.nextTick(r,null,i)})),t.toBuf=((e,t)=>r=>{let i=e(r,t);return n.from(i,"hex")}),t.fromString=((e,t)=>r=>{const i=n.isBuffer(r)?r.toString():r;return e(i,t)}),t.fromNumberTo32BitBuf=((e,t)=>r=>{let i=e(r,t);const o=new Array(4);for(let e=0;e<4;e++)o[e]=255&i,i>>=8;return n.from(o)})}).call(this,n(2),n(0).Buffer)},function(e,t){e.exports=function(e){return e&&"function"==typeof e.then}},function(e,t,n){(function(t){var n="Input must be an string, Buffer or Uint8Array";function r(e){return(4294967296+e).toString(16).substring(1)}e.exports={normalizeInput:function(e){var r;if(e instanceof Uint8Array)r=e;else if(e instanceof t)r=new Uint8Array(e);else{if("string"!=typeof e)throw new Error(n);r=new Uint8Array(t.from(e,"utf8"))}return r},toHex:function(e){return Array.prototype.map.call(e,function(e){return(e<16?"0":"")+e.toString(16)}).join("")},debugPrint:function(e,t,n){for(var i="\n"+e+" = ",o=0;onew Error("IPFS instance not defined"),LogNotDefinedError:()=>new Error("Log instance not defined"),NotALogError:()=>new Error("Given argument is not an instance of Log"),CannotJoinWithDifferentId:()=>new Error("Can't join logs with different IDs")}},function(e,t,n){"use strict";(function(t){const r=n(19),i=n(34),o=n(11),s=n(100),a=n(29),f=n(6),{LastWriteWins:c,NoZeroes:u}=n(103),h=n(104),{isDefined:l,findUniques:d}=n(12),b=()=>(new Date).getTime().toString(),p=e=>e.cid,k=(e,t)=>e.concat(t),m=e=>e.next,g=(e,t)=>Math.max(e,t.clock.time),y=(e,t)=>(e[t.cid]=t,e);class x extends i{constructor(e,t,n,r,i,o,s,h){if(!l(e))throw a.IPFSNotDefinedError();if(!l(t))throw new Error("Access controller is required");if(!l(n))throw new Error("Identity is required");if(l(i)&&!Array.isArray(i))throw new Error("'entries' argument must be an array of Entry instances");if(l(o)&&!Array.isArray(o))throw new Error("'heads' argument must be an array");l(h)||(h=c),super(),this._sortFn=u(h),this._storage=e,this._id=r||b(),this._access=t,this._identity=n,i=i||[],this._entryIndex=i.reduce(y,{}),o=o||x.findHeads(i),this._headsIndex=o.reduce(y,{}),this._nextsIndex={};i.forEach(e=>e.next.forEach(t=>this._nextsIndex[t]=e.cid)),this._length=i.length;const d=Math.max(s?s.time:0,this.heads.reduce(g,0));this._clock=new f(this._identity.publicKey,d)}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 x.findTails(this.values)}get tailCids(){return x.findTailCids(this.values)}get(e){return this._entryIndex[e]}has(e){return void 0!==this._entryIndex[e.cid||e]}traverse(e,t=-1){var n=e.sort(this._sortFn).reverse();let r={},i={},o=0;const s=e=>this.get(e),a=e=>{e&&!r[e.cid]&&(n=[e,...n].sort(this._sortFn).reverse(),r[e.cid]=!0)};for(;n.length>0&&(-1===t||othis._nextsIndex[e]=s.cid),this._headsIndex={},this._headsIndex[s.cid]=s,this._length++,s}async join(e,t=-1){if(!l(e))throw a.LogNotDefinedError();if(!x.isLog(e))throw a.NotALogError();if(this.id!==e.id)return;const n=x.difference(e,this),i=this._identity.provider,s=Object.values(n);await r(s,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`)},{concurrency:1}),await r(s,async e=>{const t=await o.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.cid}" and key "${n}"`)},{concurrency:1});Object.values(n).forEach(e=>{this.get(e.cid)||this._length++,e.next.forEach(t=>this._nextsIndex[t]=e.cid)}),this._entryIndex=Object.assign(this._entryIndex,n);const c=Object.values(n).map(m).reduce(k,[]),u=x.findHeads(Object.values(Object.assign({},this._headsIndex,e._headsIndex))).filter(e=>!c.find(t=>t===e.cid)).filter(e=>!this._nextsIndex[e.cid]).reduce(y,{});if(this._headsIndex=u,t>-1){let e=this.values;e=e.slice(-t),this._entryIndex=e.reduce(y,{}),this._headsIndex=x.findHeads(e),this._length=Object.values(this._entryIndex).length}const h=Object.values(this._headsIndex).reduce(g,0);return this._clock=new f(this.clock.id,Math.max(this.clock.time,h)),this}toJSON(){return{id:this.id,heads:this.heads.sort(this._sortFn).reverse().map(p)}}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=o.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).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}toCID(){return s.toCID(this._storage,this)}toMultihash(){return s.toMultihash(this._storage,this)}static async fromCID(e,t,n,r,i=-1,o,a){const f=await s.fromCID(e,r,i,o,a);return new x(e,t,n,f.id,f.values,f.heads,f.clock)}static async fromMultihash(e,t,n,r,i=-1,o,s){return x.fromCID(e,t,n,r,i,o,s)}static async fromEntryCid(e,t,n,r,i,o=-1,a,f){const c=await s.fromEntryCid(e,r,o,a,f);return new x(e,t,n,i,c.values)}static async fromEntryHash(e,t,n,r,i,o=-1,s,a){return x.fromEntryCid(e,t,n,r,i,o,s,a)}static async fromJSON(e,t,n,r,i=-1,o,a){const f=await s.fromJSON(e,r,i,o,a);return new x(e,t,n,f.id,f.values)}static async fromEntry(e,t,n,r,i=-1,o,a){const f=await s.fromEntry(e,r,i,o,a);return new x(e,t,n,f.id,f.values)}static findHeads(e){var t=e.reduce((e,t,n,r)=>{return t.next.forEach(n=>e[n]=t.cid),e},{});return e.filter(e=>void 0===t[e.cid]).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.cid]=!0});const s=i.filter(e=>void 0===r[e]).map(e=>t[e]).reduce((e,t,n,r)=>e.concat(d(t,"cid")),[]).concat(n);return d(s,"cid").sort(o.compare)}static findTailCids(e){var t={};return e.forEach(e=>t[e.cid]=!0),e.reduce((e,n,r,i)=>{return n.next.reverse().forEach(n=>{void 0===t[n]&&e.splice(0,0,n)}),e},[])}static difference(e,t){let n=Object.keys(e._headsIndex),r={},i={};const o=e=>{r[e]||t.get(e)||(n.push(e),r[e]=!0)};for(;n.length>0;){const s=n.shift(),a=e.get(s);a&&!t.get(s)&&a.id===t.id&&(i[a.cid]=a,r[a.cid]=!0,a.next.forEach(o))}return i}}e.exports=x,e.exports.AccessController=h}).call(this,n(0).Buffer)},function(e,t,n){"use strict";t.byteLength=function(e){var t=c(e),n=t[0],r=t[1];return 3*(n+r)/4-r},t.toByteArray=function(e){for(var t,n=c(e),r=n[0],s=n[1],a=new o(function(e,t,n){return 3*(t+n)/4-n}(0,r,s)),f=0,u=s>0?r-4:r,h=0;h>16&255,a[f++]=t>>8&255,a[f++]=255&t;2===s&&(t=i[e.charCodeAt(h)]<<2|i[e.charCodeAt(h+1)]>>4,a[f++]=255&t);1===s&&(t=i[e.charCodeAt(h)]<<10|i[e.charCodeAt(h+1)]<<4|i[e.charCodeAt(h+2)]>>2,a[f++]=t>>8&255,a[f++]=255&t);return a},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,o=[],s=0,a=n-i;sa?a:s+16383));1===i?(t=e[n-1],o.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],o.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"="));return o.join("")};for(var r=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,f=s.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 u(e,t,n){for(var i,o,s=[],a=t;a>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(e,t){t.read=function(e,t,n,r,i){var o,s,a=8*i-r-1,f=(1<>1,u=-7,h=n?i-1:0,l=n?-1:1,d=e[t+h];for(h+=l,o=d&(1<<-u)-1,d>>=-u,u+=a;u>0;o=256*o+e[t+h],h+=l,u-=8);for(s=o&(1<<-u)-1,o>>=-u,u+=r;u>0;s=256*s+e[t+h],h+=l,u-=8);if(0===o)o=1-c;else{if(o===f)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,r),o-=c}return(d?-1:1)*s*Math.pow(2,o-r)},t.write=function(e,t,n,r,i,o){var s,a,f,c=8*o-i-1,u=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=r?0:o-1,b=r?1:-1,p=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=u):(s=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-s))<1&&(s--,f*=2),(t+=s+h>=1?l/f:l*Math.pow(2,1-h))*f>=2&&(s++,f/=2),s+h>=u?(a=0,s=u):s+h>=1?(a=(t*f-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[n+d]=255&a,d+=b,a/=256,i-=8);for(s=s<0;e[n+d]=255&s,d+=b,s/=256,c-=8);e[n+d-b]|=128*p}},function(e,t){var n={}.toString;e.exports=Array.isArray||function(e){return"[object Array]"==n.call(e)}},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 o=void 0!==i[n?t[n]:t],s=void 0!==r[n?t[n]:t];return o||s||(e.push(t),r[n?t[n]:t]=!0),e},[])}},function(e,t,n){"use strict";e.exports=function(e,t){let 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(54),o=n(99)(i.DAGNode.create),s=e=>e?Array.isArray(e)?e.map(s):{"/":e}:e,a=e=>e?Array.isArray(e)?e.map(a):e.toBaseEncodedString():e,f={"dag-pb":{read:async(e,t)=>{const n=(await e.dag.get(t)).value;return JSON.parse(n.toJSON().data)},write:async(e,n)=>{const r=t.from(JSON.stringify(n)),i=await o(r);return(await e.dag.put(i,{format:"dag-pb",hashAlg:"sha2-256"})).toV0().toBaseEncodedString()}},"dag-cbor":{write:async(e,t,n)=>{const r=Object.assign({},t);return n.forEach(e=>{r[e]=s(r[e])}),(await e.dag.put(r)).toBaseEncodedString()},read:async(e,t,n)=>{const r=(await e.dag.get(t)).value;return n.forEach(e=>{r[e]=a(r[e])}),r}}};e.exports={read:(e,t,n)=>{t=new r(t);const i=f[t.codec];if(!i)throw new Error("Unsupported codec");return i.read(e,t,n)},write:(e,t,n,r)=>{const i=f[t];if(!i)throw new Error("Unsupported codec");return i.write(e,n,r)}}}).call(this,n(0).Buffer)},function(e,t,n){var r=n(20);e.exports=r("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},function(e,t,n){"use strict";t.names=Object.freeze({id:0,sha1:17,"sha2-256":18,"sha2-512":19,"dbl-sha2-256":86,"sha3-224":23,"sha3-256":22,"sha3-384":21,"sha3-512":20,"shake-128":24,"shake-256":25,"keccak-224":26,"keccak-256":27,"keccak-384":28,"keccak-512":29,"murmur3-128":34,"murmur3-32":35,"blake2b-8":45569,"blake2b-16":45570,"blake2b-24":45571,"blake2b-32":45572,"blake2b-40":45573,"blake2b-48":45574,"blake2b-56":45575,"blake2b-64":45576,"blake2b-72":45577,"blake2b-80":45578,"blake2b-88":45579,"blake2b-96":45580,"blake2b-104":45581,"blake2b-112":45582,"blake2b-120":45583,"blake2b-128":45584,"blake2b-136":45585,"blake2b-144":45586,"blake2b-152":45587,"blake2b-160":45588,"blake2b-168":45589,"blake2b-176":45590,"blake2b-184":45591,"blake2b-192":45592,"blake2b-200":45593,"blake2b-208":45594,"blake2b-216":45595,"blake2b-224":45596,"blake2b-232":45597,"blake2b-240":45598,"blake2b-248":45599,"blake2b-256":45600,"blake2b-264":45601,"blake2b-272":45602,"blake2b-280":45603,"blake2b-288":45604,"blake2b-296":45605,"blake2b-304":45606,"blake2b-312":45607,"blake2b-320":45608,"blake2b-328":45609,"blake2b-336":45610,"blake2b-344":45611,"blake2b-352":45612,"blake2b-360":45613,"blake2b-368":45614,"blake2b-376":45615,"blake2b-384":45616,"blake2b-392":45617,"blake2b-400":45618,"blake2b-408":45619,"blake2b-416":45620,"blake2b-424":45621,"blake2b-432":45622,"blake2b-440":45623,"blake2b-448":45624,"blake2b-456":45625,"blake2b-464":45626,"blake2b-472":45627,"blake2b-480":45628,"blake2b-488":45629,"blake2b-496":45630,"blake2b-504":45631,"blake2b-512":45632,"blake2s-8":45633,"blake2s-16":45634,"blake2s-24":45635,"blake2s-32":45636,"blake2s-40":45637,"blake2s-48":45638,"blake2s-56":45639,"blake2s-64":45640,"blake2s-72":45641,"blake2s-80":45642,"blake2s-88":45643,"blake2s-96":45644,"blake2s-104":45645,"blake2s-112":45646,"blake2s-120":45647,"blake2s-128":45648,"blake2s-136":45649,"blake2s-144":45650,"blake2s-152":45651,"blake2s-160":45652,"blake2s-168":45653,"blake2s-176":45654,"blake2s-184":45655,"blake2s-192":45656,"blake2s-200":45657,"blake2s-208":45658,"blake2s-216":45659,"blake2s-224":45660,"blake2s-232":45661,"blake2s-240":45662,"blake2s-248":45663,"blake2s-256":45664,"Skein256-8":45825,"Skein256-16":45826,"Skein256-24":45827,"Skein256-32":45828,"Skein256-40":45829,"Skein256-48":45830,"Skein256-56":45831,"Skein256-64":45832,"Skein256-72":45833,"Skein256-80":45834,"Skein256-88":45835,"Skein256-96":45836,"Skein256-104":45837,"Skein256-112":45838,"Skein256-120":45839,"Skein256-128":45840,"Skein256-136":45841,"Skein256-144":45842,"Skein256-152":45843,"Skein256-160":45844,"Skein256-168":45845,"Skein256-176":45846,"Skein256-184":45847,"Skein256-192":45848,"Skein256-200":45849,"Skein256-208":45850,"Skein256-216":45851,"Skein256-224":45852,"Skein256-232":45853,"Skein256-240":45854,"Skein256-248":45855,"Skein256-256":45856,"Skein512-8":45857,"Skein512-16":45858,"Skein512-24":45859,"Skein512-32":45860,"Skein512-40":45861,"Skein512-48":45862,"Skein512-56":45863,"Skein512-64":45864,"Skein512-72":45865,"Skein512-80":45866,"Skein512-88":45867,"Skein512-96":45868,"Skein512-104":45869,"Skein512-112":45870,"Skein512-120":45871,"Skein512-128":45872,"Skein512-136":45873,"Skein512-144":45874,"Skein512-152":45875,"Skein512-160":45876,"Skein512-168":45877,"Skein512-176":45878,"Skein512-184":45879,"Skein512-192":45880,"Skein512-200":45881,"Skein512-208":45882,"Skein512-216":45883,"Skein512-224":45884,"Skein512-232":45885,"Skein512-240":45886,"Skein512-248":45887,"Skein512-256":45888,"Skein512-264":45889,"Skein512-272":45890,"Skein512-280":45891,"Skein512-288":45892,"Skein512-296":45893,"Skein512-304":45894,"Skein512-312":45895,"Skein512-320":45896,"Skein512-328":45897,"Skein512-336":45898,"Skein512-344":45899,"Skein512-352":45900,"Skein512-360":45901,"Skein512-368":45902,"Skein512-376":45903,"Skein512-384":45904,"Skein512-392":45905,"Skein512-400":45906,"Skein512-408":45907,"Skein512-416":45908,"Skein512-424":45909,"Skein512-432":45910,"Skein512-440":45911,"Skein512-448":45912,"Skein512-456":45913,"Skein512-464":45914,"Skein512-472":45915,"Skein512-480":45916,"Skein512-488":45917,"Skein512-496":45918,"Skein512-504":45919,"Skein512-512":45920,"Skein1024-8":45921,"Skein1024-16":45922,"Skein1024-24":45923,"Skein1024-32":45924,"Skein1024-40":45925,"Skein1024-48":45926,"Skein1024-56":45927,"Skein1024-64":45928,"Skein1024-72":45929,"Skein1024-80":45930,"Skein1024-88":45931,"Skein1024-96":45932,"Skein1024-104":45933,"Skein1024-112":45934,"Skein1024-120":45935,"Skein1024-128":45936,"Skein1024-136":45937,"Skein1024-144":45938,"Skein1024-152":45939,"Skein1024-160":45940,"Skein1024-168":45941,"Skein1024-176":45942,"Skein1024-184":45943,"Skein1024-192":45944,"Skein1024-200":45945,"Skein1024-208":45946,"Skein1024-216":45947,"Skein1024-224":45948,"Skein1024-232":45949,"Skein1024-240":45950,"Skein1024-248":45951,"Skein1024-256":45952,"Skein1024-264":45953,"Skein1024-272":45954,"Skein1024-280":45955,"Skein1024-288":45956,"Skein1024-296":45957,"Skein1024-304":45958,"Skein1024-312":45959,"Skein1024-320":45960,"Skein1024-328":45961,"Skein1024-336":45962,"Skein1024-344":45963,"Skein1024-352":45964,"Skein1024-360":45965,"Skein1024-368":45966,"Skein1024-376":45967,"Skein1024-384":45968,"Skein1024-392":45969,"Skein1024-400":45970,"Skein1024-408":45971,"Skein1024-416":45972,"Skein1024-424":45973,"Skein1024-432":45974,"Skein1024-440":45975,"Skein1024-448":45976,"Skein1024-456":45977,"Skein1024-464":45978,"Skein1024-472":45979,"Skein1024-480":45980,"Skein1024-488":45981,"Skein1024-496":45982,"Skein1024-504":45983,"Skein1024-512":45984,"Skein1024-520":45985,"Skein1024-528":45986,"Skein1024-536":45987,"Skein1024-544":45988,"Skein1024-552":45989,"Skein1024-560":45990,"Skein1024-568":45991,"Skein1024-576":45992,"Skein1024-584":45993,"Skein1024-592":45994,"Skein1024-600":45995,"Skein1024-608":45996,"Skein1024-616":45997,"Skein1024-624":45998,"Skein1024-632":45999,"Skein1024-640":46e3,"Skein1024-648":46001,"Skein1024-656":46002,"Skein1024-664":46003,"Skein1024-672":46004,"Skein1024-680":46005,"Skein1024-688":46006,"Skein1024-696":46007,"Skein1024-704":46008,"Skein1024-712":46009,"Skein1024-720":46010,"Skein1024-728":46011,"Skein1024-736":46012,"Skein1024-744":46013,"Skein1024-752":46014,"Skein1024-760":46015,"Skein1024-768":46016,"Skein1024-776":46017,"Skein1024-784":46018,"Skein1024-792":46019,"Skein1024-800":46020,"Skein1024-808":46021,"Skein1024-816":46022,"Skein1024-824":46023,"Skein1024-832":46024,"Skein1024-840":46025,"Skein1024-848":46026,"Skein1024-856":46027,"Skein1024-864":46028,"Skein1024-872":46029,"Skein1024-880":46030,"Skein1024-888":46031,"Skein1024-896":46032,"Skein1024-904":46033,"Skein1024-912":46034,"Skein1024-920":46035,"Skein1024-928":46036,"Skein1024-936":46037,"Skein1024-944":46038,"Skein1024-952":46039,"Skein1024-960":46040,"Skein1024-968":46041,"Skein1024-976":46042,"Skein1024-984":46043,"Skein1024-992":46044,"Skein1024-1000":46045,"Skein1024-1008":46046,"Skein1024-1016":46047,"Skein1024-1024":46048}),t.codes=Object.freeze({17:"sha1",18:"sha2-256",19:"sha2-512",86:"dbl-sha2-256",23:"sha3-224",22:"sha3-256",21:"sha3-384",20:"sha3-512",24:"shake-128",25:"shake-256",26:"keccak-224",27:"keccak-256",28:"keccak-384",29:"keccak-512",34:"murmur3-128",35:"murmur3-32",45569:"blake2b-8",45570:"blake2b-16",45571:"blake2b-24",45572:"blake2b-32",45573:"blake2b-40",45574:"blake2b-48",45575:"blake2b-56",45576:"blake2b-64",45577:"blake2b-72",45578:"blake2b-80",45579:"blake2b-88",45580:"blake2b-96",45581:"blake2b-104",45582:"blake2b-112",45583:"blake2b-120",45584:"blake2b-128",45585:"blake2b-136",45586:"blake2b-144",45587:"blake2b-152",45588:"blake2b-160",45589:"blake2b-168",45590:"blake2b-176",45591:"blake2b-184",45592:"blake2b-192",45593:"blake2b-200",45594:"blake2b-208",45595:"blake2b-216",45596:"blake2b-224",45597:"blake2b-232",45598:"blake2b-240",45599:"blake2b-248",45600:"blake2b-256",45601:"blake2b-264",45602:"blake2b-272",45603:"blake2b-280",45604:"blake2b-288",45605:"blake2b-296",45606:"blake2b-304",45607:"blake2b-312",45608:"blake2b-320",45609:"blake2b-328",45610:"blake2b-336",45611:"blake2b-344",45612:"blake2b-352",45613:"blake2b-360",45614:"blake2b-368",45615:"blake2b-376",45616:"blake2b-384",45617:"blake2b-392",45618:"blake2b-400",45619:"blake2b-408",45620:"blake2b-416",45621:"blake2b-424",45622:"blake2b-432",45623:"blake2b-440",45624:"blake2b-448",45625:"blake2b-456",45626:"blake2b-464",45627:"blake2b-472",45628:"blake2b-480",45629:"blake2b-488",45630:"blake2b-496",45631:"blake2b-504",45632:"blake2b-512",45633:"blake2s-8",45634:"blake2s-16",45635:"blake2s-24",45636:"blake2s-32",45637:"blake2s-40",45638:"blake2s-48",45639:"blake2s-56",45640:"blake2s-64",45641:"blake2s-72",45642:"blake2s-80",45643:"blake2s-88",45644:"blake2s-96",45645:"blake2s-104",45646:"blake2s-112",45647:"blake2s-120",45648:"blake2s-128",45649:"blake2s-136",45650:"blake2s-144",45651:"blake2s-152",45652:"blake2s-160",45653:"blake2s-168",45654:"blake2s-176",45655:"blake2s-184",45656:"blake2s-192",45657:"blake2s-200",45658:"blake2s-208",45659:"blake2s-216",45660:"blake2s-224",45661:"blake2s-232",45662:"blake2s-240",45663:"blake2s-248",45664:"blake2s-256",45825:"Skein256-8",45826:"Skein256-16",45827:"Skein256-24",45828:"Skein256-32",45829:"Skein256-40",45830:"Skein256-48",45831:"Skein256-56",45832:"Skein256-64",45833:"Skein256-72",45834:"Skein256-80",45835:"Skein256-88",45836:"Skein256-96",45837:"Skein256-104",45838:"Skein256-112",45839:"Skein256-120",45840:"Skein256-128",45841:"Skein256-136",45842:"Skein256-144",45843:"Skein256-152",45844:"Skein256-160",45845:"Skein256-168",45846:"Skein256-176",45847:"Skein256-184",45848:"Skein256-192",45849:"Skein256-200",45850:"Skein256-208",45851:"Skein256-216",45852:"Skein256-224",45853:"Skein256-232",45854:"Skein256-240",45855:"Skein256-248",45856:"Skein256-256",45857:"Skein512-8",45858:"Skein512-16",45859:"Skein512-24",45860:"Skein512-32",45861:"Skein512-40",45862:"Skein512-48",45863:"Skein512-56",45864:"Skein512-64",45865:"Skein512-72",45866:"Skein512-80",45867:"Skein512-88",45868:"Skein512-96",45869:"Skein512-104",45870:"Skein512-112",45871:"Skein512-120",45872:"Skein512-128",45873:"Skein512-136",45874:"Skein512-144",45875:"Skein512-152",45876:"Skein512-160",45877:"Skein512-168",45878:"Skein512-176",45879:"Skein512-184",45880:"Skein512-192",45881:"Skein512-200",45882:"Skein512-208",45883:"Skein512-216",45884:"Skein512-224",45885:"Skein512-232",45886:"Skein512-240",45887:"Skein512-248",45888:"Skein512-256",45889:"Skein512-264",45890:"Skein512-272",45891:"Skein512-280",45892:"Skein512-288",45893:"Skein512-296",45894:"Skein512-304",45895:"Skein512-312",45896:"Skein512-320",45897:"Skein512-328",45898:"Skein512-336",45899:"Skein512-344",45900:"Skein512-352",45901:"Skein512-360",45902:"Skein512-368",45903:"Skein512-376",45904:"Skein512-384",45905:"Skein512-392",45906:"Skein512-400",45907:"Skein512-408",45908:"Skein512-416",45909:"Skein512-424",45910:"Skein512-432",45911:"Skein512-440",45912:"Skein512-448",45913:"Skein512-456",45914:"Skein512-464",45915:"Skein512-472",45916:"Skein512-480",45917:"Skein512-488",45918:"Skein512-496",45919:"Skein512-504",45920:"Skein512-512",45921:"Skein1024-8",45922:"Skein1024-16",45923:"Skein1024-24",45924:"Skein1024-32",45925:"Skein1024-40",45926:"Skein1024-48",45927:"Skein1024-56",45928:"Skein1024-64",45929:"Skein1024-72",45930:"Skein1024-80",45931:"Skein1024-88",45932:"Skein1024-96",45933:"Skein1024-104",45934:"Skein1024-112",45935:"Skein1024-120",45936:"Skein1024-128",45937:"Skein1024-136",45938:"Skein1024-144",45939:"Skein1024-152",45940:"Skein1024-160",45941:"Skein1024-168",45942:"Skein1024-176",45943:"Skein1024-184",45944:"Skein1024-192",45945:"Skein1024-200",45946:"Skein1024-208",45947:"Skein1024-216",45948:"Skein1024-224",45949:"Skein1024-232",45950:"Skein1024-240",45951:"Skein1024-248",45952:"Skein1024-256",45953:"Skein1024-264",45954:"Skein1024-272",45955:"Skein1024-280",45956:"Skein1024-288",45957:"Skein1024-296",45958:"Skein1024-304",45959:"Skein1024-312",45960:"Skein1024-320",45961:"Skein1024-328",45962:"Skein1024-336",45963:"Skein1024-344",45964:"Skein1024-352",45965:"Skein1024-360",45966:"Skein1024-368",45967:"Skein1024-376",45968:"Skein1024-384",45969:"Skein1024-392",45970:"Skein1024-400",45971:"Skein1024-408",45972:"Skein1024-416",45973:"Skein1024-424",45974:"Skein1024-432",45975:"Skein1024-440",45976:"Skein1024-448",45977:"Skein1024-456",45978:"Skein1024-464",45979:"Skein1024-472",45980:"Skein1024-480",45981:"Skein1024-488",45982:"Skein1024-496",45983:"Skein1024-504",45984:"Skein1024-512",45985:"Skein1024-520",45986:"Skein1024-528",45987:"Skein1024-536",45988:"Skein1024-544",45989:"Skein1024-552",45990:"Skein1024-560",45991:"Skein1024-568",45992:"Skein1024-576",45993:"Skein1024-584",45994:"Skein1024-592",45995:"Skein1024-600",45996:"Skein1024-608",45997:"Skein1024-616",45998:"Skein1024-624",45999:"Skein1024-632",46000:"Skein1024-640",46001:"Skein1024-648",46002:"Skein1024-656",46003:"Skein1024-664",46004:"Skein1024-672",46005:"Skein1024-680",46006:"Skein1024-688",46007:"Skein1024-696",46008:"Skein1024-704",46009:"Skein1024-712",46010:"Skein1024-720",46011:"Skein1024-728",46012:"Skein1024-736",46013:"Skein1024-744",46014:"Skein1024-752",46015:"Skein1024-760",46016:"Skein1024-768",46017:"Skein1024-776",46018:"Skein1024-784",46019:"Skein1024-792",46020:"Skein1024-800",46021:"Skein1024-808",46022:"Skein1024-816",46023:"Skein1024-824",46024:"Skein1024-832",46025:"Skein1024-840",46026:"Skein1024-848",46027:"Skein1024-856",46028:"Skein1024-864",46029:"Skein1024-872",46030:"Skein1024-880",46031:"Skein1024-888",46032:"Skein1024-896",46033:"Skein1024-904",46034:"Skein1024-912",46035:"Skein1024-920",46036:"Skein1024-928",46037:"Skein1024-936",46038:"Skein1024-944",46039:"Skein1024-952",46040:"Skein1024-960",46041:"Skein1024-968",46042:"Skein1024-976",46043:"Skein1024-984",46044:"Skein1024-992",46045:"Skein1024-1000",46046:"Skein1024-1008",46047:"Skein1024-1016",46048:"Skein1024-1024"}),t.defaultLengths=Object.freeze({17:20,18:32,19:64,86:32,23:28,22:32,21:48,20:64,24:32,25:64,26:28,27:32,28:48,29:64,34:32,45569:1,45570:2,45571:3,45572:4,45573:5,45574:6,45575:7,45576:8,45577:9,45578:10,45579:11,45580:12,45581:13,45582:14,45583:15,45584:16,45585:17,45586:18,45587:19,45588:20,45589:21,45590:22,45591:23,45592:24,45593:25,45594:26,45595:27,45596:28,45597:29,45598:30,45599:31,45600:32,45601:33,45602:34,45603:35,45604:36,45605:37,45606:38,45607:39,45608:40,45609:41,45610:42,45611:43,45612:44,45613:45,45614:46,45615:47,45616:48,45617:49,45618:50,45619:51,45620:52,45621:53,45622:54,45623:55,45624:56,45625:57,45626:58,45627:59,45628:60,45629:61,45630:62,45631:63,45632:64,45633:1,45634:2,45635:3,45636:4,45637:5,45638:6,45639:7,45640:8,45641:9,45642:10,45643:11,45644:12,45645:13,45646:14,45647:15,45648:16,45649:17,45650:18,45651:19,45652:20,45653:21,45654:22,45655:23,45656:24,45657:25,45658:26,45659:27,45660:28,45661:29,45662:30,45663:31,45664:32,45825:1,45826:2,45827:3,45828:4,45829:5,45830:6,45831:7,45832:8,45833:9,45834:10,45835:11,45836:12,45837:13,45838:14,45839:15,45840:16,45841:17,45842:18,45843:19,45844:20,45845:21,45846:22,45847:23,45848:24,45849:25,45850:26,45851:27,45852:28,45853:29,45854:30,45855:31,45856:32,45857:1,45858:2,45859:3,45860:4,45861:5,45862:6,45863:7,45864:8,45865:9,45866:10,45867:11,45868:12,45869:13,45870:14,45871:15,45872:16,45873:17,45874:18,45875:19,45876:20,45877:21,45878:22,45879:23,45880:24,45881:25,45882:26,45883:27,45884:28,45885:29,45886:30,45887:31,45888:32,45889:33,45890:34,45891:35,45892:36,45893:37,45894:38,45895:39,45896:40,45897:41,45898:42,45899:43,45900:44,45901:45,45902:46,45903:47,45904:48,45905:49,45906:50,45907:51,45908:52,45909:53,45910:54,45911:55,45912:56,45913:57,45914:58,45915:59,45916:60,45917:61,45918:62,45919:63,45920:64,45921:1,45922:2,45923:3,45924:4,45925:5,45926:6,45927:7,45928:8,45929:9,45930:10,45931:11,45932:12,45933:13,45934:14,45935:15,45936:16,45937:17,45938:18,45939:19,45940:20,45941:21,45942:22,45943:23,45944:24,45945:25,45946:26,45947:27,45948:28,45949:29,45950:30,45951:31,45952:32,45953:33,45954:34,45955:35,45956:36,45957:37,45958:38,45959:39,45960:40,45961:41,45962:42,45963:43,45964:44,45965:45,45966:46,45967:47,45968:48,45969:49,45970:50,45971:51,45972:52,45973:53,45974:54,45975:55,45976:56,45977:57,45978:58,45979:59,45980:60,45981:61,45982:62,45983:63,45984:64,45985:65,45986:66,45987:67,45988:68,45989:69,45990:70,45991:71,45992:72,45993:73,45994:74,45995:75,45996:76,45997:77,45998:78,45999:79,46000:80,46001:81,46002:82,46003:83,46004:84,46005:85,46006:86,46007:87,46008:88,46009:89,46010:90,46011:91,46012:92,46013:93,46014:94,46015:95,46016:96,46017:97,46018:98,46019:99,46020:100,46021:101,46022:102,46023:103,46024:104,46025:105,46026:106,46027:107,46028:108,46029:109,46030:110,46031:111,46032:112,46033:113,46034:114,46035:115,46036:116,46037:117,46038:118,46039:119,46040:120,46041:121,46042:122,46043:123,46044:124,46045:125,46046:126,46047:127,46048:128})},function(e,t){e.exports=function e(t,o,s){o=o||[];s=s||0;var a=s;for(;t>=i;)o[s++]=255&t|n,t/=128;for(;t&r;)o[s++]=255&t|n,t>>>=7;o[s]=0|t;e.bytes=s-a+1;return o};var n=128,r=-128,i=Math.pow(2,31)},function(e,t){e.exports=function e(t,i){var o,s=0,i=i||0,a=0,f=i,c=t.length;do{if(f>=c)throw e.bytes=0,new RangeError("Could not decode varint");o=t[f++],s+=a<28?(o&r)<=n);e.bytes=f-i;return s};var n=128,r=127},function(e,t){var n=Math.pow(2,7),r=Math.pow(2,14),i=Math.pow(2,21),o=Math.pow(2,28),s=Math.pow(2,35),a=Math.pow(2,42),f=Math.pow(2,49),c=Math.pow(2,56),u=Math.pow(2,63);e.exports=function(e){return e(e[t[0]]=new r(t[0],t[1],t[2],t[3]),e),{}),u=f.reduce((e,t)=>(e[t[1]]=c[t[0]],e),{});e.exports={names:c,codes:u}},function(e,t,n){"use strict";e.exports=class{constructor(e,t,n,r){this.name=e,this.code=t,this.alphabet=r,n&&r&&(this.engine=n(r))}encode(e){return this.engine.encode(e)}decode(e){return this.engine.decode(e)}isImplemented(){return this.engine}}},function(e,t,n){"use strict";(function(t){e.exports=function(e){return{encode:e=>"string"==typeof e?t.from(e).toString("hex"):e.toString("hex"),decode(n){for(let t of n)if(e.indexOf(t)<0)throw new Error("invalid base16 character");return t.from(n,"hex")}}}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(t){function n(e,t){let n=e.byteLength,r=new Uint8Array(e),i=t.indexOf("=")===t.length-1;i&&(t=t.substring(0,t.length-2));let o=0,s=0,a="";for(let e=0;e=5;)a+=t[s>>>o-5&31],o-=5;if(o>0&&(a+=t[s<<5-o&31]),i)for(;a.length%8!=0;)a+="=";return a}e.exports=function(e){return{encode:r=>n("string"==typeof r?t.from(r):r,e),decode(t){for(let n of t)if(e.indexOf(n)<0)throw new Error("invalid base32 character");return function(e,t){let n=(e=e.replace(new RegExp("=","g"),"")).length,r=0,i=0,o=0,s=new Uint8Array(5*n/8|0);for(let a=0;a=8&&(s[o++]=i>>>r-8&255,r-=8);return s.buffer}(t,e)}}}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(t){e.exports=function(e){const n=e.indexOf("=")>-1,r=e.indexOf("-")>-1&&e.indexOf("_")>-1;return{encode(e){let i="";i="string"==typeof e?t.from(e).toString("base64"):e.toString("base64"),r&&(i=i.replace(/\+/g,"-").replace(/\//g,"_"));const o=i.indexOf("=");return o>0&&!n&&(i=i.substring(0,o)),i},decode(n){for(let t of n)if(e.indexOf(t)<0)throw new Error("invalid base64 character");return t.from(n,"base64")}}}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(r){const i=n(1),o=n(51),s=n(52),a=n(22);(t=e.exports).addPrefix=((e,t)=>{let n;if(r.isBuffer(e))n=a.varintBufferEncode(e);else{if(!o[e])throw new Error("multicodec not recognized");n=o[e]}return r.concat([n,t])}),t.rmPrefix=(e=>(i.decode(e),e.slice(i.decode.bytes))),t.getCodec=(e=>{const t=a.varintBufferDecode(e),n=s[t.toString("hex")];if(void 0===n)throw new Error("Code `0x"+t.toString("hex")+"` not found");return n}),t.getCodeVarint=(e=>{const t=o[e];if(void 0===t)throw new Error("Codec `"+e+"` not found");return t}),t.addCodec=((e,t)=>{o[e]=a.varintBufferEncode(t),s[t.toString("hex")]=e})}).call(this,n(0).Buffer)},function(e,t,n){"use strict";const r=n(14),i=n(22).varintBufferEncode,o={};e.exports=o;for(let e in r){let t=r[e];o[e]=i(t)}},function(e,t,n){"use strict";const r=n(14),i={};e.exports=i;for(let e in r){i[r[e].toString("hex")]=e}},function(e,t,n){"use strict";(function(t){const r=n(13);var i={checkCIDComponents:function(e){if(null==e)return"null values are not valid CIDs";if(0!==e.version&&1!==e.version)return"Invalid version, must be a number equal to 1 or 0";if("string"!=typeof e.codec)return"codec must be string";if(!t.isBuffer(e.multihash))return"multihash must be a Buffer";try{r.validate(e.multihash)}catch(e){let t=e.message;return t||(t="Multihash validation failed"),t}}};e.exports=i}).call(this,n(0).Buffer)},function(e,t,n){"use strict";t.DAGNode=n(7),t.DAGLink=n(3),t.resolver=n(24),t.util=n(9)},function(e,t,n){(function(e,r){var i=/%[sdj%]/g;t.format=function(e){if(!m(e)){for(var t=[],n=0;n=o)return e;switch(e){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(e){return"[Circular]"}default:return e}}),f=r[n];n=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),b(n)?r.showHidden=n:n&&t._extend(r,n),g(r.showHidden)&&(r.showHidden=!1),g(r.depth)&&(r.depth=2),g(r.colors)&&(r.colors=!1),g(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=f),u(r,e,r.depth)}function f(e,t){var n=a.styles[t];return n?"["+a.colors[n][0]+"m"+e+"["+a.colors[n][1]+"m":e}function c(e,t){return e}function u(e,n,r){if(e.customInspect&&n&&S(n.inspect)&&n.inspect!==t.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,e);return m(i)||(i=u(e,i,r)),i}var o=function(e,t){if(g(t))return e.stylize("undefined","undefined");if(m(t)){var n="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(n,"string")}if(k(t))return e.stylize(""+t,"number");if(b(t))return e.stylize(""+t,"boolean");if(p(t))return e.stylize("null","null")}(e,n);if(o)return o;var s=Object.keys(n),a=function(e){var t={};return e.forEach(function(e,n){t[e]=!0}),t}(s);if(e.showHidden&&(s=Object.getOwnPropertyNames(n)),v(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return h(n);if(0===s.length){if(S(n)){var f=n.name?": "+n.name:"";return e.stylize("[Function"+f+"]","special")}if(y(n))return e.stylize(RegExp.prototype.toString.call(n),"regexp");if(w(n))return e.stylize(Date.prototype.toString.call(n),"date");if(v(n))return h(n)}var c,x="",E=!1,A=["{","}"];(d(n)&&(E=!0,A=["[","]"]),S(n))&&(x=" [Function"+(n.name?": "+n.name:"")+"]");return y(n)&&(x=" "+RegExp.prototype.toString.call(n)),w(n)&&(x=" "+Date.prototype.toUTCString.call(n)),v(n)&&(x=" "+h(n)),0!==s.length||E&&0!=n.length?r<0?y(n)?e.stylize(RegExp.prototype.toString.call(n),"regexp"):e.stylize("[Object]","special"):(e.seen.push(n),c=E?function(e,t,n,r,i){for(var o=[],s=0,a=t.length;s=0&&0,e+t.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60)return n[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+n[1];return n[0]+t+" "+e.join(", ")+" "+n[1]}(c,x,A)):A[0]+x+A[1]}function h(e){return"["+Error.prototype.toString.call(e)+"]"}function l(e,t,n,r,i,o){var s,a,f;if((f=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?a=f.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):f.set&&(a=e.stylize("[Setter]","special")),C(r,i)||(s="["+i+"]"),a||(e.seen.indexOf(f.value)<0?(a=p(n)?u(e,f.value,null):u(e,f.value,n-1)).indexOf("\n")>-1&&(a=o?a.split("\n").map(function(e){return" "+e}).join("\n").substr(2):"\n"+a.split("\n").map(function(e){return" "+e}).join("\n")):a=e.stylize("[Circular]","special")),g(s)){if(o&&i.match(/^\d+$/))return a;(s=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=e.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=e.stylize(s,"string"))}return s+": "+a}function d(e){return Array.isArray(e)}function b(e){return"boolean"==typeof e}function p(e){return null===e}function k(e){return"number"==typeof e}function m(e){return"string"==typeof e}function g(e){return void 0===e}function y(e){return x(e)&&"[object RegExp]"===E(e)}function x(e){return"object"==typeof e&&null!==e}function w(e){return x(e)&&"[object Date]"===E(e)}function v(e){return x(e)&&("[object Error]"===E(e)||e instanceof Error)}function S(e){return"function"==typeof e}function E(e){return Object.prototype.toString.call(e)}function A(e){return e<10?"0"+e.toString(10):e.toString(10)}t.debuglog=function(e){if(g(o)&&(o=r.env.NODE_DEBUG||""),e=e.toUpperCase(),!s[e])if(new RegExp("\\b"+e+"\\b","i").test(o)){var n=r.pid;s[e]=function(){var r=t.format.apply(t,arguments);console.error("%s %d: %s",e,n,r)}}else s[e]=function(){};return s[e]},t.inspect=a,a.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},a.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},t.isArray=d,t.isBoolean=b,t.isNull=p,t.isNullOrUndefined=function(e){return null==e},t.isNumber=k,t.isString=m,t.isSymbol=function(e){return"symbol"==typeof e},t.isUndefined=g,t.isRegExp=y,t.isObject=x,t.isDate=w,t.isError=v,t.isFunction=S,t.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},t.isBuffer=n(56);var _=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function C(e,t){return Object.prototype.hasOwnProperty.call(e,t)}t.log=function(){var e,n;console.log("%s - %s",(e=new Date,n=[A(e.getHours()),A(e.getMinutes()),A(e.getSeconds())].join(":"),[e.getDate(),_[e.getMonth()],n].join(" ")),t.format.apply(t,arguments))},t.inherits=n(57),t._extend=function(e,t){if(!t||!x(t))return e;for(var n=Object.keys(t),r=n.length;r--;)e[n[r]]=t[n[r]];return e}}).call(this,n(4),n(2))},function(e,t){e.exports=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8}},function(e,t){"function"==typeof Object.create?e.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:e.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},function(e,t,n){ +//! stable.js 0.1.8, https://github.com/Two-Screen/stable +//! © 2018 Angry Bytes and contributors. MIT licensed. +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),o=1;oc&&(o=c),s>c&&(s=c),a=i,f=o;;)if(a"!==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=o(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:[],messages:[],fields:[],extends:[],extensions:null};e.length;)switch(e[0]){case"map":case"repeated":case"optional":case"required":t.fields.push(s(e));break;case"enum":t.enums.push(b(e));break;case"message":t.messages.push(u(e));break;case"extensions":t.extensions=c(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=s(e);r.oneof=n,t.fields.push(r)}e.shift();break;case"extend":t.extends.push(f(e));break;case";":e.shift();break;case"reserved":case"option":for(e.shift();";"!==e[0];)e.shift();break;default:e.unshift("optional"),t.fields.push(s(e))}return t},f=function(e){return{name:e[1],message:u(e)}},c=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}},u=function(e){e.shift();var t=1,n=[],r={name:e.shift(),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;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=o(e)),e.shift(),{name:t,val:n}},b=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=p(e),n.options[t.name]=t.value}throw new Error("No closing tag for enum")},p=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 o=null;switch(e[0]){case":":if(void 0!==n[i])throw new Error("Duplicate option map key "+i);e.shift(),"{"===(o=t(e.shift()))&&(o=k(e)),n[i]=o,";"===e[0]&&e.shift();break;case"{":if(e.shift(),o=k(e),void 0===n[i]&&(n[i]=[]),!Array.isArray(n[i]))throw new Error("Duplicate option map key "+i);n[i].push(o);break;default:throw new Error("Unexpected token in option map: "+e[0])}}throw new Error("No closing tag for option map")},m=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},g=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=p(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(y(e));break;default:throw new Error("Unexpected token in service: "+e[0])}}throw new Error("No closing tag for service")},y=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=p(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)})})}),s.messages.forEach(function(e){e.fields.forEach(function(t){var n,r,o,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],o=n[1],s.messages.some(function(e){if(e.name===r)return a=e,e}),a&&a.enums&&a.enums.some(function(e){return e.name===o}))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')}})}),s}},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.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 o={};return e.fields||(e.fields=[]),e.fields.forEach(function(e){e.oneof?(o[e.oneof]||(o[e.oneof]=[]),o[e.oneof].push(n(e,[]))):t.push(n(e,[]))}),Object.keys(o).forEach(function(e){o[e].unshift("oneof "+e+" {"),o[e].push("}"),t.push(o[e])}),t.push("}",""),t},i=function(e,t){t.push("enum "+e.name+" {"),e.options||(e.options={});var n=s(e.options,[]);return n.length>1&&t.push(n.slice(0,-1)),Object.keys(e.values).map(function(n){var r=o(e.values[n]);t.push([n+" = "+r+";"])}),t.push("}",""),t},o=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},s=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},f=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=s(e.options,[]);return r.length>1?t.push(n+" {",r.slice(0,-1),"}"):t.push(n+";"),t},c=function(e){return function(t){return Array.isArray(t)?t.map(c(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={}),s(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={}),s(e.options,t),e.methods||(e.methods=[]),e.methods.forEach(function(e){t.push(f(e,[]))}),t.push("}","")}(e,t)}),t.map(c("")).join("\n")}},function(e,t,n){"use strict";var r=n(66),i=n(68),o=n(69),s=n(70),a=n(1);e.exports=function(e,t){var n={},f={},c={},u=function(e,t){e.enums&&e.enums.forEach(function(e){e.id=t+(t?".":"")+e.name,f[e.id]=e,u(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){var i="Map_"+r.map.from+"_"+r.map.to,o={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[o.id]||(n[o.id]=o,e.messages.push(o)),r.type=i,r.repeated=!0}}),u(r,r.id)})};u(e,"");var 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;var 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;var n={};e.fields.forEach(function(e){e.oneof&&(n[e.oneof]||(n[e.oneof]=[]),n[e.oneof].push(e.name))});var r=e.fields.map(function(t){return l(t.type,e.id)}),a=s(e,r,n),f=o(e,l,r,n,a),c=i(e,l,r);return f.bytes=c.bytes=0,t.buffer=!0,t.encode=f,t.decode=c,t.encodingLength=a,t},l=function(e,i,o){if(t&&t[e])return t[e];if(r[e])return r[e];var s,u,l=(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]||f[t]},null);if(!1===o)return l;if(!l)throw new Error("Could not resolve "+e);return l.values?(s=l,u=Object.keys(s.values||[]).map(function(e){return parseInt(s.values[e].value,10)}),r.make(0,function e(t,n,r){if(!u.length||-1===u.indexOf(t))throw new Error("Invalid enum value: "+t);return a.encode(t,n,r),e.bytes=a.encode.bytes,n},function e(t,n){var r=a.decode(t,n);if(!u.length||-1===u.indexOf(r))throw new Error("Invalid enum value: "+r);return e.bytes=a.decode.bytes,r},a.encodingLength)):c[l.id]||h(l,c[l.id]={})};return(e.enums||[]).concat((e.messages||[]).map(function(e){return l(e.id)}))}},function(e,t,n){"use strict";var r,i,o,s=n(1),a=n(67),f=n(21).Buffer,c=function(e,t,n,r){return t.bytes=n.bytes=0,{type:e,encode:t,decode:n,encodingLength:r}};t.make=c,t.bytes=(r=function(e){return f.isBuffer(e)?e.length:f.byteLength(e)},c(2,i=function(e,t,n){var o=n,a=r(e);return s.encode(a,t,n),n+=s.encode.bytes,f.isBuffer(e)?e.copy(t,n):t.write(e,n,a),n+=a,i.bytes=n-o,t},o=function(e,t){var n=t,r=s.decode(e,t);t+=s.decode.bytes;var i=e.slice(t,t+r);return t+=i.length,o.bytes=t-n,i},function(e){var t=r(e);return s.encodingLength(t)+t})),t.string=function(){var e=function(t,n,r){var i=r,o=f.byteLength(t);return s.encode(o,n,r,"utf-8"),r+=s.encode.bytes,n.write(t,r,o),r+=o,e.bytes=r-i,n},t=function(e,n){var r=n,i=s.decode(e,n);n+=s.decode.bytes;var o=e.toString("utf-8",n,n+i);return n+=i,t.bytes=n-r,o};return c(2,e,t,function(e){var t=f.byteLength(e);return s.encodingLength(t)+t})}(),t.bool=function(){var e=function(t,n,r){return n[r]=t?1:0,e.bytes=1,n},t=function(e,n){var r=e[n]>0;return t.bytes=1,r};return c(0,e,t,function(e){return 1})}(),t.int32=function(){var e=function(t,n){var r=s.decode(t,n);return e.bytes=s.decode.bytes,r>2147483647?r-4294967296:r};return c(0,s.encode,e,function(e){return s.encodingLength(e<0?e+4294967296:e)})}(),t.int64=function(){var e=function(t,n){var r=s.decode(t,n);if(r>=Math.pow(2,63)){for(var i=9;255===t[n+i-1];)i--;i=i||9;var o=f.allocUnsafe(i);t.copy(o,0,n,n+i),o[i-1]=127&o[i-1],r=-1*s.decode(o,0),e.bytes=10}else e.bytes=s.decode.bytes;return r},t=function(e,n,r){if(e<0){var i=r+9;for(s.encode(-1*e,n,r),n[r+=s.encode.bytes-1]=128|n[r];r=0?2*t:-2*t-1;var o=r.encode(t,n,i);return e.bytes=r.encode.bytes,o},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){"use strict";var r=n(1),i=n(17).defined;var o=function(e,t,n){switch(e){case 0:return r.decode(t,n),n+r.decode.bytes;case 1:return n+8;case 2:var i=r.decode(t,n);return n+r.decode.bytes+i;case 3:case 4:throw new Error("Groups are not supported");case 5:return n+4;default:throw new Error("Unknown wire type: "+e)}},s=function(e,t){if(e.map)return{};if(e.repeated)return[];switch(e.type){case"string":return null!=t?t:"";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||0,10);default:return null}};e.exports=function(e,t,n){for(var a=[],f={},c=[],u=[],h=0;h-1&&delete n[f[u]];if(e.message){var h=r.decode(i,o);o+=r.decode.bytes;var l=e.decode(i,o,o+h);t.map?(n[a]=n[a]||{},n[a][l.key]=l.value):t.repeated?(n[a]=n[a]||[],n[a].push(l)):n[a]=l}else t.repeated?(n[a]=n[a]||[],n[a].push(e.decode(i,o))):n[a]=e.decode(i,o);return o+=e.decode.bytes}return function t(h,l,d){if(null==l&&(l=0),null==d&&(d=h.length),!(d<=h.length&&l<=h.length))throw new Error("Decoded message is not valid");for(var b,k=l,m={};;){if(d<=l){var g,y,x="",w=0;for(w=0;w-1){v=!0;break}v||(g?b.repeated?m[x]=[]:(y=y&&g[y]?g[y].value:g[Object.keys(g)[0]].value,m[x]=parseInt(y||0,10)):m[x]=s(b,y))}return t.bytes=l-k,m}var A=r.decode(h,l);l+=r.decode.bytes;var _=f[A>>3];if(null!=_){var C=n[_];if((b=e.fields[_]).packed){var B=r.decode(h,l);for(B+=l+=r.decode.bytes;l-1){if(g)throw new Error("only one of the properties defined in oneof "+y+" can be set");g=!0}}for(m=0;m{if(e)return i(e);i(null,r.encode(o,t,n))})}e.exports=o,o.Buffer=t,o.multihash=r,o.digest=function(e,t,n,r){if("function"==typeof n&&(r=n,n=void 0),!r)throw new Error("Missing callback");let i,s=r;n&&(s=((e,t)=>{if(e)return r(e);r(null,t.slice(0,n))}));try{i=o.createHash(t)}catch(e){return s(e)}i(e,s)},o.createHash=function(e){if(e=r.coerceCode(e),!o.functions[e])throw new Error("multihash function "+e+" not yet supported");return o.functions[e]},o.functions={17:i.sha1,18:i.sha2256,19:i.sha2512,20:i.sha3512,21:i.sha3384,22:i.sha3256,23:i.sha3224,24:i.shake128,25:i.shake256,26:i.keccak224,27:i.keccak256,28:i.keccak384,29:i.keccak512,34:i.murmur3128,35:i.murmur332,86:i.dblSha2256},i.addBlake(o.functions)}).call(this,n(0).Buffer)},function(e,t,n){"use strict";(function(t){const r=n(85),i=n(87),o=n(26),s=n(89),a=o.toCallback,f=o.toBuf,c=o.fromString,u=o.fromNumberTo32BitBuf;e.exports={sha1:s.sha1,sha2256:s.sha2256,sha2512:s.sha2512,sha3512:a(f(r.sha3_512)),sha3384:a(f(r.sha3_384)),sha3256:a(f(r.sha3_256)),sha3224:a(f(r.sha3_224)),shake128:a(f(r.shake_128,128)),shake256:a(f(r.shake_256,256)),keccak224:a(f(r.keccak_224)),keccak256:a(f(r.keccak_256)),keccak384:a(f(r.keccak_384)),keccak512:a(f(r.keccak_512)),murmur3128:a(f(c(i.x64.hash128))),murmur332:a(u(c(i.x86.hash32))),addBlake:n(92),dblSha2256:(e,n)=>{s.sha2256(e,(e,r)=>{e&&n(e),s.sha2256(t.from(r),n)})}}}).call(this,n(0).Buffer)},function(e,t,n){(function(r,i){var o; +/** + * [js-sha3]{@link https://github.com/emn178/js-sha3} + * + * @version 0.8.0 + * @author Chen, Yi-Cyuan [emn178@gmail.com] + * @copyright Chen, Yi-Cyuan 2015-2018 + * @license MIT + */ +/** + * [js-sha3]{@link https://github.com/emn178/js-sha3} + * + * @version 0.8.0 + * @author Chen, Yi-Cyuan [emn178@gmail.com] + * @copyright Chen, Yi-Cyuan 2015-2018 + * @license MIT + */ +!function(){"use strict";var s="input is invalid type",a="object"==typeof window,f=a?window:{};f.JS_SHA3_NO_WINDOW&&(a=!1);var c=!a&&"object"==typeof self;!f.JS_SHA3_NO_NODE_JS&&"object"==typeof r&&r.versions&&r.versions.node?f=i:c&&(f=self);var u=!f.JS_SHA3_NO_COMMON_JS&&"object"==typeof e&&e.exports,h=n(86),l=!f.JS_SHA3_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,d="0123456789abcdef".split(""),b=[4,1024,262144,67108864],p=[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],m=[224,256,384,512],g=[128,256],y=["hex","buffer","arrayBuffer","array","digest"],x={128:168,256:136};!f.JS_SHA3_NO_NODE_JS&&Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),!l||!f.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 w=function(e,t,n){return function(r){return new N(e,t,e).update(r)[n]()}},v=function(e,t,n){return function(r,i){return new N(e,t,i).update(r)[n]()}},S=function(e,t,n){return function(t,r,i,o){return B["cshake"+e].update(t,r,i,o)[n]()}},E=function(e,t,n){return function(t,r,i,o){return B["kmac"+e].update(t,r,i,o)[n]()}},A=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 L(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(s);if(null===e)throw new Error(s);if(l&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||l&&ArrayBuffer.isView(e)))throw new Error(s);t=!0}for(var r,i,o=this.blocks,a=this.byteCount,f=e.length,c=this.blockCount,u=0,h=this.s;u>2]|=e[u]<>2]|=i<>2]|=(192|i>>6)<>2]|=(128|63&i)<=57344?(o[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=o[c],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(s);if(null===e)throw new Error(s);if(l&&e.constructor===ArrayBuffer)e=new Uint8Array(e);else if(!(Array.isArray(e)||l&&ArrayBuffer.isView(e)))throw new Error(s);t=!0}var r=0,i=e.length;if(t)r=i;else for(var o=0;o=57344?r+=3:(a=65536+((1023&a)<<10|1023&e.charCodeAt(++o)),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];s%t==0&&(M(n),o=0)}return i&&(e=n[o],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,o=0,s=0,a=this.outputBits>>3;e=i?new ArrayBuffer(r+1<<2):new ArrayBuffer(a);for(var f=new Uint32Array(e);s>8&255,f[e+2]=t>>16&255,f[e+3]=t>>24&255;a%n==0&&M(r)}return o&&(e=a<<2,t=r[s],f[e]=255&t,o>1&&(f[e+1]=t>>8&255),o>2&&(f[e+2]=t>>16&255)),f},L.prototype=new N,L.prototype.finalize=function(){return this.encode(this.outputBits,!0),N.prototype.finalize.call(this)};var M=function(e){var t,n,r,i,o,s,a,f,c,u,h,l,d,b,p,m,g,y,x,w,v,S,E,A,_,C,B,O,I,j,T,D,P,U,N,L,M,z,R,q,F,Y,H,$,J,G,V,W,Z,K,X,Q,ee,te,ne,re,ie,oe,se,ae,fe,ce,ue;for(r=0;r<48;r+=2)i=e[0]^e[10]^e[20]^e[30]^e[40],o=e[1]^e[11]^e[21]^e[31]^e[41],s=e[2]^e[12]^e[22]^e[32]^e[42],a=e[3]^e[13]^e[23]^e[33]^e[43],f=e[4]^e[14]^e[24]^e[34]^e[44],c=e[5]^e[15]^e[25]^e[35]^e[45],u=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])^(s<<1|a>>>31),n=(d=e[9]^e[19]^e[29]^e[39]^e[49])^(a<<1|s>>>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^(f<<1|c>>>31),n=o^(c<<1|f>>>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=s^(u<<1|h>>>31),n=a^(h<<1|u>>>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=f^(l<<1|d>>>31),n=c^(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=u^(i<<1|o>>>31),n=h^(o<<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,b=e[0],p=e[1],G=e[11]<<4|e[10]>>>28,V=e[10]<<4|e[11]>>>28,O=e[20]<<3|e[21]>>>29,I=e[21]<<3|e[20]>>>29,ae=e[31]<<9|e[30]>>>23,fe=e[30]<<9|e[31]>>>23,Y=e[40]<<18|e[41]>>>14,H=e[41]<<18|e[40]>>>14,U=e[2]<<1|e[3]>>>31,N=e[3]<<1|e[2]>>>31,m=e[13]<<12|e[12]>>>20,g=e[12]<<12|e[13]>>>20,W=e[22]<<10|e[23]>>>22,Z=e[23]<<10|e[22]>>>22,j=e[33]<<13|e[32]>>>19,T=e[32]<<13|e[33]>>>19,ce=e[42]<<2|e[43]>>>30,ue=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,L=e[14]<<6|e[15]>>>26,M=e[15]<<6|e[14]>>>26,y=e[25]<<11|e[24]>>>21,x=e[24]<<11|e[25]>>>21,K=e[34]<<15|e[35]>>>17,X=e[35]<<15|e[34]>>>17,D=e[45]<<29|e[44]>>>3,P=e[44]<<29|e[45]>>>3,A=e[6]<<28|e[7]>>>4,_=e[7]<<28|e[6]>>>4,re=e[17]<<23|e[16]>>>9,ie=e[16]<<23|e[17]>>>9,z=e[26]<<25|e[27]>>>7,R=e[27]<<25|e[26]>>>7,w=e[36]<<21|e[37]>>>11,v=e[37]<<21|e[36]>>>11,Q=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,$=e[8]<<27|e[9]>>>5,J=e[9]<<27|e[8]>>>5,C=e[18]<<20|e[19]>>>12,B=e[19]<<20|e[18]>>>12,oe=e[29]<<7|e[28]>>>25,se=e[28]<<7|e[29]>>>25,q=e[38]<<8|e[39]>>>24,F=e[39]<<8|e[38]>>>24,S=e[48]<<14|e[49]>>>18,E=e[49]<<14|e[48]>>>18,e[0]=b^~m&y,e[1]=p^~g&x,e[10]=A^~C&O,e[11]=_^~B&I,e[20]=U^~L&z,e[21]=N^~M&R,e[30]=$^~G&W,e[31]=J^~V&Z,e[40]=te^~re&oe,e[41]=ne^~ie&se,e[2]=m^~y&w,e[3]=g^~x&v,e[12]=C^~O&j,e[13]=B^~I&T,e[22]=L^~z&q,e[23]=M^~R&F,e[32]=G^~W&K,e[33]=V^~Z&X,e[42]=re^~oe&ae,e[43]=ie^~se&fe,e[4]=y^~w&S,e[5]=x^~v&E,e[14]=O^~j&D,e[15]=I^~T&P,e[24]=z^~q&Y,e[25]=R^~F&H,e[34]=W^~K&Q,e[35]=Z^~X&ee,e[44]=oe^~ae&ce,e[45]=se^~fe&ue,e[6]=w^~S&b,e[7]=v^~E&p,e[16]=j^~D&A,e[17]=T^~P&_,e[26]=q^~Y&U,e[27]=F^~H&N,e[36]=K^~Q&$,e[37]=X^~ee&J,e[46]=ae^~ce&te,e[47]=fe^~ue&ne,e[8]=S^~b&m,e[9]=E^~p&g,e[18]=D^~A&C,e[19]=P^~_&B,e[28]=Y^~U&L,e[29]=H^~N&M,e[38]=Q^~$&G,e[39]=ee^~J&V,e[48]=ce^~te&re,e[49]=ue^~ne&ie,e[0]^=k[r],e[1]^=k[r+1]};if(u)e.exports=B;else{for(I=0;I>>16)*t&65535)<<16)}function s(e,t){return e<>>32-t}function a(e){return e=o(e^=e>>>16,2246822507),e=o(e^=e>>>13,3266489909),e^=e>>>16}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[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 c(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 u(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 h(e,t){return 0===(t%=64)?e:t<32?[e[0]<>>32-t,e[1]<>>1]),e=l(e=c(e,[4283543511,3981806797]),[0,e[0]>>>1]),e=l(e=c(e,[3301882366,444984403]),[0,e[0]>>>1])}i.x86.hash32=function(e,t){t=t||0;for(var n=(e=e||"").length%4,r=e.length-n,i=t,f=0,c=3432918353,u=461845907,h=0;h>>0},i.x86.hash128=function(e,t){t=t||0;for(var n=(e=e||"").length%16,r=e.length-n,i=t,f=t,c=t,u=t,h=0,l=0,d=0,b=0,p=597399067,k=2869860233,m=951274213,g=2716044179,y=0;y>>0).toString(16)).slice(-8)+("00000000"+(f>>>0).toString(16)).slice(-8)+("00000000"+(c>>>0).toString(16)).slice(-8)+("00000000"+(u>>>0).toString(16)).slice(-8)},i.x64.hash128=function(e,t){t=t||0;for(var n=(e=e||"").length%16,r=e.length-n,i=[0,t],o=[0,t],s=[0,0],a=[0,0],b=[2277735313,289559509],p=[1291169091,658871167],k=0;k>>0).toString(16)).slice(-8)+("00000000"+(i[1]>>>0).toString(16)).slice(-8)+("00000000"+(o[0]>>>0).toString(16)).slice(-8)+("00000000"+(o[1]>>>0).toString(16)).slice(-8)},e.exports&&(t=e.exports=i),t.murmurHash3=i}()},function(e,t,n){"use strict";(function(t){const r=n(90),i=function(){if(self.crypto)return self.crypto.subtle||self.crypto.webkitSubtle;if(self.msCrypto)return self.msCrypto.subtle}();function o(e){if(!i)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");return(n,o)=>{const s=i.digest({name:e},n);if("function"!=typeof s.then)return s.onerror=(()=>{o(new Error(`hashing data using ${e}`))}),void(s.oncomplete=(e=>{o(null,e.target.result)}));r(s.then(e=>t.from(new Uint8Array(e))),o)}}e.exports={sha1:function(e,t){o("SHA-1")(e,t)},sha2256:function(e,t){o("SHA-256")(e,t)},sha2512:function(e,t){o("SHA-512")(e,t)}}}).call(this,n(0).Buffer)},function(e,t,n){(function(t,r){var i,o=n(91),s=n(27);function a(e,t){return"function"!=typeof t?e:e.then(function(e){i(function(){t(null,e)})},function(e){i(function(){t(e)})})}function f(e){return a(this,e)}function c(e){if(e&&s(e)){e.nodeify=f;var t=e.then;return e.then=function(){return c(t.apply(this,arguments))},e}"function"==typeof e?e.prototype.nodeify=f:o.prototype.nodeify=f}function u(e){if(!(this instanceof u))return new u(e);o.call(this,e),c(this)}i="function"==typeof t?t:"object"==typeof r&&r&&r.nextTick?r.nextTick:function(e){setTimeout(e,0)},e.exports=a,a.extend=c,a.Promise=u,u.prototype=Object.create(o.prototype),u.prototype.constructor=u}).call(this,n(16).setImmediate,n(2))},function(e,t,n){(function(t){var r,i=n(27);r="function"==typeof setImediate?setImediate:"object"==typeof t&&t&&t.nextTick?t.nextTick:function(e){setTimeout(e,0)};var o=[];function s(e){if(!(this instanceof s))return"function"==typeof e?new s(e):(n=new s(function(e){t=e}),{resolver:t,promise:n});var t,n,a,f=!1,c=!1,u=[],h=!1;function l(e){u.length?(h=!0,u.shift()(e||!1)):h=!1}this.then=function(e,t){return new s(function(n){u.push(function(i){var o=c?e:t;if("function"==typeof o){function s(){var e;try{e=o(a)}catch(e){return n.reject(e),l()}n.fulfill(e),l(!0)}i?s():r(s)}else c?(n.fulfill(a),l(i)):(n.reject(a),l(i))}),f&&!h&&l()})},function(){function t(e){f||(f=!0,c=!1,a=e,l())}for(var n={fulfill:function e(n){f||(i(n)?n.then(e,t):(f=c=!0,a=n,l()))},reject:t},r=0;ri(r=>{const i=n.init(e,null);return n.update(i,r),t.from(n.digest(i))});e.exports=(e=>{for(let t=0;t<64;t++)e[45569+t]=a(t+1,o);for(let t=0;t<32;t++)e[45633+t]=a(t+1,s)})}).call(this,n(0).Buffer)},function(e,t,n){var r=n(94),i=n(95);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(28);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 o(e,t,n,r){var i=e[t]+n;n<0&&(i+=4294967296);var o=e[t+1]+r;i>=4294967296&&o++,e[t]=i,e[t+1]=o}function s(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function a(e,t,n,r,s,a){var f=h[s],c=h[s+1],l=h[a],d=h[a+1];i(u,e,t),o(u,e,f,c);var b=u[r]^u[e],p=u[r+1]^u[e+1];u[r]=p,u[r+1]=b,i(u,n,r),b=u[t]^u[n],p=u[t+1]^u[n+1],u[t]=b>>>24^p<<8,u[t+1]=p>>>24^b<<8,i(u,e,t),o(u,e,l,d),b=u[r]^u[e],p=u[r+1]^u[e+1],u[r]=b>>>16^p<<16,u[r+1]=p>>>16^b<<16,i(u,n,r),b=u[t]^u[n],p=u[t+1]^u[n+1],u[t]=p>>>31^b<<1,u[t+1]=b>>>31^p<<1}var f=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,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,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})),u=new Uint32Array(32),h=new Uint32Array(32);function l(e,t){var n=0;for(n=0;n<16;n++)u[n]=e.h[n],u[n+16]=f[n];for(u[24]=u[24]^e.t,u[25]=u[25]^e.t/4294967296,t&&(u[28]=~u[28],u[29]=~u[29]),n=0;n<32;n++)h[n]=s(e.b,4*n);for(n=0;n<12;n++)a(0,8,16,24,c[16*n+0],c[16*n+1]),a(2,10,18,26,c[16*n+2],c[16*n+3]),a(4,12,20,28,c[16*n+4],c[16*n+5]),a(6,14,22,30,c[16*n+6],c[16*n+7]),a(0,10,20,30,c[16*n+8],c[16*n+9]),a(2,12,22,24,c[16*n+10],c[16*n+11]),a(4,14,16,26,c[16*n+12],c[16*n+13]),a(6,8,18,28,c[16*n+14],c[16*n+15]);for(n=0;n<16;n++)e.h[n]=e.h[n]^u[n]^u[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]=f[r];var i=t?t.length:0;return n.h[0]^=16842752^i<<8^e,t&&(b(n,t),n.c=128),n}function b(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 b(i,e),p(i)}e.exports={blake2b:k,blake2bHex:function(e,t,n){var i=k(e,t,n);return r.toHex(i)},blake2bInit:d,blake2bUpdate:b,blake2bFinal:p}},function(e,t,n){var r=n(28);function i(e,t){return e[t]^e[t+1]<<8^e[t+2]<<16^e[t+3]<<24}function o(e,t,n,r,i,o){c[e]=c[e]+c[t]+i,c[r]=s(c[r]^c[e],16),c[n]=c[n]+c[r],c[t]=s(c[t]^c[n],12),c[e]=c[e]+c[t]+o,c[r]=s(c[r]^c[e],8),c[n]=c[n]+c[r],c[t]=s(c[t]^c[n],7)}function s(e,t){return e>>>t^e<<32-t}var a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),f=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]),c=new Uint32Array(16),u=new Uint32Array(16);function h(e,t){var n=0;for(n=0;n<8;n++)c[n]=e.h[n],c[n+8]=a[n];for(c[12]^=e.t,c[13]^=e.t/4294967296,t&&(c[14]=~c[14]),n=0;n<16;n++)u[n]=i(e.b,4*n);for(n=0;n<10;n++)o(0,4,8,12,u[f[16*n+0]],u[f[16*n+1]]),o(1,5,9,13,u[f[16*n+2]],u[f[16*n+3]]),o(2,6,10,14,u[f[16*n+4]],u[f[16*n+5]]),o(3,7,11,15,u[f[16*n+6]],u[f[16*n+7]]),o(0,5,10,15,u[f[16*n+8]],u[f[16*n+9]]),o(1,6,11,12,u[f[16*n+10]],u[f[16*n+11]]),o(2,7,8,13,u[f[16*n+12]],u[f[16*n+13]]),o(3,4,9,14,u[f[16*n+14]],u[f[16*n+15]]);for(n=0;n<8;n++)e.h[n]^=c[n]^c[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 p(e,t,n){n=n||32,e=r.normalizeInput(e);var i=l(n,t);return d(i,e),b(i)}e.exports={blake2s:p,blake2sHex:function(e,t,n){var i=p(e,t,n);return r.toHex(i)},blake2sInit:l,blake2sUpdate:d,blake2sFinal:b}},function(e,t,n){"use strict";const r=n(10),i=r.cloneLinks,o=r.cloneData,s=n(8);e.exports=function(e,t){const n=o(e),r=i(e);s(n,r,t)}},function(e,t,n){"use strict";const r=n(10),i=r.cloneLinks,o=r.cloneData,s=r.toDAGLink,a=n(3),f=n(7),c=n(8);e.exports=function(e,t,n){const r=i(e),u=o(e);!function(e,t){if(a.isDAGLink(e))return t(null,e);if(f.isDAGNode(e))return s(e,{},t);try{t(null,new a(e.name,e.size,e.multihash||e.hash||e.cid))}catch(e){return t(e)}}(t,(e,t)=>{if(e)return n(e);r.push(t),c(u,r,n)})}},function(e,t,n){"use strict";(function(t){const r=n(10),i=r.cloneLinks,o=r.cloneData,s=n(8),a=n(5);e.exports=function(e,n,r){const f=o(e);let c=i(e);if("string"==typeof n)c=c.filter(e=>e.name!==n);else{if(!t.isBuffer(n)&&!a.isCID(n))return r(new Error("second arg needs to be a name or CID"),null);c=c.filter(e=>!e.cid.equals(n))}s(f,c,r)}}).call(this,n(0).Buffer)},function(e,t,n){"use strict";const r=(e,t)=>(function(...n){return new(0,t.promiseModule)((r,i)=>{t.multiArgs?n.push((...e)=>{t.errorFirst?e[0]?i(e):(e.shift(),r(e)):r(e)}):t.errorFirst?n.push((e,t)=>{e?i(e):r(t)}):n.push(r),e.apply(this,n)})});e.exports=((e,t)=>{t=Object.assign({exclude:[/.+(Sync|Stream)$/],errorFirst:!0,promiseModule:Promise},t);const n=typeof e;if(null===e||"object"!==n&&"function"!==n)throw new TypeError(`Expected \`input\` to be a \`Function\` or \`Object\`, got \`${null===e?"null":n}\``);const i=e=>{const n=t=>"string"==typeof t?e===t:t.test(e);return t.include?t.include.some(n):!t.exclude.some(n)};let o;o="function"===n?function(...n){return t.excludeMain?e(...n):r(e,t).apply(this,n)}:Object.create(Object.getPrototypeOf(e));for(const n in e){const s=e[n];o[n]="function"==typeof s&&i(n)?r(s,t):s}return o})},function(e,t,n){"use strict";const r=n(11),i=n(101),o=n(6),s=n(29),{isDefined:a,findUniques:f,difference:c,dagNode:u}=n(12),h=["heads"],l=(e,t)=>e.slice(e.length-t,e.length);e.exports=class{static async toCID(e,t){if(!a(e))throw s.IPFSNotDefinedError();if(!a(t))throw s.LogNotDefinedError();if(t.values.length<1)throw new Error("Can't serialize an empty log");return u.write(e,"dag-cbor",t.toJSON(),h)}static async toMultihash(e,t){if(!a(e))throw s.IPFSNotDefinedError();if(!a(t))throw s.LogNotDefinedError();if(t.values.length<1)throw new Error("Can't serialize an empty log");return u.write(e,"dag-pb",t.toJSON(),h)}static async fromCID(e,t,n=-1,f,c){if(!a(e))throw s.IPFSNotDefinedError();if(!a(t))throw new Error(`Invalid CID: ${t}`);const l=await u.read(e,t,h);if(!l.heads||!l.id)throw s.NotALogError();const d=await i.fetchAll(e,l.heads,n,f,null,c),b=d.reduce((e,t)=>t.clock.time>e.time?new o(t.clock.id,t.clock.time):e,new o(l.id)),p=d.slice().sort(r.compare),k=p.filter(e=>l.heads.includes(e.cid));return{id:l.id,values:p,heads:k,clock:b}}static async fromEntryCid(e,t,n=-1,r,o){if(!a(e))throw s.IpfsNotDefinedError();if(!a(t))throw new Error("'entryCid' must be defined");const f=Array.isArray(t)?t:[t];n=n>-1?Math.max(n,1):n;const c=await i.fetchParallel(e,f,n,r,null,null,o);return{values:n>-1?l(c,n):c}}static async fromJSON(e,t,n=-1,o,f){if(!a(e))throw s.IPFSNotDefinedError();t.heads.forEach(r.ensureInterop);const c=t.heads.map(e=>e.cid),u=(await i.fetchParallel(e,c,n,[],16,o,f)).slice().sort(r.compare);return{id:t.id,values:u,heads:t.heads}}static async fromEntry(e,t,n=-1,o,u){if(!a(e))throw s.IPFSNotDefinedError();if(!a(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]),t.forEach(r.ensureInterop),n=n>-1?Math.max(n,t.length):n;const h=t.map(e=>e.cid),l=await i.fetchParallel(e,h,n,o,null,null,u),d=t.concat(l),b=f(d,"cid").sort(r.compare),p=b.slice(n>-1?-n:-b.length),k=((e,t)=>{var n=e.slice(t.length,e.length);return t.concat(n)})(p,c(p,t,"cid"));return{id:k[k.length-1].id,values:k}}}},function(e,t,n){"use strict";const r=n(102),i=n(19),o=n(11);class s{static async fetchParallel(e,t,n=-1,r=[],o=null,a,f){const c=(e,t)=>e.concat(t);return o=Math.max(o||t.length,1),(e=>e.reduce(c,[]))(await i(t,t=>s.fetchAll(e,t,n,r,a,f),{concurrency:o}))}static async fetchAll(e,t,n=-1,i=[],s=null,a){let f=[],c={},u=Array.isArray(t)?t.slice():[t];const h=e=>u.push(e);(i=i&&Array.isArray(i)?i:[]).forEach(e=>{o.isEntry(e)&&(f.push(e),c[e.cid]=e)});return await r(()=>u.length>0&&(f.length{const t=u.shift();return c[t]?Promise.resolve():new Promise(async(n,r)=>{const i=s?setTimeout(()=>{console.warn(`Warning: Couldn't fetch entry '${t}', request timed out (${s}ms)`),n()},s):null;try{(e=>{o.isEntry(e)&&(e.next.forEach(h),f.push(e),c[t]=e,a&&a(t,e,f.length))})(await o.fromCID(e,t)),n()}catch(e){r(e)}finally{clearTimeout(i)}})}),f}}e.exports=s},function(e,t,n){"use strict";const r=e=>new Promise(t=>{t(e())});e.exports=((e,t)=>r(function n(){if(e())return r(t).then(n)}))},function(e,t,n){"use strict";const r=n(6);function i(e,t,n){const i=r.compare(e.clock,t.clock);return 0===i?n(e,t):i}function o(e,t,n){return e.clock.id===t.clock.id?n(e,t):e.clock.ide,r=(e,t)=>o(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=class{async canAppend(e,t){return!0}}}]); //# sourceMappingURL=ipfslog.min.js.map \ No newline at end of file diff --git a/lib/es5/entry-io.js b/lib/es5/entry-io.js index 11de43a3..31831d3d 100644 --- a/lib/es5/entry-io.js +++ b/lib/es5/entry-io.js @@ -25,12 +25,24 @@ function () { (0, _createClass2.default)(EntryIO, null, [{ key: "fetchParallel", - // Fetch log graphs in parallel + + /** + * Fetch log entries in parallel. + * @param {IPFS} ipfs An IPFS instance + * @param {string|Array} cids CIDs of the entries to fetch + * @param {number} [amount=-1] How many entries to fetch + * @param {Array} [exclude] Entries to not fetch + * @param {number} [concurrency=] Max concurrent fetch operations + * @param {number} [timeout] Maximum time to wait for each fetch operation, in ms + * @param {function(cid, entry, parent, depth)} onProgressCallback + * @returns {Promise>} + */ value: function () { var _fetchParallel = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee(ipfs, hashes, length) { - var exclude, + _regenerator.default.mark(function _callee(ipfs, cids) { + var amount, + exclude, concurrency, timeout, onProgressCallback, @@ -43,13 +55,14 @@ function () { while (1) { switch (_context.prev = _context.next) { case 0: + amount = _args.length > 2 && _args[2] !== undefined ? _args[2] : -1; exclude = _args.length > 3 && _args[3] !== undefined ? _args[3] : []; - concurrency = _args.length > 4 ? _args[4] : undefined; + concurrency = _args.length > 4 && _args[4] !== undefined ? _args[4] : null; timeout = _args.length > 5 ? _args[5] : undefined; onProgressCallback = _args.length > 6 ? _args[6] : undefined; - fetchOne = function fetchOne(hash) { - return EntryIO.fetchAll(ipfs, hash, length, exclude, timeout, onProgressCallback); + fetchOne = function fetchOne(cid) { + return EntryIO.fetchAll(ipfs, cid, amount, exclude, timeout, onProgressCallback); }; concatArrays = function concatArrays(arr1, arr2) { @@ -60,17 +73,17 @@ function () { return arr.reduce(concatArrays, []); }; - concurrency = Math.max(concurrency || hashes.length, 1); - _context.next = 10; - return pMap(hashes, fetchOne, { + concurrency = Math.max(concurrency || cids.length, 1); + _context.next = 11; + return pMap(cids, fetchOne, { concurrency: concurrency }); - case 10: + case 11: entries = _context.sent; return _context.abrupt("return", flatten(entries)); - case 12: + case 13: case "end": return _context.stop(); } @@ -78,22 +91,21 @@ function () { }, _callee, this); })); - function fetchParallel(_x, _x2, _x3) { + function fetchParallel(_x, _x2) { return _fetchParallel.apply(this, arguments); } return fetchParallel; }() /** - * Fetch log entries sequentially - * - * @param {IPFS} [ipfs] An IPFS instance - * @param {string} [hash] Multihash of the entry to fetch - * @param {string} [parent] Parent of the node to be fetched - * @param {Object} [all] Entries to skip - * @param {Number} [amount=-1] How many entries to fetch - * @param {Number} [depth=0] Current depth of the recursion - * @param {function(hash, entry, parent, depth)} onProgressCallback + * Fetch log entries sequentially. + * @param {IPFS} ipfs An IPFS instance + * @param {string|Array} cids CIDs of the entries to fetch + * @param {number} [amount=-1] How many entries to fetch + * @param {Array} [exclude] Entries to not fetch + * @param {number} [concurrency] Max concurrent fetch operations + * @param {number} [timeout] Maximum time to wait for each fetch operation, in ms + * @param {function(cid, entry, parent, depth)} onProgressCallback * @returns {Promise>} */ @@ -102,8 +114,9 @@ function () { value: function () { var _fetchAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee3(ipfs, hashes, amount) { - var exclude, + _regenerator.default.mark(function _callee3(ipfs, cids) { + var amount, + exclude, timeout, onProgressCallback, result, @@ -118,12 +131,13 @@ function () { while (1) { switch (_context3.prev = _context3.next) { case 0: + amount = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : -1; exclude = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : []; timeout = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : null; onProgressCallback = _args3.length > 5 ? _args3[5] : undefined; result = []; cache = {}; - loadingQueue = Array.isArray(hashes) ? hashes.slice() : [hashes]; // Add a multihash to the loading queue + loadingQueue = Array.isArray(cids) ? cids.slice() : [cids]; // Add a CID to the loading queue addToLoadingQueue = function addToLoadingQueue(e) { return loadingQueue.push(e); @@ -133,7 +147,10 @@ function () { exclude = exclude && Array.isArray(exclude) ? exclude : []; addToExcludeCache = function addToExcludeCache(e) { - return cache[e.hash] = e; + if (Entry.isEntry(e)) { + result.push(e); + cache[e.cid] = e; + } }; exclude.forEach(addToExcludeCache); @@ -143,9 +160,9 @@ function () { }; fetchEntry = function fetchEntry() { - var hash = loadingQueue.shift(); + var cid = loadingQueue.shift(); - if (cache[hash]) { + if (cache[cid]) { return Promise.resolve(); } @@ -163,20 +180,18 @@ function () { // Resolve the promise after a timeout (if given) in order to // not get stuck loading a block that is unreachable timer = timeout ? setTimeout(function () { - console.warn("Warning: Couldn't fetch entry '".concat(hash, "', request timed out (").concat(timeout, "ms)")); + console.warn("Warning: Couldn't fetch entry '".concat(cid, "', request timed out (").concat(timeout, "ms)")); resolve(); }, timeout) : null; addToResults = function addToResults(entry) { - clearTimeout(timer); - if (Entry.isEntry(entry)) { entry.next.forEach(addToLoadingQueue); result.push(entry); - cache[hash] = entry; + cache[cid] = entry; if (onProgressCallback) { - onProgressCallback(hash, entry, result.length); + onProgressCallback(cid, entry, result.length); } } }; // Load the entry @@ -184,7 +199,7 @@ function () { _context2.prev = 2; _context2.next = 5; - return Entry.fromMultihash(ipfs, hash); + return Entry.fromCID(ipfs, cid); case 5: entry = _context2.sent; @@ -199,26 +214,31 @@ function () { reject(_context2.t0); case 13: + _context2.prev = 13; + clearTimeout(timer); + return _context2.finish(13); + + case 16: case "end": return _context2.stop(); } } - }, _callee2, this, [[2, 10]]); + }, _callee2, this, [[2, 10, 13, 16]]); })); - return function (_x7, _x8) { + return function (_x5, _x6) { return _ref.apply(this, arguments); }; }()); }; - _context3.next = 14; + _context3.next = 15; return pWhilst(shouldFetchMore, fetchEntry); - case 14: + case 15: return _context3.abrupt("return", result); - case 15: + case 16: case "end": return _context3.stop(); } @@ -226,7 +246,7 @@ function () { }, _callee3, this); })); - function fetchAll(_x4, _x5, _x6) { + function fetchAll(_x3, _x4) { return _fetchAll.apply(this, arguments); } diff --git a/lib/es5/entry.js b/lib/es5/entry.js index 5854c797..6d291de6 100644 --- a/lib/es5/entry.js +++ b/lib/es5/entry.js @@ -2,6 +2,8 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); +var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); + var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); @@ -13,12 +15,19 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat var Clock = require('./lamport-clock'); var _require = require('./utils'), - isDefined = _require.isDefined; + isDefined = _require.isDefined, + dagNode = _require.dagNode; + +var IPLD_LINKS = ['next']; var IpfsNotDefinedError = function IpfsNotDefinedError() { return new Error('Ipfs instance not defined'); }; +var getCidProp = function getCidProp(entry) { + return entry.v === 0 ? 'hash' : 'cid'; +}; + var Entry = /*#__PURE__*/ function () { @@ -31,13 +40,17 @@ function () { /** * Create an Entry - * @param {string|Buffer|Object|Array} data - Data of the entry to be added. Can be any JSON.stringifyable data. - * @param {Array} [next=[]] Parents of the entry + * @param {IPFS} ipfs An IPFS instance + * @param {Identity} identity The identity instance + * @param {string} logId The unique identifier for this log + * @param {*} data Data of the entry to be added. Can be any JSON.stringifyable data + * @param {Array} [next=[]] Parent CIDs or entries + * @param {LamportClock} [clock] The lamport clock + * @returns {Promise} * @example * const entry = await Entry.create(ipfs, identity, 'hello') * console.log(entry) - * // { hash: null, payload: "hello", next: [] } - * @returns {Promise} + * // { cid: null, payload: "hello", next: [] } */ value: function () { var _create = (0, _asyncToGenerator2.default)( @@ -97,23 +110,23 @@ function () { throw new Error("'next' argument is not an array"); case 12: - // Clean the next objects and convert to hashes + // Clean the next objects and convert to cids toEntry = function toEntry(e) { - return e.hash ? e.hash : e; + return e.cid ? e.cid : e; }; nexts = next.filter(isDefined).map(toEntry); entry = { - hash: null, - // "Qm...Foo", we'll set the hash after persisting the entry + cid: null, + // "zd...Foo", we'll set the cid after persisting the entry id: logId, // For determining a unique chain payload: data, // Can be any JSON.stringifyable data next: nexts, - // Array of Multihashes - v: 0, - // For future data structure updates, should currently always be 0 + // Array of CIDs + v: 1, + // To tag the version of this data structure clock: clock || new Clock(identity.publicKey) }; _context.next = 17; @@ -125,11 +138,11 @@ function () { entry.identity = identity.toJSON(); entry.sig = signature; _context.next = 23; - return Entry.toMultihash(ipfs, entry); + return Entry.toCID(ipfs, entry); case 23: - entry.hash = _context.sent; - return _context.abrupt("return", entry); + entry.cid = _context.sent; + return _context.abrupt("return", Entry.ensureInterop(entry)); case 25: case "end": @@ -146,10 +159,11 @@ function () { return create; }() /** - * Verifies an entry signature for a given key and sig - * @param {Entry} entry Entry to verify - * @return {Promise} Returns a promise that resolves to a boolean value - * indicating if the entry signature is valid + * Verifies an entry signature. + * + * @param {IdentityProvider} identityProvider The identity provider to use + * @param {Entry} entry The entry being verified + * @return {Promise} A promise that resolves to a boolean value indicating if the signature is valid */ }, { @@ -158,6 +172,8 @@ function () { var _verify = (0, _asyncToGenerator2.default)( /*#__PURE__*/ _regenerator.default.mark(function _callee2(identityProvider, entry) { + var _e; + var e; return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { @@ -195,14 +211,7 @@ function () { throw new Error("Entry doesn't have a signature"); case 8: - e = Object.assign({}, { - hash: null, - id: entry.id, - payload: entry.payload, - next: entry.next, - v: entry.v, - clock: new Clock(entry.clock.id, entry.clock.time) - }); + e = (_e = {}, (0, _defineProperty2.default)(_e, getCidProp(entry), null), (0, _defineProperty2.default)(_e, "id", entry.id), (0, _defineProperty2.default)(_e, "payload", entry.payload), (0, _defineProperty2.default)(_e, "next", entry.next), (0, _defineProperty2.default)(_e, "v", entry.v), (0, _defineProperty2.default)(_e, "clock", entry.clock), _e); return _context2.abrupt("return", identityProvider.verify(entry.sig, entry.key, Entry.toBuffer(e))); case 10: @@ -219,20 +228,63 @@ function () { return verify; }() + /** + * Transforms an entry into a Buffer. + * @param {Entry} entry The entry + * @return {Buffer} The buffer + */ + }, { key: "toBuffer", value: function toBuffer(entry) { return Buffer.from(JSON.stringify(entry)); } /** - * Get the multihash of an Entry - * @param {IPFS} [ipfs] An IPFS instance - * @param {Entry} [entry] Entry to get a multihash for + * Get the CID of an Entry. + * @param {IPFS} ipfs An IPFS instance + * @param {Entry} entry Entry to get a CID for + * @returns {Promise} * @example - * const hash = await Entry.toMultihash(ipfs, entry) - * console.log(hash) - * // "Qm...Foo" + * const cid = await Entry.toCID(ipfs, entry) + * console.log(cid) + * // "zd...Foo" + */ + + }, { + key: "toCID", + value: function toCID(ipfs, entry) { + if (!ipfs) throw IpfsNotDefinedError(); + if (!Entry.isEntry(entry)) throw new Error('Invalid object format, cannot generate entry CID'); // Ensure `entry` follows the correct format + + var e = { + cid: null, + id: entry.id, + payload: entry.payload, + next: entry.next, + v: entry.v, + clock: entry.clock + }; + if (entry.key) Object.assign(e, { + key: entry.key + }); + if (entry.identity) Object.assign(e, { + identity: entry.identity + }); + if (entry.sig) Object.assign(e, { + sig: entry.sig + }); + return dagNode.write(ipfs, 'dag-cbor', e, IPLD_LINKS); + } + /** + * Get the multihash of an Entry. + * @param {IPFS} ipfs An IPFS instance + * @param {Entry} entry Entry to get a multihash for * @returns {Promise} + * @example + * const multihash = await Entry.toMultihash(ipfs, entry) + * console.log(multihash) + * // "Qm...Foo" + * @deprecated */ }, { @@ -241,7 +293,7 @@ function () { var _toMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/ _regenerator.default.mark(function _callee3(ipfs, entry) { - var isValidEntryObject, e, data, object; + var e; return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { @@ -254,25 +306,21 @@ function () { throw IpfsNotDefinedError(); case 2: - isValidEntryObject = function isValidEntryObject(entry) { - return entry.id && entry.clock && entry.next && entry.payload && entry.v >= 0; - }; - - if (isValidEntryObject(entry)) { - _context3.next = 5; + if (Entry.isEntry(entry)) { + _context3.next = 4; break; } - throw new Error('Invalid object format, cannot generate entry multihash'); + throw new Error('Invalid object format, cannot generate entry CID'); - case 5: + case 4: // Ensure `entry` follows the correct format e = { hash: null, id: entry.id, payload: entry.payload, next: entry.next, - v: entry.v, + v: 0, clock: entry.clock }; if (entry.key) Object.assign(e, { @@ -284,15 +332,9 @@ function () { if (entry.sig) Object.assign(e, { sig: entry.sig }); - data = Entry.toBuffer(e); - _context3.next = 12; - return ipfs.object.put(data); - - case 12: - object = _context3.sent; - return _context3.abrupt("return", object.toJSON().multihash); + return _context3.abrupt("return", dagNode.write(ipfs, 'dag-pb', e, IPLD_LINKS)); - case 14: + case 9: case "end": return _context3.stop(); } @@ -307,23 +349,25 @@ function () { return toMultihash; }() /** - * Create an Entry from a multihash - * @param {IPFS} [ipfs] An IPFS instance - * @param {string} [hash] Multihash as Base58 encoded string to create an Entry from - * @example - * const hash = await Entry.fromMultihash(ipfs, "Qm...Foo") - * console.log(hash) - * // { hash: "Qm...Foo", payload: "hello", next: [] } + * Create an Entry from a CID. + * @param {IPFS} ipfs An IPFS instance + * @param {string} cid The CID to create an Entry from * @returns {Promise} + * @example + * const entry = await Entry.fromCID(ipfs, "zd...Foo") + * console.log(entry) + * // { cid: "Zd...Foo", payload: "hello", next: [] } */ }, { - key: "fromMultihash", + key: "fromCID", value: function () { - var _fromMultihash = (0, _asyncToGenerator2.default)( + var _fromCID = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee4(ipfs, hash) { - var obj, data, entry; + _regenerator.default.mark(function _callee4(ipfs, cid) { + var _entry; + + var e, entry; return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { @@ -336,42 +380,32 @@ function () { throw IpfsNotDefinedError(); case 2: - if (hash) { + if (cid) { _context4.next = 4; break; } - throw new Error("Invalid hash: ".concat(hash)); + throw new Error("Invalid CID: ".concat(cid)); case 4: _context4.next = 6; - return ipfs.object.get(hash, { - enc: 'base58' - }); + return dagNode.read(ipfs, cid, IPLD_LINKS); case 6: - obj = _context4.sent; - data = JSON.parse(obj.toJSON().data); - entry = { - hash: hash, - id: data.id, - payload: data.payload, - next: data.next, - v: data.v, - clock: new Clock(data.clock.id, data.clock.time) - }; - if (data.key) Object.assign(entry, { - key: data.key + e = _context4.sent; + entry = (_entry = {}, (0, _defineProperty2.default)(_entry, getCidProp(e), cid), (0, _defineProperty2.default)(_entry, "id", e.id), (0, _defineProperty2.default)(_entry, "payload", e.payload), (0, _defineProperty2.default)(_entry, "next", e.next), (0, _defineProperty2.default)(_entry, "v", e.v), (0, _defineProperty2.default)(_entry, "clock", new Clock(e.clock.id, e.clock.time)), _entry); + if (e.key) Object.assign(entry, { + key: e.key }); - if (data.identity) Object.assign(entry, { - identity: data.identity + if (e.identity) Object.assign(entry, { + identity: e.identity }); - if (data.sig) Object.assign(entry, { - sig: data.sig + if (e.sig) Object.assign(entry, { + sig: e.sig }); - return _context4.abrupt("return", entry); + return _context4.abrupt("return", Entry.ensureInterop(entry)); - case 13: + case 12: case "end": return _context4.stop(); } @@ -379,14 +413,52 @@ function () { }, _callee4, this); })); - function fromMultihash(_x9, _x10) { + function fromCID(_x9, _x10) { + return _fromCID.apply(this, arguments); + } + + return fromCID; + }() + /** + * Create an Entry from a multihash. + * @param {IPFS} ipfs An IPFS instance + * @param {string} multihash Multihash (as a Base58 encoded string) to create the Entry from + * @returns {Promise} + * @example + * const entry = await Entry.fromMultihash(ipfs, "Qm...Foo") + * console.log(entry) + * // { cid: "Qm...Foo", payload: "hello", next: [] } + * @deprecated + */ + + }, { + key: "fromMultihash", + value: function () { + var _fromMultihash = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee5(ipfs, multihash) { + return _regenerator.default.wrap(function _callee5$(_context5) { + while (1) { + switch (_context5.prev = _context5.next) { + case 0: + return _context5.abrupt("return", Entry.fromCID(ipfs, multihash)); + + case 1: + case "end": + return _context5.stop(); + } + } + }, _callee5, this); + })); + + function fromMultihash(_x11, _x12) { return _fromMultihash.apply(this, arguments); } return fromMultihash; }() /** - * Check if an object is an Entry + * Check if an object is an Entry. * @param {Entry} obj * @returns {boolean} */ @@ -394,8 +466,41 @@ function () { }, { key: "isEntry", value: function isEntry(obj) { - return obj && obj.id !== undefined && obj.next !== undefined && obj.hash !== undefined && obj.payload !== undefined && obj.v !== undefined && obj.clock !== undefined; + return obj && obj.id !== undefined && obj.next !== undefined && obj.payload !== undefined && obj.v !== undefined && obj[getCidProp(obj)] !== undefined && obj.clock !== undefined; } + /** + * Ensures that this entry is interoperable between earlier versions + * and the most recent one (and vice-versa). + * @param {Entry} entry The entry to ensure interoperability + * @return {Entry} entry The same entry but with backwards and forward interoperability + */ + + }, { + key: "ensureInterop", + value: function ensureInterop(entry) { + if (entry.cid && entry.hash) { + return entry; + } + + var prop = getCidProp(entry); + var accessorProp = prop === 'hash' ? 'cid' : 'hash'; + Object.defineProperty(entry, accessorProp, { + get: function get() { + return this[prop]; + }, + set: function set(value) { + this[prop] = value; + } + }); + return entry; + } + /** + * Compares two entries. + * @param {Entry} a + * @param {Entry} b + * @returns {number} 1 if a is greater, -1 is b is greater + */ + }, { key: "compare", value: function compare(a, b) { @@ -404,7 +509,7 @@ function () { return distance; } /** - * Check if an entry equals another entry + * Check if an entry equals another entry. * @param {Entry} a * @param {Entry} b * @returns {boolean} @@ -413,28 +518,25 @@ function () { }, { key: "isEqual", value: function isEqual(a, b) { - return a.hash === b.hash; + return a.cid === b.cid; } /** * Check if an entry is a parent to another entry. - * @param {Entry} [entry1] Entry to check - * @param {Entry} [entry2] Parent + * @param {Entry} entry1 Entry to check + * @param {Entry} entry2 The parent Entry * @returns {boolean} */ }, { key: "isParent", value: function isParent(entry1, entry2) { - return entry2.next.indexOf(entry1.hash) > -1; + return entry2.next.indexOf(entry1.cid) > -1; } /** - * Find entry's children from an Array of entries - * - * @description + * Find entry's children from an Array of entries. * Returns entry's children as an Array up to the last know child. - * - * @param {Entry} [entry] Entry for which to find the parents - * @param {Array} [values] Entries to search parents from + * @param {Entry} entry Entry for which to find the parents + * @param {Array} values Entries to search parents from * @returns {Array} */ diff --git a/lib/es5/log-io.js b/lib/es5/log-io.js index 72285280..03989be4 100644 --- a/lib/es5/log-io.js +++ b/lib/es5/log-io.js @@ -21,7 +21,10 @@ var LogError = require('./log-errors'); var _require = require('./utils'), isDefined = _require.isDefined, findUniques = _require.findUniques, - difference = _require.difference; + difference = _require.difference, + dagNode = _require.dagNode; + +var IPLD_LINKS = ['heads']; var last = function last(arr, n) { return arr.slice(arr.length - n, arr.length); @@ -35,12 +38,18 @@ function () { } (0, _createClass2.default)(LogIO, null, [{ - key: "toMultihash", + key: "toCID", + + /** + * Get the CID of a Log. + * @param {IPFS} ipfs An IPFS instance + * @param {Log} log Log to get a CID for + * @returns {Promise} + */ value: function () { - var _toMultihash = (0, _asyncToGenerator2.default)( + var _toCID = (0, _asyncToGenerator2.default)( /*#__PURE__*/ _regenerator.default.mark(function _callee(ipfs, log) { - var dagNode; return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { @@ -69,14 +78,9 @@ function () { throw new Error("Can't serialize an empty log"); case 6: - _context.next = 8; - return ipfs.object.put(log.toBuffer()); + return _context.abrupt("return", dagNode.write(ipfs, 'dag-cbor', log.toJSON(), IPLD_LINKS)); - case 8: - dagNode = _context.sent; - return _context.abrupt("return", dagNode.toJSON().multihash); - - case 10: + case 7: case "end": return _context.stop(); } @@ -84,83 +88,138 @@ function () { }, _callee, this); })); - function toMultihash(_x, _x2) { + function toCID(_x, _x2) { + return _toCID.apply(this, arguments); + } + + return toCID; + }() + /** + * Get the multihash of a Log. + * @param {IPFS} ipfs An IPFS instance + * @param {Log} log Log to get a multihash for + * @returns {Promise} + * @deprecated + */ + + }, { + key: "toMultihash", + value: function () { + var _toMultihash = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee2(ipfs, log) { + return _regenerator.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (isDefined(ipfs)) { + _context2.next = 2; + break; + } + + throw LogError.IPFSNotDefinedError(); + + case 2: + if (isDefined(log)) { + _context2.next = 4; + break; + } + + throw LogError.LogNotDefinedError(); + + case 4: + if (!(log.values.length < 1)) { + _context2.next = 6; + break; + } + + throw new Error("Can't serialize an empty log"); + + case 6: + return _context2.abrupt("return", dagNode.write(ipfs, 'dag-pb', log.toJSON(), IPLD_LINKS)); + + case 7: + case "end": + return _context2.stop(); + } + } + }, _callee2, this); + })); + + function toMultihash(_x3, _x4) { return _toMultihash.apply(this, arguments); } return toMultihash; }() /** - * Create a log from multihash - * @param {IPFS} ipfs - An IPFS instance - * @param {string} hash - Multihash (as a Base58 encoded string) to create the log from - * @param {Number} [length=-1] - How many items to include in the log - * @param {function(hash, entry, parent, depth)} onProgressCallback + * Create a log from a CID. + * @param {IPFS} ipfs An IPFS instance + * @param {string} cid The CID of the log + * @param {number} [length=-1] How many items to include in the log + * @param {Array} [exclude] Entries to not fetch (cached) + * @param {function(cid, entry, parent, depth)} onProgressCallback * @returns {Promise} */ }, { - key: "fromMultihash", + key: "fromCID", value: function () { - var _fromMultihash = (0, _asyncToGenerator2.default)( + var _fromCID = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee2(ipfs, hash) { + _regenerator.default.mark(function _callee3(ipfs, cid) { var length, exclude, onProgressCallback, - dagNode, logData, entries, clock, finalEntries, heads, - _args2 = arguments; - return _regenerator.default.wrap(function _callee2$(_context2) { + _args3 = arguments; + return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { - switch (_context2.prev = _context2.next) { + switch (_context3.prev = _context3.next) { case 0: - length = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : -1; - exclude = _args2.length > 3 ? _args2[3] : undefined; - onProgressCallback = _args2.length > 4 ? _args2[4] : undefined; + length = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : -1; + exclude = _args3.length > 3 ? _args3[3] : undefined; + onProgressCallback = _args3.length > 4 ? _args3[4] : undefined; if (isDefined(ipfs)) { - _context2.next = 5; + _context3.next = 5; break; } throw LogError.IPFSNotDefinedError(); case 5: - if (isDefined(hash)) { - _context2.next = 7; + if (isDefined(cid)) { + _context3.next = 7; break; } - throw new Error("Invalid hash: ".concat(hash)); + throw new Error("Invalid CID: ".concat(cid)); case 7: - _context2.next = 9; - return ipfs.object.get(hash, { - enc: 'base58' - }); + _context3.next = 9; + return dagNode.read(ipfs, cid, IPLD_LINKS); case 9: - dagNode = _context2.sent; - logData = JSON.parse(dagNode.toJSON().data); + logData = _context3.sent; if (!(!logData.heads || !logData.id)) { - _context2.next = 13; + _context3.next = 12; break; } throw LogError.NotALogError(); - case 13: - _context2.next = 15; + case 12: + _context3.next = 14; return EntryIO.fetchAll(ipfs, logData.heads, length, exclude, null, onProgressCallback); - case 15: - entries = _context2.sent; + case 14: + entries = _context3.sent; // Find latest clock clock = entries.reduce(function (clock, entry) { if (entry.clock.time > clock.time) { @@ -171,165 +230,162 @@ function () { }, new Clock(logData.id)); finalEntries = entries.slice().sort(Entry.compare); heads = finalEntries.filter(function (e) { - return logData.heads.includes(e.hash); + return logData.heads.includes(e.cid); }); - return _context2.abrupt("return", { + return _context3.abrupt("return", { id: logData.id, values: finalEntries, heads: heads, clock: clock }); - case 20: + case 19: case "end": - return _context2.stop(); + return _context3.stop(); } } - }, _callee2, this); + }, _callee3, this); })); - function fromMultihash(_x3, _x4) { - return _fromMultihash.apply(this, arguments); + function fromCID(_x5, _x6) { + return _fromCID.apply(this, arguments); } - return fromMultihash; + return fromCID; }() }, { - key: "fromEntryHash", + key: "fromEntryCid", value: function () { - var _fromEntryHash = (0, _asyncToGenerator2.default)( + var _fromEntryCid = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee3(ipfs, entryHash, id) { + _regenerator.default.mark(function _callee4(ipfs, entryCid) { var length, exclude, onProgressCallback, - entryHashes, - excludeHashes, + entryCids, entries, sliced, - _args3 = arguments; - return _regenerator.default.wrap(function _callee3$(_context3) { + _args4 = arguments; + return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { - switch (_context3.prev = _context3.next) { + switch (_context4.prev = _context4.next) { case 0: - length = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : -1; - exclude = _args3.length > 4 ? _args3[4] : undefined; - onProgressCallback = _args3.length > 5 ? _args3[5] : undefined; + length = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : -1; + exclude = _args4.length > 3 ? _args4[3] : undefined; + onProgressCallback = _args4.length > 4 ? _args4[4] : undefined; if (isDefined(ipfs)) { - _context3.next = 5; + _context4.next = 5; break; } throw LogError.IpfsNotDefinedError(); case 5: - if (isDefined(entryHash)) { - _context3.next = 7; + if (isDefined(entryCid)) { + _context4.next = 7; break; } - throw new Error("'entryHash' must be defined"); + throw new Error("'entryCid' must be defined"); case 7: - // Convert input hash(es) to an array - entryHashes = Array.isArray(entryHash) ? entryHash : [entryHash]; // Fetch given length, return size at least the given input entries - - length = length > -1 ? Math.max(length, 1) : length; // Make sure we pass hashes instead of objects to the fetcher function + // Convert input cid(s) to an array + entryCids = Array.isArray(entryCid) ? entryCid : [entryCid]; // Fetch given length, return size at least the given input entries - excludeHashes = exclude; // ? exclude.map(e => e.hash ? e.hash : e) : exclude + length = length > -1 ? Math.max(length, 1) : length; + _context4.next = 11; + return EntryIO.fetchParallel(ipfs, entryCids, length, exclude, null, null, onProgressCallback); - _context3.next = 12; - return EntryIO.fetchParallel(ipfs, entryHashes, length, excludeHashes, null, null, onProgressCallback); - - case 12: - entries = _context3.sent; + case 11: + entries = _context4.sent; // Cap the result at the right size by taking the last n entries, // or if given length is -1, then take all sliced = length > -1 ? last(entries, length) : entries; - return _context3.abrupt("return", { + return _context4.abrupt("return", { values: sliced }); - case 15: + case 14: case "end": - return _context3.stop(); + return _context4.stop(); } } - }, _callee3, this); + }, _callee4, this); })); - function fromEntryHash(_x5, _x6, _x7) { - return _fromEntryHash.apply(this, arguments); + function fromEntryCid(_x7, _x8) { + return _fromEntryCid.apply(this, arguments); } - return fromEntryHash; + return fromEntryCid; }() }, { key: "fromJSON", value: function () { var _fromJSON = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee4(ipfs, json) { + _regenerator.default.mark(function _callee5(ipfs, json) { var length, timeout, onProgressCallback, - headHashes, + headCids, entries, finalEntries, - _args4 = arguments; - return _regenerator.default.wrap(function _callee4$(_context4) { + _args5 = arguments; + return _regenerator.default.wrap(function _callee5$(_context5) { while (1) { - switch (_context4.prev = _context4.next) { + switch (_context5.prev = _context5.next) { case 0: - length = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : -1; - timeout = _args4.length > 3 ? _args4[3] : undefined; - onProgressCallback = _args4.length > 4 ? _args4[4] : undefined; + length = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : -1; + timeout = _args5.length > 3 ? _args5[3] : undefined; + onProgressCallback = _args5.length > 4 ? _args5[4] : undefined; if (isDefined(ipfs)) { - _context4.next = 5; + _context5.next = 5; break; } throw LogError.IPFSNotDefinedError(); case 5: - headHashes = json.heads.map(function (e) { - return e.hash; + json.heads.forEach(Entry.ensureInterop); + headCids = json.heads.map(function (e) { + return e.cid; }); - _context4.next = 8; - return EntryIO.fetchParallel(ipfs, headHashes, length, [], 16, timeout, onProgressCallback); + _context5.next = 9; + return EntryIO.fetchParallel(ipfs, headCids, length, [], 16, timeout, onProgressCallback); - case 8: - entries = _context4.sent; + case 9: + entries = _context5.sent; finalEntries = entries.slice().sort(Entry.compare); - return _context4.abrupt("return", { + return _context5.abrupt("return", { id: json.id, values: finalEntries, heads: json.heads }); - case 11: + case 12: case "end": - return _context4.stop(); + return _context5.stop(); } } - }, _callee4, this); + }, _callee5, this); })); - function fromJSON(_x8, _x9) { + function fromJSON(_x9, _x10) { return _fromJSON.apply(this, arguments); } return fromJSON; }() /** - * Create a new log starting from an entry + * Create a new log starting from an entry. * @param {IPFS} ipfs An IPFS instance - * @param {Array} entries An entry or an array of entries to fetch a log from - * @param {Number} [length=-1] How many entries to include. Default: infinite. - * @param {Array} [exclude] Entries to not fetch (cached) - * @param {function(hash, entry, parent, depth)} [onProgressCallback] + * @param {Entry|Array} sourceEntries An entry or an array of entries to fetch a log from + * @param {number} [length=-1] How many entries to include + * @param {Array} [exclude] Entries to not fetch (cached) + * @param {function(cid, entry, parent, depth)} [onProgressCallback] * @returns {Promise} */ @@ -338,11 +394,10 @@ function () { value: function () { var _fromEntry = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee5(ipfs, sourceEntries) { + _regenerator.default.mark(function _callee6(ipfs, sourceEntries) { var length, exclude, onProgressCallback, - excludeHashes, hashes, entries, combined, @@ -351,17 +406,17 @@ function () { missingSourceEntries, replaceInFront, result, - _args5 = arguments; - return _regenerator.default.wrap(function _callee5$(_context5) { + _args6 = arguments; + return _regenerator.default.wrap(function _callee6$(_context6) { while (1) { - switch (_context5.prev = _context5.next) { + switch (_context6.prev = _context6.next) { case 0: - length = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : -1; - exclude = _args5.length > 3 ? _args5[3] : undefined; - onProgressCallback = _args5.length > 4 ? _args5[4] : undefined; + length = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : -1; + exclude = _args6.length > 3 ? _args6[3] : undefined; + onProgressCallback = _args6.length > 4 ? _args6[4] : undefined; if (isDefined(ipfs)) { - _context5.next = 5; + _context6.next = 5; break; } @@ -369,7 +424,7 @@ function () { case 5: if (isDefined(sourceEntries)) { - _context5.next = 7; + _context6.next = 7; break; } @@ -377,7 +432,7 @@ function () { case 7: if (!(!Array.isArray(sourceEntries) && !Entry.isEntry(sourceEntries))) { - _context5.next = 9; + _context6.next = 9; break; } @@ -386,31 +441,29 @@ function () { case 9: if (!Array.isArray(sourceEntries)) { sourceEntries = [sourceEntries]; - } // Fetch given length, return size at least the given input entries + } + sourceEntries.forEach(Entry.ensureInterop); // Fetch given length, return size at least the given input entries - length = length > -1 ? Math.max(length, sourceEntries.length) : length; // Make sure we pass hashes instead of objects to the fetcher function + length = length > -1 ? Math.max(length, sourceEntries.length) : length; // Make sure we pass cids instead of objects to the fetcher function - excludeHashes = exclude ? exclude.map(function (e) { - return e.hash ? e.hash : e; - }) : exclude; hashes = sourceEntries.map(function (e) { - return e.hash; + return e.cid; }); // Fetch the entries - _context5.next = 15; - return EntryIO.fetchParallel(ipfs, hashes, length, excludeHashes, null, null, onProgressCallback); + _context6.next = 15; + return EntryIO.fetchParallel(ipfs, hashes, length, exclude, null, null, onProgressCallback); case 15: - entries = _context5.sent; + entries = _context6.sent; // Combine the fetches with the source entries and take only uniques combined = sourceEntries.concat(entries); - uniques = findUniques(combined, 'hash').sort(Entry.compare); // Cap the result at the right size by taking the last n entries + uniques = findUniques(combined, 'cid').sort(Entry.compare); // Cap the result at the right size by taking the last n entries sliced = uniques.slice(length > -1 ? -length : -uniques.length); // Make sure that the given input entries are present in the result // in order to not lose references - missingSourceEntries = difference(sliced, sourceEntries, 'hash'); + missingSourceEntries = difference(sliced, sourceEntries, 'cid'); replaceInFront = function replaceInFront(a, withEntries) { var sliced = a.slice(withEntries.length, a.length); @@ -420,20 +473,20 @@ function () { result = replaceInFront(sliced, missingSourceEntries); - return _context5.abrupt("return", { + return _context6.abrupt("return", { id: result[result.length - 1].id, values: result }); case 23: case "end": - return _context5.stop(); + return _context6.stop(); } } - }, _callee5, this); + }, _callee6, this); })); - function fromEntry(_x10, _x11) { + function fromEntry(_x11, _x12) { return _fromEntry.apply(this, arguments); } diff --git a/lib/es5/log-sorting.js b/lib/es5/log-sorting.js index 599da31c..383392c1 100644 --- a/lib/es5/log-sorting.js +++ b/lib/es5/log-sorting.js @@ -2,12 +2,14 @@ var Clock = require('./lamport-clock'); /** - * Sort two entries as Last-Write-Wins (LWW) - * @description Last Write Wins is a conflict resolution strategy for sorting elements - * where the element with a greater clock (latest) is chosen as the winner - * @param {Entry} [a] First entry - * @param {Entry} [b] Second entry - * @returns {int} 1 if a is latest, -1 if b is latest + * Sort two entries as Last-Write-Wins (LWW). + * + * Last Write Wins is a conflict resolution strategy for sorting elements + * where the element with a greater clock (latest) is chosen as the winner. + * + * @param {Entry} a First entry + * @param {Entry} b Second entry + * @returns {number} 1 if a is latest, -1 if b is latest */ @@ -32,11 +34,11 @@ function LastWriteWins(a, b) { return sortByEntryClocks(a, b); } /** - * Sort two entries by their clock time - * @param {Entry} [a] First entry to compare - * @param {Entry} [b] Second entry to compare - * @param {function(a, b)} [resolveConflict] A function to call if entries are concurrent (happened at the same time). The function should take in two entries and return 1 if the first entry should be chosen and -1 if the second entry should be chosen. - * @returns {int} 1 if a is greater, -1 if b is greater + * Sort two entries by their clock time. + * @param {Entry} a First entry to compare + * @param {Entry} b Second entry to compare + * @param {function(a, b)} resolveConflict A function to call if entries are concurrent (happened at the same time). The function should take in two entries and return 1 if the first entry should be chosen and -1 if the second entry should be chosen. + * @returns {number} 1 if a is greater, -1 if b is greater */ @@ -48,11 +50,11 @@ function SortByClocks(a, b, resolveConflict) { return diff === 0 ? resolveConflict(a, b) : diff; } /** - * Sort two entries by their clock id - * @param {Entry} [a] First entry to compare - * @param {Entry} [b] Second entry to compare - * @param {function(a, b)} [resolveConflict] A function to call if the clocks ids are the same. The function should take in two entries and return 1 if the first entry should be chosen and -1 if the second entry should be chosen. - * @returns {int} 1 if a is greater, -1 if b is greater + * Sort two entries by their clock id. + * @param {Entry} a First entry to compare + * @param {Entry} b Second entry to compare + * @param {function(a, b)} resolveConflict A function to call if the clocks ids are the same. The function should take in two entries and return 1 if the first entry should be chosen and -1 if the second entry should be chosen. + * @returns {number} 1 if a is greater, -1 if b is greater */ diff --git a/lib/es5/log.js b/lib/es5/log.js index 56f3eea5..3ec7a6ae 100644 --- a/lib/es5/log.js +++ b/lib/es5/log.js @@ -44,8 +44,8 @@ var randomId = function randomId() { return new Date().getTime().toString(); }; -var getHash = function getHash(e) { - return e.hash; +var getCid = function getCid(e) { + return e.cid; }; var flatMap = function flatMap(res, acc) { @@ -61,14 +61,14 @@ var maxClockTimeReducer = function maxClockTimeReducer(res, acc) { }; var uniqueEntriesReducer = function uniqueEntriesReducer(res, acc) { - res[acc.hash] = acc; + res[acc.cid] = acc; return res; }; /** - * Log + * Log. * * @description - * Log implements a G-Set CRDT and adds ordering + * Log implements a G-Set CRDT and adds ordering. * * From: * "A comprehensive study of Convergent and Commutative Replicated Data Types" @@ -83,15 +83,15 @@ function (_GSet) { /** * Create a new Log instance - * @param {IPFS} [ipfs] An IPFS instance - * @param {Object} [access] AccessController (./default-access-controller) - * @param {Object} [identity] Identity (https://github.com/orbitdb/orbit-db-identity-provider/blob/master/src/identity.js) - * @param {String} [logId] ID of the log - * @param {Array} [entries] An Array of Entries from which to create the log - * @param {Array} [heads] Set the heads of the log - * @param {Clock} [clock] Set the clock of the log - * @param {Function} [sortFn] The sort function - by default LastWriteWins - * @return {Log} Log + * @param {IPFS} ipfs An IPFS instance + * @param {Object} access AccessController (./default-access-controller) + * @param {Object} identity Identity (https://github.com/orbitdb/orbit-db-identity-provider/blob/master/src/identity.js) + * @param {Array} [entries] An Array of Entries from which to create the log + * @param {string} [logId] ID of the log + * @param {Array} [heads] Set the heads of the log + * @param {Clock} [clock] Set the clock of the log + * @param {Function} [sortFn] The sort function - by default LastWriteWins + * @return {Log} The log instance */ function Log(ipfs, access, identity, logId, entries, heads, clock, sortFn) { var _this; @@ -141,7 +141,7 @@ function (_GSet) { var addToNextsIndex = function addToNextsIndex(e) { return e.next.forEach(function (a) { - return _this._nextsIndex[a] = e.hash; + return _this._nextsIndex[a] = e.cid; }); }; @@ -157,7 +157,7 @@ function (_GSet) { return _this; } /** - * Returns the ID of the log + * Returns the ID of the log. * @returns {string} */ @@ -166,17 +166,23 @@ function (_GSet) { key: "get", /** - * Find an entry - * @param {string} [hash] The Multihash of the entry as Base58 encoded string + * Find an entry. + * @param {string} [cid] The CID of the entry * @returns {Entry|undefined} */ - value: function get(hash) { - return this._entryIndex[hash]; + value: function get(cid) { + return this._entryIndex[cid]; } + /** + * Checks if a entry is part of the log + * @param {string} cid The CID of the entry + * @returns {boolean} + */ + }, { key: "has", value: function has(entry) { - return this._entryIndex[entry.hash || entry] !== undefined; + return this._entryIndex[entry.cid || entry] !== undefined; } }, { key: "traverse", @@ -200,14 +206,14 @@ function (_GSet) { var addToStack = function addToStack(entry) { // If we've already processed the entry, don't add it to the stack - if (!entry || traversed[entry.hash]) { + if (!entry || traversed[entry.cid]) { return; } // Add the entry in front of the stack and sort stack = [entry].concat((0, _toConsumableArray2.default)(stack)).sort(_this2._sortFn).reverse(); // Add to the cache of processed entries - traversed[entry.hash] = true; + traversed[entry.cid] = true; }; // Start traversal // Process stack until it's empty (traversed the full log) // or when we have the requested amount of entries @@ -220,7 +226,7 @@ function (_GSet) { var entry = stack.shift(); // Add to the result count++; - result[entry.hash] = entry; // Add entry's next references to the stack + result[entry.cid] = entry; // Add entry's next references to the stack entry.next.map(getEntry).filter(isDefined).forEach(addToStack); } @@ -228,9 +234,9 @@ function (_GSet) { return result; } /** - * Append an entry to the log - * @param {Entry} entry Entry to add - * @return {Log} New Log containing the appended value + * Append an entry to the log. + * @param {Entry} entry Entry to add + * @return {Log} New Log containing the appended value */ }, { @@ -255,7 +261,7 @@ function (_GSet) { pointerCount = _args.length > 1 && _args[1] !== undefined ? _args[1] : 1; // 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); // Get the required amount of hashes to next entries (as per current state of the log) + this._clock = new Clock(this.clock.id, newTime); // Get the required amount of cids to next entries (as per current state of the log) references = this.traverse(this.heads, Math.max(pointerCount, this.heads.length)); nexts = Object.keys(Object.assign({}, this._headsIndex, references)); // @TODO: Split Entry.create into creating object, checking permission, signing and then posting to IPFS @@ -280,12 +286,12 @@ function (_GSet) { throw new Error("Could not append entry, key \"".concat(this._identity.id, "\" is not allowed to write to the log")); case 13: - this._entryIndex[entry.hash] = entry; + this._entryIndex[entry.cid] = entry; nexts.forEach(function (e) { - return _this3._nextsIndex[e] = entry.hash; + return _this3._nextsIndex[e] = entry.cid; }); this._headsIndex = {}; - this._headsIndex[entry.hash] = entry; // Update the length + this._headsIndex[entry.cid] = entry; // Update the length this._length++; return _context.abrupt("return", entry); @@ -305,19 +311,15 @@ function (_GSet) { return append; }() /** - * Join two logs + * Join two logs. * - * @description Joins two logs returning a new log. Doesn't mutate the original logs. - * - * @param {IPFS} [ipfs] An IPFS instance - * @param {Log} log Log to join with this Log - * @param {Number} [size] Max size of the joined log - * @param {string} [id] ID to use for the new log + * Joins another log into this one. * + * @param {Log} log Log to join with this Log + * @param {number} [size=-1] Max size of the joined log + * @returns {Promise} This Log instance * @example * await log1.join(log2) - * - * @returns {Promise} */ }, { @@ -438,7 +440,7 @@ function (_GSet) { break; } - throw new Error("Could not validate signature \"".concat(entry.sig, "\" for entry \"").concat(entry.hash, "\" and key \"").concat(publicKey, "\"")); + throw new Error("Could not validate signature \"".concat(entry.sig, "\" for entry \"").concat(entry.cid, "\" and key \"").concat(publicKey, "\"")); case 6: case "end": @@ -468,13 +470,13 @@ function (_GSet) { case 16: // Update the internal next pointers index addToNextsIndex = function addToNextsIndex(e) { - var entry = _this4.get(e.hash); + var entry = _this4.get(e.cid); if (!entry) _this4._length++; /* istanbul ignore else */ e.next.forEach(function (a) { - return _this4._nextsIndex[a] = e.hash; + return _this4._nextsIndex[a] = e.cid; }); }; @@ -484,12 +486,12 @@ function (_GSet) { notReferencedByNewItems = function notReferencedByNewItems(e) { return !nextsFromNewItems.find(function (a) { - return a === e.hash; + return a === e.cid; }); }; notInCurrentNexts = function notInCurrentNexts(e) { - return !_this4._nextsIndex[e.hash]; + return !_this4._nextsIndex[e.cid]; }; nextsFromNewItems = Object.values(newItems).map(getNextPointers).reduce(flatMap, []); @@ -524,8 +526,8 @@ function (_GSet) { return join; }() /** - * Get the log in JSON format - * @returns {Object<{heads}>} + * Get the log in JSON format. + * @returns {Object} An object with the id and heads properties */ }, { @@ -535,10 +537,15 @@ function (_GSet) { id: this.id, heads: this.heads.sort(this._sortFn) // default sorting .reverse() // we want the latest as the first element - .map(getHash) // return only the head hashes + .map(getCid) // return only the head cids }; } + /** + * Get the log in JSON format as a snapshot. + * @returns {Object} An object with the id, heads and value properties + */ + }, { key: "toSnapshot", value: function toSnapshot() { @@ -549,7 +556,7 @@ function (_GSet) { }; } /** - * Get the log as a Buffer + * Get the log as a Buffer. * @returns {Buffer} */ @@ -559,12 +566,12 @@ function (_GSet) { return Buffer.from(JSON.stringify(this.toJSON())); } /** - * Returns the log entries as a formatted string + * Returns the log entries as a formatted string. + * @returns {string} * @example * two * └─one * └─three - * @returns {string} */ }, { @@ -584,28 +591,43 @@ function (_GSet) { }).join('\n'); } /** - * Check whether an object is a Log instance + * Check whether an object is a Log instance. * @param {Object} log An object to check - * @returns {true|false} + * @returns {boolean} */ }, { - key: "toMultihash", + key: "toCID", /** - * Get the log's multihash + * Get the log's CID. + * @returns {Promise} The Log CID + */ + value: function toCID() { + return LogIO.toCID(this._storage, this); + } + /** + * Get the log's multihash. * @returns {Promise} Multihash of the Log as Base58 encoded string + * @deprecated */ + + }, { + key: "toMultihash", value: function toMultihash() { return LogIO.toMultihash(this._storage, this); } /** - * Create a log from multihash - * @param {IPFS} ipfs An IPFS instance - * @param {string} hash Multihash (as a Base58 encoded string) to create the log from - * @param {Number} [length=-1] How many items to include in the log - * @param {Function(hash, entry, parent, depth)} onProgressCallback - * @return {Promise} New Log + * Create a log from a CID. + * @param {IPFS} ipfs An IPFS instance + * @param {AccessController} access The access controller instance + * @param {Identity} identity The identity instance + * @param {string} cid The log CID + * @param {number} [length=-1] How many items to include in the log + * @param {Array} [exclude] Entries to not fetch (cached) + * @param {function(cid, entry, parent, depth)} onProgressCallback + * @returns {Promise} + * @deprecated */ }, { @@ -614,7 +636,7 @@ function (_GSet) { return this._id; } /** - * Returns the clock of the log + * Returns the clock of the log. * @returns {string} */ @@ -624,8 +646,8 @@ function (_GSet) { return this._clock; } /** - * Returns the length of the log - * @return {Number} Length + * Returns the length of the log. + * @return {number} Length */ }, { @@ -634,7 +656,7 @@ function (_GSet) { return this._length; } /** - * Returns the values in the log + * Returns the values in the log. * @returns {Array} */ @@ -644,7 +666,7 @@ function (_GSet) { return Object.values(this.traverse(this.heads)).reverse(); } /** - * Returns an array of heads as multihashes + * Returns an array of heads as cids. * @returns {Array} */ @@ -655,7 +677,7 @@ function (_GSet) { } /** * Returns an array of Entry objects that reference entries which - * are not in the log currently + * are not in the log currently. * @returns {Array} */ @@ -665,15 +687,15 @@ function (_GSet) { return Log.findTails(this.values); } /** - * Returns an array of multihashes that are referenced by entries which - * are not in the log currently - * @returns {Array} Array of multihashes + * Returns an array of cids that are referenced by entries which + * are not in the log currently. + * @returns {Array} Array of CIDs */ }, { - key: "tailHashes", + key: "tailCids", get: function get() { - return Log.findTailHashes(this.values); + return Log.findTailCids(this.values); } }], [{ key: "isLog", @@ -681,11 +703,11 @@ function (_GSet) { return log.id !== undefined && log.heads !== undefined && log._entryIndex !== undefined; } }, { - key: "fromMultihash", + key: "fromCID", value: function () { - var _fromMultihash = (0, _asyncToGenerator2.default)( + var _fromCID = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee5(ipfs, access, identity, hash) { + _regenerator.default.mark(function _callee5(ipfs, access, identity, cid) { var length, exclude, onProgressCallback, @@ -698,31 +720,14 @@ function (_GSet) { length = _args5.length > 4 && _args5[4] !== undefined ? _args5[4] : -1; exclude = _args5.length > 5 ? _args5[5] : undefined; onProgressCallback = _args5.length > 6 ? _args5[6] : undefined; - - if (isDefined(ipfs)) { - _context5.next = 5; - break; - } - - throw LogError.IPFSNotDefinedError(); + _context5.next = 5; + return LogIO.fromCID(ipfs, cid, length, exclude, onProgressCallback); case 5: - if (isDefined(hash)) { - _context5.next = 7; - break; - } - - throw new Error("Invalid hash: ".concat(hash)); - - case 7: - _context5.next = 9; - return LogIO.fromMultihash(ipfs, hash, length, exclude, onProgressCallback); - - case 9: data = _context5.sent; return _context5.abrupt("return", new Log(ipfs, access, identity, data.id, data.values, data.heads, data.clock)); - case 11: + case 7: case "end": return _context5.stop(); } @@ -730,84 +735,164 @@ function (_GSet) { }, _callee5, this); })); - function fromMultihash(_x5, _x6, _x7, _x8) { - return _fromMultihash.apply(this, arguments); + function fromCID(_x5, _x6, _x7, _x8) { + return _fromCID.apply(this, arguments); } - return fromMultihash; + return fromCID; }() /** - * Create a log from a single entry's multihash - * @param {IPFS} ipfs An IPFS instance - * @param {string} hash Multihash (as a Base58 encoded string) of the Entry from which to create the log from - * @param {Number} [length=-1] How many entries to include in the log - * @param {Function(hash, entry, parent, depth)} onProgressCallback - * @return {Promise} New Log - */ + * Create a log from a multihash. + * @param {IPFS} ipfs An IPFS instance + * @param {AccessController} access The access controller instance + * @param {Identity} identity The identity instance + * @param {string} multihash Multihash (as a Base58 encoded string) to create the Log from + * @param {number} [length=-1] How many items to include in the log + * @param {Array} [exclude] Entries to not fetch (cached) + * @param {function(cid, entry, parent, depth)} onProgressCallback + * @returns {Promise} + * @deprecated + */ }, { - key: "fromEntryHash", + key: "fromMultihash", value: function () { - var _fromEntryHash = (0, _asyncToGenerator2.default)( + var _fromMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee6(ipfs, access, identity, hash, id) { + _regenerator.default.mark(function _callee6(ipfs, access, identity, multihash) { var length, exclude, onProgressCallback, - data, _args6 = arguments; return _regenerator.default.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { case 0: - length = _args6.length > 5 && _args6[5] !== undefined ? _args6[5] : -1; - exclude = _args6.length > 6 ? _args6[6] : undefined; - onProgressCallback = _args6.length > 7 ? _args6[7] : undefined; + length = _args6.length > 4 && _args6[4] !== undefined ? _args6[4] : -1; + exclude = _args6.length > 5 ? _args6[5] : undefined; + onProgressCallback = _args6.length > 6 ? _args6[6] : undefined; + return _context6.abrupt("return", Log.fromCID(ipfs, access, identity, multihash, length, exclude, onProgressCallback)); - if (isDefined(ipfs)) { - _context6.next = 5; - break; - } + case 4: + case "end": + return _context6.stop(); + } + } + }, _callee6, this); + })); + + function fromMultihash(_x9, _x10, _x11, _x12) { + return _fromMultihash.apply(this, arguments); + } - throw LogError.IPFSNotDefinedError(); + return fromMultihash; + }() + /** + * Create a log from a single entry's CID. + * @param {IPFS} ipfs An IPFS instance + * @param {AccessController} access The access controller instance + * @param {Identity} identity The identity instance + * @param {string} cid The entry's CID + * @param {string} [logId] The ID of the log + * @param {number} [length=-1] How many entries to include in the log + * @param {function(cid, entry, parent, depth)} onProgressCallback + * @return {Promise} New Log + */ - case 5: - if (isDefined(hash)) { - _context6.next = 7; - break; - } + }, { + key: "fromEntryCid", + value: function () { + var _fromEntryCid = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee7(ipfs, access, identity, cid, logId) { + var length, + exclude, + onProgressCallback, + data, + _args7 = arguments; + return _regenerator.default.wrap(function _callee7$(_context7) { + while (1) { + switch (_context7.prev = _context7.next) { + case 0: + length = _args7.length > 5 && _args7[5] !== undefined ? _args7[5] : -1; + exclude = _args7.length > 6 ? _args7[6] : undefined; + onProgressCallback = _args7.length > 7 ? _args7[7] : undefined; + _context7.next = 5; + return LogIO.fromEntryCid(ipfs, cid, length, exclude, onProgressCallback); - throw new Error("'hash' must be defined"); + case 5: + data = _context7.sent; + return _context7.abrupt("return", new Log(ipfs, access, identity, logId, data.values)); case 7: - _context6.next = 9; - return LogIO.fromEntryHash(ipfs, hash, id, length, exclude, onProgressCallback); + case "end": + return _context7.stop(); + } + } + }, _callee7, this); + })); - case 9: - data = _context6.sent; - return _context6.abrupt("return", new Log(ipfs, access, identity, id, data.values)); + function fromEntryCid(_x13, _x14, _x15, _x16, _x17) { + return _fromEntryCid.apply(this, arguments); + } - case 11: + return fromEntryCid; + }() + /** + * Create a log from a single entry's multihash. + * @param {IPFS} ipfs An IPFS instance + * @param {AccessController} access The access controller instance + * @param {Identity} identity The identity instance + * @param {string} multihash The entry's multihash + * @param {string} [logId] The ID of the log + * @param {number} [length=-1] How many entries to include in the log + * @param {function(cid, entry, parent, depth)} onProgressCallback + * @return {Promise} New Log + * @deprecated + */ + + }, { + key: "fromEntryHash", + value: function () { + var _fromEntryHash = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee8(ipfs, access, identity, multihash, logId) { + var length, + exclude, + onProgressCallback, + _args8 = arguments; + return _regenerator.default.wrap(function _callee8$(_context8) { + while (1) { + switch (_context8.prev = _context8.next) { + case 0: + length = _args8.length > 5 && _args8[5] !== undefined ? _args8[5] : -1; + exclude = _args8.length > 6 ? _args8[6] : undefined; + onProgressCallback = _args8.length > 7 ? _args8[7] : undefined; + return _context8.abrupt("return", Log.fromEntryCid(ipfs, access, identity, multihash, logId, length, exclude, onProgressCallback)); + + case 4: case "end": - return _context6.stop(); + return _context8.stop(); } } - }, _callee6, this); + }, _callee8, this); })); - function fromEntryHash(_x9, _x10, _x11, _x12, _x13) { + function fromEntryHash(_x18, _x19, _x20, _x21, _x22) { return _fromEntryHash.apply(this, arguments); } return fromEntryHash; }() /** - * Create a log from a Log Snapshot JSON - * @param {IPFS} ipfs An IPFS instance - * @param {Object} json Log snapshot as JSON object - * @param {Number} [length=-1] How many entries to include in the log - * @param {Function(hash, entry, parent, depth)} [onProgressCallback] - * @return {Promise} New Log + * Create a log from a Log Snapshot JSON. + * @param {IPFS} ipfs An IPFS instance + * @param {AccessController} access The access controller instance + * @param {Identity} identity The identity instance + * @param {Object} json Log snapshot as JSON object + * @param {number} [length=-1] How many entries to include in the log + * @param {function(cid, entry, parent, depth)} [onProgressCallback] + * @return {Promise} New Log */ }, { @@ -815,57 +900,48 @@ function (_GSet) { value: function () { var _fromJSON = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee7(ipfs, access, identity, json) { + _regenerator.default.mark(function _callee9(ipfs, access, identity, json) { var length, timeout, onProgressCallback, data, - _args7 = arguments; - return _regenerator.default.wrap(function _callee7$(_context7) { + _args9 = arguments; + return _regenerator.default.wrap(function _callee9$(_context9) { while (1) { - switch (_context7.prev = _context7.next) { + switch (_context9.prev = _context9.next) { case 0: - length = _args7.length > 4 && _args7[4] !== undefined ? _args7[4] : -1; - timeout = _args7.length > 5 ? _args7[5] : undefined; - onProgressCallback = _args7.length > 6 ? _args7[6] : undefined; - - if (isDefined(ipfs)) { - _context7.next = 5; - break; - } - - throw LogError.IPFSNotDefinedError(); + length = _args9.length > 4 && _args9[4] !== undefined ? _args9[4] : -1; + timeout = _args9.length > 5 ? _args9[5] : undefined; + onProgressCallback = _args9.length > 6 ? _args9[6] : undefined; + _context9.next = 5; + return LogIO.fromJSON(ipfs, json, length, timeout, onProgressCallback); case 5: - _context7.next = 7; - return LogIO.fromJSON(ipfs, json, length, timeout, onProgressCallback); + data = _context9.sent; + return _context9.abrupt("return", new Log(ipfs, access, identity, data.id, data.values)); case 7: - data = _context7.sent; - return _context7.abrupt("return", new Log(ipfs, access, identity, data.id, data.values)); - - case 9: case "end": - return _context7.stop(); + return _context9.stop(); } } - }, _callee7, this); + }, _callee9, this); })); - function fromJSON(_x14, _x15, _x16, _x17) { + function fromJSON(_x23, _x24, _x25, _x26) { return _fromJSON.apply(this, arguments); } return fromJSON; }() /** - * Create a new log from an Entry instance - * @param {IPFS} ipfs An IPFS instance - * @param {Entry|Array} sourceEntries An Entry or an array of entries to fetch a log from - * @param {Number} [length=-1] How many entries to include. Default: infinite. - * @param {Array} [exclude] Array of entries or hashes or entries to not fetch (foe eg. cached entries) - * @param {Function(hash, entry, parent, depth)} [onProgressCallback] - * @return {Promise} New Log + * Create a new log from an Entry instance. + * @param {IPFS} ipfs An IPFS instance + * @param {Entry|Array} sourceEntries An Entry or an array of entries to fetch a log from + * @param {number} [length=-1] How many entries to include. Default: infinite. + * @param {Array} [exclude] Entries to not fetch (cached) + * @param {function(cid, entry, parent, depth)} [onProgressCallback] + * @return {Promise} New Log */ }, { @@ -873,65 +949,47 @@ function (_GSet) { value: function () { var _fromEntry = (0, _asyncToGenerator2.default)( /*#__PURE__*/ - _regenerator.default.mark(function _callee8(ipfs, access, identity, sourceEntries) { + _regenerator.default.mark(function _callee10(ipfs, access, identity, sourceEntries) { var length, exclude, onProgressCallback, data, - _args8 = arguments; - return _regenerator.default.wrap(function _callee8$(_context8) { + _args10 = arguments; + return _regenerator.default.wrap(function _callee10$(_context10) { while (1) { - switch (_context8.prev = _context8.next) { + switch (_context10.prev = _context10.next) { case 0: - length = _args8.length > 4 && _args8[4] !== undefined ? _args8[4] : -1; - exclude = _args8.length > 5 ? _args8[5] : undefined; - onProgressCallback = _args8.length > 6 ? _args8[6] : undefined; - - if (isDefined(ipfs)) { - _context8.next = 5; - break; - } - - throw LogError.IPFSNotDefinedError(); + length = _args10.length > 4 && _args10[4] !== undefined ? _args10[4] : -1; + exclude = _args10.length > 5 ? _args10[5] : undefined; + onProgressCallback = _args10.length > 6 ? _args10[6] : undefined; + _context10.next = 5; + return LogIO.fromEntry(ipfs, sourceEntries, length, exclude, onProgressCallback); case 5: - if (isDefined(sourceEntries)) { - _context8.next = 7; - break; - } - - throw new Error("'sourceEntries' must be defined"); + data = _context10.sent; + return _context10.abrupt("return", new Log(ipfs, access, identity, data.id, data.values)); case 7: - _context8.next = 9; - return LogIO.fromEntry(ipfs, sourceEntries, length, exclude, onProgressCallback); - - case 9: - data = _context8.sent; - return _context8.abrupt("return", new Log(ipfs, access, identity, data.id, data.values)); - - case 11: case "end": - return _context8.stop(); + return _context10.stop(); } } - }, _callee8, this); + }, _callee10, this); })); - function fromEntry(_x18, _x19, _x20, _x21) { + function fromEntry(_x27, _x28, _x29, _x30) { return _fromEntry.apply(this, arguments); } return fromEntry; }() /** - * Find heads from a collection of entries + * Find heads from a collection of entries. * - * @description * Finds entries that are the heads of this collection, - * ie. entries that are not referenced by other entries + * ie. entries that are not referenced by other entries. * - * @param {Array} Entries to search heads from + * @param {Array} entries Entries to search heads from * @returns {Array} */ @@ -940,7 +998,7 @@ function (_GSet) { value: function findHeads(entries) { var indexReducer = function indexReducer(res, entry, idx, arr) { var addToResult = function addToResult(e) { - return res[e] = entry.hash; + return res[e] = entry.cid; }; entry.next.forEach(addToResult); @@ -950,7 +1008,7 @@ function (_GSet) { var items = entries.reduce(indexReducer, {}); var exists = function exists(e) { - return items[e.hash] === undefined; + return items[e.cid] === undefined; }; var compareIds = function compareIds(a, b) { @@ -967,9 +1025,9 @@ function (_GSet) { // Reverse index { next -> entry } var reverseIndex = {}; // Null index containing entries that have no parents (nexts) - var nullIndex = []; // Hashes for all entries for quick lookups + var nullIndex = []; // CIDs for all entries for quick lookups - var hashes = {}; // Hashes of all next entries + var cids = {}; // CIDs of all next entries var nexts = []; @@ -987,50 +1045,50 @@ function (_GSet) { e.next.forEach(addToReverseIndex); // Get all next references - nexts = nexts.concat(e.next); // Get the hashes of input entries + nexts = nexts.concat(e.next); // Get the cids of input entries - hashes[e.hash] = true; + cids[e.cid] = true; }; // Create our indices entries.forEach(addToIndex); var addUniques = function addUniques(res, entries, idx, arr) { - return res.concat(findUniques(entries, 'hash')); + return res.concat(findUniques(entries, 'cid')); }; var exists = function exists(e) { - return hashes[e] === undefined; + return cids[e] === undefined; }; var findFromReverseIndex = function findFromReverseIndex(e) { return reverseIndex[e]; - }; // Drop hashes that are not in the input entries + }; // Drop cids that are not in the input entries - var tails = nexts // For every multihash in nexts: + var tails = nexts // For every cid in nexts: .filter(exists) // Remove undefineds and nulls .map(findFromReverseIndex) // Get the Entry from the reverse index .reduce(addUniques, []) // Flatten the result and take only uniques .concat(nullIndex); // Combine with tails the have no next refs (ie. first-in-their-chain) - return findUniques(tails, 'hash').sort(Entry.compare); - } // Find the hashes to entries that are not in a collection + return findUniques(tails, 'cid').sort(Entry.compare); + } // Find the cids to entries that are not in a collection // but referenced by other entries }, { - key: "findTailHashes", - value: function findTailHashes(entries) { - var hashes = {}; + key: "findTailCids", + value: function findTailCids(entries) { + var cids = {}; var addToIndex = function addToIndex(e) { - return hashes[e.hash] = true; + return cids[e.cid] = true; }; - var reduceTailHashes = function reduceTailHashes(res, entry, idx, arr) { + var reduceTailCids = function reduceTailCids(res, entry, idx, arr) { var addToResult = function addToResult(e) { /* istanbul ignore else */ - if (hashes[e] === undefined) { + if (cids[e] === undefined) { res.splice(0, 0, e); } }; @@ -1040,7 +1098,7 @@ function (_GSet) { }; entries.forEach(addToIndex); - return entries.reduce(reduceTailHashes, []); + return entries.reduce(reduceTailCids, []); } }, { key: "difference", @@ -1049,20 +1107,20 @@ function (_GSet) { var traversed = {}; var res = {}; - var pushToStack = function pushToStack(hash) { - if (!traversed[hash] && !b.get(hash)) { - stack.push(hash); - traversed[hash] = true; + var pushToStack = function pushToStack(cid) { + if (!traversed[cid] && !b.get(cid)) { + stack.push(cid); + traversed[cid] = true; } }; while (stack.length > 0) { - var hash = stack.shift(); - var entry = a.get(hash); + var cid = stack.shift(); + var entry = a.get(cid); - if (entry && !b.get(hash) && entry.id === b.id) { - res[entry.hash] = entry; - traversed[entry.hash] = true; + if (entry && !b.get(cid) && entry.id === b.id) { + res[entry.cid] = entry; + traversed[entry.cid] = true; entry.next.forEach(pushToStack); } } diff --git a/lib/es5/utils/dag-node.js b/lib/es5/utils/dag-node.js new file mode 100644 index 00000000..5bb6754d --- /dev/null +++ b/lib/es5/utils/dag-node.js @@ -0,0 +1,212 @@ +"use strict"; + +var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); + +var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); + +var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); + +var CID = require('cids'); + +var dagPB = require('ipld-dag-pb'); + +var pify = require('pify'); + +var createPbDagNode = pify(dagPB.DAGNode.create); + +var cidToCborLink = function cidToCborLink(cid) { + if (!cid) { + return cid; + } + + if (Array.isArray(cid)) { + return cid.map(cidToCborLink); + } + + return { + '/': cid + }; +}; + +var stringifyCid = function stringifyCid(cid) { + if (!cid) { + return cid; + } + + if (Array.isArray(cid)) { + return cid.map(stringifyCid); + } + + return cid.toBaseEncodedString(); +}; + +var writePb = +/*#__PURE__*/ +function () { + var _ref = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee(ipfs, obj) { + var buffer, dagNode, cid; + return _regenerator.default.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + buffer = Buffer.from(JSON.stringify(obj)); + _context.next = 3; + return createPbDagNode(buffer); + + case 3: + dagNode = _context.sent; + _context.next = 6; + return ipfs.dag.put(dagNode, { + format: 'dag-pb', + hashAlg: 'sha2-256' + }); + + case 6: + cid = _context.sent; + return _context.abrupt("return", cid.toV0().toBaseEncodedString()); + + case 8: + case "end": + return _context.stop(); + } + } + }, _callee, this); + })); + + return function writePb(_x, _x2) { + return _ref.apply(this, arguments); + }; +}(); + +var readPb = +/*#__PURE__*/ +function () { + var _ref2 = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee2(ipfs, cid) { + var result, dagNode; + return _regenerator.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return ipfs.dag.get(cid); + + case 2: + result = _context2.sent; + dagNode = result.value; + return _context2.abrupt("return", JSON.parse(dagNode.toJSON().data)); + + case 5: + case "end": + return _context2.stop(); + } + } + }, _callee2, this); + })); + + return function readPb(_x3, _x4) { + return _ref2.apply(this, arguments); + }; +}(); + +var writeCbor = +/*#__PURE__*/ +function () { + var _ref3 = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee3(ipfs, obj, links) { + var dagNode, cid; + return _regenerator.default.wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + dagNode = Object.assign({}, obj); + links.forEach(function (prop) { + dagNode[prop] = cidToCborLink(dagNode[prop]); + }); + _context3.next = 4; + return ipfs.dag.put(dagNode); + + case 4: + cid = _context3.sent; + return _context3.abrupt("return", cid.toBaseEncodedString()); + + case 6: + case "end": + return _context3.stop(); + } + } + }, _callee3, this); + })); + + return function writeCbor(_x5, _x6, _x7) { + return _ref3.apply(this, arguments); + }; +}(); + +var readCbor = +/*#__PURE__*/ +function () { + var _ref4 = (0, _asyncToGenerator2.default)( + /*#__PURE__*/ + _regenerator.default.mark(function _callee4(ipfs, cid, links) { + var result, obj; + return _regenerator.default.wrap(function _callee4$(_context4) { + while (1) { + switch (_context4.prev = _context4.next) { + case 0: + _context4.next = 2; + return ipfs.dag.get(cid); + + case 2: + result = _context4.sent; + obj = result.value; + links.forEach(function (prop) { + obj[prop] = stringifyCid(obj[prop]); + }); + return _context4.abrupt("return", obj); + + case 6: + case "end": + return _context4.stop(); + } + } + }, _callee4, this); + })); + + return function readCbor(_x8, _x9, _x10) { + return _ref4.apply(this, arguments); + }; +}(); + +var formats = { + 'dag-pb': { + read: readPb, + write: writePb + }, + 'dag-cbor': { + write: writeCbor, + read: readCbor + } +}; + +var write = function write(ipfs, codec, obj, links) { + var format = formats[codec]; + if (!format) throw new Error('Unsupported codec'); + return format.write(ipfs, obj, links); +}; + +var read = function read(ipfs, cid, links) { + cid = new CID(cid); + var format = formats[cid.codec]; + if (!format) throw new Error('Unsupported codec'); + return format.read(ipfs, cid, links); +}; + +module.exports = { + read: read, + write: write +}; \ No newline at end of file diff --git a/lib/es5/utils/index.js b/lib/es5/utils/index.js index e524fbc3..a1417ba5 100644 --- a/lib/es5/utils/index.js +++ b/lib/es5/utils/index.js @@ -6,8 +6,11 @@ var findUniques = require('./find-uniques'); var isDefined = require('./is-defined'); +var dagNode = require('./dag-node'); + module.exports = { difference: difference, findUniques: findUniques, - isDefined: isDefined + isDefined: isDefined, + dagNode: dagNode }; \ No newline at end of file diff --git a/src/log-io.js b/src/log-io.js index 79f1a5d3..ad57c296 100644 --- a/src/log-io.js +++ b/src/log-io.js @@ -75,20 +75,6 @@ class LogIO { } } - /** - * Create a log from a multihash. - * @param {IPFS} ipfs An IPFS instance - * @param {string} multihash Multihash (as a Base58 encoded string) to create the Log from - * @param {number} [length=-1] How many items to include in the log - * @param {Array} [exclude] Entries to not fetch (cached) - * @param {function(cid, entry, parent, depth)} onProgressCallback - * @returns {Promise} - * @deprecated - */ - static async fromMultihash (ipfs, multihash, length = -1, exclude, onProgressCallback) { - return LogIO.fromCID(ipfs, multihash, length, exclude, onProgressCallback) - } - static async fromEntryCid (ipfs, entryCid, length = -1, exclude, onProgressCallback) { if (!isDefined(ipfs)) throw LogError.IpfsNotDefinedError() if (!isDefined(entryCid)) throw new Error("'entryCid' must be defined")