pub fn keypair_from_base_seed(
    base: &str,
    secret_key: Vec<u8>,
    more_bytes: Option<Vec<u8>>,
    program_id: Option<Pubkey>
) -> Result<Arc<Keypair>, SbError>
Expand description

Generates a keypair from a base seed, secret key, optional additional bytes, and an optional program ID.

§Arguments

  • base - The base seed as a string.
  • secret_key - The secret key as a vector of bytes.
  • more_bytes - Optional additional bytes to include in the seed.
  • program_id - Optional program ID to include in the seed.

§Returns

Returns a Result containing an Arc<Keypair> if the keypair is successfully derived, or an SbError if there is an error.

§Errors

Returns an SbError with the message “InvalidSecretKey” if the length of the secret key is not 32 bytes. Returns an SbError with the message “Failed to derive keypair” if there is an error deriving the keypair.

§Example

use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Keypair, keypair_from_seed};
use solana_sdk::hash::Hash;
use sha2::{Digest, Sha256};
use std::sync::Arc;
use switchboard_solana::SbError;

let base = "base_seed";
let secret_key = vec![0; 32];
let more_bytes = Some(vec![1, 2, 3]);
let program_id = Some(Pubkey::new_unique());

let result = switchboard_solana::client::utils::keypair_from_base_seed(base, secret_key, more_bytes, program_id);
match result {
    Ok(keypair) => {
        // Key pair successfully derived
        println!("Derived keypair: {:?}", keypair);
    }
    Err(error) => {
        // Error deriving key pair
        println!("Failed to derive keypair: {:?}", error);
    }
}