Skip to content

Conversation

@danielailie
Copy link
Contributor

No description provided.

@danielailie danielailie self-assigned this Sep 15, 2025
Copy link
Contributor

@popenta popenta left a 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

Copy link

Copilot AI left a 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 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.
import { ErrSignerCannotSign } from "../core/errors";

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +33 to +39
sign(data: Uint8Array): Uint8Array {
try {
return this.trySign(data);
} catch (err) {
throw new ErrSignerCannotSign(err as Error);
}
}
Copy link

Copilot AI Sep 16, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

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?

Comment on lines +35 to +41
return this.trySign(data);
} catch (err) {
throw new ErrSignerCannotSign(err as Error);
}
}

private trySign(data: Uint8Array): Uint8Array {
Copy link

Copilot AI Sep 16, 2025

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.

Suggested change
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 {

Copilot uses AI. Check for mistakes.
Comment on lines 33 to 38
for (const entry of entries) {
await BLS.initIfNecessary();
const secretKey = new ValidatorSecretKey(entry.message);
const item = new ValidatorPEM(entry.label, secretKey);
resultItems.push(item);
}
Copy link

Copilot AI Sep 16, 2025

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.

Copilot uses AI. Check for mistakes.
* Validator signer (BLS signer)
*/
export class ValidatorSigner {
private secretKey: ValidatorSecretKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be private readonly.

Comment on lines 7 to 8
label: string;
secretKey: ValidatorSecretKey;
Copy link
Contributor

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?

Copy link
Contributor Author

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

const resultItems: ValidatorPEM[] = [];

for (const entry of entries) {
await BLS.initIfNecessary();
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines +33 to +39
sign(data: Uint8Array): Uint8Array {
try {
return this.trySign(data);
} catch (err) {
throw new ErrSignerCannotSign(err as Error);
}
}
Copy link
Contributor

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(
Copy link
Contributor

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).

Copy link
Contributor

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.

andreibancioiu
andreibancioiu previously approved these changes Sep 16, 2025
@danielailie danielailie merged commit cd9757d into feat/next Sep 16, 2025
5 checks passed
@danielailie danielailie deleted the TOOL-677-add-validator-pem-and-validator-signer branch September 16, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants