-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Sign V2 #3284
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
Open
Antonio95
wants to merge
9
commits into
staging
Choose a base branch
from
feat/sign_v2
base: staging
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
Sign V2 #3284
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
53ddb8b
implemented sign_v2/verify_v2 and analogous bits/bytes functions, add…
Antonio95 ee5d45b
disallowed message[1] == hash_psd2([message[0]]) in console::Signatur…
Antonio95 89266df
added compatibility check, all working
Antonio95 bd7026e
removed compatibility check from tests
Antonio95 15239c8
switched sign/verify to use switch/verify_internal with prefix []
Antonio95 ccba4e6
introduced length into message, added test
Antonio95 c534e88
added branch to merge flow
Antonio95 96e9269
marked sign as deprecated, added allow(deprecated) or switched to sig…
Antonio95 45348f3
Merge branch 'staging' into feat/sign_v2
Antonio95 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -146,6 +146,7 @@ mod tests { | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||
| #[allow(deprecated)] | ||||||||||||||||||||||||||
| fn test_sign_bits() { | ||||||||||||||||||||||||||
| let private_key = PrivateKey::<CurrentNetwork>::from_str(ALEO_PRIVATE_KEY).unwrap(); | ||||||||||||||||||||||||||
| let address = Address::<CurrentNetwork>::try_from(&private_key).unwrap(); | ||||||||||||||||||||||||||
|
|
@@ -157,10 +158,15 @@ mod tests { | |||||||||||||||||||||||||
| let signature = private_key.sign_bits(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
| let verification = signature.verify_bits(&address, &message); | ||||||||||||||||||||||||||
| assert!(verification); | ||||||||||||||||||||||||||
| let signature_v2 = private_key.sign_bits_v2(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
| let verification_v2 = signature_v2.verify_bits_v2(&address, &message); | ||||||||||||||||||||||||||
| assert!(verification_v2); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
164
to
+165
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||
| #[allow(deprecated)] | ||||||||||||||||||||||||||
| fn test_invalid_sign_bits() { | ||||||||||||||||||||||||||
| let private_key = PrivateKey::<CurrentNetwork>::from_str(ALEO_PRIVATE_KEY).unwrap(); | ||||||||||||||||||||||||||
| let address = Address::<CurrentNetwork>::try_from(&private_key).unwrap(); | ||||||||||||||||||||||||||
|
|
@@ -174,10 +180,14 @@ mod tests { | |||||||||||||||||||||||||
| let signature = private_key.sign_bits(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
| let verification = signature.verify_bits(&address, &incorrect_message); | ||||||||||||||||||||||||||
| assert!(!verification); | ||||||||||||||||||||||||||
| let signature_v2 = private_key.sign_bits_v2(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
| let verification_v2 = signature_v2.verify_bits_v2(&address, &incorrect_message); | ||||||||||||||||||||||||||
| assert!(!verification_v2); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||
| #[allow(deprecated)] | ||||||||||||||||||||||||||
| fn test_aleo_signature_bech32() { | ||||||||||||||||||||||||||
| let mut rng = TestRng::default(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -192,10 +202,17 @@ mod tests { | |||||||||||||||||||||||||
| let candidate_string = &expected_signature.to_string(); | ||||||||||||||||||||||||||
| assert_eq!(216, candidate_string.len(), "Update me if serialization has changed"); | ||||||||||||||||||||||||||
| assert_eq!("sign1", &candidate_string[0..5], "Update me if the prefix has changed"); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let expected_signature_v2 = private_key.sign_bits_v2(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let candidate_string = &expected_signature_v2.to_string(); | ||||||||||||||||||||||||||
| assert_eq!(216, candidate_string.len(), "Update me if serialization has changed"); | ||||||||||||||||||||||||||
| assert_eq!("sign1", &candidate_string[0..5], "Update me if the prefix has changed"); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||
| #[allow(deprecated)] | ||||||||||||||||||||||||||
| fn test_aleo_signature_serde_json() { | ||||||||||||||||||||||||||
| let mut rng = TestRng::default(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -215,10 +232,23 @@ mod tests { | |||||||||||||||||||||||||
| // Deserialize | ||||||||||||||||||||||||||
| assert_eq!(expected_signature, serde_json::from_str(&candidate_string).unwrap()); | ||||||||||||||||||||||||||
| assert_eq!(expected_signature, Signature::<CurrentNetwork>::from_str(expected_string).unwrap()); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Craft the Aleo signature with the v2 method. | ||||||||||||||||||||||||||
| let expected_signature_v2 = private_key.sign_bits_v2(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Serialize | ||||||||||||||||||||||||||
| let expected_string = &expected_signature_v2.to_string(); | ||||||||||||||||||||||||||
| let candidate_string = serde_json::to_string(&expected_signature).unwrap(); | ||||||||||||||||||||||||||
| assert_eq!(expected_string, serde_json::Value::from_str(&candidate_string).unwrap().as_str().unwrap()); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Deserialize | ||||||||||||||||||||||||||
| assert_eq!(expected_signature_v2, serde_json::from_str(&candidate_string).unwrap()); | ||||||||||||||||||||||||||
| assert_eq!(expected_signature, Signature::<CurrentNetwork>::from_str(expected_string).unwrap()); | ||||||||||||||||||||||||||
|
Comment on lines
+241
to
+246
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||
| #[allow(deprecated)] | ||||||||||||||||||||||||||
| fn test_aleo_signature_bincode() { | ||||||||||||||||||||||||||
| let mut rng = TestRng::default(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -239,6 +269,19 @@ mod tests { | |||||||||||||||||||||||||
| // Deserialize | ||||||||||||||||||||||||||
| assert_eq!(expected_signature, bincode::deserialize(&candidate_bytes[..]).unwrap()); | ||||||||||||||||||||||||||
| assert_eq!(expected_signature, Signature::<CurrentNetwork>::read_le(&expected_bytes[..]).unwrap()); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Craft the Aleo signature with the v2 method. | ||||||||||||||||||||||||||
| let expected_signature_v2 = private_key.sign_bits_v2(&message, &mut rng).unwrap(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Serialize | ||||||||||||||||||||||||||
| let expected_bytes = expected_signature_v2.to_bytes_le().unwrap(); | ||||||||||||||||||||||||||
| let candidate_bytes = bincode::serialize(&expected_signature_v2).unwrap(); | ||||||||||||||||||||||||||
| assert_eq!(128, expected_bytes.len(), "Update me if serialization has changed"); | ||||||||||||||||||||||||||
| assert_eq!(&expected_bytes[..], &candidate_bytes[8..]); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Deserialize | ||||||||||||||||||||||||||
| assert_eq!(expected_signature_v2, bincode::deserialize(&candidate_bytes[..]).unwrap()); | ||||||||||||||||||||||||||
| assert_eq!(expected_signature_v2, Signature::<CurrentNetwork>::read_le(&expected_bytes[..]).unwrap()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Is this arithmetization equivalent / backwards compatible?