Skip to content

Commit 717731e

Browse files
2colorachingbrain
andauthored
docs: add peerIdFromString to migration guide (#2781)
Add breaking change in peerIdFromString to migration guide from 1 -> 2 Related #2772 --------- Co-authored-by: Daniel N <[email protected]> Co-authored-by: Alex Potsides <[email protected]>
1 parent b801ff8 commit 717731e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

doc/migrations/v1.0.0-v2.0.0.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ A migration guide for refactoring your application code from libp2p `v1.0.0` to
1111
- [The `createLibp2p` function accepts a `PrivateKey` instead of a `PeerId`](#the-createlibp2p-function-accepts-a-privatekey-instead-of-a-peerid)
1212
- [The `@libp2p/keychain` module operates on `PrivateKey`s instead of `PeerId`s](#the-libp2pkeychain-module-operates-on-privatekeys-instead-of-peerids)
1313
- [The `@libp2p/peer-id-factory` module has been removed](#the-libp2ppeer-id-factory-module-has-been-removed)
14+
- [`peerIdFromString` no longer accepts CID encoded PeerIDs](#peeridfromstring-no-longer-accepts-cid-encoded-peerids)
1415
- [The autodialer has been removed](#the-autodialer-has-been-removed)
1516
- ["Transient" connections have been renamed "limited"](#transient-connections-have-been-renamed-limited)
1617
- [The CustomEvent polyfill has been removed from `@libp2p/interface`](#the-customevent-polyfill-has-been-removed-from-libp2pinterface)
@@ -251,6 +252,36 @@ const privateKey = await generateKeyPair('Ed25519')
251252
const peerId = peerIdFromPrivateKey(privateKey)
252253
```
253254

255+
## `peerIdFromString` no longer accepts CID encoded PeerIDs
256+
257+
The `peerIdFromString` function used to be quite flexible in that it would attempt
258+
to interpret multibase strings as either a multihash encoded PeerID or a CID.
259+
260+
As of `@libp2p/[email protected]` the method has been simplified to only accept
261+
multibase strings containing a multihash encoded PeerID.
262+
263+
To read a PeerId from a string containing a CID, first parse the CID from the
264+
string, then use the `peerIdFromCID` method.
265+
266+
**Before**
267+
268+
```ts
269+
import { peerIdFromString } from '@libp2p/peer-id'
270+
271+
const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s')
272+
```
273+
274+
**After**
275+
276+
```ts
277+
import { peerIdFromCID } from '@libp2p/peer-id'
278+
import { CID } from 'multiformats/cid'
279+
280+
// CID encoded PeerID in base36
281+
const cid = CID.parse('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s')
282+
const peer = peerIdFromCID(cid)
283+
```
284+
254285
## The autodialer has been removed
255286

256287
The libp2p autodialer was a component that attempted to ensure a minimum number

0 commit comments

Comments
 (0)