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

Improve docs around creating peerId from private key and improve support #82

Open
jacobheun opened this issue Jul 30, 2018 · 7 comments
Labels
exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked

Comments

@jacobheun
Copy link
Contributor

Doc Updates

The docs for createFromPrivKey currently reads:

createFromPrivKey(privKey)

  • privKey: Buffer
    Creates a Peer ID from a buffer containing a private key.

This is missleading as it requires a ProtoBuf.

We should clarify the documentation for this as users may try to use simple Buffer.

Improved Support

It would be nice if we improved the support for creating a peerid from a private key to accept a simple buffer. This could allow users to generate a keypair and use that privatekey to create their peerid. A use case of this might be an EC2 instance where the private key is stored in AWS KMS. It's possible to do this leveraging libp2p-crypto, but it would be nice if a factory method existed in peer-id to handle this for users.

@daviddias daviddias added kind/bug A bug in existing code (including security flaws) help wanted Seeking public contribution on this issue exp/novice Someone with a little familiarity can pick up status/ready Ready to be worked labels Aug 15, 2018
@daviddias
Copy link
Member

Treat documentation mistakes as bugs. That said, proposal sounds good :)

@iamsaquib8
Copy link

And Please can you provide examples to start with in the docs, its tough to find out the starting point for many of the methods defined in the library. Thanks

@vogdb
Copy link

vogdb commented Feb 14, 2022

Hi! Is this still actual?

cc @vasco-santos

@wemeetagain
Copy link
Member

wemeetagain commented Feb 14, 2022

Yes, createFromPrivKey still expects a protobuf

eg:

import { keys } from "libp2p-crypto"

const privateKey = await keys.generateKeypair('secp256k1')

// this doesn't work
const peerId = await createFromPrivKey(privateKey.marshal())

// this works
const peerId = await createFromPrivKey(privateKey.bytes)

@vogdb
Copy link

vogdb commented Feb 15, 2022

@wemeetagain can you please elaborate on your example? I see that everything works in the tests https://github.com/libp2p/js-peer-id/blob/master/test/peer-id.spec.js#L214. From what I see the API has changed:

const privKey = await crypto.keys.generateKeyPair('secp256k1', 256)
const id = await PeerId.createFromPrivKey(privKey.bytes)

@wemeetagain
Copy link
Member

Ah, sorry, there are a bunch of bugs in my example. (I just updated it)

privKey.bytes returns a protobuf-wrapped private key. https://github.com/libp2p/js-libp2p-crypto/blob/master/src/keys/secp256k1-class.ts#L66
whereas privKey.marshal() returns the raw private key https://github.com/libp2p/js-libp2p-crypto/blob/master/src/keys/secp256k1-class.ts#L62

@vogdb
Copy link

vogdb commented Feb 22, 2022

@wemeetagain As a beginner I can create a PR that updates documentation. Please look at the branch of my fork https://github.com/libp2p/js-peer-id/compare/master...vogdb:readme-privkey?expand=1. If it is ok then I will create it.

If you want to change API to accept createFromPrivKey(privateKey.marshal()) then it would be better to discuss such change with the project's maintainers first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exp/novice Someone with a little familiarity can pick up help wanted Seeking public contribution on this issue kind/bug A bug in existing code (including security flaws) status/ready Ready to be worked
Projects
None yet
Development

No branches or pull requests

5 participants