Skip to content

Normalize hash handling across contract and service boundaries - #36

Merged
MaryammAli merged 1 commit into
Proof-Stell:mainfrom
TomikeDS:fix/normalize-hash-handling
Jun 23, 2026
Merged

MaryammAli merged 1 commit into
Proof-Stell:mainfrom
TomikeDS:fix/normalize-hash-handling

Conversation

@TomikeDS

Copy link
Copy Markdown
Contributor

Description

Closes #14

Enforces SHA-256 as the only accepted hash algorithm at every service boundary and provides a tested conversion path from user-provided hex strings to the BytesN<32> type required by the Soroban contract.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Related Issues

Closes #14

Changes Made

  • Add HashValidator::validate_for_contract: accepts only 64-char SHA-256 hex, explicitly rejects 128-char SHA-512 with UnsupportedAlgorithm, normalizes to lowercase
  • Add HashValidator::hex_to_bytes32: converts a validated hex string to [u8; 32] for BytesN<32> contract calls
  • Add CacheKey::verification() normalizing constructor: lowercases hash on construction so mixed-case inputs always resolve to the same cache entry
  • Update StellarClient::verification_cache_key to use the normalizing constructor
  • Update README canonical hash encoding section with API usage examples

Testing

  • cargo test passes locally
  • cargo build --target wasm32-unknown-unknown --release succeeds
  • New tests added for new functionality (if applicable)

Checklist

  • My code follows the project's coding conventions
  • I have performed a self-review of my code
  • I have commented my code where necessary
  • No unused imports or dead code remains
  • CI checks pass (build + test + wasm)

- Add HashValidator::validate_for_contract: accepts only SHA-256, explicitly
  rejects SHA-512 with UnsupportedAlgorithm error
- Add HashValidator::hex_to_bytes32: converts validated 64-char hex to [u8; 32]
  for Soroban BytesN<32> contract calls
- Add CacheKey::verification() normalizing constructor: lowercases hash on
  construction so mixed-case inputs always map to the same cache entry
- Update StellarClient::verification_cache_key to use normalizing constructor
- Add tests for all new functions; all 96 tests pass

Closes Proof-Stell#14
@MaryammAli
MaryammAli merged commit ab39eb6 into Proof-Stell:main Jun 23, 2026
1 check passed
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.

Normalize hash handling across contract and service boundaries

1 participant