Skip to content
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

refactor(InMemorySigner) factory methods to return Signer interface #12472

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

mkamonMdt
Copy link
Contributor

Following the issue #11531, the Signer/ValidatorSigner wrapper interfaces should be used. The commit implements migration to Signer wrapper for following InMemorySigner factory functions:

  • InMemorySigner::from_seed
  • InMemorySigner::from_file
    Additionally:
  • The Signer interface is extented by get_acount_id method
  • Added From for KeyFile implementation

@mkamonMdt mkamonMdt requested a review from a team as a code owner November 17, 2024 21:27
@mkamonMdt mkamonMdt requested a review from saketh-are November 17, 2024 21:27
@mkamonMdt mkamonMdt marked this pull request as draft December 4, 2024 19:54
@mkamonMdt mkamonMdt force-pushed the into_signer_interface_migration branch 2 times, most recently from 8407e4f to d8ad1e2 Compare December 5, 2024 16:04
@mkamonMdt mkamonMdt changed the title Wrapping InMemorySigner instances into Signer interface refactor(InMemorySigner) factory methods to return Signer interface Dec 5, 2024
@mkamonMdt mkamonMdt marked this pull request as ready for review December 5, 2024 16:06
@mkamonMdt mkamonMdt force-pushed the into_signer_interface_migration branch from d8ad1e2 to 908484b Compare December 5, 2024 16:28
Following the issue near#11531, the Signer/ValidatorSigner wrapper
interfaces should be used. The commit implements migration to Signer
wrapper for following InMemorySigner factory functions:
- InMemorySigner::from_seed
- InMemorySigner::from_file
Additionally:
- The Signer interface is extented by get_acount_id method
- Added From<Signer> for KeyFile implementation
@mkamonMdt mkamonMdt force-pushed the into_signer_interface_migration branch from 908484b to b6dcadc Compare December 5, 2024 19:55
Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 86.06557% with 17 lines in your changes missing coverage. Please review.

Project coverage is 70.12%. Comparing base (6af8e01) to head (b6dcadc).
Report is 16 commits behind head on master.

Files with missing lines Patch % Lines
core/crypto/src/signer.rs 82.60% 4 Missing ⚠️
nearcore/src/config.rs 80.00% 2 Missing and 2 partials ⚠️
...ntime/runtime-params-estimator/src/action_costs.rs 0.00% 3 Missing ⚠️
tools/restaked/src/main.rs 0.00% 3 Missing ⚠️
integration-tests/src/node/mod.rs 0.00% 2 Missing ⚠️
test-utils/runtime-tester/src/scenario_builder.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12472      +/-   ##
==========================================
- Coverage   70.13%   70.12%   -0.02%     
==========================================
  Files         841      841              
  Lines      169899   169898       -1     
  Branches   169899   169898       -1     
==========================================
- Hits       119156   119135      -21     
- Misses      45605    45624      +19     
- Partials     5138     5139       +1     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.30% <29.41%> (+<0.01%) ⬆️
linux 69.34% <86.06%> (-0.03%) ⬇️
linux-nightly 69.72% <86.06%> (-0.01%) ⬇️
pytests 1.59% <39.21%> (+<0.01%) ⬆️
sanity-checks 1.40% <15.68%> (-0.01%) ⬇️
unittests 69.94% <86.06%> (-0.01%) ⬇️
upgradability 0.20% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mkamonMdt
Copy link
Contributor Author

@staffik , Please review the changes when you get a chance :)
@wacban you might be also interested I guess.

Comment on lines -1892 to +1891
assert!(k1.public_key == k2.public_key && k1.secret_key == k2.secret_key);
let data: &[u8] = b"Example data for signature test";
assert!(k1.public_key() == k2.public_key() && k1.sign(&data) == k2.sign(&data));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why we changed from k1.secret_key == k2.secret_key to k1.sign(&data) == k2.sign(&data) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test here checked if given the same seeds we end-up with the same public and secret keys. Since here we changed from InMemorySigner to Signer we do not have a public members now and we need public getters.

So I wasn't sure if giving a public access method to "secret_key" is the best way to go (especially when the only attempts to retrieve it were in tests) so other way to compare SecretKeys would be to sing something with them (as there is no random and one-shot nonce generated inside the SecretKey while signing we can expect the same result).

@mkamonMdt
Copy link
Contributor Author

@staffik
Do you have ability to merge it? I do not have write access to the repo :)

@staffik staffik added this pull request to the merge queue Dec 9, 2024
Merged via the queue into near:master with commit d2dcf6f Dec 9, 2024
27 checks passed
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.

2 participants