8个版本
0.1.0-alpha.8 | 2024年7月18日 |
---|---|
0.1.0-alpha.7 | 2024年6月12日 |
0.1.0-alpha.6 | 2024年2月7日 |
0.1.0-alpha.5 | 2023年11月8日 |
0.1.0-alpha.1 | 2023年9月27日 |
#452 in Web编程
每月260次下载
22KB
269 行
Snarkify SDK
Snarkify SDK 是一个Rust库,旨在简化创建和部署ZKP证明作为无服务器服务到Snarkify无信任云的过程。
安装
要将Snarkify SDK包含到您的项目中,请在 Cargo.toml
的 [dependencies]
下添加以下行
snarkify-sdk = "0.1.0"
或者简单地运行
cargo add snarkify-sdk
快速入门
代码更改
- 在您的
src/bin
目录下创建一个名为snarkify.rs
的新文件 - 实现
ProofHandler
特性和prove
方法以创建证明 - 在主函数中调用
snarkify_sdk::run::<{YourProofHandler}>()
以下是一个基本示例,说明如何使用SDK
use std::io;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use snarkify_sdk::prover::ProofHandler;
struct MyProofHandler;
#[derive(Deserialize)]
struct MyInput {
public_input: String,
}
#[derive(Serialize)]
struct MyOutput {
proof: String,
}
#[async_trait]
impl ProofHandler for MyProofHandler {
type Input = MyInput;
type Output = MyOutput;
type Error = ();
async fn prove(data: Self::Input) -> Result<Self::Output, Self::Error> {
Ok(MyOutput {
proof: data.public_input.chars().rev().collect(),
})
}
}
fn main() -> Result<(), io::Error> {
snarkify_sdk::run::<MyProofHandler>()
}
运行 & 测试
例如,要在示例目录中运行 basic_prover
证明器,只需运行
cargo run --example basic_prover
您可以使用类似以下示例请求在本地测试证明器
curl --location --request POST 'https://127.0.0.1:8080' \
--header 'Content-Type: application/json' \
--header 'ce-specversion: 1.0' \
--header 'ce-id: abcdef123456' \
--header 'ce-source: test' \
--header 'ce-type: com.test.example' \
--data-raw '{
"public_input": "aloha"
}'
依赖项
~19–33MB
~575K SLoC