Skip to content

Commit cfd29af

Browse files
committed
Add function to build multisig output
Build a multisig output with a blank rangeproof, to build the rangeproof over a number of rounds Output commit is a sum of a partial commit to the output value and a commit to zero
1 parent 5b12dcd commit cfd29af

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

core/src/libtx/build.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use crate::core::{Input, KernelFeatures, Output, OutputFeatures, Transaction, Tx
3535
use crate::libtx::proof::{self, ProofBuild};
3636
use crate::libtx::{aggsig, Error};
3737
use keychain::{BlindSum, BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
38+
use util::secp::pedersen::{Commitment, RangeProof};
3839

3940
/// Context information available to transaction combinators.
4041
pub struct Context<'a, K, B>
@@ -143,6 +144,46 @@ where
143144
)
144145
}
145146

147+
/// Adds an output with the provided value and key identifier from the
148+
/// keychain.
149+
///
150+
/// Adds a blank Rangeproof, to build the multiparty bulletproof over
151+
/// a number of rounds
152+
pub fn multisig_output<K, B>(
153+
value: u64,
154+
key_id: Identifier,
155+
part_commit: Commitment,
156+
) -> Box<Append<K, B>>
157+
where
158+
K: Keychain,
159+
B: ProofBuild,
160+
{
161+
Box::new(
162+
move |build, acc| -> Result<(Transaction, BlindSum), Error> {
163+
let (tx, sum) = acc?;
164+
165+
// TODO: proper support for different switch commitment schemes
166+
let switch = SwitchCommitmentType::Regular;
167+
168+
// add commit to zero to the initiator's partial commit to the value
169+
let commit_key = build.keychain.derive_key(value, &key_id, switch)?;
170+
let secp = build.keychain.secp();
171+
let commit = secp.commit(0, commit_key)?;
172+
let commit_sum = secp.commit_sum(vec![commit, part_commit.clone()], vec![])?;
173+
174+
debug!("Building output: {}, {:?}", value, commit_sum);
175+
176+
// add zero Rangeproof to build the multiparty rangeproof over a number of steps
177+
let proof = RangeProof::zero();
178+
179+
Ok((
180+
tx.with_output(Output::new(OutputFeatures::Plain, commit_sum, proof)),
181+
sum.add_key_id(key_id.to_value_path(value)),
182+
))
183+
},
184+
)
185+
}
186+
146187
/// Adds a known excess value on the transaction being built. Usually used in
147188
/// combination with the initial_tx function when a new transaction is built
148189
/// by adding to a pre-existing one.

0 commit comments

Comments
 (0)