Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/favicon.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 47 additions & 4 deletions scripts/check-cross-rail-v2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { xchacha20poly1305 } from "@noble/ciphers/chacha";
import { decodeBolt11 } from "@arkade-os/swap/advanced";
import { createMcpWalletTool, WALLET_TOOL } from "../src/mcp-wallet-tool.mjs";
import { instructions } from "../src/mcp-instructions.mjs";
import { requestShape } from "../src/agent-kernel-runtime.mjs";
import {
resolveWalletOrigin,
serviceIndexHtml,
Expand Down Expand Up @@ -907,19 +908,61 @@ try {
assert.ok(sitemap.body.includes(`<loc>${origin}/llms.txt</loc>`));
}

for (const p of ["/", "/llms.txt", "/skill.md", "/openapi.json", "/robots.txt", "/sitemap.xml", "/mcp", "/v1/wallet"]) {
for (const p of ["/", "/llms.txt", "/skill.md", "/openapi.json", "/robots.txt", "/sitemap.xml", "/favicon.svg", "/favicon.ico", "/apple-touch-icon.png", "/mcp", "/v1/wallet"]) {
const headRes = await httpReq(p, { method: "HEAD", headers: { Host: "wallet.nuri.com" } });
assert.equal(headRes.status, 200);
assert.equal(headRes.status, 200, `HEAD ${p} should return 200`);
assert.equal(headRes.body, "");
}

// Plain JSON REST /v1/* tests (zero MCP setup): anonymous balance returns connect_required
// Real Nuri brand icons + 1-click install links on homepage
const svgRes = await httpReq("/favicon.svg", { headers: { Host: "wallet.nuri.com" } });
assert.equal(svgRes.status, 200);
assert.match(svgRes.headers["content-type"], /image\/svg\+xml/);
assert.ok(svgRes.body.includes("#F25E0D"), "favicon.svg must be real Nuri brand SVG");

const homeHtml = await httpReq("/", { headers: { Host: "wallet.nuri.com" } });
assert.ok(homeHtml.body.includes('href="/favicon.svg"'));
assert.ok(homeHtml.body.includes("cursor://anysphere.cursor-deeplink/mcp/install"));
assert.ok(homeHtml.body.includes("vscode:mcp/install?"));

// MCP protocol version negotiation + icons + open CORS for claude.ai / ChatGPT / MCP Inspector
for (const ver of ["2025-03-26", "2025-06-18", "2025-11-25"]) {
const initRes = await httpReq("/mcp", {
method: "POST",
headers: { Host: "wallet.nuri.com", Origin: "https://claude.ai", "Content-Type": "application/json" },
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: ver, capabilities: {}, clientInfo: { name: "test", version: "1" } } }),
});
assert.equal(initRes.status, 200);
assert.equal(initRes.headers["access-control-allow-origin"], "*");
assert.match(initRes.headers["access-control-allow-headers"], /mcp-session-id/i);
const initJson = JSON.parse(initRes.body);
assert.equal(initJson.result.protocolVersion, ver);
assert.ok(Array.isArray(initJson.result.serverInfo.icons) && initJson.result.serverInfo.icons.length >= 1);
assert.equal(initJson.result.serverInfo.icons[0].src, "https://wallet.nuri.com/favicon.svg");
assert.ok(initJson.result.instructions.includes("ALWAYS show BOTH rails"));
}

// DELETE /mcp returns 204 cleanly for stateless Streamable HTTP clients
const delRes = await httpReq("/mcp", { method: "DELETE", headers: { Host: "wallet.nuri.com", Origin: "https://claude.ai" } });
assert.equal(delRes.status, 204);
assert.equal(delRes.headers["access-control-allow-origin"], "*");

// JSON-string body auto-detection in requestShape (prevents Content-Type: text/plain 400 on LLM JSON strings)
const jsonStrShape = requestShape({ method: "POST", body: '{"model":"gemini-4-argon-high","messages":[]}' });
assert.equal(jsonStrShape.headers["Content-Type"], "application/json");
const plainStrShape = requestShape({ method: "POST", body: "hello world" });
assert.equal(plainStrShape.headers["Content-Type"], "text/plain; charset=utf-8");
const explicitTypeShape = requestShape({ method: "POST", body: '{"a":1}', contentType: "application/merge-patch+json" });
assert.equal(explicitTypeShape.headers["Content-Type"], "application/merge-patch+json");

// Plain JSON REST /v1/* tests (zero MCP setup): anonymous balance returns connect_required + open CORS
const restAnon = await httpReq("/v1/wallet", {
method: "POST",
headers: { Host: "wallet.paymentrequired.com", "Content-Type": "application/json" },
headers: { Host: "wallet.paymentrequired.com", Origin: "https://chatgpt.com", "Content-Type": "application/json" },
body: JSON.stringify({ action: "balance" }),
});
assert.equal(restAnon.status, 200);
assert.equal(restAnon.headers["access-control-allow-origin"], "*");
const restAnonJson = JSON.parse(restAnon.body);
assert.equal(restAnonJson.status, "connect_required");
assert.ok(restAnonJson.approval_url);
Expand Down
16 changes: 15 additions & 1 deletion src/agent-kernel-runtime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,26 @@ function merchantUrl(value) {
// Content-Digest, so the same bytes are bound to the unpaid and the paid request.
const METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'];
const ROUTER_CHAT_URL = 'https://router.paymentrequired.com/v1/chat/completions';
function looksLikeJsonString(value) {
if (typeof value !== 'string') return false;
const trimmed = value.trim();
if (!trimmed || (trimmed[0] !== '{' && trimmed[0] !== '[')) return false;
try {
const parsed = JSON.parse(trimmed);
return parsed !== null && typeof parsed === 'object';
} catch {
return false;
}
}
export function requestShape({ method = 'GET', body, contentType } = {}) {
check(METHODS.includes(method), 'invalid_http_method');
if (body === undefined || body === null) return { method, headers: {}, bytes: null };
const bytes = Buffer.from(typeof body === 'string' ? body : JSON.stringify(body), 'utf8');
check(bytes.length <= 262144 && !['GET', 'HEAD'].includes(method), 'invalid_request_body');
return { method, bytes, headers: { 'Content-Type': contentType || (typeof body === 'string' ? 'text/plain; charset=utf-8' : 'application/json'),
const resolvedType = contentType || (typeof body === 'string'
? (looksLikeJsonString(body) ? 'application/json' : 'text/plain; charset=utf-8')
: 'application/json');
return { method, bytes, headers: { 'Content-Type': resolvedType,
'Content-Length': String(bytes.length), 'Content-Digest': `sha-256=:${createHash('sha256').update(bytes).digest('base64')}:` } };
}
// Every merchant request (quote and paid) names its client: live 2026-09-29 a merchant behind an AWS load
Expand Down
2 changes: 1 addition & 1 deletion src/agent-lightning-pay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export function createPrfHttp402Payer({
const first = await merchantFetch(url, { headers: {}, shape });
if (first.status !== 402) {
return {
status: "done",
status: first.status >= 200 && first.status < 300 ? "done" : "failed",
paid: false,
http_status: first.status,
resource: formatResourceBody(first),
Expand Down
8 changes: 4 additions & 4 deletions src/mcp-instructions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export function instructions(toolNames = ALWAYS_TOOLS) {
${WHICH.wallet}

RULES
1. No wallet_key yet: call wallet {action: "balance"}. Show BOTH create_url (new to Nuri) and approval_url (existing Passkey). After approval, repeat wallet {action: "balance", request_id} to get your deterministic wallet_key (npw1_...).
2. Hold a wallet_key: send it on every call (balance, receive, pay, history).
3. wallet pay accepts ANY destination in \`to\`: https:// 402 API (x402/L402/MPP), lnbc... BOLT11, user@domain, bc1.../bitcoin:... on-chain Bitcoin, ark1... Arkade, or 0x... Base USDC. Always include a short request_id.
4. Over-cap error: STOP and tell the person the exact price; NEVER raise max_amount/max_sats without asking them first. Once they approve, send again with a NEW request_id and a higher max_amount. Other failures: report the exact error. Do what next says.
1. No wallet_key: call wallet {action: "balance"}. Show create_url (new) and approval_url (existing). After approval, repeat balance with same request_id to get wallet_key (npw1_...).
2. Hold wallet_key: send on every call. On balance/connect, ALWAYS show BOTH rails: Bitcoin (sats + arkade_address + Lightning receive) AND Base USDC (available + 0x address).
3. wallet pay accepts any \`to\`: https:// 402 API, lnbc..., user@domain, bc1.../bitcoin:..., ark1..., or 0x.... Include a short request_id.
4. Over-cap error: STOP, state exact price; never raise max_amount/max_sats without asking. After approval, retry with NEW request_id. Other errors: report verbatim. Follow next.

EXAMPLES
${EXAMPLES.filter(([need]) => need.every(name => here.has(name))).map(([, text]) => `- ${text}`).join("\n")}
Expand Down
22 changes: 18 additions & 4 deletions src/mcp-wallet-prf-v2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ export function createPrfWalletCoordinator({

return {
available: unitsToDecimal(String(usdcUnits), 6),
usdc: unitsToDecimal(String(usdcUnits), 6),
address: walletRecord.safeAddress,
owner_address: walletRecord.mainEoa,
sats: Number(arkadeState.sats),
Expand All @@ -691,6 +692,13 @@ export function createPrfWalletCoordinator({
};
}

function dualBalanceSummary(balances) {
const usdc = balances.available ?? "0";
const sats = balances.sats ?? 0;
const btcAddr = balances.arkade_address ? ` Arkade ${balances.arkade_address}` : "";
return `Show BOTH rails to the user: Base USDC ${usdc} (${balances.address}) AND Bitcoin ${sats} sats / ${balances.btc || "0"} BTC (${btcAddr ? `${btcAddr.trim()}; ` : ""}Lightning invoice via receive rail="lightning").`;
}

async function startOrPollOnboarding({ requestId, slotIndex = 0, policy = DEFAULT_GRANT_POLICY } = {}) {
const db = ensureStore();
if (requestId) {
Expand All @@ -706,8 +714,8 @@ export function createPrfWalletCoordinator({
...(issuedKey ? { wallet_key: issuedKey } : {}),
...balances,
next: issuedKey
? "Save wallet_key and send it on every wallet call."
: "Wallet already connected; use the wallet_key returned earlier.",
? `Save wallet_key and send it on every wallet call. ${dualBalanceSummary(balances)}`
: `Wallet already connected; use the wallet_key returned earlier. ${dualBalanceSummary(balances)}`,
};
}
if (existing.status === "expired") {
Expand Down Expand Up @@ -832,7 +840,7 @@ export function createPrfWalletCoordinator({
status: "done",
wallet_key: issuedKey,
...balances,
next: "Save wallet_key and send it on every later wallet call.",
next: `Save wallet_key and send it on every later wallet call. ${dualBalanceSummary(balances)}`,
};
}
}
Expand Down Expand Up @@ -882,7 +890,7 @@ export function createPrfWalletCoordinator({
ok: true,
status: "done",
...balances,
next: "Holdings shown.",
next: `Holdings shown. ${dualBalanceSummary(balances)}`,
};
}
return await startOrPollOnboarding({
Expand Down Expand Up @@ -1388,6 +1396,12 @@ export function createPrfWalletCoordinator({
ok: res.status !== "failed",
status: res.status,
request_id: reqId,
...(res.http_status !== undefined ? { http_status: res.http_status } : {}),
...(res.status === "failed" && res.http_status !== undefined
? {
error: `Endpoint returned HTTP ${res.http_status}${res.paid ? " after payment" : " (not paid)"}. Inspect resource.body for the exact server error.`,
}
: {}),
...(res.protocol ? { protocol: res.protocol } : {}),
...(res.rail ? { rail: res.rail } : {}),
...(res.funded_from ? { funded_from: res.funded_from } : {}),
Expand Down
2 changes: 2 additions & 0 deletions src/mcp-wallet-tool.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,14 @@ export const WALLET_TOOL = {
model: { type: "string" },
error: { type: "string", description: "One plain sentence saying what went wrong and the next thing to do, when ok is false." },
available: { type: "string", description: "Base USDC balance." },
usdc: { type: "string", description: "Base USDC balance (same as available)." },
sats: { type: "integer", description: "Spendable Bitcoin balance on Arkade in satoshis." },
btc: { type: "string", description: "Spendable Bitcoin balance on Arkade in BTC." },
address: { type: "string", description: "2-of-4 Base Safe USDC address." },
arkade_address: { type: "string", description: "2-of-2 Nuri Arkade off-chain Bitcoin address (`ark1...`)." },
owner_address: { type: "string", description: "Main Nuri wallet EOA that granted this agent wallet." },
wallet_key: { type: "string", description: "Deterministic wallet key (`npw1_...`). Save and send on every call." },
http_status: { type: "integer", description: "HTTP status code returned by the target endpoint." },
rail: { type: "string" },
funded_from: { type: "string", description: "Source rail when cross-rail auto-conversion paid the target." },
cross_rail: { type: "boolean" },
Expand Down
Loading
Loading