Compare commits

...

18 Commits

Author SHA1 Message Date
020b963711 chore: release version v0.13.12 2020-04-22 16:35:07 +02:00
e3da29a440 chore: update contributors 2020-04-22 16:35:07 +02:00
8cd9dfb137 feat(cli): add support for specifying type and size (#122) 2020-04-22 16:32:38 +02:00
3598a433dc chore: release version v0.13.11 2020-03-26 09:07:55 +01:00
5ec88281e2 chore: update contributors 2020-03-26 09:07:55 +01:00
a80c481146 chore(deps): bump cids from 0.7.5 to 0.8.0 (#121)
Bumps [cids](https://github.com/multiformats/js-cid) from 0.7.5 to 0.8.0.
- [Release notes](https://github.com/multiformats/js-cid/releases)
- [Changelog](https://github.com/multiformats/js-cid/blob/master/CHANGELOG.md)
- [Commits](https://github.com/multiformats/js-cid/compare/v0.7.5...v0.8.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-03-26 09:05:51 +01:00
efc96106a4 chore: release version v0.13.10 2020-03-18 17:38:41 +01:00
16e1c74e9a chore: update contributors 2020-03-18 17:38:40 +01:00
c305c36b26 fix: add buffer (#120)
related to this https://github.com/ipfs/js-ipfs/issues/2924
2020-03-18 17:33:29 +01:00
7e985b127f chore(deps-dev): bump @types/mocha from 5.2.7 to 7.0.2 (#119)
Bumps [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/mocha) from 5.2.7 to 7.0.2.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/mocha)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-03-04 14:23:01 +01:00
40d68cb512 chore(deps-dev): bump aegir from 20.6.1 to 21.2.0
Bumps [aegir](https://github.com/ipfs/aegir) from 20.6.1 to 21.2.0.
- [Release notes](https://github.com/ipfs/aegir/releases)
- [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md)
- [Commits](https://github.com/ipfs/aegir/compare/v20.6.1...v21.2.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2020-02-20 08:14:43 -05:00
1d86506c64 chore: release version v0.13.9 2020-02-19 12:06:43 -05:00
9dc7ce5f5e chore: update contributors 2020-02-19 12:06:42 -05:00
f775e3509b chore: update index.d.ts (#115)
Tell Typescript that `isPeerId(id)` returns true if, and only if, `id` is of type `PeerId`.

See https://www.typescriptlang.org/docs/handbook/advanced-types.html#using-type-predicates
2020-02-19 11:51:59 -05:00
00819ba4eb chore: update index.d.ts (#116)
This tells Typescript that `id` is immutable.
2020-02-19 09:17:30 -05:00
6870c8c4d7 chore: release version v0.13.8 2020-02-18 08:44:53 -05:00
71d3a100c9 chore: update contributors 2020-02-18 08:44:52 -05:00
f44645ef7e fix: remove use of assert module (#117)
The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.
2020-02-18 08:42:39 -05:00
7 changed files with 92 additions and 29 deletions

View File

@ -1,3 +1,48 @@
<a name="0.13.12"></a>
## [0.13.12](https://github.com/libp2p/js-peer-id/compare/v0.13.11...v0.13.12) (2020-04-22)
### Features
* **cli:** add support for specifying type and size ([#122](https://github.com/libp2p/js-peer-id/issues/122)) ([8cd9dfb](https://github.com/libp2p/js-peer-id/commit/8cd9dfb))
<a name="0.13.11"></a>
## [0.13.11](https://github.com/libp2p/js-peer-id/compare/v0.13.10...v0.13.11) (2020-03-26)
<a name="0.13.10"></a>
## [0.13.10](https://github.com/libp2p/js-peer-id/compare/v0.13.9...v0.13.10) (2020-03-18)
### Bug Fixes
* add buffer ([#120](https://github.com/libp2p/js-peer-id/issues/120)) ([c305c36](https://github.com/libp2p/js-peer-id/commit/c305c36))
<a name="0.13.9"></a>
## [0.13.9](https://github.com/libp2p/js-peer-id/compare/v0.13.8...v0.13.9) (2020-02-19)
<a name="0.13.8"></a>
## [0.13.8](https://github.com/libp2p/js-peer-id/compare/v0.13.6...v0.13.8) (2020-02-18)
### Bug Fixes
* remove use of assert module ([#117](https://github.com/libp2p/js-peer-id/issues/117)) ([f44645e](https://github.com/libp2p/js-peer-id/commit/f44645e))
### Features
* adds typescript types + type tests ([#110](https://github.com/libp2p/js-peer-id/issues/110)) ([a5070ae](https://github.com/libp2p/js-peer-id/commit/a5070ae))
<a name="0.13.7"></a>
## [0.13.7](https://github.com/libp2p/js-peer-id/compare/v0.13.6...v0.13.7) (2020-01-27)

View File

@ -28,6 +28,7 @@
- [Node.js](#nodejs)
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
- [Browser: `<script>` Tag](#browser-script-tag)
- [CLI](#cli)
- [API](#api)
- [Create](#create)
- [`new PeerId(id[, privKey, pubKey])`](#new-peeridid-privkey-pubkey)
@ -117,6 +118,14 @@ the global namespace.
<script src="https://unpkg.com/peer-id/dist/index.js"></script>
```
# CLI
After installing `peer-id`, `npm install peer-id`, you can leverage the cli to generate keys exported as JSON. You can specify the type for the key and size, as detailed in [`create([opts])`](#createopts). The defaults are shown here.
```sh
> peer-id --type rsa --bits 2048
```
# API
```js
@ -137,7 +146,8 @@ 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: Object`: Default: `{bits: 2048, keyType: 'rsa'}`
- `opts.bits: number` - The size of the key. Default: `2048`
- `opts.keyType: string` - The key type, one of: `['rsa', 'ed25519', 'secp256k1']`. Default: `rsa`
Returns `Promise<PeerId>`.

View File

@ -1,6 +1,6 @@
{
"name": "peer-id",
"version": "0.13.7",
"version": "0.13.12",
"description": "IPFS Peer Id implementation in Node.js",
"leadMaintainer": "Vasco Santos <santos.vasco10@gmail.com>",
"main": "src/index.js",
@ -38,49 +38,49 @@
"devDependencies": {
"@types/chai": "^4.2.7",
"@types/dirty-chai": "^2.0.2",
"@types/mocha": "^5.2.7",
"aegir": "^20.0.0",
"@types/mocha": "^7.0.2",
"aegir": "^21.2.0",
"bundlesize": "~0.18.0",
"chai": "^4.2.0",
"dirty-chai": "^2.0.1"
},
"dependencies": {
"cids": "^0.7.3",
"buffer": "^5.5.0",
"cids": "^0.8.0",
"class-is": "^1.1.0",
"libp2p-crypto": "~0.17.2",
"libp2p-crypto": "~0.17.3",
"minimist": "^1.2.5",
"multihashes": "~0.4.15",
"protons": "^1.0.1"
"protons": "^1.0.2"
},
"repository": {
"type": "git",
"url": "https://github.com/libp2p/js-peer-id.git"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
"Vasco Santos <vasco.santos@moxy.studio>",
"nginnever <ginneversource@gmail.com>",
"dignifiedquire <dignifiedquire@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"Pedro Teixeira <i@pgte.me>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"Maciej Krüger <mkg20001@gmail.com>",
"Hugo Dias <hugomrdias@gmail.com>",
"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>",
"David Dias <daviddias.p@gmail.com>",
"David Dias <mail@daviddias.me>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Henrique Dias <hacdias@gmail.com>",
"Hugo Dias <hugomrdias@gmail.com>",
"Jacob Heun <jacobheun@gmail.com>",
"Maciej Krüger <mkg20001@gmail.com>",
"Marcin Rataj <lidel@lidel.org>",
"Michael Garvin <gar+gh@danger.computer>",
"Nate Foss <npfoss@gmail.com>",
"Pedro Teixeira <i@pgte.me>",
"Prashanth Chandra <coolshanth94@gmail.com>",
"Richard Littauer <richard.littauer@gmail.com>",
"Richard Schneider <makaretu@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"Topper Bowers <topper@quorumcontrol.com>",
"Vasco Santos <vasco.santos@moxy.studio>",
"Vasco Santos <vasco.santos@ua.pt>",
"Yahya <ya7yaz@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
"Alex Potsides <alex@achingbrain.net>"
]
}

View File

@ -3,9 +3,13 @@
'use strict'
const PeerId = require('./index.js')
const argv = require('minimist')(process.argv.slice(2))
async function main () {
const id = await PeerId.create()
const id = await PeerId.create({
keyType: argv.type,
bits: argv.bits
})
console.log(JSON.stringify(id.toJSON(), null, 2)) // eslint-disable-line no-console
}

4
src/index.d.ts vendored
View File

@ -38,7 +38,7 @@ declare namespace PeerId {
* Checks if a value is an instance of PeerId.
* @param id The value to check.
*/
function isPeerId(id: any): boolean
function isPeerId(id: any): id is PeerId
/**
* Create a new PeerId.
@ -105,7 +105,7 @@ declare class PeerId {
/**
* Raw id.
*/
id: Buffer;
readonly id: Buffer;
/**
* Private key.

View File

@ -4,19 +4,21 @@
'use strict'
const { Buffer } = require('buffer')
const mh = require('multihashes')
const CID = require('cids')
const cryptoKeys = require('libp2p-crypto/src/keys')
const assert = require('assert')
const withIs = require('class-is')
const { PeerIdProto } = require('./proto')
class PeerId {
constructor (id, privKey, pubKey) {
assert(Buffer.isBuffer(id), 'invalid id provided')
if (!Buffer.isBuffer(id)) {
throw new Error('invalid id provided')
}
if (privKey && pubKey) {
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
if (privKey && pubKey && !privKey.public.bytes.equals(pubKey.bytes)) {
throw new Error('inconsistent arguments')
}
this._id = id

View File

@ -2,6 +2,7 @@
/* eslint-env mocha */
'use strict'
const { Buffer } = require('buffer')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
chai.use(dirtyChai)
@ -62,6 +63,7 @@ describe('PeerId', () => {
const id = await PeerId.create(testOpts)
expect(id.toB58String().length).to.equal(46)
expect(() => {
// @ts-ignore
id.id = Buffer.from('hello')
}).to.throw(/immutable/)
})