wallet_export/
wallet_export.rs1use anyhow::Result;
23use hex::ToHex;
24use privy_rs::{AuthorizationContext, JwtUser, PrivateKey, PrivyClient};
25use tracing_subscriber::EnvFilter;
26
27#[tokio::main]
28async fn main() -> Result<()> {
29 tracing_subscriber::fmt()
30 .with_env_filter(
31 EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
32 )
33 .init();
34
35 let wallet_id =
37 std::env::var("PRIVY_WALLET_ID").expect("PRIVY_WALLET_ID environment variable not set");
38
39 tracing::info!(
40 "initializing privy client from environment, wallet_id: {}",
41 wallet_id
42 );
43
44 tracing::info!("Generated HPKE key pair for encryption");
45
46 let private_key = std::fs::read_to_string("private_key.pem")?;
47
48 let client = PrivyClient::new_from_env()?;
49
50 let ctx = AuthorizationContext::new()
51 .push(PrivateKey(private_key))
52 .push(JwtUser(client.clone(), "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhbGV4QGFybHlvbi5kZXYiLCJpYXQiOjEwMDAwMDAwMDAwMH0.IpNgavH95CFZPjkzQW4eyxMIfJ-O_5cIaDyu_6KRXffykjYDRwxTgFJuYq0F6d8wSXf4de-vzfBRWSKMISM3rJdlhximYINGJB14mJFCD87VMLFbTpHIXcv7hc1AAYMPGhOsRkYfYXuvVopKszMvhupmQYJ1npSvKWNeBniIyOHYv4xebZD8L0RVlPvuEKTXTu-CDfs2rMwvD9g_wiBznS3uMF3v_KPaY6x0sx9zeCSxAH9zvhMMtct_Ad9kuoUncGpRzNhEk6JlVccN2Leb1JzbldxSywyS2AApD05u-GFAgFDN3P39V3qgRTGDuuUfUvKQ9S4rbu5El9Qq1CJTeA".to_string()));
53
54 let secret_key = client.wallets().export(&wallet_id, &ctx).await?;
56
57 tracing::info!("Successfully decrypted private key");
58 tracing::warn!("SECURITY WARNING: Private key exported and decrypted!");
59 println!(
60 "Decrypted private key (hex): {}",
61 secret_key.encode_hex::<String>()
62 );
63
64 Ok(())
65}