Skip to main content

Ed25519KeyPair

Struct Ed25519KeyPair 

Source
pub struct Ed25519KeyPair { /* private fields */ }
Expand description

Ed25519 key pair for Solana and other ed25519-based chains.

This key pair uses the ed25519 elliptic curve, which is the standard for Solana and some other blockchain networks.

§Security

  • The signing key is stored securely using ed25519_dalek::SigningKey
  • The signing key implements Zeroize and ZeroizeOnDrop, ensuring secret material is automatically zeroed when dropped (the “zeroize” feature is explicitly enabled in the workspace Cargo.toml)
  • Debug output does not expose the private key
  • Uses ed25519-dalek for cryptographic operations

§Example

use txgate_crypto::keypair::{KeyPair, Ed25519KeyPair};

// Generate a new key pair
let keypair = Ed25519KeyPair::generate();

// Or create from existing bytes
let secret_bytes = [0x42u8; 32]; // Use real secret in production!
let keypair = Ed25519KeyPair::from_bytes(secret_bytes)
    .expect("valid secret key");

// Sign a message hash
let hash = [0u8; 32]; // Use real hash in production!
let signature = keypair.sign(&hash).expect("signing succeeded");

// Get Solana address
let address = keypair.public_key().solana_address();
println!("Solana address: {address}");

Implementations§

Source§

impl Ed25519KeyPair

Source

pub fn from_secret_key(secret: &SecretKey) -> Result<Self, SignError>

Create a key pair from a SecretKey.

§Errors

Returns an error if the secret key bytes are not valid.

§Example
use txgate_crypto::keys::SecretKey;
use txgate_crypto::keypair::{KeyPair, Ed25519KeyPair};

let secret = SecretKey::generate();
let keypair = Ed25519KeyPair::from_secret_key(&secret)
    .expect("valid secret key");
Source

pub fn verify(&self, hash: &[u8; 32], signature: &Ed25519Signature) -> bool

Verify a signature against a hash using this key pair’s public key.

§Arguments
  • hash - The 32-byte hash that was signed
  • signature - The signature to verify
§Returns

true if the signature is valid, false otherwise.

Trait Implementations§

Source§

impl Debug for Ed25519KeyPair

Source§

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

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

impl KeyPair for Ed25519KeyPair

Source§

type Signature = Ed25519Signature

The signature type produced by this key pair.
Source§

type PublicKey = Ed25519PublicKey

The public key type for this key pair.
Source§

fn generate() -> Self

Generate a new random key pair. Read more
Source§

fn from_bytes(bytes: [u8; 32]) -> Result<Self, SignError>

Create a key pair from raw secret key bytes. Read more
Source§

fn public_key(&self) -> &Self::PublicKey

Get the public key.
Source§

fn sign(&self, hash: &[u8; 32]) -> Result<Self::Signature, SignError>

Sign a 32-byte message hash. Read more

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, 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
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