Open jacobheun opened 6 years ago
Treat documentation mistakes as bugs. That said, proposal sounds good :)
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
Hi! Is this still actual?
cc @vasco-santos
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)
@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)
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
@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.
Doc Updates
The docs for
createFromPrivKey
currently reads: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.