Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick question about Ed25519 with the libp2p-host example #227

Closed
ssikdar1 opened this issue Sep 7, 2017 · 3 comments
Closed

Quick question about Ed25519 with the libp2p-host example #227

ssikdar1 opened this issue Sep 7, 2017 · 3 comments

Comments

@ssikdar1
Copy link
Contributor

ssikdar1 commented Sep 7, 2017

Looking at the example here: https://github.com/libp2p/go-libp2p/blob/master/examples/libp2p-host/host.go

// Generate an identity keypair using go's cryptographic randomness source
priv, pub, err := crypto.GenerateEd25519Key(rand.Reader)

and then later when creating the Peer ID:

// A peers ID is the hash of its public key
pid, err := peer.IDFromPublicKey(pub)

However in the go docs for go-libp2p-peer

There is also a function to create a peer corresponding to Ed25519:
https://godoc.org/github.com/libp2p/go-libp2p-peer#IDFromEd25519PublicKey

func IDFromEd25519PublicKey
func IDFromEd25519PublicKey(pk ic.PubKey) (ID, error)
IDFromEd25519PublicKey returns the Peer ID corresponding to Id25519 pk

Should the example use this function since its using crypto.GenerateEd25519Key to generate the public key?

Or do you you use IDFromEd25519PublicKey when you generate a priv, pub pair with a function different from crypto.GenerateEd25519Key(rand.Reader)?

Or does it not matter what you use?

@whyrusleeping
Copy link
Contributor

We're currently working on this distinction. The IDFromPublicKey puts the public key in a tagged struct, hashes it, and sets the peer ID to that hash. IDFrom Ed25519PublicKey embeds the public key in the peer ID, so that if you have the nodes peer ID, you have their public key as well. For now, I would recommend using IDFromPublicKey. IDFromEd25519PublicKey is experimental and not yet fully supported.

cc @JustinDrake

@avive
Copy link
Contributor

avive commented Dec 7, 2017

this was pretty confusing for me as well so thanks for the clarification.

@Stebalien
Copy link
Member

marten-seemann pushed a commit that referenced this issue Apr 21, 2022
feat: close transports that implement io.Closer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants