mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 06:43:35 +00:00
PM-21553: Added support for credential.toJSON() (#15028)
* Added support for credential.toJSON() * Changed to import type
This commit is contained in:
@@ -88,6 +88,7 @@ export class WebauthnUtils {
|
|||||||
getClientExtensionResults: () => ({
|
getClientExtensionResults: () => ({
|
||||||
credProps: result.extensions.credProps,
|
credProps: result.extensions.credProps,
|
||||||
}),
|
}),
|
||||||
|
toJSON: () => Fido2Utils.createResultToJson(result),
|
||||||
} as PublicKeyCredential;
|
} as PublicKeyCredential;
|
||||||
|
|
||||||
// Modify prototype chains to fix `instanceof` calls.
|
// Modify prototype chains to fix `instanceof` calls.
|
||||||
@@ -134,6 +135,7 @@ export class WebauthnUtils {
|
|||||||
} as AuthenticatorAssertionResponse,
|
} as AuthenticatorAssertionResponse,
|
||||||
getClientExtensionResults: () => ({}),
|
getClientExtensionResults: () => ({}),
|
||||||
authenticatorAttachment: "platform",
|
authenticatorAttachment: "platform",
|
||||||
|
toJSON: () => Fido2Utils.getResultToJson(result),
|
||||||
} as PublicKeyCredential;
|
} as PublicKeyCredential;
|
||||||
|
|
||||||
// Modify prototype chains to fix `instanceof` calls.
|
// Modify prototype chains to fix `instanceof` calls.
|
||||||
|
|||||||
@@ -1,6 +1,45 @@
|
|||||||
// FIXME: Update this file to be type safe and remove this and next line
|
// FIXME: Update this file to be type safe and remove this and next line
|
||||||
|
import type {
|
||||||
|
AssertCredentialResult,
|
||||||
|
CreateCredentialResult,
|
||||||
|
} from "../../abstractions/fido2/fido2-client.service.abstraction";
|
||||||
|
|
||||||
// @ts-strict-ignore
|
// @ts-strict-ignore
|
||||||
export class Fido2Utils {
|
export class Fido2Utils {
|
||||||
|
static createResultToJson(result: CreateCredentialResult): any {
|
||||||
|
return {
|
||||||
|
id: result.credentialId,
|
||||||
|
rawId: result.credentialId,
|
||||||
|
response: {
|
||||||
|
clientDataJSON: result.clientDataJSON,
|
||||||
|
authenticatorData: result.authData,
|
||||||
|
transports: result.transports,
|
||||||
|
publicKey: result.publicKey,
|
||||||
|
publicKeyAlgorithm: result.publicKeyAlgorithm,
|
||||||
|
attestationObject: result.attestationObject,
|
||||||
|
},
|
||||||
|
authenticatorAttachment: "platform",
|
||||||
|
clientExtensionResults: result.extensions,
|
||||||
|
type: "public-key",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static getResultToJson(result: AssertCredentialResult): any {
|
||||||
|
return {
|
||||||
|
id: result.credentialId,
|
||||||
|
rawId: result.credentialId,
|
||||||
|
response: {
|
||||||
|
clientDataJSON: result.clientDataJSON,
|
||||||
|
authenticatorData: result.authenticatorData,
|
||||||
|
signature: result.signature,
|
||||||
|
userHandle: result.userHandle,
|
||||||
|
},
|
||||||
|
authenticatorAttachment: "platform",
|
||||||
|
clientExtensionResults: {},
|
||||||
|
type: "public-key",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static bufferToString(bufferSource: BufferSource): string {
|
static bufferToString(bufferSource: BufferSource): string {
|
||||||
return Fido2Utils.fromBufferToB64(Fido2Utils.bufferSourceToUint8Array(bufferSource))
|
return Fido2Utils.fromBufferToB64(Fido2Utils.bufferSourceToUint8Array(bufferSource))
|
||||||
.replace(/\+/g, "-")
|
.replace(/\+/g, "-")
|
||||||
|
|||||||
Reference in New Issue
Block a user