You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: support Peer ID represented as CID
This change adds two functions:
- createFromCID accepts CID as String|CID|Buffer
and creates PeerId from the multihash value inside of it
- toCIDString serializes PeerId multihash into a CIDv1 in Base32,
as agreed in libp2p/specs#209
License: MIT
Signed-off-by: Marcin Rataj <[email protected]>
* refactor: rename toCIDString to toString
CIDv1 is self describing, and toString was not defined.
Makes sense to use generic toString in this case.
This change also:
- remembers string with CID, so it is lazily generated only once
- switches createFromB58String to createFromCID (b58 is CIDv0),
making it easier to migrate existing codebases.
License: MIT
Signed-off-by: Marcin Rataj <[email protected]>
* docs: comment tests
License: MIT
Signed-off-by: Marcin Rataj <[email protected]>
* feat: validate CID multicodec
- require CID with 'libp2p-key' (CIDv1) or 'dag-pb' (CIDv0 converted to CIDv1)
- delegate CID validation to CID constructor
License: MIT
Signed-off-by: Marcin Rataj <[email protected]>
@@ -145,6 +147,14 @@ Creates a Peer ID from a buffer representing the key's multihash.
145
147
146
148
Returns `PeerId`.
147
149
150
+
### `createFromCID(cid)`
151
+
152
+
-`cid: CID|String|Buffer` - The multihash encoded as [CID](https://github.com/ipld/js-cid) (object, `String` or `Buffer`)
153
+
154
+
Creates a Peer ID from a CID representation of the key's multihash ([RFC 0001](https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md)).
155
+
156
+
Returns `PeerId`.
157
+
148
158
### `createFromB58String(str)`
149
159
150
160
Creates a Peer ID from a Base58 string representing the key's multihash.
@@ -197,9 +207,18 @@ Returns the Peer ID's `id` as a buffer.
197
207
<Buffer 12 20 d6 24 39 98 f2 fc 56 34 3a d7 ed 03 42 ab 78 86 a4 eb 18 d7 36 f1 b6 7d 44 b3 7f cc 81 e0 f3 9f>
198
208
```
199
209
210
+
211
+
### `toString()`
212
+
213
+
Returns the Peer ID's `id` as a self-describing CIDv1 in Base32 ([RFC 0001](https://github.com/libp2p/specs/blob/master/RFC/0001-text-peerid-cid.md))
0 commit comments