跳转到主要内容

Zenroom for Python:Zenroom库的Python绑定。

项目描述

在Python3中使用Zenroom


Zenroom

zenroom.py 🐍
A Python3 wrapper of Zenroom, a secure and small virtual machine for crypto language processing



Build status Code coverage PyPI


This library attempts to provide a very simple wrapper around the Zenroom (https://zenroom.dyne.org/) crypto virtual machine developed as part of the DECODE project (https://decodeproject.eu/), that aims to make the Zenroom virtual machine easier to call from normal Python code.

Zenroom itself does have good cross platform functionality, so if you are interested in finding out more about the functionalities offered by Zenroom, then please visit the website linked to above to find out more.


💾 安装

pip install zenroom

注意 - 上述命令尝试安装zenroom包,将Zenroom VM作为预编译的二进制文件拉入,因此只能在Linux和macOS机器上工作。

对于边缘(master分支的最新提交)版本,请运行

pip install zenroom --pre

The zenroom package is just a wrapper around the zencode-exec utility. You also need to install zencode-exec, you can download if from the official releases on github

下载后,您需要将其移动到您的路径中的某个位置

sudo cp zencode-exec /usr/local/bin/

警告:在Mac OS上,可执行文件是 zencode-exec.command,您需要将其链接到 zencode-exec

sudo cp zencode-exec.command /usr/local/bin/
cd /usr/local/bin
sudo ln -s zencode-exec.command zencode-exec

🎮 使用

暴露了两个主要调用,一个用于运行 zencode,另一个用于 zenroom 脚本

如果您不知道 zencode 是什么,您可以从此博客文章开始 https://decodeproject.eu/blog/smart-contracts-english-speaker 官方文档可在 https://dev.zenroom.org/zencode/ 查找

https://decodeproject.eu/ 可以找到一组关于 zencode 合同的好例子

🐍 Python 包装器

包装器公开了两个简单的调用

  • zenroom_exec
  • zencode_exec

如名称所示,是执行 zenroom(lua 脚本)和 zencode 的两种方法。

参数

两个函数都接受相同的参数

  • script 字符串 要执行的 lua 脚本或 zencode 脚本
  • keys 字符串 可选的密钥字符串,如 zenroom 文档中所述,用于执行 此处
  • data 字符串 可选的数据字符串,如 zenroom 文档中所述,用于执行 此处
  • conf 字符串 可选的 conf 字符串,根据 zen_config 此处

返回值

两个函数都返回相同的对象结果 ZenResult,该对象有两个属性

  • stdout 字符串 包含脚本执行的 stdout
  • stderr 字符串 包含脚本执行的 stderr
示例

zencode_exec(script, keys=None, data=None, conf=None) 的示例使用

from zenroom import zenroom

contract = """Scenario ecdh: Create a keypair"
Given that I am known as 'identifier'
When I create the keypair
Then print my data
"""

result = zenroom.zencode_exec(contract)
print(result.output)

zenroom_exec(script, keys=None, data=None, conf=None) 的示例使用

from zenroom import zenroom

script = "print('Hello world')"
result = zenroom.zenroom_exec(script)

print(result.output)

zencode_exec 调用相同,应用了相同的参数和相同的结果。


📋 测试

测试使用pytest进行,只需运行

python setup.py test

zenroom_test.py文件中,您可以找到更多包装器的使用示例


🌐 链接

https://decodeproject.eu/

https://zenroom.org/

https://dev.zenroom.org/

😍 致谢

版权所有(C)2018-2022,由阿姆斯特丹Dyne.org基金会

最初由Sam Mulube设计和编写。

由Puria Nafisi Azizi设计、编写和维护。

由Danilo Spinella和David Dashyan改写。

由欧盟委员会资助的项目该项目得到欧盟委员会Horizon 2020研究与创新计划的资助,项目编号732546(DECODE)。

👥 贡献

请首先查看Dyne.org - 贡献者许可协议,然后

  1. 🔀 FORK IT
  2. 创建您的功能分支 git checkout -b feature/branch
  3. 提交您的更改 git commit -am 'Add some fooBar'
  4. 推送到分支 git push origin feature/branch
  5. 创建新的Pull Request gh pr create -f
  6. 🙏 感谢

💼 许可证

  Zenroom.py - a python wrapper of zenroom
  Copyright (c) 2018-2022 Dyne.org foundation, Amsterdam

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU Affero General Public License as
  published by the Free Software Foundation, either version 3 of the
  License, or (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU Affero General Public License for more details.

  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <https://gnu.ac.cn/licenses/>.

项目详情


发布历史 发布通知 | RSS 源

下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

zenroom-4.0.0.tar.gz (6.6 kB 查看哈希值)

上传时间

由以下支持