Files: 25a1b62eac06d4d75d5b9b4ee53a86ab7f163b5f / lib / depject / keys.js
548 bytesRaw
1 | const Path = require('path') |
2 | const Keys = require('ssb-keys') |
3 | const nest = require('depnest') |
4 | |
5 | exports.needs = nest('config.sync.load', 'first') |
6 | exports.gives = nest({ |
7 | 'keys.sync': ['load', 'id'] |
8 | }) |
9 | |
10 | exports.create = (api) => { |
11 | let keys |
12 | |
13 | return nest({ |
14 | 'keys.sync': { load, id } |
15 | }) |
16 | |
17 | function id () { |
18 | return load().id |
19 | } |
20 | |
21 | function load () { |
22 | if (!keys) { |
23 | const config = api.config.sync.load() |
24 | const keyPath = Path.join(config.path, 'secret') |
25 | keys = Keys.loadOrCreateSync(keyPath) |
26 | } |
27 | return keys |
28 | } |
29 | } |
30 |
Built with git-ssb-web