From 16d7a833e4322d2b3ea14de82970a66149bea4b9 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 13 May 2024 06:55:20 -0400 Subject: [PATCH] Latest monero --- Cargo.lock | 477 +++++----------------------- Cargo.toml | 6 +- src/cli.rs | 1 - src/coins/mod.rs | 3 - src/coins/nano/client.rs | 124 -------- src/coins/nano/engine.rs | 273 ---------------- src/coins/nano/mod.rs | 7 - src/coins/nano/verifier.rs | 104 ------ src/coins/xmr/engine.rs | 2 +- src/coins/xmr/verifier.rs | 19 +- src/coins/zec/client.rs | 0 src/crypt_engines/ed25519_engine.rs | 34 +- src/main.rs | 3 - src/tests/coin_specific/mod.rs | 1 - src/tests/coin_specific/nano.rs | 24 -- src/tests/ltc_and_nano.rs | 79 ----- src/tests/mod.rs | 3 - 17 files changed, 115 insertions(+), 1045 deletions(-) delete mode 100644 src/coins/nano/client.rs delete mode 100644 src/coins/nano/engine.rs delete mode 100644 src/coins/nano/mod.rs delete mode 100644 src/coins/nano/verifier.rs delete mode 100644 src/coins/zec/client.rs delete mode 100644 src/tests/coin_specific/mod.rs delete mode 100644 src/tests/coin_specific/nano.rs delete mode 100644 src/tests/ltc_and_nano.rs diff --git a/Cargo.lock b/Cargo.lock index 77fba22..b76235d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,21 +49,20 @@ dependencies = [ "async-trait", "bincode", "bitcoin", - "blake2 0.9.2", - "curve25519-dalek 3.2.1", + "blake2", + "curve25519-dalek", "derive_more", - "digest 0.9.0", + "digest", "digest_auth", "enum-utils", "enum_dispatch", "env_logger", "futures", - "hex 0.4.3", - "hex-literal 0.4.1", + "hex", + "hex-literal", "lazy_static", "log", "monero", - "nanocurrency-types", "num_cpus", "rand 0.7.3", "rand 0.8.5", @@ -98,15 +97,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.3.0", -] - [[package]] name = "autocfg" version = "1.3.0" @@ -130,9 +120,9 @@ dependencies = [ [[package]] name = "base58-monero" -version = "0.3.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "935c90240f9b7749c80746bf88ad9cb346f34b01ee30ad4d566dfdecd6e3cc6a" +checksum = "978e81a45367d2409ecd33369a45dda2e9a3ca516153ec194de1fbda4b9fb79d" dependencies = [ "thiserror", ] @@ -186,27 +176,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -[[package]] -name = "blake2" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" -dependencies = [ - "byte-tools", - "crypto-mac 0.7.0", - "digest 0.8.1", - "opaque-debug 0.2.3", -] - [[package]] name = "blake2" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" dependencies = [ - "crypto-mac 0.8.0", - "digest 0.9.0", - "opaque-debug 0.3.1", + "crypto-mac", + "digest", + "opaque-debug", ] [[package]] @@ -215,7 +193,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.7", + "generic-array", ] [[package]] @@ -224,12 +202,6 @@ version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" -[[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.5.0" @@ -281,24 +253,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "clear_on_drop" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38508a63f4979f0048febc9966fadbd48e5dab31fd0ec6a3f151bbf4a74f7423" -dependencies = [ - "cc", -] - -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "convert_case" version = "0.4.0" @@ -336,51 +290,43 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[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 = "crypto-mac" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.7", - "subtle 2.5.0", + "generic-array", + "subtle", ] [[package]] name = "curve25519-dalek" -version = "1.2.6" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d59fed08e452f286b251f88b2fc64a01f50a7b263aa09557ad7285d9e7fa" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ - "byteorder", - "clear_on_drop", - "digest 0.8.1", - "rand_core 0.3.1", - "subtle 2.5.0", + "cfg-if 1.0.0", + "cpufeatures", + "curve25519-dalek-derive", + "fiat-crypto", + "platforms", + "rand_core 0.6.4", + "rustc_version", + "serde", + "subtle", + "zeroize", ] [[package]] -name = "curve25519-dalek" -version = "3.2.1" +name = "curve25519-dalek-derive" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", - "serde", - "subtle 2.5.0", - "zeroize", + "proc-macro2", + "quote", + "syn 2.0.63", ] [[package]] @@ -396,22 +342,13 @@ dependencies = [ "syn 1.0.109", ] -[[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.7", + "generic-array", ] [[package]] @@ -420,25 +357,13 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12fd5e24649b07f360f59a1e0a522d775540e2bc4b88f8d2657bcf8ca0360d74" dependencies = [ - "digest 0.9.0", - "hex 0.4.3", + "digest", + "hex", "md-5", "rand 0.8.5", "sha2", ] -[[package]] -name = "ed25519-dalek" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d07e8b8a8386c3b89a7a4b329fdfa4cb545de2545e9e2ebbc3dd3929253e426" -dependencies = [ - "clear_on_drop", - "curve25519-dalek 1.2.6", - "failure", - "rand 0.6.5", -] - [[package]] name = "encoding_rs" version = "0.8.34" @@ -522,11 +447,17 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "fixed-hash" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "byteorder", "rand 0.8.5", @@ -564,12 +495,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -675,15 +600,6 @@ dependencies = [ "slab", ] -[[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.7" @@ -757,6 +673,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -772,24 +694,12 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" -[[package]] -name = "hex" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "hex-literal" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" - [[package]] name = "hex-literal" version = "0.4.1" @@ -891,7 +801,7 @@ version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ - "autocfg 1.3.0", + "autocfg", "hashbrown", ] @@ -931,16 +841,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "keccak-hash" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae0386ec98c26dd721aaa3412bf3a817156ff3ee7cb6959503f8d1095f4ccc51" -dependencies = [ - "primitive-types", - "tiny-keccak", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -981,8 +881,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15" dependencies = [ "block-buffer", - "digest 0.9.0", - "opaque-debug 0.3.1", + "digest", + "opaque-debug", ] [[package]] @@ -1081,36 +981,18 @@ dependencies = [ [[package]] name = "monero" -version = "0.12.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c73108ba5cf025e437600990935234241f95ada3c4621960d50912cde739af6" +checksum = "f25218523ad4a171ddda05251669afb788cdc2f0df94082aab856a2b09541c3f" dependencies = [ "base58-monero", - "curve25519-dalek 3.2.1", + "curve25519-dalek", "fixed-hash", - "hex 0.4.3", - "hex-literal 0.3.4", - "keccak-hash", + "hex", + "hex-literal", + "sealed", "thiserror", -] - -[[package]] -name = "nanocurrency-types" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e70cbfca245c93def8a9a044ac6720d8061817753eb7c4b4078fbf9e7200f490" -dependencies = [ - "blake2 0.8.1", - "byteorder", - "curve25519-dalek 1.2.6", - "digest 0.8.1", - "ed25519-dalek", - "hex 0.3.2", - "num-bigint", - "num-traits 0.1.43", - "rand 0.6.5", - "serde", - "serde_derive", + "tiny-keccak", ] [[package]] @@ -1142,45 +1024,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "num-bigint" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" -dependencies = [ - "num-integer", - "num-traits 0.2.19", - "rand 0.4.6", - "rustc-serialize", -] - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits 0.2.19", -] - -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -dependencies = [ - "num-traits 0.2.19", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg 1.3.0", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -1206,12 +1049,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[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.1" @@ -1313,20 +1150,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] -name = "ppv-lite86" -version = "0.2.17" +name = "platforms" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] -name = "primitive-types" -version = "0.9.1" +name = "ppv-lite86" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e" -dependencies = [ - "fixed-hash", - "uint", -] +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro-error" @@ -1376,38 +1209,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "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 0.3.9", -] - [[package]] name = "rand" version = "0.7.3" @@ -1418,7 +1219,7 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", ] [[package]] @@ -1432,16 +1233,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -1462,21 +1253,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[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" @@ -1495,15 +1271,6 @@ dependencies = [ "getrandom 0.2.15", ] -[[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" @@ -1513,68 +1280,6 @@ 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 0.3.9", -] - -[[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 0.3.9", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "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.10.4" @@ -1652,12 +1357,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc-serialize" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" - [[package]] name = "rustc_version" version = "0.4.0" @@ -1695,6 +1394,18 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "sealed" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a8caec23b7800fb97971a1c6ae365b6239aaeddfb934d6265f8505e795699d" +dependencies = [ + "heck 0.4.1", + "proc-macro2", + "quote", + "syn 2.0.63", +] + [[package]] name = "secp256k1" version = "0.22.2" @@ -1719,7 +1430,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34697f9a5a65f6ff9c2e86f6ff0b092dbdf3e4bd2a4f2ca5450710389187e07f" dependencies = [ - "digest 0.9.0", + "digest", "rand_core 0.6.4", "secp256kfun_parity_backend", "serde", @@ -1828,8 +1539,8 @@ dependencies = [ "block-buffer", "cfg-if 1.0.0", "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.1", + "digest", + "opaque-debug", ] [[package]] @@ -1847,7 +1558,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ - "autocfg 1.3.0", + "autocfg", ] [[package]] @@ -1890,19 +1601,13 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck", + "heck 0.3.3", "proc-macro-error", "proc-macro2", "quote", "syn 1.0.109", ] -[[package]] -name = "subtle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" - [[package]] name = "subtle" version = "2.5.0" @@ -1913,7 +1618,7 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" name = "subtle-ng" version = "2.5.0" dependencies = [ - "subtle 2.5.0", + "subtle", ] [[package]] @@ -2119,18 +1824,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "uint" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" -dependencies = [ - "byteorder", - "crunchy", - "hex 0.4.3", - "static_assertions", -] - [[package]] name = "unicase" version = "2.7.0" @@ -2438,6 +2131,6 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.3.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/Cargo.toml b/Cargo.toml index cfca840..28584e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,22 +23,20 @@ digest = "0.9" sha2 = "0.9" blake2 = "0.9" secp256kfun = { version = "0.6", default-features = false, features = ["serde"] } -curve25519-dalek = { version = "3", features = ["serde"] } +curve25519-dalek = { version = "4", features = ["rand_core", "serde"] } serde = { version = "1", features = ["derive"] } derive_more = "0.99" bincode = "1" serde_json = "1" reqwest = { version = "0.10", features = ["json"] } bitcoin = { git = "https://github.com/rust-litecoin/rust-litecoin", branch = "ltc" } -nanocurrency-types = "0.3" num_cpus = "1" -monero = "0.12" +monero = "0.21" digest_auth = "0.2" [features] no_confs = [] test_litecoin_node = [] -test_nano_node = [] test_monero_node = [] # Always optimize dependencies diff --git a/src/cli.rs b/src/cli.rs index 95cf5e2..3710096 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -56,7 +56,6 @@ pub enum ScriptedCoin { #[derive(FromStr, Debug, Clone)] #[enumeration(rename_all = "lowercase")] pub enum UnscriptedCoin { - Nano, #[enumeration(alias = "xmr")] Monero, } diff --git a/src/coins/mod.rs b/src/coins/mod.rs index 122517e..c98bfbd 100644 --- a/src/coins/mod.rs +++ b/src/coins/mod.rs @@ -1,5 +1,4 @@ pub mod btc; -pub mod nano; pub mod xmr; use std::marker::PhantomData; @@ -70,7 +69,6 @@ pub trait UnscriptedClient { #[enum_dispatch] pub enum AnyUnscriptedClient { - Nano(nano::client::NanoClient), Monero(xmr::client::XmrClient), } @@ -121,6 +119,5 @@ pub trait UnscriptedVerifier: Send + Sync { #[enum_dispatch] pub enum AnyUnscriptedVerifier { - Nano(nano::verifier::NanoVerifier), Monero(xmr::verifier::XmrVerifier), } diff --git a/src/coins/nano/client.rs b/src/coins/nano/client.rs deleted file mode 100644 index f2deeef..0000000 --- a/src/coins/nano/client.rs +++ /dev/null @@ -1,124 +0,0 @@ -use std::{ - marker::PhantomData, - path::Path, - fs::File -}; - -use async_trait::async_trait; -use nanocurrency_types::{Account, BlockHash}; - -use crate::{ - crypt_engines::{KeyBundle, CryptEngine, ed25519_engine::Ed25519Blake2b}, - coins::{ - UnscriptedClient, ScriptedVerifier, - nano::engine::{NanoConfig, NanoEngine} - } -}; - -pub struct NanoClient { - engine: NanoEngine, - refund: Account, - key_share: Option<::PrivateKey>, - shared_key: Option<::PublicKey>, - address: Option, - input: Option<(BlockHash, u128)>, -} - -impl NanoClient { - pub fn new(config_path: &Path) -> anyhow::Result { - let config: NanoConfig = serde_json::from_reader(File::open(config_path)?)?; - Ok(NanoClient{ - refund: config.refund.parse() - .map_err(|e| anyhow::anyhow!("Error parsing Nano address: {}", e))?, - engine: NanoEngine::new(config), - key_share: None, - shared_key: None, - address: None, - input: None, - }) - } -} - -#[async_trait] -impl UnscriptedClient for NanoClient { - fn generate_keys(&mut self, verifier: &mut Verifier) -> Vec { - let (dl_eq, key) = verifier.generate_keys_for_engine::(PhantomData); - self.key_share = Some(key); - KeyBundle { - dl_eq, - B: verifier.B(), - BR: verifier.BR(), - scripted_destination: verifier.destination_script() - }.serialize() - } - - fn verify_keys(&mut self, keys: &[u8], verifier: &mut Verifier) -> anyhow::Result<()> { - let host_key = verifier.verify_keys_for_engine::(&keys, PhantomData)?; - let our_pubkey = Ed25519Blake2b::to_public_key(self.key_share.as_ref().expect("Verifying DLEQ proof before generating keys")); - self.shared_key = Some(our_pubkey + host_key); - Ok(()) - } - - fn get_address(&mut self) -> String { - let shared_key = self.shared_key.expect("Trying to get the Nano deposit addresss despite not having verified the host's DLEQ proof"); - let address = Account(shared_key.compress().to_bytes()).to_string(); - self.address = Some(address.clone()); - address - } - - async fn wait_for_deposit(&mut self) -> anyhow::Result<()> { - let address = self.address.clone().expect("Waiting for deposit despite not knowing the deposit address"); - while self.input.is_none() { - tokio::time::delay_for(std::time::Duration::from_secs(5)).await; - let mut inputs = self.engine.get_confirmed_pending(&address).await?; - inputs.truncate(1); - self.input = inputs.pop(); - } - Ok(()) - } - - async fn refund(mut self, verifier: Verifier) -> anyhow::Result<()> { - if let Some((input, amount)) = self.input { - /* - Once we publish the refund, two paths open up - A) We can claim the BTC after the second timeout expires - B) We can claim the NANO after the host claims the BTC - We assume path A, and then revert to path B if path A fails - */ - if let Some(recovered_key) = verifier.claim_refund_or_recover_key().await? { - self.engine.send( - Ed25519Blake2b::little_endian_bytes_to_private_key(recovered_key)?, - self.key_share.expect("Finishing before generating keys"), - input, - self.refund, - amount, - ).await?; - } - } - Ok(()) - } - - #[cfg(test)] - fn override_refund_with_random_address(&mut self) { - self.refund = Account(Ed25519Blake2b::to_public_key(&Ed25519Blake2b::new_private_key()).compress().to_bytes()); - } - #[cfg(test)] - async fn send_from_node(&mut self) -> anyhow::Result<()> { - self.engine.send_from_node(self.address.as_ref().unwrap(), 1) - .await - .expect("Failed to send Nano from node wallet"); - Ok(()) - } - #[cfg(test)] - async fn advance_consensus(&self) -> anyhow::Result<()> { - Ok(()) - } - #[cfg(test)] - fn get_refund_address(&self) -> String { - self.refund.to_string() - } - #[cfg(test)] - async fn get_if_funded(mut self, address: &str) -> bool { - !self.engine.get_confirmed_pending(&address).await.unwrap().is_empty() - } -} diff --git a/src/coins/nano/engine.rs b/src/coins/nano/engine.rs deleted file mode 100644 index ca5331e..0000000 --- a/src/coins/nano/engine.rs +++ /dev/null @@ -1,273 +0,0 @@ -use std::{ - collections::HashMap, - fmt::Debug, - thread, - sync::{Arc, atomic::{self, AtomicBool}, mpsc}, -}; - -use log::{debug, info}; -use serde::{Serialize, Deserialize, de::DeserializeOwned}; -use nanocurrency_types::{Account, BlockInner, BlockHash, Block, BlockHeader}; - -use crate::crypt_engines::{CryptEngine, ed25519_engine::Ed25519Blake2b}; - -/// A workaround for the Nano RPC returning empty strings instead of empty arrays or objects. -pub mod nano_rpc_maybe_empty { - use serde::{Serialize, Deserialize, de::{Deserializer, Error}, ser::Serializer}; - - #[allow(dead_code)] // 5 lines of dead code for serialize support if we ever want it ¯\_(ツ)_/¯ - pub fn serialize(item: &T, serializer: S) -> Result { - if item == &Default::default() { - "".serialize(serializer) - } else { - item.serialize(serializer) - } - } - - pub fn deserialize<'de, T: Deserialize<'de> + PartialEq + Default, D: Deserializer<'de>>(deserializer: D) -> Result { - #[derive(Deserialize)] - #[serde(untagged)] - enum OrString { - Thing(T), - String(String), - } - match OrString::deserialize(deserializer)? { - OrString::Thing(t) => Ok(t), - OrString::String(s) => { - if s.is_empty() { - Ok(T::default()) - } else { - Err(D::Error::custom(format!("Got unexpected non-empty string {:?} from Nano RPC", s))) - } - } - } - } -} - -#[derive(Deserialize)] -pub struct NanoConfig { - pub rpc_url: String, - pub destination: String, - pub refund: String, - #[cfg(test)] - pub wallet: String, - #[cfg(test)] - pub wallet_account: String, -} - -pub struct NanoEngine { - pub k: Option<::PrivateKey>, - pub client: reqwest::Client, - pub config: NanoConfig, -} - -impl NanoEngine { - pub fn new(config: NanoConfig) -> NanoEngine { - NanoEngine { - k: None, - client: reqwest::Client::new(), - config, - } - } - - async fn rpc_call< - Request: Serialize + Debug, - Response: DeserializeOwned + Debug - >(&self, request: &Request) -> anyhow::Result { - #[derive(Deserialize, Debug)] - #[serde(untagged)] - enum RespOrError { - Error { - error: String, - }, - Response(T), - } - let resp = self - .client - .post(&self.config.rpc_url) - .json(request) - .send() - .await? - .json() - .await?; - debug!("Nano RPC call {:?} returned {}", request, resp); - match serde_json::from_value(resp)? { - RespOrError::Error { error } => anyhow::bail!("Nano RPC returned an error: {}", error), - RespOrError::Response(resp) => Ok(resp), - } - } - - async fn publish(&self, block: &Block, subtype: &str) -> anyhow::Result<()> { - #[derive(Serialize, Debug)] - struct ProcessRequest<'a> { - action: &'a str, - json_block: &'a str, - subtype: &'a str, - block: &'a Block, - } - #[derive(Deserialize, Debug)] - struct ProcessResponse { - hash: String, - } - let req = ProcessRequest { - action: "process", - json_block: "true", - subtype, - block, - }; - let res: ProcessResponse = self.rpc_call(&req).await?; - debug_assert_eq!(res.hash, hex::encode_upper(block.get_hash().0)); - Ok(()) - } - - fn compute_work(root: [u8; 32], threshold: u64) -> u64 { - info!("Generating Nano proof of work for root {} with threshold 0x{:016x}", hex::encode(&root), threshold); - // TODO support calling an external work RPC - let (send, recv) = mpsc::channel(); - let running = Arc::new(AtomicBool::new(true)); - let thread_count = num_cpus::get(); - for i in 0..thread_count { - let send = send.clone(); - let running = running.clone(); - thread::spawn(move || { - let mut nonce = (u64::MAX / thread_count as u64) * i as u64; - while nanocurrency_types::work_value(&root, nonce) < threshold && - running.load(atomic::Ordering::Relaxed) - { - nonce += 1; - } - let _ = send.send(nonce); - }); - } - let nonce = recv.recv().expect("Work computation threads died"); - running.store(false, atomic::Ordering::Relaxed); - debug!("Generated Nano proof of work nonce {:016x} for root {}", nonce, hex::encode(&root)); - nonce - } - - fn complete_block(inner: BlockInner, key: ::PrivateKey, work_threshold: u64) -> Block { - let hash = inner.get_hash(); - let signature = Ed25519Blake2b::sign(&key, &hash.0).unwrap(); - let work = Self::compute_work(inner.root_bytes().clone(), work_threshold); - Block { - inner, - header: BlockHeader { - signature: nanocurrency_types::Signature::from_bytes( - &Ed25519Blake2b::signature_to_bytes(&signature) - ).expect("Generated invalid signature"), - work, - } - } - } - - async fn get_work_threshold(&self, is_receive: bool) -> anyhow::Result { - #[derive(Serialize, Debug)] - struct ActiveDifficultyRequest { - action: &'static str, - } - #[derive(Deserialize, Debug)] - struct ActiveDifficultyResponse { - network_current: String, - } - let request = ActiveDifficultyRequest { - action: "active_difficulty", - }; - let resp: ActiveDifficultyResponse = self.rpc_call(&request).await?; - let mut threshold = u64::from_str_radix(&resp.network_current, 16)?; - if is_receive && !cfg!(test) { // In automated tests epoch 2 might not've happened yet - threshold = (threshold.wrapping_neg() / 64).wrapping_neg(); - } - Ok(threshold) - } - - pub async fn send( - &self, - key_a: ::PrivateKey, - key_b: ::PrivateKey, - input: BlockHash, - destination: Account, - value: u128, - ) -> anyhow::Result<()> { - let total_key = key_a + key_b; - let account = Account((&total_key * &curve25519_dalek::constants::ED25519_BASEPOINT_TABLE).compress().to_bytes()); - debug!("Creating Nano send for shared address {}", account); - let open_inner = BlockInner::State { - account: account.clone(), - previous: BlockHash::default(), - representative: Account([0u8; 32]), - balance: value, - link: input.0, - }; - let open = Self::complete_block(open_inner, total_key, self.get_work_threshold(true).await?); - self.publish(&open, "open").await?; - let send_inner = BlockInner::State { - account, - previous: open.get_hash(), - representative: Account([0u8; 32]), - balance: 0, - link: destination.0, - }; - let send = Self::complete_block(send_inner, total_key, self.get_work_threshold(false).await?); - self.publish(&send, "send").await?; - Ok(()) - } - - pub async fn get_confirmed_pending(&self, account: &str) -> anyhow::Result> { - #[derive(Serialize, Debug)] - struct PendingRequest<'a> { - action: &'a str, - account: &'a str, - source: &'a str, - include_only_confirmed: &'a str, - } - #[derive(Deserialize, Debug)] - struct PendingResponse { - #[serde(with = "nano_rpc_maybe_empty")] - blocks: HashMap, - } - #[derive(Deserialize, Debug, PartialEq)] - struct PendingBlock { - amount: String, - } - let request = PendingRequest { - action: "pending", - account, - source: "true", - include_only_confirmed: "true", - }; - let response: PendingResponse = self.rpc_call(&request).await?; - response.blocks.into_iter().map(|(hash_str, info)| { - let mut hash = BlockHash::default(); - hex::decode_to_slice(hash_str, &mut hash.0)?; - let amount = info.amount.parse()?; - Ok((hash, amount)) - }).collect() - } - - #[cfg(test)] - pub async fn send_from_node(&self, destination: &str, amount: u128) -> anyhow::Result { - #[derive(Serialize, Debug)] - struct SendRequest<'a> { - action: &'a str, - wallet: &'a str, - source: &'a str, - destination: &'a str, - amount: String, - } - #[derive(Deserialize, Debug)] - struct SendResponse { - block: String, - } - let request = SendRequest { - action: "send", - wallet: &self.config.wallet, - source: &self.config.wallet_account, - destination, - amount: amount.to_string(), - }; - let resp: SendResponse = self.rpc_call(&request).await?; - let mut hash = BlockHash::default(); - hex::decode_to_slice(resp.block, &mut hash.0)?; - Ok(hash) - } -} diff --git a/src/coins/nano/mod.rs b/src/coins/nano/mod.rs deleted file mode 100644 index 6263c84..0000000 --- a/src/coins/nano/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(not(test))] -mod engine; -#[cfg(test)] -pub mod engine; - -pub mod client; -pub mod verifier; diff --git a/src/coins/nano/verifier.rs b/src/coins/nano/verifier.rs deleted file mode 100644 index 1a6e49c..0000000 --- a/src/coins/nano/verifier.rs +++ /dev/null @@ -1,104 +0,0 @@ -use std::{ - marker::PhantomData, - io::Write, - path::Path, - fs::File, -}; - -use async_trait::async_trait; -use nanocurrency_types::{Account, BlockHash}; - -use crate::{ - crypt_engines::{CryptEngine, ed25519_engine::Ed25519Blake2b}, - dl_eq::DlEqProof, - coins::{ - UnscriptedVerifier, ScriptedHost, - nano::engine::{NanoConfig, NanoEngine}, - }, -}; - -pub struct NanoVerifier { - engine: NanoEngine, - destination_key: Account, - - shared_key: Option<::PublicKey>, - input: Option<(BlockHash, u128)>, -} - -impl NanoVerifier { - pub fn new(config_path: &Path) -> anyhow::Result { - let config: NanoConfig = serde_json::from_reader(File::open(config_path)?)?; - - Ok(NanoVerifier { - destination_key: config.destination.parse() - .map_err(|e| anyhow::anyhow!("Error parsing Nano address: {}", e))?, - engine: NanoEngine::new(config), - - shared_key: None, - input: None, - }) - } -} - -#[async_trait] -impl UnscriptedVerifier for NanoVerifier { - fn generate_keys_for_engine(&mut self, _: PhantomData<&OtherCrypt>) -> (Vec, OtherCrypt::PrivateKey) { - let (proof, key1, key2) = DlEqProof::::new(); - self.engine.k = Some(key1); - self.shared_key = Some(Ed25519Blake2b::to_public_key(&key1)); - (proof.serialize(), key2) - } - - fn verify_dleq_for_engine(&mut self, dleq: &[u8], _: PhantomData<&OtherCrypt>) -> anyhow::Result { - let dleq = DlEqProof::::deserialize(dleq)?; - let (key1, key2) = dleq.verify()?; - self.shared_key = Some(self.shared_key.expect("Verifying DLEQ proof before generating keys") + key2); - Ok(key1) - } - - async fn verify_and_wait_for_send(&mut self) -> anyhow::Result<()> { - let shared_key = self.shared_key.as_ref().expect("Waiting for send before verifying the other's DLEQ proof"); - let address = Account(shared_key.compress().to_bytes()).to_string(); - - /* - Considering Nano transactions are directly to public keys, there's not actually anything to verify - There's no timelocks or alternate spending paths - The node will only track the transaction if it's viable, including having a valid signature - */ - - while self.input.is_none() { - let mut inputs = self.engine.get_confirmed_pending(&address).await?; - inputs.truncate(1); - self.input = inputs.pop(); - - // Don't immediately run the next loop iteration - if self.input.is_none() { - tokio::time::delay_for(std::time::Duration::from_secs(5)).await; - } - } - - if !cfg!(test) { - let amount = self.input.as_ref().unwrap().1 as f64 / 1e30; - print!("You will receive {:.2} Nano. Continue (yes/no)? ", amount); - std::io::stdout().flush().expect("Failed to flush stdout"); - let mut line = String::new(); - std::io::stdin().read_line(&mut line).expect("Couldn't read from stdin"); - if !line.to_lowercase().starts_with("y") { - anyhow::bail!("User didn't confirm Nano amount"); - } - } - Ok(()) - } - - async fn finish(&mut self, host: &Host) -> anyhow::Result<()> { - let input = self.input.clone().expect("Finishing before knowing of the UTXOs"); - self.engine.send( - Ed25519Blake2b::little_endian_bytes_to_private_key(host.recover_final_key().await?)?, - self.engine.k.expect("Finishing before generating keys"), - input.0, - self.destination_key.clone(), - input.1, - ).await?; - Ok(()) - } -} diff --git a/src/coins/xmr/engine.rs b/src/coins/xmr/engine.rs index f1c48b5..f3b285a 100644 --- a/src/coins/xmr/engine.rs +++ b/src/coins/xmr/engine.rs @@ -249,7 +249,7 @@ impl XmrEngine { .await? .expect("Couldn't get transaction included in block"); - let outputs = result.0.prefix.check_outputs(pair, 0..1, 0..1); + let outputs = result.0.check_outputs(pair, 0..1, 0..1); if outputs.is_err() || (outputs.unwrap().len() == 0) { continue; } diff --git a/src/coins/xmr/verifier.rs b/src/coins/xmr/verifier.rs index 8179c98..27d7ebf 100644 --- a/src/coins/xmr/verifier.rs +++ b/src/coins/xmr/verifier.rs @@ -78,18 +78,18 @@ impl UnscriptedVerifier for XmrVerifier { anyhow::bail!("Invalid version/unlock time"); } - let outputs = send.prefix.check_outputs(&pair, 0..1, 0..1).unwrap(); + let outputs = send.check_outputs(&pair, 0..1, 0..1).unwrap(); // Decrypt the amount, verify the accuracy of the commitment, and confirm with the user let enc_amount; - if let EcdhInfo::Bulletproof { amount } = send.rct_signatures.sig.as_ref().expect("Transaction from RPC didn't have signature data").ecdh_info[outputs[0].index] { + if let EcdhInfo::Bulletproof { amount } = send.rct_signatures.sig.as_ref().expect("Transaction from RPC didn't have signature data").ecdh_info[outputs[0].index()] { enc_amount = u64::from_le_bytes(amount.to_fixed_bytes()); } else { anyhow::bail!("Unrecognized transaction type"); } let mut amount_key; - if let Some(uncompressed) = outputs[0].tx_pubkey.point.decompress() { + if let Some(uncompressed) = outputs[0].tx_pubkey().point.decompress() { amount_key = self.0.view * uncompressed; } else { anyhow::bail!("Invalid key used in transaction"); @@ -97,31 +97,32 @@ impl UnscriptedVerifier for XmrVerifier { amount_key = amount_key.mul_by_cofactor(); let mut to_hash = amount_key.compress().to_bytes().to_vec(); // TODO: Handle this edge case - if outputs[0].index > 127 { + // It isn't immediately necessary due to the 16 output limit currently present + if outputs[0].index() > 127 { anyhow::bail!("Transaction output uses VarInt encoding which isn't supported") } - to_hash.push(outputs[0].index as u8); + to_hash.push(outputs[0].index() as u8); let amount_key = Scalar::from_bytes_mod_order( - Hash::hash(&to_hash).to_bytes() + Hash::new(&to_hash).to_bytes() ).to_bytes(); let mut amount_enc_key = "amount".as_bytes().to_vec(); amount_enc_key.extend(&amount_key); let amount = u64::from_le_bytes( - Hash::hash(&amount_enc_key).to_fixed_bytes()[0 .. 8].try_into().unwrap() + Hash::new(&amount_enc_key).to_fixed_bytes()[0 .. 8].try_into().unwrap() ) ^ enc_amount; let mut commitment_key = "commitment_mask".as_bytes().to_vec(); commitment_key.extend(&amount_key); let commitment_key = Scalar::from_bytes_mod_order( - Hash::hash(&commitment_key).to_fixed_bytes() + Hash::new(&commitment_key).to_fixed_bytes() ); if ( Ed25519Sha::to_public_key(&commitment_key) + (*C * Scalar::from(amount)) ) != Ed25519Sha::bytes_to_public_key( - &send.rct_signatures.sig.as_ref().unwrap().out_pk[outputs[0].index].mask.key + &send.rct_signatures.sig.as_ref().unwrap().out_pk[outputs[0].index()].mask.key )? { anyhow::bail!("Invalid commitment") } diff --git a/src/coins/zec/client.rs b/src/coins/zec/client.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/crypt_engines/ed25519_engine.rs b/src/crypt_engines/ed25519_engine.rs index 549a6fa..109ed8b 100644 --- a/src/crypt_engines/ed25519_engine.rs +++ b/src/crypt_engines/ed25519_engine.rs @@ -5,7 +5,7 @@ use hex_literal::hex; use log::{debug, trace, warn}; -use rand::rngs::OsRng; +use rand_8::rngs::OsRng; use digest::{Digest, generic_array::typenum::U64}; use curve25519_dalek::{ @@ -52,7 +52,7 @@ impl> CryptEngine for Ed25519Engine { Scalar::random(&mut OsRng) } fn to_public_key(key: &Self::PrivateKey) -> Self::PublicKey { - key * &ED25519_BASEPOINT_TABLE + key * ED25519_BASEPOINT_TABLE } fn bytes_to_private_key(bytes: [u8; 32]) -> anyhow::Result { @@ -68,7 +68,7 @@ impl> CryptEngine for Ed25519Engine { let mut scalar_bytes = [0; 32]; scalar_bytes.copy_from_slice(&bytes[32..]); #[allow(non_snake_case)] - let R = CompressedEdwardsY::from_slice(&bytes[..32]).decompress().ok_or(anyhow::anyhow!("Invalid point in signature specified"))?; + let R = CompressedEdwardsY::from_slice(&bytes[..32])?.decompress().ok_or(anyhow::anyhow!("Invalid point in signature specified"))?; Ok(Signature { s: Scalar::from_bytes_mod_order(scalar_bytes), R: R @@ -83,8 +83,8 @@ impl> CryptEngine for Ed25519Engine { fn dl_eq_generate_commitments(key: [u8; 32]) -> anyhow::Result>> { let mut commitments = Vec::new(); - let mut blinding_key_total = Scalar::zero(); - let mut power_of_two = Scalar::one(); + let mut blinding_key_total = Scalar::ZERO; + let mut power_of_two = Scalar::ONE; let two = Scalar::from(2u8); for i in 0..SHARED_KEY_BITS { let blinding_key = if i == SHARED_KEY_BITS - 1 { @@ -106,8 +106,8 @@ impl> CryptEngine for Ed25519Engine { commitment, }); } - debug_assert_eq!(blinding_key_total, Scalar::zero()); - let pubkey = &Scalar::from_bytes_mod_order(key) * &ED25519_BASEPOINT_TABLE; + debug_assert_eq!(blinding_key_total, Scalar::ZERO); + let pubkey = &Scalar::from_bytes_mod_order(key) * ED25519_BASEPOINT_TABLE; debug_assert_eq!( &Self::dl_eq_reconstruct_key(commitments.iter().map(|c| &c.commitment))?, &pubkey @@ -125,7 +125,7 @@ impl> CryptEngine for Ed25519Engine { Ok(commitment - ED25519_BASEPOINT_POINT) } fn dl_eq_reconstruct_key<'a>(commitments: impl Iterator) -> anyhow::Result { - let mut power_of_two = Scalar::one(); + let mut power_of_two = Scalar::ONE; let mut res = EdwardsPoint::identity(); let two = Scalar::from(2u8); for comm in commitments { @@ -162,8 +162,8 @@ impl> CryptEngine for Ed25519Engine { #[allow(non_snake_case)] fn sign(key: &Self::PrivateKey, message: &[u8]) -> anyhow::Result { let r = Scalar::random(&mut OsRng); - let R = &r * &ED25519_BASEPOINT_TABLE; - let A = key * &ED25519_BASEPOINT_TABLE; + let R = &r * ED25519_BASEPOINT_TABLE; + let A = key * ED25519_BASEPOINT_TABLE; let mut hram = [0u8; 64]; let hash = D::new() .chain(&R.compress().as_bytes()) @@ -188,7 +188,7 @@ impl> CryptEngine for Ed25519Engine { .finalize(); hram.copy_from_slice(&hash); let c = Scalar::from_bytes_mod_order_wide(&hram); - let expected_R = &signature.s * &ED25519_BASEPOINT_TABLE - c * public_key; + let expected_R = &signature.s * ED25519_BASEPOINT_TABLE - c * public_key; if expected_R == signature.R { Ok(()) } else { @@ -202,9 +202,9 @@ impl> CryptEngine for Ed25519Engine { message: &[u8] ) -> anyhow::Result { let nonce = Scalar::random(&mut OsRng); - let pub_nonce = &nonce * &ED25519_BASEPOINT_TABLE; + let pub_nonce = &nonce * ED25519_BASEPOINT_TABLE; let challenge_nonce = &pub_nonce + encryption_key; - let pub_signing_key = signing_key * &ED25519_BASEPOINT_TABLE; + let pub_signing_key = signing_key * ED25519_BASEPOINT_TABLE; let mut hram = [0u8; 64]; let hash = D::new() .chain(challenge_nonce.compress().as_bytes()) @@ -256,7 +256,7 @@ impl> CryptEngine for Ed25519Engine { let challenge = Scalar::from_bytes_mod_order_wide(&hram); #[allow(non_snake_case)] let expected_sB = ciphertext.R + challenge * signing_key; - if expected_sB != &ciphertext.s * &ED25519_BASEPOINT_TABLE { + if expected_sB != &ciphertext.s * ED25519_BASEPOINT_TABLE { anyhow::bail!("Invalid encrypted signature"); } Ok(()) @@ -265,11 +265,11 @@ impl> CryptEngine for Ed25519Engine { // update s and R to match challenge_nonce let sig = Signature { s: sig.s + key, - R: sig.R + key * &ED25519_BASEPOINT_TABLE, + R: sig.R + key * ED25519_BASEPOINT_TABLE, }; trace!( "Decrypting signature with encryption pubkey {}: {} -> {}", - hex::encode((key * &ED25519_BASEPOINT_TABLE).compress().as_bytes()), + hex::encode((key * ED25519_BASEPOINT_TABLE).compress().as_bytes()), hex::encode(Self::encrypted_signature_to_bytes(&sig)), hex::encode(Self::signature_to_bytes(&sig)) ); @@ -291,7 +291,7 @@ impl> CryptEngine for Ed25519Engine { } } let key = sig.s - ciphertext.s; - if &(&key * &ED25519_BASEPOINT_TABLE) != expected_key { + if &(&key * ED25519_BASEPOINT_TABLE) != expected_key { anyhow::bail!("Recovered VES key didn't match expected key"); } Ok(key) diff --git a/src/main.rs b/src/main.rs index cd9979d..6249c30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,6 @@ use crate::{ coins::{ *, btc::{host::BtcHost, verifier::BtcVerifier}, - nano::{client::NanoClient, verifier::NanoVerifier}, xmr::{client::XmrClient, verifier::XmrVerifier}, }, cli::{ScriptedCoin, UnscriptedCoin, Cli} @@ -52,7 +51,6 @@ async fn main() { ScriptedCoin::Litecoin => BtcHost::new(&scripted_config).map(Into::into), }.expect("Failed to create scripted host"); let mut unscripted_verifier: AnyUnscriptedVerifier = match opts.pair.unscripted { - UnscriptedCoin::Nano => NanoVerifier::new(&unscripted_config).map(Into::into), UnscriptedCoin::Monero => XmrVerifier::new(&unscripted_config).await.map(Into::into), }.expect("Failed to create unscripted verifier"); @@ -99,7 +97,6 @@ async fn main() { if opts.host_or_client.is_client() { let mut unscripted_client: AnyUnscriptedClient = match opts.pair.unscripted { - UnscriptedCoin::Nano => NanoClient::new(&unscripted_config).map(Into::into), UnscriptedCoin::Monero => XmrClient::new(&unscripted_config).await.map(Into::into), }.expect("Failed to create unscripted client"); let mut scripted_verifier: AnyScriptedVerifier = match opts.pair.scripted { diff --git a/src/tests/coin_specific/mod.rs b/src/tests/coin_specific/mod.rs deleted file mode 100644 index 95ecf78..0000000 --- a/src/tests/coin_specific/mod.rs +++ /dev/null @@ -1 +0,0 @@ -mod nano; diff --git a/src/tests/coin_specific/nano.rs b/src/tests/coin_specific/nano.rs deleted file mode 100644 index 535ed47..0000000 --- a/src/tests/coin_specific/nano.rs +++ /dev/null @@ -1,24 +0,0 @@ -use serde::Deserialize; - -use crate::coins::nano::engine::nano_rpc_maybe_empty; - -#[test] -fn empty_string_response() { - #[derive(Deserialize, PartialEq, Debug)] - struct PendingResponse { - #[serde(with = "nano_rpc_maybe_empty")] - blocks: Vec, - } - - const TEST_CASES: &[(&str, &[&str])]= &[ - (r#"{"blocks": ""}"#, &[]), - (r#"{"blocks": []}"#, &[]), - (r#"{"blocks": ["foo"]}"#, &["foo"]), - (r#"{"blocks": ["foo", "bar"]}"#, &["foo", "bar"]), - ]; - - for (s, expected) in TEST_CASES { - let result: PendingResponse = serde_json::from_str(s).unwrap(); - assert_eq!(&result.blocks, expected); - } -} diff --git a/src/tests/ltc_and_nano.rs b/src/tests/ltc_and_nano.rs deleted file mode 100644 index 526ff32..0000000 --- a/src/tests/ltc_and_nano.rs +++ /dev/null @@ -1,79 +0,0 @@ -use std::{ - path::PathBuf, - future::Future, - time::Duration -}; - -use tokio::time::delay_for; - -use crate::{ - coins::{ - *, - btc::{host::BtcHost, verifier::BtcVerifier}, - nano::{client::NanoClient, verifier::NanoVerifier} - }, - tests::swap::{ - success::test_success, - host::{ - no_address::test_no_host_address, - never_funded_address::test_never_funded_address, - funded_address_no_lock::test_funded_address_no_lock, - funded_address_created_lock::test_funded_address_created_lock, - published_lock::test_published_lock, - attempted_refund_yet_success::test_attempted_refund_yet_success - }, - client::{ - no_address::test_no_client_address, - generated_address::test_generated_address, - funded_get_unscripted::test_funded_get_unscripted, - funded_get_scripted::test_funded_get_scripted - } - } -}; - -pub async fn run_test(host_test: bool, test: F) - where F: FnOnce(AnyScriptedHost, AnyUnscriptedVerifier, AnyUnscriptedClient, AnyScriptedVerifier) -> Fut, - Fut: Future> -{ - let scripted: PathBuf = "config/litecoin.json".to_string().into(); - let unscripted: PathBuf = "config/nano.json".to_string().into(); - - let mut host: AnyScriptedHost = BtcHost::new(&scripted).expect("Failed to create BTC host").into(); - host.override_refund_with_random_address(); - let host_refund = host.get_refund_address(); - let hosts_verifier: AnyUnscriptedVerifier = NanoVerifier::new(&unscripted).expect("Failed to create Nano verifier").into(); - - let mut client: AnyUnscriptedClient = NanoClient::new(&unscripted).expect("Failed to create Nano client").into(); - client.override_refund_with_random_address(); - let client_refund = client.get_refund_address(); - let clients_verifier: AnyScriptedVerifier = BtcVerifier::new(&scripted).expect("Failed to create BTC verifier").into(); - - let should_have_funds = test(host, hosts_verifier, client, clients_verifier).await.unwrap(); - if host_test { - let host = BtcHost::new(&scripted).unwrap(); - host.advance_consensus().await.unwrap(); - assert_eq!(should_have_funds, host.get_if_funded(&host_refund).await); - } else { - let client = NanoClient::new(&unscripted).unwrap(); - delay_for(Duration::from_secs(5)).await; // wait for the transaction to be confirmed - assert_eq!(should_have_funds, client.get_if_funded(&client_refund).await); - } -} - -#[tokio::test] -pub async fn test_ltc_and_nano() { - let _ = env_logger::builder().is_test(true).try_init(); - run_test(true, test_success).await; - - run_test(true, test_no_host_address).await; - run_test(true, test_never_funded_address).await; - run_test(true, test_funded_address_no_lock).await; - run_test(true, test_funded_address_created_lock).await; - run_test(true, test_published_lock).await; - run_test(true, test_attempted_refund_yet_success).await; - - run_test(false, test_no_client_address).await; - run_test(false, test_generated_address).await; - run_test(false, test_funded_get_unscripted).await; - run_test(false, test_funded_get_scripted).await; -} diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 1bd2da9..bc3d80a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -2,11 +2,8 @@ mod dl_eq; mod secp_dl_eq; mod ves; mod serialization; -mod coin_specific; #[cfg_attr(not(feature = "test_litecoin_node"), allow(dead_code))] mod swap; -#[cfg(all(feature = "test_litecoin_node", feature = "test_nano_node"))] -mod ltc_and_nano; #[cfg(all(feature = "test_litecoin_node", feature = "test_monero_node"))] mod ltc_and_xmr;