Use same lock values as mobile clients
[ProtonMail-WebClient.git] / packages / shared / lib / keys / setupAddressKeys.ts
blob88554e4e1f03a4c016eef5988c59ebd282a9e865
1 import type { ProductParam } from '@proton/shared/lib/apps/product';
3 import { setupAddress as setupAddressRoute } from '../api/addresses';
4 import type { Api, PreAuthKTVerify, Address as tsAddress } from '../interfaces';
5 import { handleSetupKeys } from './setupKeys';
7 interface SetupAddressArgs {
8     api: Api;
9     username: string;
10     domain: string;
13 export const handleSetupAddress = async ({ api, username, domain }: SetupAddressArgs) => {
14     if (!domain) {
15         throw new Error('Missing domain');
16     }
17     const { Address } = await api<{ Address: tsAddress }>(
18         setupAddressRoute({
19             Domain: domain,
20             DisplayName: username,
21             Signature: '',
22         })
23     );
24     return [Address];
27 interface SetupAddressKeysArgs {
28     password: string;
29     api: Api;
30     username: string;
31     addresses: tsAddress[];
32     domains: string[];
33     preAuthKTVerify: PreAuthKTVerify;
34     productParam: ProductParam;
37 export const handleSetupAddressKeys = async ({
38     username,
39     password,
40     api,
41     addresses,
42     domains,
43     preAuthKTVerify,
44     productParam,
45 }: SetupAddressKeysArgs) => {
46     const addressesToUse =
47         addresses?.length > 0 ? addresses : await handleSetupAddress({ api, domain: domains[0], username });
49     return handleSetupKeys({ api, addresses: addressesToUse, password, preAuthKTVerify, product: productParam });