This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implementation of the ipfs.key API (#1133)
- Loading branch information
1 parent
3bca165
commit d945fce
Showing
33 changed files
with
683 additions
and
16 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'key', | ||
|
||
description: 'Manage your keys', | ||
|
||
builder (yargs) { | ||
return yargs | ||
.commandDir('key') | ||
}, | ||
|
||
handler (argv) {} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
|
||
module.exports = { | ||
command: 'export <name>', | ||
|
||
describe: 'Export the key as a password protected PKCS #8 PEM file', | ||
|
||
builder: { | ||
passout: { | ||
alias: 'p', | ||
describe: 'Password for the PEM', | ||
type: 'string', | ||
demandOption: true | ||
}, | ||
output: { | ||
alias: 'o', | ||
describe: 'Output file', | ||
type: 'string', | ||
default: 'stdout' | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
argv.ipfs.key.export(argv.name, argv.passout, (err, pem) => { | ||
if (err) { | ||
throw err | ||
} | ||
if (argv.output === 'stdout') { | ||
process.stdout.write(pem) | ||
} else { | ||
fs.writeFileSync(argv.output, pem) | ||
} | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'gen <name>', | ||
|
||
describe: 'Create a new key', | ||
|
||
builder: { | ||
type: { | ||
alias: 't', | ||
describe: 'type of the key to create [rsa, ed25519].', | ||
default: 'rsa' | ||
}, | ||
size: { | ||
alias: 's', | ||
describe: 'size of the key to generate.', | ||
default: '2048' | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
const opts = { | ||
type: argv.type, | ||
size: argv.size | ||
} | ||
argv.ipfs.key.gen(argv.name, opts, (err, key) => { | ||
if (err) { | ||
throw err | ||
} | ||
print(`generated ${key.id} ${key.name}`) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
const fs = require('fs') | ||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'import <name>', | ||
|
||
describe: 'Import the key from a PKCS #8 PEM file', | ||
|
||
builder: { | ||
passin: { | ||
alias: 'p', | ||
describe: 'Password for the PEM', | ||
type: 'string' | ||
}, | ||
input: { | ||
alias: 'i', | ||
describe: 'Input PEM file', | ||
type: 'string', | ||
demandOption: true, | ||
coerce: ('input', input => fs.readFileSync(input, 'utf8')) | ||
} | ||
}, | ||
|
||
handler (argv) { | ||
argv.ipfs.key.import(argv.name, argv.input, argv.passin, (err, key) => { | ||
if (err) { | ||
throw err | ||
} | ||
print(`imported ${key.id} ${key.name}`) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'list', | ||
|
||
describe: 'List all local keys', | ||
|
||
builder: {}, | ||
|
||
handler (argv) { | ||
argv.ipfs.key.list((err, keys) => { | ||
if (err) { | ||
throw err | ||
} | ||
keys.forEach((ki) => print(`${ki.id} ${ki.name}`)) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'rename <name> <newName>', | ||
|
||
describe: 'Rename a key', | ||
|
||
builder: {}, | ||
|
||
handler (argv) { | ||
argv.ipfs.key.rename(argv.name, argv.newName, (err, res) => { | ||
if (err) { | ||
throw err | ||
} | ||
print(`renamed to ${res.id} ${res.now}`) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict' | ||
|
||
const print = require('../../utils').print | ||
|
||
module.exports = { | ||
command: 'rm <name>', | ||
|
||
describe: 'Remove a key', | ||
|
||
builder: {}, | ||
|
||
handler (argv) { | ||
argv.ipfs.key.rm(argv.name, (err, key) => { | ||
if (err) { | ||
throw err | ||
} | ||
print(`${key.id} ${key.name}`) | ||
}) | ||
} | ||
} |
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
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
Oops, something went wrong.