Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / lib / passkeys / utils.ts
blobef3171cbe41a1e0ea092cfe33924cc2fecdbd3ad
1 import type { WasmGeneratePasskeyResponse } from '@protontech/pass-rust-core';
3 import type { PassConfig } from '@proton/pass/hooks/usePassConfig';
4 import type { Passkey } from '@proton/pass/types/protobuf/item-v1';
5 import { getEpoch } from '@proton/pass/utils/time/epoch';
6 import { getClientID } from '@proton/shared/lib/apps/helper';
7 import { getBrowser, getDevice } from '@proton/shared/lib/helpers/browser';
8 import { base64StringToUint8Array, uint8ArrayToBase64String } from '@proton/shared/lib/helpers/encoding';
10 import type { SanitizedPasskey } from './types';
12 export const parsePasskey = (passkey: SanitizedPasskey): Passkey => ({
13     ...passkey,
14     content: base64StringToUint8Array(passkey.content),
15     credentialId: base64StringToUint8Array(passkey.credentialId),
16     userHandle: base64StringToUint8Array(passkey.userHandle),
17     userId: base64StringToUint8Array(passkey.userId),
18 });
20 export const sanitizePasskey = (response: WasmGeneratePasskeyResponse, config: PassConfig): SanitizedPasskey => ({
21     keyId: response.key_id,
22     content: uint8ArrayToBase64String(new Uint8Array(response.passkey)),
23     domain: response.domain,
24     rpId: response.rp_id!,
25     rpName: response.rp_name,
26     userName: response.user_name,
27     userDisplayName: response.user_display_name,
28     userId: uint8ArrayToBase64String(new Uint8Array(response.user_id)),
29     createTime: getEpoch(),
30     note: '',
31     credentialId: uint8ArrayToBase64String(new Uint8Array(response.credential_id)),
32     userHandle: uint8ArrayToBase64String(new Uint8Array(response.user_handle ?? [])),
33     creationData: {
34         osName: getBrowser().name ?? '',
35         osVersion: getBrowser().version ?? '',
36         deviceName: getDevice().vendor ?? '',
37         appVersion: `${getClientID(config.APP_NAME)}@${config.APP_VERSION}`,
38     },
39 });