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,89 +1,89 @@
1
- // ─── Tool: publish_risk_score ──────────────────────────────────────────
2
- // Publishes a risk assessment result to the on-chain RiskRegistry.
3
- // ────────────────────────────────────────────────────────────────────────
4
- import { z } from "zod";
5
- import { publicClient, createPharosWalletClientFromAccount, getExplorerUrl } from "../lib/pharosClient.js";
6
- import { RISK_REGISTRY_ADDRESS, RISK_REGISTRY_ABI, CHAIN_ID, PHAROS_ENVIRONMENT } from "../lib/constants.js";
7
- import { assessRisk } from "../lib/riskEngine.js";
8
- import { fail, ok, classifyExternalError } from "../lib/toolResponse.js";
9
- import { getSigner, isSignerFailure } from "../lib/signer/index.js";
10
- import { evaluateActionPolicy } from "../lib/policy/actionPolicyEngine.js";
11
- export const publishRiskScoreSchema = z.object({
12
- action: z.enum(["swap", "transfer"]).describe("Type of on-chain action to assess"),
13
- tokenIn: z.string().optional(),
14
- tokenOut: z.string().optional(),
15
- amount: z.string().describe("Human-readable amount"),
16
- toAddress: z.string().optional().describe("Recipient address (for transfers)"),
17
- agentId: z.string().optional().describe("Managed testnet wallet agentId when WALLET_MODE=managed-testnet"),
18
- });
19
- export const publishRiskScoreTool = {
20
- name: "publish_risk_score",
21
- description: "Run a risk assessment and publish the result to the on-chain RiskRegistry. " +
22
- "Other agents can then query this wallet's risk score without re-running the assessment.",
23
- inputSchema: publishRiskScoreSchema,
24
- };
25
- export async function handlePublishRiskScore(raw) {
26
- if (process.env.WRITE_TOOLS_ENABLED !== "true") {
27
- return fail("WRITE_TOOLS_DISABLED", "publish_risk_score is disabled by default. Set WRITE_TOOLS_ENABLED=true only for trusted testnet execution.", false, "publish_risk_score");
28
- }
29
- const input = publishRiskScoreSchema.parse(raw);
30
- const signer = await getSigner(input.agentId);
31
- if (isSignerFailure(signer)) {
32
- return fail(signer.error.code, signer.error.message, false, "publish_risk_score");
33
- }
34
- const policy = evaluateActionPolicy({
35
- actionType: "publish_risk_score",
36
- chainId: CHAIN_ID,
37
- environment: PHAROS_ENVIRONMENT,
38
- isMainnet: false,
39
- signerAvailable: true,
40
- requiresSigner: true,
41
- });
42
- if (policy.decision === "BLOCK") {
43
- return fail("POLICY_BLOCKED", policy.reasons.join(" ") || "Publishing blocked by SafeHands policy.", false, "publish_risk_score");
44
- }
45
- const walletAddress = signer.address;
46
- const assessment = await assessRisk({
47
- action: input.action,
48
- tokenIn: input.tokenIn,
49
- tokenOut: input.tokenOut,
50
- amount: input.amount,
51
- toAddress: input.toAddress,
52
- walletAddress,
53
- });
54
- try {
55
- const wallet = createPharosWalletClientFromAccount(signer.account);
56
- const txHash = await wallet.writeContract({
57
- address: RISK_REGISTRY_ADDRESS,
58
- abi: RISK_REGISTRY_ABI,
59
- functionName: "publish",
60
- args: [
61
- walletAddress,
62
- BigInt(assessment.riskScore),
63
- assessment.riskLevel,
64
- assessment.recommendation,
65
- ],
66
- });
67
- const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
68
- if (receipt.status !== "success") {
69
- return fail("TX_REVERTED", "publish_risk_score transaction was mined but reverted on-chain. Ensure the calling wallet is authorized via RiskRegistry.setAuthorizedAgent() by the contract owner.", false, "publish_risk_score");
70
- }
71
- return ok({
72
- assessment,
73
- policy,
74
- signerMode: signer.mode,
75
- onChain: {
76
- txHash,
77
- explorerUrl: getExplorerUrl(txHash),
78
- contractAddress: RISK_REGISTRY_ADDRESS,
79
- gasUsed: receipt.gasUsed.toString(),
80
- blockNumber: receipt.blockNumber.toString(),
81
- },
82
- source: "publish_risk_score",
83
- });
84
- }
85
- catch (err) {
86
- return classifyExternalError("pharos_rpc", err);
87
- }
88
- }
1
+ // ─── Tool: publish_risk_score ──────────────────────────────────────────
2
+ // Publishes a risk assessment result to the on-chain RiskRegistry.
3
+ // ────────────────────────────────────────────────────────────────────────
4
+ import { z } from "zod";
5
+ import { publicClient, createPharosWalletClientFromAccount, getExplorerUrl } from "../lib/pharosClient.js";
6
+ import { RISK_REGISTRY_ADDRESS, RISK_REGISTRY_ABI, CHAIN_ID, PHAROS_ENVIRONMENT } from "../lib/constants.js";
7
+ import { assessRisk } from "../lib/riskEngine.js";
8
+ import { fail, ok, classifyExternalError } from "../lib/toolResponse.js";
9
+ import { getSigner, isSignerFailure } from "../lib/signer/index.js";
10
+ import { evaluateActionPolicy } from "../lib/policy/actionPolicyEngine.js";
11
+ export const publishRiskScoreSchema = z.object({
12
+ action: z.enum(["swap", "transfer"]).describe("Type of on-chain action to assess"),
13
+ tokenIn: z.string().optional(),
14
+ tokenOut: z.string().optional(),
15
+ amount: z.string().describe("Human-readable amount"),
16
+ toAddress: z.string().optional().describe("Recipient address (for transfers)"),
17
+ agentId: z.string().optional().describe("Managed testnet wallet agentId when WALLET_MODE=managed-testnet"),
18
+ });
19
+ export const publishRiskScoreTool = {
20
+ name: "publish_risk_score",
21
+ description: "Run a risk assessment and publish the result to the on-chain RiskRegistry. " +
22
+ "Other agents can then query this wallet's risk score without re-running the assessment.",
23
+ inputSchema: publishRiskScoreSchema,
24
+ };
25
+ export async function handlePublishRiskScore(raw) {
26
+ if (process.env.WRITE_TOOLS_ENABLED !== "true") {
27
+ return fail("WRITE_TOOLS_DISABLED", "publish_risk_score is disabled by default. Set WRITE_TOOLS_ENABLED=true only for trusted testnet execution.", false, "publish_risk_score");
28
+ }
29
+ const input = publishRiskScoreSchema.parse(raw);
30
+ const signer = await getSigner(input.agentId);
31
+ if (isSignerFailure(signer)) {
32
+ return fail(signer.error.code, signer.error.message, false, "publish_risk_score");
33
+ }
34
+ const policy = evaluateActionPolicy({
35
+ actionType: "publish_risk_score",
36
+ chainId: CHAIN_ID,
37
+ environment: PHAROS_ENVIRONMENT,
38
+ isMainnet: false,
39
+ signerAvailable: true,
40
+ requiresSigner: true,
41
+ });
42
+ if (policy.decision === "BLOCK") {
43
+ return fail("POLICY_BLOCKED", policy.reasons.join(" ") || "Publishing blocked by SafeHands policy.", false, "publish_risk_score");
44
+ }
45
+ const walletAddress = signer.address;
46
+ const assessment = await assessRisk({
47
+ action: input.action,
48
+ tokenIn: input.tokenIn,
49
+ tokenOut: input.tokenOut,
50
+ amount: input.amount,
51
+ toAddress: input.toAddress,
52
+ walletAddress,
53
+ });
54
+ try {
55
+ const wallet = createPharosWalletClientFromAccount(signer.account);
56
+ const txHash = await wallet.writeContract({
57
+ address: RISK_REGISTRY_ADDRESS,
58
+ abi: RISK_REGISTRY_ABI,
59
+ functionName: "publish",
60
+ args: [
61
+ walletAddress,
62
+ BigInt(assessment.riskScore),
63
+ assessment.riskLevel,
64
+ assessment.recommendation,
65
+ ],
66
+ });
67
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
68
+ if (receipt.status !== "success") {
69
+ return fail("TX_REVERTED", "publish_risk_score transaction was mined but reverted on-chain. Ensure the calling wallet is authorized via RiskRegistry.setAuthorizedAgent() by the contract owner.", false, "publish_risk_score");
70
+ }
71
+ return ok({
72
+ assessment,
73
+ policy,
74
+ signerMode: signer.mode,
75
+ onChain: {
76
+ txHash,
77
+ explorerUrl: getExplorerUrl(txHash),
78
+ contractAddress: RISK_REGISTRY_ADDRESS,
79
+ gasUsed: receipt.gasUsed.toString(),
80
+ blockNumber: receipt.blockNumber.toString(),
81
+ },
82
+ source: "publish_risk_score",
83
+ });
84
+ }
85
+ catch (err) {
86
+ return classifyExternalError("pharos_rpc", err);
87
+ }
88
+ }
89
89
  //# sourceMappingURL=publishRiskScore.js.map
@@ -1,39 +1,39 @@
1
- import { z } from "zod";
2
- export declare const queryRiskRegistrySchema: z.ZodObject<{
3
- walletAddress: z.ZodString;
4
- }, "strip", z.ZodTypeAny, {
5
- walletAddress: string;
6
- }, {
7
- walletAddress: string;
8
- }>;
9
- export type QueryRiskRegistryInput = z.input<typeof queryRiskRegistrySchema>;
10
- export declare const queryRiskRegistryTool: {
11
- name: string;
12
- description: string;
13
- inputSchema: z.ZodObject<{
14
- walletAddress: z.ZodString;
15
- }, "strip", z.ZodTypeAny, {
16
- walletAddress: string;
17
- }, {
18
- walletAddress: string;
19
- }>;
20
- };
21
- export declare function handleQueryRiskRegistry(raw: QueryRiskRegistryInput): Promise<import("../lib/toolResponse.js").ToolFailure | import("../lib/toolResponse.js").ToolSuccess<{
22
- walletAddress: string;
23
- found: boolean;
24
- record: null;
25
- registryContract: `0x${string}`;
26
- message: string;
27
- }> | import("../lib/toolResponse.js").ToolSuccess<{
28
- walletAddress: string;
29
- found: boolean;
30
- record: {
31
- score: number;
32
- riskLevel: string;
33
- recommendation: string;
34
- timestamp: string;
35
- assessedBy: `0x${string}`;
36
- };
37
- registryContract: `0x${string}`;
38
- }>>;
1
+ import { z } from "zod";
2
+ export declare const queryRiskRegistrySchema: z.ZodObject<{
3
+ walletAddress: z.ZodString;
4
+ }, "strip", z.ZodTypeAny, {
5
+ walletAddress: string;
6
+ }, {
7
+ walletAddress: string;
8
+ }>;
9
+ export type QueryRiskRegistryInput = z.input<typeof queryRiskRegistrySchema>;
10
+ export declare const queryRiskRegistryTool: {
11
+ name: string;
12
+ description: string;
13
+ inputSchema: z.ZodObject<{
14
+ walletAddress: z.ZodString;
15
+ }, "strip", z.ZodTypeAny, {
16
+ walletAddress: string;
17
+ }, {
18
+ walletAddress: string;
19
+ }>;
20
+ };
21
+ export declare function handleQueryRiskRegistry(raw: QueryRiskRegistryInput): Promise<import("../lib/toolResponse.js").ToolFailure | import("../lib/toolResponse.js").ToolSuccess<{
22
+ walletAddress: string;
23
+ found: boolean;
24
+ record: null;
25
+ registryContract: `0x${string}`;
26
+ message: string;
27
+ }> | import("../lib/toolResponse.js").ToolSuccess<{
28
+ walletAddress: string;
29
+ found: boolean;
30
+ record: {
31
+ score: number;
32
+ riskLevel: string;
33
+ recommendation: string;
34
+ timestamp: string;
35
+ assessedBy: `0x${string}`;
36
+ };
37
+ registryContract: `0x${string}`;
38
+ }>>;
39
39
  //# sourceMappingURL=queryRiskRegistry.d.ts.map
@@ -1,56 +1,56 @@
1
- // ─── Tool: query_risk_registry ─────────────────────────────────────────
2
- // Queries the on-chain RiskRegistry for a wallet's published risk score.
3
- // Read-only — no private key needed.
4
- // ────────────────────────────────────────────────────────────────────────
5
- import { z } from "zod";
6
- import { publicClient } from "../lib/pharosClient.js";
7
- import { RISK_REGISTRY_ADDRESS, RISK_REGISTRY_ABI } from "../lib/constants.js";
8
- import { ok, fail } from "../lib/toolResponse.js";
9
- export const queryRiskRegistrySchema = z.object({
10
- walletAddress: z.string().describe("Wallet address to query risk score for"),
11
- });
12
- export const queryRiskRegistryTool = {
13
- name: "query_risk_registry",
14
- description: "Query the on-chain RiskRegistry for a wallet's published risk score. " +
15
- "Read-only, no private key needed. Returns score, level, recommendation, timestamp, and assessor.",
16
- inputSchema: queryRiskRegistrySchema,
17
- };
18
- export async function handleQueryRiskRegistry(raw) {
19
- const input = queryRiskRegistrySchema.parse(raw);
20
- try {
21
- const result = (await publicClient.readContract({
22
- address: RISK_REGISTRY_ADDRESS,
23
- abi: RISK_REGISTRY_ABI,
24
- functionName: "query",
25
- args: [input.walletAddress],
26
- }));
27
- const score = Number(result.score);
28
- const timestamp = Number(result.timestamp);
29
- // Check if record exists (timestamp will be 0 if never published)
30
- if (timestamp === 0) {
31
- return ok({
32
- walletAddress: input.walletAddress,
33
- found: false,
34
- record: null,
35
- registryContract: RISK_REGISTRY_ADDRESS,
36
- message: "No risk score published for this wallet",
37
- });
38
- }
39
- return ok({
40
- walletAddress: input.walletAddress,
41
- found: true,
42
- record: {
43
- score,
44
- riskLevel: result.riskLevel,
45
- recommendation: result.recommendation,
46
- timestamp: new Date(timestamp * 1000).toISOString(),
47
- assessedBy: result.assessedBy,
48
- },
49
- registryContract: RISK_REGISTRY_ADDRESS,
50
- });
51
- }
52
- catch (err) {
53
- return fail("REGISTRY_QUERY_FAILED", `Failed to query registry: ${err.message}`, true, "query_risk_registry");
54
- }
55
- }
1
+ // ─── Tool: query_risk_registry ─────────────────────────────────────────
2
+ // Queries the on-chain RiskRegistry for a wallet's published risk score.
3
+ // Read-only — no private key needed.
4
+ // ────────────────────────────────────────────────────────────────────────
5
+ import { z } from "zod";
6
+ import { publicClient } from "../lib/pharosClient.js";
7
+ import { RISK_REGISTRY_ADDRESS, RISK_REGISTRY_ABI } from "../lib/constants.js";
8
+ import { ok, fail } from "../lib/toolResponse.js";
9
+ export const queryRiskRegistrySchema = z.object({
10
+ walletAddress: z.string().describe("Wallet address to query risk score for"),
11
+ });
12
+ export const queryRiskRegistryTool = {
13
+ name: "query_risk_registry",
14
+ description: "Query the on-chain RiskRegistry for a wallet's published risk score. " +
15
+ "Read-only, no private key needed. Returns score, level, recommendation, timestamp, and assessor.",
16
+ inputSchema: queryRiskRegistrySchema,
17
+ };
18
+ export async function handleQueryRiskRegistry(raw) {
19
+ const input = queryRiskRegistrySchema.parse(raw);
20
+ try {
21
+ const result = (await publicClient.readContract({
22
+ address: RISK_REGISTRY_ADDRESS,
23
+ abi: RISK_REGISTRY_ABI,
24
+ functionName: "query",
25
+ args: [input.walletAddress],
26
+ }));
27
+ const score = Number(result.score);
28
+ const timestamp = Number(result.timestamp);
29
+ // Check if record exists (timestamp will be 0 if never published)
30
+ if (timestamp === 0) {
31
+ return ok({
32
+ walletAddress: input.walletAddress,
33
+ found: false,
34
+ record: null,
35
+ registryContract: RISK_REGISTRY_ADDRESS,
36
+ message: "No risk score published for this wallet",
37
+ });
38
+ }
39
+ return ok({
40
+ walletAddress: input.walletAddress,
41
+ found: true,
42
+ record: {
43
+ score,
44
+ riskLevel: result.riskLevel,
45
+ recommendation: result.recommendation,
46
+ timestamp: new Date(timestamp * 1000).toISOString(),
47
+ assessedBy: result.assessedBy,
48
+ },
49
+ registryContract: RISK_REGISTRY_ADDRESS,
50
+ });
51
+ }
52
+ catch (err) {
53
+ return fail("REGISTRY_QUERY_FAILED", `Failed to query registry: ${err.message}`, true, "query_risk_registry");
54
+ }
55
+ }
56
56
  //# sourceMappingURL=queryRiskRegistry.js.map
@@ -1,78 +1,78 @@
1
- import { z } from "zod";
2
- import { type ToolResponse } from "../lib/toolResponse.js";
3
- export declare const safehandsPreflightCheckSchema: z.ZodObject<{
4
- actionType: z.ZodEnum<["send_payment", "approve_token", "execute_swap", "x402_pay_and_fetch", "publish_risk_score", "custom_contract_call"]>;
5
- chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
6
- environment: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
- isMainnet: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
8
- amount: z.ZodOptional<z.ZodString>;
9
- amountUnit: z.ZodOptional<z.ZodEnum<["PHRS", "USDC", "USD", "TOKEN"]>>;
10
- token: z.ZodOptional<z.ZodString>;
11
- tokenAddress: z.ZodOptional<z.ZodString>;
12
- tokenIn: z.ZodOptional<z.ZodString>;
13
- tokenOut: z.ZodOptional<z.ZodString>;
14
- recipient: z.ZodOptional<z.ZodString>;
15
- spender: z.ZodOptional<z.ZodString>;
16
- approvalAmount: z.ZodOptional<z.ZodString>;
17
- approvalToken: z.ZodOptional<z.ZodString>;
18
- approvalUnlimited: z.ZodOptional<z.ZodBoolean>;
19
- url: z.ZodOptional<z.ZodString>;
20
- paymentAmountUsdc: z.ZodOptional<z.ZodString>;
21
- paymentTokenAddress: z.ZodDefault<z.ZodOptional<z.ZodString>>;
22
- signerAvailable: z.ZodOptional<z.ZodBoolean>;
23
- tokenSecurityStatus: z.ZodOptional<z.ZodEnum<["ok", "unavailable", "unknown"]>>;
24
- recipientVerified: z.ZodOptional<z.ZodBoolean>;
25
- spenderVerified: z.ZodOptional<z.ZodBoolean>;
26
- requiresSigner: z.ZodOptional<z.ZodBoolean>;
27
- }, "strip", z.ZodTypeAny, {
28
- environment: string;
29
- actionType: "send_payment" | "approve_token" | "execute_swap" | "x402_pay_and_fetch" | "publish_risk_score" | "custom_contract_call";
30
- chainId: number;
31
- isMainnet: boolean;
32
- paymentTokenAddress: string;
33
- spender?: string | undefined;
34
- amount?: string | undefined;
35
- token?: string | undefined;
36
- tokenAddress?: string | undefined;
37
- amountUnit?: "PHRS" | "USDC" | "USD" | "TOKEN" | undefined;
38
- tokenIn?: string | undefined;
39
- tokenOut?: string | undefined;
40
- recipient?: string | undefined;
41
- approvalAmount?: string | undefined;
42
- approvalToken?: string | undefined;
43
- approvalUnlimited?: boolean | undefined;
44
- url?: string | undefined;
45
- paymentAmountUsdc?: string | undefined;
46
- signerAvailable?: boolean | undefined;
47
- tokenSecurityStatus?: "unknown" | "ok" | "unavailable" | undefined;
48
- recipientVerified?: boolean | undefined;
49
- spenderVerified?: boolean | undefined;
50
- requiresSigner?: boolean | undefined;
51
- }, {
52
- actionType: "send_payment" | "approve_token" | "execute_swap" | "x402_pay_and_fetch" | "publish_risk_score" | "custom_contract_call";
53
- spender?: string | undefined;
54
- amount?: string | undefined;
55
- environment?: string | undefined;
56
- token?: string | undefined;
57
- tokenAddress?: string | undefined;
58
- chainId?: number | undefined;
59
- isMainnet?: boolean | undefined;
60
- amountUnit?: "PHRS" | "USDC" | "USD" | "TOKEN" | undefined;
61
- tokenIn?: string | undefined;
62
- tokenOut?: string | undefined;
63
- recipient?: string | undefined;
64
- approvalAmount?: string | undefined;
65
- approvalToken?: string | undefined;
66
- approvalUnlimited?: boolean | undefined;
67
- url?: string | undefined;
68
- paymentAmountUsdc?: string | undefined;
69
- paymentTokenAddress?: string | undefined;
70
- signerAvailable?: boolean | undefined;
71
- tokenSecurityStatus?: "unknown" | "ok" | "unavailable" | undefined;
72
- recipientVerified?: boolean | undefined;
73
- spenderVerified?: boolean | undefined;
74
- requiresSigner?: boolean | undefined;
75
- }>;
76
- export type SafeHandsPreflightCheckInput = z.input<typeof safehandsPreflightCheckSchema>;
77
- export declare function handleSafeHandsPreflightCheck(raw: SafeHandsPreflightCheckInput): Promise<ToolResponse<unknown>>;
1
+ import { z } from "zod";
2
+ import { type ToolResponse } from "../lib/toolResponse.js";
3
+ export declare const safehandsPreflightCheckSchema: z.ZodObject<{
4
+ actionType: z.ZodEnum<["send_payment", "approve_token", "execute_swap", "x402_pay_and_fetch", "publish_risk_score", "custom_contract_call"]>;
5
+ chainId: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
6
+ environment: z.ZodDefault<z.ZodOptional<z.ZodString>>;
7
+ isMainnet: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
8
+ amount: z.ZodOptional<z.ZodString>;
9
+ amountUnit: z.ZodOptional<z.ZodEnum<["PHRS", "USDC", "USD", "TOKEN"]>>;
10
+ token: z.ZodOptional<z.ZodString>;
11
+ tokenAddress: z.ZodOptional<z.ZodString>;
12
+ tokenIn: z.ZodOptional<z.ZodString>;
13
+ tokenOut: z.ZodOptional<z.ZodString>;
14
+ recipient: z.ZodOptional<z.ZodString>;
15
+ spender: z.ZodOptional<z.ZodString>;
16
+ approvalAmount: z.ZodOptional<z.ZodString>;
17
+ approvalToken: z.ZodOptional<z.ZodString>;
18
+ approvalUnlimited: z.ZodOptional<z.ZodBoolean>;
19
+ url: z.ZodOptional<z.ZodString>;
20
+ paymentAmountUsdc: z.ZodOptional<z.ZodString>;
21
+ paymentTokenAddress: z.ZodDefault<z.ZodOptional<z.ZodString>>;
22
+ signerAvailable: z.ZodOptional<z.ZodBoolean>;
23
+ tokenSecurityStatus: z.ZodOptional<z.ZodEnum<["ok", "unavailable", "unknown"]>>;
24
+ recipientVerified: z.ZodOptional<z.ZodBoolean>;
25
+ spenderVerified: z.ZodOptional<z.ZodBoolean>;
26
+ requiresSigner: z.ZodOptional<z.ZodBoolean>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ environment: string;
29
+ actionType: "send_payment" | "approve_token" | "execute_swap" | "x402_pay_and_fetch" | "publish_risk_score" | "custom_contract_call";
30
+ chainId: number;
31
+ isMainnet: boolean;
32
+ paymentTokenAddress: string;
33
+ spender?: string | undefined;
34
+ amount?: string | undefined;
35
+ token?: string | undefined;
36
+ tokenAddress?: string | undefined;
37
+ amountUnit?: "PHRS" | "USDC" | "USD" | "TOKEN" | undefined;
38
+ tokenIn?: string | undefined;
39
+ tokenOut?: string | undefined;
40
+ recipient?: string | undefined;
41
+ approvalAmount?: string | undefined;
42
+ approvalToken?: string | undefined;
43
+ approvalUnlimited?: boolean | undefined;
44
+ url?: string | undefined;
45
+ paymentAmountUsdc?: string | undefined;
46
+ signerAvailable?: boolean | undefined;
47
+ tokenSecurityStatus?: "unknown" | "ok" | "unavailable" | undefined;
48
+ recipientVerified?: boolean | undefined;
49
+ spenderVerified?: boolean | undefined;
50
+ requiresSigner?: boolean | undefined;
51
+ }, {
52
+ actionType: "send_payment" | "approve_token" | "execute_swap" | "x402_pay_and_fetch" | "publish_risk_score" | "custom_contract_call";
53
+ spender?: string | undefined;
54
+ amount?: string | undefined;
55
+ environment?: string | undefined;
56
+ token?: string | undefined;
57
+ tokenAddress?: string | undefined;
58
+ chainId?: number | undefined;
59
+ isMainnet?: boolean | undefined;
60
+ amountUnit?: "PHRS" | "USDC" | "USD" | "TOKEN" | undefined;
61
+ tokenIn?: string | undefined;
62
+ tokenOut?: string | undefined;
63
+ recipient?: string | undefined;
64
+ approvalAmount?: string | undefined;
65
+ approvalToken?: string | undefined;
66
+ approvalUnlimited?: boolean | undefined;
67
+ url?: string | undefined;
68
+ paymentAmountUsdc?: string | undefined;
69
+ paymentTokenAddress?: string | undefined;
70
+ signerAvailable?: boolean | undefined;
71
+ tokenSecurityStatus?: "unknown" | "ok" | "unavailable" | undefined;
72
+ recipientVerified?: boolean | undefined;
73
+ spenderVerified?: boolean | undefined;
74
+ requiresSigner?: boolean | undefined;
75
+ }>;
76
+ export type SafeHandsPreflightCheckInput = z.input<typeof safehandsPreflightCheckSchema>;
77
+ export declare function handleSafeHandsPreflightCheck(raw: SafeHandsPreflightCheckInput): Promise<ToolResponse<unknown>>;
78
78
  //# sourceMappingURL=safehandsPreflightCheck.d.ts.map
@@ -1,48 +1,48 @@
1
- // ─── Tool: safehands_preflight_check ───────────────────────────────────
2
- // Branded SafeHands transaction safety firewall preflight.
3
- // ───────────────────────────────────────────────────────────────────────
4
- import { z } from "zod";
5
- import { ok } from "../lib/toolResponse.js";
6
- import { CHAIN_ID, PHAROS_ENVIRONMENT, IS_MAINNET, X402_PAYMENT_TOKEN_ADDRESS } from "../lib/constants.js";
7
- import { evaluateActionPolicy } from "../lib/policy/actionPolicyEngine.js";
8
- import { classifyTokenRegistryStatus } from "./tokenRegistryStatus.js";
9
- export const safehandsPreflightCheckSchema = z.object({
10
- actionType: z.enum(["send_payment", "approve_token", "execute_swap", "x402_pay_and_fetch", "publish_risk_score", "custom_contract_call"]),
11
- chainId: z.number().optional().default(CHAIN_ID),
12
- environment: z.string().optional().default(PHAROS_ENVIRONMENT),
13
- isMainnet: z.boolean().optional().default(IS_MAINNET),
14
- amount: z.string().optional(),
15
- amountUnit: z.enum(["PHRS", "USDC", "USD", "TOKEN"]).optional(),
16
- token: z.string().optional(),
17
- tokenAddress: z.string().optional(),
18
- tokenIn: z.string().optional(),
19
- tokenOut: z.string().optional(),
20
- recipient: z.string().optional(),
21
- spender: z.string().optional(),
22
- approvalAmount: z.string().optional(),
23
- approvalToken: z.string().optional(),
24
- approvalUnlimited: z.boolean().optional(),
25
- url: z.string().optional(),
26
- paymentAmountUsdc: z.string().optional(),
27
- paymentTokenAddress: z.string().optional().default(X402_PAYMENT_TOKEN_ADDRESS),
28
- signerAvailable: z.boolean().optional(),
29
- tokenSecurityStatus: z.enum(["ok", "unavailable", "unknown"]).optional(),
30
- recipientVerified: z.boolean().optional(),
31
- spenderVerified: z.boolean().optional(),
32
- requiresSigner: z.boolean().optional(),
33
- });
34
- export async function handleSafeHandsPreflightCheck(raw) {
35
- const input = safehandsPreflightCheckSchema.parse(raw);
36
- const tokenForRegistry = input.tokenAddress || input.token || input.tokenOut || input.tokenIn;
37
- const registry = tokenForRegistry ? classifyTokenRegistryStatus(tokenForRegistry) : null;
38
- const policy = evaluateActionPolicy({
39
- ...input,
40
- tokenRegistryStatus: registry?.status,
41
- });
42
- return ok({
43
- ...policy,
44
- tokenRegistry: registry,
45
- source: "safehands_preflight_check",
46
- });
47
- }
1
+ // ─── Tool: safehands_preflight_check ───────────────────────────────────
2
+ // Branded SafeHands transaction safety firewall preflight.
3
+ // ───────────────────────────────────────────────────────────────────────
4
+ import { z } from "zod";
5
+ import { ok } from "../lib/toolResponse.js";
6
+ import { CHAIN_ID, PHAROS_ENVIRONMENT, IS_MAINNET, X402_PAYMENT_TOKEN_ADDRESS } from "../lib/constants.js";
7
+ import { evaluateActionPolicy } from "../lib/policy/actionPolicyEngine.js";
8
+ import { classifyTokenRegistryStatus } from "./tokenRegistryStatus.js";
9
+ export const safehandsPreflightCheckSchema = z.object({
10
+ actionType: z.enum(["send_payment", "approve_token", "execute_swap", "x402_pay_and_fetch", "publish_risk_score", "custom_contract_call"]),
11
+ chainId: z.number().optional().default(CHAIN_ID),
12
+ environment: z.string().optional().default(PHAROS_ENVIRONMENT),
13
+ isMainnet: z.boolean().optional().default(IS_MAINNET),
14
+ amount: z.string().optional(),
15
+ amountUnit: z.enum(["PHRS", "USDC", "USD", "TOKEN"]).optional(),
16
+ token: z.string().optional(),
17
+ tokenAddress: z.string().optional(),
18
+ tokenIn: z.string().optional(),
19
+ tokenOut: z.string().optional(),
20
+ recipient: z.string().optional(),
21
+ spender: z.string().optional(),
22
+ approvalAmount: z.string().optional(),
23
+ approvalToken: z.string().optional(),
24
+ approvalUnlimited: z.boolean().optional(),
25
+ url: z.string().optional(),
26
+ paymentAmountUsdc: z.string().optional(),
27
+ paymentTokenAddress: z.string().optional().default(X402_PAYMENT_TOKEN_ADDRESS),
28
+ signerAvailable: z.boolean().optional(),
29
+ tokenSecurityStatus: z.enum(["ok", "unavailable", "unknown"]).optional(),
30
+ recipientVerified: z.boolean().optional(),
31
+ spenderVerified: z.boolean().optional(),
32
+ requiresSigner: z.boolean().optional(),
33
+ });
34
+ export async function handleSafeHandsPreflightCheck(raw) {
35
+ const input = safehandsPreflightCheckSchema.parse(raw);
36
+ const tokenForRegistry = input.tokenAddress || input.token || input.tokenOut || input.tokenIn;
37
+ const registry = tokenForRegistry ? classifyTokenRegistryStatus(tokenForRegistry) : null;
38
+ const policy = evaluateActionPolicy({
39
+ ...input,
40
+ tokenRegistryStatus: registry?.status,
41
+ });
42
+ return ok({
43
+ ...policy,
44
+ tokenRegistry: registry,
45
+ source: "safehands_preflight_check",
46
+ });
47
+ }
48
48
  //# sourceMappingURL=safehandsPreflightCheck.js.map