pub struct CurvePoint { /* private fields */ }
Expand description
Represents an elliptic curve point on the secp256k1 curve It stores the compressed (and optionally also the uncompressed) form.
let a: [u8; 32] = hex!("876027a13900aad908842c3f79307cc8e96de5c3331090e91a24c315f2a8d43a");
let b: [u8; 32] = hex!("561d3fe2990e6a768b90f7d510b69e967e0922a3b61e8141398113aede8e1d3e");
let A = CurvePoint::from_exponent(&a).unwrap();
let B = CurvePoint::from_exponent(&b).unwrap();
// A_plus_B = a * G + b * G
let A_plus_B = CurvePoint::combine(&[&A, &B]);
let scalar_a: Scalar = *NonZeroScalar::<Secp256k1>::try_from(&a[..]).unwrap();
let scalar_b: Scalar = *NonZeroScalar::<Secp256k1>::try_from(&b[..]).unwrap();
// a_plus_b = (a + b) * G
let a_plus_b = CurvePoint::from_exponent(&(scalar_a + scalar_b).to_bytes()).unwrap();
// group homomorphism
// (a + b) * G = a * G + b * G
assert_eq!(A_plus_B, a_plus_b);
Implementations§
Source§impl CurvePoint
impl CurvePoint
Sourcepub const SIZE_COMPRESSED: usize = 33usize
pub const SIZE_COMPRESSED: usize = 33usize
Size of the point if serialized via CurvePoint::as_compressed
.
Sourcepub const SIZE_UNCOMPRESSED: usize = 65usize
pub const SIZE_UNCOMPRESSED: usize = 65usize
Size of the point if serialized via CurvePoint::as_uncompressed
.
Sourcepub fn to_address(&self) -> Address
pub fn to_address(&self) -> Address
Converts the uncompressed representation of the curve point to Ethereum address.
Sourcepub fn from_exponent(exponent: &[u8]) -> Result<Self>
pub fn from_exponent(exponent: &[u8]) -> Result<Self>
Creates a curve point from a non-zero scalar. The given exponent must represent a non-zero scalar and must result into a secp256k1 identity point.
Sourcepub fn into_projective_point(self) -> ProjectivePoint<Secp256k1>
pub fn into_projective_point(self) -> ProjectivePoint<Secp256k1>
Converts the curve point to a representation suitable for calculations.
Sourcepub fn as_compressed(&self) -> &EncodedPoint<Secp256k1>
pub fn as_compressed(&self) -> &EncodedPoint<Secp256k1>
Converts the curve point into a compressed form. This is a cheap operation.
Sourcepub fn as_uncompressed(&self) -> &EncodedPoint<Secp256k1>
pub fn as_uncompressed(&self) -> &EncodedPoint<Secp256k1>
Converts the curve point into an uncompressed form. This is many cases an expensive operation.
Sourcepub fn combine(summands: &[&CurvePoint]) -> CurvePoint
pub fn combine(summands: &[&CurvePoint]) -> CurvePoint
Sums all given curve points together, creating a new curve point.
Trait Implementations§
Source§impl AsRef<[u8]> for CurvePoint
impl AsRef<[u8]> for CurvePoint
Source§impl BytesRepresentable for CurvePoint
impl BytesRepresentable for CurvePoint
Source§impl Clone for CurvePoint
impl Clone for CurvePoint
Source§fn clone(&self) -> CurvePoint
fn clone(&self) -> CurvePoint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for CurvePoint
impl Debug for CurvePoint
Source§impl Default for CurvePoint
impl Default for CurvePoint
Source§impl From<&PublicKey> for CurvePoint
impl From<&PublicKey> for CurvePoint
Source§impl From<AffinePoint> for CurvePoint
impl From<AffinePoint> for CurvePoint
Source§impl From<CurvePoint> for AffinePoint
impl From<CurvePoint> for AffinePoint
Source§fn from(value: CurvePoint) -> Self
fn from(value: CurvePoint) -> Self
Source§impl From<CurvePoint> for Challenge
impl From<CurvePoint> for Challenge
Source§fn from(curve_point: CurvePoint) -> Self
fn from(curve_point: CurvePoint) -> Self
Source§impl From<PublicKey> for CurvePoint
impl From<PublicKey> for CurvePoint
Source§impl FromStr for CurvePoint
impl FromStr for CurvePoint
Source§impl PartialEq for CurvePoint
impl PartialEq for CurvePoint
Source§impl TryFrom<&[u8]> for CurvePoint
impl TryFrom<&[u8]> for CurvePoint
Source§impl TryFrom<CurvePoint> for PublicKey
impl TryFrom<CurvePoint> for PublicKey
Source§type Error = CryptoError
type Error = CryptoError
Source§impl TryFrom<HalfKeyChallenge> for CurvePoint
impl TryFrom<HalfKeyChallenge> for CurvePoint
impl Eq for CurvePoint
Auto Trait Implementations§
impl !Freeze for CurvePoint
impl RefUnwindSafe for CurvePoint
impl Send for CurvePoint
impl Sync for CurvePoint
impl Unpin for CurvePoint
impl UnwindSafe for CurvePoint
Blanket Implementations§
§impl<T, U> AsByteSlice<T> for U
impl<T, U> AsByteSlice<T> for U
fn as_byte_slice(&self) -> &[u8] ⓘ
§impl<U> AsSliceOf for U
impl<U> AsSliceOf for U
fn as_slice_of<T>(&self) -> Result<&[T], Error>where
T: FromByteSlice,
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> ToHex for Twhere
T: BytesRepresentable,
impl<T> ToHex for Twhere
T: BytesRepresentable,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)