Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -132,7 +133,7 @@ class PeerId {
}
}

exports = module.exports = PeerId
exports = module.exports = withIs(PeerId, { className: 'PeerId', symbolName: '@libp2p/js-peer-id/PeerId' })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of occasions in this file where we're accessing the non-wrapped PeerId class:

callback(null, new PeerId(digest, privKey))

return new PeerId(mh.fromHexString(str))

return new PeerId(buf)

return new PeerId(mh.fromB58String(str))

callback(null, new PeerId(digest, null, pubKey))

callback(null, new PeerId(digest, privKey, privKey.public))

callback(null, new PeerId(id, priv, pub))

These all need to be changed otherwise they create PeerId objects that don't have the '@libp2p/js-peer-id/PeerId' symbol and so aren't considered to be instances of PeerId when used with PeerId.isPeerId.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Thanks for noticing that.

I added PeerIdWithIs to all of them. However, I feel that there might be a better approach here. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// generation
exports.create = function (opts, callback) {
Expand Down