Skip to content

Commit

Permalink
docs: add peerIdFromString to migration guide (#2781)
Browse files Browse the repository at this point in the history
Add breaking change in peerIdFromString to migration guide from 1 -> 2

Related #2772

---------

Co-authored-by: Daniel N <2color@users.noreply.github.com>
Co-authored-by: Alex Potsides <alex@achingbrain.net>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent b801ff8 commit 717731e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions doc/migrations/v1.0.0-v2.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ A migration guide for refactoring your application code from libp2p `v1.0.0` to
- [The `createLibp2p` function accepts a `PrivateKey` instead of a `PeerId`](#the-createlibp2p-function-accepts-a-privatekey-instead-of-a-peerid)
- [The `@libp2p/keychain` module operates on `PrivateKey`s instead of `PeerId`s](#the-libp2pkeychain-module-operates-on-privatekeys-instead-of-peerids)
- [The `@libp2p/peer-id-factory` module has been removed](#the-libp2ppeer-id-factory-module-has-been-removed)
- [`peerIdFromString` no longer accepts CID encoded PeerIDs](#peeridfromstring-no-longer-accepts-cid-encoded-peerids)
- [The autodialer has been removed](#the-autodialer-has-been-removed)
- ["Transient" connections have been renamed "limited"](#transient-connections-have-been-renamed-limited)
- [The CustomEvent polyfill has been removed from `@libp2p/interface`](#the-customevent-polyfill-has-been-removed-from-libp2pinterface)
Expand Down Expand Up @@ -251,6 +252,36 @@ const privateKey = await generateKeyPair('Ed25519')
const peerId = peerIdFromPrivateKey(privateKey)
```

## `peerIdFromString` no longer accepts CID encoded PeerIDs

The `peerIdFromString` function used to be quite flexible in that it would attempt
to interpret multibase strings as either a multihash encoded PeerID or a CID.

As of `@libp2p/peer-id@5.x.x` the method has been simplified to only accept
multibase strings containing a multihash encoded PeerID.

To read a PeerId from a string containing a CID, first parse the CID from the
string, then use the `peerIdFromCID` method.

**Before**

```ts
import { peerIdFromString } from '@libp2p/peer-id'

const peer = peerIdFromString('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s')
```

**After**

```ts
import { peerIdFromCID } from '@libp2p/peer-id'
import { CID } from 'multiformats/cid'

// CID encoded PeerID in base36
const cid = CID.parse('k51qzi5uqu5dkwkqm42v9j9kqcam2jiuvloi16g72i4i4amoo2m8u3ol3mqu6s')
const peer = peerIdFromCID(cid)
```

## The autodialer has been removed

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

0 comments on commit 717731e

Please sign in to comment.