@lunora/x402 1.0.0-alpha.2 → 1.0.0-alpha.3
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 +2 -0
- package/dist/charge/index.d.mts +25 -6
- package/dist/charge/index.d.ts +25 -6
- package/dist/charge/index.mjs +3 -3
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/packem_shared/{config.d-CddwCiBm.d.mts → config.d-D8gKQLAq.d.mts} +69 -12
- package/dist/packem_shared/{config.d-CddwCiBm.d.ts → config.d-D8gKQLAq.d.ts} +69 -12
- package/dist/packem_shared/{createChargeMiddleware-BJkYJeFf.mjs → createChargeMiddleware-CARkBOyH.mjs} +2 -2
- package/dist/packem_shared/{createProcedureChargeGate-CV8ITlQP.mjs → createProcedureChargeGate-MaMhu9L9.mjs} +1 -1
- package/dist/packem_shared/{withX402-rUq0voT8.mjs → withX402-SOW47gf3.mjs} +1 -1
- package/dist/pay/index.d.mts +24 -6
- package/dist/pay/index.d.ts +24 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @lunora/x402
|
|
2
2
|
|
|
3
|
+
> **Experimental** — this package is outside the Lunora 1.0 stability promise: its API may change in any release, without a major version bump.
|
|
4
|
+
|
|
3
5
|
> Agentic payments over the [x402](https://x402.org) protocol for [Lunora](https://lunora.sh).
|
|
4
6
|
|
|
5
7
|
x402 turns HTTP `402 Payment Required` into a machine-payable rail: no accounts,
|
package/dist/charge/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FacilitatorConfig, c as X402ChargeConfig, f as X402Price } from "../packem_shared/config.d-
|
|
2
|
-
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, type a as EvmAddress, type P as PaymentEventRow, type d as X402Network, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, x as toPaymentEventRow, y as toReceipt } from "../packem_shared/config.d-
|
|
1
|
+
import { F as FacilitatorConfig, c as X402ChargeConfig, f as X402Price } from "../packem_shared/config.d-D8gKQLAq.mjs";
|
|
2
|
+
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, type a as EvmAddress, type P as PaymentEventRow, type d as X402Network, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, x as toPaymentEventRow, y as toReceipt } from "../packem_shared/config.d-D8gKQLAq.mjs";
|
|
3
3
|
import { HTTPFacilitatorClient } from '@x402/core/server';
|
|
4
4
|
import { RouteConfig } from '@x402/core/http';
|
|
5
5
|
import '@x402/evm';
|
|
@@ -14,18 +14,29 @@ import '@x402/core/types';
|
|
|
14
14
|
* `supported`), so the same header map is handed to each. With no config the
|
|
15
15
|
* client points at the public {@link resolveFacilitatorUrl default} and sends no
|
|
16
16
|
* auth headers.
|
|
17
|
+
* @experimental
|
|
17
18
|
*/
|
|
18
19
|
declare const createFacilitatorClient: (config?: FacilitatorConfig) => HTTPFacilitatorClient;
|
|
19
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* A handler shaped like a Lunora HTTP action: `(context, request) => Response`.
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
20
24
|
type HttpActionHandler<Context> = (context: Context, request: Request) => Promise<Response> | Response;
|
|
21
25
|
/**
|
|
22
26
|
* Gate `handler` behind an x402 paywall described by `config`. Returns a handler
|
|
23
27
|
* of the same shape, ready to pass to `httpAction`.
|
|
28
|
+
* @experimental
|
|
24
29
|
*/
|
|
25
30
|
declare const withX402: <Context>(config: X402ChargeConfig, handler: HttpActionHandler<Context>) => HttpActionHandler<Context>;
|
|
26
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Runs the protected resource handler, producing the Response to gate.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
27
35
|
type ChargeHandler = () => Promise<Response> | Response;
|
|
28
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* A prepared, initialised paywall. Build once (it fetches facilitator support), reuse per request.
|
|
38
|
+
* @experimental
|
|
39
|
+
*/
|
|
29
40
|
interface ChargeMiddleware {
|
|
30
41
|
/** Gate `request`: challenge / verify / settle around `runHandler`. */
|
|
31
42
|
handle: (request: Request, runHandler: ChargeHandler) => Promise<Response>;
|
|
@@ -36,6 +47,7 @@ interface ChargeMiddleware {
|
|
|
36
47
|
* names the paid function (x402 core falls back to the request URL otherwise —
|
|
37
48
|
* every RPC POSTs to the same `/_lunora/rpc`, so the URL can't tell two paid
|
|
38
49
|
* procedures apart).
|
|
50
|
+
* @experimental
|
|
39
51
|
*/
|
|
40
52
|
type ChargeRouteOverrides = Pick<RouteConfig, "description" | "resource">;
|
|
41
53
|
/**
|
|
@@ -43,15 +55,20 @@ type ChargeRouteOverrides = Pick<RouteConfig, "description" | "resource">;
|
|
|
43
55
|
* facilitator support once (via `initialize()`), so call this once per config
|
|
44
56
|
* and reuse the result across requests. `routeOverrides` layers extra route
|
|
45
57
|
* metadata (e.g. `resource`) onto the generated catch-all route.
|
|
58
|
+
* @experimental
|
|
46
59
|
*/
|
|
47
60
|
declare const createChargeMiddleware: (config: X402ChargeConfig, routeOverrides?: ChargeRouteOverrides) => Promise<ChargeMiddleware>;
|
|
48
61
|
/**
|
|
49
62
|
* Charge config for the procedure gate: the worker-level settlement vocabulary
|
|
50
63
|
* (network, recipient, facilitator) minus `price` — price is per-procedure and
|
|
51
64
|
* arrives with each {@link X402ProcedureSpec}.
|
|
65
|
+
* @experimental
|
|
52
66
|
*/
|
|
53
67
|
type X402ProcedureChargeConfig = Omit<X402ChargeConfig, "price">;
|
|
54
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* The per-RPC charge spec the runtime passes the gate for each paid dispatch.
|
|
70
|
+
* @experimental
|
|
71
|
+
*/
|
|
55
72
|
interface X402ProcedureSpec {
|
|
56
73
|
/** The `file:function` id of the paid procedure; becomes the x402 challenge `resource`. */
|
|
57
74
|
readonly functionPath: string;
|
|
@@ -63,6 +80,7 @@ interface X402ProcedureSpec {
|
|
|
63
80
|
* request is unpaid, or the dispatched response (with `X-PAYMENT-RESPONSE`
|
|
64
81
|
* attached) once the client's `X-PAYMENT` is verified and settled. `dispatch`
|
|
65
82
|
* runs the actual shard forward — it is only invoked after payment is verified.
|
|
83
|
+
* @experimental
|
|
66
84
|
*/
|
|
67
85
|
type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispatch: () => Promise<Response>) => Promise<Response>;
|
|
68
86
|
/**
|
|
@@ -71,6 +89,7 @@ type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispa
|
|
|
71
89
|
* function's price + `resource`), since `createChargeMiddleware` fetches
|
|
72
90
|
* facilitator support on first use. A failed init is not cached, so a transient
|
|
73
91
|
* facilitator outage retries on the next request.
|
|
92
|
+
* @experimental
|
|
74
93
|
*/
|
|
75
94
|
declare const createProcedureChargeGate: (config: X402ProcedureChargeConfig) => X402ProcedureChargeGate;
|
|
76
95
|
export { type ChargeHandler, type ChargeMiddleware, type ChargeRouteOverrides, type FacilitatorConfig, type HttpActionHandler, type X402ChargeConfig, type X402Price, type X402ProcedureChargeConfig, type X402ProcedureChargeGate, type X402ProcedureSpec, createChargeMiddleware, createFacilitatorClient, createProcedureChargeGate, withX402 };
|
package/dist/charge/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { F as FacilitatorConfig, c as X402ChargeConfig, f as X402Price } from "../packem_shared/config.d-
|
|
2
|
-
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, type a as EvmAddress, type P as PaymentEventRow, type d as X402Network, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, x as toPaymentEventRow, y as toReceipt } from "../packem_shared/config.d-
|
|
1
|
+
import { F as FacilitatorConfig, c as X402ChargeConfig, f as X402Price } from "../packem_shared/config.d-D8gKQLAq.js";
|
|
2
|
+
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, type a as EvmAddress, type P as PaymentEventRow, type d as X402Network, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, x as toPaymentEventRow, y as toReceipt } from "../packem_shared/config.d-D8gKQLAq.js";
|
|
3
3
|
import { HTTPFacilitatorClient } from '@x402/core/server';
|
|
4
4
|
import { RouteConfig } from '@x402/core/http';
|
|
5
5
|
import '@x402/evm';
|
|
@@ -14,18 +14,29 @@ import '@x402/core/types';
|
|
|
14
14
|
* `supported`), so the same header map is handed to each. With no config the
|
|
15
15
|
* client points at the public {@link resolveFacilitatorUrl default} and sends no
|
|
16
16
|
* auth headers.
|
|
17
|
+
* @experimental
|
|
17
18
|
*/
|
|
18
19
|
declare const createFacilitatorClient: (config?: FacilitatorConfig) => HTTPFacilitatorClient;
|
|
19
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* A handler shaped like a Lunora HTTP action: `(context, request) => Response`.
|
|
22
|
+
* @experimental
|
|
23
|
+
*/
|
|
20
24
|
type HttpActionHandler<Context> = (context: Context, request: Request) => Promise<Response> | Response;
|
|
21
25
|
/**
|
|
22
26
|
* Gate `handler` behind an x402 paywall described by `config`. Returns a handler
|
|
23
27
|
* of the same shape, ready to pass to `httpAction`.
|
|
28
|
+
* @experimental
|
|
24
29
|
*/
|
|
25
30
|
declare const withX402: <Context>(config: X402ChargeConfig, handler: HttpActionHandler<Context>) => HttpActionHandler<Context>;
|
|
26
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Runs the protected resource handler, producing the Response to gate.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
27
35
|
type ChargeHandler = () => Promise<Response> | Response;
|
|
28
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* A prepared, initialised paywall. Build once (it fetches facilitator support), reuse per request.
|
|
38
|
+
* @experimental
|
|
39
|
+
*/
|
|
29
40
|
interface ChargeMiddleware {
|
|
30
41
|
/** Gate `request`: challenge / verify / settle around `runHandler`. */
|
|
31
42
|
handle: (request: Request, runHandler: ChargeHandler) => Promise<Response>;
|
|
@@ -36,6 +47,7 @@ interface ChargeMiddleware {
|
|
|
36
47
|
* names the paid function (x402 core falls back to the request URL otherwise —
|
|
37
48
|
* every RPC POSTs to the same `/_lunora/rpc`, so the URL can't tell two paid
|
|
38
49
|
* procedures apart).
|
|
50
|
+
* @experimental
|
|
39
51
|
*/
|
|
40
52
|
type ChargeRouteOverrides = Pick<RouteConfig, "description" | "resource">;
|
|
41
53
|
/**
|
|
@@ -43,15 +55,20 @@ type ChargeRouteOverrides = Pick<RouteConfig, "description" | "resource">;
|
|
|
43
55
|
* facilitator support once (via `initialize()`), so call this once per config
|
|
44
56
|
* and reuse the result across requests. `routeOverrides` layers extra route
|
|
45
57
|
* metadata (e.g. `resource`) onto the generated catch-all route.
|
|
58
|
+
* @experimental
|
|
46
59
|
*/
|
|
47
60
|
declare const createChargeMiddleware: (config: X402ChargeConfig, routeOverrides?: ChargeRouteOverrides) => Promise<ChargeMiddleware>;
|
|
48
61
|
/**
|
|
49
62
|
* Charge config for the procedure gate: the worker-level settlement vocabulary
|
|
50
63
|
* (network, recipient, facilitator) minus `price` — price is per-procedure and
|
|
51
64
|
* arrives with each {@link X402ProcedureSpec}.
|
|
65
|
+
* @experimental
|
|
52
66
|
*/
|
|
53
67
|
type X402ProcedureChargeConfig = Omit<X402ChargeConfig, "price">;
|
|
54
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* The per-RPC charge spec the runtime passes the gate for each paid dispatch.
|
|
70
|
+
* @experimental
|
|
71
|
+
*/
|
|
55
72
|
interface X402ProcedureSpec {
|
|
56
73
|
/** The `file:function` id of the paid procedure; becomes the x402 challenge `resource`. */
|
|
57
74
|
readonly functionPath: string;
|
|
@@ -63,6 +80,7 @@ interface X402ProcedureSpec {
|
|
|
63
80
|
* request is unpaid, or the dispatched response (with `X-PAYMENT-RESPONSE`
|
|
64
81
|
* attached) once the client's `X-PAYMENT` is verified and settled. `dispatch`
|
|
65
82
|
* runs the actual shard forward — it is only invoked after payment is verified.
|
|
83
|
+
* @experimental
|
|
66
84
|
*/
|
|
67
85
|
type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispatch: () => Promise<Response>) => Promise<Response>;
|
|
68
86
|
/**
|
|
@@ -71,6 +89,7 @@ type X402ProcedureChargeGate = (request: Request, spec: X402ProcedureSpec, dispa
|
|
|
71
89
|
* function's price + `resource`), since `createChargeMiddleware` fetches
|
|
72
90
|
* facilitator support on first use. A failed init is not cached, so a transient
|
|
73
91
|
* facilitator outage retries on the next request.
|
|
92
|
+
* @experimental
|
|
74
93
|
*/
|
|
75
94
|
declare const createProcedureChargeGate: (config: X402ProcedureChargeConfig) => X402ProcedureChargeGate;
|
|
76
95
|
export { type ChargeHandler, type ChargeMiddleware, type ChargeRouteOverrides, type FacilitatorConfig, type HttpActionHandler, type X402ChargeConfig, type X402Price, type X402ProcedureChargeConfig, type X402ProcedureChargeGate, type X402ProcedureSpec, createChargeMiddleware, createFacilitatorClient, createProcedureChargeGate, withX402 };
|
package/dist/charge/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { DEFAULT_FACILITATOR_URL, resolveFacilitatorUrl } from '../packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs';
|
|
2
2
|
export { createFacilitatorClient } from '../packem_shared/createFacilitatorClient-rXHBnCZm.mjs';
|
|
3
3
|
export { isEvmNetwork, isSvmNetwork, toCaip2 } from '../packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs';
|
|
4
|
-
export { withX402 } from '../packem_shared/withX402-
|
|
5
|
-
export { createChargeMiddleware } from '../packem_shared/createChargeMiddleware-
|
|
6
|
-
export { createProcedureChargeGate } from '../packem_shared/createProcedureChargeGate-
|
|
4
|
+
export { withX402 } from '../packem_shared/withX402-SOW47gf3.mjs';
|
|
5
|
+
export { createChargeMiddleware } from '../packem_shared/createChargeMiddleware-CARkBOyH.mjs';
|
|
6
|
+
export { createProcedureChargeGate } from '../packem_shared/createProcedureChargeGate-MaMhu9L9.mjs';
|
|
7
7
|
export { toPaymentEventRow, toReceipt } from '../packem_shared/toPaymentEventRow-DW4O9N7Y.mjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, E as EVM_NETWORKS, type a as EvmAddress, type F as FacilitatorConfig, type b as FriendlyNetwork, N as NETWORK_TO_CAIP2, S as SVM_NETWORKS, type X as X402CdpSignerConfig, type c as X402ChargeConfig, type d as X402Network, type e as X402PayConfig, type f as X402Price, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, type j as X402SignerConfig, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/config.d-
|
|
1
|
+
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, E as EVM_NETWORKS, type a as EvmAddress, type F as FacilitatorConfig, type b as FriendlyNetwork, N as NETWORK_TO_CAIP2, S as SVM_NETWORKS, type X as X402CdpSignerConfig, type c as X402ChargeConfig, type d as X402Network, type e as X402PayConfig, type f as X402Price, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, type j as X402SignerConfig, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/config.d-D8gKQLAq.mjs";
|
|
2
2
|
import '@x402/evm';
|
|
3
3
|
import '@x402/svm';
|
|
4
4
|
import '@x402/core/http';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, E as EVM_NETWORKS, type a as EvmAddress, type F as FacilitatorConfig, type b as FriendlyNetwork, N as NETWORK_TO_CAIP2, S as SVM_NETWORKS, type X as X402CdpSignerConfig, type c as X402ChargeConfig, type d as X402Network, type e as X402PayConfig, type f as X402Price, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, type j as X402SignerConfig, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/config.d-
|
|
1
|
+
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, E as EVM_NETWORKS, type a as EvmAddress, type F as FacilitatorConfig, type b as FriendlyNetwork, N as NETWORK_TO_CAIP2, S as SVM_NETWORKS, type X as X402CdpSignerConfig, type c as X402ChargeConfig, type d as X402Network, type e as X402PayConfig, type f as X402Price, type g as X402Receipt, type h as X402ReceiptSink, type i as X402Recipient, type j as X402SignerConfig, k as isEvmNetwork, l as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2 } from "./packem_shared/config.d-D8gKQLAq.js";
|
|
2
2
|
import '@x402/evm';
|
|
3
3
|
import '@x402/svm';
|
|
4
4
|
import '@x402/core/http';
|
|
@@ -8,6 +8,7 @@ import { PaymentRequirements } from '@x402/core/types';
|
|
|
8
8
|
* as its exact on-chain atomic-unit string (USDC has 6 decimals) — never coerced
|
|
9
9
|
* to a fractional-dollar number — so no precision is lost crossing the reporting
|
|
10
10
|
* seam.
|
|
11
|
+
* @experimental
|
|
11
12
|
*/
|
|
12
13
|
interface X402Receipt {
|
|
13
14
|
/** Settled amount in the asset's atomic base units (USDC: 6 decimals), as an exact string. */
|
|
@@ -33,6 +34,7 @@ interface X402Receipt {
|
|
|
33
34
|
* settlement, does not block the paid response on it, and swallows any error it
|
|
34
35
|
* throws — so a sink must never rely on being awaited or on its failures
|
|
35
36
|
* surfacing.
|
|
37
|
+
* @experimental
|
|
36
38
|
*/
|
|
37
39
|
type X402ReceiptSink = (receipt: X402Receipt) => Promise<void> | void;
|
|
38
40
|
/**
|
|
@@ -41,6 +43,7 @@ type X402ReceiptSink = (receipt: X402Receipt) => Promise<void> | void;
|
|
|
41
43
|
* the settlement result carries neither. Prefers the actual settled `amount`
|
|
42
44
|
* (present for `upto`-scheme partial settlements) and falls back to the route's
|
|
43
45
|
* required amount for `exact`.
|
|
46
|
+
* @experimental
|
|
44
47
|
*/
|
|
45
48
|
declare const toReceipt: (settlement: ProcessSettleSuccessResponse, context: {
|
|
46
49
|
readonly resource: string;
|
|
@@ -50,6 +53,7 @@ declare const toReceipt: (settlement: ProcessSettleSuccessResponse, context: {
|
|
|
50
53
|
* A row for `@lunora/payment`'s durable `events` table. Deliberately a plain
|
|
51
54
|
* structural type — building one imports nothing from `@lunora/payment`, so the
|
|
52
55
|
* rails stay decoupled.
|
|
56
|
+
* @experimental
|
|
53
57
|
*/
|
|
54
58
|
interface PaymentEventRow {
|
|
55
59
|
/** Epoch milliseconds the settlement was recorded. */
|
|
@@ -77,6 +81,7 @@ interface PaymentEventRow {
|
|
|
77
81
|
* table (`packages/payment/src/schema.ts`). Amount / from / to / resource are
|
|
78
82
|
* intentionally not on this row — that card renders none of them; read them off
|
|
79
83
|
* the {@link X402Receipt} (e.g. into your own revenue table) if you need them.
|
|
84
|
+
* @experimental
|
|
80
85
|
*/
|
|
81
86
|
declare const toPaymentEventRow: (receipt: X402Receipt) => PaymentEventRow;
|
|
82
87
|
/**
|
|
@@ -96,19 +101,27 @@ declare const toPaymentEventRow: (receipt: X402Receipt) => PaymentEventRow;
|
|
|
96
101
|
* friendly aliases; a caller who needs them can still pass a raw CAIP-2 id with an
|
|
97
102
|
* explicit asset.
|
|
98
103
|
*/
|
|
99
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* A CAIP-2 chain identifier, e.g. `"eip155:8453"` (Base) or `"solana:5eyk…"`.
|
|
106
|
+
* @experimental
|
|
107
|
+
*/
|
|
100
108
|
type Caip2 = `${string}:${string}`;
|
|
101
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Friendly network names Lunora maps to CAIP-2 for `@x402/core`.
|
|
111
|
+
* @experimental
|
|
112
|
+
*/
|
|
102
113
|
type FriendlyNetwork = "arbitrum" | "arbitrum-sepolia" | "base" | "base-sepolia" | "ethereum" | "polygon" | "solana" | "solana-devnet";
|
|
103
114
|
/**
|
|
104
115
|
* A network Lunora can settle on: a {@link FriendlyNetwork} alias (mapped to
|
|
105
116
|
* CAIP-2 internally) or a raw {@link Caip2} id for chains without a friendly name.
|
|
117
|
+
* @experimental
|
|
106
118
|
*/
|
|
107
119
|
type X402Network = Caip2 | FriendlyNetwork;
|
|
108
120
|
/**
|
|
109
121
|
* Friendly name → CAIP-2 id. Values verified against `@x402/evm` and `@x402/svm`
|
|
110
122
|
* `DEFAULT_STABLECOINS` at 2.17.0. `base` / `base-sepolia` are the primary
|
|
111
123
|
* prod / test pair.
|
|
124
|
+
* @experimental
|
|
112
125
|
*/
|
|
113
126
|
declare const NETWORK_TO_CAIP2: {
|
|
114
127
|
readonly arbitrum: "eip155:42161";
|
|
@@ -120,23 +133,37 @@ declare const NETWORK_TO_CAIP2: {
|
|
|
120
133
|
readonly solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
121
134
|
readonly "solana-devnet": "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
122
135
|
};
|
|
123
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* EVM friendly networks (signed via `@x402/evm` + viem).
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
124
140
|
declare const EVM_NETWORKS: readonly ["arbitrum", "arbitrum-sepolia", "base", "base-sepolia", "ethereum", "polygon"];
|
|
125
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Solana friendly networks (signed via `@x402/svm`).
|
|
143
|
+
* @experimental
|
|
144
|
+
*/
|
|
126
145
|
declare const SVM_NETWORKS: readonly ["solana", "solana-devnet"];
|
|
127
146
|
/**
|
|
128
147
|
* Resolve a network to its CAIP-2 id. Friendly aliases are looked up; a value
|
|
129
148
|
* that already looks like CAIP-2 (`namespace:reference`) passes through.
|
|
149
|
+
* @experimental
|
|
130
150
|
*/
|
|
131
151
|
declare const toCaip2: (network: X402Network) => Caip2;
|
|
132
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* True when `network` settles on an EVM chain (viem signer path).
|
|
154
|
+
* @experimental
|
|
155
|
+
*/
|
|
133
156
|
declare const isEvmNetwork: (network: X402Network) => boolean;
|
|
134
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* True when `network` settles on Solana (`@x402/svm` signer path).
|
|
159
|
+
* @experimental
|
|
160
|
+
*/
|
|
135
161
|
declare const isSvmNetwork: (network: X402Network) => boolean;
|
|
136
162
|
/**
|
|
137
163
|
* USDC — and every asset in `@x402/evm` / `@x402/svm`'s `DEFAULT_STABLECOINS` —
|
|
138
164
|
* uses 6 decimals, so a USD price converts to atomic base units at `10 ** 6`.
|
|
139
165
|
* Override per {@link SpendPolicy.decimals} only for a custom, non-6-decimal asset.
|
|
166
|
+
* @experimental
|
|
140
167
|
*/
|
|
141
168
|
declare const DEFAULT_STABLECOIN_DECIMALS = 6;
|
|
142
169
|
/**
|
|
@@ -145,6 +172,7 @@ declare const DEFAULT_STABLECOIN_DECIMALS = 6;
|
|
|
145
172
|
*
|
|
146
173
|
* Caps are denominated in USD (the stablecoin's dollar value); addresses and
|
|
147
174
|
* networks are matched against the requirement the server offers.
|
|
175
|
+
* @experimental
|
|
148
176
|
*/
|
|
149
177
|
interface SpendPolicy {
|
|
150
178
|
/** Network allowlist. When set, only these networks may be paid on. */
|
|
@@ -164,51 +192,66 @@ interface SpendPolicy {
|
|
|
164
192
|
*/
|
|
165
193
|
readonly onPaymentRequired?: (requirement: PaymentRequirements) => Promise<boolean> | boolean;
|
|
166
194
|
}
|
|
167
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* A running spend ledger the per-run cap is measured against; the guard reads it, the recorder adds to it.
|
|
197
|
+
* @experimental
|
|
198
|
+
*/
|
|
168
199
|
interface SpendState {
|
|
169
200
|
/** Add a just-committed payment (atomic base units) to the total. */
|
|
170
201
|
readonly add: (amount: bigint) => void;
|
|
171
202
|
/** Cumulative spend so far, in atomic base units. */
|
|
172
203
|
readonly spentAtomic: bigint;
|
|
173
204
|
}
|
|
174
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* A fresh spend ledger. One per wallet instance; the guard + recorder share it.
|
|
207
|
+
* @experimental
|
|
208
|
+
*/
|
|
175
209
|
declare const createSpendState: () => SpendState;
|
|
176
210
|
/**
|
|
177
211
|
* Convert a USD amount (`0.01`, `"0.01"`, or the `"$0.01"` shorthand) to atomic
|
|
178
212
|
* stablecoin base units, exactly — parsed digit-by-digit so no binary-float drift
|
|
179
213
|
* can round a cap the wrong way. Throws on a malformed amount (including
|
|
180
214
|
* exponential notation like `"1e-7"`, which a decimal string never needs).
|
|
215
|
+
* @experimental
|
|
181
216
|
*/
|
|
182
217
|
declare const usdToAtomic: (usd: X402Price, decimals?: number) => bigint;
|
|
183
218
|
/**
|
|
184
219
|
* A `PaymentPolicy` that narrows the server's offered requirements to those a
|
|
185
220
|
* bounded wallet may pay: within the per-call cap, to an allowed recipient, on an
|
|
186
221
|
* allowed network. An empty result means the client cannot pay — fail-closed.
|
|
222
|
+
* @experimental
|
|
187
223
|
*/
|
|
188
224
|
declare const buildSpendPolicy: (policy: SpendPolicy) => PaymentPolicy;
|
|
189
225
|
/**
|
|
190
226
|
* A `BeforePaymentCreationHook` enforcing the stateful bounds the stateless
|
|
191
227
|
* {@link buildSpendPolicy} filter can't: the cumulative per-run cap and the async
|
|
192
228
|
* confirmation gate. Aborts (no signature) when either would be violated.
|
|
229
|
+
* @experimental
|
|
193
230
|
*/
|
|
194
231
|
declare const buildPaymentGuard: (policy: SpendPolicy, state: SpendState) => BeforePaymentCreationHook;
|
|
195
232
|
/**
|
|
196
233
|
* An `AfterPaymentCreationHook` that adds the just-created payment to `state`, so
|
|
197
234
|
* the next {@link buildPaymentGuard} call measures the per-run cap against it.
|
|
235
|
+
* @experimental
|
|
198
236
|
*/
|
|
199
237
|
declare const recordSpend: (state: SpendState) => AfterPaymentCreationHook;
|
|
200
238
|
/**
|
|
201
239
|
* Guard at wallet-build time: refuse a policy with no bound whatsoever. Signing
|
|
202
240
|
* money on an agent's behalf with unlimited spend authority is never the intent,
|
|
203
241
|
* so this fails loudly rather than defaulting to unbounded.
|
|
242
|
+
* @experimental
|
|
204
243
|
*/
|
|
205
244
|
declare const assertBoundedPolicy: (policy: SpendPolicy) => void;
|
|
206
245
|
/**
|
|
207
246
|
* The public, Coinbase-operated facilitator (verify + settle). It needs no API
|
|
208
247
|
* key. Override with a self-hosted or CDP facilitator via {@link FacilitatorConfig}.
|
|
248
|
+
* @experimental
|
|
209
249
|
*/
|
|
210
250
|
declare const DEFAULT_FACILITATOR_URL = "https://x402.org/facilitator";
|
|
211
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* How to reach a facilitator's `/verify` + `/settle` endpoints.
|
|
253
|
+
* @experimental
|
|
254
|
+
*/
|
|
212
255
|
interface FacilitatorConfig {
|
|
213
256
|
/** Extra headers for a private facilitator (e.g. a CDP bearer token). */
|
|
214
257
|
readonly headers?: Record<string, string>;
|
|
@@ -221,11 +264,18 @@ interface FacilitatorConfig {
|
|
|
221
264
|
* to the network's stablecoin base units (USDC has 6 decimals) at challenge
|
|
222
265
|
* time. (Kept `number | string` rather than a `` `$${string}` `` template
|
|
223
266
|
* member — the template is subsumed by `string`, so it only adds noise.)
|
|
267
|
+
* @experimental
|
|
224
268
|
*/
|
|
225
269
|
type X402Price = number | string;
|
|
226
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* An EVM recipient address (the merchant wallet that receives settlement).
|
|
272
|
+
* @experimental
|
|
273
|
+
*/
|
|
227
274
|
type EvmAddress = `0x${string}`;
|
|
228
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* Recipient wallet the facilitator settles payments to, per network family.
|
|
277
|
+
* @experimental
|
|
278
|
+
*/
|
|
229
279
|
interface X402Recipient {
|
|
230
280
|
/** EVM payout address (required for EVM networks). */
|
|
231
281
|
readonly evm?: EvmAddress;
|
|
@@ -235,6 +285,7 @@ interface X402Recipient {
|
|
|
235
285
|
/**
|
|
236
286
|
* Server-side (charge rail) config. The server needs only a **recipient
|
|
237
287
|
* address** — no private key — because the facilitator performs settlement.
|
|
288
|
+
* @experimental
|
|
238
289
|
*/
|
|
239
290
|
interface X402ChargeConfig {
|
|
240
291
|
readonly facilitator?: FacilitatorConfig;
|
|
@@ -256,6 +307,7 @@ interface X402ChargeConfig {
|
|
|
256
307
|
* Client-side (pay rail) config. The signer holds spending authority, so the
|
|
257
308
|
* pay rail is ActionCtx-only and MUST be paired with a spend `policy` — the pay
|
|
258
309
|
* rail refuses to build if the policy is unbounded.
|
|
310
|
+
* @experimental
|
|
259
311
|
*/
|
|
260
312
|
interface X402PayConfig {
|
|
261
313
|
/** Network to transact on. Determines the signer family (EVM vs SVM). */
|
|
@@ -275,6 +327,7 @@ interface X402PayConfig {
|
|
|
275
327
|
* custody is `@coinbase/cdp-sdk`.) EVM only today; for CDP on Solana, build a
|
|
276
328
|
* `@solana/kit` signer around your CDP account and pass it via the `"signer"`
|
|
277
329
|
* escape hatch.
|
|
330
|
+
* @experimental
|
|
278
331
|
*/
|
|
279
332
|
interface X402CdpSignerConfig {
|
|
280
333
|
/** CDP account name to get-or-create and sign with. */
|
|
@@ -306,6 +359,7 @@ interface X402CdpSignerConfig {
|
|
|
306
359
|
* Wired today: raw-key (EVM + SVM), the user-supplied signer (both families),
|
|
307
360
|
* and CDP-managed EVM custody. CDP on Solana is not yet wired — use the escape
|
|
308
361
|
* hatch.
|
|
362
|
+
* @experimental
|
|
309
363
|
*/
|
|
310
364
|
type X402SignerConfig = X402CdpSignerConfig | {
|
|
311
365
|
/** Name of the `ctx.secrets` entry holding the private key. */
|
|
@@ -320,6 +374,9 @@ type X402SignerConfig = X402CdpSignerConfig | {
|
|
|
320
374
|
readonly signer: ClientEvmSigner | ClientSvmSigner;
|
|
321
375
|
readonly type: "signer";
|
|
322
376
|
};
|
|
323
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* Resolve a facilitator's base URL, applying the public default.
|
|
379
|
+
* @experimental
|
|
380
|
+
*/
|
|
324
381
|
declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
|
|
325
382
|
export { Caip2 as C, DEFAULT_FACILITATOR_URL as D, EVM_NETWORKS as E, FacilitatorConfig as F, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, SVM_NETWORKS as S, X402CdpSignerConfig as X, EvmAddress as a, FriendlyNetwork as b, X402ChargeConfig as c, X402Network as d, X402PayConfig as e, X402Price as f, X402Receipt as g, X402ReceiptSink as h, X402Recipient as i, X402SignerConfig as j, isEvmNetwork as k, isSvmNetwork as l, DEFAULT_STABLECOIN_DECIMALS as m, SpendPolicy as n, SpendState as o, assertBoundedPolicy as p, buildPaymentGuard as q, resolveFacilitatorUrl as r, buildSpendPolicy as s, toCaip2 as t, createSpendState as u, recordSpend as v, usdToAtomic as w, toPaymentEventRow as x, toReceipt as y };
|
|
@@ -8,6 +8,7 @@ import { PaymentRequirements } from '@x402/core/types';
|
|
|
8
8
|
* as its exact on-chain atomic-unit string (USDC has 6 decimals) — never coerced
|
|
9
9
|
* to a fractional-dollar number — so no precision is lost crossing the reporting
|
|
10
10
|
* seam.
|
|
11
|
+
* @experimental
|
|
11
12
|
*/
|
|
12
13
|
interface X402Receipt {
|
|
13
14
|
/** Settled amount in the asset's atomic base units (USDC: 6 decimals), as an exact string. */
|
|
@@ -33,6 +34,7 @@ interface X402Receipt {
|
|
|
33
34
|
* settlement, does not block the paid response on it, and swallows any error it
|
|
34
35
|
* throws — so a sink must never rely on being awaited or on its failures
|
|
35
36
|
* surfacing.
|
|
37
|
+
* @experimental
|
|
36
38
|
*/
|
|
37
39
|
type X402ReceiptSink = (receipt: X402Receipt) => Promise<void> | void;
|
|
38
40
|
/**
|
|
@@ -41,6 +43,7 @@ type X402ReceiptSink = (receipt: X402Receipt) => Promise<void> | void;
|
|
|
41
43
|
* the settlement result carries neither. Prefers the actual settled `amount`
|
|
42
44
|
* (present for `upto`-scheme partial settlements) and falls back to the route's
|
|
43
45
|
* required amount for `exact`.
|
|
46
|
+
* @experimental
|
|
44
47
|
*/
|
|
45
48
|
declare const toReceipt: (settlement: ProcessSettleSuccessResponse, context: {
|
|
46
49
|
readonly resource: string;
|
|
@@ -50,6 +53,7 @@ declare const toReceipt: (settlement: ProcessSettleSuccessResponse, context: {
|
|
|
50
53
|
* A row for `@lunora/payment`'s durable `events` table. Deliberately a plain
|
|
51
54
|
* structural type — building one imports nothing from `@lunora/payment`, so the
|
|
52
55
|
* rails stay decoupled.
|
|
56
|
+
* @experimental
|
|
53
57
|
*/
|
|
54
58
|
interface PaymentEventRow {
|
|
55
59
|
/** Epoch milliseconds the settlement was recorded. */
|
|
@@ -77,6 +81,7 @@ interface PaymentEventRow {
|
|
|
77
81
|
* table (`packages/payment/src/schema.ts`). Amount / from / to / resource are
|
|
78
82
|
* intentionally not on this row — that card renders none of them; read them off
|
|
79
83
|
* the {@link X402Receipt} (e.g. into your own revenue table) if you need them.
|
|
84
|
+
* @experimental
|
|
80
85
|
*/
|
|
81
86
|
declare const toPaymentEventRow: (receipt: X402Receipt) => PaymentEventRow;
|
|
82
87
|
/**
|
|
@@ -96,19 +101,27 @@ declare const toPaymentEventRow: (receipt: X402Receipt) => PaymentEventRow;
|
|
|
96
101
|
* friendly aliases; a caller who needs them can still pass a raw CAIP-2 id with an
|
|
97
102
|
* explicit asset.
|
|
98
103
|
*/
|
|
99
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* A CAIP-2 chain identifier, e.g. `"eip155:8453"` (Base) or `"solana:5eyk…"`.
|
|
106
|
+
* @experimental
|
|
107
|
+
*/
|
|
100
108
|
type Caip2 = `${string}:${string}`;
|
|
101
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Friendly network names Lunora maps to CAIP-2 for `@x402/core`.
|
|
111
|
+
* @experimental
|
|
112
|
+
*/
|
|
102
113
|
type FriendlyNetwork = "arbitrum" | "arbitrum-sepolia" | "base" | "base-sepolia" | "ethereum" | "polygon" | "solana" | "solana-devnet";
|
|
103
114
|
/**
|
|
104
115
|
* A network Lunora can settle on: a {@link FriendlyNetwork} alias (mapped to
|
|
105
116
|
* CAIP-2 internally) or a raw {@link Caip2} id for chains without a friendly name.
|
|
117
|
+
* @experimental
|
|
106
118
|
*/
|
|
107
119
|
type X402Network = Caip2 | FriendlyNetwork;
|
|
108
120
|
/**
|
|
109
121
|
* Friendly name → CAIP-2 id. Values verified against `@x402/evm` and `@x402/svm`
|
|
110
122
|
* `DEFAULT_STABLECOINS` at 2.17.0. `base` / `base-sepolia` are the primary
|
|
111
123
|
* prod / test pair.
|
|
124
|
+
* @experimental
|
|
112
125
|
*/
|
|
113
126
|
declare const NETWORK_TO_CAIP2: {
|
|
114
127
|
readonly arbitrum: "eip155:42161";
|
|
@@ -120,23 +133,37 @@ declare const NETWORK_TO_CAIP2: {
|
|
|
120
133
|
readonly solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
121
134
|
readonly "solana-devnet": "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
122
135
|
};
|
|
123
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* EVM friendly networks (signed via `@x402/evm` + viem).
|
|
138
|
+
* @experimental
|
|
139
|
+
*/
|
|
124
140
|
declare const EVM_NETWORKS: readonly ["arbitrum", "arbitrum-sepolia", "base", "base-sepolia", "ethereum", "polygon"];
|
|
125
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Solana friendly networks (signed via `@x402/svm`).
|
|
143
|
+
* @experimental
|
|
144
|
+
*/
|
|
126
145
|
declare const SVM_NETWORKS: readonly ["solana", "solana-devnet"];
|
|
127
146
|
/**
|
|
128
147
|
* Resolve a network to its CAIP-2 id. Friendly aliases are looked up; a value
|
|
129
148
|
* that already looks like CAIP-2 (`namespace:reference`) passes through.
|
|
149
|
+
* @experimental
|
|
130
150
|
*/
|
|
131
151
|
declare const toCaip2: (network: X402Network) => Caip2;
|
|
132
|
-
/**
|
|
152
|
+
/**
|
|
153
|
+
* True when `network` settles on an EVM chain (viem signer path).
|
|
154
|
+
* @experimental
|
|
155
|
+
*/
|
|
133
156
|
declare const isEvmNetwork: (network: X402Network) => boolean;
|
|
134
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* True when `network` settles on Solana (`@x402/svm` signer path).
|
|
159
|
+
* @experimental
|
|
160
|
+
*/
|
|
135
161
|
declare const isSvmNetwork: (network: X402Network) => boolean;
|
|
136
162
|
/**
|
|
137
163
|
* USDC — and every asset in `@x402/evm` / `@x402/svm`'s `DEFAULT_STABLECOINS` —
|
|
138
164
|
* uses 6 decimals, so a USD price converts to atomic base units at `10 ** 6`.
|
|
139
165
|
* Override per {@link SpendPolicy.decimals} only for a custom, non-6-decimal asset.
|
|
166
|
+
* @experimental
|
|
140
167
|
*/
|
|
141
168
|
declare const DEFAULT_STABLECOIN_DECIMALS = 6;
|
|
142
169
|
/**
|
|
@@ -145,6 +172,7 @@ declare const DEFAULT_STABLECOIN_DECIMALS = 6;
|
|
|
145
172
|
*
|
|
146
173
|
* Caps are denominated in USD (the stablecoin's dollar value); addresses and
|
|
147
174
|
* networks are matched against the requirement the server offers.
|
|
175
|
+
* @experimental
|
|
148
176
|
*/
|
|
149
177
|
interface SpendPolicy {
|
|
150
178
|
/** Network allowlist. When set, only these networks may be paid on. */
|
|
@@ -164,51 +192,66 @@ interface SpendPolicy {
|
|
|
164
192
|
*/
|
|
165
193
|
readonly onPaymentRequired?: (requirement: PaymentRequirements) => Promise<boolean> | boolean;
|
|
166
194
|
}
|
|
167
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* A running spend ledger the per-run cap is measured against; the guard reads it, the recorder adds to it.
|
|
197
|
+
* @experimental
|
|
198
|
+
*/
|
|
168
199
|
interface SpendState {
|
|
169
200
|
/** Add a just-committed payment (atomic base units) to the total. */
|
|
170
201
|
readonly add: (amount: bigint) => void;
|
|
171
202
|
/** Cumulative spend so far, in atomic base units. */
|
|
172
203
|
readonly spentAtomic: bigint;
|
|
173
204
|
}
|
|
174
|
-
/**
|
|
205
|
+
/**
|
|
206
|
+
* A fresh spend ledger. One per wallet instance; the guard + recorder share it.
|
|
207
|
+
* @experimental
|
|
208
|
+
*/
|
|
175
209
|
declare const createSpendState: () => SpendState;
|
|
176
210
|
/**
|
|
177
211
|
* Convert a USD amount (`0.01`, `"0.01"`, or the `"$0.01"` shorthand) to atomic
|
|
178
212
|
* stablecoin base units, exactly — parsed digit-by-digit so no binary-float drift
|
|
179
213
|
* can round a cap the wrong way. Throws on a malformed amount (including
|
|
180
214
|
* exponential notation like `"1e-7"`, which a decimal string never needs).
|
|
215
|
+
* @experimental
|
|
181
216
|
*/
|
|
182
217
|
declare const usdToAtomic: (usd: X402Price, decimals?: number) => bigint;
|
|
183
218
|
/**
|
|
184
219
|
* A `PaymentPolicy` that narrows the server's offered requirements to those a
|
|
185
220
|
* bounded wallet may pay: within the per-call cap, to an allowed recipient, on an
|
|
186
221
|
* allowed network. An empty result means the client cannot pay — fail-closed.
|
|
222
|
+
* @experimental
|
|
187
223
|
*/
|
|
188
224
|
declare const buildSpendPolicy: (policy: SpendPolicy) => PaymentPolicy;
|
|
189
225
|
/**
|
|
190
226
|
* A `BeforePaymentCreationHook` enforcing the stateful bounds the stateless
|
|
191
227
|
* {@link buildSpendPolicy} filter can't: the cumulative per-run cap and the async
|
|
192
228
|
* confirmation gate. Aborts (no signature) when either would be violated.
|
|
229
|
+
* @experimental
|
|
193
230
|
*/
|
|
194
231
|
declare const buildPaymentGuard: (policy: SpendPolicy, state: SpendState) => BeforePaymentCreationHook;
|
|
195
232
|
/**
|
|
196
233
|
* An `AfterPaymentCreationHook` that adds the just-created payment to `state`, so
|
|
197
234
|
* the next {@link buildPaymentGuard} call measures the per-run cap against it.
|
|
235
|
+
* @experimental
|
|
198
236
|
*/
|
|
199
237
|
declare const recordSpend: (state: SpendState) => AfterPaymentCreationHook;
|
|
200
238
|
/**
|
|
201
239
|
* Guard at wallet-build time: refuse a policy with no bound whatsoever. Signing
|
|
202
240
|
* money on an agent's behalf with unlimited spend authority is never the intent,
|
|
203
241
|
* so this fails loudly rather than defaulting to unbounded.
|
|
242
|
+
* @experimental
|
|
204
243
|
*/
|
|
205
244
|
declare const assertBoundedPolicy: (policy: SpendPolicy) => void;
|
|
206
245
|
/**
|
|
207
246
|
* The public, Coinbase-operated facilitator (verify + settle). It needs no API
|
|
208
247
|
* key. Override with a self-hosted or CDP facilitator via {@link FacilitatorConfig}.
|
|
248
|
+
* @experimental
|
|
209
249
|
*/
|
|
210
250
|
declare const DEFAULT_FACILITATOR_URL = "https://x402.org/facilitator";
|
|
211
|
-
/**
|
|
251
|
+
/**
|
|
252
|
+
* How to reach a facilitator's `/verify` + `/settle` endpoints.
|
|
253
|
+
* @experimental
|
|
254
|
+
*/
|
|
212
255
|
interface FacilitatorConfig {
|
|
213
256
|
/** Extra headers for a private facilitator (e.g. a CDP bearer token). */
|
|
214
257
|
readonly headers?: Record<string, string>;
|
|
@@ -221,11 +264,18 @@ interface FacilitatorConfig {
|
|
|
221
264
|
* to the network's stablecoin base units (USDC has 6 decimals) at challenge
|
|
222
265
|
* time. (Kept `number | string` rather than a `` `$${string}` `` template
|
|
223
266
|
* member — the template is subsumed by `string`, so it only adds noise.)
|
|
267
|
+
* @experimental
|
|
224
268
|
*/
|
|
225
269
|
type X402Price = number | string;
|
|
226
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* An EVM recipient address (the merchant wallet that receives settlement).
|
|
272
|
+
* @experimental
|
|
273
|
+
*/
|
|
227
274
|
type EvmAddress = `0x${string}`;
|
|
228
|
-
/**
|
|
275
|
+
/**
|
|
276
|
+
* Recipient wallet the facilitator settles payments to, per network family.
|
|
277
|
+
* @experimental
|
|
278
|
+
*/
|
|
229
279
|
interface X402Recipient {
|
|
230
280
|
/** EVM payout address (required for EVM networks). */
|
|
231
281
|
readonly evm?: EvmAddress;
|
|
@@ -235,6 +285,7 @@ interface X402Recipient {
|
|
|
235
285
|
/**
|
|
236
286
|
* Server-side (charge rail) config. The server needs only a **recipient
|
|
237
287
|
* address** — no private key — because the facilitator performs settlement.
|
|
288
|
+
* @experimental
|
|
238
289
|
*/
|
|
239
290
|
interface X402ChargeConfig {
|
|
240
291
|
readonly facilitator?: FacilitatorConfig;
|
|
@@ -256,6 +307,7 @@ interface X402ChargeConfig {
|
|
|
256
307
|
* Client-side (pay rail) config. The signer holds spending authority, so the
|
|
257
308
|
* pay rail is ActionCtx-only and MUST be paired with a spend `policy` — the pay
|
|
258
309
|
* rail refuses to build if the policy is unbounded.
|
|
310
|
+
* @experimental
|
|
259
311
|
*/
|
|
260
312
|
interface X402PayConfig {
|
|
261
313
|
/** Network to transact on. Determines the signer family (EVM vs SVM). */
|
|
@@ -275,6 +327,7 @@ interface X402PayConfig {
|
|
|
275
327
|
* custody is `@coinbase/cdp-sdk`.) EVM only today; for CDP on Solana, build a
|
|
276
328
|
* `@solana/kit` signer around your CDP account and pass it via the `"signer"`
|
|
277
329
|
* escape hatch.
|
|
330
|
+
* @experimental
|
|
278
331
|
*/
|
|
279
332
|
interface X402CdpSignerConfig {
|
|
280
333
|
/** CDP account name to get-or-create and sign with. */
|
|
@@ -306,6 +359,7 @@ interface X402CdpSignerConfig {
|
|
|
306
359
|
* Wired today: raw-key (EVM + SVM), the user-supplied signer (both families),
|
|
307
360
|
* and CDP-managed EVM custody. CDP on Solana is not yet wired — use the escape
|
|
308
361
|
* hatch.
|
|
362
|
+
* @experimental
|
|
309
363
|
*/
|
|
310
364
|
type X402SignerConfig = X402CdpSignerConfig | {
|
|
311
365
|
/** Name of the `ctx.secrets` entry holding the private key. */
|
|
@@ -320,6 +374,9 @@ type X402SignerConfig = X402CdpSignerConfig | {
|
|
|
320
374
|
readonly signer: ClientEvmSigner | ClientSvmSigner;
|
|
321
375
|
readonly type: "signer";
|
|
322
376
|
};
|
|
323
|
-
/**
|
|
377
|
+
/**
|
|
378
|
+
* Resolve a facilitator's base URL, applying the public default.
|
|
379
|
+
* @experimental
|
|
380
|
+
*/
|
|
324
381
|
declare const resolveFacilitatorUrl: (facilitator?: FacilitatorConfig) => string;
|
|
325
382
|
export { Caip2 as C, DEFAULT_FACILITATOR_URL as D, EVM_NETWORKS as E, FacilitatorConfig as F, NETWORK_TO_CAIP2 as N, PaymentEventRow as P, SVM_NETWORKS as S, X402CdpSignerConfig as X, EvmAddress as a, FriendlyNetwork as b, X402ChargeConfig as c, X402Network as d, X402PayConfig as e, X402Price as f, X402Receipt as g, X402ReceiptSink as h, X402Recipient as i, X402SignerConfig as j, isEvmNetwork as k, isSvmNetwork as l, DEFAULT_STABLECOIN_DECIMALS as m, SpendPolicy as n, SpendState as o, assertBoundedPolicy as p, buildPaymentGuard as q, resolveFacilitatorUrl as r, buildSpendPolicy as s, toCaip2 as t, createSpendState as u, recordSpend as v, usdToAtomic as w, toPaymentEventRow as x, toReceipt as y };
|
|
@@ -19,7 +19,7 @@ const buildResourceServer = async (config) => {
|
|
|
19
19
|
|
|
20
20
|
const PAYMENT_HEADER = "X-PAYMENT";
|
|
21
21
|
const headerRecord = (headers) => {
|
|
22
|
-
const record =
|
|
22
|
+
const record = /* @__PURE__ */ Object.create(null);
|
|
23
23
|
for (const [key, value] of headers) {
|
|
24
24
|
record[key] = value;
|
|
25
25
|
}
|
|
@@ -66,7 +66,7 @@ const createRequestAdapter = (request, url) => {
|
|
|
66
66
|
return values.length === 1 ? values[0] : values;
|
|
67
67
|
},
|
|
68
68
|
getQueryParams: () => {
|
|
69
|
-
const params =
|
|
69
|
+
const params = /* @__PURE__ */ Object.create(null);
|
|
70
70
|
for (const key of new Set(url.searchParams.keys())) {
|
|
71
71
|
const values = url.searchParams.getAll(key);
|
|
72
72
|
const [first, ...rest] = values;
|
package/dist/pay/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as X402PayConfig } from "../packem_shared/config.d-
|
|
2
|
-
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, m as DEFAULT_STABLECOIN_DECIMALS, type n as SpendPolicy, type o as SpendState, type X as X402CdpSignerConfig, type d as X402Network, type f as X402Price, type j as X402SignerConfig, p as assertBoundedPolicy, q as buildPaymentGuard, s as buildSpendPolicy, u as createSpendState, k as isEvmNetwork, l as isSvmNetwork, v as recordSpend, r as resolveFacilitatorUrl, t as toCaip2, w as usdToAtomic } from "../packem_shared/config.d-
|
|
1
|
+
import { e as X402PayConfig } from "../packem_shared/config.d-D8gKQLAq.mjs";
|
|
2
|
+
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, m as DEFAULT_STABLECOIN_DECIMALS, type n as SpendPolicy, type o as SpendState, type X as X402CdpSignerConfig, type d as X402Network, type f as X402Price, type j as X402SignerConfig, p as assertBoundedPolicy, q as buildPaymentGuard, s as buildSpendPolicy, u as createSpendState, k as isEvmNetwork, l as isSvmNetwork, v as recordSpend, r as resolveFacilitatorUrl, t as toCaip2, w as usdToAtomic } from "../packem_shared/config.d-D8gKQLAq.mjs";
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
4
|
import { ClientSvmSigner } from '@x402/svm';
|
|
5
5
|
import { PrivateKeyAccount } from 'viem/accounts';
|
|
@@ -8,7 +8,10 @@ import '@x402/core/http';
|
|
|
8
8
|
import '@x402/core/types';
|
|
9
9
|
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
10
|
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
12
15
|
interface WalletDeps {
|
|
13
16
|
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
14
17
|
readonly getSecret: GetSecret;
|
|
@@ -17,6 +20,7 @@ interface WalletDeps {
|
|
|
17
20
|
* Resolve a viem `LocalAccount` from a raw private key. The key may be given with
|
|
18
21
|
* or without the `0x` prefix. The account is a structural `ClientEvmSigner`
|
|
19
22
|
* (`address` + `signTypedData`), so `@x402/evm` accepts it directly.
|
|
23
|
+
* @experimental
|
|
20
24
|
*/
|
|
21
25
|
declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccount>;
|
|
22
26
|
/**
|
|
@@ -25,6 +29,7 @@ declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccou
|
|
|
25
29
|
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
26
30
|
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
27
31
|
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
32
|
+
* @experimental
|
|
28
33
|
*/
|
|
29
34
|
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
30
35
|
/**
|
|
@@ -34,11 +39,18 @@ declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
|
34
39
|
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
35
40
|
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
36
41
|
* `@coinbase/cdp-sdk`).
|
|
42
|
+
* @experimental
|
|
37
43
|
*/
|
|
38
44
|
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
39
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
40
49
|
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
41
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
+
* @experimental
|
|
53
|
+
*/
|
|
42
54
|
interface X402PayDeps extends WalletDeps {
|
|
43
55
|
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
44
56
|
readonly fetch?: typeof globalThis.fetch;
|
|
@@ -47,9 +59,13 @@ interface X402PayDeps extends WalletDeps {
|
|
|
47
59
|
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
48
60
|
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
49
61
|
* with unlimited spend authority.
|
|
62
|
+
* @experimental
|
|
50
63
|
*/
|
|
51
64
|
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
52
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
53
69
|
interface X402Pay {
|
|
54
70
|
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
55
71
|
readonly fetch: PayFetch;
|
|
@@ -58,6 +74,7 @@ interface X402Pay {
|
|
|
58
74
|
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
59
75
|
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
60
76
|
* signer) when the policy is unbounded.
|
|
77
|
+
* @experimental
|
|
61
78
|
*/
|
|
62
79
|
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
63
80
|
/**
|
|
@@ -72,6 +89,7 @@ declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promi
|
|
|
72
89
|
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
73
90
|
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
74
91
|
* fail-closed.
|
|
92
|
+
* @experimental
|
|
75
93
|
*/
|
|
76
94
|
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
77
95
|
export { type PayFetch, type WalletDeps, X402Pay, type X402PayConfig, type X402PayDeps, createPayFetch, createX402Pay, lazyX402Pay, registerWallet, resolveEvmAccount, resolveSvmSigner };
|
package/dist/pay/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { e as X402PayConfig } from "../packem_shared/config.d-
|
|
2
|
-
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, m as DEFAULT_STABLECOIN_DECIMALS, type n as SpendPolicy, type o as SpendState, type X as X402CdpSignerConfig, type d as X402Network, type f as X402Price, type j as X402SignerConfig, p as assertBoundedPolicy, q as buildPaymentGuard, s as buildSpendPolicy, u as createSpendState, k as isEvmNetwork, l as isSvmNetwork, v as recordSpend, r as resolveFacilitatorUrl, t as toCaip2, w as usdToAtomic } from "../packem_shared/config.d-
|
|
1
|
+
import { e as X402PayConfig } from "../packem_shared/config.d-D8gKQLAq.js";
|
|
2
|
+
export { type C as Caip2, D as DEFAULT_FACILITATOR_URL, m as DEFAULT_STABLECOIN_DECIMALS, type n as SpendPolicy, type o as SpendState, type X as X402CdpSignerConfig, type d as X402Network, type f as X402Price, type j as X402SignerConfig, p as assertBoundedPolicy, q as buildPaymentGuard, s as buildSpendPolicy, u as createSpendState, k as isEvmNetwork, l as isSvmNetwork, v as recordSpend, r as resolveFacilitatorUrl, t as toCaip2, w as usdToAtomic } from "../packem_shared/config.d-D8gKQLAq.js";
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
4
|
import { ClientSvmSigner } from '@x402/svm';
|
|
5
5
|
import { PrivateKeyAccount } from 'viem/accounts';
|
|
@@ -8,7 +8,10 @@ import '@x402/core/http';
|
|
|
8
8
|
import '@x402/core/types';
|
|
9
9
|
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
10
|
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
12
15
|
interface WalletDeps {
|
|
13
16
|
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
14
17
|
readonly getSecret: GetSecret;
|
|
@@ -17,6 +20,7 @@ interface WalletDeps {
|
|
|
17
20
|
* Resolve a viem `LocalAccount` from a raw private key. The key may be given with
|
|
18
21
|
* or without the `0x` prefix. The account is a structural `ClientEvmSigner`
|
|
19
22
|
* (`address` + `signTypedData`), so `@x402/evm` accepts it directly.
|
|
23
|
+
* @experimental
|
|
20
24
|
*/
|
|
21
25
|
declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccount>;
|
|
22
26
|
/**
|
|
@@ -25,6 +29,7 @@ declare const resolveEvmAccount: (privateKey: string) => Promise<PrivateKeyAccou
|
|
|
25
29
|
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
26
30
|
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
27
31
|
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
32
|
+
* @experimental
|
|
28
33
|
*/
|
|
29
34
|
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
30
35
|
/**
|
|
@@ -34,11 +39,18 @@ declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
|
34
39
|
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
35
40
|
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
36
41
|
* `@coinbase/cdp-sdk`).
|
|
42
|
+
* @experimental
|
|
37
43
|
*/
|
|
38
44
|
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
39
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
40
49
|
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
41
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
+
* @experimental
|
|
53
|
+
*/
|
|
42
54
|
interface X402PayDeps extends WalletDeps {
|
|
43
55
|
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
44
56
|
readonly fetch?: typeof globalThis.fetch;
|
|
@@ -47,9 +59,13 @@ interface X402PayDeps extends WalletDeps {
|
|
|
47
59
|
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
48
60
|
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
49
61
|
* with unlimited spend authority.
|
|
62
|
+
* @experimental
|
|
50
63
|
*/
|
|
51
64
|
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
52
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
53
69
|
interface X402Pay {
|
|
54
70
|
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
55
71
|
readonly fetch: PayFetch;
|
|
@@ -58,6 +74,7 @@ interface X402Pay {
|
|
|
58
74
|
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
59
75
|
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
60
76
|
* signer) when the policy is unbounded.
|
|
77
|
+
* @experimental
|
|
61
78
|
*/
|
|
62
79
|
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
63
80
|
/**
|
|
@@ -72,6 +89,7 @@ declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promi
|
|
|
72
89
|
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
73
90
|
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
74
91
|
* fail-closed.
|
|
92
|
+
* @experimental
|
|
75
93
|
*/
|
|
76
94
|
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
77
95
|
export { type PayFetch, type WalletDeps, X402Pay, type X402PayConfig, type X402PayDeps, createPayFetch, createX402Pay, lazyX402Pay, registerWallet, resolveEvmAccount, resolveSvmSigner };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/x402",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"description": "Agentic payments (x402) for Lunora: charge agents per request (charge rail) and let your agents pay x402-gated resources (pay rail)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agents",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
55
|
+
"@lunora/errors": "1.0.0-alpha.5",
|
|
56
56
|
"@solana/kit": "5.5.1",
|
|
57
57
|
"@x402/core": "2.17.0",
|
|
58
58
|
"@x402/evm": "2.17.0",
|