forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openpgp.d.ts
590 lines (483 loc) · 19.5 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
// Type definitions for openpgpjs
// Project: http://openpgpjs.org/
// Definitions by: Guillaume Lacasa <https://blog.lacasa.fr>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../es6-promise/es6-promise.d.ts" />
declare module openpgp {
interface KeyPair {
key: key.Key,
privateKeyArmored: string,
publicKeyArmored: string
}
interface KeyOptions {
keyType?: enums.publicKey,
numBits: number,
userId: string,
passphrase: string,
unlocked?: boolean
}
interface Keyid {
bytes: string,
}
interface Signature {
keyid: Keyid,
valid: boolean
}
interface VerifiedMessage {
text: string,
signatures: Array<Signature>
}
/** Decrypts message and verifies signatures
@param privateKey private key with decrypted secret key data
@param publicKeys array of keys to verify signatures
@param msg the message object with signed and encrypted data
*/
function decryptAndVerifyMessage(privateKey: key.Key, publicKeys: Array<key.Key>, msg: string): Promise<VerifiedMessage>;
/** Decrypts message and verifies signatures
@param privateKey private key with decrypted secret key data
@param publicKey single key to verify signatures
@param msg the message object with signed and encrypted data
*/
function decryptAndVerifyMessage(privateKey: key.Key, publicKey: key.Key, msg: string): Promise<VerifiedMessage>;
/** Decrypts message
@param privateKey private key with decrypted secret key data
@param msg the message object with the encrypted data
*/
function decryptMessage(privateKey: key.Key, msg: message.Message): Promise<string>;
/** Encrypts message text with keys
@param keys array of keys used to encrypt the message
@param text message as native JavaScript string
@returns encrypted ASCII armored message
*/
function encryptMessage(keys: Array<key.Key>, message: string): Promise<string>;
/** Encrypts message text with keys
@param single key used to encrypt the message
@param text message as native JavaScript string
*/
function encryptMessage(key: key.Key, message: string): Promise<string>;
/** Generates a new OpenPGP key pair. Currently only supports RSA keys. Primary and subkey will be of same type.
@param options
*/
function generateKeyPair(options: KeyOptions): Promise<KeyPair>;
/** Signs message text and encrypts it
@param publicKeys array of keys used to encrypt the message
@param privateKey private key with decrypted secret key data for signing
@param text private key with decrypted secret key data for signing
*/
function signAndEncryptMessage(publicKeys: Array<key.Key>, privateKey: key.Key, text: string): Promise<string>;
/** Signs message text and encrypts it
@param publicKeys single key used to encrypt the message
@param privateKey private key with decrypted secret key data for signing
@param text private key with decrypted secret key data for signing
*/
function signAndEncryptMessage(publicKey: key.Key, privateKey: key.Key, text: string): Promise<string>;
/** Signs a cleartext message
@param privateKeys array of keys with decrypted secret key data to sign cleartext
@param text cleartext
*/
function signClearMessage(privateKeys: Array<key.Key>, text: string): Promise<string>;
/** Signs a cleartext message
@param privateKeys single key with decrypted secret key data to sign cleartext
@param text cleartext
*/
function signClearMessage(privateKey: key.Key, text: string): Promise<string>;
/** Verifies signatures of cleartext signed message
@param publicKeys array of keys to verify signatures
@param msg cleartext message object with signatures
*/
function verifyClearSignedMessage(publicKeys: Array<key.Key>, msg: cleartext.CleartextMessage): Promise<VerifiedMessage>;
/** Verifies signatures of cleartext signed message
@param publicKeys single key to verify signatures
@param msg cleartext message object with signatures
*/
function verifyClearSignedMessage(publicKey: key.Key, msg: cleartext.CleartextMessage): Promise<VerifiedMessage>;
}
declare module openpgp.armor {
/** Armor an OpenPGP binary packet block
@param messagetype type of the message
@param body
@param partindex
@param parttotal
*/
function armor(messagetype: enums.armor, body: Object, partindex: number, parttotal: number): string;
/** DeArmor an OpenPGP armored message; verify the checksum and return the encoded bytes
@param text OpenPGP armored message
*/
function dearmor(text: string): Object;
}
declare module openpgp.cleartext {
/** Class that represents an OpenPGP cleartext signed message.
*/
interface CleartextMessage {
/** Returns ASCII armored text of cleartext signed message
*/
armor(): string;
/** Returns the key IDs of the keys that signed the cleartext message
*/
getSigningKeyIds(): Array<Keyid>;
/** Get cleartext
*/
getText(): string;
/** Sign the cleartext message
@param privateKeys private keys with decrypted secret key data for signing
*/
sign(privateKeys: Array<key.Key>): void;
/** Verify signatures of cleartext signed message
@param keys array of keys to verify signatures
*/
verify(keys: Array<key.Key>): Array<VerifiedMessage>;
}
function readArmored(armoredText: string): CleartextMessage;
}
declare module openpgp.config {
var prefer_hash_algorithm: enums.hash;
var encryption_cipher: enums.symmetric;
var compression: enums.compression;
var show_version: boolean;
var show_comment: boolean;
var integrity_protect: boolean;
var keyserver: string;
var debug: boolean;
}
declare module openpgp.crypto {
interface Mpi {
data: number,
read(input: string): number,
write(): string,
}
/** Generating a session key for the specified symmetric algorithm
@param algo Algorithm to use
*/
function generateSessionKey(algo: enums.symmetric): string;
/** generate random byte prefix as string for the specified algorithm
@param algo Algorithm to use
*/
function getPrefixRandom(algo: enums.symmetric): string;
/** Returns the number of integers comprising the private key of an algorithm
@param algo The public key algorithm
*/
function getPrivateMpiCount(algo: enums.symmetric): number;
/** Decrypts data using the specified public key multiprecision integers of the private key, the specified secretMPIs of the private key and the specified algorithm.
@param algo Algorithm to be used
@param publicMPIs Algorithm dependent multiprecision integers of the public key part of the private key
@param secretMPIs Algorithm dependent multiprecision integers of the private key used
@param data Data to be encrypted as MPI
*/
function publicKeyDecrypt(algo: enums.publicKey, publicMPIs: Array<Mpi>, secretMPIs: Array<Mpi>, data: Mpi): Mpi;
/** Encrypts data using the specified public key multiprecision integers and the specified algorithm.
@param algo Algorithm to be used
@param publicMPIs Algorithm dependent multiprecision integers
@param data Data to be encrypted as MPI
*/
function publicKeyEncrypt(algo: enums.publicKey, publicMPIs: Array<Mpi>, data: Mpi): Array<Mpi>;
}
declare module openpgp.crypto.cfb {
/** This function decrypts a given plaintext using the specified blockcipher to decrypt a message
@param cipherfn the algorithm cipher class to decrypt data in one block_size encryption
@param key binary string representation of key to be used to decrypt the ciphertext. This will be passed to the cipherfn
@param ciphertext to be decrypted provided as a string
@param resync a boolean value specifying if a resync of the IV should be used or not. The encrypteddatapacket uses the "old" style with a resync. Decryption within an encryptedintegrityprotecteddata packet is not resyncing the IV.
*/
function decrypt(cipherfn: string, key: string, ciphertext: string, resync: boolean): string;
/** This function encrypts a given with the specified prefixrandom using the specified blockcipher to encrypt a message
@param prefixrandom random bytes of block_size length provided as a string to be used in prefixing the data
@param cipherfn the algorithm cipher class to encrypt data in one block_size encryption
@param plaintext data to be encrypted provided as a string
@param key binary string representation of key to be used to encrypt the plaintext. This will be passed to the cipherfn
@param resync a boolean value specifying if a resync of the IV should be used or not. The encrypteddatapacket uses the "old" style with a resync. Encryption within an encryptedintegrityprotecteddata packet is not resyncing the IV.
*/
function encrypt(prefixrandom: string, cipherfn: string, plaintext: string, key: string, resync: boolean): string;
/** Decrypts the prefixed data for the Modification Detection Code (MDC) computation
@param cipherfn cipherfn.encrypt Cipher function to use
@param key binary string representation of key to be used to check the mdc This will be passed to the cipherfn
@param ciphertext The encrypted data
*/
function mdc(cipherfn: Object, key: string, ciphertext: string): string;
}
declare module openpgp.crypto.hash {
/** Create a hash on the specified data using the specified algorithm
@param algo Hash algorithm type
@param data Data to be hashed
*/
function digest(algo: enums.hash, data: string): string;
/** Returns the hash size in bytes of the specified hash algorithm type
@param algo Hash algorithm type
*/
function getHashByteLength(algo: enums.hash): number;
}
declare module openpgp.crypto.random {
/** Create a secure random big integer of bits length
@param bits Bit length of the MPI to create
*/
function getRandomBigInteger(bits: number): number;
/** Retrieve secure random byte string of the specified length
@param length Length in bytes to generate
*/
function getRandomBytes(length: number): string;
/** Helper routine which calls platform specific crypto random generator
@param buf
*/
function getRandomValues(buf: Uint8Array): void;
/** Return a secure random number in the specified range
@param from Min of the random number
@param to Max of the random number (max 32bit)
*/
function getSecureRandom(from: number, to: number): number;
}
declare module openpgp.crypto.signature {
/** Create a signature on data using the specified algorithm
@param hash_algo hash Algorithm to use
@param algo Asymmetric cipher algorithm to use
@param publicMPIs Public key multiprecision integers of the private key
@param secretMPIs Private key multiprecision integers which is used to sign the data
@param data Data to be signed
*/
function sign(hash_algo: enums.hash, algo: enums.publicKey, publicMPIs: Array<Mpi>, secretMPIs: Array<Mpi>, data: string): Mpi;
/**
@param algo public Key algorithm
@param hash_algo Hash algorithm
@param msg_MPIs Signature multiprecision integers
@param publickey_MPIs Public key multiprecision integers
@param data Data on where the signature was computed on
*/
function verify(algo: enums.publicKey, hash_algo: enums.hash, msg_MPIs: Array<Mpi>, publickey_MPIs: Array<Mpi>, data: string): boolean;
}
declare module openpgp.enums {
enum armor {
multipart_section,
multipart_last,
signed,
message,
public_key,
private_key
}
enum compression {
uncompressed,
zip,
zlib,
bzip2
}
enum hash {
md5,
sha1,
ripemd,
sha256,
sha384,
sha512,
sha224
}
enum packet {
publicKeyEncryptedSessionKey,
signature,
symEncryptedSessionKey,
onePassSignature,
secretKey,
publicKey,
secretSubkey,
compressed,
symmetricallyEncrypted,
marker,
literal,
trust,
userid,
publicSubkey,
userAttribute,
symEncryptedIntegrityProtected,
modificationDetectionCode,
}
enum publicKey {
rsa_encrypt_sign,
rsa_encrypt,
rsa_sign,
elgamal,
dsa
}
enum symmetric {
plaintext,
idea,
tripledes,
cast5,
blowfish,
aes128,
aes192,
aes256,
twofish
}
enum keyStatus {
invalid,
expired,
revoked,
valid,
no_self_cert
}
}
declare module openpgp.key {
interface KeyResult {
keys: Array<Key>,
err: Array<Error>
}
/** Class that represents an OpenPGP key. Must contain a primary key. Can contain additional subkeys, signatures, user ids, user attributes.
*/
interface Key {
armor(): string,
decrypt(passphrase: string): boolean;
getExpirationTime(): Date;
getKeyIds(): Array<Keyid>;
getPreferredHashAlgorithm(): string;
getPrimaryUser(): any;
getUserIds(): Array<string>;
isPrivate(): boolean;
isPublic(): boolean;
primaryKey: packet.PublicKey;
toPublic(): Key;
update(key: Key): void;
verifyPrimaryKey(): enums.keyStatus;
}
/** Generates a new OpenPGP key. Currently only supports RSA keys. Primary and subkey will be of same type.
@param options
*/
function generate(options: KeyOptions): Key;
/** Reads an OpenPGP armored text and returns one or multiple key objects
@param armoredText text to be parsed
*/
function readArmored(armoredText: string): KeyResult;
}
declare module openpgp.message {
/** Class that represents an OpenPGP message. Can be an encrypted message, signed message, compressed message or literal message
*/
interface Message {
/** Returns ASCII armored text of message
*/
armor(): string,
/** Decrypt the message
@param privateKey private key with decrypted secret data
*/
decrypt(privateKey: key.Key): Array<Message>,
/** Encrypt the message
@param keys array of keys, used to encrypt the message
*/
encrypt(keys: Array<key.Key>): Array<Message>,
/** Returns the key IDs of the keys to which the session key is encrypted
*/
getEncryptionKeyIds(): Array<Keyid>,
/** Get literal data that is the body of the message
*/
getLiteralData(): string,
/** Returns the key IDs of the keys that signed the message
*/
getSigningKeyIds(): Array<Keyid>,
/** Get literal data as text
*/
getText(): string,
/** Sign the message (the literal data packet of the message)
@param privateKey private keys with decrypted secret key data for signing
*/
sign(privateKey: Array<key.Key>): Message,
/** Unwrap compressed message
*/
unwrapCompressed(): Message,
/** Verify message signatures
@param keys array of keys to verify signatures
*/
verify(keys: Array<key.Key>): Array<Object>,
}
/** creates new message object from binary data
@param bytes
*/
function fromBinary(bytes: string): Message;
/** creates new message object from text
@param text
*/
function fromText(text: string): Message;
/** reads an OpenPGP armored message and returns a message object
@param armoredText text to be parsed
*/
function readArmored(armoredText: string): Message;
}
declare module openpgp.packet {
interface PublicKey {
algorithm: enums.publicKey;
created: Date;
fingerprint: string;
getBitSize(): number;
getFingerprint(): string;
getKeyId(): string;
read(input: string): any;
write(): any;
}
interface SecretKey extends PublicKey {
read(bytes:string): void;
write(): string;
clearPrivateMPIs(str_passphrase: string): boolean;
encrypt(passphrase:string): void;
}
/** Allocate a new packet from structured packet clone
@param packetClone packet clone
*/
function fromStructuredClone(packetClone: Object): Object
/** Allocate a new packet
@param property name from enums.packet
*/
function newPacketFromTag(tag: string): Object;
}
declare module openpgp.util {
/** Convert an array of integers(0.255) to a string
@param bin An array of (binary) integers to convert
*/
function bin2str(bin: Array<number>): string;
/** Calculates a 16bit sum of a string by adding each character codes modulus 65535
@param text string to create a sum of
*/
function calc_checksum(text: string): number;
/** Convert a string of utf8 bytes to a native javascript string
@param utf8 A valid squence of utf8 bytes
*/
function decode_utf8(utf8: string): string
/** Convert a native javascript string to a string of utf8 bytes
param str The string to convert
*/
function encode_utf8(str: string): string
/** Return the algorithm type as string
*/
function get_hashAlgorithmString(): string
/** Get native Web Cryptography api. The default configuration is to use the api when available. But it can also be deactivated with config.useWebCrypto
*/
function getWebCrypto(): Object
/** Create binary string from a hex encoded string
@param str Hex string to convert
*/
function hex2bin(str: string): string;
/** Creating a hex string from an binary array of integers (0..255)
@param str Array of bytes to convert
*/
function hexidump(str: string): string;
/** Create hexstring from a binary
@param str string to convert
*/
function hexstrdump(str: string): string;
/** Helper function to print a debug message. Debug messages are only printed if
@param str string of the debug message
*/
function print_debug(str: string): void;
/** Helper function to print a debug message. Debug messages are only printed if
@param str string of the debug message
*/
function print_debug_hexstr_dump(str: string): void;
/** Shifting a string to n bits right
@param value The string to shift
@param bitcount Amount of bits to shift (MUST be smaller than 9)
*/
function shiftRight(value: string, bitcount: number): string;
/** Convert a string to an array of integers(0.255)
@param str string to convert
*/
function str2bin(str: string): Array<number>;
/** Convert a string to a Uint8Array
@param str string to convert
*/
function str2Uint8Array(str: string): Uint8Array;
/** Convert a Uint8Array to a string. This currently functions the same as bin2str.
@param bin An array of (binary) integers to convert
*/
function Uint8Array2str(bin: Uint8Array): string;
}