Struct Ed25519

Source
pub struct Ed25519;
Expand description

Methods for using the ED25519 cryptographic system.

Trait Implementations§

Source§

impl CryptoImplementation for Ed25519

Source§

fn derive_keypair( &self, decoded_seed: &[u8], is_validator: bool, ) -> XRPLCoreResult<(String, String)>

Derives a key pair for use with the XRP Ledger from a seed value.

§Examples
§Basic usage
use xrpl::core::keypairs::Ed25519;
use xrpl::core::keypairs::exceptions::XRPLKeypairsException;
use xrpl::core::keypairs::CryptoImplementation;
use xrpl::core::exceptions::XRPLCoreException;

let decoded_seed: &[u8] = &[
    207, 45, 227, 120, 251, 221, 126, 46,
    232, 125, 72, 109, 251, 90, 123, 255
];
let validator: bool = false;
let tuple: (String, String) = (
    "ED60292139838CB86E719134F848F055057CA5BDA61F5A529729F1697502D53E1C".into(),
    "ED009F66528611A0D400946A01FA01F8AF4FF4C1D0C744AE3F193317DCA77598F1".into(),
);

let derivation: Option<(String, String)> = match Ed25519.derive_keypair(
    decoded_seed,
    validator,
) {
    Ok((public, private)) => Some((public, private)),
    Err(e) => match e {
        XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::InvalidSignature) => None,
        XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::ED25519Error) => None,
        XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::UnsupportedValidatorAlgorithm { expected: _ }) => None,
        _ => None,
    },
};

assert_eq!(Some(tuple), derivation);
Source§

fn sign(&self, message: &[u8], private_key: &str) -> XRPLCoreResult<Vec<u8>>

Signs a message using a given private key.

  • message - Text about foo.
  • private_key - Text about bar.
§Examples
§Basic usage
use xrpl::core::keypairs::Ed25519;
use xrpl::core::keypairs::exceptions::XRPLKeypairsException;
use xrpl::core::keypairs::CryptoImplementation;

let message: &[u8] = "test message".as_bytes();
let private_key: &str = "EDB4C4E046826BD26190D09715FC31F4E\
                         6A728204EADD112905B08B14B7F15C4F3";
let signature: Vec<u8> = vec![
    203, 25, 158, 27, 253, 78, 61, 170, 16, 94, 72, 50, 238, 223,
    163, 100, 19, 225, 244, 66, 5,228, 239, 185, 226, 126, 130, 96,
    68, 194, 30, 62, 46, 132, 139, 188, 129, 149, 232, 149, 155,
    173, 248, 135, 89, 155, 115, 16, 173, 27, 112, 71, 239, 17,
    182, 130, 224, 208, 104, 247, 55,73, 117, 14,
];

let signing: Option<Vec<u8>> = Some(Ed25519.sign(
    message,
    private_key,
).unwrap());

assert_eq!(Some(signature), signing);
Source§

fn is_valid_message( &self, message: &[u8], signature: &str, public_key: &str, ) -> bool

Verifies the signature on a given message.

§Examples
§Basic usage
use xrpl::core::keypairs::Ed25519;
use xrpl::core::keypairs::exceptions::XRPLKeypairsException;
use xrpl::core::keypairs::CryptoImplementation;

let message: &[u8] = "test message".as_bytes();
let signature: &str = "CB199E1BFD4E3DAA105E4832EEDFA3641\
                       3E1F44205E4EFB9E27E826044C21E3E2E\
                       848BBC8195E8959BADF887599B7310AD1\
                       B7047EF11B682E0D068F73749750E";
let public_key: &str = "ED01FA53FA5A7E77798F882ECE20B1AB\
                        C00BB358A9E55A202D0D0676BD0CE37A63";

assert!(Ed25519.is_valid_message(
    message,
    signature,
    public_key,
));

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
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,