-
Notifications
You must be signed in to change notification settings - Fork 80
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
Aptos HSM Signer Testing #974
Open
mzabaluev
wants to merge
7
commits into
main
Choose a base branch
from
mikhail/test-signer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
653adf7
feat(signing): byte array conversions for ed25519
mzabaluev 53e08b7
feat(signing): movement-signer-test crate
mzabaluev 7929c21
refactor(signing): no need for custom trait
mzabaluev a50bf0e
test(signing): test TestSigner
mzabaluev ca1ffac
chore: clean up unused rand_core dep
mzabaluev 82b7b68
test(signing): Add executor test for signed transactions
mzabaluev 0018145
test: add signer tests to the unit-tests workflow
mzabaluev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[package] | ||
name = "movement-signer-test" | ||
description = "Test support for Movement signing API" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
authors.workspace = true | ||
repository.workspace = true | ||
homepage.workspace = true | ||
publish.workspace = true | ||
rust-version.workspace = true | ||
|
||
[dependencies] | ||
movement-signer = { workspace = true } | ||
ed25519-dalek = { workspace = true } | ||
|
||
[dev-dependencies] | ||
maptos-dof-execution = { workspace = true } | ||
maptos-execution-util = { workspace = true } | ||
movement-signing-aptos = { workspace = true } | ||
aptos-crypto = { workspace = true } | ||
aptos-types = { workspace = true } | ||
anyhow = { workspace = true } | ||
chrono = { workspace = true } | ||
ed25519-dalek = { workspace = true, features = ["rand_core"] } | ||
# Workspace is on rand 0.7 due largely to aptos-core | ||
rand = "0.8" | ||
tempfile = { workspace = true } | ||
tokio = { workspace = true, features = ["macros"] } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use movement_signer::cryptography::ed25519::{self, Ed25519}; | ||
use movement_signer::{SignerError, Signing}; | ||
|
||
use ed25519_dalek::{Signer as _, SigningKey}; | ||
|
||
/// In-process signer used for testing the signing API. | ||
/// | ||
/// This signer wraps an Ed25519 private key to provide a signing service with | ||
/// the Ed25519 elliptic curve. Because the private key is kept in process | ||
/// memory, this signer implementation should not be used in production. | ||
pub struct TestSigner { | ||
signing_key: SigningKey, | ||
} | ||
|
||
impl TestSigner { | ||
pub fn new(signing_key: SigningKey) -> Self { | ||
Self { signing_key } | ||
} | ||
} | ||
|
||
impl Signing<Ed25519> for TestSigner { | ||
async fn sign(&self, message: &[u8]) -> Result<ed25519::Signature, SignerError> { | ||
let signature = | ||
self.signing_key.try_sign(message).map_err(|e| SignerError::Sign(e.into()))?; | ||
Ok(signature.to_bytes().into()) | ||
} | ||
|
||
async fn public_key(&self) -> Result<ed25519::PublicKey, SignerError> { | ||
let key = self.signing_key.verifying_key(); | ||
// The conversion should never fail because it's round-tripping | ||
// a valid key. | ||
Ok(key.to_bytes().try_into().unwrap()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod ed25519; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 it will be easier to have one error type for the crate. It avoids adding map_err every time when you need to extract the publickey from an u8 array, for example, and it eases the error management for external crate.
There's a reason you didn't add a new variant to the SignerError. Perhaps we need to rename it in a more generic name?
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 don't like using the "fat" main error type for the much slimmer use case of
TryFrom
conversions.