chore: add statement and KV metadata to frontend PODs (#117)
* Add statement and KV metadata to frontend PODs * Code review
This commit is contained in:
parent
02ec7c311b
commit
6627b46819
17 changed files with 290 additions and 224 deletions
|
|
@ -10,7 +10,7 @@ use crate::frontend::{
|
|||
};
|
||||
use crate::middleware::containers::Set;
|
||||
use crate::middleware::{containers::Dictionary, Params, PodType, KEY_SIGNER, KEY_TYPE};
|
||||
use crate::middleware::{hash_str, CustomPredicateRef, NativeOperation, OperationType, Pod};
|
||||
use crate::middleware::{hash_str, CustomPredicateRef, NativeOperation, OperationType};
|
||||
use crate::op;
|
||||
|
||||
// ZuKYC
|
||||
|
|
@ -47,21 +47,21 @@ pub fn zu_kyc_pod_builder(
|
|||
let now_minus_1y: i64 = 1706367566;
|
||||
|
||||
let mut kyc = MainPodBuilder::new(params);
|
||||
kyc.add_signed_pod(&gov_id);
|
||||
kyc.add_signed_pod(&pay_stub);
|
||||
kyc.add_signed_pod(&sanction_list);
|
||||
kyc.add_signed_pod(gov_id);
|
||||
kyc.add_signed_pod(pay_stub);
|
||||
kyc.add_signed_pod(sanction_list);
|
||||
kyc.pub_op(op!(
|
||||
not_contains,
|
||||
(sanction_list, "sanctionList"),
|
||||
(gov_id, "idNumber")
|
||||
));
|
||||
kyc.pub_op(op!(lt, (gov_id, "dateOfBirth"), now_minus_18y));
|
||||
))?;
|
||||
kyc.pub_op(op!(lt, (gov_id, "dateOfBirth"), now_minus_18y))?;
|
||||
kyc.pub_op(op!(
|
||||
eq,
|
||||
(gov_id, "socialSecurityNumber"),
|
||||
(pay_stub, "socialSecurityNumber")
|
||||
));
|
||||
kyc.pub_op(op!(eq, (pay_stub, "startDate"), now_minus_1y));
|
||||
))?;
|
||||
kyc.pub_op(op!(eq, (pay_stub, "startDate"), now_minus_1y))?;
|
||||
|
||||
Ok(kyc)
|
||||
}
|
||||
|
|
@ -87,20 +87,18 @@ pub fn eth_dos_pod_builder(
|
|||
|
||||
// ETHDoS POD builder
|
||||
let mut alice_bob_ethdos = MainPodBuilder::new(params);
|
||||
alice_bob_ethdos.add_signed_pod(&alice_attestation);
|
||||
alice_bob_ethdos.add_signed_pod(&charlie_attestation);
|
||||
alice_bob_ethdos.add_signed_pod(alice_attestation);
|
||||
alice_bob_ethdos.add_signed_pod(charlie_attestation);
|
||||
|
||||
// Attestation POD entries
|
||||
let alice_pubkey = alice_attestation
|
||||
let alice_pubkey = *alice_attestation
|
||||
.kvs()
|
||||
.get(&KEY_SIGNER.into())
|
||||
.ok_or(anyhow!("Could not find Alice's public key!"))?
|
||||
.clone();
|
||||
let charlie_pubkey = charlie_attestation
|
||||
.ok_or(anyhow!("Could not find Alice's public key!"))?;
|
||||
let charlie_pubkey = *charlie_attestation
|
||||
.kvs()
|
||||
.get(&KEY_SIGNER.into())
|
||||
.ok_or(anyhow!("Could not find Charlie's public key!"))?
|
||||
.clone();
|
||||
.ok_or(anyhow!("Could not find Charlie's public key!"))?;
|
||||
|
||||
// Include Alice and Bob's keys as public statements.
|
||||
let alice_pubkey_copy = alice_bob_ethdos.pub_op(Operation(
|
||||
|
|
@ -110,12 +108,9 @@ pub fn eth_dos_pod_builder(
|
|||
alice_pubkey.into(),
|
||||
)],
|
||||
))?;
|
||||
let bob_pubkey_copy = alice_bob_ethdos.pub_op(Operation(
|
||||
let _bob_pubkey_copy = alice_bob_ethdos.pub_op(Operation(
|
||||
OperationType::Native(NativeOperation::NewEntry),
|
||||
vec![OperationArg::Entry(
|
||||
"Bob".to_string(),
|
||||
bob_pubkey.clone().into(),
|
||||
)],
|
||||
vec![OperationArg::Entry("Bob".to_string(), bob_pubkey.clone())],
|
||||
))?;
|
||||
let charlie_pubkey = alice_bob_ethdos.priv_op(Operation(
|
||||
OperationType::Native(NativeOperation::NewEntry),
|
||||
|
|
@ -137,7 +132,7 @@ pub fn eth_dos_pod_builder(
|
|||
OperationArg::Statement(alice_pubkey_copy.clone()),
|
||||
],
|
||||
))?;
|
||||
let ethdos_alice_alice_is_zero = alice_bob_ethdos.priv_op(Operation(
|
||||
let _ethdos_alice_alice_is_zero = alice_bob_ethdos.priv_op(Operation(
|
||||
OperationType::Custom(CustomPredicateRef(eth_dos_batch, 0)),
|
||||
vec![
|
||||
OperationArg::Statement(alice_equals_alice),
|
||||
|
|
@ -161,7 +156,7 @@ pub fn eth_dos_pod_builder(
|
|||
OperationArg::Statement(charlie_pubkey),
|
||||
],
|
||||
))?;
|
||||
let ethfriends_alice_charlie = alice_bob_ethdos.priv_op(Operation(
|
||||
let _ethfriends_alice_charlie = alice_bob_ethdos.priv_op(Operation(
|
||||
OperationType::Custom(CustomPredicateRef(eth_friend_batch, 0)),
|
||||
vec![
|
||||
OperationArg::Statement(attestation_is_signed_pod),
|
||||
|
|
@ -171,7 +166,7 @@ pub fn eth_dos_pod_builder(
|
|||
))?;
|
||||
|
||||
// The ETHDoS distance from Alice to Charlie is 1.
|
||||
let one = alice_bob_ethdos.priv_op(Operation(
|
||||
let _one = alice_bob_ethdos.priv_op(Operation(
|
||||
OperationType::Native(NativeOperation::NewEntry),
|
||||
vec![OperationArg::Entry("ZERO".to_string(), Value::from(0i64))],
|
||||
))?;
|
||||
|
|
@ -181,7 +176,7 @@ pub fn eth_dos_pod_builder(
|
|||
// OperationType::Native(NativeOperation::SumOf
|
||||
// ),
|
||||
// vec![
|
||||
// OperationArg::Statement(one.clone()),
|
||||
// OperationArg::Statement(_one.clone()),
|
||||
// OperationArg::Statement(zero.clone()),
|
||||
// OperationArg::Statement(zero.clone())
|
||||
// ]
|
||||
|
|
@ -214,7 +209,7 @@ pub fn great_boy_pod_builder(
|
|||
friend_pods: [&SignedPod; 2],
|
||||
good_boy_issuers: &Value,
|
||||
receiver: &str,
|
||||
) -> MainPodBuilder {
|
||||
) -> Result<MainPodBuilder> {
|
||||
// Attestment chain (issuer -> good boy -> great boy):
|
||||
// issuer 0 -> good_boy_pods[0] => good boy 0
|
||||
// issuer 1 -> good_boy_pods[1] => good boy 0
|
||||
|
|
@ -225,10 +220,10 @@ pub fn great_boy_pod_builder(
|
|||
|
||||
let mut great_boy = MainPodBuilder::new(params);
|
||||
for i in 0..4 {
|
||||
great_boy.add_signed_pod(&good_boy_pods[i]);
|
||||
great_boy.add_signed_pod(good_boy_pods[i]);
|
||||
}
|
||||
for i in 0..2 {
|
||||
great_boy.add_signed_pod(&friend_pods[i]);
|
||||
great_boy.add_signed_pod(friend_pods[i]);
|
||||
}
|
||||
|
||||
for good_boy_idx in 0..2 {
|
||||
|
|
@ -237,44 +232,44 @@ pub fn great_boy_pod_builder(
|
|||
eq,
|
||||
(friend_pods[good_boy_idx], KEY_TYPE),
|
||||
PodType::MockSigned as i64
|
||||
));
|
||||
))?;
|
||||
for issuer_idx in 0..2 {
|
||||
// Type check
|
||||
great_boy.pub_op(op!(
|
||||
eq,
|
||||
(good_boy_pods[good_boy_idx * 2 + issuer_idx], KEY_TYPE),
|
||||
PodType::MockSigned as i64
|
||||
));
|
||||
))?;
|
||||
// Each good boy POD comes from a valid issuer
|
||||
great_boy.pub_op(op!(
|
||||
contains,
|
||||
good_boy_issuers,
|
||||
(good_boy_pods[good_boy_idx * 2 + issuer_idx], KEY_SIGNER)
|
||||
));
|
||||
))?;
|
||||
// Each good boy has 2 good boy pods
|
||||
great_boy.pub_op(op!(
|
||||
eq,
|
||||
(good_boy_pods[good_boy_idx * 2 + issuer_idx], "user"),
|
||||
(friend_pods[good_boy_idx], KEY_SIGNER)
|
||||
));
|
||||
))?;
|
||||
}
|
||||
// The good boy PODs from each good boy have different issuers
|
||||
great_boy.pub_op(op!(
|
||||
ne,
|
||||
(good_boy_pods[good_boy_idx * 2 + 0], KEY_SIGNER),
|
||||
(good_boy_pods[good_boy_idx * 2], KEY_SIGNER),
|
||||
(good_boy_pods[good_boy_idx * 2 + 1], KEY_SIGNER)
|
||||
));
|
||||
))?;
|
||||
// Each good boy is receivers' friend
|
||||
great_boy.pub_op(op!(eq, (friend_pods[good_boy_idx], "friend"), receiver));
|
||||
great_boy.pub_op(op!(eq, (friend_pods[good_boy_idx], "friend"), receiver))?;
|
||||
}
|
||||
// The two good boys are different
|
||||
great_boy.pub_op(op!(
|
||||
ne,
|
||||
(friend_pods[0], KEY_SIGNER),
|
||||
(friend_pods[1], KEY_SIGNER)
|
||||
));
|
||||
))?;
|
||||
|
||||
great_boy
|
||||
Ok(great_boy)
|
||||
}
|
||||
|
||||
pub fn great_boy_pod_full_flow() -> Result<MainPodBuilder> {
|
||||
|
|
@ -306,7 +301,7 @@ pub fn great_boy_pod_full_flow() -> Result<MainPodBuilder> {
|
|||
let bob = "Bob";
|
||||
let mut bob_good_boys = Vec::new();
|
||||
|
||||
let good_boy = good_boy_sign_pod_builder(¶ms, &bob, 36);
|
||||
let good_boy = good_boy_sign_pod_builder(¶ms, bob, 36);
|
||||
bob_good_boys.push(good_boy.sign(&mut giggles_signer).unwrap());
|
||||
bob_good_boys.push(good_boy.sign(&mut macrosoft_signer).unwrap());
|
||||
|
||||
|
|
@ -315,19 +310,19 @@ pub fn great_boy_pod_full_flow() -> Result<MainPodBuilder> {
|
|||
let charlie = "Charlie";
|
||||
let mut charlie_good_boys = Vec::new();
|
||||
|
||||
let good_boy = good_boy_sign_pod_builder(¶ms, &charlie, 27);
|
||||
let good_boy = good_boy_sign_pod_builder(¶ms, charlie, 27);
|
||||
charlie_good_boys.push(good_boy.sign(&mut macrosoft_signer).unwrap());
|
||||
charlie_good_boys.push(good_boy.sign(&mut faebook_signer).unwrap());
|
||||
|
||||
// Bob and Charlie send Alice a Friend POD
|
||||
|
||||
let mut alice_friend_pods = Vec::new();
|
||||
let friend = friend_sign_pod_builder(¶ms, &alice);
|
||||
let friend = friend_sign_pod_builder(¶ms, alice);
|
||||
alice_friend_pods.push(friend.sign(&mut bob_signer).unwrap());
|
||||
alice_friend_pods.push(friend.sign(&mut charlie_signer).unwrap());
|
||||
|
||||
let good_boy_issuers_dict = Value::Dictionary(Dictionary::new(&HashMap::new())?); // empty
|
||||
Ok(great_boy_pod_builder(
|
||||
great_boy_pod_builder(
|
||||
¶ms,
|
||||
[
|
||||
&bob_good_boys[0],
|
||||
|
|
@ -338,7 +333,7 @@ pub fn great_boy_pod_full_flow() -> Result<MainPodBuilder> {
|
|||
[&alice_friend_pods[0], &alice_friend_pods[1]],
|
||||
&good_boy_issuers_dict,
|
||||
alice,
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
// Tickets
|
||||
|
|
@ -361,30 +356,30 @@ pub fn tickets_pod_builder(
|
|||
expected_event_id: i64,
|
||||
expect_consumed: bool,
|
||||
blacklisted_emails: &Value,
|
||||
) -> MainPodBuilder {
|
||||
) -> Result<MainPodBuilder> {
|
||||
// Create a main pod referencing this signed pod with some statements
|
||||
let mut builder = MainPodBuilder::new(params);
|
||||
builder.add_signed_pod(signed_pod);
|
||||
builder.pub_op(op!(eq, (signed_pod, "eventId"), expected_event_id));
|
||||
builder.pub_op(op!(eq, (signed_pod, "isConsumed"), expect_consumed));
|
||||
builder.pub_op(op!(eq, (signed_pod, "isRevoked"), false));
|
||||
builder.pub_op(op!(eq, (signed_pod, "eventId"), expected_event_id))?;
|
||||
builder.pub_op(op!(eq, (signed_pod, "isConsumed"), expect_consumed))?;
|
||||
builder.pub_op(op!(eq, (signed_pod, "isRevoked"), false))?;
|
||||
builder.pub_op(op!(
|
||||
not_contains,
|
||||
blacklisted_emails,
|
||||
(signed_pod, "attendeeEmail")
|
||||
));
|
||||
builder
|
||||
))?;
|
||||
Ok(builder)
|
||||
}
|
||||
|
||||
pub fn tickets_pod_full_flow() -> Result<MainPodBuilder> {
|
||||
let params = Params::default();
|
||||
let builder = tickets_sign_pod_builder(¶ms);
|
||||
let signed_pod = builder.sign(&mut MockSigner { pk: "test".into() }).unwrap();
|
||||
Ok(tickets_pod_builder(
|
||||
tickets_pod_builder(
|
||||
¶ms,
|
||||
&signed_pod,
|
||||
123,
|
||||
true,
|
||||
&Value::Dictionary(Dictionary::new(&HashMap::new())?),
|
||||
))
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue