mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-06-29 06:21:40 +00:00
feat: isPeerId
This commit is contained in:
@ -219,6 +219,12 @@ exports.createFromJSON = function (obj, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.isPeerId = function (peerId) {
|
||||||
|
if (peerId.constructor && peerId.constructor.name) {
|
||||||
|
return peerId.constructor.name === 'PeerId'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function toB64Opt (val) {
|
function toB64Opt (val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
return val.toString('base64')
|
return val.toString('base64')
|
||||||
|
@ -32,6 +32,16 @@ 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()
|
||||||
|
Reference in New Issue
Block a user