Skip to content

Commit

Permalink
add verify bls signature after it generated
Browse files Browse the repository at this point in the history
  • Loading branch information
vadiminc committed May 21, 2023
1 parent f0facbe commit 78def1e
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dist/esbuild/main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/esbuild/main.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions dist/tsc/src/lib/KeyShares/KeyShares.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/KeyShares.js.map

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

1 change: 1 addition & 0 deletions dist/tsc/src/lib/helpers/web3.helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export declare const buildSignature: (dataToSign: string, privateKeyHex: string)
* computes the Keccak-256 hash of the signed data, and verifies the signature using the deserialized public key.
*/
export declare const validateSignature: (signedData: string, signatureHex: string, publicKey: string) => Promise<void>;
export declare const privateToPublicKey: (privateKey: string) => Promise<string>;
9 changes: 8 additions & 1 deletion dist/tsc/src/lib/helpers/web3.helper.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/helpers/web3.helper.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 examples/example-02/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"license": "ISC",
"dependencies": {
"js-base64": "^3.7.2",
"ssv-keys": "https://github.com/bloxapp/ssv-keys.git#v0.0.19",
"ssv-keys": "https://github.com/bloxapp/ssv-keys.git#v3",
"web3": "^1.7.4"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/KeyShares/KeyShares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,15 @@ export class KeyShares {
const signature = await web3Helper.buildSignature(`${address}:${ownerNonce}`, privateKey);
const signSharesBytes = web3Helper.hexArrayToBytes([signature, payload.shares]);

payload.shares = `0x${signSharesBytes.toString('hex')}`
payload.shares = `0x${signSharesBytes.toString('hex')}`;

// verify signature
await this.validateSingleShares(payload.shares, {
ownerAddress,
ownerNonce,
publicKey: await web3Helper.privateToPublicKey(privateKey),
});

return payload;
}

Expand Down
7 changes: 7 additions & 0 deletions src/lib/helpers/web3.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,10 @@ export const validateSignature = async(signedData: string, signatureHex: string,
throw new SingleSharesSignatureInvalid(signatureHex, 'Single shares signature is invalid');
}
}

export const privateToPublicKey = async(privateKey: string): Promise<string> => {
if (!bls.deserializeHexStrToSecretKey) {
await bls.init(bls.BLS12_381);
}
return `0x${bls.deserializeHexStrToSecretKey(privateKey.replace('0x', '')).getPublicKey().serializeToHexStr()}`;
}

0 comments on commit 78def1e

Please sign in to comment.