diff --git a/Cargo.lock b/Cargo.lock index 58a12e8ab..10f8fe6b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,7 +30,7 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.9", ] [[package]] @@ -40,7 +40,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" dependencies = [ "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -62,7 +62,7 @@ checksum = "7c7db3d5a9718568e4cf4a537cfd7070e6e6ff7481510d0237fb529ac850f6d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -121,16 +121,16 @@ version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a824f2aa7e75a0c98c5a504fceb80649e9c35265d44525b5f94de4771a395cd" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.10", "once_cell", "version_check", ] [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "cd7d5a2cecb58716e47d67d5703a249964b14c7be1ec3cad3affc295b2d1c35d" dependencies = [ "cfg-if 1.0.0", "once_cell", @@ -147,12 +147,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "allocator-api2" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" - [[package]] name = "android-tzdata" version = "0.1.1" @@ -227,9 +221,9 @@ dependencies = [ [[package]] name = "arbitrary" -version = "1.3.2" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110" +checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859" dependencies = [ "derive_arbitrary", ] @@ -263,19 +257,6 @@ dependencies = [ "futures-core", ] -[[package]] -name = "async-channel" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d37875bd9915b7d67c2f117ea2c30a0989874d0b2cb694fe25403c85763c0c9e" -dependencies = [ - "concurrent-queue", - "event-listener 3.1.0", - "event-listener-strategy", - "futures-core", - "pin-project-lite", -] - [[package]] name = "async-compression" version = "0.4.4" @@ -295,11 +276,11 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0" dependencies = [ - "async-lock 2.8.0", + "async-lock", "async-task", "concurrent-queue", "fastrand 2.0.1", - "futures-lite 1.13.0", + "futures-lite", "slab", ] @@ -309,10 +290,10 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "279cf904654eeebfa37ac9bb1598880884924aab82e290aa65c9e77a0e142e06" dependencies = [ - "async-lock 2.8.0", + "async-lock", "autocfg 1.1.0", "blocking", - "futures-lite 1.13.0", + "futures-lite", ] [[package]] @@ -321,40 +302,20 @@ version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" dependencies = [ - "async-lock 2.8.0", + "async-lock", "autocfg 1.1.0", "cfg-if 1.0.0", "concurrent-queue", - "futures-lite 1.13.0", + "futures-lite", "log", "parking", - "polling 2.8.0", - "rustix 0.37.27", + "polling", + "rustix 0.37.26", "slab", "socket2", "waker-fn", ] -[[package]] -name = "async-io" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed9d5715c2d329bf1b4da8d60455b99b187f27ba726df2883799af9af60997" -dependencies = [ - "async-lock 3.1.0", - "cfg-if 1.0.0", - "concurrent-queue", - "futures-io", - "futures-lite 2.0.1", - "parking", - "polling 3.3.0", - "rustix 0.38.23", - "slab", - "tracing", - "waker-fn", - "windows-sys 0.48.0", -] - [[package]] name = "async-lock" version = "2.8.0" @@ -364,26 +325,15 @@ dependencies = [ "event-listener 2.5.3", ] -[[package]] -name = "async-lock" -version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deb2ab2aa8a746e221ab826c73f48bc6ba41be6763f0855cb249eb6d154cf1d7" -dependencies = [ - "event-listener 3.1.0", - "event-listener-strategy", - "pin-project-lite", -] - [[package]] name = "async-net" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0434b1ed18ce1cf5769b8ac540e33f01fa9471058b5e89da9e06f3c882a8c12f" dependencies = [ - "async-io 1.13.0", + "async-io", "blocking", - "futures-lite 1.13.0", + "futures-lite", ] [[package]] @@ -392,30 +342,30 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" dependencies = [ - "async-io 1.13.0", - "async-lock 2.8.0", + "async-io", + "async-lock", "async-signal", "blocking", "cfg-if 1.0.0", - "event-listener 3.1.0", - "futures-lite 1.13.0", - "rustix 0.38.23", + "event-listener 3.0.0", + "futures-lite", + "rustix 0.38.20", "windows-sys 0.48.0", ] [[package]] name = "async-signal" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" +checksum = "d2a5415b7abcdc9cd7d63d6badba5288b2ca017e3fbd4173b8f405449f1a2399" dependencies = [ - "async-io 2.2.0", - "async-lock 2.8.0", + "async-io", + "async-lock", "atomic-waker", "cfg-if 1.0.0", "futures-core", "futures-io", - "rustix 0.38.23", + "rustix 0.38.20", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -440,7 +390,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -457,7 +407,7 @@ checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -782,7 +732,7 @@ dependencies = [ "pin-project-lite", "pin-utils", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.9", "tracing", ] @@ -1126,16 +1076,16 @@ checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" [[package]] name = "blocking" -version = "1.5.1" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" +checksum = "8c36a4d0d48574b3dd360b4b7d95cc651d2b6557b6402848a27d4b228a473e2a" dependencies = [ - "async-channel 2.1.0", - "async-lock 3.1.0", + "async-channel", + "async-lock", "async-task", "fastrand 2.0.1", "futures-io", - "futures-lite 2.0.1", + "futures-lite", "piper", "tracing", ] @@ -1163,7 +1113,7 @@ dependencies = [ "serde_urlencoded", "thiserror", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.9", "url 2.4.1", "winapi", ] @@ -1200,11 +1150,11 @@ dependencies = [ [[package]] name = "borsh" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf617fabf5cdbdc92f774bfe5062d870f228b80056d41180797abf48bed4056e" +checksum = "acedd71cd81a2231f8c032b8330184e4e290374ca4e782aa95916b17e04b71b8" dependencies = [ - "borsh-derive 1.2.0", + "borsh-derive 1.1.0", "cfg_aliases", ] @@ -1236,15 +1186,15 @@ dependencies = [ [[package]] name = "borsh-derive" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f404657a7ea7b5249e36808dff544bc88a28f26e0ac40009f674b7a009d14be3" +checksum = "e1dc1d79a037b13a874b34529d69de112c654da33311fcb68fedcf70a65a3914" dependencies = [ "once_cell", - "proc-macro-crate 2.0.0", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", "syn_derive", ] @@ -1398,8 +1348,8 @@ dependencies = [ [[package]] name = "cait-sith" -version = "0.8.0" -source = "git+https://github.com/LIT-Protocol/cait-sith.git#c69832416df2192c874a3013315feeaf53cb2a97" +version = "0.7.0" +source = "git+https://github.com/LIT-Protocol/cait-sith.git#ad0e4cf4d5845be03a7997d423799f98b4705978" dependencies = [ "auto_ops", "ck-meow", @@ -1500,6 +1450,30 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "chacha20" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" +dependencies = [ + "cfg-if 1.0.0", + "cipher 0.4.4", + "cpufeatures", +] + +[[package]] +name = "chacha20poly1305" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" +dependencies = [ + "aead", + "chacha20", + "cipher 0.4.4", + "poly1305", + "zeroize", +] + [[package]] name = "chrono" version = "0.4.31" @@ -1532,6 +1506,7 @@ checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ "crypto-common", "inout", + "zeroize", ] [[package]] @@ -1564,23 +1539,23 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.8" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2275f18819641850fa26c89acc84d465c1bf91ce57bc2748b28c420473352f64" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", - "clap_derive 4.4.7", + "clap_derive 4.4.2", ] [[package]] name = "clap_builder" -version = "4.4.8" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07cdf1b148b25c1e1f7a42225e30a0d99a615cd4637eae7365548dd4529b95bc" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", - "clap_lex 0.6.0", + "clap_lex 0.5.1", "strsim", ] @@ -1599,14 +1574,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -1620,9 +1595,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "cloudabi" @@ -1729,9 +1704,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "3fbc60abd742b35f2492f808e1abbb83d45f72db402e14c55057edc9c7b1e9e4" dependencies = [ "libc", ] @@ -1793,9 +1768,9 @@ dependencies = [ [[package]] name = "crypto-bigint" -version = "0.5.4" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28f85c3514d2a6e64160359b45a3918c3b4178bcbf4ae5d03ab2d02e521c479a" +checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" dependencies = [ "generic-array 0.14.7", "rand_core 0.6.4", @@ -1866,7 +1841,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddc25c87ebf29b249e801de5eed820f0c9ba001054bf73008df884690a03e6eb" dependencies = [ "cryptoxide", - "curve25519-dalek", + "curve25519-dalek 3.2.0", "digest 0.9.0", "ff-zeroize", "generic-array 0.14.7", @@ -1876,7 +1851,7 @@ dependencies = [ "merkle-cbt", "num-integer", "num-traits", - "p256", + "p256 0.9.0", "pairing-plus", "rand 0.6.5", "rand 0.7.3", @@ -1906,6 +1881,32 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "curve25519-dalek-derive", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fdaf97f4804dcebfa5862639bc9ce4121e82140bec2a987ac5140294865b5b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "darling" version = "0.13.4" @@ -1975,7 +1976,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -2008,7 +2009,7 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core 0.20.3", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -2068,13 +2069,13 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "1.3.2" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -2186,9 +2187,9 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "dyn-clone" -version = "1.0.16" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" +checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" [[package]] name = "easy-ext" @@ -2239,7 +2240,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 3.2.0", "ed25519", "rand 0.7.3", "serde", @@ -2287,11 +2288,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" dependencies = [ "base16ct", - "crypto-bigint 0.5.4", + "crypto-bigint 0.5.3", "digest 0.10.7", "ff 0.13.0", "generic-array 0.14.7", "group 0.13.0", + "hkdf", "pkcs8 0.10.2", "rand_core 0.6.4", "sec1", @@ -2311,22 +2313,22 @@ dependencies = [ [[package]] name = "enum-map" -version = "2.7.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed40247825a1a0393b91b51d475ea1063a6cbbf0847592e7f13fb427aca6a716" +checksum = "53337c2dbf26a3c31eccc73a37b10c1614e8d4ae99b6a50d553e8936423c1f16" dependencies = [ "enum-map-derive", ] [[package]] name = "enum-map-derive" -version = "0.15.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7933cd46e720348d29ed1493f89df9792563f272f96d8f13d18afe03b32f8cb8" +checksum = "04d0b288e3bb1d861c4403c1774a6f7a798781dfc519b3647df2a3dd4ae95f25" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -2344,9 +2346,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" dependencies = [ "humantime", "is-terminal", @@ -2363,9 +2365,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.6" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" +checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860" dependencies = [ "libc", "windows-sys 0.48.0", @@ -2379,25 +2381,15 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "3.1.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d93877bcde0eb80ca09131a08d23f0a5c18a620b01db137dba666d18cd9b30c2" +checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" dependencies = [ "concurrent-queue", "parking", "pin-project-lite", ] -[[package]] -name = "event-listener-strategy" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96b852f1345da36d551b9473fa1e2b1eb5c5195585c6c018118bc92a8d91160" -dependencies = [ - "event-listener 3.1.0", - "pin-project-lite", -] - [[package]] name = "fake-simd" version = "0.1.2" @@ -2471,6 +2463,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "fiat-crypto" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a481586acf778f1b1455424c343f71124b048ffa5f4fc3f8f6ae9dc432dcb3c7" + [[package]] name = "filetime" version = "0.2.22" @@ -2583,9 +2581,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -2598,9 +2596,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -2608,15 +2606,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -2625,9 +2623,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-lite" @@ -2644,44 +2642,34 @@ dependencies = [ "waker-fn", ] -[[package]] -name = "futures-lite" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" -dependencies = [ - "futures-core", - "pin-project-lite", -] - [[package]] name = "futures-macro" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] name = "futures-sink" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-util" -version = "0.3.29" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -2710,6 +2698,7 @@ version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ + "serde", "typenum", "version_check", "zeroize", @@ -2728,9 +2717,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -2807,7 +2796,7 @@ dependencies = [ "google-apis-common", "http", "hyper", - "hyper-rustls 0.24.2", + "hyper-rustls 0.24.1", "itertools 0.10.5", "mime", "serde", @@ -2827,7 +2816,7 @@ dependencies = [ "google-apis-common", "http", "hyper", - "hyper-rustls 0.24.2", + "hyper-rustls 0.24.1", "itertools 0.10.5", "mime", "serde", @@ -2871,12 +2860,11 @@ dependencies = [ [[package]] name = "goose-eggs" -version = "0.5.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c2aa48ad9785985b1dce6e7374500d4a966c9ec63fa2456c21c69526994dde3" +checksum = "83532d04a1a2d2dc0551383105ca18a3fa7e950e7e92c0012a2bdfa9f2ba637a" dependencies = [ "goose", - "http", "log", "rand 0.8.5", "regex", @@ -2941,7 +2929,7 @@ dependencies = [ "indexmap 1.9.3", "slab", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.9", "tracing", ] @@ -2959,6 +2947,9 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.7", +] [[package]] name = "hashbrown" @@ -2966,7 +2957,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.6", + "ahash 0.8.5", ] [[package]] @@ -2974,10 +2965,6 @@ name = "hashbrown" version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" -dependencies = [ - "ahash 0.8.6", - "allocator-api2", -] [[package]] name = "heck" @@ -3024,6 +3011,15 @@ dependencies = [ "serde", ] +[[package]] +name = "hkdf" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791a029f6b9fc27657f6f188ec6e5e43f6911f6f878e0dc5501396e09809d437" +dependencies = [ + "hmac 0.12.1", +] + [[package]] name = "hmac" version = "0.11.0" @@ -3052,11 +3048,34 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "hpke" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e04a5933a381bb81f00b083fce6b4528e16d735dbeecbb2bdb45e0dbbf3f7e17" +dependencies = [ + "aead", + "aes-gcm", + "byteorder", + "chacha20poly1305", + "digest 0.10.7", + "generic-array 0.14.7", + "hkdf", + "hmac 0.12.1", + "p256 0.13.2", + "rand_core 0.6.4", + "serde", + "sha2 0.10.8", + "subtle", + "x25519-dalek", + "zeroize", +] + [[package]] name = "http" -version = "0.2.11" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -3139,15 +3158,15 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.24.2" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" +checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" dependencies = [ "futures-util", "http", "hyper", "log", - "rustls 0.21.8", + "rustls 0.21.7", "rustls-native-certs", "tokio", "tokio-rustls 0.24.1", @@ -3301,9 +3320,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.1.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", "hashbrown 0.14.2", @@ -3352,7 +3371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.23", + "rustix 0.38.20", "windows-sys 0.48.0", ] @@ -3406,9 +3425,9 @@ checksum = "72167d68f5fce3b8655487b8038691a3c9984ee769590f93f2a631f4ad64e4f5" [[package]] name = "js-sys" -version = "0.3.65" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" dependencies = [ "wasm-bindgen", ] @@ -3427,9 +3446,9 @@ dependencies = [ [[package]] name = "json_comments" -version = "0.2.2" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" +checksum = "41ee439ee368ba4a77ac70d04f14015415af8600d6c894dc1f11bd79758c57d5" [[package]] name = "jsonwebtoken" @@ -3486,9 +3505,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" @@ -3506,17 +3525,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" -[[package]] -name = "libredox" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" -dependencies = [ - "bitflags 2.4.1", - "libc", - "redox_syscall 0.4.1", -] - [[package]] name = "linux-raw-sys" version = "0.1.4" @@ -3531,9 +3539,9 @@ checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "load-tests" @@ -3695,6 +3703,17 @@ dependencies = [ "serde", ] +[[package]] +name = "mpc-keys" +version = "0.1.0" +dependencies = [ + "borsh 0.9.3", + "hex 0.4.3", + "hpke", + "rand 0.8.5", + "serde", +] + [[package]] name = "mpc-recovery" version = "0.1.0" @@ -3710,7 +3729,7 @@ dependencies = [ "base64 0.21.5", "borsh 0.10.3", "chrono", - "clap 4.4.8", + "clap 4.4.6", "curv-kzen", "ed25519-dalek", "futures", @@ -3758,14 +3777,15 @@ dependencies = [ "async-process", "backon", "bollard", - "clap 4.4.8", + "clap 4.4.6", "curv-kzen", "ed25519-dalek", - "env_logger 0.10.1", + "env_logger 0.10.0", "futures", "hex 0.4.3", "hyper", "mpc-contract", + "mpc-keys", "mpc-recovery", "mpc-recovery-node", "multi-party-eddsa", @@ -3785,10 +3805,10 @@ dependencies = [ "test-log", "testcontainers", "tokio", - "tokio-util 0.7.10", - "toml 0.8.8", + "tokio-util 0.7.9", + "toml 0.8.4", "tracing", - "tracing-log 0.1.4", + "tracing-log", "tracing-subscriber", ] @@ -3801,11 +3821,12 @@ dependencies = [ "axum", "axum-extra", "cait-sith", - "clap 4.4.8", + "clap 4.4.6", "hex 0.4.3", "k256", "local-ip-address", "mpc-contract", + "mpc-keys", "near-crypto 0.17.0", "near-fetch", "near-lake-framework", @@ -3850,7 +3871,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.10", ] [[package]] @@ -3948,7 +3969,7 @@ dependencies = [ "borsh 0.9.3", "bs58 0.4.0", "c2-chacha", - "curve25519-dalek", + "curve25519-dalek 3.2.0", "derive_more", "ed25519-dalek", "near-account-id 0.14.0", @@ -3973,7 +3994,7 @@ dependencies = [ "borsh 0.10.3", "bs58 0.4.0", "c2-chacha", - "curve25519-dalek", + "curve25519-dalek 3.2.0", "derive_more", "ed25519-dalek", "hex 0.4.3", @@ -4019,11 +4040,11 @@ dependencies = [ [[package]] name = "near-gas" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14e75c875026229902d065e4435804497337b631ec69ba746b102954273e9ad1" +checksum = "95b30860db1eceba9b445dc56558a0fdcdfe29fd612a088e697b32dfb681aaac" dependencies = [ - "borsh 1.2.0", + "borsh 1.1.0", "schemars", "serde", ] @@ -4081,7 +4102,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfcc377f95e18b5aae830f673f6c885f5ce13994da7ba3235983cd409b6f7533" dependencies = [ "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -4133,7 +4154,7 @@ checksum = "af7d35397b02b131c188c72f3885e97daeccab134ec2fc8cc0073a94cf1cfe19" dependencies = [ "actix", "atty", - "clap 4.4.8", + "clap 4.4.6", "near-crypto 0.17.0", "near-primitives-core 0.17.0", "once_cell", @@ -4275,7 +4296,7 @@ checksum = "84c1eda300e2e78f4f945ae58117d49e806899f4a51ee2faa09eda5ebc2e6571" dependencies = [ "quote", "serde", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -4298,7 +4319,7 @@ dependencies = [ "fs2", "near-rpc-error-core 0.17.0", "serde", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -4705,9 +4726,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.59" +version = "0.10.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a257ad03cd8fb16ad4172fedf8094451e1af1c4b70097636ef2eac9a5f0cc33" +checksum = "bac25ee399abb46215765b1cb35bc0212377e58a061560d8b29b024fd0430e7c" dependencies = [ "bitflags 2.4.1", "cfg-if 1.0.0", @@ -4726,7 +4747,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -4737,9 +4758,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.95" +version = "0.9.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a4130519a360279579c2053038317e40eff64d13fd3f004f9e1b72b8a6aaf9" +checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" dependencies = [ "cc", "libc", @@ -4937,6 +4958,16 @@ dependencies = [ "sha2 0.9.9", ] +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "elliptic-curve 0.13.6", + "primeorder", +] + [[package]] name = "pairing-plus" version = "0.19.0" @@ -5096,7 +5127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" dependencies = [ "fixedbitset", - "indexmap 2.1.0", + "indexmap 2.0.2", ] [[package]] @@ -5125,7 +5156,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -5205,6 +5236,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "platforms" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4503fa043bf02cee09a9582e9554b4c6403b2ef55e4612e96561d294419429f8" + [[package]] name = "polling" version = "2.8.0" @@ -5222,17 +5259,14 @@ dependencies = [ ] [[package]] -name = "polling" -version = "3.3.0" +name = "poly1305" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" +checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" dependencies = [ - "cfg-if 1.0.0", - "concurrent-queue", - "pin-project-lite", - "rustix 0.38.23", - "tracing", - "windows-sys 0.48.0", + "cpufeatures", + "opaque-debug 0.3.0", + "universal-hash", ] [[package]] @@ -5265,6 +5299,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "primeorder" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c2fcef82c0ec6eefcc179b978446c399b3cdf73c392c35604e399eee6df1ee3" +dependencies = [ + "elliptic-curve 0.13.6", +] + [[package]] name = "primitive-types" version = "0.10.1" @@ -5295,15 +5338,6 @@ dependencies = [ "toml_edit 0.19.15", ] -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.7", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -5347,7 +5381,7 @@ dependencies = [ "byteorder", "hex 0.4.3", "lazy_static", - "rustix 0.36.17", + "rustix 0.36.16", ] [[package]] @@ -5602,7 +5636,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.11", + "getrandom 0.2.10", ] [[package]] @@ -5694,6 +5728,15 @@ dependencies = [ "rand_core 0.3.1", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.3.5" @@ -5714,12 +5757,12 @@ dependencies = [ [[package]] name = "redox_users" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.11", - "libredox", + "getrandom 0.2.10", + "redox_syscall 0.2.16", "thiserror", ] @@ -5794,7 +5837,7 @@ dependencies = [ "http", "http-body", "hyper", - "hyper-rustls 0.24.2", + "hyper-rustls 0.24.1", "hyper-tls", "ipnet", "js-sys", @@ -5804,7 +5847,7 @@ dependencies = [ "once_cell", "percent-encoding 2.3.0", "pin-project-lite", - "rustls 0.21.8", + "rustls 0.21.7", "rustls-pemfile", "serde", "serde_json", @@ -5813,7 +5856,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls 0.24.1", - "tokio-util 0.7.10", + "tokio-util 0.7.9", "tower-service", "url 2.4.1", "wasm-bindgen", @@ -5855,7 +5898,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb0205304757e5d899b9c2e448b867ffd03ae7f988002e47cd24954391394d0b" dependencies = [ "cc", - "getrandom 0.2.11", + "getrandom 0.2.10", "libc", "spin 0.9.8", "untrusted 0.9.0", @@ -5947,9 +5990,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.17" +version = "0.36.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "305efbd14fde4139eb501df5f136994bb520b033fa9fbdce287507dc23b8c7ed" +checksum = "6da3636faa25820d8648e0e31c5d519bbb01f72fdf57131f0f5f7da5fed36eab" dependencies = [ "bitflags 1.3.2", "errno", @@ -5961,9 +6004,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.27" +version = "0.37.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +checksum = "84f3f8f960ed3b5a59055428714943298bf3fa2d4a1d53135084e0544829d995" dependencies = [ "bitflags 1.3.2", "errno", @@ -5975,14 +6018,14 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.23" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb93593068e9babdad10e4fce47dc9b3ac25315a72a59766ffd9e9a71996a04" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys 0.4.11", + "linux-raw-sys 0.4.10", "windows-sys 0.48.0", ] @@ -6000,12 +6043,12 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.8" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "446e14c5cda4f3f30fe71863c34ec70f5ac79d6087097ad0bb433e1be5edf04c" +checksum = "cd8d6c9f025a446bc4d18ad9632e69aec8f287aa84499ee335599fabd20c3fd8" dependencies = [ "log", - "ring 0.17.5", + "ring 0.16.20", "rustls-webpki", "sct", ] @@ -6024,21 +6067,21 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "1.0.4" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +checksum = "2d3987094b1d07b653b7dfdc3f70ce9a1da9c51ac18c1b06b662e4f9a0e9f4b2" dependencies = [ "base64 0.21.5", ] [[package]] name = "rustls-webpki" -version = "0.101.7" +version = "0.101.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +checksum = "3c7d5dece342910d9ba34d259310cae3e0154b873b35408b787b59bce53d34fe" dependencies = [ - "ring 0.17.5", - "untrusted 0.9.0", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -6064,9 +6107,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c" dependencies = [ "dyn-clone", "schemars_derive", @@ -6076,9 +6119,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c" dependencies = [ "proc-macro2", "quote", @@ -6115,17 +6158,17 @@ checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] name = "sct" -version = "0.7.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +checksum = "d53dcdb7c9f8158937a7981b48accfd39a43af418591a5d008c7b22b5e1b7ca4" dependencies = [ - "ring 0.17.5", - "untrusted 0.9.0", + "ring 0.16.20", + "untrusted 0.7.1", ] [[package]] @@ -6222,9 +6265,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.192" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] @@ -6240,13 +6283,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.192" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -6262,9 +6305,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" dependencies = [ "itoa", "ryu", @@ -6283,13 +6326,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -6349,7 +6392,7 @@ dependencies = [ "chrono", "hex 0.4.3", "indexmap 1.9.3", - "indexmap 2.1.0", + "indexmap 2.0.2", "serde", "serde_json", "serde_with_macros 3.4.0", @@ -6377,7 +6420,7 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -6389,16 +6432,16 @@ dependencies = [ "darling 0.20.3", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] name = "serde_yaml" -version = "0.9.27" +version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" +checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.0.2", "itoa", "ryu", "serde", @@ -6571,9 +6614,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "smart-default" @@ -6592,15 +6635,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13f2b548cd8447f8de0fdf1c592929f70f4fc7039a05e47404b0d096ec6987a1" dependencies = [ - "async-channel 1.9.0", + "async-channel", "async-executor", "async-fs", - "async-io 1.13.0", - "async-lock 2.8.0", + "async-io", + "async-lock", "async-net", "async-process", "blocking", - "futures-lite 1.13.0", + "futures-lite", ] [[package]] @@ -6727,7 +6770,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -6791,9 +6834,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -6809,7 +6852,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -6858,14 +6901,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.1" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if 1.0.0", "fastrand 2.0.1", - "redox_syscall 0.4.1", - "rustix 0.38.23", + "redox_syscall 0.3.5", + "rustix 0.38.20", "windows-sys 0.48.0", ] @@ -6886,7 +6929,7 @@ checksum = "f66edd6b6cd810743c0c71e1d085e92b01ce6a72782032e3f794c8284fe4bcdd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -6942,7 +6985,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -7038,7 +7081,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -7079,7 +7122,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.8", + "rustls 0.21.7", "tokio", ] @@ -7122,16 +7165,16 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" dependencies = [ "bytes", "futures-core", "futures-io", "futures-sink", "futures-util", - "hashbrown 0.14.2", + "hashbrown 0.12.3", "pin-project-lite", "slab", "tokio", @@ -7149,14 +7192,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.8" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +checksum = "2ef75d881185fd2df4a040793927c153d863651108a93c7e17a9e591baa95cc6" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.21.0", + "toml_edit 0.20.4", ] [[package]] @@ -7174,29 +7217,18 @@ version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.0.2", "toml_datetime", "winnow", ] [[package]] name = "toml_edit" -version = "0.20.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" -dependencies = [ - "indexmap 2.1.0", - "toml_datetime", - "winnow", -] - -[[package]] -name = "toml_edit" -version = "0.21.0" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +checksum = "380f9e8120405471f7c9ad1860a713ef5ece6a670c7eae39225e477340f32fc4" dependencies = [ - "indexmap 2.1.0", + "indexmap 2.0.2", "serde", "serde_spanned", "toml_datetime", @@ -7288,7 +7320,7 @@ dependencies = [ "rand 0.8.5", "slab", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.9", "tower-layer", "tower-service", "tracing", @@ -7338,12 +7370,11 @@ dependencies = [ [[package]] name = "tracing-appender" -version = "0.2.3" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" +checksum = "09d48f71a791638519505cefafe162606f706c25592e4bde4d97600c0195312e" dependencies = [ "crossbeam-channel", - "thiserror", "time", "tracing-subscriber", ] @@ -7356,7 +7387,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -7390,17 +7421,6 @@ dependencies = [ "tracing-core", ] -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - [[package]] name = "tracing-opentelemetry" version = "0.17.4" @@ -7411,7 +7431,7 @@ dependencies = [ "opentelemetry 0.17.0", "tracing", "tracing-core", - "tracing-log 0.1.4", + "tracing-log", "tracing-subscriber", ] @@ -7427,7 +7447,7 @@ dependencies = [ "smallvec", "tracing", "tracing-core", - "tracing-log 0.1.4", + "tracing-log", "tracing-subscriber", ] @@ -7446,9 +7466,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.18" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" dependencies = [ "matchers", "nu-ansi-term", @@ -7459,7 +7479,7 @@ dependencies = [ "thread_local", "tracing", "tracing-core", - "tracing-log 0.2.0", + "tracing-log", ] [[package]] @@ -7579,7 +7599,7 @@ dependencies = [ "flate2", "log", "once_cell", - "rustls 0.21.8", + "rustls 0.21.7", "rustls-webpki", "url 2.4.1", "webpki-roots", @@ -7679,9 +7699,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -7689,24 +7709,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.38" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02" +checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -7716,9 +7736,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7726,22 +7746,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.88" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasmparser" @@ -7751,9 +7771,9 @@ checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" [[package]] name = "web-sys" -version = "0.3.65" +version = "0.3.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db499c5f66323272151db0e666cd34f78617522fb0c1604d31a27c50c206a85" +checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" dependencies = [ "js-sys", "wasm-bindgen", @@ -7796,7 +7816,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.23", + "rustix 0.38.20", ] [[package]] @@ -7973,9 +7993,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.19" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" dependencies = [ "memchr", ] @@ -8005,6 +8025,16 @@ dependencies = [ "tap", ] +[[package]] +name = "x25519-dalek" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb66477291e7e8d2b0ff1bcb900bf29489a9692816d79874bea351e7a8b6de96" +dependencies = [ + "curve25519-dalek 4.1.1", + "rand_core 0.6.4", +] + [[package]] name = "xattr" version = "1.0.1" @@ -8038,11 +8068,11 @@ dependencies = [ "futures", "http", "hyper", - "hyper-rustls 0.24.2", + "hyper-rustls 0.24.1", "itertools 0.10.5", "log", "percent-encoding 2.3.0", - "rustls 0.21.8", + "rustls 0.21.7", "rustls-pemfile", "seahash", "serde", @@ -8055,22 +8085,22 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.26" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +checksum = "4c19fae0c8a9efc6a8281f2e623db8af1db9e57852e04cde3e754dd2dc29340f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.26" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +checksum = "fc56589e9ddd1f1c28d4b4b5c773ce232910a6bb67a70133d61c9e347585efe9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] @@ -8090,7 +8120,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.38", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 58403271a..f6b465a7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "node", "integration-tests", "load-tests", + "keys", "test-oidc-provider", ] diff --git a/Dockerfile.multichain b/Dockerfile.multichain index 439d58e45..65714ef60 100644 --- a/Dockerfile.multichain +++ b/Dockerfile.multichain @@ -8,12 +8,14 @@ RUN apt-get update \ RUN echo "fn main() {}" > dummy.rs COPY node/Cargo.toml Cargo.toml RUN sed -i 's#src/main.rs#dummy.rs#' Cargo.toml +RUN sed -i 's#mpc-keys = { path = "../keys" }##' Cargo.toml RUN sed -i 's#mpc-contract = { path = "../contract" }##' Cargo.toml RUN cargo build COPY . . RUN sed -i 's#"mpc-recovery",##' Cargo.toml RUN sed -i 's#"integration-tests",##' Cargo.toml RUN sed -i 's#"load-tests",##' Cargo.toml +RUN sed -i 's#"keys",##' Cargo.toml RUN cargo build --package mpc-recovery-node FROM debian:stable-slim as runtime diff --git a/contract/src/lib.rs b/contract/src/lib.rs index a42c379d4..40d12a3fe 100644 --- a/contract/src/lib.rs +++ b/contract/src/lib.rs @@ -5,6 +5,10 @@ use std::collections::{HashMap, HashSet}; type ParticipantId = u32; +pub mod hpke { + pub type PublicKey = [u8; 32]; +} + #[derive( Serialize, Deserialize, @@ -22,6 +26,10 @@ pub struct ParticipantInfo { pub id: ParticipantId, pub account_id: AccountId, pub url: String, + /// The public key used for encrypting messages. + pub cipher_pk: hpke::PublicKey, + /// The public key used for verifying messages. + pub sign_pk: PublicKey, } #[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Debug)] @@ -34,6 +42,7 @@ pub struct InitializingContractState { #[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Debug)] pub struct RunningContractState { pub epoch: u64, + // TODO: why is this account id for participants instead of participant id? pub participants: HashMap, pub threshold: usize, pub public_key: PublicKey, @@ -83,7 +92,13 @@ impl MpcContract { self.protocol_state } - pub fn join(&mut self, participant_id: ParticipantId, url: String) { + pub fn join( + &mut self, + participant_id: ParticipantId, + url: String, + cipher_pk: hpke::PublicKey, + sign_pk: PublicKey, + ) { match &mut self.protocol_state { ProtocolContractState::Running(RunningContractState { participants, @@ -100,6 +115,8 @@ impl MpcContract { id: participant_id, account_id, url, + cipher_pk, + sign_pk, }, ); } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index c1e1de55c..8bdf9e153 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -16,6 +16,7 @@ futures = "0.3" hex = "0.4.3" hyper = { version = "0.14", features = ["full"] } mpc-contract = { path = "../contract" } +mpc-keys = { path = "../keys" } mpc-recovery = { path = "../mpc-recovery" } mpc-recovery-node = { path = "../node" } multi-party-eddsa = { git = "https://github.com/DavidM-D/multi-party-eddsa.git", rev = "25ae4fdc5ff7819ae70e73ab4afacf1c24fc4da1" } @@ -46,8 +47,6 @@ tracing-log = "0.1.3" tokio-util = { version = "0.7", features = ["full"] } reqwest = "0.11.16" -mpc-contract = { path = "../contract" } - [features] default = [] docker-test = [] diff --git a/integration-tests/src/multichain/containers.rs b/integration-tests/src/multichain/containers.rs index f579533a0..8af7bf2f1 100644 --- a/integration-tests/src/multichain/containers.rs +++ b/integration-tests/src/multichain/containers.rs @@ -1,4 +1,5 @@ use ed25519_dalek::ed25519::signature::digest::{consts::U32, generic_array::GenericArray}; +use mpc_keys::hpke; use multi_party_eddsa::protocols::ExpandedKeyPair; use near_workspaces::AccountId; use testcontainers::{ @@ -11,6 +12,9 @@ pub struct Node<'a> { pub container: Container<'a, GenericImage>, pub address: String, pub local_address: String, + pub cipher_pk: hpke::PublicKey, + pub cipher_sk: hpke::SecretKey, + pub sign_pk: near_workspaces::types::PublicKey, } pub struct NodeApi { @@ -33,6 +37,7 @@ impl<'a> Node<'a> { account_sk: &near_workspaces::types::SecretKey, ) -> anyhow::Result> { tracing::info!(node_id, "running node container"); + let (cipher_sk, cipher_pk) = hpke::generate(); let args = mpc_recovery_node::cli::Cli::Start { node_id: node_id.into(), near_rpc: ctx.lake_indexer.rpc_host_address.clone(), @@ -40,6 +45,8 @@ impl<'a> Node<'a> { account: account.clone(), account_sk: account_sk.to_string().parse()?, web_port: Self::CONTAINER_PORT, + cipher_pk: hex::encode(cipher_pk.to_bytes()), + cipher_sk: hex::encode(cipher_sk.to_bytes()), indexer_options: mpc_recovery_node::indexer::Options { s3_bucket: ctx.localstack.s3_host_address.clone(), s3_region: ctx.localstack.s3_region.clone(), @@ -72,6 +79,9 @@ impl<'a> Node<'a> { container, address: full_address, local_address: format!("http://localhost:{host_port}"), + cipher_pk, + cipher_sk, + sign_pk: account_sk.public_key(), }) } } diff --git a/integration-tests/src/multichain/local.rs b/integration-tests/src/multichain/local.rs index da32abd3f..6992b7797 100644 --- a/integration-tests/src/multichain/local.rs +++ b/integration-tests/src/multichain/local.rs @@ -1,5 +1,6 @@ use crate::{mpc, util}; use async_process::Child; +use mpc_keys::hpke; use near_workspaces::AccountId; #[allow(dead_code)] @@ -7,7 +8,9 @@ pub struct Node { pub address: String, node_id: usize, account: AccountId, - account_sk: near_workspaces::types::SecretKey, + pub account_sk: near_workspaces::types::SecretKey, + pub cipher_pk: hpke::PublicKey, + cipher_sk: hpke::SecretKey, // process held so it's not dropped. Once dropped, process will be killed. #[allow(unused)] @@ -22,6 +25,7 @@ impl Node { account_sk: &near_workspaces::types::SecretKey, ) -> anyhow::Result { let web_port = util::pick_unused_port().await?; + let (cipher_sk, cipher_pk) = hpke::generate(); let cli = mpc_recovery_node::cli::Cli::Start { node_id: node_id.into(), near_rpc: ctx.lake_indexer.rpc_host_address.clone(), @@ -29,6 +33,8 @@ impl Node { account: account.clone(), account_sk: account_sk.to_string().parse()?, web_port, + cipher_pk: hex::encode(cipher_pk.to_bytes()), + cipher_sk: hex::encode(cipher_sk.to_bytes()), indexer_options: mpc_recovery_node::indexer::Options { s3_bucket: ctx.localstack.s3_host_address.clone(), s3_region: ctx.localstack.s3_region.clone(), @@ -48,6 +54,8 @@ impl Node { node_id: node_id as usize, account: account.clone(), account_sk: account_sk.clone(), + cipher_pk, + cipher_sk, process, }) } diff --git a/integration-tests/src/multichain/mod.rs b/integration-tests/src/multichain/mod.rs index 9226907c2..49d4b89bb 100644 --- a/integration-tests/src/multichain/mod.rs +++ b/integration-tests/src/multichain/mod.rs @@ -144,6 +144,8 @@ pub async fn docker(nodes: usize, docker_client: &DockerClient) -> anyhow::Resul id: i as u32, account_id: account.id().to_string().parse().unwrap(), url: node.address.clone(), + cipher_pk: node.cipher_pk.to_bytes(), + sign_pk: node.sign_pk.to_string().parse().unwrap(), }, ) }) @@ -193,6 +195,8 @@ pub async fn host(nodes: usize, docker_client: &DockerClient) -> anyhow::Result< id: i as u32, account_id: account.id().to_string().parse().unwrap(), url: node.address.clone(), + cipher_pk: node.cipher_pk.to_bytes(), + sign_pk: node.account_sk.public_key().to_string().parse().unwrap(), }, ) }) diff --git a/keys/Cargo.toml b/keys/Cargo.toml new file mode 100644 index 000000000..b45de18bd --- /dev/null +++ b/keys/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "mpc-keys" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] + +[dependencies] +borsh = { version = "0.9.3" } +hpke = { version = "0.11", features = ["serde_impls", "std"] } +serde = { version = "1", features = ["derive"] } +rand = { version = "0.8" } + +[dev-dependencies] +hex = "*" diff --git a/keys/src/hpke.rs b/keys/src/hpke.rs new file mode 100644 index 000000000..e19058e00 --- /dev/null +++ b/keys/src/hpke.rs @@ -0,0 +1,158 @@ +use borsh::{self, BorshDeserialize, BorshSerialize}; +use hpke::{ + aead::{AeadTag, ChaCha20Poly1305}, + kdf::HkdfSha384, + kem::X25519HkdfSha256, + OpModeR, +}; +use serde::{Deserialize, Serialize}; + +/// This can be used to customize the generated key. This will be used as a sort of +/// versioning mechanism for the key. It's additional context about who is encrypting +/// the key. This is used to prevent a key from being used in a context it was not +/// supposed to be used for. +const INFO_ENTROPY: &[u8] = b"mpc-key-v1"; + +// Interchangeable type parameters for the HPKE context. +pub type Kem = X25519HkdfSha256; +pub type Aead = ChaCha20Poly1305; +pub type Kdf = HkdfSha384; + +#[derive(Serialize, Deserialize)] +pub struct Ciphered { + pub encapped_key: EncappedKey, + pub text: CipherText, + pub tag: Tag, +} + +#[derive(Serialize, Deserialize)] +pub struct Tag(AeadTag); + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct PublicKey(::PublicKey); + +// NOTE: Arc is used to hack up the fact that the internal private key does not have Send constraint. +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct SecretKey(::PrivateKey); + +#[derive(Clone, Serialize, Deserialize)] +pub struct EncappedKey(::EncappedKey); + +// Series of bytes that have been previously encoded/encrypted. +pub type CipherText = Vec; + +impl PublicKey { + pub fn to_bytes(&self) -> [u8; 32] { + hpke::Serializable::to_bytes(&self.0).into() + } + + pub fn try_from_bytes(bytes: &[u8]) -> Result { + Ok(Self(hpke::Deserializable::from_bytes(bytes)?)) + } + + /// Assumes the bytes are correctly formatted. + pub fn from_bytes(bytes: &[u8]) -> Self { + Self::try_from_bytes(bytes).expect("invalid bytes") + } + + pub fn encrypt(&self, msg: &[u8], associated_data: &[u8]) -> Result { + let mut csprng = ::from_entropy(); + + // Encapsulate a key and use the resulting shared secret to encrypt a message. The AEAD context + // is what you use to encrypt. + let (encapped_key, mut sender_ctx) = hpke::setup_sender::( + &hpke::OpModeS::Base, + &self.0, + INFO_ENTROPY, + &mut csprng, + )?; + + // On success, seal_in_place_detached() will encrypt the plaintext in place + let mut ciphertext = msg.to_vec(); + let tag = sender_ctx.seal_in_place_detached(&mut ciphertext, associated_data)?; + Ok(Ciphered { + encapped_key: EncappedKey(encapped_key), + text: ciphertext, + tag: Tag(tag), + }) + } +} + +impl BorshSerialize for PublicKey { + fn serialize(&self, writer: &mut W) -> std::io::Result<()> { + BorshSerialize::serialize(&self.to_bytes(), writer) + } +} + +impl BorshDeserialize for PublicKey { + fn deserialize(buf: &mut &[u8]) -> std::io::Result { + Ok(Self::from_bytes( + & as BorshDeserialize>::deserialize(buf)?, + )) + } +} + +impl SecretKey { + pub fn to_bytes(&self) -> [u8; 32] { + hpke::Serializable::to_bytes(&self.0).into() + } + + pub fn try_from_bytes(bytes: &[u8]) -> Result { + Ok(Self(hpke::Deserializable::from_bytes(bytes)?)) + } + + pub fn decrypt( + &self, + cipher: &Ciphered, + associated_data: &[u8], + ) -> Result, hpke::HpkeError> { + // Decapsulate and derive the shared secret. This creates a shared AEAD context. + let mut receiver_ctx = hpke::setup_receiver::( + &OpModeR::Base, + &self.0, + &cipher.encapped_key.0, + INFO_ENTROPY, + )?; + + // On success, open_in_place_detached() will decrypt the ciphertext in place + let mut plaintext = cipher.text.to_vec(); + receiver_ctx.open_in_place_detached(&mut plaintext, associated_data, &cipher.tag.0)?; + Ok(plaintext) + } + + /// Get the public key associated with this secret key. + pub fn public_key(&self) -> PublicKey { + PublicKey(::sk_to_pk(&self.0)) + } +} + +pub fn generate() -> (SecretKey, PublicKey) { + let mut csprng = ::from_entropy(); + let (sk, pk) = ::gen_keypair(&mut csprng); + (SecretKey(sk), PublicKey(pk)) +} + +#[cfg(test)] +mod tests { + #[test] + fn test_encrypt_decrypt() { + let (sk, pk) = super::generate(); + let msg = b"hello world"; + let associated_data = b"associated data"; + + let cipher = pk.encrypt(msg, associated_data).unwrap(); + let decrypted = sk.decrypt(&cipher, associated_data).unwrap(); + + assert_eq!(msg, &decrypted[..]); + } + + #[test] + fn test_serialization_format() { + let sk_hex = "cf3df427dc1377914349b592cfff8deb4b9f8ab1cc4baa8e8e004b6502ac1ca0"; + let pk_hex = "0e6d143bff1d67f297ac68cb9be3667e38f1dc2b244be48bf1d6c6bd7d367c3c"; + + let sk = super::SecretKey::try_from_bytes(&hex::decode(sk_hex).unwrap()).unwrap(); + let pk = super::PublicKey::try_from_bytes(&hex::decode(pk_hex).unwrap()).unwrap(); + assert_eq!(sk.public_key(), pk); + } +} diff --git a/keys/src/lib.rs b/keys/src/lib.rs new file mode 100644 index 000000000..a486f3543 --- /dev/null +++ b/keys/src/lib.rs @@ -0,0 +1 @@ +pub mod hpke; diff --git a/node/Cargo.toml b/node/Cargo.toml index 6b28242fa..28e0c5899 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -38,3 +38,4 @@ near-primitives = "0.17" near-sdk = "4.1.1" mpc-contract = { path = "../contract" } +mpc-keys = { path = "../keys" } diff --git a/node/src/cli.rs b/node/src/cli.rs index 005ac4d63..35591ce48 100644 --- a/node/src/cli.rs +++ b/node/src/cli.rs @@ -9,6 +9,8 @@ use tokio::sync::mpsc; use tracing_subscriber::EnvFilter; use url::Url; +use mpc_keys::hpke; + #[derive(Parser, Debug)] pub enum Cli { Start { @@ -34,6 +36,13 @@ pub enum Cli { /// The web port for this server #[arg(long, env("MPC_RECOVERY_WEB_PORT"))] web_port: u16, + // TODO: need to add in CipherPK type for parsing. + /// The cipher public key used to encrypt messages between nodes. + #[arg(long, env("MPC_RECOVERY_CIPHER_PK"))] + cipher_pk: String, + /// The cipher secret key used to decrypt messages between nodes. + #[arg(long, env("MPC_RECOVERY_CIPHER_SK"))] + cipher_sk: String, /// NEAR Lake Indexer options #[clap(flatten)] indexer_options: indexer::Options, @@ -55,6 +64,8 @@ impl Cli { account, account_sk, web_port, + cipher_pk, + cipher_sk, indexer_options, } => { let mut args = vec![ @@ -71,6 +82,10 @@ impl Cli { account_sk.to_string(), "--web-port".to_string(), web_port.to_string(), + "--cipher-pk".to_string(), + cipher_pk, + "--cipher-sk".to_string(), + cipher_sk, ]; args.extend(indexer_options.into_str_args()); args @@ -100,6 +115,8 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> { mpc_contract_id, account, account_sk, + cipher_pk, + cipher_sk, indexer_options, } => { tokio::runtime::Builder::new_multi_thread() @@ -122,6 +139,7 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> { rpc_client.clone(), signer.clone(), receiver, + hpke::PublicKey::try_from_bytes(&hex::decode(cipher_pk)?).unwrap(), ); tracing::debug!("protocol initialized"); let protocol_handle = tokio::spawn(async move { @@ -129,6 +147,8 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> { }); tracing::debug!("protocol thread spawned"); let mpc_contract_id_cloned = mpc_contract_id.clone(); + let cipher_sk = + hpke::SecretKey::try_from_bytes(&hex::decode(cipher_sk)?).unwrap(); let web_handle = tokio::spawn(async move { web::run( web_port, @@ -136,6 +156,7 @@ pub fn run(cmd: Cli) -> anyhow::Result<()> { rpc_client, signer, sender, + cipher_sk, protocol_state, ) .await diff --git a/node/src/http_client.rs b/node/src/http_client.rs index 7538b2855..d54454fc1 100644 --- a/node/src/http_client.rs +++ b/node/src/http_client.rs @@ -1,5 +1,7 @@ +use crate::protocol::message::SignedMessage; use crate::protocol::MpcMessage; use cait_sith::protocol::Participant; +use mpc_keys::hpke; use reqwest::{Client, IntoUrl}; use std::str::Utf8Error; use tokio_retry::strategy::{jitter, ExponentialBackoff}; @@ -9,19 +11,30 @@ use tokio_retry::Retry; pub enum SendError { #[error("http request was unsuccessful: {0}")] Unsuccessful(String), + #[error("serialization unsuccessful: {0}")] + DataConversionError(serde_json::Error), #[error("http client error: {0}")] ReqwestClientError(reqwest::Error), #[error("http response could not be parsed: {0}")] ReqwestBodyError(reqwest::Error), #[error("http response body is not valid utf-8: {0}")] MalformedResponse(Utf8Error), + #[error("encryption error: {0}")] + EncryptionError(String), } -pub async fn message( +pub async fn send_encrypted( + participant: Participant, + cipher_pk: &hpke::PublicKey, + sign_sk: &near_crypto::SecretKey, client: &Client, url: U, message: MpcMessage, ) -> Result<(), SendError> { + let encrypted = SignedMessage::encrypt(message, participant, sign_sk, cipher_pk) + .map_err(|err| SendError::EncryptionError(err.to_string()))?; + tracing::debug!(?participant, ciphertext = ?encrypted.text, "sending encrypted"); + let _span = tracing::info_span!("message_request"); let mut url = url.into_url().unwrap(); url.set_path("msg"); @@ -30,7 +43,7 @@ pub async fn message( let response = client .post(url.clone()) .header("content-type", "application/json") - .json(&message) + .json(&encrypted) .send() .await .map_err(SendError::ReqwestClientError)?; @@ -89,3 +102,29 @@ pub async fn join(client: &Client, url: U, me: &Participant) -> Resu let retry_strategy = ExponentialBackoff::from_millis(10).map(jitter).take(3); Retry::spawn(retry_strategy, action).await } + +#[cfg(test)] +mod tests { + use crate::protocol::message::GeneratingMessage; + use crate::protocol::MpcMessage; + + #[test] + fn test_sending_encrypted_message() { + let associated_data = b""; + let (sk, pk) = mpc_keys::hpke::generate(); + let starting_message = MpcMessage::Generating(GeneratingMessage { + from: cait_sith::protocol::Participant::from(0), + data: vec![], + }); + + let message = serde_json::to_vec(&starting_message).unwrap(); + let message = pk.encrypt(&message, associated_data).unwrap(); + + let message = serde_json::to_vec(&message).unwrap(); + let cipher = serde_json::from_slice(&message).unwrap(); + let message = sk.decrypt(&cipher, associated_data).unwrap(); + let message: MpcMessage = serde_json::from_slice(&message).unwrap(); + + assert_eq!(starting_message, message); + } +} diff --git a/node/src/protocol/consensus.rs b/node/src/protocol/consensus.rs index ad8372983..051871dd2 100644 --- a/node/src/protocol/consensus.rs +++ b/node/src/protocol/consensus.rs @@ -12,10 +12,13 @@ use crate::{http_client, rpc_client}; use async_trait::async_trait; use cait_sith::protocol::{InitializationError, Participant}; use k256::Secp256k1; +use mpc_keys::hpke; use near_crypto::InMemorySigner; use near_primitives::transaction::{Action, FunctionCallAction}; use near_primitives::types::AccountId; use std::cmp::Ordering; +use std::sync::Arc; +use tokio::sync::RwLock; use url::Url; pub trait ConsensusCtx { @@ -25,6 +28,8 @@ pub trait ConsensusCtx { fn signer(&self) -> &InMemorySigner; fn mpc_contract_id(&self) -> &AccountId; fn my_address(&self) -> &Url; + fn cipher_pk(&self) -> &hpke::PublicKey; + fn sign_pk(&self) -> near_crypto::PublicKey; } #[derive(thiserror::Error, Debug)] @@ -95,18 +100,20 @@ impl ConsensusProtocol for StartedState { threshold: contract_state.threshold, private_share, public_key, - triple_manager: TripleManager::new( + triple_manager: Arc::new(RwLock::new(TripleManager::new( participants_vec.clone(), ctx.me(), contract_state.threshold, epoch, - ), - presignature_manager: PresignatureManager::new( - participants_vec, - ctx.me(), - contract_state.threshold, - epoch, - ), + ))), + presignature_manager: Arc::new(RwLock::new( + PresignatureManager::new( + participants_vec, + ctx.me(), + contract_state.threshold, + epoch, + ), + )), })) } else { Ok(NodeState::Joining(JoiningState { public_key })) @@ -150,7 +157,7 @@ impl ConsensusProtocol for StartedState { Ok(NodeState::Generating(GeneratingState { participants, threshold: contract_state.threshold, - protocol: Box::new(protocol), + protocol: Arc::new(RwLock::new(protocol)), })) } else { tracing::info!("we are not a part of the initial participant set, waiting for key generation to complete"); @@ -276,18 +283,18 @@ impl ConsensusProtocol for WaitingForConsensusState { threshold: self.threshold, private_share: self.private_share, public_key: self.public_key, - triple_manager: TripleManager::new( + triple_manager: Arc::new(RwLock::new(TripleManager::new( participants_vec.clone(), ctx.me(), self.threshold, self.epoch, - ), - presignature_manager: PresignatureManager::new( + ))), + presignature_manager: Arc::new(RwLock::new(PresignatureManager::new( participants_vec, ctx.me(), self.threshold, self.epoch, - ), + ))), })) } }, @@ -503,11 +510,11 @@ impl ConsensusProtocol for JoiningState { votes_to_go = contract_state.threshold - voted.len(), "trying to get participants to vote for us" ); - for (p, url) in contract_state.participants { + for (p, info) in contract_state.participants { if voted.contains(&p) { continue; } - http_client::join(ctx.http_client(), url, &ctx.me()) + http_client::join(ctx.http_client(), info.url, &ctx.me()) .await .unwrap() } @@ -517,6 +524,8 @@ impl ConsensusProtocol for JoiningState { let args = serde_json::json!({ "participant_id": ctx.me(), "url": ctx.my_address(), + "cipher_pk": ctx.cipher_pk().to_bytes(), + "sign_pk": ctx.sign_pk(), }); ctx.rpc_client() .send_tx( @@ -597,6 +606,6 @@ fn start_resharing( new_participants: contract_state.new_participants, threshold: contract_state.threshold, public_key: contract_state.public_key, - protocol: Box::new(protocol), + protocol: Arc::new(RwLock::new(protocol)), })) } diff --git a/node/src/protocol/contract.rs b/node/src/protocol/contract.rs index e6075dde6..2276e85c2 100644 --- a/node/src/protocol/contract.rs +++ b/node/src/protocol/contract.rs @@ -1,15 +1,41 @@ use crate::types::PublicKey; use crate::util::NearPublicKeyExt; use cait_sith::protocol::Participant; -use mpc_contract::{ParticipantInfo, ProtocolContractState}; +use mpc_contract::ProtocolContractState; +use mpc_keys::hpke; +use near_primitives::borsh::BorshDeserialize; use near_sdk::AccountId; use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; -use url::Url; + +type ParticipantId = u32; + +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] +pub struct ParticipantInfo { + pub id: ParticipantId, + pub account_id: AccountId, + pub url: String, + /// The public key used for encrypting messages. + pub cipher_pk: hpke::PublicKey, + /// The public key used for verifying messages. + pub sign_pk: near_crypto::PublicKey, +} + +impl From for ParticipantInfo { + fn from(value: mpc_contract::ParticipantInfo) -> Self { + ParticipantInfo { + id: value.id, + account_id: value.account_id, + url: value.url, + cipher_pk: hpke::PublicKey::from_bytes(&value.cipher_pk), + sign_pk: BorshDeserialize::try_from_slice(value.sign_pk.as_bytes()).unwrap(), + } + } +} #[derive(Serialize, Deserialize, Debug)] pub struct InitializingContractState { - pub participants: HashMap, + pub participants: HashMap, pub threshold: usize, pub pk_votes: HashMap>, } @@ -41,7 +67,7 @@ impl From for InitializingContractState #[derive(Serialize, Deserialize, Debug)] pub struct RunningContractState { pub epoch: u64, - pub participants: HashMap, + pub participants: HashMap, pub threshold: usize, pub public_key: PublicKey, pub candidates: HashMap, @@ -59,7 +85,7 @@ impl From for RunningContractState { candidates: value .candidates .into_iter() - .map(|(p, p_info)| (Participant::from(p), p_info)) + .map(|(p, p_info)| (Participant::from(p), p_info.into())) .collect(), join_votes: value .join_votes @@ -88,8 +114,8 @@ impl From for RunningContractState { #[derive(Serialize, Deserialize, Debug)] pub struct ResharingContractState { pub old_epoch: u64, - pub old_participants: HashMap, - pub new_participants: HashMap, + pub old_participants: HashMap, + pub new_participants: HashMap, pub threshold: usize, pub public_key: PublicKey, pub finished_votes: HashSet, @@ -120,7 +146,7 @@ pub enum ProtocolState { } impl ProtocolState { - pub fn participants(&self) -> &HashMap { + pub fn participants(&self) -> &HashMap { match self { ProtocolState::Initializing(InitializingContractState { participants, .. }) => { participants @@ -164,15 +190,10 @@ impl TryFrom for ProtocolState { } fn contract_participants_into_cait_participants( - participants: HashMap, -) -> HashMap { + participants: HashMap, +) -> HashMap { participants .into_values() - .map(|p| { - ( - Participant::from(p.id), - Url::try_from(p.url.as_str()).unwrap(), - ) - }) + .map(|p| (Participant::from(p.id), p.into())) .collect() } diff --git a/node/src/protocol/cryptography.rs b/node/src/protocol/cryptography.rs index 0aed2fd36..2f96972f6 100644 --- a/node/src/protocol/cryptography.rs +++ b/node/src/protocol/cryptography.rs @@ -1,3 +1,5 @@ +use std::sync::PoisonError; + use super::state::{GeneratingState, NodeState, ResharingState, RunningState}; use crate::http_client::{self, SendError}; use crate::protocol::message::{GeneratingMessage, ResharingMessage}; @@ -10,6 +12,7 @@ use k256::elliptic_curve::group::GroupEncoding; pub trait CryptographicCtx { fn me(&self) -> Participant; fn http_client(&self) -> &reqwest::Client; + fn sign_sk(&self) -> &near_crypto::SecretKey; } #[derive(thiserror::Error, Debug)] @@ -22,6 +25,21 @@ pub enum CryptographicError { CaitSithInitializationError(#[from] InitializationError), #[error("cait-sith protocol error: {0}")] CaitSithProtocolError(#[from] ProtocolError), + #[error("sync failed: {0}")] + SyncError(String), + #[error(transparent)] + DataConversion(#[from] serde_json::Error), + #[error("encryption failed: {0}")] + Encryption(String), + #[error("more than one writing to state: {0}")] + InvalidStateHandle(String), +} + +impl From> for CryptographicError { + fn from(_: PoisonError) -> Self { + let typename = std::any::type_name::(); + Self::SyncError(format!("PoisonError: {typename}")) + } } #[async_trait] @@ -39,23 +57,28 @@ impl CryptographicProtocol for GeneratingState { ctx: C, ) -> Result { tracing::info!("progressing key generation"); + let mut protocol = self.protocol.write().await; loop { - let action = self.protocol.poke()?; + let action = protocol.poke()?; match action { Action::Wait => { + drop(protocol); tracing::debug!("waiting"); return Ok(NodeState::Generating(self)); } Action::SendMany(m) => { tracing::debug!("sending a message to many participants"); - for (p, url) in &self.participants { + for (p, info) in &self.participants { if p == &ctx.me() { // Skip yourself, cait-sith never sends messages to oneself continue; } - http_client::message( + http_client::send_encrypted( + ctx.me(), + &info.cipher_pk, + ctx.sign_sk(), ctx.http_client(), - url.clone(), + info.url.clone(), MpcMessage::Generating(GeneratingMessage { from: ctx.me(), data: m.clone(), @@ -67,10 +90,13 @@ impl CryptographicProtocol for GeneratingState { Action::SendPrivate(to, m) => { tracing::debug!("sending a private message to {to:?}"); match self.participants.get(&to) { - Some(url) => { - http_client::message( + Some(info) => { + http_client::send_encrypted( + ctx.me(), + &info.cipher_pk, + ctx.sign_sk(), ctx.http_client(), - url.clone(), + info.url.clone(), MpcMessage::Generating(GeneratingMessage { from: ctx.me(), data: m.clone(), @@ -108,23 +134,28 @@ impl CryptographicProtocol for ResharingState { ctx: C, ) -> Result { tracing::info!("progressing key reshare"); + let mut protocol = self.protocol.write().await; loop { - let action = self.protocol.poke()?; + let action = protocol.poke()?; match action { Action::Wait => { + drop(protocol); tracing::debug!("waiting"); return Ok(NodeState::Resharing(self)); } Action::SendMany(m) => { tracing::debug!("sending a message to all participants"); - for (p, url) in &self.new_participants { + for (p, info) in &self.new_participants { if p == &ctx.me() { // Skip yourself, cait-sith never sends messages to oneself continue; } - http_client::message( + http_client::send_encrypted( + ctx.me(), + &info.cipher_pk, + ctx.sign_sk(), ctx.http_client(), - url.clone(), + info.url.clone(), MpcMessage::Resharing(ResharingMessage { epoch: self.old_epoch, from: ctx.me(), @@ -137,10 +168,13 @@ impl CryptographicProtocol for ResharingState { Action::SendPrivate(to, m) => { tracing::debug!("sending a private message to {to:?}"); match self.new_participants.get(&to) { - Some(url) => { - http_client::message( + Some(info) => { + http_client::send_encrypted( + ctx.me(), + &info.cipher_pk, + ctx.sign_sk(), ctx.http_client(), - url.clone(), + info.url.clone(), MpcMessage::Resharing(ResharingMessage { epoch: self.old_epoch, from: ctx.me(), @@ -173,20 +207,34 @@ impl CryptographicProtocol for RunningState { mut self, ctx: C, ) -> Result { - if self.triple_manager.my_len() < 2 { - self.triple_manager.generate()?; + let mut triple_manager = self.triple_manager.write().await; + if triple_manager.my_len() < 2 { + triple_manager.generate()?; } - for (p, msg) in self.triple_manager.poke()? { - let url = self.participants.get(&p).unwrap(); - http_client::message(ctx.http_client(), url.clone(), MpcMessage::Triple(msg)).await?; + for (p, msg) in triple_manager.poke()? { + let info = self + .participants + .get(&p) + .ok_or(CryptographicError::UnknownParticipant(p))?; + + http_client::send_encrypted( + ctx.me(), + &info.cipher_pk, + ctx.sign_sk(), + ctx.http_client(), + info.url.clone(), + MpcMessage::Triple(msg), + ) + .await?; } - if self.presignature_manager.potential_len() < 2 { + let mut presignature_manager = self.presignature_manager.write().await; + if presignature_manager.potential_len() < 2 { // To ensure there is no contention between different nodes we are only using triples // that we proposed. This way in a non-BFT environment we are guaranteed to never try // to use the same triple as any other node. - if let Some((triple0, triple1)) = self.triple_manager.take_mine_twice() { - self.presignature_manager.generate( + if let Some((triple0, triple1)) = triple_manager.take_mine_twice() { + presignature_manager.generate( triple0, triple1, &self.public_key, @@ -196,15 +244,20 @@ impl CryptographicProtocol for RunningState { tracing::debug!("we don't have enough triples to generate a presignature"); } } - for (p, msg) in self.presignature_manager.poke()? { - let url = self.participants.get(&p).unwrap(); - http_client::message( + drop(triple_manager); + for (p, msg) in presignature_manager.poke()? { + let info = self.participants.get(&p).unwrap(); + http_client::send_encrypted( + ctx.me(), + &info.cipher_pk, + ctx.sign_sk(), ctx.http_client(), - url.clone(), + info.url.clone(), MpcMessage::Presignature(msg), ) .await?; } + drop(presignature_manager); Ok(NodeState::Running(self)) } diff --git a/node/src/protocol/message.rs b/node/src/protocol/message.rs index 7c64e2f85..d58eb8c7c 100644 --- a/node/src/protocol/message.rs +++ b/node/src/protocol/message.rs @@ -1,27 +1,35 @@ use std::collections::{HashMap, VecDeque}; +use std::sync::Arc; +use crate::http_client::SendError; + +use super::cryptography::CryptographicError; use super::state::{GeneratingState, NodeState, ResharingState, RunningState}; +use async_trait::async_trait; use cait_sith::protocol::{InitializationError, MessageData, Participant, ProtocolError}; +use mpc_keys::hpke::{self, Ciphered}; +use near_crypto::Signature; use serde::{Deserialize, Serialize}; +use tokio::sync::RwLock; pub trait MessageCtx { fn me(&self) -> Participant; } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct GeneratingMessage { pub from: Participant, pub data: MessageData, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct ResharingMessage { pub epoch: u64, pub from: Participant, pub data: MessageData, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct TripleMessage { pub id: u64, pub epoch: u64, @@ -29,7 +37,7 @@ pub struct TripleMessage { pub data: MessageData, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct PresignatureMessage { pub id: u64, pub triple0: u64, @@ -39,7 +47,7 @@ pub struct PresignatureMessage { pub data: MessageData, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] pub enum MpcMessage { Generating(GeneratingMessage), Resharing(ResharingMessage), @@ -88,65 +96,106 @@ pub enum MessageHandleError { CaitSithInitializationError(#[from] InitializationError), #[error("cait-sith protocol error: {0}")] CaitSithProtocolError(#[from] ProtocolError), + #[error("sync failed: {0}")] + SyncError(String), + #[error("failed to send a message: {0}")] + SendError(SendError), + #[error("unknown participant: {0:?}")] + UnknownParticipant(Participant), + #[error(transparent)] + DataConversion(#[from] serde_json::Error), + #[error("encryption failed: {0}")] + Encryption(String), + #[error("invalid state")] + InvalidStateHandle(String), +} + +impl From for MessageHandleError { + fn from(value: CryptographicError) -> Self { + match value { + CryptographicError::CaitSithInitializationError(e) => { + Self::CaitSithInitializationError(e) + } + CryptographicError::CaitSithProtocolError(e) => Self::CaitSithProtocolError(e), + CryptographicError::SyncError(e) => Self::SyncError(e), + CryptographicError::SendError(e) => Self::SendError(e), + CryptographicError::UnknownParticipant(e) => Self::UnknownParticipant(e), + CryptographicError::DataConversion(e) => Self::DataConversion(e), + CryptographicError::Encryption(e) => Self::Encryption(e), + CryptographicError::InvalidStateHandle(e) => Self::InvalidStateHandle(e), + } + } } +#[async_trait] pub trait MessageHandler { - fn handle( + async fn handle( &mut self, ctx: C, queue: &mut MpcMessageQueue, ) -> Result<(), MessageHandleError>; } +#[async_trait] impl MessageHandler for GeneratingState { - fn handle( + async fn handle( &mut self, _ctx: C, queue: &mut MpcMessageQueue, ) -> Result<(), MessageHandleError> { + let mut protocol = self.protocol.write().await; while let Some(msg) = queue.generating.pop_front() { tracing::debug!("handling new generating message"); - self.protocol.message(msg.from, msg.data); + protocol.message(msg.from, msg.data); } Ok(()) } } +#[async_trait] impl MessageHandler for ResharingState { - fn handle( + async fn handle( &mut self, _ctx: C, queue: &mut MpcMessageQueue, ) -> Result<(), MessageHandleError> { let q = queue.resharing_bins.entry(self.old_epoch).or_default(); + let mut protocol = self.protocol.write().await; while let Some(msg) = q.pop_front() { tracing::debug!("handling new resharing message"); - self.protocol.message(msg.from, msg.data); + protocol.message(msg.from, msg.data); } Ok(()) } } +#[async_trait] impl MessageHandler for RunningState { - fn handle( + async fn handle( &mut self, _ctx: C, queue: &mut MpcMessageQueue, ) -> Result<(), MessageHandleError> { + let mut triple_manager = self.triple_manager.write().await; for (id, queue) in queue.triple_bins.entry(self.epoch).or_default() { - if let Some(protocol) = self.triple_manager.get_or_generate(*id)? { + if let Some(protocol) = triple_manager.get_or_generate(*id)? { + let mut protocol = protocol + .write() + .map_err(|err| MessageHandleError::SyncError(err.to_string()))?; while let Some(message) = queue.pop_front() { protocol.message(message.from, message.data); } } } + + let mut presignature_manager = self.presignature_manager.write().await; for (id, queue) in queue.presignature_bins.entry(self.epoch).or_default() { while let Some(message) = queue.pop_front() { - if let Some(protocol) = self.presignature_manager.get_or_generate( + if let Some(protocol) = presignature_manager.get_or_generate( *id, message.triple0, message.triple1, - &mut self.triple_manager, + &mut triple_manager, &self.public_key, &self.private_share, )? { @@ -158,16 +207,17 @@ impl MessageHandler for RunningState { } } +#[async_trait] impl MessageHandler for NodeState { - fn handle( + async fn handle( &mut self, ctx: C, queue: &mut MpcMessageQueue, ) -> Result<(), MessageHandleError> { match self { - NodeState::Generating(state) => state.handle(ctx, queue), - NodeState::Resharing(state) => state.handle(ctx, queue), - NodeState::Running(state) => state.handle(ctx, queue), + NodeState::Generating(state) => state.handle(ctx, queue).await, + NodeState::Resharing(state) => state.handle(ctx, queue).await, + NodeState::Running(state) => state.handle(ctx, queue).await, _ => { tracing::debug!("skipping message processing"); Ok(()) @@ -175,3 +225,66 @@ impl MessageHandler for NodeState { } } } + +/// A signed message that can be encrypted. Note that the message's signature is included +/// in the encrypted message to avoid from it being tampered with without first decrypting. +#[derive(Serialize, Deserialize)] +pub struct SignedMessage { + /// The message with all it's related info. + pub msg: T, + /// The signature used to verify the authenticity of the encrypted message. + pub sig: Signature, + /// From which particpant the message was sent. + pub from: Participant, +} + +impl SignedMessage { + pub const ASSOCIATED_DATA: &'static [u8] = b""; +} + +impl SignedMessage +where + T: Serialize, +{ + pub fn encrypt( + msg: T, + from: Participant, + sign_sk: &near_crypto::SecretKey, + cipher_pk: &hpke::PublicKey, + ) -> Result { + let msg = serde_json::to_vec(&msg)?; + let sig = sign_sk.sign(&msg); + let msg = SignedMessage { msg, sig, from }; + let msg = serde_json::to_vec(&msg)?; + let ciphered = cipher_pk + .encrypt(&msg, SignedMessage::::ASSOCIATED_DATA) + .map_err(|e| CryptographicError::Encryption(e.to_string()))?; + Ok(ciphered) + } +} + +impl SignedMessage +where + T: for<'a> Deserialize<'a>, +{ + pub async fn decrypt( + cipher_sk: &hpke::SecretKey, + protocol_state: &Arc>, + encrypted: Ciphered, + ) -> Result { + let message = cipher_sk + .decrypt(&encrypted, SignedMessage::::ASSOCIATED_DATA) + .map_err(|err| CryptographicError::Encryption(err.to_string()))?; + let SignedMessage::> { msg, sig, from } = serde_json::from_slice(&message)?; + let Some(sender) = protocol_state.read().await.fetch_participant(from) else { + return Err(CryptographicError::UnknownParticipant(from)); + }; + if !sig.verify(&msg, &sender.sign_pk) { + return Err(CryptographicError::Encryption( + "invalid signature while verifying authenticity of encrypted ".to_string(), + )); + } + + Ok(serde_json::from_slice(&msg)?) + } +} diff --git a/node/src/protocol/mod.rs b/node/src/protocol/mod.rs index aaccc1132..375fccb4d 100644 --- a/node/src/protocol/mod.rs +++ b/node/src/protocol/mod.rs @@ -1,12 +1,13 @@ mod consensus; mod contract; mod cryptography; -mod message; mod presignature; -mod state; mod triple; -pub use contract::ProtocolState; +pub mod message; +pub mod state; + +pub use contract::{ParticipantInfo, ProtocolState}; pub use message::MpcMessage; pub use state::NodeState; @@ -26,6 +27,8 @@ use tokio::sync::mpsc::{self, error::TryRecvError}; use tokio::sync::RwLock; use url::Url; +use mpc_keys::hpke; + struct Ctx { me: Participant, my_address: Url, @@ -33,6 +36,8 @@ struct Ctx { signer: InMemorySigner, rpc_client: near_fetch::Client, http_client: reqwest::Client, + cipher_pk: hpke::PublicKey, + sign_sk: near_crypto::SecretKey, } impl ConsensusCtx for &Ctx { @@ -59,6 +64,14 @@ impl ConsensusCtx for &Ctx { fn my_address(&self) -> &Url { &self.my_address } + + fn cipher_pk(&self) -> &hpke::PublicKey { + &self.cipher_pk + } + + fn sign_pk(&self) -> near_crypto::PublicKey { + self.sign_sk.public_key() + } } impl CryptographicCtx for &Ctx { @@ -69,6 +82,10 @@ impl CryptographicCtx for &Ctx { fn http_client(&self) -> &reqwest::Client { &self.http_client } + + fn sign_sk(&self) -> &near_crypto::SecretKey { + &self.sign_sk + } } impl MessageCtx for &Ctx { @@ -91,15 +108,18 @@ impl MpcSignProtocol { rpc_client: near_fetch::Client, signer: InMemorySigner, receiver: mpsc::Receiver, + cipher_pk: hpke::PublicKey, ) -> (Self, Arc>) { let state = Arc::new(RwLock::new(NodeState::Starting)); let ctx = Ctx { me, my_address: my_address.into_url().unwrap(), mpc_contract_id, - signer, rpc_client, http_client: reqwest::Client::new(), + cipher_pk, + sign_sk: signer.secret_key.clone(), + signer, }; let protocol = MpcSignProtocol { ctx, @@ -145,13 +165,19 @@ impl MpcSignProtocol { } } } - let mut state_guard = self.state.write().await; - let mut state = std::mem::take(&mut *state_guard); + + let mut state = { + let guard = self.state.write().await; + guard.clone() + }; state = state.progress(&self.ctx).await?; state = state.advance(&self.ctx, contract_state).await?; - state.handle(&self.ctx, &mut queue)?; - *state_guard = state; - drop(state_guard); + state.handle(&self.ctx, &mut queue).await?; + + let mut guard = self.state.write().await; + *guard = state; + drop(guard); + tokio::time::sleep(Duration::from_millis(1000)).await; } } diff --git a/node/src/protocol/state.rs b/node/src/protocol/state.rs index 8c1d19b88..ee4368afe 100644 --- a/node/src/protocol/state.rs +++ b/node/src/protocol/state.rs @@ -1,56 +1,65 @@ use super::presignature::PresignatureManager; use super::triple::TripleManager; +use crate::protocol::ParticipantInfo; use crate::types::{KeygenProtocol, PrivateKeyShare, PublicKey, ReshareProtocol}; use cait_sith::protocol::Participant; use std::collections::HashMap; -use url::Url; +use std::sync::Arc; +use tokio::sync::RwLock; +#[derive(Clone)] pub struct PersistentNodeData { pub epoch: u64, pub private_share: PrivateKeyShare, pub public_key: PublicKey, } +#[derive(Clone)] pub struct StartedState(pub Option); +#[derive(Clone)] pub struct GeneratingState { - pub participants: HashMap, + pub participants: HashMap, pub threshold: usize, pub protocol: KeygenProtocol, } +#[derive(Clone)] pub struct WaitingForConsensusState { pub epoch: u64, - pub participants: HashMap, + pub participants: HashMap, pub threshold: usize, pub private_share: PrivateKeyShare, pub public_key: PublicKey, } +#[derive(Clone)] pub struct RunningState { pub epoch: u64, - pub participants: HashMap, + pub participants: HashMap, pub threshold: usize, pub private_share: PrivateKeyShare, pub public_key: PublicKey, - pub triple_manager: TripleManager, - pub presignature_manager: PresignatureManager, + pub triple_manager: Arc>, + pub presignature_manager: Arc>, } +#[derive(Clone)] pub struct ResharingState { pub old_epoch: u64, - pub old_participants: HashMap, - pub new_participants: HashMap, + pub old_participants: HashMap, + pub new_participants: HashMap, pub threshold: usize, pub public_key: PublicKey, pub protocol: ReshareProtocol, } +#[derive(Clone)] pub struct JoiningState { pub public_key: PublicKey, } -#[derive(Default)] +#[derive(Clone, Default)] #[allow(clippy::large_enum_variant)] pub enum NodeState { #[default] @@ -62,3 +71,25 @@ pub enum NodeState { Resharing(ResharingState), Joining(JoiningState), } + +impl NodeState { + pub fn fetch_participant(&self, p: Participant) -> Option { + let participants = match self { + NodeState::Running(state) => &state.participants, + NodeState::Generating(state) => &state.participants, + NodeState::WaitingForConsensus(state) => &state.participants, + NodeState::Resharing(state) => { + if let Some(info) = state.new_participants.get(&p) { + return Some(info.clone()); + } else if let Some(info) = state.old_participants.get(&p) { + return Some(info.clone()); + } else { + return None; + } + } + _ => return None, + }; + + participants.get(&p).cloned() + } +} diff --git a/node/src/protocol/triple.rs b/node/src/protocol/triple.rs index ca5983d96..cf037e07a 100644 --- a/node/src/protocol/triple.rs +++ b/node/src/protocol/triple.rs @@ -1,3 +1,4 @@ +use super::cryptography::CryptographicError; use super::message::TripleMessage; use crate::types::TripleProtocol; use crate::util::AffinePointExt; @@ -6,6 +7,7 @@ use cait_sith::triples::{TriplePub, TripleShare}; use k256::Secp256k1; use std::collections::hash_map::Entry; use std::collections::{HashMap, VecDeque}; +use std::sync::{Arc, RwLock}; /// Unique number used to identify a specific ongoing triple generation protocol. /// Without `TripleId` it would be unclear where to route incoming cait-sith triple generation @@ -74,18 +76,18 @@ impl TripleManager { /// Returns the number of unspent triples we will have in the manager once /// all ongoing generation protocols complete. pub fn potential_len(&self) -> usize { - self.triples.len() + self.generators.len() + self.len() + self.generators.len() } /// Starts a new Beaver triple generation protocol. pub fn generate(&mut self) -> Result<(), InitializationError> { let id = rand::random(); tracing::info!(id, "starting protocol to generate a new triple"); - let protocol: TripleProtocol = Box::new(cait_sith::triples::generate_triple( + let protocol: TripleProtocol = Arc::new(RwLock::new(cait_sith::triples::generate_triple( &self.participants, self.me, self.threshold, - )?); + )?)); self.generators.insert( id, TripleGenerator { @@ -133,18 +135,18 @@ impl TripleManager { pub fn get_or_generate( &mut self, id: TripleId, - ) -> Result, InitializationError> { + ) -> Result, CryptographicError> { if self.triples.contains_key(&id) { Ok(None) } else { match self.generators.entry(id) { Entry::Vacant(e) => { tracing::info!(id, "joining protocol to generate a new triple"); - let protocol = Box::new(cait_sith::triples::generate_triple( + let protocol = Arc::new(RwLock::new(cait_sith::triples::generate_triple( &self.participants, self.me, self.threshold, - )?); + )?)); let generator = e.insert(TripleGenerator { protocol, mine: false, @@ -165,13 +167,25 @@ impl TripleManager { let mut result = Ok(()); self.generators.retain(|id, generator| { loop { - let action = match generator.protocol.poke() { + let mut protocol = match generator.protocol.write() { + Ok(protocol) => protocol, + Err(err) => { + tracing::error!( + ?err, + "failed to acquire lock on triple generation protocol" + ); + break false; + } + }; + + let action = match protocol.poke() { Ok(action) => action, Err(e) => { result = Err(e); break false; } }; + match action { Action::Wait => { tracing::debug!("waiting"); @@ -216,6 +230,7 @@ impl TripleManager { public: output.1, }, ); + if generator.mine { self.mine.push_back(*id); } diff --git a/node/src/types.rs b/node/src/types.rs index 34b03c830..4d36caa46 100644 --- a/node/src/types.rs +++ b/node/src/types.rs @@ -1,12 +1,15 @@ +use std::sync::Arc; + use cait_sith::triples::TripleGenerationOutput; use cait_sith::PresignOutput; use cait_sith::{protocol::Protocol, KeygenOutput}; use k256::{elliptic_curve::CurveArithmetic, Secp256k1}; +use tokio::sync::RwLock; pub type PrivateKeyShare = ::Scalar; pub type PublicKey = ::AffinePoint; -pub type KeygenProtocol = Box> + Send + Sync>; -pub type ReshareProtocol = Box + Send + Sync>; +pub type KeygenProtocol = Arc> + Send + Sync>>; +pub type ReshareProtocol = Arc + Send + Sync>>; pub type TripleProtocol = - Box> + Send + Sync>; + Arc> + Send + Sync>>; pub type PresignatureProtocol = Box> + Send + Sync>; diff --git a/node/src/web/mod.rs b/node/src/web/mod.rs index 1cb31d637..631b14522 100644 --- a/node/src/web/mod.rs +++ b/node/src/web/mod.rs @@ -1,12 +1,14 @@ mod error; use self::error::MpcSignError; +use crate::protocol::message::SignedMessage; use crate::protocol::{MpcMessage, NodeState}; use axum::http::StatusCode; use axum::routing::{get, post}; use axum::{Extension, Json, Router}; use axum_extra::extract::WithRejection; use cait_sith::protocol::Participant; +use mpc_keys::hpke::{self, Ciphered}; use near_crypto::InMemorySigner; use near_primitives::transaction::{Action, FunctionCallAction}; use near_primitives::types::AccountId; @@ -20,6 +22,7 @@ struct AxumState { signer: InMemorySigner, sender: Sender, protocol_state: Arc>, + cipher_sk: hpke::SecretKey, } pub async fn run( @@ -28,6 +31,7 @@ pub async fn run( rpc_client: near_fetch::Client, signer: InMemorySigner, sender: Sender, + cipher_sk: hpke::SecretKey, protocol_state: Arc>, ) -> anyhow::Result<()> { tracing::debug!("running a node"); @@ -37,6 +41,7 @@ pub async fn run( signer, sender, protocol_state, + cipher_sk, }; let app = Router::new() @@ -72,13 +77,22 @@ pub struct MsgRequest { #[tracing::instrument(level = "debug", skip_all)] async fn msg( Extension(state): Extension>, - WithRejection(Json(message), _): WithRejection, MpcSignError>, + WithRejection(Json(encrypted), _): WithRejection, MpcSignError>, ) -> StatusCode { - tracing::debug!(?message, "received"); + tracing::debug!(ciphertext = ?encrypted.text, "received encrypted"); + let message = + match SignedMessage::decrypt(&state.cipher_sk, &state.protocol_state, encrypted).await { + Ok(msg) => msg, + Err(err) => { + tracing::error!(?err, "failed to decrypt or verify an encrypted message"); + return StatusCode::BAD_REQUEST; + } + }; + match state.sender.send(message).await { Ok(()) => StatusCode::OK, Err(e) => { - tracing::error!("failed to send a protocol message: {e}"); + tracing::error!("failed to send an encrypted protocol message: {e}"); StatusCode::INTERNAL_SERVER_ERROR } } @@ -144,13 +158,16 @@ async fn state(Extension(state): Extension>) -> (StatusCode, Json let protocol_state = state.protocol_state.read().await; match &*protocol_state { NodeState::Running(state) => { + let triple_count = state.triple_manager.read().await.len(); + let presignature_count = state.presignature_manager.read().await.len(); + tracing::debug!("not running, state unavailable"); ( StatusCode::OK, Json(StateView::Running { participants: state.participants.keys().cloned().collect(), - triple_count: state.triple_manager.len(), - presignature_count: state.presignature_manager.len(), + triple_count, + presignature_count, }), ) }