mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-25 02:22:17 +00:00
commit
bc213dd818
@ -203,6 +203,9 @@ Returns an `obj` of the form
|
||||
|
||||
Alias for `.toJSON()`.
|
||||
|
||||
### `isEqual(id)`
|
||||
|
||||
- `id` can be a PeerId or a Buffer containing the id
|
||||
|
||||
# License
|
||||
|
||||
|
10
src/index.js
10
src/index.js
@ -88,6 +88,16 @@ class PeerId {
|
||||
toB58String () {
|
||||
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
|
||||
|
@ -129,6 +129,20 @@ describe('PeerId', () => {
|
||||
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', () => {
|
||||
it('full node', (done) => {
|
||||
PeerId.create({ bits: 1024 }, (err, id) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user