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]
into()
insteadpub fn from_bytes(bytes: &[u8]) -> Option<Self>
try_from()
insteadSourcepub 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>>
fn write_to_file<F>(&self, outfile: F) -> Result<String, Box<dyn Error>>
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 From<&ElGamalKeypair> for [u8; 64]
impl From<&ElGamalKeypair> for [u8; 64]
Source§fn from(keypair: &ElGamalKeypair) -> Self
fn from(keypair: &ElGamalKeypair) -> Self
Source§impl From<ElGamalKeypair> for [u8; 64]
impl From<ElGamalKeypair> for [u8; 64]
Source§fn from(keypair: ElGamalKeypair) -> Self
fn from(keypair: ElGamalKeypair) -> Self
Source§impl PartialEq for ElGamalKeypair
impl PartialEq for ElGamalKeypair
Source§impl SeedDerivable for ElGamalKeypair
impl SeedDerivable for ElGamalKeypair
fn from_seed(seed: &[u8]) -> Result<Self, Box<dyn Error>>
fn from_seed_and_derivation_path( _seed: &[u8], _derivation_path: Option<DerivationPath>, ) -> Result<Self, Box<dyn Error>>
fn from_seed_phrase_and_passphrase( seed_phrase: &str, passphrase: &str, ) -> Result<Self, Box<dyn Error>>
Source§impl Serialize for ElGamalKeypair
impl Serialize for ElGamalKeypair
Source§impl TryFrom<&[u8]> for ElGamalKeypair
impl TryFrom<&[u8]> 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> 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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