This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[zk-token-sdk] Refactor
zk-token-elgamal
pod types (#31814)
* move `pod.rs` to separate submodule * refactor `ElGamalCiphertext` and `ElGamalPubkey` to separate submodule * refactor `PedersenCommitment` and `DecryptHandle` to separate submodule * refactor pod sigma proof types to separate submodule * refactor pod range proof types to separate submodule * refactor `AeCiphertext` into a separate submodule * refactor instruction-related pod types to separate submodule * Apply suggestions from code review Co-authored-by: Tyera <[email protected]> --------- Co-authored-by: Tyera <[email protected]>
- Loading branch information
1 parent
fc97b7d
commit 6d28fd4
Showing
8 changed files
with
314 additions
and
276 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use { | ||
crate::zk_token_elgamal::pod::{Pod, Zeroable}, | ||
base64::{prelude::BASE64_STANDARD, Engine}, | ||
std::fmt, | ||
}; | ||
|
||
/// Serialization for AeCiphertext | ||
#[derive(Clone, Copy, PartialEq, Eq)] | ||
#[repr(transparent)] | ||
pub struct AeCiphertext(pub [u8; 36]); | ||
|
||
// `AeCiphertext` is a Pod and Zeroable. | ||
// Add the marker traits manually because `bytemuck` only adds them for some `u8` arrays | ||
unsafe impl Zeroable for AeCiphertext {} | ||
unsafe impl Pod for AeCiphertext {} | ||
|
||
impl fmt::Debug for AeCiphertext { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{:?}", self.0) | ||
} | ||
} | ||
|
||
impl fmt::Display for AeCiphertext { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", BASE64_STANDARD.encode(self.0)) | ||
} | ||
} | ||
|
||
impl Default for AeCiphertext { | ||
fn default() -> Self { | ||
Self::zeroed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use { | ||
crate::zk_token_elgamal::pod::{Pod, Zeroable}, | ||
base64::{prelude::BASE64_STANDARD, Engine}, | ||
std::fmt, | ||
}; | ||
|
||
#[derive(Clone, Copy, Pod, Zeroable, PartialEq, Eq)] | ||
#[repr(transparent)] | ||
pub struct ElGamalCiphertext(pub [u8; 64]); | ||
|
||
impl fmt::Debug for ElGamalCiphertext { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{:?}", self.0) | ||
} | ||
} | ||
|
||
impl fmt::Display for ElGamalCiphertext { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", BASE64_STANDARD.encode(self.0)) | ||
} | ||
} | ||
|
||
impl Default for ElGamalCiphertext { | ||
fn default() -> Self { | ||
Self::zeroed() | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Default, Pod, Zeroable, PartialEq, Eq)] | ||
#[repr(transparent)] | ||
pub struct ElGamalPubkey(pub [u8; 32]); | ||
|
||
impl fmt::Debug for ElGamalPubkey { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{:?}", self.0) | ||
} | ||
} | ||
|
||
impl fmt::Display for ElGamalPubkey { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", BASE64_STANDARD.encode(self.0)) | ||
} | ||
} |
Oops, something went wrong.