delta_base_sdk/
crypto.rs

1//! # Cryptographic Utilities for delta
2//!
3//! This module provides cryptographic primitives and utilities for delta,
4//! including hash functions, keys, signatures, and message handling.
5
6use serializers::json::read_path;
7use std::path::Path;
8
9// Re-export of types to be exposed by the base SDK
10pub use crypto::{
11    ed25519,
12    hash::{
13        Hash256,
14        HashDigest,
15        TryHash256,
16    },
17    messages::{
18        BaseSignedMessage,
19        SignedMessage,
20    },
21    multisig,
22    owner::OwnerId,
23    passkey,
24    signature::{
25        IntoSignatureEnum,
26        Signature,
27        SignatureError,
28    },
29    signing_key::{
30        self,
31        SignError,
32    },
33};
34pub use serializers::json::IoError;
35
36/// Reads a private key from a JSON file at the specified path
37///
38/// This function loads a serialized private key from a JSON file, allowing
39/// applications to use saved keys for signing operations.
40///
41/// # Parameters
42///
43/// * `path` - File system path to a JSON file containing a serialized private key
44///
45/// # Returns
46///
47/// * `Result<PrivKey, IoError>` - Deserialized private key or an I/O error
48///
49/// # Errors
50///
51/// Returns [IoError] if:
52/// - The file cannot be read;
53/// - The file doesn't contain valid JSON; or
54/// - The JSON doesn't represent a valid private key
55///
56/// # Example
57///
58/// ```no_run
59/// use delta_base_sdk::crypto::{read_keypair, ed25519};
60/// use std::path::Path;
61///
62/// fn load_key() -> Result<ed25519::PrivKey, Box<dyn std::error::Error>> {
63///     let key_path = Path::new("./my_key.json");
64///     let private_key = read_keypair(key_path)?;
65///     Ok(private_key)
66/// }
67/// ```
68pub fn read_keypair(path: impl AsRef<Path>) -> Result<ed25519::PrivKey, IoError> {
69    read_path(path)
70}