diff --git a/conf/tsconfig.content_scripts.json b/conf/tsconfig.content_scripts.json index 1468797db9a..5b9e4689928 100644 --- a/conf/tsconfig.content_scripts.json +++ b/conf/tsconfig.content_scripts.json @@ -13,6 +13,7 @@ "strictFunctionTypes": false, "sourceMap": false, "checkJs": false, + "moduleResolution": "node", "outDir": "../build/_/content_scripts", "baseUrl": "../extension", "paths": { diff --git a/extension/js/common/core/crypto/pgp/msg-util.ts b/extension/js/common/core/crypto/pgp/msg-util.ts index c724b57b471..eb72dd725b3 100644 --- a/extension/js/common/core/crypto/pgp/msg-util.ts +++ b/extension/js/common/core/crypto/pgp/msg-util.ts @@ -5,7 +5,7 @@ import { Key, KeyInfoWithIdentity, KeyInfoWithIdentityAndOptionalPp, KeyUtil } f import { ReplaceableMsgBlockType } from '../../msg-block.js'; import { Buf } from '../../buf.js'; import { PgpArmor, PreparedForDecrypt } from './pgp-armor.js'; -import { opgp } from './openpgpjs-custom.js'; +import { OpenPGPDataType, opgp } from './openpgpjs-custom.js'; import type * as OpenPGP from 'openpgp'; import { KeyCache } from '../../../platform/key-cache.js'; import { SmimeKey, SmimeMsg } from '../smime/smime-key.js'; @@ -331,7 +331,7 @@ export class MsgUtil { return true; } - private static async getSortedKeys(kiWithPp: KeyInfoWithIdentityAndOptionalPp[], msg: OpenPGP.Message): Promise { + private static async getSortedKeys(kiWithPp: KeyInfoWithIdentityAndOptionalPp[], msg: OpenPGP.Message): Promise { const keys: SortedKeysForDecrypt = { encryptedFor: [], signedBy: [], diff --git a/extension/js/common/core/crypto/pgp/openpgp-key.ts b/extension/js/common/core/crypto/pgp/openpgp-key.ts index 9b2e41af415..bb3285756a3 100644 --- a/extension/js/common/core/crypto/pgp/openpgp-key.ts +++ b/extension/js/common/core/crypto/pgp/openpgp-key.ts @@ -1,6 +1,6 @@ /* ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com */ import { Key, PrvPacket, KeyAlgo, KeyUtil, UnexpectedKeyTypeError, PubkeyInfo } from '../key.js'; -import { opgp } from './openpgpjs-custom.js'; +import { OpenPGPDataType, opgp } from './openpgpjs-custom.js'; import { Catch } from '../../../platform/catch.js'; import { Str, Value } from '../../common.js'; import { Buf } from '../../buf.js'; @@ -8,7 +8,7 @@ import type * as OpenPGP from 'openpgp'; import { PgpMsgMethod, VerifyRes } from './msg-util.js'; import * as Stream from '@openpgp/web-stream-tools'; -type OpenpgpMsgOrCleartext = OpenPGP.Message | OpenPGP.CleartextMessage; +type OpenpgpMsgOrCleartext = OpenPGP.Message | OpenPGP.CleartextMessage; export interface KeyWithPrivateFields extends Key { internal: OpenPGP.Key | string; // usable key without weak packets rawArmored: string; @@ -117,7 +117,7 @@ export class OpenPGPKey { await OpenPGPKey.convertExternalLibraryObjToKey(encryptedPrv, key); } - public static async decryptMessage(message: OpenPGP.Message, privateKeys: Key[], passwords?: string[]) { + public static async decryptMessage(message: OpenPGP.Message, privateKeys: Key[], passwords?: string[]) { const opgpKeys = await Promise.all(privateKeys.map(key => OpenPGPKey.extractExternalLibraryObjFromKey(key))); return await message.decrypt( opgpKeys.filter(key => key.isPrivate()), @@ -477,12 +477,6 @@ export class OpenPGPKey { return p instanceof opgp.SecretKeyPacket || p instanceof opgp.SecretSubkeyPacket; } - public static isBaseKeyPacket(p: OpenPGP.BasePacket): p is OpenPGP.BasePublicKeyPacket { - return ( - p instanceof opgp.SecretKeyPacket || p instanceof opgp.SecretSubkeyPacket || p instanceof opgp.PublicKeyPacket || p instanceof opgp.PublicSubkeyPacket - ); - } - public static async isPacketDecrypted(pubkey: Key, keyid: OpenPGP.KeyID) { const [k] = (await OpenPGPKey.extractExternalLibraryObjFromKey(pubkey)).getKeys(keyid); // keyPacket.isDecrypted(keyID); if (!k) { @@ -577,7 +571,7 @@ export class OpenPGPKey { // mimicks OpenPGP.helper.getLatestValidSignature private static async getLatestValidSignature( signatures: OpenPGP.SignaturePacket[], - primaryKey: OpenPGP.BasePublicKeyPacket, + primaryKey: OpenPGP.AnyKeyPacket, signatureType: OpenPGP.enums.signature, dataToVerify: object | Uint8Array ): Promise { @@ -801,7 +795,7 @@ export class OpenPGPKey { } return undefined; } - private static arePrivateParamsMissing = (packet: OpenPGP.BasePublicKeyPacket): boolean => { + private static arePrivateParamsMissing = (packet: OpenPGP.AnyKeyPacket): boolean => { // detection of missing private params to solve #2887 if (!OpenPGPKey.paramCountByAlgo) { OpenPGPKey.paramCountByAlgo = { diff --git a/extension/js/common/core/crypto/pgp/openpgpjs-custom.ts b/extension/js/common/core/crypto/pgp/openpgpjs-custom.ts index c499d4ba704..d0f2b99747d 100644 --- a/extension/js/common/core/crypto/pgp/openpgpjs-custom.ts +++ b/extension/js/common/core/crypto/pgp/openpgpjs-custom.ts @@ -7,6 +7,8 @@ import { requireOpenpgp } from '../../../platform/require.js'; export const opgp = requireOpenpgp(); +export type OpenPGPDataType = string | Uint8Array; + if (typeof opgp !== 'undefined') { // in certain environments, eg pgp_block.htm or web content script, openpgp is not included opgp.config.versionString = `FlowCrypt Email Encryption ${VERSION}`; diff --git a/extension/js/common/core/crypto/pgp/pgp-armor.ts b/extension/js/common/core/crypto/pgp/pgp-armor.ts index 5dd76d20d04..d885f4cb73f 100644 --- a/extension/js/common/core/crypto/pgp/pgp-armor.ts +++ b/extension/js/common/core/crypto/pgp/pgp-armor.ts @@ -8,7 +8,7 @@ import { Buf } from '../../buf.js'; import { ReplaceableMsgBlockType } from '../../msg-block.js'; import { Str } from '../../common.js'; import type * as OpenPGP from 'openpgp'; -import { opgp } from './openpgpjs-custom.js'; +import { OpenPGPDataType, opgp } from './openpgpjs-custom.js'; import * as Stream from '@openpgp/web-stream-tools'; import { SmimeKey, ENVELOPED_DATA_OID } from '../smime/smime-key.js'; @@ -17,9 +17,9 @@ export type PreparedForDecrypt = isArmored: boolean; isCleartext: true; isPkcs7: false; - message: OpenPGP.CleartextMessage | OpenPGP.Message; + message: OpenPGP.CleartextMessage | OpenPGP.Message; } - | { isArmored: boolean; isCleartext: false; isPkcs7: false; message: OpenPGP.Message } + | { isArmored: boolean; isCleartext: false; isPkcs7: false; message: OpenPGP.Message } | { isArmored: boolean; isCleartext: false; isPkcs7: true; message: forge.pkcs7.PkcsEnvelopedData }; type CryptoArmorHeaderDefinitions = { diff --git a/package-lock.json b/package-lock.json index d881c04bc5a..756da837c17 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,7 +55,7 @@ "lint-staged": "^16.1.2", "mailparser": "3.7.4", "mkdirp": "3.0.1", - "openpgp": "6.1.1", + "openpgp": "6.2.0", "pdfjs-dist": "5.3.93", "prettier": "^3.6.2", "puppeteer": "24.14.0", @@ -7436,9 +7436,9 @@ } }, "node_modules/openpgp": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/openpgp/-/openpgp-6.1.1.tgz", - "integrity": "sha512-V/DXZ5AGCz3q4X8psUSc3q4SxnH/bfICaTSpNcla7wvBFhrxa9/ajm31rtMwZ1qj7Fu2oMpfX6ZcxKmTBlb6Yg==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/openpgp/-/openpgp-6.2.0.tgz", + "integrity": "sha512-zKbgazxMeGrTqUEWicKufbdcjv2E0om3YVxw+I3hRykp8ODp+yQOJIDqIr1UXJjP8vR2fky3bNQwYoQXyFkYMA==", "dev": true, "license": "LGPL-3.0+", "engines": { diff --git a/package.json b/package.json index 09f142fc294..be3d9471734 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "lint-staged": "^16.1.2", "mailparser": "3.7.4", "mkdirp": "3.0.1", - "openpgp": "6.1.1", + "openpgp": "6.2.0", "pdfjs-dist": "5.3.93", "prettier": "^3.6.2", "puppeteer": "24.14.0", diff --git a/tsconfig.json b/tsconfig.json index 66f5583ef74..1794e135b6a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,6 +13,7 @@ "useUnknownInCatchVariables": false, "outDir": "build/generic-extension-wip", "baseUrl": "./extension", + "moduleResolution": "node", "paths": { "jquery": ["lib/jquery.min.js", "COMMENT"], "sweetalert2": ["lib/sweetalert2.js", "COMMENT"],