hashsigs (Python) Python package for WOTS+ with optional Rust acceleration from hashsigs-rs. Installation bash pip install hashsigs For bes…
hashsigs (Python) Python package for WOTS+ with optional Rust acceleration from hashsigs-rs. Installation bash pip install hashsigs For bes…
Python package for WOTS+ with optional Rust acceleration from hashsigs-rs.
pip install hashsigs
For best performance, ensure you have Rust installed (the package will automatically build the Rust extension if available):
# Install Rust toolchain (optional, for better performance)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Then install hashsigs
pip install hashsigs
import hashsigs
# Create a WOTS+ instance
wots = hashsigs.WOTSPlus()
# Generate a key pair
private_key, public_key = wots.generate_key_pair()
# Sign a message
message = b"Hello, world!"
signature = wots.sign(private_key, message)
# Verify the signature
is_valid = wots.verify(public_key, message, signature)
print(f"Signature valid: {is_valid}") # True
# Check if Rust acceleration is available
try:
import hashsigs._rust
print("Using Rust acceleration")
except ImportError:
print("Using pure Python implementation")
For contributors and advanced users who want to build from source:
…
If the Rust toolchain is not available, the above will fail on the rust-backed vector tests. See the “Test options” section for alternatives.
You can choose between three categories:
All Tests (vectors + rust-backed + lint + type + coverage) — fails if keccak or rust ext are missing
Basic (pure Python functionality only; requires keccak provider, but no Rust extension)
Basic (no keccak) — internal consistency tests only using hashlib.sha3_256; no vectors
pysha3 build fails on Python 3.13 (macOS) with missing pystrhex.h
Rust extension won’t build/import
from hashsigs import WOTSPlus
# Prefer the Rust backend if available; falls back to Python keccak provider if not
wots = WOTSPlus.keccak256(prefer_rust=True)
# Derive a keypair from a 32-byte seed
seed = bytes([1]) * 32
pk, sk = wots.generate_key_pair(seed)
# Sign and verify a 32-byte message
msg = bytes([2]) * 32
sig = wots.sign(sk, msg)
assert wots.verify(pk, msg, sig)
print("Signature verifies!")
Run a one-liner to confirm the package imports, the Rust extension is available (optional), and basic operations work:
python - <<'PY'
from hashsigs import WOTSPlus
try:
import hashsigs._rust as _
print('Rust extension: available')
except Exception:
print('Rust extension: not available (falling back to Python)')
wots = WOTSPlus.keccak256(prefer_rust=True)
seed = bytes([1]) * 32
pk, sk = wots.generate_key_pair(seed)
msg = bytes([2]) * 32
sig = wots.sign(sk, msg)
print('verify:', wots.verify(pk, msg, sig))
PY
We now depend on the public crate and repository:
The Python bindings (PyO3) will attempt to build against the published crate during installation. If the build fails, the package still installs and falls back to pure Python.
AGPL-3.0-or-later; see COPYING
No open issues yet, or sync has not completed.