z-zero-mcp-server 1.10.4 → 1.12.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
@@ -31,16 +31,49 @@ export interface CardData {
31
31
  intent_id?: string;
32
32
  intent_hash?: string;
33
33
  merchant_domain?: string | null;
34
+ /** Set when the card was issued for an Agent Deal order (server-computed figures). */
35
+ deal?: DealFigures;
34
36
  error?: string;
35
37
  message?: string;
36
38
  }
37
- export type PaymentOutcome = 'confirmed' | 'declined' | 'unconfirmed' | 'not_submitted' | 'no_fields' | 'blocked' | 'error';
39
+ /** A deal order's figures, as the server holds them. USD. */
40
+ export interface DealFigures {
41
+ order_id: string;
42
+ /** L — what the checkout page shows BEFORE the discount code. */
43
+ checkout_total: number;
44
+ discount: number;
45
+ /** C — what the page must show AFTER the code; the card is for exactly this. */
46
+ card_amount: number;
47
+ }
48
+ /**
49
+ * What the card filler needs to pay a deal order: the single-use code (a secret of the same
50
+ * kind as the card number — never returned, logged or echoed) and the most the page may show
51
+ * once it is applied. `code: null` = a deal with nothing to type; the total is still checked.
52
+ */
53
+ export interface DealPayment {
54
+ code: string | null;
55
+ /** C — the page total must be at or under this once the code is on. */
56
+ maxTotal: number;
57
+ /** L — the page total must not be above this BEFORE the code (what the order was priced for). */
58
+ listTotal: number;
59
+ /** D — the page total must come down by at least this for the code to count as applied. */
60
+ discount: number;
61
+ }
62
+ export type PaymentOutcome = 'confirmed' | 'declined' | 'unconfirmed' | 'not_submitted' | 'no_fields' | 'blocked' | 'deal_not_applied' | 'error';
38
63
  export interface PaymentResult {
39
64
  success: boolean;
40
65
  status: PaymentOutcome;
41
66
  message: string;
42
67
  receipt_id?: string;
68
+ page_detail?: string;
43
69
  amount?: number;
70
+ /**
71
+ * Deal orders, attempt NOT confirmed: what the caller does with the order's discount code.
72
+ * 'release' — no order can exist (nothing was submitted, or the shop declined): ask the server to delete the code at the shop now.
73
+ * 'hold' — Pay was pressed and the outcome is unknown: leave the code alone until the order's fate is known.
74
+ * Internal to the MCP: never put in a tool result.
75
+ */
76
+ deal_code_next?: 'release' | 'hold';
44
77
  }
45
78
  export interface CheckoutHints {
46
79
  pre_steps?: string[];
@@ -52,6 +85,9 @@ export interface CheckoutHints {
52
85
  cvv_selector?: string;
53
86
  name_selector?: string;
54
87
  submit_selector?: string;
88
+ discount_selector?: string;
89
+ discount_apply_selector?: string;
90
+ total_selector?: string;
55
91
  payment_type?: string;
56
92
  notes?: string;
57
93
  }
@@ -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");
@@ -620,6 +621,17 @@ const UCP_PAY_ENABLED = process.env.Z_ZERO_UCP_PAY_ENABLED === "1";
620
621
  * ONLY on a merchant-confirmed order (that is the caller's sole burn gate).
621
622
  */
622
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) {
623
635
  const { cardData } = params;
624
636
  if (!UCP_PAY_ENABLED) {
625
637
  // Wipe immediately — we are not going to use the card.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "z-zero-mcp-server",
3
- "version": "1.10.4",
3
+ "version": "1.12.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": {
@@ -13,6 +13,8 @@
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
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",
17
+ "test:agent-deal": "npm run build && bash tests/agent-deal/run.sh",
16
18
  "test:ucp-dryrun:live": "npm run build && node --experimental-strip-types tests/ucp_dryrun_meanblvd.mts",
17
19
  "test:ucp-smoke:live": "npm run build && node --experimental-strip-types tests/ucp_smoke_colourpop.mts",
18
20
  "prepublishOnly": "npm run build"
@@ -43,7 +45,7 @@
43
45
  "README.md"
44
46
  ],
45
47
  "dependencies": {
46
- "@modelcontextprotocol/sdk": "^1.30.0",
48
+ "@modelcontextprotocol/sdk": "^1.32.2",
47
49
  "playwright": "^1.62.0",
48
50
  "zod": "^3.25.76"
49
51
  },
@@ -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
- }