@libp2p/peer-id 1.1.17 → 1.1.18
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/README.md +17 -4
- package/dist/index.min.js +3 -0
- package/dist/typedoc-urls.json +8 -0
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
# @libp2p/peer-id <!-- omit in toc -->
|
|
2
2
|
|
|
3
3
|
[](http://libp2p.io/)
|
|
4
|
-
[](http://webchat.freenode.net/?channels=%23libp2p)
|
|
5
4
|
[](https://discuss.libp2p.io)
|
|
6
5
|
[](https://codecov.io/gh/libp2p/js-libp2p-peer-id)
|
|
7
|
-
[](https://github.com/libp2p/js-libp2p-peer-id/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
|
|
8
7
|
|
|
9
8
|
> Implementation of @libp2p/interface-peer-id
|
|
10
9
|
|
|
11
10
|
## Table of contents <!-- omit in toc -->
|
|
12
11
|
|
|
13
12
|
- [Install](#install)
|
|
13
|
+
- [Browser `<script>` tag](#browser-script-tag)
|
|
14
14
|
- [Description](#description)
|
|
15
15
|
- [Example](#example)
|
|
16
|
+
- [API Docs](#api-docs)
|
|
16
17
|
- [License](#license)
|
|
17
|
-
- [
|
|
18
|
+
- [Contribute](#contribute)
|
|
18
19
|
|
|
19
20
|
## Install
|
|
20
21
|
|
|
@@ -22,6 +23,14 @@
|
|
|
22
23
|
$ npm i @libp2p/peer-id
|
|
23
24
|
```
|
|
24
25
|
|
|
26
|
+
### Browser `<script>` tag
|
|
27
|
+
|
|
28
|
+
Loading this module through a script tag will make it's exports available as `Libp2pPeerId` in the global namespace.
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<script src="https://unpkg.com/@libp2p/peer-id/dist/index.min.js"></script>
|
|
32
|
+
```
|
|
33
|
+
|
|
25
34
|
## Description
|
|
26
35
|
|
|
27
36
|
A basic implementation of a peer id
|
|
@@ -36,6 +45,10 @@ const id = new PeerId(...)
|
|
|
36
45
|
console.log(id.toCid())
|
|
37
46
|
```
|
|
38
47
|
|
|
48
|
+
## API Docs
|
|
49
|
+
|
|
50
|
+
- <https://libp2p.github.io/js-libp2p-peer-id/modules/_libp2p_peer_id.html>
|
|
51
|
+
|
|
39
52
|
## License
|
|
40
53
|
|
|
41
54
|
Licensed under either of
|
|
@@ -43,6 +56,6 @@ Licensed under either of
|
|
|
43
56
|
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
44
57
|
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
45
58
|
|
|
46
|
-
##
|
|
59
|
+
## Contribute
|
|
47
60
|
|
|
48
61
|
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,0 +1,3 @@
|
|
|
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 Xe=Object.create;var H=Object.defineProperty;var Qe=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,Ze=Object.prototype.hasOwnProperty;var et=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),u=(t,e)=>{for(var r in e)H(t,r,{get:e[r],enumerable:!0})},ve=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of We(e))!Ze.call(t,o)&&o!==r&&H(t,o,{get:()=>e[o],enumerable:!(n=Qe(e,o))||n.enumerable});return t};var tt=(t,e,r)=>(r=t!=null?Xe(Ye(t)):{},ve(e||!t||!t.__esModule?H(r,"default",{value:t,enumerable:!0}):r,t)),rt=t=>ve(H({},"__esModule",{value:!0}),t);var je=et((Yr,Fe)=>{"use strict";function ke(t,e){for(let r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}function hr(t,e,r){if(!t||typeof t=="string")throw new TypeError("Please pass an Error to err-code");r||(r={}),typeof e=="object"&&(r=e,e=""),e&&(r.code=e);try{return ke(t,r)}catch{r.message=t.message,r.stack=t.stack;let o=function(){};return o.prototype=Object.create(Object.getPrototypeOf(t)),ke(new o,r)}}Fe.exports=hr});var lr={};u(lr,{createPeerId:()=>fr,peerIdFromBytes:()=>_e,peerIdFromCID:()=>Ge,peerIdFromKeys:()=>ur,peerIdFromPeerId:()=>pr,peerIdFromString:()=>Ke});var nt=Se,Ee=128,ot=127,st=~ot,it=Math.pow(2,31);function Se(t,e,r){e=e||[],r=r||0;for(var n=r;t>=it;)e[r++]=t&255|Ee,t/=128;for(;t&st;)e[r++]=t&255|Ee,t>>>=7;return e[r]=t|0,Se.bytes=r-n+1,e}var at=Q,ct=128,Ae=127;function Q(t,n){var r=0,n=n||0,o=0,s=n,i,h=t.length;do{if(s>=h)throw Q.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ae)<<o:(i&Ae)*Math.pow(2,o),o+=7}while(i>=ct);return Q.bytes=s-n,r}var ht=Math.pow(2,7),dt=Math.pow(2,14),ft=Math.pow(2,21),pt=Math.pow(2,28),ut=Math.pow(2,35),lt=Math.pow(2,42),mt=Math.pow(2,49),bt=Math.pow(2,56),wt=Math.pow(2,63),yt=function(t){return t<ht?1:t<dt?2:t<ft?3:t<pt?4:t<ut?5:t<lt?6:t<mt?7:t<bt?8:t<wt?9:10},gt={encode:nt,decode:at,encodingLength:yt},xt=gt,F=xt;var j=(t,e=0)=>[F.decode(t,e),F.decode.bytes],T=(t,e,r=0)=>(F.encode(t,e,r),e),M=t=>F.encodingLength(t);var yr=new Uint8Array(0);var Ce=(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},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")};var De=t=>new TextEncoder().encode(t),Ue=t=>new TextDecoder().decode(t);var E=(t,e)=>{let r=e.byteLength,n=M(t),o=n+M(r),s=new Uint8Array(o+r);return T(t,s,0),T(r,s,n),s.set(e,o),new N(t,r,e,s)},q=t=>{let e=S(t),[r,n]=j(e),[o,s]=j(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new N(r,o,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&&Ce(t.bytes,r.bytes)}},N=class{constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var te={};u(te,{base58btc:()=>l,base58flickr:()=>Dt});function vt(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 h=t.length,f=t.charAt(0),L=Math.log(h)/Math.log(256),m=Math.log(256)/Math.log(h);function O(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 p=0,z=0,w=0,g=a.length;w!==g&&a[w]===0;)w++,p++;for(var x=(g-w)*m+1>>>0,b=new Uint8Array(x);w!==g;){for(var v=a[w],C=0,y=x-1;(v!==0||C<z)&&y!==-1;y--,C++)v+=256*b[y]>>>0,b[y]=v%h>>>0,v=v/h>>>0;if(v!==0)throw new Error("Non-zero carry");z=C,w++}for(var A=x-z;A!==x&&b[A]===0;)A++;for(var G=f.repeat(p);A<x;++A)G+=t.charAt(b[A]);return G}function _(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var p=0;if(a[p]!==" "){for(var z=0,w=0;a[p]===f;)z++,p++;for(var g=(a.length-p)*L+1>>>0,x=new Uint8Array(g);a[p];){var b=r[a.charCodeAt(p)];if(b===255)return;for(var v=0,C=g-1;(b!==0||v<w)&&C!==-1;C--,v++)b+=h*x[C]>>>0,x[C]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");w=v,p++}if(a[p]!==" "){for(var y=g-w;y!==g&&x[y]===0;)y++;for(var A=new Uint8Array(z+(g-y)),G=z;y!==g;)A[G++]=x[y++];return A}}}function He(a){var p=_(a);if(p)return p;throw new Error(`Non-${e} character`)}return{encode:O,decodeUnsafe:_,decode:He}}var Et=vt,At=Et,ze=At;var W=class{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")}},Y=class{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 Le(this,e)}},Z=class{constructor(e){this.decoders=e}or(e){return Le(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.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 Z({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),ee=class{constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new W(e,r,n),this.decoder=new Y(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},R=({name:t,prefix:e,encode:r,decode:n})=>new ee(t,e,r,n),D=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:o}=ze(r,e);return R({prefix:t,name:e,encode:n,decode:s=>S(o(s))})},St=(t,e,r,n)=>{let o={};for(let m=0;m<e.length;++m)o[e[m]]=m;let s=t.length;for(;t[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),h=0,f=0,L=0;for(let m=0;m<s;++m){let O=o[t[m]];if(O===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|O,h+=r,h>=8&&(h-=8,i[L++]=255&f>>h)}if(h>=r||255&f<<8-h)throw new SyntaxError("Unexpected end of data");return i},Ct=(t,e,r)=>{let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,h=0;for(let f=0;f<t.length;++f)for(h=h<<8|t[f],i+=8;i>r;)i-=r,s+=e[o&h>>i];if(i&&(s+=e[o&h<<r-i]),n)for(;s.length*r&7;)s+="=";return s},d=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>R({prefix:e,name:t,encode(o){return Ct(o,n,r)},decode(o){return St(o,n,r,t)}});var l=D({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Dt=D({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var re={};u(re,{base32:()=>V,base32hex:()=>zt,base32hexpad:()=>Ot,base32hexpadupper:()=>Tt,base32hexupper:()=>Lt,base32pad:()=>It,base32padupper:()=>Pt,base32upper:()=>Ut,base32z:()=>Mt});var V=d({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ut=d({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),It=d({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pt=d({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zt=d({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Lt=d({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ot=d({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Tt=d({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mt=d({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Nt=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return Rt(r,ne(t),e||l.encoder);default:return Vt(r,ne(t),e||V.encoder)}},Oe=new WeakMap,ne=t=>{let e=Oe.get(t);if(e==null){let r=new Map;return Oe.set(t,r),r}return e},c=class{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!==$)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==kt)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,n=E(e,r);return c.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 c.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&Pe(e.multihash,n.multihash)}toString(e){return Nt(this,e)}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}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:n,code:o,multihash:s,bytes:i}=r;return new c(n,o,s,i||Te(n,o,s.bytes))}else if(r[Ft]===!0){let{version:n,multihash:o,code:s}=r,i=q(o);return c.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!==$)throw new Error(`Version 0 CID must use dag-pb (code: ${$}) block encoding`);return new c(e,r,n,n.bytes)}case 1:{let o=Te(e,r,n.bytes);return new c(e,r,n,o)}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,n]=c.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=c.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 N(r.multihashCode,r.digestSize,s,o);return[r.version===0?c.createV0(i):c.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[O,_]=j(e.subarray(r));return r+=_,O},o=n(),s=$;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,h=n(),f=n(),L=r+f,m=L-i;return{version:o,codec:s,multihashCode:h,digestSize:f,multihashSize:m,size:L}}static parse(e,r){let[n,o]=Bt(e,r),s=c.decode(o);return ne(s).set(n,e),s}},Bt=(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)]}}},Rt=(t,e,r)=>{let{prefix:n}=r;if(n!==l.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},Vt=(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},$=112,kt=18,Te=(t,e,r)=>{let n=M(t),o=n+M(e),s=new Uint8Array(o+r.byteLength);return T(t,s,0),T(e,s,n),s.set(r,o),s},Ft=Symbol.for("@ipld/js-cid/CID");var oe={};u(oe,{identity:()=>jt});var jt=R({prefix:"\0",name:"identity",encode:t=>Ue(t),decode:t=>De(t)});var se={};u(se,{base2:()=>qt});var qt=d({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ie={};u(ie,{base8:()=>$t});var $t=d({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ae={};u(ae,{base10:()=>Jt});var Jt=D({prefix:"9",name:"base10",alphabet:"0123456789"});var ce={};u(ce,{base16:()=>Kt,base16upper:()=>_t});var Kt=d({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_t=d({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var he={};u(he,{base36:()=>Gt,base36upper:()=>Ht});var Gt=D({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ht=D({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var de={};u(de,{base64:()=>Xt,base64pad:()=>Qt,base64url:()=>Wt,base64urlpad:()=>Yt});var Xt=d({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qt=d({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Wt=d({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yt=d({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var fe={};u(fe,{base256emoji:()=>nr});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}"),Zt=Me.reduce((t,e,r)=>(t[r]=e,t),[]),er=Me.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function tr(t){return t.reduce((e,r)=>(e+=Zt[r],e),"")}function rr(t){let e=[];for(let r of t){let n=er[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var nr=R({prefix:"\u{1F680}",name:"base256emoji",encode:tr,decode:rr});var le={};u(le,{sha256:()=>J,sha512:()=>or});var ue=({name:t,code:e,encode:r})=>new pe(t,e,r),pe=class{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")}};var Be=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),J=ue({name:"sha2-256",code:18,encode:Be("SHA-256")}),or=ue({name:"sha2-512",code:19,encode:Be("SHA-512")});var me={};u(me,{identity:()=>k});var Re=0,sr="identity",Ve=S,ir=t=>E(Re,Ve(t)),k={code:Re,name:sr,encode:Ve,digest:ir};var $r=new TextEncoder,Jr=new TextDecoder;var be={...oe,...se,...ie,...ae,...ce,...re,...he,...te,...de,...fe},Xr={...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 ye=tt(je(),1);var qe=Symbol.for("@libp2p/peer-id");var dr=Symbol.for("nodejs.util.inspect.custom"),$e=Object.values(be).map(t=>t.decoder).reduce((t,e)=>t.or(e),be.identity.decoder),Je=114,ge=36,xe=37,K=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[qe](){return!0}toString(){return this.string==null&&(this.string=l.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return c.createV1(Je,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 Ke(e).equals(this);if(e?.multihash?.bytes!=null)return we(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[dr](){return`PeerId(${this.toString()})`}},U=class extends K{constructor(e){super({...e,type:"RSA"}),this.type="RSA",this.publicKey=e.publicKey}},I=class extends K{constructor(e){super({...e,type:"Ed25519"}),this.type="Ed25519",this.publicKey=e.multihash.digest}},P=class extends K{constructor(e){super({...e,type:"secp256k1"}),this.type="secp256k1",this.publicKey=e.multihash.digest}};function fr(t){if(t.type==="RSA")return new U(t);if(t.type==="Ed25519")return new I(t);if(t.type==="secp256k1")return new P(t);throw(0,ye.default)(new Error('Type must be "RSA", "Ed25519" or "secp256k1"'),"ERR_INVALID_PARAMETERS")}function pr(t){if(t.type==="RSA")return new U(t);if(t.type==="Ed25519")return new I(t);if(t.type==="secp256k1")return new P(t);throw(0,ye.default)(new Error("Not a PeerId"),"ERR_INVALID_PARAMETERS")}function Ke(t,e){if(e=e??$e,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=q(l.decode(`z${t}`));return t.startsWith("12D")?new I({multihash:r}):t.startsWith("16U")?new P({multihash:r}):new U({multihash:r})}return _e($e.decode(t))}function _e(t){try{let e=q(t);if(e.code===k.code){if(e.digest.length===ge)return new I({multihash:e});if(e.digest.length===xe)return new P({multihash:e})}if(e.code===J.code)return new U({multihash:e})}catch{return Ge(c.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function Ge(t){if(t==null||t.multihash==null||t.version==null||t.version===1&&t.code!==Je)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===k.code){if(e.digest.length===ge)return new I({multihash:t.multihash});if(e.digest.length===xe)return new P({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function ur(t,e){return t.length===ge?new I({multihash:E(k.code,t),privateKey:e}):t.length===xe?new P({multihash:E(k.code,t),privateKey:e}):new U({multihash:await J.digest(t),publicKey:t,privateKey:e})}return rt(lr);})();
|
|
3
|
+
return Libp2PPeerId}));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"createPeerId": "https://libp2p.github.io/js-libp2p-peer-id/functions/_libp2p_peer_id.createPeerId.html",
|
|
3
|
+
"peerIdFromBytes": "https://libp2p.github.io/js-libp2p-peer-id/functions/_libp2p_peer_id.peerIdFromBytes.html",
|
|
4
|
+
"peerIdFromCID": "https://libp2p.github.io/js-libp2p-peer-id/functions/_libp2p_peer_id.peerIdFromCID.html",
|
|
5
|
+
"peerIdFromKeys": "https://libp2p.github.io/js-libp2p-peer-id/functions/_libp2p_peer_id.peerIdFromKeys.html",
|
|
6
|
+
"peerIdFromPeerId": "https://libp2p.github.io/js-libp2p-peer-id/functions/_libp2p_peer_id.peerIdFromPeerId.html",
|
|
7
|
+
"peerIdFromString": "https://libp2p.github.io/js-libp2p-peer-id/functions/_libp2p_peer_id.peerIdFromString.html"
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/peer-id",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "Implementation of @libp2p/interface-peer-
|
|
3
|
+
"version": "1.1.18",
|
|
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-peer-id/tree/master/packages/libp2p-peer-id#readme",
|
|
7
7
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"types": "./dist/src/index.d.ts",
|
|
23
23
|
"files": [
|
|
24
24
|
"src",
|
|
25
|
-
"dist
|
|
25
|
+
"dist",
|
|
26
26
|
"!dist/test",
|
|
27
27
|
"!**/*.tsbuildinfo"
|
|
28
28
|
],
|
|
@@ -144,6 +144,9 @@
|
|
|
144
144
|
"uint8arrays": "^4.0.2"
|
|
145
145
|
},
|
|
146
146
|
"devDependencies": {
|
|
147
|
-
"aegir": "^37.
|
|
147
|
+
"aegir": "^37.7.5"
|
|
148
|
+
},
|
|
149
|
+
"typedoc": {
|
|
150
|
+
"entryPoint": "./src/index.ts"
|
|
148
151
|
}
|
|
149
152
|
}
|