From cd0efe6372ea8030190781fff8dc5bd9b1b320a3 Mon Sep 17 00:00:00 2001 From: Kasper Ziemianek Date: Mon, 8 Dec 2025 13:32:24 +0100 Subject: [PATCH] add cli cmd for generating oa bytes --- tee-worker/omni-executor/cli/src/main.rs | 74 +++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/tee-worker/omni-executor/cli/src/main.rs b/tee-worker/omni-executor/cli/src/main.rs index 0e86d3b559..0c435e1708 100644 --- a/tee-worker/omni-executor/cli/src/main.rs +++ b/tee-worker/omni-executor/cli/src/main.rs @@ -9,7 +9,7 @@ use oe_client_aa::{ }; use oe_client_ethereum::{AlloyRpcProvider, RpcProvider}; use oe_core::types::SerializablePackedUserOperation; -use oe_primitives::ChainId; +use oe_primitives::{ChainId, UserId}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use tracing::{debug, info}; @@ -343,6 +343,25 @@ enum Commands { #[arg(long, help = "Gas limit for call execution (decimal)")] call_gas: u64, }, + + /// Generate OmniAccount bytes from user identity and client ID + GenerateOABytes { + #[arg( + long, + help = "User identifier - format depends on user_type (e.g., 0x1234... for Evm, email@example.com for Email, base58 for Solana)" + )] + user_id: String, + + #[arg(long, default_value = "wildmeta")] + client_id: String, + + #[arg( + long, + default_value = "evm", + help = "User ID type: Evm, Substrate, Solana, Bitcoin, Email, Twitter, Discord, Google, Apple, Pumpx, Passkey" + )] + user_type: String, + }, } struct RpcClient { @@ -440,6 +459,23 @@ fn parse_owner_type(oa_type_str: &str) -> Result { } } +fn parse_user_id(user_type_str: &str, user_id_str: &str) -> Result { + match user_type_str.to_lowercase().as_str() { + "email" => Ok(UserId::Email(user_id_str.to_string())), + "evm" => Ok(UserId::Evm(user_id_str.to_string())), + "substrate" => Ok(UserId::Substrate(user_id_str.to_string())), + "bitcoin" => Ok(UserId::Bitcoin(user_id_str.to_string())), + "solana" => Ok(UserId::Solana(user_id_str.to_string())), + "twitter" => Ok(UserId::Twitter(user_id_str.to_string())), + "discord" => Ok(UserId::Discord(user_id_str.to_string())), + "apple" => Ok(UserId::Apple(user_id_str.to_string())), + "google" => Ok(UserId::Google(user_id_str.to_string())), + "pumpx" => Ok(UserId::Pumpx(user_id_str.to_string())), + "passkey" => Ok(UserId::Passkey(user_id_str.to_string())), + _ => anyhow::bail!("Invalid user type '{}'. Valid types are: Email, Evm, Substrate, Bitcoin, Solana, Twitter, Discord, Apple, Google, Pumpx, Passkey", user_type_str), + } +} + #[allow(clippy::too_many_arguments)] async fn handle_submit_user_op( client: &RpcClient, @@ -881,6 +917,39 @@ fn handle_pack_gas_limits(verification_gas: u64, call_gas: u64) -> Result<()> { Ok(()) } +fn handle_generate_oa_bytes( + user_id_str: String, + client_id: String, + user_type: String, +) -> Result<()> { + // Parse the user ID based on the user type + let user_id = parse_user_id(&user_type, &user_id_str)?; + + info!("Generating OA bytes for user_id: {:?}, client_id: {}", user_id, client_id); + + // Generate the OmniAccount bytes using the to_omni_account method + let oa = user_id + .to_omni_account(&client_id) + .map_err(|e| anyhow::anyhow!("Failed to generate OmniAccount: {}", e))?; + + let oa_bytes: &[u8] = oa.as_ref(); + + // Convert to hex string + let oa_hex = format!("0x{}", hex::encode(&oa_bytes)); + + info!( + "Generated OA bytes for user_type '{}', user_id '{}', client_id '{}': {}", + user_type, user_id_str, client_id, oa_hex + ); + + println!("OA Bytes: {}", oa_hex); + println!("\nYou can use this value with:"); + println!(" --oa-bytes {} for generate-aa-address command", oa_hex); + println!(" --oa-bytes {} for generate-init-code command", oa_hex); + + Ok(()) +} + #[tokio::main] async fn main() -> Result<()> { tracing_subscriber::fmt::init(); @@ -1020,6 +1089,9 @@ async fn main() -> Result<()> { Commands::PackGasLimits { verification_gas, call_gas } => { handle_pack_gas_limits(verification_gas, call_gas)?; }, + Commands::GenerateOABytes { user_id, client_id, user_type } => { + handle_generate_oa_bytes(user_id, client_id, user_type)?; + }, } Ok(())