Chia-rs

0.42.0 · active · verified Wed Apr 15

The `chia-rs` library provides high-performance Python bindings for core Chia blockchain primitives implemented in Rust, including consensus rules, protocol message types, and cryptography components. It offers efficient operations crucial for Chia development. The current version is 0.42.0. The library maintains a frequent release cadence, often incorporating updates related to Chia blockchain soft forks and performance enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a BLS private key, derive its public key, sign a message, and verify the signature using the `chia-rs` library. This showcases fundamental cryptographic operations built into `chia-rs`.

import os
from chia_rs import PrivateKey, G1Element, G2Element

# Generate a random private key (seed should be truly random in production)
private_key = PrivateKey.from_seed(os.urandom(32))
print(f"Private Key (G1 Element Hex): {private_key.get_g1().serialize().hex()}")

# Derive the corresponding public key (G1Element)
public_key = private_key.get_g1()
print(f"Public Key (G1Element Hex): {public_key.serialize().hex()}")

# Sign a message
message = b"Hello, Chia blockchain!"
signature = private_key.sign(message)
print(f"Signature (G2Element Hex): {signature.serialize().hex()}")

# Verify the signature
is_valid = signature.verify(public_key, message)
print(f"Signature Valid: {is_valid}")

view raw JSON →