diff --git a/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts b/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts
index 9cf42def..ba5df994 100644
--- a/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts
+++ b/src/api/routes/users/@me/mfa/webauthn/credentials/#key_id/index.ts
@@ -41,11 +41,10 @@ router.delete(
});
// disable webauthn if there are no keys left
- if (keys === 0)
- await User.update({ id: req.user_id }, { webauthn_enabled: false });
+ if (keys === 0) await User.update({ id: req.user_id }, { webauthn_enabled: false });
res.sendStatus(204);
- },
+ }
);
export default router;
diff --git a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts
index f383ffb7..b8e33da7 100644
--- a/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts
+++ b/src/api/routes/users/@me/mfa/webauthn/credentials/index.ts
@@ -35,15 +35,11 @@ import { ExpectedAttestationResult } from "fido2-lib";
import { HTTPError } from "lambert-server";
const router = Router();
-const isGenerateSchema = (
- body: WebAuthnPostSchema,
-): body is GenerateWebAuthnCredentialsSchema => {
+const isGenerateSchema = (body: WebAuthnPostSchema): body is GenerateWebAuthnCredentialsSchema => {
return "password" in body;
};
-const isCreateSchema = (
- body: WebAuthnPostSchema,
-): body is CreateWebAuthnCredentialSchema => {
+const isCreateSchema = (body: WebAuthnPostSchema): body is CreateWebAuthnCredentialSchema => {
return "credential" in body;
};
@@ -67,7 +63,7 @@ router.get("/", route({}), async (req: Request, res: Response) => {
securityKeys.map((key) => ({
id: key.id,
name: key.name,
- })),
+ }))
);
});
@@ -94,24 +90,13 @@ router.post(
where: {
id: req.user_id,
},
- select: [
- "data",
- "id",
- "disabled",
- "deleted",
- "totp_secret",
- "mfa_enabled",
- "username",
- ],
+ select: ["data", "id", "disabled", "deleted", "totp_secret", "mfa_enabled", "username"],
relations: ["settings"],
});
if (isGenerateSchema(req.body)) {
const { password } = req.body;
- const same_password = await bcrypt.compare(
- password,
- user.data.hash || "",
- );
+ const same_password = await bcrypt.compare(password, user.data.hash || "");
if (!same_password) {
throw FieldErrors({
password: {
@@ -121,14 +106,11 @@ router.post(
});
}
- const registrationOptions =
- await WebAuthn.fido2.attestationOptions();
+ const registrationOptions = await WebAuthn.fido2.attestationOptions();
const challenge = JSON.stringify({
publicKey: {
...registrationOptions,
- challenge: Buffer.from(
- registrationOptions.challenge,
- ).toString("base64"),
+ challenge: Buffer.from(registrationOptions.challenge).toString("base64"),
user: {
id: user.id,
name: user.username,
@@ -151,35 +133,22 @@ router.post(
const clientAttestationResponse = JSON.parse(credential);
- if (!clientAttestationResponse.rawId)
- throw new HTTPError("Missing rawId", 400);
+ if (!clientAttestationResponse.rawId) throw new HTTPError("Missing rawId", 400);
- const rawIdBuffer = Buffer.from(
- clientAttestationResponse.rawId,
- "base64",
- );
+ const rawIdBuffer = Buffer.from(clientAttestationResponse.rawId, "base64");
clientAttestationResponse.rawId = toArrayBuffer(rawIdBuffer);
- const attestationExpectations: ExpectedAttestationResult =
- JSON.parse(
- Buffer.from(
- clientAttestationResponse.response.clientDataJSON,
- "base64",
- ).toString(),
- );
-
- const regResult = await WebAuthn.fido2.attestationResult(
- clientAttestationResponse,
- {
- ...attestationExpectations,
- factor: "second",
- },
+ const attestationExpectations: ExpectedAttestationResult = JSON.parse(
+ Buffer.from(clientAttestationResponse.response.clientDataJSON, "base64").toString()
);
+ const regResult = await WebAuthn.fido2.attestationResult(clientAttestationResponse, {
+ ...attestationExpectations,
+ factor: "second",
+ });
+
const authnrData = regResult.authnrData;
- const keyId = Buffer.from(authnrData.get("credId")).toString(
- "base64",
- );
+ const keyId = Buffer.from(authnrData.get("credId")).toString("base64");
const counter = authnrData.get("counter");
const publicKey = authnrData.get("credentialPublicKeyPem");
@@ -191,10 +160,7 @@ router.post(
key_id: keyId,
});
- await Promise.all([
- securityKey.save(),
- User.update({ id: req.user_id }, { webauthn_enabled: true }),
- ]);
+ await Promise.all([securityKey.save(), User.update({ id: req.user_id }, { webauthn_enabled: true })]);
return res.json({
name,
@@ -203,7 +169,7 @@ router.post(
} else {
throw DiscordApiErrors.INVALID_AUTHENTICATION_TOKEN;
}
- },
+ }
);
export default router;
|