Skip to content

x402: structural signer type (drop viem from public .d.ts) - #20

Merged
planadecu merged 1 commit into
mainfrom
fix/x402-structural-account
Sep 22, 2026
Merged

planadecu merged 1 commit into
mainfrom
fix/x402-structural-account

Conversation

@planadecu

Copy link
Copy Markdown
Owner

Makes glassnode-api/x402's public types independent of viem (an optional peer), fixing the
TS1541 the quality review flagged (§3.6.4) for consumers on moduleResolution: node16 with
skipLibCheck: false.

Change

  • Replace viem's LocalAccount in X402FetchOptions.account with a new structural
    X402SignerAccount interface ({ address: 0x…, signTypedData(...): Promise<0x…> }).
  • Method syntax on signTypedData keeps a real viem account assignable.
  • Removes the import type { LocalAccount } from 'viem' from the shipped x402 .d.ts (both CJS
    and ESM), so consumers no longer need viem's types to type-check the public API.

Why it's safe

  • viem's privateKeyToAccount(pk) is still assignable to account — proven by the type-checked
    integration test
    (test/x402.integration.spec.ts passes a real viem account and is compiled by
    the tsc -p tsconfig.test.json --noEmit CI gate).
  • No runtime change; the account is still passed opaquely to @x402/evm's ExactEvmScheme.

Verification

  • arethetypeswrong --pack .: 🟢 across node10/node16 (CJS)/node16 (ESM)/bundler for .,
    ./x402, ./package.json.
  • publint: clean. No viem import remains in dist/**/x402.d.ts.
  • 53 tests pass; test typecheck passes (viem assignability).

Minor bump (0.11.0) — adds the X402SignerAccount export; viem accounts remain compatible.

…viem

Replace viem's LocalAccount in X402FetchOptions.account with a new structural
X402SignerAccount interface. signTypedData uses `unknown` (method syntax keeps
viem accounts assignable, and unlike `never` the exported interface stays
callable for custom signers/test doubles). Removes the viem type import from
the shipped x402 .d.ts (both CJS and ESM), clearing TS1541 + ~12 transitive
errors for consumers on moduleResolution node16 with skipLibCheck:false.

Add a CI regression guard (typecheck/x402-node16/) that type-checks a node16
consumer of glassnode-api/x402 with skipLibCheck:false — the leak attw cannot
detect (it runs with skipLibCheck on). Verified: reintroducing the viem import
makes the fixture fail with 13 errors.

A viem privateKeyToAccount() stays assignable (type-checked integration test).
attw/publint green across all module modes; 53 tests pass. Bump 0.11.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P91z58rNwevTzvgcrzzeFV
@planadecu
planadecu force-pushed the fix/x402-structural-account branch from 9afa718 to 65ffdf6 Compare September 22, 2026 11:32
@planadecu
planadecu merged commit 35c185d into main Sep 22, 2026
3 checks passed
@planadecu
planadecu deleted the fix/x402-structural-account branch September 22, 2026 11:40
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.

1 participant