-
Notifications
You must be signed in to change notification settings - Fork 453
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
Closed
feat: keychain #631
Changes from all commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
4c8d147
Initial commit
daviddias 49e6c47
chore: setup repo
daviddias 1a96ae8
feat: move bits from https://github.com/richardschneider/ipfs-encryption
richardschneider 658a4d7
docs: install and links
richardschneider 409a999
fix: linting
richardschneider 7c44c91
fix: more linting
richardschneider 98ba68a
test: needs more time to generate RSA key
richardschneider 569f963
test: temporarily disable webworker tests #3
richardschneider 358c8c2
test: disable webworker
richardschneider 99780ab
chore: ci coverage
richardschneider cfdd2f4
chore: publish coverage report
richardschneider 643bcd4
Add syntax highlighting to README
mkg20001 506e1d7
Merge pull request #4 from libp2p/mkg20001-patch-1
richardschneider f49e753
fix: return info on removed key #10
richardschneider 8305d20
fix: error message
richardschneider 3b8d05a
docs(keychain): add API documentation
richardschneider f71d3a6
fix: maps an IPFS hash name to its forge equivalent
richardschneider ff4f656
fix: lint errors
richardschneider 06917f7
fix: lint errors
richardschneider 2dd069b
test: importing openssl keys
richardschneider 1b2664a
refactor: keep the key info in the store
richardschneider ee9dbeb
Updating CI files
victorb b4518e0
Merge pull request #15 from libp2p/automatic-ci-script-update
richardschneider 9129d20
docs: correct hash name
richardschneider 97bf98f
Merge pull request #13 from libp2p/ds-keyinfo
richardschneider e78b248
test: key name comparision
richardschneider 3b7c691
test(openssl): verify key id
richardschneider 605d290
Merge pull request #17 from libp2p/filenames
richardschneider c1627a9
feat: use libp2p-crypto (#18)
richardschneider 5343b0f
chore: update deps
daviddias 21611e4
chore: update contributors
daviddias de15d12
chore: release version v0.2.0
daviddias 89a451c
feat: generate unique options for a key chain (#20)
richardschneider 849a7c7
chore: update contributors
daviddias 6a84873
chore: release version v0.2.1
daviddias 1e276f6
chore: update deps
daviddias 2ce4444
fix: deepmerge 2.0.1 fails in browser, stay with 1.5.2
richardschneider 3816b82
chore: update contributors
daviddias acf48a8
chore: release version v0.3.0
daviddias 5560669
CMS - PKCS #7 (#19)
richardschneider 486e54b
chore: update contributors
daviddias ee978a5
chore: release version v0.3.1
daviddias 974c507
docs: add lead-maintainer
vasco-santos 0065b0a
chore: fix out of date npms (#21)
camelmasa 73d4530
chore: update deps
daviddias f95fef4
chore: use lodash main dependency
vasco-santos 8dfaab1
fix: validate createKey params properly (#26)
65129bf
chore: update contributors
vasco-santos 5d3f489
chore: release version v0.3.2
vasco-santos 24d4374
chore: upgrade dependencies (#27)
vasco-santos 571c81a
chore: update contributors
vasco-santos 251e0b8
chore: release version v0.3.3
vasco-santos 17268d5
chore: update dependencies (#29)
vasco-santos a753b1c
chore: update contributors
vasco-santos 4b895cf
chore: release version v0.3.4
vasco-santos 7eeed87
fix: reduce bundle size (#28)
hugomrdias 5cbded5
chore: update contributors
vasco-santos 4dd2ad3
chore: release version v0.3.5
vasco-santos 18357e6
Merge branch 'master' of github.com:libp2p/js-libp2p-keychain
vasco-santos eaf6a88
chore: update contributors
vasco-santos aa5a6cb
chore: release version v0.3.6
vasco-santos 3779bd0
chore: use travis (#32)
vasco-santos 9eb11f4
feat: adds support for ed25199 and secp256k1 (#31)
AlbertoElias 217cfd3
chore: update libp2p-crypto (#33)
AlbertoElias 267002f
chore: update contributors
vasco-santos e30330e
chore: release version v0.4.0
vasco-santos f71a6bb
Revert "feat: adds support for ed25199 and secp256k1 (#31)"
vasco-santos 4e4d3d4
chore: update contributors
vasco-santos a5fd967
chore: release version v0.4.1
vasco-santos ef47374
chore: add discourse badge (#34)
vasco-santos 7051b9c
fix: throw errors with correct stack trace (#35)
achingbrain 74cb4d4
chore: update contributors
vasco-santos 717112b
chore: release version v0.4.2
vasco-santos dda315a
refactor: use async/await instead of callbacks (#37)
jacobheun e375c2f
chore: update contributors
vasco-santos ad37817
chore: release version v0.5.0
vasco-santos 893a2c9
chore: downgrade peer-id to same version used by libp2p (#38)
achingbrain b9eb9d7
chore: update contributors
vasco-santos ce8c412
chore: release version v0.5.1
vasco-santos 8de9681
chore: update node-forge dependency (#39)
ff6bd50
chore: update contributors
vasco-santos 163edbb
chore: release version v0.5.2
vasco-santos b6d5313
chore: update deps (#40)
8ff68d1
chore: update contributors
vasco-santos be63323
chore: release version v0.5.3
vasco-santos 6b9516c
Revert "chore: update deps (#40)"
vasco-santos 66c1fb3
chore: update contributors
vasco-santos 0d13a8b
chore: release version v0.5.4
vasco-santos 464fcbe
chore: update deps (#40)
24e10f3
chore: update contributors
vasco-santos 44a1e7c
chore: release version v0.6.0
vasco-santos 55fb5d5
chore(deps-dev): bump aegir from 20.6.1 to 21.2.0 (#44)
dependabot-preview[bot] be45fc4
feat: address and proto books (#590)
vasco-santos 54212cb
chore: deprecate old peer store api (#598)
vasco-santos 0f6e878
chore: remove peer-info usage
vasco-santos 984d933
chore: apply suggestions from code review
vasco-santos 8723388
chore: rename peer-store properties
vasco-santos 7627f96
chore: use kad-dht with renamed peer-store properties
vasco-santos a55a4dc
chore: refactor connection manager and registrar
vasco-santos e87b42b
chore: apply suggestions from code review
vasco-santos 7e76d0f
feat: address manager
vasco-santos 4e4a998
chore: update api docs
vasco-santos fd618b6
chore(deps-dev): bump datastore-level from 0.14.1 to 1.0.0
dependabot-preview[bot] 21b39eb
chore: rename address functions and apply suggestions from code review
vasco-santos e72a5b0
chore(deps-dev): bump datastore-level from 0.14.1 to 1.0.0
vasco-santos 9e96dbc
chore(deps-dev): bump datastore-fs from 0.9.1 to 1.0.0 (#46)
dependabot-preview[bot] d9fd726
chore: move to libp2p
vasco-santos 0b260e9
Merge branch 'master' of ../js-libp2p-keychain into feat/keychain
vasco-santos 9d54730
chore: merge 0.28x updates
vasco-santos b1a2b8a
Merge branch '0.28.x' into feat/keychain
vasco-santos c0bbda2
chore: merge 0.28x updates
vasco-santos c9d776a
feat: keychain in libp2p
vasco-santos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 | | ||
|
||
|
@@ -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> ] | ||
|
||
### contentRouting.findProviders | ||
|
||
Iterates over all content routers in series to find providers of the given key. | ||
|
@@ -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')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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