@@ -21,28 +21,12 @@ use spl_token_2022::extension::{
21
21
transfer_fee:: { TransferFee , TransferFeeAmount , TransferFeeConfig } ,
22
22
transfer_hook:: TransferHook ,
23
23
} ;
24
- use std:: fmt;
25
24
26
25
use spl_token_group_interface:: state:: { TokenGroup , TokenGroupMember } ;
27
26
use spl_token_metadata_interface:: state:: TokenMetadata ;
28
27
29
- const AE_CIPHERTEXT_LEN : usize = 36 ;
30
- const UNIT_LEN : usize = 32 ;
31
- const RISTRETTO_POINT_LEN : usize = UNIT_LEN ;
32
- pub ( crate ) const DECRYPT_HANDLE_LEN : usize = RISTRETTO_POINT_LEN ;
33
- pub ( crate ) const PEDERSEN_COMMITMENT_LEN : usize = RISTRETTO_POINT_LEN ;
34
- const ELGAMAL_PUBKEY_LEN : usize = RISTRETTO_POINT_LEN ;
35
- const ELGAMAL_CIPHERTEXT_LEN : usize = PEDERSEN_COMMITMENT_LEN + DECRYPT_HANDLE_LEN ;
36
28
type PodAccountState = u8 ;
37
29
pub type UnixTimestamp = PodI64 ;
38
- pub type EncryptedBalance = ShadowElGamalCiphertext ;
39
- pub type DecryptableBalance = ShadowAeCiphertext ;
40
- pub type EncryptedWithheldAmount = ShadowElGamalCiphertext ;
41
-
42
- use serde:: {
43
- de:: { self , SeqAccess , Visitor } ,
44
- Deserializer , Serializer ,
45
- } ;
46
30
47
31
/// Bs58 encoded public key string. Used for storing Pubkeys in a human readable format.
48
32
/// Ideally we'd store them as is in the DB and later convert them to bs58 for display on the API.
@@ -53,19 +37,6 @@ use serde::{
53
37
/// - `Pubkey` doesn't implement something like `schemars::JsonSchema` so we can't convert them back to the rust struct either.
54
38
type PublicKeyString = String ;
55
39
56
- struct ShadowAeCiphertextVisitor ;
57
-
58
- struct ShadowElGamalCiphertextVisitor ;
59
-
60
- #[ derive( Clone , Copy , Debug , PartialEq ) ]
61
- pub struct ShadowAeCiphertext ( pub [ u8 ; AE_CIPHERTEXT_LEN ] ) ;
62
-
63
- #[ derive( Clone , Copy , Debug , PartialEq , Zeroable ) ]
64
- pub struct ShadowElGamalCiphertext ( pub [ u8 ; ELGAMAL_CIPHERTEXT_LEN ] ) ;
65
-
66
- #[ derive( Clone , Copy , Debug , Default , Zeroable , PartialEq , Eq , Serialize , Deserialize ) ]
67
- pub struct ShadowElGamalPubkey ( pub [ u8 ; ELGAMAL_PUBKEY_LEN ] ) ;
68
-
69
40
#[ derive( Clone , Copy , Debug , Default , PartialEq , Zeroable , Serialize , Deserialize ) ]
70
41
pub struct ShadowCpiGuard {
71
42
pub lock_cpi : PodBool ,
@@ -164,14 +135,14 @@ pub struct ShadowConfidentialTransferMint {
164
135
pub auditor_elgamal_pubkey : OptionalNonZeroElGamalPubkey ,
165
136
}
166
137
167
- #[ derive( Clone , Copy , Debug , Default , PartialEq , Serialize , Deserialize ) ]
138
+ #[ derive( Clone , Debug , Default , PartialEq , Serialize , Deserialize ) ]
168
139
pub struct ShadowConfidentialTransferAccount {
169
140
pub approved : PodBool ,
170
- pub elgamal_pubkey : ShadowElGamalPubkey ,
171
- pub pending_balance_lo : EncryptedBalance ,
172
- pub pending_balance_hi : EncryptedBalance ,
173
- pub available_balance : EncryptedBalance ,
174
- pub decryptable_available_balance : DecryptableBalance ,
141
+ pub elgamal_pubkey : String ,
142
+ pub pending_balance_lo : String ,
143
+ pub pending_balance_hi : String ,
144
+ pub available_balance : String ,
145
+ pub decryptable_available_balance : String ,
175
146
pub allow_confidential_credits : PodBool ,
176
147
pub allow_non_confidential_credits : PodBool ,
177
148
pub pending_balance_credit_counter : PodU64 ,
@@ -180,16 +151,16 @@ pub struct ShadowConfidentialTransferAccount {
180
151
pub actual_pending_balance_credit_counter : PodU64 ,
181
152
}
182
153
183
- #[ derive( Clone , Copy , Debug , Default , PartialEq , Zeroable , Serialize , Deserialize ) ]
154
+ #[ derive( Clone , Debug , Default , PartialEq , Serialize , Deserialize ) ]
184
155
pub struct ShadowConfidentialTransferFeeConfig {
185
156
pub authority : OptionalNonZeroPubkey ,
186
- pub withdraw_withheld_authority_elgamal_pubkey : ShadowElGamalPubkey ,
157
+ pub withdraw_withheld_authority_elgamal_pubkey : String ,
187
158
pub harvest_to_mint_enabled : PodBool ,
188
- pub withheld_amount : EncryptedWithheldAmount ,
159
+ pub withheld_amount : String ,
189
160
}
190
161
191
162
pub struct ShadowConfidentialTransferFeeAmount {
192
- pub withheld_amount : EncryptedWithheldAmount ,
163
+ pub withheld_amount : String ,
193
164
}
194
165
195
166
#[ derive( Clone , Copy , Debug , Default , PartialEq , Zeroable , Serialize , Deserialize ) ]
@@ -216,114 +187,6 @@ pub struct ShadowMetadata {
216
187
pub additional_metadata : Vec < ( String , String ) > ,
217
188
}
218
189
219
- impl Serialize for ShadowAeCiphertext {
220
- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
221
- where
222
- S : Serializer ,
223
- {
224
- serializer. serialize_bytes ( & self . 0 )
225
- }
226
- }
227
-
228
- impl < ' de > Visitor < ' de > for ShadowElGamalCiphertextVisitor {
229
- type Value = ShadowElGamalCiphertext ;
230
-
231
- fn expecting ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
232
- formatter. write_str ( "a byte array of length ELGAMAL_CIPHERTEXT_LEN" )
233
- }
234
-
235
- fn visit_bytes < E > ( self , v : & [ u8 ] ) -> Result < Self :: Value , E >
236
- where
237
- E : de:: Error ,
238
- {
239
- if v. len ( ) == ELGAMAL_CIPHERTEXT_LEN {
240
- let mut arr = [ 0u8 ; ELGAMAL_CIPHERTEXT_LEN ] ;
241
- arr. copy_from_slice ( v) ;
242
- Ok ( ShadowElGamalCiphertext ( arr) )
243
- } else {
244
- Err ( E :: invalid_length ( v. len ( ) , & self ) )
245
- }
246
- }
247
- }
248
-
249
- impl < ' de > Deserialize < ' de > for ShadowElGamalCiphertext {
250
- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
251
- where
252
- D : Deserializer < ' de > ,
253
- {
254
- deserializer. deserialize_bytes ( ShadowElGamalCiphertextVisitor )
255
- }
256
- }
257
-
258
- impl Default for ShadowElGamalCiphertext {
259
- fn default ( ) -> Self {
260
- ShadowElGamalCiphertext ( [ 0u8 ; ELGAMAL_CIPHERTEXT_LEN ] )
261
- }
262
- }
263
-
264
- impl Default for ShadowAeCiphertext {
265
- fn default ( ) -> Self {
266
- ShadowAeCiphertext ( [ 0u8 ; AE_CIPHERTEXT_LEN ] )
267
- }
268
- }
269
-
270
- impl < ' de > Visitor < ' de > for ShadowAeCiphertextVisitor {
271
- type Value = ShadowAeCiphertext ;
272
-
273
- fn expecting ( & self , formatter : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
274
- formatter. write_str ( "a byte array of length AE_CIPHERTEXT_LEN" )
275
- }
276
-
277
- fn visit_seq < A > ( self , mut seq : A ) -> Result < Self :: Value , A :: Error >
278
- where
279
- A : SeqAccess < ' de > ,
280
- {
281
- let mut arr = [ 0u8 ; AE_CIPHERTEXT_LEN ] ;
282
- for ( i, item) in arr. iter_mut ( ) . enumerate ( ) . take ( AE_CIPHERTEXT_LEN ) {
283
- * item = seq
284
- . next_element ( ) ?
285
- . ok_or ( de:: Error :: invalid_length ( i, & self ) ) ?;
286
- }
287
- Ok ( ShadowAeCiphertext ( arr) )
288
- }
289
- }
290
-
291
- impl < ' de > Deserialize < ' de > for ShadowAeCiphertext {
292
- fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
293
- where
294
- D : Deserializer < ' de > ,
295
- {
296
- deserializer. deserialize_tuple ( AE_CIPHERTEXT_LEN , ShadowAeCiphertextVisitor )
297
- }
298
- }
299
-
300
- impl Serialize for ShadowElGamalCiphertext {
301
- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
302
- where
303
- S : Serializer ,
304
- {
305
- serializer. serialize_bytes ( & self . 0 )
306
- }
307
- }
308
-
309
- impl From < AeCiphertext > for ShadowAeCiphertext {
310
- fn from ( original : AeCiphertext ) -> Self {
311
- ShadowAeCiphertext ( original. 0 )
312
- }
313
- }
314
-
315
- impl From < ElGamalCiphertext > for ShadowElGamalCiphertext {
316
- fn from ( original : ElGamalCiphertext ) -> Self {
317
- ShadowElGamalCiphertext ( original. 0 )
318
- }
319
- }
320
-
321
- impl From < ElGamalPubkey > for ShadowElGamalPubkey {
322
- fn from ( original : ElGamalPubkey ) -> Self {
323
- ShadowElGamalPubkey ( original. 0 )
324
- }
325
- }
326
-
327
190
impl From < CpiGuard > for ShadowCpiGuard {
328
191
fn from ( original : CpiGuard ) -> Self {
329
192
ShadowCpiGuard {
@@ -343,7 +206,7 @@ impl From<DefaultAccountState> for ShadowDefaultAccountState {
343
206
impl From < ConfidentialTransferFeeAmount > for ShadowConfidentialTransferFeeAmount {
344
207
fn from ( original : ConfidentialTransferFeeAmount ) -> Self {
345
208
ShadowConfidentialTransferFeeAmount {
346
- withheld_amount : original. withheld_amount . into ( ) ,
209
+ withheld_amount : original. withheld_amount . to_base58 ( ) ,
347
210
}
348
211
}
349
212
}
@@ -384,7 +247,7 @@ impl From<TokenGroup> for ShadowTokenGroup {
384
247
fn from ( original : TokenGroup ) -> Self {
385
248
ShadowTokenGroup {
386
249
update_authority : original. update_authority ,
387
- mint : bs58 :: encode ( original. mint ) . into_string ( ) ,
250
+ mint : original. mint . to_string ( ) ,
388
251
size : original. size ,
389
252
max_size : original. max_size ,
390
253
}
@@ -394,8 +257,8 @@ impl From<TokenGroup> for ShadowTokenGroup {
394
257
impl From < TokenGroupMember > for ShadowTokenGroupMember {
395
258
fn from ( original : TokenGroupMember ) -> Self {
396
259
ShadowTokenGroupMember {
397
- mint : bs58 :: encode ( original. mint ) . into_string ( ) ,
398
- group : bs58 :: encode ( original. group ) . into_string ( ) ,
260
+ mint : original. mint . to_string ( ) ,
261
+ group : original. group . to_string ( ) ,
399
262
member_number : original. member_number ,
400
263
}
401
264
}
@@ -482,11 +345,11 @@ impl From<ConfidentialTransferAccount> for ShadowConfidentialTransferAccount {
482
345
fn from ( original : ConfidentialTransferAccount ) -> Self {
483
346
ShadowConfidentialTransferAccount {
484
347
approved : original. approved ,
485
- elgamal_pubkey : original. elgamal_pubkey . into ( ) ,
486
- pending_balance_lo : original. pending_balance_lo . into ( ) ,
487
- pending_balance_hi : original. pending_balance_hi . into ( ) ,
488
- available_balance : original. available_balance . into ( ) ,
489
- decryptable_available_balance : original. decryptable_available_balance . into ( ) ,
348
+ elgamal_pubkey : original. elgamal_pubkey . to_base58 ( ) ,
349
+ pending_balance_lo : original. pending_balance_lo . to_base58 ( ) ,
350
+ pending_balance_hi : original. pending_balance_hi . to_base58 ( ) ,
351
+ available_balance : original. available_balance . to_base58 ( ) ,
352
+ decryptable_available_balance : original. decryptable_available_balance . to_base58 ( ) ,
490
353
allow_confidential_credits : original. allow_confidential_credits ,
491
354
allow_non_confidential_credits : original. allow_non_confidential_credits ,
492
355
pending_balance_credit_counter : original. pending_balance_credit_counter ,
@@ -504,9 +367,9 @@ impl From<ConfidentialTransferFeeConfig> for ShadowConfidentialTransferFeeConfig
504
367
authority : original. authority ,
505
368
withdraw_withheld_authority_elgamal_pubkey : original
506
369
. withdraw_withheld_authority_elgamal_pubkey
507
- . into ( ) ,
370
+ . to_base58 ( ) ,
508
371
harvest_to_mint_enabled : original. harvest_to_mint_enabled ,
509
- withheld_amount : original. withheld_amount . into ( ) ,
372
+ withheld_amount : original. withheld_amount . to_base58 ( ) ,
510
373
}
511
374
}
512
375
}
@@ -523,3 +386,25 @@ impl From<TokenMetadata> for ShadowMetadata {
523
386
}
524
387
}
525
388
}
389
+
390
+ trait FromBytesToBase58 {
391
+ fn to_base58 ( & self ) -> String ;
392
+ }
393
+
394
+ impl FromBytesToBase58 for ElGamalPubkey {
395
+ fn to_base58 ( & self ) -> String {
396
+ bs58:: encode ( self . 0 ) . into_string ( )
397
+ }
398
+ }
399
+
400
+ impl FromBytesToBase58 for ElGamalCiphertext {
401
+ fn to_base58 ( & self ) -> String {
402
+ bs58:: encode ( self . 0 ) . into_string ( )
403
+ }
404
+ }
405
+
406
+ impl FromBytesToBase58 for AeCiphertext {
407
+ fn to_base58 ( & self ) -> String {
408
+ bs58:: encode ( self . 0 ) . into_string ( )
409
+ }
410
+ }
0 commit comments