mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-14 03:59:30 +00:00
fix: resolve shared accounts in auth-transfer commands
This commit is contained in:
parent
4e7963c655
commit
2b2275ee74
@ -317,6 +317,59 @@ impl WalletCore {
|
|||||||
self.storage.user_data.sealing_secret_key = Some(key);
|
self.storage.user_data.sealing_secret_key = Some(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resolve an `AccountId` to the appropriate `PrivacyPreservingAccount` variant.
|
||||||
|
/// Checks the key tree first, then shared private accounts.
|
||||||
|
#[must_use]
|
||||||
|
pub fn resolve_private_account(
|
||||||
|
&self,
|
||||||
|
account_id: nssa::AccountId,
|
||||||
|
) -> Option<PrivacyPreservingAccount> {
|
||||||
|
// Check key tree first
|
||||||
|
if self
|
||||||
|
.storage
|
||||||
|
.user_data
|
||||||
|
.get_private_account(account_id)
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
return Some(PrivacyPreservingAccount::PrivateOwned(account_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check shared private accounts
|
||||||
|
let entry = self.storage.user_data.shared_private_account(&account_id)?;
|
||||||
|
let holder = self
|
||||||
|
.storage
|
||||||
|
.user_data
|
||||||
|
.group_key_holder(&entry.group_label)?;
|
||||||
|
|
||||||
|
if let Some(pda_seed) = &entry.pda_seed {
|
||||||
|
let program_id = entry.pda_program_id?;
|
||||||
|
let keys = holder.derive_keys_for_pda(&program_id, pda_seed);
|
||||||
|
Some(PrivacyPreservingAccount::PrivatePda {
|
||||||
|
nsk: keys.nullifier_secret_key,
|
||||||
|
npk: keys.generate_nullifier_public_key(),
|
||||||
|
vpk: keys.generate_viewing_public_key(),
|
||||||
|
program_id,
|
||||||
|
seed: *pda_seed,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
let derivation_seed = {
|
||||||
|
use sha2::Digest as _;
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
hasher.update(b"/LEE/v0.3/SharedAccountTag/\x00\x00\x00\x00\x00");
|
||||||
|
hasher.update(entry.identifier.to_le_bytes());
|
||||||
|
let result: [u8; 32] = hasher.finalize().into();
|
||||||
|
result
|
||||||
|
};
|
||||||
|
let keys = holder.derive_keys_for_shared_account(&derivation_seed);
|
||||||
|
Some(PrivacyPreservingAccount::PrivateShared {
|
||||||
|
nsk: keys.nullifier_secret_key,
|
||||||
|
npk: keys.generate_nullifier_public_key(),
|
||||||
|
vpk: keys.generate_viewing_public_key(),
|
||||||
|
identifier: entry.identifier,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Remove a group key holder from storage. Returns the removed holder if it existed.
|
/// Remove a group key holder from storage. Returns the removed holder if it existed.
|
||||||
pub fn remove_group_key_holder(
|
pub fn remove_group_key_holder(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@ -14,9 +14,14 @@ impl NativeTokenTransfer<'_> {
|
|||||||
) -> Result<(HashType, SharedSecretKey), ExecutionFailureKind> {
|
) -> Result<(HashType, SharedSecretKey), ExecutionFailureKind> {
|
||||||
let instruction: u128 = 0;
|
let instruction: u128 = 0;
|
||||||
|
|
||||||
|
let account = self
|
||||||
|
.0
|
||||||
|
.resolve_private_account(from)
|
||||||
|
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||||
|
|
||||||
self.0
|
self.0
|
||||||
.send_privacy_preserving_tx(
|
.send_privacy_preserving_tx(
|
||||||
vec![PrivacyPreservingAccount::PrivateOwned(from)],
|
vec![account],
|
||||||
Program::serialize_instruction(instruction).unwrap(),
|
Program::serialize_instruction(instruction).unwrap(),
|
||||||
&Program::authenticated_transfer_program().into(),
|
&Program::authenticated_transfer_program().into(),
|
||||||
)
|
)
|
||||||
@ -69,12 +74,18 @@ impl NativeTokenTransfer<'_> {
|
|||||||
) -> Result<(HashType, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
) -> Result<(HashType, [SharedSecretKey; 2]), ExecutionFailureKind> {
|
||||||
let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move);
|
let (instruction_data, program, tx_pre_check) = auth_transfer_preparation(balance_to_move);
|
||||||
|
|
||||||
|
let from_account = self
|
||||||
|
.0
|
||||||
|
.resolve_private_account(from)
|
||||||
|
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||||
|
let to_account = self
|
||||||
|
.0
|
||||||
|
.resolve_private_account(to)
|
||||||
|
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||||
|
|
||||||
self.0
|
self.0
|
||||||
.send_privacy_preserving_tx_with_pre_check(
|
.send_privacy_preserving_tx_with_pre_check(
|
||||||
vec![
|
vec![from_account, to_account],
|
||||||
PrivacyPreservingAccount::PrivateOwned(from),
|
|
||||||
PrivacyPreservingAccount::PrivateOwned(to),
|
|
||||||
],
|
|
||||||
instruction_data,
|
instruction_data,
|
||||||
&program.into(),
|
&program.into(),
|
||||||
tx_pre_check,
|
tx_pre_check,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user