Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: keychain #631

Closed
wants to merge 112 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
4c8d147
Initial commit
daviddias Dec 6, 2017
49e6c47
chore: setup repo
daviddias Dec 6, 2017
1a96ae8
feat: move bits from https://github.com/richardschneider/ipfs-encryption
richardschneider Dec 6, 2017
658a4d7
docs: install and links
richardschneider Dec 6, 2017
409a999
fix: linting
richardschneider Dec 6, 2017
7c44c91
fix: more linting
richardschneider Dec 6, 2017
98ba68a
test: needs more time to generate RSA key
richardschneider Dec 6, 2017
569f963
test: temporarily disable webworker tests #3
richardschneider Dec 6, 2017
358c8c2
test: disable webworker
richardschneider Dec 6, 2017
99780ab
chore: ci coverage
richardschneider Dec 6, 2017
cfdd2f4
chore: publish coverage report
richardschneider Dec 6, 2017
643bcd4
Add syntax highlighting to README
mkg20001 Dec 6, 2017
506e1d7
Merge pull request #4 from libp2p/mkg20001-patch-1
richardschneider Dec 6, 2017
f49e753
fix: return info on removed key #10
richardschneider Dec 8, 2017
8305d20
fix: error message
richardschneider Dec 8, 2017
3b8d05a
docs(keychain): add API documentation
richardschneider Dec 9, 2017
f71d3a6
fix: maps an IPFS hash name to its forge equivalent
richardschneider Dec 10, 2017
ff4f656
fix: lint errors
richardschneider Dec 10, 2017
06917f7
fix: lint errors
richardschneider Dec 10, 2017
2dd069b
test: importing openssl keys
richardschneider Dec 10, 2017
1b2664a
refactor: keep the key info in the store
richardschneider Dec 11, 2017
ee9dbeb
Updating CI files
victorb Dec 14, 2017
b4518e0
Merge pull request #15 from libp2p/automatic-ci-script-update
richardschneider Dec 16, 2017
9129d20
docs: correct hash name
richardschneider Dec 16, 2017
97bf98f
Merge pull request #13 from libp2p/ds-keyinfo
richardschneider Dec 16, 2017
e78b248
test: key name comparision
richardschneider Dec 16, 2017
3b7c691
test(openssl): verify key id
richardschneider Dec 17, 2017
605d290
Merge pull request #17 from libp2p/filenames
richardschneider Dec 19, 2017
c1627a9
feat: use libp2p-crypto (#18)
richardschneider Dec 20, 2017
5343b0f
chore: update deps
daviddias Dec 20, 2017
21611e4
chore: update contributors
daviddias Dec 20, 2017
de15d12
chore: release version v0.2.0
daviddias Dec 20, 2017
89a451c
feat: generate unique options for a key chain (#20)
richardschneider Dec 28, 2017
849a7c7
chore: update contributors
daviddias Dec 28, 2017
6a84873
chore: release version v0.2.1
daviddias Dec 28, 2017
1e276f6
chore: update deps
daviddias Jan 29, 2018
2ce4444
fix: deepmerge 2.0.1 fails in browser, stay with 1.5.2
richardschneider Jan 29, 2018
3816b82
chore: update contributors
daviddias Jan 29, 2018
acf48a8
chore: release version v0.3.0
daviddias Jan 29, 2018
5560669
CMS - PKCS #7 (#19)
richardschneider Jan 29, 2018
486e54b
chore: update contributors
daviddias Jan 29, 2018
ee978a5
chore: release version v0.3.1
daviddias Jan 29, 2018
974c507
docs: add lead-maintainer
vasco-santos Jun 25, 2018
0065b0a
chore: fix out of date npms (#21)
camelmasa Jun 29, 2018
73d4530
chore: update deps
daviddias Jun 30, 2018
f95fef4
chore: use lodash main dependency
vasco-santos Jul 3, 2018
8dfaab1
fix: validate createKey params properly (#26)
alanshaw Sep 18, 2018
65129bf
chore: update contributors
vasco-santos Sep 18, 2018
5d3f489
chore: release version v0.3.2
vasco-santos Sep 18, 2018
24d4374
chore: upgrade dependencies (#27)
vasco-santos Oct 25, 2018
571c81a
chore: update contributors
vasco-santos Oct 25, 2018
251e0b8
chore: release version v0.3.3
vasco-santos Oct 25, 2018
17268d5
chore: update dependencies (#29)
vasco-santos Jan 4, 2019
a753b1c
chore: update contributors
vasco-santos Jan 4, 2019
4b895cf
chore: release version v0.3.4
vasco-santos Jan 4, 2019
7eeed87
fix: reduce bundle size (#28)
hugomrdias Jan 10, 2019
5cbded5
chore: update contributors
vasco-santos Jan 10, 2019
4dd2ad3
chore: release version v0.3.5
vasco-santos Jan 10, 2019
18357e6
Merge branch 'master' of github.com:libp2p/js-libp2p-keychain
vasco-santos Jan 10, 2019
eaf6a88
chore: update contributors
vasco-santos Jan 10, 2019
aa5a6cb
chore: release version v0.3.6
vasco-santos Jan 10, 2019
3779bd0
chore: use travis (#32)
vasco-santos Feb 18, 2019
9eb11f4
feat: adds support for ed25199 and secp256k1 (#31)
AlbertoElias Feb 25, 2019
217cfd3
chore: update libp2p-crypto (#33)
AlbertoElias Feb 26, 2019
267002f
chore: update contributors
vasco-santos Feb 26, 2019
e30330e
chore: release version v0.4.0
vasco-santos Feb 26, 2019
f71a6bb
Revert "feat: adds support for ed25199 and secp256k1 (#31)"
vasco-santos Mar 14, 2019
4e4d3d4
chore: update contributors
vasco-santos Mar 14, 2019
a5fd967
chore: release version v0.4.1
vasco-santos Mar 14, 2019
ef47374
chore: add discourse badge (#34)
vasco-santos Apr 11, 2019
7051b9c
fix: throw errors with correct stack trace (#35)
achingbrain Jun 13, 2019
74cb4d4
chore: update contributors
vasco-santos Jun 13, 2019
717112b
chore: release version v0.4.2
vasco-santos Jun 13, 2019
dda315a
refactor: use async/await instead of callbacks (#37)
jacobheun Aug 16, 2019
e375c2f
chore: update contributors
vasco-santos Aug 16, 2019
ad37817
chore: release version v0.5.0
vasco-santos Aug 16, 2019
893a2c9
chore: downgrade peer-id to same version used by libp2p (#38)
achingbrain Sep 25, 2019
b9eb9d7
chore: update contributors
vasco-santos Sep 25, 2019
ce8c412
chore: release version v0.5.1
vasco-santos Sep 25, 2019
8de9681
chore: update node-forge dependency (#39)
alanshaw Dec 2, 2019
ff6bd50
chore: update contributors
vasco-santos Dec 2, 2019
163edbb
chore: release version v0.5.2
vasco-santos Dec 2, 2019
b6d5313
chore: update deps (#40)
alanshaw Dec 18, 2019
8ff68d1
chore: update contributors
vasco-santos Dec 18, 2019
be63323
chore: release version v0.5.3
vasco-santos Dec 18, 2019
6b9516c
Revert "chore: update deps (#40)"
vasco-santos Dec 18, 2019
66c1fb3
chore: update contributors
vasco-santos Dec 18, 2019
0d13a8b
chore: release version v0.5.4
vasco-santos Dec 18, 2019
464fcbe
chore: update deps (#40)
alanshaw Dec 18, 2019
24e10f3
chore: update contributors
vasco-santos Dec 18, 2019
44a1e7c
chore: release version v0.6.0
vasco-santos Dec 18, 2019
55fb5d5
chore(deps-dev): bump aegir from 20.6.1 to 21.2.0 (#44)
dependabot-preview[bot] Feb 20, 2020
be45fc4
feat: address and proto books (#590)
vasco-santos Apr 9, 2020
54212cb
chore: deprecate old peer store api (#598)
vasco-santos Apr 16, 2020
0f6e878
chore: remove peer-info usage
vasco-santos Apr 14, 2020
984d933
chore: apply suggestions from code review
vasco-santos Apr 24, 2020
8723388
chore: rename peer-store properties
vasco-santos Apr 24, 2020
7627f96
chore: use kad-dht with renamed peer-store properties
vasco-santos Apr 27, 2020
a55a4dc
chore: refactor connection manager and registrar
vasco-santos Apr 18, 2020
e87b42b
chore: apply suggestions from code review
vasco-santos Apr 27, 2020
7e76d0f
feat: address manager
vasco-santos Apr 18, 2020
4e4a998
chore: update api docs
vasco-santos Apr 25, 2020
fd618b6
chore(deps-dev): bump datastore-level from 0.14.1 to 1.0.0
dependabot-preview[bot] Apr 28, 2020
21b39eb
chore: rename address functions and apply suggestions from code review
vasco-santos Apr 28, 2020
e72a5b0
chore(deps-dev): bump datastore-level from 0.14.1 to 1.0.0
vasco-santos Apr 29, 2020
9e96dbc
chore(deps-dev): bump datastore-fs from 0.9.1 to 1.0.0 (#46)
dependabot-preview[bot] Apr 29, 2020
d9fd726
chore: move to libp2p
vasco-santos Apr 29, 2020
0b260e9
Merge branch 'master' of ../js-libp2p-keychain into feat/keychain
vasco-santos Apr 29, 2020
9d54730
chore: merge 0.28x updates
vasco-santos May 1, 2020
b1a2b8a
Merge branch '0.28.x' into feat/keychain
vasco-santos May 7, 2020
c0bbda2
chore: merge 0.28x updates
vasco-santos May 7, 2020
c9d776a
feat: keychain in libp2p
vasco-santos May 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const after = async () => {
}

module.exports = {
bundlesize: { maxSize: '185kB' },
bundlesize: { maxSize: '200kB' },
hooks: {
pre: before,
post: after
Expand Down
345 changes: 344 additions & 1 deletion doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
* [`connectionManager.get`](#connectionmanagerget)
* [`connectionManager.setPeerValue`](#connectionmanagersetpeervalue)
* [`connectionManager.size`](#connectionmanagersize)
* [`keychain.createKey`](#keychaincreatekey)
* [`keychain.renameKey`](#keychainrenamekey)
* [`keychain.removeKey`](#keychainremovekey)
* [`keychain.exportKey`](#keychainexportkey)
* [`keychain.importKey`](#keychainimportkey)
* [`keychain.importPeer`](#keychainimportpeer)
* [`keychain.list`](#keychainlist)
* [`keychain.findById`](#keychainfindbyid)
* [`keychain.findByName`](#keychainfindbyname)
* [`keychain.cms.encrypt`](#keychaincmsencrypt)
* [`keychain.cms.decrypt`](#keychaincmsdecrypt)
* [`metrics.global`](#metricsglobal)
* [`metrics.peers`](#metricspeers)
* [`metrics.protocols`](#metricsprotocols)
Expand Down Expand Up @@ -75,7 +86,8 @@ Creates an instance of Libp2p.
| [options.connectionManager] | `object` | libp2p Connection Manager configuration |
| [options.datastore] | `object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
| [options.dialer] | `object` | libp2p Dialer configuration
| [options.metrics] | `object` | libp2p Metrics configuration
| [options.keychain] | [`object`](./CONFIGURATION.md#setup-with-keychain) | libp2p Keychain configuration |
| [options.metrics] | `object` | libp2p Metrics configuration |
| [options.peerId] | [`PeerId`][peer-id] | peerId instance (it will be created if not provided) |
| [options.peerStore] | `object` | libp2p PeerStore configuration |

Expand Down Expand Up @@ -470,6 +482,65 @@ const listenMa = libp2p.transportManager.getAddrs()
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
```

### addressManager.getAnnounceAddrs

Get the multiaddrs that were provided to announce to the network.

`libp2p.addressManager.getAnnounceAddrs()`

#### Returns

| Type | Description |
|------|-------------|
| `Array<Multiaddr>` | Provided announce multiaddrs |

#### Example

```js
// ...
const announceMa = libp2p.addressManager.getAnnounceAddrs()
// [ <Multiaddr 047f00000106f9ba - /dns4/peer.io/...> ]
```

### addressManager.getNoAnnounceAddrs

Get the multiaddrs that were provided to not announce to the network.

`libp2p.addressManager.getNoAnnounceAddrs()`

#### Returns

| Type | Description |
|------|-------------|
| `Array<Multiaddr>` | Provided noAnnounce multiaddrs |

#### Example

```js
// ...
const noAnnounceMa = libp2p.addressManager.getNoAnnounceAddrs()
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
```

### transportManager.getAddrs

Get the multiaddrs that libp2p transports are using to listen on.

`libp2p.transportManager.getAddrs()`

#### Returns

| Type | Description |
|------|-------------|
| `Array<Multiaddr>` | listening multiaddrs |

#### Example

```js
// ...
const listenMa = libp2p.transportManager.getAddrs()
// [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole added block already exists, this is adding duplicate data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this should also fix the formatting below as it isn't properly closing the code blocks

### contentRouting.findProviders

Iterates over all content routers in series to find providers of the given key.
Expand Down Expand Up @@ -1254,6 +1325,278 @@ libp2p.connectionManager.size
// 10
```

### keychain.createKey

Create a key in the keychain.

`libp2p.keychain.createKey(name, type, size)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The local key name. It cannot already exist. |
| type | `string` | One of the key types; 'rsa' |
| size | `number` | The key size in bits. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
const keyInfo = await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
```

### keychain.renameKey

Rename a key in the keychain.

`libp2p.keychain.renameKey(oldName, newName)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The old local key name. It must already exist. |
| type | `string` | The new local key name. It must not already exist. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const keyInfo = await libp2p.keychain.renameKey('keyTest', 'keyNewNtest')
```

### keychain.removeKey

Removes a key from the keychain.

`libp2p.keychain.removeKey(name)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The local key name. It must already exist. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const keyInfo = await libp2p.keychain.removeKey('keyTest')
```

### keychain.exportKey

Export an existing key as a PEM encrypted PKCS #8 string.

`libp2p.keychain.exportKey(name, password)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The local key name. It must already exist. |
| password | `string` | The password to use. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<string>` | Key as a PEM encrypted PKCS #8 |

#### Example

```js
await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const pemKey = await libp2p.keychain.exportKey('keyTest', 'password123')
```

### keychain.importKey

Import a new key from a PEM encoded PKCS #8 string.

`libp2p.keychain.importKey(name, pem, password)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The local key name. It must not exist. |
| pem | `string` | The PEM encoded PKCS #8 string. |
| password | `string` | The password to use. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const pemKey = await libp2p.keychain.exportKey('keyTest', 'password123')
const keyInfo = await libp2p.keychain.importKey('keyTestImport', pemKey, 'password123')
```

### keychain.importPeer

Import a new key from a PeerId.

`libp2p.keychain.importPeer(name, peerId)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The local key name. It must not exist. |
| peerId | ['PeerId'][peer-id] | The PEM encoded PKCS #8 string. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
const keyInfo = await libp2p.keychain.importPeer('keyTestImport', peerId)
```

### keychain.list

List all the keys.

`libp2p.keychain.list()`

#### Returns

| Type | Description |
|------|-------------|
| `Promise<Array<{ id, name }>>` | Array of Key info |

#### Example

```js
const keyInfos = await libp2p.keychain.list()
```

### keychain.findById

Find a key by it's id.

`libp2p.keychain.findById(id)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| id | `string` | The universally unique key identifier. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
const keyInfo = await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const keyInfo2 = await libp2p.keychain.findById(keyInfo.id)
```

### keychain.findByName

Find a key by it's name.

`libp2p.keychain.findByName(id)`

#### Parameters

| Name | Type | Description |
|------|------|-------------|
| id | `string` | The local key name. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<{ id, name }>` | Key info object |

#### Example

```js
const keyInfo = await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const keyInfo2 = await libp2p.keychain.findByName('keyTest')
```

### keychain.cms.encrypt

Encrypt protected data using the Cryptographic Message Syntax (CMS).

`libp2p.keychain.cms.encrypt(name, data)`

| Name | Type | Description |
|------|------|-------------|
| name | `string` | The local key name. |
| data | `Buffer` | The data to encrypt. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<Buffer>` | Encrypted data as a PKCS #7 message in DER. |

#### Example

```js
const keyInfo = await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const enc = await libp2p.keychain.cms.encrypt('keyTest', Buffer.from('data'))
```

### keychain.cms.decrypt

Decrypt protected data using the Cryptographic Message Syntax (CMS).
The keychain must contain one of the keys used to encrypt the data. If none of the keys exists, an Error is returned with the property 'missingKeys'.

`libp2p.keychain.cms.decrypt(cmsData)`

| Name | Type | Description |
|------|------|-------------|
| cmsData | `string` | The CMS encrypted data to decrypt. |

#### Returns

| Type | Description |
|------|-------------|
| `Promise<Buffer>` | Decrypted data. |

#### Example

```js
const keyInfo = await libp2p.keychain.createKey('keyTest', 'rsa', 4096)
const enc = await libp2p.keychain.cms.encrypt('keyTest', Buffer.from('data'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an encrypt example, but this section is decrypt

```

### metrics.global

A [`Stats`](#stats) object of tracking the global bandwidth of the libp2p node.
Expand Down
Loading