zk-token-sdk: implement convert traits for elgamal ciphertexts and ristretto points (#25549)
This commit is contained in:
parent
cafa85bfbb
commit
d33cb2fa54
|
@ -1,15 +1,51 @@
|
|||
use super::pod;
|
||||
pub use target_arch::*;
|
||||
use {super::pod, crate::curve25519::ristretto::PodRistrettoPoint};
|
||||
|
||||
impl From<(pod::PedersenCommitment, pod::DecryptHandle)> for pod::ElGamalCiphertext {
|
||||
fn from((comm, decrypt_handle): (pod::PedersenCommitment, pod::DecryptHandle)) -> Self {
|
||||
fn from((commitment, handle): (pod::PedersenCommitment, pod::DecryptHandle)) -> Self {
|
||||
let mut buf = [0_u8; 64];
|
||||
buf[..32].copy_from_slice(&comm.0);
|
||||
buf[32..].copy_from_slice(&decrypt_handle.0);
|
||||
buf[..32].copy_from_slice(&commitment.0);
|
||||
buf[32..].copy_from_slice(&handle.0);
|
||||
pod::ElGamalCiphertext(buf)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pod::ElGamalCiphertext> for (pod::PedersenCommitment, pod::DecryptHandle) {
|
||||
fn from(ciphertext: pod::ElGamalCiphertext) -> Self {
|
||||
let commitment: [u8; 32] = ciphertext.0[..32].try_into().unwrap();
|
||||
let handle: [u8; 32] = ciphertext.0[32..].try_into().unwrap();
|
||||
|
||||
(
|
||||
pod::PedersenCommitment(commitment),
|
||||
pod::DecryptHandle(handle),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pod::PedersenCommitment> for PodRistrettoPoint {
|
||||
fn from(commitment: pod::PedersenCommitment) -> Self {
|
||||
PodRistrettoPoint(commitment.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PodRistrettoPoint> for pod::PedersenCommitment {
|
||||
fn from(point: PodRistrettoPoint) -> Self {
|
||||
pod::PedersenCommitment(point.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<pod::DecryptHandle> for PodRistrettoPoint {
|
||||
fn from(handle: pod::DecryptHandle) -> Self {
|
||||
PodRistrettoPoint(handle.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PodRistrettoPoint> for pod::DecryptHandle {
|
||||
fn from(point: PodRistrettoPoint) -> Self {
|
||||
pod::DecryptHandle(point.0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "solana"))]
|
||||
mod target_arch {
|
||||
use {
|
||||
|
|
Loading…
Reference in New Issue