@paystage/auth-watch 0.0.0-stage → 0.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/README.md +58 -2
- package/dist/abis.d.ts +19 -0
- package/dist/abis.js +64 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +12 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +7 -0
- package/dist/evaluate.d.ts +3 -0
- package/dist/evaluate.js +43 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/rpc.d.ts +5 -0
- package/dist/rpc.js +40 -0
- package/dist/scan.d.ts +12 -0
- package/dist/scan.js +79 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +118 -0
- package/dist/types.d.ts +24 -0
- package/dist/types.js +1 -0
- package/package.json +58 -4
- package/server.json +36 -0
package/README.md
CHANGED
|
@@ -1,3 +1,59 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @paystage/auth-watch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Scan and evaluate outstanding token authorizations (ERC-20 allowances, Permit2
|
|
4
|
+
allowances, and EIP-3009 nonces) for a wallet against a Paystage policy.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @paystage/auth-watch
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Library usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import {
|
|
16
|
+
createRpcClient,
|
|
17
|
+
resolveRpcUrl,
|
|
18
|
+
listOutstandingAuths,
|
|
19
|
+
evaluateOutstandingAuths,
|
|
20
|
+
} from "@paystage/auth-watch";
|
|
21
|
+
import { loadPolicy } from "@paystage/policy";
|
|
22
|
+
|
|
23
|
+
const network = "eip155:8453";
|
|
24
|
+
const rpc = createRpcClient(resolveRpcUrl(network));
|
|
25
|
+
const policy = await loadPolicy("./paystage.policy.json");
|
|
26
|
+
|
|
27
|
+
const items = await listOutstandingAuths({
|
|
28
|
+
wallet: "0x...",
|
|
29
|
+
network,
|
|
30
|
+
tokens: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"],
|
|
31
|
+
spenders: policy.allowed_spenders ?? policy.allowed_pay_to,
|
|
32
|
+
rpc,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const results = evaluateOutstandingAuths(items, policy);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## MCP server
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
node dist/cli.js
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Tools:
|
|
45
|
+
|
|
46
|
+
- `list_outstanding_auths` — list outstanding authorizations.
|
|
47
|
+
- `evaluate_outstanding_auths` — list and evaluate against a policy.
|
|
48
|
+
|
|
49
|
+
Both accept `wallet`, optional `network`, `tokens`, `spenders`,
|
|
50
|
+
`policy_path` or inline `policy`, `eip3009_nonces`, and `rpc_url`.
|
|
51
|
+
|
|
52
|
+
## Environment
|
|
53
|
+
|
|
54
|
+
- `PAYSTAGE_RPC_URL` — overrides the default RPC URL for the network.
|
|
55
|
+
|
|
56
|
+
## Networks
|
|
57
|
+
|
|
58
|
+
- `eip155:8453` — Base mainnet (`https://mainnet.base.org`)
|
|
59
|
+
- `eip155:84532` — Base Sepolia (`https://sepolia.base.org`)
|
package/dist/abis.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare const SELECTORS: {
|
|
2
|
+
readonly erc20Allowance: "0xdd62ed3e";
|
|
3
|
+
readonly permit2Allowance: "0x927da105";
|
|
4
|
+
readonly usdcAuthorizationState: "0xe94a0102";
|
|
5
|
+
};
|
|
6
|
+
export declare function padAddress(addr: string): string;
|
|
7
|
+
export declare function padUint256(value: bigint | number | string): string;
|
|
8
|
+
export declare function padBytes32(hex: string): string;
|
|
9
|
+
export declare function encodeAllowance(owner: string, spender: string): string;
|
|
10
|
+
export declare function encodePermit2Allowance(owner: string, token: string, spender: string): string;
|
|
11
|
+
export declare function encodeAuthorizationState(owner: string, nonce: string): string;
|
|
12
|
+
export declare function decodeUint256(hex: string): bigint;
|
|
13
|
+
export interface Permit2Allowance {
|
|
14
|
+
amount: bigint;
|
|
15
|
+
expiration: number;
|
|
16
|
+
nonce: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function decodePermit2Allowance(hex: string): Permit2Allowance;
|
|
19
|
+
export declare function decodeBool(hex: string): boolean;
|
package/dist/abis.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Pure hex helpers. No ethers dependency.
|
|
2
|
+
export const SELECTORS = {
|
|
3
|
+
erc20Allowance: "0xdd62ed3e",
|
|
4
|
+
permit2Allowance: "0x927da105",
|
|
5
|
+
usdcAuthorizationState: "0xe94a0102",
|
|
6
|
+
};
|
|
7
|
+
function strip0x(hex) {
|
|
8
|
+
return hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
|
|
9
|
+
}
|
|
10
|
+
export function padAddress(addr) {
|
|
11
|
+
const clean = strip0x(addr).toLowerCase();
|
|
12
|
+
if (!/^[0-9a-f]{40}$/.test(clean)) {
|
|
13
|
+
throw new Error(`Invalid address: ${addr}`);
|
|
14
|
+
}
|
|
15
|
+
return clean.padStart(64, "0");
|
|
16
|
+
}
|
|
17
|
+
export function padUint256(value) {
|
|
18
|
+
const v = typeof value === "bigint" ? value : BigInt(value);
|
|
19
|
+
if (v < 0n)
|
|
20
|
+
throw new Error("uint256 cannot be negative");
|
|
21
|
+
return v.toString(16).padStart(64, "0");
|
|
22
|
+
}
|
|
23
|
+
export function padBytes32(hex) {
|
|
24
|
+
const clean = strip0x(hex).toLowerCase();
|
|
25
|
+
if (!/^[0-9a-f]{1,64}$/.test(clean)) {
|
|
26
|
+
throw new Error(`Invalid bytes32: ${hex}`);
|
|
27
|
+
}
|
|
28
|
+
return clean.padStart(64, "0");
|
|
29
|
+
}
|
|
30
|
+
export function encodeAllowance(owner, spender) {
|
|
31
|
+
return SELECTORS.erc20Allowance + padAddress(owner) + padAddress(spender);
|
|
32
|
+
}
|
|
33
|
+
export function encodePermit2Allowance(owner, token, spender) {
|
|
34
|
+
return (SELECTORS.permit2Allowance +
|
|
35
|
+
padAddress(owner) +
|
|
36
|
+
padAddress(token) +
|
|
37
|
+
padAddress(spender));
|
|
38
|
+
}
|
|
39
|
+
export function encodeAuthorizationState(owner, nonce) {
|
|
40
|
+
return SELECTORS.usdcAuthorizationState + padAddress(owner) + padBytes32(nonce);
|
|
41
|
+
}
|
|
42
|
+
export function decodeUint256(hex) {
|
|
43
|
+
const clean = strip0x(hex);
|
|
44
|
+
if (clean.length === 0)
|
|
45
|
+
return 0n;
|
|
46
|
+
return BigInt("0x" + clean);
|
|
47
|
+
}
|
|
48
|
+
export function decodePermit2Allowance(hex) {
|
|
49
|
+
const clean = strip0x(hex);
|
|
50
|
+
if (clean.length < 64 * 3) {
|
|
51
|
+
// Some nodes return empty for reverts; treat as zero.
|
|
52
|
+
return { amount: 0n, expiration: 0, nonce: 0 };
|
|
53
|
+
}
|
|
54
|
+
const amount = BigInt("0x" + clean.slice(0, 64));
|
|
55
|
+
const expiration = Number(BigInt("0x" + clean.slice(64, 128)));
|
|
56
|
+
const nonce = Number(BigInt("0x" + clean.slice(128, 192)));
|
|
57
|
+
return { amount, expiration, nonce };
|
|
58
|
+
}
|
|
59
|
+
export function decodeBool(hex) {
|
|
60
|
+
const clean = strip0x(hex);
|
|
61
|
+
if (clean.length === 0)
|
|
62
|
+
return false;
|
|
63
|
+
return BigInt("0x" + clean) !== 0n;
|
|
64
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const server = createServer();
|
|
6
|
+
const transport = new StdioServerTransport();
|
|
7
|
+
await server.connect(transport);
|
|
8
|
+
}
|
|
9
|
+
main().catch((err) => {
|
|
10
|
+
console.error(err);
|
|
11
|
+
process.exit(1);
|
|
12
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2
|
+
export declare const USDC_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
3
|
+
export declare const PERMIT2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
4
|
+
export declare const DEFAULT_RPC: Record<string, string>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const USDC_BASE = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
2
|
+
export const USDC_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
3
|
+
export const PERMIT2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
4
|
+
export const DEFAULT_RPC = {
|
|
5
|
+
"eip155:8453": "https://mainnet.base.org",
|
|
6
|
+
"eip155:84532": "https://sepolia.base.org"
|
|
7
|
+
};
|
package/dist/evaluate.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const UNLIMITED_THRESHOLD = 2n ** 255n;
|
|
2
|
+
function normalize(addr) {
|
|
3
|
+
return addr.toLowerCase();
|
|
4
|
+
}
|
|
5
|
+
function isUnlimited(item) {
|
|
6
|
+
return item.amount >= UNLIMITED_THRESHOLD;
|
|
7
|
+
}
|
|
8
|
+
function isUnknownSpender(item, policy) {
|
|
9
|
+
const allowed = policy.allowed_spenders ?? policy.allowed_pay_to;
|
|
10
|
+
const spender = normalize(item.spender);
|
|
11
|
+
return !allowed.some((a) => normalize(a) === spender);
|
|
12
|
+
}
|
|
13
|
+
function isStale(item, nowSeconds) {
|
|
14
|
+
if (item.expirationSeconds === undefined)
|
|
15
|
+
return false;
|
|
16
|
+
if (item.expirationSeconds === 0)
|
|
17
|
+
return false;
|
|
18
|
+
return nowSeconds > item.expirationSeconds;
|
|
19
|
+
}
|
|
20
|
+
export function evaluateOutstandingAuths(items, policy, nowSeconds = Math.floor(Date.now() / 1000)) {
|
|
21
|
+
return items.map((item) => {
|
|
22
|
+
const flags = [];
|
|
23
|
+
if (isUnlimited(item)) {
|
|
24
|
+
flags.push("unlimited");
|
|
25
|
+
}
|
|
26
|
+
if (isUnknownSpender(item, policy)) {
|
|
27
|
+
flags.push("unknown_spender");
|
|
28
|
+
}
|
|
29
|
+
if (isStale(item, nowSeconds)) {
|
|
30
|
+
flags.push("stale");
|
|
31
|
+
}
|
|
32
|
+
let summary = "ok";
|
|
33
|
+
if (flags.length > 0) {
|
|
34
|
+
summary = "review";
|
|
35
|
+
}
|
|
36
|
+
const hasUnlimited = flags.includes("unlimited");
|
|
37
|
+
const hasUnknown = flags.includes("unknown_spender");
|
|
38
|
+
if (hasUnlimited || (hasUnknown && policy.unknown_payee === "deny")) {
|
|
39
|
+
summary = "revoke_recommended";
|
|
40
|
+
}
|
|
41
|
+
return { item, flags, summary };
|
|
42
|
+
});
|
|
43
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { evaluateOutstandingAuths } from "./evaluate.js";
|
|
2
|
+
export { listOutstandingAuths } from "./scan.js";
|
|
3
|
+
export type { ScanInput } from "./scan.js";
|
|
4
|
+
export { createServer } from "./server.js";
|
|
5
|
+
export { createRpcClient, resolveRpcUrl } from "./rpc.js";
|
|
6
|
+
export type { JsonRpcClient } from "./rpc.js";
|
|
7
|
+
export * from "./types.js";
|
|
8
|
+
export * from "./constants.js";
|
|
9
|
+
export * from "./abis.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { evaluateOutstandingAuths } from "./evaluate.js";
|
|
2
|
+
export { listOutstandingAuths } from "./scan.js";
|
|
3
|
+
export { createServer } from "./server.js";
|
|
4
|
+
export { createRpcClient, resolveRpcUrl } from "./rpc.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./constants.js";
|
|
7
|
+
export * from "./abis.js";
|
package/dist/rpc.d.ts
ADDED
package/dist/rpc.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export function createRpcClient(url) {
|
|
2
|
+
let id = 0;
|
|
3
|
+
return {
|
|
4
|
+
async request(method, params) {
|
|
5
|
+
const body = {
|
|
6
|
+
jsonrpc: "2.0",
|
|
7
|
+
id: ++id,
|
|
8
|
+
method,
|
|
9
|
+
params,
|
|
10
|
+
};
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: { "content-type": "application/json" },
|
|
14
|
+
body: JSON.stringify(body),
|
|
15
|
+
});
|
|
16
|
+
if (!res.ok) {
|
|
17
|
+
throw new Error(`RPC HTTP ${res.status} ${res.statusText} for ${method}`);
|
|
18
|
+
}
|
|
19
|
+
const json = (await res.json());
|
|
20
|
+
if (json.error) {
|
|
21
|
+
throw new Error(`RPC error ${json.error.code}: ${json.error.message}`);
|
|
22
|
+
}
|
|
23
|
+
return json.result;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function resolveRpcUrl(network, env = process.env) {
|
|
28
|
+
const override = env.PAYSTAGE_RPC_URL;
|
|
29
|
+
if (override && override.trim().length > 0) {
|
|
30
|
+
return override.trim();
|
|
31
|
+
}
|
|
32
|
+
switch (network) {
|
|
33
|
+
case "eip155:8453":
|
|
34
|
+
return "https://mainnet.base.org";
|
|
35
|
+
case "eip155:84532":
|
|
36
|
+
return "https://sepolia.base.org";
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`No default RPC URL for network ${network}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/scan.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthItem } from "./types.js";
|
|
2
|
+
import type { JsonRpcClient } from "./rpc.js";
|
|
3
|
+
export interface ScanInput {
|
|
4
|
+
wallet: string;
|
|
5
|
+
network: string;
|
|
6
|
+
tokens: string[];
|
|
7
|
+
spenders: string[];
|
|
8
|
+
rpc: JsonRpcClient;
|
|
9
|
+
includePermit2?: boolean;
|
|
10
|
+
eip3009Nonces?: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare function listOutstandingAuths(input: ScanInput): Promise<AuthItem[]>;
|
package/dist/scan.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { encodeAllowance, encodePermit2Allowance, encodeAuthorizationState, decodeUint256, decodePermit2Allowance, decodeBool, } from "./abis.js";
|
|
2
|
+
import { PERMIT2, USDC_BASE, USDC_SEPOLIA } from "./constants.js";
|
|
3
|
+
function usdcForNetwork(network) {
|
|
4
|
+
if (network === "eip155:8453")
|
|
5
|
+
return USDC_BASE;
|
|
6
|
+
if (network === "eip155:84532")
|
|
7
|
+
return USDC_SEPOLIA;
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
10
|
+
async function ethCall(rpc, to, data) {
|
|
11
|
+
const result = await rpc.request("eth_call", [{ to, data }, "latest"]);
|
|
12
|
+
if (typeof result !== "string") {
|
|
13
|
+
throw new Error(`eth_call returned non-string for ${to}`);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
export async function listOutstandingAuths(input) {
|
|
18
|
+
const { wallet, network, tokens, spenders, rpc, includePermit2 = true, eip3009Nonces, } = input;
|
|
19
|
+
const items = [];
|
|
20
|
+
for (const token of tokens) {
|
|
21
|
+
for (const spender of spenders) {
|
|
22
|
+
const data = encodeAllowance(wallet, spender);
|
|
23
|
+
const raw = await ethCall(rpc, token, data);
|
|
24
|
+
const amount = decodeUint256(raw);
|
|
25
|
+
if (amount > 0n) {
|
|
26
|
+
items.push({
|
|
27
|
+
kind: "erc20_allowance",
|
|
28
|
+
token,
|
|
29
|
+
owner: wallet,
|
|
30
|
+
spender,
|
|
31
|
+
amount,
|
|
32
|
+
network,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (includePermit2) {
|
|
38
|
+
for (const token of tokens) {
|
|
39
|
+
for (const spender of spenders) {
|
|
40
|
+
const data = encodePermit2Allowance(wallet, token, spender);
|
|
41
|
+
const raw = await ethCall(rpc, PERMIT2, data);
|
|
42
|
+
const decoded = decodePermit2Allowance(raw);
|
|
43
|
+
if (decoded.amount > 0n) {
|
|
44
|
+
items.push({
|
|
45
|
+
kind: "permit2",
|
|
46
|
+
token,
|
|
47
|
+
owner: wallet,
|
|
48
|
+
spender,
|
|
49
|
+
amount: decoded.amount,
|
|
50
|
+
network,
|
|
51
|
+
expirationSeconds: decoded.expiration,
|
|
52
|
+
nonce: String(decoded.nonce),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (eip3009Nonces && eip3009Nonces.length > 0) {
|
|
59
|
+
const usdc = usdcForNetwork(network);
|
|
60
|
+
if (usdc) {
|
|
61
|
+
for (const nonce of eip3009Nonces) {
|
|
62
|
+
const data = encodeAuthorizationState(wallet, nonce);
|
|
63
|
+
const raw = await ethCall(rpc, usdc, data);
|
|
64
|
+
const invalidated = decodeBool(raw);
|
|
65
|
+
items.push({
|
|
66
|
+
kind: "eip3009",
|
|
67
|
+
token: usdc,
|
|
68
|
+
owner: wallet,
|
|
69
|
+
spender: usdc,
|
|
70
|
+
amount: 0n,
|
|
71
|
+
network,
|
|
72
|
+
nonce,
|
|
73
|
+
raw: { invalidated },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return items;
|
|
79
|
+
}
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { loadPolicy, parsePolicy } from "@paystage/policy";
|
|
4
|
+
import { evaluateOutstandingAuths } from "./evaluate.js";
|
|
5
|
+
import { listOutstandingAuths } from "./scan.js";
|
|
6
|
+
import { createRpcClient, resolveRpcUrl } from "./rpc.js";
|
|
7
|
+
import { USDC_BASE, USDC_SEPOLIA } from "./constants.js";
|
|
8
|
+
const DEFAULT_NETWORK = "eip155:8453";
|
|
9
|
+
function tokensForNetwork(policy, network) {
|
|
10
|
+
const assets = policy.allowed_assets ?? [];
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const asset of assets) {
|
|
13
|
+
if (typeof asset === "string") {
|
|
14
|
+
out.push(asset);
|
|
15
|
+
}
|
|
16
|
+
else if (asset && typeof asset === "object") {
|
|
17
|
+
const a = asset;
|
|
18
|
+
if (a.address && (!a.network || a.network === network)) {
|
|
19
|
+
out.push(a.address);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (out.length === 0) {
|
|
24
|
+
if (network === "eip155:8453")
|
|
25
|
+
out.push(USDC_BASE);
|
|
26
|
+
else if (network === "eip155:84532")
|
|
27
|
+
out.push(USDC_SEPOLIA);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
function spendersForPolicy(policy) {
|
|
32
|
+
const list = policy.allowed_spenders ?? policy.allowed_pay_to ?? [];
|
|
33
|
+
return list.slice();
|
|
34
|
+
}
|
|
35
|
+
async function resolvePolicy(args) {
|
|
36
|
+
if (args.policy !== undefined) {
|
|
37
|
+
return parsePolicy(args.policy);
|
|
38
|
+
}
|
|
39
|
+
if (args.policy_path) {
|
|
40
|
+
return loadPolicy(args.policy_path);
|
|
41
|
+
}
|
|
42
|
+
throw new Error("Either policy_path or policy must be provided");
|
|
43
|
+
}
|
|
44
|
+
const commonShape = {
|
|
45
|
+
wallet: z.string(),
|
|
46
|
+
network: z.string().optional(),
|
|
47
|
+
tokens: z.array(z.string()).optional(),
|
|
48
|
+
spenders: z.array(z.string()).optional(),
|
|
49
|
+
policy_path: z.string().optional(),
|
|
50
|
+
policy: z.unknown().optional(),
|
|
51
|
+
eip3009_nonces: z.array(z.string()).optional(),
|
|
52
|
+
rpc_url: z.string().optional(),
|
|
53
|
+
};
|
|
54
|
+
export function createServer() {
|
|
55
|
+
const server = new McpServer({
|
|
56
|
+
name: "paystage-auth-watch",
|
|
57
|
+
version: "0.1.0",
|
|
58
|
+
});
|
|
59
|
+
server.tool("list_outstanding_auths", "List outstanding token authorizations for a wallet", commonShape, async (args) => {
|
|
60
|
+
const policy = await resolvePolicy(args);
|
|
61
|
+
const network = args.network ?? DEFAULT_NETWORK;
|
|
62
|
+
const tokens = args.tokens ?? tokensForNetwork(policy, network);
|
|
63
|
+
const spenders = args.spenders ?? spendersForPolicy(policy);
|
|
64
|
+
const rpcUrl = args.rpc_url ?? resolveRpcUrl(network);
|
|
65
|
+
const rpc = createRpcClient(rpcUrl);
|
|
66
|
+
const items = await listOutstandingAuths({
|
|
67
|
+
wallet: args.wallet,
|
|
68
|
+
network,
|
|
69
|
+
tokens,
|
|
70
|
+
spenders,
|
|
71
|
+
rpc,
|
|
72
|
+
eip3009Nonces: args.eip3009_nonces,
|
|
73
|
+
});
|
|
74
|
+
const serialized = items.map((i) => ({
|
|
75
|
+
...i,
|
|
76
|
+
amount: i.amount.toString(),
|
|
77
|
+
}));
|
|
78
|
+
return {
|
|
79
|
+
content: [
|
|
80
|
+
{
|
|
81
|
+
type: "text",
|
|
82
|
+
text: JSON.stringify({ items: serialized }, null, 2),
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
server.tool("evaluate_outstanding_auths", "List and evaluate outstanding token authorizations against a policy", commonShape, async (args) => {
|
|
88
|
+
const policy = await resolvePolicy(args);
|
|
89
|
+
const network = args.network ?? DEFAULT_NETWORK;
|
|
90
|
+
const tokens = args.tokens ?? tokensForNetwork(policy, network);
|
|
91
|
+
const spenders = args.spenders ?? spendersForPolicy(policy);
|
|
92
|
+
const rpcUrl = args.rpc_url ?? resolveRpcUrl(network);
|
|
93
|
+
const rpc = createRpcClient(rpcUrl);
|
|
94
|
+
const items = await listOutstandingAuths({
|
|
95
|
+
wallet: args.wallet,
|
|
96
|
+
network,
|
|
97
|
+
tokens,
|
|
98
|
+
spenders,
|
|
99
|
+
rpc,
|
|
100
|
+
eip3009Nonces: args.eip3009_nonces,
|
|
101
|
+
});
|
|
102
|
+
const results = evaluateOutstandingAuths(items, policy);
|
|
103
|
+
const serialized = results.map((r) => ({
|
|
104
|
+
item: { ...r.item, amount: r.item.amount.toString() },
|
|
105
|
+
flags: r.flags,
|
|
106
|
+
summary: r.summary,
|
|
107
|
+
}));
|
|
108
|
+
return {
|
|
109
|
+
content: [
|
|
110
|
+
{
|
|
111
|
+
type: "text",
|
|
112
|
+
text: JSON.stringify({ results: serialized }, null, 2),
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return server;
|
|
118
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type AuthKind = "erc20_allowance" | "permit2" | "eip3009";
|
|
2
|
+
export interface AuthItem {
|
|
3
|
+
kind: AuthKind;
|
|
4
|
+
token: string;
|
|
5
|
+
owner: string;
|
|
6
|
+
spender: string;
|
|
7
|
+
amount: bigint;
|
|
8
|
+
network: string;
|
|
9
|
+
expirationSeconds?: number;
|
|
10
|
+
nonce?: string;
|
|
11
|
+
raw?: unknown;
|
|
12
|
+
}
|
|
13
|
+
export type AuthFlag = "unlimited" | "unknown_spender" | "stale" | "expired";
|
|
14
|
+
export interface EvaluateAuthResult {
|
|
15
|
+
item: AuthItem;
|
|
16
|
+
flags: AuthFlag[];
|
|
17
|
+
summary: "ok" | "review" | "revoke_recommended";
|
|
18
|
+
}
|
|
19
|
+
export interface ScanInput {
|
|
20
|
+
owner: string;
|
|
21
|
+
network: string;
|
|
22
|
+
tokens?: string[];
|
|
23
|
+
spenders?: string[];
|
|
24
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paystage/auth-watch",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "List and evaluate outstanding ERC-20 / Permit2 / EIP-3009 authorizations for an agent wallet (read-only)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"paystage-auth-watch": "./dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": ["dist", "server.json"],
|
|
19
|
+
"mcpName": "xyz.paystage/auth-watch",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"mcp",
|
|
25
|
+
"x402",
|
|
26
|
+
"agent-payments",
|
|
27
|
+
"usdc",
|
|
28
|
+
"base",
|
|
29
|
+
"auth-watch",
|
|
30
|
+
"permit2"
|
|
31
|
+
],
|
|
32
|
+
"homepage": "https://paystage.xyz",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/base-buzz/paystage.git",
|
|
36
|
+
"directory": "packages/auth-watch"
|
|
37
|
+
},
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/base-buzz/paystage/issues"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsc",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"typecheck": "tsc --noEmit",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
52
|
+
"@paystage/policy": "0.1.0",
|
|
53
|
+
"zod": "^3.23.8"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^20.14.0",
|
|
57
|
+
"typescript": "^5.5.4",
|
|
58
|
+
"vitest": "^2.0.5"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "xyz.paystage/auth-watch",
|
|
4
|
+
"title": "PayStage Auth Watch",
|
|
5
|
+
"description": "Read-only MCP tools to list and flag outstanding ERC-20, Permit2, and EIP-3009 auths",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://paystage.xyz",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/base-buzz/paystage",
|
|
10
|
+
"source": "github",
|
|
11
|
+
"subfolder": "packages/auth-watch"
|
|
12
|
+
},
|
|
13
|
+
"packages": [
|
|
14
|
+
{
|
|
15
|
+
"registryType": "npm",
|
|
16
|
+
"registryBaseUrl": "https://registry.npmjs.org",
|
|
17
|
+
"identifier": "@paystage/auth-watch",
|
|
18
|
+
"version": "0.1.0",
|
|
19
|
+
"transport": {
|
|
20
|
+
"type": "stdio"
|
|
21
|
+
},
|
|
22
|
+
"environmentVariables": [
|
|
23
|
+
{
|
|
24
|
+
"name": "PAYSTAGE_POLICY_PATH",
|
|
25
|
+
"description": "Path to policy.json spending rules",
|
|
26
|
+
"isRequired": false
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "PAYSTAGE_RPC_URL",
|
|
30
|
+
"description": "Base RPC URL override",
|
|
31
|
+
"isRequired": false
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|