Skip to content

Feat/issue1#858

Open
DevMuhdishaq wants to merge 4 commits into
CodeGirlsInc:mainfrom
DevMuhdishaq:feat/Issue1
Open

Feat/issue1#858
DevMuhdishaq wants to merge 4 commits into
CodeGirlsInc:mainfrom
DevMuhdishaq:feat/Issue1

Conversation

@DevMuhdishaq

@DevMuhdishaq DevMuhdishaq commented Jun 27, 2026

Copy link
Copy Markdown

feat: Implement HashNormalizationMiddleware for consistent hash handling

Closes #551

Description

This PR introduces a centralized HashNormalizationMiddleware that standardizes hash processing across all endpoints. Previously, hash normalization was duplicated in each handler, leading to potential inconsistencies. The new middleware ensures all hashes are properly trimmed and lowercased before validation.

Changes Made

  • ✅ Create src/module/middleware/mod.rs to export middleware module
  • ✅ Implement hash normalization logic in src/module/middleware/hash_normalization.rs
    • normalize() function: trims whitespace + converts to lowercase
    • Axum middleware that processes all incoming requests
    • Automatic validation of normalized hashes
  • ✅ Add middleware to Axum router in src/lib.rs
  • ✅ Replace all 6 instances of duplicated HashValidator::normalize() with the shared middleware function
  • ✅ Cover all endpoints: submit, revoke, verify, transfer, and history endpoints

Key Features

  • Consistent handling: All hashes (path params + request bodies) are normalized the same way
  • Length preservation: 64-character SHA256 hashes maintain their length after normalization
  • Early validation: Invalid hashes are rejected before reaching business logic
  • Comprehensive tests: All normalization scenarios are covered
    Closes [CT-20] Build HashNormalizationMiddleware #552

Test Coverage

  • Lowercase input remains unchanged
  • Uppercase input gets properly lowercased
  • Mixed-case input normalizes to consistent lowercase
  • Leading/trailing whitespace is stripped
  • Combined whitespace + uppercase works correctly
  • 64-character uppercase hashes → 64-character lowercase hashes
    Closes [CT-21] Build SignatureVerificationService #553

Acceptance Criteria Met

  • normalize(hash: &str) trims whitespace and converts hex characters to lowercase
  • Normalized hashes are passed to HashValidator::validate_sha256
  • All endpoints with document_hash call normalize before validation
  • All unit tests pass
  • Normalization preserves hash length (64 chars in → 64 chars out)
  • Implementation files in contract/module/middleware/
    Closes [CT-23] Build DeduplicationService #555

Testing

All existing tests continue to pass, and the new middleware adds additional test coverage for hash normalization scenarios.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

@DevMuhdishaq is attempting to deploy a commit to the Mftee's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@DevMuhdishaq Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant