Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backup spend #6495

Merged
merged 3 commits into from
Aug 21, 2024
Merged
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
28 changes: 18 additions & 10 deletions base_layer/wallet/src/output_manager_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use std::{collections::HashMap, convert::TryInto, fmt, sync::Arc};

use diesel::result::{DatabaseErrorKind, Error as DieselError};
Expand Down Expand Up @@ -1627,14 +1626,17 @@ where
{
if output.verify_mask(&self.resources.factories.range_proof, &spending_key, amount.as_u64())? {
let spending_key_id = self.resources.key_manager.import_key(spending_key).await?;
let script_key = self
.pre_mine_script_key_from_payment_id(payment_id.clone(), tx_id)
.await?;
WalletOutput::new_with_rangeproof(
output.version,
amount,
spending_key_id,
output.features,
output.script,
ExecutionStack::default(),
self.resources.key_manager.get_spend_key().await?.key_id, // Only of the master wallet
script_key.key_id,
output.sender_offset_public_key,
output.metadata_signature,
0,
Expand Down Expand Up @@ -1663,14 +1665,14 @@ where
range_proof_type,
..Default::default()
};
let script = script!(PushPubKey(Box::new(recipient_address.public_spend_key().clone())));
let temp_script = script!(PushPubKey(Box::default()));
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
let metadata_byte_size = self
.resources
.consensus_constants
.transaction_weight_params()
.round_up_features_and_scripts_size(
output_features.get_serialized_size()? +
script.get_serialized_size()? +
temp_script.get_serialized_size()? +
Covenant::default().get_serialized_size()?,
);
let fee = self.get_fee_calc();
Expand All @@ -1691,7 +1693,7 @@ where
.await?
.with_sender_address(self.resources.one_sided_tari_address.clone())
.with_recipient_data(
push_pubkey_script(recipient_address.public_spend_key()),
script!(PushPubKey(Box::default())),
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
output_features,
Covenant::default(),
minimum_value_promise,
Expand Down Expand Up @@ -1749,8 +1751,8 @@ where
)
.await?;

let spending_key = shared_secret_to_output_spending_key(&shared_secret)?;
let spending_key_id = self.resources.key_manager.import_key(spending_key).await?;
let commitment_mask_key = shared_secret_to_output_spending_key(&shared_secret)?;
let commitment_mask_key_id = self.resources.key_manager.import_key(commitment_mask_key).await?;

let encryption_private_key = shared_secret_to_output_encryption_key(&shared_secret)?;
let encryption_key_id = self.resources.key_manager.import_key(encryption_private_key).await?;
Expand All @@ -1767,13 +1769,19 @@ where
.map_err(|e| service_error_with_id(tx_id, e.to_string(), true))?,
);

// Create the output with a partially signed metadata signature
let script_spending_key = self
.resources
.key_manager
.stealth_address_script_spending_key(&commitment_mask_key_id, recipient_address.public_spend_key())
.await?;
let script = push_pubkey_script(&script_spending_key);
let payment_id = match payment_id {
PaymentId::Open(v) => PaymentId::AddressAndData(self.resources.interactive_tari_address.clone(), v),
PaymentId::Empty => PaymentId::Address(self.resources.one_sided_tari_address.clone()),
_ => payment_id,
};
let output = WalletOutputBuilder::new(amount, spending_key_id)

let output = WalletOutputBuilder::new(amount, commitment_mask_key_id)
.with_features(
sender_message
.single()
Expand All @@ -1791,7 +1799,7 @@ where
.await?
.with_input_data(ExecutionStack::default()) // Just a placeholder in the wallet
.with_sender_offset_public_key(sender_offset_public_key)
.with_script_key(self.resources.key_manager.get_spend_key().await?.key_id)
.with_script_key(KeyId::Zero)
SWvheerden marked this conversation as resolved.
Show resolved Hide resolved
.with_minimum_value_promise(minimum_value_promise)
.sign_as_sender_and_receiver_verified(
&self.resources.key_manager,
Expand Down
Loading