Struct ElligatorSwift
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§
§impl ElligatorSwift
impl ElligatorSwift
pub 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.
pub fn from_array(ellswift: [u8; 64]) -> ElligatorSwift
pub fn from_array(ellswift: [u8; 64]) -> ElligatorSwift
Creates an ElligatorSwift
object from a 64-byte array.
pub fn to_array(&self) -> [u8; 64]
pub fn to_array(&self) -> [u8; 64]
Returns the 64-byte array representation of this ElligatorSwift
object.
pub fn from_seckey<C>(
secp: &Secp256k1<C>,
sk: SecretKey,
aux_rand: Option<[u8; 32]>,
) -> ElligatorSwiftwhere
C: Verification,
pub fn from_seckey<C>(
secp: &Secp256k1<C>,
sk: SecretKey,
aux_rand: Option<[u8; 32]>,
) -> ElligatorSwiftwhere
C: Verification,
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);
pub 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§
§impl CPtr for ElligatorSwift
impl CPtr for ElligatorSwift
type Target = u8
fn as_mut_c_ptr(&mut self) -> *mut <ElligatorSwift as CPtr>::Target
fn as_c_ptr(&self) -> *const <ElligatorSwift as CPtr>::Target
§impl Clone for ElligatorSwift
impl Clone for ElligatorSwift
§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 more