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)[];
127 EncryptedSecret?: string;
130 interface UnprivatizationSetupKeysPayload extends BaseSetupKeysPayload {
131 OrgActivationToken: string;
132 OrgPrimaryUserKey: string;
135 type SetupKeysPayload = UnprivatizationSetupKeysPayload | BaseSetupKeysPayload;
137 export const setupKeys = (data: SetupKeysPayload, product: ProductParam) => ({
138 url: 'core/v4/keys/setup',
142 headers: getProductHeaders(product, {
143 endpoint: 'core/v4/keys/setup',
148 interface ActivateKeyPayload {
151 SignedKeyList: SignedKeyList;
154 export const activateKeyRoute = ({ ID, ...data }: ActivateKeyPayload) => ({
155 url: `core/v4/keys/${ID}/activate`,
160 interface ActivateKeyPayloadV2 extends ActivateKeyPayload {
165 export const activateKeyRouteV2 = ({ ID, ...data }: ActivateKeyPayloadV2) => ({
166 url: `core/v4/keys/address/${ID}`,
171 export const reactiveLegacyAddressKeyRouteV2 = ({ ID, ...data }: ActivateKeyPayloadV2) => ({
172 url: `core/v4/keys/address/${ID}`,
177 interface ReactivateKeyPayload {
180 SignedKeyList?: SignedKeyList;
183 export const reactivateKeyRoute = ({ ID, PrivateKey, SignedKeyList }: ReactivateKeyPayload) => ({
184 url: `core/v4/keys/${ID}`,
192 interface ReactivateUserKeyPayloadV2 {
195 AddressKeyFingerprints: string[];
197 [key: string]: SignedKeyList;
201 export const reactivateUserKeyRouteV2 = ({ ID, ...data }: ReactivateUserKeyPayloadV2) => ({
202 url: `core/v4/keys/user/${ID}`,
207 interface SetKeyPrimaryPayload {
209 SignedKeyList: SignedKeyList;
212 export const setKeyPrimaryRoute = ({ ID, ...data }: SetKeyPrimaryPayload) => ({
213 url: `core/v4/keys/${ID}/primary`,
218 interface SetKeyFlagsPayload {
221 SignedKeyList: SignedKeyList;
224 export const setKeyFlagsRoute = ({ ID, ...data }: SetKeyFlagsPayload) => ({
225 url: `core/v4/keys/${ID}/flags`,
230 interface RemoveUserKeyPayload {
234 export const removeUserKeyRoute = ({ ID }: RemoveUserKeyPayload) => ({
235 url: `core/v4/keys/user/${ID}`,
239 interface RemoveAddressKeyPayload {
241 SignedKeyList: SignedKeyList | null;
244 export const removeAddressKeyRoute = ({ ID, ...data }: RemoveAddressKeyPayload) => ({
245 url: `core/v4/keys/address/${ID}/delete`,
250 export interface UpdatePrivateKeyPayload {
252 Keys: { ID: string; PrivateKey: string }[];
253 OrganizationKey?: string;
254 PersistPasswordScope?: boolean;
257 export interface UpdatePrivateKeyPayloadV2 {
259 UserKeys: { ID: string; PrivateKey: string }[];
260 OrganizationKey?: string;
261 PersistPasswordScope?: boolean;
262 EncryptedSecret?: string;
265 export const updatePrivateKeyRoute = (data: UpdatePrivateKeyPayload | UpdatePrivateKeyPayloadV2) => ({
266 url: 'core/v4/keys/private',
271 export interface ResetKeysPayload {
277 export interface ResetKeysPayloadWithKeys extends ResetKeysPayload {
279 AddressKeys: AddressKeyPayload[];
282 export interface ResetKeysPayloadV2 extends ResetKeysPayload {
284 AddressKeys: AddressKeyPayloadV2[];
287 export const resetKeysRoute = (data: ResetKeysPayloadWithKeys | ResetKeysPayloadV2 | ResetKeysPayload) => ({
288 url: 'core/v4/keys/reset',
293 interface UpgradeKeyPayload {
298 interface UpgradeKeysPayload {
300 Keys: UpgradeKeyPayload[];
301 OrganizationKey?: string;
304 export interface UpgradeAddressKeyPayload {
311 interface UpgradeKeysPayloadV2 {
313 UserKeys: UpgradeKeyPayload[];
314 AddressKeys: UpgradeAddressKeyPayload[];
315 OrganizationKey?: string;
317 [key: string]: SignedKeyList;
321 export const upgradeKeysRoute = (data: UpgradeKeysPayload | UpgradeKeysPayloadV2) => ({
322 url: 'core/v4/keys/private/upgrade',
327 export interface MigrateAddressKeyPayload {
334 export interface MigrateAddressKeysPayload {
335 AddressKeys: MigrateAddressKeyPayload[];
336 SignedKeyLists: { [key: string]: SignedKeyList };
339 export const migrateAddressKeysRoute = (data: MigrateAddressKeysPayload) => ({
340 url: 'core/v4/keys/migrate',
345 export interface GetSignedKeyListsParams {
346 AfterRevision?: number;
350 export const getSignedKeyListsRoute = (params: GetSignedKeyListsParams) => ({
351 url: 'core/v4/keys/signedkeylists',
356 export interface GetSignedKeyListParams {
361 export const getSignedKeyListRoute = (params: GetSignedKeyListParams) => ({
362 url: 'keys/signedkeylist',
367 export interface UpdateSignedKeyListPayload {
369 SignedKeyList: SignedKeyList;
372 export const updateSignedKeyListRoute = (data: UpdateSignedKeyListPayload) => ({
373 url: 'core/v4/keys/signedkeylists',
378 export interface UpdateSignedKeyListSignatureData {
384 export const updateSignedKeyListSignatureRoute = (data: UpdateSignedKeyListSignatureData) => ({
385 url: 'core/v4/keys/signedkeylists/signature',