Skip to main content

vanity_core/
chain.rs

1use crate::pattern::Pattern;
2
3#[derive(Debug, Clone)]
4pub struct KeyExport {
5    pub label: String,
6    pub value: String,
7    pub hint: Option<String>,
8}
9
10#[derive(Debug, Clone)]
11pub struct KeypairResult {
12    pub address: String,
13    pub exports: Vec<KeyExport>,
14}
15
16/// Lightweight per-attempt state — export formats are built only on a match.
17pub enum GrindAttempt {
18    Solana(solana_sdk::signature::Keypair),
19    /// secp256k1 / ed25519 secret key bytes (chain-specific finalize)
20    Secret32([u8; 32]),
21}
22
23pub trait ChainGrinder: Send + Sync + Clone {
24    fn id(&self) -> &'static str;
25    fn display_name(&self) -> &'static str;
26
27    /// Generate address + retain secret material for finalize on match.
28    fn grind_attempt(&self) -> (String, GrindAttempt);
29
30    /// Build export formats from a winning attempt (called once on success).
31    fn finalize(&self, attempt: GrindAttempt) -> KeypairResult;
32
33    fn build_pattern(
34        &self,
35        prefix: Option<&str>,
36        suffix: Option<&str>,
37        exact: bool,
38    ) -> Result<Pattern, String>;
39    fn expected_attempts(&self, pattern: &Pattern) -> f64;
40    fn matches(&self, address: &str, pattern: &Pattern) -> bool;
41    fn supports_exact_case(&self) -> bool;
42    fn pattern_hint(&self) -> &'static str;
43}