aap-agent-client 2.5.0 → 2.6.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.
Files changed (3) hide show
  1. package/index.js +43 -11
  2. package/package.json +2 -2
  3. package/prover.js +14 -4
package/index.js CHANGED
@@ -8,6 +8,22 @@
8
8
  import { Prover } from './prover.js';
9
9
  import { Identity } from 'aap-agent-core';
10
10
 
11
+ // Fetch with timeout helper
12
+ async function fetchWithTimeout(url, options = {}, timeoutMs = 30000) {
13
+ const controller = new AbortController();
14
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
15
+
16
+ try {
17
+ const response = await fetch(url, {
18
+ ...options,
19
+ signal: controller.signal
20
+ });
21
+ return response;
22
+ } finally {
23
+ clearTimeout(timeout);
24
+ }
25
+ }
26
+
11
27
  /**
12
28
  * AAP Client - High-level interface for verification
13
29
  */
@@ -47,11 +63,19 @@ export class AAPClient {
47
63
 
48
64
  const callback = solutionOrCallback || this.llmCallback;
49
65
 
50
- // Step 1: Request challenge
51
- const challengeRes = await fetch(`${baseUrl}/challenge`, {
52
- method: 'POST',
53
- headers: { 'Content-Type': 'application/json' }
54
- });
66
+ // Step 1: Request challenge (with timeout)
67
+ let challengeRes;
68
+ try {
69
+ challengeRes = await fetchWithTimeout(`${baseUrl}/challenge`, {
70
+ method: 'POST',
71
+ headers: { 'Content-Type': 'application/json' }
72
+ }, 10000);
73
+ } catch (error) {
74
+ if (error.name === 'AbortError') {
75
+ throw new Error('Challenge request timed out');
76
+ }
77
+ throw error;
78
+ }
55
79
 
56
80
  if (!challengeRes.ok) {
57
81
  throw new Error(`Failed to get challenge: ${challengeRes.status}`);
@@ -62,12 +86,20 @@ export class AAPClient {
62
86
  // Step 2: Generate proof
63
87
  const proof = await this.prover.generateProof(challenge, callback);
64
88
 
65
- // Step 3: Submit proof
66
- const verifyRes = await fetch(`${baseUrl}/verify`, {
67
- method: 'POST',
68
- headers: { 'Content-Type': 'application/json' },
69
- body: JSON.stringify(proof)
70
- });
89
+ // Step 3: Submit proof (with timeout)
90
+ let verifyRes;
91
+ try {
92
+ verifyRes = await fetchWithTimeout(`${baseUrl}/verify`, {
93
+ method: 'POST',
94
+ headers: { 'Content-Type': 'application/json' },
95
+ body: JSON.stringify(proof)
96
+ }, 15000);
97
+ } catch (error) {
98
+ if (error.name === 'AbortError') {
99
+ throw new Error('Verification request timed out');
100
+ }
101
+ throw error;
102
+ }
71
103
 
72
104
  const result = await verifyRes.json();
73
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aap-agent-client",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Client library for Agent Attestation Protocol - prove your AI agent identity",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "homepage": "https://github.com/ira-hash/agent-attestation-protocol#readme",
22
22
  "dependencies": {
23
- "aap-agent-core": "^2.5.0"
23
+ "aap-agent-core": "^2.6.0"
24
24
  },
25
25
  "engines": {
26
26
  "node": ">=18.0.0"
package/prover.js CHANGED
@@ -47,10 +47,20 @@ export class Prover {
47
47
 
48
48
  if (llmCallback) {
49
49
  // Use LLM to solve all at once (more efficient)
50
- const combinedPrompt = this.createBatchPrompt(challenges);
51
- const llmResponse = await llmCallback(combinedPrompt);
52
- const parsedSolutions = this.parseBatchResponse(llmResponse, challenges.length);
53
- solutions.push(...parsedSolutions);
50
+ try {
51
+ const combinedPrompt = this.createBatchPrompt(challenges);
52
+ const llmResponse = await llmCallback(combinedPrompt);
53
+ const parsedSolutions = this.parseBatchResponse(llmResponse, challenges.length);
54
+ solutions.push(...parsedSolutions);
55
+ } catch (error) {
56
+ console.error('[AAP] LLM callback failed:', error.message);
57
+ // Fallback to placeholder solutions (will fail verification but won't crash)
58
+ for (const c of challenges) {
59
+ const saltMatch = c.challenge_string.match(/\[REQ-([A-Z0-9]+)\]/);
60
+ const salt = saltMatch ? saltMatch[1] : 'ERROR';
61
+ solutions.push(JSON.stringify({ salt, error: 'LLM callback failed' }));
62
+ }
63
+ }
54
64
  } else {
55
65
  // Use built-in solvers
56
66
  for (const challenge of challenges) {