MainPod implementation (#168)
* Initial circuit op work * Fix copy op * Add more ops * add mainpod boilerplate * pass basic test of mainpod * fix duplicate imports * WIP * fixes * wip * fix test * wip * clean up * address feedback from @ax0 * oops --------- Co-authored-by: Ahmad <root@ahmadafuni.com>
This commit is contained in:
parent
4a94b34792
commit
ce26a316a1
10 changed files with 530 additions and 104 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use itertools::Itertools;
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
@ -83,8 +84,15 @@ impl Pod for SignedPod {
|
|||
|
||||
fn pub_statements(&self) -> Vec<Statement> {
|
||||
let id = self.id();
|
||||
self.dict
|
||||
.iter()
|
||||
// By convention we put the KEY_TYPE first and KEY_SIGNER second
|
||||
let mut kvs: HashMap<_, _> = self.dict.iter().collect();
|
||||
let key_type = Value::from(hash_str(KEY_TYPE));
|
||||
let value_type = kvs.remove(&key_type).expect("KEY_TYPE");
|
||||
let key_signer = Value::from(hash_str(KEY_SIGNER));
|
||||
let value_signer = kvs.remove(&key_signer).expect("KEY_SIGNER");
|
||||
[(&key_type, value_type), (&key_signer, value_signer)]
|
||||
.into_iter()
|
||||
.chain(kvs.into_iter().sorted_by_key(|kv| kv.0))
|
||||
.map(|(k, v)| Statement::ValueOf(AnchoredKey(id, Hash(k.0)), *v))
|
||||
.collect()
|
||||
}
|
||||
|
|
@ -119,6 +127,7 @@ pub mod tests {
|
|||
pod.insert("dateOfBirth", 1169909384);
|
||||
pod.insert("socialSecurityNumber", "G2121210");
|
||||
|
||||
// TODO: Use a deterministic secret key to get deterministic tests
|
||||
let sk = SecretKey::new();
|
||||
let mut signer = Signer(sk);
|
||||
let pod = pod.sign(&mut signer).unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue