Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

fix: peer-id privKey and pubKey can be undefined #126

Merged
merged 5 commits into from
Jan 2, 2022

Conversation

nazarhussain
Copy link
Contributor

In the PR #107 the PeerId interface was introduced. Later in the PR #111 that was refactored and some intentional changes introduced.

The privKey and pubKey both can be undefined depending on the data, more details can be found in the PR libp2p/js-peer-id#150.

The PeerId object can be created with the following scenarios:

  1. new in that case both keys are optional
  2. PeerId.create in that case if provided input is valid than both keys exists
  3. PeerId.createFromBytes, PeerId.createFromB58String, PeerId.createFromHexString, PeerId.createFromCID in these cases public key can be decoded but private key don't exists
  4. PeerId.createFromPubKey in that case public key exists but not private
  5. PeerId.createFromPrivKey in that case both keys exist
  6. PeerId.createFromJSON in that case both keys exist
  7. PeerId.createFromProtobuf in that case both keys exist

Considering all the above cases, both privKey and pubKey were initially set was set to have undefined values. Seems the change in refactoring PR #111 was made unintended.

@achingbrain
Copy link
Member

TLDR: please use the v2.x.x release for the time being, tagged latest on npm - PRs can target the release/v2.x.x branch.


Longer version:

The typescript version of libp2p-interfaces is trying to take the interface definitions in a new direction. For peer id, please see the changes in #117 - it makes peer ids essentially a place to store some Uint8Arrays which you can then use to do encryption rather than pulling in libp2p-crypto by default. This is to allow using peer id datatypes in lightweight clients like ipfs-http-client instead of having everything as opaque strings.

It's all a bit in flux and will be until libp2p/js-libp2p#1021 lands.

@nazarhussain nazarhussain changed the base branch from master to release/v2.x.x December 27, 2021 18:17
@nazarhussain nazarhussain changed the base branch from release/v2.x.x to master December 27, 2021 18:17
@nazarhussain nazarhussain changed the base branch from master to release/v2.x.x December 27, 2021 19:25
@nazarhussain
Copy link
Contributor Author

@achingbrain Please review.

@achingbrain achingbrain changed the base branch from release/v2.x.x to release/v4.x.x January 1, 2022 07:13
Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - thanks! Just a few changes needed in order for the tests to not cause unhanded promise rejections if they fail.

packages/compliance-tests/src/peer-id/index.js Outdated Show resolved Hide resolved
packages/compliance-tests/src/peer-id/index.js Outdated Show resolved Hide resolved
packages/compliance-tests/src/peer-id/index.js Outdated Show resolved Hide resolved
@achingbrain achingbrain changed the title Fix the some unintended changes to peer-id fix: peer-id privKey and pubKey can be undefined Jan 2, 2022
@achingbrain achingbrain merged commit e06658d into libp2p:release/v4.x.x Jan 2, 2022
achingbrain added a commit that referenced this pull request Jan 2, 2022
Also export CreateOptions and PeerIdJSON types

Co-authored-by: Alex Potsides <alex@achingbrain.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants