Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ sha2 = "0.10.8"
arboard = { version = "3.4.0", default-features = false, features = [
"windows-sys",
] }
ambassador = "0.4.1"
directories = "5.0"

rusqlite = { version = "0.32.1", features = ["functions"]}
Expand All @@ -50,4 +49,7 @@ bitflags = "2.6.0"
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
rust-embed = "8.5.0"
zmq = "0.10"
zeroize = "1.8.1"
zeroize = "1.8.1"
zxcvbn = "3.1.0"
argon2 = "0.5" # For Argon2 key derivation
aes-gcm = "0.10"# For AES-256-GCM encryption
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct AppState {
last_repaint: Instant, // Track the last time we requested a repaint
}

#[derive(Debug, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub enum DesiredAppAction {
None,
PopScreen,
Expand Down
5 changes: 2 additions & 3 deletions src/backend_task/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::backend_task::BackendTaskSuccessResult;
use crate::context::AppContext;
use crate::model::wallet::Wallet;
use dash_sdk::dashcore_rpc::RpcApi;
use dash_sdk::dpp::dashcore::{ChainLock, Network, OutPoint, Transaction};
use dash_sdk::platform::proto::Proof;
use dash_sdk::dpp::dashcore::{Address, ChainLock, Network, OutPoint, Transaction, TxOut};
use std::sync::{Arc, RwLock};

#[derive(Debug, Clone)]
Expand All @@ -25,7 +24,7 @@ impl PartialEq for CoreTask {

#[derive(Debug, Clone, PartialEq)]
pub(crate) enum CoreItem {
ReceivedAvailableUTXOTransaction(Transaction, Vec<OutPoint>),
ReceivedAvailableUTXOTransaction(Transaction, Vec<(OutPoint, TxOut, Address)>),
ChainLock(ChainLock, Network),
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/identity/add_key_to_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl AppContext {
}
}

self.insert_local_qualified_identity(&qualified_identity)
self.update_local_qualified_identity(&qualified_identity)
.map(|_| {
BackendTaskSuccessResult::Message("Successfully added key to identity".to_string())
})
Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/identity/load_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl AppContext {
};

// Insert qualified identity into the database
self.insert_local_qualified_identity(&qualified_identity)
self.insert_local_qualified_identity(&qualified_identity, None)
.map_err(|e| format!("Database error: {}", e))?;

Ok(BackendTaskSuccessResult::Message(
Expand Down
7 changes: 4 additions & 3 deletions src/backend_task/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use crate::model::qualified_identity::{
};
use crate::model::wallet::Wallet;
use dash_sdk::dashcore_rpc::dashcore::key::Secp256k1;
use dash_sdk::dashcore_rpc::dashcore::{Address, PrivateKey};
use dash_sdk::dashcore_rpc::dashcore::{Address, PrivateKey, TxOut};
use dash_sdk::dpp::balances::credits::Duffs;
use dash_sdk::dpp::dashcore::hashes::Hash;
use dash_sdk::dpp::dashcore::Transaction;
use dash_sdk::dpp::dashcore::{OutPoint, Transaction};
use dash_sdk::dpp::fee::Credits;
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
Expand All @@ -29,7 +29,6 @@ use dash_sdk::Sdk;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::{Arc, RwLock};
use tokio::sync::mpsc;
use tracing_subscriber::util::SubscriberInitExt;

use super::BackendTaskSuccessResult;

Expand Down Expand Up @@ -168,6 +167,7 @@ pub type IdentityIndex = u32;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IdentityRegistrationMethod {
UseAssetLock(Address, AssetLockProof, Transaction),
FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex),
FundWithWallet(Duffs, IdentityIndex),
}

Expand All @@ -176,6 +176,7 @@ pub struct IdentityRegistrationInfo {
pub alias_input: String,
pub keys: IdentityKeys,
pub wallet: Arc<RwLock<Wallet>>,
pub wallet_identity_index: u32,
pub identity_registration_method: IdentityRegistrationMethod,
}

Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/identity/refresh_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl AppContext {
qualified_identity_to_update.identity = refreshed_identity;

// Insert the updated identity into local state
self.insert_local_qualified_identity(&qualified_identity_to_update)
self.insert_local_qualified_identity(&qualified_identity_to_update, None)
.map_err(|e| e.to_string())?;

// Send refresh message to refresh the Identities Screen
Expand Down
72 changes: 68 additions & 4 deletions src/backend_task/identity/register_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl AppContext {
alias_input,
keys,
wallet,
wallet_identity_index,
identity_registration_method,
} = input;

Expand All @@ -120,6 +121,8 @@ impl AppContext {
.await
.map_err(|e| e.to_string())?;

let mut wallet_id;

let (asset_lock_proof, asset_lock_proof_private_key, tx_id) =
match identity_registration_method {
IdentityRegistrationMethod::UseAssetLock(
Expand All @@ -129,6 +132,7 @@ impl AppContext {
) => {
let tx_id = transaction.txid();
let wallet = wallet.read().unwrap();
wallet_id = wallet.seed_hash();
let private_key = wallet
.private_key_for_address(&address, self.network)?
.ok_or("Asset Lock not valid for wallet")?;
Expand Down Expand Up @@ -164,6 +168,7 @@ impl AppContext {
// Scope the write lock to avoid holding it across an await.
let (asset_lock_transaction, asset_lock_proof_private_key, change_address) = {
let mut wallet = wallet.write().unwrap();
wallet_id = wallet.seed_hash();
match wallet.asset_lock_transaction(
sdk.network,
amount,
Expand Down Expand Up @@ -215,6 +220,58 @@ impl AppContext {
tokio::time::sleep(Duration::from_millis(200)).await;
}

(asset_lock_proof, asset_lock_proof_private_key, tx_id)
}
IdentityRegistrationMethod::FundWithUtxo(
utxo,
tx_out,
input_address,
identity_index,
) => {
// Scope the write lock to avoid holding it across an await.
let (asset_lock_transaction, asset_lock_proof_private_key) = {
let mut wallet = wallet.write().unwrap();
wallet_id = wallet.seed_hash();
wallet.asset_lock_transaction_for_utxo(
sdk.network,
utxo,
tx_out,
input_address,
identity_index,
Some(self),
)?
};

let tx_id = asset_lock_transaction.txid();
// todo: maybe one day we will want to use platform again, but for right now we use
// the local core as it is more stable
// let asset_lock_proof = self
// .broadcast_and_retrieve_asset_lock(&asset_lock_transaction, &change_address)
// .await
// .map_err(|e| e.to_string())?;

{
let mut proofs = self.transactions_waiting_for_finality.lock().unwrap();
proofs.insert(tx_id, None);
}

self.core_client
.send_raw_transaction(&asset_lock_transaction)
.map_err(|e| e.to_string())?;

let mut asset_lock_proof;

loop {
{
let proofs = self.transactions_waiting_for_finality.lock().unwrap();
if let Some(Some(proof)) = proofs.get(&tx_id) {
asset_lock_proof = proof.clone();
break;
}
}
tokio::time::sleep(Duration::from_millis(200)).await;
}

(asset_lock_proof, asset_lock_proof_private_key, tx_id)
}
};
Expand Down Expand Up @@ -249,8 +306,12 @@ impl AppContext {
qualified_identity.alias = Some(alias_input);
}

self.insert_local_qualified_identity_in_creation(&qualified_identity)
.map_err(|e| e.to_string())?;
self.insert_local_qualified_identity_in_creation(
&qualified_identity,
wallet_id.as_slice(),
wallet_identity_index,
)
.map_err(|e| e.to_string())?;
self.db
.set_asset_lock_identity_id_before_confirmation_by_network(
tx_id.as_byte_array(),
Expand Down Expand Up @@ -287,8 +348,11 @@ impl AppContext {

qualified_identity.identity = updated_identity;

self.insert_local_qualified_identity(&qualified_identity)
.map_err(|e| e.to_string())?;
self.insert_local_qualified_identity(
&qualified_identity,
Some((wallet_id.as_slice(), wallet_identity_index)),
)
.map_err(|e| e.to_string())?;
self.db
.set_asset_lock_identity_id(tx_id.as_byte_array(), Some(identity_id.as_slice()))
.map_err(|e| e.to_string())?;
Expand Down
4 changes: 2 additions & 2 deletions src/backend_task/identity/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ impl AppContext {
.await
.map_err(|e| format!("Withdrawal error: {}", e))?;
qualified_identity.identity.set_balance(remaining_balance);
self.insert_local_qualified_identity(&qualified_identity)
self.update_local_qualified_identity(&qualified_identity)
.map(|_| {
BackendTaskSuccessResult::Message("Successfully transferred credits".to_string())
})
.map_err(|e| format!("Database error: {}", e))
.map_err(|e| e.to_string())
}
}
2 changes: 1 addition & 1 deletion src/backend_task/identity/withdraw_from_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl AppContext {
.await
.map_err(|e| format!("Withdrawal error: {}", e))?;
qualified_identity.identity.set_balance(remaining_balance);
self.insert_local_qualified_identity(&qualified_identity)
self.update_local_qualified_identity(&qualified_identity)
.map(|_| {
BackendTaskSuccessResult::Message("Successfully withdrew from identity".to_string())
})
Expand Down
42 changes: 32 additions & 10 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use dash_sdk::dashcore_rpc::dashcore::{InstantLock, Transaction};
use dash_sdk::dashcore_rpc::{Auth, Client};
use dash_sdk::dpp::dashcore::hashes::Hash;
use dash_sdk::dpp::dashcore::transaction::special_transaction::TransactionPayload::AssetLockPayloadType;
use dash_sdk::dpp::dashcore::{Address, Network, OutPoint, Txid};
use dash_sdk::dpp::dashcore::{Address, Network, OutPoint, TxOut, Txid};
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof;
use dash_sdk::dpp::identity::state_transition::asset_lock_proof::InstantAssetLockProof;
Expand Down Expand Up @@ -123,24 +123,42 @@ impl AppContext {

pub fn insert_local_identity(&self, identity: &Identity) -> Result<()> {
self.db
.insert_local_qualified_identity(&identity.clone().into(), self)
.insert_local_qualified_identity(&identity.clone().into(), None, self)
}

pub fn insert_local_qualified_identity(
&self,
qualified_identity: &QualifiedIdentity,
wallet_and_identity_id_info: Option<(&[u8], u32)>,
) -> Result<()> {
self.db.insert_local_qualified_identity(
qualified_identity,
wallet_and_identity_id_info,
self,
)
}

pub fn update_local_qualified_identity(
&self,
qualified_identity: &QualifiedIdentity,
) -> Result<()> {
self.db
.insert_local_qualified_identity(qualified_identity, self)
.update_local_qualified_identity(qualified_identity, self)
}

/// This is for before we know if Platform will accept the identity
pub fn insert_local_qualified_identity_in_creation(
&self,
qualified_identity: &QualifiedIdentity,
wallet_id: &[u8],
identity_index: u32,
) -> Result<()> {
self.db
.insert_local_qualified_identity_in_creation(qualified_identity, self)
self.db.insert_local_qualified_identity_in_creation(
qualified_identity,
wallet_id,
identity_index,
self,
)
}

pub fn load_local_qualified_identities(&self) -> Result<Vec<QualifiedIdentity>> {
Expand Down Expand Up @@ -214,7 +232,7 @@ impl AppContext {
tx: &Transaction,
islock: Option<InstantLock>,
chain_locked_height: Option<CoreBlockHeight>,
) -> rusqlite::Result<Vec<OutPoint>> {
) -> rusqlite::Result<Vec<(OutPoint, TxOut, Address)>> {
// Initialize a vector to collect wallet outpoints
let mut wallet_outpoints = Vec::new();

Expand Down Expand Up @@ -243,7 +261,7 @@ impl AppContext {
self.network,
)?;
self.db
.add_to_address_balance(&wallet.seed, &address, tx_out.value)?;
.add_to_address_balance(&wallet.seed_hash(), &address, tx_out.value)?;

// Create the OutPoint and insert it into the wallet.utxos entry
let out_point = OutPoint::new(tx.txid(), vout as u32);
Expand All @@ -254,7 +272,7 @@ impl AppContext {
.insert(out_point.clone(), tx_out.clone()); // Insert the TxOut at the OutPoint

// Collect the outpoint
wallet_outpoints.push(out_point.clone());
wallet_outpoints.push((out_point.clone(), tx_out.clone(), address.clone()));

wallet
.address_balances
Expand Down Expand Up @@ -331,8 +349,12 @@ impl AppContext {
.sum();

// Store the asset lock transaction in the database
self.db
.store_asset_lock_transaction(tx, amount, islock.as_ref(), &wallet.seed)?;
self.db.store_asset_lock_transaction(
tx,
amount,
islock.as_ref(),
&wallet.seed_hash(),
)?;

let first = payload
.credit_outputs
Expand Down
Loading