@libp2p/record 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PRecord = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PRecord=(()=>{var Yt=Object.create;var R=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var g=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ie=(r,t)=>{for(var e in t)R(r,e,{get:t[e],enumerable:!0})},st=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ee(t))!ne.call(r,i)&&i!==e&&R(r,i,{get:()=>t[i],enumerable:!(n=te(t,i))||n.enumerable});return r};var D=(r,t,e)=>(e=r!=null?Yt(re(r)):{},st(t||!r||!r.__esModule?R(e,"default",{value:r,enumerable:!0}):e,r)),oe=r=>st(R({},"__esModule",{value:!0}),r);var at=g((Be,ut)=>{"use strict";ut.exports=se;function se(r,t){for(var e=new Array(arguments.length-1),n=0,i=2,s=!0;i<arguments.length;)e[n++]=arguments[i++];return new Promise(function(f,o){e[n]=function(c){if(s)if(s=!1,c)o(c);else{for(var y=new Array(arguments.length-1),A=0;A<y.length;)y[A++]=arguments[A];f.apply(null,y)}};try{r.apply(t||null,e)}catch(u){s&&(s=!1,o(u))}})}});var lt=g(ct=>{"use strict";var z=ct;z.length=function(t){var e=t.length;if(!e)return 0;for(var n=0;--e%4>1&&t.charAt(e)==="=";)++n;return Math.ceil(t.length*3)/4-n};var L=new Array(64),ht=new Array(123);for(w=0;w<64;)ht[L[w]=w<26?w+65:w<52?w+71:w<62?w-4:w-59|43]=w++;var w;z.encode=function(t,e,n){for(var i=null,s=[],a=0,f=0,o;e<n;){var u=t[e++];switch(f){case 0:s[a++]=L[u>>2],o=(u&3)<<4,f=1;break;case 1:s[a++]=L[o|u>>4],o=(u&15)<<2,f=2;break;case 2:s[a++]=L[o|u>>6],s[a++]=L[u&63],f=0;break}a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,s)),a=0)}return f&&(s[a++]=L[o],s[a++]=61,f===1&&(s[a++]=61)),i?(a&&i.push(String.fromCharCode.apply(String,s.slice(0,a))),i.join("")):String.fromCharCode.apply(String,s.slice(0,a))};var ft="invalid encoding";z.decode=function(t,e,n){for(var i=n,s=0,a,f=0;f<t.length;){var o=t.charCodeAt(f++);if(o===61&&s>1)break;if((o=ht[o])===void 0)throw Error(ft);switch(s){case 0:a=o,s=1;break;case 1:e[n++]=a<<2|(o&48)>>4,a=o,s=2;break;case 2:e[n++]=(a&15)<<4|(o&60)>>2,a=o,s=3;break;case 3:e[n++]=(a&3)<<6|o,s=0;break}}if(s===1)throw Error(ft);return n-i};z.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}});var dt=g((be,pt)=>{"use strict";pt.exports=U;function U(){this._listeners={}}U.prototype.on=function(t,e,n){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:e,ctx:n||this}),this};U.prototype.off=function(t,e){if(t===void 0)this._listeners={};else if(e===void 0)this._listeners[t]=[];else for(var n=this._listeners[t],i=0;i<n.length;)n[i].fn===e?n.splice(i,1):++i;return this};U.prototype.emit=function(t){var e=this._listeners[t];if(e){for(var n=[],i=1;i<arguments.length;)n.push(arguments[i++]);for(i=0;i<e.length;)e[i].fn.apply(e[i++].ctx,n)}return this}});var xt=g((ve,Bt)=>{"use strict";Bt.exports=gt(gt);function gt(r){return typeof Float32Array<"u"?function(){var t=new Float32Array([-0]),e=new Uint8Array(t.buffer),n=e[3]===128;function i(o,u,c){t[0]=o,u[c]=e[0],u[c+1]=e[1],u[c+2]=e[2],u[c+3]=e[3]}function s(o,u,c){t[0]=o,u[c]=e[3],u[c+1]=e[2],u[c+2]=e[1],u[c+3]=e[0]}r.writeFloatLE=n?i:s,r.writeFloatBE=n?s:i;function a(o,u){return e[0]=o[u],e[1]=o[u+1],e[2]=o[u+2],e[3]=o[u+3],t[0]}function f(o,u){return e[3]=o[u],e[2]=o[u+1],e[1]=o[u+2],e[0]=o[u+3],t[0]}r.readFloatLE=n?a:f,r.readFloatBE=n?f:a}():function(){function t(n,i,s,a){var f=i<0?1:0;if(f&&(i=-i),i===0)n(1/i>0?0:2147483648,s,a);else if(isNaN(i))n(2143289344,s,a);else if(i>34028234663852886e22)n((f<<31|2139095040)>>>0,s,a);else if(i<11754943508222875e-54)n((f<<31|Math.round(i/1401298464324817e-60))>>>0,s,a);else{var o=Math.floor(Math.log(i)/Math.LN2),u=Math.round(i*Math.pow(2,-o)*8388608)&8388607;n((f<<31|o+127<<23|u)>>>0,s,a)}}r.writeFloatLE=t.bind(null,yt),r.writeFloatBE=t.bind(null,mt);function e(n,i,s){var a=n(i,s),f=(a>>31)*2+1,o=a>>>23&255,u=a&8388607;return o===255?u?NaN:f*(1/0):o===0?f*1401298464324817e-60*u:f*Math.pow(2,o-150)*(u+8388608)}r.readFloatLE=e.bind(null,wt),r.readFloatBE=e.bind(null,_t)}(),typeof Float64Array<"u"?function(){var t=new Float64Array([-0]),e=new Uint8Array(t.buffer),n=e[7]===128;function i(o,u,c){t[0]=o,u[c]=e[0],u[c+1]=e[1],u[c+2]=e[2],u[c+3]=e[3],u[c+4]=e[4],u[c+5]=e[5],u[c+6]=e[6],u[c+7]=e[7]}function s(o,u,c){t[0]=o,u[c]=e[7],u[c+1]=e[6],u[c+2]=e[5],u[c+3]=e[4],u[c+4]=e[3],u[c+5]=e[2],u[c+6]=e[1],u[c+7]=e[0]}r.writeDoubleLE=n?i:s,r.writeDoubleBE=n?s:i;function a(o,u){return e[0]=o[u],e[1]=o[u+1],e[2]=o[u+2],e[3]=o[u+3],e[4]=o[u+4],e[5]=o[u+5],e[6]=o[u+6],e[7]=o[u+7],t[0]}function f(o,u){return e[7]=o[u],e[6]=o[u+1],e[5]=o[u+2],e[4]=o[u+3],e[3]=o[u+4],e[2]=o[u+5],e[1]=o[u+6],e[0]=o[u+7],t[0]}r.readDoubleLE=n?a:f,r.readDoubleBE=n?f:a}():function(){function t(n,i,s,a,f,o){var u=a<0?1:0;if(u&&(a=-a),a===0)n(0,f,o+i),n(1/a>0?0:2147483648,f,o+s);else if(isNaN(a))n(0,f,o+i),n(2146959360,f,o+s);else if(a>17976931348623157e292)n(0,f,o+i),n((u<<31|2146435072)>>>0,f,o+s);else{var c;if(a<22250738585072014e-324)c=a/5e-324,n(c>>>0,f,o+i),n((u<<31|c/4294967296)>>>0,f,o+s);else{var y=Math.floor(Math.log(a)/Math.LN2);y===1024&&(y=1023),c=a*Math.pow(2,-y),n(c*4503599627370496>>>0,f,o+i),n((u<<31|y+1023<<20|c*1048576&1048575)>>>0,f,o+s)}}}r.writeDoubleLE=t.bind(null,yt,0,4),r.writeDoubleBE=t.bind(null,mt,4,0);function e(n,i,s,a,f){var o=n(a,f+i),u=n(a,f+s),c=(u>>31)*2+1,y=u>>>20&2047,A=4294967296*(u&1048575)+o;return y===2047?A?NaN:c*(1/0):y===0?c*5e-324*A:c*Math.pow(2,y-1075)*(A+4503599627370496)}r.readDoubleLE=e.bind(null,wt,0,4),r.readDoubleBE=e.bind(null,_t,4,0)}(),r}function yt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function mt(r,t,e){t[e]=r>>>24,t[e+1]=r>>>16&255,t[e+2]=r>>>8&255,t[e+3]=r&255}function wt(r,t){return(r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24)>>>0}function _t(r,t){return(r[t]<<24|r[t+1]<<16|r[t+2]<<8|r[t+3])>>>0}});var bt=g((exports,module)=>{"use strict";module.exports=inquire;function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(r){}return null}});var At=g(vt=>{"use strict";var q=vt;q.length=function(t){for(var e=0,n=0,i=0;i<t.length;++i)n=t.charCodeAt(i),n<128?e+=1:n<2048?e+=2:(n&64512)===55296&&(t.charCodeAt(i+1)&64512)===56320?(++i,e+=4):e+=3;return e};q.read=function(t,e,n){var i=n-e;if(i<1)return"";for(var s=null,a=[],f=0,o;e<n;)o=t[e++],o<128?a[f++]=o:o>191&&o<224?a[f++]=(o&31)<<6|t[e++]&63:o>239&&o<365?(o=((o&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,a[f++]=55296+(o>>10),a[f++]=56320+(o&1023)):a[f++]=(o&15)<<12|(t[e++]&63)<<6|t[e++]&63,f>8191&&((s||(s=[])).push(String.fromCharCode.apply(String,a)),f=0);return s?(f&&s.push(String.fromCharCode.apply(String,a.slice(0,f))),s.join("")):String.fromCharCode.apply(String,a.slice(0,f))};q.write=function(t,e,n){for(var i=n,s,a,f=0;f<t.length;++f)s=t.charCodeAt(f),s<128?e[n++]=s:s<2048?(e[n++]=s>>6|192,e[n++]=s&63|128):(s&64512)===55296&&((a=t.charCodeAt(f+1))&64512)===56320?(s=65536+((s&1023)<<10)+(a&1023),++f,e[n++]=s>>18|240,e[n++]=s>>12&63|128,e[n++]=s>>6&63|128,e[n++]=s&63|128):(e[n++]=s>>12|224,e[n++]=s>>6&63|128,e[n++]=s&63|128);return n-i}});var kt=g((Ee,Et)=>{"use strict";Et.exports=ue;function ue(r,t,e){var n=e||8192,i=n>>>1,s=null,a=n;return function(o){if(o<1||o>i)return r(o);a+o>n&&(s=r(n),a=0);var u=t.call(s,a,a+=o);return a&7&&(a=(a|7)+1),u}}});var Lt=g((ke,St)=>{"use strict";St.exports=d;var C=k();function d(r,t){this.lo=r>>>0,this.hi=t>>>0}var E=d.zero=new d(0,0);E.toNumber=function(){return 0};E.zzEncode=E.zzDecode=function(){return this};E.length=function(){return 1};var ae=d.zeroHash="\0\0\0\0\0\0\0\0";d.fromNumber=function(t){if(t===0)return E;var e=t<0;e&&(t=-t);var n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new d(n,i)};d.from=function(t){if(typeof t=="number")return d.fromNumber(t);if(C.isString(t))if(C.Long)t=C.Long.fromString(t);else return d.fromNumber(parseInt(t,10));return t.low||t.high?new d(t.low>>>0,t.high>>>0):E};d.prototype.toNumber=function(t){if(!t&&this.hi>>>31){var e=~this.lo+1>>>0,n=~this.hi>>>0;return e||(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296};d.prototype.toLong=function(t){return C.Long?new C.Long(this.lo|0,this.hi|0,Boolean(t)):{low:this.lo|0,high:this.hi|0,unsigned:Boolean(t)}};var b=String.prototype.charCodeAt;d.fromHash=function(t){return t===ae?E:new d((b.call(t,0)|b.call(t,1)<<8|b.call(t,2)<<16|b.call(t,3)<<24)>>>0,(b.call(t,4)|b.call(t,5)<<8|b.call(t,6)<<16|b.call(t,7)<<24)>>>0)};d.prototype.toHash=function(){return String.fromCharCode(this.lo&255,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,this.hi&255,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)};d.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this};d.prototype.zzDecode=function(){var t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this};d.prototype.length=function(){var t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}});var k=g(H=>{"use strict";var h=H;h.asPromise=at();h.base64=lt();h.EventEmitter=dt();h.float=xt();h.inquire=bt();h.utf8=At();h.pool=kt();h.LongBits=Lt();h.isNode=Boolean(typeof globalThis<"u"&&globalThis&&globalThis.process&&globalThis.process.versions&&globalThis.process.versions.node);h.global=h.isNode&&globalThis||typeof window<"u"&&window||typeof self<"u"&&self||H;h.emptyArray=Object.freeze?Object.freeze([]):[];h.emptyObject=Object.freeze?Object.freeze({}):{};h.isInteger=Number.isInteger||function(t){return typeof t=="number"&&isFinite(t)&&Math.floor(t)===t};h.isString=function(t){return typeof t=="string"||t instanceof String};h.isObject=function(t){return t&&typeof t=="object"};h.isset=h.isSet=function(t,e){var n=t[e];return n!=null&&t.hasOwnProperty(e)?typeof n!="object"||(Array.isArray(n)?n.length:Object.keys(n).length)>0:!1};h.Buffer=function(){try{var r=h.inquire("buffer").Buffer;return r.prototype.utf8Write?r:null}catch{return null}}();h._Buffer_from=null;h._Buffer_allocUnsafe=null;h.newBuffer=function(t){return typeof t=="number"?h.Buffer?h._Buffer_allocUnsafe(t):new h.Array(t):h.Buffer?h._Buffer_from(t):typeof Uint8Array>"u"?t:new Uint8Array(t)};h.Array=typeof Uint8Array<"u"?Uint8Array:Array;h.Long=h.global.dcodeIO&&h.global.dcodeIO.Long||h.global.Long||h.inquire("long");h.key2Re=/^true|false|0|1$/;h.key32Re=/^-?(?:0|[1-9][0-9]*)$/;h.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;h.longToHash=function(t){return t?h.LongBits.from(t).toHash():h.LongBits.zeroHash};h.longFromHash=function(t,e){var n=h.LongBits.fromHash(t);return h.Long?h.Long.fromBits(n.lo,n.hi,e):n.toNumber(Boolean(e))};function Ft(r,t,e){for(var n=Object.keys(t),i=0;i<n.length;++i)(r[n[i]]===void 0||!e)&&(r[n[i]]=t[n[i]]);return r}h.merge=Ft;h.lcFirst=function(t){return t.charAt(0).toLowerCase()+t.substring(1)};function Dt(r){function t(e,n){if(!(this instanceof t))return new t(e,n);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:new Error().stack||""}),n&&Ft(this,n)}return t.prototype=Object.create(Error.prototype,{constructor:{value:t,writable:!0,enumerable:!1,configurable:!0},name:{get(){return r},set:void 0,enumerable:!1,configurable:!0},toString:{value(){return this.name+": "+this.message},writable:!0,enumerable:!1,configurable:!0}}),t}h.newError=Dt;h.ProtocolError=Dt("ProtocolError");h.oneOfGetter=function(t){for(var e={},n=0;n<t.length;++n)e[t[n]]=1;return function(){for(var i=Object.keys(this),s=i.length-1;s>-1;--s)if(e[i[s]]===1&&this[i[s]]!==void 0&&this[i[s]]!==null)return i[s]}};h.oneOfSetter=function(t){return function(e){for(var n=0;n<t.length;++n)t[n]!==e&&delete this[t[n]]}};h.toJSONOptions={longs:String,enums:String,bytes:String,json:!0};h._configure=function(){var r=h.Buffer;if(!r){h._Buffer_from=h._Buffer_allocUnsafe=null;return}h._Buffer_from=r.from!==Uint8Array.from&&r.from||function(e,n){return new r(e,n)},h._Buffer_allocUnsafe=r.allocUnsafe||function(e){return new r(e)}}});var V=g((Le,Rt)=>{"use strict";Rt.exports=p;var B=k(),W,Mt=B.LongBits,fe=B.utf8;function _(r,t){return RangeError("index out of range: "+r.pos+" + "+(t||1)+" > "+r.len)}function p(r){this.buf=r,this.pos=0,this.len=r.length}var Ct=typeof Uint8Array<"u"?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new p(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new p(t);throw Error("illegal buffer")},Nt=function(){return B.Buffer?function(e){return(p.create=function(i){return B.Buffer.isBuffer(i)?new W(i):Ct(i)})(e)}:Ct};p.create=Nt();p.prototype._slice=B.Array.prototype.subarray||B.Array.prototype.slice;p.prototype.uint32=function(){var t=4294967295;return function(){if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_(this,10);return t}}();p.prototype.int32=function(){return this.uint32()|0};p.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(t&1)|0};function $(){var r=new Mt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(r.lo=(r.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return r;if(r.lo=(r.lo|(this.buf[this.pos]&127)<<28)>>>0,r.hi=(r.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return r;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw _(this);if(r.lo=(r.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return r}return r.lo=(r.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,r}if(this.len-this.pos>4){for(;t<5;++t)if(r.hi=(r.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return r}else for(;t<5;++t){if(this.pos>=this.len)throw _(this);if(r.hi=(r.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return r}throw Error("invalid varint encoding")}p.prototype.bool=function(){return this.uint32()!==0};function O(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}p.prototype.fixed32=function(){if(this.pos+4>this.len)throw _(this,4);return O(this.buf,this.pos+=4)};p.prototype.sfixed32=function(){if(this.pos+4>this.len)throw _(this,4);return O(this.buf,this.pos+=4)|0};function It(){if(this.pos+8>this.len)throw _(this,8);return new Mt(O(this.buf,this.pos+=4),O(this.buf,this.pos+=4))}p.prototype.float=function(){if(this.pos+4>this.len)throw _(this,4);var t=B.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t};p.prototype.double=function(){if(this.pos+8>this.len)throw _(this,4);var t=B.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t};p.prototype.bytes=function(){var t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw _(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(e,n):e===n?new this.buf.constructor(0):this._slice.call(this.buf,e,n)};p.prototype.string=function(){var t=this.bytes();return fe.read(t,0,t.length)};p.prototype.skip=function(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _(this);while(this.buf[this.pos++]&128);return this};p.prototype.skipType=function(r){switch(r){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(r=this.uint32()&7)!==4;)this.skipType(r);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+r+" at offset "+this.pos)}return this};p._configure=function(r){W=r,p.create=Nt(),W._configure();var t=B.Long?"toLong":"toNumber";B.merge(p.prototype,{int64:function(){return $.call(this)[t](!1)},uint64:function(){return $.call(this)[t](!0)},sint64:function(){return $.call(this).zzDecode()[t](!1)},fixed64:function(){return It.call(this)[t](!0)},sfixed64:function(){return It.call(this)[t](!1)}})}});var Tt=g((Fe,Ot)=>{"use strict";Ot.exports=S;var Ut=V();(S.prototype=Object.create(Ut.prototype)).constructor=S;var zt=k();function S(r){Ut.call(this,r)}S._configure=function(){zt.Buffer&&(S.prototype._slice=zt.Buffer.prototype.slice)};S.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))};S._configure()});var K=g((De,Wt)=>{"use strict";Wt.exports=l;var m=k(),j,T=m.LongBits,qt=m.base64,Ht=m.utf8;function I(r,t,e){this.fn=r,this.len=t,this.next=void 0,this.val=e}function Z(){}function he(r){this.head=r.head,this.tail=r.tail,this.len=r.len,this.next=r.states}function l(){this.len=0,this.head=new I(Z,0,0),this.tail=this.head,this.states=null}var $t=function(){return m.Buffer?function(){return(l.create=function(){return new j})()}:function(){return new l}};l.create=$t();l.alloc=function(t){return new m.Array(t)};m.Array!==Array&&(l.alloc=m.pool(l.alloc,m.Array.prototype.subarray));l.prototype._push=function(t,e,n){return this.tail=this.tail.next=new I(t,e,n),this.len+=e,this};function P(r,t,e){t[e]=r&255}function ce(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}function J(r,t){this.len=r,this.next=void 0,this.val=t}J.prototype=Object.create(I.prototype);J.prototype.fn=ce;l.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new J((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this};l.prototype.int32=function(t){return t<0?this._push(X,10,T.fromNumber(t)):this.uint32(t)};l.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)};function X(r,t,e){for(;r.hi;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}l.prototype.uint64=function(t){var e=T.from(t);return this._push(X,e.length(),e)};l.prototype.int64=l.prototype.uint64;l.prototype.sint64=function(t){var e=T.from(t).zzEncode();return this._push(X,e.length(),e)};l.prototype.bool=function(t){return this._push(P,1,t?1:0)};function G(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}l.prototype.fixed32=function(t){return this._push(G,4,t>>>0)};l.prototype.sfixed32=l.prototype.fixed32;l.prototype.fixed64=function(t){var e=T.from(t);return this._push(G,4,e.lo)._push(G,4,e.hi)};l.prototype.sfixed64=l.prototype.fixed64;l.prototype.float=function(t){return this._push(m.float.writeFloatLE,4,t)};l.prototype.double=function(t){return this._push(m.float.writeDoubleLE,8,t)};var le=m.Array.prototype.set?function(t,e,n){e.set(t,n)}:function(t,e,n){for(var i=0;i<t.length;++i)e[n+i]=t[i]};l.prototype.bytes=function(t){var e=t.length>>>0;if(!e)return this._push(P,1,0);if(m.isString(t)){var n=l.alloc(e=qt.length(t));qt.decode(t,n,0),t=n}return this.uint32(e)._push(le,e,t)};l.prototype.string=function(t){var e=Ht.length(t);return e?this.uint32(e)._push(Ht.write,e,t):this._push(P,1,0)};l.prototype.fork=function(){return this.states=new he(this),this.head=this.tail=new I(Z,0,0),this.len=0,this};l.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new I(Z,0,0),this.len=0),this};l.prototype.ldelim=function(){var t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=t.next,this.tail=e,this.len+=n),this};l.prototype.finish=function(){for(var t=this.head.next,e=this.constructor.alloc(this.len),n=0;t;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e};l._configure=function(r){j=r,l.create=$t(),j._configure()}});var Gt=g((Ce,jt)=>{"use strict";jt.exports=x;var Vt=K();(x.prototype=Object.create(Vt.prototype)).constructor=x;var v=k();function x(){Vt.call(this)}x._configure=function(){x.alloc=v._Buffer_allocUnsafe,x.writeBytesBuffer=v.Buffer&&v.Buffer.prototype instanceof Uint8Array&&v.Buffer.prototype.set.name==="set"?function(t,e,n){e.set(t,n)}:function(t,e,n){if(t.copy)t.copy(e,n,0,t.length);else for(var i=0;i<t.length;)e[n++]=t[i++]}};x.prototype.bytes=function(t){v.isString(t)&&(t=v._Buffer_from(t,"base64"));var e=t.length>>>0;return this.uint32(e),e&&this._push(x.writeBytesBuffer,e,t),this};function pe(r,t,e){r.length<40?v.utf8.write(r,t,e):t.utf8Write?t.utf8Write(r,e):t.write(r,e)}x.prototype.string=function(t){var e=v.Buffer.byteLength(t);return this.uint32(e),e&&this._push(pe,e,t),this};x._configure()});var we={};ie(we,{Libp2pRecord:()=>F});var Q=D(V(),1),Zt=D(Tt(),1),Y=D(K(),1),Pt=D(Gt(),1),Jt=D(k(),1);function de(){Jt.default._configure(),Q.default._configure(Zt.default),Y.default._configure(Pt.default)}de();var Xt=["uint64","int64","sint64","fixed64","sfixed64"];function ge(r){for(let t of Xt){if(r[t]==null)continue;let e=r[t];r[t]=function(){return BigInt(e.call(this).toString())}}return r}function tt(r){return ge(new Q.default(r))}function ye(r){for(let t of Xt){if(r[t]==null)continue;let e=r[t];r[t]=function(n){return e.call(this,n.toString())}}return r}function et(){return ye(Y.default.create())}function rt(r,t){let e=tt(r instanceof Uint8Array?r:r.subarray());return t.decode(e)}function nt(r,t){let e=et();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var M;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(M||(M={}));function it(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ot(r,t){return it("message",M.LENGTH_DELIMITED,r,t)}var N;(function(r){let t;r.codec=()=>(t==null&&(t=ot((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),(i.writeDefaults===!0||e.key!=null&&e.key.byteLength>0)&&(n.uint32(10),n.bytes(e.key)),(i.writeDefaults===!0||e.value!=null&&e.value.byteLength>0)&&(n.uint32(18),n.bytes(e.value)),(i.writeDefaults===!0||e.timeReceived!=="")&&(n.uint32(42),n.string(e.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:i.key=e.bytes();break;case 2:i.value=e.bytes();break;case 5:i.timeReceived=e.string();break;default:e.skipType(a&7);break}}return i})),t),r.encode=e=>nt(e,r.codec()),r.decode=e=>rt(e,r.codec())})(N||(N={}));function Kt(r){let t=r.getUTCFullYear(),e=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),s=String(r.getUTCMinutes()).padStart(2,"0"),a=String(r.getUTCSeconds()).padStart(2,"0"),f=r.getUTCMilliseconds(),o=String(f*1e3*1e3).padStart(9,"0");return`${t}-${e}-${n}T${i}:${s}:${a}.${o}Z`}function Qt(r){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),e=String(r).trim().match(t);if(e==null)throw new Error("Invalid format");let n=parseInt(e[1],10),i=parseInt(e[2],10)-1,s=parseInt(e[3],10),a=parseInt(e[4],10),f=parseInt(e[5],10),o=parseInt(e[6],10),u=parseInt(e[7].slice(0,-6),10);return new Date(Date.UTC(n,i,s,a,f,o,u))}var F=class{constructor(t,e,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(e instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=e,this.timeReceived=n}serialize(){return N.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Kt(this.timeReceived)}}static deserialize(t){let e=N.decode(t);return new F(e.key,e.value,new Date(e.timeReceived))}static fromDeserialized(t){let e=Qt(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new F(t.key,t.value,e)}};return oe(we);})();
2
+ "use strict";var Libp2PRecord=(()=>{var Yt=Object.create;var R=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var g=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ie=(r,t)=>{for(var e in t)R(r,e,{get:t[e],enumerable:!0})},st=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of ee(t))!ne.call(r,i)&&i!==e&&R(r,i,{get:()=>t[i],enumerable:!(n=te(t,i))||n.enumerable});return r};var D=(r,t,e)=>(e=r!=null?Yt(re(r)):{},st(t||!r||!r.__esModule?R(e,"default",{value:r,enumerable:!0}):e,r)),oe=r=>st(R({},"__esModule",{value:!0}),r);var at=g((Be,ut)=>{"use strict";ut.exports=se;function se(r,t){for(var e=new Array(arguments.length-1),n=0,i=2,s=!0;i<arguments.length;)e[n++]=arguments[i++];return new Promise(function(f,o){e[n]=function(c){if(s)if(s=!1,c)o(c);else{for(var y=new Array(arguments.length-1),A=0;A<y.length;)y[A++]=arguments[A];f.apply(null,y)}};try{r.apply(t||null,e)}catch(u){s&&(s=!1,o(u))}})}});var lt=g(ct=>{"use strict";var z=ct;z.length=function(t){var e=t.length;if(!e)return 0;for(var n=0;--e%4>1&&t.charAt(e)==="=";)++n;return Math.ceil(t.length*3)/4-n};var L=new Array(64),ht=new Array(123);for(w=0;w<64;)ht[L[w]=w<26?w+65:w<52?w+71:w<62?w-4:w-59|43]=w++;var w;z.encode=function(t,e,n){for(var i=null,s=[],a=0,f=0,o;e<n;){var u=t[e++];switch(f){case 0:s[a++]=L[u>>2],o=(u&3)<<4,f=1;break;case 1:s[a++]=L[o|u>>4],o=(u&15)<<2,f=2;break;case 2:s[a++]=L[o|u>>6],s[a++]=L[u&63],f=0;break}a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,s)),a=0)}return f&&(s[a++]=L[o],s[a++]=61,f===1&&(s[a++]=61)),i?(a&&i.push(String.fromCharCode.apply(String,s.slice(0,a))),i.join("")):String.fromCharCode.apply(String,s.slice(0,a))};var ft="invalid encoding";z.decode=function(t,e,n){for(var i=n,s=0,a,f=0;f<t.length;){var o=t.charCodeAt(f++);if(o===61&&s>1)break;if((o=ht[o])===void 0)throw Error(ft);switch(s){case 0:a=o,s=1;break;case 1:e[n++]=a<<2|(o&48)>>4,a=o,s=2;break;case 2:e[n++]=(a&15)<<4|(o&60)>>2,a=o,s=3;break;case 3:e[n++]=(a&3)<<6|o,s=0;break}}if(s===1)throw Error(ft);return n-i};z.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}});var dt=g((be,pt)=>{"use strict";pt.exports=U;function U(){this._listeners={}}U.prototype.on=function(t,e,n){return(this._listeners[t]||(this._listeners[t]=[])).push({fn:e,ctx:n||this}),this};U.prototype.off=function(t,e){if(t===void 0)this._listeners={};else if(e===void 0)this._listeners[t]=[];else for(var n=this._listeners[t],i=0;i<n.length;)n[i].fn===e?n.splice(i,1):++i;return this};U.prototype.emit=function(t){var e=this._listeners[t];if(e){for(var n=[],i=1;i<arguments.length;)n.push(arguments[i++]);for(i=0;i<e.length;)e[i].fn.apply(e[i++].ctx,n)}return this}});var xt=g((ve,Bt)=>{"use strict";Bt.exports=gt(gt);function gt(r){return typeof Float32Array<"u"?function(){var t=new Float32Array([-0]),e=new Uint8Array(t.buffer),n=e[3]===128;function i(o,u,c){t[0]=o,u[c]=e[0],u[c+1]=e[1],u[c+2]=e[2],u[c+3]=e[3]}function s(o,u,c){t[0]=o,u[c]=e[3],u[c+1]=e[2],u[c+2]=e[1],u[c+3]=e[0]}r.writeFloatLE=n?i:s,r.writeFloatBE=n?s:i;function a(o,u){return e[0]=o[u],e[1]=o[u+1],e[2]=o[u+2],e[3]=o[u+3],t[0]}function f(o,u){return e[3]=o[u],e[2]=o[u+1],e[1]=o[u+2],e[0]=o[u+3],t[0]}r.readFloatLE=n?a:f,r.readFloatBE=n?f:a}():function(){function t(n,i,s,a){var f=i<0?1:0;if(f&&(i=-i),i===0)n(1/i>0?0:2147483648,s,a);else if(isNaN(i))n(2143289344,s,a);else if(i>34028234663852886e22)n((f<<31|2139095040)>>>0,s,a);else if(i<11754943508222875e-54)n((f<<31|Math.round(i/1401298464324817e-60))>>>0,s,a);else{var o=Math.floor(Math.log(i)/Math.LN2),u=Math.round(i*Math.pow(2,-o)*8388608)&8388607;n((f<<31|o+127<<23|u)>>>0,s,a)}}r.writeFloatLE=t.bind(null,yt),r.writeFloatBE=t.bind(null,mt);function e(n,i,s){var a=n(i,s),f=(a>>31)*2+1,o=a>>>23&255,u=a&8388607;return o===255?u?NaN:f*(1/0):o===0?f*1401298464324817e-60*u:f*Math.pow(2,o-150)*(u+8388608)}r.readFloatLE=e.bind(null,wt),r.readFloatBE=e.bind(null,_t)}(),typeof Float64Array<"u"?function(){var t=new Float64Array([-0]),e=new Uint8Array(t.buffer),n=e[7]===128;function i(o,u,c){t[0]=o,u[c]=e[0],u[c+1]=e[1],u[c+2]=e[2],u[c+3]=e[3],u[c+4]=e[4],u[c+5]=e[5],u[c+6]=e[6],u[c+7]=e[7]}function s(o,u,c){t[0]=o,u[c]=e[7],u[c+1]=e[6],u[c+2]=e[5],u[c+3]=e[4],u[c+4]=e[3],u[c+5]=e[2],u[c+6]=e[1],u[c+7]=e[0]}r.writeDoubleLE=n?i:s,r.writeDoubleBE=n?s:i;function a(o,u){return e[0]=o[u],e[1]=o[u+1],e[2]=o[u+2],e[3]=o[u+3],e[4]=o[u+4],e[5]=o[u+5],e[6]=o[u+6],e[7]=o[u+7],t[0]}function f(o,u){return e[7]=o[u],e[6]=o[u+1],e[5]=o[u+2],e[4]=o[u+3],e[3]=o[u+4],e[2]=o[u+5],e[1]=o[u+6],e[0]=o[u+7],t[0]}r.readDoubleLE=n?a:f,r.readDoubleBE=n?f:a}():function(){function t(n,i,s,a,f,o){var u=a<0?1:0;if(u&&(a=-a),a===0)n(0,f,o+i),n(1/a>0?0:2147483648,f,o+s);else if(isNaN(a))n(0,f,o+i),n(2146959360,f,o+s);else if(a>17976931348623157e292)n(0,f,o+i),n((u<<31|2146435072)>>>0,f,o+s);else{var c;if(a<22250738585072014e-324)c=a/5e-324,n(c>>>0,f,o+i),n((u<<31|c/4294967296)>>>0,f,o+s);else{var y=Math.floor(Math.log(a)/Math.LN2);y===1024&&(y=1023),c=a*Math.pow(2,-y),n(c*4503599627370496>>>0,f,o+i),n((u<<31|y+1023<<20|c*1048576&1048575)>>>0,f,o+s)}}}r.writeDoubleLE=t.bind(null,yt,0,4),r.writeDoubleBE=t.bind(null,mt,4,0);function e(n,i,s,a,f){var o=n(a,f+i),u=n(a,f+s),c=(u>>31)*2+1,y=u>>>20&2047,A=4294967296*(u&1048575)+o;return y===2047?A?NaN:c*(1/0):y===0?c*5e-324*A:c*Math.pow(2,y-1075)*(A+4503599627370496)}r.readDoubleLE=e.bind(null,wt,0,4),r.readDoubleBE=e.bind(null,_t,4,0)}(),r}function yt(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function mt(r,t,e){t[e]=r>>>24,t[e+1]=r>>>16&255,t[e+2]=r>>>8&255,t[e+3]=r&255}function wt(r,t){return(r[t]|r[t+1]<<8|r[t+2]<<16|r[t+3]<<24)>>>0}function _t(r,t){return(r[t]<<24|r[t+1]<<16|r[t+2]<<8|r[t+3])>>>0}});var bt=g((exports,module)=>{"use strict";module.exports=inquire;function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(r){}return null}});var At=g(vt=>{"use strict";var q=vt;q.length=function(t){for(var e=0,n=0,i=0;i<t.length;++i)n=t.charCodeAt(i),n<128?e+=1:n<2048?e+=2:(n&64512)===55296&&(t.charCodeAt(i+1)&64512)===56320?(++i,e+=4):e+=3;return e};q.read=function(t,e,n){var i=n-e;if(i<1)return"";for(var s=null,a=[],f=0,o;e<n;)o=t[e++],o<128?a[f++]=o:o>191&&o<224?a[f++]=(o&31)<<6|t[e++]&63:o>239&&o<365?(o=((o&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,a[f++]=55296+(o>>10),a[f++]=56320+(o&1023)):a[f++]=(o&15)<<12|(t[e++]&63)<<6|t[e++]&63,f>8191&&((s||(s=[])).push(String.fromCharCode.apply(String,a)),f=0);return s?(f&&s.push(String.fromCharCode.apply(String,a.slice(0,f))),s.join("")):String.fromCharCode.apply(String,a.slice(0,f))};q.write=function(t,e,n){for(var i=n,s,a,f=0;f<t.length;++f)s=t.charCodeAt(f),s<128?e[n++]=s:s<2048?(e[n++]=s>>6|192,e[n++]=s&63|128):(s&64512)===55296&&((a=t.charCodeAt(f+1))&64512)===56320?(s=65536+((s&1023)<<10)+(a&1023),++f,e[n++]=s>>18|240,e[n++]=s>>12&63|128,e[n++]=s>>6&63|128,e[n++]=s&63|128):(e[n++]=s>>12|224,e[n++]=s>>6&63|128,e[n++]=s&63|128);return n-i}});var kt=g((Ee,Et)=>{"use strict";Et.exports=ue;function ue(r,t,e){var n=e||8192,i=n>>>1,s=null,a=n;return function(o){if(o<1||o>i)return r(o);a+o>n&&(s=r(n),a=0);var u=t.call(s,a,a+=o);return a&7&&(a=(a|7)+1),u}}});var Lt=g((ke,St)=>{"use strict";St.exports=d;var C=k();function d(r,t){this.lo=r>>>0,this.hi=t>>>0}var E=d.zero=new d(0,0);E.toNumber=function(){return 0};E.zzEncode=E.zzDecode=function(){return this};E.length=function(){return 1};var ae=d.zeroHash="\0\0\0\0\0\0\0\0";d.fromNumber=function(t){if(t===0)return E;var e=t<0;e&&(t=-t);var n=t>>>0,i=(t-n)/4294967296>>>0;return e&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new d(n,i)};d.from=function(t){if(typeof t=="number")return d.fromNumber(t);if(C.isString(t))if(C.Long)t=C.Long.fromString(t);else return d.fromNumber(parseInt(t,10));return t.low||t.high?new d(t.low>>>0,t.high>>>0):E};d.prototype.toNumber=function(t){if(!t&&this.hi>>>31){var e=~this.lo+1>>>0,n=~this.hi>>>0;return e||(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296};d.prototype.toLong=function(t){return C.Long?new C.Long(this.lo|0,this.hi|0,!!t):{low:this.lo|0,high:this.hi|0,unsigned:!!t}};var b=String.prototype.charCodeAt;d.fromHash=function(t){return t===ae?E:new d((b.call(t,0)|b.call(t,1)<<8|b.call(t,2)<<16|b.call(t,3)<<24)>>>0,(b.call(t,4)|b.call(t,5)<<8|b.call(t,6)<<16|b.call(t,7)<<24)>>>0)};d.prototype.toHash=function(){return String.fromCharCode(this.lo&255,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,this.hi&255,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)};d.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this};d.prototype.zzDecode=function(){var t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this};d.prototype.length=function(){var t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}});var k=g(H=>{"use strict";var h=H;h.asPromise=at();h.base64=lt();h.EventEmitter=dt();h.float=xt();h.inquire=bt();h.utf8=At();h.pool=kt();h.LongBits=Lt();h.isNode=!!(typeof globalThis<"u"&&globalThis&&globalThis.process&&globalThis.process.versions&&globalThis.process.versions.node);h.global=h.isNode&&globalThis||typeof window<"u"&&window||typeof self<"u"&&self||H;h.emptyArray=Object.freeze?Object.freeze([]):[];h.emptyObject=Object.freeze?Object.freeze({}):{};h.isInteger=Number.isInteger||function(t){return typeof t=="number"&&isFinite(t)&&Math.floor(t)===t};h.isString=function(t){return typeof t=="string"||t instanceof String};h.isObject=function(t){return t&&typeof t=="object"};h.isset=h.isSet=function(t,e){var n=t[e];return n!=null&&t.hasOwnProperty(e)?typeof n!="object"||(Array.isArray(n)?n.length:Object.keys(n).length)>0:!1};h.Buffer=function(){try{var r=h.inquire("buffer").Buffer;return r.prototype.utf8Write?r:null}catch{return null}}();h._Buffer_from=null;h._Buffer_allocUnsafe=null;h.newBuffer=function(t){return typeof t=="number"?h.Buffer?h._Buffer_allocUnsafe(t):new h.Array(t):h.Buffer?h._Buffer_from(t):typeof Uint8Array>"u"?t:new Uint8Array(t)};h.Array=typeof Uint8Array<"u"?Uint8Array:Array;h.Long=h.global.dcodeIO&&h.global.dcodeIO.Long||h.global.Long||h.inquire("long");h.key2Re=/^true|false|0|1$/;h.key32Re=/^-?(?:0|[1-9][0-9]*)$/;h.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;h.longToHash=function(t){return t?h.LongBits.from(t).toHash():h.LongBits.zeroHash};h.longFromHash=function(t,e){var n=h.LongBits.fromHash(t);return h.Long?h.Long.fromBits(n.lo,n.hi,e):n.toNumber(!!e)};function Ft(r,t,e){for(var n=Object.keys(t),i=0;i<n.length;++i)(r[n[i]]===void 0||!e)&&(r[n[i]]=t[n[i]]);return r}h.merge=Ft;h.lcFirst=function(t){return t.charAt(0).toLowerCase()+t.substring(1)};function Dt(r){function t(e,n){if(!(this instanceof t))return new t(e,n);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:new Error().stack||""}),n&&Ft(this,n)}return t.prototype=Object.create(Error.prototype,{constructor:{value:t,writable:!0,enumerable:!1,configurable:!0},name:{get:function(){return r},set:void 0,enumerable:!1,configurable:!0},toString:{value:function(){return this.name+": "+this.message},writable:!0,enumerable:!1,configurable:!0}}),t}h.newError=Dt;h.ProtocolError=Dt("ProtocolError");h.oneOfGetter=function(t){for(var e={},n=0;n<t.length;++n)e[t[n]]=1;return function(){for(var i=Object.keys(this),s=i.length-1;s>-1;--s)if(e[i[s]]===1&&this[i[s]]!==void 0&&this[i[s]]!==null)return i[s]}};h.oneOfSetter=function(t){return function(e){for(var n=0;n<t.length;++n)t[n]!==e&&delete this[t[n]]}};h.toJSONOptions={longs:String,enums:String,bytes:String,json:!0};h._configure=function(){var r=h.Buffer;if(!r){h._Buffer_from=h._Buffer_allocUnsafe=null;return}h._Buffer_from=r.from!==Uint8Array.from&&r.from||function(e,n){return new r(e,n)},h._Buffer_allocUnsafe=r.allocUnsafe||function(e){return new r(e)}}});var V=g((Le,Rt)=>{"use strict";Rt.exports=p;var B=k(),W,Mt=B.LongBits,fe=B.utf8;function _(r,t){return RangeError("index out of range: "+r.pos+" + "+(t||1)+" > "+r.len)}function p(r){this.buf=r,this.pos=0,this.len=r.length}var Ct=typeof Uint8Array<"u"?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new p(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new p(t);throw Error("illegal buffer")},Nt=function(){return B.Buffer?function(e){return(p.create=function(i){return B.Buffer.isBuffer(i)?new W(i):Ct(i)})(e)}:Ct};p.create=Nt();p.prototype._slice=B.Array.prototype.subarray||B.Array.prototype.slice;p.prototype.uint32=function(){var t=4294967295;return function(){if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_(this,10);return t}}();p.prototype.int32=function(){return this.uint32()|0};p.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(t&1)|0};function $(){var r=new Mt(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(r.lo=(r.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return r;if(r.lo=(r.lo|(this.buf[this.pos]&127)<<28)>>>0,r.hi=(r.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return r;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw _(this);if(r.lo=(r.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return r}return r.lo=(r.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,r}if(this.len-this.pos>4){for(;t<5;++t)if(r.hi=(r.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return r}else for(;t<5;++t){if(this.pos>=this.len)throw _(this);if(r.hi=(r.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return r}throw Error("invalid varint encoding")}p.prototype.bool=function(){return this.uint32()!==0};function O(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}p.prototype.fixed32=function(){if(this.pos+4>this.len)throw _(this,4);return O(this.buf,this.pos+=4)};p.prototype.sfixed32=function(){if(this.pos+4>this.len)throw _(this,4);return O(this.buf,this.pos+=4)|0};function It(){if(this.pos+8>this.len)throw _(this,8);return new Mt(O(this.buf,this.pos+=4),O(this.buf,this.pos+=4))}p.prototype.float=function(){if(this.pos+4>this.len)throw _(this,4);var t=B.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t};p.prototype.double=function(){if(this.pos+8>this.len)throw _(this,4);var t=B.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t};p.prototype.bytes=function(){var t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw _(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(e,n):e===n?new this.buf.constructor(0):this._slice.call(this.buf,e,n)};p.prototype.string=function(){var t=this.bytes();return fe.read(t,0,t.length)};p.prototype.skip=function(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _(this);while(this.buf[this.pos++]&128);return this};p.prototype.skipType=function(r){switch(r){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(r=this.uint32()&7)!==4;)this.skipType(r);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+r+" at offset "+this.pos)}return this};p._configure=function(r){W=r,p.create=Nt(),W._configure();var t=B.Long?"toLong":"toNumber";B.merge(p.prototype,{int64:function(){return $.call(this)[t](!1)},uint64:function(){return $.call(this)[t](!0)},sint64:function(){return $.call(this).zzDecode()[t](!1)},fixed64:function(){return It.call(this)[t](!0)},sfixed64:function(){return It.call(this)[t](!1)}})}});var Tt=g((Fe,Ot)=>{"use strict";Ot.exports=S;var Ut=V();(S.prototype=Object.create(Ut.prototype)).constructor=S;var zt=k();function S(r){Ut.call(this,r)}S._configure=function(){zt.Buffer&&(S.prototype._slice=zt.Buffer.prototype.slice)};S.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))};S._configure()});var K=g((De,Wt)=>{"use strict";Wt.exports=l;var m=k(),G,T=m.LongBits,qt=m.base64,Ht=m.utf8;function I(r,t,e){this.fn=r,this.len=t,this.next=void 0,this.val=e}function Z(){}function he(r){this.head=r.head,this.tail=r.tail,this.len=r.len,this.next=r.states}function l(){this.len=0,this.head=new I(Z,0,0),this.tail=this.head,this.states=null}var $t=function(){return m.Buffer?function(){return(l.create=function(){return new G})()}:function(){return new l}};l.create=$t();l.alloc=function(t){return new m.Array(t)};m.Array!==Array&&(l.alloc=m.pool(l.alloc,m.Array.prototype.subarray));l.prototype._push=function(t,e,n){return this.tail=this.tail.next=new I(t,e,n),this.len+=e,this};function P(r,t,e){t[e]=r&255}function ce(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}function J(r,t){this.len=r,this.next=void 0,this.val=t}J.prototype=Object.create(I.prototype);J.prototype.fn=ce;l.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new J((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this};l.prototype.int32=function(t){return t<0?this._push(X,10,T.fromNumber(t)):this.uint32(t)};l.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)};function X(r,t,e){for(;r.hi;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}l.prototype.uint64=function(t){var e=T.from(t);return this._push(X,e.length(),e)};l.prototype.int64=l.prototype.uint64;l.prototype.sint64=function(t){var e=T.from(t).zzEncode();return this._push(X,e.length(),e)};l.prototype.bool=function(t){return this._push(P,1,t?1:0)};function j(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}l.prototype.fixed32=function(t){return this._push(j,4,t>>>0)};l.prototype.sfixed32=l.prototype.fixed32;l.prototype.fixed64=function(t){var e=T.from(t);return this._push(j,4,e.lo)._push(j,4,e.hi)};l.prototype.sfixed64=l.prototype.fixed64;l.prototype.float=function(t){return this._push(m.float.writeFloatLE,4,t)};l.prototype.double=function(t){return this._push(m.float.writeDoubleLE,8,t)};var le=m.Array.prototype.set?function(t,e,n){e.set(t,n)}:function(t,e,n){for(var i=0;i<t.length;++i)e[n+i]=t[i]};l.prototype.bytes=function(t){var e=t.length>>>0;if(!e)return this._push(P,1,0);if(m.isString(t)){var n=l.alloc(e=qt.length(t));qt.decode(t,n,0),t=n}return this.uint32(e)._push(le,e,t)};l.prototype.string=function(t){var e=Ht.length(t);return e?this.uint32(e)._push(Ht.write,e,t):this._push(P,1,0)};l.prototype.fork=function(){return this.states=new he(this),this.head=this.tail=new I(Z,0,0),this.len=0,this};l.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new I(Z,0,0),this.len=0),this};l.prototype.ldelim=function(){var t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n&&(this.tail.next=t.next,this.tail=e,this.len+=n),this};l.prototype.finish=function(){for(var t=this.head.next,e=this.constructor.alloc(this.len),n=0;t;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e};l._configure=function(r){G=r,l.create=$t(),G._configure()}});var jt=g((Ce,Gt)=>{"use strict";Gt.exports=x;var Vt=K();(x.prototype=Object.create(Vt.prototype)).constructor=x;var v=k();function x(){Vt.call(this)}x._configure=function(){x.alloc=v._Buffer_allocUnsafe,x.writeBytesBuffer=v.Buffer&&v.Buffer.prototype instanceof Uint8Array&&v.Buffer.prototype.set.name==="set"?function(t,e,n){e.set(t,n)}:function(t,e,n){if(t.copy)t.copy(e,n,0,t.length);else for(var i=0;i<t.length;)e[n++]=t[i++]}};x.prototype.bytes=function(t){v.isString(t)&&(t=v._Buffer_from(t,"base64"));var e=t.length>>>0;return this.uint32(e),e&&this._push(x.writeBytesBuffer,e,t),this};function pe(r,t,e){r.length<40?v.utf8.write(r,t,e):t.utf8Write?t.utf8Write(r,e):t.write(r,e)}x.prototype.string=function(t){var e=v.Buffer.byteLength(t);return this.uint32(e),e&&this._push(pe,e,t),this};x._configure()});var we={};ie(we,{Libp2pRecord:()=>F});var Q=D(V(),1),Zt=D(Tt(),1),Pt=D(k(),1),Y=D(K(),1),Jt=D(jt(),1);function de(){Pt.default._configure(),Q.default._configure(Zt.default),Y.default._configure(Jt.default)}de();var Xt=["uint64","int64","sint64","fixed64","sfixed64"];function ge(r){for(let t of Xt){if(r[t]==null)continue;let e=r[t];r[t]=function(){return BigInt(e.call(this).toString())}}return r}function tt(r){return ge(new Q.default(r))}function ye(r){for(let t of Xt){if(r[t]==null)continue;let e=r[t];r[t]=function(n){return e.call(this,n.toString())}}return r}function et(){return ye(Y.default.create())}function rt(r,t){let e=tt(r instanceof Uint8Array?r:r.subarray());return t.decode(e)}function nt(r,t){let e=et();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var M;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(M||(M={}));function it(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function ot(r,t){return it("message",M.LENGTH_DELIMITED,r,t)}var N;(function(r){let t;r.codec=()=>(t==null&&(t=ot((e,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),e.key!=null&&e.key.byteLength>0&&(n.uint32(10),n.bytes(e.key)),e.value!=null&&e.value.byteLength>0&&(n.uint32(18),n.bytes(e.value)),e.timeReceived!=null&&e.timeReceived!==""&&(n.uint32(42),n.string(e.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let i={key:new Uint8Array(0),value:new Uint8Array(0),timeReceived:""},s=n==null?e.len:e.pos+n;for(;e.pos<s;){let a=e.uint32();switch(a>>>3){case 1:i.key=e.bytes();break;case 2:i.value=e.bytes();break;case 5:i.timeReceived=e.string();break;default:e.skipType(a&7);break}}return i})),t),r.encode=e=>nt(e,r.codec()),r.decode=e=>rt(e,r.codec())})(N||(N={}));function Kt(r){let t=r.getUTCFullYear(),e=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),s=String(r.getUTCMinutes()).padStart(2,"0"),a=String(r.getUTCSeconds()).padStart(2,"0"),f=r.getUTCMilliseconds(),o=String(f*1e3*1e3).padStart(9,"0");return`${t}-${e}-${n}T${i}:${s}:${a}.${o}Z`}function Qt(r){let t=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),e=String(r).trim().match(t);if(e==null)throw new Error("Invalid format");let n=parseInt(e[1],10),i=parseInt(e[2],10)-1,s=parseInt(e[3],10),a=parseInt(e[4],10),f=parseInt(e[5],10),o=parseInt(e[6],10),u=parseInt(e[7].slice(0,-6),10);return new Date(Date.UTC(n,i,s,a,f,o,u))}var F=class{constructor(t,e,n){if(!(t instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(e instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=t,this.value=e,this.timeReceived=n}serialize(){return N.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:Kt(this.timeReceived)}}static deserialize(t){let e=N.decode(t);return new F(e.key,e.value,new Date(e.timeReceived))}static fromDeserialized(t){let e=Qt(t.timeReceived);if(t.key==null)throw new Error("key missing from deserialized object");if(t.value==null)throw new Error("value missing from deserialized object");return new F(t.key,t.value,e)}};return oe(we);})();
3
3
  return Libp2PRecord}));
@@ -9,11 +9,7 @@ export declare class Libp2pRecord {
9
9
  /**
10
10
  * Return the object format ready to be given to the protobuf library.
11
11
  */
12
- prepareSerialize(): {
13
- key: Uint8Array;
14
- value: Uint8Array;
15
- timeReceived: string;
16
- };
12
+ prepareSerialize(): Record;
17
13
  /**
18
14
  * Decode a protobuf encoded record
19
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EACL,MAAM,EACP,MAAM,aAAa,CAAA;AAGpB,qBAAa,YAAY;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,IAAI,CAAA;gBAEZ,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI;IAcnE,SAAS;IAIT;;OAEG;IACH,gBAAgB;;;;;IAQhB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc;IAMpD;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAE,GAAG,EAAE,MAAM;CAiBrC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EACL,MAAM,EACP,MAAM,aAAa,CAAA;AAGpB,qBAAa,YAAY;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,IAAI,CAAA;gBAEZ,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI;IAcnE,SAAS,IAAK,UAAU;IAIxB;;OAEG;IACH,gBAAgB,IAAK,MAAM;IAQ3B;;OAEG;IACH,MAAM,CAAC,WAAW,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,GAAG,YAAY;IAMnE;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAE,GAAG,EAAE,MAAM,GAAG,YAAY;CAiBpD"}
@@ -1,5 +1,5 @@
1
- import type { Uint8ArrayList } from 'uint8arraylist';
2
1
  import type { Codec } from 'protons-runtime';
2
+ import type { Uint8ArrayList } from 'uint8arraylist';
3
3
  export interface Record {
4
4
  key: Uint8Array;
5
5
  value: Uint8Array;
@@ -7,7 +7,7 @@ export interface Record {
7
7
  }
8
8
  export declare namespace Record {
9
9
  const codec: () => Codec<Record>;
10
- const encode: (obj: Record) => Uint8Array;
10
+ const encode: (obj: Partial<Record>) => Uint8Array;
11
11
  const decode: (buf: Uint8Array | Uint8ArrayList) => Record;
12
12
  }
13
13
  //# sourceMappingURL=record.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,yBAAiB,MAAM,CAAC;IAGf,MAAM,KAAK,QAAO,MAAM,MAAM,CA0DpC,CAAA;IAEM,MAAM,MAAM,QAAS,MAAM,KAAG,UAEpC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,MAEzD,CAAA;CACF"}
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,yBAAiB,MAAM,CAAC;IAGf,MAAM,KAAK,QAAO,MAAM,MAAM,CA0DpC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,MAAM,CAAC,KAAG,UAE7C,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,MAEzD,CAAA;CACF"}
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable complexity */
3
3
  /* eslint-disable @typescript-eslint/no-namespace */
4
4
  /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
5
6
  import { encodeMessage, decodeMessage, message } from 'protons-runtime';
6
7
  export var Record;
7
8
  (function (Record) {
@@ -12,15 +13,15 @@ export var Record;
12
13
  if (opts.lengthDelimited !== false) {
13
14
  w.fork();
14
15
  }
15
- if (opts.writeDefaults === true || (obj.key != null && obj.key.byteLength > 0)) {
16
+ if ((obj.key != null && obj.key.byteLength > 0)) {
16
17
  w.uint32(10);
17
18
  w.bytes(obj.key);
18
19
  }
19
- if (opts.writeDefaults === true || (obj.value != null && obj.value.byteLength > 0)) {
20
+ if ((obj.value != null && obj.value.byteLength > 0)) {
20
21
  w.uint32(18);
21
22
  w.bytes(obj.value);
22
23
  }
23
- if (opts.writeDefaults === true || obj.timeReceived !== '') {
24
+ if ((obj.timeReceived != null && obj.timeReceived !== '')) {
24
25
  w.uint32(42);
25
26
  w.string(obj.timeReceived);
26
27
  }
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AoB,EAAc,EAAE;QACzD,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAgC,EAAU,EAAE;QACjE,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;AACH,CAAC,EAtEgB,MAAM,KAAN,MAAM,QAsEtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;GAEG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,UA6BrF;AAWD,eAAO,MAAM,SAAS,EAAE,SAEvB,CAAA"}
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;GAEG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CA6B9F;AAWD,eAAO,MAAM,SAAS,EAAE,SAEvB,CAAA"}
@@ -1,4 +1,4 @@
1
- import errCode from 'err-code';
1
+ import { CodeError } from '@libp2p/interfaces/errors';
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
3
3
  /**
4
4
  * Select the best record out of the given records
@@ -6,18 +6,18 @@ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
6
6
  export function bestRecord(selectors, k, records) {
7
7
  if (records.length === 0) {
8
8
  const errMsg = 'No records given';
9
- throw errCode(new Error(errMsg), 'ERR_NO_RECORDS_RECEIVED');
9
+ throw new CodeError(errMsg, 'ERR_NO_RECORDS_RECEIVED');
10
10
  }
11
11
  const kStr = uint8ArrayToString(k);
12
12
  const parts = kStr.split('/');
13
13
  if (parts.length < 3) {
14
14
  const errMsg = 'Record key does not have a selector function';
15
- throw errCode(new Error(errMsg), 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY');
15
+ throw new CodeError(errMsg, 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY');
16
16
  }
17
17
  const selector = selectors[parts[1].toString()];
18
18
  if (selector == null) {
19
19
  const errMsg = `Unrecognized key prefix: ${parts[1]}`;
20
- throw errCode(new Error(errMsg), 'ERR_UNRECOGNIZED_KEY_PREFIX');
20
+ throw new CodeError(errMsg, 'ERR_UNRECOGNIZED_KEY_PREFIX');
21
21
  }
22
22
  if (records.length === 1) {
23
23
  return 0;
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGtE;;GAEG;AACH,MAAM,UAAU,UAAU,CAAE,SAAoB,EAAE,CAAa,EAAE,OAAqB;IACpF,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,MAAM,MAAM,GAAG,kBAAkB,CAAA;QAEjC,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,yBAAyB,CAAC,CAAA;KAC5D;IAED,MAAM,IAAI,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAA;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAE7B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACpB,MAAM,MAAM,GAAG,8CAA8C,CAAA;QAE7D,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,yCAAyC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CAAA;QAE7D,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE,yCAAyC,CAAC,CAAA;KACvE;IAED,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;IAE/C,IAAI,QAAQ,IAAI,IAAI,EAAE;QACpB,MAAM,MAAM,GAAG,4BAA4B,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAErD,MAAM,IAAI,SAAS,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAA;KAC3D;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;QACxB,OAAO,CAAC,CAAA;KACT;IAED,OAAO,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;AAC7B,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAE,CAAa,EAAE,OAAqB;IACvD,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAc;IAClC,EAAE,EAAE,UAAU;CACf,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,SAAS,CAAE,IAAI,EAAE,IAAI,UAWpC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAE,IAAI,EAAE,MAAM,QAwBzC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,SAAS,CAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAW7C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAwBhD"}
@@ -5,6 +5,6 @@ import type { Validators } from '@libp2p/interface-dht';
5
5
  * It runs the needed validators.
6
6
  * If verification fails the returned Promise will reject with the error.
7
7
  */
8
- export declare function verifyRecord(validators: Validators, record: Libp2pRecord): Promise<void> | undefined;
8
+ export declare function verifyRecord(validators: Validators, record: Libp2pRecord): Promise<void>;
9
9
  export declare const validators: Validators;
10
10
  //# sourceMappingURL=validators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,6BAmBzE;AAmCD,eAAO,MAAM,UAAU,EAAE,UAExB,CAAA"}
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIvD;;;;GAIG;AACH,wBAAsB,YAAY,CAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB/F;AAmCD,eAAO,MAAM,UAAU,EAAE,UAExB,CAAA"}
@@ -1,4 +1,4 @@
1
- import errCode from 'err-code';
1
+ import { CodeError } from '@libp2p/interfaces/errors';
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
3
3
  import { sha256 } from 'multiformats/hashes/sha2';
4
4
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
@@ -7,7 +7,7 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
7
7
  * It runs the needed validators.
8
8
  * If verification fails the returned Promise will reject with the error.
9
9
  */
10
- export function verifyRecord(validators, record) {
10
+ export async function verifyRecord(validators, record) {
11
11
  const key = record.key;
12
12
  const keyString = uint8ArrayToString(key);
13
13
  const parts = keyString.split('/');
@@ -18,9 +18,9 @@ export function verifyRecord(validators, record) {
18
18
  const validator = validators[parts[1].toString()];
19
19
  if (validator == null) {
20
20
  const errMsg = 'Invalid record keytype';
21
- throw errCode(new Error(errMsg), 'ERR_INVALID_RECORD_KEY_TYPE');
21
+ throw new CodeError(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE');
22
22
  }
23
- return validator(key, record.value);
23
+ await validator(key, record.value);
24
24
  }
25
25
  /**
26
26
  * Validator for public key records.
@@ -33,19 +33,19 @@ export function verifyRecord(validators, record) {
33
33
  */
34
34
  const validatePublicKeyRecord = async (key, publicKey) => {
35
35
  if (!(key instanceof Uint8Array)) {
36
- throw errCode(new Error('"key" must be a Uint8Array'), 'ERR_INVALID_RECORD_KEY_NOT_BUFFER');
36
+ throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER');
37
37
  }
38
38
  if (key.byteLength < 5) {
39
- throw errCode(new Error('invalid public key record'), 'ERR_INVALID_RECORD_KEY_TOO_SHORT');
39
+ throw new CodeError('invalid public key record', 'ERR_INVALID_RECORD_KEY_TOO_SHORT');
40
40
  }
41
41
  const prefix = uint8ArrayToString(key.subarray(0, 4));
42
42
  if (prefix !== '/pk/') {
43
- throw errCode(new Error('key was not prefixed with /pk/'), 'ERR_INVALID_RECORD_KEY_BAD_PREFIX');
43
+ throw new CodeError('key was not prefixed with /pk/', 'ERR_INVALID_RECORD_KEY_BAD_PREFIX');
44
44
  }
45
45
  const keyhash = key.slice(4);
46
46
  const publicKeyHash = await sha256.digest(publicKey);
47
47
  if (!uint8ArrayEquals(keyhash, publicKeyHash.bytes)) {
48
- throw errCode(new Error('public key does not match passed in key'), 'ERR_INVALID_RECORD_HASH_MISMATCH');
48
+ throw new CodeError('public key does not match passed in key', 'ERR_INVALID_RECORD_HASH_MISMATCH');
49
49
  }
50
50
  };
51
51
  export const validators = {
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAA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AuB;CAC5B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/record",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "libp2p record implementation",
5
5
  "author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -154,7 +154,7 @@
154
154
  "scripts": {
155
155
  "clean": "aegir clean",
156
156
  "lint": "aegir lint",
157
- "dep-check": "aegir dep-check",
157
+ "dep-check": "aegir dep-check -i protons",
158
158
  "test": "aegir test",
159
159
  "test:node": "aegir test -t node",
160
160
  "test:chrome": "aegir test -t browser",
@@ -168,15 +168,15 @@
168
168
  },
169
169
  "dependencies": {
170
170
  "@libp2p/interface-dht": "^2.0.0",
171
- "err-code": "^3.0.1",
171
+ "@libp2p/interfaces": "^3.2.0",
172
172
  "multiformats": "^11.0.0",
173
- "protons-runtime": "^4.0.1",
173
+ "protons-runtime": "^5.0.0",
174
174
  "uint8arraylist": "^2.1.1",
175
175
  "uint8arrays": "^4.0.2"
176
176
  },
177
177
  "devDependencies": {
178
178
  "@libp2p/crypto": "^1.0.11",
179
- "aegir": "^37.9.1",
180
- "protons": "^6.0.0"
179
+ "aegir": "^38.1.7",
180
+ "protons": "^7.0.2"
181
181
  }
182
182
  }
package/src/index.ts CHANGED
@@ -23,14 +23,14 @@ export class Libp2pRecord {
23
23
  this.timeReceived = timeReceived
24
24
  }
25
25
 
26
- serialize () {
26
+ serialize (): Uint8Array {
27
27
  return Record.encode(this.prepareSerialize())
28
28
  }
29
29
 
30
30
  /**
31
31
  * Return the object format ready to be given to the protobuf library.
32
32
  */
33
- prepareSerialize () {
33
+ prepareSerialize (): Record {
34
34
  return {
35
35
  key: this.key,
36
36
  value: this.value,
@@ -41,7 +41,7 @@ export class Libp2pRecord {
41
41
  /**
42
42
  * Decode a protobuf encoded record
43
43
  */
44
- static deserialize (raw: Uint8Array | Uint8ArrayList) {
44
+ static deserialize (raw: Uint8Array | Uint8ArrayList): Libp2pRecord {
45
45
  const rec = Record.decode(raw)
46
46
 
47
47
  return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived))
@@ -50,7 +50,7 @@ export class Libp2pRecord {
50
50
  /**
51
51
  * Create a record from the raw object returned from the protobuf library
52
52
  */
53
- static fromDeserialized (obj: Record) {
53
+ static fromDeserialized (obj: Record): Libp2pRecord {
54
54
  const recvtime = utils.parseRFC3339(obj.timeReceived)
55
55
 
56
56
  if (obj.key == null) {
package/src/record.ts CHANGED
@@ -2,10 +2,11 @@
2
2
  /* eslint-disable complexity */
3
3
  /* eslint-disable @typescript-eslint/no-namespace */
4
4
  /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
5
+ /* eslint-disable @typescript-eslint/no-empty-interface */
5
6
 
6
7
  import { encodeMessage, decodeMessage, message } from 'protons-runtime'
7
- import type { Uint8ArrayList } from 'uint8arraylist'
8
8
  import type { Codec } from 'protons-runtime'
9
+ import type { Uint8ArrayList } from 'uint8arraylist'
9
10
 
10
11
  export interface Record {
11
12
  key: Uint8Array
@@ -23,17 +24,17 @@ export namespace Record {
23
24
  w.fork()
24
25
  }
25
26
 
26
- if (opts.writeDefaults === true || (obj.key != null && obj.key.byteLength > 0)) {
27
+ if ((obj.key != null && obj.key.byteLength > 0)) {
27
28
  w.uint32(10)
28
29
  w.bytes(obj.key)
29
30
  }
30
31
 
31
- if (opts.writeDefaults === true || (obj.value != null && obj.value.byteLength > 0)) {
32
+ if ((obj.value != null && obj.value.byteLength > 0)) {
32
33
  w.uint32(18)
33
34
  w.bytes(obj.value)
34
35
  }
35
36
 
36
- if (opts.writeDefaults === true || obj.timeReceived !== '') {
37
+ if ((obj.timeReceived != null && obj.timeReceived !== '')) {
37
38
  w.uint32(42)
38
39
  w.string(obj.timeReceived)
39
40
  }
@@ -76,7 +77,7 @@ export namespace Record {
76
77
  return _codec
77
78
  }
78
79
 
79
- export const encode = (obj: Record): Uint8Array => {
80
+ export const encode = (obj: Partial<Record>): Uint8Array => {
80
81
  return encodeMessage(obj, Record.codec())
81
82
  }
82
83
 
package/src/selectors.ts CHANGED
@@ -1,15 +1,15 @@
1
- import errCode from 'err-code'
1
+ import { CodeError } from '@libp2p/interfaces/errors'
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
3
3
  import type { Selectors } from '@libp2p/interface-dht'
4
4
 
5
5
  /**
6
6
  * Select the best record out of the given records
7
7
  */
8
- export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]) {
8
+ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8Array[]): number {
9
9
  if (records.length === 0) {
10
10
  const errMsg = 'No records given'
11
11
 
12
- throw errCode(new Error(errMsg), 'ERR_NO_RECORDS_RECEIVED')
12
+ throw new CodeError(errMsg, 'ERR_NO_RECORDS_RECEIVED')
13
13
  }
14
14
 
15
15
  const kStr = uint8ArrayToString(k)
@@ -18,7 +18,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
18
18
  if (parts.length < 3) {
19
19
  const errMsg = 'Record key does not have a selector function'
20
20
 
21
- throw errCode(new Error(errMsg), 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY')
21
+ throw new CodeError(errMsg, 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY')
22
22
  }
23
23
 
24
24
  const selector = selectors[parts[1].toString()]
@@ -26,7 +26,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
26
26
  if (selector == null) {
27
27
  const errMsg = `Unrecognized key prefix: ${parts[1]}`
28
28
 
29
- throw errCode(new Error(errMsg), 'ERR_UNRECOGNIZED_KEY_PREFIX')
29
+ throw new CodeError(errMsg, 'ERR_UNRECOGNIZED_KEY_PREFIX')
30
30
  }
31
31
 
32
32
  if (records.length === 1) {
@@ -41,7 +41,7 @@ export function bestRecord (selectors: Selectors, k: Uint8Array, records: Uint8A
41
41
  * Simply returns the first record, as all valid public key
42
42
  * records are equal
43
43
  */
44
- function publickKey (k: Uint8Array, records: Uint8Array[]) {
44
+ function publickKey (k: Uint8Array, records: Uint8Array[]): number {
45
45
  return 0
46
46
  }
47
47
 
package/src/utils.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Convert a JavaScript date into an `RFC3339Nano` formatted
3
3
  * string
4
4
  */
5
- export function toRFC3339 (time: Date) {
5
+ export function toRFC3339 (time: Date): string {
6
6
  const year = time.getUTCFullYear()
7
7
  const month = String(time.getUTCMonth() + 1).padStart(2, '0')
8
8
  const day = String(time.getUTCDate()).padStart(2, '0')
@@ -19,7 +19,7 @@ export function toRFC3339 (time: Date) {
19
19
  * Parses a date string formatted as `RFC3339Nano` into a
20
20
  * JavaScript Date object
21
21
  */
22
- export function parseRFC3339 (time: string) {
22
+ export function parseRFC3339 (time: string): Date {
23
23
  const rfc3339Matcher = new RegExp(
24
24
  // 2006-01-02T
25
25
  '(\\d{4})-(\\d{2})-(\\d{2})T' +
package/src/validators.ts CHANGED
@@ -1,4 +1,4 @@
1
- import errCode from 'err-code'
1
+ import { CodeError } from '@libp2p/interfaces/errors'
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
3
3
  import type { Libp2pRecord } from './index.js'
4
4
  import type { Validators } from '@libp2p/interface-dht'
@@ -10,7 +10,7 @@ import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
10
10
  * It runs the needed validators.
11
11
  * If verification fails the returned Promise will reject with the error.
12
12
  */
13
- export function verifyRecord (validators: Validators, record: Libp2pRecord) {
13
+ export async function verifyRecord (validators: Validators, record: Libp2pRecord): Promise<void> {
14
14
  const key = record.key
15
15
  const keyString = uint8ArrayToString(key)
16
16
  const parts = keyString.split('/')
@@ -25,10 +25,10 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
25
25
  if (validator == null) {
26
26
  const errMsg = 'Invalid record keytype'
27
27
 
28
- throw errCode(new Error(errMsg), 'ERR_INVALID_RECORD_KEY_TYPE')
28
+ throw new CodeError(errMsg, 'ERR_INVALID_RECORD_KEY_TYPE')
29
29
  }
30
30
 
31
- return validator(key, record.value)
31
+ await validator(key, record.value)
32
32
  }
33
33
 
34
34
  /**
@@ -40,19 +40,19 @@ export function verifyRecord (validators: Validators, record: Libp2pRecord) {
40
40
  * @param {Uint8Array} key - A valid key is of the form `'/pk/<keymultihash>'`
41
41
  * @param {Uint8Array} publicKey - The public key to validate against (protobuf encoded).
42
42
  */
43
- const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array) => {
43
+ const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array): Promise<void> => {
44
44
  if (!(key instanceof Uint8Array)) {
45
- throw errCode(new Error('"key" must be a Uint8Array'), 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
45
+ throw new CodeError('"key" must be a Uint8Array', 'ERR_INVALID_RECORD_KEY_NOT_BUFFER')
46
46
  }
47
47
 
48
48
  if (key.byteLength < 5) {
49
- throw errCode(new Error('invalid public key record'), 'ERR_INVALID_RECORD_KEY_TOO_SHORT')
49
+ throw new CodeError('invalid public key record', 'ERR_INVALID_RECORD_KEY_TOO_SHORT')
50
50
  }
51
51
 
52
52
  const prefix = uint8ArrayToString(key.subarray(0, 4))
53
53
 
54
54
  if (prefix !== '/pk/') {
55
- throw errCode(new Error('key was not prefixed with /pk/'), 'ERR_INVALID_RECORD_KEY_BAD_PREFIX')
55
+ throw new CodeError('key was not prefixed with /pk/', 'ERR_INVALID_RECORD_KEY_BAD_PREFIX')
56
56
  }
57
57
 
58
58
  const keyhash = key.slice(4)
@@ -60,7 +60,7 @@ const validatePublicKeyRecord = async (key: Uint8Array, publicKey: Uint8Array) =
60
60
  const publicKeyHash = await sha256.digest(publicKey)
61
61
 
62
62
  if (!uint8ArrayEquals(keyhash, publicKeyHash.bytes)) {
63
- throw errCode(new Error('public key does not match passed in key'), 'ERR_INVALID_RECORD_HASH_MISMATCH')
63
+ throw new CodeError('public key does not match passed in key', 'ERR_INVALID_RECORD_HASH_MISMATCH')
64
64
  }
65
65
  }
66
66