| Crates.io | solana-secp256k1-ecdsa |
| lib.rs | solana-secp256k1-ecdsa |
| version | 0.1.0 |
| created_at | 2025-03-14 12:27:09.806304+00 |
| updated_at | 2025-03-14 12:27:09.806304+00 |
| description | Sign and verify Secp256k1 ECDSA signatures in SVM |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1592156 |
| size | 39,331 |
A no_std compatible ECDSA implementation for the Secp256k1 curve, designed for use within the Solana ecosystem.
This library provides a lightweight implementation of ECDSA signatures using the Secp256k1 curve. It's designed to be compatible with no_std environments, making it suitable for embedded systems, WebAssembly modules, and other constrained environments without standard library support.
solana_secp256k1 primitivesAdd this to your Cargo.toml:
[dependencies]
solana-secp256k1-ecdsa = "0.1.0"
Enable the sign feature flag to use signature creation functionality:
[dependencies]
solana-secp256k1-ecdsa = { version = "0.1.0", features = ["sign"] }
use solana_secp256k1_ecdsa::{Secp256k1EcdsaSignature, hash::Sha256};
// Your message and private key
let message = b"Hello, Solana!";
let private_key: [u8; 32] = [/* your private key */];
// Sign the message
let signature = Secp256k1EcdsaSignature::sign::<Sha256>(message, &private_key)?;
use solana_secp256k1_ecdsa::{Secp256k1EcdsaSignature, hash::Sha256};
// Your message, ephemeral key, and private key
let message = b"Hello, Solana!";
let ephemeral_key: [u8; 32] = [/* your ephemeral key */];
let private_key: [u8; 32] = [/* your private key */];
// Sign with custom k
let signature = Secp256k1EcdsaSignature::sign_with_k::<Sha256>(
message,
&ephemeral_key,
&private_key
)?;
use solana_secp256k1_ecdsa::{Secp256k1EcdsaSignature, hash::Sha256};
use solana_secp256k1::Pubkey;
// Your message, signature, and public key
let message = b"Hello, Solana!";
let signature: Secp256k1EcdsaSignature = /* your signature */;
let public_key: Pubkey = /* your public key */;
// Verify the signature
signature.verify::<Sha256, _>(message, public_key)?;
sign_with_k, ensure your ephemeral key is truly random and never reused. Reusing or using predictable ephemeral keys can compromise your private key.normalize_s to handle signature malleability concerns. This is important for blockchain applications where transaction malleability could be an issue.Implement the Secp256k1EcdsaHash trait for custom hash algorithms:
use solana_secp256k1_ecdsa::hash::Secp256k1EcdsaHash;
struct MyCustomHash;
impl Secp256k1EcdsaHash for MyCustomHash {
fn hash(message: &[u8]) -> [u8; 32] {
// Your custom hash implementation
}
}
Use this library at your own risk.
MIT