-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/zk-passport/openpassport int…
…o dev
- Loading branch information
Showing
31 changed files
with
1,436 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//todo: check with circom values | ||
pub global MAX_ECONTENT_LEN = 384; | ||
pub global HASH_LEN_BYTES = 32; | ||
pub global DG_PADDING_BYTES_LEN = 7; | ||
pub global MAX_SIGNED_ATTR_LEN = 192; | ||
|
||
pub global ASCII_ZERO = 48; | ||
pub global TEN = 10; | ||
pub global CENTURY = 100; | ||
|
||
pub global SHA256_SIZE: u32 = 32; | ||
pub global SHA512_SIZE: u32 = 64; | ||
pub global SHA160_SIZE: u32 = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pub mod dg1; | ||
|
||
use crate::constants::{MAX_ECONTENT_LEN, MAX_SIGNED_ATTR_LEN}; | ||
use dg1::{verify_dg1_and_dg2, verify_econtent}; | ||
|
||
fn Dg1( | ||
dg1: [u8; 93], | ||
dg1_hash_offset: u8, | ||
dg2_hash: [u8; 64], | ||
eContent: [u8; MAX_ECONTENT_LEN], | ||
signed_attr: [u8; MAX_SIGNED_ATTR_LEN], | ||
signed_attr_econtent_hash_offset: u8, | ||
eContent_padded_length: u16, | ||
signed_attr_padded_length: u8 | ||
) { | ||
verify_dg1_and_dg2(dg1, dg1_hash_offset, dg2_hash, eContent); | ||
|
||
verify_econtent( | ||
eContent, | ||
signed_attr, | ||
signed_attr_econtent_hash_offset, | ||
eContent_padded_length, | ||
signed_attr_padded_length | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::types::DG1; | ||
use crate::utils::array::array_equal; | ||
|
||
pub fn country_not_in_list<let N: u32>(dg1: DG1, forbidden_countries_list: [u8; N]) -> bool { | ||
assert(N % 3 == 0); | ||
|
||
let country_code = [dg1[7], dg1[8], dg1[9]]; | ||
let mut not_in_list = true; | ||
|
||
for i in 0..(N / 3) { | ||
let forbidden_country = [ | ||
forbidden_countries_list[i * 3], | ||
forbidden_countries_list[(i * 3) + 1], | ||
forbidden_countries_list[(i * 3) + 2], | ||
]; | ||
let equal = array_equal(country_code, forbidden_country); | ||
|
||
if equal { | ||
not_in_list = false; | ||
} | ||
} | ||
|
||
not_in_list | ||
} | ||
|
||
#[test] | ||
fn test_country_not_in_list() { | ||
let mut country = [0; 93]; | ||
country[7] = 1; | ||
country[8] = 2; | ||
country[9] = 3; | ||
|
||
//country is in the list | ||
let forbidden_countries_list_with_country = [1, 2, 3, 4, 5, 6]; | ||
|
||
assert(!country_not_in_list(country, forbidden_countries_list_with_country)); | ||
|
||
//country is not in the list | ||
let forbidden_countries_list_without_country = [0, 1, 2, 3, 4, 5]; | ||
assert(country_not_in_list(country, forbidden_countries_list_without_country)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::types::DG1; | ||
use crate::utils::passport::date::is_older_than::is_older_than; | ||
|
||
pub struct DiscloseOutput { | ||
revealed_data: [u8; 88], | ||
older_than: [u8; 2], | ||
} | ||
|
||
// todo: check if we have to pack revealed data? | ||
pub fn disclose( | ||
dg1: DG1, | ||
selector_dg1: [bool; 88], | ||
selector_older_than: bool, | ||
current_date: [u8; 6], | ||
age: [u8; 2], | ||
) -> DiscloseOutput { | ||
let mut revealed_data: [u8; 88] = [0; 88]; | ||
|
||
for i in 0..88 { | ||
let mut multiplier = 0; | ||
if (selector_dg1[i]) { | ||
multiplier = 1; | ||
} | ||
revealed_data[i] = dg1[i + 5] * multiplier; | ||
} | ||
|
||
let mut older_than = [0, 0]; | ||
|
||
if (selector_older_than) { | ||
let is_verified = is_older_than( | ||
age, | ||
current_date, | ||
[dg1[62], dg1[63], dg1[64], dg1[65], dg1[66], dg1[67]], | ||
); | ||
|
||
let mut multiplier = 0; | ||
if (is_verified) { | ||
multiplier = 1; | ||
} | ||
|
||
older_than[0] = multiplier * age[0]; | ||
older_than[1] = multiplier * age[1]; | ||
} | ||
|
||
DiscloseOutput { revealed_data, older_than } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod disclose; | ||
pub mod country_not_in_list; |
Oops, something went wrong.