Skip to content

Commit d01338e

Browse files
authored
fix: fix re-use string for user-ops sender/to (#465)
We recently narrowed the type used for `EthAddressStruct` to be `Hex`. This actually have a huge impact on various types that depend on it. While most of the account types are fine, the user-ops one also bubbles up to the `TransactionController` and would require a bit more refactor to re-type everything correctly. For now, we'll just revert to what it was and keep them as `string` for those types. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches shared Ethereum address validation/types, which can ripple through downstream type inference and RPC param validation; behavior should be mostly compatible but type-level impacts are broad. > > **Overview** > Reverts `EthAddressStruct`’s inferred type back to `string` (while keeping the same `0x…{40}` validation regex) to undo an unintended breaking change that propagated into ERC-4337/user-op address-like fields. > > Introduces `EthAddressStrictStruct` (Hex-typed) for callers that need strict `Hex` inference, and updates EIP-7702 authorization tuple validation to use this stricter struct. The changelog documents the revert and notes `21.4.0` will be yanked. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2b1eb24. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent f00f5be commit d01338e

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

packages/keyring-api/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `EthAddressStrictStruct` struct and `EthAddressStrict` types ([#465](https://github.com/MetaMask/accounts/pull/465))
13+
- This is a stricter variant of `EthAddressStruct` which uses `Hex` instead of `string` for its inferred type.
14+
15+
### Changed
16+
17+
- Re-use `string` for ERC4337 address-like fields ([#465](https://github.com/MetaMask/accounts/pull/465))
18+
- This change reverts that and keeps using `string` for all address-like types.
19+
- Changes in [#405](https://github.com/MetaMask/accounts/pull/405) updated the associated type for `EthAddressStruct` from `string` to `Hex`, this was actually a small breaking change that went unnoticed and that would require some effort to adapt in upstream clients/controllers, for this reason, we are undoing this change for now.
20+
- Version [21.4.0] will be marked as **YANKED**, consumers are expected to use this new version that reverts this breaking change.
21+
1022
## [21.4.0]
1123

1224
### Added

packages/keyring-api/src/eth/rpc/params.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import {
2323
unknown,
2424
} from '@metamask/superstruct';
2525

26-
import { EthAddressStruct, EthBytesStruct } from '../types';
26+
import {
27+
EthAddressStrictStruct,
28+
EthAddressStruct,
29+
EthBytesStruct,
30+
} from '../types';
2731

2832
/**
2933
* A struct for validating Ethereum transaction data.
@@ -118,7 +122,7 @@ export type EthEncryptedData = Infer<typeof EthEncryptedDataStruct>;
118122
*/
119123
export const EthEip7702AuthorizationStruct = tuple([
120124
number(), // chainId
121-
EthAddressStruct, // address (contract to delegate to)
125+
EthAddressStrictStruct, // address (contract to delegate to)
122126
number(), // nonce
123127
]);
124128

packages/keyring-api/src/eth/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import {
1212

1313
export const EthBytesStruct = definePattern('EthBytes', /^0x[0-9a-f]*$/iu);
1414

15-
export const EthAddressStruct = definePattern<Hex>(
16-
'EthAddress',
17-
/^0x[0-9a-f]{40}$/iu,
15+
const ETH_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/iu;
16+
export const EthAddressStruct = definePattern('EthAddress', ETH_ADDRESS_REGEX);
17+
// Stricter struct that uses `Hex` as final type.
18+
export const EthAddressStrictStruct = definePattern<Hex>(
19+
'EthAddressStrict',
20+
ETH_ADDRESS_REGEX,
1821
);
1922

2023
export const EthUint256Struct = definePattern(

0 commit comments

Comments
 (0)