Skip to content

Commit c8e9daa

Browse files
committed
feat: remove session creation on deployment
this has been removed from the contracts, but still existed in the sdk and UI. Best to make it clear that this doesn't exist
1 parent 0223c1d commit c8e9daa

File tree

10 files changed

+212
-51
lines changed

10 files changed

+212
-51
lines changed

examples/nft-quest-contracts/project.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
},
2626
"dependsOn": ["build", "demo-app:deploy-msa-factory"]
2727
},
28+
"deploy:nft-only": {
29+
"executor": "nx:run-commands",
30+
"options": {
31+
"cwd": "examples/nft-quest-contracts",
32+
"command": "./scripts/deploy-nft-only.sh"
33+
},
34+
"dependsOn": ["build", "demo-app:deploy-msa-factory"]
35+
},
2836
"test": {
2937
"executor": "nx:run-commands",
3038
"options": {
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Colors for output
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
YELLOW='\033[1;33m'
8+
NC='\033[0m' # No Color
9+
10+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11+
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
12+
CONTRACTS_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
13+
14+
echo -e "${GREEN}Deploying NFT Quest contract only...${NC}"
15+
16+
# Configuration
17+
RPC_URL="http://127.0.0.1:8545"
18+
ANVIL_ACCOUNT_0_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
19+
20+
# Check if demo-app contracts exist
21+
DEMO_APP_CONTRACTS="$PROJECT_ROOT/examples/demo-app/contracts-anvil.json"
22+
if [ ! -f "$DEMO_APP_CONTRACTS" ]; then
23+
echo -e "${RED}Error: Demo-app contracts not found at $DEMO_APP_CONTRACTS${NC}"
24+
echo -e "${YELLOW}Please deploy ERC-4337 infrastructure first:${NC}"
25+
echo -e " pnpm nx deploy-msa-factory demo-app"
26+
echo -e "${YELLOW}Or run auth-server dev which deploys it automatically:${NC}"
27+
echo -e " pnpm nx dev auth-server"
28+
exit 1
29+
fi
30+
31+
echo -e "${GREEN}Found demo-app contracts at $DEMO_APP_CONTRACTS${NC}"
32+
33+
# Deploy NFT Contract
34+
echo -e "${GREEN}Deploying ZeekNFTQuest...${NC}"
35+
BASE_TOKEN_URI="https://nft.zksync.dev/nft/metadata.json"
36+
37+
cd "$CONTRACTS_DIR"
38+
39+
DEPLOY_OUTPUT=$(forge create \
40+
--rpc-url "$RPC_URL" \
41+
--private-key "$ANVIL_ACCOUNT_0_KEY" \
42+
--broadcast \
43+
contracts/ZeekNFTQuest.sol:ZeekNFTQuest \
44+
--constructor-args "$BASE_TOKEN_URI" 2>&1)
45+
46+
NFT_ADDRESS=$(echo "$DEPLOY_OUTPUT" | grep "Deployed to:" | awk '{print $3}')
47+
48+
echo -e "${GREEN}NFT Contract deployed at: $NFT_ADDRESS${NC}"
49+
50+
# Read shared infrastructure from demo-app
51+
PAYMASTER=$(jq -r '.mockPaymaster // .testPaymaster' "$DEMO_APP_CONTRACTS")
52+
SESSION_VALIDATOR=$(jq -r '.sessionValidator' "$DEMO_APP_CONTRACTS")
53+
WEBAUTHN_VALIDATOR=$(jq -r '.webauthnValidator' "$DEMO_APP_CONTRACTS")
54+
ENTRY_POINT=$(jq -r '.entryPoint' "$DEMO_APP_CONTRACTS")
55+
BUNDLER_URL=$(jq -r '.bundlerUrl // "http://localhost:4337"' "$DEMO_APP_CONTRACTS")
56+
FACTORY=$(jq -r '.factory' "$DEMO_APP_CONTRACTS")
57+
EOA_VALIDATOR=$(jq -r '.eoaValidator' "$DEMO_APP_CONTRACTS")
58+
GUARDIAN_EXECUTOR=$(jq -r '.guardianExecutor' "$DEMO_APP_CONTRACTS")
59+
60+
echo -e "${GREEN}Using shared ERC-4337 infrastructure from demo-app:${NC}"
61+
echo -e " Paymaster: $PAYMASTER"
62+
echo -e " Session Validator: $SESSION_VALIDATOR"
63+
echo -e " Webauthn Validator: $WEBAUTHN_VALIDATOR"
64+
echo -e " Entry Point: $ENTRY_POINT"
65+
echo -e " Bundler URL: $BUNDLER_URL"
66+
67+
# Write .env.local for Nuxt runtime config
68+
ENV_FILE="$PROJECT_ROOT/examples/nft-quest/.env.local"
69+
cat > "$ENV_FILE" << EOF
70+
NUXT_PUBLIC_CONTRACTS_NFT=$NFT_ADDRESS
71+
NUXT_PUBLIC_CONTRACTS_PAYMASTER=$PAYMASTER
72+
EOF
73+
74+
echo -e "${GREEN}.env.local written to $ENV_FILE${NC}"
75+
76+
# Write public/contracts.json for runtime access
77+
PUBLIC_DIR="$PROJECT_ROOT/examples/nft-quest/public"
78+
mkdir -p "$PUBLIC_DIR"
79+
CONTRACTS_JSON="$PUBLIC_DIR/contracts.json"
80+
81+
cat > "$CONTRACTS_JSON" << EOF
82+
{
83+
"rpcUrl": "$RPC_URL",
84+
"chainId": 1337,
85+
"entryPoint": "$ENTRY_POINT",
86+
"bundlerUrl": "$BUNDLER_URL",
87+
"factory": "$FACTORY",
88+
"eoaValidator": "$EOA_VALIDATOR",
89+
"sessionValidator": "$SESSION_VALIDATOR",
90+
"webauthnValidator": "$WEBAUTHN_VALIDATOR",
91+
"guardianExecutor": "$GUARDIAN_EXECUTOR",
92+
"testPaymaster": "$PAYMASTER",
93+
"mockPaymaster": "$PAYMASTER",
94+
"nftContract": "$NFT_ADDRESS"
95+
}
96+
EOF
97+
98+
echo -e "${GREEN}contracts.json written to $CONTRACTS_JSON${NC}"
99+
100+
echo -e "${GREEN}✅ NFT-Quest contract deployment complete!${NC}"
101+
echo -e " - NFT Contract: $NFT_ADDRESS"
102+
echo -e " - Paymaster (shared): $PAYMASTER"
103+
echo -e " - Session Validator (shared): $SESSION_VALIDATOR"

examples/nft-quest/project.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
"name": "nft-quest",
33
"tags": ["type:app"],
44
"targets": {
5+
"dev-standalone": {
6+
"executor": "nx:run-commands",
7+
"options": {
8+
"cwd": "examples/nft-quest",
9+
"commands": [
10+
{
11+
"command": "PORT=3006 pnpm nuxt dev",
12+
"prefix": "NFT-Quest:"
13+
}
14+
]
15+
},
16+
"dependsOn": ["nft-quest-contracts:deploy:nft-only"]
17+
},
518
"dev": {
619
"executor": "nx:run-commands",
720
"options": {
@@ -17,7 +30,7 @@
1730
}
1831
]
1932
},
20-
"dependsOn": ["nft-quest-contracts:deploy:local"]
33+
"dependsOn": ["nft-quest-contracts:deploy:nft-only"]
2134
},
2235
"build": {
2336
"executor": "nx:run-commands",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"rpcUrl": "http://127.0.0.1:8545",
3+
"chainId": 1337,
4+
"entryPoint": "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
5+
"bundlerUrl": "http://localhost:4337",
6+
"factory": "0x0356cA3d0350858BCac4De0FC1dEa3Bc6e7c3e3a",
7+
"eoaValidator": "0xDd72e46653662b0118A2743574467FAA582D633e",
8+
"sessionValidator": "0xCaec08bfd740F1Ae4300b3ab62B757F99222244b",
9+
"webauthnValidator": "0xd71301c72D03b483F74BA569ff1132af81079858",
10+
"guardianExecutor": "0xD4c76bC6306657FE415Ee6B09Ea61cFA50573848",
11+
"testPaymaster": "0x206C056fE7Bddb5cC54CcB0331bcf2058b2D5BA6",
12+
"mockPaymaster": "0x206C056fE7Bddb5cC54CcB0331bcf2058b2D5BA6",
13+
"nftContract": "0xFF06F4b2ef9F9D9B96238397Db82d5C445B5244f"
14+
}

packages/auth-server-api/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
PORT=3004
33

44
# CORS Configuration (comma-separated origins)
5-
CORS_ORIGINS=http://localhost:3002,http://localhost:3003,http://localhost:3004,http://localhost:3005,http://localhost:3000
5+
CORS_ORIGINS=http://localhost:3000,http://localhost:3002,http://localhost:3003,http://localhost:3004,http://localhost:3005,http://localhost:3006
66

77
# Deployer Configuration (Private key with funds for deployment gas)
88
# For local development, use the Anvil rich account:

packages/auth-server-api/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ try {
3232
// Environment schema with optional contract addresses (can fall back to contracts.json)
3333
const envSchema = z.object({
3434
PORT: z.string().default("3004"),
35-
CORS_ORIGINS: z.string().default("http://localhost:3002,http://localhost:3003,http://localhost:3004,http://localhost:3005,http://localhost:3000"),
35+
CORS_ORIGINS: z.string().default("http://localhost:3000,http://localhost:3002,http://localhost:3003,http://localhost:3004,http://localhost:3005,http://localhost:3006"),
3636
DEPLOYER_PRIVATE_KEY: z.string().default("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"),
3737
RPC_URL: z.string().default("http://127.0.0.1:8545"),
3838
FACTORY_ADDRESS: z.string().optional(),

packages/auth-server/components/views/confirmation/RequestSession.vue

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
size="sm"
1414
/>
1515

16-
<div class="space-y-2 mt-2">
16+
<!-- Only show session permissions for logged-in users (adding session to existing account) -->
17+
<div
18+
v-if="isLoggedIn"
19+
class="space-y-2 mt-2"
20+
>
1721
<div class="bg-neutral-975 rounded-[28px]">
1822
<div class="px-5 py-2 text-neutral-400">
1923
Permissions
@@ -33,6 +37,7 @@
3337
</div>
3438
</div>
3539
<SessionTokens
40+
v-if="isLoggedIn"
3641
:onchain-actions-count="onchainActionsCount"
3742
:fetch-tokens-error="fetchTokensError"
3843
:tokens-loading="tokensLoading"
@@ -42,6 +47,25 @@
4247
class="mt-1"
4348
/>
4449

50+
<!-- For new accounts, show a simple message -->
51+
<div
52+
v-if="!isLoggedIn"
53+
class="space-y-2 mt-2"
54+
>
55+
<div class="bg-neutral-975 rounded-[28px]">
56+
<div class="px-5 py-2 text-neutral-400">
57+
Account Creation
58+
</div>
59+
<CommonLine class="text-neutral-100">
60+
<div class="py-3 px-3">
61+
<p class="text-sm text-neutral-300">
62+
A new smart account will be created for you. You can add spending permissions later when needed.
63+
</p>
64+
</div>
65+
</CommonLine>
66+
</div>
67+
</div>
68+
4569
<div
4670
v-if="hasDangerousActions"
4771
class="mt-2 bg-neutral-975 rounded-[28px]"
@@ -278,23 +302,21 @@ const confirmConnection = async () => {
278302
279303
try {
280304
if (!isLoggedIn.value) {
281-
// create a new account with initial session data
282-
// Ignore paymaster provided in params for standard connect to avoid validation failures
283-
const accountData = await createAccount(sessionConfig.value, undefined);
305+
// Just create the account - session will be created by the dapp separately
306+
const accountData = await createAccount();
284307
if (!accountData) return;
308+
// Login with the new account
285309
login({
286310
address: accountData.address,
287311
credentialId: accountData.credentialId,
288312
});
289313
314+
// Return account info without session - dapp will create session separately
290315
response = {
291316
result: constructReturn({
292-
address: accountData!.address,
293-
chainId: accountData!.chainId,
294-
session: {
295-
sessionConfig: accountData!.sessionConfig!,
296-
sessionKey: accountData!.sessionKey!,
297-
},
317+
address: accountData.address,
318+
chainId: accountData.chainId,
319+
// No session in response - dapp needs to create it separately
298320
prividiumMode: runtimeConfig.public.prividiumMode,
299321
prividiumProxyUrl: runtimeConfig.public.prividium?.rpcUrl || "",
300322
}),

packages/auth-server/composables/useAccountCreate.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,23 @@
1-
import type { Address } from "viem";
21
import { generatePrivateKey, privateKeyToAddress } from "viem/accounts";
3-
import type { SessionSpec } from "zksync-sso-4337/client";
4-
import { sessionSpecToJSON } from "zksync-sso-4337/client";
52

63
export const useAccountCreate = (_chainId: MaybeRef<SupportedChainId>) => {
74
const chainId = toRef(_chainId);
85
const { registerPasskey } = usePasskeyRegister();
96
const runtimeConfig = useRuntimeConfig();
107
const { getPrividiumInstance } = usePrividiumAuthStore();
118

12-
const { inProgress: registerInProgress, error: createAccountError, execute: createAccount } = useAsync(async (session?: Omit<SessionSpec, "signer">, paymaster?: Address) => {
9+
const { inProgress: registerInProgress, error: createAccountError, execute: createAccount } = useAsync(async () => {
1310
const result = await registerPasskey();
1411
if (!result) {
1512
throw new Error("Failed to register passkey");
1613
}
1714
const { credentialPublicKey, credentialId } = result;
1815

19-
// TODO: Session support during deployment - to be implemented
20-
// For now, sessions can be added after deployment
21-
let sessionData: SessionSpec | undefined;
22-
const sessionKey = generatePrivateKey();
23-
const signer = privateKeyToAddress(sessionKey);
24-
if (session) {
25-
sessionData = {
26-
...session,
27-
signer: signer,
28-
};
29-
}
30-
3116
// EOA owner for initial deployment signing
3217
const ownerKey = generatePrivateKey();
3318
const ownerAddress = privateKeyToAddress(ownerKey);
3419

35-
// Call backend API to deploy account
20+
// Call backend API to deploy account (without session - session will be created separately)
3621
const apiUrl = runtimeConfig.public.authServerApiUrl;
3722
if (!apiUrl) {
3823
throw new Error("Auth Server API URL is not configured");
@@ -43,10 +28,8 @@ export const useAccountCreate = (_chainId: MaybeRef<SupportedChainId>) => {
4328
credentialId,
4429
credentialPublicKey,
4530
originDomain: window.location.origin,
46-
session: sessionData ? sessionSpecToJSON(sessionData) : undefined,
4731
userId: credentialId,
4832
eoaSigners: [ownerAddress],
49-
paymaster,
5033
};
5134

5235
// Build headers - include Prividium auth if in Prividium mode
@@ -64,13 +47,33 @@ export const useAccountCreate = (_chainId: MaybeRef<SupportedChainId>) => {
6447
}
6548
}
6649

67-
const response = await fetch(`${apiUrl}/api/deploy-account`, {
68-
method: "POST",
69-
headers,
70-
body: JSON.stringify(requestBody),
71-
});
50+
let response;
51+
try {
52+
response = await fetch(`${apiUrl}/api/deploy-account`, {
53+
method: "POST",
54+
headers,
55+
body: JSON.stringify(requestBody),
56+
});
57+
} catch (error) {
58+
console.error("Failed to connect to auth-server API:", error);
59+
throw new Error(
60+
`Cannot connect to auth-server API at ${apiUrl}. Please ensure:\n`
61+
+ "1. The auth-server-api is running (pnpm nx dev auth-server-api)\n"
62+
+ "2. CORS is properly configured\n"
63+
+ "3. The API URL is correct\n\n"
64+
+ `Original error: ${error instanceof Error ? error.message : String(error)}`,
65+
);
66+
}
7267

73-
const data = await response.json();
68+
let data;
69+
try {
70+
data = await response.json();
71+
} catch (error) {
72+
throw new Error(
73+
`${error} from auth-server API (status ${response.status}). `
74+
+ "This may indicate a contract deployment mismatch or API error.",
75+
);
76+
}
7477

7578
// Check for errors in response
7679
if (data.error) {
@@ -86,9 +89,6 @@ export const useAccountCreate = (_chainId: MaybeRef<SupportedChainId>) => {
8689
return {
8790
address,
8891
chainId: chainId.value,
89-
sessionKey: session ? sessionKey : undefined,
90-
signer,
91-
sessionConfig: sessionData,
9292
credentialId,
9393
credentialPublicKey,
9494
};

packages/auth-server/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"executor": "nx:run-commands",
1616
"options": {
1717
"cwd": "packages/auth-server",
18-
"command": "pnpm run copy:snarkjs && PORT=3002 nuxt dev"
18+
"commands": ["pnpm run copy:snarkjs && PORT=3002 nuxt dev", "pnpm nx run auth-server-api:dev"],
19+
"parallel": true
1920
},
2021
"dependsOn": ["^build"]
2122
},

packages/auth-server/stores/local-node.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"rpcUrl": "http://localhost:8545",
33
"chainId": 1337,
44
"deployer": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
5-
"eoaValidator": "0xa9D2feB10194d940A70391dFb186A649A3d52106",
6-
"sessionValidator": "0x3a8604019733D4Aab2AA7CBAdb9E06E1B072b1ed",
7-
"webauthnValidator": "0x4738752455Fd18DFf349C69f3E5b7576250D634a",
8-
"guardianExecutor": "0x1e085C7feA39368ca2A435fF96CAf1aE60176fB5",
9-
"accountImplementation": "0xd1d08C9cb5Df546975c9C8EAF8BA93775Ae2E2dF",
10-
"beacon": "0x85152fDf961A761399C1b77BC3213C6F361f4f52",
11-
"factory": "0xa669dd8684305c677f0d5Cd95D1a2E465164d984",
12-
"testPaymaster": "0x480ce59387443A9Bf266a4657f0E2AE1E6a7B771",
13-
"mockPaymaster": "0x480ce59387443A9Bf266a4657f0E2AE1E6a7B771",
5+
"eoaValidator": "0xDd72e46653662b0118A2743574467FAA582D633e",
6+
"sessionValidator": "0xCaec08bfd740F1Ae4300b3ab62B757F99222244b",
7+
"webauthnValidator": "0xd71301c72D03b483F74BA569ff1132af81079858",
8+
"guardianExecutor": "0xD4c76bC6306657FE415Ee6B09Ea61cFA50573848",
9+
"accountImplementation": "0xB69ae22EE1F1141Cb8Fd6d465CC0f8eB5813C615",
10+
"beacon": "0x809eBD30a2357012E6cBaB8776682318568556c1",
11+
"factory": "0x0356cA3d0350858BCac4De0FC1dEa3Bc6e7c3e3a",
12+
"testPaymaster": "0x206C056fE7Bddb5cC54CcB0331bcf2058b2D5BA6",
13+
"mockPaymaster": "0x206C056fE7Bddb5cC54CcB0331bcf2058b2D5BA6",
1414
"entryPoint": "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
1515
"bundlerUrl": "http://localhost:4337"
1616
}

0 commit comments

Comments
 (0)