Skip to content

Commit 2fe2a8d

Browse files
authored
feat: refine EthAddressStruct in order to make it compatible with the Hex type from @metamask/utils (#405)
<!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? Are there any issues or other links reviewers should consult to understand this pull request better? For instance: * Fixes #12345 * See: #67890 --> ## Examples <!-- Are there any examples of this change being used in another repository? When considering changes to the MetaMask module template, it's strongly preferred that the change be experimented with in another repository first. This gives reviewers a better sense of how the change works, making it less likely the change will need to be reverted or adjusted later. --> <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Type `EthAddressStruct` as `Hex` and update tests and changelog accordingly. > > - **Keyring API**: > - **Types**: Update `EthAddressStruct` to `definePattern<Hex>` and import `Hex` in `src/eth/types.ts`. > - **Changelog**: Note the `EthAddressStruct` refinement for `Hex` compatibility. > - **Snap Bridge Tests**: > - Import `Hex` and cast Ethereum addresses/`to` fields to `Hex` in `SnapKeyring.test.ts` to align with new typing. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 11df2a0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 6376bb7 commit 2fe2a8d

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

packages/keyring-api/CHANGELOG.md

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

1212
- Add `KeyringWrapper` base class to adapt legacy keyrings to `KeyringV2` ([#398](https://github.com/MetaMask/accounts/pull/398))
1313

14+
### Changed
15+
16+
- Refine `EthAddressStruct` in order to make it compatible with the `Hex` type from `@metamask/utils` ([#405](https://github.com/MetaMask/accounts/pull/405))
17+
1418
## [21.3.0]
1519

1620
### Added

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { object } from '@metamask/keyring-utils';
22
import type { Infer } from '@metamask/superstruct';
33
import { nonempty, array, enums, literal } from '@metamask/superstruct';
4-
import { definePattern } from '@metamask/utils';
4+
import { definePattern, type Hex } from '@metamask/utils';
55

66
import { EthScope } from '.';
77
import {
@@ -12,7 +12,7 @@ import {
1212

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

15-
export const EthAddressStruct = definePattern(
15+
export const EthAddressStruct = definePattern<Hex>(
1616
'EthAddress',
1717
/^0x[0-9a-f]{40}$/iu,
1818
);

packages/keyring-snap-bridge/src/SnapKeyring.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import type { HandleSnapRequest } from '@metamask/snaps-controllers';
4242
import { type SnapId } from '@metamask/snaps-sdk';
4343
import type { HandlerType } from '@metamask/snaps-utils';
4444
import { assert } from '@metamask/superstruct';
45-
import type { Json } from '@metamask/utils';
45+
import type { Hex, Json } from '@metamask/utils';
4646
import { KnownCaipNamespace, toCaipChainId } from '@metamask/utils';
4747
import { v4 as uuid } from 'uuid';
4848

@@ -154,7 +154,7 @@ describe('SnapKeyring', () => {
154154
};
155155
const ethErc4337Account = {
156156
id: 'fc926fff-f515-4eb5-9952-720bbd9b9849',
157-
address: '0x2f15b30952aebe0ed5fdbfe5bf16fb9ecdb31d9a'.toLowerCase(),
157+
address: '0x2f15b30952aebe0ed5fdbfe5bf16fb9ecdb31d9a'.toLowerCase() as Hex,
158158
options: {},
159159
methods: ETH_4337_METHODS,
160160
scopes: [EthScope.Testnet],
@@ -1976,12 +1976,12 @@ describe('SnapKeyring', () => {
19761976
it('calls eth_prepareUserOperation', async () => {
19771977
const baseTxs = [
19781978
{
1979-
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
1979+
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb' as Hex,
19801980
value: '0x0',
19811981
data: '0x',
19821982
},
19831983
{
1984-
to: '0x660265edc169bab511a40c0e049cc1e33774443d',
1984+
to: '0x660265edc169bab511a40c0e049cc1e33774443d' as Hex,
19851985
value: '0x0',
19861986
data: '0x619a309f',
19871987
},
@@ -2751,7 +2751,7 @@ describe('SnapKeyring', () => {
27512751
describe('prepareUserOperation', () => {
27522752
const mockIntents = [
27532753
{
2754-
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
2754+
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb' as Hex,
27552755
value: '0x0',
27562756
data: '0x',
27572757
},

0 commit comments

Comments
 (0)