From e00c34041a67b3e59de4aaf0c8efe24823a1e5f3 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Tue, 1 Dec 2020 18:54:35 +0100 Subject: added ability to sign --- src/hdk/path.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/hdk') diff --git a/src/hdk/path.rs b/src/hdk/path.rs index f67446a..3d7c0a3 100644 --- a/src/hdk/path.rs +++ b/src/hdk/path.rs @@ -1,7 +1,10 @@ //! Module implementing parsing for BIP-0032 HD paths used for key derivation. use anyhow::{anyhow, Context as _, Result}; -use std::str::FromStr; +use std::{ + fmt::{self, Display, Formatter}, + str::FromStr, +}; /// A parsed hierarchical derivation path. #[derive(Debug)] @@ -16,6 +19,17 @@ impl Path { } } +impl Display for Path { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + f.write_str("m")?; + for component in self.components() { + write!(f, "/{}", component)?; + } + + Ok(()) + } +} + impl FromStr for Path { type Err = anyhow::Error; @@ -40,6 +54,15 @@ pub enum Component { Normal(u32), } +impl Display for Component { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + Self::Hardened(value) => write!(f, "{}'", value), + Self::Normal(value) => write!(f, "{}", value), + } + } +} + impl FromStr for Component { type Err = anyhow::Error; -- cgit v1.2.3