mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-06 13:21:47 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
b5335cd4ee | |||
519052693d | |||
bbf0416f08 |
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
<a name="0.13.5"></a>
|
||||||
|
## [0.13.5](https://github.com/libp2p/js-peer-id/compare/v0.13.4...v0.13.5) (2019-11-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* deprecate isEqual in favor of equals ([#107](https://github.com/libp2p/js-peer-id/issues/107)) ([bbf0416](https://github.com/libp2p/js-peer-id/commit/bbf0416))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<a name="0.13.4"></a>
|
<a name="0.13.4"></a>
|
||||||
## [0.13.4](https://github.com/libp2p/js-peer-id/compare/v0.13.3...v0.13.4) (2019-11-04)
|
## [0.13.4](https://github.com/libp2p/js-peer-id/compare/v0.13.3...v0.13.4) (2019-11-04)
|
||||||
|
|
||||||
|
17
README.md
17
README.md
@ -17,6 +17,9 @@
|
|||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
|
- [peer-id](#peer-id)
|
||||||
|
- [Lead Maintainer](#lead-maintainer)
|
||||||
|
- [Table of Contents](#table-of-contents)
|
||||||
- [Description](#description)
|
- [Description](#description)
|
||||||
- [Example](#example)
|
- [Example](#example)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
@ -37,13 +40,18 @@
|
|||||||
- [`createFromPubKey(pubKey)`](#createfrompubkeypubkey)
|
- [`createFromPubKey(pubKey)`](#createfrompubkeypubkey)
|
||||||
- [`createFromPrivKey(privKey)`](#createfromprivkeyprivkey)
|
- [`createFromPrivKey(privKey)`](#createfromprivkeyprivkey)
|
||||||
- [`createFromJSON(obj)`](#createfromjsonobj)
|
- [`createFromJSON(obj)`](#createfromjsonobj)
|
||||||
|
- [`createFromProtobuf(buf)`](#createfromprotobufbuf)
|
||||||
- [Export](#export)
|
- [Export](#export)
|
||||||
|
- [`toHexString()`](#tohexstring)
|
||||||
- [`toBytes()`](#tobytes)
|
- [`toBytes()`](#tobytes)
|
||||||
- [`toString()`](#tostring)
|
- [`toString()`](#tostring)
|
||||||
- [`toB58String()`](#tob58string)
|
- [`toB58String()`](#tob58string)
|
||||||
- [`toHexString()`](#tohexstring)
|
|
||||||
- [`toJSON()`](#tojson)
|
- [`toJSON()`](#tojson)
|
||||||
|
- [`marshal(excludePrivateKey)`](#marshalexcludeprivatekey)
|
||||||
|
- [`marshalPubKey()`](#marshalpubkey)
|
||||||
- [`toPrint()`](#toprint)
|
- [`toPrint()`](#toprint)
|
||||||
|
- [`equals(id)`](#equalsid)
|
||||||
|
- [`isEqual(id)`](#isequalid)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
|
|
||||||
# Description
|
# Description
|
||||||
@ -256,7 +264,14 @@ Returns the Peer ID as a printable string without the `Qm` prefix.
|
|||||||
|
|
||||||
Example: `<peer.ID xxxxxx>`
|
Example: `<peer.ID xxxxxx>`
|
||||||
|
|
||||||
|
### `equals(id)`
|
||||||
|
|
||||||
|
Returns `true` if the given PeerId is equal to the current instance.
|
||||||
|
|
||||||
|
- `id` can be a PeerId or a Buffer containing the id
|
||||||
|
|
||||||
### `isEqual(id)`
|
### `isEqual(id)`
|
||||||
|
**Deprecation Notice**: Use [`equals`](#equalsid), `isEqual` will be removed in 0.14.0.
|
||||||
|
|
||||||
- `id` can be a PeerId or a Buffer containing the id
|
- `id` can be a PeerId or a Buffer containing the id
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peer-id",
|
"name": "peer-id",
|
||||||
"version": "0.13.4",
|
"version": "0.13.5",
|
||||||
"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",
|
||||||
|
17
src/index.js
17
src/index.js
@ -133,7 +133,12 @@ class PeerId {
|
|||||||
return this._idCIDString
|
return this._idCIDString
|
||||||
}
|
}
|
||||||
|
|
||||||
isEqual (id) {
|
/**
|
||||||
|
* Checks the equality of `this` peer against a given PeerId.
|
||||||
|
* @param {Buffer|PeerId} id
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
equals (id) {
|
||||||
if (Buffer.isBuffer(id)) {
|
if (Buffer.isBuffer(id)) {
|
||||||
return this.id.equals(id)
|
return this.id.equals(id)
|
||||||
} else if (id.id) {
|
} else if (id.id) {
|
||||||
@ -143,6 +148,16 @@ class PeerId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the equality of `this` peer against a given PeerId.
|
||||||
|
* @deprecated Use `.equals`
|
||||||
|
* @param {Buffer|PeerId} id
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
isEqual (id) {
|
||||||
|
return this.equals(id)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if this PeerId instance is valid (privKey -> pubKey -> Id)
|
* Check if this PeerId instance is valid (privKey -> pubKey -> Id)
|
||||||
*/
|
*/
|
||||||
|
@ -231,6 +231,18 @@ describe('PeerId', () => {
|
|||||||
expect(ids[0].isEqual(ids[1].id)).to.equal(false)
|
expect(ids[0].isEqual(ids[1].id)).to.equal(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('equals', async () => {
|
||||||
|
const ids = await Promise.all([
|
||||||
|
PeerId.create(testOpts),
|
||||||
|
PeerId.create(testOpts)
|
||||||
|
])
|
||||||
|
|
||||||
|
expect(ids[0].equals(ids[0])).to.equal(true)
|
||||||
|
expect(ids[0].equals(ids[1])).to.equal(false)
|
||||||
|
expect(ids[0].equals(ids[0].id)).to.equal(true)
|
||||||
|
expect(ids[0].equals(ids[1].id)).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)
|
||||||
|
Reference in New Issue
Block a user