From df67684cac4c413c7c9d3fb6edfdf7c2f79b6345 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sun, 29 Aug 2021 17:23:33 +0200
Subject: [PATCH] refact: simplify key displaying

---
 src/crypto/duniter_key.rs | 8 ++++++++
 src/lib.rs                | 7 ++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/crypto/duniter_key.rs b/src/crypto/duniter_key.rs
index 4a30681..69253a1 100644
--- a/src/crypto/duniter_key.rs
+++ b/src/crypto/duniter_key.rs
@@ -31,6 +31,14 @@ impl std::fmt::Display for DuniterKey {
 
 impl DuniterKey {
 
+    pub fn get_public_base58(&self) -> String {
+        bs58::encode(self.public).into_string()
+    }
+
+    pub fn get_secret_base58(&self) -> String {
+        bs58::encode(self.secret).into_string()
+    }
+
     pub fn sign(&self, message: &str) -> DuniterSignature {
         DuniterSignature::new(ed25519::signature(message.as_bytes(), &self.secret[..]))
     }
diff --git a/src/lib.rs b/src/lib.rs
index c1068db..72795cd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,14 +4,11 @@ use crate::crypto::duniter_key::{DuniterKey, ToDuniterKey};
 use crate::crypto::scrypt_duniter_key::ScryptDuniterKey;
 
 pub fn compute_pub(sdk: impl ToDuniterKey) -> String {
-    String::from(sdk.derive().to_string().split(":").next().unwrap())
+    sdk.derive().get_public_base58()
 }
 
 pub fn compute_sec(sdk: impl ToDuniterKey) -> String {
-    let key_str = sdk.derive().to_string();
-    let mut split = key_str.split(":");
-    split.next();
-    String::from(split.next().unwrap())
+    sdk.derive().get_secret_base58()
 }
 
 pub fn compute_key(sdk: impl ToDuniterKey) -> String {
-- 
GitLab