safehands-pharos 1.0.2 → 1.1.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/.agents/skill/safehands/SKILL.md +42 -11
- package/.agents/skill/safehands/assets/networks.json +24 -0
- package/.agents/skill/safehands/assets/tokens.json +60 -0
- package/README.md +125 -56
- package/dist/index.js +20 -6
- package/dist/index.js.map +1 -1
- package/dist/lib/constants.d.ts +5 -1
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +17 -1
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/testTools.js +134 -7
- package/dist/lib/testTools.js.map +1 -1
- package/dist/tools/approveToken.d.ts +2 -2
- package/dist/tools/checkAllowance.d.ts +1 -1
- package/dist/tools/checkTokenSecurity.d.ts +54 -0
- package/dist/tools/checkTokenSecurity.d.ts.map +1 -0
- package/dist/tools/checkTokenSecurity.js +94 -0
- package/dist/tools/checkTokenSecurity.js.map +1 -0
- package/dist/tools/sendPayment.d.ts +31 -2
- package/dist/tools/sendPayment.d.ts.map +1 -1
- package/dist/tools/sendPayment.js +36 -2
- package/dist/tools/sendPayment.js.map +1 -1
- package/dist/tools/x402PayAndFetch.d.ts +64 -0
- package/dist/tools/x402PayAndFetch.d.ts.map +1 -0
- package/dist/tools/x402PayAndFetch.js +80 -0
- package/dist/tools/x402PayAndFetch.js.map +1 -0
- package/dist/x402Server.d.ts +2 -0
- package/dist/x402Server.d.ts.map +1 -0
- package/dist/x402Server.js +219 -0
- package/dist/x402Server.js.map +1 -0
- package/package.json +8 -1
|
@@ -5,20 +5,23 @@ export declare const sendPaymentSchema: z.ZodObject<{
|
|
|
5
5
|
memo: z.ZodOptional<z.ZodString>;
|
|
6
6
|
walletAddress: z.ZodString;
|
|
7
7
|
privateKey: z.ZodString;
|
|
8
|
+
bypassRiskCheck: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
8
9
|
}, "strip", z.ZodTypeAny, {
|
|
9
10
|
amount: string;
|
|
10
11
|
privateKey: string;
|
|
11
12
|
toAddress: string;
|
|
12
13
|
walletAddress: string;
|
|
14
|
+
bypassRiskCheck: boolean;
|
|
13
15
|
memo?: string | undefined;
|
|
14
16
|
}, {
|
|
15
17
|
amount: string;
|
|
16
18
|
privateKey: string;
|
|
17
19
|
toAddress: string;
|
|
18
20
|
walletAddress: string;
|
|
21
|
+
bypassRiskCheck?: boolean | undefined;
|
|
19
22
|
memo?: string | undefined;
|
|
20
23
|
}>;
|
|
21
|
-
export type SendPaymentInput = z.
|
|
24
|
+
export type SendPaymentInput = z.input<typeof sendPaymentSchema>;
|
|
22
25
|
export declare const sendPaymentTool: {
|
|
23
26
|
name: string;
|
|
24
27
|
description: string;
|
|
@@ -28,21 +31,24 @@ export declare const sendPaymentTool: {
|
|
|
28
31
|
memo: z.ZodOptional<z.ZodString>;
|
|
29
32
|
walletAddress: z.ZodString;
|
|
30
33
|
privateKey: z.ZodString;
|
|
34
|
+
bypassRiskCheck: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
31
35
|
}, "strip", z.ZodTypeAny, {
|
|
32
36
|
amount: string;
|
|
33
37
|
privateKey: string;
|
|
34
38
|
toAddress: string;
|
|
35
39
|
walletAddress: string;
|
|
40
|
+
bypassRiskCheck: boolean;
|
|
36
41
|
memo?: string | undefined;
|
|
37
42
|
}, {
|
|
38
43
|
amount: string;
|
|
39
44
|
privateKey: string;
|
|
40
45
|
toAddress: string;
|
|
41
46
|
walletAddress: string;
|
|
47
|
+
bypassRiskCheck?: boolean | undefined;
|
|
42
48
|
memo?: string | undefined;
|
|
43
49
|
}>;
|
|
44
50
|
};
|
|
45
|
-
export declare function handleSendPayment(
|
|
51
|
+
export declare function handleSendPayment(raw: SendPaymentInput): Promise<{
|
|
46
52
|
success: boolean;
|
|
47
53
|
validation: {
|
|
48
54
|
addressValid: boolean;
|
|
@@ -50,6 +56,24 @@ export declare function handleSendPayment(input: SendPaymentInput): Promise<{
|
|
|
50
56
|
warnings: string[];
|
|
51
57
|
};
|
|
52
58
|
error: string;
|
|
59
|
+
riskAssessment?: undefined;
|
|
60
|
+
txHash?: undefined;
|
|
61
|
+
explorerUrl?: undefined;
|
|
62
|
+
amountSent?: undefined;
|
|
63
|
+
gasUsed?: undefined;
|
|
64
|
+
} | {
|
|
65
|
+
success: boolean;
|
|
66
|
+
validation: {
|
|
67
|
+
addressValid: boolean;
|
|
68
|
+
balanceSufficient: boolean;
|
|
69
|
+
warnings: string[];
|
|
70
|
+
};
|
|
71
|
+
riskAssessment: {
|
|
72
|
+
riskScore: number;
|
|
73
|
+
wasBlocked: boolean;
|
|
74
|
+
blockReason: string;
|
|
75
|
+
};
|
|
76
|
+
error: string;
|
|
53
77
|
txHash?: undefined;
|
|
54
78
|
explorerUrl?: undefined;
|
|
55
79
|
amountSent?: undefined;
|
|
@@ -65,6 +89,11 @@ export declare function handleSendPayment(input: SendPaymentInput): Promise<{
|
|
|
65
89
|
balanceSufficient: boolean;
|
|
66
90
|
warnings: string[];
|
|
67
91
|
};
|
|
92
|
+
riskAssessment: {
|
|
93
|
+
riskScore: number;
|
|
94
|
+
wasBlocked: boolean;
|
|
95
|
+
blockReason?: undefined;
|
|
96
|
+
};
|
|
68
97
|
error?: undefined;
|
|
69
98
|
}>;
|
|
70
99
|
//# sourceMappingURL=sendPayment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPayment.d.ts","sourceRoot":"","sources":["../../src/tools/sendPayment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"sendPayment.d.ts","sourceRoot":"","sources":["../../src/tools/sendPayment.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAO5B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEjE,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;CAI3B,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyF5D"}
|
|
@@ -2,20 +2,23 @@
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { publicClient, createPharosWalletClient, getExplorerUrl } from "../lib/pharosClient.js";
|
|
4
4
|
import { isAddress, parseEther, formatEther } from "viem";
|
|
5
|
-
import {
|
|
5
|
+
import { assessRisk } from "../lib/riskEngine.js";
|
|
6
|
+
import { MAX_BALANCE_USAGE_PCT, RISK_BLOCK_THRESHOLD } from "../lib/constants.js";
|
|
6
7
|
export const sendPaymentSchema = z.object({
|
|
7
8
|
toAddress: z.string(),
|
|
8
9
|
amount: z.string(),
|
|
9
10
|
memo: z.string().optional(),
|
|
10
11
|
walletAddress: z.string(),
|
|
11
12
|
privateKey: z.string(),
|
|
13
|
+
bypassRiskCheck: z.boolean().optional().default(false),
|
|
12
14
|
});
|
|
13
15
|
export const sendPaymentTool = {
|
|
14
16
|
name: "send_payment",
|
|
15
17
|
description: "Send native PHRS with pre-flight validation. Checks address validity, balance sufficiency, and warns on high exposure.",
|
|
16
18
|
inputSchema: sendPaymentSchema,
|
|
17
19
|
};
|
|
18
|
-
export async function handleSendPayment(
|
|
20
|
+
export async function handleSendPayment(raw) {
|
|
21
|
+
const input = sendPaymentSchema.parse(raw);
|
|
19
22
|
const warnings = [];
|
|
20
23
|
const validation = { addressValid: false, balanceSufficient: false, warnings };
|
|
21
24
|
// Address validation
|
|
@@ -45,6 +48,33 @@ export async function handleSendPayment(input) {
|
|
|
45
48
|
if (usagePct > MAX_BALANCE_USAGE_PCT) {
|
|
46
49
|
warnings.push(`Using ${usagePct}% of wallet balance — high exposure`);
|
|
47
50
|
}
|
|
51
|
+
// Risk assessment
|
|
52
|
+
let riskScore = 0;
|
|
53
|
+
if (!input.bypassRiskCheck) {
|
|
54
|
+
const risk = await assessRisk({
|
|
55
|
+
action: "transfer",
|
|
56
|
+
amount: input.amount,
|
|
57
|
+
toAddress: input.toAddress,
|
|
58
|
+
walletAddress: input.walletAddress,
|
|
59
|
+
});
|
|
60
|
+
riskScore = risk.riskScore;
|
|
61
|
+
if (riskScore > RISK_BLOCK_THRESHOLD) {
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
validation: {
|
|
65
|
+
addressValid: true,
|
|
66
|
+
balanceSufficient: true,
|
|
67
|
+
warnings,
|
|
68
|
+
},
|
|
69
|
+
riskAssessment: {
|
|
70
|
+
riskScore,
|
|
71
|
+
wasBlocked: true,
|
|
72
|
+
blockReason: risk.suggestion,
|
|
73
|
+
},
|
|
74
|
+
error: `Payment blocked — risk score ${riskScore}/100: ${risk.suggestion}`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
48
78
|
try {
|
|
49
79
|
const wallet = createPharosWalletClient(input.privateKey);
|
|
50
80
|
const txHash = await wallet.sendTransaction({
|
|
@@ -59,6 +89,10 @@ export async function handleSendPayment(input) {
|
|
|
59
89
|
amountSent: input.amount,
|
|
60
90
|
gasUsed: receipt.gasUsed.toString(),
|
|
61
91
|
validation,
|
|
92
|
+
riskAssessment: {
|
|
93
|
+
riskScore,
|
|
94
|
+
wasBlocked: false,
|
|
95
|
+
},
|
|
62
96
|
};
|
|
63
97
|
}
|
|
64
98
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendPayment.js","sourceRoot":"","sources":["../../src/tools/sendPayment.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,SAAS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Y,CAAC,yBAAyB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAE/E,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,MAAM,KAAK,SAAS;YACrC,MAAM;YACN,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC;YACnC,UAAU,EAAE,KAAK,CAAC,MAAM;YACxB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE;YACnC,UAAU;YACV,cAAc,EAAE;gBACd,SAAS;gBACT,UAAU,EAAE,KAAK;aAClB;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,mBAAoB,GAAa,CAAC,OAAO,EAAE,EAAE,CAAC;IAC5F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const x402PayAndFetchSchema: z.ZodObject<{
|
|
3
|
+
url: z.ZodString;
|
|
4
|
+
method: z.ZodDefault<z.ZodOptional<z.ZodEnum<["GET", "POST", "PUT", "DELETE"]>>>;
|
|
5
|
+
body: z.ZodOptional<z.ZodString>;
|
|
6
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
7
|
+
rpcUrl: z.ZodOptional<z.ZodString>;
|
|
8
|
+
}, "strip", z.ZodTypeAny, {
|
|
9
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
10
|
+
url: string;
|
|
11
|
+
privateKey?: string | undefined;
|
|
12
|
+
body?: string | undefined;
|
|
13
|
+
rpcUrl?: string | undefined;
|
|
14
|
+
}, {
|
|
15
|
+
url: string;
|
|
16
|
+
privateKey?: string | undefined;
|
|
17
|
+
body?: string | undefined;
|
|
18
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | undefined;
|
|
19
|
+
rpcUrl?: string | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
export type X402PayAndFetchInput = z.input<typeof x402PayAndFetchSchema>;
|
|
22
|
+
export declare const x402PayAndFetchTool: {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
inputSchema: z.ZodObject<{
|
|
26
|
+
url: z.ZodString;
|
|
27
|
+
method: z.ZodDefault<z.ZodOptional<z.ZodEnum<["GET", "POST", "PUT", "DELETE"]>>>;
|
|
28
|
+
body: z.ZodOptional<z.ZodString>;
|
|
29
|
+
privateKey: z.ZodOptional<z.ZodString>;
|
|
30
|
+
rpcUrl: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, "strip", z.ZodTypeAny, {
|
|
32
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
33
|
+
url: string;
|
|
34
|
+
privateKey?: string | undefined;
|
|
35
|
+
body?: string | undefined;
|
|
36
|
+
rpcUrl?: string | undefined;
|
|
37
|
+
}, {
|
|
38
|
+
url: string;
|
|
39
|
+
privateKey?: string | undefined;
|
|
40
|
+
body?: string | undefined;
|
|
41
|
+
method?: "GET" | "POST" | "PUT" | "DELETE" | undefined;
|
|
42
|
+
rpcUrl?: string | undefined;
|
|
43
|
+
}>;
|
|
44
|
+
};
|
|
45
|
+
export declare function handleX402PayAndFetch(raw: X402PayAndFetchInput): Promise<{
|
|
46
|
+
success: boolean;
|
|
47
|
+
status: number;
|
|
48
|
+
statusText: string;
|
|
49
|
+
data: any;
|
|
50
|
+
paymentExecuted: boolean;
|
|
51
|
+
paymentDetails: {
|
|
52
|
+
header: string;
|
|
53
|
+
} | null;
|
|
54
|
+
error?: undefined;
|
|
55
|
+
} | {
|
|
56
|
+
success: boolean;
|
|
57
|
+
error: string;
|
|
58
|
+
status?: undefined;
|
|
59
|
+
statusText?: undefined;
|
|
60
|
+
data?: undefined;
|
|
61
|
+
paymentExecuted?: undefined;
|
|
62
|
+
paymentDetails?: undefined;
|
|
63
|
+
}>;
|
|
64
|
+
//# sourceMappingURL=x402PayAndFetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402PayAndFetch.d.ts","sourceRoot":"","sources":["../../src/tools/x402PayAndFetch.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;EAMhC,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEzE,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;CAM/B,CAAC;AAEF,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;GAkEpE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// ─── Tool: x402_pay_and_fetch ─────────────────────────────────────────────
|
|
2
|
+
// Enables an agent to fetch protected resources from an x402 server.
|
|
3
|
+
// Automatically executes the payment challenge when HTTP 402 is returned.
|
|
4
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
|
|
7
|
+
import { registerExactEvmScheme } from "@x402/evm/exact/client";
|
|
8
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
9
|
+
export const x402PayAndFetchSchema = z.object({
|
|
10
|
+
url: z.string().describe("Target URL of the protected resource requiring x402 payment"),
|
|
11
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE"]).optional().default("GET").describe("HTTP method to use"),
|
|
12
|
+
body: z.string().optional().describe("Optional stringified JSON request body"),
|
|
13
|
+
privateKey: z.string().optional().describe("EVM private key to pay with. If not provided, falls back to PRIVATE_KEY env var"),
|
|
14
|
+
rpcUrl: z.string().optional().describe("Custom RPC URL for payment verification (defaults to Atlantic Testnet RPC)"),
|
|
15
|
+
});
|
|
16
|
+
export const x402PayAndFetchTool = {
|
|
17
|
+
name: "x402_pay_and_fetch",
|
|
18
|
+
description: "Fetch resources from an HTTP x402 payment-gated server. " +
|
|
19
|
+
"If the server challenges with HTTP 402, this tool automatically signs the required payment payload and completes the fetch.",
|
|
20
|
+
inputSchema: x402PayAndFetchSchema,
|
|
21
|
+
};
|
|
22
|
+
export async function handleX402PayAndFetch(raw) {
|
|
23
|
+
const input = x402PayAndFetchSchema.parse(raw);
|
|
24
|
+
const pk = input.privateKey || process.env.PRIVATE_KEY;
|
|
25
|
+
if (!pk) {
|
|
26
|
+
throw new Error("Private key is required to execute x402 payments.");
|
|
27
|
+
}
|
|
28
|
+
const rpc = input.rpcUrl || process.env.PHAROS_RPC_URL || "https://atlantic.dplabs-internal.com/";
|
|
29
|
+
// 1. Initialize EVM Account
|
|
30
|
+
const signer = privateKeyToAccount(pk);
|
|
31
|
+
// 2. Setup x402 client
|
|
32
|
+
const client = new x402Client();
|
|
33
|
+
registerExactEvmScheme(client, {
|
|
34
|
+
signer,
|
|
35
|
+
schemeOptions: {
|
|
36
|
+
688689: { rpcUrl: rpc },
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
// 3. Wrap fetch
|
|
40
|
+
const fetchWithPayment = wrapFetchWithPayment(fetch, client);
|
|
41
|
+
// 4. Perform the request
|
|
42
|
+
const fetchOptions = {
|
|
43
|
+
method: input.method,
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
if (input.body) {
|
|
49
|
+
fetchOptions.body = input.body;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetchWithPayment(input.url, fetchOptions);
|
|
53
|
+
const contentType = res.headers.get("content-type") || "";
|
|
54
|
+
let responseData;
|
|
55
|
+
if (contentType.includes("application/json")) {
|
|
56
|
+
responseData = await res.json();
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
responseData = await res.text();
|
|
60
|
+
}
|
|
61
|
+
const paymentResponseHeader = res.headers.get("PAYMENT-RESPONSE");
|
|
62
|
+
return {
|
|
63
|
+
success: res.ok,
|
|
64
|
+
status: res.status,
|
|
65
|
+
statusText: res.statusText,
|
|
66
|
+
data: responseData,
|
|
67
|
+
paymentExecuted: !!paymentResponseHeader,
|
|
68
|
+
paymentDetails: paymentResponseHeader ? {
|
|
69
|
+
header: paymentResponseHeader,
|
|
70
|
+
} : null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
return {
|
|
75
|
+
success: false,
|
|
76
|
+
error: `x402 fetch failed: ${err.message}`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=x402PayAndFetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402PayAndFetch.js","sourceRoot":"","sources":["../../src/tools/x402PayAndFetch.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qEAAqE;AACrE,0EAA0E;AAC1E,4EAA4E;AAE5E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,6DAA6D,CAAC;IACvF,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IACzG,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;IAC9E,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
// ─── SafeHands x402 Server ──────────────────────────────────────────────
|
|
2
|
+
// Exposes SafeHands risk assessment endpoints protected by x402 paywalls.
|
|
3
|
+
// ────────────────────────────────────────────────────────────────────────
|
|
4
|
+
import express from "express";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { readFileSync } from "fs";
|
|
7
|
+
import { defineChain, createWalletClient, http, publicActions } from "viem";
|
|
8
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
9
|
+
import { x402Facilitator } from "@x402/core/facilitator";
|
|
10
|
+
import { toFacilitatorEvmSigner } from "@x402/evm";
|
|
11
|
+
import { ExactEvmScheme as FacilitatorExactEvmScheme } from "@x402/evm/exact/facilitator";
|
|
12
|
+
import { ExactEvmScheme as ServerExactEvmScheme } from "@x402/evm/exact/server";
|
|
13
|
+
import { HTTPFacilitatorClient } from "@x402/core/server";
|
|
14
|
+
import { paymentMiddleware, x402ResourceServer } from "@x402/express";
|
|
15
|
+
import { handleAssessRisk } from "./tools/assessRisk.js";
|
|
16
|
+
import { handleCheckTokenSecurity } from "./tools/checkTokenSecurity.js";
|
|
17
|
+
import { handleSimulateTransaction } from "./tools/simulateTransaction.js";
|
|
18
|
+
import { USDC_ADDRESS } from "./lib/constants.js";
|
|
19
|
+
// Load Environment Variables
|
|
20
|
+
function loadEnv() {
|
|
21
|
+
try {
|
|
22
|
+
const f = readFileSync(join(process.cwd(), ".env"), "utf-8");
|
|
23
|
+
for (const l of f.split("\n")) {
|
|
24
|
+
const t = l.trim();
|
|
25
|
+
if (!t || t.startsWith("#"))
|
|
26
|
+
continue;
|
|
27
|
+
const i = t.indexOf("=");
|
|
28
|
+
if (i === -1)
|
|
29
|
+
continue;
|
|
30
|
+
process.env[t.slice(0, i).trim()] = t.slice(i + 1).trim();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (e) { }
|
|
34
|
+
}
|
|
35
|
+
loadEnv();
|
|
36
|
+
const PK = process.env.PRIVATE_KEY;
|
|
37
|
+
const WALLET = process.env.WALLET_ADDRESS;
|
|
38
|
+
if (!PK || !WALLET) {
|
|
39
|
+
console.error("❌ PRIVATE_KEY and WALLET_ADDRESS environment variables must be configured in .env");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const payToAddress = WALLET;
|
|
43
|
+
const port = parseInt(process.env.X402_PORT || "4021", 10);
|
|
44
|
+
const rpcUrl = "https://atlantic.dplabs-internal.com/";
|
|
45
|
+
const usdcAddress = USDC_ADDRESS;
|
|
46
|
+
// === Define Pharos Testnet ===
|
|
47
|
+
const pharos = defineChain({
|
|
48
|
+
id: 688_689,
|
|
49
|
+
name: "Pharos Atlantic",
|
|
50
|
+
nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
|
|
51
|
+
rpcUrls: { default: { http: [rpcUrl] } },
|
|
52
|
+
testnet: true,
|
|
53
|
+
});
|
|
54
|
+
// === Create Facilitator EVM Client ===
|
|
55
|
+
const account = privateKeyToAccount(PK);
|
|
56
|
+
const walletClient = createWalletClient({
|
|
57
|
+
account,
|
|
58
|
+
chain: pharos,
|
|
59
|
+
transport: http(undefined, { timeout: 30_000 }),
|
|
60
|
+
}).extend(publicActions);
|
|
61
|
+
const evmSigner = toFacilitatorEvmSigner({
|
|
62
|
+
address: account.address,
|
|
63
|
+
getCode: (args) => walletClient.getCode(args),
|
|
64
|
+
readContract: (args) => walletClient.readContract({ ...args, args: args.args || [] }),
|
|
65
|
+
verifyTypedData: (args) => walletClient.verifyTypedData(args),
|
|
66
|
+
writeContract: (args) => walletClient.writeContract({ ...args, args: args.args || [] }),
|
|
67
|
+
sendTransaction: (args) => walletClient.sendTransaction(args),
|
|
68
|
+
waitForTransactionReceipt: (args) => walletClient.waitForTransactionReceipt(args),
|
|
69
|
+
});
|
|
70
|
+
// === Initialize Facilitator ===
|
|
71
|
+
const facilitator = new x402Facilitator();
|
|
72
|
+
facilitator.register("eip155:688689", new FacilitatorExactEvmScheme(evmSigner, {}));
|
|
73
|
+
// === Initialize Resource Server ===
|
|
74
|
+
const facilitatorClient = new HTTPFacilitatorClient({ url: `http://localhost:${port}` });
|
|
75
|
+
const resourceServer = new x402ResourceServer(facilitatorClient);
|
|
76
|
+
const evmScheme = new ServerExactEvmScheme();
|
|
77
|
+
evmScheme.registerMoneyParser(async (amount, network) => {
|
|
78
|
+
if (network === "eip155:688689") {
|
|
79
|
+
return {
|
|
80
|
+
amount: Math.round(amount * 1e6).toString(), // Convert to USDC integer units
|
|
81
|
+
asset: usdcAddress,
|
|
82
|
+
extra: {
|
|
83
|
+
token: "USDC",
|
|
84
|
+
name: "USDC",
|
|
85
|
+
version: "2",
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
});
|
|
91
|
+
resourceServer.register("eip155:688689", evmScheme);
|
|
92
|
+
// === Express Server setup ===
|
|
93
|
+
const app = express();
|
|
94
|
+
app.use(express.json());
|
|
95
|
+
// --- Facilitator endpoints ---
|
|
96
|
+
app.post("/verify", async (req, res) => {
|
|
97
|
+
try {
|
|
98
|
+
const { paymentPayload, paymentRequirements } = req.body;
|
|
99
|
+
const result = await facilitator.verify(paymentPayload, paymentRequirements);
|
|
100
|
+
res.json(result);
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
res.status(500).json({ error: e.message });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
app.post("/settle", async (req, res) => {
|
|
107
|
+
try {
|
|
108
|
+
const { paymentPayload, paymentRequirements } = req.body;
|
|
109
|
+
const result = await facilitator.settle(paymentPayload, paymentRequirements);
|
|
110
|
+
res.json(result);
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
res.status(500).json({ error: e.message });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
app.get("/supported", (req, res) => {
|
|
117
|
+
res.json(facilitator.getSupported());
|
|
118
|
+
});
|
|
119
|
+
// --- x402 Paid Middleware gating ---
|
|
120
|
+
app.use(paymentMiddleware({
|
|
121
|
+
"GET /assess-risk": {
|
|
122
|
+
accepts: {
|
|
123
|
+
scheme: "exact",
|
|
124
|
+
price: "0.001", // USDC amount: $0.001
|
|
125
|
+
network: "eip155:688689",
|
|
126
|
+
payTo: payToAddress,
|
|
127
|
+
},
|
|
128
|
+
description: "Assess transaction risk (USDC 0.001)",
|
|
129
|
+
mimeType: "application/json",
|
|
130
|
+
},
|
|
131
|
+
"GET /check-token-security": {
|
|
132
|
+
accepts: {
|
|
133
|
+
scheme: "exact",
|
|
134
|
+
price: "0.001", // USDC amount: $0.001
|
|
135
|
+
network: "eip155:688689",
|
|
136
|
+
payTo: payToAddress,
|
|
137
|
+
},
|
|
138
|
+
description: "Verify contract token security profile (USDC 0.001)",
|
|
139
|
+
mimeType: "application/json",
|
|
140
|
+
},
|
|
141
|
+
"GET /simulate-transaction": {
|
|
142
|
+
accepts: {
|
|
143
|
+
scheme: "exact",
|
|
144
|
+
price: "0.001", // USDC amount: $0.001
|
|
145
|
+
network: "eip155:688689",
|
|
146
|
+
payTo: payToAddress,
|
|
147
|
+
},
|
|
148
|
+
description: "Simulate EVM execution trace before broadcasting (USDC 0.001)",
|
|
149
|
+
mimeType: "application/json",
|
|
150
|
+
},
|
|
151
|
+
}, resourceServer));
|
|
152
|
+
// --- Paid Business Logic ---
|
|
153
|
+
app.get("/assess-risk", async (req, res) => {
|
|
154
|
+
try {
|
|
155
|
+
const { action, tokenIn, tokenOut, amount, toAddress, walletAddress } = req.query;
|
|
156
|
+
const result = await handleAssessRisk({
|
|
157
|
+
action: action,
|
|
158
|
+
tokenIn: tokenIn,
|
|
159
|
+
tokenOut: tokenOut,
|
|
160
|
+
amount: amount,
|
|
161
|
+
toAddress: toAddress,
|
|
162
|
+
walletAddress: walletAddress,
|
|
163
|
+
});
|
|
164
|
+
res.json(result);
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
res.status(400).json({ error: e.message });
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
app.get("/check-token-security", async (req, res) => {
|
|
171
|
+
try {
|
|
172
|
+
const { tokenAddress, chainId } = req.query;
|
|
173
|
+
const cid = chainId ? parseInt(chainId, 10) : 688689;
|
|
174
|
+
const result = await handleCheckTokenSecurity({
|
|
175
|
+
tokenAddress: tokenAddress,
|
|
176
|
+
chainId: cid,
|
|
177
|
+
});
|
|
178
|
+
res.json(result);
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
res.status(400).json({ error: e.message });
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
app.get("/simulate-transaction", async (req, res) => {
|
|
185
|
+
try {
|
|
186
|
+
const { action, tokenIn, tokenOut, amount, toAddress, walletAddress } = req.query;
|
|
187
|
+
const result = await handleSimulateTransaction({
|
|
188
|
+
action: action,
|
|
189
|
+
tokenIn: tokenIn,
|
|
190
|
+
tokenOut: tokenOut,
|
|
191
|
+
amount: amount,
|
|
192
|
+
toAddress: toAddress,
|
|
193
|
+
walletAddress: walletAddress,
|
|
194
|
+
});
|
|
195
|
+
res.json(result);
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
res.status(400).json({ error: e.message });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
// --- Free endpoints ---
|
|
202
|
+
app.get("/health", (req, res) => {
|
|
203
|
+
res.json({
|
|
204
|
+
status: "ok",
|
|
205
|
+
service: "SafeHands x402 Resource Server",
|
|
206
|
+
network: "Pharos Atlantic Testnet (Chain ID 688689)",
|
|
207
|
+
receiver: payToAddress,
|
|
208
|
+
asset: usdcAddress,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
// Start Server
|
|
212
|
+
app.listen(port, () => {
|
|
213
|
+
console.log(`✅ SafeHands x402 Server listening on http://localhost:${port}`);
|
|
214
|
+
console.log(`📡 Network: eip155:688689 (Pharos Atlantic Testnet)`);
|
|
215
|
+
console.log(`💰 Paid Recipient Address: ${payToAddress}`);
|
|
216
|
+
console.log(`🪙 USDC Contract Address: ${usdcAddress}`);
|
|
217
|
+
console.log(`🚪 Gated APIs: /assess-risk, /check-token-security, /simulate-transaction`);
|
|
218
|
+
});
|
|
219
|
+
//# sourceMappingURL=x402Server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"x402Server.js","sourceRoot":"","sources":["../src/x402Server.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,0EAA0E;AAC1E,2EAA2E;AAE3E,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,cAAc,IAAI,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,cAAc,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,6BAA6B;AAC7B,SAAS,OAAO;IACd,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,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,EAAE,CAAC,CAAC;IAC7C,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,yBAAyB;AACzB,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IAC9B,GAAG,CAAC,IAAI,CAAC;QACP,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,gCAAgC;QACzC,OAAO,EAAE,2CAA2C;QACpD,QAAQ,EAAE,YAAY;QACtB,KAAK,EAAE,WAAW;KACnB,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,eAAe;AACf,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,yDAAyD,IAAI,EAAE,CAAC,CAAC;IAC7E,OAAO,CAAC,GAAG,CAAC,qDAAqD,CAAC,CAAC;IACnE,OAAO,CAAC,GAAG,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,6BAA6B,WAAW,EAAE,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,2EAA2E,CAAC,CAAC;AAC3F,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "safehands-pharos",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Risk-gating middleware for Pharos agents. Blocks dangerous swaps and transfers before they hit the chain.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"build": "tsc",
|
|
23
23
|
"start": "node dist/index.js",
|
|
24
24
|
"dev": "tsx src/index.ts",
|
|
25
|
+
"x402-server": "tsx src/x402Server.ts",
|
|
25
26
|
"test:rpc": "tsx src/lib/testRpc.ts",
|
|
26
27
|
"test:all": "tsx src/lib/testTools.ts"
|
|
27
28
|
},
|
|
@@ -49,6 +50,12 @@
|
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
52
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
53
|
+
"@types/express": "^5.0.6",
|
|
54
|
+
"@x402/core": "^2.14.0",
|
|
55
|
+
"@x402/evm": "^2.14.0",
|
|
56
|
+
"@x402/express": "^2.14.0",
|
|
57
|
+
"@x402/fetch": "^2.14.0",
|
|
58
|
+
"express": "^5.2.1",
|
|
52
59
|
"viem": "^2.31.3",
|
|
53
60
|
"zod": "^3.25.67"
|
|
54
61
|
},
|