hashsigs-py README

The project's README from github.com/QuipNetwork/hashsigs-py. As one markdown file: README.md.

hashsigs (Python)

Python package for WOTS+ with optional Rust acceleration from hashsigs-rs.

Installation

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

Quick Usage

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")

Development Setup

For contributors and advanced users who want to build from source:

# from the repo root
python3 -m venv .hashsigs
source .hashsigs/bin/activate
python -m pip install -U pip pytest pytest-cov

# Ensure Rust toolchain (required to build the optional extension)
# macOS: also ensure Xcode CLT: xcode-select --install
rustup --version || brew install rust
cargo --version

# Install dev deps and try to build rust extension (quote extras in zsh)
pip install -v -e '.[rust,dev]'
# Install keccak provider (required for vectors when falling back to Python)
pip install pycryptodome
# or: pip install pysha3

# Quick check the extension is present (optional)
python -c "import hashsigs._rust as m; print('rust ext ok:', m)"

# Lint + type + tests with coverage; this is the full suite
pytest -q --cov=hashsigs --cov-report=term-missing

If the Rust toolchain is not available, the above will fail on the rust-backed vector tests. See the “Test options” section for alternatives.

Test options

You can choose between three categories:

Troubleshooting

Usage example

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!")

Quick self-check (from shell)

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

Rust backend

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.

License

AGPL-3.0-or-later; see COPYING

hashsigs-py (QuipNetwork/hashsigs-py)

Searching Database…

这是什么?这是一个实现 WOTS+(Winternitz 一次性签名 Plus)的 Python 包。WOTS+ 是一种基于哈希的后量子数字签名方案,可通过 hashsigs-rs 获得可选的 Rust 加速。
这是一个独立应用,还是我要导入自己代码的库?它是一个 Python 库,安装到项目里后由你自己的代码调用;它有一个可选的 Rust 扩展用于提升性能,如果不可用则会退回纯 Python 实现。
怎么安装并试用它?用 pip 以可编辑模式安装,然后在 shell 里运行快速自检的一行命令,确认可以导入且基本操作正常;完整的开发环境安装使用 pip install -e 并附带 rust 和 dev 额外依赖,外加 pycryptodome。
使用它需要装 Rust 吗?不需要,Rust 只是为了获得最佳性能的可选项;如果检测到 Rust,包会自动构建 Rust 扩展,否则就以纯 Python 模式运行。
安装上有什么坑需要知道?在 Python 3.13/macOS 上,pysha3 依赖可能因缺少 pystrhex.h 而构建失败;解决办法是改用 pycryptodome,或者使用 Python 3.11/3.12。
WOTS+ 是什么?WOTS+(Winternitz 一次性签名 Plus)是一种基于哈希的数字签名方案,被认为能抵抗量子计算机的攻击,常用作后量子签名方案的基础构件。
怎么运行测试?测试分三个层级:完整测试(测试向量、Rust 后端、lint/类型/覆盖率)需要 keccak 和 Rust 扩展;基础层级只需要 keccak 提供程序、无需 Rust(HASHSIGSBUILDRUST=0 pytest -q -m \'not requiresrust\');最小层级不依赖 keccak,使用 hashlib.sha3_256(pytest -q -m \'not vectors\')。
如果 Rust 扩展构建失败会怎样?安装仍会成功,包会透明地回退到纯 Python 实现。
Rust 后端依赖什么?它依赖已发布的 hashsigs-rs crate(0.0.2 版本),安装时 PyO3 Python 绑定会尝试针对它进行构建。
Size
0.1 MB
Stars
11.2K
Updated
CommitAug 27
Age
1y
Commits · 90 Days