Skip to content

Commit

Permalink
update license to GNU
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya committed Nov 18, 2024
1 parent 936c0e0 commit cb41fb9
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 35 deletions.
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,6 @@ yarn build-all

## License

MIT License
The ssv-api is licensed under the
[GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html),
also included in our repository in the `LICENSE` file.
2 changes: 1 addition & 1 deletion src/lib/KeyShares/KeySharesData/IKeySharesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface IKeySharesData {
}


export interface IKeySharesPartitialData {
export interface IKeySharesPartialData {
ownerNonce?: number | null;
ownerAddress?: string | null;
publicKey?: string | null;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/KeyShares/KeySharesData/IKeySharesPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface IKeySharesPayload {
build(data: any): any;
}

export interface IKeySharesPartitialPayload {
export interface IKeySharesPartialPayload {
sharesData: string;
publicKey: string;
operatorIds: number[];
Expand Down
4 changes: 2 additions & 2 deletions src/lib/KeyShares/KeySharesData/KeySharesData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsString, Length, ValidateNested, IsOptional, validateSync, IsNumber } from 'class-validator';

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'IsString' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'Length' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'ValidateNested' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'IsOptional' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'IsNumber' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'IsString' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'Length' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'ValidateNested' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'IsOptional' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'IsNumber' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'IsString' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'Length' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'ValidateNested' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'IsOptional' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'IsNumber' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'IsString' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'Length' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'ValidateNested' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'IsOptional' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'IsNumber' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'IsString' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'Length' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'ValidateNested' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'IsOptional' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'IsNumber' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'IsString' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'Length' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'ValidateNested' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'IsOptional' is defined but never used

Check warning on line 1 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'IsNumber' is defined but never used
import { OperatorData } from './OperatorData';
import { IKeySharesData, IKeySharesPartitialData } from './IKeySharesData';
import { IKeySharesData, IKeySharesPartialData } from './IKeySharesData';
import { OpeatorsListValidator, PublicKeyValidator, OwnerAddressValidator, OwnerNonceValidator } from './validators';

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'OpeatorsListValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'PublicKeyValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'OwnerAddressValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'OpeatorsListValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'PublicKeyValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'OwnerAddressValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'OpeatorsListValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'PublicKeyValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_macos (macos-latest)

'OwnerAddressValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'OpeatorsListValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'PublicKeyValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (ubuntu-latest)

'OwnerAddressValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'OpeatorsListValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'PublicKeyValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'OwnerAddressValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'OpeatorsListValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'PublicKeyValidator' is defined but never used

Check warning on line 4 in src/lib/KeyShares/KeySharesData/KeySharesData.ts

View workflow job for this annotation

GitHub Actions / release_linux (windows-latest)

'OwnerAddressValidator' is defined but never used
import { operatorSortedList } from '../../helpers/operator.helper';

Expand All @@ -26,7 +26,7 @@ export class KeySharesData implements IKeySharesData {
@OpeatorsListValidator()
public operators?: OperatorData[] | null = null;

update(data: IKeySharesPartitialData) {
update(data: IKeySharesPartialData) {
if (data.ownerAddress) {
this.ownerAddress = data.ownerAddress;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/KeyShares/KeySharesData/KeySharesPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hexArrayToBytes } from '../../helpers/web3.helper';
import { IsString, Length, validateSync, IsNumber } from 'class-validator';
import { PublicKeyValidator } from './validators';

import { IKeySharesPartitialPayload, IKeySharesPayload } from './IKeySharesPayload';
import { IKeySharesPartialPayload, IKeySharesPayload } from './IKeySharesPayload';
import { EncryptShare } from '../../Encryption/Encryption';

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ export class KeySharesPayload implements IKeySharesPayload {
* Updates the payload with new data and validates it.
* @param data Partial key shares payload to update.
*/
update(data: IKeySharesPartitialPayload): void {
update(data: IKeySharesPartialPayload): void {
this.publicKey = data.publicKey;
this.sharesData = data.sharesData;
this.operatorIds = data.operatorIds;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/KeyShares/KeySharesItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IsOptional, ValidateNested, validateSync } from 'class-validator';
import { KeySharesData } from './KeySharesData/KeySharesData';
import { KeySharesPayload } from './KeySharesData/KeySharesPayload';
import { EncryptShare } from '../Encryption/Encryption';
import { IKeySharesPartitialData } from './KeySharesData/IKeySharesData';
import { IKeySharesPartialData } from './KeySharesData/IKeySharesData';
import { IOperator } from './KeySharesData/IOperator';
import { operatorSortedList } from '../helpers/operator.helper';
import { OwnerAddressFormatError, OwnerNonceFormatError } from '../exceptions/keystore';
Expand Down Expand Up @@ -152,7 +152,7 @@ export class KeySharesItem {
/**
* Updates the current instance with partial data and payload, and validates.
*/
update(data: IKeySharesPartitialData): void {
update(data: IKeySharesPartialData): void {
this.data.update(data);
this.validate();
}
Expand Down
77 changes: 77 additions & 0 deletions src/lib/SSVKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ import EthereumKeyStore from './EthereumKeyStore/EthereumKeyStore';
import Encryption, { EncryptShare } from './Encryption/Encryption';
import { operatorSortedList } from './helpers/operator.helper';
import { IOperator } from './KeyShares/KeySharesData/IOperator';
import { KeySharesItem } from "./KeyShares/KeySharesItem";


export interface ExtractedKeys {
privateKey: string;
publicKey: string;
}

interface ISharesValidation {
shares: string;
operatorsCount: number;
validatorPublicKey: string;
isAccountExists: boolean;
ownerAddress: string;
ownerNonce: number;
blockNumber: number;
}

/**
* SSVKeys class provides high-level methods to easily work with entire flow:
* - getting private key from keystore file using password
Expand Down Expand Up @@ -79,4 +91,69 @@ export class SSVKeys {
getThreshold() {
return this.threshold;
}

async validateSharesPostRegistration({
shares,
operatorsCount,
validatorPublicKey,
isAccountExists,
ownerAddress,
ownerNonce,
blockNumber
}: ISharesValidation) {
const keySharesItem = new KeySharesItem();
let restoredSharesPublicKeys;
let restoredSharesEncryptedKeys;
let sharesError = '';
let sharesErrorMessage = '';
let signatureError = '';
let signatureErrorMessage = '';
let errorMessage = '';

try {
const restoredShares = keySharesItem.buildSharesFromBytes(shares, operatorsCount);
const { sharesPublicKeys, encryptedKeys } = restoredShares;
restoredSharesPublicKeys = sharesPublicKeys;
restoredSharesEncryptedKeys = encryptedKeys;
}
catch (e: any) {
sharesError = e.stack || e.trace || e;
sharesErrorMessage = e.message;
errorMessage = 'Can not extract shares from bytes';
}

if (!sharesError && !errorMessage) {
const signatureData = { ownerNonce, publicKey: validatorPublicKey, ownerAddress };
try {
await keySharesItem.validateSingleShares(shares, signatureData)
}
catch (e: any) {
signatureError = e.stack || e.trace || e;
signatureErrorMessage = e.message;
errorMessage = 'Failed to validate single shares';
if (isAccountExists) {
errorMessage += `. Account exist for owner address: ${ownerAddress}`;
} else {
errorMessage += `. Account is not synced for owner address: ${ownerAddress}`;
}
if (ownerNonce) {
errorMessage += `. Used nonce: ${ownerNonce}`;
}
errorMessage += `. Signature Data: ${JSON.stringify(signatureData)}`;
}
}

return {
isValid: !!sharesError && !!signatureError && !!errorMessage,
isSharesValid: !!sharesError,
sharesPublicKeys: restoredSharesPublicKeys,
encryptedKeys: restoredSharesEncryptedKeys,
memo: !!sharesError && !!signatureError ? [{
message: errorMessage,
error: sharesError || signatureError,
data: `${sharesErrorMessage}${signatureErrorMessage ? '. ' + signatureErrorMessage : ''}`,
blockNumber
}] : []
}
}
}
10 changes: 5 additions & 5 deletions src/lib/Threshold/Threshold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import { PrivateKeyFormatError } from '../exceptions/keystore';
import { isOperatorsLengthValid } from '../../commands/actions/validators';

export interface IShares {
privateKey: string,
publicKey: string,
id?: any
privateKey: string,
publicKey: string,
id?: any
}

export interface ISharesKeyPairs {
privateKey: string,
publicKey: string,
shares: IShares[]
publicKey: string,
shares: IShares[]
}

export class ThresholdInvalidOperatorsLengthError extends SSVKeysException {
Expand Down

0 comments on commit cb41fb9

Please sign in to comment.