-
Notifications
You must be signed in to change notification settings - Fork 411
Invoices crate #870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheBlueMatt
merged 5 commits into
lightningdevkit:main
from
valentinewallace:invoices-crate
Apr 10, 2021
Merged
Invoices crate #870
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f00bb10
Pure import of lightning-invoice crate
sgeisler 56069ba
Clean up lightning-invoice CI, license, and add to workspaces
valentinewallace b516b3d
Add lightning invoice fuzzing to CI
valentinewallace 741f118
Clean up lightning-invoice Cargo.toml and README
valentinewallace c3d25ed
Fix Windows
valentinewallace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target | ||
**/*.rs.bk | ||
Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
name = "lightning-invoice" | ||
description = "Data structures to parse and serialize BOLT11 lightning invoices" | ||
version = "0.4.0" | ||
authors = ["Sebastian Geisler <[email protected]>"] | ||
documentation = "https://docs.rs/lightning-invoice/" | ||
license = "MIT OR Apache-2.0" | ||
keywords = [ "lightning", "bitcoin", "invoice", "BOLT11" ] | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
bech32 = "0.7" | ||
secp256k1 = { version = "0.20", features = ["recovery"] } | ||
num-traits = "0.2.8" | ||
bitcoin_hashes = "0.9.4" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# lightning-invoice | ||
[](https://docs.rs/lightning-invoice/) | ||
|
||
This repo provides data structures for BOLT 11 lightning invoices and | ||
functions to parse and serialize these from and to bech32. | ||
|
||
**Please be sure to run the test suite since we need to check assumptions | ||
regarding `SystemTime`'s bounds on your platform. You can also call `check_platform` | ||
on startup or in your test suite to do so.** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
hfuzz_* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "lightning-invoice-fuzz" | ||
version = "0.0.1" | ||
authors = ["Automatically generated"] | ||
publish = false | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[features] | ||
afl_fuzz = ["afl"] | ||
honggfuzz_fuzz = ["honggfuzz"] | ||
|
||
[dependencies] | ||
honggfuzz = { version = "0.5", optional = true } | ||
afl = { version = "0.4", optional = true } | ||
lightning-invoice = { path = ".."} | ||
bech32 = "0.7" | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "serde_data_part" | ||
path = "fuzz_targets/serde_data_part.rs" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
set -e | ||
cargo install --force honggfuzz | ||
for TARGET in fuzz_targets/*; do | ||
FILENAME=$(basename $TARGET) | ||
FILE="${FILENAME%.*}" | ||
if [ -d hfuzz_input/$FILE ]; then | ||
HFUZZ_INPUT_ARGS="-f hfuzz_input/$FILE/input" | ||
fi | ||
HFUZZ_BUILD_ARGS="--features honggfuzz_fuzz" HFUZZ_RUN_ARGS="-N1000000 --exit_upon_crash -v $HFUZZ_INPUT_ARGS" cargo hfuzz run $FILE | ||
|
||
if [ -f hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT ]; then | ||
cat hfuzz_workspace/$FILE/HONGGFUZZ.REPORT.TXT | ||
for CASE in hfuzz_workspace/$FILE/SIG*; do | ||
cat $CASE | xxd -p | ||
done | ||
exit 1 | ||
fi | ||
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
extern crate lightning_invoice; | ||
extern crate bech32; | ||
|
||
use lightning_invoice::RawDataPart; | ||
use bech32::{FromBase32, ToBase32, u5}; | ||
|
||
fn do_test(data: &[u8]) { | ||
let bech32 = data.iter().map(|x| u5::try_from_u8(x % 32).unwrap()).collect::<Vec<_>>(); | ||
let invoice = match RawDataPart::from_base32(&bech32) { | ||
Ok(invoice) => invoice, | ||
Err(_) => return, | ||
}; | ||
|
||
// Our encoding is not worse than the input | ||
assert!(invoice.to_base32().len() <= bech32.len()); | ||
|
||
// Our serialization is loss-less | ||
assert_eq!( | ||
RawDataPart::from_base32(&invoice.to_base32()).expect("faild parsing out own encoding"), | ||
invoice | ||
); | ||
} | ||
|
||
#[cfg(feature = "afl")] | ||
#[macro_use] extern crate afl; | ||
#[cfg(feature = "afl")] | ||
fn main() { | ||
fuzz!(|data| { | ||
do_test(&data); | ||
}); | ||
} | ||
|
||
#[cfg(feature = "honggfuzz")] | ||
#[macro_use] extern crate honggfuzz; | ||
#[cfg(feature = "honggfuzz")] | ||
fn main() { | ||
loop { | ||
fuzz!(|data| { | ||
do_test(data); | ||
}); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) { | ||
let mut b = 0; | ||
for (idx, c) in hex.as_bytes().iter().filter(|&&c| c != b'\n').enumerate() { | ||
b <<= 4; | ||
match *c { | ||
b'A'...b'F' => b |= c - b'A' + 10, | ||
b'a'...b'f' => b |= c - b'a' + 10, | ||
b'0'...b'9' => b |= c - b'0', | ||
_ => panic!("Bad hex"), | ||
} | ||
if (idx & 1) == 1 { | ||
out.push(b); | ||
b = 0; | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn duplicate_crash() { | ||
let mut a = Vec::new(); | ||
extend_vec_from_hex("000000", &mut a); | ||
super::do_test(&a); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about licenses, but if you need my ok for this you hereby have it.