prs-utility 是 PRS 为 Python 提供的算法工具库,包含项目中用到的消息摘要、签名算法。
Python 版本支持
支持 >= Python 3.6
安装
pip install prs-utility
使用示例
# 根据 keystore 和 password 得到私钥
import json
import prs_utility
keystore = {
"address": "758ea2601697fbd3ba6eb6774ed70b6c4cdb0ef9",
"crypto": {
"cipher": "aes-128-ctr",
"ciphertext": "92af6f6710eba271eae5ac7fec72c70d9f49215e7880a0c45d4c53e56bd7ea59",
"cipherparams": {
"iv": "13ddf95d970e924c97e4dcd29ba96520"
},
"mac": "b9d81d78f067334ee922fb2863e32c14cbc46e479eeb0acc11fb31e39256004e",
"kdf": "pbkdf2",
"kdfparams": {
"c": 262144,
"dklen": 32,
"prf": "hmac-sha256",
"salt": "79f90bb603491573e40a79fe356b88d0c7869852e43c2bbaabed44578a82bbfa"
}
},
"id": "93028e51-a2a4-4514-bc1a-94b089445f35",
"version": 3
}
password = '123123'
private_key = prs_utility.recover_private_key(
json.dumps(keystore), password
)
print('private_key:', private_key)
# 计算 hash 值
## 计算 bytes、int、bool 的 hash 值
print(prs_utility.keccak256(primitive=b'hello'))
print(prs_utility.keccak256(primitive=42))
print(prs_utility.keccak256(primitive=True))
注: 函数的第一个可选参数是 primitive,所以,可以不写该参数
print(prs_utility.keccak256(42))
## 计算 text 或 字符串 的 hash 值
print(prs_utility.keccak256(text='hello'))
with open(__file__) as fp:
content = fp.read()
file_hash = prs_utility.keccak256(text=content)
print('file hash:', file_hash)
## 计算 hex str 的 hash 值
print(prs_utility.keccak256(hexstr='0xabcd'))
# 根据 PRS 协议组合 block data, 并且使用 privateKey 进行签名
data = {
'file_hash': file_hash,
}
key_pair = prs_utility.create_key_pair()
private_key = key_pair['privateKey']
sig = prs_utility.sign_block_data(data, private_key)
print('signature:', sig)
# 生成一对新密钥
key_pair = prs_utility.create_key_pair()
print('key_pair:', key_pair)
API
prs-utility 提供了常用的加解密函数和一些用于格式转化的工具函数
$ pydoc prs_utility
Metadata
Release files for prs-utility 0.0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| prs-utility-0.0.8.tar.gz | 11.7 kB | Without provenance | Details for prs-utility-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prs_utility-0.0.8-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for prs_utility-0.0.8-py2.py3-none-any.whl |
Total release size: 18.4 kB
Release files / prs-utility-0.0.8.tar.gz
| Download URL | prs-utility-0.0.8.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ba23426171be0a7e6667cc0fcab6979a0fe498ea75bc36b3a5e86f7b599fdd8
|
|
BLAKE2b-256 checksum How to use checksums |
37049efa4a99230a8117ffa6436893189ab2454b4f447b15801986a1f6c18ff1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.1
|
Release files / prs_utility-0.0.8-py2.py3-none-any.whl
| Download URL | prs_utility-0.0.8-py2.py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
f2329954f8c895ce88dc35e2e95f9df5283b10ab0650c1e15dffb5025c47cda6
|
|
BLAKE2b-256 checksum How to use checksums |
d3138600f436f0723a3f36b02c34d8a144eccfb548da0c1818c0f4194f4c4a37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/3.7.1
|
Security for prs-utility 0.0.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.