Skip to content

About

A lightweight Rust tool for signing messages with Casper Network secret keys and verifying signatures.

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

Casper Sign & Verify

A lightweight Rust tool for signing messages with Casper Network validator keys and verifying signatures. This tool replaces the Python-based casper-testnet-validator-identification with a modern, fast Rust implementation that supports both Ed25519 and Secp256k1 key types.

Note: This tool was developed using AI assistance. While it has been tested and verified to work correctly with Casper Network keys, please review the source code and test thoroughly in your environment before using in production.

Features

Dual Key Algorithm Support: Seamlessly work with both Ed25519 (algorithm tag 01) and Secp256k1 (algorithm tag 02) keys. The tool automatically detects the key type from PEM files.

Modern Rust Implementation: Built on the proven casper-types library from the Casper ecosystem, providing fast, secure cryptographic operations with minimal dependencies.

Drop-in Replacement: Output format exactly matches the original Python tool, enabling seamless migration without script modifications.

Minimal Dependencies: Uses only essential crates (casper-types, hex, clap, anyhow), avoiding unnecessary bloat from the full casper-client-rs.

Installation

From Source

Ensure you have Rust installed (version 1.56 or later). If not, install it from https://rustup.rs/.

git clone https://github.com/yourusername/casper-sign-verify.git
cd casper-sign-verify
cargo build --release

The binary will be available at target/release/casper-sign-verify.

Copy to System Path (Optional)

sudo cp target/release/casper-sign-verify /usr/local/bin/

Usage

Sign a Message

Sign a message using your validator secret key:

casper-sign-verify sign -m "your-email@example.com" -k /path/to/secret_key.pem

Output:

Public Key:
 01abcd1234...
Message:
 your-email@example.com
Signature:
 ef0123456789...

Parameters:

  • -m, --message <MESSAGE>: The message to sign (required)
  • -k, --key <PATH>: Path to the secret key PEM file (optional, defaults to /etc/casper/validator_keys/secret_key.pem)

Verify a Signature

Verify that a signature is valid for a given message:

casper-sign-verify verify -m "your-email@example.com" -s "ef0123456789..." -k "01abcd1234..."

Output on Success:

Public Key:
 01abcd1234...
Message:
 your-email@example.com
Signature:
 ef0123456789...
Verified!

Output on Failure:

Public Key:
 01abcd1234...
Message:
 your-email@example.com
Signature:
 ef0123456789...
Verification failed!

Parameters:

  • -m, --message <MESSAGE>: The message that was signed (required)
  • -s, --signature <SIGNATURE>: The signature in hex format (required)
  • -k, --key <PUBLIC_KEY_HEX>: Public key in hex format with algorithm prefix (optional, can read from /etc/casper/validator_keys/public_key_hex if not provided)

Key Formats

Algorithm Prefixes

The tool uses standard Casper Network algorithm prefixes in hex-encoded public keys:

Algorithm Prefix
Ed25519 01
Secp256k1 02

Example Public Keys

Ed25519: 010204715db766ec022b354ac5c5e1cf0aafa2c5292d8576b9323cec7f0918421f

Secp256k1: 02abcd1234... (33 bytes after prefix)

Key File Formats

Secret Key: PEM-encoded PKCS#8 format (standard output from casper-client-rs keygen)

Public Key: PEM-encoded SubjectPublicKeyInfo format

Public Key Hex: Raw hex string with algorithm prefix prepended (no newlines)

Comparison with Original Python Tool

Feature Python Version Rust Version
Ed25519 Support ✓ ✓
Secp256k1 Support ✗ ✓
Performance Moderate Fast
Dependencies Python 3 + cryptography Rust + minimal crates
Maintenance Deprecated Active
Output Format Identical Identical

Migration from Python Tool

The Rust version is designed as a drop-in replacement. Simply replace the Python scripts with the Rust binary:

Before (Python):

./sign.py -m "email@example.com"
./verify.py -m "email@example.com" -s "signature_hex"

After (Rust):

casper-sign-verify sign -m "email@example.com"
casper-sign-verify verify -m "email@example.com" -s "signature_hex"

Building from Source

Prerequisites

  • Rust 1.56+ (install from https://rustup.rs/)
  • C toolchain (for building cryptographic libraries)

Build Steps

# Clone the repository
git clone https://github.com/yourusername/casper-sign-verify.git
cd casper-sign-verify

# Build release binary
cargo build --release

# The binary is at target/release/casper-sign-verify

Running Tests

# Run all tests
cargo test

# Run with verbose output
cargo test -- --nocapture

Error Handling

The tool provides clear error messages for common issues:

Missing Key File:

Error: Couldn't access your private key at this location: /path/to/key
Please make sure your secret_key.pem file is at the given location...

Invalid Key Format:

Error: Failed to read secret key from /path/to/key

Invalid Signature Format:

Error: Invalid hex string for signature

Verification Failure:

Verification failed!

Architecture

The tool is organized into modular components:

  • main.rs: CLI entry point and argument parsing using clap
  • sign.rs: Message signing functionality
  • verify.rs: Signature verification functionality
  • key_utils.rs: Key loading, formatting, and parsing utilities

All cryptographic operations are delegated to the battle-tested casper-types library, which provides both Ed25519 and Secp256k1 support.

Dependencies

Crate Version Purpose
casper-types 7.0.0 Cryptographic operations and key types
clap 4.5 Command-line argument parsing
hex 0.4.3 Hex encoding/decoding
anyhow 1.0.81 Error handling

Performance

The Rust implementation is significantly faster than the Python version:

  • Signing: ~1-2ms per operation
  • Verification: ~2-3ms per operation
  • Binary Size: ~8MB (release build, stripped)

Security Considerations

  • Secret keys are never logged or displayed
  • Signatures are validated using constant-time comparison
  • All cryptographic operations use industry-standard algorithms from casper-types
  • The tool does not store any sensitive data in memory longer than necessary

License

Apache License 2.0 (same as Casper Network ecosystem projects)

Contributing

Contributions are welcome! Please open issues or pull requests on the repository.

Support

For issues or questions:

  1. Check the Casper Network documentation
  2. Review the casper-types documentation
  3. Open an issue on the repository

Changelog

Version 0.1.0 (Initial Release)

  • Full support for Ed25519 and Secp256k1 keys
  • Sign and verify subcommands
  • Drop-in replacement for Python tool
  • Comprehensive error handling
  • Minimal dependencies

About

A lightweight Rust tool for signing messages with Casper Network secret keys and verifying signatures.

Topics

Resources

Code of conduct

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages