2022-05-21 15:33:35 -04:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
|
|
use rand_core::{RngCore, CryptoRng};
|
|
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
|
|
2022-07-15 01:26:07 -04:00
|
|
|
use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwards::EdwardsPoint};
|
2022-05-21 15:33:35 -04:00
|
|
|
|
2022-06-28 00:01:20 -04:00
|
|
|
use monero::{consensus::Encodable, PublicKey, blockdata::transaction::SubField};
|
2022-05-21 15:33:35 -04:00
|
|
|
|
|
|
|
|
#[cfg(feature = "multisig")]
|
|
|
|
|
use frost::FrostError;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
2022-07-27 04:05:43 -05:00
|
|
|
Protocol, Commitment, random_scalar,
|
2022-05-22 02:24:24 -04:00
|
|
|
ringct::{
|
2022-07-10 16:11:55 -04:00
|
|
|
generate_key_image,
|
2022-05-22 02:24:24 -04:00
|
|
|
clsag::{ClsagError, ClsagInput, Clsag},
|
2022-06-19 12:03:01 -04:00
|
|
|
bulletproofs::{MAX_OUTPUTS, Bulletproofs},
|
2022-07-15 01:26:07 -04:00
|
|
|
RctBase, RctPrunable, RctSignatures,
|
2022-05-22 02:24:24 -04:00
|
|
|
},
|
2022-06-02 00:00:26 -04:00
|
|
|
transaction::{Input, Output, Timelock, TransactionPrefix, Transaction},
|
2022-05-21 15:33:35 -04:00
|
|
|
rpc::{Rpc, RpcError},
|
2022-06-28 00:01:20 -04:00
|
|
|
wallet::{
|
2022-07-15 01:26:07 -04:00
|
|
|
address::{AddressType, Address},
|
|
|
|
|
SpendableOutput, Decoys, key_image_sort, uniqueness, shared_key, commitment_mask,
|
|
|
|
|
amount_encryption,
|
|
|
|
|
},
|
2022-05-21 15:33:35 -04:00
|
|
|
};
|
|
|
|
|
#[cfg(feature = "multisig")]
|
|
|
|
|
use crate::frost::MultisigError;
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "multisig")]
|
|
|
|
|
mod multisig;
|
2022-06-10 09:36:07 -04:00
|
|
|
#[cfg(feature = "multisig")]
|
|
|
|
|
pub use multisig::TransactionMachine;
|
2022-05-21 15:33:35 -04:00
|
|
|
|
|
|
|
|
#[allow(non_snake_case)]
|
2022-07-22 02:34:36 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
2022-05-21 15:33:35 -04:00
|
|
|
struct SendOutput {
|
|
|
|
|
R: EdwardsPoint,
|
|
|
|
|
dest: EdwardsPoint,
|
2022-06-19 12:03:01 -04:00
|
|
|
commitment: Commitment,
|
2022-07-15 01:26:07 -04:00
|
|
|
amount: [u8; 8],
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SendOutput {
|
|
|
|
|
fn new<R: RngCore + CryptoRng>(
|
|
|
|
|
rng: &mut R,
|
2022-06-19 12:03:01 -04:00
|
|
|
unique: [u8; 32],
|
2022-06-28 00:01:20 -04:00
|
|
|
output: (Address, u64),
|
2022-07-15 01:26:07 -04:00
|
|
|
o: usize,
|
2022-06-19 12:03:01 -04:00
|
|
|
) -> SendOutput {
|
2022-05-21 15:33:35 -04:00
|
|
|
let r = random_scalar(rng);
|
2022-07-15 01:26:07 -04:00
|
|
|
let shared_key =
|
|
|
|
|
shared_key(Some(unique).filter(|_| output.0.meta.guaranteed), r, &output.0.view, o);
|
2022-05-21 15:33:35 -04:00
|
|
|
|
2022-06-28 00:01:20 -04:00
|
|
|
let spend = output.0.spend;
|
2022-06-19 12:03:01 -04:00
|
|
|
SendOutput {
|
2022-06-28 00:01:20 -04:00
|
|
|
R: match output.0.meta.kind {
|
2022-06-19 12:03:01 -04:00
|
|
|
AddressType::Standard => &r * &ED25519_BASEPOINT_TABLE,
|
2022-07-15 01:26:07 -04:00
|
|
|
AddressType::Integrated(_) => {
|
|
|
|
|
unimplemented!("SendOutput::new doesn't support Integrated addresses")
|
|
|
|
|
}
|
2022-07-22 02:34:36 -04:00
|
|
|
AddressType::Subaddress => r * spend,
|
2022-06-19 12:03:01 -04:00
|
|
|
},
|
|
|
|
|
dest: ((&shared_key * &ED25519_BASEPOINT_TABLE) + spend),
|
|
|
|
|
commitment: Commitment::new(commitment_mask(shared_key), output.1),
|
2022-07-15 01:26:07 -04:00
|
|
|
amount: amount_encryption(output.1, shared_key),
|
2022-06-19 12:03:01 -04:00
|
|
|
}
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-28 05:08:37 -04:00
|
|
|
#[derive(Clone, Error, Debug)]
|
2022-05-21 15:33:35 -04:00
|
|
|
pub enum TransactionError {
|
2022-06-19 12:03:01 -04:00
|
|
|
#[error("invalid address")]
|
|
|
|
|
InvalidAddress,
|
2022-05-21 15:33:35 -04:00
|
|
|
#[error("no inputs")]
|
|
|
|
|
NoInputs,
|
|
|
|
|
#[error("no outputs")]
|
|
|
|
|
NoOutputs,
|
2022-06-19 12:03:01 -04:00
|
|
|
#[error("only one output and no change address")]
|
|
|
|
|
NoChange,
|
2022-05-21 15:33:35 -04:00
|
|
|
#[error("too many outputs")]
|
|
|
|
|
TooManyOutputs,
|
|
|
|
|
#[error("not enough funds (in {0}, out {1})")]
|
|
|
|
|
NotEnoughFunds(u64, u64),
|
2022-06-09 04:05:57 -04:00
|
|
|
#[error("wrong spend private key")]
|
|
|
|
|
WrongPrivateKey,
|
2022-05-21 15:33:35 -04:00
|
|
|
#[error("rpc error ({0})")]
|
|
|
|
|
RpcError(RpcError),
|
|
|
|
|
#[error("clsag error ({0})")]
|
|
|
|
|
ClsagError(ClsagError),
|
|
|
|
|
#[error("invalid transaction ({0})")]
|
|
|
|
|
InvalidTransaction(RpcError),
|
|
|
|
|
#[cfg(feature = "multisig")]
|
|
|
|
|
#[error("frost error {0}")]
|
|
|
|
|
FrostError(FrostError),
|
|
|
|
|
#[cfg(feature = "multisig")]
|
|
|
|
|
#[error("multisig error {0}")]
|
2022-07-15 01:26:07 -04:00
|
|
|
MultisigError(MultisigError),
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn prepare_inputs<R: RngCore + CryptoRng>(
|
|
|
|
|
rng: &mut R,
|
|
|
|
|
rpc: &Rpc,
|
2022-07-27 04:05:43 -05:00
|
|
|
ring_len: usize,
|
2022-05-21 15:33:35 -04:00
|
|
|
inputs: &[SpendableOutput],
|
|
|
|
|
spend: &Scalar,
|
2022-07-15 01:26:07 -04:00
|
|
|
tx: &mut Transaction,
|
2022-05-21 15:33:35 -04:00
|
|
|
) -> Result<Vec<(Scalar, EdwardsPoint, ClsagInput)>, TransactionError> {
|
|
|
|
|
let mut signable = Vec::with_capacity(inputs.len());
|
|
|
|
|
|
|
|
|
|
// Select decoys
|
|
|
|
|
let decoys = Decoys::select(
|
|
|
|
|
rng,
|
|
|
|
|
rpc,
|
2022-07-27 04:05:43 -05:00
|
|
|
ring_len,
|
2022-07-22 02:34:36 -04:00
|
|
|
rpc.get_height().await.map_err(TransactionError::RpcError)? - 10,
|
2022-07-15 01:26:07 -04:00
|
|
|
inputs,
|
|
|
|
|
)
|
|
|
|
|
.await
|
2022-07-22 02:34:36 -04:00
|
|
|
.map_err(TransactionError::RpcError)?;
|
2022-05-21 15:33:35 -04:00
|
|
|
|
|
|
|
|
for (i, input) in inputs.iter().enumerate() {
|
|
|
|
|
signable.push((
|
|
|
|
|
spend + input.key_offset,
|
2022-07-10 16:11:55 -04:00
|
|
|
generate_key_image(spend + input.key_offset),
|
2022-07-22 02:34:36 -04:00
|
|
|
ClsagInput::new(input.commitment, decoys[i].clone()).map_err(TransactionError::ClsagError)?,
|
2022-05-21 15:33:35 -04:00
|
|
|
));
|
|
|
|
|
|
|
|
|
|
tx.prefix.inputs.push(Input::ToKey {
|
|
|
|
|
amount: 0,
|
|
|
|
|
key_offsets: decoys[i].offsets.clone(),
|
2022-07-15 01:26:07 -04:00
|
|
|
key_image: signable[i].1,
|
2022-05-21 15:33:35 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
signable.sort_by(|x, y| x.1.compress().to_bytes().cmp(&y.1.compress().to_bytes()).reverse());
|
2022-07-15 01:26:07 -04:00
|
|
|
tx.prefix.inputs.sort_by(|x, y| {
|
|
|
|
|
if let (Input::ToKey { key_image: x, .. }, Input::ToKey { key_image: y, .. }) = (x, y) {
|
|
|
|
|
x.compress().to_bytes().cmp(&y.compress().to_bytes()).reverse()
|
|
|
|
|
} else {
|
|
|
|
|
panic!("Input wasn't ToKey")
|
|
|
|
|
}
|
2022-05-21 15:33:35 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Ok(signable)
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-19 12:03:01 -04:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
|
|
|
|
pub struct Fee {
|
|
|
|
|
pub per_weight: u64,
|
2022-07-15 01:26:07 -04:00
|
|
|
pub mask: u64,
|
2022-06-19 12:03:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Fee {
|
|
|
|
|
pub fn calculate(&self, weight: usize) -> u64 {
|
|
|
|
|
((((self.per_weight * u64::try_from(weight).unwrap()) - 1) / self.mask) + 1) * self.mask
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 02:34:36 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
2022-05-21 15:33:35 -04:00
|
|
|
pub struct SignableTransaction {
|
2022-07-27 04:05:43 -05:00
|
|
|
protocol: Protocol,
|
2022-05-21 15:33:35 -04:00
|
|
|
inputs: Vec<SpendableOutput>,
|
2022-06-28 00:01:20 -04:00
|
|
|
payments: Vec<(Address, u64)>,
|
2022-06-19 12:03:01 -04:00
|
|
|
outputs: Vec<SendOutput>,
|
2022-07-15 01:26:07 -04:00
|
|
|
fee: u64,
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SignableTransaction {
|
|
|
|
|
pub fn new(
|
2022-07-27 04:05:43 -05:00
|
|
|
protocol: Protocol,
|
2022-05-21 15:33:35 -04:00
|
|
|
inputs: Vec<SpendableOutput>,
|
2022-06-28 00:01:20 -04:00
|
|
|
mut payments: Vec<(Address, u64)>,
|
2022-06-19 12:03:01 -04:00
|
|
|
change_address: Option<Address>,
|
2022-07-15 01:26:07 -04:00
|
|
|
fee_rate: Fee,
|
2022-05-21 15:33:35 -04:00
|
|
|
) -> Result<SignableTransaction, TransactionError> {
|
2022-06-19 12:03:01 -04:00
|
|
|
// Make sure all addresses are valid
|
2022-07-15 01:26:07 -04:00
|
|
|
let test = |addr: Address| match addr.meta.kind {
|
|
|
|
|
AddressType::Standard => Ok(()),
|
|
|
|
|
AddressType::Integrated(..) => Err(TransactionError::InvalidAddress),
|
|
|
|
|
AddressType::Subaddress => Ok(()),
|
2022-06-19 12:03:01 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for payment in &payments {
|
|
|
|
|
test(payment.0)?;
|
|
|
|
|
}
|
|
|
|
|
if let Some(change) = change_address {
|
|
|
|
|
test(change)?;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-22 02:34:36 -04:00
|
|
|
if inputs.is_empty() {
|
2022-05-21 15:33:35 -04:00
|
|
|
Err(TransactionError::NoInputs)?;
|
|
|
|
|
}
|
2022-07-22 02:34:36 -04:00
|
|
|
if payments.is_empty() {
|
2022-05-21 15:33:35 -04:00
|
|
|
Err(TransactionError::NoOutputs)?;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-19 12:03:01 -04:00
|
|
|
// TODO TX MAX SIZE
|
|
|
|
|
|
|
|
|
|
// If we don't have two outputs, as required by Monero, add a second
|
|
|
|
|
let mut change = payments.len() == 1;
|
|
|
|
|
if change && change_address.is_none() {
|
|
|
|
|
Err(TransactionError::NoChange)?;
|
|
|
|
|
}
|
2022-07-27 04:05:43 -05:00
|
|
|
let outputs = payments.len() + (if change { 1 } else { 0 });
|
2022-06-19 12:03:01 -04:00
|
|
|
|
2022-06-19 12:19:57 -04:00
|
|
|
// Calculate the extra length.
|
|
|
|
|
// Type, length, value, with 1 field for the first key and 1 field for the rest
|
|
|
|
|
let extra = (outputs * (2 + 32)) - (outputs.saturating_sub(2) * 2);
|
|
|
|
|
|
2022-06-19 12:03:01 -04:00
|
|
|
// Calculate the fee.
|
2022-07-27 04:05:43 -05:00
|
|
|
let mut fee = fee_rate.calculate(Transaction::fee_weight(
|
|
|
|
|
protocol.ring_len(),
|
|
|
|
|
inputs.len(),
|
|
|
|
|
outputs,
|
|
|
|
|
extra,
|
|
|
|
|
));
|
2022-06-19 12:03:01 -04:00
|
|
|
|
|
|
|
|
// Make sure we have enough funds
|
|
|
|
|
let in_amount = inputs.iter().map(|input| input.commitment.amount).sum::<u64>();
|
|
|
|
|
let mut out_amount = payments.iter().map(|payment| payment.1).sum::<u64>() + fee;
|
|
|
|
|
if in_amount < out_amount {
|
|
|
|
|
Err(TransactionError::NotEnoughFunds(in_amount, out_amount))?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we have yet to add a change output, do so if it's economically viable
|
|
|
|
|
if (!change) && change_address.is_some() && (in_amount != out_amount) {
|
|
|
|
|
// Check even with the new fee, there's remaining funds
|
2022-07-27 04:05:43 -05:00
|
|
|
let change_fee = fee_rate.calculate(Transaction::fee_weight(
|
|
|
|
|
protocol.ring_len(),
|
|
|
|
|
inputs.len(),
|
|
|
|
|
outputs + 1,
|
|
|
|
|
extra,
|
|
|
|
|
)) - fee;
|
2022-06-19 12:03:01 -04:00
|
|
|
if (out_amount + change_fee) < in_amount {
|
|
|
|
|
change = true;
|
|
|
|
|
out_amount += change_fee;
|
|
|
|
|
fee += change_fee;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if change {
|
2022-06-28 00:01:20 -04:00
|
|
|
payments.push((change_address.unwrap(), in_amount - out_amount));
|
2022-06-19 12:03:01 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-27 04:05:43 -05:00
|
|
|
if payments.len() > MAX_OUTPUTS {
|
|
|
|
|
Err(TransactionError::TooManyOutputs)?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(SignableTransaction { protocol, inputs, payments, outputs: vec![], fee })
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn prepare_outputs<R: RngCore + CryptoRng>(
|
|
|
|
|
&mut self,
|
|
|
|
|
rng: &mut R,
|
2022-07-15 01:26:07 -04:00
|
|
|
uniqueness: [u8; 32],
|
2022-06-19 12:03:01 -04:00
|
|
|
) -> (Vec<Commitment>, Scalar) {
|
|
|
|
|
// Shuffle the payments
|
|
|
|
|
self.payments.shuffle(rng);
|
2022-05-21 15:33:35 -04:00
|
|
|
|
|
|
|
|
// Actually create the outputs
|
2022-06-19 12:03:01 -04:00
|
|
|
self.outputs = Vec::with_capacity(self.payments.len() + 1);
|
|
|
|
|
for (o, output) in self.payments.iter().enumerate() {
|
|
|
|
|
self.outputs.push(SendOutput::new(rng, uniqueness, *output, o));
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
2022-06-19 12:03:01 -04:00
|
|
|
let commitments = self.outputs.iter().map(|output| output.commitment).collect::<Vec<_>>();
|
|
|
|
|
let sum = commitments.iter().map(|commitment| commitment.mask).sum();
|
|
|
|
|
(commitments, sum)
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
|
2022-07-27 04:05:43 -05:00
|
|
|
fn prepare_transaction<R: RngCore + CryptoRng>(
|
|
|
|
|
&self,
|
|
|
|
|
rng: &mut R,
|
|
|
|
|
commitments: &[Commitment],
|
|
|
|
|
) -> Transaction {
|
|
|
|
|
// Safe due to the constructor checking MAX_OUTPUTS
|
|
|
|
|
let bp = Bulletproofs::prove(rng, commitments, self.protocol.bp_plus()).unwrap();
|
|
|
|
|
|
2022-05-21 15:33:35 -04:00
|
|
|
// Create the TX extra
|
2022-06-10 02:38:19 -04:00
|
|
|
// TODO: Review this for canonicity with Monero
|
2022-05-21 15:33:35 -04:00
|
|
|
let mut extra = vec![];
|
2022-07-15 01:26:07 -04:00
|
|
|
SubField::TxPublicKey(PublicKey { point: self.outputs[0].R.compress() })
|
|
|
|
|
.consensus_encode(&mut extra)
|
|
|
|
|
.unwrap();
|
2022-05-21 15:33:35 -04:00
|
|
|
SubField::AdditionalPublickKey(
|
2022-07-15 01:26:07 -04:00
|
|
|
self.outputs[1 ..].iter().map(|output| PublicKey { point: output.R.compress() }).collect(),
|
|
|
|
|
)
|
|
|
|
|
.consensus_encode(&mut extra)
|
|
|
|
|
.unwrap();
|
2022-05-21 15:33:35 -04:00
|
|
|
|
|
|
|
|
let mut tx_outputs = Vec::with_capacity(self.outputs.len());
|
|
|
|
|
let mut ecdh_info = Vec::with_capacity(self.outputs.len());
|
|
|
|
|
for o in 0 .. self.outputs.len() {
|
2022-07-27 04:05:43 -05:00
|
|
|
tx_outputs.push(Output {
|
|
|
|
|
amount: 0,
|
|
|
|
|
key: self.outputs[o].dest,
|
|
|
|
|
tag: Some(0).filter(|_| matches!(self.protocol, Protocol::v16)),
|
|
|
|
|
});
|
2022-05-21 15:33:35 -04:00
|
|
|
ecdh_info.push(self.outputs[o].amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Transaction {
|
|
|
|
|
prefix: TransactionPrefix {
|
|
|
|
|
version: 2,
|
2022-06-02 00:00:26 -04:00
|
|
|
timelock: Timelock::None,
|
2022-05-21 15:33:35 -04:00
|
|
|
inputs: vec![],
|
|
|
|
|
outputs: tx_outputs,
|
2022-07-15 01:26:07 -04:00
|
|
|
extra,
|
2022-05-21 15:33:35 -04:00
|
|
|
},
|
|
|
|
|
rct_signatures: RctSignatures {
|
|
|
|
|
base: RctBase {
|
|
|
|
|
fee: self.fee,
|
|
|
|
|
ecdh_info,
|
2022-07-15 01:26:07 -04:00
|
|
|
commitments: commitments.iter().map(|commitment| commitment.calculate()).collect(),
|
2022-05-21 15:33:35 -04:00
|
|
|
},
|
|
|
|
|
prunable: RctPrunable::Clsag {
|
|
|
|
|
bulletproofs: vec![bp],
|
|
|
|
|
clsags: vec![],
|
2022-07-15 01:26:07 -04:00
|
|
|
pseudo_outs: vec![],
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub async fn sign<R: RngCore + CryptoRng>(
|
|
|
|
|
&mut self,
|
|
|
|
|
rng: &mut R,
|
|
|
|
|
rpc: &Rpc,
|
2022-07-15 01:26:07 -04:00
|
|
|
spend: &Scalar,
|
2022-05-21 15:33:35 -04:00
|
|
|
) -> Result<Transaction, TransactionError> {
|
2022-05-21 21:44:57 -04:00
|
|
|
let mut images = Vec::with_capacity(self.inputs.len());
|
|
|
|
|
for input in &self.inputs {
|
2022-06-09 04:05:57 -04:00
|
|
|
let offset = spend + input.key_offset;
|
|
|
|
|
if (&offset * &ED25519_BASEPOINT_TABLE) != input.key {
|
|
|
|
|
Err(TransactionError::WrongPrivateKey)?;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 16:11:55 -04:00
|
|
|
images.push(generate_key_image(offset));
|
2022-05-21 21:44:57 -04:00
|
|
|
}
|
2022-05-22 01:56:17 -04:00
|
|
|
images.sort_by(key_image_sort);
|
2022-05-21 21:44:57 -04:00
|
|
|
|
2022-05-21 15:33:35 -04:00
|
|
|
let (commitments, mask_sum) = self.prepare_outputs(
|
|
|
|
|
rng,
|
2022-05-22 01:56:17 -04:00
|
|
|
uniqueness(
|
2022-07-15 01:26:07 -04:00
|
|
|
&images
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|image| Input::ToKey { amount: 0, key_offsets: vec![], key_image: *image })
|
|
|
|
|
.collect::<Vec<_>>(),
|
|
|
|
|
),
|
2022-06-19 12:03:01 -04:00
|
|
|
);
|
2022-05-21 15:33:35 -04:00
|
|
|
|
2022-07-27 04:05:43 -05:00
|
|
|
let mut tx = self.prepare_transaction(rng, &commitments);
|
2022-05-21 15:33:35 -04:00
|
|
|
|
2022-07-27 04:05:43 -05:00
|
|
|
let signable =
|
|
|
|
|
prepare_inputs(rng, rpc, self.protocol.ring_len(), &self.inputs, spend, &mut tx).await?;
|
2022-05-21 15:33:35 -04:00
|
|
|
|
|
|
|
|
let clsag_pairs = Clsag::sign(rng, &signable, mask_sum, tx.signature_hash());
|
|
|
|
|
match tx.rct_signatures.prunable {
|
|
|
|
|
RctPrunable::Null => panic!("Signing for RctPrunable::Null"),
|
|
|
|
|
RctPrunable::Clsag { ref mut clsags, ref mut pseudo_outs, .. } => {
|
|
|
|
|
clsags.append(&mut clsag_pairs.iter().map(|clsag| clsag.0.clone()).collect::<Vec<_>>());
|
2022-07-22 02:34:36 -04:00
|
|
|
pseudo_outs.append(&mut clsag_pairs.iter().map(|clsag| clsag.1).collect::<Vec<_>>());
|
2022-05-21 15:33:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(tx)
|
|
|
|
|
}
|
|
|
|
|
}
|