@@ -54,7 +54,46 @@ class MusigContext
5454 private Context ctx ;
5555 public ECPubKey ? SigningPubKey { get ; }
5656
57+ public MusigContext Clone ( )
58+ {
59+ return new MusigContext ( this ) ;
60+ }
61+
62+
63+ /// <inheritdoc cref="MusigContext.MusigContext(ECPubKey[], bool, ReadOnlySpan{byte}, ECPubKey?)"/>
64+ public MusigContext ( ECPubKey [ ] pubkeys , ReadOnlySpan < byte > msg32 , ECPubKey ? signingPubKey = null )
65+ : this ( pubkeys , false , msg32 , signingPubKey )
66+ {
67+ }
68+ /// <summary>
69+ /// Create a new musig context
70+ /// </summary>
71+ /// <param name="pubkeys"><inheritdoc cref="ECPubKey.MusigAggregate(ECPubKey[], bool)" path="/param[@name='pubkeys']"/></param>
72+ /// <param name="sort"><inheritdoc cref="ECPubKey.MusigAggregate(ECPubKey[], bool)" path="/param[@name='sort']"/></param>
73+ /// <param name="msg32">The 32 bytes message to sign</param>
74+ /// <param name="signingPubKey">The pubkey of the key that will sign in this context</param>
75+ /// <exception cref="ArgumentNullException"></exception>
76+ /// <exception cref="ArgumentException"></exception>
77+ /// <exception cref="InvalidOperationException"></exception>
78+ public MusigContext ( ECPubKey [ ] pubkeys , bool sort , ReadOnlySpan < byte > msg32 , ECPubKey ? signingPubKey = null )
79+ {
80+ if ( pubkeys == null )
81+ throw new ArgumentNullException ( nameof ( pubkeys ) ) ;
82+ if ( pubkeys . Length is 0 )
83+ throw new ArgumentException ( nameof ( pubkeys ) , "There should be at least one pubkey in pubKeys" ) ;
84+ if ( signingPubKey != null && ! pubkeys . Contains ( signingPubKey ) )
85+ throw new InvalidOperationException ( "The pubkeys do not contain the signing public key" ) ;
86+ this . SigningPubKey = signingPubKey ;
87+ this . aggregatePubKey = ECPubKey . MusigAggregate ( pubkeys , this , sort ) ;
88+ this . ctx = pubkeys [ 0 ] . ctx ;
89+ this . msg32 = msg32 . ToArray ( ) ;
90+ }
5791
92+ /// <summary>
93+ /// Clone a musig context
94+ /// </summary>
95+ /// <param name="musigContext"></param>
96+ /// <exception cref="ArgumentNullException"></exception>
5897 public MusigContext ( MusigContext musigContext )
5998 {
6099 if ( musigContext == null )
@@ -73,25 +112,6 @@ public MusigContext(MusigContext musigContext)
73112 SigningPubKey = musigContext . SigningPubKey ;
74113 }
75114
76- public MusigContext Clone ( )
77- {
78- return new MusigContext ( this ) ;
79- }
80-
81- public MusigContext ( ECPubKey [ ] pubKeys , ReadOnlySpan < byte > msg32 , ECPubKey ? signingPubKey = null )
82- {
83- if ( pubKeys == null )
84- throw new ArgumentNullException ( nameof ( pubKeys ) ) ;
85- if ( pubKeys . Length is 0 )
86- throw new ArgumentException ( nameof ( pubKeys ) , "There should be at least one pubkey in pubKeys" ) ;
87- if ( signingPubKey != null && ! pubKeys . Contains ( signingPubKey ) )
88- throw new InvalidOperationException ( "The pubkeys do not contain the signing public key" ) ;
89- this . SigningPubKey = signingPubKey ;
90- this . aggregatePubKey = ECPubKey . MusigAggregate ( pubKeys , this ) ;
91- this . ctx = pubKeys [ 0 ] . ctx ;
92- this . msg32 = msg32 . ToArray ( ) ;
93- }
94-
95115 /// <summary>
96116 /// Add tweak to the xonly aggregated pubkey
97117 /// </summary>
@@ -275,12 +295,9 @@ public SecpSchnorrSignature AggregateSignatures(MusigPartialSignature[] partialS
275295 /// <summary>
276296 /// <inheritdoc cref="DeterministicSign(ECPrivKey, byte[])"/>
277297 /// </summary>
278- /// <param name="privKey"><inheritdoc cref="DeterministicSign(ECPrivKey, byte[])" path="/param/ [@name='privKey']"></inheritdoc>/ ></param>
298+ /// <param name="privKey"><inheritdoc cref="DeterministicSign(ECPrivKey, byte[])" path="/param[@name='privKey']"></inheritdoc></param>
279299 /// <returns></returns>
280- public ( MusigPartialSignature Signature , MusigPubNonce PubNonce ) DeterministicSign ( ECPrivKey privKey )
281- {
282- return DeterministicSign ( privKey , null ) ;
283- }
300+ public ( MusigPartialSignature Signature , MusigPubNonce PubNonce ) DeterministicSign ( ECPrivKey privKey ) => DeterministicSign ( privKey , null ) ;
284301
285302 /// <summary>
286303 /// <para>Generates a deterministic nonce and sign with it.</para>
@@ -294,7 +311,7 @@ public SecpSchnorrSignature AggregateSignatures(MusigPartialSignature[] partialS
294311 /// <returns>The partial signature with the deterministic public nonce of this signer</returns>
295312 /// <exception cref="ArgumentNullException"></exception>
296313 /// <exception cref="InvalidOperationException"></exception>
297- public ( MusigPartialSignature Signature , MusigPubNonce PubNonce ) DeterministicSign ( ECPrivKey privKey , byte [ ] ? rand = null )
314+ public ( MusigPartialSignature Signature , MusigPubNonce PubNonce ) DeterministicSign ( ECPrivKey privKey , byte [ ] ? rand )
298315 {
299316 var nonce = GenerateDeterministicNonce ( privKey , rand ) ;
300317 return ( Sign ( privKey , nonce ) , nonce . CreatePubNonce ( ) ) ;
0 commit comments