Skip to content

Commit

Permalink
Make the software wallet use priv and pub key types
Browse files Browse the repository at this point in the history
  • Loading branch information
brianp committed Apr 23, 2024
1 parent f56952f commit f86d7e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Expand Up @@ -45,6 +45,7 @@ pub enum Instruction {
GetAppName = 0x02,
GetPrivateKey = 0x03,
GetPublicKey = 0x04,
GetScriptSignature = 0x05,
}

impl Instruction {
Expand Down Expand Up @@ -78,7 +79,7 @@ impl<D: Deref<Target = [u8]>> Command<D> {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LedgerWallet {
account: u64,
pubkey: Option<RistrettoPublicKey>,
pub pubkey: Option<RistrettoPublicKey>,
}

impl Display for LedgerWallet {
Expand Down
16 changes: 7 additions & 9 deletions base_layer/common_types/src/wallet_types.rs
Expand Up @@ -28,30 +28,28 @@ use std::{
use chacha20poly1305::aead::OsRng;
use minotari_ledger_wallet_comms::ledger_wallet::LedgerWallet;
use serde::{Deserialize, Serialize};
use tari_crypto::{
keys::{PublicKey, SecretKey},
ristretto::{RistrettoPublicKey, RistrettoSecretKey},
};
use tari_utilities::ByteArray;
use tari_crypto::keys::{PublicKey as PublicKeyTrait, SecretKey};

use crate::types::{PrivateKey, PublicKey};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum WalletType {
Software(Vec<u8>, Vec<u8>), // Make them a priv and pub
Software(PrivateKey, PublicKey), // Make them a priv and pub
Ledger(LedgerWallet),
}

impl Display for WalletType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
WalletType::Software(pk, _k) => write!(f, "Software({:?})", pk),
WalletType::Software(_k, pk) => write!(f, "Software({:?})", pk),
WalletType::Ledger(account) => write!(f, "Ledger({account})"),
}
}
}

impl Default for WalletType {
fn default() -> Self {
let k = RistrettoSecretKey::random(&mut OsRng);
WalletType::Software(RistrettoPublicKey::from_secret_key(&k).to_vec(), k.to_vec())
let k: PrivateKey = SecretKey::random(&mut OsRng);
WalletType::Software(k.clone(), PublicKey::from_secret_key(&k))
}
}

0 comments on commit f86d7e3

Please sign in to comment.