Skip to content

feat(passkey): create server side helper functions#20101

Merged
MagentaManifold merged 1 commit intomainfrom
FXA-13056
Feb 26, 2026
Merged

feat(passkey): create server side helper functions#20101
MagentaManifold merged 1 commit intomainfrom
FXA-13056

Conversation

@MagentaManifold
Copy link
Contributor

Because

  • we need helper functions for passkeys

This pull request

  • creates helpers wrapping @simplewebauthn/server library functions

Issue that this pull request solves

Closes: FXA-13056

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

@MagentaManifold MagentaManifold requested a review from a team as a code owner February 24, 2026 14:42
@nshirley nshirley self-assigned this Feb 25, 2026
@MagentaManifold
Copy link
Contributor Author

(just rebased to resolve a conflict with main)

Copy link
Contributor

@nshirley nshirley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments, but I'll leave it to you if you want to address them here - let me know what you think!


const libMocks = jest.requireMock('@simplewebauthn/server') as {
generateRegistrationOptions: jest.MockedFunction<
(...args: unknown[]) => Promise<unknown>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not know or have the types available here? If the underlying library changes function signature, we won't catch the changed with typescript, only during runtime. Probably unlikely, but also means we don't get strong typing on the expected results

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried introducing actual types here, but it ended up requiring using as to assert mocked values' types everywhere, which doesn't help with making types stronger. If the function changes to an incompatible signature, the main file won't compile, so I think we are fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. Having to use type assertion isn't great and just kind of moves the problem elsewhere. Thanks for trying though!

*
* @param config - PasskeyConfig instance (provides allowedOrigins, rpId)
* @param input - Per-request inputs: browser response, challenge, stored credential
* @returns verification result and extracted data (not a discriminated union, to match library output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious if it makes sense to have a better interface because we're making the wrapper.

As it is, if the verification fails, a caller could inadvertently still check data and proceed. But, using a discriminated union would allow strong type support and a caller would be able to check :

const result = await verifyRegistrationResponse(config, input);

if (result.verified) {
  // typescript knows the data exists here and we can do something with it
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be a reason why this function doesn't use a discriminated union, while the registration one does. Maybe it's for logging failed attempts? That said, in our case, if we only return signCount and sync status, there's no point in logging them for a failed attempt anyway. I'll make it a discriminated union

Because:

* we need helper functions for passkeys

This commit:

* creates helpers wrapping @simplewebauthn/server library functions

Closes FXA-13056
Copy link
Contributor

@nshirley nshirley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for checking out my suggestions!

@MagentaManifold MagentaManifold merged commit b7f67a6 into main Feb 26, 2026
22 checks passed
@MagentaManifold MagentaManifold deleted the FXA-13056 branch February 26, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants