-
Notifications
You must be signed in to change notification settings - Fork 45
Add validator pem and extend validator signer #657
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
Add validator pem and extend validator signer #657
Conversation
popenta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, but add unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new ValidatorPEM class for handling validator keys in PEM format and extends the ValidatorSigner class with additional functionality including constructor initialization and PEM file loading capabilities.
- Introduces ValidatorPEM class for parsing and managing validator keys from PEM files
- Extends ValidatorSigner with constructor, sign methods, and static factory method for PEM loading
- Adds comprehensive test coverage for ValidatorPEM functionality
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wallet/validatorSigner.ts | Enhanced with constructor, sign methods, and PEM file loading support |
| src/wallet/validatorPem.ts | New class for handling validator PEM file operations |
| src/wallet/validatorPem.spec.ts | Test suite for ValidatorPEM functionality |
| src/wallet/index.ts | Export added for new ValidatorPEM class |
| src/testdata/testwallets/validators.pem | Test data file with multiple validator keys |
Comments suppressed due to low confidence (1)
src/wallet/validatorSigner.ts:1
- There are now two different
signmethods and two differenttrySignmethods with different signatures. The originaltrySignmethod (lines 17-23) takes asecretKeyparameter, while the newtrySignmethod (lines 41-42) uses the instance'ssecretKey. Consider renaming one of these methods to avoid confusion and maintain consistency.
import { ErrSignerCannotSign } from "../core/errors";
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| sign(data: Uint8Array): Uint8Array { | ||
| try { | ||
| return this.trySign(data); | ||
| } catch (err) { | ||
| throw new ErrSignerCannotSign(err as Error); | ||
| } | ||
| } |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now two different sign methods and two different trySign methods with different signatures. The original trySign method (lines 17-23) takes a secretKey parameter, while the new trySign method (lines 41-42) uses the instance's secretKey. Consider renaming one of these methods to avoid confusion and maintain consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is somehow wrong.
But maybe async signUsingPem should be static?
| return this.trySign(data); | ||
| } catch (err) { | ||
| throw new ErrSignerCannotSign(err as Error); | ||
| } | ||
| } | ||
|
|
||
| private trySign(data: Uint8Array): Uint8Array { |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now two different sign methods and two different trySign methods with different signatures. The original trySign method (lines 17-23) takes a secretKey parameter, while the new trySign method (lines 41-42) uses the instance's secretKey. Consider renaming one of these methods to avoid confusion and maintain consistency.
| return this.trySign(data); | |
| } catch (err) { | |
| throw new ErrSignerCannotSign(err as Error); | |
| } | |
| } | |
| private trySign(data: Uint8Array): Uint8Array { | |
| return this.signWithSecretKey(data); | |
| } catch (err) { | |
| throw new ErrSignerCannotSign(err as Error); | |
| } | |
| } | |
| private signWithSecretKey(data: Uint8Array): Uint8Array { |
| for (const entry of entries) { | ||
| await BLS.initIfNecessary(); | ||
| const secretKey = new ValidatorSecretKey(entry.message); | ||
| const item = new ValidatorPEM(entry.label, secretKey); | ||
| resultItems.push(item); | ||
| } |
Copilot
AI
Sep 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The BLS.initIfNecessary() call is inside the loop, which means it will be called for each entry. Since this is likely an expensive initialization operation, it should be moved outside the loop to be called only once before processing all entries.
src/wallet/validatorSigner.ts
Outdated
| * Validator signer (BLS signer) | ||
| */ | ||
| export class ValidatorSigner { | ||
| private secretKey: ValidatorSecretKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be private readonly.
src/wallet/validatorPem.ts
Outdated
| label: string; | ||
| secretKey: ValidatorSecretKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe can be readonly. Should they be private, as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are places where I use the fields if I'll make them private I'll have to add get Methods
src/wallet/validatorPem.ts
Outdated
| const resultItems: ValidatorPEM[] = []; | ||
|
|
||
| for (const entry of entries) { | ||
| await BLS.initIfNecessary(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved above the loop (opinion).
|
|
||
| // fromFile is async → await | ||
| const pem = await ValidatorPEM.fromFile(pemPath); | ||
| pem.save(savedPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's no test for toText(), but maybe this one for save() is sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added tests for toText, save is already tested via the other tests
| sign(data: Uint8Array): Uint8Array { | ||
| try { | ||
| return this.trySign(data); | ||
| } catch (err) { | ||
| throw new ErrSignerCannotSign(err as Error); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is somehow wrong.
But maybe async signUsingPem should be static?
| * Signs a message. | ||
| */ | ||
| async signUsingPem(pemText: string, pemIndex: number = 0, signable: Buffer | Uint8Array): Promise<Uint8Array> { | ||
| static async signUsingPem( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny breaking change in theory, but can be in minor version - since, actually, it's a "design correction change" (it's a fix).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed with @andreibancioiu, I think we can mark this as deprecated since we already have the sign method and this does not seem to bring significant benefits.
No description provided.