1- use super :: RegisterValidatorMessage ;
1+ use std:: collections:: BTreeMap ;
2+
3+ use super :: { CandidateKeyParam , RegisterValidatorMessage } ;
24use crate :: config:: KEYS_FILE_PATH ;
35use crate :: io:: IOContext ;
46use crate :: keystore:: { CROSS_CHAIN , keystore_path} ;
@@ -10,9 +12,9 @@ use partner_chains_cardano_offchain::csl::NetworkTypeExt;
1012use select_utxo:: { query_utxos, select_from_utxos} ;
1113use serde:: de:: DeserializeOwned ;
1214use serde:: { Deserialize , Serialize } ;
15+ use sidechain_domain:: byte_string:: ByteString ;
1316use sidechain_domain:: crypto:: sc_public_key_and_signature_for_datum;
1417use sidechain_domain:: { NetworkType , SidechainPublicKey , UtxoId } ;
15- use sp_core:: bytes:: from_hex;
1618use sp_core:: { Pair , ecdsa} ;
1719
1820#[ derive( Clone , Debug , clap:: Parser ) ]
@@ -26,7 +28,7 @@ impl CmdRun for Register1Cmd {
2628 let node_data_base_path =
2729 config_fields:: SUBSTRATE_NODE_DATA_BASE_PATH . load_or_prompt_and_save ( context) ;
2830
29- let GeneratedKeysFileContent { sidechain_pub_key : pc_pub_key , aura_pub_key , grandpa_pub_key } =
31+ let GeneratedKeysFileContent { partner_chains_key , keys } =
3032 read_generated_keys ( context) . map_err ( |e| {
3133 context. eprint ( & format ! ( "⚠️ The keys file `{KEYS_FILE_PATH}` is missing or invalid. Please run the `generate-keys` command first" ) ) ;
3234 anyhow ! ( e)
@@ -54,33 +56,43 @@ impl CmdRun for Register1Cmd {
5456 ) ;
5557 context. print ( "" ) ;
5658
57- let pc_pub_key_typed: SidechainPublicKey =
58- SidechainPublicKey ( from_hex ( & pc_pub_key) . map_err ( |e| {
59- context. eprint ( & format ! ( "⚠️ Failed to decode partner-chains public key: {e}" ) ) ;
60- anyhow ! ( e)
61- } ) ?) ;
59+ let pc_pub_key_typed: SidechainPublicKey = SidechainPublicKey ( partner_chains_key. 0 . clone ( ) ) ;
6260
6361 let registration_message = RegisterValidatorMessage {
6462 genesis_utxo,
6563 sidechain_pub_key : pc_pub_key_typed,
6664 registration_utxo,
6765 } ;
6866
69- let ecdsa_pair =
70- get_ecdsa_pair_from_file ( context, & keystore_path ( & node_data_base_path) , & pc_pub_key)
71- . map_err ( |e| {
72- context. eprint ( & format ! (
73- "⚠️ Failed to read partner chain key from the keystore: {e}"
74- ) ) ;
75- anyhow ! ( e)
76- } ) ?;
67+ let ecdsa_pair = get_ecdsa_pair_from_file (
68+ context,
69+ & keystore_path ( & node_data_base_path) ,
70+ & partner_chains_key. to_hex_string ( ) ,
71+ )
72+ . map_err ( |e| {
73+ context. eprint ( & format ! ( "⚠️ Failed to read partner chain key from the keystore: {e}" ) ) ;
74+ anyhow ! ( e)
75+ } ) ?;
76+
77+ let partner_chains_key_str = partner_chains_key. to_hex_string ( ) ;
7778
7879 let pc_signature =
7980 sign_registration_message_with_sidechain_key ( registration_message, ecdsa_pair) ?;
8081 let executable = context. current_executable ( ) ?;
8182 context. print ( "Run the following command to generate signatures on the next step. It has to be executed on the machine with your SPO cold signing key." ) ;
8283 context. print ( "" ) ;
83- context. print ( & format ! ( "{executable} wizards register2 \\ \n --genesis-utxo {genesis_utxo} \\ \n --registration-utxo {registration_utxo} \\ \n --aura-pub-key {aura_pub_key} \\ \n --grandpa-pub-key {grandpa_pub_key} \\ \n --partner-chain-pub-key {pc_pub_key} \\ \n --partner-chain-signature {pc_signature}" ) ) ;
84+ context. print ( & format ! (
85+ "{executable} wizards register2 \\
86+ --genesis-utxo {genesis_utxo} \\
87+ --registration-utxo {registration_utxo} \\
88+ --partner-chain-pub-key {partner_chains_key_str} \\
89+ --partner-chain-signature {pc_signature}{}" ,
90+ keys. iter( )
91+ . map( CandidateKeyParam :: to_string)
92+ . map( |arg| format!( " \\ \n --keys {arg}" ) )
93+ . collect:: <Vec <_>>( )
94+ . join( "" )
95+ ) ) ;
8496
8597 Ok ( ( ) )
8698 }
@@ -111,18 +123,32 @@ fn sign_registration_message_with_sidechain_key(
111123 Ok ( hex:: encode ( sig. serialize_compact ( ) ) )
112124}
113125
114- #[ derive( Serialize , Deserialize , Debug ) ]
126+ #[ derive( Debug ) ]
115127pub struct GeneratedKeysFileContent {
116- pub sidechain_pub_key : String ,
117- pub aura_pub_key : String ,
118- pub grandpa_pub_key : String ,
128+ pub partner_chains_key : ByteString ,
129+ pub keys : Vec < CandidateKeyParam > ,
119130}
120131
121132pub fn read_generated_keys < C : IOContext > ( context : & C ) -> anyhow:: Result < GeneratedKeysFileContent > {
122133 let keys_file_content = context
123134 . read_file ( KEYS_FILE_PATH )
124135 . ok_or_else ( || anyhow:: anyhow!( "failed to read keys file" ) ) ?;
125- Ok ( serde_json:: from_str ( & keys_file_content) ?)
136+
137+ #[ derive( Serialize , Deserialize , Debug ) ]
138+ pub struct GeneratedKeysFileContentRaw {
139+ pub partner_chains_key : ByteString ,
140+ pub keys : BTreeMap < String , ByteString > ,
141+ }
142+
143+ let GeneratedKeysFileContentRaw { partner_chains_key, keys : raw_keys } =
144+ serde_json:: from_str ( & keys_file_content) ?;
145+
146+ let mut keys = vec ! [ ] ;
147+ for ( id, bytes) in raw_keys. into_iter ( ) {
148+ keys. push ( CandidateKeyParam :: try_new_from ( & id, bytes. 0 ) ?)
149+ }
150+
151+ Ok ( GeneratedKeysFileContent { partner_chains_key, keys } )
126152}
127153
128154pub fn load_chain_config_field < C : IOContext , T > (
@@ -411,9 +437,11 @@ mod tests {
411437
412438 fn generated_keys_file_content ( ) -> serde_json:: Value {
413439 serde_json:: json!( {
414- "sidechain_pub_key" : "0x031e75acbf45ef8df98bbe24b19b28fff807be32bf88838c30c0564d7bec5301f6" ,
415- "aura_pub_key" : "0xdf883ee0648f33b6103017b61be702017742d501b8fe73b1d69ca0157460b777" ,
416- "grandpa_pub_key" : "0x5a091a06abd64f245db11d2987b03218c6bd83d64c262fe10e3a2a1230e90327"
440+ "partner_chains_key" : "0x031e75acbf45ef8df98bbe24b19b28fff807be32bf88838c30c0564d7bec5301f6" ,
441+ "keys" : {
442+ "aura" : "0xdf883ee0648f33b6103017b61be702017742d501b8fe73b1d69ca0157460b777" ,
443+ "gran" : "0x5a091a06abd64f245db11d2987b03218c6bd83d64c262fe10e3a2a1230e90327"
444+ }
417445 } )
418446 }
419447
@@ -508,7 +536,13 @@ mod tests {
508536 ) ,
509537 MockIO :: print( "" ) ,
510538 MockIO :: print(
511- "<mock executable> wizards register2 \\ \n --genesis-utxo 0000000000000000000000000000000000000000000000000000000000000001#0 \\ \n --registration-utxo 4704a903b01514645067d851382efd4a6ed5d2ff07cf30a538acc78fed7c4c02#93 \\ \n --aura-pub-key 0xdf883ee0648f33b6103017b61be702017742d501b8fe73b1d69ca0157460b777 \\ \n --grandpa-pub-key 0x5a091a06abd64f245db11d2987b03218c6bd83d64c262fe10e3a2a1230e90327 \\ \n --partner-chain-pub-key 0x031e75acbf45ef8df98bbe24b19b28fff807be32bf88838c30c0564d7bec5301f6 \\ \n --partner-chain-signature 6e295e36a6b11d8b1c5ec01ac8a639b466fbfbdda94b39ea82b0992e303d58543341345fc705e09c7838786ba0bc746d9038036f66a36d1127d924c4a0228bec" ,
539+ "<mock executable> wizards register2 \\
540+ --genesis-utxo 0000000000000000000000000000000000000000000000000000000000000001#0 \\
541+ --registration-utxo 4704a903b01514645067d851382efd4a6ed5d2ff07cf30a538acc78fed7c4c02#93 \\
542+ --partner-chain-pub-key 0x031e75acbf45ef8df98bbe24b19b28fff807be32bf88838c30c0564d7bec5301f6 \\
543+ --partner-chain-signature 6e295e36a6b11d8b1c5ec01ac8a639b466fbfbdda94b39ea82b0992e303d58543341345fc705e09c7838786ba0bc746d9038036f66a36d1127d924c4a0228bec \\
544+ --keys aura:df883ee0648f33b6103017b61be702017742d501b8fe73b1d69ca0157460b777 \\
545+ --keys gran:5a091a06abd64f245db11d2987b03218c6bd83d64c262fe10e3a2a1230e90327" ,
512546 ) ,
513547 ]
514548 }
0 commit comments