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 for ElGamalKeypair
impl PartialEq for ElGamalKeypair
Source§impl Serialize for ElGamalKeypair
impl Serialize for ElGamalKeypair
Source§impl Zeroize for ElGamalKeypair
impl Zeroize for ElGamalKeypair
impl Eq for ElGamalKeypair
impl StructuralPartialEq for ElGamalKeypair
Auto Trait Implementations§
impl Freeze for ElGamalKeypair
impl RefUnwindSafe for ElGamalKeypair
impl Send for ElGamalKeypair
impl Sync for ElGamalKeypair
impl Unpin for ElGamalKeypair
impl UnwindSafe for ElGamalKeypair
Blanket Implementations§
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, _digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> AbiEnumVisitor for T
impl<T> AbiEnumVisitor for T
default fn visit_for_abi( &self, digester: &mut AbiDigester, ) -> Result<AbiDigester, DigestError>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more