Skip to content

Commit

Permalink
extended catch error flow (#62)
Browse files Browse the repository at this point in the history
* extended catch error flow

* version up

* update build

* clean not used code

* remove error from json

* Version up

* minor example update
  • Loading branch information
vadiminc authored Jan 11, 2024
1 parent 0272ae8 commit a6a4c97
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 45 deletions.
2 changes: 1 addition & 1 deletion dist/tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ssv-keys",
"version": "1.0.6",
"version": "1.0.9",
"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
2 changes: 1 addition & 1 deletion dist/tsc/src/lib/KeyShares/KeyShares.js.map

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

2 changes: 2 additions & 0 deletions dist/tsc/src/lib/KeyShares/KeySharesItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { KeySharesPayload } from './KeySharesData/KeySharesPayload';
import { EncryptShare } from '../Encryption/Encryption';
import { IKeySharesPartitialData } from './KeySharesData/IKeySharesData';
import { IOperator } from './KeySharesData/IOperator';
import { SSVKeysException } from '../../lib/exceptions/base';
export interface IKeySharesPayloadData {
publicKey: string;
operators: IOperator[];
Expand All @@ -24,6 +25,7 @@ export interface IKeySharesFromSignatureData {
export declare class KeySharesItem {
data: KeySharesData;
payload: KeySharesPayload;
error: SSVKeysException | null;
constructor();
/**
* Build payload from operators list, encrypted shares and validator public key
Expand Down
27 changes: 18 additions & 9 deletions dist/tsc/src/lib/KeyShares/KeySharesItem.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/lib/KeyShares/KeySharesItem.js.map

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

17 changes: 14 additions & 3 deletions examples/console/example-complex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const fsp = require('fs').promises;
const { SSVKeys, KeyShares, KeySharesItem } = require('ssv-keys');
const { SSVKeys, KeyShares, KeySharesItem, SSVKeysException } = require('ssv-keys');

const operatorKeys = require('./operators.json');
const keystore = require('./test.keystore.json');
Expand Down Expand Up @@ -66,8 +66,19 @@ async function main() {
const jsonKeyShares = await fsp.readFile(getKeySharesFilePath(4), { encoding: 'utf-8' });

const keyShares2 = await KeyShares.fromJson(jsonKeyShares);

console.log('KeyShares list', keyShares2.list().map(item => item.toJson()));
for (const keySharesItem of keyShares2.list()) {
if (keySharesItem.error) {
if (keySharesItem.error instanceof SSVKeysException) {
console.log('SSVKeys Error name:', keySharesItem.error.name);
console.log('SSVKeys Error message:', keySharesItem.error.message);
console.log('SSVKeys Error trace:', keySharesItem.error.trace);
} else {
// Handle other types of errors
console.log('Other Error caught:', keySharesItem.error);
}
}
console.log(keySharesItem.toJson());
}
}

void main();
27 changes: 14 additions & 13 deletions examples/console/example-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ async function main() {
await fsp.writeFile(getKeySharesFilePath(4), keyShares.toJson(), { encoding: 'utf-8' });

// example to work with keyshares from file
const jsonKeyShares = await fsp.readFile(getKeySharesFilePath(4), { encoding: 'utf-8' });

try {
const keyShares2 = await KeyShares.fromJson(jsonKeyShares);
console.log('Created keyShares list from json', keyShares2.list().map(item => item.toJson()));
} catch (e: any) {
if (e instanceof SSVKeysException) {
console.log('SSVKeys Error name:', e.name);
console.log('SSVKeys Error message:', e.message);
console.log('SSVKeys Error trace:', e.trace);
} else {
// Handle other types of errors
console.log('Other Error caught:', e.message);
const jsonKeyShares = await fsp.readFile('./data/test-error.json', { encoding: 'utf-8' });

const keyShares2 = await KeyShares.fromJson(jsonKeyShares);
for (const keySharesItem of keyShares2.list()) {
if (keySharesItem.error) {
if (keySharesItem.error instanceof SSVKeysException) {
console.log('SSVKeys Error name:', keySharesItem.error.name);
console.log('SSVKeys Error message:', keySharesItem.error.message);
console.log('SSVKeys Error trace:', keySharesItem.error.trace);
} else {
// Handle other types of errors
console.log('Other Error caught:', keySharesItem.error);
}
}
console.log(keySharesItem.toJson());
}
}

Expand Down
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.7",
"version": "1.0.9",
"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
1 change: 0 additions & 1 deletion src/lib/KeyShares/KeyShares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class KeyShares {
// Handle old format (single item)
instance.shares.push(await KeySharesItem.fromJson(body));
}

return instance;
}
}
Loading

0 comments on commit a6a4c97

Please sign in to comment.