mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-04 12:01:33 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
10ead07dd9 | |||
d940099131 | |||
b2ee34295b | |||
ecc1e5be6d | |||
153bc8ea38 | |||
d40d588776 | |||
224b30cb65 | |||
6d571ae196 |
30
CHANGELOG.md
30
CHANGELOG.md
@ -1,3 +1,33 @@
|
||||
<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>
|
||||
## [0.14.1](https://github.com/libp2p/js-peer-id/compare/v0.13.13...v0.14.1) (2020-09-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* privKey possible undefined ([#129](https://github.com/libp2p/js-peer-id/issues/129)) ([224b30c](https://github.com/libp2p/js-peer-id/commit/224b30c))
|
||||
* replace node buffers with uint8arrays ([#127](https://github.com/libp2p/js-peer-id/issues/127)) ([d16ce9c](https://github.com/libp2p/js-peer-id/commit/d16ce9c))
|
||||
* ts constructor types ([#130](https://github.com/libp2p/js-peer-id/issues/130)) ([d40d588](https://github.com/libp2p/js-peer-id/commit/d40d588))
|
||||
* typo in readme ([#128](https://github.com/libp2p/js-peer-id/issues/128)) ([6d571ae](https://github.com/libp2p/js-peer-id/commit/6d571ae))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
* - Where node Buffers were returned, now Uint8Arrays are
|
||||
|
||||
* chore: remove gh dep
|
||||
|
||||
|
||||
|
||||
<a name="0.14.0"></a>
|
||||
# [0.14.0](https://github.com/libp2p/js-peer-id/compare/v0.13.13...v0.14.0) (2020-08-07)
|
||||
|
||||
|
@ -157,7 +157,7 @@ Returns `Promise<PeerId>`.
|
||||
|
||||
Creates a Peer ID from hex string representing the key's multihash.
|
||||
|
||||
Returns `PeerId.
|
||||
Returns `PeerId`.
|
||||
|
||||
### `createFromBytes(buf)`
|
||||
|
||||
|
20
package.json
20
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "peer-id",
|
||||
"version": "0.14.0",
|
||||
"version": "0.14.2",
|
||||
"description": "IPFS Peer Id implementation in Node.js",
|
||||
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@ -65,19 +65,21 @@
|
||||
"Hugo Dias <hugomrdias@gmail.com>",
|
||||
"Maciej Krüger <mkg20001@gmail.com>",
|
||||
"Alex Potsides <alex@achingbrain.net>",
|
||||
"Robert Kiel <robert.kiel@validitylabs.org>",
|
||||
"Nate Foss <npfoss@gmail.com>",
|
||||
"Robert Kiel <robert.kiel@validitylabs.org>",
|
||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
||||
"Arve Knudsen <arve.knudsen@gmail.com>",
|
||||
"Carson Farmer <carson.farmer@gmail.com>",
|
||||
"Christian Paul <info@jaller.de>",
|
||||
"Henrique Dias <hacdias@gmail.com>",
|
||||
"Marcin Rataj <lidel@lidel.org>",
|
||||
"Michael Garvin <gar+gh@danger.computer>",
|
||||
"Prashanth Chandra <coolshanth94@gmail.com>",
|
||||
"Richard Littauer <richard.littauer@gmail.com>",
|
||||
"Richard Schneider <makaretu@gmail.com>",
|
||||
"Marcin Rataj <lidel@lidel.org>",
|
||||
"Topper Bowers <topper@quorumcontrol.com>",
|
||||
"Henrique Dias <hacdias@gmail.com>",
|
||||
"Vojtech Simetka <vojtech@simetka.cz>",
|
||||
"Yahya <ya7yaz@gmail.com>",
|
||||
"Christian Paul <info@jaller.de>",
|
||||
"Carson Farmer <carson.farmer@gmail.com>",
|
||||
"Arve Knudsen <arve.knudsen@gmail.com>",
|
||||
"Michael Garvin <gar+gh@danger.computer>",
|
||||
"Prashanth Chandra <coolshanth94@gmail.com>"
|
||||
"Adam Uhlíř <adam@uhlir.dev>"
|
||||
]
|
||||
}
|
||||
|
9
src/index.d.ts
vendored
9
src/index.d.ts
vendored
@ -31,7 +31,7 @@ declare namespace PeerId {
|
||||
/**
|
||||
* Private key.
|
||||
*/
|
||||
privKey: string;
|
||||
privKey?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -100,7 +100,7 @@ declare namespace PeerId {
|
||||
* PeerId is an object representation of a peer identifier.
|
||||
*/
|
||||
declare class PeerId {
|
||||
constructor(id: Uint8Array | string, privKey?: PrivateKey, pubKey?: PublicKey);
|
||||
constructor(id: Uint8Array, privKey?: PrivateKey, pubKey?: PublicKey);
|
||||
|
||||
/**
|
||||
* Raw id.
|
||||
@ -183,6 +183,11 @@ declare class PeerId {
|
||||
* Check if this PeerId instance is valid (privKey -> pubKey -> Id)
|
||||
*/
|
||||
isValid(): boolean;
|
||||
|
||||
/**
|
||||
* Check if the PeerId has an inline public key.
|
||||
*/
|
||||
hasInlinePublicKey(): boolean;
|
||||
}
|
||||
|
||||
export = PeerId;
|
||||
|
17
src/index.js
17
src/index.js
@ -178,6 +178,23 @@ class PeerId {
|
||||
this.pubKey.bytes instanceof Uint8Array &&
|
||||
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, {
|
||||
|
@ -243,6 +243,18 @@ describe('PeerId', () => {
|
||||
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', () => {
|
||||
it('full node', async () => {
|
||||
const id = await PeerId.create(testOpts)
|
||||
|
Reference in New Issue
Block a user