js-peer-id icon indicating copy to clipboard operation
js-peer-id copied to clipboard

Does a peer id require the private key and the public key to be carried around?

Open CMCDragonkai opened this issue 7 years ago • 9 comments

In this implementation of peer, it appears the constructor allows undefined public key and private key, is this meant to be allowed, or is peer id only useful if both pub and priv keys are available?

CMCDragonkai avatar Jun 05 '17 10:06 CMCDragonkai

The go implementation appears to indicate that these keys are optional, and that if you want to access further functionality, you should pass them into the relevant functions.

CMCDragonkai avatar Jun 05 '17 10:06 CMCDragonkai

@CMCDragonkai The Public Key is derived from the Private Key. ~~These keys are not optional.~~ Only the private key is optional

daviddias avatar Jun 06 '17 13:06 daviddias

If they are not optional, how come the constructor of a peer doesn't enforce that both keys must be present for a correctly constructed peer object. https://github.com/libp2p/js-peer-id/blob/master/src/index.js#L13-L24

CMCDragonkai avatar Jun 06 '17 16:06 CMCDragonkai

PeerId is used as a general abstraction within libp2p and IPFS code, i.e. your peer id string representation that gets wrapped in the PeerId object for internal consumption - the keys are optional for that use case. In other words, internally libp2p and ipfs uses PeerId everywhere to represent a peer, even tho the keys might not be absent.

dryajov avatar Jun 06 '17 17:06 dryajov

Fixed my statement. Only the PrivateKey is optional.

daviddias avatar Jul 27 '17 06:07 daviddias

If only the private key is optional, then why is this allowed? https://github.com/libp2p/js-peer-id/blob/master/src/index.js#L151-L161 Creating a peer id from a buffer doesn't automatically derive the public key.

CMCDragonkai avatar Aug 18 '17 10:08 CMCDragonkai

I think it's allowed because sometimes when dialing a peer whose peer id is known (as it's encoded in the address) but the pubkey is not known it is useful to create a peer id object only to validate whether the ids match (like it is done in secio here)

mkg20001 avatar Feb 16 '18 14:02 mkg20001

@CMCDragonkai is it possible to get public key from B58 string?

MicrowaveDev avatar Aug 20 '19 23:08 MicrowaveDev

@Jonybang Generally it's not possible to get the public key from just the id, since the id is a hashed version of the publickey. Instead you can only verify whether a publicKey belongs to a peerid by hashing that public key.

mkg20001 avatar Aug 22 '19 01:08 mkg20001