From 1e11591d16118c79bd26ed52b394f9278f2c77c3 Mon Sep 17 00:00:00 2001 From: Florian Kleber Date: Sat, 28 Jun 2025 19:58:31 +0200 Subject: [PATCH 1/3] feat(auth): patch pylon to avoid createSign --- package.json | 10 ++++++---- patches/@getcronit+pylon+2.0.0.patch | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 patches/@getcronit+pylon+2.0.0.patch diff --git a/package.json b/package.json index 37135b4..47c751d 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "deploy": "pylon build && wrangler deploy", "dev": "pylon dev -c \"wrangler dev --port 3000\" --client --client-port 3000 --client-path ./clients/jaen-agent/index.ts", "cf-typegen": "wrangler types", - "start": "wrangler dev", - "test": "vitest", - "build": "tsc", - "migrate:deploy": "./scripts/migrate.sh prod", + "start": "wrangler dev", + "test": "vitest", + "build": "tsc", + "postinstall": "patch-package", + "migrate:deploy": "./scripts/migrate.sh prod", "migrate:reset": "./scripts/migrate.sh reset", "migrate:seed": "./scripts/migrate.sh seed dev", "migrate:status": "./scripts/migrate.sh status", @@ -40,6 +41,7 @@ "prisma": "^6.9.0", "typescript": "^5.6.3", "wrangler": "^3.60.3" + ,"patch-package": "^8.0.0" }, "repository": { "type": "git", diff --git a/patches/@getcronit+pylon+2.0.0.patch b/patches/@getcronit+pylon+2.0.0.patch new file mode 100644 index 0000000..ccf9db1 --- /dev/null +++ b/patches/@getcronit+pylon+2.0.0.patch @@ -0,0 +1,24 @@ +*** Begin Patch +*** Update File: node_modules/@getcronit/pylon/auth.js +@@ +- const sign = crypto.createSign('RSA-SHA256'); +- sign.update(payload); +- return sign.sign(privateKey, 'base64'); ++ // Cloudflare Workers do not support crypto.createSign. ++ // Use WebCrypto to sign instead. ++ const encoder = new TextEncoder(); ++ const key = await crypto.subtle.importKey( ++ 'pkcs8', ++ typeof privateKey === 'string' ? Buffer.from(privateKey, 'base64') : privateKey, ++ { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, ++ false, ++ ['sign'] ++ ); ++ const signature = await crypto.subtle.sign( ++ 'RSASSA-PKCS1-v1_5', ++ key, ++ encoder.encode(payload) ++ ); ++ return Buffer.from(signature).toString('base64'); + } +*** End Patch From d936eceee5e6d1e0bff9f7d16c86174d13bed082 Mon Sep 17 00:00:00 2001 From: Florian Kleber Date: Sat, 28 Jun 2025 20:03:12 +0200 Subject: [PATCH 2/3] Update patches/@getcronit+pylon+2.0.0.patch Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- patches/@getcronit+pylon+2.0.0.patch | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/patches/@getcronit+pylon+2.0.0.patch b/patches/@getcronit+pylon+2.0.0.patch index ccf9db1..39d504a 100644 --- a/patches/@getcronit+pylon+2.0.0.patch +++ b/patches/@getcronit+pylon+2.0.0.patch @@ -19,6 +19,8 @@ + key, + encoder.encode(payload) + ); -+ return Buffer.from(signature).toString('base64'); ++ const uint8Array = new Uint8Array(signature); ++ const base64String = btoa(String.fromCharCode(...uint8Array)); ++ return base64String; } *** End Patch From b2763453d9e7119e554bdccff5228db306ef0f9e Mon Sep 17 00:00:00 2001 From: Florian Kleber Date: Sat, 28 Jun 2025 20:03:31 +0200 Subject: [PATCH 3/3] chore: update package.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 47c751d..8fc9c11 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,8 @@ "@getcronit/pylon-dev": "^1.0.0", "prisma": "^6.9.0", "typescript": "^5.6.3", - "wrangler": "^3.60.3" - ,"patch-package": "^8.0.0" + "wrangler": "^3.60.3", + "patch-package": "^8.0.0" }, "repository": { "type": "git",