Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Feb 25, 2025
1 parent 8166d46 commit 82b71a8
Show file tree
Hide file tree
Showing 27 changed files with 579 additions and 547 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.

Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ impl StandardInputSignature {
pub fn raw_signature(&self) -> &[u8] {
&self.raw_signature
}

pub fn into_raw_signature(self) -> Vec<u8> {
self.raw_signature
}
}

impl Decode for StandardInputSignature {
Expand Down
36 changes: 25 additions & 11 deletions common/src/chain/transaction/signed_transaction_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,20 @@ pub struct SignedTransactionIntent {
}

impl SignedTransactionIntent {
pub fn new_unchecked(signed_message: String, signatures: Vec<Vec<u8>>) -> Self {
Self {
pub fn from_components(
signed_message: String,
signatures: Vec<Vec<u8>>,
input_destinations: &[Destination],
chain_config: &ChainConfig,
) -> Result<Self, SignedTransactionIntentError> {
let intent = Self {
signed_message,
signatures,
}
};

intent.verify(chain_config, input_destinations, intent.signed_message())?;

Ok(intent)
}

/// Create a signed intent given the id of the transaction and its input destinations.
Expand Down Expand Up @@ -192,14 +201,7 @@ impl SignedTransactionIntent {
for (idx, (signature, destination)) in
self.signatures.iter().zip(input_destinations).enumerate()
{
let destination = match destination {
| Destination::PublicKey(pubkey) => Destination::PublicKeyHash(pubkey.into()),

dest @ (Destination::PublicKeyHash(_)
| Destination::AnyoneCanSpend
| Destination::ScriptHash(_)
| Destination::ClassicMultisig(_)) => dest.clone(),
};
let destination = Self::normalize_destination(destination);

let signature = ArbitraryMessageSignatureRef::from_data(signature);

Expand Down Expand Up @@ -227,6 +229,18 @@ impl SignedTransactionIntent {
pub fn get_message_to_sign(intent: &str, tx_id: &Id<Transaction>) -> String {
format!("<tx_id:{tx_id:x};intent:{intent}>")
}

/// Converts PublicKey to PublicKeyHash destination
pub fn normalize_destination(destination: &Destination) -> Destination {
match destination {
| Destination::PublicKey(pubkey) => Destination::PublicKeyHash(pubkey.into()),

dest @ (Destination::PublicKeyHash(_)
| Destination::AnyoneCanSpend
| Destination::ScriptHash(_)
| Destination::ClassicMultisig(_)) => dest.clone(),
}
}
}

#[derive(thiserror::Error, Debug, Clone, Eq, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/key/secp256k1/extended_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Secp256k1ExtendedPublicKey {
}
}

pub fn new(
pub fn new_unchecked(
derivation_path: DerivationPath,
chain_code: ChainCode,
public_key: Secp256k1PublicKey,
Expand Down
15 changes: 11 additions & 4 deletions crypto/src/key/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@ impl Signature {
Ok(decoded_sig)
}

pub fn from_raw_data<T: AsRef<[u8]>>(data: T) -> Result<Self, SignatureError> {
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
.map_err(|_| SignatureError::SignatureConstructionError)?;
Ok(Self::Secp256k1Schnorr(decoded_sig))
pub fn from_raw_data<T: AsRef<[u8]>>(
data: T,
kind: SignatureKind,
) -> Result<Self, SignatureError> {
match kind {
SignatureKind::Secp256k1Schnorr => {
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
.map_err(|_| SignatureError::SignatureConstructionError)?;
Ok(Self::Secp256k1Schnorr(decoded_sig))
}
}
}

pub fn is_aggregable(&self) -> bool {
Expand Down
6 changes: 4 additions & 2 deletions node-gui/src/main_window/main_widget/tabs/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl WalletTab {
WalletType::Hot => SelectedPanel::Transactions,
WalletType::Cold => SelectedPanel::Addresses,
#[cfg(feature = "trezor")]
WalletType::Trezor => SelectedPanel::Addresses,
WalletType::Trezor => SelectedPanel::Transactions,
};

WalletTab {
Expand Down Expand Up @@ -485,7 +485,9 @@ impl Tab for WalletTab {
let still_syncing = match wallet_info.wallet_type {
WalletType::Cold => false,
#[cfg(feature = "trezor")]
WalletType::Trezor => false,
WalletType::Trezor => {
wallet_info.best_block.1.next_height() < node_state.chain_info.best_block_height
}
WalletType::Hot => {
wallet_info.best_block.1.next_height() < node_state.chain_info.best_block_height
}
Expand Down
109 changes: 53 additions & 56 deletions node-gui/src/main_window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,12 @@ mod main_widget;
#[derive(Debug, PartialEq, Eq)]
enum ActiveDialog {
None,
WalletCreate {
wallet_args: WalletArgs,
wallet_type: WalletType,
},
WalletRecover {
wallet_type: WalletType,
},
WalletSetPassword {
wallet_id: WalletId,
},
WalletUnlock {
wallet_id: WalletId,
},
NewAccount {
wallet_id: WalletId,
},
ConfirmTransaction {
transaction_info: TransactionInfo,
},
WalletCreate { wallet_args: WalletArgs },
WalletRecover { wallet_type: WalletType },
WalletSetPassword { wallet_id: WalletId },
WalletUnlock { wallet_id: WalletId },
NewAccount { wallet_id: WalletId },
ConfirmTransaction { transaction_info: TransactionInfo },
}

#[derive(Debug)]
Expand Down Expand Up @@ -157,11 +144,31 @@ pub struct MainWindow {
pub enum WalletArgs {
Software {
mnemonic: String,
is_cold: bool,
},
#[cfg(feature = "trezor")]
Trezor,
}

impl From<&WalletArgs> for WalletType {
fn from(value: &WalletArgs) -> Self {
match value {
WalletArgs::Software {
mnemonic: _,
is_cold,
} => {
if *is_cold {
WalletType::Cold
} else {
WalletType::Hot
}
}
#[cfg(feature = "trezor")]
WalletArgs::Trezor => WalletType::Trezor,
}
}
}

#[derive(Debug, Clone)]
pub enum MainWindowMessage {
MenuMessage(main_menu::MenuMessage),
Expand All @@ -177,7 +184,6 @@ pub enum MainWindowMessage {
ImportWalletMnemonic {
args: WalletArgs,
import: ImportOrCreate,
wallet_type: WalletType,
},
ImportWalletFileSelected {
wallet_args: WalletTypeArgs,
Expand Down Expand Up @@ -281,14 +287,12 @@ impl MainWindow {
self.language,
)
.to_string(),
is_cold: wallet_type == WalletType::Cold,
},
#[cfg(feature = "trezor")]
WalletType::Trezor => WalletArgs::Trezor,
};
self.active_dialog = ActiveDialog::WalletCreate {
wallet_type,
wallet_args,
};
self.active_dialog = ActiveDialog::WalletCreate { wallet_args };
Task::none()
}
MenuMessage::RecoverWallet { wallet_type } => {
Expand Down Expand Up @@ -680,13 +684,13 @@ impl MainWindow {
Task::none()
}

MainWindowMessage::ImportWalletMnemonic {
args,
import,
wallet_type,
} => {
MainWindowMessage::ImportWalletMnemonic { args, import } => {
let wallet_type = (&args).into();
let wallet_args = match args {
WalletArgs::Software { mnemonic } => {
WalletArgs::Software {
mnemonic,
is_cold: _,
} => {
let mnemonic_res =
wallet_controller::mnemonic::parse_mnemonic(self.language, &mnemonic);
match mnemonic_res {
Expand Down Expand Up @@ -812,45 +816,39 @@ impl MainWindow {
match &self.active_dialog {
ActiveDialog::None => Text::new("Nothing to show").into(),

ActiveDialog::WalletCreate {
wallet_type,
wallet_args,
} => {
let wallet_type = *wallet_type;
match wallet_args {
WalletArgs::Software { mnemonic } => wallet_mnemonic_dialog(
ActiveDialog::WalletCreate { wallet_args } => match wallet_args {
WalletArgs::Software { mnemonic, is_cold } => {
let is_cold = *is_cold;
wallet_mnemonic_dialog(
Some(mnemonic.clone()),
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Software { mnemonic },
args: WalletArgs::Software { mnemonic, is_cold },
import: ImportOrCreate::Create,
wallet_type,
}),
Box::new(|| MainWindowMessage::CloseDialog),
Box::new(MainWindowMessage::CopyToClipboard),
)
.into(),
#[cfg(feature = "trezor")]
WalletArgs::Trezor => hw_wallet_create_dialog(
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Trezor,
import: ImportOrCreate::Create,
wallet_type,
}),
Box::new(|| MainWindowMessage::CloseDialog),
ImportOrCreate::Create,
)
.into(),
.into()
}
}
#[cfg(feature = "trezor")]
WalletArgs::Trezor => hw_wallet_create_dialog(
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Trezor,
import: ImportOrCreate::Create,
}),
Box::new(|| MainWindowMessage::CloseDialog),
ImportOrCreate::Create,
)
.into(),
},
ActiveDialog::WalletRecover { wallet_type } => {
let wallet_type = *wallet_type;
let is_cold = *wallet_type == WalletType::Cold;
match wallet_type {
WalletType::Hot | WalletType::Cold => wallet_mnemonic_dialog(
None,
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Software { mnemonic },
args: WalletArgs::Software { mnemonic, is_cold },
import: ImportOrCreate::Import,
wallet_type,
}),
Box::new(|| MainWindowMessage::CloseDialog),
Box::new(MainWindowMessage::CopyToClipboard),
Expand All @@ -861,7 +859,6 @@ impl MainWindow {
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
args: WalletArgs::Trezor,
import: ImportOrCreate::Create,
wallet_type,
}),
Box::new(|| MainWindowMessage::CloseDialog),
ImportOrCreate::Import,
Expand Down
3 changes: 2 additions & 1 deletion wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ zeroize.workspace = true

[dev-dependencies]
test-utils = { path = "../test-utils" }
serial_test = "3.2"

rstest.workspace = true
tempfile.workspace = true

[features]
trezor = ["dep:trezor-client", "wallet-types/trezor"]
trezor-emulator = []
enable-trezor-device-tests = []
2 changes: 1 addition & 1 deletion wallet/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ impl<K: AccountKeyChains> Account<K> {
}
}

pub fn find_unspent_utxo_with_destination(
pub fn find_unspent_utxo_and_destination(
&self,
outpoint: &UtxoOutPoint,
current_block_info: BlockInfo,
Expand Down
7 changes: 1 addition & 6 deletions wallet/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ use common::{
Transaction,
},
};
use crypto::key::{
hdkd::{derivable::DerivationError, u31::U31},
SignatureError,
};
use crypto::key::hdkd::{derivable::DerivationError, u31::U31};
use wallet_storage::{
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
};
Expand Down Expand Up @@ -91,8 +88,6 @@ pub enum SignerError {
InvalidUtxo,
#[error("Address error: {0}")]
AddressError(#[from] AddressError),
#[error("Signature error: {0}")]
SignatureError(#[from] SignatureError),
#[error("Order was filled more than the available balance")]
OrderFillUnderflow,
}
Expand Down
3 changes: 1 addition & 2 deletions wallet/src/signer/software_signer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ fn sign_transaction(#[case] seed: Seed) {
}
}

#[rstest]
#[trace]
#[test]
fn fixed_signatures() {
use std::num::NonZeroU8;

Expand Down
Loading

0 comments on commit 82b71a8

Please sign in to comment.