pub struct Ed25519;
Expand description
Methods for using the ED25519 cryptographic system.
Trait Implementations§
Source§impl CryptoImplementation for Ed25519
impl CryptoImplementation for Ed25519
Source§fn derive_keypair(
&self,
decoded_seed: &[u8],
is_validator: bool,
) -> XRPLCoreResult<(String, String)>
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>>
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
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§
impl Freeze for Ed25519
impl RefUnwindSafe for Ed25519
impl Send for Ed25519
impl Sync for Ed25519
impl Unpin for Ed25519
impl UnwindSafe for Ed25519
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
Mutably borrows from an owned value. Read more