diff --git a/packages/auth-server-api/.env.example b/packages/auth-server-api/.env.example index 95527073..c2289bc7 100644 --- a/packages/auth-server-api/.env.example +++ b/packages/auth-server-api/.env.example @@ -9,7 +9,6 @@ CORS_ORIGINS=http://localhost:3003,http://localhost:3002,http://localhost:3000 DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # Blockchain Configuration -CHAIN_ID=1337 RPC_URL=http://127.0.0.1:8545 BUNDLER_URL=http://127.0.0.1:4337 diff --git a/packages/auth-server-api/src/config.ts b/packages/auth-server-api/src/config.ts index 9d0084fe..e059c041 100644 --- a/packages/auth-server-api/src/config.ts +++ b/packages/auth-server-api/src/config.ts @@ -2,6 +2,8 @@ import dotenv from "dotenv"; import { readFileSync } from "fs"; import { dirname, join } from "path"; import { fileURLToPath } from "url"; +import type { Chain } from "viem"; +import { localhost, sepolia } from "viem/chains"; import { z } from "zod"; // Load environment variables @@ -31,7 +33,6 @@ const envSchema = z.object({ PORT: z.string().default("3004"), CORS_ORIGINS: z.string().default("http://localhost:3003,http://localhost:3002,http://localhost:3000"), DEPLOYER_PRIVATE_KEY: z.string().default("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"), - CHAIN_ID: z.string().default("1337"), RPC_URL: z.string().default("http://127.0.0.1:8545"), BUNDLER_URL: z.string().default("http://127.0.0.1:4337"), FACTORY_ADDRESS: z.string().optional(), @@ -67,4 +68,15 @@ if (!FACTORY_ADDRESS || !EOA_VALIDATOR_ADDRESS || !WEBAUTHN_VALIDATOR_ADDRESS || process.exit(1); } -export { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, SESSION_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS }; +// Supported chains configuration +const SUPPORTED_CHAINS: Chain[] = [localhost, sepolia]; + +function getChain(chainId: number): Chain { + const chain = SUPPORTED_CHAINS.find((c) => c.id === chainId); + if (!chain) { + throw new Error(`Unsupported chainId: ${chainId}. Supported: ${SUPPORTED_CHAINS.map((c) => c.id).join(", ")}`); + } + return chain; +} + +export { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, getChain, SESSION_VALIDATOR_ADDRESS, SUPPORTED_CHAINS, WEBAUTHN_VALIDATOR_ADDRESS }; diff --git a/packages/auth-server-api/src/handlers/deploy-account.ts b/packages/auth-server-api/src/handlers/deploy-account.ts index f6194fb3..c1d74b4b 100644 --- a/packages/auth-server-api/src/handlers/deploy-account.ts +++ b/packages/auth-server-api/src/handlers/deploy-account.ts @@ -2,11 +2,9 @@ import type { Request, Response } from "express"; import { type Address, createPublicClient, createWalletClient, type Hex, http } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { waitForTransactionReceipt } from "viem/actions"; -import { localhost } from "viem/chains"; -import { getAccountAddressFromLogs, prepareDeploySmartAccount, type SessionSpecJSON } from "zksync-sso-4337/client"; -import { parseSessionConfigJSON } from "zksync-sso-4337/client-auth-server"; +import { getAccountAddressFromLogs, prepareDeploySmartAccount } from "zksync-sso-4337/client"; -import { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, SESSION_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS } from "../config.js"; +import { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, getChain, SESSION_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS } from "../config.js"; import { deployAccountSchema } from "../schemas.js"; type DeployAccountRequest = { @@ -14,7 +12,6 @@ type DeployAccountRequest = { credentialId: Hex; credentialPublicKey: { x: Hex; y: Hex }; originDomain: string; - session?: SessionSpecJSON; userId?: string; eoaSigners?: Address[]; }; @@ -33,21 +30,19 @@ export const deployAccountHandler = async (req: Request, res: Response): Promise const body = req.body as DeployAccountRequest; - // Convert session from JSON (with string bigints) to SessionSpec (with actual bigints) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const initialSession = body.session ? parseSessionConfigJSON(body.session) : undefined; - // TODO: Use initialSession during deployment + // Get chain from request + const chain = getChain(body.chainId); // Create clients const publicClient = createPublicClient({ - chain: localhost, + chain, transport: http(env.RPC_URL), }); const deployerAccount = privateKeyToAccount(env.DEPLOYER_PRIVATE_KEY as Hex); const walletClient = createWalletClient({ account: deployerAccount, - chain: localhost, + chain, transport: http(env.RPC_URL), });