-
Notifications
You must be signed in to change notification settings - Fork 226
NDRS-156: handle the new Chainspec format #86
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ use super::Result; | |
|
|
||
| const ED25519_TAG: u8 = 0; | ||
| const ED25519: &str = "Ed25519"; | ||
| const ED25519_LOWERCASE: &str = "ed25519"; | ||
|
|
||
| /// A secret or private asymmetric key. | ||
| #[derive(Serialize, Deserialize)] | ||
|
|
@@ -72,6 +73,17 @@ impl PublicKey { | |
| Ok(PublicKey::Ed25519(ed25519::PublicKey::from_bytes(&bytes)?)) | ||
| } | ||
|
|
||
| /// Constructs a new key from the algorithm name and a byte slice. | ||
| pub fn key_from_algorithm_name_and_bytes<N: AsRef<str>, T: AsRef<[u8]>>( | ||
| name: N, | ||
| bytes: T, | ||
| ) -> Result<Self> { | ||
| match &*name.as_ref().trim().to_lowercase() { | ||
| ED25519_LOWERCASE => Self::ed25519_from_bytes(bytes), | ||
| _ => panic!("Invalid algorithm name!"), | ||
|
Contributor
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. We could just return an error here couldn't we? It'd need a new variant in the
Contributor
Author
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. I wonder if we should - it means that a config file is invalid. Does it make sense to treat it as a recoverable error?
Contributor
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. OK - I see your point. I guess we can change it later if we find this method is used by other callers which need non-panicking behaviour. |
||
| } | ||
| } | ||
|
|
||
| /// Constructs a new Ed25519 variant from a byte slice. | ||
| pub fn ed25519_from_bytes<T: AsRef<[u8]>>(bytes: T) -> Result<Self> { | ||
| Ok(PublicKey::Ed25519(ed25519::PublicKey::from_bytes( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| SLx/2wN11ID70D5390/+3DC585VEVf4E2hWEOgpq8Mc=,100000000000000000,0 | ||
| H2bqYyGkipNfZul9T35g7i1/yczGLfvjEPM7SDn8Yus=,1000000000000000,400000000000000 | ||
| iedEeDwtcJAqXy73joLh9EECtesIymI0JB2V5Q9hWms=,1000000000000000,300000000000000 | ||
| VptB1XTEY5AhLWmGYLUyYmndsKdh0SlCWIl6xxe0lYs=,1000000000000000,200000000000000 | ||
| 0oZSZmPKN2bIB4FUOhSMY18jiL/hKJgcPkrGnOqI3DU=,1000000000000000,100000000000001 | ||
| 48bc7fdb0375d480fbd03e77f74ffedc30b9f3954455fe04da15843a0a6af0c7,ed25519,100000000000000000,0 | ||
| 1f66ea6321a48a935f66e97d4f7e60ee2d7fc9ccc62dfbe310f33b4839fc62eb,ed25519,1000000000000000,400000000000000 | ||
| 89e744783c2d70902a5f2ef78e82e1f44102b5eb08ca6234241d95e50f615a6b,ed25519,1000000000000000,300000000000000 | ||
| 569b41d574c46390212d698660b5326269ddb0a761d1294258897ac717b4958b,ed25519,1000000000000000,200000000000000 | ||
| d286526663ca3766c80781543a148c635f2388bfe128981c3e4ac69cea88dc35,ed25519,1000000000000000,100000000000001 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=,1,10 | ||
| AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI=,2,20 | ||
| 0303030303030303030303030303030303030303030303030303030303030303,3,30 | ||
| 0404040404040404040404040404040404040404040404040404040404040404,4,40 | ||
| 48bc7fdb0375d480fbd03e77f74ffedc30b9f3954455fe04da15843a0a6af0c7,ed25519,1,10 | ||
|
Contributor
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. I guess if we convert the algo name to lowercase when parsing, we could have some of these "ed25519" instances with uppercase? |
||
| 1f66ea6321a48a935f66e97d4f7e60ee2d7fc9ccc62dfbe310f33b4839fc62eb,Ed25519,2,20 | ||
| 89e744783c2d70902a5f2ef78e82e1f44102b5eb08ca6234241d95e50f615a6b,eD25519,3,30 | ||
| 569b41d574c46390212d698660b5326269ddb0a761d1294258897ac717b4958b,ED25519,4,40 | ||
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.
Should this constructor still exist? When would we know an account hash, but not the corresponding public key?
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.
When constructing the system account in the contract runtime. Specifically, we need it here: https://github.com/CasperLabs/casperlabs-node/blob/master/node/src/components/contract_runtime/core/engine_state/mod.rs#L419