mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-06 10:51:50 +00:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
020b963711 | |||
e3da29a440 | |||
8cd9dfb137 |
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,3 +1,13 @@
|
|||||||
|
<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>
|
<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)
|
## [0.13.11](https://github.com/libp2p/js-peer-id/compare/v0.13.10...v0.13.11) (2020-03-26)
|
||||||
|
|
||||||
|
12
README.md
12
README.md
@ -28,6 +28,7 @@
|
|||||||
- [Node.js](#nodejs)
|
- [Node.js](#nodejs)
|
||||||
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
|
- [Browser: Browserify, Webpack, other bundlers](#browser-browserify-webpack-other-bundlers)
|
||||||
- [Browser: `<script>` Tag](#browser-script-tag)
|
- [Browser: `<script>` Tag](#browser-script-tag)
|
||||||
|
- [CLI](#cli)
|
||||||
- [API](#api)
|
- [API](#api)
|
||||||
- [Create](#create)
|
- [Create](#create)
|
||||||
- [`new PeerId(id[, privKey, pubKey])`](#new-peeridid-privkey-pubkey)
|
- [`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>
|
<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
|
# API
|
||||||
|
|
||||||
```js
|
```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.
|
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>`.
|
Returns `Promise<PeerId>`.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peer-id",
|
"name": "peer-id",
|
||||||
"version": "0.13.11",
|
"version": "0.13.12",
|
||||||
"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",
|
||||||
@ -49,6 +49,7 @@
|
|||||||
"cids": "^0.8.0",
|
"cids": "^0.8.0",
|
||||||
"class-is": "^1.1.0",
|
"class-is": "^1.1.0",
|
||||||
"libp2p-crypto": "~0.17.3",
|
"libp2p-crypto": "~0.17.3",
|
||||||
|
"minimist": "^1.2.5",
|
||||||
"multihashes": "~0.4.15",
|
"multihashes": "~0.4.15",
|
||||||
"protons": "^1.0.2"
|
"protons": "^1.0.2"
|
||||||
},
|
},
|
||||||
|
@ -3,9 +3,13 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const PeerId = require('./index.js')
|
const PeerId = require('./index.js')
|
||||||
|
const argv = require('minimist')(process.argv.slice(2))
|
||||||
|
|
||||||
async function main () {
|
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
|
console.log(JSON.stringify(id.toJSON(), null, 2)) // eslint-disable-line no-console
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ describe('PeerId', () => {
|
|||||||
const id = await PeerId.create(testOpts)
|
const id = await PeerId.create(testOpts)
|
||||||
expect(id.toB58String().length).to.equal(46)
|
expect(id.toB58String().length).to.equal(46)
|
||||||
expect(() => {
|
expect(() => {
|
||||||
|
// @ts-ignore
|
||||||
id.id = Buffer.from('hello')
|
id.id = Buffer.from('hello')
|
||||||
}).to.throw(/immutable/)
|
}).to.throw(/immutable/)
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user