From aaeffddb6560dd72d7084f5f383dbc83907853aa Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Fri, 19 Mar 2021 16:03:50 +0100 Subject: [PATCH] Rust lib extracted from LNP/BP Core Lib repo --- .gitignore | 12 + CODE_OF_CONDUCT.md | 5 + LICENSE | 21 + README.md | 18 + codecov.yml | 17 + rust/.rustfmt.toml | 3 + rust/Cargo.lock | 1924 ++++++++++++++++++++++++++++++++++++++++++++ rust/Cargo.toml | 68 ++ rust/src/base.rs | 908 +++++++++++++++++++++ rust/src/lib.rs | 40 + rust/src/main.rs | 250 ++++++ 11 files changed, 3266 insertions(+) create mode 100644 .gitignore create mode 100644 CODE_OF_CONDUCT.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 codecov.yml create mode 100644 rust/.rustfmt.toml create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/src/base.rs create mode 100644 rust/src/lib.rs create mode 100644 rust/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8ab911 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# Generated by Cargo +# will have compiled files and executables +/target + +# These are backup files generated by rustfmt +**/*.rs.bk + +.idea + +*.swp + +/dep_test diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d010486 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,5 @@ +# Code of Conduct + +Out code of conduct is not to have a code of conduct. Restriction is the word +of sin: free people writing free code take their own decisions and act in a +way they like; taking all responsibility for the consequences. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ca265a6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020-2021 LNP/BP Standards Association + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f60c65b --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# LNP/BP Invoice Library + +Library providing functionality for doing universal invoices covering Bitcoin, +Lightning Network and RGB (on-chain and LN) according to LNPBP-38 standard. +Supports address-, UTXO-, channel-, miniscript-descriptor- and PSBT-based +invoices with such features as: +- Paying arbitrary amounts (donations etc) +- Recurrent payments +- Per-item prices with multiple item orders +- Expiration dates +- Currency exchange rate requirements +- Extended information about merchants, invoice details etc +- Optional merchant signatures + +Read more on this invoices in +[slides](https://github.com/LNP-BP/FAQ/blob/master/Presentation%20slides/Universal%20LNP-BP%20invoices.pdf) +or watch [YouTube recording](https://www.youtube.com/watch?v=R1QudCywRGk) of one +of LNP/BP Association development calls discussing universal invoices. diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..68325a2 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,17 @@ +codecov: + require_ci_to_pass: no + +coverage: + precision: 1 + round: nearest + range: "0...95" + # TODO: Update codecov default requirements after v1.0 release + status: + project: + default: + target: 0% + threshold: 1% + patch: + default: + target: 0% + threshold: 1% \ No newline at end of file diff --git a/rust/.rustfmt.toml b/rust/.rustfmt.toml new file mode 100644 index 0000000..83a2153 --- /dev/null +++ b/rust/.rustfmt.toml @@ -0,0 +1,3 @@ +max_width = 80 +wrap_comments = true +format_code_in_doc_comments = true diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..7d4db80 --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,1924 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "aead" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + +[[package]] +name = "amplify" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cd7d8887f771c295502e7d5c5c7ee130b794f65af92f3176f22a762587b03d3" +dependencies = [ + "amplify_derive", + "serde", + "serde_json", + "serde_yaml", + "stringly_conversions", + "toml 0.5.8", +] + +[[package]] +name = "amplify_derive" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9edf4e78ede9a2e3ac65cc3a984135878d897cbd7055d6f36e4f2942cf7417" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "amplify_derive_helpers" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9076b2ac55f9451a0b7f36921d1c7d3a4c8822c3cbf6ecb5eece6fab90c7fc22" +dependencies = [ + "proc-macro2 1.0.24", + "syn 1.0.64", +] + +[[package]] +name = "arrayvec" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06f59fe10306bb78facd90d28c2038ad23ffaaefa85bac43c8a434cde383334f" +dependencies = [ + "nodrop", + "odds", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "base32" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" + +[[package]] +name = "base58" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" + +[[package]] +name = "base64" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +dependencies = [ + "byteorder", +] + +[[package]] +name = "base64-compat" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a8d4d2746f89841e49230dd26917df1876050f95abafafbe34f47cb534b88d7" +dependencies = [ + "byteorder", +] + +[[package]] +name = "bech32" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dabbe35f96fb9507f7330793dc490461b2962659ac5d427181e451a623751d1" + +[[package]] +name = "bech32" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c7f7096bc256f5e5cb960f60dfc4f4ef979ca65abe7fb9d5a4f77150d3783d4" + +[[package]] +name = "bitcoin" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec5f88a446d66e7474a3b8fa2e348320b574463fb78d799d90ba68f79f48e0e" +dependencies = [ + "bech32 0.7.3", + "bitcoin_hashes", + "secp256k1", + "serde", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aaf87b776808e26ae93289bc7d025092b6d909c193f0cdee0b3a86e7bd3c776" +dependencies = [ + "serde", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array 0.12.4", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0dcbc35f504eb6fc275a6d20e4ebcda18cf50d40ba6fabff8c711fa16cb3b16" + +[[package]] +name = "cc" +version = "1.0.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chacha20" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed8738f14471a99f0e316c327e68fc82a3611cc2895fcb604b89eedaf8f39d95" +dependencies = [ + "cipher", + "zeroize 1.2.0", +] + +[[package]] +name = "chacha20poly1305" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1fc18e6d90c40164bf6c317476f2a98f04661e310e79830366b7e914c58a8e" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize 1.2.0", +] + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "serde", + "time", + "winapi", +] + +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "clap" +version = "3.0.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd1061998a501ee7d4b6d449020df3266ca3124b941ec56cf2005c3779ca142" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "indexmap", + "lazy_static", + "os_str_bytes", + "strsim 0.10.0", + "termcolor", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.0.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "370f715b81112975b1b69db93e0b56ea4cd4e5002ac43b2da8474106a54096a1" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "client_side_validation" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69fbcc681ab39919398f924b998d939d818e732608c72d20da4c9e39b9769453" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin_hashes", + "grin_secp256k1zkp", + "strict_encoding", +] + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "cmake" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855" +dependencies = [ + "cc", +] + +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + +[[package]] +name = "cpuid-bool" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" + +[[package]] +name = "crypto-mac" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +dependencies = [ + "generic-array 0.12.4", + "subtle 1.0.0", +] + +[[package]] +name = "curve25519-dalek" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f627126b946c25a4638eec0ea634fc52506dea98db118aae985118ce7c3d723f" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle 2.4.0", + "zeroize 1.2.0", +] + +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2 1.0.24", + "quote 1.0.9", + "strsim 0.9.3", + "syn 1.0.64", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "deflate" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" +dependencies = [ + "adler32", + "byteorder", +] + +[[package]] +name = "derive_more" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe" +dependencies = [ + "lazy_static", + "proc-macro2 0.4.30", + "quote 0.6.13", + "regex", + "rustc_version", + "syn 0.15.44", +] + +[[package]] +name = "descriptor-wallet" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e854d5d4a2875669e6885c7a1ddc760aa5dbdb25f42e4b8ccbc1bd903157f6" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin", + "chrono", + "lazy_static", + "miniscript", + "regex", + "serde", + "serde_with", + "slip132", + "strict_encoding", +] + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array 0.12.4", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "dtoa" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" + +[[package]] +name = "ed25519" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37c66a534cbb46ab4ea03477eae19d5c22c01da8258030280b7bd9d8433fb6ef" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand 0.7.3", + "serde", + "sha2 0.9.3", + "zeroize 1.2.0", +] + +[[package]] +name = "error-chain" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +dependencies = [ + "matches", + "percent-encoding", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "generic-array" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +dependencies = [ + "typenum", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "grin_secp256k1zkp" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daca5852d12dbd4df8b7b760eaad791d191ea546bf80c46b033bbcc650b35a5c" +dependencies = [ + "arrayvec", + "cc", + "libc", + "rand 0.5.6", + "rustc-serialize", + "serde", + "serde_json", + "zeroize 0.9.3", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" + +[[package]] +name = "heck" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +dependencies = [ + "crypto-mac", + "digest 0.8.1", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "indexmap" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" +dependencies = [ + "autocfg 1.0.1", + "hashbrown", +] + +[[package]] +name = "inet2_addr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d17de954f78b83e7327701a1be5e67878691eaabf6b3d83c8f07db800759b0c" +dependencies = [ + "amplify", + "amplify_derive", + "ed25519-dalek", + "parse_arg", + "serde", + "serde_json", + "serde_yaml", + "strict_encoding", + "stringly_conversions", + "toml 0.5.8", + "torut", +] + +[[package]] +name = "inet2_derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c62ffe0c3f4e7c0e557a7e2833daf409555e547e977d6712f640835c83a14c" +dependencies = [ + "amplify", + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "inflate" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" +dependencies = [ + "adler32", +] + +[[package]] +name = "internet2" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a07ae295e404b850980559ea28bd42e3bd43cdfd59ea704ad12e056bf510f7" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin", + "chacha20poly1305", + "inet2_addr", + "inet2_derive", + "lazy_static", + "lightning_encoding", + "serde", + "serde_with", + "serde_with_macros", + "strict_encoding", + "url", + "zmq", +] + +[[package]] +name = "itoa" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" + +[[package]] +name = "keccak" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae" + +[[package]] +name = "lightning_encoding" +version = "0.4.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5afb64e0b91319373c7030726cce1144b8e425a05f6ccdd39295c4da8fdad60" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin", + "descriptor-wallet", + "lightning_encoding_derive", + "strict_encoding", +] + +[[package]] +name = "lightning_encoding_derive" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "483bbbb5309dec107fca8f16811e01184b2b10497c7d1933de446204742169de" +dependencies = [ + "amplify", + "amplify_derive_helpers", + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + +[[package]] +name = "lnp-core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c0d979dd4b7da78d2711d80f20fa8d68563109dbacb356f0d774153dad080c" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin", + "descriptor-wallet", + "internet2", + "lazy_static", + "lightning_encoding", + "lnpbp", + "serde", + "serde_with", + "strict_encoding", +] + +[[package]] +name = "lnpbp" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82895efc2bfbd69b26e60650a22839536ff0cfc2d2301cba76502ed51cf21f83" +dependencies = [ + "amplify", + "amplify_derive", + "bech32 0.7.3", + "bitcoin", + "bitcoin_hashes", + "client_side_validation", + "deflate", + "descriptor-wallet", + "inflate", + "lazy_static", + "lightning_encoding", + "miniscript", + "serde", + "serde_with", + "serde_with_macros", + "strict_encoding", + "strict_encoding_derive", +] + +[[package]] +name = "lnpbp-invoice" +version = "0.1.0" +dependencies = [ + "amplify", + "amplify_derive", + "base58", + "base64-compat", + "bech32 0.8.0", + "bitcoin", + "chrono", + "clap", + "descriptor-wallet", + "internet2", + "lightning_encoding", + "lnp-core", + "lnpbp", + "miniscript", + "openssl", + "rgb-core", + "serde", + "serde_json", + "serde_with", + "serde_yaml", + "strict_encoding", + "strict_encoding_derive", + "toml 0.5.8", + "url", +] + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" + +[[package]] +name = "memchr" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" + +[[package]] +name = "metadeps" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b122901b3a675fac8cecf68dcb2f0d3036193bc861d1ac0e1c337f7d5254c2" +dependencies = [ + "error-chain", + "pkg-config", + "toml 0.2.1", +] + +[[package]] +name = "miniscript" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71f455be59a359d50370c4f587afbc5739c862e684c5afecae80ab93e7474b4e" +dependencies = [ + "bitcoin", + "serde", +] + +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg 1.0.1", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg 1.0.1", +] + +[[package]] +name = "odds" +version = "0.2.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eae0151b9dacf24fcc170d9995e511669a082856a91f958a2fe380bfab3fb22" + +[[package]] +name = "once_cell" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl" +version = "0.10.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a61075b62a23fef5a29815de7536d940aa35ce96d18ce0cc5076272db678a577" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-sys", +] + +[[package]] +name = "openssl-src" +version = "111.14.0+1.1.1j" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "055b569b5bd7e5462a1700f595c7c7d487691d73b5ce064176af7f9f0cbb80a9" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "313752393519e876837e09e1fa183ddef0be7735868dced3196f4472d536277f" +dependencies = [ + "autocfg 1.0.1", + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "os_str_bytes" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb2e1c3ee07430c2cf76151675e583e0f19985fa6efae47d6848a3e2c824f85" + +[[package]] +name = "parse_arg" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14248cc8eced350e20122a291613de29e4fa129ba2731818c4cdbb44fccd3e55" + +[[package]] +name = "paste" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" + +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" + +[[package]] +name = "pin-project-lite" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" + +[[package]] +name = "pkg-config" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c" + +[[package]] +name = "poly1305" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b7456bc1ad2d4cf82b3a016be4c2ac48daf11bf990c1603ebd447fe6f30fca8" +dependencies = [ + "cpuid-bool 0.2.0", + "universal-hash", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid 0.2.1", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" +dependencies = [ + "proc-macro2 1.0.24", +] + +[[package]] +name = "rand" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "winapi", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc 0.2.0", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "regex" +version = "1.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548" + +[[package]] +name = "rgb-core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4abf30a6bd99279a794f8e9b2a71db895195726150071f35cdcaa9ae7e7503d2" +dependencies = [ + "amplify", + "amplify_derive", + "bech32 0.7.3", + "bitcoin", + "bitcoin_hashes", + "chrono", + "deflate", + "descriptor-wallet", + "ed25519-dalek", + "grin_secp256k1zkp", + "inflate", + "lazy_static", + "lightning_encoding", + "lnpbp", + "miniscript", + "num-derive", + "num-traits", + "regex", + "serde", + "serde_with", + "serde_with_macros", + "strict_encoding", +] + +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "secp256k1" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "733b114f058f260c0af7591434eef4272ae1a8ec2751766d3cb89c6df8d5e450" +dependencies = [ + "rand 0.6.5", + "secp256k1-sys", + "serde", +] + +[[package]] +name = "secp256k1-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e4b6455ee49f5901c8985b88f98fb0a0e1d90a6661f5a03f4888bd987dad29" +dependencies = [ + "cc", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.124" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.124" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "serde_json" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_str_helpers" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b744a7c94f2f3785496af33a0d93857dfc0c521e25c38e993e9c5bb45f09c841" +dependencies = [ + "serde", + "serde_derive", +] + +[[package]] +name = "serde_with" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bac272128fb3b1e98872dca27a05c18d8b78b9bd089d3edb7b5871501b50bce" +dependencies = [ + "hex", + "serde", + "serde_with_macros", +] + +[[package]] +name = "serde_with_macros" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c747a9ab2e833b807f74f6b6141530655010bfa9c9c06d5508bce75c8f8072f" +dependencies = [ + "darling", + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "serde_yaml" +version = "0.8.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23" +dependencies = [ + "dtoa", + "linked-hash-map", + "serde", + "yaml-rust", +] + +[[package]] +name = "sha1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" + +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer 0.7.3", + "digest 0.8.1", + "fake-simd", + "opaque-debug 0.2.3", +] + +[[package]] +name = "sha2" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpuid-bool 0.1.2", + "digest 0.9.0", + "opaque-debug 0.3.0", +] + +[[package]] +name = "sha3" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" +dependencies = [ + "block-buffer 0.7.3", + "byte-tools", + "digest 0.8.1", + "keccak", + "opaque-debug 0.2.3", +] + +[[package]] +name = "signature" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0242b8e50dd9accdd56170e94ca1ebd223b098eb9c83539a6e367d0f36ae68" + +[[package]] +name = "slip132" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "296e95fcf964943e0a16730184a929e9476615e31fb7fbcdc6476d99b2690cac" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin", +] + +[[package]] +name = "strict_encoding" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8552fff4110a8689be2beb58dc2d89e24880fa192de2d192eebde88549eada6f" +dependencies = [ + "amplify", + "amplify_derive", + "bitcoin", + "chrono", + "ed25519-dalek", + "grin_secp256k1zkp", + "miniscript", + "strict_encoding_derive", +] + +[[package]] +name = "strict_encoding_derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89347dfd57ea3160e6de4d7b21b3236b8a40800c1760ebfcfe9d69e3634e8955" +dependencies = [ + "amplify", + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", +] + +[[package]] +name = "stringly_conversions" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff63080f492dd4d289ffcaed8d7ece38adfb423db910eb342c0e04d409536a7a" +dependencies = [ + "paste", + "serde_str_helpers", +] + +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" + +[[package]] +name = "subtle" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd9d1e9976102a03c542daa2eff1b43f9d72306342f3f8b3ed5fb8908195d6f" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "unicode-xid 0.2.1", +] + +[[package]] +name = "synstructure" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", + "unicode-xid 0.1.0", +] + +[[package]] +name = "synstructure" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", + "unicode-xid 0.2.1", +] + +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "203008d98caf094106cfaba70acfed15e18ed3ddb7d94e49baec153a2b462789" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[package]] +name = "tinyvec" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46409491c9375a693ce7032101970a54f8a2010efb77e13f70788f0d84489e39" +dependencies = [ + "autocfg 1.0.1", + "bytes", + "memchr", + "pin-project-lite", +] + +[[package]] +name = "toml" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" + +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "torut" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0f9ee72e91955797223909df23bab7c857abf33806fd6b2cc66726b9b16bdb6" +dependencies = [ + "base32", + "base64", + "derive_more", + "ed25519-dalek", + "hex", + "hmac", + "openssl", + "rand 0.7.3", + "serde", + "serde_derive", + "sha1", + "sha2 0.8.2", + "sha3", + "tokio", +] + +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +dependencies = [ + "matches", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-segmentation" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "universal-hash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +dependencies = [ + "generic-array 0.14.4", + "subtle 2.4.0", +] + +[[package]] +name = "url" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +dependencies = [ + "form_urlencoded", + "idna", + "matches", + "percent-encoding", + "serde", +] + +[[package]] +name = "vcpkg" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00bca6106a5e23f3eee943593759b7fcddb00554332e856d990c893966879fb" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + +[[package]] +name = "zeroize" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" +dependencies = [ + "zeroize_derive 0.9.3", +] + +[[package]] +name = "zeroize" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a974bcdd357f0dca4d41677db03436324d45a4c9ed2d0b873a5a360ce41c36" +dependencies = [ + "zeroize_derive 1.0.1", +] + +[[package]] +name = "zeroize_derive" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080616bd0e31f36095288bb0acdf1f78ef02c2fa15527d7e993f2a6c7591643e" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", + "synstructure 0.10.2", +] + +[[package]] +name = "zeroize_derive" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3f369ddb18862aba61aa49bf31e74d29f0f162dec753063200e1dc084345d16" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.9", + "syn 1.0.64", + "synstructure 0.12.4", +] + +[[package]] +name = "zeromq-src" +version = "0.1.10+4.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9133d366817fcffe22e4356043ba187ae122ec5db63d7ce73d1e6a18efa2f1" +dependencies = [ + "cmake", +] + +[[package]] +name = "zmq" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aad98a7a617d608cd9e1127147f630d24af07c7cd95ba1533246d96cbdd76c66" +dependencies = [ + "bitflags", + "libc", + "log", + "zmq-sys", +] + +[[package]] +name = "zmq-sys" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d33a2c51dde24d5b451a2ed4b488266df221a5eaee2ee519933dc46b9a9b3648" +dependencies = [ + "libc", + "metadeps", + "zeromq-src", +] diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..116df6f --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,68 @@ +[package] +name = "lnpbp-invoice" +version = "0.1.0" +license = "MIT" +authors = ["Dr. Maxim Orlovsky "] +description = "LNP/BP universal invoices library implementing LNPBP-38 standard" +repository = "https://github.com/LNP-BP/rust-lnpbp" +homepage = "https://github.com/LNP-BP" +keywords = ["bitcoin", "lightning", "lnp-bp", "rgb", "invoice"] +categories = ["cryptography::cryptocurrencies"] +readme = "README.md" +edition = "2018" + +[[bin]] +name = "invoice" +path = "src/main.rs" +required-features = ["cli"] + +[lib] +name = "invoice" +path = "src/lib.rs" +crate-type = ["rlib", "staticlib"] + +[dependencies] +# Dependencies on other LNP/BP repositories +# ----------------------------------------- +amplify = { version = "3", features = ["stringly_conversions", "std"] } +amplify_derive = "2.4.3" +strict_encoding = { version = "1.0.6", features = ["miniscript"] } +strict_encoding_derive = { version = "1" } +lightning_encoding = "0.4.0-beta.1" +descriptor-wallet = { version = "0.4", features = ["keygen"] } +internet2 = "0.3.10" +lnpbp = "0.4" +lnp-core = "0.3.1" +rgb-core = { version = "0.4", optional = true } +# Dependencies on core rust-bitcoin ecosystem projects +# ---------------------------------------------------- +bitcoin = { version = "0.26", features = ["rand"] } +miniscript = { version = "5", features = ["compiler"] } +# Serialization +# ------------- +base64-compat = { version = "1", optional = true } # Used by cli only +base58 = { version = "0.1", optional = true } # Used by cli only +bech32 = { version = "0", optional = true } # Used by cli only +serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true } +serde_with = { version = "1.5", features = ["hex"], optional = true } +serde_json = { version = "1", optional = true } # Used by cli only +serde_yaml = { version = "0.8", optional = true } # Used by cli only +toml = { version = "0.5", optional = true } # Used by cli only +clap = { version = "3.0.0-beta.2", optional = true } # Used by cli only +# Internal data representations +# ----------------------------- +url = "2.2" +chrono = "0.4.19" + +[target.'cfg(target_os="windows")'.dependencies] +openssl = { version = "0.10", features = ["vendored"] } + +[features] +default = [] +all = ["serde", "rgb"] +cli = ["clap", "base64-compat", "base58", "bech32", "serde", "serde_yaml", "serde_json", "toml"] +serde = ["serde_crate", "serde_with", "amplify/serde", "descriptor-wallet/serde", + "lnp-core/serde", "internet2/serde", "lnp-core/serde", + "bitcoin/use-serde", "miniscript/serde", + "chrono/serde", "url/serde"] +rgb = ["rgb-core"] diff --git a/rust/src/base.rs b/rust/src/base.rs new file mode 100644 index 0000000..8fad57e --- /dev/null +++ b/rust/src/base.rs @@ -0,0 +1,908 @@ +// LNP/BP universal invoice library implementing LNPBP-38 standard +// Written in 2021 by +// Dr. Maxim Orlovsky +// +// To the extent possible under law, the author(s) have dedicated all +// copyright and related and neighboring rights to this software to +// the public domain worldwide. This software is distributed without +// any warranty. +// +// You should have received a copy of the MIT License +// along with this software. +// If not, see . + +use chrono::NaiveDateTime; +#[cfg(feature = "serde")] +use serde_with::{As, DisplayFromStr}; +use std::cmp::Ordering; +use std::fmt::{self, Display, Formatter, Write}; +use std::io; +use std::str::FromStr; + +#[cfg(feature = "rgb")] +use amplify::Wrapper; +#[cfg(feature = "rgb")] +use bitcoin::hashes::sha256t; +use bitcoin::hashes::{sha256d, Hash}; +use bitcoin::secp256k1::{self, PublicKey, Signature}; +use bitcoin::Address; +use internet2::tlv; +use lnp::features::InitFeatures; +use lnp::payment::ShortChannelId; +use lnpbp::bech32::{self, Blob, FromBech32Str, ToBech32String}; +use lnpbp::chain::{AssetId, Chain}; +use lnpbp::client_side_validation::MerkleNode; +use lnpbp::seals::OutpointHash; +use miniscript::{descriptor::DescriptorPublicKey, Descriptor}; +use strict_encoding::{StrictDecode, StrictEncode}; +use wallet::{HashLock, Psbt}; + +// TODO: Derive `Eq` & `Hash` once Psbt will support them +/// NB: Invoice fields are non-public since each time we update them we must +/// clear signature +#[cfg_attr( + feature = "serde", + serde_as, + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] +#[derive( + Getters, + Clone, + PartialEq, + Debug, + Display, + StrictEncode, + StrictDecode, + LightningEncode, + LightningDecode, +)] +#[display(Invoice::to_bech32_string)] +pub struct Invoice { + /// Version byte, always 0 for the initial version + version: u8, + + /// Amount in the specified asset - a price per single item, if `quantity` + /// options is set + #[cfg_attr(feature = "serde", serde(with = "As::"))] + amount: AmountExt, + + /// Main beneficiary. Separating the first beneficiary into a standalone + /// field allows to ensure that there is always at lease one beneficiary + /// at compile time + beneficiary: Beneficiary, + + /// List of beneficiary ordered in most desirable-first order, which follow + /// `beneficiary` value + #[tlv(type = 1)] + alt_beneficiaries: Vec, + + /// AssetId can also be used to define blockchain. If it's empty it implies + /// bitcoin mainnet + #[tlv(type = 2)] + #[cfg_attr( + feature = "serde", + serde(with = "As::>") + )] + asset: Option, + + /// Interval between recurrent payments + #[tlv(type = 3)] + recurrent: Recurrent, + + #[tlv(type = 4)] + #[cfg_attr( + feature = "serde", + serde(with = "As::>") + )] + expiry: Option, // Must be mapped to i64 + + #[tlv(type = 5)] + quantity: Option, + + /// If the price of the asset provided by fiat provider URL goes below this + /// limit the merchant will not accept the payment and it will become + /// expired + #[tlv(type = 6)] + currency_requirement: Option, + + #[tlv(type = 7)] + merchant: Option, + + #[tlv(type = 8)] + purpose: Option, + + #[tlv(type = 9)] + details: Option
, + + #[tlv(type = 0)] + #[cfg_attr( + feature = "serde", + serde(with = "As::>") + )] + signature: Option<(PublicKey, Signature)>, + + #[tlv(unknown)] + #[cfg_attr(feature = "serde", serde(skip))] + unknown: tlv::Map, + /* TODO: Add RGB feature vec optional field + * TODO: Add Bifrost server list as a TLV vec (empty if not provided) */ +} + +impl bech32::Strategy for Invoice { + const HRP: &'static str = "i"; + + type Strategy = bech32::strategies::CompressedStrictEncoding; +} + +impl FromStr for Invoice { + type Err = bech32::Error; + + fn from_str(s: &str) -> Result { + Invoice::from_bech32_str(s) + } +} + +impl Ord for Invoice { + fn cmp(&self, other: &Self) -> Ordering { + self.to_string().cmp(&other.to_string()) + } +} + +impl PartialOrd for Invoice { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl std::hash::Hash for Invoice { + fn hash(&self, state: &mut H) { + self.to_string().hash(state) + } +} + +impl Eq for Invoice {} + +impl Invoice { + pub fn new( + beneficiary: Beneficiary, + amount: Option, + asset: Option, + ) -> Invoice { + Invoice { + version: 0, + amount: amount + .map(|value| AmountExt::Normal(value)) + .unwrap_or(AmountExt::Any), + beneficiary, + alt_beneficiaries: vec![], + asset, + recurrent: Default::default(), + expiry: None, + quantity: None, + currency_requirement: None, + merchant: None, + purpose: None, + details: None, + signature: None, + unknown: Default::default(), + } + } + + pub fn with_descriptor( + descr: Descriptor, + amount: Option, + chain: &Chain, + ) -> Invoice { + Invoice::new( + Beneficiary::Descriptor(descr), + amount, + if chain == &Chain::Mainnet { + None + } else { + Some(chain.native_asset()) + }, + ) + } + + pub fn with_address(address: Address, amount: Option) -> Invoice { + let asset = if address.network != bitcoin::Network::Bitcoin { + Some(AssetId::native(&address.network.into())) + } else { + None + }; + Invoice::new(Beneficiary::Address(address), amount, asset) + } + + #[cfg(feature = "rgb")] + pub fn is_rgb(&self) -> bool { + self.rgb_asset().is_none() + } + + #[cfg(feature = "rgb")] + pub fn rgb_asset(&self) -> Option { + self.asset.and_then(|asset_id| { + if *&[ + Chain::Mainnet, + Chain::Signet, + Chain::LiquidV1, + Chain::Testnet3, + ] + .iter() + .map(Chain::native_asset) + .all(|id| id != asset_id) + { + Some(rgb::ContractId::from_inner(sha256t::Hash::from_inner( + asset_id.into_inner(), + ))) + } else { + None + } + }) + } + + pub fn classify_asset(&self, chain: Option) -> AssetClass { + match (self.asset, chain) { + (None, Some(Chain::Mainnet)) => AssetClass::Native, + (None, _) => AssetClass::InvalidNativeChain, + (Some(asset_id), Some(chain)) + if asset_id == chain.native_asset() => + { + AssetClass::Native + } + (Some(asset_id), _) + if *&[ + Chain::Mainnet, + Chain::Signet, + Chain::LiquidV1, + Chain::Testnet3, + ] + .iter() + .map(Chain::native_asset) + .find(|id| id == &asset_id) + .is_some() => + { + AssetClass::InvalidNativeChain + } + #[cfg(feature = "rgb")] + (Some(asset_id), _) => { + AssetClass::Rgb(rgb::ContractId::from_inner( + sha256t::Hash::from_inner(asset_id.into_inner()), + )) + } + #[cfg(not(feature = "rgb"))] + (Some(asset_id), _) => AssetClass::Other(asset_id), + } + } + + pub fn beneficiaries(&self) -> BeneficiariesIter { + BeneficiariesIter { + invoice: self, + index: 0, + } + } + + pub fn set_amount(&mut self, amount: AmountExt) -> bool { + if self.amount == amount { + return false; + } + self.amount = amount; + self.signature = None; + return true; + } + + pub fn set_recurrent(&mut self, recurrent: Recurrent) -> bool { + if self.recurrent == recurrent { + return false; + } + self.recurrent = recurrent; + self.signature = None; + return true; + } + + pub fn set_expiry(&mut self, expiry: NaiveDateTime) -> bool { + if self.expiry == Some(expiry) { + return false; + } + self.expiry = Some(expiry); + self.signature = None; + return true; + } + + pub fn set_no_expiry(&mut self) -> bool { + if self.expiry == None { + return false; + } + self.expiry = None; + self.signature = None; + return true; + } + + pub fn set_quantity(&mut self, quantity: Quantity) -> bool { + if self.quantity == Some(quantity) { + return false; + } + self.quantity = Some(quantity); + self.signature = None; + return true; + } + + pub fn remove_quantity(&mut self) -> bool { + if self.quantity == None { + return false; + } + self.quantity = None; + self.signature = None; + return true; + } + + pub fn set_currency_requirement( + &mut self, + currency_data: CurrencyData, + ) -> bool { + let currency_data = Some(currency_data); + if self.currency_requirement == currency_data { + return false; + } + self.currency_requirement = currency_data; + self.signature = None; + return true; + } + + pub fn remove_currency_requirement(&mut self) -> bool { + if self.currency_requirement == None { + return false; + } + self.currency_requirement = None; + self.signature = None; + return true; + } + + pub fn set_merchant(&mut self, merchant: String) -> bool { + let merchant = if merchant.is_empty() { + None + } else { + Some(merchant) + }; + if self.merchant == merchant { + return false; + } + self.merchant = merchant; + self.signature = None; + return true; + } + + pub fn remove_merchant(&mut self) -> bool { + if self.merchant == None { + return false; + } + self.merchant = None; + self.signature = None; + return true; + } + + pub fn set_purpose(&mut self, purpose: String) -> bool { + let purpose = if purpose.is_empty() { + None + } else { + Some(purpose) + }; + if self.purpose == purpose { + return false; + } + self.purpose = purpose; + self.signature = None; + return true; + } + + pub fn remove_purpose(&mut self) -> bool { + if self.purpose == None { + return false; + } + self.purpose = None; + self.signature = None; + return true; + } + + pub fn set_details(&mut self, details: Details) -> bool { + let details = Some(details); + if self.details == details { + return false; + } + self.details = details; + self.signature = None; + return true; + } + + pub fn remove_details(&mut self) -> bool { + if self.details == None { + return false; + } + self.details = None; + self.signature = None; + return true; + } + + pub fn signature_hash(&self) -> MerkleNode { + // TODO: Change signature encoding algorithm to a merkle-tree based + MerkleNode::hash( + &self.strict_serialize().expect( + "invoice data are inconsistent for strict serialization", + ), + ) + } + + pub fn set_signature(&mut self, pubkey: PublicKey, signature: Signature) { + self.signature = Some((pubkey, signature)) + } + + pub fn remove_signature(&mut self) { + self.signature = None + } +} + +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] +pub enum AssetClass { + Native, + #[cfg(feature = "rgb")] + Rgb(rgb::ContractId), + #[cfg(not(feature = "rgb"))] + Other(AssetId), + InvalidNativeChain, +} + +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct BeneficiariesIter<'a> { + invoice: &'a Invoice, + index: usize, +} + +impl<'a> Iterator for BeneficiariesIter<'a> { + type Item = &'a Beneficiary; + + fn next(&mut self) -> Option { + self.index += 1; + if self.index == 1 { + Some(&self.invoice.beneficiary) + } else { + self.invoice.alt_beneficiaries.get(self.index - 2) + } + } +} + +#[derive( + Clone, + Copy, + PartialEq, + Eq, + PartialOrd, + Ord, + Debug, + Display, + From, + StrictEncode, + StrictDecode, +)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename_all = "camelCase") +)] +#[non_exhaustive] +pub enum Recurrent { + #[display("non-recurrent")] + NonRecurrent, + + #[display("each {0} seconds")] + Seconds(u64), + + #[display("each {0} months")] + Months(u8), + + #[display("each {0} years")] + Years(u8), +} + +impl lightning_encoding::Strategy for Recurrent { + type Strategy = lightning_encoding::strategies::AsStrict; +} + +impl Default for Recurrent { + fn default() -> Self { + Recurrent::NonRecurrent + } +} + +// TODO: Derive `Eq` & `Hash` once Psbt will support them +#[cfg_attr( + feature = "serde", + serde_as, + derive(Serialize, Deserialize), + serde(crate = "serde_crate", rename = "lowercase", untagged) +)] +#[derive( + Clone, PartialEq, Debug, Display, From, StrictEncode, StrictDecode, +)] +#[display(inner)] +#[non_exhaustive] +pub enum Beneficiary { + /// Addresses are useful when you do not like to leak public key + /// information + #[from] + Address( + #[cfg_attr(feature = "serde", serde(with = "As::"))] + Address, + ), + + /// Used by protocols that work with existing UTXOs and can assign some + /// client-validated data to them (like in RGB). We always hide the real + /// UTXO behind the hashed version (using some salt) + #[from] + BlindUtxo( + #[cfg_attr(feature = "serde", serde(with = "As::"))] + OutpointHash, + ), + + /// Miniscript-based descriptors allowing custom derivation & key + /// generation + #[from] + Descriptor( + #[cfg_attr(feature = "serde", serde(with = "As::"))] + Descriptor, + ), + + /// Full transaction template in PSBT format + #[from] + // TODO: Fix display once PSBT implement `Display` + #[display("PSBT!")] + Psbt(Psbt), + + /// Lightning node receiving the payment. Not the same as lightning invoice + /// since many of the invoice data now will be part of [`Invoice`] here. + #[from] + Lightning(LnAddress), + + /// Fallback option for all future variants + Unknown( + #[cfg_attr(feature = "serde", serde(with = "As::"))] + Blob, + ), +} + +impl lightning_encoding::Strategy for Beneficiary { + type Strategy = lightning_encoding::strategies::AsStrict; +} + +#[derive( + Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display, Error, +)] +#[display(doc_comments)] +/// Incorrect beneficiary format +pub struct BeneficiaryParseError; + +// TODO: Since we can't present full beneficiary data in a string form (because +// of the lightning part) we have to remove this implementation once +// serde_with will be working +impl FromStr for Beneficiary { + type Err = BeneficiaryParseError; + + fn from_str(s: &str) -> Result { + if let Ok(address) = Address::from_str(s) { + Ok(Beneficiary::Address(address)) + } else if let Ok(outpoint) = OutpointHash::from_str(s) { + Ok(Beneficiary::BlindUtxo(outpoint)) + } else if let Ok(descriptor) = + Descriptor::::from_str(s) + { + Ok(Beneficiary::Descriptor(descriptor)) + } else { + Err(BeneficiaryParseError) + } + } +} + +#[cfg_attr( + feature = "serde", + serde_as, + derive(Serialize, Deserialize), + serde(crate = "serde_crate") +)] +#[derive( + Clone, + Ord, + PartialOrd, + Eq, + PartialEq, + Hash, + Debug, + Display, + StrictEncode, + StrictDecode, + LightningEncode, + LightningDecode, +)] +#[display("{node_id}")] +pub struct LnAddress { + #[cfg_attr(feature = "serde", serde(with = "As::"))] + pub node_id: secp256k1::PublicKey, + pub features: InitFeatures, + #[cfg_attr(feature = "serde", serde(with = "As::"))] + pub lock: HashLock, /* When PTLC will be available the same field will + * be re-used for them + the + * use will be indicated with a + * feature flag */ + pub min_final_cltv_expiry: Option, + pub path_hints: Vec, +} + +/// Path hints for a lightning network payment, equal to the value of the `r` +/// key of the lightning BOLT-11 invoice +/// +#[cfg_attr( + feature = "serde", + serde_as, + derive(Serialize, Deserialize), + serde(crate = "serde_crate") +)] +#[derive( + Copy, + Clone, + Ord, + PartialOrd, + Eq, + PartialEq, + Hash, + Debug, + Display, + StrictEncode, + StrictDecode, + LightningEncode, + LightningDecode, +)] +#[display("{short_channel_id}@{node_id}")] +pub struct LnPathHint { + #[cfg_attr(feature = "serde", serde(with = "As::"))] + pub node_id: secp256k1::PublicKey, + #[cfg_attr(feature = "serde", serde(with = "As::"))] + pub short_channel_id: ShortChannelId, + pub fee_base_msat: u32, + pub fee_proportional_millionths: u32, + pub cltv_expiry_delta: u16, +} + +#[derive( + Copy, + Clone, + Ord, + PartialOrd, + Eq, + PartialEq, + Hash, + Debug, + Display, + From, + StrictEncode, + StrictDecode, +)] +pub enum AmountExt { + /// Payments for any amount is accepted: useful for charity/donations, etc + #[display("any")] + Any, + + #[from] + #[display(inner)] + Normal(u64), + + #[display("{0}.{1}")] + Milli(u64, u16), +} + +impl Default for AmountExt { + fn default() -> Self { + AmountExt::Any + } +} + +impl lightning_encoding::Strategy for AmountExt { + type Strategy = lightning_encoding::strategies::AsStrict; +} + +impl AmountExt { + pub fn atomic_value(&self) -> Option { + match self { + AmountExt::Any => None, + AmountExt::Normal(val) => Some(*val), + AmountExt::Milli(_, _) => None, + } + } +} + +#[derive( + Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug, Display, Error, From, +)] +#[display(doc_comments)] +#[from(std::num::ParseIntError)] +/// Incorrect beneficiary format +pub struct AmountParseError; + +impl FromStr for AmountExt { + type Err = AmountParseError; + + fn from_str(s: &str) -> Result { + if s.trim().to_lowercase() == "any" { + return Ok(AmountExt::Any); + } + let mut split = s.split("."); + Ok(match (split.next(), split.next()) { + (Some(amt), None) => AmountExt::Normal(amt.parse()?), + (Some(int), Some(frac)) => { + AmountExt::Milli(int.parse()?, frac.parse()?) + } + _ => Err(AmountParseError)?, + }) + } +} + +#[derive( + Clone, + Ord, + PartialOrd, + Eq, + PartialEq, + Hash, + Debug, + Display, + StrictEncode, + StrictDecode, + LightningEncode, + LightningDecode, +)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate") +)] +#[display("{source}#commitment")] +pub struct Details { + #[cfg_attr(feature = "serde", serde(with = "As::"))] + pub commitment: sha256d::Hash, + pub source: String, // Url +} + +#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, From)] +// TODO: Move to amplify library +pub struct Iso4217([u8; 3]); + +impl Display for Iso4217 { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_char(self.0[0].into())?; + f.write_char(self.0[1].into())?; + f.write_char(self.0[2].into()) + } +} + +#[derive( + Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Error, +)] +#[display(doc_comments)] +pub enum Iso4217Error { + /// Wrong string length to parse ISO4217 data + WrongLen, +} + +impl FromStr for Iso4217 { + type Err = Iso4217Error; + + fn from_str(s: &str) -> Result { + if s.bytes().len() != 3 { + return Err(Iso4217Error::WrongLen); + } + + let mut inner = [0u8; 3]; + inner.copy_from_slice(&s.bytes().collect::>()[0..3]); + Ok(Iso4217(inner)) + } +} + +impl StrictEncode for Iso4217 { + fn strict_encode( + &self, + mut e: E, + ) -> Result { + e.write(&self.0)?; + Ok(3) + } +} + +impl StrictDecode for Iso4217 { + fn strict_decode( + mut d: D, + ) -> Result { + let mut me = Self([0u8; 3]); + d.read_exact(&mut me.0)?; + Ok(me) + } +} + +impl lightning_encoding::Strategy for Iso4217 { + type Strategy = lightning_encoding::strategies::AsStrict; +} + +#[cfg_attr( + feature = "serde", + serde_as, + derive(Serialize, Deserialize), + serde(crate = "serde_crate") +)] +#[derive( + Clone, + Ord, + PartialOrd, + Eq, + PartialEq, + Hash, + Debug, + Display, + StrictEncode, + StrictDecode, + LightningEncode, + LightningDecode, +)] +#[display("{coins}.{fractions} {iso4217}")] +pub struct CurrencyData { + #[cfg_attr(feature = "serde", serde(with = "As::"))] + pub iso4217: Iso4217, + pub coins: u32, + pub fractions: u8, + pub price_provider: String, // Url, +} + +#[derive( + Copy, + Clone, + Ord, + PartialOrd, + Eq, + PartialEq, + Hash, + Debug, + From, + StrictEncode, + StrictDecode, + LightningEncode, + LightningDecode, +)] +#[cfg_attr( + feature = "serde", + derive(Serialize, Deserialize), + serde(crate = "serde_crate") +)] +pub struct Quantity { + pub min: u32, // We will default to zero + pub max: Option, + #[from] + pub default: u32, +} + +impl Default for Quantity { + fn default() -> Self { + Self { + min: 0, + max: None, + default: 1, + } + } +} + +impl Display for Quantity { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!(f, "{} items", self.default)?; + match (self.min, self.max) { + (0, Some(max)) => write!(f, " (or any amount up to {})", max), + (0, None) => Ok(()), + (_, Some(max)) => write!(f, " (or from {} to {})", self.min, max), + (_, None) => write!(f, " (or any amount above {})", self.min), + } + } +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs new file mode 100644 index 0000000..27411b7 --- /dev/null +++ b/rust/src/lib.rs @@ -0,0 +1,40 @@ +// LNP/BP universal invoice library implementing LNPBP-38 standard +// Written in 2021 by +// Dr. Maxim Orlovsky +// +// To the extent possible under law, the author(s) have dedicated all +// copyright and related and neighboring rights to this software to +// the public domain worldwide. This software is distributed without +// any warranty. +// +// You should have received a copy of the MIT License +// along with this software. +// If not, see . + +#![recursion_limit = "256"] +// Coding conventions +#![deny( + non_upper_case_globals, + non_camel_case_types, + non_snake_case, + unused_mut, + unused_imports, + // dead_code, + //missing_docs +)] +// TODO: when we will be ready for the release #![deny(missing_docs)] + +#[macro_use] +extern crate amplify_derive; +#[macro_use] +extern crate lightning_encoding; + +#[cfg(feature = "serde")] +#[macro_use] +extern crate serde_with; +#[cfg(feature = "serde")] +extern crate serde_crate as serde; + +mod base; + +pub use base::*; diff --git a/rust/src/main.rs b/rust/src/main.rs new file mode 100644 index 0000000..f6462b5 --- /dev/null +++ b/rust/src/main.rs @@ -0,0 +1,250 @@ +// LNP/BP universal invoice library implementing LNPBP-38 standard +// Written in 2021 by +// Dr. Maxim Orlovsky +// +// To the extent possible under law, the author(s) have dedicated all +// copyright and related and neighboring rights to this software to +// the public domain worldwide. This software is distributed without +// any warranty. +// +// You should have received a copy of the MIT License +// along with this software. +// If not, see . + +extern crate serde_crate as serde; + +use clap::{AppSettings, Clap}; +use serde::Serialize; +use std::fmt::{self, Debug, Display, Formatter}; +use std::io::{self, Read}; +use std::str::FromStr; + +use base58::{FromBase58, ToBase58}; +use bitcoin::hashes::hex::{self, FromHex, ToHex}; +use invoice::Invoice; +use strict_encoding::{StrictDecode, StrictEncode}; + +#[derive(Clap, Clone, Debug)] +#[clap( + name = "invoice", + bin_name = "invoice", + author, + version, + about = "Command-line tool for working with LNP/BP invoicing", + setting = AppSettings::ColoredHelp, +)] +pub struct Opts { + /// Command to execute + #[clap(subcommand)] + pub command: Command, +} + +#[derive(Clap, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[clap(setting = AppSettings::ColoredHelp)] +pub enum Command { + /// Converting between different representations of invoice data + Convert { + /// Invoice data; if none are given reads from STDIN + invoice: Option, + + /// Formatting of the input invoice data + #[clap(short, long, default_value = "bech32")] + input: Format, + + /// Formatting for the output invoice data + #[clap(short, long, default_value = "yaml")] + output: Format, + }, + + RgbConvert { + /// Asset id in any format + asset: Option, + + /// Formatting of the input invoice data + #[clap(short, long, default_value = "hex")] + input: Format, + + /// Formatting for the output invoice data + #[clap(short, long, default_value = "bech32")] + output: Format, + }, +} + +/// Formatting of the data +#[derive(Clap, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)] +pub enum Format { + /// Format according to the rust debug rules + Debug, + + /// Format using Bech32 representation + Bech32, + + /// Format using Base58 encoding + Base58, + + /// Format using Base64 encoding + Base64, + + /// Format as YAML + Yaml, + + /// Format as JSON + Json, + + /// Format according to the strict encoding rules + Hexadecimal, + + /// Format as a rust array (using hexadecimal byte values) + Rust, + + /// Produce binary (raw) output according to LNPBP-39 serialization rules + Raw, +} + +impl Display for Format { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Format::Debug => f.write_str("debug"), + Format::Base58 => f.write_str("base58"), + Format::Base64 => f.write_str("base64"), + Format::Bech32 => f.write_str("bech32"), + Format::Yaml => f.write_str("yaml"), + Format::Json => f.write_str("json"), + Format::Hexadecimal => f.write_str("hex"), + Format::Rust => f.write_str("rust"), + Format::Raw => f.write_str("raw"), + } + } +} + +impl FromStr for Format { + type Err = String; + + fn from_str(s: &str) -> Result { + Ok(match s.trim().to_lowercase().as_str() { + "debug" => Format::Debug, + "base58" => Format::Base58, + "base64" => Format::Base64, + "bech32" => Format::Bech32, + "yaml" => Format::Yaml, + "json" => Format::Json, + "hex" => Format::Hexadecimal, + "raw" | "bin" => Format::Raw, + "rust" => Format::Rust, + other => Err(format!("Unknown format: {}", other))?, + }) + } +} + +fn input_read(data: Option, format: Format) -> Result +where + T: FromStr + StrictDecode + for<'de> serde::Deserialize<'de>, + ::Err: Display, +{ + let data = data + .map(|d| d.as_bytes().to_vec()) + .ok_or(String::default()) + .or_else(|_| -> Result, String> { + let mut buf = Vec::new(); + io::stdin() + .read_to_end(&mut buf) + .as_ref() + .map_err(io::Error::to_string)?; + Ok(buf) + })?; + let s = &String::from_utf8_lossy(&data); + Ok(match format { + Format::Bech32 => T::from_str(s).map_err(|err| err.to_string())?, + Format::Base58 => { + T::strict_deserialize(s.from_base58().map_err(|err| { + format!("Incorrect Base58 encoding: {:?}", err) + })?) + .map_err(|err| format!("Wrong invoice data: {}", err))? + } + Format::Base64 => T::strict_deserialize( + &base64::decode(&data) + .map_err(|err| format!("Incorrect Base64 encoding: {}", err))?, + ) + .map_err(|err| format!("Wrong invoice data: {}", err))?, + Format::Yaml => { + serde_yaml::from_str(s).map_err(|err| err.to_string())? + } + Format::Json => { + serde_json::from_str(s).map_err(|err| err.to_string())? + } + Format::Hexadecimal => T::strict_deserialize( + Vec::::from_hex(s) + .as_ref() + .map_err(hex::Error::to_string)?, + ) + .map_err(|err| format!("Wrong invoice data: {}", err))?, + Format::Raw => T::strict_deserialize(&data) + .map_err(|err| format!("Wrong invoice data: {}", err))?, + _ => Err(format!("Can't read data from {} format", format))?, + }) +} + +fn output_write( + mut f: impl io::Write, + data: T, + format: Format, +) -> Result<(), String> +where + T: Debug + Display + Serialize + StrictEncode, +{ + let strict = data.strict_serialize().map_err(|err| err.to_string())?; + match format { + Format::Debug => write!(f, "{:#?}", data), + Format::Bech32 => write!(f, "{}", data), + Format::Base58 => write!(f, "{}", strict.to_base58()), + Format::Base64 => write!(f, "{}", base64::encode(&strict)), + Format::Yaml => write!( + f, + "{}", + serde_yaml::to_string(&data) + .as_ref() + .map_err(serde_yaml::Error::to_string)? + ), + Format::Json => write!( + f, + "{}", + serde_json::to_string(&data) + .as_ref() + .map_err(serde_json::Error::to_string)? + ), + Format::Hexadecimal => write!(f, "{}", strict.to_hex()), + Format::Rust => write!(f, "{:#04X?}", strict), + Format::Raw => data + .strict_encode(f) + .map(|_| ()) + .map_err(|_| io::Error::from_raw_os_error(0)), + } + .as_ref() + .map_err(io::Error::to_string)?; + Ok(()) +} + +fn main() -> Result<(), String> { + let opts = Opts::parse(); + + match opts.command { + Command::Convert { + invoice, + input, + output, + } => { + let invoice: Invoice = input_read(invoice, input)?; + output_write(io::stdout(), invoice, output)?; + } + Command::RgbConvert { + asset, + input, + output, + } => { + let asset: rgb::ContractId = input_read(asset, input)?; + output_write(io::stdout(), asset, output)?; + } + } + + Ok(()) +}