Skip to content
Merged
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
13 changes: 13 additions & 0 deletions .changeset/fix-global-wallet-viem-peer-drift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@sei-js/sei-global-wallet': patch
---

Verify consumers against `viem@2.57.19`, and drop Viem's two `ws` advisories from the Bun waiver.

Dynamic published `@dynamic-labs/global-wallet-client@4.104.0` inside this package's `^4.96.3` range on November 3, raising the `viem` peer of the client and of `@dynamic-labs/ethereum-aa` from `^2.45.3` to `^2.54.2`. The consumer verifier still installed `viem@2.45.3`, so every nightly consumer run since then failed with `ERESOLVE` rather than on any change in this repository. Its full consumers now install `viem@2.57.19`, and the [Optional peer versions](https://github.com/sei-protocol/sei-js/blob/main/packages/sei-global-wallet/README.md#optional-peer-versions) table lists it as the verified version.

Every Viem inside `^2.54.2` depends on an Ox whose Tempo `VirtualMaster` miner loads `node:worker_threads` for its Node worker pool, which Vite resolves and reports as externalized for browser compatibility. No wallet path reaches the miner and it is tree-shaken out of the bundle, so the verifier now tolerates that one warning from `ox/_esm/tempo/internal/virtualMasterPool.js`. It still fails if Vite externalizes `node:worker_threads` for any other module, or if a browser or edge bundle contains a `worker_threads` path.

Viem 2.54.2 and later pin `ws@8.21.0`, outside both `GHSA-58qx-3vcg-4xpx` and `GHSA-96hv-2xvq-fx4p`, so the Bun AA consumer no longer reports them and they leave the Bun waiver. The scoped npm `ws` override stays in the [Required consumer overrides](https://github.com/sei-protocol/sei-js/blob/main/packages/sei-global-wallet/README.md#required-consumer-overrides) blocks for applications that still hold an older Viem; on current Viem it changes nothing.

No published dependency or peer range changes.
12 changes: 5 additions & 7 deletions packages/sei-global-wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,21 @@ Applications using the optional `./zerodev` / Dynamic account-abstraction path m

Bun 1.3.14 does not support nested overrides. Do **not** globally override `bn.js` or `ws`: Solana/borsh require bn5 while Jayson requires ws7. Bun's complete root override block is therefore the same with or without the optional AA path.

For npm, scoped `bn.js@4.12.5` stays on the legacy dependencies' expected major while Solana resolves `bn.js@5.2.5`. Scoped `ws@8.21.0` patches Viem's ws8 subtree while Jayson resolves `ws@7.5.13` from its `^7.5.10` range. With the overrides above, a wallet-only npm install audits clean; the optional AA path carries the three `stream-json` advisories described below, on npm and Bun alike.
For npm, scoped `bn.js@4.12.5` stays on the legacy dependencies' expected major while Solana resolves `bn.js@5.2.5`. Scoped `ws@8.21.0` patches the ws8 subtree of any Viem older than 2.54.2, while Jayson resolves `ws@7.5.13` from its `^7.5.10` range. Viem 2.54.2 and later, which Dynamic 4.104.0 and later require, already pin `ws@8.21.0`, so on those the override changes nothing. With the overrides above, a wallet-only npm install audits clean; the optional AA path carries the three `stream-json` advisories described below, on npm and Bun alike.

The verifier builds its browser consumer against `viem@2.45.3`, because the previously tested 2.55.19 pulls Ox Tempo's `node:worker_threads` path into Vite resolution while 2.45.3 predates it. That is a property of the verifier's own bundle, not a constraint on applications: the published `viem` peer range stays `^2.7.12`. If your bundler externalizes `node:worker_threads` on a newer Viem, configure it in your application rather than downgrading.
The verifier builds its browser consumer against `viem@2.57.19`, because Dynamic 4.104.0 raised its `viem` peer to `^2.54.2`. Every Viem in that range depends on an Ox whose Tempo `VirtualMaster` miner loads `node:worker_threads` for its Node worker pool, so Vite warns that it externalized `node:worker_threads` for `ox/_esm/tempo/internal/virtualMasterPool.js`. No wallet path reaches the miner, and it is tree-shaken out of the bundle. The verifier tolerates that one warning, and still fails if Vite externalizes `node:worker_threads` for any other module or if a browser or edge bundle contains a `worker_threads` path. The published `viem` peer range stays `^2.7.12`. If your own Vite build prints the same warning, it comes from Viem's Ox dependency rather than this package.

Three advisories on the optional AA path have no fix any override can reach, on either package manager. All three are on `stream-json@1.9.1`, which the Solana RPC client's `jayson` requires as CommonJS. Every release outside them is ESM-only under a moved `src/` layout (`3.5.0` onward for the first, `3.6.0` onward for the other two), so overriding `stream-json` to a fixed version replaces the advisories with a `MODULE_NOT_FOUND` on `jayson`'s own require. `jayson` loads `stream-json` only in its TCP and TLS transports, and the Solana RPC client uses `jayson/lib/client/browser`, which never does:

- `GHSA-528h-pc64-c93x` — moderate, CVSS 6.2. An `O(depth²)` slowdown in the `pick`/`ignore`/`filter`/`replace` filters, reachable only by feeding crafted deeply nested JSON through them, which no wallet path does.
- `GHSA-hqr4-qq8f-hg3x` — moderate, CVSS 6.2. A quadratic re-scan of long comments in the JSONC parser and verifier. `stream-json@1.9.1` ships no JSONC parser, so the advisory matches it by version range only.
- `GHSA-mjw6-4jj6-33hc` — moderate, CVSS 5.1. A `__proto__` key in streamed JSON replaces the prototype of the object `Assembler` builds. `jayson` parses streams that way only in its TCP and TLS transports.

For Bun, scoped overrides are unavailable, so the waiver also accepts these advisories that npm resolves with the scoped blocks above, while preserving compatible majors:
For Bun, scoped overrides are unavailable, so the waiver also accepts this advisory that npm resolves with the scoped blocks above, while preserving compatible majors:

- `GHSA-378v-28hj-76wf` on `bn.js@4.11.6` — moderate, CVSS 5.3.
- `GHSA-58qx-3vcg-4xpx` on Viem's `ws@8.18.3` — moderate, CVSS 4.4.
- `GHSA-96hv-2xvq-fx4p` on Viem's `ws@8.18.3` — high, CVSS 7.5.

Jayson remains on `ws@7.5.13`; globally forcing ws8 would violate that major contract. The verifier fails on any advisory outside each waiver, and reports rather than fails when one of them stops being reported, so an upstream fix or a withdrawn advisory never turns an unrelated pull request red. The wallet-only npm consumer is held to a strictly clean audit with no waiver at all, so nothing here excuses a finding that a default install would hand an application.
Viem's `ws` advisories `GHSA-58qx-3vcg-4xpx` and `GHSA-96hv-2xvq-fx4p` are no longer waived, because Viem 2.54.2 and later pin the fixed `ws@8.21.0`. A Bun application that holds an older Viem should upgrade it rather than override `ws` globally: Jayson remains on `ws@7.5.13`, and globally forcing ws8 would violate that major contract. The verifier fails on any advisory outside each waiver, and reports rather than fails when one of them stops being reported, so an upstream fix or a withdrawn advisory never turns an unrelated pull request red. The wallet-only npm consumer is held to a strictly clean audit with no waiver at all, so nothing here excuses a finding that a default install would hand an application.

## Quick start

Expand Down Expand Up @@ -137,7 +135,7 @@ Install only the peers needed by the subpaths your application uses. The declare

| Peer | Declared range | Verified against | Needed by |
| --- | --- | --- | --- |
| `viem` | `^2.7.12` | `2.45.3` | `./zerodev`, Dynamic AA |
| `viem` | `^2.7.12` | `2.57.19` | `./zerodev`, Dynamic AA |
| `@dynamic-labs/ethereum-aa` | `^4.15.0` | `4.96.3+` (exact client match) | `./zerodev` |
| `@zerodev/sdk` | `^5.4.36` | `5.5.7` | `./zerodev` |
| `@solana/web3.js` | `^1.92.1` | `1.98.1` | `./solana` |
Expand Down
38 changes: 23 additions & 15 deletions scripts/check-sei-global-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,7 @@ const fastCheck = process.env.SEI_GLOBAL_WALLET_FAST_CHECK === '1';
// requires it, and every version outside its advisories is ESM-only under a
// moved `src/` layout, so an override turns them into a MODULE_NOT_FOUND.
const acceptedNpmAdvisories: readonly string[] = ['GHSA-528h-pc64-c93x', 'GHSA-hqr4-qq8f-hg3x', 'GHSA-mjw6-4jj6-33hc'];
const acceptedBunAdvisories: readonly string[] = [
'GHSA-378v-28hj-76wf',
'GHSA-528h-pc64-c93x',
'GHSA-58qx-3vcg-4xpx',
'GHSA-96hv-2xvq-fx4p',
'GHSA-hqr4-qq8f-hg3x',
'GHSA-mjw6-4jj6-33hc'
];
const acceptedBunAdvisories: readonly string[] = ['GHSA-378v-28hj-76wf', 'GHSA-528h-pc64-c93x', 'GHSA-hqr4-qq8f-hg3x', 'GHSA-mjw6-4jj6-33hc'];

const manifest = JSON.parse(await readFile(join(packageDir, 'package.json'), 'utf8')) as {
dependencies: Record<string, string>;
Expand Down Expand Up @@ -151,12 +144,20 @@ const makeTestedPeerVersions = (ethereumAa: string) =>
'@wallet-standard/features': '^1.0.3',
'@wallet-standard/wallet': '^1.1.0',
'@zerodev/sdk': '5.5.7',
viem: '2.45.3',
viem: '2.57.19',
'zksync-sso': '0.2.0'
}) as const;

type TestedPeerVersions = ReturnType<typeof makeTestedPeerVersions>;

// Current Viem releases depend on an Ox that ships a Tempo `VirtualMaster`
// miner, whose Node worker pool imports `node:worker_threads` through a
// constant. Vite resolves it, and warns, while loading the module graph. No
// wallet path reaches the miner and it is tree-shaken out, which the bundle
// scan in runBrowserBundle enforces, so it is the only importer the Vite check
// tolerates.
const toleratedWorkerThreadsImporter = /(?:^|\/)node_modules\/ox\/_esm\/tempo\/internal\/virtualMasterPool\.js$/;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] (?:^|\/)node_modules\/ox\/... also matches a nested copy such as node_modules/viem/node_modules/ox/..., which seems intended. Note that the safety argument depends on the bundle scans in runBrowserBundle/edge (!bundle.includes('node:worker_threads')) staying in place. If those scans are ever relaxed, this tolerance should be revisited too.


const assertTestedPeersFitPublishedRanges = (testedPeerVersions: TestedPeerVersions) => {
// Guards the two from drifting: every version the harness installs has to be
// allowed by the range the package publishes. This is what catches Dynamic
Expand Down Expand Up @@ -897,7 +898,7 @@ try {
assert.equal(npmLock.packages['node_modules/number-to-bn/node_modules/bn.js']?.version, '4.12.5');
assertMajor(npmLock.packages['node_modules/bn.js']?.version, '5', 'hoisted bn.js');
assert.equal(npmLock.packages['node_modules/ws']?.version, '8.21.0');
assert.equal(npmLock.packages['node_modules/viem']?.dependencies?.ws, '8.18.3');
assert.equal(npmLock.packages['node_modules/viem']?.dependencies?.ws, '8.21.0');
assert.equal(npmLock.packages['node_modules/jayson']?.dependencies?.ws, '^7.5.10');
assertMajor(npmLock.packages['node_modules/jayson/node_modules/ws']?.version, '7', 'jayson nested ws');
await run(['node', 'check-ssr.mjs'], npmConsumerDir);
Expand Down Expand Up @@ -940,11 +941,18 @@ try {
// Vite routes externalization warnings through its own logger, which writes
// to stdout in most versions, so scan both streams.
const viteOutput = `${viteBuild.stdout}\n${viteBuild.stderr}`;
assert.doesNotMatch(
viteOutput,
/(?:node:)?worker_threads.*externaliz|externaliz.*(?:node:)?worker_threads/i,
`Vite externalized worker_threads:\n${viteOutput}`
const workerThreadsExternalizations = viteOutput
.split('\n')
.filter((line) => /(?:node:)?worker_threads.*externaliz|externaliz.*(?:node:)?worker_threads/i.test(line));
const unexpectedExternalizations = workerThreadsExternalizations.filter(
(line) => !toleratedWorkerThreadsImporter.test(line.match(/imported by "([^"]+)"/)?.[1]?.replaceAll('\\', '/') ?? '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nit] This fails closed when a matching line has no imported by "..." clause (the importer becomes '', so the line counts as unexpected), which is the right default. But Vite's warning format and ANSI colouring vary by version, and a future format change would produce a confusing failure. Consider adding a short comment saying the parse is deliberately fail-closed, and printing only unexpectedExternalizations in the assertion message rather than the full viteOutput, so the failing line is easy to find.

);
assert.deepEqual(unexpectedExternalizations, [], `Vite externalized worker_threads:\n${viteOutput}`);
if (workerThreadsExternalizations.length === 0) {
reportWaiverProgress(
"Vite no longer externalizes node:worker_threads for Ox's Tempo miner. Remove toleratedWorkerThreadsImporter from this script and the Vite note from packages/sei-global-wallet/README.md."
);
}
const viteFiles = (await readdir(join(npmConsumerDir, 'vite-dist'))).filter((path) => path.endsWith('.js'));
assert.equal(viteFiles.length, 1, `Expected one Vite bundle, found: ${viteFiles.join(', ')}`);
await runBrowserBundle(join(npmConsumerDir, 'vite-dist', viteFiles[0]), true);
Expand All @@ -971,7 +979,7 @@ try {
console.log(
fastCheck
? 'Sei Global Wallet fast npm consumer checks passed.'
: 'Sei Global Wallet consumer checks passed: the wallet-only npm consumer audited clean, npm scoped patched bn.js/ws8 while preserving Solana bn5/Jayson ws7, and both full consumers stayed within the accepted advisory waiver.'
: 'Sei Global Wallet consumer checks passed: the wallet-only npm consumer audited clean, npm scoped patched bn.js while preserving Solana bn5/Jayson ws7, and both full consumers stayed within the accepted advisory waiver.'
);
} finally {
await rm(temporaryRoot, { force: true, recursive: true });
Expand Down
Loading