Skip to content

worldcoin/bedrock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Banner image

Bedrock

Foundational library which powers World App's crypto wallet.

🧱 Local Development & Contributing

Review our CONTRIBUTING guide. Including details on how to run this project locally.

πŸ¦β€πŸ”₯ Swift Bindings

Bedrock ships with foreign bindings for native Swift. All details can be found in the /swift folder.

🧬 Kotlin Bindings

Bedrock ships with foreign bindings for native Kotlin. All details can be found in the /kotlin folder.

🌍 Global Configuration

Bedrock provides a global configuration system for managing environment settings across your application.

Initialization

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)

πŸ› οΈ Error Handling & Logging Tooling

Each module should implement its own error enum. See tooling_tests for example references.

#[bedrock_error] Macro

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() and from_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())
}

#[bedrock_export] Macro

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

Context-Aware Logging

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!

Manual Context Management

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

About

Foundational library which powers World App's crypto wallet.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages