Skip to content
Open
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
6 changes: 6 additions & 0 deletions packages/eth-json-rpc-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#9754](https://github.com/MetaMask/core/pull/9754))

### Fixed

- Accept a numeric `chainId` in `eth_sendTransaction` and `eth_signTransaction` params ([#9965](https://github.com/MetaMask/core/pull/9965))
- `chainId` is now validated as a quantity (hex string or number), matching `gas`, `nonce`, `value`, and the other numerical fields
- Previously it was restricted to a string, so dapps sending a number were rejected with `-32602 Invalid params`

## [24.0.0]

### Changed
Expand Down
31 changes: 31 additions & 0 deletions packages/eth-json-rpc-middleware/src/utils/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,37 @@ describe('Validation Utils', () => {
).not.toThrow();
});

it('does not throw when `chainId` is a number', () => {
expect(() =>
validateTransactionParams({
from: VALID_FROM,
to: VALID_TO,
chainId: 1,
}),
).not.toThrow();
});

it('does not throw when `chainId` is a hex string', () => {
expect(() =>
validateTransactionParams({
from: VALID_FROM,
to: VALID_TO,
chainId: '0x1',
}),
).not.toThrow();
});

it('throws for an extraneous top-level key alongside a numeric `chainId`', () => {
expect(() =>
validateTransactionParams({
from: VALID_FROM,
to: VALID_TO,
chainId: 1,
extraKey: 'unexpected',
}),
).toThrow(/Invalid params/u);
});

it.each([
['null', null],
['undefined', undefined],
Expand Down
2 changes: 1 addition & 1 deletion packages/eth-json-rpc-middleware/src/utils/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const TransactionParamsStruct = object({
}),
),
),
chainId: optional(string()),
chainId: optional(QuantityStruct),
data: optional(string()),
from: string(),
gas: optional(QuantityStruct),
Expand Down