Commit Graph

38 Commits

Author SHA1 Message Date
Johan T. Halseth
386f8ece54
routing+zpay32: copy pubkeys before nilling Curve and spewing
Since nilling the pubkey curve will lead to a nil-pointer exception if
the key is later used for signature verification, we make sure to make a
copy before nilling and spewing.
2019-06-12 12:19:43 +02:00
Joost Jager
2be1051fb6
zpay32: move HopHint and DefaultFinalCLTVDelta 2019-03-15 10:08:32 +01:00
Conner Fromknecht
1ded697e8d
multi: sort import paths with gofmt 2018-08-02 18:20:49 -07:00
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Wilmer Paulino
ea9e609ef0
zpay32: modify an invoice's r field to allow multiple routes
Before this commit, if an invoice encoded multiple `r` fields, we would
decode them as one single route. We fix this by allowing an invoice to
store multiple routes.
2018-04-20 04:01:34 -04:00
Sean Erle Johnson
c6499f095a zpay32: improve "wrong network" error message 2018-04-18 12:37:28 -07:00
Olaoluwa Osuntokun
f6e6196f65
Merge pull request #898 from vapopov/hrprefix
Wrong BOLT11 prefix in regtest
2018-04-17 18:30:37 -07:00
Olaoluwa Osuntokun
10847170ee
zpay32: adjust uint64 encoding to account for math.MaxUnit64
In this commit, we fix a logic error in our routine for converting a
uint64 to/from base32. Before this commit, we assumed that the max
number of groups was 12. However, the math.MaxUint64 (1<<64 - 1) can
actually consume more than 12 groups with an extra set of bits. Before
this commit, we would panic when attempting to parse an invoice
generated like so:
  * addinvoice --amt 1337000 --expiry 99999999999999999

To fix this issue, we modify our logic to expect at most 13 groups.
Additionally, we've added a new test that would panic before applying
this commit.

Fixes #972.
2018-03-29 16:24:20 -07:00
Vadym Popov
818eab7109
#882: wrong BOLT11 prefix in regtest 2018-03-21 11:51:04 +02:00
Olaoluwa Osuntokun
8d35ea381e
zpay32: remove test case with negative amt 2018-03-08 12:50:50 -05:00
Daniel McNally
6e5477e378 zpay32 test: litecoin decode tests
New tests are added for creating, decoding, and re-encoding
litecoin invoices for both mainnet and testnet, as well as a test
that expects an error when the active network mismatches the
invoice.
2018-02-19 10:19:24 -05:00
Daniel McNally
fdbdcf1560 zpay32: handle segwit prefixes > 2 chars
This change fixes a bug when an invoice is decoded for a network
whose bech32 segwit prefix is longer than 2 characters. The length
of the Bech32HRPSegwit network parameter is used to determine
where in the human-readable portion of the invoice the amount
begins, rather than assuming it begins after the first four
characters.

Decode() now throws an error when the encoded invoice does
not match the active network.

Changes the minimum hrp length check to >= 3 instead of >= 4.

Also removes a redundant "if ...; err != nil check" that was raising
a warning in invoice.go.
2018-02-19 10:18:16 -05:00
Nalin Bhardwaj
00dacc7bb5
zpay32: Add test for non-ASCII(UTF-8) descriptions 2018-02-10 04:24:53 +05:30
Olaoluwa Osuntokun
9f0214428a
zpay32: update parsing to use new lnwire.Sig API 2018-02-06 20:14:33 -08:00
practicalswift
a93736d21e multi: comprehensive typo fixes across all packages 2018-02-06 19:11:11 -08:00
Valentine Wallace
3b4ffbca48 zpay32: add 2 tests for invalid invoice fields
Test for empty fallback address field, and separately test for invalid
routing info length (not a multiple of 51).
2018-01-27 18:45:57 -08:00
Olaoluwa Osuntokun
42014f5b7b
Merge pull request #650 from wilmerpaulino/invoice-negative-amount
invoice: avoid negative msat amounts
2018-01-27 18:34:56 -08:00
Wilmer Paulino
c09cbdc284
zpay32: add encode/decode tests for invoices with zero amount 2018-01-27 19:05:25 -05:00
Wilmer Paulino
cfb19b8d51
invoice: avoid negative msat amounts 2018-01-23 14:38:20 -05:00
Wilmer Paulino
8807fb804b
invoice: add unit tests for each parsed tagged field
This commit introduces unit tests for each parsed tagged field to cover
all possible input scenarios.
2018-01-19 12:00:51 -05:00
Wilmer Paulino
07ac278771
invoice: properly parse the field data length
When accessing a value from a byte slice, the value is returned as a
byte, which is just a uint8. When the first byte takes more than 3 bits
of space, shifting 5 bits left results in data loss.
2018-01-19 10:52:24 -05:00
Wilmer Paulino
fa2cc57ca6
invoice: sanity check routing info field
This commit allows parseRoutingInfo to return an error when parsing a
routing info field whose length is not a multiple of 51 bytes, rather
than crash.
2018-01-19 10:52:23 -05:00
Wilmer Paulino
db7154a401
invoice: sanity check empty fallback addr field
This commit allows parseFallbackAddr to return an error when parsing an
empty fallback address field, rather than crash.
2018-01-19 10:52:22 -05:00
Wilmer Paulino
00d530bd91
invoice: remove duplicate code when parsing the timestamp 2018-01-19 10:52:21 -05:00
Wilmer Paulino
6f5d673679
invoice: refactor parsing tagged fields
This commit refactors parsing each of the tagged fields of an invoice
into their own method. This makes the code easier to read and will allow
us to introduce unit tests for each parsing method.
2018-01-19 10:52:21 -05:00
Wilmer Paulino
445e11db5c bolt11: handle r field fee spec change
Updates the way fees are handled for routing payments.
See lightningnetwork/lightning-rfc#317.
2018-01-04 13:23:56 +01:00
Matt Drollette
adf0d98194 multi: fix several typos in godoc comments 2017-12-17 18:40:05 -08:00
Olaoluwa Osuntokun
a29210f089
rpc: properly interpret and parse cltvDelta from payreqs (if exists) 2017-10-22 18:37:00 -07:00
Olaoluwa Osuntokun
c54e6fc803
zpay32: add new 'c' field to payreqs for specifying final cltv delta 2017-10-22 18:36:53 -07:00
Johan T. Halseth
070eb0ec3e
zpay32: make expiry time only accessable using Expiry()
This commit renames the invoice field Expiry to expiry, and changes
the type from time.Time to time.Duration. Getting the value of the
field will now have to be done using the getter Expiry(), which
will also return the default invoice expiry (3600s) if it is not set
explicitly by the the invoice.
2017-09-27 13:17:18 +02:00
Johan T. Halseth
b645f02418
zpay32: move the BOLT-11 compatible invoice format to zpay32 namespace 2017-09-27 12:26:06 +02:00
Olaoluwa Osuntokun
1be4d67ce4
multi: run all test instances in parallel 2017-06-17 01:00:07 +02:00
Olaoluwa Osuntokun
6b3a258e86
multi: fix formatting issues in packge README's 2017-03-27 16:25:25 -07:00
Alex Akselrod
55e693aa09 zpay32: fix decoding when payment request is too short
This commit fixes a panic that can result when a zpay32 payment request
that is too short (and possibly invalid) is attempted to be decoded.

To fix this bug, we now simply ensure that that after we decode the
zbase32 encoding, the resulting set of bytes is _exactly_ the length we
expect. A new error has been introduced to handle this case, and a
simple test has been added which ensures proper handling of short
payment requests.

Fixes #127.
2017-02-16 19:30:28 +08:00
Olaoluwa Osuntokun
d94777acf6
zpay32: ensure argument to Decode is not an empty string
This commit fixes a possible panic which can arise within the library
due to poor user-data. We now explicitly check for an empty string,
exiting early if found within the Decode method.
2017-01-29 14:58:15 -08:00
Trevin Hofmann
a13ac90d46 multi: add link to LICENSE in README license badges (#100) 2017-01-12 16:31:08 -08:00
Olaoluwa Osuntokun
4ccdad0d66
multi: add README's for all sub-packages 2017-01-10 15:02:37 -08:00
Olaoluwa Osuntokun
bd0cf51581
zpay32: create new package for encoding/decoding payment requests
This commit adds a new package “zpay32”: which is used within the
daemon to encode/decode payment requests. A payment request currently
consists of: the public key of the payee, the payment hash to use, and
finally the amount to send over the network. The encoded payment
request consists of the mentioned fields concatenated to each other, a
cc32 checksum is added, then the blob is finally encoded using zbas32.
I call the resulting scheme “zpay32”.

A number of extensions may be explored in future commits including
adding a version byte, adding “hint” routing information,
cryptographically signed receipts and more,
2017-01-02 15:17:58 -08:00