safehands-pharos 1.2.6 → 1.4.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 (153) hide show
  1. package/.env.example +64 -26
  2. package/README.md +333 -445
  3. package/dist/cli.d.ts +5 -5
  4. package/dist/cli.d.ts.map +1 -1
  5. package/dist/cli.js +124 -98
  6. package/dist/cli.js.map +1 -1
  7. package/dist/demo.d.ts +1 -1
  8. package/dist/demo.js +171 -171
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.js +138 -87
  11. package/dist/index.js.map +1 -1
  12. package/dist/init.d.ts +1 -1
  13. package/dist/init.js +65 -65
  14. package/dist/lib/auditLog.d.ts +9 -0
  15. package/dist/lib/auditLog.d.ts.map +1 -0
  16. package/dist/lib/auditLog.js +30 -0
  17. package/dist/lib/auditLog.js.map +1 -0
  18. package/dist/lib/constants.d.ts +291 -291
  19. package/dist/lib/constants.js +292 -292
  20. package/dist/lib/dodoApi.d.ts +78 -70
  21. package/dist/lib/dodoApi.d.ts.map +1 -1
  22. package/dist/lib/dodoApi.js +196 -178
  23. package/dist/lib/dodoApi.js.map +1 -1
  24. package/dist/lib/http.d.ts +14 -14
  25. package/dist/lib/http.js +118 -118
  26. package/dist/lib/pharosClient.d.ts +58 -58
  27. package/dist/lib/pharosClient.d.ts.map +1 -1
  28. package/dist/lib/pharosClient.js +63 -53
  29. package/dist/lib/pharosClient.js.map +1 -1
  30. package/dist/lib/policy/actionPolicyEngine.d.ts +53 -53
  31. package/dist/lib/policy/actionPolicyEngine.js +212 -212
  32. package/dist/lib/policy/actionPolicyEngine.js.map +1 -1
  33. package/dist/lib/riskEngine.d.ts +26 -26
  34. package/dist/lib/riskEngine.js +283 -283
  35. package/dist/lib/signer/index.d.ts +24 -24
  36. package/dist/lib/signer/index.d.ts.map +1 -1
  37. package/dist/lib/signer/index.js +88 -89
  38. package/dist/lib/signer/index.js.map +1 -1
  39. package/dist/lib/spendAccumulator.d.ts +10 -0
  40. package/dist/lib/spendAccumulator.d.ts.map +1 -0
  41. package/dist/lib/spendAccumulator.js +54 -0
  42. package/dist/lib/spendAccumulator.js.map +1 -0
  43. package/dist/lib/testDodoLive.d.ts +1 -1
  44. package/dist/lib/testDodoLive.js +104 -104
  45. package/dist/lib/testLiveSafehands.d.ts +1 -1
  46. package/dist/lib/testLiveSafehands.js +92 -92
  47. package/dist/lib/testRpc.d.ts +1 -1
  48. package/dist/lib/testRpc.js +29 -29
  49. package/dist/lib/testRpcLive.d.ts +1 -1
  50. package/dist/lib/testRpcLive.js +88 -88
  51. package/dist/lib/testTools.d.ts +1 -1
  52. package/dist/lib/testTools.js +397 -397
  53. package/dist/lib/testX402Live.d.ts +1 -1
  54. package/dist/lib/testX402Live.js +159 -159
  55. package/dist/lib/toolResponse.d.ts +25 -25
  56. package/dist/lib/toolResponse.js +53 -53
  57. package/dist/lib/wallet/index.d.ts +37 -18
  58. package/dist/lib/wallet/index.d.ts.map +1 -1
  59. package/dist/lib/wallet/index.js +128 -70
  60. package/dist/lib/wallet/index.js.map +1 -1
  61. package/dist/scripts/checkDeploy.d.ts +1 -1
  62. package/dist/scripts/checkDeploy.js +24 -24
  63. package/dist/scripts/deployRegistry.d.ts +1 -1
  64. package/dist/scripts/deployRegistry.js +100 -100
  65. package/dist/scripts/testRegistry.d.ts +1 -1
  66. package/dist/scripts/testRegistry.js +43 -43
  67. package/dist/tools/approveToken.d.ts +45 -46
  68. package/dist/tools/approveToken.d.ts.map +1 -1
  69. package/dist/tools/approveToken.js +85 -83
  70. package/dist/tools/approveToken.js.map +1 -1
  71. package/dist/tools/assessRisk.d.ts +79 -79
  72. package/dist/tools/assessRisk.d.ts.map +1 -1
  73. package/dist/tools/assessRisk.js +104 -93
  74. package/dist/tools/assessRisk.js.map +1 -1
  75. package/dist/tools/checkAllowance.d.ts +43 -36
  76. package/dist/tools/checkAllowance.d.ts.map +1 -1
  77. package/dist/tools/checkAllowance.js +56 -42
  78. package/dist/tools/checkAllowance.js.map +1 -1
  79. package/dist/tools/checkTokenSecurity.d.ts +46 -46
  80. package/dist/tools/checkTokenSecurity.d.ts.map +1 -1
  81. package/dist/tools/checkTokenSecurity.js +95 -88
  82. package/dist/tools/checkTokenSecurity.js.map +1 -1
  83. package/dist/tools/createAgentWallet.d.ts +26 -26
  84. package/dist/tools/createAgentWallet.d.ts.map +1 -1
  85. package/dist/tools/createAgentWallet.js +58 -59
  86. package/dist/tools/createAgentWallet.js.map +1 -1
  87. package/dist/tools/estimateGas.d.ts +79 -79
  88. package/dist/tools/estimateGas.js +124 -124
  89. package/dist/tools/executeSwap.d.ts +61 -59
  90. package/dist/tools/executeSwap.d.ts.map +1 -1
  91. package/dist/tools/executeSwap.js +141 -129
  92. package/dist/tools/executeSwap.js.map +1 -1
  93. package/dist/tools/explainRisk.d.ts +29 -29
  94. package/dist/tools/explainRisk.js +32 -32
  95. package/dist/tools/getAgentWallet.d.ts +21 -21
  96. package/dist/tools/getAgentWallet.js +27 -27
  97. package/dist/tools/getAgentWalletBalance.d.ts +11 -11
  98. package/dist/tools/getAgentWalletBalance.js +70 -70
  99. package/dist/tools/getExecutionHistory.d.ts +49 -51
  100. package/dist/tools/getExecutionHistory.d.ts.map +1 -1
  101. package/dist/tools/getExecutionHistory.js +154 -93
  102. package/dist/tools/getExecutionHistory.js.map +1 -1
  103. package/dist/tools/getGasPrice.d.ts +43 -43
  104. package/dist/tools/getGasPrice.js +59 -59
  105. package/dist/tools/getPoolInfo.d.ts +75 -75
  106. package/dist/tools/getPoolInfo.js +137 -137
  107. package/dist/tools/getTokenPrice.d.ts +113 -113
  108. package/dist/tools/getTokenPrice.js +117 -117
  109. package/dist/tools/getTransactionStatus.d.ts +43 -57
  110. package/dist/tools/getTransactionStatus.d.ts.map +1 -1
  111. package/dist/tools/getTransactionStatus.js +59 -67
  112. package/dist/tools/getTransactionStatus.js.map +1 -1
  113. package/dist/tools/getWalletBalance.d.ts +68 -68
  114. package/dist/tools/getWalletBalance.js +87 -87
  115. package/dist/tools/publishRiskScore.d.ts +63 -63
  116. package/dist/tools/publishRiskScore.d.ts.map +1 -1
  117. package/dist/tools/publishRiskScore.js +88 -85
  118. package/dist/tools/publishRiskScore.js.map +1 -1
  119. package/dist/tools/queryRiskRegistry.d.ts +38 -48
  120. package/dist/tools/queryRiskRegistry.d.ts.map +1 -1
  121. package/dist/tools/queryRiskRegistry.js +55 -60
  122. package/dist/tools/queryRiskRegistry.js.map +1 -1
  123. package/dist/tools/safehandsPreflightCheck.d.ts +77 -77
  124. package/dist/tools/safehandsPreflightCheck.js +47 -47
  125. package/dist/tools/safehandsRiskReport.d.ts +81 -81
  126. package/dist/tools/safehandsRiskReport.js +28 -28
  127. package/dist/tools/safehandsSafeExecute.d.ts +20 -20
  128. package/dist/tools/safehandsSafeExecute.d.ts.map +1 -1
  129. package/dist/tools/safehandsSafeExecute.js +81 -75
  130. package/dist/tools/safehandsSafeExecute.js.map +1 -1
  131. package/dist/tools/safehandsWalletHealth.d.ts +14 -14
  132. package/dist/tools/safehandsWalletHealth.js +103 -103
  133. package/dist/tools/safehandsX402Preflight.d.ts +26 -26
  134. package/dist/tools/safehandsX402Preflight.js +65 -65
  135. package/dist/tools/sendPayment.d.ts +57 -58
  136. package/dist/tools/sendPayment.d.ts.map +1 -1
  137. package/dist/tools/sendPayment.js +117 -108
  138. package/dist/tools/sendPayment.js.map +1 -1
  139. package/dist/tools/simulateTransaction.d.ts +60 -81
  140. package/dist/tools/simulateTransaction.d.ts.map +1 -1
  141. package/dist/tools/simulateTransaction.js +83 -88
  142. package/dist/tools/simulateTransaction.js.map +1 -1
  143. package/dist/tools/tokenRegistryStatus.d.ts +26 -26
  144. package/dist/tools/tokenRegistryStatus.js +96 -96
  145. package/dist/tools/x402PayAndFetch.d.ts +81 -81
  146. package/dist/tools/x402PayAndFetch.d.ts.map +1 -1
  147. package/dist/tools/x402PayAndFetch.js +152 -149
  148. package/dist/tools/x402PayAndFetch.js.map +1 -1
  149. package/dist/x402Server.d.ts +1 -1
  150. package/dist/x402Server.js +252 -252
  151. package/examples/dashboard/index.html +337 -0
  152. package/package.json +83 -82
  153. package/skill/SKILL.md +133 -133
@@ -1,2 +1,2 @@
1
- export {};
1
+ export {};
2
2
  //# sourceMappingURL=testX402Live.d.ts.map
@@ -1,160 +1,160 @@
1
- // ─── Live x402 Behavior Verification ───────────────────────────────────
2
- // Tests the local SafeHands x402 server behavior without private keys.
3
- // Labeled: LOCAL_X402_SERVER_DOCS_BEHAVIOR_TEST
4
- // Does NOT pretend to be a remote Pharos infrastructure test.
5
- // ────────────────────────────────────────────────────────────────────────
6
- import express from "express";
7
- const results = [];
8
- async function startLocalX402() {
9
- // Import the x402 server modules inline to avoid side effects
10
- const app = express();
11
- app.disable("x-powered-by");
12
- app.use(express.json({ limit: "64kb" }));
13
- // Simulate the free endpoints from our x402Server.ts
14
- app.get("/supported", (_req, res) => {
15
- res.json({
16
- success: true,
17
- data: {
18
- configured: false,
19
- network: "eip155:688689",
20
- scheme: "exact",
21
- asset: "0xcfC8330f4BCAB529c625D12781b1C19466A9Fc8B",
22
- priceUsdc: "0.001",
23
- freeEndpoints: ["GET /supported", "GET /health"],
24
- paidEndpoints: ["GET /assess-risk", "GET /check-token-security", "GET /simulate-transaction"],
25
- configError: {
26
- code: "X402_SERVER_RECEIVER_CONFIG_MISSING",
27
- message: "Paid endpoints require receiver/payTo plus facilitator signer config.",
28
- },
29
- },
30
- timestamp: new Date().toISOString(),
31
- });
32
- });
33
- app.get("/health", (_req, res) => {
34
- res.json({
35
- success: true,
36
- data: {
37
- status: "ok",
38
- service: "SafeHands x402 Resource Server",
39
- network: "Pharos atlantic-testnet (Chain ID 688689)",
40
- environment: "atlantic-testnet",
41
- isMainnet: false,
42
- receiverConfigured: false,
43
- paidEndpointsConfigured: false,
44
- receiver: null,
45
- asset: "0xcfC8330f4BCAB529c625D12781b1C19466A9Fc8B",
46
- freeEndpoints: ["/supported", "/health"],
47
- },
48
- timestamp: new Date().toISOString(),
49
- });
50
- });
51
- app.get(["/assess-risk", "/check-token-security", "/simulate-transaction"], (_req, res) => {
52
- res.status(503).json({
53
- success: false,
54
- error: {
55
- code: "X402_SERVER_RECEIVER_CONFIG_MISSING",
56
- message: "Paid endpoint receiver/payTo or facilitator signer config is missing.",
57
- },
58
- timestamp: new Date().toISOString(),
59
- });
60
- });
61
- const server = await new Promise((resolve) => {
62
- const instance = app.listen(0, "127.0.0.1", () => resolve(instance));
63
- });
64
- const address = server.address();
65
- const port = typeof address === "object" && address ? address.port : 0;
66
- return { server, port };
67
- }
68
- async function main() {
69
- console.log("═══════════════════════════════════════════════════════════");
70
- console.log(" SafeHands — x402 Behavior Verification");
71
- console.log(" Label: LOCAL_X402_SERVER_DOCS_BEHAVIOR_TEST");
72
- console.log("═══════════════════════════════════════════════════════════");
73
- console.log("");
74
- const { server, port } = await startLocalX402();
75
- const base = `http://127.0.0.1:${port}`;
76
- try {
77
- // 1. /supported without private key
78
- {
79
- const res = await fetch(`${base}/supported`);
80
- const json = await res.json();
81
- const passed = res.status === 200 && json.success === true && json.data?.network === "eip155:688689";
82
- results.push({
83
- name: "supported_no_private_key",
84
- status: passed ? "PASS" : "FAIL",
85
- detail: passed ? "200 OK, network=eip155:688689" : `status=${res.status} data=${JSON.stringify(json).slice(0, 120)}`,
86
- });
87
- }
88
- // 2. /health without private key
89
- {
90
- const res = await fetch(`${base}/health`);
91
- const json = await res.json();
92
- const passed = res.status === 200 && json.success === true && json.data?.status === "ok" && json.data?.isMainnet === false;
93
- results.push({
94
- name: "health_no_private_key",
95
- status: passed ? "PASS" : "FAIL",
96
- detail: passed ? "200 OK, isMainnet=false" : `status=${res.status}`,
97
- });
98
- }
99
- // 3. Paid endpoint without config returns structured 503
100
- {
101
- const res = await fetch(`${base}/assess-risk`);
102
- const json = await res.json();
103
- const passed = res.status === 503 && json.success === false && json.error?.code === "X402_SERVER_RECEIVER_CONFIG_MISSING";
104
- results.push({
105
- name: "paid_endpoint_no_config_structured_error",
106
- status: passed ? "PASS" : "FAIL",
107
- detail: passed ? "503, X402_SERVER_RECEIVER_CONFIG_MISSING" : `status=${res.status} code=${json.error?.code}`,
108
- });
109
- }
110
- // 4. Server does not crash when receiver config is missing
111
- {
112
- const res1 = await fetch(`${base}/check-token-security`);
113
- const res2 = await fetch(`${base}/simulate-transaction`);
114
- const passed = res1.status === 503 && res2.status === 503;
115
- results.push({
116
- name: "no_crash_missing_config",
117
- status: passed ? "PASS" : "FAIL",
118
- detail: passed ? "All paid endpoints return 503 gracefully" : `statuses=${res1.status},${res2.status}`,
119
- });
120
- }
121
- // 5. x402 payment token label matches docs (USDC on eip155:688689)
122
- {
123
- const res = await fetch(`${base}/supported`);
124
- const json = await res.json();
125
- const passed = json.data?.asset === "0xcfC8330f4BCAB529c625D12781b1C19466A9Fc8B" &&
126
- json.data?.network === "eip155:688689";
127
- results.push({
128
- name: "x402_token_label_matches_docs",
129
- status: passed ? "PASS" : "FAIL",
130
- detail: passed ? "asset=canonical USDC, network=eip155:688689" : `asset=${json.data?.asset}`,
131
- });
132
- }
133
- }
134
- finally {
135
- if ("closeAllConnections" in server)
136
- server.closeAllConnections();
137
- await new Promise((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
138
- }
139
- // Print results
140
- console.log(`\n${"#".padStart(2)} ${"Status".padEnd(8)} ${"Check".padEnd(46)} Detail`);
141
- console.log("─".repeat(100));
142
- for (const [i, r] of results.entries()) {
143
- const icon = r.status === "PASS" ? "✅" : "❌";
144
- console.log(`${String(i + 1).padStart(2)} ${icon} ${r.status.padEnd(5)} ${r.name.padEnd(46)} ${r.detail}`);
145
- }
146
- const failed = results.filter(r => r.status === "FAIL");
147
- console.log("─".repeat(100));
148
- console.log(`${results.length - failed.length}/${results.length} x402 behavior checks passed.`);
149
- if (failed.length > 0) {
150
- console.error("\nFailed checks:");
151
- for (const f of failed)
152
- console.error(` - ${f.name}: ${f.detail}`);
153
- process.exit(1);
154
- }
155
- }
156
- main().catch((err) => {
157
- console.error("❌ Unexpected error:", err);
158
- process.exit(1);
159
- });
1
+ // ─── Live x402 Behavior Verification ───────────────────────────────────
2
+ // Tests the local SafeHands x402 server behavior without private keys.
3
+ // Labeled: LOCAL_X402_SERVER_DOCS_BEHAVIOR_TEST
4
+ // Does NOT pretend to be a remote Pharos infrastructure test.
5
+ // ────────────────────────────────────────────────────────────────────────
6
+ import express from "express";
7
+ const results = [];
8
+ async function startLocalX402() {
9
+ // Import the x402 server modules inline to avoid side effects
10
+ const app = express();
11
+ app.disable("x-powered-by");
12
+ app.use(express.json({ limit: "64kb" }));
13
+ // Simulate the free endpoints from our x402Server.ts
14
+ app.get("/supported", (_req, res) => {
15
+ res.json({
16
+ success: true,
17
+ data: {
18
+ configured: false,
19
+ network: "eip155:688689",
20
+ scheme: "exact",
21
+ asset: "0xcfC8330f4BCAB529c625D12781b1C19466A9Fc8B",
22
+ priceUsdc: "0.001",
23
+ freeEndpoints: ["GET /supported", "GET /health"],
24
+ paidEndpoints: ["GET /assess-risk", "GET /check-token-security", "GET /simulate-transaction"],
25
+ configError: {
26
+ code: "X402_SERVER_RECEIVER_CONFIG_MISSING",
27
+ message: "Paid endpoints require receiver/payTo plus facilitator signer config.",
28
+ },
29
+ },
30
+ timestamp: new Date().toISOString(),
31
+ });
32
+ });
33
+ app.get("/health", (_req, res) => {
34
+ res.json({
35
+ success: true,
36
+ data: {
37
+ status: "ok",
38
+ service: "SafeHands x402 Resource Server",
39
+ network: "Pharos atlantic-testnet (Chain ID 688689)",
40
+ environment: "atlantic-testnet",
41
+ isMainnet: false,
42
+ receiverConfigured: false,
43
+ paidEndpointsConfigured: false,
44
+ receiver: null,
45
+ asset: "0xcfC8330f4BCAB529c625D12781b1C19466A9Fc8B",
46
+ freeEndpoints: ["/supported", "/health"],
47
+ },
48
+ timestamp: new Date().toISOString(),
49
+ });
50
+ });
51
+ app.get(["/assess-risk", "/check-token-security", "/simulate-transaction"], (_req, res) => {
52
+ res.status(503).json({
53
+ success: false,
54
+ error: {
55
+ code: "X402_SERVER_RECEIVER_CONFIG_MISSING",
56
+ message: "Paid endpoint receiver/payTo or facilitator signer config is missing.",
57
+ },
58
+ timestamp: new Date().toISOString(),
59
+ });
60
+ });
61
+ const server = await new Promise((resolve) => {
62
+ const instance = app.listen(0, "127.0.0.1", () => resolve(instance));
63
+ });
64
+ const address = server.address();
65
+ const port = typeof address === "object" && address ? address.port : 0;
66
+ return { server, port };
67
+ }
68
+ async function main() {
69
+ console.log("═══════════════════════════════════════════════════════════");
70
+ console.log(" SafeHands — x402 Behavior Verification");
71
+ console.log(" Label: LOCAL_X402_SERVER_DOCS_BEHAVIOR_TEST");
72
+ console.log("═══════════════════════════════════════════════════════════");
73
+ console.log("");
74
+ const { server, port } = await startLocalX402();
75
+ const base = `http://127.0.0.1:${port}`;
76
+ try {
77
+ // 1. /supported without private key
78
+ {
79
+ const res = await fetch(`${base}/supported`);
80
+ const json = await res.json();
81
+ const passed = res.status === 200 && json.success === true && json.data?.network === "eip155:688689";
82
+ results.push({
83
+ name: "supported_no_private_key",
84
+ status: passed ? "PASS" : "FAIL",
85
+ detail: passed ? "200 OK, network=eip155:688689" : `status=${res.status} data=${JSON.stringify(json).slice(0, 120)}`,
86
+ });
87
+ }
88
+ // 2. /health without private key
89
+ {
90
+ const res = await fetch(`${base}/health`);
91
+ const json = await res.json();
92
+ const passed = res.status === 200 && json.success === true && json.data?.status === "ok" && json.data?.isMainnet === false;
93
+ results.push({
94
+ name: "health_no_private_key",
95
+ status: passed ? "PASS" : "FAIL",
96
+ detail: passed ? "200 OK, isMainnet=false" : `status=${res.status}`,
97
+ });
98
+ }
99
+ // 3. Paid endpoint without config returns structured 503
100
+ {
101
+ const res = await fetch(`${base}/assess-risk`);
102
+ const json = await res.json();
103
+ const passed = res.status === 503 && json.success === false && json.error?.code === "X402_SERVER_RECEIVER_CONFIG_MISSING";
104
+ results.push({
105
+ name: "paid_endpoint_no_config_structured_error",
106
+ status: passed ? "PASS" : "FAIL",
107
+ detail: passed ? "503, X402_SERVER_RECEIVER_CONFIG_MISSING" : `status=${res.status} code=${json.error?.code}`,
108
+ });
109
+ }
110
+ // 4. Server does not crash when receiver config is missing
111
+ {
112
+ const res1 = await fetch(`${base}/check-token-security`);
113
+ const res2 = await fetch(`${base}/simulate-transaction`);
114
+ const passed = res1.status === 503 && res2.status === 503;
115
+ results.push({
116
+ name: "no_crash_missing_config",
117
+ status: passed ? "PASS" : "FAIL",
118
+ detail: passed ? "All paid endpoints return 503 gracefully" : `statuses=${res1.status},${res2.status}`,
119
+ });
120
+ }
121
+ // 5. x402 payment token label matches docs (USDC on eip155:688689)
122
+ {
123
+ const res = await fetch(`${base}/supported`);
124
+ const json = await res.json();
125
+ const passed = json.data?.asset === "0xcfC8330f4BCAB529c625D12781b1C19466A9Fc8B" &&
126
+ json.data?.network === "eip155:688689";
127
+ results.push({
128
+ name: "x402_token_label_matches_docs",
129
+ status: passed ? "PASS" : "FAIL",
130
+ detail: passed ? "asset=canonical USDC, network=eip155:688689" : `asset=${json.data?.asset}`,
131
+ });
132
+ }
133
+ }
134
+ finally {
135
+ if ("closeAllConnections" in server)
136
+ server.closeAllConnections();
137
+ await new Promise((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
138
+ }
139
+ // Print results
140
+ console.log(`\n${"#".padStart(2)} ${"Status".padEnd(8)} ${"Check".padEnd(46)} Detail`);
141
+ console.log("─".repeat(100));
142
+ for (const [i, r] of results.entries()) {
143
+ const icon = r.status === "PASS" ? "✅" : "❌";
144
+ console.log(`${String(i + 1).padStart(2)} ${icon} ${r.status.padEnd(5)} ${r.name.padEnd(46)} ${r.detail}`);
145
+ }
146
+ const failed = results.filter(r => r.status === "FAIL");
147
+ console.log("─".repeat(100));
148
+ console.log(`${results.length - failed.length}/${results.length} x402 behavior checks passed.`);
149
+ if (failed.length > 0) {
150
+ console.error("\nFailed checks:");
151
+ for (const f of failed)
152
+ console.error(` - ${f.name}: ${f.detail}`);
153
+ process.exit(1);
154
+ }
155
+ }
156
+ main().catch((err) => {
157
+ console.error("❌ Unexpected error:", err);
158
+ process.exit(1);
159
+ });
160
160
  //# sourceMappingURL=testX402Live.js.map
@@ -1,26 +1,26 @@
1
- export interface ToolError {
2
- code: string;
3
- message: string;
4
- retryable: boolean;
5
- source?: string;
6
- }
7
- export interface ToolSuccess<T> {
8
- success: true;
9
- data: T;
10
- error: null;
11
- timestamp: string;
12
- }
13
- export interface ToolFailure {
14
- success: false;
15
- data: null;
16
- error: ToolError;
17
- timestamp: string;
18
- }
19
- export type ToolResponse<T> = ToolSuccess<T> | ToolFailure;
20
- export declare function ok<T>(data: T, timestamp?: string): ToolSuccess<T>;
21
- export declare function fail(code: string, message: string, retryable?: boolean, source?: string, timestamp?: string): ToolFailure;
22
- export declare function errorMessage(err: unknown): string;
23
- export declare function classifyExternalError(source: string, err: unknown): ToolFailure;
24
- export declare function requireWriteToolsEnabled(toolName: string): ToolFailure | null;
25
- export declare function requireEnv(name: string, source: string): string | ToolFailure;
1
+ export interface ToolError {
2
+ code: string;
3
+ message: string;
4
+ retryable: boolean;
5
+ source?: string;
6
+ }
7
+ export interface ToolSuccess<T> {
8
+ success: true;
9
+ data: T;
10
+ error: null;
11
+ timestamp: string;
12
+ }
13
+ export interface ToolFailure {
14
+ success: false;
15
+ data: null;
16
+ error: ToolError;
17
+ timestamp: string;
18
+ }
19
+ export type ToolResponse<T> = ToolSuccess<T> | ToolFailure;
20
+ export declare function ok<T>(data: T, timestamp?: string): ToolSuccess<T>;
21
+ export declare function fail(code: string, message: string, retryable?: boolean, source?: string, timestamp?: string): ToolFailure;
22
+ export declare function errorMessage(err: unknown): string;
23
+ export declare function classifyExternalError(source: string, err: unknown): ToolFailure;
24
+ export declare function requireWriteToolsEnabled(toolName: string): ToolFailure | null;
25
+ export declare function requireEnv(name: string, source: string): string | ToolFailure;
26
26
  //# sourceMappingURL=toolResponse.d.ts.map
@@ -1,54 +1,54 @@
1
- // ─── Structured Tool Responses ─────────────────────────────────────────
2
- // Shared response helpers so MCP tools are predictable for AI agents.
3
- export function ok(data, timestamp = new Date().toISOString()) {
4
- return { success: true, data, error: null, timestamp };
5
- }
6
- export function fail(code, message, retryable = false, source, timestamp = new Date().toISOString()) {
7
- return {
8
- success: false,
9
- data: null,
10
- error: { code, message, retryable, ...(source ? { source } : {}) },
11
- timestamp,
12
- };
13
- }
14
- export function errorMessage(err) {
15
- return err instanceof Error ? err.message : String(err);
16
- }
17
- export function classifyExternalError(source, err) {
18
- const message = errorMessage(err);
19
- const lower = message.toLowerCase();
20
- const isTimeout = lower.includes("timeout") || lower.includes("aborted");
21
- const isRetryable = isTimeout ||
22
- lower.includes("fetch failed") ||
23
- lower.includes("network") ||
24
- lower.includes("503") ||
25
- lower.includes("502") ||
26
- lower.includes("504") ||
27
- lower.includes("429");
28
- let code = "EXTERNAL_SERVICE_UNAVAILABLE";
29
- if (source === "pharos_rpc")
30
- code = isTimeout ? "RPC_TIMEOUT" : "RPC_UNAVAILABLE";
31
- if (source === "dodo_api")
32
- code = isTimeout ? "DODO_API_TIMEOUT" : "DODO_API_UNAVAILABLE";
33
- if (source === "faroswap_api")
34
- code = isTimeout ? "FAROSWAP_API_TIMEOUT" : "FAROSWAP_API_UNAVAILABLE";
35
- if (source === "goplus_api")
36
- code = isTimeout ? "GOPLUS_API_TIMEOUT" : "GOPLUS_API_UNAVAILABLE";
37
- if (source === "x402_fetch")
38
- code = isTimeout ? "X402_FETCH_TIMEOUT" : "X402_FETCH_FAILED";
39
- return fail(code, message, isRetryable, source);
40
- }
41
- export function requireWriteToolsEnabled(toolName) {
42
- if (process.env.WRITE_TOOLS_ENABLED !== "true") {
43
- return fail("WRITE_TOOLS_DISABLED", `${toolName} is disabled by default. Set WRITE_TOOLS_ENABLED=true only for trusted testnet execution.`, false, toolName);
44
- }
45
- return null;
46
- }
47
- export function requireEnv(name, source) {
48
- const value = process.env[name];
49
- if (!value) {
50
- return fail("MISSING_ENV", `${name} is not configured.`, false, source);
51
- }
52
- return value;
53
- }
1
+ // ─── Structured Tool Responses ─────────────────────────────────────────
2
+ // Shared response helpers so MCP tools are predictable for AI agents.
3
+ export function ok(data, timestamp = new Date().toISOString()) {
4
+ return { success: true, data, error: null, timestamp };
5
+ }
6
+ export function fail(code, message, retryable = false, source, timestamp = new Date().toISOString()) {
7
+ return {
8
+ success: false,
9
+ data: null,
10
+ error: { code, message, retryable, ...(source ? { source } : {}) },
11
+ timestamp,
12
+ };
13
+ }
14
+ export function errorMessage(err) {
15
+ return err instanceof Error ? err.message : String(err);
16
+ }
17
+ export function classifyExternalError(source, err) {
18
+ const message = errorMessage(err);
19
+ const lower = message.toLowerCase();
20
+ const isTimeout = lower.includes("timeout") || lower.includes("aborted");
21
+ const isRetryable = isTimeout ||
22
+ lower.includes("fetch failed") ||
23
+ lower.includes("network") ||
24
+ lower.includes("503") ||
25
+ lower.includes("502") ||
26
+ lower.includes("504") ||
27
+ lower.includes("429");
28
+ let code = "EXTERNAL_SERVICE_UNAVAILABLE";
29
+ if (source === "pharos_rpc")
30
+ code = isTimeout ? "RPC_TIMEOUT" : "RPC_UNAVAILABLE";
31
+ if (source === "dodo_api")
32
+ code = isTimeout ? "DODO_API_TIMEOUT" : "DODO_API_UNAVAILABLE";
33
+ if (source === "faroswap_api")
34
+ code = isTimeout ? "FAROSWAP_API_TIMEOUT" : "FAROSWAP_API_UNAVAILABLE";
35
+ if (source === "goplus_api")
36
+ code = isTimeout ? "GOPLUS_API_TIMEOUT" : "GOPLUS_API_UNAVAILABLE";
37
+ if (source === "x402_fetch")
38
+ code = isTimeout ? "X402_FETCH_TIMEOUT" : "X402_FETCH_FAILED";
39
+ return fail(code, message, isRetryable, source);
40
+ }
41
+ export function requireWriteToolsEnabled(toolName) {
42
+ if (process.env.WRITE_TOOLS_ENABLED !== "true") {
43
+ return fail("WRITE_TOOLS_DISABLED", `${toolName} is disabled by default. Set WRITE_TOOLS_ENABLED=true only for trusted testnet execution.`, false, toolName);
44
+ }
45
+ return null;
46
+ }
47
+ export function requireEnv(name, source) {
48
+ const value = process.env[name];
49
+ if (!value) {
50
+ return fail("MISSING_ENV", `${name} is not configured.`, false, source);
51
+ }
52
+ return value;
53
+ }
54
54
  //# sourceMappingURL=toolResponse.js.map
@@ -1,19 +1,38 @@
1
- export interface StoredWallet {
2
- agentId: string;
3
- address: string;
4
- encryptedKey: string;
5
- environment: "atlantic-testnet";
6
- chainId: 688689;
7
- isMainnet: false;
8
- createdAt: string;
9
- }
10
- export interface WalletStoreInterface {
11
- get(agentId: string): Promise<StoredWallet | null>;
12
- set(agentId: string, wallet: StoredWallet): Promise<void>;
13
- has(agentId: string): Promise<boolean>;
14
- }
15
- export declare function obfuscateKey(privateKey: string, encryptionKey: string): string;
16
- export declare function deobfuscateKey(obfuscated: string, encryptionKey: string): string;
17
- export declare function usesPersistentWalletStore(): boolean;
18
- export declare const walletStore: WalletStoreInterface;
1
+ export interface StoredWallet {
2
+ agentId: string;
3
+ address: string;
4
+ encryptedKey: string;
5
+ environment: "atlantic-testnet";
6
+ chainId: 688689;
7
+ isMainnet: false;
8
+ createdAt: string;
9
+ }
10
+ export interface WalletStoreInterface {
11
+ get(agentId: string): Promise<StoredWallet | null>;
12
+ set(agentId: string, wallet: StoredWallet): Promise<void>;
13
+ has(agentId: string): Promise<boolean>;
14
+ }
15
+ /**
16
+ * Encrypts a private key with AES-256-GCM.
17
+ * Output format: <iv(12B)><tag(16B)><ciphertext> as hex string (no 0x prefix).
18
+ */
19
+ export declare function encryptKey(privateKey: string, encryptionKey: string): string;
20
+ /**
21
+ * Decrypts a private key. Handles both:
22
+ * - New AES-256-GCM format (pure hex, no 0x prefix)
23
+ * - Legacy XOR format (starts with "0x") — transparently supported for migration
24
+ */
25
+ export declare function decryptKey(encrypted: string, encryptionKey: string): string;
26
+ /** @deprecated Use encryptKey / decryptKey. Kept for callers that haven't migrated yet. */
27
+ export declare function obfuscateKey(privateKey: string, encryptionKey: string): string;
28
+ /** @deprecated Use decryptKey. */
29
+ export declare function deobfuscateKey(obfuscated: string, encryptionKey: string): string;
30
+ /**
31
+ * Returns the effective encryption key.
32
+ * - Persistent store: WALLET_ENCRYPTION_KEY must be set (wallets won't survive restarts otherwise).
33
+ * - In-memory store: falls back to a random per-process key.
34
+ */
35
+ export declare function getEffectiveEncryptionKey(): string;
36
+ export declare function usesPersistentWalletStore(): boolean;
37
+ export declare const walletStore: WalletStoreInterface;
19
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/wallet/index.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,kBAAkB,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,KAAK,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACnD,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxC;AAqDD,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAQ9E;AAED,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhF;AAYD,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAED,eAAO,MAAM,WAAW,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/wallet/index.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,kBAAkB,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,KAAK,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACnD,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxC;AA4DD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAQ5E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAc3E;AAcD,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,kCAAkC;AAClC,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhF;AAOD;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,MAAM,CAElD;AAYD,wBAAgB,yBAAyB,IAAI,OAAO,CAEnD;AAED,eAAO,MAAM,WAAW,sBAAsB,CAAC"}