added extended key validator

This commit is contained in:
jash
2018-10-06 21:45:45 +02:00
committed by kexkey
parent 90d9a8944c
commit ee94109bd3
3 changed files with 17 additions and 10 deletions

View File

@@ -14,16 +14,11 @@ module.exports = {
choices: utils._featureChoices()
},
{
type: 'confirm',
name: 'cyphernode_rocks0',
default: utils._getDefault( 'cyphernode_rocks0' ),
message: 'Does cyphernode rock?'+'\n',
},
{
type: 'confirm',
name: 'cyphernode_rocks1',
default: utils._getDefault( 'cyphernode_rocks1' ),
message: 'Does cyphernode rock?'+'\n',
type: 'input',
name: 'cyphernode_xpub',
default: utils._getDefault( 'cyphernode_xpub' ),
message: 'What is your xpub to watch?'+'\n',
validate: utils._xkeyValidator
}];
},
env: function( props ) {

View File

@@ -6,6 +6,7 @@ const wrap = require('wordwrap')(86);
const validator = require('validator');
const path = require("path");
const featureChoices = require(path.join(__dirname, "features.json"));
const coinstring = require('coinstring');
let featurePromptModules = [];
const normalizedPath = path.join(__dirname, "features");
@@ -76,6 +77,16 @@ module.exports = class extends Generator {
return validator.isIP((ip+"").trim());
}
_xpubValidator( xpub ) {
try {
coinstring.decode(xpub);
} catch( e ) {
throw new Error('Invalid extended public key. Please check your input.');
}
return true;
}
_trimFilter( input ) {
return (input+"").trim();
}

View File

@@ -21,6 +21,7 @@
},
"dependencies": {
"chalk": "^2.1.0",
"coinstring": "^2.3.0",
"validator": "^10.8.0",
"wordwrap": "^1.0.0",
"yeoman-generator": "^2.0.1"