@@ -10,6 +10,7 @@ import (
1010 "github.com/btcsuite/btcd/btcec/v2"
1111 "github.com/btcsuite/btcd/btcutil"
1212 "github.com/btcsuite/btcd/chaincfg"
13+ "github.com/btcsuite/btcd/chaincfg/chainhash"
1314 "github.com/btcsuite/btcd/wire"
1415 "github.com/lightninglabs/lndclient"
1516 "github.com/lightninglabs/loop/loopdb"
@@ -140,6 +141,12 @@ type MuSig2SignSweep func(ctx context.Context,
140141 prevoutMap map [wire.OutPoint ]* wire.TxOut ) (
141142 []byte , []byte , error )
142143
144+ // SignMuSig2 is a function that can be used to sign a sweep transaction in a
145+ // custom way.
146+ type SignMuSig2 func (ctx context.Context , muSig2Version input.MuSig2Version ,
147+ swapHash lntypes.Hash , rootHash chainhash.Hash , sigHash [32 ]byte ,
148+ ) ([]byte , error )
149+
143150// VerifySchnorrSig is a function that can be used to verify a schnorr
144151// signature.
145152type VerifySchnorrSig func (pubKey * btcec.PublicKey , hash , sig []byte ) error
@@ -245,6 +252,12 @@ type Batcher struct {
245252 // the caller has to update it in the source of SweepInfo (interface
246253 // SweepFetcher) and re-add the sweep by calling AddSweep.
247254 noBumping bool
255+
256+ // customMuSig2Signer is a custom signer. If it is set, it is used to
257+ // create musig2 signatures instead of musig2SignSweep and signerClient.
258+ // Note that musig2SignSweep must be nil in this case, however signer
259+ // client must still be provided, as it is used for non-coop spendings.
260+ customMuSig2Signer SignMuSig2
248261}
249262
250263// BatcherConfig holds batcher configuration.
@@ -254,6 +267,12 @@ type BatcherConfig struct {
254267 // the caller has to update it in the source of SweepInfo (interface
255268 // SweepFetcher) and re-add the sweep by calling AddSweep.
256269 noBumping bool
270+
271+ // customMuSig2Signer is a custom signer. If it is set, it is used to
272+ // create musig2 signatures instead of musig2SignSweep and signerClient.
273+ // Note that musig2SignSweep must be nil in this case, however signer
274+ // client must still be provided, as it is used for non-coop spendings.
275+ customMuSig2Signer SignMuSig2
257276}
258277
259278// BatcherOption configures batcher behaviour.
@@ -269,6 +288,17 @@ func WithNoBumping() BatcherOption {
269288 }
270289}
271290
291+ // WithCustomSignMuSig2 instructs sweepbatcher to use a custom function to
292+ // produce MuSig2 signatures. If it is set, it is used to create
293+ // musig2 signatures instead of musig2SignSweep and signerClient. Note
294+ // that musig2SignSweep must be nil in this case, however signerClient
295+ // must still be provided, as it is used for non-coop spendings.
296+ func WithCustomSignMuSig2 (customMuSig2Signer SignMuSig2 ) BatcherOption {
297+ return func (cfg * BatcherConfig ) {
298+ cfg .customMuSig2Signer = customMuSig2Signer
299+ }
300+ }
301+
272302// NewBatcher creates a new Batcher instance.
273303func NewBatcher (wallet lndclient.WalletKitClient ,
274304 chainNotifier lndclient.ChainNotifierClient ,
@@ -282,21 +312,27 @@ func NewBatcher(wallet lndclient.WalletKitClient,
282312 opt (& cfg )
283313 }
284314
315+ if cfg .customMuSig2Signer != nil && musig2ServerSigner != nil {
316+ panic ("customMuSig2Signer must not be used with " +
317+ "musig2ServerSigner" )
318+ }
319+
285320 return & Batcher {
286- batches : make (map [int32 ]* batch ),
287- sweepReqs : make (chan SweepRequest ),
288- errChan : make (chan error , 1 ),
289- quit : make (chan struct {}),
290- initDone : make (chan struct {}),
291- wallet : wallet ,
292- chainNotifier : chainNotifier ,
293- signerClient : signerClient ,
294- musig2ServerSign : musig2ServerSigner ,
295- VerifySchnorrSig : verifySchnorrSig ,
296- chainParams : chainparams ,
297- store : store ,
298- sweepStore : sweepStore ,
299- noBumping : cfg .noBumping ,
321+ batches : make (map [int32 ]* batch ),
322+ sweepReqs : make (chan SweepRequest ),
323+ errChan : make (chan error , 1 ),
324+ quit : make (chan struct {}),
325+ initDone : make (chan struct {}),
326+ wallet : wallet ,
327+ chainNotifier : chainNotifier ,
328+ signerClient : signerClient ,
329+ musig2ServerSign : musig2ServerSigner ,
330+ VerifySchnorrSig : verifySchnorrSig ,
331+ chainParams : chainparams ,
332+ store : store ,
333+ sweepStore : sweepStore ,
334+ noBumping : cfg .noBumping ,
335+ customMuSig2Signer : cfg .customMuSig2Signer ,
300336 }
301337}
302338
@@ -456,6 +492,7 @@ func (b *Batcher) spinUpBatch(ctx context.Context) (*batch, error) {
456492 cfg := batchConfig {
457493 maxTimeoutDistance : defaultMaxTimeoutDistance ,
458494 noBumping : b .noBumping ,
495+ customMuSig2Signer : b .customMuSig2Signer ,
459496 }
460497
461498 switch b .chainParams {
@@ -574,6 +611,7 @@ func (b *Batcher) spinUpBatchFromDB(ctx context.Context, batch *batch) error {
574611 cfg := batchConfig {
575612 maxTimeoutDistance : batch .cfg .maxTimeoutDistance ,
576613 noBumping : b .noBumping ,
614+ customMuSig2Signer : b .customMuSig2Signer ,
577615 }
578616
579617 newBatch , err := NewBatchFromDB (cfg , batchKit )
@@ -637,6 +675,7 @@ func (b *Batcher) FetchUnconfirmedBatches(ctx context.Context) ([]*batch,
637675 bchCfg := batchConfig {
638676 maxTimeoutDistance : bch .MaxTimeoutDistance ,
639677 noBumping : b .noBumping ,
678+ customMuSig2Signer : b .customMuSig2Signer ,
640679 }
641680 batch .cfg = & bchCfg
642681
0 commit comments