Compare commits

...

7 Commits

Author SHA1 Message Date
bd1dc9bda0 chore: release version v0.11.0 2018-07-02 19:28:04 +02:00
31cbb5d94c chore: update contributors 2018-07-02 19:28:03 +02:00
35556c3a37 chore: update deps 2018-07-02 19:26:36 +02:00
e8ab1b9281 feat: change toPrint output to match go implementation 2018-07-02 19:26:03 +02:00
a786018528 chore: remove pre-commit module 2018-06-04 09:48:30 +01:00
417fd330b9 docs: add lead maintainer 2018-06-04 09:48:30 +01:00
d74bdebcc8 chore: update deps 2018-06-04 09:48:30 +01:00
5 changed files with 42 additions and 13 deletions

View File

@ -1,3 +1,13 @@
<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)

View File

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

View File

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

View File

@ -67,9 +67,19 @@ class PeerId {
}
}
// pretty print
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

View File

@ -136,9 +136,10 @@ describe('PeerId', () => {
it('Pretty printing', (done) => {
PeerId.create(testOpts, (err, id1) => {
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(id1.toPrint()).to.be.eql(id2.toPrint())
expect(id1.toPrint()).to.equal('<peer.ID ' + id1.toB58String().substr(2, 6) + '>')
done()
})
})