@@ -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