mirror of
https://github.com/fluencelabs/js-peer-id
synced 2025-07-04 23:41:48 +00:00
Compare commits
25 Commits
Author | SHA1 | Date | |
---|---|---|---|
cd99cb2c7d | |||
c295329300 | |||
bb32b12395 | |||
6fd5ca2a12 | |||
020b963711 | |||
e3da29a440 | |||
8cd9dfb137 | |||
3598a433dc | |||
5ec88281e2 | |||
a80c481146 | |||
efc96106a4 | |||
16e1c74e9a | |||
c305c36b26 | |||
7e985b127f | |||
40d68cb512 | |||
1d86506c64 | |||
9dc7ce5f5e | |||
f775e3509b | |||
00819ba4eb | |||
6870c8c4d7 | |||
71d3a100c9 | |||
f44645ef7e | |||
a68855a5d2 | |||
d8c307a44f | |||
a5070aea6e |
60
CHANGELOG.md
60
CHANGELOG.md
@ -1,3 +1,63 @@
|
|||||||
|
<a name="0.13.13"></a>
|
||||||
|
## [0.13.13](https://github.com/libp2p/js-peer-id/compare/v0.13.12...v0.13.13) (2020-06-23)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<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)
|
||||||
|
|
||||||
|
|
||||||
|
### 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.6"></a>
|
<a name="0.13.6"></a>
|
||||||
## [0.13.6](https://github.com/libp2p/js-peer-id/compare/v0.13.5...v0.13.6) (2019-12-18)
|
## [0.13.6](https://github.com/libp2p/js-peer-id/compare/v0.13.5...v0.13.6) (2019-12-18)
|
||||||
|
|
||||||
|
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>`.
|
||||||
|
|
||||||
|
54
package.json
54
package.json
@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "peer-id",
|
"name": "peer-id",
|
||||||
"version": "0.13.6",
|
"version": "0.13.13",
|
||||||
"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",
|
||||||
|
"types": "src/index.d.ts",
|
||||||
"bin": "src/bin.js",
|
"bin": "src/bin.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "aegir lint",
|
"lint": "aegir lint",
|
||||||
@ -11,6 +12,7 @@
|
|||||||
"test": "aegir test",
|
"test": "aegir test",
|
||||||
"test:node": "aegir test -t node",
|
"test:node": "aegir test -t node",
|
||||||
"test:browser": "aegir test -t browser -t webworker",
|
"test:browser": "aegir test -t browser -t webworker",
|
||||||
|
"test:types": "npx tsc",
|
||||||
"release": "aegir release",
|
"release": "aegir release",
|
||||||
"release-minor": "aegir release --type minor",
|
"release-minor": "aegir release --type minor",
|
||||||
"release-major": "aegir release --type major",
|
"release-major": "aegir release --type major",
|
||||||
@ -34,47 +36,51 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/libp2p/js-peer-id",
|
"homepage": "https://github.com/libp2p/js-peer-id",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"aegir": "^20.0.0",
|
"@types/chai": "^4.2.7",
|
||||||
|
"@types/dirty-chai": "^2.0.2",
|
||||||
|
"@types/mocha": "^7.0.2",
|
||||||
|
"aegir": "^22.0.0",
|
||||||
"bundlesize": "~0.18.0",
|
"bundlesize": "~0.18.0",
|
||||||
"chai": "^4.2.0",
|
"chai": "^4.2.0",
|
||||||
"dirty-chai": "^2.0.1"
|
"dirty-chai": "^2.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cids": "~0.7.1",
|
"buffer": "^5.5.0",
|
||||||
|
"cids": "^0.8.0",
|
||||||
"class-is": "^1.1.0",
|
"class-is": "^1.1.0",
|
||||||
"libp2p-crypto": "~0.17.0",
|
"libp2p-crypto": "^0.17.7",
|
||||||
"multihashes": "~0.4.15",
|
"minimist": "^1.2.5",
|
||||||
"protons": "^1.0.1"
|
"multihashes": "^1.0.1",
|
||||||
|
"protons": "^1.0.2"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/libp2p/js-peer-id.git"
|
"url": "https://github.com/libp2p/js-peer-id.git"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Arve Knudsen <arve.knudsen@gmail.com>",
|
|
||||||
"Christian Paul <info@jaller.de>",
|
|
||||||
"David Dias <daviddias.p@gmail.com>",
|
"David Dias <daviddias.p@gmail.com>",
|
||||||
"David Dias <mail@daviddias.me>",
|
"Vasco Santos <vasco.santos@moxy.studio>",
|
||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"nginnever <ginneversource@gmail.com>",
|
||||||
"Henrique Dias <hacdias@gmail.com>",
|
"dignifiedquire <dignifiedquire@gmail.com>",
|
||||||
"Hugo Dias <hugomrdias@gmail.com>",
|
|
||||||
"Jacob Heun <jacobheun@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>",
|
"Pedro Teixeira <i@pgte.me>",
|
||||||
"Prashanth Chandra <coolshanth94@gmail.com>",
|
"Stephen Whitmore <stephen.whitmore@gmail.com>",
|
||||||
|
"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>",
|
||||||
|
"Michael Garvin <gar+gh@danger.computer>",
|
||||||
"Richard Littauer <richard.littauer@gmail.com>",
|
"Richard Littauer <richard.littauer@gmail.com>",
|
||||||
"Richard Schneider <makaretu@gmail.com>",
|
"Richard Schneider <makaretu@gmail.com>",
|
||||||
"Stephen Whitmore <stephen.whitmore@gmail.com>",
|
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
||||||
|
"Marcin Rataj <lidel@lidel.org>",
|
||||||
"Topper Bowers <topper@quorumcontrol.com>",
|
"Topper Bowers <topper@quorumcontrol.com>",
|
||||||
"Vasco Santos <vasco.santos@moxy.studio>",
|
"Henrique Dias <hacdias@gmail.com>",
|
||||||
"Vasco Santos <vasco.santos@ua.pt>",
|
|
||||||
"Yahya <ya7yaz@gmail.com>",
|
"Yahya <ya7yaz@gmail.com>",
|
||||||
"greenkeeperio-bot <support@greenkeeper.io>",
|
"Christian Paul <info@jaller.de>",
|
||||||
"nginnever <ginneversource@gmail.com>",
|
"Carson Farmer <carson.farmer@gmail.com>",
|
||||||
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>",
|
"Arve Knudsen <arve.knudsen@gmail.com>",
|
||||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>"
|
"Prashanth Chandra <coolshanth94@gmail.com>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
188
src/index.d.ts
vendored
Normal file
188
src/index.d.ts
vendored
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
import crypto, { PrivateKey, PublicKey, KeyType } from "libp2p-crypto";
|
||||||
|
import CID from 'cids'
|
||||||
|
|
||||||
|
declare namespace PeerId {
|
||||||
|
/**
|
||||||
|
* Options for PeerId creation.
|
||||||
|
*/
|
||||||
|
type CreateOptions = {
|
||||||
|
/**
|
||||||
|
* The number of bits to use.
|
||||||
|
*/
|
||||||
|
bits?: number;
|
||||||
|
/**
|
||||||
|
* The type of key to use.
|
||||||
|
*/
|
||||||
|
keyType?: KeyType;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PeerId JSON format.
|
||||||
|
*/
|
||||||
|
type JSONPeerId = {
|
||||||
|
/**
|
||||||
|
* String representation of PeerId.
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* Public key.
|
||||||
|
*/
|
||||||
|
pubKey?: string;
|
||||||
|
/**
|
||||||
|
* Private key.
|
||||||
|
*/
|
||||||
|
privKey: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a value is an instance of PeerId.
|
||||||
|
* @param id The value to check.
|
||||||
|
*/
|
||||||
|
function isPeerId(id: any): id is PeerId
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new PeerId.
|
||||||
|
* @param opts Options.
|
||||||
|
*/
|
||||||
|
function create(opts?: PeerId.CreateOptions): Promise<PeerId>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from hex string.
|
||||||
|
* @param str The input hex string.
|
||||||
|
*/
|
||||||
|
function createFromHexString(str: string): PeerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from raw bytes.
|
||||||
|
* @param buf The raw bytes.
|
||||||
|
*/
|
||||||
|
function createFromBytes(buf: Buffer): PeerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from base58-encoded string.
|
||||||
|
* @param str The base58-encoded string.
|
||||||
|
*/
|
||||||
|
function createFromB58String(str: string): PeerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from CID.
|
||||||
|
* @param cid The CID.
|
||||||
|
*/
|
||||||
|
function createFromCID(cid: CID | Buffer | string | object): PeerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from public key.
|
||||||
|
* @param key Public key, as Buffer or base64-encoded string.
|
||||||
|
*/
|
||||||
|
function createFromPubKey(key: Buffer | string): Promise<PeerId>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from private key.
|
||||||
|
* @param key Private key, as Buffer or base64-encoded string.
|
||||||
|
*/
|
||||||
|
function createFromPrivKey(key: Buffer | string): Promise<PeerId>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from PeerId JSON formatted object.
|
||||||
|
* @see {@link PeerId#toJSON}
|
||||||
|
* @param json PeerId in JSON format.
|
||||||
|
*/
|
||||||
|
function createFromJSON(json: JSONPeerId): Promise<PeerId>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create PeerId from Protobuf bytes.
|
||||||
|
* @param buf Protobuf bytes, as Buffer or hex-encoded string.
|
||||||
|
*/
|
||||||
|
function createFromProtobuf(buf: Buffer | string): Promise<PeerId>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PeerId is an object representation of a peer identifier.
|
||||||
|
*/
|
||||||
|
declare class PeerId {
|
||||||
|
constructor(id: Buffer | string, privKey?: PrivateKey, pubKey?: PublicKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Raw id.
|
||||||
|
*/
|
||||||
|
readonly id: Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private key.
|
||||||
|
*/
|
||||||
|
privKey: PrivateKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public key.
|
||||||
|
*/
|
||||||
|
pubKey: PublicKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the protobuf version of the public key, matching go ipfs formatting.
|
||||||
|
*/
|
||||||
|
marshalPubKey(): Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the protobuf version of the private key, matching go ipfs formatting.
|
||||||
|
*/
|
||||||
|
marshalPrivKey(): Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the protobuf version of the peer-id.
|
||||||
|
* @param excludePriv Whether to exclude the private key information from the output.
|
||||||
|
*/
|
||||||
|
marshal(excludePriv?: boolean): Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String representation.
|
||||||
|
*/
|
||||||
|
toPrint(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the jsonified version of the key.
|
||||||
|
* Matches the formatting of go-ipfs for its config file.
|
||||||
|
* @see {@link PeerId.createFromJSON}
|
||||||
|
*/
|
||||||
|
toJSON(): PeerId.JSONPeerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode to hex.
|
||||||
|
*/
|
||||||
|
toHexString(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return raw id bytes.
|
||||||
|
*/
|
||||||
|
toBytes(): Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode to base58 string.
|
||||||
|
*/
|
||||||
|
toB58String(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return self-describing string representation.
|
||||||
|
* Uses default format from RFC 0001: https://github.com/libp2p/specs/pull/209
|
||||||
|
*/
|
||||||
|
toString(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the equality of `this` peer against a given PeerId.
|
||||||
|
* @param id The other PeerId.
|
||||||
|
*/
|
||||||
|
equals(id: PeerId | Buffer): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the equality of `this` peer against a given PeerId.
|
||||||
|
* @deprecated Use {.equals}
|
||||||
|
* @param id The other PeerId.
|
||||||
|
*/
|
||||||
|
isEqual(id: PeerId | Buffer): boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if this PeerId instance is valid (privKey -> pubKey -> Id)
|
||||||
|
*/
|
||||||
|
isValid(): boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export = PeerId;
|
10
src/index.js
10
src/index.js
@ -4,19 +4,21 @@
|
|||||||
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { Buffer } = require('buffer')
|
||||||
const mh = require('multihashes')
|
const mh = require('multihashes')
|
||||||
const CID = require('cids')
|
const CID = require('cids')
|
||||||
const cryptoKeys = require('libp2p-crypto/src/keys')
|
const cryptoKeys = require('libp2p-crypto/src/keys')
|
||||||
const assert = require('assert')
|
|
||||||
const withIs = require('class-is')
|
const withIs = require('class-is')
|
||||||
const { PeerIdProto } = require('./proto')
|
const { PeerIdProto } = require('./proto')
|
||||||
|
|
||||||
class PeerId {
|
class PeerId {
|
||||||
constructor (id, privKey, pubKey) {
|
constructor (id, privKey, pubKey) {
|
||||||
assert(Buffer.isBuffer(id), 'invalid id provided')
|
if (!Buffer.isBuffer(id)) {
|
||||||
|
throw new Error('invalid id provided')
|
||||||
|
}
|
||||||
|
|
||||||
if (privKey && pubKey) {
|
if (privKey && pubKey && !privKey.public.bytes.equals(pubKey.bytes)) {
|
||||||
assert(privKey.public.bytes.equals(pubKey.bytes), 'inconsistent arguments')
|
throw new Error('inconsistent arguments')
|
||||||
}
|
}
|
||||||
|
|
||||||
this._id = id
|
this._id = id
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
/* eslint-env mocha */
|
/* eslint-env mocha */
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { Buffer } = require('buffer')
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const dirtyChai = require('dirty-chai')
|
const dirtyChai = require('dirty-chai')
|
||||||
chai.use(dirtyChai)
|
chai.use(dirtyChai)
|
||||||
@ -62,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/)
|
||||||
})
|
})
|
||||||
@ -271,24 +273,28 @@ describe('PeerId', () => {
|
|||||||
|
|
||||||
it('set privKey (valid)', async () => {
|
it('set privKey (valid)', async () => {
|
||||||
const peerId = await PeerId.create(testOpts)
|
const peerId = await PeerId.create(testOpts)
|
||||||
|
// @ts-ignore
|
||||||
peerId.privKey = peerId._privKey
|
peerId.privKey = peerId._privKey
|
||||||
expect(peerId.isValid()).to.equal(true)
|
expect(peerId.isValid()).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('set pubKey (valid)', async () => {
|
it('set pubKey (valid)', async () => {
|
||||||
const peerId = await PeerId.create(testOpts)
|
const peerId = await PeerId.create(testOpts)
|
||||||
|
// @ts-ignore
|
||||||
peerId.pubKey = peerId._pubKey
|
peerId.pubKey = peerId._pubKey
|
||||||
expect(peerId.isValid()).to.equal(true)
|
expect(peerId.isValid()).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('set privKey (invalid)', async () => {
|
it('set privKey (invalid)', async () => {
|
||||||
const peerId = await PeerId.create(testOpts)
|
const peerId = await PeerId.create(testOpts)
|
||||||
|
// @ts-ignore
|
||||||
peerId.privKey = Buffer.from('bufff')
|
peerId.privKey = Buffer.from('bufff')
|
||||||
expect(peerId.isValid()).to.equal(false)
|
expect(peerId.isValid()).to.equal(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('set pubKey (invalid)', async () => {
|
it('set pubKey (invalid)', async () => {
|
||||||
const peerId = await PeerId.create(testOpts)
|
const peerId = await PeerId.create(testOpts)
|
||||||
|
// @ts-ignore
|
||||||
peerId.pubKey = Buffer.from('bufff')
|
peerId.pubKey = Buffer.from('bufff')
|
||||||
expect(peerId.isValid()).to.equal(false)
|
expect(peerId.isValid()).to.equal(false)
|
||||||
})
|
})
|
||||||
|
37
tsconfig.json
Normal file
37
tsconfig.json
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": [
|
||||||
|
"es6"
|
||||||
|
],
|
||||||
|
"target": "ES5",
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"noImplicitThis": true,
|
||||||
|
"strictFunctionTypes": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"allowJs": true,
|
||||||
|
"checkJs": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"peer-id": [
|
||||||
|
"./src",
|
||||||
|
"../src",
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"types": [
|
||||||
|
"node",
|
||||||
|
"mocha",
|
||||||
|
"chai"
|
||||||
|
],
|
||||||
|
"noEmit": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"./src/index.d.ts",
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"./test/**/*.spec.js"
|
||||||
|
]
|
||||||
|
}
|
Reference in New Issue
Block a user