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
552
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 2.0.2 to 2.0.3-3dfc236e

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

@@ -0,6 +1,5 @@

import { type PeerIdType, type PeerId } from '@libp2p/interface-peer-id';
import { CID } from 'multiformats/cid';
import { PeerIdType } from '@libp2p/interface-peer-id';
import type { MultibaseDecoder } from 'multiformats/bases/interface';
import type { MultihashDigest } from 'multiformats/hashes/interface';
import type { PeerId } from '@libp2p/interface-peer-id';
interface PeerIdInit {

@@ -7,0 +6,0 @@ type: PeerIdType;

@@ -0,10 +1,10 @@

import { symbol } from '@libp2p/interface-peer-id';
import { CodeError } from '@libp2p/interfaces/errors';
import { base58btc } from 'multiformats/bases/base58';
import { bases } from 'multiformats/basics';
import { CID } from 'multiformats/cid';
import { bases } from 'multiformats/basics';
import { base58btc } from 'multiformats/bases/base58';
import * as Digest from 'multiformats/hashes/digest';
import { identity } from 'multiformats/hashes/identity';
import { sha256 } from 'multiformats/hashes/sha2';
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
import { sha256 } from 'multiformats/hashes/sha2';
import { CodeError } from '@libp2p/interfaces/errors';
import { symbol } from '@libp2p/interface-peer-id';
const inspect = Symbol.for('nodejs.util.inspect.custom');

@@ -21,2 +21,7 @@ const baseDecoder = Object

class PeerIdImpl {
type;
multihash;
privateKey;
publicKey;
string;
constructor(init) {

@@ -35,5 +40,3 @@ this.type = init.type;

}
get [symbol]() {
return true;
}
[symbol] = true;
toString() {

@@ -93,5 +96,6 @@ if (this.string == null) {

class RSAPeerIdImpl extends PeerIdImpl {
type = 'RSA';
publicKey;
constructor(init) {
super({ ...init, type: 'RSA' });
this.type = 'RSA';
this.publicKey = init.publicKey;

@@ -101,5 +105,6 @@ }

class Ed25519PeerIdImpl extends PeerIdImpl {
type = 'Ed25519';
publicKey;
constructor(init) {
super({ ...init, type: 'Ed25519' });
this.type = 'Ed25519';
this.publicKey = init.multihash.digest;

@@ -109,5 +114,6 @@ }

class Secp256k1PeerIdImpl extends PeerIdImpl {
type = 'secp256k1';
publicKey;
constructor(init) {
super({ ...init, type: 'secp256k1' });
this.type = 'secp256k1';
this.publicKey = init.multihash.digest;

@@ -114,0 +120,0 @@ }

{
"name": "@libp2p/peer-id",
"version": "2.0.2",
"version": "2.0.3-3dfc236e",
"description": "Implementation of @libp2p/interface-peer-id",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/libp2p/js-libp2p-peer-id/tree/master/packages/libp2p-peer-id#readme",
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/peer-id#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-peer-id.git"
"url": "git+https://github.com/libp2p/js-libp2p.git"
},
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-peer-id/issues"
"url": "https://github.com/libp2p/js-libp2p/issues"
},

@@ -17,6 +17,2 @@ "keywords": [

],
"engines": {
"node": ">=16.0.0",
"npm": ">=7.0.0"
},
"type": "module",

@@ -42,87 +38,2 @@ "types": "./dist/src/index.d.ts",

},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
]
},
"scripts": {

@@ -139,13 +50,12 @@ "clean": "aegir clean",

"test:node": "aegir test -t node --cov",
"test:electron-main": "aegir test -t electron-main",
"release": "aegir release"
"test:electron-main": "aegir test -t electron-main"
},
"dependencies": {
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interfaces": "^3.2.0",
"multiformats": "^11.0.0",
"uint8arrays": "^4.0.2"
"@libp2p/interface-peer-id": "2.0.2-3dfc236e",
"@libp2p/interfaces": "3.3.2-3dfc236e",
"multiformats": "^11.0.2",
"uint8arrays": "^4.0.3"
},
"devDependencies": {
"aegir": "^38.1.0"
"aegir": "^39.0.10"
},

@@ -152,0 +62,0 @@ "typedoc": {

@@ -5,4 +5,4 @@ # @libp2p/peer-id <!-- omit in toc -->

[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-peer-id.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-peer-id)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-peer-id/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-peer-id/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amaster)

@@ -19,3 +19,3 @@ > Implementation of @libp2p/interface-peer-id

- [License](#license)
- [Contribute](#contribute)
- [Contribution](#contribution)

@@ -53,3 +53,3 @@ ## Install

- <https://libp2p.github.io/js-libp2p-peer-id/modules/_libp2p_peer_id.html>
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_peer_id.html>

@@ -63,4 +63,4 @@ ## License

## Contribute
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

@@ -0,13 +1,12 @@

import { type Ed25519PeerId, type PeerIdType, type RSAPeerId, type Secp256k1PeerId, symbol, type PeerId } from '@libp2p/interface-peer-id'
import { CodeError } from '@libp2p/interfaces/errors'
import { base58btc } from 'multiformats/bases/base58'
import { bases } from 'multiformats/basics'
import { CID } from 'multiformats/cid'
import { bases } from 'multiformats/basics'
import { base58btc } from 'multiformats/bases/base58'
import * as Digest from 'multiformats/hashes/digest'
import { identity } from 'multiformats/hashes/identity'
import { sha256 } from 'multiformats/hashes/sha2'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { sha256 } from 'multiformats/hashes/sha2'
import { CodeError } from '@libp2p/interfaces/errors'
import { Ed25519PeerId, PeerIdType, RSAPeerId, Secp256k1PeerId, symbol } from '@libp2p/interface-peer-id'
import type { MultibaseDecoder } from 'multiformats/bases/interface'
import type { MultihashDigest } from 'multiformats/hashes/interface'
import type { PeerId } from '@libp2p/interface-peer-id'

@@ -73,5 +72,3 @@ const inspect = Symbol.for('nodejs.util.inspect.custom')

get [symbol] (): boolean {
return true
}
readonly [symbol] = true

@@ -78,0 +75,0 @@ toString (): string {

Sorry, the diff of this file is not supported yet

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