mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-04 17:41:40 +00:00
Compare commits
31 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e030b24d4 | |||
9f69e1ba74 | |||
cbc8c5e2ba | |||
77000dbd8b | |||
eb062759c6 | |||
39e17c0c0b | |||
e03a4098df | |||
d7e633a90b | |||
2e5e666140 | |||
b388257b69 | |||
6ecd9a8cb0 | |||
6513a02e1e | |||
bd1dc9bda0 | |||
31cbb5d94c | |||
35556c3a37 | |||
e8ab1b9281 | |||
a786018528 | |||
417fd330b9 | |||
d74bdebcc8 | |||
ffed046595 | |||
1727a135aa | |||
466b3a030d | |||
464c92a53b | |||
8a608def32 | |||
19deeff432 | |||
b18c0082ff | |||
2b050bcaa1 | |||
b19edf2ab2 | |||
35b384ed15 | |||
655ceec29b | |||
8b9a134276 |
55
CHANGELOG.md
55
CHANGELOG.md
@ -1,3 +1,58 @@
|
|||||||
|
<a name="0.12.1"></a>
|
||||||
|
## [0.12.1](https://github.com/libp2p/js-peer-id/compare/v0.12.0...v0.12.1) (2019-01-03)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="0.12.0"></a>
|
||||||
|
# [0.12.0](https://github.com/libp2p/js-peer-id/compare/v0.11.0...v0.12.0) (2018-10-18)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add peerIdWithIs to the API functions using the instance ([2e5e666](https://github.com/libp2p/js-peer-id/commit/2e5e666))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add class-is module ([6513a02](https://github.com/libp2p/js-peer-id/commit/6513a02))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<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)
|
||||||
|
|
||||||
|
16
README.md
16
README.md
@ -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)
|
||||||
@ -138,6 +144,7 @@ Creates a Peer ID from hex string representing the key's multihash.
|
|||||||
Creates a Peer ID from a buffer representing the key's multihash.
|
Creates a Peer ID from a buffer representing the key's multihash.
|
||||||
|
|
||||||
### `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.
|
||||||
|
|
||||||
### `createFromPubKey(pubKey)`
|
### `createFromPubKey(pubKey)`
|
||||||
@ -155,8 +162,8 @@ Creates a Peer ID from a buffer containing a private key.
|
|||||||
### `createFromJSON(obj)`
|
### `createFromJSON(obj)`
|
||||||
|
|
||||||
- `obj.id: String` - The multihash encoded in `base58`
|
- `obj.id: String` - The multihash encoded in `base58`
|
||||||
- `obj.pubKey: String` - The public key in protobuf format, encoded in 'base64'
|
- `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'
|
- `obj.privKey: String` - The private key in protobuf format, encoded in `base64`
|
||||||
|
|
||||||
## Export
|
## Export
|
||||||
|
|
||||||
@ -192,10 +199,11 @@ Returns an `obj` of the form
|
|||||||
- `obj.pubKey: String` - The public key in protobuf format, encoded in 'base64'
|
- `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'
|
- `obj.privKey: String` - The private key in protobuf format, encoded in 'base 64'
|
||||||
|
|
||||||
|
|
||||||
### `toPrint()`
|
### `toPrint()`
|
||||||
|
|
||||||
Alias for `.toJSON()`.
|
Returns the Peer ID as a printable string without the `Qm` prefix.
|
||||||
|
|
||||||
|
Example: `<peer.ID xxxxxx>`
|
||||||
|
|
||||||
### `isEqual(id)`
|
### `isEqual(id)`
|
||||||
|
|
||||||
|
26
package.json
26
package.json
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "peer-id",
|
"name": "peer-id",
|
||||||
"version": "0.10.3",
|
"version": "0.12.1",
|
||||||
"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,16 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/libp2p/js-peer-id",
|
"homepage": "https://github.com/libp2p/js-peer-id",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^12.2.0",
|
"aegir": "^18.0.2",
|
||||||
"chai": "^4.1.2",
|
"chai": "^4.2.0",
|
||||||
"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",
|
"class-is": "^1.1.0",
|
||||||
"lodash": "^4.17.4",
|
"libp2p-crypto": "~0.15.0",
|
||||||
"multihashes": "~0.4.12"
|
"lodash": "^4.17.11",
|
||||||
|
"multihashes": "~0.4.14"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -53,9 +53,13 @@
|
|||||||
"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>",
|
||||||
|
"Pedro Teixeira <i@pgte.me>",
|
||||||
"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>",
|
||||||
|
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||||
"Yahya <ya7yaz@gmail.com>",
|
"Yahya <ya7yaz@gmail.com>",
|
||||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
"greenkeeperio-bot <support@greenkeeper.io>",
|
||||||
"nginnever <ginneversource@gmail.com>",
|
"nginnever <ginneversource@gmail.com>",
|
||||||
|
35
src/index.js
35
src/index.js
@ -8,6 +8,7 @@ const mh = require('multihashes')
|
|||||||
const crypto = require('libp2p-crypto')
|
const crypto = require('libp2p-crypto')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const waterfall = require('async/waterfall')
|
const waterfall = require('async/waterfall')
|
||||||
|
const withIs = require('class-is')
|
||||||
|
|
||||||
class PeerId {
|
class PeerId {
|
||||||
constructor (id, privKey, pubKey) {
|
constructor (id, privKey, pubKey) {
|
||||||
@ -67,9 +68,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
|
||||||
@ -122,7 +133,9 @@ class PeerId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports = module.exports = PeerId
|
const PeerIdWithIs = withIs(PeerId, { className: 'PeerId', symbolName: '@libp2p/js-peer-id/PeerId' })
|
||||||
|
|
||||||
|
exports = module.exports = PeerIdWithIs
|
||||||
|
|
||||||
// generation
|
// generation
|
||||||
exports.create = function (opts, callback) {
|
exports.create = function (opts, callback) {
|
||||||
@ -143,20 +156,20 @@ exports.create = function (opts, callback) {
|
|||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, new PeerId(digest, privKey))
|
callback(null, new PeerIdWithIs(digest, privKey))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createFromHexString = function (str) {
|
exports.createFromHexString = function (str) {
|
||||||
return new PeerId(mh.fromHexString(str))
|
return new PeerIdWithIs(mh.fromHexString(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createFromBytes = function (buf) {
|
exports.createFromBytes = function (buf) {
|
||||||
return new PeerId(buf)
|
return new PeerIdWithIs(buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createFromB58String = function (str) {
|
exports.createFromB58String = function (str) {
|
||||||
return new PeerId(mh.fromB58String(str))
|
return new PeerIdWithIs(mh.fromB58String(str))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public Key input will be a buffer
|
// Public Key input will be a buffer
|
||||||
@ -185,7 +198,7 @@ exports.createFromPubKey = function (key, callback) {
|
|||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, new PeerId(digest, null, pubKey))
|
callback(null, new PeerIdWithIs(digest, null, pubKey))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +230,7 @@ exports.createFromPrivKey = function (key, callback) {
|
|||||||
return callback(err)
|
return callback(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, new PeerId(digest, privKey, privKey.public))
|
callback(null, new PeerIdWithIs(digest, privKey, privKey.public))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,10 +281,10 @@ exports.createFromJSON = function (obj, callback) {
|
|||||||
return callback(new Error('Id and private key do not match'))
|
return callback(new Error('Id and private key do not match'))
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, new PeerId(id, priv, pub))
|
callback(null, new PeerIdWithIs(id, priv, pub))
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
callback(null, new PeerId(id, null, pub))
|
callback(null, new PeerIdWithIs(id, null, pub))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user