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

feat(platform): get identities for non unique public key hash #2324

Draft
wants to merge 1 commit into
base: v1.7-dev
Choose a base branch
from

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Nov 10, 2024

Issue being fixed or feature implemented

We had no way to get identities having a non unique public key hash. This would cause a problem trying to looking identities by public keys that are hashes in the state.

What was done?

Added the ability to lookup identities by non unique public key hash.

How Has This Been Tested?

Added a few unit tests.

Breaking Changes

Nothing should be breaking.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced functionality to fetch identities associated with non-unique public key hashes.
    • Added new RPC methods and message types for identity retrieval based on non-unique public key hashes.
    • Implemented methods for verifying and proving identities linked to non-unique public key hashes.
    • Enhanced identity management with new structures and query capabilities.
  • Bug Fixes

    • Improved error handling for identity verification and retrieval processes.
  • Documentation

    • Updated documentation to reflect new methods and features related to non-unique public key hashes.
  • Chores

    • Refactored existing code for improved clarity and organization in handling identity queries.

@QuantumExplorer QuantumExplorer added this to the v1.6.0 milestone Nov 10, 2024
@QuantumExplorer QuantumExplorer self-assigned this Nov 10, 2024
Copy link
Contributor

coderabbitai bot commented Nov 10, 2024

Walkthrough

The changes in this pull request introduce new functionalities to handle identities associated with non-unique public key hashes across various modules. Key additions include the getIdentitiesForNonUniquePublicKeyHash RPC method and corresponding request/response message types in the platform.proto file. Additionally, several new methods and modules have been created in the rs-drive-abci and rs-sdk packages to support querying and verifying identities based on non-unique public key hashes. Various existing methods have also been updated for consistency with the new features.

Changes

File Change Summary
packages/dapi-grpc/protos/platform/v0/platform.proto Added RPC method getIdentitiesForNonUniquePublicKeyHash and new message types GetIdentitiesForNonUniquePublicKeyHashRequest and GetIdentitiesForNonUniquePublicKeyHashResponse.
packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/mod.rs Introduced module for querying identities with method query_identities_for_non_unique_public_key_hash.
packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/v0/mod.rs Added method query_identities_for_non_unique_public_key_hash_v0 for handling identity queries.
packages/rs-drive-abci/src/query/identity_based_queries/mod.rs Added new module identities_for_non_unique_public_key_hash.
packages/rs-drive-abci/src/query/service.rs Introduced method get_identities_for_non_unique_public_key_hash in PlatformService trait.
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/mod.rs Added method fetch_full_identities_for_non_unique_public_key_hash.
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/v0/mod.rs Introduced methods for fetching identities based on non-unique public key hashes.
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/mod.rs Modified method to include an optional limit parameter.
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/v0/mod.rs Updated methods to include limit parameter for fetching identity IDs.
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs Added module for fetching full identities.
packages/rs-drive/src/drive/identity/fetch/prove/mod.rs Introduced module for proving identities associated with non-unique public key hashes.
packages/rs-drive/src/verify/identity/mod.rs Added modules for verifying identities associated with non-unique public key hashes.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs Added fields to support new identity query features.
packages/rs-platform-version/src/version/drive_versions/drive_identity_method_versions/mod.rs Added fields for fetching and proving identities with non-unique public key hashes.
packages/rs-sdk/src/platform/fetch_many.rs Added implementation for fetching identities based on non-unique public key hashes.
packages/rs-sdk/src/platform/types/identity.rs Introduced new struct NonUniquePublicKeyHash for handling non-unique public key hashes.

Suggested reviewers

  • shumkov

🐰 In the meadow, hopping around,
New features for identities we have found!
With hashes that aren't unique, oh what a sight,
Fetching and proving, all feels just right!
So let’s celebrate this code, oh so bright! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@QuantumExplorer QuantumExplorer marked this pull request as draft November 10, 2024 03:06
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (38)
packages/rs-drive/src/verify/identity/mod.rs (1)

Line range hint 1-17: Consider grouping related modules

The file has a good organization of identity verification modules, but could benefit from grouping related functionality. Consider organizing modules into groups:

  1. Unique public key hash verifications
  2. Non-unique public key hash verifications
  3. Identity-specific verifications
  4. Balance and revision verifications

This could be achieved through comments or by extracting related modules into submodules.

Example structure:

// Unique public key hash verifications
mod verify_full_identity_by_public_key_hash;
mod verify_identity_id_by_unique_public_key_hash;
mod verify_identity_ids_by_unique_public_key_hashes;

// Non-unique public key hash verifications
mod verify_full_identities_for_non_unique_public_key_hash;
mod verify_identity_ids_for_non_unique_public_key_hash;

// Identity-specific verifications
mod verify_full_identity_by_identity_id;
mod verify_identity_keys_by_identity_id;
mod verify_identities_contract_keys;
mod verify_identity_contract_nonce;
mod verify_identity_nonce;

// Balance and revision verifications
mod verify_identity_balance_and_revision_for_identity_id;
mod verify_identity_balance_for_identity_id;
mod verify_identity_balances_for_identity_ids;
mod verify_identity_revision_for_identity_id;
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/mod.rs (1)

Line range hint 13-24: Update method documentation to include the limit parameter.

The function documentation needs to be updated to describe the new limit parameter and its purpose in controlling the number of returned identity IDs.

Add the following to the documentation under the Arguments section:

 /// # Arguments
 ///
 /// * `public_key_hash` - A non-unique public key hash corresponding to the identity ids to be fetched.
+/// * `limit` - Optional maximum number of identity IDs to return.
 /// * `transaction` - Transaction arguments.
 /// * `drive_version` - A reference to the drive version.
packages/rs-drive/src/verify/identity/verify_identity_id_by_unique_public_key_hash/mod.rs (1)

Line range hint 36-42: Consider adding a cross-reference in the documentation.

The documentation could be enhanced by adding a note about the existence of a separate method for handling non-unique public key hashes, helping developers choose the appropriate method for their use case.

Add a note like this to the documentation:

    /// Verifies the identity ID of a user by their public key hash.
+   /// For handling non-unique public key hashes, see `verify_identity_ids_for_non_unique_public_key_hash`.
    ///
    /// # Parameters
packages/rs-drive/src/verify/identity/verify_identity_ids_by_unique_public_key_hashes/mod.rs (3)

61-63: Consider enhancing error message with migration guidance.

Since this is part of a feature that introduces handling for non-unique public key hashes, it would be helpful to include guidance in the error message about which method to use for non-unique cases.

- method: "verify_identity_ids_by_unique_public_key_hashes".to_string(),
+ method: "verify_identity_ids_by_unique_public_key_hashes (use verify_identity_ids_for_non_unique_public_key_hash for non-unique cases)".to_string(),

Line range hint 39-66: Documentation needs updating to reflect uniqueness requirement.

While the function is well-documented, it should explicitly mention that this method is specifically for unique public key hashes and point to the alternative method for non-unique cases.

Add to the documentation:

 /// Verifies the identity IDs of multiple identities by their public key hashes.
+/// This method specifically handles unique public key hashes. For non-unique public key hashes,
+/// use `verify_identity_ids_for_non_unique_public_key_hash` instead.
 ///
 /// # Parameters

Warning: Inconsistent method naming found in C bindings

The verification revealed that while most of the codebase has been updated to use the new "unique" naming convention, the C bindings in rs-drive-verify-c-binding/src/lib.rs still use the old method name verify_identity_ids_by_public_key_hashes. This inconsistency needs to be addressed to:

  • Maintain API consistency across the codebase
  • Prevent potential misuse of the function
  • Ensure clear distinction between unique and non-unique public key hash handling
  • packages/rs-drive-verify-c-binding/src/lib.rs: Update the following occurrences:
    • Line containing pub unsafe extern "C" fn verify_identity_ids_by_public_key_hashes
    • Line containing let verification_result = Drive::verify_identity_ids_by_public_key_hashes
    • Line containing fn verify_identity_ids_by_public_key_hashes()
🔗 Analysis chain

Line range hint 39-51: Method name change accurately reflects its unique key handling behavior.

The renaming from verify_identity_ids_by_public_key_hashes to verify_identity_ids_by_unique_public_key_hashes aligns well with the PR's objective of distinguishing between unique and non-unique public key hash handling. This explicit naming helps prevent misuse.

Let's verify this is the only instance of the old method name in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of the old method name
# Expect: No matches as the method should be fully renamed

rg "verify_identity_ids_by_public_key_hashes" --type rust

Length of output: 158


Script:

#!/bin/bash
# Search for any variations of the method name (both old and new) to ensure complete verification
rg -i "verify_identity_ids.*public_key_hash" --type rust

# Also search for test files that might reference this functionality
rg -i "verify_identity_ids.*public_key_hash" --type rust --glob "*test*.rs"

# Search for potential imports or uses of this functionality
ast-grep --pattern 'use $$$verify_identity_ids$$$'

Length of output: 3722

packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/v0/mod.rs (1)

44-48: Consider adding index hints for range queries

The implementation correctly applies the limit to the range query. However, for better performance with large datasets, consider adding index hints or documentation about required indexes for this query pattern.

packages/rs-drive/src/verify/identity/verify_full_identity_by_public_key_hash/v0/mod.rs (1)

Line range hint 46-51: Update documentation to reflect uniqueness requirement.

The method now explicitly handles unique public key hashes, but this requirement isn't documented. Consider updating the function's documentation to clarify this constraint.

Apply this diff to enhance the documentation:

    /// Verifies the full identity of a user by their public key hash.
    ///
    /// This function takes a byte slice `proof` and a 20-byte array `public_key_hash` as arguments,
-   /// then it verifies the identity of the user with the given public key hash.
+   /// then it verifies the identity of the user with the given unique public key hash.
    ///
    /// The `proof` should contain the proof of authentication from the user.
-   /// The `public_key_hash` should contain the hash of the public key of the user.
+   /// The `public_key_hash` should contain a unique hash of the public key of the user.
+   /// For non-unique public key hashes, use the appropriate non-unique verification methods.
packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs (1)

36-36: LGTM! Consider adding rate limiting.

The feature version bounds field is well-placed and aligns with the PR objective. Since this endpoint could potentially return multiple identities, consider implementing rate limiting to prevent abuse.

Consider:

  1. Adding request rate limiting per client
  2. Implementing caching for frequently requested public key hashes
  3. Adding monitoring for this endpoint's usage patterns
packages/rs-drive/src/verify/identity/verify_full_identities_by_public_key_hashes/v0/mod.rs (1)

51-51: Method rename improves clarity but needs documentation update.

The rename from verify_identity_ids_by_public_key_hashes to verify_identity_ids_by_unique_public_key_hashes better reflects the method's requirement for unique public key hashes. However, this requirement should be documented in the function's documentation.

Consider updating the function documentation to explicitly mention the uniqueness requirement for public key hashes:

    /// # Parameters
    ///
    /// - `proof`: A byte slice representing the proof of authentication from the users.
-   /// - `public_key_hashes`: A reference to a slice of 20-byte arrays, each representing
-   ///    a hash of a public key of a user.
+   /// - `public_key_hashes`: A reference to a slice of 20-byte arrays, each representing
+   ///    a unique hash of a public key of a user. The hashes must be unique as this method
+   ///    does not handle duplicate public key hashes.
packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs (1)

44-44: LGTM: Complementary field for ID-only retrieval

The addition of verify_identity_ids_for_non_unique_public_key_hash provides a lightweight alternative to full identity retrieval, which is a good architectural choice for cases where only IDs are needed.

Consider documenting the performance implications and recommended usage patterns for both full identity and ID-only retrieval methods in the API documentation.

packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs (1)

Line range hint 44-86: Consider adding more test cases.

While the current test covers the happy path well, consider adding tests for:

  1. Non-existent public key hash (proving absence)
  2. Error cases (invalid public key hash format/length)
  3. Edge cases around version handling

This will ensure robust handling of all scenarios.

packages/rs-drive/src/verify/identity/verify_identity_id_by_unique_public_key_hash/v0/mod.rs (1)

Line range hint 13-35: Enhance documentation to clarify uniqueness requirement.

The function documentation should explicitly mention that this function is specifically for unique public key hashes, distinguishing it from the non-unique case.

 /// Verifies the identity ID of a user by their public key hash.
+/// This function specifically handles unique public key hashes. For non-unique public key hashes,
+/// use the corresponding non-unique verification method.
 ///
 /// # Parameters
 ///
 /// - `proof`: A byte slice representing the proof of authentication from the user.
packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs (1)

Inconsistent method naming found in C bindings

The verification reveals that while the Rust codebase has been updated to use the new verify_identity_ids_by_unique_public_key_hashes naming, the C bindings in packages/rs-drive-verify-c-binding still use the old method name verify_identity_ids_by_public_key_hashes. This inconsistency needs to be addressed to maintain API coherence.

  • packages/rs-drive-verify-c-binding/src/lib.rs: Update the C binding function name and its implementation
  • packages/rs-drive-verify-c-binding/c/main.c: Update the corresponding test function names and calls
🔗 Analysis chain

Line range hint 92-97: Method rename accurately reflects its unique key hash handling.

The rename from verify_identity_ids_by_public_key_hashes to verify_identity_ids_by_unique_public_key_hashes improves code clarity by explicitly indicating that this method handles only unique public key hashes. This aligns well with the PR's objective of distinguishing between unique and non-unique public key hash handling.

Let's verify the consistency of this naming change across the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old method name
# and verify the introduction of corresponding non-unique methods

# Search for any remaining instances of the old method name
echo "Checking for old method name references:"
rg "verify_identity_ids_by_public_key_hashes"

# Search for the new unique/non-unique method pattern to verify the split
echo "Verifying the method split pattern:"
rg "verify_identity_ids_by_(unique|non_unique)_public_key_hashes"

Length of output: 2737

packages/rs-drive/src/verify/identity/verify_identity_ids_by_unique_public_key_hashes/v0/mod.rs (2)

Line range hint 40-93: Consider performance optimization for large collections.

The implementation is correct and well-documented. However, for better performance with large collections, consider:

  1. Using a pre-allocated vector if the size is known
  2. Implementing parallel processing for the mapping operation when dealing with large sets

Here's a suggested optimization using pre-allocation:

-        let values = proved_key_values
+        let mut values = Vec::with_capacity(proved_key_values.len());
+        values = proved_key_values
             .into_iter()
             .map(|proved_key_value| {

Function rename requires updates in C bindings

The function has been properly renamed to verify_identity_ids_by_unique_public_key_hashes in the Rust codebase, but the C bindings in packages/rs-drive-verify-c-binding still use the old name verify_identity_ids_by_public_key_hashes. This needs to be updated for consistency:

  • packages/rs-drive-verify-c-binding/c/main.c: Update function name in test and function call
  • packages/rs-drive-verify-c-binding/src/lib.rs: Update the extern function name and test function name
🔗 Analysis chain

Line range hint 40-47: Verify the function rename impact across the codebase.

The function rename from verify_identity_ids_by_public_key_hashes_v0 to verify_identity_ids_by_unique_public_key_hashes_v0 better reflects its purpose, but we should verify all call sites have been updated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining references to the old function name
# and verify all calls to the new function name

echo "Checking for old function name references..."
rg "verify_identity_ids_by_public_key_hashes_v0"

echo "Verifying new function usage..."
rg "verify_identity_ids_by_unique_public_key_hashes_v0"

Length of output: 610


Script:

#!/bin/bash
# Let's check the usage context in the mod.rs file to ensure proper integration
echo "Checking the module integration..."
cat "packages/rs-drive/src/verify/identity/verify_identity_ids_by_unique_public_key_hashes/mod.rs"

# Let's also check for any test files that might use this function
echo -e "\nChecking test files..."
fd "test.*\.rs" packages/rs-drive/src/verify/identity | xargs rg "verify_identity_ids.*public_key_hashes"

Length of output: 5100

packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs (1)

Line range hint 47-143: Consider adding edge case tests.

While the current test coverage is thorough for the happy path, consider adding tests for:

  • Empty public key hash list
  • Invalid/malformed public key hashes
  • Mix of existing and non-existing public key hashes

Would you like me to help generate these additional test cases?

packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v1.rs (1)

75-79: LGTM! Consider adding documentation.

The new feature version configuration for identities_for_non_unique_public_key_hash is correctly structured and consistent with other feature version bounds. Consider adding documentation to describe:

  • The purpose of this feature
  • Expected behavior when multiple identities share the same public key hash
  • Any performance implications
packages/rs-sdk/src/platform/types/identity.rs (2)

61-66: Documentation could be enhanced with example usage.

The struct definition and documentation are well-structured. Consider adding a code example to demonstrate usage, similar to other structs in the codebase.

Add a usage example to the documentation:

 /// Non-unique Public key hash that can be used as a [Query] to find identities.
 ///
 /// You can use [`FetchMany::fetch_many(Vec<NonUniquePublicKeyHash>)`](crate::platform::FetchMany::fetch_many()) to fetch the identities
 /// having this public key hash.
+///
+/// # Example
+/// ```rust
+/// use platform::types::NonUniquePublicKeyHash;
+/// 
+/// let hash = [0u8; 20];
+/// let query = NonUniquePublicKeyHash(hash);
+/// let identities = platform.fetch_many(vec![query]).await?;
+/// ```
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct NonUniquePublicKeyHash(pub [u8; 20]);

178-198: Consider improving error handling for non-proof queries.

The implementation is correct and follows the established pattern. However, the use of unimplemented!() for non-proof queries could be improved to provide a more informative error message.

Consider this improvement:

     fn query(self, prove: bool) -> Result<GetIdentitiesForNonUniquePublicKeyHashRequest, Error> {
         if !prove {
-            unimplemented!("queries without proofs are not supported yet");
+            return Err(Error::Transport(TransportError::Custom(
+                "Queries without proofs are not supported yet".to_string(),
+            )));
         }

This change would:

  1. Return a proper Error type instead of panicking
  2. Be more consistent with Rust's error handling patterns
  3. Provide better error information to API consumers
packages/rs-drive/src/drive/identity/fetch/queries/mod.rs (1)

96-102: Add feature flag to maintain consistency.

The implementation correctly handles retrieval of multiple identity IDs for a non-unique public key hash. However, since it uses the server-gated function, it should also be feature-gated.

Add the feature flag:

+#[cfg(feature = "server")]
pub fn identity_ids_for_non_unique_public_key_hash_query(
    public_key_hash: [u8; 20],
) -> PathQuery {
    let non_unique_key_hashes = non_unique_key_hashes_sub_tree_path_vec(public_key_hash);
    PathQuery::new_single_query_item(non_unique_key_hashes, QueryItem::RangeFull(RangeFull))
}
packages/rs-sdk/src/platform/fetch_many.rs (1)

463-470: Documentation could be more descriptive.

The implementation looks good and follows the established patterns. However, the documentation could be enhanced to:

  1. Explain the purpose of fetching identities by non-unique public key hash
  2. Include example usage similar to other implementations
  3. Specify any limitations or edge cases

Consider expanding the documentation like this:

 /// Fetch multiple elements.
+/// Fetches identities associated with a non-unique public key hash.
 ///
 /// ## Supported query types
 ///
 /// * [NonUniquePublicKeyHash]
+///
+/// ## Example
+///
+/// ```rust
+/// use dash_sdk::{Sdk, platform::FetchMany};
+/// use crate::platform::types::identity::NonUniquePublicKeyHash;
+///
+/// # tokio_test::block_on(async {
+/// let sdk = Sdk::new_mock();
+/// let hash = NonUniquePublicKeyHash::new([0; 32]);
+/// let result = hash.fetch_many(&sdk, hash).await;
+/// # });
+/// ```
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/v0/mod.rs (1)

47-54: Consider batch fetching identities to improve performance

Currently, identities are fetched individually in a loop:

identity_ids
    .into_iter()
    .filter_map(|identity_id| {
        self.fetch_full_identity(identity_id, transaction, platform_version)
            .transpose()
    })
    .collect::<Result<Vec<Identity>, Error>>()

If there is support for batch fetching identities, consider implementing a method to retrieve all identities in a single operation. This would reduce the number of database calls and improve performance when dealing with multiple identities.

packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/mod.rs (1)

31-33: Clarify behavior when no identities are found

The documentation states that an Error is returned if the provided public key hash does not correspond to any identities. Consider whether it would be more appropriate to return an empty Vec<Identity> instead of an error in this case. Returning an empty vector allows callers to handle the "no identities found" case without treating it as an exceptional condition, leading to cleaner and more idiomatic code.

packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/mod.rs (1)

41-60: Consider adding unit tests for the verification method

Adding unit tests for verify_identity_ids_for_non_unique_public_key_hash will help ensure its robustness and correctness across different platform versions and input scenarios.

Would you like assistance in creating unit tests for this method or opening a GitHub issue to track this task?

packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/mod.rs (3)

17-23: Add detailed documentation for the public function

Consider adding more comprehensive documentation to the query_identities_for_non_unique_public_key_hash function. Including detailed explanations of parameters, return values, and possible errors will improve maintainability and help other developers understand its usage.


26-29: Improve the error message for clarity

The error message could be more specific. Consider rephrasing it to clearly indicate the missing version field in the request.

Apply this diff to enhance the error message:

- QueryError::DecodingError(
-     "could not decode identities for non unique public key hash query".to_string(),
- ),
+ QueryError::DecodingError(
+     "Missing 'version' field in GetIdentitiesForNonUniquePublicKeyHashRequest".to_string(),
+ ),

54-68: Handle potential future versions in the match statement

Currently, the match on version only handles RequestVersion::V0. To make the code more resilient to future changes, consider adding a wildcard arm to handle unexpected versions or prepare for additional versions.

packages/rs-drive/src/verify/identity/verify_full_identities_for_non_unique_public_key_hash/v0/mod.rs (3)

50-56: Replace hardcoded boolean true with a named constant or variable

In the call to Self::verify_identity_ids_for_non_unique_public_key_hash, the second argument is true. Passing boolean literals directly can reduce code readability and make it harder to understand the purpose of the argument. Consider using a named constant or variable to clarify what this boolean represents.


60-66: Use named constant or variable instead of hardcoded true

Similarly, in the call to Self::verify_full_identity_by_identity_id, the second argument is true. For better readability and maintainability, replace the hardcoded boolean with a named constant or variable that describes its purpose.


42-73: Ensure unit tests cover the new method

The verify_full_identities_for_non_unique_public_key_hash_v0 function is a critical addition to the codebase. Please ensure that comprehensive unit tests are added to verify its functionality, including edge cases like invalid proofs, empty identity lists, and different platform versions.

packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/v0/mod.rs (4)

29-33: Improve error message for invalid public key hash length

When the public_key_hash is not 20 bytes long, including the provided length in the error message can help with debugging and provide clearer feedback to the caller.

You can update the error message to include the actual length:

 .map_err(|_| QueryError::InvalidArgument(
-    "public key hash must be 20 bytes long".to_string()
+    format!("public key hash must be 20 bytes long, but got {} bytes", public_key_hash.len())
 ))

35-43: Handle potential errors with more context in proof generation

In the prove branch, any errors from prove_full_identities_for_non_unique_public_key_hash are propagated directly. Adding context to these errors can facilitate debugging.

Consider wrapping the error to provide additional information:

 )?;
+    .map_err(|e| Error::ProofGenerationError(format!("Failed to generate proof: {}", e)))?

Ensure you have an appropriate variant like ProofGenerationError in your Error enum.


66-68: Preserve serialization error details

When serializing identities, errors are currently converted to Error::Protocol without preserving the original error message. Capturing the original error can aid in troubleshooting.

Modify the error handling to include the serialization error details:

 .map_err(Error::Protocol)
+    .map_err(|e| Error::Protocol(e))

86-152: Organize test modules for clarity

The tests are currently all within a single mod tests module. Organizing them into sub-modules or separating them based on functionality can improve readability and maintainability.

Consider structuring the tests like this:

#[cfg(test)]
mod tests {
    mod invalid_inputs {
        // Tests for invalid inputs
    }

    mod identity_queries {
        // Tests related to identity queries without proofs
    }

    mod proof_generation {
        // Tests related to proof generation
    }
}
packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_for_non_unique_public_key_hash/v0/mod.rs (3)

10-10: Update function documentation to reflect dynamic limit

The comment states that the function "fetches up to 5 full identities," but the actual number fetched is determined by the limit parameter provided to the function. To prevent confusion, consider updating the documentation to accurately describe this behavior.

Apply this diff to update the comment:

-    /// Given public key hash, fetches up to 5 full identities as proofs.
+    /// Given a public key hash, fetches up to `limit` full identities as proofs.
+    /// If `limit` is `None`, all matching identities are fetched.

75-137: Refactor tests to eliminate duplicated code

The test functions should_prove_multiple_identities and should_prove_multiple_identities_limit_under_total contain duplicated code for setting up the drive, generating identities, and adding them to the drive. Refactoring shared code into helper functions will improve maintainability and reduce repetition.

Here's an example of how you might refactor the common setup code:

fn setup_test_identities(
    drive: &Drive,
    num_identities: usize,
    public_key: &IdentityPublicKey,
    platform_version: &PlatformVersion,
) {
    let identities: BTreeMap<[u8; 32], Identity> =
        Identity::random_identities(num_identities, 3, Some(14), *platform_version)
            .expect("expected random identities")
            .into_iter()
            .map(|identity| (identity.id().to_buffer(), identity))
            .collect();

    for identity in identities.values() {
        let mut identity = identity.clone();
        identity.add_public_key(public_key.clone());
        drive
            .add_new_identity(
                identity,
                false,
                &BlockInfo::default(),
                true,
                None,
                *platform_version,
            )
            .expect("expected to add an identity");
    }
}

Then, in your test functions, you can use this helper:

#[test]
fn should_prove_multiple_identities() {
    let drive = setup_drive_with_initial_state_structure(None);
    let platform_version = PlatformVersion::latest();

    let mut rng = StdRng::seed_from_u64(394);
    let (public_key, _) = IdentityPublicKey::random_key_with_known_attributes(
        4,
        &mut rng,
        Purpose::AUTHENTICATION,
        SecurityLevel::MEDIUM,
        KeyType::ECDSA_HASH160,
        None,
        platform_version,
    )
    .expect("expected key");

    setup_test_identities(&drive, 2, &public_key, &platform_version);

    // Rest of the test code...
}

This approach reduces duplication and makes the tests more concise.

Also applies to: 140-214


202-202: Remove unnecessary debug print statement

The println! statement at line 202 prints the grovedb_proof_string, which may not be necessary in the context of an automated test. Removing this statement can clean up the test output and improve efficiency.

Apply this diff to remove the print statement:

-        println!("{}", grovedb_proof_string);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3b7ca92 and 0f0b255.

📒 Files selected for processing (39)
  • packages/dapi-grpc/protos/platform/v0/platform.proto (2 hunks)
  • packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/query/identity_based_queries/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/query/service.rs (2 hunks)
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/mod.rs (2 hunks)
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs (2 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_for_non_unique_public_key_hash/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_for_non_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_id_by_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/drive/identity/fetch/queries/mod.rs (3 hunks)
  • packages/rs-drive/src/query/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_full_identities_by_public_key_hashes/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_full_identities_for_non_unique_public_key_hash/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_full_identities_for_non_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_full_identity_by_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_identity_id_by_unique_public_key_hash/mod.rs (2 hunks)
  • packages/rs-drive/src/verify/identity/verify_identity_id_by_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_identity_ids_by_unique_public_key_hashes/mod.rs (2 hunks)
  • packages/rs-drive/src/verify/identity/verify_identity_ids_by_unique_public_key_hashes/v0/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/v0/mod.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs (2 hunks)
  • packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v1.rs (2 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_identity_method_versions/mod.rs (2 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_identity_method_versions/v1.rs (2 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs (1 hunks)
  • packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs (1 hunks)
  • packages/rs-platform-version/src/version/mocks/v2_test.rs (2 hunks)
  • packages/rs-sdk/src/platform/fetch_many.rs (3 hunks)
  • packages/rs-sdk/src/platform/types/identity.rs (3 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/rs-drive-abci/src/query/identity_based_queries/mod.rs
  • packages/rs-drive/src/query/mod.rs
🧰 Additional context used
🪛 GitHub Check: Rust packages (dash-sdk) / Linting
packages/rs-drive/src/drive/identity/fetch/queries/mod.rs

[failure] 4-4: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path_vec
error[E0432]: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path_vec
--> packages/rs-drive/src/drive/identity/fetch/queries/mod.rs:4:29
|
4 | identity_tree_path_vec, non_unique_key_hashes_sub_tree_path_vec,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| no non_unique_key_hashes_sub_tree_path_vec in drive
| help: a similar name exists in the module: unique_key_hashes_tree_path_vec
|
note: found an item that was configured out
--> packages/rs-drive/src/drive/mod.rs:268:15
|
268 | pub(crate) fn non_unique_key_hashes_sub_tree_path_vec(public_key_hash: [u8; 20]) -> Vec<Vec> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: the item is gated behind the server feature

packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/v0/mod.rs

[failure] 1-1: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path
error[E0432]: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path
--> packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/v0/mod.rs:1:20
|
1 | use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no non_unique_key_hashes_sub_tree_path in drive
|
note: found an item that was configured out
--> packages/rs-drive/src/drive/mod.rs:259:15
|
259 | pub(crate) fn non_unique_key_hashes_sub_tree_path(public_key_hash: &[u8]) -> [&[u8]; 2] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: the item is gated behind the server feature

🔇 Additional comments (47)
packages/rs-drive/src/drive/identity/fetch/prove/mod.rs (1)

3-3: LGTM! Well-structured module addition.

The new module declaration follows the established naming pattern and integrates naturally with the existing identity proof functionality. It appropriately extends the system to handle non-unique public key hash scenarios while maintaining consistency with the codebase organization.

packages/rs-drive/src/verify/identity/mod.rs (1)

2-2: LGTM: New modules align with feature requirements

The addition of verify_full_identities_for_non_unique_public_key_hash and verify_identity_ids_for_non_unique_public_key_hash modules directly supports the PR's objective of handling non-unique public key hashes. The naming follows the established pattern and clearly indicates their purpose.

Also applies to: 12-12

packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/mod.rs (1)

Line range hint 25-41: LGTM! Implementation looks good.

The changes properly integrate the new limit parameter:

  • Using Option<u16> is a good choice for the limit parameter
  • The parameter is correctly forwarded to the versioned implementation
  • Version handling logic remains intact
packages/rs-drive/src/verify/identity/verify_identity_id_by_unique_public_key_hash/mod.rs (1)

Line range hint 36-42: LGTM! Clear method naming improvement.

The rename from verify_identity_id_by_public_key_hash to verify_identity_id_by_unique_public_key_hash better reflects the method's specific purpose of handling unique public key hashes.

packages/rs-drive/src/verify/identity/verify_identity_ids_by_unique_public_key_hashes/mod.rs (1)

52-58: Verify version handler implementation exists.

The code calls verify_identity_ids_by_unique_public_key_hashes_v0 which should be implemented in the v0 module.

Let's confirm the v0 implementation exists:

#!/bin/bash
# Description: Check for the v0 implementation
# Expect: Should find the implementation in the v0 module

ast-grep --pattern 'fn verify_identity_ids_by_unique_public_key_hashes_v0'
packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/v0/mod.rs (2)

20-20: LGTM: Well-structured limit parameter addition

The Option<u16> is a good choice for the limit parameter, providing sufficient range (0-65535) while remaining memory efficient. The parameter is properly passed through to the underlying operations method.

Also applies to: 27-27


35-35: Verify the expanded visibility scope

The visibility has been changed from pub(super) to pub(crate), expanding access to the entire crate. Please confirm this is intentional and identify which other modules require this access.

Also applies to: 38-38

✅ Verification successful

Based on the search results, I can generate the final response as we have clear evidence of usage outside the parent module.

Visibility change to pub(crate) is justified

The expanded visibility is necessary as the method is used in fetch_full_identities_for_non_unique_public_key_hash/v0/mod.rs, which is a sibling module. The visibility change from pub(super) to pub(crate) is required to enable this cross-module access.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any usages of this method outside its parent module
rg "fetch_identity_ids_by_non_unique_public_key_hash_operations_v0" --type rust

Length of output: 725

packages/rs-drive/src/verify/identity/verify_full_identity_by_public_key_hash/v0/mod.rs (1)

Line range hint 46-51: Verify consistent handling of unique vs non-unique hashes.

The method now explicitly expects a unique public key hash. Let's verify that the codebase consistently handles unique and non-unique cases.

✅ Verification successful

Based on the search results, I can now provide a final response since I have enough information to verify the consistent handling of unique vs non-unique public key hashes:

The codebase consistently handles unique and non-unique public key hash cases through dedicated methods and clear separation of concerns.

The codebase has well-defined methods for both cases:

  • Unique public key hash methods:

    • verify_identity_id_by_unique_public_key_hash
    • verify_identity_ids_by_unique_public_key_hashes
    • verify_full_identity_by_public_key_hash (which internally uses unique verification)
  • Non-unique public key hash methods:

    • verify_identity_ids_for_non_unique_public_key_hash
    • verify_full_identities_for_non_unique_public_key_hash

The implementation includes proper validation checks:

  • Unique methods verify there are no duplicates before proceeding
  • Non-unique methods handle multiple identities associated with the same hash
  • Both cases have corresponding test coverage and C bindings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent handling of unique vs non-unique public key hashes
# Expected: Find related methods and their usage patterns

echo "1. Checking for related public key hash verification methods:"
rg -A 2 "verify.*public_key_hash"

echo -e "\n2. Checking for potential validation of hash uniqueness:"
rg -A 5 "unique.*public_key_hash"

echo -e "\n3. Looking for test cases:"
rg -A 5 "test.*public_key_hash"

Length of output: 398125

packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/v1.rs (4)

20-20: LGTM: New method added for non-unique public key hash verification.

The addition of verify_full_identities_for_non_unique_public_key_hash aligns with the PR's objective to support identity retrieval for non-unique public key hashes.


32-32: LGTM: Added complementary method for identity IDs verification.

The addition of verify_identity_ids_for_non_unique_public_key_hash complements the full identity verification method, providing a way to verify just the identity IDs.


25-26: Improved clarity in method naming.

Good renaming of methods to explicitly indicate they work with unique public key hashes:

  • verify_identity_id_by_public_key_hashverify_identity_id_by_unique_public_key_hash
  • verify_identity_ids_by_public_key_hashesverify_identity_ids_by_unique_public_key_hashes

This change enhances code clarity without modifying functionality.

#!/bin/bash
# Verify that the old method names are not used elsewhere in the codebase
echo "Checking for any remaining usage of old method names..."
rg "verify_identity_id_by_public_key_hash|verify_identity_ids_by_public_key_hashes"

20-32: Verify version number consistency.

All new and modified methods are correctly initialized with version 0, maintaining consistency with other methods in the structure.

✅ Verification successful

Version numbers are correctly initialized to 0

Based on the verification results, all methods in the DriveVerifyIdentityMethodVersions struct are consistently initialized with version 0 in the v1.rs implementation, maintaining version consistency across the entire structure. This includes all the identity-related verification methods mentioned in the review.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that all methods in the identity struct are initialized to 0
ast-grep --pattern 'identity: DriveVerifyIdentityMethodVersions {
  $$$
  $_: 0,
  $$$
}'

Length of output: 185


Script:

#!/bin/bash
# Search for the struct definition and initialization
rg -A 20 "DriveVerifyIdentityMethodVersions" 

Length of output: 10642

packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_id_by_unique_public_key_hash/v0/mod.rs (1)

Line range hint 68-74: LGTM! Method renaming improves clarity.

The renaming of verify_identity_id_by_public_key_hash to verify_identity_id_by_unique_public_key_hash enhances code clarity by explicitly indicating that this method handles unique public key hashes. This change aligns well with the PR's objective of distinguishing between unique and non-unique public key hash handling.

packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/mod.rs (1)

8-8: Verify the limit value for max_returned_full_identities.

The field addition looks good and follows the existing pattern. However, let's verify the configured limit value.

✅ Verification successful

✓ The max_returned_full_identities limit is set to 3

Found the initialization in tests where the limit is set to 3, which is a reasonable value to prevent excessive resource usage while allowing multiple identity results. This aligns with the AI summary and follows similar patterns in the codebase for limiting returned elements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find where the limit value is set and verify it's reasonable
# Expected: Should find initialization with value 3 as mentioned in the AI summary

# Search for assignments to max_returned_full_identities
rg "max_returned_full_identities.*=.*3" -A 2

Length of output: 46


Script:

#!/bin/bash
# Let's try a broader search to find any assignments to max_returned_full_identities
rg "max_returned_full_identities.*=" -A 2

# Also search for any constant or static declarations that might define this value
rg "const.*MAX_RETURNED.*IDENTITIES" -A 2

Length of output: 87


Script:

#!/bin/bash
# Let's search for the struct initialization or tests where this field might be used
rg "DriveAbciQueryVersions\s*{" -A 10

# Also search for any test files that might use this field
fd -e rs test -x rg "max_returned_full_identities" {} -A 2

Length of output: 344

packages/rs-platform-version/src/version/drive_versions/drive_verify_method_versions/mod.rs (1)

32-32: LGTM: New field for non-unique public key hash verification

The addition of verify_full_identities_for_non_unique_public_key_hash aligns with the PR's objective to support identity retrieval using non-unique public key hashes.

packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/mod.rs (1)

1-2: LGTM: Module declaration follows good practices

The new module is well-named and logically placed among related identity fetching modules.

packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs (2)

Line range hint 23-27: LGTM! Method name change improves clarity.

The rename from full_identity_with_public_key_hash_query to full_identity_with_unique_public_key_hash_query better reflects the method's specific purpose and aligns with the new non-unique public key hash functionality being added.


Line range hint 9-38: Verify completeness of unique public key hash implementation.

The implementation correctly handles unique public key hashes, but given the PR's objective of supporting non-unique public key hashes, please verify:

  1. Are there any edge cases where this method might be called with a non-unique public key hash?
  2. Should there be any additional validation or error messages to explicitly prevent non-unique public key hashes from being processed here?
✅ Verification successful

Let me gather more context about the usage and validation of this method.


Based on the extensive search results, I can now provide a definitive response:

Implementation correctly handles unique vs non-unique public key hash separation

The implementation has robust validation and separation between unique and non-unique public key hash handling:

  1. The method prove_full_identity_by_unique_public_key_hash_v0 is specifically for unique public key hashes and cannot be called with non-unique ones because:

    • It uses fetch_identity_id_by_unique_public_key_hash_operations internally which operates on a separate storage tree for unique keys
    • Non-unique keys are stored in a different tree accessed via non_unique_key_hashes_sub_tree_path
    • There are separate validation methods and storage paths for unique vs non-unique keys
  2. The codebase has explicit validation to prevent misuse:

    • insert_unique_public_key_hash_reference_to_identity_operations_v0 checks if key exists in non-unique set
    • insert_non_unique_public_key_hash_reference_to_identity_operations_v0 checks if key exists in unique set
    • Cross-validation prevents the same key from being in both unique and non-unique sets
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential calls to this method with non-unique public key hashes
ast-grep --pattern 'prove_full_identity_by_unique_public_key_hash'

Length of output: 338


Script:

#!/bin/bash
# Check the implementation and callers of prove_full_identity_by_unique_public_key_hash
ast-grep --pattern 'fn prove_full_identity_by_unique_public_key_hash($$$)'

# Look for any validation of public key hash uniqueness
rg -A 5 "unique.*public.*key.*hash" 

Length of output: 261432

packages/rs-drive/src/verify/identity/verify_identity_id_by_unique_public_key_hash/v0/mod.rs (1)

36-36: LGTM! Function rename improves clarity.

The rename from verify_identity_id_by_public_key_hash_v0 to verify_identity_id_by_unique_public_key_hash_v0 better reflects the function's requirement for a unique public key hash.

packages/rs-drive/src/drive/identity/fetch/prove/prove_identity_ids_by_unique_public_key_hashes/v0/mod.rs (1)

Line range hint 39-91: Test case properly validates unique key handling.

The test case effectively validates the unique public key hash verification by:

  1. Explicitly filtering for unique key types using is_unique_key_type()
  2. Testing multiple identities to ensure robust verification
  3. Properly asserting the expected identity mappings
packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs (1)

Line range hint 25-29: LGTM! Method rename improves clarity.

The rename from full_identity_with_public_key_hash_query to full_identity_with_unique_public_key_hash_query better reflects the uniqueness requirement and aligns with the PR's objective of handling both unique and non-unique public key hashes.

Let's verify the consistency of this rename across the codebase:

✅ Verification successful

Method rename is consistent across the codebase

The verification shows that:

  • No instances of the old method name full_identity_with_public_key_hash_query remain
  • The new method name full_identity_with_unique_public_key_hash_query is used consistently in:
    • Main implementation: packages/rs-drive/src/drive/identity/fetch/queries/mod.rs
    • Single identity proof: packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identity_by_unique_public_key_hash/v0/mod.rs
    • Multiple identities proof: packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_by_unique_public_key_hashes/v0/mod.rs
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of the old method name
# and verify the new method name is used consistently

echo "Checking for any remaining instances of the old method name:"
rg "full_identity_with_public_key_hash_query"

echo -e "\nVerifying usage of the new method name:"
rg "full_identity_with_unique_public_key_hash_query"

Length of output: 810

packages/rs-platform-version/src/version/drive_abci_versions/drive_abci_query_versions/v1.rs (1)

10-10: Verify the rationale for the identity limit.

The hard limit of 3 for max_returned_full_identities could impact system behavior. Please ensure this limit is:

  1. Documented in the API documentation
  2. Sufficient for typical use cases
  3. Consistent with system performance requirements
✅ Verification successful

Based on the search results, I can now generate a final response:

The limit of 3 for max_returned_full_identities is a reasonable system constraint

The limit is used as a default upper bound when retrieving identities with non-unique public key hashes, as evidenced by:

  • Implementation in verify_identity_ids_for_non_unique_public_key_hash/v0/mod.rs shows it's used as a fallback when no explicit limit is provided
  • Consistent with other platform query limits (e.g., max_returned_elements: 100)
  • Part of a broader platform update that added limits to identity queries (referenced in CHANGELOG.md)

This limit helps prevent potential system abuse while still allowing sufficient results for typical use cases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for documentation or comments about this limit
rg -i "max.*full.*identities|return.*3.*identities" --type md

Length of output: 63


Script:

#!/bin/bash
# Let's try a broader search for any mentions of this limit in code comments, docs, or test files
rg -i "max.*returned.*identities|limit.*identities|return.*3.*identit" 

# Also search for related test cases
fd -e rs -e toml . | xargs rg -l "max_returned_full_identities"

# Look for related configuration or constants
ast-grep --pattern 'const $_: $_ = 3;'

Length of output: 56582


Script:

#!/bin/bash
# Let's check the implementation and usage context of this limit
rg -A 5 -B 5 "max_returned_full_identities" packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/v0/mod.rs

# Also check if there are any tests or documentation about this limit
rg -A 5 -B 5 "max_returned_full_identities" packages/rs-platform-version/src/version/mocks/v2_test.rs

# Look for any related configuration or documentation
rg -i "limit.*identit|max.*identit" -g "*.md" -g "*.rs"

Length of output: 9341

packages/rs-platform-version/src/version/drive_versions/drive_identity_method_versions/v1.rs (2)

30-30: LGTM: Fetch method version properly initialized.

The addition of fetch_full_identities_for_non_unique_public_key_hash is well-placed within the fetch operations group and correctly initialized to version 0, aligning with the PR's objective to support identity retrieval for non-unique public key hashes.


62-62: LGTM: Prove method version properly initialized.

The addition of prove_full_identities_for_non_unique_public_key_hash is well-placed within the prove operations group and correctly initialized to version 0, complementing the fetch operation by providing verification capabilities for non-unique public key hash identity retrieval.

packages/rs-sdk/src/platform/types/identity.rs (1)

10-10: LGTM: Import statements are well-organized.

The new imports for non-unique public key hash functionality are properly organized and follow the existing pattern.

Also applies to: 18-24

packages/rs-platform-version/src/version/drive_versions/drive_identity_method_versions/mod.rs (2)

92-92: LGTM! Well-integrated fetch functionality.

The new fetch_full_identities_for_non_unique_public_key_hash field complements the existing fetch_identity_ids_by_non_unique_public_key_hash field, providing a natural extension from ID-only fetching to full identity retrieval.


131-131: LGTM! Good symmetry with fetch capabilities.

The addition of prove_full_identities_for_non_unique_public_key_hash provides the necessary proving capabilities to match the new fetch functionality, maintaining a consistent pattern of paired fetch/prove operations throughout the codebase.

packages/rs-drive/src/drive/identity/fetch/queries/mod.rs (1)

212-212: Verify function rename impact.

The function rename from full_identity_with_public_key_hash_query to full_identity_with_unique_public_key_hash_query improves clarity but may affect existing code.

Let's verify all usages of this function:

✅ Verification successful

Let me analyze the git history to see if this is a recent rename and check the PR changes to ensure completeness.


Based on the git log output, I can see this is indeed a function rename with corresponding updates to all its usages. The changes show:

  1. The function was renamed from full_identity_with_public_key_hash_query to full_identity_with_unique_public_key_hash_query
  2. All call sites were updated in the same changeset
  3. The change appears to be part of a larger refactoring that introduces non-unique public key hash functionality (evidenced by the new file prove_full_identities_for_non_unique_public_key_hash/mod.rs)

Function rename is properly implemented

All usages of the old function name have been updated to use the new name. The rename is part of a consistent refactoring to distinguish between unique and non-unique public key hash functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for both old and new function names to ensure all occurrences are updated
echo "Searching for old function name..."
rg "full_identity_with_public_key_hash_query" --type rust

echo "Searching for new function name..."
rg "full_identity_with_unique_public_key_hash_query" --type rust

Length of output: 766


Script:

#!/bin/bash
# Check git history for the function rename
git log -p | grep -A 10 -B 10 "full_identity_with_public_key_hash_query"

# Get the changes in the current PR
git diff origin/main | grep -A 5 -B 5 "full_identity_with.*public_key_hash_query"

Length of output: 6775

packages/rs-platform-version/src/version/mocks/v2_test.rs (2)

142-142: LGTM! Good security practice with the identity limit.

The addition of max_returned_full_identities: 3 is a sensible safeguard that prevents potential DoS attacks by limiting the number of full identities that can be returned in a single query.


207-211: LGTM! Feature version bounds are consistent.

The addition of identities_for_non_unique_public_key_hash with version bounds set to 0 follows the established pattern for new features and properly integrates the non-unique public key hash lookup functionality.

Let's verify the consistency of version bounds with other identity-based queries:

✅ Verification successful

Let me gather more information to verify the consistency of version bounds specifically for identity-based queries.


Version bounds are correctly aligned across all identity-based queries

The verification confirms that identities_for_non_unique_public_key_hash follows the same version bounds pattern (min_version: 0, max_version: 0, default_current_version: 0) as all other identity-based queries in both the test mock (v2_test.rs) and the implementation (v1.rs). This consistency maintains the proper versioning strategy across all identity-related features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all identity-based queries follow the same version bounds pattern
# Expected: All version bounds should be consistently set to 0 for new features

rg -A 3 "identity_based_queries.*DriveAbciQueryIdentityVersions" 

Length of output: 1657


Script:

#!/bin/bash
# Search for all identity-based feature version bounds in the codebase
ast-grep --pattern 'DriveAbciQueryIdentityVersions {
    $$$
}'

Length of output: 12007

packages/rs-sdk/src/platform/fetch_many.rs (1)

9-9: LGTM! Import changes are well-organized.

The new imports are correctly added and necessary for implementing the non-unique public key hash functionality.

Also applies to: 22-24, 29-29

packages/rs-drive-abci/src/query/service.rs (2)

25-26: LGTM! Import changes are well-organized.

The new request and response types are correctly imported and follow the established naming conventions.


408-418: LGTM! Implementation follows established patterns.

The new method is well-implemented and:

  • Uses the existing handle_blocking_query helper consistently
  • Inherits robust error handling
  • Follows the same pattern as other query methods
  • Uses descriptive endpoint name for metrics and logging
packages/dapi-grpc/protos/platform/v0/platform.proto (3)

36-37: LGTM: RPC method addition follows service conventions.

The new RPC method is well-placed and follows the established naming and type reference conventions of the Platform service.


597-603: LGTM: Request message definition is well-structured.

The request message type follows the service's versioning pattern and includes appropriate fields with clear comments. The structure matches other request messages in the service.


605-619: LGTM: Response message definition is comprehensive.

The response message type is well-designed with:

  • Proper versioning using V0 message
  • A nested Identities message for the repeated field
  • Consistent use of the result oneof pattern
  • Inclusion of ResponseMetadata
  • Clear documentation
packages/rs-drive/src/drive/identity/fetch/prove/prove_full_identities_for_non_unique_public_key_hash/mod.rs (1)

25-52: Function implementation looks correct and follows versioning practices.

The method correctly handles different PlatformVersions and provides appropriate error handling for unknown versions.

packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_full_identities_for_non_unique_public_key_hash/mod.rs (1)

34-61: Implementation correctly handles versioned identity fetching

The method fetch_full_identities_for_non_unique_public_key_hash appropriately dispatches to version-specific implementations based on platform_version. Error handling for unknown versions is correctly implemented.

packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/mod.rs (1)

14-68: Well-implemented method with proper version handling and error reporting

The verify_identity_ids_for_non_unique_public_key_hash method is well-designed, with clear documentation, appropriate version checks, and comprehensive error handling. The alignment with the PlatformVersion struct ensures future scalability.

packages/rs-drive/src/verify/identity/verify_full_identities_for_non_unique_public_key_hash/mod.rs (5)

1-2: Module declaration is properly structured

The inclusion of the v0 submodule sets up the foundation for versioned implementations, promoting modularity and maintainability.


3-16: Imports are well-organized and necessary

All the required crates and modules are imported, and the use statements are neatly organized for readability.


17-74: Well-documented and versioned function implementation

The verify_full_identities_for_non_unique_public_key_hash function is thoroughly documented, providing clear explanations of its purpose, type parameters, parameters, return values, and potential errors. This aids in understanding and maintaining the code.


48-53: Generic type parameter enhances flexibility

Using the generic type parameter T: FromIterator<Identity> allows callers to specify the collection type for the returned identities, enhancing the function's flexibility and reusability.


54-72: Effective version handling with appropriate error reporting

The match statement correctly delegates to the versioned implementation based on the platform_version. The error handling for unknown versions is precise, providing helpful information about the method name, known versions, and the received version. This ensures that any version mismatches are transparently reported.

packages/rs-drive/src/verify/identity/verify_full_identities_for_non_unique_public_key_hash/v0/mod.rs (1)

1-74: Overall implementation is well-structured and clear

The new method is well-documented, and the logic appears sound. The use of iterators and error handling is appropriate. With the minor readability improvements suggested, the code should integrate seamlessly.

packages/rs-drive-abci/src/query/identity_based_queries/identities_for_non_unique_public_key_hash/v0/mod.rs (2)

125-126: Verify the response data when no identities are found

In test_identity_not_found, the test checks that there are no errors but does not assert the contents of the response. To ensure correctness, verify that the result contains an empty list of identities.

Add an assertion to check that the identities list is empty:

assert!(matches!(
    result.data,
    Some(GetIdentitiesForNonUniquePublicKeyHashResponseV0 {
        result: Some(
            get_identities_for_non_unique_public_key_hash_response_v0::Result::Identities(
                get_identities_for_non_unique_public_key_hash_response_v0::Identities { ref identities }
            )
        ),
        ..
    }) if identities.is_empty()
));

142-150: Validate absence proof content

In test_identity_absence_proof, while the test confirms that a proof is returned, it does not verify the proof's content. Ensuring the proof correctly represents the absence of identities strengthens the test.

Consider enhancing the test with additional validation:

if let Some(GetIdentitiesForNonUniquePublicKeyHashResponseV0 {
    result: Some(
        get_identities_for_non_unique_public_key_hash_response_v0::Result::Proof(ref proof),
    ),
    ..
}) = result.data
{
    // Add code here to validate the proof content
    // For example, ensure the proof indicates that no identities are associated with the public_key_hash
    assert!(validate_absence_proof(proof));
} else {
    panic!("Expected proof in the response");
}

Ensure you have a validate_absence_proof function or equivalent logic to check the proof's correctness.

Comment on lines +10 to +11
mod verify_identity_id_by_unique_public_key_hash;
mod verify_identity_ids_by_unique_public_key_hashes;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

References to old names found in documentation and tests

The occurrences of the old names are found in:

  • Documentation comments describing internal implementation details
  • Test functions and C bindings that appear to be outdated

This needs attention as these references should be updated to match the new naming convention.

Locations that need updates:

  • packages/rs-drive/src/verify/identity/verify_full_identity_by_public_key_hash/v0/mod.rs: Documentation comment
  • packages/rs-drive-verify-c-binding/src/lib.rs: Multiple locations including function names and tests
🔗 Analysis chain

LGTM: Improved clarity through explicit naming

The renaming of modules to include "unique" in their names:

  • verify_identity_id_by_unique_public_key_hash
  • verify_identity_ids_by_unique_public_key_hashes

This is a good change as it:

  1. Makes the distinction between unique and non-unique hash handling explicit
  2. Reduces potential confusion for developers
  3. Maintains consistency with the new non-unique variants

Let me check the actual content of the files that still reference the old names to determine if they are legitimate references or if they need updating.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that the renamed modules are consistently used across the codebase
# Description: Search for any remaining uses of the old module names to ensure complete migration

echo "Checking for any remaining references to old module names..."
rg -l "verify_identity_id_by_public_key_hash|verify_identity_ids_by_public_key_hashes" --type rust

echo "Checking usage of new module names..."
rg -l "verify_identity_id_by_unique_public_key_hash|verify_identity_ids_by_unique_public_key_hashes" --type rust

Length of output: 1554


Script:

#!/bin/bash
# Check the content of files that still contain old module names
echo "Content of verify_full_identity_by_public_key_hash/v0/mod.rs:"
rg -A 5 -B 5 "verify_identity_id_by_public_key_hash|verify_identity_ids_by_public_key_hashes" packages/rs-drive/src/verify/identity/verify_full_identity_by_public_key_hash/v0/mod.rs

echo -e "\nContent of rs-drive-verify-c-binding/src/lib.rs:"
rg -A 5 -B 5 "verify_identity_id_by_public_key_hash|verify_identity_ids_by_public_key_hashes" packages/rs-drive-verify-c-binding/src/lib.rs

Length of output: 4429

Comment on lines +37 to +38
pub verify_identity_id_by_unique_public_key_hash: FeatureVersion,
pub verify_identity_ids_by_unique_public_key_hashes: FeatureVersion,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update references to the renamed verification methods

The search results show that there are still references to the old method names in several files that need to be updated to match the renamed fields:

  • packages/rs-drive-verify-c-binding/src/lib.rs: Contains multiple occurrences of old method names
  • packages/rs-drive/src/verify/identity/verify_full_identity_by_public_key_hash/v0/mod.rs: Contains old method name in comments

The implementation files have been updated with the new "unique" naming, but the C bindings and some documentation still reference the old names, which needs to be synchronized.

🔗 Analysis chain

Verify the impact of field renaming

The renaming of these fields to include "unique" qualifier improves clarity but may affect existing code.

Let's check for any references to these fields in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any usage of the old field names to ensure all references are updated
rg "verify_identity_id_by_public_key_hash|verify_identity_ids_by_public_key_hashes" -t rust

# Search for the new field names to confirm the changes are consistent
rg "verify_identity_id_by_unique_public_key_hash|verify_identity_ids_by_unique_public_key_hashes" -t rust

Length of output: 4498

Comment on lines 74 to 78
hash,
None,
Some(&transaction),
&drive_version,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Documentation exists but is incomplete for the limit parameter

The function is documented in fetch_identity_ids_by_non_unique_public_key_hash/v0/mod.rs, but the limit parameter's purpose is not explained in the documentation. The parameter is used to limit the number of identity IDs returned.

  • packages/rs-drive/src/drive/identity/fetch/fetch_by_public_key_hashes/fetch_identity_ids_by_non_unique_public_key_hash/v0/mod.rs: Add parameter documentation for limit: Option<u16> explaining its purpose in controlling the maximum number of results returned.
🔗 Analysis chain

Verify documentation for the new None parameter

The test has been updated to include a None parameter in fetch_identity_ids_by_non_unique_public_key_hash. Please ensure this parameter's purpose is documented in the module's documentation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the None parameter is documented in the module or its tests

# Look for documentation about the parameter in the module
rg -A 5 "fetch_identity_ids_by_non_unique_public_key_hash.*None" --type rust

# Look for parameter documentation in doc comments
rg "/// .*fetch_identity_ids_by_non_unique_public_key_hash" --type rust

Length of output: 152


Script:

#!/bin/bash
# Let's try a broader search to find the function definition and its documentation

# Search for the function definition and surrounding context
ast-grep --pattern 'pub fn fetch_identity_ids_by_non_unique_public_key_hash($$$)'

# Search for any documentation or usage of this function
rg "fetch_identity_ids_by_non_unique_public_key_hash" --type rust -B 5 -A 2

Length of output: 15319

Comment on lines +3 to +6
use crate::drive::{
identity_tree_path_vec, non_unique_key_hashes_sub_tree_path_vec,
unique_key_hashes_tree_path_vec, Drive,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add feature flag requirement documentation.

The imported non_unique_key_hashes_sub_tree_path_vec function is gated behind the server feature flag. This dependency should be documented to prevent compilation issues.

Add a comment above the import to indicate the feature requirement:

+#[cfg(feature = "server")]
use crate::drive::{
    identity_tree_path_vec, non_unique_key_hashes_sub_tree_path_vec,
    unique_key_hashes_tree_path_vec, Drive,
};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use crate::drive::{
identity_tree_path_vec, non_unique_key_hashes_sub_tree_path_vec,
unique_key_hashes_tree_path_vec, Drive,
};
#[cfg(feature = "server")]
use crate::drive::{
identity_tree_path_vec, non_unique_key_hashes_sub_tree_path_vec,
unique_key_hashes_tree_path_vec, Drive,
};
🧰 Tools
🪛 GitHub Check: Rust packages (dash-sdk) / Linting

[failure] 4-4: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path_vec
error[E0432]: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path_vec
--> packages/rs-drive/src/drive/identity/fetch/queries/mod.rs:4:29
|
4 | identity_tree_path_vec, non_unique_key_hashes_sub_tree_path_vec,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| no non_unique_key_hashes_sub_tree_path_vec in drive
| help: a similar name exists in the module: unique_key_hashes_tree_path_vec
|
note: found an item that was configured out
--> packages/rs-drive/src/drive/mod.rs:268:15
|
268 | pub(crate) fn non_unique_key_hashes_sub_tree_path_vec(public_key_hash: [u8; 20]) -> Vec<Vec> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: the item is gated behind the server feature

)
}

/// Given an identity, fetches the identity with its flags from storage.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct the function's documentation for accuracy

The documentation for fetch_full_identities_for_non_unique_public_key_hash_operations_v0 is inaccurate. It currently reads:

/// Given an identity, fetches the identity with its flags from storage.

However, this function fetches multiple identities associated with a non-unique public key hash, not a single identity.

Please update the documentation to accurately reflect the function's purpose. Apply this diff to correct it:

-    /// Given an identity, fetches the identity with its flags from storage.
+    /// Fetches full identities associated with a non-unique public key hash.

Comment on lines +17 to +19
/// * `public_key_hash` - A 20-byte array representing the public key hash for which identities are requested.
/// * `transaction` - The transaction context for the operation.
/// * `platform_version` - A reference to the platform version, determining the method version to call.
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add missing documentation for the limit parameter.

The limit parameter is not documented in the function's docstring. Please include a description of limit to explain its purpose and how it affects the method's behavior.

@@ -0,0 +1,83 @@
use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix unresolved import due to feature gating.

The import non_unique_key_hashes_sub_tree_path is unresolved because it is gated behind the server feature. This causes a compilation error.

Apply this diff to fix the issue:

- use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};
+ #[cfg(feature = "server")]
+ use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};

Alternatively, if the non_unique_key_hashes_sub_tree_path function is required in this context regardless of the server feature, consider adjusting the feature gating in its definition to make it available.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};
#[cfg(feature = "server")]
use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};
🧰 Tools
🪛 GitHub Check: Rust packages (dash-sdk) / Linting

[failure] 1-1: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path
error[E0432]: unresolved import crate::drive::non_unique_key_hashes_sub_tree_path
--> packages/rs-drive/src/verify/identity/verify_identity_ids_for_non_unique_public_key_hash/v0/mod.rs:1:20
|
1 | use crate::drive::{non_unique_key_hashes_sub_tree_path, Drive};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no non_unique_key_hashes_sub_tree_path in drive
|
note: found an item that was configured out
--> packages/rs-drive/src/drive/mod.rs:259:15
|
259 | pub(crate) fn non_unique_key_hashes_sub_tree_path(public_key_hash: &[u8]) -> [&[u8]; 2] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: the item is gated behind the server feature

@lklimek lklimek self-assigned this Nov 13, 2024
@shumkov shumkov deleted the branch v1.7-dev November 29, 2024 10:09
@shumkov shumkov closed this Nov 29, 2024
@shumkov shumkov reopened this Nov 29, 2024
@shumkov shumkov changed the base branch from v1.6-dev to v1.7-dev November 29, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants