@@ -54,7 +54,46 @@ class MusigContext
54
54
private Context ctx ;
55
55
public ECPubKey ? SigningPubKey { get ; }
56
56
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
+ }
57
91
92
+ /// <summary>
93
+ /// Clone a musig context
94
+ /// </summary>
95
+ /// <param name="musigContext"></param>
96
+ /// <exception cref="ArgumentNullException"></exception>
58
97
public MusigContext ( MusigContext musigContext )
59
98
{
60
99
if ( musigContext == null )
@@ -73,25 +112,6 @@ public MusigContext(MusigContext musigContext)
73
112
SigningPubKey = musigContext . SigningPubKey ;
74
113
}
75
114
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
-
95
115
/// <summary>
96
116
/// Add tweak to the xonly aggregated pubkey
97
117
/// </summary>
@@ -275,12 +295,9 @@ public SecpSchnorrSignature AggregateSignatures(MusigPartialSignature[] partialS
275
295
/// <summary>
276
296
/// <inheritdoc cref="DeterministicSign(ECPrivKey, byte[])"/>
277
297
/// </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>
279
299
/// <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 ) ;
284
301
285
302
/// <summary>
286
303
/// <para>Generates a deterministic nonce and sign with it.</para>
@@ -294,7 +311,7 @@ public SecpSchnorrSignature AggregateSignatures(MusigPartialSignature[] partialS
294
311
/// <returns>The partial signature with the deterministic public nonce of this signer</returns>
295
312
/// <exception cref="ArgumentNullException"></exception>
296
313
/// <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 )
298
315
{
299
316
var nonce = GenerateDeterministicNonce ( privKey , rand ) ;
300
317
return ( Sign ( privKey , nonce ) , nonce . CreatePubNonce ( ) ) ;
0 commit comments