Linter: update to eslint v9

This eslint version brings breaking changes related to the eslint config.
eslint-airbnb-config has yet to release a compatible version with the
new format, and it generally looks unmaintained, hence we drop the dependency
in favor of the built-in recommended configs.
This commit is contained in:
larabr 2025-09-23 18:29:38 +02:00
parent 5a69043aad
commit d4bb70815b
No known key found for this signature in database
GPG Key ID: 2A4BEC40729185DD
30 changed files with 1044 additions and 1399 deletions

View File

@ -1,4 +0,0 @@
dist
test/lib/
test/typescript/
docs

View File

@ -1,146 +0,0 @@
module.exports = {
'extends': [
'airbnb-base',
'airbnb-typescript/base'
],
'parser': '@typescript-eslint/parser',
'parserOptions': {
'ecmaVersion': 11,
'sourceType': 'module',
'project': 'tsconfig.json'
},
'env': {
'browser': true,
'es6': true,
'node': true
},
'plugins': [
'@typescript-eslint',
'chai-friendly',
'import',
'unicorn'
],
'settings': {
'import/resolver': {
'typescript': {}
}
},
'globals': { // TODO are all these necessary?
'globalThis': true,
'console': true,
'Promise': true,
'importScripts': true,
'process': true,
'Event': true,
'describe': true,
'it': true,
'mocha': true,
'before': true,
'beforeEach': true,
'after': true,
'afterEach': true,
'escape': true,
'unescape': true,
'resolves': true,
'rejects': true,
'TransformStream': true,
'BigInt': true
},
'rules': {
'arrow-body-style': 'off',
'arrow-parens': ['error','as-needed'],
'class-methods-use-this': 'off',
'@typescript-eslint/comma-dangle': ['error', 'never'],
'@typescript-eslint/comma-spacing': 'off',
'consistent-return': 'off',
'default-case': 'off',
'@typescript-eslint/default-param-last': 'off',
'eol-last': ['error', 'always'],
'function-call-argument-newline': 'off',
'func-names': ['error', 'never'],
'function-paren-newline': 'off',
'global-require': 'off',
'key-spacing': 'off',
'keyword-spacing': 'error',
'max-classes-per-file': 'off',
'max-len': 'off',
'newline-per-chained-call': 'off',
'no-bitwise': 'off',
'no-continue': 'off',
'no-else-return': 'off',
'no-empty': ['error', { 'allowEmptyCatch': true }],
'no-multiple-empty-lines': ['error', { 'max': 2, 'maxEOF': 1, 'maxBOF':0 }],
'no-nested-ternary': 'off',
'no-param-reassign': 'off', // TODO get rid of this
'no-plusplus': 'off',
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
'object-curly-newline': 'off',
'@typescript-eslint/no-shadow': 'off', // TODO get rid of this
'object-property-newline': [
'error',
{
'allowMultiplePropertiesPerLine': true
}
],
'object-shorthand': 'off',
'operator-assignment': 'off',
'operator-linebreak': [
'error',
'after'
],
'padded-blocks': 'off',
'prefer-arrow-callback': 'off',
'prefer-destructuring': 'off',
'prefer-rest-params': 'off', // TODO get rid of this
'prefer-spread': 'off', // TODO get rid of this
'prefer-template': 'off',
'quote-props': 'off',
'quotes': ['error', 'single', { 'avoidEscape': true }],
'@typescript-eslint/space-before-function-paren': ['error', { 'anonymous': 'ignore', 'named': 'never', 'asyncArrow': 'always' }],
'spaced-comment': 'off',
'indent': 'off',
'@typescript-eslint/indent': ['error', 2, { 'SwitchCase': 1 }],
'no-unused-vars': 'off',
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_",
}
],
// eslint-plugin-import rules:
'import/named': 'error',
'import/extensions': 'off', // temporary: we use them in tests (ESM compliant), but not in the lib (to limit diff)
'import/first': 'off',
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true, 'optionalDependencies': false, 'peerDependencies': false }],
'import/no-unassigned-import': 'error',
'import/no-unresolved': 'error',
'import/prefer-default-export': 'off',
// Custom silencers:
'no-multi-assign': 'off',
'no-underscore-dangle': 'off',
'no-await-in-loop': 'off',
'camelcase': 'off', // snake_case used in tests, need to fix separately
'@typescript-eslint/naming-convention': 'off', // supersedes 'camelcase' rule
'@typescript-eslint/lines-between-class-members': 'off',
// Custom errors:
'@typescript-eslint/no-use-before-define': ['error', { 'functions': false, 'classes': true, 'variables': false, 'allowNamedExports': true }],
'no-constant-condition': [2, { 'checkLoops': false }],
'new-cap': [2, { 'properties': false, 'capIsNewExceptionPattern': 'EAX|OCB|GCM|CMAC|CBC|OMAC|CTR', 'newIsCapExceptionPattern': 'type|hash*' }],
'max-lines': [2, { 'max': 620, 'skipBlankLines': true, 'skipComments': true }],
'@typescript-eslint/no-unused-expressions': 0,
'chai-friendly/no-unused-expressions': [2, { 'allowShortCircuit': true }],
'unicorn/switch-case-braces': ['error', 'avoid'],
// Custom warnings:
'no-console': 1
}
};

155
eslint.config.js Normal file
View File

@ -0,0 +1,155 @@
// @ts-check
import eslint from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import tseslint from 'typescript-eslint';
import globals from 'globals';
// @ts-expect-error missing types
import pluginChaiFriendly from 'eslint-plugin-chai-friendly';
import pluginImport from 'eslint-plugin-import';
import pluginStylistic from '@stylistic/eslint-plugin';
// @ts-expect-error missing types
import pluginUnicorn from 'eslint-plugin-unicorn';
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
globalIgnores(['dist/', 'test/lib/', 'docs/', '.jsdocrc.cjs']),
{
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname
},
globals: {
...globals.browser,
...globals.nodeBuiltin,
...globals.mocha
}
},
settings: {
'import/resolver': {
typescript: { alwaysTryTypes: true }
}
},
plugins: {
'chai-friendly': pluginChaiFriendly,
'import': pluginImport,
'@stylistic': pluginStylistic,
'unicorn': pluginUnicorn
},
rules: {
'arrow-body-style': 'off',
'arrow-parens': ['error','as-needed'],
'class-methods-use-this': 'off', // TODO warn
'comma-dangle': ['error', 'never'],
'@typescript-eslint/comma-spacing': 'off',
'consistent-return': 'off',
'default-case': 'off',
'@typescript-eslint/default-param-last': 'off',
'eol-last': ['error', 'always'],
'function-call-argument-newline': 'off',
'func-names': ['error', 'never'],
'function-paren-newline': 'off',
'global-require': 'off',
'key-spacing': 'off',
'keyword-spacing': 'error',
'max-classes-per-file': 'off',
'max-len': 'off',
'newline-per-chained-call': 'off',
'no-bitwise': 'off',
'no-continue': 'off',
'no-else-return': 'off',
'no-empty': ['error', { 'allowEmptyCatch': true }],
'no-multiple-empty-lines': ['error', { 'max': 2, 'maxEOF': 1, 'maxBOF':0 }],
'no-nested-ternary': 'off', // TODO warn
'no-param-reassign': 'off', // TODO get rid of this
'no-plusplus': 'off',
'no-restricted-syntax': ['error', 'ForInStatement', 'LabeledStatement', 'WithStatement'],
'object-curly-newline': 'off',
'@typescript-eslint/no-shadow': 'off', // TODO get rid of this
'object-property-newline': [
'error',
{
'allowMultiplePropertiesPerLine': true
}
],
'object-shorthand': 'off',
'operator-assignment': 'off',
'operator-linebreak': [
'error',
'after'
],
'padded-blocks': 'off',
'prefer-arrow-callback': 'off',
'prefer-destructuring': 'off',
'prefer-rest-params': 'off', // TODO get rid of this
'prefer-spread': 'off', // TODO get rid of this
'prefer-template': 'off',
'quote-props': 'off',
'quotes': ['error', 'single', { 'avoidEscape': true }],
'spaced-comment': 'off',
'indent': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
'argsIgnorePattern': '^_'
}
],
// eslint-plugin-import rules:
'import/named': 'error',
'import/extensions': 'off', // temporary: we use them in tests (ESM compliant), but not in the lib (to limit diff)
'import/first': 'off',
'import/no-extraneous-dependencies': ['error', { 'devDependencies': true, 'optionalDependencies': false, 'peerDependencies': false }],
'import/no-unassigned-import': 'error',
'import/no-unresolved': 'error',
'import/prefer-default-export': 'off',
'import/newline-after-import': 'error',
// Custom silencers:
'no-multi-assign': 'off',
'no-underscore-dangle': 'off',
'no-await-in-loop': 'off',
'camelcase': 'off', // snake_case used in tests, need to fix separately
'@typescript-eslint/naming-convention': 'off', // supersedes 'camelcase' rule
'@typescript-eslint/lines-between-class-members': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-this-alias': 'off',
// Custom errors:
'@typescript-eslint/no-use-before-define': ['error', { 'functions': false, 'classes': true, 'variables': false, 'allowNamedExports': true }],
'no-constant-condition': [2, { 'checkLoops': false }],
'new-cap': ['error', {
properties: false,
newIsCap: true,
newIsCapExceptions: [],
capIsNew: false
}],
'max-lines': [2, { 'max': 620, 'skipBlankLines': true, 'skipComments': true }],
'@typescript-eslint/no-unused-expressions': 'off',
'chai-friendly/no-unused-expressions': ['error', { 'allowShortCircuit': true }],
'@typescript-eslint/no-empty-object-type': ['error', { allowInterfaces: 'with-single-extends' }],
'@stylistic/indent': ['error', 2, { 'SwitchCase': 1 }],
'@stylistic/quotes': ['error', 'single', { avoidEscape: true }],
'@stylistic/space-before-function-paren': ['error', { 'anonymous': 'ignore', 'named': 'never', 'asyncArrow': 'always' }],
'@stylistic/no-mixed-operators': ['error', {
allowSamePrecedence: true,
groups: [
['==', '!=', '===', '!==', '>', '>=', '<', '<='],
['&&', '||']
]
}],
'@stylistic/no-mixed-spaces-and-tabs': 'error',
'@stylistic/eol-last': 'error',
'@stylistic/no-trailing-spaces': 'error',
'@stylistic/no-tabs': 'error',
'unicorn/switch-case-braces': ['error', 'avoid'],
'no-console': 'warn',
'no-process-exit': 'error'
}
}
);

4
openpgp.d.ts vendored
View File

@ -1,4 +1,4 @@
/* eslint-disable max-lines, @typescript-eslint/indent */
/* eslint-disable @stylistic/indent */
/**
* Type definitions for OpenPGP.js http://openpgpjs.org/
@ -411,7 +411,7 @@ 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>;
private crypt(fn: (block: Uint8Array) => Uint8Array, sessionKey: Uint8Array, data: MaybeStream<Uint8Array>): MaybeStream<Uint8Array>;
}
export class PublicKeyEncryptedSessionKeyPacket extends BasePacket {

1649
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -63,6 +63,7 @@
"postversion": "git push --follow-tags && npm publish"
},
"devDependencies": {
"@eslint/js": "^9.36.0",
"@noble/ciphers": "^1.3.0",
"@noble/curves": "^1.9.6",
"@noble/hashes": "^1.8.0",
@ -77,10 +78,10 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.4",
"@rollup/plugin-wasm": "^6.2.2",
"@stylistic/eslint-plugin": "^5.4.0",
"@types/chai": "^4.3.20",
"@types/node": "^24.3.1",
"@types/sinon": "^17.0.4",
"@typescript-eslint/parser": "^7.18.0",
"@web/test-runner": "^0.19.0",
"@web/test-runner-browserstack": "^0.8.0",
"@web/test-runner-mocha": "^0.9.0",
@ -92,21 +93,20 @@
"chai": "^4.5.0",
"chai-as-promised": "^8.0.1",
"eckey-utils": "^0.7.14",
"eslint": "^8.57.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-import-resolver-typescript": "^3.10.1",
"eslint-plugin-chai-friendly": "^0.7.4",
"eslint": "^9.36.0",
"eslint-import-resolver-typescript": "^4.4.4",
"eslint-plugin-chai-friendly": "^1.1.0",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-unicorn": "^48.0.1",
"fflate": "^0.8.2",
"globals": "^16.4.0",
"mocha": "^11.7.1",
"playwright": "^1.56.0",
"rollup": "^4.48.1",
"sinon": "^21.0.0",
"tsx": "^4.20.5",
"typescript": "^5.9.2",
"typescript-eslint": "^8.44.1",
"web-streams-polyfill": "^4.2.0"
},
"overrides": {

View File

@ -1,5 +1,3 @@
/* eslint-disable no-process-env */
import { builtinModules } from 'module';
import { readFileSync } from 'fs';

View File

@ -189,7 +189,7 @@ function verifyHeaders(headers, packetlist) {
.map(hashName => {
try {
return enums.write(enums.hash, hashName.toLowerCase());
} catch (e) {
} catch {
throw new Error('Unknown hash algorithm in armor header: ' + hashName.toLowerCase());
}
});

View File

@ -458,7 +458,7 @@ export function generateSessionKey(algo) {
function checkSupportedCurve(oid) {
try {
oid.getName();
} catch (e) {
} catch {
throw new UnsupportedError('Unknown curve OID');
}
}

View File

@ -88,7 +88,7 @@ export async function validateParams(algo, A, k) {
const recomputedSharedSecret = await recomputeSharedSecret(algo, ephemeralPublicKey, A, k);
return util.equalsUint8Array(sharedSecret, recomputedSharedSecret);
} catch (_) {
} catch {
return false;
}

View File

@ -161,7 +161,7 @@ export async function validateParams(oid, Q, d) {
const signature = await sign(oid, hashAlgo, message, Q, d, hashed);
// eslint-disable-next-line @typescript-eslint/return-await
return await verify(oid, hashAlgo, signature, message, Q, hashed);
} catch (err) {
} catch {
return false;
}
}
@ -284,7 +284,7 @@ async function nodeVerify(curve, hashAlgo, { r, s }, message, publicKey) {
try {
return verify.verify({ key: derPublicKey, format: 'der', type: 'spki', dsaEncoding: 'ieee-p1363' }, signature);
} catch (err) {
} catch {
return false;
}
}

View File

@ -143,7 +143,7 @@ class CurveWithOID {
this.name = oidOrName instanceof OID ?
oidOrName.getName() :
enums.write(enums.curve,oidOrName);
} catch (err) {
} catch {
throw new UnsupportedError('Unknown curve');
}
const params = curves[this.name];

View File

@ -333,7 +333,7 @@ async function nodeVerify(hashAlgo, data, s, n, e) {
try {
return verify.verify(key, s);
} catch (err) {
} catch {
return false;
}
}
@ -361,7 +361,7 @@ async function nodeDecrypt(data, n, e, d, p, q, u) {
try {
return new Uint8Array(nodeCrypto.privateDecrypt(key, data));
} catch (err) {
} catch {
throw new Error('Decryption error');
}
}

1
src/enums.d.ts vendored
View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
declare namespace enums {
export function read(type: typeof armor, e: armor): armorNames;
export function read(type: typeof compression, e: compression): compressionNames;

View File

@ -357,7 +357,7 @@ export async function isDataRevoked(primaryKey, signatureType, dataToVerify, rev
// TODO get an identifier of the revoked object instead
revocationKeyIDs.push(revocationSignature.issuerKeyID);
}
} catch (e) {}
} catch {}
}));
// TODO further verify that this is the signature that should be revoked
if (signature) {
@ -398,7 +398,7 @@ export function sanitizeKeyOptions(options, subkeyDefaults = {}) {
case 'ecc': // NB: this case also handles legacy eddsa and x25519 keys, based on `options.curve`
try {
options.curve = enums.write(enums.curve, options.curve);
} catch (e) {
} catch {
throw new Error('Unknown curve');
}
if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy ||

View File

@ -442,7 +442,7 @@ class Key {
} else {
primaryKeyExpiry = selfSigKeyExpiry < selfSigExpiry ? selfSigKeyExpiry : selfSigExpiry;
}
} catch (e) {
} catch {
primaryKeyExpiry = null;
}
@ -510,7 +510,7 @@ class Key {
}
}
if (!users.length) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw exception || new Error('Could not find primary user');
}
await Promise.all(users.map(async function (a) {
@ -751,8 +751,7 @@ class Key {
}
['getKeyID', 'getFingerprint', 'getAlgorithmInfo', 'getCreationTime', 'hasSameFingerprintAs'].forEach(name => {
Key.prototype[name] =
Subkey.prototype[name];
Key.prototype[name] = Subkey.prototype[name];
});
export default Key;

View File

@ -114,7 +114,7 @@ class PrivateKey extends PublicKey {
}
if (keys.length === 0) {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw exception || new Error('No decryption key packets found');
}

View File

@ -112,7 +112,7 @@ class Subkey {
let bindingSignature;
try {
bindingSignature = await helper.getLatestValidSignature(this.bindingSignatures, primaryKey, enums.signature.subkeyBinding, dataToVerify, date, config);
} catch (e) {
} catch {
return null;
}
const keyExpiry = helper.getKeyExpirationTime(this.keyPacket, bindingSignature);
@ -153,7 +153,7 @@ class Subkey {
try {
await srcBindSig.verify(primaryKey, enums.signature.subkeyBinding, dataToVerify, date, undefined, config);
return true;
} catch (e) {
} catch {
return false;
}
});

View File

@ -222,7 +222,7 @@ class User {
try {
await srcSelfSig.verify(primaryKey, enums.signature.certGeneric, dataToVerify, date, false, config);
return true;
} catch (e) {
} catch {
return false;
}
});

View File

@ -220,7 +220,7 @@ export class Message {
if (selfCertification.preferredSymmetricAlgorithms) {
algos = algos.concat(selfCertification.preferredSymmetricAlgorithms);
}
} catch (e) {}
} catch {}
await Promise.all(decryptionKeyPackets.map(async function(decryptionKeyPacket) {
if (!decryptionKeyPacket.isDecrypted()) {
@ -460,7 +460,7 @@ export class Message {
try {
await keyPacket.decrypt(password);
return 1;
} catch (e) {
} catch {
return 0;
}
};

View File

@ -26,7 +26,7 @@ export function newPacketFromTag(tag, allowedPackets) {
let packetType;
try {
packetType = enums.read(enums.packet, tag);
} catch (e) {
} catch {
throw new UnknownPacketError(`Unknown packet type with tag: ${tag}`);
}
throw new Error(`Packet not allowed in this context: ${packetType}`);
@ -174,7 +174,7 @@ class PacketList extends Array {
// in case there's an MDC error, which should take precedence.
if (unauthenticatedError) {
await reader.readToEnd();
// eslint-disable-next-line @typescript-eslint/no-throw-literal
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw unauthenticatedError;
}

View File

@ -481,7 +481,7 @@ class SecretKeyPacket extends PublicKeyPacket {
try {
const { privateParams } = parsePrivateKeyParams(this.algorithm, cleartext, this.publicParams);
this.privateParams = privateParams;
} catch (err) {
} catch {
throw new Error('Error reading MPIs');
}
this.isEncrypted = false;
@ -515,7 +515,7 @@ class SecretKeyPacket extends PublicKeyPacket {
try {
// this can throw if some parameters are undefined
validParams = await validateParams(this.algorithm, this.publicParams, this.privateParams);
} catch (_) {
} catch {
validParams = false;
}
if (!validParams) {

View File

@ -30,7 +30,7 @@ import defaultConfig from './config';
const debugMode = (() => {
try {
return process.env.NODE_ENV === 'development'; // eslint-disable-line no-process-env
} catch (e) {}
} catch {}
return false;
})();
@ -606,7 +606,7 @@ const util = {
try {
error.message += ': ' + cause.message;
error.cause = cause;
} catch (e) {}
} catch {}
return error;
}
return new Error(error + ': ' + cause.message, { cause });

View File

@ -1,4 +1,7 @@
/* global require */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable no-console */
import assert from 'assert';
import path from 'path';
import { writeFileSync, unlinkSync } from 'fs';

View File

@ -1016,8 +1016,7 @@ export default () => describe('Packet', function() {
});
it('Reading signersUserID from armored signature', async function() {
const armoredSignature =
`-----BEGIN PGP SIGNATURE-----
const armoredSignature = `-----BEGIN PGP SIGNATURE-----
iQFKBAEBCgA0FiEEdOyNPagqedqiXfEMa6Ve2Dq64bsFAlszXwQWHHRlc3Qtd2tk
QG1ldGFjb2RlLmJpegAKCRBrpV7YOrrhuw1PB/9KhFRR/M3OR6NmIent6ri1ekWn
@ -1035,8 +1034,7 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu
});
it('Reading notations from armored key', async function() {
const pubkey =
`-----BEGIN PGP PUBLIC KEY BLOCK-----
const pubkey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
mQENBFzQOToBCADd0Pwh8edZ6gR3x49L1PaBPtiAQUr1QDUDWeNes8co5MTFl5hG
lHzptt+VD0JGucuIkvi34f5z2ZbInAV/xYDX3kSYefy6LB8XJD527I/o9bqY1P7T

View File

@ -61,7 +61,7 @@ async function makeKeyValid() {
encryptionKeys: k
});
return false;
} catch (e) {
} catch {
return true;
}
}

View File

@ -16,7 +16,7 @@ import {
encrypt, decrypt, sign, verify, config, enums,
generateSessionKey, encryptSessionKey, decryptSessionKeys,
LiteralDataPacket, PacketList, CompressedDataPacket, PublicKeyPacket, PublicSubkeyPacket, SecretKeyPacket, SecretSubkeyPacket, CleartextMessage,
WebStream, NodeWebStream,
WebStream, NodeWebStream
} from 'openpgp';
(async () => {
@ -47,7 +47,7 @@ import {
const parsedBinaryPrivateKey: PrivateKey = await readPrivateKey({ binaryKey: privateKeyBinary });
expect(parsedBinaryPrivateKey.isPrivate()).to.be.true;
// a generic Key can be directly used as PublicKey, since both classes have the same properties
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const unusedPublicKey: PublicKey = parsedKey;
// Check PrivateKey type inference
@ -55,23 +55,23 @@ import {
expect(parsedKey.isDecrypted()).to.be.true;
} else {
// @ts-expect-error isDecrypted is not defined for public keys
try { parsedKey.isDecrypted(); } catch (e) {}
try { parsedKey.isDecrypted(); } catch {}
}
(await privateKey.update(privateKey)).isDecrypted();
(await privateKey.toPublic().update(privateKey)).isDecrypted();
// @ts-expect-error isDecrypted is not defined for public keys
try { (await privateKey.toPublic().update(privateKey.toPublic())).isDecrypted(); } catch (e) {}
try { (await privateKey.toPublic().update(privateKey.toPublic())).isDecrypted(); } catch {}
// Revoke keys
await revokeKey({ key: privateKey });
// @ts-expect-error for missing revocation certificate
try { await revokeKey({ key: publicKey }); } catch (e) {}
try { await revokeKey({ key: publicKey }); } catch {}
const { privateKey: revokedPrivateKey, publicKey: revokedPublicKey } = await revokeKey({ key: privateKey, revocationCertificate, format: 'object' });
expect(revokedPrivateKey).to.be.instanceOf(PrivateKey);
expect(revokedPublicKey).to.be.instanceOf(PublicKey);
const revokedKeyPair = await revokeKey({ key: publicKey, revocationCertificate, format: 'object' });
// @ts-expect-error for null private key
try { revokedKeyPair.privateKey.armor(); } catch (e) {}
try { revokedKeyPair.privateKey.armor(); } catch {}
expect(revokedKeyPair.privateKey).to.be.null;
expect(revokedKeyPair.publicKey).to.be.instanceOf(PublicKey);
@ -123,16 +123,16 @@ import {
const verifiedCleartextData: string = verificationResult.data;
expect(verifiedCleartextData).to.equal(cleartextMessage.getText());
// @ts-expect-error Binary output not available for cleartext messages
try { await verify({ message: cleartextMessage, verificationKeys: publicKey, format: 'binary' }) } catch (e) {}
try { await verify({ message: cleartextMessage, verificationKeys: publicKey, format: 'binary' }) } catch {}
const clearSignedArmor = await sign({ signingKeys: privateKeys, message: cleartextMessage });
expect(clearSignedArmor).to.include('-----BEGIN PGP SIGNED MESSAGE-----');
const clearSignedObject: CleartextMessage = await sign({ signingKeys: privateKeys, message: cleartextMessage, format: 'object' });
expect(clearSignedObject).to.be.instanceOf(CleartextMessage);
// @ts-expect-error PublicKey not assignable to PrivateKey
try { await sign({ signingKeys: publicKeys, message: cleartextMessage }); } catch (e) {}
try { await sign({ signingKeys: publicKeys, message: cleartextMessage }); } catch {}
// @ts-expect-error Key not assignable to PrivateKey
try { await sign({ signingKeys: parsedKey, message: cleartextMessage }); } catch (e) {}
try { await sign({ signingKeys: parsedKey, message: cleartextMessage }); } catch {}
// Sign text message (armored)
const textSignedArmor: string = await sign({ signingKeys: privateKeys, message: textMessage });
@ -147,7 +147,10 @@ import {
expect(textSignedObject).to.be.instanceOf(Message);
// Sign text message (armored)
const textSignedWithNotations: string = await sign({ signingKeys: privateKeys, message: textMessage, signatureNotations: [{
const textSignedWithNotations: string = await sign({
signingKeys: privateKeys,
message: textMessage,
signatureNotations: [{
name: 'test@example.org',
value: new TextEncoder().encode('test'),
humanReadable: true,
@ -176,7 +179,7 @@ import {
// @ts-expect-error for unsafe downcasting
packets.map((packet: LiteralDataPacket) => packet.getText());
// @ts-expect-error for non-packet element
try { new PacketList().push(1); } catch (e) {}
try { new PacketList().push(1); } catch {}
// Packetlist of specific type
const literalPackets = new PacketList<LiteralDataPacket>();
@ -216,7 +219,7 @@ import {
const nodeTextStream = NodeNativeReadableStream.toWeb(createReadStream('non-existent-file', { encoding: 'utf8' }));
const messageFromNodeTextStream = await createMessage({ text: nodeTextStream });
(await encrypt({ message: messageFromNodeTextStream, passwords: 'password', format: 'armored' })) as NodeWebStream<string>;
} catch (err) {}
} catch {}
const webTextStream = new WebReadableStream<string>();
const messageFromWebTextStream = await createMessage({ text: webTextStream });
(await encrypt({ message: messageFromWebTextStream, passwords: 'password', format: 'armored' })) as WebStream<string>;
@ -228,7 +231,7 @@ import {
const nodeBinaryStream = NodeNativeReadableStream.toWeb(createReadStream('non-existent-file'));
const messageFromNodeBinaryStream = await createMessage({ binary: nodeBinaryStream });
(await encrypt({ message: messageFromNodeBinaryStream, passwords: 'password', format: 'binary' })) as NodeWebStream<Uint8Array>;
} catch (err) {}
} catch {}
const webBinaryStream = new WebReadableStream<Uint8Array>();
const messageFromWebBinaryStream = await createMessage({ binary: webBinaryStream });
(await encrypt({ message: messageFromWebBinaryStream, passwords: 'password', format: 'binary' })) as WebStream<Uint8Array>;
@ -239,5 +242,6 @@ import {
})().catch(e => {
console.error('TypeScript definitions tests failed by throwing the following error');
console.error(e);
// eslint-disable-next-line no-process-exit
process.exit(1);
});

View File

@ -54,7 +54,7 @@ describe('Unit Tests', function () {
openpgp.config[key] = decodeURIComponent(value);
try {
openpgp.config[key] = window.eval(openpgp.config[key]); // eslint-disable-line no-eval
} catch (e) {}
} catch {}
}
});
} else {

View File

@ -1,4 +1,4 @@
/* globals openpgp */
/* globals openpgp, importScripts */
importScripts('../../dist/openpgp.js');