pub struct Secp256k1KeyPair { /* private fields */ }Expand description
secp256k1 key pair for Ethereum, Bitcoin, Tron, and Ripple.
This key pair uses the secp256k1 elliptic curve, which is the standard for most major blockchain networks.
§Security
- The signing key is stored securely and is
ZeroizeOnDrop - Signatures are normalized to prevent malleability
- Recovery IDs are computed for Ethereum compatibility
§Example
use txgate_crypto::keypair::{KeyPair, Secp256k1KeyPair};
// Generate a new key pair
let keypair = Secp256k1KeyPair::generate();
// Or create from existing bytes
let secret_bytes = [0x42u8; 32]; // Use real secret in production!
let keypair = Secp256k1KeyPair::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 Ethereum address
let address = keypair.public_key().ethereum_address();
println!("Address: 0x{}", hex::encode(address));Implementations§
Source§impl Secp256k1KeyPair
impl Secp256k1KeyPair
Sourcepub fn from_secret_key(secret: &SecretKey) -> Result<Self, SignError>
pub fn from_secret_key(secret: &SecretKey) -> Result<Self, SignError>
Create a key pair from a SecretKey.
This consumes the SecretKey to ensure the key material exists
in only one place.
§Errors
Returns an error if the secret key bytes are not a valid secp256k1 scalar (e.g., zero or greater than the curve order).
§Example
use txgate_crypto::keys::SecretKey;
use txgate_crypto::keypair::{KeyPair, Secp256k1KeyPair};
let secret = SecretKey::generate();
let keypair = Secp256k1KeyPair::from_secret_key(&secret)
.expect("valid secret key");Sourcepub fn verify(&self, hash: &[u8; 32], signature: &Secp256k1Signature) -> bool
pub fn verify(&self, hash: &[u8; 32], signature: &Secp256k1Signature) -> bool
Verify a signature against a hash using this key pair’s public key.
This is primarily useful for testing. In production, verification is typically done using the public key alone.
§Arguments
hash- The 32-byte hash that was signedsignature- The signature to verify
§Returns
true if the signature is valid, false otherwise.
Trait Implementations§
Source§impl Debug for Secp256k1KeyPair
impl Debug for Secp256k1KeyPair
Source§impl KeyPair for Secp256k1KeyPair
impl KeyPair for Secp256k1KeyPair
Source§type Signature = Secp256k1Signature
type Signature = Secp256k1Signature
The signature type produced by this key pair.
Source§type PublicKey = Secp256k1PublicKey
type PublicKey = Secp256k1PublicKey
The public key type for this key pair.
Source§fn from_bytes(bytes: [u8; 32]) -> Result<Self, SignError>
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
fn public_key(&self) -> &Self::PublicKey
Get the public key.
Auto Trait Implementations§
impl Freeze for Secp256k1KeyPair
impl RefUnwindSafe for Secp256k1KeyPair
impl Send for Secp256k1KeyPair
impl Sync for Secp256k1KeyPair
impl Unpin for Secp256k1KeyPair
impl UnwindSafe for Secp256k1KeyPair
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