Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support browser extensions #46

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add context mode for server
  • Loading branch information
raynirola committed Apr 14, 2024
commit 65e52e73f6d2466107501091850b0f0f9d7d3703
6 changes: 3 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ interface AuthenticationChecks {
}


export async function verifyAuthentication(authenticationRaw: AuthenticationEncoded, credential: CredentialKey, expected: AuthenticationChecks): Promise<AuthenticationParsed> {
export async function verifyAuthentication(authenticationRaw: AuthenticationEncoded, credential: CredentialKey, expected: AuthenticationChecks, mode: "browser" | "extension" = "browser"): Promise<AuthenticationParsed> {
if (authenticationRaw.credentialId !== credential.id)
throw new Error(`Credential ID mismatch: ${authenticationRaw.credentialId} vs ${credential.id}`)

Expand Down Expand Up @@ -79,7 +79,7 @@ export async function verifyAuthentication(authenticationRaw: AuthenticationEnco
throw new Error(`Unexpected ClientData challenge: ${authentication.client.challenge}`)

// this only works because we consider `rp.origin` and `rp.id` to be the same during authentication/registration
const rpId = new URL(authentication.client.origin).hostname
const rpId = mode === "extension" ? authentication.client.origin : new URL(authentication.client.origin).hostname
const expectedRpIdHash = utils.toBase64url(await utils.sha256(utils.toBuffer(rpId)))
if (authentication.authenticator.rpIdHash !== expectedRpIdHash)
throw new Error(`Unexpected RpIdHash: ${authentication.authenticator.rpIdHash} vs ${expectedRpIdHash}`)
Expand Down Expand Up @@ -160,7 +160,7 @@ type VerifyParams = {
export async function verifySignature({ algorithm, publicKey, authenticatorData, clientData, signature, verbose }: VerifyParams): Promise<boolean> {
const algoParams = getAlgoParams(algorithm)
let cryptoKey = await parseCryptoKey(algoParams, publicKey)

if(verbose) {
console.debug(cryptoKey)
}
Expand Down