diff --git a/Cargo.lock b/Cargo.lock index 5f24967b..b03a31ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,12 +26,75 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2faccea4cc4ab4a667ce676a30e8ec13922a692c99bb8f5b11f1502c72e04220" + +[[package]] +name = "anstyle-parse" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys 0.52.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys 0.52.0", +] + [[package]] name = "anyhow" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" +[[package]] +name = "assert_cmd" +version = "2.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00ad3f3a942eee60335ab4342358c161ee296829e0d16ff42fc1d6cb07815467" +dependencies = [ + "anstyle", + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "async-trait" version = "0.1.77" @@ -40,7 +103,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -147,7 +210,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -194,12 +257,36 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base16" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + [[package]] name = "base64" version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "bit-set" version = "0.5.3" @@ -227,6 +314,17 @@ version = "2.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest 0.9.0", + "opaque-debug", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -236,12 +334,62 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc" +dependencies = [ + "memchr", + "regex-automata 0.4.5", + "serde", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "casper-types" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e01525b7bbae90fe9de3f1def6ffe05052a94ed7d14b1c2b38baec81eeec31b" +dependencies = [ + "base16", + "base64 0.13.1", + "bitflags 1.3.2", + "blake2", + "derp", + "ed25519-dalek", + "getrandom", + "hex", + "hex_fmt", + "humantime", + "k256", + "num", + "num-derive", + "num-integer", + "num-rational", + "num-traits", + "once_cell", + "pem", + "rand", + "serde", + "serde_bytes", + "serde_json", + "thiserror", + "uint", + "untrusted", +] + [[package]] name = "cc" version = "1.0.83" @@ -257,6 +405,58 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + [[package]] name = "cookie" version = "0.18.0" @@ -276,6 +476,24 @@ dependencies = [ "libc", ] +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -286,6 +504,54 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89b8c6a2e4b1f45971ad09761aafb85514a84744b67a95e32c3cc1352d1f65c" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] +name = "der" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "deranged" version = "0.3.11" @@ -295,12 +561,36 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derp" +version = "0.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9b84cfd9b6fa437e498215e5625e9e3ae3bf9bb54d623028a181c40820db169" +dependencies = [ + "untrusted", +] + [[package]] name = "diff" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + [[package]] name = "digest" version = "0.10.7" @@ -308,15 +598,78 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer", + "const-oid", "crypto-common", + "subtle", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "dotenvy" version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f628eaec48bfd21b865dc2950cfa014450c01d2fa2b69a86c2fd5844ec523c0" +dependencies = [ + "curve25519-dalek", + "ed25519", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -339,6 +692,31 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" + +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + [[package]] name = "fnv" version = "1.0.7" @@ -410,6 +788,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -429,6 +808,17 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + [[package]] name = "h2" version = "0.4.1" @@ -460,7 +850,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "322106e6bd0cba2d5ead589ddb8150a13d7c4217cf80d7c4f682ca994ccc6aa9" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "headers-core", "http 1.0.0", @@ -490,6 +880,27 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex_fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "http" version = "0.2.11" @@ -547,6 +958,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "hyper" version = "1.1.0" @@ -613,9 +1030,29 @@ version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2", +] + [[package]] name = "kairos-cli" version = "0.1.0" +dependencies = [ + "assert_cmd", + "casper-types", + "clap", + "hex", + "predicates", + "thiserror", +] [[package]] name = "kairos-server" @@ -732,6 +1169,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -742,6 +1185,84 @@ dependencies = [ "winapi", ] +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.17" @@ -777,6 +1298,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "overload" version = "0.1.1" @@ -806,6 +1333,17 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "pem" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd56cbd21fea48d0c440b41cd69c589faacade08c992d9a54e471b79d0fd13eb" +dependencies = [ + "base64 0.13.1", + "once_cell", + "regex", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -829,7 +1367,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -844,6 +1382,22 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "platforms" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" + [[package]] name = "powerfmt" version = "0.2.0" @@ -856,6 +1410,36 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "predicates" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174" + +[[package]] +name = "predicates-tree" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "pretty_assertions" version = "1.4.0" @@ -1012,6 +1596,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "rust-multipart-rfc7578_2" version = "0.6.1" @@ -1034,6 +1628,15 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustix" version = "0.38.30" @@ -1077,6 +1680,25 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" + [[package]] name = "serde" version = "1.0.195" @@ -1086,6 +1708,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_bytes" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.195" @@ -1094,7 +1725,7 @@ checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1116,6 +1747,7 @@ version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ + "indexmap", "itoa", "ryu", "serde", @@ -1151,7 +1783,18 @@ checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", ] [[package]] @@ -1172,6 +1815,16 @@ dependencies = [ "libc", ] +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core", +] + [[package]] name = "slab" version = "0.4.9" @@ -1197,6 +1850,45 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.48" @@ -1227,6 +1919,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + [[package]] name = "thiserror" version = "1.0.56" @@ -1244,7 +1942,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1329,7 +2027,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1394,7 +2092,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1448,6 +2146,18 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unarray" version = "0.1.4" @@ -1484,6 +2194,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + [[package]] name = "url" version = "2.5.0" @@ -1495,6 +2211,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "valuable" version = "0.1.0" @@ -1690,3 +2412,9 @@ name = "yansi" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" diff --git a/flake.nix b/flake.nix index d7278be3..0974826d 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,12 @@ kairosNodeAttrs = { src = lib.cleanSourceWith { src = craneLib.path ./.; - filter = path: type: craneLib.filterCargoSources path type; + filter = path: type: + # Allow static files. + (lib.hasInfix "/fixtures/" path) || + # Default filter (from crane) for .rs files. + (craneLib.filterCargoSources path type) + ; }; nativeBuildInputs = with pkgs; [ pkg-config ]; diff --git a/kairos-cli/Cargo.toml b/kairos-cli/Cargo.toml index 4a864138..abf507c8 100644 --- a/kairos-cli/Cargo.toml +++ b/kairos-cli/Cargo.toml @@ -13,3 +13,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +casper-types = { version = "4.0.1", features = ["std"] } # TODO: Change `std` -> `std-fs-io` in the future version. +clap = { version = "4.4.18", features = ["derive"] } +hex = "0.4.3" +thiserror = "1.0.56" + +[dev-dependencies] +assert_cmd = "2.0.13" +predicates = "3.1.0" diff --git a/kairos-cli/bin/main.rs b/kairos-cli/bin/main.rs index e7a11a96..0de33073 100644 --- a/kairos-cli/bin/main.rs +++ b/kairos-cli/bin/main.rs @@ -1,3 +1,31 @@ +use std::process; + +use clap::Parser; +use kairos_cli::commands::{self, Command}; + +#[derive(Parser)] +#[command(name = "Kairos Client", about = "CLI for interacting with Kairos")] +struct Cli { + #[command(subcommand)] + command: Command, +} + fn main() { - println!("Hello, world!"); + let cli = Cli::parse(); + + let result = match cli.command { + Command::Deposit(args) => commands::deposit::run(args), + Command::Transfer(args) => commands::transfer::run(args), + Command::Withdraw(args) => commands::withdraw::run(args), + }; + + match result { + Ok(output) => { + println!("{}", output) + } + Err(error) => { + eprintln!("{}", error); + process::exit(1); + } + } } diff --git a/kairos-cli/src/commands/deposit.rs b/kairos-cli/src/commands/deposit.rs new file mode 100644 index 00000000..a90650ff --- /dev/null +++ b/kairos-cli/src/commands/deposit.rs @@ -0,0 +1,26 @@ +use crate::common::args::{AmountArg, PrivateKeyPathArg}; +use crate::crypto::error::CryptoError; +use crate::crypto::signer::CasperSigner; +use crate::error::CliError; + +use clap::Parser; + +#[derive(Parser, Debug)] +pub struct Args { + #[clap(flatten)] + amount: AmountArg, + #[clap(flatten)] + private_key_path: PrivateKeyPathArg, +} + +pub fn run(args: Args) -> Result { + let _amount: u64 = args.amount.field; + let _signer = + CasperSigner::from_file(args.private_key_path.field).map_err(CryptoError::from)?; + + // TODO: Create transaction and sign it with `signer`. + + // TODO: Send transaction to the network, using Rust SDK. + + Ok("ok".to_string()) +} diff --git a/kairos-cli/src/commands/mod.rs b/kairos-cli/src/commands/mod.rs new file mode 100644 index 00000000..069a0721 --- /dev/null +++ b/kairos-cli/src/commands/mod.rs @@ -0,0 +1,15 @@ +pub mod deposit; +pub mod transfer; +pub mod withdraw; + +use clap::Subcommand; + +#[derive(Subcommand)] +pub enum Command { + #[command(about = "Deposits funds into your account")] + Deposit(deposit::Args), + #[command(about = "Transfers funds to another account")] + Transfer(transfer::Args), + #[command(about = "Withdraws funds from your account")] + Withdraw(withdraw::Args), +} diff --git a/kairos-cli/src/commands/transfer.rs b/kairos-cli/src/commands/transfer.rs new file mode 100644 index 00000000..508057eb --- /dev/null +++ b/kairos-cli/src/commands/transfer.rs @@ -0,0 +1,31 @@ +use crate::common::args::{AmountArg, PrivateKeyPathArg}; +use crate::crypto::error::CryptoError; +use crate::crypto::public_key::CasperPublicKey; +use crate::crypto::signer::CasperSigner; +use crate::error::CliError; +use crate::utils::parse_hex_string; + +use clap::Parser; + +#[derive(Parser)] +pub struct Args { + #[arg(long, short, value_name = "PUBLIC_KEY", value_parser = parse_hex_string)] + recipient: ::std::vec::Vec, // Absolute path is required here - see https://github.com/clap-rs/clap/issues/4626#issue-1528622454. + #[clap(flatten)] + amount: AmountArg, + #[clap(flatten)] + private_key_path: PrivateKeyPathArg, +} + +pub fn run(args: Args) -> Result { + let _recipient = CasperPublicKey::from_bytes(args.recipient.as_ref())?; + let _amount: u64 = args.amount.field; + let _signer = + CasperSigner::from_file(args.private_key_path.field).map_err(CryptoError::from)?; + + // TODO: Create transaction and sign it with `signer`. + + // TODO: Send transaction to the network, using Rust SDK. + + Ok("ok".to_string()) +} diff --git a/kairos-cli/src/commands/withdraw.rs b/kairos-cli/src/commands/withdraw.rs new file mode 100644 index 00000000..45a6b130 --- /dev/null +++ b/kairos-cli/src/commands/withdraw.rs @@ -0,0 +1,26 @@ +use crate::common::args::{AmountArg, PrivateKeyPathArg}; +use crate::crypto::error::CryptoError; +use crate::crypto::signer::CasperSigner; +use crate::error::CliError; + +use clap::Parser; + +#[derive(Parser)] +pub struct Args { + #[clap(flatten)] + amount: AmountArg, + #[clap(flatten)] + private_key_path: PrivateKeyPathArg, +} + +pub fn run(args: Args) -> Result { + let _amount: u64 = args.amount.field; + let _signer = + CasperSigner::from_file(args.private_key_path.field).map_err(CryptoError::from)?; + + // TODO: Create transaction and sign it with `signer`. + + // TODO: Send transaction to the network, using Rust SDK. + + Ok("ok".to_string()) +} diff --git a/kairos-cli/src/common/args.rs b/kairos-cli/src/common/args.rs new file mode 100644 index 00000000..696dfa12 --- /dev/null +++ b/kairos-cli/src/common/args.rs @@ -0,0 +1,15 @@ +use std::path::PathBuf; + +use clap::Args; + +#[derive(Args, Debug)] +pub struct AmountArg { + #[arg(name = "amount", long, short, value_name = "NUM_MOTES")] + pub field: u64, +} + +#[derive(Args, Debug)] +pub struct PrivateKeyPathArg { + #[arg(name = "private-key", long, short = 'k', value_name = "FILE_PATH")] + pub field: PathBuf, +} diff --git a/kairos-cli/src/common/mod.rs b/kairos-cli/src/common/mod.rs new file mode 100644 index 00000000..6e10f4ad --- /dev/null +++ b/kairos-cli/src/common/mod.rs @@ -0,0 +1 @@ +pub mod args; diff --git a/kairos-cli/src/crypto/error.rs b/kairos-cli/src/crypto/error.rs new file mode 100644 index 00000000..789afa5d --- /dev/null +++ b/kairos-cli/src/crypto/error.rs @@ -0,0 +1,15 @@ +use casper_types::ErrorExt; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum CryptoError { + /// Failed to parse a public key from a raw data. + #[error("failed to parse private key: {error}")] + FailedToParseKey { + #[from] + error: ErrorExt, + }, + /// Invalid public key (hexdigest) or other encoding related error. + #[error("failed to serialize/deserialize '{context}'")] + Serialization { context: &'static str }, +} diff --git a/kairos-cli/src/crypto/mod.rs b/kairos-cli/src/crypto/mod.rs new file mode 100644 index 00000000..b68afd01 --- /dev/null +++ b/kairos-cli/src/crypto/mod.rs @@ -0,0 +1,4 @@ +pub mod error; +pub mod private_key; +pub mod public_key; +pub mod signer; diff --git a/kairos-cli/src/crypto/private_key.rs b/kairos-cli/src/crypto/private_key.rs new file mode 100644 index 00000000..9cfd7902 --- /dev/null +++ b/kairos-cli/src/crypto/private_key.rs @@ -0,0 +1,11 @@ +use std::path::Path; + +use casper_types::ErrorExt; + +pub struct CasperPrivateKey(pub casper_types::SecretKey); + +impl CasperPrivateKey { + pub fn from_file>(file_path: P) -> Result { + casper_types::SecretKey::from_file(file_path).map(Self) + } +} diff --git a/kairos-cli/src/crypto/public_key.rs b/kairos-cli/src/crypto/public_key.rs new file mode 100644 index 00000000..9bf0d571 --- /dev/null +++ b/kairos-cli/src/crypto/public_key.rs @@ -0,0 +1,68 @@ +use crate::crypto::error::CryptoError; +use casper_types::bytesrepr::{FromBytes, ToBytes}; + +#[derive(Clone)] +pub struct CasperPublicKey(pub casper_types::PublicKey); + +impl CasperPublicKey { + pub fn from_bytes(bytes: &[u8]) -> Result { + let (public_key, _remainder) = + casper_types::PublicKey::from_bytes(bytes).map_err(|_e| { + CryptoError::Serialization { + context: "public key serialization", + } + })?; + Ok(Self(public_key)) + } + + #[allow(unused)] + fn to_bytes(&self) -> Result, CryptoError> { + self.0.to_bytes().map_err(|_e| CryptoError::Serialization { + context: "public key deserialization", + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_casper_ed25519_public_key() { + // This public key has a 01 prefix indicating Ed25519. + let bytes = + hex::decode("01c377281132044bd3278b039925eeb3efdb9d99dd5f46d9ec6a764add34581af7") + .unwrap(); + let result = CasperPublicKey::from_bytes(&bytes); + assert!( + result.is_ok(), + "Ed25519 public key should be parsed correctly" + ); + } + + #[test] + fn test_casper_secp256k1_public_key() { + // This public key has a 02 prefix indicating Secp256k1. + let bytes = + hex::decode("0202e99759649fa63a72c685b72e696b30c90f1deabb02d0d9b1de45eb371a73e5bb") + .unwrap(); + let result = CasperPublicKey::from_bytes(&bytes); + assert!( + result.is_ok(), + "Secp256k1 public key should be parsed correctly" + ); + } + + #[test] + fn test_casper_unrecognized_prefix() { + // Using a 99 prefix which is not recognized. + let bytes = + hex::decode("99c377281132044bd3278b039925eeb3efdb9d99dd5f46d9ec6a764add34581af7") + .unwrap(); + let result = CasperPublicKey::from_bytes(&bytes); + assert!( + result.is_err(), + "Unrecognized prefix should result in an error" + ); + } +} diff --git a/kairos-cli/src/crypto/signer.rs b/kairos-cli/src/crypto/signer.rs new file mode 100644 index 00000000..7ce62e5f --- /dev/null +++ b/kairos-cli/src/crypto/signer.rs @@ -0,0 +1,38 @@ +use std::path::Path; + +use super::private_key::CasperPrivateKey; +use super::public_key::CasperPublicKey; +use crate::crypto::error::CryptoError; +use casper_types::bytesrepr::ToBytes; +use casper_types::{crypto, ErrorExt, PublicKey}; + +pub struct CasperSigner { + secret_key: CasperPrivateKey, + pub public_key: CasperPublicKey, +} + +#[allow(unused)] +impl CasperSigner { + pub fn from_file>(file_path: P) -> Result { + let secret_key = CasperPrivateKey::from_file(file_path)?; + + // Derive the public key. + let public_key = CasperPublicKey(PublicKey::from(&secret_key.0)); + + Ok(CasperSigner { + secret_key, + public_key, + }) + } + + pub fn sign_message(&self, message: &[u8]) -> Result, CryptoError> { + let signature = crypto::sign(message, &self.secret_key.0, &self.public_key.0); + let bytes = signature + .to_bytes() + .map_err(|_e| CryptoError::Serialization { + context: "signature", + })?; + + Ok(bytes) + } +} diff --git a/kairos-cli/src/error.rs b/kairos-cli/src/error.rs new file mode 100644 index 00000000..9338ee2b --- /dev/null +++ b/kairos-cli/src/error.rs @@ -0,0 +1,20 @@ +use hex::FromHexError; +use thiserror::Error; + +use crate::crypto::error::CryptoError; + +#[derive(Error, Debug)] +pub enum CliError { + /// Cryptography error. + #[error("cryptography error: {error}")] + CryptoError { + #[from] + error: CryptoError, + }, + /// Failed to parse hex string. + #[error("failed to parse hex string: {error}")] + ParseError { + #[from] + error: FromHexError, + }, +} diff --git a/kairos-cli/src/lib.rs b/kairos-cli/src/lib.rs new file mode 100644 index 00000000..86f168d4 --- /dev/null +++ b/kairos-cli/src/lib.rs @@ -0,0 +1,5 @@ +pub mod commands; +pub mod common; +pub mod crypto; +pub mod error; +pub mod utils; diff --git a/kairos-cli/src/utils.rs b/kairos-cli/src/utils.rs new file mode 100644 index 00000000..07c23c11 --- /dev/null +++ b/kairos-cli/src/utils.rs @@ -0,0 +1,6 @@ +use crate::error::CliError; + +/// Custom parser function to convert a hexadecimal string to a byte array. +pub fn parse_hex_string(s: &str) -> Result, CliError> { + hex::decode(s).map_err(|e| e.into()) +} diff --git a/kairos-cli/tests/cli_tests.rs b/kairos-cli/tests/cli_tests.rs new file mode 100644 index 00000000..2893ba7d --- /dev/null +++ b/kairos-cli/tests/cli_tests.rs @@ -0,0 +1,113 @@ +use assert_cmd::Command; +use std::path::PathBuf; + +// Helper function to get the path to a fixture file +fn fixture_path(relative_path: &str) -> PathBuf { + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.extend(["tests", "fixtures", relative_path].iter()); + path +} + +#[test] +fn deposit_successful_with_ed25519() { + let secret_key_path = fixture_path("ed25519/secret_key.pem"); + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("deposit") + .arg("--amount") + .arg("123") + .arg("--private-key") + .arg(secret_key_path); + cmd.assert().success().stdout("ok\n"); +} + +#[test] +fn transfer_successful_with_secp256k1() { + let secret_key_path = fixture_path("secp256k1/secret_key.pem"); + let recipient = "01a26419a7d82b2263deaedea32d35eee8ae1c850bd477f62a82939f06e80df356"; // Example recipient + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("transfer") + .arg("--recipient") + .arg(recipient) + .arg("--amount") + .arg("123") + .arg("--private-key") + .arg(secret_key_path); + cmd.assert().success().stdout("ok\n"); +} + +#[test] +fn withdraw_successful_with_ed25519() { + let secret_key_path = fixture_path("ed25519/secret_key.pem"); + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("withdraw") + .arg("--amount") + .arg("123") + .arg("--private-key") + .arg(secret_key_path); + cmd.assert().success().stdout("ok\n"); +} + +#[test] +fn deposit_invalid_amount() { + let secret_key_path = fixture_path("ed25519/secret_key.pem"); + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("deposit") + .arg("--amount") + .arg("foo") // Invalid amount + .arg("--private-key") + .arg(secret_key_path); + cmd.assert() + .failure() + .stderr(predicates::str::contains("invalid value")); +} + +#[test] +fn deposit_invalid_private_key_path() { + let secret_key_path = fixture_path("ed25519/non_existing.pem"); // Non-existing path + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("deposit") + .arg("--amount") + .arg("123") + .arg("--private-key") + .arg(secret_key_path); + cmd.assert() + .failure() + .stderr(predicates::str::contains("failed to parse private key")); +} + +#[test] +fn deposit_invalid_private_key_content() { + let secret_key_path = fixture_path("invalid.pem"); // Invalid content + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("deposit") + .arg("--amount") + .arg("123") + .arg("--private-key") + .arg(secret_key_path); + cmd.assert() + .failure() + .stderr(predicates::str::contains("failed to parse private key")); +} + +#[test] +fn transfer_invalid_recipient() { + let secret_key_path = fixture_path("ed25519/secret_key.pem"); + + let mut cmd = Command::cargo_bin("kairos-cli").unwrap(); + cmd.arg("transfer") + .arg("--recipient") + .arg("foo") // Invalid recipient format + .arg("--amount") + .arg("123") + .arg("--private-key") + .arg(secret_key_path); + cmd.assert() + .failure() + .stderr(predicates::str::contains("failed to parse hex string")); +} diff --git a/kairos-cli/tests/fixtures/ed25519/public_key.pem b/kairos-cli/tests/fixtures/ed25519/public_key.pem new file mode 100644 index 00000000..0fabc70e --- /dev/null +++ b/kairos-cli/tests/fixtures/ed25519/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEA/nhOuK9V0WBgXegPtMgJXxzzrr9Cr6VXAyRVA4s9HOY= +-----END PUBLIC KEY----- diff --git a/kairos-cli/tests/fixtures/ed25519/secret_key.pem b/kairos-cli/tests/fixtures/ed25519/secret_key.pem new file mode 100644 index 00000000..c8b5e128 --- /dev/null +++ b/kairos-cli/tests/fixtures/ed25519/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEINGZqbfpO+UnBomOhxW0Y+ynRuDPpD4354zEYVPM3hpz +-----END PRIVATE KEY----- diff --git a/kairos-cli/tests/fixtures/invalid.pem b/kairos-cli/tests/fixtures/invalid.pem new file mode 100644 index 00000000..f9129d7a --- /dev/null +++ b/kairos-cli/tests/fixtures/invalid.pem @@ -0,0 +1 @@ +Ooops! diff --git a/kairos-cli/tests/fixtures/secp256k1/public_key.pem b/kairos-cli/tests/fixtures/secp256k1/public_key.pem new file mode 100644 index 00000000..9052f23d --- /dev/null +++ b/kairos-cli/tests/fixtures/secp256k1/public_key.pem @@ -0,0 +1,4 @@ +-----BEGIN PUBLIC KEY----- +MDYwEAYHKoZIzj0CAQYFK4EEAAoDIgADnu3WpM+rtgFyMjU9/M5Pi6npWn6zEtRy +ZnyS1LP24Ys= +-----END PUBLIC KEY----- diff --git a/kairos-cli/tests/fixtures/secp256k1/secret_key.pem b/kairos-cli/tests/fixtures/secp256k1/secret_key.pem new file mode 100644 index 00000000..24036c2c --- /dev/null +++ b/kairos-cli/tests/fixtures/secp256k1/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN EC PRIVATE KEY----- +MC4CAQEEIKJ1twPHznYeFtbkBygA8rLf9Y3rQJ9mlSQz1WxErM5UoAcGBSuBBAAK +-----END EC PRIVATE KEY-----