Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend files validation logic #50

Merged
merged 4 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/tsc/src/cli-shared.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/tsc/src/cli-shared.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions dist/tsc/src/commands/actions/KeySharesAction.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/tsc/src/commands/actions/KeySharesAction.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssv-keys",
"version": "1.0.3",
"version": "1.0.4",
"description": "Tool for splitting a validator key into a predefined threshold of shares via Shamir-Secret-Sharing (SSS), and encrypt them with a set of operator keys.",
"author": "SSV.Network",
"repository": "https://github.com/bloxapp/ssv-keys",
Expand Down
18 changes: 11 additions & 7 deletions src/commands/actions/KeySharesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,30 @@ export class KeySharesAction extends BaseAction {
if (multiShares) {
const { files } = await getKeyStoreFiles(keystorePath);
// validate all files
console.debug('Validating keystore files, do not terminate process!');
const validatedFiles = [];
let failedValidation = 0;
for (const file of files) {
const isKeyStoreValid = await keystorePathArgument.interactive.options.validateSingle(file);
if (isKeyStoreValid !== true) {
throw Error(String(isKeyStoreValid));
}
const isValidPassword = await keystorePasswordValidator.validatePassword(password, file);
if (isValidPassword !== true) {
throw Error(String(isValidPassword));
if (isKeyStoreValid === true && isValidPassword === true) {
validatedFiles.push(file);
} else {
failedValidation++;
}
process.stdout.write(`\r${validatedFiles.length}/${files.length} keystore files successfully validated. ${failedValidation} failed validation`);
}
process.stdout.write('\n');
const outputFiles = [];
let nextNonce = ownerNonce;
let processedFilesCount = 0;
console.debug('Splitting keystore files to shares, do not terminate process!');
for (const file of files) {
for (const file of validatedFiles) {
const keySharesFilePath = await this._processFile(file, password, outputFolder, operators, ownerAddress, nextNonce);
outputFiles.push(keySharesFilePath);

processedFilesCount++;
process.stdout.write(`\r${processedFilesCount}/${files.length} keystore files successfully split into shares`);
process.stdout.write(`\r${processedFilesCount}/${validatedFiles.length} keystore files successfully split into shares`);

nextNonce++;
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands/actions/validators/file.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fs from 'fs';
import * as path from 'path';

export const fileExistsValidator = (filePath: string, message = ''): boolean | string => {
filePath = sanitizePath(filePath);

if (!path.basename(filePath).includes('keystore') || !fs.existsSync(filePath.trim())) {
if (!fs.existsSync(filePath.trim())) {
return message || 'Couldn’t locate keystore file or directory.';
}
return true;
Expand Down
Loading