Introduce Ed25519 verify as an external.

This commit is contained in:
Gav
2018-01-17 19:17:34 +01:00
parent 6b1153d975
commit ec78b7244a
3 changed files with 32 additions and 3 deletions
+10 -3
View File
@@ -3,6 +3,9 @@ extern crate environmental;
extern crate polkadot_state_machine;
extern crate tiny_keccak;
use std::fmt;
use primitives::ed25519;
pub use std::vec::Vec;
pub use std::rc::Rc;
pub use std::cell::RefCell;
@@ -11,7 +14,6 @@ pub use std::slice;
pub use std::mem::{size_of, transmute, swap, uninitialized};
pub use polkadot_state_machine::Externalities;
use std::fmt;
// TODO: use the real error, not NoError.
@@ -63,9 +65,9 @@ pub fn storage_into<T: Sized>(_key: &[u8]) -> Option<T> {
}).unwrap_or(None)
}
pub fn set_storage(_key: &[u8], _value: &[u8]) {
pub fn set_storage(key: &[u8], value: &[u8]) {
ext::with(|holder|
holder.ext.set_storage(_key.to_vec(), _value.to_vec())
holder.ext.set_storage(key.to_vec(), value.to_vec())
);
}
@@ -79,6 +81,11 @@ pub fn chain_id() -> u64 {
/// Conduct a Keccak-256 hash of the given data.
pub use tiny_keccak::keccak256;
/// Verify a ed25519 signature.
pub fn ed25519_verify(sig: &[u8; 64], msg: &[u8], pubkey: &[u8; 32]) -> bool {
ed25519::verify(&sig[..], msg, &pubkey[..])
}
/// Execute the given closure with global function available whose functionality routes into the
/// externalities `ext`. Forwards the value that the closure returns.
pub fn with_externalities<R, F: FnOnce() -> R>(ext: &mut Externalities<Error=NoError>, f: F) -> R {