@lunora/x402 1.0.0-alpha.83 → 1.0.0-alpha.85
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 -4
- package/dist/charge/index.d.mts +18 -43
- package/dist/charge/index.d.ts +18 -43
- package/dist/charge/index.mjs +1 -1
- package/dist/index.d.mts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-CX67Ktyc.mjs +1 -0
- package/dist/packem_shared/EVM_NETWORKS-CwbBEtp1.mjs +1 -0
- package/dist/packem_shared/createChargeMiddleware-DyOEuTCT.mjs +1 -0
- package/dist/packem_shared/{createProcedureChargeGate-g4DR6RkQ.mjs → createProcedureChargeGate-BidGWCmf.mjs} +1 -1
- package/dist/packem_shared/{index.d-C1PlJUJL.d.mts → index.d-A-g7yKuO.d.mts} +8 -145
- package/dist/packem_shared/{index.d-C1PlJUJL.d.ts → index.d-A-g7yKuO.d.ts} +8 -145
- package/dist/packem_shared/{withX402-BN0YZQRe.mjs → withX402-mUrRb9a2.mjs} +1 -1
- package/dist/pay/index.d.mts +8 -57
- package/dist/pay/index.d.ts +8 -57
- package/dist/pay/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/DEFAULT_ALLOWED_ASSETS-CYVf8dQC.mjs +0 -1
- package/dist/packem_shared/EVM_NETWORKS-C5yyzK27.mjs +0 -1
- package/dist/packem_shared/createChargeMiddleware-CCcn8Fg_.mjs +0 -1
- package/dist/packem_shared/createFacilitatorClient-piLSnKs5.mjs +0 -1
- package/dist/packem_shared/createPayFetch-A6ED62ml.mjs +0 -1
- package/dist/packem_shared/registerWallet-DvCt0Q7M.mjs +0 -1
package/dist/pay/index.d.mts
CHANGED
|
@@ -1,70 +1,22 @@
|
|
|
1
|
-
import { X as X402PayConfig
|
|
2
|
-
export { type A as AllowedAsset, type
|
|
3
|
-
import { x402Client } from '@x402/core/client';
|
|
4
|
-
import '@x402/core/http';
|
|
1
|
+
import { X as X402PayConfig } from "../packem_shared/index.d-A-g7yKuO.mjs";
|
|
2
|
+
export { type A as AllowedAsset, type C as Caip2, D as DEFAULT_ALLOWED_ASSETS, a as DEFAULT_FACILITATOR_URL, b as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type c as X402CdpSignerConfig, type d as X402Network, type e as X402Price, type f as X402SignerConfig, i as isEvmNetwork, g as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-A-g7yKuO.mjs";
|
|
5
3
|
import '@x402/core/types';
|
|
6
4
|
import '@solana/accounts';
|
|
7
|
-
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
8
|
-
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
11
|
-
* @experimental
|
|
12
|
-
*/
|
|
13
|
-
interface WalletDeps {
|
|
14
|
-
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
15
|
-
readonly getSecret: GetSecret;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
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
|
-
*/
|
|
44
|
-
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
45
5
|
/**
|
|
46
6
|
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
-
* @experimental
|
|
48
7
|
*/
|
|
49
8
|
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
50
9
|
/**
|
|
51
10
|
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
-
* @experimental
|
|
53
11
|
*/
|
|
54
|
-
interface X402PayDeps
|
|
12
|
+
interface X402PayDeps {
|
|
55
13
|
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
56
14
|
readonly fetch?: typeof globalThis.fetch;
|
|
15
|
+
/** Read a secret (e.g. a private key) by name; `undefined` when unset. Wire it to `ctx.secrets.get`. */
|
|
16
|
+
readonly getSecret: (name: string) => Promise<string | undefined> | string | undefined;
|
|
57
17
|
}
|
|
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
|
-
*/
|
|
64
|
-
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
65
18
|
/**
|
|
66
19
|
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
-
* @experimental
|
|
68
20
|
*/
|
|
69
21
|
interface X402Pay {
|
|
70
22
|
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
@@ -74,7 +26,6 @@ interface X402Pay {
|
|
|
74
26
|
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
75
27
|
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
76
28
|
* signer) when the policy is unbounded.
|
|
77
|
-
* @experimental
|
|
78
29
|
*/
|
|
79
30
|
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
80
31
|
/**
|
|
@@ -86,10 +37,10 @@ declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promi
|
|
|
86
37
|
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
87
38
|
* only when an action actually pays, and the single `SpendState` behind the
|
|
88
39
|
* 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
|
|
40
|
+
* per-run cap scopes to the ctx (one function invocation), not to each request
|
|
41
|
+
* and not across invocations. A failed build (e.g. an
|
|
90
42
|
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
91
43
|
* fail-closed.
|
|
92
|
-
* @experimental
|
|
93
44
|
*/
|
|
94
45
|
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
95
|
-
export { type PayFetch,
|
|
46
|
+
export { type PayFetch, X402Pay, type X402PayConfig, type X402PayDeps, createX402Pay, lazyX402Pay };
|
package/dist/pay/index.d.ts
CHANGED
|
@@ -1,70 +1,22 @@
|
|
|
1
|
-
import { X as X402PayConfig
|
|
2
|
-
export { type A as AllowedAsset, type
|
|
3
|
-
import { x402Client } from '@x402/core/client';
|
|
4
|
-
import '@x402/core/http';
|
|
1
|
+
import { X as X402PayConfig } from "../packem_shared/index.d-A-g7yKuO.js";
|
|
2
|
+
export { type A as AllowedAsset, type C as Caip2, D as DEFAULT_ALLOWED_ASSETS, a as DEFAULT_FACILITATOR_URL, b as DEFAULT_STABLECOIN_DECIMALS, type S as SpendPolicy, type c as X402CdpSignerConfig, type d as X402Network, type e as X402Price, type f as X402SignerConfig, i as isEvmNetwork, g as isSvmNetwork, r as resolveFacilitatorUrl, t as toCaip2, u as usdToAtomic } from "../packem_shared/index.d-A-g7yKuO.js";
|
|
5
3
|
import '@x402/core/types';
|
|
6
4
|
import '@solana/accounts';
|
|
7
|
-
/** Reads a secret by name; resolves `undefined` when unset. */
|
|
8
|
-
type GetSecret = (name: string) => Promise<string | undefined> | string | undefined;
|
|
9
|
-
/**
|
|
10
|
-
* How the wallet reads its key material — wired to `ctx.secrets.get` in an action.
|
|
11
|
-
* @experimental
|
|
12
|
-
*/
|
|
13
|
-
interface WalletDeps {
|
|
14
|
-
/** Read a secret (e.g. a private key) by name; `undefined` when unset. */
|
|
15
|
-
readonly getSecret: GetSecret;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
declare const resolveSvmSigner: (secret: string) => Promise<ClientSvmSigner>;
|
|
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
|
-
*/
|
|
44
|
-
declare const registerWallet: (client: x402Client, config: X402PayConfig, deps: WalletDeps) => Promise<void>;
|
|
45
5
|
/**
|
|
46
6
|
* A payment-enabled `fetch`: same signature as the platform `fetch`.
|
|
47
|
-
* @experimental
|
|
48
7
|
*/
|
|
49
8
|
type PayFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
50
9
|
/**
|
|
51
10
|
* Dependencies for building a pay-rail fetch: secret access, plus an optional base `fetch` to wrap.
|
|
52
|
-
* @experimental
|
|
53
11
|
*/
|
|
54
|
-
interface X402PayDeps
|
|
12
|
+
interface X402PayDeps {
|
|
55
13
|
/** The `fetch` to wrap (defaults to `globalThis.fetch`). Inject to test or to chain transports. */
|
|
56
14
|
readonly fetch?: typeof globalThis.fetch;
|
|
15
|
+
/** Read a secret (e.g. a private key) by name; `undefined` when unset. Wire it to `ctx.secrets.get`. */
|
|
16
|
+
readonly getSecret: (name: string) => Promise<string | undefined> | string | undefined;
|
|
57
17
|
}
|
|
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
|
-
*/
|
|
64
|
-
declare const createPayFetch: (config: X402PayConfig, deps: X402PayDeps) => Promise<PayFetch>;
|
|
65
18
|
/**
|
|
66
19
|
* A configured pay rail: a payment-enabled `fetch` bounded by the spend policy.
|
|
67
|
-
* @experimental
|
|
68
20
|
*/
|
|
69
21
|
interface X402Pay {
|
|
70
22
|
/** A `fetch` that transparently pays for `402`-gated resources under the policy. */
|
|
@@ -74,7 +26,6 @@ interface X402Pay {
|
|
|
74
26
|
* Build a pay rail for `config`. The returned `fetch` answers `402` challenges by
|
|
75
27
|
* signing and retrying, within `config.policy`. Throws (before touching the
|
|
76
28
|
* signer) when the policy is unbounded.
|
|
77
|
-
* @experimental
|
|
78
29
|
*/
|
|
79
30
|
declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promise<X402Pay>;
|
|
80
31
|
/**
|
|
@@ -86,10 +37,10 @@ declare const createX402Pay: (config: X402PayConfig, deps: X402PayDeps) => Promi
|
|
|
86
37
|
* memoises it: the viem/`@x402` signer imports + Secrets Store read are paid for
|
|
87
38
|
* only when an action actually pays, and the single `SpendState` behind the
|
|
88
39
|
* 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
|
|
40
|
+
* per-run cap scopes to the ctx (one function invocation), not to each request
|
|
41
|
+
* and not across invocations. A failed build (e.g. an
|
|
90
42
|
* unbounded policy) is memoised too, keeping the rail deterministically
|
|
91
43
|
* fail-closed.
|
|
92
|
-
* @experimental
|
|
93
44
|
*/
|
|
94
45
|
declare const lazyX402Pay: (config: X402PayConfig, deps: X402PayDeps) => X402Pay;
|
|
95
|
-
export { type PayFetch,
|
|
46
|
+
export { type PayFetch, X402Pay, type X402PayConfig, type X402PayDeps, createX402Pay, lazyX402Pay };
|
package/dist/pay/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{x402Client as h}from"@x402/core/client";import{wrapFetchWithPayment as u}from"@x402/fetch";import{assertBoundedPolicy as E,buildSpendPolicy as S,buildPaymentGuard as k,createSpendState as A,releaseSpendOnFailure as N}from"../packem_shared/DEFAULT_ALLOWED_ASSETS-CX67Ktyc.mjs";import{DEFAULT_ALLOWED_ASSETS as B,DEFAULT_STABLECOIN_DECIMALS as W,usdToAtomic as $}from"../packem_shared/DEFAULT_ALLOWED_ASSETS-CX67Ktyc.mjs";import{LunoraError as c}from"@lunora/errors";import{toCaip2 as f,isEvmNetwork as x}from"../packem_shared/EVM_NETWORKS-CwbBEtp1.mjs";import{isSvmNetwork as Y}from"../packem_shared/EVM_NETWORKS-CwbBEtp1.mjs";import{i as l}from"../packem_shared/optional-peer-BBhVxozi.mjs";import{DEFAULT_FACILITATOR_URL as G,resolveFacilitatorUrl as q}from"../packem_shared/DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";const P=/^0x[0-9a-fA-F]{64}$/,p=async(e,t)=>{const a=await e(t);if(a===void 0||a.length===0)throw new c("ENV_INVALID",`x402 pay: secret "${t}" is not set — the agent wallet has no key to sign with.`);return a},g=(e,t)=>{const a=e.address.startsWith("0x");if(t&&!a)throw new c("ENV_INVALID",`x402 pay: the supplied signer address "${e.address}" is not an EVM (0x…) address, but the network is EVM.`);if(!t&&a)throw new c("ENV_INVALID",`x402 pay: the supplied signer address "${e.address}" is an EVM (0x…) address, but the network is Solana.`)},I=async(e,t)=>{const{CdpClient:a}=await l(()=>import("@coinbase/cdp-sdk"),'x402 pay: CDP-managed custody needs the optional @coinbase/cdp-sdk peer — install it, or use "raw-key"/"signer" custody instead.'),[i,o,r]=await Promise.all([p(t,e.apiKeyIdSecretName??"CDP_API_KEY_ID"),p(t,e.apiKeySecretName??"CDP_API_KEY_SECRET"),p(t,e.walletSecretName??"CDP_WALLET_SECRET")]);return new a({apiKeyId:i,apiKeySecret:o,walletSecret:r}).evm.getOrCreateAccount({name:e.account})},v=async e=>{const t=e.startsWith("0x")?e:`0x${e}`;if(!P.test(t))throw new c("ENV_INVALID","x402 pay: the EVM wallet key must be a 32-byte hex private key (64 hex chars, optional 0x prefix).");const{privateKeyToAccount:a}=await l(()=>import("viem/accounts"),'x402 pay: raw-key EVM custody needs the optional viem peer — install it, or use "cdp"/"signer" custody instead.');return a(t)},V=async e=>{const t=e.trim(),{createKeyPairSignerFromBytes:a,createKeyPairSignerFromPrivateKeyBytes:i,getBase58Encoder:o}=await l(()=>import("@solana/kit"),'x402 pay: raw-key Solana custody needs the optional @solana/kit peer — install it, or pass a pre-built signer via "signer" custody instead.');let r;if(t.startsWith("[")){let s;try{s=JSON.parse(t)}catch{throw new c("ENV_INVALID","x402 pay: the Solana wallet key looks like a JSON byte array but is not valid JSON.")}if(!Array.isArray(s)||s.some(n=>typeof n!="number"))throw new c("ENV_INVALID","x402 pay: the Solana wallet key JSON must be an array of byte values.");r=Uint8Array.from(s)}else try{r=Uint8Array.from(o().encode(t))}catch{throw new c("ENV_INVALID","x402 pay: the Solana wallet key must be a base58 secret key or a JSON byte array.")}if(r.length===64)return a(r);if(r.length===32)return i(r);throw new c("ENV_INVALID",`x402 pay: the Solana wallet key must decode to 32 or 64 bytes (got ${String(r.length)}). Provide a base58 secret key or a JSON byte array.`)},_=async(e,t,a)=>{const i=f(t.network),{signer:o}=t,r=x(t.network);let s;if(o.type==="signer")g(o.signer,r),s=o.signer;else if(o.type==="cdp"){if(!r)throw new c("NOT_IMPLEMENTED",`x402 pay: CDP-managed Solana custody (account "${o.account}") is not wired — a CDP Solana account is not a @solana/kit signer. Build a @solana/kit signer around it and pass it via the { type: "signer" } escape hatch, or use "raw-key".`);s=await I(o,a.getSecret)}else{const n=await p(a.getSecret,o.secretName);s=r?await v(n):await V(n)}if(r){const{registerExactEvmScheme:n}=await l(()=>import("@x402/evm/exact/client"),"x402 pay: EVM networks need the optional @x402/evm + viem peers — install them, or configure an SVM network.");n(e,{networks:[i],signer:s})}else{const{registerExactSvmScheme:n}=await l(()=>import("@x402/svm/exact/client"),"x402 pay: SVM networks need the optional @x402/svm + @solana/kit peers — install them, or configure an EVM network.");n(e,{networks:[i],signer:s})}},b=async(e,t)=>{E(e.policy);const a=A(),i=S(e.policy),o=k(e.policy,a),r=N(a),s=new h;await _(s,e,t),s.registerPolicy(i),s.onBeforePaymentCreation(o),s.onPaymentCreationFailure(r);const n=t.fetch??globalThis.fetch,w=u(n,s);return async(y,d)=>{const m=new Headers(d?.headers??(y instanceof Request?y.headers:void 0));return m.has("PAYMENT-SIGNATURE")||m.has("X-PAYMENT")?n(y,d):w(y,d)}},D=async(e,t)=>({fetch:await b(e,t)}),K=(e,t)=>{let a;return{fetch:async(o,r)=>(a??=D(e,t),(await a).fetch(o,r))}};export{B as DEFAULT_ALLOWED_ASSETS,G as DEFAULT_FACILITATOR_URL,W as DEFAULT_STABLECOIN_DECIMALS,D as createX402Pay,x as isEvmNetwork,Y as isSvmNetwork,K as lazyX402Pay,q as resolveFacilitatorUrl,f as toCaip2,$ 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.85",
|
|
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.51 <2.0.0-0",
|
|
56
56
|
"@x402/core": "2.28.0",
|
|
57
57
|
"@x402/fetch": "2.28.0"
|
|
58
58
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as l}from"@lunora/errors";import{toCaip2 as f}from"./EVM_NETWORKS-C5yyzK27.mjs";const h=/^\d+(?:\.\d+)?$/,u=(e,t)=>t.startsWith("eip155:")?e.toLowerCase():e,p=(e,t)=>`${t}|${u(e,t)}`,v=/^\d+$/,w=e=>v.test(e)?BigInt(e):void 0,S=6,x=[{asset:"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",decimals:6,network:"base"},{asset:"0x036CbD53842c5426634e7929541eC2318f3dCF7e",decimals:6,network:"base-sepolia"},{asset:"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",decimals:6,network:"polygon"},{asset:"0xaf88d065e77c8cC2239327C5EDb3A432268e5831",decimals:6,network:"arbitrum"},{asset:"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",decimals:6,network:"arbitrum-sepolia"},{asset:"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",decimals:6,network:"solana"},{asset:"4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",decimals:6,network:"solana-devnet"}],C=()=>{let e=0n;return{add:t=>{e+=t},release:t=>{e=e>t?e-t:0n},get spentAtomic(){return e}}},E=(e,t=S)=>{if(!Number.isInteger(t)||t<0)throw new l("BAD_REQUEST",`x402 policy: decimals must be a non-negative integer, got ${String(t)}.`);const n=(typeof e=="number"?e.toString():e).trim(),s=n.startsWith("$")?n.slice(1):n;if(!h.test(s))throw new l("BAD_REQUEST",`x402 policy: "${String(e)}" is not a valid USD amount (use a plain decimal like "0.01").`);const[i="0",r=""]=s.split("."),a=r.slice(0,t).padEnd(t,"0");return BigInt(i)*10n**BigInt(t)+BigInt(a===""?"0":a)},b=e=>{if(e.decimals!==void 0)throw new l("BAD_REQUEST","x402 policy: `decimals` is no longer supported — a single policy-wide decimal count can't describe the assets a server may name. List the asset in `allowedAssets` with its own `decimals` instead.");const t=e.allowedAssets??x;if(t.length===0)throw new l("BAD_REQUEST","x402 policy: `allowedAssets` is empty, so no payment could ever be made. Omit it to accept the default USDC assets, or list at least one asset.");const n=new Map;for(const s of t){if(!Number.isInteger(s.decimals)||s.decimals<0)throw new l("BAD_REQUEST",`x402 policy: allowedAssets[${s.asset}].decimals must be a non-negative integer, got ${String(s.decimals)}.`);const i=f(s.network),r=p(s.asset,i),a=n.get(r);if(a!==void 0&&a.decimals!==s.decimals)throw new l("BAD_REQUEST",`x402 policy: allowedAssets lists ${s.asset} on ${i} twice with different decimals (${String(a.decimals)} and ${String(s.decimals)}). One asset cannot have two precisions.`);n.set(r,{...s,network:i})}return n},g=(e,t)=>{const n=new Map;if(e===void 0)return n;for(const{decimals:s}of t.values())n.has(s)||n.set(s,E(e,s));return n},R=e=>{const t=b(e),n=g(e.maxPerCall,t),s=e.allowedNetworks?.map(r=>f(r)),{allowedRecipients:i}=e;return(r,a)=>a.filter(o=>{const c=t.get(p(o.asset,o.network));if(c===void 0)return!1;const d=w(o.amount);if(d===void 0)return!1;const m=n.get(c.decimals);if(m!==void 0&&d>m||s!==void 0&&!s.includes(o.network))return!1;if(i!==void 0){const A=u(o.payTo,o.network);return i.some(y=>u(y,o.network)===A)}return!0})},P=(e,t)=>{const n=b(e),s=g(e.maxPerRun,n);let i;return async r=>{const a=r.selectedRequirements,o=n.get(p(a.asset,a.network));if(o===void 0)return{abort:!0,reason:`x402 policy: asset ${a.asset} on ${a.network} is not in this wallet's allowed assets, so its amount cannot be priced against the caps.`};if(t.spentAtomic>0n&&i!==o.decimals)return{abort:!0,reason:`x402 policy: this payment is in a ${String(o.decimals)}-decimal asset but the run's spend is tracked in ${String(i)}-decimal units. One wallet cannot mix asset precisions under a single per-run cap.`};const c=w(a.amount);if(c===void 0)return{abort:!0,reason:`x402 policy: this payment's amount (${a.amount}) is not a canonical atomic quantity, so it cannot be checked against the caps.`};const d=s.get(o.decimals);if(d!==void 0&&t.spentAtomic+c>d)return{abort:!0,reason:`x402 policy: this payment (${a.amount}) would exceed the per-run cap (already spent ${t.spentAtomic.toString()}, cap ${d.toString()}, in atomic base units).`};t.add(c),i=o.decimals;try{return e.onPaymentRequired!==void 0&&await e.onPaymentRequired(a)!==!0?(t.release(c),{abort:!0,reason:"x402 policy: payment was declined by onPaymentRequired."}):void 0}catch(m){throw t.release(c),m}}},$=e=>t=>{const n=w(t.selectedRequirements.amount);return n!==void 0&&e.release(n),Promise.resolve()},T=e=>{if(!(e.maxPerCall!==void 0||e.maxPerRun!==void 0||e.onPaymentRequired!==void 0))throw new l("FORBIDDEN","x402 pay: refusing to build a wallet with an unbounded spend policy. Set at least one of maxPerCall, maxPerRun, or onPaymentRequired (allowedNetworks/allowedRecipients/allowedAssets narrow but do not bound spend).")};export{x as DEFAULT_ALLOWED_ASSETS,S as DEFAULT_STABLECOIN_DECIMALS,T as assertBoundedPolicy,P as buildPaymentGuard,R as buildSpendPolicy,C as createSpendState,$ as releaseSpendOnFailure,E as usdToAtomic};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const s={arbitrum:"eip155:42161","arbitrum-sepolia":"eip155:421614",base:"eip155:8453","base-sepolia":"eip155:84532",ethereum:"eip155:1",polygon:"eip155:137",solana:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp","solana-devnet":"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"},i=["arbitrum","arbitrum-sepolia","base","base-sepolia","ethereum","polygon"],t=["solana","solana-devnet"],o=a=>{const e=s[a];if(e!==void 0)return e;if(a.includes(":"))return a;throw new Error(`Unknown x402 network "${a}". Use a friendly name (${i.join(", ")}, ${t.join(", ")}) or a raw CAIP-2 id.`)},n=a=>o(a).startsWith("eip155:"),r=a=>o(a).startsWith("solana:");export{i as EVM_NETWORKS,s as NETWORK_TO_CAIP2,t as SVM_NETWORKS,n as isEvmNetwork,r as isSvmNetwork,o as toCaip2};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{x402HTTPResourceServer as E}from"@x402/core/http";import{toCaip2 as k,isEvmNetwork as x}from"./EVM_NETWORKS-C5yyzK27.mjs";import{toReceipt as P}from"./toPaymentEventRow-DTXuTDh0.mjs";import{createFacilitatorClient as S}from"./createFacilitatorClient-piLSnKs5.mjs";import{i as g}from"./optional-peer-BBhVxozi.mjs";const H=async e=>{const{x402ResourceServer:r}=await import("@x402/core/server"),t=new r(S(e.facilitator)),s=k(e.network);if(x(e.network)){const{registerExactEvmScheme:a}=await g(()=>import("@x402/evm/exact/server"),"x402 charge: EVM networks need the optional @x402/evm + viem peers — install them, or configure an SVM network.");a(t,{networks:[s]})}else{const{registerExactSvmScheme:a}=await g(()=>import("@x402/svm/exact/server"),"x402 charge: SVM networks need the optional @x402/svm + @solana/kit peers — install them, or configure an EVM network.");a(t,{networks:[s]})}return t},T="PAYMENT-SIGNATURE",A=e=>{const r=e.toLowerCase();return r==="cdn-cache-control"||r.endsWith("-cdn-cache-control")||r==="surrogate-control"},C=e=>["private",...(e??"").split(",").map(t=>t.trim()).filter(t=>{const s=t.split("=")[0]?.trim().toLowerCase();return s!==""&&s!=="public"&&s!=="private"&&s!=="s-maxage"})].join(", "),b=e=>{const r=Object.create(null);for(const[t,s]of e)r[t]=s;return r},R=(e,r,t,s)=>{if(e!==void 0)try{const a=Promise.resolve(e(P(r,{resource:t,ts:Date.now()}))).catch(()=>{});s?.(a)}catch{}},M=e=>{const r=x(e.network),t=r?e.recipient.evm:e.recipient.svm;if(t===void 0||t.length===0)throw new Error(`x402 charge on "${e.network}" needs recipient.${r?"evm":"svm"} set.`);return t},U=e=>({accepts:{network:k(e.network),payTo:M(e),price:e.price,scheme:"exact"}}),j=(e,r)=>({getAcceptHeader:()=>e.headers.get("accept")??"",getHeader:t=>e.headers.get(t)??void 0,getMethod:()=>e.method,getPath:()=>r.pathname,getQueryParam:t=>{const s=r.searchParams.getAll(t);if(s.length!==0)return s.length===1?s[0]:s},getQueryParams:()=>{const t=Object.create(null);for(const s of new Set(r.searchParams.keys())){const a=r.searchParams.getAll(s),[h,...d]=a;h!==void 0&&(t[s]=d.length>0?a:h)}return t},getUrl:()=>e.url,getUserAgent:()=>e.headers.get("user-agent")??""}),y=e=>{const r=new Headers(e.headers),{body:t}=e;return t==null?new Response(void 0,{headers:r,status:e.status}):typeof t=="string"?(e.isHtml&&!r.has("content-type")&&r.set("content-type","text/html; charset=utf-8"),new Response(t,{headers:r,status:e.status})):Response.json(t,{headers:r,status:e.status})},N=(e,r)=>{const t=new Headers(e.headers);for(const[s,a]of Object.entries(r))t.set(s,a);return new Response(e.body,{headers:t,status:e.status,statusText:e.statusText})},Y=async(e,r,t)=>{const s=await H(e),a=new E(s,{...U(e),...r});await a.initialize();const h=t?.settleBeforeHandler??!0,d=(o,l)=>{const i=N(o,{...l,"cache-control":C(o.headers.get("cache-control"))});for(const m of[...i.headers.keys()].filter(p=>A(p)))i.headers.delete(m);return i};return{handle:async(o,l,i)=>{const m=new URL(o.url),p={adapter:j(o,m),method:o.method,path:m.pathname,paymentHeader:o.headers.get(T)??void 0},n=await a.processHTTPRequest(p);if(n.type==="no-payment-required")return l();if(n.type==="payment-error")return y(n.response);const f=r?.resource??o.url;if(h){const c=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:p});if(!c.success)return y(c.response);R(e.onReceipt,c,f,i?.waitUntil);const v=await l();return d(v,c.headers)}let w;try{w=await l()}catch(c){try{await n.cancellationDispatcher.cancel({error:c,reason:"handler_threw"})}catch(v){console.error("x402 charge: failed to cancel payment after the handler threw",v)}throw c}const u=await a.processSettlement(n.paymentPayload,n.paymentRequirements,n.declaredExtensions,{request:p,responseHeaders:b(w.headers)});return u.success?(R(e.onReceipt,u,f,i?.waitUntil),d(w,u.headers)):y(u.response)}}};export{U as buildRoute,Y as createChargeMiddleware,j as createRequestAdapter,R as reportReceipt,M as resolvePayTo,y as toResponse,N as withHeaders};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{HTTPFacilitatorClient as o}from"@x402/core/server";import{resolveFacilitatorUrl as a}from"./DEFAULT_FACILITATOR_URL-CPJNUMvi.mjs";const l=e=>{const t=a(e);if(e?.headers===void 0)return new o({url:t});const r={...e.headers};return new o({createAuthHeaders:()=>Promise.resolve({settle:r,supported:r,verify:r}),url:t})};export{l as createFacilitatorClient};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{x402Client as l}from"@x402/core/client";import{wrapFetchWithPayment as c}from"@x402/fetch";import{assertBoundedPolicy as s,buildSpendPolicy as p,buildPaymentGuard as y,releaseSpendOnFailure as m,createSpendState as d}from"./DEFAULT_ALLOWED_ASSETS-CYVf8dQC.mjs";import{registerWallet as P}from"./registerWallet-DvCt0Q7M.mjs";const S=async(t,r)=>{s(t.policy);const o=d(),a=p(t.policy),n=y(t.policy,o),i=m(o),e=new l;return await P(e,t,r),e.registerPolicy(a),e.onBeforePaymentCreation(n),e.onPaymentCreationFailure(i),c(r.fetch??globalThis.fetch,e)};export{S as createPayFetch};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as n}from"@lunora/errors";import{toCaip2 as p,isEvmNetwork as w}from"./EVM_NETWORKS-C5yyzK27.mjs";import{i as l}from"./optional-peer-BBhVxozi.mjs";const d=/^0x[0-9a-fA-F]{64}$/,y=async(t,e)=>{const a=await t(e);if(a===void 0||a.length===0)throw new n("ENV_INVALID",`x402 pay: secret "${e}" is not set — the agent wallet has no key to sign with.`);return a},m=(t,e)=>{const a=t.address.startsWith("0x");if(e&&!a)throw new n("ENV_INVALID",`x402 pay: the supplied signer address "${t.address}" is not an EVM (0x…) address, but the network is EVM.`);if(!e&&a)throw new n("ENV_INVALID",`x402 pay: the supplied signer address "${t.address}" is an EVM (0x…) address, but the network is Solana.`)},h=async(t,e)=>{const{CdpClient:a}=await l(()=>import("@coinbase/cdp-sdk"),'x402 pay: CDP-managed custody needs the optional @coinbase/cdp-sdk peer — install it, or use "raw-key"/"signer" custody instead.'),[c,s,r]=await Promise.all([y(e,t.apiKeyIdSecretName??"CDP_API_KEY_ID"),y(e,t.apiKeySecretName??"CDP_API_KEY_SECRET"),y(e,t.walletSecretName??"CDP_WALLET_SECRET")]);return new a({apiKeyId:c,apiKeySecret:s,walletSecret:r}).evm.getOrCreateAccount({name:t.account})},u=async t=>{const e=t.startsWith("0x")?t:`0x${t}`;if(!d.test(e))throw new n("ENV_INVALID","x402 pay: the EVM wallet key must be a 32-byte hex private key (64 hex chars, optional 0x prefix).");const{privateKeyToAccount:a}=await l(()=>import("viem/accounts"),'x402 pay: raw-key EVM custody needs the optional viem peer — install it, or use "cdp"/"signer" custody instead.');return a(e)},E=async t=>{const e=t.trim(),{createKeyPairSignerFromBytes:a,createKeyPairSignerFromPrivateKeyBytes:c,getBase58Encoder:s}=await l(()=>import("@solana/kit"),'x402 pay: raw-key Solana custody needs the optional @solana/kit peer — install it, or pass a pre-built signer via "signer" custody instead.');let r;if(e.startsWith("[")){let o;try{o=JSON.parse(e)}catch{throw new n("ENV_INVALID","x402 pay: the Solana wallet key looks like a JSON byte array but is not valid JSON.")}if(!Array.isArray(o)||o.some(i=>typeof i!="number"))throw new n("ENV_INVALID","x402 pay: the Solana wallet key JSON must be an array of byte values.");r=Uint8Array.from(o)}else try{r=Uint8Array.from(s().encode(e))}catch{throw new n("ENV_INVALID","x402 pay: the Solana wallet key must be a base58 secret key or a JSON byte array.")}if(r.length===64)return a(r);if(r.length===32)return c(r);throw new n("ENV_INVALID",`x402 pay: the Solana wallet key must decode to 32 or 64 bytes (got ${String(r.length)}). Provide a base58 secret key or a JSON byte array.`)},x=async(t,e,a)=>{const c=p(e.network),{signer:s}=e,r=w(e.network);let o;if(s.type==="signer")m(s.signer,r),o=s.signer;else if(s.type==="cdp"){if(!r)throw new n("NOT_IMPLEMENTED",`x402 pay: CDP-managed Solana custody (account "${s.account}") is not wired — a CDP Solana account is not a @solana/kit signer. Build a @solana/kit signer around it and pass it via the { type: "signer" } escape hatch, or use "raw-key".`);o=await h(s,a.getSecret)}else{const i=await y(a.getSecret,s.secretName);o=r?await u(i):await E(i)}if(r){const{registerExactEvmScheme:i}=await l(()=>import("@x402/evm/exact/client"),"x402 pay: EVM networks need the optional @x402/evm + viem peers — install them, or configure an SVM network.");i(t,{networks:[c],signer:o})}else{const{registerExactSvmScheme:i}=await l(()=>import("@x402/svm/exact/client"),"x402 pay: SVM networks need the optional @x402/svm + @solana/kit peers — install them, or configure an EVM network.");i(t,{networks:[c],signer:o})}};export{x as registerWallet,u as resolveEvmAccount,E as resolveSvmSigner};
|