@absol-labs/agent 0.11.0 → 0.12.0-rc.1
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 +42 -50
- package/dist/capability/invocation-capability.d.ts +2 -2
- package/dist/capability/probe-capability.d.ts +225 -0
- package/dist/capability/probe-capability.d.ts.map +1 -0
- package/dist/capability/probe-capability.js +248 -0
- package/dist/capability/probe-capability.js.map +1 -0
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +23 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/commands/claim.js +1 -1
- package/dist/cli/commands/claim.js.map +1 -1
- package/dist/cli/commands/close.d.ts.map +1 -1
- package/dist/cli/commands/close.js +35 -3
- package/dist/cli/commands/close.js.map +1 -1
- package/dist/cli/commands/invoke.d.ts +2 -0
- package/dist/cli/commands/invoke.d.ts.map +1 -1
- package/dist/cli/commands/invoke.js +2 -2
- package/dist/cli/commands/invoke.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +15 -2
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/open.d.ts.map +1 -1
- package/dist/cli/commands/open.js +58 -4
- package/dist/cli/commands/open.js.map +1 -1
- package/dist/cli/commands/pay.d.ts +19 -0
- package/dist/cli/commands/pay.d.ts.map +1 -0
- package/dist/cli/commands/pay.js +355 -0
- package/dist/cli/commands/pay.js.map +1 -0
- package/dist/cli/commands/reclaim-unverified.d.ts.map +1 -1
- package/dist/cli/commands/reclaim-unverified.js +3 -2
- package/dist/cli/commands/reclaim-unverified.js.map +1 -1
- package/dist/cli/commands/reclaim.d.ts +23 -2
- package/dist/cli/commands/reclaim.d.ts.map +1 -1
- package/dist/cli/commands/reclaim.js +184 -16
- package/dist/cli/commands/reclaim.js.map +1 -1
- package/dist/cli/commands/refund.d.ts +13 -0
- package/dist/cli/commands/refund.d.ts.map +1 -0
- package/dist/cli/commands/refund.js +224 -0
- package/dist/cli/commands/refund.js.map +1 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +10 -1
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/streams.js +8 -12
- package/dist/cli/commands/streams.js.map +1 -1
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +2 -1
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/config.d.ts +44 -26
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +88 -38
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/deps.d.ts +33 -0
- package/dist/cli/deps.d.ts.map +1 -1
- package/dist/cli/deps.js +37 -1
- package/dist/cli/deps.js.map +1 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +21 -1
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/escape-hatch.d.ts +6 -4
- package/dist/cli/escape-hatch.d.ts.map +1 -1
- package/dist/cli/escape-hatch.js +6 -2
- package/dist/cli/escape-hatch.js.map +1 -1
- package/dist/cli/listings.d.ts +18 -0
- package/dist/cli/listings.d.ts.map +1 -1
- package/dist/cli/listings.js +22 -12
- package/dist/cli/listings.js.map +1 -1
- package/dist/cli/preflight.d.ts +20 -14
- package/dist/cli/preflight.d.ts.map +1 -1
- package/dist/cli/preflight.js +34 -20
- package/dist/cli/preflight.js.map +1 -1
- package/dist/cli/privy.d.ts.map +1 -1
- package/dist/cli/privy.js +4 -2
- package/dist/cli/privy.js.map +1 -1
- package/dist/cli/reclaimability.d.ts +82 -0
- package/dist/cli/reclaimability.d.ts.map +1 -0
- package/dist/cli/reclaimability.js +80 -0
- package/dist/cli/reclaimability.js.map +1 -0
- package/dist/cli/run.d.ts +2 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +40 -11
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/scan-range.d.ts +2 -2
- package/dist/cli/scan-range.js +2 -2
- package/dist/cli/status.d.ts +3 -1
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +15 -3
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/wallet.d.ts +1 -1
- package/dist/cli/wallet.js +2 -2
- package/dist/cli/wallet.js.map +1 -1
- package/dist/discovery/rate-band.d.ts +74 -0
- package/dist/discovery/rate-band.d.ts.map +1 -0
- package/dist/discovery/rate-band.js +114 -0
- package/dist/discovery/rate-band.js.map +1 -0
- package/dist/escrow-generation.d.ts +81 -0
- package/dist/escrow-generation.d.ts.map +1 -0
- package/dist/escrow-generation.js +76 -0
- package/dist/escrow-generation.js.map +1 -0
- package/dist/frameworks/agentkit.d.ts +8 -4
- package/dist/frameworks/agentkit.d.ts.map +1 -1
- package/dist/frameworks/agentkit.js +27 -10
- package/dist/frameworks/agentkit.js.map +1 -1
- package/dist/frameworks/eliza.d.ts +3 -3
- package/dist/frameworks/eliza.d.ts.map +1 -1
- package/dist/frameworks/eliza.js +15 -6
- package/dist/frameworks/eliza.js.map +1 -1
- package/dist/frameworks/langchain.d.ts.map +1 -1
- package/dist/frameworks/langchain.js +8 -0
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/gateway/caller-auth-gateway.d.ts +83 -31
- package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
- package/dist/gateway/caller-auth-gateway.js +180 -27
- package/dist/gateway/caller-auth-gateway.js.map +1 -1
- package/dist/gateway/http-server.d.ts +111 -44
- package/dist/gateway/http-server.d.ts.map +1 -1
- package/dist/gateway/http-server.js +439 -155
- package/dist/gateway/http-server.js.map +1 -1
- package/dist/gateway/probe-auth.d.ts +112 -0
- package/dist/gateway/probe-auth.d.ts.map +1 -0
- package/dist/gateway/probe-auth.js +127 -0
- package/dist/gateway/probe-auth.js.map +1 -0
- package/dist/gateway/signed-rate-bounds.d.ts +51 -0
- package/dist/gateway/signed-rate-bounds.d.ts.map +1 -0
- package/dist/gateway/signed-rate-bounds.js +94 -0
- package/dist/gateway/signed-rate-bounds.js.map +1 -0
- package/dist/gateway/x402-opener-mode.d.ts +215 -0
- package/dist/gateway/x402-opener-mode.d.ts.map +1 -0
- package/dist/gateway/x402-opener-mode.js +639 -0
- package/dist/gateway/x402-opener-mode.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +52 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +228 -37
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/x402-tools.d.ts +104 -0
- package/dist/mcp/x402-tools.d.ts.map +1 -0
- package/dist/mcp/x402-tools.js +434 -0
- package/dist/mcp/x402-tools.js.map +1 -0
- package/dist/network.d.ts +119 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +199 -0
- package/dist/network.js.map +1 -0
- package/dist/sdk/invoke.d.ts +4 -0
- package/dist/sdk/invoke.d.ts.map +1 -1
- package/dist/sdk/invoke.js +2 -5
- package/dist/sdk/invoke.js.map +1 -1
- package/dist/wallet/autonomous-wallet-broker.d.ts +3 -0
- package/dist/wallet/autonomous-wallet-broker.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet-broker.js +27 -23
- package/dist/wallet/autonomous-wallet-broker.js.map +1 -1
- package/dist/wallet/autonomous-wallet-protocol.d.ts +8 -2
- package/dist/wallet/autonomous-wallet-protocol.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet-protocol.js +9 -2
- package/dist/wallet/autonomous-wallet-protocol.js.map +1 -1
- package/dist/wallet/autonomous-wallet.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet.js +3 -2
- package/dist/wallet/autonomous-wallet.js.map +1 -1
- package/dist/wallet/broker-escrows.d.ts +222 -0
- package/dist/wallet/broker-escrows.d.ts.map +1 -0
- package/dist/wallet/broker-escrows.js +36 -0
- package/dist/wallet/broker-escrows.js.map +1 -0
- package/dist/wallet/lifecycle.d.ts +21 -5
- package/dist/wallet/lifecycle.d.ts.map +1 -1
- package/dist/wallet/lifecycle.js +32 -12
- package/dist/wallet/lifecycle.js.map +1 -1
- package/dist/wallet/privy-broker-server.d.ts.map +1 -1
- package/dist/wallet/privy-broker-server.js +31 -26
- package/dist/wallet/privy-broker-server.js.map +1 -1
- package/dist/wallet/privy-session-broker.d.ts +14 -5
- package/dist/wallet/privy-session-broker.d.ts.map +1 -1
- package/dist/wallet/privy-session-broker.js +29 -17
- package/dist/wallet/privy-session-broker.js.map +1 -1
- package/dist/wallet/privy-session-provider.d.ts +3 -1
- package/dist/wallet/privy-session-provider.d.ts.map +1 -1
- package/dist/wallet/privy-session-provider.js +5 -3
- package/dist/wallet/privy-session-provider.js.map +1 -1
- package/dist/wallet/provider.d.ts.map +1 -1
- package/dist/wallet/provider.js +15 -8
- package/dist/wallet/provider.js.map +1 -1
- package/dist/x402/facilitator.d.ts +3 -30
- package/dist/x402/facilitator.d.ts.map +1 -1
- package/dist/x402/facilitator.js +0 -27
- package/dist/x402/facilitator.js.map +1 -1
- package/dist/x402-buyer/guarded-fetch.d.ts +51 -0
- package/dist/x402-buyer/guarded-fetch.d.ts.map +1 -0
- package/dist/x402-buyer/guarded-fetch.js +147 -0
- package/dist/x402-buyer/guarded-fetch.js.map +1 -0
- package/dist/x402-buyer/index.d.ts +10 -0
- package/dist/x402-buyer/index.d.ts.map +1 -0
- package/dist/x402-buyer/index.js +10 -0
- package/dist/x402-buyer/index.js.map +1 -0
- package/dist/x402-buyer/pay.d.ts +135 -0
- package/dist/x402-buyer/pay.d.ts.map +1 -0
- package/dist/x402-buyer/pay.js +336 -0
- package/dist/x402-buyer/pay.js.map +1 -0
- package/dist/x402-opener/abi.d.ts +684 -0
- package/dist/x402-opener/abi.d.ts.map +1 -0
- package/dist/x402-opener/abi.js +880 -0
- package/dist/x402-opener/abi.js.map +1 -0
- package/dist/x402-opener/facilitator-entry.d.ts +3 -0
- package/dist/x402-opener/facilitator-entry.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-entry.js +37 -0
- package/dist/x402-opener/facilitator-entry.js.map +1 -0
- package/dist/x402-opener/facilitator-server.d.ts +180 -0
- package/dist/x402-opener/facilitator-server.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-server.js +696 -0
- package/dist/x402-opener/facilitator-server.js.map +1 -0
- package/dist/x402-opener/index.d.ts +14 -0
- package/dist/x402-opener/index.d.ts.map +1 -0
- package/dist/x402-opener/index.js +14 -0
- package/dist/x402-opener/index.js.map +1 -0
- package/dist/x402-opener/listing-resolver.d.ts +55 -0
- package/dist/x402-opener/listing-resolver.d.ts.map +1 -0
- package/dist/x402-opener/listing-resolver.js +125 -0
- package/dist/x402-opener/listing-resolver.js.map +1 -0
- package/dist/x402-opener/refund-relay.d.ts +240 -0
- package/dist/x402-opener/refund-relay.d.ts.map +1 -0
- package/dist/x402-opener/refund-relay.js +1240 -0
- package/dist/x402-opener/refund-relay.js.map +1 -0
- package/dist/x402-opener/relayer-queue.d.ts +14 -0
- package/dist/x402-opener/relayer-queue.d.ts.map +1 -0
- package/dist/x402-opener/relayer-queue.js +18 -0
- package/dist/x402-opener/relayer-queue.js.map +1 -0
- package/dist/x402-opener/scheme.d.ts +217 -0
- package/dist/x402-opener/scheme.d.ts.map +1 -0
- package/dist/x402-opener/scheme.js +749 -0
- package/dist/x402-opener/scheme.js.map +1 -0
- package/dist/x402-opener/terms.d.ts +105 -0
- package/dist/x402-opener/terms.d.ts.map +1 -0
- package/dist/x402-opener/terms.js +212 -0
- package/dist/x402-opener/terms.js.map +1 -0
- package/dist/zktls/reclaim.d.ts +2 -2
- package/dist/zktls/t2-delivery-proof.d.ts +6 -6
- package/docs/agent-layer.md +3 -2
- package/docs/autonomous-privy-wallet.md +188 -0
- package/docs/cli.md +184 -31
- package/docs/langchain.md +5 -0
- package/docs/mcp-reference.md +75 -5
- package/docs/probe-capability.md +191 -0
- package/docs/quickstart.md +36 -1
- package/docs/threat-model.md +20 -0
- package/docs/x402.md +628 -595
- package/package.json +19 -17
- package/src/capability/probe-capability.ts +355 -0
- package/src/cli/args.ts +29 -0
- package/src/cli/commands/claim.ts +1 -1
- package/src/cli/commands/close.ts +36 -3
- package/src/cli/commands/invoke.ts +5 -2
- package/src/cli/commands/mcp.ts +18 -2
- package/src/cli/commands/open.ts +75 -4
- package/src/cli/commands/pay.ts +442 -0
- package/src/cli/commands/reclaim-unverified.ts +8 -2
- package/src/cli/commands/reclaim.ts +252 -14
- package/src/cli/commands/refund.ts +277 -0
- package/src/cli/commands/status.ts +17 -1
- package/src/cli/commands/streams.ts +10 -14
- package/src/cli/commands/watch.ts +7 -1
- package/src/cli/config.ts +139 -52
- package/src/cli/deps.ts +74 -1
- package/src/cli/errors.ts +24 -1
- package/src/cli/escape-hatch.ts +19 -5
- package/src/cli/listings.ts +43 -10
- package/src/cli/preflight.ts +36 -21
- package/src/cli/privy.ts +4 -2
- package/src/cli/reclaimability.ts +154 -0
- package/src/cli/run.ts +54 -11
- package/src/cli/scan-range.ts +2 -2
- package/src/cli/status.ts +14 -1
- package/src/cli/wallet.ts +2 -2
- package/src/discovery/rate-band.ts +172 -0
- package/src/escrow-generation.ts +135 -0
- package/src/frameworks/agentkit.ts +45 -11
- package/src/frameworks/eliza.ts +27 -5
- package/src/frameworks/langchain.ts +14 -0
- package/src/gateway/caller-auth-gateway.ts +320 -68
- package/src/gateway/http-server.ts +629 -220
- package/src/gateway/probe-auth.ts +191 -0
- package/src/gateway/signed-rate-bounds.ts +164 -0
- package/src/gateway/x402-opener-mode.ts +974 -0
- package/src/index.ts +82 -19
- package/src/mcp/server.ts +319 -42
- package/src/mcp/x402-tools.ts +621 -0
- package/src/network.ts +302 -0
- package/src/sdk/invoke.ts +6 -5
- package/src/wallet/autonomous-wallet-broker.ts +46 -20
- package/src/wallet/autonomous-wallet-protocol.ts +11 -2
- package/src/wallet/autonomous-wallet.ts +4 -2
- package/src/wallet/broker-escrows.ts +66 -0
- package/src/wallet/lifecycle.ts +53 -18
- package/src/wallet/privy-broker-server.ts +35 -25
- package/src/wallet/privy-session-broker.ts +58 -25
- package/src/wallet/privy-session-provider.ts +7 -3
- package/src/wallet/provider.ts +20 -15
- package/src/x402/facilitator.ts +3 -43
- package/src/x402-buyer/guarded-fetch.ts +213 -0
- package/src/x402-buyer/index.ts +9 -0
- package/src/x402-buyer/pay.ts +517 -0
- package/src/x402-opener/abi.ts +881 -0
- package/src/x402-opener/facilitator-entry.ts +45 -0
- package/src/x402-opener/facilitator-server.ts +1014 -0
- package/src/x402-opener/index.ts +13 -0
- package/src/x402-opener/listing-resolver.ts +202 -0
- package/src/x402-opener/refund-relay.ts +1743 -0
- package/src/x402-opener/relayer-queue.ts +18 -0
- package/src/x402-opener/scheme.ts +1133 -0
- package/src/x402-opener/terms.ts +300 -0
- package/dist/gateway/x402-mode.d.ts +0 -123
- package/dist/gateway/x402-mode.d.ts.map +0 -1
- package/dist/gateway/x402-mode.js +0 -212
- package/dist/gateway/x402-mode.js.map +0 -1
- package/dist/x402/delivery-oracle.d.ts +0 -108
- package/dist/x402/delivery-oracle.d.ts.map +0 -1
- package/dist/x402/delivery-oracle.js +0 -174
- package/dist/x402/delivery-oracle.js.map +0 -1
- package/dist/x402/facilitator-server-entry.d.ts +0 -3
- package/dist/x402/facilitator-server-entry.d.ts.map +0 -1
- package/dist/x402/facilitator-server-entry.js +0 -27
- package/dist/x402/facilitator-server-entry.js.map +0 -1
- package/dist/x402/facilitator-server.d.ts +0 -73
- package/dist/x402/facilitator-server.d.ts.map +0 -1
- package/dist/x402/facilitator-server.js +0 -305
- package/dist/x402/facilitator-server.js.map +0 -1
- package/dist/x402/payment-requirements.d.ts +0 -106
- package/dist/x402/payment-requirements.d.ts.map +0 -1
- package/dist/x402/payment-requirements.js +0 -138
- package/dist/x402/payment-requirements.js.map +0 -1
- package/dist/x402/relayer.d.ts +0 -41
- package/dist/x402/relayer.d.ts.map +0 -1
- package/dist/x402/relayer.js +0 -64
- package/dist/x402/relayer.js.map +0 -1
- package/dist/x402/resource-index.d.ts +0 -75
- package/dist/x402/resource-index.d.ts.map +0 -1
- package/dist/x402/resource-index.js +0 -126
- package/dist/x402/resource-index.js.map +0 -1
- package/dist/x402/verified-delivery-facilitator.d.ts +0 -285
- package/dist/x402/verified-delivery-facilitator.d.ts.map +0 -1
- package/dist/x402/verified-delivery-facilitator.js +0 -423
- package/dist/x402/verified-delivery-facilitator.js.map +0 -1
- package/src/gateway/x402-mode.ts +0 -350
- package/src/x402/delivery-oracle.ts +0 -285
- package/src/x402/facilitator-server-entry.ts +0 -35
- package/src/x402/facilitator-server.ts +0 -445
- package/src/x402/payment-requirements.ts +0 -231
- package/src/x402/relayer.ts +0 -122
- package/src/x402/resource-index.ts +0 -228
- package/src/x402/verified-delivery-facilitator.ts +0 -744
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import { createServer, } from "node:http";
|
|
2
|
-
import { timingSafeEqual } from "node:crypto";
|
|
3
|
-
import { isAddress, isHex } from "viem";
|
|
4
|
-
import { createOracleDeliveryOracle, DEFAULT_DELIVERY_FRESHNESS_SECONDS, DEFAULT_METRIK_ORACLE_URL, } from "./delivery-oracle.js";
|
|
5
|
-
import { createRegistryResourceIndex } from "./resource-index.js";
|
|
6
|
-
import { createX402PaymentSettler, createX402PaymentVerifier, relayerAddress, } from "./relayer.js";
|
|
7
|
-
import { DEFAULT_SETTLEMENT_SCOPE, MetrikVerifiedDeliveryFacilitator, RelayerNotConfiguredError, } from "./verified-delivery-facilitator.js";
|
|
8
|
-
/**
|
|
9
|
-
* Reference HTTP server for Metrik's x402 facilitator: `POST /verify`,
|
|
10
|
-
* `POST /settle`, `GET /supported` — the three endpoints the x402 facilitator
|
|
11
|
-
* interface defines, with Metrik's verified-delivery gate wired into `/verify`.
|
|
12
|
-
*
|
|
13
|
-
* Point any x402 resource server at this with
|
|
14
|
-
* `facilitator: { url: "https://<host>" }` and it becomes a resource server
|
|
15
|
-
* whose payments stop when the seller stops delivering.
|
|
16
|
-
*/
|
|
17
|
-
const MAX_BODY_BYTES = 256 * 1024;
|
|
18
|
-
export function createMetrikFacilitatorServer(config) {
|
|
19
|
-
const httpServer = createServer((req, res) => {
|
|
20
|
-
handle(req, res, config).catch((error) => {
|
|
21
|
-
if (error instanceof RelayerNotConfiguredError) {
|
|
22
|
-
writeJson(res, 503, {
|
|
23
|
-
success: false,
|
|
24
|
-
errorReason: "unexpected_settle_error",
|
|
25
|
-
transaction: "",
|
|
26
|
-
error: error.message,
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
logError("unhandled request error", error);
|
|
31
|
-
writeJson(res, 500, { error: "internal-error" });
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
return {
|
|
35
|
-
httpServer,
|
|
36
|
-
listen: (port, host = "0.0.0.0") => new Promise((resolve, reject) => {
|
|
37
|
-
const onError = (error) => reject(error);
|
|
38
|
-
httpServer.once("error", onError);
|
|
39
|
-
httpServer.listen(port, host, () => {
|
|
40
|
-
httpServer.removeListener("error", onError);
|
|
41
|
-
const address = httpServer.address();
|
|
42
|
-
resolve({ port: address.port, host });
|
|
43
|
-
});
|
|
44
|
-
}),
|
|
45
|
-
close: () => new Promise((resolve, reject) => {
|
|
46
|
-
httpServer.close((error) => (error ? reject(error) : resolve()));
|
|
47
|
-
}),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
async function handle(req, res, config) {
|
|
51
|
-
const url = new URL(req.url ?? "/", "http://localhost");
|
|
52
|
-
const path = url.pathname.replace(/\/+$/, "") || "/";
|
|
53
|
-
if (req.method === "GET" && (path === "/supported" || path === "/")) {
|
|
54
|
-
writeJson(res, 200, {
|
|
55
|
-
...config.facilitator.supported(),
|
|
56
|
-
settlementEnabled: config.settlementEnabled,
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (req.method !== "POST") {
|
|
61
|
-
writeJson(res, 405, { error: "method-not-allowed" });
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (path !== "/verify" && path !== "/settle") {
|
|
65
|
-
writeJson(res, 404, { error: "not-found" });
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
// Authenticate BEFORE reading the body: an unauthenticated caller must not be
|
|
69
|
-
// able to make this process do work, parse input, or reach the chain.
|
|
70
|
-
if (path === "/settle" && !isAuthorizedSettle(req, config)) {
|
|
71
|
-
writeJson(res, 401, {
|
|
72
|
-
success: false,
|
|
73
|
-
errorReason: "invalid_payment",
|
|
74
|
-
transaction: "",
|
|
75
|
-
error: "POST /settle requires the facilitator's bearer token. It spends the operator's gas.",
|
|
76
|
-
});
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
let body;
|
|
80
|
-
try {
|
|
81
|
-
body = JSON.parse(await readBody(req));
|
|
82
|
-
}
|
|
83
|
-
catch {
|
|
84
|
-
writeJson(res, 400, { error: "invalid-json" });
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (path === "/verify") {
|
|
88
|
-
writeJson(res, 200, await config.facilitator.verify(body));
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
writeJson(res, 200, await config.facilitator.settle(body));
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Constant-time bearer check. A missing configured token denies, so a
|
|
95
|
-
* misconfiguration can never silently open the endpoint.
|
|
96
|
-
*/
|
|
97
|
-
function isAuthorizedSettle(req, config) {
|
|
98
|
-
const expected = config.settlementToken;
|
|
99
|
-
if (expected === undefined || expected.length === 0) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
const header = req.headers.authorization;
|
|
103
|
-
if (typeof header !== "string") {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
const match = /^Bearer\s+(.+)$/i.exec(header.trim());
|
|
107
|
-
if (match === null) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
const presented = Buffer.from(match[1], "utf8");
|
|
111
|
-
const target = Buffer.from(expected, "utf8");
|
|
112
|
-
// `timingSafeEqual` throws on a length mismatch, which would itself leak the
|
|
113
|
-
// length, so compare a fixed-width digest-shaped pair instead: pad both to the
|
|
114
|
-
// longer length and AND in the length equality.
|
|
115
|
-
const width = Math.max(presented.length, target.length);
|
|
116
|
-
const a = Buffer.alloc(width);
|
|
117
|
-
const b = Buffer.alloc(width);
|
|
118
|
-
presented.copy(a);
|
|
119
|
-
target.copy(b);
|
|
120
|
-
return timingSafeEqual(a, b) && presented.length === target.length;
|
|
121
|
-
}
|
|
122
|
-
async function readBody(req) {
|
|
123
|
-
const chunks = [];
|
|
124
|
-
let size = 0;
|
|
125
|
-
for await (const chunk of req) {
|
|
126
|
-
const buffer = chunk;
|
|
127
|
-
size += buffer.length;
|
|
128
|
-
if (size > MAX_BODY_BYTES) {
|
|
129
|
-
throw new Error("request body too large");
|
|
130
|
-
}
|
|
131
|
-
chunks.push(buffer);
|
|
132
|
-
}
|
|
133
|
-
return Buffer.concat(chunks).toString("utf8");
|
|
134
|
-
}
|
|
135
|
-
function writeJson(res, status, body) {
|
|
136
|
-
if (res.headersSent) {
|
|
137
|
-
res.end();
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
res
|
|
141
|
-
.writeHead(status, { "Content-Type": "application/json" })
|
|
142
|
-
.end(JSON.stringify(body));
|
|
143
|
-
}
|
|
144
|
-
function logError(context, error) {
|
|
145
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
146
|
-
console.error(`[metrik-x402-facilitator] ${context}: ${message}`);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Env contract:
|
|
150
|
-
* - `METRIK_X402_RPC_URL` (required) — RPC for balance checks and, when a relayer
|
|
151
|
-
* is configured, for broadcasting.
|
|
152
|
-
* - `METRIK_X402_RELAYER_PRIVATE_KEY` (required unless
|
|
153
|
-
* `METRIK_X402_ALLOW_VERIFY_ONLY=true`) — the relayer that broadcasts EIP-3009
|
|
154
|
-
* transfers and pays gas.
|
|
155
|
-
* - `METRIK_X402_ALLOW_VERIFY_ONLY` (optional) — explicit opt-in to booting a
|
|
156
|
-
* verify-only facilitator. Without it, a missing relayer key is a STARTUP
|
|
157
|
-
* FAILURE rather than a server that silently never settles.
|
|
158
|
-
* - `METRIK_X402_CHAIN_ID` (optional) — default `84532`.
|
|
159
|
-
* - `METRIK_X402_ORACLE_URL` (optional) — default the public Metrik oracle.
|
|
160
|
-
* - `METRIK_X402_REGISTRY_URL` (optional) — listing source; default the oracle's
|
|
161
|
-
* public credential-free registry.
|
|
162
|
-
* - `METRIK_X402_FRESHNESS_SECONDS` (optional) — default
|
|
163
|
-
* {@link DEFAULT_DELIVERY_FRESHNESS_SECONDS}.
|
|
164
|
-
* - `METRIK_X402_INDETERMINATE_POLICY` (optional) — `allow` (default) or `deny`.
|
|
165
|
-
* - `PORT` / `METRIK_X402_PORT` (optional) — default `8788`.
|
|
166
|
-
* - `METRIK_X402_HOST` (optional) — default `0.0.0.0`.
|
|
167
|
-
*/
|
|
168
|
-
export function parseMetrikFacilitatorEnvConfig(env = process.env) {
|
|
169
|
-
const rpcUrl = env.METRIK_X402_RPC_URL;
|
|
170
|
-
if (rpcUrl === undefined || rpcUrl.trim().length === 0) {
|
|
171
|
-
throw new Error("METRIK_X402_RPC_URL is required (fail-closed)");
|
|
172
|
-
}
|
|
173
|
-
const rawKey = env.METRIK_X402_RELAYER_PRIVATE_KEY?.trim();
|
|
174
|
-
const allowVerifyOnly = env.METRIK_X402_ALLOW_VERIFY_ONLY === "true";
|
|
175
|
-
let relayerPrivateKey;
|
|
176
|
-
if (rawKey !== undefined && rawKey.length > 0) {
|
|
177
|
-
if (!isHex(rawKey, { strict: true }) || rawKey.length !== 66) {
|
|
178
|
-
throw new Error("METRIK_X402_RELAYER_PRIVATE_KEY must be a 32-byte 0x-prefixed hex private key");
|
|
179
|
-
}
|
|
180
|
-
relayerPrivateKey = rawKey;
|
|
181
|
-
}
|
|
182
|
-
else if (!allowVerifyOnly) {
|
|
183
|
-
throw new Error("METRIK_X402_RELAYER_PRIVATE_KEY is required to settle payments. " +
|
|
184
|
-
"This facilitator will NOT start without one, because a facilitator that " +
|
|
185
|
-
"accepts /settle and never broadcasts is worse than one that is absent. " +
|
|
186
|
-
"Set METRIK_X402_ALLOW_VERIFY_ONLY=true to deliberately run verify-only.");
|
|
187
|
-
}
|
|
188
|
-
// `/settle` makes the relayer sign and pay gas. An open one is a
|
|
189
|
-
// permissionless "broadcast for me" endpoint, so a settling facilitator
|
|
190
|
-
// cannot boot without a token. Fail closed at startup, not at request time.
|
|
191
|
-
const settlementToken = env.METRIK_X402_FACILITATOR_TOKEN?.trim();
|
|
192
|
-
if (relayerPrivateKey !== undefined) {
|
|
193
|
-
if (settlementToken === undefined || settlementToken.length < 32) {
|
|
194
|
-
throw new Error("METRIK_X402_FACILITATOR_TOKEN is required (at least 32 characters) whenever a " +
|
|
195
|
-
"settlement relayer is configured. POST /settle spends the operator's gas and " +
|
|
196
|
-
"binds 0.0.0.0; without a token anyone who can reach it can make the relayer " +
|
|
197
|
-
"broadcast and pay for it.");
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
const rawAllowlist = (env.METRIK_X402_SETTLEMENT_ASSETS ?? "")
|
|
201
|
-
.split(",")
|
|
202
|
-
.map((value) => value.trim())
|
|
203
|
-
.filter((value) => value.length > 0);
|
|
204
|
-
for (const candidate of rawAllowlist) {
|
|
205
|
-
if (!isAddress(candidate)) {
|
|
206
|
-
throw new Error(`METRIK_X402_SETTLEMENT_ASSETS must contain only EVM addresses (got ${candidate})`);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const rawScope = env.METRIK_X402_SETTLEMENT_SCOPE ?? DEFAULT_SETTLEMENT_SCOPE;
|
|
210
|
-
if (rawScope !== "tracked-resources" && rawScope !== "any-resource") {
|
|
211
|
-
throw new Error(`invalid METRIK_X402_SETTLEMENT_SCOPE: ${rawScope} (tracked-resources|any-resource)`);
|
|
212
|
-
}
|
|
213
|
-
const chainId = Number(env.METRIK_X402_CHAIN_ID ?? "84532");
|
|
214
|
-
if (!Number.isInteger(chainId) || chainId <= 0) {
|
|
215
|
-
throw new Error(`invalid METRIK_X402_CHAIN_ID: ${env.METRIK_X402_CHAIN_ID}`);
|
|
216
|
-
}
|
|
217
|
-
const freshnessWindowSeconds = Number(env.METRIK_X402_FRESHNESS_SECONDS ??
|
|
218
|
-
String(DEFAULT_DELIVERY_FRESHNESS_SECONDS));
|
|
219
|
-
if (!Number.isFinite(freshnessWindowSeconds) || freshnessWindowSeconds <= 0) {
|
|
220
|
-
throw new Error(`invalid METRIK_X402_FRESHNESS_SECONDS: ${env.METRIK_X402_FRESHNESS_SECONDS}`);
|
|
221
|
-
}
|
|
222
|
-
const rawPolicy = env.METRIK_X402_INDETERMINATE_POLICY ?? "allow";
|
|
223
|
-
if (rawPolicy !== "allow" && rawPolicy !== "deny") {
|
|
224
|
-
throw new Error(`invalid METRIK_X402_INDETERMINATE_POLICY: ${rawPolicy} (allow|deny)`);
|
|
225
|
-
}
|
|
226
|
-
const port = Number(env.METRIK_X402_PORT ?? env.PORT ?? "8788");
|
|
227
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535) {
|
|
228
|
-
throw new Error(`invalid port: ${env.METRIK_X402_PORT ?? env.PORT}`);
|
|
229
|
-
}
|
|
230
|
-
const registryUrl = env.METRIK_X402_REGISTRY_URL;
|
|
231
|
-
return {
|
|
232
|
-
host: env.METRIK_X402_HOST ?? "0.0.0.0",
|
|
233
|
-
port,
|
|
234
|
-
chainId,
|
|
235
|
-
rpcUrl,
|
|
236
|
-
oracleUrl: env.METRIK_X402_ORACLE_URL ?? DEFAULT_METRIK_ORACLE_URL,
|
|
237
|
-
freshnessWindowSeconds,
|
|
238
|
-
indeterminatePolicy: rawPolicy,
|
|
239
|
-
settlementScope: rawScope,
|
|
240
|
-
...(rawAllowlist.length === 0
|
|
241
|
-
? {}
|
|
242
|
-
: { settlementAssetAllowlist: rawAllowlist }),
|
|
243
|
-
...(registryUrl === undefined ? {} : { registryUrl }),
|
|
244
|
-
...(relayerPrivateKey === undefined ? {} : { relayerPrivateKey }),
|
|
245
|
-
...(settlementToken === undefined || settlementToken.length === 0
|
|
246
|
-
? {}
|
|
247
|
-
: { settlementToken }),
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
export function buildMetrikFacilitatorFromEnvConfig(config) {
|
|
251
|
-
return new MetrikVerifiedDeliveryFacilitator({
|
|
252
|
-
paymentVerifier: createX402PaymentVerifier({
|
|
253
|
-
chainId: config.chainId,
|
|
254
|
-
rpcUrl: config.rpcUrl,
|
|
255
|
-
}),
|
|
256
|
-
...(config.relayerPrivateKey === undefined
|
|
257
|
-
? {}
|
|
258
|
-
: {
|
|
259
|
-
paymentSettler: createX402PaymentSettler({
|
|
260
|
-
chainId: config.chainId,
|
|
261
|
-
rpcUrl: config.rpcUrl,
|
|
262
|
-
privateKey: config.relayerPrivateKey,
|
|
263
|
-
}),
|
|
264
|
-
}),
|
|
265
|
-
resourceIndex: createRegistryResourceIndex(config.registryUrl === undefined
|
|
266
|
-
? {}
|
|
267
|
-
: { discoverOptions: { registryUrl: config.registryUrl } }),
|
|
268
|
-
deliveryOracle: createOracleDeliveryOracle({
|
|
269
|
-
oracleUrl: config.oracleUrl,
|
|
270
|
-
freshnessWindowSeconds: config.freshnessWindowSeconds,
|
|
271
|
-
}),
|
|
272
|
-
indeterminatePolicy: config.indeterminatePolicy,
|
|
273
|
-
chainId: config.chainId,
|
|
274
|
-
settlementScope: config.settlementScope,
|
|
275
|
-
...(config.settlementAssetAllowlist === undefined
|
|
276
|
-
? {}
|
|
277
|
-
: { settlementAssetAllowlist: config.settlementAssetAllowlist }),
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
export async function startMetrikFacilitatorServerFromEnv(env = process.env) {
|
|
281
|
-
const config = parseMetrikFacilitatorEnvConfig(env);
|
|
282
|
-
const facilitator = buildMetrikFacilitatorFromEnvConfig(config);
|
|
283
|
-
if (config.relayerPrivateKey === undefined) {
|
|
284
|
-
console.error("[metrik-x402-facilitator] SETTLEMENT DISABLED — no METRIK_X402_RELAYER_PRIVATE_KEY. " +
|
|
285
|
-
"/verify works; /settle will return 503 and broadcast nothing.");
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
console.error(`[metrik-x402-facilitator] settlement relayer ${relayerAddress(config.relayerPrivateKey)} — this address must hold native gas on chain ${config.chainId}.`);
|
|
289
|
-
}
|
|
290
|
-
console.error(`[metrik-x402-facilitator] delivery gate: oracle=${config.oracleUrl} ` +
|
|
291
|
-
`freshness=${config.freshnessWindowSeconds}s policy-on-no-evidence=${config.indeterminatePolicy}`);
|
|
292
|
-
console.error(`[metrik-x402-facilitator] settlement policy: scope=${config.settlementScope} ` +
|
|
293
|
-
`assets=${facilitator.allowedSettlementAssets.join(",")} — the relayer will not be ` +
|
|
294
|
-
"asked to call any other contract.");
|
|
295
|
-
const server = createMetrikFacilitatorServer({
|
|
296
|
-
facilitator,
|
|
297
|
-
settlementEnabled: config.relayerPrivateKey !== undefined,
|
|
298
|
-
...(config.settlementToken === undefined
|
|
299
|
-
? {}
|
|
300
|
-
: { settlementToken: config.settlementToken }),
|
|
301
|
-
});
|
|
302
|
-
const { port } = await server.listen(config.port, config.host);
|
|
303
|
-
return Object.assign(server, { boundPort: port });
|
|
304
|
-
}
|
|
305
|
-
//# sourceMappingURL=facilitator-server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"facilitator-server.js","sourceRoot":"","sources":["../../src/x402/facilitator-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,GAIb,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,KAAK,EAAY,MAAM,MAAM,CAAC;AAElD,OAAO,EACL,0BAA0B,EAC1B,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;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CACzB,iDAAiD,MAAM,CAAC,OAAO,GAAG,CACpE,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,KAAK,CACX,mDAAmD,MAAM,CAAC,SAAS,GAAG;QACpE,aAAa,MAAM,CAAC,sBAAsB,2BAA2B,MAAM,CAAC,mBAAmB,EAAE,CACpG,CAAC;IACF,OAAO,CAAC,KAAK,CACX,sDAAsD,MAAM,CAAC,eAAe,GAAG;QAC7E,UAAU,WAAW,CAAC,uBAAuB,CAAC,IAAI,CAAC,GAAG,CAAC,6BAA6B;QACpF,mCAAmC,CACtC,CAAC;IAEF,MAAM,MAAM,GAAG,6BAA6B,CAAC;QAC3C,WAAW;QACX,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,KAAK,SAAS;QACzD,GAAG,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS;YACtC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,EAAE,eAAe,EAAE,MAAM,CAAC,eAAe,EAAE,CAAC;KACjD,CAAC,CAAC;IACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { Address, Hex } from "viem";
|
|
2
|
-
import type { PaymentRequirements } from "x402/types";
|
|
3
|
-
/**
|
|
4
|
-
* Standard x402 `exact` payment requirements, built from an OPERATOR-SIGNED
|
|
5
|
-
* Metrik listing.
|
|
6
|
-
*
|
|
7
|
-
* This is the "additional way in" described in `docs/x402.md`: the Metrik
|
|
8
|
-
* verified-stream flow (`./facilitator.ts`) is unchanged and is still the only
|
|
9
|
-
* path with recoverable escrow. What this module adds is the ability for a
|
|
10
|
-
* seller's gateway to ALSO quote an ordinary, fully conformant x402 `exact`
|
|
11
|
-
* price for a single call, so an agent holding nothing but `x402-fetch` can pay
|
|
12
|
-
* without knowing Metrik exists.
|
|
13
|
-
*
|
|
14
|
-
* ## What is signed and what is not
|
|
15
|
-
*
|
|
16
|
-
* `payTo` is derived from the operator's EIP-712-signed service descriptor and
|
|
17
|
-
* from nothing else. It is never read from configuration and never read from a
|
|
18
|
-
* caller-supplied field, because `payTo` is the one field whose corruption
|
|
19
|
-
* silently redirects money.
|
|
20
|
-
*
|
|
21
|
-
* The PRICE is not signed. The descriptor schema (`@absol-labs/shared`) carries
|
|
22
|
-
* `minRatePerSecond` / `maxRatePerSecond` for metered streams and has no
|
|
23
|
-
* per-call price field, so a per-call x402 amount can only come from the seller
|
|
24
|
-
* running the gateway. That is legitimate — it is the seller's own price on the
|
|
25
|
-
* seller's own gateway — but a buyer CANNOT cross-check it against the registry
|
|
26
|
-
* the way they can cross-check `payTo`. Said plainly here so nobody assumes a
|
|
27
|
-
* guarantee that does not exist.
|
|
28
|
-
*/
|
|
29
|
-
/** The only x402 protocol version implemented by the published `x402` package. */
|
|
30
|
-
export declare const X402_VERSION: 1;
|
|
31
|
-
/** The only x402 payment scheme implemented by the published `x402` package. */
|
|
32
|
-
export declare const X402_EXACT_SCHEME: "exact";
|
|
33
|
-
/** x402 v1 uses bare network names, not CAIP-2. Metrik settles on Base only. */
|
|
34
|
-
export declare const X402_NETWORK_BY_CHAIN_ID: Readonly<Record<number, "base" | "base-sepolia">>;
|
|
35
|
-
export interface X402AssetConfig {
|
|
36
|
-
readonly address: Address;
|
|
37
|
-
/** EIP-712 domain `name` of the asset, needed to sign EIP-3009 offline. */
|
|
38
|
-
readonly eip712Name: string;
|
|
39
|
-
/** EIP-712 domain `version` of the asset. */
|
|
40
|
-
readonly eip712Version: string;
|
|
41
|
-
readonly decimals: number;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* USDC per Base chain. The EIP-712 domain values are what a client needs to
|
|
45
|
-
* sign `TransferWithAuthorization` WITHOUT an extra RPC round trip: the x402
|
|
46
|
-
* client falls back to reading `version()` on chain only when
|
|
47
|
-
* `PaymentRequirements.extra` omits it, so quoting them here removes a network
|
|
48
|
-
* dependency from the payer's hot path.
|
|
49
|
-
*
|
|
50
|
-
* Base Sepolia values read from the live contract on 2026-09-18
|
|
51
|
-
* (`name() == "USDC"`, `version() == "2"`).
|
|
52
|
-
*/
|
|
53
|
-
export declare const X402_USDC_BY_CHAIN_ID: Readonly<Record<number, X402AssetConfig>>;
|
|
54
|
-
export declare class X402RequirementsError extends Error {
|
|
55
|
-
constructor(message: string);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* The minimum a payee must prove. Both fields MUST be projected from the
|
|
59
|
-
* operator-signed descriptor (see `../discovery/registry.ts`, which recovers the
|
|
60
|
-
* EIP-712 signer and re-derives `serviceRef` from the signed content), never
|
|
61
|
-
* from an unsigned registry column and never from a request.
|
|
62
|
-
*/
|
|
63
|
-
export interface SignedListingPayee {
|
|
64
|
-
readonly serviceRef: Hex;
|
|
65
|
-
readonly operator: Address;
|
|
66
|
-
}
|
|
67
|
-
export interface BuildMetrikPaymentRequirementsInput {
|
|
68
|
-
readonly listing: SignedListingPayee;
|
|
69
|
-
/** Absolute URL of the paid resource, as the buyer will request it. */
|
|
70
|
-
readonly resource: string;
|
|
71
|
-
/** Price for ONE call, in the asset's base units (micro-USDC at 6 decimals). */
|
|
72
|
-
readonly priceBaseUnits: bigint;
|
|
73
|
-
readonly chainId: number;
|
|
74
|
-
readonly description?: string;
|
|
75
|
-
readonly mimeType?: string;
|
|
76
|
-
/** How long the signed authorization stays valid. Default 60s. */
|
|
77
|
-
readonly maxTimeoutSeconds?: number;
|
|
78
|
-
readonly outputSchema?: Record<string, unknown>;
|
|
79
|
-
/** Override the settlement asset (defaults to USDC for `chainId`). */
|
|
80
|
-
readonly asset?: X402AssetConfig;
|
|
81
|
-
}
|
|
82
|
-
/** Default authorization validity window quoted to payers, in seconds. */
|
|
83
|
-
export declare const DEFAULT_X402_MAX_TIMEOUT_SECONDS = 60;
|
|
84
|
-
/**
|
|
85
|
-
* Builds standard-`exact` `PaymentRequirements` for one call of a Metrik-listed
|
|
86
|
-
* resource. Throws rather than emitting anything a conformant client would
|
|
87
|
-
* reject or a payer could be harmed by.
|
|
88
|
-
*/
|
|
89
|
-
export declare function buildMetrikPaymentRequirements(input: BuildMetrikPaymentRequirementsInput): PaymentRequirements;
|
|
90
|
-
/**
|
|
91
|
-
* The HTTP `402` response body a resource server returns.
|
|
92
|
-
*
|
|
93
|
-
* NOTE on `error`: the shipped `x402ResponseSchema` types `error` as the closed
|
|
94
|
-
* `ErrorReasons` enum, which no real x402 server obeys — `x402-express` and
|
|
95
|
-
* friends put human-readable text there, and `x402-fetch` never reads the field
|
|
96
|
-
* at all. Metrik follows the real-world behaviour (free text) rather than the
|
|
97
|
-
* schema; `test/x402-facilitator-conformance.test.ts` pins that divergence so it
|
|
98
|
-
* is a recorded decision and not an accident.
|
|
99
|
-
*/
|
|
100
|
-
export interface X402PaymentRequiredBody {
|
|
101
|
-
readonly x402Version: typeof X402_VERSION;
|
|
102
|
-
readonly error: string;
|
|
103
|
-
readonly accepts: readonly PaymentRequirements[];
|
|
104
|
-
}
|
|
105
|
-
export declare function buildX402PaymentRequiredBody(accepts: readonly PaymentRequirements[], error?: string): X402PaymentRequiredBody;
|
|
106
|
-
//# sourceMappingURL=payment-requirements.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment-requirements.d.ts","sourceRoot":"","sources":["../../src/x402/payment-requirements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAOzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,kFAAkF;AAClF,eAAO,MAAM,YAAY,EAAG,CAAU,CAAC;AAEvC,gFAAgF;AACh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AAC,KAAK,CAAC,EAAE,eAAe,CAAC;CAClC;AAED,0EAA0E;AAC1E,eAAO,MAAM,gCAAgC,KAAK,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,mCAAmC,GACzC,mBAAmB,CAyErB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,WAAW,EAAE,OAAO,YAAY,CAAC;IAC1C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,CAAC;CAClD;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,SAAS,mBAAmB,EAAE,EACvC,KAAK,SAAiC,GACrC,uBAAuB,CAOzB"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { getAddress, isAddress, isHex } from "viem";
|
|
2
|
-
/**
|
|
3
|
-
* Standard x402 `exact` payment requirements, built from an OPERATOR-SIGNED
|
|
4
|
-
* Metrik listing.
|
|
5
|
-
*
|
|
6
|
-
* This is the "additional way in" described in `docs/x402.md`: the Metrik
|
|
7
|
-
* verified-stream flow (`./facilitator.ts`) is unchanged and is still the only
|
|
8
|
-
* path with recoverable escrow. What this module adds is the ability for a
|
|
9
|
-
* seller's gateway to ALSO quote an ordinary, fully conformant x402 `exact`
|
|
10
|
-
* price for a single call, so an agent holding nothing but `x402-fetch` can pay
|
|
11
|
-
* without knowing Metrik exists.
|
|
12
|
-
*
|
|
13
|
-
* ## What is signed and what is not
|
|
14
|
-
*
|
|
15
|
-
* `payTo` is derived from the operator's EIP-712-signed service descriptor and
|
|
16
|
-
* from nothing else. It is never read from configuration and never read from a
|
|
17
|
-
* caller-supplied field, because `payTo` is the one field whose corruption
|
|
18
|
-
* silently redirects money.
|
|
19
|
-
*
|
|
20
|
-
* The PRICE is not signed. The descriptor schema (`@absol-labs/shared`) carries
|
|
21
|
-
* `minRatePerSecond` / `maxRatePerSecond` for metered streams and has no
|
|
22
|
-
* per-call price field, so a per-call x402 amount can only come from the seller
|
|
23
|
-
* running the gateway. That is legitimate — it is the seller's own price on the
|
|
24
|
-
* seller's own gateway — but a buyer CANNOT cross-check it against the registry
|
|
25
|
-
* the way they can cross-check `payTo`. Said plainly here so nobody assumes a
|
|
26
|
-
* guarantee that does not exist.
|
|
27
|
-
*/
|
|
28
|
-
/** The only x402 protocol version implemented by the published `x402` package. */
|
|
29
|
-
export const X402_VERSION = 1;
|
|
30
|
-
/** The only x402 payment scheme implemented by the published `x402` package. */
|
|
31
|
-
export const X402_EXACT_SCHEME = "exact";
|
|
32
|
-
/** x402 v1 uses bare network names, not CAIP-2. Metrik settles on Base only. */
|
|
33
|
-
export const X402_NETWORK_BY_CHAIN_ID = Object.freeze({
|
|
34
|
-
8453: "base",
|
|
35
|
-
84532: "base-sepolia",
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* USDC per Base chain. The EIP-712 domain values are what a client needs to
|
|
39
|
-
* sign `TransferWithAuthorization` WITHOUT an extra RPC round trip: the x402
|
|
40
|
-
* client falls back to reading `version()` on chain only when
|
|
41
|
-
* `PaymentRequirements.extra` omits it, so quoting them here removes a network
|
|
42
|
-
* dependency from the payer's hot path.
|
|
43
|
-
*
|
|
44
|
-
* Base Sepolia values read from the live contract on 2026-09-18
|
|
45
|
-
* (`name() == "USDC"`, `version() == "2"`).
|
|
46
|
-
*/
|
|
47
|
-
export const X402_USDC_BY_CHAIN_ID = Object.freeze({
|
|
48
|
-
8453: Object.freeze({
|
|
49
|
-
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
50
|
-
eip712Name: "USD Coin",
|
|
51
|
-
eip712Version: "2",
|
|
52
|
-
decimals: 6,
|
|
53
|
-
}),
|
|
54
|
-
84532: Object.freeze({
|
|
55
|
-
address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
|
|
56
|
-
eip712Name: "USDC",
|
|
57
|
-
eip712Version: "2",
|
|
58
|
-
decimals: 6,
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
|
-
export class X402RequirementsError extends Error {
|
|
62
|
-
constructor(message) {
|
|
63
|
-
super(message);
|
|
64
|
-
this.name = "X402RequirementsError";
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/** Default authorization validity window quoted to payers, in seconds. */
|
|
68
|
-
export const DEFAULT_X402_MAX_TIMEOUT_SECONDS = 60;
|
|
69
|
-
/**
|
|
70
|
-
* Builds standard-`exact` `PaymentRequirements` for one call of a Metrik-listed
|
|
71
|
-
* resource. Throws rather than emitting anything a conformant client would
|
|
72
|
-
* reject or a payer could be harmed by.
|
|
73
|
-
*/
|
|
74
|
-
export function buildMetrikPaymentRequirements(input) {
|
|
75
|
-
const network = X402_NETWORK_BY_CHAIN_ID[input.chainId];
|
|
76
|
-
if (network === undefined) {
|
|
77
|
-
throw new X402RequirementsError(`x402 v1 has no network name for chain ${input.chainId} (Metrik settles on Base: 8453, 84532)`);
|
|
78
|
-
}
|
|
79
|
-
const asset = input.asset ?? X402_USDC_BY_CHAIN_ID[input.chainId];
|
|
80
|
-
if (asset === undefined) {
|
|
81
|
-
throw new X402RequirementsError(`no default settlement asset known for chain ${input.chainId}`);
|
|
82
|
-
}
|
|
83
|
-
if (!isAddress(input.listing.operator)) {
|
|
84
|
-
throw new X402RequirementsError("listing.operator must be an EVM address (it becomes payTo)");
|
|
85
|
-
}
|
|
86
|
-
if (!isHex(input.listing.serviceRef, { strict: true }) ||
|
|
87
|
-
input.listing.serviceRef.length !== 66) {
|
|
88
|
-
throw new X402RequirementsError("listing.serviceRef must be a 32-byte hex value");
|
|
89
|
-
}
|
|
90
|
-
if (input.priceBaseUnits <= 0n) {
|
|
91
|
-
throw new X402RequirementsError("priceBaseUnits must be positive — a zero-priced x402 quote is not a payment");
|
|
92
|
-
}
|
|
93
|
-
let resource;
|
|
94
|
-
try {
|
|
95
|
-
resource = new URL(input.resource);
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
throw new X402RequirementsError(`resource must be an absolute URL`);
|
|
99
|
-
}
|
|
100
|
-
const maxTimeoutSeconds = input.maxTimeoutSeconds ?? DEFAULT_X402_MAX_TIMEOUT_SECONDS;
|
|
101
|
-
if (!Number.isInteger(maxTimeoutSeconds) || maxTimeoutSeconds <= 0) {
|
|
102
|
-
throw new X402RequirementsError("maxTimeoutSeconds must be a positive integer");
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
scheme: X402_EXACT_SCHEME,
|
|
106
|
-
network,
|
|
107
|
-
maxAmountRequired: input.priceBaseUnits.toString(),
|
|
108
|
-
resource: resource.toString(),
|
|
109
|
-
description: input.description ??
|
|
110
|
-
"One call to a Metrik-listed service. Metrik's facilitator refuses to settle this payment while its oracle reports the service as failing.",
|
|
111
|
-
mimeType: input.mimeType ?? "application/json",
|
|
112
|
-
payTo: getAddress(input.listing.operator),
|
|
113
|
-
maxTimeoutSeconds,
|
|
114
|
-
asset: getAddress(asset.address),
|
|
115
|
-
extra: {
|
|
116
|
-
// Required by the x402 `exact` EVM binding so the payer can sign the
|
|
117
|
-
// EIP-3009 authorization offline.
|
|
118
|
-
name: asset.eip712Name,
|
|
119
|
-
version: asset.eip712Version,
|
|
120
|
-
// ADVISORY ONLY. The facilitator NEVER reads this to decide anything: it
|
|
121
|
-
// arrives inside a caller-supplied request body, so trusting it would let
|
|
122
|
-
// a caller pick which service's delivery record gets checked. The
|
|
123
|
-
// facilitator re-derives the service from `resource` against its own
|
|
124
|
-
// registry view. Published purely so a client can look the listing up.
|
|
125
|
-
metrikServiceRef: input.listing.serviceRef,
|
|
126
|
-
},
|
|
127
|
-
...(input.outputSchema === undefined
|
|
128
|
-
? {}
|
|
129
|
-
: { outputSchema: input.outputSchema }),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
export function buildX402PaymentRequiredBody(accepts, error = "X-PAYMENT header is required") {
|
|
133
|
-
if (accepts.length === 0) {
|
|
134
|
-
throw new X402RequirementsError("a 402 must advertise at least one PaymentRequirements");
|
|
135
|
-
}
|
|
136
|
-
return { x402Version: X402_VERSION, error, accepts };
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=payment-requirements.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment-requirements.js","sourceRoot":"","sources":["../../src/x402/payment-requirements.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAQpD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,kFAAkF;AAClF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAU,CAAC;AAEvC,gFAAgF;AAChF,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAgB,CAAC;AAElD,gFAAgF;AAChF,MAAM,CAAC,MAAM,wBAAwB,GAEjC,MAAM,CAAC,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,cAAc;CACtB,CAAC,CAAC;AAWH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAChC,MAAM,CAAC,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;QAClB,OAAO,EAAE,4CAAuD;QAChE,UAAU,EAAE,UAAU;QACtB,aAAa,EAAE,GAAG;QAClB,QAAQ,EAAE,CAAC;KACZ,CAAC;IACF,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;QACnB,OAAO,EAAE,4CAAuD;QAChE,UAAU,EAAE,MAAM;QAClB,aAAa,EAAE,GAAG;QAClB,QAAQ,EAAE,CAAC;KACZ,CAAC;CACH,CAAC,CAAC;AAEL,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AA6BD,0EAA0E;AAC1E,MAAM,CAAC,M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AE,WAAW,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AACvD,CAAC"}
|
package/dist/x402/relayer.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type Chain, type Hex } from "viem";
|
|
2
|
-
import type { PaymentSettler, PaymentVerifier } from "./verified-delivery-facilitator.js";
|
|
3
|
-
/**
|
|
4
|
-
* Chain wiring for the payment half of Metrik's x402 facilitator.
|
|
5
|
-
*
|
|
6
|
-
* Nothing here is Metrik-specific: verification and settlement are delegated
|
|
7
|
-
* VERBATIM to the real `x402/facilitator` implementation of the `exact` scheme.
|
|
8
|
-
* Metrik does not reimplement EIP-3009, and a change in the library's rules is
|
|
9
|
-
* inherited rather than drifted away from. The Metrik-specific part — the
|
|
10
|
-
* delivery gate — lives entirely in `./verified-delivery-facilitator.ts` and is
|
|
11
|
-
* layered ON TOP of whatever this returns.
|
|
12
|
-
*/
|
|
13
|
-
export declare const X402_CHAINS: Readonly<Record<number, Chain>>;
|
|
14
|
-
export interface X402ChainOptions {
|
|
15
|
-
/** Default `84532` (Base Sepolia). */
|
|
16
|
-
readonly chainId?: number;
|
|
17
|
-
/** RPC endpoint. Required: the library's default public RPCs are not operable infrastructure. */
|
|
18
|
-
readonly rpcUrl: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Read-only verifier. Needs an RPC because the `exact` scheme checks the payer's
|
|
22
|
-
* on-chain balance; it holds no key and can broadcast nothing.
|
|
23
|
-
*/
|
|
24
|
-
export declare function createX402PaymentVerifier(options: X402ChainOptions): PaymentVerifier;
|
|
25
|
-
export interface X402RelayerOptions extends X402ChainOptions {
|
|
26
|
-
/**
|
|
27
|
-
* The relayer's private key. This wallet BROADCASTS and pays gas; it never
|
|
28
|
-
* custodies payment funds (EIP-3009 moves value directly from payer to payee).
|
|
29
|
-
* Supplied by the operator through the environment, exactly like every other
|
|
30
|
-
* wallet in this package. Never committed, never defaulted.
|
|
31
|
-
*/
|
|
32
|
-
readonly privateKey: Hex;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* The settlement half. Constructing this is the ONLY place a key enters the
|
|
36
|
-
* facilitator, and there is no code path that broadcasts without one.
|
|
37
|
-
*/
|
|
38
|
-
export declare function createX402PaymentSettler(options: X402RelayerOptions): PaymentSettler;
|
|
39
|
-
/** The relayer address, so an operator can check what they must fund with gas. */
|
|
40
|
-
export declare function relayerAddress(privateKey: Hex): `0x${string}`;
|
|
41
|
-
//# sourceMappingURL=relayer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relayer.d.ts","sourceRoot":"","sources":["../../src/x402/relayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,KAAK,EACV,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AAWd,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAChB,MAAM,oCAAoC,CAAC;AAE5C;;;;;;;;;GASG;AAEH,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAGtD,CAAC;AAEH,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,iGAAiG;IACjG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAUD;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,gBAAgB,GACxB,eAAe,CAkBjB;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,kBAAkB,GAC1B,cAAc,CAoBhB;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,UAAU,EAAE,GAAG,GAAG,KAAK,MAAM,EAAE,CAE7D"}
|