fix: code review and docs and go interop

This commit is contained in:
dignifiedquire
2016-05-24 14:03:31 +02:00
parent ab5504686a
commit 58f1933980
6 changed files with 98 additions and 70 deletions

View File

@ -29,8 +29,8 @@ var bs58 = require('bs58')
var id = PeerId.create({ bits: 32 }) var id = PeerId.create({ bits: 32 })
console.log('id ', id.toB58String()) console.log('id ', id.toB58String())
console.log('priv key ', bs58.encode(id.privKey)) console.log('priv key ', bs58.encode(id.privKey.bytes))
console.log('pub key ', bs58.encode(id.pubKey)) console.log('pub key ', bs58.encode(id.pubKey.bytes))
``` ```
``` ```
@ -51,7 +51,7 @@ pub key 2BeBZVKJ9RQs4i4LbGv4ReEeuBA5dck2Gje3wt67e44XuyyPq5jE
## Node.js ## Node.js
```JavaScript ```js
var PeerId = require('peer-id') var PeerId = require('peer-id')
``` ```
@ -62,7 +62,7 @@ transpiled version with the right shims added. This means that you can require
it and use with your favourite bundler without having to adjust asset management it and use with your favourite bundler without having to adjust asset management
process. process.
```JavaScript ```js
var PeerId = require('peer-id') var PeerId = require('peer-id')
``` ```
@ -85,50 +85,51 @@ const PeerId = require('peer-id')
## Create ## Create
### PeerId.create() ### `new PeerId(id[, privKey, pubKey])`
Generates a new Peer ID, complete with public/private keypair. A Peer ID has the - `id: Buffer` - The multihash of the publick key as `Buffer`
following properties: - `privKey: RsaPrivateKey` - The private key
- `pubKey: RsaPublicKey` - The public key
- `pubKey` - Buffer containing the public key bytes The key format is detailed in [libp2p-crypto](https://github.com/ipfs/js-libp2p-crypto).
- `privKey` - Buffer containing the private key bytes
- `id` - Buffer containing the multihash bytes ### `create([opts])`
Generates a new Peer ID, complete with public/private keypair.
- `opts: Object`: Default: `{bits: 2048}`
## Import ## Import
### PeerId.createFromHexString(str) ### `createFromHexString(str)`
Creates a Peer ID from hex string representing the key's multihash. Creates a Peer ID from hex string representing the key's multihash.
### PeerId.createFromBytes(buf) ### `createFromBytes(buf)`
Creates a Peer ID from a buffer representing the key's multihash. Creates a Peer ID from a buffer representing the key's multihash.
### PeerId.createFromB58String(str) ### `createFromB58String(str)`
Creates a Peer ID from a Base58 string representing the key's multihash. Creates a Peer ID from a Base58 string representing the key's multihash.
### PeerId.createFromPubKey(pubKey) ### `createFromPubKey(pubKey)`
Creates a Peer ID from a buffer containing a public key. Creates a Peer ID from a buffer containing a public key.
### PeerId.createFromPrivKey(privKey) ### `createFromPrivKey(privKey)`
Creates a Peer ID from a buffer containing a private key. Creates a Peer ID from a buffer containing a private key.
### `createFromJSON(obj)`
- `obj.id: String` - The multihash encoded in `base58`
- `obj.pubKey: String` - The public key in protobuf format, encoded in 'base64'
- `obj.privKey: String` - The private key in protobuf format, encoded in 'base 64'
## Export ## Export
### id.toPrint() ### `toHexString()`
Returns an object with the ID's properties in hex format:
```js
{
id: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi',
privKey: '080012a609308204a20201000282010100a608889914da08959d3a3db0734cee812c96...',
pubKey: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010...'
}
```
### id.toHexString()
Returns the Peer ID's `id` as a hex string. Returns the Peer ID's `id` as a hex string.
@ -136,16 +137,15 @@ Returns the Peer ID's `id` as a hex string.
1220d6243998f2fc56343ad7ed0342ab7886a4eb18d736f1b67d44b37fcc81e0f39f 1220d6243998f2fc56343ad7ed0342ab7886a4eb18d736f1b67d44b37fcc81e0f39f
``` ```
### id.toBytes() ### `toBytes()`
Returns the Peer ID's `id` as a buffer. Returns the Peer ID's `id` as a buffer.
``` ```
<Buffer 12 20 d6 24 39 98 f2 fc 56 34 3a d7 ed 03 42 ab 78 86 a4 eb 18 d7 36 f1 b6 7d 44 b3 7f cc 81 e0 f3 9f> <Buffer 12 20 d6 24 39 98 f2 fc 56 34 3a d7 ed 03 42 ab 78 86 a4 eb 18 d7 36 f1 b6 7d 44 b3 7f cc 81 e0 f3 9f>
``` ```
### id.toB58String() ### `toB58String()`
Returns the Peer ID's `id` as a base58 string. Returns the Peer ID's `id` as a base58 string.
@ -153,6 +153,20 @@ Returns the Peer ID's `id` as a base58 string.
QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi
``` ```
### `toJSON()`
Returns an `obj` of the form
- `obj.id: String` - The multihash encoded in `base58`
- `obj.pubKey: String` - The public key in protobuf format, encoded in 'base64'
- `obj.privKey: String` - The private key in protobuf format, encoded in 'base 64'
### `toPrint()`
Alias for `.toJSON()`.
# License # License
MIT MIT

View File

@ -32,9 +32,9 @@
}, },
"homepage": "https://github.com/diasdavid/js-peer-id", "homepage": "https://github.com/diasdavid/js-peer-id",
"devDependencies": { "devDependencies": {
"aegir": "^3.0.4", "aegir": "^3.0.5",
"chai": "^3.5.0", "chai": "^3.5.0",
"pre-commit": "^1.1.2" "pre-commit": "^1.1.3"
}, },
"dependencies": { "dependencies": {
"libp2p-crypto": "^0.5.0", "libp2p-crypto": "^0.5.0",

View File

@ -10,24 +10,21 @@ const assert = require('assert')
class PeerId { class PeerId {
constructor (id, privKey, pubKey) { constructor (id, privKey, pubKey) {
if (Buffer.isBuffer(id)) { assert(Buffer.isBuffer(id), 'invalid id provided')
this.id = id
} else {
throw new Error('invalid id provided')
}
if (pubKey) { if (pubKey) {
assert(this.id.equals(pubKey.hash()), 'inconsistent arguments') assert(id.equals(pubKey.hash()), 'inconsistent arguments')
} }
if (privKey) { if (privKey) {
assert(this.id.equals(privKey.public.hash()), 'inconsistent arguments') assert(id.equals(privKey.public.hash()), 'inconsistent arguments')
} }
if (privKey && pubKey) { if (privKey && pubKey) {
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments') assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
} }
this.id = id
this.privKey = privKey this.privKey = privKey
this._pubKey = pubKey this._pubKey = pubKey
} }
@ -42,12 +39,16 @@ class PeerId {
} }
} }
// Return the protobuf version of the public key,
// matching go ipfs formatting
marshalPubKey () { marshalPubKey () {
if (this.pubKey) { if (this.pubKey) {
return crypto.marshalPublicKey(this.pubKey) return crypto.marshalPublicKey(this.pubKey)
} }
} }
// Return the protobuf version of the private key,
// matching go ipfs formatting
marshalPrivKey () { marshalPrivKey () {
if (this.privKey) { if (this.privKey) {
return crypto.marshalPrivateKey(this.privKey) return crypto.marshalPrivateKey(this.privKey)
@ -56,18 +57,16 @@ class PeerId {
// pretty print // pretty print
toPrint () { toPrint () {
return { return this.toJSON()
id: mh.toB58String(this.id),
privKey: toHexOpt(this.marshalPrivKey()),
pubKey: toHexOpt(this.marshalPubKey())
}
} }
// return the jsonified version of the key, matching the formatting
// of go-ipfs for its config file
toJSON () { toJSON () {
return { return {
id: mh.toHexString(this.id), id: mh.toB58String(this.id),
privKey: toHexOpt(this.marshalPrivKey()), privKey: toB64Opt(this.marshalPrivKey()),
pubKey: toHexOpt(this.marshalPubKey()) pubKey: toB64Opt(this.marshalPubKey())
} }
} }
@ -136,18 +135,18 @@ exports.createFromJSON = function (obj) {
let pub let pub
if (obj.privKey) { if (obj.privKey) {
priv = crypto.unmarshalPrivateKey(new Buffer(obj.privKey, 'hex')) priv = crypto.unmarshalPrivateKey(new Buffer(obj.privKey, 'base64'))
} }
if (obj.pubKey) { if (obj.pubKey) {
pub = crypto.unmarshalPublicKey(new Buffer(obj.pubKey, 'hex')) pub = crypto.unmarshalPublicKey(new Buffer(obj.pubKey, 'base64'))
} }
return new PeerId(mh.fromHexString(obj.id), priv, pub) return new PeerId(mh.fromB58String(obj.id), priv, pub)
} }
function toHexOpt (val) { function toB64Opt (val) {
if (val) { if (val) {
return val.toString('hex') return val.toString('base64')
} }
} }

6
test/fixtures/go-private-key.js vendored Normal file
View File

@ -0,0 +1,6 @@
'use strict'
module.exports = {
id: 'QmRLoXS3E73psYaUsma1VSbboTa2J8Z9kso1tpiGLk9WQ4',
privKey: 'CAASpwkwggSjAgEAAoIBAQDWBEbO8kc6a5kEks09CKPQargY3p0DCmCczoCT52/RYFqxvH9dI+s+u4Z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xA7POEXLi4b5dIEjFZ0YIiVk21gEw5UiFoMl7d+ihcY2Xqbslrb507SdhZLAY6V3pITRQo06K2XIgQWlJiE4uATepAoGBALZ2vEiBnYZW5vfN4tKbUyhGq3B1pggNgbr8odyV4mIcDlk6OOGov0WeZ5ut0AyUesSLyFnaOIoc0ZuTP/8rxBwG1bMrO8FP39sx83pDX25P9PkQZixyALjGsp+pXOFeOhtAvo9azO5M4j638Bydtjc3neBX62dwOLtyx7tDYN0hAoGAVLmr3w7XMVHTfEuCSzKHyRrOaN2PAuSX31QAji1PwlwVKMylVrb8rRvBOpTicA/wXPX9Q5O/yjegqhqLT/LXAm9ziFzy5b9/9SzXPukKebXXbvc0FOmcsrcxtijlPyUzf9fKM1ShiwqqsgM9eNyZ9GWUJw2GFATCWW7pl7rtnWk='
}

7
test/fixtures/sample-id.js vendored Normal file
View File

@ -0,0 +1,7 @@
'use strict'
module.exports = {
id: '122019318b6e5e0cf93a2314bf01269a2cc23cd3dcd452d742cdb9379d8646f6e4a9',
privKey: 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZ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wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE='
}

View File

@ -3,20 +3,16 @@
const expect = require('chai').expect const expect = require('chai').expect
const crypto = require('libp2p-crypto') const crypto = require('libp2p-crypto')
const mh = require('multihashes')
const PeerId = require('../src') const PeerId = require('../src')
const testId = { const testId = require('./fixtures/sample-id')
id: '1220151ab1658d8294ab34b71d5582cfe20d06414212f440a69366f1bc31deb5c72d', const testIdHex = testId.id
privKey: 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302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h28+RJS6AQX6KHrK1o2uw==', const testIdBytes = mh.fromHexString(testId.id)
pubKey: 'CAASpgIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAE=' const testIdB58String = mh.toB58String(testIdBytes)
}
const testIdHex = '1220151ab1658d8294ab34b71d5582cfe20d06414212f440a69366f1bc31deb5c72d' const goId = require('./fixtures/go-private-key')
const testIdBytes = new Buffer('1220151ab1658d8294ab34b71d5582cfe20d06414212f440a69366f1bc31deb5c72d', 'hex')
const testIdB58String = 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A'
describe('PeerId', () => { describe('PeerId', () => {
it('create an id without \'new\'', () => { it('create an id without \'new\'', () => {
@ -71,14 +67,10 @@ describe('PeerId', () => {
it('Pretty printing', () => { it('Pretty printing', () => {
const id = PeerId.createFromPrivKey(testId.privKey) const id = PeerId.createFromPrivKey(testId.privKey)
const out = id.toPrint() const out = id.toPrint()
const expected = {
id: 'QmQ2zigjQikYnyYUSXZydNXrDRhBut2mubwJBaLXobMt3A', expect(out.id).to.equal(testIdB58String)
privKey: '080012a609308204a20201000282010100b648aa3f1cc1597819a5d401775e28f3af1adf417749ce378f05901b771a8a47531cea3b911d78a3e875d83e3940934d41845d52dcb9782f08b47001e18207f8e7bb0c839e545b278629e52fd2e720bc2a41c25479710d36d22d0c8338cf58e2d6ab5aedbd26cd7008b6644567ebe43611c1e8df052f591b4b78acfe0d94997f0d8f1030be0c63c93e5edff20ef3979e98ca69a6cc7f658992cdaf383faa2768914bf9bb5a5d1ab7292ee3cd79338393472a281f8e51bb8a8fd1928581020848dac9b24397ddbbea86a52fd82106d49e12fdb492e81ab53bd8cb9f74c05949924bf297e9cfc481f410460c28af5745696ef57627a127dba22c1cbfc3374a5b2302030100010282010066d8eefdb70abca14fcf49a41e2689729c9ccbd4932a9868ae9093f37b2b055422e7d09d154e8c8fe68bff1b749023cc562809c3c3f7fd808427d27ead2f01b28584fb159412c26fb57a13eefccf1da02d337722d4765ddf4d8ccf5f86812f04a5dc7eec5e69f345c014b0d49c42f33b329fb6f58666659f49e0e7b25c1538d90bff5540cf02b2ec27ba864e12c5113b976344d8e9254873b30865357fbf19cd560a4a74b9020f58ac68ce0264ce5c36ca34a37fa88a2b010d5ba2fcc6a02c31de21886ad40a14ec72542c8ed4fb09613ec93be9196e105645113e2fb97ea693c447d6dd2c5c6cd6de42aca734efc87ec2e52bd394b53f52635e4ebca64dfe9102818100de2bc011d75dfbdccce26fabb3a631b380d44ccdd60db84c568f1cb1033cf9dcd011ef3acf1ef5ef7c8aa30d270b27835c44ed9375d85701f66838f547e64e0f24728b04f2ae5d9a56968a24080c84358efe3dde794bcafe6be32eb2b31a8183658dbe566d54e037c7207698a6f656db20596937a4996958cb40bdc9f13587eb02818100d20a1cc8b64a965f5d4236cb49f73272504db423b2eba720493601b582dbf3dd93144029f73f1c47b50ccdf67d4fd2649262cfa304a3eea12c982edd70c1ed74fe5a602f8ae4296537fe6d4ccadd2dbde27d59ca8787ab737006dbfdf5e95054ffa384960e299690f92e09bfbc8ffff6ca25e4d1afd3d9fdfacca32e66fba3a90281802e81ec10100c6d87d81fe28e87e9d767a3254dfa9cbf7c800672a8e7e92c9f8578ccf84e504343ea6120c8671d70395247436a943ecc0dd2ac593eeb21a4f55c381dfe3a07ef364af3ab49b9a731af8f62a29822f533478820df8acbffb021c276c4c83e615eae1d1f030db080eafa5d9e94f8f09bf53d57481d025dbeaf9d070281802edb0aa8cbe1bfc1ee7003013eb2e29215cfffcba6f2630a14caf37ea67ea2dc5f1f39612342f4f01a378d0adbd19ec1c8d63a33c7a93a66c22800ec6d6715adefc0018d1992e4992bf09a397357fc084c2a628987ca8038f458d362c8251042a5f4b873311d9df521615fd362214d9ca463e7b3cf619753cd4b316bfc954e610281806beec9501236f93a79f99999c60e1fbbd81c4b35d83006484ed0e09da5d212aa4d05d0fc5bcb6d8314e297644a62c88f5760fd42f303e226c4a11a6db213004f5979ebad9356733695b826d71eb664590a200431b71c65cd754e0c0160b28989728a7201a4fa68009652ce918b9966cc5a1dbcf91252e80417e8a1eb2b5a36bb', expect(out.privKey).to.equal(testId.privKey)
pubKey: '080012a60230820122300d06092a864886f70d01010105000382010f003082010a0282010100b648aa3f1cc1597819a5d401775e28f3af1adf417749ce378f05901b771a8a47531cea3b911d78a3e875d83e3940934d41845d52dcb9782f08b47001e18207f8e7bb0c839e545b278629e52fd2e720bc2a41c25479710d36d22d0c8338cf58e2d6ab5aedbd26cd7008b6644567ebe43611c1e8df052f591b4b78acfe0d94997f0d8f1030be0c63c93e5edff20ef3979e98ca69a6cc7f658992cdaf383faa2768914bf9bb5a5d1ab7292ee3cd79338393472a281f8e51bb8a8fd1928581020848dac9b24397ddbbea86a52fd82106d49e12fdb492e81ab53bd8cb9f74c05949924bf297e9cfc481f410460c28af5745696ef57627a127dba22c1cbfc3374a5b230203010001' expect(out.pubKey).to.equal(testId.pubKey)
}
expect(out.id).to.equal(expected.id)
expect(out.privKey).to.equal(expected.privKey)
expect(out.pubKey).to.equal(expected.pubKey)
}) })
it('toBytes', () => { it('toBytes', () => {
@ -118,6 +110,16 @@ describe('PeerId', () => {
expect(id.privKey).to.not.exist expect(id.privKey).to.not.exist
expect(id.pubKey).to.not.exist expect(id.pubKey).to.not.exist
}) })
it('go interop', () => {
const id = PeerId.createFromJSON(goId)
expect(
mh.toB58String(id.privKey.public.hash())
).to.be.eql(
goId.id
)
})
}) })
describe('throws on inconsistent data', () => { describe('throws on inconsistent data', () => {