Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/keyring-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `EthAddressStrictStruct` struct and `EthAddressStrict` types ([#465](https://github.com/MetaMask/accounts/pull/465))
- This is a stricter variant of `EthAddressStruct` which uses `Hex` instead of `string` for its inferred type.

### Changed

- Re-use `string` for ERC4337 address-like fields ([#465](https://github.com/MetaMask/accounts/pull/465))
- This change reverts that and keeps using `string` for all address-like types.
- 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.
- Version [21.4.0] will be marked as **YANKED**, consumers are expected to use this new version that reverts this breaking change.

## [21.4.0]

### Added
Expand Down
8 changes: 6 additions & 2 deletions packages/keyring-api/src/eth/rpc/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
unknown,
} from '@metamask/superstruct';

import { EthAddressStruct, EthBytesStruct } from '../types';
import {
EthAddressStrictStruct,
EthAddressStruct,
EthBytesStruct,
} from '../types';

/**
* A struct for validating Ethereum transaction data.
Expand Down Expand Up @@ -118,7 +122,7 @@ export type EthEncryptedData = Infer<typeof EthEncryptedDataStruct>;
*/
export const EthEip7702AuthorizationStruct = tuple([
number(), // chainId
EthAddressStruct, // address (contract to delegate to)
EthAddressStrictStruct, // address (contract to delegate to)
number(), // nonce
]);

Expand Down
9 changes: 6 additions & 3 deletions packages/keyring-api/src/eth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import {

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

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

export const EthUint256Struct = definePattern(
Expand Down
Loading