From 5841cde180c80a1cd6f23091b2750cc6db545dc8 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 11 Nov 2022 15:50:04 +0000 Subject: [PATCH 01/20] first commit --- Cargo.lock | 641 +++++++++++++--------- base_layer/key_manager/Cargo.toml | 2 +- base_layer/key_manager/src/cipher_seed.rs | 25 +- base_layer/key_manager/src/key_manager.rs | 45 +- base_layer/key_manager/src/lib.rs | 3 + base_layer/key_manager/src/mnemonic.rs | 8 +- base_layer/wallet/src/wallet.rs | 8 +- 7 files changed, 446 insertions(+), 286 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b7c9c5bf6..ad0d8572bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -80,7 +80,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "once_cell", "version_check 0.9.4", ] @@ -114,9 +114,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.65" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" [[package]] name = "arc-swap" @@ -141,15 +141,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" -[[package]] -name = "arrayvec" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" -dependencies = [ - "nodrop", -] - [[package]] name = "arrayvec" version = "0.7.2" @@ -179,9 +170,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.57" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" +checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c" dependencies = [ "proc-macro2", "quote", @@ -258,9 +249,9 @@ checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64-compat" @@ -273,9 +264,9 @@ dependencies = [ [[package]] name = "base64ct" -version = "1.5.2" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2b2456fd614d856680dcd9fcc660a51a820fa09daef2e49772b56a193c8474" +checksum = "b645a089122eccb6111b4f81cbc1a49f5900ac4666bb93ac027feaecf15607bf" [[package]] name = "bigdecimal" @@ -451,15 +442,15 @@ checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8" [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "bytemuck" -version = "1.12.1" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f5715e491b5a1598fc2bef5a606847b5dc1d48ea625bd3c02c00de8285591da" +checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f" [[package]] name = "byteorder" @@ -539,7 +530,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" dependencies = [ - "clap 3.2.22", + "clap 3.2.23", "heck 0.4.0", "indexmap", "log", @@ -554,9 +545,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" [[package]] name = "cexpr" @@ -708,9 +699,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.22" +version = "3.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" dependencies = [ "atty", "bitflags 1.3.2", @@ -720,7 +711,7 @@ dependencies = [ "once_cell", "strsim 0.10.0", "termcolor", - "textwrap 0.15.1", + "textwrap 0.16.0", ] [[package]] @@ -747,9 +738,9 @@ dependencies = [ [[package]] name = "clear_on_drop" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9cc5db465b294c3fa986d5bbb0f3017cd850bff6dd6c52f9ccff8b4d21b7b08" +checksum = "38508a63f4979f0048febc9966fadbd48e5dab31fd0ec6a3f151bbf4a74f7423" dependencies = [ "cc", ] @@ -774,6 +765,16 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -1053,7 +1054,7 @@ dependencies = [ "crossterm_winapi 0.9.0", "futures-core", "libc", - "mio 0.8.4", + "mio 0.8.5", "parking_lot 0.12.1", "signal-hook", "signal-hook-mio", @@ -1069,7 +1070,7 @@ dependencies = [ "bitflags 1.3.2", "crossterm_winapi 0.9.0", "libc", - "mio 0.8.4", + "mio 0.8.5", "parking_lot 0.12.1", "signal-hook", "signal-hook-mio", @@ -1153,9 +1154,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.56+curl-7.83.1" +version = "0.4.59+curl-7.86.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6093e169dd4de29e468fa649fbae11cdcd5551c81fe5bf1b0677adad7ef3d26f" +checksum = "6cfce34829f448b08f55b7db6d0009e23e2e86a34e8c2b366269bf5799b4a407" dependencies = [ "cc", "libc", @@ -1194,6 +1195,50 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cxx" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97abf9f0eca9e52b7f81b945524e76710e6cb2366aead23b7d4fbf72e281f888" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cc32cc5fea1d894b77d269ddb9f192110069a8a9c1f1d441195fba90553dea3" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca220e4794c934dc6b1207c3b42856ad4c302f2df1712e9f8d2eec5afaacf1f" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b846f081361125bfc8dc9d3940c84e1fd83ba54bbca7b17cd29483c828be0704" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "darling" version = "0.10.2" @@ -1237,9 +1282,9 @@ checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" [[package]] name = "decimal-rs" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2492291a982ad198a2c3b84b091b48348372ffe8a9f7194cc90a2d8b901762c" +checksum = "5653f2734c2c9603718347b1f29ee0acc26855282574203b5128e993fa7a001e" dependencies = [ "ethnum", "fast-float", @@ -1539,13 +1584,13 @@ dependencies = [ [[package]] name = "fd-lock" -version = "3.0.6" +version = "3.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11dcc7e4d79a8c89b9ab4c6f5c30b1fc4a83c420792da3542fd31179ed5f517" +checksum = "bb21c69b9fea5e15dbc1049e4b77145dd0ba1c84019c488102de0dc4ea4b0a27" dependencies = [ "cfg-if 1.0.0", "rustix", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1642,9 +1687,9 @@ checksum = "3a471a38ef8ed83cd6e40aa59c1ffe17db6855c18e3604d9c4ed8c08ebc28678" [[package]] name = "futures" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" dependencies = [ "futures-channel", "futures-core", @@ -1657,9 +1702,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", "futures-sink", @@ -1667,15 +1712,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-executor" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" +checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" dependencies = [ "futures-core", "futures-task", @@ -1684,15 +1729,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-macro" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" dependencies = [ "proc-macro2", "quote", @@ -1701,21 +1746,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" [[package]] name = "futures-test" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee87d68bf5bca8a0270f477fa1ceab0fbdf735fa21ea17e617ed5381b634fa4" +checksum = "8b57590ad76d93051b7024d7cca00ada0d6521f6e71ecef9516141ebefcb9998" dependencies = [ "futures-core", "futures-executor", @@ -1730,9 +1775,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures 0.1.31", "futures-channel", @@ -1772,9 +1817,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -1816,9 +1861,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ "bytes 1.2.1", "fnv", @@ -1864,7 +1909,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bitflags 1.3.2", "bytes 1.2.1", "headers-core", @@ -1927,7 +1972,7 @@ checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes 1.2.1", "fnv", - "itoa 1.0.3", + "itoa 1.0.4", ] [[package]] @@ -1970,9 +2015,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.20" +version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ "bytes 1.2.1", "futures-channel", @@ -1983,7 +2028,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa 1.0.3", + "itoa 1.0.4", "pin-project-lite", "socket2", "tokio", @@ -2019,17 +2064,28 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.50" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", + "iana-time-zone-haiku", "js-sys", "wasm-bindgen", "winapi", ] +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +dependencies = [ + "cxx", + "cxx-build", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2115,15 +2171,19 @@ checksum = "8bb03732005da905c88227371639bf1ad885cc712789c011c31c5fb3ab3ccf02" [[package]] name = "io-lifetimes" -version = "0.7.3" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06" +checksum = "a7d367024b3f3414d8e01f437f704f41a9f64ab36f9067fa73e526ad4c763c87" +dependencies = [ + "libc", + "windows-sys 0.42.0", +] [[package]] name = "ipnet" -version = "2.5.0" +version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" +checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" [[package]] name = "itertools" @@ -2151,9 +2211,9 @@ checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] name = "itoa" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" @@ -2221,9 +2281,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.134" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "libgit2-sys" @@ -2251,9 +2311,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if 1.0.0", "winapi", @@ -2267,9 +2327,9 @@ checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" [[package]] name = "libm" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "libsqlite3-sys" @@ -2345,6 +2405,15 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -2353,9 +2422,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.0.46" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" +checksum = "bb68f22743a3fb35785f1e7f844ca5a3de2dde5bd0c0ef5b372065814699b121" [[package]] name = "lmdb-zero" @@ -2553,14 +2622,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2620,9 +2689,9 @@ dependencies = [ [[package]] name = "multihash-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" +checksum = "1d6d4752e6230d8ef7adf7bd5d8c4b1f6561c1014c5ba9a37445ccefe18aa1db" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -2640,9 +2709,9 @@ checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" [[package]] name = "native-tls" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", @@ -2684,12 +2753,6 @@ dependencies = [ "memoffset", ] -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - [[package]] name = "nohash-hasher" version = "0.2.0" @@ -2755,7 +2818,7 @@ dependencies = [ "autocfg 0.1.8", "byteorder", "lazy_static", - "libm 0.2.5", + "libm 0.2.6", "num-integer", "num-iter", "num-traits", @@ -2778,12 +2841,12 @@ dependencies = [ [[package]] name = "num-format" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bafe4179722c2894288ee77a9f044f02811c86af699344c498b0840c698a2465" +checksum = "54b862ff8df690cf089058c98b183676a7ed0f974cc08b426800093227cbff3b" dependencies = [ - "arrayvec 0.4.12", - "itoa 0.4.8", + "arrayvec", + "itoa 1.0.4", ] [[package]] @@ -2829,28 +2892,19 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", ] -[[package]] -name = "num_threads" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" -dependencies = [ - "libc", -] - [[package]] name = "once_cell" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "oorandom" @@ -2898,18 +2952,18 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "111.22.0+1.1.1q" +version = "111.24.0+1.1.1s" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f31f0d509d1c1ae9cada2f9539ff8f37933831fd5098879e482aa687d659853" +checksum = "3498f259dab01178c6228c6b00dcef0ed2a2d5e20d648c017861227773ea4abd" dependencies = [ "cc", ] [[package]] name = "openssl-sys" -version = "0.9.76" +version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ "autocfg 1.1.0", "cc", @@ -2927,7 +2981,7 @@ checksum = "e1cf9b1c4e9a6c4de793c632496fa490bdc0e1eea73f0c91394f7b6990935d22" dependencies = [ "async-trait", "crossbeam-channel", - "futures 0.3.24", + "futures 0.3.25", "js-sys", "lazy_static", "percent-encoding 2.2.0", @@ -3010,9 +3064,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.3.0" +version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" [[package]] name = "packed_simd_2" @@ -3042,7 +3096,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.3", + "parking_lot_core 0.9.4", ] [[package]] @@ -3061,15 +3115,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if 1.0.0", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -3107,7 +3161,7 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "once_cell", "regex", ] @@ -3126,9 +3180,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbc7bc69c062e492337d74d59b120c274fd3d261b6bf6d3207d499b4b379c41a" +checksum = "a528564cc62c19a7acac4d81e01f39e53e25e17b934878f4c6d25cc2836e62f8" dependencies = [ "thiserror", "ucd-trie", @@ -3136,9 +3190,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b75706b9642ebcb34dab3bc7750f811609a0eb1dd8b88c2d15bf628c1c65b2" +checksum = "d5fd9bc6500181952d34bd0b2b0163a54d794227b498be0b7afa7698d0a7b18f" dependencies = [ "pest", "pest_generator", @@ -3146,9 +3200,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f9272122f5979a6511a749af9db9bfc810393f63119970d7085fed1c4ea0db" +checksum = "d2610d5ac5156217b4ff8e46ddcef7cdf44b273da2ac5bca2ecbfa86a330e7c4" dependencies = [ "pest", "pest_meta", @@ -3159,9 +3213,9 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8717927f9b79515e565a64fe46c38b8cd0427e64c40680b14a7365ab09ac8d" +checksum = "824749bf7e21dd66b36fbe26b3f45c713879cccd4a009a917ab8e045ca8246fe" dependencies = [ "once_cell", "pest", @@ -3292,9 +3346,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "plotters" @@ -3349,17 +3403,16 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "e17d47ce914bf4de440332250b0edd23ce48c005f59fab39d3335866b114f11a" dependencies = [ - "once_cell", "thiserror", "toml", ] @@ -3390,18 +3443,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.46" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] [[package]] name = "prometheus" -version = "0.13.2" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45c8babc29389186697fe5a2a4859d697825496b83db5d0b65271cdc0488e88c" +checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" dependencies = [ "cfg-if 1.0.0", "fnv", @@ -3591,7 +3644,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", ] [[package]] @@ -3685,16 +3738,16 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.7", + "getrandom 0.2.8", "redox_syscall", "thiserror", ] [[package]] name = "regex" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" dependencies = [ "aho-corasick", "memchr", @@ -3712,9 +3765,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.27" +version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" [[package]] name = "remove_dir_all" @@ -3731,7 +3784,7 @@ version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bytes 1.2.1", "encoding_rs", "futures-core", @@ -3794,7 +3847,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bitflags 1.3.2", "serde", ] @@ -3864,23 +3917,23 @@ dependencies = [ [[package]] name = "rustix" -version = "0.35.11" +version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbb2fda4666def1433b1b05431ab402e42a1084285477222b72d6c564c417cef" +checksum = "812a2ec2043c4d6bc6482f5be2ab8244613cac2493d128d36c0759e52a626ab3" dependencies = [ "bitflags 1.3.2", "errno", "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "rustls" -version = "0.20.6" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aab8ee6c7097ed6057f43c187a62418d0c05a4bd5f18b3571db50ee0f9ce033" +checksum = "539a2bfe908f471bfa933876bd1eb6a19cf2176d375f82ef7f99530a40e48c2c" dependencies = [ "log", "ring", @@ -3894,7 +3947,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", ] [[package]] @@ -3903,7 +3956,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", ] [[package]] @@ -3968,7 +4021,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -3982,9 +4035,9 @@ dependencies = [ [[package]] name = "scoped-tls" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "scopeguard" @@ -3992,6 +4045,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + [[package]] name = "sct" version = "0.7.0" @@ -4045,9 +4104,9 @@ checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.145" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] @@ -4083,9 +4142,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.145" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -4094,11 +4153,11 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ - "itoa 1.0.3", + "itoa 1.0.4", "ryu", "serde", ] @@ -4121,7 +4180,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa 1.0.3", + "itoa 1.0.4", "ryu", "serde", ] @@ -4237,7 +4296,7 @@ checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", "mio 0.7.14", - "mio 0.8.4", + "mio 0.8.5", "signal-hook", ] @@ -4252,9 +4311,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.3" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb766570a2825fa972bceff0d195727876a9cdf2460ab2e52d455dc2de47fd9" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "simple_asn1" @@ -4409,9 +4468,9 @@ checksum = "171758edb47aa306a78dfa4ab9aeb5167405bd4e3dc2b64e88f6a84bbe98bd63" [[package]] name = "syn" -version = "1.0.101" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -4435,7 +4494,7 @@ name = "tari_app_grpc" version = "0.38.8" dependencies = [ "argon2", - "base64 0.13.0", + "base64 0.13.1", "chrono", "digest 0.9.0", "log", @@ -4448,7 +4507,7 @@ dependencies = [ "tari_core", "tari_crypto", "tari_script", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", "tonic", "tonic-build", @@ -4459,10 +4518,10 @@ dependencies = [ name = "tari_app_utilities" version = "0.38.8" dependencies = [ - "clap 3.2.22", + "clap 3.2.23", "config", "dirs-next 1.0.2", - "futures 0.3.24", + "futures 0.3.25", "json5 0.2.8", "log", "rand 0.7.3", @@ -4472,7 +4531,7 @@ dependencies = [ "tari_common_types", "tari_comms", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", "tokio", ] @@ -4485,12 +4544,12 @@ dependencies = [ "async-trait", "bincode", "chrono", - "clap 3.2.22", + "clap 3.2.23", "config", "crossterm 0.23.2", "derive_more", "either", - "futures 0.3.24", + "futures 0.3.25", "log", "log-mdc", "nom 7.1.1", @@ -4520,7 +4579,7 @@ dependencies = [ "tari_service_framework", "tari_shutdown", "tari_storage", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", "tokio", "tonic", @@ -4619,13 +4678,13 @@ dependencies = [ name = "tari_common_types" version = "0.38.8" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "digest 0.9.0", "lazy_static", "rand 0.7.3", "serde", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", "tokio", "zeroize", @@ -4646,7 +4705,7 @@ dependencies = [ "derivative", "digest 0.9.0", "env_logger", - "futures 0.3.24", + "futures 0.3.25", "lazy_static", "lmdb-zero", "log", @@ -4669,7 +4728,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities", + "tari_utilities 0.4.7", "tempfile", "thiserror", "tokio", @@ -4695,7 +4754,7 @@ dependencies = [ "diesel_migrations", "digest 0.9.0", "env_logger", - "futures 0.3.24", + "futures 0.3.25", "futures-test", "futures-util", "lazy_static", @@ -4718,7 +4777,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities", + "tari_utilities 0.4.7", "tempfile", "thiserror", "tokio", @@ -4731,7 +4790,7 @@ dependencies = [ name = "tari_comms_rpc_macros" version = "0.38.8" dependencies = [ - "futures 0.3.24", + "futures 0.3.25", "proc-macro2", "prost", "quote", @@ -4746,14 +4805,14 @@ dependencies = [ name = "tari_console_wallet" version = "0.38.8" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bitflags 1.3.2", "chrono", - "clap 3.2.22", + "clap 3.2.23", "config", "crossterm 0.25.0", "digest 0.9.0", - "futures 0.3.24", + "futures 0.3.25", "log", "opentelemetry", "opentelemetry-jaeger", @@ -4779,7 +4838,7 @@ dependencies = [ "tari_libtor", "tari_p2p", "tari_shutdown", - "tari_utilities", + "tari_utilities 0.4.7", "tari_wallet", "thiserror", "tokio", @@ -4811,7 +4870,7 @@ dependencies = [ "digest 0.9.0", "env_logger", "fs2", - "futures 0.3.24", + "futures 0.3.25", "hex", "integer-encoding 3.0.4", "lmdb-zero", @@ -4846,7 +4905,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities", + "tari_utilities 0.4.7", "tempfile", "thiserror", "tokio", @@ -4865,7 +4924,7 @@ dependencies = [ "cbindgen 0.17.0", "curve25519-dalek 3.2.1", "digest 0.9.0", - "getrandom 0.2.7", + "getrandom 0.2.8", "lazy_static", "log", "merlin 2.0.1", @@ -4876,7 +4935,7 @@ dependencies = [ "sha3", "tari_bulletproofs", "tari_bulletproofs_plus", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", "wasm-bindgen", "zeroize", @@ -4887,14 +4946,14 @@ name = "tari_key_manager" version = "0.38.8" dependencies = [ "argon2", - "arrayvec 0.7.2", + "arrayvec", "blake2 0.9.2", "chacha20 0.7.3", "console_error_panic_hook", "crc32fast", "derivative", "digest 0.9.0", - "getrandom 0.2.7", + "getrandom 0.2.8", "js-sys", "rand 0.7.3", "serde", @@ -4906,7 +4965,7 @@ dependencies = [ "subtle", "tari_common_types", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.8", "thiserror", "wasm-bindgen", "wasm-bindgen-test", @@ -4938,11 +4997,11 @@ dependencies = [ "bincode", "bytes 1.2.1", "chrono", - "clap 3.2.22", + "clap 3.2.23", "config", "crossterm 0.25.0", "derivative", - "futures 0.3.24", + "futures 0.3.25", "hex", "hyper", "jsonrpc", @@ -4958,7 +5017,7 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "tari_wallet_grpc_client", "thiserror", "tokio", @@ -4972,7 +5031,7 @@ name = "tari_metrics" version = "0.1.0" dependencies = [ "anyhow", - "futures 0.3.24", + "futures 0.3.25", "log", "once_cell", "prometheus", @@ -4986,15 +5045,15 @@ dependencies = [ name = "tari_miner" version = "0.38.8" dependencies = [ - "base64 0.13.0", + "base64 0.13.1", "bufstream", "chrono", - "clap 3.2.22", + "clap 3.2.23", "config", "crossbeam", "crossterm 0.25.0", "derivative", - "futures 0.3.24", + "futures 0.3.25", "hex", "log", "native-tls", @@ -5012,7 +5071,7 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", "tokio", "tonic", @@ -5031,7 +5090,7 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", ] @@ -5050,7 +5109,7 @@ dependencies = [ "serde_json", "tari_common", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", ] @@ -5064,7 +5123,7 @@ dependencies = [ "clap 2.34.0", "config", "fs2", - "futures 0.3.24", + "futures 0.3.25", "lazy_static", "lmdb-zero", "log", @@ -5084,7 +5143,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities", + "tari_utilities 0.4.7", "tempfile", "thiserror", "tokio", @@ -5107,7 +5166,7 @@ dependencies = [ "sha2 0.9.9", "sha3", "tari_crypto", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", ] @@ -5117,7 +5176,7 @@ version = "0.38.8" dependencies = [ "anyhow", "async-trait", - "futures 0.3.24", + "futures 0.3.25", "futures-test", "log", "tari_shutdown", @@ -5132,7 +5191,7 @@ dependencies = [ name = "tari_shutdown" version = "0.38.8" dependencies = [ - "futures 0.3.24", + "futures 0.3.25", "tokio", ] @@ -5146,7 +5205,7 @@ dependencies = [ "rand 0.7.3", "serde", "serde_derive", - "tari_utilities", + "tari_utilities 0.4.7", "thiserror", ] @@ -5154,7 +5213,7 @@ dependencies = [ name = "tari_test_utils" version = "0.38.8" dependencies = [ - "futures 0.3.24", + "futures 0.3.25", "futures-test", "rand 0.7.3", "tari_shutdown", @@ -5168,7 +5227,22 @@ version = "0.4.7" source = "git+https://github.com/tari-project/tari_utilities.git?tag=v0.4.7#890a67140f56d9948ba64e8b0be981589875e75c" dependencies = [ "base58-monero 0.3.2", - "base64 0.13.0", + "base64 0.13.1", + "bincode", + "newtype-ops", + "serde", + "serde_json", + "thiserror", + "zeroize", +] + +[[package]] +name = "tari_utilities" +version = "0.4.8" +source = "git+https://github.com/AaronFeickert/tari_utilities.git?branch=clandestine#31cfd74d82ddf181f70bf94928f23437366bae82" +dependencies = [ + "base58-monero 0.3.2", + "base64 0.13.1", "bincode", "newtype-ops", "serde", @@ -5193,7 +5267,7 @@ dependencies = [ "digest 0.9.0", "env_logger", "fs2", - "futures 0.3.24", + "futures 0.3.25", "itertools 0.10.5", "libsqlite3-sys", "lmdb-zero", @@ -5220,7 +5294,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities", + "tari_utilities 0.4.7", "tempfile", "thiserror", "tokio", @@ -5234,7 +5308,7 @@ version = "0.38.8" dependencies = [ "cbindgen 0.24.3", "chrono", - "futures 0.3.24", + "futures 0.3.25", "itertools 0.10.5", "lazy_static", "libc", @@ -5256,7 +5330,7 @@ dependencies = [ "tari_service_framework", "tari_shutdown", "tari_test_utils", - "tari_utilities", + "tari_utilities 0.4.7", "tari_wallet", "tempfile", "thiserror", @@ -5308,9 +5382,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.1" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" @@ -5387,14 +5461,20 @@ dependencies = [ [[package]] name = "time" -version = "0.3.15" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" +checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376" dependencies = [ - "libc", - "num_threads", + "serde", + "time-core", ] +[[package]] +name = "time-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -5439,7 +5519,7 @@ dependencies = [ "bytes 1.2.1", "libc", "memchr", - "mio 0.8.4", + "mio 0.8.5", "num_cpus", "pin-project-lite", "signal-hook-registry", @@ -5492,9 +5572,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6edf2d6bc038a43d31353570e27270603f4648d18f5ed10c0e179abe43255af" +checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" dependencies = [ "futures-core", "pin-project-lite", @@ -5548,7 +5628,7 @@ checksum = "ff08f4649d10a70ffa3522ca559031285d8e421d727ac85c60825761818f5d0a" dependencies = [ "async-stream", "async-trait", - "base64 0.13.0", + "base64 0.13.1", "bytes 1.2.1", "futures-core", "futures-util", @@ -5619,9 +5699,9 @@ dependencies = [ [[package]] name = "tower-layer" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" +checksum = "c20c8dbed6283a09604c3e69b4b7eeb54e298b8a600d4d5ecb5ad39de609f1d0" [[package]] name = "tower-service" @@ -5631,9 +5711,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if 1.0.0", "log", @@ -5644,9 +5724,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", @@ -5655,9 +5735,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", "valuable", @@ -5746,7 +5826,7 @@ dependencies = [ "ring", "rustls", "thiserror", - "time 0.3.15", + "time 0.3.17", "tokio", "trust-dns-proto", "webpki 0.22.0", @@ -5871,9 +5951,9 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" @@ -6229,43 +6309,100 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winreg" version = "0.10.1" @@ -6301,7 +6438,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d9ba232399af1783a58d8eb26f6b5006fbefe2dc9ef36bd283324792d03ea5" dependencies = [ - "futures 0.3.24", + "futures 0.3.25", "log", "nohash-hasher", "parking_lot 0.12.1", diff --git a/base_layer/key_manager/Cargo.toml b/base_layer/key_manager/Cargo.toml index af873fab56..f470b78be3 100644 --- a/base_layer/key_manager/Cargo.toml +++ b/base_layer/key_manager/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["lib", "cdylib"] [dependencies] tari_common_types = { version = "^0.38", path = "../../base_layer/common_types", optional = true } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/AaronFeickert/tari_utilities.git", branch="clandestine" } arrayvec = "0.7.1" argon2 = { version = "0.4.1", features = ["std", "alloc"] } diff --git a/base_layer/key_manager/src/cipher_seed.rs b/base_layer/key_manager/src/cipher_seed.rs index 22f70b4116..22705ba56b 100644 --- a/base_layer/key_manager/src/cipher_seed.rs +++ b/base_layer/key_manager/src/cipher_seed.rs @@ -34,12 +34,14 @@ use rand::{rngs::OsRng, RngCore}; use serde::{Deserialize, Serialize}; use subtle::ConstantTimeEq; use tari_crypto::hash::blake2::Blake256; +use tari_utilities::hidden::Hidden; use zeroize::{Zeroize, Zeroizing}; use crate::{ error::KeyManagerError, mac_domain_hasher, mnemonic::{from_bytes, to_bytes, to_bytes_with_language, Mnemonic, MnemonicLanguage}, + KeyManagerHiddenType, LABEL_ARGON_ENCODING, LABEL_CHACHA20_ENCODING, LABEL_MAC_GENERATION, @@ -343,6 +345,7 @@ impl CipherSeed { } /// Use Argon2 to derive encryption and MAC keys from a passphrase and main salt + // TODO: passhphrase should be SafePassword fn derive_keys(passphrase: &str, salt: &[u8]) -> DerivedCipherSeedKeys { // The Argon2 salt is derived from the main salt let argon2_salt = mac_domain_hasher::(LABEL_ARGON_ENCODING) @@ -369,8 +372,8 @@ impl CipherSeed { .map_err(|_| KeyManagerError::CryptographicError("Problem generating Argon2 password hash".to_string()))?; // Split off the keys - let encryption_key = Zeroizing::new(main_key.as_ref()[..CIPHER_SEED_ENCRYPTION_KEY_BYTES].to_vec()); - let mac_key = Zeroizing::new(main_key.as_ref()[CIPHER_SEED_ENCRYPTION_KEY_BYTES..].to_vec()); + let encryption_key = Zeroizing::new(main_key.as_ref()[..CIPHER_SEED_ENCRYPTION_KEY_BYTES].to_vec()); // TODO + let mac_key = Zeroizing::new(main_key.as_ref()[CIPHER_SEED_ENCRYPTION_KEY_BYTES..].to_vec()); // TODO Ok((encryption_key, mac_key)) } } @@ -404,8 +407,11 @@ impl Mnemonic for CipherSeed { &self, language: MnemonicLanguage, passphrase: Option, - ) -> Result, KeyManagerError> { - Ok(from_bytes(&self.encipher(passphrase)?, language)?) + ) -> Result, KeyManagerHiddenType>, KeyManagerError> { + Ok(Hidden::, KeyManagerHiddenType>::hide(from_bytes( + &self.encipher(passphrase)?, + language, + )?)) } } @@ -543,13 +549,14 @@ mod test { let mnemonic_seq = seed .to_mnemonic(MnemonicLanguage::Japanese, None) .expect("Couldn't convert CipherSeed to Mnemonic"); - match CipherSeed::from_mnemonic(&mnemonic_seq, None) { + match CipherSeed::from_mnemonic(mnemonic_seq.reveal(), None) { Ok(mnemonic_seed) => assert_eq!(seed, mnemonic_seed), Err(e) => panic!("Couldn't create CipherSeed from Mnemonic: {}", e), } // Language known - let mnemonic_seed = CipherSeed::from_mnemonic_with_language(&mnemonic_seq, MnemonicLanguage::Japanese, None) - .expect("Couldn't create CipherSeed from Mnemonic with Language"); + let mnemonic_seed = + CipherSeed::from_mnemonic_with_language(mnemonic_seq.reveal(), MnemonicLanguage::Japanese, None) + .expect("Couldn't create CipherSeed from Mnemonic with Language"); assert_eq!(seed, mnemonic_seed); // Invalid Mnemonic sequence let mnemonic_seq = vec![ @@ -577,7 +584,7 @@ mod test { let mnemonic_seq = seed .to_mnemonic(MnemonicLanguage::Spanish, Some("Passphrase".to_string())) .expect("Couldn't convert CipherSeed to Mnemonic"); - match CipherSeed::from_mnemonic(&mnemonic_seq, Some("Passphrase".to_string())) { + match CipherSeed::from_mnemonic(mnemonic_seq.reveal(), Some("Passphrase".to_string())) { Ok(mnemonic_seed) => assert_eq!(seed, mnemonic_seed), Err(e) => panic!("Couldn't create CipherSeed from Mnemonic: {}", e), } @@ -586,7 +593,7 @@ mod test { .to_mnemonic(MnemonicLanguage::Spanish, Some("Passphrase".to_string())) .expect("Couldn't convert CipherSeed to Mnemonic"); assert!( - CipherSeed::from_mnemonic(&mnemonic_seq, Some("WrongPassphrase".to_string())).is_err(), + CipherSeed::from_mnemonic(mnemonic_seq.reveal(), Some("WrongPassphrase".to_string())).is_err(), "Should not be able to derive seed with wrong passphrase" ); } diff --git a/base_layer/key_manager/src/key_manager.rs b/base_layer/key_manager/src/key_manager.rs index e66f282d7f..1a9e08e3d4 100644 --- a/base_layer/key_manager/src/key_manager.rs +++ b/base_layer/key_manager/src/key_manager.rs @@ -30,13 +30,15 @@ use tari_crypto::{ keys::SecretKey, tari_utilities::byte_array::ByteArrayError, }; +use tari_utilities::Hidden; +use zeroize::Zeroize; -use crate::{cipher_seed::CipherSeed, mac_domain_hasher, LABEL_DERIVE_KEY}; +use crate::{cipher_seed::CipherSeed, mac_domain_hasher, KeyManagerHiddenType, LABEL_DERIVE_KEY}; -#[derive(Clone, Derivative, Serialize, Deserialize)] +#[derive(Clone, Derivative, Serialize, Deserialize, Zeroize)] #[derivative(Debug)] pub struct DerivedKey -where K: SecretKey +where K: SecretKey + Zeroize { #[derivative(Debug = "ignore")] #[serde(skip_serializing)] @@ -44,7 +46,7 @@ where K: SecretKey pub key_index: u64, } -#[derive(Clone, Derivative, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Derivative, PartialEq, Serialize, Deserialize, Zeroize)] #[derivative(Debug)] pub struct KeyManager { #[derivative(Debug = "ignore")] @@ -58,7 +60,7 @@ pub struct KeyManager impl KeyManager where - K: SecretKey, + K: SecretKey + Zeroize, D: Digest + LengthExtensionAttackResistant, { /// Creates a new KeyManager with a new randomly selected entropy @@ -85,7 +87,7 @@ where /// Derive a new private key from master key: derived_key=H(master_key||branch_seed||index), for some /// hash function H which is Length attack resistant, such as Blake2b. - pub fn derive_key(&self, key_index: u64) -> Result, ByteArrayError> { + pub fn derive_key(&self, key_index: u64) -> Result, KeyManagerHiddenType>, ByteArrayError> { // apply domain separation to generate derive key. Under the hood, the hashing api prepends the length of each // piece of data for concatenation, reducing the risk of collisions due to redundancy of variable length // input @@ -98,13 +100,16 @@ where let derive_key = derive_key.as_ref(); match K::from_bytes(derive_key) { - Ok(k) => Ok(DerivedKey { k, key_index }), + Ok(k) => Ok(Hidden::, KeyManagerHiddenType>::hide(DerivedKey { + k, + key_index, + })), Err(e) => Err(e), } } /// Generate next deterministic private key derived from master key - pub fn next_key(&mut self) -> Result, ByteArrayError> { + pub fn next_key(&mut self) -> Result, KeyManagerHiddenType>, ByteArrayError> { self.primary_key_index += 1; self.derive_key(self.primary_key_index) } @@ -124,7 +129,7 @@ where impl Default for KeyManager where - K: SecretKey, + K: SecretKey + Zeroize, D: Digest + LengthExtensionAttackResistant, { fn default() -> Self { @@ -158,11 +163,11 @@ mod test { let next_key2 = next_key2_result.unwrap(); let derived_key1 = derived_key1_result.unwrap(); let derived_key2 = derived_key2_result.unwrap(); - assert_ne!(next_key1.k, next_key2.k); - assert_eq!(next_key1.k, derived_key1.k); - assert_eq!(next_key2.k, derived_key2.k); - assert_eq!(next_key1.key_index, desired_key_index1); - assert_eq!(next_key2.key_index, desired_key_index2); + assert_ne!(next_key1.reveal().k, next_key2.reveal().k); + assert_eq!(next_key1.reveal().k, derived_key1.reveal().k); + assert_eq!(next_key2.reveal().k, derived_key2.reveal().k); + assert_eq!(next_key1.reveal().key_index, desired_key_index1); + assert_eq!(next_key2.reveal().key_index, desired_key_index2); } #[test] @@ -178,11 +183,11 @@ mod test { let next_key2 = next_key2_result.unwrap(); let derived_key1 = derived_key1_result.unwrap(); let derived_key2 = derived_key2_result.unwrap(); - assert_ne!(next_key1.k, next_key2.k); - assert_eq!(next_key1.k, derived_key1.k); - assert_eq!(next_key2.k, derived_key2.k); - assert_eq!(next_key1.key_index, desired_key_index1); - assert_eq!(next_key2.key_index, desired_key_index2); + assert_ne!(next_key1.reveal().k, next_key2.reveal().k); + assert_eq!(next_key1.reveal().k, derived_key1.reveal().k); + assert_eq!(next_key2.reveal().k, derived_key2.reveal().k); + assert_eq!(next_key1.reveal().key_index, desired_key_index1); + assert_eq!(next_key2.reveal().key_index, desired_key_index2); } #[test] @@ -192,6 +197,6 @@ mod test { let mut km2 = KeyManager::::from(x, "other".to_string(), 0); let next_key1 = km1.next_key().unwrap(); let next_key2 = km2.next_key().unwrap(); - assert_ne!(next_key1.k, next_key2.k); + assert_ne!(next_key1.reveal().k, next_key2.reveal().k); } } diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index c7cf4d650d..1bc1187a2e 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -6,6 +6,7 @@ use tari_crypto::{ hash_domain, hashing::{DomainSeparatedHasher, LengthExtensionAttackResistant}, }; +use tari_utilities::{hidden::HiddenLabel, hidden_label}; pub mod cipher_seed; pub mod diacritics; @@ -30,3 +31,5 @@ pub(crate) fn mac_domain_hasher( ) -> DomainSeparatedHasher { DomainSeparatedHasher::::new_with_label(label) } + +hidden_label!(KeyManagerHiddenType); diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index 4a5093316d..d1c0c682da 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -24,12 +24,16 @@ use std::{cmp::Ordering, slice::Iter}; use serde::{Deserialize, Serialize}; use strum_macros::{Display, EnumString}; -use tari_utilities::bit::{bytes_to_bits, checked_bits_to_uint}; +use tari_utilities::{ + bit::{bytes_to_bits, checked_bits_to_uint}, + Hidden, +}; use crate::{ diacritics::*, error::{KeyManagerError, MnemonicError}, mnemonic_wordlists::*, + KeyManagerHiddenType, }; /// The Mnemonic system simplifies the encoding and decoding of a secret key into and from a Mnemonic word sequence @@ -255,7 +259,7 @@ pub trait Mnemonic { &self, language: MnemonicLanguage, passphrase: Option, - ) -> Result, KeyManagerError>; + ) -> Result, KeyManagerHiddenType>, KeyManagerError>; } #[cfg(test)] diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index c042fd332b..7e6ab0b9e3 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -51,6 +51,7 @@ use tari_key_manager::{ cipher_seed::CipherSeed, key_manager::KeyManager, mnemonic::{Mnemonic, MnemonicLanguage}, + KeyManagerHiddenType, }; use tari_p2p::{ auto_update::{AutoUpdateConfig, SoftwareUpdaterHandle, SoftwareUpdaterService}, @@ -63,7 +64,7 @@ use tari_p2p::{ use tari_script::{script, ExecutionStack, TariScript}; use tari_service_framework::StackBuilder; use tari_shutdown::ShutdownSignal; -use tari_utilities::{ByteArray, SafePassword}; +use tari_utilities::{ByteArray, Hidden, SafePassword}; use crate::{ base_node_service::{handle::BaseNodeServiceHandle, BaseNodeServiceInitializer}, @@ -669,7 +670,10 @@ where Ok(self.db.get_client_key_value(RECOVERY_KEY.to_string())?.is_some()) } - pub fn get_seed_words(&self, language: &MnemonicLanguage) -> Result, WalletError> { + pub fn get_seed_words( + &self, + language: &MnemonicLanguage, + ) -> Result, KeyManagerHiddenType>, WalletError> { let master_seed = self.db.get_master_seed()?.ok_or_else(|| { WalletError::WalletStorageError(WalletStorageError::RecoverySeedError( "Cipher Seed not found".to_string(), From cc21bd9e282876c2cf5acb1df913ac7e6c44c6a2 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 15 Nov 2022 19:28:27 +0000 Subject: [PATCH 02/20] add seed words --- Cargo.lock | 45 ++++--- applications/tari_app_grpc/Cargo.toml | 2 +- applications/tari_app_utilities/Cargo.toml | 2 +- applications/tari_base_node/Cargo.toml | 2 +- applications/tari_console_wallet/Cargo.toml | 2 +- .../tari_merge_mining_proxy/Cargo.toml | 2 +- applications/tari_miner/Cargo.toml | 2 +- base_layer/common_types/Cargo.toml | 2 +- base_layer/core/Cargo.toml | 2 +- base_layer/key_manager/Cargo.toml | 2 +- base_layer/key_manager/src/cipher_seed.rs | 119 +++++++++++------- base_layer/key_manager/src/diacritics.rs | 35 +++--- base_layer/key_manager/src/key_manager.rs | 11 +- base_layer/key_manager/src/lib.rs | 37 +++++- base_layer/key_manager/src/mnemonic.rs | 95 ++++++++------ base_layer/mmr/Cargo.toml | 2 +- base_layer/p2p/Cargo.toml | 2 +- base_layer/tari_mining_helper_ffi/Cargo.toml | 2 +- base_layer/wallet/Cargo.toml | 4 +- .../wallet/src/key_manager_service/handle.rs | 5 +- .../src/key_manager_service/interface.rs | 9 +- .../wallet/src/key_manager_service/mock.rs | 19 +-- .../wallet/src/key_manager_service/service.rs | 15 ++- .../recovery/standard_outputs_recoverer.rs | 9 +- base_layer/wallet/src/wallet.rs | 8 +- base_layer/wallet_ffi/Cargo.toml | 2 +- common/Cargo.toml | 2 +- comms/core/Cargo.toml | 2 +- comms/dht/Cargo.toml | 2 +- infrastructure/tari_script/Cargo.toml | 2 +- 30 files changed, 280 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad0d8572bd..6c5d44b686 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,7 +131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db4ce4441f99dbd377ca8a8f57b698c44d0d6e712d8329b5040da5a64aa1ce73" dependencies = [ "base64ct", - "blake2 0.10.4", + "blake2 0.10.5", "password-hash", ] @@ -344,9 +344,9 @@ dependencies = [ [[package]] name = "blake2" -version = "0.10.4" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9cf849ee05b2ee5fba5e36f97ff8ec2533916700fc0758d40d92136a42f3388" +checksum = "b12e5fd123190ce1c2e559308a94c9bacad77907d4c6005d9e58fe1a0689e55e" dependencies = [ "digest 0.10.5", ] @@ -623,9 +623,9 @@ checksum = "17cc5e6b5ab06331c33589842070416baa137e8b0eb912b008cfd4a78ada7919" [[package]] name = "chrono" -version = "0.4.22" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ "iana-time-zone", "js-sys", @@ -2260,9 +2260,12 @@ dependencies = [ [[package]] name = "keccak" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" +checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +dependencies = [ + "cpufeatures", +] [[package]] name = "lazy_static" @@ -3064,9 +3067,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.3.1" +version = "6.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" +checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" [[package]] name = "packed_simd_2" @@ -4130,6 +4133,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfc62771e7b829b517cb213419236475f434fb480eddd76112ae182d274434a" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_cbor" version = "0.11.2" @@ -4348,7 +4362,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "774d05a3edae07ce6d68ea6984f3c05e9bba8927e3dd591e3b479e5b03213d0d" dependencies = [ "aes-gcm", - "blake2 0.10.4", + "blake2 0.10.5", "chacha20poly1305", "curve25519-dalek 4.0.0-pre.2", "rand_core 0.6.4", @@ -4697,7 +4711,7 @@ dependencies = [ "anyhow", "async-trait", "bitflags 1.3.2", - "blake2 0.10.4", + "blake2 0.10.5", "bytes 1.2.1", "chrono", "cidr", @@ -4916,8 +4930,8 @@ dependencies = [ [[package]] name = "tari_crypto" -version = "0.15.7" -source = "git+https://github.com/tari-project/tari-crypto.git?tag=v0.15.7#bd66b3d2021bf0b391d50f1ba8db339a62231738" +version = "0.16.0" +source = "git+https://github.com/tari-project/tari-crypto.git?tag=v0.16.0#8f3bce7ed1ece78d58c90ba9abda59cbfa0863f6" dependencies = [ "base64 0.10.1", "blake2 0.9.2", @@ -4931,6 +4945,7 @@ dependencies = [ "once_cell", "rand 0.7.3", "serde", + "serde-wasm-bindgen", "serde_json", "sha3", "tari_bulletproofs", @@ -5239,7 +5254,7 @@ dependencies = [ [[package]] name = "tari_utilities" version = "0.4.8" -source = "git+https://github.com/AaronFeickert/tari_utilities.git?branch=clandestine#31cfd74d82ddf181f70bf94928f23437366bae82" +source = "git+https://github.com/AaronFeickert/tari_utilities.git?branch=clandestine#c3d2f7f235ec595b4664b3b82ce6da69213644f5" dependencies = [ "base58-monero 0.3.2", "base64 0.13.1", @@ -5294,7 +5309,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities 0.4.7", + "tari_utilities 0.4.8", "tempfile", "thiserror", "tokio", diff --git a/applications/tari_app_grpc/Cargo.toml b/applications/tari_app_grpc/Cargo.toml index 3413276aa0..c145e007ea 100644 --- a/applications/tari_app_grpc/Cargo.toml +++ b/applications/tari_app_grpc/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" tari_common_types = { version = "^0.38", path = "../../base_layer/common_types" } tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_script = { path = "../../infrastructure/tari_script" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } diff --git a/applications/tari_app_utilities/Cargo.toml b/applications/tari_app_utilities/Cargo.toml index e861c7094f..a60e34b814 100644 --- a/applications/tari_app_utilities/Cargo.toml +++ b/applications/tari_app_utilities/Cargo.toml @@ -7,7 +7,7 @@ license = "BSD-3-Clause" [dependencies] tari_comms = { path = "../../comms/core" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = { path = "../../common" } tari_common_types = { path = "../../base_layer/common_types" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } diff --git a/applications/tari_base_node/Cargo.toml b/applications/tari_base_node/Cargo.toml index cacfaf7d23..a08cda2eaa 100644 --- a/applications/tari_base_node/Cargo.toml +++ b/applications/tari_base_node/Cargo.toml @@ -15,7 +15,7 @@ tari_comms = { path = "../../comms/core", features = ["rpc"] } tari_common_types = { path = "../../base_layer/common_types" } tari_comms_dht = { path = "../../comms/dht" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_libtor = { path = "../../infrastructure/libtor", optional = true } tari_mmr = { path = "../../base_layer/mmr", features = ["native_bitmap"] } tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index 00e75fd3bd..fec5b32479 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -7,7 +7,7 @@ license = "BSD-3-Clause" [dependencies] tari_wallet = { path = "../../base_layer/wallet", features = ["bundled_sqlite"] } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = { path = "../../common" } tari_app_utilities = { path = "../tari_app_utilities" } tari_comms = { path = "../../comms/core" } diff --git a/applications/tari_merge_mining_proxy/Cargo.toml b/applications/tari_merge_mining_proxy/Cargo.toml index 5046b6a96c..fdb36849d2 100644 --- a/applications/tari_merge_mining_proxy/Cargo.toml +++ b/applications/tari_merge_mining_proxy/Cargo.toml @@ -15,7 +15,7 @@ tari_common = { path = "../../common" } tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] } tari_app_utilities = { path = "../tari_app_utilities" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } tari_base_node_grpc_client = {path="../../clients/rust/base_node_grpc_client" } tari_wallet_grpc_client = {path="../../clients/rust/wallet_grpc_client" } diff --git a/applications/tari_miner/Cargo.toml b/applications/tari_miner/Cargo.toml index 62ca142e61..af4d4d53e5 100644 --- a/applications/tari_miner/Cargo.toml +++ b/applications/tari_miner/Cargo.toml @@ -14,7 +14,7 @@ tari_common_types = { path = "../../base_layer/common_types" } tari_comms = { path = "../../comms/core" } tari_app_utilities = { path = "../tari_app_utilities" } tari_app_grpc = { path = "../tari_app_grpc" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } crossterm = { version = "0.25.0" } diff --git a/base_layer/common_types/Cargo.toml b/base_layer/common_types/Cargo.toml index 64c62d8d8d..bfc26c2306 100644 --- a/base_layer/common_types/Cargo.toml +++ b/base_layer/common_types/Cargo.toml @@ -7,7 +7,7 @@ version = "0.38.8" edition = "2018" [dependencies] -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } base64 = "0.13.0" diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 203d0e75e1..67e8a94ea2 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -24,7 +24,7 @@ tari_common_types = { version = "^0.38", path = "../../base_layer/common_types" tari_comms = { version = "^0.38", path = "../../comms/core" } tari_comms_dht = { version = "^0.38", path = "../../comms/dht" } tari_comms_rpc_macros = { version = "^0.38", path = "../../comms/rpc_macros" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_metrics = { path = "../../infrastructure/metrics" } tari_mmr = { version = "^0.38", path = "../../base_layer/mmr", optional = true, features = ["native_bitmap"] } tari_p2p = { version = "^0.38", path = "../../base_layer/p2p" } diff --git a/base_layer/key_manager/Cargo.toml b/base_layer/key_manager/Cargo.toml index f470b78be3..1f007a58d5 100644 --- a/base_layer/key_manager/Cargo.toml +++ b/base_layer/key_manager/Cargo.toml @@ -13,7 +13,7 @@ crate-type = ["lib", "cdylib"] # NB: All dependencies must support or be gated for the WASM target. [dependencies] tari_common_types = { version = "^0.38", path = "../../base_layer/common_types", optional = true } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/AaronFeickert/tari_utilities.git", branch="clandestine" } arrayvec = "0.7.1" diff --git a/base_layer/key_manager/src/cipher_seed.rs b/base_layer/key_manager/src/cipher_seed.rs index 22705ba56b..d5428e939b 100644 --- a/base_layer/key_manager/src/cipher_seed.rs +++ b/base_layer/key_manager/src/cipher_seed.rs @@ -20,7 +20,7 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use std::{convert::TryFrom, mem::size_of}; +use std::{convert::TryFrom, mem::size_of, str::FromStr}; use argon2; use chacha20::{ @@ -34,14 +34,16 @@ use rand::{rngs::OsRng, RngCore}; use serde::{Deserialize, Serialize}; use subtle::ConstantTimeEq; use tari_crypto::hash::blake2::Blake256; -use tari_utilities::hidden::Hidden; +use tari_utilities::{hidden::Hidden, SafePassword}; use zeroize::{Zeroize, Zeroizing}; use crate::{ error::KeyManagerError, mac_domain_hasher, mnemonic::{from_bytes, to_bytes, to_bytes_with_language, Mnemonic, MnemonicLanguage}, - KeyManagerHiddenType, + CipherSeedEncryptionKey, + CipherSeedMacKey, + SeedWords, LABEL_ARGON_ENCODING, LABEL_CHACHA20_ENCODING, LABEL_MAC_GENERATION, @@ -123,7 +125,7 @@ pub struct CipherSeed { } // This is a separate type to make the linter happy -type DerivedCipherSeedKeys = Result<(Zeroizing>, Zeroizing>), KeyManagerError>; +type DerivedCipherSeedKeys = Result<(CipherSeedEncryptionKey, CipherSeedMacKey), KeyManagerError>; impl CipherSeed { #[cfg(not(target_arch = "wasm32"))] @@ -167,9 +169,12 @@ impl CipherSeed { } /// Generate an encrypted seed from a passphrase - pub fn encipher(&self, passphrase: Option) -> Result, KeyManagerError> { + pub fn encipher(&self, passphrase: Option) -> Result, KeyManagerError> { // Derive encryption and MAC keys from passphrase and main salt - let passphrase = Zeroizing::new(passphrase.unwrap_or_else(|| DEFAULT_CIPHER_SEED_PASSPHRASE.to_string())); + let passphrase = passphrase.unwrap_or_else(|| { + SafePassword::from_str(DEFAULT_CIPHER_SEED_PASSPHRASE) + .expect("Failed to parse default cipher seed passphrase to SafePassword") + }); let (encryption_key, mac_key) = Self::derive_keys(&passphrase, self.salt.as_ref())?; // Generate the MAC @@ -178,7 +183,7 @@ impl CipherSeed { self.entropy.as_ref(), CIPHER_SEED_VERSION, self.salt.as_ref(), - mac_key.as_ref(), + mac_key.reveal(), )?; // Assemble the secret data to be encrypted: birthday, entropy, MAC @@ -190,7 +195,7 @@ impl CipherSeed { secret_data.extend(&mac); // Encrypt the secret data - Self::apply_stream_cipher(&mut secret_data, encryption_key.as_ref(), self.salt.as_ref())?; + Self::apply_stream_cipher(&mut secret_data, encryption_key.reveal(), self.salt.as_ref())?; // Assemble the final seed: version, main salt, secret data, checksum let mut encrypted_seed = @@ -208,7 +213,10 @@ impl CipherSeed { } /// Recover a seed from encrypted data and a passphrase - pub fn from_enciphered_bytes(encrypted_seed: &[u8], passphrase: Option) -> Result { + pub fn from_enciphered_bytes( + encrypted_seed: &[u8], + passphrase: Option, + ) -> Result { // Check the length: version, birthday, entropy, MAC, salt, checksum if encrypted_seed.len() != 1 + CIPHER_SEED_BIRTHDAY_BYTES + @@ -243,7 +251,10 @@ impl CipherSeed { } // Derive encryption and MAC keys from passphrase and main salt - let passphrase = Zeroizing::new(passphrase.unwrap_or_else(|| DEFAULT_CIPHER_SEED_PASSPHRASE.to_string())); + let passphrase = passphrase.unwrap_or_else(|| { + SafePassword::from_str(DEFAULT_CIPHER_SEED_PASSPHRASE) + .expect("Failed to parse default cipher seed passphrase to SafePassword") + }); let salt: Box<[u8; CIPHER_SEED_MAIN_SALT_BYTES]> = encrypted_seed .split_off(1 + CIPHER_SEED_BIRTHDAY_BYTES + CIPHER_SEED_ENTROPY_BYTES + CIPHER_SEED_MAC_BYTES) .into_boxed_slice() @@ -253,7 +264,7 @@ impl CipherSeed { // Decrypt the secret data: birthday, entropy, MAC let mut secret_data = Zeroizing::new(encrypted_seed.split_off(1)); - Self::apply_stream_cipher(&mut secret_data, encryption_key.as_ref(), salt.as_ref())?; + Self::apply_stream_cipher(&mut secret_data, encryption_key.reveal(), salt.as_ref())?; // Parse secret data let mac = secret_data.split_off(CIPHER_SEED_BIRTHDAY_BYTES + CIPHER_SEED_ENTROPY_BYTES); @@ -273,7 +284,7 @@ impl CipherSeed { entropy.as_ref(), version, salt.as_ref(), - mac_key.as_ref(), + mac_key.reveal(), )?; // Verify the MAC in constant time to avoid leaking data @@ -346,7 +357,7 @@ impl CipherSeed { /// Use Argon2 to derive encryption and MAC keys from a passphrase and main salt // TODO: passhphrase should be SafePassword - fn derive_keys(passphrase: &str, salt: &[u8]) -> DerivedCipherSeedKeys { + fn derive_keys(passphrase: &SafePassword, salt: &[u8]) -> DerivedCipherSeedKeys { // The Argon2 salt is derived from the main salt let argon2_salt = mac_domain_hasher::(LABEL_ARGON_ENCODING) .chain(salt) @@ -365,15 +376,23 @@ impl CipherSeed { .map_err(|_| KeyManagerError::CryptographicError("Problem generating Argon2 parameters".to_string()))?; // Derive the main key from the password in place - let mut main_key = Zeroizing::new([0u8; CIPHER_SEED_ENCRYPTION_KEY_BYTES + CIPHER_SEED_MAC_KEY_BYTES]); + let mut main_key = Hidden::hide([0u8; CIPHER_SEED_ENCRYPTION_KEY_BYTES + CIPHER_SEED_MAC_KEY_BYTES]); let hasher = argon2::Argon2::new(argon2::Algorithm::Argon2d, argon2::Version::V0x13, params); hasher - .hash_password_into(passphrase.as_bytes(), argon2_salt, main_key.as_mut()) + .hash_password_into(passphrase.reveal(), argon2_salt, main_key.reveal_mut()) .map_err(|_| KeyManagerError::CryptographicError("Problem generating Argon2 password hash".to_string()))?; // Split off the keys - let encryption_key = Zeroizing::new(main_key.as_ref()[..CIPHER_SEED_ENCRYPTION_KEY_BYTES].to_vec()); // TODO - let mac_key = Zeroizing::new(main_key.as_ref()[CIPHER_SEED_ENCRYPTION_KEY_BYTES..].to_vec()); // TODO + let mut encryption_key = CipherSeedEncryptionKey::from([0u8; CIPHER_SEED_ENCRYPTION_KEY_BYTES]); + encryption_key + .reveal_mut() + .copy_from_slice(&main_key.reveal()[..CIPHER_SEED_ENCRYPTION_KEY_BYTES]); + + let mut mac_key = CipherSeedMacKey::from([0u8; CIPHER_SEED_MAC_KEY_BYTES]); + mac_key + .reveal_mut() + .copy_from_slice(&main_key.reveal()[CIPHER_SEED_ENCRYPTION_KEY_BYTES..]); + Ok((encryption_key, mac_key)) } } @@ -387,16 +406,19 @@ impl Default for CipherSeed { impl Mnemonic for CipherSeed { /// Generates a CipherSeed that represent the provided mnemonic sequence of words, the language of the mnemonic /// sequence is autodetected - fn from_mnemonic(mnemonic_seq: &[String], passphrase: Option) -> Result { + fn from_mnemonic( + mnemonic_seq: &SeedWords, + passphrase: Option, + ) -> Result { let bytes = to_bytes(mnemonic_seq)?; CipherSeed::from_enciphered_bytes(&bytes, passphrase) } /// Generates a SecretKey that represent the provided mnemonic sequence of words using the specified language fn from_mnemonic_with_language( - mnemonic_seq: &[String], + mnemonic_seq: &SeedWords, language: MnemonicLanguage, - passphrase: Option, + passphrase: Option, ) -> Result { let bytes = to_bytes_with_language(mnemonic_seq, &language)?; CipherSeed::from_enciphered_bytes(&bytes, passphrase) @@ -406,44 +428,51 @@ impl Mnemonic for CipherSeed { fn to_mnemonic( &self, language: MnemonicLanguage, - passphrase: Option, - ) -> Result, KeyManagerHiddenType>, KeyManagerError> { - Ok(Hidden::, KeyManagerHiddenType>::hide(from_bytes( - &self.encipher(passphrase)?, - language, - )?)) + passphrase: Option, + ) -> Result { + Ok(from_bytes(&self.encipher(passphrase)?, language)?) } } #[cfg(test)] mod test { + use std::str::FromStr; + use crc32fast::Hasher as CrcHasher; + use tari_utilities::SafePassword; use crate::{ cipher_seed::{CipherSeed, CIPHER_SEED_VERSION}, error::KeyManagerError, mnemonic::{Mnemonic, MnemonicLanguage}, + SeedWords, }; #[test] fn test_cipher_seed_generation_and_deciphering() { let seed = CipherSeed::new(); - let mut enciphered_seed = seed.encipher(Some("Passphrase".to_string())).unwrap(); + let mut enciphered_seed = seed + .encipher(Some(SafePassword::from_str("Passphrase").unwrap())) + .unwrap(); let deciphered_seed = - CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("Passphrase".to_string())).unwrap(); + CipherSeed::from_enciphered_bytes(&enciphered_seed, Some(SafePassword::from_str("Passphrase").unwrap())) + .unwrap(); assert_eq!(seed, deciphered_seed); - match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("WrongPassphrase".to_string())) { + match CipherSeed::from_enciphered_bytes( + &enciphered_seed, + Some(SafePassword::from_str("WrongPassphrase").unwrap()), + ) { Err(KeyManagerError::DecryptionFailed) => (), _ => panic!("Version should not match"), } enciphered_seed[0] = CIPHER_SEED_VERSION + 1; // this is an unsupported version - match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("Passphrase".to_string())) { + match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some(SafePassword::from_str("Passphrase").unwrap())) { Err(KeyManagerError::VersionMismatch) => (), _ => panic!("Version should not match"), } @@ -453,7 +482,7 @@ mod test { // flip some bits enciphered_seed[1] = !enciphered_seed[1]; - match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("Passphrase".to_string())) { + match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some(SafePassword::from_str("Passphrase").unwrap())) { Err(KeyManagerError::CrcError) => (), _ => panic!("Crc should not match"), } @@ -479,7 +508,7 @@ mod test { enciphered_seed[(n - 4)..].copy_from_slice(&calculated_checksum); // the MAC decryption should fail in this case - match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("passphrase".to_string())) { + match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some(SafePassword::from_str("passphrase").unwrap())) { Err(KeyManagerError::DecryptionFailed) => (), _ => panic!("Decryption should fail"), } @@ -506,7 +535,7 @@ mod test { enciphered_seed[(n - 4)..].copy_from_slice(&calculated_checksum); // the MAC decryption should fail in this case - match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("passphrase".to_string())) { + match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some(SafePassword::from_str("passphrase").unwrap())) { Err(KeyManagerError::DecryptionFailed) => (), _ => panic!("Decryption should fail"), } @@ -532,7 +561,7 @@ mod test { enciphered_seed[(n - 4)..].copy_from_slice(&calculated_checksum); // the MAC decryption should fail in this case - match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some("passphrase".to_string())) { + match CipherSeed::from_enciphered_bytes(&enciphered_seed, Some(SafePassword::from_str("passphrase").unwrap())) { Err(KeyManagerError::DecryptionFailed) => (), _ => panic!("Decryption should fail"), } @@ -549,14 +578,13 @@ mod test { let mnemonic_seq = seed .to_mnemonic(MnemonicLanguage::Japanese, None) .expect("Couldn't convert CipherSeed to Mnemonic"); - match CipherSeed::from_mnemonic(mnemonic_seq.reveal(), None) { + match CipherSeed::from_mnemonic(&mnemonic_seq, None) { Ok(mnemonic_seed) => assert_eq!(seed, mnemonic_seed), Err(e) => panic!("Couldn't create CipherSeed from Mnemonic: {}", e), } // Language known - let mnemonic_seed = - CipherSeed::from_mnemonic_with_language(mnemonic_seq.reveal(), MnemonicLanguage::Japanese, None) - .expect("Couldn't create CipherSeed from Mnemonic with Language"); + let mnemonic_seed = CipherSeed::from_mnemonic_with_language(&mnemonic_seq, MnemonicLanguage::Japanese, None) + .expect("Couldn't create CipherSeed from Mnemonic with Language"); assert_eq!(seed, mnemonic_seed); // Invalid Mnemonic sequence let mnemonic_seq = vec![ @@ -566,6 +594,7 @@ mod test { .iter() .map(|x| x.to_string()) .collect::>(); + let mnemonic_seq = SeedWords::new(&mnemonic_seq); // Language not known match CipherSeed::from_mnemonic(&mnemonic_seq, None) { Ok(_k) => panic!(), @@ -582,18 +611,24 @@ mod test { fn cipher_seed_to_and_from_mnemonic_with_passphrase() { let seed = CipherSeed::new(); let mnemonic_seq = seed - .to_mnemonic(MnemonicLanguage::Spanish, Some("Passphrase".to_string())) + .to_mnemonic( + MnemonicLanguage::Spanish, + Some(SafePassword::from_str("Passphrase").unwrap()), + ) .expect("Couldn't convert CipherSeed to Mnemonic"); - match CipherSeed::from_mnemonic(mnemonic_seq.reveal(), Some("Passphrase".to_string())) { + match CipherSeed::from_mnemonic(&mnemonic_seq, Some(SafePassword::from_str("Passphrase").unwrap())) { Ok(mnemonic_seed) => assert_eq!(seed, mnemonic_seed), Err(e) => panic!("Couldn't create CipherSeed from Mnemonic: {}", e), } let mnemonic_seq = seed - .to_mnemonic(MnemonicLanguage::Spanish, Some("Passphrase".to_string())) + .to_mnemonic( + MnemonicLanguage::Spanish, + Some(SafePassword::from_str("Passphrase").unwrap()), + ) .expect("Couldn't convert CipherSeed to Mnemonic"); assert!( - CipherSeed::from_mnemonic(mnemonic_seq.reveal(), Some("WrongPassphrase".to_string())).is_err(), + CipherSeed::from_mnemonic(&mnemonic_seq, Some(SafePassword::from_str("WrongPassphrase").unwrap())).is_err(), "Should not be able to derive seed with wrong passphrase" ); } diff --git a/base_layer/key_manager/src/diacritics.rs b/base_layer/key_manager/src/diacritics.rs index 2ed5c30e32..1bb6164f5e 100644 --- a/base_layer/key_manager/src/diacritics.rs +++ b/base_layer/key_manager/src/diacritics.rs @@ -1,13 +1,13 @@ // Copyright 2022 The Tari Project // SPDX-License-Identifier: BSD-3-Clause +use tari_utilities::Hidden; + /// Remove diacritic marks, points and accents on lowercase characters -pub fn remove_diacritics(word: &str) -> String { +pub fn remove_diacritics(word: &str) -> Hidden { // Replace diacritics accents - let clean_string: String = - word.to_lowercase() - .as_str() - .chars() + let clean_string: Hidden = Hidden::hide( + word.chars() .map(|x| match x { 'a' | '\u{24D0}' | '\u{FF41}' | '\u{1E9A}' | '\u{00E0}' | '\u{00E1}' | '\u{00E2}' | '\u{1EA7}' | '\u{1EA5}' | '\u{1EAB}' | '\u{1EA9}' | '\u{00E3}' | '\u{0101}' | '\u{0103}' | '\u{1EB1}' | @@ -77,9 +77,10 @@ pub fn remove_diacritics(word: &str) -> String { '\u{1E95}' | '\u{01B6}' | '\u{0225}' | '\u{0240}' | '\u{2C6C}' | '\u{A763}' => 'z', _ => x, }) - .collect(); + .collect(), + ); // Remove any remaining non-ascii characters - clean_string.replace(|c: char| !c.is_ascii(), "") + Hidden::hide(clean_string.reveal().replace(|c: char| !c.is_ascii(), "")) } #[cfg(test)] @@ -89,17 +90,17 @@ mod test { #[test] fn test_temp() { // Words with Diacretics - assert_eq!(remove_diacritics("ábaco"), "abaco".to_string()); - assert_eq!(remove_diacritics("cúpula"), "cupula".to_string()); - assert_eq!(remove_diacritics("legión"), "legion".to_string()); - assert_eq!(remove_diacritics("sureño"), "sureno".to_string()); - assert_eq!(remove_diacritics("chimère"), "chimere".to_string()); - assert_eq!(remove_diacritics("élève"), "eleve".to_string()); + assert_eq!(remove_diacritics("ábaco").reveal(), "abaco"); + assert_eq!(remove_diacritics("cúpula").reveal(), "cupula"); + assert_eq!(remove_diacritics("legión").reveal(), "legion"); + assert_eq!(remove_diacritics("sureño").reveal(), "sureno"); + assert_eq!(remove_diacritics("chimère").reveal(), "chimere"); + assert_eq!(remove_diacritics("élève").reveal(), "eleve"); // Words without Diacretics - assert_eq!(remove_diacritics("observe"), "observe".to_string()); - assert_eq!(remove_diacritics("response"), "response".to_string()); - assert_eq!(remove_diacritics("bizzarro"), "bizzarro".to_string()); - assert_eq!(remove_diacritics("materasso"), "materasso".to_string()); + assert_eq!(remove_diacritics("observe").reveal(), "observe"); + assert_eq!(remove_diacritics("response").reveal(), "response"); + assert_eq!(remove_diacritics("bizzarro").reveal(), "bizzarro"); + assert_eq!(remove_diacritics("materasso").reveal(), "materasso"); } } diff --git a/base_layer/key_manager/src/key_manager.rs b/base_layer/key_manager/src/key_manager.rs index 1a9e08e3d4..70248a0c95 100644 --- a/base_layer/key_manager/src/key_manager.rs +++ b/base_layer/key_manager/src/key_manager.rs @@ -33,7 +33,7 @@ use tari_crypto::{ use tari_utilities::Hidden; use zeroize::Zeroize; -use crate::{cipher_seed::CipherSeed, mac_domain_hasher, KeyManagerHiddenType, LABEL_DERIVE_KEY}; +use crate::{cipher_seed::CipherSeed, mac_domain_hasher, LABEL_DERIVE_KEY}; #[derive(Clone, Derivative, Serialize, Deserialize, Zeroize)] #[derivative(Debug)] @@ -87,7 +87,7 @@ where /// Derive a new private key from master key: derived_key=H(master_key||branch_seed||index), for some /// hash function H which is Length attack resistant, such as Blake2b. - pub fn derive_key(&self, key_index: u64) -> Result, KeyManagerHiddenType>, ByteArrayError> { + pub fn derive_key(&self, key_index: u64) -> Result>, ByteArrayError> { // apply domain separation to generate derive key. Under the hood, the hashing api prepends the length of each // piece of data for concatenation, reducing the risk of collisions due to redundancy of variable length // input @@ -100,16 +100,13 @@ where let derive_key = derive_key.as_ref(); match K::from_bytes(derive_key) { - Ok(k) => Ok(Hidden::, KeyManagerHiddenType>::hide(DerivedKey { - k, - key_index, - })), + Ok(k) => Ok(Hidden::>::hide(DerivedKey { k, key_index })), Err(e) => Err(e), } } /// Generate next deterministic private key derived from master key - pub fn next_key(&mut self) -> Result, KeyManagerHiddenType>, ByteArrayError> { + pub fn next_key(&mut self) -> Result>, ByteArrayError> { self.primary_key_index += 1; self.derive_key(self.primary_key_index) } diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index 1bc1187a2e..14a341857e 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -2,11 +2,18 @@ // SPDX-License-Identifier: BSD-3-Clause use digest::Digest; +use serde::{Deserialize, Serialize}; use tari_crypto::{ hash_domain, hashing::{DomainSeparatedHasher, LengthExtensionAttackResistant}, }; -use tari_utilities::{hidden::HiddenLabel, hidden_label}; +use tari_utilities::{hidden::Hidden, hidden_type}; +use zeroize::Zeroize; + +use crate::{ + cipher_seed::{CIPHER_SEED_ENCRYPTION_KEY_BYTES, CIPHER_SEED_MAC_KEY_BYTES}, + error::MnemonicError, +}; pub mod cipher_seed; pub mod diacritics; @@ -32,4 +39,30 @@ pub(crate) fn mac_domain_hasher( DomainSeparatedHasher::::new_with_label(label) } -hidden_label!(KeyManagerHiddenType); +hidden_type!(CipherSeedEncryptionKey, [u8; CIPHER_SEED_ENCRYPTION_KEY_BYTES]); +hidden_type!(CipherSeedMacKey, [u8; CIPHER_SEED_MAC_KEY_BYTES]); + +#[derive(Debug, Clone)] +pub struct SeedWords { + words: Vec>, +} + +impl SeedWords { + pub fn new(words: &[String]) -> Self { + Self { + words: words.into_iter().map(|m| Hidden::hide(m.clone())).collect::>(), + } + } + + pub fn len(&self) -> usize { + self.words.len() + } + + pub fn get_word(&self, index: usize) -> Result<&String, MnemonicError> { + if index > self.len() - 1 { + return Err(MnemonicError::IndexOutOfBounds); + } + + Ok(self.words[index].reveal()) + } +} diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index d1c0c682da..2ac02eba7f 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -27,13 +27,14 @@ use strum_macros::{Display, EnumString}; use tari_utilities::{ bit::{bytes_to_bits, checked_bits_to_uint}, Hidden, + SafePassword, }; use crate::{ diacritics::*, error::{KeyManagerError, MnemonicError}, mnemonic_wordlists::*, - KeyManagerHiddenType, + SeedWords, }; /// The Mnemonic system simplifies the encoding and decoding of a secret key into and from a Mnemonic word sequence @@ -56,7 +57,7 @@ pub enum MnemonicLanguage { impl MnemonicLanguage { /// Detects the mnemonic language of a specific word by searching all defined mnemonic word lists pub fn from(mnemonic_word: &str) -> Result { - let words = vec![mnemonic_word.to_string()]; + let words = SeedWords::new(&[mnemonic_word.to_string()]); MnemonicLanguage::detect_language(&words) } @@ -88,14 +89,14 @@ impl MnemonicLanguage { } /// Detects the language of a list of words - pub fn detect_language(words: &[String]) -> Result { - let count = words.iter().len(); + pub fn detect_language(words: &SeedWords) -> Result { + let count = words.len(); match count.cmp(&1) { Ordering::Less => { return Err(MnemonicError::UnknownLanguage); }, Ordering::Equal => { - let word = words.get(0).ok_or(MnemonicError::EncodeInvalidLength)?; + let word = words.get_word(0)?; for language in MnemonicLanguage::iterator() { if find_mnemonic_index_from_word(word, *language).is_ok() { return Ok(*language); @@ -104,7 +105,8 @@ impl MnemonicLanguage { return Err(MnemonicError::UnknownLanguage); }, Ordering::Greater => { - for word in words { + for word_ind in 0..words.len() { + let word = words.get_word(word_ind)?; let mut languages = Vec::with_capacity(MnemonicLanguage::iterator().len()); // detect all languages in which a word falls into for language in MnemonicLanguage::iterator() { @@ -116,7 +118,8 @@ impl MnemonicLanguage { // yielded from the initial word for this iteration for language in languages { let mut consistent = true; - for compare in words { + for compare_ind in 0..words.len() { + let compare = words.get_word(compare_ind)?; if compare != word && find_mnemonic_index_from_word(compare, language).is_err() { consistent = false; } @@ -135,19 +138,27 @@ impl MnemonicLanguage { /// Finds and returns the index of a specific word in a mnemonic word list defined by the specified language fn find_mnemonic_index_from_word(word: &str, language: MnemonicLanguage) -> Result { - let lowercase_word = word.to_lowercase(); + let lowercase_word = Hidden::hide(word.to_lowercase()); let search_result = match language { // Search through languages are ordered according to the predominance (number of speakers in the world) of that // language MnemonicLanguage::ChineseSimplified => { - MNEMONIC_CHINESE_SIMPLIFIED_WORDS.binary_search(&lowercase_word.as_str()) + MNEMONIC_CHINESE_SIMPLIFIED_WORDS.binary_search(&lowercase_word.reveal().as_str()) + }, + MnemonicLanguage::English => { + MNEMONIC_ENGLISH_WORDS.binary_search(&remove_diacritics(lowercase_word.reveal()).reveal().as_str()) + }, + MnemonicLanguage::French => { + MNEMONIC_FRENCH_WORDS.binary_search(&remove_diacritics(lowercase_word.reveal()).reveal().as_str()) + }, + MnemonicLanguage::Italian => { + MNEMONIC_ITALIAN_WORDS.binary_search(&remove_diacritics(lowercase_word.reveal()).reveal().as_str()) + }, + MnemonicLanguage::Japanese => MNEMONIC_JAPANESE_WORDS.binary_search(&lowercase_word.reveal().as_str()), + MnemonicLanguage::Korean => MNEMONIC_KOREAN_WORDS.binary_search(&lowercase_word.reveal().as_str()), + MnemonicLanguage::Spanish => { + MNEMONIC_SPANISH_WORDS.binary_search(&remove_diacritics(&lowercase_word.reveal()).reveal().as_str()) }, - MnemonicLanguage::English => MNEMONIC_ENGLISH_WORDS.binary_search(&remove_diacritics(&lowercase_word).as_str()), - MnemonicLanguage::French => MNEMONIC_FRENCH_WORDS.binary_search(&remove_diacritics(&lowercase_word).as_str()), - MnemonicLanguage::Italian => MNEMONIC_ITALIAN_WORDS.binary_search(&remove_diacritics(&lowercase_word).as_str()), - MnemonicLanguage::Japanese => MNEMONIC_JAPANESE_WORDS.binary_search(&lowercase_word.as_str()), - MnemonicLanguage::Korean => MNEMONIC_KOREAN_WORDS.binary_search(&lowercase_word.as_str()), - MnemonicLanguage::Spanish => MNEMONIC_SPANISH_WORDS.binary_search(&remove_diacritics(&lowercase_word).as_str()), }; match search_result { Ok(v) => Ok(v), @@ -175,7 +186,7 @@ fn find_mnemonic_word_from_index(index: usize, language: MnemonicLanguage) -> Re } /// Converts a vector of bytes to a sequence of mnemonic words using the specified language -pub fn from_bytes(bytes: &[u8], language: MnemonicLanguage) -> Result, MnemonicError> { +pub fn from_bytes(bytes: &[u8], language: MnemonicLanguage) -> Result { let mut bits = bytes_to_bits(bytes); // Pad with zeros if length not divisible by 11 @@ -198,12 +209,12 @@ pub fn from_bytes(bytes: &[u8], language: MnemonicLanguage) -> Result Result, MnemonicError> { +pub fn to_bytes(mnemonic_seq: &SeedWords) -> Result, MnemonicError> { let language = MnemonicLanguage::detect_language(mnemonic_seq)?; to_bytes_with_language(mnemonic_seq, &language) } @@ -223,14 +234,19 @@ pub fn to_bytes(mnemonic_seq: &[String]) -> Result, MnemonicError> { /// 1) the first output 'a' is last 8 bits from input 'A', we have leftover 3 bits from 'A' /// 2) We add 5 bits from 'B' to generate 'b', the leftover is 6 bits from 'B' /// 3) We add 2 bits from 'C to generate 'c', now we have 8 bits needed to generate 'd' and we have 1 bit leftover. -pub fn to_bytes_with_language(mnemonic_seq: &[String], language: &MnemonicLanguage) -> Result, MnemonicError> { +pub fn to_bytes_with_language(mnemonic_seq: &SeedWords, language: &MnemonicLanguage) -> Result, MnemonicError> { const MASK: u64 = (1u64 << 8) - 1; let mut bytes = Vec::new(); let mut rest = 0u64; let mut rest_bits: u8 = 0; - for curr_word in mnemonic_seq { - let index = find_mnemonic_index_from_word(curr_word, *language)? as u64; + for curr_ind in 0..mnemonic_seq.len() { + let index = find_mnemonic_index_from_word( + mnemonic_seq + .get_word(curr_ind) + .map_err(|_| MnemonicError::IndexOutOfBounds)?, + *language, + )? as u64; // Add 11 bits to the front rest += index << rest_bits; rest_bits += 11; @@ -249,17 +265,17 @@ pub fn to_bytes_with_language(mnemonic_seq: &[String], language: &MnemonicLangua } pub trait Mnemonic { - fn from_mnemonic(mnemonic_seq: &[String], passphrase: Option) -> Result; + fn from_mnemonic(mnemonic_seq: &SeedWords, passphrase: Option) -> Result; fn from_mnemonic_with_language( - mnemonic_seq: &[String], + mnemonic_seq: &SeedWords, language: MnemonicLanguage, - passphrase: Option, + passphrase: Option, ) -> Result; fn to_mnemonic( &self, language: MnemonicLanguage, - passphrase: Option, - ) -> Result, KeyManagerHiddenType>, KeyManagerError>; + passphrase: Option, + ) -> Result; } #[cfg(test)] @@ -339,45 +355,54 @@ mod test { assert!(MnemonicLanguage::from("desvelado").is_err()); // Invalid Mnemonic Spanish word // English/Spanish + English/French -> English - let words1 = vec![ + let words1 = SeedWords::new(&[ "album".to_string(), "area".to_string(), "opera".to_string(), "abandon".to_string(), - ]; + ]); assert_eq!( MnemonicLanguage::detect_language(&words1), Ok(MnemonicLanguage::English) ); // English/Spanish + English/French + Italian/Spanish - let words2 = vec![ + let words2 = SeedWords::new(&[ "album".to_string(), "area".to_string(), "opera".to_string(), "abandon".to_string(), "tipico".to_string(), - ]; + ]); assert!(MnemonicLanguage::detect_language(&words2).is_err()); // bounds check (last word is invalid) - let words3 = vec![ + let words3 = SeedWords::new(&[ "album".to_string(), "area".to_string(), "opera".to_string(), "abandon".to_string(), "topazio".to_string(), - ]; + ]); assert!(MnemonicLanguage::detect_language(&words3).is_err()); // building up a word list: English/French + French -> French let mut words = Vec::with_capacity(3); words.push("concert".to_string()); - assert_eq!(MnemonicLanguage::detect_language(&words), Ok(MnemonicLanguage::English)); + assert_eq!( + MnemonicLanguage::detect_language(&SeedWords::new(&words)), + Ok(MnemonicLanguage::English) + ); words.push("abandon".to_string()); - assert_eq!(MnemonicLanguage::detect_language(&words), Ok(MnemonicLanguage::English)); + assert_eq!( + MnemonicLanguage::detect_language(&SeedWords::new(&words)), + Ok(MnemonicLanguage::English) + ); words.push("barbier".to_string()); - assert_eq!(MnemonicLanguage::detect_language(&words), Ok(MnemonicLanguage::French)); + assert_eq!( + MnemonicLanguage::detect_language(&SeedWords::new(&words)), + Ok(MnemonicLanguage::French) + ); } #[test] diff --git a/base_layer/mmr/Cargo.toml b/base_layer/mmr/Cargo.toml index 9a1ec64034..f785b2dc3f 100644 --- a/base_layer/mmr/Cargo.toml +++ b/base_layer/mmr/Cargo.toml @@ -14,7 +14,7 @@ benches = ["criterion"] [dependencies] tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = {path = "../../common"} thiserror = "1.0.26" digest = "0.9.0" diff --git a/base_layer/p2p/Cargo.toml b/base_layer/p2p/Cargo.toml index 1406b4709d..aebd871eb9 100644 --- a/base_layer/p2p/Cargo.toml +++ b/base_layer/p2p/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" tari_comms = { version = "^0.38", path = "../../comms/core" } tari_comms_dht = { version = "^0.38", path = "../../comms/dht" } tari_common = { version = "^0.38", path = "../../common" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_service_framework = { version = "^0.38", path = "../service_framework" } tari_shutdown = { version = "^0.38", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.38", path = "../../infrastructure/storage" } diff --git a/base_layer/tari_mining_helper_ffi/Cargo.toml b/base_layer/tari_mining_helper_ffi/Cargo.toml index 5a83647f29..ee11b3b66c 100644 --- a/base_layer/tari_mining_helper_ffi/Cargo.toml +++ b/base_layer/tari_mining_helper_ffi/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] tari_comms = { version = "^0.38", path = "../../comms/core" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = { path = "../../common" } tari_core = { path = "../core", default-features = false, features = ["transactions"]} tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } diff --git a/base_layer/wallet/Cargo.toml b/base_layer/wallet/Cargo.toml index d5add7e939..cec377dac7 100644 --- a/base_layer/wallet/Cargo.toml +++ b/base_layer/wallet/Cargo.toml @@ -12,7 +12,7 @@ tari_common = { path = "../../common" } tari_common_types = { version = "^0.38", path = "../../base_layer/common_types" } tari_comms = { version = "^0.38", path = "../../comms/core" } tari_comms_dht = { version = "^0.38", path = "../../comms/dht" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_key_manager = { version = "^0.38", path = "../key_manager" } tari_p2p = { version = "^0.38", path = "../p2p", features = ["auto-update"] } tari_script = { path = "../../infrastructure/tari_script" } @@ -20,7 +20,7 @@ tari_service_framework = { version = "^0.38", path = "../service_framework" } tari_shutdown = { version = "^0.38", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.38", path = "../../infrastructure/storage" } tari_common_sqlite = { path = "../../common_sqlite" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/AaronFeickert/tari_utilities.git", branch = "clandestine" } # Uncomment for tokio tracing via tokio-console (needs "tracing" features) #console-subscriber = "0.1.3" diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index 78b1454e06..e80599a3f5 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -25,6 +25,7 @@ use std::sync::Arc; use chacha20poly1305::XChaCha20Poly1305; use tari_common_types::types::PrivateKey; use tari_key_manager::cipher_seed::CipherSeed; +use tari_utilities::Hidden; use tokio::sync::RwLock; use crate::key_manager_service::{ @@ -85,7 +86,7 @@ where TBackend: KeyManagerBackend + 'static &self, branch: T, index: u64, - ) -> Result { + ) -> Result, KeyManagerServiceError> { (*self.key_manager_inner) .read() .await @@ -96,7 +97,7 @@ where TBackend: KeyManagerBackend + 'static async fn find_key_index + Send>( &self, branch: T, - key: &PrivateKey, + key: Hidden, ) -> Result { (*self.key_manager_inner) .read() diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index a03266e03c..30a16a28e0 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -23,6 +23,7 @@ use chacha20poly1305::XChaCha20Poly1305; use tari_common_types::types::{PrivateKey, PublicKey}; use tari_crypto::keys::PublicKey as PublicKeyTrait; +use tari_utilities::Hidden; use crate::key_manager_service::error::KeyManagerServiceError; @@ -35,13 +36,13 @@ pub enum AddResult { } pub struct NextKeyResult { - pub key: PrivateKey, + pub key: Hidden, pub index: u64, } impl NextKeyResult { pub fn to_public_key(&self) -> PublicKey { - PublicKey::from_secret_key(&self.key) + PublicKey::from_secret_key(self.key.reveal()) } } @@ -70,13 +71,13 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { &self, branch: T, index: u64, - ) -> Result; + ) -> Result, KeyManagerServiceError>; /// Searches the branch to find the index used to generated the key, O(N) where N = index used. async fn find_key_index + Send>( &self, branch: T, - key: &PrivateKey, + key: Hidden, ) -> Result; /// Will update the index of the branch if the index given is higher than the current saved index diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index 3a9ba2a3da..65b634b3b4 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -24,6 +24,7 @@ use chacha20poly1305::XChaCha20Poly1305; use log::*; use tari_common_types::types::PrivateKey; use tari_key_manager::{cipher_seed::CipherSeed, key_manager::KeyManager}; +use tari_utilities::Hidden; use tokio::sync::RwLock; use crate::{ @@ -85,7 +86,7 @@ impl KeyManagerMock { let km = lock.get_mut(&branch).ok_or(KeyManagerServiceError::UnknownKeyBranch)?; let key = km.next_key()?; Ok(NextKeyResult { - key: key.k, + key: Hidden::hide(key.reveal().k), index: km.key_index(), }) } @@ -95,22 +96,26 @@ impl KeyManagerMock { &self, branch: String, index: u64, - ) -> Result { + ) -> Result, KeyManagerServiceError> { let lock = self.key_managers.read().await; let km = lock.get(&branch).ok_or(KeyManagerServiceError::UnknownKeyBranch)?; let key = km.derive_key(index)?; - Ok(key.k) + Ok(Hidden::hide(key.reveal().k)) } /// Search the specified branch key manager key chain to find the index of the specified key. - pub async fn find_key_index_mock(&self, branch: String, key: &PrivateKey) -> Result { + pub async fn find_key_index_mock( + &self, + branch: String, + key: Hidden, + ) -> Result { let lock = self.key_managers.read().await; let km = lock.get(&branch).ok_or(KeyManagerServiceError::UnknownKeyBranch)?; let current_index = km.key_index(); for i in 0u64..current_index + KEY_MANAGER_MAX_SEARCH_DEPTH { - if km.derive_key(i)?.k == *key { + if km.derive_key(i)?.reveal().k == *key.reveal() { trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, i); return Ok(i); } @@ -150,7 +155,7 @@ impl KeyManagerInterface for KeyManagerMock { &self, branch: T, index: u64, - ) -> Result { + ) -> Result, KeyManagerServiceError> { self.get_key_at_index_mock(branch.into(), index).await } @@ -165,7 +170,7 @@ impl KeyManagerInterface for KeyManagerMock { async fn find_key_index + Send>( &self, branch: T, - key: &PrivateKey, + key: Hidden, ) -> Result { self.find_key_index_mock(branch.into(), key).await } diff --git a/base_layer/wallet/src/key_manager_service/service.rs b/base_layer/wallet/src/key_manager_service/service.rs index 9378f6c68b..ef3a749dfd 100644 --- a/base_layer/wallet/src/key_manager_service/service.rs +++ b/base_layer/wallet/src/key_manager_service/service.rs @@ -24,6 +24,7 @@ use futures::lock::Mutex; use log::*; use tari_common_types::types::PrivateKey; use tari_key_manager::{cipher_seed::CipherSeed, key_manager::KeyManager}; +use tari_utilities::Hidden; use crate::types::KeyDigest; @@ -94,12 +95,16 @@ where TBackend: KeyManagerBackend + 'static let key = km.next_key()?; self.db.increment_key_index(branch)?; Ok(NextKeyResult { - key: key.k, + key: Hidden::hide(key.reveal().k), index: km.key_index(), }) } - pub async fn get_key_at_index(&self, branch: String, index: u64) -> Result { + pub async fn get_key_at_index( + &self, + branch: String, + index: u64, + ) -> Result, KeyManagerServiceError> { let km = self .key_managers .get(&branch) @@ -107,7 +112,7 @@ where TBackend: KeyManagerBackend + 'static .lock() .await; let key = km.derive_key(index)?; - Ok(key.k) + Ok(Hidden::hide(key.reveal().k)) } pub fn apply_encryption(&self, cipher: XChaCha20Poly1305) -> Result<(), KeyManagerServiceError> { @@ -121,7 +126,7 @@ where TBackend: KeyManagerBackend + 'static } /// Search the specified branch key manager key chain to find the index of the specified key. - pub async fn find_key_index(&self, branch: String, key: &PrivateKey) -> Result { + pub async fn find_key_index(&self, branch: String, key: Hidden) -> Result { let km = self .key_managers .get(&branch) @@ -132,7 +137,7 @@ where TBackend: KeyManagerBackend + 'static let current_index = km.key_index(); for i in 0u64..current_index + KEY_MANAGER_MAX_SEARCH_DEPTH { - if km.derive_key(i)?.k == *key { + if km.derive_key(i)?.reveal().k == *key.reveal() { trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, i); return Ok(i); } diff --git a/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs b/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs index 00d81a9334..aa3604425e 100644 --- a/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs +++ b/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs @@ -38,6 +38,7 @@ use tari_crypto::{ tari_utilities::hex::Hex, }; use tari_script::{inputs, script, Opcode}; +use tari_utilities::Hidden; use crate::{ key_manager_service::KeyManagerInterface, @@ -203,7 +204,7 @@ where .master_key_manager .find_key_index( OutputManagerKeyManagerBranch::Coinbase.get_branch_key(), - &output.spending_key, + Hidden::hide(output.spending_key), ) .await?; @@ -218,7 +219,7 @@ where .master_key_manager .find_key_index( OutputManagerKeyManagerBranch::Spend.get_branch_key(), - &output.spending_key, + Hidden::hide(output.spending_key), ) .await?; @@ -237,8 +238,8 @@ where .await? }; - output.input_data = inputs!(PublicKey::from_secret_key(&script_key)); - output.script_private_key = script_key; + output.input_data = inputs!(PublicKey::from_secret_key(script_key.reveal())); + output.script_private_key = *script_key.reveal(); Ok(()) } } diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index 7e6ab0b9e3..1f6c65cb1b 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -51,7 +51,6 @@ use tari_key_manager::{ cipher_seed::CipherSeed, key_manager::KeyManager, mnemonic::{Mnemonic, MnemonicLanguage}, - KeyManagerHiddenType, }; use tari_p2p::{ auto_update::{AutoUpdateConfig, SoftwareUpdaterHandle, SoftwareUpdaterService}, @@ -670,10 +669,7 @@ where Ok(self.db.get_client_key_value(RECOVERY_KEY.to_string())?.is_some()) } - pub fn get_seed_words( - &self, - language: &MnemonicLanguage, - ) -> Result, KeyManagerHiddenType>, WalletError> { + pub fn get_seed_words(&self, language: &MnemonicLanguage) -> Result>, WalletError> { let master_seed = self.db.get_master_seed()?.ok_or_else(|| { WalletError::WalletStorageError(WalletStorageError::RecoverySeedError( "Cipher Seed not found".to_string(), @@ -724,7 +720,7 @@ pub fn derive_comms_secret_key(master_seed: &CipherSeed) -> Result Date: Tue, 15 Nov 2022 19:46:03 +0000 Subject: [PATCH 03/20] first commit --- Cargo.lock | 16 ++++++++++++++-- applications/tari_app_grpc/Cargo.toml | 2 +- applications/tari_app_utilities/Cargo.toml | 2 +- applications/tari_base_node/Cargo.toml | 2 +- applications/tari_console_wallet/Cargo.toml | 2 +- applications/tari_merge_mining_proxy/Cargo.toml | 2 +- applications/tari_miner/Cargo.toml | 2 +- base_layer/common_types/Cargo.toml | 2 +- base_layer/core/Cargo.toml | 2 +- base_layer/key_manager/Cargo.toml | 2 +- base_layer/mmr/Cargo.toml | 2 +- base_layer/p2p/Cargo.toml | 2 +- base_layer/tari_mining_helper_ffi/Cargo.toml | 2 +- base_layer/wallet/Cargo.toml | 2 +- base_layer/wallet_ffi/Cargo.toml | 2 +- common/Cargo.toml | 2 +- comms/core/Cargo.toml | 2 +- comms/dht/Cargo.toml | 2 +- infrastructure/tari_script/Cargo.toml | 2 +- 19 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f944c83b16..3ab11e9011 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3977,6 +3977,17 @@ dependencies = [ "serde", ] +[[package]] +name = "serde-wasm-bindgen" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfc62771e7b829b517cb213419236475f434fb480eddd76112ae182d274434a" +dependencies = [ + "js-sys", + "serde", + "wasm-bindgen", +] + [[package]] name = "serde_cbor" version = "0.11.2" @@ -4746,8 +4757,8 @@ dependencies = [ [[package]] name = "tari_crypto" -version = "0.15.7" -source = "git+https://github.com/tari-project/tari-crypto.git?tag=v0.15.7#bd66b3d2021bf0b391d50f1ba8db339a62231738" +version = "0.16.0" +source = "git+https://github.com/tari-project/tari-crypto.git?tag=v0.16.0#8f3bce7ed1ece78d58c90ba9abda59cbfa0863f6" dependencies = [ "base64 0.10.1", "blake2 0.9.2", @@ -4761,6 +4772,7 @@ dependencies = [ "once_cell", "rand 0.7.3", "serde", + "serde-wasm-bindgen", "serde_json", "sha3", "tari_bulletproofs", diff --git a/applications/tari_app_grpc/Cargo.toml b/applications/tari_app_grpc/Cargo.toml index 63e8da20d6..45e6643566 100644 --- a/applications/tari_app_grpc/Cargo.toml +++ b/applications/tari_app_grpc/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" tari_common_types = { version = "^0.39", path = "../../base_layer/common_types" } tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_script = { path = "../../infrastructure/tari_script" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } diff --git a/applications/tari_app_utilities/Cargo.toml b/applications/tari_app_utilities/Cargo.toml index c3c76d18a8..3142a36754 100644 --- a/applications/tari_app_utilities/Cargo.toml +++ b/applications/tari_app_utilities/Cargo.toml @@ -7,7 +7,7 @@ license = "BSD-3-Clause" [dependencies] tari_comms = { path = "../../comms/core" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = { path = "../../common" } tari_common_types = { path = "../../base_layer/common_types" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } diff --git a/applications/tari_base_node/Cargo.toml b/applications/tari_base_node/Cargo.toml index fa625485e2..0b10d73ec1 100644 --- a/applications/tari_base_node/Cargo.toml +++ b/applications/tari_base_node/Cargo.toml @@ -15,7 +15,7 @@ tari_comms = { path = "../../comms/core", features = ["rpc"] } tari_common_types = { path = "../../base_layer/common_types" } tari_comms_dht = { path = "../../comms/dht" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_libtor = { path = "../../infrastructure/libtor", optional = true } tari_mmr = { path = "../../base_layer/mmr", features = ["native_bitmap"] } tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index a6c2752718..90ecc4e402 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -7,7 +7,7 @@ license = "BSD-3-Clause" [dependencies] tari_wallet = { path = "../../base_layer/wallet", features = ["bundled_sqlite"] } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = { path = "../../common" } tari_app_utilities = { path = "../tari_app_utilities" } tari_comms = { path = "../../comms/core" } diff --git a/applications/tari_merge_mining_proxy/Cargo.toml b/applications/tari_merge_mining_proxy/Cargo.toml index 54cf3b85ea..a82842d3dd 100644 --- a/applications/tari_merge_mining_proxy/Cargo.toml +++ b/applications/tari_merge_mining_proxy/Cargo.toml @@ -15,7 +15,7 @@ tari_common = { path = "../../common" } tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] } tari_app_utilities = { path = "../tari_app_utilities" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } tari_base_node_grpc_client = {path="../../clients/rust/base_node_grpc_client" } tari_wallet_grpc_client = {path="../../clients/rust/wallet_grpc_client" } diff --git a/applications/tari_miner/Cargo.toml b/applications/tari_miner/Cargo.toml index c30372421a..85c01c495e 100644 --- a/applications/tari_miner/Cargo.toml +++ b/applications/tari_miner/Cargo.toml @@ -14,7 +14,7 @@ tari_common_types = { path = "../../base_layer/common_types" } tari_comms = { path = "../../comms/core" } tari_app_utilities = { path = "../tari_app_utilities" } tari_app_grpc = { path = "../tari_app_grpc" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } crossterm = { version = "0.25.0" } diff --git a/base_layer/common_types/Cargo.toml b/base_layer/common_types/Cargo.toml index 48fa9857e2..d42e15332d 100644 --- a/base_layer/common_types/Cargo.toml +++ b/base_layer/common_types/Cargo.toml @@ -7,7 +7,7 @@ version = "0.39.0" edition = "2018" [dependencies] -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } tari_common = { version = "^0.39", path = "../../common" } diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 846893dce6..fdfe8addb1 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -24,7 +24,7 @@ tari_common_types = { version = "^0.39", path = "../../base_layer/common_types" tari_comms = { version = "^0.39", path = "../../comms/core" } tari_comms_dht = { version = "^0.39", path = "../../comms/dht" } tari_comms_rpc_macros = { version = "^0.39", path = "../../comms/rpc_macros" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_metrics = { path = "../../infrastructure/metrics" } tari_mmr = { version = "^0.39", path = "../../base_layer/mmr", optional = true, features = ["native_bitmap"] } tari_p2p = { version = "^0.39", path = "../../base_layer/p2p" } diff --git a/base_layer/key_manager/Cargo.toml b/base_layer/key_manager/Cargo.toml index 3879dae20c..2eaf280371 100644 --- a/base_layer/key_manager/Cargo.toml +++ b/base_layer/key_manager/Cargo.toml @@ -13,7 +13,7 @@ crate-type = ["lib", "cdylib"] # NB: All dependencies must support or be gated for the WASM target. [dependencies] tari_common_types = { version = "^0.39", path = "../../base_layer/common_types", optional = true } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } argon2 = { version = "0.4.1", features = ["std", "alloc"] } diff --git a/base_layer/mmr/Cargo.toml b/base_layer/mmr/Cargo.toml index 8825e65618..8e819d425a 100644 --- a/base_layer/mmr/Cargo.toml +++ b/base_layer/mmr/Cargo.toml @@ -14,7 +14,7 @@ benches = ["criterion"] [dependencies] tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = {path = "../../common"} thiserror = "1.0.26" digest = "0.9.0" diff --git a/base_layer/p2p/Cargo.toml b/base_layer/p2p/Cargo.toml index 9c7b4a3565..c07f9322b7 100644 --- a/base_layer/p2p/Cargo.toml +++ b/base_layer/p2p/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" tari_comms = { version = "^0.39", path = "../../comms/core" } tari_comms_dht = { version = "^0.39", path = "../../comms/dht" } tari_common = { version = "^0.39", path = "../../common" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_service_framework = { version = "^0.39", path = "../service_framework" } tari_shutdown = { version = "^0.39", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.39", path = "../../infrastructure/storage" } diff --git a/base_layer/tari_mining_helper_ffi/Cargo.toml b/base_layer/tari_mining_helper_ffi/Cargo.toml index 9fe113f653..bc47f5bcbb 100644 --- a/base_layer/tari_mining_helper_ffi/Cargo.toml +++ b/base_layer/tari_mining_helper_ffi/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] tari_comms = { version = "^0.39", path = "../../comms/core" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = { path = "../../common" } tari_core = { path = "../core", default-features = false, features = ["transactions"]} tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } diff --git a/base_layer/wallet/Cargo.toml b/base_layer/wallet/Cargo.toml index 13594ebe99..429129cfe6 100644 --- a/base_layer/wallet/Cargo.toml +++ b/base_layer/wallet/Cargo.toml @@ -12,7 +12,7 @@ tari_common = { path = "../../common" } tari_common_types = { version = "^0.39", path = "../../base_layer/common_types" } tari_comms = { version = "^0.39", path = "../../comms/core" } tari_comms_dht = { version = "^0.39", path = "../../comms/dht" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_key_manager = { version = "^0.39", path = "../key_manager" } tari_p2p = { version = "^0.39", path = "../p2p", features = ["auto-update"] } tari_script = { path = "../../infrastructure/tari_script" } diff --git a/base_layer/wallet_ffi/Cargo.toml b/base_layer/wallet_ffi/Cargo.toml index 9a7e980b81..8c4d23f49a 100644 --- a/base_layer/wallet_ffi/Cargo.toml +++ b/base_layer/wallet_ffi/Cargo.toml @@ -12,7 +12,7 @@ tari_common = {path="../../common"} tari_common_types = {path="../common_types"} tari_comms = { version = "^0.39", path = "../../comms/core", features = ["c_integration"]} tari_comms_dht = { version = "^0.39", path = "../../comms/dht", default-features = false } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_key_manager = { version = "^0.39", path = "../key_manager" } tari_p2p = { version = "^0.39", path = "../p2p" } tari_script = { path = "../../infrastructure/tari_script" } diff --git a/common/Cargo.toml b/common/Cargo.toml index 5e70bc587a..6dfb3fa93b 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -14,7 +14,7 @@ build = ["toml", "prost-build"] static-application-info = ["git2"] [dependencies] -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } anyhow = "1.0.53" config = { version = "0.13.0", default_features = false, features = ["toml"] } diff --git a/comms/core/Cargo.toml b/comms/core/Cargo.toml index 29afaae193..47e7082653 100644 --- a/comms/core/Cargo.toml +++ b/comms/core/Cargo.toml @@ -10,7 +10,7 @@ version = "0.39.0" edition = "2018" [dependencies] -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_common = {path = "../../common"} tari_metrics = { path = "../../infrastructure/metrics" } tari_storage = { version = "^0.39", path = "../../infrastructure/storage" } diff --git a/comms/dht/Cargo.toml b/comms/dht/Cargo.toml index f0ebe28e72..2f51d72134 100644 --- a/comms/dht/Cargo.toml +++ b/comms/dht/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" tari_comms = { version = "^0.39", path = "../core", features = ["rpc"] } tari_common = { path = "../../common" } tari_comms_rpc_macros = { version = "^0.39", path = "../rpc_macros" } -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } tari_shutdown = { version = "^0.39", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.39", path = "../../infrastructure/storage" } diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 17d8586260..c0078082e2 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" license = "BSD-3-Clause" [dependencies] -tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.15.7" } +tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } blake2 = "0.9" From 8b5dca7f33d1e5823c3040acba7d5b6aa57cda2d Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 16 Nov 2022 11:15:22 +0000 Subject: [PATCH 04/20] address PR changes --- Cargo.lock | 2 +- base_layer/key_manager/Cargo.toml | 2 +- base_layer/key_manager/src/cipher_seed.rs | 8 ++-- base_layer/key_manager/src/lib.rs | 11 +++-- base_layer/key_manager/src/mnemonic.rs | 56 +++++++++++------------ 5 files changed, 40 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec8393e6ca..62df932352 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4874,7 +4874,7 @@ dependencies = [ "subtle", "tari_common_types", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.8", "thiserror", "wasm-bindgen", "wasm-bindgen-test", diff --git a/base_layer/key_manager/Cargo.toml b/base_layer/key_manager/Cargo.toml index 2eaf280371..46b36bf924 100644 --- a/base_layer/key_manager/Cargo.toml +++ b/base_layer/key_manager/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["lib", "cdylib"] [dependencies] tari_common_types = { version = "^0.39", path = "../../base_layer/common_types", optional = true } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.0" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/AaronFeickert/tari_utilities.git", branch="clandestine" } argon2 = { version = "0.4.1", features = ["std", "alloc"] } blake2 = "0.9.1" diff --git a/base_layer/key_manager/src/cipher_seed.rs b/base_layer/key_manager/src/cipher_seed.rs index 35eba4efd8..efe0a353c4 100644 --- a/base_layer/key_manager/src/cipher_seed.rs +++ b/base_layer/key_manager/src/cipher_seed.rs @@ -439,7 +439,7 @@ mod test { use std::str::FromStr; use crc32fast::Hasher as CrcHasher; - use tari_utilities::SafePassword; + use tari_utilities::{Hidden, SafePassword}; use super::BIRTHDAY_GENESIS_FROM_UNIX_EPOCH; use crate::{ @@ -594,9 +594,9 @@ mod test { "cover", "vote", "federal", "husband", "cave", "alone", "dynamic", "reopen", "visa", "young", "gas", ] .iter() - .map(|x| x.to_string()) - .collect::>(); - let mnemonic_seq = SeedWords::new(&mnemonic_seq); + .map(|x| Hidden::hide(x.to_string())) + .collect::>>(); + let mnemonic_seq = SeedWords::new(mnemonic_seq); // Language not known match CipherSeed::from_mnemonic(&mnemonic_seq, None) { Ok(_k) => panic!(), diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index 51068e5aad..8cca15145b 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -3,7 +3,6 @@ use cipher_seed::BIRTHDAY_GENESIS_FROM_UNIX_EPOCH; use digest::Digest; -use serde::{Deserialize, Serialize}; use tari_crypto::{ hash_domain, hashing::{DomainSeparatedHasher, LengthExtensionAttackResistant}, @@ -57,10 +56,8 @@ pub struct SeedWords { } impl SeedWords { - pub fn new(words: &[String]) -> Self { - Self { - words: words.into_iter().map(|m| Hidden::hide(m.clone())).collect::>(), - } + pub fn new(words: Vec>) -> Self { + Self { words } } pub fn len(&self) -> usize { @@ -74,4 +71,8 @@ impl SeedWords { Ok(self.words[index].reveal()) } + + pub fn is_empty(&self) -> bool { + self.words.is_empty() + } } diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index 2ac02eba7f..bcd4fe8455 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -57,7 +57,7 @@ pub enum MnemonicLanguage { impl MnemonicLanguage { /// Detects the mnemonic language of a specific word by searching all defined mnemonic word lists pub fn from(mnemonic_word: &str) -> Result { - let words = SeedWords::new(&[mnemonic_word.to_string()]); + let words = SeedWords::new(vec![Hidden::hide(mnemonic_word.to_string())]); MnemonicLanguage::detect_language(&words) } @@ -157,7 +157,7 @@ fn find_mnemonic_index_from_word(word: &str, language: MnemonicLanguage) -> Resu MnemonicLanguage::Japanese => MNEMONIC_JAPANESE_WORDS.binary_search(&lowercase_word.reveal().as_str()), MnemonicLanguage::Korean => MNEMONIC_KOREAN_WORDS.binary_search(&lowercase_word.reveal().as_str()), MnemonicLanguage::Spanish => { - MNEMONIC_SPANISH_WORDS.binary_search(&remove_diacritics(&lowercase_word.reveal()).reveal().as_str()) + MNEMONIC_SPANISH_WORDS.binary_search(&remove_diacritics(lowercase_word.reveal()).reveal().as_str()) }, }; match search_result { @@ -199,17 +199,17 @@ pub fn from_bytes(bytes: &[u8], language: MnemonicLanguage) -> Result = Vec::new(); + let mut mnemonic_sequence: Vec> = Vec::new(); for i in 0..bits.len() / group_bit_count { let start_index = i * group_bit_count; let stop_index = start_index + group_bit_count; let sub_v = &bits[start_index..stop_index]; let word_index = checked_bits_to_uint(sub_v).ok_or(MnemonicError::BitsToIntConversion)?; - let mnemonic_word = find_mnemonic_word_from_index(word_index, language)?; + let mnemonic_word = Hidden::hide(find_mnemonic_word_from_index(word_index, language)?); mnemonic_sequence.push(mnemonic_word); } - Ok(SeedWords::new(mnemonic_sequence.as_slice())) + Ok(SeedWords::new(mnemonic_sequence)) } /// Generates a vector of bytes that represent the provided mnemonic sequence of words, the language of the mnemonic @@ -355,11 +355,11 @@ mod test { assert!(MnemonicLanguage::from("desvelado").is_err()); // Invalid Mnemonic Spanish word // English/Spanish + English/French -> English - let words1 = SeedWords::new(&[ - "album".to_string(), - "area".to_string(), - "opera".to_string(), - "abandon".to_string(), + let words1 = SeedWords::new(vec![ + Hidden::hide("album".to_string()), + Hidden::hide("area".to_string()), + Hidden::hide("opera".to_string()), + Hidden::hide("abandon".to_string()), ]); assert_eq!( MnemonicLanguage::detect_language(&words1), @@ -367,40 +367,40 @@ mod test { ); // English/Spanish + English/French + Italian/Spanish - let words2 = SeedWords::new(&[ - "album".to_string(), - "area".to_string(), - "opera".to_string(), - "abandon".to_string(), - "tipico".to_string(), + let words2 = SeedWords::new(vec![ + Hidden::hide("album".to_string()), + Hidden::hide("area".to_string()), + Hidden::hide("opera".to_string()), + Hidden::hide("abandon".to_string()), + Hidden::hide("tipico".to_string()), ]); assert!(MnemonicLanguage::detect_language(&words2).is_err()); // bounds check (last word is invalid) - let words3 = SeedWords::new(&[ - "album".to_string(), - "area".to_string(), - "opera".to_string(), - "abandon".to_string(), - "topazio".to_string(), + let words3 = SeedWords::new(vec![ + Hidden::hide("album".to_string()), + Hidden::hide("area".to_string()), + Hidden::hide("opera".to_string()), + Hidden::hide("abandon".to_string()), + Hidden::hide("topazio".to_string()), ]); assert!(MnemonicLanguage::detect_language(&words3).is_err()); // building up a word list: English/French + French -> French let mut words = Vec::with_capacity(3); - words.push("concert".to_string()); + words.push(Hidden::hide("concert".to_string())); assert_eq!( - MnemonicLanguage::detect_language(&SeedWords::new(&words)), + MnemonicLanguage::detect_language(&SeedWords::new(words.clone())), Ok(MnemonicLanguage::English) ); - words.push("abandon".to_string()); + words.push(Hidden::hide("abandon".to_string())); assert_eq!( - MnemonicLanguage::detect_language(&SeedWords::new(&words)), + MnemonicLanguage::detect_language(&SeedWords::new(words.clone())), Ok(MnemonicLanguage::English) ); - words.push("barbier".to_string()); + words.push(Hidden::hide("barbier".to_string())); assert_eq!( - MnemonicLanguage::detect_language(&SeedWords::new(&words)), + MnemonicLanguage::detect_language(&SeedWords::new(words)), Ok(MnemonicLanguage::French) ); } From 1f0c191e0b16fa3f2664cdacdafdc55637dbae4e Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Wed, 16 Nov 2022 12:33:55 +0000 Subject: [PATCH 05/20] revert unnecessary changes --- base_layer/key_manager/src/cipher_seed.rs | 1 - base_layer/key_manager/src/key_manager.rs | 29 +++++++++---------- .../wallet/src/key_manager_service/handle.rs | 5 ++-- .../src/key_manager_service/interface.rs | 9 +++--- .../wallet/src/key_manager_service/mock.rs | 19 +++++------- .../wallet/src/key_manager_service/service.rs | 15 ++++------ .../recovery/standard_outputs_recoverer.rs | 9 +++--- base_layer/wallet/src/wallet.rs | 6 ++-- 8 files changed, 39 insertions(+), 54 deletions(-) diff --git a/base_layer/key_manager/src/cipher_seed.rs b/base_layer/key_manager/src/cipher_seed.rs index efe0a353c4..9c75effeae 100644 --- a/base_layer/key_manager/src/cipher_seed.rs +++ b/base_layer/key_manager/src/cipher_seed.rs @@ -356,7 +356,6 @@ impl CipherSeed { } /// Use Argon2 to derive encryption and MAC keys from a passphrase and main salt - // TODO: passhphrase should be SafePassword fn derive_keys(passphrase: &SafePassword, salt: &[u8]) -> DerivedCipherSeedKeys { // The Argon2 salt is derived from the main salt let argon2_salt = mac_domain_hasher::(LABEL_ARGON_ENCODING) diff --git a/base_layer/key_manager/src/key_manager.rs b/base_layer/key_manager/src/key_manager.rs index 70248a0c95..598152a256 100644 --- a/base_layer/key_manager/src/key_manager.rs +++ b/base_layer/key_manager/src/key_manager.rs @@ -30,7 +30,6 @@ use tari_crypto::{ keys::SecretKey, tari_utilities::byte_array::ByteArrayError, }; -use tari_utilities::Hidden; use zeroize::Zeroize; use crate::{cipher_seed::CipherSeed, mac_domain_hasher, LABEL_DERIVE_KEY}; @@ -87,7 +86,7 @@ where /// Derive a new private key from master key: derived_key=H(master_key||branch_seed||index), for some /// hash function H which is Length attack resistant, such as Blake2b. - pub fn derive_key(&self, key_index: u64) -> Result>, ByteArrayError> { + pub fn derive_key(&self, key_index: u64) -> Result, ByteArrayError> { // apply domain separation to generate derive key. Under the hood, the hashing api prepends the length of each // piece of data for concatenation, reducing the risk of collisions due to redundancy of variable length // input @@ -100,13 +99,13 @@ where let derive_key = derive_key.as_ref(); match K::from_bytes(derive_key) { - Ok(k) => Ok(Hidden::>::hide(DerivedKey { k, key_index })), + Ok(k) => Ok(DerivedKey { k, key_index }), Err(e) => Err(e), } } /// Generate next deterministic private key derived from master key - pub fn next_key(&mut self) -> Result>, ByteArrayError> { + pub fn next_key(&mut self) -> Result, ByteArrayError> { self.primary_key_index += 1; self.derive_key(self.primary_key_index) } @@ -160,11 +159,11 @@ mod test { let next_key2 = next_key2_result.unwrap(); let derived_key1 = derived_key1_result.unwrap(); let derived_key2 = derived_key2_result.unwrap(); - assert_ne!(next_key1.reveal().k, next_key2.reveal().k); - assert_eq!(next_key1.reveal().k, derived_key1.reveal().k); - assert_eq!(next_key2.reveal().k, derived_key2.reveal().k); - assert_eq!(next_key1.reveal().key_index, desired_key_index1); - assert_eq!(next_key2.reveal().key_index, desired_key_index2); + assert_ne!(next_key1.k, next_key2.k); + assert_eq!(next_key1.k, derived_key1.k); + assert_eq!(next_key2.k, derived_key2.k); + assert_eq!(next_key1.key_index, desired_key_index1); + assert_eq!(next_key2.key_index, desired_key_index2); } #[test] @@ -180,11 +179,11 @@ mod test { let next_key2 = next_key2_result.unwrap(); let derived_key1 = derived_key1_result.unwrap(); let derived_key2 = derived_key2_result.unwrap(); - assert_ne!(next_key1.reveal().k, next_key2.reveal().k); - assert_eq!(next_key1.reveal().k, derived_key1.reveal().k); - assert_eq!(next_key2.reveal().k, derived_key2.reveal().k); - assert_eq!(next_key1.reveal().key_index, desired_key_index1); - assert_eq!(next_key2.reveal().key_index, desired_key_index2); + assert_ne!(next_key1.k, next_key2.k); + assert_eq!(next_key1.k, derived_key1.k); + assert_eq!(next_key2.k, derived_key2.k); + assert_eq!(next_key1.key_index, desired_key_index1); + assert_eq!(next_key2.key_index, desired_key_index2); } #[test] @@ -194,6 +193,6 @@ mod test { let mut km2 = KeyManager::::from(x, "other".to_string(), 0); let next_key1 = km1.next_key().unwrap(); let next_key2 = km2.next_key().unwrap(); - assert_ne!(next_key1.reveal().k, next_key2.reveal().k); + assert_ne!(next_key1.k, next_key2.k); } } diff --git a/base_layer/wallet/src/key_manager_service/handle.rs b/base_layer/wallet/src/key_manager_service/handle.rs index e80599a3f5..78b1454e06 100644 --- a/base_layer/wallet/src/key_manager_service/handle.rs +++ b/base_layer/wallet/src/key_manager_service/handle.rs @@ -25,7 +25,6 @@ use std::sync::Arc; use chacha20poly1305::XChaCha20Poly1305; use tari_common_types::types::PrivateKey; use tari_key_manager::cipher_seed::CipherSeed; -use tari_utilities::Hidden; use tokio::sync::RwLock; use crate::key_manager_service::{ @@ -86,7 +85,7 @@ where TBackend: KeyManagerBackend + 'static &self, branch: T, index: u64, - ) -> Result, KeyManagerServiceError> { + ) -> Result { (*self.key_manager_inner) .read() .await @@ -97,7 +96,7 @@ where TBackend: KeyManagerBackend + 'static async fn find_key_index + Send>( &self, branch: T, - key: Hidden, + key: &PrivateKey, ) -> Result { (*self.key_manager_inner) .read() diff --git a/base_layer/wallet/src/key_manager_service/interface.rs b/base_layer/wallet/src/key_manager_service/interface.rs index 30a16a28e0..a03266e03c 100644 --- a/base_layer/wallet/src/key_manager_service/interface.rs +++ b/base_layer/wallet/src/key_manager_service/interface.rs @@ -23,7 +23,6 @@ use chacha20poly1305::XChaCha20Poly1305; use tari_common_types::types::{PrivateKey, PublicKey}; use tari_crypto::keys::PublicKey as PublicKeyTrait; -use tari_utilities::Hidden; use crate::key_manager_service::error::KeyManagerServiceError; @@ -36,13 +35,13 @@ pub enum AddResult { } pub struct NextKeyResult { - pub key: Hidden, + pub key: PrivateKey, pub index: u64, } impl NextKeyResult { pub fn to_public_key(&self) -> PublicKey { - PublicKey::from_secret_key(self.key.reveal()) + PublicKey::from_secret_key(&self.key) } } @@ -71,13 +70,13 @@ pub trait KeyManagerInterface: Clone + Send + Sync + 'static { &self, branch: T, index: u64, - ) -> Result, KeyManagerServiceError>; + ) -> Result; /// Searches the branch to find the index used to generated the key, O(N) where N = index used. async fn find_key_index + Send>( &self, branch: T, - key: Hidden, + key: &PrivateKey, ) -> Result; /// Will update the index of the branch if the index given is higher than the current saved index diff --git a/base_layer/wallet/src/key_manager_service/mock.rs b/base_layer/wallet/src/key_manager_service/mock.rs index 65b634b3b4..3a9ba2a3da 100644 --- a/base_layer/wallet/src/key_manager_service/mock.rs +++ b/base_layer/wallet/src/key_manager_service/mock.rs @@ -24,7 +24,6 @@ use chacha20poly1305::XChaCha20Poly1305; use log::*; use tari_common_types::types::PrivateKey; use tari_key_manager::{cipher_seed::CipherSeed, key_manager::KeyManager}; -use tari_utilities::Hidden; use tokio::sync::RwLock; use crate::{ @@ -86,7 +85,7 @@ impl KeyManagerMock { let km = lock.get_mut(&branch).ok_or(KeyManagerServiceError::UnknownKeyBranch)?; let key = km.next_key()?; Ok(NextKeyResult { - key: Hidden::hide(key.reveal().k), + key: key.k, index: km.key_index(), }) } @@ -96,26 +95,22 @@ impl KeyManagerMock { &self, branch: String, index: u64, - ) -> Result, KeyManagerServiceError> { + ) -> Result { let lock = self.key_managers.read().await; let km = lock.get(&branch).ok_or(KeyManagerServiceError::UnknownKeyBranch)?; let key = km.derive_key(index)?; - Ok(Hidden::hide(key.reveal().k)) + Ok(key.k) } /// Search the specified branch key manager key chain to find the index of the specified key. - pub async fn find_key_index_mock( - &self, - branch: String, - key: Hidden, - ) -> Result { + pub async fn find_key_index_mock(&self, branch: String, key: &PrivateKey) -> Result { let lock = self.key_managers.read().await; let km = lock.get(&branch).ok_or(KeyManagerServiceError::UnknownKeyBranch)?; let current_index = km.key_index(); for i in 0u64..current_index + KEY_MANAGER_MAX_SEARCH_DEPTH { - if km.derive_key(i)?.reveal().k == *key.reveal() { + if km.derive_key(i)?.k == *key { trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, i); return Ok(i); } @@ -155,7 +150,7 @@ impl KeyManagerInterface for KeyManagerMock { &self, branch: T, index: u64, - ) -> Result, KeyManagerServiceError> { + ) -> Result { self.get_key_at_index_mock(branch.into(), index).await } @@ -170,7 +165,7 @@ impl KeyManagerInterface for KeyManagerMock { async fn find_key_index + Send>( &self, branch: T, - key: Hidden, + key: &PrivateKey, ) -> Result { self.find_key_index_mock(branch.into(), key).await } diff --git a/base_layer/wallet/src/key_manager_service/service.rs b/base_layer/wallet/src/key_manager_service/service.rs index ef3a749dfd..9378f6c68b 100644 --- a/base_layer/wallet/src/key_manager_service/service.rs +++ b/base_layer/wallet/src/key_manager_service/service.rs @@ -24,7 +24,6 @@ use futures::lock::Mutex; use log::*; use tari_common_types::types::PrivateKey; use tari_key_manager::{cipher_seed::CipherSeed, key_manager::KeyManager}; -use tari_utilities::Hidden; use crate::types::KeyDigest; @@ -95,16 +94,12 @@ where TBackend: KeyManagerBackend + 'static let key = km.next_key()?; self.db.increment_key_index(branch)?; Ok(NextKeyResult { - key: Hidden::hide(key.reveal().k), + key: key.k, index: km.key_index(), }) } - pub async fn get_key_at_index( - &self, - branch: String, - index: u64, - ) -> Result, KeyManagerServiceError> { + pub async fn get_key_at_index(&self, branch: String, index: u64) -> Result { let km = self .key_managers .get(&branch) @@ -112,7 +107,7 @@ where TBackend: KeyManagerBackend + 'static .lock() .await; let key = km.derive_key(index)?; - Ok(Hidden::hide(key.reveal().k)) + Ok(key.k) } pub fn apply_encryption(&self, cipher: XChaCha20Poly1305) -> Result<(), KeyManagerServiceError> { @@ -126,7 +121,7 @@ where TBackend: KeyManagerBackend + 'static } /// Search the specified branch key manager key chain to find the index of the specified key. - pub async fn find_key_index(&self, branch: String, key: Hidden) -> Result { + pub async fn find_key_index(&self, branch: String, key: &PrivateKey) -> Result { let km = self .key_managers .get(&branch) @@ -137,7 +132,7 @@ where TBackend: KeyManagerBackend + 'static let current_index = km.key_index(); for i in 0u64..current_index + KEY_MANAGER_MAX_SEARCH_DEPTH { - if km.derive_key(i)?.reveal().k == *key.reveal() { + if km.derive_key(i)?.k == *key { trace!(target: LOG_TARGET, "Key found in {} Key Chain at index {}", branch, i); return Ok(i); } diff --git a/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs b/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs index aa3604425e..00d81a9334 100644 --- a/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs +++ b/base_layer/wallet/src/output_manager_service/recovery/standard_outputs_recoverer.rs @@ -38,7 +38,6 @@ use tari_crypto::{ tari_utilities::hex::Hex, }; use tari_script::{inputs, script, Opcode}; -use tari_utilities::Hidden; use crate::{ key_manager_service::KeyManagerInterface, @@ -204,7 +203,7 @@ where .master_key_manager .find_key_index( OutputManagerKeyManagerBranch::Coinbase.get_branch_key(), - Hidden::hide(output.spending_key), + &output.spending_key, ) .await?; @@ -219,7 +218,7 @@ where .master_key_manager .find_key_index( OutputManagerKeyManagerBranch::Spend.get_branch_key(), - Hidden::hide(output.spending_key), + &output.spending_key, ) .await?; @@ -238,8 +237,8 @@ where .await? }; - output.input_data = inputs!(PublicKey::from_secret_key(script_key.reveal())); - output.script_private_key = *script_key.reveal(); + output.input_data = inputs!(PublicKey::from_secret_key(&script_key)); + output.script_private_key = script_key; Ok(()) } } diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index af26b0cc63..4514c36d1b 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -64,7 +64,7 @@ use tari_p2p::{ use tari_script::{script, ExecutionStack, TariScript}; use tari_service_framework::StackBuilder; use tari_shutdown::ShutdownSignal; -use tari_utilities::{ByteArray, Hidden, SafePassword}; +use tari_utilities::{ByteArray, SafePassword}; use crate::{ base_node_service::{handle::BaseNodeServiceHandle, BaseNodeServiceInitializer}, @@ -672,7 +672,7 @@ where Ok(self.db.get_client_key_value(RECOVERY_KEY.to_string())?.is_some()) } - pub fn get_seed_words(&self, language: &MnemonicLanguage) -> Result>, WalletError> { + pub fn get_seed_words(&self, language: &MnemonicLanguage) -> Result { let master_seed = self.db.get_master_seed()?.ok_or_else(|| { WalletError::WalletStorageError(WalletStorageError::RecoverySeedError( "Cipher Seed not found".to_string(), @@ -723,7 +723,7 @@ pub fn derive_comms_secret_key(master_seed: &CipherSeed) -> Result Date: Thu, 17 Nov 2022 08:19:56 +0000 Subject: [PATCH 06/20] add imports --- base_layer/wallet/src/wallet.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/base_layer/wallet/src/wallet.rs b/base_layer/wallet/src/wallet.rs index 4514c36d1b..edd73480df 100644 --- a/base_layer/wallet/src/wallet.rs +++ b/base_layer/wallet/src/wallet.rs @@ -52,6 +52,7 @@ use tari_key_manager::{ cipher_seed::CipherSeed, key_manager::KeyManager, mnemonic::{Mnemonic, MnemonicLanguage}, + SeedWords, }; use tari_p2p::{ auto_update::{AutoUpdateConfig, SoftwareUpdaterHandle, SoftwareUpdaterService}, From f39caac7a34317b8a69ff67ea7417995b9e317e5 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Thu, 17 Nov 2022 08:21:19 +0000 Subject: [PATCH 07/20] add serde imports --- base_layer/key_manager/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index 8cca15145b..67c1e00b26 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -3,6 +3,7 @@ use cipher_seed::BIRTHDAY_GENESIS_FROM_UNIX_EPOCH; use digest::Digest; +use serde::{Deserialize, Serialize}; use tari_crypto::{ hash_domain, hashing::{DomainSeparatedHasher, LengthExtensionAttackResistant}, From bf78cd6228cb0e796597baa29e30656428ff8a27 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 18 Nov 2022 09:36:03 +0000 Subject: [PATCH 08/20] update tari-utilities tag version --- applications/tari_app_grpc/Cargo.toml | 2 +- applications/tari_app_utilities/Cargo.toml | 2 +- applications/tari_base_node/Cargo.toml | 2 +- applications/tari_console_wallet/Cargo.toml | 2 +- applications/tari_merge_mining_proxy/Cargo.toml | 2 +- applications/tari_miner/Cargo.toml | 2 +- base_layer/common_types/Cargo.toml | 2 +- base_layer/core/Cargo.toml | 2 +- base_layer/key_manager/Cargo.toml | 2 +- base_layer/mmr/Cargo.toml | 2 +- base_layer/p2p/Cargo.toml | 2 +- base_layer/tari_mining_helper_ffi/Cargo.toml | 2 +- base_layer/wallet_ffi/Cargo.toml | 2 +- comms/core/Cargo.toml | 2 +- comms/dht/Cargo.toml | 2 +- infrastructure/storage/Cargo.toml | 2 +- infrastructure/tari_script/Cargo.toml | 2 +- 17 files changed, 17 insertions(+), 17 deletions(-) diff --git a/applications/tari_app_grpc/Cargo.toml b/applications/tari_app_grpc/Cargo.toml index cfc1c4c155..4926957147 100644 --- a/applications/tari_app_grpc/Cargo.toml +++ b/applications/tari_app_grpc/Cargo.toml @@ -13,7 +13,7 @@ tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } tari_script = { path = "../../infrastructure/tari_script" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } argon2 = { version = "0.4.1", features = ["std", "password-hash"] } base64 = "0.13.0" diff --git a/applications/tari_app_utilities/Cargo.toml b/applications/tari_app_utilities/Cargo.toml index 0c69fa1253..e98322ff42 100644 --- a/applications/tari_app_utilities/Cargo.toml +++ b/applications/tari_app_utilities/Cargo.toml @@ -10,7 +10,7 @@ tari_comms = { path = "../../comms/core" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } tari_common = { path = "../../common" } tari_common_types = { path = "../../base_layer/common_types" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } clap = { version = "3.2.0", features = ["derive", "env"] } config = { version = "0.13.0" } diff --git a/applications/tari_base_node/Cargo.toml b/applications/tari_base_node/Cargo.toml index 5b5de4dcb0..e7bfab9a61 100644 --- a/applications/tari_base_node/Cargo.toml +++ b/applications/tari_base_node/Cargo.toml @@ -22,7 +22,7 @@ tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } tari_storage = {path="../../infrastructure/storage"} tari_service_framework = { path = "../../base_layer/service_framework" } tari_shutdown = { path = "../../infrastructure/shutdown" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } anyhow = "1.0.53" async-trait = "0.1.52" diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index a70a15b68f..509b1d5cd2 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -18,7 +18,7 @@ tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] } tari_app_grpc = { path = "../tari_app_grpc" } tari_shutdown = { path = "../../infrastructure/shutdown" } tari_key_manager = { path = "../../base_layer/key_manager" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } # Uncomment for tokio tracing via tokio-console (needs "tracing" featurs) #console-subscriber = "0.1.3" diff --git a/applications/tari_merge_mining_proxy/Cargo.toml b/applications/tari_merge_mining_proxy/Cargo.toml index ba848fcc2c..f7d8ac0e24 100644 --- a/applications/tari_merge_mining_proxy/Cargo.toml +++ b/applications/tari_merge_mining_proxy/Cargo.toml @@ -16,7 +16,7 @@ tari_comms = { path = "../../comms/core" } tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] } tari_app_utilities = { path = "../tari_app_utilities" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } tari_base_node_grpc_client = {path="../../clients/rust/base_node_grpc_client" } tari_wallet_grpc_client = {path="../../clients/rust/wallet_grpc_client" } diff --git a/applications/tari_miner/Cargo.toml b/applications/tari_miner/Cargo.toml index 9cc40dee70..4917bc04cc 100644 --- a/applications/tari_miner/Cargo.toml +++ b/applications/tari_miner/Cargo.toml @@ -15,7 +15,7 @@ tari_comms = { path = "../../comms/core" } tari_app_utilities = { path = "../tari_app_utilities" } tari_app_grpc = { path = "../tari_app_grpc" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } crossterm = { version = "0.25.0" } clap = { version = "3.1.1", features = ["derive"] } diff --git a/base_layer/common_types/Cargo.toml b/base_layer/common_types/Cargo.toml index 0c7ab43432..4f4a67e48d 100644 --- a/base_layer/common_types/Cargo.toml +++ b/base_layer/common_types/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" [dependencies] tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } tari_common = { version = "^0.40", path = "../../common" } base64 = "0.13.0" diff --git a/base_layer/core/Cargo.toml b/base_layer/core/Cargo.toml index 8c2bb31a34..cf54255533 100644 --- a/base_layer/core/Cargo.toml +++ b/base_layer/core/Cargo.toml @@ -33,7 +33,7 @@ tari_service_framework = { version = "^0.40", path = "../service_framework" } tari_shutdown = { version = "^0.40", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.40", path = "../../infrastructure/storage" } tari_test_utils = { version = "^0.40", path = "../../infrastructure/test_utils" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } async-trait = "0.1.50" bincode = "1.1.4" diff --git a/base_layer/key_manager/Cargo.toml b/base_layer/key_manager/Cargo.toml index 7949a629fd..c6a2472fa9 100644 --- a/base_layer/key_manager/Cargo.toml +++ b/base_layer/key_manager/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["lib", "cdylib"] [dependencies] tari_common_types = { version = "^0.40", path = "../../base_layer/common_types", optional = true } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } argon2 = { version = "0.4.1", features = ["std", "alloc"] } blake2 = "0.9.1" diff --git a/base_layer/mmr/Cargo.toml b/base_layer/mmr/Cargo.toml index 1ff106ee2f..8943dc5c87 100644 --- a/base_layer/mmr/Cargo.toml +++ b/base_layer/mmr/Cargo.toml @@ -13,7 +13,7 @@ native_bitmap = ["croaring"] benches = ["criterion"] [dependencies] -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } tari_common = {path = "../../common"} thiserror = "1.0.26" diff --git a/base_layer/p2p/Cargo.toml b/base_layer/p2p/Cargo.toml index 28843f47f0..16efef1f89 100644 --- a/base_layer/p2p/Cargo.toml +++ b/base_layer/p2p/Cargo.toml @@ -17,7 +17,7 @@ tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = " tari_service_framework = { version = "^0.40", path = "../service_framework" } tari_shutdown = { version = "^0.40", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.40", path = "../../infrastructure/storage" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } anyhow = "1.0.53" bytes = "0.5" diff --git a/base_layer/tari_mining_helper_ffi/Cargo.toml b/base_layer/tari_mining_helper_ffi/Cargo.toml index a55b878d6d..177d29bb78 100644 --- a/base_layer/tari_mining_helper_ffi/Cargo.toml +++ b/base_layer/tari_mining_helper_ffi/Cargo.toml @@ -11,7 +11,7 @@ tari_comms = { version = "^0.40", path = "../../comms/core" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } tari_common = { path = "../../common" } tari_core = { path = "../core", default-features = false, features = ["transactions"]} -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } libc = "0.2.65" thiserror = "1.0.26" hex = "0.4.2" diff --git a/base_layer/wallet_ffi/Cargo.toml b/base_layer/wallet_ffi/Cargo.toml index 9c98f19fc0..2d10c9de41 100644 --- a/base_layer/wallet_ffi/Cargo.toml +++ b/base_layer/wallet_ffi/Cargo.toml @@ -17,7 +17,7 @@ tari_key_manager = { version = "^0.40", path = "../key_manager" } tari_p2p = { version = "^0.40", path = "../p2p" } tari_script = { path = "../../infrastructure/tari_script" } tari_shutdown = { version = "^0.40", path = "../../infrastructure/shutdown" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } tari_wallet = { version = "^0.40", path = "../wallet", features = ["c_integration"]} chrono = { version = "0.4.19", default-features = false, features = ["serde"] } diff --git a/comms/core/Cargo.toml b/comms/core/Cargo.toml index 4616145b05..3b2ad5e245 100644 --- a/comms/core/Cargo.toml +++ b/comms/core/Cargo.toml @@ -15,7 +15,7 @@ tari_common = {path = "../../common"} tari_metrics = { path = "../../infrastructure/metrics" } tari_storage = { version = "^0.40", path = "../../infrastructure/storage" } tari_shutdown = { version = "^0.40", path = "../../infrastructure/shutdown" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } anyhow = "1.0.53" async-trait = "0.1.36" diff --git a/comms/dht/Cargo.toml b/comms/dht/Cargo.toml index 68ef9e31bd..42f9c6c5a9 100644 --- a/comms/dht/Cargo.toml +++ b/comms/dht/Cargo.toml @@ -14,7 +14,7 @@ tari_comms = { version = "^0.40", path = "../core", features = ["rpc"] } tari_common = { path = "../../common" } tari_comms_rpc_macros = { version = "^0.40", path = "../rpc_macros" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } tari_shutdown = { version = "^0.40", path = "../../infrastructure/shutdown" } tari_storage = { version = "^0.40", path = "../../infrastructure/storage" } tari_common_sqlite = { path = "../../common_sqlite" } diff --git a/infrastructure/storage/Cargo.toml b/infrastructure/storage/Cargo.toml index 1f818f235d..8856e4aa7d 100644 --- a/infrastructure/storage/Cargo.toml +++ b/infrastructure/storage/Cargo.toml @@ -19,4 +19,4 @@ serde_derive = "1.0.80" [dev-dependencies] rand = "0.7.3" -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } diff --git a/infrastructure/tari_script/Cargo.toml b/infrastructure/tari_script/Cargo.toml index 5dd600b5f6..3183e19547 100644 --- a/infrastructure/tari_script/Cargo.toml +++ b/infrastructure/tari_script/Cargo.toml @@ -12,7 +12,7 @@ license = "BSD-3-Clause" [dependencies] tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", tag = "v0.16.1" } -tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.7" } +tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", tag="v0.4.9" } blake2 = "0.9" digest = "0.9.0" From 7d7c25cc2d4b25c7c2966e7d8a69295eb6b25ae2 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Fri, 18 Nov 2022 09:48:32 +0000 Subject: [PATCH 09/20] remove unused dependencies --- Cargo.lock | 102 +++++++++++++---------- base_layer/key_manager/src/lib.rs | 1 - base_layer/wallet_ffi/wallet.h | 134 ++++++++++++------------------ 3 files changed, 111 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 878b69b690..c6145f5633 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4408,7 +4408,7 @@ dependencies = [ [[package]] name = "tari_app_grpc" -version = "0.40.1" +version = "0.40.2" dependencies = [ "argon2", "base64 0.13.1", @@ -4424,7 +4424,7 @@ dependencies = [ "tari_core", "tari_crypto", "tari_script", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", "tonic", "tonic-build", @@ -4433,7 +4433,7 @@ dependencies = [ [[package]] name = "tari_app_utilities" -version = "0.40.1" +version = "0.40.2" dependencies = [ "clap 3.2.23", "config", @@ -4448,14 +4448,14 @@ dependencies = [ "tari_common_types", "tari_comms", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", "tokio", ] [[package]] name = "tari_base_node" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "async-trait", @@ -4494,7 +4494,7 @@ dependencies = [ "tari_service_framework", "tari_shutdown", "tari_storage", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", "tokio", "tonic", @@ -4552,7 +4552,7 @@ dependencies = [ [[package]] name = "tari_common" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "blake2 0.9.2", @@ -4579,7 +4579,7 @@ dependencies = [ [[package]] name = "tari_common_sqlite" -version = "0.40.1" +version = "0.40.2" dependencies = [ "diesel", "log", @@ -4588,7 +4588,7 @@ dependencies = [ [[package]] name = "tari_common_types" -version = "0.40.1" +version = "0.40.2" dependencies = [ "base64 0.13.1", "digest 0.9.0", @@ -4597,7 +4597,7 @@ dependencies = [ "serde", "tari_common", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", "tokio", "zeroize", @@ -4605,7 +4605,7 @@ dependencies = [ [[package]] name = "tari_comms" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "async-trait", @@ -4641,7 +4641,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tempfile", "thiserror", "tokio", @@ -4655,7 +4655,7 @@ dependencies = [ [[package]] name = "tari_comms_dht" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "bitflags 1.3.2", @@ -4690,7 +4690,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tempfile", "thiserror", "tokio", @@ -4701,7 +4701,7 @@ dependencies = [ [[package]] name = "tari_comms_rpc_macros" -version = "0.40.1" +version = "0.40.2" dependencies = [ "futures 0.3.25", "proc-macro2", @@ -4716,7 +4716,7 @@ dependencies = [ [[package]] name = "tari_console_wallet" -version = "0.40.1" +version = "0.40.2" dependencies = [ "base64 0.13.1", "bitflags 1.3.2", @@ -4749,7 +4749,7 @@ dependencies = [ "tari_libtor", "tari_p2p", "tari_shutdown", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tari_wallet", "thiserror", "tokio", @@ -4762,7 +4762,7 @@ dependencies = [ [[package]] name = "tari_core" -version = "0.40.1" +version = "0.40.2" dependencies = [ "async-trait", "bincode", @@ -4814,7 +4814,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tempfile", "thiserror", "tokio", @@ -4825,13 +4825,8 @@ dependencies = [ [[package]] name = "tari_crypto" -<<<<<<< HEAD -version = "0.16.0" -source = "git+https://github.com/tari-project/tari-crypto.git?tag=v0.16.0#8f3bce7ed1ece78d58c90ba9abda59cbfa0863f6" -======= version = "0.16.1" source = "git+https://github.com/tari-project/tari-crypto.git?tag=v0.16.1#fa042e498be144d8d2af7b96efe805c5af0b2d4f" ->>>>>>> development dependencies = [ "base64 0.10.1", "blake2 0.9.2", @@ -4858,7 +4853,7 @@ dependencies = [ [[package]] name = "tari_key_manager" -version = "0.40.1" +version = "0.40.2" dependencies = [ "argon2", "blake2 0.9.2", @@ -4879,7 +4874,7 @@ dependencies = [ "subtle", "tari_common_types", "tari_crypto", - "tari_utilities 0.4.8", + "tari_utilities 0.4.9", "thiserror", "wasm-bindgen", "wasm-bindgen-test", @@ -4905,7 +4900,7 @@ dependencies = [ [[package]] name = "tari_merge_mining_proxy" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "bincode", @@ -4931,7 +4926,7 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tari_wallet_grpc_client", "thiserror", "tokio", @@ -4957,7 +4952,7 @@ dependencies = [ [[package]] name = "tari_miner" -version = "0.40.1" +version = "0.40.2" dependencies = [ "base64 0.13.1", "bufstream", @@ -4985,7 +4980,7 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", "tokio", "tonic", @@ -4993,7 +4988,7 @@ dependencies = [ [[package]] name = "tari_mining_helper_ffi" -version = "0.40.1" +version = "0.40.2" dependencies = [ "hex", "libc", @@ -5004,13 +4999,13 @@ dependencies = [ "tari_comms", "tari_core", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", ] [[package]] name = "tari_mmr" -version = "0.40.1" +version = "0.40.2" dependencies = [ "bincode", "blake2 0.9.2", @@ -5023,13 +5018,13 @@ dependencies = [ "serde_json", "tari_common", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", ] [[package]] name = "tari_p2p" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "bytes 0.5.6", @@ -5057,7 +5052,7 @@ dependencies = [ "tari_shutdown", "tari_storage", "tari_test_utils", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tempfile", "thiserror", "tokio", @@ -5080,13 +5075,13 @@ dependencies = [ "sha2 0.9.9", "sha3", "tari_crypto", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", ] [[package]] name = "tari_service_framework" -version = "0.40.1" +version = "0.40.2" dependencies = [ "anyhow", "async-trait", @@ -5103,7 +5098,7 @@ dependencies = [ [[package]] name = "tari_shutdown" -version = "0.40.1" +version = "0.40.2" dependencies = [ "futures 0.3.25", "tokio", @@ -5111,7 +5106,7 @@ dependencies = [ [[package]] name = "tari_storage" -version = "0.40.1" +version = "0.40.2" dependencies = [ "bincode", "lmdb-zero", @@ -5119,13 +5114,13 @@ dependencies = [ "rand 0.7.3", "serde", "serde_derive", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "thiserror", ] [[package]] name = "tari_test_utils" -version = "0.40.1" +version = "0.40.2" dependencies = [ "futures 0.3.25", "futures-test", @@ -5165,9 +5160,26 @@ dependencies = [ "zeroize", ] +[[package]] +name = "tari_utilities" +version = "0.4.9" +source = "git+https://github.com/tari-project/tari_utilities.git?tag=v0.4.9#492468581fd10d555e743095a9aebe34b84023ce" +dependencies = [ + "base58-monero 0.3.2", + "base64 0.13.1", + "bincode", + "generic-array", + "newtype-ops", + "serde", + "serde_json", + "subtle", + "thiserror", + "zeroize", +] + [[package]] name = "tari_wallet" -version = "0.40.1" +version = "0.40.2" dependencies = [ "argon2", "async-trait", @@ -5218,7 +5230,7 @@ dependencies = [ [[package]] name = "tari_wallet_ffi" -version = "0.40.1" +version = "0.40.2" dependencies = [ "cbindgen 0.24.3", "chrono", @@ -5244,7 +5256,7 @@ dependencies = [ "tari_service_framework", "tari_shutdown", "tari_test_utils", - "tari_utilities 0.4.7", + "tari_utilities 0.4.9", "tari_wallet", "tempfile", "thiserror", diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index 67c1e00b26..8cca15145b 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -3,7 +3,6 @@ use cipher_seed::BIRTHDAY_GENESIS_FROM_UNIX_EPOCH; use digest::Digest; -use serde::{Deserialize, Serialize}; use tari_crypto::{ hash_domain, hashing::{DomainSeparatedHasher, LengthExtensionAttackResistant}, diff --git a/base_layer/wallet_ffi/wallet.h b/base_layer/wallet_ffi/wallet.h index 83ee5fb7b8..13d207f170 100644 --- a/base_layer/wallet_ffi/wallet.h +++ b/base_layer/wallet_ffi/wallet.h @@ -865,32 +865,6 @@ TariPrivateKey *private_key_generate(void); TariPrivateKey *private_key_from_hex(const char *key, int *error_out); -/** - * -------------------------------------------------------------------------------------------- /// - * - * ------------------------------- Commitment Signature ---------------------------------------/// - * Creates a TariCommitmentSignature from `u`, `v` and `public_nonce` ByteVectors - * - * ## Arguments - * `public_nonce_bytes` - The public nonce signature component as a ByteVector - * `u_bytes` - The u signature component as a ByteVector - * `v_bytes` - The v signature component as a ByteVector - * `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions - * as an out parameter. - * - * ## Returns - * `TariCommitmentSignature` - Returns a commitment signature. Note that it will be ptr::null_mut() if any argument is - * null or if there was an error with the contents of bytes - * - * # Safety - * The ```commitment_signature_destroy``` function must be called when finished with a TariCommitmentSignature to - * prevent a memory leak - */ -TariCommitmentSignature *commitment_signature_create_from_bytes(const struct ByteVector *public_nonce_bytes, - const struct ByteVector *u_bytes, - const struct ByteVector *v_bytes, - int *error_out); - /** * Frees memory for a TariCommitmentSignature * @@ -997,8 +971,6 @@ void encrypted_value_destroy(TariEncryptedValue *encrypted_value); * `output_type` - The encoded value of the output type as a byte * `maturity` - The encoded value maturity as bytes * `metadata` - The metadata componenet as a ByteVector. It cannot be null - * `unique_id` - The unique id componenet as a ByteVector. It can be null - * `mparent_public_key` - The parent public key component as a ByteVector. It can be null * `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions * as an out parameter. * @@ -1585,10 +1557,10 @@ unsigned long long completed_transaction_get_transaction_id(TariCompletedTransac * ptr::null_mut() if transaction is null * * # Safety - * The ```public_key_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory leak + * The ```tari_address_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory leak */ -TariWalletAddress *completed_transaction_get_destination_public_key(TariCompletedTransaction *transaction, - int *error_out); +TariWalletAddress *completed_transaction_get_destination_tari_address(TariCompletedTransaction *transaction, + int *error_out); /** * Gets the TariTransactionKernel of a TariCompletedTransaction @@ -1625,8 +1597,8 @@ TariTransactionKernel *completed_transaction_get_transaction_kernel(TariComplete * # Safety * The ```tari_address_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory leak */ -TariWalletAddress *completed_transaction_get_source_public_key(TariCompletedTransaction *transaction, - int *error_out); +TariWalletAddress *completed_transaction_get_source_tari_address(TariCompletedTransaction *transaction, + int *error_out); /** * Gets the status of a TariCompletedTransaction @@ -1831,10 +1803,10 @@ unsigned long long pending_outbound_transaction_get_transaction_id(TariPendingOu * ptr::null_mut() if transaction is null * * # Safety - * The ```public_key_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory leak + * The ```tari_address_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory leak */ -TariWalletAddress *pending_outbound_transaction_get_destination_public_key(TariPendingOutboundTransaction *transaction, - int *error_out); +TariWalletAddress *pending_outbound_transaction_get_destination_tari_address(TariPendingOutboundTransaction *transaction, + int *error_out); /** * Gets the amount of a TariPendingOutboundTransaction @@ -1978,10 +1950,11 @@ unsigned long long pending_inbound_transaction_get_transaction_id(TariPendingInb * ptr::null_mut() if transaction is null * * # Safety - * The ```public_key_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory leak + * The ```tari_address_destroy``` method must be called when finished with a TariWalletAddress to prevent a memory + * leak */ -TariWalletAddress *pending_inbound_transaction_get_source_public_key(TariPendingInboundTransaction *transaction, - int *error_out); +TariWalletAddress *pending_inbound_transaction_get_source_tari_address(TariPendingInboundTransaction *transaction, + int *error_out); /** * Gets the amount of a TariPendingInboundTransaction @@ -2578,6 +2551,48 @@ struct TariCoinPreview *wallet_preview_coin_split(struct TariWallet *wallet, uint64_t fee_per_gram, int32_t *error_ptr); +/** + * Signs a message using the public key of the TariWallet + * + * ## Arguments + * `wallet` - The TariWallet pointer. + * `msg` - The message pointer. + * `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions + * as an out parameter. + * ## Returns + * `*mut c_char` - Returns the pointer to the hexadecimal representation of the signature and + * public nonce, seperated by a pipe character. Empty if an error occured. + * + * # Safety + * The ```string_destroy``` method must be called when finished with a string coming from rust to prevent a memory leak + */ +char *wallet_sign_message(struct TariWallet *wallet, + const char *msg, + int *error_out); + +/** + * Verifies the signature of the message signed by a TariWallet + * + * ## Arguments + * `wallet` - The TariWallet pointer. + * `public_key` - The pointer to the TariPublicKey of the wallet which originally signed the message + * `hex_sig_nonce` - The pointer to the sting containing the hexadecimal representation of the + * signature and public nonce seperated by a pipe character. + * `msg` - The pointer to the msg the signature will be checked against. + * `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions + * as an out parameter. + * ## Returns + * `bool` - Returns if the signature is valid or not, will be false if an error occurs. + * + * # Safety + * None + */ +bool wallet_verify_message_signature(struct TariWallet *wallet, + TariPublicKey *public_key, + const char *hex_sig_nonce, + const char *msg, + int *error_out); + /** * Adds a base node peer to the TariWallet * @@ -3015,47 +3030,6 @@ TariCompletedTransaction *wallet_get_cancelled_transaction_by_id(struct TariWall TariWalletAddress *wallet_get_tari_address(struct TariWallet *wallet, int *error_out); -/** - * Import an external UTXO into the wallet as a non-rewindable (i.e. non-recoverable) output. This will add a spendable - * UTXO (as EncumberedToBeReceived) and create a faux completed transaction to record the event. - * - * ## Arguments - * `wallet` - The TariWallet pointer - * `amount` - The value of the UTXO in MicroTari - * `spending_key` - The private spending key - * `source_address` - The tari address of the source of the transaction - * `features` - Options for an output's structure or use - * `metadata_signature` - UTXO signature with the script offset private key, k_O - * `sender_offset_public_key` - Tari script offset pubkey, K_O - * `script_private_key` - Tari script private key, k_S, is used to create the script signature - * `covenant` - The covenant that will be executed when spending this output - * `message` - The message that the transaction will have - * `encrypted_value` - Encrypted value. - * `minimum_value_promise` - The minimum value of the commitment that is proven by the range proof - * `error_out` - Pointer to an int which will be modified to an error code should one occur, may not be null. Functions - * as an out parameter. - * - * ## Returns - * `c_ulonglong` - Returns the TransactionID of the generated transaction, note that it will be zero if the - * transaction is null - * - * # Safety - * None - */ -unsigned long long wallet_import_external_utxo_as_non_rewindable(struct TariWallet *wallet, - unsigned long long amount, - TariPrivateKey *spending_key, - TariWalletAddress *source_address, - TariOutputFeatures *features, - TariCommitmentSignature *metadata_signature, - TariPublicKey *sender_offset_public_key, - TariPrivateKey *script_private_key, - TariCovenant *covenant, - TariEncryptedValue *encrypted_value, - unsigned long long minimum_value_promise, - const char *message, - int *error_out); - /** * Cancel a Pending Transaction * From 8d65187b051bbdce84c137104ae3d0a80046f3ad Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 09:41:17 +0000 Subject: [PATCH 10/20] improve code chunks --- base_layer/wallet_ffi/src/lib.rs | 34 +++++++++++--------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index d2a4b08fc7..d27ae154cc 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -1731,13 +1731,8 @@ pub unsafe extern "C" fn seed_words_get_mnemonic_word_list_for_language( target: LOG_TARGET, "Retrieved mnemonic wordlist for'{}'", language_string ); - mnemonic_word_list_vec = SeedWords::new( - mnemonic_word_list - .to_vec() - .into_iter() - .map(|s| Hidden::hide(s.to_string())) - .collect(), - ); + mnemonic_word_list_vec = + SeedWords::new(mnemonic_word_list.iter().map(|s| Hidden::hide(s.to_string())).collect()); } Box::into_raw(Box::new(TariSeedWords(mnemonic_word_list_vec))) @@ -1800,22 +1795,17 @@ pub unsafe extern "C" fn seed_words_get_at( if position > len as u32 { error = LibWalletError::from(InterfaceError::PositionInvalidError).code; ptr::swap(error_out, &mut error as *mut c_int); + } else if let Ok(v) = CString::new( + (*seed_words) + .0 + .get_word(position as usize) + .expect("Seed Words position is in bounds") + .as_str(), + ) { + word = v; } else { - match CString::new( - (*seed_words) - .0 - .get_word(position as usize) - .expect("Seed Words position is in bounds") - .as_str(), - ) { - Ok(v) => { - word = v; - }, - _ => { - error = LibWalletError::from(InterfaceError::PointerError("seed_words".to_string())).code; - ptr::swap(error_out, &mut error as *mut c_int); - }, - } + error = LibWalletError::from(InterfaceError::PointerError("seed_words".to_string())).code; + ptr::swap(error_out, &mut error as *mut c_int); } } CString::into_raw(word) From c98c1cde4ffef5010590b5240eb7ee3f6094e4eb Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 09:56:15 +0000 Subject: [PATCH 11/20] merge development and compiled tests --- .../output_manager_service_tests/service.rs | 23 ++++++++----------- base_layer/wallet/tests/wallet.rs | 11 +++++---- base_layer/wallet_ffi/src/lib.rs | 12 ++++++---- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/base_layer/wallet/tests/output_manager_service_tests/service.rs b/base_layer/wallet/tests/output_manager_service_tests/service.rs index 642b0890dc..8c4981b4c7 100644 --- a/base_layer/wallet/tests/output_manager_service_tests/service.rs +++ b/base_layer/wallet/tests/output_manager_service_tests/service.rs @@ -52,10 +52,11 @@ use tari_crypto::{ commitment::HomomorphicCommitmentFactory, keys::{PublicKey as PublicKeyTrait, SecretKey}, }; -use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic}; +use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic, SeedWords}; use tari_script::{inputs, script, TariScript}; use tari_service_framework::reply_channel; use tari_shutdown::Shutdown; +use tari_utilities::Hidden; use tari_wallet::{ base_node_service::{ handle::{BaseNodeEvent, BaseNodeServiceHandle}, @@ -180,18 +181,14 @@ async fn setup_output_manager_service>(), - None, - ) - .unwrap(); + let words = [ + "scan", "train", "success", "hover", "prepare", "donor", "upgrade", "attitude", "debate", "emotion", "myself", + "ladder", "display", "athlete", "welcome", "artist", "home", "punch", "sense", "park", "midnight", "quantum", + "bright", "carbon", + ]; + let seed_words = SeedWords::new(words.iter().map(|s| Hidden::hide(s.to_string())).collect::>()); + + let cipher_seed = CipherSeed::from_mnemonic(&seed_words, None).unwrap(); let key_manager = KeyManagerHandle::new(cipher_seed.clone(), KeyManagerDatabase::new(ks_backend)); let output_manager_service = OutputManagerService::new( diff --git a/base_layer/wallet/tests/wallet.rs b/base_layer/wallet/tests/wallet.rs index 182bb80d56..a343355624 100644 --- a/base_layer/wallet/tests/wallet.rs +++ b/base_layer/wallet/tests/wallet.rs @@ -47,7 +47,7 @@ use tari_core::{ }, }; use tari_crypto::keys::{PublicKey as PublicKeyTrait, SecretKey}; -use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic}; +use tari_key_manager::{cipher_seed::CipherSeed, mnemonic::Mnemonic, SeedWords}; use tari_p2p::{ auto_update::AutoUpdateConfig, comms_connector::InboundDomainConnector, @@ -62,7 +62,7 @@ use tari_p2p::{ use tari_script::{inputs, script}; use tari_shutdown::{Shutdown, ShutdownSignal}; use tari_test_utils::{collect_recv, random}; -use tari_utilities::SafePassword; +use tari_utilities::{Hidden, SafePassword}; use tari_wallet::{ contacts_service::{ handle::ContactsLivenessEvent, @@ -795,16 +795,17 @@ async fn test_recovery_birthday() { // .expect("Couldn't convert CipherSeed to Mnemonic"); // println!("{:?}", mnemonic_seq); - let seed_words: Vec = [ + let vec_words: Vec> = [ "octubre", "rinon", "ameno", "rigido", "verbo", "dosis", "ocaso", "fallo", "tez", "ladron", "entrar", "pedal", "fortuna", "ahogo", "llanto", "mascara", "intuir", "buey", "cubrir", "anillo", "cajon", "entrar", "clase", "latir", ] .iter() - .map(|w| w.to_string()) + .map(|w| Hidden::hide(w.to_string())) .collect(); + let seed_words = SeedWords::new(vec_words); - let recovery_seed = CipherSeed::from_mnemonic(seed_words.as_slice(), None).unwrap(); + let recovery_seed = CipherSeed::from_mnemonic(&seed_words, None).unwrap(); let birthday = recovery_seed.birthday(); let wallet = create_wallet( diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index d27ae154cc..5469de5dea 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -8952,11 +8952,13 @@ mod test { // Compare from Rust's perspective assert_eq!( (*mnemonic_wordlist_ffi).0, - mnemonic_wordlist - .to_vec() - .iter() - .map(|s| s.to_string()) - .collect::>() + SeedWords::new( + mnemonic_wordlist + .to_vec() + .iter() + .map(|s| Hidden::hide(s.to_string())) + .collect::>>() + ) ); // Compare from C's perspective let count = seed_words_get_length(mnemonic_wordlist_ffi, error_ptr); From dd0810986780f6e6e46ae47f6eca027a7a3dd63e Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 10:56:13 +0000 Subject: [PATCH 12/20] catching bugs --- applications/tari_console_wallet/src/init/mod.rs | 2 +- base_layer/key_manager/src/lib.rs | 11 +++++------ base_layer/wallet_ffi/src/lib.rs | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/applications/tari_console_wallet/src/init/mod.rs b/applications/tari_console_wallet/src/init/mod.rs index ce774cbda5..5fab553e61 100644 --- a/applications/tari_console_wallet/src/init/mod.rs +++ b/applications/tari_console_wallet/src/init/mod.rs @@ -549,7 +549,7 @@ fn confirm_seed_words(wallet: &mut WalletSqlite) -> Result<(), ExitError> { println!("WRITE THEM DOWN OR COPY THEM NOW. THIS IS YOUR ONLY CHANCE TO DO SO."); println!(); println!("========================="); - println!("{}", seed_words.join(" ")); + println!("{}", seed_words.join(" ").reveal()); println!("========================="); println!("\x07"); // beep! diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index 607833301b..ce006ce8e2 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -139,9 +139,9 @@ mod tests { "olá".to_string(), ]; - for index in 0..5_usize { - // Notice we should not dereference the word, in practice. But these are unit tests - assert_eq!(*seed_words.get_word(index).unwrap(), vec_words[index]); + for (index, word) in vec_words.iter().enumerate().take(5_usize) { + // should not derefence, in practice. We do it here, for testing purposes + assert_eq!(*seed_words.get_word(index).unwrap(), *word); } } @@ -173,7 +173,7 @@ mod tests { seed_words.push("ciao".to_string()); assert_eq!(seed_words.len(), 6_usize); - assert_eq!(*seed_words.get_word(5).unwrap(), "ciao") + assert_eq!(seed_words.get_word(5).unwrap(), "ciao") } #[test] @@ -187,8 +187,7 @@ mod tests { ]); let joined = seed_words.join(", "); - // should not dereference, in practice. We do it here for testing purposes - assert_eq!(*joined.reveal(), "hi, niao, hola, bonjour, olá"); + assert_eq!(joined.reveal(), "hi, niao, hola, bonjour, olá"); } #[test] diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index 5469de5dea..2d23938188 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -1893,7 +1893,6 @@ pub unsafe extern "C" fn seed_words_push_word( // Try push to a temporary copy first to prevent existing object becoming invalid if let Ok(language) = MnemonicLanguage::detect_language(&(*seed_words).0) { - (*seed_words).0.push(word_string.clone()); // Check words in temp are still consistent for a language, note that detected language can change // depending on word added if MnemonicLanguage::detect_language(&(*seed_words).0).is_ok() { From 7ebbb1b081c39dbfb81342153948b7df19ab354c Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 11:16:03 +0000 Subject: [PATCH 13/20] add comments --- applications/tari_console_wallet/src/lib.rs | 1 + applications/tari_console_wallet/src/recovery.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/applications/tari_console_wallet/src/lib.rs b/applications/tari_console_wallet/src/lib.rs index 1b4a4d25f5..6c73cb8ab5 100644 --- a/applications/tari_console_wallet/src/lib.rs +++ b/applications/tari_console_wallet/src/lib.rs @@ -214,6 +214,7 @@ fn get_password(config: &ApplicationConfig, cli: &Cli) -> Option { fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result, ExitError> { if matches!(boot_mode, WalletBoot::Recovery) { let seed = if cli.seed_words.is_some() { + // TODO: fix leaks let seed_words: SeedWords = SeedWords::new( cli.seed_words .clone() diff --git a/applications/tari_console_wallet/src/recovery.rs b/applications/tari_console_wallet/src/recovery.rs index 8cad1519af..8b8e68eb24 100644 --- a/applications/tari_console_wallet/src/recovery.rs +++ b/applications/tari_console_wallet/src/recovery.rs @@ -53,6 +53,7 @@ pub fn prompt_private_key_from_seed_words() -> Result { println!(); println!("Type or paste all of your seed words on one line, only separated by spaces."); let input = rl.readline(">> ").map_err(|e| ExitError::new(ExitCode::IOError, e))?; + // TODO: fix leaks let seed_words: SeedWords = SeedWords::new(input.split_whitespace().map(|s| Hidden::hide(s.to_string())).collect()); From 654364dc933c9984cce3c5bf8d50e106f6b0586a Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 11:46:52 +0000 Subject: [PATCH 14/20] add refactor --- Cargo.lock | 1 + applications/tari_console_wallet/Cargo.toml | 1 + applications/tari_console_wallet/src/lib.rs | 8 +++++--- applications/tari_console_wallet/src/recovery.rs | 12 ++++++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cba0af5382..c1e82152b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4766,6 +4766,7 @@ dependencies = [ "tui", "unicode-segmentation", "unicode-width", + "zeroize", ] [[package]] diff --git a/applications/tari_console_wallet/Cargo.toml b/applications/tari_console_wallet/Cargo.toml index 1aba3a720f..91d1d542b4 100644 --- a/applications/tari_console_wallet/Cargo.toml +++ b/applications/tari_console_wallet/Cargo.toml @@ -50,6 +50,7 @@ tonic = "0.6.2" tracing = "0.1.26" unicode-segmentation = "1.6.0" unicode-width = "0.1" +zeroize = "1.3.0" [dependencies.tari_core] path = "../../base_layer/core" diff --git a/applications/tari_console_wallet/src/lib.rs b/applications/tari_console_wallet/src/lib.rs index 6c73cb8ab5..cf50bb2803 100644 --- a/applications/tari_console_wallet/src/lib.rs +++ b/applications/tari_console_wallet/src/lib.rs @@ -56,6 +56,7 @@ use tari_shutdown::Shutdown; use tari_utilities::SafePassword; use tokio::runtime::Runtime; use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode}; +use zeroize::Zeroizing; pub use crate::config::ApplicationConfig; use crate::init::wallet_mode; @@ -214,10 +215,11 @@ fn get_password(config: &ApplicationConfig, cli: &Cli) -> Option { fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result, ExitError> { if matches!(boot_mode, WalletBoot::Recovery) { let seed = if cli.seed_words.is_some() { - // TODO: fix leaks + // need to zeroize first, to clean up memory of cli.seed_words clone + let vec_words = Zeroizing::new(cli.seed_words.clone()); let seed_words: SeedWords = SeedWords::new( - cli.seed_words - .clone() + vec_words + .as_ref() .unwrap() .split_whitespace() .map(|v| Hidden::hide(v.to_string())) diff --git a/applications/tari_console_wallet/src/recovery.rs b/applications/tari_console_wallet/src/recovery.rs index 8b8e68eb24..c8878467a5 100644 --- a/applications/tari_console_wallet/src/recovery.rs +++ b/applications/tari_console_wallet/src/recovery.rs @@ -38,6 +38,7 @@ use tari_wallet::{ WalletSqlite, }; use tokio::sync::broadcast; +use zeroize::Zeroizing; use crate::wallet_modes::PeerConfig; @@ -52,10 +53,13 @@ pub fn prompt_private_key_from_seed_words() -> Result { println!("Recovery Mode"); println!(); println!("Type or paste all of your seed words on one line, only separated by spaces."); - let input = rl.readline(">> ").map_err(|e| ExitError::new(ExitCode::IOError, e))?; - // TODO: fix leaks - let seed_words: SeedWords = - SeedWords::new(input.split_whitespace().map(|s| Hidden::hide(s.to_string())).collect()); + let input = Zeroizing::new(rl.readline(">> ").map_err(|e| ExitError::new(ExitCode::IOError, e))?); + let seed_words: SeedWords = SeedWords::new( + input + .split_whitespace() + .map(|s| Hidden::hide(s.to_string())) + .collect(), + ); match CipherSeed::from_mnemonic(&seed_words, None) { Ok(seed) => break Ok(seed), From 75ee612b2d7fe284269f52b36d811262c6987ff1 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 11:49:09 +0000 Subject: [PATCH 15/20] cargo fmt --- applications/tari_console_wallet/src/recovery.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/applications/tari_console_wallet/src/recovery.rs b/applications/tari_console_wallet/src/recovery.rs index c8878467a5..3fdf55edfa 100644 --- a/applications/tari_console_wallet/src/recovery.rs +++ b/applications/tari_console_wallet/src/recovery.rs @@ -54,12 +54,8 @@ pub fn prompt_private_key_from_seed_words() -> Result { println!(); println!("Type or paste all of your seed words on one line, only separated by spaces."); let input = Zeroizing::new(rl.readline(">> ").map_err(|e| ExitError::new(ExitCode::IOError, e))?); - let seed_words: SeedWords = SeedWords::new( - input - .split_whitespace() - .map(|s| Hidden::hide(s.to_string())) - .collect(), - ); + let seed_words: SeedWords = + SeedWords::new(input.split_whitespace().map(|s| Hidden::hide(s.to_string())).collect()); match CipherSeed::from_mnemonic(&seed_words, None) { Ok(seed) => break Ok(seed), From 7924a230e727bd665af1c02431dfa63f9435e797 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 21 Nov 2022 15:13:48 +0000 Subject: [PATCH 16/20] refactor get_recovery_seed --- applications/tari_console_wallet/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/tari_console_wallet/src/lib.rs b/applications/tari_console_wallet/src/lib.rs index cf50bb2803..9abcd714b9 100644 --- a/applications/tari_console_wallet/src/lib.rs +++ b/applications/tari_console_wallet/src/lib.rs @@ -216,13 +216,13 @@ fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result Date: Mon, 21 Nov 2022 15:19:26 +0000 Subject: [PATCH 17/20] further refactor --- applications/tari_console_wallet/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/applications/tari_console_wallet/src/lib.rs b/applications/tari_console_wallet/src/lib.rs index 9abcd714b9..5203305558 100644 --- a/applications/tari_console_wallet/src/lib.rs +++ b/applications/tari_console_wallet/src/lib.rs @@ -56,7 +56,6 @@ use tari_shutdown::Shutdown; use tari_utilities::SafePassword; use tokio::runtime::Runtime; use wallet_modes::{command_mode, grpc_mode, recovery_mode, script_mode, tui_mode, WalletMode}; -use zeroize::Zeroizing; pub use crate::config::ApplicationConfig; use crate::init::wallet_mode; @@ -216,7 +215,6 @@ fn get_recovery_seed(boot_mode: WalletBoot, cli: &Cli) -> Result Date: Tue, 22 Nov 2022 09:18:45 +0000 Subject: [PATCH 18/20] address PR comments --- base_layer/key_manager/src/cipher_seed.rs | 39 +++++++-------- base_layer/key_manager/src/key_manager.rs | 6 +-- base_layer/key_manager/src/lib.rs | 6 +-- base_layer/key_manager/src/mnemonic.rs | 58 ++++++++++++----------- 4 files changed, 56 insertions(+), 53 deletions(-) diff --git a/base_layer/key_manager/src/cipher_seed.rs b/base_layer/key_manager/src/cipher_seed.rs index 9c75effeae..71c1dbce0f 100644 --- a/base_layer/key_manager/src/cipher_seed.rs +++ b/base_layer/key_manager/src/cipher_seed.rs @@ -34,7 +34,7 @@ use rand::{rngs::OsRng, RngCore}; use serde::{Deserialize, Serialize}; use subtle::ConstantTimeEq; use tari_crypto::hash::blake2::Blake256; -use tari_utilities::{hidden::Hidden, SafePassword}; +use tari_utilities::{hidden::Hidden, safe_array::SafeArray, SafePassword}; use zeroize::{Zeroize, Zeroizing}; use crate::{ @@ -183,7 +183,7 @@ impl CipherSeed { self.entropy.as_ref(), CIPHER_SEED_VERSION, self.salt.as_ref(), - mac_key.reveal(), + &mac_key, )?; // Assemble the secret data to be encrypted: birthday, entropy, MAC @@ -195,7 +195,7 @@ impl CipherSeed { secret_data.extend(&mac); // Encrypt the secret data - Self::apply_stream_cipher(&mut secret_data, encryption_key.reveal(), self.salt.as_ref())?; + Self::apply_stream_cipher(&mut secret_data, &encryption_key, self.salt.as_ref())?; // Assemble the final seed: version, main salt, secret data, checksum let mut encrypted_seed = @@ -264,7 +264,7 @@ impl CipherSeed { // Decrypt the secret data: birthday, entropy, MAC let mut secret_data = Zeroizing::new(encrypted_seed.split_off(1)); - Self::apply_stream_cipher(&mut secret_data, encryption_key.reveal(), salt.as_ref())?; + Self::apply_stream_cipher(&mut secret_data, &encryption_key, salt.as_ref())?; // Parse secret data let mac = secret_data.split_off(CIPHER_SEED_BIRTHDAY_BYTES + CIPHER_SEED_ENTROPY_BYTES); @@ -279,13 +279,7 @@ impl CipherSeed { let birthday = u16::from_le_bytes(birthday_bytes); // Generate the MAC - let expected_mac = Self::generate_mac( - &birthday_bytes, - entropy.as_ref(), - version, - salt.as_ref(), - mac_key.reveal(), - )?; + let expected_mac = Self::generate_mac(&birthday_bytes, entropy.as_ref(), version, salt.as_ref(), &mac_key)?; // Verify the MAC in constant time to avoid leaking data if mac.ct_eq(&expected_mac).unwrap_u8() == 0 { @@ -301,7 +295,11 @@ impl CipherSeed { } /// Encrypt or decrypt data using ChaCha20 - fn apply_stream_cipher(data: &mut [u8], encryption_key: &[u8], salt: &[u8]) -> Result<(), KeyManagerError> { + fn apply_stream_cipher( + data: &mut [u8], + encryption_key: &CipherSeedEncryptionKey, + salt: &[u8], + ) -> Result<(), KeyManagerError> { // The ChaCha20 nonce is derived from the main salt let encryption_nonce = mac_domain_hasher::(LABEL_CHACHA20_ENCODING) .chain(salt) @@ -309,7 +307,10 @@ impl CipherSeed { let encryption_nonce = &encryption_nonce.as_ref()[..size_of::()]; // Encrypt/decrypt the data - let mut cipher = ChaCha20::new(Key::from_slice(encryption_key), Nonce::from_slice(encryption_nonce)); + let mut cipher = ChaCha20::new( + Key::from_slice(encryption_key.reveal()), + Nonce::from_slice(encryption_nonce), + ); cipher.apply_keystream(data); Ok(()) @@ -331,7 +332,7 @@ impl CipherSeed { entropy: &[u8], cipher_seed_version: u8, salt: &[u8], - mac_key: &[u8], + mac_key: &CipherSeedMacKey, ) -> Result, KeyManagerError> { // Check all lengths are valid if birthday.len() != CIPHER_SEED_BIRTHDAY_BYTES { @@ -349,7 +350,7 @@ impl CipherSeed { .chain(entropy) .chain(&[cipher_seed_version]) .chain(salt) - .chain(mac_key) + .chain(mac_key.reveal()) .finalize() .as_ref()[..CIPHER_SEED_MAC_BYTES] .to_vec()) @@ -382,12 +383,12 @@ impl CipherSeed { .map_err(|_| KeyManagerError::CryptographicError("Problem generating Argon2 password hash".to_string()))?; // Split off the keys - let mut encryption_key = CipherSeedEncryptionKey::from([0u8; CIPHER_SEED_ENCRYPTION_KEY_BYTES]); + let mut encryption_key = CipherSeedEncryptionKey::from(SafeArray::default()); encryption_key .reveal_mut() .copy_from_slice(&main_key.reveal()[..CIPHER_SEED_ENCRYPTION_KEY_BYTES]); - let mut mac_key = CipherSeedMacKey::from([0u8; CIPHER_SEED_MAC_KEY_BYTES]); + let mut mac_key = CipherSeedMacKey::from(SafeArray::default()); mac_key .reveal_mut() .copy_from_slice(&main_key.reveal()[CIPHER_SEED_ENCRYPTION_KEY_BYTES..]); @@ -410,7 +411,7 @@ impl Mnemonic for CipherSeed { passphrase: Option, ) -> Result { let bytes = to_bytes(mnemonic_seq)?; - CipherSeed::from_enciphered_bytes(&bytes, passphrase) + CipherSeed::from_enciphered_bytes(bytes.reveal(), passphrase) } /// Generates a SecretKey that represent the provided mnemonic sequence of words using the specified language @@ -420,7 +421,7 @@ impl Mnemonic for CipherSeed { passphrase: Option, ) -> Result { let bytes = to_bytes_with_language(mnemonic_seq, &language)?; - CipherSeed::from_enciphered_bytes(&bytes, passphrase) + CipherSeed::from_enciphered_bytes(bytes.reveal(), passphrase) } /// Generates a mnemonic sequence of words from the provided secret key diff --git a/base_layer/key_manager/src/key_manager.rs b/base_layer/key_manager/src/key_manager.rs index 598152a256..1d24e14376 100644 --- a/base_layer/key_manager/src/key_manager.rs +++ b/base_layer/key_manager/src/key_manager.rs @@ -37,7 +37,7 @@ use crate::{cipher_seed::CipherSeed, mac_domain_hasher, LABEL_DERIVE_KEY}; #[derive(Clone, Derivative, Serialize, Deserialize, Zeroize)] #[derivative(Debug)] pub struct DerivedKey -where K: SecretKey + Zeroize +where K: SecretKey { #[derivative(Debug = "ignore")] #[serde(skip_serializing)] @@ -59,7 +59,7 @@ pub struct KeyManager impl KeyManager where - K: SecretKey + Zeroize, + K: SecretKey, D: Digest + LengthExtensionAttackResistant, { /// Creates a new KeyManager with a new randomly selected entropy @@ -125,7 +125,7 @@ where impl Default for KeyManager where - K: SecretKey + Zeroize, + K: SecretKey, D: Digest + LengthExtensionAttackResistant, { fn default() -> Self { diff --git a/base_layer/key_manager/src/lib.rs b/base_layer/key_manager/src/lib.rs index ce006ce8e2..33ac743b1d 100644 --- a/base_layer/key_manager/src/lib.rs +++ b/base_layer/key_manager/src/lib.rs @@ -7,7 +7,7 @@ use tari_crypto::{ hash_domain, hashing::{DomainSeparatedHasher, LengthExtensionAttackResistant}, }; -use tari_utilities::{hidden::Hidden, hidden_type}; +use tari_utilities::{hidden::Hidden, hidden_type, safe_array::SafeArray}; use zeroize::Zeroize; use crate::{ @@ -39,8 +39,8 @@ pub(crate) fn mac_domain_hasher( DomainSeparatedHasher::::new_with_label(label) } -hidden_type!(CipherSeedEncryptionKey, [u8; CIPHER_SEED_ENCRYPTION_KEY_BYTES]); -hidden_type!(CipherSeedMacKey, [u8; CIPHER_SEED_MAC_KEY_BYTES]); +hidden_type!(CipherSeedEncryptionKey, SafeArray); +hidden_type!(CipherSeedMacKey, SafeArray< u8, CIPHER_SEED_MAC_KEY_BYTES>); /// Computes the birthday duration, in seconds, from the unix epoch. Currently, birthday is stored /// on the wallet as days since 2022-01-01, mainly to preserve space regarding u16 type. That said, diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index bcd4fe8455..bd795ef33d 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -167,19 +167,18 @@ fn find_mnemonic_index_from_word(word: &str, language: MnemonicLanguage) -> Resu } /// Finds and returns the word for a specific index in a mnemonic word list defined by the specified language -fn find_mnemonic_word_from_index(index: usize, language: MnemonicLanguage) -> Result { +fn find_mnemonic_word_from_index(index: usize, language: MnemonicLanguage) -> Result, MnemonicError> { if index < MNEMONIC_ENGLISH_WORDS.len() { Ok(match language { // Select word according to specified language - MnemonicLanguage::ChineseSimplified => MNEMONIC_CHINESE_SIMPLIFIED_WORDS[index], - MnemonicLanguage::English => MNEMONIC_ENGLISH_WORDS[index], - MnemonicLanguage::French => MNEMONIC_FRENCH_WORDS[index], - MnemonicLanguage::Italian => MNEMONIC_ITALIAN_WORDS[index], - MnemonicLanguage::Japanese => MNEMONIC_JAPANESE_WORDS[index], - MnemonicLanguage::Korean => MNEMONIC_KOREAN_WORDS[index], - MnemonicLanguage::Spanish => MNEMONIC_SPANISH_WORDS[index], - } - .to_string()) + MnemonicLanguage::ChineseSimplified => Hidden::hide(MNEMONIC_CHINESE_SIMPLIFIED_WORDS[index].to_string()), + MnemonicLanguage::English => Hidden::hide(MNEMONIC_ENGLISH_WORDS[index].to_string()), + MnemonicLanguage::French => Hidden::hide(MNEMONIC_FRENCH_WORDS[index].to_string()), + MnemonicLanguage::Italian => Hidden::hide(MNEMONIC_ITALIAN_WORDS[index].to_string()), + MnemonicLanguage::Japanese => Hidden::hide(MNEMONIC_JAPANESE_WORDS[index].to_string()), + MnemonicLanguage::Korean => Hidden::hide(MNEMONIC_KOREAN_WORDS[index].to_string()), + MnemonicLanguage::Spanish => Hidden::hide(MNEMONIC_SPANISH_WORDS[index].to_string()), + }) } else { Err(MnemonicError::IndexOutOfBounds) } @@ -205,7 +204,7 @@ pub fn from_bytes(bytes: &[u8], language: MnemonicLanguage) -> Result Result Result, MnemonicError> { +pub fn to_bytes(mnemonic_seq: &SeedWords) -> Result>, MnemonicError> { let language = MnemonicLanguage::detect_language(mnemonic_seq)?; to_bytes_with_language(mnemonic_seq, &language) } @@ -234,32 +233,35 @@ pub fn to_bytes(mnemonic_seq: &SeedWords) -> Result, MnemonicError> { /// 1) the first output 'a' is last 8 bits from input 'A', we have leftover 3 bits from 'A' /// 2) We add 5 bits from 'B' to generate 'b', the leftover is 6 bits from 'B' /// 3) We add 2 bits from 'C to generate 'c', now we have 8 bits needed to generate 'd' and we have 1 bit leftover. -pub fn to_bytes_with_language(mnemonic_seq: &SeedWords, language: &MnemonicLanguage) -> Result, MnemonicError> { +pub fn to_bytes_with_language( + mnemonic_seq: &SeedWords, + language: &MnemonicLanguage, +) -> Result>, MnemonicError> { const MASK: u64 = (1u64 << 8) - 1; - let mut bytes = Vec::new(); + let mut bytes = Hidden::hide(Vec::new()); let mut rest = 0u64; let mut rest_bits: u8 = 0; for curr_ind in 0..mnemonic_seq.len() { - let index = find_mnemonic_index_from_word( + let index = Hidden::hide(find_mnemonic_index_from_word( mnemonic_seq .get_word(curr_ind) .map_err(|_| MnemonicError::IndexOutOfBounds)?, *language, - )? as u64; + )? as u64); // Add 11 bits to the front - rest += index << rest_bits; + rest += index.reveal() << rest_bits; rest_bits += 11; while rest_bits >= 8 { // Get last 8 bits and shift it - bytes.push((rest & MASK) as u8); + bytes.reveal_mut().push((rest & MASK) as u8); rest >>= 8; rest_bits -= 8; } } // If we have any leftover, we write it. if rest > 0 { - bytes.push((rest & MASK) as u8); + bytes.reveal_mut().push((rest & MASK) as u8); } Ok(bytes) } @@ -413,7 +415,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::ChineseSimplified).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::ChineseSimplified).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); // Encoding and Decoding using English Simplified let desired_index = 1717; @@ -421,7 +423,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::English).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::English).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); // Encoding and Decoding using French Simplified let desired_index = 824; @@ -429,7 +431,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::French).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::French).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); // Encoding and Decoding using Italian Simplified let desired_index = 1123; @@ -437,7 +439,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::Italian).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::Italian).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); // Encoding and Decoding using Japanese Simplified let desired_index = 1856; @@ -445,7 +447,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::Japanese).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::Japanese).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); // Encoding and Decoding using Korean Simplified let desired_index = 345; @@ -453,7 +455,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::Korean).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::Korean).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); // Encoding and Decoding using Spanish Simplified let desired_index = 345; @@ -461,7 +463,7 @@ mod test { let index = find_mnemonic_index_from_word(&desired_word, MnemonicLanguage::Spanish).expect(""); assert_eq!(desired_index, index); let word = find_mnemonic_word_from_index(desired_index, MnemonicLanguage::Spanish).expect(""); - assert_eq!(desired_word, word); + assert_eq!(&desired_word, word.reveal()); } #[test] @@ -471,7 +473,7 @@ mod test { let mnemonic_bytes = mnemonic::to_bytes(&mnemonic_seq).expect(""); let mismatched_bytes = secretkey_bytes .iter() - .zip(mnemonic_bytes.iter()) + .zip(mnemonic_bytes.reveal().iter()) .filter(|&(a, b)| a != b) .count(); assert_eq!(mismatched_bytes, 0); @@ -487,7 +489,7 @@ mod test { OsRng.fill_bytes(&mut secretkey_bytes); let mnemonic_seq = mnemonic::from_bytes(&secretkey_bytes, MnemonicLanguage::English).unwrap(); let mnemonic_bytes = mnemonic::to_bytes(&mnemonic_seq).unwrap(); - assert_eq!(secretkey_bytes, mnemonic_bytes, "failed len = {}", len); + assert_eq!(&secretkey_bytes, mnemonic_bytes.reveal(), "failed len = {}", len); } } } From c450789902614fc3d44f48d339b91615dc995bc5 Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 22 Nov 2022 09:28:27 +0000 Subject: [PATCH 19/20] address one more comment --- base_layer/key_manager/src/mnemonic.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index bd795ef33d..2b21436951 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -186,23 +186,23 @@ fn find_mnemonic_word_from_index(index: usize, language: MnemonicLanguage) -> Re /// Converts a vector of bytes to a sequence of mnemonic words using the specified language pub fn from_bytes(bytes: &[u8], language: MnemonicLanguage) -> Result { - let mut bits = bytes_to_bits(bytes); + let mut bits = Hidden::hide(bytes_to_bits(bytes)); // Pad with zeros if length not divisible by 11 let group_bit_count = 11; - let mut padded_size = bits.len() / group_bit_count; - if bits.len() % group_bit_count > 0 { + let mut padded_size = bits.reveal().len() / group_bit_count; + if bits.reveal().len() % group_bit_count > 0 { padded_size += 1; } padded_size *= group_bit_count; - bits.resize(padded_size, false); + bits.reveal_mut().resize(padded_size, false); // Group each set of 11 bits to form one mnemonic word let mut mnemonic_sequence: Vec> = Vec::new(); - for i in 0..bits.len() / group_bit_count { + for i in 0..bits.reveal().len() / group_bit_count { let start_index = i * group_bit_count; let stop_index = start_index + group_bit_count; - let sub_v = &bits[start_index..stop_index]; + let sub_v = &bits.reveal()[start_index..stop_index]; let word_index = checked_bits_to_uint(sub_v).ok_or(MnemonicError::BitsToIntConversion)?; let mnemonic_word = find_mnemonic_word_from_index(word_index, language)?; mnemonic_sequence.push(mnemonic_word); From 992b62ff07fb607df66425fc2d4c845eb3399e6f Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Tue, 22 Nov 2022 09:47:27 +0000 Subject: [PATCH 20/20] reduce allocations, while preserving security --- base_layer/key_manager/src/mnemonic.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/base_layer/key_manager/src/mnemonic.rs b/base_layer/key_manager/src/mnemonic.rs index 2b21436951..3d852da313 100644 --- a/base_layer/key_manager/src/mnemonic.rs +++ b/base_layer/key_manager/src/mnemonic.rs @@ -243,14 +243,14 @@ pub fn to_bytes_with_language( let mut rest_bits: u8 = 0; for curr_ind in 0..mnemonic_seq.len() { - let index = Hidden::hide(find_mnemonic_index_from_word( + let index = find_mnemonic_index_from_word( mnemonic_seq .get_word(curr_ind) .map_err(|_| MnemonicError::IndexOutOfBounds)?, *language, - )? as u64); + )? as u64; // Add 11 bits to the front - rest += index.reveal() << rest_bits; + rest += index << rest_bits; rest_bits += 11; while rest_bits >= 8 { // Get last 8 bits and shift it