Standard authorization for a specific user to decrypt specific data:
Copy
use privora_sdk_program::auth::pda::DecryptionAuth;// Find the authorization PDAlet (auth_pda, bump) = DecryptionAuth::find_pda( &data_hash, // Hash of encrypted data &user_pubkey, // User being authorized);
For orderbook-style applications where matching creates authorization:
Copy
use privora_sdk_program::auth::pda::MatchAuth;let (auth_pda, bump) = MatchAuth::find_pda( buy_order_id, // First order ID sell_order_id, // Second order ID "price", // Field being authorized &user_pubkey, // User being authorized);
use privora_sdk_program::auth::cpi::create_decryption_auth;pub fn authorize_user( program_id: &Pubkey, accounts: &[AccountInfo], data_hash: [u8; 32],) -> ProgramResult { let account_info_iter = &mut accounts.iter(); let fhe_auth_program = next_account_info(account_info_iter)?; let auth_pda = next_account_info(account_info_iter)?; let user = next_account_info(account_info_iter)?; let payer = next_account_info(account_info_iter)?; let system_program = next_account_info(account_info_iter)?; // Create the authorization PDA create_decryption_auth( fhe_auth_program, auth_pda, &data_hash, user.key, payer, system_program, )?; msg!("Authorization created for user {}", user.key); Ok(())}
pub fn match_orders( program_id: &Pubkey, accounts: &[AccountInfo],) -> ProgramResult { let account_info_iter = &mut accounts.iter(); let orderbook = next_account_info(account_info_iter)?; let buy_order_account = next_account_info(account_info_iter)?; let sell_order_account = next_account_info(account_info_iter)?; let match_result_account = next_account_info(account_info_iter)?; let fhe_auth_program = next_account_info(account_info_iter)?; let buy_user_auth_pda = next_account_info(account_info_iter)?; let sell_user_auth_pda = next_account_info(account_info_iter)?; let payer = next_account_info(account_info_iter)?; let system_program = next_account_info(account_info_iter)?; // Load orders let buy_order = Order::try_from_slice(&buy_order_account.data.borrow())?; let sell_order = Order::try_from_slice(&sell_order_account.data.borrow())?; // Load encrypted data and perform matching let buy_price = buy_order.price_ref.load()?; let sell_price = sell_order.price_ref.load()?; let buy_qty = buy_order.qty_ref.load()?; let sell_qty = sell_order.qty_ref.load()?; // Check match and calculate fill let can_match = buy_price.ge(&sell_price)?; let fill_qty = buy_qty.min(&sell_qty)?; let fill_qty_ref = fill_qty.store()?; // Authorize buy user to decrypt fill details create_match_authorization( fhe_auth_program, buy_user_auth_pda, payer, system_program, buy_order.order_id, sell_order.order_id, "fill_qty", &buy_order.owner, )?; // Authorize sell user to decrypt fill details create_match_authorization( fhe_auth_program, sell_user_auth_pda, payer, system_program, buy_order.order_id, sell_order.order_id, "fill_qty", &sell_order.owner, )?; msg!("Orders matched, users authorized to decrypt results"); Ok(())}
// When user depositslet encrypted_balance = amount.store()?;// Authorize user to decrypt their own balancecreate_decryption_auth( &encrypted_balance.hash(), &depositor_pubkey,)?;