Struct secp256k1::ellswift::ElligatorSwift
source · pub struct ElligatorSwift(/* private fields */);
Expand description
ElligatorSwift
is an encoding of a uniformly chosen point on the curve
as a 64-byte array that is indistinguishable from a uniformly random array.
This object holds two field elements u and t, which are the inputs to
the ElligatorSwift
encoding function.
Implementations§
source§impl ElligatorSwift
impl ElligatorSwift
sourcepub fn new(secret_key: SecretKey, rand: [u8; 32]) -> ElligatorSwift
pub fn new(secret_key: SecretKey, rand: [u8; 32]) -> ElligatorSwift
Create a new ElligatorSwift
object from a 64-byte array.
sourcepub fn from_array(ellswift: [u8; 64]) -> ElligatorSwift
pub fn from_array(ellswift: [u8; 64]) -> ElligatorSwift
Creates an ElligatorSwift
object from a 64-byte array.
sourcepub fn to_array(&self) -> [u8; 64]
pub fn to_array(&self) -> [u8; 64]
Returns the 64-byte array representation of this ElligatorSwift
object.
sourcepub fn from_seckey<C: Verification>(
secp: &Secp256k1<C>,
sk: SecretKey,
aux_rand: Option<[u8; 32]>,
) -> ElligatorSwift
pub fn from_seckey<C: Verification>( secp: &Secp256k1<C>, sk: SecretKey, aux_rand: Option<[u8; 32]>, ) -> ElligatorSwift
Creates the Elligator Swift encoding from a secret key, using some aux_rand if defined. This method is preferred instead of just decoding, because the private key offers extra entropy.
§Example
use secp256k1::{ellswift::ElligatorSwift, PublicKey, Secp256k1, SecretKey};
let secp = Secp256k1::new();
let sk = SecretKey::from_slice(&[1; 32]).unwrap();
let es = ElligatorSwift::from_seckey(&secp, sk, None);
sourcepub fn from_pubkey(pk: PublicKey) -> ElligatorSwift
pub fn from_pubkey(pk: PublicKey) -> ElligatorSwift
Computes the ElligatorSwift
encoding for a valid public key
§Example
use secp256k1::{ellswift::ElligatorSwift, PublicKey, Secp256k1, SecretKey};
let secp = Secp256k1::new();
let sk = SecretKey::from_slice(&[1; 32]).unwrap();
let pk = PublicKey::from_secret_key(&secp, &sk);
let es = ElligatorSwift::from_pubkey(pk);
Computes a shared secret only known by Alice and Bob. This is obtained by computing the x-only Elliptic Curve Diffie-Hellman (ECDH) shared secret between Alice and Bob.
§Example
use secp256k1::{
ellswift::{ElligatorSwift, ElligatorSwiftParty},
PublicKey, SecretKey, XOnlyPublicKey, Secp256k1,
};
use core::str::FromStr;
let secp = Secp256k1::new();
let alice_sk = SecretKey::from_str("e714e76bdd67ad9f495683c37934148f4efc25ce3f01652c8a906498339e1f3a").unwrap();
let bob_sk = SecretKey::from_str("b6c4b0e2f8c4359caf356a618cd1649d18790a1d67f7c2d1e4760e04c785db4f").unwrap();
let alice_es = ElligatorSwift::from_seckey(&secp, alice_sk, None);
let bob_es = ElligatorSwift::from_seckey(&secp, bob_sk, None);
let alice_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, alice_sk, ElligatorSwiftParty::A, None);
let bob_shared_secret = ElligatorSwift::shared_secret(alice_es, bob_es, bob_sk, ElligatorSwiftParty::B, None);
assert_eq!(alice_shared_secret, bob_shared_secret);
Computes a shared secret, just like shared_secret
, but with a custom hash function
for computing the shared secret. For compatibility with other libraries, you should
use shared_secret
instead, which is already compatible with BIP324.
The hash function takes three arguments: the shared point, and the ElligatorSwift
encodings of the two parties and returns a 32-byte shared secret.
Trait Implementations§
source§impl CPtr for ElligatorSwift
impl CPtr for ElligatorSwift
source§impl Clone for ElligatorSwift
impl Clone for ElligatorSwift
source§fn clone(&self) -> ElligatorSwift
fn clone(&self) -> ElligatorSwift
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ElligatorSwift
impl Debug for ElligatorSwift
source§impl Display for ElligatorSwift
impl Display for ElligatorSwift
source§impl FromStr for ElligatorSwift
impl FromStr for ElligatorSwift
source§impl Hash for ElligatorSwift
impl Hash for ElligatorSwift
source§impl LowerHex for ElligatorSwift
impl LowerHex for ElligatorSwift
source§impl Ord for ElligatorSwift
impl Ord for ElligatorSwift
source§fn cmp(&self, other: &ElligatorSwift) -> Ordering
fn cmp(&self, other: &ElligatorSwift) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for ElligatorSwift
impl PartialEq for ElligatorSwift
source§fn eq(&self, other: &ElligatorSwift) -> bool
fn eq(&self, other: &ElligatorSwift) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for ElligatorSwift
impl PartialOrd for ElligatorSwift
source§fn partial_cmp(&self, other: &ElligatorSwift) -> Option<Ordering>
fn partial_cmp(&self, other: &ElligatorSwift) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for ElligatorSwift
impl Eq for ElligatorSwift
impl StructuralPartialEq for ElligatorSwift
Auto Trait Implementations§
impl Freeze for ElligatorSwift
impl RefUnwindSafe for ElligatorSwift
impl Send for ElligatorSwift
impl Sync for ElligatorSwift
impl Unpin for ElligatorSwift
impl UnwindSafe for ElligatorSwift
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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)