Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/peer-id

Package Overview
Dependencies
Maintainers
6
Versions
569
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/peer-id - npm Package Compare versions

Comparing version 4.2.2 to 4.2.3

2

dist/index.min.js
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerId = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PPeerId=(()=>{var W=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var u=(t,e)=>{for(var r in e)W(t,r,{get:e[r],enumerable:!0})},st=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of nt(e))!ot.call(t,o)&&o!==r&&W(t,o,{get:()=>e[o],enumerable:!(n=rt(e,o))||n.enumerable});return t};var it=t=>st(W({},"__esModule",{value:!0}),t);var br={};u(br,{createPeerId:()=>fr,peerIdFromBytes:()=>Ze,peerIdFromCID:()=>et,peerIdFromKeys:()=>mr,peerIdFromPeerId:()=>lr,peerIdFromString:()=>We});var Z=Symbol.for("@libp2p/peer-id");var $=class extends Error{code;props;constructor(e,r,n){super(e),this.code=r,this.name=n?.name??"CodeError",this.props=n??{}}};var oe={};u(oe,{base58btc:()=>f,base58flickr:()=>ut});var wr=new Uint8Array(0);function Ie(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 S(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 Re(t){return new TextEncoder().encode(t)}function Ue(t){return new TextDecoder().decode(t)}function at(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=t.length,p=t.charAt(0),O=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function P(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 h=0,T=0,b=0,y=a.length;b!==y&&a[b]===0;)b++,h++;for(var g=(y-b)*l+1>>>0,m=new Uint8Array(g);b!==y;){for(var w=a[b],A=0,x=g-1;(w!==0||A<T)&&x!==-1;x--,A++)w+=256*m[x]>>>0,m[x]=w%c>>>0,w=w/c>>>0;if(w!==0)throw new Error("Non-zero carry");T=A,b++}for(var v=g-T;v!==g&&m[v]===0;)v++;for(var X=p.repeat(h);v<g;++v)X+=t.charAt(m[v]);return X}function H(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var h=0;if(a[h]!==" "){for(var T=0,b=0;a[h]===p;)T++,h++;for(var y=(a.length-h)*O+1>>>0,g=new Uint8Array(y);a[h];){var m=r[a.charCodeAt(h)];if(m===255)return;for(var w=0,A=y-1;(m!==0||w<b)&&A!==-1;A--,w++)m+=c*g[A]>>>0,g[A]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");b=w,h++}if(a[h]!==" "){for(var x=y-b;x!==y&&g[x]===0;)x++;for(var v=new Uint8Array(T+(y-x)),X=T;x!==y;)v[X++]=g[x++];return v}}}function tt(a){var h=H(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:P,decodeUnsafe:H,decode:tt}}var ct=at,dt=ct,Ne=dt;var ee=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},te=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){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=n}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 Oe(this,e)}},re=class{decoders;constructor(e){this.decoders=e}or(e){return Oe(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Oe(t,e){return new re({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ne=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ee(e,r,n),this.decoder=new te(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function L({name:t,prefix:e,encode:r,decode:n}){return new ne(t,e,r,n)}function D({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ne(r,t);return L({prefix:e,name:t,encode:n,decode:s=>S(o(s))})}function pt(t,e,r,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),c=0,p=0,O=0;for(let l=0;l<s;++l){let P=o[t[l]];if(P===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<r|P,c+=r,c>=8&&(c-=8,i[O++]=255&p>>c)}if(c>=r||255&p<<8-c)throw new SyntaxError("Unexpected end of data");return i}function ht(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let p=0;p<t.length;++p)for(c=c<<8|t[p],i+=8;i>r;)i-=r,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<r-i]),n)for(;s.length*r&7;)s+="=";return s}function d({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return L({prefix:e,name:t,encode(o){return ht(o,n,r)},decode(o){return pt(o,n,r,t)}})}var f=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ut=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var se={};u(se,{base10:()=>ft});var ft=D({prefix:"9",name:"base10",alphabet:"0123456789"});var ie={};u(ie,{base16:()=>lt,base16upper:()=>mt});var lt=d({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mt=d({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ae={};u(ae,{base2:()=>bt});var bt=d({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ce={};u(ce,{base256emoji:()=>Et});var Pe=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}"),xt=Pe.reduce((t,e,r)=>(t[r]=e,t),[]),yt=Pe.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function gt(t){return t.reduce((e,r)=>(e+=xt[r],e),"")}function wt(t){let e=[];for(let r of t){let n=yt[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var Et=L({prefix:"\u{1F680}",name:"base256emoji",encode:gt,decode:wt});var de={};u(de,{base32:()=>M,base32hex:()=>Dt,base32hexpad:()=>It,base32hexpadupper:()=>Rt,base32hexupper:()=>Ct,base32pad:()=>St,base32padupper:()=>At,base32upper:()=>vt,base32z:()=>Ut});var M=d({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vt=d({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),St=d({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),At=d({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Dt=d({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ct=d({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),It=d({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rt=d({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ut=d({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pe={};u(pe,{base36:()=>Tt,base36upper:()=>Nt});var Tt=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nt=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var he={};u(he,{base64:()=>Ot,base64pad:()=>Pt,base64url:()=>Lt,base64urlpad:()=>Mt});var Ot=d({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Pt=d({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Lt=d({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mt=d({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ue={};u(ue,{base8:()=>zt});var zt=d({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var fe={};u(fe,{identity:()=>Bt});var Bt=L({prefix:"\0",name:"identity",encode:t=>Ue(t),decode:t=>Re(t)});var zr=new TextEncoder,Br=new TextDecoder;var me={};u(me,{identity:()=>N});var Ft=ze,Le=128,$t=127,kt=~$t,qt=Math.pow(2,31);function ze(t,e,r){e=e||[],r=r||0;for(var n=r;t>=qt;)e[r++]=t&255|Le,t/=128;for(;t&kt;)e[r++]=t&255|Le,t>>>=7;return e[r]=t|0,ze.bytes=r-n+1,e}var jt=le,Kt=128,Me=127;function le(t,n){var r=0,n=n||0,o=0,s=n,i,c=t.length;do{if(s>=c)throw le.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Me)<<o:(i&Me)*Math.pow(2,o),o+=7}while(i>=Kt);return le.bytes=s-n,r}var Jt=Math.pow(2,7),Gt=Math.pow(2,14),Ht=Math.pow(2,21),Xt=Math.pow(2,28),Yt=Math.pow(2,35),Qt=Math.pow(2,42),Wt=Math.pow(2,49),Zt=Math.pow(2,56),er=Math.pow(2,63),tr=function(t){return t<Jt?1:t<Gt?2:t<Ht?3:t<Xt?4:t<Yt?5:t<Qt?6:t<Wt?7:t<Zt?8:t<er?9:10},rr={encode:Ft,decode:jt,encodingLength:tr},nr=rr,k=nr;function q(t,e=0){return[k.decode(t,e),k.decode.bytes]}function z(t,e,r=0){return k.encode(t,e,r),e}function B(t){return k.encodingLength(t)}function E(t,e){let r=e.byteLength,n=B(t),o=n+B(r),s=new Uint8Array(o+r);return z(t,s,0),z(r,s,n),s.set(e,o),new V(t,r,e,s)}function j(t){let e=S(t),[r,n]=q(e),[o,s]=q(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new V(r,o,i,e)}function Be(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ie(t.bytes,r.bytes)}}var V=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Ve=0,or="identity",_e=S;function sr(t){return E(Ve,_e(t))}var N={code:Ve,name:or,encode:_e,digest:sr};var ye={};u(ye,{sha256:()=>K,sha512:()=>ir});function xe({name:t,code:e,encode:r}){return new be(t,e,r)}var be=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?E(this.code,r):r.then(n=>E(this.code,n))}else throw Error("Unknown type, must be binary type")}};function $e(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var K=xe({name:"sha2-256",code:18,encode:$e("SHA-256")}),ir=xe({name:"sha2-512",code:19,encode:$e("SHA-512")});function ke(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return cr(r,ge(t),e??f.encoder);default:return dr(r,ge(t),e??M.encoder)}}var qe=new WeakMap;function ge(t){let e=qe.get(t);if(e==null){let r=new Map;return qe.set(t,r),r}return e}var C=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==J)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==pr)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,n=E(e,r);return t.createV1(this.code,n)}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 n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Be(e.multihash,n.multihash)}toString(e){return ke(this,e)}toJSON(){return{"/":ke(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:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??je(n,o,s.bytes))}else if(r[hr]===!0){let{version:n,multihash:o,code:s}=r,i=j(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==J)throw new Error(`Version 0 CID must use dag-pb (code: ${J}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=je(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,J,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=S(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new V(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[P,H]=q(e.subarray(r));return r+=H,P},o=n(),s=J;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),p=n(),O=r+p,l=O-i;return{version:o,codec:s,multihashCode:c,digestSize:p,multihashSize:l,size:O}}static parse(e,r){let[n,o]=ar(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ge(s).set(n,e),s}};function ar(t,e){switch(t[0]){case"Q":{let r=e??f;return[f.prefix,r.decode(`${f.prefix}${t}`)]}case f.prefix:{let r=e??f;return[f.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 cr(t,e,r){let{prefix:n}=r;if(n!==f.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function dr(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var J=112,pr=18;function je(t,e,r){let n=B(t),o=n+B(e),s=new Uint8Array(o+r.byteLength);return z(t,s,0),z(e,s,n),s.set(r,o),s}var hr=Symbol.for("@ipld/js-cid/CID");var F={...fe,...ae,...ue,...se,...ie,...de,...pe,...oe,...he,...ce},on={...ye,...me};function we(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 Ke(t=0){return new Uint8Array(t)}function Ge(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Je=Ge("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ee=Ge("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ke(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ur={utf8:Je,"utf-8":Je,hex:F.base16,latin1:Ee,ascii:Ee,binary:Ee,...F},Q=ur;function He(t,e="utf8"){let r=Q[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function ve(t,e="utf8"){let r=Q[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Ye=Symbol.for("nodejs.util.inspect.custom"),Xe=Object.values(F).map(t=>t.decoder).reduce((t,e)=>t.or(e),F.identity.decoder),Qe=114,De=36,Ce=37,G=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()})`}[Z]=!0;toString(){return this.string==null&&(this.string=f.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return C.createV1(Qe,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return we(this.multihash.bytes,e);if(typeof e=="string")return We(e).equals(this);if(e?.multihash?.bytes!=null)return we(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Ye](){return`PeerId(${this.toString()})`}},I=class extends G{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},R=class extends G{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},U=class extends G{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},Se=2336,Ae=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=N.digest(He(this.url))}[Ye](){return`PeerId(${this.url})`}[Z]=!0;toString(){return this.toCID().toString()}toCID(){return C.createV1(Se,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ve(e)),e.toString()===this.toString())}};function fr(t){if(t.type==="RSA")return new I(t);if(t.type==="Ed25519")return new R(t);if(t.type==="secp256k1")return new U(t);throw new $('Type must be "RSA", "Ed25519" or "secp256k1"',"ERR_INVALID_PARAMETERS")}function lr(t){if(t.type==="RSA")return new I(t);if(t.type==="Ed25519")return new R(t);if(t.type==="secp256k1")return new U(t);throw new $("Not a PeerId","ERR_INVALID_PARAMETERS")}function We(t,e){if(e=e??Xe,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=j(f.decode(`z${t}`));return t.startsWith("12D")?new R({multihash:r}):t.startsWith("16U")?new U({multihash:r}):new I({multihash:r})}return Ze(Xe.decode(t))}function Ze(t){try{let e=j(t);if(e.code===N.code){if(e.digest.length===De)return new R({multihash:e});if(e.digest.length===Ce)return new U({multihash:e})}if(e.code===K.code)return new I({multihash:e})}catch{return et(C.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function et(t){if(t==null||t.multihash==null||t.version==null||t.version===1&&t.code!==Qe&&t.code!==Se)throw new Error("Supplied PeerID CID is invalid");if(t.code===Se){let r=ve(t.multihash.digest);return new Ae(new URL(r))}let e=t.multihash;if(e.code===K.code)return new I({multihash:t.multihash});if(e.code===N.code){if(e.digest.length===De)return new R({multihash:t.multihash});if(e.digest.length===Ce)return new U({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function mr(t,e){return t.length===De?new R({multihash:E(N.code,t),privateKey:e}):t.length===Ce?new U({multihash:E(N.code,t),privateKey:e}):new I({multihash:await K.digest(t),publicKey:t,privateKey:e})}return it(br);})();
"use strict";var Libp2PPeerId=(()=>{var W=Object.defineProperty;var rt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var u=(t,e)=>{for(var r in e)W(t,r,{get:e[r],enumerable:!0})},st=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of nt(e))!ot.call(t,o)&&o!==r&&W(t,o,{get:()=>e[o],enumerable:!(n=rt(e,o))||n.enumerable});return t};var it=t=>st(W({},"__esModule",{value:!0}),t);var br={};u(br,{createPeerId:()=>fr,peerIdFromBytes:()=>Ze,peerIdFromCID:()=>et,peerIdFromKeys:()=>mr,peerIdFromPeerId:()=>lr,peerIdFromString:()=>We});var Z=Symbol.for("@libp2p/peer-id");var $=class extends Error{code;props;constructor(e,r,n){super(e),this.code=r,this.name=n?.name??"CodeError",this.props=n??{}}};var oe={};u(oe,{base58btc:()=>f,base58flickr:()=>ut});var wr=new Uint8Array(0);function Ie(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 S(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 Re(t){return new TextEncoder().encode(t)}function Ue(t){return new TextDecoder().decode(t)}function at(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=t.length,p=t.charAt(0),O=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function P(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 h=0,T=0,b=0,y=a.length;b!==y&&a[b]===0;)b++,h++;for(var g=(y-b)*l+1>>>0,m=new Uint8Array(g);b!==y;){for(var w=a[b],A=0,x=g-1;(w!==0||A<T)&&x!==-1;x--,A++)w+=256*m[x]>>>0,m[x]=w%c>>>0,w=w/c>>>0;if(w!==0)throw new Error("Non-zero carry");T=A,b++}for(var v=g-T;v!==g&&m[v]===0;)v++;for(var X=p.repeat(h);v<g;++v)X+=t.charAt(m[v]);return X}function H(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var h=0;if(a[h]!==" "){for(var T=0,b=0;a[h]===p;)T++,h++;for(var y=(a.length-h)*O+1>>>0,g=new Uint8Array(y);a[h];){var m=r[a.charCodeAt(h)];if(m===255)return;for(var w=0,A=y-1;(m!==0||w<b)&&A!==-1;A--,w++)m+=c*g[A]>>>0,g[A]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");b=w,h++}if(a[h]!==" "){for(var x=y-b;x!==y&&g[x]===0;)x++;for(var v=new Uint8Array(T+(y-x)),X=T;x!==y;)v[X++]=g[x++];return v}}}function tt(a){var h=H(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:P,decodeUnsafe:H,decode:tt}}var ct=at,dt=ct,Ne=dt;var ee=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},te=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){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=n}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 Oe(this,e)}},re=class{decoders;constructor(e){this.decoders=e}or(e){return Oe(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Oe(t,e){return new re({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var ne=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ee(e,r,n),this.decoder=new te(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function L({name:t,prefix:e,encode:r,decode:n}){return new ne(t,e,r,n)}function D({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ne(r,t);return L({prefix:e,name:t,encode:n,decode:s=>S(o(s))})}function pt(t,e,r,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),c=0,p=0,O=0;for(let l=0;l<s;++l){let P=o[t[l]];if(P===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<r|P,c+=r,c>=8&&(c-=8,i[O++]=255&p>>c)}if(c>=r||255&p<<8-c)throw new SyntaxError("Unexpected end of data");return i}function ht(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let p=0;p<t.length;++p)for(c=c<<8|t[p],i+=8;i>r;)i-=r,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<r-i]),n)for(;s.length*r&7;)s+="=";return s}function d({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return L({prefix:e,name:t,encode(o){return ht(o,n,r)},decode(o){return pt(o,n,r,t)}})}var f=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ut=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var se={};u(se,{base10:()=>ft});var ft=D({prefix:"9",name:"base10",alphabet:"0123456789"});var ie={};u(ie,{base16:()=>lt,base16upper:()=>mt});var lt=d({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mt=d({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ae={};u(ae,{base2:()=>bt});var bt=d({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ce={};u(ce,{base256emoji:()=>Et});var Pe=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}"),xt=Pe.reduce((t,e,r)=>(t[r]=e,t),[]),yt=Pe.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function gt(t){return t.reduce((e,r)=>(e+=xt[r],e),"")}function wt(t){let e=[];for(let r of t){let n=yt[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var Et=L({prefix:"\u{1F680}",name:"base256emoji",encode:gt,decode:wt});var de={};u(de,{base32:()=>M,base32hex:()=>Dt,base32hexpad:()=>It,base32hexpadupper:()=>Rt,base32hexupper:()=>Ct,base32pad:()=>St,base32padupper:()=>At,base32upper:()=>vt,base32z:()=>Ut});var M=d({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),vt=d({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),St=d({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),At=d({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Dt=d({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ct=d({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),It=d({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Rt=d({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ut=d({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var pe={};u(pe,{base36:()=>Tt,base36upper:()=>Nt});var Tt=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nt=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var he={};u(he,{base64:()=>Ot,base64pad:()=>Pt,base64url:()=>Lt,base64urlpad:()=>Mt});var Ot=d({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Pt=d({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Lt=d({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mt=d({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ue={};u(ue,{base8:()=>zt});var zt=d({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var fe={};u(fe,{identity:()=>Bt});var Bt=L({prefix:"\0",name:"identity",encode:t=>Ue(t),decode:t=>Re(t)});var zr=new TextEncoder,Br=new TextDecoder;var me={};u(me,{identity:()=>N});var Ft=ze,Le=128,$t=127,kt=~$t,qt=Math.pow(2,31);function ze(t,e,r){e=e||[],r=r||0;for(var n=r;t>=qt;)e[r++]=t&255|Le,t/=128;for(;t&kt;)e[r++]=t&255|Le,t>>>=7;return e[r]=t|0,ze.bytes=r-n+1,e}var jt=le,Kt=128,Me=127;function le(t,n){var r=0,n=n||0,o=0,s=n,i,c=t.length;do{if(s>=c)throw le.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Me)<<o:(i&Me)*Math.pow(2,o),o+=7}while(i>=Kt);return le.bytes=s-n,r}var Jt=Math.pow(2,7),Gt=Math.pow(2,14),Ht=Math.pow(2,21),Xt=Math.pow(2,28),Yt=Math.pow(2,35),Qt=Math.pow(2,42),Wt=Math.pow(2,49),Zt=Math.pow(2,56),er=Math.pow(2,63),tr=function(t){return t<Jt?1:t<Gt?2:t<Ht?3:t<Xt?4:t<Yt?5:t<Qt?6:t<Wt?7:t<Zt?8:t<er?9:10},rr={encode:Ft,decode:jt,encodingLength:tr},nr=rr,k=nr;function q(t,e=0){return[k.decode(t,e),k.decode.bytes]}function z(t,e,r=0){return k.encode(t,e,r),e}function B(t){return k.encodingLength(t)}function E(t,e){let r=e.byteLength,n=B(t),o=n+B(r),s=new Uint8Array(o+r);return z(t,s,0),z(r,s,n),s.set(e,o),new V(t,r,e,s)}function j(t){let e=S(t),[r,n]=q(e),[o,s]=q(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new V(r,o,i,e)}function Be(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ie(t.bytes,r.bytes)}}var V=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Ve=0,or="identity",_e=S;function sr(t){return E(Ve,_e(t))}var N={code:Ve,name:or,encode:_e,digest:sr};var ye={};u(ye,{sha256:()=>K,sha512:()=>ir});function xe({name:t,code:e,encode:r}){return new be(t,e,r)}var be=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?E(this.code,r):r.then(n=>E(this.code,n))}else throw Error("Unknown type, must be binary type")}};function $e(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var K=xe({name:"sha2-256",code:18,encode:$e("SHA-256")}),ir=xe({name:"sha2-512",code:19,encode:$e("SHA-512")});function ke(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return cr(r,ge(t),e??f.encoder);default:return dr(r,ge(t),e??M.encoder)}}var qe=new WeakMap;function ge(t){let e=qe.get(t);if(e==null){let r=new Map;return qe.set(t,r),r}return e}var C=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==J)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==pr)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,n=E(e,r);return t.createV1(this.code,n)}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 n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Be(e.multihash,n.multihash)}toString(e){return ke(this,e)}toJSON(){return{"/":ke(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:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??je(n,o,s.bytes))}else if(r[hr]===!0){let{version:n,multihash:o,code:s}=r,i=j(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==J)throw new Error(`Version 0 CID must use dag-pb (code: ${J}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=je(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,J,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=S(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new V(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[P,H]=q(e.subarray(r));return r+=H,P},o=n(),s=J;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),p=n(),O=r+p,l=O-i;return{version:o,codec:s,multihashCode:c,digestSize:p,multihashSize:l,size:O}}static parse(e,r){let[n,o]=ar(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ge(s).set(n,e),s}};function ar(t,e){switch(t[0]){case"Q":{let r=e??f;return[f.prefix,r.decode(`${f.prefix}${t}`)]}case f.prefix:{let r=e??f;return[f.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 cr(t,e,r){let{prefix:n}=r;if(n!==f.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function dr(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var J=112,pr=18;function je(t,e,r){let n=B(t),o=n+B(e),s=new Uint8Array(o+r.byteLength);return z(t,s,0),z(e,s,n),s.set(r,o),s}var hr=Symbol.for("@ipld/js-cid/CID");var F={...fe,...ae,...ue,...se,...ie,...de,...pe,...oe,...he,...ce},on={...ye,...me};function we(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 Ke(t=0){return new Uint8Array(t)}function Ge(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Je=Ge("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ee=Ge("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ke(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ur={utf8:Je,"utf-8":Je,hex:F.base16,latin1:Ee,ascii:Ee,binary:Ee,...F},Q=ur;function He(t,e="utf8"){let r=Q[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function ve(t,e="utf8"){let r=Q[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Ye=Symbol.for("nodejs.util.inspect.custom"),Xe=Object.values(F).map(t=>t.decoder).reduce((t,e)=>t.or(e),F.identity.decoder),Qe=114,De=36,Ce=37,G=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()})`}[Z]=!0;toString(){return this.string==null&&(this.string=f.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return C.createV1(Qe,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return we(this.multihash.bytes,e);if(typeof e=="string")return We(e).equals(this);if(e?.multihash?.bytes!=null)return we(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[Ye](){return`PeerId(${this.toString()})`}},I=class extends G{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},R=class extends G{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},U=class extends G{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}},Se=2336,Ae=class{type="url";multihash;privateKey;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=N.digest(He(this.url))}[Ye](){return`PeerId(${this.url})`}[Z]=!0;toString(){return this.toCID().toString()}toCID(){return C.createV1(Se,this.multihash)}toBytes(){return this.toCID().bytes}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ve(e)),e.toString()===this.toString())}};function fr(t){if(t.type==="RSA")return new I(t);if(t.type==="Ed25519")return new R(t);if(t.type==="secp256k1")return new U(t);throw new $('Type must be "RSA", "Ed25519" or "secp256k1"',"ERR_INVALID_PARAMETERS")}function lr(t){if(t.type==="RSA")return new I(t);if(t.type==="Ed25519")return new R(t);if(t.type==="secp256k1")return new U(t);throw new $("Not a PeerId","ERR_INVALID_PARAMETERS")}function We(t,e){if(e=e??Xe,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=j(f.decode(`z${t}`));return t.startsWith("12D")?new R({multihash:r}):t.startsWith("16U")?new U({multihash:r}):new I({multihash:r})}return Ze(Xe.decode(t))}function Ze(t){try{let e=j(t);if(e.code===N.code){if(e.digest.length===De)return new R({multihash:e});if(e.digest.length===Ce)return new U({multihash:e})}if(e.code===K.code)return new I({multihash:e})}catch{return et(C.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function et(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Qe&&t.code!==Se)throw new Error("Supplied PeerID CID is invalid");if(t.code===Se){let r=ve(t.multihash.digest);return new Ae(new URL(r))}let e=t.multihash;if(e.code===K.code)return new I({multihash:t.multihash});if(e.code===N.code){if(e.digest.length===De)return new R({multihash:t.multihash});if(e.digest.length===Ce)return new U({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function mr(t,e){return t.length===De?new R({multihash:E(N.code,t),privateKey:e}):t.length===Ce?new U({multihash:E(N.code,t),privateKey:e}):new I({multihash:await K.digest(t),publicKey:t,privateKey:e})}return it(br);})();
return Libp2PPeerId}));

@@ -235,3 +235,3 @@ /**

export function peerIdFromCID(cid) {
if (cid == null || cid.multihash == null || cid.version == null || (cid.version === 1 && (cid.code !== LIBP2P_KEY_CODE) && cid.code !== TRANSPORT_IPFS_GATEWAY_HTTP_CODE)) {
if (cid?.multihash == null || cid.version == null || (cid.version === 1 && (cid.code !== LIBP2P_KEY_CODE) && cid.code !== TRANSPORT_IPFS_GATEWAY_HTTP_CODE)) {
throw new Error('Supplied PeerID CID is invalid');

@@ -238,0 +238,0 @@ }

{
"name": "@libp2p/peer-id",
"version": "4.2.2",
"version": "4.2.3",
"description": "Implementation of @libp2p/interface-peer-id",

@@ -57,3 +57,3 @@ "license": "Apache-2.0 OR MIT",

"dependencies": {
"@libp2p/interface": "^1.6.2",
"@libp2p/interface": "^1.6.3",
"multiformats": "^13.1.0",

@@ -63,5 +63,5 @@ "uint8arrays": "^5.1.0"

"devDependencies": {
"aegir": "^43.0.1"
"aegir": "^44.0.1"
},
"sideEffects": false
}

@@ -307,3 +307,3 @@ /**

export function peerIdFromCID (cid: CID): Ed25519PeerId | Secp256k1PeerId | RSAPeerId | URLPeerId {
if (cid == null || cid.multihash == null || cid.version == null || (cid.version === 1 && (cid.code !== LIBP2P_KEY_CODE) && cid.code !== TRANSPORT_IPFS_GATEWAY_HTTP_CODE)) {
if (cid?.multihash == null || cid.version == null || (cid.version === 1 && (cid.code !== LIBP2P_KEY_CODE) && cid.code !== TRANSPORT_IPFS_GATEWAY_HTTP_CODE)) {
throw new Error('Supplied PeerID CID is invalid')

@@ -310,0 +310,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc