Compare commits

...

19 Commits

5 changed files with 69 additions and 14 deletions

View File

@ -1,3 +1,38 @@
<a name="0.11.0"></a>
# [0.11.0](https://github.com/libp2p/js-peer-id/compare/v0.10.7...v0.11.0) (2018-07-02)
### Features
* change toPrint output to match go implementation ([e8ab1b9](https://github.com/libp2p/js-peer-id/commit/e8ab1b9))
<a name="0.10.7"></a>
## [0.10.7](https://github.com/libp2p/js-peer-id/compare/v0.10.6...v0.10.7) (2018-04-05)
<a name="0.10.6"></a>
## [0.10.6](https://github.com/libp2p/js-peer-id/compare/v0.10.5...v0.10.6) (2018-02-12)
<a name="0.10.5"></a>
## [0.10.5](https://github.com/libp2p/js-peer-id/compare/v0.10.4...v0.10.5) (2018-01-28)
<a name="0.10.4"></a>
## [0.10.4](https://github.com/libp2p/js-peer-id/compare/v0.10.3...v0.10.4) (2017-12-20)
### Bug Fixes
* update dependencies ([#73](https://github.com/libp2p/js-peer-id/issues/73)) ([8b9a134](https://github.com/libp2p/js-peer-id/commit/8b9a134))
<a name="0.10.3"></a> <a name="0.10.3"></a>
## [0.10.3](https://github.com/libp2p/js-peer-id/compare/v0.10.2...v0.10.3) (2017-12-01) ## [0.10.3](https://github.com/libp2p/js-peer-id/compare/v0.10.2...v0.10.3) (2017-12-01)

View File

@ -11,6 +11,12 @@
> [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript. > [IPFS](https://github.com/ipfs/ipfs) Peer ID implementation in JavaScript.
## Lead Maintainer
[Pedro Teixeira](https://github.com/pgte)
## Table of Contents
- [Description](#description) - [Description](#description)
- [Example](#example) - [Example](#example)
- [Installation](#installation) - [Installation](#installation)
@ -195,7 +201,9 @@ Returns an `obj` of the form
### `toPrint()` ### `toPrint()`
Alias for `.toJSON()`. Returns the Peer ID as a printable string.
Example: `<peer.ID xxxxxx>`
### `isEqual(id)` ### `isEqual(id)`

View File

@ -1,7 +1,8 @@
{ {
"name": "peer-id", "name": "peer-id",
"version": "0.10.3", "version": "0.11.0",
"description": "IPFS Peer Id implementation in Node.js", "description": "IPFS Peer Id implementation in Node.js",
"leadMaintainer": "Pedro Teixeira <i@pgte.me>",
"main": "src/index.js", "main": "src/index.js",
"bin": "src/bin.js", "bin": "src/bin.js",
"scripts": { "scripts": {
@ -18,9 +19,8 @@
"keywords": [ "keywords": [
"IPFS" "IPFS"
], ],
"author": "David Dias <daviddias@ipfs.io>",
"license": "MIT", "license": "MIT",
"pre-commit": [ "pre-push": [
"lint", "lint",
"test" "test"
], ],
@ -33,16 +33,15 @@
}, },
"homepage": "https://github.com/libp2p/js-peer-id", "homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": { "devDependencies": {
"aegir": "^12.2.0", "aegir": "^14.0.0",
"chai": "^4.1.2", "chai": "^4.1.2",
"dirty-chai": "^2.0.1", "dirty-chai": "^2.0.1"
"pre-commit": "^1.2.2"
}, },
"dependencies": { "dependencies": {
"async": "^2.6.0", "async": "^2.6.1",
"libp2p-crypto": "~0.10.4", "libp2p-crypto": "~0.13.0",
"lodash": "^4.17.4", "lodash": "^4.17.10",
"multihashes": "~0.4.12" "multihashes": "~0.4.13"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -53,8 +52,10 @@
"David Dias <mail@daviddias.me>", "David Dias <mail@daviddias.me>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>", "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Maciej Krüger <mkg20001@gmail.com>", "Maciej Krüger <mkg20001@gmail.com>",
"Michael Garvin <gar+gh@danger.computer>",
"Prashanth Chandra <coolshanth94@gmail.com>", "Prashanth Chandra <coolshanth94@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>", "Richard Littauer <richard.littauer@gmail.com>",
"Richard Schneider <makaretu@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>", "Stephen Whitmore <stephen.whitmore@gmail.com>",
"Yahya <ya7yaz@gmail.com>", "Yahya <ya7yaz@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>", "greenkeeperio-bot <support@greenkeeper.io>",

View File

@ -67,9 +67,19 @@ class PeerId {
} }
} }
// pretty print
toPrint () { toPrint () {
return this.toJSON() let pid = this.toB58String()
// All sha256 nodes start with Qm
// We can skip the Qm to make the peer.ID more useful
if (pid.startsWith('Qm')) {
pid = pid.slice(2)
}
let maxRunes = 6
if (pid.length < maxRunes) {
maxRunes = pid.length
}
return '<peer.ID ' + pid.substr(0, maxRunes) + '>'
} }
// return the jsonified version of the key, matching the formatting // return the jsonified version of the key, matching the formatting

View File

@ -136,9 +136,10 @@ describe('PeerId', () => {
it('Pretty printing', (done) => { it('Pretty printing', (done) => {
PeerId.create(testOpts, (err, id1) => { PeerId.create(testOpts, (err, id1) => {
expect(err).to.not.exist() expect(err).to.not.exist()
PeerId.createFromPrivKey(id1.toPrint().privKey, (err, id2) => { PeerId.createFromPrivKey(id1.toJSON().privKey, (err, id2) => {
expect(err).to.not.exist() expect(err).to.not.exist()
expect(id1.toPrint()).to.be.eql(id2.toPrint()) expect(id1.toPrint()).to.be.eql(id2.toPrint())
expect(id1.toPrint()).to.equal('<peer.ID ' + id1.toB58String().substr(2, 6) + '>')
done() done()
}) })
}) })