Merge pull request #8 from ZcashFoundation/add_split_362

Add split function
This commit is contained in:
natalie 2023-06-05 19:33:10 +01:00 committed by GitHub
commit ac921c364d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 268 additions and 108 deletions

167
Cargo.lock generated
View File

@ -57,9 +57,9 @@ dependencies = [
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.12.1" version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -87,9 +87,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "ciborium" name = "ciborium"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926"
dependencies = [ dependencies = [
"ciborium-io", "ciborium-io",
"ciborium-ll", "ciborium-ll",
@ -98,15 +98,15 @@ dependencies = [
[[package]] [[package]]
name = "ciborium-io" name = "ciborium-io"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656"
[[package]] [[package]]
name = "ciborium-ll" name = "ciborium-ll"
version = "0.2.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b"
dependencies = [ dependencies = [
"ciborium-io", "ciborium-io",
"half", "half",
@ -114,9 +114,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.2.23" version = "3.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"clap_lex", "clap_lex",
@ -255,9 +255,9 @@ checksum = "f400d0750c0c069e8493f2256cb4da6f604b6d2eeb69a0ca8863acde352f8400"
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.6" version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"crypto-common", "crypto-common",
@ -319,9 +319,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]] [[package]]
name = "frost-core" name = "frost-core"
version = "0.2.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05b1dfe39cf39c73c9d2b5f3cac4c482984028ccf5235f455b8c984d977c71a0" checksum = "e2329106b2265939420de478389a83ffd63a76ec86b306c6d78ea345a5efced3"
dependencies = [ dependencies = [
"byteorder", "byteorder",
"criterion", "criterion",
@ -339,9 +339,9 @@ dependencies = [
[[package]] [[package]]
name = "frost-ed25519" name = "frost-ed25519"
version = "0.2.0" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c190b586c268a320b683a6b57aa4b1a73176d85ecd69b0dbcb2e2786a034c8d3" checksum = "b749ea831d8e9205f6c8d912d5656c5d320b0bb1489b4b6fdd715941a1e8dd1a"
dependencies = [ dependencies = [
"curve25519-dalek", "curve25519-dalek",
"frost-core", "frost-core",
@ -474,9 +474,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.61" version = "0.3.63"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790"
dependencies = [ dependencies = [
"wasm-bindgen", "wasm-bindgen",
] ]
@ -489,9 +489,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.142" version = "0.2.144"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
[[package]] [[package]]
name = "libm" name = "libm"
@ -501,15 +501,15 @@ checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a"
[[package]] [[package]]
name = "libm" name = "libm"
version = "0.2.6" version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4"
[[package]] [[package]]
name = "linux-raw-sys" name = "linux-raw-sys"
version = "0.3.4" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519"
[[package]] [[package]]
name = "log" name = "log"
@ -536,7 +536,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm 0.2.6", "libm 0.2.7",
] ]
[[package]] [[package]]
@ -628,25 +628,24 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.56" version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" checksum = "fa1fb82fc0c281dd9671101b66b771ebbe1eaf967b96ac8740dcba4b70005ca8"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "proptest" name = "proptest"
version = "1.1.0" version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65"
dependencies = [ dependencies = [
"bit-set", "bit-set",
"bitflags", "bitflags",
"byteorder", "byteorder",
"lazy_static", "lazy_static",
"num-traits", "num-traits",
"quick-error 2.0.1",
"rand", "rand",
"rand_chacha", "rand_chacha",
"rand_xorshift", "rand_xorshift",
@ -673,12 +672,6 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quick-error"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
[[package]] [[package]]
name = "quote" name = "quote"
version = "0.6.13" version = "0.6.13"
@ -690,11 +683,11 @@ dependencies = [
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.26" version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
] ]
[[package]] [[package]]
@ -769,11 +762,11 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.8.1" version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" checksum = "d1a59b5d8e97dee33696bf13c5ba8ab85341c002922fba050069326b9c498974"
dependencies = [ dependencies = [
"regex-syntax 0.7.1", "regex-syntax 0.7.2",
] ]
[[package]] [[package]]
@ -784,15 +777,15 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]] [[package]]
name = "regex-syntax" name = "regex-syntax"
version = "0.7.1" version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.37.14" version = "0.37.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b864d3c18a5785a05953adeed93e2dca37ed30f18e69bba9f30079d51f363f" checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"errno", "errno",
@ -809,7 +802,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f"
dependencies = [ dependencies = [
"fnv", "fnv",
"quick-error 1.2.3", "quick-error",
"tempfile", "tempfile",
"wait-timeout", "wait-timeout",
] ]
@ -837,22 +830,22 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.160" version = "1.0.163"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.160" version = "1.0.163"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -900,19 +893,19 @@ version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"unicode-ident", "unicode-ident",
] ]
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.15" version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"unicode-ident", "unicode-ident",
] ]
@ -950,9 +943,9 @@ version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"syn 2.0.15", "syn 2.0.16",
] ]
[[package]] [[package]]
@ -1001,8 +994,8 @@ version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8881d5cc0ae34e3db2f1de5af81e5117a420d2f937506c2dc20d6f4cfb069051" checksum = "8881d5cc0ae34e3db2f1de5af81e5117a420d2f937506c2dc20d6f4cfb069051"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"syn 1.0.109", "syn 1.0.109",
] ]
@ -1033,9 +1026,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]] [[package]]
name = "wasm-bindgen" name = "wasm-bindgen"
version = "0.2.84" version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"wasm-bindgen-macro", "wasm-bindgen-macro",
@ -1043,53 +1036,53 @@ dependencies = [
[[package]] [[package]]
name = "wasm-bindgen-backend" name = "wasm-bindgen-backend"
version = "0.2.84" version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"log", "log",
"once_cell", "once_cell",
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"syn 1.0.109", "syn 2.0.16",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-macro" name = "wasm-bindgen-macro"
version = "0.2.84" version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258"
dependencies = [ dependencies = [
"quote 1.0.26", "quote 1.0.27",
"wasm-bindgen-macro-support", "wasm-bindgen-macro-support",
] ]
[[package]] [[package]]
name = "wasm-bindgen-macro-support" name = "wasm-bindgen-macro-support"
version = "0.2.84" version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"syn 1.0.109", "syn 2.0.16",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
[[package]] [[package]]
name = "wasm-bindgen-shared" name = "wasm-bindgen-shared"
version = "0.2.84" version = "0.2.86"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93"
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.61" version = "0.3.63"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2"
dependencies = [ dependencies = [
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
@ -1273,7 +1266,7 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
dependencies = [ dependencies = [
"proc-macro2 1.0.56", "proc-macro2 1.0.58",
"quote 1.0.26", "quote 1.0.27",
"syn 2.0.15", "syn 2.0.16",
] ]

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
frost-ed25519 = "0.2.0" frost-ed25519 = "0.3.0"
thiserror = "1.0" thiserror = "1.0"
rand = "0.8" rand = "0.8"
hex = "0.4" hex = "0.4"

View File

@ -92,4 +92,4 @@ NOTE: A signer is a participant that generates a signing share which is aggregat
Test coverage checks are performed in the pipeline. This is configured here: `.github/workflows/coverage.yaml` Test coverage checks are performed in the pipeline. This is configured here: `.github/workflows/coverage.yaml`
To run these locally: To run these locally:
1. Install coverage tool by running `cargo install cargo-llvm-cov` 1. Install coverage tool by running `cargo install cargo-llvm-cov`
2. Run `cargo cov` (you may be asked if you want to install `llvm-tools-preview`, if so type `Y`) 2. Run `cargo make cov` (you may be asked if you want to install `llvm-tools-preview`, if so type `Y`)

View File

@ -1,10 +1,12 @@
use frost_ed25519::Error; use frost::Error;
use frost_ed25519 as frost;
use std::io::BufRead; use std::io::BufRead;
#[derive(Debug, PartialEq, Copy, Clone)] #[derive(Debug, PartialEq, Clone)]
pub struct Config { pub struct Config {
pub min_signers: u16, pub min_signers: u16,
pub max_signers: u16, pub max_signers: u16,
pub secret: Vec<u8>, // todo
} }
pub fn validate_inputs(config: &Config) -> Result<(), Error> { pub fn validate_inputs(config: &Config) -> Result<(), Error> {
@ -43,8 +45,17 @@ pub fn request_inputs(input: &mut impl BufRead) -> Result<Config, Error> {
.parse::<u16>() .parse::<u16>()
.map_err(|_| Error::InvalidMaxSigners)?; .map_err(|_| Error::InvalidMaxSigners)?;
Ok(Config { println!("Secret key (press enter to randomly generate a fresh one): ");
let mut secret_input = String::new();
input.read_line(&mut secret_input).unwrap();
let secret = hex::decode(secret_input.trim()).map_err(|_| Error::MalformedSigningKey)?;
let config = Config {
min_signers, min_signers,
max_signers, max_signers,
}) secret,
};
Ok(config)
} }

View File

@ -7,6 +7,7 @@ use std::io;
use output::{print_values, Logger}; use output::{print_values, Logger};
use rand::thread_rng; use rand::thread_rng;
use trusted_dealer_keygen::split_secret;
mod output; mod output;
use crate::inputs::{request_inputs, validate_inputs}; use crate::inputs::{request_inputs, validate_inputs};
@ -30,14 +31,19 @@ fn main() -> io::Result<()> {
std::process::exit(exitcode::DATAERR) std::process::exit(exitcode::DATAERR)
} }
let keygen = if config.secret.is_empty() {
trusted_dealer_keygen(&config, &mut rng)
} else {
split_secret(&config, &mut rng)
};
// Print outputs // Print outputs
let out = trusted_dealer_keygen(config, &mut rng); if let Err(e) = keygen {
if let Err(e) = out {
eprintln!("Error: {}", e); eprintln!("Error: {}", e);
std::process::exit(1) std::process::exit(1)
} }
let (key_packages, pubkeys) = out.unwrap(); let (key_packages, pubkeys) = keygen.unwrap();
let mut console_logger = ConsoleLogger::default(); let mut console_logger = ConsoleLogger::default();

View File

@ -5,6 +5,7 @@ fn check_valid_input_for_signers() {
let config = Config { let config = Config {
min_signers: 2, min_signers: 2,
max_signers: 3, max_signers: 3,
secret: Vec::new(),
}; };
let expected = validate_inputs(&config); let expected = validate_inputs(&config);
@ -17,6 +18,7 @@ fn return_error_if_min_participant_greater_than_max_participant() {
let config = Config { let config = Config {
min_signers: 4, min_signers: 4,
max_signers: 3, max_signers: 3,
secret: Vec::new(),
}; };
let expected = validate_inputs(&config); let expected = validate_inputs(&config);
@ -29,6 +31,7 @@ fn return_error_if_min_participant_is_less_than_2() {
let config = Config { let config = Config {
min_signers: 1, min_signers: 1,
max_signers: 3, max_signers: 3,
secret: Vec::new(),
}; };
let expected = validate_inputs(&config); let expected = validate_inputs(&config);
@ -41,6 +44,7 @@ fn return_error_if_max_participant_is_less_than_2() {
let config = Config { let config = Config {
min_signers: 2, min_signers: 2,
max_signers: 1, max_signers: 1,
secret: Vec::new(),
}; };
let expected = validate_inputs(&config); let expected = validate_inputs(&config);
@ -48,13 +52,22 @@ fn return_error_if_max_participant_is_less_than_2() {
assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)); assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners));
} }
// Testing inclusion of secret input
#[test] #[test]
fn return_config_if_valid_input() { fn check_valid_input_with_secret() {
let mut valid_input = "3\n6\n".as_bytes(); let mut valid_input =
"3\n6\n7b1c33d3f5291d85de664833beb1ad469f7fb6025a0ec78b3a790c6e13a98304\n".as_bytes();
let config = request_inputs(&mut valid_input).unwrap(); let config = request_inputs(&mut valid_input).unwrap();
let secret: Vec<u8> = vec![
123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2,
90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4,
];
let expected = Config { let expected = Config {
min_signers: 3, min_signers: 3,
max_signers: 6, max_signers: 6,
secret,
}; };
assert_eq!(expected, config) assert_eq!(expected, config)
@ -62,7 +75,7 @@ fn return_config_if_valid_input() {
#[test] #[test]
fn return_error_if_invalid_min_signers_input() { fn return_error_if_invalid_min_signers_input() {
let mut invalid_input = "hello\n6\n".as_bytes(); let mut invalid_input = "hello\n6\n\n".as_bytes();
let expected = request_inputs(&mut invalid_input); let expected = request_inputs(&mut invalid_input);
assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners)) assert_eq!(expected, Err(frost_ed25519::Error::InvalidMinSigners))
@ -70,8 +83,16 @@ fn return_error_if_invalid_min_signers_input() {
#[test] #[test]
fn return_error_if_invalid_max_signers_input() { fn return_error_if_invalid_max_signers_input() {
let mut invalid_input = "4\nworld\n".as_bytes(); let mut invalid_input = "4\nworld\n\n".as_bytes();
let expected = request_inputs(&mut invalid_input); let expected = request_inputs(&mut invalid_input);
assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners)) assert_eq!(expected, Err(frost_ed25519::Error::InvalidMaxSigners))
} }
#[test]
fn return_error_if_secret_is_invalid() {
let mut secret_input = "4\n6\nasecret\n".as_bytes();
let expected = request_inputs(&mut secret_input);
assert_eq!(expected, Err(frost_ed25519::Error::MalformedSigningKey))
}

View File

@ -1,4 +1,5 @@
use crate::inputs::Config; use crate::inputs::Config;
use crate::trusted_dealer_keygen::split_secret;
use frost_ed25519 as frost; use frost_ed25519 as frost;
use rand::thread_rng; use rand::thread_rng;
@ -6,13 +7,14 @@ use crate::trusted_dealer_keygen::trusted_dealer_keygen;
mod signature_gen; mod signature_gen;
#[test] #[test]
fn check_keygen() { fn check_keygen_with_dealer() {
let mut rng = thread_rng(); let mut rng = thread_rng();
let config = Config { let config = Config {
min_signers: 2, min_signers: 2,
max_signers: 3, max_signers: 3,
secret: Vec::new(),
}; };
let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng).unwrap(); let (key_packages, pubkeys) = trusted_dealer_keygen(&config, &mut rng).unwrap();
let (nonces, commitments) = let (nonces, commitments) =
signature_gen::generate_nonces_and_commitments(config.min_signers, &key_packages, &mut rng); signature_gen::generate_nonces_and_commitments(config.min_signers, &key_packages, &mut rng);
let message = "message to sign".as_bytes(); let message = "message to sign".as_bytes();
@ -26,3 +28,33 @@ fn check_keygen() {
assert!(verify_signature.is_ok()); assert!(verify_signature.is_ok());
} }
#[test]
fn check_keygen_with_dealer_with_secret() {
let mut rng = thread_rng();
let secret: Vec<u8> = vec![
123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2,
90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4,
];
let secret_config = Config {
min_signers: 2,
max_signers: 3,
secret,
};
let (key_packages, pubkeys) = split_secret(&secret_config, &mut rng).unwrap();
let (nonces, commitments) = signature_gen::generate_nonces_and_commitments(
secret_config.min_signers,
&key_packages,
&mut rng,
);
let message = "message to sign".as_bytes();
let comms = commitments.into_values().collect();
let signing_package = frost::SigningPackage::new(comms, message.to_vec());
let signature_shares =
signature_gen::generate_signature_shares(nonces, &key_packages, &signing_package);
let group_signature =
frost::aggregate(&signing_package, &signature_shares[..], &pubkeys).unwrap();
let verify_signature = pubkeys.group_public.verify(message, &group_signature);
assert!(verify_signature.is_ok());
}

View File

@ -4,7 +4,7 @@ use rand::thread_rng;
use crate::inputs::Config; use crate::inputs::Config;
use crate::output::{print_values, Logger}; use crate::output::{print_values, Logger};
use crate::trusted_dealer_keygen; use crate::trusted_dealer_keygen::{split_secret, trusted_dealer_keygen};
struct TestLogger(Vec<String>); struct TestLogger(Vec<String>);
@ -15,14 +15,93 @@ impl Logger for TestLogger {
} }
#[test] #[test]
fn check_output() { fn check_output_without_secret() {
let mut test_logger = TestLogger(Vec::new()); let mut test_logger = TestLogger(Vec::new());
let mut rng = thread_rng(); let mut rng = thread_rng();
let config = Config { let config = Config {
min_signers: 2, min_signers: 2,
max_signers: 3, max_signers: 3,
secret: Vec::new(),
}; };
let (key_packages, pubkeys) = trusted_dealer_keygen(config, &mut rng).unwrap(); let (key_packages, pubkeys) = trusted_dealer_keygen(&config, &mut rng).unwrap();
print_values(&key_packages, pubkeys, &mut test_logger);
let signer_1 = Identifier::try_from(1).unwrap();
let signer_2 = Identifier::try_from(2).unwrap();
let signer_3 = Identifier::try_from(3).unwrap();
assert_eq!(
test_logger.0[0],
format!(
"Group public key: \"{}\"",
hex::encode(key_packages[&signer_1].group_public.to_bytes())
)
);
assert_eq!(test_logger.0[1], format!("Participant {:?}", signer_1));
assert_eq!(
test_logger.0[2],
format!(
"Secret share: \"{}\"",
hex::encode(key_packages[&signer_1].secret_share.to_bytes())
)
);
assert_eq!(
test_logger.0[3],
format!(
"Public key: \"{}\"",
hex::encode(key_packages[&signer_1].public.to_bytes())
)
);
assert_eq!(test_logger.0[4], format!("Participant {:?}", signer_2));
assert_eq!(
test_logger.0[5],
format!(
"Secret share: \"{}\"",
hex::encode(key_packages[&signer_2].secret_share.to_bytes())
)
);
assert_eq!(
test_logger.0[6],
format!(
"Public key: \"{}\"",
hex::encode(key_packages[&signer_2].public.to_bytes())
)
);
assert_eq!(test_logger.0[7], format!("Participant {:?}", signer_3));
assert_eq!(
test_logger.0[8],
format!(
"Secret share: \"{}\"",
hex::encode(key_packages[&signer_3].secret_share.to_bytes())
)
);
assert_eq!(
test_logger.0[9],
format!(
"Public key: \"{}\"",
hex::encode(key_packages[&signer_3].public.to_bytes())
)
);
}
#[test]
fn check_output_with_secret() {
let mut test_logger = TestLogger(Vec::new());
let mut rng = thread_rng();
let secret: Vec<u8> = vec![
123, 28, 51, 211, 245, 41, 29, 133, 222, 102, 72, 51, 190, 177, 173, 70, 159, 127, 182, 2,
90, 14, 199, 139, 58, 121, 12, 110, 19, 169, 131, 4,
];
let config = Config {
min_signers: 2,
max_signers: 3,
secret,
};
let (key_packages, pubkeys) = split_secret(&config, &mut rng).unwrap();
print_values(&key_packages, pubkeys, &mut test_logger); print_values(&key_packages, pubkeys, &mut test_logger);

View File

@ -1,5 +1,5 @@
use frost::keys::{KeyPackage, PublicKeyPackage}; use frost::keys::{KeyPackage, PublicKeyPackage};
use frost::{Error, Identifier}; use frost::{Error, Identifier, SigningKey};
use frost_ed25519 as frost; use frost_ed25519 as frost;
use rand::rngs::ThreadRng; use rand::rngs::ThreadRng;
use std::collections::HashMap; use std::collections::HashMap;
@ -7,11 +7,11 @@ use std::collections::HashMap;
use crate::inputs::Config; use crate::inputs::Config;
pub fn trusted_dealer_keygen( pub fn trusted_dealer_keygen(
config: Config, config: &Config,
rng: &mut ThreadRng, rng: &mut ThreadRng,
) -> Result<(HashMap<Identifier, KeyPackage>, PublicKeyPackage), Error> { ) -> Result<(HashMap<Identifier, KeyPackage>, PublicKeyPackage), Error> {
let (shares, pubkeys) = let (shares, pubkeys) =
frost::keys::keygen_with_dealer(config.max_signers, config.min_signers, rng)?; frost::keys::generate_with_dealer(config.max_signers, config.min_signers, rng)?;
let mut key_packages: HashMap<_, _> = HashMap::new(); let mut key_packages: HashMap<_, _> = HashMap::new();
@ -22,3 +22,21 @@ pub fn trusted_dealer_keygen(
Ok((key_packages, pubkeys)) Ok((key_packages, pubkeys))
} }
pub fn split_secret(
config: &Config,
rng: &mut ThreadRng,
) -> Result<(HashMap<Identifier, KeyPackage>, PublicKeyPackage), Error> {
let sec = config.secret.clone();
let again = sec.try_into().unwrap();
let secret_key = SigningKey::from_bytes(again)?;
let (shares, pubkeys) =
frost::keys::split(&secret_key, config.max_signers, config.min_signers, rng)?;
let mut key_packages: HashMap<_, _> = HashMap::new();
for (k, v) in shares {
let key_package = frost::keys::KeyPackage::try_from(v)?;
key_packages.insert(k, key_package);
}
Ok((key_packages, pubkeys))
}