2019-03-06 20:13:50 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
2019-12-09 15:47:23 +00:00
|
|
|
"bytes"
|
2019-03-06 20:13:50 +00:00
|
|
|
"context"
|
2020-02-08 00:16:38 +00:00
|
|
|
"fmt"
|
2019-03-06 20:13:50 +00:00
|
|
|
|
2020-01-21 23:37:49 +00:00
|
|
|
"github.com/btcsuite/btcd/btcec"
|
2019-03-06 20:13:50 +00:00
|
|
|
"github.com/btcsuite/btcd/wire"
|
2020-08-13 09:17:03 +00:00
|
|
|
"github.com/lightninglabs/lndclient"
|
2019-03-06 20:13:50 +00:00
|
|
|
"github.com/lightningnetwork/lnd/input"
|
2019-12-09 15:34:02 +00:00
|
|
|
"github.com/lightningnetwork/lnd/keychain"
|
2019-03-06 20:13:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type mockSigner struct {
|
2019-12-09 15:34:02 +00:00
|
|
|
lnd *LndMockServices
|
2019-03-06 20:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
|
2020-08-13 09:17:03 +00:00
|
|
|
signDescriptors []*lndclient.SignDescriptor) ([][]byte, error) {
|
2019-03-06 20:13:50 +00:00
|
|
|
|
2020-01-15 08:55:22 +00:00
|
|
|
s.lnd.SignOutputRawChannel <- SignOutputRawRequest{
|
|
|
|
Tx: tx,
|
|
|
|
SignDescriptors: signDescriptors,
|
|
|
|
}
|
|
|
|
|
2019-03-06 20:13:50 +00:00
|
|
|
rawSigs := [][]byte{{1, 2, 3}}
|
|
|
|
|
|
|
|
return rawSigs, nil
|
|
|
|
}
|
2019-12-09 15:34:02 +00:00
|
|
|
|
2020-02-08 00:16:38 +00:00
|
|
|
func (s *mockSigner) ComputeInputScript(ctx context.Context, tx *wire.MsgTx,
|
2020-08-13 09:17:03 +00:00
|
|
|
signDescriptors []*lndclient.SignDescriptor) ([]*input.Script, error) {
|
2020-02-08 00:16:38 +00:00
|
|
|
|
|
|
|
return nil, fmt.Errorf("unimplemented")
|
|
|
|
}
|
|
|
|
|
2019-12-09 15:34:02 +00:00
|
|
|
func (s *mockSigner) SignMessage(ctx context.Context, msg []byte,
|
|
|
|
locator keychain.KeyLocator) ([]byte, error) {
|
|
|
|
|
|
|
|
return s.lnd.Signature, nil
|
|
|
|
}
|
2019-12-09 15:47:23 +00:00
|
|
|
|
|
|
|
func (s *mockSigner) VerifyMessage(ctx context.Context, msg, sig []byte,
|
|
|
|
pubkey [33]byte) (bool, error) {
|
|
|
|
|
|
|
|
// Make the mock somewhat functional by asserting that the message and
|
|
|
|
// signature is what we expect from the mock parameters.
|
|
|
|
mockAssertion := bytes.Equal(msg, []byte(s.lnd.SignatureMsg)) &&
|
|
|
|
bytes.Equal(sig, s.lnd.Signature)
|
|
|
|
|
|
|
|
return mockAssertion, nil
|
|
|
|
}
|
2020-01-21 23:37:49 +00:00
|
|
|
|
|
|
|
func (s *mockSigner) DeriveSharedKey(context.Context, *btcec.PublicKey,
|
|
|
|
*keychain.KeyLocator) ([32]byte, error) {
|
|
|
|
|
|
|
|
return [32]byte{4, 5, 6}, nil
|
|
|
|
}
|