Struct solana_zk_token_sdk::encryption::elgamal::ElGamalKeypair
source · pub struct ElGamalKeypair { /* private fields */ }
Expand description
A (twisted) ElGamal encryption keypair.
The instances of the secret key are zeroized on drop.
Implementations§
source§impl ElGamalKeypair
impl ElGamalKeypair
sourcepub fn new_for_tests(public: ElGamalPubkey, secret: ElGamalSecretKey) -> Self
pub fn new_for_tests(public: ElGamalPubkey, secret: ElGamalSecretKey) -> Self
Create an ElGamal keypair from an ElGamal public key and an ElGamal secret key.
An ElGamal keypair should never be instantiated manually; ElGamalKeypair::new_rand
or
ElGamalKeypair::new_from_signer
should be used instead. This function exists to create
custom ElGamal keypairs for tests.
sourcepub fn new_from_signer(
signer: &dyn Signer,
public_seed: &[u8]
) -> Result<Self, Box<dyn Error>>
pub fn new_from_signer( signer: &dyn Signer, public_seed: &[u8] ) -> Result<Self, Box<dyn Error>>
Deterministically derives an ElGamal keypair from a Solana signer and a public seed.
This function exists for applications where a user may not wish to maintain a Solana signer and an ElGamal keypair separately. Instead, a user can derive the ElGamal keypair on-the-fly whenever encryption/decryption is needed.
For the spl-token-2022 confidential extension, the ElGamal public key is specified in a token account. A natural way to derive an ElGamal keypair is to define it from the hash of a Solana keypair and a Solana address as the public seed. However, for general hardware wallets, the signing key is not exposed in the API. Therefore, this function uses a signer to sign a public seed and the resulting signature is then hashed to derive an ElGamal keypair.
sourcepub fn new_rand() -> Self
pub fn new_rand() -> Self
Generates the public and secret keys for ElGamal encryption.
This function is randomized. It internally samples a scalar element using OsRng
.
pub fn pubkey(&self) -> &ElGamalPubkey
pub fn secret(&self) -> &ElGamalSecretKey
pub fn to_bytes(&self) -> [u8; 64]
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
sourcepub fn read_json<R: Read>(reader: &mut R) -> Result<Self, Box<dyn Error>>
pub fn read_json<R: Read>(reader: &mut R) -> Result<Self, Box<dyn Error>>
Reads a JSON-encoded keypair from a Reader
implementor
sourcepub fn read_json_file<F: AsRef<Path>>(path: F) -> Result<Self, Box<dyn Error>>
pub fn read_json_file<F: AsRef<Path>>(path: F) -> Result<Self, Box<dyn Error>>
Reads keypair from a file
Trait Implementations§
source§impl Clone for ElGamalKeypair
impl Clone for ElGamalKeypair
source§fn clone(&self) -> ElGamalKeypair
fn clone(&self) -> ElGamalKeypair
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ElGamalKeypair
impl Debug for ElGamalKeypair
source§impl<'de> Deserialize<'de> for ElGamalKeypair
impl<'de> Deserialize<'de> for ElGamalKeypair
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl EncodableKey for ElGamalKeypair
impl EncodableKey for ElGamalKeypair
fn read<R: Read>(reader: &mut R) -> Result<Self, Box<dyn Error>>
fn write<W: Write>(&self, writer: &mut W) -> Result<String, Box<dyn Error>>
fn read_from_file<F>(path: F) -> Result<Self, Box<dyn Error, Global>>where F: AsRef<Path>,
fn write_to_file<F>(&self, outfile: F) -> Result<String, Box<dyn Error, Global>>where F: AsRef<Path>,
source§impl EncodableKeypair for ElGamalKeypair
impl EncodableKeypair for ElGamalKeypair
type Pubkey = ElGamalPubkey
source§fn encodable_pubkey(&self) -> Self::Pubkey
fn encodable_pubkey(&self) -> Self::Pubkey
source§impl PartialEq<ElGamalKeypair> for ElGamalKeypair
impl PartialEq<ElGamalKeypair> for ElGamalKeypair
source§fn eq(&self, other: &ElGamalKeypair) -> bool
fn eq(&self, other: &ElGamalKeypair) -> bool
self
and other
values to be equal, and is used
by ==
.