fix(wallet_ffi): suggestions 2

This commit is contained in:
Pravdyvy 2026-07-08 14:33:32 +03:00
parent 91e310b8a0
commit e61306e498
3 changed files with 54 additions and 6 deletions

View File

@ -5,7 +5,7 @@ use crate::{FfiBytes32, FfiNullifierPublicKey, FfiPdaSeed, FfiProgramId, FfiU128
/// Produce account id for public PDA.
///
/// # Parameters
/// - `program_id`: Id of a owner program
/// - `program_id`: Id of the owner program
/// - `pda_seed`: 32 byte seed
///
/// # Returns
@ -21,9 +21,10 @@ pub extern "C" fn wallet_ffi_account_id_for_public_pda(
/// Produce account id for private PDA.
///
/// # Parameters
/// - `program_id`: Id of a owner program
/// - `program_id`: Id of the owner program
/// - `pda_seed`: 32 byte seed
/// - `npk`: 32 byte nullifier public key(can be get from `wallet_ffi_get_private_account_keys`)
/// - `npk`: 32 byte nullifier public key (can be obtained from
/// `wallet_ffi_get_private_account_keys`)
/// - `identifier`: little endian encoded `u128`
///
/// # Returns
@ -43,3 +44,41 @@ pub extern "C" fn wallet_ffi_account_id_for_private_pda(
)
.into()
}
#[cfg(test)]
mod tests {
use lee::AccountId;
use lee_core::NullifierPublicKey;
use vault_core::PdaSeed;
use crate::pda::{wallet_ffi_account_id_for_private_pda, wallet_ffi_account_id_for_public_pda};
#[test]
fn public_pda_consistent_derivation() {
let program_id = [100_u32, 101, 102, 103, 104, 105, 106, 107];
let pda_seed = PdaSeed::new([42; 32]);
let pda_id = AccountId::for_public_pda(&program_id, &pda_seed);
let ffi_pda_id = wallet_ffi_account_id_for_public_pda(program_id.into(), pda_seed.into());
assert_eq!(pda_id.into_value(), ffi_pda_id.data);
}
#[test]
fn private_pda_consistent_derivation() {
let program_id = [100_u32, 101, 102, 103, 104, 105, 106, 107];
let pda_seed = PdaSeed::new([42; 32]);
let npk = NullifierPublicKey([43; 32]);
let identifier = 100_000_u128;
let pda_id = AccountId::for_private_pda(&program_id, &pda_seed, &npk, identifier);
let ffi_pda_id = wallet_ffi_account_id_for_private_pda(
program_id.into(),
pda_seed.into(),
npk.into(),
identifier.into(),
);
assert_eq!(pda_id.into_value(), ffi_pda_id.data);
}
}

View File

@ -37,6 +37,14 @@ impl From<FfiPdaSeed> for PdaSeed {
}
}
impl From<PdaSeed> for FfiPdaSeed {
fn from(value: PdaSeed) -> Self {
Self {
data: *value.as_bytes(),
}
}
}
pub type FfiNullifierPublicKey = FfiBytes32;
impl From<FfiNullifierPublicKey> for NullifierPublicKey {

View File

@ -922,7 +922,7 @@ enum WalletFfiError wallet_ffi_free_label_list(struct LabelList *label_list);
* Produce account id for public PDA.
*
* # Parameters
* - `program_id`: Id of a owner program
* - `program_id`: Id of the owner program
* - `pda_seed`: 32 byte seed
*
* # Returns
@ -935,9 +935,10 @@ struct FfiBytes32 wallet_ffi_account_id_for_public_pda(struct FfiProgramId progr
* Produce account id for private PDA.
*
* # Parameters
* - `program_id`: Id of a owner program
* - `program_id`: Id of the owner program
* - `pda_seed`: 32 byte seed
* - `npk`: 32 byte nullifier public key(can be get from `wallet_ffi_get_private_account_keys`)
* - `npk`: 32 byte nullifier public key (can be obtained from
* `wallet_ffi_get_private_account_keys`)
* - `identifier`: little endian encoded `u128`
*
* # Returns