79 lines
4.5 KiB
Rust
79 lines
4.5 KiB
Rust
/// Generate test secp256k1 keypairs for supervisor authentication testing
|
|
///
|
|
/// Run with: cargo run --example generate_test_keys
|
|
|
|
use secp256k1::{Secp256k1, SecretKey, PublicKey};
|
|
use hex;
|
|
|
|
fn main() {
|
|
let secp = Secp256k1::new();
|
|
|
|
println!("\n╔════════════════════════════════════════════════════════════╗");
|
|
println!("║ Test Keypairs for Supervisor Auth ║");
|
|
println!("╚════════════════════════════════════════════════════════════╝\n");
|
|
println!("⚠️ WARNING: These are TEST keypairs only! Never use in production!\n");
|
|
|
|
// Generate 5 keypairs with simple private keys for testing
|
|
let test_keys = vec![
|
|
("Alice (Admin)", "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"),
|
|
("Bob (User)", "fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321"),
|
|
("Charlie (Register)", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
|
|
("Dave (Test)", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
|
|
("Eve (Test)", "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"),
|
|
];
|
|
|
|
for (i, (name, privkey_hex)) in test_keys.iter().enumerate() {
|
|
println!("## Keypair {} - {}", i + 1, name);
|
|
println!("─────────────────────────────────────────────────────────────");
|
|
|
|
// Parse private key
|
|
let privkey_bytes = hex::decode(privkey_hex).expect("Invalid hex");
|
|
let secret_key = SecretKey::from_slice(&privkey_bytes).expect("Invalid private key");
|
|
|
|
// Derive public key
|
|
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
|
|
|
|
// Serialize keys
|
|
let pubkey_uncompressed = hex::encode(public_key.serialize_uncompressed());
|
|
let pubkey_compressed = hex::encode(public_key.serialize());
|
|
|
|
println!("Private Key (hex): 0x{}", privkey_hex);
|
|
println!("Public Key (uncomp): 0x{}", pubkey_uncompressed);
|
|
println!("Public Key (comp): 0x{}", pubkey_compressed);
|
|
println!();
|
|
}
|
|
|
|
println!("\n╔════════════════════════════════════════════════════════════╗");
|
|
println!("║ Usage Examples ║");
|
|
println!("╚════════════════════════════════════════════════════════════╝\n");
|
|
|
|
println!("### Using with OpenRPC Client (Rust)\n");
|
|
println!("```rust");
|
|
println!("use secp256k1::{{Secp256k1, SecretKey}};");
|
|
println!("use hex;");
|
|
println!();
|
|
println!("// Alice's private key for admin access");
|
|
println!("let privkey_hex = \"1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef\";");
|
|
println!("let privkey_bytes = hex::decode(privkey_hex).unwrap();");
|
|
println!("let secret_key = SecretKey::from_slice(&privkey_bytes).unwrap();");
|
|
println!();
|
|
println!("// Use with client");
|
|
println!("let client = SupervisorClient::new_with_keypair(");
|
|
println!(" \"http://127.0.0.1:3030\",");
|
|
println!(" secret_key");
|
|
println!(");");
|
|
println!("```\n");
|
|
|
|
println!("### Testing Different Scopes\n");
|
|
println!("1. **Admin Scope** - Use Alice's keypair for full admin access");
|
|
println!("2. **User Scope** - Use Bob's keypair for limited user access");
|
|
println!("3. **Register Scope** - Use Charlie's keypair for runner registration\n");
|
|
|
|
println!("### Quick Copy-Paste Keys\n");
|
|
println!("Alice (Admin): 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef");
|
|
println!("Bob (User): fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321");
|
|
println!("Charlie (Reg): aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
println!("Dave (Test): bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
|
|
println!("Eve (Test): cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\n");
|
|
}
|