Skip to content

Commit 887ea83

Browse files
Merge PR #672: feat(key-wallet): add DIP-13 identity authentication accounts (ECDSA + BLS)
2 parents 2a9359f + ef345d1 commit 887ea83

17 files changed

Lines changed: 1109 additions & 72 deletions

File tree

key-wallet-ffi/src/account.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,20 @@ pub unsafe extern "C" fn wallet_get_account(
8989
}
9090

9191
let wallet = &*wallet;
92-
let account_type_rust = account_type.to_account_type(account_index);
92+
let account_type_rust = match account_type.to_account_type(account_index) {
93+
Ok(t) => t,
94+
Err(mut err) => {
95+
let code = err.code;
96+
let message = if err.message.is_null() {
97+
"Invalid account type".to_string()
98+
} else {
99+
let msg = std::ffi::CStr::from_ptr(err.message).to_string_lossy().to_string();
100+
err.free_message();
101+
msg
102+
};
103+
return FFIAccountResult::error(code, message);
104+
}
105+
};
93106

94107
match wallet.inner().accounts.account_of_type(account_type_rust) {
95108
Some(account) => {

key-wallet-ffi/src/address_pool.rs

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ fn get_managed_account_by_type<'a>(
4545
collection.identity_topup_not_bound.as_ref()
4646
}
4747
AccountType::IdentityInvitation => collection.identity_invitation.as_ref(),
48+
AccountType::IdentityAuthenticationEcdsa {
49+
identity_index,
50+
} => collection.identity_authentication_ecdsa.get(identity_index),
51+
AccountType::IdentityAuthenticationBls {
52+
identity_index,
53+
} => collection.identity_authentication_bls.get(identity_index),
4854
AccountType::AssetLockAddressTopUp => collection.asset_lock_address_topup.as_ref(),
4955
AccountType::AssetLockShieldedAddressTopUp => {
5056
collection.asset_lock_shielded_address_topup.as_ref()
@@ -98,6 +104,12 @@ fn get_managed_account_by_type_mut<'a>(
98104
collection.identity_topup_not_bound.as_mut()
99105
}
100106
AccountType::IdentityInvitation => collection.identity_invitation.as_mut(),
107+
AccountType::IdentityAuthenticationEcdsa {
108+
identity_index,
109+
} => collection.identity_authentication_ecdsa.get_mut(identity_index),
110+
AccountType::IdentityAuthenticationBls {
111+
identity_index,
112+
} => collection.identity_authentication_bls.get_mut(identity_index),
101113
AccountType::AssetLockAddressTopUp => collection.asset_lock_address_topup.as_mut(),
102114
AccountType::AssetLockShieldedAddressTopUp => {
103115
collection.asset_lock_shielded_address_topup.as_mut()
@@ -298,7 +310,20 @@ pub unsafe extern "C" fn managed_wallet_get_address_pool_info(
298310
let wrapper = &*managed_wallet;
299311
let managed_wallet = wrapper.inner();
300312

301-
let account_type_rust = account_type.to_account_type(account_index);
313+
let account_type_rust = match account_type.to_account_type(account_index) {
314+
Ok(t) => t,
315+
Err(mut e) => {
316+
let msg = if e.message.is_null() {
317+
"Invalid account type".to_string()
318+
} else {
319+
let m = std::ffi::CStr::from_ptr(e.message).to_string_lossy().to_string();
320+
e.free_message();
321+
m
322+
};
323+
FFIError::set_error(error, e.code, msg);
324+
return false;
325+
}
326+
};
302327

303328
// Get the specific managed account
304329
let managed_account =
@@ -404,7 +429,20 @@ pub unsafe extern "C" fn managed_wallet_set_gap_limit(
404429

405430
let managed_wallet = (&mut *managed_wallet).inner_mut();
406431

407-
let account_type_rust = account_type.to_account_type(account_index);
432+
let account_type_rust = match account_type.to_account_type(account_index) {
433+
Ok(t) => t,
434+
Err(mut e) => {
435+
let msg = if e.message.is_null() {
436+
"Invalid account type".to_string()
437+
} else {
438+
let m = std::ffi::CStr::from_ptr(e.message).to_string_lossy().to_string();
439+
e.free_message();
440+
m
441+
};
442+
FFIError::set_error(error, e.code, msg);
443+
return false;
444+
}
445+
};
408446

409447
// Get the specific managed account
410448
let managed_account =
@@ -501,7 +539,20 @@ pub unsafe extern "C" fn managed_wallet_generate_addresses_to_index(
501539
let managed_wallet = (&mut *managed_wallet).inner_mut();
502540
let wallet = &*wallet;
503541

504-
let account_type_rust = account_type.to_account_type(account_index);
542+
let account_type_rust = match account_type.to_account_type(account_index) {
543+
Ok(t) => t,
544+
Err(mut e) => {
545+
let msg = if e.message.is_null() {
546+
"Invalid account type".to_string()
547+
} else {
548+
let m = std::ffi::CStr::from_ptr(e.message).to_string_lossy().to_string();
549+
e.free_message();
550+
m
551+
};
552+
FFIError::set_error(error, e.code, msg);
553+
return false;
554+
}
555+
};
505556

506557
let account_type_to_check = match account_type_rust.try_into() {
507558
Ok(check_type) => check_type,
@@ -746,6 +797,22 @@ pub unsafe extern "C" fn managed_wallet_mark_address_used(
746797
}
747798
}
748799
}
800+
if !found {
801+
for account in collection.identity_authentication_ecdsa.values_mut() {
802+
if account.mark_address_used(&address) {
803+
found = true;
804+
break;
805+
}
806+
}
807+
}
808+
if !found {
809+
for account in collection.identity_authentication_bls.values_mut() {
810+
if account.mark_address_used(&address) {
811+
found = true;
812+
break;
813+
}
814+
}
815+
}
749816
if !found {
750817
if let Some(account) = &mut collection.asset_lock_address_topup {
751818
if account.mark_address_used(&address).0 {

key-wallet-ffi/src/managed_account.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,20 @@ pub unsafe extern "C" fn managed_wallet_get_account(
218218
}
219219

220220
let managed_wallet = &*managed_wallet_ptr;
221-
let account_type_rust = account_type.to_account_type(account_index);
221+
let account_type_rust = match account_type.to_account_type(account_index) {
222+
Ok(t) => t,
223+
Err(mut e) => {
224+
let code = e.code;
225+
let message = if e.message.is_null() {
226+
"Invalid account type".to_string()
227+
} else {
228+
let m = std::ffi::CStr::from_ptr(e.message).to_string_lossy().to_string();
229+
e.free_message();
230+
m
231+
};
232+
return FFIManagedCoreAccountResult::error(code, message);
233+
}
234+
};
222235

223236
let result = {
224237
use key_wallet::account::StandardAccountType;
@@ -247,6 +260,12 @@ pub unsafe extern "C" fn managed_wallet_get_account(
247260
managed_collection.identity_topup_not_bound.as_ref()
248261
}
249262
AccountType::IdentityInvitation => managed_collection.identity_invitation.as_ref(),
263+
AccountType::IdentityAuthenticationEcdsa {
264+
identity_index,
265+
} => managed_collection.identity_authentication_ecdsa.get(&identity_index),
266+
AccountType::IdentityAuthenticationBls {
267+
identity_index,
268+
} => managed_collection.identity_authentication_bls.get(&identity_index),
250269
AccountType::AssetLockAddressTopUp => {
251270
managed_collection.asset_lock_address_topup.as_ref()
252271
}
@@ -564,6 +583,12 @@ pub unsafe extern "C" fn managed_core_account_get_account_type(
564583
FFIAccountType::IdentityTopUpNotBoundToIdentity
565584
}
566585
AccountType::IdentityInvitation => FFIAccountType::IdentityInvitation,
586+
AccountType::IdentityAuthenticationEcdsa {
587+
..
588+
} => FFIAccountType::IdentityAuthenticationEcdsa,
589+
AccountType::IdentityAuthenticationBls {
590+
..
591+
} => FFIAccountType::IdentityAuthenticationBls,
567592
AccountType::AssetLockAddressTopUp => FFIAccountType::AssetLockAddressTopUp,
568593
AccountType::AssetLockShieldedAddressTopUp => FFIAccountType::AssetLockShieldedAddressTopUp,
569594
AccountType::ProviderVotingKeys => FFIAccountType::ProviderVotingKeys,
@@ -1167,6 +1192,14 @@ pub unsafe extern "C" fn managed_core_account_get_address_pool(
11671192
addresses,
11681193
..
11691194
} => addresses,
1195+
ManagedAccountType::IdentityAuthenticationEcdsa {
1196+
addresses,
1197+
..
1198+
} => addresses,
1199+
ManagedAccountType::IdentityAuthenticationBls {
1200+
addresses,
1201+
..
1202+
} => addresses,
11701203
};
11711204

11721205
let ffi_pool = FFIAddressPool {

0 commit comments

Comments
 (0)