Compare commits

...

13 Commits

Author SHA1 Message Date
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
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
ecc1e5be6d chore: release version v0.14.1 2020-09-03 18:49:02 +02:00
153bc8ea38 chore: update contributors 2020-09-03 18:49:01 +02:00
d40d588776 fix: ts constructor types (#130) 2020-08-26 11:46:38 +02:00
224b30cb65 fix: privKey possible undefined (#129) 2020-08-17 16:35:13 +02:00
6d571ae196 fix: typo in readme (#128) 2020-08-12 13:40:13 +02:00
6 changed files with 106 additions and 22 deletions

View File

@ -1,3 +1,37 @@
## [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)
### 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)

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>`.
@ -157,7 +159,7 @@ Returns `Promise<PeerId>`.
Creates a Peer ID from hex string representing the key's multihash.
Returns `PeerId.
Returns `PeerId`.
### `createFromBytes(buf)`
@ -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.0",
"version": "0.14.3",
"description": "IPFS Peer Id implementation in Node.js",
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
"main": "src/index.js",
@ -8,7 +8,7 @@
"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",
@ -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": "^30.3.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": "^3.1.1",
"protons": "^2.0.0",
"uint8arrays": "^1.1.0"
"uint8arrays": "^2.0.5"
},
"repository": {
"type": "git",
@ -65,19 +65,22 @@
"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>",
"Adam Uhlíř <adam@uhlir.dev>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <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>"
"a1300 <matthias-knopp@gmx.net>"
]
}

9
src/index.d.ts vendored
View File

@ -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;

View File

@ -144,6 +144,7 @@ class PeerId {
/**
* Checks the equality of `this` peer against a given PeerId.
*
* @param {Uint8Array|PeerId} id
* @returns {boolean}
*/
@ -159,6 +160,7 @@ class PeerId {
/**
* Checks the equality of `this` peer against a given PeerId.
*
* @deprecated Use `.equals`
* @param {Uint8Array|PeerId} id
* @returns {boolean}
@ -178,6 +180,24 @@ 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, {

View File

@ -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)