safehands-pharos 1.4.0 → 1.5.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 (124) hide show
  1. package/README.md +174 -63
  2. package/dist/cli.d.ts +5 -5
  3. package/dist/cli.d.ts.map +1 -1
  4. package/dist/cli.js +126 -124
  5. package/dist/cli.js.map +1 -1
  6. package/dist/demo.d.ts +1 -1
  7. package/dist/demo.js +171 -171
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +73 -65
  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/constants.d.ts +303 -291
  15. package/dist/lib/constants.d.ts.map +1 -1
  16. package/dist/lib/constants.js +302 -292
  17. package/dist/lib/constants.js.map +1 -1
  18. package/dist/lib/dodoApi.d.ts +78 -78
  19. package/dist/lib/dodoApi.js +196 -196
  20. package/dist/lib/envLoader.d.ts +2 -0
  21. package/dist/lib/envLoader.d.ts.map +1 -0
  22. package/dist/lib/envLoader.js +44 -0
  23. package/dist/lib/envLoader.js.map +1 -0
  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.js +63 -63
  28. package/dist/lib/policy/actionPolicyEngine.d.ts +53 -53
  29. package/dist/lib/policy/actionPolicyEngine.js +212 -212
  30. package/dist/lib/riskEngine.d.ts +26 -26
  31. package/dist/lib/riskEngine.d.ts.map +1 -1
  32. package/dist/lib/riskEngine.js +288 -283
  33. package/dist/lib/riskEngine.js.map +1 -1
  34. package/dist/lib/signer/index.d.ts +24 -24
  35. package/dist/lib/signer/index.js +88 -88
  36. package/dist/lib/testDodoLive.d.ts +1 -1
  37. package/dist/lib/testDodoLive.js +104 -104
  38. package/dist/lib/testLiveSafehands.d.ts +1 -1
  39. package/dist/lib/testLiveSafehands.js +92 -92
  40. package/dist/lib/testRpcLive.d.ts +1 -1
  41. package/dist/lib/testRpcLive.js +88 -88
  42. package/dist/lib/testTools.js +397 -398
  43. package/dist/lib/testX402Live.d.ts +1 -1
  44. package/dist/lib/testX402Live.js +159 -159
  45. package/dist/lib/toolResponse.d.ts +25 -25
  46. package/dist/lib/toolResponse.js +53 -53
  47. package/dist/lib/wallet/index.d.ts +37 -37
  48. package/dist/lib/wallet/index.js +128 -128
  49. package/dist/scripts/checkDeploy.d.ts +1 -1
  50. package/dist/scripts/checkDeploy.js +24 -24
  51. package/dist/scripts/deployRegistry.d.ts +1 -1
  52. package/dist/scripts/deployRegistry.js +100 -100
  53. package/dist/scripts/testRegistry.d.ts +1 -1
  54. package/dist/scripts/testRegistry.js +43 -43
  55. package/dist/tools/approveToken.d.ts +45 -45
  56. package/dist/tools/approveToken.js +85 -85
  57. package/dist/tools/assessRisk.d.ts +79 -79
  58. package/dist/tools/assessRisk.js +104 -104
  59. package/dist/tools/checkAllowance.d.ts +43 -43
  60. package/dist/tools/checkAllowance.js +56 -56
  61. package/dist/tools/checkTokenSecurity.d.ts +46 -46
  62. package/dist/tools/checkTokenSecurity.js +95 -95
  63. package/dist/tools/createAgentWallet.d.ts +28 -26
  64. package/dist/tools/createAgentWallet.d.ts.map +1 -1
  65. package/dist/tools/createAgentWallet.js +82 -58
  66. package/dist/tools/createAgentWallet.js.map +1 -1
  67. package/dist/tools/estimateGas.d.ts +79 -79
  68. package/dist/tools/estimateGas.js +124 -124
  69. package/dist/tools/executeSwap.d.ts +61 -61
  70. package/dist/tools/executeSwap.js +141 -141
  71. package/dist/tools/explainRisk.d.ts +29 -29
  72. package/dist/tools/explainRisk.js +32 -32
  73. package/dist/tools/getAgentWallet.d.ts +21 -21
  74. package/dist/tools/getAgentWallet.js +27 -27
  75. package/dist/tools/getAgentWalletBalance.d.ts +11 -11
  76. package/dist/tools/getAgentWalletBalance.js +70 -70
  77. package/dist/tools/getExecutionHistory.d.ts +49 -49
  78. package/dist/tools/getExecutionHistory.js +154 -154
  79. package/dist/tools/getGasPrice.d.ts +43 -43
  80. package/dist/tools/getGasPrice.js +59 -59
  81. package/dist/tools/getPoolInfo.d.ts +75 -75
  82. package/dist/tools/getPoolInfo.js +137 -137
  83. package/dist/tools/getTokenPrice.d.ts +113 -113
  84. package/dist/tools/getTokenPrice.js +117 -117
  85. package/dist/tools/getTransactionStatus.d.ts +43 -43
  86. package/dist/tools/getTransactionStatus.js +59 -59
  87. package/dist/tools/getWalletBalance.d.ts +68 -68
  88. package/dist/tools/getWalletBalance.js +87 -87
  89. package/dist/tools/publishRiskScore.d.ts +63 -63
  90. package/dist/tools/publishRiskScore.js +88 -88
  91. package/dist/tools/queryRiskRegistry.d.ts +38 -38
  92. package/dist/tools/queryRiskRegistry.js +55 -55
  93. package/dist/tools/safehandsPreflightCheck.d.ts +77 -77
  94. package/dist/tools/safehandsPreflightCheck.js +47 -47
  95. package/dist/tools/safehandsRiskReport.d.ts +81 -81
  96. package/dist/tools/safehandsRiskReport.js +28 -28
  97. package/dist/tools/safehandsSafeExecute.d.ts +20 -20
  98. package/dist/tools/safehandsSafeExecute.js +81 -81
  99. package/dist/tools/safehandsWalletHealth.d.ts +14 -14
  100. package/dist/tools/safehandsWalletHealth.js +103 -103
  101. package/dist/tools/safehandsX402Preflight.d.ts +26 -26
  102. package/dist/tools/safehandsX402Preflight.js +65 -65
  103. package/dist/tools/sendPayment.d.ts +57 -57
  104. package/dist/tools/sendPayment.js +117 -117
  105. package/dist/tools/simulateTransaction.d.ts +60 -60
  106. package/dist/tools/simulateTransaction.js +83 -83
  107. package/dist/tools/tokenRegistryStatus.d.ts +26 -26
  108. package/dist/tools/tokenRegistryStatus.js +96 -96
  109. package/dist/tools/x402PayAndFetch.d.ts +81 -81
  110. package/dist/tools/x402PayAndFetch.js +152 -152
  111. package/dist/x402Server.d.ts +1 -1
  112. package/dist/x402Server.js +300 -252
  113. package/dist/x402Server.js.map +1 -1
  114. package/package.json +6 -16
  115. package/examples/dashboard/index.html +0 -337
  116. package/examples/pharos-skill-engine/SKILL.safehands.md +0 -85
  117. package/examples/pharos-skill-engine/assets/safehands/example-actions.json +0 -49
  118. package/examples/pharos-skill-engine/assets/safehands/policy-defaults.json +0 -11
  119. package/examples/pharos-skill-engine/references/safehands.md +0 -345
  120. package/examples/scenario-hack.ts +0 -38
  121. package/skill/SKILL.md +0 -133
  122. package/skill/assets/safehands/example-actions.json +0 -49
  123. package/skill/assets/safehands/policy-defaults.json +0 -11
  124. package/skill/references/safehands.md +0 -345
@@ -1,345 +0,0 @@
1
- # SafeHands Guard Reference
2
-
3
- ## Overview
4
-
5
- SafeHands Guard is a Transaction Safety Firewall / Guardrail Skill for Pharos Skill Engine. It lets an AI agent run policy-based preflight checks before execution. The CLI adapter returns the same standard response envelope as the MCP tools.
6
-
7
- ```json
8
- {
9
- "success": true,
10
- "data": {},
11
- "error": null,
12
- "timestamp": "ISO_DATE_STRING"
13
- }
14
- ```
15
-
16
- Failure responses use:
17
-
18
- ```json
19
- {
20
- "success": false,
21
- "data": null,
22
- "error": {
23
- "code": "ERROR_CODE",
24
- "message": "Human-readable message",
25
- "retryable": false,
26
- "source": "source_name"
27
- },
28
- "timestamp": "ISO_DATE_STRING"
29
- }
30
- ```
31
-
32
- ## Command Template
33
-
34
- ```bash
35
- npx safehands-pharos skill <tool_name> --input-json '<json>'
36
- ```
37
-
38
- All outputs are valid JSON. Do not parse stdout as prose.
39
-
40
- ## SafeHands Preflight Check
41
-
42
- ### Overview
43
-
44
- Use this command before any payment, token approval, swap, x402 payment, registry publish, or custom contract call. It returns `ALLOW`, `WARN`, `BLOCK`, `REQUIRE_CONFIRMATION`, `REQUIRE_FUNDING`, or `REQUIRE_TOKEN_REVIEW`.
45
-
46
- ### Command Template
47
-
48
- ```bash
49
- npx safehands-pharos skill safehands_preflight_check --input-json '<action_json>'
50
- ```
51
-
52
- Example:
53
-
54
- ```bash
55
- npx safehands-pharos skill safehands_preflight_check --input-json '{"actionType":"approve_token","chainId":688689,"tokenAddress":"0xE0BE08c77f415F577A1B3A9aD7a1Df1479564ec8","spenderAddress":"0x0000000000000000000000000000000000000001","amount":"1"}'
56
- ```
57
-
58
- ### Parameters
59
-
60
- | Parameter | Type | Required | Description |
61
- |---|---|---|---|
62
- | actionType | string | Yes | `send_payment`, `approve_token`, `execute_swap`, `x402_pay_and_fetch`, `publish_risk_score`, `custom_contract_call` |
63
- | chainId | number | Yes | Must be `688689` for Pharos Atlantic Testnet |
64
- | walletAddress | address | Optional | Agent wallet address |
65
- | targetAddress | address | Optional | Recipient, spender, or contract target |
66
- | tokenAddress | address | Optional | Token involved in the action |
67
- | amount | string | Optional | Amount to send, approve, swap, or pay |
68
- | url | string | Optional | x402 URL for x402 actions |
69
- | approvalAmount | string | Optional | Approval amount, including `max` for unlimited approval |
70
- | recipient | address | Optional | Payment recipient |
71
- | spender | address | Optional | Token spender |
72
-
73
- ### Output Parsing
74
-
75
- | Field | Meaning |
76
- |---|---|
77
- | decision | `ALLOW`, `WARN`, `BLOCK`, `REQUIRE_CONFIRMATION`, `REQUIRE_FUNDING`, `REQUIRE_TOKEN_REVIEW` |
78
- | riskLevel | `LOW`, `MEDIUM`, `HIGH`, `CRITICAL`, `UNKNOWN` |
79
- | safeToExecute | `true` or `false` |
80
- | reasons | Why SafeHands made the decision |
81
- | requiredActions | What user/agent should do next |
82
- | checks | Individual policy checks |
83
- | environment | Expected to be `atlantic-testnet` |
84
- | chainId | Expected to be `688689` |
85
- | isMainnet | Expected to be `false` |
86
-
87
- ### Error Handling
88
-
89
- | Error code | Meaning | Agent action |
90
- |---|---|---|
91
- | `TOOL_EXECUTION_FAILED` | Input failed schema validation or handler threw | Fix the JSON input and retry |
92
- | `CHAIN_ID_MISMATCH` | Action targets the wrong chain | Switch to Pharos Atlantic Testnet |
93
- | `MAINNET_NOT_SUPPORTED` | Mainnet action was requested | Do not execute |
94
- | `POLICY_BLOCKED` | Safety policy blocked execution | Explain reasons to the user |
95
-
96
- ### Agent Guidelines
97
-
98
- 1. Always run preflight before write actions.
99
- 2. If decision is `BLOCK`, do not execute the action.
100
- 3. If decision is `WARN`, explain the risk and ask for user confirmation.
101
- 4. If decision is `REQUIRE_CONFIRMATION`, ask for explicit user approval.
102
- 5. If decision is `ALLOW`, the action may continue through Pharos Skill Engine or MCP execution.
103
-
104
- ## SafeHands x402 Preflight
105
-
106
- ### Overview
107
-
108
- Use this command before paying any x402 resource. It checks URL safety, SSRF protection, endpoint probing when requested, payment amount, token, signer readiness, `MAX_X402_PAYMENT_USDC`, and whether payment appears required.
109
-
110
- ### Command Template
111
-
112
- ```bash
113
- npx safehands-pharos skill safehands_x402_preflight --input-json '<x402_action_json>'
114
- ```
115
-
116
- Example:
117
-
118
- ```bash
119
- npx safehands-pharos skill safehands_x402_preflight --input-json '{"url":"https://example.com/assess-risk","paymentAmountUsdc":"0.001","probeEndpoint":false}'
120
- ```
121
-
122
- ### Parameters
123
-
124
- | Parameter | Type | Required | Description |
125
- |---|---|---|---|
126
- | url | string | Yes | x402 resource URL |
127
- | method | string | Optional | HTTP method, default `GET` |
128
- | paymentAmountUsdc | string | Optional | Estimated USDC payment amount |
129
- | paymentTokenAddress | address | Optional | x402 payment token address |
130
- | agentId | string | Optional | Managed wallet agent ID for signer readiness |
131
- | probeEndpoint | boolean | Optional | If true, SafeHands probes the endpoint to detect HTTP 402 |
132
-
133
- ### Output Parsing
134
-
135
- | Field | Meaning |
136
- |---|---|
137
- | decision | Safety decision for payment |
138
- | safeToExecute | Whether the agent may continue |
139
- | safeToPay | Interpret as true only when `decision` is `ALLOW` |
140
- | paymentAmountUsdc | Estimated payment amount |
141
- | maxPaymentUsdc | Configured `MAX_X402_PAYMENT_USDC` |
142
- | signerAvailable | Whether a signer is available if payment is required |
143
- | probe.paymentRequired | `true`, `false`, or `unknown` |
144
-
145
- ### Error Handling
146
-
147
- | Error code | Meaning | Agent action |
148
- |---|---|---|
149
- | `SSRF_BLOCKED` | URL points to local/private/unsafe host | Do not fetch or pay |
150
- | `NO_SIGNER_AVAILABLE` | Payment may require signer but none is ready | Ask user to configure managed wallet or signer |
151
- | `POLICY_BLOCKED` | Amount, URL, token, or chain failed policy | Do not pay |
152
-
153
- ### Agent Guidelines
154
-
155
- 1. Run x402 preflight before paying any x402 resource.
156
- 2. If the endpoint is free, do not request a private key.
157
- 3. If HTTP 402/payment is required, verify amount, token, URL, and signer readiness.
158
- 4. If decision is `BLOCK`, do not pay.
159
- 5. If signer is unavailable, ask user to configure managed wallet or signer.
160
-
161
- ## SafeHands Wallet Health
162
-
163
- ### Overview
164
-
165
- Use this command to check whether the current or managed agent wallet can pay gas, pay x402 resources, and execute write tools safely.
166
-
167
- ### Command Template
168
-
169
- ```bash
170
- npx safehands-pharos skill safehands_wallet_health --input-json '{}'
171
- ```
172
-
173
- ### Parameters
174
-
175
- | Parameter | Type | Required | Description |
176
- |---|---|---|---|
177
- | agentId | string | Optional | Managed wallet agent ID |
178
- | walletAddress | address | Optional | Explicit wallet address for read-only balance checks |
179
-
180
- ### Output Parsing
181
-
182
- | Field | Meaning |
183
- |---|---|
184
- | status | `READY`, `DEGRADED`, or `NOT_READY` |
185
- | walletReady | Treat as true only when status is `READY` |
186
- | walletMode | `none`, `env`, `managed-testnet`, or future signer mode |
187
- | writeToolsEnabled | Whether execution tools can broadcast |
188
- | readiness.canPayGas | PHRS gas readiness |
189
- | readiness.canPayX402 | USDC x402 readiness |
190
- | readiness.canExecuteWrites | Signer + gas + write-tool readiness |
191
- | balances.PHRS | Native gas balance if RPC is available |
192
- | balances.USDC | USDC balance if RPC is available |
193
-
194
- ### Error Handling
195
-
196
- | Error code | Meaning | Agent action |
197
- |---|---|---|
198
- | `RPC_UNAVAILABLE` | RPC balance read failed | Treat wallet health as degraded and retry later |
199
- | `NO_SIGNER_AVAILABLE` | No signer mode configured | Ask user to configure wallet mode |
200
- | `WALLET_ENCRYPTION_KEY_REQUIRED` | Persistent managed wallet needs encryption key | Ask user to configure testnet wallet storage |
201
-
202
- ### Agent Guidelines
203
-
204
- 1. Run wallet health before x402 payment or write execution.
205
- 2. Do not execute writes if `writeToolsEnabled` is false.
206
- 3. If RPC is unavailable, report degraded status rather than assuming the wallet is funded.
207
- 4. If signer is unavailable, do not ask the user to paste a key into chat.
208
-
209
- ## Token Registry Status
210
-
211
- ### Overview
212
-
213
- Use this command to classify whether a token is canonical, test liquidity, custom/non-registry, unknown, or invalid. The exact user-provided token address is checked; SafeHands does not silently replace it.
214
-
215
- ### Command Template
216
-
217
- ```bash
218
- npx safehands-pharos skill token_registry_status --input-json '{"token":"<token_address>"}'
219
- ```
220
-
221
- ### Parameters
222
-
223
- | Parameter | Type | Required | Description |
224
- |---|---|---|---|
225
- | token | string | Yes | Token symbol or exact contract address to classify |
226
-
227
- ### Status Values
228
-
229
- | Status | Meaning |
230
- |---|---|
231
- | `CANONICAL_TESTNET_TOKEN` | Token is recognized as canonical for this testnet config |
232
- | `TEST_LIQUIDITY_TOKEN` | Token is a test/demo liquidity token |
233
- | `CUSTOM_NON_REGISTRY` | Valid address but not in SafeHands registry |
234
- | `UNKNOWN` | Unknown status |
235
- | `INVALID_ADDRESS` | Input is not a valid EVM address or known symbol |
236
-
237
- ### Output Parsing
238
-
239
- | Field | Meaning |
240
- |---|---|
241
- | status | Registry classification |
242
- | normalizedAddress | Checksummed address when valid |
243
- | verificationStatus | `DOCS_VERIFIED`, `PROJECT_CONFIGURED`, `UNVERIFIED_CUSTOM_TOKEN`, etc. |
244
- | docsSource | Source used for classification, when available |
245
-
246
- ### Error Handling
247
-
248
- | Error code | Meaning | Agent action |
249
- |---|---|---|
250
- | `TOOL_EXECUTION_FAILED` | Missing token input or malformed request | Ask for exact token address |
251
-
252
- ### Agent Guidelines
253
-
254
- 1. Never silently replace user-provided token addresses.
255
- 2. If token is custom, clearly say it is custom/non-registry.
256
- 3. If token is canonical, show `docsSource` or `verificationStatus`.
257
-
258
- ## Explain Risk
259
-
260
- ### Overview
261
-
262
- Use this command to convert a policy result into a concise human-readable explanation.
263
-
264
- ### Command Template
265
-
266
- ```bash
267
- npx safehands-pharos skill explain_risk --input-json '<risk_json>'
268
- ```
269
-
270
- ### Parameters
271
-
272
- | Parameter | Type | Required | Description |
273
- |---|---|---|---|
274
- | decision | string | Yes | Policy decision |
275
- | riskLevel | string | Yes | Risk level |
276
- | reasons | string[] | Optional | Reasons returned by policy engine |
277
- | requiredActions | string[] | Optional | Required next actions |
278
-
279
- ### Output Parsing
280
-
281
- | Field | Meaning |
282
- |---|---|
283
- | explanation | Human-readable explanation |
284
- | decision | Original policy decision |
285
- | riskLevel | Original risk level |
286
-
287
- ### Error Handling
288
-
289
- | Error code | Meaning | Agent action |
290
- |---|---|---|
291
- | `TOOL_EXECUTION_FAILED` | Invalid risk JSON | Re-run with a policy result or valid fields |
292
-
293
- ### Agent Guidelines
294
-
295
- 1. Use this after a preflight result when the user asks “why?”.
296
- 2. Keep the explanation factual and tied to SafeHands reasons.
297
- 3. Do not override a `BLOCK` decision with reassuring language.
298
-
299
- ## SafeHands Risk Report
300
-
301
- ### Overview
302
-
303
- Use this command to generate a judge/demo-friendly safety report. It runs preflight and returns a summary, reasons, required actions, checks, and environment.
304
-
305
- ### Command Template
306
-
307
- ```bash
308
- npx safehands-pharos skill safehands_risk_report --input-json '<action_or_policy_result_json>'
309
- ```
310
-
311
- ### Parameters
312
-
313
- | Parameter | Type | Required | Description |
314
- |---|---|---|---|
315
- | actionType | string | Yes | Same action type list as preflight |
316
- | chainId | number | Optional | Defaults to Pharos Atlantic Testnet |
317
- | amount | string | Optional | Amount involved |
318
- | tokenAddress | address | Optional | Token involved |
319
- | url | string | Optional | x402 URL when relevant |
320
- | includeChecks | boolean | Optional | Include detailed policy checks, default true |
321
-
322
- ### Output Parsing
323
-
324
- | Field | Meaning |
325
- |---|---|
326
- | summary | Human-readable risk report |
327
- | decision | Safety decision |
328
- | riskLevel | Risk level |
329
- | reasons | Reasons for decision |
330
- | requiredActions | Next steps |
331
- | checks | Detailed checks when requested |
332
-
333
- ### Error Handling
334
-
335
- | Error code | Meaning | Agent action |
336
- |---|---|---|
337
- | `TOOL_EXECUTION_FAILED` | Invalid action JSON | Fix the action JSON and retry |
338
- | `POLICY_BLOCKED` | Safety policy blocked the action | Do not execute the action |
339
-
340
- ### Agent Guidelines
341
-
342
- 1. Use this for demos, user-facing summaries, and audit trails.
343
- 2. If the report says `BLOCK`, stop execution.
344
- 3. If the report says `WARN` or `REQUIRE_CONFIRMATION`, ask for explicit user confirmation.
345
- 4. If the report says `ALLOW`, the action may continue through Pharos Skill Engine or MCP execution.