Compare commits

...

12 Commits

Author SHA1 Message Date
f3fc3449c1 chore: release version v0.14.6 2021-04-06 14:09:48 +02:00
927a6cf078 chore: update contributors 2021-04-06 14:09:48 +02:00
73fe2c553f chore: add no types to release script 2021-04-06 14:04:43 +02:00
719ddfe8e2 chore: update deps (#143) 2021-04-06 13:59:19 +02:00
037ed87dac chore: release version v0.14.4 2021-03-29 12:57:18 +02:00
af47794289 chore: update contributors 2021-03-29 12:57:18 +02:00
eeb53305c8 fix: remove toString side effect that breaks deep equals (#142)
Makes the cached string cid property non-enumerable so deep equals
still works even after a peer id has been stringifed.

Fixes #141
2021-03-29 12:53:11 +02:00
5468ee0877 chore: release version v0.14.3 2021-01-26 09:22:15 +01:00
f895151451 chore: update contributors 2021-01-26 09:22:15 +01:00
e7d0eaa796 chore: update deps (#137) 2021-01-26 09:10:46 +01:00
41ab96c47d docs: correct case for RSA keyType (#136)
* docs: correct case for RSA keyType

correct case of rsa keytype in docs/examples to match keyType exported from libp2p-crypto

Co-authored-by: Vasco Santos <vasco.santos@ua.pt>
2021-01-06 15:13:25 +01:00
4178e53db8 docs: add documentation for isPeerId(id) (#134) (#135) 2020-12-01 17:33:15 +01:00
5 changed files with 62 additions and 15 deletions

View File

@ -1,3 +1,20 @@
## [0.14.6](https://github.com/libp2p/js-peer-id/compare/v0.14.4...v0.14.6) (2021-04-06)
## [0.14.4](https://github.com/libp2p/js-peer-id/compare/v0.14.3...v0.14.4) (2021-03-29)
### Bug Fixes
* remove toString side effect that breaks deep equals ([#142](https://github.com/libp2p/js-peer-id/issues/142)) ([eeb5330](https://github.com/libp2p/js-peer-id/commit/eeb53305c8767a6a2b3f610fe9e45a589b4fa972)), closes [#141](https://github.com/libp2p/js-peer-id/issues/141)
## [0.14.3](https://github.com/libp2p/js-peer-id/compare/v0.14.2...v0.14.3) (2021-01-26)
<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)

View File

@ -53,6 +53,8 @@
- [`toPrint()`](#toprint)
- [`equals(id)`](#equalsid)
- [`isEqual(id)`](#isequalid)
- [Others](#others)
- [`isPeerId(id)`](#ispeeridid)
- [License](#license)
# Description
@ -68,7 +70,7 @@ The public key is a base64 encoded string of a protobuf containing an RSA DER bu
```JavaScript
const PeerId = require('peer-id')
const id = await PeerId.create({ bits: 1024, keyType: 'rsa' })
const id = await PeerId.create({ bits: 1024, keyType: 'RSA' })
console.log(JSON.stringify(id.toJSON(), null, 2))
```
@ -147,7 +149,7 @@ The key format is detailed in [libp2p-crypto](https://github.com/libp2p/js-libp2
Generates a new Peer ID, complete with public/private keypair.
- `opts.bits: number` - The size of the key. Default: `2048`
- `opts.keyType: string` - The key type, one of: `['rsa', 'ed25519', 'secp256k1']`. Default: `rsa`
- `opts.keyType: string` - The key type, one of: `['RSA', 'Ed25519', 'secp256k1']`. Default: `RSA`
Returns `Promise<PeerId>`.
@ -285,6 +287,14 @@ Returns `true` if the given PeerId is equal to the current instance.
- `id` can be a PeerId or a Buffer containing the id
## Others
### `isPeerId(id)`
Returns `true` if the given id is an instance of PeerId
- `id` should be an instance of PeerId
# License
MIT

View File

@ -1,6 +1,6 @@
{
"name": "peer-id",
"version": "0.14.2",
"version": "0.14.6",
"description": "IPFS Peer Id implementation in Node.js",
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
"main": "src/index.js",
@ -8,12 +8,12 @@
"bin": "src/bin.js",
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
"build": "aegir build --no-types",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser -t webworker",
"test:types": "npx tsc",
"release": "aegir release",
"release": "aegir release --no-types",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"coverage": "aegir coverage",
@ -36,19 +36,19 @@
},
"homepage": "https://github.com/libp2p/js-peer-id",
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/chai": "^4.2.14",
"@types/dirty-chai": "^2.0.2",
"@types/mocha": "^8.0.1",
"aegir": "^25.0.0"
"@types/mocha": "^8.2.0",
"aegir": "^32.2.0"
},
"dependencies": {
"cids": "^1.0.0",
"cids": "^1.1.5",
"class-is": "^1.1.0",
"libp2p-crypto": "^0.18.0",
"libp2p-crypto": "^0.19.0",
"minimist": "^1.2.5",
"multihashes": "^3.0.1",
"multihashes": "^4.0.2",
"protons": "^2.0.0",
"uint8arrays": "^1.1.0"
"uint8arrays": "^2.0.5"
},
"repository": {
"type": "git",
@ -62,11 +62,12 @@
"Jacob Heun <jacobheun@gmail.com>",
"Pedro Teixeira <i@pgte.me>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"Alex Potsides <alex@achingbrain.net>",
"Hugo Dias <hugomrdias@gmail.com>",
"Maciej Krüger <mkg20001@gmail.com>",
"Alex Potsides <alex@achingbrain.net>",
"Nate Foss <npfoss@gmail.com>",
"Robert Kiel <robert.kiel@validitylabs.org>",
"Adam Uhlíř <adam@uhlir.dev>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
"Arve Knudsen <arve.knudsen@gmail.com>",
"Carson Farmer <carson.farmer@gmail.com>",
@ -80,6 +81,6 @@
"Topper Bowers <topper@quorumcontrol.com>",
"Vojtech Simetka <vojtech@simetka.cz>",
"Yahya <ya7yaz@gmail.com>",
"Adam Uhlíř <adam@uhlir.dev>"
"a1300 <matthias-knopp@gmx.net>"
]
}

View File

@ -137,13 +137,18 @@ class PeerId {
toString () {
if (!this._idCIDString) {
const cid = new CID(1, 'libp2p-key', this.id, 'base32')
this._idCIDString = cid.toBaseEncodedString('base32')
Object.defineProperty(this, '_idCIDString', {
value: cid.toBaseEncodedString('base32'),
enumerable: false
})
}
return this._idCIDString
}
/**
* Checks the equality of `this` peer against a given PeerId.
*
* @param {Uint8Array|PeerId} id
* @returns {boolean}
*/
@ -159,6 +164,7 @@ class PeerId {
/**
* Checks the equality of `this` peer against a given PeerId.
*
* @deprecated Use `.equals`
* @param {Uint8Array|PeerId} id
* @returns {boolean}
@ -181,6 +187,7 @@ class PeerId {
/**
* Check if the PeerId has an inline public key.
*
* @returns {boolean}
*/
hasInlinePublicKey () {

View File

@ -309,6 +309,18 @@ describe('PeerId', () => {
expect(peerId.isValid()).to.equal(false)
})
it('keys are equal after one is stringified', async () => {
const peerId = await PeerId.create(testOpts)
const peerId1 = PeerId.createFromB58String(peerId.toB58String())
const peerId2 = PeerId.createFromB58String(peerId.toB58String())
expect(peerId1).to.deep.equal(peerId2)
peerId1.toString()
expect(peerId1).to.deep.equal(peerId2)
})
describe('returns error via cb instead of crashing', () => {
const garbage = [
uint8ArrayFromString('00010203040506070809', 'base16'),