@dupecom/botcha-cloudflare 0.18.0 → 0.19.0

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.
package/dist/tap-jwks.js CHANGED
@@ -3,6 +3,7 @@
3
3
  * Implements .well-known/jwks for TAP agent public key discovery
4
4
  * Per Visa TAP spec: https://developer.visa.com/capabilities/trusted-agent-protocol
5
5
  */
6
+ import { getSigningPublicKeyJWK } from './auth.js';
6
7
  // ============ PEM <-> JWK CONVERSION ============
7
8
  /**
8
9
  * Convert PEM public key to JWK format
@@ -122,27 +123,49 @@ function arrayBufferToPem(buffer) {
122
123
  // ============ JWKS ENDPOINT HANDLERS ============
123
124
  /**
124
125
  * GET /.well-known/jwks
125
- * Returns JWK Set for app's TAP-enabled agents
126
+ * Returns JWK Set for app's TAP-enabled agents.
127
+ * Also includes BOTCHA's own signing public key when JWT_SIGNING_KEY is configured.
126
128
  */
127
129
  export async function jwksRoute(c) {
128
130
  try {
131
+ const allKeys = [];
132
+ // Always include BOTCHA's own signing public key if configured
133
+ const jwtSigningKeyEnv = c.env.JWT_SIGNING_KEY;
134
+ if (jwtSigningKeyEnv) {
135
+ try {
136
+ const privateKeyJwk = JSON.parse(jwtSigningKeyEnv);
137
+ const publicKeyJwk = getSigningPublicKeyJWK(privateKeyJwk);
138
+ allKeys.push({
139
+ kty: publicKeyJwk.kty,
140
+ crv: publicKeyJwk.crv,
141
+ x: publicKeyJwk.x,
142
+ y: publicKeyJwk.y,
143
+ kid: 'botcha-signing-1',
144
+ use: 'sig',
145
+ alg: 'ES256',
146
+ });
147
+ }
148
+ catch (error) {
149
+ console.error('Failed to derive BOTCHA signing public key for JWKS:', error);
150
+ }
151
+ }
129
152
  const appId = c.req.query('app_id');
130
- // Security: Don't expose all keys globally
153
+ // If no app_id, return just the BOTCHA signing key (if any)
131
154
  if (!appId) {
132
- return c.json({ keys: [] }, 200, {
155
+ return c.json({ keys: allKeys }, 200, {
133
156
  'Cache-Control': 'public, max-age=3600',
134
157
  });
135
158
  }
136
159
  const agents = c.env.AGENTS;
137
160
  if (!agents) {
138
161
  console.error('AGENTS KV namespace not available');
139
- return c.json({ keys: [] }, 200);
162
+ return c.json({ keys: allKeys }, 200);
140
163
  }
141
164
  // Get agent list for this app
142
165
  const agentIndexKey = `app_agents:${appId}`;
143
166
  const agentIdsData = await agents.get(agentIndexKey, 'text');
144
167
  if (!agentIdsData) {
145
- return c.json({ keys: [] }, 200, {
168
+ return c.json({ keys: allKeys }, 200, {
146
169
  'Cache-Control': 'public, max-age=3600',
147
170
  });
148
171
  }
@@ -174,8 +197,9 @@ export async function jwksRoute(c) {
174
197
  return null;
175
198
  }
176
199
  });
177
- const jwks = (await Promise.all(jwkPromises)).filter((jwk) => jwk !== null);
178
- return c.json({ keys: jwks }, 200, {
200
+ const agentJwks = (await Promise.all(jwkPromises)).filter((jwk) => jwk !== null);
201
+ allKeys.push(...agentJwks);
202
+ return c.json({ keys: allKeys }, 200, {
179
203
  'Cache-Control': 'public, max-age=3600',
180
204
  });
181
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dupecom/botcha-cloudflare",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "BOTCHA for Cloudflare Workers - Prove you're a bot. Humans need not apply.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",