Skip to content

[CT-20] Build HashNormalizationMiddleware #552

@mftee

Description

@mftee

Problem

Hash inputs arrive in varied formats: uppercase hex, leading and trailing whitespace, or mixed case. The validator rejects these even though they represent valid hashes, leading to false validation failures for legitimate callers.

Proposed Solution

Create a HashNormalizationMiddleware inside contract/module/middleware/ that normalises hash input before it reaches validation logic.

Acceptance Criteria

  • normalize(hash: &str) function trims leading and trailing whitespace and converts all hex characters to lowercase
  • After normalisation the hash is passed to HashValidator::validate_sha256 for format checking
  • All endpoints that accept a document_hash (submit, revoke, verify, transfer, dispute) call normalize before validation
  • Unit tests cover: lowercase input unchanged, uppercase input lowercased, mixed-case input lowercased, leading/trailing spaces stripped, combined whitespace and uppercase
  • The normalisation does not change the length of the hash — a 64-char uppercase hash normalises to a 64-char lowercase hash
  • Implementation files live inside contract/module/middleware/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions