Skip to content

Commit 6b72da8

Browse files
committed
feat: add more paymaster
1 parent a60ed6f commit 6b72da8

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

examples/nft-quest/stores/connector.ts

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { startRegistration } from "@simplewebauthn/browser";
22
import type { Address, Hex } from "viem";
3+
import { concat, decodeErrorResult, encodeFunctionData } from "viem";
4+
import { entryPoint07Address } from "viem/account-abstraction";
5+
import { prepareDeploySmartAccount } from "zksync-sso-4337/client";
6+
7+
import contractsConfig from "../contracts-anvil.json";
8+
import { useAccountStore } from "./account";
9+
import { useClientStore } from "./client";
310

411
export const useConnectorStore = defineStore("connector", () => {
512
const accountStore = useAccountStore();
@@ -113,19 +120,61 @@ export const useConnectorStore = defineStore("connector", () => {
113120
const toHex = (arr: Uint8Array) => `0x${Array.from(arr).map((b) => b.toString(16).padStart(2, "0")).join("")}` as Hex;
114121
const x = toHex(xBytes);
115122
const y = toHex(yBytes);
116-
// WORKAROUND: Use Anvil rich account #1 for testing
117-
// This bypasses smart account deployment which requires factory contracts
118-
// TODO: Deploy factory contracts once forge deployment issue is resolved
119-
const richAccountAddress = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" as Address;
120-
121-
console.log("WORKAROUND: Using rich account", {
122-
address: richAccountAddress,
123-
credentialId: credIdHex,
124-
passkeyCoords: { x, y },
123+
const clientStore = useClientStore();
124+
const publicClient = clientStore.getPublicClient();
125+
126+
const { transaction } = prepareDeploySmartAccount({
127+
contracts: {
128+
factory: contractsConfig.factory as Address,
129+
webauthnValidator: contractsConfig.webauthnValidator as Address,
130+
},
131+
passkeySigners: [{
132+
credentialId: credIdHex,
133+
publicKey: { x, y },
134+
originDomain: window.location.origin,
135+
}],
125136
});
126-
accountStore.setAccount(richAccountAddress, credIdHex);
127-
return { address: richAccountAddress, credentialId: credIdHex };
137+
138+
const initCode = concat([transaction.to, transaction.data]);
139+
const entryPoint = entryPoint07Address;
140+
141+
let senderAddress: Address;
142+
try {
143+
await publicClient.call({
144+
to: entryPoint,
145+
data: encodeFunctionData({
146+
abi: [{
147+
name: "getSenderAddress",
148+
type: "function",
149+
stateMutability: "view",
150+
inputs: [{ name: "initCode", type: "bytes" }],
151+
outputs: [],
152+
}],
153+
functionName: "getSenderAddress",
154+
args: [initCode],
155+
}),
156+
});
157+
throw new Error("getSenderAddress did not revert");
158+
} catch (e) {
159+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
160+
const data = (e as any).data || (e as any).cause?.data || (e as any).cause?.cause?.data;
161+
if (!data) throw e;
162+
163+
const error = decodeErrorResult({
164+
abi: [{
165+
name: "SenderAddressResult",
166+
type: "error",
167+
inputs: [{ name: "sender", type: "address" }],
168+
}],
169+
data,
170+
});
171+
senderAddress = error.args[0];
172+
}
173+
174+
accountStore.setAccount(senderAddress, credIdHex);
175+
return { address: senderAddress, credentialId: credIdHex };
128176
} catch (error) {
177+
// eslint-disable-next-line no-console
129178
console.error("Failed to connect account:", error);
130179
throw error;
131180
}

examples/nft-quest/tests/main.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ test("Create account with passkey and mint NFT", async ({ page }) => {
8484
await expect(page.getByText("You've got Zeek.")).toBeVisible();
8585

8686
// Send a friend the NFT
87-
const richWallet0 = "0x36615Cf349d7F6344891B1e7CA7C72883F5dc049";
88-
await page.getByPlaceholder("Wallet address").fill(richWallet0);
87+
const randomRecipient = "0x1234567890123456789012345678901234567890";
88+
await page.getByPlaceholder("Wallet address").fill(randomRecipient);
8989
await page.getByRole("button", { name: "Mint and send" }).click();
9090
await expect(page.getByTestId("spinner")).not.toBeVisible({ timeout: 60000 });
9191
await expect(page.getByText("You've sent the minted copy to")).toBeVisible({ timeout: 15000 });

0 commit comments

Comments
 (0)