4

I want to benchmark verifying sr25519 signatures and for that I need to create a bunch of key pairs, sign some data, then benchmark the verification process, however using sp_core::sr25519::Pair is not allowed, it throws this error:

error[E0432]: unresolved import `sp_core::sr25519::Pair`
 --> /home/test/projects/custom/pallet/src/benchmarking.rs:8:5
  |
8 | use sp_core::sr25519::Pair;
  |     ^^^^^^^^^^^^^^^^^^^^^^ no `Pair` in `sr25519`

I assume this is happening because it could be leaking some std features in Pair so it wouldn't compile, so how do I solve this?

PS: I'm not tied necessarily to that specific struct (in fact this is the first time going to work with it); I used to work with a cryptostore that generates sr25519 keys, so anything similar.

1 Answer 1

3

Try something like this:

use sp_io::crypto::{sr25519_generate, sr25519_sign};
let caller_public = sr25519_generate(key_type_id, None);

And if you need a Substrate account from your sr25519 public key:

let caller = MultiSigner::Sr25519(caller_public).into_account().into();

You can see an example here.

2

Your Answer

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

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