GitHunt
WU

wuminzhe/py-sr25519-bindings

Python bindings for the RUST implementation of the sr25519 cryptography library

py-sr25519-bindings

Python bindings for sr25519 library: https://github.com/w3f/schnorrkel

Reference to https://github.com/LocalCoinSwap/kusama-reference-implementation/tree/improve-trading-tests/bindings and https://gitlab.com/kauriid/schnorrpy/ for the initial work

Documentation

https://docs.rs/py-sr25519-bindings

Installation

Install from PyPI

pip install py-sr25519-bindings

Compile for local development

pip install -r requirements.txt
maturin develop

Build wheelhouses

pip install -r requirements.txt

# Build local OS wheelhouse
maturin build

# Build manylinux1 wheelhouse
docker build . --tag polkasource/maturin
docker run --rm -i -v $(pwd):/io polkasource/maturin build

Usage

import bip39
import sr25519

message = b"test"

# Get private and public key from seed
seed = bip39.bip39_to_mini_secret('daughter song common combine misery cotton audit morning stuff weasel flee field','')

public_key, private_key = sr25519.pair_from_seed(bytes(seed))

# Generate signature
signature = sr25519.sign(
    (public_key, private_key),
    message
)

print('Signature', signature.hex())

# Verify message with signature
if sr25519.verify(signature, message, public_key):
    print('Verified')

License

https://github.com/polkascan/py-sr25519-bindings/blob/master/LICENSE

Languages

Rust87.7%Python11.5%Shell0.7%Dockerfile0.2%

Contributors

Apache License 2.0
Created May 30, 2021
Updated March 28, 2025
wuminzhe/py-sr25519-bindings | GitHunt