diff --git a/Cargo.lock b/Cargo.lock index 62b9f151..41a6f048 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "addr2line" -version = "0.20.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" dependencies = [ "gimli", ] @@ -23,6 +23,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + [[package]] name = "ahash" version = "0.7.6" @@ -48,9 +58,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6748e8def348ed4d14996fa801f4122cd763fff530258cdc03f64b25f89d3a5a" +checksum = "0c378d78423fdad8089616f827526ee33c19f2fddbd5de1629152c9593ba4783" dependencies = [ "memchr", ] @@ -93,24 +103,23 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" [[package]] name = "anstyle-parse" @@ -132,9 +141,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" dependencies = [ "anstyle", "windows-sys", @@ -191,9 +200,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "backtrace" -version = "0.3.68" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" dependencies = [ "addr2line", "cc", @@ -212,9 +221,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.2" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" [[package]] name = "base64ct" @@ -432,9 +441,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.82" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305fe645edc1442a0fa8b6726ba61d422798d37a52e12eaecf4b022ebbb88f01" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" dependencies = [ "libc", ] @@ -454,16 +463,40 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" -version = "0.4.26" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5" +checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f" dependencies = [ "android-tzdata", "iana-time-zone", "num-traits", - "winapi", + "windows-targets", ] [[package]] @@ -472,6 +505,17 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cca491388666e04d7248af3f60f0c40cfb0991c72205595d7c396e3510207d1a" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", + "zeroize", +] + [[package]] name = "clang-sys" version = "1.6.1" @@ -485,18 +529,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.22" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b417ae4361bca3f5de378294fc7472d3c4ed86a5ef9f49e93ae722f432aae8d2" +checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.3.22" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c90dc0f0e42c64bff177ca9d7be6fcc9ddb0f26a6e062174a61c84dd6c644d4" +checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" dependencies = [ "anstream", "anstyle", @@ -506,9 +550,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "cmake" @@ -651,6 +695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ "generic-array", + "rand_core", "typenum", ] @@ -677,9 +722,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" +checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" [[package]] name = "digest" @@ -716,9 +761,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.32" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ "cfg-if", ] @@ -744,9 +789,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", @@ -945,9 +990,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.27.3" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" [[package]] name = "glob" @@ -966,9 +1011,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.20" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -1004,9 +1049,9 @@ dependencies = [ [[package]] name = "hashlink" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "312f66718a2d7789ffef4f4b7b213138ed9f1eb3aa1d0d82fc99f88fb3ffd26f" +checksum = "e8094feaf31ff591f651a2664fb9cfd92bba7a60ce3197265e9482ebe753c8f7" dependencies = [ "hashbrown 0.14.0", ] @@ -1205,21 +1250,19 @@ dependencies = [ ] [[package]] -name = "ipnet" -version = "2.8.0" +name = "inout" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] [[package]] -name = "is-terminal" -version = "0.4.9" +name = "ipnet" +version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi 0.3.2", - "rustix", - "windows-sys", -] +checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" [[package]] name = "itertools" @@ -1395,9 +1438,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "5486aed0026218e61b8a01d5fbd5a0a134649abb71a0e53b7bc088529dced86e" [[package]] name = "mime" @@ -1438,7 +1481,7 @@ checksum = "3de406eeb24aba36ed3829532fa01649129677186b44a49debec0ec574ca7da7" dependencies = [ "log", "once_cell", - "rustls 0.20.8", + "rustls 0.20.9", "webpki", "webpki-roots", ] @@ -1579,9 +1622,9 @@ dependencies = [ [[package]] name = "object" -version = "0.31.1" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +checksum = "77ac5bbd07aea88c60a577a1ce218075ffd59208b2d7ca97adf9bfc5aeb21ebe" dependencies = [ "memchr", ] @@ -1598,13 +1641,19 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[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.56" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "729b745ad4a5575dd06a3e1af1414bd330ee561c01b3899eb584baeaa8def17e" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", "foreign-types", "libc", @@ -1641,9 +1690,9 @@ dependencies = [ [[package]] name = "openssl-sys" -version = "0.9.91" +version = "0.9.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "866b5f16f90776b9bb8dc1e1802ac6f0513de3a7a7465867bfbc563dc737faac" +checksum = "db7e971c2c2bba161b2d2fdf37080177eff520b3bc044787c7f1f5f9e78d869b" dependencies = [ "cc", "libc", @@ -1710,6 +1759,7 @@ dependencies = [ "bip21", "bitcoin", "bitcoind", + "chacha20poly1305", "env_logger", "log", "rand", @@ -1764,7 +1814,7 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b13fe415cdf3c8e44518e18a7c95a13431d9bdf6d15367d82b23c377fdd441a" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "serde", ] @@ -1791,19 +1841,20 @@ checksum = "3637c05577168127568a64e9dc5a6887da720efef07b3d9472d45f63ab191166" [[package]] name = "pest" -version = "2.7.2" +version = "2.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1acb4a4365a13f749a93f1a094a7805e5cfa0955373a9de860d962eaa3a5fe5a" +checksum = "d7a4d085fd991ac8d5b05a147b437791b4260b76326baf0fc60cf7c9c27ecd33" dependencies = [ + "memchr", "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.7.2" +version = "2.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "666d00490d4ac815001da55838c500eafb0320019bbaa44444137c48b443a853" +checksum = "a2bee7be22ce7918f641a33f08e3f43388c7656772244e2bbb2477f44cc9021a" dependencies = [ "pest", "pest_generator", @@ -1811,9 +1862,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.7.2" +version = "2.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ca01446f50dbda87c1786af8770d535423fa8a53aec03b8f4e3d7eb10e0929" +checksum = "d1511785c5e98d79a05e8a6bc34b4ac2168a0e3e92161862030ad84daa223141" dependencies = [ "pest", "pest_meta", @@ -1824,9 +1875,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.7.2" +version = "2.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56af0a30af74d0445c0bf6d9d051c979b516a1a5af790d251daee76005420a48" +checksum = "b42f0394d3123e33353ca5e1e89092e533d2cc490389f2bd6131c43c634ebc5f" dependencies = [ "once_cell", "pest", @@ -1855,9 +1906,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.12" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -1892,6 +1943,17 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "poly1305" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" +dependencies = [ + "cpufeatures", + "opaque-debug", + "universal-hash", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -1934,7 +1996,7 @@ dependencies = [ "quinn-proto", "quinn-udp", "rustc-hash", - "rustls 0.21.6", + "rustls 0.21.7", "thiserror", "tokio", "tracing", @@ -1942,15 +2004,15 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c8bb234e70c863204303507d841e7fa2295e95c822b2bb4ca8ebf57f17b1cb" +checksum = "e13f81c9a9d574310b8351f8666f5a93ac3b0069c45c28ad52c10291389a7cf9" dependencies = [ "bytes", "rand", "ring", "rustc-hash", - "rustls 0.21.6", + "rustls 0.21.7", "rustls-native-certs", "slab", "thiserror", @@ -1960,9 +2022,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6df19e284d93757a9fb91d63672f7741b129246a669db09d1c0063071debc0c0" +checksum = "055b4e778e8feb9f93c4e439f71dc2156ef13360b432b799e179a8c4cdf0b1d7" dependencies = [ "bytes", "libc", @@ -2018,7 +2080,7 @@ checksum = "4954fbc00dcd4d8282c987710e50ba513d351400dbdd00e803a05172a90d8976" dependencies = [ "pem", "ring", - "time 0.3.25", + "time 0.3.28", "yasna", ] @@ -2033,14 +2095,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bc1d4caf89fac26a70747fe603c130093b53c773888797a6329091246d651a" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.3.6", - "regex-syntax 0.7.4", + "regex-automata 0.3.7", + "regex-syntax 0.7.5", ] [[package]] @@ -2054,13 +2116,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed1ceff11a1dddaee50c9dc8e4938bd106e9d89ae372f192311e7da498e3b69" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.4", + "regex-syntax 0.7.5", ] [[package]] @@ -2071,17 +2133,17 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.4" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "reqwest" -version = "0.11.18" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", "bytes", "encoding_rs", "futures-core", @@ -2157,7 +2219,7 @@ dependencies = [ "serde_json", "sha1_smol", "threadpool", - "time 0.3.25", + "time 0.3.28", "tiny_http", "url", ] @@ -2208,9 +2270,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.8" +version = "0.38.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" dependencies = [ "bitflags 2.4.0", "errno", @@ -2221,9 +2283,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.20.8" +version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff78fc74d175294f4e83b28343315ffcfb114b156f0185e9741cb5570f50e2f" +checksum = "1b80e3dec595989ea8510028f30c408a4630db12c9cbb8de34203b89d6577e99" dependencies = [ "log", "ring", @@ -2233,9 +2295,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.6" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1feddffcfcc0b33f5c6ce9a29e341e4cd59c3f78e7ee45f4a40c038b1d6cbb" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", "ring", @@ -2261,14 +2323,14 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ - "base64 0.21.2", + "base64 0.21.3", ] [[package]] name = "rustls-webpki" -version = "0.101.3" +version = "0.101.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261e9e0888cba427c3316e6322805653c9425240b6fd96cee7cb671ab70ab8d0" +checksum = "7d93931baf2d282fff8d3a532bbfd7653f734643161b87e3e01e59a04439bf0d" dependencies = [ "ring", "untrusted", @@ -2357,18 +2419,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.183" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" dependencies = [ "proc-macro2", "quote", @@ -2462,9 +2524,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] @@ -2630,7 +2692,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ca69bf415b93b60b80dc8fda3cb4ef52b2336614d8da2de5456cc942a110482" dependencies = [ "atoi", - "base64 0.21.2", + "base64 0.21.3", "bitflags 2.4.0", "byteorder", "bytes", @@ -2672,7 +2734,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0db2df1b8731c3651e204629dd55e52adbae0462fa1bdcbed56a2302c18181e" dependencies = [ "atoi", - "base64 0.21.2", + "base64 0.21.3", "bitflags 2.4.0", "byteorder", "crc", @@ -2783,9 +2845,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.7.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc02fddf48964c42031a0b3fe0428320ecf3a73c401040fc0096f97794310651" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", @@ -2855,9 +2917,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.25" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +checksum = "17f6bb557fd245c28e6411aa56b6403c689ad95061f50e4be16c274e70a17e48" dependencies = [ "deranged", "libc", @@ -3073,9 +3135,9 @@ checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" [[package]] name = "unicase" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" dependencies = [ "version_check", ] @@ -3113,6 +3175,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e" +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + [[package]] name = "untrusted" version = "0.7.1" @@ -3121,9 +3193,9 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +checksum = "143b538f18257fac9cad154828a57c6bf5157e1aa604d4816b5995bf6de87ae5" dependencies = [ "form_urlencoded", "idna", @@ -3253,9 +3325,9 @@ dependencies = [ [[package]] name = "webpki" -version = "0.22.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f095d78192e208183081cc07bc5515ef55216397af48b873e5edcd72637fa1bd" +checksum = "f0e74f82d49d545ad128049b7e88f6576df2da6b02e9ce565c6f533be576957e" dependencies = [ "ring", "untrusted", @@ -3395,11 +3467,12 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" -version = "0.10.1" +version = "0.50.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" dependencies = [ - "winapi", + "cfg-if", + "windows-sys", ] [[package]] @@ -3411,7 +3484,7 @@ dependencies = [ "bytes", "quinn", "quinn-proto", - "rustls 0.21.6", + "rustls 0.21.7", "rustls-native-certs", "rustls-pemfile", "thiserror", @@ -3456,7 +3529,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" dependencies = [ - "time 0.3.25", + "time 0.3.28", ] [[package]] diff --git a/payjoin-cli/src/app.rs b/payjoin-cli/src/app.rs index 62ab7d74..7946c546 100644 --- a/payjoin-cli/src/app.rs +++ b/payjoin-cli/src/app.rs @@ -46,6 +46,7 @@ impl App { pub async fn send_payjoin(&self, bip21: &str) -> Result<()> { use std::net::{Ipv6Addr, SocketAddr}; + use tokio::io::AsyncReadExt; use wtransport::{ClientConfig, Endpoint}; let (req, ctx) = self.create_pj_request(bip21)?; @@ -64,6 +65,7 @@ impl App { let connection = Endpoint::client(config)?.connect(&req.url).await?; let (mut write, mut read) = connection.open_bi().await?.await?; log::debug!("Sending request"); + log::debug!("body.len(): {}", req.body.len()); write.write(&req.body).await?; log::debug!("Awaiting response"); let mut buffer = vec![0; 65536]; @@ -197,12 +199,11 @@ impl App { #[cfg(feature = "v2")] pub async fn receive_payjoin(self, amount_arg: &str) -> Result<()> { - let secp = bitcoin::secp256k1::Secp256k1::new(); - let mut rng = bitcoin::secp256k1::rand::thread_rng(); - let key = bitcoin::secp256k1::KeyPair::new(&secp, &mut rng); - let b64_config = base64::Config::new(base64::CharacterSet::UrlSafe, false); - let pubkey_base64 = base64::encode_config(key.public_key().to_string(), b64_config); - let pj_uri_string = self.construct_payjoin_uri(amount_arg, Some(&pubkey_base64))?; + use tokio::io::AsyncReadExt; + + let context = payjoin::receive::ProposalContext::new(); + let pj_uri_string = + self.construct_payjoin_uri(amount_arg, Some(&context.subdirectory()))?; println!( "Listening at {}. Configured to accept payjoin at BIP 21 Payjoin Uri:", self.config.pj_host @@ -213,19 +214,24 @@ impl App { // enroll receiver let (mut write, mut read) = connection.open_bi().await?.await?; log::debug!("Generating ephemeral keypair"); - let enroll_string = format!("{} {}", payjoin::v2::RECEIVE, pubkey_base64); - write.write_all(enroll_string.as_bytes()).await?; + write.write_all(context.enroll_string().as_bytes()).await?; log::debug!("Enrolled receiver, awaiting request"); - let mut buffer = vec![0; 65536].into_boxed_slice(); + let mut buffer = vec![0; 65536]; let len = read.read(&mut buffer).await?.unwrap(); + log::debug!("read len: {}", len); + log::debug!("buffer.len(): {}", buffer.len()); + buffer.truncate(len); log::debug!("Received request"); - let proposal = UncheckedProposal::from_streamed(&buffer[..len]) + let (proposal, e) = context + .parse_proposal(&mut buffer) .map_err(|e| anyhow!("Failed to parse into UncheckedProposal {}", e))?; let payjoin_psbt = self .process_proposal(proposal) .map_err(|e| anyhow!("Failed to process UncheckedProposal {}", e))?; - let payjoin_psbt_ser = base64::encode(&payjoin_psbt.serialize()); - write.write_all(payjoin_psbt_ser.as_bytes()).await?; + let mut payjoin_bytes = payjoin_psbt.serialize(); + log::debug!("payjoin_bytes: {:?}", payjoin_bytes); + let payload = payjoin::v2::encrypt_message_b(&mut payjoin_bytes, e); + write.write_all(&payload).await?; write.finish().await?; Ok(()) } @@ -376,10 +382,7 @@ impl App { headers, )?; - let payjoin_proposal_psbt = self.process_proposal(proposal)?; - log::debug!("Receiver's Payjoin proposal PSBT Rsponse: {:#?}", payjoin_proposal_psbt); - - let payload = base64::encode(&payjoin_proposal_psbt.serialize()); + let payload = self.process_proposal(proposal)?; log::info!("successful response"); Ok(Response::text(payload)) } diff --git a/payjoin-relay/src/main.rs b/payjoin-relay/src/main.rs index f675f186..e5709f7f 100644 --- a/payjoin-relay/src/main.rs +++ b/payjoin-relay/src/main.rs @@ -83,19 +83,23 @@ async fn handle_connection_impl(incoming_session: IncomingSession, pool: DbPool) let (mut write, mut read) = stream?; info!("Accepted BI stream for pubkey_id {}", pubkey_id); - match read_stream_to_string(&mut read).await? { - Some(data) => { - let mut parts = data.split_whitespace(); - let operation = parts.next().ok_or(anyhow::anyhow!("No operation"))?; - if operation == RECEIVE { - let pubkey_id = parts.next().ok_or(anyhow::anyhow!("No pubkey_id"))?; - let pubkey_id = shorten_string(pubkey_id); - info!("Received receiver enroll request for pubkey_id {}", pubkey_id); - handle_receiver_request(&mut write, &mut read, &pool, &pubkey_id).await?; - } else { - handle_sender_request(&mut write, &data, &pool, &pubkey_id).await?; + let mut buffer = vec![0; MAX_BUFFER_SIZE]; + match read.read(&mut buffer).await? { + Some(bytes_read) => { + match std::str::from_utf8(&buffer[..bytes_read]) { + Ok(message) => { + let mut parts = message.split_whitespace(); + let operation = parts.next().ok_or(anyhow::anyhow!("No operation"))?; + if operation == RECEIVE { + let pubkey_id = parts.next().ok_or(anyhow::anyhow!("No pubkey_id"))?; + let pubkey_id = shorten_string(pubkey_id); + info!("Received receiver enroll request for pubkey_id {}", pubkey_id); + handle_receiver_request(&mut write, &mut read, &pool, &pubkey_id).await?; + } + } + _ => handle_sender_request(&mut write, buffer[..bytes_read].to_vec(), &pool, &pubkey_id).await? } - } + }, None => continue, } @@ -115,14 +119,6 @@ fn init_logging() { println!("Logging initialized"); } -async fn read_stream_to_string(read: &mut RecvStream) -> Result> { - let mut buffer = vec![0; MAX_BUFFER_SIZE]; - match read.read(&mut buffer).await? { - Some(bytes_read) => Ok(Some(std::str::from_utf8(&buffer[..bytes_read])?.to_string())), - None => Ok(None), - } -} - async fn handle_receiver_request( write: &mut SendStream, read: &mut RecvStream, @@ -131,9 +127,9 @@ async fn handle_receiver_request( ) -> Result<()> { let buffered_req = pool.peek_req(pubkey_id).await?; write.write_all(&buffered_req).await?; - - if let Some(response) = read_stream_to_string(read).await? { - pool.push_res(pubkey_id, response.as_bytes().to_vec()).await?; + let mut buffer = vec![0; MAX_BUFFER_SIZE]; + if let Some(bytes_read) = read.read(&mut buffer).await? { + pool.push_res(pubkey_id, buffer[..bytes_read].to_vec()).await?; } Ok(()) @@ -141,11 +137,11 @@ async fn handle_receiver_request( async fn handle_sender_request( write: &mut SendStream, - data: &str, + data: Vec, pool: &DbPool, pubkey_id: &str, ) -> Result<()> { - pool.push_req(pubkey_id, data.as_bytes().to_vec()).await?; + pool.push_req(pubkey_id, data).await?; debug!("pushed req"); let response = pool.peek_res(pubkey_id).await?; debug!("peek req"); diff --git a/payjoin/Cargo.toml b/payjoin/Cargo.toml index 7eac8df0..82a2b708 100644 --- a/payjoin/Cargo.toml +++ b/payjoin/Cargo.toml @@ -15,11 +15,12 @@ edition = "2018" [features] send = [] receive = ["rand"] -v2 = ["serde", "serde_json"] +v2 = ["bitcoin/rand-std", "chacha20poly1305", "serde", "serde_json"] [dependencies] bitcoin = { version = "0.30.0", features = ["base64"] } bip21 = "0.3.1" +chacha20poly1305 = { version = "0.10.1", optional = true } log = { version = "0.4.14"} rand = { version = "0.8.4", optional = true } serde = { version = "1.0", optional = true } diff --git a/payjoin/src/receive/mod.rs b/payjoin/src/receive/mod.rs index ddebb41e..d133bab6 100644 --- a/payjoin/src/receive/mod.rs +++ b/payjoin/src/receive/mod.rs @@ -278,6 +278,7 @@ pub use error::{Error, RequestError, SelectionError}; use error::{InternalRequestError, InternalSelectionError}; use rand::seq::SliceRandom; use rand::Rng; +use serde::Serialize; use crate::input_type::InputType; use crate::optional_parameters::Params; @@ -287,6 +288,45 @@ pub trait Headers { fn get_header(&self, key: &str) -> Option<&str>; } +#[cfg(feature = "v2")] +pub struct ProposalContext { + s: bitcoin::secp256k1::KeyPair, +} + +impl ProposalContext { + pub fn new() -> Self { + let secp = bitcoin::secp256k1::Secp256k1::new(); + let (sk, _) = secp.generate_keypair(&mut rand::rngs::OsRng); + ProposalContext { s: bitcoin::secp256k1::KeyPair::from_secret_key(&secp, &sk) } + } + + pub fn subdirectory(&self) -> String { + let pubkey = &self.s.public_key().serialize(); + let b64_config = + bitcoin::base64::Config::new(bitcoin::base64::CharacterSet::UrlSafe, false); + let pubkey_base64 = bitcoin::base64::encode_config(pubkey, b64_config); + pubkey_base64 + } + + pub fn enroll_string(&self) -> String { + format!("{} {}", crate::v2::RECEIVE, self.subdirectory()) + } + + pub fn parse_proposal( + self, + encrypted_proposal: &mut [u8], + ) -> Result<(UncheckedProposal, bitcoin::secp256k1::PublicKey), RequestError> { + let (proposal, e) = crate::v2::decrypt_message_a(encrypted_proposal, self.s.secret_key()); + let mut proposal = serde_json::from_slice::(&proposal) + .map_err(InternalRequestError::Json)?; + proposal.psbt = proposal.psbt.validate().map_err(InternalRequestError::InconsistentPsbt)?; + log::debug!("Received original psbt: {:?}", proposal.psbt); + log::debug!("Received request with params: {:?}", proposal.params); + + Ok((proposal, e)) + } +} + /// The sender's original PSBT and optional parameters /// /// This type is used to proces the request. It is returned by @@ -341,20 +381,8 @@ where Ok(unchecked_psbt) } -#[cfg(feature = "v2")] -impl UncheckedProposal { - pub fn from_streamed(streamed: &[u8]) -> Result { - let mut proposal = serde_json::from_slice::(streamed) - .map_err(InternalRequestError::Json)?; - proposal.psbt = proposal.psbt.validate().map_err(InternalRequestError::InconsistentPsbt)?; - log::debug!("Received original psbt: {:?}", proposal.psbt); - log::debug!("Received request with params: {:?}", proposal.params); - - Ok(proposal) - } -} - impl UncheckedProposal { + #[cfg(not(feature = "v2"))] pub fn from_request( mut body: impl std::io::Read, query: &str, diff --git a/payjoin/src/send/mod.rs b/payjoin/src/send/mod.rs index cb465c15..24a25cd7 100644 --- a/payjoin/src/send/mod.rs +++ b/payjoin/src/send/mod.rs @@ -322,6 +322,8 @@ pub struct Context { input_type: InputType, sequence: Sequence, payee: ScriptBuf, + #[cfg(feature = "v2")] + e: bitcoin::secp256k1::SecretKey, } macro_rules! check_eq { @@ -348,6 +350,7 @@ impl Context { /// Call this method with response from receiver to continue BIP78 flow. If the response is /// valid you will get appropriate PSBT that you should sign and broadcast. #[inline] + #[cfg(not(feature = "v2"))] pub fn process_response( self, response: &mut impl std::io::Read, @@ -360,6 +363,19 @@ impl Context { self.process_proposal(proposal).map(Into::into).map_err(Into::into) } + #[cfg(feature = "v2")] + pub fn process_response( + self, + response: &mut impl std::io::Read, + ) -> Result { + let mut res_buf = Vec::new(); + response.read_to_end(&mut res_buf).map_err(InternalValidationError::Io)?; + let psbt = crate::v2::decrypt_message_b(&mut res_buf, self.e); + let proposal = Psbt::deserialize(&psbt).expect("PSBT deserialization failed"); + // process in non-generic function + self.process_proposal(proposal).map(Into::into).map_err(Into::into) + } + fn process_proposal(self, proposal: Psbt) -> InternalResult { self.basic_checks(&proposal)?; let in_stats = self.check_inputs(&proposal)?; @@ -833,13 +849,20 @@ pub(crate) fn from_psbt_and_uri( let sequence = zeroth_input.txin.sequence; let txout = zeroth_input.previous_txout().expect("We already checked this above"); let input_type = InputType::from_spent_input(txout, zeroth_input.psbtin).unwrap(); - let url = uri.extras._endpoint; + let rs_base64 = crate::v2::subdir(uri.extras._endpoint.as_str()).to_string(); + log::debug!("rs_base64: {:?}", rs_base64); + let b64_config = bitcoin::base64::Config::new(bitcoin::base64::CharacterSet::UrlSafe, false); + let rs = bitcoin::base64::decode_config(rs_base64, b64_config).unwrap(); + log::debug!("rs: {:?}", rs.len()); + let rs = bitcoin::secp256k1::PublicKey::from_slice(&rs).unwrap(); let body = serialize_v2_body( &psbt, disable_output_substitution, fee_contribution, params.min_fee_rate, ); + let (body, e) = crate::v2::encrypt_message_a(&body, rs); + let url = uri.extras._endpoint; Ok(( Request { url, body }, Context { @@ -850,6 +873,7 @@ pub(crate) fn from_psbt_and_uri( input_type, sequence, min_fee_rate: params.min_fee_rate, + e, }, )) } @@ -857,6 +881,7 @@ pub(crate) fn from_psbt_and_uri( #[cfg(test)] mod tests { #[test] + #[cfg(not(feature = "v2"))] fn official_vectors() { use std::str::FromStr; diff --git a/payjoin/src/v2.rs b/payjoin/src/v2.rs index 93dfc652..d9e613cf 100644 --- a/payjoin/src/v2.rs +++ b/payjoin/src/v2.rs @@ -1,2 +1,110 @@ pub const MAX_BUFFER_SIZE: usize = 65536; pub const RECEIVE: &str = "receive"; + +pub fn subdir(path: &str) -> String { + let subdirectory: String; + + if let Some(pos) = path.rfind('/') { + subdirectory = path[pos + 1..].to_string(); + } else { + subdirectory = path.to_string(); + } + + let pubkey_id: String; + + if let Some(pos) = subdirectory.find('?') { + pubkey_id = subdirectory[..pos].to_string(); + } else { + pubkey_id = subdirectory; + } + pubkey_id +} + +use bitcoin::secp256k1::ecdh::SharedSecret; +use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; +use chacha20poly1305::aead::generic_array::sequence::GenericSequence; +use chacha20poly1305::aead::{Aead, KeyInit, OsRng, Payload}; +use chacha20poly1305::{AeadCore, ChaCha20Poly1305, Nonce}; + +/// crypto context +/// +/// <- Receiver S +/// -> Sender E, ES(payload), payload protected by knowledge of receiver key +/// <- Receiver E, EE(payload), payload protected by knowledge of sender & receiver key +pub fn encrypt_message_a(msg: &[u8], s: PublicKey) -> (Vec, SecretKey) { + let secp = Secp256k1::new(); + let (e_sec, e_pub) = secp.generate_keypair(&mut OsRng); + let es = SharedSecret::new(&s, &e_sec); + let cipher = + ChaCha20Poly1305::new_from_slice(&es.secret_bytes()).expect("cipher creation failed"); + let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng); // key es encrypts only 1 message so 0 is unique + let aad = &e_pub.serialize(); + let payload = Payload { msg, aad }; + log::debug!("payload.msg: {:?}", payload.msg); + log::debug!("payload.aad: {:?}", payload.aad); + let c_t: Vec = cipher.encrypt(&nonce, payload).expect("encryption failed"); + log::debug!("c_t: {:?}", c_t); + // let ct_payload = Payload { + // msg: &c_t[..], + // aad, + // }; + // let plaintext = cipher.decrypt(&nonce, ct_payload).map_err(|e| log::error!("error: {:?}", e)).unwrap(); + //log::debug!("plaintext: {:?}", plaintext); + log::debug!("es: {:?}", es); + let mut message_a = e_pub.serialize().to_vec(); + log::debug!("e: {:?}", e_pub); + message_a.extend(&nonce[..]); + log::debug!("nonce: {:?}", nonce); + message_a.extend(&c_t[..]); + (message_a, e_sec) +} + +pub fn decrypt_message_a(message_a: &mut [u8], s: SecretKey) -> (Vec, PublicKey) { + // let message a = [pubkey/AD][nonce][authentication tag][ciphertext] + let e = PublicKey::from_slice(&message_a[..33]).expect("invalid public key"); + log::debug!("e: {:?}", e); + let nonce = Nonce::from_slice(&message_a[33..45]); + log::debug!("nonce: {:?}", nonce); + let es = SharedSecret::new(&e, &s); + log::debug!("es: {:?}", es); + let cipher = + ChaCha20Poly1305::new_from_slice(&es.secret_bytes()).expect("cipher creation failed"); + let c_t = &message_a[45..]; + let aad = &e.serialize(); + log::debug!("c_t: {:?}", c_t); + log::debug!("aad: {:?}", aad); + let payload = Payload { msg: &c_t, aad }; + log::debug!("payload.msg: {:?}", payload.msg); + log::debug!("payload.aad: {:?}", payload.aad); + let buffer = cipher.decrypt(&nonce, payload).expect("decryption failed"); + (buffer, e) +} + +pub fn encrypt_message_b(msg: &mut Vec, re_pub: PublicKey) -> Vec { + // let message b = [pubkey/AD][nonce][authentication tag][ciphertext] + let secp = Secp256k1::new(); + let (e_sec, e_pub) = secp.generate_keypair(&mut OsRng); + let ee = SharedSecret::new(&re_pub, &e_sec); + let cipher = + ChaCha20Poly1305::new_from_slice(&ee.secret_bytes()).expect("cipher creation failed"); + let nonce = Nonce::from_slice(&[0u8; 12]); // key es encrypts only 1 message so 0 is unique + let aad = &e_pub.serialize(); + let payload = Payload { msg, aad }; + let c_t = cipher.encrypt(nonce, payload).expect("encryption failed"); + let mut message_b = e_pub.serialize().to_vec(); + message_b.extend(&nonce[..]); + message_b.extend(&c_t[..]); + message_b +} + +pub fn decrypt_message_b(message_b: &mut Vec, e: SecretKey) -> Vec { + // let message b = [pubkey/AD][nonce][authentication tag][ciphertext] + let re = PublicKey::from_slice(&message_b[..33]).expect("invalid public key"); + let nonce = Nonce::from_slice(&message_b[33..45]); + let ee = SharedSecret::new(&re, &e); + let cipher = + ChaCha20Poly1305::new_from_slice(&ee.secret_bytes()).expect("cipher creation failed"); + let payload = Payload { msg: &message_b[45..], aad: &re.serialize() }; + let buffer = cipher.decrypt(&nonce, payload).expect("decryption failed"); + buffer +}