diff --git a/analytics/package-lock.json b/analytics/package-lock.json index 87ece444e..3c0f7f01d 100644 --- a/analytics/package-lock.json +++ b/analytics/package-lock.json @@ -25,7 +25,7 @@ "serverless-scaleway-functions": ">=0.4.16", "tsdown": "^0.23.1", "tsx": "^4.23.5", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^4.1.11" }, @@ -8107,9 +8107,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "devOptional": true, "license": "Apache-2.0", "bin": { diff --git a/analytics/package.json b/analytics/package.json index d320c0298..b7c3fbf5c 100644 --- a/analytics/package.json +++ b/analytics/package.json @@ -49,7 +49,7 @@ "serverless-scaleway-functions": ">=0.4.16", "tsdown": "^0.23.1", "tsx": "^4.23.5", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^4.1.11" }, diff --git a/analytics/test/stats.test.ts b/analytics/test/stats.test.ts index 7e5a29123..3575e8545 100644 --- a/analytics/test/stats.test.ts +++ b/analytics/test/stats.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; -import { privateKeyToAccount } from "viem/accounts"; +import { privateKeyToAccount } from "@fretchen/chain-utils"; // The handler's module-level storage is S3HitStorage; the range logic below is // tested directly against MemoryHitStorage instead. diff --git a/bunny_js/package-lock.json b/bunny_js/package-lock.json index 1a148b2b3..d44c84650 100644 --- a/bunny_js/package-lock.json +++ b/bunny_js/package-lock.json @@ -27,7 +27,7 @@ "prettier": "^3.6.2", "tsdown": "^0.23.1", "tsx": "^4.23.15", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.58.2", "vitest": "^4.1.11" } @@ -3912,9 +3912,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "devOptional": true, "license": "Apache-2.0", "bin": { diff --git a/bunny_js/package.json b/bunny_js/package.json index e482942ab..10efa30fd 100644 --- a/bunny_js/package.json +++ b/bunny_js/package.json @@ -42,7 +42,7 @@ "prettier": "^3.6.2", "tsdown": "^0.23.1", "tsx": "^4.23.15", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.58.2", "vitest": "^4.1.11" }, diff --git a/bunny_js/src/facilitator/chain_utils.ts b/bunny_js/src/facilitator/chain_utils.ts index 8ec7c34ad..20a450f5b 100644 --- a/bunny_js/src/facilitator/chain_utils.ts +++ b/bunny_js/src/facilitator/chain_utils.ts @@ -5,7 +5,6 @@ * Uses @fretchen/chain-utils for chain/address data. */ -import type { Chain } from "viem"; import { getViemChain, tryGetEIP3009SplitterAddress, @@ -14,6 +13,7 @@ import { getSettlementTokens, type Network, type SettlementTokenInfo, + type Chain, } from "@fretchen/chain-utils"; export interface ChainConfig { diff --git a/bunny_js/src/facilitator/facilitator_instance.ts b/bunny_js/src/facilitator/facilitator_instance.ts index 3470d9224..ec5c90a30 100644 --- a/bunny_js/src/facilitator/facilitator_instance.ts +++ b/bunny_js/src/facilitator/facilitator_instance.ts @@ -10,7 +10,7 @@ * schemes coexist on the same /verify and /settle endpoints. */ -import { createPublicClient, createWalletClient, http, type Account } from "viem"; +import { createPublicClient, createWalletClient, http, type Account } from "@fretchen/chain-utils"; import { x402Facilitator } from "@x402/core/facilitator"; import { toFacilitatorEvmSigner } from "@x402/evm"; import { ExactEvmScheme } from "@x402/evm/exact/facilitator"; diff --git a/bunny_js/src/facilitator/x402_fee.ts b/bunny_js/src/facilitator/x402_fee.ts index db678f234..06fedd56a 100644 --- a/bunny_js/src/facilitator/x402_fee.ts +++ b/bunny_js/src/facilitator/x402_fee.ts @@ -17,14 +17,14 @@ import { http, getContract, nonceManager, + privateKeyToAccount, + loadPrivateKey, WaitForTransactionReceiptTimeoutError, type Address, type Abi, type Hex, -} from "viem"; -import { privateKeyToAccount } from "viem/accounts"; +} from "@fretchen/chain-utils"; import { logger } from "../logger"; -import { loadPrivateKey } from "@fretchen/chain-utils"; import { findFeeToken, getChainConfig, getRpcUrl } from "./chain_utils"; // ═══════════════════════════════════════════════════════════════ diff --git a/bunny_js/src/x402_channel_sync.ts b/bunny_js/src/x402_channel_sync.ts index f69f0d8ec..8802fea4e 100644 --- a/bunny_js/src/x402_channel_sync.ts +++ b/bunny_js/src/x402_channel_sync.ts @@ -1,5 +1,4 @@ -import { createPublicClient, http } from "viem"; -import { getViemChain, getRpcUrl } from "@fretchen/chain-utils"; +import { createPublicClient, getViemChain, getRpcUrl, http } from "@fretchen/chain-utils"; import type { Channel, ChannelStorage } from "@x402/evm/batch-settlement/server"; import { logger } from "./logger.js"; diff --git a/bunny_js/test/facilitator/facilitator_routes.test.ts b/bunny_js/test/facilitator/facilitator_routes.test.ts index 488113b7a..d27e260d4 100644 --- a/bunny_js/test/facilitator/facilitator_routes.test.ts +++ b/bunny_js/test/facilitator/facilitator_routes.test.ts @@ -496,7 +496,6 @@ describe("facilitator routes (verify + settle)", () => { throw new Error("the body must not be read when Content-Length already refuses"); }, } as unknown as Request; - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument await expect(readCappedBody(req)).resolves.toBe("too-large"); }); diff --git a/bunny_js/test/x402_channel_sync.test.ts b/bunny_js/test/x402_channel_sync.test.ts index 5906345d1..7f581e32e 100644 --- a/bunny_js/test/x402_channel_sync.test.ts +++ b/bunny_js/test/x402_channel_sync.test.ts @@ -3,14 +3,13 @@ import type { Channel, ChannelStorage } from "@x402/evm/batch-settlement/server" const { mockReadContract } = vi.hoisted(() => ({ mockReadContract: vi.fn() })); -vi.mock("viem", async () => { - const actual = await vi.importActual("viem"); - return { ...actual, createPublicClient: vi.fn(() => ({ readContract: mockReadContract })) }; -}); - +// The module takes its viem surface through the chain-utils facade (see +// shared/VIEM_TS6_NOTES.md), so the client factory is mocked where it is imported from. vi.mock("@fretchen/chain-utils", () => ({ getViemChain: vi.fn(() => ({ id: 10 })), getRpcUrl: vi.fn(() => "https://rpc.example"), + createPublicClient: vi.fn(() => ({ readContract: mockReadContract })), + http: vi.fn(() => "transport"), })); import { resyncChannelState } from "../src/x402_channel_sync.js"; diff --git a/bunny_js/tsconfig.json b/bunny_js/tsconfig.json index 76829792f..0a8fe1c8e 100644 --- a/bunny_js/tsconfig.json +++ b/bunny_js/tsconfig.json @@ -7,6 +7,8 @@ "verbatimModuleSyntax": true, "resolveJsonModule": true, "skipLibCheck": true, + "types": ["node"], + "rootDir": "..", "outDir": "dist", "declaration": false, "noEmit": true diff --git a/bunny_js/vitest.config.js b/bunny_js/vitest.config.js index 1c9dbee67..07514e676 100644 --- a/bunny_js/vitest.config.js +++ b/bunny_js/vitest.config.js @@ -1,6 +1,13 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ + // One viem copy for the whole test graph: the src takes its viem surface through + // @fretchen/chain-utils (see shared/VIEM_TS6_NOTES.md), which resolves its own + // node_modules copy — without dedupe the vi.mock("viem") in the tests would only + // intercept this package's copy, and the chain-utils re-export would run real. + resolve: { + dedupe: ["viem"], + }, test: { environment: "node", globals: true, diff --git a/comment_service/package-lock.json b/comment_service/package-lock.json index a7d6ba1bb..b87962592 100644 --- a/comment_service/package-lock.json +++ b/comment_service/package-lock.json @@ -20,7 +20,7 @@ "prettier": "^3.0.0", "serverless-scaleway-functions": ">=0.4.16", "tsdown": "^0.23.1", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^4.1.11" }, @@ -7399,9 +7399,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/comment_service/package.json b/comment_service/package.json index 45de29bb6..581342867 100644 --- a/comment_service/package.json +++ b/comment_service/package.json @@ -40,7 +40,7 @@ "prettier": "^3.0.0", "serverless-scaleway-functions": ">=0.4.16", "tsdown": "^0.23.1", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^4.1.11" }, diff --git a/comment_service/tsconfig.json b/comment_service/tsconfig.json index c70096b4f..f8a0a5410 100644 --- a/comment_service/tsconfig.json +++ b/comment_service/tsconfig.json @@ -13,6 +13,7 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, + "types": ["node"], "noEmit": true }, "include": ["*.ts", "test/**/*.ts"], diff --git a/observability/package-lock.json b/observability/package-lock.json index 8244cf685..43cd06228 100644 --- a/observability/package-lock.json +++ b/observability/package-lock.json @@ -16,7 +16,7 @@ "eslint": "^10.0.0", "prettier": "^3.6.2", "tsx": "^4.23.12", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.58.2", "vitest": "^5.0.3" } @@ -2702,9 +2702,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/observability/package.json b/observability/package.json index b944f9c2c..4719f0d6b 100644 --- a/observability/package.json +++ b/observability/package.json @@ -22,7 +22,7 @@ "eslint": "^10.0.0", "prettier": "^3.6.2", "tsx": "^4.23.12", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.58.2", "vitest": "^5.0.3" } diff --git a/scw_js/genimg_x402_token.ts b/scw_js/genimg_x402_token.ts index d131e94a2..970a21752 100644 --- a/scw_js/genimg_x402_token.ts +++ b/scw_js/genimg_x402_token.ts @@ -5,30 +5,28 @@ import { isTestnet, loadPrivateKey, getRpcUrl, -} from "@fretchen/chain-utils"; -import { parseJsonBody, CORS_HEADERS, errorResponse, openAiError } from "./utils.js"; -import { - ImageGenerationRequestSchema, - ADVERTISED_MODELS, - MODEL_TO_PROVIDER, - type ImageGenerationResponse, -} from "./genimg_schemas.js"; -import type { z } from "zod"; -import { getContract, createWalletClient, createPublicClient, http, parseEther, + privateKeyToAccount, type PublicClient, type WalletClient, type Chain, type Account, type Transport, type GetContractReturnType, -} from "viem"; +} from "@fretchen/chain-utils"; +import { parseJsonBody, CORS_HEADERS, errorResponse, openAiError } from "./utils.js"; +import { + ImageGenerationRequestSchema, + ADVERTISED_MODELS, + MODEL_TO_PROVIDER, + type ImageGenerationResponse, +} from "./genimg_schemas.js"; +import type { z } from "zod"; import { generateAndUploadImage, JSON_BASE_PATH, type Provider } from "./image_service.js"; -import { privateKeyToAccount } from "viem/accounts"; import { createResourceServer, createPaymentRequirements, diff --git a/scw_js/llm_x402_cron.ts b/scw_js/llm_x402_cron.ts index e2e796666..a2aba2ee9 100644 --- a/scw_js/llm_x402_cron.ts +++ b/scw_js/llm_x402_cron.ts @@ -1,9 +1,10 @@ import { logger } from "./logger.js"; -import { createPublicClient, http } from "viem"; import { + createPublicClient, getSettlementTokens, getViemChain, getRpcUrl, + http, type SettlementTokenInfo, } from "@fretchen/chain-utils"; import { diff --git a/scw_js/package-lock.json b/scw_js/package-lock.json index 247fe7b07..1256a80ce 100644 --- a/scw_js/package-lock.json +++ b/scw_js/package-lock.json @@ -35,7 +35,7 @@ "prettier": "^3.6.2", "serverless-scaleway-functions": ">=0.5.1", "tsdown": "^0.23.1", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.58.2", "vitest": "^4.1.11" } @@ -10220,9 +10220,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "devOptional": true, "license": "Apache-2.0", "bin": { diff --git a/scw_js/package.json b/scw_js/package.json index 5b3b0e73f..8cd44a3fa 100644 --- a/scw_js/package.json +++ b/scw_js/package.json @@ -40,7 +40,7 @@ "prettier": "^3.6.2", "serverless-scaleway-functions": ">=0.5.1", "tsdown": "^0.23.1", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.58.2", "vitest": "^4.1.11" }, diff --git a/scw_js/scripts/fee_allowances.ts b/scw_js/scripts/fee_allowances.ts index d7263def5..13ff6ff29 100644 --- a/scw_js/scripts/fee_allowances.ts +++ b/scw_js/scripts/fee_allowances.ts @@ -35,13 +35,11 @@ import { erc20Abi, formatUnits, http, - type Address, -} from "viem"; -import { privateKeyToAccount } from "viem/accounts"; -import { + privateKeyToAccount, getRpcUrl, getViemChain, loadPrivateKey, + type Address, type SettlementTokenInfo, } from "@fretchen/chain-utils"; import { facilitatorFeeFor } from "../fee_config.js"; @@ -108,7 +106,10 @@ function units(atomic: bigint, decimals: number): string { } function publicClientFor(network: string) { - return createPublicClient({ chain: getViemChain(network), transport: http(getRpcUrl(network)) }); + return createPublicClient({ + chain: getViemChain(network), + transport: http(getRpcUrl(network)), + }); } async function readAllowance( diff --git a/scw_js/scripts/sign_ownership_proof.ts b/scw_js/scripts/sign_ownership_proof.ts index 7c437e64d..abd777609 100644 --- a/scw_js/scripts/sign_ownership_proof.ts +++ b/scw_js/scripts/sign_ownership_proof.ts @@ -11,8 +11,7 @@ * Usage (from scw_js/): npx tsx scripts/sign_ownership_proof.ts */ import dotenv from "dotenv"; -import { privateKeyToAccount } from "viem/accounts"; -import { loadPrivateKey } from "@fretchen/chain-utils"; +import { loadPrivateKey, privateKeyToAccount } from "@fretchen/chain-utils"; // Resolves relative to cwd (scw_js/), matching how npm run dev:* scripts are invoked. dotenv.config(); diff --git a/scw_js/test/getChain.test.ts b/scw_js/test/getChain.test.ts index e6e288eb9..2733b6be3 100644 --- a/scw_js/test/getChain.test.ts +++ b/scw_js/test/getChain.test.ts @@ -15,22 +15,25 @@ * - Mismatch causes settlement to fail AFTER expensive operations complete */ import { describe, test, expect } from "vitest"; -import { createPublicClient, http, type Chain } from "viem"; -import { optimism, optimismSepolia, base, baseSepolia } from "viem/chains"; - -// Import functions under test -import { getExpectedNetworks, validatePaymentNetwork } from "../getChain.js"; - -// Import from chain-utils import { + createPublicClient, + http, + optimism, + optimismSepolia, + base, + baseSepolia, getGenAiNFTMainnetNetworks, getGenAiNFTTestnetNetworks, getViemChain, getUSDCConfig, getRpcUrl, toCAIP2, + type Chain, } from "@fretchen/chain-utils"; +// Import functions under test +import { getExpectedNetworks, validatePaymentNetwork } from "../getChain.js"; + // USDC contracts expose name() and version() functions for EIP-712 domain // Note: They do NOT implement EIP-5267 eip712Domain(), so we read individual functions const USDC_ABI = [ diff --git a/scw_js/test/growth_api.test.ts b/scw_js/test/growth_api.test.ts index e51609e92..0e3c391eb 100644 --- a/scw_js/test/growth_api.test.ts +++ b/scw_js/test/growth_api.test.ts @@ -13,7 +13,7 @@ vi.mock("@fretchen/s3-utils", () => ({ // @fretchen/chain-utils, which resolves its own copy of viem through the // symlinked workspace package — a `vi.mock("viem")` in this package cannot // reach it. Signing for real is also the stronger test. -import { privateKeyToAccount } from "viem/accounts"; +import { privateKeyToAccount } from "@fretchen/chain-utils"; // ===== Test data ===== diff --git a/scw_js/test/x402_channel_sync.test.ts b/scw_js/test/x402_channel_sync.test.ts index d99ca931c..de00fc134 100644 --- a/scw_js/test/x402_channel_sync.test.ts +++ b/scw_js/test/x402_channel_sync.test.ts @@ -3,14 +3,13 @@ import type { Channel, ChannelStorage } from "@x402/evm/batch-settlement/server" const { mockReadContract } = vi.hoisted(() => ({ mockReadContract: vi.fn() })); -vi.mock("viem", async () => { - const actual = await vi.importActual("viem"); - return { ...actual, createPublicClient: vi.fn(() => ({ readContract: mockReadContract })) }; -}); - +// The module takes its viem surface through the chain-utils facade (see +// shared/VIEM_TS6_NOTES.md), so the client factory is mocked where it is imported from. vi.mock("@fretchen/chain-utils", () => ({ getViemChain: vi.fn(() => ({ id: 10 })), getRpcUrl: vi.fn(() => "https://rpc.example"), + createPublicClient: vi.fn(() => ({ readContract: mockReadContract })), + http: vi.fn(() => "transport"), })); import { resyncChannelState } from "../x402_channel_sync.js"; diff --git a/scw_js/test/x402_offer_eure.test.ts b/scw_js/test/x402_offer_eure.test.ts index faae0b8aa..3abbe8dd5 100644 --- a/scw_js/test/x402_offer_eure.test.ts +++ b/scw_js/test/x402_offer_eure.test.ts @@ -16,8 +16,7 @@ * this contract is precisely that spread — every `base.extra` key survives enhancement. */ import { describe, expect, it } from "vitest"; -import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; -import { EURE_ADDRESSES } from "@fretchen/chain-utils"; +import { EURE_ADDRESSES, generatePrivateKey, privateKeyToAccount } from "@fretchen/chain-utils"; import { createBatchSettlementPaymentRequirements, createPaymentRequirements, diff --git a/scw_js/tsconfig.json b/scw_js/tsconfig.json index d7ebb03e5..d1ac26b94 100644 --- a/scw_js/tsconfig.json +++ b/scw_js/tsconfig.json @@ -7,6 +7,7 @@ "verbatimModuleSyntax": true, "resolveJsonModule": true, "skipLibCheck": true, + "rootDir": "..", "outDir": "dist", "declaration": false, "noEmit": true diff --git a/scw_js/vitest.config.js b/scw_js/vitest.config.js index 1c9dbee67..1b8a660e8 100644 --- a/scw_js/vitest.config.js +++ b/scw_js/vitest.config.js @@ -1,6 +1,13 @@ import { defineConfig } from "vitest/config"; export default defineConfig({ + // One viem copy for the whole test graph: consumers import viem through + // @fretchen/chain-utils (see shared/VIEM_TS6_NOTES.md), which resolves its own + // node_modules copy — without dedupe the vi.mock("viem") in test/setup.ts would + // only intercept this package's copy, and the chain-utils re-export would run real. + resolve: { + dedupe: ["viem"], + }, test: { environment: "node", globals: true, diff --git a/scw_js/x402_channel_sync.ts b/scw_js/x402_channel_sync.ts index f69f0d8ec..8802fea4e 100644 --- a/scw_js/x402_channel_sync.ts +++ b/scw_js/x402_channel_sync.ts @@ -1,5 +1,4 @@ -import { createPublicClient, http } from "viem"; -import { getViemChain, getRpcUrl } from "@fretchen/chain-utils"; +import { createPublicClient, getViemChain, getRpcUrl, http } from "@fretchen/chain-utils"; import type { Channel, ChannelStorage } from "@x402/evm/batch-settlement/server"; import { logger } from "./logger.js"; diff --git a/scw_js/x402_server.ts b/scw_js/x402_server.ts index d8df04d10..5a38ce378 100644 --- a/scw_js/x402_server.ts +++ b/scw_js/x402_server.ts @@ -9,8 +9,7 @@ import { sanitizeResourceServiceMetadata, type SanitizedResourceServiceMetadata, } from "@x402/extensions/bazaar"; -import { loadPrivateKey } from "@fretchen/chain-utils"; -import { privateKeyToAccount } from "viem/accounts"; +import { loadPrivateKey, privateKeyToAccount } from "@fretchen/chain-utils"; import { S3ChannelStorage } from "./x402_channel_storage.js"; import { EXPOSED_X402_HEADERS } from "./utils.js"; import { logger } from "./logger.js"; diff --git a/shared/chain-utils/package-lock.json b/shared/chain-utils/package-lock.json index 681fccc4e..e31c54687 100644 --- a/shared/chain-utils/package-lock.json +++ b/shared/chain-utils/package-lock.json @@ -12,7 +12,7 @@ "@vitest/coverage-v8": "^5.0.0", "eslint": "^10.0.0", "prettier": "^3.8.1", - "typescript": "^5.0.0", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "viem": "^2.57.4", "vitest": "^5.0.3" @@ -2292,7 +2292,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/shared/chain-utils/package.json b/shared/chain-utils/package.json index 51ebf5869..9b88ecfd6 100644 --- a/shared/chain-utils/package.json +++ b/shared/chain-utils/package.json @@ -31,7 +31,7 @@ "@vitest/coverage-v8": "^5.0.0", "eslint": "^10.0.0", "prettier": "^3.8.1", - "typescript": "^5.0.0", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "viem": "^2.57.4", "vitest": "^5.0.3" diff --git a/shared/chain-utils/src/index.ts b/shared/chain-utils/src/index.ts index f52a89cfa..c4a28f86d 100644 --- a/shared/chain-utils/src/index.ts +++ b/shared/chain-utils/src/index.ts @@ -163,3 +163,6 @@ export { verifySignedMessage, type BearerPayload, } from "./auth-protocol"; + +// The viem facade — see src/viem.ts. Consumers import viem through this package. +export * from "./viem"; diff --git a/shared/chain-utils/src/viem.ts b/shared/chain-utils/src/viem.ts new file mode 100644 index 000000000..9d7f51167 --- /dev/null +++ b/shared/chain-utils/src/viem.ts @@ -0,0 +1,22 @@ +/** + * The viem facade — this package's consumers import the viem surface from here, never from + * "viem" directly. + * + * Why: each consumer compiles against two viem type copies — this package's (its resolved + * `import("viem")` finds `shared/chain-utils/node_modules/viem`) and its own `node_modules/viem` + * — and TypeScript 6 refuses to treat the two `Chain`s as the same type at any call site where + * they cross. Routing every viem import through this facade resolves all viem types through + * the one copy, so the crossing never happens, at any viem version. The full story, including + * the alternatives tested and discarded, is in `../../VIEM_TS6_NOTES.md` (repo root `shared/`). + * + * Extend deliberately: add entries here only when a consumer needs them, and never + * `export *` from "viem/accounts" — its names (signMessage, …) collide with viem's root + * exports, and ambiguous star re-exports are silently dropped, not errored. + */ + +export * from "viem"; +// "viem/chains" star-exports share names with viem's root (TS2308), so the module goes out +// as a namespace (`chains.base`), plus the four chains this repo's networks use, named. +export * as chains from "viem/chains"; +export { optimism, optimismSepolia, base, baseSepolia } from "viem/chains"; +export { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; diff --git a/shared/s3-utils/package-lock.json b/shared/s3-utils/package-lock.json index e3c6cc3ef..4ada1f5eb 100644 --- a/shared/s3-utils/package-lock.json +++ b/shared/s3-utils/package-lock.json @@ -13,7 +13,7 @@ "@vitest/coverage-v8": "^5.0.0", "eslint": "^10.0.0", "prettier": "^3.8.1", - "typescript": "^5.0.0", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^5.0.3" } @@ -2244,9 +2244,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", "bin": { diff --git a/shared/s3-utils/package.json b/shared/s3-utils/package.json index fed8d2b50..e5ebdbd3f 100644 --- a/shared/s3-utils/package.json +++ b/shared/s3-utils/package.json @@ -31,7 +31,7 @@ "@vitest/coverage-v8": "^5.0.0", "eslint": "^10.0.0", "prettier": "^3.8.1", - "typescript": "^5.0.0", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^5.0.3" } diff --git a/shared/s3-utils/tsconfig.json b/shared/s3-utils/tsconfig.json index bc5c409f5..12b916c78 100644 --- a/shared/s3-utils/tsconfig.json +++ b/shared/s3-utils/tsconfig.json @@ -10,6 +10,7 @@ "strict": true, "esModuleInterop": true, "skipLibCheck": true, + "types": ["node"], "forceConsistentCasingInFileNames": true }, "include": ["src"], diff --git a/x402_facilitator/chain_utils.ts b/x402_facilitator/chain_utils.ts index 8ec7c34ad..20a450f5b 100644 --- a/x402_facilitator/chain_utils.ts +++ b/x402_facilitator/chain_utils.ts @@ -5,7 +5,6 @@ * Uses @fretchen/chain-utils for chain/address data. */ -import type { Chain } from "viem"; import { getViemChain, tryGetEIP3009SplitterAddress, @@ -14,6 +13,7 @@ import { getSettlementTokens, type Network, type SettlementTokenInfo, + type Chain, } from "@fretchen/chain-utils"; export interface ChainConfig { diff --git a/x402_facilitator/package-lock.json b/x402_facilitator/package-lock.json index 5188fbba8..1148026c0 100644 --- a/x402_facilitator/package-lock.json +++ b/x402_facilitator/package-lock.json @@ -24,7 +24,7 @@ "serverless-scaleway-functions": ">=0.4.16", "tsdown": "^0.23.1", "tsx": "^4.23.13", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^4.1.11" }, @@ -8101,9 +8101,9 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "devOptional": true, "license": "Apache-2.0", "bin": { diff --git a/x402_facilitator/package.json b/x402_facilitator/package.json index ba3c27503..9ec329477 100644 --- a/x402_facilitator/package.json +++ b/x402_facilitator/package.json @@ -48,7 +48,7 @@ "serverless-scaleway-functions": ">=0.4.16", "tsdown": "^0.23.1", "tsx": "^4.23.13", - "typescript": "^5.9.3", + "typescript": "^6.0.3", "typescript-eslint": "^8.60.0", "vitest": "^4.1.11" }, diff --git a/x402_facilitator/test/eip712_reference.test.ts b/x402_facilitator/test/eip712_reference.test.ts index cd9670bcf..82c24f78c 100644 --- a/x402_facilitator/test/eip712_reference.test.ts +++ b/x402_facilitator/test/eip712_reference.test.ts @@ -8,7 +8,7 @@ */ import { describe, test, expect } from "vitest"; -import { hashTypedData, keccak256, toHex } from "viem"; +import { hashTypedData, keccak256, toHex } from "@fretchen/chain-utils"; describe("EIP-712 Reference Tests", () => { // Offizielle Test-Daten aus der EIP-712 Spezifikation diff --git a/x402_facilitator/tsconfig.json b/x402_facilitator/tsconfig.json index 339409432..ae58a690d 100644 --- a/x402_facilitator/tsconfig.json +++ b/x402_facilitator/tsconfig.json @@ -12,6 +12,7 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, + "rootDir": "..", "noEmit": true }, "include": ["*.ts", "scripts/**/*.ts", "test/**/*.ts"], diff --git a/x402_facilitator/vitest.config.js b/x402_facilitator/vitest.config.js index 21ea7d897..c4912a494 100644 --- a/x402_facilitator/vitest.config.js +++ b/x402_facilitator/vitest.config.js @@ -1,6 +1,13 @@ import { defineConfig, configDefaults } from "vitest/config"; export default defineConfig({ + // One viem copy for the whole test graph: consumers import viem through + // @fretchen/chain-utils (see shared/VIEM_TS6_NOTES.md), which resolves its own + // node_modules copy — without dedupe the vi.mock("viem") in the tests would only + // intercept this package's copy, and the chain-utils re-export would run real. + resolve: { + dedupe: ["viem"], + }, test: { environment: "node", globals: true, diff --git a/x402_facilitator/wallet_report_cron.ts b/x402_facilitator/wallet_report_cron.ts index 89ff2f74b..33664900c 100644 --- a/x402_facilitator/wallet_report_cron.ts +++ b/x402_facilitator/wallet_report_cron.ts @@ -35,7 +35,7 @@ import { formatEther, type Address, type Abi, -} from "viem"; +} from "@fretchen/chain-utils"; import { logger } from "./logger"; import { feeAmountFor, getFacilitatorAddress } from "./wallet_report_fee"; import { getChainConfig, getFeeTokens, getRpcUrl } from "./chain_utils"; diff --git a/x402_facilitator/wallet_report_fee.ts b/x402_facilitator/wallet_report_fee.ts index d6f4f37c6..a7c4c5dec 100644 --- a/x402_facilitator/wallet_report_fee.ts +++ b/x402_facilitator/wallet_report_fee.ts @@ -7,9 +7,7 @@ * same sitting. The stakes are low and one-sided: nothing funds-bearing runs here anymore, * a drift only mis-estimates the report's nominal-fee arithmetic. */ -import type { Address } from "viem"; -import { privateKeyToAccount } from "viem/accounts"; -import { loadPrivateKey } from "@fretchen/chain-utils"; +import { loadPrivateKey, privateKeyToAccount, type Address } from "@fretchen/chain-utils"; import { logger } from "./logger"; /**