Skip to content

fix(deps): upgrade ox to 1.8.16 and migrate p256 - #62

Open
mariano-aguero wants to merge 5 commits into
mainfrom
fix/ox-1.8.16
Open

mariano-aguero wants to merge 5 commits into
mainfrom
fix/ox-1.8.16

Conversation

@mariano-aguero

@mariano-aguero mariano-aguero commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What this changes

Upgrades ox from 0.14.45 to 1.8.16 and moves the P-256 code to the ox 1.x API, which now uses noble v2 and returns public key coordinates and signature scalars as 32-byte hex instead of bigints. engines.node stays >=20: ox is bundled into the CommonJS build so require() keeps working on every Node 20 and 22 release.

Supersedes #61.

Why

The Dependabot bump in #61 fails typecheck in CI because the ox 1.x P-256 API changed. P256.noble.ProjectivePoint no longer exists in noble v2, and at runtime the catch around it turned the missing class into "P-256 public key is not a point on the curve", so every valid key would have been rejected. This PR uses P256.noble.Point, types the derived key as ReturnType<typeof P256.getPublicKey<'Object'>>, concatenates the hex x, y, r and s directly, and passes hex values to P256.verify.

It pins 1.8.16 instead of 1.8.13 because 1.8.13 was published without npm provenance and 1.8.16 has it. 1.8.16 is also older than the 7-day minimumReleaseAge in bunfig.toml, and its P-256 code is the same as in 1.8.13.

Consumer-facing change: ox 1.x ships as ESM only, and dist/index.cjs does require('ox/P256'). On Node 20.0 to 20.18 and 22.0 to 22.11 that throws ERR_REQUIRE_ESM. The CommonJS build now bundles ox (noExternal: ['ox'] in a separate tsup config), so dist/index.cjs grows from about 52 KB to 160 KB and only requires viem. The ESM build is unchanged and keeps ox external. A new CI job, cjs-oldest-node, builds and then loads both CJS entries on Node 20.0.0 and checks the derived P-256 address and signature against the ESM build. It failed on 2c9c01d with ERR_REQUIRE_ESM and passes with 5ea177a.

Outputs are unchanged. Main and this branch were built and compared with privateKeyToP256Account on 67 deterministic private keys (27 of them with one or more leading zero bytes, plus the scalars 1 and 2) against 6 digests each, including one with a leading zero byte and the zero digest. Address, public key and all 402 .sign outputs match byte for byte.

CommonJS loading of the built dist/index.cjs and dist/viem.cjs with require, followed by deriving an account and signing, was checked per Node version:

  • 20.19.0, 20.20.1, 22.12.0, 22.23.3, 24.21.0: works (22.12.0 prints the require() of ES module ExperimentalWarning, later releases do not)
  • 20.18.0, 22.11.0: ERR_REQUIRE_ESM with ox external; with ox bundled into the CJS build they load and match, as do 20.0.0 and 24.21.0

How the new behaviour is pinned

Which oracle covers this change, and why it could actually fail:

  • A published figure, transcribed rather than derived
  • The golden byte vector or sig-hash from ethrex's frame_tx_wire_tests.rs
  • Re-encoding captured chain data and reproducing the transaction hash
  • A live receipt (recovered signer, maxCost, or the gasUsed decomposition)
  • N/A, this change has no wire-format or gas behaviour

The existing P-256 tests cover key validation and signing, and the byte-for-byte comparison against main above covers the signing output.

Load-bearing rules

Did this touch anything under "Rules that are not style preferences" in CONTRIBUTING.md, such as a derived gas constant, a golden vector, a captured fixture, the module import order, or encodeFrameTx validating?

  • No
  • Yes, and the argument for it is below

Checks

Only tick what you ran.

  • bun run test
  • bun run typecheck
  • bun run build && bunx @arethetypeswrong/cli --pack . (required if exports, files, typesVersions or tsup.config.ts changed; otherwise N/A)
  • bun run test:live (optional, hits the public endpoint, not a gate)

bun install --frozen-lockfile passes. 373 tests pass, the same count as main. arethetypeswrong reports no problems, the same output as on main.

Release impact

The commit history sets the version, so say which this is:

  • No release (docs, chore, test, ci, refactor, style, perf, build)
  • Patch (fix)
  • Minor (feat)
  • Major (feat! or a BREAKING CHANGE: footer)

A wire-format or gas change is almost always at least a fix:, because someone downstream is encoding bytes with this.

Ships as 0.5.1. With ox bundled into the CommonJS build and engines.node still >=20, no supported consumer loses anything on the patch update, so fix: is accurate.

AI assistance

  • This change was written or reviewed with an assistant, and I have read every line of it

@justalab-agents justalab-agents Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR upgrades the ox dependency from v0.14.x to v1.8.x (a major version bump), adapting the codebase to the new API where P-256 public key coordinates and signature r/s values are now Hex strings rather than BigInts. The changes also update the Point.fromHex reference (replacing ProjectivePoint.fromHex) and tighten the Node.js engine requirement to versions that support the require(esm) flag (^20.19.0 || >=22.12.0). The lockfile warning about missing pnpm-lock.yaml is a non-issue since this project uses Bun's lockfile (bun.lock), which is properly updated.

Findings outside the diff

These sit on lines this PR did not change, but this PR is what makes them wrong. They cannot be posted as inline comments.

  • [WARNING] package.json — package.json has dependency changes but no pnpm-lock.yaml update was found in this PR. Commit the lockfile together with manifest changes.

@Ghadi8 Ghadi8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Findings

  • .github/workflows/ci.yml:20 No CI step loads the built CommonJS entries, so this kind of break goes unnoticed: on this branch the test suite and the attw type-resolution check both pass while dist/index.cjs fails to load on Node 22.11. CI also runs only on the latest Node 22, where require() of ES modules already works. After bun run build, add a job on the lowest supported Node version (20.19.0 with the current engines, or 20.0 if ox is bundled into the CJS output) that runs node -e "require('./dist/index.cjs'); require('./dist/viem.cjs')" and derives a P-256 account through the CJS entry.

Comment thread package.json Resolved
Comment thread package.json Resolved
@mariano-aguero mariano-aguero added dependencies Pull requests that update a dependency file signatures Area: signatures labels Nov 25, 2026

@justalab-agents justalab-agents Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewer callouts (3)

Non-blocking observations. Nothing here needs to change before merge.

  • .github/workflows/ci.yml:59 — Pin to a full commit SHA for reproducible builds (e.g. actions/checkout@ # v7).
  • .github/workflows/ci.yml:69 — Pin to a full commit SHA for reproducible builds (e.g. actions/setup-node@ # v7).
  • scripts/check-cjs.cjs:22 — Debug console statement should be removed before merging.

Comment thread .github/workflows/ci.yml Resolved
@mariano-aguero

Copy link
Copy Markdown
Collaborator Author

@Ghadi8 On the .github/workflows/ci.yml:20 finding: added a cjs-oldest-node job in 2c9c01d. After bun run build it switches to Node 20.0.0 and runs scripts/check-cjs.cjs, which requires dist/index.cjs and dist/viem.cjs and checks that a P-256 account derived through the CJS entry has the same address and signature as the ESM build. It failed on 2c9c01d with ERR_REQUIRE_ESM (run) and passes with the fix in 5ea177a (run).

@Ghadi8 Ghadi8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Line notes

  • tsup.config.ts:17 tsup runs the configs in this array at the same time, and the ESM config's clean: true deletes files in dist/ (including all .d.ts/.d.cts declarations, from its dts worker's buildStart hook) without waiting for the CJS config. When the CJS declarations are written before that clean runs, they are deleted: repeated bun run build on a loaded machine ends with dist/index.d.cts and dist/viem.d.cts missing in about 1 run in 17, and the build still exits 0. The CJS entries can in principle go the same way, since the main-task clean is not ordered against the CJS write either. release.yml publishes straight after bun run build with no check of dist/, so a release can ship without types for require consumers (attw reports node16 (from CJS): No types), and npm versions cannot be replaced. Suggest dropping clean from both configs and clearing dist/ before tsup instead (e.g. "build": "rm -rf dist && tsup" or a node -e rmSync one-liner), and running node scripts/check-cjs.cjs and attw in release.yml between the build and semantic-release.
  • package.json:95 engines.node stays >=20, but ox 1.8.16 pulls in @noble/curves, @noble/hashes, @noble/ciphers 2.4.0 and @noble/post-quantum 0.6.1, which all declare node >= 20.19.0. Bundling ox into the CJS build fixes require(), but ox is still a runtime dependency, so those packages are still installed (and the ESM build still imports them). On Node 20.0-20.18, a Yarn 1 install of this package now fails with The engine "node" is incompatible with this module. Expected version ">= 20.19.0" on @noble/ciphers. The same install with ox 0.14.45 succeeds. npm --engine-strict would fail the same way, and plain npm warns. Either set engines back to ^20.19.0 || >=22.12.0, or keep >=20 and document that Node 20.0-20.18 needs --ignore-engines or produces engine warnings.

@mariano-aguero

Copy link
Copy Markdown
Collaborator Author

@Ghadi8 thanks, both line notes answered.

tsup.config.ts:17 (clean race). Fixed in b66a8e7. Neither config sets clean now, and build is rm -rf dist && tsup, so nothing deletes files while the two configs run. I couldn't reproduce the missing .d.cts locally (55 builds, 25 of them with every core busy, all 8 entry files present each time), but tsup 8.5.1's source matches your description: the dts plugin removes **/*.d.{ts,mts,cts} in buildStart when clean is set, with no ordering against the other config. release.yml now runs node scripts/check-cjs.cjs and attw between the build and the publish step. I checked that the attw step fails (exit 1, node16 (from CJS): No types) when dist/index.d.cts is deleted after a build.

package.json:95 (engines). Leaving >=20 as decided. The runtime path doesn't need 20.19: the built ESM and CJS entries both load on Node 20.0.0 and 20.18.0, derive the same P-256 account and sign (scripts/check-cjs.cjs already imports dist/index.js too, and the cjs-oldest-node job runs it on 20.0.0). The noble 2.x packages declare >= 20.19.0 because they ship ESM only and that's where require() of ESM works; the one newer API they touch, Uint8Array.fromHex, is feature-detected with a fallback. You're right that the install-time check is still there: Yarn 1 and npm --engine-strict reject Node 20.0 to 20.18 through those transitive engines, and plain npm warns. Whether to document that in the README or move engines to ^20.19.0 || >=22.12.0 (a different release type) is the maintainer's call, so I've left it open here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file signatures Area: signatures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants