Skip to main content

Module keypair

Module keypair 

Source
Expand description

Cryptographic key pair traits and implementations.

This module provides the KeyPair trait for abstracting over different elliptic curve key pairs, and implementations for specific curves.

§Supported Curves

§Example

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

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

// Get the public key
let pubkey = keypair.public_key();
println!("Compressed: {} bytes", pubkey.compressed().len());

// Get Ethereum address
let eth_address = pubkey.ethereum_address();
println!("Ethereum address: 0x{}", hex::encode(eth_address));

// Sign a message hash
let hash = [0u8; 32]; // In practice, this would be a real hash
let signature = keypair.sign(&hash).expect("signing failed");
println!("Signature: {} bytes", signature.as_ref().len());

Structs§

Ed25519KeyPair
Ed25519 key pair for Solana and other ed25519-based chains.
Ed25519PublicKey
Wrapper for ed25519 public keys.
Ed25519Signature
Wrapper for ed25519 signatures.
Secp256k1KeyPair
secp256k1 key pair for Ethereum, Bitcoin, Tron, and Ripple.
Secp256k1PublicKey
Wrapper for secp256k1 public keys.
Secp256k1Signature
Wrapper for secp256k1 ECDSA signatures.

Traits§

KeyPair
Trait for cryptographic key pairs.