1 import type { WasmPublicKeyCredentialAssertion, WasmPublicKeyCredentialAttestation } from '@protontech/pass-rust-core';
3 import { SafeUint8Array } from '@proton/pass/utils/buffer/sanitization';
5 export const intoAuthenticatorAttestationResponse = ({
7 }: WasmPublicKeyCredentialAttestation): AuthenticatorAttestationResponse =>
10 attestationObject: new SafeUint8Array(response.attestation_object).buffer,
11 clientDataJSON: new SafeUint8Array(response.client_data_json).buffer,
12 getAuthenticatorData: () => new SafeUint8Array(response.authenticator_data).buffer,
13 getPublicKey: () => (response.public_key ? new SafeUint8Array(response.public_key).buffer : null),
14 getPublicKeyAlgorithm: () => response.public_key_algorithm,
15 getTransports: () => response?.transports ?? [],
17 AuthenticatorAttestationResponse.prototype
20 export const intoAuthenticatorAssertionResponse = (
21 credential: WasmPublicKeyCredentialAssertion
22 ): AuthenticatorAssertionResponse =>
23 Object.setPrototypeOf(
25 clientDataJSON: new SafeUint8Array(credential.response.client_data_json).buffer,
26 authenticatorData: new SafeUint8Array(credential.response.authenticator_data).buffer,
27 signature: new SafeUint8Array(credential.response.signature).buffer,
28 userHandle: credential.response.user_handle
29 ? new SafeUint8Array(credential.response.user_handle).buffer
32 AuthenticatorAssertionResponse.prototype
35 export const intoPublicKeyCredential = (
36 result: WasmPublicKeyCredentialAttestation | WasmPublicKeyCredentialAssertion,
37 response: AuthenticatorAttestationResponse | AuthenticatorAssertionResponse,
38 clone: <T>(obj: T) => T
39 ): PublicKeyCredential =>
40 Object.setPrototypeOf(
42 authenticatorAttachment: result.authenticator_attachment,
44 rawId: new SafeUint8Array(result.raw_id).buffer,
47 getClientExtensionResults: () => clone(result.client_extension_results ?? {}),
49 PublicKeyCredential.prototype