A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.

0 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-browser.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-browser.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-browser.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 site icons (favicons) in tabs, address bar suggestions and the bookmarks panel 7249579 16 hours ago History
cli.ts · 2.4 KB · 66 lines
1#!/usr/bin/env node
2/**
3 * `x402-proxy` — run the payment proxy on 127.0.0.1:8402.
4 *
5 * Uses a throwaway test key by default; wire a real signer (session hot wallet) once
6 * that task lands. Prints where to trust the root CA so https interception works.
7 */
8
9import { join } from "node:path";
10import { homedir } from "node:os";
11import { privateKeyToAccount } from "viem/accounts";
12import { PolicyEngine, Ledger, X402Engine, formatUsd } from "@dbbasic/x402-engine";
13import { X402Proxy } from "./server.js";
14
15const PORT = Number(process.env.X402_PROXY_PORT) || 8402;
16
17// TEST KEY ONLY. Never fund this. Replaced by the session hot wallet task.
18const TEST_KEY = (process.env.X402_PRIVATE_KEY ??
19 "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d") as `0x${string}`;
20
21const account = privateKeyToAccount(TEST_KEY);
22const policy = new PolicyEngine();
23const ledger = new Ledger();
24
25const engine = new X402Engine({
26 account,
27 policy,
28 ledger,
29 approve: async (req) => {
30 // Headless: anything needing a prompt is refused. The browser wires a real UI here.
31 console.log(`[x402] prompt required, refusing (headless): ${req.reason}`);
32 return false;
33 },
34 onEvent: (e) => {
35 if (e.type === "paid") {
36 const r = e.receipt;
37 console.log(`[x402] paid ${formatUsd(r.priceUsdMicro)} ${r.assetSymbol} -> ${r.destOrigin} (${r.status}${r.txHash ? " " + r.txHash : ""})`);
38 } else if (e.type === "skipped") {
39 console.log(`[x402] skipped ${e.resourceUrl}: ${e.reason}`);
40 }
41 },
42});
43
44const proxy = new X402Proxy({
45 engine,
46 onError: (err, url) => console.error(`[x402] error ${url}: ${String(err)}`),
47});
48
49const caPath = join(homedir(), ".dbbasic-browser", "ca-cert.pem");
50
51proxy.listen(PORT).then(({ host, port }) => {
52 console.log(`x402 proxy on http://${host}:${port}`);
53 console.log(`signer: ${account.address} (TEST KEY — do not fund)`);
54 console.log(`spent this window: ${formatUsd(policy.spentUsdMicro())}`);
55 console.log("");
56 console.log("To intercept https, trust the root CA once:");
57 console.log(` macOS: sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ${caPath}`);
58 console.log("Then point a client at the proxy:");
59 console.log(` curl -x http://${host}:${port} --cacert ${caPath} https://<x402-url>`);
60});
61
62process.on("SIGINT", async () => {
63 console.log(`\nfinal spend: ${formatUsd(policy.spentUsdMicro())}, receipts: ${ledger.all().length}`);
64 await proxy.close();
65 process.exit(0);
66});