Skip to content

Commit

Permalink
feat: inline public key handling for the 0.12.x line (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobowers authored and vasco-santos committed Sep 25, 2019
1 parent 8f4027b commit ceeff13
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:

- stage: check
script:
- npx aegir commitlint --travis
- npx aegir dep-check
- npm run lint

Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ class PeerId {
if (this._privKey) {
return this._privKey.public
}

const decoded = mh.decode(this.id)

if (decoded.name === 'identity') {
this._pubKey = cryptoKeys.unmarshalPublicKey(decoded.digest)
return this._pubKey
}
}

set pubKey (pubKey) {
Expand Down
10 changes: 10 additions & 0 deletions test/peer-id.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ describe('PeerId', () => {
})
})

it('can get the public key from a Secp256k1 key', (done) => {
PeerId.create({ keyType: 'secp256k1', bits: 256 }, (err, original) => {
expect(err).to.not.exist()

const newId = PeerId.createFromB58String(original.toB58String())
expect(original.pubKey.bytes).to.eql(newId.pubKey.bytes)
done()
})
})

it('isPeerId', (done) => {
PeerId.create(testOpts, (err, id) => {
expect(err).to.not.exist()
Expand Down

0 comments on commit ceeff13

Please sign in to comment.