Skip to main content

vanity_core/
chain.rs

1use crate::pattern::Pattern;
2use zeroize::Zeroize;
3
4#[derive(Debug, Clone)]
5pub struct KeyExport {
6    pub label: String,
7    pub value: String,
8    pub hint: Option<String>,
9}
10
11impl Drop for KeyExport {
12    fn drop(&mut self) {
13        self.value.zeroize();
14    }
15}
16
17#[derive(Debug, Clone)]
18pub struct KeypairResult {
19    pub address: String,
20    pub exports: Vec<KeyExport>,
21}
22
23/// Lightweight per-attempt state — export formats are built only on a match.
24pub enum GrindAttempt {
25    /// secp256k1 / ed25519 secret key bytes (chain-specific finalize)
26    Secret32([u8; 32]),
27}
28
29impl GrindAttempt {
30    pub fn secret_bytes(&self) -> [u8; 32] {
31        let GrindAttempt::Secret32(bytes) = self;
32        *bytes
33    }
34}
35
36impl Drop for GrindAttempt {
37    fn drop(&mut self) {
38        let GrindAttempt::Secret32(bytes) = self;
39        bytes.zeroize();
40    }
41}
42
43pub trait ChainGrinder: Send + Sync + Clone {
44    fn id(&self) -> &'static str;
45    fn display_name(&self) -> &'static str;
46
47    /// Generate address + retain secret material for finalize on match.
48    fn grind_attempt(&self) -> (String, GrindAttempt);
49
50    /// Build export formats from a winning attempt (called once on success).
51    fn finalize(&self, attempt: GrindAttempt) -> KeypairResult;
52
53    fn build_pattern(
54        &self,
55        prefix: Option<&str>,
56        suffix: Option<&str>,
57        contains: Option<&str>,
58        exact: bool,
59    ) -> Result<Pattern, String>;
60    fn expected_attempts(&self, pattern: &Pattern) -> f64;
61    fn matches(&self, address: &str, pattern: &Pattern) -> bool;
62    fn supports_exact_case(&self) -> bool;
63    fn pattern_hint(&self) -> &'static str;
64}