Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
[zk-token-sdk] Refactor zk-token-elgamal pod types (#31814)
Browse files Browse the repository at this point in the history
* 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
samkim-crypto and CriesofCarrots authored May 26, 2023
1 parent fc97b7d commit 6d28fd4
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 276 deletions.
276 changes: 0 additions & 276 deletions zk-token-sdk/src/zk_token_elgamal/pod.rs

This file was deleted.

33 changes: 33 additions & 0 deletions zk-token-sdk/src/zk_token_elgamal/pod/auth_encryption.rs
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()
}
}
43 changes: 43 additions & 0 deletions zk-token-sdk/src/zk_token_elgamal/pod/elgamal.rs
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))
}
}
Loading

0 comments on commit 6d28fd4

Please sign in to comment.