pub struct Secp256k1;
Expand description
Methods for using the ECDSA cryptographic system with the SECP256K1 elliptic curve.
Trait Implementations§
Source§impl CryptoImplementation for Secp256k1
impl CryptoImplementation for Secp256k1
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::Secp256k1;
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) = (
"0203F2D90BC50012EC7CB20B07A1B818D6863636FB1E945D17449092CFB5495E1E".into(),
"0048D93A3B5948E5F9B323BF654BFAD6E8FF75B5FCAB03C5A55AD30CB2515B461F".into(),
);
let derivation: Option<(String, String)> = match Secp256k1.derive_keypair(
decoded_seed,
validator,
) {
Ok((public, private)) => Some((public, private)),
Err(e) => match e {
XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::InvalidSignature) => None,
XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::InvalidSecret) => None,
XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::SECP256K1Error(_)) => None,
_ => None,
},
};
assert_eq!(Some(tuple), derivation);
Source§fn sign(
&self,
message_bytes: &[u8],
private_key: &str,
) -> XRPLCoreResult<Vec<u8>>
fn sign( &self, message_bytes: &[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::Secp256k1;
use xrpl::core::keypairs::exceptions::XRPLKeypairsException;
use xrpl::core::keypairs::CryptoImplementation;
use xrpl::core::exceptions::XRPLCoreException;
let message: &[u8] = "test message".as_bytes();
let private_key: &str = "00D78B9735C3F26501C7337B8A5727FD5\
3A6EFDBC6AA55984F098488561F985E23";
let signature: Vec<u8> = vec![
48, 68, 2, 32, 88, 58, 145, 201, 94, 84, 230, 166, 81, 196,
123, 236, 34, 116, 78, 11, 16, 30, 44, 64, 96, 231, 176, 143,
99, 65, 101, 125, 173, 155, 195, 238, 2, 32, 125, 20, 137,
199, 57, 93, 176, 24, 141, 58, 86, 169, 119, 236, 186, 84,
179, 111, 169, 55, 27, 64, 49, 150, 85, 177, 180, 66, 158,
51, 239, 45,
];
let signing: Option<Vec<u8>> = match Secp256k1.sign(
message,
private_key,
) {
Ok(signature) => Some(signature),
Err(e) => match e {
XRPLCoreException::XRPLKeypairsError(XRPLKeypairsException::SECP256K1Error(_)) => None,
_ => None,
},
};
assert_eq!(Some(signature), signing);
Source§fn is_valid_message(
&self,
message_bytes: &[u8],
signature: &str,
public_key: &str,
) -> bool
fn is_valid_message( &self, message_bytes: &[u8], signature: &str, public_key: &str, ) -> bool
Verifies the signature on a given message.
§Examples
§Basic usage
use xrpl::core::keypairs::Secp256k1;
use xrpl::core::keypairs::exceptions::XRPLKeypairsException;
use xrpl::core::keypairs::CryptoImplementation;
let message: &[u8] = "test message".as_bytes();
let signature: &str = "30440220583A91C95E54E6A651C47BEC\
22744E0B101E2C4060E7B08F6341657D\
AD9BC3EE02207D1489C7395DB0188D3A\
56A977ECBA54B36FA9371B40319655B1\
B4429E33EF2D";
let public_key: &str = "030D58EB48B4420B1F7B9DF55087E0E\
29FEF0E8468F9A6825B01CA2C361042D435";
assert!(Secp256k1.is_valid_message(
message,
signature,
public_key,
));
Auto Trait Implementations§
impl Freeze for Secp256k1
impl RefUnwindSafe for Secp256k1
impl Send for Secp256k1
impl Sync for Secp256k1
impl Unpin for Secp256k1
impl UnwindSafe for Secp256k1
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