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
fix!: remove private key field from peer id (#2660)
The only time you should ever see a private key on a `PeerId` is for the id of the currently running node. An exception to this is the keychain which used `PeerId`s to export private keys, but a nicer API there is to just deal with `PrivateKey` instances directly.
At runtime a service can obtain the unmarshaled private key by adding a `privateKey: PrivateKey` field to it's components map so there's no need to have the field on every `PeerId`.
The `publicKey` field of a `PeerId` was a `Uint8Array` which (if present) held the public key bytes in a protobuf wrapper along with a field saying what type of key it was. This was because we wanted to avoid pulling `@libp2p/crypto` into front ends, since it had a dependency on `node-forge` which was a large blob of untreeshakable CSJ code. This dependency has been removed so `@libp2p/crypto` is now comparatively lightweight so we can use the `PublicKey` type instead of `Uint8Array`, which also saves CPU time since we don't need to unmarshal the key before we can use it.
Fixes#2659
BREAKING CHANGE:
- The `.privateKey` field of the `PeerId` interface has been removed
- The `.publicKey` field of the `PeerId` interface is now a `PublicKey` instead of a `Uint8Array`
- `createLibp2p` now accepts a `privateKey` instead of a `peerId`
- The keychain operates on `PrivateKey` instances instead of `PeerId`s with `.privateKey` fields
- `@libp2p/peer-id-factory` has been removed, use `generateKeyPair` and `peerIdFromPrivateKey` instead
0 commit comments