diff --git a/substrate/README.adoc b/substrate/README.adoc index 4d8bc466f5..48ccc3ef91 100644 --- a/substrate/README.adoc +++ b/substrate/README.adoc @@ -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 diff --git a/substrate/core/rpc/api/src/author/mod.rs b/substrate/core/rpc/api/src/author/mod.rs index 3d5698880a..e8314c5c5f 100644 --- a/substrate/core/rpc/api/src/author/mod.rs +++ b/substrate/core/rpc/api/src/author/mod.rs @@ -44,8 +44,8 @@ pub trait AuthorApi { fn insert_key(&self, key_type: String, suri: String, - maybe_public: Option - ) -> Result; + public: Bytes, + ) -> Result<()>; /// Generate new session keys and returns the corresponding public keys. #[rpc(name = "author_rotateKeys")] diff --git a/substrate/core/rpc/src/author/mod.rs b/substrate/core/rpc/src/author/mod.rs index 4c72a96023..78a8ff804f 100644 --- a/substrate/core/rpc/src/author/mod.rs +++ b/substrate/core/rpc/src/author/mod.rs @@ -94,29 +94,14 @@ impl AuthorApi, BlockHash

> for Author whe &self, key_type: String, suri: String, - maybe_public: Option, - ) -> Result { + 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 { diff --git a/substrate/core/rpc/src/author/tests.rs b/substrate/core/rpc/src/author/tests.rs index e7cf84c927..8e6243f40e 100644 --- a/substrate/core/rpc/src/author/tests.rs +++ b/substrate/core/rpc/src/author/tests.rs @@ -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()