The PodSigner trait was taking `&mut self` in the `sign` method, but the signer doesn't need mutation in the Shcnorr implementation. Remove the `mut`. Previously the PodProver trait was also taking `&mut self` in the `prove` method, and we had many tests creating a `mut Prover/mut MockProver`. Remove all those `mut`. Breaking change: `PodSigner` trait method `sign` replaces `&mut self` by `&self`
44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
//! Simple example of building a signed pod and verifying it
|
|
//!
|
|
//! Run: `cargo run --release --example signed_pod`
|
|
use std::collections::HashSet;
|
|
|
|
use pod2::{
|
|
backends::plonky2::{primitives::ec::schnorr::SecretKey, signedpod::Signer},
|
|
frontend::SignedPodBuilder,
|
|
middleware::{containers::Set, Params, Value},
|
|
};
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
let params = Params::default();
|
|
|
|
// Create a schnorr key pair to sign the pod
|
|
let sk = SecretKey::new_rand();
|
|
let pk = sk.public_key();
|
|
println!("Public key: {}\n", pk);
|
|
|
|
let signer = Signer(sk);
|
|
|
|
// Build the signed pod
|
|
let mut builder = SignedPodBuilder::new(¶ms);
|
|
// The values can be String, i64, bool, Array, Set, Dictionary, ...
|
|
builder.insert("name", "Alice");
|
|
builder.insert("lucky_number", 42);
|
|
builder.insert("human", true);
|
|
let friends_set: HashSet<Value> = ["Bob", "Charlie", "Dave"]
|
|
.into_iter()
|
|
.map(Value::from)
|
|
.collect();
|
|
builder.insert(
|
|
"friends",
|
|
Set::new(params.max_merkle_proofs_containers, friends_set)?,
|
|
);
|
|
|
|
// Sign the pod and verify it
|
|
let pod = builder.sign(&signer)?;
|
|
pod.verify()?;
|
|
|
|
println!("{}", pod);
|
|
|
|
Ok(())
|
|
}
|