mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-07 00:01:50 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
4575a1589a | |||
1beebb65c1 | |||
3dbd9a718d |
@ -203,9 +203,6 @@ Returns an `obj` of the form
|
|||||||
|
|
||||||
Alias for `.toJSON()`.
|
Alias for `.toJSON()`.
|
||||||
|
|
||||||
### `isEqual(id)`
|
|
||||||
|
|
||||||
- `id` can be a PeerId or a Buffer containing the id
|
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
13
package.json
13
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peer-id",
|
"name": "peer-id",
|
||||||
"version": "0.8.6",
|
"version": "0.8.3",
|
||||||
"description": "IPFS Peer Id implementation in Node.js",
|
"description": "IPFS Peer Id implementation in Node.js",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"bin": "src/bin.js",
|
"bin": "src/bin.js",
|
||||||
@ -34,16 +34,15 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/libp2p/js-peer-id",
|
"homepage": "https://github.com/libp2p/js-peer-id",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^11.0.1",
|
"aegir": "^11.0.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"dirty-chai": "^1.2.2",
|
"dirty-chai": "^1.2.2",
|
||||||
"pre-commit": "^1.2.2"
|
"pre-commit": "^1.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.2.0",
|
"libp2p-crypto": "~0.8.6",
|
||||||
"libp2p-crypto": "~0.8.7",
|
"multihashes": "~0.4.4",
|
||||||
"lodash": "^4.17.4",
|
"async": "^2.1.5"
|
||||||
"multihashes": "~0.4.5"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -53,10 +52,10 @@
|
|||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
"David Dias <mail@daviddias.me>",
|
"David Dias <mail@daviddias.me>",
|
||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
|
"Greenkeeper <support@greenkeeper.io>",
|
||||||
"Prashanth Chandra <coolshanth94@gmail.com>",
|
"Prashanth Chandra <coolshanth94@gmail.com>",
|
||||||
"Richard Littauer <richard.littauer@gmail.com>",
|
"Richard Littauer <richard.littauer@gmail.com>",
|
||||||
"Stephen Whitmore <stephen.whitmore@gmail.com>",
|
"Stephen Whitmore <stephen.whitmore@gmail.com>",
|
||||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
|
||||||
"nginnever <ginneversource@gmail.com>",
|
"nginnever <ginneversource@gmail.com>",
|
||||||
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
|
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>"
|
||||||
]
|
]
|
||||||
|
17
src/index.js
17
src/index.js
@ -88,19 +88,10 @@ class PeerId {
|
|||||||
toB58String () {
|
toB58String () {
|
||||||
return this._idB58String
|
return this._idB58String
|
||||||
}
|
}
|
||||||
|
|
||||||
isEqual (id) {
|
|
||||||
if (Buffer.isBuffer(id)) {
|
|
||||||
return this.id.equals(id)
|
|
||||||
} else if (id.id) {
|
|
||||||
return this.id.equals(id.id)
|
|
||||||
} else {
|
|
||||||
throw new Error('not valid Id')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports = module.exports = PeerId
|
exports = module.exports = PeerId
|
||||||
|
exports.Buffer = Buffer
|
||||||
|
|
||||||
// generation
|
// generation
|
||||||
exports.create = function (opts, callback) {
|
exports.create = function (opts, callback) {
|
||||||
@ -228,12 +219,6 @@ exports.createFromJSON = function (obj, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.isPeerId = function (peerId) {
|
|
||||||
return Boolean(typeof peerId === 'object' &&
|
|
||||||
peerId._id &&
|
|
||||||
peerId._idB58String)
|
|
||||||
}
|
|
||||||
|
|
||||||
function toB64Opt (val) {
|
function toB64Opt (val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
return val.toString('base64')
|
return val.toString('base64')
|
||||||
|
@ -32,16 +32,6 @@ describe('PeerId', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('isPeerId', (done) => {
|
|
||||||
PeerId.create((err, id) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(PeerId.isPeerId(id)).to.equal(true)
|
|
||||||
expect(PeerId.isPeerId('aaa')).to.equal(false)
|
|
||||||
expect(PeerId.isPeerId(new Buffer('batatas'))).to.equal(false)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('throws on changing the id', (done) => {
|
it('throws on changing the id', (done) => {
|
||||||
PeerId.create((err, id) => {
|
PeerId.create((err, id) => {
|
||||||
expect(err).to.not.exist()
|
expect(err).to.not.exist()
|
||||||
@ -129,20 +119,6 @@ describe('PeerId', () => {
|
|||||||
expect(id.toBytes().toString('hex')).to.equal(testIdBytes.toString('hex'))
|
expect(id.toBytes().toString('hex')).to.equal(testIdBytes.toString('hex'))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('isEqual', (done) => {
|
|
||||||
parallel([
|
|
||||||
(cb) => PeerId.create(cb),
|
|
||||||
(cb) => PeerId.create(cb)
|
|
||||||
], (err, ids) => {
|
|
||||||
expect(err).to.not.exist()
|
|
||||||
expect(ids[0].isEqual(ids[0])).to.equal(true)
|
|
||||||
expect(ids[0].isEqual(ids[1])).to.equal(false)
|
|
||||||
expect(ids[0].isEqual(ids[0].id)).to.equal(true)
|
|
||||||
expect(ids[0].isEqual(ids[1].id)).to.equal(false)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('fromJSON', () => {
|
describe('fromJSON', () => {
|
||||||
it('full node', (done) => {
|
it('full node', (done) => {
|
||||||
PeerId.create({ bits: 1024 }, (err, id) => {
|
PeerId.create({ bits: 1024 }, (err, id) => {
|
||||||
|
Reference in New Issue
Block a user