lib.rs

Overview

This file serves as a core utility and module aggregator within its scope, providing essential data structures, utility functions, and module exports to support key operations in the system. It primarily handles cryptographic key representations, base64 decoding for identifiers, and reading key data from JSON files. The file also re-exports modules related to business process resolving, message routing, and external message processing, centralizing access to these functionalities.

Modules and Re-Exports

The file re-exports key items for convenient external use:

These re-exports enable other parts of the system to access these constants and types without importing the internal module paths directly.

KeyPair Struct

#[derive(Clone, Deserialize)]
pub struct KeyPair {
    pub public: String,
    pub secret: String,
}

Description

KeyPair represents a cryptographic key pair consisting of a public key and a secret key, both stored as strings.

Fields

Traits

Usage Example

let keypair_json = r#"{
    "public": "public_key_string",
    "secret": "secret_key_string"
}"#;
let keypair: KeyPair = serde_json::from_str(keypair_json).unwrap();
println!("Public Key: {}", keypair.public);

Implementation Notes

base64_id_decode Function

pub fn base64_id_decode(base64_str: &serde_json::Value) -> Result<String, String>

Description

Decodes a base64-encoded string wrapped in a JSON value into a hexadecimal string representation.

Parameters

Returns

Implementation Details

Usage Example

let json_val = serde_json::json!("c29tZS1iYXNlNjQtc3RyaW5n");
match base64_id_decode(&json_val) {
    Ok(hex_str) => println!("Decoded hex: {}", hex_str),
    Err(err) => eprintln!("Error decoding: {}", err),
}

read_keys_from_file Function

pub fn read_keys_from_file(path: &str) -> Result<KeyPair, Box<dyn std::error::Error>>

Description

Reads a JSON file from the specified path and deserializes its content into a KeyPair struct.

Parameters

Returns

Implementation Details

Usage Example

match read_keys_from_file("keys.json") {
    Ok(keys) => println!("Public key: {}", keys.public),
    Err(e) => eprintln!("Failed to read keys: {}", e),
}

Interaction with Other Parts of the System

Diagram

flowchart TD
lib.rs --> bp_resolver[Module: bp_resolver]
lib.rs --> message_router[Module: message_router]
lib.rs --> process_ext_messages[Module: process_ext_messages]
lib.rs --> defaults[Module: defaults]
subgraph KeyPair Struct
KP[KeyPair]
end
subgraph Utility Functions
B64[base64_id_decode]
READ[read_keys_from_file]
end
lib.rs --> KP
lib.rs --> B64
lib.rs --> READ
bp_resolver -->|exports| MockBPResolver
defaults -->|exports| DEFAULT_NODE_URL_PATH
defaults -->|exports| DEFAULT_NODE_URL_PORT
defaults -->|exports| DEFAULT_URL_PATH

This flowchart illustrates the module structure and key components exposed by this file, showing the relationship between modules, key data structures, and utility functions.