@@ -20,11 +20,12 @@ use {
20
20
} ,
21
21
spl_token_2022:: {
22
22
extension:: {
23
- confidential_transfer, confidential_transfer :: EncryptionPubkey , cpi_guard ,
24
- default_account_state , interest_bearing_mint , memo_transfer , transfer_fee ,
25
- BaseStateWithExtensions , ExtensionType , StateWithExtensionsOwned ,
23
+ confidential_transfer, cpi_guard , default_account_state , interest_bearing_mint ,
24
+ memo_transfer , transfer_fee , BaseStateWithExtensions , ExtensionType ,
25
+ StateWithExtensionsOwned ,
26
26
} ,
27
27
instruction,
28
+ pod:: EncryptionPubkey ,
28
29
solana_zk_token_sdk:: {
29
30
encryption:: { auth_encryption:: * , elgamal:: * } ,
30
31
errors:: ProofError ,
@@ -106,8 +107,8 @@ pub enum ExtensionInitializationParams {
106
107
ConfidentialTransferMint {
107
108
authority : Option < Pubkey > ,
108
109
auto_approve_new_accounts : bool ,
109
- auditor_encryption_pubkey : EncryptionPubkey ,
110
- withdraw_withheld_authority_encryption_pubkey : EncryptionPubkey ,
110
+ auditor_encryption_pubkey : Option < EncryptionPubkey > ,
111
+ withdraw_withheld_authority_encryption_pubkey : Option < EncryptionPubkey > ,
111
112
} ,
112
113
DefaultAccountState {
113
114
state : AccountState ,
@@ -158,10 +159,10 @@ impl ExtensionInitializationParams {
158
159
} => confidential_transfer:: instruction:: initialize_mint (
159
160
token_program_id,
160
161
mint,
161
- authority. as_ref ( ) ,
162
+ authority,
162
163
auto_approve_new_accounts,
163
- & auditor_encryption_pubkey,
164
- & withdraw_withheld_authority_encryption_pubkey,
164
+ auditor_encryption_pubkey,
165
+ withdraw_withheld_authority_encryption_pubkey,
165
166
) ,
166
167
Self :: DefaultAccountState { state } => {
167
168
default_account_state:: instruction:: initialize_default_account_state (
@@ -1492,7 +1493,7 @@ where
1492
1493
authority : & S ,
1493
1494
new_authority : Option < & S > ,
1494
1495
auto_approve_new_account : bool ,
1495
- auditor_encryption_pubkey : & EncryptionPubkey ,
1496
+ auditor_encryption_pubkey : Option < EncryptionPubkey > ,
1496
1497
) -> TokenResult < T :: Output > {
1497
1498
let mut signers = vec ! [ authority] ;
1498
1499
let new_authority_pubkey = if let Some ( new_authority) = new_authority {
@@ -1789,16 +1790,20 @@ where
1789
1790
/// Fetch the ElGamal pubkey key of the auditor associated with a confidential token mint
1790
1791
pub async fn confidential_transfer_get_auditor_encryption_pubkey < S : Signer > (
1791
1792
& self ,
1792
- ) -> TokenResult < ElGamalPubkey > {
1793
+ ) -> TokenResult < Option < ElGamalPubkey > > {
1793
1794
let mint_state = self . get_mint_info ( ) . await . unwrap ( ) ;
1794
1795
let ct_mint =
1795
1796
mint_state. get_extension :: < confidential_transfer:: ConfidentialTransferMint > ( ) ?;
1796
- let auditor_pubkey = ct_mint
1797
- . auditor_encryption_pubkey
1798
- . try_into ( )
1799
- . map_err ( TokenError :: Proof ) ?;
1797
+ let auditor_encryption_pubkey: Option < EncryptionPubkey > =
1798
+ ct_mint. auditor_encryption_pubkey . into ( ) ;
1800
1799
1801
- Ok ( auditor_pubkey)
1800
+ if let Some ( encryption_pubkey) = auditor_encryption_pubkey {
1801
+ let encryption_pubkey: ElGamalPubkey =
1802
+ encryption_pubkey. try_into ( ) . map_err ( TokenError :: Proof ) ?;
1803
+ Ok ( Some ( encryption_pubkey) )
1804
+ } else {
1805
+ Ok ( None )
1806
+ }
1802
1807
}
1803
1808
1804
1809
/// Fetch the ElGamal pubkey key of the withdraw withheld authority associated with a
@@ -1807,16 +1812,20 @@ where
1807
1812
S : Signer ,
1808
1813
> (
1809
1814
& self ,
1810
- ) -> TokenResult < ElGamalPubkey > {
1815
+ ) -> TokenResult < Option < ElGamalPubkey > > {
1811
1816
let mint_state = self . get_mint_info ( ) . await . unwrap ( ) ;
1812
1817
let ct_mint =
1813
1818
mint_state. get_extension :: < confidential_transfer:: ConfidentialTransferMint > ( ) ?;
1814
- let auditor_pubkey = ct_mint
1815
- . withdraw_withheld_authority_encryption_pubkey
1816
- . try_into ( )
1817
- . map_err ( TokenError :: Proof ) ?;
1819
+ let withdraw_withheld_authority_encryption_pubkey: Option < EncryptionPubkey > =
1820
+ ct_mint. withdraw_withheld_authority_encryption_pubkey . into ( ) ;
1818
1821
1819
- Ok ( auditor_pubkey)
1822
+ if let Some ( encryption_pubkey) = withdraw_withheld_authority_encryption_pubkey {
1823
+ let encryption_pubkey: ElGamalPubkey =
1824
+ encryption_pubkey. try_into ( ) . map_err ( TokenError :: Proof ) ?;
1825
+ Ok ( Some ( encryption_pubkey) )
1826
+ } else {
1827
+ Ok ( None )
1828
+ }
1820
1829
}
1821
1830
1822
1831
/// Deposit SPL Tokens into the pending balance of a confidential token account
@@ -1932,7 +1941,7 @@ where
1932
1941
source_available_balance : u64 ,
1933
1942
source_available_balance_ciphertext : & ElGamalCiphertext ,
1934
1943
destination_elgamal_pubkey : & ElGamalPubkey ,
1935
- auditor_elgamal_pubkey : & ElGamalPubkey ,
1944
+ auditor_elgamal_pubkey : Option < ElGamalPubkey > ,
1936
1945
) -> TokenResult < T :: Output > {
1937
1946
let source_elgamal_keypair =
1938
1947
ElGamalKeypair :: new ( source_token_authority, source_token_account)
@@ -1966,22 +1975,24 @@ where
1966
1975
source_available_balance : u64 ,
1967
1976
source_available_balance_ciphertext : & ElGamalCiphertext ,
1968
1977
destination_elgamal_pubkey : & ElGamalPubkey ,
1969
- auditor_elgamal_pubkey : & ElGamalPubkey ,
1978
+ auditor_elgamal_pubkey : Option < ElGamalPubkey > ,
1970
1979
source_elgamal_keypair : & ElGamalKeypair ,
1971
1980
source_authenticated_encryption_key : & AeKey ,
1972
1981
) -> TokenResult < T :: Output > {
1973
1982
if amount >> confidential_transfer:: MAXIMUM_DEPOSIT_TRANSFER_AMOUNT_BIT_LENGTH != 0 {
1974
1983
return Err ( TokenError :: MaximumDepositTransferAmountExceeded ) ;
1975
1984
}
1976
1985
1986
+ let auditor_elgamal_pubkey = auditor_elgamal_pubkey. unwrap_or_default ( ) ;
1987
+
1977
1988
let proof_data = confidential_transfer:: instruction:: TransferData :: new (
1978
1989
amount,
1979
1990
(
1980
1991
source_available_balance,
1981
1992
source_available_balance_ciphertext,
1982
1993
) ,
1983
1994
source_elgamal_keypair,
1984
- ( destination_elgamal_pubkey, auditor_elgamal_pubkey) ,
1995
+ ( destination_elgamal_pubkey, & auditor_elgamal_pubkey) ,
1985
1996
)
1986
1997
. map_err ( TokenError :: Proof ) ?;
1987
1998
@@ -2019,7 +2030,7 @@ where
2019
2030
source_available_balance : u64 ,
2020
2031
source_available_balance_ciphertext : & ElGamalCiphertext ,
2021
2032
destination_elgamal_pubkey : & ElGamalPubkey ,
2022
- auditor_elgamal_pubkey : & ElGamalPubkey ,
2033
+ auditor_elgamal_pubkey : Option < ElGamalPubkey > ,
2023
2034
withdraw_withheld_authority_elgamal_pubkey : & ElGamalPubkey ,
2024
2035
epoch_info : & EpochInfo ,
2025
2036
) -> TokenResult < T :: Output > {
@@ -2057,7 +2068,7 @@ where
2057
2068
source_available_balance : u64 ,
2058
2069
source_available_balance_ciphertext : & ElGamalCiphertext ,
2059
2070
destination_elgamal_pubkey : & ElGamalPubkey ,
2060
- auditor_elgamal_pubkey : & ElGamalPubkey ,
2071
+ auditor_elgamal_pubkey : Option < ElGamalPubkey > ,
2061
2072
withdraw_withheld_authority_elgamal_pubkey : & ElGamalPubkey ,
2062
2073
source_elgamal_keypair : & ElGamalKeypair ,
2063
2074
source_authenticated_encryption_key : & AeKey ,
@@ -2067,7 +2078,8 @@ where
2067
2078
return Err ( TokenError :: MaximumDepositTransferAmountExceeded ) ;
2068
2079
}
2069
2080
2070
- // TODO: take transfer fee params as input
2081
+ let auditor_elgamal_pubkey = auditor_elgamal_pubkey. unwrap_or_default ( ) ;
2082
+
2071
2083
let mint_state = self . get_mint_info ( ) . await . unwrap ( ) ;
2072
2084
let transfer_fee_config = mint_state
2073
2085
. get_extension :: < transfer_fee:: TransferFeeConfig > ( )
@@ -2081,7 +2093,7 @@ where
2081
2093
source_available_balance_ciphertext,
2082
2094
) ,
2083
2095
source_elgamal_keypair,
2084
- ( destination_elgamal_pubkey, auditor_elgamal_pubkey) ,
2096
+ ( destination_elgamal_pubkey, & auditor_elgamal_pubkey) ,
2085
2097
FeeParameters {
2086
2098
fee_rate_basis_points : u16:: from ( fee_parameters. transfer_fee_basis_points ) ,
2087
2099
maximum_fee : u64:: from ( fee_parameters. maximum_fee ) ,
0 commit comments