hopr_crypto_types::types

Struct CurvePoint

Source
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

Source

pub const SIZE_COMPRESSED: usize = 33usize

Size of the point if serialized via CurvePoint::as_compressed.

Source

pub const SIZE_UNCOMPRESSED: usize = 65usize

Size of the point if serialized via CurvePoint::as_uncompressed.

Source

pub fn to_address(&self) -> Address

Converts the uncompressed representation of the curve point to Ethereum address.

Source

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.

Source

pub fn into_projective_point(self) -> ProjectivePoint<Secp256k1>

Converts the curve point to a representation suitable for calculations.

Source

pub fn as_compressed(&self) -> &EncodedPoint<Secp256k1>

Converts the curve point into a compressed form. This is a cheap operation.

Source

pub fn as_uncompressed(&self) -> &EncodedPoint<Secp256k1>

Converts the curve point into an uncompressed form. This is many cases an expensive operation.

Source

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

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl BytesRepresentable for CurvePoint

Source§

const SIZE: usize = 33usize

Size of the encoded byte array.
§

fn into_boxed(self) -> Box<[u8]>

Convenience function to copy this type’s binary representation into a Box.
Source§

impl Clone for CurvePoint

Source§

fn clone(&self) -> CurvePoint

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CurvePoint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CurvePoint

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<&PublicKey> for CurvePoint

Source§

fn from(pubkey: &PublicKey) -> Self

Converts to this type from the input type.
Source§

impl From<AffinePoint> for CurvePoint

Source§

fn from(affine: AffinePoint) -> Self

Converts to this type from the input type.
Source§

impl From<CurvePoint> for AffinePoint

Source§

fn from(value: CurvePoint) -> Self

Converts to this type from the input type.
Source§

impl From<CurvePoint> for Challenge

Source§

fn from(curve_point: CurvePoint) -> Self

Converts to this type from the input type.
Source§

impl From<PublicKey> for CurvePoint

Source§

fn from(pubkey: PublicKey) -> Self

Converts to this type from the input type.
Source§

impl FromStr for CurvePoint

Source§

type Err = CryptoError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for CurvePoint

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for CurvePoint

Source§

type Error = GeneralError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<CurvePoint> for PublicKey

Source§

type Error = CryptoError

The type returned in the event of a conversion error.
Source§

fn try_from(value: CurvePoint) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<HalfKeyChallenge> for CurvePoint

Source§

type Error = GeneralError

The type returned in the event of a conversion error.
Source§

fn try_from(value: HalfKeyChallenge) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for CurvePoint

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T, U> AsByteSlice<T> for U
where T: ToByteSlice, U: AsRef<[T]> + ?Sized,

§

fn as_byte_slice(&self) -> &[u8]

§

impl<U> AsSliceOf for U
where U: AsRef<[u8]> + ?Sized,

§

fn as_slice_of<T>(&self) -> Result<&[T], Error>
where T: FromByteSlice,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToHex for T
where T: BytesRepresentable,

§

fn to_hex(&self) -> String

Hexadecimal representation of this type.
§

fn from_hex(str: &str) -> Result<T, GeneralError>

Tries to parse the type from the hexadecimal representation.
Source§

impl<T> ToHex for T
where T: AsRef<[u8]>,

Source§

fn encode_hex<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Lower case letters are used (e.g. f9b4ca)
Source§

fn encode_hex_upper<U>(&self) -> U
where U: FromIterator<char>,

Encode the hex strict representing self into the result. Upper case letters are used (e.g. F9B4CA)
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> JsonSchemaMaybe for T