Struct safe_zk_token_sdk::encryption::elgamal::ElGamalKeypair
source · pub struct ElGamalKeypair {
pub public: ElGamalPubkey,
pub secret: ElGamalSecretKey,
}
Expand description
A (twisted) ElGamal encryption keypair.
The instances of the secret key are zeroized on drop.
Fields§
§public: ElGamalPubkey
The public half of this keypair.
secret: ElGamalSecretKey
The secret half of this keypair.
Implementations§
source§impl ElGamalKeypair
impl ElGamalKeypair
sourcepub fn new(signer: &dyn Signer, address: &Pubkey) -> Result<Self, SignerError>
pub fn new(signer: &dyn Signer, address: &Pubkey) -> Result<Self, SignerError>
Deterministically derives an ElGamal keypair from an Ed25519 signing key and a Safecoin address.
This function exists for applications where a user may not wish to maintin a Safecoin (Ed25519) keypair and an ElGamal keypair separately. A user may wish to solely maintain the Safecoin keypair and then derive the ElGamal keypair on-the-fly whenever encryption/decryption is needed.
For the spl token-2022 confidential extension application, the ElGamal encryption public key is specified in a token account address. A natural way to derive an ElGamal keypair is then to define it from the hash of a Safecoin keypair and a Safecoin address. However, for general hardware wallets, the signing key is not exposed in the API. Therefore, this function uses a signer to sign a pre-specified message with respect to a Safecoin address. 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 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 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 ==
.