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
1 change: 0 additions & 1 deletion packages/auth-server-api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions packages/auth-server-api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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 };
17 changes: 6 additions & 11 deletions packages/auth-server-api/src/handlers/deploy-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ 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 = {
chainId: number;
credentialId: Hex;
credentialPublicKey: { x: Hex; y: Hex };
originDomain: string;
session?: SessionSpecJSON;
userId?: string;
eoaSigners?: Address[];
};
Expand All @@ -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),
});

Expand Down
Loading