1个不稳定版本
0.1.2 | 2020年8月27日 |
---|
#101 in #python-bindings
31KB
425 行
py-sr25519-bindings
sr25519库的Python绑定: https://github.com/w3f/schnorrkel
参考了 https://github.com/LocalCoinSwap/kusama-reference-implementation/tree/improve-trading-tests/bindings 和 https://gitlab.com/kauriid/schnorrpy/ 的初始工作
安装
从PyPI安装
pip install py-sr25519-bindings
编译本地开发版本
pip install -r requirements.txt
maturin develop
构建wheelhouse
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
使用方法
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')
许可协议
https://github.com/polkascan/py-sr25519-bindings/blob/master/LICENSE
依赖项
~7MB
~138K SLoC