Is there any way to access to ECDSA capabilities (like sign) inside the Runtime?

I need to create benchmarks where the parameter of one extrinsic needs to be signed using ECDSA. I could create some 'hosted-functions' to do that, but I think it should be already done for each crypto schema (ed25519, sr25519, and ecdsa).

1 Answer 1


yes you can sign some data for your benchmarking code. In sp-io there is the function crypto::ecdsa_sign. You can use crypto::ecdsa_generate to generate you some public/private key to use for signing.

BTW: All of the things I mentioned above are also available through the RuntimePublic trait.

So, your code using this trait would look like this:

use sp_application_crypto::ecdsa::Public;

let public = Public::generate_pair(sp_core::testing::ECDSA, None);
public.sign(sp_core::testing::ECDSA, "my message").unwrap();

While sp_core::testing::ECDSA being the KeyTypeId. If you already have a custom KeyTypeId for your application, you can use this.

  • In my case I also had to add a benchmark where clause where_clause { where T::Public : From<sp_core::ecdsa::Public> } in order to use that key in place where T::Public is expected Commented Feb 3, 2023 at 0:35
  • You can also require that your public type implements the RuntimePublic trait.
    – bkchr
    Commented Feb 3, 2023 at 10:15
  • @bkchr How do you resolve the key store error that comes up when you use this in benchmarking i.e thread 'benchmarking::<>' panicked at 'No keystore' associated for the current context!' Commented Jun 23, 2023 at 7:33
  • The KeyStore is being registered by the benchmarking cli. Maybe you are using some old version where this wasn't the case? Which Polkadot bran are you using?
    – bkchr
    Commented Jun 23, 2023 at 13:47
  • Am using branch = "polkadot-v0.9.42" Commented Jun 23, 2023 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.