forked from openpgpjs/openpgpjs
-
Notifications
You must be signed in to change notification settings - Fork 8
/
openpgp.d.ts
964 lines (851 loc) · 40.9 KB
/
openpgp.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
/* eslint-disable max-lines, @typescript-eslint/indent */
/**
* Type definitions for OpenPGP.js http://openpgpjs.org/
*
* Contributors:
* - FlowCrypt a. s. <https://flowcrypt.com>
* - Guillaume Lacasa <https://blog.lacasa.fr>
* - Errietta Kostala <https://github.com/errietta>
*/
import type { WebStream as GenericWebStream, NodeWebStream as GenericNodeWebStream } from '@openpgp/web-stream-tools';
/* ############## STREAM #################### */
type Data = Uint8Array | string;
// web-stream-tools might end up supporting additional data types, so we re-declare the types
// to enforce the type contraint that we need.
export type WebStream<T extends Data> = GenericWebStream<T>;
export type NodeWebStream<T extends Data> = GenericNodeWebStream<T>;
export type Stream<T extends Data> = WebStream<T> | NodeWebStream<T>;
export type MaybeStream<T extends Data> = T | Stream<T>;
type MaybeArray<T> = T | Array<T>;
/* ############## KEY #################### */
// The Key and PublicKey types can be used interchangably since TS cannot detect the difference, as they have the same class properties.
// The declared readKey(s) return type is Key instead of a PublicKey since it seems more obvious that a Key can be cast to a PrivateKey.
export function readKey(options: { armoredKey: string, config?: PartialConfig }): Promise<Key>;
export function readKey(options: { binaryKey: Uint8Array, config?: PartialConfig }): Promise<Key>;
export function readKeys(options: { armoredKeys: string, config?: PartialConfig }): Promise<Key[]>;
export function readKeys(options: { binaryKeys: Uint8Array, config?: PartialConfig }): Promise<Key[]>;
export function readPrivateKey(options: { armoredKey: string, config?: PartialConfig }): Promise<PrivateKey>;
export function readPrivateKey(options: { binaryKey: Uint8Array, config?: PartialConfig }): Promise<PrivateKey>;
export function readPrivateKeys(options: { armoredKeys: string, config?: PartialConfig }): Promise<PrivateKey[]>;
export function readPrivateKeys(options: { binaryKeys: Uint8Array, config?: PartialConfig }): Promise<PrivateKey[]>;
export function generateKey(options: GenerateKeyOptions & { format?: 'armored' }): Promise<SerializedKeyPair<string> & { revocationCertificate: string }>;
export function generateKey(options: GenerateKeyOptions & { format: 'binary' }): Promise<SerializedKeyPair<Uint8Array> & { revocationCertificate: string }>;
export function generateKey(options: GenerateKeyOptions & { format: 'object' }): Promise<KeyPair & { revocationCertificate: string }>;
export function decryptKey(options: { privateKey: PrivateKey; passphrase?: MaybeArray<string>; config?: PartialConfig }): Promise<PrivateKey>;
export function encryptKey(options: { privateKey: PrivateKey; passphrase?: MaybeArray<string>; config?: PartialConfig }): Promise<PrivateKey>;
export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format?: 'armored', config?: PartialConfig }): Promise<SerializedKeyPair<string> & { revocationCertificate: string }>;
export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array> & { revocationCertificate: string }>;
export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format: 'object', config?: PartialConfig }): Promise<KeyPair & { revocationCertificate: string }>;
export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format?: 'armored', config?: PartialConfig }): Promise<SerializedKeyPair<string>>;
export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array>>;
export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format: 'object', config?: PartialConfig }): Promise<KeyPair>;
export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format?: 'armored', config?: PartialConfig }): Promise<SerializedKeyPair<string>>;
export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array>>;
export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format: 'object', config?: PartialConfig }): Promise<KeyPair>;
export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format?: 'armored', config?: PartialConfig }): Promise<{ publicKey: string, privateKey: null }>;
export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format: 'binary', config?: PartialConfig }): Promise<{ publicKey: Uint8Array, privateKey: null }>;
export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format: 'object', config?: PartialConfig }): Promise<{ publicKey: PublicKey, privateKey: null }>;
export abstract class Key {
public readonly keyPacket: PublicKeyPacket | SecretKeyPacket;
public subkeys: Subkey[]; // do not add/replace users directly
public users: User[]; // do not add/replace subkeys directly
public revocationSignatures: SignaturePacket[];
public write(): Uint8Array;
public armor(config?: Config): string;
public getExpirationTime(userID?: UserID, config?: Config): Promise<Date | typeof Infinity | null>;
public getKeyIDs(): KeyID[];
public getPrimaryUser(date?: Date, userID?: UserID, config?: Config): Promise<PrimaryUser>; // throws on error
public getUserIDs(): string[];
public isPrivate(): this is PrivateKey;
public toPublic(): PublicKey;
// NB: the order of the `update` declarations matters, since PublicKey includes PrivateKey
public update(sourceKey: PrivateKey, date?: Date, config?: Config): Promise<PrivateKey>;
public update(sourceKey: PublicKey, date?: Date, config?: Config): Promise<PublicKey>;
public signPrimaryUser(privateKeys: PrivateKey[], date?: Date, userID?: UserID, config?: Config): Promise<this>;
public signAllUsers(privateKeys: PrivateKey[], date?: Date, config?: Config): Promise<this>;
public verifyPrimaryKey(date?: Date, userID?: UserID, config?: Config): Promise<void>; // throws on error
public verifyPrimaryUser(publicKeys: PublicKey[], date?: Date, userIDs?: UserID, config?: Config): Promise<{ keyID: KeyID, valid: boolean | null }[]>;
public verifyAllUsers(publicKeys?: PublicKey[], date?: Date, config?: Config): Promise<{ userID: string, keyID: KeyID, valid: boolean | null }[]>;
public isRevoked(signature?: SignaturePacket, key?: AnyKeyPacket, date?: Date, config?: Config): Promise<boolean>;
public getRevocationCertificate(date?: Date, config?: Config): Promise<MaybeStream<string> | undefined>;
public getEncryptionKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<this | Subkey>;
public getSigningKey(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<this | Subkey>;
public getKeys(keyID?: KeyID): (this | Subkey)[];
public getSubkeys(keyID?: KeyID): Subkey[];
public getFingerprint(): string;
public getCreationTime(): Date;
public getAlgorithmInfo(): AlgorithmInfo;
public getKeyID(): KeyID;
public toPacketList(): PacketList<AllowedKeyPackets>;
}
type AllowedKeyPackets = PublicKeyPacket | PublicSubkeyPacket | SecretKeyPacket | SecretSubkeyPacket | UserIDPacket | UserAttributePacket | SignaturePacket;
export class PublicKey extends Key {
constructor(packetlist: PacketList<AnyPacket>);
}
export class PrivateKey extends PublicKey {
constructor(packetlist: PacketList<AnyPacket>);
public revoke(reason?: ReasonForRevocation, date?: Date, config?: Config): Promise<PrivateKey>;
public isDecrypted(): boolean;
public addSubkey(options: SubkeyOptions): Promise<PrivateKey>;
public getDecryptionKeys(keyID?: KeyID, date?: Date | null, userID?: UserID, config?: Config): Promise<(PrivateKey | Subkey)[]>;
public update(sourceKey: PublicKey, date?: Date, config?: Config): Promise<PrivateKey>;
}
export class Subkey {
constructor(subkeyPacket: SecretSubkeyPacket | PublicSubkeyPacket, mainKey: PublicKey);
public readonly keyPacket: SecretSubkeyPacket | PublicSubkeyPacket;
public readonly mainKey: PublicKey;
public bindingSignatures: SignaturePacket[];
public revocationSignatures: SignaturePacket[];
public verify(date?: Date, config?: Config): Promise<SignaturePacket>;
public isDecrypted(): boolean;
public getFingerprint(): string;
public getCreationTime(): Date;
public getAlgorithmInfo(): AlgorithmInfo;
public getKeyID(): KeyID;
public getExpirationTime(date?: Date, config?: Config): Promise<Date | typeof Infinity | null>;
public isRevoked(signature: SignaturePacket, key: AnyKeyPacket, date?: Date, config?: Config): Promise<boolean>;
public update(subKey: Subkey, date?: Date, config?: Config): Promise<void>;
public revoke(primaryKey: SecretKeyPacket, reasonForRevocation?: ReasonForRevocation, date?: Date, config?: Config): Promise<Subkey>;
}
export interface User {
userID: UserIDPacket | null;
userAttribute: UserAttributePacket | null;
selfCertifications: SignaturePacket[];
otherCertifications: SignaturePacket[];
revocationSignatures: SignaturePacket[];
}
export interface PrimaryUser {
index: number;
user: User;
selfCertification: SignaturePacket;
}
export type AlgorithmInfo = {
algorithm: enums.publicKeyNames;
bits?: number;
curve?: EllipticCurveName;
};
/* ############## SIG #################### */
export function readSignature(options: { armoredSignature: string, config?: PartialConfig }): Promise<Signature>;
export function readSignature(options: { binarySignature: Uint8Array, config?: PartialConfig }): Promise<Signature>;
export class Signature {
public readonly packets: PacketList<SignaturePacket>;
constructor(packetlist: PacketList<SignaturePacket>);
public write(): MaybeStream<Uint8Array>;
public armor(config?: Config): string;
public getSigningKeyIDs(): Array<KeyID>;
}
interface VerificationResult {
keyID: KeyID;
verified: Promise<true>; // throws on invalid signature
signature: Promise<Signature>;
}
/* ############## CLEARTEXT #################### */
export function readCleartextMessage(options: { cleartextMessage: string, config?: PartialConfig }): Promise<CleartextMessage>;
export function createCleartextMessage(options: { text: string }): Promise<CleartextMessage>;
/** Class that represents an OpenPGP cleartext signed message.
*/
export class CleartextMessage {
/** Returns ASCII armored text of cleartext signed message
*/
armor(config?: Config): string;
/** Returns the key IDs of the keys that signed the cleartext message
*/
getSigningKeyIDs(): KeyID[];
/** Get cleartext
*/
getText(): string;
/** Sign the cleartext message
*
* @param privateKeys private keys with decrypted secret key data for signing
*/
sign(privateKeys: PrivateKey[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], notations?: RawNotation[], config?: Config): void;
/** Verify signatures of cleartext signed message
* @param keys array of keys to verify signatures
*/
verify(keys: PublicKey[], date?: Date, config?: Config): Promise<VerificationResult[]>;
}
/* ############## MSG #################### */
export function generateSessionKey(options: { encryptionKeys: MaybeArray<PublicKey>, date?: Date, encryptionUserIDs?: MaybeArray<UserID>, config?: PartialConfig }): Promise<SessionKey>;
export function encryptSessionKey(options: EncryptSessionKeyOptions & { format?: 'armored' }): Promise<string>;
export function encryptSessionKey(options: EncryptSessionKeyOptions & { format: 'binary' }): Promise<Uint8Array>;
export function encryptSessionKey(options: EncryptSessionKeyOptions & { format: 'object' }): Promise<Message<Data>>;
export function decryptSessionKeys<T extends MaybeStream<Data>>(options: { message: Message<T>, decryptionKeys?: MaybeArray<PrivateKey>, passwords?: MaybeArray<string>, date?: Date, config?: PartialConfig }): Promise<DecryptedSessionKey[]>;
export function readMessage<T extends MaybeStream<string>>(options: { armoredMessage: T, config?: PartialConfig }): Promise<Message<T>>;
export function readMessage<T extends MaybeStream<Uint8Array>>(options: { binaryMessage: T, config?: PartialConfig }): Promise<Message<T>>;
export function createMessage<T extends MaybeStream<string>>(options: { text: T, filename?: string, date?: Date, format?: enums.literalFormatNames }): Promise<Message<T>>;
export function createMessage<T extends MaybeStream<Uint8Array>>(options: { binary: T, filename?: string, date?: Date, format?: enums.literalFormatNames }): Promise<Message<T>>;
export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & { message: Message<T>, format?: 'armored' }): Promise<
T extends WebStream<Data> ? WebStream<string> :
T extends NodeWebStream<Data> ? NodeWebStream<string> :
string
>;
export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & { message: Message<T>, format: 'binary' }): Promise<
T extends WebStream<Data> ? WebStream<Uint8Array> :
T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
Uint8Array
>;
export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & { message: Message<T>, format: 'object' }): Promise<Message<T>>;
export function sign<T extends MaybeStream<Data>>(options: SignOptions & { message: Message<T>, format?: 'armored' }): Promise<
T extends WebStream<Data> ? WebStream<string> :
T extends NodeWebStream<Data> ? NodeWebStream<string> :
string
>;
export function sign<T extends MaybeStream<Data>>(options: SignOptions & { message: Message<T>, format: 'binary' }): Promise<
T extends WebStream<Data> ? WebStream<Uint8Array> :
T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
Uint8Array
>;
export function sign<T extends MaybeStream<Data>>(options: SignOptions & { message: Message<T>, format: 'object' }): Promise<Message<T>>;
export function sign(options: SignOptions & { message: CleartextMessage, format?: 'armored' }): Promise<string>;
export function sign(options: SignOptions & { message: CleartextMessage, format: 'object' }): Promise<CleartextMessage>;
export function decrypt<T extends MaybeStream<Data>>(options: DecryptOptions & { message: Message<T>, format: 'binary' }): Promise<DecryptMessageResult & {
data:
T extends WebStream<Data> ? WebStream<Uint8Array> :
T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
Uint8Array
}>;
export function decrypt<T extends MaybeStream<Data>>(options: DecryptOptions & { message: Message<T> }): Promise<DecryptMessageResult & {
data:
T extends WebStream<Data> ? WebStream<string> :
T extends NodeWebStream<Data> ? NodeWebStream<string> :
string
}>;
export function verify(options: VerifyOptions & { message: CleartextMessage, format?: 'utf8' }): Promise<VerifyMessageResult<string>>;
export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T>, format: 'binary' }): Promise<VerifyMessageResult<
T extends WebStream<Data> ? WebStream<Uint8Array> :
T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
Uint8Array
>>;
export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T> }): Promise<VerifyMessageResult<
T extends WebStream<Data> ? WebStream<string> :
T extends NodeWebStream<Data> ? NodeWebStream<string> :
string
>>;
/** Class that represents an OpenPGP message. Can be an encrypted message, signed message, compressed message or literal message
*/
export class Message<T extends MaybeStream<Data>> {
public readonly packets: PacketList<AnyPacket>;
constructor(packetlist: PacketList<AnyPacket>);
/** Returns binary representation of message
*/
public write(): MaybeStream<Uint8Array>;
/** Returns ASCII armored text of message
*/
public armor(config?: Config): string;
/** Decrypt the message
@param decryptionKeys array of private keys with decrypted secret data
*/
public decrypt(decryptionKeys?: PrivateKey[], passwords?: string[], sessionKeys?: SessionKey[], date?: Date, config?: Config): Promise<Message<MaybeStream<Data>>>;
/** Encrypt the message
@param encryptionKeys array of public keys, used to encrypt the message
*/
public encrypt(encryptionKeys?: PublicKey[], passwords?: string[], sessionKeys?: SessionKey[], wildcard?: boolean, encryptionKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], config?: Config): Promise<Message<MaybeStream<Data>>>;
/** Returns the key IDs of the keys to which the session key is encrypted
*/
public getEncryptionKeyIDs(): KeyID[];
/** Get literal data that is the body of the message
*/
public getLiteralData(): (T extends Stream<Data> ? WebStream<Uint8Array> : Uint8Array) | null;
/** Returns the key IDs of the keys that signed the message
*/
public getSigningKeyIDs(): KeyID[];
/** Get literal data as text
*/
public getText(): (T extends Stream<Data> ? WebStream<string> : string) | null;
public getFilename(): string | null;
/** Sign the message (the literal data packet of the message)
@param signingKeys private keys with decrypted secret key data for signing
*/
public sign(signingKeys: PrivateKey[], signature?: Signature, signingKeyIDs?: KeyID[], date?: Date, userIDs?: UserID[], notations?: RawNotation[], config?: Config): Promise<Message<T>>;
/** Unwrap compressed message
*/
public unwrapCompressed(): Message<T>;
/** Verify message signatures
@param verificationKeys array of public keys to verify signatures
*/
public verify(verificationKeys: PublicKey[], date?: Date, config?: Config): Promise<VerificationResult[]>;
/**
* Append signature to unencrypted message object
* @param {String|Uint8Array} detachedSignature - The detached ASCII-armored or Uint8Array PGP signature
*/
public appendSignature(detachedSignature: string | Uint8Array, config?: Config): Promise<void>;
}
/* ############## CONFIG #################### */
interface Config {
preferredHashAlgorithm: enums.hash;
preferredSymmetricAlgorithm: enums.symmetric;
preferredCompressionAlgorithm: enums.compression;
showVersion: boolean;
showComment: boolean;
aeadProtect: boolean;
ignoreSEIPDv2FeatureFlag: boolean;
allowUnauthenticatedMessages: boolean;
allowUnauthenticatedStream: boolean;
allowForwardedMessages: boolean;
minRSABits: number;
passwordCollisionCheck: boolean;
ignoreUnsupportedPackets: boolean;
ignoreMalformedPackets: boolean;
versionString: string;
commentString: string;
allowInsecureDecryptionWithSigningKeys: boolean;
allowInsecureVerificationWithReformattedKeys: boolean;
allowMissingKeyFlags: boolean;
constantTimePKCS1Decryption: boolean;
constantTimePKCS1DecryptionSupportedSymmetricAlgorithms: Set<enums.symmetric>;
v6Keys: boolean;
enableParsingV5Entities: boolean;
preferredAEADAlgorithm: enums.aead;
aeadChunkSizeByte: number;
s2kType: enums.s2k.iterated | enums.s2k.argon2;
s2kIterationCountByte: number;
s2kArgon2Params: { passes: number, parallelism: number; memoryExponent: number; };
maxUserIDLength: number;
knownNotations: string[];
useEllipticFallback: boolean;
rejectHashAlgorithms: Set<enums.hash>;
rejectMessageHashAlgorithms: Set<enums.hash>;
rejectPublicKeyAlgorithms: Set<enums.publicKey>;
rejectCurves: Set<enums.curve>;
}
export const config: Config;
// PartialConfig has the same properties as Config, but declared as optional.
// This interface is relevant for top-level functions, which accept a subset of configuration options
export interface PartialConfig extends Partial<Config> {}
/* ############## PACKET #################### */
export declare abstract class BasePacket {
static readonly tag: enums.packet;
public read(bytes: Uint8Array): void;
public write(): Uint8Array;
}
/**
* The relationship between the KeyPacket classes is modeled by considering the following:
* - A Secret (Sub)Key Packet can always be used when a Public one is expected.
* - A Subkey Packet cannot always be used when a Primary Key Packet is expected (and vice versa).
*/
declare abstract class BasePublicKeyPacket extends BasePacket {
public algorithm: enums.publicKey;
public created: Date;
public version: number;
public getAlgorithmInfo(): AlgorithmInfo;
public getFingerprint(): string;
public getFingerprintBytes(): Uint8Array | null;
public hasSameFingerprintAs(other: BasePublicKeyPacket): boolean;
public getCreationTime(): Date;
public getKeyID(): KeyID;
public isDecrypted(): boolean;
public publicParams: object;
// `isSubkey` is a dummy method to ensure that Subkey packets are not accepted as Key one, and vice versa.
// The key class hierarchy is already modelled to cover this, but the concrete key packet classes
// have compatible structure and TS can't detect the difference.
protected isSubkey(): boolean;
}
export class PublicKeyPacket extends BasePublicKeyPacket {
static readonly tag: enums.packet.publicKey;
protected isSubkey(): false;
}
export class PublicSubkeyPacket extends BasePublicKeyPacket {
static readonly tag: enums.packet.publicSubkey;
protected isSubkey(): true;
}
declare abstract class BaseSecretKeyPacket extends BasePublicKeyPacket {
public privateParams: object | null;
public encrypt(passphrase: string, config?: Config): Promise<void>; // throws on error
public decrypt(passphrase: string): Promise<void>; // throws on error
public validate(): Promise<void>; // throws on error
public isDummy(): boolean;
public isMissingSecretKeyMaterial(): boolean;
public makeDummy(config?: Config): void;
}
export class SecretKeyPacket extends BaseSecretKeyPacket {
static readonly tag: enums.packet.secretKey;
protected isSubkey(): false;
}
export class SecretSubkeyPacket extends BaseSecretKeyPacket {
static readonly tag: enums.packet.secretSubkey;
protected isSubkey(): true;
}
export class CompressedDataPacket extends BasePacket {
static readonly tag: enums.packet.compressedData;
private compress(): void;
private decompress(config?: Config): void;
}
export class SymEncryptedIntegrityProtectedDataPacket extends BasePacket {
static readonly tag: enums.packet.symEncryptedIntegrityProtectedData;
}
export class AEADEncryptedDataPacket extends BasePacket {
static readonly tag: enums.packet.aeadEncryptedData;
private decrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
private encrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
private crypt(fn: Function, sessionKey: Uint8Array, data: MaybeStream<Uint8Array>): MaybeStream<Uint8Array>;
}
export class PublicKeyEncryptedSessionKeyPacket extends BasePacket {
static readonly tag: enums.packet.publicKeyEncryptedSessionKey;
private decrypt(keyPacket: SecretKeyPacket): void; // throws on error
private encrypt(keyPacket: PublicKeyPacket): void; // throws on error
}
export class SymEncryptedSessionKeyPacket extends BasePacket {
static readonly tag: enums.packet.symEncryptedSessionKey;
private decrypt(passphrase: string): Promise<void>;
private encrypt(passphrase: string, config?: Config): Promise<void>;
}
export class LiteralDataPacket extends BasePacket {
static readonly tag: enums.packet.literalData;
private getText(clone?: boolean): MaybeStream<string>;
private getBytes(clone?: boolean): MaybeStream<Uint8Array>;
private setText(text: MaybeStream<string>, format?: enums.literal);
private setBytes(bytes: MaybeStream<Uint8Array>, format: enums.literal);
private setFilename(filename: string);
private getFilename(): string;
private writeHeader(): Uint8Array;
}
export class SymmetricallyEncryptedDataPacket extends BasePacket {
static readonly tag: enums.packet.symmetricallyEncryptedData;
private decrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
private encrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
}
export class MarkerPacket extends BasePacket {
static readonly tag: enums.packet.marker;
}
export class UserAttributePacket extends BasePacket {
static readonly tag: enums.packet.userAttribute;
private equals(packet: UserAttributePacket): boolean;
}
export class OnePassSignaturePacket extends BasePacket {
static readonly tag: enums.packet.onePassSignature;
public correspondingSig?: Promise<SignaturePacket>;
private verify: SignaturePacket['verify'];
}
export class UserIDPacket extends BasePacket {
static readonly tag: enums.packet.userID;
public readonly name: string;
public readonly comment: string;
public readonly email: string;
public readonly userID: string;
static fromObject(userID: UserID): UserIDPacket;
}
export class SignaturePacket extends BasePacket {
static readonly tag: enums.packet.signature;
public version: number;
public signatureType: enums.signature | null;
public hashAlgorithm: enums.hash | null;
public publicKeyAlgorithm: enums.publicKey | null;
public signatureData: null | Uint8Array;
public unhashedSubpackets: RawSubpacket[];
public unknownSubpackets: RawSubpacket[];
public signedHashValue: null | Uint8Array;
public created: Date | null;
public signatureExpirationTime: null | number;
public signatureNeverExpires: boolean;
public exportable: null | boolean;
public trustLevel: null | number;
public trustAmount: null | number;
public regularExpression: null | number;
public revocable: null | boolean;
public keyExpirationTime: null | number;
public keyNeverExpires: null | boolean;
public preferredSymmetricAlgorithms: enums.symmetric[] | null;
public revocationKeyClass: null | number;
public revocationKeyAlgorithm: null | enums.publicKey;
public revocationKeyFingerprint: null | Uint8Array;
public issuerKeyID: KeyID;
public notation: null | { [name: string]: string };
public preferredHashAlgorithms: enums.hash[] | null;
public preferredCompressionAlgorithms: enums.compression[] | null;
public keyServerPreferences: null | number[];
public preferredKeyServer: null | string;
public isPrimaryUserID: null | boolean;
public policyURI: null | string;
public keyFlags: Uint8Array | null;
public signersUserID: null | string;
public reasonForRevocationFlag: null | enums.reasonForRevocation;
public reasonForRevocationString: null | string;
public features: Uint8Array | null;
public signatureTargetPublicKeyAlgorithm: enums.publicKey | null;
public signatureTargetHashAlgorithm: enums.hash | null;
public signatureTargetHash: null | string;
public embeddedSignature: null | SignaturePacket;
public issuerKeyVersion: null | number;
public issuerFingerprint: null | Uint8Array;
public preferredAEADAlgorithms: enums.aead[] | null;
public revoked: null | boolean;
public rawNotations: RawNotation[];
public sign(key: AnySecretKeyPacket, data: Uint8Array, date?: Date, detached?: boolean): Promise<void>;
public verify(key: AnyKeyPacket, signatureType: enums.signature, data: Uint8Array | object, date?: Date, detached?: boolean, config?: Config): Promise<void>; // throws on error
public isExpired(date?: Date): boolean;
public getExpirationTime(): Date | typeof Infinity;
}
export interface RawSubpacket {
type: number;
critical: boolean;
body: Uint8Array;
}
export interface RawNotation {
name: string;
value: Uint8Array;
humanReadable: boolean;
critical: boolean;
}
export class TrustPacket extends BasePacket {
static readonly tag: enums.packet.trust;
}
export class UnparseablePacket {
tag: enums.packet;
write: () => Uint8Array;
}
export type AnyPacket = BasePacket | UnparseablePacket;
export type AnySecretKeyPacket = SecretKeyPacket | SecretSubkeyPacket;
export type AnyKeyPacket = BasePublicKeyPacket;
type AllowedPackets = Map<enums.packet, object>; // mapping to Packet classes (i.e. typeof LiteralDataPacket etc.)
export class PacketList<T extends AnyPacket> extends Array<T> {
static fromBinary(bytes: MaybeStream<Uint8Array>, allowedPackets: AllowedPackets, config?: Config): PacketList<AnyPacket>; // the packet types depend on`allowedPackets`
public read(bytes: MaybeStream<Uint8Array>, allowedPackets: AllowedPackets, config?: Config): void;
public write(): Uint8Array;
public filterByTag(...args: enums.packet[]): PacketList<T>;
public indexOfTag(...tags: enums.packet[]): number[];
public findPacket(tag: enums.packet): T | undefined;
}
/* ############## GENERAL #################### */
export interface UserID { name?: string; email?: string; comment?: string; }
export interface SessionKey {
data: Uint8Array;
algorithm: enums.symmetricNames;
aeadAlgorithm?: enums.aeadNames;
}
export interface DecryptedSessionKey {
data: Uint8Array;
algorithm: enums.symmetricNames | null; // `null` if the session key is associated with a SEIPDv2 packet
}
export interface ReasonForRevocation { flag?: enums.reasonForRevocation, string?: string }
export interface EncryptOptions {
/** message to be encrypted as created by createMessage */
message: Message<MaybeStream<Data>>;
/** (optional) array of keys or single key, used to encrypt the message */
encryptionKeys?: MaybeArray<PublicKey>;
/** (optional) private keys for signing. If omitted message will not be signed */
signingKeys?: MaybeArray<PrivateKey>;
/** (optional) array of passwords or a single password to encrypt the message */
passwords?: MaybeArray<string>;
/** (optional) session key */
sessionKey?: SessionKey;
/** if the return values should be ascii armored or the message/signature objects */
format?: 'armored' | 'binary' | 'object';
/** (optional) if the signature should be detached (if true, signature will be added to returned object) */
signature?: Signature;
/** (optional) encrypt as of a certain date */
date?: Date;
/** (optional) use a key ID of 0 instead of the public key IDs */
wildcard?: boolean;
/** (optional) Array of key IDs to use for signing. Each `signingKeyIDs[i]` corresponds to `signingKeys[i]` */
signingKeyIDs?: MaybeArray<KeyID>;
/** (optional) Array of key IDs to use for encryption. Each `encryptionKeyIDs[i]` corresponds to `encryptionKeys[i]`*/
encryptionKeyIDs?: MaybeArray<KeyID>;
/** (optional) Array of user IDs to sign with, e.g. { name:'Steve Sender', email:'[email protected]' } */
signingUserIDs?: MaybeArray<UserID>;
/** (optional) array of user IDs to encrypt for, e.g. { name:'Robert Receiver', email:'[email protected]' } */
encryptionUserIDs?: MaybeArray<UserID>;
/** (optional) array of notations to add to the signatures, e.g. { name: '[email protected]', value: new TextEncoder().encode('test'), humanReadable: true, critical: false } */
signatureNotations?: MaybeArray<RawNotation>;
config?: PartialConfig;
}
export interface DecryptOptions {
/** the message object with the encrypted data */
message: Message<MaybeStream<Data>>;
/** (optional) private keys with decrypted secret key data or session key */
decryptionKeys?: MaybeArray<PrivateKey>;
/** (optional) passwords to decrypt the message */
passwords?: MaybeArray<string>;
/** (optional) session keys in the form: { data:Uint8Array, algorithm:String } */
sessionKeys?: MaybeArray<SessionKey>;
/** (optional) array of public keys or single key, to verify signatures */
verificationKeys?: MaybeArray<PublicKey>;
/** (optional) whether data decryption should fail if the message is not signed with the provided publicKeys */
expectSigned?: boolean;
/** (optional) whether to return data as a string(Stream) or Uint8Array(Stream). If 'utf8' (the default), also normalize newlines. */
format?: 'utf8' | 'binary';
/** (optional) detached signature for verification */
signature?: Signature;
/** (optional) use the given date for verification instead of the current time */
date?: Date;
config?: PartialConfig;
}
export interface SignOptions {
message: CleartextMessage | Message<MaybeStream<Data>>;
signingKeys: MaybeArray<PrivateKey>;
format?: 'armored' | 'binary' | 'object';
detached?: boolean;
signingKeyIDs?: MaybeArray<KeyID>;
date?: Date;
signingUserIDs?: MaybeArray<UserID>;
signatureNotations?: MaybeArray<RawNotation>;
config?: PartialConfig;
}
export interface VerifyOptions {
/** (cleartext) message object with signatures */
message: CleartextMessage | Message<MaybeStream<Data>>;
/** array of publicKeys or single key, to verify signatures */
verificationKeys: MaybeArray<PublicKey>;
/** (optional) whether verification should throw if the message is not signed with the provided publicKeys */
expectSigned?: boolean;
/** (optional) whether to return data as a string(Stream) or Uint8Array(Stream). If 'utf8' (the default), also normalize newlines. */
format?: 'utf8' | 'binary';
/** (optional) detached signature for verification */
signature?: Signature;
/** (optional) use the given date for verification instead of the current time */
date?: Date | null;
config?: PartialConfig;
}
export interface EncryptSessionKeyOptions extends SessionKey {
encryptionKeys?: MaybeArray<PublicKey>,
passwords?: MaybeArray<string>,
format?: 'armored' | 'binary' | 'object',
date?: Date,
wildcard?: boolean,
encryptionKeyIDs?: MaybeArray<KeyID>,
encryptionUserIDs?: MaybeArray<UserID>,
config?: PartialConfig
}
interface SerializedKeyPair<T extends string | Uint8Array> {
privateKey: T;
publicKey: T;
}
interface KeyPair {
privateKey: PrivateKey;
publicKey: PublicKey;
}
export type EllipticCurveName = 'ed25519Legacy' | 'curve25519Legacy' | 'nistP256' | 'nistP384' | 'nistP521' | 'secp256k1' | 'brainpoolP256r1' | 'brainpoolP384r1' | 'brainpoolP512r1';
interface GenerateKeyOptions {
userIDs: MaybeArray<UserID>;
passphrase?: string;
type?: 'ecc' | 'rsa' | 'curve25519' | 'curve448' | 'pqc';
curve?: EllipticCurveName;
rsaBits?: number;
keyExpirationTime?: number;
date?: Date;
subkeys?: SubkeyOptions[];
format?: 'armored' | 'object' | 'binary';
config?: PartialConfig;
}
export type KeyOptions = GenerateKeyOptions;
export interface SubkeyOptions extends Pick<GenerateKeyOptions, 'type' | 'curve' | 'rsaBits' | 'keyExpirationTime' | 'date' | 'config' > {
sign?: boolean;
forwarding?: boolean;
}
export declare class KeyID {
bytes: string;
equals(keyID: KeyID, matchWildcard?: boolean): boolean;
toHex(): string;
static fromID(hex: string): KeyID;
}
export interface DecryptMessageResult {
data: MaybeStream<Data>;
signatures: VerificationResult[];
filename: string;
}
export interface VerifyMessageResult<T extends MaybeStream<Data> = MaybeStream<Data>> {
data: T;
signatures: VerificationResult[];
}
/**
* Armor an OpenPGP binary packet block
*/
export function armor(messagetype: enums.armor, body: object, partindex?: number, parttotal?: number, customComment?: string, emitChecksum?: boolean, config?: Config): string;
/**
* DeArmor an OpenPGP armored message; verify the checksum and return the encoded bytes
*/
export function unarmor(input: string, config?: Config): Promise<{ text: string, data: Stream<Uint8Array>, type: enums.armor }>;
/* ############## v5 ENUMS #################### */
export namespace enums {
export function read(type: typeof armor, e: armor): armorNames;
export function read(type: typeof compression, e: compression): compressionNames;
export function read(type: typeof hash, e: hash): hashNames;
export function read(type: typeof packet, e: packet): packetNames;
export function read(type: typeof publicKey, e: publicKey): publicKeyNames;
export function read(type: typeof symmetric, e: symmetric): symmetricNames;
export function read(type: typeof keyStatus, e: keyStatus): keyStatusNames;
export function read(type: typeof keyFlags, e: keyFlags): keyFlagsNames;
export type armorNames = 'multipartSection' | 'multipartLast' | 'signed' | 'message' | 'publicKey' | 'privateKey';
export enum armor {
multipartSection = 0,
multipartLast = 1,
signed = 2,
message = 3,
publicKey = 4,
privateKey = 5,
signature = 6
}
export enum reasonForRevocation {
noReason = 0, // No reason specified (key revocations or cert revocations)
keySuperseded = 1, // Key is superseded (key revocations)
keyCompromised = 2, // Key material has been compromised (key revocations)
keyRetired = 3, // Key is retired and no longer used (key revocations)
userIDInvalid = 32 // User ID information is no longer valid (cert revocations)
}
export type compressionNames = 'uncompressed' | 'zip' | 'zlib' | 'bzip2';
export enum compression {
uncompressed = 0,
zip = 1,
zlib = 2,
bzip2 = 3
}
export type hashNames = 'md5' | 'sha1' | 'ripemd' | 'sha256' | 'sha384' | 'sha512' | 'sha224' | 'sha3_256' | 'sha3_512';
export enum hash {
md5 = 1,
sha1 = 2,
ripemd = 3,
sha256 = 8,
sha384 = 9,
sha512 = 10,
sha224 = 11,
sha3_256 = 12,
sha3_512 = 14
}
export type packetNames = 'publicKeyEncryptedSessionKey' | 'signature' | 'symEncryptedSessionKey' | 'onePassSignature' | 'secretKey' | 'publicKey' |
'secretSubkey' | 'compressed' | 'symmetricallyEncrypted' | 'marker' | 'literal' | 'trust' | 'userID' | 'publicSubkey' | 'userAttribute' |
'symEncryptedIntegrityProtected' | 'modificationDetectionCode' | 'AEADEncryptedDataPacket';
export enum packet {
publicKeyEncryptedSessionKey = 1,
signature = 2,
symEncryptedSessionKey = 3,
onePassSignature = 4,
secretKey = 5,
publicKey = 6,
secretSubkey = 7,
compressedData = 8,
symmetricallyEncryptedData = 9,
marker = 10,
literalData = 11,
trust = 12,
userID = 13,
publicSubkey = 14,
userAttribute = 17,
symEncryptedIntegrityProtectedData = 18,
modificationDetectionCode = 19,
aeadEncryptedData = 20
}
export type publicKeyNames = 'rsaEncryptSign' | 'rsaEncrypt' | 'rsaSign' | 'elgamal' | 'dsa' | 'ecdh' | 'ecdsa' | 'eddsaLegacy' | 'aedh' | 'aedsa' | 'ed25519' | 'x25519' | 'ed448' | 'x448' | 'pqc_mlkem_x25519' | 'pqc_mldsa_ed25519';
export enum publicKey {
rsaEncryptSign = 1,
rsaEncrypt = 2,
rsaSign = 3,
elgamal = 16,
dsa = 17,
ecdh = 18,
ecdsa = 19,
eddsaLegacy = 22,
aedh = 23,
aedsa = 24,
x25519 = 25,
x448 = 26,
ed25519 = 27,
ed448 = 28,
pqc_mlkem_x25519 = 105,
pqc_mldsa_ed25519 = 107
}
export enum curve {
/** @deprecated use `nistP256` instead */
p256 = 'nistP256',
nistP256 = 'nistP256',
/** @deprecated use `nistP384` instead */
p384 = 'nistP384',
nistP384 = 'nistP384',
/** @deprecated use `nistP521` instead */
p521 = 'nistP521',
nistP521 = 'nistP521',
/** @deprecated use `ed25519Legacy` instead */
ed25519 = 'ed25519Legacy',
ed25519Legacy = 'ed25519Legacy',
/** @deprecated use `curve25519Legacy` instead */
curve25519 = 'curve25519Legacy',
curve25519Legacy = 'curve25519Legacy',
secp256k1 = 'secp256k1',
brainpoolP256r1 = 'brainpoolP256r1',
brainpoolP384r1 = 'brainpoolP384r1',
brainpoolP512r1 = 'brainpoolP512r1'
}
export type symmetricNames = 'idea' | 'tripledes' | 'cast5' | 'blowfish' | 'aes128' | 'aes192' | 'aes256' | 'twofish';
export enum symmetric {
idea = 1,
tripledes = 2,
cast5 = 3,
blowfish = 4,
aes128 = 7,
aes192 = 8,
aes256 = 9,
twofish = 10
}
export type keyStatusNames = 'invalid' | 'expired' | 'revoked' | 'valid' | 'noSelfCert';
export enum keyStatus {
invalid = 0,
expired = 1,
revoked = 2,
valid = 3,
noSelfCert = 4
}
export type keyFlagsNames = 'certifyKeys' | 'signData' | 'encryptCommunication' | 'encryptStorage' | 'splitPrivateKey' | 'authentication' | 'sharedPrivateKey';
export enum keyFlags {
certifyKeys = 1,
signData = 2,
encryptCommunication = 4,
encryptStorage = 8,
splitPrivateKey = 16,
authentication = 32,
forwardedCommunication = 64,
sharedPrivateKey = 128
}
export enum signature {
binary = 0,
text = 1,
standalone = 2,
certGeneric = 16,
certPersona = 17,
certCasual = 18,
certPositive = 19,
certRevocation = 48,
subkeyBinding = 24,
keyBinding = 25,
key = 31,
keyRevocation = 32,
subkeyRevocation = 40,
timestamp = 64,
thirdParty = 80
}
export type aeadNames = 'eax' | 'ocb' | 'gcm';
export enum aead {
eax = 1,
ocb = 2,
experimentalGCM = 100 // Private algorithm
}
export type literalFormatNames = 'utf8' | 'binary' | 'text' | 'mime';
export enum literal {
binary = 98,
text = 116,
utf8 = 117,
mime = 109
}
export enum s2k {
simple = 0,
salted = 1,
iterated = 3,
argon2 = 4,
gnu = 101
}
}
export declare class Argon2S2K {
static reloadWasmModule(): void;
static ARGON2_WASM_MEMORY_THRESHOLD_RELOAD: number;
constructor(config: Config);
salt: Uint8Array;
/** @throws Argon2OutOfMemoryError */
produceKey(passphrase: string, keySize: number): Promise<Uint8Array>;
}
interface KDFParamsData {
version: number;
hash: enums.hash;
cipher: enums.symmetric;
replacementFingerprint?: Uint8Array;
}
export class KDFParams {
constructor(data: KDFParamsData);
write(forReplacementParams?: boolean): Uint8Array;
}