use crypto::keys::bip44::Bip44;
use serde::{Deserialize, Serialize};
use crate::{
types::block::output::{Output, OutputId, OutputMetadata},
utils::serde::bip44::option_bip44,
};
#[cfg(feature = "stronghold")]
#[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StrongholdDto {
pub password: Option<crate::client::Password>,
pub timeout: Option<u64>,
pub snapshot_path: String,
}
#[cfg(feature = "stronghold")]
impl core::fmt::Debug for StrongholdDto {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("StrongholdDto")
.field("timeout", &self.timeout)
.field("snapshot_path", &self.snapshot_path)
.finish()
}
}
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub struct GenerateAddressOptions {
pub internal: bool,
pub ledger_nano_prompt: bool,
}
impl GenerateAddressOptions {
pub const fn internal() -> Self {
Self {
internal: true,
ledger_nano_prompt: false,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct LedgerApp {
pub(crate) name: String,
pub(crate) version: String,
}
impl LedgerApp {
pub fn name(&self) -> &String {
&self.name
}
pub fn version(&self) -> &String {
&self.version
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum LedgerDeviceType {
#[serde(alias = "ledgerNanoS")]
LedgerNanoS,
#[serde(alias = "ledgerNanoX")]
LedgerNanoX,
#[serde(alias = "ledgerNanoSPlus")]
LedgerNanoSPlus,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LedgerNanoStatus {
pub(crate) connected: bool,
pub(crate) locked: Option<bool>,
pub(crate) blind_signing_enabled: bool,
pub(crate) app: Option<LedgerApp>,
pub(crate) device: Option<LedgerDeviceType>,
pub(crate) buffer_size: Option<usize>,
}
impl LedgerNanoStatus {
pub fn connected(&self) -> bool {
self.connected
}
pub fn locked(&self) -> Option<bool> {
self.locked
}
pub fn blind_signing_enabled(&self) -> bool {
self.blind_signing_enabled
}
pub fn app(&self) -> Option<&LedgerApp> {
self.app.as_ref()
}
pub fn device(&self) -> Option<LedgerDeviceType> {
self.device
}
pub fn buffer_size(&self) -> Option<usize> {
self.buffer_size
}
}
#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InputSigningData {
pub output: Output,
pub output_metadata: OutputMetadata,
#[serde(with = "option_bip44", default)]
pub chain: Option<Bip44>,
}
impl InputSigningData {
pub fn output_id(&self) -> &OutputId {
self.output_metadata.output_id()
}
}