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 {
19 export interface ProcessedAddressKey extends ProcessedApiKey {
21 publicKey: PublicKeyReference;
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 {
34 lastSelfAudit: SelfAuditResult | undefined;
37 addressKeys: DecryptedAddressKey[];
41 export interface KeyTransparencyState {
42 selfAuditResult?: SelfAuditResult;
45 export type KeyTransparencyVerify = (
47 signedKeyList: SignedKeyList,
48 publicKeys: PublicKeyReference[]
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 {
60 getUser: () => Promise<User>;
61 getUserKeys: () => Promise<DecryptedKey[]>;
62 getAddressKeys: (addressID: string) => Promise<DecryptedKey[]>;
65 export type VerifyOutboundPublicKeys = (data: {
66 userContext?: KTUserContext;
69 * Optimisations for apps where users with external domains do not have valid keys (e.g. Mail)
71 skipVerificationOfExternalDomains: boolean;
73 keyList: ProcessedApiKey[];
74 signedKeyList: FetchedSignedKeyList | null;
77 keyList: ProcessedApiKey[];
78 signedKeyList: FetchedSignedKeyList | null;
82 addressKTResult?: KeyTransparencyVerificationResult;
83 catchAllKTResult?: KeyTransparencyVerificationResult;
86 export type SaveSKLToLS = (data: {
87 userContext: KTUserContext;
91 expectedMinEpochID: number;
96 export type KeyMigrationKTVerifier = (options: {
98 signedKeyList: Partial<FetchedSignedKeyList> | null | undefined;
102 export enum KeyTransparencyActivation {
108 export type GetLatestEpoch = (forceRefresh?: boolean) => Promise<Epoch>;
110 export enum KT_VERIFICATION_STATUS {
116 export interface KeyTransparencyVerificationResult {
117 status: KT_VERIFICATION_STATUS;
118 keysChangedRecently?: boolean;
121 export type UploadMissingSKL = (data: {
124 userContext: KTUserContext;
128 export type ResetSelfAudit = (user: User, keyPassword: string, addressesBeforeReset: Address[]) => Promise<void>;
130 export interface ResignSKLWithPrimaryKeyArguments {
132 newPrimaryKeys: PrimaryAddressKeys;
133 formerPrimaryKeys: PrimaryAddressKeys;
134 userKeys: DecryptedKey[];
137 export type ResignSKLWithPrimaryKey = (args: ResignSKLWithPrimaryKeyArguments) => Promise<void>;