Add sign command which can perform actions
This commit is contained in:
57
lib/commands/sign.js
Normal file
57
lib/commands/sign.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const registrationLogic = require('../core/logic/register');
|
||||
const authenticationLogic = require('../core/logic/authentication');
|
||||
|
||||
|
||||
module.exports.description = "Sign message/challenge."
|
||||
|
||||
module.exports.builder = (yargs) => {
|
||||
return yargs
|
||||
.usage(`Usage: $0 sign [options]`)
|
||||
.help(false)
|
||||
.version(false)
|
||||
.option('challenge', {
|
||||
describe: 'Challenge to sign',
|
||||
type: 'string'
|
||||
})
|
||||
.demandOption(['challenge'])
|
||||
.argv;
|
||||
}
|
||||
|
||||
module.exports.handler = (argv) => {
|
||||
console.log("Sign challenge.");
|
||||
|
||||
const challengeArgument = argv["challenge"].js || argv["challenge"];
|
||||
|
||||
const challenge = JSON.parse(challengeArgument);
|
||||
// Parse Action
|
||||
try {
|
||||
const request = JSON.parse(challenge.message);
|
||||
|
||||
if(request.action != undefined) {
|
||||
switch(request.action) {
|
||||
case "register":
|
||||
// Ask user if they want to register with service
|
||||
registrationLogic.registration(challenge, request);
|
||||
break;
|
||||
case "authenticate":
|
||||
// Ask user if they want to authenticate with service
|
||||
authenticationLogic.authenticate(challenge, request, argv)
|
||||
break;
|
||||
default:
|
||||
// Tell user that action is unsupported
|
||||
// ask if they want to sign regardless if they want to continue any way.
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// No action provided... should just sign
|
||||
console.log("No action required.");
|
||||
}
|
||||
// TODO: Validate lock-definition is of the correct format...
|
||||
|
||||
} catch(e) {
|
||||
// Should just be signed...
|
||||
console.error("challenge.messsage isn't json Object")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user