Compare commits

...

3 Commits

Author SHA1 Message Date
10ead07dd9 chore: release version v0.14.2 2020-09-23 19:11:12 +02:00
d940099131 chore: update contributors 2020-09-23 19:11:12 +02:00
b2ee34295b feat: has inline public key method (#132) 2020-09-23 19:07:28 +02:00
5 changed files with 45 additions and 1 deletions

View File

@ -1,3 +1,13 @@
<a name="0.14.2"></a>
## [0.14.2](https://github.com/libp2p/js-peer-id/compare/v0.14.1...v0.14.2) (2020-09-23)
### Features
* has inline public key method ([#132](https://github.com/libp2p/js-peer-id/issues/132)) ([b2ee342](https://github.com/libp2p/js-peer-id/commit/b2ee342))
<a name="0.14.1"></a> <a name="0.14.1"></a>
## [0.14.1](https://github.com/libp2p/js-peer-id/compare/v0.13.13...v0.14.1) (2020-09-03) ## [0.14.1](https://github.com/libp2p/js-peer-id/compare/v0.13.13...v0.14.1) (2020-09-03)

View File

@ -1,6 +1,6 @@
{ {
"name": "peer-id", "name": "peer-id",
"version": "0.14.1", "version": "0.14.2",
"description": "IPFS Peer Id implementation in Node.js", "description": "IPFS Peer Id implementation in Node.js",
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>", "leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
"main": "src/index.js", "main": "src/index.js",

5
src/index.d.ts vendored
View File

@ -183,6 +183,11 @@ declare class PeerId {
* Check if this PeerId instance is valid (privKey -> pubKey -> Id) * Check if this PeerId instance is valid (privKey -> pubKey -> Id)
*/ */
isValid(): boolean; isValid(): boolean;
/**
* Check if the PeerId has an inline public key.
*/
hasInlinePublicKey(): boolean;
} }
export = PeerId; export = PeerId;

View File

@ -178,6 +178,23 @@ class PeerId {
this.pubKey.bytes instanceof Uint8Array && this.pubKey.bytes instanceof Uint8Array &&
uint8ArrayEquals(this.privKey.public.bytes, this.pubKey.bytes)) uint8ArrayEquals(this.privKey.public.bytes, this.pubKey.bytes))
} }
/**
* Check if the PeerId has an inline public key.
* @returns {boolean}
*/
hasInlinePublicKey () {
try {
const decoded = mh.decode(this.id)
if (decoded.name === 'identity') {
return true
}
} catch (_) {
// Ignore, there is no valid public key
}
return false
}
} }
const PeerIdWithIs = withIs(PeerId, { const PeerIdWithIs = withIs(PeerId, {

View File

@ -243,6 +243,18 @@ describe('PeerId', () => {
expect(ids[0].equals(ids[1].id)).to.equal(false) expect(ids[0].equals(ids[1].id)).to.equal(false)
}) })
describe('hasInlinePublicKey', () => {
it('returns true if uses a key type with inline public key', async () => {
const peerId = await PeerId.create({ keyType: 'secp256k1' })
expect(peerId.hasInlinePublicKey()).to.equal(true)
})
it('returns false if uses a key type with no inline public key', async () => {
const peerId = await PeerId.create({ keyType: 'RSA' })
expect(peerId.hasInlinePublicKey()).to.equal(false)
})
})
describe('fromJSON', () => { describe('fromJSON', () => {
it('full node', async () => { it('full node', async () => {
const id = await PeerId.create(testOpts) const id = await PeerId.create(testOpts)