Repository navigation
fix(deps): upgrade ox to 1.8.16 and migrate p256 - #62
mariano-aguero wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Findings
.github/workflows/ci.yml:20No 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 whiledist/index.cjsfails to load on Node 22.11. CI also runs only on the latest Node 22, whererequire()of ES modules already works. Afterbun run build, add a job on the lowest supported Node version (20.19.0 with the currentengines, or 20.0 if ox is bundled into the CJS output) that runsnode -e "require('./dist/index.cjs'); require('./dist/viem.cjs')"and derives a P-256 account through the CJS entry.
There was a problem hiding this comment.
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.
|
@Ghadi8 On the |
Ghadi8
left a comment
There was a problem hiding this comment.
Line notes
tsup.config.ts:17tsup runs the configs in this array at the same time, and the ESM config'sclean: truedeletes files in dist/ (including all.d.ts/.d.ctsdeclarations, 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: repeatedbun run buildon a loaded machine ends withdist/index.d.ctsanddist/viem.d.ctsmissing 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 afterbun run buildwith no check of dist/, so a release can ship without types forrequireconsumers (attw reportsnode16 (from CJS): No types), and npm versions cannot be replaced. Suggest droppingcleanfrom both configs and clearing dist/ before tsup instead (e.g."build": "rm -rf dist && tsup"or anode -ermSync one-liner), and runningnode scripts/check-cjs.cjsand attw in release.yml between the build and semantic-release.package.json:95engines.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 declarenode >= 20.19.0. Bundling ox into the CJS build fixesrequire(), 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 withThe 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-strictwould fail the same way, and plain npm warns. Either set engines back to^20.19.0 || >=22.12.0, or keep>=20and document that Node 20.0-20.18 needs--ignore-enginesor produces engine warnings.
|
@Ghadi8 thanks, both line notes answered.
|
What this changes
Upgrades
oxfrom 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.nodestays>=20: ox is bundled into the CommonJS build sorequire()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.ProjectivePointno longer exists in noble v2, and at runtime thecatcharound 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 usesP256.noble.Point, types the derived key asReturnType<typeof P256.getPublicKey<'Object'>>, concatenates the hexx,y,randsdirectly, and passes hex values toP256.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
minimumReleaseAgeinbunfig.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.cjsdoesrequire('ox/P256'). On Node 20.0 to 20.18 and 22.0 to 22.11 that throwsERR_REQUIRE_ESM. The CommonJS build now bundles ox (noExternal: ['ox']in a separate tsup config), sodist/index.cjsgrows from about 52 KB to 160 KB and only requiresviem. 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 withERR_REQUIRE_ESMand passes with 5ea177a.Outputs are unchanged. Main and this branch were built and compared with
privateKeyToP256Accounton 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.signoutputs match byte for byte.CommonJS loading of the built
dist/index.cjsanddist/viem.cjswithrequire, followed by deriving an account and signing, was checked per Node version:require()of ES module ExperimentalWarning, later releases do not)ERR_REQUIRE_ESMwith ox external; with ox bundled into the CJS build they load and match, as do 20.0.0 and 24.21.0How the new behaviour is pinned
Which oracle covers this change, and why it could actually fail:
frame_tx_wire_tests.rsmaxCost, or thegasUseddecomposition)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, orencodeFrameTxvalidating?Checks
Only tick what you ran.
bun run testbun run typecheckbun run build && bunx @arethetypeswrong/cli --pack .(required ifexports,files,typesVersionsortsup.config.tschanged; otherwise N/A)bun run test:live(optional, hits the public endpoint, not a gate)bun install --frozen-lockfilepasses. 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:
docs,chore,test,ci,refactor,style,perf,build)fix)feat)feat!or aBREAKING 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.nodestill>=20, no supported consumer loses anything on the patch update, sofix:is accurate.AI assistance