Compare commits

...

4 Commits

6 changed files with 33 additions and 10 deletions

View File

@ -22,7 +22,6 @@ jobs:
- stage: check - stage: check
script: script:
- npx aegir commitlint --travis
- npx aegir dep-check - npx aegir dep-check
- npm run lint - npm run lint

View File

@ -1,3 +1,13 @@
<a name="0.13.3"></a>
## [0.13.3](https://github.com/libp2p/js-peer-id/compare/v0.13.2...v0.13.3) (2019-09-25)
### Features
* allow nested PeerIds to support pubKey function when using identity encoding ([#101](https://github.com/libp2p/js-peer-id/issues/101)) ([f39fb24](https://github.com/libp2p/js-peer-id/commit/f39fb24))
<a name="0.13.2"></a> <a name="0.13.2"></a>
## [0.13.2](https://github.com/libp2p/js-peer-id/compare/v0.13.1...v0.13.2) (2019-07-12) ## [0.13.2](https://github.com/libp2p/js-peer-id/compare/v0.13.1...v0.13.2) (2019-07-12)

View File

@ -13,7 +13,7 @@
## Lead Maintainer ## Lead Maintainer
[Pedro Teixeira](https://github.com/pgte) [Vasco Santos](https://github.com/vasco-santos)
## Table of Contents ## Table of Contents

View File

@ -1,8 +1,8 @@
{ {
"name": "peer-id", "name": "peer-id",
"version": "0.13.2", "version": "0.13.3",
"description": "IPFS Peer Id implementation in Node.js", "description": "IPFS Peer Id implementation in Node.js",
"leadMaintainer": "Pedro Teixeira <i@pgte.me>", "leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
"main": "src/index.js", "main": "src/index.js",
"bin": "src/bin.js", "bin": "src/bin.js",
"scripts": { "scripts": {
@ -34,7 +34,7 @@
}, },
"homepage": "https://github.com/libp2p/js-peer-id", "homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": { "devDependencies": {
"aegir": "^19.0.5", "aegir": "^20.0.0",
"bundlesize": "~0.18.0", "bundlesize": "~0.18.0",
"chai": "^4.2.0", "chai": "^4.2.0",
"dirty-chai": "^2.0.1" "dirty-chai": "^2.0.1"
@ -64,8 +64,9 @@
"Richard Littauer <richard.littauer@gmail.com>", "Richard Littauer <richard.littauer@gmail.com>",
"Richard Schneider <makaretu@gmail.com>", "Richard Schneider <makaretu@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>", "Stephen Whitmore <stephen.whitmore@gmail.com>",
"Vasco Santos <vasco.santos@ua.pt>", "Topper Bowers <topper@quorumcontrol.com>",
"Vasco Santos <vasco.santos@moxy.studio>", "Vasco Santos <vasco.santos@moxy.studio>",
"Vasco Santos <vasco.santos@ua.pt>",
"Yahya <ya7yaz@gmail.com>", "Yahya <ya7yaz@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>", "greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>", "nginnever <ginneversource@gmail.com>",

View File

@ -48,6 +48,13 @@ class PeerId {
if (this._privKey) { if (this._privKey) {
return this._privKey.public 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) { set pubKey (pubKey) {
@ -213,10 +220,10 @@ exports.createFromPrivKey = async (key) => {
} }
exports.createFromJSON = async (obj) => { exports.createFromJSON = async (obj) => {
let id = mh.fromB58String(obj.id) const id = mh.fromB58String(obj.id)
let rawPrivKey = obj.privKey && Buffer.from(obj.privKey, 'base64') const rawPrivKey = obj.privKey && Buffer.from(obj.privKey, 'base64')
let rawPubKey = obj.pubKey && Buffer.from(obj.pubKey, 'base64') const rawPubKey = obj.pubKey && Buffer.from(obj.pubKey, 'base64')
let pub = rawPubKey && await cryptoKeys.unmarshalPublicKey(rawPubKey) const pub = rawPubKey && await cryptoKeys.unmarshalPublicKey(rawPubKey)
if (!rawPrivKey) { if (!rawPrivKey) {
return new PeerIdWithIs(id, null, pub) return new PeerIdWithIs(id, null, pub)

View File

@ -42,6 +42,12 @@ describe('PeerId', () => {
expect(id.toB58String()).to.equal(expB58) expect(id.toB58String()).to.equal(expB58)
}) })
it('can get the public key from a Secp256k1 key', async () => {
const original = await PeerId.create({ keyType: 'secp256k1', bits: 256 })
const newId = PeerId.createFromB58String(original.toB58String())
expect(original.pubKey.bytes).to.eql(newId.pubKey.bytes)
})
it('isPeerId', async () => { it('isPeerId', async () => {
const id = await PeerId.create(testOpts) const id = await PeerId.create(testOpts)
expect(PeerId.isPeerId(id)).to.equal(true) expect(PeerId.isPeerId(id)).to.equal(true)