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    /// secp256k1 / ed25519 secret key bytes (chain-specific finalize)
19    Secret32([u8; 32]),
20}
21
22pub trait ChainGrinder: Send + Sync + Clone {
23    fn id(&self) -> &'static str;
24    fn display_name(&self) -> &'static str;
25
26    /// Generate address + retain secret material for finalize on match.
27    fn grind_attempt(&self) -> (String, GrindAttempt);
28
29    /// Build export formats from a winning attempt (called once on success).
30    fn finalize(&self, attempt: GrindAttempt) -> KeypairResult;
31
32    fn build_pattern(
33        &self,
34        prefix: Option<&str>,
35        suffix: Option<&str>,
36        exact: bool,
37    ) -> Result<Pattern, String>;
38    fn expected_attempts(&self, pattern: &Pattern) -> f64;
39    fn matches(&self, address: &str, pattern: &Pattern) -> bool;
40    fn supports_exact_case(&self) -> bool;
41    fn pattern_hint(&self) -> &'static str;
42}