Skip to content

Commit 4a06d2f

Browse files
authored
fix: load private keys when loading a user identity (#12)
1 parent 7b175c8 commit 4a06d2f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/platform/identity/load_identity.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use crate::context::AppContext;
22
use crate::model::qualified_identity::EncryptedPrivateKeyTarget::{
3-
PrivateKeyOnMainIdentity, PrivateKeyOnVoterIdentity,
3+
self, PrivateKeyOnMainIdentity, PrivateKeyOnVoterIdentity,
44
};
55
use crate::model::qualified_identity::{IdentityType, QualifiedIdentity};
66
use crate::platform::identity::{verify_key_input, IdentityInputToLoad};
77
use dash_sdk::dashcore_rpc::dashcore::key::Secp256k1;
88
use dash_sdk::dashcore_rpc::dashcore::PrivateKey;
99
use dash_sdk::dpp::identifier::MasternodeIdentifiers;
10+
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
1011
use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
1112
use dash_sdk::dpp::platform_value::string_encoding::Encoding;
1213
use dash_sdk::platform::{Fetch, Identifier, Identity};
@@ -26,7 +27,7 @@ impl AppContext {
2627
alias_input,
2728
owner_private_key_input,
2829
payout_address_private_key_input,
29-
keys_input: _,
30+
keys_input,
3031
} = input;
3132

3233
// Verify the voting private key
@@ -114,6 +115,29 @@ impl AppContext {
114115
None
115116
};
116117

118+
if identity_type == IdentityType::User {
119+
for (i, private_key_input) in keys_input.into_iter().enumerate() {
120+
let key_id = i as u32;
121+
let public_key = match identity.public_keys().get(&key_id) {
122+
Some(key) => key,
123+
None => return Err("No public key matching key id {key_id}".to_string()),
124+
};
125+
let private_key_bytes = match verify_key_input(
126+
private_key_input,
127+
&public_key.key_type().to_string(),
128+
)? {
129+
Some(bytes) => bytes,
130+
None => {
131+
return Err("Private key input length is 0 for key id {key_id}".to_string())
132+
}
133+
};
134+
encrypted_private_keys.insert(
135+
(EncryptedPrivateKeyTarget::PrivateKeyOnMainIdentity, key_id),
136+
(public_key.clone(), private_key_bytes),
137+
);
138+
}
139+
}
140+
117141
let qualified_identity = QualifiedIdentity {
118142
identity,
119143
associated_voter_identity,

src/ui/identities/add_existing_identity_screen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl AddExistingIdentityScreen {
159159
// For User, show multiple key inputs
160160
for (i, key) in self.keys_input.iter_mut().enumerate() {
161161
ui.horizontal(|ui| {
162-
ui.label(format!("Key {}:", i + 1));
162+
ui.label(format!("Private Key {} (Hex or WIF):", i + 1));
163163
ui.text_edit_singleline(key);
164164
if ui.button("-").clicked() {
165165
keys_to_remove.push(i);

0 commit comments

Comments
 (0)