use crate::pattern::Pattern;
use zeroize::Zeroize;
#[derive(Debug, Clone)]
pub struct KeyExport {
pub label: String,
pub value: String,
pub hint: Option<String>,
}
impl Drop for KeyExport {
fn drop(&mut self) {
self.value.zeroize();
}
}
#[derive(Debug, Clone)]
pub struct KeypairResult {
pub address: String,
pub exports: Vec<KeyExport>,
}
pub enum GrindAttempt {
Secret32([u8; 32]),
}
impl GrindAttempt {
pub fn secret_bytes(&self) -> [u8; 32] {
let GrindAttempt::Secret32(bytes) = self;
*bytes
}
}
impl Drop for GrindAttempt {
fn drop(&mut self) {
let GrindAttempt::Secret32(bytes) = self;
bytes.zeroize();
}
}
pub trait ChainGrinder: Send + Sync + Clone {
fn id(&self) -> &'static str;
fn display_name(&self) -> &'static str;
fn grind_attempt(&self) -> (String, GrindAttempt);
fn finalize(&self, attempt: GrindAttempt) -> KeypairResult;
fn build_pattern(
&self,
prefix: Option<&str>,
suffix: Option<&str>,
contains: Option<&str>,
exact: bool,
) -> Result<Pattern, String>;
fn expected_attempts(&self, pattern: &Pattern) -> f64;
fn matches(&self, address: &str, pattern: &Pattern) -> bool;
fn supports_exact_case(&self) -> bool;
fn pattern_hint(&self) -> &'static str;
}