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 {
13 export const handleSetupAddress = async ({ api, username, domain }: SetupAddressArgs) => {
15 throw new Error('Missing domain');
17 const { Address } = await api<{ Address: tsAddress }>(
20 DisplayName: username,
27 interface SetupAddressKeysArgs {
31 addresses: tsAddress[];
33 preAuthKTVerify: PreAuthKTVerify;
34 productParam: ProductParam;
37 export const handleSetupAddressKeys = async ({
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 });