[offchain] Support for sign & verify for crypto keys (#3023)

* Implement sign & verify.

* Use phrases and password.

* Sign & verify with authority keys.

* Fix tests.

* WiP

* WiP

* Allow the caller to decide on 'CryptoKind'.

* Remove TODO.

* Make seed private back.

* Fix non-std build and bump version.

* Use Into<u32> instead of asses.

* Add missing typedef.
This commit is contained in:
Tomasz Drwięga
2019-07-09 17:09:14 +02:00
committed by Gavin Wood
parent ed630e5eda
commit e729dbabbe
22 changed files with 647 additions and 178 deletions
+25 -8
View File
@@ -275,27 +275,44 @@ impl OffchainApi for () {
}, "new_crypto_key can be called only in the offchain worker context")
}
fn encrypt(key: Option<offchain::CryptoKeyId>, data: &[u8]) -> Result<Vec<u8>, ()> {
fn encrypt(
key: Option<offchain::CryptoKeyId>,
kind: offchain::CryptoKind,
data: &[u8],
) -> Result<Vec<u8>, ()> {
with_offchain(|ext| {
ext.encrypt(key, data)
ext.encrypt(key, kind, data)
}, "encrypt can be called only in the offchain worker context")
}
fn decrypt(key: Option<offchain::CryptoKeyId>, data: &[u8]) -> Result<Vec<u8>, ()> {
fn decrypt(
key: Option<offchain::CryptoKeyId>,
kind: offchain::CryptoKind,
data: &[u8],
) -> Result<Vec<u8>, ()> {
with_offchain(|ext| {
ext.decrypt(key, data)
ext.decrypt(key, kind, data)
}, "decrypt can be called only in the offchain worker context")
}
fn sign(key: Option<offchain::CryptoKeyId>, data: &[u8]) -> Result<Vec<u8>, ()> {
fn sign(
key: Option<offchain::CryptoKeyId>,
kind: offchain::CryptoKind,
data: &[u8],
) -> Result<Vec<u8>, ()> {
with_offchain(|ext| {
ext.sign(key, data)
ext.sign(key, kind, data)
}, "sign can be called only in the offchain worker context")
}
fn verify(key: Option<offchain::CryptoKeyId>, msg: &[u8], signature: &[u8]) -> Result<bool, ()> {
fn verify(
key: Option<offchain::CryptoKeyId>,
kind: offchain::CryptoKind,
msg: &[u8],
signature: &[u8],
) -> Result<bool, ()> {
with_offchain(|ext| {
ext.verify(key, msg, signature)
ext.verify(key, kind, msg, signature)
}, "verify can be called only in the offchain worker context")
}