@@ -35,6 +35,7 @@ use crate::core::{Input, KernelFeatures, Output, OutputFeatures, Transaction, Tx
3535use crate :: libtx:: proof:: { self , ProofBuild } ;
3636use crate :: libtx:: { aggsig, Error } ;
3737use keychain:: { BlindSum , BlindingFactor , Identifier , Keychain , SwitchCommitmentType } ;
38+ use util:: secp:: pedersen:: { Commitment , RangeProof } ;
3839
3940/// Context information available to transaction combinators.
4041pub 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