In the Substrate framework, how do you get the private key (secret key) from a Keypair?

Viewed 432

I have this code:

use schnorrkel;
use schnorrkel::{
    derive::{ChainCode, Derivation, CHAIN_CODE_LENGTH},
    signing_context, Keypair, MiniSecretKey, PublicKey, SecretKey,
};
use substrate_primitives::crypto::Pair as PairT;
use substrate_primitives::sr25519;
use substrate_primitives::sr25519::Pair;

fn main() {
    let keypair = sr25519::Pair::generate();
    let private_key = keypair.somehow_get_the_private_key_func();
}

I tried to use the SecretKey trait (imported at the beginning), but it says SecretKey is private, so the only way I am thinking of is to modify Substrate's sources to add a function that gives me the private key, but I don't want to do it by source code alteration.

What would be the way to go?

1 Answers
Related