Skip to content

Commit

Permalink
feat!: new tari address scheme (#6353)
Browse files Browse the repository at this point in the history
Description
--- 
Changes the tari address scheme to support view keys and spend keys. 
Makes network and features human-readable

Motivation and Context
---
This allows Tari to support stealth one-sided transactions via Hardware
devices.
Makes features and network human readable. 

How Has This Been Tested?
---

---------

Co-authored-by: Hansie Odendaal <39146854+hansieodendaal@users.noreply.github.com>
  • Loading branch information
SWvheerden and hansieodendaal committed May 30, 2024
1 parent 561ac67 commit 4c0ce46
Show file tree
Hide file tree
Showing 66 changed files with 2,518 additions and 856 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions applications/minotari_app_utilities/src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ impl FromStr for UniPublicKey {
Ok(Self(PublicKey::from(&emoji_id)))
} else if let Ok(public_key) = PublicKey::from_hex(key) {
Ok(Self(public_key))
} else if let Ok(tari_address) = TariAddress::from_hex(key) {
Ok(Self(tari_address.public_key().clone()))
} else {
Err(UniIdError::UnknownIdType)
}
Expand Down Expand Up @@ -136,7 +134,7 @@ impl TryFrom<UniNodeId> for PublicKey {
fn try_from(id: UniNodeId) -> Result<Self, Self::Error> {
match id {
UniNodeId::PublicKey(public_key) => Ok(public_key),
UniNodeId::TariAddress(tari_address) => Ok(tari_address.public_key().clone()),
UniNodeId::TariAddress(tari_address) => Ok(tari_address.public_spend_key().clone()),
UniNodeId::NodeId(_) => Err(UniIdError::Nonconvertible),
}
}
Expand All @@ -147,7 +145,7 @@ impl From<UniNodeId> for NodeId {
match id {
UniNodeId::PublicKey(public_key) => NodeId::from_public_key(&public_key),
UniNodeId::NodeId(node_id) => node_id,
UniNodeId::TariAddress(tari_address) => NodeId::from_public_key(tari_address.public_key()),
UniNodeId::TariAddress(tari_address) => NodeId::from_public_key(tari_address.public_spend_key()),
}
}
}
8 changes: 4 additions & 4 deletions applications/minotari_console_wallet/src/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Completed(completed) => TransactionEvent {
event,
tx_id: completed.tx_id.to_string(),
source_address: completed.source_address.to_bytes().to_vec(),
dest_address: completed.destination_address.to_bytes().to_vec(),
source_address: completed.source_address.to_vec(),
dest_address: completed.destination_address.to_vec(),
status: completed.status.to_string(),
direction: completed.direction.to_string(),
amount: completed.amount.as_u64(),
Expand All @@ -34,7 +34,7 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
event,
tx_id: outbound.tx_id.to_string(),
source_address: vec![],
dest_address: outbound.destination_address.to_bytes().to_vec(),
dest_address: outbound.destination_address.to_vec(),
status: outbound.status.to_string(),
direction: "outbound".to_string(),
amount: outbound.amount.as_u64(),
Expand All @@ -43,7 +43,7 @@ pub fn convert_to_transaction_event(event: String, source: TransactionWrapper) -
TransactionWrapper::Inbound(inbound) => TransactionEvent {
event,
tx_id: inbound.tx_id.to_string(),
source_address: inbound.source_address.to_bytes().to_vec(),
source_address: inbound.source_address.to_vec(),
dest_address: vec![],
status: inbound.status.to_string(),
direction: "inbound".to_string(),
Expand Down
35 changes: 19 additions & 16 deletions applications/minotari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
}

async fn get_address(&self, _: Request<tari_rpc::Empty>) -> Result<Response<GetAddressResponse>, Status> {
let network = self.wallet.network.as_network();
let pk = self.wallet.comms.node_identity().public_key().clone();
let address = TariAddress::new(pk, network);
let address = self
.wallet
.get_wallet_address()
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;
Ok(Response::new(GetAddressResponse {
address: address.to_bytes().to_vec(),
address: address.to_vec(),
}))
}

Expand Down Expand Up @@ -650,10 +652,11 @@ impl wallet_server::Wallet for WalletGrpcServer {
.await
.map(|tx| tx.into_iter())
.map_err(|err| Status::unknown(err.to_string()))?;

let wallet_pk = self.wallet.comms.node_identity_ref().public_key();
let wallet_network = self.wallet.network.as_network();
let wallet_address = TariAddress::new(wallet_pk.clone(), wallet_network);
let wallet_address = self
.wallet
.get_wallet_address()
.await
.map_err(|e| Status::internal(format!("{:?}", e)))?;
let transactions = transactions
.map(|(tx_id, tx)| match tx {
Some(tx) => convert_wallet_transaction_into_transaction_info(tx, &wallet_address),
Expand Down Expand Up @@ -755,8 +758,8 @@ impl wallet_server::Wallet for WalletGrpcServer {
let response = GetCompletedTransactionsResponse {
transaction: Some(TransactionInfo {
tx_id: txn.tx_id.into(),
source_address: txn.source_address.to_bytes().to_vec(),
dest_address: txn.destination_address.to_bytes().to_vec(),
source_address: txn.source_address.to_vec(),
dest_address: txn.destination_address.to_vec(),
status: TransactionStatus::from(txn.status.clone()) as i32,
amount: txn.amount.into(),
is_cancelled: txn.cancelled.is_some(),
Expand Down Expand Up @@ -1097,8 +1100,8 @@ fn convert_wallet_transaction_into_transaction_info(
match tx {
PendingInbound(tx) => TransactionInfo {
tx_id: tx.tx_id.into(),
source_address: tx.source_address.to_bytes().to_vec(),
dest_address: wallet_address.to_bytes().to_vec(),
source_address: tx.source_address.to_vec(),
dest_address: wallet_address.to_vec(),
status: TransactionStatus::from(tx.status) as i32,
amount: tx.amount.into(),
is_cancelled: tx.cancelled,
Expand All @@ -1110,8 +1113,8 @@ fn convert_wallet_transaction_into_transaction_info(
},
PendingOutbound(tx) => TransactionInfo {
tx_id: tx.tx_id.into(),
source_address: wallet_address.to_bytes().to_vec(),
dest_address: tx.destination_address.to_bytes().to_vec(),
source_address: wallet_address.to_vec(),
dest_address: tx.destination_address.to_vec(),
status: TransactionStatus::from(tx.status) as i32,
amount: tx.amount.into(),
is_cancelled: tx.cancelled,
Expand All @@ -1123,8 +1126,8 @@ fn convert_wallet_transaction_into_transaction_info(
},
Completed(tx) => TransactionInfo {
tx_id: tx.tx_id.into(),
source_address: tx.source_address.to_bytes().to_vec(),
dest_address: tx.destination_address.to_bytes().to_vec(),
source_address: tx.source_address.to_vec(),
dest_address: tx.destination_address.to_vec(),
status: TransactionStatus::from(tx.status) as i32,
amount: tx.amount.into(),
is_cancelled: tx.cancelled.is_some(),
Expand Down
7 changes: 5 additions & 2 deletions applications/minotari_console_wallet/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@

#![allow(dead_code, unused)]

use std::ptr;

use chrono::offset::Local;
use futures::FutureExt;
use log::*;
use minotari_wallet::{
connectivity_service::WalletConnectivityHandle,
error::WalletError,
storage::sqlite_db::wallet::WalletSqliteDatabase,
utxo_scanner_service::{handle::UtxoScannerEvent, service::UtxoScannerService},
WalletSqlite,
Expand All @@ -37,7 +40,7 @@ use tari_crypto::tari_utilities::Hidden;
use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic, SeedWords};
use tari_shutdown::Shutdown;
use tari_utilities::hex::Hex;
use tokio::sync::broadcast;
use tokio::{runtime::Runtime, sync::broadcast};
use zeroize::{Zeroize, Zeroizing};

use crate::wallet_modes::PeerConfig;
Expand Down Expand Up @@ -122,7 +125,7 @@ pub async fn wallet_recovery(
.with_peers(peer_public_keys)
// Do not make this a small number as wallet recovery needs to be resilient
.with_retry_limit(retry_limit)
.build_with_wallet(wallet, shutdown_signal);
.build_with_wallet(wallet, shutdown_signal).await.map_err(|e| ExitError::new(ExitCode::RecoveryError, e))?;

let mut event_stream = recovery_task.get_event_receiver();

Expand Down
12 changes: 7 additions & 5 deletions applications/minotari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use minotari_wallet::{util::wallet_identity::WalletIdentity, WalletConfig, WalletSqlite};
use tari_common::exit_codes::ExitError;
use tari_comms::peer_manager::Peer;
use tokio::runtime::Handle;
use tui::{
Expand Down Expand Up @@ -69,15 +70,16 @@ pub struct App<B: Backend> {
}

impl<B: Backend> App<B> {
pub fn new(
pub async fn new(
title: String,
wallet: WalletSqlite,
wallet_config: WalletConfig,
base_node_selected: Peer,
base_node_config: PeerConfig,
notifier: Notifier,
) -> Self {
let wallet_id = WalletIdentity::new(wallet.comms.node_identity(), wallet.network.as_network());
) -> Result<Self, ExitError> {
let wallet_address = wallet.get_wallet_address().await?;
let wallet_id = WalletIdentity::new(wallet.comms.node_identity(), wallet_address);
let app_state = AppState::new(
&wallet_id,
wallet,
Expand All @@ -101,15 +103,15 @@ impl<B: Backend> App<B> {
let base_node_status = BaseNode::new();
let menu = Menu::new();

Self {
Ok(Self {
title,
should_quit: false,
app_state,
tabs,
base_node_status,
menu,
notifier,
}
})
}

pub fn on_control_key(&mut self, c: char) {
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use ui_error::UiError;

use crate::utils::events::{Event, EventStream};

pub const MAX_WIDTH: u16 = 133;
pub const MAX_WIDTH: u16 = 157;

pub fn run(app: App<CrosstermBackend<Stdout>>) -> Result<(), ExitError> {
let mut app = app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,11 @@ impl AppStateInner {
}

pub async fn refresh_network_id(&mut self) -> Result<(), UiError> {
let wallet_id = WalletIdentity::new(self.wallet.comms.node_identity(), self.wallet.network.as_network());
let wallet_id = self.wallet.get_wallet_id().await?;
let eid = wallet_id.address.to_emoji_string();
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_id.network,
wallet_id.network(),
wallet_id.address.to_hex()
);
let code = QrCode::new(qr_link).unwrap();
Expand Down Expand Up @@ -1278,7 +1278,7 @@ impl AppStateData {
let eid = wallet_identity.address.to_emoji_string();
let qr_link = format!(
"tari://{}/transactions/send?tariAddress={}",
wallet_identity.network,
wallet_identity.network(),
wallet_identity.address.to_hex()
);
let code = QrCode::new(qr_link).unwrap();
Expand Down
9 changes: 5 additions & 4 deletions applications/minotari_console_wallet/src/wallet_modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ pub fn tui_mode(
return Err(ExitError::new(ExitCode::WalletError, "Could not select a base node"));
}

let app = App::<CrosstermBackend<Stdout>>::new(
let app = handle.block_on(App::<CrosstermBackend<Stdout>>::new(
"Minotari Wallet".into(),
wallet,
config.clone(),
base_node_selected,
base_node_config.clone(),
notifier,
);
))?;

info!(target: LOG_TARGET, "Starting app");

Expand Down Expand Up @@ -490,15 +490,16 @@ mod test {
discover-peer f6b2ca781342a3ebe30ee1643655c96f1d7c14f4d49f077695395de98ae73665
send-minotari --message Our_secret! 125T 5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d615e
send-minotari --message Our_secret! 125T \
2603fed9cf87097105913096da423ae4e3096e44a172185742ce5bc00d27016cd81118
burn-minotari --message Ups_these_funds_will_be_burned! 100T
coin-split --message Make_many_dust_UTXOs! --fee-per-gram 2 0.001T 499
make-it-rain --duration 100 --transactions-per-second 10 --start-amount 0.009200T --increase-amount 0T \
--start-time now --message Stressing_it_a_bit...!_(from_Feeling-a-bit-Generous) \
5c4f2a4b3f3f84e047333218a84fd24f581a9d7e4f23b78e3714e9d174427d615e
2603fed9cf87097105913096da423ae4e3096e44a172185742ce5bc00d27016cd81118
export-tx 123456789 --output-file pie.txt
Expand Down
10 changes: 6 additions & 4 deletions base_layer/chat_ffi/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ extern "C" {
* The ```destroy_chat_client``` method must be called when finished with a ClientFFI to prevent a memory leak
*/
struct ChatClient *create_chat_client(struct ApplicationConfig *config,
int *error_out,
CallbackContactStatusChange callback_contact_status_change,
CallbackMessageReceived callback_message_received,
CallbackDeliveryConfirmationReceived callback_delivery_confirmation_received,
CallbackReadConfirmationReceived callback_read_confirmation_received);
CallbackReadConfirmationReceived callback_read_confirmation_received,
struct TariAddress *tari_address,
int *error_out);

/**
* Side loads a chat client
Expand All @@ -98,11 +99,12 @@ struct ChatClient *create_chat_client(struct ApplicationConfig *config,
*/
struct ChatClient *sideload_chat_client(struct ApplicationConfig *config,
struct ContactsServiceHandle *contacts_handle,
int *error_out,
CallbackContactStatusChange callback_contact_status_change,
CallbackMessageReceived callback_message_received,
CallbackDeliveryConfirmationReceived callback_delivery_confirmation_received,
CallbackReadConfirmationReceived callback_read_confirmation_received);
CallbackReadConfirmationReceived callback_read_confirmation_received,
struct TariAddress *tari_address,
int *error_out);

/**
* Frees memory for a ChatClient
Expand Down
4 changes: 2 additions & 2 deletions base_layer/chat_ffi/src/contacts_liveness_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod test {
#[test]
fn test_reading_address() {
let address =
TariAddress::from_hex("0c017c5cd01385f34ac065e3b05948326dc55d2494f120c6f459a07389011b4ec1").unwrap();
TariAddress::from_hex("2603fed9cf87097105913096da423ae4e3096e44a172185742ce5bc00d27016cd81118").unwrap();
let liveness = ContactsLivenessData::new(
address.clone(),
Default::default(),
Expand All @@ -172,7 +172,7 @@ mod test {
unsafe {
let address_ptr = read_liveness_data_address(liveness_ptr, error_out);

assert_eq!(address.to_bytes(), (*address_ptr).to_bytes());
assert_eq!(address.to_vec(), (*address_ptr).to_vec());

destroy_contacts_liveness_data(liveness_ptr);
destroy_tari_address(address_ptr);
Expand Down
2 changes: 1 addition & 1 deletion base_layer/chat_ffi/src/conversationalists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ mod test {
#[test]
fn test_retrieving_conversationalists_from_vector() {
let (_, pk) = PublicKey::random_keypair(&mut OsRng);
let a = TariAddress::from_public_key(&pk, Network::LocalNet);
let a = TariAddress::new_single_address_with_interactive_only(pk, Network::LocalNet);
let conversationalists =
ConversationalistsVector(vec![TariAddress::default(), TariAddress::default(), a.clone()]);

Expand Down
Loading

0 comments on commit 4c0ce46

Please sign in to comment.