From 5bfad030c6ce0e4eaf1de983f02b7f9baa11fca6 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 13 Aug 2024 11:27:46 +0700 Subject: [PATCH 1/3] feat: log private keys of new identities in strategy tests --- packages/strategy-tests/src/transitions.rs | 34 +++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index b35cfd38d8..f317075440 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -16,6 +16,7 @@ use dpp::identity::KeyType::ECDSA_SECP256K1; use dpp::identity::Purpose::{AUTHENTICATION, TRANSFER}; use dpp::identity::SecurityLevel::{CRITICAL, MASTER}; use dpp::identity::{Identity, IdentityPublicKey, KeyID, KeyType, Purpose, SecurityLevel}; +use dpp::platform_value::string_encoding::Encoding; use dpp::prelude::AssetLockProof; use dpp::state_transition::identity_create_transition::methods::IdentityCreateTransitionMethodsV0; use dpp::state_transition::identity_create_transition::IdentityCreateTransition; @@ -656,8 +657,8 @@ pub fn create_identities_state_transitions( .max() .map_or(0, |max_key| max_key.id() + 1); + // Add extra keys for (i, identity) in identities.iter_mut().enumerate() { - // TODO: deal with the case where there's more than one extra key for (_, (purpose, security_to_key_type_map)) in extra_keys.iter().enumerate() { for (security_level, key_types) in security_to_key_type_map { for key_type in key_types { @@ -671,8 +672,10 @@ pub fn create_identities_state_transitions( platform_version, )?; identity.add_public_key(key.clone()); - let key_num = key_count as usize * (i + 1) + i; - keys.insert(key_num, (key, private_key)) + let key_num = i * (key_count as usize + extra_keys.len()) + + identity.public_keys().len() + - 1; + keys.insert(key_num, (key, private_key)); } } } @@ -683,20 +686,18 @@ pub fn create_identities_state_transitions( for (key, _) in &mut keys { let IdentityPublicKey::V0(ref mut id_pub_key_v0) = key; id_pub_key_v0.set_id(current_id_num); - current_id_num += 1; // Increment for each key + current_id_num += 1; } - signer.add_keys(keys); + signer.add_keys(keys.clone()); // Generate state transitions for each identity identities .into_iter() .enumerate() .map(|(index, mut identity)| { - // Calculate the starting KeyID for this identity let identity_starting_id = starting_id_num + index as u32 * (key_count + extra_keys.len() as u32); - // Update the identity with the new KeyIDs let public_keys_map = identity.public_keys_mut(); public_keys_map .values_mut() @@ -721,6 +722,25 @@ pub fn create_identities_state_transitions( ) { Ok(identity_create_transition) => { identity.set_id(identity_create_transition.owner_id()); + + // Log public and private keys here + let identity_id = identity.id().to_string(Encoding::Base58); + for (key_index, public_key) in identity.public_keys().iter().enumerate() { + let key_num = index * (key_count as usize + extra_keys.len()) + key_index; + let private_key_wif = + PrivateKey::from_slice(&keys[*&key_num].1, Network::Testnet) + .unwrap() + .to_wif(); + + tracing::info!( + "Identity ID: {:?} Public key ID: {:?} Public key: {:?} Private key: {:?}", + identity_id, + public_key.1.id(), + public_key, + private_key_wif + ); + } + Ok((identity, identity_create_transition)) } Err(e) => Err(e), From 51baef1929743b04a700c3c239d2dae2c3c63d07 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Thu, 29 Aug 2024 19:05:16 +0700 Subject: [PATCH 2/3] fix: dash network private key --- packages/strategy-tests/src/transitions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index f317075440..d0aa54cddb 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -728,7 +728,7 @@ pub fn create_identities_state_transitions( for (key_index, public_key) in identity.public_keys().iter().enumerate() { let key_num = index * (key_count as usize + extra_keys.len()) + key_index; let private_key_wif = - PrivateKey::from_slice(&keys[*&key_num].1, Network::Testnet) + PrivateKey::from_slice(&keys[*&key_num].1, Network::Dash) .unwrap() .to_wif(); From d011329cee6bbad685682adc235ad29fc5321ab4 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Thu, 12 Sep 2024 10:13:15 +0700 Subject: [PATCH 3/3] revert change --- packages/strategy-tests/src/transitions.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index d0aa54cddb..b2dc25f90f 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -672,10 +672,8 @@ pub fn create_identities_state_transitions( platform_version, )?; identity.add_public_key(key.clone()); - let key_num = i * (key_count as usize + extra_keys.len()) - + identity.public_keys().len() - - 1; - keys.insert(key_num, (key, private_key)); + let key_num = key_count as usize * (i + 1) + i; + keys.insert(key_num, (key, private_key)) } } } @@ -723,7 +721,7 @@ pub fn create_identities_state_transitions( Ok(identity_create_transition) => { identity.set_id(identity_create_transition.owner_id()); - // Log public and private keys here + // Log public and private keys let identity_id = identity.id().to_string(Encoding::Base58); for (key_index, public_key) in identity.public_keys().iter().enumerate() { let key_num = index * (key_count as usize + extra_keys.len()) + key_index;