Skip to content

Improve Types by Replacing 0x${string} With Proper Viem Types#74

Merged
hanzel98 merged 2 commits into
mainfrom
improve-viem-types
Sep 10, 2025
Merged

Improve Types by Replacing 0x${string} With Proper Viem Types#74
hanzel98 merged 2 commits into
mainfrom
improve-viem-types

Conversation

@hanzel98

@hanzel98 hanzel98 commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

📝 Description

Improve type safety throughout the delegation-toolkit codebase by replacing generic 0x${string} type assertions with proper viem types like Hex and Address.

🔄 What Changed?

List the specific changes made:

  • Replaced private key types from 0x${string} to Hex in test files
  • Updated SignUserOperationReturnType and SignDelegationReturnType from 0x${string} to Hex
  • Fixed userOp private key parameter type from 0x${string} to Hex
  • Updated deployment address types from 0x${string} to Address for contract addresses
  • Replaced delegation authority and salt fields with proper Hex types in tests
  • Fixed callData, paymasterData, and factoryData to use Hex type consistently
  • Added missing Hex type imports where needed across multiple files
  • Preserved intentional test assertions for invalid data validation

🚀 Why?

Explain the motivation behind these changes:

  • Improve type safety by using semantic types instead of generic string templates
  • Better code clarity - Address vs Hex makes intent explicit (contract addresses vs hex data)
  • Align with viem best practices for better ecosystem compatibility
  • Reduce potential type-related bugs by leveraging TypeScript's type system more effectively
  • Make the codebase more maintainable with proper type semantics

🧪 How to Test?

Describe how to test these changes:

  • Manual testing steps:
  1. Run yarn clean && yarn build to ensure all packages build successfully
  2. Run yarn test to verify all 587 tests pass across all packages
  3. Run yarn lint to confirm no type-related linting errors
  • Automated tests added/updated
  • All existing tests pass

⚠️ Breaking Changes

List any breaking changes:

  • No breaking changes
  • Breaking changes (describe below):

All changes are internal type improvements that maintain the same runtime behavior and public API.

📋 Checklist

Check off completed items:

  • Code follows the project's coding standards
  • Self-review completed
  • Documentation updated (if needed)
  • Tests added/updated
  • Changelog updated (if needed)
  • All CI checks pass

🔗 Related Issues

Link to related issues:
Closes # (related to type safety improvements)
Related to # (if there are any existing type-related issues)

📚 Additional Notes

  • Preserved the standalone Hex type definition in 7715-permission-types package for ERC-7715 standard compliance
  • Documentation examples in markdown files were intentionally left unchanged to maintain consistency
  • Test files that use intentionally invalid data for validation testing maintain proper type assertions
  • All changes maintain backward compatibility while improving type safety
  • Future consideration: The 7715-permission-types package could potentially import viem types for even better consistency, but current approach maintains package independence

@hanzel98
hanzel98 requested a review from a team as a code owner September 9, 2025 04:24
@hanzel98 hanzel98 self-assigned this Sep 9, 2025
@hanzel98
hanzel98 requested a review from jeffsmale90 September 9, 2025 04:24
jeffsmale90
jeffsmale90 previously approved these changes Sep 9, 2025

@jeffsmale90 jeffsmale90 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Love it!

@hanzel98
hanzel98 merged commit d8d775d into main Sep 10, 2025
17 checks passed
@hanzel98
hanzel98 deleted the improve-viem-types branch September 10, 2025 02:25
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.

2 participants