mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 03:01:07 +00:00
Make public key mandatory in insert_key (#3512)
This commit is contained in:
@@ -406,11 +406,12 @@ https://github.com/paritytech/substrate/blob/master/core/primitives/src/crypto.r
|
||||
user can declare any key type.
|
||||
|
||||
```
|
||||
curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["KEY_TYPE", "SEED"],"id":1 }' localhost:9933
|
||||
curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["KEY_TYPE", "SEED", "PUBLIC"],"id":1 }' localhost:9933
|
||||
```
|
||||
|
||||
`KEY_TYPE` - needs to be replaced with the 4-character key type identifier.
|
||||
`SEED` - is the seed of the key.
|
||||
`PUBLIC` - public key for the given key.
|
||||
|
||||
== Documentation
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ pub trait AuthorApi<Hash, BlockHash> {
|
||||
fn insert_key(&self,
|
||||
key_type: String,
|
||||
suri: String,
|
||||
maybe_public: Option<Bytes>
|
||||
) -> Result<Bytes>;
|
||||
public: Bytes,
|
||||
) -> Result<()>;
|
||||
|
||||
/// Generate new session keys and returns the corresponding public keys.
|
||||
#[rpc(name = "author_rotateKeys")]
|
||||
|
||||
@@ -94,29 +94,14 @@ impl<B, E, P, RA> AuthorApi<ExHash<P>, BlockHash<P>> for Author<B, E, P, RA> whe
|
||||
&self,
|
||||
key_type: String,
|
||||
suri: String,
|
||||
maybe_public: Option<Bytes>,
|
||||
) -> Result<Bytes> {
|
||||
public: Bytes,
|
||||
) -> Result<()> {
|
||||
let key_type = key_type.as_str().try_into().map_err(|_| Error::BadKeyType)?;
|
||||
let mut keystore = self.keystore.write();
|
||||
let maybe_password = keystore.password();
|
||||
let public = match maybe_public {
|
||||
Some(public) => public.0,
|
||||
None => {
|
||||
let maybe_public = match key_type {
|
||||
key_types::BABE | key_types::SR25519 =>
|
||||
sr25519::Pair::from_string(&suri, maybe_password)
|
||||
.map(|pair| pair.public().to_raw_vec()),
|
||||
key_types::GRANDPA | key_types::ED25519 =>
|
||||
ed25519::Pair::from_string(&suri, maybe_password)
|
||||
.map(|pair| pair.public().to_raw_vec()),
|
||||
_ => Err(Error::UnsupportedKeyType)?,
|
||||
};
|
||||
maybe_public.map_err(|_| Error::BadSeedPhrase)?
|
||||
}
|
||||
};
|
||||
keystore.insert_unknown(key_type, &suri, &public[..])
|
||||
.map_err(|_| Error::KeyStoreUnavailable)?;
|
||||
Ok(public.into())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn rotate_keys(&self) -> Result<Bytes> {
|
||||
|
||||
@@ -200,7 +200,7 @@ fn should_insert_key() {
|
||||
p.insert_key(
|
||||
String::from_utf8(key_types::ED25519.0.to_vec()).expect("Keytype is a valid string"),
|
||||
suri.to_string(),
|
||||
Some(key_pair.public().0.to_vec().into()),
|
||||
key_pair.public().0.to_vec().into(),
|
||||
).expect("Insert key");
|
||||
|
||||
let store_key_pair = keystore.read()
|
||||
|
||||
Reference in New Issue
Block a user