Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cred status list impl #320

Merged
merged 12 commits into from
Sep 4, 2024
Merged

cred status list impl #320

merged 12 commits into from
Sep 4, 2024

Conversation

nitro-neal
Copy link
Contributor

No description provided.

})
}

/// Checks if a given credential is disabled according to this Status List Credential.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 docs 🙏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs 🙌 🙌 🙌

///
/// # Returns
/// `true` if the bit at the specified index is 1, `false` if it is 0.
fn get_bit(compressed_bitstring: &str, bit_index: usize) -> Result<bool> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's not StatusListCredential-specific, no? Might be better to put this in a separate helper file and move associated tests as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in reality it will only be used for status list credential, its getting the bit from a compressed gziped base64 string, which I think nothing else in the universe uses 😆

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it doesn't mention StatusListCredential, still seems worth putting in a separate module. Could be in a module within mod status_list_credential if you like. Putting it in the impl StatusListCredential disrupts the focus.

@angiejones angiejones requested a review from acekyd September 3, 2024 20:14
}

// Check if the status purpose matches
let status_purpose = self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for both status_purpose and encoded_list we've got these similar, super vertical blocks of code that do "get this string attribute from additional_properties". I think it'd be more readable and reusable to put logic in a private function that doesn't use as many and_thens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup you are right, let me do this

})?;

if status_list_entry.status_purpose != *status_purpose {
return Err(Web5Error::Parameter("status purpose mismatch".to_string()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do you mind adding the expected and actual status purposes to this error message?

///
/// # Returns
/// A `Result` containing the compressed, base64-encoded bitstring, or an error if an index is out of range.
fn bitstring_generation(status_list_indexes: Vec<usize>) -> Result<String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need to take ownership. might avoid unnecessary cloning

Suggested change
fn bitstring_generation(status_list_indexes: Vec<usize>) -> Result<String> {
fn bitstring_generation(status_list_indexes: &[usize]) -> Result<String> {

Comment on lines 37 to 52
let additional_properties = {
let mut properties = HashMap::new();
properties.insert(
"statusPurpose".to_string(),
JsonValue::String(status_purpose.clone()),
);
properties.insert(
"type".to_string(),
JsonValue::String(STATUS_LIST_2021.to_string()),
);
properties.insert(
"encodedList".to_string(),
JsonValue::String(base64_bitstring.clone()),
);
JsonObject { properties }
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to see that we're just initting a hashmap with a few values. You can also use HashMap::from() if you prefer, instead of into_iter().collect().

Suggested change
let additional_properties = {
let mut properties = HashMap::new();
properties.insert(
"statusPurpose".to_string(),
JsonValue::String(status_purpose.clone()),
);
properties.insert(
"type".to_string(),
JsonValue::String(STATUS_LIST_2021.to_string()),
);
properties.insert(
"encodedList".to_string(),
JsonValue::String(base64_bitstring.clone()),
);
JsonObject { properties }
};
let additional_properties = JsonObject {
properties: [
("statusPurpose".to_string(), JsonValue::String(status_purpose)),
("type".to_string(), JsonValue::String(STATUS_LIST_2021.to_string())),
("encodedList".to_string(), JsonValue::String(base64_bitstring)),
].into_iter().collect(),
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

genius.

Comment on lines 63 to 67
issuance_date: None,
expiration_date: None,
credential_status: None,
credential_schema: None,
evidence: None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
issuance_date: None,
expiration_date: None,
credential_status: None,
credential_schema: None,
evidence: None,
..Default::default()

Copy link
Contributor

@diehuxx diehuxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. all my comments are non blocking

};

let vc_options = VerifiableCredentialCreateOptions {
id: Some(format!("urn:uuid:{}", uuid::Uuid::new_v4())),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't necessarily have to pass this in

Copy link
Contributor Author

@nitro-neal nitro-neal Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to actually update ids and introduce a status list credential options (or something like this) for custom ids. Still hashing that out, but will add in next pr

@nitro-neal nitro-neal merged commit c63823e into main Sep 4, 2024
21 checks passed
@nitro-neal nitro-neal deleted the cred-status-list-impl branch September 4, 2024 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants