mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-30 19:09:36 +00:00
feat(wallet-ffi): pda helpers
This commit is contained in:
parent
fade3b488a
commit
0ee39e04ee
@ -47,6 +47,7 @@ pub mod error;
|
||||
pub mod generic_transaction;
|
||||
pub mod keys;
|
||||
pub mod label;
|
||||
pub mod pda;
|
||||
pub mod pinata;
|
||||
pub mod program_deployment;
|
||||
pub mod sync;
|
||||
|
||||
45
lez/wallet-ffi/src/pda.rs
Normal file
45
lez/wallet-ffi/src/pda.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use lee::AccountId;
|
||||
|
||||
use crate::{FfiBytes32, FfiNullifierPublicKey, FfiPdaSeed, FfiProgramId, FfiU128};
|
||||
|
||||
/// Produce account id for public PDA.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `program_id`: Id of a owner program
|
||||
/// - `pda_seed`: 32 byte seed
|
||||
///
|
||||
/// # Returns
|
||||
/// - `FfiBytes32` representing account id bytes
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wallet_ffi_account_id_for_public_pda(
|
||||
program_id: FfiProgramId,
|
||||
pda_seed: FfiPdaSeed,
|
||||
) -> FfiBytes32 {
|
||||
AccountId::for_public_pda(&program_id.data, &pda_seed.into()).into()
|
||||
}
|
||||
|
||||
/// Produce account id for public PDA.
|
||||
///
|
||||
/// # Parameters
|
||||
/// - `program_id`: Id of a owner program
|
||||
/// - `pda_seed`: 32 byte seed
|
||||
/// - `npk`: 32 byte nullifier public key(can be get from `wallet_ffi_get_private_account_keys`)
|
||||
/// - `identifier`: little endian encoded `u128`
|
||||
///
|
||||
/// # Returns
|
||||
/// - `FfiBytes32` representing account id bytes
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wallet_ffi_account_id_for_private_pda(
|
||||
program_id: FfiProgramId,
|
||||
pda_seed: FfiPdaSeed,
|
||||
npk: FfiNullifierPublicKey,
|
||||
identifier: FfiU128,
|
||||
) -> FfiBytes32 {
|
||||
AccountId::for_private_pda(
|
||||
&program_id.data,
|
||||
&pda_seed.into(),
|
||||
&npk.into(),
|
||||
identifier.into(),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
@ -8,7 +8,7 @@ use std::{
|
||||
};
|
||||
|
||||
use lee::{Data, ProgramId, SharedSecretKey};
|
||||
use lee_core::{encryption::MlKem768EncapsulationKey, NullifierPublicKey};
|
||||
use lee_core::{encryption::MlKem768EncapsulationKey, program::PdaSeed, NullifierPublicKey};
|
||||
use wallet::{account::AccountIdWithPrivacy, AccountIdentity};
|
||||
|
||||
use crate::error::WalletFfiError;
|
||||
@ -29,6 +29,22 @@ pub struct FfiBytes32 {
|
||||
pub data: [u8; 32],
|
||||
}
|
||||
|
||||
pub type FfiPdaSeed = FfiBytes32;
|
||||
|
||||
impl From<FfiPdaSeed> for PdaSeed {
|
||||
fn from(value: FfiPdaSeed) -> Self {
|
||||
Self::new(value.data)
|
||||
}
|
||||
}
|
||||
|
||||
pub type FfiNullifierPublicKey = FfiBytes32;
|
||||
|
||||
impl From<FfiNullifierPublicKey> for NullifierPublicKey {
|
||||
fn from(value: FfiNullifierPublicKey) -> Self {
|
||||
Self(value.data)
|
||||
}
|
||||
}
|
||||
|
||||
/// Program ID - 8 u32 values (32 bytes total).
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
|
||||
@ -320,6 +320,10 @@ typedef struct LabelList {
|
||||
enum WalletFfiError error;
|
||||
} LabelList;
|
||||
|
||||
typedef struct FfiBytes32 FfiPdaSeed;
|
||||
|
||||
typedef struct FfiBytes32 FfiNullifierPublicKey;
|
||||
|
||||
typedef struct FfiCreateWalletOutput {
|
||||
struct WalletHandle *wallet;
|
||||
/**
|
||||
@ -914,6 +918,36 @@ struct LabelList wallet_ffi_get_all_labels_for_account(struct WalletHandle *hand
|
||||
*/
|
||||
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
|
||||
* - `pda_seed`: 32 byte seed
|
||||
*
|
||||
* # Returns
|
||||
* - `FfiBytes32` representing account id bytes
|
||||
*/
|
||||
struct FfiBytes32 wallet_ffi_account_id_for_public_pda(struct FfiProgramId program_id,
|
||||
FfiPdaSeed pda_seed);
|
||||
|
||||
/**
|
||||
* Produce account id for public PDA.
|
||||
*
|
||||
* # Parameters
|
||||
* - `program_id`: Id of a owner program
|
||||
* - `pda_seed`: 32 byte seed
|
||||
* - `npk`: 32 byte nullifier public key(can be get from `wallet_ffi_get_private_account_keys`)
|
||||
* - `identifier`: little endian encoded `u128`
|
||||
*
|
||||
* # Returns
|
||||
* - `FfiBytes32` representing account id bytes
|
||||
*/
|
||||
struct FfiBytes32 wallet_ffi_account_id_for_private_pda(struct FfiProgramId program_id,
|
||||
FfiPdaSeed pda_seed,
|
||||
FfiNullifierPublicKey npk,
|
||||
struct FfiU128 identifier);
|
||||
|
||||
/**
|
||||
* Claim a pinata reward using a public transaction.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user