@lunora/x402 1.0.0-alpha.4 → 1.0.0-alpha.41
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/LICENSE.md +18 -0
- package/README.md +18 -0
- package/dist/charge/index.d.mts +155 -95
- package/dist/charge/index.d.ts +155 -95
- package/dist/charge/index.mjs +1 -7
- package/dist/index.d.mts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.mjs +1 -2
- package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-hq1xeZL6.mjs +1 -0
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs +1 -0
- package/dist/packem_shared/EVM_NETWORKS-C5yyzK27.mjs +1 -0
- package/dist/packem_shared/createChargeMiddleware-CURPSr23.mjs +1 -0
- package/dist/packem_shared/createFacilitatorClient-piLSnKs5.mjs +1 -0
- package/dist/packem_shared/createPayFetch-lyg7i3Js.mjs +1 -0
- package/dist/packem_shared/createProcedureChargeGate-Ki_K8dQE.mjs +1 -0
- package/dist/packem_shared/index.d-CzQaqaP6.d.mts +533 -0
- package/dist/packem_shared/index.d-CzQaqaP6.d.ts +533 -0
- package/dist/packem_shared/optional-peer-BBhVxozi.mjs +1 -0
- package/dist/packem_shared/registerWallet-DvCt0Q7M.mjs +1 -0
- package/dist/packem_shared/toPaymentEventRow-DTXuTDh0.mjs +1 -0
- package/dist/packem_shared/withX402-CJcBVHdI.mjs +1 -0
- package/dist/pay/index.d.mts +61 -61
- package/dist/pay/index.d.ts +61 -61
- package/dist/pay/index.mjs +1 -21
- package/package.json +21 -9
- package/dist/packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs +0 -4
- package/dist/packem_shared/DEFAULT_STABLECOIN_DECIMALS-CpW619nu.mjs +0 -90
- package/dist/packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs +0 -26
- package/dist/packem_shared/config.d-5Nqi5iox.d.mts +0 -404
- package/dist/packem_shared/config.d-5Nqi5iox.d.ts +0 -404
- package/dist/packem_shared/createChargeMiddleware-D3yhOpFs.mjs +0 -162
- package/dist/packem_shared/createFacilitatorClient-rXHBnCZm.mjs +0 -16
- package/dist/packem_shared/createPayFetch-BeT05njL.mjs +0 -17
- package/dist/packem_shared/createProcedureChargeGate-eh9yv36U.mjs +0 -21
- package/dist/packem_shared/registerWallet-I4pVwq65.mjs +0 -109
- package/dist/packem_shared/toPaymentEventRow-DW4O9N7Y.mjs +0 -22
- package/dist/packem_shared/withX402-DILL2DvD.mjs +0 -15
package/dist/pay/index.d.mts
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type
|
|
1
|
+
import { X as X402PayConfig, C as ClientEvmSigner, a as ClientSvmSigner } from "../packem_shared/index.d-CzQaqaP6.mjs";
|
|
2
|
+
export { type A as AllowedAsset, type b as Caip2, D as DEFAULT_ALLOWED_ASSETS, c as DEFAULT_FACILITATOR_URL, d as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type e as SpendState, type f as X402CdpSignerConfig, type g as X402Network, type h as X402Price, type i as X402SignerConfig, j as assertBoundedPolicy, k as buildPaymentGuard, l as buildSpendPolicy, m as createSpendState, n as isEvmNetwork, o as isSvmNetwork, r as releaseSpendOnFailure, p as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-CzQaqaP6.mjs";
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
|
-
import { ClientSvmSigner } from '@x402/svm';
|
|
5
|
-
import { PrivateKeyAccount } from 'viem/accounts';
|
|
6
|
-
import '@x402/evm';
|
|
7
4
|
import '@x402/core/http';
|
|
8
5
|
import '@x402/core/types';
|
|
6
|
+
import '@solana/accounts';
|
|
9
7
|
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
8
|
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
11
9
|
/**
|
|
12
|
-
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
13
|
-
* @experimental
|
|
14
|
-
*/
|
|
10
|
+
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
15
13
|
interface WalletDeps {
|
|
16
14
|
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
17
15
|
readonly getSecret: GetSecret;
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
|
-
* Resolve a
|
|
21
|
-
* or without the `0x` prefix.
|
|
22
|
-
* (`address` + `signTypedData`)
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
* Resolve a signer from a raw private key (a viem `LocalAccount` under the hood).
|
|
19
|
+
* The key may be given with or without the `0x` prefix. Typed as the structural
|
|
20
|
+
* `ClientEvmSigner` (`address` + `signTypedData`) rather than viem's own
|
|
21
|
+
* `PrivateKeyAccount` so the published declarations don't require the optional
|
|
22
|
+
* viem peer to type-check.
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
declare const resolveEvmAccount: (privateKey: string) => Promise<ClientEvmSigner>;
|
|
26
26
|
/**
|
|
27
|
-
* Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
|
|
28
|
-
* may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
|
|
29
|
-
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
30
|
-
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
31
|
-
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
32
|
-
* @experimental
|
|
33
|
-
*/
|
|
27
|
+
* Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
|
|
28
|
+
* may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
|
|
29
|
+
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
30
|
+
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
31
|
+
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
32
|
+
* @experimental
|
|
33
|
+
*/
|
|
34
34
|
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
35
35
|
/**
|
|
36
|
-
* Register the scheme family the configured network needs on `client`, wired to
|
|
37
|
-
* the agent signer. Dispatches on network family (EVM vs SVM) and on custody —
|
|
38
|
-
* `"signer"` (a signer the caller already built; registered directly, no secret
|
|
39
|
-
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
40
|
-
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
41
|
-
* `@coinbase/cdp-sdk`).
|
|
42
|
-
* @experimental
|
|
43
|
-
*/
|
|
36
|
+
* Register the scheme family the configured network needs on `client`, wired to
|
|
37
|
+
* the agent signer. Dispatches on network family (EVM vs SVM) and on custody —
|
|
38
|
+
* `"signer"` (a signer the caller already built; registered directly, no secret
|
|
39
|
+
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
40
|
+
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
41
|
+
* `@coinbase/cdp-sdk`).
|
|
42
|
+
* @experimental
|
|
43
|
+
*/
|
|
44
44
|
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
45
45
|
/**
|
|
46
|
-
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
-
* @experimental
|
|
48
|
-
*/
|
|
46
|
+
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
49
|
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
50
50
|
/**
|
|
51
|
-
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
-
* @experimental
|
|
53
|
-
*/
|
|
51
|
+
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
+
* @experimental
|
|
53
|
+
*/
|
|
54
54
|
interface X402PayDeps extends WalletDeps {
|
|
55
55
|
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
56
56
|
readonly fetch?: typeof globalThis.fetch;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
60
|
-
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
61
|
-
* with unlimited spend authority.
|
|
62
|
-
* @experimental
|
|
63
|
-
*/
|
|
59
|
+
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
60
|
+
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
61
|
+
* with unlimited spend authority.
|
|
62
|
+
* @experimental
|
|
63
|
+
*/
|
|
64
64
|
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
65
65
|
/**
|
|
66
|
-
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
-
* @experimental
|
|
68
|
-
*/
|
|
66
|
+
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
69
|
interface X402Pay {
|
|
70
70
|
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
71
71
|
readonly fetch: PayFetch;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
75
|
-
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
76
|
-
* signer) when the policy is unbounded.
|
|
77
|
-
* @experimental
|
|
78
|
-
*/
|
|
74
|
+
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
75
|
+
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
76
|
+
* signer) when the policy is unbounded.
|
|
77
|
+
* @experimental
|
|
78
|
+
*/
|
|
79
79
|
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
80
80
|
/**
|
|
81
|
-
* A synchronous, lazily-initialised pay rail — what codegen wires `ctx.x402` to.
|
|
82
|
-
*
|
|
83
|
-
* `buildCtx` must stay synchronous, but {@link createX402Pay} is async (it reads
|
|
84
|
-
* the wallet secret and imports the signer). So this returns an {@link X402Pay}
|
|
85
|
-
* immediately whose `fetch` builds the real rail on its **first** call and
|
|
86
|
-
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
87
|
-
* only when an action actually pays, and the single `SpendState` behind the
|
|
88
|
-
* rail is shared across every payment for the lifetime of this ctx — so the
|
|
89
|
-
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
90
|
-
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
91
|
-
* fail-closed.
|
|
92
|
-
* @experimental
|
|
93
|
-
*/
|
|
81
|
+
* A synchronous, lazily-initialised pay rail — what codegen wires `ctx.x402` to.
|
|
82
|
+
*
|
|
83
|
+
* `buildCtx` must stay synchronous, but {@link createX402Pay} is async (it reads
|
|
84
|
+
* the wallet secret and imports the signer). So this returns an {@link X402Pay}
|
|
85
|
+
* immediately whose `fetch` builds the real rail on its **first** call and
|
|
86
|
+
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
87
|
+
* only when an action actually pays, and the single `SpendState` behind the
|
|
88
|
+
* rail is shared across every payment for the lifetime of this ctx — so the
|
|
89
|
+
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
90
|
+
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
91
|
+
* fail-closed.
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
94
94
|
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
95
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,95 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type
|
|
1
|
+
import { X as X402PayConfig, C as ClientEvmSigner, a as ClientSvmSigner } from "../packem_shared/index.d-CzQaqaP6.js";
|
|
2
|
+
export { type A as AllowedAsset, type b as Caip2, D as DEFAULT_ALLOWED_ASSETS, c as DEFAULT_FACILITATOR_URL, d as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type e as SpendState, type f as X402CdpSignerConfig, type g as X402Network, type h as X402Price, type i as X402SignerConfig, j as assertBoundedPolicy, k as buildPaymentGuard, l as buildSpendPolicy, m as createSpendState, n as isEvmNetwork, o as isSvmNetwork, r as releaseSpendOnFailure, p as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-CzQaqaP6.js";
|
|
3
3
|
import { x402Client } from '@x402/core/client';
|
|
4
|
-
import { ClientSvmSigner } from '@x402/svm';
|
|
5
|
-
import { PrivateKeyAccount } from 'viem/accounts';
|
|
6
|
-
import '@x402/evm';
|
|
7
4
|
import '@x402/core/http';
|
|
8
5
|
import '@x402/core/types';
|
|
6
|
+
import '@solana/accounts';
|
|
9
7
|
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
10
8
|
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
11
9
|
/**
|
|
12
|
-
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
13
|
-
* @experimental
|
|
14
|
-
*/
|
|
10
|
+
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
15
13
|
interface WalletDeps {
|
|
16
14
|
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
17
15
|
readonly getSecret: GetSecret;
|
|
18
16
|
}
|
|
19
17
|
/**
|
|
20
|
-
* Resolve a
|
|
21
|
-
* or without the `0x` prefix.
|
|
22
|
-
* (`address` + `signTypedData`)
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
* Resolve a signer from a raw private key (a viem `LocalAccount` under the hood).
|
|
19
|
+
* The key may be given with or without the `0x` prefix. Typed as the structural
|
|
20
|
+
* `ClientEvmSigner` (`address` + `signTypedData`) rather than viem's own
|
|
21
|
+
* `PrivateKeyAccount` so the published declarations don't require the optional
|
|
22
|
+
* viem peer to type-check.
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
declare const resolveEvmAccount: (privateKey: string) => Promise<ClientEvmSigner>;
|
|
26
26
|
/**
|
|
27
|
-
* Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
|
|
28
|
-
* may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
|
|
29
|
-
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
30
|
-
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
31
|
-
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
32
|
-
* @experimental
|
|
33
|
-
*/
|
|
27
|
+
* Resolve a `@solana/kit` `KeyPairSigner` from a raw Solana secret key. The secret
|
|
28
|
+
* may be given as a JSON byte array (`[12,34,…]`, the `solana-keygen` keyfile
|
|
29
|
+
* format) or as a base58 string. A 64-byte value is a full secret key (seed ‖
|
|
30
|
+
* public key); a 32-byte value is the seed alone. The returned signer is a
|
|
31
|
+
* structural `ClientSvmSigner` (`TransactionSigner`), so `@x402/svm` accepts it.
|
|
32
|
+
* @experimental
|
|
33
|
+
*/
|
|
34
34
|
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
35
35
|
/**
|
|
36
|
-
* Register the scheme family the configured network needs on `client`, wired to
|
|
37
|
-
* the agent signer. Dispatches on network family (EVM vs SVM) and on custody —
|
|
38
|
-
* `"signer"` (a signer the caller already built; registered directly, no secret
|
|
39
|
-
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
40
|
-
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
41
|
-
* `@coinbase/cdp-sdk`).
|
|
42
|
-
* @experimental
|
|
43
|
-
*/
|
|
36
|
+
* Register the scheme family the configured network needs on `client`, wired to
|
|
37
|
+
* the agent signer. Dispatches on network family (EVM vs SVM) and on custody —
|
|
38
|
+
* `"signer"` (a signer the caller already built; registered directly, no secret
|
|
39
|
+
* read), `"raw-key"` (a `ctx.secrets` private key → viem account on EVM or a
|
|
40
|
+
* `@solana/kit` keypair on SVM), or `"cdp"` (a Coinbase-managed wallet via
|
|
41
|
+
* `@coinbase/cdp-sdk`).
|
|
42
|
+
* @experimental
|
|
43
|
+
*/
|
|
44
44
|
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
45
45
|
/**
|
|
46
|
-
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
-
* @experimental
|
|
48
|
-
*/
|
|
46
|
+
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
49
|
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
50
50
|
/**
|
|
51
|
-
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
-
* @experimental
|
|
53
|
-
*/
|
|
51
|
+
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
+
* @experimental
|
|
53
|
+
*/
|
|
54
54
|
interface X402PayDeps extends WalletDeps {
|
|
55
55
|
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
56
56
|
readonly fetch?: typeof globalThis.fetch;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
60
|
-
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
61
|
-
* with unlimited spend authority.
|
|
62
|
-
* @experimental
|
|
63
|
-
*/
|
|
59
|
+
* Build a payment-enabled `fetch` for `config`. Throws (before resolving a
|
|
60
|
+
* signer) when `config.policy` is unbounded — an agent wallet is never built
|
|
61
|
+
* with unlimited spend authority.
|
|
62
|
+
* @experimental
|
|
63
|
+
*/
|
|
64
64
|
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
65
65
|
/**
|
|
66
|
-
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
-
* @experimental
|
|
68
|
-
*/
|
|
66
|
+
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
69
|
interface X402Pay {
|
|
70
70
|
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
71
71
|
readonly fetch: PayFetch;
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
75
|
-
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
76
|
-
* signer) when the policy is unbounded.
|
|
77
|
-
* @experimental
|
|
78
|
-
*/
|
|
74
|
+
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
75
|
+
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
76
|
+
* signer) when the policy is unbounded.
|
|
77
|
+
* @experimental
|
|
78
|
+
*/
|
|
79
79
|
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
80
80
|
/**
|
|
81
|
-
* A synchronous, lazily-initialised pay rail — what codegen wires `ctx.x402` to.
|
|
82
|
-
*
|
|
83
|
-
* `buildCtx` must stay synchronous, but {@link createX402Pay} is async (it reads
|
|
84
|
-
* the wallet secret and imports the signer). So this returns an {@link X402Pay}
|
|
85
|
-
* immediately whose `fetch` builds the real rail on its **first** call and
|
|
86
|
-
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
87
|
-
* only when an action actually pays, and the single `SpendState` behind the
|
|
88
|
-
* rail is shared across every payment for the lifetime of this ctx — so the
|
|
89
|
-
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
90
|
-
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
91
|
-
* fail-closed.
|
|
92
|
-
* @experimental
|
|
93
|
-
*/
|
|
81
|
+
* A synchronous, lazily-initialised pay rail — what codegen wires `ctx.x402` to.
|
|
82
|
+
*
|
|
83
|
+
* `buildCtx` must stay synchronous, but {@link createX402Pay} is async (it reads
|
|
84
|
+
* the wallet secret and imports the signer). So this returns an {@link X402Pay}
|
|
85
|
+
* immediately whose `fetch` builds the real rail on its **first** call and
|
|
86
|
+
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
87
|
+
* only when an action actually pays, and the single `SpendState` behind the
|
|
88
|
+
* rail is shared across every payment for the lifetime of this ctx — so the
|
|
89
|
+
* per-run cap scopes to the ctx, not to each request. A failed build (e.g. an
|
|
90
|
+
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
91
|
+
* fail-closed.
|
|
92
|
+
* @experimental
|
|
93
|
+
*/
|
|
94
94
|
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
95
95
|
export { type PayFetch, type WalletDeps, X402Pay, type X402PayConfig, type X402PayDeps, createPayFetch, createX402Pay, lazyX402Pay, registerWallet, resolveEvmAccount, resolveSvmSigner };
|
package/dist/pay/index.mjs
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export { DEFAULT_FACILITATOR_URL, resolveFacilitatorUrl } from '../packem_shared/DEFAULT_FACILITATOR_URL-Cbz6kIqa.mjs';
|
|
3
|
-
export { isEvmNetwork, isSvmNetwork, toCaip2 } from '../packem_shared/EVM_NETWORKS-BhnYWUQ4.mjs';
|
|
4
|
-
export { DEFAULT_STABLECOIN_DECIMALS, assertBoundedPolicy, buildPaymentGuard, buildSpendPolicy, createSpendState, releaseSpendOnFailure, usdToAtomic } from '../packem_shared/DEFAULT_STABLECOIN_DECIMALS-CpW619nu.mjs';
|
|
5
|
-
export { registerWallet, resolveEvmAccount, resolveSvmSigner } from '../packem_shared/registerWallet-I4pVwq65.mjs';
|
|
6
|
-
|
|
7
|
-
const createX402Pay = async (config, deps) => {
|
|
8
|
-
const fetch = await createPayFetch(config, deps);
|
|
9
|
-
return { fetch };
|
|
10
|
-
};
|
|
11
|
-
const lazyX402Pay = (config, deps) => {
|
|
12
|
-
let railPromise;
|
|
13
|
-
const fetch = async (input, init) => {
|
|
14
|
-
railPromise ??= createX402Pay(config, deps);
|
|
15
|
-
const rail = await railPromise;
|
|
16
|
-
return rail.fetch(input, init);
|
|
17
|
-
};
|
|
18
|
-
return { fetch };
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export { createPayFetch, createX402Pay, lazyX402Pay };
|
|
1
|
+
import{createPayFetch as c}from"../packem_shared/createPayFetch-lyg7i3Js.mjs";import{DEFAULT_FACILITATOR_URL as f,resolveFacilitatorUrl as p}from"../packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";import{isEvmNetwork as d,isSvmNetwork as y,toCaip2 as E}from"../packem_shared/EVM_NETWORKS-C5yyzK27.mjs";import{DEFAULT_ALLOWED_ASSETS as T,DEFAULT_STABLECOIN_DECIMALS as v,assertBoundedPolicy as F,buildPaymentGuard as P,buildSpendPolicy as h,createSpendState as _,releaseSpendOnFailure as x,usdToAtomic as D}from"../packem_shared/DEFAULT_ALLOWED_ASSETS-hq1xeZL6.mjs";import{registerWallet as w,resolveEvmAccount as C,resolveSvmSigner as I}from"../packem_shared/registerWallet-DvCt0Q7M.mjs";const i=async(e,t)=>({fetch:await c(e,t)}),m=(e,t)=>{let r;return{fetch:async(o,a)=>(r??=i(e,t),(await r).fetch(o,a))}};export{T as DEFAULT_ALLOWED_ASSETS,f as DEFAULT_FACILITATOR_URL,v as DEFAULT_STABLECOIN_DECIMALS,F as assertBoundedPolicy,P as buildPaymentGuard,h as buildSpendPolicy,c as createPayFetch,_ as createSpendState,i as createX402Pay,d as isEvmNetwork,y as isSvmNetwork,m as lazyX402Pay,w as registerWallet,x as releaseSpendOnFailure,C as resolveEvmAccount,p as resolveFacilitatorUrl,I as resolveSvmSigner,E as toCaip2,D as usdToAtomic};
|
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.41",
|
|
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,17 +52,17 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
56
|
-
"@
|
|
57
|
-
"@x402/
|
|
58
|
-
"@x402/evm": "2.17.0",
|
|
59
|
-
"@x402/fetch": "2.17.0",
|
|
60
|
-
"@x402/svm": "2.17.0",
|
|
61
|
-
"viem": "2.54.1"
|
|
55
|
+
"@lunora/errors": "1.0.0-alpha.23",
|
|
56
|
+
"@x402/core": "2.21.0",
|
|
57
|
+
"@x402/fetch": "2.21.0"
|
|
62
58
|
},
|
|
63
59
|
"peerDependencies": {
|
|
64
60
|
"@coinbase/cdp-sdk": ">=1.0.0",
|
|
65
|
-
"@coinbase/x402": ">=2.0.0"
|
|
61
|
+
"@coinbase/x402": ">=2.0.0",
|
|
62
|
+
"@solana/kit": ">=7.0.0",
|
|
63
|
+
"@x402/evm": ">=2.0.0",
|
|
64
|
+
"@x402/svm": ">=2.0.0",
|
|
65
|
+
"viem": ">=2.0.0"
|
|
66
66
|
},
|
|
67
67
|
"peerDependenciesMeta": {
|
|
68
68
|
"@coinbase/cdp-sdk": {
|
|
@@ -70,6 +70,18 @@
|
|
|
70
70
|
},
|
|
71
71
|
"@coinbase/x402": {
|
|
72
72
|
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@solana/kit": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"@x402/evm": {
|
|
78
|
+
"optional": true
|
|
79
|
+
},
|
|
80
|
+
"@x402/svm": {
|
|
81
|
+
"optional": true
|
|
82
|
+
},
|
|
83
|
+
"viem": {
|
|
84
|
+
"optional": true
|
|
73
85
|
}
|
|
74
86
|
},
|
|
75
87
|
"engines": {
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { toCaip2 } from './EVM_NETWORKS-BhnYWUQ4.mjs';
|
|
3
|
-
|
|
4
|
-
const USD_AMOUNT = /^\d+(?:\.\d+)?$/;
|
|
5
|
-
const normaliseAddress = (address, network) => network.startsWith("eip155:") ? address.toLowerCase() : address;
|
|
6
|
-
const DEFAULT_STABLECOIN_DECIMALS = 6;
|
|
7
|
-
const createSpendState = () => {
|
|
8
|
-
let spent = 0n;
|
|
9
|
-
return {
|
|
10
|
-
add: (amount) => {
|
|
11
|
-
spent += amount;
|
|
12
|
-
},
|
|
13
|
-
release: (amount) => {
|
|
14
|
-
spent = spent > amount ? spent - amount : 0n;
|
|
15
|
-
},
|
|
16
|
-
get spentAtomic() {
|
|
17
|
-
return spent;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
const usdToAtomic = (usd, decimals = DEFAULT_STABLECOIN_DECIMALS) => {
|
|
22
|
-
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
23
|
-
throw new LunoraError("BAD_REQUEST", `x402 policy: decimals must be a non-negative integer, got ${String(decimals)}.`);
|
|
24
|
-
}
|
|
25
|
-
const raw = (typeof usd === "number" ? usd.toString() : usd).trim();
|
|
26
|
-
const unsigned = raw.startsWith("$") ? raw.slice(1) : raw;
|
|
27
|
-
if (!USD_AMOUNT.test(unsigned)) {
|
|
28
|
-
throw new LunoraError("BAD_REQUEST", `x402 policy: "${String(usd)}" is not a valid USD amount (use a plain decimal like "0.01").`);
|
|
29
|
-
}
|
|
30
|
-
const [whole = "0", fraction = ""] = unsigned.split(".");
|
|
31
|
-
const scaled = fraction.slice(0, decimals).padEnd(decimals, "0");
|
|
32
|
-
return BigInt(whole) * 10n ** BigInt(decimals) + BigInt(scaled === "" ? "0" : scaled);
|
|
33
|
-
};
|
|
34
|
-
const buildSpendPolicy = (policy) => {
|
|
35
|
-
const decimals = policy.decimals ?? DEFAULT_STABLECOIN_DECIMALS;
|
|
36
|
-
const maxPerCall = policy.maxPerCall === void 0 ? void 0 : usdToAtomic(policy.maxPerCall, decimals);
|
|
37
|
-
const allowedNetworks = policy.allowedNetworks?.map((network) => toCaip2(network));
|
|
38
|
-
const { allowedRecipients } = policy;
|
|
39
|
-
return (_version, requirements) => requirements.filter((requirement) => {
|
|
40
|
-
if (maxPerCall !== void 0 && BigInt(requirement.amount) > maxPerCall) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
if (allowedNetworks !== void 0 && !allowedNetworks.includes(requirement.network)) {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
if (allowedRecipients !== void 0) {
|
|
47
|
-
const payTo = normaliseAddress(requirement.payTo, requirement.network);
|
|
48
|
-
return allowedRecipients.some((allowed) => normaliseAddress(allowed, requirement.network) === payTo);
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
const buildPaymentGuard = (policy, state) => {
|
|
54
|
-
const decimals = policy.decimals ?? DEFAULT_STABLECOIN_DECIMALS;
|
|
55
|
-
const maxPerRun = policy.maxPerRun === void 0 ? void 0 : usdToAtomic(policy.maxPerRun, decimals);
|
|
56
|
-
return async (context) => {
|
|
57
|
-
const requirement = context.selectedRequirements;
|
|
58
|
-
const amount = BigInt(requirement.amount);
|
|
59
|
-
if (maxPerRun !== void 0 && state.spentAtomic + amount > maxPerRun) {
|
|
60
|
-
return {
|
|
61
|
-
abort: true,
|
|
62
|
-
reason: `x402 policy: this payment (${requirement.amount}) would exceed the per-run cap (already spent ${state.spentAtomic.toString()}, cap ${maxPerRun.toString()}, in atomic base units).`
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
state.add(amount);
|
|
66
|
-
if (policy.onPaymentRequired !== void 0) {
|
|
67
|
-
const approved = await policy.onPaymentRequired(requirement);
|
|
68
|
-
if (!approved) {
|
|
69
|
-
state.release(amount);
|
|
70
|
-
return { abort: true, reason: "x402 policy: payment was declined by onPaymentRequired." };
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return void 0;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
const releaseSpendOnFailure = (state) => (context) => {
|
|
77
|
-
state.release(BigInt(context.selectedRequirements.amount));
|
|
78
|
-
return Promise.resolve();
|
|
79
|
-
};
|
|
80
|
-
const assertBoundedPolicy = (policy) => {
|
|
81
|
-
const bounded = policy.maxPerCall !== void 0 || policy.maxPerRun !== void 0 || policy.onPaymentRequired !== void 0;
|
|
82
|
-
if (!bounded) {
|
|
83
|
-
throw new LunoraError(
|
|
84
|
-
"FORBIDDEN",
|
|
85
|
-
"x402 pay: refusing to build a wallet with an unbounded spend policy. Set at least one of maxPerCall, maxPerRun, or onPaymentRequired (allowedNetworks/allowedRecipients narrow but do not bound spend)."
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export { DEFAULT_STABLECOIN_DECIMALS, assertBoundedPolicy, buildPaymentGuard, buildSpendPolicy, createSpendState, releaseSpendOnFailure, usdToAtomic };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const NETWORK_TO_CAIP2 = {
|
|
2
|
-
arbitrum: "eip155:42161",
|
|
3
|
-
"arbitrum-sepolia": "eip155:421614",
|
|
4
|
-
base: "eip155:8453",
|
|
5
|
-
"base-sepolia": "eip155:84532",
|
|
6
|
-
ethereum: "eip155:1",
|
|
7
|
-
polygon: "eip155:137",
|
|
8
|
-
solana: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
9
|
-
"solana-devnet": "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"
|
|
10
|
-
};
|
|
11
|
-
const EVM_NETWORKS = ["arbitrum", "arbitrum-sepolia", "base", "base-sepolia", "ethereum", "polygon"];
|
|
12
|
-
const SVM_NETWORKS = ["solana", "solana-devnet"];
|
|
13
|
-
const toCaip2 = (network) => {
|
|
14
|
-
const mapped = NETWORK_TO_CAIP2[network];
|
|
15
|
-
if (mapped !== void 0) {
|
|
16
|
-
return mapped;
|
|
17
|
-
}
|
|
18
|
-
if (network.includes(":")) {
|
|
19
|
-
return network;
|
|
20
|
-
}
|
|
21
|
-
throw new Error(`Unknown x402 network "${network}". Use a friendly name (${EVM_NETWORKS.join(", ")}, ${SVM_NETWORKS.join(", ")}) or a raw CAIP-2 id.`);
|
|
22
|
-
};
|
|
23
|
-
const isEvmNetwork = (network) => toCaip2(network).startsWith("eip155:");
|
|
24
|
-
const isSvmNetwork = (network) => toCaip2(network).startsWith("solana:");
|
|
25
|
-
|
|
26
|
-
export { EVM_NETWORKS, NETWORK_TO_CAIP2, SVM_NETWORKS, isEvmNetwork, isSvmNetwork, toCaip2 };
|