rustywallet_export/
types.rs

1//! Types for export operations.
2
3use serde::{Deserialize, Serialize};
4
5/// Network type for export.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(rename_all = "lowercase")]
8pub enum Network {
9    /// Bitcoin mainnet
10    Mainnet,
11    /// Bitcoin testnet
12    Testnet,
13}
14
15impl std::fmt::Display for Network {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            Network::Mainnet => write!(f, "mainnet"),
19            Network::Testnet => write!(f, "testnet"),
20        }
21    }
22}
23
24/// Options for hex export.
25#[derive(Debug, Clone, Default)]
26pub struct HexOptions {
27    /// Include 0x prefix
28    pub prefix: bool,
29    /// Use uppercase hex
30    pub uppercase: bool,
31}
32
33impl HexOptions {
34    /// Create default options (no prefix, lowercase).
35    pub fn new() -> Self {
36        Self::default()
37    }
38
39    /// Set prefix option.
40    pub fn with_prefix(mut self, prefix: bool) -> Self {
41        self.prefix = prefix;
42        self
43    }
44
45    /// Set uppercase option.
46    pub fn with_uppercase(mut self, uppercase: bool) -> Self {
47        self.uppercase = uppercase;
48        self
49    }
50}
51
52/// Exported key data in JSON format.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct KeyExport {
55    /// Bitcoin address (P2PKH)
56    pub address: String,
57    /// WIF format
58    pub wif: String,
59    /// Hex format (no prefix)
60    pub hex: String,
61    /// Compressed public key hex
62    pub public_key: String,
63    /// Network
64    pub network: String,
65    /// Whether key is compressed
66    pub compressed: bool,
67}
68
69/// CSV column options.
70#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71pub enum CsvColumn {
72    /// Bitcoin address
73    Address,
74    /// WIF format
75    Wif,
76    /// Hex format
77    Hex,
78    /// Public key
79    PublicKey,
80    /// Network
81    Network,
82}
83
84impl CsvColumn {
85    /// Get column header name.
86    pub fn header(&self) -> &'static str {
87        match self {
88            CsvColumn::Address => "address",
89            CsvColumn::Wif => "wif",
90            CsvColumn::Hex => "hex",
91            CsvColumn::PublicKey => "public_key",
92            CsvColumn::Network => "network",
93        }
94    }
95}
96
97/// Options for CSV export.
98#[derive(Debug, Clone)]
99pub struct CsvOptions {
100    /// Columns to include
101    pub columns: Vec<CsvColumn>,
102    /// Include header row
103    pub header: bool,
104    /// Network for export
105    pub network: Network,
106}
107
108impl Default for CsvOptions {
109    fn default() -> Self {
110        Self {
111            columns: vec![
112                CsvColumn::Address,
113                CsvColumn::Wif,
114                CsvColumn::Hex,
115            ],
116            header: true,
117            network: Network::Mainnet,
118        }
119    }
120}
121
122impl CsvOptions {
123    /// Create default options.
124    pub fn new() -> Self {
125        Self::default()
126    }
127
128    /// Set columns.
129    pub fn with_columns(mut self, columns: Vec<CsvColumn>) -> Self {
130        self.columns = columns;
131        self
132    }
133
134    /// Set header option.
135    pub fn with_header(mut self, header: bool) -> Self {
136        self.header = header;
137        self
138    }
139
140    /// Set network.
141    pub fn with_network(mut self, network: Network) -> Self {
142        self.network = network;
143        self
144    }
145}
146
147/// Paper wallet data.
148#[derive(Debug, Clone, Serialize, Deserialize)]
149pub struct PaperWallet {
150    /// Public address for receiving
151    pub address: String,
152    /// Private key in WIF format
153    pub wif: String,
154    /// Network
155    pub network: String,
156    /// Address type (p2pkh, p2wpkh, etc.)
157    pub address_type: String,
158}
159
160/// Address type for paper wallet.
161#[derive(Debug, Clone, Copy, PartialEq, Eq)]
162pub enum AddressType {
163    /// Legacy P2PKH (1...)
164    P2PKH,
165    /// Native SegWit P2WPKH (bc1q...)
166    P2WPKH,
167    /// Taproot P2TR (bc1p...)
168    P2TR,
169}
170
171impl std::fmt::Display for AddressType {
172    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
173        match self {
174            AddressType::P2PKH => write!(f, "p2pkh"),
175            AddressType::P2WPKH => write!(f, "p2wpkh"),
176            AddressType::P2TR => write!(f, "p2tr"),
177        }
178    }
179}
180
181/// Options for BIP21 URI generation.
182#[derive(Debug, Clone, Default)]
183pub struct Bip21Options {
184    /// Amount in BTC
185    pub amount: Option<f64>,
186    /// Label for the address
187    pub label: Option<String>,
188    /// Message/memo
189    pub message: Option<String>,
190}
191
192impl Bip21Options {
193    /// Create empty options.
194    pub fn new() -> Self {
195        Self::default()
196    }
197
198    /// Set amount.
199    pub fn with_amount(mut self, amount: f64) -> Self {
200        self.amount = Some(amount);
201        self
202    }
203
204    /// Set label.
205    pub fn with_label(mut self, label: impl Into<String>) -> Self {
206        self.label = Some(label.into());
207        self
208    }
209
210    /// Set message.
211    pub fn with_message(mut self, message: impl Into<String>) -> Self {
212        self.message = Some(message.into());
213        self
214    }
215}