Skip to content

Commit 9bdacf5

Browse files
authored
Merge branch 'main' into nft-quest-setup
2 parents c56d985 + 58b9186 commit 9bdacf5

File tree

18 files changed

+162
-68
lines changed

18 files changed

+162
-68
lines changed

.github/workflows/deploy-auth-server.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ jobs:
5959

6060
- name: Build apps
6161
env:
62-
NUXT_PUBLIC_DEFAULT_CHAIN_ID: 11155111
62+
NUXT_PUBLIC_DEFAULT_CHAIN_ID: 8022833
63+
NUXT_PUBLIC_AUTH_SERVER_API_URL: https://auth-server-api.stage-sso.zksync.dev
6364
NUXT_PUBLIC_SALT_SERVICE_URL: "https://sso-oidc.zksync.dev/salt"
6465
run: pnpm nx build auth-server
6566

.github/workflows/deploy-preview.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ jobs:
6161

6262
- name: Build Auth Server
6363
env:
64-
NUXT_PUBLIC_DEFAULT_CHAIN_ID: 300
64+
NUXT_PUBLIC_DEFAULT_CHAIN_ID: 8022833
65+
NUXT_PUBLIC_AUTH_SERVER_API_URL: https://auth-server-api.stage-sso.zksync.dev
6566
NUXT_PUBLIC_SALT_SERVICE_URL: "https://sso-oidc.zksync.dev/salt"
6667
run: pnpm nx build auth-server
6768

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ CORS_ORIGINS=http://localhost:3003,http://localhost:3002,http://localhost:3000
99
DEPLOYER_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
1010

1111
# Blockchain Configuration
12-
CHAIN_ID=1337
1312
RPC_URL=http://127.0.0.1:8545
1413
BUNDLER_URL=http://127.0.0.1:4337
1514

packages/auth-server-api/Dockerfile

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,52 @@ WORKDIR /usr/src/app/packages/erc4337-contracts
5959
RUN forge soldeer install
6060
RUN forge build
6161

62-
# Build ERC-4337 related packages
62+
# Build ERC-4337 related packages (following CI build order)
6363
WORKDIR /usr/src/app
6464

65-
# Build auth-server-api
66-
RUN pnpm nx build auth-server-api
65+
# Build in correct dependency order: web-sdk -> sdk-4337 -> auth-server-api
66+
RUN pnpm nx build web-sdk
67+
RUN pnpm nx build sdk-4337 || (echo "===SDK-4337 Build Failed, trying direct build===" && cd packages/sdk-4337 && pnpm build)
68+
RUN pnpm nx build auth-server-api || (echo "===Auth-Server-API Build Failed, trying direct build===" && cd packages/auth-server-api && pnpm build)
6769

6870
# Deploy only production dependencies for auth-server-api
6971
RUN pnpm deploy --filter=auth-server-api --prod /prod/auth-server-api
7072

7173
# Stage 3: Production runtime
72-
# Using distroless for minimal attack surface
73-
FROM gcr.io/distroless/nodejs22-debian12:nonroot AS production
74+
FROM node:22-slim AS production
75+
76+
# Install curl for healthcheck
77+
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
7478

7579
# Copy the deployed auth-server-api with its dependencies
76-
COPY --from=builder --chown=nonroot:nonroot /prod/auth-server-api /prod/auth-server-api
80+
COPY --from=builder /prod/auth-server-api /prod/auth-server-api
7781

7882
# Copy the built dist folder
79-
COPY --from=builder --chown=nonroot:nonroot /usr/src/app/packages/auth-server-api/dist /prod/auth-server-api/dist
83+
COPY --from=builder /usr/src/app/packages/auth-server-api/dist /prod/auth-server-api/dist
84+
85+
# Copy sdk-4337 built files to node_modules
86+
COPY --from=builder /usr/src/app/packages/sdk-4337/dist /prod/auth-server-api/node_modules/zksync-sso-4337/dist
87+
88+
# Copy web-sdk built files and WASM packages to .pnpm directory structure
89+
RUN mkdir -p $(find /prod/auth-server-api/node_modules/.pnpm -type d -name "zksync-sso-web-sdk" 2>/dev/null | head -1)
90+
COPY --from=builder /usr/src/app/packages/sdk-platforms/web/pkg-bundler /tmp/pkg-bundler
91+
COPY --from=builder /usr/src/app/packages/sdk-platforms/web/pkg-node /tmp/pkg-node
92+
COPY --from=builder /usr/src/app/packages/sdk-platforms/web/dist /tmp/web-dist
93+
RUN PNPM_WEB_SDK=$(find /prod/auth-server-api/node_modules/.pnpm -type d -name "zksync-sso-web-sdk" 2>/dev/null | head -1) && \
94+
if [ -n "$PNPM_WEB_SDK" ]; then \
95+
cp -r /tmp/pkg-bundler "$PNPM_WEB_SDK/" && \
96+
cp -r /tmp/pkg-node "$PNPM_WEB_SDK/" && \
97+
cp -r /tmp/web-dist "$PNPM_WEB_SDK/dist"; \
98+
fi && \
99+
rm -rf /tmp/pkg-bundler /tmp/pkg-node /tmp/web-dist
100+
101+
# Copy sdk-4337 built files to .pnpm directory structure
102+
COPY --from=builder /usr/src/app/packages/sdk-4337/dist /tmp/sdk-4337-dist
103+
RUN PNPM_SDK_4337=$(find /prod/auth-server-api/node_modules/.pnpm -type d -name "zksync-sso-4337" 2>/dev/null | head -1) && \
104+
if [ -n "$PNPM_SDK_4337" ]; then \
105+
cp -r /tmp/sdk-4337-dist "$PNPM_SDK_4337/dist"; \
106+
fi && \
107+
rm -rf /tmp/sdk-4337-dist
80108

81109
WORKDIR /prod/auth-server-api
82110

@@ -86,7 +114,7 @@ ENV NODE_ENV=production
86114

87115
# Healthcheck
88116
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
89-
CMD ["node", "-e", "require('http').get('http://localhost:3004/api/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
117+
CMD ["curl", "-f", "http://localhost:3004/api/health"]
90118

91119
# Expose port
92120
EXPOSE 3004

packages/auth-server-api/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"start": "node --experimental-wasm-modules dist/index.js"
99
},
1010
"dependencies": {
11+
"@simplewebauthn/browser": "13.x",
12+
"@simplewebauthn/server": "13.x",
1113
"@t3-oss/env-core": "^0.12.0",
1214
"cors": "^2.8.5",
1315
"dotenv": "^16.4.7",

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

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import dotenv from "dotenv";
22
import { readFileSync } from "fs";
33
import { dirname, join } from "path";
44
import { fileURLToPath } from "url";
5+
import { type Chain, defineChain } from "viem";
6+
import { localhost } from "viem/chains";
57
import { z } from "zod";
68

79
// Load environment variables
@@ -31,7 +33,6 @@ const envSchema = z.object({
3133
PORT: z.string().default("3004"),
3234
CORS_ORIGINS: z.string().default("http://localhost:3003,http://localhost:3002,http://localhost:3000"),
3335
DEPLOYER_PRIVATE_KEY: z.string().default("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"),
34-
CHAIN_ID: z.string().default("1337"),
3536
RPC_URL: z.string().default("http://127.0.0.1:8545"),
3637
BUNDLER_URL: z.string().default("http://127.0.0.1:4337"),
3738
FACTORY_ADDRESS: z.string().optional(),
@@ -67,4 +68,35 @@ if (!FACTORY_ADDRESS || !EOA_VALIDATOR_ADDRESS || !WEBAUTHN_VALIDATOR_ADDRESS ||
6768
process.exit(1);
6869
}
6970

70-
export { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, SESSION_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS };
71+
// Supported chains configuration
72+
const zksyncOsTestnet = defineChain({
73+
id: 8022833,
74+
name: "ZKsyncOS Testnet",
75+
nativeCurrency: {
76+
name: "Ether",
77+
symbol: "ETH",
78+
decimals: 18,
79+
},
80+
rpcUrls: {
81+
default: {
82+
http: ["https://zksync-os-testnet-alpha.zksync.dev"],
83+
},
84+
},
85+
blockExplorers: {
86+
default: {
87+
name: "ZKsyncOS Testnet Explorer",
88+
url: "https://zksync-os-testnet-alpha.staging-scan-v2.zksync.dev",
89+
},
90+
},
91+
});
92+
const SUPPORTED_CHAINS: Chain[] = [localhost, zksyncOsTestnet];
93+
94+
function getChain(chainId: number): Chain {
95+
const chain = SUPPORTED_CHAINS.find((c) => c.id === chainId);
96+
if (!chain) {
97+
throw new Error(`Unsupported chainId: ${chainId}. Supported: ${SUPPORTED_CHAINS.map((c) => c.id).join(", ")}`);
98+
}
99+
return chain;
100+
}
101+
102+
export { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, getChain, SESSION_VALIDATOR_ADDRESS, SUPPORTED_CHAINS, WEBAUTHN_VALIDATOR_ADDRESS };

packages/auth-server-api/src/handlers/deploy-account.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ import type { Request, Response } from "express";
22
import { type Address, createPublicClient, createWalletClient, type Hex, http } from "viem";
33
import { privateKeyToAccount } from "viem/accounts";
44
import { waitForTransactionReceipt } from "viem/actions";
5-
import { localhost } from "viem/chains";
6-
import { getAccountAddressFromLogs, prepareDeploySmartAccount, type SessionSpecJSON } from "zksync-sso-4337/client";
7-
import { parseSessionConfigJSON } from "zksync-sso-4337/client-auth-server";
5+
import { getAccountAddressFromLogs, prepareDeploySmartAccount } from "zksync-sso-4337/client";
86

9-
import { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, SESSION_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS } from "../config.js";
7+
import { env, EOA_VALIDATOR_ADDRESS, FACTORY_ADDRESS, getChain, SESSION_VALIDATOR_ADDRESS, WEBAUTHN_VALIDATOR_ADDRESS } from "../config.js";
108
import { deployAccountSchema } from "../schemas.js";
119

1210
type DeployAccountRequest = {
1311
chainId: number;
1412
credentialId: Hex;
1513
credentialPublicKey: { x: Hex; y: Hex };
1614
originDomain: string;
17-
session?: SessionSpecJSON;
1815
userId?: string;
1916
eoaSigners?: Address[];
2017
};
@@ -33,21 +30,19 @@ export const deployAccountHandler = async (req: Request, res: Response): Promise
3330

3431
const body = req.body as DeployAccountRequest;
3532

36-
// Convert session from JSON (with string bigints) to SessionSpec (with actual bigints)
37-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
38-
const initialSession = body.session ? parseSessionConfigJSON(body.session) : undefined;
39-
// TODO: Use initialSession during deployment
33+
// Get chain from request
34+
const chain = getChain(body.chainId);
4035

4136
// Create clients
4237
const publicClient = createPublicClient({
43-
chain: localhost,
38+
chain,
4439
transport: http(env.RPC_URL),
4540
});
4641

4742
const deployerAccount = privateKeyToAccount(env.DEPLOYER_PRIVATE_KEY as Hex);
4843
const walletClient = createWalletClient({
4944
account: deployerAccount,
50-
chain: localhost,
45+
chain,
5146
transport: http(env.RPC_URL),
5247
});
5348

packages/auth-server/app.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
</template>
66

77
<script lang="ts" setup>
8-
import { createAppKit } from "@reown/appkit/vue";
8+
/* import { createAppKit } from "@reown/appkit/vue";
99
1010
const { defaultChain } = useClientStore();
1111
const { metadata, projectId, wagmiAdapter } = useAppKit();
1212
13-
// BigInt polyfill
14-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15-
(BigInt.prototype as any).toJSON = function () {
16-
return this.toString();
17-
};
18-
1913
createAppKit({
2014
adapters: [wagmiAdapter],
2115
networks: [defaultChain],
2216
projectId,
2317
metadata,
24-
});
18+
}); */
19+
20+
// BigInt polyfill
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22+
(BigInt.prototype as any).toJSON = function () {
23+
return this.toString();
24+
};
2525
</script>

packages/auth-server/components/account-recovery.disabled/guardian-flow/Step4ConfirmNow.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
Confirm Guardian
6464
</ZkButton>
6565

66-
<CommonConnectButton
66+
<!-- <CommonConnectButton
6767
v-if="!isSsoAccount"
6868
type="primary"
6969
class="w-full md:max-w-48 mt-4"
7070
:disabled="confirmGuardianInProgress || getConfigurableAccountInProgress"
71-
/>
71+
/> -->
7272

7373
<ZkButton
7474
type="secondary"

packages/auth-server/components/account-recovery.disabled/passkey-generation-flow/Step3ConfirmNow.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656
>
5757
Confirm Recovery
5858
</ZkButton>
59-
<CommonConnectButton
59+
<!-- <CommonConnectButton
6060
v-if="!selectedGuardianInfo?.isSsoAccount"
6161
type="primary"
6262
class="w-full mt-4"
6363
:disabled="initRecoveryInProgress || getConfigurableAccountInProgress"
64-
/>
64+
/> -->
6565
</template>
6666

6767
<ZkButton

0 commit comments

Comments
 (0)