mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 02:51:08 +00:00
Keystore overhaul (iter 2) (#13634)
* Remove bloat about remote keystore * Update docs and remove unused 'KeystoreRef' trait * Use wherever possible, MemoryKeystore for testing * Remove unrequired fully qualified method syntax for Keystore
This commit is contained in:
@@ -253,7 +253,7 @@ mod tests {
|
||||
use crate::{crypto, known_payloads, KEY_TYPE};
|
||||
use codec::Decode;
|
||||
use sp_core::{keccak_256, Pair};
|
||||
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr};
|
||||
use sp_keystore::{testing::MemoryKeystore, KeystorePtr};
|
||||
|
||||
type TestCommitment = Commitment<u128>;
|
||||
type TestSignedCommitment = SignedCommitment<u128, crypto::Signature>;
|
||||
@@ -266,17 +266,13 @@ mod tests {
|
||||
let store: KeystorePtr = MemoryKeystore::new().into();
|
||||
|
||||
let alice = sp_core::ecdsa::Pair::from_string("//Alice", None).unwrap();
|
||||
let _ = Keystore::insert(&*store, KEY_TYPE, "//Alice", alice.public().as_ref()).unwrap();
|
||||
store.insert(KEY_TYPE, "//Alice", alice.public().as_ref()).unwrap();
|
||||
|
||||
let msg = keccak_256(b"This is the first message");
|
||||
let sig1 = Keystore::ecdsa_sign_prehashed(&*store, KEY_TYPE, &alice.public(), &msg)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let sig1 = store.ecdsa_sign_prehashed(KEY_TYPE, &alice.public(), &msg).unwrap().unwrap();
|
||||
|
||||
let msg = keccak_256(b"This is the second message");
|
||||
let sig2 = Keystore::ecdsa_sign_prehashed(&*store, KEY_TYPE, &alice.public(), &msg)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let sig2 = store.ecdsa_sign_prehashed(KEY_TYPE, &alice.public(), &msg).unwrap().unwrap();
|
||||
|
||||
(sig1.into(), sig2.into())
|
||||
}
|
||||
|
||||
@@ -74,9 +74,8 @@ impl<TBlockNumber, TMerkleRoot> SignedCommitmentWitness<TBlockNumber, TMerkleRoo
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use sp_core::{keccak_256, Pair};
|
||||
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr};
|
||||
use sp_keystore::{testing::MemoryKeystore, KeystorePtr};
|
||||
|
||||
use super::*;
|
||||
use codec::Decode;
|
||||
@@ -93,17 +92,13 @@ mod tests {
|
||||
let store: KeystorePtr = MemoryKeystore::new().into();
|
||||
|
||||
let alice = sp_core::ecdsa::Pair::from_string("//Alice", None).unwrap();
|
||||
let _ = Keystore::insert(&*store, KEY_TYPE, "//Alice", alice.public().as_ref()).unwrap();
|
||||
store.insert(KEY_TYPE, "//Alice", alice.public().as_ref()).unwrap();
|
||||
|
||||
let msg = keccak_256(b"This is the first message");
|
||||
let sig1 = Keystore::ecdsa_sign_prehashed(&*store, KEY_TYPE, &alice.public(), &msg)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let sig1 = store.ecdsa_sign_prehashed(KEY_TYPE, &alice.public(), &msg).unwrap().unwrap();
|
||||
|
||||
let msg = keccak_256(b"This is the second message");
|
||||
let sig2 = Keystore::ecdsa_sign_prehashed(&*store, KEY_TYPE, &alice.public(), &msg)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
let sig2 = store.ecdsa_sign_prehashed(KEY_TYPE, &alice.public(), &msg).unwrap().unwrap();
|
||||
|
||||
(sig1.into(), sig2.into())
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ use serde::Serialize;
|
||||
use codec::{Codec, Decode, Encode, Input};
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use sp_keystore::{Keystore, KeystorePtr};
|
||||
use sp_keystore::KeystorePtr;
|
||||
use sp_runtime::{
|
||||
traits::{Header as HeaderT, NumberFor},
|
||||
ConsensusEngineId, RuntimeDebug,
|
||||
@@ -455,16 +455,12 @@ where
|
||||
use sp_core::crypto::Public;
|
||||
|
||||
let encoded = localized_payload(round, set_id, &message);
|
||||
let signature = Keystore::sign_with(
|
||||
&*keystore,
|
||||
AuthorityId::ID,
|
||||
&public.to_public_crypto_pair(),
|
||||
&encoded[..],
|
||||
)
|
||||
.ok()
|
||||
.flatten()?
|
||||
.try_into()
|
||||
.ok()?;
|
||||
let signature = keystore
|
||||
.sign_with(AuthorityId::ID, &public.to_public_crypto_pair(), &encoded[..])
|
||||
.ok()
|
||||
.flatten()?
|
||||
.try_into()
|
||||
.ok()?;
|
||||
|
||||
Some(grandpa::SignedMessage { message, signature, id: public })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user