Skip to content

Commit 518ec24

Browse files
authored
Merge pull request #123 from guggero/getinfo-addr
lndclient: expose node URIs and message signing RPCs in lightning client
2 parents 53dc21f + 304c8f5 commit 518ec24

File tree

7 files changed

+126
-6
lines changed

7 files changed

+126
-6
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ require (
1010
github.com/google/go-cmp v0.3.1 // indirect
1111
github.com/grpc-ecosystem/grpc-gateway v1.10.0
1212
github.com/jessevdk/go-flags v1.4.0
13-
github.com/lightningnetwork/lnd v0.8.0-beta-rc3.0.20191127212142-d59aba35a0ad
14-
github.com/lightningnetwork/lnd/queue v1.0.1
13+
github.com/lightningnetwork/lnd v0.8.0-beta-rc3.0.20191212054348-dca31c2bf8be
14+
github.com/lightningnetwork/lnd/queue v1.0.2
1515
github.com/urfave/cli v1.20.0
1616
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 // indirect
1717
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297

go.sum

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2+
git.schwanenlied.me/yawning/bsaes.git v0.0.0-20180720073208-c0276d75487e h1:F2x1bq7RaNCIuqYpswggh1+c1JmwdnkHNC9wy1KDip0=
23
git.schwanenlied.me/yawning/bsaes.git v0.0.0-20180720073208-c0276d75487e/go.mod h1:BWqTsj8PgcPriQJGl7el20J/7TuT1d/hSyFDXMEpoEo=
34
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
5+
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
46
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e/go.mod h1:Bdzq+51GR4/0DIhaICZEOm+OHvXGwwB2trKZ8B4Y6eQ=
7+
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82 h1:MG93+PZYs9PyEsj/n5/haQu2gK0h4tUtSy9ejtMwWa0=
58
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82/go.mod h1:GbuBk21JqF+driLX3XtJYNZjGa45YDoa9IqCTzNSfEc=
69
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
10+
github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2 h1:2be4ykKKov3M1yISM2E8gnGXZ/N2SsPawfnGiXxaYEU=
711
github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk=
812
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
913
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
@@ -12,6 +16,7 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
1216
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
1317
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
1418
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
19+
github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0=
1520
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
1621
github.com/btcsuite/btcd v0.0.0-20190629003639-c26ffa870fd8/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
1722
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
@@ -83,14 +88,18 @@ github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5a
8388
github.com/google/go-cmp v0.2.1-0.20190312032427-6f77996f0c42/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
8489
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
8590
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
91+
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
8692
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
93+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
8794
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
8895
github.com/grpc-ecosystem/grpc-gateway v1.8.6/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
8996
github.com/grpc-ecosystem/grpc-gateway v1.10.0 h1:yqx/nTDLC6pVrQ8fTaCeeeMJNbmt7HglUpysQATYXV4=
9097
github.com/grpc-ecosystem/grpc-gateway v1.10.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
9198
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
9299
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
100+
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
93101
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
102+
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad h1:heFfj7z0pGsNCekUlsFhO2jstxO4b5iQ665LjwM5mDc=
94103
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
95104
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
96105
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
@@ -129,16 +138,20 @@ github.com/lightninglabs/neutrino v0.11.0 h1:lPpYFCtsfJX2W5zI4pWycPmbbBdr7zU+Baf
129138
github.com/lightninglabs/neutrino v0.11.0/go.mod h1:CuhF0iuzg9Sp2HO6ZgXgayviFTn1QHdSTJlMncK80wg=
130139
github.com/lightningnetwork/lightning-onion v0.0.0-20190909101754-850081b08b6a h1:GoWPN4i4jTKRxhVNh9a2vvBBO1Y2seiJB+SopUYoKyo=
131140
github.com/lightningnetwork/lightning-onion v0.0.0-20190909101754-850081b08b6a/go.mod h1:rigfi6Af/KqsF7Za0hOgcyq2PNH4AN70AaMRxcJkff4=
132-
github.com/lightningnetwork/lnd v0.8.0-beta-rc3.0.20191127212142-d59aba35a0ad h1:0jkgXvk9ZwODFph6yGQZ3JQ9b5WZHIJ91LuB+2Vef/g=
133-
github.com/lightningnetwork/lnd v0.8.0-beta-rc3.0.20191127212142-d59aba35a0ad/go.mod h1:51tWqgjX5ZfYOLTlgkn7fQXCODJPUD3d1t1CsV1DKS4=
141+
github.com/lightningnetwork/lnd v0.8.0-beta-rc3.0.20191212054348-dca31c2bf8be h1:CX8ScoYxJju6AcceHY6nATfRLThZpewqHcgn4sGMdZE=
142+
github.com/lightningnetwork/lnd v0.8.0-beta-rc3.0.20191212054348-dca31c2bf8be/go.mod h1:60/zDjDYaYPmISAm3J1WWKyyt+ZiAvuET1XzglO8s70=
143+
github.com/lightningnetwork/lnd/cert v1.0.0 h1:J0gtf2UNQX2U+/j5cXnX2wIMSTuJuwrXv7m9qJr2wtw=
134144
github.com/lightningnetwork/lnd/cert v1.0.0/go.mod h1:fmtemlSMf5t4hsQmcprSoOykypAPp+9c+0d0iqTScMo=
135145
github.com/lightningnetwork/lnd/queue v1.0.1 h1:jzJKcTy3Nj5lQrooJ3aaw9Lau3I0IwvQR5sqtjdv2R0=
136146
github.com/lightningnetwork/lnd/queue v1.0.1/go.mod h1:vaQwexir73flPW43Mrm7JOgJHmcEFBWWSl9HlyASoms=
147+
github.com/lightningnetwork/lnd/queue v1.0.2 h1:Hx43fmTz2pDH4fIYDr57P/M5cB+GEMLzN+eif8576Xo=
148+
github.com/lightningnetwork/lnd/queue v1.0.2/go.mod h1:YTkTVZCxz8tAYreH27EO3s8572ODumWrNdYW2E/YKxg=
137149
github.com/lightningnetwork/lnd/ticker v1.0.0 h1:S1b60TEGoTtCe2A0yeB+ecoj/kkS4qpwh6l+AkQEZwU=
138150
github.com/lightningnetwork/lnd/ticker v1.0.0/go.mod h1:iaLXJiVgI1sPANIF2qYYUJXjoksPNvGNYowB8aRbpX0=
139151
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=
140152
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1sNPI5H8P3NkTFF4LuwMdPl2DodF60qAKqY=
141153
github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
154+
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
142155
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
143156
github.com/miekg/dns v0.0.0-20171125082028-79bfde677fa8 h1:PRMAcldsl4mXKJeRNB/KVNz6TlbS6hk2Rs42PqgU3Ws=
144157
github.com/miekg/dns v0.0.0-20171125082028-79bfde677fa8/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
@@ -153,12 +166,16 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
153166
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
154167
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
155168
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
169+
github.com/prometheus/client_golang v0.9.3 h1:9iH4JKXLzFbOAdtqv/a+j8aewx2Y8lAjAydhbaScPF8=
156170
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
157171
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
172+
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 h1:S/YWwWx/RA8rT8tKFRuGUZhuA90OyIBpPCXkcbwU8DE=
158173
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
159174
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
175+
github.com/prometheus/common v0.4.0 h1:7etb9YClo3a6HjLzfl6rIQaU+FDfi0VSX39io3aQ+DM=
160176
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
161177
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
178+
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084 h1:sofwID9zm4tzrgykg80hfFph1mryUeLRsUfoocVVmRY=
162179
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
163180
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
164181
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
@@ -168,6 +185,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
168185
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
169186
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
170187
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
188+
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02 h1:tcJ6OjwOMvExLlzrAVZute09ocAGa7KqOON60++Gz4E=
171189
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02/go.mod h1:tHlrkM198S068ZqfrO6S8HsoJq2bF3ETfTL+kt4tInY=
172190
github.com/urfave/cli v1.18.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
173191
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
@@ -218,6 +236,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
218236
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
219237
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
220238
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
239+
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM=
221240
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
222241
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
223242
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

lndclient/lightning_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Info struct {
4444
IdentityPubkey [33]byte
4545
Alias string
4646
Network string
47+
Uris []string
4748
}
4849

4950
var (
@@ -145,6 +146,7 @@ func (s *lightningClient) GetInfo(ctx context.Context) (*Info, error) {
145146
IdentityPubkey: pubKeyArray,
146147
Alias: resp.Alias,
147148
Network: resp.Chains[0].Network,
149+
Uris: resp.Uris,
148150
}, nil
149151
}
150152

lndclient/signer_client.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/btcsuite/btcd/wire"
77
"github.com/lightninglabs/loop/swap"
88
"github.com/lightningnetwork/lnd/input"
9+
"github.com/lightningnetwork/lnd/keychain"
910
"github.com/lightningnetwork/lnd/lnrpc/signrpc"
1011
"google.golang.org/grpc"
1112
)
@@ -14,6 +15,17 @@ import (
1415
type SignerClient interface {
1516
SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
1617
signDescriptors []*input.SignDescriptor) ([][]byte, error)
18+
19+
// SignMessage signs a message with the key specified in the key
20+
// locator. The returned signature is fixed-size LN wire format encoded.
21+
SignMessage(ctx context.Context, msg []byte,
22+
locator keychain.KeyLocator) ([]byte, error)
23+
24+
// VerifyMessage verifies a signature over a message using the public
25+
// key provided. The signature must be fixed-size LN wire format
26+
// encoded.
27+
VerifyMessage(ctx context.Context, msg, sig []byte, pubkey [33]byte) (
28+
bool, error)
1729
}
1830

1931
type signerClient struct {
@@ -93,3 +105,50 @@ func (s *signerClient) SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
93105

94106
return resp.RawSigs, nil
95107
}
108+
109+
// SignMessage signs a message with the key specified in the key locator. The
110+
// returned signature is fixed-size LN wire format encoded.
111+
func (s *signerClient) SignMessage(ctx context.Context, msg []byte,
112+
locator keychain.KeyLocator) ([]byte, error) {
113+
114+
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
115+
defer cancel()
116+
117+
rpcIn := &signrpc.SignMessageReq{
118+
Msg: msg,
119+
KeyLoc: &signrpc.KeyLocator{
120+
KeyFamily: int32(locator.Family),
121+
KeyIndex: int32(locator.Index),
122+
},
123+
}
124+
125+
rpcCtx = s.signerMac.WithMacaroonAuth(rpcCtx)
126+
resp, err := s.client.SignMessage(rpcCtx, rpcIn)
127+
if err != nil {
128+
return nil, err
129+
}
130+
131+
return resp.Signature, nil
132+
}
133+
134+
// VerifyMessage verifies a signature over a message using the public key
135+
// provided. The signature must be fixed-size LN wire format encoded.
136+
func (s *signerClient) VerifyMessage(ctx context.Context, msg, sig []byte,
137+
pubkey [33]byte) (bool, error) {
138+
139+
rpcCtx, cancel := context.WithTimeout(ctx, rpcTimeout)
140+
defer cancel()
141+
142+
rpcIn := &signrpc.VerifyMessageReq{
143+
Msg: msg,
144+
Signature: sig,
145+
Pubkey: pubkey[:],
146+
}
147+
148+
rpcCtx = s.signerMac.WithMacaroonAuth(rpcCtx)
149+
resp, err := s.client.VerifyMessage(rpcCtx, rpcIn)
150+
if err != nil {
151+
return false, err
152+
}
153+
return resp.Valid, nil
154+
}

test/lightning_client_mock.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package test
22

33
import (
44
"crypto/rand"
5+
"encoding/hex"
56
"fmt"
67
"sync"
78
"time"
@@ -48,10 +49,16 @@ func (h *mockLightningClient) ConfirmedWalletBalance(ctx context.Context) (
4849
func (h *mockLightningClient) GetInfo(ctx context.Context) (*lndclient.Info,
4950
error) {
5051

52+
pubKeyBytes, err := hex.DecodeString(h.lnd.NodePubkey)
53+
if err != nil {
54+
return nil, err
55+
}
5156
var pubKey [33]byte
57+
copy(pubKey[:], pubKeyBytes)
5258
return &lndclient.Info{
5359
BlockHeight: 600,
5460
IdentityPubkey: pubKey,
61+
Uris: []string{h.lnd.NodePubkey + "@127.0.0.1:9735"},
5562
}, nil
5663
}
5764

test/lnd_services_mock.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import (
1414
"github.com/lightningnetwork/lnd/zpay32"
1515
)
1616

17-
var testStartingHeight = int32(600)
17+
var (
18+
testStartingHeight = int32(600)
19+
testNodePubkey = "03f5374b16f0b1f1b49101de1b9d89e0b460bc57ce9c2f9" +
20+
"132b73dfc76d3704daa"
21+
testSignature = []byte{55, 66, 77, 88, 99}
22+
testSignatureMsg = "test"
23+
)
1824

1925
// NewMockLnd returns a new instance of LndMockServices that can be used in unit
2026
// tests.
@@ -54,13 +60,17 @@ func NewMockLnd() *LndMockServices {
5460
FailInvoiceChannel: make(chan lntypes.Hash, 2),
5561
epochChannel: make(chan int32),
5662
Height: testStartingHeight,
63+
NodePubkey: testNodePubkey,
64+
Signature: testSignature,
65+
SignatureMsg: testSignatureMsg,
5766
}
5867

5968
lightningClient.lnd = &lnd
6069
chainNotifier.lnd = &lnd
6170
walletKit.lnd = &lnd
6271
invoices.lnd = &lnd
6372
router.lnd = &lnd
73+
signer.lnd = &lnd
6474

6575
lnd.WaitForFinished = func() {
6676
chainNotifier.WaitForFinished()
@@ -120,7 +130,10 @@ type LndMockServices struct {
120130
RouterSendPaymentChannel chan RouterPaymentChannelMessage
121131
TrackPaymentChannel chan TrackPaymentMessage
122132

123-
Height int32
133+
Height int32
134+
NodePubkey string
135+
Signature []byte
136+
SignatureMsg string
124137

125138
WaitForFinished func()
126139

test/signer_mock.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package test
22

33
import (
4+
"bytes"
45
"context"
56

67
"github.com/btcsuite/btcd/wire"
78
"github.com/lightningnetwork/lnd/input"
9+
"github.com/lightningnetwork/lnd/keychain"
810
)
911

1012
type mockSigner struct {
13+
lnd *LndMockServices
1114
}
1215

1316
func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
@@ -17,3 +20,20 @@ func (s *mockSigner) SignOutputRaw(ctx context.Context, tx *wire.MsgTx,
1720

1821
return rawSigs, nil
1922
}
23+
24+
func (s *mockSigner) SignMessage(ctx context.Context, msg []byte,
25+
locator keychain.KeyLocator) ([]byte, error) {
26+
27+
return s.lnd.Signature, nil
28+
}
29+
30+
func (s *mockSigner) VerifyMessage(ctx context.Context, msg, sig []byte,
31+
pubkey [33]byte) (bool, error) {
32+
33+
// Make the mock somewhat functional by asserting that the message and
34+
// signature is what we expect from the mock parameters.
35+
mockAssertion := bytes.Equal(msg, []byte(s.lnd.SignatureMsg)) &&
36+
bytes.Equal(sig, s.lnd.Signature)
37+
38+
return mockAssertion, nil
39+
}

0 commit comments

Comments
 (0)