#![allow(clippy::upper_case_acronyms)]
use std::fmt;
use thiserror::Error;
#[derive(Clone, Debug)]
pub enum DerivationType {
LedgerLive(usize),
Legacy(usize),
Other(String),
}
impl fmt::Display for DerivationType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(
f,
"{}",
match self {
DerivationType::Legacy(index) => format!("m/44'/60'/0'/{index}"),
DerivationType::LedgerLive(index) => format!("m/44'/60'/{index}'/0/0"),
DerivationType::Other(inner) => inner.to_owned(),
}
)
}
}
#[derive(Error, Debug)]
pub enum LedgerError {
#[error(transparent)]
LedgerError(#[from] coins_ledger::errors::LedgerError),
#[error("Received unexpected response from device. Expected data in response, found none.")]
UnexpectedNullResponse,
#[error(transparent)]
HexError(#[from] hex::FromHexError),
#[error(transparent)]
SemVerError(#[from] semver::Error),
#[error("error encoding eip712 struct: {0:?}")]
Eip712Error(String),
#[error("Ledger ethereum app requires at least version: {0:?}")]
UnsupportedAppVersion(String),
#[error("Cannot deserialize ledger response, insufficient bytes. Got {got} expected at least {at_least}")]
ShortResponse { got: usize, at_least: usize },
#[error("Payload must not be empty")]
EmptyPayload,
}
pub const P1_FIRST: u8 = 0x00;
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum INS {
GET_PUBLIC_KEY = 0x02,
SIGN = 0x04,
GET_APP_CONFIGURATION = 0x06,
SIGN_PERSONAL_MESSAGE = 0x08,
SIGN_ETH_EIP_712 = 0x0C,
}
impl std::fmt::Display for INS {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
INS::GET_PUBLIC_KEY => write!(f, "GET_PUBLIC_KEY"),
INS::SIGN => write!(f, "SIGN"),
INS::GET_APP_CONFIGURATION => write!(f, "GET_APP_CONFIGURATION"),
INS::SIGN_PERSONAL_MESSAGE => write!(f, "SIGN_PERSONAL_MESSAGE"),
INS::SIGN_ETH_EIP_712 => write!(f, "SIGN_ETH_EIP_712"),
}
}
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum P1 {
NON_CONFIRM = 0x00,
MORE = 0x80,
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum P2 {
NO_CHAINCODE = 0x00,
}