forked from lightninglabs/taproot-assets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtual_tx_signer.go
51 lines (42 loc) · 1.45 KB
/
virtual_tx_signer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package taprootassets
import (
"context"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/lndclient"
"github.com/lightninglabs/taproot-assets/tapscript"
)
// LndRpcVirtualTxSigner is an implementation of the tapscript.Signer
// interface backed by an active lnd node.
type LndRpcVirtualTxSigner struct {
lnd *lndclient.LndServices
}
// NewLndRpcVirtualTxSigner returns a new tx signer instance backed by the
// passed connection to a remote lnd node.
func NewLndRpcVirtualTxSigner(lnd *lndclient.LndServices) *LndRpcVirtualTxSigner {
return &LndRpcVirtualTxSigner{
lnd: lnd,
}
}
// SignVirtualTx generates a signature according to the passed signing
// descriptor and virtual TX.
func (l *LndRpcVirtualTxSigner) SignVirtualTx(signDesc *lndclient.SignDescriptor,
tx *wire.MsgTx, prevOut *wire.TxOut) (*schnorr.Signature, error) {
sigs, err := l.lnd.Signer.SignOutputRaw(
context.Background(), tx, []*lndclient.SignDescriptor{signDesc},
[]*wire.TxOut{prevOut},
)
if err != nil {
return nil, err
}
// Our signer should only ever produce one signature or fail before this
// point, so accessing the signature directly is safe.
virtualTxSig, err := schnorr.ParseSignature(sigs[0])
if err != nil {
return nil, err
}
return virtualTxSig, nil
}
// A compile time assertion to ensure LndRpcVirtualTxSigner meets the
// tapscript.Signer interface.
var _ tapscript.Signer = (*LndRpcVirtualTxSigner)(nil)