Foundational library which powers World App's crypto wallet.
Review our CONTRIBUTING guide. Including details on how to run this project locally.
Bedrock ships with foreign bindings for native Swift. All details can be found in the /swift folder.
Bedrock ships with foreign bindings for native Kotlin. All details can be found in the /kotlin folder.
Bedrock provides a global configuration system for managing environment settings across your application.
Initialize the global configuration once at app startup:
Swift:
@_exported import Bedrock
Bedrock.setConfig(environment: .staging)
// or
import Bedrock
setConfig(environment: .staging)
Kotlin:
uniffi.bedrock.setConfig(BedrockEnvironment.STAGING)
Each module should implement its own error enum. See tooling_tests for example references.
Automatically enhances error enums with UniFFI compatibility and anyhow
integration:
#[bedrock_error]
pub enum MyError {
#[error("Authentication failed with code: {code}")]
AuthenticationFailed { code: u32 },
#[error("Network timeout after {seconds} seconds")]
NetworkTimeout { seconds: u32 },
// Generic variant added automatically for anyhow integration
}
Features:
- Auto-derives
Debug
,thiserror::Error
,uniffi::Error
- Adds
Generic { message: String }
variant automatically - Adds
FileSystem(FileSystemError)
variant automatically for filesystem operations - Implements
From<anyhow::Error>
for seamless error conversion - Implements
From<FileSystemError>
for automatic filesystem error conversion - Provides helper methods like
from_anyhow_result()
andfrom_anyhow_result_with_prefix()
This means filesystem operations automatically work with your error types:
pub fn load_config(&self) -> Result<String, MyError> {
// FileSystemError automatically converts to MyError::FileSystem
let data = _bedrock_fs.read_file("config.json")?;
Ok(String::from_utf8_lossy(&data).to_string())
}
Wraps #[uniffi::export]
with automatic logging context and filesystem middleware injection:
#[bedrock_export]
impl MyStruct {
pub fn some_method(&self) -> String {
// LogContext automatically set to "MyStruct"
info!("This will be prefixed with [Bedrock][MyStruct]");
// Filesystem middleware available as _bedrock_fs with automatic path prefixing
// Files will be prefixed with snake_case version of struct name: "my_struct/"
_bedrock_fs.write_file("data.txt", b"content".to_vec()).ok();
"result".to_string()
}
}
Features:
- Automatically injects
LogContext::new("StructName")
at the start of every public method - Works with any
impl
block for structs or traits - Maintains all original
#[uniffi::export]
functionality
Simplified logging macros that automatically use the current context:
use bedrock::{trace, debug, info, warn, error};
// In a bedrock_export impl, logs will be automatically prefixed
info!("User authenticated successfully"); // Logs: [Bedrock][MyStruct] User authenticated successfully
debug!("Processing data: {}", value); // Logs: [Bedrock][MyStruct] Processing data: 42
Available macros: trace!
, debug!
, info!
, warn!
, error!
For fine-grained control over logging context:
use bedrock::logger::LogContext;
{
let _bedrock_logger_ctx = LogContext::new("CustomContext");
info!("This message has custom context"); // Logs: [Bedrock][CustomContext] This message has custom context
} // Context automatically cleared when _bedrock_logger_ctx is dropped