fix: catch errors thrown by multihash decode (#109)

This commit is contained in:
Jacob Heun
2019-12-18 11:17:59 +01:00
committed by Vasco Santos
parent 74cdb24544
commit 65e0b746a5

View File

@@ -50,12 +50,17 @@ class PeerId {
return this._privKey.public
}
const decoded = mh.decode(this.id)
try {
const decoded = mh.decode(this.id)
if (decoded.name === 'identity') {
this._pubKey = cryptoKeys.unmarshalPublicKey(decoded.digest)
return this._pubKey
if (decoded.name === 'identity') {
this._pubKey = cryptoKeys.unmarshalPublicKey(decoded.digest)
}
} catch (_) {
// Ignore, there is no valid public key
}
return this._pubKey
}
set pubKey (pubKey) {