rustywallet_import/
types.rs

1//! Types for import results.
2
3use rustywallet_keys::prelude::PrivateKey;
4use rustywallet_hd::Network;
5
6/// Detected import format.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum ImportFormat {
9    /// Wallet Import Format (WIF)
10    Wif,
11    /// Raw hex (64 characters)
12    Hex,
13    /// BIP39 mnemonic phrase
14    Mnemonic,
15    /// Electrum seed format
16    ElectrumSeed,
17    /// BIP38 encrypted key
18    Bip38,
19    /// Mini private key (Casascius)
20    MiniKey,
21}
22
23impl std::fmt::Display for ImportFormat {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            ImportFormat::Wif => write!(f, "WIF"),
27            ImportFormat::Hex => write!(f, "Hex"),
28            ImportFormat::Mnemonic => write!(f, "Mnemonic"),
29            ImportFormat::ElectrumSeed => write!(f, "Electrum Seed"),
30            ImportFormat::Bip38 => write!(f, "BIP38"),
31            ImportFormat::MiniKey => write!(f, "Mini Key"),
32        }
33    }
34}
35
36/// Result of a successful import.
37#[derive(Debug)]
38pub struct ImportResult {
39    /// The imported private key
40    pub private_key: PrivateKey,
41    /// Detected format
42    pub format: ImportFormat,
43    /// Detected network (if applicable)
44    pub network: Option<Network>,
45    /// Whether the key is compressed (for WIF)
46    pub compressed: bool,
47    /// Additional metadata
48    pub metadata: ImportMetadata,
49}
50
51/// Additional metadata from import.
52#[derive(Debug, Default)]
53pub struct ImportMetadata {
54    /// Derivation path (for mnemonic imports)
55    pub derivation_path: Option<String>,
56    /// Number of words (for mnemonic)
57    pub word_count: Option<usize>,
58    /// Whether passphrase was used
59    pub has_passphrase: bool,
60}
61
62impl ImportResult {
63    /// Create a new import result.
64    pub fn new(private_key: PrivateKey, format: ImportFormat) -> Self {
65        Self {
66            private_key,
67            format,
68            network: None,
69            compressed: true,
70            metadata: ImportMetadata::default(),
71        }
72    }
73
74    /// Set the network.
75    pub fn with_network(mut self, network: Network) -> Self {
76        self.network = Some(network);
77        self
78    }
79
80    /// Set compressed flag.
81    pub fn with_compressed(mut self, compressed: bool) -> Self {
82        self.compressed = compressed;
83        self
84    }
85
86    /// Set metadata.
87    pub fn with_metadata(mut self, metadata: ImportMetadata) -> Self {
88        self.metadata = metadata;
89        self
90    }
91}