Skip to content

Enforce chainId - #324

Merged
estebanmino merged 11 commits into
developfrom
enforce-chain-id
Jan 19, 2021
Merged

estebanmino merged 11 commits into
developfrom
enforce-chain-id

Conversation

@estebanmino

Copy link
Copy Markdown
Contributor

This PR makes sure that all custom rpc networks have a valid chainId, and disregard the usage of networkId in favor of chainId

@estebanmino
estebanmino requested a review from a team as a code owner January 13, 2021 18:35
This reverts commit 20b0adb.

@rekmarks rekmarks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good! Just a few questions and requests.

Comment thread src/network/NetworkController.ts Outdated
Comment thread src/transaction/TransactionController.ts
Comment on lines +15 to +21
mainnet = '1',
kovan = '42',
rinkeby = '4',
goerli = '5',
ropsten = '3',
localhost = '',
rpc = '',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we store these in hexadecimal instead?

Possibly related: #326

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll do it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh wait, this would need a migration as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

for transactions, I'd put that together with the work on the tx controller

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We decided to do this in a follow-up.

Comment thread tests/TransactionController.test.ts Outdated

@rekmarks rekmarks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@estebanmino
estebanmino merged commit 23cdb2d into develop Jan 19, 2021
@estebanmino
estebanmino deleted the enforce-chain-id branch January 19, 2021 15:54
Mrtenz pushed a commit that referenced this pull request Oct 16, 2025
* 13.0.1

This is the release candidate for version 14.0.0.

---------

Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: Jongsun Suh <jongsun.suh@icloud.com>
Co-authored-by: cryptodev-2s <109512101+cryptodev-2s@users.noreply.github.com>
Naz-Ovh pushed a commit to 0x-fork/metamask-core that referenced this pull request Sep 13, 2026
Replaces MetaMask#324, which GitHub auto-closed as merged during a stack reorder
when its head briefly became an ancestor of its base. The changes never
reached `main`; this carries the same two commits.

Mirrors
[MetaMask#9976](MetaMask#9976), the
bottom of core's foundational stack.

| | Before | After |
| --- | --- | --- |
| `engines.node` | `^18.18 \|\| ^20.14 \|\| >=22` | `^22.14.0 \|\| ^24`
|
| `@types/node` | `~18.18.14` | `^22.13.14` |
| CI matrix | 18, 20, 22 | 22, 24 |

`constraints.pro` is updated so `yarn constraints` enforces the new
range. Core makes the `@types/node` bump in this same PR rather than
with its TypeScript change, since the types track the supported runtime.

## Position in the stack

This now sits **below** the ESM conversion (MetaMask#323), so everything up to
and including this PR is still a hybrid CJS/ESM build:

```
main → … → MetaMask#322 → this → MetaMask#323 (ESM only) → MetaMask#325 (TypeScript)
```

That matters for testing. A preview build from here still resolves
through `main: ./dist/index.cjs` with the `require` condition intact, so
it can be consumed by `metamask-extension` as-is. Everything below the
ESM cut can therefore be verified against a real downstream consumer
before the breaking change lands.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Semver-breaking runtime requirement may block consumers still on Node
18 or 20; in-repo changes are mostly policy, CI, and test cleanup with
limited logic impact.
> 
> **Overview**
> **Breaking:** supported Node is now `^22.14.0 || ^24` instead of
18/20/22. That is enforced in `package.json`, `constraints.pro`, and
documented under Unreleased in `CHANGELOG.md`.
> 
> CI **prepare**, **test**, and **compatibility-test** jobs now run on
Node **22.x** and **24.x** only (18 and 20 dropped from the matrix). Dev
typings move from `@types/node` ~18 to **^22.13.14**, with matching
`yarn.lock` updates.
> 
> Test and lint tooling align with the new floor: ESLint comments for
`n/no-unsupported-features/node-builtins` reflect that global `crypto`
is expected on 22+, and `hashing.test.ts` drops the Node 18 `webcrypto`
polyfill/`beforeEach` setup—tests assume `globalThis.crypto.subtle`
exists.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
ba81eca2d4fa1d9a00faa1bd7e975d1b5d02fc8d. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Naz-Ovh pushed a commit to 0x-fork/metamask-core that referenced this pull request Sep 13, 2026
Top of stack MetaMask#315, on MetaMask#324. Mirrors
[MetaMask#9518](MetaMask#9518).

| | Before | After |
| --- | --- | --- |
| `packageManager` | `yarn@4.16.0` | `yarn@4.17.1` |
| `typescript` | `~5.3.3` | `npm:@typescript/typescript6@^6.0.2` |
| `@typescript/native` | — | `npm:typescript@^7.0.2` |

## Why not just bump to TypeScript 7

I tried that first. It fails for two independent reasons:

**1. Yarn.** 4.16.0 auto-applies a builtin `compat/typescript` patch
targeting `lib/_tsc.js`. That file doesn't exist in TS 7, which is the
native port with a different layout, so the install fails outright:

```
typescript@patch:typescript@npm%3A7.0.2#optional!builtin<compat/typescript>
ENOENT: no such file or directory, lstat '.../typescript/lib/_tsc.js'
```

Yarn 4.17.1 resolves it, which is why core bumps the package manager in
the same PR.

**2. typescript-eslint.** With the install fixed, linting then
hard-errors:

```
typescript-eslint does not support TS 7.0.
Please see ... to run typescript-eslint using the TS 6 API.
```

Tracked upstream at
[typescript-eslint#10940](typescript-eslint/typescript-eslint#10940).

So the aliases aren't incidental overhead. Resolving `typescript` to the
**TS 6 API** is what keeps `typescript-eslint`, `ts-jest` and `typedoc`
working, while TS 7 sits alongside as `@typescript/native`. Compilation
runs on 6.0.3; nothing in the toolchain can consume 7 yet. Same position
core is in.

## Source changes

Two, both from `Uint8Array` becoming generic:

- **`hashing.ts`** — `crypto.subtle.digest` takes a `BufferSource`,
which no longer accepts a plain `Uint8Array` because the buffer could be
a `SharedArrayBuffer`. Asserted at the three call sites rather than
narrowing the exported signatures, which would break callers.
- **`errors.ts`** — `no-base-to-string` now sees that `String(error)`
can produce `[object Object]`. That is the documented fallback of
`getErrorMessage`, so it's suppressed with a reason.

## Not carried over

Core's third entry, `@typescript/old`, is a patched 6.0.3 pointing at a
patch file in core's own `.yarn/patches`. Nothing here needs it and its
contents aren't reproducible from outside that repo.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Toolchain-wide TypeScript/Yarn changes can surface build or lint
regressions; hashing changes touch crypto paths but preserve digest
output via the noble fallback.
> 
> **Overview**
> Aligns the repo with MetaMask core’s **TypeScript 6 + native TS 7**
setup: **`typescript`** resolves to **`@typescript/typescript6@^6.0.2`**
(so **typescript-eslint**, **ts-jest**, and **typedoc** keep working),
adds **`@typescript/native`** (TS 7) alongside, bumps **Yarn** to
**4.17.1**, and refreshes the lockfile.
> 
> **Jest/ts-jest** gets **`ignoreDeprecations: '6.0'`** so test
compilation can keep **`moduleResolution: 'Node'`** under TS 6 without
noise.
> 
> Two small **source** fixes for stricter TS 6 types: **`hashing.ts`**
only calls **`crypto.subtle.digest`** when input bytes are backed by an
**`ArrayBuffer`** (otherwise **noble**), avoiding runtime errors on
**`SharedArrayBuffer`** views while keeping public APIs unchanged.
**`getErrorMessage`** adds a targeted **`no-base-to-string`**
suppression for the intentional **`String(error)`** fallback.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
aac3fa43658ca1e6db082bd80fb06d132caf6fc6. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
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