6 } from '@proton/crypto';
8 import type { RequireSome } from './utils';
10 export interface KeyWithRecoverySecret extends Key {
11 RecoverySecret: string;
12 RecoverySecretSignature: string;
15 export interface Key {
19 Flags?: number; // Only available for address keys
21 Fingerprints: string[];
22 PublicKey: string; // armored key
25 PrivateKey: string; // armored key
27 Signature?: string; // Only available for address keys
28 RecoverySecret?: string | null; // Only available for user keys
29 RecoverySecretSignature?: string | null; // Only available for user keys
30 AddressForwardingID?: string | null; // Only available for address keys
33 export type AddressKey = RequireSome<Key, 'Flags' | 'Signature' | 'AddressForwardingID'>;
34 export type UserKey = RequireSome<Key, 'RecoverySecret' | 'RecoverySecretSignature'>;
36 export interface KeyPair<PrivateKeyReferenceWithVersion extends PrivateKeyReference = PrivateKeyReference> {
37 privateKey: PrivateKeyReferenceWithVersion;
38 publicKey: PublicKeyReference;
41 export interface KeysPair {
42 privateKeys: PrivateKeyReference[];
43 publicKeys: PublicKeyReference[];
46 export interface DecryptedKey<PrivateKeyReferenceWithVersion extends PrivateKeyReference = PrivateKeyReference>
47 extends KeyPair<PrivateKeyReferenceWithVersion> {
51 export interface DecryptedAddressKey extends KeyPair {
57 export interface InactiveKey {
62 export interface ActiveKey<
63 PrivateKeyReferenceWithVersion extends PrivateKeyReference = PrivateKeyReferenceV4 | PrivateKeyReferenceV6,
64 > extends DecryptedKey<PrivateKeyReferenceWithVersion> {
68 sha256Fingerprints: string[];
71 export type ActiveKeyWithVersion = ActiveKey<PrivateKeyReferenceV6> | ActiveKey<PrivateKeyReferenceV4>;
74 * Users who have generated a v6 address key might have two primary keys instead of one.
75 * This is because a v6 address key can only be marked as primary alongside a v4 key,
76 * for compatibility reasons with Proton apps/clients that do not support encrypting to v6 keys.
77 * We store v4 and v6 keys separately to make it easier to implement primary key changes and checks,
78 * and to help keep track of the key versions being used with TS support.
80 export interface ActiveAddressKeysByVersion {
81 v4: ActiveKey<PrivateKeyReferenceV4>[]; // one or more
82 v6: ActiveKey<PrivateKeyReferenceV6>[]; // zero or more
85 export const isActiveKeyV6 = (activeKey: ActiveKey): activeKey is ActiveKey<PrivateKeyReferenceV6> =>
86 activeKey.privateKey.isPrivateKeyV6();