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
4 changes: 4 additions & 0 deletions wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ tempfile.workspace = true
[features]
trezor = ["dep:trezor-client", "wallet-types/trezor"]
enable-trezor-device-tests = []
# Note: currently this is used in certain external tests (in particular, in the bridge), so we only
# allow it for regtest. TODO: it's better to have some regtest-specific options for the wallet,
# similar to what we have for the node.
use-deterministic-signatures-in-software-signer-for-regtest = []
default = ["trezor"]
20 changes: 18 additions & 2 deletions wallet/src/signer/software_signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use itertools::Itertools;

use common::{
chain::{
config::ChainType,
htlc::HtlcSecret,
signature::{
inputsig::{
Expand Down Expand Up @@ -46,7 +47,7 @@ use common::{
use crypto::key::{
extended::{ExtendedPrivateKey, ExtendedPublicKey},
hdkd::{derivable::Derivable, u31::U31},
PrivateKey, SigAuxDataProvider,
PredefinedSigAuxDataProvider, PrivateKey, SigAuxDataProvider,
};
use randomness::make_true_rng;
use wallet_storage::{
Expand Down Expand Up @@ -76,7 +77,22 @@ pub struct SoftwareSigner {

impl SoftwareSigner {
pub fn new(chain_config: Arc<ChainConfig>, account_index: U31) -> Self {
Self::new_with_sig_aux_data_provider(chain_config, account_index, Box::new(make_true_rng()))
let use_deterministic_signer = *chain_config.chain_type() == ChainType::Regtest
&& cfg!(feature = "use-deterministic-signatures-in-software-signer-for-regtest");

if use_deterministic_signer {
Self::new_with_sig_aux_data_provider(
chain_config,
account_index,
Box::new(PredefinedSigAuxDataProvider),
)
} else {
Self::new_with_sig_aux_data_provider(
chain_config,
account_index,
Box::new(make_true_rng()),
)
}
}

pub fn new_with_sig_aux_data_provider(
Expand Down
57 changes: 43 additions & 14 deletions wallet/types/src/partially_signed_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use common::{
Signable, Transactable,
},
tokens::TokenId,
ChainConfig, Destination, OrderId, PoolId, SighashInputCommitmentVersion,
SignedTransaction, Transaction, TransactionCreationError, TxInput, TxOutput,
AccountCommand, ChainConfig, Destination, OrderAccountCommand, OrderId, PoolId,
SighashInputCommitmentVersion, SignedTransaction, Transaction, TransactionCreationError,
TxInput, TxOutput,
},
primitives::{Amount, BlockHeight},
};
Expand Down Expand Up @@ -160,6 +161,14 @@ impl TxAdditionalInfo {
self.order_info.get(order_id)
}

pub fn token_info_iter(&self) -> impl Iterator<Item = (&'_ TokenId, &'_ TokenAdditionalInfo)> {
self.token_info.iter()
}

pub fn pool_info_iter(&self) -> impl Iterator<Item = (&'_ PoolId, &'_ PoolAdditionalInfo)> {
self.pool_info.iter()
}

pub fn order_info_iter(&self) -> impl Iterator<Item = (&'_ OrderId, &'_ OrderAdditionalInfo)> {
self.order_info.iter()
}
Expand Down Expand Up @@ -211,31 +220,51 @@ pub struct PartiallySignedTransaction {
}

impl PartiallySignedTransaction {
pub fn new(
pub fn new_unchecked(
tx: Transaction,
witnesses: Vec<Option<InputWitness>>,
input_utxos: Vec<Option<TxOutput>>,
destinations: Vec<Option<Destination>>,
htlc_secrets: Option<Vec<Option<HtlcSecret>>>,
additional_info: TxAdditionalInfo,
) -> Result<Self, PartiallySignedTransactionError> {
) -> Self {
let htlc_secrets = htlc_secrets.unwrap_or_else(|| vec![None; tx.inputs().len()]);

let this = Self {
Self {
tx,
witnesses,
input_utxos,
destinations,
htlc_secrets,
additional_info,
};
}
}

this.ensure_consistency()?;
pub fn new(
tx: Transaction,
witnesses: Vec<Option<InputWitness>>,
input_utxos: Vec<Option<TxOutput>>,
destinations: Vec<Option<Destination>>,
htlc_secrets: Option<Vec<Option<HtlcSecret>>>,
additional_info: TxAdditionalInfo,
) -> Result<Self, PartiallySignedTransactionError> {
let this = Self::new_unchecked(
tx,
witnesses,
input_utxos,
destinations,
htlc_secrets,
additional_info,
);

this.ensure_consistency(Self::need_heavy_consistency_checks())?;
Ok(this)
}

pub fn ensure_consistency(&self) -> Result<(), PartiallySignedTransactionError> {
pub fn ensure_consistency(
&self,
with_heavy_checks: bool,
) -> Result<(), PartiallySignedTransactionError> {
ensure!(
self.tx.inputs().len() == self.witnesses.len(),
PartiallySignedTransactionError::InvalidWitnessCount
Expand All @@ -256,18 +285,18 @@ impl PartiallySignedTransaction {
PartiallySignedTransactionError::InvalidHtlcSecretsCount
);

#[cfg(debug_assertions)]
{
if with_heavy_checks {
self.ensure_additional_info_completeness()?;
}

Ok(())
}

#[cfg(debug_assertions)]
fn ensure_additional_info_completeness(&self) -> Result<(), PartiallySignedTransactionError> {
use common::chain::{AccountCommand, OrderAccountCommand};
fn need_heavy_consistency_checks() -> bool {
cfg!(debug_assertions)
}

fn ensure_additional_info_completeness(&self) -> Result<(), PartiallySignedTransactionError> {
let ensure_order_info_present =
|order_id: &OrderId| -> Result<_, PartiallySignedTransactionError> {
ensure!(
Expand Down Expand Up @@ -387,7 +416,7 @@ impl PartiallySignedTransaction {
witnesses: Vec<Option<InputWitness>>,
) -> Result<Self, PartiallySignedTransactionError> {
self.witnesses = witnesses;
self.ensure_consistency()?;
self.ensure_consistency(Self::need_heavy_consistency_checks())?;
Ok(self)
}

Expand Down
Loading