@protontech/openpgp 6.1.1-patch.4 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +13 -2
  2. package/dist/lightweight/argon2id.min.mjs +2 -2
  3. package/dist/lightweight/argon2id.min.mjs.map +1 -1
  4. package/dist/lightweight/argon2id.mjs +4 -4
  5. package/dist/lightweight/legacy_ciphers.min.mjs +1 -1
  6. package/dist/lightweight/legacy_ciphers.min.mjs.map +1 -1
  7. package/dist/lightweight/legacy_ciphers.mjs +10 -10
  8. package/dist/lightweight/nacl-fast.min.mjs +3 -0
  9. package/dist/lightweight/nacl-fast.min.mjs.map +1 -0
  10. package/dist/lightweight/nacl-fast.mjs +1382 -0
  11. package/dist/lightweight/noble_curves.min.mjs +11 -12
  12. package/dist/lightweight/noble_curves.min.mjs.map +1 -1
  13. package/dist/lightweight/noble_curves.mjs +2175 -1752
  14. package/dist/lightweight/noble_hashes.min.mjs +2 -2
  15. package/dist/lightweight/noble_hashes.min.mjs.map +1 -1
  16. package/dist/lightweight/noble_hashes.mjs +80 -51
  17. package/dist/lightweight/noble_post_quantum.min.mjs +3 -4
  18. package/dist/lightweight/noble_post_quantum.min.mjs.map +1 -1
  19. package/dist/lightweight/noble_post_quantum.mjs +352 -10
  20. package/dist/lightweight/openpgp.min.mjs +3 -4
  21. package/dist/lightweight/openpgp.min.mjs.map +1 -1
  22. package/dist/lightweight/openpgp.mjs +998 -2820
  23. package/dist/lightweight/seek-bzip.min.mjs +2 -2
  24. package/dist/lightweight/seek-bzip.min.mjs.map +1 -1
  25. package/dist/lightweight/seek-bzip.mjs +780 -746
  26. package/dist/lightweight/sha512.min.mjs +4 -2
  27. package/dist/lightweight/sha512.min.mjs.map +1 -1
  28. package/dist/lightweight/sha512.mjs +672 -130
  29. package/dist/node/openpgp.cjs +10685 -10141
  30. package/dist/node/openpgp.min.cjs +14 -17
  31. package/dist/node/openpgp.min.cjs.map +1 -1
  32. package/dist/node/openpgp.min.mjs +14 -17
  33. package/dist/node/openpgp.min.mjs.map +1 -1
  34. package/dist/node/openpgp.mjs +10685 -10140
  35. package/dist/openpgp.js +11728 -11188
  36. package/dist/openpgp.min.js +14 -17
  37. package/dist/openpgp.min.js.map +1 -1
  38. package/dist/openpgp.min.mjs +14 -17
  39. package/dist/openpgp.min.mjs.map +1 -1
  40. package/dist/openpgp.mjs +11728 -11188
  41. package/{src → dist/types}/config/config.d.ts +1 -21
  42. package/{openpgp.d.ts → dist/types/index.d.ts} +94 -76
  43. package/dist/types/packet/grammar.d.ts +33 -0
  44. package/package.json +40 -39
  45. package/dist/lightweight/sha3.min.mjs +0 -4
  46. package/dist/lightweight/sha3.min.mjs.map +0 -1
  47. package/dist/lightweight/sha3.mjs +0 -401
  48. /package/{src → dist/types}/config/index.d.ts +0 -0
  49. /package/{src → dist/types}/enums.d.ts +0 -0
@@ -1,20 +1,3 @@
1
- // GPG4Browsers - An OpenPGP implementation in javascript
2
- // Copyright (C) 2011 Recurity Labs GmbH
3
- //
4
- // This library is free software; you can redistribute it and/or
5
- // modify it under the terms of the GNU Lesser General Public
6
- // License as published by the Free Software Foundation; either
7
- // version 3.0 of the License, or (at your option) any later version.
8
- //
9
- // This library is distributed in the hope that it will be useful,
10
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- // Lesser General Public License for more details.
13
- //
14
- // You should have received a copy of the GNU Lesser General Public
15
- // License along with this library; if not, write to the Free Software
16
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
1
  /**
19
2
  * Global configuration values.
20
3
  */
@@ -29,7 +12,6 @@ export interface Config {
29
12
  showComment: boolean;
30
13
  aeadProtect: boolean;
31
14
  ignoreSEIPDv2FeatureFlag: boolean;
32
- parseAEADEncryptedV4KeysAsLegacy: boolean;
33
15
  allowUnauthenticatedMessages: boolean;
34
16
  allowUnauthenticatedStream: boolean;
35
17
  allowForwardedMessages: boolean;
@@ -38,8 +20,7 @@ export interface Config {
38
20
  ignoreUnsupportedPackets: boolean;
39
21
  ignoreMalformedPackets: boolean;
40
22
  enforceGrammar: boolean;
41
- pluggableGrammarErrorReporter: ((errorMessage: string) => any) | null;
42
- additionalAllowedPackets: Array<{ new(): any }>;
23
+ additionalAllowedPackets: Array<{ new(): any, tag: enums.packet }>;
43
24
  versionString: string;
44
25
  commentString: string;
45
26
  allowInsecureDecryptionWithSigningKeys: boolean;
@@ -56,7 +37,6 @@ export interface Config {
56
37
  s2kArgon2Params: { passes: number, parallelism: number; memoryExponent: number; };
57
38
  maxUserIDLength: number;
58
39
  knownNotations: string[];
59
- nonDeterministicSignaturesViaNotation: boolean;
60
40
  useEllipticFallback: boolean;
61
41
  rejectHashAlgorithms: Set<enums.hash>;
62
42
  rejectMessageHashAlgorithms: Set<enums.hash>;
@@ -10,13 +10,15 @@
10
10
  */
11
11
 
12
12
  import type { WebStream as GenericWebStream, NodeWebStream as GenericNodeWebStream } from '@openpgp/web-stream-tools';
13
- import enums from './src/enums';
14
- import config, { type Config, type PartialConfig } from './src/config';
13
+ import enums from './enums';
14
+ import config, { type Config, type PartialConfig } from './config';
15
+
16
+ export { GrammarError } from './packet/grammar';
15
17
 
16
18
  export { enums, config, Config, PartialConfig };
17
19
 
18
20
  /* ############## STREAM #################### */
19
- type Data = Uint8Array | string;
21
+ type Data = Uint8Array<ArrayBuffer> | string;
20
22
  // web-stream-tools might end up supporting additional data types, so we re-declare the types
21
23
  // to enforce the type contraint that we need.
22
24
  export type WebStream<T extends Data> = GenericWebStream<T>;
@@ -29,29 +31,29 @@ type MaybeArray<T> = T | Array<T>;
29
31
  // The Key and PublicKey types can be used interchangably since TS cannot detect the difference, as they have the same class properties.
30
32
  // 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.
31
33
  export function readKey(options: { armoredKey: string, config?: PartialConfig }): Promise<Key>;
32
- export function readKey(options: { binaryKey: Uint8Array, config?: PartialConfig }): Promise<Key>;
34
+ export function readKey(options: { binaryKey: Uint8Array<ArrayBuffer>, config?: PartialConfig }): Promise<Key>;
33
35
  export function readKeys(options: { armoredKeys: string, config?: PartialConfig }): Promise<Key[]>;
34
- export function readKeys(options: { binaryKeys: Uint8Array, config?: PartialConfig }): Promise<Key[]>;
36
+ export function readKeys(options: { binaryKeys: Uint8Array<ArrayBuffer>, config?: PartialConfig }): Promise<Key[]>;
35
37
  export function readPrivateKey(options: { armoredKey: string, config?: PartialConfig }): Promise<PrivateKey>;
36
- export function readPrivateKey(options: { binaryKey: Uint8Array, config?: PartialConfig }): Promise<PrivateKey>;
38
+ export function readPrivateKey(options: { binaryKey: Uint8Array<ArrayBuffer>, config?: PartialConfig }): Promise<PrivateKey>;
37
39
  export function readPrivateKeys(options: { armoredKeys: string, config?: PartialConfig }): Promise<PrivateKey[]>;
38
- export function readPrivateKeys(options: { binaryKeys: Uint8Array, config?: PartialConfig }): Promise<PrivateKey[]>;
40
+ export function readPrivateKeys(options: { binaryKeys: Uint8Array<ArrayBuffer>, config?: PartialConfig }): Promise<PrivateKey[]>;
39
41
  export function generateKey(options: GenerateKeyOptions & { format?: 'armored' }): Promise<SerializedKeyPair<string> & { revocationCertificate: string }>;
40
- export function generateKey(options: GenerateKeyOptions & { format: 'binary' }): Promise<SerializedKeyPair<Uint8Array> & { revocationCertificate: string }>;
42
+ export function generateKey(options: GenerateKeyOptions & { format: 'binary' }): Promise<SerializedKeyPair<Uint8Array<ArrayBuffer>> & { revocationCertificate: string }>;
41
43
  export function generateKey(options: GenerateKeyOptions & { format: 'object' }): Promise<KeyPair & { revocationCertificate: string }>;
42
44
  export function decryptKey(options: { privateKey: PrivateKey; passphrase?: MaybeArray<string>; config?: PartialConfig }): Promise<PrivateKey>;
43
45
  export function encryptKey(options: { privateKey: PrivateKey; passphrase?: MaybeArray<string>; config?: PartialConfig }): Promise<PrivateKey>;
44
46
  export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format?: 'armored', config?: PartialConfig }): Promise<SerializedKeyPair<string> & { revocationCertificate: string }>;
45
- export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array> & { revocationCertificate: string }>;
47
+ export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array<ArrayBuffer>> & { revocationCertificate: string }>;
46
48
  export function reformatKey(options: { privateKey: PrivateKey; userIDs?: MaybeArray<UserID>; passphrase?: string; keyExpirationTime?: number; date?: Date, format: 'object', config?: PartialConfig }): Promise<KeyPair & { revocationCertificate: string }>;
47
49
  export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format?: 'armored', config?: PartialConfig }): Promise<SerializedKeyPair<string>>;
48
- export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array>>;
50
+ export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array<ArrayBuffer>>>;
49
51
  export function revokeKey(options: { key: PrivateKey, reasonForRevocation?: ReasonForRevocation, date?: Date, format: 'object', config?: PartialConfig }): Promise<KeyPair>;
50
52
  export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format?: 'armored', config?: PartialConfig }): Promise<SerializedKeyPair<string>>;
51
- export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array>>;
53
+ export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format: 'binary', config?: PartialConfig }): Promise<SerializedKeyPair<Uint8Array<ArrayBuffer>>>;
52
54
  export function revokeKey(options: { key: PrivateKey, revocationCertificate: string, date?: Date, format: 'object', config?: PartialConfig }): Promise<KeyPair>;
53
55
  export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format?: 'armored', config?: PartialConfig }): Promise<{ publicKey: string, privateKey: null }>;
54
- export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format: 'binary', config?: PartialConfig }): Promise<{ publicKey: Uint8Array, privateKey: null }>;
56
+ export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format: 'binary', config?: PartialConfig }): Promise<{ publicKey: Uint8Array<ArrayBuffer>, privateKey: null }>;
55
57
  export function revokeKey(options: { key: PublicKey, revocationCertificate: string, date?: Date, format: 'object', config?: PartialConfig }): Promise<{ publicKey: PublicKey, privateKey: null }>;
56
58
 
57
59
  export abstract class Key {
@@ -59,7 +61,7 @@ export abstract class Key {
59
61
  public subkeys: Subkey[]; // do not add/replace users directly
60
62
  public users: User[]; // do not add/replace subkeys directly
61
63
  public revocationSignatures: SignaturePacket[];
62
- public write(): Uint8Array;
64
+ public write(): Uint8Array<ArrayBuffer>;
63
65
  public armor(config?: Config): string;
64
66
  public getExpirationTime(userID?: UserID, config?: Config): Promise<Date | typeof Infinity | null>;
65
67
  public getKeyIDs(): KeyID[];
@@ -120,12 +122,28 @@ export class Subkey {
120
122
  public revoke(primaryKey: SecretKeyPacket, reasonForRevocation?: ReasonForRevocation, date?: Date, config?: Config): Promise<Subkey>;
121
123
  }
122
124
 
123
- export interface User {
124
- userID: UserIDPacket | null;
125
- userAttribute: UserAttributePacket | null;
126
- selfCertifications: SignaturePacket[];
127
- otherCertifications: SignaturePacket[];
128
- revocationSignatures: SignaturePacket[];
125
+ export class User {
126
+ constructor(userPacket: UserIDPacket | UserAttributePacket, mainKey: Key);
127
+ public readonly userID: UserIDPacket | null;
128
+ public readonly userAttribute: UserAttributePacket | null;
129
+ public selfCertifications: SignaturePacket[];
130
+ public otherCertifications: SignaturePacket[];
131
+ public revocationSignatures: SignaturePacket[];
132
+ public readonly mainKey: Key;
133
+ public toPacketList(): PacketList<AnyPacket>;
134
+ public clone(): User;
135
+ public certify(signingKeys: PrivateKey[], date?: Date, config?: Config): Promise<User>;
136
+ public isRevoked(
137
+ certificate: SignaturePacket,
138
+ keyPacket?: PublicSubkeyPacket | SecretSubkeyPacket | PublicKeyPacket | SecretKeyPacket,
139
+ date?: Date,
140
+ config?: Config,
141
+ ): Promise<boolean>;
142
+ public verifyCertificate(certificate: SignaturePacket, verificationKeys: PublicKey[], date?: Date, config?: Config): Promise<true | null>;
143
+ public verifyAllCertifications(verificationKeys: PublicKey[], date?: Date, config?: Config): Promise<{ keyID: KeyID; valid: boolean | null }[]>;
144
+ public verify(date?: Date, config?: Config): Promise<true>;
145
+ public update(sourceUser: User, date?: Date, config?: Config): Promise<void>;
146
+ public revoke(primaryKey: SecretKeyPacket, reasonForRevocation?: ReasonForRevocation, date?: Date, config?: Config): Promise<User>;
129
147
  }
130
148
 
131
149
  export interface PrimaryUser {
@@ -143,12 +161,12 @@ export type AlgorithmInfo = {
143
161
  /* ############## SIG #################### */
144
162
 
145
163
  export function readSignature(options: { armoredSignature: string, config?: PartialConfig }): Promise<Signature>;
146
- export function readSignature(options: { binarySignature: Uint8Array, config?: PartialConfig }): Promise<Signature>;
164
+ export function readSignature(options: { binarySignature: Uint8Array<ArrayBuffer>, config?: PartialConfig }): Promise<Signature>;
147
165
 
148
166
  export class Signature {
149
167
  public readonly packets: PacketList<SignaturePacket>;
150
168
  constructor(packetlist: PacketList<SignaturePacket>);
151
- public write(): MaybeStream<Uint8Array>;
169
+ public write(): MaybeStream<Uint8Array<ArrayBuffer>>;
152
170
  public armor(config?: Config): string;
153
171
  public getSigningKeyIDs(): Array<KeyID>;
154
172
  }
@@ -195,15 +213,15 @@ export class CleartextMessage {
195
213
  /* ############## MSG #################### */
196
214
  export function generateSessionKey(options: { encryptionKeys: MaybeArray<PublicKey>, date?: Date, encryptionUserIDs?: MaybeArray<UserID>, config?: PartialConfig }): Promise<SessionKey>;
197
215
  export function encryptSessionKey(options: EncryptSessionKeyOptions & { format?: 'armored' }): Promise<string>;
198
- export function encryptSessionKey(options: EncryptSessionKeyOptions & { format: 'binary' }): Promise<Uint8Array>;
216
+ export function encryptSessionKey(options: EncryptSessionKeyOptions & { format: 'binary' }): Promise<Uint8Array<ArrayBuffer>>;
199
217
  export function encryptSessionKey(options: EncryptSessionKeyOptions & { format: 'object' }): Promise<Message<Data>>;
200
218
  export function decryptSessionKeys<T extends MaybeStream<Data>>(options: { message: Message<T>, decryptionKeys?: MaybeArray<PrivateKey>, passwords?: MaybeArray<string>, date?: Date, config?: PartialConfig }): Promise<DecryptedSessionKey[]>;
201
219
 
202
220
  export function readMessage<T extends MaybeStream<string>>(options: { armoredMessage: T, config?: PartialConfig }): Promise<Message<T>>;
203
- export function readMessage<T extends MaybeStream<Uint8Array>>(options: { binaryMessage: T, config?: PartialConfig }): Promise<Message<T>>;
221
+ export function readMessage<T extends MaybeStream<Uint8Array<ArrayBuffer>>>(options: { binaryMessage: T, config?: PartialConfig }): Promise<Message<T>>;
204
222
 
205
223
  export function createMessage<T extends MaybeStream<string>>(options: { text: T, filename?: string, date?: Date, format?: enums.literalFormatNames }): Promise<Message<T>>;
206
- export function createMessage<T extends MaybeStream<Uint8Array>>(options: { binary: T, filename?: string, date?: Date, format?: enums.literalFormatNames }): Promise<Message<T>>;
224
+ export function createMessage<T extends MaybeStream<Uint8Array<ArrayBuffer>>>(options: { binary: T, filename?: string, date?: Date, format?: enums.literalFormatNames }): Promise<Message<T>>;
207
225
 
208
226
  export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & { message: Message<T>, format?: 'armored' }): Promise<
209
227
  T extends WebStream<Data> ? WebStream<string> :
@@ -211,9 +229,9 @@ export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & {
211
229
  string
212
230
  >;
213
231
  export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & { message: Message<T>, format: 'binary' }): Promise<
214
- T extends WebStream<Data> ? WebStream<Uint8Array> :
215
- T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
216
- Uint8Array
232
+ T extends WebStream<Data> ? WebStream<Uint8Array<ArrayBuffer>> :
233
+ T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array<ArrayBuffer>> :
234
+ Uint8Array<ArrayBuffer>
217
235
  >;
218
236
  export function encrypt<T extends MaybeStream<Data>>(options: EncryptOptions & { message: Message<T>, format: 'object' }): Promise<Message<T>>;
219
237
 
@@ -223,9 +241,9 @@ export function sign<T extends MaybeStream<Data>>(options: SignOptions & { messa
223
241
  string
224
242
  >;
225
243
  export function sign<T extends MaybeStream<Data>>(options: SignOptions & { message: Message<T>, format: 'binary' }): Promise<
226
- T extends WebStream<Data> ? WebStream<Uint8Array> :
227
- T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
228
- Uint8Array
244
+ T extends WebStream<Data> ? WebStream<Uint8Array<ArrayBuffer>> :
245
+ T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array<ArrayBuffer>> :
246
+ Uint8Array<ArrayBuffer>
229
247
  >;
230
248
  export function sign<T extends MaybeStream<Data>>(options: SignOptions & { message: Message<T>, format: 'object' }): Promise<Message<T>>;
231
249
  export function sign(options: SignOptions & { message: CleartextMessage, format?: 'armored' }): Promise<string>;
@@ -233,9 +251,9 @@ export function sign(options: SignOptions & { message: CleartextMessage, format:
233
251
 
234
252
  export function decrypt<T extends MaybeStream<Data>>(options: DecryptOptions & { message: Message<T>, format: 'binary' }): Promise<DecryptMessageResult & {
235
253
  data:
236
- T extends WebStream<Data> ? WebStream<Uint8Array> :
237
- T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
238
- Uint8Array
254
+ T extends WebStream<Data> ? WebStream<Uint8Array<ArrayBuffer>> :
255
+ T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array<ArrayBuffer>> :
256
+ Uint8Array<ArrayBuffer>
239
257
  }>;
240
258
  export function decrypt<T extends MaybeStream<Data>>(options: DecryptOptions & { message: Message<T> }): Promise<DecryptMessageResult & {
241
259
  data:
@@ -246,9 +264,9 @@ export function decrypt<T extends MaybeStream<Data>>(options: DecryptOptions & {
246
264
 
247
265
  export function verify(options: VerifyOptions & { message: CleartextMessage, format?: 'utf8' }): Promise<VerifyMessageResult<string>>;
248
266
  export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T>, format: 'binary' }): Promise<VerifyMessageResult<
249
- T extends WebStream<Data> ? WebStream<Uint8Array> :
250
- T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array> :
251
- Uint8Array
267
+ T extends WebStream<Data> ? WebStream<Uint8Array<ArrayBuffer>> :
268
+ T extends NodeWebStream<Data> ? NodeWebStream<Uint8Array<ArrayBuffer>> :
269
+ Uint8Array<ArrayBuffer>
252
270
  >>;
253
271
  export function verify<T extends MaybeStream<Data>>(options: VerifyOptions & { message: Message<T> }): Promise<VerifyMessageResult<
254
272
  T extends WebStream<Data> ? WebStream<string> :
@@ -265,7 +283,7 @@ export class Message<T extends MaybeStream<Data>> {
265
283
 
266
284
  /** Returns binary representation of message
267
285
  */
268
- public write(): MaybeStream<Uint8Array>;
286
+ public write(): MaybeStream<Uint8Array<ArrayBuffer>>;
269
287
 
270
288
  /** Returns ASCII armored text of message
271
289
  */
@@ -287,7 +305,7 @@ export class Message<T extends MaybeStream<Data>> {
287
305
 
288
306
  /** Get literal data that is the body of the message
289
307
  */
290
- public getLiteralData(): (T extends Stream<Data> ? WebStream<Uint8Array> : Uint8Array) | null;
308
+ public getLiteralData(): (T extends Stream<Data> ? WebStream<Uint8Array<ArrayBuffer>> : Uint8Array<ArrayBuffer>) | null;
291
309
 
292
310
  /** Returns the key IDs of the keys that signed the message
293
311
  */
@@ -315,17 +333,17 @@ export class Message<T extends MaybeStream<Data>> {
315
333
 
316
334
  /**
317
335
  * Append signature to unencrypted message object
318
- * @param {String|Uint8Array} detachedSignature - The detached ASCII-armored or Uint8Array PGP signature
336
+ * @param {String|Uint8Array<ArrayBuffer>} detachedSignature - The detached ASCII-armored or Uint8Array<ArrayBuffer> PGP signature
319
337
  */
320
- public appendSignature(detachedSignature: string | Uint8Array, config?: Config): Promise<void>;
338
+ public appendSignature(detachedSignature: string | Uint8Array<ArrayBuffer>, config?: Config): Promise<void>;
321
339
  }
322
340
 
323
341
  /* ############## PACKET #################### */
324
342
 
325
343
  export declare abstract class BasePacket {
326
344
  static readonly tag: enums.packet;
327
- public read(bytes: Uint8Array): void;
328
- public write(): Uint8Array;
345
+ public read(bytes: Uint8Array<ArrayBuffer>): void;
346
+ public write(): Uint8Array<ArrayBuffer>;
329
347
  }
330
348
 
331
349
  /**
@@ -339,7 +357,7 @@ declare abstract class BasePublicKeyPacket extends BasePacket {
339
357
  public version: number;
340
358
  public getAlgorithmInfo(): AlgorithmInfo;
341
359
  public getFingerprint(): string;
342
- public getFingerprintBytes(): Uint8Array | null;
360
+ public getFingerprintBytes(): Uint8Array<ArrayBuffer> | null;
343
361
  public hasSameFingerprintAs(other: BasePublicKeyPacket): boolean;
344
362
  public getCreationTime(): Date;
345
363
  public getKeyID(): KeyID;
@@ -393,9 +411,9 @@ export class SymEncryptedIntegrityProtectedDataPacket extends BasePacket {
393
411
 
394
412
  export class AEADEncryptedDataPacket extends BasePacket {
395
413
  static readonly tag: enums.packet.aeadEncryptedData;
396
- private decrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
397
- private encrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
398
- private crypt(fn: Function, sessionKey: Uint8Array, data: MaybeStream<Uint8Array>): MaybeStream<Uint8Array>;
414
+ private decrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array<ArrayBuffer>, config?: Config): void;
415
+ private encrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array<ArrayBuffer>, config?: Config): void;
416
+ private crypt(fn: Function, sessionKey: Uint8Array<ArrayBuffer>, data: MaybeStream<Uint8Array<ArrayBuffer>>): MaybeStream<Uint8Array<ArrayBuffer>>;
399
417
  }
400
418
 
401
419
  export class PublicKeyEncryptedSessionKeyPacket extends BasePacket {
@@ -413,18 +431,18 @@ export class SymEncryptedSessionKeyPacket extends BasePacket {
413
431
  export class LiteralDataPacket extends BasePacket {
414
432
  static readonly tag: enums.packet.literalData;
415
433
  private getText(clone?: boolean): MaybeStream<string>;
416
- private getBytes(clone?: boolean): MaybeStream<Uint8Array>;
434
+ private getBytes(clone?: boolean): MaybeStream<Uint8Array<ArrayBuffer>>;
417
435
  private setText(text: MaybeStream<string>, format?: enums.literal);
418
- private setBytes(bytes: MaybeStream<Uint8Array>, format: enums.literal);
436
+ private setBytes(bytes: MaybeStream<Uint8Array<ArrayBuffer>>, format: enums.literal);
419
437
  private setFilename(filename: string);
420
438
  private getFilename(): string;
421
- private writeHeader(): Uint8Array;
439
+ private writeHeader(): Uint8Array<ArrayBuffer>;
422
440
  }
423
441
 
424
442
  export class SymmetricallyEncryptedDataPacket extends BasePacket {
425
443
  static readonly tag: enums.packet.symmetricallyEncryptedData;
426
- private decrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
427
- private encrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array, config?: Config): void;
444
+ private decrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array<ArrayBuffer>, config?: Config): void;
445
+ private encrypt(sessionKeyAlgorithm: enums.symmetric, sessionKey: Uint8Array<ArrayBuffer>, config?: Config): void;
428
446
  }
429
447
 
430
448
  export class MarkerPacket extends BasePacket {
@@ -457,10 +475,10 @@ export class SignaturePacket extends BasePacket {
457
475
  public signatureType: enums.signature | null;
458
476
  public hashAlgorithm: enums.hash | null;
459
477
  public publicKeyAlgorithm: enums.publicKey | null;
460
- public signatureData: null | Uint8Array;
478
+ public signatureData: null | Uint8Array<ArrayBuffer>;
461
479
  public unhashedSubpackets: RawSubpacket[];
462
480
  public unknownSubpackets: RawSubpacket[];
463
- public signedHashValue: null | Uint8Array;
481
+ public signedHashValue: null | Uint8Array<ArrayBuffer>;
464
482
  public created: Date | null;
465
483
  public signatureExpirationTime: null | number;
466
484
  public signatureNeverExpires: boolean;
@@ -474,7 +492,7 @@ export class SignaturePacket extends BasePacket {
474
492
  public preferredSymmetricAlgorithms: enums.symmetric[] | null;
475
493
  public revocationKeyClass: null | number;
476
494
  public revocationKeyAlgorithm: null | enums.publicKey;
477
- public revocationKeyFingerprint: null | Uint8Array;
495
+ public revocationKeyFingerprint: null | Uint8Array<ArrayBuffer>;
478
496
  public issuerKeyID: KeyID;
479
497
  public notation: null | { [name: string]: string };
480
498
  public preferredHashAlgorithms: enums.hash[] | null;
@@ -483,22 +501,22 @@ export class SignaturePacket extends BasePacket {
483
501
  public preferredKeyServer: null | string;
484
502
  public isPrimaryUserID: null | boolean;
485
503
  public policyURI: null | string;
486
- public keyFlags: Uint8Array | null;
504
+ public keyFlags: Uint8Array<ArrayBuffer> | null;
487
505
  public signersUserID: null | string;
488
506
  public reasonForRevocationFlag: null | enums.reasonForRevocation;
489
507
  public reasonForRevocationString: null | string;
490
- public features: Uint8Array | null;
508
+ public features: Uint8Array<ArrayBuffer> | null;
491
509
  public signatureTargetPublicKeyAlgorithm: enums.publicKey | null;
492
510
  public signatureTargetHashAlgorithm: enums.hash | null;
493
511
  public signatureTargetHash: null | string;
494
512
  public embeddedSignature: null | SignaturePacket;
495
513
  public issuerKeyVersion: null | number;
496
- public issuerFingerprint: null | Uint8Array;
514
+ public issuerFingerprint: null | Uint8Array<ArrayBuffer>;
497
515
  public preferredAEADAlgorithms: enums.aead[] | null;
498
516
  public revoked: null | boolean;
499
517
  public rawNotations: RawNotation[];
500
- public sign(key: AnySecretKeyPacket, data: Uint8Array, date?: Date, detached?: boolean): Promise<void>;
501
- public verify(key: AnyKeyPacket, signatureType: enums.signature, data: Uint8Array | object, date?: Date, detached?: boolean, config?: Config): Promise<void>; // throws on error
518
+ public sign(key: AnySecretKeyPacket, data: Uint8Array<ArrayBuffer>, date?: Date, detached?: boolean): Promise<void>;
519
+ public verify(key: AnyKeyPacket, signatureType: enums.signature, data: Uint8Array<ArrayBuffer> | object, date?: Date, detached?: boolean, config?: Config): Promise<void>; // throws on error
502
520
  public isExpired(date?: Date): boolean;
503
521
  public getExpirationTime(): Date | typeof Infinity;
504
522
  }
@@ -506,12 +524,12 @@ export class SignaturePacket extends BasePacket {
506
524
  export interface RawSubpacket {
507
525
  type: number;
508
526
  critical: boolean;
509
- body: Uint8Array;
527
+ body: Uint8Array<ArrayBuffer>;
510
528
  }
511
529
 
512
530
  export interface RawNotation {
513
531
  name: string;
514
- value: Uint8Array;
532
+ value: Uint8Array<ArrayBuffer>;
515
533
  humanReadable: boolean;
516
534
  critical: boolean;
517
535
  }
@@ -522,7 +540,7 @@ export class TrustPacket extends BasePacket {
522
540
 
523
541
  export class UnparseablePacket {
524
542
  tag: enums.packet;
525
- write: () => Uint8Array;
543
+ write: () => Uint8Array<ArrayBuffer>;
526
544
  }
527
545
 
528
546
  export type AnyPacket = BasePacket | UnparseablePacket;
@@ -531,9 +549,9 @@ export type AnyKeyPacket = BasePublicKeyPacket;
531
549
 
532
550
  type AllowedPackets = Map<enums.packet, object>; // mapping to Packet classes (i.e. typeof LiteralDataPacket etc.)
533
551
  export class PacketList<T extends AnyPacket> extends Array<T> {
534
- static fromBinary(bytes: MaybeStream<Uint8Array>, allowedPackets: AllowedPackets, config?: Config): PacketList<AnyPacket>; // the packet types depend on`allowedPackets`
535
- public read(bytes: MaybeStream<Uint8Array>, allowedPackets: AllowedPackets, config?: Config): void;
536
- public write(): Uint8Array;
552
+ static fromBinary(bytes: MaybeStream<Uint8Array<ArrayBuffer>>, allowedPackets: AllowedPackets, config?: Config): PacketList<AnyPacket>; // the packet types depend on`allowedPackets`
553
+ public read(bytes: MaybeStream<Uint8Array<ArrayBuffer>>, allowedPackets: AllowedPackets, config?: Config): void;
554
+ public write(): Uint8Array<ArrayBuffer>;
537
555
  public filterByTag(...args: enums.packet[]): PacketList<T>;
538
556
  public indexOfTag(...tags: enums.packet[]): number[];
539
557
  public findPacket(tag: enums.packet): T | undefined;
@@ -543,13 +561,13 @@ export class PacketList<T extends AnyPacket> extends Array<T> {
543
561
 
544
562
  export interface UserID { name?: string; email?: string; comment?: string; }
545
563
  export interface SessionKey {
546
- data: Uint8Array;
564
+ data: Uint8Array<ArrayBuffer>;
547
565
  algorithm: enums.symmetricNames;
548
566
  aeadAlgorithm?: enums.aeadNames;
549
567
  }
550
568
 
551
569
  export interface DecryptedSessionKey {
552
- data: Uint8Array;
570
+ data: Uint8Array<ArrayBuffer>;
553
571
  algorithm: enums.symmetricNames | null; // `null` if the session key is associated with a SEIPDv2 packet
554
572
  }
555
573
 
@@ -594,13 +612,13 @@ export interface DecryptOptions {
594
612
  decryptionKeys?: MaybeArray<PrivateKey>;
595
613
  /** (optional) passwords to decrypt the message */
596
614
  passwords?: MaybeArray<string>;
597
- /** (optional) session keys in the form: { data:Uint8Array, algorithm:String } */
615
+ /** (optional) session keys in the form: { data:Uint8Array<ArrayBuffer>, algorithm:String } */
598
616
  sessionKeys?: MaybeArray<SessionKey>;
599
617
  /** (optional) array of public keys or single key, to verify signatures */
600
618
  verificationKeys?: MaybeArray<PublicKey>;
601
619
  /** (optional) whether data decryption should fail if the message is not signed with the provided publicKeys */
602
620
  expectSigned?: boolean;
603
- /** (optional) whether to return data as a string(Stream) or Uint8Array(Stream). If 'utf8' (the default), also normalize newlines. */
621
+ /** (optional) whether to return data as a string(Stream) or Uint8Array<ArrayBuffer>(Stream). If 'utf8' (the default), also normalize newlines. */
604
622
  format?: 'utf8' | 'binary';
605
623
  /** (optional) detached signature for verification */
606
624
  signature?: Signature;
@@ -628,7 +646,7 @@ export interface VerifyOptions {
628
646
  verificationKeys: MaybeArray<PublicKey>;
629
647
  /** (optional) whether verification should throw if the message is not signed with the provided publicKeys */
630
648
  expectSigned?: boolean;
631
- /** (optional) whether to return data as a string(Stream) or Uint8Array(Stream). If 'utf8' (the default), also normalize newlines. */
649
+ /** (optional) whether to return data as a string(Stream) or Uint8Array<ArrayBuffer>(Stream). If 'utf8' (the default), also normalize newlines. */
632
650
  format?: 'utf8' | 'binary';
633
651
  /** (optional) detached signature for verification */
634
652
  signature?: Signature;
@@ -648,7 +666,7 @@ export interface EncryptSessionKeyOptions extends SessionKey {
648
666
  config?: PartialConfig
649
667
  }
650
668
 
651
- interface SerializedKeyPair<T extends string | Uint8Array> {
669
+ interface SerializedKeyPair<T extends string | Uint8Array<ArrayBuffer>> {
652
670
  privateKey: T;
653
671
  publicKey: T;
654
672
  }
@@ -705,25 +723,25 @@ export function armor(messagetype: enums.armor, body: object, partindex?: number
705
723
  /**
706
724
  * DeArmor an OpenPGP armored message; verify the checksum and return the encoded bytes
707
725
  */
708
- export function unarmor(input: string, config?: Config): Promise<{ text: string, data: Stream<Uint8Array>, type: enums.armor }>;
726
+ export function unarmor(input: string, config?: Config): Promise<{ text: string, data: Stream<Uint8Array<ArrayBuffer>>, type: enums.armor }>;
709
727
 
710
728
  export declare class Argon2S2K {
711
729
  static reloadWasmModule(): void;
712
730
  static ARGON2_WASM_MEMORY_THRESHOLD_RELOAD: number;
713
731
  constructor(config: Config);
714
- salt: Uint8Array;
732
+ salt: Uint8Array<ArrayBuffer>;
715
733
  /** @throws Argon2OutOfMemoryError */
716
- produceKey(passphrase: string, keySize: number): Promise<Uint8Array>;
734
+ produceKey(passphrase: string, keySize: number): Promise<Uint8Array<ArrayBuffer>>;
717
735
  }
718
736
 
719
737
  interface KDFParamsData {
720
738
  version: number;
721
739
  hash: enums.hash;
722
740
  cipher: enums.symmetric;
723
- replacementFingerprint?: Uint8Array;
741
+ replacementFingerprint?: Uint8Array<ArrayBuffer>;
724
742
  }
725
743
 
726
744
  export class KDFParams {
727
745
  constructor(data: KDFParamsData);
728
- write(forReplacementParams?: boolean): Uint8Array;
746
+ write(forReplacementParams?: boolean): Uint8Array<ArrayBuffer>;
729
747
  }
@@ -0,0 +1,33 @@
1
+ import enums from '../enums';
2
+ export declare class GrammarError extends Error {
3
+ constructor(...params: any[]);
4
+ }
5
+ /**
6
+ * Implement OpenPGP message grammar based on: https://www.rfc-editor.org/rfc/rfc9580.html#section-10.3 .
7
+ * It is slightly more lenient as it also allows standalone ESK sequences, as well as empty (signed) messages.
8
+ * This latter case is needed to allow unknown packets.
9
+ * A new `MessageGrammarValidator` instance must be created for each packet sequence, as the instance is stateful:
10
+ * - `recordPacket` must be called for each packet in the sequence; the function will throw as soon as
11
+ * an invalid packet is detected.
12
+ * - `recordEnd` must be called at the end of the packet sequence to confirm its validity.
13
+ */
14
+ export declare class MessageGrammarValidator {
15
+ private state;
16
+ private leadingOnePassSignatureCounter;
17
+ /**
18
+ * Determine validity of the next packet in the sequence.
19
+ * NB: padding, marker and unknown packets are expected to already be filtered out on parsing,
20
+ * and are not accepted by `recordPacket`.
21
+ * @param packet - packet to validate
22
+ * @param additionalAllowedPackets - object containing packets which are allowed anywhere in the sequence, except they cannot precede a OPS packet
23
+ * @throws {GrammarError} on invalid `packet` input
24
+ */
25
+ recordPacket(packet: enums.packet, additionalAllowedPackets?: {
26
+ [key in enums.packet]: any;
27
+ }): void;
28
+ /**
29
+ * Signal end of the packet sequence for final validity check
30
+ * @throws {GrammarError} on invalid sequence
31
+ */
32
+ recordEnd(): void;
33
+ }