1 import type { ProductParam } from '@proton/shared/lib/apps/product';
2 import type { DeviceSecretData } from '@proton/shared/lib/keys/device';
4 import { setupAddress as setupAddressRoute } from '../api/addresses';
5 import type { Api, PreAuthKTVerify, Address as tsAddress } from '../interfaces';
6 import { handleSetupKeys } from './setupKeys';
8 interface SetupAddressArgs {
14 export const handleSetupAddress = async ({ api, username, domain }: SetupAddressArgs) => {
16 throw new Error('Missing domain');
18 const { Address } = await api<{ Address: tsAddress }>(
21 DisplayName: username,
28 interface SetupAddressKeysArgs {
32 addresses: tsAddress[];
34 preAuthKTVerify: PreAuthKTVerify;
35 productParam: ProductParam;
36 deviceSecretData?: DeviceSecretData;
39 export const handleSetupAddressKeys = async ({
47 }: SetupAddressKeysArgs) => {
48 const addressesToUse =
49 addresses?.length > 0 ? addresses : await handleSetupAddress({ api, domain: domains[0], username });
51 return handleSetupKeys({
53 addresses: addressesToUse,
56 product: productParam,