@libp2p/peer-id 4.0.7 → 4.0.8-3ffecc5bf

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.Libp2PPeerId = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPeerId=(()=>{var Q=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Xe=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var r in e)Q(t,r,{get:e[r],enumerable:!0})},He=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ge(e))!Xe.call(t,n)&&n!==r&&Q(t,n,{get:()=>e[n],enumerable:!(o=Je(e,n))||o.enumerable});return t};var Qe=t=>He(Q({},"__esModule",{value:!0}),t);var ir={};f(ir,{createPeerId:()=>or,peerIdFromBytes:()=>je,peerIdFromCID:()=>$e,peerIdFromKeys:()=>sr,peerIdFromPeerId:()=>nr,peerIdFromString:()=>qe});var ve=Symbol.for("@libp2p/peer-id");var F=class extends Error{code;props;constructor(e,r,o){super(e),this.code=r,this.name=o?.name??"CodeError",this.props=o??{}}};var te={};f(te,{base58btc:()=>u,base58flickr:()=>rt});var hr=new Uint8Array(0);function Ee(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function A(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Ae(t){return new TextEncoder().encode(t)}function Se(t){return new TextDecoder().decode(t)}function Ye(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=n}var c=t.length,h=t.charAt(0),T=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function L(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var d=0,U=0,b=0,y=a.length;b!==y&&a[b]===0;)b++,d++;for(var w=(y-b)*l+1>>>0,m=new Uint8Array(w);b!==y;){for(var g=a[b],S=0,x=w-1;(g!==0||S<U)&&x!==-1;x--,S++)g+=256*m[x]>>>0,m[x]=g%c>>>0,g=g/c>>>0;if(g!==0)throw new Error("Non-zero carry");U=S,b++}for(var E=w-U;E!==w&&m[E]===0;)E++;for(var X=h.repeat(d);E<w;++E)X+=t.charAt(m[E]);return X}function G(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var d=0;if(a[d]!==" "){for(var U=0,b=0;a[d]===h;)U++,d++;for(var y=(a.length-d)*T+1>>>0,w=new Uint8Array(y);a[d];){var m=r[a.charCodeAt(d)];if(m===255)return;for(var g=0,S=y-1;(m!==0||g<b)&&S!==-1;S--,g++)m+=c*w[S]>>>0,w[S]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");b=g,d++}if(a[d]!==" "){for(var x=y-b;x!==y&&w[x]===0;)x++;for(var E=new Uint8Array(U+(y-x)),X=U;x!==y;)E[X++]=w[x++];return E}}}function Ke(a){var d=G(a);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:L,decodeUnsafe:G,decode:Ke}}var We=Ye,Ze=We,Ce=Ze;var Y=class{name;prefix;baseEncode;constructor(e,r,o){this.name=e,this.prefix=r,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},W=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,o){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=o}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ie(this,e)}},Z=class{decoders;constructor(e){this.decoders=e}or(e){return Ie(this,e)}decode(e){let r=e[0],o=this.decoders[r];if(o!=null)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ie(t,e){return new Z({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ee=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,o,n){this.name=e,this.prefix=r,this.baseEncode=o,this.baseDecode=n,this.encoder=new Y(e,r,o),this.decoder=new W(e,r,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function O({name:t,prefix:e,encode:r,decode:o}){return new ee(t,e,r,o)}function D({name:t,prefix:e,alphabet:r}){let{encode:o,decode:n}=Ce(r,t);return O({prefix:e,name:t,encode:o,decode:s=>A(n(s))})}function et(t,e,r,o){let n={};for(let l=0;l<e.length;++l)n[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),c=0,h=0,T=0;for(let l=0;l<s;++l){let L=n[t[l]];if(L===void 0)throw new SyntaxError(`Non-${o} character`);h=h<<r|L,c+=r,c>=8&&(c-=8,i[T++]=255&h>>c)}if(c>=r||255&h<<8-c)throw new SyntaxError("Unexpected end of data");return i}function tt(t,e,r){let o=e[e.length-1]==="=",n=(1<<r)-1,s="",i=0,c=0;for(let h=0;h<t.length;++h)for(c=c<<8|t[h],i+=8;i>r;)i-=r,s+=e[n&c>>i];if(i!==0&&(s+=e[n&c<<r-i]),o)for(;s.length*r&7;)s+="=";return s}function p({name:t,prefix:e,bitsPerChar:r,alphabet:o}){return O({prefix:e,name:t,encode(n){return tt(n,o,r)},decode(n){return et(n,o,r,t)}})}var u=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rt=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var re={};f(re,{base10:()=>ot});var ot=D({prefix:"9",name:"base10",alphabet:"0123456789"});var oe={};f(oe,{base16:()=>nt,base16upper:()=>st});var nt=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),st=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ne={};f(ne,{base2:()=>it});var it=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var se={};f(se,{base256emoji:()=>dt});var Re=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),at=Re.reduce((t,e,r)=>(t[r]=e,t),[]),ct=Re.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function pt(t){return t.reduce((e,r)=>(e+=at[r],e),"")}function ht(t){let e=[];for(let r of t){let o=ct[r.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var dt=O({prefix:"\u{1F680}",name:"base256emoji",encode:pt,decode:ht});var ie={};f(ie,{base32:()=>M,base32hex:()=>mt,base32hexpad:()=>xt,base32hexpadupper:()=>yt,base32hexupper:()=>bt,base32pad:()=>ut,base32padupper:()=>lt,base32upper:()=>ft,base32z:()=>wt});var M=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ft=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ut=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lt=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mt=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bt=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xt=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yt=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wt=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ae={};f(ae,{base36:()=>gt,base36upper:()=>vt});var gt=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vt=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ce={};f(ce,{base64:()=>Et,base64pad:()=>At,base64url:()=>St,base64urlpad:()=>Dt});var Et=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),At=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),St=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dt=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pe={};f(pe,{base8:()=>Ct});var Ct=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var he={};f(he,{identity:()=>It});var It=O({prefix:"\0",name:"identity",encode:t=>Se(t),decode:t=>Ae(t)});var Cr=new TextEncoder,Ir=new TextDecoder;var fe={};f(fe,{identity:()=>_});var Nt=Te,Ue=128,Tt=127,Lt=~Tt,Ot=Math.pow(2,31);function Te(t,e,r){e=e||[],r=r||0;for(var o=r;t>=Ot;)e[r++]=t&255|Ue,t/=128;for(;t&Lt;)e[r++]=t&255|Ue,t>>>=7;return e[r]=t|0,Te.bytes=r-o+1,e}var Mt=de,Pt=128,Ne=127;function de(t,o){var r=0,o=o||0,n=0,s=o,i,c=t.length;do{if(s>=c)throw de.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=n<28?(i&Ne)<<n:(i&Ne)*Math.pow(2,n),n+=7}while(i>=Pt);return de.bytes=s-o,r}var zt=Math.pow(2,7),Vt=Math.pow(2,14),Bt=Math.pow(2,21),_t=Math.pow(2,28),Ft=Math.pow(2,35),kt=Math.pow(2,42),qt=Math.pow(2,49),jt=Math.pow(2,56),$t=Math.pow(2,63),Kt=function(t){return t<zt?1:t<Vt?2:t<Bt?3:t<_t?4:t<Ft?5:t<kt?6:t<qt?7:t<jt?8:t<$t?9:10},Jt={encode:Nt,decode:Mt,encodingLength:Kt},Gt=Jt,k=Gt;function q(t,e=0){return[k.decode(t,e),k.decode.bytes]}function P(t,e,r=0){return k.encode(t,e,r),e}function z(t){return k.encodingLength(t)}function v(t,e){let r=e.byteLength,o=z(t),n=o+z(r),s=new Uint8Array(n+r);return P(t,s,0),P(r,s,o),s.set(e,n),new V(t,r,e,s)}function j(t){let e=A(t),[r,o]=q(e),[n,s]=q(e.subarray(o)),i=e.subarray(o+s);if(i.byteLength!==n)throw new Error("Incorrect length");return new V(r,n,i,e)}function Le(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ee(t.bytes,r.bytes)}}var V=class{code;size;digest;bytes;constructor(e,r,o,n){this.code=e,this.size=r,this.digest=o,this.bytes=n}};var Oe=0,Xt="identity",Me=A;function Ht(t){return v(Oe,Me(t))}var _={code:Oe,name:Xt,encode:Me,digest:Ht};var me={};f(me,{sha256:()=>$,sha512:()=>Qt});function le({name:t,code:e,encode:r}){return new ue(t,e,r)}var ue=class{name;code;encode;constructor(e,r,o){this.name=e,this.code=r,this.encode=o}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?v(this.code,r):r.then(o=>v(this.code,o))}else throw Error("Unknown type, must be binary type")}};function ze(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var $=le({name:"sha2-256",code:18,encode:ze("SHA-256")}),Qt=le({name:"sha2-512",code:19,encode:ze("SHA-512")});function Ve(t,e){let{bytes:r,version:o}=t;switch(o){case 0:return Wt(r,be(t),e??u.encoder);default:return Zt(r,be(t),e??M.encoder)}}var Be=new WeakMap;function be(t){let e=Be.get(t);if(e==null){let r=new Map;return Be.set(t,r),r}return e}var N=class t{code;version;multihash;bytes;"/";constructor(e,r,o,n){this.code=r,this.version=e,this.multihash=o,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==K)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==er)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,o=v(e,r);return t.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let o=r;return o!=null&&e.code===o.code&&e.version===o.version&&Le(e.multihash,o.multihash)}toString(e){return Ve(this,e)}toJSON(){return{"/":Ve(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:o,code:n,multihash:s,bytes:i}=r;return new t(o,n,s,i??_e(o,n,s.bytes))}else if(r[tr]===!0){let{version:o,multihash:n,code:s}=r,i=j(n);return t.create(o,s,i)}else return null}static create(e,r,o){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(o.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==K)throw new Error(`Version 0 CID must use dag-pb (code: ${K}) block encoding`);return new t(e,r,o,o.bytes)}case 1:{let n=_e(e,r,o.bytes);return new t(e,r,o,n)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,K,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,o]=t.decodeFirst(e);if(o.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),o=r.size-r.multihashSize,n=A(e.subarray(o,o+r.multihashSize));if(n.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=n.subarray(r.multihashSize-r.digestSize),i=new V(r.multihashCode,r.digestSize,s,n);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,o=()=>{let[L,G]=q(e.subarray(r));return r+=G,L},n=o(),s=K;if(n===18?(n=0,r=0):s=o(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let i=r,c=o(),h=o(),T=r+h,l=T-i;return{version:n,codec:s,multihashCode:c,digestSize:h,multihashSize:l,size:T}}static parse(e,r){let[o,n]=Yt(e,r),s=t.decode(n);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return be(s).set(o,e),s}};function Yt(t,e){switch(t[0]){case"Q":{let r=e??u;return[u.prefix,r.decode(`${u.prefix}${t}`)]}case u.prefix:{let r=e??u;return[u.prefix,r.decode(t)]}case M.prefix:{let r=e??M;return[M.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Wt(t,e,r){let{prefix:o}=r;if(o!==u.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let n=e.get(o);if(n==null){let s=r.encode(t).slice(1);return e.set(o,s),s}else return n}function Zt(t,e,r){let{prefix:o}=r,n=e.get(o);if(n==null){let s=r.encode(t);return e.set(o,s),s}else return n}var K=112,er=18;function _e(t,e,r){let o=z(t),n=o+z(e),s=new Uint8Array(n+r.byteLength);return P(t,s,0),P(e,s,o),s.set(r,n),s}var tr=Symbol.for("@ipld/js-cid/CID");var xe={...he,...ne,...pe,...re,...oe,...ie,...ae,...te,...ce,...se},Xr={...me,...fe};function ye(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var rr=Symbol.for("nodejs.util.inspect.custom"),Fe=Object.values(xe).map(t=>t.decoder).reduce((t,e)=>t.or(e),xe.identity.decoder),ke=114,we=36,ge=37,J=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ve]=!0;toString(){return this.string==null&&(this.string=u.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return N.createV1(ke,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ye(this.multihash.bytes,e);if(typeof e=="string")return qe(e).equals(this);if(e?.multihash?.bytes!=null)return ye(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[rr](){return`PeerId(${this.toString()})`}},C=class extends J{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},I=class extends J{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},R=class extends J{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function or(t){if(t.type==="RSA")return new C(t);if(t.type==="Ed25519")return new I(t);if(t.type==="secp256k1")return new R(t);throw new F('Type must be "RSA", "Ed25519" or "secp256k1"',"ERR_INVALID_PARAMETERS")}function nr(t){if(t.type==="RSA")return new C(t);if(t.type==="Ed25519")return new I(t);if(t.type==="secp256k1")return new R(t);throw new F("Not a PeerId","ERR_INVALID_PARAMETERS")}function qe(t,e){if(e=e??Fe,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=j(u.decode(`z${t}`));return t.startsWith("12D")?new I({multihash:r}):t.startsWith("16U")?new R({multihash:r}):new C({multihash:r})}return je(Fe.decode(t))}function je(t){try{let e=j(t);if(e.code===_.code){if(e.digest.length===we)return new I({multihash:e});if(e.digest.length===ge)return new R({multihash:e})}if(e.code===$.code)return new C({multihash:e})}catch{return $e(N.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function $e(t){if(t==null||t.multihash==null||t.version==null||t.version===1&&t.code!==ke)throw new Error("Supplied PeerID CID is invalid");let e=t.multihash;if(e.code===$.code)return new C({multihash:t.multihash});if(e.code===_.code){if(e.digest.length===we)return new I({multihash:t.multihash});if(e.digest.length===ge)return new R({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function sr(t,e){return t.length===we?new I({multihash:v(_.code,t),privateKey:e}):t.length===ge?new R({multihash:v(_.code,t),privateKey:e}):new C({multihash:await $.digest(t),publicKey:t,privateKey:e})}return Qe(ir);})();
2
+ "use strict";var Libp2PPeerId=(()=>{var Q=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var Xe=Object.prototype.hasOwnProperty;var f=(t,e)=>{for(var r in e)Q(t,r,{get:e[r],enumerable:!0})},He=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ge(e))!Xe.call(t,n)&&n!==r&&Q(t,n,{get:()=>e[n],enumerable:!(o=Je(e,n))||o.enumerable});return t};var Qe=t=>He(Q({},"__esModule",{value:!0}),t);var ir={};f(ir,{createPeerId:()=>or,peerIdFromBytes:()=>je,peerIdFromCID:()=>$e,peerIdFromKeys:()=>sr,peerIdFromPeerId:()=>nr,peerIdFromString:()=>qe});var Ee=Symbol.for("@libp2p/peer-id");var F=class extends Error{code;props;constructor(e,r,o){super(e),this.code=r,this.name=o?.name??"CodeError",this.props=o??{}}};var te={};f(te,{base58btc:()=>u,base58flickr:()=>rt});var hr=new Uint8Array(0);function ve(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function A(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Ae(t){return new TextEncoder().encode(t)}function Se(t){return new TextDecoder().decode(t)}function Ye(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=n}var c=t.length,h=t.charAt(0),T=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function L(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var d=0,U=0,b=0,y=a.length;b!==y&&a[b]===0;)b++,d++;for(var w=(y-b)*l+1>>>0,m=new Uint8Array(w);b!==y;){for(var g=a[b],S=0,x=w-1;(g!==0||S<U)&&x!==-1;x--,S++)g+=256*m[x]>>>0,m[x]=g%c>>>0,g=g/c>>>0;if(g!==0)throw new Error("Non-zero carry");U=S,b++}for(var v=w-U;v!==w&&m[v]===0;)v++;for(var X=h.repeat(d);v<w;++v)X+=t.charAt(m[v]);return X}function G(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var d=0;if(a[d]!==" "){for(var U=0,b=0;a[d]===h;)U++,d++;for(var y=(a.length-d)*T+1>>>0,w=new Uint8Array(y);a[d];){var m=r[a.charCodeAt(d)];if(m===255)return;for(var g=0,S=y-1;(m!==0||g<b)&&S!==-1;S--,g++)m+=c*w[S]>>>0,w[S]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");b=g,d++}if(a[d]!==" "){for(var x=y-b;x!==y&&w[x]===0;)x++;for(var v=new Uint8Array(U+(y-x)),X=U;x!==y;)v[X++]=w[x++];return v}}}function Ke(a){var d=G(a);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:L,decodeUnsafe:G,decode:Ke}}var We=Ye,Ze=We,Ce=Ze;var Y=class{name;prefix;baseEncode;constructor(e,r,o){this.name=e,this.prefix=r,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},W=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,o){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=o}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ie(this,e)}},Z=class{decoders;constructor(e){this.decoders=e}or(e){return Ie(this,e)}decode(e){let r=e[0],o=this.decoders[r];if(o!=null)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ie(t,e){return new Z({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ee=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,o,n){this.name=e,this.prefix=r,this.baseEncode=o,this.baseDecode=n,this.encoder=new Y(e,r,o),this.decoder=new W(e,r,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function O({name:t,prefix:e,encode:r,decode:o}){return new ee(t,e,r,o)}function D({name:t,prefix:e,alphabet:r}){let{encode:o,decode:n}=Ce(r,t);return O({prefix:e,name:t,encode:o,decode:s=>A(n(s))})}function et(t,e,r,o){let n={};for(let l=0;l<e.length;++l)n[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),c=0,h=0,T=0;for(let l=0;l<s;++l){let L=n[t[l]];if(L===void 0)throw new SyntaxError(`Non-${o} character`);h=h<<r|L,c+=r,c>=8&&(c-=8,i[T++]=255&h>>c)}if(c>=r||255&h<<8-c)throw new SyntaxError("Unexpected end of data");return i}function tt(t,e,r){let o=e[e.length-1]==="=",n=(1<<r)-1,s="",i=0,c=0;for(let h=0;h<t.length;++h)for(c=c<<8|t[h],i+=8;i>r;)i-=r,s+=e[n&c>>i];if(i!==0&&(s+=e[n&c<<r-i]),o)for(;s.length*r&7;)s+="=";return s}function p({name:t,prefix:e,bitsPerChar:r,alphabet:o}){return O({prefix:e,name:t,encode(n){return tt(n,o,r)},decode(n){return et(n,o,r,t)}})}var u=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rt=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var re={};f(re,{base10:()=>ot});var ot=D({prefix:"9",name:"base10",alphabet:"0123456789"});var oe={};f(oe,{base16:()=>nt,base16upper:()=>st});var nt=p({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),st=p({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ne={};f(ne,{base2:()=>it});var it=p({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var se={};f(se,{base256emoji:()=>dt});var Re=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),at=Re.reduce((t,e,r)=>(t[r]=e,t),[]),ct=Re.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function pt(t){return t.reduce((e,r)=>(e+=at[r],e),"")}function ht(t){let e=[];for(let r of t){let o=ct[r.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var dt=O({prefix:"\u{1F680}",name:"base256emoji",encode:pt,decode:ht});var ie={};f(ie,{base32:()=>P,base32hex:()=>mt,base32hexpad:()=>xt,base32hexpadupper:()=>yt,base32hexupper:()=>bt,base32pad:()=>ut,base32padupper:()=>lt,base32upper:()=>ft,base32z:()=>wt});var P=p({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ft=p({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ut=p({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lt=p({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mt=p({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bt=p({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xt=p({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yt=p({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wt=p({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ae={};f(ae,{base36:()=>gt,base36upper:()=>Et});var gt=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Et=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ce={};f(ce,{base64:()=>vt,base64pad:()=>At,base64url:()=>St,base64urlpad:()=>Dt});var vt=p({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),At=p({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),St=p({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dt=p({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var pe={};f(pe,{base8:()=>Ct});var Ct=p({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var he={};f(he,{identity:()=>It});var It=O({prefix:"\0",name:"identity",encode:t=>Se(t),decode:t=>Ae(t)});var Cr=new TextEncoder,Ir=new TextDecoder;var fe={};f(fe,{identity:()=>_});var Nt=Te,Ue=128,Tt=127,Lt=~Tt,Ot=Math.pow(2,31);function Te(t,e,r){e=e||[],r=r||0;for(var o=r;t>=Ot;)e[r++]=t&255|Ue,t/=128;for(;t&Lt;)e[r++]=t&255|Ue,t>>>=7;return e[r]=t|0,Te.bytes=r-o+1,e}var Pt=de,Mt=128,Ne=127;function de(t,o){var r=0,o=o||0,n=0,s=o,i,c=t.length;do{if(s>=c)throw de.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=n<28?(i&Ne)<<n:(i&Ne)*Math.pow(2,n),n+=7}while(i>=Mt);return de.bytes=s-o,r}var zt=Math.pow(2,7),Vt=Math.pow(2,14),Bt=Math.pow(2,21),_t=Math.pow(2,28),Ft=Math.pow(2,35),kt=Math.pow(2,42),qt=Math.pow(2,49),jt=Math.pow(2,56),$t=Math.pow(2,63),Kt=function(t){return t<zt?1:t<Vt?2:t<Bt?3:t<_t?4:t<Ft?5:t<kt?6:t<qt?7:t<jt?8:t<$t?9:10},Jt={encode:Nt,decode:Pt,encodingLength:Kt},Gt=Jt,k=Gt;function q(t,e=0){return[k.decode(t,e),k.decode.bytes]}function M(t,e,r=0){return k.encode(t,e,r),e}function z(t){return k.encodingLength(t)}function E(t,e){let r=e.byteLength,o=z(t),n=o+z(r),s=new Uint8Array(n+r);return M(t,s,0),M(r,s,o),s.set(e,n),new V(t,r,e,s)}function j(t){let e=A(t),[r,o]=q(e),[n,s]=q(e.subarray(o)),i=e.subarray(o+s);if(i.byteLength!==n)throw new Error("Incorrect length");return new V(r,n,i,e)}function Le(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ve(t.bytes,r.bytes)}}var V=class{code;size;digest;bytes;constructor(e,r,o,n){this.code=e,this.size=r,this.digest=o,this.bytes=n}};var Oe=0,Xt="identity",Pe=A;function Ht(t){return E(Oe,Pe(t))}var _={code:Oe,name:Xt,encode:Pe,digest:Ht};var me={};f(me,{sha256:()=>$,sha512:()=>Qt});function le({name:t,code:e,encode:r}){return new ue(t,e,r)}var ue=class{name;code;encode;constructor(e,r,o){this.name=e,this.code=r,this.encode=o}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?E(this.code,r):r.then(o=>E(this.code,o))}else throw Error("Unknown type, must be binary type")}};function ze(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var $=le({name:"sha2-256",code:18,encode:ze("SHA-256")}),Qt=le({name:"sha2-512",code:19,encode:ze("SHA-512")});function Ve(t,e){let{bytes:r,version:o}=t;switch(o){case 0:return Wt(r,be(t),e??u.encoder);default:return Zt(r,be(t),e??P.encoder)}}var Be=new WeakMap;function be(t){let e=Be.get(t);if(e==null){let r=new Map;return Be.set(t,r),r}return e}var N=class t{code;version;multihash;bytes;"/";constructor(e,r,o,n){this.code=r,this.version=e,this.multihash=o,this.bytes=n,this["/"]=n}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==K)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==er)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,o=E(e,r);return t.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let o=r;return o!=null&&e.code===o.code&&e.version===o.version&&Le(e.multihash,o.multihash)}toString(e){return Ve(this,e)}toJSON(){return{"/":Ve(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:o,code:n,multihash:s,bytes:i}=r;return new t(o,n,s,i??_e(o,n,s.bytes))}else if(r[tr]===!0){let{version:o,multihash:n,code:s}=r,i=j(n);return t.create(o,s,i)}else return null}static create(e,r,o){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(o.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==K)throw new Error(`Version 0 CID must use dag-pb (code: ${K}) block encoding`);return new t(e,r,o,o.bytes)}case 1:{let n=_e(e,r,o.bytes);return new t(e,r,o,n)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,K,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,o]=t.decodeFirst(e);if(o.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),o=r.size-r.multihashSize,n=A(e.subarray(o,o+r.multihashSize));if(n.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=n.subarray(r.multihashSize-r.digestSize),i=new V(r.multihashCode,r.digestSize,s,n);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,o=()=>{let[L,G]=q(e.subarray(r));return r+=G,L},n=o(),s=K;if(n===18?(n=0,r=0):s=o(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let i=r,c=o(),h=o(),T=r+h,l=T-i;return{version:n,codec:s,multihashCode:c,digestSize:h,multihashSize:l,size:T}}static parse(e,r){let[o,n]=Yt(e,r),s=t.decode(n);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return be(s).set(o,e),s}};function Yt(t,e){switch(t[0]){case"Q":{let r=e??u;return[u.prefix,r.decode(`${u.prefix}${t}`)]}case u.prefix:{let r=e??u;return[u.prefix,r.decode(t)]}case P.prefix:{let r=e??P;return[P.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Wt(t,e,r){let{prefix:o}=r;if(o!==u.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let n=e.get(o);if(n==null){let s=r.encode(t).slice(1);return e.set(o,s),s}else return n}function Zt(t,e,r){let{prefix:o}=r,n=e.get(o);if(n==null){let s=r.encode(t);return e.set(o,s),s}else return n}var K=112,er=18;function _e(t,e,r){let o=z(t),n=o+z(e),s=new Uint8Array(n+r.byteLength);return M(t,s,0),M(e,s,o),s.set(r,n),s}var tr=Symbol.for("@ipld/js-cid/CID");var xe={...he,...ne,...pe,...re,...oe,...ie,...ae,...te,...ce,...se},Xr={...me,...fe};function ye(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var rr=Symbol.for("nodejs.util.inspect.custom"),Fe=Object.values(xe).map(t=>t.decoder).reduce((t,e)=>t.or(e),xe.identity.decoder),ke=114,we=36,ge=37,J=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ee]=!0;toString(){return this.string==null&&(this.string=u.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return N.createV1(ke,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ye(this.multihash.bytes,e);if(typeof e=="string")return qe(e).equals(this);if(e?.multihash?.bytes!=null)return ye(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[rr](){return`PeerId(${this.toString()})`}},C=class extends J{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},I=class extends J{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},R=class extends J{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function or(t){if(t.type==="RSA")return new C(t);if(t.type==="Ed25519")return new I(t);if(t.type==="secp256k1")return new R(t);throw new F('Type must be "RSA", "Ed25519" or "secp256k1"',"ERR_INVALID_PARAMETERS")}function nr(t){if(t.type==="RSA")return new C(t);if(t.type==="Ed25519")return new I(t);if(t.type==="secp256k1")return new R(t);throw new F("Not a PeerId","ERR_INVALID_PARAMETERS")}function qe(t,e){if(e=e??Fe,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=j(u.decode(`z${t}`));return t.startsWith("12D")?new I({multihash:r}):t.startsWith("16U")?new R({multihash:r}):new C({multihash:r})}return je(Fe.decode(t))}function je(t){try{let e=j(t);if(e.code===_.code){if(e.digest.length===we)return new I({multihash:e});if(e.digest.length===ge)return new R({multihash:e})}if(e.code===$.code)return new C({multihash:e})}catch{return $e(N.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function $e(t){if(t==null||t.multihash==null||t.version==null||t.version===1&&t.code!==ke)throw new Error("Supplied PeerID CID is invalid");let e=t.multihash;if(e.code===$.code)return new C({multihash:t.multihash});if(e.code===_.code){if(e.digest.length===we)return new I({multihash:t.multihash});if(e.digest.length===ge)return new R({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function sr(t,e){return t.length===we?new I({multihash:E(_.code,t),privateKey:e}):t.length===ge?new R({multihash:E(_.code,t),privateKey:e}):new C({multihash:await $.digest(t),publicKey:t,privateKey:e})}return Qe(ir);})();
3
3
  return Libp2PPeerId}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/peer-id",
3
- "version": "4.0.7",
3
+ "version": "4.0.8-3ffecc5bf",
4
4
  "description": "Implementation of @libp2p/interface-peer-id",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/peer-id#readme",
@@ -54,12 +54,12 @@
54
54
  "test:electron-main": "aegir test -t electron-main"
55
55
  },
56
56
  "dependencies": {
57
- "@libp2p/interface": "^1.1.4",
57
+ "@libp2p/interface": "1.1.5-3ffecc5bf",
58
58
  "multiformats": "^13.1.0",
59
- "uint8arrays": "^5.0.2"
59
+ "uint8arrays": "^5.0.3"
60
60
  },
61
61
  "devDependencies": {
62
- "aegir": "^42.2.4"
62
+ "aegir": "^42.2.5"
63
63
  },
64
64
  "sideEffects": false
65
65
  }
@@ -1,14 +0,0 @@
1
- {
2
- "createPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.createPeerId.html",
3
- ".:createPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.createPeerId.html",
4
- "peerIdFromBytes": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromBytes.html",
5
- ".:peerIdFromBytes": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromBytes.html",
6
- "peerIdFromCID": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromCID.html",
7
- ".:peerIdFromCID": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromCID.html",
8
- "peerIdFromKeys": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromKeys.html",
9
- ".:peerIdFromKeys": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromKeys.html",
10
- "peerIdFromPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromPeerId.html",
11
- ".:peerIdFromPeerId": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromPeerId.html",
12
- "peerIdFromString": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromString.html",
13
- ".:peerIdFromString": "https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_id.peerIdFromString.html"
14
- }