I am trying to use openpgp.js in CloudFlare worker.
It fails with Object.getOwnPropertyDescriptors.
As suggested here, it might indicate a bug in CloudFlare runtime's Object.getOwnPropertyDescriptors implementation.
- OpenPGP.js version: 6.1.0
- Affected platform: CloudFlare Workers edge runtime (with nodejs compatibility flag)
- "wrangler": "^4.4.0"
The library do not work on some edge runtimes as internally it tries to clone streams in unsafe manner. Due to rising popularity of such runtimes it might be worth fixing.
Sample code:
export async function sign(
url: string,
privateKeyArmored: string,
passphrase: string,
) {
const response = await fetch(url);
if (!response.ok || !response.body) {
throw new Error(`Fetch failed: ${response.status}`);
}
const privateKey = await openpgp.decryptKey({
privateKey: await openpgp.readPrivateKey({ armoredKey: privateKeyArmored }),
passphrase,
});
const message = await openpgp.createMessage({ binary: response.body });
const signature = await openpgp.sign({
message,
signingKeys: privateKey,
});
return { signature };
Throws such an error
✘ [ERROR] TypeError: Illegal invocation: function called with incorrect `this` reference. See https://developers.cloudflare.com/workers/observability/errors/#illegal-invocation-errors for details.
at Object.getOwnPropertyDescriptors (<anonymous>)
at overwrite
(file:///Users/xxx/myapp/node_modules/openpgp/node_modules/@openpgp/web-stream-tools/lib/streams.js:417:25)
at streamClone
(file:///Users/xxx/myapp/node_modules/openpgp/node_modules/@openpgp/web-stream-tools/lib/streams.js:360:5)
at _Ba.notations [as sign]
(file:///Users/xxx/myapp/node_modules/openpgp/src/packet/signature.js:258:40)
at async fo
(file:///Users/xxx/myapp/node_modules/openpgp/src/key/helper.js:284:38)
at async Promise.all (index 0)
at signaturePackets
(file:///Users/xxx/myapp/node_modules/openpgp/src/message.js:737:3)
at async _Ho.config [as sign]
(file:///Users/xxx/myapp/node_modules/openpgp/src/message.js:518:11)
at async nc
(file:///Users/xxx/myapp/node_modules/openpgp/src/openpgp.js:428:160)
at async processPackage
(file:///Users/xxx/myapp/src/example.ts:25:21)
wrangler.jsonc
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "xxx-worker",
"main": "src/index.ts",
"compatibility_date": "2025-04-30",
"compatibility_flags": ["nodejs_compat"],
"d1_databases": [
{
"binding": "DB",
"database_name": "xxx",
"database_id": "12341234-0a07-4731-b0ce-123412341234",
},
],
}
I am trying to use openpgp.js in CloudFlare worker.
It fails with Object.getOwnPropertyDescriptors.
As suggested here, it might indicate a bug in CloudFlare runtime's Object.getOwnPropertyDescriptors implementation.
The library do not work on some edge runtimes as internally it tries to clone streams in unsafe manner. Due to rising popularity of such runtimes it might be worth fixing.
Sample code:
Throws such an error
wrangler.jsonc