@absol-labs/agent 0.10.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.
Files changed (331) hide show
  1. package/README.md +106 -30
  2. package/dist/capability/invocation-capability.d.ts +20 -8
  3. package/dist/capability/invocation-capability.d.ts.map +1 -1
  4. package/dist/capability/invocation-capability.js.map +1 -1
  5. package/dist/capability/probe-capability.d.ts +225 -0
  6. package/dist/capability/probe-capability.d.ts.map +1 -0
  7. package/dist/capability/probe-capability.js +248 -0
  8. package/dist/capability/probe-capability.js.map +1 -0
  9. package/dist/cli/args.d.ts +11 -0
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js +23 -0
  12. package/dist/cli/args.js.map +1 -1
  13. package/dist/cli/commands/claim.d.ts.map +1 -1
  14. package/dist/cli/commands/claim.js +21 -5
  15. package/dist/cli/commands/claim.js.map +1 -1
  16. package/dist/cli/commands/close.d.ts.map +1 -1
  17. package/dist/cli/commands/close.js +51 -7
  18. package/dist/cli/commands/close.js.map +1 -1
  19. package/dist/cli/commands/invoke.d.ts +2 -0
  20. package/dist/cli/commands/invoke.d.ts.map +1 -1
  21. package/dist/cli/commands/invoke.js +3 -2
  22. package/dist/cli/commands/invoke.js.map +1 -1
  23. package/dist/cli/commands/mcp.d.ts.map +1 -1
  24. package/dist/cli/commands/mcp.js +15 -2
  25. package/dist/cli/commands/mcp.js.map +1 -1
  26. package/dist/cli/commands/open.d.ts.map +1 -1
  27. package/dist/cli/commands/open.js +121 -15
  28. package/dist/cli/commands/open.js.map +1 -1
  29. package/dist/cli/commands/pay.d.ts +19 -0
  30. package/dist/cli/commands/pay.d.ts.map +1 -0
  31. package/dist/cli/commands/pay.js +355 -0
  32. package/dist/cli/commands/pay.js.map +1 -0
  33. package/dist/cli/commands/reclaim-unverified.d.ts.map +1 -1
  34. package/dist/cli/commands/reclaim-unverified.js +15 -6
  35. package/dist/cli/commands/reclaim-unverified.js.map +1 -1
  36. package/dist/cli/commands/reclaim.d.ts +23 -2
  37. package/dist/cli/commands/reclaim.d.ts.map +1 -1
  38. package/dist/cli/commands/reclaim.js +200 -21
  39. package/dist/cli/commands/reclaim.js.map +1 -1
  40. package/dist/cli/commands/refund.d.ts +13 -0
  41. package/dist/cli/commands/refund.d.ts.map +1 -0
  42. package/dist/cli/commands/refund.js +224 -0
  43. package/dist/cli/commands/refund.js.map +1 -0
  44. package/dist/cli/commands/status.d.ts.map +1 -1
  45. package/dist/cli/commands/status.js +10 -1
  46. package/dist/cli/commands/status.js.map +1 -1
  47. package/dist/cli/commands/streams.js +9 -13
  48. package/dist/cli/commands/streams.js.map +1 -1
  49. package/dist/cli/commands/watch.d.ts.map +1 -1
  50. package/dist/cli/commands/watch.js +2 -1
  51. package/dist/cli/commands/watch.js.map +1 -1
  52. package/dist/cli/config.d.ts +44 -26
  53. package/dist/cli/config.d.ts.map +1 -1
  54. package/dist/cli/config.js +88 -38
  55. package/dist/cli/config.js.map +1 -1
  56. package/dist/cli/deps.d.ts +86 -7
  57. package/dist/cli/deps.d.ts.map +1 -1
  58. package/dist/cli/deps.js +102 -16
  59. package/dist/cli/deps.js.map +1 -1
  60. package/dist/cli/errors.d.ts.map +1 -1
  61. package/dist/cli/errors.js +21 -1
  62. package/dist/cli/errors.js.map +1 -1
  63. package/dist/cli/escape-hatch.d.ts +6 -4
  64. package/dist/cli/escape-hatch.d.ts.map +1 -1
  65. package/dist/cli/escape-hatch.js +6 -2
  66. package/dist/cli/escape-hatch.js.map +1 -1
  67. package/dist/cli/listings.d.ts +18 -0
  68. package/dist/cli/listings.d.ts.map +1 -1
  69. package/dist/cli/listings.js +22 -12
  70. package/dist/cli/listings.js.map +1 -1
  71. package/dist/cli/preflight.d.ts +20 -14
  72. package/dist/cli/preflight.d.ts.map +1 -1
  73. package/dist/cli/preflight.js +34 -20
  74. package/dist/cli/preflight.js.map +1 -1
  75. package/dist/cli/privy.d.ts +83 -0
  76. package/dist/cli/privy.d.ts.map +1 -0
  77. package/dist/cli/privy.js +232 -0
  78. package/dist/cli/privy.js.map +1 -0
  79. package/dist/cli/reclaimability.d.ts +82 -0
  80. package/dist/cli/reclaimability.d.ts.map +1 -0
  81. package/dist/cli/reclaimability.js +80 -0
  82. package/dist/cli/reclaimability.js.map +1 -0
  83. package/dist/cli/run.d.ts +2 -1
  84. package/dist/cli/run.d.ts.map +1 -1
  85. package/dist/cli/run.js +40 -11
  86. package/dist/cli/run.js.map +1 -1
  87. package/dist/cli/scan-range.d.ts +2 -2
  88. package/dist/cli/scan-range.js +2 -2
  89. package/dist/cli/spend-policy.d.ts +60 -0
  90. package/dist/cli/spend-policy.d.ts.map +1 -0
  91. package/dist/cli/spend-policy.js +65 -0
  92. package/dist/cli/spend-policy.js.map +1 -0
  93. package/dist/cli/status.d.ts +3 -1
  94. package/dist/cli/status.d.ts.map +1 -1
  95. package/dist/cli/status.js +15 -3
  96. package/dist/cli/status.js.map +1 -1
  97. package/dist/cli/wallet.d.ts +109 -40
  98. package/dist/cli/wallet.d.ts.map +1 -1
  99. package/dist/cli/wallet.js +109 -44
  100. package/dist/cli/wallet.js.map +1 -1
  101. package/dist/discovery/rate-band.d.ts +74 -0
  102. package/dist/discovery/rate-band.d.ts.map +1 -0
  103. package/dist/discovery/rate-band.js +114 -0
  104. package/dist/discovery/rate-band.js.map +1 -0
  105. package/dist/escrow-generation.d.ts +81 -0
  106. package/dist/escrow-generation.d.ts.map +1 -0
  107. package/dist/escrow-generation.js +76 -0
  108. package/dist/escrow-generation.js.map +1 -0
  109. package/dist/frameworks/agentkit.d.ts +8 -4
  110. package/dist/frameworks/agentkit.d.ts.map +1 -1
  111. package/dist/frameworks/agentkit.js +27 -10
  112. package/dist/frameworks/agentkit.js.map +1 -1
  113. package/dist/frameworks/eliza.d.ts +3 -3
  114. package/dist/frameworks/eliza.d.ts.map +1 -1
  115. package/dist/frameworks/eliza.js +15 -6
  116. package/dist/frameworks/eliza.js.map +1 -1
  117. package/dist/frameworks/langchain.d.ts.map +1 -1
  118. package/dist/frameworks/langchain.js +8 -0
  119. package/dist/frameworks/langchain.js.map +1 -1
  120. package/dist/gateway/caller-auth-gateway.d.ts +91 -4
  121. package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
  122. package/dist/gateway/caller-auth-gateway.js +184 -7
  123. package/dist/gateway/caller-auth-gateway.js.map +1 -1
  124. package/dist/gateway/http-server.d.ts +121 -1
  125. package/dist/gateway/http-server.d.ts.map +1 -1
  126. package/dist/gateway/http-server.js +474 -5
  127. package/dist/gateway/http-server.js.map +1 -1
  128. package/dist/gateway/probe-auth.d.ts +112 -0
  129. package/dist/gateway/probe-auth.d.ts.map +1 -0
  130. package/dist/gateway/probe-auth.js +127 -0
  131. package/dist/gateway/probe-auth.js.map +1 -0
  132. package/dist/gateway/signed-rate-bounds.d.ts +51 -0
  133. package/dist/gateway/signed-rate-bounds.d.ts.map +1 -0
  134. package/dist/gateway/signed-rate-bounds.js +94 -0
  135. package/dist/gateway/signed-rate-bounds.js.map +1 -0
  136. package/dist/gateway/x402-opener-mode.d.ts +215 -0
  137. package/dist/gateway/x402-opener-mode.d.ts.map +1 -0
  138. package/dist/gateway/x402-opener-mode.js +639 -0
  139. package/dist/gateway/x402-opener-mode.js.map +1 -0
  140. package/dist/index.d.ts +11 -5
  141. package/dist/index.d.ts.map +1 -1
  142. package/dist/index.js +15 -5
  143. package/dist/index.js.map +1 -1
  144. package/dist/mandates/env.d.ts +3 -2
  145. package/dist/mandates/env.d.ts.map +1 -1
  146. package/dist/mandates/env.js +3 -2
  147. package/dist/mandates/env.js.map +1 -1
  148. package/dist/mcp/server.d.ts +100 -0
  149. package/dist/mcp/server.d.ts.map +1 -1
  150. package/dist/mcp/server.js +719 -39
  151. package/dist/mcp/server.js.map +1 -1
  152. package/dist/mcp/service-invoker.d.ts +97 -0
  153. package/dist/mcp/service-invoker.d.ts.map +1 -0
  154. package/dist/mcp/service-invoker.js +167 -0
  155. package/dist/mcp/service-invoker.js.map +1 -0
  156. package/dist/mcp/x402-tools.d.ts +104 -0
  157. package/dist/mcp/x402-tools.d.ts.map +1 -0
  158. package/dist/mcp/x402-tools.js +434 -0
  159. package/dist/mcp/x402-tools.js.map +1 -0
  160. package/dist/network.d.ts +119 -0
  161. package/dist/network.d.ts.map +1 -0
  162. package/dist/network.js +199 -0
  163. package/dist/network.js.map +1 -0
  164. package/dist/sdk/invoke.d.ts +23 -4
  165. package/dist/sdk/invoke.d.ts.map +1 -1
  166. package/dist/sdk/invoke.js +71 -10
  167. package/dist/sdk/invoke.js.map +1 -1
  168. package/dist/wallet/autonomous-wallet-broker.d.ts +3 -0
  169. package/dist/wallet/autonomous-wallet-broker.d.ts.map +1 -1
  170. package/dist/wallet/autonomous-wallet-broker.js +27 -23
  171. package/dist/wallet/autonomous-wallet-broker.js.map +1 -1
  172. package/dist/wallet/autonomous-wallet-protocol.d.ts +8 -2
  173. package/dist/wallet/autonomous-wallet-protocol.d.ts.map +1 -1
  174. package/dist/wallet/autonomous-wallet-protocol.js +9 -2
  175. package/dist/wallet/autonomous-wallet-protocol.js.map +1 -1
  176. package/dist/wallet/autonomous-wallet.d.ts.map +1 -1
  177. package/dist/wallet/autonomous-wallet.js +3 -2
  178. package/dist/wallet/autonomous-wallet.js.map +1 -1
  179. package/dist/wallet/broker-escrows.d.ts +222 -0
  180. package/dist/wallet/broker-escrows.d.ts.map +1 -0
  181. package/dist/wallet/broker-escrows.js +36 -0
  182. package/dist/wallet/broker-escrows.js.map +1 -0
  183. package/dist/wallet/lifecycle.d.ts +21 -5
  184. package/dist/wallet/lifecycle.d.ts.map +1 -1
  185. package/dist/wallet/lifecycle.js +32 -12
  186. package/dist/wallet/lifecycle.js.map +1 -1
  187. package/dist/wallet/privy-broker-server.d.ts.map +1 -1
  188. package/dist/wallet/privy-broker-server.js +31 -26
  189. package/dist/wallet/privy-broker-server.js.map +1 -1
  190. package/dist/wallet/privy-session-broker.d.ts +14 -5
  191. package/dist/wallet/privy-session-broker.d.ts.map +1 -1
  192. package/dist/wallet/privy-session-broker.js +29 -17
  193. package/dist/wallet/privy-session-broker.js.map +1 -1
  194. package/dist/wallet/privy-session-provider.d.ts +3 -1
  195. package/dist/wallet/privy-session-provider.d.ts.map +1 -1
  196. package/dist/wallet/privy-session-provider.js +5 -3
  197. package/dist/wallet/privy-session-provider.js.map +1 -1
  198. package/dist/wallet/provider.d.ts.map +1 -1
  199. package/dist/wallet/provider.js +15 -8
  200. package/dist/wallet/provider.js.map +1 -1
  201. package/dist/x402/facilitator.d.ts +42 -17
  202. package/dist/x402/facilitator.d.ts.map +1 -1
  203. package/dist/x402/facilitator.js +49 -33
  204. package/dist/x402/facilitator.js.map +1 -1
  205. package/dist/x402-buyer/guarded-fetch.d.ts +51 -0
  206. package/dist/x402-buyer/guarded-fetch.d.ts.map +1 -0
  207. package/dist/x402-buyer/guarded-fetch.js +147 -0
  208. package/dist/x402-buyer/guarded-fetch.js.map +1 -0
  209. package/dist/x402-buyer/index.d.ts +10 -0
  210. package/dist/x402-buyer/index.d.ts.map +1 -0
  211. package/dist/x402-buyer/index.js +10 -0
  212. package/dist/x402-buyer/index.js.map +1 -0
  213. package/dist/x402-buyer/pay.d.ts +135 -0
  214. package/dist/x402-buyer/pay.d.ts.map +1 -0
  215. package/dist/x402-buyer/pay.js +336 -0
  216. package/dist/x402-buyer/pay.js.map +1 -0
  217. package/dist/x402-opener/abi.d.ts +684 -0
  218. package/dist/x402-opener/abi.d.ts.map +1 -0
  219. package/dist/x402-opener/abi.js +880 -0
  220. package/dist/x402-opener/abi.js.map +1 -0
  221. package/dist/x402-opener/facilitator-entry.d.ts +3 -0
  222. package/dist/x402-opener/facilitator-entry.d.ts.map +1 -0
  223. package/dist/x402-opener/facilitator-entry.js +37 -0
  224. package/dist/x402-opener/facilitator-entry.js.map +1 -0
  225. package/dist/x402-opener/facilitator-server.d.ts +180 -0
  226. package/dist/x402-opener/facilitator-server.d.ts.map +1 -0
  227. package/dist/x402-opener/facilitator-server.js +696 -0
  228. package/dist/x402-opener/facilitator-server.js.map +1 -0
  229. package/dist/x402-opener/index.d.ts +14 -0
  230. package/dist/x402-opener/index.d.ts.map +1 -0
  231. package/dist/x402-opener/index.js +14 -0
  232. package/dist/x402-opener/index.js.map +1 -0
  233. package/dist/x402-opener/listing-resolver.d.ts +55 -0
  234. package/dist/x402-opener/listing-resolver.d.ts.map +1 -0
  235. package/dist/x402-opener/listing-resolver.js +125 -0
  236. package/dist/x402-opener/listing-resolver.js.map +1 -0
  237. package/dist/x402-opener/refund-relay.d.ts +240 -0
  238. package/dist/x402-opener/refund-relay.d.ts.map +1 -0
  239. package/dist/x402-opener/refund-relay.js +1240 -0
  240. package/dist/x402-opener/refund-relay.js.map +1 -0
  241. package/dist/x402-opener/relayer-queue.d.ts +14 -0
  242. package/dist/x402-opener/relayer-queue.d.ts.map +1 -0
  243. package/dist/x402-opener/relayer-queue.js +18 -0
  244. package/dist/x402-opener/relayer-queue.js.map +1 -0
  245. package/dist/x402-opener/scheme.d.ts +217 -0
  246. package/dist/x402-opener/scheme.d.ts.map +1 -0
  247. package/dist/x402-opener/scheme.js +749 -0
  248. package/dist/x402-opener/scheme.js.map +1 -0
  249. package/dist/x402-opener/terms.d.ts +105 -0
  250. package/dist/x402-opener/terms.d.ts.map +1 -0
  251. package/dist/x402-opener/terms.js +212 -0
  252. package/dist/x402-opener/terms.js.map +1 -0
  253. package/dist/zktls/reclaim.d.ts +2 -2
  254. package/docs/agent-layer.md +13 -8
  255. package/docs/autonomous-privy-wallet.md +188 -0
  256. package/docs/cli.md +342 -53
  257. package/docs/langchain.md +5 -0
  258. package/docs/mcp-hosted.md +4 -3
  259. package/docs/mcp-reference.md +245 -0
  260. package/docs/probe-capability.md +191 -0
  261. package/docs/quickstart.md +54 -5
  262. package/docs/threat-model.md +24 -3
  263. package/docs/x402.md +681 -0
  264. package/package.json +19 -6
  265. package/src/capability/invocation-capability.ts +17 -1
  266. package/src/capability/probe-capability.ts +355 -0
  267. package/src/cli/args.ts +29 -0
  268. package/src/cli/commands/claim.ts +31 -5
  269. package/src/cli/commands/close.ts +56 -7
  270. package/src/cli/commands/invoke.ts +6 -2
  271. package/src/cli/commands/mcp.ts +18 -2
  272. package/src/cli/commands/open.ts +151 -14
  273. package/src/cli/commands/pay.ts +442 -0
  274. package/src/cli/commands/reclaim-unverified.ts +24 -6
  275. package/src/cli/commands/reclaim.ts +274 -19
  276. package/src/cli/commands/refund.ts +277 -0
  277. package/src/cli/commands/status.ts +17 -1
  278. package/src/cli/commands/streams.ts +11 -15
  279. package/src/cli/commands/watch.ts +7 -1
  280. package/src/cli/config.ts +139 -52
  281. package/src/cli/deps.ts +189 -25
  282. package/src/cli/errors.ts +24 -1
  283. package/src/cli/escape-hatch.ts +19 -5
  284. package/src/cli/listings.ts +43 -10
  285. package/src/cli/preflight.ts +36 -21
  286. package/src/cli/privy.ts +398 -0
  287. package/src/cli/reclaimability.ts +154 -0
  288. package/src/cli/run.ts +54 -11
  289. package/src/cli/scan-range.ts +2 -2
  290. package/src/cli/spend-policy.ts +139 -0
  291. package/src/cli/status.ts +14 -1
  292. package/src/cli/wallet.ts +189 -58
  293. package/src/discovery/rate-band.ts +172 -0
  294. package/src/escrow-generation.ts +135 -0
  295. package/src/frameworks/agentkit.ts +45 -11
  296. package/src/frameworks/eliza.ts +27 -5
  297. package/src/frameworks/langchain.ts +14 -0
  298. package/src/gateway/caller-auth-gateway.ts +336 -13
  299. package/src/gateway/http-server.ts +690 -7
  300. package/src/gateway/probe-auth.ts +191 -0
  301. package/src/gateway/signed-rate-bounds.ts +164 -0
  302. package/src/gateway/x402-opener-mode.ts +974 -0
  303. package/src/index.ts +112 -14
  304. package/src/mandates/env.ts +3 -2
  305. package/src/mcp/server.ts +973 -44
  306. package/src/mcp/service-invoker.ts +285 -0
  307. package/src/mcp/x402-tools.ts +621 -0
  308. package/src/network.ts +302 -0
  309. package/src/sdk/invoke.ts +96 -17
  310. package/src/wallet/autonomous-wallet-broker.ts +46 -20
  311. package/src/wallet/autonomous-wallet-protocol.ts +11 -2
  312. package/src/wallet/autonomous-wallet.ts +4 -2
  313. package/src/wallet/broker-escrows.ts +66 -0
  314. package/src/wallet/lifecycle.ts +53 -18
  315. package/src/wallet/privy-broker-server.ts +35 -25
  316. package/src/wallet/privy-session-broker.ts +58 -25
  317. package/src/wallet/privy-session-provider.ts +7 -3
  318. package/src/wallet/provider.ts +20 -15
  319. package/src/x402/facilitator.ts +85 -46
  320. package/src/x402-buyer/guarded-fetch.ts +213 -0
  321. package/src/x402-buyer/index.ts +9 -0
  322. package/src/x402-buyer/pay.ts +517 -0
  323. package/src/x402-opener/abi.ts +881 -0
  324. package/src/x402-opener/facilitator-entry.ts +45 -0
  325. package/src/x402-opener/facilitator-server.ts +1014 -0
  326. package/src/x402-opener/index.ts +13 -0
  327. package/src/x402-opener/listing-resolver.ts +202 -0
  328. package/src/x402-opener/refund-relay.ts +1743 -0
  329. package/src/x402-opener/relayer-queue.ts +18 -0
  330. package/src/x402-opener/scheme.ts +1133 -0
  331. package/src/x402-opener/terms.ts +300 -0
@@ -0,0 +1,112 @@
1
+ import type { Address } from "viem";
2
+ /**
3
+ * Seller-side plumbing for oracle-signed probe verification.
4
+ *
5
+ * Two pieces, both deliberately small and both fail-closed:
6
+ *
7
+ * 1. {@link OracleSignerSetReader} — WHO may mint a `ProbeCapability`. Read
8
+ * straight off the escrow's `getOracleSigners()`, which is a public `view`.
9
+ * There is no registration step, no shared secret, and no trust in the
10
+ * oracle's own say-so: a third-party seller performs the identical read.
11
+ * 2. {@link ProbeRateLimiter} — how often a probe may be served for free.
12
+ * Without a bound, an oracle-signed capability is a licence to consume the
13
+ * seller's service indefinitely at no cost.
14
+ */
15
+ /** Resolves the escrow's current oracle signer set (lowercased). */
16
+ export interface OracleSignerSetReader {
17
+ getOracleSigners(): Promise<readonly Address[]>;
18
+ }
19
+ /** Default reader: a read-only `getOracleSigners()` call. No wallet, no writes. */
20
+ export declare function createSdkOracleSignerSetReader(options: {
21
+ readonly escrowAddress: Address;
22
+ readonly rpcUrl: string;
23
+ /** Chain of the escrow; must be a registered network. Default: the registry default. */
24
+ readonly chainId?: number;
25
+ }): OracleSignerSetReader;
26
+ /**
27
+ * Default freshness bound for the cached signer set, in seconds. The set only
28
+ * changes by an explicit escrow transaction, so a short cache costs nothing in
29
+ * correctness while keeping one RPC read off every probe.
30
+ */
31
+ export declare const DEFAULT_ORACLE_SIGNER_CACHE_SECONDS = 60;
32
+ /**
33
+ * Bounded-staleness cache over {@link OracleSignerSetReader}.
34
+ *
35
+ * FAIL-CLOSED by construction: once the cached set is older than its TTL it is
36
+ * discarded, and a refresh that fails resolves to `undefined` rather than
37
+ * serving the stale set. A probe is a free call, so "the RPC is down" must deny
38
+ * — which the oracle then reports as unverifiable, never as passing.
39
+ *
40
+ * Concurrent callers share one in-flight refresh, so a burst of probes cannot
41
+ * fan out into a burst of RPC reads.
42
+ */
43
+ export declare class CachedOracleSignerSet {
44
+ private readonly reader;
45
+ private readonly ttlSeconds;
46
+ private readonly now;
47
+ private cached;
48
+ private inFlight;
49
+ constructor(reader: OracleSignerSetReader, ttlSeconds?: number, now?: () => number);
50
+ /** The current set, or `undefined` when it could not be read fresh enough. */
51
+ resolve(): Promise<ReadonlySet<string> | undefined>;
52
+ }
53
+ /** Bounds how many probes this gateway will serve for free. */
54
+ export interface ProbeRateLimiter {
55
+ /** Returns `true` (and consumes budget) IFF a probe may be served now. */
56
+ tryConsume(): boolean;
57
+ }
58
+ /**
59
+ * Default probe budget, in probes per minute.
60
+ *
61
+ * Derived from the real cadence, not picked round: the oracle checkpoints every
62
+ * ~15-22s, so a single vantage probes a given service at most ~4 times a
63
+ * minute. T1 multi-vantage fans that out across at most 9 vantages (the
64
+ * coordinator plus the 8-worker cap in the oracle's vantage config), giving a
65
+ * worst-case honest load of ~36 probes/minute. 60 leaves headroom for a
66
+ * re-execution sample and clock jitter while capping the free-service surface
67
+ * at one request per second — orders of magnitude below what would make this an
68
+ * economically interesting way to get the service for nothing.
69
+ */
70
+ export declare const DEFAULT_MAX_PROBES_PER_MINUTE = 60;
71
+ /**
72
+ * Fixed-window probe limiter. One counter for the whole gateway (which fronts
73
+ * one service), so the bound holds no matter how many oracle signers exist or
74
+ * how many vantages a coordinator runs.
75
+ *
76
+ * A useful secondary effect: because every probe capability is single-use and
77
+ * short-lived, this limiter is also what bounds the shared nonce replay cache —
78
+ * at most `maxPerMinute x ttl/60` probe nonces can be live at once.
79
+ */
80
+ export declare class FixedWindowProbeRateLimiter implements ProbeRateLimiter {
81
+ private readonly maxPerMinute;
82
+ private readonly now;
83
+ private windowStart;
84
+ private count;
85
+ constructor(maxPerMinute?: number, now?: () => number);
86
+ tryConsume(): boolean;
87
+ }
88
+ /** Opt-in probe verification mode for {@link CallerAuthGateway}. */
89
+ export interface GatewayProbeMode {
90
+ /**
91
+ * Who may mint. Defaults to a read-only `getOracleSigners()` reader built
92
+ * from the gateway's own escrow + RPC.
93
+ */
94
+ readonly signerSetReader?: OracleSignerSetReader;
95
+ /** Freshness bound for the cached signer set. Default {@link DEFAULT_ORACLE_SIGNER_CACHE_SECONDS}. */
96
+ readonly signerCacheSeconds?: number;
97
+ /** Probe budget. Default {@link DEFAULT_MAX_PROBES_PER_MINUTE}. */
98
+ readonly maxProbesPerMinute?: number;
99
+ /** Override the limiter entirely (tests, or a shared multi-instance store). */
100
+ readonly rateLimiter?: ProbeRateLimiter;
101
+ /** Probe capability header name. Default `x-metrik-probe-capability`. */
102
+ readonly headerName?: string;
103
+ }
104
+ /** What an authorized probe tells the caller. Carries NO stream and NO payment. */
105
+ export interface ProbeAuthorization {
106
+ /** The oracle signer that minted the capability. */
107
+ readonly oracle: Address;
108
+ readonly serviceRef: `0x${string}`;
109
+ /** Unix seconds the capability expires at. */
110
+ readonly expiry: number;
111
+ }
112
+ //# sourceMappingURL=probe-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe-auth.d.ts","sourceRoot":"","sources":["../../src/gateway/probe-au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C,KAAK,CAAK;gBAGC,YAAY,GAAE,MAAsC,EACpD,GAAG,GAAE,MAAM,MAA4C;IAQ1E,UAAU,IAAI,OAAO;CAYtB;AAED,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACjD,sGAAsG;IACtG,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,mEAAmE;IACnE,QAAQ,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IACrC,+EAA+E;IAC/E,QAAQ,CAAC,WAAW,CAAC,EAAE,gBAAgB,CAAC;IACxC,yEAAyE;IACzE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,mFAAmF;AACnF,MAAM,WAAW,kBAAkB;IACjC,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,KAAK,MAAM,EAAE,CAAC;IACnC,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,127 @@
1
+ import { streamEscrowV2Abi } from "@absol-labs/shared";
2
+ import { readOnlyMetrikClient } from "../network.js";
3
+ /** Default reader: a read-only `getOracleSigners()` call. No wallet, no writes. */
4
+ export function createSdkOracleSignerSetReader(options) {
5
+ const metrik = readOnlyMetrikClient(options);
6
+ return {
7
+ async getOracleSigners() {
8
+ return (await metrik.publicClient.readContract({
9
+ address: options.escrowAddress,
10
+ abi: streamEscrowV2Abi,
11
+ functionName: "getOracleSigners",
12
+ }));
13
+ },
14
+ };
15
+ }
16
+ /**
17
+ * Default freshness bound for the cached signer set, in seconds. The set only
18
+ * changes by an explicit escrow transaction, so a short cache costs nothing in
19
+ * correctness while keeping one RPC read off every probe.
20
+ */
21
+ export const DEFAULT_ORACLE_SIGNER_CACHE_SECONDS = 60;
22
+ /**
23
+ * Bounded-staleness cache over {@link OracleSignerSetReader}.
24
+ *
25
+ * FAIL-CLOSED by construction: once the cached set is older than its TTL it is
26
+ * discarded, and a refresh that fails resolves to `undefined` rather than
27
+ * serving the stale set. A probe is a free call, so "the RPC is down" must deny
28
+ * — which the oracle then reports as unverifiable, never as passing.
29
+ *
30
+ * Concurrent callers share one in-flight refresh, so a burst of probes cannot
31
+ * fan out into a burst of RPC reads.
32
+ */
33
+ export class CachedOracleSignerSet {
34
+ reader;
35
+ ttlSeconds;
36
+ now;
37
+ cached;
38
+ inFlight;
39
+ constructor(reader, ttlSeconds = DEFAULT_ORACLE_SIGNER_CACHE_SECONDS, now = () => Math.floor(Date.now() / 1000)) {
40
+ this.reader = reader;
41
+ this.ttlSeconds = ttlSeconds;
42
+ this.now = now;
43
+ if (!Number.isFinite(ttlSeconds) || ttlSeconds <= 0) {
44
+ throw new Error("oracle signer cache ttlSeconds must be a positive number");
45
+ }
46
+ }
47
+ /** The current set, or `undefined` when it could not be read fresh enough. */
48
+ async resolve() {
49
+ const cached = this.cached;
50
+ if (cached !== undefined && this.now() - cached.at <= this.ttlSeconds) {
51
+ return cached.signers;
52
+ }
53
+ if (this.inFlight !== undefined) {
54
+ return this.inFlight;
55
+ }
56
+ const refresh = (async () => {
57
+ try {
58
+ const signers = await this.reader.getOracleSigners();
59
+ const set = new Set(signers.map((signer) => signer.toLowerCase()));
60
+ // An empty set is a real answer, and it means nobody may probe.
61
+ this.cached = { signers: set, at: this.now() };
62
+ return set;
63
+ }
64
+ catch {
65
+ // Drop the stale entry rather than serving it: a signer REMOVED from
66
+ // the escrow must stop being able to probe within one TTL, not within
67
+ // "however long the RPC stays down".
68
+ this.cached = undefined;
69
+ return undefined;
70
+ }
71
+ finally {
72
+ this.inFlight = undefined;
73
+ }
74
+ })();
75
+ this.inFlight = refresh;
76
+ return refresh;
77
+ }
78
+ }
79
+ /**
80
+ * Default probe budget, in probes per minute.
81
+ *
82
+ * Derived from the real cadence, not picked round: the oracle checkpoints every
83
+ * ~15-22s, so a single vantage probes a given service at most ~4 times a
84
+ * minute. T1 multi-vantage fans that out across at most 9 vantages (the
85
+ * coordinator plus the 8-worker cap in the oracle's vantage config), giving a
86
+ * worst-case honest load of ~36 probes/minute. 60 leaves headroom for a
87
+ * re-execution sample and clock jitter while capping the free-service surface
88
+ * at one request per second — orders of magnitude below what would make this an
89
+ * economically interesting way to get the service for nothing.
90
+ */
91
+ export const DEFAULT_MAX_PROBES_PER_MINUTE = 60;
92
+ /**
93
+ * Fixed-window probe limiter. One counter for the whole gateway (which fronts
94
+ * one service), so the bound holds no matter how many oracle signers exist or
95
+ * how many vantages a coordinator runs.
96
+ *
97
+ * A useful secondary effect: because every probe capability is single-use and
98
+ * short-lived, this limiter is also what bounds the shared nonce replay cache —
99
+ * at most `maxPerMinute x ttl/60` probe nonces can be live at once.
100
+ */
101
+ export class FixedWindowProbeRateLimiter {
102
+ maxPerMinute;
103
+ now;
104
+ windowStart;
105
+ count = 0;
106
+ constructor(maxPerMinute = DEFAULT_MAX_PROBES_PER_MINUTE, now = () => Math.floor(Date.now() / 1000)) {
107
+ this.maxPerMinute = maxPerMinute;
108
+ this.now = now;
109
+ if (!Number.isInteger(maxPerMinute) || maxPerMinute <= 0) {
110
+ throw new Error("maxProbesPerMinute must be a positive integer");
111
+ }
112
+ this.windowStart = this.now();
113
+ }
114
+ tryConsume() {
115
+ const nowSeconds = this.now();
116
+ if (nowSeconds - this.windowStart >= 60) {
117
+ this.windowStart = nowSeconds;
118
+ this.count = 0;
119
+ }
120
+ if (this.count >= this.maxPerMinute) {
121
+ return false;
122
+ }
123
+ this.count += 1;
124
+ return true;
125
+ }
126
+ }
127
+ //# sourceMappingURL=probe-auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probe-auth.js","sourceRoot":"","sources":["../../src/gateway/probe-auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,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C,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI,YAAY,IAAI,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,UAAU;QACR,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,UAAU,GAAG,IAAI,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;YAC9B,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACjB,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ import { type Address, type Hex } from "viem";
2
+ /**
3
+ * Operator-SIGNED rate bounds for the gateway's capability path
4
+ * (metrik-agent#121 item 5, metrik-contracts#41).
5
+ *
6
+ * `StreamEscrowV2.openStream` only requires `ratePerSecond != 0`; the seller's
7
+ * signed `minRatePerSecond` / `maxRatePerSecond` are checked by the buyer-side
8
+ * SDK and the marketplace, not by the contract. A buyer who calls the escrow
9
+ * directly can therefore open a stream at 1 base unit per second. The gateway
10
+ * is the seller's own trust boundary, so it refuses to SERVE such a stream:
11
+ * the on-chain `ratePerSecond` must fall inside the band the operator signed.
12
+ *
13
+ * Bounds are only ever taken from a signed descriptor that verifies here — the
14
+ * serviceRef re-derives from the signed content and the EIP-712 signature
15
+ * recovers to the descriptor's operator. `CallerAuthGateway` accepts only
16
+ * objects this module produced, so a hand-built `{ minRatePerSecond: 0n }`
17
+ * cannot slip through as "signed".
18
+ */
19
+ export interface SignedRateBounds {
20
+ /** The serviceRef the bounds were signed for (re-derived, lower-case). */
21
+ readonly serviceRef: Hex;
22
+ /** The operator whose EIP-712 signature was recovered. */
23
+ readonly operator: Address;
24
+ /** Signed minimum rate, USDC base units per second; `null` = none signed. */
25
+ readonly minRatePerSecond: bigint | null;
26
+ /** Signed maximum rate, USDC base units per second; `null` = none signed. */
27
+ readonly maxRatePerSecond: bigint | null;
28
+ }
29
+ export declare class SignedRateBoundsError extends Error {
30
+ constructor(message: string, options?: {
31
+ readonly cause?: unknown;
32
+ });
33
+ }
34
+ /** Whether `bounds` came out of {@link verifySignedRateBounds} in this process. */
35
+ export declare function isVerifiedSignedRateBounds(bounds: unknown): bounds is SignedRateBounds;
36
+ /**
37
+ * Verify a signed service descriptor and extract its operator-signed rate band.
38
+ * Throws {@link SignedRateBoundsError} unless the schema parses, the serviceRef
39
+ * re-derives from the signed content, and the signature recovers to the
40
+ * descriptor's operator.
41
+ */
42
+ export declare function verifySignedRateBounds(signedDescriptor: unknown): Promise<SignedRateBounds>;
43
+ /**
44
+ * Load and verify the signed descriptor(s) in a JSON file: one signed
45
+ * descriptor object, or an array of them (one per served serviceRef, e.g. a
46
+ * migration alias). Fail closed on any read, parse or verification error.
47
+ */
48
+ export declare function loadSignedRateBoundsFile(path: string): Promise<SignedRateBounds[]>;
49
+ /** `undefined` when `rate` is inside the band, otherwise why it is not. */
50
+ export declare function rateOutsideBounds(rate: bigint, bounds: SignedRateBounds): string | undefined;
51
+ //# sourceMappingURL=signed-rate-bounds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-rate-bounds.d.ts","sourceRoot":"","sources":["../../src/gateway/signed-rate-bounds.ts"],"names":[],"mappings":"AAOA,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,CAAC;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC;IACzB,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,6EAA6E;IAC7E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,6EAA6E;IAC7E,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1C;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIpE;AAID,mFAAmF;AACnF,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,GACd,MAAM,IAAI,gBAAgB,CAE5B;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,gBAAgB,EAAE,OAAO,GACxB,OAAO,CAAC,gBAAgB,CAAC,CAmD3B;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA4B7B;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,gBAAgB,GACvB,MAAM,GAAG,SAAS,CAQpB"}
@@ -0,0 +1,94 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { deriveServiceRef, recoverServiceDescriptorSigner, signedServiceDescriptorSchema, } from "@absol-labs/shared";
3
+ import { getAddress } from "viem";
4
+ export class SignedRateBoundsError extends Error {
5
+ constructor(message, options) {
6
+ super(message, options);
7
+ this.name = "SignedRateBoundsError";
8
+ }
9
+ }
10
+ const verified = new WeakSet();
11
+ /** Whether `bounds` came out of {@link verifySignedRateBounds} in this process. */
12
+ export function isVerifiedSignedRateBounds(bounds) {
13
+ return typeof bounds === "object" && bounds !== null && verified.has(bounds);
14
+ }
15
+ /**
16
+ * Verify a signed service descriptor and extract its operator-signed rate band.
17
+ * Throws {@link SignedRateBoundsError} unless the schema parses, the serviceRef
18
+ * re-derives from the signed content, and the signature recovers to the
19
+ * descriptor's operator.
20
+ */
21
+ export async function verifySignedRateBounds(signedDescriptor) {
22
+ const parsed = signedServiceDescriptorSchema.safeParse(signedDescriptor);
23
+ if (!parsed.success) {
24
+ throw new SignedRateBoundsError(`not a signed service descriptor: ${parsed.error.issues
25
+ .map((issue) => `${issue.path.join(".")}: ${issue.message}`)
26
+ .join("; ")}`);
27
+ }
28
+ const signed = parsed.data;
29
+ const derived = deriveServiceRef(signed.descriptor).toLowerCase();
30
+ if (signed.serviceRef.toLowerCase() !== derived) {
31
+ throw new SignedRateBoundsError(`the signed descriptor's serviceRef ${signed.serviceRef} does not derive from its content (${derived}); it was tampered with or re-labelled`);
32
+ }
33
+ let signer;
34
+ try {
35
+ signer = await recoverServiceDescriptorSigner(signed.descriptor, signed.signature);
36
+ }
37
+ catch (cause) {
38
+ throw new SignedRateBoundsError("the signed descriptor's signature could not be recovered", { cause });
39
+ }
40
+ if (signer === null ||
41
+ signer.toLowerCase() !== signed.descriptor.operator.toLowerCase()) {
42
+ throw new SignedRateBoundsError(`the descriptor for ${derived} is not signed by its operator ${signed.descriptor.operator}`);
43
+ }
44
+ const commercial = signed.descriptor.commercial;
45
+ const bounds = Object.freeze({
46
+ serviceRef: derived,
47
+ operator: getAddress(signed.descriptor.operator),
48
+ minRatePerSecond: commercial?.minRatePerSecond === undefined
49
+ ? null
50
+ : BigInt(commercial.minRatePerSecond),
51
+ maxRatePerSecond: commercial?.maxRatePerSecond === undefined
52
+ ? null
53
+ : BigInt(commercial.maxRatePerSecond),
54
+ });
55
+ verified.add(bounds);
56
+ return bounds;
57
+ }
58
+ /**
59
+ * Load and verify the signed descriptor(s) in a JSON file: one signed
60
+ * descriptor object, or an array of them (one per served serviceRef, e.g. a
61
+ * migration alias). Fail closed on any read, parse or verification error.
62
+ */
63
+ export async function loadSignedRateBoundsFile(path) {
64
+ let raw;
65
+ try {
66
+ raw = await readFile(path, "utf8");
67
+ }
68
+ catch (cause) {
69
+ throw new SignedRateBoundsError(`could not read the signed descriptor file ${path}`, { cause });
70
+ }
71
+ let json;
72
+ try {
73
+ json = JSON.parse(raw);
74
+ }
75
+ catch (cause) {
76
+ throw new SignedRateBoundsError(`the signed descriptor file ${path} is not valid JSON`, { cause });
77
+ }
78
+ const entries = Array.isArray(json) ? json : [json];
79
+ if (entries.length === 0) {
80
+ throw new SignedRateBoundsError(`the signed descriptor file ${path} holds no descriptor`);
81
+ }
82
+ return await Promise.all(entries.map((entry) => verifySignedRateBounds(entry)));
83
+ }
84
+ /** `undefined` when `rate` is inside the band, otherwise why it is not. */
85
+ export function rateOutsideBounds(rate, bounds) {
86
+ if (bounds.minRatePerSecond !== null && rate < bounds.minRatePerSecond) {
87
+ return `rate ${rate} is below the operator-signed minimum ${bounds.minRatePerSecond}`;
88
+ }
89
+ if (bounds.maxRatePerSecond !== null && rate > bounds.maxRatePerSecond) {
90
+ return `rate ${rate} is above the operator-signed maximum ${bounds.maxRatePerSecond}`;
91
+ }
92
+ return undefined;
93
+ }
94
+ //# sourceMappingURL=signed-rate-bounds.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signed-rate-bounds.js","sourceRoot":"","sources":["../../src/gateway/signed-rate-bounds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAA0B,MAAM,MAAM,CAAC;AA8B1D,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,YAAY,OAAe,EAAE,OAAsC;QACjE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAU,CAAC;AAEvC,mFAAmF;AACnF,M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AC;QACf,MAAM,IAAI,qBAAqB,CAC7B,8BAA8B,IAAI,oBAAoB,EACtD,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACpD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,qBAAqB,CAC7B,8BAA8B,IAAI,sBAAsB,CACzD,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,OAAO,CAAC,GAAG,CACtB,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CACtD,CAAC;AACJ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,MAAwB;IAExB,IAAI,MAAM,CAAC,gBAAgB,KAAK,IAAI,IAAI,IAAI,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QACvE,OAAO,QAAQ,IAAI,yCAAyC,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACxF,CAAC;IACD,IAAI,MAAM,CAAC,gBAAgB,KAAK,IAAI,IAAI,IAAI,GAAG,MAAM,CAAC,gBAAgB,EAAE,CAAC;QACvE,OAAO,QAAQ,IAAI,yCAAyC,MAAM,CAAC,gBAAgB,EAAE,CAAC;IACxF,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,215 @@
1
+ import { x402HTTPResourceServer, type FacilitatorClient } from "@x402/core/server";
2
+ import type { Network } from "@x402/core/types";
3
+ import { type Address, type PublicClient } from "viem";
4
+ import { type OperatorSignedListingResolver } from "../x402-opener/listing-resolver.js";
5
+ import { type OpenerTerms, type X402SchemaDeclaration } from "../x402-opener/terms.js";
6
+ /**
7
+ * The gateway's x402 v2 mode (metrik-agent#116): answer an uncapabilitied
8
+ * request with a standard x402 v2 `402` whose `payTo` is the listing's
9
+ * `X402StreamOpener` address, and settle every accepted payment INTO a
10
+ * `StreamEscrowV2` stream through the Metrik opener facilitator.
11
+ *
12
+ * The wire format is the official `@x402/core` resource server's, not a
13
+ * re-implementation: `x402HTTPResourceServer` builds `PAYMENT-REQUIRED`,
14
+ * matches `PAYMENT-SIGNATURE`, verifies and settles through the facilitator and
15
+ * builds `PAYMENT-RESPONSE`.
16
+ *
17
+ * ## The opener payTo must ONLY ever be settled by the Metrik opener facilitator
18
+ *
19
+ * A stock x402 `exact` facilitator settles by calling
20
+ * `USDC.transferWithAuthorization(to = payTo)` directly. Pointed at an opener,
21
+ * that strands 100% of the payer's funds in the opener permanently (there is,
22
+ * deliberately, no sweep). So this mode:
23
+ *
24
+ * - refuses to START unless the configured facilitator's `GET /supported`
25
+ * advertises the opener marker for exactly this factory, escrow, token and
26
+ * chain; and re-checks that marker on a timer, failing CLOSED (503, no
27
+ * `payTo` quoted, nothing verified or settled) whenever it cannot;
28
+ * - uses exactly one facilitator client, never a fallback list;
29
+ * - registers no discovery (Bazaar) extension and never submits the route to
30
+ * any catalog. When (and only when) the operator configures an input/output
31
+ * schema, it is DECLARED in the 402 in the standard `extensions.bazaar`
32
+ * shape so a client can read what to send; only the Metrik opener
33
+ * facilitator ever sees the payment, and it catalogs nothing;
34
+ * - states plainly in the 402 `description` what is bought (the stream
35
+ * window, rate, that the seller earns only verified seconds, and that
36
+ * unearned money is refundable without ETH through the facilitator's
37
+ * refund relay) and refuses to start unless that facilitator advertises
38
+ * the relay (`refundRelay: true` in its marker) — the 402 never promises a
39
+ * refund path that is not there. Refunds are not automatic;
40
+ * - authenticates the opener only as `factory.predict(terms)` — never by code
41
+ * or codehash, which a clone outside the factory can reproduce;
42
+ * - serves one EIP-3009 authorization at most once: a `PAYMENT-SIGNATURE`
43
+ * whose authorization is in flight or already settled gets `409` WITHOUT an
44
+ * upstream call (in-memory, per gateway instance). A retry after
45
+ * `settlement_pending` is let through so it can reconcile;
46
+ * - refuses to start if its price is below the facilitator's advertised
47
+ * minimum, or if its facilitator timeout would not outlast the facilitator's
48
+ * receipt wait.
49
+ */
50
+ /** How long a successful `/supported` marker check is trusted, seconds. */
51
+ export declare const DEFAULT_FACILITATOR_MARKER_TTL_SECONDS = 300;
52
+ /** Default per-request facilitator HTTP timeout. Must outlast its receipt wait. */
53
+ export declare const DEFAULT_FACILITATOR_TIMEOUT_MS = 120000;
54
+ export interface GatewayX402OpenerModeConfig {
55
+ /** Base URL of the Metrik opener facilitator (e.g. `https://facilitator.example`). */
56
+ readonly facilitatorUrl: string;
57
+ /** Bearer token the facilitator requires on `/settle`. */
58
+ readonly facilitatorToken: string;
59
+ /** CAIP-2 network (`eip155:<chainId>`), as the registry gives it. */
60
+ readonly network: Network;
61
+ readonly factoryAddress: Address;
62
+ /** The escrow this gateway checks streams against; the factory must point at it. */
63
+ readonly escrowAddress: Address;
64
+ /** Settlement token; must equal the factory's. */
65
+ readonly asset: Address;
66
+ /** EIP-712 domain of the token (Circle USDC: `USDC` / `2`). */
67
+ readonly assetName: string;
68
+ readonly assetVersion: string;
69
+ /** Opener terms. `operator` + `serviceRef` must resolve to one operator-signed listing. */
70
+ readonly terms: OpenerTerms;
71
+ /** Price per paid request in token base units. Becomes the stream deposit. */
72
+ readonly price: bigint;
73
+ /** Authorization validity the client signs for. Default 300s. */
74
+ readonly maxTimeoutSeconds?: number;
75
+ /** Public origin clients reach this gateway at, for the 402 `resource.url`. */
76
+ readonly resourceBaseUrl?: string;
77
+ /**
78
+ * What the service does, in one sentence. Prefixed to the fixed disclosure
79
+ * of what the payment buys ({@link describeOpenerPurchase}); it can never
80
+ * replace that disclosure.
81
+ */
82
+ readonly description?: string;
83
+ /**
84
+ * Public base URL of the facilitator's refund relay (`/streams/:streamId`).
85
+ * Default `facilitatorUrl`. When different, its `/supported` must advertise
86
+ * the same opener marker with `refundRelay: true` (checked at startup).
87
+ */
88
+ readonly refundBaseUrl?: string;
89
+ /** Docs link carried in the 402. Default {@link DEFAULT_OPENER_DOCS_URL}. */
90
+ readonly docsUrl?: string;
91
+ /** Token decimals for the human-readable amounts in the description. Default 6 (USDC). */
92
+ readonly assetDecimals?: number;
93
+ /**
94
+ * Optional input/output schema, declared in the 402 as
95
+ * `extensions.bazaar` (`{info: {input, output}, schema}`). Declared only;
96
+ * never registered with any discovery catalog.
97
+ */
98
+ readonly schemaDeclaration?: X402SchemaDeclaration;
99
+ /** Registry used to prove the listing at startup. Default the public registry. */
100
+ readonly registryUrl?: string;
101
+ readonly markerTtlSeconds?: number;
102
+ /**
103
+ * Per-request facilitator HTTP timeout, ms. Default
104
+ * {@link DEFAULT_FACILITATOR_TIMEOUT_MS}. Must exceed the facilitator's
105
+ * advertised receipt timeout by 30 s, so the gateway never gives up on a
106
+ * settlement the facilitator is still waiting for.
107
+ */
108
+ readonly facilitatorTimeoutMs?: number;
109
+ }
110
+ /**
111
+ * The plain statement of what one payment buys, used as the 402 resource
112
+ * `description`. It names the window, the rate, that the seller earns only for
113
+ * seconds Metrik's verifier confirms, and where unearned money is refundable
114
+ * without ETH. It says that refunds are not automatic, because they are not:
115
+ * someone has to call the refund relay.
116
+ */
117
+ export declare function describeOpenerPurchase(input: {
118
+ readonly terms: OpenerTerms;
119
+ readonly price: bigint;
120
+ readonly assetDecimals: number;
121
+ readonly assetSymbol: string;
122
+ /** Refund URL template containing `{streamId}`. */
123
+ readonly refundUrlTemplate: string;
124
+ readonly docsUrl: string;
125
+ readonly serviceDescription?: string;
126
+ }): string;
127
+ export interface GatewayX402OpenerModeDeps {
128
+ /** Read client for the factory. Default built from `rpcUrl`. */
129
+ readonly publicClient?: PublicClient;
130
+ readonly rpcUrl?: string;
131
+ readonly listingResolver?: OperatorSignedListingResolver;
132
+ /** Override the facilitator transport (tests). Default {@link HTTPFacilitatorClient}. */
133
+ readonly facilitatorClient?: FacilitatorClient;
134
+ readonly now?: () => number;
135
+ /** HTTP client for checking a separate `refundBaseUrl`. Default global fetch. */
136
+ readonly fetch?: typeof fetch;
137
+ }
138
+ export interface GatewayX402OpenerMode {
139
+ /** The predicted opener address quoted as `payTo`. */
140
+ readonly payTo: Address;
141
+ readonly network: Network;
142
+ readonly terms: OpenerTerms;
143
+ readonly price: bigint;
144
+ readonly resourceBaseUrl: string | undefined;
145
+ /** The 402 `description` (what the payment buys). */
146
+ readonly description: string;
147
+ /** Refund relay base; a stream's refund page is `${refundBaseUrl}/streams/:streamId`. */
148
+ readonly refundBaseUrl: string;
149
+ readonly httpServer: x402HTTPResourceServer;
150
+ /** One-use accounting of authorizations this gateway has seen. */
151
+ readonly authorizations: GatewayAuthorizationLedger;
152
+ /**
153
+ * Resolves once the facilitator is proven to be the Metrik opener
154
+ * facilitator for this factory (cached for the marker TTL) and the resource
155
+ * server is initialized. Rejects otherwise — callers must fail closed.
156
+ */
157
+ ready(): Promise<void>;
158
+ /** Serves one x402-mode request over the supplied transport. Never throws. */
159
+ handle(io: X402GatewayRequestIO): Promise<void>;
160
+ }
161
+ /** JSON reasons the x402 path can answer with, beyond the gateway's own. */
162
+ export type X402GatewayResponseReason = "x402-facilitator-unavailable" | "x402-settlement-failed" | "internal-error" | "upstream-unavailable" | "x402-payment-already-used";
163
+ export interface X402UpstreamResult {
164
+ readonly status: number;
165
+ readonly headers: Record<string, string>;
166
+ readonly body: Buffer;
167
+ }
168
+ /** The transport the HTTP server hands the x402 path. */
169
+ export interface X402GatewayRequestIO {
170
+ readonly requestUrl: URL;
171
+ readonly method: string;
172
+ /** Lower-cased request headers. */
173
+ readonly headers: Readonly<Record<string, string | undefined>>;
174
+ /** Proxies the request upstream (payment headers stripped) and buffers the response. */
175
+ callUpstream(): Promise<X402UpstreamResult>;
176
+ writeJson(status: number, reason: X402GatewayResponseReason): void;
177
+ write(status: number, headers: Record<string, string>, body: Buffer | string): void;
178
+ logError(context: string, error: unknown): void;
179
+ }
180
+ /**
181
+ * Per-gateway, in-memory record of EIP-3009 authorizations (chain + asset +
182
+ * payer + nonce): `in-flight` while a request is being verified/served/
183
+ * settled, `pending` after a `settlement_pending` (a retry may reconcile), and
184
+ * `settled` once a success was delivered. In-flight and settled
185
+ * authorizations are refused before the upstream is ever called. Entries are
186
+ * dropped once the authorization's `validBefore` has passed (plus a grace).
187
+ */
188
+ export declare class GatewayAuthorizationLedger {
189
+ private readonly now;
190
+ private readonly maxEntries;
191
+ private readonly entries;
192
+ constructor(now: () => number, maxEntries?: number);
193
+ /** Claims the authorization for one request; false if it is in flight or settled. */
194
+ claim(key: string, validBefore: bigint): boolean;
195
+ release(key: string): void;
196
+ markPending(key: string, validBefore: bigint): void;
197
+ markSettled(key: string, validBefore: bigint): void;
198
+ private prune;
199
+ }
200
+ export declare class X402OpenerModeConfigError extends Error {
201
+ constructor(message: string);
202
+ }
203
+ export declare class X402OpenerFacilitatorUnverifiedError extends Error {
204
+ constructor(message: string, options?: {
205
+ readonly cause?: unknown;
206
+ });
207
+ }
208
+ /**
209
+ * Builds the x402 mode and proves, before returning, every fact it will quote:
210
+ * valid terms and price, one operator-signed listing for the terms, the
211
+ * factory's escrow and token, the predicted `payTo`, and the facilitator's
212
+ * opener marker. Throws on any doubt; the gateway then refuses to start.
213
+ */
214
+ export declare function buildGatewayX402OpenerMode(config: GatewayX402OpenerModeConfig, deps?: GatewayX402OpenerModeDeps): Promise<GatewayX402OpenerMode>;
215
+ //# sourceMappingURL=x402-opener-mode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"x402-opener-mode.d.ts","sourceRoot":"","sources":["../../src/gateway/x402-opener-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,sBAAsB,EAEtB,KAAK,iBAAiB,EAQvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAML,KAAK,OAAO,EACZ,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAGd,OAAO,EAEL,KAAK,6BAA6B,EACnC,M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