├── .github
├── dependabot.yml
└── workflows
│ ├── automerge.yml
│ ├── js-test-and-release.yml
│ ├── semantic-pull-request.yml
│ └── stale.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
├── doc
├── private-key.png
└── private-key.xml
├── package.json
├── src
├── errors.ts
├── index.ts
└── util.ts
├── test
├── keychain.spec.ts
└── peerid.spec.ts
└── tsconfig.json
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: npm
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "10:00"
8 | open-pull-requests-limit: 10
9 | commit-message:
10 | prefix: "deps"
11 | prefix-development: "deps(dev)"
12 |
--------------------------------------------------------------------------------
/.github/workflows/automerge.yml:
--------------------------------------------------------------------------------
1 | # File managed by web3-bot. DO NOT EDIT.
2 | # See https://github.com/protocol/.github/ for details.
3 |
4 | name: Automerge
5 | on: [ pull_request ]
6 |
7 | jobs:
8 | automerge:
9 | uses: protocol/.github/.github/workflows/automerge.yml@master
10 | with:
11 | job: 'automerge'
12 |
--------------------------------------------------------------------------------
/.github/workflows/js-test-and-release.yml:
--------------------------------------------------------------------------------
1 | # File managed by web3-bot. DO NOT EDIT.
2 | # See https://github.com/protocol/.github/ for details.
3 |
4 | name: test & maybe release
5 | on:
6 | push:
7 | branches:
8 | - master
9 | pull_request:
10 |
11 | jobs:
12 |
13 | check:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v3
17 | - uses: actions/setup-node@v3
18 | with:
19 | node-version: lts/*
20 | - uses: ipfs/aegir/actions/cache-node-modules@master
21 | - run: npm run --if-present lint
22 | - run: npm run --if-present dep-check
23 |
24 | test-node:
25 | needs: check
26 | runs-on: ${{ matrix.os }}
27 | strategy:
28 | matrix:
29 | os: [windows-latest, ubuntu-latest, macos-latest]
30 | node: [lts/*]
31 | fail-fast: true
32 | steps:
33 | - uses: actions/checkout@v3
34 | - uses: actions/setup-node@v3
35 | with:
36 | node-version: ${{ matrix.node }}
37 | - uses: ipfs/aegir/actions/cache-node-modules@master
38 | - run: npm run --if-present test:node
39 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
40 | with:
41 | flags: node
42 |
43 | test-chrome:
44 | needs: check
45 | runs-on: ubuntu-latest
46 | steps:
47 | - uses: actions/checkout@v3
48 | - uses: actions/setup-node@v3
49 | with:
50 | node-version: lts/*
51 | - uses: ipfs/aegir/actions/cache-node-modules@master
52 | - run: npm run --if-present test:chrome
53 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
54 | with:
55 | flags: chrome
56 |
57 | test-chrome-webworker:
58 | needs: check
59 | runs-on: ubuntu-latest
60 | steps:
61 | - uses: actions/checkout@v3
62 | - uses: actions/setup-node@v3
63 | with:
64 | node-version: lts/*
65 | - uses: ipfs/aegir/actions/cache-node-modules@master
66 | - run: npm run --if-present test:chrome-webworker
67 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
68 | with:
69 | flags: chrome-webworker
70 |
71 | test-firefox:
72 | needs: check
73 | runs-on: ubuntu-latest
74 | steps:
75 | - uses: actions/checkout@v3
76 | - uses: actions/setup-node@v3
77 | with:
78 | node-version: lts/*
79 | - uses: ipfs/aegir/actions/cache-node-modules@master
80 | - run: npm run --if-present test:firefox
81 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
82 | with:
83 | flags: firefox
84 |
85 | test-firefox-webworker:
86 | needs: check
87 | runs-on: ubuntu-latest
88 | steps:
89 | - uses: actions/checkout@v3
90 | - uses: actions/setup-node@v3
91 | with:
92 | node-version: lts/*
93 | - uses: ipfs/aegir/actions/cache-node-modules@master
94 | - run: npm run --if-present test:firefox-webworker
95 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
96 | with:
97 | flags: firefox-webworker
98 |
99 | test-webkit:
100 | needs: check
101 | runs-on: ${{ matrix.os }}
102 | strategy:
103 | matrix:
104 | os: [ubuntu-latest, macos-latest]
105 | node: [lts/*]
106 | fail-fast: true
107 | steps:
108 | - uses: actions/checkout@v3
109 | - uses: actions/setup-node@v3
110 | with:
111 | node-version: lts/*
112 | - uses: ipfs/aegir/actions/cache-node-modules@master
113 | - run: npm run --if-present test:webkit
114 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
115 | with:
116 | flags: webkit
117 |
118 | test-webkit-webworker:
119 | needs: check
120 | runs-on: ${{ matrix.os }}
121 | strategy:
122 | matrix:
123 | os: [ubuntu-latest, macos-latest]
124 | node: [lts/*]
125 | fail-fast: true
126 | steps:
127 | - uses: actions/checkout@v3
128 | - uses: actions/setup-node@v3
129 | with:
130 | node-version: lts/*
131 | - uses: ipfs/aegir/actions/cache-node-modules@master
132 | - run: npm run --if-present test:webkit-webworker
133 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
134 | with:
135 | flags: webkit-webworker
136 |
137 | test-electron-main:
138 | needs: check
139 | runs-on: ubuntu-latest
140 | steps:
141 | - uses: actions/checkout@v3
142 | - uses: actions/setup-node@v3
143 | with:
144 | node-version: lts/*
145 | - uses: ipfs/aegir/actions/cache-node-modules@master
146 | - run: npx xvfb-maybe npm run --if-present test:electron-main
147 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
148 | with:
149 | flags: electron-main
150 |
151 | test-electron-renderer:
152 | needs: check
153 | runs-on: ubuntu-latest
154 | steps:
155 | - uses: actions/checkout@v3
156 | - uses: actions/setup-node@v3
157 | with:
158 | node-version: lts/*
159 | - uses: ipfs/aegir/actions/cache-node-modules@master
160 | - run: npx xvfb-maybe npm run --if-present test:electron-renderer
161 | - uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
162 | with:
163 | flags: electron-renderer
164 |
165 | release:
166 | needs: [test-node, test-chrome, test-chrome-webworker, test-firefox, test-firefox-webworker, test-webkit, test-webkit-webworker, test-electron-main, test-electron-renderer]
167 | runs-on: ubuntu-latest
168 | if: github.event_name == 'push' && github.ref == 'refs/heads/master'
169 | steps:
170 | - uses: actions/checkout@v3
171 | with:
172 | fetch-depth: 0
173 | - uses: actions/setup-node@v3
174 | with:
175 | node-version: lts/*
176 | - uses: ipfs/aegir/actions/cache-node-modules@master
177 | - uses: ipfs/aegir/actions/docker-login@master
178 | with:
179 | docker-token: ${{ secrets.DOCKER_TOKEN }}
180 | docker-username: ${{ secrets.DOCKER_USERNAME }}
181 | - run: npm run --if-present release
182 | env:
183 | GITHUB_TOKEN: ${{ secrets.UCI_GITHUB_TOKEN || github.token }}
184 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
185 |
--------------------------------------------------------------------------------
/.github/workflows/semantic-pull-request.yml:
--------------------------------------------------------------------------------
1 | name: Semantic PR
2 |
3 | on:
4 | pull_request_target:
5 | types:
6 | - opened
7 | - edited
8 | - synchronize
9 |
10 | jobs:
11 | main:
12 | uses: pl-strflt/.github/.github/workflows/reusable-semantic-pull-request.yml@v0.3
13 |
--------------------------------------------------------------------------------
/.github/workflows/stale.yml:
--------------------------------------------------------------------------------
1 | name: Close and mark stale issue
2 |
3 | on:
4 | schedule:
5 | - cron: '0 0 * * *'
6 |
7 | jobs:
8 | stale:
9 | uses: pl-strflt/.github/.github/workflows/reusable-stale-issue.yml@v0.3
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | build
3 | dist
4 | .docs
5 | .coverage
6 | node_modules
7 | package-lock.json
8 | yarn.lock
9 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [2.0.1](https://github.com/libp2p/js-libp2p-keychain/compare/v2.0.0...v2.0.1) (2023-06-15)
2 |
3 |
4 | ### Trivial Changes
5 |
6 | * Update .github/workflows/semantic-pull-request.yml [skip ci] ([7fd8023](https://github.com/libp2p/js-libp2p-keychain/commit/7fd80233db0b8706eb0ffe5372c6bad584ec211f))
7 | * Update .github/workflows/stale.yml [skip ci] ([c185b0d](https://github.com/libp2p/js-libp2p-keychain/commit/c185b0de456611ca42ec49bc7d52f803e4a76930))
8 |
9 |
10 | ### Dependencies
11 |
12 | * **dev:** bump aegir from 38.1.8 to 39.0.10 ([#70](https://github.com/libp2p/js-libp2p-keychain/issues/70)) ([4da4a08](https://github.com/libp2p/js-libp2p-keychain/commit/4da4a08b86f436c36e2fae48ecc48817e9b8066f))
13 |
14 | ## [2.0.0](https://github.com/libp2p/js-libp2p-keychain/compare/v1.0.1...v2.0.0) (2023-03-13)
15 |
16 |
17 | ### ⚠ BREAKING CHANGES
18 |
19 | * requires most recent datastore implementation
20 |
21 | ### Bug Fixes
22 |
23 | * update datastore dependency ([#58](https://github.com/libp2p/js-libp2p-keychain/issues/58)) ([a8a1628](https://github.com/libp2p/js-libp2p-keychain/commit/a8a162875e48f23611190c3fb31e439da1d2d64b))
24 |
25 | ## [1.0.1](https://github.com/libp2p/js-libp2p-keychain/compare/v1.0.0...v1.0.1) (2023-03-13)
26 |
27 |
28 | ### Bug Fixes
29 |
30 | * replace err-code with CodeError ([#57](https://github.com/libp2p/js-libp2p-keychain/issues/57)) ([cc752d9](https://github.com/libp2p/js-libp2p-keychain/commit/cc752d9349a622f013cb3b713d09a663b1169766))
31 |
32 |
33 | ### Trivial Changes
34 |
35 | * Update .github/workflows/semantic-pull-request.yml [skip ci] ([f3985cc](https://github.com/libp2p/js-libp2p-keychain/commit/f3985cc47ae966a33537af3f58c071f6c58184c9))
36 | * Update .github/workflows/semantic-pull-request.yml [skip ci] ([d8b81ff](https://github.com/libp2p/js-libp2p-keychain/commit/d8b81ff5e03ca56541ae2117a928dedf180e85ac))
37 | * Update .github/workflows/semantic-pull-request.yml [skip ci] ([a0a6972](https://github.com/libp2p/js-libp2p-keychain/commit/a0a6972d7af40488344e619e116f4d665190db6e))
38 | * Update .github/workflows/stale.yml [skip ci] ([b2cf129](https://github.com/libp2p/js-libp2p-keychain/commit/b2cf129fb1a3e0263a03d5a8a0e1ee74cd543004))
39 |
40 | ## [1.0.0](https://github.com/libp2p/js-libp2p-keychain/compare/v0.6.1...v1.0.0) (2023-01-27)
41 |
42 |
43 | ### ⚠ BREAKING CHANGES
44 |
45 | * this module is now typescript and does not store the self key on startup. cms operations have also been moved to [@libp2p/cms](https://www.npmjs.com/@libp2p/cms)
46 |
47 | ### Features
48 |
49 | * convert to typescript ([#53](https://github.com/libp2p/js-libp2p-keychain/issues/53)) ([3544df7](https://github.com/libp2p/js-libp2p-keychain/commit/3544df7c119b8cebded3f5c483e9f44bf499280f))
50 |
51 |
52 | ### Trivial Changes
53 |
54 | * add deprecation notice ([#50](https://github.com/libp2p/js-libp2p-keychain/issues/50)) ([2a9b99c](https://github.com/libp2p/js-libp2p-keychain/commit/2a9b99cd402ed7260ebcac49d9e44905697beee0))
55 |
56 |
57 | ## [0.6.1](https://github.com/libp2p/js-libp2p-keychain/compare/v0.6.0...v0.6.1) (2020-06-09)
58 |
59 |
60 |
61 |
62 | # [0.6.0](https://github.com/libp2p/js-libp2p-keychain/compare/v0.5.4...v0.6.0) (2019-12-18)
63 |
64 |
65 |
66 |
67 | ## [0.5.4](https://github.com/libp2p/js-libp2p-keychain/compare/v0.5.3...v0.5.4) (2019-12-18)
68 |
69 |
70 |
71 |
72 | ## [0.5.3](https://github.com/libp2p/js-libp2p-keychain/compare/v0.5.2...v0.5.3) (2019-12-18)
73 |
74 |
75 |
76 |
77 | ## [0.5.2](https://github.com/libp2p/js-libp2p-keychain/compare/v0.5.1...v0.5.2) (2019-12-02)
78 |
79 |
80 |
81 |
82 | ## [0.5.1](https://github.com/libp2p/js-libp2p-keychain/compare/v0.5.0...v0.5.1) (2019-09-25)
83 |
84 |
85 |
86 |
87 | # [0.5.0](https://github.com/libp2p/js-libp2p-keychain/compare/v0.4.2...v0.5.0) (2019-08-16)
88 |
89 |
90 | * refactor: use async/await instead of callbacks (#37) ([dda315a](https://github.com/libp2p/js-libp2p-keychain/commit/dda315a)), closes [#37](https://github.com/libp2p/js-libp2p-keychain/issues/37)
91 |
92 |
93 | ### BREAKING CHANGES
94 |
95 | * The api now uses async/await instead of callbacks.
96 |
97 | Co-Authored-By: Vasco Santos
98 |
99 |
100 |
101 |
102 | ## [0.4.2](https://github.com/libp2p/js-libp2p-keychain/compare/v0.4.1...v0.4.2) (2019-06-13)
103 |
104 |
105 | ### Bug Fixes
106 |
107 | * throw errors with correct stack trace ([#35](https://github.com/libp2p/js-libp2p-keychain/issues/35)) ([7051b9c](https://github.com/libp2p/js-libp2p-keychain/commit/7051b9c))
108 |
109 |
110 |
111 |
112 | ## [0.4.1](https://github.com/libp2p/js-libp2p-keychain/compare/v0.4.0...v0.4.1) (2019-03-14)
113 |
114 |
115 |
116 |
117 | # [0.4.0](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.6...v0.4.0) (2019-02-26)
118 |
119 |
120 | ### Features
121 |
122 | * adds support for ed25199 and secp256k1 ([#31](https://github.com/libp2p/js-libp2p-keychain/issues/31)) ([9eb11f4](https://github.com/libp2p/js-libp2p-keychain/commit/9eb11f4))
123 |
124 |
125 |
126 |
127 | ## [0.3.6](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.5...v0.3.6) (2019-01-10)
128 |
129 |
130 | ### Bug Fixes
131 |
132 | * reduce bundle size ([#28](https://github.com/libp2p/js-libp2p-keychain/issues/28)) ([7eeed87](https://github.com/libp2p/js-libp2p-keychain/commit/7eeed87))
133 |
134 |
135 |
136 |
137 | ## [0.3.5](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.4...v0.3.5) (2019-01-10)
138 |
139 |
140 |
141 |
142 | ## [0.3.4](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.3...v0.3.4) (2019-01-04)
143 |
144 |
145 |
146 |
147 | ## [0.3.3](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.2...v0.3.3) (2018-10-25)
148 |
149 |
150 |
151 |
152 | ## [0.3.2](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.1...v0.3.2) (2018-09-18)
153 |
154 |
155 | ### Bug Fixes
156 |
157 | * validate createKey params properly ([#26](https://github.com/libp2p/js-libp2p-keychain/issues/26)) ([8dfaab1](https://github.com/libp2p/js-libp2p-keychain/commit/8dfaab1))
158 |
159 |
160 |
161 |
162 | ## [0.3.1](https://github.com/libp2p/js-libp2p-keychain/compare/v0.3.0...v0.3.1) (2018-01-29)
163 |
164 |
165 |
166 |
167 | # [0.3.0](https://github.com/libp2p/js-libp2p-keychain/compare/v0.2.1...v0.3.0) (2018-01-29)
168 |
169 |
170 | ### Bug Fixes
171 |
172 | * deepmerge 2.0.1 fails in browser, stay with 1.5.2 ([2ce4444](https://github.com/libp2p/js-libp2p-keychain/commit/2ce4444))
173 |
174 |
175 |
176 |
177 | ## [0.2.1](https://github.com/libp2p/js-libp2p-keychain/compare/v0.2.0...v0.2.1) (2017-12-28)
178 |
179 |
180 | ### Features
181 |
182 | * generate unique options for a key chain ([#20](https://github.com/libp2p/js-libp2p-keychain/issues/20)) ([89a451c](https://github.com/libp2p/js-libp2p-keychain/commit/89a451c))
183 |
184 |
185 |
186 |
187 | # 0.2.0 (2017-12-20)
188 |
189 |
190 | ### Bug Fixes
191 |
192 | * error message ([8305d20](https://github.com/libp2p/js-libp2p-keychain/commit/8305d20))
193 | * lint errors ([06917f7](https://github.com/libp2p/js-libp2p-keychain/commit/06917f7))
194 | * lint errors ([ff4f656](https://github.com/libp2p/js-libp2p-keychain/commit/ff4f656))
195 | * linting ([409a999](https://github.com/libp2p/js-libp2p-keychain/commit/409a999))
196 | * maps an IPFS hash name to its forge equivalent ([f71d3a6](https://github.com/libp2p/js-libp2p-keychain/commit/f71d3a6)), closes [#12](https://github.com/libp2p/js-libp2p-keychain/issues/12)
197 | * more linting ([7c44c91](https://github.com/libp2p/js-libp2p-keychain/commit/7c44c91))
198 | * return info on removed key [#10](https://github.com/libp2p/js-libp2p-keychain/issues/10) ([f49e753](https://github.com/libp2p/js-libp2p-keychain/commit/f49e753))
199 |
200 |
201 | ### Features
202 |
203 | * move bits from https://github.com/richardschneider/ipfs-encryption ([1a96ae8](https://github.com/libp2p/js-libp2p-keychain/commit/1a96ae8))
204 | * use libp2p-crypto ([#18](https://github.com/libp2p/js-libp2p-keychain/issues/18)) ([c1627a9](https://github.com/libp2p/js-libp2p-keychain/commit/c1627a9))
205 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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
5 |
--------------------------------------------------------------------------------
/LICENSE-APACHE:
--------------------------------------------------------------------------------
1 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2 |
3 | http://www.apache.org/licenses/LICENSE-2.0
4 |
5 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
6 |
--------------------------------------------------------------------------------
/LICENSE-MIT:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 📁 Archived - this module has been merged into [js-libp2p](https://github.com/libp2p/js-libp2p/tree/master/packages/keychain)
2 |
3 | # @libp2p/keychain
4 |
5 | [](http://libp2p.io/)
6 | [](https://discuss.libp2p.io)
7 | [](https://codecov.io/gh/libp2p/js-libp2p-keychain)
8 | [](https://github.com/libp2p/js-libp2p-keychain/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
9 |
10 | > Key management and cryptographically protected messages
11 |
12 | ## Table of contents
13 |
14 | - [Install](#install)
15 | - [Browser `
36 | ```
37 |
38 | ## Features
39 |
40 | - Manages the lifecycle of a key
41 | - Keys are encrypted at rest
42 | - Enforces the use of safe key names
43 | - Uses encrypted PKCS 8 for key storage
44 | - Uses PBKDF2 for a "stetched" key encryption key
45 | - Enforces NIST SP 800-131A and NIST SP 800-132
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 | 
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 benefit 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 | ## API Docs
86 |
87 | -
88 |
89 | ## License
90 |
91 | Licensed under either of
92 |
93 | - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / )
94 | - MIT ([LICENSE-MIT](LICENSE-MIT) / )
95 |
96 | ## Contribution
97 |
98 | 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.
99 |
--------------------------------------------------------------------------------
/doc/private-key.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/libp2p/js-libp2p-keychain/b6046140dade0194db582affdb4c4d3b348c8fb3/doc/private-key.png
--------------------------------------------------------------------------------
/doc/private-key.xml:
--------------------------------------------------------------------------------
1 | 7VlNb6MwEP01HLfCGBJ6bNJ2V9pdqVIP2x4dcMAKYGScJumvXxNsvkw+SmgSVe2hMs9mbL839swQA07j9U+G0vAv9XFkWKa/NuC9YVmua4n/ObApAOjCAggY8QsIVMAzeccSNCW6JD7OGgM5pREnaRP0aJJgjzcwxBhdNYfNadScNUUB1oBnD0U6+o/4PJTbssYV/guTIFQzg9Ft0TND3iJgdJnI+QwLzrd/RXeMlC250SxEPl3VIPhgwCmjlBeteD3FUU6toq1473FHb7luhhN+zAtSpzcULeXWU5RluYmQoQzLRfKNIobjtbA7CXkcCQCIZsYZXeApjSgTSEITMXIyJ1HUglBEgkQ8emJlWOCTN8w4EZTfyY6Y+H4+zWQVEo6fU+Tlc66EfwlsSynOF22KJ7loYQCvd24clHQKL8U0xpxtxBDlolIA6aBgJJ9Xldy2hMKa0ko3JB0sKA1XJIuG5Lmbc6hx/jT5ff9oaWQL50jzZsqoh4Uq3dTUtBiAF9AmxtaJAVYHM6MBmLE1Zny8EABNOaFJ9nW9sfQryfr4fN7oaJxrNOPEv8sv1ZyvSFwPxGuSLjbJNi85GzcmGCvgdQvAUQk8YUbE8nK6a7xhX7uKD7JWo8XpoEVhDEeIk7em+S6u5AxPlIiJq6PQEgWMraaJjC6Zh+Vb9Uu2bUiFw12GOGIB5pqhrXTlto9SczSomk5Dyw9IJsL1dku1C+9SKpYHR5Fvmj1VhE1D2ukbTkX3WlQsuGmErbqw4KLnE5oHBDlWWbt10K22i+xQVgiANrVhaT4g271g22xfKI3kTDQKi33d5rY7fB4Mmgxn5B3NtgNy/5D7EKOdieHcfyhcRmiGo0mZBauwW+XBe+KlzOblSoxSz7pjunvj6A8RgcpaY9Mw3tfZ1BA6n2f41IOt6puaRAucrz/AiSbUNaR/Fjxj+geAxk668PJqRLiPexX8QPuS/OjVmo84yjhleqV2CXac9o18Vnb06uEm3e01PvWW8XZfh4iZFdn+n9mQTLWSCQhcjanRntB5ElF6yl9cQl++zGpfbo7unp9VZgE9M2dJoFFdbRmc5cRarRMLLd0P3S5KnAEoGWuUaHwcTHPXhL/U2q/NjPdF+k6tIHV6J8AqeF9PBtzyZxu2HLVvaQPdlqHhShswaG0zmLQdVWsRbb+lPV5avf44Qdpm2Vo/67JLnfb+oo86RDeNKxLdHkr0208TXcXGz/pW0S066C+61SG6/S36x0TXC7VTRP9SH43VLahyzHZpc/xHY7DfUG85xWP1A2MxvPoRFz78Bw==
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@libp2p/keychain",
3 | "version": "2.0.1",
4 | "description": "Key management and cryptographically protected messages",
5 | "license": "Apache-2.0 OR MIT",
6 | "homepage": "https://github.com/libp2p/js-libp2p-keychain#readme",
7 | "repository": {
8 | "type": "git",
9 | "url": "git+https://github.com/libp2p/js-libp2p-keychain.git"
10 | },
11 | "bugs": {
12 | "url": "https://github.com/libp2p/js-libp2p-keychain/issues"
13 | },
14 | "keywords": [
15 | "IPFS",
16 | "crypto",
17 | "encryption",
18 | "keys",
19 | "libp2p",
20 | "secure"
21 | ],
22 | "engines": {
23 | "node": ">=16.0.0",
24 | "npm": ">=7.0.0"
25 | },
26 | "type": "module",
27 | "types": "./dist/src/index.d.ts",
28 | "files": [
29 | "src",
30 | "dist",
31 | "!dist/test",
32 | "!**/*.tsbuildinfo"
33 | ],
34 | "exports": {
35 | ".": {
36 | "types": "./src/index.d.ts",
37 | "import": "./dist/src/index.js"
38 | }
39 | },
40 | "eslintConfig": {
41 | "extends": "ipfs",
42 | "parserOptions": {
43 | "sourceType": "module"
44 | }
45 | },
46 | "release": {
47 | "branches": [
48 | "master"
49 | ],
50 | "plugins": [
51 | [
52 | "@semantic-release/commit-analyzer",
53 | {
54 | "preset": "conventionalcommits",
55 | "releaseRules": [
56 | {
57 | "breaking": true,
58 | "release": "major"
59 | },
60 | {
61 | "revert": true,
62 | "release": "patch"
63 | },
64 | {
65 | "type": "feat",
66 | "release": "minor"
67 | },
68 | {
69 | "type": "fix",
70 | "release": "patch"
71 | },
72 | {
73 | "type": "docs",
74 | "release": "patch"
75 | },
76 | {
77 | "type": "test",
78 | "release": "patch"
79 | },
80 | {
81 | "type": "deps",
82 | "release": "patch"
83 | },
84 | {
85 | "scope": "no-release",
86 | "release": false
87 | }
88 | ]
89 | }
90 | ],
91 | [
92 | "@semantic-release/release-notes-generator",
93 | {
94 | "preset": "conventionalcommits",
95 | "presetConfig": {
96 | "types": [
97 | {
98 | "type": "feat",
99 | "section": "Features"
100 | },
101 | {
102 | "type": "fix",
103 | "section": "Bug Fixes"
104 | },
105 | {
106 | "type": "chore",
107 | "section": "Trivial Changes"
108 | },
109 | {
110 | "type": "docs",
111 | "section": "Documentation"
112 | },
113 | {
114 | "type": "deps",
115 | "section": "Dependencies"
116 | },
117 | {
118 | "type": "test",
119 | "section": "Tests"
120 | }
121 | ]
122 | }
123 | }
124 | ],
125 | "@semantic-release/changelog",
126 | "@semantic-release/npm",
127 | "@semantic-release/github",
128 | "@semantic-release/git"
129 | ]
130 | },
131 | "scripts": {
132 | "clean": "aegir clean",
133 | "lint": "aegir lint",
134 | "dep-check": "aegir dep-check",
135 | "build": "aegir build",
136 | "test": "aegir test",
137 | "test:chrome": "aegir test -t browser --cov",
138 | "test:chrome-webworker": "aegir test -t webworker",
139 | "test:firefox": "aegir test -t browser -- --browser firefox",
140 | "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
141 | "test:node": "aegir test -t node --cov",
142 | "test:electron-main": "aegir test -t electron-main",
143 | "release": "aegir release",
144 | "docs": "aegir docs"
145 | },
146 | "dependencies": {
147 | "@libp2p/crypto": "^1.0.11",
148 | "@libp2p/interface-keychain": "^2.0.3",
149 | "@libp2p/interface-peer-id": "^2.0.1",
150 | "@libp2p/interfaces": "^3.3.1",
151 | "@libp2p/logger": "^2.0.5",
152 | "@libp2p/peer-id": "^2.0.1",
153 | "interface-datastore": "^8.0.0",
154 | "merge-options": "^3.0.4",
155 | "sanitize-filename": "^1.6.3",
156 | "uint8arrays": "^4.0.3"
157 | },
158 | "devDependencies": {
159 | "@libp2p/peer-id-factory": "^2.0.1",
160 | "aegir": "^39.0.10",
161 | "datastore-core": "^9.0.1",
162 | "multiformats": "^11.0.1"
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/errors.ts:
--------------------------------------------------------------------------------
1 |
2 | export enum codes {
3 | ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS',
4 | ERR_INVALID_KEY_NAME = 'ERR_INVALID_KEY_NAME',
5 | ERR_INVALID_KEY_TYPE = 'ERR_INVALID_KEY_TYPE',
6 | ERR_KEY_ALREADY_EXISTS = 'ERR_KEY_ALREADY_EXISTS',
7 | ERR_INVALID_KEY_SIZE = 'ERR_INVALID_KEY_SIZE',
8 | ERR_KEY_NOT_FOUND = 'ERR_KEY_NOT_FOUND',
9 | ERR_OLD_KEY_NAME_INVALID = 'ERR_OLD_KEY_NAME_INVALID',
10 | ERR_NEW_KEY_NAME_INVALID = 'ERR_NEW_KEY_NAME_INVALID',
11 | ERR_PASSWORD_REQUIRED = 'ERR_PASSWORD_REQUIRED',
12 | ERR_PEM_REQUIRED = 'ERR_PEM_REQUIRED',
13 | ERR_CANNOT_READ_KEY = 'ERR_CANNOT_READ_KEY',
14 | ERR_MISSING_PRIVATE_KEY = 'ERR_MISSING_PRIVATE_KEY',
15 | ERR_INVALID_OLD_PASS_TYPE = 'ERR_INVALID_OLD_PASS_TYPE',
16 | ERR_INVALID_NEW_PASS_TYPE = 'ERR_INVALID_NEW_PASS_TYPE',
17 | ERR_INVALID_PASS_LENGTH = 'ERR_INVALID_PASS_LENGTH'
18 | }
19 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | /* eslint max-nested-callbacks: ["error", 5] */
2 |
3 | import { pbkdf2, randomBytes } from '@libp2p/crypto'
4 | import { generateKeyPair, importKey, unmarshalPrivateKey } from '@libp2p/crypto/keys'
5 | import { CodeError } from '@libp2p/interfaces/errors'
6 | import { logger } from '@libp2p/logger'
7 | import { peerIdFromKeys } from '@libp2p/peer-id'
8 | import { Key } from 'interface-datastore/key'
9 | import mergeOptions from 'merge-options'
10 | import sanitize from 'sanitize-filename'
11 | import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
12 | import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
13 | import { codes } from './errors.js'
14 | import type { KeyChain, KeyInfo, KeyType } from '@libp2p/interface-keychain'
15 | import type { PeerId } from '@libp2p/interface-peer-id'
16 | import type { Datastore } from 'interface-datastore'
17 |
18 | const log = logger('libp2p:keychain')
19 |
20 | export interface DEKConfig {
21 | hash: string
22 | salt: string
23 | iterationCount: number
24 | keyLength: number
25 | }
26 |
27 | export interface KeyChainInit {
28 | pass?: string
29 | dek?: DEKConfig
30 | }
31 |
32 | const keyPrefix = '/pkcs8/'
33 | const infoPrefix = '/info/'
34 | const privates = new WeakMap