read_keypair

Function read_keypair 

Source
pub fn read_keypair(path: impl AsRef<Path>) -> Result<PrivKey, IoError>
Expand description

Reads a private key from a JSON file at the specified path

This function loads a serialized private key from a JSON file, allowing applications to use saved keys for signing operations.

§Parameters

  • path - File system path to a JSON file containing a serialized private key

§Returns

  • Result<PrivKey, IoError> - Deserialized private key or an I/O error

§Errors

Returns IoError if:

  • The file cannot be read;
  • The file doesn’t contain valid JSON; or
  • The JSON doesn’t represent a valid private key

§Example

use delta_base_sdk::crypto::{read_keypair, ed25519};
use std::path::Path;

fn load_key() -> Result<ed25519::PrivKey, Box<dyn std::error::Error>> {
    let key_path = Path::new("./my_key.json");
    let private_key = read_keypair(key_path)?;
    Ok(private_key)
}