Skip to content

Commit 82b71a8

Browse files
committed
fix comments
1 parent 8166d46 commit 82b71a8

File tree

27 files changed

+579
-547
lines changed

27 files changed

+579
-547
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/chain/transaction/signature/inputsig/standard_signature.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ impl StandardInputSignature {
175175
pub fn raw_signature(&self) -> &[u8] {
176176
&self.raw_signature
177177
}
178+
179+
pub fn into_raw_signature(self) -> Vec<u8> {
180+
self.raw_signature
181+
}
178182
}
179183

180184
impl Decode for StandardInputSignature {

common/src/chain/transaction/signed_transaction_intent.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,20 @@ pub struct SignedTransactionIntent {
6666
}
6767

6868
impl SignedTransactionIntent {
69-
pub fn new_unchecked(signed_message: String, signatures: Vec<Vec<u8>>) -> Self {
70-
Self {
69+
pub fn from_components(
70+
signed_message: String,
71+
signatures: Vec<Vec<u8>>,
72+
input_destinations: &[Destination],
73+
chain_config: &ChainConfig,
74+
) -> Result<Self, SignedTransactionIntentError> {
75+
let intent = Self {
7176
signed_message,
7277
signatures,
73-
}
78+
};
79+
80+
intent.verify(chain_config, input_destinations, intent.signed_message())?;
81+
82+
Ok(intent)
7483
}
7584

7685
/// Create a signed intent given the id of the transaction and its input destinations.
@@ -192,14 +201,7 @@ impl SignedTransactionIntent {
192201
for (idx, (signature, destination)) in
193202
self.signatures.iter().zip(input_destinations).enumerate()
194203
{
195-
let destination = match destination {
196-
| Destination::PublicKey(pubkey) => Destination::PublicKeyHash(pubkey.into()),
197-
198-
dest @ (Destination::PublicKeyHash(_)
199-
| Destination::AnyoneCanSpend
200-
| Destination::ScriptHash(_)
201-
| Destination::ClassicMultisig(_)) => dest.clone(),
202-
};
204+
let destination = Self::normalize_destination(destination);
203205

204206
let signature = ArbitraryMessageSignatureRef::from_data(signature);
205207

@@ -227,6 +229,18 @@ impl SignedTransactionIntent {
227229
pub fn get_message_to_sign(intent: &str, tx_id: &Id<Transaction>) -> String {
228230
format!("<tx_id:{tx_id:x};intent:{intent}>")
229231
}
232+
233+
/// Converts PublicKey to PublicKeyHash destination
234+
pub fn normalize_destination(destination: &Destination) -> Destination {
235+
match destination {
236+
| Destination::PublicKey(pubkey) => Destination::PublicKeyHash(pubkey.into()),
237+
238+
dest @ (Destination::PublicKeyHash(_)
239+
| Destination::AnyoneCanSpend
240+
| Destination::ScriptHash(_)
241+
| Destination::ClassicMultisig(_)) => dest.clone(),
242+
}
243+
}
230244
}
231245

232246
#[derive(thiserror::Error, Debug, Clone, Eq, PartialEq)]

crypto/src/key/secp256k1/extended_keys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Secp256k1ExtendedPublicKey {
201201
}
202202
}
203203

204-
pub fn new(
204+
pub fn new_unchecked(
205205
derivation_path: DerivationPath,
206206
chain_code: ChainCode,
207207
public_key: Secp256k1PublicKey,

crypto/src/key/signature/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,17 @@ impl Signature {
7979
Ok(decoded_sig)
8080
}
8181

82-
pub fn from_raw_data<T: AsRef<[u8]>>(data: T) -> Result<Self, SignatureError> {
83-
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
84-
.map_err(|_| SignatureError::SignatureConstructionError)?;
85-
Ok(Self::Secp256k1Schnorr(decoded_sig))
82+
pub fn from_raw_data<T: AsRef<[u8]>>(
83+
data: T,
84+
kind: SignatureKind,
85+
) -> Result<Self, SignatureError> {
86+
match kind {
87+
SignatureKind::Secp256k1Schnorr => {
88+
let decoded_sig = secp256k1::schnorr::Signature::from_slice(data.as_ref())
89+
.map_err(|_| SignatureError::SignatureConstructionError)?;
90+
Ok(Self::Secp256k1Schnorr(decoded_sig))
91+
}
92+
}
8693
}
8794

8895
pub fn is_aggregable(&self) -> bool {

node-gui/src/main_window/main_widget/tabs/wallet/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl WalletTab {
179179
WalletType::Hot => SelectedPanel::Transactions,
180180
WalletType::Cold => SelectedPanel::Addresses,
181181
#[cfg(feature = "trezor")]
182-
WalletType::Trezor => SelectedPanel::Addresses,
182+
WalletType::Trezor => SelectedPanel::Transactions,
183183
};
184184

185185
WalletTab {
@@ -485,7 +485,9 @@ impl Tab for WalletTab {
485485
let still_syncing = match wallet_info.wallet_type {
486486
WalletType::Cold => false,
487487
#[cfg(feature = "trezor")]
488-
WalletType::Trezor => false,
488+
WalletType::Trezor => {
489+
wallet_info.best_block.1.next_height() < node_state.chain_info.best_block_height
490+
}
489491
WalletType::Hot => {
490492
wallet_info.best_block.1.next_height() < node_state.chain_info.best_block_height
491493
}

node-gui/src/main_window/mod.rs

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,12 @@ mod main_widget;
6363
#[derive(Debug, PartialEq, Eq)]
6464
enum ActiveDialog {
6565
None,
66-
WalletCreate {
67-
wallet_args: WalletArgs,
68-
wallet_type: WalletType,
69-
},
70-
WalletRecover {
71-
wallet_type: WalletType,
72-
},
73-
WalletSetPassword {
74-
wallet_id: WalletId,
75-
},
76-
WalletUnlock {
77-
wallet_id: WalletId,
78-
},
79-
NewAccount {
80-
wallet_id: WalletId,
81-
},
82-
ConfirmTransaction {
83-
transaction_info: TransactionInfo,
84-
},
66+
WalletCreate { wallet_args: WalletArgs },
67+
WalletRecover { wallet_type: WalletType },
68+
WalletSetPassword { wallet_id: WalletId },
69+
WalletUnlock { wallet_id: WalletId },
70+
NewAccount { wallet_id: WalletId },
71+
ConfirmTransaction { transaction_info: TransactionInfo },
8572
}
8673

8774
#[derive(Debug)]
@@ -157,11 +144,31 @@ pub struct MainWindow {
157144
pub enum WalletArgs {
158145
Software {
159146
mnemonic: String,
147+
is_cold: bool,
160148
},
161149
#[cfg(feature = "trezor")]
162150
Trezor,
163151
}
164152

153+
impl From<&WalletArgs> for WalletType {
154+
fn from(value: &WalletArgs) -> Self {
155+
match value {
156+
WalletArgs::Software {
157+
mnemonic: _,
158+
is_cold,
159+
} => {
160+
if *is_cold {
161+
WalletType::Cold
162+
} else {
163+
WalletType::Hot
164+
}
165+
}
166+
#[cfg(feature = "trezor")]
167+
WalletArgs::Trezor => WalletType::Trezor,
168+
}
169+
}
170+
}
171+
165172
#[derive(Debug, Clone)]
166173
pub enum MainWindowMessage {
167174
MenuMessage(main_menu::MenuMessage),
@@ -177,7 +184,6 @@ pub enum MainWindowMessage {
177184
ImportWalletMnemonic {
178185
args: WalletArgs,
179186
import: ImportOrCreate,
180-
wallet_type: WalletType,
181187
},
182188
ImportWalletFileSelected {
183189
wallet_args: WalletTypeArgs,
@@ -281,14 +287,12 @@ impl MainWindow {
281287
self.language,
282288
)
283289
.to_string(),
290+
is_cold: wallet_type == WalletType::Cold,
284291
},
285292
#[cfg(feature = "trezor")]
286293
WalletType::Trezor => WalletArgs::Trezor,
287294
};
288-
self.active_dialog = ActiveDialog::WalletCreate {
289-
wallet_type,
290-
wallet_args,
291-
};
295+
self.active_dialog = ActiveDialog::WalletCreate { wallet_args };
292296
Task::none()
293297
}
294298
MenuMessage::RecoverWallet { wallet_type } => {
@@ -680,13 +684,13 @@ impl MainWindow {
680684
Task::none()
681685
}
682686

683-
MainWindowMessage::ImportWalletMnemonic {
684-
args,
685-
import,
686-
wallet_type,
687-
} => {
687+
MainWindowMessage::ImportWalletMnemonic { args, import } => {
688+
let wallet_type = (&args).into();
688689
let wallet_args = match args {
689-
WalletArgs::Software { mnemonic } => {
690+
WalletArgs::Software {
691+
mnemonic,
692+
is_cold: _,
693+
} => {
690694
let mnemonic_res =
691695
wallet_controller::mnemonic::parse_mnemonic(self.language, &mnemonic);
692696
match mnemonic_res {
@@ -812,45 +816,39 @@ impl MainWindow {
812816
match &self.active_dialog {
813817
ActiveDialog::None => Text::new("Nothing to show").into(),
814818

815-
ActiveDialog::WalletCreate {
816-
wallet_type,
817-
wallet_args,
818-
} => {
819-
let wallet_type = *wallet_type;
820-
match wallet_args {
821-
WalletArgs::Software { mnemonic } => wallet_mnemonic_dialog(
819+
ActiveDialog::WalletCreate { wallet_args } => match wallet_args {
820+
WalletArgs::Software { mnemonic, is_cold } => {
821+
let is_cold = *is_cold;
822+
wallet_mnemonic_dialog(
822823
Some(mnemonic.clone()),
823824
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
824-
args: WalletArgs::Software { mnemonic },
825+
args: WalletArgs::Software { mnemonic, is_cold },
825826
import: ImportOrCreate::Create,
826-
wallet_type,
827827
}),
828828
Box::new(|| MainWindowMessage::CloseDialog),
829829
Box::new(MainWindowMessage::CopyToClipboard),
830830
)
831-
.into(),
832-
#[cfg(feature = "trezor")]
833-
WalletArgs::Trezor => hw_wallet_create_dialog(
834-
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
835-
args: WalletArgs::Trezor,
836-
import: ImportOrCreate::Create,
837-
wallet_type,
838-
}),
839-
Box::new(|| MainWindowMessage::CloseDialog),
840-
ImportOrCreate::Create,
841-
)
842-
.into(),
831+
.into()
843832
}
844-
}
833+
#[cfg(feature = "trezor")]
834+
WalletArgs::Trezor => hw_wallet_create_dialog(
835+
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
836+
args: WalletArgs::Trezor,
837+
import: ImportOrCreate::Create,
838+
}),
839+
Box::new(|| MainWindowMessage::CloseDialog),
840+
ImportOrCreate::Create,
841+
)
842+
.into(),
843+
},
845844
ActiveDialog::WalletRecover { wallet_type } => {
846-
let wallet_type = *wallet_type;
845+
let is_cold = *wallet_type == WalletType::Cold;
847846
match wallet_type {
848847
WalletType::Hot | WalletType::Cold => wallet_mnemonic_dialog(
849848
None,
850849
Box::new(move |mnemonic| MainWindowMessage::ImportWalletMnemonic {
851-
args: WalletArgs::Software { mnemonic },
850+
args: WalletArgs::Software { mnemonic, is_cold },
852851
import: ImportOrCreate::Import,
853-
wallet_type,
854852
}),
855853
Box::new(|| MainWindowMessage::CloseDialog),
856854
Box::new(MainWindowMessage::CopyToClipboard),
@@ -861,7 +859,6 @@ impl MainWindow {
861859
Box::new(move || MainWindowMessage::ImportWalletMnemonic {
862860
args: WalletArgs::Trezor,
863861
import: ImportOrCreate::Create,
864-
wallet_type,
865862
}),
866863
Box::new(|| MainWindowMessage::CloseDialog),
867864
ImportOrCreate::Import,

wallet/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ zeroize.workspace = true
3838

3939
[dev-dependencies]
4040
test-utils = { path = "../test-utils" }
41+
serial_test = "3.2"
4142

4243
rstest.workspace = true
4344
tempfile.workspace = true
4445

4546
[features]
4647
trezor = ["dep:trezor-client", "wallet-types/trezor"]
47-
trezor-emulator = []
48+
enable-trezor-device-tests = []

wallet/src/account/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ impl<K: AccountKeyChains> Account<K> {
13661366
}
13671367
}
13681368

1369-
pub fn find_unspent_utxo_with_destination(
1369+
pub fn find_unspent_utxo_and_destination(
13701370
&self,
13711371
outpoint: &UtxoOutPoint,
13721372
current_block_info: BlockInfo,

wallet/src/signer/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ use common::{
2929
Transaction,
3030
},
3131
};
32-
use crypto::key::{
33-
hdkd::{derivable::DerivationError, u31::U31},
34-
SignatureError,
35-
};
32+
use crypto::key::hdkd::{derivable::DerivationError, u31::U31};
3633
use wallet_storage::{
3734
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
3835
};
@@ -91,8 +88,6 @@ pub enum SignerError {
9188
InvalidUtxo,
9289
#[error("Address error: {0}")]
9390
AddressError(#[from] AddressError),
94-
#[error("Signature error: {0}")]
95-
SignatureError(#[from] SignatureError),
9691
#[error("Order was filled more than the available balance")]
9792
OrderFillUnderflow,
9893
}

wallet/src/signer/software_signer/tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,7 @@ fn sign_transaction(#[case] seed: Seed) {
464464
}
465465
}
466466

467-
#[rstest]
468-
#[trace]
467+
#[test]
469468
fn fixed_signatures() {
470469
use std::num::NonZeroU8;
471470

0 commit comments

Comments
 (0)