@libp2p/keychain 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ This project is dual licensed under MIT and Apache-2.0.
2
+
3
+ MIT: https://www.opensource.org/licenses/mit
4
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @libp2p/keychain <!-- omit in toc -->
2
+
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
5
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-keychain.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-keychain)
6
+ [![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-keychain/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-keychain/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
7
+
8
+ > Key management and cryptographically protected messages
9
+
10
+ ## Table of contents <!-- omit in toc -->
11
+
12
+ - [Install](#install)
13
+ - [Browser `<script>` tag](#browser-script-tag)
14
+ - [Features](#features)
15
+ - [KeyInfo](#keyinfo)
16
+ - [Private key storage](#private-key-storage)
17
+ - [Physical storage](#physical-storage)
18
+ - [Cryptographic Message Syntax (CMS)](#cryptographic-message-syntax-cms)
19
+ - [API Docs](#api-docs)
20
+ - [License](#license)
21
+ - [Contribution](#contribution)
22
+
23
+ ## Install
24
+
25
+ ```console
26
+ $ npm i @libp2p/keychain
27
+ ```
28
+
29
+ ### Browser `<script>` tag
30
+
31
+ Loading this module through a script tag will make it's exports available as `Libp2pKeychain` in the global namespace.
32
+
33
+ ```html
34
+ <script src="https://unpkg.com/@libp2p/keychain/dist/index.min.js"></script>
35
+ ```
36
+
37
+ ## Features
38
+
39
+ - Manages the lifecycle of a key
40
+ - Keys are encrypted at rest
41
+ - Enforces the use of safe key names
42
+ - Uses encrypted PKCS 8 for key storage
43
+ - Uses PBKDF2 for a "stetched" key encryption key
44
+ - Enforces NIST SP 800-131A and NIST SP 800-132
45
+ - Uses PKCS 7: CMS (aka RFC 5652) to provide cryptographically protected messages
46
+ - Delays reporting errors to slow down brute force attacks
47
+
48
+ ### KeyInfo
49
+
50
+ The key management and naming service API all return a `KeyInfo` object. The `id` is a universally unique identifier for the key. The `name` is local to the key chain.
51
+
52
+ ```js
53
+ {
54
+ name: 'rsa-key',
55
+ id: 'QmYWYSUZ4PV6MRFYpdtEDJBiGs4UrmE6g8wmAWSePekXVW'
56
+ }
57
+ ```
58
+
59
+ The **key id** is the SHA-256 [multihash](https://github.com/multiformats/multihash) of its public key. The *public key* is a [protobuf encoding](https://github.com/libp2p/js-libp2p-crypto/blob/master/src/keys/keys.proto.js) containing a type and the [DER encoding](https://en.wikipedia.org/wiki/X.690) of the PKCS [SubjectPublicKeyInfo](https://www.ietf.org/rfc/rfc3279.txt).
60
+
61
+ ### Private key storage
62
+
63
+ A private key is stored as an encrypted PKCS 8 structure in the PEM format. It is protected by a key generated from the key chain's *passPhrase* using **PBKDF2**.
64
+
65
+ The default options for generating the derived encryption key are in the `dek` object. This, along with the passPhrase, is the input to a `PBKDF2` function.
66
+
67
+ ```js
68
+ const defaultOptions = {
69
+ //See https://cryptosense.com/parameter-choice-for-pbkdf2/
70
+ dek: {
71
+ keyLength: 512 / 8,
72
+ iterationCount: 1000,
73
+ salt: 'at least 16 characters long',
74
+ hash: 'sha2-512'
75
+ }
76
+ }
77
+ ```
78
+
79
+ ![key storage](./doc/private-key.png?raw=true)
80
+
81
+ ### Physical storage
82
+
83
+ The actual physical storage of an encrypted key is left to implementations of [interface-datastore](https://github.com/ipfs/interface-datastore/). A key benifit is that now the key chain can be used in browser with the [js-datastore-level](https://github.com/ipfs/js-datastore-level) implementation.
84
+
85
+ ### Cryptographic Message Syntax (CMS)
86
+
87
+ CMS, aka [PKCS #7](https://en.wikipedia.org/wiki/PKCS) and [RFC 5652](https://tools.ietf.org/html/rfc5652), describes an encapsulation syntax for data protection. It is used to digitally sign, digest, authenticate, or encrypt arbitrary message content. Basically, `cms.encrypt` creates a DER message that can be only be read by someone holding the private key.
88
+
89
+ ## API Docs
90
+
91
+ - <https://libp2p.github.io/js-libp2p-keychain>
92
+
93
+ ## License
94
+
95
+ Licensed under either of
96
+
97
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
98
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
99
+
100
+ ## Contribution
101
+
102
+ Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.