Skip to content

Commit e4e2cf0

Browse files
committed
fix: add signature e2e tests
1 parent 21e4ed7 commit e4e2cf0

File tree

3 files changed

+106
-2
lines changed

3 files changed

+106
-2
lines changed

examples/demo-app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@simplewebauthn/server": "^13.1.1",
1717
"@wagmi/core": "^2.13.3",
1818
"@web3modal/wagmi": "^5.1.11",
19-
"@zksync-sso/connector-export": "workspace:*",
2019
"ethers": "^6.13.2",
2120
"nuxt": "^3.12.3",
2221
"viem": "2.30.0",

examples/demo-app/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
class="mt-4"
7474
>
7575
<p class="break-all">
76-
<strong>Signature:</strong> <span class="text-xs line-clamp-3">{{ typedDataSignature }}</span>
76+
<strong>Signature:</strong> <span class="text-xs line-clamp-2">{{ typedDataSignature }}</span>
7777
</p>
7878
</div>
7979
<div

examples/demo-app/tests/create-account.spec.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,108 @@ test("Create passkey account and send ETH with paymaster", async ({ page }) => {
369369
await expect(startBalance, "Balance after transfer should be 0.1 ETH less (no fees)")
370370
.toEqual(endBalance + 0.1);
371371
});
372+
373+
test("Create passkey account and sign typed data", async ({ page }) => {
374+
// Click the Connect button
375+
await page.getByRole("button", { name: "Connect", exact: true }).click();
376+
377+
// Ensure popup is displayed
378+
await page.waitForTimeout(2000);
379+
let popup = page.context().pages()[1];
380+
await expect(popup.getByText("Connect to")).toBeVisible();
381+
popup.on("console", (msg) => {
382+
if (msg.type() === "error")
383+
console.log(`Auth server error console: "${msg.text()}"`);
384+
});
385+
popup.on("pageerror", (exception) => {
386+
console.log(`Auth server uncaught exception: "${exception}"`);
387+
});
388+
389+
// Setup webauthn a Chrome Devtools Protocol session
390+
// NOTE: This needs to be done for every page of every test that uses WebAuthn
391+
let client = await popup.context().newCDPSession(popup);
392+
await client.send("WebAuthn.enable");
393+
await client.send("WebAuthn.addVirtualAuthenticator", {
394+
options: {
395+
protocol: "ctap2",
396+
transport: "usb",
397+
hasResidentKey: true,
398+
hasUserVerification: true,
399+
isUserVerified: true,
400+
automaticPresenceSimulation: true,
401+
},
402+
});
403+
let newCredential = null;
404+
client.on("WebAuthn.credentialAdded", (credentialAdded) => {
405+
console.log("New Passkey credential added");
406+
console.log(`Authenticator ID: ${credentialAdded.authenticatorId}`);
407+
console.log(`Credential: ${credentialAdded.credential}`);
408+
newCredential = credentialAdded.credential;
409+
});
410+
411+
// Click Sign Up
412+
await popup.getByTestId("signup").click();
413+
414+
// Confirm access to your account
415+
await expect(popup.getByText("Connect to ZKsync SSO Demo")).toBeVisible();
416+
await expect(popup.getByText("localhost:3004")).toBeVisible();
417+
await expect(popup.getByText("Let it see your address, balance and activity")).toBeVisible();
418+
await popup.getByTestId("connect").click();
419+
420+
// Waits for session to complete and popup to close
421+
await page.waitForTimeout(2000);
422+
423+
// Check address/balance is shown
424+
await expect(page.getByText("Disconnect")).toBeVisible();
425+
await expect(page.getByText("Balance:")).toBeVisible();
426+
427+
// Verify typed data section is visible
428+
await expect(page.getByText("Typed Data Signature Verification")).toBeVisible();
429+
await expect(page.getByRole("button", { name: "Sign Typed Data" })).toBeVisible();
430+
431+
// Click Sign Typed Data button
432+
await page.getByRole("button", { name: "Sign Typed Data" }).click();
433+
434+
// Wait for Auth Server popup to open
435+
await page.waitForTimeout(2000);
436+
popup = page.context().pages()[1];
437+
438+
// We need to recreate the virtual authenticator to match the previous one
439+
client = await popup.context().newCDPSession(popup);
440+
await client.send("WebAuthn.enable");
441+
const result = await client.send("WebAuthn.addVirtualAuthenticator", {
442+
options: {
443+
protocol: "ctap2",
444+
transport: "usb",
445+
hasResidentKey: true,
446+
hasUserVerification: true,
447+
isUserVerified: true,
448+
automaticPresenceSimulation: true,
449+
},
450+
});
451+
await expect(newCredential).not.toBeNull();
452+
await client.send("WebAuthn.addCredential", {
453+
authenticatorId: result.authenticatorId,
454+
credential: newCredential!,
455+
});
456+
457+
// Verify the sign typed data popup content
458+
await expect(popup.getByText("Sign Typed Data Request")).toBeVisible();
459+
await expect(popup.getByText("Message (TestStruct)", { exact: true })).toBeVisible();
460+
461+
// Click Sign button in the popup
462+
await popup.getByTestId("confirm").click();
463+
464+
// Wait for signature to complete and popup to close
465+
await page.waitForTimeout(3000);
466+
467+
// Verify signature appears on main page
468+
await expect(page.getByText("Signature:")).toBeVisible();
469+
470+
// Wait for signature verification to complete
471+
await page.waitForTimeout(2000);
472+
473+
// Verify signature validation shows as successful
474+
await expect(page.getByText("Typed Data Verification Result:")).toBeVisible();
475+
await expect(page.getByText("Valid ✓")).toBeVisible();
476+
});

0 commit comments

Comments
 (0)