z-zero-mcp-server 1.10.3 → 1.11.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/dist/types.d.ts CHANGED
@@ -30,15 +30,17 @@ export interface CardData {
30
30
  authorized_amount?: number;
31
31
  intent_id?: string;
32
32
  intent_hash?: string;
33
+ merchant_domain?: string | null;
33
34
  error?: string;
34
35
  message?: string;
35
36
  }
36
- export type PaymentOutcome = 'confirmed' | 'declined' | 'unconfirmed' | 'not_submitted' | 'no_fields' | 'error';
37
+ export type PaymentOutcome = 'confirmed' | 'declined' | 'unconfirmed' | 'not_submitted' | 'no_fields' | 'blocked' | 'error';
37
38
  export interface PaymentResult {
38
39
  success: boolean;
39
40
  status: PaymentOutcome;
40
41
  message: string;
41
42
  receipt_id?: string;
43
+ page_detail?: string;
42
44
  amount?: number;
43
45
  }
44
46
  export interface CheckoutHints {
@@ -1,16 +1,7 @@
1
1
  import type { CardData, PaymentResult } from "./types.js";
2
+ import { isPrivateIp, expandIpv6 } from "./lib/url-guard.js";
2
3
  import * as https from "node:https";
3
4
  declare function assertSafeUcpUrl(rawUrl: string, what: string): void;
4
- /** Expand any IPv6 literal (::, zone id, embedded dotted IPv4) to 8 numeric groups; null if malformed. */
5
- declare function expandIpv6(ip: string): number[] | null;
6
- /**
7
- * RFC1918 / loopback / link-local / CGNAT / multicast / unspecified for IPv4;
8
- * for IPv6: ::/96 (unspecified, loopback, deprecated IPv4-compatible), IPv4-mapped
9
- * ::ffff:0:0/96 in ANY spelling (dotted or hex — "::ffff:7f00:1" IS 127.0.0.1),
10
- * NAT64 64:ff9b::/96, ULA fc00::/7, link-local fe80::/10, site-local fec0::/10,
11
- * multicast ff00::/8. Unparseable literals are treated as unsafe.
12
- */
13
- declare function isPrivateIp(ip: string): boolean;
14
5
  type ResolvedAddr = {
15
6
  address: string;
16
7
  family: number;
@@ -54,6 +54,7 @@ exports.ucpCreateCheckout = ucpCreateCheckout;
54
54
  exports.ucpGetCheckout = ucpGetCheckout;
55
55
  exports.ucpPayCheckout = ucpPayCheckout;
56
56
  const with_timeout_js_1 = require("./lib/with-timeout.js");
57
+ const failure_taxonomy_js_1 = require("./failure_taxonomy.js");
57
58
  const url_guard_js_1 = require("./lib/url-guard.js");
58
59
  const node_dns_1 = require("node:dns");
59
60
  const node_net_1 = require("node:net");
@@ -74,75 +75,13 @@ function assertSafeUcpUrl(rawUrl, what) {
74
75
  const host = new URL(rawUrl).hostname;
75
76
  const bare = host.replace(/^\[|\]$/g, "");
76
77
  // Hostnames are vetted at resolve time (resolvePublic); only IP LITERALS are judged here.
77
- if (/^localhost$/i.test(host) || ((0, node_net_1.isIP)(bare) && isPrivateIp(bare)))
78
+ if (/^localhost$/i.test(host) || ((0, node_net_1.isIP)(bare) && (0, url_guard_js_1.isPrivateIp)(bare)))
78
79
  throw new Error(`SSRF blocked host: ${host}`);
79
80
  }
80
81
  catch (err) {
81
82
  throw new Error(`UCP ${what} rejected: ${err?.message ?? err}`);
82
83
  }
83
84
  }
84
- /** Expand any IPv6 literal (::, zone id, embedded dotted IPv4) to 8 numeric groups; null if malformed. */
85
- function expandIpv6(ip) {
86
- let str = ip.toLowerCase().split("%")[0];
87
- const dotted = str.match(/^(.*:)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);
88
- if (dotted) {
89
- const v4 = dotted[2].split(".").map(Number);
90
- if (v4.some((n) => n > 255))
91
- return null;
92
- str = dotted[1] + ((v4[0] << 8) | v4[1]).toString(16) + ":" + ((v4[2] << 8) | v4[3]).toString(16);
93
- }
94
- const halves = str.split("::");
95
- if (halves.length > 2)
96
- return null;
97
- const head = halves[0] ? halves[0].split(":") : [];
98
- const tail = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
99
- const fill = halves.length === 2 ? 8 - head.length - tail.length : 0;
100
- if (fill < 0 || (halves.length === 1 && head.length !== 8))
101
- return null;
102
- const groups = [...head, ...new Array(fill).fill("0"), ...tail].map((g) => (/^[0-9a-f]{1,4}$/.test(g) ? parseInt(g, 16) : NaN));
103
- if (groups.length !== 8 || groups.some((n) => Number.isNaN(n)))
104
- return null;
105
- return groups;
106
- }
107
- /**
108
- * RFC1918 / loopback / link-local / CGNAT / multicast / unspecified for IPv4;
109
- * for IPv6: ::/96 (unspecified, loopback, deprecated IPv4-compatible), IPv4-mapped
110
- * ::ffff:0:0/96 in ANY spelling (dotted or hex — "::ffff:7f00:1" IS 127.0.0.1),
111
- * NAT64 64:ff9b::/96, ULA fc00::/7, link-local fe80::/10, site-local fec0::/10,
112
- * multicast ff00::/8. Unparseable literals are treated as unsafe.
113
- */
114
- function isPrivateIp(ip) {
115
- const v = (0, node_net_1.isIP)(ip);
116
- if (v === 4) {
117
- const [a, b] = ip.split(".").map(Number);
118
- return a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31)
119
- || (a === 192 && b === 168) || (a === 100 && b >= 64 && b <= 127) || a >= 224;
120
- }
121
- if (v === 6) {
122
- const g = expandIpv6(ip);
123
- if (!g)
124
- return true;
125
- const v4 = (hi, lo) => `${hi >> 8}.${hi & 255}.${lo >> 8}.${lo & 255}`;
126
- const zero5 = g[0] === 0 && g[1] === 0 && g[2] === 0 && g[3] === 0 && g[4] === 0;
127
- if (zero5 && g[5] === 0xffff)
128
- return isPrivateIp(v4(g[6], g[7])); // IPv4-mapped, any spelling
129
- if (zero5 && g[5] === 0)
130
- return true; // ::, ::1, ::a.b.c.d
131
- if (g[0] === 0x64 && g[1] === 0xff9b && g[2] === 0 && g[3] === 0 && g[4] === 0 && g[5] === 0) {
132
- return isPrivateIp(v4(g[6], g[7])); // NAT64
133
- }
134
- if ((g[0] & 0xfe00) === 0xfc00)
135
- return true; // ULA fc00::/7
136
- if ((g[0] & 0xffc0) === 0xfe80)
137
- return true; // link-local
138
- if ((g[0] & 0xffc0) === 0xfec0)
139
- return true; // site-local (deprecated)
140
- if ((g[0] & 0xff00) === 0xff00)
141
- return true; // multicast
142
- return false;
143
- }
144
- return true; // not an IP literal at all → caller must not treat as safe
145
- }
146
85
  /**
147
86
  * Resolve the host, reject if ANY address is private, and RETURN the vetted
148
87
  * addresses so the socket can be pinned to them. Resolving here and letting the
@@ -152,7 +91,7 @@ async function resolvePublic(rawUrl, what) {
152
91
  const host = new URL(rawUrl).hostname.replace(/^\[|\]$/g, "");
153
92
  const lit = (0, node_net_1.isIP)(host);
154
93
  if (lit) {
155
- if (isPrivateIp(host))
94
+ if ((0, url_guard_js_1.isPrivateIp)(host))
156
95
  throw new Error(`UCP ${what} rejected: SSRF blocked IP ${host}`);
157
96
  return [{ address: host, family: lit }];
158
97
  }
@@ -165,7 +104,7 @@ async function resolvePublic(rawUrl, what) {
165
104
  }
166
105
  if (!addrs.length)
167
106
  throw new Error(`UCP ${what} rejected: ${host} did not resolve`);
168
- const bad = addrs.find((a) => isPrivateIp(a.address));
107
+ const bad = addrs.find((a) => (0, url_guard_js_1.isPrivateIp)(a.address));
169
108
  if (bad)
170
109
  throw new Error(`UCP ${what} rejected: ${host} resolves to private address ${bad.address}`);
171
110
  return addrs;
@@ -682,6 +621,17 @@ const UCP_PAY_ENABLED = process.env.Z_ZERO_UCP_PAY_ENABLED === "1";
682
621
  * ONLY on a merchant-confirmed order (that is the caller's sole burn gate).
683
622
  */
684
623
  async function ucpPayCheckout(params) {
624
+ // A merchant error can quote the instrument back ("number=4242…"). Same rule as
625
+ // the browser lane: no card value leaves in any string (audit T13 F2 list, M.1).
626
+ const secrets = { number: params.cardData.number, cvv: params.cardData.cvv };
627
+ const r = await ucpPayCheckoutRaw(params);
628
+ return {
629
+ ...r,
630
+ message: (0, failure_taxonomy_js_1.scrubCardValues)(r.message, secrets),
631
+ ...(r.receipt_id ? { receipt_id: (0, failure_taxonomy_js_1.scrubCardValues)(r.receipt_id, secrets, { cards: "valid" }) } : {}),
632
+ };
633
+ }
634
+ async function ucpPayCheckoutRaw(params) {
685
635
  const { cardData } = params;
686
636
  if (!UCP_PAY_ENABLED) {
687
637
  // Wipe immediately — we are not going to use the card.
@@ -883,4 +833,4 @@ async function _ucpPayInner(params) {
883
833
  };
884
834
  }
885
835
  // Exposed for offline unit tests only — not part of the public bridge API.
886
- exports.__ucpInternals = { isPrivateIp, expandIpv6, assertSafeUcpUrl, summarizeCheckout, pinnedRequest };
836
+ exports.__ucpInternals = { isPrivateIp: url_guard_js_1.isPrivateIp, expandIpv6: url_guard_js_1.expandIpv6, assertSafeUcpUrl, summarizeCheckout, pinnedRequest };
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "z-zero-mcp-server",
3
- "version": "1.10.3",
3
+ "version": "1.11.0",
4
4
  "description": "Z-ZERO MCP Server — Secure JIT Virtual Card Payment tools for AI Agents (Claude, Cursor, AutoGPT) — Real Single-Use Virtual Cards, settled in USDC on Base",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
7
7
  "z-zero-mcp-server": "dist/index.js"
8
8
  },
9
9
  "scripts": {
10
- "build": "tsc",
10
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
11
11
  "start": "node dist/index.js",
12
12
  "dev": "npx tsx src/index.ts",
13
13
  "test:mock-checkout": "npm run build && node --experimental-strip-types tests/backtest_mock_checkout_e2e.mts",
14
14
  "test:ucp-offline": "npm run build && node --experimental-strip-types --test tests/ucp_bridge_offline.test.mts",
15
+ "test:domain-lock": "npm run build && node --experimental-strip-types --test tests/domain_lock.test.mts",
16
+ "test:audit-wave-m": "npm run build && bash tests/audit-wave-m/run.sh",
15
17
  "test:ucp-dryrun:live": "npm run build && node --experimental-strip-types tests/ucp_dryrun_meanblvd.mts",
16
18
  "test:ucp-smoke:live": "npm run build && node --experimental-strip-types tests/ucp_smoke_colourpop.mts",
17
19
  "prepublishOnly": "npm run build"
@@ -42,7 +44,7 @@
42
44
  "README.md"
43
45
  ],
44
46
  "dependencies": {
45
- "@modelcontextprotocol/sdk": "^1.30.0",
47
+ "@modelcontextprotocol/sdk": "^1.32.2",
46
48
  "playwright": "^1.62.0",
47
49
  "zod": "^3.25.76"
48
50
  },
@@ -1,19 +0,0 @@
1
- export interface Web3TxParams {
2
- to: string;
3
- value?: string;
4
- data?: string;
5
- chainId?: number;
6
- eip681_amount?: number;
7
- }
8
- export interface Web3DetectionResult {
9
- detected: boolean;
10
- method: "eth_sendTransaction" | "EIP-681" | null;
11
- params: Web3TxParams | null;
12
- message: string;
13
- }
14
- /**
15
- * Checks a page for Web3 payment indicators (EIP-681 or interrupted eth_sendTransaction).
16
- * Injects a mock window.ethereum (MetaMask emulation).
17
- * Returns the tx params if Web3 payment is detected, else null.
18
- */
19
- export declare function detectWeb3Payment(page: import("playwright").Page, checkoutUrl: string): Promise<Web3DetectionResult>;
@@ -1,157 +0,0 @@
1
- "use strict";
2
- // web3-detector.ts
3
- // Phase 2: Smart Routing — Web3 Payment Detector
4
- // Injects a mock window.ethereum into a checkout page, waits for Web3 tx request.
5
- // If the page calls eth_sendTransaction → capture params and return them.
6
- // If page is not Web3-aware → return null (caller falls back to Fiat JIT card).
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.detectWeb3Payment = detectWeb3Payment;
9
- const WEB3_DETECT_TIMEOUT_MS = 12_000; // 12s max to detect Web3 button click
10
- /**
11
- * Checks a page for Web3 payment indicators (EIP-681 or interrupted eth_sendTransaction).
12
- * Injects a mock window.ethereum (MetaMask emulation).
13
- * Returns the tx params if Web3 payment is detected, else null.
14
- */
15
- async function detectWeb3Payment(page, checkoutUrl) {
16
- try {
17
- // ─── Inject mock window.ethereum BEFORE page loads ───────────────────
18
- await page.addInitScript(() => {
19
- const mockEthereum = {
20
- isMetaMask: true,
21
- selectedAddress: "0x0000000000000000000000000000000000000001",
22
- chainId: "0x2105", // Base mainnet (8453)
23
- networkVersion: "8453",
24
- request: async ({ method, params }) => {
25
- if (method === "eth_requestAccounts" || method === "eth_accounts") {
26
- return ["0x0000000000000000000000000000000000000001"];
27
- }
28
- if (method === "eth_chainId")
29
- return "0x2105";
30
- if (method === "net_version")
31
- return "8453";
32
- if (method === "eth_sendTransaction") {
33
- const tx = params?.[0];
34
- window["__zzCapturedTx"] = tx;
35
- return "0xdeadbeef00000000000000000000000000000000000000000000000000000001";
36
- }
37
- if (method === "wallet_switchEthereumChain")
38
- return null;
39
- if (method === "eth_getBalance")
40
- return "0x0";
41
- window["__zzUnknownMethod_" + method] = true;
42
- return null;
43
- },
44
- on: (event, handler) => {
45
- if (event === "connect")
46
- setTimeout(() => handler({ chainId: "0x2105" }), 100);
47
- if (event === "accountsChanged")
48
- setTimeout(() => handler(["0x0000000000000000000000000000000000000001"]), 200);
49
- },
50
- removeListener: () => { },
51
- removeAllListeners: () => { },
52
- isConnected: () => true,
53
- };
54
- Object.defineProperty(window, "ethereum", {
55
- value: mockEthereum,
56
- writable: false,
57
- configurable: true,
58
- });
59
- });
60
- // ─── Navigate to page ─────────────────────────────────────────────────
61
- await page.goto(checkoutUrl, { waitUntil: "domcontentloaded", timeout: 20_000 });
62
- // ─── Strategy A: Scan for EIP-681 links ──────────────────────────────
63
- const eip681Result = await page.evaluate(() => {
64
- const links = Array.from(document.querySelectorAll("a[href]"))
65
- .map(a => a.href)
66
- .filter(href => href.startsWith("ethereum:"));
67
- const texts = [document.body.innerText ?? ""];
68
- const allText = texts.join(" ");
69
- const inlineMatch = allText.match(/ethereum:0x[0-9a-fA-F]{40}[^\s]*/);
70
- const href = links[0] ?? inlineMatch?.[0] ?? null;
71
- if (!href)
72
- return null;
73
- const contractMatch = href.match(/ethereum:(0x[0-9a-fA-F]{40})/);
74
- const chainMatch = href.match(/@(\d+)/);
75
- const uint256Match = href.match(/uint256=(\d+)/);
76
- const recipientMatch = href.match(/[?&]address=(0x[0-9a-fA-F]{40})/);
77
- return {
78
- to: recipientMatch?.[1] ?? contractMatch?.[1] ?? null,
79
- contract: contractMatch?.[1] ?? null,
80
- chainId: chainMatch ? parseInt(chainMatch[1]) : 8453,
81
- uint256: uint256Match?.[1] ?? null,
82
- raw: href,
83
- };
84
- });
85
- if (eip681Result?.to) {
86
- const usdcAmount = eip681Result.uint256
87
- ? parseInt(eip681Result.uint256) / 1_000_000 // USDC has 6 decimals
88
- : null;
89
- return {
90
- detected: true,
91
- method: "EIP-681",
92
- params: {
93
- to: eip681Result.to,
94
- chainId: eip681Result.chainId,
95
- eip681_amount: usdcAmount ?? undefined,
96
- },
97
- message: `EIP-681 payment link found. Merchant: ${eip681Result.to}, amount: ${usdcAmount} USDC.`,
98
- };
99
- }
100
- // ─── Strategy B: Wait for eth_sendTransaction after clicking "Pay" ────
101
- const web3ButtonSelectors = [
102
- 'button:has-text("MetaMask")', 'button:has-text("Pay with Crypto")',
103
- 'button:has-text("Connect Wallet")', 'button:has-text("Pay with Web3")',
104
- 'button:has-text("Pay with Wallet")', '#pay-metamask-btn',
105
- '[class*="web3"] button', '[class*="metamask"] button',
106
- ];
107
- // Click buttons sequentially, small delay to let UI reaction
108
- for (const sel of web3ButtonSelectors) {
109
- try {
110
- const btn = await page.$(sel);
111
- if (btn && await btn.isVisible()) {
112
- console.error(`[WEB3] Clicking Web3 pay button: ${sel}`);
113
- await btn.click();
114
- await page.waitForTimeout(500);
115
- }
116
- }
117
- catch { /* skip */ }
118
- }
119
- // Poll for captured tx
120
- const start = Date.now();
121
- while (Date.now() - start < WEB3_DETECT_TIMEOUT_MS) {
122
- const tx = await page.evaluate(() => {
123
- return window["__zzCapturedTx"] ?? null;
124
- });
125
- if (tx) {
126
- const capturedTx = tx;
127
- return {
128
- detected: true,
129
- method: "eth_sendTransaction",
130
- params: {
131
- to: capturedTx["to"],
132
- value: capturedTx["value"],
133
- data: capturedTx["data"],
134
- chainId: 8453,
135
- },
136
- message: `Web3 payment detected via eth_sendTransaction. Recipient: ${capturedTx["to"]}`,
137
- };
138
- }
139
- await page.waitForTimeout(500);
140
- }
141
- return {
142
- detected: false,
143
- method: null,
144
- params: null,
145
- message: "No Web3 payment gateway detected. Will proceed with JIT virtual card (Fiat) route.",
146
- };
147
- }
148
- catch (err) {
149
- const msg = err instanceof Error ? err.message : String(err);
150
- return {
151
- detected: false,
152
- method: null,
153
- params: null,
154
- message: `Detection failed: ${msg}. Defaulting to Fiat route.`,
155
- };
156
- }
157
- }