-
Notifications
You must be signed in to change notification settings - Fork 443
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
sr25519
signature verification
#1757
Changes from 8 commits
57c27e3
5d9cbee
37fa479
0a910e1
b2224d6
d6a9f7c
9d00c92
da71ca2
eb93905
9ca19c4
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 |
---|---|---|
|
@@ -60,6 +60,7 @@ reentrancy | |
refcount | ||
scalability | ||
scalable | ||
sr25519 | ||
stdin | ||
stdout | ||
tuple | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,11 @@ use ink_engine::{ | |
ext::Engine, | ||
}; | ||
use ink_storage_traits::Storable; | ||
use schnorrkel::{ | ||
signing_context, | ||
PublicKey, | ||
Signature, | ||
}; | ||
|
||
/// The capacity of the static buffer. | ||
/// This is the same size as the ink! on-chain environment. We chose to use the same size | ||
|
@@ -115,6 +120,7 @@ impl From<ext::Error> for crate::Error { | |
ext::Error::NotCallable => Self::NotCallable, | ||
ext::Error::LoggingDisabled => Self::LoggingDisabled, | ||
ext::Error::EcdsaRecoveryFailed => Self::EcdsaRecoveryFailed, | ||
ext::Error::Sr25519VerifyFailed => Self::Sr25519VerifyFailed, | ||
} | ||
} | ||
} | ||
|
@@ -333,6 +339,21 @@ impl EnvBackend for EnvInstance { | |
Ok(()) | ||
} | ||
|
||
fn sr25519_verify( | ||
&mut self, | ||
signature: &[u8; 64], | ||
message: &[u8], | ||
pub_key: &[u8; 32], | ||
) -> Result<()> { | ||
let context = signing_context(b"substrate"); | ||
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. For further use, i think there should be an option to verify signature from any context. Right now there is such limitation. 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. Could you create a |
||
let signature: Signature = Signature::from_bytes(signature).unwrap(); | ||
let public_key: PublicKey = PublicKey::from_bytes(pub_key).unwrap(); | ||
|
||
public_key | ||
.verify(context.bytes(message), &signature) | ||
.map_err(|_| Error::Sr25519VerifyFailed) | ||
} | ||
|
||
fn call_chain_extension<I, T, E, ErrorCode, F, D>( | ||
&mut self, | ||
func_id: u32, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,7 +263,7 @@ impl ItemMod { | |
.into_combine(format_err!( | ||
overlap.span(), | ||
"first ink! message with overlapping wildcard selector here", | ||
))) | ||
))); | ||
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. Could you exclude this file from the PR, please?=) |
||
} | ||
} | ||
} | ||
|
@@ -283,7 +283,7 @@ impl ItemMod { | |
.into_combine(format_err!( | ||
overlap.span(), | ||
"first ink! constructor with overlapping wildcard selector here", | ||
))) | ||
))); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,7 +384,7 @@ impl InkItemTrait { | |
).into_combine(format_err_spanned!( | ||
duplicate_selector, | ||
"first ink! trait constructor or message with same selector found here", | ||
))) | ||
))); | ||
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. Could you exclude this file from the PR, please?=) |
||
} | ||
assert!( | ||
duplicate_ident.is_none(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -880,6 +880,16 @@ where | |
.map_err(|_| Error::EcdsaRecoveryFailed) | ||
} | ||
|
||
pub fn sr25519_verify( | ||
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. Could you add a comment here as well, please?=) |
||
self, | ||
signature: &[u8; 64], | ||
message: &[u8], | ||
pub_key: &[u8; 32], | ||
) -> Result<()> { | ||
ink_env::sr25519_verify(signature, message, pub_key) | ||
.map_err(|_| Error::Sr25519VerifyFailed) | ||
} | ||
|
||
/// Checks whether a specified account belongs to a contract. | ||
/// | ||
/// # Example | ||
|
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.
Could you exclude this file from the PR, please?=)