diff --git a/token/client/Cargo.toml b/token/client/Cargo.toml index adfcd321074..694eec7f257 100644 --- a/token/client/Cargo.toml +++ b/token/client/Cargo.toml @@ -31,4 +31,3 @@ thiserror = "1.0" [features] default = ["display"] display = ["dep:solana-cli-output"] -proof-program = ["spl-token-2022/proof-program"] diff --git a/token/client/src/token.rs b/token/client/src/token.rs index 44d6df96198..bc147721dae 100644 --- a/token/client/src/token.rs +++ b/token/client/src/token.rs @@ -68,15 +68,6 @@ use { }, thiserror::Error, }; -#[cfg(feature = "proof-program")] -use { - solana_sdk::epoch_info::EpochInfo, - spl_token_2022::solana_zk_token_sdk::{ - encryption::{auth_encryption::*, elgamal::*}, - instruction::transfer_with_fee::FeeParameters, - }, - std::convert::TryInto, -}; #[derive(Error, Debug)] pub enum TokenError { @@ -1859,191 +1850,6 @@ where .await } - /// Fetch and decrypt the available balance of a confidential token account using the uniquely - /// derived decryption key from a signer - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_available_balance( - &self, - token_account: &Pubkey, - authority: &S, - ) -> TokenResult { - let authenticated_encryption_key = - AeKey::new(authority, token_account).map_err(TokenError::Key)?; - - self.confidential_transfer_get_available_balance_with_key( - token_account, - &authenticated_encryption_key, - ) - .await - } - - /// Fetch and decrypt the available balance of a confidential token account using a custom - /// decryption key - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_available_balance_with_key( - &self, - token_account: &Pubkey, - authenticated_encryption_key: &AeKey, - ) -> TokenResult { - let state = self.get_account_info(token_account).await.unwrap(); - let extension = - state.get_extension::()?; - - let decryptable_balance_ciphertext: AeCiphertext = extension - .decryptable_available_balance - .try_into() - .map_err(TokenError::Proof)?; - let decryptable_balance = decryptable_balance_ciphertext - .decrypt(authenticated_encryption_key) - .ok_or(TokenError::AccountDecryption)?; - - Ok(decryptable_balance) - } - - /// Fetch and decrypt the pending balance of a confidential token account using the uniquely - /// derived decryption key from a signer - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_pending_balance( - &self, - token_account: &Pubkey, - authority: &S, - ) -> TokenResult { - let elgamal_keypair = - ElGamalKeypair::new(authority, token_account).map_err(TokenError::Key)?; - - self.confidential_transfer_get_pending_balance_with_key(token_account, &elgamal_keypair) - .await - } - - /// Fetch and decrypt the pending balance of a confidential token account using a custom - /// decryption key - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_pending_balance_with_key( - &self, - token_account: &Pubkey, - elgamal_keypair: &ElGamalKeypair, - ) -> TokenResult { - let state = self.get_account_info(token_account).await.unwrap(); - let extension = - state.get_extension::()?; - - // decrypt pending balance - let pending_balance_lo = extension - .pending_balance_lo - .decrypt(&elgamal_keypair.secret) - .ok_or(TokenError::AccountDecryption)?; - let pending_balance_hi = extension - .pending_balance_hi - .decrypt(&elgamal_keypair.secret) - .ok_or(TokenError::AccountDecryption)?; - - let pending_balance = pending_balance_lo - .checked_add(pending_balance_hi << confidential_transfer::PENDING_BALANCE_HI_BIT_LENGTH) - .ok_or(TokenError::AccountDecryption)?; - - Ok(pending_balance) - } - - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_withheld_amount( - &self, - withdraw_withheld_authority: &S, - sources: &[&Pubkey], - ) -> TokenResult { - let withdraw_withheld_authority_elgamal_keypair = - ElGamalKeypair::new(withdraw_withheld_authority, &self.pubkey) - .map_err(TokenError::Key)?; - - self.confidential_transfer_get_withheld_amount_with_key( - &withdraw_withheld_authority_elgamal_keypair, - sources, - ) - .await - } - - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_withheld_amount_with_key( - &self, - withdraw_withheld_authority_elgamal_keypair: &ElGamalKeypair, - sources: &[&Pubkey], - ) -> TokenResult { - let mut aggregate_withheld_amount_ciphertext = ElGamalCiphertext::default(); - for &source in sources { - let state = self.get_account_info(source).await.unwrap(); - let extension = - state.get_extension::()?; - - let withheld_amount_ciphertext: ElGamalCiphertext = - extension.withheld_amount.try_into().unwrap(); - - aggregate_withheld_amount_ciphertext = - aggregate_withheld_amount_ciphertext + withheld_amount_ciphertext; - } - - let aggregate_withheld_amount = aggregate_withheld_amount_ciphertext - .decrypt_u32(&withdraw_withheld_authority_elgamal_keypair.secret) - .ok_or(TokenError::AccountDecryption)?; - - Ok(aggregate_withheld_amount) - } - - /// Fetch the ElGamal public key associated with a confidential token account - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_elgamal_pubkey( - &self, - token_account: &Pubkey, - ) -> TokenResult { - let state = self.get_account_info(token_account).await.unwrap(); - let extension = - state.get_extension::()?; - let elgamal_pubkey = extension - .elgamal_pubkey - .try_into() - .map_err(TokenError::Proof)?; - - Ok(elgamal_pubkey) - } - - /// Fetch the ElGamal pubkey key of the auditor associated with a confidential token mint - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_auditor_elgamal_pubkey( - &self, - ) -> TokenResult> { - let mint_state = self.get_mint_info().await.unwrap(); - let ct_mint = - mint_state.get_extension::()?; - let auditor_elgamal_pubkey: Option = ct_mint.auditor_elgamal_pubkey.into(); - - if let Some(elgamal_pubkey) = auditor_elgamal_pubkey { - let elgamal_pubkey: ElGamalPubkey = - elgamal_pubkey.try_into().map_err(TokenError::Proof)?; - Ok(Some(elgamal_pubkey)) - } else { - Ok(None) - } - } - - /// Fetch the ElGamal pubkey key of the withdraw withheld authority associated with a - /// confidential token mint - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_get_withdraw_withheld_authority_elgamal_pubkey( - &self, - ) -> TokenResult> { - let mint_state = self.get_mint_info().await.unwrap(); - let ct_mint = - mint_state.get_extension::()?; - let withdraw_withheld_authority_elgamal_pubkey: Option = - ct_mint.withdraw_withheld_authority_elgamal_pubkey.into(); - - if let Some(elgamal_pubkey) = withdraw_withheld_authority_elgamal_pubkey { - let elgamal_pubkey: ElGamalPubkey = - elgamal_pubkey.try_into().map_err(TokenError::Proof)?; - Ok(Some(elgamal_pubkey)) - } else { - Ok(None) - } - } - /// Deposit SPL Tokens into the pending balance of a confidential token account pub async fn confidential_transfer_deposit( &self, @@ -2135,53 +1941,6 @@ where .await } - /// Withdraw SPL Tokens from the available balance of a confidential token account using custom - /// keys - #[allow(clippy::too_many_arguments)] - #[cfg(feature = "proof-program")] - pub async fn confidential_transfer_withdraw_with_key( - &self, - token_account: &Pubkey, - token_authority: &Pubkey, - amount: u64, - decimals: u8, - available_balance: u64, - available_balance_ciphertext: &ElGamalCiphertext, - elgamal_keypair: &ElGamalKeypair, - authenticated_encryption_key: &AeKey, - signing_keypairs: &S, - ) -> TokenResult { - let proof_data = confidential_transfer::instruction::WithdrawData::new( - amount, - elgamal_keypair, - available_balance, - available_balance_ciphertext, - ) - .map_err(TokenError::Proof)?; - - let remaining_balance = available_balance - .checked_sub(amount) - .ok_or(TokenError::NotEnoughFunds)?; - let new_decryptable_available_balance = - authenticated_encryption_key.encrypt(remaining_balance); - - self.process_ixs( - &confidential_transfer::instruction::withdraw( - &self.program_id, - token_account, - &self.pubkey, - amount, - decimals, - new_decryptable_available_balance, - token_authority, - &[], - &proof_data, - )?, - signing_keypairs, - ) - .await - } - /// Transfer tokens confidentially #[allow(clippy::too_many_arguments)] pub async fn confidential_transfer_transfer(