1 import type { ProductParam } from '@proton/shared/lib/apps/product';
2 import { getProductHeaders } from '@proton/shared/lib/apps/product';
4 import type { AddressKeyPayload, AddressKeyPayloadV2, SignedKeyList } from '../interfaces';
6 interface GetPublicKeysForInboxParams {
11 /** @deprecated in favor of `getAllPublicKeys` */
12 export const getPublicKeys = (params: GetPublicKeysForInboxParams) => ({
18 interface GetAllPublicKeysParams {
23 export const getAllPublicKeys = (params: GetAllPublicKeysParams) => ({
24 url: 'core/v4/keys/all',
29 export const getKeySalts = () => ({
30 url: 'core/v4/keys/salts',
34 interface CreateUserKeyPayload {
39 export const createUserKeyRoute = (data: CreateUserKeyPayload) => ({
40 url: 'core/v4/keys/user',
45 interface AddressKeyToken {
51 interface AddressTokensPayload {
52 AddressKeyTokens: AddressKeyToken[];
55 export const replaceAddressTokens = (data: AddressTokensPayload) => ({
56 url: 'core/v4/keys/tokens',
61 interface CreateAddressKeyPayload {
65 SignedKeyList: SignedKeyList;
66 AddressForwardingID?: string;
67 GroupMemberID?: string;
70 export const createAddressKeyRoute = (data: CreateAddressKeyPayload) => ({
76 interface CreateAddressKeyPayloadV2 extends CreateAddressKeyPayload {
81 export const createAddressKeyRouteV2 = (data: CreateAddressKeyPayloadV2) => ({
82 url: 'core/v4/keys/address',
87 interface CreateGroupAddressKeyPayload {
92 SignedKeyList: SignedKeyList;
95 export const createGroupAddressKeyRoute = (data: CreateGroupAddressKeyPayload) => ({
96 url: 'core/v4/keys/group',
101 export enum AddressActiveStatus {
106 export interface ActiveAddressKeyPayload {
107 AddressKeyID: string;
108 Active: AddressActiveStatus;
111 interface UpdateAddressActiveKeysRoutePayload {
113 Keys: ActiveAddressKeyPayload[];
114 SignedKeyList: SignedKeyList;
117 export const updateAddressActiveKeysRoute = (data: UpdateAddressActiveKeysRoutePayload) => ({
118 url: 'core/v4/keys/address/active',
123 interface BaseSetupKeysPayload {
126 AddressKeys: (AddressKeyPayload | AddressKeyPayloadV2)[];
129 interface UnprivatizationSetupKeysPayload extends BaseSetupKeysPayload {
130 OrgActivationToken: string;
131 OrgPrimaryUserKey: string;
134 type SetupKeysPayload = UnprivatizationSetupKeysPayload | BaseSetupKeysPayload;
136 export const setupKeys = (data: SetupKeysPayload, product: ProductParam) => ({
137 url: 'core/v4/keys/setup',
141 headers: getProductHeaders(product, {
142 endpoint: 'core/v4/keys/setup',
147 interface ActivateKeyPayload {
150 SignedKeyList: SignedKeyList;
153 export const activateKeyRoute = ({ ID, ...data }: ActivateKeyPayload) => ({
154 url: `core/v4/keys/${ID}/activate`,
159 interface ActivateKeyPayloadV2 extends ActivateKeyPayload {
164 export const activateKeyRouteV2 = ({ ID, ...data }: ActivateKeyPayloadV2) => ({
165 url: `core/v4/keys/address/${ID}`,
170 export const reactiveLegacyAddressKeyRouteV2 = ({ ID, ...data }: ActivateKeyPayloadV2) => ({
171 url: `core/v4/keys/address/${ID}`,
176 interface ReactivateKeyPayload {
179 SignedKeyList?: SignedKeyList;
182 export const reactivateKeyRoute = ({ ID, PrivateKey, SignedKeyList }: ReactivateKeyPayload) => ({
183 url: `core/v4/keys/${ID}`,
191 interface ReactivateUserKeyPayloadV2 {
194 AddressKeyFingerprints: string[];
196 [key: string]: SignedKeyList;
200 export const reactivateUserKeyRouteV2 = ({ ID, ...data }: ReactivateUserKeyPayloadV2) => ({
201 url: `core/v4/keys/user/${ID}`,
206 interface SetKeyPrimaryPayload {
208 SignedKeyList: SignedKeyList;
211 export const setKeyPrimaryRoute = ({ ID, ...data }: SetKeyPrimaryPayload) => ({
212 url: `core/v4/keys/${ID}/primary`,
217 interface SetKeyFlagsPayload {
220 SignedKeyList: SignedKeyList;
223 export const setKeyFlagsRoute = ({ ID, ...data }: SetKeyFlagsPayload) => ({
224 url: `core/v4/keys/${ID}/flags`,
229 interface RemoveKeyPayload {
231 SignedKeyList: SignedKeyList;
234 export const removeKeyRoute = ({ ID, ...data }: RemoveKeyPayload) => ({
235 url: `core/v4/keys/${ID}/delete`,
240 export interface UpdatePrivateKeyPayload {
242 Keys: { ID: string; PrivateKey: string }[];
243 OrganizationKey?: string;
244 PersistPasswordScope?: boolean;
247 export interface UpdatePrivateKeyPayloadV2 {
249 UserKeys: { ID: string; PrivateKey: string }[];
250 OrganizationKey?: string;
251 PersistPasswordScope?: boolean;
254 export const updatePrivateKeyRoute = (data: UpdatePrivateKeyPayload | UpdatePrivateKeyPayloadV2) => ({
255 url: 'core/v4/keys/private',
260 export interface ResetKeysPayload {
266 export interface ResetKeysPayloadWithKeys extends ResetKeysPayload {
268 AddressKeys: AddressKeyPayload[];
271 export interface ResetKeysPayloadV2 extends ResetKeysPayload {
273 AddressKeys: AddressKeyPayloadV2[];
276 export const resetKeysRoute = (data: ResetKeysPayloadWithKeys | ResetKeysPayloadV2 | ResetKeysPayload) => ({
277 url: 'core/v4/keys/reset',
282 interface UpgradeKeyPayload {
287 interface UpgradeKeysPayload {
289 Keys: UpgradeKeyPayload[];
290 OrganizationKey?: string;
293 export interface UpgradeAddressKeyPayload {
300 interface UpgradeKeysPayloadV2 {
302 UserKeys: UpgradeKeyPayload[];
303 AddressKeys: UpgradeAddressKeyPayload[];
304 OrganizationKey?: string;
306 [key: string]: SignedKeyList;
310 export const upgradeKeysRoute = (data: UpgradeKeysPayload | UpgradeKeysPayloadV2) => ({
311 url: 'core/v4/keys/private/upgrade',
316 export interface MigrateAddressKeyPayload {
323 export interface MigrateAddressKeysPayload {
324 AddressKeys: MigrateAddressKeyPayload[];
325 SignedKeyLists: { [key: string]: SignedKeyList };
328 export const migrateAddressKeysRoute = (data: MigrateAddressKeysPayload) => ({
329 url: 'core/v4/keys/migrate',
334 export interface GetSignedKeyListsParams {
335 AfterRevision?: number;
339 export const getSignedKeyListsRoute = (params: GetSignedKeyListsParams) => ({
340 url: 'core/v4/keys/signedkeylists',
345 export interface GetSignedKeyListParams {
350 export const getSignedKeyListRoute = (params: GetSignedKeyListParams) => ({
351 url: 'keys/signedkeylist',
356 export interface UpdateSignedKeyListPayload {
358 SignedKeyList: SignedKeyList;
361 export const updateSignedKeyListRoute = (data: UpdateSignedKeyListPayload) => ({
362 url: 'core/v4/keys/signedkeylists',
367 export interface UpdateSignedKeyListSignatureData {
373 export const updateSignedKeyListSignatureRoute = (data: UpdateSignedKeyListSignatureData) => ({
374 url: 'core/v4/keys/signedkeylists/signature',