Skip to content

Commit 82a73df

Browse files
authored
fix: few more prividium related changes (#253)
1 parent 971101b commit 82a73df

File tree

11 files changed

+142
-33
lines changed

11 files changed

+142
-33
lines changed

examples/demo-app/scripts/deploy-msa-anvil.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ FACTORY=$(echo "$DEPLOY_OUTPUT" | grep "MSAFactory:" | awk '{print $2}')
4444
echo ""
4545
echo "📦 Deploying MockPaymaster..."
4646
cd "$CONTRACTS_DIR"
47-
PAYMASTER_OUTPUT=$(forge create test/mocks/MockPaymaster.sol:MockPaymaster --rpc-url "$RPC_URL" --private-key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6 --broadcast 2>&1)
47+
ANVIL_ACCOUNT_0_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
48+
PAYMASTER_OUTPUT=$(forge create test/mocks/MockPaymaster.sol:MockPaymaster --rpc-url "$RPC_URL" --private-key "$ANVIL_ACCOUNT_0_KEY" --broadcast 2>&1)
4849
echo "$PAYMASTER_OUTPUT"
4950
PAYMASTER=$(echo "$PAYMASTER_OUTPUT" | grep "Deployed to:" | awk '{print $3}')
5051

@@ -53,7 +54,6 @@ echo "MockPaymaster deployed to: $PAYMASTER"
5354
# Fund the paymaster with ETH from Anvil account #0 (has plenty of ETH)
5455
echo ""
5556
echo "💰 Funding paymaster with 10 ETH..."
56-
ANVIL_ACCOUNT_0_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
5757
cast send "$PAYMASTER" --value 10ether --private-key "$ANVIL_ACCOUNT_0_KEY" --rpc-url "$RPC_URL" 2>&1 || echo "Fund transfer initiated"
5858

5959
# Deposit the paymaster's ETH into the EntryPoint

packages/auth-server/components/PrividiumLogin.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="h-full flex flex-col justify-center px-4">
33
<div class="max-w-md mx-auto w-full">
4-
<AppAccountLogo class="dark:text-neutral-100 h-16 md:h-20 mb-14" />
4+
<AppAccountLogo class="dark:text-neutral-100 h-16 md:h-20 mb-14 mx-auto" />
55
<!-- Error display -->
66
<CommonHeightTransition :opened="!!error">
77
<p class="pb-3 text-sm text-error-300 text-center">

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ const { respond, deny } = useRequestsStore();
5656
const { responseInProgress, requestChain } = storeToRefs(useRequestsStore());
5757
const { address } = storeToRefs(useAccountStore());
5858
const { getClient } = useClientStore();
59+
const runtimeConfig = useRuntimeConfig();
5960
6061
const confirmConnection = () => {
6162
respond(async () => {
6263
const client = getClient({ chainId: requestChain.value!.id });
6364
return {
64-
result: constructReturn(client.account.address, client.chain.id),
65+
result: constructReturn({
66+
address: client.account.address,
67+
chainId: client.chain.id,
68+
prividiumMode: runtimeConfig.public.prividiumMode,
69+
prividiumProxyUrl: runtimeConfig.public.prividium?.rpcUrl || "",
70+
}),
6571
};
6672
});
6773
};

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const { responseInProgress, requestChainId } = storeToRefs(useRequestsStore());
148148
const { createAccount } = useAccountCreate(requestChainId);
149149
const { respond, deny } = useRequestsStore();
150150
const { getClient } = useClientStore();
151+
const runtimeConfig = useRuntimeConfig();
151152
152153
const defaults = {
153154
expiresAt: BigInt(Math.floor(Date.now() / 1000) + 60 * 60 * 24), // 24 hours
@@ -287,14 +288,16 @@ const confirmConnection = async () => {
287288
});
288289
289290
response = {
290-
result: constructReturn(
291-
accountData!.address,
292-
accountData!.chainId,
293-
{
291+
result: constructReturn({
292+
address: accountData!.address,
293+
chainId: accountData!.chainId,
294+
session: {
294295
sessionConfig: accountData!.sessionConfig!,
295296
sessionKey: accountData!.sessionKey!,
296297
},
297-
),
298+
prividiumMode: runtimeConfig.public.prividiumMode,
299+
prividiumProxyUrl: runtimeConfig.public.prividium?.rpcUrl || "",
300+
}),
298301
};
299302
} else {
300303
// create a new session for the existing account
@@ -329,11 +332,13 @@ const confirmConnection = async () => {
329332
});
330333
331334
response = {
332-
result: constructReturn(
333-
client.account.address,
334-
client.chain.id,
335+
result: constructReturn({
336+
address: client.account.address,
337+
chainId: client.chain.id,
335338
session,
336-
),
339+
prividiumMode: runtimeConfig.public.prividiumMode,
340+
prividiumProxyUrl: runtimeConfig.public.prividium?.rpcUrl || "",
341+
}),
337342
};
338343
}
339344
} catch (error) {

packages/auth-server/pages/confirm/index.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@
2626
key="sign-typed-data"
2727
/>
2828
<ViewsConfirmationSend
29-
v-else
29+
v-else-if="requestMethod === 'eth_sendTransaction'"
3030
key="confirmation"
3131
/>
32+
<div
33+
v-else
34+
key="unsupported-method"
35+
class="flex h-full items-center justify-center"
36+
>
37+
<p>Unsupported request method.</p>
38+
</div>
3239
</TransitionGroup>
3340
</template>
3441

packages/auth-server/project.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111
},
1212
"dependsOn": ["^build", "demo-app:deploy-contracts-erc4337"]
1313
},
14-
"dev:with-api": {
15-
"executor": "nx:run-commands",
16-
"options": {
17-
"cwd": "packages/auth-server",
18-
"commands": ["pnpm run copy:snarkjs && PORT=3002 nuxt dev", "pnpm nx run auth-server-api:dev"]
19-
},
20-
"dependsOn": ["^build"]
21-
},
2214
"dev:no-deploy": {
2315
"executor": "nx:run-commands",
2416
"options": {

packages/auth-server/stores/client.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,22 @@ export const useClientStore = defineStore("client", () => {
134134
const contracts = contractsByChain[chainId];
135135
const publicClient = getPublicClient({ chainId });
136136

137+
// In prividium mode, use prividium transport for bundler as well
138+
// Get transport from existing prividium instance - it auto-routes bundler methods
139+
const bundlerTransport = runtimeConfig.public.prividiumMode
140+
? (() => {
141+
const prividiumTransport = prividiumAuthStore.getTransport();
142+
if (!prividiumTransport) {
143+
throw new Error("Prividium transport not available. User may need to authenticate.");
144+
}
145+
return prividiumTransport;
146+
})()
147+
: http(contracts.bundlerUrl || "http://localhost:4337");
148+
137149
return createBundlerClient({
138150
client: publicClient,
139151
chain,
140-
transport: http(contracts.bundlerUrl || "http://localhost:4337"),
152+
transport: bundlerTransport,
141153
userOperation: {
142154
async estimateFeesPerGas() {
143155
const feesPerGas = await publicClient.estimateFeesPerGas();
@@ -160,7 +172,7 @@ export const useClientStore = defineStore("client", () => {
160172
const contracts = contractsByChain[chainId];
161173
const bundlerClient = getBundlerClient({ chainId });
162174

163-
const finalPaymasterAddress = paymasterAddress ?? (usePaymaster ? contracts.testPaymaster : undefined);
175+
const finalPaymasterAddress = paymasterAddress as Address | undefined ?? (usePaymaster ? contracts.testPaymaster : undefined);
164176

165177
const client = createPasskeyClient({
166178
account: {

packages/auth-server/utils/constructReturn.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import type { SessionSpec } from "zksync-sso-4337/client";
22
import type { AuthServerRpcSchema, ExtractReturnType } from "zksync-sso-4337/client-auth-server";
33

4-
export const constructReturn = (address: `0x${string}`, chainId: number, session?: { sessionKey: `0x${string}`; sessionConfig: SessionSpec }): ExtractReturnType<"eth_requestAccounts", AuthServerRpcSchema> => {
4+
type ConstructReturnOptions = {
5+
address: `0x${string}`;
6+
chainId: number;
7+
session?: { sessionKey: `0x${string}`; sessionConfig: SessionSpec };
8+
prividiumMode: boolean;
9+
prividiumProxyUrl: string;
10+
};
11+
12+
export const constructReturn = ({
13+
address,
14+
chainId,
15+
session,
16+
prividiumMode,
17+
prividiumProxyUrl,
18+
}: ConstructReturnOptions): ExtractReturnType<"eth_requestAccounts", AuthServerRpcSchema> => {
519
return {
620
account: {
721
address,
@@ -22,7 +36,10 @@ export const constructReturn = (address: `0x${string}`, chainId: number, session
2236
},
2337
},
2438
contracts: contractsByChain[chain.id],
25-
bundlerUrl: contractsByChain[chain.id].bundlerUrl,
39+
bundlerUrl: prividiumMode
40+
? prividiumProxyUrl
41+
: contractsByChain[chain.id].bundlerUrl || "",
42+
prividiumMode,
2643
})),
2744
};
2845
};

packages/sdk-4337/src/client-auth-server/Signer.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type Address, type Chain, createPublicClient, createWalletClient, custom, type Hash, http, type RpcSchema as RpcSchemaGeneric, type SendTransactionParameters, type Transport, type WalletClient } from "viem";
1+
import { type Address, type Chain, createPublicClient, createWalletClient, custom, type Hash, http, type RpcSchema as RpcSchemaGeneric, type SendTransactionParameters, toHex, type Transport, type WalletClient } from "viem";
22
import { type BundlerClient, createBundlerClient } from "viem/account-abstraction";
33

44
import type { PaymasterConfig } from "../actions/sendUserOperation.js";
@@ -143,9 +143,8 @@ export class Signer implements SignerInterface {
143143
return this.bundlerClients[chainId];
144144
}
145145

146-
// Try to create bundler client from chainsInfo if bundlerUrl is available
147146
const chainInfo = this.chainsInfo.find((c) => c.id === chainId);
148-
if (!chainInfo?.bundlerUrl) {
147+
if (!chainInfo) {
149148
return undefined;
150149
}
151150

@@ -154,6 +153,16 @@ export class Signer implements SignerInterface {
154153
return undefined;
155154
}
156155

156+
// In prividium mode, use transport from constructor; otherwise use bundlerUrl
157+
const bundlerTransport = chainInfo.prividiumMode
158+
? this.transports[chainId]
159+
: http(chainInfo.bundlerUrl);
160+
161+
if (!bundlerTransport) {
162+
console.error(`Prividium mode requires a transport for chain ${chainId}`);
163+
return undefined;
164+
}
165+
157166
const publicClient = createPublicClient({
158167
chain,
159168
transport: this.transports[chain.id] || http(),
@@ -162,7 +171,7 @@ export class Signer implements SignerInterface {
162171
this.bundlerClients[chain.id] = createBundlerClient({
163172
client: publicClient,
164173
chain,
165-
transport: http(chainInfo.bundlerUrl),
174+
transport: bundlerTransport,
166175
userOperation: {
167176
// Use fixed gas values matching old Rust SDK implementation
168177
// (old SDK used: 2M callGas, 2M verificationGas, 1M preVerificationGas)
@@ -333,6 +342,9 @@ export class Signer implements SignerInterface {
333342
case "eth_accounts": {
334343
return this.accounts as ExtractReturnType<TMethod>;
335344
}
345+
case "eth_chainId": {
346+
return toHex(this.chain.id) as ExtractReturnType<TMethod>;
347+
}
336348
default:
337349
return undefined;
338350
}

packages/sdk-4337/src/client-auth-server/rpc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export type AuthServerRpcSchema = [
2828
id: Chain["id"];
2929
capabilities: Record<string, unknown>;
3030
contracts: SessionRequiredContracts;
31-
bundlerUrl?: string;
31+
bundlerUrl: string;
32+
prividiumMode: boolean;
3233
}[];
3334
};
3435
},

0 commit comments

Comments
 (0)