Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / lib / interfaces / KeyTransparency.ts
blob2f9eebf92b690431f265609a3836a050510e0f70
1 import type { PublicKeyReference } from '@proton/crypto';
2 import type { Epoch, SelfAuditResult } from '@proton/key-transparency/lib';
3 import type { APP_NAMES } from '@proton/shared/lib/constants';
5 import type { Address } from './Address';
6 import type { Api } from './Api';
7 import type { ProcessedApiKey } from './EncryptionPreferences';
8 import type { DecryptedAddressKey, DecryptedKey, KeyPair } from './Key';
9 import type { FetchedSignedKeyList, SignedKeyList } from './SignedKeyList';
10 import type { User } from './User';
11 import type { PrimaryAddressKeys } from '../keys';
13 export enum IGNORE_KT {
14     NORMAL,
15     EXTERNAL,
16     CATCHALL,
19 export interface ProcessedAddressKey extends ProcessedApiKey {
20     flags: number;
21     publicKey: PublicKeyReference;
22     primary: 1 | 0;
25 export interface KTLocalStorageAPI {
26     getBlobs: () => Promise<string[]>;
27     removeItem: (key: string) => Promise<void | undefined>;
28     getItem: (key: string) => Promise<string | null | undefined>;
29     setItem: (key: string, value: string) => Promise<void | undefined>;
32 export interface SelfAuditState {
33     userKeys: KeyPair[];
34     lastSelfAudit: SelfAuditResult | undefined;
35     addresses: {
36         address: Address;
37         addressKeys: DecryptedAddressKey[];
38     }[];
41 export interface KeyTransparencyState {
42     selfAuditResult?: SelfAuditResult;
45 export type KeyTransparencyVerify = (
46     address: Address,
47     signedKeyList: SignedKeyList,
48     publicKeys: PublicKeyReference[]
49 ) => Promise<void>;
50 export type PreAuthKTVerify = (userKeys: DecryptedKey[]) => KeyTransparencyVerify;
51 export type KeyTransparencyCommit = (userKeys: DecryptedKey[]) => Promise<void>;
53 export interface PreAuthKTVerifier {
54     preAuthKTVerify: PreAuthKTVerify;
55     preAuthKTCommit: (userID: string, api: Api) => Promise<void>;
58 export interface KTUserContext {
59     appName: APP_NAMES;
60     getUser: () => Promise<User>;
61     getUserKeys: () => Promise<DecryptedKey[]>;
62     getAddressKeys: (addressID: string) => Promise<DecryptedKey[]>;
65 export type VerifyOutboundPublicKeys = (data: {
66     userContext?: KTUserContext;
67     email: string;
68     /**
69      * Optimisations for apps where users with external domains do not have valid keys (e.g. Mail)
70      */
71     skipVerificationOfExternalDomains: boolean;
72     address: {
73         keyList: ProcessedApiKey[];
74         signedKeyList: FetchedSignedKeyList | null;
75     };
76     catchAll?: {
77         keyList: ProcessedApiKey[];
78         signedKeyList: FetchedSignedKeyList | null;
79     };
80     api: Api;
81 }) => Promise<{
82     addressKTResult?: KeyTransparencyVerificationResult;
83     catchAllKTResult?: KeyTransparencyVerificationResult;
84 }>;
86 export type SaveSKLToLS = (data: {
87     userContext: KTUserContext;
88     email: string;
89     data: string;
90     revision: number;
91     expectedMinEpochID: number;
92     addressID?: string;
93     isCatchall: boolean;
94 }) => Promise<void>;
96 export type KeyMigrationKTVerifier = (options: {
97     email: string;
98     signedKeyList: Partial<FetchedSignedKeyList> | null | undefined;
99     api: Api;
100 }) => Promise<void>;
102 export enum KeyTransparencyActivation {
103     DISABLED,
104     LOG_ONLY,
105     SHOW_UI,
108 export type GetLatestEpoch = (forceRefresh?: boolean) => Promise<Epoch>;
110 export enum KT_VERIFICATION_STATUS {
111     VERIFIED_KEYS,
112     UNVERIFIED_KEYS,
113     VERIFICATION_FAILED,
116 export interface KeyTransparencyVerificationResult {
117     status: KT_VERIFICATION_STATUS;
118     keysChangedRecently?: boolean;
121 export type UploadMissingSKL = (data: {
122     address: Address;
123     epoch: Epoch;
124     userContext: KTUserContext;
125     api: Api;
126 }) => Promise<void>;
128 export type ResetSelfAudit = (user: User, keyPassword: string, addressesBeforeReset: Address[]) => Promise<void>;
130 export interface ResignSKLWithPrimaryKeyArguments {
131     address: Address;
132     newPrimaryKeys: PrimaryAddressKeys;
133     formerPrimaryKeys: PrimaryAddressKeys;
134     userKeys: DecryptedKey[];
137 export type ResignSKLWithPrimaryKey = (args: ResignSKLWithPrimaryKeyArguments) => Promise<void>;