mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-04-25 06:22:24 +00:00
Merge pull request #84 from libp2p/feat/add-class-is-module
feat: add class-is module
This commit is contained in:
commit
d7e633a90b
@ -39,6 +39,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.6.1",
|
||||
"class-is": "^1.1.0",
|
||||
"libp2p-crypto": "~0.13.0",
|
||||
"lodash": "^4.17.10",
|
||||
"multihashes": "~0.4.13"
|
||||
|
21
src/index.js
21
src/index.js
@ -8,6 +8,7 @@ const mh = require('multihashes')
|
||||
const crypto = require('libp2p-crypto')
|
||||
const assert = require('assert')
|
||||
const waterfall = require('async/waterfall')
|
||||
const withIs = require('class-is')
|
||||
|
||||
class PeerId {
|
||||
constructor (id, privKey, pubKey) {
|
||||
@ -132,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
|
||||
exports.create = function (opts, callback) {
|
||||
@ -153,20 +156,20 @@ exports.create = function (opts, callback) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
callback(null, new PeerId(digest, privKey))
|
||||
callback(null, new PeerIdWithIs(digest, privKey))
|
||||
})
|
||||
}
|
||||
|
||||
exports.createFromHexString = function (str) {
|
||||
return new PeerId(mh.fromHexString(str))
|
||||
return new PeerIdWithIs(mh.fromHexString(str))
|
||||
}
|
||||
|
||||
exports.createFromBytes = function (buf) {
|
||||
return new PeerId(buf)
|
||||
return new PeerIdWithIs(buf)
|
||||
}
|
||||
|
||||
exports.createFromB58String = function (str) {
|
||||
return new PeerId(mh.fromB58String(str))
|
||||
return new PeerIdWithIs(mh.fromB58String(str))
|
||||
}
|
||||
|
||||
// Public Key input will be a buffer
|
||||
@ -195,7 +198,7 @@ exports.createFromPubKey = function (key, callback) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
callback(null, new PeerId(digest, null, pubKey))
|
||||
callback(null, new PeerIdWithIs(digest, null, pubKey))
|
||||
})
|
||||
}
|
||||
|
||||
@ -227,7 +230,7 @@ exports.createFromPrivKey = function (key, callback) {
|
||||
return callback(err)
|
||||
}
|
||||
|
||||
callback(null, new PeerId(digest, privKey, privKey.public))
|
||||
callback(null, new PeerIdWithIs(digest, privKey, privKey.public))
|
||||
})
|
||||
}
|
||||
|
||||
@ -278,10 +281,10 @@ exports.createFromJSON = function (obj, callback) {
|
||||
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 {
|
||||
callback(null, new PeerId(id, null, pub))
|
||||
callback(null, new PeerIdWithIs(id, null, pub))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user