Skip to content
Permalink
Newer
Older
100644 47 lines (43 sloc) 1023 Bytes
1
import fs from 'fs'
2
import parseDuration from 'parse-duration'
4
export default {
5
command: 'export <name>',
6
7
describe: 'Export the key as a password protected PKCS #8 PEM file',
8
9
builder: {
10
passout: {
11
alias: 'p',
12
describe: 'Password for the PEM',
13
type: 'string',
14
demandOption: true
15
},
16
output: {
17
alias: 'o',
18
describe: 'Output file',
19
type: 'string',
20
default: 'stdout'
21
},
22
timeout: {
23
type: 'string',
24
coerce: parseDuration
28
/**
29
* @param {object} argv
30
* @param {import('../../types').Context} argv.ctx
31
* @param {string} argv.name
32
* @param {string} argv.passout
33
* @param {string} argv.output
34
* @param {number} argv.timeout
35
*/
36
async handler ({ ctx, name, passout, output, timeout }) {
37
const { ipfs } = ctx
38
const pem = await ipfs.key.export(name, passout, {
39
timeout
40
})
41
if (output === 'stdout') {
42
process.stdout.write(pem)
43
} else {
44
fs.writeFileSync(output, pem)
45
}